changeset 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents 8ced16adf2e1
children 3549bbe597ed
files src/AutoBuild.h src/Makefile.am src/NLS.h src/Port.h src/SFMT/CHANGE-LOG.txt src/SFMT/LICENSE.txt src/SFMT/README.txt src/SFMT/SFMT-alti.h src/SFMT/SFMT-params.h src/SFMT/SFMT-params11213.h src/SFMT/SFMT-params1279.h src/SFMT/SFMT-params132049.h src/SFMT/SFMT-params19937.h src/SFMT/SFMT-params216091.h src/SFMT/SFMT-params2281.h src/SFMT/SFMT-params4253.h src/SFMT/SFMT-params44497.h src/SFMT/SFMT-params607.h src/SFMT/SFMT-params86243.h src/SFMT/SFMT-sse2.h src/SFMT/SFMT.c src/SFMT/SFMT.h src/VisualBoyAdvance.cfg src/apu/Blip_Buffer.cpp src/apu/Blip_Buffer.h src/common/CheatSearch.cpp src/common/CheatSearch.h src/common/Makefile.am src/common/System.h src/common/Text.cpp src/common/Text.h src/common/Util.cpp src/common/Util.h src/common/inputGlobal.h src/common/lua-engine.cpp src/common/memgzio.c src/common/memgzio.h src/common/movie.cpp src/common/movie.h src/common/nesvideos-piece.cpp src/common/nesvideos-piece.h src/common/unzip.cpp src/common/unzip.h src/common/vbalua.h src/filters/2xSaI.cpp src/filters/2xSaImmx.asm src/filters/Makefile.am src/filters/admame.cpp src/filters/bilinear.cpp src/filters/filters.h src/filters/hq2x.cpp src/filters/hq2x.h src/filters/hq3x32.cpp src/filters/hq3x32.h src/filters/hq_shared32.cpp src/filters/hq_shared32.h src/filters/interframe.cpp src/filters/interp.h src/filters/lq2x.h src/filters/motionblur.cpp src/filters/pixel.cpp src/filters/scanline.cpp src/filters/simple2x.cpp src/gb/GB.cpp src/gb/GB.h src/gb/Makefile.am src/gb/gbCheats.cpp src/gb/gbCheats.h src/gb/gbCodes.h src/gb/gbCodesCB.h src/gb/gbDis.cpp src/gb/gbGfx.cpp src/gb/gbGlobals.cpp src/gb/gbGlobals.h src/gb/gbMemory.cpp src/gb/gbMemory.h src/gb/gbPrinter.cpp src/gb/gbPrinter.h src/gb/gbSGB.cpp src/gb/gbSGB.h src/gb/gbSound.cpp src/gb/gbSound.h src/gba/EEprom.cpp src/gba/EEprom.h src/gba/Flash.cpp src/gba/Flash.h src/gba/GBA.cpp src/gba/GBA.h src/gba/GBACheats.cpp src/gba/GBACheats.h src/gba/GBAGfx.cpp src/gba/GBAGfx.h src/gba/GBAGlobals.cpp src/gba/GBAGlobals.h src/gba/GBASound.cpp src/gba/GBASound.h src/gba/GBAinline.h src/gba/Makefile.am src/gba/Mode0.cpp src/gba/Mode1.cpp src/gba/Mode2.cpp src/gba/Mode3.cpp src/gba/Mode4.cpp src/gba/Mode5.cpp src/gba/RTC.cpp src/gba/RTC.h src/gba/Sram.cpp src/gba/Sram.h src/gba/agbprint.cpp src/gba/agbprint.h src/gba/arm-new.h src/gba/armdis.cpp src/gba/armdis.h src/gba/bios.cpp src/gba/bios.h src/gba/elf.cpp src/gba/elf.h src/gba/remote.cpp src/gba/thumb.h src/gtk/.deps/gvba-configfile.Po src/gtk/.deps/gvba-filters.Po src/gtk/.deps/gvba-input.Po src/gtk/.deps/gvba-joypadconfig.Po src/gtk/.deps/gvba-main.Po src/gtk/.deps/gvba-screenarea.Po src/gtk/.deps/gvba-system.Po src/gtk/.deps/gvba-tools.Po src/gtk/.deps/gvba-window.Po src/gtk/.deps/gvba-windowcallbacks.Po src/gtk/Makefile src/gtk/Makefile.am src/gtk/configfile.cpp src/gtk/configfile.h src/gtk/filters.cpp src/gtk/filters.h src/gtk/images/Makefile src/gtk/images/Makefile.am src/gtk/images/stock-vba-wm-16.png src/gtk/images/stock-vba-wm-32.png src/gtk/images/stock-vba-wm-48.png src/gtk/images/stock-vba-wm-64.png src/gtk/images/vba-64.png src/gtk/input.cpp src/gtk/input.h src/gtk/intl.h src/gtk/joypadconfig.cpp src/gtk/joypadconfig.h src/gtk/main.cpp src/gtk/menuitem.h src/gtk/screenarea.cpp src/gtk/screenarea.h src/gtk/sigccompat.h src/gtk/system.cpp src/gtk/tools.cpp src/gtk/tools.h src/gtk/vba.glade src/gtk/window.cpp src/gtk/window.h src/gtk/windowcallbacks.cpp src/lua/Makefile.am src/lua/src/lapi.c src/lua/src/lapi.h src/lua/src/lauxlib.c src/lua/src/lauxlib.h src/lua/src/lbaselib.c src/lua/src/lcode.c src/lua/src/lcode.h src/lua/src/ldblib.c src/lua/src/ldebug.c src/lua/src/ldebug.h src/lua/src/ldo.c src/lua/src/ldo.h src/lua/src/ldump.c src/lua/src/lfunc.c src/lua/src/lfunc.h src/lua/src/lgc.c src/lua/src/lgc.h src/lua/src/linit.c src/lua/src/liolib.c src/lua/src/llex.c src/lua/src/llex.h src/lua/src/llimits.h src/lua/src/lmathlib.c src/lua/src/lmem.c src/lua/src/lmem.h src/lua/src/loadlib.c src/lua/src/lobject.c src/lua/src/lobject.h src/lua/src/lopcodes.c src/lua/src/lopcodes.h src/lua/src/loslib.c src/lua/src/lparser.c src/lua/src/lparser.h src/lua/src/lstate.c src/lua/src/lstate.h src/lua/src/lstring.c src/lua/src/lstring.h src/lua/src/lstrlib.c src/lua/src/ltable.c src/lua/src/ltable.h src/lua/src/ltablib.c src/lua/src/ltm.c src/lua/src/ltm.h src/lua/src/lua.h src/lua/src/luaconf.h src/lua/src/lualib.h src/lua/src/lundump.c src/lua/src/lundump.h src/lua/src/lvm.c src/lua/src/lvm.h src/lua/src/lzio.c src/lua/src/lzio.h src/lua/src/print.c src/prof/Makefile.am src/prof/gmon.h src/prof/gmon_out.h src/prof/prof.cpp src/prof/prof.h src/sdl/Array.h src/sdl/Makefile.am src/sdl/RingBuffer.h src/sdl/SDL.cpp src/sdl/SoundDriver.h src/sdl/SoundSDL.cpp src/sdl/SoundSDL.h src/sdl/TestEmu.cpp src/sdl/Types.h src/sdl/debugger.cpp src/sdl/debugger.h src/sdl/expr-lex.cpp src/sdl/expr.cpp src/sdl/expr.cpp.h src/sdl/expr.l src/sdl/expr.y src/sdl/exprNode.cpp src/sdl/exprNode.h src/sdl/getopt.c src/sdl/getopt.h src/sdl/getopt1.c src/version.h src/win32/.cvsignore src/win32/7zip/7z/7zip_2005.vcproj src/win32/7zip/7z/7zip_2008.vcproj src/win32/7zip/7z/7zip_2010.vcxproj src/win32/7zip/7z/7zip_2010.vcxproj.filters src/win32/7zip/7z/C/7zCrc.c src/win32/7zip/7z/C/7zCrc.h src/win32/7zip/7z/C/Aes.c src/win32/7zip/7z/C/Aes.h src/win32/7zip/7z/C/Alloc.c src/win32/7zip/7z/C/Alloc.h src/win32/7zip/7z/C/Bra.c src/win32/7zip/7z/C/Bra.h src/win32/7zip/7z/C/Bra86.c src/win32/7zip/7z/C/BraIA64.c src/win32/7zip/7z/C/BwtSort.c src/win32/7zip/7z/C/BwtSort.h src/win32/7zip/7z/C/CpuArch.h src/win32/7zip/7z/C/HuffEnc.c src/win32/7zip/7z/C/HuffEnc.h src/win32/7zip/7z/C/LzFind.c src/win32/7zip/7z/C/LzFind.h src/win32/7zip/7z/C/LzFindMt.c src/win32/7zip/7z/C/LzFindMt.h src/win32/7zip/7z/C/LzHash.h src/win32/7zip/7z/C/LzmaDec.c src/win32/7zip/7z/C/LzmaDec.h src/win32/7zip/7z/C/LzmaEnc.c src/win32/7zip/7z/C/LzmaEnc.h src/win32/7zip/7z/C/RotateDefs.h src/win32/7zip/7z/C/Sha256.c src/win32/7zip/7z/C/Sha256.h src/win32/7zip/7z/C/Sort.c src/win32/7zip/7z/C/Sort.h src/win32/7zip/7z/C/Threads.c src/win32/7zip/7z/C/Threads.h src/win32/7zip/7z/C/Types.h src/win32/7zip/7z/CPP/7zip/Archive/7z/7zCompressionMode.cpp src/win32/7zip/7z/CPP/7zip/Archive/7z/7zCompressionMode.h src/win32/7zip/7z/CPP/7zip/Archive/7z/7zDecode.cpp src/win32/7zip/7z/CPP/7zip/Archive/7z/7zDecode.h src/win32/7zip/7z/CPP/7zip/Archive/7z/7zExtract.cpp src/win32/7zip/7z/CPP/7zip/Archive/7z/7zFolderInStream.cpp src/win32/7zip/7z/CPP/7zip/Archive/7z/7zFolderInStream.h src/win32/7zip/7z/CPP/7zip/Archive/7z/7zFolderOutStream.cpp src/win32/7zip/7z/CPP/7zip/Archive/7z/7zFolderOutStream.h src/win32/7zip/7z/CPP/7zip/Archive/7z/7zHandler.cpp src/win32/7zip/7z/CPP/7zip/Archive/7z/7zHandler.h src/win32/7zip/7z/CPP/7zip/Archive/7z/7zHeader.cpp src/win32/7zip/7z/CPP/7zip/Archive/7z/7zHeader.h src/win32/7zip/7z/CPP/7zip/Archive/7z/7zIn.cpp src/win32/7zip/7z/CPP/7zip/Archive/7z/7zIn.h src/win32/7zip/7z/CPP/7zip/Archive/7z/7zItem.h src/win32/7zip/7z/CPP/7zip/Archive/7z/7zProperties.cpp src/win32/7zip/7z/CPP/7zip/Archive/7z/7zProperties.h src/win32/7zip/7z/CPP/7zip/Archive/7z/7zRegister.cpp src/win32/7zip/7z/CPP/7zip/Archive/7z/7zSpecStream.cpp src/win32/7zip/7z/CPP/7zip/Archive/7z/7zSpecStream.h src/win32/7zip/7z/CPP/7zip/Archive/7z/StdAfx.h src/win32/7zip/7z/CPP/7zip/Archive/ArchiveExports.cpp src/win32/7zip/7z/CPP/7zip/Archive/BZip2/BZip2Handler.cpp src/win32/7zip/7z/CPP/7zip/Archive/BZip2/BZip2Handler.h src/win32/7zip/7z/CPP/7zip/Archive/BZip2/BZip2Item.h src/win32/7zip/7z/CPP/7zip/Archive/BZip2/StdAfx.h src/win32/7zip/7z/CPP/7zip/Archive/BZip2/bz2Register.cpp src/win32/7zip/7z/CPP/7zip/Archive/Common/CoderMixer2.cpp src/win32/7zip/7z/CPP/7zip/Archive/Common/CoderMixer2.h src/win32/7zip/7z/CPP/7zip/Archive/Common/CoderMixer2MT.cpp src/win32/7zip/7z/CPP/7zip/Archive/Common/CoderMixer2MT.h src/win32/7zip/7z/CPP/7zip/Archive/Common/DummyOutStream.cpp src/win32/7zip/7z/CPP/7zip/Archive/Common/DummyOutStream.h src/win32/7zip/7z/CPP/7zip/Archive/Common/FindSignature.cpp src/win32/7zip/7z/CPP/7zip/Archive/Common/FindSignature.h src/win32/7zip/7z/CPP/7zip/Archive/Common/InStreamWithCRC.cpp src/win32/7zip/7z/CPP/7zip/Archive/Common/InStreamWithCRC.h src/win32/7zip/7z/CPP/7zip/Archive/Common/ItemNameUtils.cpp src/win32/7zip/7z/CPP/7zip/Archive/Common/ItemNameUtils.h src/win32/7zip/7z/CPP/7zip/Archive/Common/MultiStream.cpp src/win32/7zip/7z/CPP/7zip/Archive/Common/MultiStream.h src/win32/7zip/7z/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp src/win32/7zip/7z/CPP/7zip/Archive/Common/OutStreamWithCRC.h src/win32/7zip/7z/CPP/7zip/Archive/Common/ParseProperties.cpp src/win32/7zip/7z/CPP/7zip/Archive/Common/ParseProperties.h src/win32/7zip/7z/CPP/7zip/Archive/Common/StdAfx.h src/win32/7zip/7z/CPP/7zip/Archive/DllExports2.cpp src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipHandler.cpp src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipHandler.h src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipHeader.cpp src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipHeader.h src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipIn.cpp src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipIn.h src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipItem.h src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipRegister.cpp src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipUpdate.h src/win32/7zip/7z/CPP/7zip/Archive/GZip/StdAfx.h src/win32/7zip/7z/CPP/7zip/Archive/IArchive.h src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhCRC.cpp src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhCRC.h src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhHandler.cpp src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhHandler.h src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhHeader.h src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhIn.cpp src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhIn.h src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhItem.h src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhOutStreamWithCRC.cpp src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhOutStreamWithCRC.h src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhRegister.cpp src/win32/7zip/7z/CPP/7zip/Archive/Lzh/StdAfx.h src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaArcRegister.cpp src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.cpp src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.h src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaHandler.cpp src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaHandler.h src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaIn.cpp src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaIn.h src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaItem.h src/win32/7zip/7z/CPP/7zip/Archive/Lzma/StdAfx.h src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarHandler.cpp src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarHandler.h src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarHeader.cpp src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarHeader.h src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarIn.cpp src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarIn.h src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarItem.cpp src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarItem.h src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarRegister.cpp src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarVolumeInStream.h src/win32/7zip/7z/CPP/7zip/Archive/Rar/StdAfx.h src/win32/7zip/7z/CPP/7zip/Archive/Split/SplitHandler.cpp src/win32/7zip/7z/CPP/7zip/Archive/Split/SplitHandler.h src/win32/7zip/7z/CPP/7zip/Archive/Split/SplitRegister.cpp src/win32/7zip/7z/CPP/7zip/Archive/Split/StdAfx.h src/win32/7zip/7z/CPP/7zip/Archive/StdAfx.h src/win32/7zip/7z/CPP/7zip/Archive/Tar/StdAfx.h src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarHandler.cpp src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarHandler.h src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarHeader.cpp src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarHeader.h src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarIn.cpp src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarIn.h src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarItem.h src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarRegister.cpp src/win32/7zip/7z/CPP/7zip/Archive/Zip/StdAfx.h src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipCompressionMode.h src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipHandler.cpp src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipHandler.h src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipHeader.cpp src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipHeader.h src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipIn.cpp src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipIn.h src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipItem.cpp src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipItem.h src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipItemEx.h src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipRegister.cpp src/win32/7zip/7z/CPP/7zip/Common/CreateCoder.cpp src/win32/7zip/7z/CPP/7zip/Common/CreateCoder.h src/win32/7zip/7z/CPP/7zip/Common/DeclareArcs.h src/win32/7zip/7z/CPP/7zip/Common/DeclareCodecs.h src/win32/7zip/7z/CPP/7zip/Common/FilterCoder.cpp src/win32/7zip/7z/CPP/7zip/Common/FilterCoder.h src/win32/7zip/7z/CPP/7zip/Common/InBuffer.cpp src/win32/7zip/7z/CPP/7zip/Common/InBuffer.h src/win32/7zip/7z/CPP/7zip/Common/InOutTempBuffer.cpp src/win32/7zip/7z/CPP/7zip/Common/InOutTempBuffer.h src/win32/7zip/7z/CPP/7zip/Common/LimitedStreams.cpp src/win32/7zip/7z/CPP/7zip/Common/LimitedStreams.h src/win32/7zip/7z/CPP/7zip/Common/LockedStream.cpp src/win32/7zip/7z/CPP/7zip/Common/LockedStream.h src/win32/7zip/7z/CPP/7zip/Common/MemBlocks.cpp src/win32/7zip/7z/CPP/7zip/Common/MemBlocks.h src/win32/7zip/7z/CPP/7zip/Common/MethodId.cpp src/win32/7zip/7z/CPP/7zip/Common/MethodId.h src/win32/7zip/7z/CPP/7zip/Common/MethodProps.cpp src/win32/7zip/7z/CPP/7zip/Common/MethodProps.h src/win32/7zip/7z/CPP/7zip/Common/OffsetStream.cpp src/win32/7zip/7z/CPP/7zip/Common/OffsetStream.h src/win32/7zip/7z/CPP/7zip/Common/OutBuffer.cpp src/win32/7zip/7z/CPP/7zip/Common/OutBuffer.h src/win32/7zip/7z/CPP/7zip/Common/OutMemStream.cpp src/win32/7zip/7z/CPP/7zip/Common/OutMemStream.h src/win32/7zip/7z/CPP/7zip/Common/ProgressMt.cpp src/win32/7zip/7z/CPP/7zip/Common/ProgressMt.h src/win32/7zip/7z/CPP/7zip/Common/ProgressUtils.cpp src/win32/7zip/7z/CPP/7zip/Common/ProgressUtils.h src/win32/7zip/7z/CPP/7zip/Common/RegisterArc.h src/win32/7zip/7z/CPP/7zip/Common/RegisterCodec.h src/win32/7zip/7z/CPP/7zip/Common/StdAfx.h src/win32/7zip/7z/CPP/7zip/Common/StreamBinder.cpp src/win32/7zip/7z/CPP/7zip/Common/StreamBinder.h src/win32/7zip/7z/CPP/7zip/Common/StreamObjects.cpp src/win32/7zip/7z/CPP/7zip/Common/StreamObjects.h src/win32/7zip/7z/CPP/7zip/Common/StreamUtils.cpp src/win32/7zip/7z/CPP/7zip/Common/StreamUtils.h src/win32/7zip/7z/CPP/7zip/Common/VirtThread.cpp src/win32/7zip/7z/CPP/7zip/Common/VirtThread.h src/win32/7zip/7z/CPP/7zip/Compress/BZip2Const.h src/win32/7zip/7z/CPP/7zip/Compress/BZip2Crc.cpp src/win32/7zip/7z/CPP/7zip/Compress/BZip2Crc.h src/win32/7zip/7z/CPP/7zip/Compress/BZip2Decoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/BZip2Decoder.h src/win32/7zip/7z/CPP/7zip/Compress/BZip2Register.cpp src/win32/7zip/7z/CPP/7zip/Compress/Bcj2Coder.cpp src/win32/7zip/7z/CPP/7zip/Compress/Bcj2Coder.h src/win32/7zip/7z/CPP/7zip/Compress/Bcj2Register.cpp src/win32/7zip/7z/CPP/7zip/Compress/BcjCoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/BcjCoder.h src/win32/7zip/7z/CPP/7zip/Compress/BcjRegister.cpp src/win32/7zip/7z/CPP/7zip/Compress/BitlDecoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/BitlDecoder.h src/win32/7zip/7z/CPP/7zip/Compress/BitmDecoder.h src/win32/7zip/7z/CPP/7zip/Compress/BranchCoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/BranchCoder.h src/win32/7zip/7z/CPP/7zip/Compress/BranchMisc.cpp src/win32/7zip/7z/CPP/7zip/Compress/BranchMisc.h src/win32/7zip/7z/CPP/7zip/Compress/BranchRegister.cpp src/win32/7zip/7z/CPP/7zip/Compress/ByteSwap.cpp src/win32/7zip/7z/CPP/7zip/Compress/ByteSwap.h src/win32/7zip/7z/CPP/7zip/Compress/ByteSwapRegister.cpp src/win32/7zip/7z/CPP/7zip/Compress/Codec.def src/win32/7zip/7z/CPP/7zip/Compress/CodecExports.cpp src/win32/7zip/7z/CPP/7zip/Compress/CopyCoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/CopyCoder.h src/win32/7zip/7z/CPP/7zip/Compress/CopyRegister.cpp src/win32/7zip/7z/CPP/7zip/Compress/Deflate64Register.cpp src/win32/7zip/7z/CPP/7zip/Compress/DeflateConst.h src/win32/7zip/7z/CPP/7zip/Compress/DeflateDecoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/DeflateDecoder.h src/win32/7zip/7z/CPP/7zip/Compress/DeflateNsisRegister.cpp src/win32/7zip/7z/CPP/7zip/Compress/DeflateRegister.cpp src/win32/7zip/7z/CPP/7zip/Compress/HuffmanDecoder.h src/win32/7zip/7z/CPP/7zip/Compress/ImplodeDecoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/ImplodeDecoder.h src/win32/7zip/7z/CPP/7zip/Compress/ImplodeHuffmanDecoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/ImplodeHuffmanDecoder.h src/win32/7zip/7z/CPP/7zip/Compress/LzOutWindow.cpp src/win32/7zip/7z/CPP/7zip/Compress/LzOutWindow.h src/win32/7zip/7z/CPP/7zip/Compress/LzhDecoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/LzhDecoder.h src/win32/7zip/7z/CPP/7zip/Compress/LzmaDecoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/LzmaDecoder.h src/win32/7zip/7z/CPP/7zip/Compress/LzmaRegister.cpp src/win32/7zip/7z/CPP/7zip/Compress/Mtf8.h src/win32/7zip/7z/CPP/7zip/Compress/PpmdContext.h src/win32/7zip/7z/CPP/7zip/Compress/PpmdDecode.h src/win32/7zip/7z/CPP/7zip/Compress/PpmdDecoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/PpmdDecoder.h src/win32/7zip/7z/CPP/7zip/Compress/PpmdRegister.cpp src/win32/7zip/7z/CPP/7zip/Compress/PpmdSubAlloc.h src/win32/7zip/7z/CPP/7zip/Compress/PpmdType.h src/win32/7zip/7z/CPP/7zip/Compress/RangeCoder.h src/win32/7zip/7z/CPP/7zip/Compress/RangeCoderBit.h src/win32/7zip/7z/CPP/7zip/Compress/Rar1Decoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/Rar1Decoder.h src/win32/7zip/7z/CPP/7zip/Compress/Rar2Decoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/Rar2Decoder.h src/win32/7zip/7z/CPP/7zip/Compress/Rar3Decoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/Rar3Decoder.h src/win32/7zip/7z/CPP/7zip/Compress/Rar3Vm.cpp src/win32/7zip/7z/CPP/7zip/Compress/Rar3Vm.h src/win32/7zip/7z/CPP/7zip/Compress/RarCodecsRegister.cpp src/win32/7zip/7z/CPP/7zip/Compress/ShrinkDecoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/ShrinkDecoder.h src/win32/7zip/7z/CPP/7zip/Compress/StdAfx.h src/win32/7zip/7z/CPP/7zip/Compress/ZlibDecoder.cpp src/win32/7zip/7z/CPP/7zip/Compress/ZlibDecoder.h src/win32/7zip/7z/CPP/7zip/Compress/makefile src/win32/7zip/7z/CPP/7zip/Crypto/7zAes.cpp src/win32/7zip/7z/CPP/7zip/Crypto/7zAes.h src/win32/7zip/7z/CPP/7zip/Crypto/7zAesRegister.cpp src/win32/7zip/7z/CPP/7zip/Crypto/HmacSha1.cpp src/win32/7zip/7z/CPP/7zip/Crypto/HmacSha1.h src/win32/7zip/7z/CPP/7zip/Crypto/MyAes.cpp src/win32/7zip/7z/CPP/7zip/Crypto/MyAes.h src/win32/7zip/7z/CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp src/win32/7zip/7z/CPP/7zip/Crypto/Pbkdf2HmacSha1.h src/win32/7zip/7z/CPP/7zip/Crypto/RandGen.cpp src/win32/7zip/7z/CPP/7zip/Crypto/RandGen.h src/win32/7zip/7z/CPP/7zip/Crypto/Rar20Crypto.cpp src/win32/7zip/7z/CPP/7zip/Crypto/Rar20Crypto.h src/win32/7zip/7z/CPP/7zip/Crypto/RarAes.cpp src/win32/7zip/7z/CPP/7zip/Crypto/RarAes.h src/win32/7zip/7z/CPP/7zip/Crypto/Sha1.cpp src/win32/7zip/7z/CPP/7zip/Crypto/Sha1.h src/win32/7zip/7z/CPP/7zip/Crypto/StdAfx.h src/win32/7zip/7z/CPP/7zip/Crypto/WzAes.cpp src/win32/7zip/7z/CPP/7zip/Crypto/WzAes.h src/win32/7zip/7z/CPP/7zip/Crypto/ZipCrypto.cpp src/win32/7zip/7z/CPP/7zip/Crypto/ZipCrypto.h src/win32/7zip/7z/CPP/7zip/Crypto/ZipStrong.cpp src/win32/7zip/7z/CPP/7zip/Crypto/ZipStrong.h src/win32/7zip/7z/CPP/7zip/ICoder.h src/win32/7zip/7z/CPP/7zip/IDecl.h src/win32/7zip/7z/CPP/7zip/IPassword.h src/win32/7zip/7z/CPP/7zip/IProgress.h src/win32/7zip/7z/CPP/7zip/IStream.h src/win32/7zip/7z/CPP/7zip/PropID.h src/win32/7zip/7z/CPP/Common/Buffer.h src/win32/7zip/7z/CPP/Common/CRC.cpp src/win32/7zip/7z/CPP/Common/ComTry.h src/win32/7zip/7z/CPP/Common/Defs.h src/win32/7zip/7z/CPP/Common/DynamicBuffer.h src/win32/7zip/7z/CPP/Common/InitializeStaticLib.h src/win32/7zip/7z/CPP/Common/IntToString.cpp src/win32/7zip/7z/CPP/Common/IntToString.h src/win32/7zip/7z/CPP/Common/MyCom.h src/win32/7zip/7z/CPP/Common/MyException.h src/win32/7zip/7z/CPP/Common/MyInitGuid.h src/win32/7zip/7z/CPP/Common/MyMap.cpp src/win32/7zip/7z/CPP/Common/MyMap.h src/win32/7zip/7z/CPP/Common/MyString.cpp src/win32/7zip/7z/CPP/Common/MyString.h src/win32/7zip/7z/CPP/Common/MyUnknown.h src/win32/7zip/7z/CPP/Common/MyVector.cpp src/win32/7zip/7z/CPP/Common/MyVector.h src/win32/7zip/7z/CPP/Common/MyWindows.h src/win32/7zip/7z/CPP/Common/MyXml.cpp src/win32/7zip/7z/CPP/Common/MyXml.h src/win32/7zip/7z/CPP/Common/NewHandler.cpp src/win32/7zip/7z/CPP/Common/NewHandler.h src/win32/7zip/7z/CPP/Common/StdAfx.h src/win32/7zip/7z/CPP/Common/StringConvert.cpp src/win32/7zip/7z/CPP/Common/StringConvert.h src/win32/7zip/7z/CPP/Common/StringToInt.cpp src/win32/7zip/7z/CPP/Common/StringToInt.h src/win32/7zip/7z/CPP/Common/Types.h src/win32/7zip/7z/CPP/Common/UTFConvert.cpp src/win32/7zip/7z/CPP/Common/UTFConvert.h src/win32/7zip/7z/CPP/Common/Wildcard.cpp src/win32/7zip/7z/CPP/Common/Wildcard.h src/win32/7zip/7z/CPP/Windows/Defs.h src/win32/7zip/7z/CPP/Windows/FileDir.cpp src/win32/7zip/7z/CPP/Windows/FileDir.h src/win32/7zip/7z/CPP/Windows/FileFind.cpp src/win32/7zip/7z/CPP/Windows/FileFind.h src/win32/7zip/7z/CPP/Windows/FileIO.cpp src/win32/7zip/7z/CPP/Windows/FileIO.h src/win32/7zip/7z/CPP/Windows/FileName.h src/win32/7zip/7z/CPP/Windows/Handle.h src/win32/7zip/7z/CPP/Windows/PropVariant.cpp src/win32/7zip/7z/CPP/Windows/PropVariant.h src/win32/7zip/7z/CPP/Windows/StdAfx.h src/win32/7zip/7z/CPP/Windows/Synchronization.h src/win32/7zip/7z/CPP/Windows/Thread.h src/win32/7zip/7z/CPP/Windows/Time.cpp src/win32/7zip/7z/CPP/Windows/Time.h src/win32/7zip/7z/DOC/License.txt src/win32/7zip/7z/DOC/gpl.txt src/win32/7zip/7z/DOC/readme.txt src/win32/7zip/7z/DOC/unRarLicense.txt src/win32/7zip/7zip.cpp src/win32/7zip/7zip.h src/win32/7zip/7zip.rc src/win32/7zip/7zipstreams.h src/win32/7zip/OpenArchive.cpp src/win32/7zip/OpenArchive.h src/win32/AVIWrite.cpp src/win32/AVIWrite.h src/win32/AboutDialog.cpp src/win32/AboutDialog.h src/win32/AccelEditor.cpp src/win32/AccelEditor.h src/win32/AcceleratorManager.cpp src/win32/AcceleratorManager.h src/win32/Associate.cpp src/win32/Associate.h src/win32/BitmapControl.cpp src/win32/BitmapControl.h src/win32/BugReport.cpp src/win32/BugReport.h src/win32/CmdAccelOb.cpp src/win32/CmdAccelOb.h src/win32/ColorButton.cpp src/win32/ColorButton.h src/win32/ColorControl.cpp src/win32/ColorControl.h src/win32/Commands.cpp src/win32/Direct3D.cpp src/win32/DirectDraw.cpp src/win32/DirectInput.cpp src/win32/DirectSound.cpp src/win32/Directories.cpp src/win32/Directories.h src/win32/Disassemble.cpp src/win32/Disassemble.h src/win32/Display.h src/win32/ExportGSASnapshot.cpp src/win32/ExportGSASnapshot.h src/win32/FileDlg.cpp src/win32/FileDlg.h src/win32/GBACheatsDlg.cpp src/win32/GBACheatsDlg.h src/win32/GBCheatsDlg.cpp src/win32/GBCheatsDlg.h src/win32/GBColorDlg.cpp src/win32/GBColorDlg.h src/win32/GBDisassemble.cpp src/win32/GBDisassemble.h src/win32/GBMapView.cpp src/win32/GBMapView.h src/win32/GBMemoryViewerDlg.cpp src/win32/GBMemoryViewerDlg.h src/win32/GBOamView.cpp src/win32/GBOamView.h src/win32/GBPaletteView.cpp src/win32/GBPaletteView.h src/win32/GBPrinterDlg.cpp src/win32/GBPrinterDlg.h src/win32/GBTileView.cpp src/win32/GBTileView.h src/win32/GDBConnection.cpp src/win32/GDBConnection.h src/win32/GDIDisplay.cpp src/win32/GSACodeSelect.cpp src/win32/GSACodeSelect.h src/win32/Hyperlink.cpp src/win32/Hyperlink.h src/win32/IOViewer.cpp src/win32/IOViewer.h src/win32/IOViewerRegs.h src/win32/IUpdate.h src/win32/Input.h src/win32/Joypad.cpp src/win32/Joypad.h src/win32/KeyboardEdit.cpp src/win32/KeyboardEdit.h src/win32/LangSelect.cpp src/win32/LangSelect.h src/win32/Logging.cpp src/win32/Logging.h src/win32/LuaOpenDialog.cpp src/win32/LuaOpenDialog.h src/win32/MainWnd.cpp src/win32/MainWnd.h src/win32/MainWndCheats.cpp src/win32/MainWndFile.cpp src/win32/MainWndHelp.cpp src/win32/MainWndOptions.cpp src/win32/MainWndTools.cpp src/win32/MapView.cpp src/win32/MapView.h src/win32/MaxScale.cpp src/win32/MaxScale.h src/win32/MemoryViewer.cpp src/win32/MemoryViewer.h src/win32/MemoryViewerAddressSize.cpp src/win32/MemoryViewerAddressSize.h src/win32/MemoryViewerDlg.cpp src/win32/MemoryViewerDlg.h src/win32/ModeConfirm.cpp src/win32/ModeConfirm.h src/win32/MovieCreate.cpp src/win32/MovieCreate.h src/win32/MovieOpen.cpp src/win32/MovieOpen.h src/win32/OamView.cpp src/win32/OamView.h src/win32/OpenGL.cpp src/win32/PaletteView.cpp src/win32/PaletteView.h src/win32/PaletteViewControl.cpp src/win32/PaletteViewControl.h src/win32/PerfTimer.cpp src/win32/PerfTimer.h src/win32/Reg.cpp src/win32/Reg.h src/win32/ResizeDlg.cpp src/win32/ResizeDlg.h src/win32/RewindInterval.cpp src/win32/RewindInterval.h src/win32/RomInfo.cpp src/win32/RomInfo.h src/win32/Sound.h src/win32/StringTokenizer.cpp src/win32/StringTokenizer.h src/win32/System.cpp src/win32/TextOptions.cpp src/win32/TextOptions.h src/win32/Throttle.cpp src/win32/Throttle.h src/win32/TileView.cpp src/win32/TileView.h src/win32/VBA.clw src/win32/VBA.cpp src/win32/VBA.h src/win32/VersionInfo.h src/win32/VideoMode.cpp src/win32/VideoMode.h src/win32/VisualBoyAdvance.exe.manifest src/win32/WavWriter.cpp src/win32/WavWriter.h src/win32/WinHelper.h src/win32/WinMiscUtil.cpp src/win32/WinMiscUtil.h src/win32/WinResUtil.cpp src/win32/WinResUtil.h src/win32/ZoomControl.cpp src/win32/ZoomControl.h src/win32/gbadvance.ico src/win32/ram_search.cpp src/win32/ram_search.h src/win32/ramwatch.cpp src/win32/ramwatch.h src/win32/resource.h src/win32/stdafx.cpp src/win32/stdafx.h src/win32/vba.rc src/win32/vba.rc2
diffstat 748 files changed, 221655 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/AutoBuild.h	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,30 @@
     1.4 +// -*- C++ -*-
     1.5 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
     1.6 +// Copyright (C) 1999-2003 Forgotten
     1.7 +// Copyright (C) 2004 Forgotten and the VBA development team
     1.8 +
     1.9 +// This program is free software; you can redistribute it and/or modify
    1.10 +// it under the terms of the GNU General Public License as published by
    1.11 +// the Free Software Foundation; either version 2, or(at your option)
    1.12 +// any later version.
    1.13 +//
    1.14 +// This program is distributed in the hope that it will be useful,
    1.15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.17 +// GNU General Public License for more details.
    1.18 +//
    1.19 +// You should have received a copy of the GNU General Public License
    1.20 +// along with this program; if not, write to the Free Software Foundation,
    1.21 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    1.22 +
    1.23 +#ifndef __AUTOBUILD_H__
    1.24 +#define __AUTOBUILD_H__
    1.25 +#include "version.h"
    1.26 +//change the FALSE to TRUE for autoincrement of build number
    1.27 +#define INCREMENT_VERSION FALSE
    1.28 +#define FILEVER        1,8,0,600
    1.29 +#define PRODUCTVER     1,8,0,600
    1.30 +#define STRFILEVER     "1, 8, 0, 600\0"
    1.31 +#define STRPRODUCTVER  "1, 8, 0, 600\0"
    1.32 +#endif //__AUTOBUILD_H__
    1.33 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/Makefile.am	Sat Mar 03 10:31:27 2012 -0600
     2.3 @@ -0,0 +1,15 @@
     2.4 +CORE_SUBDIRS = gba gb common filters
     2.5 +
     2.6 +EXTRA_SUBDIRS = prof sdl gtk lua
     2.7 +
     2.8 +SUBDIRS = $(CORE_SUBDIRS) @VBA_SRC_EXTRA@
     2.9 +
    2.10 +DIST_SUBDIRS = $(CORE_SUBDIRS) $(EXTRA_SUBDIRS)
    2.11 +
    2.12 +dist_sysconf_DATA = VisualBoyAdvance.cfg
    2.13 +
    2.14 +EXTRA_DIST = \
    2.15 +	win32
    2.16 +
    2.17 +dist-hook:
    2.18 +	rm -rf `find $(distdir)/win32 -name CVS`
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/NLS.h	Sat Mar 03 10:31:27 2012 -0600
     3.3 @@ -0,0 +1,52 @@
     3.4 +#ifndef VBS_NLS_H
     3.5 +#define VBA_NLS_H
     3.6 +
     3.7 +#if _MSC_VER > 1000
     3.8 +#pragma once
     3.9 +#endif // _MSC_VER > 1000
    3.10 +
    3.11 +#define N_(String) (String)
    3.12 +
    3.13 +#define MSG_UNSUPPORTED_VBA_SGM             1
    3.14 +#define MSG_CANNOT_LOAD_SGM                 2
    3.15 +#define MSG_SAVE_GAME_NOT_USING_BIOS        3
    3.16 +#define MSG_SAVE_GAME_USING_BIOS            4
    3.17 +#define MSG_UNSUPPORTED_SAVE_TYPE           5
    3.18 +#define MSG_CANNOT_OPEN_FILE                6
    3.19 +#define MSG_BAD_ZIP_FILE                    7
    3.20 +#define MSG_NO_IMAGE_ON_ZIP                 8
    3.21 +#define MSG_ERROR_OPENING_IMAGE             9
    3.22 +#define MSG_ERROR_READING_IMAGE            10
    3.23 +#define MSG_UNSUPPORTED_BIOS_FUNCTION      11
    3.24 +#define MSG_INVALID_BIOS_FILE_SIZE         12
    3.25 +#define MSG_INVALID_CHEAT_CODE             13
    3.26 +#define MSG_UNKNOWN_ARM_OPCODE             14
    3.27 +#define MSG_UNKNOWN_THUMB_OPCODE           15
    3.28 +#define MSG_ERROR_CREATING_FILE            16
    3.29 +#define MSG_FAILED_TO_READ_SGM             17
    3.30 +#define MSG_FAILED_TO_READ_RTC             18
    3.31 +#define MSG_UNSUPPORTED_VB_SGM             19
    3.32 +#define MSG_CANNOT_LOAD_SGM_FOR            20
    3.33 +#define MSG_ERROR_OPENING_IMAGE_FROM       21
    3.34 +#define MSG_ERROR_READING_IMAGE_FROM       22
    3.35 +#define MSG_UNSUPPORTED_ROM_SIZE           23
    3.36 +#define MSG_UNSUPPORTED_RAM_SIZE           24
    3.37 +#define MSG_UNKNOWN_CARTRIDGE_TYPE         25
    3.38 +#define MSG_MAXIMUM_NUMBER_OF_CHEATS       26
    3.39 +#define MSG_INVALID_GAMESHARK_CODE         27
    3.40 +#define MSG_INVALID_GAMEGENIE_CODE         28
    3.41 +#define MSG_INVALID_CHEAT_TO_REMOVE        29
    3.42 +#define MSG_INVALID_CHEAT_CODE_ADDRESS     30
    3.43 +#define MSG_UNSUPPORTED_CHEAT_LIST_VERSION 31
    3.44 +#define MSG_UNSUPPORTED_CHEAT_LIST_TYPE    32
    3.45 +#define MSG_INVALID_GSA_CODE               33
    3.46 +#define MSG_CANNOT_IMPORT_SNAPSHOT_FOR     34
    3.47 +#define MSG_UNSUPPORTED_SNAPSHOT_FILE      35
    3.48 +#define MSG_UNSUPPORTED_ARM_MODE           36
    3.49 +#define MSG_UNSUPPORTED_CODE_FILE          37
    3.50 +#define MSG_GBA_CODE_WARNING               38
    3.51 +#define MSG_INVALID_CBA_CODE               39
    3.52 +#define MSG_CBA_CODE_WARNING               40
    3.53 +#define MSG_OUT_OF_MEMORY                  41
    3.54 +
    3.55 +#endif // VBA_NLS_H
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/Port.h	Sat Mar 03 10:31:27 2012 -0600
     4.3 @@ -0,0 +1,178 @@
     4.4 +#ifndef VBA_PORT_H
     4.5 +#define VBA_PORT_H
     4.6 +
     4.7 +#if _MSC_VER > 1000
     4.8 +#pragma once
     4.9 +#endif // _MSC_VER > 1000
    4.10 +
    4.11 +#include <ctime>
    4.12 +
    4.13 +#ifndef NULL
    4.14 +#define NULL 0
    4.15 +#endif
    4.16 +
    4.17 +typedef unsigned char bool8;
    4.18 +
    4.19 +#ifdef HAVE_STDINT_H
    4.20 +#include <stdint.h>
    4.21 +
    4.22 +typedef int8_t   int8;
    4.23 +typedef uint8_t  uint8;
    4.24 +typedef int16_t  int16;
    4.25 +typedef uint16_t uint16;
    4.26 +typedef int32_t  int32;
    4.27 +typedef uint32_t uint32;
    4.28 +typedef int64_t  int64;
    4.29 +typedef uint64_t uint64;
    4.30 +typedef intptr_t pint;
    4.31 +
    4.32 +#else /* Don't have stdint.h */
    4.33 +
    4.34 +#ifdef PTR_NOT_INT
    4.35 +typedef long pint;
    4.36 +#else /* pointer is int */
    4.37 +typedef int pint;
    4.38 +#endif /* PTR_NOT_INT */
    4.39 +
    4.40 +/* FIXME: Refactor this by moving out the BORLAND part and unifying typedefs */
    4.41 +#ifndef WIN32
    4.42 +typedef unsigned char  uint8;
    4.43 +typedef unsigned short uint16;
    4.44 +typedef signed char    int8;
    4.45 +typedef short          int16;
    4.46 +typedef int            int32;
    4.47 +typedef unsigned int   uint32;
    4.48 +# ifdef __GNUC__  /* long long is not part of ISO C++ */
    4.49 +__extension__ typedef long long          int64;
    4.50 +__extension__ typedef unsigned long long uint64;
    4.51 +# else
    4.52 +typedef long long          int64;
    4.53 +typedef unsigned long long uint64;
    4.54 +# endif
    4.55 +#else /* WIN32 */
    4.56 +
    4.57 +# ifdef __BORLANDC__
    4.58 +#   include <systypes.h>
    4.59 +# else
    4.60 +
    4.61 +typedef unsigned char  uint8;
    4.62 +typedef unsigned short uint16;
    4.63 +typedef signed char    int8;
    4.64 +typedef short          int16;
    4.65 +
    4.66 +# ifndef WSAAPI
    4.67 +/* winsock2.h typedefs int32 as well. */
    4.68 +typedef long int32;
    4.69 +# endif
    4.70 +
    4.71 +typedef unsigned int uint32;
    4.72 +
    4.73 +# endif /* __BORLANDC__ */
    4.74 +
    4.75 +typedef __int64          int64;
    4.76 +typedef unsigned __int64 uint64;
    4.77 +
    4.78 +#endif /* WIN32 */
    4.79 +#endif /* HAVE_STDINT_H */
    4.80 +
    4.81 +#ifndef WIN32
    4.82 +
    4.83 +#ifndef PATH_MAX
    4.84 +#define PATH_MAX 1024
    4.85 +#endif
    4.86 +
    4.87 +#define _MAX_DIR PATH_MAX
    4.88 +#define _MAX_DRIVE 1
    4.89 +#define _MAX_FNAME PATH_MAX
    4.90 +#define _MAX_EXT PATH_MAX
    4.91 +#define _MAX_PATH PATH_MAX
    4.92 +
    4.93 +#define ZeroMemory(a, b) memset((a), 0, (b))
    4.94 +
    4.95 +void _makepath(char *path, const char *drive, const char *dir,
    4.96 +               const char *fname, const char *ext);
    4.97 +void _splitpath(const char *path, char *drive, char *dir, char *fname,
    4.98 +                char *ext);
    4.99 +#else /* WIN32 */
   4.100 +#define strcasecmp stricmp
   4.101 +#define strncasecmp strnicmp
   4.102 +#endif
   4.103 +
   4.104 +typedef uint8  u8;
   4.105 +typedef uint16 u16;
   4.106 +typedef uint32 u32;
   4.107 +typedef uint64 u64;
   4.108 +typedef int8   s8;
   4.109 +typedef int16  s16;
   4.110 +typedef int32  s32;
   4.111 +typedef int64  s64;
   4.112 +
   4.113 +// for consistency
   4.114 +static inline u8 swap8(u8 v)
   4.115 +{
   4.116 +	return v;
   4.117 +}
   4.118 +
   4.119 +// swaps a 16-bit value
   4.120 +static inline u16 swap16(u16 v)
   4.121 +{
   4.122 +	return (v<<8)|(v>>8);
   4.123 +}
   4.124 +
   4.125 +// swaps a 32-bit value
   4.126 +static inline u32 swap32(u32 v)
   4.127 +{
   4.128 +	return (v<<24)|((v<<8)&0xff0000)|((v>>8)&0xff00)|(v>>24);
   4.129 +}
   4.130 +
   4.131 +#define READ8LE(x) \
   4.132 +    *((u8 *)x)
   4.133 +
   4.134 +#define WRITE8LE(x, v) \
   4.135 +    *((u8 *)x) = (v)
   4.136 +
   4.137 +#ifdef WORDS_BIGENDIAN
   4.138 +#if defined(__GNUC__) && defined(__ppc__)
   4.139 +
   4.140 +#define READ16LE(base) \
   4.141 +    ({ unsigned short lhbrxResult;       \
   4.142 +       __asm__("lhbrx %0, 0, %1" : "=r" (lhbrxResult) : "r" (base) : "memory"); \
   4.143 +       lhbrxResult; })
   4.144 +
   4.145 +#define READ32LE(base) \
   4.146 +    ({ unsigned long lwbrxResult; \
   4.147 +       __asm__("lwbrx %0, 0, %1" : "=r" (lwbrxResult) : "r" (base) : "memory"); \
   4.148 +       lwbrxResult; })
   4.149 +
   4.150 +#define WRITE16LE(base, value) \
   4.151 +    __asm__("sthbrx %0, 0, %1" : : "r" (value), "r" (base) : "memory")
   4.152 +
   4.153 +#define WRITE32LE(base, value) \
   4.154 +    __asm__("stwbrx %0, 0, %1" : : "r" (value), "r" (base) : "memory")
   4.155 +
   4.156 +#else
   4.157 +#define READ16LE(x) \
   4.158 +    swap16(*((u16 *)(x)))
   4.159 +#define READ32LE(x) \
   4.160 +    swap32(*((u32 *)(x)))
   4.161 +#define WRITE16LE(x, v) \
   4.162 +    *((u16 *)x) = swap16((v))
   4.163 +#define WRITE32LE(x, v) \
   4.164 +    *((u32 *)x) = swap32((v))
   4.165 +#endif
   4.166 +#else
   4.167 +#define READ16LE(x) \
   4.168 +    *((u16 *)x)
   4.169 +#define READ32LE(x) \
   4.170 +    *((u32 *)x)
   4.171 +#define WRITE16LE(x, v) \
   4.172 +    *((u16 *)x) = (v)
   4.173 +#define WRITE32LE(x, v) \
   4.174 +    *((u32 *)x) = (v)
   4.175 +#endif
   4.176 +
   4.177 +#ifndef CTASSERT
   4.178 +#define CTASSERT(x)  typedef char __assert ## y[(x) ? 1 : -1];
   4.179 +#endif
   4.180 +
   4.181 +#endif // VBA_PORT_H
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/SFMT/CHANGE-LOG.txt	Sat Mar 03 10:31:27 2012 -0600
     5.3 @@ -0,0 +1,55 @@
     5.4 +ver 1.3.3
     5.5 +-------
     5.6 +change condition compile of do_recursion in SFMT.c
     5.7 +
     5.8 +ver 1.3.2
     5.9 +-------
    5.10 +bug fix to_res53_mix and genrand_res53_mix.
    5.11 +
    5.12 +ver 1.3.1
    5.13 +-------
    5.14 +gcc compile option changed form -O9 to -O3.
    5.15 +add functions genrand_res53_mix and to_res53_mix.
    5.16 +bug fix about definition of ALWAYS_INLINE.
    5.17 +add new definition PRE_ALWAYS for MSC.
    5.18 +
    5.19 +ver 1.3
    5.20 +-------
    5.21 +bug fixed: -DONLY64 without -DBIG_ENIAN64 had been generating
    5.22 +wrong sequence.
    5.23 +bug fixed: There is no documentation about BIG_ENDIAN64.
    5.24 +add automatic endian check by __BIG_ENDIAN__ predefined macro.
    5.25 +bug fixed: change == in check.sh to =
    5.26 +add SFMT-params216091.h
    5.27 +add AltiVec parameter format for systems which are not osx.
    5.28 +change Makefile for systems which are not osx and support AltiVec.
    5.29 +change sample2 of howto-compile for Free BSD.
    5.30 +change source files for BORLANDC and Visual Studio.
    5.31 +change period certification code more smart.
    5.32 +add params directory.
    5.33 +
    5.34 +ver 1.2.1
    5.35 +-------
    5.36 +Fix typo in SFMT-alti.c SFMT-sse2.c
    5.37 +marge SFMT-alti.c and SFMT-alti.h into SFMT-alti.h
    5.38 +marge SFMT-sse2.c and SFMT-sse2.h into SFMT-sse2.h
    5.39 +This version is not released.
    5.40 +
    5.41 +ver 1.2
    5.42 +-------
    5.43 +Support many periods: 2^{607}, 2^{1279}, 2^{2281}, 2^{4253}, 2^{11213},
    5.44 +2^{19937}, 2^{44497}, 2^{86243}, 2^{132049}
    5.45 +Fix typo in LICENSE.txt.
    5.46 +Add cast to vec_perm for SFMT-alti.c, SFMT-alti64.c.
    5.47 +combine source codes.
    5.48 +
    5.49 +ver 1.1
    5.50 +-------
    5.51 +The period certification method is changed from constant to function.
    5.52 +The convert functions from 32-bit and 64-bit integer to double are added.
    5.53 +The documentation is changed.
    5.54 +Sample programs are added.
    5.55 +
    5.56 +ver 1.0
    5.57 +-------
    5.58 +The first version.
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/SFMT/LICENSE.txt	Sat Mar 03 10:31:27 2012 -0600
     6.3 @@ -0,0 +1,29 @@
     6.4 +Copyright (c) 2006,2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
     6.5 +University. All rights reserved.
     6.6 +
     6.7 +Redistribution and use in source and binary forms, with or without
     6.8 +modification, are permitted provided that the following conditions are
     6.9 +met:
    6.10 +
    6.11 +    * Redistributions of source code must retain the above copyright
    6.12 +      notice, this list of conditions and the following disclaimer.
    6.13 +    * Redistributions in binary form must reproduce the above
    6.14 +      copyright notice, this list of conditions and the following
    6.15 +      disclaimer in the documentation and/or other materials provided
    6.16 +      with the distribution.
    6.17 +    * Neither the name of the Hiroshima University nor the names of
    6.18 +      its contributors may be used to endorse or promote products
    6.19 +      derived from this software without specific prior written
    6.20 +      permission.
    6.21 +
    6.22 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    6.23 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    6.24 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    6.25 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    6.26 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    6.27 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    6.28 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    6.29 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    6.30 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    6.31 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    6.32 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/SFMT/README.txt	Sat Mar 03 10:31:27 2012 -0600
     7.3 @@ -0,0 +1,22 @@
     7.4 + =================================================================
     7.5 + SFMT ver. 1.3.3
     7.6 + SIMD oriented Fast Mersenne Twister(SFMT)
     7.7 +
     7.8 + Mutsuo Saito (Hiroshima University) and
     7.9 + Makoto Matsumoto (Hiroshima University)
    7.10 +
    7.11 + Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
    7.12 + University. All rights reserved.
    7.13 +
    7.14 + The (modified) BSD License is applied to this software, see LICENSE.txt
    7.15 + =================================================================
    7.16 +
    7.17 + To see documents, see html/index.html.
    7.18 +
    7.19 + To make test program, see html/howto-compile.html
    7.20 +
    7.21 + If you want to redistribute and/or change source files, see LICENSE.txt.
    7.22 +
    7.23 + When you change these files and redistribute them, PLEASE write your
    7.24 + e-mail address in redistribution and write to contact YOU first if
    7.25 + users of your changed source encounter troubles.
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/SFMT/SFMT-alti.h	Sat Mar 03 10:31:27 2012 -0600
     8.3 @@ -0,0 +1,156 @@
     8.4 +/** 
     8.5 + * @file SFMT-alti.h 
     8.6 + *
     8.7 + * @brief SIMD oriented Fast Mersenne Twister(SFMT)
     8.8 + * pseudorandom number generator
     8.9 + *
    8.10 + * @author Mutsuo Saito (Hiroshima University)
    8.11 + * @author Makoto Matsumoto (Hiroshima University)
    8.12 + *
    8.13 + * Copyright (C) 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
    8.14 + * University. All rights reserved.
    8.15 + *
    8.16 + * The new BSD License is applied to this software.
    8.17 + * see LICENSE.txt
    8.18 + */
    8.19 +
    8.20 +#ifndef SFMT_ALTI_H
    8.21 +#define SFMT_ALTI_H
    8.22 +
    8.23 +inline static vector unsigned int vec_recursion(vector unsigned int a,
    8.24 +						vector unsigned int b,
    8.25 +						vector unsigned int c,
    8.26 +						vector unsigned int d)
    8.27 +    ALWAYSINLINE;
    8.28 +
    8.29 +/**
    8.30 + * This function represents the recursion formula in AltiVec and BIG ENDIAN.
    8.31 + * @param a a 128-bit part of the interal state array
    8.32 + * @param b a 128-bit part of the interal state array
    8.33 + * @param c a 128-bit part of the interal state array
    8.34 + * @param d a 128-bit part of the interal state array
    8.35 + * @return output
    8.36 + */
    8.37 +inline static vector unsigned int vec_recursion(vector unsigned int a,
    8.38 +						vector unsigned int b,
    8.39 +						vector unsigned int c,
    8.40 +						vector unsigned int d) {
    8.41 +
    8.42 +    const vector unsigned int sl1 = ALTI_SL1;
    8.43 +    const vector unsigned int sr1 = ALTI_SR1;
    8.44 +#ifdef ONLY64
    8.45 +    const vector unsigned int mask = ALTI_MSK64;
    8.46 +    const vector unsigned char perm_sl = ALTI_SL2_PERM64;
    8.47 +    const vector unsigned char perm_sr = ALTI_SR2_PERM64;
    8.48 +#else
    8.49 +    const vector unsigned int mask = ALTI_MSK;
    8.50 +    const vector unsigned char perm_sl = ALTI_SL2_PERM;
    8.51 +    const vector unsigned char perm_sr = ALTI_SR2_PERM;
    8.52 +#endif
    8.53 +    vector unsigned int v, w, x, y, z;
    8.54 +    x = vec_perm(a, (vector unsigned int)perm_sl, perm_sl);
    8.55 +    v = a;
    8.56 +    y = vec_sr(b, sr1);
    8.57 +    z = vec_perm(c, (vector unsigned int)perm_sr, perm_sr);
    8.58 +    w = vec_sl(d, sl1);
    8.59 +    z = vec_xor(z, w);
    8.60 +    y = vec_and(y, mask);
    8.61 +    v = vec_xor(v, x);
    8.62 +    z = vec_xor(z, y);
    8.63 +    z = vec_xor(z, v);
    8.64 +    return z;
    8.65 +}
    8.66 +
    8.67 +/**
    8.68 + * This function fills the internal state array with pseudorandom
    8.69 + * integers.
    8.70 + */
    8.71 +inline static void gen_rand_all(void) {
    8.72 +    int i;
    8.73 +    vector unsigned int r, r1, r2;
    8.74 +
    8.75 +    r1 = sfmt[N - 2].s;
    8.76 +    r2 = sfmt[N - 1].s;
    8.77 +    for (i = 0; i < N - POS1; i++) {
    8.78 +	r = vec_recursion(sfmt[i].s, sfmt[i + POS1].s, r1, r2);
    8.79 +	sfmt[i].s = r;
    8.80 +	r1 = r2;
    8.81 +	r2 = r;
    8.82 +    }
    8.83 +    for (; i < N; i++) {
    8.84 +	r = vec_recursion(sfmt[i].s, sfmt[i + POS1 - N].s, r1, r2);
    8.85 +	sfmt[i].s = r;
    8.86 +	r1 = r2;
    8.87 +	r2 = r;
    8.88 +    }
    8.89 +}
    8.90 +
    8.91 +/**
    8.92 + * This function fills the user-specified array with pseudorandom
    8.93 + * integers.
    8.94 + *
    8.95 + * @param array an 128-bit array to be filled by pseudorandom numbers.  
    8.96 + * @param size number of 128-bit pesudorandom numbers to be generated.
    8.97 + */
    8.98 +inline static void gen_rand_array(w128_t *array, int size) {
    8.99 +    int i, j;
   8.100 +    vector unsigned int r, r1, r2;
   8.101 +
   8.102 +    r1 = sfmt[N - 2].s;
   8.103 +    r2 = sfmt[N - 1].s;
   8.104 +    for (i = 0; i < N - POS1; i++) {
   8.105 +	r = vec_recursion(sfmt[i].s, sfmt[i + POS1].s, r1, r2);
   8.106 +	array[i].s = r;
   8.107 +	r1 = r2;
   8.108 +	r2 = r;
   8.109 +    }
   8.110 +    for (; i < N; i++) {
   8.111 +	r = vec_recursion(sfmt[i].s, array[i + POS1 - N].s, r1, r2);
   8.112 +	array[i].s = r;
   8.113 +	r1 = r2;
   8.114 +	r2 = r;
   8.115 +    }
   8.116 +    /* main loop */
   8.117 +    for (; i < size - N; i++) {
   8.118 +	r = vec_recursion(array[i - N].s, array[i + POS1 - N].s, r1, r2);
   8.119 +	array[i].s = r;
   8.120 +	r1 = r2;
   8.121 +	r2 = r;
   8.122 +    }
   8.123 +    for (j = 0; j < 2 * N - size; j++) {
   8.124 +	sfmt[j].s = array[j + size - N].s;
   8.125 +    }
   8.126 +    for (; i < size; i++) {
   8.127 +	r = vec_recursion(array[i - N].s, array[i + POS1 - N].s, r1, r2);
   8.128 +	array[i].s = r;
   8.129 +	sfmt[j++].s = r;
   8.130 +	r1 = r2;
   8.131 +	r2 = r;
   8.132 +    }
   8.133 +}
   8.134 +
   8.135 +#ifndef ONLY64
   8.136 +#if defined(__APPLE__)
   8.137 +#define ALTI_SWAP (vector unsigned char) \
   8.138 +	(4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11)
   8.139 +#else
   8.140 +#define ALTI_SWAP {4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11}
   8.141 +#endif
   8.142 +/**
   8.143 + * This function swaps high and low 32-bit of 64-bit integers in user
   8.144 + * specified array.
   8.145 + *
   8.146 + * @param array an 128-bit array to be swaped.
   8.147 + * @param size size of 128-bit array.
   8.148 + */
   8.149 +inline static void swap(w128_t *array, int size) {
   8.150 +    int i;
   8.151 +    const vector unsigned char perm = ALTI_SWAP;
   8.152 +
   8.153 +    for (i = 0; i < size; i++) {
   8.154 +	array[i].s = vec_perm(array[i].s, (vector unsigned int)perm, perm);
   8.155 +    }
   8.156 +}
   8.157 +#endif
   8.158 +
   8.159 +#endif
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/SFMT/SFMT-params.h	Sat Mar 03 10:31:27 2012 -0600
     9.3 @@ -0,0 +1,97 @@
     9.4 +#ifndef SFMT_PARAMS_H
     9.5 +#define SFMT_PARAMS_H
     9.6 +
     9.7 +#if !defined(MEXP)
     9.8 +#ifdef __GNUC__
     9.9 +  #warning "MEXP is not defined. I assume MEXP is 19937."
    9.10 +#endif
    9.11 +  #define MEXP 19937
    9.12 +#endif
    9.13 +/*-----------------
    9.14 +  BASIC DEFINITIONS
    9.15 +  -----------------*/
    9.16 +/** Mersenne Exponent. The period of the sequence 
    9.17 + *  is a multiple of 2^MEXP-1.
    9.18 + * #define MEXP 19937 */
    9.19 +/** SFMT generator has an internal state array of 128-bit integers,
    9.20 + * and N is its size. */
    9.21 +#define N (MEXP / 128 + 1)
    9.22 +/** N32 is the size of internal state array when regarded as an array
    9.23 + * of 32-bit integers.*/
    9.24 +#define N32 (N * 4)
    9.25 +/** N64 is the size of internal state array when regarded as an array
    9.26 + * of 64-bit integers.*/
    9.27 +#define N64 (N * 2)
    9.28 +
    9.29 +/*----------------------
    9.30 +  the parameters of SFMT
    9.31 +  following definitions are in paramsXXXX.h file.
    9.32 +  ----------------------*/
    9.33 +/** the pick up position of the array.
    9.34 +#define POS1 122 
    9.35 +*/
    9.36 +
    9.37 +/** the parameter of shift left as four 32-bit registers.
    9.38 +#define SL1 18
    9.39 + */
    9.40 +
    9.41 +/** the parameter of shift left as one 128-bit register. 
    9.42 + * The 128-bit integer is shifted by (SL2 * 8) bits. 
    9.43 +#define SL2 1 
    9.44 +*/
    9.45 +
    9.46 +/** the parameter of shift right as four 32-bit registers.
    9.47 +#define SR1 11
    9.48 +*/
    9.49 +
    9.50 +/** the parameter of shift right as one 128-bit register. 
    9.51 + * The 128-bit integer is shifted by (SL2 * 8) bits. 
    9.52 +#define SR2 1 
    9.53 +*/
    9.54 +
    9.55 +/** A bitmask, used in the recursion.  These parameters are introduced
    9.56 + * to break symmetry of SIMD.
    9.57 +#define MSK1 0xdfffffefU
    9.58 +#define MSK2 0xddfecb7fU
    9.59 +#define MSK3 0xbffaffffU
    9.60 +#define MSK4 0xbffffff6U 
    9.61 +*/
    9.62 +
    9.63 +/** These definitions are part of a 128-bit period certification vector.
    9.64 +#define PARITY1	0x00000001U
    9.65 +#define PARITY2	0x00000000U
    9.66 +#define PARITY3	0x00000000U
    9.67 +#define PARITY4	0xc98e126aU
    9.68 +*/
    9.69 +
    9.70 +#if MEXP == 607
    9.71 +  #include "SFMT-params607.h"
    9.72 +#elif MEXP == 1279
    9.73 +  #include "SFMT-params1279.h"
    9.74 +#elif MEXP == 2281
    9.75 +  #include "SFMT-params2281.h"
    9.76 +#elif MEXP == 4253
    9.77 +  #include "SFMT-params4253.h"
    9.78 +#elif MEXP == 11213
    9.79 +  #include "SFMT-params11213.h"
    9.80 +#elif MEXP == 19937
    9.81 +  #include "SFMT-params19937.h"
    9.82 +#elif MEXP == 44497
    9.83 +  #include "SFMT-params44497.h"
    9.84 +#elif MEXP == 86243
    9.85 +  #include "SFMT-params86243.h"
    9.86 +#elif MEXP == 132049
    9.87 +  #include "SFMT-params132049.h"
    9.88 +#elif MEXP == 216091
    9.89 +  #include "SFMT-params216091.h"
    9.90 +#else
    9.91 +#ifdef __GNUC__
    9.92 +  #error "MEXP is not valid."
    9.93 +  #undef MEXP
    9.94 +#else
    9.95 +  #undef MEXP
    9.96 +#endif
    9.97 +
    9.98 +#endif
    9.99 +
   9.100 +#endif /* SFMT_PARAMS_H */
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/SFMT/SFMT-params11213.h	Sat Mar 03 10:31:27 2012 -0600
    10.3 @@ -0,0 +1,46 @@
    10.4 +#ifndef SFMT_PARAMS11213_H
    10.5 +#define SFMT_PARAMS11213_H
    10.6 +
    10.7 +#define POS1	68
    10.8 +#define SL1	14
    10.9 +#define SL2	3
   10.10 +#define SR1	7
   10.11 +#define SR2	3
   10.12 +#define MSK1	0xeffff7fbU
   10.13 +#define MSK2	0xffffffefU
   10.14 +#define MSK3	0xdfdfbfffU
   10.15 +#define MSK4	0x7fffdbfdU
   10.16 +#define PARITY1	0x00000001U
   10.17 +#define PARITY2	0x00000000U
   10.18 +#define PARITY3	0xe8148000U
   10.19 +#define PARITY4	0xd0c7afa3U
   10.20 +
   10.21 +
   10.22 +/* PARAMETERS FOR ALTIVEC */
   10.23 +#if defined(__APPLE__)	/* For OSX */
   10.24 +    #define ALTI_SL1	(vector unsigned int)(SL1, SL1, SL1, SL1)
   10.25 +    #define ALTI_SR1	(vector unsigned int)(SR1, SR1, SR1, SR1)
   10.26 +    #define ALTI_MSK	(vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
   10.27 +    #define ALTI_MSK64 \
   10.28 +	(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
   10.29 +    #define ALTI_SL2_PERM \
   10.30 +	(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
   10.31 +    #define ALTI_SL2_PERM64 \
   10.32 +	(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
   10.33 +    #define ALTI_SR2_PERM \
   10.34 +	(vector unsigned char)(5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12)
   10.35 +    #define ALTI_SR2_PERM64 \
   10.36 +	(vector unsigned char)(13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12)
   10.37 +#else	/* For OTHER OSs(Linux?) */
   10.38 +    #define ALTI_SL1	{SL1, SL1, SL1, SL1}
   10.39 +    #define ALTI_SR1	{SR1, SR1, SR1, SR1}
   10.40 +    #define ALTI_MSK	{MSK1, MSK2, MSK3, MSK4}
   10.41 +    #define ALTI_MSK64	{MSK2, MSK1, MSK4, MSK3}
   10.42 +    #define ALTI_SL2_PERM	{3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
   10.43 +    #define ALTI_SL2_PERM64	{3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
   10.44 +    #define ALTI_SR2_PERM	{5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12}
   10.45 +    #define ALTI_SR2_PERM64	{13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12}
   10.46 +#endif	/* For OSX */
   10.47 +#define IDSTR	"SFMT-11213:68-14-3-7-3:effff7fb-ffffffef-dfdfbfff-7fffdbfd"
   10.48 +
   10.49 +#endif /* SFMT_PARAMS11213_H */
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/SFMT/SFMT-params1279.h	Sat Mar 03 10:31:27 2012 -0600
    11.3 @@ -0,0 +1,46 @@
    11.4 +#ifndef SFMT_PARAMS1279_H
    11.5 +#define SFMT_PARAMS1279_H
    11.6 +
    11.7 +#define POS1	7
    11.8 +#define SL1	14
    11.9 +#define SL2	3
   11.10 +#define SR1	5
   11.11 +#define SR2	1
   11.12 +#define MSK1	0xf7fefffdU
   11.13 +#define MSK2	0x7fefcfffU
   11.14 +#define MSK3	0xaff3ef3fU
   11.15 +#define MSK4	0xb5ffff7fU
   11.16 +#define PARITY1	0x00000001U
   11.17 +#define PARITY2	0x00000000U
   11.18 +#define PARITY3	0x00000000U
   11.19 +#define PARITY4	0x20000000U
   11.20 +
   11.21 +
   11.22 +/* PARAMETERS FOR ALTIVEC */
   11.23 +#if defined(__APPLE__)	/* For OSX */
   11.24 +    #define ALTI_SL1	(vector unsigned int)(SL1, SL1, SL1, SL1)
   11.25 +    #define ALTI_SR1	(vector unsigned int)(SR1, SR1, SR1, SR1)
   11.26 +    #define ALTI_MSK	(vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
   11.27 +    #define ALTI_MSK64 \
   11.28 +	(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
   11.29 +    #define ALTI_SL2_PERM \
   11.30 +	(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
   11.31 +    #define ALTI_SL2_PERM64 \
   11.32 +	(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
   11.33 +    #define ALTI_SR2_PERM \
   11.34 +	(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
   11.35 +    #define ALTI_SR2_PERM64 \
   11.36 +	(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
   11.37 +#else	/* For OTHER OSs(Linux?) */
   11.38 +    #define ALTI_SL1	{SL1, SL1, SL1, SL1}
   11.39 +    #define ALTI_SR1	{SR1, SR1, SR1, SR1}
   11.40 +    #define ALTI_MSK	{MSK1, MSK2, MSK3, MSK4}
   11.41 +    #define ALTI_MSK64	{MSK2, MSK1, MSK4, MSK3}
   11.42 +    #define ALTI_SL2_PERM	{3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
   11.43 +    #define ALTI_SL2_PERM64	{3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
   11.44 +    #define ALTI_SR2_PERM	{7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
   11.45 +    #define ALTI_SR2_PERM64	{15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
   11.46 +#endif	/* For OSX */
   11.47 +#define IDSTR	"SFMT-1279:7-14-3-5-1:f7fefffd-7fefcfff-aff3ef3f-b5ffff7f"
   11.48 +
   11.49 +#endif /* SFMT_PARAMS1279_H */
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/SFMT/SFMT-params132049.h	Sat Mar 03 10:31:27 2012 -0600
    12.3 @@ -0,0 +1,46 @@
    12.4 +#ifndef SFMT_PARAMS132049_H
    12.5 +#define SFMT_PARAMS132049_H
    12.6 +
    12.7 +#define POS1	110
    12.8 +#define SL1	19
    12.9 +#define SL2	1
   12.10 +#define SR1	21
   12.11 +#define SR2	1
   12.12 +#define MSK1	0xffffbb5fU
   12.13 +#define MSK2	0xfb6ebf95U
   12.14 +#define MSK3	0xfffefffaU
   12.15 +#define MSK4	0xcff77fffU
   12.16 +#define PARITY1	0x00000001U
   12.17 +#define PARITY2	0x00000000U
   12.18 +#define PARITY3	0xcb520000U
   12.19 +#define PARITY4	0xc7e91c7dU
   12.20 +
   12.21 +
   12.22 +/* PARAMETERS FOR ALTIVEC */
   12.23 +#if defined(__APPLE__)	/* For OSX */
   12.24 +    #define ALTI_SL1	(vector unsigned int)(SL1, SL1, SL1, SL1)
   12.25 +    #define ALTI_SR1	(vector unsigned int)(SR1, SR1, SR1, SR1)
   12.26 +    #define ALTI_MSK	(vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
   12.27 +    #define ALTI_MSK64 \
   12.28 +	(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
   12.29 +    #define ALTI_SL2_PERM \
   12.30 +	(vector unsigned char)(1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8)
   12.31 +    #define ALTI_SL2_PERM64 \
   12.32 +	(vector unsigned char)(1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0)
   12.33 +    #define ALTI_SR2_PERM \
   12.34 +	(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
   12.35 +    #define ALTI_SR2_PERM64 \
   12.36 +	(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
   12.37 +#else	/* For OTHER OSs(Linux?) */
   12.38 +    #define ALTI_SL1	{SL1, SL1, SL1, SL1}
   12.39 +    #define ALTI_SR1	{SR1, SR1, SR1, SR1}
   12.40 +    #define ALTI_MSK	{MSK1, MSK2, MSK3, MSK4}
   12.41 +    #define ALTI_MSK64	{MSK2, MSK1, MSK4, MSK3}
   12.42 +    #define ALTI_SL2_PERM	{1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8}
   12.43 +    #define ALTI_SL2_PERM64	{1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0}
   12.44 +    #define ALTI_SR2_PERM	{7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
   12.45 +    #define ALTI_SR2_PERM64	{15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
   12.46 +#endif	/* For OSX */
   12.47 +#define IDSTR	"SFMT-132049:110-19-1-21-1:ffffbb5f-fb6ebf95-fffefffa-cff77fff"
   12.48 +
   12.49 +#endif /* SFMT_PARAMS132049_H */
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/SFMT/SFMT-params19937.h	Sat Mar 03 10:31:27 2012 -0600
    13.3 @@ -0,0 +1,46 @@
    13.4 +#ifndef SFMT_PARAMS19937_H
    13.5 +#define SFMT_PARAMS19937_H
    13.6 +
    13.7 +#define POS1	122
    13.8 +#define SL1	18
    13.9 +#define SL2	1
   13.10 +#define SR1	11
   13.11 +#define SR2	1
   13.12 +#define MSK1	0xdfffffefU
   13.13 +#define MSK2	0xddfecb7fU
   13.14 +#define MSK3	0xbffaffffU
   13.15 +#define MSK4	0xbffffff6U
   13.16 +#define PARITY1	0x00000001U
   13.17 +#define PARITY2	0x00000000U
   13.18 +#define PARITY3	0x00000000U
   13.19 +#define PARITY4	0x13c9e684U
   13.20 +
   13.21 +
   13.22 +/* PARAMETERS FOR ALTIVEC */
   13.23 +#if defined(__APPLE__)	/* For OSX */
   13.24 +    #define ALTI_SL1	(vector unsigned int)(SL1, SL1, SL1, SL1)
   13.25 +    #define ALTI_SR1	(vector unsigned int)(SR1, SR1, SR1, SR1)
   13.26 +    #define ALTI_MSK	(vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
   13.27 +    #define ALTI_MSK64 \
   13.28 +	(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
   13.29 +    #define ALTI_SL2_PERM \
   13.30 +	(vector unsigned char)(1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8)
   13.31 +    #define ALTI_SL2_PERM64 \
   13.32 +	(vector unsigned char)(1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0)
   13.33 +    #define ALTI_SR2_PERM \
   13.34 +	(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
   13.35 +    #define ALTI_SR2_PERM64 \
   13.36 +	(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
   13.37 +#else	/* For OTHER OSs(Linux?) */
   13.38 +    #define ALTI_SL1	{SL1, SL1, SL1, SL1}
   13.39 +    #define ALTI_SR1	{SR1, SR1, SR1, SR1}
   13.40 +    #define ALTI_MSK	{MSK1, MSK2, MSK3, MSK4}
   13.41 +    #define ALTI_MSK64	{MSK2, MSK1, MSK4, MSK3}
   13.42 +    #define ALTI_SL2_PERM	{1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8}
   13.43 +    #define ALTI_SL2_PERM64	{1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0}
   13.44 +    #define ALTI_SR2_PERM	{7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
   13.45 +    #define ALTI_SR2_PERM64	{15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
   13.46 +#endif	/* For OSX */
   13.47 +#define IDSTR	"SFMT-19937:122-18-1-11-1:dfffffef-ddfecb7f-bffaffff-bffffff6"
   13.48 +
   13.49 +#endif /* SFMT_PARAMS19937_H */
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/SFMT/SFMT-params216091.h	Sat Mar 03 10:31:27 2012 -0600
    14.3 @@ -0,0 +1,46 @@
    14.4 +#ifndef SFMT_PARAMS216091_H
    14.5 +#define SFMT_PARAMS216091_H
    14.6 +
    14.7 +#define POS1	627
    14.8 +#define SL1	11
    14.9 +#define SL2	3
   14.10 +#define SR1	10
   14.11 +#define SR2	1
   14.12 +#define MSK1	0xbff7bff7U
   14.13 +#define MSK2	0xbfffffffU
   14.14 +#define MSK3	0xbffffa7fU
   14.15 +#define MSK4	0xffddfbfbU
   14.16 +#define PARITY1	0xf8000001U
   14.17 +#define PARITY2	0x89e80709U
   14.18 +#define PARITY3	0x3bd2b64bU
   14.19 +#define PARITY4	0x0c64b1e4U
   14.20 +
   14.21 +
   14.22 +/* PARAMETERS FOR ALTIVEC */
   14.23 +#if defined(__APPLE__)	/* For OSX */
   14.24 +    #define ALTI_SL1	(vector unsigned int)(SL1, SL1, SL1, SL1)
   14.25 +    #define ALTI_SR1	(vector unsigned int)(SR1, SR1, SR1, SR1)
   14.26 +    #define ALTI_MSK	(vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
   14.27 +    #define ALTI_MSK64 \
   14.28 +	(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
   14.29 +    #define ALTI_SL2_PERM \
   14.30 +	(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
   14.31 +    #define ALTI_SL2_PERM64 \
   14.32 +	(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
   14.33 +    #define ALTI_SR2_PERM \
   14.34 +	(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
   14.35 +    #define ALTI_SR2_PERM64 \
   14.36 +	(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
   14.37 +#else	/* For OTHER OSs(Linux?) */
   14.38 +    #define ALTI_SL1	{SL1, SL1, SL1, SL1}
   14.39 +    #define ALTI_SR1	{SR1, SR1, SR1, SR1}
   14.40 +    #define ALTI_MSK	{MSK1, MSK2, MSK3, MSK4}
   14.41 +    #define ALTI_MSK64	{MSK2, MSK1, MSK4, MSK3}
   14.42 +    #define ALTI_SL2_PERM	{3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
   14.43 +    #define ALTI_SL2_PERM64	{3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
   14.44 +    #define ALTI_SR2_PERM	{7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
   14.45 +    #define ALTI_SR2_PERM64	{15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
   14.46 +#endif	/* For OSX */
   14.47 +#define IDSTR	"SFMT-216091:627-11-3-10-1:bff7bff7-bfffffff-bffffa7f-ffddfbfb"
   14.48 +
   14.49 +#endif /* SFMT_PARAMS216091_H */
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/SFMT/SFMT-params2281.h	Sat Mar 03 10:31:27 2012 -0600
    15.3 @@ -0,0 +1,46 @@
    15.4 +#ifndef SFMT_PARAMS2281_H
    15.5 +#define SFMT_PARAMS2281_H
    15.6 +
    15.7 +#define POS1	12
    15.8 +#define SL1	19
    15.9 +#define SL2	1
   15.10 +#define SR1	5
   15.11 +#define SR2	1
   15.12 +#define MSK1	0xbff7ffbfU
   15.13 +#define MSK2	0xfdfffffeU
   15.14 +#define MSK3	0xf7ffef7fU
   15.15 +#define MSK4	0xf2f7cbbfU
   15.16 +#define PARITY1	0x00000001U
   15.17 +#define PARITY2	0x00000000U
   15.18 +#define PARITY3	0x00000000U
   15.19 +#define PARITY4	0x41dfa600U
   15.20 +
   15.21 +
   15.22 +/* PARAMETERS FOR ALTIVEC */
   15.23 +#if defined(__APPLE__)	/* For OSX */
   15.24 +    #define ALTI_SL1	(vector unsigned int)(SL1, SL1, SL1, SL1)
   15.25 +    #define ALTI_SR1	(vector unsigned int)(SR1, SR1, SR1, SR1)
   15.26 +    #define ALTI_MSK	(vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
   15.27 +    #define ALTI_MSK64 \
   15.28 +	(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
   15.29 +    #define ALTI_SL2_PERM \
   15.30 +	(vector unsigned char)(1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8)
   15.31 +    #define ALTI_SL2_PERM64 \
   15.32 +	(vector unsigned char)(1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0)
   15.33 +    #define ALTI_SR2_PERM \
   15.34 +	(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
   15.35 +    #define ALTI_SR2_PERM64 \
   15.36 +	(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
   15.37 +#else	/* For OTHER OSs(Linux?) */
   15.38 +    #define ALTI_SL1	{SL1, SL1, SL1, SL1}
   15.39 +    #define ALTI_SR1	{SR1, SR1, SR1, SR1}
   15.40 +    #define ALTI_MSK	{MSK1, MSK2, MSK3, MSK4}
   15.41 +    #define ALTI_MSK64	{MSK2, MSK1, MSK4, MSK3}
   15.42 +    #define ALTI_SL2_PERM	{1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8}
   15.43 +    #define ALTI_SL2_PERM64	{1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0}
   15.44 +    #define ALTI_SR2_PERM	{7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
   15.45 +    #define ALTI_SR2_PERM64	{15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
   15.46 +#endif	/* For OSX */
   15.47 +#define IDSTR	"SFMT-2281:12-19-1-5-1:bff7ffbf-fdfffffe-f7ffef7f-f2f7cbbf"
   15.48 +
   15.49 +#endif /* SFMT_PARAMS2281_H */
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/SFMT/SFMT-params4253.h	Sat Mar 03 10:31:27 2012 -0600
    16.3 @@ -0,0 +1,46 @@
    16.4 +#ifndef SFMT_PARAMS4253_H
    16.5 +#define SFMT_PARAMS4253_H
    16.6 +
    16.7 +#define POS1	17
    16.8 +#define SL1	20
    16.9 +#define SL2	1
   16.10 +#define SR1	7
   16.11 +#define SR2	1
   16.12 +#define MSK1	0x9f7bffffU
   16.13 +#define MSK2	0x9fffff5fU
   16.14 +#define MSK3	0x3efffffbU
   16.15 +#define MSK4	0xfffff7bbU
   16.16 +#define PARITY1	0xa8000001U
   16.17 +#define PARITY2	0xaf5390a3U
   16.18 +#define PARITY3	0xb740b3f8U
   16.19 +#define PARITY4	0x6c11486dU
   16.20 +
   16.21 +
   16.22 +/* PARAMETERS FOR ALTIVEC */
   16.23 +#if defined(__APPLE__)	/* For OSX */
   16.24 +    #define ALTI_SL1	(vector unsigned int)(SL1, SL1, SL1, SL1)
   16.25 +    #define ALTI_SR1	(vector unsigned int)(SR1, SR1, SR1, SR1)
   16.26 +    #define ALTI_MSK	(vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
   16.27 +    #define ALTI_MSK64 \
   16.28 +	(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
   16.29 +    #define ALTI_SL2_PERM \
   16.30 +	(vector unsigned char)(1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8)
   16.31 +    #define ALTI_SL2_PERM64 \
   16.32 +	(vector unsigned char)(1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0)
   16.33 +    #define ALTI_SR2_PERM \
   16.34 +	(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
   16.35 +    #define ALTI_SR2_PERM64 \
   16.36 +	(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
   16.37 +#else	/* For OTHER OSs(Linux?) */
   16.38 +    #define ALTI_SL1	{SL1, SL1, SL1, SL1}
   16.39 +    #define ALTI_SR1	{SR1, SR1, SR1, SR1}
   16.40 +    #define ALTI_MSK	{MSK1, MSK2, MSK3, MSK4}
   16.41 +    #define ALTI_MSK64	{MSK2, MSK1, MSK4, MSK3}
   16.42 +    #define ALTI_SL2_PERM	{1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8}
   16.43 +    #define ALTI_SL2_PERM64	{1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0}
   16.44 +    #define ALTI_SR2_PERM	{7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
   16.45 +    #define ALTI_SR2_PERM64	{15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
   16.46 +#endif	/* For OSX */
   16.47 +#define IDSTR	"SFMT-4253:17-20-1-7-1:9f7bffff-9fffff5f-3efffffb-fffff7bb"
   16.48 +
   16.49 +#endif /* SFMT_PARAMS4253_H */
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/SFMT/SFMT-params44497.h	Sat Mar 03 10:31:27 2012 -0600
    17.3 @@ -0,0 +1,46 @@
    17.4 +#ifndef SFMT_PARAMS44497_H
    17.5 +#define SFMT_PARAMS44497_H
    17.6 +
    17.7 +#define POS1	330
    17.8 +#define SL1	5
    17.9 +#define SL2	3
   17.10 +#define SR1	9
   17.11 +#define SR2	3
   17.12 +#define MSK1	0xeffffffbU
   17.13 +#define MSK2	0xdfbebfffU
   17.14 +#define MSK3	0xbfbf7befU
   17.15 +#define MSK4	0x9ffd7bffU
   17.16 +#define PARITY1	0x00000001U
   17.17 +#define PARITY2	0x00000000U
   17.18 +#define PARITY3	0xa3ac4000U
   17.19 +#define PARITY4	0xecc1327aU
   17.20 +
   17.21 +
   17.22 +/* PARAMETERS FOR ALTIVEC */
   17.23 +#if defined(__APPLE__)	/* For OSX */
   17.24 +    #define ALTI_SL1	(vector unsigned int)(SL1, SL1, SL1, SL1)
   17.25 +    #define ALTI_SR1	(vector unsigned int)(SR1, SR1, SR1, SR1)
   17.26 +    #define ALTI_MSK	(vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
   17.27 +    #define ALTI_MSK64 \
   17.28 +	(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
   17.29 +    #define ALTI_SL2_PERM \
   17.30 +	(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
   17.31 +    #define ALTI_SL2_PERM64 \
   17.32 +	(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
   17.33 +    #define ALTI_SR2_PERM \
   17.34 +	(vector unsigned char)(5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12)
   17.35 +    #define ALTI_SR2_PERM64 \
   17.36 +	(vector unsigned char)(13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12)
   17.37 +#else	/* For OTHER OSs(Linux?) */
   17.38 +    #define ALTI_SL1	{SL1, SL1, SL1, SL1}
   17.39 +    #define ALTI_SR1	{SR1, SR1, SR1, SR1}
   17.40 +    #define ALTI_MSK	{MSK1, MSK2, MSK3, MSK4}
   17.41 +    #define ALTI_MSK64	{MSK2, MSK1, MSK4, MSK3}
   17.42 +    #define ALTI_SL2_PERM	{3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
   17.43 +    #define ALTI_SL2_PERM64	{3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
   17.44 +    #define ALTI_SR2_PERM	{5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12}
   17.45 +    #define ALTI_SR2_PERM64	{13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12}
   17.46 +#endif	/* For OSX */
   17.47 +#define IDSTR	"SFMT-44497:330-5-3-9-3:effffffb-dfbebfff-bfbf7bef-9ffd7bff"
   17.48 +
   17.49 +#endif /* SFMT_PARAMS44497_H */
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/SFMT/SFMT-params607.h	Sat Mar 03 10:31:27 2012 -0600
    18.3 @@ -0,0 +1,46 @@
    18.4 +#ifndef SFMT_PARAMS607_H
    18.5 +#define SFMT_PARAMS607_H
    18.6 +
    18.7 +#define POS1	2
    18.8 +#define SL1	15
    18.9 +#define SL2	3
   18.10 +#define SR1	13
   18.11 +#define SR2	3
   18.12 +#define MSK1	0xfdff37ffU
   18.13 +#define MSK2	0xef7f3f7dU
   18.14 +#define MSK3	0xff777b7dU
   18.15 +#define MSK4	0x7ff7fb2fU
   18.16 +#define PARITY1	0x00000001U
   18.17 +#define PARITY2	0x00000000U
   18.18 +#define PARITY3	0x00000000U
   18.19 +#define PARITY4	0x5986f054U
   18.20 +
   18.21 +
   18.22 +/* PARAMETERS FOR ALTIVEC */
   18.23 +#if defined(__APPLE__)	/* For OSX */
   18.24 +    #define ALTI_SL1	(vector unsigned int)(SL1, SL1, SL1, SL1)
   18.25 +    #define ALTI_SR1	(vector unsigned int)(SR1, SR1, SR1, SR1)
   18.26 +    #define ALTI_MSK	(vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
   18.27 +    #define ALTI_MSK64 \
   18.28 +	(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
   18.29 +    #define ALTI_SL2_PERM \
   18.30 +	(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
   18.31 +    #define ALTI_SL2_PERM64 \
   18.32 +	(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
   18.33 +    #define ALTI_SR2_PERM \
   18.34 +	(vector unsigned char)(5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12)
   18.35 +    #define ALTI_SR2_PERM64 \
   18.36 +	(vector unsigned char)(13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12)
   18.37 +#else	/* For OTHER OSs(Linux?) */
   18.38 +    #define ALTI_SL1	{SL1, SL1, SL1, SL1}
   18.39 +    #define ALTI_SR1	{SR1, SR1, SR1, SR1}
   18.40 +    #define ALTI_MSK	{MSK1, MSK2, MSK3, MSK4}
   18.41 +    #define ALTI_MSK64	{MSK2, MSK1, MSK4, MSK3}
   18.42 +    #define ALTI_SL2_PERM	{3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
   18.43 +    #define ALTI_SL2_PERM64	{3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
   18.44 +    #define ALTI_SR2_PERM	{5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12}
   18.45 +    #define ALTI_SR2_PERM64	{13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12}
   18.46 +#endif	/* For OSX */
   18.47 +#define IDSTR	"SFMT-607:2-15-3-13-3:fdff37ff-ef7f3f7d-ff777b7d-7ff7fb2f"
   18.48 +
   18.49 +#endif /* SFMT_PARAMS607_H */
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/src/SFMT/SFMT-params86243.h	Sat Mar 03 10:31:27 2012 -0600
    19.3 @@ -0,0 +1,46 @@
    19.4 +#ifndef SFMT_PARAMS86243_H
    19.5 +#define SFMT_PARAMS86243_H
    19.6 +
    19.7 +#define POS1	366
    19.8 +#define SL1	6
    19.9 +#define SL2	7
   19.10 +#define SR1	19
   19.11 +#define SR2	1
   19.12 +#define MSK1	0xfdbffbffU
   19.13 +#define MSK2	0xbff7ff3fU
   19.14 +#define MSK3	0xfd77efffU
   19.15 +#define MSK4	0xbf9ff3ffU
   19.16 +#define PARITY1	0x00000001U
   19.17 +#define PARITY2	0x00000000U
   19.18 +#define PARITY3	0x00000000U
   19.19 +#define PARITY4	0xe9528d85U
   19.20 +
   19.21 +
   19.22 +/* PARAMETERS FOR ALTIVEC */
   19.23 +#if defined(__APPLE__)	/* For OSX */
   19.24 +    #define ALTI_SL1	(vector unsigned int)(SL1, SL1, SL1, SL1)
   19.25 +    #define ALTI_SR1	(vector unsigned int)(SR1, SR1, SR1, SR1)
   19.26 +    #define ALTI_MSK	(vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
   19.27 +    #define ALTI_MSK64 \
   19.28 +	(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
   19.29 +    #define ALTI_SL2_PERM \
   19.30 +	(vector unsigned char)(25,25,25,25,3,25,25,25,7,0,1,2,11,4,5,6)
   19.31 +    #define ALTI_SL2_PERM64 \
   19.32 +	(vector unsigned char)(7,25,25,25,25,25,25,25,15,0,1,2,3,4,5,6)
   19.33 +    #define ALTI_SR2_PERM \
   19.34 +	(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
   19.35 +    #define ALTI_SR2_PERM64 \
   19.36 +	(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
   19.37 +#else	/* For OTHER OSs(Linux?) */
   19.38 +    #define ALTI_SL1	{SL1, SL1, SL1, SL1}
   19.39 +    #define ALTI_SR1	{SR1, SR1, SR1, SR1}
   19.40 +    #define ALTI_MSK	{MSK1, MSK2, MSK3, MSK4}
   19.41 +    #define ALTI_MSK64	{MSK2, MSK1, MSK4, MSK3}
   19.42 +    #define ALTI_SL2_PERM	{25,25,25,25,3,25,25,25,7,0,1,2,11,4,5,6}
   19.43 +    #define ALTI_SL2_PERM64	{7,25,25,25,25,25,25,25,15,0,1,2,3,4,5,6}
   19.44 +    #define ALTI_SR2_PERM	{7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
   19.45 +    #define ALTI_SR2_PERM64	{15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
   19.46 +#endif	/* For OSX */
   19.47 +#define IDSTR	"SFMT-86243:366-6-7-19-1:fdbffbff-bff7ff3f-fd77efff-bf9ff3ff"
   19.48 +
   19.49 +#endif /* SFMT_PARAMS86243_H */
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/SFMT/SFMT-sse2.h	Sat Mar 03 10:31:27 2012 -0600
    20.3 @@ -0,0 +1,121 @@
    20.4 +/** 
    20.5 + * @file  SFMT-sse2.h
    20.6 + * @brief SIMD oriented Fast Mersenne Twister(SFMT) for Intel SSE2
    20.7 + *
    20.8 + * @author Mutsuo Saito (Hiroshima University)
    20.9 + * @author Makoto Matsumoto (Hiroshima University)
   20.10 + *
   20.11 + * @note We assume LITTLE ENDIAN in this file
   20.12 + *
   20.13 + * Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
   20.14 + * University. All rights reserved.
   20.15 + *
   20.16 + * The new BSD License is applied to this software, see LICENSE.txt
   20.17 + */
   20.18 +
   20.19 +#ifndef SFMT_SSE2_H
   20.20 +#define SFMT_SSE2_H
   20.21 +
   20.22 +PRE_ALWAYS static __m128i mm_recursion(__m128i *a, __m128i *b, __m128i c,
   20.23 +				   __m128i d, __m128i mask) ALWAYSINLINE;
   20.24 +
   20.25 +/**
   20.26 + * This function represents the recursion formula.
   20.27 + * @param a a 128-bit part of the interal state array
   20.28 + * @param b a 128-bit part of the interal state array
   20.29 + * @param c a 128-bit part of the interal state array
   20.30 + * @param d a 128-bit part of the interal state array
   20.31 + * @param mask 128-bit mask
   20.32 + * @return output
   20.33 + */
   20.34 +PRE_ALWAYS static __m128i mm_recursion(__m128i *a, __m128i *b, 
   20.35 +				   __m128i c, __m128i d, __m128i mask) {
   20.36 +    __m128i v, x, y, z;
   20.37 +    
   20.38 +    x = _mm_load_si128(a);
   20.39 +    y = _mm_srli_epi32(*b, SR1);
   20.40 +    z = _mm_srli_si128(c, SR2);
   20.41 +    v = _mm_slli_epi32(d, SL1);
   20.42 +    z = _mm_xor_si128(z, x);
   20.43 +    z = _mm_xor_si128(z, v);
   20.44 +    x = _mm_slli_si128(x, SL2);
   20.45 +    y = _mm_and_si128(y, mask);
   20.46 +    z = _mm_xor_si128(z, x);
   20.47 +    z = _mm_xor_si128(z, y);
   20.48 +    return z;
   20.49 +}
   20.50 +
   20.51 +/**
   20.52 + * This function fills the internal state array with pseudorandom
   20.53 + * integers.
   20.54 + */
   20.55 +inline static void gen_rand_all(void) {
   20.56 +    int i;
   20.57 +    __m128i r, r1, r2, mask;
   20.58 +    mask = _mm_set_epi32(MSK4, MSK3, MSK2, MSK1);
   20.59 +
   20.60 +    r1 = _mm_load_si128(&sfmt[N - 2].si);
   20.61 +    r2 = _mm_load_si128(&sfmt[N - 1].si);
   20.62 +    for (i = 0; i < N - POS1; i++) {
   20.63 +	r = mm_recursion(&sfmt[i].si, &sfmt[i + POS1].si, r1, r2, mask);
   20.64 +	_mm_store_si128(&sfmt[i].si, r);
   20.65 +	r1 = r2;
   20.66 +	r2 = r;
   20.67 +    }
   20.68 +    for (; i < N; i++) {
   20.69 +	r = mm_recursion(&sfmt[i].si, &sfmt[i + POS1 - N].si, r1, r2, mask);
   20.70 +	_mm_store_si128(&sfmt[i].si, r);
   20.71 +	r1 = r2;
   20.72 +	r2 = r;
   20.73 +    }
   20.74 +}
   20.75 +
   20.76 +/**
   20.77 + * This function fills the user-specified array with pseudorandom
   20.78 + * integers.
   20.79 + *
   20.80 + * @param array an 128-bit array to be filled by pseudorandom numbers.  
   20.81 + * @param size number of 128-bit pesudorandom numbers to be generated.
   20.82 + */
   20.83 +inline static void gen_rand_array(w128_t *array, int size) {
   20.84 +    int i, j;
   20.85 +    __m128i r, r1, r2, mask;
   20.86 +    mask = _mm_set_epi32(MSK4, MSK3, MSK2, MSK1);
   20.87 +
   20.88 +    r1 = _mm_load_si128(&sfmt[N - 2].si);
   20.89 +    r2 = _mm_load_si128(&sfmt[N - 1].si);
   20.90 +    for (i = 0; i < N - POS1; i++) {
   20.91 +	r = mm_recursion(&sfmt[i].si, &sfmt[i + POS1].si, r1, r2, mask);
   20.92 +	_mm_store_si128(&array[i].si, r);
   20.93 +	r1 = r2;
   20.94 +	r2 = r;
   20.95 +    }
   20.96 +    for (; i < N; i++) {
   20.97 +	r = mm_recursion(&sfmt[i].si, &array[i + POS1 - N].si, r1, r2, mask);
   20.98 +	_mm_store_si128(&array[i].si, r);
   20.99 +	r1 = r2;
  20.100 +	r2 = r;
  20.101 +    }
  20.102 +    /* main loop */
  20.103 +    for (; i < size - N; i++) {
  20.104 +	r = mm_recursion(&array[i - N].si, &array[i + POS1 - N].si, r1, r2,
  20.105 +			 mask);
  20.106 +	_mm_store_si128(&array[i].si, r);
  20.107 +	r1 = r2;
  20.108 +	r2 = r;
  20.109 +    }
  20.110 +    for (j = 0; j < 2 * N - size; j++) {
  20.111 +	r = _mm_load_si128(&array[j + size - N].si);
  20.112 +	_mm_store_si128(&sfmt[j].si, r);
  20.113 +    }
  20.114 +    for (; i < size; i++) {
  20.115 +	r = mm_recursion(&array[i - N].si, &array[i + POS1 - N].si, r1, r2,
  20.116 +			 mask);
  20.117 +	_mm_store_si128(&array[i].si, r);
  20.118 +	_mm_store_si128(&sfmt[j++].si, r);
  20.119 +	r1 = r2;
  20.120 +	r2 = r;
  20.121 +    }
  20.122 +}
  20.123 +
  20.124 +#endif
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/SFMT/SFMT.c	Sat Mar 03 10:31:27 2012 -0600
    21.3 @@ -0,0 +1,620 @@
    21.4 +/** 
    21.5 + * @file  SFMT.c
    21.6 + * @brief SIMD oriented Fast Mersenne Twister(SFMT)
    21.7 + *
    21.8 + * @author Mutsuo Saito (Hiroshima University)
    21.9 + * @author Makoto Matsumoto (Hiroshima University)
   21.10 + *
   21.11 + * Copyright (C) 2006,2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
   21.12 + * University. All rights reserved.
   21.13 + *
   21.14 + * The new BSD License is applied to this software, see LICENSE.txt
   21.15 + */
   21.16 +#include <string.h>
   21.17 +#include <assert.h>
   21.18 +#include "SFMT.h"
   21.19 +#include "SFMT-params.h"
   21.20 +
   21.21 +#if defined(__BIG_ENDIAN__) && !defined(__amd64) && !defined(BIG_ENDIAN64)
   21.22 +#define BIG_ENDIAN64 1
   21.23 +#endif
   21.24 +#if defined(HAVE_ALTIVEC) && !defined(BIG_ENDIAN64)
   21.25 +#define BIG_ENDIAN64 1
   21.26 +#endif
   21.27 +#if defined(ONLY64) && !defined(BIG_ENDIAN64)
   21.28 +  #if defined(__GNUC__)
   21.29 +    #error "-DONLY64 must be specified with -DBIG_ENDIAN64"
   21.30 +  #endif
   21.31 +#undef ONLY64
   21.32 +#endif
   21.33 +/*------------------------------------------------------
   21.34 +  128-bit SIMD data type for Altivec, SSE2 or standard C
   21.35 +  ------------------------------------------------------*/
   21.36 +#if defined(HAVE_ALTIVEC)
   21.37 +  #if !defined(__APPLE__)
   21.38 +    #include <altivec.h>
   21.39 +  #endif
   21.40 +/** 128-bit data structure */
   21.41 +union W128_T {
   21.42 +    vector unsigned int s;
   21.43 +    uint32_t u[4];
   21.44 +};
   21.45 +/** 128-bit data type */
   21.46 +typedef union W128_T w128_t;
   21.47 +
   21.48 +#elif defined(HAVE_SSE2)
   21.49 +  #include <emmintrin.h>
   21.50 +
   21.51 +/** 128-bit data structure */
   21.52 +union W128_T {
   21.53 +    __m128i si;
   21.54 +    uint32_t u[4];
   21.55 +};
   21.56 +/** 128-bit data type */
   21.57 +typedef union W128_T w128_t;
   21.58 +
   21.59 +#else
   21.60 +
   21.61 +/** 128-bit data structure */
   21.62 +struct W128_T {
   21.63 +    uint32_t u[4];
   21.64 +};
   21.65 +/** 128-bit data type */
   21.66 +typedef struct W128_T w128_t;
   21.67 +
   21.68 +#endif
   21.69 +
   21.70 +/*--------------------------------------
   21.71 +  FILE GLOBAL VARIABLES
   21.72 +  internal state, index counter and flag 
   21.73 +  --------------------------------------*/
   21.74 +/** the 128-bit internal state array */
   21.75 +static w128_t sfmt[N];
   21.76 +/** the 32bit integer pointer to the 128-bit internal state array */
   21.77 +static uint32_t *psfmt32 = &sfmt[0].u[0];
   21.78 +#if !defined(BIG_ENDIAN64) || defined(ONLY64)
   21.79 +/** the 64bit integer pointer to the 128-bit internal state array */
   21.80 +static uint64_t *psfmt64 = (uint64_t *)&sfmt[0].u[0];
   21.81 +#endif
   21.82 +/** index counter to the 32-bit internal state array */
   21.83 +static int idx;
   21.84 +/** a flag: it is 0 if and only if the internal state is not yet
   21.85 + * initialized. */
   21.86 +static int initialized = 0;
   21.87 +/** a parity check vector which certificate the period of 2^{MEXP} */
   21.88 +static uint32_t parity[4] = {PARITY1, PARITY2, PARITY3, PARITY4};
   21.89 +
   21.90 +/*----------------
   21.91 +  STATIC FUNCTIONS
   21.92 +  ----------------*/
   21.93 +inline static int idxof(int i);
   21.94 +inline static void rshift128(w128_t *out,  w128_t const *in, int shift);
   21.95 +inline static void lshift128(w128_t *out,  w128_t const *in, int shift);
   21.96 +inline static void gen_rand_all(void);
   21.97 +inline static void gen_rand_array(w128_t *array, int size);
   21.98 +inline static uint32_t func1(uint32_t x);
   21.99 +inline static uint32_t func2(uint32_t x);
  21.100 +static void period_certification(void);
  21.101 +#if defined(BIG_ENDIAN64) && !defined(ONLY64)
  21.102 +inline static void swap(w128_t *array, int size);
  21.103 +#endif
  21.104 +
  21.105 +#if defined(HAVE_ALTIVEC)
  21.106 +  #include "SFMT-alti.h"
  21.107 +#elif defined(HAVE_SSE2)
  21.108 +  #include "SFMT-sse2.h"
  21.109 +#endif
  21.110 +
  21.111 +/**
  21.112 + * This function simulate a 64-bit index of LITTLE ENDIAN 
  21.113 + * in BIG ENDIAN machine.
  21.114 + */
  21.115 +#ifdef ONLY64
  21.116 +inline static int idxof(int i) {
  21.117 +    return i ^ 1;
  21.118 +}
  21.119 +#else
  21.120 +inline static int idxof(int i) {
  21.121 +    return i;
  21.122 +}
  21.123 +#endif
  21.124 +/**
  21.125 + * This function simulates SIMD 128-bit right shift by the standard C.
  21.126 + * The 128-bit integer given in in is shifted by (shift * 8) bits.
  21.127 + * This function simulates the LITTLE ENDIAN SIMD.
  21.128 + * @param out the output of this function
  21.129 + * @param in the 128-bit data to be shifted
  21.130 + * @param shift the shift value
  21.131 + */
  21.132 +#ifdef ONLY64
  21.133 +inline static void rshift128(w128_t *out, w128_t const *in, int shift) {
  21.134 +    uint64_t th, tl, oh, ol;
  21.135 +
  21.136 +    th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
  21.137 +    tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
  21.138 +
  21.139 +    oh = th >> (shift * 8);
  21.140 +    ol = tl >> (shift * 8);
  21.141 +    ol |= th << (64 - shift * 8);
  21.142 +    out->u[0] = (uint32_t)(ol >> 32);
  21.143 +    out->u[1] = (uint32_t)(ol & 0xffffffff);
  21.144 +    out->u[2] = (uint32_t)(oh >> 32);
  21.145 +    out->u[3] = (uint32_t)(oh & 0xffffffff);
  21.146 +}
  21.147 +#else
  21.148 +inline static void rshift128(w128_t *out, w128_t const *in, int shift) {
  21.149 +    uint64_t th, tl, oh, ol;
  21.150 +
  21.151 +    th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
  21.152 +    tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
  21.153 +
  21.154 +    oh = th >> (shift * 8);
  21.155 +    ol = tl >> (shift * 8);
  21.156 +    ol |= th << (64 - shift * 8);
  21.157 +    out->u[1] = (uint32_t)(ol >> 32);
  21.158 +    out->u[0] = (uint32_t)(ol & 0xffffffff);
  21.159 +    out->u[3] = (uint32_t)(oh >> 32);
  21.160 +    out->u[2] = (uint32_t)(oh & 0xffffffff);
  21.161 +}
  21.162 +#endif
  21.163 +/**
  21.164 + * This function simulates SIMD 128-bit left shift by the standard C.
  21.165 + * The 128-bit integer given in in is shifted by (shift * 8) bits.
  21.166 + * This function simulates the LITTLE ENDIAN SIMD.
  21.167 + * @param out the output of this function
  21.168 + * @param in the 128-bit data to be shifted
  21.169 + * @param shift the shift value
  21.170 + */
  21.171 +#ifdef ONLY64
  21.172 +inline static void lshift128(w128_t *out, w128_t const *in, int shift) {
  21.173 +    uint64_t th, tl, oh, ol;
  21.174 +
  21.175 +    th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
  21.176 +    tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
  21.177 +
  21.178 +    oh = th << (shift * 8);
  21.179 +    ol = tl << (shift * 8);
  21.180 +    oh |= tl >> (64 - shift * 8);
  21.181 +    out->u[0] = (uint32_t)(ol >> 32);
  21.182 +    out->u[1] = (uint32_t)(ol & 0xffffffff);
  21.183 +    out->u[2] = (uint32_t)(oh >> 32);
  21.184 +    out->u[3] = (uint32_t)(oh & 0xffffffff);
  21.185 +}
  21.186 +#else
  21.187 +inline static void lshift128(w128_t *out, w128_t const *in, int shift) {
  21.188 +    uint64_t th, tl, oh, ol;
  21.189 +
  21.190 +    th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
  21.191 +    tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
  21.192 +
  21.193 +    oh = th << (shift * 8);
  21.194 +    ol = tl << (shift * 8);
  21.195 +    oh |= tl >> (64 - shift * 8);
  21.196 +    out->u[1] = (uint32_t)(ol >> 32);
  21.197 +    out->u[0] = (uint32_t)(ol & 0xffffffff);
  21.198 +    out->u[3] = (uint32_t)(oh >> 32);
  21.199 +    out->u[2] = (uint32_t)(oh & 0xffffffff);
  21.200 +}
  21.201 +#endif
  21.202 +
  21.203 +/**
  21.204 + * This function represents the recursion formula.
  21.205 + * @param r output
  21.206 + * @param a a 128-bit part of the internal state array
  21.207 + * @param b a 128-bit part of the internal state array
  21.208 + * @param c a 128-bit part of the internal state array
  21.209 + * @param d a 128-bit part of the internal state array
  21.210 + */
  21.211 +#if (!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
  21.212 +#ifdef ONLY64
  21.213 +inline static void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c,
  21.214 +				w128_t *d) {
  21.215 +    w128_t x;
  21.216 +    w128_t y;
  21.217 +
  21.218 +    lshift128(&x, a, SL2);
  21.219 +    rshift128(&y, c, SR2);
  21.220 +    r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK2) ^ y.u[0] 
  21.221 +	^ (d->u[0] << SL1);
  21.222 +    r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK1) ^ y.u[1] 
  21.223 +	^ (d->u[1] << SL1);
  21.224 +    r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK4) ^ y.u[2] 
  21.225 +	^ (d->u[2] << SL1);
  21.226 +    r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK3) ^ y.u[3] 
  21.227 +	^ (d->u[3] << SL1);
  21.228 +}
  21.229 +#else
  21.230 +inline static void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c,
  21.231 +				w128_t *d) {
  21.232 +    w128_t x;
  21.233 +    w128_t y;
  21.234 +
  21.235 +    lshift128(&x, a, SL2);
  21.236 +    rshift128(&y, c, SR2);
  21.237 +    r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK1) ^ y.u[0] 
  21.238 +	^ (d->u[0] << SL1);
  21.239 +    r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK2) ^ y.u[1] 
  21.240 +	^ (d->u[1] << SL1);
  21.241 +    r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK3) ^ y.u[2] 
  21.242 +	^ (d->u[2] << SL1);
  21.243 +    r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK4) ^ y.u[3] 
  21.244 +	^ (d->u[3] << SL1);
  21.245 +}
  21.246 +#endif
  21.247 +#endif
  21.248 +
  21.249 +#if (!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
  21.250 +/**
  21.251 + * This function fills the internal state array with pseudorandom
  21.252 + * integers.
  21.253 + */
  21.254 +inline static void gen_rand_all(void) {
  21.255 +    int i;
  21.256 +    w128_t *r1, *r2;
  21.257 +
  21.258 +    r1 = &sfmt[N - 2];
  21.259 +    r2 = &sfmt[N - 1];
  21.260 +    for (i = 0; i < N - POS1; i++) {
  21.261 +	do_recursion(&sfmt[i], &sfmt[i], &sfmt[i + POS1], r1, r2);
  21.262 +	r1 = r2;
  21.263 +	r2 = &sfmt[i];
  21.264 +    }
  21.265 +    for (; i < N; i++) {
  21.266 +	do_recursion(&sfmt[i], &sfmt[i], &sfmt[i + POS1 - N], r1, r2);
  21.267 +	r1 = r2;
  21.268 +	r2 = &sfmt[i];
  21.269 +    }
  21.270 +}
  21.271 +
  21.272 +/**
  21.273 + * This function fills the user-specified array with pseudorandom
  21.274 + * integers.
  21.275 + *
  21.276 + * @param array an 128-bit array to be filled by pseudorandom numbers.  
  21.277 + * @param size number of 128-bit pseudorandom numbers to be generated.
  21.278 + */
  21.279 +inline static void gen_rand_array(w128_t *array, int size) {
  21.280 +    int i, j;
  21.281 +    w128_t *r1, *r2;
  21.282 +
  21.283 +    r1 = &sfmt[N - 2];
  21.284 +    r2 = &sfmt[N - 1];
  21.285 +    for (i = 0; i < N - POS1; i++) {
  21.286 +	do_recursion(&array[i], &sfmt[i], &sfmt[i + POS1], r1, r2);
  21.287 +	r1 = r2;
  21.288 +	r2 = &array[i];
  21.289 +    }
  21.290 +    for (; i < N; i++) {
  21.291 +	do_recursion(&array[i], &sfmt[i], &array[i + POS1 - N], r1, r2);
  21.292 +	r1 = r2;
  21.293 +	r2 = &array[i];
  21.294 +    }
  21.295 +    for (; i < size - N; i++) {
  21.296 +	do_recursion(&array[i], &array[i - N], &array[i + POS1 - N], r1, r2);
  21.297 +	r1 = r2;
  21.298 +	r2 = &array[i];
  21.299 +    }
  21.300 +    for (j = 0; j < 2 * N - size; j++) {
  21.301 +	sfmt[j] = array[j + size - N];
  21.302 +    }
  21.303 +    for (; i < size; i++, j++) {
  21.304 +	do_recursion(&array[i], &array[i - N], &array[i + POS1 - N], r1, r2);
  21.305 +	r1 = r2;
  21.306 +	r2 = &array[i];
  21.307 +	sfmt[j] = array[i];
  21.308 +    }
  21.309 +}
  21.310 +#endif
  21.311 +
  21.312 +#if defined(BIG_ENDIAN64) && !defined(ONLY64) && !defined(HAVE_ALTIVEC)
  21.313 +inline static void swap(w128_t *array, int size) {
  21.314 +    int i;
  21.315 +    uint32_t x, y;
  21.316 +
  21.317 +    for (i = 0; i < size; i++) {
  21.318 +	x = array[i].u[0];
  21.319 +	y = array[i].u[2];
  21.320 +	array[i].u[0] = array[i].u[1];
  21.321 +	array[i].u[2] = array[i].u[3];
  21.322 +	array[i].u[1] = x;
  21.323 +	array[i].u[3] = y;
  21.324 +    }
  21.325 +}
  21.326 +#endif
  21.327 +/**
  21.328 + * This function represents a function used in the initialization
  21.329 + * by init_by_array
  21.330 + * @param x 32-bit integer
  21.331 + * @return 32-bit integer
  21.332 + */
  21.333 +static uint32_t func1(uint32_t x) {
  21.334 +    return (x ^ (x >> 27)) * (uint32_t)1664525UL;
  21.335 +}
  21.336 +
  21.337 +/**
  21.338 + * This function represents a function used in the initialization
  21.339 + * by init_by_array
  21.340 + * @param x 32-bit integer
  21.341 + * @return 32-bit integer
  21.342 + */
  21.343 +static uint32_t func2(uint32_t x) {
  21.344 +    return (x ^ (x >> 27)) * (uint32_t)1566083941UL;
  21.345 +}
  21.346 +
  21.347 +/**
  21.348 + * This function certificate the period of 2^{MEXP}
  21.349 + */
  21.350 +static void period_certification(void) {
  21.351 +    int inner = 0;
  21.352 +    int i, j;
  21.353 +    uint32_t work;
  21.354 +
  21.355 +    for (i = 0; i < 4; i++)
  21.356 +	inner ^= psfmt32[idxof(i)] & parity[i];
  21.357 +    for (i = 16; i > 0; i >>= 1)
  21.358 +	inner ^= inner >> i;
  21.359 +    inner &= 1;
  21.360 +    /* check OK */
  21.361 +    if (inner == 1) {
  21.362 +	return;
  21.363 +    }
  21.364 +    /* check NG, and modification */
  21.365 +    for (i = 0; i < 4; i++) {
  21.366 +	work = 1;
  21.367 +	for (j = 0; j < 32; j++) {
  21.368 +	    if ((work & parity[i]) != 0) {
  21.369 +		psfmt32[idxof(i)] ^= work;
  21.370 +		return;
  21.371 +	    }
  21.372 +	    work = work << 1;
  21.373 +	}
  21.374 +    }
  21.375 +}
  21.376 +
  21.377 +/*----------------
  21.378 +  PUBLIC FUNCTIONS
  21.379 +  ----------------*/
  21.380 +/**
  21.381 + * This function returns the identification string.
  21.382 + * The string shows the word size, the Mersenne exponent,
  21.383 + * and all parameters of this generator.
  21.384 + */
  21.385 +const char *get_idstring(void) {
  21.386 +    return IDSTR;
  21.387 +}
  21.388 +
  21.389 +/**
  21.390 + * This function returns the minimum size of array used for \b
  21.391 + * fill_array32() function.
  21.392 + * @return minimum size of array used for fill_array32() function.
  21.393 + */
  21.394 +int get_min_array_size32(void) {
  21.395 +    return N32;
  21.396 +}
  21.397 +
  21.398 +/**
  21.399 + * This function returns the minimum size of array used for \b
  21.400 + * fill_array64() function.
  21.401 + * @return minimum size of array used for fill_array64() function.
  21.402 + */
  21.403 +int get_min_array_size64(void) {
  21.404 +    return N64;
  21.405 +}
  21.406 +
  21.407 +#ifndef ONLY64
  21.408 +/**
  21.409 + * This function generates and returns 32-bit pseudorandom number.
  21.410 + * init_gen_rand or init_by_array must be called before this function.
  21.411 + * @return 32-bit pseudorandom number
  21.412 + */
  21.413 +uint32_t gen_rand32(void) {
  21.414 +    uint32_t r;
  21.415 +
  21.416 +    assert(initialized);
  21.417 +    if (idx >= N32) {
  21.418 +	gen_rand_all();
  21.419 +	idx = 0;
  21.420 +    }
  21.421 +    r = psfmt32[idx++];
  21.422 +    return r;
  21.423 +}
  21.424 +#endif
  21.425 +/**
  21.426 + * This function generates and returns 64-bit pseudorandom number.
  21.427 + * init_gen_rand or init_by_array must be called before this function.
  21.428 + * The function gen_rand64 should not be called after gen_rand32,
  21.429 + * unless an initialization is again executed. 
  21.430 + * @return 64-bit pseudorandom number
  21.431 + */
  21.432 +uint64_t gen_rand64(void) {
  21.433 +#if defined(BIG_ENDIAN64) && !defined(ONLY64)
  21.434 +    uint32_t r1, r2;
  21.435 +#else
  21.436 +    uint64_t r;
  21.437 +#endif
  21.438 +
  21.439 +    assert(initialized);
  21.440 +    assert(idx % 2 == 0);
  21.441 +
  21.442 +    if (idx >= N32) {
  21.443 +	gen_rand_all();
  21.444 +	idx = 0;
  21.445 +    }
  21.446 +#if defined(BIG_ENDIAN64) && !defined(ONLY64)
  21.447 +    r1 = psfmt32[idx];
  21.448 +    r2 = psfmt32[idx + 1];
  21.449 +    idx += 2;
  21.450 +    return ((uint64_t)r2 << 32) | r1;
  21.451 +#else
  21.452 +    r = psfmt64[idx / 2];
  21.453 +    idx += 2;
  21.454 +    return r;
  21.455 +#endif
  21.456 +}
  21.457 +
  21.458 +#ifndef ONLY64
  21.459 +/**
  21.460 + * This function generates pseudorandom 32-bit integers in the
  21.461 + * specified array[] by one call. The number of pseudorandom integers
  21.462 + * is specified by the argument size, which must be at least 624 and a
  21.463 + * multiple of four.  The generation by this function is much faster
  21.464 + * than the following gen_rand function.
  21.465 + *
  21.466 + * For initialization, init_gen_rand or init_by_array must be called
  21.467 + * before the first call of this function. This function can not be
  21.468 + * used after calling gen_rand function, without initialization.
  21.469 + *
  21.470 + * @param array an array where pseudorandom 32-bit integers are filled
  21.471 + * by this function.  The pointer to the array must be \b "aligned"
  21.472 + * (namely, must be a multiple of 16) in the SIMD version, since it
  21.473 + * refers to the address of a 128-bit integer.  In the standard C
  21.474 + * version, the pointer is arbitrary.
  21.475 + *
  21.476 + * @param size the number of 32-bit pseudorandom integers to be
  21.477 + * generated.  size must be a multiple of 4, and greater than or equal
  21.478 + * to (MEXP / 128 + 1) * 4.
  21.479 + *
  21.480 + * @note \b memalign or \b posix_memalign is available to get aligned
  21.481 + * memory. Mac OSX doesn't have these functions, but \b malloc of OSX
  21.482 + * returns the pointer to the aligned memory block.
  21.483 + */
  21.484 +void fill_array32(uint32_t *array, int size) {
  21.485 +    assert(initialized);
  21.486 +    assert(idx == N32);
  21.487 +    assert(size % 4 == 0);
  21.488 +    assert(size >= N32);
  21.489 +
  21.490 +    gen_rand_array((w128_t *)array, size / 4);
  21.491 +    idx = N32;
  21.492 +}
  21.493 +#endif
  21.494 +
  21.495 +/**
  21.496 + * This function generates pseudorandom 64-bit integers in the
  21.497 + * specified array[] by one call. The number of pseudorandom integers
  21.498 + * is specified by the argument size, which must be at least 312 and a
  21.499 + * multiple of two.  The generation by this function is much faster
  21.500 + * than the following gen_rand function.
  21.501 + *
  21.502 + * For initialization, init_gen_rand or init_by_array must be called
  21.503 + * before the first call of this function. This function can not be
  21.504 + * used after calling gen_rand function, without initialization.
  21.505 + *
  21.506 + * @param array an array where pseudorandom 64-bit integers are filled
  21.507 + * by this function.  The pointer to the array must be "aligned"
  21.508 + * (namely, must be a multiple of 16) in the SIMD version, since it
  21.509 + * refers to the address of a 128-bit integer.  In the standard C
  21.510 + * version, the pointer is arbitrary.
  21.511 + *
  21.512 + * @param size the number of 64-bit pseudorandom integers to be
  21.513 + * generated.  size must be a multiple of 2, and greater than or equal
  21.514 + * to (MEXP / 128 + 1) * 2
  21.515 + *
  21.516 + * @note \b memalign or \b posix_memalign is available to get aligned
  21.517 + * memory. Mac OSX doesn't have these functions, but \b malloc of OSX
  21.518 + * returns the pointer to the aligned memory block.
  21.519 + */
  21.520 +void fill_array64(uint64_t *array, int size) {
  21.521 +    assert(initialized);
  21.522 +    assert(idx == N32);
  21.523 +    assert(size % 2 == 0);
  21.524 +    assert(size >= N64);
  21.525 +
  21.526 +    gen_rand_array((w128_t *)array, size / 2);
  21.527 +    idx = N32;
  21.528 +
  21.529 +#if defined(BIG_ENDIAN64) && !defined(ONLY64)
  21.530 +    swap((w128_t *)array, size /2);
  21.531 +#endif
  21.532 +}
  21.533 +
  21.534 +/**
  21.535 + * This function initializes the internal state array with a 32-bit
  21.536 + * integer seed.
  21.537 + *
  21.538 + * @param seed a 32-bit integer used as the seed.
  21.539 + */
  21.540 +void init_gen_rand(uint32_t seed) {
  21.541 +    int i;
  21.542 +
  21.543 +    psfmt32[idxof(0)] = seed;
  21.544 +    for (i = 1; i < N32; i++) {
  21.545 +	psfmt32[idxof(i)] = 1812433253UL * (psfmt32[idxof(i - 1)] 
  21.546 +					    ^ (psfmt32[idxof(i - 1)] >> 30))
  21.547 +	    + i;
  21.548 +    }
  21.549 +    idx = N32;
  21.550 +    period_certification();
  21.551 +    initialized = 1;
  21.552 +}
  21.553 +
  21.554 +/**
  21.555 + * This function initializes the internal state array,
  21.556 + * with an array of 32-bit integers used as the seeds
  21.557 + * @param init_key the array of 32-bit integers, used as a seed.
  21.558 + * @param key_length the length of init_key.
  21.559 + */
  21.560 +void init_by_array(uint32_t *init_key, int key_length) {
  21.561 +    int i, j, count;
  21.562 +    uint32_t r;
  21.563 +    int lag;
  21.564 +    int mid;
  21.565 +    int size = N * 4;
  21.566 +
  21.567 +    if (size >= 623) {
  21.568 +	lag = 11;
  21.569 +    } else if (size >= 68) {
  21.570 +	lag = 7;
  21.571 +    } else if (size >= 39) {
  21.572 +	lag = 5;
  21.573 +    } else {
  21.574 +	lag = 3;
  21.575 +    }
  21.576 +    mid = (size - lag) / 2;
  21.577 +
  21.578 +    memset(sfmt, 0x8b, sizeof(sfmt));
  21.579 +    if (key_length + 1 > N32) {
  21.580 +	count = key_length + 1;
  21.581 +    } else {
  21.582 +	count = N32;
  21.583 +    }
  21.584 +    r = func1(psfmt32[idxof(0)] ^ psfmt32[idxof(mid)] 
  21.585 +	      ^ psfmt32[idxof(N32 - 1)]);
  21.586 +    psfmt32[idxof(mid)] += r;
  21.587 +    r += key_length;
  21.588 +    psfmt32[idxof(mid + lag)] += r;
  21.589 +    psfmt32[idxof(0)] = r;
  21.590 +
  21.591 +    count--;
  21.592 +    for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
  21.593 +	r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)] 
  21.594 +		  ^ psfmt32[idxof((i + N32 - 1) % N32)]);
  21.595 +	psfmt32[idxof((i + mid) % N32)] += r;
  21.596 +	r += init_key[j] + i;
  21.597 +	psfmt32[idxof((i + mid + lag) % N32)] += r;
  21.598 +	psfmt32[idxof(i)] = r;
  21.599 +	i = (i + 1) % N32;
  21.600 +    }
  21.601 +    for (; j < count; j++) {
  21.602 +	r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)] 
  21.603 +		  ^ psfmt32[idxof((i + N32 - 1) % N32)]);
  21.604 +	psfmt32[idxof((i + mid) % N32)] += r;
  21.605 +	r += i;
  21.606 +	psfmt32[idxof((i + mid + lag) % N32)] += r;
  21.607 +	psfmt32[idxof(i)] = r;
  21.608 +	i = (i + 1) % N32;
  21.609 +    }
  21.610 +    for (j = 0; j < N32; j++) {
  21.611 +	r = func2(psfmt32[idxof(i)] + psfmt32[idxof((i + mid) % N32)] 
  21.612 +		  + psfmt32[idxof((i + N32 - 1) % N32)]);
  21.613 +	psfmt32[idxof((i + mid) % N32)] ^= r;
  21.614 +	r -= i;
  21.615 +	psfmt32[idxof((i + mid + lag) % N32)] ^= r;
  21.616 +	psfmt32[idxof(i)] = r;
  21.617 +	i = (i + 1) % N32;
  21.618 +    }
  21.619 +
  21.620 +    idx = N32;
  21.621 +    period_certification();
  21.622 +    initialized = 1;
  21.623 +}
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/src/SFMT/SFMT.h	Sat Mar 03 10:31:27 2012 -0600
    22.3 @@ -0,0 +1,165 @@
    22.4 +/** 
    22.5 + * @file SFMT.h 
    22.6 + *
    22.7 + * @brief SIMD oriented Fast Mersenne Twister(SFMT) pseudorandom
    22.8 + * number generator
    22.9 + *
   22.10 + * @author Mutsuo Saito (Hiroshima University)
   22.11 + * @author Makoto Matsumoto (Hiroshima University)
   22.12 + *
   22.13 + * Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
   22.14 + * University. All rights reserved.
   22.15 + *
   22.16 + * The new BSD License is applied to this software.
   22.17 + * see LICENSE.txt
   22.18 + *
   22.19 + * @note We assume that your system has inttypes.h.  If your system
   22.20 + * doesn't have inttypes.h, you have to typedef uint32_t and uint64_t,
   22.21 + * and you have to define PRIu64 and PRIx64 in this file as follows:
   22.22 + * @verbatim
   22.23 + typedef unsigned int uint32_t
   22.24 + typedef unsigned long long uint64_t  
   22.25 + #define PRIu64 "llu"
   22.26 + #define PRIx64 "llx"
   22.27 +@endverbatim
   22.28 + * uint32_t must be exactly 32-bit unsigned integer type (no more, no
   22.29 + * less), and uint64_t must be exactly 64-bit unsigned integer type.
   22.30 + * PRIu64 and PRIx64 are used for printf function to print 64-bit
   22.31 + * unsigned int and 64-bit unsigned int in hexadecimal format.
   22.32 + */
   22.33 +
   22.34 +#ifndef SFMT_H
   22.35 +#define SFMT_H
   22.36 +
   22.37 +#include <stdio.h>
   22.38 +
   22.39 +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
   22.40 +  #include <inttypes.h>
   22.41 +#elif defined(_MSC_VER) || defined(__BORLANDC__)
   22.42 +  typedef unsigned int uint32_t;
   22.43 +  typedef unsigned __int64 uint64_t;
   22.44 +  #define inline __inline
   22.45 +#else
   22.46 +  #include <inttypes.h>
   22.47 +  #if defined(__GNUC__)
   22.48 +    #define inline __inline__
   22.49 +  #endif
   22.50 +#endif
   22.51 +
   22.52 +#ifndef PRIu64
   22.53 +  #if defined(_MSC_VER) || defined(__BORLANDC__)
   22.54 +    #define PRIu64 "I64u"
   22.55 +    #define PRIx64 "I64x"
   22.56 +  #else
   22.57 +    #define PRIu64 "llu"
   22.58 +    #define PRIx64 "llx"
   22.59 +  #endif
   22.60 +#endif
   22.61 +
   22.62 +#if defined(__GNUC__)
   22.63 +#define ALWAYSINLINE __attribute__((always_inline))
   22.64 +#else
   22.65 +#define ALWAYSINLINE
   22.66 +#endif
   22.67 +
   22.68 +#if defined(_MSC_VER)
   22.69 +  #if _MSC_VER >= 1200
   22.70 +    #define PRE_ALWAYS __forceinline
   22.71 +  #else
   22.72 +    #define PRE_ALWAYS inline
   22.73 +  #endif
   22.74 +#else
   22.75 +  #define PRE_ALWAYS inline
   22.76 +#endif
   22.77 +
   22.78 +#if defined(__cplusplus) || defined(c_plusplus)
   22.79 +//extern "C" {
   22.80 +#endif
   22.81 +
   22.82 +uint32_t gen_rand32(void);
   22.83 +uint64_t gen_rand64(void);
   22.84 +void fill_array32(uint32_t *array, int size);
   22.85 +void fill_array64(uint64_t *array, int size);
   22.86 +void init_gen_rand(uint32_t seed);
   22.87 +void init_by_array(uint32_t *init_key, int key_length);
   22.88 +const char *get_idstring(void);
   22.89 +int get_min_array_size32(void);
   22.90 +int get_min_array_size64(void);
   22.91 +
   22.92 +#if defined(__cplusplus) || defined(c_plusplus)
   22.93 +//} // end extern
   22.94 +#endif
   22.95 +
   22.96 +/* These real versions are due to Isaku Wada */
   22.97 +/** generates a random number on [0,1]-real-interval */
   22.98 +inline static double to_real1(uint32_t v)
   22.99 +{
  22.100 +    return v * (1.0/4294967295.0); 
  22.101 +    /* divided by 2^32-1 */ 
  22.102 +}
  22.103 +
  22.104 +/** generates a random number on [0,1]-real-interval */
  22.105 +inline static double genrand_real1(void)
  22.106 +{
  22.107 +    return to_real1(gen_rand32());
  22.108 +}
  22.109 +
  22.110 +/** generates a random number on [0,1)-real-interval */
  22.111 +inline static double to_real2(uint32_t v)
  22.112 +{
  22.113 +    return v * (1.0/4294967296.0); 
  22.114 +    /* divided by 2^32 */
  22.115 +}
  22.116 +
  22.117 +/** generates a random number on [0,1)-real-interval */
  22.118 +inline static double genrand_real2(void)
  22.119 +{
  22.120 +    return to_real2(gen_rand32());
  22.121 +}
  22.122 +
  22.123 +/** generates a random number on (0,1)-real-interval */
  22.124 +inline static double to_real3(uint32_t v)
  22.125 +{
  22.126 +    return (((double)v) + 0.5)*(1.0/4294967296.0); 
  22.127 +    /* divided by 2^32 */
  22.128 +}
  22.129 +
  22.130 +/** generates a random number on (0,1)-real-interval */
  22.131 +inline static double genrand_real3(void)
  22.132 +{
  22.133 +    return to_real3(gen_rand32());
  22.134 +}
  22.135 +/** These real versions are due to Isaku Wada */
  22.136 +
  22.137 +/** generates a random number on [0,1) with 53-bit resolution*/
  22.138 +inline static double to_res53(uint64_t v) 
  22.139 +{ 
  22.140 +    return v * (1.0/18446744073709551616.0L);
  22.141 +}
  22.142 +
  22.143 +/** generates a random number on [0,1) with 53-bit resolution from two
  22.144 + * 32 bit integers */
  22.145 +inline static double to_res53_mix(uint32_t x, uint32_t y) 
  22.146 +{ 
  22.147 +    return to_res53(x | ((uint64_t)y << 32));
  22.148 +}
  22.149 +
  22.150 +/** generates a random number on [0,1) with 53-bit resolution
  22.151 + */
  22.152 +inline static double genrand_res53(void) 
  22.153 +{ 
  22.154 +    return to_res53(gen_rand64());
  22.155 +} 
  22.156 +
  22.157 +/** generates a random number on [0,1) with 53-bit resolution
  22.158 +    using 32bit integer.
  22.159 + */
  22.160 +inline static double genrand_res53_mix(void) 
  22.161 +{ 
  22.162 +    uint32_t x, y;
  22.163 +
  22.164 +    x = gen_rand32();
  22.165 +    y = gen_rand32();
  22.166 +    return to_res53_mix(x, y);
  22.167 +} 
  22.168 +#endif
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/src/VisualBoyAdvance.cfg	Sat Mar 03 10:31:27 2012 -0600
    23.3 @@ -0,0 +1,213 @@
    23.4 +# All numeric values are in hexadecimal
    23.5 +# Use TAB or EQUAL sign to separate name from value
    23.6 +
    23.7 +#
    23.8 +# Key configuration (all numbers are in hexadecimal!)
    23.9 +#
   23.10 +# Keys values are in the format YXXX where Y is the device number. 0 means
   23.11 +# keyborad and XXX is the SDL define for the desired key (read SDL_keysym.h).
   23.12 +#
   23.13 +# If Y is greater than 0, it means joystick number Y-1 and it uses the
   23.14 +# following format for XXX:
   23.15 +#
   23.16 +# - if XXX < 20, XXX is the axis number multiplied by 2. An even number means
   23.17 +#   movement to the negative side (on the X axis, it means left). An odd
   23.18 +#   number means movement to the positive side (on the X axis, it mean
   23.19 +#   right). For the Y axis, negative means up and positive means down.
   23.20 +#   X axis is usally axis number 0 and Y is axis number 1.
   23.21 +# - if 20 >= XXX > 30, then XXX is the HAT number multiplied by 4 plus the
   23.22 +#   direction: 0 for up, 1 for down, 2 for right and 3 for left. Example:
   23.23 +#   0021 is HAT 0 down, 0026 is HAT 1 right.
   23.24 +# - if 80 >= XXX > 100, XXX is the joystick button number (XXX-080).
   23.25 +#
   23.26 +# Default key configuration is (value in parenthesis):
   23.27 +#
   23.28 +# Left          Left Arrow  (0114)
   23.29 +# Right         Right Arrow (0113)
   23.30 +# Up            Up Arrow    (0111)
   23.31 +# Down          Down Arrow  (0112)
   23.32 +# A             Z           (007a)
   23.33 +# B             X           (0078)
   23.34 +# L             A           (0061)
   23.35 +# R             S           (0073)
   23.36 +# Start         ENTER       (000d)
   23.37 +# Select        BACKSPACE   (0008)
   23.38 +# Speed up      SPACE       (0020)
   23.39 +# Capture       F12         (0125)
   23.40 +#
   23.41 +Joy0_Left=0114
   23.42 +Joy0_Right=0113
   23.43 +Joy0_Up=0111
   23.44 +Joy0_Down=0112
   23.45 +Joy0_A=007a
   23.46 +Joy0_B=0078
   23.47 +Joy0_L=0061
   23.48 +Joy0_R=0073
   23.49 +Joy0_Start=000d
   23.50 +Joy0_Select=0008
   23.51 +Joy0_Speed=0020
   23.52 +Joy0_Capture=0125
   23.53 +
   23.54 +# Motion support keys. Same format as above
   23.55 +#
   23.56 +# Default keys are (value in parenthesis):
   23.57 +#
   23.58 +# Left          Numeric Pad 4 (0104)
   23.59 +# Right         Numeric Pad 6 (0106)
   23.60 +# Up            Numeric Pad 8 (0108)
   23.61 +# Down          Numeric Pad 2 (0102)
   23.62 +#
   23.63 +Motion_Left=0104
   23.64 +Motion_Right=0106
   23.65 +Motion_Up=0108
   23.66 +Motion_Down=0102
   23.67 +
   23.68 +# Frame skip setting. Allowed values are from 0 to 5 only.
   23.69 +frameSkip=2
   23.70 +
   23.71 +# Gameboy Frame skip setting. Allowed values are from 0 to 5 only.
   23.72 +gbFrameSkip=0
   23.73 +
   23.74 +# Video setting. 0=1x, 1=2x, 2=3x, 3=4x.
   23.75 +video=1
   23.76 +
   23.77 +# Use fullscreen mode. 0=false, any other value means true
   23.78 +fullScreen=0
   23.79 +
   23.80 +# Disables MMX support
   23.81 +disableMMX=1
   23.82 +
   23.83 +# Use bios file. 0=false, any other value means true
   23.84 +useBios=0
   23.85 +
   23.86 +# Bios file full path and name (ZIP not supported)
   23.87 +biosFile=none
   23.88 +
   23.89 +# Filter to use. 0=no filter, 1=TV Mode, 2=2xSaI, 3=Super 2xSaI, 4=Super Eagle
   23.90 +# 5=Pixelate, 6=Motion Blur, 7=AdvanceMAME Scale2x, 8=Simple 2x,
   23.91 +# 9=Bilinear, A=Bilinear Plus, B=hq2x, C=lq2x
   23.92 +filter=0
   23.93 +
   23.94 +# Disable status messages. 0=false, any other value means true
   23.95 +disableStatus=0
   23.96 +
   23.97 +# Enable Gameboy border. 0=false, any other value means true
   23.98 +borderOn=0
   23.99 +
  23.100 +# Gameboy emulator type. 0=automatic, 1=CGB/GBC, 2=SGB, 3=GB, 4=GBA, 5=SGB2
  23.101 +emulatorType=1
  23.102 +
  23.103 +# Enable washed colors. 0=false, any other value means true
  23.104 +colorOption=1
  23.105 +
  23.106 +# Directories. Not setting one them makes the file go the rom directory.
  23.107 +
  23.108 +# Save state directory
  23.109 +#saveDir=
  23.110 +
  23.111 +# Screen shot Capture directory
  23.112 +#captureDir=
  23.113 +
  23.114 +# Battery directory
  23.115 +#batteryDir=
  23.116 +
  23.117 +# Screen capture format
  23.118 +# 0=PNG, anything else for BMP
  23.119 +captureFormat=0
  23.120 +
  23.121 +# Sound quality
  23.122 +# 1=44 Khz, 2=22Khz, 4=11Khz
  23.123 +soundQuality=1
  23.124 +
  23.125 +# Sound Echo
  23.126 +# 0=false, anything else for true
  23.127 +soundEcho=0
  23.128 +
  23.129 +# Sound Low pass filter
  23.130 +# 0=false, anything else for true
  23.131 +soundLowPass=0
  23.132 +
  23.133 +# Sound reverse stereo
  23.134 +# 0=false, anything else for true
  23.135 +soundReverse=0
  23.136 +
  23.137 +# Remove GBA intros (not supported anymore)
  23.138 +# 0=false, anything else for true
  23.139 +# removeIntros=0
  23.140 +
  23.141 +# Save Type
  23.142 +# 0=automatic, 1=EEPROM, 2=SRAM, 3=Flash, 4=EEPROM+Sensor, 5=NONE
  23.143 +saveType=0
  23.144 +
  23.145 +# Flash size
  23.146 +# 0=64K Flash, 1=128K Flash
  23.147 +
  23.148 +flashSize=0
  23.149 +
  23.150 +# Sound volume
  23.151 +# 0=1x, 1=2x, 2=3x, 3=4x
  23.152 +soundVolume=0
  23.153 +
  23.154 +# Interframe blending
  23.155 +# 0=none, 1=motion blur, 2=smart
  23.156 +ifbType=0
  23.157 +
  23.158 +# Show emulation speed
  23.159 +# 0=none, 1=percentage, 2=detailed
  23.160 +showSpeed=1
  23.161 +
  23.162 +# Show speed in transparent mode
  23.163 +# 0=normal, anything else for transparent
  23.164 +showSpeedTransparent=1
  23.165 +
  23.166 +# Enable/Disable auto frameskip
  23.167 +# 0=disable, anything else to enable
  23.168 +autoFrameSkip=0
  23.169 +
  23.170 +# Sets the desired throttle
  23.171 +# 0=disable, 5...1000 valid throttle speeds
  23.172 +throttle=0
  23.173 +
  23.174 +# Pauses the emulator when the window is inactive
  23.175 +# 0=disable, anything else to enable
  23.176 +pauseWhenInactive=0
  23.177 +
  23.178 +# Enables AGBPrint support
  23.179 +# 0=disable, anything else to enable
  23.180 +agbPrint=0
  23.181 +
  23.182 +# Enables GBA RTC support
  23.183 +# 0=disable, anything else to enable
  23.184 +rtcEnabled=0
  23.185 +
  23.186 +# Sound OFF flag
  23.187 +# 0=sound on, anything else turns off sound
  23.188 +soundOff=0
  23.189 +
  23.190 +# Sound Enable
  23.191 +# Controls which channels are enabled: (add values)
  23.192 +#   1 - Channel 1
  23.193 +#   2 - Channel 2
  23.194 +#   4 - Channel 3
  23.195 +#   8 - Channel 4
  23.196 +# 100 - DirectSound A
  23.197 +# 200 - DirectSound B
  23.198 +# 30f=all enabled, 0=mute all
  23.199 +soundEnable=30f
  23.200 +
  23.201 +# Controls automatic SGB border
  23.202 +# 0=disable, anything else enables automatic SGB border display
  23.203 +borderAutomatic=0
  23.204 +
  23.205 +# Skip bios code
  23.206 +# 0=disable, anything else skips BIOS code
  23.207 +skipBios=0
  23.208 +
  23.209 +# The interval between the rewind saves
  23.210 +# Minimum of 0 seconds to disable rewind support, 
  23.211 +# Maximum of 60 minutes. Value in seconds (hexadecimal numbers)
  23.212 +rewindTimer=0
  23.213 +
  23.214 +# Enable enhanced save type detection
  23.215 +# 0=disable, anything else to enable (no longer used)
  23.216 +#enhancedDetection=1
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/src/apu/Blip_Buffer.cpp	Sat Mar 03 10:31:27 2012 -0600
    24.3 @@ -0,0 +1,465 @@
    24.4 +// Blip_Buffer 0.4.1. http://www.slack.net/~ant/
    24.5 +
    24.6 +#include "Blip_Buffer.h"
    24.7 +
    24.8 +#include <assert.h>
    24.9 +#include <limits.h>
   24.10 +#include <string.h>
   24.11 +#include <stdlib.h>
   24.12 +#include <math.h>
   24.13 +
   24.14 +/* Copyright (C) 2003-2007 Shay Green. This module is free software; you
   24.15 +can redistribute it and/or modify it under the terms of the GNU Lesser
   24.16 +General Public License as published by the Free Software Foundation; either
   24.17 +version 2.1 of the License, or (at your option) any later version. This
   24.18 +module is distributed in the hope that it will be useful, but WITHOUT ANY
   24.19 +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   24.20 +FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
   24.21 +details. You should have received a copy of the GNU Lesser General Public
   24.22 +License along with this module; if not, write to the Free Software Foundation,
   24.23 +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
   24.24 +
   24.25 +// TODO: use scoped for variables in treble_eq()
   24.26 +
   24.27 +#ifdef BLARGG_ENABLE_OPTIMIZER
   24.28 +	#include BLARGG_ENABLE_OPTIMIZER
   24.29 +#endif
   24.30 +
   24.31 +int const silent_buf_size = 1; // size used for Silent_Blip_Buffer
   24.32 +
   24.33 +Blip_Buffer::Blip_Buffer()
   24.34 +{
   24.35 +	factor_       = LONG_MAX;
   24.36 +	buffer_       = 0;
   24.37 +	buffer_size_  = 0;
   24.38 +	sample_rate_  = 0;
   24.39 +	bass_shift_   = 0;
   24.40 +	clock_rate_   = 0;
   24.41 +	bass_freq_    = 16;
   24.42 +	length_       = 0;
   24.43 +
   24.44 +	// assumptions code makes about implementation-defined features
   24.45 +	#ifndef NDEBUG
   24.46 +		// right shift of negative value preserves sign
   24.47 +		buf_t_ i = -0x7FFFFFFE;
   24.48 +		assert( (i >> 1) == -0x3FFFFFFF );
   24.49 +
   24.50 +		// casting to short truncates to 16 bits and sign-extends
   24.51 +		i = 0x18000;
   24.52 +		assert( (short) i == -0x8000 );
   24.53 +	#endif
   24.54 +
   24.55 +	clear();
   24.56 +}
   24.57 +
   24.58 +Blip_Buffer::~Blip_Buffer()
   24.59 +{
   24.60 +	if ( buffer_size_ != silent_buf_size )
   24.61 +		free( buffer_ );
   24.62 +}
   24.63 +
   24.64 +Silent_Blip_Buffer::Silent_Blip_Buffer()
   24.65 +{
   24.66 +	factor_      = 0;
   24.67 +	buffer_      = buf;
   24.68 +	buffer_size_ = silent_buf_size;
   24.69 +	clear();
   24.70 +}
   24.71 +
   24.72 +void Blip_Buffer::clear( int entire_buffer )
   24.73 +{
   24.74 +	offset_       = 0;
   24.75 +	reader_accum_ = 0;
   24.76 +	modified_     = 0;
   24.77 +	if ( buffer_ )
   24.78 +	{
   24.79 +		long count = (entire_buffer ? buffer_size_ : samples_avail());
   24.80 +		memset( buffer_, 0, (count + blip_buffer_extra_) * sizeof (buf_t_) );
   24.81 +	}
   24.82 +}
   24.83 +
   24.84 +Blip_Buffer::blargg_err_t Blip_Buffer::set_sample_rate( long new_rate, int msec )
   24.85 +{
   24.86 +	if ( buffer_size_ == silent_buf_size )
   24.87 +	{
   24.88 +		assert( 0 );
   24.89 +		return "Internal (tried to resize Silent_Blip_Buffer)";
   24.90 +	}
   24.91 +
   24.92 +	// start with maximum length that resampled time can represent
   24.93 +	long new_size = (ULONG_MAX >> BLIP_BUFFER_ACCURACY) - blip_buffer_extra_ - 64;
   24.94 +	if ( msec != blip_max_length )
   24.95 +	{
   24.96 +		long s = (new_rate * (msec + 1) + 999) / 1000;
   24.97 +		if ( s < new_size )
   24.98 +			new_size = s;
   24.99 +		else
  24.100 +			assert( 0 ); // fails if requested buffer length exceeds limit
  24.101 +	}
  24.102 +
  24.103 +	if ( buffer_size_ != new_size )
  24.104 +	{
  24.105 +		void* p = realloc( buffer_, (new_size + blip_buffer_extra_) * sizeof *buffer_ );
  24.106 +		if ( !p )
  24.107 +			return "Out of memory";
  24.108 +		buffer_ = (buf_t_*) p;
  24.109 +	}
  24.110 +
  24.111 +	buffer_size_ = new_size;
  24.112 +	assert( buffer_size_ != silent_buf_size ); // size should never happen to match this
  24.113 +
  24.114 +	// update things based on the sample rate
  24.115 +	sample_rate_ = new_rate;
  24.116 +	length_ = new_size * 1000 / new_rate - 1;
  24.117 +	if ( msec )
  24.118 +		assert( length_ == msec ); // ensure length is same as that passed in
  24.119 +
  24.120 +	// update these since they depend on sample rate
  24.121 +	if ( clock_rate_ )
  24.122 +		clock_rate( clock_rate_ );
  24.123 +	bass_freq( bass_freq_ );
  24.124 +
  24.125 +	clear();
  24.126 +
  24.127 +	return 0; // success
  24.128 +}
  24.129 +
  24.130 +blip_resampled_time_t Blip_Buffer::clock_rate_factor( long rate ) const
  24.131 +{
  24.132 +	double ratio = (double) sample_rate_ / rate;
  24.133 +	blip_long factor = (blip_long) floor( ratio * (1L << BLIP_BUFFER_ACCURACY) + 0.5 );
  24.134 +	assert( factor > 0 || !sample_rate_ ); // fails if clock/output ratio is too large
  24.135 +	return (blip_resampled_time_t) factor;
  24.136 +}
  24.137 +
  24.138 +void Blip_Buffer::bass_freq( int freq )
  24.139 +{
  24.140 +	bass_freq_ = freq;
  24.141 +	int shift = 31;
  24.142 +	if ( freq > 0 )
  24.143 +	{
  24.144 +		shift = 13;
  24.145 +		long f = (freq << 16) / sample_rate_;
  24.146 +		while ( (f >>= 1) && --shift ) { }
  24.147 +	}
  24.148 +	bass_shift_ = shift;
  24.149 +}
  24.150 +
  24.151 +void Blip_Buffer::end_frame( blip_time_t t )
  24.152 +{
  24.153 +	offset_ += t * factor_;
  24.154 +	assert( samples_avail() <= (long) buffer_size_ ); // fails if time is past end of buffer
  24.155 +}
  24.156 +
  24.157 +long Blip_Buffer::count_samples( blip_time_t t ) const
  24.158 +{
  24.159 +	blip_resampled_time_t last_sample  = resampled_time( t ) >> BLIP_BUFFER_ACCURACY;
  24.160 +	blip_resampled_time_t first_sample = offset_ >> BLIP_BUFFER_ACCURACY;
  24.161 +	return long (last_sample - first_sample);
  24.162 +}
  24.163 +
  24.164 +blip_time_t Blip_Buffer::count_clocks( long count ) const
  24.165 +{
  24.166 +	if ( !factor_ )
  24.167 +	{
  24.168 +		assert( 0 ); // sample rate and clock rates must be set first
  24.169 +		return 0;
  24.170 +	}
  24.171 +
  24.172 +	if ( count > buffer_size_ )
  24.173 +		count = buffer_size_;
  24.174 +	blip_resampled_time_t time = (blip_resampled_time_t) count << BLIP_BUFFER_ACCURACY;
  24.175 +	return (blip_time_t) ((time - offset_ + factor_ - 1) / factor_);
  24.176 +}
  24.177 +
  24.178 +void Blip_Buffer::remove_samples( long count )
  24.179 +{
  24.180 +	if ( count )
  24.181 +	{
  24.182 +		remove_silence( count );
  24.183 +
  24.184 +		// copy remaining samples to beginning and clear old samples
  24.185 +		long remain = samples_avail() + blip_buffer_extra_;
  24.186 +		memmove( buffer_, buffer_ + count, remain * sizeof *buffer_ );
  24.187 +		memset( buffer_ + remain, 0, count * sizeof *buffer_ );
  24.188 +	}
  24.189 +}
  24.190 +
  24.191 +// Blip_Synth_
  24.192 +
  24.193 +Blip_Synth_Fast_::Blip_Synth_Fast_()
  24.194 +{
  24.195 +	buf          = 0;
  24.196 +	last_amp     = 0;
  24.197 +	delta_factor = 0;
  24.198 +}
  24.199 +
  24.200 +void Blip_Synth_Fast_::volume_unit( double new_unit )
  24.201 +{
  24.202 +	delta_factor = int (new_unit * (1L << blip_sample_bits) + 0.5);
  24.203 +}
  24.204 +
  24.205 +#if !BLIP_BUFFER_FAST
  24.206 +
  24.207 +Blip_Synth_::Blip_Synth_( short* p, int w ) :
  24.208 +	impulses( p ),
  24.209 +	width( w )
  24.210 +{
  24.211 +	volume_unit_ = 0.0;
  24.212 +	kernel_unit  = 0;
  24.213 +	buf          = 0;
  24.214 +	last_amp     = 0;
  24.215 +	delta_factor = 0;
  24.216 +}
  24.217 +
  24.218 +#undef PI
  24.219 +#define PI 3.1415926535897932384626433832795029
  24.220 +
  24.221 +static void gen_sinc( float* out, int count, double oversample, double treble, double cutoff )
  24.222 +{
  24.223 +	if ( cutoff >= 0.999 )
  24.224 +		cutoff = 0.999;
  24.225 +
  24.226 +	if ( treble < -300.0 )
  24.227 +		treble = -300.0;
  24.228 +	if ( treble > 5.0 )
  24.229 +		treble = 5.0;
  24.230 +
  24.231 +	double const maxh = 4096.0;
  24.232 +	double const rolloff = pow( 10.0, 1.0 / (maxh * 20.0) * treble / (1.0 - cutoff) );
  24.233 +	double const pow_a_n = pow( rolloff, maxh - maxh * cutoff );
  24.234 +	double const to_angle = PI / 2 / maxh / oversample;
  24.235 +	for ( int i = 0; i < count; i++ )
  24.236 +	{
  24.237 +		double angle = ((i - count) * 2 + 1) * to_angle;
  24.238 +		double c = rolloff * cos( (maxh - 1.0) * angle ) - cos( maxh * angle );
  24.239 +		double cos_nc_angle = cos( maxh * cutoff * angle );
  24.240 +		double cos_nc1_angle = cos( (maxh * cutoff - 1.0) * angle );
  24.241 +		double cos_angle = cos( angle );
  24.242 +
  24.243 +		c = c * pow_a_n - rolloff * cos_nc1_angle + cos_nc_angle;
  24.244 +		double d = 1.0 + rolloff * (rolloff - cos_angle - cos_angle);
  24.245 +		double b = 2.0 - cos_angle - cos_angle;
  24.246 +		double a = 1.0 - cos_angle - cos_nc_angle + cos_nc1_angle;
  24.247 +
  24.248 +		out [i] = (float) ((a * d + c * b) / (b * d)); // a / b + c / d
  24.249 +	}
  24.250 +}
  24.251 +
  24.252 +void blip_eq_t::generate( float* out, int count ) const
  24.253 +{
  24.254 +	// lower cutoff freq for narrow kernels with their wider transition band
  24.255 +	// (8 points->1.49, 16 points->1.15)
  24.256 +	double oversample = blip_res * 2.25 / count + 0.85;
  24.257 +	double half_rate = sample_rate * 0.5;
  24.258 +	if ( cutoff_freq )
  24.259 +		oversample = half_rate / cutoff_freq;
  24.260 +	double cutoff = rolloff_freq * oversample / half_rate;
  24.261 +
  24.262 +	gen_sinc( out, count, blip_res * oversample, treble, cutoff );
  24.263 +
  24.264 +	// apply (half of) hamming window
  24.265 +	double to_fraction = PI / (count - 1);
  24.266 +	for ( int i = count; i--; )
  24.267 +		out [i] *= 0.54f - 0.46f * (float) cos( i * to_fraction );
  24.268 +}
  24.269 +
  24.270 +void Blip_Synth_::adjust_impulse()
  24.271 +{
  24.272 +	// sum pairs for each phase and add error correction to end of first half
  24.273 +	int const size = impulses_size();
  24.274 +	for ( int p = blip_res; p-- >= blip_res / 2; )
  24.275 +	{
  24.276 +		int p2 = blip_res - 2 - p;
  24.277 +		long error = kernel_unit;
  24.278 +		for ( int i = 1; i < size; i += blip_res )
  24.279 +		{
  24.280 +			error -= impulses [i + p ];
  24.281 +			error -= impulses [i + p2];
  24.282 +		}
  24.283 +		if ( p == p2 )
  24.284 +			error /= 2; // phase = 0.5 impulse uses same half for both sides
  24.285 +		impulses [size - blip_res + p] += (short) error;
  24.286 +		//printf( "error: %ld\n", error );
  24.287 +	}
  24.288 +
  24.289 +	//for ( int i = blip_res; i--; printf( "\n" ) )
  24.290 +	//  for ( int j = 0; j < width / 2; j++ )
  24.291 +	//      printf( "%5ld,", impulses [j * blip_res + i + 1] );
  24.292 +}
  24.293 +
  24.294 +void Blip_Synth_::treble_eq( blip_eq_t const& eq )
  24.295 +{
  24.296 +	float fimpulse [blip_res / 2 * (blip_widest_impulse_ - 1) + blip_res * 2];
  24.297 +
  24.298 +	int const half_size = blip_res / 2 * (width - 1);
  24.299 +	eq.generate( &fimpulse [blip_res], half_size );
  24.300 +
  24.301 +	int i;
  24.302 +
  24.303 +	// need mirror slightly past center for calculation
  24.304 +	for ( i = blip_res; i--; )
  24.305 +		fimpulse [blip_res + half_size + i] = fimpulse [blip_res + half_size - 1 - i];
  24.306 +
  24.307 +	// starts at 0
  24.308 +	for ( i = 0; i < blip_res; i++ )
  24.309 +		fimpulse [i] = 0.0f;
  24.310 +
  24.311 +	// find rescale factor
  24.312 +	double total = 0.0;
  24.313 +	for ( i = 0; i < half_size; i++ )
  24.314 +		total += fimpulse [blip_res + i];
  24.315 +
  24.316 +	//double const base_unit = 44800.0 - 128 * 18; // allows treble up to +0 dB
  24.317 +	//double const base_unit = 37888.0; // allows treble to +5 dB
  24.318 +	double const base_unit = 32768.0; // necessary for blip_unscaled to work
  24.319 +	double rescale = base_unit / 2 / total;
  24.320 +	kernel_unit = (long) base_unit;
  24.321 +
  24.322 +	// integrate, first difference, rescale, convert to int
  24.323 +	double sum = 0.0;
  24.324 +	double next = 0.0;
  24.325 +	int const size = this->impulses_size();
  24.326 +	for ( i = 0; i < size; i++ )
  24.327 +	{
  24.328 +		impulses [i] = (short) (int) floor( (next - sum) * rescale + 0.5 );
  24.329 +		sum += fimpulse [i];
  24.330 +		next += fimpulse [i + blip_res];
  24.331 +	}
  24.332 +	adjust_impulse();
  24.333 +
  24.334 +	// volume might require rescaling
  24.335 +	double vol = volume_unit_;
  24.336 +	if ( vol )
  24.337 +	{
  24.338 +		volume_unit_ = 0.0;
  24.339 +		volume_unit( vol );
  24.340 +	}
  24.341 +}
  24.342 +
  24.343 +void Blip_Synth_::volume_unit( double new_unit )
  24.344 +{
  24.345 +	if ( new_unit != volume_unit_ )
  24.346 +	{
  24.347 +		// use default eq if it hasn't been set yet
  24.348 +		if ( !kernel_unit )
  24.349 +			treble_eq( -8.0 );
  24.350 +
  24.351 +		volume_unit_ = new_unit;
  24.352 +		double factor = new_unit * (1L << blip_sample_bits) / kernel_unit;
  24.353 +
  24.354 +		if ( factor > 0.0 )
  24.355 +		{
  24.356 +			int shift = 0;
  24.357 +
  24.358 +			// if unit is really small, might need to attenuate kernel
  24.359 +			while ( factor < 2.0 )
  24.360 +			{
  24.361 +				shift++;
  24.362 +				factor *= 2.0;
  24.363 +			}
  24.364 +
  24.365 +			if ( shift )
  24.366 +			{
  24.367 +				kernel_unit >>= shift;
  24.368 +				assert( kernel_unit > 0 ); // fails if volume unit is too low
  24.369 +
  24.370 +				// keep values positive to avoid round-towards-zero of sign-preserving
  24.371 +				// right shift for negative values
  24.372 +				long offset = 0x8000 + (1 << (shift - 1));
  24.373 +				long offset2 = 0x8000 >> shift;
  24.374 +				for ( int i = impulses_size(); i--; )
  24.375 +					impulses [i] = (short) (int) (((impulses [i] + offset) >> shift) - offset2);
  24.376 +				adjust_impulse();
  24.377 +			}
  24.378 +		}
  24.379 +		delta_factor = (int) floor( factor + 0.5 );
  24.380 +		//printf( "delta_factor: %d, kernel_unit: %d\n", delta_factor, kernel_unit );
  24.381 +	}
  24.382 +}
  24.383 +#endif
  24.384 +
  24.385 +long Blip_Buffer::read_samples( blip_sample_t* out_, long max_samples, int stereo )
  24.386 +{
  24.387 +	long count = samples_avail();
  24.388 +	if ( count > max_samples )
  24.389 +		count = max_samples;
  24.390 +
  24.391 +	if ( count )
  24.392 +	{
  24.393 +		int const bass = BLIP_READER_BASS( *this );
  24.394 +		BLIP_READER_BEGIN( reader, *this );
  24.395 +		BLIP_READER_ADJ_( reader, count );
  24.396 +		blip_sample_t* BLIP_RESTRICT out = out_ + count;
  24.397 +		blip_long offset = (blip_long) -count;
  24.398 +
  24.399 +		if ( !stereo )
  24.400 +		{
  24.401 +			do
  24.402 +			{
  24.403 +				blip_long s = BLIP_READER_READ( reader );
  24.404 +				BLIP_READER_NEXT_IDX_( reader, bass, offset );
  24.405 +				BLIP_CLAMP( s, s );
  24.406 +				out [offset] = (blip_sample_t) s;
  24.407 +			}
  24.408 +			while ( ++offset );
  24.409 +		}
  24.410 +		else
  24.411 +		{
  24.412 +			do
  24.413 +			{
  24.414 +				blip_long s = BLIP_READER_READ( reader );
  24.415 +				BLIP_READER_NEXT_IDX_( reader, bass, offset );
  24.416 +				BLIP_CLAMP( s, s );
  24.417 +				out [offset * 2] = (blip_sample_t) s;
  24.418 +			}
  24.419 +			while ( ++offset );
  24.420 +		}
  24.421 +
  24.422 +		BLIP_READER_END( reader, *this );
  24.423 +
  24.424 +		remove_samples( count );
  24.425 +	}
  24.426 +	return count;
  24.427 +}
  24.428 +
  24.429 +void Blip_Buffer::mix_samples( blip_sample_t const* in, long count )
  24.430 +{
  24.431 +	if ( buffer_size_ == silent_buf_size )
  24.432 +	{
  24.433 +		assert( 0 );
  24.434 +		return;
  24.435 +	}
  24.436 +
  24.437 +	buf_t_* out = buffer_ + (offset_ >> BLIP_BUFFER_ACCURACY) + blip_widest_impulse_ / 2;
  24.438 +
  24.439 +	int const sample_shift = blip_sample_bits - 16;
  24.440 +	int prev = 0;
  24.441 +	while ( count-- )
  24.442 +	{
  24.443 +		blip_long s = (blip_long) *in++ << sample_shift;
  24.444 +		*out += s - prev;
  24.445 +		prev = s;
  24.446 +		++out;
  24.447 +	}
  24.448 +	*out -= prev;
  24.449 +}
  24.450 +
  24.451 +blip_ulong const subsample_mask = (1L << BLIP_BUFFER_ACCURACY) - 1;
  24.452 +
  24.453 +void Blip_Buffer::save_state( blip_buffer_state_t* out )
  24.454 +{
  24.455 +	assert( samples_avail() == 0 );
  24.456 +	out->offset_       = offset_;
  24.457 +	out->reader_accum_ = reader_accum_;
  24.458 +	memcpy( out->buf, &buffer_ [offset_ >> BLIP_BUFFER_ACCURACY], sizeof out->buf );
  24.459 +}
  24.460 +
  24.461 +void Blip_Buffer::load_state( blip_buffer_state_t const& in )
  24.462 +{
  24.463 +	clear( false );
  24.464 +
  24.465 +	offset_       = in.offset_;
  24.466 +	reader_accum_ = in.reader_accum_;
  24.467 +	memcpy( buffer_, in.buf, sizeof in.buf );
  24.468 +}
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/src/apu/Blip_Buffer.h	Sat Mar 03 10:31:27 2012 -0600
    25.3 @@ -0,0 +1,556 @@
    25.4 +// Band-limited sound synthesis buffer
    25.5 +
    25.6 +// Blip_Buffer 0.4.1
    25.7 +#ifndef BLIP_BUFFER_H
    25.8 +#define BLIP_BUFFER_H
    25.9 +
   25.10 +	// internal
   25.11 +	#include <limits.h>
   25.12 +	#if INT_MAX < 0x7FFFFFFF || LONG_MAX == 0x7FFFFFFF
   25.13 +		typedef long blip_long;
   25.14 +		typedef unsigned long blip_ulong;
   25.15 +	#else
   25.16 +		typedef int blip_long;
   25.17 +		typedef unsigned blip_ulong;
   25.18 +	#endif
   25.19 +
   25.20 +// Time unit at source clock rate
   25.21 +typedef blip_long blip_time_t;
   25.22 +
   25.23 +// Output samples are 16-bit signed, with a range of -32768 to 32767
   25.24 +typedef short blip_sample_t;
   25.25 +enum { blip_sample_max = 32767 };
   25.26 +
   25.27 +struct blip_buffer_state_t;
   25.28 +
   25.29 +class Blip_Buffer {
   25.30 +public:
   25.31 +	typedef const char* blargg_err_t;
   25.32 +
   25.33 +	// Sets output sample rate and buffer length in milliseconds (1/1000 sec, defaults
   25.34 +	// to 1/4 second) and clears buffer. If there isn't enough memory, leaves buffer
   25.35 +	// untouched and returns "Out of memory", otherwise returns NULL.
   25.36 +	blargg_err_t set_sample_rate( long samples_per_sec, int msec_length = 1000 / 4 );
   25.37 +
   25.38 +	// Sets number of source time units per second
   25.39 +	void clock_rate( long clocks_per_sec );
   25.40 +
   25.41 +	// Ends current time frame of specified duration and makes its samples available
   25.42 +	// (along with any still-unread samples) for reading with read_samples(). Begins
   25.43 +	// a new time frame at the end of the current frame.
   25.44 +	void end_frame( blip_time_t time );
   25.45 +
   25.46 +	// Reads at most 'max_samples' out of buffer into 'dest', removing them from from
   25.47 +	// the buffer. Returns number of samples actually read and removed. If stereo is
   25.48 +	// true, increments 'dest' one extra time after writing each sample, to allow
   25.49 +	// easy interleving of two channels into a stereo output buffer.
   25.50 +	long read_samples( blip_sample_t* dest, long max_samples, int stereo = 0 );
   25.51 +
   25.52 +// Additional features
   25.53 +
   25.54 +	// Removes all available samples and clear buffer to silence. If 'entire_buffer' is
   25.55 +	// false, just clears out any samples waiting rather than the entire buffer.
   25.56 +	void clear( int entire_buffer = 1 );
   25.57 +
   25.58 +	// Number of samples available for reading with read_samples()
   25.59 +	long samples_avail() const;
   25.60 +
   25.61 +	// Removes 'count' samples from those waiting to be read
   25.62 +	void remove_samples( long count );
   25.63 +
   25.64 +	// Sets frequency high-pass filter frequency, where higher values reduce bass more
   25.65 +	void bass_freq( int frequency );
   25.66 +
   25.67 +	// Current output sample rate
   25.68 +	long sample_rate() const;
   25.69 +
   25.70 +	// Length of buffer in milliseconds
   25.71 +	int length() const;
   25.72 +
   25.73 +	// Number of source time units per second
   25.74 +	long clock_rate() const;
   25.75 +
   25.76 +// Experimental features
   25.77 +
   25.78 +	// Saves state, including high-pass filter and tails of last deltas.
   25.79 +	// All samples must have been read from buffer before calling this.
   25.80 +	void save_state( blip_buffer_state_t* out );
   25.81 +
   25.82 +	// Loads state. State must have been saved from Blip_Buffer with same
   25.83 +	// settings during same run of program. States can NOT be stored on disk.
   25.84 +	// Clears buffer before loading state.
   25.85 +	void load_state( blip_buffer_state_t const& in );
   25.86 +
   25.87 +	// Number of samples delay from synthesis to samples read out
   25.88 +	int output_latency() const;
   25.89 +
   25.90 +	// Counts number of clocks needed until 'count' samples will be available.
   25.91 +	// If buffer can't even hold 'count' samples, returns number of clocks until
   25.92 +	// buffer becomes full.
   25.93 +	blip_time_t count_clocks( long count ) const;
   25.94 +
   25.95 +	// Number of raw samples that can be mixed within frame of specified duration.
   25.96 +	long count_samples( blip_time_t duration ) const;
   25.97 +
   25.98 +	// Mixes in 'count' samples from 'buf_in'
   25.99 +	void mix_samples( blip_sample_t const* buf_in, long count );
  25.100 +
  25.101 +
  25.102 +	// Signals that sound has been added to buffer. Could be done automatically in
  25.103 +	// Blip_Synth, but that would affect performance more, as you can arrange that
  25.104 +	// this is called only once per time frame rather than for every delta.
  25.105 +	void set_modified() { modified_ = this; }
  25.106 +
  25.107 +	// not documented yet
  25.108 +	blip_ulong unsettled() const;
  25.109 +	Blip_Buffer* clear_modified() { Blip_Buffer* b = modified_; modified_ = 0; return b; }
  25.110 +	void remove_silence( long count );
  25.111 +	typedef blip_ulong blip_resampled_time_t;
  25.112 +	blip_resampled_time_t resampled_duration( int t ) const     { return t * factor_; }
  25.113 +	blip_resampled_time_t resampled_time( blip_time_t t ) const { return t * factor_ + offset_; }
  25.114 +	blip_resampled_time_t clock_rate_factor( long clock_rate ) const;
  25.115 +public:
  25.116 +	Blip_Buffer();
  25.117 +	~Blip_Buffer();
  25.118 +
  25.119 +	// Deprecated
  25.120 +	typedef blip_resampled_time_t resampled_time_t;
  25.121 +	blargg_err_t sample_rate( long r ) { return set_sample_rate( r ); }
  25.122 +	blargg_err_t sample_rate( long r, int msec ) { return set_sample_rate( r, msec ); }
  25.123 +private:
  25.124 +	// noncopyable
  25.125 +	Blip_Buffer( const Blip_Buffer& );
  25.126 +	Blip_Buffer& operator = ( const Blip_Buffer& );
  25.127 +public:
  25.128 +	typedef blip_long buf_t_;
  25.129 +	blip_ulong factor_;
  25.130 +	blip_resampled_time_t offset_;
  25.131 +	buf_t_* buffer_;
  25.132 +	blip_long buffer_size_;
  25.133 +	blip_long reader_accum_;
  25.134 +	int bass_shift_;
  25.135 +private:
  25.136 +	long sample_rate_;
  25.137 +	long clock_rate_;
  25.138 +	int bass_freq_;
  25.139 +	int length_;
  25.140 +	Blip_Buffer* modified_; // non-zero = true (more optimal than using bool, heh)
  25.141 +	friend class Blip_Reader;
  25.142 +};
  25.143 +
  25.144 +#ifdef HAVE_CONFIG_H
  25.145 +	#include "config.h"
  25.146 +#endif
  25.147 +
  25.148 +// Number of bits in resample ratio fraction. Higher values give a more accurate ratio
  25.149 +// but reduce maximum buffer size.
  25.150 +#ifndef BLIP_BUFFER_ACCURACY
  25.151 +	#define BLIP_BUFFER_ACCURACY 16
  25.152 +#endif
  25.153 +
  25.154 +// Number bits in phase offset. Fewer than 6 bits (64 phase offsets) results in
  25.155 +// noticeable broadband noise when synthesizing high frequency square waves.
  25.156 +// Affects size of Blip_Synth objects since they store the waveform directly.
  25.157 +#ifndef BLIP_PHASE_BITS
  25.158 +	#if BLIP_BUFFER_FAST
  25.159 +		#define BLIP_PHASE_BITS 8
  25.160 +	#else
  25.161 +		#define BLIP_PHASE_BITS 6
  25.162 +	#endif
  25.163 +#endif
  25.164 +
  25.165 +	// Internal
  25.166 +	typedef blip_ulong blip_resampled_time_t;
  25.167 +	int const blip_widest_impulse_ = 16;
  25.168 +	int const blip_buffer_extra_ = blip_widest_impulse_ + 2;
  25.169 +	int const blip_res = 1 << BLIP_PHASE_BITS;
  25.170 +	class blip_eq_t;
  25.171 +
  25.172 +	class Blip_Synth_Fast_ {
  25.173 +	public:
  25.174 +		Blip_Buffer* buf;
  25.175 +		int last_amp;
  25.176 +		int delta_factor;
  25.177 +
  25.178 +		void volume_unit( double );
  25.179 +		Blip_Synth_Fast_();
  25.180 +		void treble_eq( blip_eq_t const& ) { }
  25.181 +	};
  25.182 +
  25.183 +	class Blip_Synth_ {
  25.184 +	public:
  25.185 +		Blip_Buffer* buf;
  25.186 +		int last_amp;
  25.187 +		int delta_factor;
  25.188 +
  25.189 +		void volume_unit( double );
  25.190 +		Blip_Synth_( short* impulses, int width );
  25.191 +		void treble_eq( blip_eq_t const& );
  25.192 +	private:
  25.193 +		double volume_unit_;
  25.194 +		short* const impulses;
  25.195 +		int const width;
  25.196 +		blip_long kernel_unit;
  25.197 +		int impulses_size() const { return blip_res / 2 * width + 1; }
  25.198 +		void adjust_impulse();
  25.199 +	};
  25.200 +
  25.201 +// Quality level, better = slower. In general, use blip_good_quality.
  25.202 +const int blip_med_quality  = 8;
  25.203 +const int blip_good_quality = 12;
  25.204 +const int blip_high_quality = 16;
  25.205 +
  25.206 +// Range specifies the greatest expected change in amplitude. Calculate it
  25.207 +// by finding the difference between the maximum and minimum expected
  25.208 +// amplitudes (max - min).
  25.209 +template<int quality,int range>
  25.210 +class Blip_Synth {
  25.211 +public:
  25.212 +	// Sets overall volume of waveform
  25.213 +	void volume( double v ) { impl.volume_unit( v * (1.0 / (range < 0 ? -range : range)) ); }
  25.214 +
  25.215 +	// Configures low-pass filter (see blip_buffer.txt)
  25.216 +	void treble_eq( blip_eq_t const& eq )       { impl.treble_eq( eq ); }
  25.217 +
  25.218 +	// Gets/sets Blip_Buffer used for output
  25.219 +	Blip_Buffer* output() const                 { return impl.buf; }
  25.220 +	void output( Blip_Buffer* b )               { impl.buf = b; impl.last_amp = 0; }
  25.221 +
  25.222 +	// Updates amplitude of waveform at given time. Using this requires a separate
  25.223 +	// Blip_Synth for each waveform.
  25.224 +	void update( blip_time_t time, int amplitude );
  25.225 +
  25.226 +// Low-level interface
  25.227 +
  25.228 +	// Adds an amplitude transition of specified delta, optionally into specified buffer
  25.229 +	// rather than the one set with output(). Delta can be positive or negative.
  25.230 +	// The actual change in amplitude is delta * (volume / range)
  25.231 +	void offset( blip_time_t, int delta, Blip_Buffer* ) const;
  25.232 +	void offset( blip_time_t t, int delta ) const { offset( t, delta, impl.buf ); }
  25.233 +
  25.234 +	// Works directly in terms of fractional output samples. Contact author for more info.
  25.235 +	void offset_resampled( blip_resampled_time_t, int delta, Blip_Buffer* ) const;
  25.236 +
  25.237 +	// Same as offset(), except code is inlined for higher performance
  25.238 +	void offset_inline( blip_time_t t, int delta, Blip_Buffer* buf ) const {
  25.239 +		offset_resampled( t * buf->factor_ + buf->offset_, delta, buf );
  25.240 +	}
  25.241 +	void offset_inline( blip_time_t t, int delta ) const {
  25.242 +		offset_resampled( t * impl.buf->factor_ + impl.buf->offset_, delta, impl.buf );
  25.243 +	}
  25.244 +
  25.245 +private:
  25.246 +#if BLIP_BUFFER_FAST
  25.247 +	Blip_Synth_Fast_ impl;
  25.248 +#else
  25.249 +	Blip_Synth_ impl;
  25.250 +	typedef short imp_t;
  25.251 +	imp_t impulses [blip_res * (quality / 2) + 1];
  25.252 +public:
  25.253 +	Blip_Synth() : impl( impulses, quality ) { }
  25.254 +#endif
  25.255 +};
  25.256 +
  25.257 +// Low-pass equalization parameters
  25.258 +class blip_eq_t {
  25.259 +public:
  25.260 +	// Logarithmic rolloff to treble dB at half sampling rate. Negative values reduce
  25.261 +	// treble, small positive values (0 to 5.0) increase treble.
  25.262 +	blip_eq_t( double treble_db = 0 );
  25.263 +
  25.264 +	// See blip_buffer.txt
  25.265 +	blip_eq_t( double treble, long rolloff_freq, long sample_rate, long cutoff_freq = 0 );
  25.266 +
  25.267 +private:
  25.268 +	double treble;
  25.269 +	long rolloff_freq;
  25.270 +	long sample_rate;
  25.271 +	long cutoff_freq;
  25.272 +	void generate( float* out, int count ) const;
  25.273 +	friend class Blip_Synth_;
  25.274 +};
  25.275 +
  25.276 +int const blip_sample_bits = 30;
  25.277 +
  25.278 +// Dummy Blip_Buffer to direct sound output to, for easy muting without
  25.279 +// having to stop sound code.
  25.280 +class Silent_Blip_Buffer : public Blip_Buffer {
  25.281 +	buf_t_ buf [blip_buffer_extra_ + 1];
  25.282 +public:
  25.283 +	// The following cannot be used (an assertion will fail if attempted):
  25.284 +	blargg_err_t set_sample_rate( long samples_per_sec, int msec_length );
  25.285 +	blip_time_t count_clocks( long count ) const;
  25.286 +	void mix_samples( blip_sample_t const* buf, long count );
  25.287 +
  25.288 +	Silent_Blip_Buffer();
  25.289 +};
  25.290 +
  25.291 +	#if __GNUC__ >= 3 || _MSC_VER >= 1400
  25.292 +		#define BLIP_RESTRICT __restrict
  25.293 +	#else
  25.294 +		#define BLIP_RESTRICT
  25.295 +	#endif
  25.296 +
  25.297 +// Optimized reading from Blip_Buffer, for use in custom sample output
  25.298 +
  25.299 +// Begins reading from buffer. Name should be unique to the current block.
  25.300 +#define BLIP_READER_BEGIN( name, blip_buffer ) \
  25.301 +	const Blip_Buffer::buf_t_* BLIP_RESTRICT name##_reader_buf = (blip_buffer).buffer_;\
  25.302 +	blip_long name##_reader_accum = (blip_buffer).reader_accum_
  25.303 +
  25.304 +// Gets value to pass to BLIP_READER_NEXT()
  25.305 +#define BLIP_READER_BASS( blip_buffer ) ((blip_buffer).bass_shift_)
  25.306 +
  25.307 +// Constant value to use instead of BLIP_READER_BASS(), for slightly more optimal
  25.308 +// code at the cost of having no bass control
  25.309 +int const blip_reader_default_bass = 9;
  25.310 +
  25.311 +// Current sample
  25.312 +#define BLIP_READER_READ( name )        (name##_reader_accum >> (blip_sample_bits - 16))
  25.313 +
  25.314 +// Current raw sample in full internal resolution
  25.315 +#define BLIP_READER_READ_RAW( name )    (name##_reader_accum)
  25.316 +
  25.317 +// Advances to next sample
  25.318 +#define BLIP_READER_NEXT( name, bass ) \
  25.319 +	(void) (name##_reader_accum += *name##_reader_buf++ - (name##_reader_accum >> (bass)))
  25.320 +
  25.321 +// Ends reading samples from buffer. The number of samples read must now be removed
  25.322 +// using Blip_Buffer::remove_samples().
  25.323 +#define BLIP_READER_END( name, blip_buffer ) \
  25.324 +	(void) ((blip_buffer).reader_accum_ = name##_reader_accum)
  25.325 +
  25.326 +
  25.327 +// experimental
  25.328 +#define BLIP_READER_ADJ_( name, offset ) (name##_reader_buf += offset)
  25.329 +
  25.330 +blip_long const blip_reader_idx_factor = sizeof (Blip_Buffer::buf_t_);
  25.331 +
  25.332 +#define BLIP_READER_NEXT_IDX_( name, bass, idx ) {\
  25.333 +	name##_reader_accum -= name##_reader_accum >> (bass);\
  25.334 +	name##_reader_accum += name##_reader_buf [(idx)];\
  25.335 +}
  25.336 +
  25.337 +#define BLIP_READER_NEXT_RAW_IDX_( name, bass, idx ) {\
  25.338 +	name##_reader_accum -= name##_reader_accum >> (bass);\
  25.339 +	name##_reader_accum +=\
  25.340 +			*(Blip_Buffer::buf_t_ const*) ((char const*) name##_reader_buf + (idx));\
  25.341 +}
  25.342 +
  25.343 +// Compatibility with older version
  25.344 +const long blip_unscaled = 65535;
  25.345 +const int blip_low_quality  = blip_med_quality;
  25.346 +const int blip_best_quality = blip_high_quality;
  25.347 +
  25.348 +// Deprecated; use BLIP_READER macros as follows:
  25.349 +// Blip_Reader r; r.begin( buf ); -> BLIP_READER_BEGIN( r, buf );
  25.350 +// int bass = r.begin( buf )      -> BLIP_READER_BEGIN( r, buf ); int bass = BLIP_READER_BASS( buf );
  25.351 +// r.read()                       -> BLIP_READER_READ( r )
  25.352 +// r.read_raw()                   -> BLIP_READER_READ_RAW( r )
  25.353 +// r.next( bass )                 -> BLIP_READER_NEXT( r, bass )
  25.354 +// r.next()                       -> BLIP_READER_NEXT( r, blip_reader_default_bass )
  25.355 +// r.end( buf )                   -> BLIP_READER_END( r, buf )
  25.356 +class Blip_Reader {
  25.357 +public:
  25.358 +	int begin( Blip_Buffer& );
  25.359 +	blip_long read() const          { return accum >> (blip_sample_bits - 16); }
  25.360 +	blip_long read_raw() const      { return accum; }
  25.361 +	void next( int bass_shift = 9 ) { accum += *buf++ - (accum >> bass_shift); }
  25.362 +	void end( Blip_Buffer& b )      { b.reader_accum_ = accum; }
  25.363 +private:
  25.364 +	const Blip_Buffer::buf_t_* buf;
  25.365 +	blip_long accum;
  25.366 +};
  25.367 +
  25.368 +#if defined (_M_IX86) || defined (_M_IA64) || defined (__i486__) || \
  25.369 +		defined (__x86_64__) || defined (__ia64__) || defined (__i386__)
  25.370 +	#define BLIP_CLAMP_( in ) in < -0x8000 || 0x7FFF < in
  25.371 +#else
  25.372 +	#define BLIP_CLAMP_( in ) (blip_sample_t) in != in
  25.373 +#endif
  25.374 +
  25.375 +// Clamp sample to blip_sample_t range
  25.376 +#define BLIP_CLAMP( sample, out )\
  25.377 +	{ if ( BLIP_CLAMP_( (sample) ) ) (out) = ((sample) >> 24) ^ 0x7FFF; }
  25.378 +
  25.379 +struct blip_buffer_state_t
  25.380 +{
  25.381 +	blip_resampled_time_t offset_;
  25.382 +	blip_long reader_accum_;
  25.383 +	blip_long buf [blip_buffer_extra_];
  25.384 +};
  25.385 +
  25.386 +// End of public interface
  25.387 +
  25.388 +#ifndef assert
  25.389 +	#include <assert.h>
  25.390 +#endif
  25.391 +
  25.392 +template<int quality,int range>
  25.393 +inline void Blip_Synth<quality,range>::offset_resampled( blip_resampled_time_t time,
  25.394 +		int delta, Blip_Buffer* blip_buf ) const
  25.395 +{
  25.396 +	// If this assertion fails, it means that an attempt was made to add a delta
  25.397 +	// at a negative time or past the end of the buffer.
  25.398 +	assert( (blip_long) (time >> BLIP_BUFFER_ACCURACY) < blip_buf->buffer_size_ );
  25.399 +
  25.400 +	delta *= impl.delta_factor;
  25.401 +	blip_long* BLIP_RESTRICT buf = blip_buf->buffer_ + (time >> BLIP_BUFFER_ACCURACY);
  25.402 +	int phase = (int) (time >> (BLIP_BUFFER_ACCURACY - BLIP_PHASE_BITS) & (blip_res - 1));
  25.403 +
  25.404 +#if BLIP_BUFFER_FAST
  25.405 +	blip_long left = buf [0] + delta;
  25.406 +
  25.407 +	// Kind of crappy, but doing shift after multiply results in overflow.
  25.408 +	// Alternate way of delaying multiply by delta_factor results in worse
  25.409 +	// sub-sample resolution.
  25.410 +	blip_long right = (delta >> BLIP_PHASE_BITS) * phase;
  25.411 +	left  -= right;
  25.412 +	right += buf [1];
  25.413 +
  25.414 +	buf [0] = left;
  25.415 +	buf [1] = right;
  25.416 +#else
  25.417 +
  25.418 +	int const fwd = (blip_widest_impulse_ - quality) / 2;
  25.419 +	int const rev = fwd + quality - 2;
  25.420 +	int const mid = quality / 2 - 1;
  25.421 +
  25.422 +	imp_t const* BLIP_RESTRICT imp = impulses + blip_res - phase;
  25.423 +
  25.424 +	#if defined (_M_IX86) || defined (_M_IA64) || defined (__i486__) || \
  25.425 +			defined (__x86_64__) || defined (__ia64__) || defined (__i386__)
  25.426 +
  25.427 +	// this straight forward version gave in better code on GCC for x86
  25.428 +
  25.429 +	#define ADD_IMP( out, in ) \
  25.430 +		buf [out] += (blip_long) imp [blip_res * (in)] * delta
  25.431 +
  25.432 +	#define BLIP_FWD( i ) {\
  25.433 +		ADD_IMP( fwd     + i, i     );\
  25.434 +		ADD_IMP( fwd + 1 + i, i + 1 );\
  25.435 +	}
  25.436 +	#define BLIP_REV( r ) {\
  25.437 +		ADD_IMP( rev     - r, r + 1 );\
  25.438 +		ADD_IMP( rev + 1 - r, r     );\
  25.439 +	}
  25.440 +
  25.441 +		BLIP_FWD( 0 )
  25.442 +		if ( quality > 8  ) BLIP_FWD( 2 )
  25.443 +		if ( quality > 12 ) BLIP_FWD( 4 )
  25.444 +		{
  25.445 +			ADD_IMP( fwd + mid - 1, mid - 1 );
  25.446 +			ADD_IMP( fwd + mid    , mid     );
  25.447 +			imp = impulses + phase;
  25.448 +		}
  25.449 +		if ( quality > 12 ) BLIP_REV( 6 )
  25.450 +		if ( quality > 8  ) BLIP_REV( 4 )
  25.451 +		BLIP_REV( 2 )
  25.452 +
  25.453 +		ADD_IMP( rev    , 1 );
  25.454 +		ADD_IMP( rev + 1, 0 );
  25.455 +
  25.456 +	#undef ADD_IMP
  25.457 +
  25.458 +	#else
  25.459 +
  25.460 +	// for RISC processors, help compiler by reading ahead of writes
  25.461 +
  25.462 +	#define BLIP_FWD( i ) {\
  25.463 +		blip_long t0 =                       i0 * delta + buf [fwd     + i];\
  25.464 +		blip_long t1 = imp [blip_res * (i + 1)] * delta + buf [fwd + 1 + i];\
  25.465 +		i0 =           imp [blip_res * (i + 2)];\
  25.466 +		buf [fwd     + i] = t0;\
  25.467 +		buf [fwd + 1 + i] = t1;\
  25.468 +	}
  25.469 +	#define BLIP_REV( r ) {\
  25.470 +		blip_long t0 =                 i0 * delta + buf [rev     - r];\
  25.471 +		blip_long t1 = imp [blip_res * r] * delta + buf [rev + 1 - r];\
  25.472 +		i0 =           imp [blip_res * (r - 1)];\
  25.473 +		buf [rev     - r] = t0;\
  25.474 +		buf [rev + 1 - r] = t1;\
  25.475 +	}
  25.476 +
  25.477 +		blip_long i0 = *imp;
  25.478 +		BLIP_FWD( 0 )
  25.479 +		if ( quality > 8  ) BLIP_FWD( 2 )
  25.480 +		if ( quality > 12 ) BLIP_FWD( 4 )
  25.481 +		{
  25.482 +			blip_long t0 =                   i0 * delta + buf [fwd + mid - 1];
  25.483 +			blip_long t1 = imp [blip_res * mid] * delta + buf [fwd + mid    ];
  25.484 +			imp = impulses + phase;
  25.485 +			i0 = imp [blip_res * mid];
  25.486 +			buf [fwd + mid - 1] = t0;
  25.487 +			buf [fwd + mid    ] = t1;
  25.488 +		}
  25.489 +		if ( quality > 12 ) BLIP_REV( 6 )
  25.490 +		if ( quality > 8  ) BLIP_REV( 4 )
  25.491 +		BLIP_REV( 2 )
  25.492 +
  25.493 +		blip_long t0 =   i0 * delta + buf [rev    ];
  25.494 +		blip_long t1 = *imp * delta + buf [rev + 1];
  25.495 +		buf [rev    ] = t0;
  25.496 +		buf [rev + 1] = t1;
  25.497 +	#endif
  25.498 +
  25.499 +#endif
  25.500 +}
  25.501 +
  25.502 +#undef BLIP_FWD
  25.503 +#undef BLIP_REV
  25.504 +
  25.505 +template<int quality,int range>
  25.506 +#if BLIP_BUFFER_FAST
  25.507 +	inline
  25.508 +#endif
  25.509 +void Blip_Synth<quality,range>::offset( blip_time_t t, int delta, Blip_Buffer* buf ) const
  25.510 +{
  25.511 +	offset_resampled( t * buf->factor_ + buf->offset_, delta, buf );
  25.512 +}
  25.513 +
  25.514 +template<int quality,int range>
  25.515 +#if BLIP_BUFFER_FAST
  25.516 +	inline
  25.517 +#endif
  25.518 +void Blip_Synth<quality,range>::update( blip_time_t t, int amp )
  25.519 +{
  25.520 +	int delta = amp - impl.last_amp;
  25.521 +	impl.last_amp = amp;
  25.522 +	offset_resampled( t * impl.buf->factor_ + impl.buf->offset_, delta, impl.buf );
  25.523 +}
  25.524 +
  25.525 +inline blip_eq_t::blip_eq_t( double t ) :
  25.526 +		treble( t ), rolloff_freq( 0 ), sample_rate( 44100 ), cutoff_freq( 0 ) { }
  25.527 +inline blip_eq_t::blip_eq_t( double t, long rf, long sr, long cf ) :
  25.528 +		treble( t ), rolloff_freq( rf ), sample_rate( sr ), cutoff_freq( cf ) { }
  25.529 +
  25.530 +inline int  Blip_Buffer::length() const         { return length_; }
  25.531 +inline long Blip_Buffer::samples_avail() const  { return (long) (offset_ >> BLIP_BUFFER_ACCURACY); }
  25.532 +inline long Blip_Buffer::sample_rate() const    { return sample_rate_; }
  25.533 +inline int  Blip_Buffer::output_latency() const { return blip_widest_impulse_ / 2; }
  25.534 +inline long Blip_Buffer::clock_rate() const     { return clock_rate_; }
  25.535 +inline void Blip_Buffer::clock_rate( long cps ) { factor_ = clock_rate_factor( clock_rate_ = cps ); }
  25.536 +
  25.537 +inline int Blip_Reader::begin( Blip_Buffer& blip_buf )
  25.538 +{
  25.539 +	buf   = blip_buf.buffer_;
  25.540 +	accum = blip_buf.reader_accum_;
  25.541 +	return blip_buf.bass_shift_;
  25.542 +}
  25.543 +
  25.544 +inline void Blip_Buffer::remove_silence( long count )
  25.545 +{
  25.546 +	// fails if you try to remove more samples than available
  25.547 +	assert( count <= samples_avail() );
  25.548 +	offset_ -= (blip_resampled_time_t) count << BLIP_BUFFER_ACCURACY;
  25.549 +}
  25.550 +
  25.551 +inline blip_ulong Blip_Buffer::unsettled() const
  25.552 +{
  25.553 +	return reader_accum_ >> (blip_sample_bits - 16);
  25.554 +}
  25.555 +
  25.556 +int const blip_max_length = 0;
  25.557 +int const blip_default_length = 250; // 1/4 second
  25.558 +
  25.559 +#endif
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/src/common/CheatSearch.cpp	Sat Mar 03 10:31:27 2012 -0600
    26.3 @@ -0,0 +1,371 @@
    26.4 +#include <cstdlib>
    26.5 +#include <cstring>
    26.6 +
    26.7 +#include "CheatSearch.h"
    26.8 +
    26.9 +CheatSearchBlock cheatSearchBlocks[4];
   26.10 +
   26.11 +CheatSearchData cheatSearchData = {
   26.12 +	0,
   26.13 +	cheatSearchBlocks
   26.14 +};
   26.15 +
   26.16 +static bool cheatSearchEQ(u32 a, u32 b)
   26.17 +{
   26.18 +	return a == b;
   26.19 +}
   26.20 +
   26.21 +static bool cheatSearchNE(u32 a, u32 b)
   26.22 +{
   26.23 +	return a != b;
   26.24 +}
   26.25 +
   26.26 +static bool cheatSearchLT(u32 a, u32 b)
   26.27 +{
   26.28 +	return a < b;
   26.29 +}
   26.30 +
   26.31 +static bool cheatSearchLE(u32 a, u32 b)
   26.32 +{
   26.33 +	return a <= b;
   26.34 +}
   26.35 +
   26.36 +static bool cheatSearchGT(u32 a, u32 b)
   26.37 +{
   26.38 +	return a > b;
   26.39 +}
   26.40 +
   26.41 +static bool cheatSearchGE(u32 a, u32 b)
   26.42 +{
   26.43 +	return a >= b;
   26.44 +}
   26.45 +
   26.46 +static bool cheatSearchSignedEQ(s32 a, s32 b)
   26.47 +{
   26.48 +	return a == b;
   26.49 +}
   26.50 +
   26.51 +static bool cheatSearchSignedNE(s32 a, s32 b)
   26.52 +{
   26.53 +	return a != b;
   26.54 +}
   26.55 +
   26.56 +static bool cheatSearchSignedLT(s32 a, s32 b)
   26.57 +{
   26.58 +	return a < b;
   26.59 +}
   26.60 +
   26.61 +static bool cheatSearchSignedLE(s32 a, s32 b)
   26.62 +{
   26.63 +	return a <= b;
   26.64 +}
   26.65 +
   26.66 +static bool cheatSearchSignedGT(s32 a, s32 b)
   26.67 +{
   26.68 +	return a > b;
   26.69 +}
   26.70 +
   26.71 +static bool cheatSearchSignedGE(s32 a, s32 b)
   26.72 +{
   26.73 +	return a >= b;
   26.74 +}
   26.75 +
   26.76 +static bool (*cheatSearchFunc[])(u32, u32) = {
   26.77 +	cheatSearchEQ,
   26.78 +	cheatSearchNE,
   26.79 +	cheatSearchLT,
   26.80 +	cheatSearchLE,
   26.81 +	cheatSearchGT,
   26.82 +	cheatSearchGE
   26.83 +};
   26.84 +
   26.85 +static bool (*cheatSearchSignedFunc[])(s32, s32) = {
   26.86 +	cheatSearchSignedEQ,
   26.87 +	cheatSearchSignedNE,
   26.88 +	cheatSearchSignedLT,
   26.89 +	cheatSearchSignedLE,
   26.90 +	cheatSearchSignedGT,
   26.91 +	cheatSearchSignedGE
   26.92 +};
   26.93 +
   26.94 +void cheatSearchSetSavedAndBits(CheatSearchBlock *block)
   26.95 +{
   26.96 +	if (!block->saved)
   26.97 +	{
   26.98 +		block->saved = (u8 *)malloc(block->size);
   26.99 +		memcpy(block->saved, block->data, block->size);
  26.100 +	}
  26.101 +	if (!block->bits)
  26.102 +	{
  26.103 +		block->bits  = (u8 *)malloc(block->size >> 3);
  26.104 +		memset(block->bits, 0xff, block->size >> 3);
  26.105 +	}
  26.106 +}
  26.107 +
  26.108 +void cheatSearchZeroBlock(CheatSearchBlock *block)
  26.109 +{
  26.110 +	block->data	  = 0;
  26.111 +	block->offset = 0;
  26.112 +	block->size	  = 0;
  26.113 +	free(block->saved);
  26.114 +	free(block->bits);
  26.115 +	block->saved  = 0;
  26.116 +	block->bits	  = 0;
  26.117 +}
  26.118 +
  26.119 +void cheatSearchCleanup(CheatSearchData *cs)
  26.120 +{
  26.121 +	int count = cs->count;
  26.122 +
  26.123 +	for (int i = 0; i < count; i++)
  26.124 +	{
  26.125 +		CheatSearchBlock &block = cs->blocks[i];
  26.126 +		free(block.saved);
  26.127 +		free(block.bits);
  26.128 +		block.saved = 0;
  26.129 +		block.bits  = 0;
  26.130 +	}
  26.131 +	cs->count = 0;
  26.132 +}
  26.133 +
  26.134 +void cheatSearchStart(const CheatSearchData *cs)
  26.135 +{
  26.136 +	int count = cs->count;
  26.137 +
  26.138 +	for (int i = 0; i < count; i++)
  26.139 +	{
  26.140 +		CheatSearchBlock *block = &cs->blocks[i];
  26.141 +
  26.142 +		memset(block->bits, 0xff, block->size >> 3);
  26.143 +		memcpy(block->saved, block->data, block->size);
  26.144 +	}
  26.145 +}
  26.146 +
  26.147 +s32 cheatSearchSignedRead(u8 *data, int off, int size)
  26.148 +{
  26.149 +	u32 res = data[off++];
  26.150 +
  26.151 +	switch (size)
  26.152 +	{
  26.153 +	case BITS_8:
  26.154 +		res <<= 24;
  26.155 +		return ((s32)res) >> 24;
  26.156 +	case BITS_16:
  26.157 +		res  |= ((u32)data[off++])<<8;
  26.158 +		res <<= 16;
  26.159 +		return ((s32)res) >> 16;
  26.160 +	case BITS_32:
  26.161 +		res |= ((u32)data[off++])<<8;
  26.162 +		res |= ((u32)data[off++])<<16;
  26.163 +		res |= ((u32)data[off++])<<24;
  26.164 +		return (s32)res;
  26.165 +	}
  26.166 +	return (s32)res;
  26.167 +}
  26.168 +
  26.169 +u32 cheatSearchRead(u8 *data, int off, int size)
  26.170 +{
  26.171 +	u32 res = data[off++];
  26.172 +	if (size == BITS_16)
  26.173 +		res |= ((u32)data[off++])<<8;
  26.174 +	else if (size == BITS_32)
  26.175 +	{
  26.176 +		res |= ((u32)data[off++])<<8;
  26.177 +		res |= ((u32)data[off++])<<16;
  26.178 +		res |= ((u32)data[off++])<<24;
  26.179 +	}
  26.180 +	return res;
  26.181 +}
  26.182 +
  26.183 +void cheatSearch(const CheatSearchData *cs, int compare, int size,
  26.184 +                 bool isSigned)
  26.185 +{
  26.186 +	if (compare < 0 || compare > SEARCH_GE)
  26.187 +		return;
  26.188 +	int inc = 1;
  26.189 +	if (size == BITS_16)
  26.190 +		inc = 2;
  26.191 +	else if (size == BITS_32)
  26.192 +		inc = 4;
  26.193 +
  26.194 +	if (isSigned)
  26.195 +	{
  26.196 +		bool (*func)(s32, s32) = cheatSearchSignedFunc[compare];
  26.197 +
  26.198 +		for (int i = 0; i < cs->count; i++)
  26.199 +		{
  26.200 +			CheatSearchBlock *block = &cs->blocks[i];
  26.201 +			int size2 = block->size;
  26.202 +			u8 *bits  = block->bits;
  26.203 +			u8 *data  = block->data;
  26.204 +			u8 *saved = block->saved;
  26.205 +
  26.206 +			for (int j = 0; j < size2; j += inc)
  26.207 +			{
  26.208 +				if (IS_BIT_SET(bits, j))
  26.209 +				{
  26.210 +					s32 a = cheatSearchSignedRead(data, j, size);
  26.211 +					s32 b = cheatSearchSignedRead(saved, j, size);
  26.212 +
  26.213 +					if (!func(a, b))
  26.214 +					{
  26.215 +						CLEAR_BIT(bits, j);
  26.216 +						if (size == BITS_16)
  26.217 +							CLEAR_BIT(bits, j+1);
  26.218 +						if (size == BITS_32)
  26.219 +						{
  26.220 +							CLEAR_BIT(bits, j+2);
  26.221 +							CLEAR_BIT(bits, j+3);
  26.222 +						}
  26.223 +					}
  26.224 +				}
  26.225 +			}
  26.226 +		}
  26.227 +	}
  26.228 +	else
  26.229 +	{
  26.230 +		bool (*func)(u32, u32) = cheatSearchFunc[compare];
  26.231 +
  26.232 +		for (int i = 0; i < cs->count; i++)
  26.233 +		{
  26.234 +			CheatSearchBlock *block = &cs->blocks[i];
  26.235 +			int size2 = block->size;
  26.236 +			u8 *bits  = block->bits;
  26.237 +			u8 *data  = block->data;
  26.238 +			u8 *saved = block->saved;
  26.239 +
  26.240 +			for (int j = 0; j < size2; j += inc)
  26.241 +			{
  26.242 +				if (IS_BIT_SET(bits, j))
  26.243 +				{
  26.244 +					u32 a = cheatSearchRead(data, j, size);
  26.245 +					u32 b = cheatSearchRead(saved, j, size);
  26.246 +
  26.247 +					if (!func(a, b))
  26.248 +					{
  26.249 +						CLEAR_BIT(bits, j);
  26.250 +						if (size == BITS_16)
  26.251 +							CLEAR_BIT(bits, j+1);
  26.252 +						if (size == BITS_32)
  26.253 +						{
  26.254 +							CLEAR_BIT(bits, j+2);
  26.255 +							CLEAR_BIT(bits, j+3);
  26.256 +						}
  26.257 +					}
  26.258 +				}
  26.259 +			}
  26.260 +		}
  26.261 +	}
  26.262 +}
  26.263 +
  26.264 +void cheatSearchValue(const CheatSearchData *cs, int compare, int size,
  26.265 +                      bool isSigned, u32 value)
  26.266 +{
  26.267 +	if (compare < 0 || compare > SEARCH_GE)
  26.268 +		return;
  26.269 +	int inc = 1;
  26.270 +	if (size == BITS_16)
  26.271 +		inc = 2;
  26.272 +	else if (size == BITS_32)
  26.273 +		inc = 4;
  26.274 +
  26.275 +	if (isSigned)
  26.276 +	{
  26.277 +		bool (*func)(s32, s32) = cheatSearchSignedFunc[compare];
  26.278 +
  26.279 +		for (int i = 0; i < cs->count; i++)
  26.280 +		{
  26.281 +			CheatSearchBlock *block = &cs->blocks[i];
  26.282 +			int size2 = block->size;
  26.283 +			u8 *bits  = block->bits;
  26.284 +			u8 *data  = block->data;
  26.285 +
  26.286 +			for (int j = 0; j < size2; j += inc)
  26.287 +			{
  26.288 +				if (IS_BIT_SET(bits, j))
  26.289 +				{
  26.290 +					s32 a = cheatSearchSignedRead(data, j, size);
  26.291 +					s32 b = (s32)value;
  26.292 +
  26.293 +					if (!func(a, b))
  26.294 +					{
  26.295 +						CLEAR_BIT(bits, j);
  26.296 +						if (size == BITS_16)
  26.297 +							CLEAR_BIT(bits, j+1);
  26.298 +						if (size == BITS_32)
  26.299 +						{
  26.300 +							CLEAR_BIT(bits, j+2);
  26.301 +							CLEAR_BIT(bits, j+3);
  26.302 +						}
  26.303 +					}
  26.304 +				}
  26.305 +			}
  26.306 +		}
  26.307 +	}
  26.308 +	else
  26.309 +	{
  26.310 +		bool (*func)(u32, u32) = cheatSearchFunc[compare];
  26.311 +
  26.312 +		for (int i = 0; i < cs->count; i++)
  26.313 +		{
  26.314 +			CheatSearchBlock *block = &cs->blocks[i];
  26.315 +			int size2 = block->size;
  26.316 +			u8 *bits  = block->bits;
  26.317 +			u8 *data  = block->data;
  26.318 +
  26.319 +			for (int j = 0; j < size2; j += inc)
  26.320 +			{
  26.321 +				if (IS_BIT_SET(bits, j))
  26.322 +				{
  26.323 +					u32 a = cheatSearchRead(data, j, size);
  26.324 +
  26.325 +					if (!func(a, value))
  26.326 +					{
  26.327 +						CLEAR_BIT(bits, j);
  26.328 +						if (size == BITS_16)
  26.329 +							CLEAR_BIT(bits, j+1);
  26.330 +						if (size == BITS_32)
  26.331 +						{
  26.332 +							CLEAR_BIT(bits, j+2);
  26.333 +							CLEAR_BIT(bits, j+3);
  26.334 +						}
  26.335 +					}
  26.336 +				}
  26.337 +			}
  26.338 +		}
  26.339 +	}
  26.340 +}
  26.341 +
  26.342 +int cheatSearchGetCount(const CheatSearchData *cs, int size)
  26.343 +{
  26.344 +	int res = 0;
  26.345 +	int inc = 1;
  26.346 +	if (size == BITS_16)
  26.347 +		inc = 2;
  26.348 +	else if (size == BITS_32)
  26.349 +		inc = 4;
  26.350 +
  26.351 +	for (int i = 0; i < cs->count; i++)
  26.352 +	{
  26.353 +		CheatSearchBlock *block = &cs->blocks[i];
  26.354 +
  26.355 +		int size2 = block->size;
  26.356 +		u8 *bits  = block->bits;
  26.357 +		for (int j = 0; j < size2; j += inc)
  26.358 +		{
  26.359 +			if (IS_BIT_SET(bits, j))
  26.360 +				res++;
  26.361 +		}
  26.362 +	}
  26.363 +	return res;
  26.364 +}
  26.365 +
  26.366 +void cheatSearchUpdateValues(const CheatSearchData *cs)
  26.367 +{
  26.368 +	for (int i = 0; i < cs->count; i++)
  26.369 +	{
  26.370 +		CheatSearchBlock *block = &cs->blocks[i];
  26.371 +
  26.372 +		memcpy(block->saved, block->data, block->size);
  26.373 +	}
  26.374 +}
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/src/common/CheatSearch.h	Sat Mar 03 10:31:27 2012 -0600
    27.3 @@ -0,0 +1,65 @@
    27.4 +#ifndef VBA_CHEATSEARCH_H
    27.5 +#define VBA_CHEATSEARCH_H
    27.6 +
    27.7 +#if _MSC_VER > 1000
    27.8 +#pragma once
    27.9 +#endif // _MSC_VER > 1000
   27.10 +
   27.11 +#include "../Port.h"
   27.12 +
   27.13 +struct CheatSearchBlock
   27.14 +{
   27.15 +	u8 *data;
   27.16 +	int size;
   27.17 +	u32 offset;
   27.18 +	u8 *saved;
   27.19 +	u8 *bits;
   27.20 +};
   27.21 +
   27.22 +struct CheatSearchData
   27.23 +{
   27.24 +	int count;
   27.25 +	CheatSearchBlock *blocks;
   27.26 +};
   27.27 +
   27.28 +enum
   27.29 +{
   27.30 +	SEARCH_EQ,
   27.31 +	SEARCH_NE,
   27.32 +	SEARCH_LT,
   27.33 +	SEARCH_LE,
   27.34 +	SEARCH_GT,
   27.35 +	SEARCH_GE
   27.36 +};
   27.37 +
   27.38 +enum
   27.39 +{
   27.40 +	BITS_8,
   27.41 +	BITS_16,
   27.42 +	BITS_32
   27.43 +};
   27.44 +
   27.45 +#define SET_BIT(bits, off) \
   27.46 +    (bits)[(off) >> 3] |= (1 << ((off) & 7))
   27.47 +
   27.48 +#define CLEAR_BIT(bits, off) \
   27.49 +    (bits)[(off) >> 3] &= ~(1 << ((off) & 7))
   27.50 +
   27.51 +#define IS_BIT_SET(bits, off) \
   27.52 +    (bits)[(off) >> 3] & (1 << ((off) & 7))
   27.53 +
   27.54 +extern CheatSearchData cheatSearchData;
   27.55 +extern void cheatSearchSetSavedAndBits(CheatSearchBlock *block);
   27.56 +extern void cheatSearchZeroBlock(CheatSearchBlock *block);
   27.57 +extern void cheatSearchCleanup(CheatSearchData *cs);
   27.58 +extern void cheatSearchStart(const CheatSearchData *cs);
   27.59 +extern void cheatSearch(const CheatSearchData *cs, int compare, int size,
   27.60 +                        bool isSigned);
   27.61 +extern void cheatSearchValue(const CheatSearchData *cs, int compare, int size,
   27.62 +                             bool isSigned, u32 value);
   27.63 +extern int cheatSearchGetCount(const CheatSearchData *cs, int size);
   27.64 +extern void cheatSearchUpdateValues(const CheatSearchData *cs);
   27.65 +extern s32 cheatSearchSignedRead(u8 *data, int off, int size);
   27.66 +extern u32 cheatSearchRead(u8 *data, int off, int size);
   27.67 +
   27.68 +#endif // VBA_CHEATSEARCH_H
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/src/common/Makefile.am	Sat Mar 03 10:31:27 2012 -0600
    28.3 @@ -0,0 +1,23 @@
    28.4 +noinst_LIBRARIES = libgbcom.a
    28.5 +
    28.6 +libgbcom_a_SOURCES = \
    28.7 +	lua-engine.cpp		\
    28.8 +	memgzio.c		\
    28.9 +	memgzio.h		\
   28.10 +	movie.cpp		\
   28.11 +	movie.h			\
   28.12 +	System.h		\
   28.13 +	Text.cpp		\
   28.14 +	Text.h			\
   28.15 +	unzip.cpp		\
   28.16 +	unzip.h			\
   28.17 +	Util.cpp		\
   28.18 +	Util.h			\
   28.19 +	vbalua.h
   28.20 +
   28.21 +AM_CPPFLAGS = \
   28.22 +	-I$(top_srcdir)/src		\
   28.23 +	-DSDL				\
   28.24 +	-DSYSCONFDIR=\"$(sysconfdir)\"
   28.25 +
   28.26 +AM_CXXFLAGS = -fno-exceptions @SDL_CFLAGS@
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/src/common/System.h	Sat Mar 03 10:31:27 2012 -0600
    29.3 @@ -0,0 +1,137 @@
    29.4 +#ifndef VBA_SYSTEM_H
    29.5 +#define VBA_SYSTEM_H
    29.6 +
    29.7 +#if _MSC_VER > 1000
    29.8 +#pragma once
    29.9 +#endif // _MSC_VER > 1000
   29.10 +
   29.11 +#include "zlib.h"
   29.12 +#include "../Port.h"
   29.13 +
   29.14 +// c++ lacks a way to implement Smart Referrences or Delphi-Style Properties
   29.15 +// in order to maintain consistency, value-copied things should not be modified too often
   29.16 +struct EmulatedSystem
   29.17 +{
   29.18 +	// main emulation function
   29.19 +	void (*emuMain)(int);
   29.20 +	// reset emulator
   29.21 +	void (*emuReset)(bool);
   29.22 +	// clean up memory
   29.23 +	void (*emuCleanUp)();
   29.24 +	// load battery file
   29.25 +	bool (*emuReadBattery)(const char *);
   29.26 +	// write battery file
   29.27 +	bool (*emuWriteBattery)(const char *);
   29.28 +	// load battery file from stream
   29.29 +	bool (*emuReadBatteryFromStream)(gzFile);
   29.30 +	// write battery file to stream
   29.31 +	bool (*emuWriteBatteryToStream)(gzFile);
   29.32 +	// load state
   29.33 +	bool (*emuReadState)(const char *);
   29.34 +	// save state
   29.35 +	bool (*emuWriteState)(const char *);
   29.36 +	// load state from stream
   29.37 +	bool (*emuReadStateFromStream)(gzFile);
   29.38 +	// save state to stream
   29.39 +	bool (*emuWriteStateToStream)(gzFile);
   29.40 +	// load memory state (rewind)
   29.41 +	bool (*emuReadMemState)(char *, int);
   29.42 +	// write memory state (rewind)
   29.43 +	bool (*emuWriteMemState)(char *, int);
   29.44 +	// write PNG file
   29.45 +	bool (*emuWritePNG)(const char *);
   29.46 +	// write BMP file
   29.47 +	bool (*emuWriteBMP)(const char *);
   29.48 +	// emulator update CPSR (ARM only)
   29.49 +	void (*emuUpdateCPSR)();
   29.50 +	// emulator has debugger
   29.51 +	bool emuHasDebugger;
   29.52 +	// clock ticks to emulate
   29.53 +	int emuCount;
   29.54 +};
   29.55 +
   29.56 +// why not convert the value type only when doing I/O?
   29.57 +struct EmulatedSystemCounters
   29.58 +{
   29.59 +	int32 frameCount;
   29.60 +	int32 lagCount;
   29.61 +	int32 extraCount;
   29.62 +	bool8 lagged;
   29.63 +	bool8 laggedLast;
   29.64 +};
   29.65 +
   29.66 +extern struct EmulatedSystem theEmulator;
   29.67 +extern struct EmulatedSystemCounters systemCounters;
   29.68 +
   29.69 +extern void log(const char *, ...);
   29.70 +
   29.71 +extern void systemGbPrint(u8 *, int, int, int, int);
   29.72 +extern int  systemScreenCapture(int);
   29.73 +extern void systemRefreshScreen();
   29.74 +extern void systemRenderFrame();
   29.75 +extern void systemRedrawScreen();
   29.76 +extern void systemUpdateListeners();
   29.77 +// updates the joystick data
   29.78 +extern void systemSetSensorX(int32);
   29.79 +extern void systemSetSensorY(int32);
   29.80 +extern void systemResetSensor();
   29.81 +extern int32 systemGetSensorX();
   29.82 +extern int32 systemGetSensorY();
   29.83 +extern void systemUpdateMotionSensor(int);
   29.84 +extern int  systemGetDefaultJoypad();
   29.85 +extern void systemSetDefaultJoypad(int);
   29.86 +extern bool systemReadJoypads();
   29.87 +// return information about the given joystick, -1 for default joystick... the bool is for if motion sensor should be handled
   29.88 +// too
   29.89 +extern u32  systemGetOriginalJoypad(int, bool);
   29.90 +extern u32  systemGetJoypad(int, bool);
   29.91 +extern void systemSetJoypad(int, u32);
   29.92 +extern void systemClearJoypads();
   29.93 +extern void systemMessage(int, const char *, ...);
   29.94 +extern void systemScreenMessage(const char *msg, int slot = 0, int duration = 3000, const char *colorList = NULL);
   29.95 +extern bool systemSoundInit();
   29.96 +extern void systemSoundShutdown();
   29.97 +extern void systemSoundPause();
   29.98 +extern void systemSoundResume();
   29.99 +extern bool systemSoundIsPaused();
  29.100 +extern void systemSoundReset();
  29.101 +extern void systemSoundWriteToBuffer();
  29.102 +extern void systemSoundClearBuffer();
  29.103 +extern bool systemSoundCanChangeQuality();
  29.104 +extern bool systemSoundSetQuality(int quality);
  29.105 +extern u32  systemGetClock();
  29.106 +extern void systemSetTitle(const char *);
  29.107 +extern void systemShowSpeed(int);
  29.108 +extern void systemIncreaseThrottle();
  29.109 +extern void systemDecreaseThrottle();
  29.110 +extern void systemSetThrottle(int);
  29.111 +extern int  systemGetThrottle();
  29.112 +extern void systemFrame();
  29.113 +extern int  systemFramesToSkip();
  29.114 +extern bool systemIsEmulating();
  29.115 +extern void systemGbBorderOn();
  29.116 +extern bool systemIsRunningGBA();
  29.117 +extern bool systemIsSpedUp();
  29.118 +extern bool systemIsPaused();
  29.119 +extern void systemSetPause(bool pause);
  29.120 +extern bool systemPauseOnFrame();
  29.121 +
  29.122 +extern int	systemCartridgeType;
  29.123 +extern int  systemSpeed;
  29.124 +extern bool systemSoundOn;
  29.125 +extern u16  systemColorMap16[0x10000];
  29.126 +extern u32  systemColorMap32[0x10000];
  29.127 +extern u16  systemGbPalette[24];
  29.128 +extern int  systemRedShift;
  29.129 +extern int  systemGreenShift;
  29.130 +extern int  systemBlueShift;
  29.131 +extern int  systemColorDepth;
  29.132 +extern int  systemDebug;
  29.133 +extern int  systemVerbose;
  29.134 +extern int  systemFrameSkip;
  29.135 +extern int  systemSaveUpdateCounter;
  29.136 +
  29.137 +#define SYSTEM_SAVE_UPDATED 30
  29.138 +#define SYSTEM_SAVE_NOT_UPDATED 0
  29.139 +
  29.140 +#endif // VBA_SYSTEM_H
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/src/common/Text.cpp	Sat Mar 03 10:31:27 2012 -0600
    30.3 @@ -0,0 +1,496 @@
    30.4 +/* FCE Ultra - NES/Famicom Emulator
    30.5 + *
    30.6 + * Copyright notice for this file:
    30.7 + *  Copyright (C) 2002 Ben Parnell
    30.8 + *
    30.9 + * This program is free software; you can redistribute it and/or modify
   30.10 + * it under the terms of the GNU General Public License as published by
   30.11 + * the Free Software Foundation; either version 2 of the License, or
   30.12 + * (at your option) any later version.
   30.13 + *
   30.14 + * This program is distributed in the hope that it will be useful,
   30.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   30.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   30.17 + * GNU General Public License for more details.
   30.18 + *
   30.19 + * You should have received a copy of the GNU General Public License
   30.20 + * along with this program; if not, write to the Free Software
   30.21 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   30.22 + */
   30.23 +
   30.24 +/* Code originally from fceu/drawing.h file, adapted by Forgotten
   30.25 + */
   30.26 +#include "System.h"
   30.27 +
   30.28 +bool outlinedText = true, transparentText = false;
   30.29 +int  textColor    = 0, textMethod = 1;
   30.30 +
   30.31 +extern u32 RGB_LOW_BITS_MASK;
   30.32 +
   30.33 +static const u8 fontdata2[2048] = {
   30.34 +	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0xbd, 0x99, 0x81, 0x7e, 0x7e, 0xff,  0xdb, 0xff,
   30.35 +	0xc3, 0xe7, 0xff, 0x7e, 0x36, 0x7f, 0x7f, 0x7f, 0x3e, 0x1c, 0x08, 0x00, 0x08, 0x1c, 0x3e, 0x7f, 0x3e, 0x1c, 0x08, 0x00,
   30.36 +	0x1c,
   30.37 +	0x3e, 0x1c, 0x7f, 0x7f, 0x3e, 0x1c, 0x3e, 0x08, 0x08, 0x1c, 0x3e, 0x7f, 0x3e, 0x1c, 0x3e, 0x00, 0x00, 0x18, 0x3c, 0x3c,
   30.38 +	0x18,
   30.39 +	0x00, 0x00, 0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00,  0xff, 0xc3,
   30.40 +	0x99, 0xbd, 0xbd, 0x99, 0xc3, 0xff, 0xf0, 0xe0, 0xf0, 0xbe, 0x33, 0x33, 0x33, 0x1e, 0x3c, 0x66, 0x66, 0x66, 0x3c, 0x18,
   30.41 +	0x7e,
   30.42 +	0x18, 0xfc, 0xcc, 0xfc, 0x0c, 0x0c, 0x0e, 0x0f, 0x07, 0xfe, 0xc6, 0xfe, 0xc6, 0xc6, 0xe6, 0x67, 0x03, 0x99, 0x5a, 0x3c,
   30.43 +	0xe7,
   30.44 +	0xe7, 0x3c, 0x5a, 0x99, 0x01, 0x07, 0x1f, 0x7f, 0x1f, 0x07, 0x01, 0x00, 0x40, 0x70, 0x7c, 0x7f, 0x7c, 0x70, 0x40, 0x00,
   30.45 +	0x18,
   30.46 +	0x3c, 0x7e, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00, 0xfe, 0xdb, 0xdb, 0xde, 0xd8,
   30.47 +	0xd8,
   30.48 +	0xd8, 0x00, 0x7c, 0xc6, 0x1c, 0x36, 0x36, 0x1c, 0x33, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x00, 0x18, 0x3c,
   30.49 +	0x7e,
   30.50 +	0x18, 0x7e, 0x3c, 0x18, 0xff, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18,
   30.51 +	0x00,
   30.52 +	0x00, 0x18, 0x30, 0x7f, 0x30, 0x18, 0x00, 0x00, 0x00, 0x0c, 0x06, 0x7f, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03,
   30.53 +	0x03,
   30.54 +	0x7f, 0x00, 0x00, 0x00, 0x24, 0x66, 0xff, 0x66, 0x24, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x00, 0x00, 0x00,
   30.55 +	0xff,
   30.56 +	0xff, 0x7e, 0x3c, 0x18, 0x00, 0x00,
   30.57 +	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1e, 0x1e, 0x0c, 0x0c, 0x00, 0x0c, 0x00, 0x36, 0x36, 0x36, 0x00,
   30.58 +	0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x7f, 0x36, 0x7f, 0x36, 0x36, 0x00, 0x0c, 0x3e, 0x03, 0x1e, 0x30, 0x1f, 0x0c, 0x00,
   30.59 +	0x00,
   30.60 +	0x63, 0x33, 0x18, 0x0c, 0x66, 0x63, 0x00, 0x1c, 0x36, 0x1c, 0x6e, 0x3b, 0x33, 0x6e, 0x00, 0x06, 0x06, 0x03, 0x00, 0x00,
   30.61 +	0x00,
   30.62 +	0x00, 0x00, 0x18, 0x0c, 0x06, 0x06, 0x06, 0x0c, 0x18, 0x00, 0x06, 0x0c, 0x18, 0x18, 0x18, 0x0c, 0x06, 0x00, 0x00, 0x66,
   30.63 +	0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x0c, 0x0c, 0x3f, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
   30.64 +	0x0c,
   30.65 +	0x06, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0c, 0x00, 0x60, 0x30, 0x18,
   30.66 +	0x0c,
   30.67 +	0x06, 0x03, 0x01, 0x00, 0x3e, 0x63, 0x73, 0x7b, 0x6f, 0x67, 0x3e, 0x00, 0x0c, 0x0e, 0x0c, 0x0c, 0x0c, 0x0c, 0x3f, 0x00,
   30.68 +	0x1e,
   30.69 +	0x33, 0x30, 0x1c, 0x06, 0x33, 0x3f, 0x00, 0x1e, 0x33, 0x30, 0x1c, 0x30, 0x33, 0x1e, 0x00, 0x38, 0x3c, 0x36, 0x33, 0x7f,
   30.70 +	0x30,
   30.71 +	0x78, 0x00, 0x3f, 0x03, 0x1f, 0x30, 0x30, 0x33, 0x1e, 0x00, 0x1c, 0x06, 0x03, 0x1f, 0x33, 0x33, 0x1e, 0x00, 0x3f, 0x33,
   30.72 +	0x30,
   30.73 +	0x18, 0x0c, 0x0c, 0x0c, 0x00, 0x1e, 0x33, 0x33, 0x1e, 0x33, 0x33, 0x1e, 0x00, 0x1e, 0x33, 0x33, 0x3e, 0x30, 0x18, 0x0e,
   30.74 +	0x00,
   30.75 +	0x00, 0x0c, 0x0c, 0x00, 0x00, 0x0c, 0x0c, 0x00, 0x00, 0x0c, 0x0c, 0x00, 0x00, 0x0c, 0x0c, 0x06, 0x18, 0x0c, 0x06, 0x03,
   30.76 +	0x06,
   30.77 +	0x0c, 0x18, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x18, 0x0c, 0x06, 0x00, 0x1e,
   30.78 +	0x33,
   30.79 +	0x30, 0x18, 0x0c, 0x00, 0x0c, 0x00,
   30.80 +	0x3e, 0x63, 0x7b, 0x7b, 0x7b, 0x03, 0x1e, 0x00, 0x0c, 0x1e, 0x33, 0x33, 0x3f, 0x33, 0x33, 0x00, 0x3f, 0x66, 0x66, 0x3e,
   30.81 +	0x66, 0x66, 0x3f, 0x00, 0x3c, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3c, 0x00, 0x1f, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1f, 0x00,
   30.82 +	0x7f,
   30.83 +	0x46, 0x16, 0x1e, 0x16, 0x46, 0x7f, 0x00, 0x7f, 0x46, 0x16, 0x1e, 0x16, 0x06, 0x0f, 0x00, 0x3c, 0x66, 0x03, 0x03, 0x73,
   30.84 +	0x66,
   30.85 +	0x7c, 0x00, 0x33, 0x33, 0x33, 0x3f, 0x33, 0x33, 0x33, 0x00, 0x1e, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x78, 0x30,
   30.86 +	0x30, 0x30, 0x33, 0x33, 0x1e, 0x00, 0x67, 0x66, 0x36, 0x1e, 0x36, 0x66, 0x67, 0x00, 0x0f, 0x06, 0x06, 0x06, 0x46, 0x66,
   30.87 +	0x7f,
   30.88 +	0x00, 0x63, 0x77, 0x7f, 0x7f, 0x6b, 0x63, 0x63, 0x00, 0x63, 0x67, 0x6f, 0x7b, 0x73, 0x63, 0x63, 0x00, 0x1c, 0x36, 0x63,
   30.89 +	0x63,
   30.90 +	0x63, 0x36, 0x1c, 0x00, 0x3f, 0x66, 0x66, 0x3e, 0x06, 0x06, 0x0f, 0x00, 0x1e, 0x33, 0x33, 0x33, 0x3b, 0x1e, 0x38, 0x00,
   30.91 +	0x3f,
   30.92 +	0x66, 0x66, 0x3e, 0x36, 0x66, 0x67, 0x00, 0x1e, 0x33, 0x07, 0x0e, 0x38, 0x33, 0x1e, 0x00, 0x3f, 0x2d, 0x0c, 0x0c, 0x0c,
   30.93 +	0x0c,
   30.94 +	0x1e, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3f, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x1e, 0x0c, 0x00, 0x63, 0x63,
   30.95 +	0x63,
   30.96 +	0x6b, 0x7f, 0x77, 0x63, 0x00, 0x63, 0x63, 0x36, 0x1c, 0x1c, 0x36, 0x63, 0x00, 0x33, 0x33, 0x33, 0x1e, 0x0c, 0x0c, 0x1e,
   30.97 +	0x00,
   30.98 +	0x7f, 0x63, 0x31, 0x18, 0x4c, 0x66, 0x7f, 0x00, 0x1e, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1e, 0x00, 0x03, 0x06, 0x0c, 0x18,
   30.99 +	0x30,
  30.100 +	0x60, 0x40, 0x00, 0x1e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1e, 0x00, 0x08, 0x1c, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00,
  30.101 +	0x00,
  30.102 +	0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
  30.103 +	0x0c, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x30, 0x3e, 0x33, 0x6e, 0x00, 0x07, 0x06, 0x06, 0x3e,
  30.104 +	0x66, 0x66, 0x3b, 0x00, 0x00, 0x00, 0x1e, 0x33, 0x03, 0x33, 0x1e, 0x00, 0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6e, 0x00,
  30.105 +	0x00,
  30.106 +	0x00, 0x1e, 0x33, 0x3f, 0x03, 0x1e, 0x00, 0x1c, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x6e, 0x33, 0x33,
  30.107 +	0x3e,
  30.108 +	0x30, 0x1f, 0x07, 0x06, 0x36, 0x6e, 0x66, 0x66, 0x67, 0x00, 0x0c, 0x00, 0x0e, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x30, 0x00,
  30.109 +	0x30, 0x30, 0x30, 0x33, 0x33, 0x1e, 0x07, 0x06, 0x66, 0x36, 0x1e, 0x36, 0x67, 0x00, 0x0e, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
  30.110 +	0x1e,
  30.111 +	0x00, 0x00, 0x00, 0x33, 0x7f, 0x7f, 0x6b, 0x63, 0x00, 0x00, 0x00, 0x1f, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00, 0x1e,
  30.112 +	0x33,
  30.113 +	0x33, 0x33, 0x1e, 0x00, 0x00, 0x00, 0x3b, 0x66, 0x66, 0x3e, 0x06, 0x0f, 0x00, 0x00, 0x6e, 0x33, 0x33, 0x3e, 0x30, 0x78,
  30.114 +	0x00,
  30.115 +	0x00, 0x3b, 0x6e, 0x66, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x3e, 0x03, 0x1e, 0x30, 0x1f, 0x00, 0x08, 0x0c, 0x3e, 0x0c, 0x0c,
  30.116 +	0x2c,
  30.117 +	0x18, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x1e, 0x0c, 0x00, 0x00, 0x00,
  30.118 +	0x63,
  30.119 +	0x6b, 0x7f, 0x7f, 0x36, 0x00, 0x00, 0x00, 0x63, 0x36, 0x1c, 0x36, 0x63, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x3e, 0x30,
  30.120 +	0x1f,
  30.121 +	0x00, 0x00, 0x3f, 0x19, 0x0c, 0x26, 0x3f, 0x00, 0x38, 0x0c, 0x0c, 0x07, 0x0c, 0x0c, 0x38, 0x00, 0x18, 0x18, 0x18, 0x00,
  30.122 +	0x18,
  30.123 +	0x18, 0x18, 0x00, 0x07, 0x0c, 0x0c, 0x38, 0x0c, 0x0c, 0x07, 0x00, 0x6e, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  30.124 +	0x08,
  30.125 +	0x1c, 0x36, 0x63, 0x63, 0x7f, 0x00,
  30.126 +	0x1e, 0x33, 0x03, 0x33, 0x1e, 0x18, 0x30, 0x1e, 0x00, 0x33, 0x00, 0x33, 0x33, 0x33, 0x7e, 0x00, 0x38, 0x00, 0x1e, 0x33,
  30.127 +	0x3f, 0x03, 0x1e, 0x00, 0x7e, 0xc3, 0x3c, 0x60, 0x7c, 0x66, 0xfc, 0x00, 0x33, 0x00, 0x1e, 0x30, 0x3e, 0x33, 0x7e, 0x00,
  30.128 +	0x07,
  30.129 +	0x00, 0x1e, 0x30, 0x3e, 0x33, 0x7e, 0x00, 0x0c, 0x0c, 0x1e, 0x30, 0x3e, 0x33, 0x7e, 0x00, 0x00, 0x00, 0x1e, 0x03, 0x03,
  30.130 +	0x1e,
  30.131 +	0x30, 0x1c, 0x7e, 0xc3, 0x3c, 0x66, 0x7e, 0x06, 0x3c, 0x00, 0x33, 0x00, 0x1e, 0x33, 0x3f, 0x03, 0x1e, 0x00, 0x07, 0x00,
  30.132 +	0x1e, 0x33, 0x3f, 0x03, 0x1e, 0x00, 0x33, 0x00, 0x0e, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x3e, 0x63, 0x1c, 0x18, 0x18, 0x18,
  30.133 +	0x3c,
  30.134 +	0x00, 0x07, 0x00, 0x0e, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x63, 0x1c, 0x36, 0x63, 0x7f, 0x63, 0x63, 0x00, 0x0c, 0x0c, 0x00,
  30.135 +	0x1e,
  30.136 +	0x33, 0x3f, 0x33, 0x00, 0x38, 0x00, 0x3f, 0x06, 0x1e, 0x06, 0x3f, 0x00, 0x00, 0x00, 0xfe, 0x30, 0xfe, 0x33, 0xfe, 0x00,
  30.137 +	0x7c,
  30.138 +	0x36, 0x33, 0x7f, 0x33, 0x33, 0x73, 0x00, 0x1e, 0x33, 0x00, 0x1e, 0x33, 0x33, 0x1e, 0x00, 0x00, 0x33, 0x00, 0x1e, 0x33,
  30.139 +	0x33,
  30.140 +	0x1e, 0x00, 0x00, 0x07, 0x00, 0x1e, 0x33, 0x33, 0x1e, 0x00, 0x1e, 0x33, 0x00, 0x33, 0x33, 0x33, 0x7e, 0x00, 0x00, 0x07,
  30.141 +	0x00,
  30.142 +	0x33, 0x33, 0x33, 0x7e, 0x00, 0x00, 0x33, 0x00, 0x33, 0x33, 0x3e, 0x30, 0x1f, 0xc3, 0x18, 0x3c, 0x66, 0x66, 0x3c, 0x18,
  30.143 +	0x00,
  30.144 +	0x33, 0x00, 0x33, 0x33, 0x33, 0x33, 0x1e, 0x00, 0x18, 0x18, 0x7e, 0x03, 0x03, 0x7e, 0x18, 0x18, 0x1c, 0x36, 0x26, 0x0f,
  30.145 +	0x06,
  30.146 +	0x67, 0x3f, 0x00, 0x33, 0x33, 0x1e, 0x3f, 0x0c, 0x3f, 0x0c, 0x0c, 0x1f, 0x33, 0x33, 0x5f, 0x63, 0xf3, 0x63, 0xe3, 0x70,
  30.147 +	0xd8,
  30.148 +	0x18, 0x3c, 0x18, 0x18, 0x1b, 0x0e,
  30.149 +	0x38, 0x00, 0x1e, 0x30, 0x3e, 0x33, 0x7e, 0x00, 0x1c, 0x00, 0x0e, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x00, 0x38, 0x00, 0x1e,
  30.150 +	0x33, 0x33, 0x1e, 0x00, 0x00, 0x38, 0x00, 0x33, 0x33, 0x33, 0x7e, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x33, 0x33, 0x33, 0x00,
  30.151 +	0x3f,
  30.152 +	0x00, 0x33, 0x37, 0x3f, 0x3b, 0x33, 0x00, 0x3c, 0x36, 0x36, 0x7c, 0x00, 0x7e, 0x00, 0x00, 0x1c, 0x36, 0x36, 0x1c, 0x00,
  30.153 +	0x3e,
  30.154 +	0x00, 0x00, 0x0c, 0x00, 0x0c, 0x06, 0x03, 0x33, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00,
  30.155 +	0x00, 0x3f, 0x30, 0x30, 0x00, 0x00, 0xc3, 0x63, 0x33, 0x7b, 0xcc, 0x66, 0x33, 0xf0, 0xc3, 0x63, 0x33, 0xdb, 0xec, 0xf6,
  30.156 +	0xf3,
  30.157 +	0xc0, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0xcc, 0x66, 0x33, 0x66, 0xcc, 0x00, 0x00, 0x00, 0x33, 0x66,
  30.158 +	0xcc,
  30.159 +	0x66, 0x33, 0x00, 0x00, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55,
  30.160 +	0xdb,
  30.161 +	0xee, 0xdb, 0x77, 0xdb, 0xee, 0xdb, 0x77, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f,
  30.162 +	0x18,
  30.163 +	0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x6c, 0x6c, 0x6c, 0x6c, 0x6f, 0x6c, 0x6c, 0x6c, 0x00, 0x00,
  30.164 +	0x00,
  30.165 +	0x00, 0x7f, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x6c, 0x6c, 0x6f, 0x60, 0x6f, 0x6c, 0x6c,
  30.166 +	0x6c,
  30.167 +	0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x7f, 0x60, 0x6f, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6f, 0x60,
  30.168 +	0x7f,
  30.169 +	0x00, 0x00, 0x00, 0x6c, 0x6c, 0x6c, 0x6c, 0x7f, 0x00, 0x00, 0x00, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00,
  30.170 +	0x00,
  30.171 +	0x00, 0x00, 0x1f, 0x18, 0x18, 0x18,
  30.172 +	0x18, 0x18, 0x18, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  30.173 +	0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
  30.174 +	0x18,
  30.175 +	0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x6c, 0x6c, 0x6c, 0x6c, 0xec,
  30.176 +	0x6c,
  30.177 +	0x6c, 0x6c, 0x6c, 0x6c, 0xec, 0x0c, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0xec, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c,
  30.178 +	0xef, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xef, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0xec, 0x0c, 0xec, 0x6c,
  30.179 +	0x6c,
  30.180 +	0x6c, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0xef, 0x00, 0xef, 0x6c, 0x6c, 0x6c, 0x18, 0x18, 0xff,
  30.181 +	0x00,
  30.182 +	0xff, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0x6c, 0x6c, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18,
  30.183 +	0x00,
  30.184 +	0x00, 0x00, 0x00, 0xff, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0xfc, 0x00, 0x00, 0x00, 0x18, 0x18, 0xf8, 0x18, 0xf8,
  30.185 +	0x00,
  30.186 +	0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c,
  30.187 +	0x6c,
  30.188 +	0x6c, 0xff, 0x6c, 0x6c, 0x6c, 0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x00, 0x00,
  30.189 +	0x00,
  30.190 +	0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0x18, 0x18, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  30.191 +	0xff,
  30.192 +	0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff,
  30.193 +	0xff,
  30.194 +	0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  30.195 +	0x00, 0x00, 0x6e, 0x3b, 0x13, 0x3b, 0x6e, 0x00, 0x00, 0x1e, 0x33, 0x1f, 0x33, 0x1f, 0x03, 0x03, 0x00, 0x3f, 0x33, 0x03,
  30.196 +	0x03, 0x03, 0x03, 0x00, 0x00, 0x7f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x3f, 0x33, 0x06, 0x0c, 0x06, 0x33, 0x3f, 0x00,
  30.197 +	0x00,
  30.198 +	0x00, 0x7e, 0x1b, 0x1b, 0x1b, 0x0e, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3e, 0x06, 0x03, 0x00, 0x6e, 0x3b, 0x18, 0x18,
  30.199 +	0x18,
  30.200 +	0x18, 0x00, 0x3f, 0x0c, 0x1e, 0x33, 0x33, 0x1e, 0x0c, 0x3f, 0x1c, 0x36, 0x63, 0x7f, 0x63, 0x36, 0x1c, 0x00, 0x1c, 0x36,
  30.201 +	0x63, 0x63, 0x36, 0x36, 0x77, 0x00, 0x38, 0x0c, 0x18, 0x3e, 0x33, 0x33, 0x1e, 0x00, 0x00, 0x00, 0x7e, 0xdb, 0xdb, 0x7e,
  30.202 +	0x00,
  30.203 +	0x00, 0x60, 0x30, 0x7e, 0xdb, 0xdb, 0x7e, 0x06, 0x03, 0x1c, 0x06, 0x03, 0x1f, 0x03, 0x06, 0x1c, 0x00, 0x1e, 0x33, 0x33,
  30.204 +	0x33,
  30.205 +	0x33, 0x33, 0x33, 0x00, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x00, 0x0c, 0x0c, 0x3f, 0x0c, 0x0c, 0x00, 0x3f, 0x00,
  30.206 +	0x06,
  30.207 +	0x0c, 0x18, 0x0c, 0x06, 0x00, 0x3f, 0x00, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x00, 0x3f, 0x00, 0x70, 0xd8, 0xd8, 0x18, 0x18,
  30.208 +	0x18,
  30.209 +	0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1b, 0x1b, 0x0e, 0x0c, 0x0c, 0x00, 0x3f, 0x00, 0x0c, 0x0c, 0x00, 0x00, 0x6e,
  30.210 +	0x3b,
  30.211 +	0x00, 0x6e, 0x3b, 0x00, 0x00, 0x1c, 0x36, 0x36, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
  30.212 +	0x00,
  30.213 +	0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0xf0, 0x30, 0x30, 0x30, 0x37, 0x36, 0x3c, 0x38, 0x1e, 0x36, 0x36, 0x36,
  30.214 +	0x36,
  30.215 +	0x00, 0x00, 0x00, 0x0e, 0x18, 0x0c, 0x06, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00, 0x00,
  30.216 +	0x00,
  30.217 +	0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  30.218 +};
  30.219 +
  30.220 +static void calcColors(const int colorNum, int & lo, int & hi, int & out)
  30.221 +{
  30.222 +	int redLo, redHi, greenLo, greenHi, blueLo, blueHi;
  30.223 +
  30.224 +	if (colorNum == 0 || colorNum == 1 || colorNum == 2 || colorNum == 6) // white, red, yellow, or magenta
  30.225 +		redLo = (0xf) << systemRedShift, redHi = (0x1f) << systemRedShift;
  30.226 +	else
  30.227 +		redLo = redHi = 0;
  30.228 +
  30.229 +	if (colorNum == 0 || colorNum == 2 || colorNum == 3 || colorNum == 4) // white, yellow, green, or cyan
  30.230 +		greenLo = (0xf) << systemGreenShift, greenHi = (0x1f) << systemGreenShift;
  30.231 +	else
  30.232 +		greenLo = greenHi = 0;
  30.233 +
  30.234 +	if (colorNum == 0 || colorNum == 4 || colorNum == 5 || colorNum == 6) // white, cyan, blue, or magenta
  30.235 +		blueLo = (0xf) << systemBlueShift, blueHi = (0x1f) << systemBlueShift;
  30.236 +	else
  30.237 +		blueLo = blueHi = 0;
  30.238 +
  30.239 +	lo = redLo + greenLo + blueLo;
  30.240 +	hi = redHi + greenHi + blueHi;
  30.241 +
  30.242 +	if (colorNum == 7) // black
  30.243 +		out = 0xffffffff; // white border
  30.244 +	else
  30.245 +		out = 0;  // black border
  30.246 +}
  30.247 +
  30.248 +int lastColID = 0;
  30.249 +static void progressColorList(const char *& colorList, int & lo, int & hi, int & out)
  30.250 +{
  30.251 +	if (*colorList)
  30.252 +	{
  30.253 +		if (*colorList != lastColID)
  30.254 +		{
  30.255 +			calcColors((int)(*colorList)-1, lo, hi, out);
  30.256 +			lastColID = *colorList;
  30.257 +		}
  30.258 +		colorList++;
  30.259 +	}
  30.260 +	else
  30.261 +	{
  30.262 +		colorList = NULL;
  30.263 +	}
  30.264 +}
  30.265 +
  30.266 +static void drawTextInternal(u8 *screen, int pitch, int x, int y,
  30.267 +                             const char *string, bool trans, const char *colorList = NULL)
  30.268 +{
  30.269 +	if (colorList && !*colorList)
  30.270 +		colorList = NULL;
  30.271 +
  30.272 +	int loCol, hiCol, outCol;
  30.273 +	calcColors(textColor, loCol, hiCol, outCol);
  30.274 +
  30.275 +	lastColID = 0;
  30.276 +
  30.277 +	const static int xd [8] = {-1, 0, 1, 1, 1, 0, -1, -1};
  30.278 +	const static int yd [8] = {-1, -1, -1, 0, 1, 1, 1, 0};
  30.279 +
  30.280 +	screen += y*pitch;
  30.281 +	int inc = 2;
  30.282 +	switch (systemColorDepth)
  30.283 +	{
  30.284 +	case 24:
  30.285 +		inc = 3;
  30.286 +		break;
  30.287 +	case 32:
  30.288 +		inc = 4;
  30.289 +		break;
  30.290 +	}
  30.291 +	screen += x*inc;
  30.292 +
  30.293 +	int xpos = x;
  30.294 +	switch (systemColorDepth)
  30.295 +	{
  30.296 +	case 16:
  30.297 +	{
  30.298 +		while (*string)
  30.299 +		{
  30.300 +			char c   = *string++;
  30.301 +			u8 * scr = screen;
  30.302 +
  30.303 +			if (colorList)
  30.304 +				progressColorList(colorList, loCol, hiCol, outCol);
  30.305 +
  30.306 +			u16  mask = u16(~RGB_LOW_BITS_MASK);
  30.307 +			u16 *s = (u16 *)scr;
  30.308 +			for (int h = 0-1; h < 8+1; h++)
  30.309 +			{
  30.310 +				for (int w = 0-1; w < 8+1; w++, s++)
  30.311 +				{
  30.312 +					int on = (h < 0 || w < 0 || h >= 8 || w >= 8) ? 0 : (fontdata2[(c<<3)+h]>>w)&1;
  30.313 +
  30.314 +					int border = 0;
  30.315 +					if (outlinedText)
  30.316 +						for (int i = 0; i < 8; i++)
  30.317 +						{
  30.318 +							int h2 = h+yd[i], w2 = w+xd[i];
  30.319 +							border = (h2 < 0 || w2 < 0 || h2 >= 8 || w2 >= 8) ? 0 : (fontdata2[(c<<3)+h2]>>w2)&1;
  30.320 +							if (border)
  30.321 +								break;
  30.322 +						}
  30.323 +
  30.324 +					if (trans)
  30.325 +					{
  30.326 +						if (on)
  30.327 +							*s = loCol +
  30.328 +							     ((*s & mask) >>1);
  30.329 +						else if (border)
  30.330 +						{
  30.331 +							*s = outCol +
  30.332 +							     ((*s & mask) >>1);
  30.333 +						}
  30.334 +					}
  30.335 +					else
  30.336 +					{
  30.337 +						if (on)
  30.338 +							*s = hiCol;
  30.339 +						else if (border)
  30.340 +							*s = outCol;
  30.341 +					}
  30.342 +				}
  30.343 +				scr += pitch;
  30.344 +				s    = (u16 *)scr;
  30.345 +			}
  30.346 +			screen += inc*8;
  30.347 +
  30.348 +			xpos += 8;
  30.349 +			if (xpos+8 > pitch>>1) // cut off text at right boundary
  30.350 +				break;
  30.351 +		}
  30.352 +		break;
  30.353 +	}
  30.354 +	case 24: // TODO: verify this code's correctness
  30.355 +	{
  30.356 +		while (*string)
  30.357 +		{
  30.358 +			char c   = *string++;
  30.359 +			u8 * scr = screen;
  30.360 +
  30.361 +			if (colorList)
  30.362 +				progressColorList(colorList, loCol, hiCol, outCol);
  30.363 +
  30.364 +			int h, w;
  30.365 +			u8 *s = (u8 *)scr;
  30.366 +			for (h = 0-1; h < 8+1; h++)
  30.367 +			{
  30.368 +				for (w = 0-1; w < 8+1; w++, s++)
  30.369 +				{
  30.370 +					int on = (h < 0 || w < 0 || h >= 8 || w >= 8) ? 0 : (fontdata2[(c<<3)+h]>>w)&1;
  30.371 +
  30.372 +					int border = 0;
  30.373 +					if (outlinedText)
  30.374 +						for (int i = 0; i < 8; i++)
  30.375 +						{
  30.376 +							int h2 = h+yd[i], w2 = w+xd[i];
  30.377 +							border = (h2 < 0 || w2 < 0 || h2 >= 8 || w2 >= 8) ? 0 : (fontdata2[(c<<3)+h2]>>w2)&1;
  30.378 +							if (border)
  30.379 +								break;
  30.380 +						}
  30.381 +
  30.382 +					if (trans)
  30.383 +					{
  30.384 +						if (on)
  30.385 +						{
  30.386 +							u32 color = hiCol;
  30.387 +							*s     = ((color & 255)>>1)+(*s>>1);
  30.388 +							*(s+1) = (((color >> 8) & 255)>>1)+(*(s+1)>>1);
  30.389 +							*(s+2) = (((color >> 16) & 255)>>1)+(*(s+2)>>1);
  30.390 +						}
  30.391 +						else if (border)
  30.392 +						{
  30.393 +							u32 color = outCol;
  30.394 +							*s     = ((color & 255)>>1)+(*s>>1);
  30.395 +							*(s+1) = (((color >> 8) & 255)>>1)+(*(s+1)>>1);
  30.396 +							*(s+2) = (((color >> 16) & 255)>>1)+(*(s+2)>>1);
  30.397 +						}
  30.398 +					}
  30.399 +					else
  30.400 +					{
  30.401 +						if (on)
  30.402 +						{
  30.403 +							u32 color = hiCol;
  30.404 +							*s     = (color & 255);
  30.405 +							*(s+1) = (color >> 8) & 255;
  30.406 +							*(s+2) = (color >> 16) & 255;
  30.407 +						}
  30.408 +						else if (border)
  30.409 +						{
  30.410 +							u32 color = outCol;
  30.411 +							*s     = (color & 255);
  30.412 +							*(s+1) = (color >> 8) & 255;
  30.413 +							*(s+2) = (color >> 16) & 255;
  30.414 +						}
  30.415 +					}
  30.416 +				}
  30.417 +				scr += pitch;
  30.418 +				s    = (u8 *)scr;
  30.419 +			}
  30.420 +			screen += inc*8;
  30.421 +
  30.422 +			xpos += 8;
  30.423 +			if (xpos+8 > pitch/3) // cut off text at right boundary
  30.424 +				break;
  30.425 +		}
  30.426 +		break;
  30.427 +	}
  30.428 +	case 32:
  30.429 +	{
  30.430 +		while (*string)
  30.431 +		{
  30.432 +			char c   = *string++;
  30.433 +			u8 * scr = screen;
  30.434 +
  30.435 +			if (colorList)
  30.436 +				progressColorList(colorList, loCol, hiCol, outCol);
  30.437 +
  30.438 +			int  h, w;
  30.439 +			u32  mask = 0xfefefe;
  30.440 +			u32 *s    = (u32 *)scr;
  30.441 +			for (h = 0-1; h < 8+1; h++)
  30.442 +			{
  30.443 +				for (w = 0-1; w < 8+1; w++, s++)
  30.444 +				{
  30.445 +					int on = (h < 0 || w < 0 || h >= 8 || w >= 8) ? 0 : (fontdata2[(c<<3)+h]>>w)&1;
  30.446 +
  30.447 +					int border = 0;
  30.448 +					if (outlinedText)
  30.449 +						for (int i = 0; i < 8; i++)
  30.450 +						{
  30.451 +							int h2 = h+yd[i], w2 = w+xd[i];
  30.452 +							border = (h2 < 0 || w2 < 0 || h2 >= 8 || w2 >= 8) ? 0 : (fontdata2[(c<<3)+h2]>>w2)&1;
  30.453 +							if (border)
  30.454 +								break;
  30.455 +						}
  30.456 +
  30.457 +					if (trans)
  30.458 +					{
  30.459 +						if (on)
  30.460 +							*s = loCol +
  30.461 +							     ((*s & mask)>>1);
  30.462 +						else if (border)
  30.463 +						{
  30.464 +							*s = outCol +
  30.465 +							     ((*s & mask)>>1);
  30.466 +						}
  30.467 +					}
  30.468 +					else
  30.469 +					{
  30.470 +						if (on)
  30.471 +							*s = hiCol;
  30.472 +						else if (border)
  30.473 +							*s = outCol;
  30.474 +					}
  30.475 +				}
  30.476 +				scr += pitch;
  30.477 +				s    = (u32 *)scr;
  30.478 +			}
  30.479 +			screen += inc*8;
  30.480 +
  30.481 +			xpos += 8;
  30.482 +			if (xpos+8 > pitch>>2) // cut off text at right boundary
  30.483 +				break;
  30.484 +		}
  30.485 +		break;
  30.486 +	}
  30.487 +	}
  30.488 +}
  30.489 +
  30.490 +void drawText(u8 *screen, int pitch, int x, int y, const char *string, const char *colorList)
  30.491 +{
  30.492 +	drawTextInternal(screen, pitch, x, y, string, transparentText, colorList);
  30.493 +}
  30.494 +
  30.495 +void drawTextTransp(u8 *screen, int pitch, int x, int y, const char *string, const char *colorList)
  30.496 +{
  30.497 +	drawTextInternal(screen, pitch, x, y, string, true, colorList);
  30.498 +}
  30.499 +
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/src/common/Text.h	Sat Mar 03 10:31:27 2012 -0600
    31.3 @@ -0,0 +1,14 @@
    31.4 +#ifndef VBA_TEXT_H
    31.5 +#define VBA_TEXT_H
    31.6 +
    31.7 +#if _MSC_VER > 1000
    31.8 +#pragma once
    31.9 +#endif // _MSC_VER > 1000
   31.10 +
   31.11 +extern void drawText(u8 *, int, int, int, const char *, const char*cl = NULL);
   31.12 +extern void drawTextTransp(u8 *, int, int, int, const char *, const char*cl = NULL);
   31.13 +
   31.14 +extern bool outlinedText, transparentText;
   31.15 +extern int  textColor, textMethod;
   31.16 +
   31.17 +#endif // VBA_TEXT_H
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/src/common/Util.cpp	Sat Mar 03 10:31:27 2012 -0600
    32.3 @@ -0,0 +1,1400 @@
    32.4 +#include <cstdio>
    32.5 +#include <cstdlib>
    32.6 +#include <cstring>
    32.7 +#include <zlib.h>
    32.8 +
    32.9 +extern "C" {
   32.10 +#include <png.h>
   32.11 +}
   32.12 +
   32.13 +#if 0
   32.14 +#include "unrarlib.h"
   32.15 +#endif
   32.16 +
   32.17 +#include "unzip.h"
   32.18 +
   32.19 +#include "../NLS.h"
   32.20 +#include "System.h"
   32.21 +#include "Util.h"
   32.22 +#include "../gba/Flash.h"
   32.23 +#include "../gba/RTC.h"
   32.24 +
   32.25 +extern "C" {
   32.26 +#include "memgzio.h"
   32.27 +}
   32.28 +
   32.29 +#ifndef _MSC_VER
   32.30 +#define _stricmp strcasecmp
   32.31 +#endif // ! _MSC_VER
   32.32 +
   32.33 +extern int32 cpuSaveType;
   32.34 +
   32.35 +extern int systemColorDepth;
   32.36 +extern int systemRedShift;
   32.37 +extern int systemGreenShift;
   32.38 +extern int systemBlueShift;
   32.39 +
   32.40 +extern u16 systemColorMap16[0x10000];
   32.41 +extern u32 systemColorMap32[0x10000];
   32.42 +
   32.43 +static int	   (ZEXPORT *utilGzWriteFunc)(gzFile, voidp, unsigned int) = NULL;
   32.44 +static int	   (ZEXPORT *utilGzReadFunc)(gzFile, voidp, unsigned int)  = NULL;
   32.45 +static int	   (ZEXPORT *utilGzCloseFunc)(gzFile) = NULL;
   32.46 +static z_off_t (ZEXPORT *utilGzSeekFunc)(gzFile, z_off_t, int) = NULL;
   32.47 +static z_off_t (ZEXPORT *utilGzTellFunc)(gzFile) = NULL;
   32.48 +
   32.49 +//Kludge to get it to compile in Linux, GCC cannot convert
   32.50 +//gzwrite function pointer to the type of utilGzWriteFunc
   32.51 +//due to void* and const void* differences
   32.52 +//--Felipe 
   32.53 +int gzWrite(gzFile file, void* buf, unsigned len){
   32.54 +	return gzwrite(file,buf,len);
   32.55 +}
   32.56 +
   32.57 +void utilPutDword(u8 *p, u32 value)
   32.58 +{
   32.59 +	*p++ = value & 255;
   32.60 +	*p++ = (value >> 8) & 255;
   32.61 +	*p++ = (value >> 16) & 255;
   32.62 +	*p	 = (value >> 24) & 255;
   32.63 +}
   32.64 +
   32.65 +void utilPutWord(u8 *p, u16 value)
   32.66 +{
   32.67 +	*p++ = value & 255;
   32.68 +	*p	 = (value >> 8) & 255;
   32.69 +}
   32.70 +
   32.71 +void utilWriteBMP(u8 *b, int w, int h, int dstDepth, u8 *pix)
   32.72 +{
   32.73 +	int sizeX = w;
   32.74 +	int sizeY = h;
   32.75 +
   32.76 +	switch (dstDepth > 0 ? dstDepth : systemColorDepth)
   32.77 +	{
   32.78 +	case 16:
   32.79 +	{
   32.80 +		u16 *p = (u16 *)(pix + (w + 2) * (h) * 2); // skip first black line
   32.81 +		for (int y = 0; y < sizeY; y++)
   32.82 +		{
   32.83 +			for (int x = 0; x < sizeX; x++)
   32.84 +			{
   32.85 +				u16 v = *p++;
   32.86 +
   32.87 +				*b++ = ((v >> systemBlueShift) & 0x01f) << 3; // B
   32.88 +				*b++ = ((v >> systemGreenShift) & 0x001f) << 3; // G
   32.89 +				*b++ = ((v >> systemRedShift) & 0x001f) << 3; // R
   32.90 +			}
   32.91 +			p++; // skip black pixel for filters
   32.92 +			p++; // skip black pixel for filters
   32.93 +			p -= 2 * (w + 2);
   32.94 +		}
   32.95 +		break;
   32.96 +	}
   32.97 +	case 24:
   32.98 +	{
   32.99 +		u8 *pixU8 = (u8 *)pix + 3 * w * (h - 1);
  32.100 +		for (int y = 0; y < sizeY; y++)
  32.101 +		{
  32.102 +			for (int x = 0; x < sizeX; x++)
  32.103 +			{
  32.104 +				if (systemRedShift > systemBlueShift)
  32.105 +				{
  32.106 +					*b++ = *pixU8++; // B
  32.107 +					*b++ = *pixU8++; // G
  32.108 +					*b++ = *pixU8++; // R
  32.109 +				}
  32.110 +				else
  32.111 +				{
  32.112 +					int red	  = *pixU8++;
  32.113 +					int green = *pixU8++;
  32.114 +					int blue  = *pixU8++;
  32.115 +
  32.116 +					*b++ = blue;
  32.117 +					*b++ = green;
  32.118 +					*b++ = red;
  32.119 +				}
  32.120 +			}
  32.121 +			pixU8 -= 2 * 3 * w;
  32.122 +		}
  32.123 +		break;
  32.124 +	}
  32.125 +	case 32:
  32.126 +	{
  32.127 +		u32 *pixU32 = (u32 *)(pix + 4 * (w + 1) * (h));
  32.128 +		for (int y = 0; y < sizeY; y++)
  32.129 +		{
  32.130 +			for (int x = 0; x < sizeX; x++)
  32.131 +			{
  32.132 +				u32 v = *pixU32++;
  32.133 +
  32.134 +				*b++ = ((v >> systemBlueShift) & 0x001f) << 3; // B
  32.135 +				*b++ = ((v >> systemGreenShift) & 0x001f) << 3; // G
  32.136 +				*b++ = ((v >> systemRedShift) & 0x001f) << 3; // R
  32.137 +			}
  32.138 +			pixU32++;
  32.139 +			pixU32 -= 2 * (w + 1);
  32.140 +		}
  32.141 +		break;
  32.142 +	}
  32.143 +	}
  32.144 +}
  32.145 +
  32.146 +bool utilWriteBMPFile(const char *fileName, int w, int h, u8 *pix)
  32.147 +{
  32.148 +	u8 writeBuffer[256 * 3];
  32.149 +
  32.150 +	FILE *fp = fopen(fileName, "wb");
  32.151 +
  32.152 +	if (!fp)
  32.153 +	{
  32.154 +		systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), fileName);
  32.155 +		return false;
  32.156 +	}
  32.157 +
  32.158 +	struct
  32.159 +	{
  32.160 +		u8 ident[2];
  32.161 +		u8 filesize[4];
  32.162 +		u8 reserved[4];
  32.163 +		u8 dataoffset[4];
  32.164 +		u8 headersize[4];
  32.165 +		u8 width[4];
  32.166 +		u8 height[4];
  32.167 +		u8 planes[2];
  32.168 +		u8 bitsperpixel[2];
  32.169 +		u8 compression[4];
  32.170 +		u8 datasize[4];
  32.171 +		u8 hres[4];
  32.172 +		u8 vres[4];
  32.173 +		u8 colors[4];
  32.174 +		u8 importantcolors[4];
  32.175 +		//    u8 pad[2];
  32.176 +	} bmpheader;
  32.177 +	memset(&bmpheader, 0, sizeof(bmpheader));
  32.178 +
  32.179 +	bmpheader.ident[0] = 'B';
  32.180 +	bmpheader.ident[1] = 'M';
  32.181 +
  32.182 +	u32 fsz = sizeof(bmpheader) + w * h * 3;
  32.183 +	utilPutDword(bmpheader.filesize, fsz);
  32.184 +	utilPutDword(bmpheader.dataoffset, 0x36);
  32.185 +	utilPutDword(bmpheader.headersize, 0x28);
  32.186 +	utilPutDword(bmpheader.width, w);
  32.187 +	utilPutDword(bmpheader.height, h);
  32.188 +	utilPutDword(bmpheader.planes, 1);
  32.189 +	utilPutDword(bmpheader.bitsperpixel, 24);
  32.190 +	utilPutDword(bmpheader.datasize, 3 * w * h);
  32.191 +
  32.192 +	fwrite(&bmpheader, 1, sizeof(bmpheader), fp);
  32.193 +
  32.194 +#if 0
  32.195 +	// FIXME: need sufficient buffer
  32.196 +	utilWriteBMP(writeBuffer, w, h, systemColorDepth, pix);
  32.197 +#else
  32.198 +	u8 *b = writeBuffer;
  32.199 +
  32.200 +	int sizeX = w;
  32.201 +	int sizeY = h;
  32.202 +
  32.203 +	switch (systemColorDepth)
  32.204 +	{
  32.205 +	case 16:
  32.206 +	{
  32.207 +		u16 *p = (u16 *)(pix + (w + 2) * (h) * 2); // skip first black line
  32.208 +		for (int y = 0; y < sizeY; y++)
  32.209 +		{
  32.210 +			for (int x = 0; x < sizeX; x++)
  32.211 +			{
  32.212 +				u16 v = *p++;
  32.213 +
  32.214 +				*b++ = ((v >> systemBlueShift) & 0x01f) << 3; // B
  32.215 +				*b++ = ((v >> systemGreenShift) & 0x001f) << 3; // G
  32.216 +				*b++ = ((v >> systemRedShift) & 0x001f) << 3; // R
  32.217 +			}
  32.218 +			p++; // skip black pixel for filters
  32.219 +			p++; // skip black pixel for filters
  32.220 +			p -= 2 * (w + 2);
  32.221 +			fwrite(writeBuffer, 1, 3 * w, fp);
  32.222 +
  32.223 +			b = writeBuffer;
  32.224 +		}
  32.225 +		break;
  32.226 +	}
  32.227 +	case 24:
  32.228 +	{
  32.229 +		u8 *pixU8 = (u8 *)pix + 3 * w * (h - 1);
  32.230 +		for (int y = 0; y < sizeY; y++)
  32.231 +		{
  32.232 +			for (int x = 0; x < sizeX; x++)
  32.233 +			{
  32.234 +				if (systemRedShift > systemBlueShift)
  32.235 +				{
  32.236 +					*b++ = *pixU8++; // B
  32.237 +					*b++ = *pixU8++; // G
  32.238 +					*b++ = *pixU8++; // R
  32.239 +				}
  32.240 +				else
  32.241 +				{
  32.242 +					int red	  = *pixU8++;
  32.243 +					int green = *pixU8++;
  32.244 +					int blue  = *pixU8++;
  32.245 +
  32.246 +					*b++ = blue;
  32.247 +					*b++ = green;
  32.248 +					*b++ = red;
  32.249 +				}
  32.250 +			}
  32.251 +			pixU8 -= 2 * 3 * w;
  32.252 +			fwrite(writeBuffer, 1, 3 * w, fp);
  32.253 +
  32.254 +			b = writeBuffer;
  32.255 +		}
  32.256 +		break;
  32.257 +	}
  32.258 +	case 32:
  32.259 +	{
  32.260 +		u32 *pixU32 = (u32 *)(pix + 4 * (w + 1) * (h));
  32.261 +		for (int y = 0; y < sizeY; y++)
  32.262 +		{
  32.263 +			for (int x = 0; x < sizeX; x++)
  32.264 +			{
  32.265 +				u32 v = *pixU32++;
  32.266 +
  32.267 +				*b++ = ((v >> systemBlueShift) & 0x001f) << 3; // B
  32.268 +				*b++ = ((v >> systemGreenShift) & 0x001f) << 3; // G
  32.269 +				*b++ = ((v >> systemRedShift) & 0x001f) << 3; // R
  32.270 +			}
  32.271 +			pixU32++;
  32.272 +			pixU32 -= 2 * (w + 1);
  32.273 +
  32.274 +			fwrite(writeBuffer, 1, 3 * w, fp);
  32.275 +
  32.276 +			b = writeBuffer;
  32.277 +		}
  32.278 +		break;
  32.279 +	}
  32.280 +	}
  32.281 +#endif
  32.282 +
  32.283 +	fclose(fp);
  32.284 +
  32.285 +	return true;
  32.286 +}
  32.287 +
  32.288 +bool utilWritePNGFile(const char *fileName, int w, int h, u8 *pix)
  32.289 +{
  32.290 +	u8 writeBuffer[256 * 3];
  32.291 +
  32.292 +	FILE *fp = fopen(fileName, "wb");
  32.293 +
  32.294 +	if (!fp)
  32.295 +	{
  32.296 +		systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), fileName);
  32.297 +		return false;
  32.298 +	}
  32.299 +
  32.300 +	png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
  32.301 +	                                              NULL,
  32.302 +	                                              NULL,
  32.303 +	                                              NULL);
  32.304 +	if (!png_ptr)
  32.305 +	{
  32.306 +		fclose(fp);
  32.307 +		return false;
  32.308 +	}
  32.309 +
  32.310 +	png_infop info_ptr = png_create_info_struct(png_ptr);
  32.311 +
  32.312 +	if (!info_ptr)
  32.313 +	{
  32.314 +		png_destroy_write_struct(&png_ptr, NULL);
  32.315 +		fclose(fp);
  32.316 +		return false;
  32.317 +	}
  32.318 +
  32.319 +	if (setjmp(png_ptr->jmpbuf))
  32.320 +	{
  32.321 +		png_destroy_write_struct(&png_ptr, NULL);
  32.322 +		fclose(fp);
  32.323 +		return false;
  32.324 +	}
  32.325 +
  32.326 +	png_init_io(png_ptr, fp);
  32.327 +
  32.328 +	png_set_IHDR(png_ptr,
  32.329 +	             info_ptr,
  32.330 +	             w,
  32.331 +	             h,
  32.332 +	             8,
  32.333 +	             PNG_COLOR_TYPE_RGB,
  32.334 +	             PNG_INTERLACE_NONE,
  32.335 +	             PNG_COMPRESSION_TYPE_DEFAULT,
  32.336 +	             PNG_FILTER_TYPE_DEFAULT);
  32.337 +
  32.338 +	png_write_info(png_ptr, info_ptr);
  32.339 +
  32.340 +	u8 *b = writeBuffer;
  32.341 +
  32.342 +	int sizeX = w;
  32.343 +	int sizeY = h;
  32.344 +
  32.345 +	switch (systemColorDepth)
  32.346 +	{
  32.347 +	case 16:
  32.348 +	{
  32.349 +		u16 *p = (u16 *)(pix + (w + 2) * 2); // skip first black line
  32.350 +		for (int y = 0; y < sizeY; y++)
  32.351 +		{
  32.352 +			for (int x = 0; x < sizeX; x++)
  32.353 +			{
  32.354 +				u16 v = *p++;
  32.355 +
  32.356 +				*b++ = ((v >> systemRedShift) & 0x001f) << 3; // R
  32.357 +				*b++ = ((v >> systemGreenShift) & 0x001f) << 3; // G
  32.358 +				*b++ = ((v >> systemBlueShift) & 0x01f) << 3; // B
  32.359 +			}
  32.360 +			p++; // skip black pixel for filters
  32.361 +			p++; // skip black pixel for filters
  32.362 +			png_write_row(png_ptr, writeBuffer);
  32.363 +
  32.364 +			b = writeBuffer;
  32.365 +		}
  32.366 +		break;
  32.367 +	}
  32.368 +	case 24:
  32.369 +	{
  32.370 +		u8 *pixU8 = (u8 *)pix;
  32.371 +		for (int y = 0; y < sizeY; y++)
  32.372 +		{
  32.373 +			for (int x = 0; x < sizeX; x++)
  32.374 +			{
  32.375 +				if (systemRedShift < systemBlueShift)
  32.376 +				{
  32.377 +					*b++ = *pixU8++; // R
  32.378 +					*b++ = *pixU8++; // G
  32.379 +					*b++ = *pixU8++; // B
  32.380 +				}
  32.381 +				else
  32.382 +				{
  32.383 +					int blue  = *pixU8++;
  32.384 +					int green = *pixU8++;
  32.385 +					int red	  = *pixU8++;
  32.386 +
  32.387 +					*b++ = red;
  32.388 +					*b++ = green;
  32.389 +					*b++ = blue;
  32.390 +				}
  32.391 +			}
  32.392 +			png_write_row(png_ptr, writeBuffer);
  32.393 +
  32.394 +			b = writeBuffer;
  32.395 +		}
  32.396 +		break;
  32.397 +	}
  32.398 +	case 32:
  32.399 +	{
  32.400 +		u32 *pixU32 = (u32 *)(pix + 4 * (w + 1));
  32.401 +		for (int y = 0; y < sizeY; y++)
  32.402 +		{
  32.403 +			for (int x = 0; x < sizeX; x++)
  32.404 +			{
  32.405 +				u32 v = *pixU32++;
  32.406 +
  32.407 +				*b++ = ((v >> systemRedShift) & 0x001f) << 3; // R
  32.408 +				*b++ = ((v >> systemGreenShift) & 0x001f) << 3; // G
  32.409 +				*b++ = ((v >> systemBlueShift) & 0x001f) << 3; // B
  32.410 +			}
  32.411 +			pixU32++;
  32.412 +
  32.413 +			png_write_row(png_ptr, writeBuffer);
  32.414 +
  32.415 +			b = writeBuffer;
  32.416 +		}
  32.417 +		break;
  32.418 +	}
  32.419 +	}
  32.420 +
  32.421 +	png_write_end(png_ptr, info_ptr);
  32.422 +
  32.423 +	png_destroy_write_struct(&png_ptr, &info_ptr);
  32.424 +
  32.425 +	fclose(fp);
  32.426 +
  32.427 +	return true;
  32.428 +}
  32.429 +
  32.430 +static int utilReadInt2(FILE *f)
  32.431 +{
  32.432 +	int res = 0;
  32.433 +	int c	= fgetc(f);
  32.434 +	if (c == EOF)
  32.435 +		return -1;
  32.436 +	res = c;
  32.437 +	c	= fgetc(f);
  32.438 +	if (c == EOF)
  32.439 +		return -1;
  32.440 +	return c + (res << 8);
  32.441 +}
  32.442 +
  32.443 +static int utilReadInt3(FILE *f)
  32.444 +{
  32.445 +	int res = 0;
  32.446 +	int c	= fgetc(f);
  32.447 +	if (c == EOF)
  32.448 +		return -1;
  32.449 +	res = c;
  32.450 +	c	= fgetc(f);
  32.451 +	if (c == EOF)
  32.452 +		return -1;
  32.453 +	res = c + (res << 8);
  32.454 +	c	= fgetc(f);
  32.455 +	if (c == EOF)
  32.456 +		return -1;
  32.457 +	return c + (res << 8);
  32.458 +}
  32.459 +
  32.460 +void utilApplyIPS(const char *ips, u8 * *r, int *s)
  32.461 +{
  32.462 +	// from the IPS spec at http://zerosoft.zophar.net/ips.htm
  32.463 +	FILE *f = fopen(ips, "rb");
  32.464 +	if (!f)
  32.465 +		return;
  32.466 +	u8 *rom	 = *r;
  32.467 +	int size = *s;
  32.468 +	if (fgetc(f) == 'P' &&
  32.469 +	    fgetc(f) == 'A' &&
  32.470 +	    fgetc(f) == 'T' &&
  32.471 +	    fgetc(f) == 'C' &&
  32.472 +	    fgetc(f) == 'H')
  32.473 +	{
  32.474 +		int b;
  32.475 +		int offset;
  32.476 +		int len;
  32.477 +		for (;; )
  32.478 +		{
  32.479 +			// read offset
  32.480 +			offset = utilReadInt3(f);
  32.481 +			// if offset == EOF, end of patch
  32.482 +			if (offset == 0x454f46)
  32.483 +				break;
  32.484 +			// read length
  32.485 +			len = utilReadInt2(f);
  32.486 +			if (!len)
  32.487 +			{
  32.488 +				// len == 0, RLE block
  32.489 +				len = utilReadInt2(f);
  32.490 +				// byte to fill
  32.491 +				int c = fgetc(f);
  32.492 +				if (c == -1)
  32.493 +					break;
  32.494 +				b = (u8)c;
  32.495 +			}
  32.496 +			else
  32.497 +				b = -1;
  32.498 +			// check if we need to reallocate our ROM
  32.499 +			if ((offset + len) >= size)
  32.500 +			{
  32.501 +				size *= 2;
  32.502 +				rom	  = (u8 *)realloc(rom, size);
  32.503 +				*r	  = rom;
  32.504 +				*s	  = size;
  32.505 +			}
  32.506 +			if (b == -1)
  32.507 +			{
  32.508 +				// normal block, just read the data
  32.509 +				if (fread(&rom[offset], 1, len, f) != (size_t)len)
  32.510 +					break;
  32.511 +			}
  32.512 +			else
  32.513 +			{
  32.514 +				// fill the region with the given byte
  32.515 +				while (len--)
  32.516 +				{
  32.517 +					rom[offset++] = b;
  32.518 +				}
  32.519 +			}
  32.520 +		}
  32.521 +	}
  32.522 +	// close the file
  32.523 +	fclose(f);
  32.524 +}
  32.525 +
  32.526 +extern bool8 cpuIsMultiBoot;
  32.527 +
  32.528 +bool utilIsGBAImage(const char *file)
  32.529 +{
  32.530 +	cpuIsMultiBoot = false;
  32.531 +	if (strlen(file) > 4)
  32.532 +	{
  32.533 +		const char *p = strrchr(file, '.');
  32.534 +
  32.535 +		if (p != NULL)
  32.536 +		{
  32.537 +			if (_stricmp(p, ".gba") == 0)
  32.538 +				return true;
  32.539 +			if (_stricmp(p, ".agb") == 0)
  32.540 +				return true;
  32.541 +			if (_stricmp(p, ".bin") == 0)
  32.542 +				return true;
  32.543 +			if (_stricmp(p, ".elf") == 0)
  32.544 +				return true;
  32.545 +			if (_stricmp(p, ".mb") == 0)
  32.546 +			{
  32.547 +				cpuIsMultiBoot = true;
  32.548 +				return true;
  32.549 +			}
  32.550 +		}
  32.551 +	}
  32.552 +
  32.553 +	return false;
  32.554 +}
  32.555 +
  32.556 +bool utilIsGBImage(const char *file)
  32.557 +{
  32.558 +	if (strlen(file) > 4)
  32.559 +	{
  32.560 +		const char *p = strrchr(file, '.');
  32.561 +
  32.562 +		if (p != NULL)
  32.563 +		{
  32.564 +			if (_stricmp(p, ".gb") == 0)
  32.565 +				return true;
  32.566 +			if (_stricmp(p, ".gbc") == 0)
  32.567 +				return true;
  32.568 +			if (_stricmp(p, ".cgb") == 0)
  32.569 +				return true;
  32.570 +			if (_stricmp(p, ".sgb") == 0)
  32.571 +				return true;
  32.572 +		}
  32.573 +	}
  32.574 +
  32.575 +	return false;
  32.576 +}
  32.577 +
  32.578 +bool utilIsGBABios(const char *file)
  32.579 +{
  32.580 +	if (strlen(file) > 4)
  32.581 +	{
  32.582 +		const char *p = strrchr(file, '.');
  32.583 +
  32.584 +		if (p != NULL)
  32.585 +		{
  32.586 +			if (_stricmp(p, ".gba") == 0)
  32.587 +				return true;
  32.588 +			if (_stricmp(p, ".agb") == 0)
  32.589 +				return true;
  32.590 +			if (_stricmp(p, ".bin") == 0)
  32.591 +				return true;
  32.592 +			if (_stricmp(p, ".bios") == 0)
  32.593 +				return true;
  32.594 +			if (_stricmp(p, ".rom") == 0)
  32.595 +				return true;
  32.596 +		}
  32.597 +	}
  32.598 +
  32.599 +	return false;
  32.600 +}
  32.601 +
  32.602 +bool utilIsGBBios(const char *file)
  32.603 +{
  32.604 +	if (strlen(file) > 4)
  32.605 +	{
  32.606 +		const char *p = strrchr(file, '.');
  32.607 +
  32.608 +		if (p != NULL)
  32.609 +		{
  32.610 +			if (_stricmp(p, ".gb") == 0)
  32.611 +				return true;
  32.612 +			if (_stricmp(p, ".bin") == 0)
  32.613 +				return true;
  32.614 +			if (_stricmp(p, ".bios") == 0)
  32.615 +				return true;
  32.616 +			if (_stricmp(p, ".rom") == 0)
  32.617 +				return true;
  32.618 +		}
  32.619 +	}
  32.620 +
  32.621 +	return false;
  32.622 +}
  32.623 +
  32.624 +bool utilIsELF(const char *file)
  32.625 +{
  32.626 +	if (strlen(file) > 4)
  32.627 +	{
  32.628 +		const char *p = strrchr(file, '.');
  32.629 +
  32.630 +		if (p != NULL)
  32.631 +		{
  32.632 +			if (_stricmp(p, ".elf") == 0)
  32.633 +				return true;
  32.634 +		}
  32.635 +	}
  32.636 +	return false;
  32.637 +}
  32.638 +
  32.639 +bool utilIsZipFile(const char *file)
  32.640 +{
  32.641 +	if (strlen(file) > 4)
  32.642 +	{
  32.643 +		const char *p = strrchr(file, '.');
  32.644 +
  32.645 +		if (p != NULL)
  32.646 +		{
  32.647 +			if (_stricmp(p, ".zip") == 0)
  32.648 +				return true;
  32.649 +		}
  32.650 +	}
  32.651 +
  32.652 +	return false;
  32.653 +}
  32.654 +
  32.655 +#if 0
  32.656 +bool utilIsRarFile(const char *file)
  32.657 +{
  32.658 +	if (strlen(file) > 4)
  32.659 +	{
  32.660 +		char *p = strrchr(file, '.');
  32.661 +
  32.662 +		if (p != NULL)
  32.663 +		{
  32.664 +			if (_stricmp(p, ".rar") == 0)
  32.665 +				return true;
  32.666 +		}
  32.667 +	}
  32.668 +
  32.669 +	return false;
  32.670 +}
  32.671 +
  32.672 +#endif
  32.673 +
  32.674 +bool utilIsGzipFile(const char *file)
  32.675 +{
  32.676 +	if (strlen(file) > 3)
  32.677 +	{
  32.678 +		const char *p = strrchr(file, '.');
  32.679 +
  32.680 +		if (p != NULL)
  32.681 +		{
  32.682 +			if (_stricmp(p, ".gz") == 0)
  32.683 +				return true;
  32.684 +			if (_stricmp(p, ".z") == 0)
  32.685 +				return true;
  32.686 +		}
  32.687 +	}
  32.688 +
  32.689 +	return false;
  32.690 +}
  32.691 +
  32.692 +void utilGetBaseName(const char *file, char *buffer)
  32.693 +{
  32.694 +	strcpy(buffer, file);
  32.695 +
  32.696 +	if (utilIsGzipFile(file))
  32.697 +	{
  32.698 +		char *p = strrchr(buffer, '.');
  32.699 +
  32.700 +		if (p)
  32.701 +			*p = 0;
  32.702 +	}
  32.703 +}
  32.704 +
  32.705 +IMAGE_TYPE utilFindType(const char *file)
  32.706 +{
  32.707 +	char buffer[2048];
  32.708 +
  32.709 +	if (utilIsZipFile(file))
  32.710 +	{
  32.711 +		unzFile unz = unzOpen(file);
  32.712 +
  32.713 +		if (unz == NULL)
  32.714 +		{
  32.715 +			systemMessage(MSG_CANNOT_OPEN_FILE, N_("Cannot open file %s"), file);
  32.716 +			return IMAGE_UNKNOWN;
  32.717 +		}
  32.718 +
  32.719 +		int r = unzGoToFirstFile(unz);
  32.720 +
  32.721 +		if (r != UNZ_OK)
  32.722 +		{
  32.723 +			unzClose(unz);
  32.724 +			systemMessage(MSG_BAD_ZIP_FILE, N_("Bad ZIP file %s"), file);
  32.725 +			return IMAGE_UNKNOWN;
  32.726 +		}
  32.727 +
  32.728 +		IMAGE_TYPE found = IMAGE_UNKNOWN;
  32.729 +
  32.730 +		unz_file_info info;
  32.731 +
  32.732 +		while (true)
  32.733 +		{
  32.734 +			r = unzGetCurrentFileInfo(unz,
  32.735 +			                          &info,
  32.736 +			                          buffer,
  32.737 +			                          sizeof(buffer),
  32.738 +			                          NULL,
  32.739 +			                          0,
  32.740 +			                          NULL,
  32.741 +			                          0);
  32.742 +
  32.743 +			if (r != UNZ_OK)
  32.744 +			{
  32.745 +				unzClose(unz);
  32.746 +				systemMessage(MSG_BAD_ZIP_FILE, N_("Bad ZIP file %s"), file);
  32.747 +				return IMAGE_UNKNOWN;
  32.748 +			}
  32.749 +
  32.750 +			if (utilIsGBAImage(buffer))
  32.751 +			{
  32.752 +				found = IMAGE_GBA;
  32.753 +				break;
  32.754 +			}
  32.755 +
  32.756 +			if (utilIsGBImage(buffer))
  32.757 +			{
  32.758 +				found = IMAGE_GB;
  32.759 +				break;
  32.760 +			}
  32.761 +
  32.762 +			r = unzGoToNextFile(unz);
  32.763 +
  32.764 +			if (r != UNZ_OK)
  32.765 +				break;
  32.766 +		}
  32.767 +		unzClose(unz);
  32.768 +
  32.769 +		if (found == IMAGE_UNKNOWN)
  32.770 +		{
  32.771 +			systemMessage(MSG_NO_IMAGE_ON_ZIP,
  32.772 +			              N_("No image found on ZIP file %s"), file);
  32.773 +			return found;
  32.774 +		}
  32.775 +		return found;
  32.776 +#if 0
  32.777 +	}
  32.778 +	else if (utilIsRarFile(file))
  32.779 +	{
  32.780 +		IMAGE_TYPE found = IMAGE_UNKNOWN;
  32.781 +
  32.782 +		ArchiveList_struct *rarList = NULL;
  32.783 +		if (urarlib_list((void *)file, (ArchiveList_struct *)&rarList))
  32.784 +		{
  32.785 +			ArchiveList_struct *p = rarList;
  32.786 +
  32.787 +			while (p)
  32.788 +			{
  32.789 +				if (utilIsGBAImage(p->item.Name))
  32.790 +				{
  32.791 +					found = IMAGE_GBA;
  32.792 +					break;
  32.793 +				}
  32.794 +
  32.795 +				if (utilIsGBImage(p->item.Name))
  32.796 +				{
  32.797 +					found = IMAGE_GB;
  32.798 +					break;
  32.799 +				}
  32.800 +				p = p->next;
  32.801 +			}
  32.802 +
  32.803 +			urarlib_freelist(rarList);
  32.804 +		}
  32.805 +		return found;
  32.806 +#endif
  32.807 +	}
  32.808 +	else
  32.809 +	{
  32.810 +		if (utilIsGzipFile(file))
  32.811 +			utilGetBaseName(file, buffer);
  32.812 +		else
  32.813 +			strcpy(buffer, file);
  32.814 +
  32.815 +		if (utilIsGBAImage(buffer))
  32.816 +			return IMAGE_GBA;
  32.817 +		if (utilIsGBImage(buffer))
  32.818 +			return IMAGE_GB;
  32.819 +	}
  32.820 +	return IMAGE_UNKNOWN;
  32.821 +}
  32.822 +
  32.823 +static int utilGetSize(int size)
  32.824 +{
  32.825 +	int res = 1;
  32.826 +	while (res < size)
  32.827 +		res <<= 1;
  32.828 +	return res;
  32.829 +}
  32.830 +
  32.831 +static u8 *utilLoadFromZip(const char *file,
  32.832 +                           bool (*accept)(const char *),
  32.833 +                           u8 *data,
  32.834 +                           int &size)
  32.835 +{
  32.836 +	char buffer[2048];
  32.837 +
  32.838 +	unzFile unz = unzOpen(file);
  32.839 +
  32.840 +	if (unz == NULL)
  32.841 +	{
  32.842 +		systemMessage(MSG_CANNOT_OPEN_FILE, N_("Cannot open file %s"), file);
  32.843 +		return NULL;
  32.844 +	}
  32.845 +	int r = unzGoToFirstFile(unz);
  32.846 +
  32.847 +	if (r != UNZ_OK)
  32.848 +	{
  32.849 +		unzClose(unz);
  32.850 +		systemMessage(MSG_BAD_ZIP_FILE, N_("Bad ZIP file %s"), file);
  32.851 +		return NULL;
  32.852 +	}
  32.853 +
  32.854 +	bool found = false;
  32.855 +
  32.856 +	unz_file_info info;
  32.857 +
  32.858 +	while (true)
  32.859 +	{
  32.860 +		r = unzGetCurrentFileInfo(unz,
  32.861 +		                          &info,
  32.862 +		                          buffer,
  32.863 +		                          sizeof(buffer),
  32.864 +		                          NULL,
  32.865 +		                          0,
  32.866 +		                          NULL,
  32.867 +		                          0);
  32.868 +
  32.869 +		if (r != UNZ_OK)
  32.870 +		{
  32.871 +			unzClose(unz);
  32.872 +			systemMessage(MSG_BAD_ZIP_FILE, N_("Bad ZIP file %s"), file);
  32.873 +			return NULL;
  32.874 +		}
  32.875 +
  32.876 +		if (accept(buffer))
  32.877 +		{
  32.878 +			found = true;
  32.879 +			break;
  32.880 +		}
  32.881 +
  32.882 +		r = unzGoToNextFile(unz);
  32.883 +
  32.884 +		if (r != UNZ_OK)
  32.885 +			break;
  32.886 +	}
  32.887 +
  32.888 +	if (!found)
  32.889 +	{
  32.890 +		unzClose(unz);
  32.891 +		systemMessage(MSG_NO_IMAGE_ON_ZIP,
  32.892 +		              N_("No image found on ZIP file %s"), file);
  32.893 +		return NULL;
  32.894 +	}
  32.895 +
  32.896 +	int fileSize = info.uncompressed_size;
  32.897 +	if (size == 0)
  32.898 +		size = fileSize;
  32.899 +	r = unzOpenCurrentFile(unz);
  32.900 +
  32.901 +	if (r != UNZ_OK)
  32.902 +	{
  32.903 +		unzClose(unz);
  32.904 +		systemMessage(MSG_ERROR_OPENING_IMAGE, N_("Error opening image %s"), buffer);
  32.905 +		return NULL;
  32.906 +	}
  32.907 +
  32.908 +	u8 *image = data;
  32.909 +
  32.910 +	if (image == NULL)
  32.911 +	{
  32.912 +		image = (u8 *)malloc(utilGetSize(size));
  32.913 +		if (image == NULL)
  32.914 +		{
  32.915 +			unzCloseCurrentFile(unz);
  32.916 +			unzClose(unz);
  32.917 +			systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
  32.918 +			              "data");
  32.919 +			return NULL;
  32.920 +		}
  32.921 +		size = fileSize;
  32.922 +	}
  32.923 +	int read = fileSize <= size ? fileSize : size;
  32.924 +	r = unzReadCurrentFile(unz,
  32.925 +	                       image,
  32.926 +	                       read);
  32.927 +
  32.928 +	unzCloseCurrentFile(unz);
  32.929 +	unzClose(unz);
  32.930 +
  32.931 +	if (r != (int)read)
  32.932 +	{
  32.933 +		systemMessage(MSG_ERROR_READING_IMAGE,
  32.934 +		              N_("Error reading image %s"), buffer);
  32.935 +		if (data == NULL)
  32.936 +			free(image);
  32.937 +		return NULL;
  32.938 +	}
  32.939 +
  32.940 +	size = fileSize;
  32.941 +
  32.942 +	return image;
  32.943 +}
  32.944 +
  32.945 +static u8 *utilLoadGzipFile(const char *file,
  32.946 +                            bool (*accept)(const char *),
  32.947 +                            u8 *data,
  32.948 +                            int &size)
  32.949 +{
  32.950 +	FILE *f = fopen(file, "rb");
  32.951 +
  32.952 +	if (f == NULL)
  32.953 +	{
  32.954 +		systemMessage(MSG_ERROR_OPENING_IMAGE, N_("Error opening image %s"), file);
  32.955 +		return NULL;
  32.956 +	}
  32.957 +
  32.958 +	fseek(f, -4, SEEK_END);
  32.959 +	int fileSize = fgetc(f) | (fgetc(f) << 8) | (fgetc(f) << 16) | (fgetc(f) << 24);
  32.960 +	fclose(f);
  32.961 +	if (size == 0)
  32.962 +		size = fileSize;
  32.963 +
  32.964 +	gzFile gz = gzopen(file, "rb");
  32.965 +
  32.966 +	if (gz == NULL)
  32.967 +	{
  32.968 +		// should not happen, but who knows?
  32.969 +		systemMessage(MSG_ERROR_OPENING_IMAGE, N_("Error opening image %s"), file);
  32.970 +		return NULL;
  32.971 +	}
  32.972 +
  32.973 +	u8 *image = data;
  32.974 +
  32.975 +	if (image == NULL)
  32.976 +	{
  32.977 +		image = (u8 *)malloc(utilGetSize(size));
  32.978 +		if (image == NULL)
  32.979 +		{
  32.980 +			systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
  32.981 +			              "data");
  32.982 +			fclose(f);
  32.983 +			return NULL;
  32.984 +		}
  32.985 +		size = fileSize;
  32.986 +	}
  32.987 +	int read = fileSize <= size ? fileSize : size;
  32.988 +	int r	 = gzread(gz, image, read);
  32.989 +	gzclose(gz);
  32.990 +
  32.991 +	if (r != (int)read)
  32.992 +	{
  32.993 +		systemMessage(MSG_ERROR_READING_IMAGE,
  32.994 +		              N_("Error reading image %s"), file);
  32.995 +		if (data == NULL)
  32.996 +			free(image);
  32.997 +		return NULL;
  32.998 +	}
  32.999 +
 32.1000 +	size = fileSize;
 32.1001 +
 32.1002 +	return image;
 32.1003 +}
 32.1004 +
 32.1005 +#if 0
 32.1006 +static u8 *utilLoadRarFile(const char *file,
 32.1007 +                           bool (*accept)(const char *),
 32.1008 +                           u8 *data,
 32.1009 +                           int &size)
 32.1010 +{
 32.1011 +	char buffer[2048];
 32.1012 +
 32.1013 +	ArchiveList_struct *rarList = NULL;
 32.1014 +	if (urarlib_list((void *)file, (ArchiveList_struct *)&rarList))
 32.1015 +	{
 32.1016 +		ArchiveList_struct *p = rarList;
 32.1017 +
 32.1018 +		bool found = false;
 32.1019 +		while (p)
 32.1020 +		{
 32.1021 +			if (accept(p->item.Name))
 32.1022 +			{
 32.1023 +				strcpy(buffer, p->item.Name);
 32.1024 +				found = true;
 32.1025 +				break;
 32.1026 +			}
 32.1027 +			p = p->next;
 32.1028 +		}
 32.1029 +		if (found)
 32.1030 +		{
 32.1031 +			void *memory		= NULL;
 32.1032 +			unsigned long lsize = 0;
 32.1033 +			size = p->item.UnpSize;
 32.1034 +			int r = urarlib_get((void *)&memory, &lsize, buffer, (void *)file, "");
 32.1035 +			if (!r)
 32.1036 +			{
 32.1037 +				systemMessage(MSG_ERROR_READING_IMAGE,
 32.1038 +				              N_("Error reading image %s"), buffer);
 32.1039 +				urarlib_freelist(rarList);
 32.1040 +				return NULL;
 32.1041 +			}
 32.1042 +			u8 *image = (u8 *)memory;
 32.1043 +			if (data != NULL)
 32.1044 +			{
 32.1045 +				memcpy(image, data, size);
 32.1046 +			}
 32.1047 +			urarlib_freelist(rarList);
 32.1048 +			return image;
 32.1049 +		}
 32.1050 +		systemMessage(MSG_NO_IMAGE_ON_ZIP,
 32.1051 +		              N_("No image found on RAR file %s"), file);
 32.1052 +		urarlib_freelist(rarList);
 32.1053 +		return NULL;
 32.1054 +	}
 32.1055 +	// nothing found
 32.1056 +	return NULL;
 32.1057 +}
 32.1058 +
 32.1059 +#endif
 32.1060 +
 32.1061 +// the caller is responsible for caling free(return value) to release the memory
 32.1062 +u8 *utilLoad(const char *file,
 32.1063 +             bool (*accept)(const char *),
 32.1064 +             u8 *data,
 32.1065 +             int &size)
 32.1066 +{
 32.1067 +	if (utilIsZipFile(file))
 32.1068 +	{
 32.1069 +		return utilLoadFromZip(file, accept, data, size);
 32.1070 +	}
 32.1071 +	if (utilIsGzipFile(file))
 32.1072 +	{
 32.1073 +		return utilLoadGzipFile(file, accept, data, size);
 32.1074 +	}
 32.1075 +#if 0
 32.1076 +	if (utilIsRarFile(file))
 32.1077 +	{
 32.1078 +		return utilLoadRarFile(file, accept, data, size);
 32.1079 +	}
 32.1080 +#endif
 32.1081 +
 32.1082 +	u8 *image = data;
 32.1083 +
 32.1084 +	FILE *f = fopen(file, "rb");
 32.1085 +
 32.1086 +	if (!f)
 32.1087 +	{
 32.1088 +		systemMessage(MSG_ERROR_OPENING_IMAGE, N_("Error opening image %s"), file);
 32.1089 +		return NULL;
 32.1090 +	}
 32.1091 +
 32.1092 +	fseek(f, 0, SEEK_END);
 32.1093 +	int fileSize = ftell(f);
 32.1094 +	fseek(f, 0, SEEK_SET);
 32.1095 +	if (size == 0)
 32.1096 +		size = fileSize;
 32.1097 +
 32.1098 +	if (image == NULL)
 32.1099 +	{
 32.1100 +		image = (u8 *)malloc(utilGetSize(size));
 32.1101 +		if (image == NULL)
 32.1102 +		{
 32.1103 +			systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
 32.1104 +			              "data");
 32.1105 +			fclose(f);
 32.1106 +			return NULL;
 32.1107 +		}
 32.1108 +		size = fileSize;
 32.1109 +	}
 32.1110 +	int read = fileSize <= size ? fileSize : size;
 32.1111 +	int r	 = fread(image, 1, read, f);
 32.1112 +	fclose(f);
 32.1113 +
 32.1114 +	if (r != (int)read)
 32.1115 +	{
 32.1116 +		systemMessage(MSG_ERROR_READING_IMAGE,
 32.1117 +		              N_("Error reading image %s"), file);
 32.1118 +		if (data == NULL)
 32.1119 +			free(image);
 32.1120 +		return NULL;
 32.1121 +	}
 32.1122 +
 32.1123 +	size = fileSize;
 32.1124 +
 32.1125 +	return image;
 32.1126 +}
 32.1127 +
 32.1128 +void utilWriteInt(gzFile gzFile, int32 i)
 32.1129 +{
 32.1130 +	utilGzWrite(gzFile, &i, sizeof(int32));
 32.1131 +}
 32.1132 +
 32.1133 +int32 utilReadInt(gzFile gzFile)
 32.1134 +{
 32.1135 +	int32 i = 0;
 32.1136 +	utilGzRead(gzFile, &i, sizeof(int32));
 32.1137 +	return i;
 32.1138 +}
 32.1139 +
 32.1140 +void utilReadData(gzFile gzFile, variable_desc *data)
 32.1141 +{
 32.1142 +	while (data->address)
 32.1143 +	{
 32.1144 +		utilGzRead(gzFile, data->address, data->size);
 32.1145 +		data++;
 32.1146 +	}
 32.1147 +}
 32.1148 +
 32.1149 +void utilWriteData(gzFile gzFile, variable_desc *data)
 32.1150 +{
 32.1151 +	while (data->address)
 32.1152 +	{
 32.1153 +		utilGzWrite(gzFile, data->address, data->size);
 32.1154 +		data++;
 32.1155 +	}
 32.1156 +}
 32.1157 +
 32.1158 +gzFile utilGzOpen(const char *file, const char *mode)
 32.1159 +{
 32.1160 +	utilGzWriteFunc = gzWrite;
 32.1161 +	utilGzReadFunc	= gzread;
 32.1162 +	utilGzCloseFunc = gzclose;
 32.1163 +	utilGzSeekFunc	= gzseek;
 32.1164 +	utilGzTellFunc	= gztell;
 32.1165 +
 32.1166 +	return gzopen(file, mode);
 32.1167 +}
 32.1168 +
 32.1169 +gzFile utilGzReopen(int id, const char *mode)
 32.1170 +{
 32.1171 +	utilGzWriteFunc = gzWrite;
 32.1172 +	utilGzReadFunc	= gzread;
 32.1173 +	utilGzCloseFunc = gzclose;
 32.1174 +	utilGzSeekFunc	= gzseek;
 32.1175 +	utilGzTellFunc	= gztell;
 32.1176 +
 32.1177 +	return gzdopen(id, mode);
 32.1178 +}
 32.1179 +
 32.1180 +gzFile utilMemGzOpen(char *memory, int available, char *mode)
 32.1181 +{
 32.1182 +	utilGzWriteFunc = memgzwrite;
 32.1183 +	utilGzReadFunc	= memgzread;
 32.1184 +	utilGzCloseFunc = memgzclose;
 32.1185 +	utilGzSeekFunc	= NULL;	// FIXME: not implemented...
 32.1186 +	utilGzTellFunc	= memtell;
 32.1187 +
 32.1188 +	return memgzopen(memory, available, mode);
 32.1189 +}
 32.1190 +
 32.1191 +int utilGzWrite(gzFile file, voidp buffer, unsigned int len)
 32.1192 +{
 32.1193 +	return utilGzWriteFunc(file, buffer, len);
 32.1194 +}
 32.1195 +
 32.1196 +int utilGzRead(gzFile file, voidp buffer, unsigned int len)
 32.1197 +{
 32.1198 +	return utilGzReadFunc(file, buffer, len);
 32.1199 +}
 32.1200 +
 32.1201 +int utilGzClose(gzFile file)
 32.1202 +{
 32.1203 +	return utilGzCloseFunc(file);
 32.1204 +}
 32.1205 +
 32.1206 +z_off_t utilGzSeek(gzFile file, z_off_t offset, int whence)
 32.1207 +{
 32.1208 +	return utilGzSeekFunc(file, offset, whence);
 32.1209 +}
 32.1210 +
 32.1211 +z_off_t utilGzTell(gzFile file)
 32.1212 +{
 32.1213 +	return utilGzTellFunc(file);
 32.1214 +}
 32.1215 +
 32.1216 +void utilGBAFindSave(const u8 *data, const int size)
 32.1217 +{
 32.1218 +	u32 *p		   = (u32 *)data;
 32.1219 +	u32 *end	   = (u32 *)(data + size);
 32.1220 +	int	 saveType  = 0;
 32.1221 +	int	 flashSize = 0x10000;
 32.1222 +	bool rtcFound  = false;
 32.1223 +
 32.1224 +	while (p  < end)
 32.1225 +	{
 32.1226 +		u32 d = READ32LE(p);
 32.1227 +
 32.1228 +		if (d == 0x52504545)
 32.1229 +		{
 32.1230 +			if (memcmp(p, "EEPROM_", 7) == 0)
 32.1231 +			{
 32.1232 +				if (saveType == 0)
 32.1233 +					saveType = 1;
 32.1234 +			}
 32.1235 +		}
 32.1236 +		else if (d == 0x4D415253)
 32.1237 +		{
 32.1238 +			if (memcmp(p, "SRAM_", 5) == 0)
 32.1239 +			{
 32.1240 +				if (saveType == 0)
 32.1241 +					saveType = 2;
 32.1242 +			}
 32.1243 +		}
 32.1244 +		else if (d == 0x53414C46)
 32.1245 +		{
 32.1246 +			if (memcmp(p, "FLASH1M_", 8) == 0)
 32.1247 +			{
 32.1248 +				if (saveType == 0)
 32.1249 +				{
 32.1250 +					saveType  = 3;
 32.1251 +					flashSize = 0x20000;
 32.1252 +				}
 32.1253 +			}
 32.1254 +			else if (memcmp(p, "FLASH", 5) == 0)
 32.1255 +			{
 32.1256 +				if (saveType == 0)
 32.1257 +				{
 32.1258 +					saveType  = 3;
 32.1259 +					flashSize = 0x10000;
 32.1260 +				}
 32.1261 +			}
 32.1262 +		}
 32.1263 +		else if (d == 0x52494953)
 32.1264 +		{
 32.1265 +			if (memcmp(p, "SIIRTC_V", 8) == 0)
 32.1266 +				rtcFound = true;
 32.1267 +		}
 32.1268 +		p++;
 32.1269 +	}
 32.1270 +	// if no matches found, then set it to NONE
 32.1271 +	if (saveType == 0)
 32.1272 +	{
 32.1273 +		saveType = 5;
 32.1274 +	}
 32.1275 +	rtcEnable(rtcFound);
 32.1276 +	cpuSaveType = saveType;
 32.1277 +	flashSetSize(flashSize);
 32.1278 +}
 32.1279 +
 32.1280 +void utilUpdateSystemColorMaps()
 32.1281 +{
 32.1282 +	switch (systemColorDepth)
 32.1283 +	{
 32.1284 +	case 16:
 32.1285 +	{
 32.1286 +		for (int i = 0; i < 0x10000; i++)
 32.1287 +		{
 32.1288 +			systemColorMap16[i] = ((i & 0x1f) << systemRedShift) |
 32.1289 +			                      (((i & 0x3e0) >> 5) << systemGreenShift) |
 32.1290 +			                      (((i & 0x7c00) >> 10) << systemBlueShift);
 32.1291 +		}
 32.1292 +		break;
 32.1293 +	}
 32.1294 +	case 24:
 32.1295 +	case 32:
 32.1296 +	{
 32.1297 +		for (int i = 0; i < 0x10000; i++)
 32.1298 +		{
 32.1299 +			systemColorMap32[i] = ((i & 0x1f) << systemRedShift) |
 32.1300 +			                      (((i & 0x3e0) >> 5) << systemGreenShift) |
 32.1301 +			                      (((i & 0x7c00) >> 10) << systemBlueShift);
 32.1302 +		}
 32.1303 +		break;
 32.1304 +	}
 32.1305 +	}
 32.1306 +}
 32.1307 +
 32.1308 +//// BIOS stuff
 32.1309 +// systemType uses the same enum values as gbEmulatorType does
 32.1310 +
 32.1311 +bool utilLoadBIOS(u8 *bios, const char *biosFileName, int systemType)
 32.1312 +{
 32.1313 +	if (bios == NULL || strlen(biosFileName) == 0)
 32.1314 +		return false;
 32.1315 +
 32.1316 +	if (systemType == 4)
 32.1317 +	{
 32.1318 +		int biosSize = 0x4000;
 32.1319 +		if (utilLoad(biosFileName, utilIsGBABios, bios, biosSize))
 32.1320 +		{
 32.1321 +			if (biosSize == 0x4000)
 32.1322 +				return true;
 32.1323 +		}
 32.1324 +	}
 32.1325 +	else
 32.1326 +	{
 32.1327 +		int biosSize = 0x100;
 32.1328 +		if (utilLoad(biosFileName, utilIsGBBios, bios, biosSize))
 32.1329 +		{
 32.1330 +			if (biosSize == 0x100)
 32.1331 +				return true;
 32.1332 +		}
 32.1333 +	}
 32.1334 +
 32.1335 +	return false;
 32.1336 +}
 32.1337 +
 32.1338 +bool utilCheckBIOS(const char *biosFileName, int systemType)
 32.1339 +{
 32.1340 +	if (strlen(biosFileName) == 0)
 32.1341 +		return false;
 32.1342 +
 32.1343 +	u8 * tempBIOS = (u8 *)malloc(systemType == 4 ? 0x4000 : 0x100);
 32.1344 +	bool result	  = utilLoadBIOS(tempBIOS, biosFileName, systemType);
 32.1345 +	free(tempBIOS);
 32.1346 +
 32.1347 +	return result;
 32.1348 +}
 32.1349 +
 32.1350 +#if 0
 32.1351 +// returns the checksum of the BIOS that will be loaded after the next restart
 32.1352 +u16 utilCalcBIOSChecksum(const u8 *bios, int systemType)
 32.1353 +{
 32.1354 +	u32	biosChecksum = 0;
 32.1355 +	if (bios)
 32.1356 +	{
 32.1357 +		int biosSize	= (systemType == 4 ? 0x4000 : 0x100);
 32.1358 +		const u16 *data = reinterpret_cast<const u16 *>(bios);
 32.1359 +		for (int i = biosSize; i > 0; i -= 2)
 32.1360 +			biosChecksum += *data++;
 32.1361 +	}
 32.1362 +
 32.1363 +	while ((biosChecksum >> 16) & 0xFFFF)
 32.1364 +		biosChecksum = (biosChecksum &0xFFFF) + ((biosChecksum >> 16) & 0xFFFF);
 32.1365 +
 32.1366 +	return biosChecksum & 0xFFFF;
 32.1367 +}
 32.1368 +#else
 32.1369 +// returns the checksum of the BIOS that will be loaded after the next restart
 32.1370 +u16 utilCalcBIOSChecksum(const u8 *bios, int systemType)
 32.1371 +{
 32.1372 +	u32	biosChecksum = 0;
 32.1373 +	if (bios)
 32.1374 +	{
 32.1375 +		int biosSize	= (systemType == 4 ? 0x4000 : 0x100);
 32.1376 +		const u32 *data = reinterpret_cast<const u32 *>(bios);
 32.1377 +		for (int i = biosSize; i > 0; i -= 4)
 32.1378 +			biosChecksum += *data++;
 32.1379 +	}
 32.1380 +
 32.1381 +	return biosChecksum & 0xFFFF;
 32.1382 +}
 32.1383 +#endif
 32.1384 +
 32.1385 +// returns the checksum of the BIOS file
 32.1386 +u16 utilCalcBIOSFileChecksum(const char *biosFileName, int systemType)
 32.1387 +{
 32.1388 +	if (strlen(biosFileName) == 0)
 32.1389 +		return 0;
 32.1390 +
 32.1391 +	u16		  biosChecksum = 0;
 32.1392 +	const int biosSize	   = (systemType == 4 ? 0x4000 : 0x100);
 32.1393 +	u8 *	  tempBIOS	   = (u8 *)malloc(biosSize);
 32.1394 +	bool	  hasBIOS	   = utilLoadBIOS(tempBIOS, biosFileName, systemType);
 32.1395 +	if (hasBIOS)
 32.1396 +	{
 32.1397 +		biosChecksum = utilCalcBIOSChecksum(tempBIOS, systemType);
 32.1398 +	}
 32.1399 +	free(tempBIOS);
 32.1400 +
 32.1401 +	return biosChecksum;
 32.1402 +}
 32.1403 +
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/src/common/Util.h	Sat Mar 03 10:31:27 2012 -0600
    33.3 @@ -0,0 +1,64 @@
    33.4 +#ifndef VBA_UTIL_H
    33.5 +#define VBA_UTIL_H
    33.6 +
    33.7 +#if _MSC_VER > 1000
    33.8 +#pragma once
    33.9 +#endif // _MSC_VER > 1000
   33.10 +
   33.11 +#include "zlib.h"
   33.12 +#include "../Port.h"
   33.13 +
   33.14 +enum IMAGE_TYPE
   33.15 +{
   33.16 +	IMAGE_UNKNOWN = -1,
   33.17 +	IMAGE_GBA	  = 0,
   33.18 +	IMAGE_GB	  = 1
   33.19 +};
   33.20 +
   33.21 +// save game
   33.22 +
   33.23 +typedef struct
   33.24 +{
   33.25 +	void *address;
   33.26 +	int	  size;
   33.27 +} variable_desc;
   33.28 +
   33.29 +extern void utilWriteBMP(u8 *out, int w, int h, int dstDepth, u8 *in);
   33.30 +extern bool utilWriteBMPFile(const char *, int, int, u8 *);
   33.31 +extern bool utilWritePNGFile(const char *, int, int, u8 *);
   33.32 +extern void utilApplyIPS(const char *ips, u8 * *rom, int *size);
   33.33 +extern bool utilIsGBAImage(const char *);
   33.34 +extern bool utilIsGBABios(const char *file);
   33.35 +extern bool utilIsELF(const char *file);
   33.36 +extern bool utilIsGBImage(const char *);
   33.37 +extern bool utilIsGBBios(const char *file);
   33.38 +extern bool utilIsZipFile(const char *);
   33.39 +extern bool utilIsGzipFile(const char *);
   33.40 +extern bool utilIsRarFile(const char *);
   33.41 +extern void utilGetBaseName(const char *, char *);
   33.42 +extern IMAGE_TYPE utilFindType(const char *);
   33.43 +extern u8 *	 utilLoad(const char *, bool (*)(const char *), u8 *, int &);
   33.44 +extern void	 utilPutDword(u8 *, u32);
   33.45 +extern void	 utilPutWord(u8 *, u16);
   33.46 +extern void	 utilWriteData(gzFile, variable_desc *);
   33.47 +extern void	 utilReadData(gzFile, variable_desc *);
   33.48 +extern int32 utilReadInt(gzFile);
   33.49 +extern void	 utilWriteInt(gzFile, int32);
   33.50 +extern gzFile utilGzOpen(const char *file, const char *mode);
   33.51 +extern gzFile utilGzReopen(int id, const char *mode);
   33.52 +extern gzFile utilMemGzOpen(char *memory, int available, char *mode);
   33.53 +extern int utilGzWrite(gzFile file, voidp buffer, unsigned int len);
   33.54 +extern int utilGzRead(gzFile file, voidp buffer, unsigned int len);
   33.55 +extern int utilGzClose(gzFile file);
   33.56 +extern z_off_t utilGzSeek(gzFile file, z_off_t offset, int whence);
   33.57 +extern z_off_t utilGzTell(gzFile file);
   33.58 +extern void utilGBAFindSave(const u8 *, const int);
   33.59 +extern void utilUpdateSystemColorMaps();
   33.60 +extern bool utilLoadBIOS(u8 *bios, const char *biosFileName, int systemType);
   33.61 +extern bool utilCheckBIOS(const char *biosFileName, int systemType);
   33.62 +extern u16 utilCalcBIOSChecksum(const u8 *bios, int systemType);
   33.63 +extern u16 utilCalcBIOSFileChecksum(const char *biosFileName, int systemType);
   33.64 +
   33.65 +extern int gzWrite(gzFile file, void* buf, unsigned len);
   33.66 +
   33.67 +#endif // VBA_UTIL_H
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/src/common/inputGlobal.h	Sat Mar 03 10:31:27 2012 -0600
    34.3 @@ -0,0 +1,48 @@
    34.4 +#ifndef VBA_INPUT_GLOBAL_H
    34.5 +#define VBA_INPUT_GLOBAL_H
    34.6 +
    34.7 +#if _MSC_VER > 1000
    34.8 +#pragma once
    34.9 +#endif // _MSC_VER > 1000
   34.10 +
   34.11 +enum
   34.12 +{
   34.13 +	KEY_BUTTON_A, KEY_BUTTON_B,
   34.14 +	KEY_BUTTON_SELECT, KEY_BUTTON_START,
   34.15 +	KEY_RIGHT, KEY_LEFT,
   34.16 +	KEY_UP, KEY_DOWN,
   34.17 +	KEY_BUTTON_R, KEY_BUTTON_L,
   34.18 +	KEY_BUTTON_SPEED, KEY_BUTTON_CAPTURE,
   34.19 +	KEY_BUTTON_GS
   34.20 +};
   34.21 +
   34.22 +#define BUTTON_MASK_A                    (0x0001)
   34.23 +#define BUTTON_MASK_B                    (0x0002)
   34.24 +#define BUTTON_MASK_SELECT               (0x0004)
   34.25 +#define BUTTON_MASK_START                (0x0008)
   34.26 +#define BUTTON_MASK_RIGHT                (0x0010)
   34.27 +#define BUTTON_MASK_LEFT                 (0x0020)
   34.28 +#define BUTTON_MASK_UP                   (0x0040)
   34.29 +#define BUTTON_MASK_DOWN                 (0x0080)
   34.30 +#define BUTTON_MASK_R                    (0x0100)
   34.31 +#define BUTTON_MASK_L                    (0x0200)
   34.32 +#define BUTTON_GB_MASK                   (BUTTON_MASK_A|BUTTON_MASK_B|BUTTON_MASK_SELECT|BUTTON_MASK_START| \
   34.33 +                                          BUTTON_MASK_RIGHT|BUTTON_MASK_LEFT|BUTTON_MASK_UP|BUTTON_MASK_DOWN)
   34.34 +#define BUTTON_GBA_ONLY                  (BUTTON_MASK_R|BUTTON_MASK_L)
   34.35 +#define BUTTON_REGULAR_MASK              (BUTTON_GB_MASK|BUTTON_GBA_ONLY)
   34.36 +#define BUTTON_MASK_OLD_RESET            (0x0400)
   34.37 +#define BUTTON_MASK_NEW_RESET            (0x0800)
   34.38 +#define BUTTON_MASK_LEFT_MOTION          (0x1000)
   34.39 +#define BUTTON_MASK_RIGHT_MOTION         (0x2000)
   34.40 +#define BUTTON_MASK_DOWN_MOTION          (0x4000)
   34.41 +#define BUTTON_MASK_UP_MOTION            (0x8000)
   34.42 +#define BUTTON_MOTION_MASK               (BUTTON_MASK_LEFT_MOTION|BUTTON_MASK_RIGHT_MOTION|BUTTON_MASK_DOWN_MOTION| \
   34.43 +                                          BUTTON_MASK_UP_MOTION)
   34.44 +#define BUTTON_RECORDINGONLY_MASK        (BUTTON_MASK_OLD_RESET|BUTTON_MASK_NEW_RESET|BUTTON_MOTION_MASK)
   34.45 +#define BUTTON_REGULAR_RECORDING_MASK	 (BUTTON_REGULAR_MASK|BUTTON_RECORDINGONLY_MASK)
   34.46 +#define BUTTON_MASK_SPEED                (0x040000)
   34.47 +#define BUTTON_MASK_CAPTURE              (0x080000)
   34.48 +#define BUTTON_MASK_GAMESHARK            (0x100000)
   34.49 +#define BUTTON_NONRECORDINGONLY_MASK     (BUTTON_MASK_SPEED|BUTTON_MASK_CAPTURE|BUTTON_MASK_GAMESHARK)
   34.50 +
   34.51 +#endif // VBA_INPUT_GLOBAL_H
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/src/common/lua-engine.cpp	Sat Mar 03 10:31:27 2012 -0600
    35.3 @@ -0,0 +1,5102 @@
    35.4 +#include <cstdio>
    35.5 +#include <cstdlib>
    35.6 +#include <malloc.h>
    35.7 +#include <string>
    35.8 +#include <cassert>
    35.9 +#include <cctype>
   35.10 +#include <cmath>
   35.11 +#include <ctime>
   35.12 +
   35.13 +#include <vector>
   35.14 +#include <map>
   35.15 +#include <string>
   35.16 +#include <algorithm>
   35.17 +
   35.18 +using namespace std;
   35.19 +
   35.20 +#ifdef __linux
   35.21 +	#include <unistd.h> // for unlink
   35.22 +	#include <sys/types.h>
   35.23 +	#include <sys/wait.h>
   35.24 +#endif
   35.25 +#if (defined(WIN32) && !defined(SDL))
   35.26 +	#include <direct.h>
   35.27 +	#include "../win32/stdafx.h"
   35.28 +	#include "../win32/Input.h"
   35.29 +	#include "../win32/MainWnd.h"
   35.30 +	#include "../win32/VBA.h"
   35.31 +	#include "../win32/LuaOpenDialog.h"
   35.32 +#else
   35.33 +	#define stricmp strcasecmp
   35.34 +	#define strnicmp strncasecmp
   35.35 +#endif
   35.36 +
   35.37 +#include "../Port.h"
   35.38 +#include "System.h"
   35.39 +#include "movie.h"
   35.40 +#include "../gba/GBA.h"
   35.41 +#include "../gba/GBAGlobals.h"
   35.42 +#include "../gb/GB.h"
   35.43 +#include "../gb/gbGlobals.h"
   35.44 +#include "../gba/GBASound.h"
   35.45 +
   35.46 +#ifdef _WIN32
   35.47 +#include "../win32/Sound.h"
   35.48 +//#include "../win32/WinMiscUtil.h"
   35.49 +extern CString winGetSavestateFilename(const CString &LogicalRomName, int nID);
   35.50 +#else
   35.51 +#endif
   35.52 +
   35.53 +extern "C"
   35.54 +{
   35.55 +#include "../lua/src/lua.h"
   35.56 +#include "../lua/src/lauxlib.h"
   35.57 +#include "../lua/src/lualib.h"
   35.58 +#include "../lua/src/lstate.h"
   35.59 +}
   35.60 +#include "vbalua.h"
   35.61 +
   35.62 +#include "../SFMT/SFMT.c"
   35.63 +
   35.64 +static void (*info_print)(int uid, const char *str);
   35.65 +static void (*info_onstart)(int uid);
   35.66 +static void (*info_onstop)(int uid);
   35.67 +static int	info_uid;
   35.68 +
   35.69 +#ifndef countof
   35.70 +	#define countof(a)  (sizeof(a) / sizeof(a[0]))
   35.71 +#endif
   35.72 +
   35.73 +static lua_State *LUA;
   35.74 +
   35.75 +// Are we running any code right now?
   35.76 +static char *luaScriptName = NULL;
   35.77 +
   35.78 +// Are we running any code right now?
   35.79 +static bool8 luaRunning = false;
   35.80 +
   35.81 +// True at the frame boundary, false otherwise.
   35.82 +static bool8 frameBoundary = false;
   35.83 +
   35.84 +// The execution speed we're running at.
   35.85 +static enum { SPEED_NORMAL, SPEED_NOTHROTTLE, SPEED_TURBO, SPEED_MAXIMUM } speedmode = SPEED_NORMAL;
   35.86 +
   35.87 +// Rerecord count skip mode
   35.88 +static bool8 skipRerecords = false;
   35.89 +
   35.90 +// Used by the registry to find our functions
   35.91 +static const char *frameAdvanceThread = "VBA.FrameAdvance";
   35.92 +static const char *guiCallbackTable	  = "VBA.GUI";
   35.93 +
   35.94 +// True if there's a thread waiting to run after a run of frame-advance.
   35.95 +static bool8 frameAdvanceWaiting = false;
   35.96 +
   35.97 +// We save our pause status in the case of a natural death.
   35.98 +//static bool8 wasPaused = false;
   35.99 +
  35.100 +// Transparency strength. 255=opaque, 0=so transparent it's invisible
  35.101 +static int transparencyModifier = 255;
  35.102 +
  35.103 +// Our joypads.
  35.104 +static uint32 lua_joypads[4];
  35.105 +static uint8  lua_joypads_used = 0;
  35.106 +
  35.107 +static bool8  gui_used = false;
  35.108 +static uint8 *gui_data = NULL;          // BGRA
  35.109 +
  35.110 +// Protects Lua calls from going nuts.
  35.111 +// We set this to a big number like 1000 and decrement it
  35.112 +// over time. The script gets knifed once this reaches zero.
  35.113 +static int numTries;
  35.114 +
  35.115 +// number of registered memory functions (1 per hooked byte)
  35.116 +static unsigned int numMemHooks;
  35.117 +
  35.118 +// Look in inputglobal.h for macros named like BUTTON_MASK_UP to determine the order.
  35.119 +static const char *button_mappings[] = {
  35.120 +	"A", "B", "select", "start", "right", "left", "up", "down", "R", "L"
  35.121 +};
  35.122 +
  35.123 +#ifdef _MSC_VER
  35.124 +	#define snprintf _snprintf
  35.125 +	#define vscprintf _vscprintf
  35.126 +#else
  35.127 +	#define stricmp strcasecmp
  35.128 +	#define strnicmp strncasecmp
  35.129 +	#define __forceinline __attribute__((always_inline))
  35.130 +#endif
  35.131 +
  35.132 +static const char *luaCallIDStrings[] =
  35.133 +{
  35.134 +	"CALL_BEFOREEMULATION",
  35.135 +	"CALL_AFTEREMULATION",
  35.136 +	"CALL_BEFOREEXIT"
  35.137 +};
  35.138 +
  35.139 +//make sure we have the right number of strings
  35.140 +CTASSERT(sizeof(luaCallIDStrings) / sizeof(*luaCallIDStrings) == LUACALL_COUNT)
  35.141 +
  35.142 +static const char *luaMemHookTypeStrings [] =
  35.143 +{
  35.144 +	"MEMHOOK_WRITE",
  35.145 +	"MEMHOOK_READ",
  35.146 +	"MEMHOOK_EXEC",
  35.147 +
  35.148 +	"MEMHOOK_WRITE_SUB",
  35.149 +	"MEMHOOK_READ_SUB",
  35.150 +	"MEMHOOK_EXEC_SUB",
  35.151 +};
  35.152 +
  35.153 +//make sure we have the right number of strings
  35.154 +CTASSERT(sizeof(luaMemHookTypeStrings) / sizeof(*luaMemHookTypeStrings) ==  LUAMEMHOOK_COUNT)
  35.155 +
  35.156 +static char *rawToCString(lua_State * L, int idx = 0);
  35.157 +static const char *toCString(lua_State *L, int idx = 0);
  35.158 +
  35.159 +// GBA memory I/O functions copied from win32/MemoryViewerDlg.cpp
  35.160 +static inline u8 CPUReadByteQuick(u32 addr)
  35.161 +{
  35.162 +	return ::map[addr >> 24].address[addr & ::map[addr >> 24].mask];
  35.163 +}
  35.164 +
  35.165 +static inline void CPUWriteByteQuick(u32 addr, u8 b)
  35.166 +{
  35.167 +	::map[addr >> 24].address[addr & ::map[addr >> 24].mask] = b;
  35.168 +}
  35.169 +
  35.170 +static inline u16 CPUReadHalfWordQuick(u32 addr)
  35.171 +{
  35.172 +	return *((u16 *) &::map[addr >> 24].address[addr & ::map[addr >> 24].mask]);
  35.173 +}
  35.174 +
  35.175 +static inline void CPUWriteHalfWordQuick(u32 addr, u16 b)
  35.176 +{
  35.177 +	*((u16 *) &::map[addr >> 24].address[addr & ::map[addr >> 24].mask]) = b;
  35.178 +}
  35.179 +
  35.180 +static inline u32 CPUReadMemoryQuick(u32 addr)
  35.181 +{
  35.182 +	return *((u32 *) &::map[addr >> 24].address[addr & ::map[addr >> 24].mask]);
  35.183 +}
  35.184 +
  35.185 +static inline void CPUWriteMemoryQuick(u32 addr, u32 b)
  35.186 +{
  35.187 +	*((u32 *) &::map[addr >> 24].address[addr & ::map[addr >> 24].mask]) = b;
  35.188 +}
  35.189 +
  35.190 +// GB
  35.191 +static inline u8 gbReadMemoryQuick8(u16 addr)
  35.192 +{
  35.193 +	return gbReadMemoryQuick(addr);
  35.194 +}
  35.195 +
  35.196 +static inline void gbWriteMemoryQuick8(u16 addr, u8 b)
  35.197 +{
  35.198 +	gbWriteMemoryQuick(addr, b);
  35.199 +}
  35.200 +
  35.201 +static inline u16 gbReadMemoryQuick16(u16 addr)
  35.202 +{
  35.203 +	return (gbReadMemoryQuick(addr + 1) << 8) | gbReadMemoryQuick(addr);
  35.204 +}
  35.205 +
  35.206 +static inline void gbWriteMemoryQuick16(u16 addr, u16 b)
  35.207 +{
  35.208 +	gbWriteMemoryQuick(addr, b & 0xff);
  35.209 +	gbWriteMemoryQuick(addr + 1, (b >> 8) & 0xff);
  35.210 +}
  35.211 +
  35.212 +static inline u32 gbReadMemoryQuick32(u16 addr)
  35.213 +{
  35.214 +	return (gbReadMemoryQuick(addr + 3) << 24) |
  35.215 +	       (gbReadMemoryQuick(addr + 2) << 16) |
  35.216 +	       (gbReadMemoryQuick(addr + 1) << 8) |
  35.217 +	       gbReadMemoryQuick(addr);
  35.218 +}
  35.219 +
  35.220 +static inline void gbWriteMemoryQuick32(u16 addr, u32 b)
  35.221 +{
  35.222 +	gbWriteMemoryQuick(addr, b & 0xff);
  35.223 +	gbWriteMemoryQuick(addr + 1, (b >> 8) & 0xff);
  35.224 +	gbWriteMemoryQuick(addr + 2, (b >> 16) & 0xff);
  35.225 +	gbWriteMemoryQuick(addr + 1, (b >> 24) & 0xff);
  35.226 +}
  35.227 +
  35.228 +static inline u8 gbReadROMQuick8(u32 addr)
  35.229 +{
  35.230 +	return gbReadROMQuick(addr & gbRomSizeMask);
  35.231 +}
  35.232 +
  35.233 +static inline u8 gbReadROMQuick16(u32 addr)
  35.234 +{
  35.235 +	return (gbReadROMQuick(addr+1 & gbRomSizeMask) << 8) | gbReadROMQuick(addr & gbRomSizeMask);
  35.236 +}
  35.237 +
  35.238 +static inline u8 gbReadROMQuick32(u32 addr)
  35.239 +{
  35.240 +	return (gbReadROMQuick(addr+3 & gbRomSizeMask) << 24) |
  35.241 +	       (gbReadROMQuick(addr+2 & gbRomSizeMask) << 16) |
  35.242 +	       (gbReadROMQuick(addr+1 & gbRomSizeMask) << 8) |
  35.243 +	       gbReadROMQuick(addr & gbRomSizeMask);
  35.244 +}
  35.245 +
  35.246 +typedef void (*GetColorFunc)(const uint8 *, uint8 *, uint8 *, uint8 *);
  35.247 +typedef void (*SetColorFunc)(uint8 *, uint8, uint8, uint8);
  35.248 +
  35.249 +static void getColor16(const uint8 *s, uint8 *r, uint8 *g, uint8 *b)
  35.250 +{
  35.251 +	u16 v = *(const uint16 *)s;
  35.252 +	*r = ((v >> systemBlueShift) & 0x001f) << 3;
  35.253 +	*g = ((v >> systemGreenShift) & 0x001f) << 3;
  35.254 +	*b = ((v >> systemRedShift) & 0x001f) << 3;
  35.255 +}
  35.256 +
  35.257 +static void getColor24(const uint8 *s, uint8 *r, uint8 *g, uint8 *b)
  35.258 +{
  35.259 +	if (systemRedShift > systemBlueShift)
  35.260 +		*b = s[0], *g = s[1], *r = s[2];
  35.261 +	else
  35.262 +		*r = s[0], *g = s[1], *b = s[2];
  35.263 +}
  35.264 +
  35.265 +static void getColor32(const uint8 *s, uint8 *r, uint8 *g, uint8 *b)
  35.266 +{
  35.267 +	u32 v = *(const uint32 *)s;
  35.268 +	*b = ((v >> systemBlueShift) & 0x001f) << 3;
  35.269 +	*g = ((v >> systemGreenShift) & 0x001f) << 3;
  35.270 +	*r = ((v >> systemRedShift) & 0x001f) << 3;
  35.271 +}
  35.272 +
  35.273 +static void setColor16(uint8 *s, uint8 r, uint8 g, uint8 b)
  35.274 +{
  35.275 +	*(uint16 *)s = ((b >> 3) & 0x01f) <<
  35.276 +	               systemBlueShift |
  35.277 +	               ((g >> 3) & 0x01f) <<
  35.278 +	               systemGreenShift |
  35.279 +	               ((r >> 3) & 0x01f) <<
  35.280 +	               systemRedShift;
  35.281 +}
  35.282 +
  35.283 +static void setColor24(uint8 *s, uint8 r, uint8 g, uint8 b)
  35.284 +{
  35.285 +	if (systemRedShift > systemBlueShift)
  35.286 +		s[0] = b, s[1] = g, s[2] = r;
  35.287 +	else
  35.288 +		s[0] = r, s[1] = g, s[2] = b;
  35.289 +}
  35.290 +
  35.291 +static void setColor32(uint8 *s, uint8 r, uint8 g, uint8 b)
  35.292 +{
  35.293 +	*(uint32 *)s = ((b >> 3) & 0x01f) <<
  35.294 +	               systemBlueShift |
  35.295 +	               ((g >> 3) & 0x01f) <<
  35.296 +	               systemGreenShift |
  35.297 +	               ((r >> 3) & 0x01f) <<
  35.298 +	               systemRedShift;
  35.299 +}
  35.300 +
  35.301 +static bool getColorIOFunc(int depth, GetColorFunc *getColor, SetColorFunc *setColor)
  35.302 +{
  35.303 +	switch (depth)
  35.304 +	{
  35.305 +	case 16:
  35.306 +		if (getColor)
  35.307 +			*getColor = getColor16;
  35.308 +		if (setColor)
  35.309 +			*setColor = setColor16;
  35.310 +		return true;
  35.311 +	case 24:
  35.312 +		if (getColor)
  35.313 +			*getColor = getColor24;
  35.314 +		if (setColor)
  35.315 +			*setColor = setColor24;
  35.316 +		return true;
  35.317 +	case 32:
  35.318 +		if (getColor)
  35.319 +			*getColor = getColor32;
  35.320 +		if (setColor)
  35.321 +			*setColor = setColor32;
  35.322 +		return true;
  35.323 +	default:
  35.324 +		return false;
  35.325 +	}
  35.326 +}
  35.327 +
  35.328 +/**
  35.329 + * Resets emulator speed / pause states after script exit.
  35.330 + */
  35.331 +static void VBALuaOnStop(void)
  35.332 +{
  35.333 +	luaRunning		 = false;
  35.334 +	lua_joypads_used = 0;
  35.335 +	gui_used		 = false;
  35.336 +	//if (wasPaused)
  35.337 +	//	systemSetPause(true);
  35.338 +}
  35.339 +
  35.340 +/**
  35.341 + * Asks Lua if it wants control of the emulator's speed.
  35.342 + * Returns 0 if no, 1 if yes. If yes, we also tamper with the
  35.343 + * IPPU's settings for speed ourselves, so the calling code
  35.344 + * need not do anything.
  35.345 + */
  35.346 +int VBALuaSpeed(void)
  35.347 +{
  35.348 +	if (!LUA || !luaRunning)
  35.349 +		return 0;
  35.350 +
  35.351 +	//printf("%d\n", speedmode);
  35.352 +	switch (speedmode)
  35.353 +	{
  35.354 +	/*
  35.355 +	   case SPEED_NORMAL:
  35.356 +	    return 0;
  35.357 +	   case SPEED_NOTHROTTLE:
  35.358 +	    IPPU.RenderThisFrame = true;
  35.359 +	    return 1;
  35.360 +
  35.361 +	   case SPEED_TURBO:
  35.362 +	    IPPU.SkippedFrames++;
  35.363 +	    if (IPPU.SkippedFrames >= 40) {
  35.364 +	        IPPU.SkippedFrames = 0;
  35.365 +	        IPPU.RenderThisFrame = true;
  35.366 +	    }
  35.367 +	    else
  35.368 +	        IPPU.RenderThisFrame = false;
  35.369 +	    return 1;
  35.370 +
  35.371 +	   // In mode 3, SkippedFrames is set to zero so that the frame
  35.372 +	   // skipping code doesn't try anything funny.
  35.373 +	   case SPEED_MAXIMUM:
  35.374 +	    IPPU.SkippedFrames=0;
  35.375 +	    IPPU.RenderThisFrame = false;
  35.376 +	    return 1;
  35.377 +	 */
  35.378 +	case 0: // FIXME: to get rid of the warning
  35.379 +	default:
  35.380 +		assert(false);
  35.381 +		return 0;
  35.382 +	}
  35.383 +}
  35.384 +
  35.385 +///////////////////////////
  35.386 +// vba.speedmode(string mode)
  35.387 +//
  35.388 +//   Takes control of the emulation speed
  35.389 +//   of the system. Normal is normal speed (60fps, 50 for PAL),
  35.390 +//   nothrottle disables speed control but renders every frame,
  35.391 +//   turbo renders only a few frames in order to speed up emulation,
  35.392 +
  35.393 +//   maximum renders no frames
  35.394 +static int vba_speedmode(lua_State *L)
  35.395 +{
  35.396 +	const char *mode = luaL_checkstring(L, 1);
  35.397 +
  35.398 +	if (strcasecmp(mode, "normal") == 0)
  35.399 +	{
  35.400 +		speedmode = SPEED_NORMAL;
  35.401 +	}
  35.402 +	else if (strcasecmp(mode, "nothrottle") == 0)
  35.403 +	{
  35.404 +		speedmode = SPEED_NOTHROTTLE;
  35.405 +	}
  35.406 +	else if (strcasecmp(mode, "turbo") == 0)
  35.407 +	{
  35.408 +		speedmode = SPEED_TURBO;
  35.409 +	}
  35.410 +	else if (strcasecmp(mode, "maximum") == 0)
  35.411 +	{
  35.412 +		speedmode = SPEED_MAXIMUM;
  35.413 +	}
  35.414 +	else
  35.415 +		luaL_error(L, "Invalid mode %s to vba.speedmode", mode);
  35.416 +
  35.417 +	//printf("new speed mode:  %d\n", speedmode);
  35.418 +	return 0;
  35.419 +}
  35.420 +
  35.421 +// vba.frameadvnace()
  35.422 +//
  35.423 +//  Executes a frame advance. Occurs by yielding the coroutine, then re-running
  35.424 +
  35.425 +//  when we break out.
  35.426 +static int vba_frameadvance(lua_State *L)
  35.427 +{
  35.428 +	// We're going to sleep for a frame-advance. Take notes.
  35.429 +	if (frameAdvanceWaiting)
  35.430 +		return luaL_error(L, "can't call vba.frameadvance() from here");
  35.431 +
  35.432 +	frameAdvanceWaiting = true;
  35.433 +
  35.434 +	// Don't do this! The user won't like us sending their emulator out of control!
  35.435 +	//	Settings.FrameAdvance = true;
  35.436 +	// Now we can yield to the main
  35.437 +	return lua_yield(L, 0);
  35.438 +
  35.439 +	// It's actually rather disappointing...
  35.440 +}
  35.441 +
  35.442 +// vba.pause()
  35.443 +//
  35.444 +//  Pauses the emulator, function "waits" until the user unpauses.
  35.445 +//  This function MAY be called from a non-frame boundary, but the frame
  35.446 +
  35.447 +//  finishes executing anwyays. In this case, the function returns immediately.
  35.448 +static int vba_pause(lua_State *L)
  35.449 +{
  35.450 +	systemSetPause(true);
  35.451 +	speedmode = SPEED_NORMAL;
  35.452 +
  35.453 +	// Return control if we're midway through a frame. We can't pause here.
  35.454 +	if (frameAdvanceWaiting)
  35.455 +	{
  35.456 +		return 0;
  35.457 +	}
  35.458 +
  35.459 +	// If it's on a frame boundary, we also yield.
  35.460 +	frameAdvanceWaiting = true;
  35.461 +	return lua_yield(L, 0);
  35.462 +}
  35.463 +
  35.464 +static int vba_registerbefore(lua_State *L)
  35.465 +{
  35.466 +	if (!lua_isnil(L, 1))
  35.467 +		luaL_checktype(L, 1, LUA_TFUNCTION);
  35.468 +	lua_settop(L, 1);
  35.469 +	lua_getfield(L, LUA_REGISTRYINDEX, luaCallIDStrings[LUACALL_BEFOREEMULATION]);
  35.470 +	lua_insert(L, 1);
  35.471 +	lua_setfield(L, LUA_REGISTRYINDEX, luaCallIDStrings[LUACALL_BEFOREEMULATION]);
  35.472 +
  35.473 +	//StopScriptIfFinished(luaStateToUIDMap[L]);
  35.474 +	return 1;
  35.475 +}
  35.476 +
  35.477 +static int vba_registerafter(lua_State *L)
  35.478 +{
  35.479 +	if (!lua_isnil(L, 1))
  35.480 +		luaL_checktype(L, 1, LUA_TFUNCTION);
  35.481 +	lua_settop(L, 1);
  35.482 +	lua_getfield(L, LUA_REGISTRYINDEX, luaCallIDStrings[LUACALL_AFTEREMULATION]);
  35.483 +	lua_insert(L, 1);
  35.484 +	lua_setfield(L, LUA_REGISTRYINDEX, luaCallIDStrings[LUACALL_AFTEREMULATION]);
  35.485 +
  35.486 +	//StopScriptIfFinished(luaStateToUIDMap[L]);
  35.487 +	return 1;
  35.488 +}
  35.489 +
  35.490 +static int vba_registerexit(lua_State *L)
  35.491 +{
  35.492 +	if (!lua_isnil(L, 1))
  35.493 +		luaL_checktype(L, 1, LUA_TFUNCTION);
  35.494 +	lua_settop(L, 1);
  35.495 +	lua_getfield(L, LUA_REGISTRYINDEX, luaCallIDStrings[LUACALL_BEFOREEXIT]);
  35.496 +	lua_insert(L, 1);
  35.497 +	lua_setfield(L, LUA_REGISTRYINDEX, luaCallIDStrings[LUACALL_BEFOREEXIT]);
  35.498 +
  35.499 +	//StopScriptIfFinished(luaStateToUIDMap[L]);
  35.500 +	return 1;
  35.501 +}
  35.502 +
  35.503 +static inline bool isalphaorunderscore(char c)
  35.504 +{
  35.505 +	return isalpha(c) || c == '_';
  35.506 +}
  35.507 +
  35.508 +static std::vector<const void *> s_tableAddressStack; // prevents infinite recursion of a table within a table (when cycle is
  35.509 +                                                      // found, print something like table:parent)
  35.510 +static std::vector<const void *> s_metacallStack; // prevents infinite recursion if something's __tostring returns another table
  35.511 +                                                  // that contains that something (when cycle is found, print the inner result
  35.512 +                                                  // without using __tostring)
  35.513 +
  35.514 +#define APPENDPRINT { int _n = snprintf(ptr, remaining,
  35.515 +#define END ); if (_n >= 0) { ptr += _n; remaining -= _n; } else { remaining = 0; } }
  35.516 +static void toCStringConverter(lua_State *L, int i, char * &ptr, int &remaining)
  35.517 +{
  35.518 +    if (remaining <= 0)
  35.519 +		return;
  35.520 +
  35.521 +    const char *str = ptr; // for debugging
  35.522 +
  35.523 +    // if there is a __tostring metamethod then call it
  35.524 +    int usedMeta = luaL_callmeta(L, i, "__tostring");
  35.525 +    if (usedMeta)
  35.526 +    {
  35.527 +        std::vector<const void *>::const_iterator foundCycleIter = std::find(s_metacallStack.begin(), s_metacallStack.end(), lua_topointer(L, i));
  35.528 +        if (foundCycleIter != s_metacallStack.end())
  35.529 +        {
  35.530 +            lua_pop(L, 1);
  35.531 +            usedMeta = false;
  35.532 +		}
  35.533 +        else
  35.534 +        {
  35.535 +            s_metacallStack.push_back(lua_topointer(L, i));
  35.536 +            i = lua_gettop(L);
  35.537 +		}
  35.538 +	}
  35.539 +
  35.540 +    switch (lua_type(L, i))
  35.541 +    {
  35.542 +	case LUA_TNONE:
  35.543 +		break;
  35.544 +	case LUA_TNIL:
  35.545 +		APPENDPRINT "nil" END break;
  35.546 +	case LUA_TBOOLEAN:
  35.547 +		APPENDPRINT lua_toboolean(L, i) ? "true" : "false" END break;
  35.548 +	case LUA_TSTRING : APPENDPRINT "%s", lua_tostring(L, i) END break;
  35.549 +	case LUA_TNUMBER:
  35.550 +		APPENDPRINT "%.12Lg", lua_tonumber(L, i) END break;
  35.551 +	case LUA_TFUNCTION:
  35.552 +		if ((L->base + i - 1)->value.gc->cl.c.isC)
  35.553 +		{
  35.554 +		    //lua_CFunction func = lua_tocfunction(L, i);
  35.555 +		    //std::map<lua_CFunction, const char*>::iterator iter = s_cFuncInfoMap.find(func);
  35.556 +		    //if(iter == s_cFuncInfoMap.end())
  35.557 +		    goto defcase;
  35.558 +		    //APPENDPRINT "function(%s)", iter->second END
  35.559 +		}
  35.560 +		else
  35.561 +		{
  35.562 +		    APPENDPRINT "function(" END
  35.563 +		    Proto * p = (L->base + i - 1)->value.gc->cl.l.p;
  35.564 +		    int numParams = p->numparams + (p->is_vararg ? 1 : 0);
  35.565 +		    for (int n = 0; n < p->numparams; n++)
  35.566 +		    {
  35.567 +		        APPENDPRINT "%s", getstr(p->locvars[n].varname) END
  35.568 +		        if (n != numParams - 1)
  35.569 +					APPENDPRINT "," END
  35.570 +					}
  35.571 +					if (p->is_vararg)
  35.572 +						APPENDPRINT "..." END
  35.573 +						APPENDPRINT ")" END
  35.574 +						}
  35.575 +						break;
  35.576 +defcase: default:
  35.577 +				APPENDPRINT "%s:%p", luaL_typename(L, i), lua_topointer(L, i) END break;
  35.578 +			case LUA_TTABLE:
  35.579 +				{
  35.580 +				    // first make sure there's enough stack space
  35.581 +				    if (!lua_checkstack(L, 4))
  35.582 +				    {
  35.583 +				        // note that even if lua_checkstack never returns false,
  35.584 +				        // that doesn't mean we didn't need to call it,
  35.585 +				        // because calling it retrieves stack space past LUA_MINSTACK
  35.586 +				        goto defcase;
  35.587 +					}
  35.588 +
  35.589 +				    std::vector<const void *>::const_iterator foundCycleIter =
  35.590 +				        std::find(s_tableAddressStack.begin(), s_tableAddressStack.end(), lua_topointer(L, i));
  35.591 +				    if (foundCycleIter != s_tableAddressStack.end())
  35.592 +				    {
  35.593 +				        int parentNum = s_tableAddressStack.end() - foundCycleIter;
  35.594 +				        if (parentNum > 1)
  35.595 +							APPENDPRINT "%s:parent^%d", luaL_typename(L, i), parentNum END
  35.596 +							else
  35.597 +								APPENDPRINT "%s:parent", luaL_typename(L, i) END
  35.598 +								}
  35.599 +								else
  35.600 +								{
  35.601 +								    s_tableAddressStack.push_back(lua_topointer(L, i));
  35.602 +								    struct Scope { ~Scope(){ s_tableAddressStack. pop_back(); } } scope;
  35.603 +
  35.604 +								    APPENDPRINT "{" END
  35.605 +
  35.606 +								               lua_pushnil(L); // first key
  35.607 +								    int		   keyIndex = lua_gettop(L);
  35.608 +								    int		   valueIndex = keyIndex + 1;
  35.609 +								    bool	   first = true;
  35.610 +								    bool	   skipKey = true; // true if we're still in the "array part" of the table
  35.611 +								    lua_Number arrayIndex = (lua_Number)0;
  35.612 +								    while (lua_next(L, i))
  35.613 +								    {
  35.614 +								        if (first)
  35.615 +											first = false;
  35.616 +								        else
  35.617 +											APPENDPRINT ", " END
  35.618 +											if (skipKey)
  35.619 +											{
  35.620 +											    arrayIndex += (lua_Number)1;
  35.621 +											    bool keyIsNumber = (lua_type(L, keyIndex) == LUA_TNUMBER);
  35.622 +											    skipKey = keyIsNumber && (lua_tonumber(L, keyIndex) == arrayIndex);
  35.623 +											}
  35.624 +								        if (!skipKey)
  35.625 +								        {
  35.626 +								            bool keyIsString = (lua_type(L, keyIndex) == LUA_TSTRING);
  35.627 +								            bool invalidLuaIdentifier = (!keyIsString || !isalphaorunderscore(*lua_tostring(L, keyIndex)));
  35.628 +								            if (invalidLuaIdentifier)
  35.629 +												if (keyIsString)
  35.630 +													APPENDPRINT "['" END
  35.631 +													else
  35.632 +														APPENDPRINT "[" END
  35.633 +
  35.634 +														toCStringConverter(L, keyIndex, ptr, remaining);
  35.635 +								            // key
  35.636 +
  35.637 +								            if (invalidLuaIdentifier)
  35.638 +												if (keyIsString)
  35.639 +													APPENDPRINT "']=" END
  35.640 +													else
  35.641 +														APPENDPRINT "]=" END
  35.642 +														else
  35.643 +															APPENDPRINT "=" END
  35.644 +															}
  35.645 +
  35.646 +															bool valueIsString = (lua_type(L, valueIndex) == LUA_TSTRING);
  35.647 +								            if (valueIsString)
  35.648 +												APPENDPRINT "'" END
  35.649 +
  35.650 +												toCStringConverter(L, valueIndex, ptr, remaining);  // value
  35.651 +
  35.652 +								            if (valueIsString)
  35.653 +												APPENDPRINT "'" END
  35.654 +
  35.655 +												lua_pop(L, 1);
  35.656 +
  35.657 +								            if (remaining <= 0)
  35.658 +								            {
  35.659 +								                lua_settop(L, keyIndex - 1); // stack might not be clean yet if we're breaking
  35.660 +								                                             // early
  35.661 +								                break;
  35.662 +											}
  35.663 +										}
  35.664 +								        APPENDPRINT "}" END
  35.665 +									}
  35.666 +								}
  35.667 +				        break;
  35.668 +					}
  35.669 +
  35.670 +				    if (usedMeta)
  35.671 +				    {
  35.672 +				        s_metacallStack.pop_back();
  35.673 +				        lua_pop(L, 1);
  35.674 +					}
  35.675 +				}
  35.676 +
  35.677 +				static const int s_tempStrMaxLen = 64 * 1024;
  35.678 +				static char s_tempStr [s_tempStrMaxLen];
  35.679 +
  35.680 +				static char *rawToCString(lua_State *L, int idx)
  35.681 +				{
  35.682 +				    int a = idx > 0 ? idx : 1;
  35.683 +				    int n = idx > 0 ? idx : lua_gettop(L);
  35.684 +
  35.685 +				    char *ptr = s_tempStr;
  35.686 +				    *ptr = 0;
  35.687 +
  35.688 +				    int remaining = s_tempStrMaxLen;
  35.689 +				    for (int i = a; i <= n; i++)
  35.690 +				    {
  35.691 +				        toCStringConverter(L, i, ptr, remaining);
  35.692 +				        if (i != n)
  35.693 +							APPENDPRINT " " END
  35.694 +							}
  35.695 +
  35.696 +							if (remaining < 3)
  35.697 +							{
  35.698 +							    while (remaining < 6)
  35.699 +									remaining++, ptr--;
  35.700 +							    APPENDPRINT "..." END
  35.701 +							}
  35.702 +				        APPENDPRINT "\r\n" END
  35.703 +				        // the trailing newline is so print() can avoid having to do wasteful things to print its newline
  35.704 +				        // (string copying would be wasteful and calling info.print() twice can be extremely slow)
  35.705 +				        // at the cost of functions that don't want the newline needing to trim off the last two characters
  35.706 +				        // (which is a very fast operation and thus acceptable in this case)
  35.707 +
  35.708 +				        return s_tempStr;
  35.709 +					}
  35.710 +#undef APPENDPRINT
  35.711 +#undef END
  35.712 +
  35.713 +// replacement for luaB_tostring() that is able to show the contents of tables (and formats numbers better, and show function
  35.714 +// prototypes)
  35.715 +// can be called directly from lua via tostring(), assuming tostring hasn't been reassigned
  35.716 +				    static int tostring(lua_State *L)
  35.717 +				    {
  35.718 +				        char *str = rawToCString(L);
  35.719 +				        str[strlen(str) - 2] = 0; // hack: trim off the \r\n (which is there to simplify the print function's
  35.720 +				                                  // task)
  35.721 +				        lua_pushstring(L, str);
  35.722 +				        return 1;
  35.723 +					}
  35.724 +
  35.725 +// like rawToCString, but will check if the global Lua function tostring()
  35.726 +// has been replaced with a custom function, and call that instead if so
  35.727 +				    static const char *toCString(lua_State *L, int idx)
  35.728 +				    {
  35.729 +				        int a = idx > 0 ? idx : 1;
  35.730 +				        int n = idx > 0 ? idx : lua_gettop(L);
  35.731 +				        lua_getglobal(L, "tostring");
  35.732 +				        lua_CFunction cf = lua_tocfunction(L, -1);
  35.733 +				        if (cf == tostring || lua_isnil(L, -1)) // optimization: if using our own C tostring function, we can
  35.734 +				                                                // bypass the call through Lua and all the string object
  35.735 +				                                                // allocation that would entail
  35.736 +				        {
  35.737 +				            lua_pop(L, 1);
  35.738 +				            return rawToCString(L, idx);
  35.739 +						}
  35.740 +				        else // if the user overrided the tostring function, we have to actually call it and store the
  35.741 +				             // temporarily allocated string it returns
  35.742 +				        {
  35.743 +				            lua_pushstring(L, "");
  35.744 +				            for (int i = a; i <= n; i++)
  35.745 +				            {
  35.746 +				                lua_pushvalue(L, -2); // function to be called
  35.747 +				                lua_pushvalue(L, i); // value to print
  35.748 +				                lua_call(L, 1, 1);
  35.749 +				                if (lua_tostring(L, -1) == NULL)
  35.750 +									luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("print"));
  35.751 +				                lua_pushstring(L, (i < n) ? " " : "\r\n");
  35.752 +				                lua_concat(L, 3);
  35.753 +							}
  35.754 +				            const char *str = lua_tostring(L, -1);
  35.755 +				            strncpy(s_tempStr, str, s_tempStrMaxLen);
  35.756 +				            s_tempStr[s_tempStrMaxLen - 1] = 0;
  35.757 +				            lua_pop(L, 2);
  35.758 +				            return s_tempStr;
  35.759 +						}
  35.760 +					}
  35.761 +
  35.762 +// replacement for luaB_print() that goes to the appropriate textbox instead of stdout
  35.763 +				    static int print(lua_State *L)
  35.764 +				    {
  35.765 +				        const char *str = toCString(L);
  35.766 +
  35.767 +				        int uid = info_uid; //luaStateToUIDMap[L->l_G->mainthread];
  35.768 +				        //LuaContextInfo& info = GetCurrentInfo();
  35.769 +
  35.770 +				        if (info_print)
  35.771 +							info_print(uid, str);
  35.772 +				        else
  35.773 +							puts(str);
  35.774 +
  35.775 +				        //worry(L, 100);
  35.776 +				        return 0;
  35.777 +					}
  35.778 +
  35.779 +				    static int printerror(lua_State *L, int idx)
  35.780 +				    {
  35.781 +				        lua_checkstack(L, lua_gettop(L) + 4);
  35.782 +
  35.783 +				        if (idx < 0)
  35.784 +							idx = lua_gettop(L) + 1 + idx;
  35.785 +
  35.786 +				        const char *str = rawToCString(L, idx);
  35.787 +
  35.788 +				        int uid = info_uid; //luaStateToUIDMap[L->l_G->mainthread];
  35.789 +				        //LuaContextInfo& info = GetCurrentInfo();
  35.790 +
  35.791 +				        if (info_print)
  35.792 +							info_print(uid, str);
  35.793 +				        else
  35.794 +							fputs(str, stderr);
  35.795 +
  35.796 +				        //worry(L, 100);
  35.797 +				        return 0;
  35.798 +					}
  35.799 +
  35.800 +// vba.message(string msg)
  35.801 +//
  35.802 +//  Displays the given message on the screen.
  35.803 +				    static int vba_message(lua_State *L)
  35.804 +				    {
  35.805 +				        const char *msg = luaL_checkstring(L, 1);
  35.806 +				        systemScreenMessage(msg);
  35.807 +
  35.808 +				        return 0;
  35.809 +					}
  35.810 +
  35.811 +// provides an easy way to copy a table from Lua
  35.812 +// (simple assignment only makes an alias, but sometimes an independent table is desired)
  35.813 +// currently this function only performs a shallow copy,
  35.814 +// but I think it should be changed to do a deep copy (possibly of configurable depth?)
  35.815 +// that maintains the internal table reference structure
  35.816 +				    static int copytable(lua_State *L)
  35.817 +				    {
  35.818 +				        int origIndex = 1; // we only care about the first argument
  35.819 +				        int origType = lua_type(L, origIndex);
  35.820 +				        if (origType == LUA_TNIL)
  35.821 +				        {
  35.822 +				            lua_pushnil(L);
  35.823 +				            return 1;
  35.824 +						}
  35.825 +				        if (origType != LUA_TTABLE)
  35.826 +				        {
  35.827 +				            luaL_typerror(L, 1, lua_typename(L, LUA_TTABLE));
  35.828 +				            lua_pushnil(L);
  35.829 +				            return 1;
  35.830 +						}
  35.831 +
  35.832 +				        lua_createtable(L, lua_objlen(L, 1), 0);
  35.833 +				        int copyIndex = lua_gettop(L);
  35.834 +
  35.835 +				        lua_pushnil(L); // first key
  35.836 +				        int keyIndex = lua_gettop(L);
  35.837 +				        int valueIndex = keyIndex + 1;
  35.838 +
  35.839 +				        while (lua_next(L, origIndex))
  35.840 +				        {
  35.841 +				            lua_pushvalue(L, keyIndex);
  35.842 +				            lua_pushvalue(L, valueIndex);
  35.843 +				            lua_rawset(L, copyIndex); // copytable[key] = value
  35.844 +				            lua_pop(L, 1);
  35.845 +						}
  35.846 +
  35.847 +				        // copy the reference to the metatable as well, if any
  35.848 +				        if (lua_getmetatable(L, origIndex))
  35.849 +							lua_setmetatable(L, copyIndex);
  35.850 +
  35.851 +				        return 1; // return the new table
  35.852 +					}
  35.853 +
  35.854 +// because print traditionally shows the address of tables,
  35.855 +// and the print function I provide instead shows the contents of tables,
  35.856 +// I also provide this function
  35.857 +// (otherwise there would be no way to see a table's address, AFAICT)
  35.858 +				    static int addressof(lua_State *L)
  35.859 +				    {
  35.860 +				        const void *ptr = lua_topointer(L, -1);
  35.861 +				        lua_pushinteger(L, (lua_Integer)ptr);
  35.862 +				        return 1;
  35.863 +					}
  35.864 +
  35.865 +				    struct registerPointerMap
  35.866 +				    {
  35.867 +				        const char *  registerName;
  35.868 +				        unsigned int *pointer;
  35.869 +				        int dataSize;
  35.870 +					};
  35.871 +
  35.872 +#define RPM_ENTRY(name, var) \
  35.873 +	{ name, (unsigned int *)&var, sizeof(var) \
  35.874 +	} \
  35.875 +	,
  35.876 +
  35.877 +				    extern gbRegister AF;
  35.878 +				    extern gbRegister BC;
  35.879 +				    extern gbRegister DE;
  35.880 +				    extern gbRegister HL;
  35.881 +				    extern gbRegister SP;
  35.882 +				    extern gbRegister PC;
  35.883 +				    extern u16 IFF;
  35.884 +
  35.885 +				    registerPointerMap regPointerMap [] = {
  35.886 +				        // gba registers
  35.887 +				        RPM_ENTRY("r0",	  reg[0].I)
  35.888 +				        RPM_ENTRY("r1",	  reg[1].I)
  35.889 +				        RPM_ENTRY("r2",	  reg[2].I)
  35.890 +				        RPM_ENTRY("r3",	  reg[3].I)
  35.891 +				        RPM_ENTRY("r4",	  reg[4].I)
  35.892 +				        RPM_ENTRY("r5",	  reg[5].I)
  35.893 +				        RPM_ENTRY("r6",	  reg[6].I)
  35.894 +				        RPM_ENTRY("r7",	  reg[7].I)
  35.895 +				        RPM_ENTRY("r8",	  reg[8].I)
  35.896 +				        RPM_ENTRY("r9",	  reg[9].I)
  35.897 +				        RPM_ENTRY("r10",  reg[10].I)
  35.898 +				        RPM_ENTRY("r11",  reg[11].I)
  35.899 +				        RPM_ENTRY("r12",  reg[12].I)
  35.900 +				        RPM_ENTRY("r13",  reg[13].I)
  35.901 +				        RPM_ENTRY("r14",  reg[14].I)
  35.902 +				        RPM_ENTRY("r15",  reg[15].I)
  35.903 +				        RPM_ENTRY("cpsr", reg[16].I)
  35.904 +				        RPM_ENTRY("spsr", reg[17].I)
  35.905 +				        // gb registers
  35.906 +				        RPM_ENTRY("a",	  AF.B.B1)
  35.907 +				        RPM_ENTRY("f",	  AF.B.B0)
  35.908 +				        RPM_ENTRY("b",	  BC.B.B1)
  35.909 +				        RPM_ENTRY("c",	  BC.B.B0)
  35.910 +				        RPM_ENTRY("d",	  DE.B.B1)
  35.911 +				        RPM_ENTRY("e",	  DE.B.B0)
  35.912 +				        RPM_ENTRY("h",	  HL.B.B1)
  35.913 +				        RPM_ENTRY("l",	  HL.B.B0)
  35.914 +				        RPM_ENTRY("af",	  AF.W)
  35.915 +				        RPM_ENTRY("bc",	  BC.W)
  35.916 +				        RPM_ENTRY("de",	  DE.W)
  35.917 +				        RPM_ENTRY("hl",	  HL.W)
  35.918 +				        RPM_ENTRY("sp",	  SP.W)
  35.919 +				        RPM_ENTRY("pc",	  PC.W)
  35.920 +				        {}
  35.921 +					};
  35.922 +
  35.923 +				    struct cpuToRegisterMap
  35.924 +				    {
  35.925 +				        const char *cpuName;
  35.926 +				        registerPointerMap *rpmap;
  35.927 +					}
  35.928 +				    cpuToRegisterMaps [] =
  35.929 +				    {
  35.930 +				        { "", regPointerMap },
  35.931 +					};
  35.932 +
  35.933 +//DEFINE_LUA_FUNCTION(memory_getregister, "cpu_dot_registername_string")
  35.934 +				    static int memory_getregister(lua_State *L)
  35.935 +				    {
  35.936 +				        const char *qualifiedRegisterName = luaL_checkstring(L, 1);
  35.937 +				        lua_settop(L, 0);
  35.938 +				        for (int cpu = 0; cpu < sizeof(cpuToRegisterMaps) / sizeof(*cpuToRegisterMaps); cpu++)
  35.939 +				        {
  35.940 +				            cpuToRegisterMap ctrm = cpuToRegisterMaps[cpu];
  35.941 +				            int cpuNameLen		  = strlen(ctrm.cpuName);
  35.942 +				            if (!strnicmp(qualifiedRegisterName, ctrm.cpuName, cpuNameLen))
  35.943 +				            {
  35.944 +				                qualifiedRegisterName += cpuNameLen;
  35.945 +				                for (int reg = 0; ctrm.rpmap[reg].dataSize; reg++)
  35.946 +				                {
  35.947 +				                    registerPointerMap rpm = ctrm.rpmap[reg];
  35.948 +				                    if (!stricmp(qualifiedRegisterName, rpm.registerName))
  35.949 +				                    {
  35.950 +				                        switch (rpm.dataSize)
  35.951 +				                        {
  35.952 +										default:
  35.953 +										case 1:
  35.954 +											lua_pushinteger(L, *(unsigned char *)rpm.pointer); break;
  35.955 +										case 2:
  35.956 +											lua_pushinteger(L, *(unsigned short *)rpm.pointer); break;
  35.957 +										case 4:
  35.958 +											lua_pushinteger(L, *(unsigned long *)rpm.pointer); break;
  35.959 +										}
  35.960 +				                        return 1;
  35.961 +									}
  35.962 +								}
  35.963 +				                lua_pushnil(L);
  35.964 +				                return 1;
  35.965 +							}
  35.966 +						}
  35.967 +				        lua_pushnil(L);
  35.968 +				        return 1;
  35.969 +					}
  35.970 +
  35.971 +//DEFINE_LUA_FUNCTION(memory_setregister, "cpu_dot_registername_string,value")
  35.972 +				    static int memory_setregister(lua_State *L)
  35.973 +				    {
  35.974 +				        const char *  qualifiedRegisterName = luaL_checkstring(L, 1);
  35.975 +				        unsigned long value = (unsigned long)(luaL_checkinteger(L, 2));
  35.976 +				        lua_settop(L, 0);
  35.977 +				        for (int cpu = 0; cpu < sizeof(cpuToRegisterMaps) / sizeof(*cpuToRegisterMaps); cpu++)
  35.978 +				        {
  35.979 +				            cpuToRegisterMap ctrm = cpuToRegisterMaps[cpu];
  35.980 +				            int cpuNameLen		  = strlen(ctrm.cpuName);
  35.981 +				            if (!strnicmp(qualifiedRegisterName, ctrm.cpuName, cpuNameLen))
  35.982 +				            {
  35.983 +				                qualifiedRegisterName += cpuNameLen;
  35.984 +				                for (int reg = 0; ctrm.rpmap[reg].dataSize; reg++)
  35.985 +				                {
  35.986 +				                    registerPointerMap rpm = ctrm.rpmap[reg];
  35.987 +				                    if (!stricmp(qualifiedRegisterName, rpm.registerName))
  35.988 +				                    {
  35.989 +				                        switch (rpm.dataSize)
  35.990 +				                        {
  35.991 +										default:
  35.992 +										case 1:
  35.993 +											*(unsigned char *)rpm.pointer = (unsigned char)(value & 0xFF); break;
  35.994 +										case 2:
  35.995 +											*(unsigned short *)rpm.pointer = (unsigned short)(value & 0xFFFF); break;
  35.996 +										case 4:
  35.997 +											*(unsigned long *)rpm.pointer = value; break;
  35.998 +										}
  35.999 +				                        return 0;
 35.1000 +									}
 35.1001 +								}
 35.1002 +				                return 0;
 35.1003 +							}
 35.1004 +						}
 35.1005 +				        return 0;
 35.1006 +					}
 35.1007 +
 35.1008 +				    void HandleCallbackError(lua_State *L)
 35.1009 +				    {
 35.1010 +				        if (L->errfunc || L->errorJmp)
 35.1011 +							luaL_error(L, "%s", lua_tostring(L, -1));
 35.1012 +				        else
 35.1013 +				        {
 35.1014 +				            lua_pushnil(LUA);
 35.1015 +				            lua_setfield(LUA, LUA_REGISTRYINDEX, guiCallbackTable);
 35.1016 +
 35.1017 +				            // Error?
 35.1018 +//#if (defined(WIN32) && !defined(SDL))
 35.1019 +//		info_print(info_uid, lua_tostring(LUA, -1)); //Clear_Sound_Buffer();
 35.1020 +// AfxGetApp()->m_pMainWnd->MessageBox(lua_tostring(LUA, -1), "Lua run error", MB_OK | MB_ICONSTOP);
 35.1021 +//#else
 35.1022 +//		fprintf(stderr, "Lua thread bombed out: %s\n", lua_tostring(LUA, -1));
 35.1023 +//#endif
 35.1024 +				            printerror(LUA, -1);
 35.1025 +				            VBALuaStop();
 35.1026 +						}
 35.1027 +					}
 35.1028 +
 35.1029 +				    void CallRegisteredLuaFunctions(LuaCallID calltype)
 35.1030 +				    {
 35.1031 +				        assert((unsigned int)calltype < (unsigned int)LUACALL_COUNT);
 35.1032 +
 35.1033 +				        const char *idstring = luaCallIDStrings[calltype];
 35.1034 +
 35.1035 +				        if (!LUA)
 35.1036 +							return;
 35.1037 +
 35.1038 +				        lua_settop(LUA, 0);
 35.1039 +				        lua_getfield(LUA, LUA_REGISTRYINDEX, idstring);
 35.1040 +
 35.1041 +				        int errorcode = 0;
 35.1042 +				        if (lua_isfunction(LUA, -1))
 35.1043 +				        {
 35.1044 +				            errorcode = lua_pcall(LUA, 0, 0, 0);
 35.1045 +				            if (errorcode)
 35.1046 +								HandleCallbackError(LUA);
 35.1047 +						}
 35.1048 +				        else
 35.1049 +				        {
 35.1050 +				            lua_pop(LUA, 1);
 35.1051 +						}
 35.1052 +					}
 35.1053 +
 35.1054 +// the purpose of this structure is to provide a way of
 35.1055 +// QUICKLY determining whether a memory address range has a hook associated with it,
 35.1056 +// with a bias toward fast rejection because the majority of addresses will not be hooked.
 35.1057 +// (it must not use any part of Lua or perform any per-script operations,
 35.1058 +//  otherwise it would definitely be too slow.)
 35.1059 +// calculating the regions when a hook is added/removed may be slow,
 35.1060 +// but this is an intentional tradeoff to obtain a high speed of checking during later execution
 35.1061 +				    struct TieredRegion
 35.1062 +				    {
 35.1063 +				        template<unsigned int maxGap>
 35.1064 +				        struct Region
 35.1065 +				        {
 35.1066 +				            struct Island
 35.1067 +				            {
 35.1068 +				                unsigned int	   start;
 35.1069 +				                unsigned int	   end;
 35.1070 +				                __forceinline bool Contains(unsigned int address, int size) const { return address < end && address + size > start; }
 35.1071 +							};
 35.1072 +				            std::vector<Island> islands;
 35.1073 +
 35.1074 +				            void Calculate(const std::vector<unsigned int> &bytes)
 35.1075 +				            {
 35.1076 +				                islands. clear();
 35.1077 +
 35.1078 +				                unsigned int lastEnd = ~0;
 35.1079 +
 35.1080 +				                std::vector<unsigned int>::const_iterator iter = bytes.begin();
 35.1081 +				                std::vector<unsigned int>::const_iterator end  = bytes.end();
 35.1082 +				                for (; iter != end; ++iter)
 35.1083 +				                {
 35.1084 +				                    unsigned int addr = *iter;
 35.1085 +				                    if (addr < lastEnd || addr > lastEnd + (long long)maxGap)
 35.1086 +				                    {
 35.1087 +				                        islands. push_back(Island());
 35.1088 +				                        islands. back().start = addr;
 35.1089 +									}
 35.1090 +				                    islands.back(). end = addr + 1;
 35.1091 +				                    lastEnd = addr + 1;
 35.1092 +								}
 35.1093 +							}
 35.1094 +
 35.1095 +				            bool Contains(unsigned int address, int size) const
 35.1096 +				            {
 35.1097 +				                for (size_t i = 0; i != islands.size(); ++i)
 35.1098 +				                {
 35.1099 +				                    if (islands[i].Contains(address, size))
 35.1100 +										return true;
 35.1101 +								}
 35.1102 +				                return false;
 35.1103 +							}
 35.1104 +						};
 35.1105 +
 35.1106 +				        Region<0xFFFFFFFF> broad;
 35.1107 +				        Region<0x1000>	   mid;
 35.1108 +				        Region<0>		   narrow;
 35.1109 +
 35.1110 +				        void Calculate(std::vector<unsigned int> &bytes)
 35.1111 +				        {
 35.1112 +				            std:: sort(bytes.begin(), bytes.end());
 35.1113 +
 35.1114 +				            broad.	Calculate(bytes);
 35.1115 +				            mid.	Calculate(bytes);
 35.1116 +				            narrow. Calculate(bytes);
 35.1117 +						}
 35.1118 +
 35.1119 +				        TieredRegion()
 35.1120 +				        {
 35.1121 +				            std::vector <unsigned int> temp;
 35.1122 +				            Calculate(temp);
 35.1123 +						}
 35.1124 +
 35.1125 +				        __forceinline int NotEmpty()
 35.1126 +				        {
 35.1127 +				            return broad.islands.size();
 35.1128 +						}
 35.1129 +
 35.1130 +				        // note: it is illegal to call this if NotEmpty() returns 0
 35.1131 +				        __forceinline bool Contains(unsigned int address, int size)
 35.1132 +				        {
 35.1133 +				            return broad.islands[0].Contains(address, size) &&
 35.1134 +				                   mid.Contains(address, size) &&
 35.1135 +				                   narrow.Contains(address, size);
 35.1136 +						}
 35.1137 +					};
 35.1138 +				    TieredRegion hookedRegions [LUAMEMHOOK_COUNT];
 35.1139 +
 35.1140 +				    static void CalculateMemHookRegions(LuaMemHookType hookType)
 35.1141 +				    {
 35.1142 +				        std::vector<unsigned int> hookedBytes;
 35.1143 +//	std::map<int, LuaContextInfo*>::iterator iter = luaContextInfo.begin();
 35.1144 +//	std::map<int, LuaContextInfo*>::iterator end = luaContextInfo.end();
 35.1145 +//	while(iter != end)
 35.1146 +//	{
 35.1147 +//		LuaContextInfo& info = *iter->second;
 35.1148 +				        if (/*info.*/ numMemHooks)
 35.1149 +				        {
 35.1150 +				            lua_State *L = LUA /*info.L*/;
 35.1151 +				            if (L)
 35.1152 +				            {
 35.1153 +				                lua_settop(L, 0);
 35.1154 +				                lua_getfield(L, LUA_REGISTRYINDEX, luaMemHookTypeStrings[hookType]);
 35.1155 +				                lua_pushnil(L);
 35.1156 +				                while (lua_next(L, -2))
 35.1157 +				                {
 35.1158 +				                    if (lua_isfunction(L, -1))
 35.1159 +				                    {
 35.1160 +				                        unsigned int addr = lua_tointeger(L, -2);
 35.1161 +				                        hookedBytes.push_back(addr);
 35.1162 +									}
 35.1163 +				                    lua_pop(L, 1);
 35.1164 +								}
 35.1165 +				                lua_settop(L, 0);
 35.1166 +							}
 35.1167 +						}
 35.1168 +//		++iter;
 35.1169 +//	}
 35.1170 +				        hookedRegions[hookType].Calculate(hookedBytes);
 35.1171 +					}
 35.1172 +
 35.1173 +				    static void CallRegisteredLuaMemHook_LuaMatch(unsigned int address, int size, unsigned int value, LuaMemHookType hookType)
 35.1174 +				    {
 35.1175 +//	std::map<int, LuaContextInfo*>::iterator iter = luaContextInfo.begin();
 35.1176 +//	std::map<int, LuaContextInfo*>::iterator end = luaContextInfo.end();
 35.1177 +//	while(iter != end)
 35.1178 +//	{
 35.1179 +//		LuaContextInfo& info = *iter->second;
 35.1180 +				        if (/*info.*/ numMemHooks)
 35.1181 +				        {
 35.1182 +				            lua_State *L = LUA /*info.L*/;
 35.1183 +				            if (L /* && !info.panic*/)
 35.1184 +				            {
 35.1185 +#ifdef USE_INFO_STACK
 35.1186 +				                infoStack.insert(infoStack.begin(), &info);
 35.1187 +				                struct Scope { ~Scope(){ infoStack. erase(infoStack.begin()); } } scope;
 35.1188 +#endif
 35.1189 +				                lua_settop(L, 0);
 35.1190 +				                lua_getfield(L, LUA_REGISTRYINDEX, luaMemHookTypeStrings[hookType]);
 35.1191 +				                for (int i = address; i != address + size; i++)
 35.1192 +				                {
 35.1193 +				                    lua_rawgeti(L, -1, i);
 35.1194 +				                    if (lua_isfunction(L, -1))
 35.1195 +				                    {
 35.1196 +				                        bool wasRunning = (luaRunning != 0) /*info.running*/;
 35.1197 +				                        luaRunning /*info.running*/ = true;
 35.1198 +				                        //RefreshScriptSpeedStatus();
 35.1199 +				                        lua_pushinteger(L, address);
 35.1200 +				                        lua_pushinteger(L, size);
 35.1201 +				                        int errorcode = lua_pcall(L, 2, 0, 0);
 35.1202 +				                        luaRunning /*info.running*/ = wasRunning;
 35.1203 +				                        //RefreshScriptSpeedStatus();
 35.1204 +				                        if (errorcode)
 35.1205 +				                        {
 35.1206 +				                            HandleCallbackError(L);
 35.1207 +				                            //int uid = iter->first;
 35.1208 +				                            //HandleCallbackError(L,info,uid,true);
 35.1209 +										}
 35.1210 +				                        break;
 35.1211 +									}
 35.1212 +				                    else
 35.1213 +				                    {
 35.1214 +				                        lua_pop(L, 1);
 35.1215 +									}
 35.1216 +								}
 35.1217 +				                lua_settop(L, 0);
 35.1218 +							}
 35.1219 +						}
 35.1220 +//		++iter;
 35.1221 +//	}
 35.1222 +					}
 35.1223 +
 35.1224 +				    void CallRegisteredLuaMemHook(unsigned int address, int size, unsigned int value, LuaMemHookType hookType)
 35.1225 +				    {
 35.1226 +				        // performance critical! (called VERY frequently)
 35.1227 +				        // I suggest timing a large number of calls to this function in Release if you change anything in here,
 35.1228 +				        // before and after, because even the most innocent change can make it become 30% to 400% slower.
 35.1229 +				        // a good amount to test is: 100000000 calls with no hook set, and another 100000000 with a hook set.
 35.1230 +				        // (on my system that consistently took 200 ms total in the former case and 350 ms total in the latter
 35.1231 +				        // case)
 35.1232 +				        if (hookedRegions[hookType].NotEmpty())
 35.1233 +				        {
 35.1234 +				            //if((hookType <= LUAMEMHOOK_EXEC) && (address >= 0xE00000))
 35.1235 +				            //	address |= 0xFF0000; // account for mirroring of RAM
 35.1236 +				            if (hookedRegions[hookType].Contains(address, size))
 35.1237 +								CallRegisteredLuaMemHook_LuaMatch(address, size, value, hookType);  // something has hooked this
 35.1238 +				                                                                                    // specific address
 35.1239 +						}
 35.1240 +					}
 35.1241 +
 35.1242 +				    static int memory_registerHook(lua_State *L, LuaMemHookType hookType, int defaultSize)
 35.1243 +				    {
 35.1244 +				        // get first argument: address
 35.1245 +				        unsigned int addr = luaL_checkinteger(L, 1);
 35.1246 +				        //if((addr & ~0xFFFFFF) == ~0xFFFFFF)
 35.1247 +				        //	addr &= 0xFFFFFF;
 35.1248 +
 35.1249 +				        // get optional second argument: size
 35.1250 +				        int size	= defaultSize;
 35.1251 +				        int funcIdx = 2;
 35.1252 +				        if (lua_isnumber(L, 2))
 35.1253 +				        {
 35.1254 +				            size = luaL_checkinteger(L, 2);
 35.1255 +				            if (size < 0)
 35.1256 +				            {
 35.1257 +				                size  = -size;
 35.1258 +				                addr -= size;
 35.1259 +							}
 35.1260 +				            funcIdx++;
 35.1261 +						}
 35.1262 +
 35.1263 +				        // check last argument: callback function
 35.1264 +				        bool clearing = lua_isnil(L, funcIdx);
 35.1265 +				        if (!clearing)
 35.1266 +							luaL_checktype(L, funcIdx, LUA_TFUNCTION);
 35.1267 +				        lua_settop(L, funcIdx);
 35.1268 +
 35.1269 +				        // get the address-to-callback table for this hook type of the current script
 35.1270 +				        lua_getfield(L, LUA_REGISTRYINDEX, luaMemHookTypeStrings[hookType]);
 35.1271 +
 35.1272 +				        // count how many callback functions we'll be displacing
 35.1273 +				        int numFuncsAfter  = clearing ? 0 : size;
 35.1274 +				        int numFuncsBefore = 0;
 35.1275 +				        for (unsigned int i = addr; i != addr + size; i++)
 35.1276 +				        {
 35.1277 +				            lua_rawgeti(L, -1, i);
 35.1278 +				            if (lua_isfunction(L, -1))
 35.1279 +								numFuncsBefore++;
 35.1280 +				            lua_pop(L, 1);
 35.1281 +						}
 35.1282 +
 35.1283 +				        // put the callback function in the address slots
 35.1284 +				        for (unsigned int i = addr; i != addr + size; i++)
 35.1285 +				        {
 35.1286 +				            lua_pushvalue(L, -2);
 35.1287 +				            lua_rawseti(L, -2, i);
 35.1288 +						}
 35.1289 +
 35.1290 +				        // adjust the count of active hooks
 35.1291 +				        //LuaContextInfo& info = GetCurrentInfo();
 35.1292 +				        /*info.*/ numMemHooks += numFuncsAfter - numFuncsBefore;
 35.1293 +
 35.1294 +				        // re-cache regions of hooked memory across all scripts
 35.1295 +				        CalculateMemHookRegions(hookType);
 35.1296 +
 35.1297 +				        //StopScriptIfFinished(luaStateToUIDMap[L]);
 35.1298 +				        return 0;
 35.1299 +					}
 35.1300 +
 35.1301 +				    LuaMemHookType MatchHookTypeToCPU(lua_State *L, LuaMemHookType hookType)
 35.1302 +				    {
 35.1303 +				        int cpuID = 0;
 35.1304 +
 35.1305 +				        int cpunameIndex = 0;
 35.1306 +				        if (lua_type(L, 2) == LUA_TSTRING)
 35.1307 +							cpunameIndex = 2;
 35.1308 +				        else if (lua_type(L, 3) == LUA_TSTRING)
 35.1309 +							cpunameIndex = 3;
 35.1310 +
 35.1311 +				        if (cpunameIndex)
 35.1312 +				        {
 35.1313 +				            const char *cpuName = lua_tostring(L, cpunameIndex);
 35.1314 +				            if (!stricmp(cpuName, "sub"))
 35.1315 +								cpuID = 1;
 35.1316 +				            lua_remove(L, cpunameIndex);
 35.1317 +						}
 35.1318 +
 35.1319 +				        switch (cpuID)
 35.1320 +				        {
 35.1321 +						case 0:
 35.1322 +							return hookType;
 35.1323 +
 35.1324 +						case 1:
 35.1325 +							switch (hookType)
 35.1326 +							{
 35.1327 +							case LUAMEMHOOK_WRITE:
 35.1328 +								return LUAMEMHOOK_WRITE_SUB;
 35.1329 +							case LUAMEMHOOK_READ:
 35.1330 +								return LUAMEMHOOK_READ_SUB;
 35.1331 +							case LUAMEMHOOK_EXEC:
 35.1332 +								return LUAMEMHOOK_EXEC_SUB;
 35.1333 +							}
 35.1334 +						}
 35.1335 +				        return hookType;
 35.1336 +					}
 35.1337 +
 35.1338 +				    static int memory_registerwrite(lua_State *L)
 35.1339 +				    {
 35.1340 +				        return memory_registerHook(L, MatchHookTypeToCPU(L, LUAMEMHOOK_WRITE), 1);
 35.1341 +					}
 35.1342 +
 35.1343 +				    static int memory_registerread(lua_State *L)
 35.1344 +				    {
 35.1345 +				        return memory_registerHook(L, MatchHookTypeToCPU(L, LUAMEMHOOK_READ), 1);
 35.1346 +					}
 35.1347 +
 35.1348 +				    static int memory_registerexec(lua_State *L)
 35.1349 +				    {
 35.1350 +				        return memory_registerHook(L, MatchHookTypeToCPU(L, LUAMEMHOOK_EXEC), 1);
 35.1351 +					}
 35.1352 +
 35.1353 +//int vba.lagcount
 35.1354 +//
 35.1355 +
 35.1356 +//Returns the lagcounter variable
 35.1357 +				    static int vba_getlagcount(lua_State *L)
 35.1358 +				    {
 35.1359 +				        lua_pushinteger(L, systemCounters.lagCount);
 35.1360 +				        return 1;
 35.1361 +					}
 35.1362 +
 35.1363 +//int vba.lagged
 35.1364 +//
 35.1365 +//Returns true if the current frame is a lag frame
 35.1366 +				    static int vba_lagged(lua_State *L)
 35.1367 +				    {
 35.1368 +				        lua_pushboolean(L, systemCounters.laggedLast);
 35.1369 +				        return 1;
 35.1370 +					}
 35.1371 +
 35.1372 +// boolean vba.emulating()
 35.1373 +				    int vba_emulating(lua_State *L)
 35.1374 +				    {
 35.1375 +				        lua_pushboolean(L, systemIsEmulating());
 35.1376 +				        return 1;
 35.1377 +					}
 35.1378 +
 35.1379 +				    int movie_isactive(lua_State *L)
 35.1380 +				    {
 35.1381 +				        lua_pushboolean(L, VBAMovieActive());
 35.1382 +				        return 1;
 35.1383 +					}
 35.1384 +
 35.1385 +				    int movie_isrecording(lua_State *L)
 35.1386 +				    {
 35.1387 +				        lua_pushboolean(L, VBAMovieRecording());
 35.1388 +				        return 1;
 35.1389 +					}
 35.1390 +
 35.1391 +				    int movie_isplaying(lua_State *L)
 35.1392 +				    {
 35.1393 +				        lua_pushboolean(L, VBAMoviePlaying());
 35.1394 +				        return 1;
 35.1395 +					}
 35.1396 +
 35.1397 +				    int movie_getlength(lua_State *L)
 35.1398 +				    {
 35.1399 +				        if (VBAMovieActive())
 35.1400 +							lua_pushinteger(L, VBAMovieGetLength());
 35.1401 +				        else
 35.1402 +							lua_pushinteger(L, 0);
 35.1403 +				        return 1;
 35.1404 +					}
 35.1405 +
 35.1406 +				    static int memory_readbyte(lua_State *L)
 35.1407 +				    {
 35.1408 +				        u32 addr;
 35.1409 +				        u8	val;
 35.1410 +
 35.1411 +				        addr = luaL_checkinteger(L, 1);
 35.1412 +				        if (systemIsRunningGBA())
 35.1413 +				        {
 35.1414 +				            val = CPUReadByteQuick(addr);
 35.1415 +						}
 35.1416 +				        else
 35.1417 +				        {
 35.1418 +				            val = gbReadMemoryQuick8(addr);
 35.1419 +						}
 35.1420 +
 35.1421 +				        lua_pushinteger(L, val);
 35.1422 +				        return 1;
 35.1423 +					}
 35.1424 +
 35.1425 +				    static int memory_readbytesigned(lua_State *L)
 35.1426 +				    {
 35.1427 +				        u32 addr;
 35.1428 +				        s8	val;
 35.1429 +
 35.1430 +				        addr = luaL_checkinteger(L, 1);
 35.1431 +				        if (systemIsRunningGBA())
 35.1432 +				        {
 35.1433 +				            val = (s8) CPUReadByteQuick(addr);
 35.1434 +						}
 35.1435 +				        else
 35.1436 +				        {
 35.1437 +				            val = (s8) gbReadMemoryQuick8(addr);
 35.1438 +						}
 35.1439 +
 35.1440 +				        lua_pushinteger(L, val);
 35.1441 +				        return 1;
 35.1442 +					}
 35.1443 +
 35.1444 +				    static int memory_readword(lua_State *L)
 35.1445 +				    {
 35.1446 +				        u32 addr;
 35.1447 +				        u16 val;
 35.1448 +
 35.1449 +				        addr = luaL_checkinteger(L, 1);
 35.1450 +				        if (systemIsRunningGBA())
 35.1451 +				        {
 35.1452 +				            val = CPUReadHalfWordQuick(addr);
 35.1453 +						}
 35.1454 +				        else
 35.1455 +				        {
 35.1456 +				            val = gbReadMemoryQuick16(addr & 0x0000FFFF);
 35.1457 +						}
 35.1458 +
 35.1459 +				        lua_pushinteger(L, val);
 35.1460 +				        return 1;
 35.1461 +					}
 35.1462 +
 35.1463 +				    static int memory_readwordsigned(lua_State *L)
 35.1464 +				    {
 35.1465 +				        u32 addr;
 35.1466 +				        s16 val;
 35.1467 +
 35.1468 +				        addr = luaL_checkinteger(L, 1);
 35.1469 +				        if (systemIsRunningGBA())
 35.1470 +				        {
 35.1471 +				            val = (s16) CPUReadHalfWordQuick(addr);
 35.1472 +						}
 35.1473 +				        else
 35.1474 +				        {
 35.1475 +				            val = (s16) gbReadMemoryQuick16(addr);
 35.1476 +						}
 35.1477 +
 35.1478 +				        lua_pushinteger(L, val);
 35.1479 +				        return 1;
 35.1480 +					}
 35.1481 +
 35.1482 +				    static int memory_readdword(lua_State *L)
 35.1483 +				    {
 35.1484 +				        u32 addr;
 35.1485 +				        u32 val;
 35.1486 +
 35.1487 +				        addr = luaL_checkinteger(L, 1);
 35.1488 +				        if (systemIsRunningGBA())
 35.1489 +				        {
 35.1490 +				            val = CPUReadMemoryQuick(addr);
 35.1491 +						}
 35.1492 +				        else
 35.1493 +				        {
 35.1494 +				            val = gbReadMemoryQuick32(addr & 0x0000FFFF);
 35.1495 +						}
 35.1496 +
 35.1497 +				        // lua_pushinteger doesn't work properly for 32bit system, does it?
 35.1498 +				        if (val >= 0x80000000 && sizeof(int) <= 4)
 35.1499 +							lua_pushnumber(L, val);
 35.1500 +				        else
 35.1501 +							lua_pushinteger(L, val);
 35.1502 +				        return 1;
 35.1503 +					}
 35.1504 +
 35.1505 +				    static int memory_readdwordsigned(lua_State *L)
 35.1506 +				    {
 35.1507 +				        u32 addr;
 35.1508 +				        s32 val;
 35.1509 +
 35.1510 +				        addr = luaL_checkinteger(L, 1);
 35.1511 +				        if (systemIsRunningGBA())
 35.1512 +				        {
 35.1513 +				            val = (s32) CPUReadMemoryQuick(addr);
 35.1514 +						}
 35.1515 +				        else
 35.1516 +				        {
 35.1517 +				            val = (s32) gbReadMemoryQuick32(addr);
 35.1518 +						}
 35.1519 +
 35.1520 +				        lua_pushinteger(L, val);
 35.1521 +				        return 1;
 35.1522 +					}
 35.1523 +
 35.1524 +				    static int memory_readbyterange(lua_State *L)
 35.1525 +				    {
 35.1526 +				        uint32 address = luaL_checkinteger(L, 1);
 35.1527 +				        int	   length  = luaL_checkinteger(L, 2);
 35.1528 +
 35.1529 +				        if (length < 0)
 35.1530 +				        {
 35.1531 +				            address += length;
 35.1532 +				            length	 = -length;
 35.1533 +						}
 35.1534 +
 35.1535 +				        // push the array
 35.1536 +				        lua_createtable(L, abs(length), 0);
 35.1537 +
 35.1538 +				        // put all the values into the (1-based) array
 35.1539 +				        for (int a = address, n = 1; n <= length; a++, n++)
 35.1540 +				        {
 35.1541 +				            unsigned char value;
 35.1542 +
 35.1543 +				            if (systemIsRunningGBA())
 35.1544 +				            {
 35.1545 +				                value = CPUReadByteQuick(a);
 35.1546 +							}
 35.1547 +				            else
 35.1548 +				            {
 35.1549 +				                value = gbReadMemoryQuick8(a);
 35.1550 +							}
 35.1551 +
 35.1552 +				            lua_pushinteger(L, value);
 35.1553 +				            lua_rawseti(L, -2, n);
 35.1554 +						}
 35.1555 +
 35.1556 +				        return 1;
 35.1557 +					}
 35.1558 +
 35.1559 +				    static int memory_writebyte(lua_State *L)
 35.1560 +				    {
 35.1561 +				        u32 addr;
 35.1562 +				        int val;
 35.1563 +
 35.1564 +				        addr = luaL_checkinteger(L, 1);
 35.1565 +				        val	 = luaL_checkinteger(L, 2);
 35.1566 +				        if (systemIsRunningGBA())
 35.1567 +				        {
 35.1568 +				            CPUWriteByteQuick(addr, val);
 35.1569 +						}
 35.1570 +				        else
 35.1571 +				        {
 35.1572 +				            gbWriteMemoryQuick8(addr, val);
 35.1573 +						}
 35.1574 +
 35.1575 +				        CallRegisteredLuaMemHook(addr, 1, val, LUAMEMHOOK_WRITE);
 35.1576 +				        return 0;
 35.1577 +					}
 35.1578 +
 35.1579 +				    static int memory_writeword(lua_State *L)
 35.1580 +				    {
 35.1581 +				        u32 addr;
 35.1582 +				        int val;
 35.1583 +
 35.1584 +				        addr = luaL_checkinteger(L, 1);
 35.1585 +				        val	 = luaL_checkinteger(L, 2);
 35.1586 +				        if (systemIsRunningGBA())
 35.1587 +				        {
 35.1588 +				            CPUWriteHalfWordQuick(addr, val);
 35.1589 +						}
 35.1590 +				        else
 35.1591 +				        {
 35.1592 +				            gbWriteMemoryQuick16(addr, val);
 35.1593 +						}
 35.1594 +
 35.1595 +				        CallRegisteredLuaMemHook(addr, 2, val, LUAMEMHOOK_WRITE);
 35.1596 +				        return 0;
 35.1597 +					}
 35.1598 +
 35.1599 +				    static int memory_writedword(lua_State *L)
 35.1600 +				    {
 35.1601 +				        u32 addr;
 35.1602 +				        int val;
 35.1603 +
 35.1604 +				        addr = luaL_checkinteger(L, 1);
 35.1605 +				        val	 = luaL_checkinteger(L, 2);
 35.1606 +				        if (systemIsRunningGBA())
 35.1607 +				        {
 35.1608 +				            CPUWriteMemoryQuick(addr, val);
 35.1609 +						}
 35.1610 +				        else
 35.1611 +				        {
 35.1612 +				            gbWriteMemoryQuick32(addr, val);
 35.1613 +						}
 35.1614 +
 35.1615 +				        CallRegisteredLuaMemHook(addr, 4, val, LUAMEMHOOK_WRITE);
 35.1616 +				        return 0;
 35.1617 +					}
 35.1618 +
 35.1619 +				    static int memory_gbromreadbyte(lua_State *L)
 35.1620 +				    {
 35.1621 +				        u32 addr;
 35.1622 +				        u8	val;
 35.1623 +
 35.1624 +				        addr = luaL_checkinteger(L, 1);
 35.1625 +				        if (systemIsRunningGBA())
 35.1626 +				        {
 35.1627 +							lua_pushnil(L);
 35.1628 +							return 1;
 35.1629 +						}
 35.1630 +				        else
 35.1631 +				        {
 35.1632 +				            val = gbReadROMQuick8(addr);
 35.1633 +						}
 35.1634 +
 35.1635 +				        lua_pushinteger(L, val);
 35.1636 +				        return 1;
 35.1637 +					}
 35.1638 +
 35.1639 +				    static int memory_gbromreadbytesigned(lua_State *L)
 35.1640 +				    {
 35.1641 +				        u32 addr;
 35.1642 +				        s8	val;
 35.1643 +
 35.1644 +				        addr = luaL_checkinteger(L, 1);
 35.1645 +				        if (systemIsRunningGBA())
 35.1646 +				        {
 35.1647 +				            lua_pushnil(L);
 35.1648 +							return 1;
 35.1649 +						}
 35.1650 +				        else
 35.1651 +				        {
 35.1652 +				            val = (s8) gbReadROMQuick8(addr);
 35.1653 +						}
 35.1654 +
 35.1655 +				        lua_pushinteger(L, val);
 35.1656 +				        return 1;
 35.1657 +					}
 35.1658 +
 35.1659 +				    static int memory_gbromreadword(lua_State *L)
 35.1660 +				    {
 35.1661 +				        u32 addr;
 35.1662 +				        u16 val;
 35.1663 +
 35.1664 +				        addr = luaL_checkinteger(L, 1);
 35.1665 +				        if (systemIsRunningGBA())
 35.1666 +				        {
 35.1667 +				            lua_pushnil(L);
 35.1668 +							return 1;
 35.1669 +						}
 35.1670 +				        else
 35.1671 +				        {
 35.1672 +				            val = gbReadROMQuick16(addr);
 35.1673 +						}
 35.1674 +
 35.1675 +				        lua_pushinteger(L, val);
 35.1676 +				        return 1;
 35.1677 +					}
 35.1678 +
 35.1679 +				    static int memory_gbromreadwordsigned(lua_State *L)
 35.1680 +				    {
 35.1681 +				        u32 addr;
 35.1682 +				        s16 val;
 35.1683 +
 35.1684 +				        addr = luaL_checkinteger(L, 1);
 35.1685 +				        if (systemIsRunningGBA())
 35.1686 +				        {
 35.1687 +				            lua_pushnil(L);
 35.1688 +							return 1;
 35.1689 +						}
 35.1690 +				        else
 35.1691 +				        {
 35.1692 +				            val = (s16) gbReadROMQuick16(addr);
 35.1693 +						}
 35.1694 +
 35.1695 +				        lua_pushinteger(L, val);
 35.1696 +				        return 1;
 35.1697 +					}
 35.1698 +
 35.1699 +				    static int memory_gbromreaddword(lua_State *L)
 35.1700 +				    {
 35.1701 +				        u32 addr;
 35.1702 +				        u32 val;
 35.1703 +
 35.1704 +				        addr = luaL_checkinteger(L, 1);
 35.1705 +				        if (systemIsRunningGBA())
 35.1706 +				        {
 35.1707 +				            lua_pushnil(L);
 35.1708 +							return 1;
 35.1709 +						}
 35.1710 +				        else
 35.1711 +				        {
 35.1712 +				            val = gbReadROMQuick32(addr);
 35.1713 +						}
 35.1714 +
 35.1715 +				        // lua_pushinteger doesn't work properly for 32bit system, does it?
 35.1716 +				        if (val >= 0x80000000 && sizeof(int) <= 4)
 35.1717 +							lua_pushnumber(L, val);
 35.1718 +				        else
 35.1719 +							lua_pushinteger(L, val);
 35.1720 +				        return 1;
 35.1721 +					}
 35.1722 +
 35.1723 +				    static int memory_gbromreaddwordsigned(lua_State *L)
 35.1724 +				    {
 35.1725 +				        u32 addr;
 35.1726 +				        s32 val;
 35.1727 +
 35.1728 +				        addr = luaL_checkinteger(L, 1);
 35.1729 +				        if (systemIsRunningGBA())
 35.1730 +				        {
 35.1731 +				            lua_pushnil(L);
 35.1732 +							return 1;
 35.1733 +						}
 35.1734 +				        else
 35.1735 +				        {
 35.1736 +				            val = (s32) gbReadROMQuick32(addr);
 35.1737 +						}
 35.1738 +
 35.1739 +				        lua_pushinteger(L, val);
 35.1740 +				        return 1;
 35.1741 +					}
 35.1742 +
 35.1743 +				    static int memory_gbromreadbyterange(lua_State *L)
 35.1744 +				    {
 35.1745 +				        uint32 address = luaL_checkinteger(L, 1);
 35.1746 +				        int	   length  = luaL_checkinteger(L, 2);
 35.1747 +
 35.1748 +				        if (length < 0)
 35.1749 +				        {
 35.1750 +				            address += length;
 35.1751 +				            length	 = -length;
 35.1752 +						}
 35.1753 +
 35.1754 +				        // push the array
 35.1755 +				        lua_createtable(L, abs(length), 0);
 35.1756 +
 35.1757 +				        // put all the values into the (1-based) array
 35.1758 +				        for (int a = address, n = 1; n <= length; a++, n++)
 35.1759 +				        {
 35.1760 +				            unsigned char value;
 35.1761 +
 35.1762 +				            if (systemIsRunningGBA())
 35.1763 +				            {
 35.1764 +				                lua_pushnil(L);
 35.1765 +								return 1;
 35.1766 +							}
 35.1767 +				            else
 35.1768 +				            {
 35.1769 +				                value = gbReadROMQuick8(a);
 35.1770 +							}
 35.1771 +
 35.1772 +				            lua_pushinteger(L, value);
 35.1773 +				            lua_rawseti(L, -2, n);
 35.1774 +						}
 35.1775 +
 35.1776 +				        return 1;
 35.1777 +					}
 35.1778 +
 35.1779 +// table joypad.get(int which = 1)
 35.1780 +//
 35.1781 +//  Reads the joypads as inputted by the user.
 35.1782 +				    static int joy_get_internal(lua_State *L, bool reportUp, bool reportDown)
 35.1783 +				    {
 35.1784 +				        // Reads the joypads as inputted by the user
 35.1785 +				        int which = luaL_checkinteger(L, 1);
 35.1786 +
 35.1787 +				        if (which < 0 || which > 4)
 35.1788 +				        {
 35.1789 +				            luaL_error(L, "Invalid input port (valid range 0-4, specified %d)", which);
 35.1790 +						}
 35.1791 +
 35.1792 +				        uint32 buttons = systemGetOriginalJoypad(which - 1, false);
 35.1793 +
 35.1794 +				        lua_newtable(L);
 35.1795 +
 35.1796 +				        int i;
 35.1797 +				        for (i = 0; i < 10; i++)
 35.1798 +				        {
 35.1799 +				            bool pressed = (buttons & (1 << i)) != 0;
 35.1800 +				            if ((pressed && reportDown) || (!pressed && reportUp))
 35.1801 +				            {
 35.1802 +				                lua_pushboolean(L, pressed);
 35.1803 +				                lua_setfield(L, -2, button_mappings[i]);
 35.1804 +							}
 35.1805 +						}
 35.1806 +
 35.1807 +				        return 1;
 35.1808 +					}
 35.1809 +
 35.1810 +// joypad.get(which)
 35.1811 +// returns a table of every game button,
 35.1812 +// true meaning currently-held and false meaning not-currently-held
 35.1813 +// (as of last frame boundary)
 35.1814 +// this WILL read input from a currently-playing movie
 35.1815 +				    static int joypad_get(lua_State *L)
 35.1816 +				    {
 35.1817 +				        return joy_get_internal(L, true, true);
 35.1818 +					}
 35.1819 +
 35.1820 +// joypad.getdown(which)
 35.1821 +// returns a table of every game button that is currently held
 35.1822 +				    static int joypad_getdown(lua_State *L)
 35.1823 +				    {
 35.1824 +				        return joy_get_internal(L, false, true);
 35.1825 +					}
 35.1826 +
 35.1827 +// joypad.getup(which)
 35.1828 +// returns a table of every game button that is not currently held
 35.1829 +				    static int joypad_getup(lua_State *L)
 35.1830 +				    {
 35.1831 +				        return joy_get_internal(L, true, false);
 35.1832 +					}
 35.1833 +
 35.1834 +// joypad.set(int which, table buttons)
 35.1835 +//
 35.1836 +//   Sets the given buttons to be pressed during the next
 35.1837 +//   frame advance. The table should have the right
 35.1838 +
 35.1839 +//   keys (no pun intended) set.
 35.1840 +				    static int joypad_set(lua_State *L)
 35.1841 +				    {
 35.1842 +				        // Which joypad we're tampering with
 35.1843 +				        int which = luaL_checkinteger(L, 1);
 35.1844 +				        if (which < 0 || which > 4)
 35.1845 +				        {
 35.1846 +				            luaL_error(L, "Invalid output port (valid range 0-4, specified %d)", which);
 35.1847 +						}
 35.1848 +
 35.1849 +				        if (which == 0)
 35.1850 +							which = systemGetDefaultJoypad();
 35.1851 +
 35.1852 +				        // And the table of buttons.
 35.1853 +				        luaL_checktype(L, 2, LUA_TTABLE);
 35.1854 +
 35.1855 +				        // Set up for taking control of the indicated controller
 35.1856 +				        lua_joypads_used	  |= 1 << (which - 1);
 35.1857 +				        lua_joypads[which - 1] = 0;
 35.1858 +
 35.1859 +				        for (int i = 0; i < 10; i++)
 35.1860 +				        {
 35.1861 +				            const char *name = button_mappings[i];
 35.1862 +				            lua_getfield(L, 2, name);
 35.1863 +				            if (!lua_isnil(L, -1))
 35.1864 +				            {
 35.1865 +				                bool pressed = lua_toboolean(L, -1) != 0;
 35.1866 +				                if (pressed)
 35.1867 +									lua_joypads[which - 1] |= 1 << i;
 35.1868 +				                else
 35.1869 +									lua_joypads[which - 1] &= ~(1 << i);
 35.1870 +							}
 35.1871 +				            lua_pop(L, 1);
 35.1872 +						}
 35.1873 +
 35.1874 +				        return 0;
 35.1875 +					}
 35.1876 +
 35.1877 +// Helper function to convert a savestate object to the filename it represents.
 35.1878 +				    static const char *savestateobj2filename(lua_State *L, int offset)
 35.1879 +				    {
 35.1880 +				        // First we get the metatable of the indicated object
 35.1881 +				        int result = lua_getmetatable(L, offset);
 35.1882 +
 35.1883 +				        if (!result)
 35.1884 +							luaL_error(L, "object not a savestate object");
 35.1885 +
 35.1886 +				        // Also check that the type entry is set
 35.1887 +				        lua_getfield(L, -1, "__metatable");
 35.1888 +				        if (strcmp(lua_tostring(L, -1), "vba Savestate") != 0)
 35.1889 +							luaL_error(L, "object not a savestate object");
 35.1890 +				        lua_pop(L, 1);
 35.1891 +
 35.1892 +				        // Now, get the field we want
 35.1893 +				        lua_getfield(L, -1, "filename");
 35.1894 +
 35.1895 +				        // Return it
 35.1896 +				        return lua_tostring(L, -1);
 35.1897 +					}
 35.1898 +
 35.1899 +// Helper function for garbage collection.
 35.1900 +				    static int savestate_gc(lua_State *L)
 35.1901 +				    {
 35.1902 +				        // The object we're collecting is on top of the stack
 35.1903 +				        lua_getmetatable(L, 1);
 35.1904 +
 35.1905 +				        // Get the filename
 35.1906 +				        const char *filename;
 35.1907 +				        lua_getfield(L, -1, "filename");
 35.1908 +				        filename = lua_tostring(L, -1);
 35.1909 +
 35.1910 +				        // Delete the file
 35.1911 +				        remove(filename);
 35.1912 +
 35.1913 +				        // We exit, and the garbage collector takes care of the rest.
 35.1914 +				        // Edit: Visual Studio needs a return value anyway, so returns 0.
 35.1915 +				        return 0;
 35.1916 +					}
 35.1917 +
 35.1918 +// object savestate.create(int which = nil)
 35.1919 +//
 35.1920 +//  Creates an object used for savestates.
 35.1921 +//  The object can be associated with a player-accessible savestate
 35.1922 +
 35.1923 +//  ("which" between 1 and 12) or not (which == nil).
 35.1924 +				    static int savestate_create(lua_State *L)
 35.1925 +				    {
 35.1926 +				        int which = -1;
 35.1927 +				        if (lua_gettop(L) >= 1)
 35.1928 +				        {
 35.1929 +				            which = luaL_checkinteger(L, 1);
 35.1930 +				            if (which < 1 || which > 12)
 35.1931 +				            {
 35.1932 +				                luaL_error(L, "invalid player's savestate %d", which);
 35.1933 +							}
 35.1934 +						}
 35.1935 +
 35.1936 +				        char stateName[2048];
 35.1937 +
 35.1938 +				        if (which > 0)
 35.1939 +				        {
 35.1940 +				            // Find an appropriate filename. This is OS specific, unfortunately.
 35.1941 +#if (defined(WIN32) && !defined(SDL))
 35.1942 +				            CString stateName = winGetSavestateFilename(theApp.gameFilename, which);
 35.1943 +#else
 35.1944 +				            extern char saveDir[2048];
 35.1945 +				            extern char filename[2048];
 35.1946 +				            extern char *sdlGetFilename(char *name);
 35.1947 +
 35.1948 +				            if (saveDir[0])
 35.1949 +								sprintf(stateName, "%s/%s%d.sgm", saveDir, sdlGetFilename(filename), which);
 35.1950 +				            else
 35.1951 +								sprintf(stateName, "%s%d.sgm", filename, which);
 35.1952 +#endif
 35.1953 +						}
 35.1954 +				        else
 35.1955 +				        {
 35.1956 +				            char *stateNameTemp = tempnam(NULL, "snlua");
 35.1957 +				            strcpy(stateName, stateNameTemp);
 35.1958 +				            if (stateNameTemp)
 35.1959 +								free(stateNameTemp);
 35.1960 +						}
 35.1961 +
 35.1962 +				        // Our "object". We don't care about the type, we just need the memory and GC services.
 35.1963 +				        lua_newuserdata(L, 1);
 35.1964 +
 35.1965 +				        // The metatable we use, protected from Lua and contains garbage collection info and stuff.
 35.1966 +				        lua_newtable(L);
 35.1967 +
 35.1968 +				        // First, we must protect it
 35.1969 +				        lua_pushstring(L, "vba Savestate");
 35.1970 +				        lua_setfield(L, -2, "__metatable");
 35.1971 +
 35.1972 +				        // Now we need to save the file itself.
 35.1973 +				        lua_pushstring(L, stateName);
 35.1974 +				        lua_setfield(L, -2, "filename");
 35.1975 +
 35.1976 +				        // If it's an anonymous savestate, we must delete the file from disk should it be gargage collected
 35.1977 +				        if (which < 0)
 35.1978 +				        {
 35.1979 +				            lua_pushcfunction(L, savestate_gc);
 35.1980 +				            lua_setfield(L, -2, "__gc");
 35.1981 +						}
 35.1982 +
 35.1983 +				        // Set the metatable
 35.1984 +				        lua_setmetatable(L, -2);
 35.1985 +
 35.1986 +				        // Awesome. Return the object
 35.1987 +				        return 1;
 35.1988 +					}
 35.1989 +
 35.1990 +// savestate.save(object state)
 35.1991 +//
 35.1992 +
 35.1993 +//   Saves a state to the given object.
 35.1994 +				    static int savestate_save(lua_State *L)
 35.1995 +				    {
 35.1996 +				        const char *filename = savestateobj2filename(L, 1);
 35.1997 +
 35.1998 +				        //	printf("saving %s\n", filename);
 35.1999 +				        // Save states are very expensive. They take time.
 35.2000 +				        numTries--;
 35.2001 +
 35.2002 +				        bool8 retvalue = theEmulator.emuWriteState ? theEmulator.emuWriteState(filename) : false;
 35.2003 +				        if (!retvalue)
 35.2004 +				        {
 35.2005 +				            // Uh oh
 35.2006 +				            luaL_error(L, "savestate failed");
 35.2007 +						}
 35.2008 +
 35.2009 +				        return 0;
 35.2010 +					}
 35.2011 +
 35.2012 +// savestate.load(object state)
 35.2013 +//
 35.2014 +
 35.2015 +//   Loads the given state
 35.2016 +				    static int savestate_load(lua_State *L)
 35.2017 +				    {
 35.2018 +				        const char *filename = savestateobj2filename(L, 1);
 35.2019 +
 35.2020 +				        numTries--;
 35.2021 +
 35.2022 +				        //	printf("loading %s\n", filename);
 35.2023 +				        bool8 retvalue = theEmulator.emuReadState ? theEmulator.emuReadState(filename) : false;
 35.2024 +				        if (!retvalue)
 35.2025 +				        {
 35.2026 +				            // Uh oh
 35.2027 +				            luaL_error(L, "loadstate failed");
 35.2028 +						}
 35.2029 +
 35.2030 +				        return 0;
 35.2031 +					}
 35.2032 +
 35.2033 +// int vba.framecount()
 35.2034 +//
 35.2035 +
 35.2036 +//   Gets the frame counter for the movie, or the number of frames since last reset.
 35.2037 +				    int vba_framecount(lua_State *L)
 35.2038 +				    {
 35.2039 +				        if (!VBAMovieActive())
 35.2040 +				        {
 35.2041 +				            lua_pushinteger(L, systemCounters.frameCount);
 35.2042 +						}
 35.2043 +				        else
 35.2044 +				        {
 35.2045 +				            lua_pushinteger(L, VBAMovieGetFrameCounter());
 35.2046 +						}
 35.2047 +
 35.2048 +				        return 1;
 35.2049 +					}
 35.2050 +
 35.2051 +//string movie.getauthor
 35.2052 +//
 35.2053 +
 35.2054 +// returns author info field of .vbm file
 35.2055 +				    int movie_getauthor(lua_State *L)
 35.2056 +				    {
 35.2057 +				        if (!VBAMovieActive())
 35.2058 +				        {
 35.2059 +				            //lua_pushnil(L);
 35.2060 +				            lua_pushstring(L, "");
 35.2061 +				            return 1;
 35.2062 +						}
 35.2063 +
 35.2064 +				        lua_pushstring(L, VBAMovieGetAuthorInfo().c_str());
 35.2065 +				        return 1;
 35.2066 +					}
 35.2067 +
 35.2068 +//string movie.filename
 35.2069 +				    int movie_getfilename(lua_State *L)
 35.2070 +				    {
 35.2071 +				        if (!VBAMovieActive())
 35.2072 +				        {
 35.2073 +				            //lua_pushnil(L);
 35.2074 +				            lua_pushstring(L, "");
 35.2075 +				            return 1;
 35.2076 +						}
 35.2077 +
 35.2078 +				        lua_pushstring(L, VBAMovieGetFilename().c_str());
 35.2079 +				        return 1;
 35.2080 +					}
 35.2081 +
 35.2082 +// string movie.mode()
 35.2083 +//
 35.2084 +
 35.2085 +//   "record", "playback" or nil
 35.2086 +				    int movie_getmode(lua_State *L)
 35.2087 +				    {
 35.2088 +				        assert(!VBAMovieLoading());
 35.2089 +				        if (!VBAMovieActive())
 35.2090 +				        {
 35.2091 +				            lua_pushnil(L);
 35.2092 +				            return 1;
 35.2093 +						}
 35.2094 +
 35.2095 +				        if (VBAMovieRecording())
 35.2096 +							lua_pushstring(L, "record");
 35.2097 +				        else
 35.2098 +							lua_pushstring(L, "playback");
 35.2099 +				        return 1;
 35.2100 +					}
 35.2101 +
 35.2102 +				    static int movie_rerecordcount(lua_State *L)
 35.2103 +				    {
 35.2104 +				        if (VBAMovieActive())
 35.2105 +							lua_pushinteger(L, VBAMovieGetRerecordCount());
 35.2106 +				        else
 35.2107 +							lua_pushinteger(L, 0);
 35.2108 +				        return 1;
 35.2109 +					}
 35.2110 +
 35.2111 +				    static int movie_setrerecordcount(lua_State *L)
 35.2112 +				    {
 35.2113 +				        if (VBAMovieActive())
 35.2114 +							VBAMovieSetRerecordCount(luaL_checkinteger(L, 1));
 35.2115 +				        return 0;
 35.2116 +					}
 35.2117 +
 35.2118 +				    static int movie_rerecordcounting(lua_State *L)
 35.2119 +				    {
 35.2120 +				        if (lua_gettop(L) == 0)
 35.2121 +							luaL_error(L, "no parameters specified");
 35.2122 +
 35.2123 +				        skipRerecords = lua_toboolean(L, 1);
 35.2124 +				        return 0;
 35.2125 +					}
 35.2126 +
 35.2127 +// movie.stop()
 35.2128 +//
 35.2129 +
 35.2130 +//   Stops movie playback/recording. Bombs out if movie is not running.
 35.2131 +				    static int movie_stop(lua_State *L)
 35.2132 +				    {
 35.2133 +				        if (!VBAMovieActive())
 35.2134 +							luaL_error(L, "no movie");
 35.2135 +
 35.2136 +				        VBAMovieStop(false);
 35.2137 +				        return 0;
 35.2138 +					}
 35.2139 +
 35.2140 +#define LUA_SCREEN_WIDTH    256
 35.2141 +#define LUA_SCREEN_HEIGHT   239
 35.2142 +
 35.2143 +// Common code by the gui library: make sure the screen array is ready
 35.2144 +				    static void gui_prepare(void)
 35.2145 +				    {
 35.2146 +				        if (!gui_data)
 35.2147 +							gui_data = (uint8 *)malloc(LUA_SCREEN_WIDTH * LUA_SCREEN_HEIGHT * 4);
 35.2148 +				        if (!gui_used)
 35.2149 +							memset(gui_data, 0, LUA_SCREEN_WIDTH * LUA_SCREEN_HEIGHT * 4);
 35.2150 +				        gui_used = true;
 35.2151 +					}
 35.2152 +
 35.2153 +// pixform for lua graphics
 35.2154 +#define BUILD_PIXEL_ARGB8888(A, R, G, B)    (((int)(A) << 24) | ((int)(R) << 16) | ((int)(G) << 8) | (int)(B))
 35.2155 +#define DECOMPOSE_PIXEL_ARGB8888(PIX, A, R, G, B) \
 35.2156 +	{                                             \
 35.2157 +		(A) = ((PIX) >> 24) & 0xff;               \
 35.2158 +		(R) = ((PIX) >> 16) & 0xff;               \
 35.2159 +		(G) = ((PIX) >> 8) & 0xff;                \
 35.2160 +		(B) = (PIX) & 0xff;                       \
 35.2161 +	}
 35.2162 +#define LUA_BUILD_PIXEL     BUILD_PIXEL_ARGB8888
 35.2163 +#define LUA_DECOMPOSE_PIXEL DECOMPOSE_PIXEL_ARGB8888
 35.2164 +#define LUA_PIXEL_A(PIX) (((PIX) >> 24) & 0xff)
 35.2165 +#define LUA_PIXEL_R(PIX) (((PIX) >> 16) & 0xff)
 35.2166 +#define LUA_PIXEL_G(PIX) (((PIX) >> 8) & 0xff)
 35.2167 +#define LUA_PIXEL_B(PIX) ((PIX) & 0xff)
 35.2168 +
 35.2169 +				    template<class T>
 35.2170 +				    static void swap(T &one, T &two)
 35.2171 +				    {
 35.2172 +				        T temp = one;
 35.2173 +				        one = two;
 35.2174 +				        two = temp;
 35.2175 +					}
 35.2176 +
 35.2177 +// write a pixel to buffer
 35.2178 +				    static inline void blend32(uint32 *dstPixel, uint32 colour)
 35.2179 +				    {
 35.2180 +				        uint8 *dst = (uint8 *)dstPixel;
 35.2181 +				        int	   a, r, g, b;
 35.2182 +				        LUA_DECOMPOSE_PIXEL(colour, a, r, g, b);
 35.2183 +
 35.2184 +				        if (a == 255 || dst[3] == 0)
 35.2185 +				        {
 35.2186 +				            // direct copy
 35.2187 +				            *(uint32 *) (dst) = colour;
 35.2188 +						}
 35.2189 +				        else if (a == 0)
 35.2190 +				        {
 35.2191 +				            // do not copy
 35.2192 +						}
 35.2193 +				        else
 35.2194 +				        {
 35.2195 +				            // alpha-blending
 35.2196 +				            int a_dst = ((255 - a) * dst[3] + 128) / 255;
 35.2197 +				            int a_new = a + a_dst;
 35.2198 +
 35.2199 +				            dst[0] = (uint8) (((dst[0] * a_dst + b * a) + (a_new / 2)) / a_new);
 35.2200 +				            dst[1] = (uint8) (((dst[1] * a_dst + g * a) + (a_new / 2)) / a_new);
 35.2201 +				            dst[2] = (uint8) (((dst[2] * a_dst + r * a) + (a_new / 2)) / a_new);
 35.2202 +				            dst[3] = (uint8) a_new;
 35.2203 +						}
 35.2204 +					}
 35.2205 +
 35.2206 +// check if a pixel is in the lua canvas
 35.2207 +				    static inline bool gui_check_boundary(int x, int y)
 35.2208 +				    {
 35.2209 +				        return !(x < 0 || x >= LUA_SCREEN_WIDTH || y < 0 || y >= LUA_SCREEN_HEIGHT);
 35.2210 +					}
 35.2211 +
 35.2212 +// check if any part of a box is in the lua canvas
 35.2213 +				    static inline bool gui_checkbox(int x1, int y1, int x2, int y2)
 35.2214 +				    {
 35.2215 +				        if ((x1 <  0 && x2 <  0)
 35.2216 +				            || (x1 >= LUA_SCREEN_WIDTH && x2 >= LUA_SCREEN_WIDTH)
 35.2217 +				            || (y1 <  0 && y2 <  0)
 35.2218 +				            || (y1 >= LUA_SCREEN_HEIGHT && y2 >= LUA_SCREEN_HEIGHT))
 35.2219 +							return false;
 35.2220 +				        return true;
 35.2221 +					}
 35.2222 +
 35.2223 +// write a pixel to gui_data (do not check boundaries for speedup)
 35.2224 +				    static inline void gui_drawpixel_fast(int x, int y, uint32 colour)
 35.2225 +				    {
 35.2226 +				        //gui_prepare();
 35.2227 +				        blend32((uint32 *) &gui_data[(y * LUA_SCREEN_WIDTH + x) * 4], colour);
 35.2228 +					}
 35.2229 +
 35.2230 +// write a pixel to gui_data (check boundaries)
 35.2231 +				    static inline void gui_drawpixel_internal(int x, int y, uint32 colour)
 35.2232 +				    {
 35.2233 +				        //gui_prepare();
 35.2234 +				        if (gui_check_boundary(x, y))
 35.2235 +							gui_drawpixel_fast(x, y, colour);
 35.2236 +					}
 35.2237 +
 35.2238 +// draw a line on gui_data (checks boundaries)
 35.2239 +				    static void gui_drawline_internal(int x1, int y1, int x2, int y2, bool lastPixel, uint32 colour)
 35.2240 +				    {
 35.2241 +				        //gui_prepare();
 35.2242 +				        // Note: New version of Bresenham's Line Algorithm
 35.2243 +				        //
 35.2244 +				        //
 35.2245 +				        // http://groups.google.co.jp/group/rec.games.roguelike.development/browse_thread/thread/345f4c42c3b25858/29e07a3af3a450e6?show_docid=29e07a3af3a450e6
 35.2246 +				        int swappedx = 0;
 35.2247 +				        int swappedy = 0;
 35.2248 +
 35.2249 +				        int xtemp = x1 - x2;
 35.2250 +				        int ytemp = y1 - y2;
 35.2251 +				        if (xtemp == 0 && ytemp == 0)
 35.2252 +				        {
 35.2253 +				            gui_drawpixel_internal(x1, y1, colour);
 35.2254 +				            return;
 35.2255 +						}
 35.2256 +
 35.2257 +				        if (xtemp < 0)
 35.2258 +				        {
 35.2259 +				            xtemp	 = -xtemp;
 35.2260 +				            swappedx = 1;
 35.2261 +						}
 35.2262 +
 35.2263 +				        if (ytemp < 0)
 35.2264 +				        {
 35.2265 +				            ytemp	 = -ytemp;
 35.2266 +				            swappedy = 1;
 35.2267 +						}
 35.2268 +
 35.2269 +				        int delta_x = xtemp << 1;
 35.2270 +				        int delta_y = ytemp << 1;
 35.2271 +
 35.2272 +				        signed char ix = x1 > x2 ? 1 : -1;
 35.2273 +				        signed char iy = y1 > y2 ? 1 : -1;
 35.2274 +
 35.2275 +				        if (lastPixel)
 35.2276 +							gui_drawpixel_internal(x2, y2, colour);
 35.2277 +
 35.2278 +				        if (delta_x >= delta_y)
 35.2279 +				        {
 35.2280 +				            int error = delta_y - (delta_x >> 1);
 35.2281 +
 35.2282 +				            while (x2 != x1)
 35.2283 +				            {
 35.2284 +				                if (error == 0 && !swappedx)
 35.2285 +									gui_drawpixel_internal(x2 + ix, y2, colour);
 35.2286 +				                if (error >= 0)
 35.2287 +				                {
 35.2288 +				                    if (error || (ix > 0))
 35.2289 +				                    {
 35.2290 +				                        y2	  += iy;
 35.2291 +				                        error -= delta_x;
 35.2292 +									}
 35.2293 +								}
 35.2294 +
 35.2295 +				                x2 += ix;
 35.2296 +				                gui_drawpixel_internal(x2, y2, colour);
 35.2297 +				                if (error == 0 && swappedx)
 35.2298 +									gui_drawpixel_internal(x2, y2 + iy, colour);
 35.2299 +				                error += delta_y;
 35.2300 +							}
 35.2301 +						}
 35.2302 +				        else
 35.2303 +				        {
 35.2304 +				            int error = delta_x - (delta_y >> 1);
 35.2305 +
 35.2306 +				            while (y2 != y1)
 35.2307 +				            {
 35.2308 +				                if (error == 0 && !swappedy)
 35.2309 +									gui_drawpixel_internal(x2, y2 + iy, colour);
 35.2310 +				                if (error >= 0)
 35.2311 +				                {
 35.2312 +				                    if (error || (iy > 0))
 35.2313 +				                    {
 35.2314 +				                        x2	  += ix;
 35.2315 +				                        error -= delta_y;
 35.2316 +									}
 35.2317 +								}
 35.2318 +
 35.2319 +				                y2 += iy;
 35.2320 +				                gui_drawpixel_internal(x2, y2, colour);
 35.2321 +				                if (error == 0 && swappedy)
 35.2322 +									gui_drawpixel_internal(x2 + ix, y2, colour);
 35.2323 +				                error += delta_x;
 35.2324 +							}
 35.2325 +						}
 35.2326 +					}
 35.2327 +
 35.2328 +// draw a rect on gui_data
 35.2329 +				    static void gui_drawbox_internal(int x1, int y1, int x2, int y2, uint32 colour)
 35.2330 +				    {
 35.2331 +				        if (x1 > x2)
 35.2332 +							std::swap(x1, x2);
 35.2333 +				        if (y1 > y2)
 35.2334 +							std::swap(y1, y2);
 35.2335 +				        if (x1 < 0)
 35.2336 +							x1 = -1;
 35.2337 +				        if (y1 < 0)
 35.2338 +							y1 = -1;
 35.2339 +				        if (x2 >= LUA_SCREEN_WIDTH)
 35.2340 +							x2 = LUA_SCREEN_WIDTH;
 35.2341 +				        if (y2 >= LUA_SCREEN_HEIGHT)
 35.2342 +							y2 = LUA_SCREEN_HEIGHT;
 35.2343 +
 35.2344 +				        if (!gui_checkbox(x1, y1, x2, y2))
 35.2345 +							return;
 35.2346 +
 35.2347 +				        //gui_prepare();
 35.2348 +				        gui_drawline_internal(x1, y1, x2, y1, true, colour);
 35.2349 +				        gui_drawline_internal(x1, y2, x2, y2, true, colour);
 35.2350 +				        gui_drawline_internal(x1, y1, x1, y2, true, colour);
 35.2351 +				        gui_drawline_internal(x2, y1, x2, y2, true, colour);
 35.2352 +					}
 35.2353 +
 35.2354 +// draw a circle on gui_data
 35.2355 +				    static void gui_drawcircle_internal(int x0, int y0, int radius, uint32 colour)
 35.2356 +				    {
 35.2357 +				        //gui_prepare();
 35.2358 +				        if (radius < 0)
 35.2359 +							radius = -radius;
 35.2360 +				        if (radius == 0)
 35.2361 +							return;
 35.2362 +				        if (radius == 1)
 35.2363 +				        {
 35.2364 +				            gui_drawpixel_internal(x0, y0, colour);
 35.2365 +				            return;
 35.2366 +						}
 35.2367 +
 35.2368 +				        // http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
 35.2369 +				        int f	  = 1 - radius;
 35.2370 +				        int ddF_x = 1;
 35.2371 +				        int ddF_y = -2 * radius;
 35.2372 +				        int x	  = 0;
 35.2373 +				        int y	  = radius;
 35.2374 +
 35.2375 +				        if (!gui_checkbox(x0 - radius, y0 - radius, x0 + radius, y0 + radius))
 35.2376 +							return;
 35.2377 +
 35.2378 +				        gui_drawpixel_internal(x0, y0 + radius, colour);
 35.2379 +				        gui_drawpixel_internal(x0, y0 - radius, colour);
 35.2380 +				        gui_drawpixel_internal(x0 + radius, y0, colour);
 35.2381 +				        gui_drawpixel_internal(x0 - radius, y0, colour);
 35.2382 +
 35.2383 +				        // same pixel shouldn't be drawed twice,
 35.2384 +				        // because each pixel has opacity.
 35.2385 +				        // so now the routine gets ugly.
 35.2386 +				        while (true)
 35.2387 +				        {
 35.2388 +				            assert(ddF_x == 2 * x + 1);
 35.2389 +				            assert(ddF_y == -2 * y);
 35.2390 +				            assert(f == x * x + y * y - radius * radius + 2 * x - y + 1);
 35.2391 +				            if (f >= 0)
 35.2392 +				            {
 35.2393 +				                y--;
 35.2394 +				                ddF_y += 2;
 35.2395 +				                f	  += ddF_y;
 35.2396 +							}
 35.2397 +
 35.2398 +				            x++;
 35.2399 +				            ddF_x += 2;
 35.2400 +				            f	  += ddF_x;
 35.2401 +				            if (x < y)
 35.2402 +				            {
 35.2403 +				                gui_drawpixel_internal(x0 + x, y0 + y, colour);
 35.2404 +				                gui_drawpixel_internal(x0 - x, y0 + y, colour);
 35.2405 +				                gui_drawpixel_internal(x0 + x, y0 - y, colour);
 35.2406 +				                gui_drawpixel_internal(x0 - x, y0 - y, colour);
 35.2407 +				                gui_drawpixel_internal(x0 + y, y0 + x, colour);
 35.2408 +				                gui_drawpixel_internal(x0 - y, y0 + x, colour);
 35.2409 +				                gui_drawpixel_internal(x0 + y, y0 - x, colour);
 35.2410 +				                gui_drawpixel_internal(x0 - y, y0 - x, colour);
 35.2411 +							}
 35.2412 +				            else if (x == y)
 35.2413 +				            {
 35.2414 +				                gui_drawpixel_internal(x0 + x, y0 + y, colour);
 35.2415 +				                gui_drawpixel_internal(x0 - x, y0 + y, colour);
 35.2416 +				                gui_drawpixel_internal(x0 + x, y0 - y, colour);
 35.2417 +				                gui_drawpixel_internal(x0 - x, y0 - y, colour);
 35.2418 +				                break;
 35.2419 +							}
 35.2420 +				            else
 35.2421 +								break;
 35.2422 +						}
 35.2423 +					}
 35.2424 +
 35.2425 +// draw fill rect on gui_data
 35.2426 +				    static void gui_fillbox_internal(int x1, int y1, int x2, int y2, uint32 colour)
 35.2427 +				    {
 35.2428 +				        if (x1 > x2)
 35.2429 +							std::swap(x1, x2);
 35.2430 +				        if (y1 > y2)
 35.2431 +							std::swap(y1, y2);
 35.2432 +				        if (x1 < 0)
 35.2433 +							x1 = 0;
 35.2434 +				        if (y1 < 0)
 35.2435 +							y1 = 0;
 35.2436 +				        if (x2 >= LUA_SCREEN_WIDTH)
 35.2437 +							x2 = LUA_SCREEN_WIDTH - 1;
 35.2438 +				        if (y2 >= LUA_SCREEN_HEIGHT)
 35.2439 +							y2 = LUA_SCREEN_HEIGHT - 1;
 35.2440 +
 35.2441 +				        //gui_prepare();
 35.2442 +				        int ix, iy;
 35.2443 +				        for (iy = y1; iy <= y2; iy++)
 35.2444 +				        {
 35.2445 +				            for (ix = x1; ix <= x2; ix++)
 35.2446 +				            {
 35.2447 +				                gui_drawpixel_fast(ix, iy, colour);
 35.2448 +							}
 35.2449 +						}
 35.2450 +					}
 35.2451 +
 35.2452 +// fill a circle on gui_data
 35.2453 +				    static void gui_fillcircle_internal(int x0, int y0, int radius, uint32 colour)
 35.2454 +				    {
 35.2455 +				        //gui_prepare();
 35.2456 +				        if (radius < 0)
 35.2457 +							radius = -radius;
 35.2458 +				        if (radius == 0)
 35.2459 +							return;
 35.2460 +				        if (radius == 1)
 35.2461 +				        {
 35.2462 +				            gui_drawpixel_internal(x0, y0, colour);
 35.2463 +				            return;
 35.2464 +						}
 35.2465 +
 35.2466 +				        // http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
 35.2467 +				        int f	  = 1 - radius;
 35.2468 +				        int ddF_x = 1;
 35.2469 +				        int ddF_y = -2 * radius;
 35.2470 +				        int x	  = 0;
 35.2471 +				        int y	  = radius;
 35.2472 +
 35.2473 +				        if (!gui_checkbox(x0 - radius, y0 - radius, x0 + radius, y0 + radius))
 35.2474 +							return;
 35.2475 +
 35.2476 +				        gui_drawline_internal(x0, y0 - radius, x0, y0 + radius, true, colour);
 35.2477 +
 35.2478 +				        while (true)
 35.2479 +				        {
 35.2480 +				            assert(ddF_x == 2 * x + 1);
 35.2481 +				            assert(ddF_y == -2 * y);
 35.2482 +				            assert(f == x * x + y * y - radius * radius + 2 * x - y + 1);
 35.2483 +				            if (f >= 0)
 35.2484 +				            {
 35.2485 +				                y--;
 35.2486 +				                ddF_y += 2;
 35.2487 +				                f	  += ddF_y;
 35.2488 +							}
 35.2489 +
 35.2490 +				            x++;
 35.2491 +				            ddF_x += 2;
 35.2492 +				            f	  += ddF_x;
 35.2493 +
 35.2494 +				            if (x < y)
 35.2495 +				            {
 35.2496 +				                gui_drawline_internal(x0 + x, y0 - y, x0 + x, y0 + y, true, colour);
 35.2497 +				                gui_drawline_internal(x0 - x, y0 - y, x0 - x, y0 + y, true, colour);
 35.2498 +				                if (f >= 0)
 35.2499 +				                {
 35.2500 +				                    gui_drawline_internal(x0 + y, y0 - x, x0 + y, y0 + x, true, colour);
 35.2501 +				                    gui_drawline_internal(x0 - y, y0 - x, x0 - y, y0 + x, true, colour);
 35.2502 +								}
 35.2503 +							}
 35.2504 +				            else if (x == y)
 35.2505 +				            {
 35.2506 +				                gui_drawline_internal(x0 + x, y0 - y, x0 + x, y0 + y, true, colour);
 35.2507 +				                gui_drawline_internal(x0 - x, y0 - y, x0 - x, y0 + y, true, colour);
 35.2508 +				                break;
 35.2509 +							}
 35.2510 +				            else
 35.2511 +								break;
 35.2512 +						}
 35.2513 +					}
 35.2514 +
 35.2515 +// Helper for a simple hex parser
 35.2516 +				    static int hex2int(lua_State *L, char c)
 35.2517 +				    {
 35.2518 +				        if (c >= '0' && c <= '9')
 35.2519 +							return c - '0';
 35.2520 +				        if (c >= 'a' && c <= 'f')
 35.2521 +							return c - 'a' + 10;
 35.2522 +				        if (c >= 'A' && c <= 'F')
 35.2523 +							return c - 'A' + 10;
 35.2524 +				        return luaL_error(L, "invalid hex in colour");
 35.2525 +					}
 35.2526 +
 35.2527 +				    static const struct ColorMapping
 35.2528 +				    {
 35.2529 +				        const char *name;
 35.2530 +				        int			value;
 35.2531 +					}
 35.2532 +				    s_colorMapping[] =
 35.2533 +				    {
 35.2534 +				        { "white",		0xFFFFFFFF		  },
 35.2535 +				        { "black",		0x000000FF		  },
 35.2536 +				        { "clear",		0x00000000		  },
 35.2537 +				        { "gray",		0x7F7F7FFF		  },
 35.2538 +				        { "grey",		0x7F7F7FFF		  },
 35.2539 +				        { "red",		0xFF0000FF		  },
 35.2540 +				        { "orange",		0xFF7F00FF		  },
 35.2541 +				        { "yellow",		0xFFFF00FF		  },
 35.2542 +				        { "chartreuse", 0x7FFF00FF		  },
 35.2543 +				        { "green",		0x00FF00FF		  },
 35.2544 +				        { "teal",		0x00FF7FFF		  },
 35.2545 +				        { "cyan",		0x00FFFFFF		  },
 35.2546 +				        { "blue",		0x0000FFFF		  },
 35.2547 +				        { "purple",		0x7F00FFFF		  },
 35.2548 +				        { "magenta",	0xFF00FFFF		  },
 35.2549 +					};
 35.2550 +
 35.2551 +/**
 35.2552 + * Converts an integer or a string on the stack at the given
 35.2553 + * offset to a RGB32 colour. Several encodings are supported.
 35.2554 + * The user may construct their own RGB value, given a simple colour name,
 35.2555 + * or an HTML-style "#09abcd" colour. 16 bit reduction doesn't occur at this time.
 35.2556 + */
 35.2557 +				    static inline bool str2colour(uint32 *colour, lua_State *L, const char *str)
 35.2558 +				    {
 35.2559 +				        if (str[0] == '#')
 35.2560 +				        {
 35.2561 +				            int color;
 35.2562 +				            sscanf(str + 1, "%X", &color);
 35.2563 +
 35.2564 +				            int len		= strlen(str + 1);
 35.2565 +				            int missing = max(0, 8 - len);
 35.2566 +				            color <<= missing << 2;
 35.2567 +				            if (missing >= 2)
 35.2568 +								color |= 0xFF;
 35.2569 +				            *colour = color;
 35.2570 +				            return true;
 35.2571 +						}
 35.2572 +				        else
 35.2573 +				        {
 35.2574 +				            if (!strnicmp(str, "rand", 4))
 35.2575 +				            {
 35.2576 +				                *colour = gen_rand32() | 0xFF; //((rand()*255/RAND_MAX) << 8) | ((rand()*255/RAND_MAX) << 16) |
 35.2577 +				                                               // ((rand()*255/RAND_MAX) << 24) | 0xFF;
 35.2578 +				                return true;
 35.2579 +							}
 35.2580 +
 35.2581 +				            for (int i = 0; i < sizeof(s_colorMapping) / sizeof(*s_colorMapping); i++)
 35.2582 +				            {
 35.2583 +				                if (!stricmp(str, s_colorMapping[i].name))
 35.2584 +				                {
 35.2585 +				                    *colour = s_colorMapping[i].value;
 35.2586 +				                    return true;
 35.2587 +								}
 35.2588 +							}
 35.2589 +						}
 35.2590 +
 35.2591 +				        return false;
 35.2592 +					}
 35.2593 +
 35.2594 +				    static inline uint32 gui_getcolour_wrapped(lua_State *L, int offset, bool hasDefaultValue, uint32 defaultColour)
 35.2595 +				    {
 35.2596 +				        switch (lua_type(L, offset))
 35.2597 +				        {
 35.2598 +						case LUA_TSTRING:
 35.2599 +							{
 35.2600 +							    const char *str = lua_tostring(L, offset);
 35.2601 +							    uint32		colour;
 35.2602 +
 35.2603 +							    if (str2colour(&colour, L, str))
 35.2604 +									return colour;
 35.2605 +							    else
 35.2606 +							    {
 35.2607 +							        if (hasDefaultValue)
 35.2608 +										return defaultColour;
 35.2609 +							        else
 35.2610 +										return luaL_error(L, "unknown colour %s", str);
 35.2611 +								}
 35.2612 +							}
 35.2613 +
 35.2614 +						case LUA_TNUMBER:
 35.2615 +							{
 35.2616 +							    uint32 colour = (uint32) lua_tointeger(L, offset);
 35.2617 +							    return colour;
 35.2618 +							}
 35.2619 +
 35.2620 +						case LUA_TTABLE:
 35.2621 +							{
 35.2622 +							    int color = 0xFF;
 35.2623 +							    lua_pushnil(L); // first key
 35.2624 +							    int	 keyIndex	= lua_gettop(L);
 35.2625 +							    int	 valueIndex = keyIndex + 1;
 35.2626 +							    bool first		= true;
 35.2627 +							    while (lua_next(L, offset))
 35.2628 +							    {
 35.2629 +							        bool keyIsString = (lua_type(L, keyIndex) == LUA_TSTRING);
 35.2630 +							        bool keyIsNumber = (lua_type(L, keyIndex) == LUA_TNUMBER);
 35.2631 +							        int	 key		 = keyIsString ? tolower(*lua_tostring(L, keyIndex)) : (keyIsNumber ? lua_tointeger(L, keyIndex) : 0);
 35.2632 +							        int	 value		 = lua_tointeger(L, valueIndex);
 35.2633 +							        if (value < 0) value = 0;
 35.2634 +							        if (value > 255) value = 255;
 35.2635 +							        switch (key)
 35.2636 +							        {
 35.2637 +									case 1:
 35.2638 +									case 'r':
 35.2639 +										color |= value << 24; break;
 35.2640 +									case 2:
 35.2641 +									case 'g':
 35.2642 +										color |= value << 16; break;
 35.2643 +									case 3:
 35.2644 +									case 'b':
 35.2645 +										color |= value << 8; break;
 35.2646 +									case 4:
 35.2647 +									case 'a':
 35.2648 +										color = (color & ~0xFF) | value; break;
 35.2649 +									}
 35.2650 +							        lua_pop(L, 1);
 35.2651 +								}
 35.2652 +							    return color;
 35.2653 +							}   break;
 35.2654 +
 35.2655 +						case LUA_TFUNCTION:
 35.2656 +							luaL_error(L, "invalid colour"); // NYI
 35.2657 +							return 0;
 35.2658 +
 35.2659 +						default:
 35.2660 +							if (hasDefaultValue)
 35.2661 +								return defaultColour;
 35.2662 +							else
 35.2663 +								return luaL_error(L, "invalid colour");
 35.2664 +						}
 35.2665 +					}
 35.2666 +
 35.2667 +				    static uint32 gui_getcolour(lua_State *L, int offset)
 35.2668 +				    {
 35.2669 +				        uint32 colour;
 35.2670 +				        int	   a, r, g, b;
 35.2671 +
 35.2672 +				        colour = gui_getcolour_wrapped(L, offset, false, 0);
 35.2673 +				        a	   = ((colour & 0xff) * transparencyModifier) / 255;
 35.2674 +				        if (a > 255)
 35.2675 +							a = 255;
 35.2676 +				        b = (colour >> 8) & 0xff;
 35.2677 +				        g = (colour >> 16) & 0xff;
 35.2678 +				        r = (colour >> 24) & 0xff;
 35.2679 +				        return LUA_BUILD_PIXEL(a, r, g, b);
 35.2680 +					}
 35.2681 +
 35.2682 +				    static uint32 gui_optcolour(lua_State *L, int offset, uint32 defaultColour)
 35.2683 +				    {
 35.2684 +				        uint32 colour;
 35.2685 +				        int	   a, r, g, b;
 35.2686 +				        uint8  defA, defB, defG, defR;
 35.2687 +
 35.2688 +				        LUA_DECOMPOSE_PIXEL(defaultColour, defA, defR, defG, defB);
 35.2689 +				        defaultColour = (defR << 24) | (defG << 16) | (defB << 8) | defA;
 35.2690 +
 35.2691 +				        colour = gui_getcolour_wrapped(L, offset, true, defaultColour);
 35.2692 +				        a	   = ((colour & 0xff) * transparencyModifier) / 255;
 35.2693 +				        if (a > 255)
 35.2694 +							a = 255;
 35.2695 +				        b = (colour >> 8) & 0xff;
 35.2696 +				        g = (colour >> 16) & 0xff;
 35.2697 +				        r = (colour >> 24) & 0xff;
 35.2698 +				        return LUA_BUILD_PIXEL(a, r, g, b);
 35.2699 +					}
 35.2700 +
 35.2701 +// gui.drawpixel(x,y,colour)
 35.2702 +				    static int gui_drawpixel(lua_State *L)
 35.2703 +				    {
 35.2704 +				        int x = luaL_checkinteger(L, 1);
 35.2705 +				        int y = luaL_checkinteger(L, 2);
 35.2706 +
 35.2707 +				        uint32 colour = gui_getcolour(L, 3);
 35.2708 +
 35.2709 +				        //	if (!gui_check_boundary(x, y))
 35.2710 +				        //		luaL_error(L,"bad coordinates");
 35.2711 +				        gui_prepare();
 35.2712 +
 35.2713 +				        gui_drawpixel_internal(x, y, colour);
 35.2714 +
 35.2715 +				        return 0;
 35.2716 +					}
 35.2717 +
 35.2718 +// gui.drawline(x1,y1,x2,y2,color,skipFirst)
 35.2719 +				    static int gui_drawline(lua_State *L)
 35.2720 +				    {
 35.2721 +				        int	   x1, y1, x2, y2;
 35.2722 +				        uint32 color;
 35.2723 +				        x1	  = luaL_checkinteger(L, 1);
 35.2724 +				        y1	  = luaL_checkinteger(L, 2);
 35.2725 +				        x2	  = luaL_checkinteger(L, 3);
 35.2726 +				        y2	  = luaL_checkinteger(L, 4);
 35.2727 +				        color = gui_optcolour(L, 5, LUA_BUILD_PIXEL(255, 255, 255, 255));
 35.2728 +				        int skipFirst = lua_toboolean(L, 6);
 35.2729 +
 35.2730 +				        gui_prepare();
 35.2731 +
 35.2732 +				        gui_drawline_internal(x2, y2, x1, y1, !skipFirst, color);
 35.2733 +
 35.2734 +				        return 0;
 35.2735 +					}
 35.2736 +
 35.2737 +// gui.drawbox(x1, y1, x2, y2, fillcolor, outlinecolor)
 35.2738 +				    static int gui_drawbox(lua_State *L)
 35.2739 +				    {
 35.2740 +				        int	   x1, y1, x2, y2;
 35.2741 +				        uint32 fillcolor;
 35.2742 +				        uint32 outlinecolor;
 35.2743 +
 35.2744 +				        x1 = luaL_checkinteger(L, 1);
 35.2745 +				        y1 = luaL_checkinteger(L, 2);
 35.2746 +				        x2 = luaL_checkinteger(L, 3);
 35.2747 +				        y2 = luaL_checkinteger(L, 4);
 35.2748 +				        fillcolor	 = gui_optcolour(L, 5, LUA_BUILD_PIXEL(63, 255, 255, 255));
 35.2749 +				        outlinecolor = gui_optcolour(L, 6, LUA_BUILD_PIXEL(255, LUA_PIXEL_R(fillcolor), LUA_PIXEL_G(fillcolor), LUA_PIXEL_B(fillcolor)));
 35.2750 +
 35.2751 +				        if (x1 > x2)
 35.2752 +							std::swap(x1, x2);
 35.2753 +				        if (y1 > y2)
 35.2754 +							std::swap(y1, y2);
 35.2755 +
 35.2756 +				        gui_prepare();
 35.2757 +
 35.2758 +				        gui_drawbox_internal(x1, y1, x2, y2, outlinecolor);
 35.2759 +				        if ((x2 - x1) >= 2 && (y2 - y1) >= 2)
 35.2760 +							gui_fillbox_internal(x1 + 1, y1 + 1, x2 - 1, y2 - 1, fillcolor);
 35.2761 +
 35.2762 +				        return 0;
 35.2763 +					}
 35.2764 +
 35.2765 +// gui.drawcircle(x0, y0, radius, colour)
 35.2766 +				    static int gui_drawcircle(lua_State *L)
 35.2767 +				    {
 35.2768 +				        int	   x, y, r;
 35.2769 +				        uint32 colour;
 35.2770 +
 35.2771 +				        x	   = luaL_checkinteger(L, 1);
 35.2772 +				        y	   = luaL_checkinteger(L, 2);
 35.2773 +				        r	   = luaL_checkinteger(L, 3);
 35.2774 +				        colour = gui_getcolour(L, 4);
 35.2775 +
 35.2776 +				        gui_prepare();
 35.2777 +
 35.2778 +				        gui_drawcircle_internal(x, y, r, colour);
 35.2779 +
 35.2780 +				        return 0;
 35.2781 +					}
 35.2782 +
 35.2783 +// gui.fillbox(x1, y1, x2, y2, colour)
 35.2784 +				    static int gui_fillbox(lua_State *L)
 35.2785 +				    {
 35.2786 +				        int	   x1, y1, x2, y2;
 35.2787 +				        uint32 colour;
 35.2788 +
 35.2789 +				        x1	   = luaL_checkinteger(L, 1);
 35.2790 +				        y1	   = luaL_checkinteger(L, 2);
 35.2791 +				        x2	   = luaL_checkinteger(L, 3);
 35.2792 +				        y2	   = luaL_checkinteger(L, 4);
 35.2793 +				        colour = gui_getcolour(L, 5);
 35.2794 +
 35.2795 +				        //	if (!gui_check_boundary(x1, y1))
 35.2796 +				        //		luaL_error(L,"bad coordinates");
 35.2797 +				        //
 35.2798 +				        //	if (!gui_check_boundary(x2, y2))
 35.2799 +				        //		luaL_error(L,"bad coordinates");
 35.2800 +				        gui_prepare();
 35.2801 +
 35.2802 +				        if (!gui_checkbox(x1, y1, x2, y2))
 35.2803 +							return 0;
 35.2804 +
 35.2805 +				        gui_fillbox_internal(x1, y1, x2, y2, colour);
 35.2806 +
 35.2807 +				        return 0;
 35.2808 +					}
 35.2809 +
 35.2810 +// gui.fillcircle(x0, y0, radius, colour)
 35.2811 +				    static int gui_fillcircle(lua_State *L)
 35.2812 +				    {
 35.2813 +				        int	   x, y, r;
 35.2814 +				        uint32 colour;
 35.2815 +
 35.2816 +				        x	   = luaL_checkinteger(L, 1);
 35.2817 +				        y	   = luaL_checkinteger(L, 2);
 35.2818 +				        r	   = luaL_checkinteger(L, 3);
 35.2819 +				        colour = gui_getcolour(L, 4);
 35.2820 +
 35.2821 +				        gui_prepare();
 35.2822 +
 35.2823 +				        gui_fillcircle_internal(x, y, r, colour);
 35.2824 +
 35.2825 +				        return 0;
 35.2826 +					}
 35.2827 +
 35.2828 +				    static int gui_getpixel(lua_State *L)
 35.2829 +				    {
 35.2830 +				        int x = luaL_checkinteger(L, 1);
 35.2831 +				        int y = luaL_checkinteger(L, 2);
 35.2832 +
 35.2833 +				        int pixWidth   = 240, pixHeight = 160;
 35.2834 +				        int scrWidth   = 240, scrHeight = 160;
 35.2835 +				        int scrOffsetX = 0, scrOffsetY = 0;
 35.2836 +				        int pitch;
 35.2837 +				        if (!systemIsRunningGBA())
 35.2838 +				        {
 35.2839 +				            if (gbBorderOn)
 35.2840 +				            {
 35.2841 +				                pixWidth   = 256, pixHeight = 224;
 35.2842 +				                scrOffsetX = 48, scrOffsetY = 40;
 35.2843 +							}
 35.2844 +				            else
 35.2845 +				            {
 35.2846 +				                pixWidth = 160, pixHeight = 144;
 35.2847 +							}
 35.2848 +				            scrWidth = 160, scrHeight = 144;
 35.2849 +						}
 35.2850 +				        pitch = pixWidth * (systemColorDepth / 8) + (systemColorDepth == 24 ? 0 : 4);
 35.2851 +				        scrOffsetY++; // don't know why it's needed
 35.2852 +
 35.2853 +				        if (!(x >= 0 && y >= 0 && x < scrWidth && y < scrHeight) /*!gui_check_boundary(x,y)*/)
 35.2854 +				        {
 35.2855 +				            lua_pushinteger(L, 0);
 35.2856 +				            lua_pushinteger(L, 0);
 35.2857 +				            lua_pushinteger(L, 0);
 35.2858 +						}
 35.2859 +				        else
 35.2860 +				        {
 35.2861 +				            switch (systemColorDepth)
 35.2862 +				            {
 35.2863 +							case 16:
 35.2864 +								{
 35.2865 +								    uint16 *screen	 = (uint16 *) (&pix[scrOffsetY * pitch + scrOffsetX * 2]);
 35.2866 +								    uint16	pixColor = screen[y * pitch / 2 + x];
 35.2867 +								    lua_pushinteger(L, (pixColor >> 8) & 0xF8); // red
 35.2868 +								    lua_pushinteger(L, (pixColor >> 3) & 0xFC); // green
 35.2869 +								    lua_pushinteger(L, (pixColor << 3) & 0xF8); // blue
 35.2870 +								}
 35.2871 +								break;
 35.2872 +							case 24:
 35.2873 +								{
 35.2874 +								    uint8 *screen = &pix[scrOffsetY * pitch + scrOffsetX * 3];
 35.2875 +								    lua_pushinteger(L, screen[y * pitch + x * 3 + 2]); // red
 35.2876 +								    lua_pushinteger(L, screen[y * pitch + x * 3 + 1]); // green
 35.2877 +								    lua_pushinteger(L, screen[y * pitch + x * 3 + 0]); // blue
 35.2878 +								}
 35.2879 +								break;
 35.2880 +							case 32:
 35.2881 +								{
 35.2882 +								    uint8 *screen = &pix[scrOffsetY * pitch + scrOffsetX * 4];
 35.2883 +								    lua_pushinteger(L, screen[y * pitch + x * 4 + 2]); // red
 35.2884 +								    lua_pushinteger(L, screen[y * pitch + x * 4 + 1]); // green
 35.2885 +								    lua_pushinteger(L, screen[y * pitch + x * 4 + 0]); // blue
 35.2886 +								}
 35.2887 +								break;
 35.2888 +							default:
 35.2889 +								lua_pushinteger(L, 0);
 35.2890 +								lua_pushinteger(L, 0);
 35.2891 +								lua_pushinteger(L, 0);
 35.2892 +								break;
 35.2893 +							}
 35.2894 +						}
 35.2895 +				        return 3;
 35.2896 +					}
 35.2897 +
 35.2898 +				    static int gui_parsecolor(lua_State *L)
 35.2899 +				    {
 35.2900 +				        int	   r, g, b, a;
 35.2901 +				        uint32 color = gui_getcolour(L, 1);
 35.2902 +				        LUA_DECOMPOSE_PIXEL(color, a, r, g, b);
 35.2903 +				        lua_pushinteger(L, r);
 35.2904 +				        lua_pushinteger(L, g);
 35.2905 +				        lua_pushinteger(L, b);
 35.2906 +				        lua_pushinteger(L, a);
 35.2907 +				        return 4;
 35.2908 +					}
 35.2909 +
 35.2910 +// gui.gdscreenshot()
 35.2911 +//
 35.2912 +//  Returns a screen shot as a string in gd's v1 file format.
 35.2913 +//  This allows us to make screen shots available without gd installed locally.
 35.2914 +//  Users can also just grab pixels via substring selection.
 35.2915 +//
 35.2916 +//  I think...  Does lua support grabbing byte values from a string? // yes, string.byte(str,offset)
 35.2917 +//  Well, either way, just install gd and do what you like with it.
 35.2918 +//  It really is easier that way.
 35.2919 +
 35.2920 +// example: gd.createFromGdStr(gui.gdscreenshot()):png("outputimage.png")
 35.2921 +				    static int gui_gdscreenshot(lua_State *L)
 35.2922 +				    {
 35.2923 +				        int xofs = 0, yofs = 0, ppl = 240, width = 240, height = 160;
 35.2924 +				        if (!systemIsRunningGBA())
 35.2925 +				        {
 35.2926 +				            if (gbBorderOn)
 35.2927 +								xofs = 48, yofs = 40, ppl = 256;
 35.2928 +				            else
 35.2929 +								ppl = 160;
 35.2930 +				            width = 160, height = 144;
 35.2931 +						}
 35.2932 +
 35.2933 +				        yofs++;
 35.2934 +
 35.2935 +				        //int pitch = (((ppl * systemColorDepth + 7)>>3)+3)&~3;
 35.2936 +				        int	   pitch  = ppl * (systemColorDepth / 8) + (systemColorDepth == 24 ? 0 : 4);
 35.2937 +				        uint8 *screen = &pix[yofs * pitch + xofs * (systemColorDepth / 8)];
 35.2938 +
 35.2939 +				        int	  size = 11 + width * height * 4;
 35.2940 +				        char *str  = new char[size + 1];
 35.2941 +				        str[size] = 0;
 35.2942 +
 35.2943 +				        unsigned char *ptr = (unsigned char *)str;
 35.2944 +
 35.2945 +				        // GD format header for truecolor image (11 bytes)
 35.2946 +				        *ptr++ = (65534 >> 8) & 0xFF;
 35.2947 +				        *ptr++ = (65534) & 0xFF;
 35.2948 +				        *ptr++ = (width >> 8) & 0xFF;
 35.2949 +				        *ptr++ = (width) & 0xFF;
 35.2950 +				        *ptr++ = (height >> 8) & 0xFF;
 35.2951 +				        *ptr++ = (height) & 0xFF;
 35.2952 +				        *ptr++ = 1;
 35.2953 +				        *ptr++ = 255;
 35.2954 +				        *ptr++ = 255;
 35.2955 +				        *ptr++ = 255;
 35.2956 +				        *ptr++ = 255;
 35.2957 +
 35.2958 +				        GetColorFunc getColor;
 35.2959 +				        getColorIOFunc(systemColorDepth, &getColor, NULL);
 35.2960 +
 35.2961 +				        int x, y;
 35.2962 +				        for (y = 0; y < height; y++)
 35.2963 +				        {
 35.2964 +				            uint8 *s = &screen[y * pitch];
 35.2965 +				            for (x = 0; x < width; x++, s += systemColorDepth / 8)
 35.2966 +				            {
 35.2967 +				                uint8 r, g, b;
 35.2968 +				                getColor(s, &r, &g, &b);
 35.2969 +
 35.2970 +				                *ptr++ = 0;
 35.2971 +				                *ptr++ = r;
 35.2972 +				                *ptr++ = g;
 35.2973 +				                *ptr++ = b;
 35.2974 +							}
 35.2975 +						}
 35.2976 +
 35.2977 +				        lua_pushlstring(L, str, size);
 35.2978 +				        delete[] str;
 35.2979 +				        return 1;
 35.2980 +					}
 35.2981 +
 35.2982 +// gui.opacity(number alphaValue)
 35.2983 +// sets the transparency of subsequent draw calls
 35.2984 +// 0.0 is completely transparent, 1.0 is completely opaque
 35.2985 +// non-integer values are supported and meaningful, as are values greater than 1.0
 35.2986 +// it is not necessary to use this function to get transparency (or the less-recommended gui.transparency() either),
 35.2987 +// because you can provide an alpha value in the color argument of each draw call.
 35.2988 +
 35.2989 +// however, it can be convenient to be able to globally modify the drawing transparency
 35.2990 +				    static int gui_setopacity(lua_State *L)
 35.2991 +				    {
 35.2992 +				        double opacF = luaL_checknumber(L, 1);
 35.2993 +				        transparencyModifier = (int)(opacF * 255);
 35.2994 +				        if (transparencyModifier < 0)
 35.2995 +							transparencyModifier = 0;
 35.2996 +				        return 0;
 35.2997 +					}
 35.2998 +
 35.2999 +// gui.transparency(int strength)
 35.3000 +//
 35.3001 +
 35.3002 +//  0 = solid,
 35.3003 +				    static int gui_transparency(lua_State *L)
 35.3004 +				    {
 35.3005 +				        double trans = luaL_checknumber(L, 1);
 35.3006 +				        transparencyModifier = (int)((4.0 - trans) / 4.0 * 255);
 35.3007 +				        if (transparencyModifier < 0)
 35.3008 +							transparencyModifier = 0;
 35.3009 +				        return 0;
 35.3010 +					}
 35.3011 +
 35.3012 +				    static const uint32 Small_Font_Data[] =
 35.3013 +				    {
 35.3014 +				        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 32
 35.3015 +				        0x00000000, 0x00000300, 0x00000400, 0x00000500, 0x00000000, 0x00000700, 0x00000000, // 33	!
 35.3016 +				        0x00000000, 0x00040002, 0x00050003, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 34	"
 35.3017 +				        0x00000000, 0x00040002, 0x00050403, 0x00060004, 0x00070605, 0x00080006, 0x00000000, // 35	#
 35.3018 +				        0x00000000, 0x00040300, 0x00000403, 0x00000500, 0x00070600, 0x00000706, 0x00000000, // 36	$
 35.3019 +				        0x00000000, 0x00000002, 0x00050000, 0x00000500, 0x00000005, 0x00080000, 0x00000000, // 37	%
 35.3020 +				        0x00000000, 0x00000300, 0x00050003, 0x00000500, 0x00070005, 0x00080700, 0x00000000, // 38	&
 35.3021 +				        0x00000000, 0x00000300, 0x00000400, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 39	'
 35.3022 +				        0x00000000, 0x00000300, 0x00000003, 0x00000004, 0x00000005, 0x00000700, 0x00000000, // 40	(
 35.3023 +				        0x00000000, 0x00000300, 0x00050000, 0x00060000, 0x00070000, 0x00000700, 0x00000000, // 41	)
 35.3024 +				        0x00000000, 0x00000000, 0x00000400, 0x00060504, 0x00000600, 0x00080006, 0x00000000, // 42	*
 35.3025 +				        0x00000000, 0x00000000, 0x00000400, 0x00060504, 0x00000600, 0x00000000, 0x00000000, // 43	+
 35.3026 +				        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000600, 0x00000700, 0x00000007, // 44	,
 35.3027 +				        0x00000000, 0x00000000, 0x00000000, 0x00060504, 0x00000000, 0x00000000, 0x00000000, // 45	-
 35.3028 +				        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000700, 0x00000000, // 46	.
 35.3029 +				        0x00030000, 0x00040000, 0x00000400, 0x00000500, 0x00000005, 0x00000006, 0x00000000, // 47	/
 35.3030 +				        0x00000000, 0x00000300, 0x00050003, 0x00060004, 0x00070005, 0x00000700, 0x00000000, // 48	0
 35.3031 +				        0x00000000, 0x00000300, 0x00000403, 0x00000500, 0x00000600, 0x00000700, 0x00000000, // 49	1
 35.3032 +				        0x00000000, 0x00000302, 0x00050000, 0x00000500, 0x00000005, 0x00080706, 0x00000000, // 50	2
 35.3033 +				        0x00000000, 0x00000302, 0x00050000, 0x00000504, 0x00070000, 0x00000706, 0x00000000, // 51	3
 35.3034 +				        0x00000000, 0x00000300, 0x00000003, 0x00060004, 0x00070605, 0x00080000, 0x00000000, // 52	4
 35.3035 +				        0x00000000, 0x00040302, 0x00000003, 0x00000504, 0x00070000, 0x00000706, 0x00000000, // 53	5
 35.3036 +				        0x00000000, 0x00000300, 0x00000003, 0x00000504, 0x00070005, 0x00000700, 0x00000000, // 54	6
 35.3037 +				        0x00000000, 0x00040302, 0x00050000, 0x00000500, 0x00000600, 0x00000700, 0x00000000, // 55	7
 35.3038 +				        0x00000000, 0x00000300, 0x00050003, 0x00000500, 0x00070005, 0x00000700, 0x00000000, // 56	8
 35.3039 +				        0x00000000, 0x00000300, 0x00050003, 0x00060500, 0x00070000, 0x00000700, 0x00000000, // 57	9
 35.3040 +				        0x00000000, 0x00000000, 0x00000400, 0x00000000, 0x00000000, 0x00000700, 0x00000000, // 58	:
 35.3041 +				        0x00000000, 0x00000000, 0x00000000, 0x00000500, 0x00000000, 0x00000700, 0x00000007, // 59	;
 35.3042 +				        0x00000000, 0x00040000, 0x00000400, 0x00000004, 0x00000600, 0x00080000, 0x00000000, // 60	<
 35.3043 +				        0x00000000, 0x00000000, 0x00050403, 0x00000000, 0x00070605, 0x00000000, 0x00000000, // 61	=
 35.3044 +				        0x00000000, 0x00000002, 0x00000400, 0x00060000, 0x00000600, 0x00000006, 0x00000000, // 62	>
 35.3045 +				        0x00000000, 0x00000302, 0x00050000, 0x00000500, 0x00000000, 0x00000700, 0x00000000, // 63	?
 35.3046 +				        0x00000000, 0x00000300, 0x00050400, 0x00060004, 0x00070600, 0x00000000, 0x00000000, // 64	@
 35.3047 +				        0x00000000, 0x00000300, 0x00050003, 0x00060504, 0x00070005, 0x00080006, 0x00000000, // 65	A
 35.3048 +				        0x00000000, 0x00000302, 0x00050003, 0x00000504, 0x00070005, 0x00000706, 0x00000000, // 66	B
 35.3049 +				        0x00000000, 0x00040300, 0x00000003, 0x00000004, 0x00000005, 0x00080700, 0x00000000, // 67	C
 35.3050 +				        0x00000000, 0x00000302, 0x00050003, 0x00060004, 0x00070005, 0x00000706, 0x00000000, // 68	D
 35.3051 +				        0x00000000, 0x00040302, 0x00000003, 0x00000504, 0x00000005, 0x00080706, 0x00000000, // 69	E
 35.3052 +				        0x00000000, 0x00040302, 0x00000003, 0x00000504, 0x00000005, 0x00000006, 0x00000000, // 70	F
 35.3053 +				        0x00000000, 0x00040300, 0x00000003, 0x00060004, 0x00070005, 0x00080700, 0x00000000, // 71	G
 35.3054 +				        0x00000000, 0x00040002, 0x00050003, 0x00060504, 0x00070005, 0x00080006, 0x00000000, // 72	H
 35.3055 +				        0x00000000, 0x00000300, 0x00000400, 0x00000500, 0x00000600, 0x00000700, 0x00000000, // 73	I
 35.3056 +				        0x00000000, 0x00040000, 0x00050000, 0x00060000, 0x00070005, 0x00000700, 0x00000000, // 74	J
 35.3057 +				        0x00000000, 0x00040002, 0x00050003, 0x00000504, 0x00070005, 0x00080006, 0x00000000, // 75	K
 35.3058 +				        0x00000000, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00080706, 0x00000000, // 76	l
 35.3059 +				        0x00000000, 0x00040002, 0x00050403, 0x00060004, 0x00070005, 0x00080006, 0x00000000, // 77	M
 35.3060 +				        0x00000000, 0x00000302, 0x00050003, 0x00060004, 0x00070005, 0x00080006, 0x00000000, // 78	N
 35.3061 +				        0x00000000, 0x00040302, 0x00050003, 0x00060004, 0x00070005, 0x00080706, 0x00000000, // 79	O
 35.3062 +				        0x00000000, 0x00000302, 0x00050003, 0x00000504, 0x00000005, 0x00000006, 0x00000000, // 80	P
 35.3063 +				        0x00000000, 0x00040302, 0x00050003, 0x00060004, 0x00070005, 0x00080706, 0x00090000, // 81	Q
 35.3064 +				        0x00000000, 0x00000302, 0x00050003, 0x00000504, 0x00070005, 0x00080006, 0x00000000, // 82	R
 35.3065 +				        0x00000000, 0x00040300, 0x00000003, 0x00000500, 0x00070000, 0x00000706, 0x00000000, // 83	S
 35.3066 +				        0x00000000, 0x00040302, 0x00000400, 0x00000500, 0x00000600, 0x00000700, 0x00000000, // 84	T
 35.3067 +				        0x00000000, 0x00040002, 0x00050003, 0x00060004, 0x00070005, 0x00080706, 0x00000000, // 85	U
 35.3068 +				        0x00000000, 0x00040002, 0x00050003, 0x00060004, 0x00000600, 0x00000700, 0x00000000, // 86	V
 35.3069 +				        0x00000000, 0x00040002, 0x00050003, 0x00060004, 0x00070605, 0x00080006, 0x00000000, // 87	W
 35.3070 +				        0x00000000, 0x00040002, 0x00050003, 0x00000500, 0x00070005, 0x00080006, 0x00000000, // 88	X
 35.3071 +				        0x00000000, 0x00040002, 0x00050003, 0x00000500, 0x00000600, 0x00000700, 0x00000000, // 89	Y
 35.3072 +				        0x00000000, 0x00040302, 0x00050000, 0x00000500, 0x00000005, 0x00080706, 0x00000000, // 90	Z
 35.3073 +				        0x00000000, 0x00040300, 0x00000400, 0x00000500, 0x00000600, 0x00080700, 0x00000000, // 91	[
 35.3074 +				        0x00000000, 0x00000002, 0x00000400, 0x00000500, 0x00070000, 0x00080000, 0x00000000, // 92	'\'
 35.3075 +				        0x00000000, 0x00000302, 0x00000400, 0x00000500, 0x00000600, 0x00000706, 0x00000000, // 93	]
 35.3076 +				        0x00000000, 0x00000300, 0x00050003, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 94	^
 35.3077 +				        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00080706, 0x00000000, // 95	_
 35.3078 +				        0x00000000, 0x00000002, 0x00000400, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 96	`
 35.3079 +				        0x00000000, 0x00000000, 0x00050400, 0x00060004, 0x00070005, 0x00080700, 0x00000000, // 97	a
 35.3080 +				        0x00000000, 0x00000002, 0x00000003, 0x00000504, 0x00070005, 0x00000706, 0x00000000, // 98	b
 35.3081 +				        0x00000000, 0x00000000, 0x00050400, 0x00000004, 0x00000005, 0x00080700, 0x00000000, // 99	c
 35.3082 +				        0x00000000, 0x00040000, 0x00050000, 0x00060500, 0x00070005, 0x00080700, 0x00000000, // 100	d
 35.3083 +				        0x00000000, 0x00000000, 0x00050400, 0x00060504, 0x00000005, 0x00080700, 0x00000000, // 101	e
 35.3084 +				        0x00000000, 0x00040300, 0x00000003, 0x00000504, 0x00000005, 0x00000006, 0x00000000, // 102	f
 35.3085 +				        0x00000000, 0x00000000, 0x00050400, 0x00060004, 0x00070600, 0x00080000, 0x00000807, // 103	g
 35.3086 +				        0x00000000, 0x00000002, 0x00000003, 0x00000504, 0x00070005, 0x00080006, 0x00000000, // 104	h
 35.3087 +				        0x00000000, 0x00000300, 0x00000000, 0x00000500, 0x00000600, 0x00000700, 0x00000000, // 105	i
 35.3088 +				        0x00000000, 0x00000300, 0x00000000, 0x00000500, 0x00000600, 0x00000700, 0x00000007, // 106	j
 35.3089 +				        0x00000000, 0x00000002, 0x00000003, 0x00060004, 0x00000605, 0x00080006, 0x00000000, // 107	k
 35.3090 +				        0x00000000, 0x00000300, 0x00000400, 0x00000500, 0x00000600, 0x00080000, 0x00000000, // 108	l
 35.3091 +				        0x00000000, 0x00000000, 0x00050003, 0x00060504, 0x00070005, 0x00080006, 0x00000000, // 109	m
 35.3092 +				        0x00000000, 0x00000000, 0x00000403, 0x00060004, 0x00070005, 0x00080006, 0x00000000, // 110	n
 35.3093 +				        0x00000000, 0x00000000, 0x00000400, 0x00060004, 0x00070005, 0x00000700, 0x00000000, // 111	o
 35.3094 +				        0x00000000, 0x00000000, 0x00000400, 0x00060004, 0x00000605, 0x00000006, 0x00000007, // 112	p
 35.3095 +				        0x00000000, 0x00000000, 0x00000400, 0x00060004, 0x00070600, 0x00080000, 0x00090000, // 113	q
 35.3096 +				        0x00000000, 0x00000000, 0x00050003, 0x00000504, 0x00000005, 0x00000006, 0x00000000, // 114	r
 35.3097 +				        0x00000000, 0x00000000, 0x00050400, 0x00000004, 0x00070600, 0x00000706, 0x00000000, // 115	s
 35.3098 +				        0x00000000, 0x00000300, 0x00050403, 0x00000500, 0x00000600, 0x00080000, 0x00000000, // 116	t
 35.3099 +				        0x00000000, 0x00000000, 0x00050003, 0x00060004, 0x00070005, 0x00080700, 0x00000000, // 117	u
 35.3100 +				        0x00000000, 0x00000000, 0x00050003, 0x00060004, 0x00070005, 0x00000700, 0x00000000, // 118	v
 35.3101 +				        0x00000000, 0x00000000, 0x00050003, 0x00060004, 0x00070605, 0x00080006, 0x00000000, // 119	w
 35.3102 +				        0x00000000, 0x00000000, 0x00050003, 0x00000500, 0x00070005, 0x00080006, 0x00000000, // 120	x
 35.3103 +				        0x00000000, 0x00000000, 0x00050003, 0x00060004, 0x00000600, 0x00000700, 0x00000007, // 121	y
 35.3104 +				        0x00000000, 0x00000000, 0x00050403, 0x00000500, 0x00000005, 0x00080706, 0x00000000, // 122	z
 35.3105 +				        0x00000000, 0x00040300, 0x00000400, 0x00000504, 0x00000600, 0x00080700, 0x00000000, // 123	{
 35.3106 +				        0x00000000, 0x00000300, 0x00000400, 0x00000000, 0x00000600, 0x00000700, 0x00000000, // 124	|
 35.3107 +				        0x00000000, 0x00000302, 0x00000400, 0x00060500, 0x00000600, 0x00000706, 0x00000000, // 125	}
 35.3108 +				        0x00000000, 0x00000302, 0x00050000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 126	~
 35.3109 +				        0x00000000, 0x00000000, 0x00000400, 0x00060004, 0x00070605, 0x00000000, 0x00000000, // 127	
 35.3110 +				        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
 35.3111 +					};
 35.3112 +
 35.3113 +				    static void PutTextInternal(const char *str, int len, short x, short y, int color, int backcolor)
 35.3114 +				    {
 35.3115 +				        int Opac	 = (color >> 24) & 0xFF;
 35.3116 +				        int backOpac = (backcolor >> 24) & 0xFF;
 35.3117 +				        int origX	 = x;
 35.3118 +
 35.3119 +				        if (!Opac && !backOpac)
 35.3120 +							return;
 35.3121 +
 35.3122 +				        while (*str && len && y < LUA_SCREEN_HEIGHT)
 35.3123 +				        {
 35.3124 +				            int c = *str++;
 35.3125 +				            while (x > LUA_SCREEN_WIDTH && c != '\n')
 35.3126 +				            {
 35.3127 +				                c = *str;
 35.3128 +				                if (c == '\0')
 35.3129 +									break;
 35.3130 +				                str++;
 35.3131 +							}
 35.3132 +
 35.3133 +				            if (c == '\n')
 35.3134 +				            {
 35.3135 +				                x  = origX;
 35.3136 +				                y += 8;
 35.3137 +				                continue;
 35.3138 +							}
 35.3139 +				            else if (c == '\t') // just in case
 35.3140 +				            {
 35.3141 +				                const int tabSpace = 8;
 35.3142 +				                x += (tabSpace - (((x - origX) / 4) % tabSpace)) * 4;
 35.3143 +				                continue;
 35.3144 +							}
 35.3145 +
 35.3146 +				            if ((unsigned int)(c - 32) >= 96)
 35.3147 +								continue;
 35.3148 +
 35.3149 +				            const unsigned char *Cur_Glyph = (const unsigned char *) &Small_Font_Data + (c - 32) * 7 * 4;
 35.3150 +
 35.3151 +				            for (int y2 = 0; y2 < 8; y2++)
 35.3152 +				            {
 35.3153 +				                unsigned int glyphLine = *((unsigned int *)Cur_Glyph + y2);
 35.3154 +				                for (int x2 = -1; x2 < 4; x2++)
 35.3155 +				                {
 35.3156 +				                    int shift	  = x2 << 3;
 35.3157 +				                    int mask	  = 0xFF << shift;
 35.3158 +				                    int intensity = (glyphLine & mask) >> shift;
 35.3159 +
 35.3160 +				                    if (intensity && x2 >= 0 && y2 < 7)
 35.3161 +				                    {
 35.3162 +				                        //int xdraw = max(0,min(LUA_SCREEN_WIDTH - 1,x+x2));
 35.3163 +				                        //int ydraw = max(0,min(LUA_SCREEN_HEIGHT - 1,y+y2));
 35.3164 +				                        //gui_drawpixel_fast(xdraw, ydraw, color);
 35.3165 +				                        gui_drawpixel_internal(x + x2, y + y2, color);
 35.3166 +									}
 35.3167 +				                    else if (backOpac)
 35.3168 +				                    {
 35.3169 +				                        for (int y3 = max(0, y2 - 1); y3 <= min(6, y2 + 1); y3++)
 35.3170 +				                        {
 35.3171 +				                            unsigned int glyphLine = *((unsigned int *)Cur_Glyph + y3);
 35.3172 +				                            for (int x3 = max(0, x2 - 1); x3 <= min(3, x2 + 1); x3++)
 35.3173 +				                            {
 35.3174 +				                                int shift = x3 << 3;
 35.3175 +				                                int mask  = 0xFF << shift;
 35.3176 +				                                intensity |= (glyphLine & mask) >> shift;
 35.3177 +				                                if (intensity)
 35.3178 +													goto draw_outline;  // speedup?
 35.3179 +											}
 35.3180 +										}
 35.3181 +
 35.3182 +draw_outline:
 35.3183 +				                        if (intensity)
 35.3184 +				                        {
 35.3185 +				                            //int xdraw = max(0,min(LUA_SCREEN_WIDTH - 1,x+x2));
 35.3186 +				                            //int ydraw = max(0,min(LUA_SCREEN_HEIGHT - 1,y+y2));
 35.3187 +				                            //gui_drawpixel_fast(xdraw, ydraw, backcolor);
 35.3188 +				                            gui_drawpixel_internal(x + x2, y + y2, backcolor);
 35.3189 +										}
 35.3190 +									}
 35.3191 +								}
 35.3192 +							}
 35.3193 +
 35.3194 +				            x += 4;
 35.3195 +				            len--;
 35.3196 +						}
 35.3197 +					}
 35.3198 +
 35.3199 +				    static int strlinelen(const char *string)
 35.3200 +				    {
 35.3201 +				        const char *s = string;
 35.3202 +				        while (*s && *s != '\n')
 35.3203 +							s++;
 35.3204 +				        if (*s)
 35.3205 +							s++;
 35.3206 +				        return s - string;
 35.3207 +					}
 35.3208 +
 35.3209 +				    static void LuaDisplayString(const char *string, int y, int x, uint32 color, uint32 outlineColor)
 35.3210 +				    {
 35.3211 +				        if (!string)
 35.3212 +							return;
 35.3213 +
 35.3214 +				        gui_prepare();
 35.3215 +
 35.3216 +				        PutTextInternal(string, strlen(string), x, y, color, outlineColor);
 35.3217 +
 35.3218 +				        /*
 35.3219 +				           const char* ptr = string;
 35.3220 +				           while(*ptr && y < LUA_SCREEN_HEIGHT)
 35.3221 +				           {
 35.3222 +				            int len = strlinelen(ptr);
 35.3223 +				            int skip = 0;
 35.3224 +				            if(len < 1) len = 1;
 35.3225 +
 35.3226 +				            // break up the line if it's too long to display otherwise
 35.3227 +				            if(len > 63)
 35.3228 +				            {
 35.3229 +				                len = 63;
 35.3230 +				                const char* ptr2 = ptr + len-1;
 35.3231 +				                for(int j = len-1; j; j--, ptr2--)
 35.3232 +				                {
 35.3233 +				                    if(*ptr2 == ' ' || *ptr2 == '\t')
 35.3234 +				                    {
 35.3235 +				                        len = j;
 35.3236 +				                        skip = 1;
 35.3237 +				                        break;
 35.3238 +				                    }
 35.3239 +				                }
 35.3240 +				            }
 35.3241 +
 35.3242 +				            int xl = 0;
 35.3243 +				            int yl = 0;
 35.3244 +				            int xh = (LUA_SCREEN_WIDTH - 1 - 1) - 4*len;
 35.3245 +				            int yh = LUA_SCREEN_HEIGHT - 1;
 35.3246 +				            int x2 = min(max(x,xl),xh);
 35.3247 +				            int y2 = min(max(y,yl),yh);
 35.3248 +
 35.3249 +				            PutTextInternal(ptr,len,x2,y2,color,outlineColor);
 35.3250 +
 35.3251 +				            ptr += len + skip;
 35.3252 +				            y += 8;
 35.3253 +				           }
 35.3254 +				         */
 35.3255 +					}
 35.3256 +
 35.3257 +// gui.text(int x, int y, string msg)
 35.3258 +//
 35.3259 +//  Displays the given text on the screen, using the same font and techniques as the
 35.3260 +
 35.3261 +//  main HUD.
 35.3262 +				    static int gui_text(lua_State *L)
 35.3263 +				    {
 35.3264 +				        //extern int font_height;
 35.3265 +				        const char *msg;
 35.3266 +				        int			x, y;
 35.3267 +				        uint32		colour, borderColour;
 35.3268 +
 35.3269 +				        x = luaL_checkinteger(L, 1);
 35.3270 +				        y = luaL_checkinteger(L, 2);
 35.3271 +				        //msg = luaL_checkstring(L, 3);
 35.3272 +				        msg = toCString(L, 3);
 35.3273 +
 35.3274 +				        //	if (x < 0 || x >= LUA_SCREEN_WIDTH || y < 0 || y >= (LUA_SCREEN_HEIGHT - font_height))
 35.3275 +				        //		luaL_error(L,"bad coordinates");
 35.3276 +				        colour		 = gui_optcolour(L, 4, LUA_BUILD_PIXEL(255, 255, 255, 255));
 35.3277 +				        borderColour = gui_optcolour(L, 5, LUA_BUILD_PIXEL(255, 0, 0, 0));
 35.3278 +
 35.3279 +				        gui_prepare();
 35.3280 +
 35.3281 +				        LuaDisplayString(msg, y, x, colour, borderColour);
 35.3282 +
 35.3283 +				        return 0;
 35.3284 +					}
 35.3285 +
 35.3286 +// gui.gdoverlay([int dx=0, int dy=0,] string str [, sx=0, sy=0, sw, sh] [, float alphamul=1.0])
 35.3287 +//
 35.3288 +//  Overlays the given image on the screen.
 35.3289 +
 35.3290 +// example: gui.gdoverlay(gd.createFromPng("myimage.png"):gdStr())
 35.3291 +				    static int gui_gdoverlay(lua_State *L)
 35.3292 +				    {
 35.3293 +				        int argCount = lua_gettop(L);
 35.3294 +
 35.3295 +				        int xStartDst = 0;
 35.3296 +				        int yStartDst = 0;
 35.3297 +				        int xStartSrc = 0;
 35.3298 +				        int yStartSrc = 0;
 35.3299 +
 35.3300 +				        int index = 1;
 35.3301 +				        if (lua_type(L, index) == LUA_TNUMBER)
 35.3302 +				        {
 35.3303 +				            xStartDst = lua_tointeger(L, index++);
 35.3304 +				            if (lua_type(L, index) == LUA_TNUMBER)
 35.3305 +								yStartDst = lua_tointeger(L, index++);
 35.3306 +						}
 35.3307 +
 35.3308 +				        luaL_checktype(L, index, LUA_TSTRING);
 35.3309 +
 35.3310 +				        const unsigned char *ptr = (const unsigned char *)lua_tostring(L, index++);
 35.3311 +
 35.3312 +				        if (ptr[0] != 255 || (ptr[1] != 254 && ptr[1] != 255))
 35.3313 +							luaL_error(L, "bad image data");
 35.3314 +
 35.3315 +				        bool trueColor = (ptr[1] == 254);
 35.3316 +				        ptr += 2;
 35.3317 +
 35.3318 +				        int imgwidth = *ptr++ << 8;
 35.3319 +				        imgwidth |= *ptr++;
 35.3320 +
 35.3321 +				        int width	  = imgwidth;
 35.3322 +				        int imgheight = *ptr++ << 8;
 35.3323 +				        imgheight |= *ptr++;
 35.3324 +
 35.3325 +				        int height = imgheight;
 35.3326 +				        if ((!trueColor && *ptr) || (trueColor && !*ptr))
 35.3327 +							luaL_error(L, "bad image data");
 35.3328 +				        ptr++;
 35.3329 +
 35.3330 +				        int pitch = imgwidth * (trueColor ? 4 : 1);
 35.3331 +
 35.3332 +				        if ((argCount - index + 1) >= 4)
 35.3333 +				        {
 35.3334 +				            xStartSrc = luaL_checkinteger(L, index++);
 35.3335 +				            yStartSrc = luaL_checkinteger(L, index++);
 35.3336 +				            width	  = luaL_checkinteger(L, index++);
 35.3337 +				            height	  = luaL_checkinteger(L, index++);
 35.3338 +						}
 35.3339 +
 35.3340 +				        int alphaMul = transparencyModifier;
 35.3341 +				        if (lua_isnumber(L, index))
 35.3342 +							alphaMul = (int)(alphaMul * lua_tonumber(L, index++));
 35.3343 +				        if (alphaMul <= 0)
 35.3344 +							return 0;
 35.3345 +
 35.3346 +				        // since there aren't that many possible opacity levels,
 35.3347 +				        // do the opacity modification calculations beforehand instead of per pixel
 35.3348 +				        int opacMap[256];
 35.3349 +				        for (int i = 0; i < 128; i++)
 35.3350 +				        {
 35.3351 +				            int opac = 255 - ((i << 1) | (i & 1)); // gdAlphaMax = 127, not 255
 35.3352 +				            opac = (opac * alphaMul) / 255;
 35.3353 +				            if (opac < 0)
 35.3354 +								opac = 0;
 35.3355 +				            if (opac > 255)
 35.3356 +								opac = 255;
 35.3357 +				            opacMap[i] = opac;
 35.3358 +						}
 35.3359 +
 35.3360 +				        for (int i = 128; i < 256; i++)
 35.3361 +							opacMap[i] = 0;  // what should we do for them, actually?
 35.3362 +				        int colorsTotal = 0;
 35.3363 +				        if (!trueColor)
 35.3364 +				        {
 35.3365 +				            colorsTotal	 = *ptr++ << 8;
 35.3366 +				            colorsTotal |= *ptr++;
 35.3367 +						}
 35.3368 +
 35.3369 +				        int transparent = *ptr++ << 24;
 35.3370 +				        transparent |= *ptr++ << 16;
 35.3371 +				        transparent |= *ptr++ << 8;
 35.3372 +				        transparent |= *ptr++;
 35.3373 +				        struct
 35.3374 +				        {
 35.3375 +				            uint8 r, g, b, a;
 35.3376 +						} pal[256];
 35.3377 +				        if (!trueColor)
 35.3378 +							for (int i = 0; i < 256; i++)
 35.3379 +							{
 35.3380 +							    pal[i].r = *ptr++;
 35.3381 +							    pal[i].g = *ptr++;
 35.3382 +							    pal[i].b = *ptr++;
 35.3383 +							    pal[i].a = opacMap[*ptr++];
 35.3384 +							}
 35.3385 +
 35.3386 +				        // some of clippings
 35.3387 +				        if (xStartSrc < 0)
 35.3388 +				        {
 35.3389 +				            width	  += xStartSrc;
 35.3390 +				            xStartDst -= xStartSrc;
 35.3391 +				            xStartSrc  = 0;
 35.3392 +						}
 35.3393 +
 35.3394 +				        if (yStartSrc < 0)
 35.3395 +				        {
 35.3396 +				            height	  += yStartSrc;
 35.3397 +				            yStartDst -= yStartSrc;
 35.3398 +				            yStartSrc  = 0;
 35.3399 +						}
 35.3400 +
 35.3401 +				        if (xStartSrc + width >= imgwidth)
 35.3402 +							width = imgwidth - xStartSrc;
 35.3403 +				        if (yStartSrc + height >= imgheight)
 35.3404 +							height = imgheight - yStartSrc;
 35.3405 +				        if (xStartDst < 0)
 35.3406 +				        {
 35.3407 +				            width += xStartDst;
 35.3408 +				            if (width <= 0)
 35.3409 +								return 0;
 35.3410 +				            xStartSrc = -xStartDst;
 35.3411 +				            xStartDst = 0;
 35.3412 +						}
 35.3413 +
 35.3414 +				        if (yStartDst < 0)
 35.3415 +				        {
 35.3416 +				            height += yStartDst;
 35.3417 +				            if (height <= 0)
 35.3418 +								return 0;
 35.3419 +				            yStartSrc = -yStartDst;
 35.3420 +				            yStartDst = 0;
 35.3421 +						}
 35.3422 +
 35.3423 +				        if (xStartDst + width >= LUA_SCREEN_WIDTH)
 35.3424 +							width = LUA_SCREEN_WIDTH - xStartDst;
 35.3425 +				        if (yStartDst + height >= LUA_SCREEN_HEIGHT)
 35.3426 +							height = LUA_SCREEN_HEIGHT - yStartDst;
 35.3427 +				        if (width <= 0 || height <= 0)
 35.3428 +							return 0;  // out of screen or invalid size
 35.3429 +				        gui_prepare();
 35.3430 +
 35.3431 +				        const uint8 *pix = (const uint8 *)(&ptr[yStartSrc * pitch + (xStartSrc * (trueColor ? 4 : 1))]);
 35.3432 +				        int			 bytesToNextLine = pitch - (width * (trueColor ? 4 : 1));
 35.3433 +				        if (trueColor)
 35.3434 +				        {
 35.3435 +				            for (int y = yStartDst; y < height + yStartDst && y < LUA_SCREEN_HEIGHT; y++, pix += bytesToNextLine)
 35.3436 +				            {
 35.3437 +				                for (int x = xStartDst; x < width + xStartDst && x < LUA_SCREEN_WIDTH; x++, pix += 4)
 35.3438 +				                {
 35.3439 +				                    gui_drawpixel_fast(x, y, LUA_BUILD_PIXEL(opacMap[pix[0]], pix[1], pix[2], pix[3]));
 35.3440 +								}
 35.3441 +							}
 35.3442 +						}
 35.3443 +				        else
 35.3444 +				        {
 35.3445 +				            for (int y = yStartDst; y < height + yStartDst && y < LUA_SCREEN_HEIGHT; y++, pix += bytesToNextLine)
 35.3446 +				            {
 35.3447 +				                for (int x = xStartDst; x < width + xStartDst && x < LUA_SCREEN_WIDTH; x++, pix++)
 35.3448 +				                {
 35.3449 +				                    gui_drawpixel_fast(x, y, LUA_BUILD_PIXEL(pal[*pix].a, pal[*pix].r, pal[*pix].g, pal[*pix].b));
 35.3450 +								}
 35.3451 +							}
 35.3452 +						}
 35.3453 +
 35.3454 +				        return 0;
 35.3455 +					}
 35.3456 +
 35.3457 +// function gui.register(function f)
 35.3458 +//
 35.3459 +//  This function will be called just before a graphical update.
 35.3460 +//  More complicated, but doesn't suffer any frame delays.
 35.3461 +//  Nil will be accepted in place of a function to erase
 35.3462 +//  a previously registered function, and the previous function
 35.3463 +
 35.3464 +//  (if any) is returned, or nil if none.
 35.3465 +				    static int gui_register(lua_State *L)
 35.3466 +				    {
 35.3467 +				        // We'll do this straight up.
 35.3468 +				        // First set up the stack.
 35.3469 +				        lua_settop(L, 1);
 35.3470 +
 35.3471 +				        // Verify the validity of the entry
 35.3472 +				        if (!lua_isnil(L, 1))
 35.3473 +							luaL_checktype(L, 1, LUA_TFUNCTION);
 35.3474 +
 35.3475 +				        // Get the old value
 35.3476 +				        lua_getfield(L, LUA_REGISTRYINDEX, guiCallbackTable);
 35.3477 +
 35.3478 +				        // Save the new value
 35.3479 +				        lua_pushvalue(L, 1);
 35.3480 +				        lua_setfield(L, LUA_REGISTRYINDEX, guiCallbackTable);
 35.3481 +
 35.3482 +				        // The old value is on top of the stack. Return it.
 35.3483 +				        return 1;
 35.3484 +					}
 35.3485 +
 35.3486 +// string gui.popup(string message, [string type = "ok"])
 35.3487 +//
 35.3488 +
 35.3489 +//  Popup dialog!
 35.3490 +				    int gui_popup(lua_State *L)
 35.3491 +				    {
 35.3492 +				        const char *message = luaL_checkstring(L, 1);
 35.3493 +				        const char *type	= luaL_optstring(L, 2, "ok");
 35.3494 +
 35.3495 +#if (defined(WIN32) && !defined(SDL))
 35.3496 +				        int t;
 35.3497 +				        if (strcmp(type, "ok") == 0)
 35.3498 +							t = MB_OK;
 35.3499 +				        else if (strcmp(type, "yesno") == 0)
 35.3500 +							t = MB_YESNO;
 35.3501 +				        else if (strcmp(type, "yesnocancel") == 0)
 35.3502 +							t = MB_YESNOCANCEL;
 35.3503 +				        else
 35.3504 +							return luaL_error(L, "invalid popup type \"%s\"", type);
 35.3505 +
 35.3506 +				        theApp.winCheckFullscreen();
 35.3507 +				        systemSoundClearBuffer();
 35.3508 +				        int result = AfxGetApp()->m_pMainWnd->MessageBox(message, "Lua Script Pop-up", t);
 35.3509 +
 35.3510 +				        lua_settop(L, 1);
 35.3511 +
 35.3512 +				        if (t != MB_OK)
 35.3513 +				        {
 35.3514 +				            if (result == IDYES)
 35.3515 +								lua_pushstring(L, "yes");
 35.3516 +				            else if (result == IDNO)
 35.3517 +								lua_pushstring(L, "no");
 35.3518 +				            else if (result == IDCANCEL)
 35.3519 +								lua_pushstring(L, "cancel");
 35.3520 +				            else
 35.3521 +								luaL_error(L, "win32 unrecognized return value %d", result);
 35.3522 +				            return 1;
 35.3523 +						}
 35.3524 +
 35.3525 +				        // else, we don't care.
 35.3526 +				        return 0;
 35.3527 +#else
 35.3528 +				        char *t;
 35.3529 +	#ifdef __linux
 35.3530 +				        // The Linux backend has a "FromPause" variable.
 35.3531 +				        // If set to 1, assume some known external event has screwed with the flow of time.
 35.3532 +				        // Since this pauses the emulator waiting for a response, we set it to 1.
 35.3533 +// FIXME: Well, actually it doesn't
 35.3534 +//	extern int FromPause;
 35.3535 +//	FromPause = 1;
 35.3536 +
 35.3537 +				        int pid; // appease compiler
 35.3538 +
 35.3539 +				        // Before doing any work, verify the correctness of the parameters.
 35.3540 +				        if (strcmp(type, "ok") == 0)
 35.3541 +							t = "OK:100";
 35.3542 +				        else if (strcmp(type, "yesno") == 0)
 35.3543 +							t = "Yes:100,No:101";
 35.3544 +				        else if (strcmp(type, "yesnocancel") == 0)
 35.3545 +							t = "Yes:100,No:101,Cancel:102";
 35.3546 +				        else
 35.3547 +							return luaL_error(L, "invalid popup type \"%s\"", type);
 35.3548 +
 35.3549 +				        // Can we find a copy of xmessage? Search the path.
 35.3550 +				        char *path = strdup(getenv("PATH"));
 35.3551 +
 35.3552 +				        char *current = path;
 35.3553 +
 35.3554 +				        char *colon;
 35.3555 +
 35.3556 +				        int found = 0;
 35.3557 +
 35.3558 +				        while (current)
 35.3559 +				        {
 35.3560 +				            colon = strchr(current, ':');
 35.3561 +
 35.3562 +				            // Clip off the colon.
 35.3563 +				            *colon++ = 0;
 35.3564 +
 35.3565 +				            int	  len	   = strlen(current);
 35.3566 +				            char *filename = (char *)malloc(len + 12); // always give excess
 35.3567 +				            snprintf(filename, len + 12, "%s/xmessage", current);
 35.3568 +
 35.3569 +				            if (access(filename, X_OK) == 0)
 35.3570 +				            {
 35.3571 +				                free(filename);
 35.3572 +				                found = 1;
 35.3573 +				                break;
 35.3574 +							}
 35.3575 +
 35.3576 +				            // Failed, move on.
 35.3577 +				            current = colon;
 35.3578 +				            free(filename);
 35.3579 +						}
 35.3580 +
 35.3581 +				        free(path);
 35.3582 +
 35.3583 +				        // We've found it?
 35.3584 +				        if (!found)
 35.3585 +							goto use_console;
 35.3586 +
 35.3587 +				        pid = fork();
 35.3588 +				        if (pid == 0)
 35.3589 +				        { // I'm the virgin sacrifice
 35.3590 +				          // I'm gonna be dead in a matter of microseconds anyways, so wasted memory doesn't matter to me.
 35.3591 +				          // Go ahead and abuse strdup.
 35.3592 +				            char *parameters[] = { "xmessage", "-buttons", t, strdup(message), NULL };
 35.3593 +
 35.3594 +				            execvp("xmessage", parameters);
 35.3595 +
 35.3596 +				            // Aw shitty
 35.3597 +				            perror("exec xmessage");
 35.3598 +				            exit(1);
 35.3599 +						}
 35.3600 +				        else if (pid < 0) // something went wrong!!! Oh hell... use the console
 35.3601 +							goto use_console;
 35.3602 +				        else
 35.3603 +				        {
 35.3604 +				            // We're the parent. Watch for the child.
 35.3605 +				            int r;
 35.3606 +				            int res = waitpid(pid, &r, 0);
 35.3607 +				            if (res < 0) // wtf?
 35.3608 +								goto use_console;
 35.3609 +
 35.3610 +				            // The return value gets copmlicated...
 35.3611 +				            if (!WIFEXITED(r))
 35.3612 +				            {
 35.3613 +				                luaL_error(L, "don't screw with my xmessage process!");
 35.3614 +							}
 35.3615 +
 35.3616 +				            r = WEXITSTATUS(r);
 35.3617 +
 35.3618 +				            // We assume it's worked.
 35.3619 +				            if (r == 0)
 35.3620 +				            {
 35.3621 +				                return 0; // no parameters for an OK
 35.3622 +							}
 35.3623 +
 35.3624 +				            if (r == 100)
 35.3625 +				            {
 35.3626 +				                lua_pushstring(L, "yes");
 35.3627 +				                return 1;
 35.3628 +							}
 35.3629 +
 35.3630 +				            if (r == 101)
 35.3631 +				            {
 35.3632 +				                lua_pushstring(L, "no");
 35.3633 +				                return 1;
 35.3634 +							}
 35.3635 +
 35.3636 +				            if (r == 102)
 35.3637 +				            {
 35.3638 +				                lua_pushstring(L, "cancel");
 35.3639 +				                return 1;
 35.3640 +							}
 35.3641 +
 35.3642 +				            // Wtf?
 35.3643 +				            return luaL_error(L, "popup failed due to unknown results involving xmessage (%d)", r);
 35.3644 +						}
 35.3645 +
 35.3646 +use_console:
 35.3647 +	#endif
 35.3648 +
 35.3649 +				        // All else has failed
 35.3650 +				        if (strcmp(type, "ok") == 0)
 35.3651 +							t = "";
 35.3652 +				        else if (strcmp(type, "yesno") == 0)
 35.3653 +							t = "yn";
 35.3654 +				        else if (strcmp(type, "yesnocancel") == 0)
 35.3655 +							t = "ync";
 35.3656 +				        else
 35.3657 +							return luaL_error(L, "invalid popup type \"%s\"", type);
 35.3658 +
 35.3659 +				        fprintf(stderr, "Lua Message: %s\n", message);
 35.3660 +
 35.3661 +				        while (true)
 35.3662 +				        {
 35.3663 +				            char buffer[64];
 35.3664 +
 35.3665 +				            // We don't want parameters
 35.3666 +				            if (!t[0])
 35.3667 +				            {
 35.3668 +				                fprintf(stderr, "[Press Enter]");
 35.3669 +				                fgets(buffer, sizeof(buffer), stdin);
 35.3670 +
 35.3671 +				                // We're done
 35.3672 +				                return 0;
 35.3673 +							}
 35.3674 +
 35.3675 +				            fprintf(stderr, "(%s): ", t);
 35.3676 +				            fgets(buffer, sizeof(buffer), stdin);
 35.3677 +
 35.3678 +				            // Check if the option is in the list
 35.3679 +				            if (strchr(t, tolower(buffer[0])))
 35.3680 +				            {
 35.3681 +				                switch (tolower(buffer[0]))
 35.3682 +				                {
 35.3683 +								case 'y':
 35.3684 +									lua_pushstring(L, "yes");
 35.3685 +									return 1;
 35.3686 +								case 'n':
 35.3687 +									lua_pushstring(L, "no");
 35.3688 +									return 1;
 35.3689 +								case 'c':
 35.3690 +									lua_pushstring(L, "cancel");
 35.3691 +									return 1;
 35.3692 +								default:
 35.3693 +									luaL_error(L, "internal logic error in console based prompts for gui.popup");
 35.3694 +								}
 35.3695 +							}
 35.3696 +
 35.3697 +				            // We fell through, so we assume the user answered wrong and prompt again.
 35.3698 +						}
 35.3699 +
 35.3700 +				        // Nothing here, since the only way out is in the loop.
 35.3701 +#endif
 35.3702 +					}
 35.3703 +
 35.3704 +#if (defined(WIN32) && !defined(SDL))
 35.3705 +				    const char  *s_keyToName[256] =
 35.3706 +				    {
 35.3707 +				        NULL,
 35.3708 +				        "leftclick",
 35.3709 +				        "rightclick",
 35.3710 +				        NULL,
 35.3711 +				        "middleclick",
 35.3712 +				        NULL,
 35.3713 +				        NULL,
 35.3714 +				        NULL,
 35.3715 +				        "backspace",
 35.3716 +				        "tab",
 35.3717 +				        NULL,
 35.3718 +				        NULL,
 35.3719 +				        NULL,
 35.3720 +				        "enter",
 35.3721 +				        NULL,
 35.3722 +				        NULL,
 35.3723 +				        "shift",       // 0x10
 35.3724 +				        "control",
 35.3725 +				        "alt",
 35.3726 +				        "pause",
 35.3727 +				        "capslock",
 35.3728 +				        NULL,
 35.3729 +				        NULL,
 35.3730 +				        NULL,
 35.3731 +				        NULL,
 35.3732 +				        NULL,
 35.3733 +				        NULL,
 35.3734 +				        "escape",
 35.3735 +				        NULL,
 35.3736 +				        NULL,
 35.3737 +				        NULL,
 35.3738 +				        NULL,
 35.3739 +				        "space",       // 0x20
 35.3740 +				        "pageup",
 35.3741 +				        "pagedown",
 35.3742 +				        "end",
 35.3743 +				        "home",
 35.3744 +				        "left",
 35.3745 +				        "up",
 35.3746 +				        "right",
 35.3747 +				        "down",
 35.3748 +				        NULL,
 35.3749 +				        NULL,
 35.3750 +				        NULL,
 35.3751 +				        NULL,
 35.3752 +				        "insert",
 35.3753 +				        "delete",
 35.3754 +				        NULL,
 35.3755 +				        "0",		   "1",			   "2",			   "3",			   "4",		   "5",		  "6",		 "7",		"8",	   "9",
 35.3756 +				        NULL,		   NULL,		   NULL,		   NULL,		   NULL,	   NULL,	  NULL,
 35.3757 +				        "A",		   "B",			   "C",			   "D",			   "E",		   "F",		  "G",		 "H",		"I",	   "J",
 35.3758 +				        "K",		   "L",			   "M",			   "N",			   "O",		   "P",		  "Q",		 "R",		"S",	   "T",
 35.3759 +				        "U",		   "V",			   "W",			   "X",			   "Y",		   "Z",
 35.3760 +				        NULL,
 35.3761 +				        NULL,
 35.3762 +				        NULL,
 35.3763 +				        NULL,
 35.3764 +				        NULL,
 35.3765 +				        "numpad0",	   "numpad1",	   "numpad2",	   "numpad3",	   "numpad4",  "numpad5", "numpad6", "numpad7", "numpad8", "numpad9",
 35.3766 +				        "numpad*",	   "numpad+",
 35.3767 +				        NULL,
 35.3768 +				        "numpad-",	   "numpad.",	   "numpad/",
 35.3769 +				        "F1",		   "F2",		   "F3",		   "F4",		   "F5",	   "F6",	  "F7",		 "F8",		"F9",	   "F10",	  "F11",
 35.3770 +				        "F12",
 35.3771 +				        "F13",		   "F14",		   "F15",		   "F16",		   "F17",	   "F18",	  "F19",	 "F20",		"F21",	   "F22",	  "F23",
 35.3772 +				        "F24",
 35.3773 +				        NULL,
 35.3774 +				        NULL,
 35.3775 +				        NULL,
 35.3776 +				        NULL,
 35.3777 +				        NULL,
 35.3778 +				        NULL,
 35.3779 +				        NULL,
 35.3780 +				        NULL,
 35.3781 +				        "numlock",
 35.3782 +				        "scrolllock",
 35.3783 +				        NULL,          // 0x92
 35.3784 +				        NULL,		   NULL,		   NULL,		   NULL,		   NULL,	   NULL,	  NULL,		 NULL,		NULL,	   NULL,	  NULL,
 35.3785 +				        NULL,		   NULL,		   NULL,		   NULL,		   NULL,	   NULL,	  NULL,		 NULL,		NULL,	   NULL,
 35.3786 +				        NULL,		   NULL,		   NULL,		   NULL,		   NULL,	   NULL,	  NULL,		 NULL,		NULL,
 35.3787 +				        NULL,		   NULL,		   NULL,		   NULL,		   NULL,	   NULL,	  NULL,		 NULL,
 35.3788 +				        NULL,          // 0xB9
 35.3789 +				        "semicolon",
 35.3790 +				        "plus",
 35.3791 +				        "comma",
 35.3792 +				        "minus",
 35.3793 +				        "period",
 35.3794 +				        "slash",
 35.3795 +				        "tilde",
 35.3796 +				        NULL,          // 0xC1
 35.3797 +				        NULL,		   NULL,		   NULL,		   NULL,		   NULL,	   NULL,	  NULL,		 NULL,		NULL,
 35.3798 +				        NULL,		   NULL,		   NULL,		   NULL,		   NULL,	   NULL,	  NULL,		 NULL,
 35.3799 +				        NULL,		   NULL,		   NULL,		   NULL,		   NULL,	   NULL,	  NULL,
 35.3800 +				        NULL,          // 0xDA
 35.3801 +				        "leftbracket",
 35.3802 +				        "backslash",
 35.3803 +				        "rightbracket",
 35.3804 +				        "quote",
 35.3805 +					};
 35.3806 +#endif
 35.3807 +
 35.3808 +// input.get()
 35.3809 +// takes no input, returns a lua table of entries representing the current input state,
 35.3810 +// independent of the joypad buttons the emulated game thinks are pressed
 35.3811 +// for example:
 35.3812 +//   if the user is holding the W key and the left mouse button
 35.3813 +//   and has the mouse at the bottom-right corner of the game screen,
 35.3814 +
 35.3815 +//   then this would return {W=true, leftclick=true, xmouse=255, ymouse=223}
 35.3816 +				    static int input_getcurrentinputstatus(lua_State *L)
 35.3817 +				    {
 35.3818 +				        lua_newtable(L);
 35.3819 +
 35.3820 +#if (defined(WIN32) && !defined(SDL))
 35.3821 +				        // keyboard and mouse button status
 35.3822 +				        {
 35.3823 +				            unsigned char keys[256];
 35.3824 +				            if (true /*!GUI.BackgroundInput*/) // TODO: background input
 35.3825 +				            {
 35.3826 +				                if (GetKeyboardState(keys))
 35.3827 +				                {
 35.3828 +				                    for (int i = 1; i < 255; i++)
 35.3829 +				                    {
 35.3830 +				                        int mask = (i == VK_CAPITAL || i == VK_NUMLOCK || i == VK_SCROLL) ? 0x01 : 0x80;
 35.3831 +				                        if (keys[i] & mask)
 35.3832 +				                        {
 35.3833 +				                            const char *name = s_keyToName[i];
 35.3834 +				                            if (name)
 35.3835 +				                            {
 35.3836 +				                                lua_pushboolean(L, true);
 35.3837 +				                                lua_setfield(L, -2, name);
 35.3838 +											}
 35.3839 +										}
 35.3840 +									}
 35.3841 +								}
 35.3842 +							}
 35.3843 +				            else // use a slightly different method that will detect background input:
 35.3844 +				            {
 35.3845 +				                for (int i = 1; i < 255; i++)
 35.3846 +				                {
 35.3847 +				                    const char *name = s_keyToName[i];
 35.3848 +				                    if (name)
 35.3849 +				                    {
 35.3850 +				                        int active;
 35.3851 +				                        if (i == VK_CAPITAL || i == VK_NUMLOCK || i == VK_SCROLL)
 35.3852 +											active = GetKeyState(i) & 0x01;
 35.3853 +				                        else
 35.3854 +											active = GetAsyncKeyState(i) & 0x8000;
 35.3855 +				                        if (active)
 35.3856 +				                        {
 35.3857 +				                            lua_pushboolean(L, true);
 35.3858 +				                            lua_setfield(L, -2, name);
 35.3859 +										}
 35.3860 +									}
 35.3861 +								}
 35.3862 +							}
 35.3863 +						}
 35.3864 +
 35.3865 +				        // mouse position in game screen pixel coordinates
 35.3866 +				        {
 35.3867 +				            POINT mouse;
 35.3868 +
 35.3869 +				            int xofs = 0, yofs = 0, width = 240, height = 160;
 35.3870 +				            if (!systemIsRunningGBA())
 35.3871 +				            {
 35.3872 +				                if (gbBorderOn)
 35.3873 +									width = 256, height = 224, xofs = 48, yofs = 40;
 35.3874 +				                else
 35.3875 +									width = 160, height = 144;
 35.3876 +							}
 35.3877 +
 35.3878 +				            GetCursorPos(&mouse);
 35.3879 +				            AfxGetApp()->m_pMainWnd->ScreenToClient(&mouse);
 35.3880 +
 35.3881 +				            // game screen is always fully stretched to window size,
 35.3882 +				            // with no aspect rate correction, or something like that.
 35.3883 +				            RECT clientRect;
 35.3884 +				            AfxGetApp()->m_pMainWnd->GetClientRect(&clientRect);
 35.3885 +
 35.3886 +				            int wndWidth  = clientRect.right - clientRect.left;
 35.3887 +				            int wndHeight = clientRect.bottom - clientRect.top;
 35.3888 +				            mouse.x = (LONG) (mouse.x * ((float)width / wndWidth)) - xofs;
 35.3889 +				            mouse.y = (LONG) (mouse.y * ((float)height / wndHeight)) - yofs;
 35.3890 +
 35.3891 +				            lua_pushinteger(L, mouse.x);
 35.3892 +				            lua_setfield(L, -2, "xmouse");
 35.3893 +				            lua_pushinteger(L, mouse.y);
 35.3894 +				            lua_setfield(L, -2, "ymouse");
 35.3895 +						}
 35.3896 +
 35.3897 +#else
 35.3898 +				        // NYI (well, return an empty table)
 35.3899 +#endif
 35.3900 +				        return 1;
 35.3901 +					}
 35.3902 +
 35.3903 +				    static int avi_framecount(lua_State *L)
 35.3904 +				    {
 35.3905 +	#ifdef WIN32
 35.3906 +				        if (theApp.aviRecorder != NULL)
 35.3907 +				        {
 35.3908 +				            lua_pushinteger(L, theApp.aviRecorder->videoFrames());
 35.3909 +						}
 35.3910 +				        else
 35.3911 +	#endif
 35.3912 +				        {
 35.3913 +				            lua_pushinteger(L, 0);
 35.3914 +						}
 35.3915 +				        return 1;
 35.3916 +					}
 35.3917 +
 35.3918 +				    static int avi_pause(lua_State *L)
 35.3919 +				    {
 35.3920 +	#ifdef WIN32
 35.3921 +				        if (theApp.aviRecorder != NULL)
 35.3922 +							theApp.aviRecorder->Pause(true);
 35.3923 +	#endif
 35.3924 +				        return 1;
 35.3925 +					}
 35.3926 +
 35.3927 +				    static int avi_resume(lua_State *L)
 35.3928 +				    {
 35.3929 +	#ifdef WIN32
 35.3930 +				        if (theApp.aviRecorder != NULL)
 35.3931 +							theApp.aviRecorder->Pause(false);
 35.3932 +	#endif
 35.3933 +				        return 1;
 35.3934 +					}
 35.3935 +
 35.3936 +					static int sound_get(lua_State *L)
 35.3937 +					{
 35.3938 +						extern int32 soundLevel1;
 35.3939 +						extern int32 soundLevel2;
 35.3940 +						extern int32 soundBalance;
 35.3941 +						extern int32 soundMasterOn;
 35.3942 +						extern int32 soundVIN;
 35.3943 +						extern int32 sound1On;
 35.3944 +						extern int32 sound1EnvelopeVolume;
 35.3945 +						extern int32 sound2On;
 35.3946 +						extern int32 sound2EnvelopeVolume;
 35.3947 +						extern int32 sound3On;
 35.3948 +						extern int32 sound3OutputLevel;
 35.3949 +						extern int32 sound3Bank;
 35.3950 +						extern int32 sound3DataSize;
 35.3951 +						extern int32 sound3ForcedOutput;
 35.3952 +						extern int32 sound4On;
 35.3953 +						extern int32 sound4EnvelopeVolume;
 35.3954 +						extern u8 sound3WaveRam[0x20];
 35.3955 +
 35.3956 +						int freqReg;
 35.3957 +						double freq;
 35.3958 +						double leftvolscale;
 35.3959 +						double rightvolscale;
 35.3960 +						double panpot;
 35.3961 +						bool gba = systemIsRunningGBA();
 35.3962 +						u8* gbMem = gba ? ioMem : gbMemory;
 35.3963 +						const int rNR10 = gba ? 0x60 : 0xff10;
 35.3964 +						const int rNR11 = gba ? 0x62 : 0xff11;
 35.3965 +						const int rNR12 = gba ? 0x63 : 0xff12;
 35.3966 +						const int rNR13 = gba ? 0x64 : 0xff13;
 35.3967 +						const int rNR14 = gba ? 0x65 : 0xff14;
 35.3968 +						const int rNR21 = gba ? 0x68 : 0xff16;
 35.3969 +						const int rNR22 = gba ? 0x69 : 0xff17;
 35.3970 +						const int rNR23 = gba ? 0x6c : 0xff18;
 35.3971 +						const int rNR24 = gba ? 0x6d : 0xff19;
 35.3972 +						const int rNR30 = gba ? 0x70 : 0xff1a;
 35.3973 +						const int rNR31 = gba ? 0x72 : 0xff1b;
 35.3974 +						const int rNR32 = gba ? 0x73 : 0xff1c;
 35.3975 +						const int rNR33 = gba ? 0x74 : 0xff1d;
 35.3976 +						const int rNR34 = gba ? 0x75 : 0xff1e;
 35.3977 +						const int rNR41 = gba ? 0x78 : 0xff20;
 35.3978 +						const int rNR42 = gba ? 0x79 : 0xff21;
 35.3979 +						const int rNR43 = gba ? 0x7c : 0xff22;
 35.3980 +						const int rNR44 = gba ? 0x7d : 0xff23;
 35.3981 +						const int rNR50 = gba ? 0x80 : 0xff24;
 35.3982 +						const int rNR51 = gba ? 0x81 : 0xff25;
 35.3983 +						const int rNR52 = gba ? 0x84 : 0xff26;
 35.3984 +						const int rWAVE_RAM = gba ? 0x90 : 0xff30;
 35.3985 +
 35.3986 +						const int32 _soundVIN = 0x88; // gba ? 0x88 : soundVIN;
 35.3987 +						const bool soundVINLeft = ((_soundVIN & 0x80) != 0);
 35.3988 +						const bool soundVINRight = ((_soundVIN & 0x08) != 0);
 35.3989 +
 35.3990 +						lua_newtable(L);
 35.3991 +
 35.3992 +						// square1
 35.3993 +						lua_newtable(L);
 35.3994 +						if(sound1On == 0 || soundMasterOn == 0)
 35.3995 +						{
 35.3996 +							lua_pushnumber(L, 0.0);
 35.3997 +							panpot = 0.5;
 35.3998 +						}
 35.3999 +						else
 35.4000 +						{
 35.4001 +							double envVolume = sound1EnvelopeVolume / 15.0;
 35.4002 +							if (soundVINLeft && (soundBalance & 0x10) != 0)
 35.4003 +								leftvolscale = ((soundLevel2 / 7.0) * envVolume);
 35.4004 +							else
 35.4005 +								leftvolscale = 0.0;
 35.4006 +							if (soundVINRight && (soundBalance & 0x01) != 0)
 35.4007 +								rightvolscale = ((soundLevel1 / 7.0) * envVolume);
 35.4008 +							else
 35.4009 +								rightvolscale = 0.0;
 35.4010 +							if ((leftvolscale + rightvolscale) != 0)
 35.4011 +								panpot = rightvolscale / (leftvolscale + rightvolscale);
 35.4012 +							else
 35.4013 +								panpot = 0.5;
 35.4014 +							lua_pushnumber(L, (leftvolscale + rightvolscale) / 2.0);
 35.4015 +						}
 35.4016 +						lua_setfield(L, -2, "volume");
 35.4017 +						lua_pushnumber(L, panpot);
 35.4018 +						lua_setfield(L, -2, "panpot");
 35.4019 +						freqReg = (((int)(gbMem[rNR14] & 7) << 8) | gbMem[rNR13]);
 35.4020 +						freq = 131072.0 / (2048 - freqReg);
 35.4021 +						lua_pushnumber(L, freq);
 35.4022 +						lua_setfield(L, -2, "frequency");
 35.4023 +						lua_pushnumber(L, (log(freq / 440.0) * 12 / log(2.0)) + 69);
 35.4024 +						lua_setfield(L, -2, "midikey");
 35.4025 +						lua_pushinteger(L, (gbMem[rNR11] & 0xC0) >> 6);
 35.4026 +						lua_setfield(L, -2, "duty");
 35.4027 +						lua_newtable(L);
 35.4028 +						lua_pushinteger(L, freqReg);
 35.4029 +						lua_setfield(L, -2, "frequency");
 35.4030 +						lua_setfield(L, -2, "regs");
 35.4031 +						lua_setfield(L, -2, "square1");
 35.4032 +						// square2
 35.4033 +						lua_newtable(L);
 35.4034 +						if(sound2On == 0 || soundMasterOn == 0)
 35.4035 +						{
 35.4036 +							lua_pushnumber(L, 0.0);
 35.4037 +							panpot = 0.5;
 35.4038 +						}
 35.4039 +						else
 35.4040 +						{
 35.4041 +							double envVolume = sound2EnvelopeVolume / 15.0;
 35.4042 +							if (soundVINLeft && (soundBalance & 0x20) != 0)
 35.4043 +								leftvolscale = ((soundLevel2 / 7.0) * envVolume);
 35.4044 +							else
 35.4045 +								leftvolscale = 0.0;
 35.4046 +							if (soundVINRight && (soundBalance & 0x02) != 0)
 35.4047 +								rightvolscale = ((soundLevel1 / 7.0) * envVolume);
 35.4048 +							else
 35.4049 +								rightvolscale = 0.0;
 35.4050 +							if ((leftvolscale + rightvolscale) != 0)
 35.4051 +								panpot = rightvolscale / (leftvolscale + rightvolscale);
 35.4052 +							else
 35.4053 +								panpot = 0.5;
 35.4054 +							lua_pushnumber(L, (leftvolscale + rightvolscale) / 2.0);
 35.4055 +						}
 35.4056 +						lua_setfield(L, -2, "volume");
 35.4057 +						lua_pushnumber(L, panpot);
 35.4058 +						lua_setfield(L, -2, "panpot");
 35.4059 +						freqReg = (((int)(gbMem[rNR24] & 7) << 8) | gbMem[rNR23]);
 35.4060 +						freq = 131072.0 / (2048 - freqReg);
 35.4061 +						lua_pushnumber(L, freq);
 35.4062 +						lua_setfield(L, -2, "frequency");
 35.4063 +						lua_pushnumber(L, (log(freq / 440.0) * 12 / log(2.0)) + 69);
 35.4064 +						lua_setfield(L, -2, "midikey");
 35.4065 +						lua_pushinteger(L, (gbMem[rNR21] & 0xC0) >> 6);
 35.4066 +						lua_setfield(L, -2, "duty");
 35.4067 +						lua_newtable(L);
 35.4068 +						lua_pushinteger(L, freqReg);
 35.4069 +						lua_setfield(L, -2, "frequency");
 35.4070 +						lua_setfield(L, -2, "regs");
 35.4071 +						lua_setfield(L, -2, "square2");
 35.4072 +						// wavememory
 35.4073 +						lua_newtable(L);
 35.4074 +						if(sound3On == 0 || soundMasterOn == 0)
 35.4075 +						{
 35.4076 +							lua_pushnumber(L, 0.0);
 35.4077 +							panpot = 0.5;
 35.4078 +						}
 35.4079 +						else
 35.4080 +						{
 35.4081 +							double envVolume;
 35.4082 +							if (gba && sound3ForcedOutput != 0)
 35.4083 +								envVolume = 0.75;
 35.4084 +							else
 35.4085 +							{
 35.4086 +								double volTable[4] = { 0.0, 1.0, 0.5, 0.25 };
 35.4087 +								envVolume = volTable[sound3OutputLevel & 3];
 35.4088 +							}
 35.4089 +
 35.4090 +							if (soundVINLeft && (soundBalance & 0x40) != 0)
 35.4091 +								leftvolscale = ((soundLevel2 / 7.0) * envVolume);
 35.4092 +							else
 35.4093 +								leftvolscale = 0.0;
 35.4094 +							if (soundVINRight && (soundBalance & 0x04) != 0)
 35.4095 +								rightvolscale = ((soundLevel1 / 7.0) * envVolume);
 35.4096 +							else
 35.4097 +								rightvolscale = 0.0;
 35.4098 +							if ((leftvolscale + rightvolscale) != 0)
 35.4099 +								panpot = rightvolscale / (leftvolscale + rightvolscale);
 35.4100 +							else
 35.4101 +								panpot = 0.5;
 35.4102 +							lua_pushnumber(L, (leftvolscale + rightvolscale) / 2.0);
 35.4103 +						}
 35.4104 +						lua_setfield(L, -2, "volume");
 35.4105 +						lua_pushnumber(L, panpot);
 35.4106 +						lua_setfield(L, -2, "panpot");
 35.4107 +						int waveMemSamples = 32;
 35.4108 +						if (gba)
 35.4109 +						{
 35.4110 +							lua_pushlstring(L, (const char *) &sound3WaveRam[sound3Bank * 0x10], sound3DataSize ? 0x20 : 0x10);
 35.4111 +							waveMemSamples = sound3DataSize ? 64 : 32;
 35.4112 +						}
 35.4113 +						else
 35.4114 +						{
 35.4115 +							lua_pushlstring(L, (const char *) &gbMem[rWAVE_RAM], 0x10);
 35.4116 +						}
 35.4117 +						lua_setfield(L, -2, "waveform");
 35.4118 +						freqReg = (((int)(gbMem[rNR34] & 7) << 8) | gbMem[rNR33]);
 35.4119 +						freq = 2097152.0 / (waveMemSamples * (2048 - freqReg));
 35.4120 +						lua_pushnumber(L, freq);
 35.4121 +						lua_setfield(L, -2, "frequency");
 35.4122 +						lua_pushnumber(L, (log(freq / 440.0) * 12 / log(2.0)) + 69);
 35.4123 +						lua_setfield(L, -2, "midikey");
 35.4124 +						lua_newtable(L);
 35.4125 +						lua_pushinteger(L, freqReg);
 35.4126 +						lua_setfield(L, -2, "frequency");
 35.4127 +						lua_setfield(L, -2, "regs");
 35.4128 +						lua_setfield(L, -2, "wavememory");
 35.4129 +						// noise
 35.4130 +						lua_newtable(L);
 35.4131 +						if(sound4On == 0 || soundMasterOn == 0)
 35.4132 +						{
 35.4133 +							lua_pushnumber(L, 0.0);
 35.4134 +							panpot = 0.5;
 35.4135 +						}
 35.4136 +						else
 35.4137 +						{
 35.4138 +							double envVolume = sound4EnvelopeVolume / 15.0;
 35.4139 +							if (soundVINLeft && (soundBalance & 0x80) != 0)
 35.4140 +								leftvolscale = ((soundLevel2 / 7.0) * envVolume);
 35.4141 +							else
 35.4142 +								leftvolscale = 0.0;
 35.4143 +							if (soundVINRight && (soundBalance & 0x08) != 0)
 35.4144 +								rightvolscale = ((soundLevel1 / 7.0) * envVolume);
 35.4145 +							else
 35.4146 +								rightvolscale = 0.0;
 35.4147 +							if ((leftvolscale + rightvolscale) != 0)
 35.4148 +								panpot = rightvolscale / (leftvolscale + rightvolscale);
 35.4149 +							else
 35.4150 +								panpot = 0.5;
 35.4151 +							lua_pushnumber(L, (leftvolscale + rightvolscale) / 2.0);
 35.4152 +						}
 35.4153 +						lua_setfield(L, -2, "volume");
 35.4154 +						lua_pushnumber(L, panpot);
 35.4155 +						lua_setfield(L, -2, "panpot");
 35.4156 +						const int gbNoiseFreqTable[8] = { 1, 2, 4, 6, 8, 10, 12, 14 };
 35.4157 +						freqReg = gbNoiseFreqTable[gbMem[rNR43] & 7] << (1 + (gbMem[rNR43] >> 4));
 35.4158 +						lua_pushboolean(L, (gbMem[rNR43] & 8) != 0);
 35.4159 +						lua_setfield(L, -2, "short");
 35.4160 +						freq = 1048576.0 / freqReg;
 35.4161 +						lua_pushnumber(L, freq);
 35.4162 +						lua_setfield(L, -2, "frequency");
 35.4163 +						lua_pushnumber(L, (log(freq / 440.0) * 12 / log(2.0)) + 69);
 35.4164 +						lua_setfield(L, -2, "midikey");
 35.4165 +						lua_newtable(L);
 35.4166 +						lua_pushinteger(L, freqReg);
 35.4167 +						lua_setfield(L, -2, "frequency");
 35.4168 +						lua_setfield(L, -2, "regs");
 35.4169 +						lua_setfield(L, -2, "noise");
 35.4170 +
 35.4171 +						return 1;
 35.4172 +					}
 35.4173 +
 35.4174 +// same as math.random, but uses SFMT instead of C rand()
 35.4175 +// FIXME: this function doesn't care multi-instance,
 35.4176 +
 35.4177 +//        original math.random either though (Lua 5.1)
 35.4178 +				    static int sfmt_random(lua_State *L)
 35.4179 +				    {
 35.4180 +				        lua_Number r = (lua_Number) genrand_real2();
 35.4181 +				        switch (lua_gettop(L))
 35.4182 +				        { // check number of arguments
 35.4183 +						case 0:
 35.4184 +							{ // no arguments
 35.4185 +							    lua_pushnumber(L, r); // Number between 0 and 1
 35.4186 +							    break;
 35.4187 +							}
 35.4188 +
 35.4189 +						case 1:
 35.4190 +							{ // only upper limit
 35.4191 +							    int u = luaL_checkint(L, 1);
 35.4192 +							    luaL_argcheck(L, 1 <= u, 1, "interval is empty");
 35.4193 +							    lua_pushnumber(L, floor(r * u) + 1); // int between 1 and `u'
 35.4194 +							    break;
 35.4195 +							}
 35.4196 +
 35.4197 +						case 2:
 35.4198 +							{ // lower and upper limits
 35.4199 +							    int l = luaL_checkint(L, 1);
 35.4200 +							    int u = luaL_checkint(L, 2);
 35.4201 +							    luaL_argcheck(L, l <= u, 2, "interval is empty");
 35.4202 +							    lua_pushnumber(L, floor(r * (u - l + 1)) + l); // int between `l' and `u'
 35.4203 +							    break;
 35.4204 +							}
 35.4205 +
 35.4206 +						default:
 35.4207 +							return luaL_error(L, "wrong number of arguments");
 35.4208 +						}
 35.4209 +
 35.4210 +				        return 1;
 35.4211 +					}
 35.4212 +
 35.4213 +// same as math.randomseed, but uses SFMT instead of C srand()
 35.4214 +// FIXME: this function doesn't care multi-instance,
 35.4215 +
 35.4216 +//        original math.randomseed either though (Lua 5.1)
 35.4217 +				    static int sfmt_randomseed(lua_State *L)
 35.4218 +				    {
 35.4219 +				        init_gen_rand(luaL_checkint(L, 1));
 35.4220 +				        return 0;
 35.4221 +					}
 35.4222 +
 35.4223 +// the following bit operations are ported from LuaBitOp 1.0.1,
 35.4224 +// because it can handle the sign bit (bit 31) correctly.
 35.4225 +
 35.4226 +/*
 35.4227 +** Lua BitOp -- a bit operations library for Lua 5.1.
 35.4228 +** http://bitop.luajit.org/
 35.4229 +**
 35.4230 +** Copyright (C) 2008-2009 Mike Pall. All rights reserved.
 35.4231 +**
 35.4232 +** Permission is hereby granted, free of charge, to any person obtaining
 35.4233 +** a copy of this software and associated documentation files (the
 35.4234 +** "Software"), to deal in the Software without restriction, including
 35.4235 +** without limitation the rights to use, copy, modify, merge, publish,
 35.4236 +** distribute, sublicense, and/or sell copies of the Software, and to
 35.4237 +** permit persons to whom the Software is furnished to do so, subject to
 35.4238 +** the following conditions:
 35.4239 +**
 35.4240 +** The above copyright notice and this permission notice shall be
 35.4241 +** included in all copies or substantial portions of the Software.
 35.4242 +**
 35.4243 +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 35.4244 +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 35.4245 +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 35.4246 +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 35.4247 +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 35.4248 +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 35.4249 +** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 35.4250 +**
 35.4251 +** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]
 35.4252 +*/
 35.4253 +
 35.4254 +#ifdef _MSC_VER
 35.4255 +/* MSVC is stuck in the last century and doesn't have C99's stdint.h. */
 35.4256 +				    typedef __int32			 int32_t;
 35.4257 +				    typedef unsigned __int32 uint32_t;
 35.4258 +				    typedef unsigned __int64 uint64_t;
 35.4259 +#else
 35.4260 +#include <stdint.h>
 35.4261 +#endif
 35.4262 +
 35.4263 +				    typedef int32_t	 SBits;
 35.4264 +				    typedef uint32_t UBits;
 35.4265 +
 35.4266 +				    typedef union
 35.4267 +				    {
 35.4268 +				        lua_Number n;
 35.4269 +#ifdef LUA_NUMBER_DOUBLE
 35.4270 +				        uint64_t b;
 35.4271 +#else
 35.4272 +				        UBits b;
 35.4273 +#endif
 35.4274 +					} BitNum;
 35.4275 +
 35.4276 +/* Convert argument to bit type. */
 35.4277 +				    static UBits barg(lua_State *L, int idx)
 35.4278 +				    {
 35.4279 +				        BitNum bn;
 35.4280 +				        UBits  b;
 35.4281 +				        bn.n = lua_tonumber(L, idx);
 35.4282 +#if defined(LUA_NUMBER_DOUBLE)
 35.4283 +				        bn.n += 6755399441055744.0; /* 2^52+2^51 */
 35.4284 +#ifdef SWAPPED_DOUBLE
 35.4285 +				        b = (UBits)(bn.b >> 32);
 35.4286 +#else
 35.4287 +				        b = (UBits)(bn.b & 0xffffffff);
 35.4288 +#endif
 35.4289 +#elif defined(LUA_NUMBER_INT) || defined(LUA_NUMBER_LONG) || \
 35.4290 +				        defined(LUA_NUMBER_LONGLONG) || defined(LUA_NUMBER_LONG_LONG) || \
 35.4291 +				        defined(LUA_NUMBER_LLONG)
 35.4292 +				        if (sizeof(UBits) == sizeof(lua_Number))
 35.4293 +							b = bn.b;
 35.4294 +				        else
 35.4295 +							b = (UBits)(SBits)bn.n;
 35.4296 +#elif defined(LUA_NUMBER_FLOAT)
 35.4297 +#error "A 'float' lua_Number type is incompatible with this library"
 35.4298 +#else
 35.4299 +#error "Unknown number type, check LUA_NUMBER_* in luaconf.h"
 35.4300 +#endif
 35.4301 +				        if (b == 0 && !lua_isnumber(L, idx))
 35.4302 +							luaL_typerror(L, idx, "number");
 35.4303 +				        return b;
 35.4304 +					}
 35.4305 +
 35.4306 +/* Return bit type. */
 35.4307 +#define BRET(b)  lua_pushnumber(L, (lua_Number)(SBits)(b)); return 1;
 35.4308 +
 35.4309 +				    static int bit_tobit(lua_State *L) { BRET(barg(L, 1)) }
 35.4310 +				    static int bit_bnot(lua_State *L) { BRET(~barg(L, 1)) }
 35.4311 +
 35.4312 +#define BIT_OP(func, opr) \
 35.4313 +	static int func(lua_State * L) { int i; UBits b = barg(L, 1); \
 35.4314 +				                     for (i = lua_gettop(L); i > 1; i--) \
 35.4315 +										 b opr barg(L, i); BRET(b) }
 35.4316 +				    BIT_OP(bit_band, &= )
 35.4317 +				    BIT_OP(bit_bor, |= )
 35.4318 +				    BIT_OP(bit_bxor, ^= )
 35.4319 +
 35.4320 +#define bshl(b, n)  (b << n)
 35.4321 +#define bshr(b, n)  (b >> n)
 35.4322 +#define bsar(b, n)  ((SBits)b >> n)
 35.4323 +#define brol(b, n)  ((b << n) | (b >> (32 - n)))
 35.4324 +#define bror(b, n)  ((b << (32 - n)) | (b >> n))
 35.4325 +#define BIT_SH(func, fn) \
 35.4326 +	static int func(lua_State * L) { \
 35.4327 +		UBits b = barg(L, 1); UBits n = barg(L, 2) & 31; BRET(fn(b, n)) }
 35.4328 +				    BIT_SH(bit_lshift, bshl)
 35.4329 +				    BIT_SH(bit_rshift, bshr)
 35.4330 +				    BIT_SH(bit_arshift, bsar)
 35.4331 +				    BIT_SH(bit_rol, brol)
 35.4332 +				    BIT_SH(bit_ror, bror)
 35.4333 +
 35.4334 +				    static int bit_bswap(lua_State *L)
 35.4335 +				    {
 35.4336 +				        UBits b = barg(L, 1);
 35.4337 +				        b = (b >> 24) | ((b >> 8) & 0xff00) | ((b & 0xff00) << 8) | (b << 24);
 35.4338 +				        BRET(b)
 35.4339 +					}
 35.4340 +
 35.4341 +				    static int bit_tohex(lua_State *L)
 35.4342 +				    {
 35.4343 +				        UBits		b		  = barg(L, 1);
 35.4344 +				        SBits		n		  = lua_isnone(L, 2) ? 8 : (SBits)barg(L, 2);
 35.4345 +				        const char *hexdigits = "0123456789abcdef";
 35.4346 +				        char		buf[8];
 35.4347 +				        int			i;
 35.4348 +				        if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; }
 35.4349 +				        if (n > 8) n = 8;
 35.4350 +				        for (i = (int)n; --i >= 0; )
 35.4351 +				        {
 35.4352 +				            buf[i] = hexdigits[b & 15]; b >>= 4;
 35.4353 +						}
 35.4354 +				        lua_pushlstring(L, buf, (size_t)n);
 35.4355 +				        return 1;
 35.4356 +					}
 35.4357 +
 35.4358 +				    static const struct luaL_Reg bit_funcs[] = {
 35.4359 +				        { "tobit",	 bit_tobit	 },
 35.4360 +				        { "bnot",	 bit_bnot	 },
 35.4361 +				        { "band",	 bit_band	 },
 35.4362 +				        { "bor",	 bit_bor	 },
 35.4363 +				        { "bxor",	 bit_bxor	 },
 35.4364 +				        { "lshift",	 bit_lshift	 },
 35.4365 +				        { "rshift",	 bit_rshift	 },
 35.4366 +				        { "arshift", bit_arshift },
 35.4367 +				        { "rol",	 bit_rol	 },
 35.4368 +				        { "ror",	 bit_ror	 },
 35.4369 +				        { "bswap",	 bit_bswap	 },
 35.4370 +				        { "tohex",	 bit_tohex	 },
 35.4371 +				        { NULL,		 NULL		 }
 35.4372 +					};
 35.4373 +
 35.4374 +/* Signed right-shifts are implementation-defined per C89/C99.
 35.4375 +** But the de facto standard are arithmetic right-shifts on two's
 35.4376 +** complement CPUs. This behaviour is required here, so test for it.
 35.4377 +*/
 35.4378 +#define BAD_SAR     (bsar(-8, 2) != (SBits) - 2)
 35.4379 +
 35.4380 +				    bool luabitop_validate(lua_State *L) // originally named as luaopen_bit
 35.4381 +				    {
 35.4382 +				        UBits b;
 35.4383 +				        lua_pushnumber(L, (lua_Number)1437217655L);
 35.4384 +				        b = barg(L, -1);
 35.4385 +				        if (b != (UBits)1437217655L || BAD_SAR) /* Perform a simple self-test. */
 35.4386 +				        {
 35.4387 +				            const char *msg = "compiled with incompatible luaconf.h";
 35.4388 +#ifdef LUA_NUMBER_DOUBLE
 35.4389 +#ifdef WIN32
 35.4390 +				            if (b == (UBits)1610612736L)
 35.4391 +								msg = "use D3DCREATE_FPU_PRESERVE with DirectX";
 35.4392 +#endif
 35.4393 +				            if (b == (UBits)1127743488L)
 35.4394 +								msg = "not compiled with SWAPPED_DOUBLE";
 35.4395 +#endif
 35.4396 +				            if (BAD_SAR)
 35.4397 +								msg = "arithmetic right-shift broken";
 35.4398 +				            luaL_error(L, "bit library self-test failed (%s)", msg);
 35.4399 +				            return false;
 35.4400 +						}
 35.4401 +				        return true;
 35.4402 +					}
 35.4403 +
 35.4404 +// LuaBitOp ends here
 35.4405 +
 35.4406 +				    static int bit_bshift_emulua(lua_State *L)
 35.4407 +				    {
 35.4408 +				        int shift = luaL_checkinteger(L, 2);
 35.4409 +				        if (shift < 0)
 35.4410 +				        {
 35.4411 +				            lua_pushinteger(L, -shift);
 35.4412 +				            lua_replace(L, 2);
 35.4413 +				            return bit_lshift(L);
 35.4414 +						}
 35.4415 +				        else
 35.4416 +							return bit_rshift(L);
 35.4417 +					}
 35.4418 +
 35.4419 +				    static int bitbit(lua_State *L)
 35.4420 +				    {
 35.4421 +				        int rv		= 0;
 35.4422 +				        int numArgs = lua_gettop(L);
 35.4423 +				        for (int i = 1; i <= numArgs; i++)
 35.4424 +				        {
 35.4425 +				            int where = luaL_checkinteger(L, i);
 35.4426 +				            if (where >= 0 && where < 32)
 35.4427 +								rv |= (1 << where);
 35.4428 +						}
 35.4429 +				        lua_settop(L, 0);
 35.4430 +				        BRET(rv);
 35.4431 +					}
 35.4432 +
 35.4433 +// The function called periodically to ensure Lua doesn't run amok.
 35.4434 +				    static void VBALuaHookFunction(lua_State *L, lua_Debug *dbg)
 35.4435 +				    {
 35.4436 +				        if (numTries-- == 0)
 35.4437 +				        {
 35.4438 +				            int kill = 0;
 35.4439 +
 35.4440 +#if (defined(WIN32) && !defined(SDL))
 35.4441 +				            // Uh oh
 35.4442 +				            theApp.winCheckFullscreen();
 35.4443 +				            systemSoundClearBuffer();
 35.4444 +				            int ret = AfxGetApp()->m_pMainWnd->MessageBox(
 35.4445 +				                "The Lua script running has been running a long time. It may have gone crazy. Kill it?\n\n(No = don't check anymore either)",
 35.4446 +				                "Lua Script Gone Nuts?",
 35.4447 +				                MB_YESNO);
 35.4448 +
 35.4449 +				            if (ret == IDYES)
 35.4450 +				            {
 35.4451 +				                kill = 1;
 35.4452 +							}
 35.4453 +
 35.4454 +#else
 35.4455 +				            fprintf(
 35.4456 +				                stderr,
 35.4457 +				                "The Lua script running has been running a long time.\nIt may have gone crazy. Kill it? (I won't ask again if you say No)\n");
 35.4458 +
 35.4459 +				            char buffer[64];
 35.4460 +				            while (true)
 35.4461 +				            {
 35.4462 +				                fprintf(stderr, "(y/n): ");
 35.4463 +				                fgets(buffer, sizeof(buffer), stdin);
 35.4464 +				                if (buffer[0] == 'y' || buffer[0] == 'Y')
 35.4465 +				                {
 35.4466 +				                    kill = 1;
 35.4467 +				                    break;
 35.4468 +								}
 35.4469 +
 35.4470 +				                if (buffer[0] == 'n' || buffer[0] == 'N')
 35.4471 +									break;
 35.4472 +							}
 35.4473 +#endif
 35.4474 +				            if (kill)
 35.4475 +				            {
 35.4476 +				                luaL_error(L, "Killed by user request.");
 35.4477 +				                VBALuaOnStop();
 35.4478 +							}
 35.4479 +
 35.4480 +				            // else, kill the debug hook.
 35.4481 +				            lua_sethook(L, NULL, 0, 0);
 35.4482 +						}
 35.4483 +					}
 35.4484 +
 35.4485 +				    static const struct luaL_reg vbalib[] = {
 35.4486 +				        //	{"speedmode", vba_speedmode},	// TODO: NYI
 35.4487 +				        { "frameadvance",	vba_frameadvance	  },
 35.4488 +				        { "pause",			vba_pause			  },
 35.4489 +				        { "framecount",		vba_framecount		  },
 35.4490 +				        { "lagcount",		vba_getlagcount		  },
 35.4491 +				        { "lagged",			vba_lagged			  },
 35.4492 +				        { "emulating",		vba_emulating		  },
 35.4493 +				        { "registerbefore", vba_registerbefore	  },
 35.4494 +				        { "registerafter",	vba_registerafter	  },
 35.4495 +				        { "registerexit",	vba_registerexit	  },
 35.4496 +				        { "message",		vba_message			  },
 35.4497 +				        { "print",			print				  }, // sure, why not
 35.4498 +				        { NULL,				NULL				  }
 35.4499 +					};
 35.4500 +
 35.4501 +				    static const struct luaL_reg memorylib[] = {
 35.4502 +				        { "readbyte",				memory_readbyte				},
 35.4503 +				        { "readbytesigned",			memory_readbytesigned		},
 35.4504 +				        { "readword",				memory_readword				},
 35.4505 +				        { "readwordsigned",			memory_readwordsigned		},
 35.4506 +				        { "readdword",				memory_readdword			},
 35.4507 +				        { "readdwordsigned",		memory_readdwordsigned		},
 35.4508 +				        { "readbyterange",			memory_readbyterange		},
 35.4509 +				        { "writebyte",				memory_writebyte			},
 35.4510 +				        { "writeword",				memory_writeword			},
 35.4511 +				        { "writedword",				memory_writedword			},
 35.4512 +				        { "getregister",			memory_getregister			},
 35.4513 +				        { "setregister",			memory_setregister			},
 35.4514 +						{ "gbromreadbyte",			memory_gbromreadbyte		},
 35.4515 +						{ "gbromreadbytesigned",	memory_gbromreadbytesigned	},
 35.4516 +						{ "gbromreadword",			memory_gbromreadword		},
 35.4517 +						{ "gbromreadwordsigned",	memory_gbromreadwordsigned	},
 35.4518 +						{ "gbromreaddword",			memory_gbromreaddword		},
 35.4519 +						{ "gbromreaddwordsigned",	memory_gbromreaddwordsigned	},
 35.4520 +						{ "gbromreadbyterange",		memory_gbromreadbyterange	},
 35.4521 +
 35.4522 +				        // alternate naming scheme for word and double-word and unsigned
 35.4523 +				        { "readbyteunsigned",		memory_readbyte				},
 35.4524 +				        { "readwordunsigned",		memory_readword				},
 35.4525 +				        { "readdwordunsigned",		memory_readdword			},
 35.4526 +				        { "readshort",				memory_readword				},
 35.4527 +				        { "readshortunsigned",		memory_readword				},
 35.4528 +				        { "readshortsigned",		memory_readwordsigned		},
 35.4529 +				        { "readlong",				memory_readdword			},
 35.4530 +				        { "readlongunsigned",		memory_readdword			},
 35.4531 +						{ "readlongsigned",			memory_readdwordsigned		},
 35.4532 +				        { "writeshort",				memory_writeword			},
 35.4533 +				        { "writelong",				memory_writedword			},
 35.4534 +						{ "gbromreadbyteunsigned",	memory_gbromreadbyte		},
 35.4535 +						{ "gbromreadwordunsigned",	memory_gbromreadword		},
 35.4536 +						{ "gbromreaddwordunsigned",	memory_gbromreaddword		},
 35.4537 +						{ "gbromreadshort",			memory_gbromreadword		},
 35.4538 +						{ "gbromreadshortunsigned",	memory_gbromreadword		},
 35.4539 +						{ "gbromreadshortsigned",	memory_gbromreadwordsigned	},
 35.4540 +						{ "gbromreadlong",			memory_gbromreaddword		},
 35.4541 +						{ "gbromreadlongunsigned",	memory_gbromreaddword		},
 35.4542 +						{ "gbromreadlongsigned",	memory_gbromreaddwordsigned	},
 35.4543 +
 35.4544 +				        // memory hooks
 35.4545 +				        { "registerwrite",	   memory_registerwrite			 },
 35.4546 +				        //{"registerread", memory_registerread},
 35.4547 +				        { "registerexec",	   memory_registerexec			 },
 35.4548 +				        // alternate names
 35.4549 +				        { "register",		   memory_registerwrite			 },
 35.4550 +				        { "registerrun",	   memory_registerexec			 },
 35.4551 +				        { "registerexecute",   memory_registerexec			 },
 35.4552 +
 35.4553 +				        { NULL,				   NULL							 }
 35.4554 +					};
 35.4555 +
 35.4556 +				    static const struct luaL_reg joypadlib[] = {
 35.4557 +				        { "get",	  joypad_get	  },
 35.4558 +				        { "getdown",  joypad_getdown  },
 35.4559 +				        { "getup",	  joypad_getup	  },
 35.4560 +				        { "set",	  joypad_set	  },
 35.4561 +
 35.4562 +				        // alternative names
 35.4563 +				        { "read",	  joypad_get	  },
 35.4564 +				        { "write",	  joypad_set	  },
 35.4565 +				        { "readdown", joypad_getdown  },
 35.4566 +				        { "readup",	  joypad_getup	  },
 35.4567 +				        { NULL,		  NULL			  }
 35.4568 +					};
 35.4569 +
 35.4570 +				    static const struct luaL_reg savestatelib[] = {
 35.4571 +				        { "create", savestate_create },
 35.4572 +				        { "save",	savestate_save	 },
 35.4573 +				        { "load",	savestate_load	 },
 35.4574 +
 35.4575 +				        { NULL,		NULL			 }
 35.4576 +					};
 35.4577 +
 35.4578 +				    static const struct luaL_reg movielib[] = {
 35.4579 +				        { "active",			  movie_isactive				},
 35.4580 +				        { "recording",		  movie_isrecording				},
 35.4581 +				        { "playing",		  movie_isplaying				},
 35.4582 +				        { "mode",			  movie_getmode					},
 35.4583 +
 35.4584 +				        { "length",			  movie_getlength				},
 35.4585 +				        { "author",			  movie_getauthor				},
 35.4586 +				        { "name",			  movie_getfilename				},
 35.4587 +				        { "rerecordcount",	  movie_rerecordcount			},
 35.4588 +				        { "setrerecordcount", movie_setrerecordcount		},
 35.4589 +
 35.4590 +				        { "rerecordcounting", movie_rerecordcounting		},
 35.4591 +				        { "framecount",		  vba_framecount				}, // for those familiar with
 35.4592 +				                                                              // other emulators that have
 35.4593 +				                                                              // movie.framecount()
 35.4594 +				                                                              // instead of
 35.4595 +				                                                              // emulatorname.framecount()
 35.4596 +
 35.4597 +				        { "stop",			  movie_stop					},
 35.4598 +
 35.4599 +				        // alternative names
 35.4600 +				        { "close",			  movie_stop					},
 35.4601 +				        { "getauthor",		  movie_getauthor				},
 35.4602 +				        { "getname",		  movie_getfilename				},
 35.4603 +				        { NULL,				  NULL							}
 35.4604 +					};
 35.4605 +
 35.4606 +				    static const struct luaL_reg guilib[] = {
 35.4607 +				        { "register",	  gui_register		   },
 35.4608 +				        { "text",		  gui_text			   },
 35.4609 +				        { "box",		  gui_drawbox		   },
 35.4610 +				        { "line",		  gui_drawline		   },
 35.4611 +				        { "pixel",		  gui_drawpixel		   },
 35.4612 +				        { "opacity",	  gui_setopacity	   },
 35.4613 +				        { "transparency", gui_transparency	   },
 35.4614 +				        { "popup",		  gui_popup			   },
 35.4615 +				        { "parsecolor",	  gui_parsecolor	   },
 35.4616 +				        { "gdscreenshot", gui_gdscreenshot	   },
 35.4617 +				        { "gdoverlay",	  gui_gdoverlay		   },
 35.4618 +				        { "getpixel",	  gui_getpixel		   },
 35.4619 +
 35.4620 +				        // alternative names
 35.4621 +				        { "drawtext",	  gui_text			   },
 35.4622 +				        { "drawbox",	  gui_drawbox		   },
 35.4623 +				        { "drawline",	  gui_drawline		   },
 35.4624 +				        { "drawpixel",	  gui_drawpixel		   },
 35.4625 +				        { "setpixel",	  gui_drawpixel		   },
 35.4626 +				        { "writepixel",	  gui_drawpixel		   },
 35.4627 +				        { "rect",		  gui_drawbox		   },
 35.4628 +				        { "drawrect",	  gui_drawbox		   },
 35.4629 +				        { "drawimage",	  gui_gdoverlay		   },
 35.4630 +				        { "image",		  gui_gdoverlay		   },
 35.4631 +				        { "readpixel",	  gui_getpixel		   },
 35.4632 +				        { NULL,			  NULL				   }
 35.4633 +					};
 35.4634 +
 35.4635 +				    static const struct luaL_reg inputlib[] = {
 35.4636 +				        { "get",  input_getcurrentinputstatus  },
 35.4637 +
 35.4638 +				        // alternative names
 35.4639 +				        { "read", input_getcurrentinputstatus  },
 35.4640 +				        { NULL,	  NULL						   }
 35.4641 +					};
 35.4642 +
 35.4643 +				    static const struct luaL_reg soundlib[] = {
 35.4644 +				        { "get",  sound_get                    },
 35.4645 +
 35.4646 +				        // alternative names
 35.4647 +				        { NULL,	  NULL						   }
 35.4648 +					};
 35.4649 +
 35.4650 +// gocha: since vba dumps avi so badly,
 35.4651 +// I add avilib as a workaround for enhanced video encoding.
 35.4652 +				    static const struct luaL_reg avilib[] = {
 35.4653 +				        { "framecount", avi_framecount },
 35.4654 +				        { "pause",		avi_pause	   },
 35.4655 +				        { "resume",		avi_resume	   },
 35.4656 +				        { NULL,			NULL		   }
 35.4657 +					};
 35.4658 +
 35.4659 +				    void CallExitFunction(void)
 35.4660 +				    {
 35.4661 +				        if (!LUA)
 35.4662 +							return;
 35.4663 +
 35.4664 +				        lua_settop(LUA, 0);
 35.4665 +				        lua_getfield(LUA, LUA_REGISTRYINDEX, luaCallIDStrings[LUACALL_BEFOREEXIT]);
 35.4666 +
 35.4667 +				        int errorcode = 0;
 35.4668 +				        if (lua_isfunction(LUA, -1))
 35.4669 +				        {
 35.4670 +				            errorcode = lua_pcall(LUA, 0, 0, 0);
 35.4671 +						}
 35.4672 +
 35.4673 +				        if (errorcode)
 35.4674 +							HandleCallbackError(LUA);
 35.4675 +					}
 35.4676 +
 35.4677 +				    void VBALuaFrameBoundary(void)
 35.4678 +				    {
 35.4679 +				        //	printf("Lua Frame\n");
 35.4680 +
 35.4681 +				        lua_joypads_used = 0;
 35.4682 +
 35.4683 +				        // HA!
 35.4684 +				        if (!LUA || !luaRunning)
 35.4685 +							return;
 35.4686 +
 35.4687 +				        // Our function needs calling
 35.4688 +				        lua_settop(LUA, 0);
 35.4689 +				        lua_getfield(LUA, LUA_REGISTRYINDEX, frameAdvanceThread);
 35.4690 +
 35.4691 +				        lua_State *thread = lua_tothread(LUA, 1);
 35.4692 +
 35.4693 +				        // Lua calling C must know that we're busy inside a frame boundary
 35.4694 +				        frameBoundary		= true;
 35.4695 +				        frameAdvanceWaiting = false;
 35.4696 +
 35.4697 +				        numTries = 1000;
 35.4698 +
 35.4699 +				        int result = lua_resume(thread, 0);
 35.4700 +
 35.4701 +				        if (result == LUA_YIELD)
 35.4702 +				        {
 35.4703 +				            // Okay, we're fine with that.
 35.4704 +						}
 35.4705 +				        else if (result != 0)
 35.4706 +				        {
 35.4707 +				            // Done execution by bad causes
 35.4708 +				            VBALuaOnStop();
 35.4709 +				            lua_pushnil(LUA);
 35.4710 +				            lua_setfield(LUA, LUA_REGISTRYINDEX, frameAdvanceThread);
 35.4711 +				            lua_pushnil(LUA);
 35.4712 +				            lua_setfield(LUA, LUA_REGISTRYINDEX, guiCallbackTable);
 35.4713 +
 35.4714 +				            // Error?
 35.4715 +//#if (defined(WIN32) && !defined(SDL))
 35.4716 +//		info_print(info_uid, lua_tostring(thread, -1)); //Clear_Sound_Buffer();
 35.4717 +// AfxGetApp()->m_pMainWnd->MessageBox(lua_tostring(thread, -1), "Lua run error", MB_OK | MB_ICONSTOP);
 35.4718 +//#else
 35.4719 +//		fprintf(stderr, "Lua thread bombed out: %s\n", lua_tostring(thread, -1));
 35.4720 +//#endif
 35.4721 +				            printerror(thread, -1);
 35.4722 +						}
 35.4723 +				        else
 35.4724 +				        {
 35.4725 +				            VBALuaOnStop();
 35.4726 +				            printf("Script died of natural causes.\n");
 35.4727 +						}
 35.4728 +
 35.4729 +				        // Past here, VBA actually runs, so any Lua code is called mid-frame. We must
 35.4730 +				        // not do anything too stupid, so let ourselves know.
 35.4731 +				        frameBoundary = false;
 35.4732 +
 35.4733 +				        if (!frameAdvanceWaiting)
 35.4734 +				        {
 35.4735 +				            VBALuaOnStop();
 35.4736 +						}
 35.4737 +					}
 35.4738 +
 35.4739 +/**
 35.4740 + * Loads and runs the given Lua script.
 35.4741 + * The emulator MUST be paused for this function to be
 35.4742 + * called. Otherwise, all frame boundary assumptions go out the window.
 35.4743 + *
 35.4744 + * Returns true on success, false on failure.
 35.4745 + */
 35.4746 +				    int VBALoadLuaCode(const char *filename)
 35.4747 +				    {
 35.4748 +				        static bool sfmtInitialized = false;
 35.4749 +				        if (!sfmtInitialized)
 35.4750 +				        {
 35.4751 +				            init_gen_rand((unsigned)time(NULL));
 35.4752 +				            sfmtInitialized = true;
 35.4753 +						}
 35.4754 +
 35.4755 +				        if (filename != luaScriptName)
 35.4756 +				        {
 35.4757 +				            if (luaScriptName)
 35.4758 +								free(luaScriptName);
 35.4759 +				            luaScriptName = strdup(filename);
 35.4760 +						}
 35.4761 +
 35.4762 +				        //stop any lua we might already have had running
 35.4763 +				        VBALuaStop();
 35.4764 +
 35.4765 +				        // Set current directory from filename (for dofile)
 35.4766 +				        char  dir[_MAX_PATH];
 35.4767 +				        char *slash, *backslash;
 35.4768 +				        strcpy(dir, filename);
 35.4769 +				        slash	  = strrchr(dir, '/');
 35.4770 +				        backslash = strrchr(dir, '\\');
 35.4771 +				        if (!slash || (backslash && backslash < slash))
 35.4772 +							slash = backslash;
 35.4773 +				        if (slash)
 35.4774 +				        {
 35.4775 +				            slash[1] = '\0'; // keep slash itself for some reasons
 35.4776 +				            chdir(dir);
 35.4777 +						}
 35.4778 +
 35.4779 +				        if (!LUA)
 35.4780 +				        {
 35.4781 +				            LUA = lua_open();
 35.4782 +				            luaL_openlibs(LUA);
 35.4783 +
 35.4784 +				            luaL_register(LUA, "emu", vbalib); // added for better cross-emulator compatibility
 35.4785 +				            luaL_register(LUA, "vba", vbalib); // kept for backward compatibility
 35.4786 +				            luaL_register(LUA, "memory", memorylib);
 35.4787 +				            luaL_register(LUA, "joypad", joypadlib);
 35.4788 +				            luaL_register(LUA, "savestate", savestatelib);
 35.4789 +				            luaL_register(LUA, "movie", movielib);
 35.4790 +				            luaL_register(LUA, "gui", guilib);
 35.4791 +				            luaL_register(LUA, "input", inputlib);
 35.4792 +				            luaL_register(LUA, "sound", soundlib);
 35.4793 +				            luaL_register(LUA, "bit", bit_funcs); // LuaBitOp library
 35.4794 +				            luaL_register(LUA, "avi", avilib); // workaround for enhanced video encoding
 35.4795 +				            lua_settop(LUA, 0); // clean the stack, because each call to luaL_register leaves a table on top
 35.4796 +
 35.4797 +				            // register a few utility functions outside of libraries (in the global namespace)
 35.4798 +				            lua_register(LUA, "print", print);
 35.4799 +				            lua_register(LUA, "tostring", tostring);
 35.4800 +				            lua_register(LUA, "addressof", addressof);
 35.4801 +				            lua_register(LUA, "copytable", copytable);
 35.4802 +
 35.4803 +				            // old bit operation functions
 35.4804 +				            lua_register(LUA, "AND", bit_band);
 35.4805 +				            lua_register(LUA, "OR", bit_bor);
 35.4806 +				            lua_register(LUA, "XOR", bit_bxor);
 35.4807 +				            lua_register(LUA, "SHIFT", bit_bshift_emulua);
 35.4808 +				            lua_register(LUA, "BIT", bitbit);
 35.4809 +
 35.4810 +				            luabitop_validate(LUA);
 35.4811 +
 35.4812 +				            lua_pushstring(LUA, "math");
 35.4813 +				            lua_gettable(LUA, LUA_GLOBALSINDEX);
 35.4814 +				            lua_pushcfunction(LUA, sfmt_random);
 35.4815 +				            lua_setfield(LUA, -2, "random");
 35.4816 +				            lua_pushcfunction(LUA, sfmt_randomseed);
 35.4817 +				            lua_setfield(LUA, -2, "randomseed");
 35.4818 +				            lua_settop(LUA, 0);
 35.4819 +
 35.4820 +				            // push arrays for storing hook functions in
 35.4821 +				            for (int i = 0; i < LUAMEMHOOK_COUNT; i++)
 35.4822 +				            {
 35.4823 +				                lua_newtable(LUA);
 35.4824 +				                lua_setfield(LUA, LUA_REGISTRYINDEX, luaMemHookTypeStrings[i]);
 35.4825 +							}
 35.4826 +						}
 35.4827 +
 35.4828 +				        // We make our thread NOW because we want it at the bottom of the stack.
 35.4829 +				        // If all goes wrong, we let the garbage collector remove it.
 35.4830 +				        lua_State *thread = lua_newthread(LUA);
 35.4831 +
 35.4832 +				        // Load the data
 35.4833 +				        int result = luaL_loadfile(LUA, filename);
 35.4834 +
 35.4835 +				        if (result)
 35.4836 +				        {
 35.4837 +//#if (defined(WIN32) && !defined(SDL))
 35.4838 +//		info_print(info_uid, lua_tostring(LUA, -1)); //Clear_Sound_Buffer();
 35.4839 +// AfxGetApp()->m_pMainWnd->MessageBox(lua_tostring(LUA, -1), "Lua load error", MB_OK | MB_ICONSTOP);
 35.4840 +//#else
 35.4841 +//		fprintf(stderr, "Failed to compile file: %s\n", lua_tostring(LUA, -1));
 35.4842 +//#endif
 35.4843 +				            printerror(LUA, -1);
 35.4844 +
 35.4845 +				            // Wipe the stack. Our thread
 35.4846 +				            lua_settop(LUA, 0);
 35.4847 +				            return 0; // Oh shit.
 35.4848 +						}
 35.4849 +
 35.4850 +				        // Get our function into it
 35.4851 +				        lua_xmove(LUA, thread, 1);
 35.4852 +
 35.4853 +				        // Save the thread to the registry. This is why I make the thread FIRST.
 35.4854 +				        lua_setfield(LUA, LUA_REGISTRYINDEX, frameAdvanceThread);
 35.4855 +
 35.4856 +				        // Initialize settings
 35.4857 +				        luaRunning = true;
 35.4858 +				        skipRerecords		 = false;
 35.4859 +				        numMemHooks			 = 0;
 35.4860 +				        transparencyModifier = 255; // opaque
 35.4861 +				        lua_joypads_used	 = 0; // not used
 35.4862 +				        //wasPaused = systemIsPaused();
 35.4863 +				        //systemSetPause(false);
 35.4864 +
 35.4865 +				        // Set up our protection hook to be executed once every 10,000 bytecode instructions.
 35.4866 +				        lua_sethook(thread, VBALuaHookFunction, LUA_MASKCOUNT, 10000);
 35.4867 +
 35.4868 +#ifdef WIN32
 35.4869 +				        info_print	 = PrintToWindowConsole;
 35.4870 +				        info_onstart = WinLuaOnStart;
 35.4871 +				        info_onstop	 = WinLuaOnStop;
 35.4872 +				        if (!LuaConsoleHWnd)
 35.4873 +							LuaConsoleHWnd = CreateDialog(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD_LUA),
 35.4874 +							                              AfxGetMainWnd()->GetSafeHwnd(), (DLGPROC) DlgLuaScriptDialog);
 35.4875 +				        info_uid = (int)LuaConsoleHWnd;
 35.4876 +#else
 35.4877 +				        info_print	 = NULL;
 35.4878 +				        info_onstart = NULL;
 35.4879 +				        info_onstop	 = NULL;
 35.4880 +#endif
 35.4881 +				        if (info_onstart)
 35.4882 +							info_onstart(info_uid);
 35.4883 +
 35.4884 +				        // And run it right now. :)
 35.4885 +				        VBALuaFrameBoundary();
 35.4886 +				        systemRenderFrame();
 35.4887 +
 35.4888 +				        // We're done.
 35.4889 +				        return 1;
 35.4890 +					}
 35.4891 +
 35.4892 +/**
 35.4893 + * Equivalent to repeating the last VBALoadLuaCode() call.
 35.4894 + */
 35.4895 +				    int VBAReloadLuaCode(void)
 35.4896 +				    {
 35.4897 +				        if (!luaScriptName)
 35.4898 +				        {
 35.4899 +				            systemScreenMessage("There's no script to reload.");
 35.4900 +				            return 0;
 35.4901 +						}
 35.4902 +				        else
 35.4903 +							return VBALoadLuaCode(luaScriptName);
 35.4904 +					}
 35.4905 +
 35.4906 +/**
 35.4907 + * Terminates a running Lua script by killing the whole Lua engine.
 35.4908 + *
 35.4909 + * Always safe to call, except from within a lua call itself (duh).
 35.4910 + *
 35.4911 + */
 35.4912 +				    void VBALuaStop(void)
 35.4913 +				    {
 35.4914 +				        //already killed
 35.4915 +				        if (!LUA)
 35.4916 +							return;
 35.4917 +
 35.4918 +				        //execute the user's shutdown callbacks
 35.4919 +				        CallExitFunction();
 35.4920 +
 35.4921 +				        /*info.*/ numMemHooks = 0;
 35.4922 +				        for (int i = 0; i < LUAMEMHOOK_COUNT; i++)
 35.4923 +							CalculateMemHookRegions((LuaMemHookType)i);
 35.4924 +
 35.4925 +				        //sometimes iup uninitializes com
 35.4926 +				        //MBG TODO - test whether this is really necessary. i dont think it is
 35.4927 +#if (defined(WIN32) && !defined(SDL))
 35.4928 +				        CoInitialize(0);
 35.4929 +#endif
 35.4930 +
 35.4931 +				        if (info_onstop)
 35.4932 +							info_onstop(info_uid);
 35.4933 +
 35.4934 +				        //lua_gc(LUA,LUA_GCCOLLECT,0);
 35.4935 +				        lua_close(LUA); // this invokes our garbage collectors for us
 35.4936 +				        LUA = NULL;
 35.4937 +				        VBALuaOnStop();
 35.4938 +					}
 35.4939 +
 35.4940 +/**
 35.4941 + * Returns true if there is a Lua script running.
 35.4942 + *
 35.4943 + */
 35.4944 +				    int VBALuaRunning(void)
 35.4945 +				    {
 35.4946 +				        // FIXME: return false when no callback functions are registered.
 35.4947 +				        return (int) (LUA != NULL); // should return true if callback functions are active.
 35.4948 +					}
 35.4949 +
 35.4950 +/**
 35.4951 + * Returns true if Lua would like to steal the given joypad control.
 35.4952 + *
 35.4953 + * Range is 0 through 3
 35.4954 + */
 35.4955 +				    int VBALuaUsingJoypad(int which)
 35.4956 +				    {
 35.4957 +				        if (which < 0 || which > 3)
 35.4958 +							which = systemGetDefaultJoypad();
 35.4959 +				        return lua_joypads_used & (1 << which);
 35.4960 +					}
 35.4961 +
 35.4962 +/**
 35.4963 + * Reads the buttons Lua is feeding for the given joypad, in the same
 35.4964 + * format as the OS-specific code.
 35.4965 + *
 35.4966 + * <del>This function must not be called more than once per frame. </del>Ideally exactly once
 35.4967 + * per frame (if VBALuaUsingJoypad says it's safe to do so)
 35.4968 + */
 35.4969 +				    int VBALuaReadJoypad(int which)
 35.4970 +				    {
 35.4971 +				        if (which < 0 || which > 3)
 35.4972 +							which = systemGetDefaultJoypad();
 35.4973 +
 35.4974 +				        //lua_joypads_used &= ~(1 << which);
 35.4975 +				        return lua_joypads[which];
 35.4976 +					}
 35.4977 +
 35.4978 +/**
 35.4979 + * If this function returns true, the movie code should NOT increment
 35.4980 + * the rerecord count for a load-state.
 35.4981 + *
 35.4982 + * This function will not return true if a script is not running.
 35.4983 + */
 35.4984 +				    bool8 VBALuaRerecordCountSkip(void)
 35.4985 +				    {
 35.4986 +				        // FIXME: return true if (there are any active callback functions && skipRerecords)
 35.4987 +				        return LUA && luaRunning && skipRerecords;
 35.4988 +					}
 35.4989 +
 35.4990 +/**
 35.4991 + * Given a screen with the indicated resolution,
 35.4992 + * draw the current GUI onto it.
 35.4993 + */
 35.4994 +				    void VBALuaGui(uint8 *screen, int ppl, int width, int height)
 35.4995 +				    {
 35.4996 +				        if (!LUA /* || !luaRunning*/)
 35.4997 +							return;
 35.4998 +
 35.4999 +				        // First, check if we're being called by anybody
 35.5000 +				        lua_getfield(LUA, LUA_REGISTRYINDEX, guiCallbackTable);
 35.5001 +
 35.5002 +				        if (lua_isfunction(LUA, -1))
 35.5003 +				        {
 35.5004 +				            // We call it now
 35.5005 +				            numTries = 1000;
 35.5006 +
 35.5007 +				            int ret = lua_pcall(LUA, 0, 0, 0);
 35.5008 +				            if (ret != 0)
 35.5009 +				            {
 35.5010 +				                // This is grounds for trashing the function
 35.5011 +				                // Note: This must be done before the messagebox pops up,
 35.5012 +				                //       otherwise the messagebox will cause a paint event which causes a weird
 35.5013 +				                //       infinite call sequence that makes Snes9x silently exit with error code 3,
 35.5014 +				                //       if a Lua GUI function crashes. (nitsuja)
 35.5015 +				                lua_pushnil(LUA);
 35.5016 +				                lua_setfield(LUA, LUA_REGISTRYINDEX, guiCallbackTable);
 35.5017 +
 35.5018 +//#if (defined(WIN32) && !defined(SDL))
 35.5019 +//			info_print(info_uid, lua_tostring(LUA, -1)); //AfxGetApp()->m_pMainWnd->MessageBox(lua_tostring(LUA, -1), "Lua Error
 35.5020 +// in GUI function", MB_OK);
 35.5021 +//#else
 35.5022 +//			fprintf(stderr, "Lua error in gui.register function: %s\n", lua_tostring(LUA, -1));
 35.5023 +//#endif
 35.5024 +				                printerror(LUA, -1);
 35.5025 +							}
 35.5026 +						}
 35.5027 +
 35.5028 +				        // And wreak the stack
 35.5029 +				        lua_settop(LUA, 0);
 35.5030 +
 35.5031 +				        if (!gui_used)
 35.5032 +							return;
 35.5033 +
 35.5034 +				        gui_used = false;
 35.5035 +
 35.5036 +				        int x, y;
 35.5037 +
 35.5038 +				        //int pitch = (((ppl * systemColorDepth + 7)>>3)+3)&~3;
 35.5039 +				        int pitch = ppl * (systemColorDepth / 8) + (systemColorDepth == 24 ? 0 : 4);
 35.5040 +
 35.5041 +				        if (width > LUA_SCREEN_WIDTH)
 35.5042 +							width = LUA_SCREEN_WIDTH;
 35.5043 +				        if (height > LUA_SCREEN_HEIGHT)
 35.5044 +							height = LUA_SCREEN_HEIGHT;
 35.5045 +
 35.5046 +				        GetColorFunc getColor;
 35.5047 +				        SetColorFunc setColor;
 35.5048 +				        getColorIOFunc(systemColorDepth, &getColor, &setColor);
 35.5049 +
 35.5050 +				        for (y = 0; y < height; y++)
 35.5051 +				        {
 35.5052 +				            uint8 *scr = &screen[y * pitch];
 35.5053 +				            for (x = 0; x < width; x++, scr += systemColorDepth / 8)
 35.5054 +				            {
 35.5055 +				                const uint8 gui_alpha = gui_data[(y * LUA_SCREEN_WIDTH + x) * 4 + 3];
 35.5056 +				                if (gui_alpha == 0)
 35.5057 +				                {
 35.5058 +				                    // do nothing
 35.5059 +				                    continue;
 35.5060 +								}
 35.5061 +
 35.5062 +				                const uint8 gui_red	  = gui_data[(y * LUA_SCREEN_WIDTH + x) * 4 + 2];
 35.5063 +				                const uint8 gui_green = gui_data[(y * LUA_SCREEN_WIDTH + x) * 4 + 1];
 35.5064 +				                const uint8 gui_blue  = gui_data[(y * LUA_SCREEN_WIDTH + x) * 4];
 35.5065 +				                int			red, green, blue;
 35.5066 +
 35.5067 +				                if (gui_alpha == 255)
 35.5068 +				                {
 35.5069 +				                    // direct copy
 35.5070 +				                    red	  = gui_red;
 35.5071 +				                    green = gui_green;
 35.5072 +				                    blue  = gui_blue;
 35.5073 +								}
 35.5074 +				                else
 35.5075 +				                {
 35.5076 +				                    // alpha-blending
 35.5077 +				                    uint8 scr_red, scr_green, scr_blue;
 35.5078 +				                    getColor(scr, &scr_red, &scr_green, &scr_blue);
 35.5079 +				                    red	  = (((int)gui_red - scr_red) * gui_alpha / 255 + scr_red) & 255;
 35.5080 +				                    green = (((int)gui_green - scr_green) * gui_alpha / 255 + scr_green) & 255;
 35.5081 +				                    blue  = (((int)gui_blue - scr_blue) * gui_alpha / 255 + scr_blue) & 255;
 35.5082 +								}
 35.5083 +
 35.5084 +				                setColor(scr, (uint8) red, (uint8) green, (uint8) blue);
 35.5085 +							}
 35.5086 +						}
 35.5087 +
 35.5088 +				        return;
 35.5089 +					}
 35.5090 +
 35.5091 +				    void VBALuaClearGui(void)
 35.5092 +				    {
 35.5093 +				        gui_used = false;
 35.5094 +					}
 35.5095 +
 35.5096 +				    lua_State *VBAGetLuaState()
 35.5097 +				    {
 35.5098 +				        return LUA;
 35.5099 +					}
 35.5100 +
 35.5101 +				    char *VBAGetLuaScriptName()
 35.5102 +				    {
 35.5103 +				        return luaScriptName;
 35.5104 +					}
 35.5105 +
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/src/common/memgzio.c	Sat Mar 03 10:31:27 2012 -0600
    36.3 @@ -0,0 +1,791 @@
    36.4 +/* gzio.c -- IO on .gz files
    36.5 + * Copyright (C) 1995-2002 Jean-loup Gailly.
    36.6 + * For conditions of distribution and use, see copyright notice in zlib.h
    36.7 + *
    36.8 + * Compile this file with -DNO_DEFLATE to avoid the compression code.
    36.9 + */
   36.10 +
   36.11 +/* memgzio.c - IO on .gz files in memory
   36.12 + * Adapted from original gzio.c from zlib library by Forgotten
   36.13 + */
   36.14 +
   36.15 +/* @(#) $Id: memgzio.c,v 1.5 2006/06/06 21:04:20 spacy51 Exp $ */
   36.16 +
   36.17 +#include <stdio.h>
   36.18 +#include <stdarg.h>
   36.19 +#include <stdlib.h>
   36.20 +#include <string.h>
   36.21 +#include <errno.h>
   36.22 +
   36.23 +#include "memgzio.h"
   36.24 +
   36.25 +#ifndef local
   36.26 +#define local static
   36.27 +#endif
   36.28 +
   36.29 +#ifndef DEF_MEM_LEVEL
   36.30 +#  define DEF_MEM_LEVEL 8
   36.31 +#endif
   36.32 +
   36.33 +#ifndef OS_CODE
   36.34 +#define OS_CODE 3
   36.35 +#endif
   36.36 +
   36.37 +#ifndef zmemcpy
   36.38 +#define zmemcpy memcpy
   36.39 +#endif
   36.40 +
   36.41 +/*struct internal_state {int dummy;};*/ /* for buggy compilers */
   36.42 +
   36.43 +#ifndef Z_BUFSIZE
   36.44 +#  ifdef MAXSEG_64K
   36.45 +#    define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */
   36.46 +#  else
   36.47 +#    define Z_BUFSIZE 16384
   36.48 +#  endif
   36.49 +#endif
   36.50 +#ifndef Z_PRINTF_BUFSIZE
   36.51 +#  define Z_PRINTF_BUFSIZE 4096
   36.52 +#endif
   36.53 +
   36.54 +#define ALLOC(size) malloc(size)
   36.55 +#define TRYFREE(p) \
   36.56 +	{if (p)                            \
   36.57 +		 free(p);}
   36.58 +
   36.59 +static int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
   36.60 +
   36.61 +/* gzip flag byte */
   36.62 +#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
   36.63 +#define HEAD_CRC     0x02 /* bit 1 set: header CRC present */
   36.64 +#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
   36.65 +#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
   36.66 +#define COMMENT      0x10 /* bit 4 set: file comment present */
   36.67 +#define RESERVED     0xE0 /* bits 5..7: reserved */
   36.68 +
   36.69 +typedef struct _MemFile
   36.70 +{
   36.71 +	char *memory;
   36.72 +	char *next;
   36.73 +	int   available;
   36.74 +	int   error;
   36.75 +	char  mode;
   36.76 +} MEMFILE;
   36.77 +
   36.78 +typedef struct mem_stream
   36.79 +{
   36.80 +	z_stream stream;
   36.81 +	int      z_err;   /* error code for last stream operation */
   36.82 +	int      z_eof;   /* set if end of input file */
   36.83 +	MEMFILE *file;    /* memoru file */
   36.84 +	Byte *   inbuf;   /* input buffer */
   36.85 +	Byte *   outbuf;  /* output buffer */
   36.86 +	uLong    crc;     /* crc32 of uncompressed data */
   36.87 +	char *   msg;     /* error message */
   36.88 +	int      transparent; /* 1 if input file is not a .gz file */
   36.89 +	char     mode;    /* 'w' or 'r' */
   36.90 +	long     startpos; /* start of compressed data in file (header skipped) */
   36.91 +} mem_stream;
   36.92 +
   36.93 +local gzFile gz_open      OF((char *memory, const int available, const char *mode));
   36.94 +local int do_flush        OF((gzFile file, int flush));
   36.95 +local int get_byte     OF((mem_stream *s));
   36.96 +local void check_header OF((mem_stream *s));
   36.97 +local int destroy      OF((mem_stream *s));
   36.98 +local void putLong      OF((MEMFILE *file, uLong x));
   36.99 +local uLong getLong      OF((mem_stream *s));
  36.100 +
  36.101 +local MEMFILE *memOpen(char *memory, int available, char mode)
  36.102 +{
  36.103 +	MEMFILE *f;
  36.104 +
  36.105 +	if (available <= 8)
  36.106 +		return NULL;
  36.107 +
  36.108 +	if (mode != 'w' && mode != 'r')
  36.109 +		return NULL;
  36.110 +
  36.111 +	f = (MEMFILE *)malloc(sizeof(MEMFILE));
  36.112 +
  36.113 +	f->memory = memory;
  36.114 +	f->mode   = mode;
  36.115 +	f->error  = 0;
  36.116 +
  36.117 +	if (mode == 'w')
  36.118 +	{
  36.119 +		f->available         = available - 8;
  36.120 +		f->next              = memory + 8;
  36.121 +		memory[0]            = 'V';
  36.122 +		memory[1]            = 'B';
  36.123 +		memory[2]            = 'A';
  36.124 +		memory[3]            = ' ';
  36.125 +		*((int *)(memory+4)) = 0;
  36.126 +	}
  36.127 +	else
  36.128 +	{
  36.129 +		if (memory[0] != 'V' || memory[1] != 'B' || memory[2] != 'A' ||
  36.130 +		    memory[3] != ' ')
  36.131 +		{
  36.132 +			free(f);
  36.133 +			return NULL;
  36.134 +		}
  36.135 +		f->available = *((int *)(memory+4));
  36.136 +		f->next      = memory+8;
  36.137 +	}
  36.138 +
  36.139 +	return f;
  36.140 +}
  36.141 +
  36.142 +local size_t memWrite(const void *buffer, size_t size, size_t count,
  36.143 +                      MEMFILE *file)
  36.144 +{
  36.145 +	size_t total = size*count;
  36.146 +
  36.147 +	if (file->mode != 'w')
  36.148 +	{
  36.149 +		file->error = 1;
  36.150 +		return 0;
  36.151 +	}
  36.152 +
  36.153 +	if (total > (size_t)file->available)
  36.154 +	{
  36.155 +		total = file->available;
  36.156 +	}
  36.157 +	memcpy(file->next, buffer, total);
  36.158 +	file->available -= (int)total;
  36.159 +	file->next      += total;
  36.160 +	return total;
  36.161 +}
  36.162 +
  36.163 +local size_t memRead(void *buffer, size_t size, size_t count,
  36.164 +                     MEMFILE *file)
  36.165 +{
  36.166 +	size_t total = size*count;
  36.167 +
  36.168 +	if (file->mode != 'r')
  36.169 +	{
  36.170 +		file->error = 1;
  36.171 +		return 0;
  36.172 +	}
  36.173 +
  36.174 +	if (file->available == 0)
  36.175 +		return -1;
  36.176 +
  36.177 +	if (total > (size_t)file->available)
  36.178 +	{
  36.179 +		total = file->available;
  36.180 +	}
  36.181 +	memcpy(buffer, file->next, total);
  36.182 +	file->available -= (int)total;
  36.183 +	file->next      += total;
  36.184 +	return total;
  36.185 +}
  36.186 +
  36.187 +local int memPutc(int c, MEMFILE *file)
  36.188 +{
  36.189 +	if (file->mode != 'w')
  36.190 +	{
  36.191 +		file->error = 1;
  36.192 +		return -1;
  36.193 +	}
  36.194 +
  36.195 +	if (file->available >= 1)
  36.196 +	{
  36.197 +		*file->next++ = c;
  36.198 +		file->available--;
  36.199 +	}
  36.200 +	else
  36.201 +		return -1;
  36.202 +
  36.203 +	return c;
  36.204 +}
  36.205 +
  36.206 +local long memTell(MEMFILE *f)
  36.207 +{
  36.208 +	return (long)(f->next - f->memory) - 8;
  36.209 +}
  36.210 +
  36.211 +local int memError(MEMFILE *f)
  36.212 +{
  36.213 +	return f->error;
  36.214 +}
  36.215 +
  36.216 +local int memClose(MEMFILE *f)
  36.217 +{
  36.218 +	if (f->mode == 'w')
  36.219 +	{
  36.220 +		*((int *)(f->memory+4)) = memTell(f);
  36.221 +	}
  36.222 +	free(f);
  36.223 +	return 0;
  36.224 +}
  36.225 +
  36.226 +local int memPrintf(MEMFILE *f, const char *format, ...)
  36.227 +{
  36.228 +	char    buffer[80];
  36.229 +	va_list list;
  36.230 +	int     len;
  36.231 +
  36.232 +	va_start(list, format);
  36.233 +	len = vsprintf(buffer, format, list);
  36.234 +	va_end(list);
  36.235 +
  36.236 +	return (int)memWrite(buffer, 1, len, f);
  36.237 +}
  36.238 +
  36.239 +/* ===========================================================================
  36.240 +     Opens a gzip (.gz) file for reading or writing. The mode parameter
  36.241 +   is as in fopen ("rb" or "wb"). The file is given either by file descriptor
  36.242 +   or path name (if fd == -1).
  36.243 +     gz_open return NULL if the file could not be opened or if there was
  36.244 +   insufficient memory to allocate the (de)compression state; errno
  36.245 +   can be checked to distinguish the two cases (if errno is zero, the
  36.246 +   zlib error is Z_MEM_ERROR).
  36.247 + */
  36.248 +local gzFile gz_open(memory, available, mode)
  36.249 +char *memory;
  36.250 +const int   available;
  36.251 +const char *mode;
  36.252 +{
  36.253 +	int         err;
  36.254 +	int         level    = Z_DEFAULT_COMPRESSION; /* compression level */
  36.255 +	int         strategy = Z_DEFAULT_STRATEGY; /* compression strategy */
  36.256 +	char *      p        = (char *)mode;
  36.257 +	mem_stream *s;
  36.258 +	char        fmode[80]; /* copy of mode, without the compression level */
  36.259 +	char *      m = fmode;
  36.260 +
  36.261 +	s = (mem_stream *)ALLOC(sizeof(mem_stream));
  36.262 +	if (!s)
  36.263 +		return Z_NULL;
  36.264 +
  36.265 +	s->stream.zalloc   = (alloc_func)0;
  36.266 +	s->stream.zfree    = (free_func)0;
  36.267 +	s->stream.opaque   = (voidpf)0;
  36.268 +	s->stream.next_in  = s->inbuf = Z_NULL;
  36.269 +	s->stream.next_out = s->outbuf = Z_NULL;
  36.270 +	s->stream.avail_in = s->stream.avail_out = 0;
  36.271 +	s->z_err           = Z_OK;
  36.272 +	s->z_eof           = 0;
  36.273 +	s->crc             = crc32(0L, Z_NULL, 0);
  36.274 +	s->msg             = NULL;
  36.275 +	s->transparent     = 0;
  36.276 +	s->file            = NULL;
  36.277 +
  36.278 +	s->mode = '\0';
  36.279 +	do
  36.280 +	{
  36.281 +		if (*p == 'r')
  36.282 +			s->mode = 'r';
  36.283 +		if (*p == 'w' || *p == 'a')
  36.284 +			s->mode = 'w';
  36.285 +		if (*p >= '0' && *p <= '9')
  36.286 +		{
  36.287 +			level = *p - '0';
  36.288 +		}
  36.289 +		else if (*p == 'f')
  36.290 +		{
  36.291 +			strategy = Z_FILTERED;
  36.292 +		}
  36.293 +		else if (*p == 'h')
  36.294 +		{
  36.295 +			strategy = Z_HUFFMAN_ONLY;
  36.296 +		}
  36.297 +		else
  36.298 +		{
  36.299 +			*m++ = *p; /* copy the mode */
  36.300 +		}
  36.301 +	}
  36.302 +	while (*p++ && m != fmode + sizeof(fmode));
  36.303 +	if (s->mode == '\0')
  36.304 +		return destroy(s), (gzFile)Z_NULL;
  36.305 +
  36.306 +	if (s->mode == 'w')
  36.307 +	{
  36.308 +#ifdef NO_DEFLATE
  36.309 +		err = Z_STREAM_ERROR;
  36.310 +#else
  36.311 +		err = deflateInit2(&(s->stream), level,
  36.312 +		                   Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy);
  36.313 +		/* windowBits is passed < 0 to suppress zlib header */
  36.314 +
  36.315 +		s->stream.next_out = s->outbuf = (Byte *)ALLOC(Z_BUFSIZE);
  36.316 +#endif
  36.317 +		if (err != Z_OK || s->outbuf == Z_NULL)
  36.318 +		{
  36.319 +			return destroy(s), (gzFile)Z_NULL;
  36.320 +		}
  36.321 +	}
  36.322 +	else
  36.323 +	{
  36.324 +		s->stream.next_in = s->inbuf = (Byte *)ALLOC(Z_BUFSIZE);
  36.325 +
  36.326 +		err = inflateInit2(&(s->stream), -MAX_WBITS);
  36.327 +		/* windowBits is passed < 0 to tell that there is no zlib header.
  36.328 +		 * Note that in this case inflate *requires* an extra "dummy" byte
  36.329 +		 * after the compressed stream in order to complete decompression and
  36.330 +		 * return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are
  36.331 +		 * present after the compressed stream.
  36.332 +		 */
  36.333 +		if (err != Z_OK || s->inbuf == Z_NULL)
  36.334 +		{
  36.335 +			return destroy(s), (gzFile)Z_NULL;
  36.336 +		}
  36.337 +	}
  36.338 +	s->stream.avail_out = Z_BUFSIZE;
  36.339 +
  36.340 +	errno   = 0;
  36.341 +	s->file = memOpen(memory, available, s->mode);
  36.342 +
  36.343 +	if (s->file == NULL)
  36.344 +	{
  36.345 +		return destroy(s), (gzFile)Z_NULL;
  36.346 +	}
  36.347 +
  36.348 +	if (s->mode == 'w')
  36.349 +	{
  36.350 +		/* Write a very simple .gz header:
  36.351 +		 */
  36.352 +		memPrintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
  36.353 +		          Z_DEFLATED, 0 /*flags*/, 0, 0, 0, 0 /*time*/, 0 /*xflags*/, OS_CODE);
  36.354 +		s->startpos = 10L;
  36.355 +		/* We use 10L instead of ftell(s->file) to because ftell causes an
  36.356 +		 * fflush on some systems. This version of the library doesn't use
  36.357 +		 * startpos anyway in write mode, so this initialization is not
  36.358 +		 * necessary.
  36.359 +		 */
  36.360 +	}
  36.361 +	else
  36.362 +	{
  36.363 +		check_header(s); /* skip the .gz header */
  36.364 +		s->startpos = (memTell(s->file) - s->stream.avail_in);
  36.365 +	}
  36.366 +
  36.367 +	return (gzFile)s;
  36.368 +}
  36.369 +
  36.370 +/* ===========================================================================
  36.371 +     Opens a gzip (.gz) file for reading or writing.
  36.372 + */
  36.373 +gzFile ZEXPORT memgzopen(memory, available, mode)
  36.374 +char *memory;
  36.375 +int         available;
  36.376 +const char *mode;
  36.377 +{
  36.378 +	return gz_open(memory, available, mode);
  36.379 +}
  36.380 +
  36.381 +/* ===========================================================================
  36.382 +     Read a byte from a mem_stream; update next_in and avail_in. Return EOF
  36.383 +   for end of file.
  36.384 +   IN assertion: the stream s has been sucessfully opened for reading.
  36.385 + */
  36.386 +local int get_byte(s)
  36.387 +mem_stream *s;
  36.388 +{
  36.389 +	if (s->z_eof)
  36.390 +		return EOF;
  36.391 +	if (s->stream.avail_in == 0)
  36.392 +	{
  36.393 +		errno = 0;
  36.394 +		s->stream.avail_in = (uInt)memRead(s->inbuf, 1, Z_BUFSIZE, s->file);
  36.395 +		if (s->stream.avail_in == 0)
  36.396 +		{
  36.397 +			s->z_eof = 1;
  36.398 +			if (memError(s->file))
  36.399 +				s->z_err = Z_ERRNO;
  36.400 +			return EOF;
  36.401 +		}
  36.402 +		s->stream.next_in = s->inbuf;
  36.403 +	}
  36.404 +	s->stream.avail_in--;
  36.405 +	return *(s->stream.next_in)++;
  36.406 +}
  36.407 +
  36.408 +/* ===========================================================================
  36.409 +      Check the gzip header of a mem_stream opened for reading. Set the stream
  36.410 +    mode to transparent if the gzip magic header is not present; set s->err
  36.411 +    to Z_DATA_ERROR if the magic header is present but the rest of the header
  36.412 +    is incorrect.
  36.413 +    IN assertion: the stream s has already been created sucessfully;
  36.414 +       s->stream.avail_in is zero for the first time, but may be non-zero
  36.415 +       for concatenated .gz files.
  36.416 + */
  36.417 +local void check_header(s)
  36.418 +mem_stream *s;
  36.419 +{
  36.420 +	int  method; /* method byte */
  36.421 +	int  flags; /* flags byte */
  36.422 +	uInt len;
  36.423 +	int  c;
  36.424 +
  36.425 +	/* Check the gzip magic header */
  36.426 +	for (len = 0; len < 2; len++)
  36.427 +	{
  36.428 +		c = get_byte(s);
  36.429 +		if (c != gz_magic[len])
  36.430 +		{
  36.431 +			if (len != 0)
  36.432 +				s->stream.avail_in++, s->stream.next_in--;
  36.433 +			if (c != EOF)
  36.434 +			{
  36.435 +				s->stream.avail_in++, s->stream.next_in--;
  36.436 +				s->transparent = 1;
  36.437 +			}
  36.438 +			s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END;
  36.439 +			return;
  36.440 +		}
  36.441 +	}
  36.442 +	method = get_byte(s);
  36.443 +	flags  = get_byte(s);
  36.444 +	if (method != Z_DEFLATED || (flags & RESERVED) != 0)
  36.445 +	{
  36.446 +		s->z_err = Z_DATA_ERROR;
  36.447 +		return;
  36.448 +	}
  36.449 +
  36.450 +	/* Discard time, xflags and OS code: */
  36.451 +	for (len = 0; len < 6; len++)
  36.452 +		(void)get_byte(s);
  36.453 +
  36.454 +	if ((flags & EXTRA_FIELD) != 0)   /* skip the extra field */
  36.455 +	{
  36.456 +		len  =  (uInt)get_byte(s);
  36.457 +		len += ((uInt)get_byte(s))<<8;
  36.458 +		/* len is garbage if EOF but the loop below will quit anyway */
  36.459 +		while (len-- != 0 && get_byte(s) != EOF)
  36.460 +			;
  36.461 +	}
  36.462 +	if ((flags & ORIG_NAME) != 0)   /* skip the original file name */
  36.463 +	{
  36.464 +		while ((c = get_byte(s)) != 0 && c != EOF)
  36.465 +			;
  36.466 +	}
  36.467 +	if ((flags & COMMENT) != 0)     /* skip the .gz file comment */
  36.468 +	{
  36.469 +		while ((c = get_byte(s)) != 0 && c != EOF)
  36.470 +			;
  36.471 +	}
  36.472 +	if ((flags & HEAD_CRC) != 0)    /* skip the header crc */
  36.473 +	{
  36.474 +		for (len = 0; len < 2; len++)
  36.475 +			(void)get_byte(s);
  36.476 +	}
  36.477 +	s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
  36.478 +}
  36.479 +
  36.480 +/* ===========================================================================
  36.481 + * Cleanup then free the given mem_stream. Return a zlib error code.
  36.482 +   Try freeing in the reverse order of allocations.
  36.483 + */
  36.484 +local int destroy(s)
  36.485 +mem_stream *s;
  36.486 +{
  36.487 +	int err = Z_OK;
  36.488 +
  36.489 +	if (!s)
  36.490 +		return Z_STREAM_ERROR;
  36.491 +
  36.492 +	TRYFREE(s->msg);
  36.493 +
  36.494 +	if (s->stream.state != NULL)
  36.495 +	{
  36.496 +		if (s->mode == 'w')
  36.497 +		{
  36.498 +#ifdef NO_DEFLATE
  36.499 +			err = Z_STREAM_ERROR;
  36.500 +#else
  36.501 +			err = deflateEnd(&(s->stream));
  36.502 +#endif
  36.503 +		}
  36.504 +		else if (s->mode == 'r')
  36.505 +		{
  36.506 +			err = inflateEnd(&(s->stream));
  36.507 +		}
  36.508 +	}
  36.509 +	if (s->file != NULL && memClose(s->file))
  36.510 +	{
  36.511 +#ifdef ESPIPE
  36.512 +		if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
  36.513 +#endif
  36.514 +		err = Z_ERRNO;
  36.515 +	}
  36.516 +	if (s->z_err < 0)
  36.517 +		err = s->z_err;
  36.518 +
  36.519 +	TRYFREE(s->inbuf);
  36.520 +	TRYFREE(s->outbuf);
  36.521 +	TRYFREE(s);
  36.522 +	return err;
  36.523 +}
  36.524 +
  36.525 +/* ===========================================================================
  36.526 +     Reads the given number of uncompressed bytes from the compressed file.
  36.527 +   gzread returns the number of bytes actually read (0 for end of file).
  36.528 + */
  36.529 +int ZEXPORT memgzread(file, buf, len)
  36.530 +gzFile file;
  36.531 +voidp    buf;
  36.532 +unsigned len;
  36.533 +{
  36.534 +	mem_stream *s     = (mem_stream *)file;
  36.535 +	Bytef *     start = (Bytef *)buf; /* starting point for crc computation */
  36.536 +	Byte *      next_out; /* == stream.next_out but not forced far (for MSDOS) */
  36.537 +
  36.538 +	if (s == NULL || s->mode != 'r')
  36.539 +		return Z_STREAM_ERROR;
  36.540 +
  36.541 +	if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO)
  36.542 +		return -1;
  36.543 +	if (s->z_err == Z_STREAM_END)
  36.544 +		return 0;                            /* EOF */
  36.545 +
  36.546 +	next_out = (Byte *)buf;
  36.547 +	s->stream.next_out  = (Bytef *)buf;
  36.548 +	s->stream.avail_out = len;
  36.549 +
  36.550 +	while (s->stream.avail_out != 0)
  36.551 +	{
  36.552 +		if (s->transparent)
  36.553 +		{
  36.554 +			/* Copy first the lookahead bytes: */
  36.555 +			uInt n = s->stream.avail_in;
  36.556 +			if (n > s->stream.avail_out)
  36.557 +				n = s->stream.avail_out;
  36.558 +			if (n > 0)
  36.559 +			{
  36.560 +				zmemcpy(s->stream.next_out, s->stream.next_in, n);
  36.561 +				next_out += n;
  36.562 +				s->stream.next_out   = next_out;
  36.563 +				s->stream.next_in   += n;
  36.564 +				s->stream.avail_out -= n;
  36.565 +				s->stream.avail_in  -= n;
  36.566 +			}
  36.567 +			if (s->stream.avail_out > 0)
  36.568 +			{
  36.569 +				s->stream.avail_out -= (uInt)memRead(next_out, 1, s->stream.avail_out, s->file);
  36.570 +			}
  36.571 +			len -= s->stream.avail_out;
  36.572 +			s->stream.total_in  += (uLong)len;
  36.573 +			s->stream.total_out += (uLong)len;
  36.574 +			if (len == 0)
  36.575 +				s->z_eof = 1;
  36.576 +			return (int)len;
  36.577 +		}
  36.578 +		if (s->stream.avail_in == 0 && !s->z_eof)
  36.579 +		{
  36.580 +			errno = 0;
  36.581 +			s->stream.avail_in = (uInt)memRead(s->inbuf, 1, Z_BUFSIZE, s->file);
  36.582 +			if (s->stream.avail_in == 0)
  36.583 +			{
  36.584 +				s->z_eof = 1;
  36.585 +				if (memError(s->file))
  36.586 +				{
  36.587 +					s->z_err = Z_ERRNO;
  36.588 +					break;
  36.589 +				}
  36.590 +			}
  36.591 +			s->stream.next_in = s->inbuf;
  36.592 +		}
  36.593 +		s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
  36.594 +
  36.595 +		if (s->z_err == Z_STREAM_END)
  36.596 +		{
  36.597 +			/* Check CRC and original size */
  36.598 +			s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
  36.599 +			start  = s->stream.next_out;
  36.600 +
  36.601 +			if (getLong(s) != s->crc)
  36.602 +			{
  36.603 +				s->z_err = Z_DATA_ERROR;
  36.604 +			}
  36.605 +			else
  36.606 +			{
  36.607 +				(void)getLong(s);
  36.608 +				/* The uncompressed length returned by above getlong() may
  36.609 +				 * be different from s->stream.total_out) in case of
  36.610 +				 * concatenated .gz files. Check for such files:
  36.611 +				 */
  36.612 +				check_header(s);
  36.613 +				if (s->z_err == Z_OK)
  36.614 +				{
  36.615 +					uLong total_in  = s->stream.total_in;
  36.616 +					uLong total_out = s->stream.total_out;
  36.617 +
  36.618 +					inflateReset(&(s->stream));
  36.619 +					s->stream.total_in  = total_in;
  36.620 +					s->stream.total_out = total_out;
  36.621 +					s->crc = crc32(0L, Z_NULL, 0);
  36.622 +				}
  36.623 +			}
  36.624 +		}
  36.625 +		if (s->z_err != Z_OK || s->z_eof)
  36.626 +			break;
  36.627 +	}
  36.628 +	s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
  36.629 +
  36.630 +	return (int)(len - s->stream.avail_out);
  36.631 +}
  36.632 +
  36.633 +#ifndef NO_DEFLATE
  36.634 +/* ===========================================================================
  36.635 +     Writes the given number of uncompressed bytes into the compressed file.
  36.636 +   gzwrite returns the number of bytes actually written (0 in case of error).
  36.637 + */
  36.638 +int ZEXPORT memgzwrite(file, buf, len)
  36.639 +gzFile file;
  36.640 +const voidp buf;
  36.641 +unsigned    len;
  36.642 +{
  36.643 +	mem_stream *s = (mem_stream *)file;
  36.644 +
  36.645 +	if (s == NULL || s->mode != 'w')
  36.646 +		return Z_STREAM_ERROR;
  36.647 +
  36.648 +	s->stream.next_in  = (Bytef *)buf;
  36.649 +	s->stream.avail_in = len;
  36.650 +
  36.651 +	while (s->stream.avail_in != 0)
  36.652 +	{
  36.653 +		if (s->stream.avail_out == 0)
  36.654 +		{
  36.655 +			s->stream.next_out = s->outbuf;
  36.656 +			if (memWrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE)
  36.657 +			{
  36.658 +				s->z_err = Z_ERRNO;
  36.659 +				break;
  36.660 +			}
  36.661 +			s->stream.avail_out = Z_BUFSIZE;
  36.662 +		}
  36.663 +		s->z_err = deflate(&(s->stream), Z_NO_FLUSH);
  36.664 +		if (s->z_err != Z_OK)
  36.665 +			break;
  36.666 +	}
  36.667 +	s->crc = crc32(s->crc, (const Bytef *)buf, len);
  36.668 +
  36.669 +	return (int)(len - s->stream.avail_in);
  36.670 +}
  36.671 +#endif
  36.672 +/* ===========================================================================
  36.673 +     Flushes all pending output into the compressed file. The parameter
  36.674 +   flush is as in the deflate() function.
  36.675 + */
  36.676 +local int do_flush(file, flush)
  36.677 +gzFile file;
  36.678 +int flush;
  36.679 +{
  36.680 +	uInt        len;
  36.681 +	int         done = 0;
  36.682 +	mem_stream *s    = (mem_stream *)file;
  36.683 +
  36.684 +	if (s == NULL || s->mode != 'w')
  36.685 +		return Z_STREAM_ERROR;
  36.686 +
  36.687 +	s->stream.avail_in = 0; /* should be zero already anyway */
  36.688 +
  36.689 +	for (;;)
  36.690 +	{
  36.691 +		len = Z_BUFSIZE - s->stream.avail_out;
  36.692 +
  36.693 +		if (len != 0)
  36.694 +		{
  36.695 +			if ((uInt)memWrite(s->outbuf, 1, len, s->file) != len)
  36.696 +			{
  36.697 +				s->z_err = Z_ERRNO;
  36.698 +				return Z_ERRNO;
  36.699 +			}
  36.700 +			s->stream.next_out  = s->outbuf;
  36.701 +			s->stream.avail_out = Z_BUFSIZE;
  36.702 +		}
  36.703 +		if (done)
  36.704 +			break;
  36.705 +		s->z_err = deflate(&(s->stream), flush);
  36.706 +
  36.707 +		/* Ignore the second of two consecutive flushes: */
  36.708 +		if (len == 0 && s->z_err == Z_BUF_ERROR)
  36.709 +			s->z_err = Z_OK;
  36.710 +
  36.711 +		/* deflate has finished flushing only when it hasn't used up
  36.712 +		 * all the available space in the output buffer:
  36.713 +		 */
  36.714 +		done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
  36.715 +
  36.716 +		if (s->z_err != Z_OK && s->z_err != Z_STREAM_END)
  36.717 +			break;
  36.718 +	}
  36.719 +	return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
  36.720 +}
  36.721 +
  36.722 +/* ===========================================================================
  36.723 +   Outputs a long in LSB order to the given file
  36.724 + */
  36.725 +local void putLong(file, x)
  36.726 +MEMFILE *file;
  36.727 +uLong x;
  36.728 +{
  36.729 +	int n;
  36.730 +	for (n = 0; n < 4; n++)
  36.731 +	{
  36.732 +		memPutc((int)(x & 0xff), file);
  36.733 +		x >>= 8;
  36.734 +	}
  36.735 +}
  36.736 +
  36.737 +/* ===========================================================================
  36.738 +   Reads a long in LSB order from the given mem_stream. Sets z_err in case
  36.739 +   of error.
  36.740 + */
  36.741 +local uLong getLong(s)
  36.742 +mem_stream *s;
  36.743 +{
  36.744 +	uLong x = (uLong)get_byte(s);
  36.745 +	int   c;
  36.746 +
  36.747 +	x += ((uLong)get_byte(s))<<8;
  36.748 +	x += ((uLong)get_byte(s))<<16;
  36.749 +	c  = get_byte(s);
  36.750 +	if (c == EOF)
  36.751 +		s->z_err = Z_DATA_ERROR;
  36.752 +	x += ((uLong)c)<<24;
  36.753 +	return x;
  36.754 +}
  36.755 +
  36.756 +/* ===========================================================================
  36.757 +     Flushes all pending output if necessary, closes the compressed file
  36.758 +   and deallocates all the (de)compression state.
  36.759 + */
  36.760 +int ZEXPORT memgzclose(file)
  36.761 +gzFile file;
  36.762 +{
  36.763 +	int         err;
  36.764 +	mem_stream *s = (mem_stream *)file;
  36.765 +
  36.766 +	if (s == NULL)
  36.767 +		return Z_STREAM_ERROR;
  36.768 +
  36.769 +	if (s->mode == 'w')
  36.770 +	{
  36.771 +#ifdef NO_DEFLATE
  36.772 +		return Z_STREAM_ERROR;
  36.773 +#else
  36.774 +		err = do_flush(file, Z_FINISH);
  36.775 +		if (err != Z_OK)
  36.776 +			return destroy((mem_stream *)file);
  36.777 +
  36.778 +		putLong(s->file, s->crc);
  36.779 +		putLong(s->file, s->stream.total_in);
  36.780 +#endif
  36.781 +	}
  36.782 +	return destroy((mem_stream *)file);
  36.783 +}
  36.784 +
  36.785 +long ZEXPORT memtell(file)
  36.786 +gzFile file;
  36.787 +{
  36.788 +	mem_stream *s = (mem_stream *)file;
  36.789 +
  36.790 +	if (s == NULL)
  36.791 +		return Z_STREAM_ERROR;
  36.792 +
  36.793 +	return memTell(s->file);
  36.794 +}
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/src/common/memgzio.h	Sat Mar 03 10:31:27 2012 -0600
    37.3 @@ -0,0 +1,23 @@
    37.4 +#ifndef MEMGZIO_H
    37.5 +#define MEMGZIO_H
    37.6 +
    37.7 +/* gzio.c -- IO on .gz files
    37.8 + * Copyright (C) 1995-2002 Jean-loup Gailly.
    37.9 + * For conditions of distribution and use, see copyright notice in zlib.h
   37.10 + *
   37.11 + * Compile this file with -DNO_DEFLATE to avoid the compression code.
   37.12 + */
   37.13 +
   37.14 +/* memgzio.c - IO on .gz files in memory
   37.15 + * Adapted from original gzio.c from zlib library by Forgotten
   37.16 + */
   37.17 +
   37.18 +#include <zlib.h>
   37.19 +
   37.20 +gzFile ZEXPORT memgzopen(char *memory, int available, const char *mode);
   37.21 +int ZEXPORT memgzread(gzFile file, voidp buf, unsigned len);
   37.22 +int ZEXPORT memgzwrite(gzFile file, const voidp buf, unsigned len);
   37.23 +int ZEXPORT memgzclose(gzFile file);
   37.24 +long ZEXPORT memtell(gzFile file);
   37.25 +
   37.26 +#endif // MEMGZIO_H
    38.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.2 +++ b/src/common/movie.cpp	Sat Mar 03 10:31:27 2012 -0600
    38.3 @@ -0,0 +1,1772 @@
    38.4 +#include <cstdio>
    38.5 +#include <cctype>
    38.6 +#include <cstdlib>
    38.7 +#include <cstring>
    38.8 +#include <cassert>
    38.9 +#include <algorithm>
   38.10 +
   38.11 +using namespace std;
   38.12 +
   38.13 +#ifdef HAVE_STRINGS_H
   38.14 +#   include <strings.h>
   38.15 +#endif
   38.16 +
   38.17 +#if defined(__unix) || defined(__linux) || defined(__sun) || defined(__DJGPP)
   38.18 +#   include <unistd.h>
   38.19 +#   include <sys/types.h>
   38.20 +#   include <sys/stat.h>
   38.21 +#   include <climits>
   38.22 +#   define stricmp strcasecmp
   38.23 +// FIXME: this is wrong, but we don't want buffer overflow
   38.24 +#   if defined _MAX_PATH
   38.25 +#       undef _MAX_PATH
   38.26 +//#       define _MAX_PATH 128
   38.27 +#       define _MAX_PATH 260
   38.28 +#   endif
   38.29 +#endif
   38.30 +
   38.31 +#ifdef WIN32
   38.32 +#   include <io.h>
   38.33 +#   ifndef W_OK
   38.34 +#       define W_OK 2
   38.35 +#   endif
   38.36 +#   define ftruncate chsize
   38.37 +#endif
   38.38 +
   38.39 +#include "movie.h"
   38.40 +#include "System.h"
   38.41 +#include "../gba/GBA.h"
   38.42 +#include "../gba/GBAGlobals.h"
   38.43 +#include "../gba/RTC.h"
   38.44 +#include "../gb/GB.h"
   38.45 +#include "../gb/gbGlobals.h"
   38.46 +#include "inputGlobal.h"
   38.47 +#include "unzip.h"
   38.48 +#include "Util.h"
   38.49 +
   38.50 +#include "vbalua.h"
   38.51 +
   38.52 +#if (defined(WIN32) && !defined(SDL))
   38.53 +#   include "../win32/stdafx.h"
   38.54 +#   include "../win32/MainWnd.h"
   38.55 +#   include "../win32/VBA.h"
   38.56 +#   include "../win32/WinMiscUtil.h"
   38.57 +#endif
   38.58 +
   38.59 +extern int emulating; // from system.cpp
   38.60 +extern u16 currentButtons[4];     // from System.cpp
   38.61 +extern u16 lastKeys;
   38.62 +
   38.63 +SMovie Movie;
   38.64 +bool   loadingMovie = false;
   38.65 +
   38.66 +// probably bad idea to have so many global variables, but I hate to recompile almost everything after editing VBA.h
   38.67 +bool autoConvertMovieWhenPlaying = false;
   38.68 +
   38.69 +static u16 initialInputs[4] = { 0 };
   38.70 +
   38.71 +static bool resetSignaled	  = false;
   38.72 +static bool resetSignaledLast = false;
   38.73 +
   38.74 +static int prevEmulatorType, prevBorder, prevWinBorder, prevBorderAuto;
   38.75 +
   38.76 +// little-endian integer pop/push functions:
   38.77 +static inline uint32 Pop32(const uint8 * &ptr)
   38.78 +{
   38.79 +	uint32 v = (ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24));
   38.80 +	ptr += 4;
   38.81 +	return v;
   38.82 +}
   38.83 +
   38.84 +static inline uint16 Pop16(const uint8 * &ptr) /* const version */
   38.85 +{
   38.86 +	uint16 v = (ptr[0] | (ptr[1] << 8));
   38.87 +	ptr += 2;
   38.88 +	return v;
   38.89 +}
   38.90 +
   38.91 +static inline uint16 Pop16(uint8 * &ptr) /* non-const version */
   38.92 +{
   38.93 +	uint16 v = (ptr[0] | (ptr[1] << 8));
   38.94 +	ptr += 2;
   38.95 +	return v;
   38.96 +}
   38.97 +
   38.98 +static inline uint8 Pop8(const uint8 * &ptr)
   38.99 +{
  38.100 +	return *(ptr)++;
  38.101 +}
  38.102 +
  38.103 +static inline void Push32(uint32 v, uint8 * &ptr)
  38.104 +{
  38.105 +	ptr[0] = (uint8)(v & 0xff);
  38.106 +	ptr[1] = (uint8)((v >> 8) & 0xff);
  38.107 +	ptr[2] = (uint8)((v >> 16) & 0xff);
  38.108 +	ptr[3] = (uint8)((v >> 24) & 0xff);
  38.109 +	ptr	  += 4;
  38.110 +}
  38.111 +
  38.112 +static inline void Push16(uint16 v, uint8 * &ptr)
  38.113 +{
  38.114 +	ptr[0] = (uint8)(v & 0xff);
  38.115 +	ptr[1] = (uint8)((v >> 8) & 0xff);
  38.116 +	ptr	  += 2;
  38.117 +}
  38.118 +
  38.119 +static inline void Push8(uint8 v, uint8 * &ptr)
  38.120 +{
  38.121 +	*ptr++ = v;
  38.122 +}
  38.123 +
  38.124 +// little-endian integer read/write functions:
  38.125 +static inline uint16 Read16(const uint8 *ptr)
  38.126 +{
  38.127 +	return ptr[0] | (ptr[1] << 8);
  38.128 +}
  38.129 +
  38.130 +static inline void Write16(uint16 v, uint8 *ptr)
  38.131 +{
  38.132 +	ptr[0] = uint8(v & 0xff);
  38.133 +	ptr[1] = uint8((v >> 8) & 0xff);
  38.134 +}
  38.135 +
  38.136 +static long file_length(FILE *fp)
  38.137 +{
  38.138 +	long cur_pos = ftell(fp);
  38.139 +	fseek(fp, 0, SEEK_END);
  38.140 +	long length = ftell(fp);
  38.141 +	fseek(fp, cur_pos, SEEK_SET);
  38.142 +	return length;
  38.143 +}
  38.144 +
  38.145 +static int bytes_per_frame(SMovie &mov)
  38.146 +{
  38.147 +	int num_controllers = 0;
  38.148 +
  38.149 +	for (int i = 0; i < MOVIE_NUM_OF_POSSIBLE_CONTROLLERS; ++i)
  38.150 +		if (mov.header.controllerFlags & MOVIE_CONTROLLER(i))
  38.151 +			++num_controllers;
  38.152 +
  38.153 +	return CONTROLLER_DATA_SIZE * num_controllers;
  38.154 +}
  38.155 +
  38.156 +static void reserve_buffer_space(uint32 space_needed)
  38.157 +{
  38.158 +	if (space_needed > Movie.inputBufferSize)
  38.159 +	{
  38.160 +		uint32 ptr_offset	= Movie.inputBufferPtr - Movie.inputBuffer;
  38.161 +		uint32 alloc_chunks = (space_needed - 1) / BUFFER_GROWTH_SIZE + 1;
  38.162 +		uint32 old_size     = Movie.inputBufferSize;
  38.163 +		Movie.inputBufferSize = BUFFER_GROWTH_SIZE * alloc_chunks;
  38.164 +		Movie.inputBuffer	  = (uint8 *)realloc(Movie.inputBuffer, Movie.inputBufferSize);
  38.165 +		// FIXME: this only fixes the random input problem during dma-frame-skip, but not the skip
  38.166 +		memset(Movie.inputBuffer + old_size, 0, Movie.inputBufferSize - old_size);
  38.167 +		Movie.inputBufferPtr  = Movie.inputBuffer + ptr_offset;
  38.168 +	}
  38.169 +}
  38.170 +
  38.171 +static int read_movie_header(FILE *file, SMovie &movie)
  38.172 +{
  38.173 +	assert(file != NULL);
  38.174 +	assert(VBM_HEADER_SIZE == sizeof(SMovieFileHeader)); // sanity check on the header type definition
  38.175 +
  38.176 +	uint8 headerData [VBM_HEADER_SIZE];
  38.177 +
  38.178 +	if (fread(headerData, 1, VBM_HEADER_SIZE, file) != VBM_HEADER_SIZE)
  38.179 +		return MOVIE_WRONG_FORMAT;  // if we failed to read in all VBM_HEADER_SIZE bytes of the header
  38.180 +
  38.181 +	const uint8 *	  ptr	 = headerData;
  38.182 +	SMovieFileHeader &header = movie.header;
  38.183 +
  38.184 +	header.magic = Pop32(ptr);
  38.185 +	if (header.magic != VBM_MAGIC)
  38.186 +		return MOVIE_WRONG_FORMAT;
  38.187 +
  38.188 +	header.version = Pop32(ptr);
  38.189 +	if (header.version != VBM_VERSION)
  38.190 +		return MOVIE_WRONG_VERSION;
  38.191 +
  38.192 +	header.uid = Pop32(ptr);
  38.193 +	header.length_frames  = Pop32(ptr) + 1;    // HACK: add 1 to the length for compatibility
  38.194 +	header.rerecord_count = Pop32(ptr);
  38.195 +
  38.196 +	header.startFlags	   = Pop8(ptr);
  38.197 +	header.controllerFlags = Pop8(ptr);
  38.198 +	header.typeFlags	   = Pop8(ptr);
  38.199 +	header.optionFlags	   = Pop8(ptr);
  38.200 +
  38.201 +	header.saveType		  = Pop32(ptr);
  38.202 +	header.flashSize	  = Pop32(ptr);
  38.203 +	header.gbEmulatorType = Pop32(ptr);
  38.204 +
  38.205 +	for (int i = 0; i < 12; i++)
  38.206 +		header.romTitle[i] = Pop8(ptr);
  38.207 +
  38.208 +	header.minorVersion = Pop8(ptr);
  38.209 +
  38.210 +	header.romCRC = Pop8(ptr);
  38.211 +	header.romOrBiosChecksum = Pop16(ptr);
  38.212 +	header.romGameCode		 = Pop32(ptr);
  38.213 +
  38.214 +	header.offset_to_savestate		 = Pop32(ptr);
  38.215 +	header.offset_to_controller_data = Pop32(ptr);
  38.216 +
  38.217 +	return MOVIE_SUCCESS;
  38.218 +}
  38.219 +
  38.220 +static void write_movie_header(FILE *file, const SMovie &movie)
  38.221 +{
  38.222 +	assert(ftell(file) == 0); // we assume file points to beginning of movie file
  38.223 +
  38.224 +	uint8  headerData [VBM_HEADER_SIZE];
  38.225 +	uint8 *ptr = headerData;
  38.226 +	const SMovieFileHeader &header = movie.header;
  38.227 +
  38.228 +	Push32(header.magic, ptr);
  38.229 +	Push32(header.version, ptr);
  38.230 +
  38.231 +	Push32(header.uid, ptr);
  38.232 +	Push32(header.length_frames - 1, ptr);     // HACK: reduce the length by 1 for compatibility with certain faulty old tools
  38.233 +	                                           // like TME
  38.234 +	Push32(header.rerecord_count, ptr);
  38.235 +
  38.236 +	Push8(header.startFlags, ptr);
  38.237 +	Push8(header.controllerFlags, ptr);
  38.238 +	Push8(header.typeFlags, ptr);
  38.239 +	Push8(header.optionFlags, ptr);
  38.240 +
  38.241 +	Push32(header.saveType, ptr);
  38.242 +	Push32(header.flashSize, ptr);
  38.243 +	Push32(header.gbEmulatorType, ptr);
  38.244 +
  38.245 +	for (int i = 0; i < 12; ++i)
  38.246 +		Push8(header.romTitle[i], ptr);
  38.247 +
  38.248 +	Push8(header.minorVersion, ptr);
  38.249 +
  38.250 +	Push8(header.romCRC, ptr);
  38.251 +	Push16(header.romOrBiosChecksum, ptr);
  38.252 +	Push32(header.romGameCode, ptr);
  38.253 +
  38.254 +	Push32(header.offset_to_savestate, ptr);
  38.255 +	Push32(header.offset_to_controller_data, ptr);
  38.256 +
  38.257 +	fwrite(headerData, 1, VBM_HEADER_SIZE, file);
  38.258 +}
  38.259 +
  38.260 +static void flush_movie_header()
  38.261 +{
  38.262 +	assert(Movie.file != 0 && "logical error!");
  38.263 +	if (!Movie.file)
  38.264 +		return;
  38.265 +
  38.266 +	long originalPos = ftell(Movie.file);
  38.267 +
  38.268 +	// (over-)write the header
  38.269 +	fseek(Movie.file, 0, SEEK_SET);
  38.270 +	write_movie_header(Movie.file, Movie);
  38.271 +
  38.272 +	fflush(Movie.file);
  38.273 +
  38.274 +	fseek(Movie.file, originalPos, SEEK_SET);
  38.275 +}
  38.276 +
  38.277 +static void flush_movie_frames()
  38.278 +{
  38.279 +	assert(Movie.file && "logical error!");
  38.280 +	if (!Movie.file)
  38.281 +		return;
  38.282 +
  38.283 +	long originalPos = ftell(Movie.file);
  38.284 +
  38.285 +	// overwrite the controller data
  38.286 +	fseek(Movie.file, Movie.header.offset_to_controller_data, SEEK_SET);
  38.287 +	fwrite(Movie.inputBuffer, 1, Movie.bytesPerFrame * Movie.header.length_frames, Movie.file);
  38.288 +
  38.289 +	fflush(Movie.file);
  38.290 +
  38.291 +	fseek(Movie.file, originalPos, SEEK_SET);
  38.292 +}
  38.293 +
  38.294 +static void truncate_movie(long length)
  38.295 +{
  38.296 +	// truncate movie to length
  38.297 +	// NOTE: it's certain that the savestate block is never after the
  38.298 +	//       controller data block, because the VBM format decrees it.
  38.299 +
  38.300 +	assert(Movie.file && length >= 0);
  38.301 +	if (!Movie.file || length < 0)
  38.302 +		return;
  38.303 +
  38.304 +	assert(Movie.header.offset_to_savestate <= Movie.header.offset_to_controller_data);
  38.305 +	if (Movie.header.offset_to_savestate > Movie.header.offset_to_controller_data)
  38.306 +		return;
  38.307 +
  38.308 +	Movie.header.length_frames = length;
  38.309 +	flush_movie_header();
  38.310 +	const long truncLen = long(Movie.header.offset_to_controller_data + Movie.bytesPerFrame * length);
  38.311 +	if (file_length(Movie.file) != truncLen)
  38.312 +	{
  38.313 +		ftruncate(fileno(Movie.file), truncLen);
  38.314 +	}
  38.315 +}
  38.316 +
  38.317 +static void remember_input_state()
  38.318 +{
  38.319 +	for (int i = 0; i < MOVIE_NUM_OF_POSSIBLE_CONTROLLERS; ++i)
  38.320 +	{
  38.321 +		if (systemCartridgeType == 0)
  38.322 +		{
  38.323 +			initialInputs[i] = u16(~P1 & 0x03FF);
  38.324 +		}
  38.325 +		else
  38.326 +		{
  38.327 +			extern int32 gbJoymask[4];
  38.328 +			for (int i = 0; i < 4; ++i)
  38.329 +				initialInputs[i] = u16(gbJoymask[i] & 0xFFFF);
  38.330 +		}
  38.331 +	}
  38.332 +}
  38.333 +
  38.334 +static void change_state(MovieState new_state)
  38.335 +{
  38.336 +#if (defined(WIN32) && !defined(SDL))
  38.337 +	theApp.frameSearching	   = false;
  38.338 +	theApp.frameSearchSkipping = false;
  38.339 +#endif
  38.340 +
  38.341 +	if (new_state == MOVIE_STATE_NONE)
  38.342 +	{
  38.343 +		Movie.pauseFrame = -1;
  38.344 +
  38.345 +		if (Movie.state == MOVIE_STATE_NONE)
  38.346 +			return;
  38.347 +
  38.348 +		truncate_movie(Movie.header.length_frames);
  38.349 +
  38.350 +		fclose(Movie.file);
  38.351 +		Movie.file		   = NULL;
  38.352 +		Movie.currentFrame = 0;
  38.353 +#if (defined(WIN32) && !defined(SDL))
  38.354 +		// undo changes to border settings
  38.355 +		{
  38.356 +			gbBorderOn = prevBorder;
  38.357 +			theApp.winGbBorderOn = prevWinBorder;
  38.358 +			gbBorderAutomatic	 = prevBorderAuto;
  38.359 +			systemGbBorderOn();
  38.360 +		}
  38.361 +#endif
  38.362 +		gbEmulatorType = prevEmulatorType;
  38.363 +
  38.364 +		extern int32 gbDMASpeedVersion;
  38.365 +		gbDMASpeedVersion = 1;
  38.366 +
  38.367 +		extern int32 gbEchoRAMFixOn;
  38.368 +		gbEchoRAMFixOn = 1;
  38.369 +
  38.370 +		gbNullInputHackTempEnabled = gbNullInputHackEnabled;
  38.371 +
  38.372 +		if (Movie.inputBuffer)
  38.373 +		{
  38.374 +			free(Movie.inputBuffer);
  38.375 +			Movie.inputBuffer = NULL;
  38.376 +		}
  38.377 +	}
  38.378 +	else if (new_state == MOVIE_STATE_PLAY)
  38.379 +	{
  38.380 +		assert(Movie.file);
  38.381 +
  38.382 +		// this would cause problems if not dealt with
  38.383 +		if (Movie.currentFrame >= Movie.header.length_frames)
  38.384 +		{
  38.385 +			new_state = MOVIE_STATE_END;
  38.386 +			Movie.inputBufferPtr = Movie.inputBuffer + Movie.bytesPerFrame * Movie.header.length_frames;
  38.387 +		}
  38.388 +	}
  38.389 +	else if (new_state == MOVIE_STATE_RECORD)
  38.390 +	{
  38.391 +		assert(Movie.file);
  38.392 +
  38.393 +		// this would cause problems if not dealt with
  38.394 +		if (Movie.currentFrame > Movie.header.length_frames)
  38.395 +		{
  38.396 +			new_state = MOVIE_STATE_END;
  38.397 +			Movie.inputBufferPtr = Movie.inputBuffer + Movie.bytesPerFrame * Movie.header.length_frames;
  38.398 +		}
  38.399 +
  38.400 +		fseek(Movie.file, Movie.header.offset_to_controller_data + Movie.bytesPerFrame * Movie.currentFrame, SEEK_SET);
  38.401 +	}
  38.402 +
  38.403 +	if (new_state == MOVIE_STATE_END && Movie.state != MOVIE_STATE_END)
  38.404 +	{
  38.405 +#if defined(SDL)		
  38.406 +		systemClearJoypads();
  38.407 +#endif
  38.408 +		systemScreenMessage("Movie end");
  38.409 +	}
  38.410 +
  38.411 +	Movie.state = new_state;
  38.412 +
  38.413 +	// checking for movie end
  38.414 +	bool willPause = false;
  38.415 +
  38.416 +	// if the movie's been set to pause at a certain frame
  38.417 +	if (Movie.state != MOVIE_STATE_NONE && Movie.pauseFrame >= 0 && Movie.currentFrame == (uint32)Movie.pauseFrame)
  38.418 +	{
  38.419 +		Movie.pauseFrame = -1;
  38.420 +		willPause		 = true;
  38.421 +	}
  38.422 +
  38.423 +	if (Movie.state == MOVIE_STATE_END)
  38.424 +	{
  38.425 +		if (Movie.currentFrame == Movie.header.length_frames)
  38.426 +		{
  38.427 +#if (defined(WIN32) && !defined(SDL))
  38.428 +			if (theApp.movieOnEndPause)
  38.429 +			{
  38.430 +				willPause = true;
  38.431 +			}
  38.432 +#else
  38.433 +			// SDL FIXME
  38.434 +#endif
  38.435 +
  38.436 +#if (defined(WIN32) && !defined(SDL))
  38.437 +			switch (theApp.movieOnEndBehavior)
  38.438 +			{
  38.439 +			case 1:
  38.440 +				// the old behavior
  38.441 +				//VBAMovieRestart();
  38.442 +				break;
  38.443 +			case 2:
  38.444 +#else
  38.445 +			// SDL FIXME
  38.446 +#endif
  38.447 +				if (Movie.RecordedThisSession)
  38.448 +				{
  38.449 +					// if user has been recording this movie since the last time it started playing,
  38.450 +					// they probably don't want the movie to end now during playback,
  38.451 +					// so switch back to recording when it reaches the end
  38.452 +					VBAMovieSwitchToRecording();
  38.453 +					systemScreenMessage("Recording resumed");
  38.454 +					willPause = true;
  38.455 +				}
  38.456 +#if (defined(WIN32) && !defined(SDL))
  38.457 +				break;
  38.458 +			case 3:
  38.459 +				// keep open
  38.460 +				break;
  38.461 +			case 0:
  38.462 +				// fall through
  38.463 +			default:
  38.464 +				// close movie
  38.465 +				//VBAMovieStop(false);
  38.466 +				break;
  38.467 +			}
  38.468 +#else
  38.469 +				// SDL FIXME
  38.470 +#endif
  38.471 +		}
  38.472 +#if 1
  38.473 +		else if (Movie.currentFrame > Movie.header.length_frames)
  38.474 +		{
  38.475 +#if (defined(WIN32) && !defined(SDL))
  38.476 +			switch (theApp.movieOnEndBehavior)
  38.477 +			{
  38.478 +			case 1:
  38.479 +				// FIXME: this should be delayed till the current frame ends
  38.480 +				VBAMovieRestart();
  38.481 +				break;
  38.482 +			case 2:
  38.483 +				// nothing
  38.484 +				break;
  38.485 +			case 3:
  38.486 +				// keep open
  38.487 +				break;
  38.488 +			case 0:
  38.489 +				// fall through
  38.490 +			default:
  38.491 +				// close movie
  38.492 +				VBAMovieStop(false);
  38.493 +				break;
  38.494 +			}
  38.495 +#else
  38.496 +			// SDLFIXME
  38.497 +#endif
  38.498 +		}
  38.499 +#endif
  38.500 +	} // end if (Movie.state == MOVIE_STATE_END)
  38.501 +
  38.502 +	if (willPause)
  38.503 +	{
  38.504 +		systemSetPause(true);
  38.505 +	}
  38.506 +}
  38.507 +
  38.508 +void VBAMovieInit()
  38.509 +{
  38.510 +	memset(&Movie, 0, sizeof(Movie));
  38.511 +	Movie.state		 = MOVIE_STATE_NONE;
  38.512 +	Movie.pauseFrame = -1;
  38.513 +
  38.514 +	resetSignaled	  = false;
  38.515 +	resetSignaledLast = false;
  38.516 +}
  38.517 +
  38.518 +void VBAMovieGetRomInfo(const SMovie &movieInfo, char romTitle [12], uint32 &romGameCode, uint16 &checksum, uint8 &crc)
  38.519 +{
  38.520 +	if (systemCartridgeType == 0) // GBA
  38.521 +	{
  38.522 +		extern u8 *bios, *rom;
  38.523 +		memcpy(romTitle, &rom[0xa0], 12); // GBA TITLE
  38.524 +		memcpy(&romGameCode, &rom[0xac], 4); // GBA ROM GAME CODE
  38.525 +		if ((movieInfo.header.optionFlags & MOVIE_SETTING_USEBIOSFILE) != 0)
  38.526 +			checksum = utilCalcBIOSChecksum(bios, 4);  // GBA BIOS CHECKSUM
  38.527 +		else
  38.528 +			checksum = 0;
  38.529 +		crc = rom[0xbd]; // GBA ROM CRC
  38.530 +	}
  38.531 +	else // non-GBA
  38.532 +	{
  38.533 +		extern u8 *gbRom;
  38.534 +		memcpy(romTitle, &gbRom[0x134], 12); // GB TITLE (note this can be 15 but is truncated to 12)
  38.535 +		romGameCode = (uint32)gbRom[0x146]; // GB ROM UNIT CODE
  38.536 +
  38.537 +		checksum = (gbRom[0x14e] << 8) | gbRom[0x14f]; // GB ROM CHECKSUM, read from big-endian
  38.538 +		crc		 = gbRom[0x14d]; // GB ROM CRC
  38.539 +	}
  38.540 +}
  38.541 +
  38.542 +#ifdef SDL
  38.543 +static void GetBatterySaveName(char *buffer)
  38.544 +{
  38.545 +	extern char batteryDir[2048], filename[2048];     // from SDL.cpp
  38.546 +	extern char *sdlGetFilename(char *name);     // from SDL.cpp
  38.547 +	if (batteryDir[0])
  38.548 +		sprintf(buffer, "%s/%s.sav", batteryDir, sdlGetFilename(filename));
  38.549 +	else
  38.550 +		sprintf(buffer, "%s.sav", filename);
  38.551 +}
  38.552 +
  38.553 +#endif
  38.554 +
  38.555 +static void SetPlayEmuSettings()
  38.556 +{
  38.557 +	prevEmulatorType = gbEmulatorType;
  38.558 +	gbEmulatorType	 = Movie.header.gbEmulatorType;
  38.559 +
  38.560 +#if (defined(WIN32) && !defined(SDL))
  38.561 +//    theApp.removeIntros   = false;
  38.562 +	theApp.skipBiosFile = (Movie.header.optionFlags & MOVIE_SETTING_SKIPBIOSFILE) != 0;
  38.563 +	theApp.useBiosFile	= (Movie.header.optionFlags & MOVIE_SETTING_USEBIOSFILE) != 0;
  38.564 +#else
  38.565 +	extern int	 saveType, sdlRtcEnable, sdlFlashSize;   // from SDL.cpp
  38.566 +	extern bool8 useBios, skipBios, removeIntros;     // from SDL.cpp
  38.567 +	useBios		 = (Movie.header.optionFlags & MOVIE_SETTING_USEBIOSFILE) != 0;
  38.568 +	skipBios	 = (Movie.header.optionFlags & MOVIE_SETTING_SKIPBIOSFILE) != 0;
  38.569 +	removeIntros = false /*(Movie.header.optionFlags & MOVIE_SETTING_REMOVEINTROS) != 0*/;
  38.570 +#endif
  38.571 +
  38.572 +	extern void SetPrefetchHack(bool);
  38.573 +	if (systemCartridgeType == 0)    // lag disablement applies only to GBA
  38.574 +		SetPrefetchHack((Movie.header.optionFlags & MOVIE_SETTING_LAGHACK) != 0);
  38.575 +
  38.576 +	gbNullInputHackTempEnabled = ((Movie.header.optionFlags & MOVIE_SETTING_GBINPUTHACK) != 0);
  38.577 +
  38.578 +	// some GB/GBC games depend on the sound rate, so just use the highest one
  38.579 +	systemSoundSetQuality(1);
  38.580 +	useOldFrameTiming = false;
  38.581 +
  38.582 +	extern int32 gbDMASpeedVersion;
  38.583 +	if ((Movie.header.optionFlags & MOVIE_SETTING_GBCFF55FIX) != 0)
  38.584 +		gbDMASpeedVersion = 1;
  38.585 +	else
  38.586 +		gbDMASpeedVersion = 0;     // old CGB HDMA5 timing was used
  38.587 +
  38.588 +	extern int32 gbEchoRAMFixOn;
  38.589 +	if ((Movie.header.optionFlags & MOVIE_SETTING_GBECHORAMFIX) != 0)
  38.590 +		gbEchoRAMFixOn = 1;
  38.591 +	else
  38.592 +		gbEchoRAMFixOn = 0;
  38.593 +
  38.594 +#if (defined(WIN32) && !defined(SDL))
  38.595 +	rtcEnable((Movie.header.optionFlags & MOVIE_SETTING_RTCENABLE) != 0);
  38.596 +	theApp.winSaveType	= Movie.header.saveType;
  38.597 +	theApp.winFlashSize = Movie.header.flashSize;
  38.598 +
  38.599 +	prevBorder	   = gbBorderOn;
  38.600 +	prevWinBorder  = theApp.winGbBorderOn;
  38.601 +	prevBorderAuto = gbBorderAutomatic;
  38.602 +	if ((gbEmulatorType == 2 || gbEmulatorType == 5)
  38.603 +	    && !theApp.hideMovieBorder) // games played in SGB mode can have a border
  38.604 +	{
  38.605 +		gbBorderOn = true;
  38.606 +		theApp.winGbBorderOn = true;
  38.607 +		gbBorderAutomatic	 = false;
  38.608 +	}
  38.609 +	else
  38.610 +	{
  38.611 +		gbBorderOn = false;
  38.612 +		theApp.winGbBorderOn = false;
  38.613 +		gbBorderAutomatic	 = false;
  38.614 +		if (theApp.hideMovieBorder)
  38.615 +		{
  38.616 +			theApp.hideMovieBorder = false;
  38.617 +			prevBorder = false;     // it might be expected behaviour that it stays hidden after the movie
  38.618 +		}
  38.619 +	}
  38.620 +	systemGbBorderOn();
  38.621 +#else
  38.622 +	sdlRtcEnable = (Movie.header.optionFlags & MOVIE_SETTING_RTCENABLE) != 0;
  38.623 +	saveType	 = Movie.header.saveType;
  38.624 +	sdlFlashSize = Movie.header.flashSize;
  38.625 +#endif
  38.626 +}
  38.627 +
  38.628 +static void HardResetAndSRAMClear()
  38.629 +{
  38.630 +#if (defined(WIN32) && !defined(SDL))
  38.631 +	winEraseBatteryFile(); // delete the damn SRAM file and keep it from being resurrected from RAM
  38.632 +	MainWnd *temp = ((MainWnd *)theApp.m_pMainWnd);
  38.633 +	if (!temp->winFileRun(true)) // restart running the game
  38.634 +	{
  38.635 +		temp->winFileClose();
  38.636 +	}
  38.637 +#else
  38.638 +	char fname [1024];
  38.639 +	GetBatterySaveName(fname);
  38.640 +	remove(fname);     // delete the damn SRAM file
  38.641 +
  38.642 +	// Henceforth, emuCleanUp means "clear out SRAM"
  38.643 +	//theEmulator.emuCleanUp();     // keep it from being resurrected from RAM <--This is wrong, it'll deallocate all variables --Felipe
  38.644 +
  38.645 +	/// FIXME the correct SDL code to call for a full restart isn't in a function yet
  38.646 +	theEmulator.emuReset(false);
  38.647 +#endif
  38.648 +}
  38.649 +
  38.650 +int VBAMovieOpen(const char *filename, bool8 read_only)
  38.651 +{
  38.652 +	loadingMovie = true;
  38.653 +	uint8 movieReadOnly = read_only ? 1 : 0;
  38.654 +
  38.655 +	FILE * file;
  38.656 +	STREAM stream;
  38.657 +	int	   result;
  38.658 +	int	   fn;
  38.659 +
  38.660 +	char movie_filename[_MAX_PATH];
  38.661 +#ifdef WIN32
  38.662 +	_fullpath(movie_filename, filename, _MAX_PATH);
  38.663 +#else
  38.664 +	// SDL FIXME: convert to fullpath
  38.665 +	strncpy(movie_filename, filename, _MAX_PATH);
  38.666 +	movie_filename[_MAX_PATH - 1] = '\0';
  38.667 +#endif
  38.668 +
  38.669 +	if (movie_filename[0] == '\0')
  38.670 +	{ loadingMovie = false; return MOVIE_FILE_NOT_FOUND; }
  38.671 +
  38.672 +	if (!emulating)
  38.673 +	{ loadingMovie = false; return MOVIE_UNKNOWN_ERROR; }
  38.674 +
  38.675 +//	bool alreadyOpen = (Movie.file != NULL && _stricmp(movie_filename, Movie.filename) == 0);
  38.676 +
  38.677 +//	if (alreadyOpen)
  38.678 +	change_state(MOVIE_STATE_NONE);     // have to stop current movie before trying to re-open it
  38.679 +
  38.680 +	if (!(file = fopen(movie_filename, "rb+")))
  38.681 +		if (!(file = fopen(movie_filename, "rb")))
  38.682 +		{ loadingMovie = false; return MOVIE_FILE_NOT_FOUND; }
  38.683 +	//else
  38.684 +	//	movieReadOnly = 2; // we have to open the movie twice, no need to do this both times
  38.685 +
  38.686 +//	if (!alreadyOpen)
  38.687 +//		change_state(MOVIE_STATE_NONE); // stop current movie when we're able to open the other one
  38.688 +//
  38.689 +//	if (!(file = fopen(movie_filename, "rb+")))
  38.690 +//		if(!(file = fopen(movie_filename, "rb")))
  38.691 +//			{loadingMovie = false; return MOVIE_FILE_NOT_FOUND;}
  38.692 +//		else
  38.693 +//			movieReadOnly = 2;
  38.694 +
  38.695 +	// clear out the current movie
  38.696 +	VBAMovieInit();
  38.697 +
  38.698 +	// read header
  38.699 +	if ((result = read_movie_header(file, Movie)) != MOVIE_SUCCESS)
  38.700 +	{
  38.701 +		fclose(file);
  38.702 +		{ loadingMovie = false; return result; }
  38.703 +	}
  38.704 +
  38.705 +	// set emulator settings that make the movie more likely to stay synchronized
  38.706 +	SetPlayEmuSettings();
  38.707 +
  38.708 +//	extern bool systemLoadBIOS();
  38.709 +//	if (!systemLoadBIOS())
  38.710 +//	{ loadingMovie = false; return MOVIE_UNKNOWN_ERROR; }
  38.711 +
  38.712 +	// read the metadata / author info from file
  38.713 +	fread(Movie.authorInfo, 1, MOVIE_METADATA_SIZE, file);
  38.714 +	fn = dup(fileno(file)); // XXX: why does this fail?? it returns -1 but errno == 0
  38.715 +	fclose(file);
  38.716 +
  38.717 +	// apparently this lseek is necessary
  38.718 +	lseek(fn, Movie.header.offset_to_savestate, SEEK_SET);
  38.719 +	if (!(stream = utilGzReopen(fn, "rb")))
  38.720 +		if (!(stream = utilGzOpen(movie_filename, "rb")))
  38.721 +		{ loadingMovie = false; return MOVIE_FILE_NOT_FOUND; }
  38.722 +		else
  38.723 +			fn = dup(fileno(file));
  38.724 +	// in case the above dup failed but opening the file normally doesn't fail
  38.725 +
  38.726 +	if (Movie.header.startFlags & MOVIE_START_FROM_SNAPSHOT)
  38.727 +	{
  38.728 +		// load the snapshot
  38.729 +		result = theEmulator.emuReadStateFromStream(stream) ? MOVIE_SUCCESS : MOVIE_WRONG_FORMAT;
  38.730 +
  38.731 +		// FIXME: Kludge for conversion
  38.732 +		remember_input_state();
  38.733 +	}
  38.734 +	else if (Movie.header.startFlags & MOVIE_START_FROM_SRAM)
  38.735 +	{
  38.736 +		// 'soft' reset:
  38.737 +		theEmulator.emuReset(false);
  38.738 +
  38.739 +		// load the SRAM
  38.740 +		result = theEmulator.emuReadBatteryFromStream(stream) ? MOVIE_SUCCESS : MOVIE_WRONG_FORMAT;
  38.741 +	}
  38.742 +	else
  38.743 +	{
  38.744 +		HardResetAndSRAMClear();
  38.745 +	}
  38.746 +
  38.747 +	utilGzClose(stream);
  38.748 +
  38.749 +	if (result != MOVIE_SUCCESS)
  38.750 +	{ loadingMovie = false; return result; }
  38.751 +
  38.752 +//	if (!(file = fopen(movie_filename, /*read_only ? "rb" :*/ "rb+"))) // want to be able to switch out of read-only later
  38.753 +//	{
  38.754 +//		if(!Movie.readOnly || !(file = fopen(movie_filename, "rb"))) // try read-only if failed
  38.755 +//			return MOVIE_FILE_NOT_FOUND;
  38.756 +//	}
  38.757 +	if (!(file = fopen(movie_filename, "rb+")))
  38.758 +		if (!(file = fopen(movie_filename, "rb")))
  38.759 +		{ loadingMovie = false; return MOVIE_FILE_NOT_FOUND; }
  38.760 +		else
  38.761 +			movieReadOnly = 2;
  38.762 +
  38.763 +	// recalculate length of movie from the file size
  38.764 +	Movie.bytesPerFrame = bytes_per_frame(Movie);
  38.765 +	fseek(file, 0, SEEK_END);
  38.766 +	long fileSize = ftell(file);
  38.767 +	Movie.header.length_frames = (fileSize - Movie.header.offset_to_controller_data) / Movie.bytesPerFrame;
  38.768 +
  38.769 +	if (fseek(file, Movie.header.offset_to_controller_data, SEEK_SET))
  38.770 +	{ fclose(file); loadingMovie = false; return MOVIE_WRONG_FORMAT; }
  38.771 +
  38.772 +	strcpy(Movie.filename, movie_filename);
  38.773 +	Movie.file = file;
  38.774 +	Movie.inputBufferPtr	  = Movie.inputBuffer;
  38.775 +	Movie.currentFrame		  = 0;
  38.776 +	Movie.readOnly			  = movieReadOnly;
  38.777 +	Movie.RecordedThisSession = false;
  38.778 +
  38.779 +	// read controller data
  38.780 +	uint32 to_read = Movie.bytesPerFrame * Movie.header.length_frames;
  38.781 +	reserve_buffer_space(to_read);
  38.782 +	fread(Movie.inputBuffer, 1, to_read, file);
  38.783 +
  38.784 +	change_state(MOVIE_STATE_PLAY);
  38.785 +
  38.786 +	char messageString[64] = "Movie ";
  38.787 +	bool converted		   = false;
  38.788 +	if (autoConvertMovieWhenPlaying)
  38.789 +	{
  38.790 +		int result = VBAMovieConvertCurrent();
  38.791 +		if (result == MOVIE_SUCCESS)
  38.792 +			strcat(messageString, "converted and ");
  38.793 +		else if (result == MOVIE_WRONG_VERSION)
  38.794 +			strcat(messageString, "higher revision ");
  38.795 +	}
  38.796 +
  38.797 +	if (Movie.state == MOVIE_STATE_PLAY)
  38.798 +		strcat(messageString, "replaying ");
  38.799 +	else
  38.800 +		strcat(messageString, "finished ");
  38.801 +	if (Movie.readOnly)
  38.802 +		strcat(messageString, "(read)");
  38.803 +	else
  38.804 +		strcat(messageString, "(edit)");
  38.805 +	systemScreenMessage(messageString);
  38.806 +
  38.807 +	VBAUpdateButtonPressDisplay();
  38.808 +	VBAUpdateFrameCountDisplay();
  38.809 +	systemRefreshScreen();
  38.810 +
  38.811 +	{ loadingMovie = false; return MOVIE_SUCCESS; }
  38.812 +}
  38.813 +
  38.814 +static void SetRecordEmuSettings()
  38.815 +{
  38.816 +	Movie.header.optionFlags = 0;
  38.817 +#if (defined(WIN32) && !defined(SDL))
  38.818 +	if (theApp.useBiosFile)
  38.819 +		Movie.header.optionFlags |= MOVIE_SETTING_USEBIOSFILE;
  38.820 +	if (theApp.skipBiosFile)
  38.821 +		Movie.header.optionFlags |= MOVIE_SETTING_SKIPBIOSFILE;
  38.822 +	if (rtcIsEnabled())
  38.823 +		Movie.header.optionFlags |= MOVIE_SETTING_RTCENABLE;
  38.824 +	Movie.header.saveType  = theApp.winSaveType;
  38.825 +	Movie.header.flashSize = theApp.winFlashSize;
  38.826 +#else
  38.827 +	extern int	 saveType, sdlRtcEnable, sdlFlashSize;   // from SDL.cpp
  38.828 +	extern bool8 useBios, skipBios;     // from SDL.cpp
  38.829 +	if (useBios)
  38.830 +		Movie.header.optionFlags |= MOVIE_SETTING_USEBIOSFILE;
  38.831 +	if (skipBios)
  38.832 +		Movie.header.optionFlags |= MOVIE_SETTING_SKIPBIOSFILE;
  38.833 +	if (sdlRtcEnable)
  38.834 +		Movie.header.optionFlags |= MOVIE_SETTING_RTCENABLE;
  38.835 +	Movie.header.saveType  = saveType;
  38.836 +	Movie.header.flashSize = sdlFlashSize;
  38.837 +#endif
  38.838 +	prevEmulatorType = Movie.header.gbEmulatorType = gbEmulatorType;
  38.839 +
  38.840 +	if (!memLagTempEnabled)
  38.841 +		Movie.header.optionFlags |= MOVIE_SETTING_LAGHACK;
  38.842 +
  38.843 +	if (gbNullInputHackTempEnabled)
  38.844 +		Movie.header.optionFlags |= MOVIE_SETTING_GBINPUTHACK;
  38.845 +
  38.846 +	Movie.header.optionFlags |= MOVIE_SETTING_GBCFF55FIX;
  38.847 +	extern int32 gbDMASpeedVersion;
  38.848 +	gbDMASpeedVersion = 1;
  38.849 +
  38.850 +	Movie.header.optionFlags |= MOVIE_SETTING_GBECHORAMFIX;
  38.851 +	extern int32 gbEchoRAMFixOn;
  38.852 +	gbEchoRAMFixOn = 1;
  38.853 +
  38.854 +	// some GB/GBC games depend on the sound rate, so just use the highest one
  38.855 +	systemSoundSetQuality(1);
  38.856 +
  38.857 +	useOldFrameTiming = false;
  38.858 +
  38.859 +#if (defined(WIN32) && !defined(SDL))
  38.860 +//    theApp.removeIntros   = false;
  38.861 +
  38.862 +	prevBorder	   = gbBorderOn;
  38.863 +	prevWinBorder  = theApp.winGbBorderOn;
  38.864 +	prevBorderAuto = gbBorderAutomatic;
  38.865 +	if (gbEmulatorType == 2 || gbEmulatorType == 5)     // only games played in SGB mode will have a border
  38.866 +	{
  38.867 +		gbBorderOn = true;
  38.868 +		theApp.winGbBorderOn = true;
  38.869 +		gbBorderAutomatic	 = false;
  38.870 +	}
  38.871 +	else
  38.872 +	{
  38.873 +		gbBorderOn = false;
  38.874 +		theApp.winGbBorderOn = false;
  38.875 +		gbBorderAutomatic	 = false;
  38.876 +	}
  38.877 +	systemGbBorderOn();
  38.878 +#else
  38.879 +	/// SDLFIXME
  38.880 +#endif
  38.881 +}
  38.882 +
  38.883 +uint16 VBAMovieGetCurrentInputOf(int controllerNum, bool normalOnly)
  38.884 +{
  38.885 +	if (controllerNum < 0 || controllerNum >= MOVIE_NUM_OF_POSSIBLE_CONTROLLERS)
  38.886 +		return 0;
  38.887 +
  38.888 +	return normalOnly ? (currentButtons[controllerNum] & BUTTON_REGULAR_MASK) : currentButtons[controllerNum];
  38.889 +}
  38.890 +
  38.891 +int VBAMovieCreate(const char *filename, const char *authorInfo, uint8 startFlags, uint8 controllerFlags, uint8 typeFlags)
  38.892 +{
  38.893 +	// make sure at least one controller is enabled
  38.894 +	if ((controllerFlags & MOVIE_CONTROLLERS_ANY_MASK) == 0)
  38.895 +		return MOVIE_WRONG_FORMAT;
  38.896 +
  38.897 +	if (!emulating)
  38.898 +		return MOVIE_UNKNOWN_ERROR;
  38.899 +
  38.900 +	loadingMovie = true;
  38.901 +
  38.902 +	FILE * file;
  38.903 +	STREAM stream;
  38.904 +	int	   fn;
  38.905 +
  38.906 +	char movie_filename [_MAX_PATH];
  38.907 +#ifdef WIN32
  38.908 +	_fullpath(movie_filename, filename, _MAX_PATH);
  38.909 +#else
  38.910 +	// FIXME: convert to fullpath
  38.911 +	strncpy(movie_filename, filename, _MAX_PATH);
  38.912 +	movie_filename[_MAX_PATH - 1] = '\0';
  38.913 +#endif
  38.914 +
  38.915 +	bool alreadyOpen = (Movie.file != NULL && stricmp(movie_filename, Movie.filename) == 0);
  38.916 +
  38.917 +	if (alreadyOpen)
  38.918 +		change_state(MOVIE_STATE_NONE);  // have to stop current movie before trying to re-open it
  38.919 +
  38.920 +	if (movie_filename[0] == '\0')
  38.921 +	{ loadingMovie = false; return MOVIE_FILE_NOT_FOUND; }
  38.922 +
  38.923 +	if (!(file = fopen(movie_filename, "wb")))
  38.924 +	{ loadingMovie = false; return MOVIE_FILE_NOT_FOUND; }
  38.925 +
  38.926 +	if (!alreadyOpen)
  38.927 +		change_state(MOVIE_STATE_NONE);  // stop current movie when we're able to open the other one
  38.928 +
  38.929 +	// clear out the current movie
  38.930 +	VBAMovieInit();
  38.931 +
  38.932 +	// fill in the movie's header
  38.933 +	Movie.header.uid   = (uint32)time(NULL);
  38.934 +	Movie.header.magic = VBM_MAGIC;
  38.935 +	Movie.header.version		 = VBM_VERSION;
  38.936 +	Movie.header.rerecord_count	 = 0;
  38.937 +	Movie.header.length_frames	 = 0;
  38.938 +	Movie.header.startFlags		 = startFlags;
  38.939 +	Movie.header.controllerFlags = controllerFlags;
  38.940 +	Movie.header.typeFlags		 = typeFlags;
  38.941 +	Movie.header.minorVersion	 = VBM_REVISION;
  38.942 +
  38.943 +	// set emulator settings that make the movie more likely to stay synchronized when it's later played back
  38.944 +	SetRecordEmuSettings();
  38.945 +
  38.946 +	// set ROM and BIOS checksums and stuff
  38.947 +	VBAMovieGetRomInfo(Movie, Movie.header.romTitle, Movie.header.romGameCode, Movie.header.romOrBiosChecksum, Movie.header.romCRC);
  38.948 +
  38.949 +	// write the header to file
  38.950 +	write_movie_header(file, Movie);
  38.951 +
  38.952 +	// copy over the metadata / author info
  38.953 +	VBAMovieSetMetadata(authorInfo);
  38.954 +
  38.955 +	// write the metadata / author info to file
  38.956 +	fwrite(Movie.authorInfo, 1, sizeof(char) * MOVIE_METADATA_SIZE, file);
  38.957 +
  38.958 +	// write snapshot or SRAM if applicable
  38.959 +	if (Movie.header.startFlags & MOVIE_START_FROM_SNAPSHOT
  38.960 +	    || Movie.header.startFlags & MOVIE_START_FROM_SRAM)
  38.961 +	{
  38.962 +		Movie.header.offset_to_savestate = (uint32)ftell(file);
  38.963 +
  38.964 +		// close the file and reopen it as a stream:
  38.965 +
  38.966 +		fn = dup(fileno(file));
  38.967 +		fclose(file);
  38.968 +
  38.969 +		if (!(stream = utilGzReopen(fn, "ab"))) // append mode to start at end, no seek necessary
  38.970 +		{ loadingMovie = false; return MOVIE_FILE_NOT_FOUND; }
  38.971 +
  38.972 +		// write the save data:
  38.973 +		if (Movie.header.startFlags & MOVIE_START_FROM_SNAPSHOT)
  38.974 +		{
  38.975 +			// save snapshot
  38.976 +			if (!theEmulator.emuWriteStateToStream(stream))
  38.977 +			{
  38.978 +				utilGzClose(stream);
  38.979 +				{ loadingMovie = false; return MOVIE_UNKNOWN_ERROR; }
  38.980 +			}
  38.981 +		}
  38.982 +		else if (Movie.header.startFlags & MOVIE_START_FROM_SRAM)
  38.983 +		{
  38.984 +			// save SRAM
  38.985 +			if (!theEmulator.emuWriteBatteryToStream(stream))
  38.986 +			{
  38.987 +				utilGzClose(stream);
  38.988 +				{ loadingMovie = false; return MOVIE_UNKNOWN_ERROR; }
  38.989 +			}
  38.990 +
  38.991 +			// 'soft' reset:
  38.992 +			theEmulator.emuReset(false);
  38.993 +		}
  38.994 +
  38.995 +		utilGzClose(stream);
  38.996 +
  38.997 +		// reopen the file and seek back to the end
  38.998 +
  38.999 +		if (!(file = fopen(movie_filename, "rb+")))
 38.1000 +		{ loadingMovie = false; return MOVIE_FILE_NOT_FOUND; }
 38.1001 +
 38.1002 +		fseek(file, 0, SEEK_END);
 38.1003 +	}
 38.1004 +	else // no snapshot or SRAM
 38.1005 +	{
 38.1006 +		HardResetAndSRAMClear();
 38.1007 +	}
 38.1008 +
 38.1009 +	Movie.header.offset_to_controller_data = (uint32)ftell(file);
 38.1010 +
 38.1011 +	strcpy(Movie.filename, movie_filename);
 38.1012 +	Movie.file = file;
 38.1013 +	Movie.bytesPerFrame		  = bytes_per_frame(Movie);
 38.1014 +	Movie.inputBufferPtr	  = Movie.inputBuffer;
 38.1015 +	Movie.currentFrame		  = 0;
 38.1016 +	Movie.readOnly			  = false;
 38.1017 +	Movie.RecordedThisSession = true;
 38.1018 +
 38.1019 +	change_state(MOVIE_STATE_RECORD);
 38.1020 +
 38.1021 +	systemScreenMessage("Recording movie...");
 38.1022 +	{ loadingMovie = false; return MOVIE_SUCCESS; }
 38.1023 +}
 38.1024 +
 38.1025 +void VBAUpdateButtonPressDisplay()
 38.1026 +{
 38.1027 +	uint32 keys = currentButtons[0] & BUTTON_REGULAR_RECORDING_MASK;
 38.1028 +
 38.1029 +	const static char KeyMap[]	 =  { 'A', 'B', 's', 'S', '>', '<', '^', 'v', 'R', 'L', '!', '?', '{', '}', 'v', '^' };
 38.1030 +	const static int  KeyOrder[] = { 5, 6, 4, 7, 0, 1, 9, 8, 3, 2, 12, 15, 13, 14, 11, 10 }; // < ^ > v   A B  L R  S s  { = } _
 38.1031 +	                                                                                         // ? !
 38.1032 +	char buffer[256];
 38.1033 +	sprintf(buffer, "                    ");
 38.1034 +
 38.1035 +#ifndef WIN32
 38.1036 +	// don't bother color-coding autofire and such
 38.1037 +	int i;
 38.1038 +	for (i = 0; i < 15; i++)
 38.1039 +	{
 38.1040 +		int j	 = KeyOrder[i];
 38.1041 +		int mask = (1 << (j));
 38.1042 +		buffer[strlen("    ") + i] = ((keys & mask) != 0) ? KeyMap[j] : ' ';
 38.1043 +	}
 38.1044 +
 38.1045 +	systemScreenMessage(buffer, 2, -1);
 38.1046 +#else
 38.1047 +	const bool eraseAll		= !theApp.inputDisplay;
 38.1048 +	uint32	   autoHeldKeys = eraseAll ? 0 : theApp.autoHold & BUTTON_REGULAR_RECORDING_MASK;
 38.1049 +	uint32	   autoFireKeys = eraseAll ? 0 : (theApp.autoFire | theApp.autoFire2) & BUTTON_REGULAR_RECORDING_MASK;
 38.1050 +	uint32	   pressedKeys	= eraseAll ? 0 : keys;
 38.1051 +
 38.1052 +	char colorList[64];
 38.1053 +	memset(colorList, 1, strlen(buffer));
 38.1054 +
 38.1055 +	if (!eraseAll)
 38.1056 +	{
 38.1057 +		for (int i = 0; i < 15; i++)
 38.1058 +		{
 38.1059 +			const int  j		 = KeyOrder[i];
 38.1060 +			const int  mask		 = (1 << (j));
 38.1061 +			bool	   pressed	 = (pressedKeys  & mask) != 0;
 38.1062 +			const bool autoHeld	 = (autoHeldKeys & mask) != 0;
 38.1063 +			const bool autoFired = (autoFireKeys & mask) != 0;
 38.1064 +			const bool erased	 = (lastKeys & mask) != 0 && (!pressed && !autoHeld && !autoFired);
 38.1065 +			extern int textMethod;
 38.1066 +			if (textMethod != 2 && (autoHeld || (autoFired && !pressed) || erased))
 38.1067 +			{
 38.1068 +				int colorNum = 1;     // default is white
 38.1069 +				if (autoHeld)
 38.1070 +					colorNum += (pressed ? 2 : 1);     // yellow if pressed, red if not
 38.1071 +				else if (autoFired)
 38.1072 +					colorNum += 5;     // blue if autofired and not currently pressed
 38.1073 +				else if (erased)
 38.1074 +					colorNum += 8;     // black on black
 38.1075 +
 38.1076 +				colorList[strlen("    ") + i] = colorNum;
 38.1077 +				pressed = true;
 38.1078 +			}
 38.1079 +			buffer[strlen("    ") + i] = pressed ? KeyMap[j] : ' ';
 38.1080 +		}
 38.1081 +	}
 38.1082 +
 38.1083 +	lastKeys  = currentButtons[0];
 38.1084 +	lastKeys |= theApp.autoHold & BUTTON_REGULAR_RECORDING_MASK;
 38.1085 +	lastKeys |= (theApp.autoFire | theApp.autoFire2) & BUTTON_REGULAR_RECORDING_MASK;
 38.1086 +
 38.1087 +	systemScreenMessage(buffer, 2, -1, colorList);
 38.1088 +#endif
 38.1089 +}
 38.1090 +
 38.1091 +void VBAUpdateFrameCountDisplay()
 38.1092 +{
 38.1093 +	const int MAGICAL_NUMBER = 64;  // FIXME: this won't do any better, but only to remind you of sz issues
 38.1094 +	char	  frameDisplayString[MAGICAL_NUMBER];
 38.1095 +	char	  lagFrameDisplayString[MAGICAL_NUMBER];
 38.1096 +	char      extraCountDisplayString[MAGICAL_NUMBER];
 38.1097 +
 38.1098 +#if (defined(WIN32) && !defined(SDL))
 38.1099 +	if (theApp.frameCounter)
 38.1100 +#else
 38.1101 +	/// SDL FIXME
 38.1102 +#endif
 38.1103 +	{
 38.1104 +		switch (Movie.state)
 38.1105 +		{
 38.1106 +		case MOVIE_STATE_PLAY:
 38.1107 +		case MOVIE_STATE_END:
 38.1108 +		{
 38.1109 +			sprintf(frameDisplayString, "%d / %d", Movie.currentFrame, Movie.header.length_frames);
 38.1110 +			if (!Movie.readOnly)
 38.1111 +				strcat(frameDisplayString, " (edit)");
 38.1112 +			break;
 38.1113 +		}
 38.1114 +		case MOVIE_STATE_RECORD:
 38.1115 +		{
 38.1116 +			sprintf(frameDisplayString, "%d (record)", Movie.currentFrame);
 38.1117 +			break;
 38.1118 +		}
 38.1119 +		default:
 38.1120 +		{
 38.1121 +			sprintf(frameDisplayString, "%d (no movie)", systemCounters.frameCount);
 38.1122 +			break;
 38.1123 +		}
 38.1124 +		}
 38.1125 +
 38.1126 +#if (defined(WIN32) && !defined(SDL))
 38.1127 +		if (theApp.lagCounter)
 38.1128 +#else
 38.1129 +		/// SDL FIXME
 38.1130 +#endif
 38.1131 +		{
 38.1132 +//			sprintf(lagFrameDisplayString, " %c %d", systemCounters.laggedLast ? '*' : '|', systemCounters.lagCount);
 38.1133 +			sprintf(lagFrameDisplayString, " | %d%s", systemCounters.lagCount, systemCounters.laggedLast ? " *" : "");
 38.1134 +			strcat(frameDisplayString, lagFrameDisplayString);
 38.1135 +		}
 38.1136 +
 38.1137 +#if (defined(WIN32) && !defined(SDL))
 38.1138 +		if (theApp.extraCounter)
 38.1139 +#else
 38.1140 +		/// SDL FIXME
 38.1141 +#endif
 38.1142 +		{
 38.1143 +			sprintf(extraCountDisplayString, " | %d", systemCounters.frameCount - systemCounters.extraCount);
 38.1144 +			strcat(frameDisplayString, extraCountDisplayString);
 38.1145 +		}
 38.1146 +	}
 38.1147 +#if (defined(WIN32) && !defined(SDL))
 38.1148 +	else
 38.1149 +	{
 38.1150 +		frameDisplayString[0] = '\0';
 38.1151 +	}
 38.1152 +#else
 38.1153 +	/// SDL FIXME
 38.1154 +#endif
 38.1155 +	systemScreenMessage(frameDisplayString, 1, -1);
 38.1156 +}
 38.1157 +
 38.1158 +// this function should only be called once every frame
 38.1159 +void VBAMovieUpdateState()
 38.1160 +{
 38.1161 +	++Movie.currentFrame;
 38.1162 +
 38.1163 +	if (Movie.state == MOVIE_STATE_PLAY)
 38.1164 +	{
 38.1165 +		Movie.inputBufferPtr += Movie.bytesPerFrame;
 38.1166 +		if (Movie.currentFrame >= Movie.header.length_frames)
 38.1167 +		{
 38.1168 +			// the movie ends anyway; what to do next depends on the settings
 38.1169 +			change_state(MOVIE_STATE_END);
 38.1170 +		}
 38.1171 +	}
 38.1172 +	else if (Movie.state == MOVIE_STATE_RECORD)
 38.1173 +	{
 38.1174 +		// use first fseek?
 38.1175 +		fwrite(Movie.inputBufferPtr, 1, Movie.bytesPerFrame, Movie.file);
 38.1176 +		Movie.header.length_frames = Movie.currentFrame;
 38.1177 +		Movie.inputBufferPtr	 += Movie.bytesPerFrame;
 38.1178 +		Movie.RecordedThisSession = true;
 38.1179 +		flush_movie_header();
 38.1180 +	}
 38.1181 +	else if (Movie.state == MOVIE_STATE_END)
 38.1182 +	{
 38.1183 +		change_state(MOVIE_STATE_END);
 38.1184 +	}
 38.1185 +}
 38.1186 +
 38.1187 +void VBAMovieRead(int i, bool /*sensor*/)
 38.1188 +{
 38.1189 +	if (Movie.state != MOVIE_STATE_PLAY)
 38.1190 +		return;
 38.1191 +
 38.1192 +	if (i < 0 || i >= MOVIE_NUM_OF_POSSIBLE_CONTROLLERS)
 38.1193 +		return;      // not a controller we're recognizing
 38.1194 +
 38.1195 +	if (Movie.header.controllerFlags & MOVIE_CONTROLLER(i))
 38.1196 +	{
 38.1197 +		currentButtons[i] = Read16(Movie.inputBufferPtr + CONTROLLER_DATA_SIZE * i);
 38.1198 +	}
 38.1199 +	else
 38.1200 +	{
 38.1201 +		currentButtons[i] = 0;        // pretend the controller is disconnected
 38.1202 +	}
 38.1203 +
 38.1204 +	if ((currentButtons[i] & BUTTON_MASK_NEW_RESET) != 0)
 38.1205 +		resetSignaled = true;
 38.1206 +}
 38.1207 +
 38.1208 +void VBAMovieWrite(int i, bool /*sensor*/)
 38.1209 +{
 38.1210 +	if (Movie.state != MOVIE_STATE_RECORD)
 38.1211 +		return;
 38.1212 +
 38.1213 +	if (i < 0 || i >= MOVIE_NUM_OF_POSSIBLE_CONTROLLERS)
 38.1214 +		return;      // not a controller we're recognizing
 38.1215 +
 38.1216 +	reserve_buffer_space((uint32)((Movie.inputBufferPtr - Movie.inputBuffer) + Movie.bytesPerFrame));
 38.1217 +
 38.1218 +	if (Movie.header.controllerFlags & MOVIE_CONTROLLER(i))
 38.1219 +	{
 38.1220 +		// get the current controller data
 38.1221 +		uint16 buttonData = currentButtons[i];
 38.1222 +
 38.1223 +		// mask away the irrelevent bits
 38.1224 +		buttonData &= BUTTON_REGULAR_MASK | BUTTON_MOTION_MASK;
 38.1225 +
 38.1226 +		// soft-reset "button" for 1 frame if the game is reset while recording
 38.1227 +		if (resetSignaled)
 38.1228 +		{
 38.1229 +			buttonData |= BUTTON_MASK_NEW_RESET;
 38.1230 +		}
 38.1231 +
 38.1232 +		// backward compatibility kludge
 38.1233 +		if (resetSignaledLast)
 38.1234 +		{
 38.1235 +			buttonData |= BUTTON_MASK_OLD_RESET;
 38.1236 +		}
 38.1237 +
 38.1238 +		Write16(buttonData, Movie.inputBufferPtr + CONTROLLER_DATA_SIZE * i);
 38.1239 +
 38.1240 +		// and for display
 38.1241 +		currentButtons[i] = buttonData;
 38.1242 +	}
 38.1243 +	else
 38.1244 +	{
 38.1245 +		// pretend the controller is disconnected (otherwise input it gives could cause desync since we're not writing it to the
 38.1246 +		// movie)
 38.1247 +		currentButtons[i] = 0;
 38.1248 +	}
 38.1249 +}
 38.1250 +
 38.1251 +void VBAMovieStop(bool8 suppress_message)
 38.1252 +{
 38.1253 +	if (Movie.state != MOVIE_STATE_NONE)
 38.1254 +	{
 38.1255 +		change_state(MOVIE_STATE_NONE);
 38.1256 +		if (!suppress_message)
 38.1257 +			systemScreenMessage("Movie stop");
 38.1258 +	}
 38.1259 +}
 38.1260 +
 38.1261 +int VBAMovieGetInfo(const char *filename, SMovie *info)
 38.1262 +{
 38.1263 +	assert(info != NULL);
 38.1264 +	if (info == NULL)
 38.1265 +		return -1;
 38.1266 +
 38.1267 +	FILE *	file;
 38.1268 +	int		result;
 38.1269 +	SMovie &local_movie = *info;
 38.1270 +
 38.1271 +	memset(info, 0, sizeof(*info));
 38.1272 +	if (filename[0] == '\0')
 38.1273 +		return MOVIE_FILE_NOT_FOUND;
 38.1274 +	if (!(file = fopen(filename, "rb")))
 38.1275 +		return MOVIE_FILE_NOT_FOUND;
 38.1276 +
 38.1277 +	// read header
 38.1278 +	if ((result = (read_movie_header(file, local_movie))) != MOVIE_SUCCESS)
 38.1279 +	{
 38.1280 +		fclose(file);
 38.1281 +		return result;
 38.1282 +	}
 38.1283 +
 38.1284 +	// read the metadata / author info from file
 38.1285 +	fread(local_movie.authorInfo, 1, sizeof(char) * MOVIE_METADATA_SIZE, file);
 38.1286 +
 38.1287 +	strncpy(local_movie.filename, filename, _MAX_PATH);
 38.1288 +	local_movie.filename[_MAX_PATH - 1] = '\0';
 38.1289 +
 38.1290 +	if (Movie.file != NULL && stricmp(local_movie.filename, Movie.filename) == 0) // alreadyOpen
 38.1291 +	{
 38.1292 +		local_movie.bytesPerFrame		 = Movie.bytesPerFrame;
 38.1293 +		local_movie.header.length_frames = Movie.header.length_frames;
 38.1294 +	}
 38.1295 +	else
 38.1296 +	{
 38.1297 +		// recalculate length of movie from the file size
 38.1298 +		local_movie.bytesPerFrame = bytes_per_frame(local_movie);
 38.1299 +		fseek(file, 0, SEEK_END);
 38.1300 +		int fileSize = ftell(file);
 38.1301 +		local_movie.header.length_frames =
 38.1302 +		    (fileSize - local_movie.header.offset_to_controller_data) / local_movie.bytesPerFrame;
 38.1303 +	}
 38.1304 +
 38.1305 +	fclose(file);
 38.1306 +
 38.1307 +	if (access(filename, W_OK))
 38.1308 +		info->readOnly = true;
 38.1309 +
 38.1310 +	return MOVIE_SUCCESS;
 38.1311 +}
 38.1312 +
 38.1313 +bool8 VBAMovieActive()
 38.1314 +{
 38.1315 +	return (Movie.state != MOVIE_STATE_NONE);
 38.1316 +}
 38.1317 +
 38.1318 +bool8 VBAMovieLoading()
 38.1319 +{
 38.1320 +	return loadingMovie;
 38.1321 +}
 38.1322 +
 38.1323 +bool8 VBAMoviePlaying()
 38.1324 +{
 38.1325 +	return (Movie.state == MOVIE_STATE_PLAY);
 38.1326 +}
 38.1327 +
 38.1328 +bool8 VBAMovieRecording()
 38.1329 +{
 38.1330 +	return (Movie.state == MOVIE_STATE_RECORD);
 38.1331 +}
 38.1332 +
 38.1333 +bool8 VBAMovieReadOnly()
 38.1334 +{
 38.1335 +	if (!VBAMovieActive())
 38.1336 +		return false;
 38.1337 +
 38.1338 +	return Movie.readOnly;
 38.1339 +}
 38.1340 +
 38.1341 +void VBAMovieToggleReadOnly()
 38.1342 +{
 38.1343 +	if (!VBAMovieActive())
 38.1344 +		return;
 38.1345 +
 38.1346 +	if (Movie.readOnly != 2)
 38.1347 +	{
 38.1348 +		Movie.readOnly = !Movie.readOnly;
 38.1349 +
 38.1350 +		systemScreenMessage(Movie.readOnly ? "Movie now read-only" : "Movie now editable");
 38.1351 +	}
 38.1352 +	else
 38.1353 +	{
 38.1354 +		systemScreenMessage("Can't toggle read-only movie");
 38.1355 +	}
 38.1356 +}
 38.1357 +
 38.1358 +uint32 VBAMovieGetVersion()
 38.1359 +{
 38.1360 +	if (!VBAMovieActive())
 38.1361 +		return 0;
 38.1362 +
 38.1363 +	return Movie.header.version;
 38.1364 +}
 38.1365 +
 38.1366 +uint32 VBAMovieGetMinorVersion()
 38.1367 +{
 38.1368 +	if (!VBAMovieActive())
 38.1369 +		return 0;
 38.1370 +
 38.1371 +	return Movie.header.minorVersion;
 38.1372 +}
 38.1373 +
 38.1374 +uint32 VBAMovieGetId()
 38.1375 +{
 38.1376 +	if (!VBAMovieActive())
 38.1377 +		return 0;
 38.1378 +
 38.1379 +	return Movie.header.uid;
 38.1380 +}
 38.1381 +
 38.1382 +uint32 VBAMovieGetLength()
 38.1383 +{
 38.1384 +	if (!VBAMovieActive())
 38.1385 +		return 0;
 38.1386 +
 38.1387 +	return Movie.header.length_frames;
 38.1388 +}
 38.1389 +
 38.1390 +uint32 VBAMovieGetFrameCounter()
 38.1391 +{
 38.1392 +	if (!VBAMovieActive())
 38.1393 +		return 0;
 38.1394 +
 38.1395 +	return Movie.currentFrame;
 38.1396 +}
 38.1397 +
 38.1398 +uint32 VBAMovieGetRerecordCount()
 38.1399 +{
 38.1400 +	if (!VBAMovieActive())
 38.1401 +		return 0;
 38.1402 +
 38.1403 +	return Movie.header.rerecord_count;
 38.1404 +}
 38.1405 +
 38.1406 +uint32 VBAMovieSetRerecordCount(uint32 newRerecordCount)
 38.1407 +{
 38.1408 +	uint32 oldRerecordCount = 0;
 38.1409 +	if (!VBAMovieActive())
 38.1410 +		return 0;
 38.1411 +
 38.1412 +	oldRerecordCount = Movie.header.rerecord_count;
 38.1413 +	Movie.header.rerecord_count = newRerecordCount;
 38.1414 +	return oldRerecordCount;
 38.1415 +}
 38.1416 +
 38.1417 +std::string VBAMovieGetAuthorInfo()
 38.1418 +{
 38.1419 +	if (!VBAMovieActive())
 38.1420 +		return "";
 38.1421 +
 38.1422 +	return Movie.authorInfo;
 38.1423 +}
 38.1424 +
 38.1425 +std::string VBAMovieGetFilename()
 38.1426 +{
 38.1427 +	if (!VBAMovieActive())
 38.1428 +		return "";
 38.1429 +
 38.1430 +	return Movie.filename;
 38.1431 +}
 38.1432 +
 38.1433 +void VBAMovieFreeze(uint8 * *buf, uint32 *size)
 38.1434 +{
 38.1435 +	// sanity check
 38.1436 +	if (!VBAMovieActive())
 38.1437 +	{
 38.1438 +		return;
 38.1439 +	}
 38.1440 +
 38.1441 +	*buf  = NULL;
 38.1442 +	*size = 0;
 38.1443 +
 38.1444 +	// compute size needed for the buffer
 38.1445 +	// room for header.uid, currentFrame, and header.length_frames
 38.1446 +	uint32 size_needed = sizeof(Movie.header.uid) + sizeof(Movie.currentFrame) + sizeof(Movie.header.length_frames);
 38.1447 +	size_needed += (uint32)(Movie.bytesPerFrame * Movie.header.length_frames);
 38.1448 +	*buf		 = new uint8[size_needed];
 38.1449 +	*size		 = size_needed;
 38.1450 +
 38.1451 +	uint8 *ptr = *buf;
 38.1452 +	if (!ptr)
 38.1453 +	{
 38.1454 +		return;
 38.1455 +	}
 38.1456 +
 38.1457 +	Push32(Movie.header.uid, ptr);
 38.1458 +	Push32(Movie.currentFrame, ptr);
 38.1459 +	Push32(Movie.header.length_frames - 1, ptr);   // HACK: shorten the length by 1 for backward compatibility
 38.1460 +
 38.1461 +	memcpy(ptr, Movie.inputBuffer, Movie.bytesPerFrame * Movie.header.length_frames);
 38.1462 +}
 38.1463 +
 38.1464 +int VBAMovieUnfreeze(const uint8 *buf, uint32 size)
 38.1465 +{
 38.1466 +	// sanity check
 38.1467 +	if (!VBAMovieActive())
 38.1468 +	{
 38.1469 +		return MOVIE_NOT_FROM_A_MOVIE;
 38.1470 +	}
 38.1471 +
 38.1472 +	const uint8 *ptr = buf;
 38.1473 +	if (size < sizeof(Movie.header.uid) + sizeof(Movie.currentFrame) + sizeof(Movie.header.length_frames))
 38.1474 +	{
 38.1475 +		return MOVIE_WRONG_FORMAT;
 38.1476 +	}
 38.1477 +
 38.1478 +	uint32 movie_id		 = Pop32(ptr);
 38.1479 +	uint32 current_frame = Pop32(ptr);
 38.1480 +	uint32 end_frame	 = Pop32(ptr) + 1;     // HACK: restore the length for backward compatibility
 38.1481 +	uint32 space_needed	 = Movie.bytesPerFrame * end_frame;
 38.1482 +
 38.1483 +	if (movie_id != Movie.header.uid)
 38.1484 +		return MOVIE_NOT_FROM_THIS_MOVIE;
 38.1485 +
 38.1486 +	if (space_needed > size)
 38.1487 +		return MOVIE_WRONG_FORMAT;
 38.1488 +
 38.1489 +	if (Movie.readOnly)
 38.1490 +	{
 38.1491 +		// here, we are going to keep the input data from the movie file
 38.1492 +		// and simply rewind to the currentFrame pointer
 38.1493 +		// this will cause a desync if the savestate is not in sync // <-- NOT ANYMORE
 38.1494 +		// with the on-disk recording data, but it's easily solved
 38.1495 +		// by loading another savestate or playing the movie from the beginning
 38.1496 +
 38.1497 +		// don't allow loading a state inconsistent with the current movie
 38.1498 +		uint32 length_history = min(current_frame, Movie.header.length_frames);
 38.1499 +		if (end_frame < length_history)
 38.1500 +			return MOVIE_SNAPSHOT_INCONSISTENT;
 38.1501 +
 38.1502 +		uint32 space_shared = Movie.bytesPerFrame * length_history;
 38.1503 +		if (memcmp(Movie.inputBuffer, ptr, space_shared))
 38.1504 +			return MOVIE_SNAPSHOT_INCONSISTENT;
 38.1505 +
 38.1506 +		Movie.currentFrame	 = current_frame;
 38.1507 +		Movie.inputBufferPtr = Movie.inputBuffer + Movie.bytesPerFrame * min(current_frame, Movie.header.length_frames);
 38.1508 +	}
 38.1509 +	else
 38.1510 +	{
 38.1511 +		// here, we are going to take the input data from the savestate
 38.1512 +		// and make it the input data for the current movie, then continue
 38.1513 +		// writing new input data at the currentFrame pointer
 38.1514 +		Movie.currentFrame		   = current_frame;
 38.1515 +		Movie.header.length_frames = end_frame;
 38.1516 +		if (!VBALuaRerecordCountSkip())
 38.1517 +			++Movie.header.rerecord_count;
 38.1518 +
 38.1519 +		Movie.RecordedThisSession = true;
 38.1520 +
 38.1521 +		// do this before calling reserve_buffer_space()
 38.1522 +		Movie.inputBufferPtr = Movie.inputBuffer + Movie.bytesPerFrame * min(current_frame, Movie.header.length_frames);
 38.1523 +		reserve_buffer_space(space_needed);
 38.1524 +		memcpy(Movie.inputBuffer, ptr, space_needed);
 38.1525 +
 38.1526 +		// for consistency, no auto movie conversion here since we don't auto convert the corresponding savestate
 38.1527 +		flush_movie_header();
 38.1528 +		flush_movie_frames();
 38.1529 +	}
 38.1530 +
 38.1531 +	change_state(MOVIE_STATE_PLAY);	// check for movie end
 38.1532 +
 38.1533 +	// necessary!
 38.1534 +	resetSignaled	  = false;
 38.1535 +	resetSignaledLast = false;
 38.1536 +
 38.1537 +	// necessary to check if there's a reset signal at the previous frame
 38.1538 +	if (current_frame > 0)
 38.1539 +	{
 38.1540 +		const u8 NEW_RESET = u8(BUTTON_MASK_NEW_RESET >> 8);
 38.1541 +		for (int i = 0; i < MOVIE_NUM_OF_POSSIBLE_CONTROLLERS; ++i)
 38.1542 +		{
 38.1543 +			if ((Movie.header.controllerFlags & MOVIE_CONTROLLER(i)) && (*(Movie.inputBufferPtr+1- Movie.bytesPerFrame) & NEW_RESET))
 38.1544 +			{
 38.1545 +				resetSignaledLast = true;
 38.1546 +				break;
 38.1547 +			}
 38.1548 +		}
 38.1549 +	}
 38.1550 +
 38.1551 +	return MOVIE_SUCCESS;
 38.1552 +}
 38.1553 +
 38.1554 +bool VBAMovieEnded()
 38.1555 +{
 38.1556 +	return (Movie.state == MOVIE_STATE_END);
 38.1557 +//	return (Movie.state != MOVIE_STATE_NONE && Movie.currentFrame >= Movie.header.length_frames);
 38.1558 +}
 38.1559 +
 38.1560 +bool VBAMovieAllowsRerecording()
 38.1561 +{
 38.1562 +	bool allows = (Movie.state != MOVIE_STATE_NONE) && (Movie.currentFrame <= Movie.header.length_frames);
 38.1563 +	return /*!VBAMovieReadOnly() &&*/ allows;
 38.1564 +}
 38.1565 +
 38.1566 +bool VBAMovieSwitchToPlaying()
 38.1567 +{
 38.1568 +	if (!VBAMovieActive())
 38.1569 +		return false;
 38.1570 +
 38.1571 +	if (!Movie.readOnly)
 38.1572 +	{
 38.1573 +		VBAMovieToggleReadOnly();
 38.1574 +	}
 38.1575 +
 38.1576 +	change_state(MOVIE_STATE_PLAY);
 38.1577 +	if (Movie.state == MOVIE_STATE_PLAY)
 38.1578 +		systemScreenMessage("Movie replay (continue)");
 38.1579 +	else
 38.1580 +		systemScreenMessage("Movie end");
 38.1581 +
 38.1582 +	return true;
 38.1583 +}
 38.1584 +
 38.1585 +bool VBAMovieSwitchToRecording()
 38.1586 +{
 38.1587 +	if (!VBAMovieAllowsRerecording())
 38.1588 +		return false;
 38.1589 +
 38.1590 +	if (Movie.readOnly)
 38.1591 +	{
 38.1592 +		VBAMovieToggleReadOnly();
 38.1593 +	}
 38.1594 +
 38.1595 +	if (!VBALuaRerecordCountSkip())
 38.1596 +		++Movie.header.rerecord_count;
 38.1597 +
 38.1598 +	change_state(MOVIE_STATE_RECORD);
 38.1599 +	systemScreenMessage("Movie re-record");
 38.1600 +
 38.1601 +	//truncate_movie(Movie.currentFrame);
 38.1602 +
 38.1603 +	return true;
 38.1604 +}
 38.1605 +
 38.1606 +uint32 VBAMovieGetState()
 38.1607 +{
 38.1608 +	// ?
 38.1609 +	if (!VBAMovieActive())
 38.1610 +		return MOVIE_STATE_NONE;
 38.1611 +
 38.1612 +	return Movie.state;
 38.1613 +}
 38.1614 +
 38.1615 +void VBAMovieSignalReset()
 38.1616 +{
 38.1617 +	if (VBAMovieActive())
 38.1618 +		resetSignaled = true;
 38.1619 +}
 38.1620 +
 38.1621 +void VBAMovieResetIfRequested()
 38.1622 +{
 38.1623 +	if (resetSignaled)
 38.1624 +	{
 38.1625 +		theEmulator.emuReset(false);
 38.1626 +		resetSignaled	  = false;
 38.1627 +		resetSignaledLast = true;
 38.1628 +	}
 38.1629 +	else
 38.1630 +	{
 38.1631 +		resetSignaledLast = false;
 38.1632 +	}
 38.1633 +}
 38.1634 +
 38.1635 +void VBAMovieSetMetadata(const char *info)
 38.1636 +{
 38.1637 +	if (!memcmp(Movie.authorInfo, info, MOVIE_METADATA_SIZE))
 38.1638 +		return;
 38.1639 +
 38.1640 +	memcpy(Movie.authorInfo, info, MOVIE_METADATA_SIZE); // strncpy would omit post-0 bytes
 38.1641 +	Movie.authorInfo[MOVIE_METADATA_SIZE - 1] = '\0';
 38.1642 +
 38.1643 +	if (Movie.file)
 38.1644 +	{
 38.1645 +		// (over-)write the header
 38.1646 +		fseek(Movie.file, 0, SEEK_SET);
 38.1647 +		write_movie_header(Movie.file, Movie);
 38.1648 +
 38.1649 +		// write the metadata / author info to file
 38.1650 +		fwrite(Movie.authorInfo, 1, sizeof(char) * MOVIE_METADATA_SIZE, Movie.file);
 38.1651 +
 38.1652 +		fflush(Movie.file);
 38.1653 +	}
 38.1654 +}
 38.1655 +
 38.1656 +void VBAMovieRestart()
 38.1657 +{
 38.1658 +	if (VBAMovieActive())
 38.1659 +	{
 38.1660 +		systemSoundClearBuffer();
 38.1661 +
 38.1662 +		bool8 modified = Movie.RecordedThisSession;
 38.1663 +
 38.1664 +		VBAMovieStop(true);
 38.1665 +
 38.1666 +		char movieName [_MAX_PATH];
 38.1667 +		strncpy(movieName, Movie.filename, _MAX_PATH);
 38.1668 +		movieName[_MAX_PATH - 1] = '\0';
 38.1669 +		VBAMovieOpen(movieName, Movie.readOnly); // can't just pass in Movie.filename, since VBAMovieOpen clears out Movie's
 38.1670 +		                                         // variables
 38.1671 +
 38.1672 +		Movie.RecordedThisSession = modified;
 38.1673 +
 38.1674 +		systemScreenMessage("Movie replay (restart)");
 38.1675 +	}
 38.1676 +}
 38.1677 +
 38.1678 +int VBAMovieGetPauseAt()
 38.1679 +{
 38.1680 +	return Movie.pauseFrame;
 38.1681 +}
 38.1682 +
 38.1683 +void VBAMovieSetPauseAt(int at)
 38.1684 +{
 38.1685 +	Movie.pauseFrame = at;
 38.1686 +}
 38.1687 +
 38.1688 +///////////////////////
 38.1689 +// movie tools
 38.1690 +
 38.1691 +// FIXME: is it safe to convert/flush a movie while recording it (considering fseek() problem)?
 38.1692 +int VBAMovieConvertCurrent()
 38.1693 +{
 38.1694 +	if (!VBAMovieActive())
 38.1695 +	{
 38.1696 +		return MOVIE_NOTHING;
 38.1697 +	}
 38.1698 +
 38.1699 +	if (Movie.header.minorVersion > VBM_REVISION)
 38.1700 +	{
 38.1701 +		return MOVIE_WRONG_VERSION;
 38.1702 +	}
 38.1703 +
 38.1704 +	if (Movie.header.minorVersion == VBM_REVISION)
 38.1705 +	{
 38.1706 +		return MOVIE_NOTHING;
 38.1707 +	}
 38.1708 +
 38.1709 +	Movie.header.minorVersion = VBM_REVISION;
 38.1710 +
 38.1711 +	if (Movie.header.length_frames == 0) // this could happen
 38.1712 +	{
 38.1713 +		truncate_movie(0);
 38.1714 +		return MOVIE_SUCCESS;
 38.1715 +	}
 38.1716 +
 38.1717 +	// fix movies recorded from snapshots
 38.1718 +	if (Movie.header.startFlags & MOVIE_START_FROM_SNAPSHOT)
 38.1719 +	{
 38.1720 +		uint8 *firstFramePtr = Movie.inputBuffer;
 38.1721 +		for (int i = 0; i < MOVIE_NUM_OF_POSSIBLE_CONTROLLERS; ++i)
 38.1722 +		{
 38.1723 +			if (Movie.header.controllerFlags & MOVIE_CONTROLLER(i))
 38.1724 +			{
 38.1725 +				Push16(initialInputs[i], firstFramePtr);
 38.1726 +				// note: this is correct since Push16 advances the dest pointer by sizeof u16
 38.1727 +			}
 38.1728 +		}
 38.1729 +	}
 38.1730 +
 38.1731 +	// convert old resets to new ones
 38.1732 +	const u8 OLD_RESET = u8(BUTTON_MASK_OLD_RESET >> 8);
 38.1733 +	const u8 NEW_RESET = u8(BUTTON_MASK_NEW_RESET >> 8);
 38.1734 +	for (int i = 0; i < MOVIE_NUM_OF_POSSIBLE_CONTROLLERS; ++i)
 38.1735 +	{
 38.1736 +		if (Movie.header.controllerFlags & MOVIE_CONTROLLER(i))
 38.1737 +		{
 38.1738 +			uint8 *startPtr = Movie.inputBuffer + sizeof(u16) * i + 1;
 38.1739 +			uint8 *endPtr	= Movie.inputBuffer + Movie.bytesPerFrame * (Movie.header.length_frames - 1);
 38.1740 +			for (; startPtr < endPtr; startPtr += Movie.bytesPerFrame)
 38.1741 +			{
 38.1742 +				if (startPtr[Movie.bytesPerFrame] & OLD_RESET)
 38.1743 +				{
 38.1744 +					startPtr[0] |= NEW_RESET;
 38.1745 +				}
 38.1746 +			}
 38.1747 +		}
 38.1748 +	}
 38.1749 +
 38.1750 +	flush_movie_header();
 38.1751 +	flush_movie_frames();
 38.1752 +	return MOVIE_SUCCESS;
 38.1753 +}
 38.1754 +
 38.1755 +bool VBAMovieTuncateAtCurrentFrame()
 38.1756 +{
 38.1757 +	if (!VBAMovieActive())
 38.1758 +		return false;
 38.1759 +
 38.1760 +	truncate_movie(Movie.currentFrame);
 38.1761 +	change_state(MOVIE_STATE_END);
 38.1762 +	systemScreenMessage("Movie truncated");
 38.1763 +
 38.1764 +	return true;
 38.1765 +}
 38.1766 +
 38.1767 +bool VBAMovieFixHeader()
 38.1768 +{
 38.1769 +	if (!VBAMovieActive())
 38.1770 +		return false;
 38.1771 +
 38.1772 +	flush_movie_header();
 38.1773 +	systemScreenMessage("Movie header fixed");
 38.1774 +	return true;
 38.1775 +}
    39.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.2 +++ b/src/common/movie.h	Sat Mar 03 10:31:27 2012 -0600
    39.3 @@ -0,0 +1,190 @@
    39.4 +#ifndef VBA_MOVIE_H
    39.5 +#define VBA_MOVIE_H
    39.6 +
    39.7 +#if _MSC_VER > 1000
    39.8 +#pragma once
    39.9 +#endif // _MSC_VER > 1000
   39.10 +
   39.11 +#include <ctime>
   39.12 +#include <string>
   39.13 +
   39.14 +#include "../Port.h"
   39.15 +
   39.16 +#define ZLIB
   39.17 +///#ifdef ZLIB
   39.18 +#ifndef WIN32
   39.19 +#include "zlib.h"
   39.20 +#endif
   39.21 +
   39.22 +#ifndef MOVIE_SUCCESS
   39.23 +#  define MOVIE_SUCCESS 1
   39.24 +#  define MOVIE_NOTHING 0
   39.25 +#  define MOVIE_WRONG_FORMAT (-1)
   39.26 +#  define MOVIE_WRONG_VERSION (-2)
   39.27 +#  define MOVIE_FILE_NOT_FOUND (-3)
   39.28 +#  define MOVIE_NOT_FROM_THIS_MOVIE (-4)
   39.29 +#  define MOVIE_NOT_FROM_A_MOVIE (-5)
   39.30 +#  define MOVIE_SNAPSHOT_INCONSISTENT (-6)
   39.31 +#  define MOVIE_UNKNOWN_ERROR (-7)
   39.32 +#endif
   39.33 +
   39.34 +#define VBM_MAGIC (0x1a4D4256) // VBM0x1a
   39.35 +#define VBM_VERSION (1)
   39.36 +#define VBM_HEADER_SIZE (64)
   39.37 +#define CONTROLLER_DATA_SIZE (2)
   39.38 +#define BUFFER_GROWTH_SIZE (4096)
   39.39 +#define MOVIE_METADATA_SIZE (192)
   39.40 +#define MOVIE_METADATA_AUTHOR_SIZE (64)
   39.41 +
   39.42 +// revision 1 uses (?) insted of (!) as reset
   39.43 +#define VBM_REVISION   (1)
   39.44 +
   39.45 +#define MOVIE_START_FROM_SNAPSHOT   (1<<0)
   39.46 +#define MOVIE_START_FROM_SRAM       (1<<1)
   39.47 +
   39.48 +#define MOVIE_CONTROLLER(i)         (1<<(i))
   39.49 +#define MOVIE_CONTROLLERS_ANY_MASK  (MOVIE_CONTROLLER(0)|MOVIE_CONTROLLER(1)|MOVIE_CONTROLLER(2)|MOVIE_CONTROLLER(3))
   39.50 +#define MOVIE_NUM_OF_POSSIBLE_CONTROLLERS   (4)
   39.51 +
   39.52 +#define MOVIE_TYPE_GBA              (1<<0)
   39.53 +#define MOVIE_TYPE_GBC              (1<<1)
   39.54 +#define MOVIE_TYPE_SGB              (1<<2)
   39.55 +
   39.56 +#define MOVIE_SETTING_USEBIOSFILE   (1<<0)
   39.57 +#define MOVIE_SETTING_SKIPBIOSFILE  (1<<1)
   39.58 +#define MOVIE_SETTING_RTCENABLE     (1<<2)
   39.59 +#define MOVIE_SETTING_GBINPUTHACK   (1<<3)
   39.60 +#define MOVIE_SETTING_LAGHACK       (1<<4)
   39.61 +#define MOVIE_SETTING_GBCFF55FIX    (1<<5)
   39.62 +#define MOVIE_SETTING_GBECHORAMFIX  (1<<6)
   39.63 +
   39.64 +#define STREAM gzFile
   39.65 +/*#define READ_STREAM(p,l,s) gzread (s,p,l)
   39.66 + #define WRITE_STREAM(p,l,s) gzwrite (s,p,l)
   39.67 + #define OPEN_STREAM(f,m) gzopen (f,m)
   39.68 + #define REOPEN_STREAM(f,m) gzdopen (f,m)
   39.69 + #define FIND_STREAM(f)	gztell(f)
   39.70 + #define REVERT_STREAM(f,o,s)  gzseek(f,o,s)
   39.71 + #define CLOSE_STREAM(s) gzclose (s)
   39.72 + #else
   39.73 + #define STREAM FILE *
   39.74 + #define READ_STREAM(p,l,s) fread (p,1,l,s)
   39.75 + #define WRITE_STREAM(p,l,s) fwrite (p,1,l,s)
   39.76 + #define OPEN_STREAM(f,m) fopen (f,m)
   39.77 + #define REOPEN_STREAM(f,m) fdopen (f,m)
   39.78 + #define FIND_STREAM(f)	ftell(f)
   39.79 + #define REVERT_STREAM(f,o,s)	 fseek(f,o,s)
   39.80 + #define CLOSE_STREAM(s) fclose (s)
   39.81 + #endif*/
   39.82 +
   39.83 +enum MovieState
   39.84 +{
   39.85 +	MOVIE_STATE_NONE = 0,
   39.86 +	MOVIE_STATE_PLAY,
   39.87 +	MOVIE_STATE_RECORD,
   39.88 +	MOVIE_STATE_END
   39.89 +};
   39.90 +
   39.91 +struct SMovieFileHeader
   39.92 +{
   39.93 +	uint32 magic;       // VBM0x1a
   39.94 +	uint32 version;     // 1
   39.95 +	int32  uid;         // used to match savestates to a particular movie
   39.96 +	uint32 length_frames;
   39.97 +	uint32 rerecord_count;
   39.98 +	uint8  startFlags;
   39.99 +	uint8  controllerFlags;
  39.100 +	uint8  typeFlags;
  39.101 +	uint8  optionFlags;
  39.102 +	uint32 saveType;        // emulator setting value
  39.103 +	uint32 flashSize;       // emulator setting value
  39.104 +	uint32 gbEmulatorType;  // emulator setting value
  39.105 +	char   romTitle [12];
  39.106 +	uint8  minorVersion;	// minor version/revision of the current movie version
  39.107 +	uint8  romCRC;						// the CRC of the ROM used while recording
  39.108 +	uint16 romOrBiosChecksum;			// the Checksum of the ROM used while recording, or a CRC of the BIOS if GBA
  39.109 +	uint32 romGameCode;					// the Game Code of the ROM used while recording, or "\0\0\0\0" if not GBA
  39.110 +	uint32 offset_to_savestate;         // offset to the savestate or SRAM inside file, set to 0 if unused
  39.111 +	uint32 offset_to_controller_data;   // offset to the controller data inside file
  39.112 +};
  39.113 +
  39.114 +struct SMovie
  39.115 +{
  39.116 +	enum   MovieState state;
  39.117 +	char   filename[/*_MAX_PATH*/ 260]; // FIXME: should use a string instead
  39.118 +	FILE*  file;
  39.119 +	uint8  readOnly;
  39.120 +	int32  pauseFrame;	// FIXME: byte size
  39.121 +
  39.122 +	SMovieFileHeader header;
  39.123 +	char  authorInfo[MOVIE_METADATA_SIZE];
  39.124 +
  39.125 +	uint32 currentFrame;    // should == length_frame when recording, and be < length_frames when playing
  39.126 +	uint32 bytesPerFrame;
  39.127 +	uint8* inputBuffer;
  39.128 +	uint32 inputBufferSize;
  39.129 +	uint8* inputBufferPtr;
  39.130 +
  39.131 +	// bool8 doesn't make much sense if it is meant to solve any portability problem,
  39.132 +	//   because there's no guarantee that true == 1 and false == 0 (or TRUE == 1 and FALSE == 0) on all platforms.
  39.133 +	//   while using user-defined boolean types might impact on performance.
  39.134 +	//   the more reliable (and faster!) way to maintain cross-platform I/O compatibility is
  39.135 +	//   to manually map from/to built-in boolean types to/from fixed-sized types value by value ONLY when doing I/O
  39.136 +	//   e.g. bool(true) <-> u8(1) and <-> bool(false) <-> u8(0), BOOL(TRUE) <-> s32(-1) and BOOL(FALSE) <-> s32(0) etc.
  39.137 +	bool8 RecordedThisSession;
  39.138 +};
  39.139 +
  39.140 +// methods used by the user-interface code
  39.141 +int VBAMovieOpen(const char *filename, bool8 read_only);
  39.142 +int VBAMovieCreate(const char *filename, const char *authorInfo, uint8 startFlags, uint8 controllerFlags, uint8 typeFlags);
  39.143 +int VBAMovieGetInfo(const char *filename, SMovie*info);
  39.144 +void VBAMovieGetRomInfo(const SMovie &movieInfo, char romTitle[12], uint32 &romGameCode, uint16 &checksum, uint8 &crc);
  39.145 +void VBAMovieStop(bool8 suppress_message);
  39.146 +const char *VBAChooseMovieFilename(bool8 read_only);
  39.147 +
  39.148 +// methods used by the emulation
  39.149 +void VBAMovieInit();
  39.150 +void VBAMovieUpdateState();
  39.151 +void VBAMovieRead(int controllerNum = 0, bool sensor = false);
  39.152 +void VBAMovieWrite(int controllerNum = 0, bool sensor = false);
  39.153 +void VBAUpdateButtonPressDisplay();
  39.154 +void VBAUpdateFrameCountDisplay();
  39.155 +//bool8 VBAMovieRewind (uint32 at_frame);
  39.156 +void VBAMovieFreeze(uint8 **buf, uint32 *size);
  39.157 +int VBAMovieUnfreeze(const uint8 *buf, uint32 size);
  39.158 +void VBAMovieRestart();
  39.159 +
  39.160 +// accessor functions
  39.161 +bool8 VBAMovieActive();
  39.162 +bool8 VBAMovieLoading();
  39.163 +bool8 VBAMoviePlaying();
  39.164 +bool8 VBAMovieRecording();
  39.165 +// the following accessors return 0/false if !VBAMovieActive()
  39.166 +uint8 VBAMovieReadOnly();
  39.167 +uint32 VBAMovieGetVersion();
  39.168 +uint32 VBAMovieGetMinorVersion();
  39.169 +uint32 VBAMovieGetId();
  39.170 +uint32 VBAMovieGetLength();
  39.171 +uint32 VBAMovieGetFrameCounter();
  39.172 +uint32 VBAMovieGetState();
  39.173 +uint32 VBAMovieGetRerecordCount ();
  39.174 +uint32 VBAMovieSetRerecordCount (uint32 newRerecordCount);
  39.175 +std::string VBAMovieGetAuthorInfo();
  39.176 +std::string VBAMovieGetFilename();
  39.177 +
  39.178 +uint16 VBAMovieGetCurrentInputOf(int controllerNum, bool normalOnly = true);
  39.179 +void VBAMovieSignalReset();
  39.180 +void VBAMovieResetIfRequested();
  39.181 +void VBAMovieSetMetadata(const char *info);
  39.182 +void VBAMovieToggleReadOnly();
  39.183 +bool VBAMovieEnded();
  39.184 +bool VBAMovieAllowsRerecording();
  39.185 +bool VBAMovieSwitchToPlaying();
  39.186 +bool VBAMovieSwitchToRecording();
  39.187 +int  VBAMovieGetPauseAt();
  39.188 +void VBAMovieSetPauseAt(int at);
  39.189 +int  VBAMovieConvertCurrent();
  39.190 +bool VBAMovieTuncateAtCurrentFrame();
  39.191 +bool VBAMovieFixHeader();
  39.192 +
  39.193 +#endif // VBA_MOVIE_H
    40.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.2 +++ b/src/common/nesvideos-piece.cpp	Sat Mar 03 10:31:27 2012 -0600
    40.3 @@ -0,0 +1,525 @@
    40.4 +#include <cmath>
    40.5 +#include <cstdio>
    40.6 +#include <string>
    40.7 +#include <vector>
    40.8 +
    40.9 +/* Note: This module assumes everyone uses RGB15 as display depth */
   40.10 +
   40.11 +static std::string VIDEO_CMD =
   40.12 +    "mencoder - -o test0.avi"
   40.13 +    " -noskip -mc 0"
   40.14 +    " -ovc lavc"
   40.15 +    " -oac mp3lame"
   40.16 +    " -lameopts preset=256:aq=2:mode=3"
   40.17 +    " -lavcopts vcodec=ffv1:context=0:format=BGR32:coder=0:vstrict=-1"
   40.18 +    " >& mencoder.log";
   40.19 +
   40.20 +static void FlushWrite(FILE* fp, const unsigned char*buf, unsigned length);
   40.21 +
   40.22 +#define BGR24 (0x42475218)  // BGR24 fourcc
   40.23 +#define BGR16 (0x42475210)  // BGR16 fourcc
   40.24 +#define BGR15 (0x4247520F)  // BGR15 fourcc
   40.25 +
   40.26 +static FILE* (*openFunc)  (const char*, const char*) = NULL;
   40.27 +static int (*closeFunc) (FILE*) = NULL;
   40.28 +
   40.29 +#if (defined(WIN32) || defined(win32)) // capital is standard, but check for either
   40.30 + #include <cstdlib>
   40.31 + #define popen _popen;
   40.32 + #define pclose _pclose;
   40.33 +#endif
   40.34 +
   40.35 +#define u32(n) (n)&255,((n)>>8)&255,((n)>>16)&255,((n)>>24)&255
   40.36 +#define u16(n) (n)&255,((n)>>8)&255
   40.37 +#define s4(s) s[0],s[1],s[2],s[3]
   40.38 +
   40.39 +static const unsigned FPS_SCALE = (0x1000000);
   40.40 +
   40.41 +// general-purpose A/V sync debugging, ignored unless explicitly enabled with NESVideoEnableDebugging
   40.42 +static void (*debugVideoMessageFunc)(const char *msg) = NULL;
   40.43 +static void (*debugAudioMessageFunc)(const char *msg) = NULL;
   40.44 +// logo adds 1 "frame" to audio, so offset that (A/V frames shouldn't necessarily match up depending on the rates, but should at least make them start out matching in case they do)
   40.45 +static unsigned audioFramesWritten=0, videoFramesWritten=1;
   40.46 +static double audioSecondsWritten=0, videoSecondsWritten=0;
   40.47 +
   40.48 +
   40.49 +static class AVI
   40.50 +{
   40.51 +    FILE* avifp;
   40.52 +    
   40.53 +    bool KnowVideo;
   40.54 +    unsigned width;
   40.55 +    unsigned height;
   40.56 +    unsigned fps_scaled;
   40.57 +    std::vector<unsigned char> VideoBuffer;
   40.58 +    
   40.59 +    bool KnowAudio;
   40.60 +    unsigned rate;
   40.61 +    unsigned chans;
   40.62 +    unsigned bits;
   40.63 +    std::vector<unsigned char> AudioBuffer;
   40.64 +    
   40.65 +public:
   40.66 +    AVI() :
   40.67 +        avifp(NULL),
   40.68 +        KnowVideo(false),
   40.69 +        KnowAudio(false)
   40.70 +    {
   40.71 +    }
   40.72 +    ~AVI()
   40.73 +    {
   40.74 +        if(avifp) closeFunc(avifp);
   40.75 +    }
   40.76 +    
   40.77 +    void Audio(unsigned r,unsigned b,unsigned c,
   40.78 +               const unsigned char*d, unsigned nsamples)
   40.79 +    {
   40.80 +        if(!KnowAudio)
   40.81 +        {
   40.82 +            rate = r;
   40.83 +            chans = c;
   40.84 +            bits = b;
   40.85 +            KnowAudio = true;
   40.86 +            CheckFlushing();
   40.87 +        }
   40.88 +        unsigned bytes = nsamples*chans*(bits/8);
   40.89 +
   40.90 +		if(debugAudioMessageFunc)
   40.91 +		{
   40.92 +			audioFramesWritten++;
   40.93 +			audioSecondsWritten += (double)nsamples / (double)rate; // += bytes times seconds per byte
   40.94 +			char temp [64];
   40.95 +			sprintf(temp, "A: %.2lf s, %d f", audioSecondsWritten, audioFramesWritten);
   40.96 +			debugAudioMessageFunc(temp);
   40.97 +		}
   40.98 +
   40.99 +        if(KnowVideo)
  40.100 +            SendAudioFrame(d, bytes);
  40.101 +        else
  40.102 +        {
  40.103 +            AudioBuffer.insert(AudioBuffer.end(), d, d+bytes);
  40.104 +            fprintf(stderr, "Buffering %u bytes of audio\n", bytes);
  40.105 +        }
  40.106 +    }
  40.107 +    void Video(unsigned w,unsigned h,unsigned f, const unsigned char*d)
  40.108 +    {
  40.109 +        if(!KnowVideo)
  40.110 +        {
  40.111 +            width=w;
  40.112 +            height=h;
  40.113 +            fps_scaled=f;
  40.114 +            KnowVideo = true;
  40.115 +            CheckFlushing();
  40.116 +        }
  40.117 +        
  40.118 +        unsigned bytes = width*height*2;
  40.119 +        
  40.120 +        //std::vector<unsigned char> tmp(bytes, 'k');
  40.121 +        //d = &tmp[0];
  40.122 +
  40.123 +		if(debugVideoMessageFunc)
  40.124 +		{
  40.125 +			videoFramesWritten++;
  40.126 +			videoSecondsWritten += (double)FPS_SCALE / (double)fps_scaled; // += seconds per frame
  40.127 +			char temp [64];
  40.128 +			sprintf(temp, "V: %.2lf s, %d f", videoSecondsWritten, videoFramesWritten);
  40.129 +			debugVideoMessageFunc(temp);
  40.130 +		}
  40.131 +
  40.132 +        if(KnowAudio)
  40.133 +            SendVideoFrame(d, bytes);
  40.134 +        else
  40.135 +        {
  40.136 +            VideoBuffer.insert(VideoBuffer.end(), d, d+bytes);
  40.137 +            fprintf(stderr, "Buffering %u bytes of video\n", bytes);
  40.138 +        }
  40.139 +    }
  40.140 +
  40.141 +private:
  40.142 +    void CheckFlushing()
  40.143 +    {
  40.144 +        //AudioBuffer.clear();
  40.145 +        //VideoBuffer.clear();
  40.146 +        
  40.147 +        if(KnowAudio && KnowVideo)
  40.148 +        {
  40.149 +            unsigned last_offs;
  40.150 +            
  40.151 +            // Flush Audio
  40.152 +            
  40.153 +            last_offs = 0;
  40.154 +            while(last_offs < AudioBuffer.size())
  40.155 +            {
  40.156 +                unsigned bytes = rate / (fps_scaled / FPS_SCALE);
  40.157 +                bytes *= chans*(bits/8);
  40.158 +                
  40.159 +                unsigned remain = AudioBuffer.size() - last_offs;
  40.160 +                if(bytes > remain) bytes = remain;
  40.161 +                if(!bytes) break;
  40.162 +                
  40.163 +                unsigned begin = last_offs;
  40.164 +                last_offs += bytes;
  40.165 +                SendAudioFrame(&AudioBuffer[begin], bytes);
  40.166 +            }
  40.167 +            AudioBuffer.erase(AudioBuffer.begin(), AudioBuffer.begin()+last_offs);
  40.168 +            
  40.169 +            // Flush Video
  40.170 +            
  40.171 +            last_offs = 0;
  40.172 +            while(last_offs < VideoBuffer.size())
  40.173 +            {
  40.174 +                unsigned bytes  = width*height*2;
  40.175 +                unsigned remain = VideoBuffer.size() - last_offs;
  40.176 +                if(bytes > remain) bytes = remain;
  40.177 +                if(!bytes)break;
  40.178 +                
  40.179 +                unsigned begin = last_offs;
  40.180 +                last_offs += bytes;
  40.181 +                SendVideoFrame(&VideoBuffer[begin], bytes);
  40.182 +            }
  40.183 +            VideoBuffer.erase(VideoBuffer.begin(), VideoBuffer.begin()+last_offs);
  40.184 +        }
  40.185 +    }
  40.186 +    
  40.187 +    void SendVideoFrame(const unsigned char* vidbuf, unsigned framesize)
  40.188 +    {
  40.189 +        CheckBegin();
  40.190 +        
  40.191 +        //fprintf(stderr, "Writing 00dc of %u bytes\n", framesize);
  40.192 +        
  40.193 +        const unsigned char header[] = { s4("00dc"), u32(framesize) };
  40.194 +        FlushWrite(avifp, header, sizeof(header));
  40.195 +        FlushWrite(avifp, vidbuf, framesize);
  40.196 +    }
  40.197 +
  40.198 +    void SendAudioFrame(const unsigned char* audbuf, unsigned framesize)
  40.199 +    {
  40.200 +        CheckBegin();
  40.201 +        
  40.202 +        //fprintf(stderr, "Writing 01wb of %u bytes\n", framesize);
  40.203 +        
  40.204 +        const unsigned char header[] = { s4("01wb"), u32(framesize) };
  40.205 +        FlushWrite(avifp, header, sizeof(header));
  40.206 +        FlushWrite(avifp, audbuf, framesize);
  40.207 +    }
  40.208 +
  40.209 +    void CheckBegin()
  40.210 +    {
  40.211 +        if(avifp) return;
  40.212 +        
  40.213 +		if(!openFunc) openFunc = popen; // default
  40.214 +		if(!closeFunc) closeFunc = pclose; // default
  40.215 +
  40.216 +        avifp = openFunc(VIDEO_CMD.c_str(), "wb");
  40.217 +        if(!avifp) return;
  40.218 +
  40.219 +        const unsigned fourcc = BGR16;
  40.220 +        const unsigned framesize = width*height*2;
  40.221 +        
  40.222 +        const unsigned aud_rate  = rate;
  40.223 +        const unsigned aud_chans = chans;
  40.224 +        const unsigned aud_bits  = bits;
  40.225 +
  40.226 +        const unsigned nframes    = 0; //unknown
  40.227 +        const unsigned scale      = FPS_SCALE;
  40.228 +        const unsigned scaled_fps = fps_scaled;
  40.229 +        
  40.230 +        const unsigned SIZE_strh_vids = 4 + 4*2 + 2*2 + 8*4 + 2*4;
  40.231 +        const unsigned SIZE_strf_vids = 4*3 + 2*2 + 4*6;
  40.232 +        const unsigned SIZE_strl_vids = 4+ 4+(4+SIZE_strh_vids) + 4+(4+SIZE_strf_vids);
  40.233 +
  40.234 +        const unsigned SIZE_strh_auds = 4 + 4*3 + 2*2 + 4*8 + 2*4;
  40.235 +        const unsigned SIZE_strf_auds = 2*2 + 4*2 + 2*3;
  40.236 +        const unsigned SIZE_strl_auds = 4+ 4+(4+SIZE_strh_auds) + 4+(4+SIZE_strf_auds);
  40.237 +        
  40.238 +        const unsigned SIZE_avih = 4*12;
  40.239 +        const unsigned SIZE_hdrl = 4+4+ (4+SIZE_avih) + 4 + (4+SIZE_strl_vids) + 4 + (4+SIZE_strl_auds);
  40.240 +        const unsigned SIZE_movi = 4 + nframes*(4+4+framesize);
  40.241 +        const unsigned SIZE_avi = 4+4+ (4+SIZE_hdrl) + 4 + (4+SIZE_movi);
  40.242 +        
  40.243 +        const unsigned char AVIheader[] =
  40.244 +        {
  40.245 +            s4("RIFF"),
  40.246 +            u32(SIZE_avi),
  40.247 +            s4("AVI "),   
  40.248 +            
  40.249 +            // HEADER
  40.250 +
  40.251 +            s4("LIST"),   
  40.252 +            u32(SIZE_hdrl),
  40.253 +             s4("hdrl"),   
  40.254 +             
  40.255 +             s4("avih"),
  40.256 +             u32(SIZE_avih),
  40.257 +              u32(0),
  40.258 +              u32(0),
  40.259 +              u32(0),
  40.260 +              u32(0),
  40.261 +              u32(nframes),
  40.262 +              u32(0),
  40.263 +              u32(2), // two streams
  40.264 +              u32(0),
  40.265 +              u32(0),
  40.266 +              u32(0),
  40.267 +              u32(0),
  40.268 +              u32(0),
  40.269 +             
  40.270 +             // VIDEO HEADER
  40.271 +             
  40.272 +             s4("LIST"),
  40.273 +             u32(SIZE_strl_vids),
  40.274 +              s4("strl"),   
  40.275 +              
  40.276 +               s4("strh"),
  40.277 +               u32(SIZE_strh_vids),
  40.278 +                s4("vids"),
  40.279 +                u32(0),
  40.280 +                u32(0),
  40.281 +                u16(0),
  40.282 +                u16(0),
  40.283 +                u32(0),
  40.284 +                u32(scale),
  40.285 +                u32(scaled_fps),
  40.286 +                u32(0),
  40.287 +                u32(0),
  40.288 +                u32(0),
  40.289 +                u32(0),
  40.290 +                u32(0),
  40.291 +                u16(0),
  40.292 +                u16(0),
  40.293 +                u16(0),
  40.294 +                u16(0),
  40.295 +               
  40.296 +               s4("strf"),
  40.297 +               u32(SIZE_strf_vids),
  40.298 +                u32(0),
  40.299 +                u32(width),
  40.300 +                u32(height),
  40.301 +                u16(0),
  40.302 +                u16(0),
  40.303 +                u32(fourcc),
  40.304 +                u32(0),
  40.305 +                u32(0),
  40.306 +                u32(0),
  40.307 +                u32(0),
  40.308 +                u32(0),
  40.309 +             
  40.310 +             // AUDIO HEADER
  40.311 +             
  40.312 +             s4("LIST"),
  40.313 +             u32(SIZE_strl_auds),
  40.314 +              s4("strl"),   
  40.315 +              
  40.316 +               s4("strh"),
  40.317 +               u32(SIZE_strh_auds),
  40.318 +                s4("auds"),
  40.319 +                u32(0), //fourcc
  40.320 +                u32(0), //handler
  40.321 +                u32(0), //flags
  40.322 +                u16(0), //prio
  40.323 +                u16(0), //lang
  40.324 +                u32(0), //init frames
  40.325 +                u32(1), //scale
  40.326 +                u32(aud_rate),
  40.327 +                u32(0), //start
  40.328 +                u32(0), //rate*length
  40.329 +                u32(1048576), //suggested bufsize
  40.330 +                u32(0), //quality
  40.331 +                u32(aud_chans * (aud_bits / 8)), //sample size
  40.332 +                u16(0), //frame size
  40.333 +                u16(0),
  40.334 +                u16(0),
  40.335 +                u16(0),
  40.336 +               
  40.337 +               s4("strf"),
  40.338 +               u32(SIZE_strf_auds),
  40.339 +                u16(1), // pcm format
  40.340 +                u16(aud_chans),
  40.341 +                u32(aud_rate),
  40.342 +                u32(aud_rate * aud_chans * (aud_bits/8)), // samples per second
  40.343 +                u16(aud_chans * (aud_bits/8)), //block align
  40.344 +                u16(aud_bits), //bits
  40.345 +                u16(0), //cbSize
  40.346 +
  40.347 +            // MOVIE
  40.348 +
  40.349 +            s4("LIST"),
  40.350 +            u32(SIZE_movi),
  40.351 +             s4("movi")
  40.352 +        };
  40.353 +          
  40.354 +        FlushWrite(avifp, AVIheader, sizeof(AVIheader));
  40.355 +    }
  40.356 +} AVI;
  40.357 +
  40.358 +extern "C"
  40.359 +{
  40.360 +    int LoggingEnabled = 0; /* 0=no, 1=yes, 2=recording! */
  40.361 +
  40.362 +    const char* NESVideoGetVideoCmd()
  40.363 +    {
  40.364 +        return VIDEO_CMD.c_str();
  40.365 +    }
  40.366 +    void NESVideoSetVideoCmd(const char *cmd)
  40.367 +    {
  40.368 +        VIDEO_CMD = cmd;
  40.369 +    }
  40.370 +	void NESVideoEnableDebugging( void videoMessageFunc(const char *msg), void audioMessageFunc(const char *msg) )
  40.371 +	{
  40.372 +		debugVideoMessageFunc = videoMessageFunc;
  40.373 +		debugAudioMessageFunc = audioMessageFunc;
  40.374 +	}
  40.375 +	void NESVideoSetFileFuncs( FILE* open(const char *,const char *), int close(FILE*) )
  40.376 +	{
  40.377 +		openFunc = open;
  40.378 +		closeFunc = close;
  40.379 +	}
  40.380 +
  40.381 +    void NESVideoLoggingVideo
  40.382 +        (const void*data, unsigned width,unsigned height,
  40.383 +         unsigned fps_scaled
  40.384 +        )
  40.385 +    {
  40.386 +        if(LoggingEnabled < 2) return;
  40.387 +        
  40.388 +        unsigned LogoFrames = fps_scaled >> 24;
  40.389 +
  40.390 +        static bool First = true;
  40.391 +        if(First)
  40.392 +        {
  40.393 +            First=false;
  40.394 +            /* Bisqwit's logo addition routine. */
  40.395 +            /* If you don't have his files, this function does nothing
  40.396 +             * and it does not matter at all.
  40.397 +             */
  40.398 +            
  40.399 +            const char *background =
  40.400 +                width==320 ? "logo320_240"
  40.401 +              : width==160 ? "logo160_144"
  40.402 +              : width==240 ? "logo240_160"
  40.403 +              : height>224 ? "logo256_240"
  40.404 +              :              "logo256_224";
  40.405 +            
  40.406 +            /* Note: This should be 1 second long. */
  40.407 +            for(unsigned frame = 0; frame < LogoFrames; ++frame)
  40.408 +            {
  40.409 +                char Buf[4096];
  40.410 +                sprintf(Buf, "/shares/home/bisqwit/povray/nesvlogo/%s_f%u.tga",
  40.411 +                    background, frame);
  40.412 +                
  40.413 +                FILE*fp = fopen(Buf, "rb");
  40.414 +                if(!fp) // write blackness when missing frames to keep the intro 1 second long:
  40.415 +				{
  40.416 +			        unsigned bytes = width*height*2;
  40.417 +					unsigned char* buf = (unsigned char*)malloc(bytes);
  40.418 +					if(buf)
  40.419 +					{
  40.420 +						memset(buf,0,bytes);
  40.421 +						AVI.Video(width,height,fps_scaled, buf);
  40.422 +						if(debugVideoMessageFunc) videoFramesWritten--;
  40.423 +						free(buf);
  40.424 +					}
  40.425 +				}
  40.426 +				else // write 1 frame of the logo:
  40.427 +				{
  40.428 +					int idlen = fgetc(fp);
  40.429 +					/* Silently ignore all other header data.
  40.430 +					 * These files are assumed to be uncompressed BGR24 tga files with Y swapped.
  40.431 +					 * Even their geometry is assumed to match perfectly.
  40.432 +					 */
  40.433 +					fseek(fp, 1+1+2+2+1+ /*org*/2+2+ /*geo*/2+2+ 1+1+idlen, SEEK_CUR);
  40.434 +
  40.435 +					bool yflip=true;
  40.436 +					std::vector<unsigned char> data(width*height*3);
  40.437 +					for(unsigned y=height; y-->0; )
  40.438 +						fread(&data[y*width*3], 1, width*3, fp);
  40.439 +					fclose(fp);
  40.440 +	                
  40.441 +					std::vector<unsigned short> result(width*height);
  40.442 +					for(unsigned pos=0, max=result.size(); pos<max; ++pos)
  40.443 +					{
  40.444 +						unsigned usepos = pos;
  40.445 +						if(yflip)
  40.446 +						{
  40.447 +							unsigned y = pos/width;
  40.448 +							usepos = (usepos%width) + (height-y-1)*width;
  40.449 +						}
  40.450 +	                    
  40.451 +						unsigned B = data[usepos*3+0];
  40.452 +						unsigned G = data[usepos*3+1];
  40.453 +						unsigned R = data[usepos*3+2];
  40.454 +						result[pos] = ((B*31/255)<<0)
  40.455 +									| ((G*63/255)<<5)
  40.456 +									| ((R*31/255)<<11);
  40.457 +					}
  40.458 +					AVI.Video(width,height,fps_scaled, (const unsigned char*)&result[0]);
  40.459 +					if(debugVideoMessageFunc) videoFramesWritten--;
  40.460 +				}
  40.461 +            }
  40.462 +        }
  40.463 +        AVI.Video(width,height,fps_scaled,  (const unsigned char*) data);
  40.464 +    }
  40.465 +
  40.466 +    void NESVideoLoggingAudio
  40.467 +        (const void*data,
  40.468 +         unsigned rate, unsigned bits, unsigned chans,
  40.469 +         unsigned nsamples)
  40.470 +    {
  40.471 +        if(LoggingEnabled < 2) return;
  40.472 +
  40.473 +        static bool First = true;
  40.474 +        if(First)
  40.475 +        {
  40.476 +            First=false;
  40.477 +            
  40.478 +			const unsigned n = rate; // assumes 1 second of logo to write silence for
  40.479 +            if(n > 0)
  40.480 +			{
  40.481 +				unsigned bytes = n*chans*(bits/8);
  40.482 +				unsigned char* buf = (unsigned char*)malloc(bytes);
  40.483 +				if(buf)
  40.484 +				{
  40.485 +					memset(buf,0,bytes);
  40.486 +					AVI.Audio(rate,bits,chans, buf, n);
  40.487 +					free(buf);
  40.488 +				}
  40.489 +			}
  40.490 +        }
  40.491 +        
  40.492 +        AVI.Audio(rate,bits,chans, (const unsigned char*) data, nsamples);
  40.493 +    }
  40.494 +} /* extern "C" */
  40.495 +
  40.496 +
  40.497 +
  40.498 +static void FlushWrite(FILE* fp, const unsigned char*buf, unsigned length)
  40.499 +{
  40.500 +///	unsigned failures = 0;
  40.501 +///	const static int FAILURE_THRESH = 8092; // don't want to loop infinitely if we keep failing to make progress - actually maybe you would want this, so the checking is disabled
  40.502 +    while(length > 0 /*&& failures < FAILURE_THRESH*/)
  40.503 +    {
  40.504 +        unsigned written = fwrite(buf, 1, length, fp);
  40.505 +///		if(written == 0)
  40.506 +///			failures++;
  40.507 +///		else
  40.508 +///		{
  40.509 +			length -= written;
  40.510 +			buf += written;
  40.511 +///			failures = 0;
  40.512 +///		}
  40.513 +    }
  40.514 +///	if(failures >= FAILURE_THRESH)
  40.515 +///	{
  40.516 +///		fprintf(stderr, "FlushWrite() failed to write %d bytes %d times - giving up.", length, failures);
  40.517 +///		LoggingEnabled = 0;
  40.518 +///	}
  40.519 +}
  40.520 +
  40.521 +// for the UB tech
  40.522 +#undef BGR24
  40.523 +#undef BGR16
  40.524 +#undef BGR15
  40.525 +
  40.526 +#undef u32
  40.527 +#undef u16
  40.528 +#undef s4
    41.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.2 +++ b/src/common/nesvideos-piece.h	Sat Mar 03 10:31:27 2012 -0600
    41.3 @@ -0,0 +1,48 @@
    41.4 +#ifndef NESVPIECEhh
    41.5 +#define NESVPIECEhh
    41.6 +
    41.7 +#define NESVIDEOS_LOGGING 1
    41.8 +
    41.9 +#ifdef __cplusplus
   41.10 +extern "C" {
   41.11 +#endif
   41.12 +
   41.13 +/* Is video logging enabled? 0=no, 1=yes, 2=active. Default value: 0 */ 
   41.14 +extern int LoggingEnabled; 
   41.15 +
   41.16 +/* Get and set the video recording command (shell command) */ 
   41.17 +extern const char* NESVideoGetVideoCmd(); 
   41.18 +extern void NESVideoSetVideoCmd(const char *cmd);
   41.19 +
   41.20 +/* Tells to use these functions for obtaining/releasing FILE pointers for writing - if not specified, popen/pclose are used. */
   41.21 +extern void NESVideoSetFileFuncs( FILE* openFunc(const char *,const char *), int closeFunc(FILE*) );
   41.22 +
   41.23 +/* Tells to call these functions per frame with amounts (seconds and frames) of video and audio progress */
   41.24 +extern void NESVideoEnableDebugging( void videoMessageFunc(const char *msg), void audioMessageFunc(const char *msg) );
   41.25 +
   41.26 +/* Save 1 frame of video. (Assumed to be 16-bit RGB) */ 
   41.27 +/* FPS is scaled by 24 bits (*0x1000000) */
   41.28 +/* Does not do anything if LoggingEnabled<2. */ 
   41.29 +extern void NESVideoLoggingVideo
   41.30 +    (const void*data, unsigned width, unsigned height,
   41.31 +     unsigned fps_scaled); 
   41.32 +
   41.33 +/* Save N bytes of audio. bytes_per_second is required on the first call. */ 
   41.34 +/* Does not do anything if LoggingEnabled<2. */ 
   41.35 +/* The interval of calling this function is not important, as long as all the audio
   41.36 + * data is eventually written without too big delay (5 seconds is too big)
   41.37 + * This function may be called multiple times per video frame, or once per a few video
   41.38 + * frames, or anything in between. Just that all audio data must be written exactly once,
   41.39 + * and in order. */ 
   41.40 +extern void NESVideoLoggingAudio
   41.41 +    (const void*data,
   41.42 +     unsigned rate, unsigned bits, unsigned chans,
   41.43 +     unsigned nsamples);
   41.44 +/* nsamples*chans*(bits/8) = bytes in *data. */
   41.45 +/*     rate*chans*(bits/8) = bytes per second. */
   41.46 +
   41.47 +#ifdef __cplusplus
   41.48 +}
   41.49 +#endif
   41.50 +
   41.51 +#endif
    42.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.2 +++ b/src/common/unzip.cpp	Sat Mar 03 10:31:27 2012 -0600
    42.3 @@ -0,0 +1,1208 @@
    42.4 +/* unzip.c -- IO on .zip files using zlib
    42.5 +   Version 0.15 beta, Mar 19th, 1998,
    42.6 +
    42.7 +   Read unzip.h for more info
    42.8 + */
    42.9 +
   42.10 +#include <cstdio>
   42.11 +#include <cstdlib>
   42.12 +#include <cstring>
   42.13 +#include "zlib.h"
   42.14 +#include "unzip.h"
   42.15 +
   42.16 +#ifdef NO_ERRNO_H
   42.17 +extern int errno;
   42.18 +#else
   42.19 +#   include <cerrno>
   42.20 +#endif
   42.21 +
   42.22 +#ifndef local
   42.23 +#  define local static
   42.24 +#endif
   42.25 +/* compile with -Dlocal if your debugger can't find static symbols */
   42.26 +
   42.27 +#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \
   42.28 +    !defined(CASESENSITIVITYDEFAULT_NO)
   42.29 +#define CASESENSITIVITYDEFAULT_NO
   42.30 +#endif
   42.31 +
   42.32 +#ifndef UNZ_BUFSIZE
   42.33 +#define UNZ_BUFSIZE (16384)
   42.34 +#endif
   42.35 +
   42.36 +#ifndef UNZ_MAXFILENAMEINZIP
   42.37 +#define UNZ_MAXFILENAMEINZIP (256)
   42.38 +#endif
   42.39 +
   42.40 +#ifndef ALLOC
   42.41 +# define ALLOC(size) (malloc(size))
   42.42 +#endif
   42.43 +#ifndef TRYFREE
   42.44 +# define TRYFREE(p) {if (p) \
   42.45 +						 free(p);}
   42.46 +#endif
   42.47 +
   42.48 +#define SIZECENTRALDIRITEM (0x2e)
   42.49 +#define SIZEZIPLOCALHEADER (0x1e)
   42.50 +
   42.51 +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
   42.52 +
   42.53 +#ifndef SEEK_CUR
   42.54 +#define SEEK_CUR    1
   42.55 +#endif
   42.56 +
   42.57 +#ifndef SEEK_END
   42.58 +#define SEEK_END    2
   42.59 +#endif
   42.60 +
   42.61 +#ifndef SEEK_SET
   42.62 +#define SEEK_SET    0
   42.63 +#endif
   42.64 +
   42.65 +const char unz_copyright[] =
   42.66 +    " unzip 0.15 Copyright 1998 Gilles Vollant ";
   42.67 +
   42.68 +/* unz_file_info_interntal contain internal info about a file in zipfile*/
   42.69 +typedef struct unz_file_info_internal_s
   42.70 +{
   42.71 +	uLong offset_curfile; /* relative offset of local header 4 bytes */
   42.72 +} unz_file_info_internal;
   42.73 +
   42.74 +/* file_in_zip_read_info_s contain internal information about a file in zipfile,
   42.75 +    when reading and decompress it */
   42.76 +typedef struct
   42.77 +{
   42.78 +	char *   read_buffer;           /* internal buffer for compressed data */
   42.79 +	z_stream stream;                /* zLib stream structure for inflate */
   42.80 +
   42.81 +	uLong pos_in_zipfile;           /* position in byte on the zipfile, for fseek*/
   42.82 +	uLong stream_initialised;       /* flag set if stream structure is initialised*/
   42.83 +
   42.84 +	uLong offset_local_extrafield;    /* offset of the local extra field */
   42.85 +	uInt  size_local_extrafield;    /* size of the local extra field */
   42.86 +	uLong pos_local_extrafield;       /* position in the local extra field in read*/
   42.87 +
   42.88 +	uLong crc32;                    /* crc32 of all data uncompressed */
   42.89 +	uLong crc32_wait;               /* crc32 we must obtain after decompress all */
   42.90 +	uLong rest_read_compressed;     /* number of byte to be decompressed */
   42.91 +	uLong rest_read_uncompressed;    /*number of byte to be obtained after decomp*/
   42.92 +	FILE* file;                     /* io structore of the zipfile */
   42.93 +	uLong compression_method;       /* compression method (0==store) */
   42.94 +	uLong byte_before_the_zipfile;    /* byte before the zipfile, (>0 for sfx)*/
   42.95 +} file_in_zip_read_info_s;
   42.96 +
   42.97 +/* unz_s contain internal information about the zipfile
   42.98 + */
   42.99 +typedef struct
  42.100 +{
  42.101 +	FILE*file;                      /* io structore of the zipfile */
  42.102 +	unz_global_info gi;           /* public global information */
  42.103 +	uLong byte_before_the_zipfile;    /* byte before the zipfile, (>0 for sfx)*/
  42.104 +	uLong num_file;                 /* number of the current file in the zipfile*/
  42.105 +	uLong pos_in_central_dir;       /* pos of the current file in the central dir*/
  42.106 +	uLong current_file_ok;          /* flag about the usability of the current file*/
  42.107 +	uLong central_pos;              /* position of the beginning of the central dir*/
  42.108 +
  42.109 +	uLong size_central_dir;         /* size of the central directory  */
  42.110 +	uLong offset_central_dir;       /* offset of start of central directory with
  42.111 +									                               respect to the starting disk number */
  42.112 +
  42.113 +	unz_file_info cur_file_info;     /* public info about the current file in zip*/
  42.114 +	unz_file_info_internal  cur_file_info_internal;    /* private info about it*/
  42.115 +	file_in_zip_read_info_s*pfile_in_zip_read;  /* structure about the current
  42.116 +												   file if we are decompressing it */
  42.117 +} unz_s;
  42.118 +
  42.119 +/* ===========================================================================
  42.120 +     Read a byte from a gz_stream; update next_in and avail_in. Return EOF
  42.121 +   for end of file.
  42.122 +   IN assertion: the stream s has been sucessfully opened for reading.
  42.123 + */
  42.124 +
  42.125 +local int unzlocal_getByte(FILE *fin, int *pi)
  42.126 +{
  42.127 +	unsigned char c;
  42.128 +	int err = fread(&c, 1, 1, fin);
  42.129 +	if (err == 1)
  42.130 +	{
  42.131 +		*pi = (int)c;
  42.132 +		return UNZ_OK;
  42.133 +	}
  42.134 +	else
  42.135 +	{
  42.136 +		if (ferror(fin))
  42.137 +			return UNZ_ERRNO;
  42.138 +		else
  42.139 +			return UNZ_EOF;
  42.140 +	}
  42.141 +}
  42.142 +
  42.143 +/* ===========================================================================
  42.144 +   Reads a long in LSB order from the given gz_stream. Sets
  42.145 + */
  42.146 +local int unzlocal_getShort(FILE *fin, uLong *pX)
  42.147 +{
  42.148 +	uLong x ;
  42.149 +	int   i;
  42.150 +	int   err;
  42.151 +
  42.152 +	err = unzlocal_getByte(fin, &i);
  42.153 +	x   = (uLong)i;
  42.154 +
  42.155 +	if (err == UNZ_OK)
  42.156 +		err = unzlocal_getByte(fin, &i);
  42.157 +	x += ((uLong)i)<<8;
  42.158 +
  42.159 +	if (err == UNZ_OK)
  42.160 +		*pX = x;
  42.161 +	else
  42.162 +		*pX = 0;
  42.163 +	return err;
  42.164 +}
  42.165 +
  42.166 +local int unzlocal_getLong(FILE *fin, uLong *pX)
  42.167 +{
  42.168 +	uLong x ;
  42.169 +	int   i;
  42.170 +	int   err;
  42.171 +
  42.172 +	err = unzlocal_getByte(fin, &i);
  42.173 +	x   = (uLong)i;
  42.174 +
  42.175 +	if (err == UNZ_OK)
  42.176 +		err = unzlocal_getByte(fin, &i);
  42.177 +	x += ((uLong)i)<<8;
  42.178 +
  42.179 +	if (err == UNZ_OK)
  42.180 +		err = unzlocal_getByte(fin, &i);
  42.181 +	x += ((uLong)i)<<16;
  42.182 +
  42.183 +	if (err == UNZ_OK)
  42.184 +		err = unzlocal_getByte(fin, &i);
  42.185 +	x += ((uLong)i)<<24;
  42.186 +
  42.187 +	if (err == UNZ_OK)
  42.188 +		*pX = x;
  42.189 +	else
  42.190 +		*pX = 0;
  42.191 +	return err;
  42.192 +}
  42.193 +
  42.194 +/* My own strcmpi / strcasecmp */
  42.195 +local int strcmpcasenosensitive_internal(const char *fileName1,
  42.196 +                                         const char *fileName2)
  42.197 +{
  42.198 +	for (;;)
  42.199 +	{
  42.200 +		char c1 = *(fileName1++);
  42.201 +		char c2 = *(fileName2++);
  42.202 +		if ((c1 >= 'a') && (c1 <= 'z'))
  42.203 +			c1 -= 0x20;
  42.204 +		if ((c2 >= 'a') && (c2 <= 'z'))
  42.205 +			c2 -= 0x20;
  42.206 +		if (c1 == '\0')
  42.207 +			return ((c2 == '\0') ? 0 : -1);
  42.208 +		if (c2 == '\0')
  42.209 +			return 1;
  42.210 +		if (c1 < c2)
  42.211 +			return -1;
  42.212 +		if (c1 > c2)
  42.213 +			return 1;
  42.214 +	}
  42.215 +}
  42.216 +
  42.217 +#ifdef  CASESENSITIVITYDEFAULT_NO
  42.218 +#define CASESENSITIVITYDEFAULTVALUE 2
  42.219 +#else
  42.220 +#define CASESENSITIVITYDEFAULTVALUE 1
  42.221 +#endif
  42.222 +
  42.223 +#ifndef STRCMPCASENOSENTIVEFUNCTION
  42.224 +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
  42.225 +#endif
  42.226 +
  42.227 +/*
  42.228 +   Compare two filename (fileName1,fileName2).
  42.229 +   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
  42.230 +   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
  42.231 +                                                                or strcasecmp)
  42.232 +   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
  42.233 +        (like 1 on Unix, 2 on Windows)
  42.234 +
  42.235 + */
  42.236 +extern int ZEXPORT unzStringFileNameCompare(const char *fileName1,
  42.237 +                                            const char *fileName2,
  42.238 +                                            int iCaseSensitivity)
  42.239 +{
  42.240 +	if (iCaseSensitivity == 0)
  42.241 +		iCaseSensitivity = CASESENSITIVITYDEFAULTVALUE;
  42.242 +
  42.243 +	if (iCaseSensitivity == 1)
  42.244 +		return strcmp(fileName1, fileName2);
  42.245 +
  42.246 +	return STRCMPCASENOSENTIVEFUNCTION(fileName1, fileName2);
  42.247 +}
  42.248 +
  42.249 +#define BUFREADCOMMENT (0x400)
  42.250 +
  42.251 +/*
  42.252 +   Locate the Central directory of a zipfile (at the end, just before
  42.253 +    the global comment)
  42.254 + */
  42.255 +local uLong unzlocal_SearchCentralDir(FILE *fin)
  42.256 +{
  42.257 +	unsigned char*buf;
  42.258 +	uLong         uSizeFile;
  42.259 +	uLong         uBackRead;
  42.260 +	uLong         uMaxBack  = 0xffff; /* maximum size of global comment */
  42.261 +	uLong         uPosFound = 0;
  42.262 +
  42.263 +	if (fseek(fin, 0, SEEK_END) != 0)
  42.264 +		return 0;
  42.265 +
  42.266 +	uSizeFile = ftell(fin);
  42.267 +
  42.268 +	if (uMaxBack > uSizeFile)
  42.269 +		uMaxBack = uSizeFile;
  42.270 +
  42.271 +	buf = (unsigned char *)ALLOC(BUFREADCOMMENT+4);
  42.272 +	if (buf == NULL)
  42.273 +		return 0;
  42.274 +
  42.275 +	uBackRead = 4;
  42.276 +	while (uBackRead < uMaxBack)
  42.277 +	{
  42.278 +		uLong uReadSize, uReadPos ;
  42.279 +		int   i;
  42.280 +		if (uBackRead+BUFREADCOMMENT > uMaxBack)
  42.281 +			uBackRead = uMaxBack;
  42.282 +		else
  42.283 +			uBackRead += BUFREADCOMMENT;
  42.284 +		uReadPos = uSizeFile-uBackRead ;
  42.285 +
  42.286 +		uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
  42.287 +		            (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
  42.288 +		if (fseek(fin, uReadPos, SEEK_SET) != 0)
  42.289 +			break;
  42.290 +
  42.291 +		if (fread(buf, (uInt)uReadSize, 1, fin) != 1)
  42.292 +			break;
  42.293 +
  42.294 +		for (i = (int)uReadSize-3; (i--) > 0;)
  42.295 +			if (((*(buf+i)) == 0x50) && ((*(buf+i+1)) == 0x4b) &&
  42.296 +			    ((*(buf+i+2)) == 0x05) && ((*(buf+i+3)) == 0x06))
  42.297 +			{
  42.298 +				uPosFound = uReadPos+i;
  42.299 +				break;
  42.300 +			}
  42.301 +
  42.302 +		if (uPosFound != 0)
  42.303 +			break;
  42.304 +	}
  42.305 +	TRYFREE(buf);
  42.306 +	return uPosFound;
  42.307 +}
  42.308 +
  42.309 +/*
  42.310 +   Open a Zip file. path contain the full pathname (by example,
  42.311 +     on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer
  42.312 +         "zlib/zlib109.zip".
  42.313 +         If the zipfile cannot be opened (file don't exist or in not valid), the
  42.314 +           return value is NULL.
  42.315 +     Else, the return value is a unzFile Handle, usable with other function
  42.316 +           of this unzip package.
  42.317 + */
  42.318 +extern unzFile ZEXPORT unzOpen(const char *path)
  42.319 +{
  42.320 +	unz_s  us;
  42.321 +	unz_s *s;
  42.322 +	uLong  central_pos, uL;
  42.323 +	FILE * fin ;
  42.324 +
  42.325 +	uLong number_disk;              /* number of the current dist, used for
  42.326 +									                               spaning ZIP, unsupported, always 0*/
  42.327 +	uLong number_disk_with_CD;      /* number the the disk with central dir, used
  42.328 +									                               for spaning ZIP, unsupported, always 0*/
  42.329 +	uLong number_entry_CD;          /* total number of entries in
  42.330 +									   the central dir
  42.331 +									   (same than number_entry on nospan) */
  42.332 +
  42.333 +	int err = UNZ_OK;
  42.334 +
  42.335 +	if (unz_copyright[0] != ' ')
  42.336 +		return NULL;
  42.337 +
  42.338 +	fin = fopen(path, "rb");
  42.339 +	if (fin == NULL)
  42.340 +		return NULL;
  42.341 +
  42.342 +	central_pos = unzlocal_SearchCentralDir(fin);
  42.343 +	if (central_pos == 0)
  42.344 +		err = UNZ_ERRNO;
  42.345 +
  42.346 +	if (fseek(fin, central_pos, SEEK_SET) != 0)
  42.347 +		err = UNZ_ERRNO;
  42.348 +
  42.349 +	/* the signature, already checked */
  42.350 +	if (unzlocal_getLong(fin, &uL) != UNZ_OK)
  42.351 +		err = UNZ_ERRNO;
  42.352 +
  42.353 +	/* number of this disk */
  42.354 +	if (unzlocal_getShort(fin, &number_disk) != UNZ_OK)
  42.355 +		err = UNZ_ERRNO;
  42.356 +
  42.357 +	/* number of the disk with the start of the central directory */
  42.358 +	if (unzlocal_getShort(fin, &number_disk_with_CD) != UNZ_OK)
  42.359 +		err = UNZ_ERRNO;
  42.360 +
  42.361 +	/* total number of entries in the central dir on this disk */
  42.362 +	if (unzlocal_getShort(fin, &us.gi.number_entry) != UNZ_OK)
  42.363 +		err = UNZ_ERRNO;
  42.364 +
  42.365 +	/* total number of entries in the central dir */
  42.366 +	if (unzlocal_getShort(fin, &number_entry_CD) != UNZ_OK)
  42.367 +		err = UNZ_ERRNO;
  42.368 +
  42.369 +	if ((number_entry_CD != us.gi.number_entry) ||
  42.370 +	    (number_disk_with_CD != 0) ||
  42.371 +	    (number_disk != 0))
  42.372 +		err = UNZ_BADZIPFILE;
  42.373 +
  42.374 +	/* size of the central directory */
  42.375 +	if (unzlocal_getLong(fin, &us.size_central_dir) != UNZ_OK)
  42.376 +		err = UNZ_ERRNO;
  42.377 +
  42.378 +	/* offset of start of central directory with respect to the
  42.379 +	      starting disk number */
  42.380 +	if (unzlocal_getLong(fin, &us.offset_central_dir) != UNZ_OK)
  42.381 +		err = UNZ_ERRNO;
  42.382 +
  42.383 +	/* zipfile comment length */
  42.384 +	if (unzlocal_getShort(fin, &us.gi.size_comment) != UNZ_OK)
  42.385 +		err = UNZ_ERRNO;
  42.386 +
  42.387 +	if ((central_pos < us.offset_central_dir+us.size_central_dir) &&
  42.388 +	    (err == UNZ_OK))
  42.389 +		err = UNZ_BADZIPFILE;
  42.390 +
  42.391 +	if (err != UNZ_OK)
  42.392 +	{
  42.393 +		fclose(fin);
  42.394 +		return NULL;
  42.395 +	}
  42.396 +
  42.397 +	us.file = fin;
  42.398 +	us.byte_before_the_zipfile = central_pos -
  42.399 +	                             (us.offset_central_dir+us.size_central_dir);
  42.400 +	us.central_pos       = central_pos;
  42.401 +	us.pfile_in_zip_read = NULL;
  42.402 +
  42.403 +	s  = (unz_s *)ALLOC(sizeof(unz_s));
  42.404 +	*s = us;
  42.405 +	unzGoToFirstFile((unzFile)s);
  42.406 +	return (unzFile)s;
  42.407 +}
  42.408 +
  42.409 +/*
  42.410 +   Close a ZipFile opened with unzipOpen.
  42.411 +   If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
  42.412 +    these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
  42.413 +   return UNZ_OK if there is no problem. */
  42.414 +extern int ZEXPORT unzClose(unzFile file)
  42.415 +{
  42.416 +	unz_s*s;
  42.417 +	if (file == NULL)
  42.418 +		return UNZ_PARAMERROR;
  42.419 +	s = (unz_s *)file;
  42.420 +
  42.421 +	if (s->pfile_in_zip_read != NULL)
  42.422 +		unzCloseCurrentFile(file);
  42.423 +
  42.424 +	fclose(s->file);
  42.425 +	TRYFREE(s);
  42.426 +	return UNZ_OK;
  42.427 +}
  42.428 +
  42.429 +/*
  42.430 +   Write info about the ZipFile in the *pglobal_info structure.
  42.431 +   No preparation of the structure is needed
  42.432 +   return UNZ_OK if there is no problem. */
  42.433 +extern int ZEXPORT unzGetGlobalInfo(unzFile file,
  42.434 +                                    unz_global_info *pglobal_info)
  42.435 +{
  42.436 +	unz_s*s;
  42.437 +	if (file == NULL)
  42.438 +		return UNZ_PARAMERROR;
  42.439 +	s = (unz_s *)file;
  42.440 +	*pglobal_info = s->gi;
  42.441 +	return UNZ_OK;
  42.442 +}
  42.443 +
  42.444 +/*
  42.445 +   Translate date/time from Dos format to tm_unz (readable more easilty)
  42.446 + */
  42.447 +local void unzlocal_DosDateToTmuDate(uLong ulDosDate, tm_unz *ptm)
  42.448 +{
  42.449 +	uLong uDate;
  42.450 +	uDate        = (uLong)(ulDosDate>>16);
  42.451 +	ptm->tm_mday = (uInt)(uDate&0x1f) ;
  42.452 +	ptm->tm_mon  =  (uInt)((((uDate)&0x1E0)/0x20)-1) ;
  42.453 +	ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
  42.454 +
  42.455 +	ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
  42.456 +	ptm->tm_min  =  (uInt) ((ulDosDate&0x7E0)/0x20) ;
  42.457 +	ptm->tm_sec  =  (uInt) (2*(ulDosDate&0x1f)) ;
  42.458 +}
  42.459 +
  42.460 +/*
  42.461 +   Get Info about the current file in the zipfile, with internal only info
  42.462 + */
  42.463 +local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
  42.464 +                                                  unz_file_info *pfile_info,
  42.465 +                                                  unz_file_info_internal
  42.466 +                                                  *pfile_info_internal,
  42.467 +                                                  char *szFileName,
  42.468 +                                                  uLong fileNameBufferSize,
  42.469 +                                                  void *extraField,
  42.470 +                                                  uLong extraFieldBufferSize,
  42.471 +                                                  char *szComment,
  42.472 +                                                  uLong commentBufferSize));
  42.473 +
  42.474 +local int unzlocal_GetCurrentFileInfoInternal(unzFile file,
  42.475 +                                              unz_file_info *pfile_info,
  42.476 +                                              unz_file_info_internal *pfile_info_internal,
  42.477 +                                              char *szFileName,
  42.478 +                                              uLong fileNameBufferSize,
  42.479 +                                              void *extraField,
  42.480 +                                              uLong extraFieldBufferSize,
  42.481 +                                              char *szComment,
  42.482 +                                              uLong commentBufferSize)
  42.483 +{
  42.484 +	unz_s*        s;
  42.485 +	unz_file_info file_info;
  42.486 +	unz_file_info_internal file_info_internal;
  42.487 +	int   err = UNZ_OK;
  42.488 +	uLong uMagic;
  42.489 +	long  lSeek = 0;
  42.490 +
  42.491 +	if (file == NULL)
  42.492 +		return UNZ_PARAMERROR;
  42.493 +	s = (unz_s *)file;
  42.494 +	if (fseek(s->file, s->pos_in_central_dir+s->byte_before_the_zipfile, SEEK_SET) != 0)
  42.495 +		err = UNZ_ERRNO;
  42.496 +
  42.497 +	/* we check the magic */
  42.498 +	if (err == UNZ_OK)
  42.499 +		if (unzlocal_getLong(s->file, &uMagic) != UNZ_OK)
  42.500 +			err = UNZ_ERRNO;
  42.501 +		else if (uMagic != 0x02014b50)
  42.502 +			err = UNZ_BADZIPFILE;
  42.503 +
  42.504 +	if (unzlocal_getShort(s->file, &file_info.version) != UNZ_OK)
  42.505 +		err = UNZ_ERRNO;
  42.506 +
  42.507 +	if (unzlocal_getShort(s->file, &file_info.version_needed) != UNZ_OK)
  42.508 +		err = UNZ_ERRNO;
  42.509 +
  42.510 +	if (unzlocal_getShort(s->file, &file_info.flag) != UNZ_OK)
  42.511 +		err = UNZ_ERRNO;
  42.512 +
  42.513 +	if (unzlocal_getShort(s->file, &file_info.compression_method) != UNZ_OK)
  42.514 +		err = UNZ_ERRNO;
  42.515 +
  42.516 +	if (unzlocal_getLong(s->file, &file_info.dosDate) != UNZ_OK)
  42.517 +		err = UNZ_ERRNO;
  42.518 +
  42.519 +	unzlocal_DosDateToTmuDate(file_info.dosDate, &file_info.tmu_date);
  42.520 +
  42.521 +	if (unzlocal_getLong(s->file, &file_info.crc) != UNZ_OK)
  42.522 +		err = UNZ_ERRNO;
  42.523 +
  42.524 +	if (unzlocal_getLong(s->file, &file_info.compressed_size) != UNZ_OK)
  42.525 +		err = UNZ_ERRNO;
  42.526 +
  42.527 +	if (unzlocal_getLong(s->file, &file_info.uncompressed_size) != UNZ_OK)
  42.528 +		err = UNZ_ERRNO;
  42.529 +
  42.530 +	if (unzlocal_getShort(s->file, &file_info.size_filename) != UNZ_OK)
  42.531 +		err = UNZ_ERRNO;
  42.532 +
  42.533 +	if (unzlocal_getShort(s->file, &file_info.size_file_extra) != UNZ_OK)
  42.534 +		err = UNZ_ERRNO;
  42.535 +
  42.536 +	if (unzlocal_getShort(s->file, &file_info.size_file_comment) != UNZ_OK)
  42.537 +		err = UNZ_ERRNO;
  42.538 +
  42.539 +	if (unzlocal_getShort(s->file, &file_info.disk_num_start) != UNZ_OK)
  42.540 +		err = UNZ_ERRNO;
  42.541 +
  42.542 +	if (unzlocal_getShort(s->file, &file_info.internal_fa) != UNZ_OK)
  42.543 +		err = UNZ_ERRNO;
  42.544 +
  42.545 +	if (unzlocal_getLong(s->file, &file_info.external_fa) != UNZ_OK)
  42.546 +		err = UNZ_ERRNO;
  42.547 +
  42.548 +	if (unzlocal_getLong(s->file, &file_info_internal.offset_curfile) != UNZ_OK)
  42.549 +		err = UNZ_ERRNO;
  42.550 +
  42.551 +	lSeek += file_info.size_filename;
  42.552 +	if ((err == UNZ_OK) && (szFileName != NULL))
  42.553 +	{
  42.554 +		uLong uSizeRead ;
  42.555 +		if (file_info.size_filename < fileNameBufferSize)
  42.556 +		{
  42.557 +			*(szFileName+file_info.size_filename) = '\0';
  42.558 +			uSizeRead = file_info.size_filename;
  42.559 +		}
  42.560 +		else
  42.561 +			uSizeRead = fileNameBufferSize;
  42.562 +
  42.563 +		if ((file_info.size_filename > 0) && (fileNameBufferSize > 0))
  42.564 +			if (fread(szFileName, (uInt)uSizeRead, 1, s->file) != 1)
  42.565 +				err = UNZ_ERRNO;
  42.566 +		lSeek -= uSizeRead;
  42.567 +	}
  42.568 +
  42.569 +	if ((err == UNZ_OK) && (extraField != NULL))
  42.570 +	{
  42.571 +		uLong uSizeRead ;
  42.572 +		if (file_info.size_file_extra < extraFieldBufferSize)
  42.573 +			uSizeRead = file_info.size_file_extra;
  42.574 +		else
  42.575 +			uSizeRead = extraFieldBufferSize;
  42.576 +
  42.577 +		if (lSeek != 0)
  42.578 +			if (fseek(s->file, lSeek, SEEK_CUR) == 0)
  42.579 +				lSeek = 0;
  42.580 +			else
  42.581 +				err = UNZ_ERRNO;
  42.582 +		if ((file_info.size_file_extra > 0) && (extraFieldBufferSize > 0))
  42.583 +			if (fread(extraField, (uInt)uSizeRead, 1, s->file) != 1)
  42.584 +				err = UNZ_ERRNO;
  42.585 +		lSeek += file_info.size_file_extra - uSizeRead;
  42.586 +	}
  42.587 +	else
  42.588 +		lSeek += file_info.size_file_extra;
  42.589 +
  42.590 +	if ((err == UNZ_OK) && (szComment != NULL))
  42.591 +	{
  42.592 +		uLong uSizeRead ;
  42.593 +		if (file_info.size_file_comment < commentBufferSize)
  42.594 +		{
  42.595 +			*(szComment+file_info.size_file_comment) = '\0';
  42.596 +			uSizeRead = file_info.size_file_comment;
  42.597 +		}
  42.598 +		else
  42.599 +			uSizeRead = commentBufferSize;
  42.600 +
  42.601 +		if (lSeek != 0)
  42.602 +			if (fseek(s->file, lSeek, SEEK_CUR) == 0)
  42.603 +				lSeek = 0;
  42.604 +			else
  42.605 +				err = UNZ_ERRNO;
  42.606 +		if ((file_info.size_file_comment > 0) && (commentBufferSize > 0))
  42.607 +			if (fread(szComment, (uInt)uSizeRead, 1, s->file) != 1)
  42.608 +				err = UNZ_ERRNO;
  42.609 +		lSeek += file_info.size_file_comment - uSizeRead;
  42.610 +	}
  42.611 +	else
  42.612 +		lSeek += file_info.size_file_comment;
  42.613 +
  42.614 +	if ((err == UNZ_OK) && (pfile_info != NULL))
  42.615 +		*pfile_info = file_info;
  42.616 +
  42.617 +	if ((err == UNZ_OK) && (pfile_info_internal != NULL))
  42.618 +		*pfile_info_internal = file_info_internal;
  42.619 +
  42.620 +	return err;
  42.621 +}
  42.622 +
  42.623 +/*
  42.624 +   Write info about the ZipFile in the *pglobal_info structure.
  42.625 +   No preparation of the structure is needed
  42.626 +   return UNZ_OK if there is no problem.
  42.627 + */
  42.628 +extern int ZEXPORT unzGetCurrentFileInfo(unzFile file,
  42.629 +                                         unz_file_info *pfile_info,
  42.630 +                                         char *szFileName,
  42.631 +                                         uLong fileNameBufferSize,
  42.632 +                                         void *extraField,
  42.633 +                                         uLong extraFieldBufferSize,
  42.634 +                                         char *szComment,
  42.635 +                                         uLong commentBufferSize)
  42.636 +{
  42.637 +	return unzlocal_GetCurrentFileInfoInternal(file, pfile_info, NULL,
  42.638 +	                                           szFileName, fileNameBufferSize,
  42.639 +	                                           extraField, extraFieldBufferSize,
  42.640 +	                                           szComment, commentBufferSize);
  42.641 +}
  42.642 +
  42.643 +/*
  42.644 +   Set the current file of the zipfile to the first file.
  42.645 +   return UNZ_OK if there is no problem
  42.646 + */
  42.647 +extern int ZEXPORT unzGoToFirstFile(unzFile file)
  42.648 +{
  42.649 +	int   err = UNZ_OK;
  42.650 +	unz_s*s;
  42.651 +	if (file == NULL)
  42.652 +		return UNZ_PARAMERROR;
  42.653 +	s = (unz_s *)file;
  42.654 +	s->pos_in_central_dir = s->offset_central_dir;
  42.655 +	s->num_file = 0;
  42.656 +	err         = unzlocal_GetCurrentFileInfoInternal(file, &s->cur_file_info,
  42.657 +	                                                  &s->cur_file_info_internal,
  42.658 +	                                                  NULL, 0, NULL, 0, NULL, 0);
  42.659 +	s->current_file_ok = (err == UNZ_OK);
  42.660 +	return err;
  42.661 +}
  42.662 +
  42.663 +/*
  42.664 +   Set the current file of the zipfile to the next file.
  42.665 +   return UNZ_OK if there is no problem
  42.666 +   return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
  42.667 + */
  42.668 +extern int ZEXPORT unzGoToNextFile(unzFile file)
  42.669 +{
  42.670 +	unz_s*s;
  42.671 +	int   err;
  42.672 +
  42.673 +	if (file == NULL)
  42.674 +		return UNZ_PARAMERROR;
  42.675 +	s = (unz_s *)file;
  42.676 +	if (!s->current_file_ok)
  42.677 +		return UNZ_END_OF_LIST_OF_FILE;
  42.678 +	if (s->num_file+1 == s->gi.number_entry)
  42.679 +		return UNZ_END_OF_LIST_OF_FILE;
  42.680 +
  42.681 +	s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
  42.682 +	                         s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
  42.683 +	s->num_file++;
  42.684 +	err = unzlocal_GetCurrentFileInfoInternal(file, &s->cur_file_info,
  42.685 +	                                          &s->cur_file_info_internal,
  42.686 +	                                          NULL, 0, NULL, 0, NULL, 0);
  42.687 +	s->current_file_ok = (err == UNZ_OK);
  42.688 +	return err;
  42.689 +}
  42.690 +
  42.691 +/*
  42.692 +   Try locate the file szFileName in the zipfile.
  42.693 +   For the iCaseSensitivity signification, see unzipStringFileNameCompare
  42.694 +
  42.695 +   return value :
  42.696 +   UNZ_OK if the file is found. It becomes the current file.
  42.697 +   UNZ_END_OF_LIST_OF_FILE if the file is not found
  42.698 + */
  42.699 +extern int ZEXPORT unzLocateFile(unzFile file,
  42.700 +                                 const char *szFileName,
  42.701 +                                 int iCaseSensitivity)
  42.702 +{
  42.703 +	unz_s*s;
  42.704 +	int   err;
  42.705 +
  42.706 +	uLong num_fileSaved;
  42.707 +	uLong pos_in_central_dirSaved;
  42.708 +
  42.709 +	if (file == NULL)
  42.710 +		return UNZ_PARAMERROR;
  42.711 +
  42.712 +	if (strlen(szFileName) >= UNZ_MAXFILENAMEINZIP)
  42.713 +		return UNZ_PARAMERROR;
  42.714 +
  42.715 +	s = (unz_s *)file;
  42.716 +	if (!s->current_file_ok)
  42.717 +		return UNZ_END_OF_LIST_OF_FILE;
  42.718 +
  42.719 +	num_fileSaved = s->num_file;
  42.720 +	pos_in_central_dirSaved = s->pos_in_central_dir;
  42.721 +
  42.722 +	err = unzGoToFirstFile(file);
  42.723 +
  42.724 +	while (err == UNZ_OK)
  42.725 +	{
  42.726 +		char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
  42.727 +		unzGetCurrentFileInfo(file, NULL,
  42.728 +		                      szCurrentFileName, sizeof(szCurrentFileName)-1,
  42.729 +		                      NULL, 0, NULL, 0);
  42.730 +		if (unzStringFileNameCompare(szCurrentFileName,
  42.731 +		                             szFileName, iCaseSensitivity) == 0)
  42.732 +			return UNZ_OK;
  42.733 +		err = unzGoToNextFile(file);
  42.734 +	}
  42.735 +
  42.736 +	s->num_file = num_fileSaved ;
  42.737 +	s->pos_in_central_dir = pos_in_central_dirSaved ;
  42.738 +	return err;
  42.739 +}
  42.740 +
  42.741 +/*
  42.742 +   Read the local header of the current zipfile
  42.743 +   Check the coherency of the local header and info in the end of central
  42.744 +        directory about this file
  42.745 +   store in *piSizeVar the size of extra info in local header
  42.746 +        (filename and size of extra field data)
  42.747 + */
  42.748 +local int unzlocal_CheckCurrentFileCoherencyHeader(unz_s *s,
  42.749 +                                                   uInt *piSizeVar,
  42.750 +                                                   uLong *poffset_local_extrafield,
  42.751 +                                                   uInt *psize_local_extrafield)
  42.752 +{
  42.753 +	uLong uMagic, uData, uFlags;
  42.754 +	uLong size_filename;
  42.755 +	uLong size_extra_field;
  42.756 +	int   err = UNZ_OK;
  42.757 +
  42.758 +	*piSizeVar = 0;
  42.759 +	*poffset_local_extrafield = 0;
  42.760 +	*psize_local_extrafield   = 0;
  42.761 +
  42.762 +	if (fseek(s->file, s->cur_file_info_internal.offset_curfile +
  42.763 +	          s->byte_before_the_zipfile, SEEK_SET) != 0)
  42.764 +		return UNZ_ERRNO;
  42.765 +
  42.766 +	if (err == UNZ_OK)
  42.767 +		if (unzlocal_getLong(s->file, &uMagic) != UNZ_OK)
  42.768 +			err = UNZ_ERRNO;
  42.769 +		else if (uMagic != 0x04034b50)
  42.770 +			err = UNZ_BADZIPFILE;
  42.771 +
  42.772 +	if (unzlocal_getShort(s->file, &uData) != UNZ_OK)
  42.773 +		err = UNZ_ERRNO;
  42.774 +/*
  42.775 +        else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
  42.776 +                err=UNZ_BADZIPFILE;
  42.777 + */
  42.778 +	if (unzlocal_getShort(s->file, &uFlags) != UNZ_OK)
  42.779 +		err = UNZ_ERRNO;
  42.780 +
  42.781 +	if (unzlocal_getShort(s->file, &uData) != UNZ_OK)
  42.782 +		err = UNZ_ERRNO;
  42.783 +	else if ((err == UNZ_OK) && (uData != s->cur_file_info.compression_method))
  42.784 +		err = UNZ_BADZIPFILE;
  42.785 +
  42.786 +	if ((err == UNZ_OK) && (s->cur_file_info.compression_method != 0) &&
  42.787 +	    (s->cur_file_info.compression_method != Z_DEFLATED))
  42.788 +		err = UNZ_BADZIPFILE;
  42.789 +
  42.790 +	if (unzlocal_getLong(s->file, &uData) != UNZ_OK)    /* date/time */
  42.791 +		err = UNZ_ERRNO;
  42.792 +
  42.793 +	if (unzlocal_getLong(s->file, &uData) != UNZ_OK)    /* crc */
  42.794 +		err = UNZ_ERRNO;
  42.795 +	else if ((err == UNZ_OK) && (uData != s->cur_file_info.crc) &&
  42.796 +	         ((uFlags & 8) == 0))
  42.797 +		err = UNZ_BADZIPFILE;
  42.798 +
  42.799 +	if (unzlocal_getLong(s->file, &uData) != UNZ_OK)    /* size compr */
  42.800 +		err = UNZ_ERRNO;
  42.801 +	else if ((err == UNZ_OK) && (uData != s->cur_file_info.compressed_size) &&
  42.802 +	         ((uFlags & 8) == 0))
  42.803 +		err = UNZ_BADZIPFILE;
  42.804 +
  42.805 +	if (unzlocal_getLong(s->file, &uData) != UNZ_OK)    /* size uncompr */
  42.806 +		err = UNZ_ERRNO;
  42.807 +	else if ((err == UNZ_OK) && (uData != s->cur_file_info.uncompressed_size) &&
  42.808 +	         ((uFlags & 8) == 0))
  42.809 +		err = UNZ_BADZIPFILE;
  42.810 +
  42.811 +	if (unzlocal_getShort(s->file, &size_filename) != UNZ_OK)
  42.812 +		err = UNZ_ERRNO;
  42.813 +	else if ((err == UNZ_OK) && (size_filename != s->cur_file_info.size_filename))
  42.814 +		err = UNZ_BADZIPFILE;
  42.815 +
  42.816 +	*piSizeVar += (uInt)size_filename;
  42.817 +
  42.818 +	if (unzlocal_getShort(s->file, &size_extra_field) != UNZ_OK)
  42.819 +		err = UNZ_ERRNO;
  42.820 +	*poffset_local_extrafield = s->cur_file_info_internal.offset_curfile +
  42.821 +	                            SIZEZIPLOCALHEADER + size_filename;
  42.822 +	*psize_local_extrafield = (uInt)size_extra_field;
  42.823 +
  42.824 +	*piSizeVar += (uInt)size_extra_field;
  42.825 +
  42.826 +	return err;
  42.827 +}
  42.828 +
  42.829 +/*
  42.830 +   Open for reading data the current file in the zipfile.
  42.831 +   If there is no error and the file is opened, the return value is UNZ_OK.
  42.832 + */
  42.833 +extern int ZEXPORT unzOpenCurrentFile(unzFile file)
  42.834 +{
  42.835 +	int   err = UNZ_OK;
  42.836 +	int   Store;
  42.837 +	uInt  iSizeVar;
  42.838 +	unz_s*s;
  42.839 +	file_in_zip_read_info_s*pfile_in_zip_read_info;
  42.840 +	uLong offset_local_extrafield;      /* offset of the local extra field */
  42.841 +	uInt  size_local_extrafield;        /* size of the local extra field */
  42.842 +
  42.843 +	if (file == NULL)
  42.844 +		return UNZ_PARAMERROR;
  42.845 +	s = (unz_s *)file;
  42.846 +	if (!s->current_file_ok)
  42.847 +		return UNZ_PARAMERROR;
  42.848 +
  42.849 +	if (s->pfile_in_zip_read != NULL)
  42.850 +		unzCloseCurrentFile(file);
  42.851 +
  42.852 +	if (unzlocal_CheckCurrentFileCoherencyHeader(s, &iSizeVar,
  42.853 +	                                             &offset_local_extrafield, &size_local_extrafield) != UNZ_OK)
  42.854 +		return UNZ_BADZIPFILE;
  42.855 +
  42.856 +	pfile_in_zip_read_info = (file_in_zip_read_info_s *)
  42.857 +	                         ALLOC(sizeof(file_in_zip_read_info_s));
  42.858 +	if (pfile_in_zip_read_info == NULL)
  42.859 +		return UNZ_INTERNALERROR;
  42.860 +
  42.861 +	pfile_in_zip_read_info->read_buffer = (char *)ALLOC(UNZ_BUFSIZE);
  42.862 +	pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
  42.863 +	pfile_in_zip_read_info->size_local_extrafield   = size_local_extrafield;
  42.864 +	pfile_in_zip_read_info->pos_local_extrafield    = 0;
  42.865 +
  42.866 +	if (pfile_in_zip_read_info->read_buffer == NULL)
  42.867 +	{
  42.868 +		TRYFREE(pfile_in_zip_read_info);
  42.869 +		return UNZ_INTERNALERROR;
  42.870 +	}
  42.871 +
  42.872 +	pfile_in_zip_read_info->stream_initialised = 0;
  42.873 +
  42.874 +	if ((s->cur_file_info.compression_method != 0) &&
  42.875 +	    (s->cur_file_info.compression_method != Z_DEFLATED))
  42.876 +		err = UNZ_BADZIPFILE;
  42.877 +	Store = s->cur_file_info.compression_method == 0;
  42.878 +
  42.879 +	pfile_in_zip_read_info->crc32_wait         = s->cur_file_info.crc;
  42.880 +	pfile_in_zip_read_info->crc32              = 0;
  42.881 +	pfile_in_zip_read_info->compression_method =
  42.882 +	    s->cur_file_info.compression_method;
  42.883 +	pfile_in_zip_read_info->file = s->file;
  42.884 +	pfile_in_zip_read_info->byte_before_the_zipfile = s->byte_before_the_zipfile;
  42.885 +
  42.886 +	pfile_in_zip_read_info->stream.total_out = 0;
  42.887 +
  42.888 +	if (!Store)
  42.889 +	{
  42.890 +		pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
  42.891 +		pfile_in_zip_read_info->stream.zfree  = (free_func)0;
  42.892 +		pfile_in_zip_read_info->stream.opaque = (voidpf)0;
  42.893 +
  42.894 +		err = inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
  42.895 +		if (err == Z_OK)
  42.896 +			pfile_in_zip_read_info->stream_initialised = 1;
  42.897 +		/* windowBits is passed < 0 to tell that there is no zlib header.
  42.898 +		 * Note that in this case inflate *requires* an extra "dummy" byte
  42.899 +		 * after the compressed stream in order to complete decompression and
  42.900 +		 * return Z_STREAM_END.
  42.901 +		 * In unzip, i don't wait absolutely Z_STREAM_END because I known the
  42.902 +		 * size of both compressed and uncompressed data
  42.903 +		 */
  42.904 +	}
  42.905 +	pfile_in_zip_read_info->rest_read_compressed =
  42.906 +	    s->cur_file_info.compressed_size ;
  42.907 +	pfile_in_zip_read_info->rest_read_uncompressed =
  42.908 +	    s->cur_file_info.uncompressed_size ;
  42.909 +
  42.910 +	pfile_in_zip_read_info->pos_in_zipfile =
  42.911 +	    s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
  42.912 +	    iSizeVar;
  42.913 +
  42.914 +	pfile_in_zip_read_info->stream.avail_in = (uInt)0;
  42.915 +
  42.916 +	s->pfile_in_zip_read = pfile_in_zip_read_info;
  42.917 +	return UNZ_OK;
  42.918 +}
  42.919 +
  42.920 +/*
  42.921 +   Read bytes from the current file.
  42.922 +   buf contain buffer where data must be copied
  42.923 +   len the size of buf.
  42.924 +
  42.925 +   return the number of byte copied if somes bytes are copied
  42.926 +   return 0 if the end of file was reached
  42.927 +   return <0 with error code if there is an error
  42.928 +    (UNZ_ERRNO for IO error, or zLib error for uncompress error)
  42.929 + */
  42.930 +extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len)
  42.931 +{
  42.932 +	int   err   = UNZ_OK;
  42.933 +	uInt  iRead = 0;
  42.934 +	unz_s*s;
  42.935 +	file_in_zip_read_info_s*pfile_in_zip_read_info;
  42.936 +	if (file == NULL)
  42.937 +		return UNZ_PARAMERROR;
  42.938 +	s = (unz_s *)file;
  42.939 +	pfile_in_zip_read_info = s->pfile_in_zip_read;
  42.940 +
  42.941 +	if (pfile_in_zip_read_info == NULL)
  42.942 +		return UNZ_PARAMERROR;
  42.943 +
  42.944 +	if ((pfile_in_zip_read_info->read_buffer == NULL))
  42.945 +		return UNZ_END_OF_LIST_OF_FILE;
  42.946 +	if (len == 0)
  42.947 +		return 0;
  42.948 +
  42.949 +	pfile_in_zip_read_info->stream.next_out = (Bytef *)buf;
  42.950 +
  42.951 +	pfile_in_zip_read_info->stream.avail_out = (uInt)len;
  42.952 +
  42.953 +	if (len > pfile_in_zip_read_info->rest_read_uncompressed)
  42.954 +		pfile_in_zip_read_info->stream.avail_out =
  42.955 +		    (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
  42.956 +
  42.957 +	while (pfile_in_zip_read_info->stream.avail_out > 0)
  42.958 +	{
  42.959 +		if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
  42.960 +		    (pfile_in_zip_read_info->rest_read_compressed > 0))
  42.961 +		{
  42.962 +			uInt uReadThis = UNZ_BUFSIZE;
  42.963 +			if (pfile_in_zip_read_info->rest_read_compressed < uReadThis)
  42.964 +				uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
  42.965 +			if (uReadThis == 0)
  42.966 +				return UNZ_EOF;
  42.967 +			if (fseek(pfile_in_zip_read_info->file,
  42.968 +			          pfile_in_zip_read_info->pos_in_zipfile +
  42.969 +			          pfile_in_zip_read_info->byte_before_the_zipfile, SEEK_SET) != 0)
  42.970 +				return UNZ_ERRNO;
  42.971 +			if (fread(pfile_in_zip_read_info->read_buffer, uReadThis, 1,
  42.972 +			          pfile_in_zip_read_info->file) != 1)
  42.973 +				return UNZ_ERRNO;
  42.974 +			pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
  42.975 +
  42.976 +			pfile_in_zip_read_info->rest_read_compressed -= uReadThis;
  42.977 +
  42.978 +			pfile_in_zip_read_info->stream.next_in =
  42.979 +			    (Bytef *)pfile_in_zip_read_info->read_buffer;
  42.980 +			pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
  42.981 +		}
  42.982 +
  42.983 +		if (pfile_in_zip_read_info->compression_method == 0)
  42.984 +		{
  42.985 +			uInt uDoCopy, i ;
  42.986 +			if (pfile_in_zip_read_info->stream.avail_out <
  42.987 +			    pfile_in_zip_read_info->stream.avail_in)
  42.988 +				uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
  42.989 +			else
  42.990 +				uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
  42.991 +
  42.992 +			for (i = 0; i < uDoCopy; i++)
  42.993 +				*(pfile_in_zip_read_info->stream.next_out+i) =
  42.994 +				    *(pfile_in_zip_read_info->stream.next_in+i);
  42.995 +
  42.996 +			pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
  42.997 +			                                      pfile_in_zip_read_info->stream.next_out,
  42.998 +			                                      uDoCopy);
  42.999 +			pfile_in_zip_read_info->rest_read_uncompressed -= uDoCopy;
 42.1000 +			pfile_in_zip_read_info->stream.avail_in        -= uDoCopy;
 42.1001 +			pfile_in_zip_read_info->stream.avail_out       -= uDoCopy;
 42.1002 +			pfile_in_zip_read_info->stream.next_out        += uDoCopy;
 42.1003 +			pfile_in_zip_read_info->stream.next_in         += uDoCopy;
 42.1004 +			pfile_in_zip_read_info->stream.total_out       += uDoCopy;
 42.1005 +			iRead += uDoCopy;
 42.1006 +		}
 42.1007 +		else
 42.1008 +		{
 42.1009 +			uLong        uTotalOutBefore, uTotalOutAfter;
 42.1010 +			const Bytef *bufBefore;
 42.1011 +			uLong        uOutThis;
 42.1012 +			int flush = Z_SYNC_FLUSH;
 42.1013 +
 42.1014 +			uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
 42.1015 +			bufBefore       = pfile_in_zip_read_info->stream.next_out;
 42.1016 +
 42.1017 +			/*
 42.1018 +			   if ((pfile_in_zip_read_info->rest_read_uncompressed ==
 42.1019 +			         pfile_in_zip_read_info->stream.avail_out) &&
 42.1020 +			        (pfile_in_zip_read_info->rest_read_compressed == 0))
 42.1021 +			        flush = Z_FINISH;
 42.1022 +			 */
 42.1023 +			err = inflate(&pfile_in_zip_read_info->stream, flush);
 42.1024 +
 42.1025 +			uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
 42.1026 +			uOutThis       = uTotalOutAfter-uTotalOutBefore;
 42.1027 +
 42.1028 +			pfile_in_zip_read_info->crc32 =
 42.1029 +			    crc32(pfile_in_zip_read_info->crc32, bufBefore,
 42.1030 +			          (uInt)(uOutThis));
 42.1031 +
 42.1032 +			pfile_in_zip_read_info->rest_read_uncompressed -=
 42.1033 +			    uOutThis;
 42.1034 +
 42.1035 +			iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
 42.1036 +
 42.1037 +			if (err == Z_STREAM_END)
 42.1038 +				return (iRead == 0) ? UNZ_EOF : iRead;
 42.1039 +			if (err != Z_OK)
 42.1040 +				break;
 42.1041 +		}
 42.1042 +	}
 42.1043 +
 42.1044 +	if (err == Z_OK)
 42.1045 +		return iRead;
 42.1046 +	return err;
 42.1047 +}
 42.1048 +
 42.1049 +/*
 42.1050 +   Give the current position in uncompressed data
 42.1051 + */
 42.1052 +extern z_off_t ZEXPORT unztell(unzFile file)
 42.1053 +{
 42.1054 +	unz_s*s;
 42.1055 +	file_in_zip_read_info_s*pfile_in_zip_read_info;
 42.1056 +	if (file == NULL)
 42.1057 +		return UNZ_PARAMERROR;
 42.1058 +	s = (unz_s *)file;
 42.1059 +	pfile_in_zip_read_info = s->pfile_in_zip_read;
 42.1060 +
 42.1061 +	if (pfile_in_zip_read_info == NULL)
 42.1062 +		return UNZ_PARAMERROR;
 42.1063 +
 42.1064 +	return (z_off_t)pfile_in_zip_read_info->stream.total_out;
 42.1065 +}
 42.1066 +
 42.1067 +/*
 42.1068 +   return 1 if the end of file was reached, 0 elsewhere
 42.1069 + */
 42.1070 +extern int ZEXPORT unzeof(unzFile file)
 42.1071 +{
 42.1072 +	unz_s*s;
 42.1073 +	file_in_zip_read_info_s*pfile_in_zip_read_info;
 42.1074 +	if (file == NULL)
 42.1075 +		return UNZ_PARAMERROR;
 42.1076 +	s = (unz_s *)file;
 42.1077 +	pfile_in_zip_read_info = s->pfile_in_zip_read;
 42.1078 +
 42.1079 +	if (pfile_in_zip_read_info == NULL)
 42.1080 +		return UNZ_PARAMERROR;
 42.1081 +
 42.1082 +	if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
 42.1083 +		return 1;
 42.1084 +	else
 42.1085 +		return 0;
 42.1086 +}
 42.1087 +
 42.1088 +/*
 42.1089 +   Read extra field from the current file (opened by unzOpenCurrentFile)
 42.1090 +   This is the local-header version of the extra field (sometimes, there is
 42.1091 +    more info in the local-header version than in the central-header)
 42.1092 +
 42.1093 +   if buf==NULL, it return the size of the local extra field that can be read
 42.1094 +
 42.1095 +   if buf!=NULL, len is the size of the buffer, the extra header is copied in
 42.1096 +        buf.
 42.1097 +   the return value is the number of bytes copied in buf, or (if <0)
 42.1098 +        the error code
 42.1099 + */
 42.1100 +extern int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, unsigned len)
 42.1101 +{
 42.1102 +	unz_s*s;
 42.1103 +	file_in_zip_read_info_s*pfile_in_zip_read_info;
 42.1104 +	uInt  read_now;
 42.1105 +	uLong size_to_read;
 42.1106 +
 42.1107 +	if (file == NULL)
 42.1108 +		return UNZ_PARAMERROR;
 42.1109 +	s = (unz_s *)file;
 42.1110 +	pfile_in_zip_read_info = s->pfile_in_zip_read;
 42.1111 +
 42.1112 +	if (pfile_in_zip_read_info == NULL)
 42.1113 +		return UNZ_PARAMERROR;
 42.1114 +
 42.1115 +	size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
 42.1116 +	                pfile_in_zip_read_info->pos_local_extrafield);
 42.1117 +
 42.1118 +	if (buf == NULL)
 42.1119 +		return (int)size_to_read;
 42.1120 +
 42.1121 +	if (len > size_to_read)
 42.1122 +		read_now = (uInt)size_to_read;
 42.1123 +	else
 42.1124 +		read_now = (uInt)len ;
 42.1125 +
 42.1126 +	if (read_now == 0)
 42.1127 +		return 0;
 42.1128 +
 42.1129 +	if (fseek(pfile_in_zip_read_info->file,
 42.1130 +	          pfile_in_zip_read_info->offset_local_extrafield +
 42.1131 +	          pfile_in_zip_read_info->pos_local_extrafield, SEEK_SET) != 0)
 42.1132 +		return UNZ_ERRNO;
 42.1133 +
 42.1134 +	if (fread(buf, (uInt)size_to_read, 1, pfile_in_zip_read_info->file) != 1)
 42.1135 +		return UNZ_ERRNO;
 42.1136 +
 42.1137 +	return (int)read_now;
 42.1138 +}
 42.1139 +
 42.1140 +/*
 42.1141 +   Close the file in zip opened with unzipOpenCurrentFile
 42.1142 +   Return UNZ_CRCERROR if all the file was read but the CRC is not good
 42.1143 + */
 42.1144 +extern int ZEXPORT unzCloseCurrentFile(unzFile file)
 42.1145 +{
 42.1146 +	int err = UNZ_OK;
 42.1147 +
 42.1148 +	unz_s*s;
 42.1149 +	file_in_zip_read_info_s*pfile_in_zip_read_info;
 42.1150 +	if (file == NULL)
 42.1151 +		return UNZ_PARAMERROR;
 42.1152 +	s = (unz_s *)file;
 42.1153 +	pfile_in_zip_read_info = s->pfile_in_zip_read;
 42.1154 +
 42.1155 +	if (pfile_in_zip_read_info == NULL)
 42.1156 +		return UNZ_PARAMERROR;
 42.1157 +
 42.1158 +	if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
 42.1159 +	{
 42.1160 +		if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
 42.1161 +			err = UNZ_CRCERROR;
 42.1162 +	}
 42.1163 +
 42.1164 +	TRYFREE(pfile_in_zip_read_info->read_buffer);
 42.1165 +	pfile_in_zip_read_info->read_buffer = NULL;
 42.1166 +	if (pfile_in_zip_read_info->stream_initialised)
 42.1167 +		inflateEnd(&pfile_in_zip_read_info->stream);
 42.1168 +
 42.1169 +	pfile_in_zip_read_info->stream_initialised = 0;
 42.1170 +	TRYFREE(pfile_in_zip_read_info);
 42.1171 +
 42.1172 +	s->pfile_in_zip_read = NULL;
 42.1173 +
 42.1174 +	return err;
 42.1175 +}
 42.1176 +
 42.1177 +/*
 42.1178 +   Get the global comment string of the ZipFile, in the szComment buffer.
 42.1179 +   uSizeBuf is the size of the szComment buffer.
 42.1180 +   return the number of byte copied or an error code <0
 42.1181 + */
 42.1182 +extern int ZEXPORT unzGetGlobalComment(unzFile file,
 42.1183 +                                       char *szComment,
 42.1184 +                                       uLong uSizeBuf)
 42.1185 +{
 42.1186 +	//int err=UNZ_OK;
 42.1187 +	unz_s*s;
 42.1188 +	uLong uReadThis ;
 42.1189 +	if (file == NULL)
 42.1190 +		return UNZ_PARAMERROR;
 42.1191 +	s = (unz_s *)file;
 42.1192 +
 42.1193 +	uReadThis = uSizeBuf;
 42.1194 +	if (uReadThis > s->gi.size_comment)
 42.1195 +		uReadThis = s->gi.size_comment;
 42.1196 +
 42.1197 +	if (fseek(s->file, s->central_pos+22, SEEK_SET) != 0)
 42.1198 +		return UNZ_ERRNO;
 42.1199 +
 42.1200 +	if (uReadThis > 0)
 42.1201 +	{
 42.1202 +		*szComment = '\0';
 42.1203 +		if (fread(szComment, (uInt)uReadThis, 1, s->file) != 1)
 42.1204 +			return UNZ_ERRNO;
 42.1205 +	}
 42.1206 +
 42.1207 +	if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
 42.1208 +		*(szComment+s->gi.size_comment) = '\0';
 42.1209 +	return (int)uReadThis;
 42.1210 +}
 42.1211 +
    43.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.2 +++ b/src/common/unzip.h	Sat Mar 03 10:31:27 2012 -0600
    43.3 @@ -0,0 +1,275 @@
    43.4 +/* unzip.h -- IO for uncompress .zip files using zlib 
    43.5 +   Version 0.15 beta, Mar 19th, 1998,
    43.6 +
    43.7 +   Copyright (C) 1998 Gilles Vollant
    43.8 +
    43.9 +   This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
   43.10 +     WinZip, InfoZip tools and compatible.
   43.11 +   Encryption and multi volume ZipFile (span) are not supported.
   43.12 +   Old compressions used by old PKZip 1.x are not supported
   43.13 +
   43.14 +   THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
   43.15 +   CAN CHANGE IN FUTURE VERSION !!
   43.16 +   I WAIT FEEDBACK at mail info@winimage.com
   43.17 +   Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
   43.18 +
   43.19 +   Condition of use and distribution are the same than zlib :
   43.20 +
   43.21 +  This software is provided 'as-is', without any express or implied
   43.22 +  warranty.  In no event will the authors be held liable for any damages
   43.23 +  arising from the use of this software.
   43.24 +
   43.25 +  Permission is granted to anyone to use this software for any purpose,
   43.26 +  including commercial applications, and to alter it and redistribute it
   43.27 +  freely, subject to the following restrictions:
   43.28 +
   43.29 +  1. The origin of this software must not be misrepresented; you must not
   43.30 +     claim that you wrote the original software. If you use this software
   43.31 +     in a product, an acknowledgment in the product documentation would be
   43.32 +     appreciated but is not required.
   43.33 +  2. Altered source versions must be plainly marked as such, and must not be
   43.34 +     misrepresented as being the original software.
   43.35 +  3. This notice may not be removed or altered from any source distribution.
   43.36 +
   43.37 +
   43.38 +*/
   43.39 +/* for more info about .ZIP format, see 
   43.40 +      ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
   43.41 +   PkWare has also a specification at :
   43.42 +      ftp://ftp.pkware.com/probdesc.zip */
   43.43 +
   43.44 +#ifndef _unz_H
   43.45 +#define _unz_H
   43.46 +
   43.47 +#ifdef __cplusplus
   43.48 +extern "C" {
   43.49 +#endif
   43.50 +
   43.51 +#ifndef _ZLIB_H
   43.52 +#include "zlib.h"
   43.53 +#endif
   43.54 +
   43.55 +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
   43.56 +/* like the STRICT of WIN32, we define a pointer that cannot be converted
   43.57 +    from (void*) without cast */
   43.58 +typedef struct TagunzFile__ { int unused; } unzFile__; 
   43.59 +typedef unzFile__ *unzFile;
   43.60 +#else
   43.61 +typedef voidp unzFile;
   43.62 +#endif
   43.63 +
   43.64 +
   43.65 +#define UNZ_OK                                  (0)
   43.66 +#define UNZ_END_OF_LIST_OF_FILE (-100)
   43.67 +#define UNZ_ERRNO               (Z_ERRNO)
   43.68 +#define UNZ_EOF                 (0)
   43.69 +#define UNZ_PARAMERROR                  (-102)
   43.70 +#define UNZ_BADZIPFILE                  (-103)
   43.71 +#define UNZ_INTERNALERROR               (-104)
   43.72 +#define UNZ_CRCERROR                    (-105)
   43.73 +
   43.74 +/* tm_unz contain date/time info */
   43.75 +typedef struct tm_unz_s 
   43.76 +{
   43.77 +        uInt tm_sec;            /* seconds after the minute - [0,59] */
   43.78 +        uInt tm_min;            /* minutes after the hour - [0,59] */
   43.79 +        uInt tm_hour;           /* hours since midnight - [0,23] */
   43.80 +        uInt tm_mday;           /* day of the month - [1,31] */
   43.81 +        uInt tm_mon;            /* months since January - [0,11] */
   43.82 +        uInt tm_year;           /* years - [1980..2044] */
   43.83 +} tm_unz;
   43.84 +
   43.85 +/* unz_global_info structure contain global data about the ZIPfile
   43.86 +   These data comes from the end of central dir */
   43.87 +typedef struct unz_global_info_s
   43.88 +{
   43.89 +        uLong number_entry;         /* total number of entries in
   43.90 +                                       the central dir on this disk */
   43.91 +        uLong size_comment;         /* size of the global comment of the zipfile */
   43.92 +} unz_global_info;
   43.93 +
   43.94 +
   43.95 +/* unz_file_info contain information about a file in the zipfile */
   43.96 +typedef struct unz_file_info_s
   43.97 +{
   43.98 +    uLong version;              /* version made by                 2 bytes */
   43.99 +    uLong version_needed;       /* version needed to extract       2 bytes */
  43.100 +    uLong flag;                 /* general purpose bit flag        2 bytes */
  43.101 +    uLong compression_method;   /* compression method              2 bytes */
  43.102 +    uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
  43.103 +    uLong crc;                  /* crc-32                          4 bytes */
  43.104 +    uLong compressed_size;      /* compressed size                 4 bytes */ 
  43.105 +    uLong uncompressed_size;    /* uncompressed size               4 bytes */ 
  43.106 +    uLong size_filename;        /* filename length                 2 bytes */
  43.107 +    uLong size_file_extra;      /* extra field length              2 bytes */
  43.108 +    uLong size_file_comment;    /* file comment length             2 bytes */
  43.109 +
  43.110 +    uLong disk_num_start;       /* disk number start               2 bytes */
  43.111 +    uLong internal_fa;          /* internal file attributes        2 bytes */
  43.112 +    uLong external_fa;          /* external file attributes        4 bytes */
  43.113 +
  43.114 +    tm_unz tmu_date;
  43.115 +} unz_file_info;
  43.116 +
  43.117 +extern int ZEXPORT  unzStringFileNameCompare OF ((const char* fileName1,
  43.118 +                                                 const char* fileName2,
  43.119 +                                                 int iCaseSensitivity));
  43.120 +/*
  43.121 +   Compare two filename (fileName1,fileName2).
  43.122 +   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
  43.123 +   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
  43.124 +                                                                or strcasecmp)
  43.125 +   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
  43.126 +        (like 1 on Unix, 2 on Windows)
  43.127 +*/
  43.128 +
  43.129 +
  43.130 +extern unzFile ZEXPORT  unzOpen OF((const char *path));
  43.131 +/*
  43.132 +  Open a Zip file. path contain the full pathname (by example,
  43.133 +     on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
  43.134 +         "zlib/zlib111.zip".
  43.135 +         If the zipfile cannot be opened (file don't exist or in not valid), the
  43.136 +           return value is NULL.
  43.137 +     Else, the return value is a unzFile Handle, usable with other function
  43.138 +           of this unzip package.
  43.139 +*/
  43.140 +
  43.141 +extern int ZEXPORT  unzClose OF((unzFile file));
  43.142 +/*
  43.143 +  Close a ZipFile opened with unzipOpen.
  43.144 +  If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
  43.145 +    these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
  43.146 +  return UNZ_OK if there is no problem. */
  43.147 +
  43.148 +extern int ZEXPORT  unzGetGlobalInfo OF((unzFile file,
  43.149 +                                        unz_global_info *pglobal_info));
  43.150 +/*
  43.151 +  Write info about the ZipFile in the *pglobal_info structure.
  43.152 +  No preparation of the structure is needed
  43.153 +  return UNZ_OK if there is no problem. */
  43.154 +
  43.155 +
  43.156 +extern int ZEXPORT  unzGetGlobalComment OF((unzFile file,
  43.157 +                                           char *szComment,
  43.158 +                                           uLong uSizeBuf));
  43.159 +/*
  43.160 +  Get the global comment string of the ZipFile, in the szComment buffer.
  43.161 +  uSizeBuf is the size of the szComment buffer.
  43.162 +  return the number of byte copied or an error code <0
  43.163 +*/
  43.164 +
  43.165 +
  43.166 +/***************************************************************************/
  43.167 +/* Unzip package allow you browse the directory of the zipfile */
  43.168 +
  43.169 +extern int ZEXPORT  unzGoToFirstFile OF((unzFile file));
  43.170 +/*
  43.171 +  Set the current file of the zipfile to the first file.
  43.172 +  return UNZ_OK if there is no problem
  43.173 +*/
  43.174 +
  43.175 +extern int ZEXPORT  unzGoToNextFile OF((unzFile file));
  43.176 +/*
  43.177 +  Set the current file of the zipfile to the next file.
  43.178 +  return UNZ_OK if there is no problem
  43.179 +  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
  43.180 +*/
  43.181 +
  43.182 +extern int ZEXPORT  unzLocateFile OF((unzFile file, 
  43.183 +                                     const char *szFileName,
  43.184 +                                     int iCaseSensitivity));
  43.185 +/*
  43.186 +  Try locate the file szFileName in the zipfile.
  43.187 +  For the iCaseSensitivity signification, see unzStringFileNameCompare
  43.188 +
  43.189 +  return value :
  43.190 +  UNZ_OK if the file is found. It becomes the current file.
  43.191 +  UNZ_END_OF_LIST_OF_FILE if the file is not found
  43.192 +*/
  43.193 +
  43.194 +
  43.195 +extern int ZEXPORT  unzGetCurrentFileInfo OF((unzFile file,
  43.196 +                                             unz_file_info *pfile_info,
  43.197 +                                             char *szFileName,
  43.198 +                                             uLong fileNameBufferSize,
  43.199 +                                             void *extraField,
  43.200 +                                             uLong extraFieldBufferSize,
  43.201 +                                             char *szComment,
  43.202 +                                             uLong commentBufferSize));
  43.203 +/*
  43.204 +  Get Info about the current file
  43.205 +  if pfile_info!=NULL, the *pfile_info structure will contain somes info about
  43.206 +            the current file
  43.207 +  if szFileName!=NULL, the filemane string will be copied in szFileName
  43.208 +                        (fileNameBufferSize is the size of the buffer)
  43.209 +  if extraField!=NULL, the extra field information will be copied in extraField
  43.210 +                        (extraFieldBufferSize is the size of the buffer).
  43.211 +                        This is the Central-header version of the extra field
  43.212 +  if szComment!=NULL, the comment string of the file will be copied in szComment
  43.213 +                        (commentBufferSize is the size of the buffer)
  43.214 +*/
  43.215 +
  43.216 +/***************************************************************************/
  43.217 +/* for reading the content of the current zipfile, you can open it, read data
  43.218 +   from it, and close it (you can close it before reading all the file)
  43.219 +   */
  43.220 +
  43.221 +extern int ZEXPORT  unzOpenCurrentFile OF((unzFile file));
  43.222 +/*
  43.223 +  Open for reading data the current file in the zipfile.
  43.224 +  If there is no error, the return value is UNZ_OK.
  43.225 +*/
  43.226 +
  43.227 +extern int ZEXPORT  unzCloseCurrentFile OF((unzFile file));
  43.228 +/*
  43.229 +  Close the file in zip opened with unzOpenCurrentFile
  43.230 +  Return UNZ_CRCERROR if all the file was read but the CRC is not good
  43.231 +*/
  43.232 +
  43.233 +                                                                                                
  43.234 +extern int ZEXPORT  unzReadCurrentFile OF((unzFile file, 
  43.235 +                                          voidp buf,
  43.236 +                                          unsigned len));
  43.237 +/*
  43.238 +  Read bytes from the current file (opened by unzOpenCurrentFile)
  43.239 +  buf contain buffer where data must be copied
  43.240 +  len the size of buf.
  43.241 +
  43.242 +  return the number of byte copied if somes bytes are copied
  43.243 +  return 0 if the end of file was reached
  43.244 +  return <0 with error code if there is an error
  43.245 +    (UNZ_ERRNO for IO error, or zLib error for uncompress error)
  43.246 +*/
  43.247 +
  43.248 +extern z_off_t ZEXPORT  unztell OF((unzFile file));
  43.249 +/*
  43.250 +  Give the current position in uncompressed data
  43.251 +*/
  43.252 +
  43.253 +extern int ZEXPORT  unzeof OF((unzFile file));
  43.254 +/*
  43.255 +  return 1 if the end of file was reached, 0 elsewhere 
  43.256 +*/
  43.257 +
  43.258 +extern int ZEXPORT  unzGetLocalExtrafield OF((unzFile file,
  43.259 +                                             voidp buf,
  43.260 +                                             unsigned len));
  43.261 +/*
  43.262 +  Read extra field from the current file (opened by unzOpenCurrentFile)
  43.263 +  This is the local-header version of the extra field (sometimes, there is
  43.264 +    more info in the local-header version than in the central-header)
  43.265 +
  43.266 +  if buf==NULL, it return the size of the local extra field
  43.267 +
  43.268 +  if buf!=NULL, len is the size of the buffer, the extra header is copied in
  43.269 +        buf.
  43.270 +  the return value is the number of bytes copied in buf, or (if <0) 
  43.271 +        the error code
  43.272 +*/
  43.273 +
  43.274 +#ifdef __cplusplus
  43.275 +}
  43.276 +#endif
  43.277 +
  43.278 +#endif /* _unz_H */
    44.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.2 +++ b/src/common/vbalua.h	Sat Mar 03 10:31:27 2012 -0600
    44.3 @@ -0,0 +1,52 @@
    44.4 +#ifndef VBA_LUA_H
    44.5 +#define VBA_LUA_H
    44.6 +
    44.7 +#if _MSC_VER > 1000
    44.8 +#pragma once
    44.9 +#endif // _MSC_VER > 1000
   44.10 +
   44.11 +enum LuaCallID
   44.12 +{
   44.13 +	LUACALL_BEFOREEMULATION,
   44.14 +	LUACALL_AFTEREMULATION,
   44.15 +	LUACALL_BEFOREEXIT,
   44.16 +
   44.17 +	LUACALL_COUNT
   44.18 +};
   44.19 +void CallRegisteredLuaFunctions(LuaCallID calltype);
   44.20 +
   44.21 +enum LuaMemHookType
   44.22 +{
   44.23 +	LUAMEMHOOK_WRITE,
   44.24 +	LUAMEMHOOK_READ,
   44.25 +	LUAMEMHOOK_EXEC,
   44.26 +	LUAMEMHOOK_WRITE_SUB,
   44.27 +	LUAMEMHOOK_READ_SUB,
   44.28 +	LUAMEMHOOK_EXEC_SUB,
   44.29 +
   44.30 +	LUAMEMHOOK_COUNT
   44.31 +};
   44.32 +void CallRegisteredLuaMemHook(unsigned int address, int size, unsigned int value, LuaMemHookType hookType);
   44.33 +
   44.34 +// Just forward function declarations
   44.35 +
   44.36 +void VBALuaFrameBoundary();
   44.37 +int VBALoadLuaCode(const char *filename);
   44.38 +int VBAReloadLuaCode();
   44.39 +void VBALuaStop();
   44.40 +int VBALuaRunning();
   44.41 +
   44.42 +int VBALuaUsingJoypad(int);
   44.43 +int VBALuaReadJoypad(int);
   44.44 +int VBALuaSpeed();
   44.45 +bool8 VBALuaRerecordCountSkip();
   44.46 +
   44.47 +void VBALuaGui(uint8 *screen, int ppl, int width, int height);
   44.48 +void VBALuaClearGui();
   44.49 +
   44.50 +char* VBAGetLuaScriptName();
   44.51 +
   44.52 +// And some interesting REVERSE declarations!
   44.53 +char *VBAGetFreezeFilename(int slot);
   44.54 +
   44.55 +#endif // VBA_LUA_H
    45.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.2 +++ b/src/filters/2xSaI.cpp	Sat Mar 03 10:31:27 2012 -0600
    45.3 @@ -0,0 +1,1434 @@
    45.4 +#include "../common/System.h"
    45.5 +
    45.6 +extern "C"
    45.7 +{
    45.8 +#ifdef MMX
    45.9 +	void _2xSaILine(u8 *srcPtr, u8 *deltaPtr, u32 srcPitch,
   45.10 +	                u32 width, u8 *dstPtr, u32 dstPitch);
   45.11 +	void _2xSaISuperEagleLine(u8 *srcPtr, u8 *deltaPtr,
   45.12 +	                          u32 srcPitch, u32 width,
   45.13 +	                          u8 *dstPtr, u32 dstPitch);
   45.14 +	void _2xSaISuper2xSaILine(u8 *srcPtr, u8 *deltaPtr,
   45.15 +	                          u32 srcPitch, u32 width,
   45.16 +	                          u8 *dstPtr, u32 dstPitch);
   45.17 +	void Init_2xSaIMMX(u32 BitFormat);
   45.18 +	void BilinearMMX(u16 *A, u16 *B, u16 *C, u16 *D,
   45.19 +	                 u16 *dx, u16 *dy, u8 *dP);
   45.20 +	void BilinearMMXGrid0(u16 *A, u16 *B, u16 *C, u16 *D,
   45.21 +	                      u16 *dx, u16 *dy, u8 *dP);
   45.22 +	void BilinearMMXGrid1(u16 *A, u16 *B, u16 *C, u16 *D,
   45.23 +	                      u16 *dx, u16 *dy, u8 *dP);
   45.24 +	void EndMMX();
   45.25 +
   45.26 +	bool cpu_mmx = 1;
   45.27 +#endif
   45.28 +}
   45.29 +static u32 colorMask	 = 0xF7DEF7DE;
   45.30 +static u32 lowPixelMask	 = 0x08210821;
   45.31 +static u32 qcolorMask	 = 0xE79CE79C;
   45.32 +static u32 qlowpixelMask = 0x18631863;
   45.33 +static u32 redblueMask	 = 0xF81F;
   45.34 +static u32 greenMask	 = 0x7E0;
   45.35 +
   45.36 +u32 qRGB_COLOR_MASK[2] = { 0xF7DEF7DE, 0xF7DEF7DE };
   45.37 +
   45.38 +extern void hq2x_init(unsigned);
   45.39 +
   45.40 +int Init_2xSaI(u32 BitFormat)
   45.41 +{
   45.42 +	if (systemColorDepth == 16)
   45.43 +	{
   45.44 +		if (BitFormat == 565)
   45.45 +		{
   45.46 +			colorMask		   = 0xF7DEF7DE;
   45.47 +			lowPixelMask	   = 0x08210821;
   45.48 +			qcolorMask		   = 0xE79CE79C;
   45.49 +			qlowpixelMask	   = 0x18631863;
   45.50 +			redblueMask		   = 0xF81F;
   45.51 +			greenMask		   = 0x7E0;
   45.52 +			qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0xF7DEF7DE;
   45.53 +			hq2x_init(16);
   45.54 +		}
   45.55 +		else if (BitFormat == 555)
   45.56 +		{
   45.57 +			colorMask		   = 0x7BDE7BDE;
   45.58 +			lowPixelMask	   = 0x04210421;
   45.59 +			qcolorMask		   = 0x739C739C;
   45.60 +			qlowpixelMask	   = 0x0C630C63;
   45.61 +			redblueMask		   = 0x7C1F;
   45.62 +			greenMask		   = 0x3E0;
   45.63 +			qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0x7BDE7BDE;
   45.64 +			hq2x_init(15);
   45.65 +		}
   45.66 +		else
   45.67 +		{
   45.68 +			return 0;
   45.69 +		}
   45.70 +	}
   45.71 +	else if (systemColorDepth == 32)
   45.72 +	{
   45.73 +		colorMask		   = 0xfefefe;
   45.74 +		lowPixelMask	   = 0x010101;
   45.75 +		qcolorMask		   = 0xfcfcfc;
   45.76 +		qlowpixelMask	   = 0x030303;
   45.77 +		qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0xfefefe;
   45.78 +		hq2x_init(32);
   45.79 +	}
   45.80 +	else
   45.81 +		return 0;
   45.82 +
   45.83 +#ifdef MMX
   45.84 +	Init_2xSaIMMX(BitFormat);
   45.85 +#endif
   45.86 +
   45.87 +	return 1;
   45.88 +}
   45.89 +
   45.90 +static inline int GetResult1(u32 A, u32 B, u32 C, u32 D,
   45.91 +                             u32 /* E */)
   45.92 +{
   45.93 +	int x = 0;
   45.94 +	int y = 0;
   45.95 +	int r = 0;
   45.96 +
   45.97 +	if (A == C)
   45.98 +		x += 1;
   45.99 +	else if (B == C)
  45.100 +		y += 1;
  45.101 +	if (A == D)
  45.102 +		x += 1;
  45.103 +	else if (B == D)
  45.104 +		y += 1;
  45.105 +	if (x <= 1)
  45.106 +		r += 1;
  45.107 +	if (y <= 1)
  45.108 +		r -= 1;
  45.109 +	return r;
  45.110 +}
  45.111 +
  45.112 +static inline int GetResult2(u32 A, u32 B, u32 C, u32 D,
  45.113 +                             u32 /* E */)
  45.114 +{
  45.115 +	int x = 0;
  45.116 +	int y = 0;
  45.117 +	int r = 0;
  45.118 +
  45.119 +	if (A == C)
  45.120 +		x += 1;
  45.121 +	else if (B == C)
  45.122 +		y += 1;
  45.123 +	if (A == D)
  45.124 +		x += 1;
  45.125 +	else if (B == D)
  45.126 +		y += 1;
  45.127 +	if (x <= 1)
  45.128 +		r -= 1;
  45.129 +	if (y <= 1)
  45.130 +		r += 1;
  45.131 +	return r;
  45.132 +}
  45.133 +
  45.134 +static inline int GetResult(u32 A, u32 B, u32 C, u32 D)
  45.135 +{
  45.136 +	int x = 0;
  45.137 +	int y = 0;
  45.138 +	int r = 0;
  45.139 +
  45.140 +	if (A == C)
  45.141 +		x += 1;
  45.142 +	else if (B == C)
  45.143 +		y += 1;
  45.144 +	if (A == D)
  45.145 +		x += 1;
  45.146 +	else if (B == D)
  45.147 +		y += 1;
  45.148 +	if (x <= 1)
  45.149 +		r += 1;
  45.150 +	if (y <= 1)
  45.151 +		r -= 1;
  45.152 +	return r;
  45.153 +}
  45.154 +
  45.155 +static inline u32 INTERPOLATE(u32 A, u32 B)
  45.156 +{
  45.157 +	if (A != B)
  45.158 +	{
  45.159 +		return (((A & colorMask) >> 1) + ((B & colorMask) >> 1) +
  45.160 +		        (A & B & lowPixelMask));
  45.161 +	}
  45.162 +	else
  45.163 +		return A;
  45.164 +}
  45.165 +
  45.166 +static inline u32 Q_INTERPOLATE(u32 A, u32 B, u32 C, u32 D)
  45.167 +{
  45.168 +	register u32 x = ((A & qcolorMask) >> 2) +
  45.169 +	                 ((B & qcolorMask) >> 2) +
  45.170 +	                 ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2);
  45.171 +	register u32 y = (A & qlowpixelMask) +
  45.172 +	                 (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask);
  45.173 +
  45.174 +	y = (y >> 2) & qlowpixelMask;
  45.175 +	return x + y;
  45.176 +}
  45.177 +
  45.178 +static inline int GetResult1_32(u32 A, u32 B, u32 C, u32 D,
  45.179 +                                u32 /* E */)
  45.180 +{
  45.181 +	int x = 0;
  45.182 +	int y = 0;
  45.183 +	int r = 0;
  45.184 +
  45.185 +	if (A == C)
  45.186 +		x += 1;
  45.187 +	else if (B == C)
  45.188 +		y += 1;
  45.189 +	if (A == D)
  45.190 +		x += 1;
  45.191 +	else if (B == D)
  45.192 +		y += 1;
  45.193 +	if (x <= 1)
  45.194 +		r += 1;
  45.195 +	if (y <= 1)
  45.196 +		r -= 1;
  45.197 +	return r;
  45.198 +}
  45.199 +
  45.200 +static inline int GetResult2_32(u32 A, u32 B, u32 C, u32 D,
  45.201 +                                u32 /* E */)
  45.202 +{
  45.203 +	int x = 0;
  45.204 +	int y = 0;
  45.205 +	int r = 0;
  45.206 +
  45.207 +	if (A == C)
  45.208 +		x += 1;
  45.209 +	else if (B == C)
  45.210 +		y += 1;
  45.211 +	if (A == D)
  45.212 +		x += 1;
  45.213 +	else if (B == D)
  45.214 +		y += 1;
  45.215 +	if (x <= 1)
  45.216 +		r -= 1;
  45.217 +	if (y <= 1)
  45.218 +		r += 1;
  45.219 +	return r;
  45.220 +}
  45.221 +
  45.222 +#define BLUE_MASK565 0x001F001F
  45.223 +#define RED_MASK565 0xF800F800
  45.224 +#define GREEN_MASK565 0x07E007E0
  45.225 +
  45.226 +#define BLUE_MASK555 0x001F001F
  45.227 +#define RED_MASK555 0x7C007C00
  45.228 +#define GREEN_MASK555 0x03E003E0
  45.229 +
  45.230 +void Super2xSaI(u8 *srcPtr, u32 srcPitch,
  45.231 +                u8 *deltaPtr, u8 *dstPtr, u32 dstPitch,
  45.232 +                int width, int height)
  45.233 +{
  45.234 +	u16 *bP;
  45.235 +	u8 * dP;
  45.236 +	u32	 inc_bP;
  45.237 +	u32	 Nextline = srcPitch >> 1;
  45.238 +#ifdef MMX
  45.239 +	if (cpu_mmx)
  45.240 +	{
  45.241 +		for (; height; height--)
  45.242 +		{
  45.243 +			_2xSaISuper2xSaILine(srcPtr, deltaPtr, srcPitch, width,
  45.244 +			                     dstPtr, dstPitch);
  45.245 +			srcPtr	 += srcPitch;
  45.246 +			dstPtr	 += dstPitch * 2;
  45.247 +			deltaPtr += srcPitch;
  45.248 +		}
  45.249 +	}
  45.250 +	else
  45.251 +#endif
  45.252 +	{
  45.253 +		inc_bP = 1;
  45.254 +
  45.255 +		for (; height; height--)
  45.256 +		{
  45.257 +			bP = (u16 *) srcPtr;
  45.258 +			dP = (u8 *) dstPtr;
  45.259 +
  45.260 +			for (u32 finish = width; finish; finish -= inc_bP)
  45.261 +			{
  45.262 +				u32 color4, color5, color6;
  45.263 +				u32 color1, color2, color3;
  45.264 +				u32 colorA0, colorA1, colorA2, colorA3,
  45.265 +				    colorB0, colorB1, colorB2, colorB3, colorS1, colorS2;
  45.266 +				u32 product1a, product1b, product2a, product2b;
  45.267 +
  45.268 +				//---------------------------------------    B1 B2
  45.269 +				//                                         4  5  6 S2
  45.270 +				//                                         1  2  3 S1
  45.271 +				//                                           A1 A2
  45.272 +
  45.273 +				colorB0 = *(bP - Nextline - 1);
  45.274 +				colorB1 = *(bP - Nextline);
  45.275 +				colorB2 = *(bP - Nextline + 1);
  45.276 +				colorB3 = *(bP - Nextline + 2);
  45.277 +
  45.278 +				color4	= *(bP - 1);
  45.279 +				color5	= *(bP);
  45.280 +				color6	= *(bP + 1);
  45.281 +				colorS2 = *(bP + 2);
  45.282 +
  45.283 +				color1	= *(bP + Nextline - 1);
  45.284 +				color2	= *(bP + Nextline);
  45.285 +				color3	= *(bP + Nextline + 1);
  45.286 +				colorS1 = *(bP + Nextline + 2);
  45.287 +
  45.288 +				colorA0 = *(bP + Nextline + Nextline - 1);
  45.289 +				colorA1 = *(bP + Nextline + Nextline);
  45.290 +				colorA2 = *(bP + Nextline + Nextline + 1);
  45.291 +				colorA3 = *(bP + Nextline + Nextline + 2);
  45.292 +
  45.293 +				//--------------------------------------
  45.294 +				if (color2 == color6 && color5 != color3)
  45.295 +				{
  45.296 +					product2b = product1b = color2;
  45.297 +				}
  45.298 +				else if (color5 == color3 && color2 != color6)
  45.299 +				{
  45.300 +					product2b = product1b = color5;
  45.301 +				}
  45.302 +				else if (color5 == color3 && color2 == color6)
  45.303 +				{
  45.304 +					register int r = 0;
  45.305 +
  45.306 +					r += GetResult(color6, color5, color1, colorA1);
  45.307 +					r += GetResult(color6, color5, color4, colorB1);
  45.308 +					r += GetResult(color6, color5, colorA2, colorS1);
  45.309 +					r += GetResult(color6, color5, colorB2, colorS2);
  45.310 +
  45.311 +					if (r > 0)
  45.312 +						product2b = product1b = color6;
  45.313 +					else if (r < 0)
  45.314 +						product2b = product1b = color5;
  45.315 +					else
  45.316 +					{
  45.317 +						product2b = product1b = INTERPOLATE(color5, color6);
  45.318 +					}
  45.319 +				}
  45.320 +				else
  45.321 +				{
  45.322 +					if (color6 == color3 && color3 == colorA1
  45.323 +					    && color2 != colorA2 && color3 != colorA0)
  45.324 +						product2b =
  45.325 +						    Q_INTERPOLATE(color3, color3, color3, color2);
  45.326 +					else if (color5 == color2 && color2 == colorA2
  45.327 +					         && colorA1 != color3 && color2 != colorA3)
  45.328 +						product2b =
  45.329 +						    Q_INTERPOLATE(color2, color2, color2, color3);
  45.330 +					else
  45.331 +						product2b = INTERPOLATE(color2, color3);
  45.332 +
  45.333 +					if (color6 == color3 && color6 == colorB1
  45.334 +					    && color5 != colorB2 && color6 != colorB0)
  45.335 +						product1b =
  45.336 +						    Q_INTERPOLATE(color6, color6, color6, color5);
  45.337 +					else if (color5 == color2 && color5 == colorB2
  45.338 +					         && colorB1 != color6 && color5 != colorB3)
  45.339 +						product1b =
  45.340 +						    Q_INTERPOLATE(color6, color5, color5, color5);
  45.341 +					else
  45.342 +						product1b = INTERPOLATE(color5, color6);
  45.343 +				}
  45.344 +
  45.345 +				if (color5 == color3 && color2 != color6 && color4 == color5
  45.346 +				    && color5 != colorA2)
  45.347 +					product2a = INTERPOLATE(color2, color5);
  45.348 +				else
  45.349 +					if (color5 == color1 && color6 == color5
  45.350 +					    && color4 != color2 && color5 != colorA0)
  45.351 +						product2a = INTERPOLATE(color2, color5);
  45.352 +					else
  45.353 +						product2a = color2;
  45.354 +
  45.355 +				if (color2 == color6 && color5 != color3 && color1 == color2
  45.356 +				    && color2 != colorB2)
  45.357 +					product1a = INTERPOLATE(color2, color5);
  45.358 +				else
  45.359 +					if (color4 == color2 && color3 == color2
  45.360 +					    && color1 != color5 && color2 != colorB0)
  45.361 +						product1a = INTERPOLATE(color2, color5);
  45.362 +					else
  45.363 +						product1a = color5;
  45.364 +
  45.365 +#ifdef WORDS_BIGENDIAN
  45.366 +				product1a = (product1a << 16) | product1b;
  45.367 +				product2a = (product2a << 16) | product2b;
  45.368 +#else
  45.369 +				product1a = product1a | (product1b << 16);
  45.370 +				product2a = product2a | (product2b << 16);
  45.371 +#endif
  45.372 +
  45.373 +				*((u32 *) dP) = product1a;
  45.374 +				*((u32 *) (dP + dstPitch)) = product2a;
  45.375 +
  45.376 +				bP += inc_bP;
  45.377 +				dP += sizeof(u32);
  45.378 +			}                   // end of for ( finish= width etc..)
  45.379 +
  45.380 +			srcPtr	 += srcPitch;
  45.381 +			dstPtr	 += dstPitch << 1;
  45.382 +			deltaPtr += srcPitch;
  45.383 +		}               // endof: for (; height; height--)
  45.384 +	}
  45.385 +}
  45.386 +
  45.387 +void Super2xSaI32(u8 *srcPtr, u32 srcPitch,
  45.388 +                  u8 * /* deltaPtr */, u8 *dstPtr, u32 dstPitch,
  45.389 +                  int width, int height)
  45.390 +{
  45.391 +	u32 *bP;
  45.392 +	u32 *dP;
  45.393 +	u32	 inc_bP;
  45.394 +	u32	 Nextline = srcPitch >> 2;
  45.395 +	inc_bP = 1;
  45.396 +
  45.397 +	for (; height; height--)
  45.398 +	{
  45.399 +		bP = (u32 *) srcPtr;
  45.400 +		dP = (u32 *) dstPtr;
  45.401 +
  45.402 +		for (u32 finish = width; finish; finish -= inc_bP)
  45.403 +		{
  45.404 +			u32 color4, color5, color6;
  45.405 +			u32 color1, color2, color3;
  45.406 +			u32 colorA0, colorA1, colorA2, colorA3,
  45.407 +			    colorB0, colorB1, colorB2, colorB3, colorS1, colorS2;
  45.408 +			u32 product1a, product1b, product2a, product2b;
  45.409 +
  45.410 +			//---------------------------------------    B1 B2
  45.411 +			//                                         4  5  6 S2
  45.412 +			//                                         1  2  3 S1
  45.413 +			//                                           A1 A2
  45.414 +
  45.415 +			colorB0 = *(bP - Nextline - 1);
  45.416 +			colorB1 = *(bP - Nextline);
  45.417 +			colorB2 = *(bP - Nextline + 1);
  45.418 +			colorB3 = *(bP - Nextline + 2);
  45.419 +
  45.420 +			color4	= *(bP - 1);
  45.421 +			color5	= *(bP);
  45.422 +			color6	= *(bP + 1);
  45.423 +			colorS2 = *(bP + 2);
  45.424 +
  45.425 +			color1	= *(bP + Nextline - 1);
  45.426 +			color2	= *(bP + Nextline);
  45.427 +			color3	= *(bP + Nextline + 1);
  45.428 +			colorS1 = *(bP + Nextline + 2);
  45.429 +
  45.430 +			colorA0 = *(bP + Nextline + Nextline - 1);
  45.431 +			colorA1 = *(bP + Nextline + Nextline);
  45.432 +			colorA2 = *(bP + Nextline + Nextline + 1);
  45.433 +			colorA3 = *(bP + Nextline + Nextline + 2);
  45.434 +
  45.435 +			//--------------------------------------
  45.436 +			if (color2 == color6 && color5 != color3)
  45.437 +			{
  45.438 +				product2b = product1b = color2;
  45.439 +			}
  45.440 +			else if (color5 == color3 && color2 != color6)
  45.441 +			{
  45.442 +				product2b = product1b = color5;
  45.443 +			}
  45.444 +			else if (color5 == color3 && color2 == color6)
  45.445 +			{
  45.446 +				register int r = 0;
  45.447 +
  45.448 +				r += GetResult(color6, color5, color1, colorA1);
  45.449 +				r += GetResult(color6, color5, color4, colorB1);
  45.450 +				r += GetResult(color6, color5, colorA2, colorS1);
  45.451 +				r += GetResult(color6, color5, colorB2, colorS2);
  45.452 +
  45.453 +				if (r > 0)
  45.454 +					product2b = product1b = color6;
  45.455 +				else if (r < 0)
  45.456 +					product2b = product1b = color5;
  45.457 +				else
  45.458 +				{
  45.459 +					product2b = product1b = INTERPOLATE(color5, color6);
  45.460 +				}
  45.461 +			}
  45.462 +			else
  45.463 +			{
  45.464 +				if (color6 == color3 && color3 == colorA1
  45.465 +				    && color2 != colorA2 && color3 != colorA0)
  45.466 +					product2b =
  45.467 +					    Q_INTERPOLATE(color3, color3, color3, color2);
  45.468 +				else if (color5 == color2 && color2 == colorA2
  45.469 +				         && colorA1 != color3 && color2 != colorA3)
  45.470 +					product2b =
  45.471 +					    Q_INTERPOLATE(color2, color2, color2, color3);
  45.472 +				else
  45.473 +					product2b = INTERPOLATE(color2, color3);
  45.474 +
  45.475 +				if (color6 == color3 && color6 == colorB1
  45.476 +				    && color5 != colorB2 && color6 != colorB0)
  45.477 +					product1b =
  45.478 +					    Q_INTERPOLATE(color6, color6, color6, color5);
  45.479 +				else if (color5 == color2 && color5 == colorB2
  45.480 +				         && colorB1 != color6 && color5 != colorB3)
  45.481 +					product1b =
  45.482 +					    Q_INTERPOLATE(color6, color5, color5, color5);
  45.483 +				else
  45.484 +					product1b = INTERPOLATE(color5, color6);
  45.485 +			}
  45.486 +
  45.487 +			if (color5 == color3 && color2 != color6 && color4 == color5
  45.488 +			    && color5 != colorA2)
  45.489 +				product2a = INTERPOLATE(color2, color5);
  45.490 +			else
  45.491 +				if (color5 == color1 && color6 == color5
  45.492 +				    && color4 != color2 && color5 != colorA0)
  45.493 +					product2a = INTERPOLATE(color2, color5);
  45.494 +				else
  45.495 +					product2a = color2;
  45.496 +
  45.497 +			if (color2 == color6 && color5 != color3 && color1 == color2
  45.498 +			    && color2 != colorB2)
  45.499 +				product1a = INTERPOLATE(color2, color5);
  45.500 +			else
  45.501 +				if (color4 == color2 && color3 == color2
  45.502 +				    && color1 != color5 && color2 != colorB0)
  45.503 +					product1a = INTERPOLATE(color2, color5);
  45.504 +				else
  45.505 +					product1a = color5;
  45.506 +			*(dP)	  = product1a;
  45.507 +			*(dP + 1) = product1b;
  45.508 +			*(dP + (dstPitch >> 2))		= product2a;
  45.509 +			*(dP + (dstPitch >> 2) + 1) = product2b;
  45.510 +
  45.511 +			bP += inc_bP;
  45.512 +			dP += 2;
  45.513 +		}                   // end of for ( finish= width etc..)
  45.514 +
  45.515 +		srcPtr += srcPitch;
  45.516 +		dstPtr += dstPitch << 1;
  45.517 +		//        deltaPtr += srcPitch;
  45.518 +	}               // endof: for (; height; height--)
  45.519 +}
  45.520 +
  45.521 +void SuperEagle(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
  45.522 +                u8 *dstPtr, u32 dstPitch, int width, int height)
  45.523 +{
  45.524 +	u8 * dP;
  45.525 +	u16 *bP;
  45.526 +	u16 *xP;
  45.527 +	u32	 inc_bP;
  45.528 +
  45.529 +#ifdef MMX
  45.530 +	if (cpu_mmx)
  45.531 +	{
  45.532 +		for (; height; height--)
  45.533 +		{
  45.534 +			_2xSaISuperEagleLine(srcPtr, deltaPtr, srcPitch, width,
  45.535 +			                     dstPtr, dstPitch);
  45.536 +			srcPtr	 += srcPitch;
  45.537 +			dstPtr	 += dstPitch * 2;
  45.538 +			deltaPtr += srcPitch;
  45.539 +		}
  45.540 +	}
  45.541 +	else
  45.542 +#endif
  45.543 +	{
  45.544 +		inc_bP = 1;
  45.545 +
  45.546 +		u32 Nextline = srcPitch >> 1;
  45.547 +
  45.548 +		for (; height; height--)
  45.549 +		{
  45.550 +			bP = (u16 *) srcPtr;
  45.551 +			xP = (u16 *) deltaPtr;
  45.552 +			dP = dstPtr;
  45.553 +			for (u32 finish = width; finish; finish -= inc_bP)
  45.554 +			{
  45.555 +				u32 color4, color5, color6;
  45.556 +				u32 color1, color2, color3;
  45.557 +				u32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2;
  45.558 +				u32 product1a, product1b, product2a, product2b;
  45.559 +
  45.560 +				colorB1 = *(bP - Nextline);
  45.561 +				colorB2 = *(bP - Nextline + 1);
  45.562 +
  45.563 +				color4	= *(bP - 1);
  45.564 +				color5	= *(bP);
  45.565 +				color6	= *(bP + 1);
  45.566 +				colorS2 = *(bP + 2);
  45.567 +
  45.568 +				color1	= *(bP + Nextline - 1);
  45.569 +				color2	= *(bP + Nextline);
  45.570 +				color3	= *(bP + Nextline + 1);
  45.571 +				colorS1 = *(bP + Nextline + 2);
  45.572 +
  45.573 +				colorA1 = *(bP + Nextline + Nextline);
  45.574 +				colorA2 = *(bP + Nextline + Nextline + 1);
  45.575 +
  45.576 +				// --------------------------------------
  45.577 +				if (color2 == color6 && color5 != color3)
  45.578 +				{
  45.579 +					product1b = product2a = color2;
  45.580 +					if ((color1 == color2) || (color6 == colorB2))
  45.581 +					{
  45.582 +						product1a = INTERPOLATE(color2, color5);
  45.583 +						product1a = INTERPOLATE(color2, product1a);
  45.584 +						//                       product1a = color2;
  45.585 +					}
  45.586 +					else
  45.587 +					{
  45.588 +						product1a = INTERPOLATE(color5, color6);
  45.589 +					}
  45.590 +
  45.591 +					if ((color6 == colorS2) || (color2 == colorA1))
  45.592 +					{
  45.593 +						product2b = INTERPOLATE(color2, color3);
  45.594 +						product2b = INTERPOLATE(color2, product2b);
  45.595 +						//                       product2b = color2;
  45.596 +					}
  45.597 +					else
  45.598 +					{
  45.599 +						product2b = INTERPOLATE(color2, color3);
  45.600 +					}
  45.601 +				}
  45.602 +				else if (color5 == color3 && color2 != color6)
  45.603 +				{
  45.604 +					product2b = product1a = color5;
  45.605 +
  45.606 +					if ((colorB1 == color5) || (color3 == colorS1))
  45.607 +					{
  45.608 +						product1b = INTERPOLATE(color5, color6);
  45.609 +						product1b = INTERPOLATE(color5, product1b);
  45.610 +						//                       product1b = color5;
  45.611 +					}
  45.612 +					else
  45.613 +					{
  45.614 +						product1b = INTERPOLATE(color5, color6);
  45.615 +					}
  45.616 +
  45.617 +					if ((color3 == colorA2) || (color4 == color5))
  45.618 +					{
  45.619 +						product2a = INTERPOLATE(color5, color2);
  45.620 +						product2a = INTERPOLATE(color5, product2a);
  45.621 +						//                       product2a = color5;
  45.622 +					}
  45.623 +					else
  45.624 +					{
  45.625 +						product2a = INTERPOLATE(color2, color3);
  45.626 +					}
  45.627 +				}
  45.628 +				else if (color5 == color3 && color2 == color6)
  45.629 +				{
  45.630 +					register int r = 0;
  45.631 +
  45.632 +					r += GetResult(color6, color5, color1, colorA1);
  45.633 +					r += GetResult(color6, color5, color4, colorB1);
  45.634 +					r += GetResult(color6, color5, colorA2, colorS1);
  45.635 +					r += GetResult(color6, color5, colorB2, colorS2);
  45.636 +
  45.637 +					if (r > 0)
  45.638 +					{
  45.639 +						product1b = product2a = color2;
  45.640 +						product1a = product2b = INTERPOLATE(color5, color6);
  45.641 +					}
  45.642 +					else if (r < 0)
  45.643 +					{
  45.644 +						product2b = product1a = color5;
  45.645 +						product1b = product2a = INTERPOLATE(color5, color6);
  45.646 +					}
  45.647 +					else
  45.648 +					{
  45.649 +						product2b = product1a = color5;
  45.650 +						product1b = product2a = color2;
  45.651 +					}
  45.652 +				}
  45.653 +				else
  45.654 +				{
  45.655 +					product2b = product1a = INTERPOLATE(color2, color6);
  45.656 +					product2b =
  45.657 +					    Q_INTERPOLATE(color3, color3, color3, product2b);
  45.658 +					product1a =
  45.659 +					    Q_INTERPOLATE(color5, color5, color5, product1a);
  45.660 +
  45.661 +					product2a = product1b = INTERPOLATE(color5, color3);
  45.662 +					product2a =
  45.663 +					    Q_INTERPOLATE(color2, color2, color2, product2a);
  45.664 +					product1b =
  45.665 +					    Q_INTERPOLATE(color6, color6, color6, product1b);
  45.666 +
  45.667 +					//                    product1a = color5;
  45.668 +					//                    product1b = color6;
  45.669 +					//                    product2a = color2;
  45.670 +					//                    product2b = color3;
  45.671 +				}
  45.672 +#ifdef WORDS_BIGENDIAN
  45.673 +				product1a = (product1a << 16) | product1b;
  45.674 +				product2a = (product2a << 16) | product2b;
  45.675 +#else
  45.676 +				product1a = product1a | (product1b << 16);
  45.677 +				product2a = product2a | (product2b << 16);
  45.678 +#endif
  45.679 +
  45.680 +				*((u32 *) dP) = product1a;
  45.681 +				*((u32 *) (dP + dstPitch)) = product2a;
  45.682 +				*xP = color5;
  45.683 +
  45.684 +				bP += inc_bP;
  45.685 +				xP += inc_bP;
  45.686 +				dP += sizeof(u32);
  45.687 +			}           // end of for ( finish= width etc..)
  45.688 +
  45.689 +			srcPtr	 += srcPitch;
  45.690 +			dstPtr	 += dstPitch << 1;
  45.691 +			deltaPtr += srcPitch;
  45.692 +		}               // endof: for (height; height; height--)
  45.693 +	}
  45.694 +}
  45.695 +
  45.696 +void SuperEagle32(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
  45.697 +                  u8 *dstPtr, u32 dstPitch, int width, int height)
  45.698 +{
  45.699 +	u32 *dP;
  45.700 +	u32 *bP;
  45.701 +	u32 *xP;
  45.702 +	u32	 inc_bP;
  45.703 +
  45.704 +	inc_bP = 1;
  45.705 +
  45.706 +	u32 Nextline = srcPitch >> 2;
  45.707 +
  45.708 +	for (; height; height--)
  45.709 +	{
  45.710 +		bP = (u32 *) srcPtr;
  45.711 +		xP = (u32 *) deltaPtr;
  45.712 +		dP = (u32 *)dstPtr;
  45.713 +		for (u32 finish = width; finish; finish -= inc_bP)
  45.714 +		{
  45.715 +			u32 color4, color5, color6;
  45.716 +			u32 color1, color2, color3;
  45.717 +			u32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2;
  45.718 +			u32 product1a, product1b, product2a, product2b;
  45.719 +
  45.720 +			colorB1 = *(bP - Nextline);
  45.721 +			colorB2 = *(bP - Nextline + 1);
  45.722 +
  45.723 +			color4	= *(bP - 1);
  45.724 +			color5	= *(bP);
  45.725 +			color6	= *(bP + 1);
  45.726 +			colorS2 = *(bP + 2);
  45.727 +
  45.728 +			color1	= *(bP + Nextline - 1);
  45.729 +			color2	= *(bP + Nextline);
  45.730 +			color3	= *(bP + Nextline + 1);
  45.731 +			colorS1 = *(bP + Nextline + 2);
  45.732 +
  45.733 +			colorA1 = *(bP + Nextline + Nextline);
  45.734 +			colorA2 = *(bP + Nextline + Nextline + 1);
  45.735 +
  45.736 +			// --------------------------------------
  45.737 +			if (color2 == color6 && color5 != color3)
  45.738 +			{
  45.739 +				product1b = product2a = color2;
  45.740 +				if ((color1 == color2) || (color6 == colorB2))
  45.741 +				{
  45.742 +					product1a = INTERPOLATE(color2, color5);
  45.743 +					product1a = INTERPOLATE(color2, product1a);
  45.744 +					//                       product1a = color2;
  45.745 +				}
  45.746 +				else
  45.747 +				{
  45.748 +					product1a = INTERPOLATE(color5, color6);
  45.749 +				}
  45.750 +
  45.751 +				if ((color6 == colorS2) || (color2 == colorA1))
  45.752 +				{
  45.753 +					product2b = INTERPOLATE(color2, color3);
  45.754 +					product2b = INTERPOLATE(color2, product2b);
  45.755 +					//                       product2b = color2;
  45.756 +				}
  45.757 +				else
  45.758 +				{
  45.759 +					product2b = INTERPOLATE(color2, color3);
  45.760 +				}
  45.761 +			}
  45.762 +			else if (color5 == color3 && color2 != color6)
  45.763 +			{
  45.764 +				product2b = product1a = color5;
  45.765 +
  45.766 +				if ((colorB1 == color5) || (color3 == colorS1))
  45.767 +				{
  45.768 +					product1b = INTERPOLATE(color5, color6);
  45.769 +					product1b = INTERPOLATE(color5, product1b);
  45.770 +					//                       product1b = color5;
  45.771 +				}
  45.772 +				else
  45.773 +				{
  45.774 +					product1b = INTERPOLATE(color5, color6);
  45.775 +				}
  45.776 +
  45.777 +				if ((color3 == colorA2) || (color4 == color5))
  45.778 +				{
  45.779 +					product2a = INTERPOLATE(color5, color2);
  45.780 +					product2a = INTERPOLATE(color5, product2a);
  45.781 +					//                       product2a = color5;
  45.782 +				}
  45.783 +				else
  45.784 +				{
  45.785 +					product2a = INTERPOLATE(color2, color3);
  45.786 +				}
  45.787 +			}
  45.788 +			else if (color5 == color3 && color2 == color6)
  45.789 +			{
  45.790 +				register int r = 0;
  45.791 +
  45.792 +				r += GetResult(color6, color5, color1, colorA1);
  45.793 +				r += GetResult(color6, color5, color4, colorB1);
  45.794 +				r += GetResult(color6, color5, colorA2, colorS1);
  45.795 +				r += GetResult(color6, color5, colorB2, colorS2);
  45.796 +
  45.797 +				if (r > 0)
  45.798 +				{
  45.799 +					product1b = product2a = color2;
  45.800 +					product1a = product2b = INTERPOLATE(color5, color6);
  45.801 +				}
  45.802 +				else if (r < 0)
  45.803 +				{
  45.804 +					product2b = product1a = color5;
  45.805 +					product1b = product2a = INTERPOLATE(color5, color6);
  45.806 +				}
  45.807 +				else
  45.808 +				{
  45.809 +					product2b = product1a = color5;
  45.810 +					product1b = product2a = color2;
  45.811 +				}
  45.812 +			}
  45.813 +			else
  45.814 +			{
  45.815 +				product2b = product1a = INTERPOLATE(color2, color6);
  45.816 +				product2b =
  45.817 +				    Q_INTERPOLATE(color3, color3, color3, product2b);
  45.818 +				product1a =
  45.819 +				    Q_INTERPOLATE(color5, color5, color5, product1a);
  45.820 +
  45.821 +				product2a = product1b = INTERPOLATE(color5, color3);
  45.822 +				product2a =
  45.823 +				    Q_INTERPOLATE(color2, color2, color2, product2a);
  45.824 +				product1b =
  45.825 +				    Q_INTERPOLATE(color6, color6, color6, product1b);
  45.826 +
  45.827 +				//                    product1a = color5;
  45.828 +				//                    product1b = color6;
  45.829 +				//                    product2a = color2;
  45.830 +				//                    product2b = color3;
  45.831 +			}
  45.832 +			*(dP)	  = product1a;
  45.833 +			*(dP + 1) = product1b;
  45.834 +			*(dP + (dstPitch >> 2))		= product2a;
  45.835 +			*(dP + (dstPitch >> 2) + 1) = product2b;
  45.836 +			*xP = color5;
  45.837 +
  45.838 +			bP += inc_bP;
  45.839 +			xP += inc_bP;
  45.840 +			dP += 2;
  45.841 +		}             // end of for ( finish= width etc..)
  45.842 +
  45.843 +		srcPtr	 += srcPitch;
  45.844 +		dstPtr	 += dstPitch << 1;
  45.845 +		deltaPtr += srcPitch;
  45.846 +	}                 // endof: for (height; height; height--)
  45.847 +}
  45.848 +
  45.849 +void _2xSaI(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
  45.850 +            u8 *dstPtr, u32 dstPitch, int width, int height)
  45.851 +{
  45.852 +	u8 * dP;
  45.853 +	u16 *bP;
  45.854 +	u32	 inc_bP;
  45.855 +
  45.856 +#ifdef MMX
  45.857 +	if (cpu_mmx)
  45.858 +	{
  45.859 +		for (; height; height -= 1)
  45.860 +		{
  45.861 +			_2xSaILine(srcPtr, deltaPtr, srcPitch, width, dstPtr, dstPitch);
  45.862 +			srcPtr	 += srcPitch;
  45.863 +			dstPtr	 += dstPitch * 2;
  45.864 +			deltaPtr += srcPitch;
  45.865 +		}
  45.866 +	}
  45.867 +	else
  45.868 +#endif
  45.869 +	{
  45.870 +		inc_bP = 1;
  45.871 +
  45.872 +		u32 Nextline = srcPitch >> 1;
  45.873 +
  45.874 +		for (; height; height--)
  45.875 +		{
  45.876 +			bP = (u16 *) srcPtr;
  45.877 +			dP = dstPtr;
  45.878 +
  45.879 +			for (u32 finish = width; finish; finish -= inc_bP)
  45.880 +			{
  45.881 +				register u32 colorA, colorB;
  45.882 +				u32 colorC, colorD,
  45.883 +				    colorE, colorF, colorG, colorH,
  45.884 +				    colorI, colorJ, colorK, colorL,
  45.885 +
  45.886 +				    colorM, colorN, colorO, colorP;
  45.887 +				u32 product, product1, product2;
  45.888 +
  45.889 +				//---------------------------------------
  45.890 +				// Map of the pixels:                    I|E F|J
  45.891 +				//                                       G|A B|K
  45.892 +				//                                       H|C D|L
  45.893 +				//                                       M|N O|P
  45.894 +				colorI = *(bP - Nextline - 1);
  45.895 +				colorE = *(bP - Nextline);
  45.896 +				colorF = *(bP - Nextline + 1);
  45.897 +				colorJ = *(bP - Nextline + 2);
  45.898 +
  45.899 +				colorG = *(bP - 1);
  45.900 +				colorA = *(bP);
  45.901 +				colorB = *(bP + 1);
  45.902 +				colorK = *(bP + 2);
  45.903 +
  45.904 +				colorH = *(bP + Nextline - 1);
  45.905 +				colorC = *(bP + Nextline);
  45.906 +				colorD = *(bP + Nextline + 1);
  45.907 +				colorL = *(bP + Nextline + 2);
  45.908 +
  45.909 +				colorM = *(bP + Nextline + Nextline - 1);
  45.910 +				colorN = *(bP + Nextline + Nextline);
  45.911 +				colorO = *(bP + Nextline + Nextline + 1);
  45.912 +				colorP = *(bP + Nextline + Nextline + 2);
  45.913 +
  45.914 +				if ((colorA == colorD) && (colorB != colorC))
  45.915 +				{
  45.916 +					if (((colorA == colorE) && (colorB == colorL)) ||
  45.917 +					    ((colorA == colorC) && (colorA == colorF)
  45.918 +					     && (colorB != colorE) && (colorB == colorJ)))
  45.919 +					{
  45.920 +						product = colorA;
  45.921 +					}
  45.922 +					else
  45.923 +					{
  45.924 +						product = INTERPOLATE(colorA, colorB);
  45.925 +					}
  45.926 +
  45.927 +					if (((colorA == colorG) && (colorC == colorO)) ||
  45.928 +					    ((colorA == colorB) && (colorA == colorH)
  45.929 +					     && (colorG != colorC) && (colorC == colorM)))
  45.930 +					{
  45.931 +						product1 = colorA;
  45.932 +					}
  45.933 +					else
  45.934 +					{
  45.935 +						product1 = INTERPOLATE(colorA, colorC);
  45.936 +					}
  45.937 +					product2 = colorA;
  45.938 +				}
  45.939 +				else if ((colorB == colorC) && (colorA != colorD))
  45.940 +				{
  45.941 +					if (((colorB == colorF) && (colorA == colorH)) ||
  45.942 +					    ((colorB == colorE) && (colorB == colorD)
  45.943 +					     && (colorA != colorF) && (colorA == colorI)))
  45.944 +					{
  45.945 +						product = colorB;
  45.946 +					}
  45.947 +					else
  45.948 +					{
  45.949 +						product = INTERPOLATE(colorA, colorB);
  45.950 +					}
  45.951 +
  45.952 +					if (((colorC == colorH) && (colorA == colorF)) ||
  45.953 +					    ((colorC == colorG) && (colorC == colorD)
  45.954 +					     && (colorA != colorH) && (colorA == colorI)))
  45.955 +					{
  45.956 +						product1 = colorC;
  45.957 +					}
  45.958 +					else
  45.959 +					{
  45.960 +						product1 = INTERPOLATE(colorA, colorC);
  45.961 +					}
  45.962 +					product2 = colorB;
  45.963 +				}
  45.964 +				else if ((colorA == colorD) && (colorB == colorC))
  45.965 +				{
  45.966 +					if (colorA == colorB)
  45.967 +					{
  45.968 +						product	 = colorA;
  45.969 +						product1 = colorA;
  45.970 +						product2 = colorA;
  45.971 +					}
  45.972 +					else
  45.973 +					{
  45.974 +						register int r = 0;
  45.975 +
  45.976 +						product1 = INTERPOLATE(colorA, colorC);
  45.977 +						product	 = INTERPOLATE(colorA, colorB);
  45.978 +
  45.979 +						r +=
  45.980 +						    GetResult1(colorA, colorB, colorG, colorE,
  45.981 +						               colorI);
  45.982 +						r +=
  45.983 +						    GetResult2(colorB, colorA, colorK, colorF,
  45.984 +						               colorJ);
  45.985 +						r +=
  45.986 +						    GetResult2(colorB, colorA, colorH, colorN,
  45.987 +						               colorM);
  45.988 +						r +=
  45.989 +						    GetResult1(colorA, colorB, colorL, colorO,
  45.990 +						               colorP);
  45.991 +
  45.992 +						if (r > 0)
  45.993 +							product2 = colorA;
  45.994 +						else if (r < 0)
  45.995 +							product2 = colorB;
  45.996 +						else
  45.997 +						{
  45.998 +							product2 =
  45.999 +							    Q_INTERPOLATE(colorA, colorB, colorC,
 45.1000 +							                  colorD);
 45.1001 +						}
 45.1002 +					}
 45.1003 +				}
 45.1004 +				else
 45.1005 +				{
 45.1006 +					product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD);
 45.1007 +
 45.1008 +					if ((colorA == colorC) && (colorA == colorF)
 45.1009 +					    && (colorB != colorE) && (colorB == colorJ))
 45.1010 +					{
 45.1011 +						product = colorA;
 45.1012 +					}
 45.1013 +					else if ((colorB == colorE) && (colorB == colorD)
 45.1014 +					         && (colorA != colorF) && (colorA == colorI))
 45.1015 +					{
 45.1016 +						product = colorB;
 45.1017 +					}
 45.1018 +					else
 45.1019 +					{
 45.1020 +						product = INTERPOLATE(colorA, colorB);
 45.1021 +					}
 45.1022 +
 45.1023 +					if ((colorA == colorB) && (colorA == colorH)
 45.1024 +					    && (colorG != colorC) && (colorC == colorM))
 45.1025 +					{
 45.1026 +						product1 = colorA;
 45.1027 +					}
 45.1028 +					else if ((colorC == colorG) && (colorC == colorD)
 45.1029 +					         && (colorA != colorH) && (colorA == colorI))
 45.1030 +					{
 45.1031 +						product1 = colorC;
 45.1032 +					}
 45.1033 +					else
 45.1034 +					{
 45.1035 +						product1 = INTERPOLATE(colorA, colorC);
 45.1036 +					}
 45.1037 +				}
 45.1038 +
 45.1039 +#ifdef WORDS_BIGENDIAN
 45.1040 +				product	 = (colorA << 16) | product;
 45.1041 +				product1 = (product1 << 16) | product2;
 45.1042 +#else
 45.1043 +				product	 = colorA | (product << 16);
 45.1044 +				product1 = product1 | (product2 << 16);
 45.1045 +#endif
 45.1046 +				*((s32 *) dP) = product;
 45.1047 +				*((u32 *) (dP + dstPitch)) = product1;
 45.1048 +
 45.1049 +				bP += inc_bP;
 45.1050 +				dP += sizeof(u32);
 45.1051 +			}           // end of for ( finish= width etc..)
 45.1052 +
 45.1053 +			srcPtr	 += srcPitch;
 45.1054 +			dstPtr	 += dstPitch << 1;
 45.1055 +			deltaPtr += srcPitch;
 45.1056 +		}               // endof: for (height; height; height--)
 45.1057 +	}
 45.1058 +}
 45.1059 +
 45.1060 +void _2xSaI32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
 45.1061 +              u8 *dstPtr, u32 dstPitch, int width, int height)
 45.1062 +{
 45.1063 +	u32 *dP;
 45.1064 +	u32 *bP;
 45.1065 +	u32	 inc_bP = 1;
 45.1066 +
 45.1067 +	u32 Nextline = srcPitch >> 2;
 45.1068 +
 45.1069 +	for (; height; height--)
 45.1070 +	{
 45.1071 +		bP = (u32 *) srcPtr;
 45.1072 +		dP = (u32 *) dstPtr;
 45.1073 +
 45.1074 +		for (u32 finish = width; finish; finish -= inc_bP)
 45.1075 +		{
 45.1076 +			register u32 colorA, colorB;
 45.1077 +			u32 colorC, colorD,
 45.1078 +			    colorE, colorF, colorG, colorH,
 45.1079 +			    colorI, colorJ, colorK, colorL,
 45.1080 +
 45.1081 +			    colorM, colorN, colorO, colorP;
 45.1082 +			u32 product, product1, product2;
 45.1083 +
 45.1084 +			//---------------------------------------
 45.1085 +			// Map of the pixels:                    I|E F|J
 45.1086 +			//                                       G|A B|K
 45.1087 +			//                                       H|C D|L
 45.1088 +			//                                       M|N O|P
 45.1089 +			colorI = *(bP - Nextline - 1);
 45.1090 +			colorE = *(bP - Nextline);
 45.1091 +			colorF = *(bP - Nextline + 1);
 45.1092 +			colorJ = *(bP - Nextline + 2);
 45.1093 +
 45.1094 +			colorG = *(bP - 1);
 45.1095 +			colorA = *(bP);
 45.1096 +			colorB = *(bP + 1);
 45.1097 +			colorK = *(bP + 2);
 45.1098 +
 45.1099 +			colorH = *(bP + Nextline - 1);
 45.1100 +			colorC = *(bP + Nextline);
 45.1101 +			colorD = *(bP + Nextline + 1);
 45.1102 +			colorL = *(bP + Nextline + 2);
 45.1103 +
 45.1104 +			colorM = *(bP + Nextline + Nextline - 1);
 45.1105 +			colorN = *(bP + Nextline + Nextline);
 45.1106 +			colorO = *(bP + Nextline + Nextline + 1);
 45.1107 +			colorP = *(bP + Nextline + Nextline + 2);
 45.1108 +
 45.1109 +			if ((colorA == colorD) && (colorB != colorC))
 45.1110 +			{
 45.1111 +				if (((colorA == colorE) && (colorB == colorL)) ||
 45.1112 +				    ((colorA == colorC) && (colorA == colorF)
 45.1113 +				     && (colorB != colorE) && (colorB == colorJ)))
 45.1114 +				{
 45.1115 +					product = colorA;
 45.1116 +				}
 45.1117 +				else
 45.1118 +				{
 45.1119 +					product = INTERPOLATE(colorA, colorB);
 45.1120 +				}
 45.1121 +
 45.1122 +				if (((colorA == colorG) && (colorC == colorO)) ||
 45.1123 +				    ((colorA == colorB) && (colorA == colorH)
 45.1124 +				     && (colorG != colorC) && (colorC == colorM)))
 45.1125 +				{
 45.1126 +					product1 = colorA;
 45.1127 +				}
 45.1128 +				else
 45.1129 +				{
 45.1130 +					product1 = INTERPOLATE(colorA, colorC);
 45.1131 +				}
 45.1132 +				product2 = colorA;
 45.1133 +			}
 45.1134 +			else if ((colorB == colorC) && (colorA != colorD))
 45.1135 +			{
 45.1136 +				if (((colorB == colorF) && (colorA == colorH)) ||
 45.1137 +				    ((colorB == colorE) && (colorB == colorD)
 45.1138 +				     && (colorA != colorF) && (colorA == colorI)))
 45.1139 +				{
 45.1140 +					product = colorB;
 45.1141 +				}
 45.1142 +				else
 45.1143 +				{
 45.1144 +					product = INTERPOLATE(colorA, colorB);
 45.1145 +				}
 45.1146 +
 45.1147 +				if (((colorC == colorH) && (colorA == colorF)) ||
 45.1148 +				    ((colorC == colorG) && (colorC == colorD)
 45.1149 +				     && (colorA != colorH) && (colorA == colorI)))
 45.1150 +				{
 45.1151 +					product1 = colorC;
 45.1152 +				}
 45.1153 +				else
 45.1154 +				{
 45.1155 +					product1 = INTERPOLATE(colorA, colorC);
 45.1156 +				}
 45.1157 +				product2 = colorB;
 45.1158 +			}
 45.1159 +			else if ((colorA == colorD) && (colorB == colorC))
 45.1160 +			{
 45.1161 +				if (colorA == colorB)
 45.1162 +				{
 45.1163 +					product	 = colorA;
 45.1164 +					product1 = colorA;
 45.1165 +					product2 = colorA;
 45.1166 +				}
 45.1167 +				else
 45.1168 +				{
 45.1169 +					register int r = 0;
 45.1170 +
 45.1171 +					product1 = INTERPOLATE(colorA, colorC);
 45.1172 +					product	 = INTERPOLATE(colorA, colorB);
 45.1173 +
 45.1174 +					r +=
 45.1175 +					    GetResult1(colorA, colorB, colorG, colorE,
 45.1176 +					               colorI);
 45.1177 +					r +=
 45.1178 +					    GetResult2(colorB, colorA, colorK, colorF,
 45.1179 +					               colorJ);
 45.1180 +					r +=
 45.1181 +					    GetResult2(colorB, colorA, colorH, colorN,
 45.1182 +					               colorM);
 45.1183 +					r +=
 45.1184 +					    GetResult1(colorA, colorB, colorL, colorO,
 45.1185 +					               colorP);
 45.1186 +
 45.1187 +					if (r > 0)
 45.1188 +						product2 = colorA;
 45.1189 +					else if (r < 0)
 45.1190 +						product2 = colorB;
 45.1191 +					else
 45.1192 +					{
 45.1193 +						product2 =
 45.1194 +						    Q_INTERPOLATE(colorA, colorB, colorC,
 45.1195 +						                  colorD);
 45.1196 +					}
 45.1197 +				}
 45.1198 +			}
 45.1199 +			else
 45.1200 +			{
 45.1201 +				product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD);
 45.1202 +
 45.1203 +				if ((colorA == colorC) && (colorA == colorF)
 45.1204 +				    && (colorB != colorE) && (colorB == colorJ))
 45.1205 +				{
 45.1206 +					product = colorA;
 45.1207 +				}
 45.1208 +				else if ((colorB == colorE) && (colorB == colorD)
 45.1209 +				         && (colorA != colorF) && (colorA == colorI))
 45.1210 +				{
 45.1211 +					product = colorB;
 45.1212 +				}
 45.1213 +				else
 45.1214 +				{
 45.1215 +					product = INTERPOLATE(colorA, colorB);
 45.1216 +				}
 45.1217 +
 45.1218 +				if ((colorA == colorB) && (colorA == colorH)
 45.1219 +				    && (colorG != colorC) && (colorC == colorM))
 45.1220 +				{
 45.1221 +					product1 = colorA;
 45.1222 +				}
 45.1223 +				else if ((colorC == colorG) && (colorC == colorD)
 45.1224 +				         && (colorA != colorH) && (colorA == colorI))
 45.1225 +				{
 45.1226 +					product1 = colorC;
 45.1227 +				}
 45.1228 +				else
 45.1229 +				{
 45.1230 +					product1 = INTERPOLATE(colorA, colorC);
 45.1231 +				}
 45.1232 +			}
 45.1233 +			*(dP)	  = colorA;
 45.1234 +			*(dP + 1) = product;
 45.1235 +			*(dP + (dstPitch >> 2))		= product1;
 45.1236 +			*(dP + (dstPitch >> 2) + 1) = product2;
 45.1237 +
 45.1238 +			bP += inc_bP;
 45.1239 +			dP += 2;
 45.1240 +		}             // end of for ( finish= width etc..)
 45.1241 +
 45.1242 +		srcPtr += srcPitch;
 45.1243 +		dstPtr += dstPitch << 1;
 45.1244 +		//    deltaPtr += srcPitch;
 45.1245 +	}                 // endof: for (height; height; height--)
 45.1246 +}
 45.1247 +
 45.1248 +static u32 Bilinear(u32 A, u32 B, u32 x)
 45.1249 +{
 45.1250 +	unsigned long areaA, areaB;
 45.1251 +	unsigned long result;
 45.1252 +
 45.1253 +	if (A == B)
 45.1254 +		return A;
 45.1255 +
 45.1256 +	areaB = (x >> 11) & 0x1f;   // reduce 16 bit fraction to 5 bits
 45.1257 +	areaA = 0x20 - areaB;
 45.1258 +
 45.1259 +	A = (A & redblueMask) | ((A & greenMask) << 16);
 45.1260 +	B = (B & redblueMask) | ((B & greenMask) << 16);
 45.1261 +
 45.1262 +	result = ((areaA * A) + (areaB * B)) >> 5;
 45.1263 +
 45.1264 +	return (result & redblueMask) | ((result >> 16) & greenMask);
 45.1265 +}
 45.1266 +
 45.1267 +static u32 Bilinear4(u32 A, u32 B, u32 C, u32 D, u32 x,
 45.1268 +                     u32 y)
 45.1269 +{
 45.1270 +	unsigned long areaA, areaB, areaC, areaD;
 45.1271 +	unsigned long result, xy;
 45.1272 +
 45.1273 +	x  = (x >> 11) & 0x1f;
 45.1274 +	y  = (y >> 11) & 0x1f;
 45.1275 +	xy = (x * y) >> 5;
 45.1276 +
 45.1277 +	A = (A & redblueMask) | ((A & greenMask) << 16);
 45.1278 +	B = (B & redblueMask) | ((B & greenMask) << 16);
 45.1279 +	C = (C & redblueMask) | ((C & greenMask) << 16);
 45.1280 +	D = (D & redblueMask) | ((D & greenMask) << 16);
 45.1281 +
 45.1282 +	areaA = 0x20 + xy - x - y;
 45.1283 +	areaB = x - xy;
 45.1284 +	areaC = y - xy;
 45.1285 +	areaD = xy;
 45.1286 +
 45.1287 +	result = ((areaA * A) + (areaB * B) + (areaC * C) + (areaD * D)) >> 5;
 45.1288 +
 45.1289 +	return (result & redblueMask) | ((result >> 16) & greenMask);
 45.1290 +}
 45.1291 +
 45.1292 +void Scale_2xSaI(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
 45.1293 +                 u8 *dstPtr, u32 dstPitch,
 45.1294 +                 u32 dstWidth, u32 dstHeight, int width, int height)
 45.1295 +{
 45.1296 +	u8 * dP;
 45.1297 +	u16 *bP;
 45.1298 +
 45.1299 +	u32 w;
 45.1300 +	u32 h;
 45.1301 +	u32 dw;
 45.1302 +	u32 dh;
 45.1303 +	u32 hfinish;
 45.1304 +	u32 wfinish;
 45.1305 +
 45.1306 +	u32 Nextline = srcPitch >> 1;
 45.1307 +
 45.1308 +	wfinish = (width - 1) << 16; // convert to fixed point
 45.1309 +	dw		= wfinish / (dstWidth - 1);
 45.1310 +	hfinish = (height - 1) << 16; // convert to fixed point
 45.1311 +	dh		= hfinish / (dstHeight - 1);
 45.1312 +
 45.1313 +	for (h = 0; h < hfinish; h += dh)
 45.1314 +	{
 45.1315 +		u32 y1, y2;
 45.1316 +
 45.1317 +		y1 = h & 0xffff; // fraction part of fixed point
 45.1318 +		bP = (u16 *) (srcPtr + ((h >> 16) * srcPitch));
 45.1319 +		dP = dstPtr;
 45.1320 +		y2 = 0x10000 - y1;
 45.1321 +
 45.1322 +		w = 0;
 45.1323 +
 45.1324 +		for (; w < wfinish; )
 45.1325 +		{
 45.1326 +			u32 A, B, C, D;
 45.1327 +			u32 E, F, G, H;
 45.1328 +			u32 I, J, K, L;
 45.1329 +			u32 x1, x2, a1, f1, f2;
 45.1330 +			u32 position, product1;
 45.1331 +
 45.1332 +			position = w >> 16;
 45.1333 +			A		 = bP[position]; // current pixel
 45.1334 +			B		 = bP[position + 1]; // next pixel
 45.1335 +			C		 = bP[position + Nextline];
 45.1336 +			D		 = bP[position + Nextline + 1];
 45.1337 +			E		 = bP[position - Nextline];
 45.1338 +			F		 = bP[position - Nextline + 1];
 45.1339 +			G		 = bP[position - 1];
 45.1340 +			H		 = bP[position + Nextline - 1];
 45.1341 +			I		 = bP[position + 2];
 45.1342 +			J		 = bP[position + Nextline + 2];
 45.1343 +			K		 = bP[position + Nextline + Nextline];
 45.1344 +			L		 = bP[position + Nextline + Nextline + 1];
 45.1345 +
 45.1346 +			x1 = w & 0xffff; // fraction part of fixed point
 45.1347 +			x2 = 0x10000 - x1;
 45.1348 +
 45.1349 +			/*0*/
 45.1350 +			if (A == B && C == D && A == C)
 45.1351 +				product1 = A;
 45.1352 +			else /*1*/ if (A == D && B != C)
 45.1353 +			{
 45.1354 +				f1 = (x1 >> 1) + (0x10000 >> 2);
 45.1355 +				f2 = (y1 >> 1) + (0x10000 >> 2);
 45.1356 +				if (y1 <= f1 && A == J && A != E) // close to B
 45.1357 +				{
 45.1358 +					a1		 = f1 - y1;
 45.1359 +					product1 = Bilinear(A, B, a1);
 45.1360 +				}
 45.1361 +				else if (y1 >= f1 && A == G && A != L)  // close to C
 45.1362 +				{
 45.1363 +					a1		 = y1 - f1;
 45.1364 +					product1 = Bilinear(A, C, a1);
 45.1365 +				}
 45.1366 +				else if (x1 >= f2 && A == E && A != J) // close to B
 45.1367 +				{
 45.1368 +					a1		 = x1 - f2;
 45.1369 +					product1 = Bilinear(A, B, a1);
 45.1370 +				}
 45.1371 +				else if (x1 <= f2 && A == L && A != G) // close to C
 45.1372 +				{
 45.1373 +					a1		 = f2 - x1;
 45.1374 +					product1 = Bilinear(A, C, a1);
 45.1375 +				}
 45.1376 +				else if (y1 >= x1) // close to C
 45.1377 +				{
 45.1378 +					a1		 = y1 - x1;
 45.1379 +					product1 = Bilinear(A, C, a1);
 45.1380 +				}
 45.1381 +				else if (y1 <= x1) // close to B
 45.1382 +				{
 45.1383 +					a1		 = x1 - y1;
 45.1384 +					product1 = Bilinear(A, B, a1);
 45.1385 +				}
 45.1386 +			}
 45.1387 +			else
 45.1388 +				/*2*/
 45.1389 +				if (B == C && A != D)
 45.1390 +				{
 45.1391 +					f1 = (x1 >> 1) + (0x10000 >> 2);
 45.1392 +					f2 = (y1 >> 1) + (0x10000 >> 2);
 45.1393 +					if (y2 >= f1 && B == H && B != F) // close to A
 45.1394 +					{
 45.1395 +						a1		 = y2 - f1;
 45.1396 +						product1 = Bilinear(B, A, a1);
 45.1397 +					}
 45.1398 +					else if (y2 <= f1 && B == I && B != K) // close to D
 45.1399 +					{
 45.1400 +						a1		 = f1 - y2;
 45.1401 +						product1 = Bilinear(B, D, a1);
 45.1402 +					}
 45.1403 +					else if (x2 >= f2 && B == F && B != H) // close to A
 45.1404 +					{
 45.1405 +						a1		 = x2 - f2;
 45.1406 +						product1 = Bilinear(B, A, a1);
 45.1407 +					}
 45.1408 +					else if (x2 <= f2 && B == K && B != I) // close to D
 45.1409 +					{
 45.1410 +						a1		 = f2 - x2;
 45.1411 +						product1 = Bilinear(B, D, a1);
 45.1412 +					}
 45.1413 +					else if (y2 >= x1) // close to A
 45.1414 +					{
 45.1415 +						a1		 = y2 - x1;
 45.1416 +						product1 = Bilinear(B, A, a1);
 45.1417 +					}
 45.1418 +					else if (y2 <= x1) // close to D
 45.1419 +					{
 45.1420 +						a1		 = x1 - y2;
 45.1421 +						product1 = Bilinear(B, D, a1);
 45.1422 +					}
 45.1423 +				}
 45.1424 +				/*3*/
 45.1425 +				else
 45.1426 +				{
 45.1427 +					product1 = Bilinear4(A, B, C, D, x1, y1);
 45.1428 +				}
 45.1429 +
 45.1430 +			//end First Pixel
 45.1431 +			*(u32 *) dP = product1;
 45.1432 +			dP += 2;
 45.1433 +			w  += dw;
 45.1434 +		}
 45.1435 +		dstPtr += dstPitch;
 45.1436 +	}
 45.1437 +}
    46.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.2 +++ b/src/filters/2xSaImmx.asm	Sat Mar 03 10:31:27 2012 -0600
    46.3 @@ -0,0 +1,2109 @@
    46.4 +;/*---------------------------------------------------------------------*
    46.5 +; * The following (piece of) code, (part of) the 2xSaI engine,          *
    46.6 +; * copyright (c) 1999 - 2001 by Derek Liauw Kie Fa.                    *
    46.7 +; * Non-Commercial use of this software is allowed and is encouraged,   *
    46.8 +; * provided that appropriate credit be given.                          *
    46.9 +; * You may freely modify this code, but I request                      *
   46.10 +; * that any improvements to the engine be submitted to me, so          *
   46.11 +; * that I can implement these improvements in newer versions of        *
   46.12 +; * the software.                                                       *
   46.13 +; * If you need more information, have any comments or suggestions,     *
   46.14 +; * you can e-mail me. My e-mail: derek-liauw@usa.net.                  *
   46.15 +; *---------------------------------------------------------------------*/
   46.16 +
   46.17 +;----------------------
   46.18 +; 2xSaI version 0.59 WIP, soon to become version 0.60
   46.19 +;----------------------
   46.20 +
   46.21 +;%define FAR_POINTER
   46.22 +
   46.23 +
   46.24 +
   46.25 +          BITS 32
   46.26 +%ifdef __DJGPP__
   46.27 +          GLOBAL __2xSaILine
   46.28 +          GLOBAL __2xSaISuperEagleLine
   46.29 +                  GLOBAL __2xSaISuper2xSaILine
   46.30 +          GLOBAL _Init_2xSaIMMX
   46.31 +%else
   46.32 +          GLOBAL _2xSaILine
   46.33 +          GLOBAL _2xSaISuperEagleLine
   46.34 +                  GLOBAL _2xSaISuper2xSaILine
   46.35 +          GLOBAL Init_2xSaIMMX
   46.36 +%endif
   46.37 +          SECTION .text ALIGN = 32
   46.38 +
   46.39 +%ifdef FAR_POINTER
   46.40 +;EXTERN_C void _2xSaILine (uint8 *srcPtr, uint32 srcPitch, uint32 width,
   46.41 +;                        uint8 *dstPtr, uint32 dstPitch, uint16 dstSegment);
   46.42 +%else
   46.43 +;EXTERN_C void _2xSaILine (uint8 *srcPtr, uint32 srcPitch, uint32 width,
   46.44 +;                        uint8 *dstPtr, uint32 dstPitch);
   46.45 +%endif
   46.46 +
   46.47 +srcPtr        equ 8
   46.48 +deltaPtr      equ 12
   46.49 +srcPitch      equ 16
   46.50 +width         equ 20
   46.51 +dstOffset     equ 24
   46.52 +dstPitch      equ 28
   46.53 +dstSegment    equ 32
   46.54 +
   46.55 +
   46.56 +
   46.57 +
   46.58 +colorB0   equ -2
   46.59 +colorB1   equ 0
   46.60 +colorB2   equ 2
   46.61 +colorB3   equ 4
   46.62 +
   46.63 +color7   equ -2
   46.64 +color8   equ 0
   46.65 +color9   equ 2
   46.66 +
   46.67 +color4   equ -2
   46.68 +color5   equ 0
   46.69 +color6   equ 2
   46.70 +colorS2   equ 4
   46.71 +
   46.72 +color1   equ -2
   46.73 +color2   equ 0
   46.74 +color3   equ 2
   46.75 +colorS1   equ 4
   46.76 +
   46.77 +colorA0   equ -2
   46.78 +colorA1   equ 0
   46.79 +colorA2   equ 2
   46.80 +colorA3   equ 4
   46.81 +
   46.82 +
   46.83 +
   46.84 +
   46.85 +%ifdef __DJGPP__
   46.86 +__2xSaISuper2xSaILine:
   46.87 +%else
   46.88 +_2xSaISuper2xSaILine:
   46.89 +%endif
   46.90 +; Store some stuff
   46.91 +         push ebp
   46.92 +         mov ebp, esp
   46.93 +         pushad
   46.94 +
   46.95 +; Prepare the destination
   46.96 +%ifdef FAR_POINTER
   46.97 +         ; Set the selector
   46.98 +         mov eax, [ebp+dstSegment]
   46.99 +         mov fs, ax
  46.100 +%endif
  46.101 +         mov edx, [ebp+dstOffset]         ; edx points to the screen
  46.102 +; Prepare the source
  46.103 +         ; eax points to colorA
  46.104 +         mov eax, [ebp+srcPtr]                          ;eax points to colorA
  46.105 +         mov ebx, [ebp+srcPitch]                        ;ebx contains the source pitch
  46.106 +         mov ecx, [ebp+width]                           ;ecx contains the number of pixels to process
  46.107 +         ; eax now points to colorB1
  46.108 +         sub eax, ebx                                           ;eax points to B1 which is the base 
  46.109 +
  46.110 +; Main Loop
  46.111 +.Loop:   push ecx
  46.112 +
  46.113 +         ;-----Check Delta------------------
  46.114 +         mov ecx, [ebp+deltaPtr]
  46.115 +
  46.116 +
  46.117 +                ;load source img
  46.118 +         movq mm0, [eax+colorB0]
  46.119 +         movq mm1, [eax+colorB3]
  46.120 +         movq mm2, [eax+ebx+color4]
  46.121 +         movq mm3, [eax+ebx+colorS2]
  46.122 +         movq mm4, [eax+ebx+ebx+color1]
  46.123 +         movq mm5, [eax+ebx+ebx+colorS1]
  46.124 +         push eax
  46.125 +         add eax, ebx
  46.126 +         movq mm6, [eax+ebx+ebx+colorA0]
  46.127 +         movq mm7, [eax+ebx+ebx+colorA3]
  46.128 +         pop eax
  46.129 +
  46.130 +                ;compare to delta
  46.131 +         pcmpeqw mm0, [ecx+2+colorB0]
  46.132 +         pcmpeqw mm1, [ecx+2+colorB3]
  46.133 +         pcmpeqw mm2, [ecx+ebx+2+color4]
  46.134 +         pcmpeqw mm3, [ecx+ebx+2+colorS2]
  46.135 +         pcmpeqw mm4, [ecx+ebx+ebx+2+color1]
  46.136 +         pcmpeqw mm5, [ecx+ebx+ebx+2+colorS1]
  46.137 +         add ecx, ebx
  46.138 +         pcmpeqw mm6, [ecx+ebx+ebx+2+colorA0]
  46.139 +         pcmpeqw mm7, [ecx+ebx+ebx+2+colorA3]
  46.140 +         sub ecx, ebx
  46.141 +
  46.142 +
  46.143 +                ;compose results
  46.144 +         pand mm0, mm1
  46.145 +         pand mm2, mm3
  46.146 +         pand mm4, mm5
  46.147 +         pand mm6, mm7
  46.148 +         pand mm0, mm2
  46.149 +         pand mm4, mm6
  46.150 +         pxor mm7, mm7
  46.151 +         pand mm0, mm4
  46.152 +         movq mm6, [eax+colorB0]
  46.153 +         pcmpeqw mm7, mm0                       ;did any compare give us a zero ?
  46.154 +
  46.155 +         movq [ecx+2+colorB0], mm6
  46.156 +
  46.157 +         packsswb mm7, mm7
  46.158 +         movd ecx, mm7
  46.159 +         test ecx, ecx                          
  46.160 +         jz near .SKIP_PROCESS          ;no, so we can skip
  46.161 +
  46.162 +         ;End Delta
  46.163 +
  46.164 +         ;---------------------------------
  46.165 +         movq mm0, [eax+ebx+color5]
  46.166 +         movq mm1, [eax+ebx+color6]
  46.167 +         movq mm2, mm0
  46.168 +         movq mm3, mm1
  46.169 +         movq mm4, mm0
  46.170 +         movq mm5, mm1
  46.171 +
  46.172 +         pand mm0, [colorMask]
  46.173 +         pand mm1, [colorMask]
  46.174 +
  46.175 +         psrlw mm0, 1
  46.176 +         psrlw mm1, 1
  46.177 +
  46.178 +         pand mm3, [lowPixelMask]
  46.179 +         paddw mm0, mm1
  46.180 +
  46.181 +         pand mm3, mm2
  46.182 +         paddw mm0, mm3                ;mm0 contains the interpolated values
  46.183 +         movq [I56Pixel], mm0
  46.184 +         movq mm7, mm0
  46.185 +
  46.186 +         ;-------------------
  46.187 +         movq mm0, mm7
  46.188 +         movq mm1, mm4  ;5,5,5,6
  46.189 +         movq mm2, mm0
  46.190 +         movq mm3, mm1
  46.191 +
  46.192 +         pand mm0, [colorMask]
  46.193 +         pand mm1, [colorMask]
  46.194 +
  46.195 +         psrlw mm0, 1
  46.196 +         psrlw mm1, 1
  46.197 +
  46.198 +         pand mm3, [lowPixelMask]
  46.199 +         paddw mm0, mm1
  46.200 +
  46.201 +         pand mm3, mm2
  46.202 +         paddw mm0, mm3                ;mm0 contains the interpolated values
  46.203 +         movq [I5556Pixel], mm0
  46.204 +         ;--------------------
  46.205 +
  46.206 +         movq mm0, mm7
  46.207 +         movq mm1, mm5  ;6,6,6,5
  46.208 +         movq mm2, mm0
  46.209 +         movq mm3, mm1
  46.210 +
  46.211 +         pand mm0, [colorMask]
  46.212 +         pand mm1, [colorMask]
  46.213 +
  46.214 +         psrlw mm0, 1
  46.215 +         psrlw mm1, 1
  46.216 +
  46.217 +         pand mm3, [lowPixelMask]
  46.218 +         paddw mm0, mm1
  46.219 +
  46.220 +         pand mm3, mm2
  46.221 +         paddw mm0, mm3
  46.222 +         movq [I5666Pixel], mm0
  46.223 +
  46.224 +         ;-------------------------
  46.225 +         ;-------------------------
  46.226 +         movq mm0, [eax+ebx+ebx+color2]
  46.227 +         movq mm1, [eax+ebx+ebx+color3]
  46.228 +         movq mm2, mm0
  46.229 +         movq mm3, mm1
  46.230 +         movq mm4, mm0
  46.231 +         movq mm5, mm1
  46.232 +
  46.233 +         pand mm0, [colorMask]
  46.234 +         pand mm1, [colorMask]
  46.235 +
  46.236 +         psrlw mm0, 1
  46.237 +         psrlw mm1, 1
  46.238 +
  46.239 +         pand mm3, [lowPixelMask]
  46.240 +         paddw mm0, mm1
  46.241 +
  46.242 +         pand mm3, mm2
  46.243 +         paddw mm0, mm3
  46.244 +         movq [I23Pixel], mm0
  46.245 +         movq mm7, mm0
  46.246 +
  46.247 +         ;---------------------
  46.248 +         movq mm0, mm7
  46.249 +         movq mm1, mm4  ;2,2,2,3
  46.250 +         movq mm2, mm0
  46.251 +         movq mm3, mm1
  46.252 +
  46.253 +         pand mm0, [colorMask]
  46.254 +         pand mm1, [colorMask]
  46.255 +
  46.256 +         psrlw mm0, 1
  46.257 +         psrlw mm1, 1
  46.258 +
  46.259 +         pand mm3, [lowPixelMask]
  46.260 +         paddw mm0, mm1
  46.261 +
  46.262 +         pand mm3, mm2
  46.263 +         paddw mm0, mm3
  46.264 +         movq [I2223Pixel], mm0
  46.265 +
  46.266 +         ;----------------------
  46.267 +         movq mm0, mm7
  46.268 +         movq mm1, mm5  ;3,3,3,2
  46.269 +         movq mm2, mm0
  46.270 +         movq mm3, mm1
  46.271 +
  46.272 +         pand mm0, [colorMask]
  46.273 +         pand mm1, [colorMask]
  46.274 +
  46.275 +         psrlw mm0, 1
  46.276 +         psrlw mm1, 1
  46.277 +
  46.278 +         pand mm3, [lowPixelMask]
  46.279 +         paddw mm0, mm1
  46.280 +
  46.281 +         pand mm3, mm2
  46.282 +         paddw mm0, mm3
  46.283 +         movq [I2333Pixel], mm0
  46.284 +
  46.285 +
  46.286 +         ;--------------------
  46.287 +;////////////////////////////////
  46.288 +; Decide which "branch" to take
  46.289 +;--------------------------------
  46.290 +         movq mm0, [eax+ebx+color5]
  46.291 +         movq mm1, [eax+ebx+color6]
  46.292 +         movq mm6, mm0
  46.293 +         movq mm7, mm1
  46.294 +         pcmpeqw mm0, [eax+ebx+ebx+color3]
  46.295 +         pcmpeqw mm1, [eax+ebx+ebx+color2]
  46.296 +         pcmpeqw mm6, mm7
  46.297 +
  46.298 +         movq mm2, mm0
  46.299 +         movq mm3, mm0
  46.300 +
  46.301 +         pand mm0, mm1       ;colorA == colorD && colorB == colorC
  46.302 +         pxor mm7, mm7
  46.303 +
  46.304 +         pcmpeqw mm2, mm7
  46.305 +         pand mm6, mm0
  46.306 +         pand mm2, mm1       ;colorA != colorD && colorB == colorC
  46.307 +
  46.308 +         pcmpeqw mm1, mm7
  46.309 +
  46.310 +         pand mm1, mm3       ;colorA == colorD && colorB != colorC
  46.311 +         pxor mm0, mm6
  46.312 +         por mm1, mm6
  46.313 +         movq mm7, mm0
  46.314 +         movq [Mask26], mm2
  46.315 +         packsswb mm7, mm7
  46.316 +         movq [Mask35], mm1
  46.317 +
  46.318 +         movd ecx, mm7
  46.319 +         test ecx, ecx
  46.320 +         jz near .SKIP_GUESS
  46.321 +
  46.322 +;---------------------------------------------
  46.323 +         movq mm6, mm0
  46.324 +         movq mm4, [eax+ebx+colorA]
  46.325 +         movq mm5, [eax+ebx+colorB]
  46.326 +         pxor mm7, mm7
  46.327 +         pand mm6, [ONE]
  46.328 +
  46.329 +         movq mm0, [eax+colorE]
  46.330 +         movq mm1, [eax+ebx+colorG]
  46.331 +         movq mm2, mm0
  46.332 +         movq mm3, mm1
  46.333 +         pcmpeqw mm0, mm4
  46.334 +         pcmpeqw mm1, mm4
  46.335 +         pcmpeqw mm2, mm5
  46.336 +         pcmpeqw mm3, mm5
  46.337 +         pand mm0, mm6
  46.338 +         pand mm1, mm6
  46.339 +         pand mm2, mm6
  46.340 +         pand mm3, mm6
  46.341 +         paddw mm0, mm1
  46.342 +         paddw mm2, mm3
  46.343 +
  46.344 +         pxor mm3, mm3
  46.345 +         pcmpgtw mm0, mm6
  46.346 +         pcmpgtw mm2, mm6
  46.347 +         pcmpeqw mm0, mm3
  46.348 +         pcmpeqw mm2, mm3
  46.349 +         pand mm0, mm6
  46.350 +         pand mm2, mm6
  46.351 +         paddw mm7, mm0
  46.352 +         psubw mm7, mm2
  46.353 +
  46.354 +         movq mm0, [eax+colorF]
  46.355 +         movq mm1, [eax+ebx+colorK]
  46.356 +         movq mm2, mm0
  46.357 +         movq mm3, mm1
  46.358 +         pcmpeqw mm0, mm4
  46.359 +         pcmpeqw mm1, mm4
  46.360 +         pcmpeqw mm2, mm5
  46.361 +         pcmpeqw mm3, mm5
  46.362 +         pand mm0, mm6
  46.363 +         pand mm1, mm6
  46.364 +         pand mm2, mm6
  46.365 +         pand mm3, mm6
  46.366 +         paddw mm0, mm1
  46.367 +         paddw mm2, mm3
  46.368 +
  46.369 +         pxor mm3, mm3
  46.370 +         pcmpgtw mm0, mm6
  46.371 +         pcmpgtw mm2, mm6
  46.372 +         pcmpeqw mm0, mm3
  46.373 +         pcmpeqw mm2, mm3
  46.374 +         pand mm0, mm6
  46.375 +         pand mm2, mm6
  46.376 +         paddw mm7, mm0
  46.377 +         psubw mm7, mm2
  46.378 +
  46.379 +         push eax
  46.380 +         add eax, ebx
  46.381 +         movq mm0, [eax+ebx+colorH]
  46.382 +         movq mm1, [eax+ebx+ebx+colorN]
  46.383 +         movq mm2, mm0
  46.384 +         movq mm3, mm1
  46.385 +         pcmpeqw mm0, mm4
  46.386 +         pcmpeqw mm1, mm4
  46.387 +         pcmpeqw mm2, mm5
  46.388 +         pcmpeqw mm3, mm5
  46.389 +         pand mm0, mm6
  46.390 +         pand mm1, mm6
  46.391 +         pand mm2, mm6
  46.392 +         pand mm3, mm6
  46.393 +         paddw mm0, mm1
  46.394 +         paddw mm2, mm3
  46.395 +
  46.396 +         pxor mm3, mm3
  46.397 +         pcmpgtw mm0, mm6
  46.398 +         pcmpgtw mm2, mm6
  46.399 +         pcmpeqw mm0, mm3
  46.400 +         pcmpeqw mm2, mm3
  46.401 +         pand mm0, mm6
  46.402 +         pand mm2, mm6
  46.403 +         paddw mm7, mm0
  46.404 +         psubw mm7, mm2
  46.405 +
  46.406 +         movq mm0, [eax+ebx+colorL]
  46.407 +         movq mm1, [eax+ebx+ebx+colorO]
  46.408 +         movq mm2, mm0
  46.409 +         movq mm3, mm1
  46.410 +         pcmpeqw mm0, mm4
  46.411 +         pcmpeqw mm1, mm4
  46.412 +         pcmpeqw mm2, mm5
  46.413 +         pcmpeqw mm3, mm5
  46.414 +         pand mm0, mm6
  46.415 +         pand mm1, mm6
  46.416 +         pand mm2, mm6
  46.417 +         pand mm3, mm6
  46.418 +         paddw mm0, mm1
  46.419 +         paddw mm2, mm3
  46.420 +
  46.421 +         pxor mm3, mm3
  46.422 +         pcmpgtw mm0, mm6
  46.423 +         pcmpgtw mm2, mm6
  46.424 +         pcmpeqw mm0, mm3
  46.425 +         pcmpeqw mm2, mm3
  46.426 +         pand mm0, mm6
  46.427 +         pand mm2, mm6
  46.428 +         paddw mm7, mm0
  46.429 +         psubw mm7, mm2
  46.430 +
  46.431 +         pop eax
  46.432 +         movq mm1, mm7
  46.433 +         pxor mm0, mm0
  46.434 +         pcmpgtw mm7, mm0
  46.435 +         pcmpgtw mm0, mm1
  46.436 +
  46.437 +         por mm7, [Mask35]
  46.438 +         por mm0, [Mask26] 
  46.439 +         movq [Mask35], mm7
  46.440 +         movq [Mask26], mm0
  46.441 +
  46.442 +.SKIP_GUESS:
  46.443 +
  46.444 +         ;Start the ASSEMBLY !!!        eh... compose all the results together to form the final image...
  46.445 +
  46.446 +                 
  46.447 +         movq mm0, [eax+ebx+color5]
  46.448 +         movq mm1, [eax+ebx+ebx+color2]
  46.449 +         movq mm2, mm0
  46.450 +         movq mm3, mm1
  46.451 +         movq mm4, mm0
  46.452 +         movq mm5, mm1
  46.453 +
  46.454 +         pand mm0, [colorMask]
  46.455 +         pand mm1, [colorMask]
  46.456 +
  46.457 +         psrlw mm0, 1
  46.458 +         psrlw mm1, 1
  46.459 +
  46.460 +         pand mm3, [lowPixelMask]
  46.461 +         paddw mm0, mm1
  46.462 +
  46.463 +         pand mm3, mm2
  46.464 +         paddw mm0, mm3                ;mm0 contains the interpolated values
  46.465 +                 ;---------------------------
  46.466 +
  46.467 +
  46.468 +
  46.469 +%ifdef dfhsdfhsdahdsfhdsfh
  46.470 +
  46.471 +                if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2)
  46.472 +                   product2a = INTERPOLATE (color2, color5);
  46.473 +                else
  46.474 +                if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0)
  46.475 +                   product2a = INTERPOLATE(color2, color5);
  46.476 +                else
  46.477 +                   product2a = color2;
  46.478 +
  46.479 +                if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2)
  46.480 +                   product1a = INTERPOLATE (color2, color5);
  46.481 +                else
  46.482 +                if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0)
  46.483 +                   product1a = INTERPOLATE(color2, color5);
  46.484 +                else
  46.485 +                   product1a = color5;
  46.486 +
  46.487 +%endif
  46.488 +
  46.489 +
  46.490 +                 movq mm7, [Mask26]
  46.491 +                 movq mm6, [eax+colorB2]
  46.492 +                 movq mm5, [eax+ebx+ebx+color2]
  46.493 +                 movq mm4, [eax+ebx+ebx+color1]
  46.494 +                 pcmpeqw mm4, mm5
  46.495 +                 pcmpeqw mm6, mm5
  46.496 +                 pxor mm5, mm5
  46.497 +                 pand mm7, mm4
  46.498 +                 pcmpeqw mm6, mm5
  46.499 +                 pand mm7, mm6
  46.500 +
  46.501 +
  46.502 +
  46.503 +                 movq mm6, [eax+ebx+ebx+color3]
  46.504 +                 movq mm5, [eax+ebx+ebx+color2]
  46.505 +                 movq mm4, [eax+ebx+ebx+color1]
  46.506 +                 movq mm2, [eax+ebx+color5]
  46.507 +                 movq mm1, [eax+ebx+color4]
  46.508 +                 movq mm3, [eax+colorB0]
  46.509 +
  46.510 +                 pcmpeqw mm2, mm4
  46.511 +                 pcmpeqw mm6, mm5
  46.512 +                 pcmpeqw mm1, mm5
  46.513 +                 pcmpeqw mm3, mm5
  46.514 +                 pxor mm5, mm5
  46.515 +                 pcmpeqw mm2, mm5
  46.516 +                 pcmpeqw mm3, mm5
  46.517 +                 pand mm6, mm1
  46.518 +                 pand mm2, mm3
  46.519 +                 pand mm6, mm2
  46.520 +                 por mm7, mm6
  46.521 +
  46.522 +                 
  46.523 +                 movq mm6, mm7
  46.524 +                 pcmpeqw mm6, mm5
  46.525 +                 pand mm7, mm0
  46.526 +
  46.527 +                 movq mm1, [eax+ebx+color5]
  46.528 +                 pand mm6, mm1
  46.529 +                 por mm7, mm6
  46.530 +                 movq [final1a], mm7                    ;finished  1a
  46.531 +
  46.532 +
  46.533 +         
  46.534 +             ;--------------------------------           
  46.535 +
  46.536 +                 movq mm7, [Mask35]
  46.537 +                 push eax
  46.538 +                 add eax, ebx
  46.539 +                 movq mm6, [eax+ebx+ebx+colorA2]
  46.540 +                 pop eax
  46.541 +                 movq mm5, [eax+ebx+color5]
  46.542 +                 movq mm4, [eax+ebx+color4]
  46.543 +                 pcmpeqw mm4, mm5
  46.544 +                 pcmpeqw mm6, mm5
  46.545 +                 pxor mm5, mm5
  46.546 +                 pand mm7, mm4
  46.547 +                 pcmpeqw mm6, mm5
  46.548 +                 pand mm7, mm6
  46.549 +
  46.550 +
  46.551 +
  46.552 +                 movq mm6, [eax+ebx+color6]
  46.553 +                 movq mm5, [eax+ebx+color5]
  46.554 +                 movq mm4, [eax+ebx+color4]
  46.555 +                 movq mm2, [eax+ebx+ebx+color2]
  46.556 +                 movq mm1, [eax+ebx+ebx+color1]
  46.557 +                 push eax
  46.558 +                 add eax, ebx
  46.559 +                 movq mm3, [eax+ebx+ebx+colorA0]
  46.560 +                 pop eax
  46.561 +
  46.562 +                 pcmpeqw mm2, mm4
  46.563 +                 pcmpeqw mm6, mm5
  46.564 +                 pcmpeqw mm1, mm5
  46.565 +                 pcmpeqw mm3, mm5
  46.566 +                 pxor mm5, mm5
  46.567 +                 pcmpeqw mm2, mm5
  46.568 +                 pcmpeqw mm3, mm5
  46.569 +                 pand mm6, mm1
  46.570 +                 pand mm2, mm3
  46.571 +                 pand mm6, mm2
  46.572 +                 por mm7, mm6
  46.573 +
  46.574 +                 
  46.575 +                 movq mm6, mm7
  46.576 +                 pcmpeqw mm6, mm5
  46.577 +                 pand mm7, mm0
  46.578 +
  46.579 +                 movq mm1, [eax+ebx+ebx+color2]
  46.580 +                 pand mm6, mm1
  46.581 +                 por mm7, mm6
  46.582 +                 movq [final2a], mm7                    ;finished  2a
  46.583 +
  46.584 +
  46.585 +                 ;--------------------------------------------
  46.586 + 
  46.587 +
  46.588 +%ifdef dfhsdfhsdahdsfhdsfh
  46.589 +                   if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0)
  46.590 +                      product2b = Q_INTERPOLATE (color3, color3, color3, color2);
  46.591 +                   else
  46.592 +                   if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3)
  46.593 +                      product2b = Q_INTERPOLATE (color2, color2, color2, color3);
  46.594 +                   else
  46.595 +                      product2b = INTERPOLATE (color2, color3);
  46.596 +
  46.597 +                   if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0)
  46.598 +                      product1b = Q_INTERPOLATE (color6, color6, color6, color5);
  46.599 +                   else
  46.600 +                   if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3)
  46.601 +                      product1b = Q_INTERPOLATE (color6, color5, color5, color5);
  46.602 +                   else
  46.603 +                      product1b = INTERPOLATE (color5, color6);
  46.604 +%endif
  46.605 +
  46.606 +                 push eax
  46.607 +                 add eax, ebx
  46.608 +                 pxor mm7, mm7
  46.609 +                 movq mm0, [eax+ebx+ebx+colorA0]
  46.610 +                 movq mm1, [eax+ebx+ebx+colorA1]
  46.611 +                 movq mm2, [eax+ebx+ebx+colorA2]
  46.612 +                 movq mm3, [eax+ebx+ebx+colorA3]
  46.613 +                 pop eax
  46.614 +                 movq mm4, [eax+ebx+ebx+color2]
  46.615 +                 movq mm5, [eax+ebx+ebx+color3]
  46.616 +                 movq mm6, [eax+ebx+color6]
  46.617 +
  46.618 +                 pcmpeqw mm6, mm5
  46.619 +                 pcmpeqw mm1, mm5
  46.620 +                 pcmpeqw mm4, mm2
  46.621 +                 pcmpeqw mm0, mm5
  46.622 +                 pcmpeqw mm4, mm7
  46.623 +                 pcmpeqw mm0, mm7
  46.624 +                 pand mm0, mm4
  46.625 +                 pand mm6, mm1
  46.626 +                 pand mm0, mm6
  46.627 +
  46.628 +
  46.629 +                 push eax
  46.630 +                 add eax, ebx
  46.631 +                 movq mm1, [eax+ebx+ebx+colorA1]
  46.632 +                 pop eax
  46.633 +                 movq mm4, [eax+ebx+ebx+color2]
  46.634 +                 movq mm5, [eax+ebx+color5]
  46.635 +                 movq mm6, [eax+ebx+ebx+color3]
  46.636 +
  46.637 +                 pcmpeqw mm5, mm4
  46.638 +                 pcmpeqw mm2, mm4
  46.639 +                 pcmpeqw mm1, mm6
  46.640 +                 pcmpeqw mm3, mm4
  46.641 +                 pcmpeqw mm1, mm7
  46.642 +                 pcmpeqw mm3, mm7
  46.643 +                 pand mm2, mm5
  46.644 +                 pand mm1, mm3
  46.645 +                 pand mm1, mm2
  46.646 +
  46.647 +
  46.648 +                 movq mm7, mm0
  46.649 +                 por mm7, mm1
  46.650 +
  46.651 +                 movq mm4, [Mask35]
  46.652 +                 movq mm3, [Mask26]
  46.653 +                 
  46.654 +                 movq mm6, mm4
  46.655 +                 pand mm6, mm7
  46.656 +                 pxor mm4, mm6
  46.657 +
  46.658 +                 movq mm6, mm3
  46.659 +                 pand mm6, mm7
  46.660 +                 pxor mm3, mm6
  46.661 +
  46.662 +                 movq mm2, mm0
  46.663 +                 movq mm7, [I2333Pixel]
  46.664 +                 movq mm6, [I2223Pixel]
  46.665 +                 movq mm5, [I23Pixel]
  46.666 +
  46.667 +
  46.668 +                 por mm2, mm4
  46.669 +                 pand mm4, [eax+ebx+ebx+color3]
  46.670 +                 por mm2, mm3
  46.671 +                 pand mm3, [eax+ebx+ebx+color2]
  46.672 +                 por mm2, mm1
  46.673 +                 pand mm0, mm7
  46.674 +                 pand mm1, mm6
  46.675 +                 pxor mm7, mm7
  46.676 +                 pcmpeqw mm2, mm7
  46.677 +                 por mm0, mm1
  46.678 +                 por mm3, mm4
  46.679 +                 pand mm2, mm5
  46.680 +                 por mm0, mm3
  46.681 +                 por mm0, mm2
  46.682 +                 movq [final2b], mm0
  46.683 +
  46.684 +                 ;-----------------------------------
  46.685 +                 
  46.686 +
  46.687 +                 pxor mm7, mm7
  46.688 +                 movq mm0, [eax+colorB0]
  46.689 +                 movq mm1, [eax+colorB1]
  46.690 +                 movq mm2, [eax+colorB2]
  46.691 +                 movq mm3, [eax+colorB3]
  46.692 +                 movq mm4, [eax+ebx+color5]
  46.693 +                 movq mm5, [eax+ebx+color6]
  46.694 +                 movq mm6, [eax+ebx+ebx+color3]
  46.695 +
  46.696 +                 pcmpeqw mm6, mm5
  46.697 +                 pcmpeqw mm1, mm5
  46.698 +                 pcmpeqw mm4, mm2
  46.699 +                 pcmpeqw mm0, mm5
  46.700 +                 pcmpeqw mm4, mm7
  46.701 +                 pcmpeqw mm0, mm7
  46.702 +                 pand mm0, mm4
  46.703 +                 pand mm6, mm1
  46.704 +                 pand mm0, mm6
  46.705 +
  46.706 +                 movq mm1, [eax+colorB1]
  46.707 +                 movq mm4, [eax+ebx+color5]
  46.708 +                 movq mm5, [eax+ebx+ebx+color2]
  46.709 +                 movq mm6, [eax+ebx+color6]
  46.710 +
  46.711 +                 pcmpeqw mm5, mm4
  46.712 +                 pcmpeqw mm2, mm4
  46.713 +                 pcmpeqw mm1, mm6
  46.714 +                 pcmpeqw mm3, mm4
  46.715 +                 pcmpeqw mm1, mm7
  46.716 +                 pcmpeqw mm3, mm7
  46.717 +                 pand mm2, mm5
  46.718 +                 pand mm1, mm3
  46.719 +                 pand mm1, mm2
  46.720 +
  46.721 +
  46.722 +                 movq mm7, mm0
  46.723 +                 por mm7, mm1
  46.724 +
  46.725 +                 movq mm4, [Mask35]
  46.726 +                 movq mm3, [Mask26]
  46.727 +                 
  46.728 +                 movq mm6, mm4
  46.729 +                 pand mm6, mm7
  46.730 +                 pxor mm4, mm6
  46.731 +
  46.732 +                 movq mm6, mm3
  46.733 +                 pand mm6, mm7
  46.734 +                 pxor mm3, mm6
  46.735 +
  46.736 +                 movq mm2, mm0
  46.737 +                 movq mm7, [I5666Pixel]
  46.738 +                 movq mm6, [I5556Pixel]
  46.739 +                 movq mm5, [I56Pixel]
  46.740 +
  46.741 +
  46.742 +                 por mm2, mm4
  46.743 +                 pand mm4, [eax+ebx+color5]
  46.744 +                 por mm2, mm3
  46.745 +                 pand mm3, [eax+ebx+color6]
  46.746 +                 por mm2, mm1
  46.747 +                 pand mm0, mm7
  46.748 +                 pand mm1, mm6
  46.749 +                 pxor mm7, mm7
  46.750 +                 pcmpeqw mm2, mm7
  46.751 +                 por mm0, mm1
  46.752 +                 por mm3, mm4
  46.753 +                 pand mm2, mm5
  46.754 +                 por mm0, mm3
  46.755 +                 por mm0, mm2
  46.756 +                 movq [final1b], mm0
  46.757 +                 
  46.758 +          ;---------
  46.759 +
  46.760 +                 movq mm0, [final1a]
  46.761 +                 movq mm4, [final2a]
  46.762 +                 movq mm2, [final1b]
  46.763 +                 movq mm6, [final2b]
  46.764 +
  46.765 +
  46.766 +                 movq mm1, mm0
  46.767 +                 movq mm5, mm4
  46.768 +
  46.769 +
  46.770 +         punpcklwd mm0, mm2
  46.771 +         punpckhwd mm1, mm2
  46.772 +
  46.773 +         punpcklwd mm4, mm6
  46.774 +         punpckhwd mm5, mm6
  46.775 +
  46.776 +
  46.777 +%ifdef FAR_POINTER
  46.778 +         movq [fs:edx], mm0
  46.779 +         movq [fs:edx+8], mm1
  46.780 +         push edx
  46.781 +         add edx, [ebp+dstPitch]
  46.782 +         movq [fs:edx], mm4
  46.783 +         movq [fs:edx+8], mm5
  46.784 +         pop edx
  46.785 +%else
  46.786 +         movq [edx], mm0
  46.787 +         movq [edx+8], mm1
  46.788 +         push edx
  46.789 +         add edx, [ebp+dstPitch]
  46.790 +         movq [edx], mm4
  46.791 +         movq [edx+8], mm5
  46.792 +         pop edx
  46.793 +%endif
  46.794 +.SKIP_PROCESS:
  46.795 +         mov ecx, [ebp+deltaPtr]
  46.796 +         add ecx, 8
  46.797 +         mov [ebp+deltaPtr], ecx
  46.798 +         add edx, 16
  46.799 +         add eax, 8
  46.800 +
  46.801 +         pop ecx
  46.802 +         sub ecx, 4
  46.803 +         cmp ecx, 0
  46.804 +         jg  near .Loop
  46.805 +
  46.806 +; Restore some stuff
  46.807 +         popad
  46.808 +         mov esp, ebp
  46.809 +         pop ebp
  46.810 +         emms
  46.811 +         ret
  46.812 +
  46.813 +
  46.814 +;-------------------------------------------------------------------------
  46.815 +;-------------------------------------------------------------------------
  46.816 +;-------------------------------------------------------------------------
  46.817 +;-------------------------------------------------------------------------
  46.818 +;-------------------------------------------------------------------------
  46.819 +;-------------------------------------------------------------------------
  46.820 +;-------------------------------------------------------------------------
  46.821 +
  46.822 +
  46.823 +
  46.824 +%ifdef __DJGPP__
  46.825 +__2xSaISuperEagleLine:
  46.826 +%else
  46.827 +_2xSaISuperEagleLine:
  46.828 +%endif
  46.829 +; Store some stuff
  46.830 +         push ebp
  46.831 +         mov ebp, esp
  46.832 +         pushad
  46.833 +
  46.834 +; Prepare the destination
  46.835 +%ifdef FAR_POINTER
  46.836 +         ; Set the selector
  46.837 +         mov eax, [ebp+dstSegment]
  46.838 +         mov fs, ax
  46.839 +%endif
  46.840 +         mov edx, [ebp+dstOffset]         ; edx points to the screen
  46.841 +; Prepare the source
  46.842 +         ; eax points to colorA
  46.843 +         mov eax, [ebp+srcPtr]
  46.844 +         mov ebx, [ebp+srcPitch]
  46.845 +         mov ecx, [ebp+width]
  46.846 +         ; eax now points to colorB1
  46.847 +         sub eax, ebx
  46.848 +
  46.849 +; Main Loop
  46.850 +.Loop:   push ecx
  46.851 +
  46.852 +         ;-----Check Delta------------------
  46.853 +         mov ecx, [ebp+deltaPtr]
  46.854 +
  46.855 +         movq mm0, [eax+colorB0]
  46.856 +         movq mm1, [eax+colorB3]
  46.857 +         movq mm2, [eax+ebx+color4]
  46.858 +         movq mm3, [eax+ebx+colorS2]
  46.859 +         movq mm4, [eax+ebx+ebx+color1]
  46.860 +         movq mm5, [eax+ebx+ebx+colorS1]
  46.861 +         push eax
  46.862 +         add eax, ebx
  46.863 +         movq mm6, [eax+ebx+ebx+colorA0]
  46.864 +         movq mm7, [eax+ebx+ebx+colorA3]
  46.865 +         pop eax
  46.866 +
  46.867 +         pcmpeqw mm0, [ecx+2+colorB0]
  46.868 +         pcmpeqw mm1, [ecx+2+colorB3]
  46.869 +         pcmpeqw mm2, [ecx+ebx+2+color4]
  46.870 +         pcmpeqw mm3, [ecx+ebx+2+colorS2]
  46.871 +         pcmpeqw mm4, [ecx+ebx+ebx+2+color1]
  46.872 +         pcmpeqw mm5, [ecx+ebx+ebx+2+colorS1]
  46.873 +         add ecx, ebx
  46.874 +         pcmpeqw mm6, [ecx+ebx+ebx+2+colorA0]
  46.875 +         pcmpeqw mm7, [ecx+ebx+ebx+2+colorA3]
  46.876 +         sub ecx, ebx
  46.877 +
  46.878 +
  46.879 +         pand mm0, mm1
  46.880 +         pand mm2, mm3
  46.881 +         pand mm4, mm5
  46.882 +         pand mm6, mm7
  46.883 +         pand mm0, mm2
  46.884 +         pand mm4, mm6
  46.885 +         pxor mm7, mm7
  46.886 +         pand mm0, mm4
  46.887 +         movq mm6, [eax+colorB0]
  46.888 +         pcmpeqw mm7, mm0
  46.889 +
  46.890 +         movq [ecx+2+colorB0], mm6
  46.891 +
  46.892 +         packsswb mm7, mm7
  46.893 +         movd ecx, mm7
  46.894 +         test ecx, ecx
  46.895 +         jz near .SKIP_PROCESS
  46.896 +
  46.897 +         ;End Delta
  46.898 +
  46.899 +         ;---------------------------------
  46.900 +         movq mm0, [eax+ebx+color5]
  46.901 +         movq mm1, [eax+ebx+color6]
  46.902 +         movq mm2, mm0
  46.903 +         movq mm3, mm1
  46.904 +         movq mm4, mm0
  46.905 +         movq mm5, mm1
  46.906 +
  46.907 +         pand mm0, [colorMask]
  46.908 +         pand mm1, [colorMask]
  46.909 +
  46.910 +         psrlw mm0, 1
  46.911 +         psrlw mm1, 1
  46.912 +
  46.913 +         pand mm3, [lowPixelMask]
  46.914 +         paddw mm0, mm1
  46.915 +
  46.916 +         pand mm3, mm2
  46.917 +         paddw mm0, mm3                ;mm0 contains the interpolated values
  46.918 +         movq [I56Pixel], mm0
  46.919 +         movq mm7, mm0
  46.920 +
  46.921 +         ;-------------------
  46.922 +         movq mm0, mm7
  46.923 +         movq mm1, mm4  ;5,5,5,6
  46.924 +         movq mm2, mm0
  46.925 +         movq mm3, mm1
  46.926 +
  46.927 +         pand mm0, [colorMask]
  46.928 +         pand mm1, [colorMask]
  46.929 +
  46.930 +         psrlw mm0, 1
  46.931 +         psrlw mm1, 1
  46.932 +
  46.933 +         pand mm3, [lowPixelMask]
  46.934 +         paddw mm0, mm1
  46.935 +
  46.936 +         pand mm3, mm2
  46.937 +         paddw mm0, mm3                ;mm0 contains the interpolated values
  46.938 +         movq [product1a], mm0
  46.939 +         ;--------------------
  46.940 +
  46.941 +         movq mm0, mm7
  46.942 +         movq mm1, mm5  ;6,6,6,5
  46.943 +         movq mm2, mm0
  46.944 +         movq mm3, mm1
  46.945 +
  46.946 +         pand mm0, [colorMask]
  46.947 +         pand mm1, [colorMask]
  46.948 +
  46.949 +         psrlw mm0, 1
  46.950 +         psrlw mm1, 1
  46.951 +
  46.952 +         pand mm3, [lowPixelMask]
  46.953 +         paddw mm0, mm1
  46.954 +
  46.955 +         pand mm3, mm2
  46.956 +         paddw mm0, mm3
  46.957 +         movq [product1b], mm0
  46.958 +
  46.959 +         ;-------------------------
  46.960 +         ;-------------------------
  46.961 +         movq mm0, [eax+ebx+ebx+color2]
  46.962 +         movq mm1, [eax+ebx+ebx+color3]
  46.963 +         movq mm2, mm0
  46.964 +         movq mm3, mm1
  46.965 +         movq mm4, mm0
  46.966 +         movq mm5, mm1
  46.967 +
  46.968 +         pand mm0, [colorMask]
  46.969 +         pand mm1, [colorMask]
  46.970 +
  46.971 +         psrlw mm0, 1
  46.972 +         psrlw mm1, 1
  46.973 +
  46.974 +         pand mm3, [lowPixelMask]
  46.975 +         paddw mm0, mm1
  46.976 +
  46.977 +         pand mm3, mm2
  46.978 +         paddw mm0, mm3
  46.979 +         movq [I23Pixel], mm0
  46.980 +         movq mm7, mm0
  46.981 +
  46.982 +         ;---------------------
  46.983 +         movq mm0, mm7
  46.984 +         movq mm1, mm4  ;2,2,2,3
  46.985 +         movq mm2, mm0
  46.986 +         movq mm3, mm1
  46.987 +
  46.988 +         pand mm0, [colorMask]
  46.989 +         pand mm1, [colorMask]
  46.990 +
  46.991 +         psrlw mm0, 1
  46.992 +         psrlw mm1, 1
  46.993 +
  46.994 +         pand mm3, [lowPixelMask]
  46.995 +         paddw mm0, mm1
  46.996 +
  46.997 +         pand mm3, mm2
  46.998 +         paddw mm0, mm3
  46.999 +         movq [product2a], mm0
 46.1000 +
 46.1001 +         ;----------------------
 46.1002 +         movq mm0, mm7
 46.1003 +         movq mm1, mm5  ;3,3,3,2
 46.1004 +         movq mm2, mm0
 46.1005 +         movq mm3, mm1
 46.1006 +
 46.1007 +         pand mm0, [colorMask]
 46.1008 +         pand mm1, [colorMask]
 46.1009 +
 46.1010 +         psrlw mm0, 1
 46.1011 +         psrlw mm1, 1
 46.1012 +
 46.1013 +         pand mm3, [lowPixelMask]
 46.1014 +         paddw mm0, mm1
 46.1015 +
 46.1016 +         pand mm3, mm2
 46.1017 +         paddw mm0, mm3
 46.1018 +         movq [product2b], mm0
 46.1019 +
 46.1020 +
 46.1021 +         ;////////////////////////////////
 46.1022 +         ; Decide which "branch" to take
 46.1023 +         ;--------------------------------
 46.1024 +         movq mm4, [eax+ebx+color5]
 46.1025 +         movq mm5, [eax+ebx+color6]
 46.1026 +         movq mm6, [eax+ebx+ebx+color3]
 46.1027 +         movq mm7, [eax+ebx+ebx+color2]
 46.1028 +
 46.1029 +         pxor mm3, mm3
 46.1030 +         movq mm0, mm4
 46.1031 +         movq mm1, mm5
 46.1032 +
 46.1033 +         pcmpeqw mm0, mm6
 46.1034 +         pcmpeqw mm1, mm7
 46.1035 +         pcmpeqw mm1, mm3
 46.1036 +         pand mm0, mm1
 46.1037 +         movq [Mask35], mm0
 46.1038 +
 46.1039 +         movq mm0, [eax+ebx+ebx+colorS1]
 46.1040 +         movq mm1, [eax+ebx+color4]
 46.1041 +         push eax
 46.1042 +         add eax, ebx
 46.1043 +         movq mm2, [eax+ebx+ebx+colorA2]
 46.1044 +         pop eax
 46.1045 +         movq mm3, [eax+colorB1]
 46.1046 +         pcmpeqw mm0, mm4
 46.1047 +         pcmpeqw mm1, mm4
 46.1048 +         pcmpeqw mm2, mm4
 46.1049 +         pcmpeqw mm3, mm4
 46.1050 +         pand mm0, mm1
 46.1051 +         pand mm2, mm3
 46.1052 +         por mm0, mm2
 46.1053 +         pand mm0, [Mask35]
 46.1054 +         movq [Mask35b], mm0
 46.1055 +
 46.1056 +         ;-----------
 46.1057 +         pxor mm3, mm3
 46.1058 +         movq mm0, mm4
 46.1059 +         movq mm1, mm5
 46.1060 +
 46.1061 +         pcmpeqw mm0, mm6
 46.1062 +         pcmpeqw mm1, mm7
 46.1063 +         pcmpeqw mm0, mm3
 46.1064 +         pand mm0, mm1
 46.1065 +         movq [Mask26], mm0
 46.1066 +
 46.1067 +         movq mm0, [eax+ebx+ebx+color1]
 46.1068 +         movq mm1, [eax+ebx+colorS2]
 46.1069 +         push eax
 46.1070 +         add eax, ebx
 46.1071 +         movq mm2, [eax+ebx+ebx+colorA1]
 46.1072 +         pop eax
 46.1073 +         movq mm3, [eax+colorB2]
 46.1074 +         pcmpeqw mm0, mm5
 46.1075 +         pcmpeqw mm1, mm5
 46.1076 +         pcmpeqw mm2, mm5
 46.1077 +         pcmpeqw mm3, mm5
 46.1078 +         pand mm0, mm1
 46.1079 +         pand mm2, mm3
 46.1080 +         por mm0, mm2
 46.1081 +         pand mm0, [Mask26]
 46.1082 +         movq [Mask26b], mm0
 46.1083 +
 46.1084 +         ;--------------------
 46.1085 +         movq mm0, mm4
 46.1086 +         movq mm1, mm5
 46.1087 +         movq mm2, mm0
 46.1088 +
 46.1089 +         pcmpeqw mm2, mm1
 46.1090 +         pcmpeqw mm0, mm6
 46.1091 +         pcmpeqw mm1, mm7
 46.1092 +         pand mm0, mm1
 46.1093 +         pand mm2, mm0
 46.1094 +         pxor mm0, mm2
 46.1095 +         movq mm7, mm0
 46.1096 +
 46.1097 +         ;------------------
 46.1098 +         packsswb mm7, mm7
 46.1099 +         movd ecx, mm7
 46.1100 +         test ecx, ecx
 46.1101 +         jz near .SKIP_GUESS
 46.1102 +
 46.1103 +;---------------------------------------------
 46.1104 +; Map of the pixels:                    I|E F|J
 46.1105 +;                                       G|A B|K
 46.1106 +;                                       H|C D|L
 46.1107 +;                                       M|N O|P
 46.1108 +         movq mm6, mm0
 46.1109 +         movq mm4, [eax+ebx+color5]
 46.1110 +         movq mm5, [eax+ebx+color6]
 46.1111 +         pxor mm7, mm7
 46.1112 +         pand mm6, [ONE]
 46.1113 +
 46.1114 +         movq mm0, [eax+colorB1]
 46.1115 +         movq mm1, [eax+ebx+color4]
 46.1116 +         movq mm2, mm0
 46.1117 +         movq mm3, mm1
 46.1118 +         pcmpeqw mm0, mm4
 46.1119 +         pcmpeqw mm1, mm4
 46.1120 +         pcmpeqw mm2, mm5
 46.1121 +         pcmpeqw mm3, mm5
 46.1122 +         pand mm0, mm6
 46.1123 +         pand mm1, mm6
 46.1124 +         pand mm2, mm6
 46.1125 +         pand mm3, mm6
 46.1126 +         paddw mm0, mm1
 46.1127 +         paddw mm2, mm3
 46.1128 +
 46.1129 +         pxor mm3, mm3
 46.1130 +         pcmpgtw mm0, mm6
 46.1131 +         pcmpgtw mm2, mm6
 46.1132 +         pcmpeqw mm0, mm3
 46.1133 +         pcmpeqw mm2, mm3
 46.1134 +         pand mm0, mm6
 46.1135 +         pand mm2, mm6
 46.1136 +         paddw mm7, mm0
 46.1137 +         psubw mm7, mm2
 46.1138 +
 46.1139 +         movq mm0, [eax+colorB2]
 46.1140 +         movq mm1, [eax+ebx+colorS2]
 46.1141 +         movq mm2, mm0
 46.1142 +         movq mm3, mm1
 46.1143 +         pcmpeqw mm0, mm4
 46.1144 +         pcmpeqw mm1, mm4
 46.1145 +         pcmpeqw mm2, mm5
 46.1146 +         pcmpeqw mm3, mm5
 46.1147 +         pand mm0, mm6
 46.1148 +         pand mm1, mm6
 46.1149 +         pand mm2, mm6
 46.1150 +         pand mm3, mm6
 46.1151 +         paddw mm0, mm1
 46.1152 +         paddw mm2, mm3
 46.1153 +
 46.1154 +         pxor mm3, mm3
 46.1155 +         pcmpgtw mm0, mm6
 46.1156 +         pcmpgtw mm2, mm6
 46.1157 +         pcmpeqw mm0, mm3
 46.1158 +         pcmpeqw mm2, mm3
 46.1159 +         pand mm0, mm6
 46.1160 +         pand mm2, mm6
 46.1161 +         paddw mm7, mm0
 46.1162 +         psubw mm7, mm2
 46.1163 +
 46.1164 +         push eax
 46.1165 +         add eax, ebx
 46.1166 +         movq mm0, [eax+ebx+color1]
 46.1167 +         movq mm1, [eax+ebx+ebx+colorA1]
 46.1168 +         movq mm2, mm0
 46.1169 +         movq mm3, mm1
 46.1170 +         pcmpeqw mm0, mm4
 46.1171 +         pcmpeqw mm1, mm4
 46.1172 +         pcmpeqw mm2, mm5
 46.1173 +         pcmpeqw mm3, mm5
 46.1174 +         pand mm0, mm6
 46.1175 +         pand mm1, mm6
 46.1176 +         pand mm2, mm6
 46.1177 +         pand mm3, mm6
 46.1178 +         paddw mm0, mm1
 46.1179 +         paddw mm2, mm3
 46.1180 +
 46.1181 +         pxor mm3, mm3
 46.1182 +         pcmpgtw mm0, mm6
 46.1183 +         pcmpgtw mm2, mm6
 46.1184 +         pcmpeqw mm0, mm3
 46.1185 +         pcmpeqw mm2, mm3
 46.1186 +         pand mm0, mm6
 46.1187 +         pand mm2, mm6
 46.1188 +         paddw mm7, mm0
 46.1189 +         psubw mm7, mm2
 46.1190 +
 46.1191 +         movq mm0, [eax+ebx+colorS1]
 46.1192 +         movq mm1, [eax+ebx+ebx+colorA2]
 46.1193 +         movq mm2, mm0
 46.1194 +         movq mm3, mm1
 46.1195 +         pcmpeqw mm0, mm4
 46.1196 +         pcmpeqw mm1, mm4
 46.1197 +         pcmpeqw mm2, mm5
 46.1198 +         pcmpeqw mm3, mm5
 46.1199 +         pand mm0, mm6
 46.1200 +         pand mm1, mm6
 46.1201 +         pand mm2, mm6
 46.1202 +         pand mm3, mm6
 46.1203 +         paddw mm0, mm1
 46.1204 +         paddw mm2, mm3
 46.1205 +
 46.1206 +         pxor mm3, mm3
 46.1207 +         pcmpgtw mm0, mm6
 46.1208 +         pcmpgtw mm2, mm6
 46.1209 +         pcmpeqw mm0, mm3
 46.1210 +         pcmpeqw mm2, mm3
 46.1211 +         pand mm0, mm6
 46.1212 +         pand mm2, mm6
 46.1213 +         paddw mm7, mm0
 46.1214 +         psubw mm7, mm2
 46.1215 +
 46.1216 +         pop eax
 46.1217 +         movq mm1, mm7
 46.1218 +         pxor mm0, mm0
 46.1219 +         pcmpgtw mm7, mm0
 46.1220 +         pcmpgtw mm0, mm1
 46.1221 +
 46.1222 +         por mm7, [Mask35]
 46.1223 +         por mm0, [Mask26]
 46.1224 +         movq [Mask35], mm7
 46.1225 +         movq [Mask26], mm0
 46.1226 +
 46.1227 +.SKIP_GUESS:
 46.1228 +         ;Start the ASSEMBLY !!!
 46.1229 +
 46.1230 +         movq mm4, [Mask35]
 46.1231 +         movq mm5, [Mask26]
 46.1232 +         movq mm6, [Mask35b]
 46.1233 +         movq mm7, [Mask26b]
 46.1234 +
 46.1235 +         movq mm0, [eax+ebx+color5]
 46.1236 +         movq mm1, [eax+ebx+color6]
 46.1237 +         movq mm2, [eax+ebx+ebx+color2]
 46.1238 +         movq mm3, [eax+ebx+ebx+color3]
 46.1239 +         pcmpeqw mm0, mm2
 46.1240 +         pcmpeqw mm1, mm3
 46.1241 +         movq mm2, mm4
 46.1242 +         movq mm3, mm5
 46.1243 +         por mm0, mm1
 46.1244 +         por mm2, mm3
 46.1245 +         pand mm2, mm0
 46.1246 +         pxor mm0, mm2
 46.1247 +         movq mm3, mm0
 46.1248 +
 46.1249 +         movq mm2, mm0
 46.1250 +         pxor mm0, mm0
 46.1251 +         por mm2, mm4
 46.1252 +         pxor mm4, mm6
 46.1253 +         por mm2, mm5
 46.1254 +         pxor mm5, mm7
 46.1255 +         pcmpeqw mm2, mm0
 46.1256 +         ;----------------
 46.1257 +
 46.1258 +         movq mm0, [eax+ebx+color5]
 46.1259 +         movq mm1, mm3
 46.1260 +         por mm1, mm4
 46.1261 +         por mm1, mm6
 46.1262 +         pand mm0, mm1
 46.1263 +         movq mm1, mm5
 46.1264 +         pand mm1, [I56Pixel]
 46.1265 +         por mm0, mm1
 46.1266 +         movq mm1, mm7
 46.1267 +         pand mm1, [product1b]
 46.1268 +         por mm0, mm1
 46.1269 +         movq mm1, mm2
 46.1270 +         pand mm1, [product1a]
 46.1271 +         por mm0, mm1
 46.1272 +         movq [final1a], mm0
 46.1273 +
 46.1274 +         movq mm0, [eax+ebx+color6]
 46.1275 +         movq mm1, mm3
 46.1276 +         por mm1, mm5
 46.1277 +         por mm1, mm7
 46.1278 +         pand mm0, mm1
 46.1279 +         movq mm1, mm4
 46.1280 +         pand mm1, [I56Pixel]
 46.1281 +         por mm0, mm1
 46.1282 +         movq mm1, mm6
 46.1283 +         pand mm1, [product1a]
 46.1284 +         por mm0, mm1
 46.1285 +         movq mm1, mm2
 46.1286 +         pand mm1, [product1b]
 46.1287 +         por mm0, mm1
 46.1288 +         movq [final1b], mm0
 46.1289 +
 46.1290 +         movq mm0, [eax+ebx+ebx+color2]
 46.1291 +         movq mm1, mm3
 46.1292 +         por mm1, mm5
 46.1293 +         por mm1, mm7
 46.1294 +         pand mm0, mm1
 46.1295 +         movq mm1, mm4
 46.1296 +         pand mm1, [I23Pixel]
 46.1297 +         por mm0, mm1
 46.1298 +         movq mm1, mm6
 46.1299 +         pand mm1, [product2b]
 46.1300 +         por mm0, mm1
 46.1301 +         movq mm1, mm2
 46.1302 +         pand mm1, [product2a]
 46.1303 +         por mm0, mm1
 46.1304 +         movq [final2a], mm0
 46.1305 +
 46.1306 +         movq mm0, [eax+ebx+ebx+color3]
 46.1307 +         movq mm1, mm3
 46.1308 +         por mm1, mm4
 46.1309 +         por mm1, mm6
 46.1310 +         pand mm0, mm1
 46.1311 +         movq mm1, mm5
 46.1312 +         pand mm1, [I23Pixel]
 46.1313 +         por mm0, mm1
 46.1314 +         movq mm1, mm7
 46.1315 +         pand mm1, [product2a]
 46.1316 +         por mm0, mm1
 46.1317 +         movq mm1, mm2
 46.1318 +         pand mm1, [product2b]
 46.1319 +         por mm0, mm1
 46.1320 +         movq [final2b], mm0
 46.1321 +
 46.1322 +
 46.1323 +         movq mm0, [final1a]
 46.1324 +         movq mm2, [final1b]
 46.1325 +         movq mm1, mm0
 46.1326 +         movq mm4, [final2a]
 46.1327 +         movq mm6, [final2b]
 46.1328 +         movq mm5, mm4
 46.1329 +         punpcklwd mm0, mm2
 46.1330 +         punpckhwd mm1, mm2
 46.1331 +         punpcklwd mm4, mm6
 46.1332 +         punpckhwd mm5, mm6
 46.1333 +
 46.1334 +
 46.1335 +
 46.1336 +
 46.1337 +%ifdef FAR_POINTER
 46.1338 +         movq [fs:edx], mm0
 46.1339 +         movq [fs:edx+8], mm1
 46.1340 +         push edx
 46.1341 +         add edx, [ebp+dstPitch]
 46.1342 +         movq [fs:edx], mm4
 46.1343 +         movq [fs:edx+8], mm5
 46.1344 +         pop edx
 46.1345 +%else
 46.1346 +         movq [edx], mm0
 46.1347 +         movq [edx+8], mm1
 46.1348 +         push edx
 46.1349 +         add edx, [ebp+dstPitch]
 46.1350 +         movq [edx], mm4
 46.1351 +         movq [edx+8], mm5
 46.1352 +         pop edx
 46.1353 +%endif
 46.1354 +.SKIP_PROCESS:
 46.1355 +         mov ecx, [ebp+deltaPtr]
 46.1356 +         add ecx, 8
 46.1357 +         mov [ebp+deltaPtr], ecx
 46.1358 +         add edx, 16
 46.1359 +         add eax, 8
 46.1360 +
 46.1361 +         pop ecx
 46.1362 +         sub ecx, 4
 46.1363 +         cmp ecx, 0
 46.1364 +         jg  near .Loop
 46.1365 +
 46.1366 +; Restore some stuff
 46.1367 +         popad
 46.1368 +         mov esp, ebp
 46.1369 +         pop ebp
 46.1370 +         emms
 46.1371 +         ret
 46.1372 +
 46.1373 +
 46.1374 +;-------------------------------------------------------------------------
 46.1375 +;-------------------------------------------------------------------------
 46.1376 +;-------------------------------------------------------------------------
 46.1377 +;-------------------------------------------------------------------------
 46.1378 +;-------------------------------------------------------------------------
 46.1379 +;-------------------------------------------------------------------------
 46.1380 +;-------------------------------------------------------------------------
 46.1381 +
 46.1382 +
 46.1383 +;This is version 0.50
 46.1384 +colorI   equ -2
 46.1385 +colorE   equ 0
 46.1386 +colorF   equ 2
 46.1387 +colorJ   equ 4
 46.1388 +
 46.1389 +colorG   equ -2
 46.1390 +colorA   equ 0
 46.1391 +colorB   equ 2
 46.1392 +colorK   equ 4
 46.1393 +
 46.1394 +colorH   equ -2
 46.1395 +colorC   equ 0
 46.1396 +colorD   equ 2
 46.1397 +colorL   equ 4
 46.1398 +
 46.1399 +colorM   equ -2
 46.1400 +colorN   equ 0
 46.1401 +colorO   equ 2
 46.1402 +colorP   equ 4
 46.1403 +
 46.1404 +%ifdef __DJGPP__
 46.1405 +__2xSaILine:
 46.1406 +%else
 46.1407 +_2xSaILine:
 46.1408 +%endif
 46.1409 +; Store some stuff
 46.1410 +         push ebp
 46.1411 +         mov ebp, esp
 46.1412 +         pushad
 46.1413 +
 46.1414 +; Prepare the destination
 46.1415 +%ifdef FAR_POINTER
 46.1416 +         ; Set the selector
 46.1417 +         mov eax, [ebp+dstSegment]
 46.1418 +         mov fs, ax
 46.1419 +%endif
 46.1420 +         mov edx, [ebp+dstOffset]         ; edx points to the screen
 46.1421 +; Prepare the source
 46.1422 +         ; eax points to colorA
 46.1423 +         mov eax, [ebp+srcPtr]
 46.1424 +         mov ebx, [ebp+srcPitch]
 46.1425 +         mov ecx, [ebp+width]
 46.1426 +         ; eax now points to colorE
 46.1427 +         sub eax, ebx
 46.1428 +
 46.1429 +
 46.1430 +; Main Loop
 46.1431 +.Loop:   push ecx
 46.1432 +
 46.1433 +         ;-----Check Delta------------------
 46.1434 +         mov ecx, [ebp+deltaPtr]
 46.1435 +
 46.1436 +         movq mm0, [eax+colorI]
 46.1437 +         movq mm1, [eax+colorJ]
 46.1438 +         movq mm2, [eax+ebx+colorG]
 46.1439 +         movq mm3, [eax+ebx+colorK]
 46.1440 +         movq mm4, [eax+ebx+ebx+colorH]
 46.1441 +         movq mm5, [eax+ebx+ebx+colorL]
 46.1442 +         push eax
 46.1443 +         add eax, ebx
 46.1444 +         movq mm6, [eax+ebx+ebx+colorM]
 46.1445 +         movq mm7, [eax+ebx+ebx+colorP]
 46.1446 +         pop eax
 46.1447 +
 46.1448 +         pcmpeqw mm0, [ecx+2+colorI]
 46.1449 +         pcmpeqw mm1, [ecx+2+colorK]
 46.1450 +         pcmpeqw mm2, [ecx+ebx+2+colorG]
 46.1451 +         pcmpeqw mm3, [ecx+ebx+2+colorK]
 46.1452 +         pcmpeqw mm4, [ecx+ebx+ebx+2+colorH]
 46.1453 +         pcmpeqw mm5, [ecx+ebx+ebx+2+colorL]
 46.1454 +         add ecx, ebx
 46.1455 +         pcmpeqw mm6, [ecx+ebx+ebx+2+colorM]
 46.1456 +         pcmpeqw mm7, [ecx+ebx+ebx+2+colorP]
 46.1457 +         sub ecx, ebx
 46.1458 +
 46.1459 +
 46.1460 +         pand mm0, mm1
 46.1461 +         pand mm2, mm3
 46.1462 +         pand mm4, mm5
 46.1463 +         pand mm6, mm7
 46.1464 +         pand mm0, mm2
 46.1465 +         pand mm4, mm6
 46.1466 +         pxor mm7, mm7
 46.1467 +         pand mm0, mm4
 46.1468 +         movq mm6, [eax+colorI]
 46.1469 +         pcmpeqw mm7, mm0
 46.1470 +
 46.1471 +         movq [ecx+2+colorI], mm6
 46.1472 +
 46.1473 +         packsswb mm7, mm7
 46.1474 +         movd ecx, mm7
 46.1475 +         test ecx, ecx
 46.1476 +         jz near .SKIP_PROCESS
 46.1477 +
 46.1478 +         ;End Delta
 46.1479 +
 46.1480 +         ;---------------------------------
 46.1481 +
 46.1482 +
 46.1483 +;1
 46.1484 +         ;if ((colorA == colorD) && (colorB != colorC) && (colorA == colorE) && (colorB == colorL)
 46.1485 +         movq mm0, [eax+ebx+colorA]        ;mm0 and mm1 contain colorA
 46.1486 +         movq mm2, [eax+ebx+colorB]        ;mm2 and mm3 contain colorB
 46.1487 +
 46.1488 +         movq mm1, mm0
 46.1489 +         movq mm3, mm2
 46.1490 +
 46.1491 +         pcmpeqw mm0, [eax+ebx+ebx+colorD]
 46.1492 +         pcmpeqw mm1, [eax+colorE]
 46.1493 +         pcmpeqw mm2, [eax+ebx+ebx+colorL]
 46.1494 +         pcmpeqw mm3, [eax+ebx+ebx+colorC]
 46.1495 +
 46.1496 +         pand mm0, mm1
 46.1497 +         pxor mm1, mm1
 46.1498 +         pand mm0, mm2
 46.1499 +         pcmpeqw mm3, mm1
 46.1500 +         pand mm0, mm3                 ;result in mm0
 46.1501 +
 46.1502 +         ;if ((colorA == colorC) && (colorB != colorE) && (colorA == colorF) && (colorB == colorJ)
 46.1503 +         movq mm4, [eax+ebx+colorA]        ;mm4 and mm5 contain colorA
 46.1504 +         movq mm6, [eax+ebx+colorB]        ;mm6 and mm7 contain colorB
 46.1505 +         movq mm5, mm4
 46.1506 +         movq mm7, mm6
 46.1507 +
 46.1508 +         pcmpeqw mm4, [eax+ebx+ebx+colorC]
 46.1509 +         pcmpeqw mm5, [eax+colorF]
 46.1510 +         pcmpeqw mm6, [eax+colorJ]
 46.1511 +         pcmpeqw mm7, [eax+colorE]
 46.1512 +
 46.1513 +         pand mm4, mm5
 46.1514 +         pxor mm5, mm5
 46.1515 +         pand mm4, mm6
 46.1516 +         pcmpeqw mm7, mm5
 46.1517 +         pand mm4, mm7                 ;result in mm4
 46.1518 +
 46.1519 +         por mm0, mm4                  ;combine the masks
 46.1520 +         movq [Mask1], mm0
 46.1521 +
 46.1522 +         ;--------------------------------------------
 46.1523 +
 46.1524 +;2
 46.1525 +         ;if ((colorB == colorC) && (colorA != colorD) && (colorB == colorF) && (colorA == colorH)
 46.1526 +         movq mm0, [eax+ebx+colorB]        ;mm0 and mm1 contain colorB
 46.1527 +         movq mm2, [eax+ebx+colorA]        ;mm2 and mm3 contain colorA
 46.1528 +         movq mm1, mm0
 46.1529 +         movq mm3, mm2
 46.1530 +
 46.1531 +         pcmpeqw mm0, [eax+ebx+ebx+colorC]
 46.1532 +         pcmpeqw mm1, [eax+colorF]
 46.1533 +         pcmpeqw mm2, [eax+ebx+ebx+colorH]
 46.1534 +         pcmpeqw mm3, [eax+ebx+ebx+colorD]
 46.1535 +
 46.1536 +         pand mm0, mm1
 46.1537 +         pxor mm1, mm1
 46.1538 +         pand mm0, mm2
 46.1539 +         pcmpeqw mm3, mm1
 46.1540 +         pand mm0, mm3                 ;result in mm0
 46.1541 +
 46.1542 +         ;if ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI)
 46.1543 +         movq mm4, [eax+ebx+colorB]        ;mm4 and mm5 contain colorB
 46.1544 +         movq mm6, [eax+ebx+colorA]        ;mm6 and mm7 contain colorA
 46.1545 +         movq mm5, mm4
 46.1546 +         movq mm7, mm6
 46.1547 +
 46.1548 +         pcmpeqw mm4, [eax+ebx+ebx+colorD]
 46.1549 +         pcmpeqw mm5, [eax+colorE]
 46.1550 +         pcmpeqw mm6, [eax+colorI]
 46.1551 +         pcmpeqw mm7, [eax+colorF]
 46.1552 +
 46.1553 +         pand mm4, mm5
 46.1554 +         pxor mm5, mm5
 46.1555 +         pand mm4, mm6
 46.1556 +         pcmpeqw mm7, mm5
 46.1557 +         pand mm4, mm7                 ;result in mm4
 46.1558 +
 46.1559 +         por mm0, mm4                  ;combine the masks
 46.1560 +         movq [Mask2], mm0
 46.1561 +
 46.1562 +
 46.1563 +;interpolate colorA and colorB
 46.1564 +         movq mm0, [eax+ebx+colorA]
 46.1565 +         movq mm1, [eax+ebx+colorB]
 46.1566 +
 46.1567 +         movq mm2, mm0
 46.1568 +         movq mm3, mm1
 46.1569 +
 46.1570 +         pand mm0, [colorMask]
 46.1571 +         pand mm1, [colorMask]
 46.1572 +
 46.1573 +         psrlw mm0, 1
 46.1574 +         psrlw mm1, 1
 46.1575 +
 46.1576 +         pand mm3, [lowPixelMask]
 46.1577 +         paddw mm0, mm1
 46.1578 +
 46.1579 +         pand mm3, mm2
 46.1580 +         paddw mm0, mm3                ;mm0 contains the interpolated values
 46.1581 +
 46.1582 +         ;assemble the pixels
 46.1583 +         movq mm1, [eax+ebx+colorA]
 46.1584 +         movq mm2, [eax+ebx+colorB]
 46.1585 +
 46.1586 +         movq mm3, [Mask1]
 46.1587 +         movq mm5, mm1
 46.1588 +         movq mm4, [Mask2]
 46.1589 +         movq mm6, mm1
 46.1590 +
 46.1591 +         pand mm1, mm3
 46.1592 +         por mm3, mm4
 46.1593 +         pxor mm7, mm7
 46.1594 +         pand mm2, mm4
 46.1595 +
 46.1596 +         pcmpeqw mm3, mm7
 46.1597 +         por mm1, mm2
 46.1598 +         pand mm0, mm3
 46.1599 +
 46.1600 +         por mm0, mm1
 46.1601 +
 46.1602 +         punpcklwd mm5, mm0
 46.1603 +         punpckhwd mm6, mm0
 46.1604 +
 46.1605 +%ifdef FAR_POINTER
 46.1606 +         movq [fs:edx], mm5
 46.1607 +         movq [fs:edx+8], mm6
 46.1608 +%else
 46.1609 +         movq [edx], mm5
 46.1610 +         movq [edx+8], mm6
 46.1611 +%endif
 46.1612 +
 46.1613 +;------------------------------------------------
 46.1614 +;        Create the Nextline
 46.1615 +;------------------------------------------------
 46.1616 +;3       ;if ((colorA == colorD) && (colorB != colorC) && (colorA == colorG) && (colorC == colorO)
 46.1617 +         movq mm0, [eax+ebx+colorA]        ;mm0 and mm1 contain colorA
 46.1618 +         movq mm2, [eax+ebx+ebx+colorC]        ;mm2 and mm3 contain colorC
 46.1619 +         movq mm1, mm0
 46.1620 +         movq mm3, mm2
 46.1621 +
 46.1622 +         push eax
 46.1623 +         add eax, ebx
 46.1624 +         pcmpeqw mm0, [eax+ebx+colorD]
 46.1625 +         pcmpeqw mm1, [eax+colorG]
 46.1626 +         pcmpeqw mm2, [eax+ebx+ebx+colorO]
 46.1627 +         pcmpeqw mm3, [eax+colorB]
 46.1628 +         pop eax
 46.1629 +
 46.1630 +         pand mm0, mm1
 46.1631 +         pxor mm1, mm1
 46.1632 +         pand mm0, mm2
 46.1633 +         pcmpeqw mm3, mm1
 46.1634 +         pand mm0, mm3                 ;result in mm0
 46.1635 +
 46.1636 +         ;if ((colorA == colorB) && (colorG != colorC) && (colorA == colorH) && (colorC == colorM)
 46.1637 +         movq mm4, [eax+ebx+colorA]        ;mm4 and mm5 contain colorA
 46.1638 +         movq mm6, [eax+ebx+ebx+colorC]        ;mm6 and mm7 contain colorC
 46.1639 +         movq mm5, mm4
 46.1640 +         movq mm7, mm6
 46.1641 +
 46.1642 +         push eax
 46.1643 +         add eax, ebx
 46.1644 +         pcmpeqw mm4, [eax+ebx+colorH]
 46.1645 +         pcmpeqw mm5, [eax+colorB]
 46.1646 +         pcmpeqw mm6, [eax+ebx+ebx+colorM]
 46.1647 +         pcmpeqw mm7, [eax+colorG]
 46.1648 +         pop eax
 46.1649 +
 46.1650 +         pand mm4, mm5
 46.1651 +         pxor mm5, mm5
 46.1652 +         pand mm4, mm6
 46.1653 +         pcmpeqw mm7, mm5
 46.1654 +         pand mm4, mm7                 ;result in mm4
 46.1655 +
 46.1656 +         por mm0, mm4                  ;combine the masks
 46.1657 +         movq [Mask1], mm0
 46.1658 +         ;--------------------------------------------
 46.1659 +
 46.1660 +;4
 46.1661 +         ;if ((colorB == colorC) && (colorA != colorD) && (colorC == colorH) && (colorA == colorF)
 46.1662 +         movq mm0, [eax+ebx+ebx+colorC]        ;mm0 and mm1 contain colorC
 46.1663 +         movq mm2, [eax+ebx+colorA]        ;mm2 and mm3 contain colorA
 46.1664 +         movq mm1, mm0
 46.1665 +         movq mm3, mm2
 46.1666 +
 46.1667 +         pcmpeqw mm0, [eax+ebx+colorB]
 46.1668 +         pcmpeqw mm1, [eax+ebx+ebx+colorH]
 46.1669 +         pcmpeqw mm2, [eax+colorF]
 46.1670 +         pcmpeqw mm3, [eax+ebx+ebx+colorD]
 46.1671 +
 46.1672 +         pand mm0, mm1
 46.1673 +         pxor mm1, mm1
 46.1674 +         pand mm0, mm2
 46.1675 +         pcmpeqw mm3, mm1
 46.1676 +         pand mm0, mm3                 ;result in mm0
 46.1677 +
 46.1678 +         ;if ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI)
 46.1679 +         movq mm4, [eax+ebx+ebx+colorC]        ;mm4 and mm5 contain colorC
 46.1680 +         movq mm6, [eax+ebx+colorA]        ;mm6 and mm7 contain colorA
 46.1681 +         movq mm5, mm4
 46.1682 +         movq mm7, mm6
 46.1683 +
 46.1684 +         pcmpeqw mm4, [eax+ebx+ebx+colorD]
 46.1685 +         pcmpeqw mm5, [eax+ebx+colorG]
 46.1686 +         pcmpeqw mm6, [eax+colorI]
 46.1687 +         pcmpeqw mm7, [eax+ebx+ebx+colorH]
 46.1688 +
 46.1689 +         pand mm4, mm5
 46.1690 +         pxor mm5, mm5
 46.1691 +         pand mm4, mm6
 46.1692 +         pcmpeqw mm7, mm5
 46.1693 +         pand mm4, mm7                 ;result in mm4
 46.1694 +
 46.1695 +         por mm0, mm4                  ;combine the masks
 46.1696 +         movq [Mask2], mm0
 46.1697 +         ;----------------------------------------------
 46.1698 +
 46.1699 +;interpolate colorA and colorC
 46.1700 +         movq mm0, [eax+ebx+colorA]
 46.1701 +         movq mm1, [eax+ebx+ebx+colorC]
 46.1702 +
 46.1703 +         movq mm2, mm0
 46.1704 +         movq mm3, mm1
 46.1705 +
 46.1706 +         pand mm0, [colorMask]
 46.1707 +         pand mm1, [colorMask]
 46.1708 +
 46.1709 +         psrlw mm0, 1
 46.1710 +         psrlw mm1, 1
 46.1711 +
 46.1712 +         pand mm3, [lowPixelMask]
 46.1713 +         paddw mm0, mm1
 46.1714 +
 46.1715 +         pand mm3, mm2
 46.1716 +         paddw mm0, mm3                ;mm0 contains the interpolated values
 46.1717 +         ;-------------
 46.1718 +
 46.1719 +         ;assemble the pixels
 46.1720 +         movq mm1, [eax+ebx+colorA]
 46.1721 +         movq mm2, [eax+ebx+ebx+colorC]
 46.1722 +
 46.1723 +         movq mm3, [Mask1]
 46.1724 +         movq mm4, [Mask2]
 46.1725 +
 46.1726 +         pand mm1, mm3
 46.1727 +         pand mm2, mm4
 46.1728 +
 46.1729 +         por mm3, mm4
 46.1730 +         pxor mm7, mm7
 46.1731 +         por mm1, mm2
 46.1732 +
 46.1733 +         pcmpeqw mm3, mm7
 46.1734 +         pand mm0, mm3
 46.1735 +         por mm0, mm1
 46.1736 +         movq [ACPixel], mm0
 46.1737 +
 46.1738 +;////////////////////////////////
 46.1739 +; Decide which "branch" to take
 46.1740 +;--------------------------------
 46.1741 +         movq mm0, [eax+ebx+colorA]
 46.1742 +         movq mm1, [eax+ebx+colorB]
 46.1743 +         movq mm6, mm0
 46.1744 +         movq mm7, mm1
 46.1745 +         pcmpeqw mm0, [eax+ebx+ebx+colorD]
 46.1746 +         pcmpeqw mm1, [eax+ebx+ebx+colorC]
 46.1747 +         pcmpeqw mm6, mm7
 46.1748 +
 46.1749 +         movq mm2, mm0
 46.1750 +         movq mm3, mm0
 46.1751 +
 46.1752 +         pand mm0, mm1       ;colorA == colorD && colorB == colorC
 46.1753 +         pxor mm7, mm7
 46.1754 +
 46.1755 +         pcmpeqw mm2, mm7
 46.1756 +         pand mm6, mm0
 46.1757 +         pand mm2, mm1       ;colorA != colorD && colorB == colorC
 46.1758 +
 46.1759 +         pcmpeqw mm1, mm7
 46.1760 +
 46.1761 +         pand mm1, mm3       ;colorA == colorD && colorB != colorC
 46.1762 +         pxor mm0, mm6
 46.1763 +         por mm1, mm6
 46.1764 +         movq mm7, mm0
 46.1765 +         movq [Mask2], mm2
 46.1766 +         packsswb mm7, mm7
 46.1767 +         movq [Mask1], mm1
 46.1768 +
 46.1769 +         movd ecx, mm7
 46.1770 +         test ecx, ecx
 46.1771 +         jz near .SKIP_GUESS
 46.1772 +
 46.1773 +;---------------------------------------------
 46.1774 +; Map of the pixels:                    I|E F|J
 46.1775 +;                                       G|A B|K
 46.1776 +;                                       H|C D|L
 46.1777 +;                                       M|N O|P
 46.1778 +         movq mm6, mm0
 46.1779 +         movq mm4, [eax+ebx+colorA]
 46.1780 +         movq mm5, [eax+ebx+colorB]
 46.1781 +         pxor mm7, mm7
 46.1782 +         pand mm6, [ONE]
 46.1783 +
 46.1784 +         movq mm0, [eax+colorE]
 46.1785 +         movq mm1, [eax+ebx+colorG]
 46.1786 +         movq mm2, mm0
 46.1787 +         movq mm3, mm1
 46.1788 +         pcmpeqw mm0, mm4
 46.1789 +         pcmpeqw mm1, mm4
 46.1790 +         pcmpeqw mm2, mm5
 46.1791 +         pcmpeqw mm3, mm5
 46.1792 +         pand mm0, mm6
 46.1793 +         pand mm1, mm6
 46.1794 +         pand mm2, mm6
 46.1795 +         pand mm3, mm6
 46.1796 +         paddw mm0, mm1
 46.1797 +         paddw mm2, mm3
 46.1798 +
 46.1799 +         pxor mm3, mm3
 46.1800 +         pcmpgtw mm0, mm6
 46.1801 +         pcmpgtw mm2, mm6
 46.1802 +         pcmpeqw mm0, mm3
 46.1803 +         pcmpeqw mm2, mm3
 46.1804 +         pand mm0, mm6
 46.1805 +         pand mm2, mm6
 46.1806 +         paddw mm7, mm0
 46.1807 +         psubw mm7, mm2
 46.1808 +
 46.1809 +         movq mm0, [eax+colorF]
 46.1810 +         movq mm1, [eax+ebx+colorK]
 46.1811 +         movq mm2, mm0
 46.1812 +         movq mm3, mm1
 46.1813 +         pcmpeqw mm0, mm4
 46.1814 +         pcmpeqw mm1, mm4
 46.1815 +         pcmpeqw mm2, mm5
 46.1816 +         pcmpeqw mm3, mm5
 46.1817 +         pand mm0, mm6
 46.1818 +         pand mm1, mm6
 46.1819 +         pand mm2, mm6
 46.1820 +         pand mm3, mm6
 46.1821 +         paddw mm0, mm1
 46.1822 +         paddw mm2, mm3
 46.1823 +
 46.1824 +         pxor mm3, mm3
 46.1825 +         pcmpgtw mm0, mm6
 46.1826 +         pcmpgtw mm2, mm6
 46.1827 +         pcmpeqw mm0, mm3
 46.1828 +         pcmpeqw mm2, mm3
 46.1829 +         pand mm0, mm6
 46.1830 +         pand mm2, mm6
 46.1831 +         paddw mm7, mm0
 46.1832 +         psubw mm7, mm2
 46.1833 +
 46.1834 +         push eax
 46.1835 +         add eax, ebx
 46.1836 +         movq mm0, [eax+ebx+colorH]
 46.1837 +         movq mm1, [eax+ebx+ebx+colorN]
 46.1838 +         movq mm2, mm0
 46.1839 +         movq mm3, mm1
 46.1840 +         pcmpeqw mm0, mm4
 46.1841 +         pcmpeqw mm1, mm4
 46.1842 +         pcmpeqw mm2, mm5
 46.1843 +         pcmpeqw mm3, mm5
 46.1844 +         pand mm0, mm6
 46.1845 +         pand mm1, mm6
 46.1846 +         pand mm2, mm6
 46.1847 +         pand mm3, mm6
 46.1848 +         paddw mm0, mm1
 46.1849 +         paddw mm2, mm3
 46.1850 +
 46.1851 +         pxor mm3, mm3
 46.1852 +         pcmpgtw mm0, mm6
 46.1853 +         pcmpgtw mm2, mm6
 46.1854 +         pcmpeqw mm0, mm3
 46.1855 +         pcmpeqw mm2, mm3
 46.1856 +         pand mm0, mm6
 46.1857 +         pand mm2, mm6
 46.1858 +         paddw mm7, mm0
 46.1859 +         psubw mm7, mm2
 46.1860 +
 46.1861 +         movq mm0, [eax+ebx+colorL]
 46.1862 +         movq mm1, [eax+ebx+ebx+colorO]
 46.1863 +         movq mm2, mm0
 46.1864 +         movq mm3, mm1
 46.1865 +         pcmpeqw mm0, mm4
 46.1866 +         pcmpeqw mm1, mm4
 46.1867 +         pcmpeqw mm2, mm5
 46.1868 +         pcmpeqw mm3, mm5
 46.1869 +         pand mm0, mm6
 46.1870 +         pand mm1, mm6
 46.1871 +         pand mm2, mm6
 46.1872 +         pand mm3, mm6
 46.1873 +         paddw mm0, mm1
 46.1874 +         paddw mm2, mm3
 46.1875 +
 46.1876 +         pxor mm3, mm3
 46.1877 +         pcmpgtw mm0, mm6
 46.1878 +         pcmpgtw mm2, mm6
 46.1879 +         pcmpeqw mm0, mm3
 46.1880 +         pcmpeqw mm2, mm3
 46.1881 +         pand mm0, mm6
 46.1882 +         pand mm2, mm6
 46.1883 +         paddw mm7, mm0
 46.1884 +         psubw mm7, mm2
 46.1885 +
 46.1886 +         pop eax
 46.1887 +         movq mm1, mm7
 46.1888 +         pxor mm0, mm0
 46.1889 +         pcmpgtw mm7, mm0
 46.1890 +         pcmpgtw mm0, mm1
 46.1891 +
 46.1892 +         por mm7, [Mask1]
 46.1893 +         por mm0, [Mask2]
 46.1894 +         movq [Mask1], mm7
 46.1895 +         movq [Mask2], mm0
 46.1896 +
 46.1897 +.SKIP_GUESS:
 46.1898 +         ;----------------------------
 46.1899 +         ;interpolate A, B, C and D
 46.1900 +         movq mm0, [eax+ebx+colorA]
 46.1901 +         movq mm1, [eax+ebx+colorB]
 46.1902 +         movq mm4, mm0
 46.1903 +         movq mm2, [eax+ebx+ebx+colorC]
 46.1904 +         movq mm5, mm1
 46.1905 +         movq mm3, [qcolorMask]
 46.1906 +         movq mm6, mm2
 46.1907 +         movq mm7, [qlowpixelMask]
 46.1908 +
 46.1909 +         pand mm0, mm3
 46.1910 +         pand mm1, mm3
 46.1911 +         pand mm2, mm3
 46.1912 +         pand mm3, [eax+ebx+ebx+colorD]
 46.1913 +
 46.1914 +         psrlw mm0, 2
 46.1915 +         pand mm4, mm7
 46.1916 +         psrlw mm1, 2
 46.1917 +         pand mm5, mm7
 46.1918 +         psrlw mm2, 2
 46.1919 +         pand mm6, mm7
 46.1920 +         psrlw mm3, 2
 46.1921 +         pand mm7, [eax+ebx+ebx+colorD]
 46.1922 +
 46.1923 +         paddw mm0, mm1
 46.1924 +         paddw mm2, mm3
 46.1925 +
 46.1926 +         paddw mm4, mm5
 46.1927 +         paddw mm6, mm7
 46.1928 +
 46.1929 +         paddw mm4, mm6
 46.1930 +         paddw mm0, mm2
 46.1931 +         psrlw mm4, 2
 46.1932 +         pand mm4, [qlowpixelMask]
 46.1933 +         paddw mm0, mm4      ;mm0 contains the interpolated value of A, B, C and D
 46.1934 +
 46.1935 +;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
 46.1936 +         ;assemble the pixels
 46.1937 +         movq mm1, [Mask1]
 46.1938 +         movq mm2, [Mask2]
 46.1939 +         movq mm4, [eax+ebx+colorA]
 46.1940 +         movq mm5, [eax+ebx+colorB]
 46.1941 +         pand mm4, mm1
 46.1942 +         pand mm5, mm2
 46.1943 +
 46.1944 +         pxor mm7, mm7
 46.1945 +         por mm1, mm2
 46.1946 +         por mm4, mm5
 46.1947 +         pcmpeqw mm1, mm7
 46.1948 +         pand mm0, mm1
 46.1949 +         por mm4, mm0        ;mm4 contains the diagonal pixels
 46.1950 +
 46.1951 +         movq mm0, [ACPixel]
 46.1952 +         movq mm1, mm0
 46.1953 +         punpcklwd mm0, mm4
 46.1954 +         punpckhwd mm1, mm4
 46.1955 +
 46.1956 +         push edx
 46.1957 +         add edx, [ebp+dstPitch]
 46.1958 +
 46.1959 +%ifdef FAR_POINTER
 46.1960 +         movq [fs:edx], mm0
 46.1961 +         movq [fs:edx+8], mm1
 46.1962 +%else
 46.1963 +         movq [edx], mm0
 46.1964 +         movq [edx+8], mm1
 46.1965 +%endif
 46.1966 +         pop edx
 46.1967 +
 46.1968 +.SKIP_PROCESS:
 46.1969 +         mov ecx, [ebp+deltaPtr]
 46.1970 +         add ecx, 8
 46.1971 +         mov [ebp+deltaPtr], ecx
 46.1972 +         add edx, 16
 46.1973 +         add eax, 8
 46.1974 +
 46.1975 +         pop ecx
 46.1976 +         sub ecx, 4
 46.1977 +         cmp ecx, 0
 46.1978 +         jg  near .Loop
 46.1979 +
 46.1980 +; Restore some stuff
 46.1981 +         popad
 46.1982 +         mov esp, ebp
 46.1983 +         pop ebp
 46.1984 +         emms
 46.1985 +         ret
 46.1986 +
 46.1987 +;-------------------------------------------------------------------------
 46.1988 +;-------------------------------------------------------------------------
 46.1989 +;-------------------------------------------------------------------------
 46.1990 +;-------------------------------------------------------------------------
 46.1991 +;-------------------------------------------------------------------------
 46.1992 +;-------------------------------------------------------------------------
 46.1993 +;-------------------------------------------------------------------------
 46.1994 +
 46.1995 +%ifdef __DJGPP__
 46.1996 +_Init_2xSaIMMX:
 46.1997 +%else
 46.1998 +Init_2xSaIMMX:
 46.1999 +%endif
 46.2000 +; Store some stuff
 46.2001 +         push ebp
 46.2002 +         mov ebp, esp
 46.2003 +         push edx
 46.2004 +
 46.2005 +
 46.2006 +;Damn thing doesn't work
 46.2007 +;        mov eax,1
 46.2008 +;        cpuid
 46.2009 +;        test edx, 0x00800000     ;test bit 23
 46.2010 +;        jz end2 ;bit not set => no MMX detected
 46.2011 +
 46.2012 +         mov eax, [ebp+8]         ;PixelFormat
 46.2013 +         cmp eax, 555
 46.2014 +         jz Bits555
 46.2015 +         cmp eax, 565
 46.2016 +         jz Bits565
 46.2017 +end2:
 46.2018 +         mov eax, 1
 46.2019 +         jmp end3
 46.2020 +Bits555:
 46.2021 +         mov edx, 0x7BDE7BDE
 46.2022 +         mov eax, colorMask
 46.2023 +         mov [eax], edx
 46.2024 +         mov [eax+4], edx
 46.2025 +         mov edx, 0x04210421
 46.2026 +         mov eax, lowPixelMask
 46.2027 +         mov [eax], edx
 46.2028 +         mov [eax+4], edx
 46.2029 +         mov edx, 0x739C739C
 46.2030 +         mov eax, qcolorMask
 46.2031 +         mov [eax], edx
 46.2032 +         mov [eax+4], edx
 46.2033 +         mov edx, 0x0C630C63
 46.2034 +         mov eax, qlowpixelMask
 46.2035 +         mov [eax], edx
 46.2036 +         mov [eax+4], edx
 46.2037 +         mov eax, 0
 46.2038 +         jmp end3
 46.2039 +Bits565:
 46.2040 +         mov edx, 0xF7DEF7DE
 46.2041 +         mov eax, colorMask
 46.2042 +         mov [eax], edx
 46.2043 +         mov [eax+4], edx
 46.2044 +         mov edx, 0x08210821
 46.2045 +         mov eax, lowPixelMask
 46.2046 +         mov [eax], edx
 46.2047 +         mov [eax+4], edx
 46.2048 +         mov edx, 0xE79CE79C
 46.2049 +         mov eax, qcolorMask
 46.2050 +         mov [eax], edx
 46.2051 +         mov [eax+4], edx
 46.2052 +         mov edx, 0x18631863
 46.2053 +         mov eax, qlowpixelMask
 46.2054 +         mov [eax], edx
 46.2055 +         mov [eax+4], edx
 46.2056 +         mov eax, 0
 46.2057 +         jmp end3
 46.2058 +end3:   
 46.2059 +         pop edx
 46.2060 +         mov esp, ebp
 46.2061 +         pop ebp
 46.2062 +         ret
 46.2063 +
 46.2064 +
 46.2065 +;-------------------------------------------------------------------------
 46.2066 +;-------------------------------------------------------------------------
 46.2067 +;-------------------------------------------------------------------------
 46.2068 +;-------------------------------------------------------------------------
 46.2069 +;-------------------------------------------------------------------------
 46.2070 +;-------------------------------------------------------------------------
 46.2071 +;-------------------------------------------------------------------------
 46.2072 +
 46.2073 +        SECTION .data ALIGN = 32
 46.2074 +;Some constants
 46.2075 +colorMask     dd 0xF7DEF7DE,0xF7DEF7DE
 46.2076 +lowPixelMask  dd 0x08210821,0x08210821
 46.2077 +
 46.2078 +qcolorMask    dd 0xE79CE79C,0xE79CE79C
 46.2079 +qlowpixelMask dd 0x18631863,0x18631863
 46.2080 +
 46.2081 +darkenMask    dd 0xC718C718,0xC718C718
 46.2082 +GreenMask     dd 0x07E007E0,0x07E007E0
 46.2083 +RedBlueMask   dd 0xF81FF81F,0xF81FF81F
 46.2084 +
 46.2085 +FALSE         dd 0x00000000,0x00000000
 46.2086 +TRUE          dd 0xffffffff,0xffffffff
 46.2087 +ONE           dd 0x00010001,0x00010001
 46.2088 +
 46.2089 +
 46.2090 +        SECTION .bss ALIGN = 32
 46.2091 +ACPixel       resb 8
 46.2092 +Mask1         resb 8
 46.2093 +Mask2         resb 8
 46.2094 +
 46.2095 +I56Pixel      resb 8
 46.2096 +I23Pixel      resb 8
 46.2097 +I5556Pixel    resb 8
 46.2098 +I2223Pixel    resb 8
 46.2099 +I5666Pixel    resb 8
 46.2100 +I2333Pixel    resb 8
 46.2101 +Mask26        resb 8
 46.2102 +Mask35        resb 8
 46.2103 +Mask26b       resb 8
 46.2104 +Mask35b       resb 8
 46.2105 +product1a     resb 8
 46.2106 +product1b     resb 8
 46.2107 +product2a     resb 8
 46.2108 +product2b     resb 8
 46.2109 +final1a       resb 8
 46.2110 +final1b       resb 8
 46.2111 +final2a       resb 8
 46.2112 +final2b       resb 8
    47.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.2 +++ b/src/filters/Makefile.am	Sat Mar 03 10:31:27 2012 -0600
    47.3 @@ -0,0 +1,22 @@
    47.4 +SUFFIXES = .asm
    47.5 +
    47.6 +noinst_LIBRARIES = lib386.a libfilter.a
    47.7 +
    47.8 +lib386_a_SOURCES = 2xSaImmx.asm
    47.9 +
   47.10 +.asm.o:
   47.11 +	$(NASM) -f elf -o $@ $<
   47.12 +
   47.13 +libfilter_a_SOURCES = \
   47.14 +	2xSaI.cpp		\
   47.15 +	admame.cpp		\
   47.16 +	bilinear.cpp		\
   47.17 +	hq2x.cpp		\
   47.18 +	hq2x.h			\
   47.19 +	interframe.cpp		\
   47.20 +	interp.h		\
   47.21 +	lq2x.h			\
   47.22 +	motionblur.cpp		\
   47.23 +	pixel.cpp		\
   47.24 +	scanline.cpp		\
   47.25 +	simple2x.cpp
    48.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.2 +++ b/src/filters/admame.cpp	Sat Mar 03 10:31:27 2012 -0600
    48.3 @@ -0,0 +1,1036 @@
    48.4 +/*
    48.5 + * This file is part of the Advance project.
    48.6 + *
    48.7 + * Copyright (C) 1999-2002 Andrea Mazzoleni
    48.8 + *
    48.9 + * This program is free software; you can redistribute it and/or modify
   48.10 + * it under the terms of the GNU General Public License as published by
   48.11 + * the Free Software Foundation; either version 2 of the License, or
   48.12 + * (at your option) any later version.
   48.13 + *
   48.14 + * This program is distributed in the hope that it will be useful,
   48.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   48.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   48.17 + * GNU General Public License for more details.
   48.18 + *
   48.19 + * You should have received a copy of the GNU General Public License
   48.20 + * along with this program; if not, write to the Free Software
   48.21 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   48.22 + *
   48.23 + * In addition, as a special exception, Andrea Mazzoleni
   48.24 + * gives permission to link the code of this program with
   48.25 + * the MAME library (or with modified versions of MAME that use the
   48.26 + * same license as MAME), and distribute linked combinations including
   48.27 + * the two.  You must obey the GNU General Public License in all
   48.28 + * respects for all of the code used other than MAME.  If you modify
   48.29 + * this file, you may extend this exception to your version of the
   48.30 + * file, but you are not obligated to do so.  If you do not wish to
   48.31 + * do so, delete this exception statement from your version.
   48.32 + */
   48.33 +
   48.34 +/*
   48.35 + * Alternatively at the previous license terms, you are allowed to use this
   48.36 + * code in your program with these conditions:
   48.37 + * - the program is not used in commercial activities.
   48.38 + * - the whole source code of the program is released with the binary.
   48.39 + */
   48.40 +
   48.41 +#include "../Port.h"
   48.42 +
   48.43 +#ifdef MMX
   48.44 +extern "C" bool cpu_mmx;
   48.45 +#endif
   48.46 +
   48.47 +static void internal_scale2x_16_def(u16 *dst, const u16 *src0, const u16 *src1, const u16 *src2, unsigned count)
   48.48 +{
   48.49 +	/* first pixel */
   48.50 +	dst[0] = src1[0];
   48.51 +	if (src1[1] == src0[0] && src2[0] != src0[0])
   48.52 +		dst[1] = src0[0];
   48.53 +	else
   48.54 +		dst[1] = src1[0];
   48.55 +	++src0;
   48.56 +	++src1;
   48.57 +	++src2;
   48.58 +	dst += 2;
   48.59 +
   48.60 +	/* central pixels */
   48.61 +	count -= 2;
   48.62 +	while (count)
   48.63 +	{
   48.64 +		if (src0[0] != src2[0] && src1[-1] != src1[1])
   48.65 +		{
   48.66 +			dst[0] = src1[-1] == src0[0] ? src0[0] : src1[0];
   48.67 +			dst[1] = src1[1] == src0[0] ? src0[0] : src1[0];
   48.68 +		}
   48.69 +		else
   48.70 +		{
   48.71 +			dst[0] = src1[0];
   48.72 +			dst[1] = src1[0];
   48.73 +		}
   48.74 +
   48.75 +		++src0;
   48.76 +		++src1;
   48.77 +		++src2;
   48.78 +		dst += 2;
   48.79 +		--count;
   48.80 +	}
   48.81 +
   48.82 +	/* last pixel */
   48.83 +	if (src1[-1] == src0[0] && src2[0] != src0[0])
   48.84 +		dst[0] = src0[0];
   48.85 +	else
   48.86 +		dst[0] = src1[0];
   48.87 +	dst[1] = src1[0];
   48.88 +}
   48.89 +
   48.90 +static void internal_scale2x_32_def(u32 *dst,
   48.91 +                                    const u32 *src0,
   48.92 +                                    const u32 *src1,
   48.93 +                                    const u32 *src2,
   48.94 +                                    unsigned count)
   48.95 +{
   48.96 +	/* first pixel */
   48.97 +	dst[0] = src1[0];
   48.98 +	if (src1[1] == src0[0] && src2[0] != src0[0])
   48.99 +		dst[1] = src0[0];
  48.100 +	else
  48.101 +		dst[1] = src1[0];
  48.102 +	++src0;
  48.103 +	++src1;
  48.104 +	++src2;
  48.105 +	dst += 2;
  48.106 +
  48.107 +	/* central pixels */
  48.108 +	count -= 2;
  48.109 +	while (count)
  48.110 +	{
  48.111 +		if (src0[0] != src2[0] && src1[-1] != src1[1])
  48.112 +		{
  48.113 +			dst[0] = src1[-1] == src0[0] ? src0[0] : src1[0];
  48.114 +			dst[1] = src1[1] == src0[0] ? src0[0] : src1[0];
  48.115 +		}
  48.116 +		else
  48.117 +		{
  48.118 +			dst[0] = src1[0];
  48.119 +			dst[1] = src1[0];
  48.120 +		}
  48.121 +
  48.122 +		++src0;
  48.123 +		++src1;
  48.124 +		++src2;
  48.125 +		dst += 2;
  48.126 +		--count;
  48.127 +	}
  48.128 +
  48.129 +	/* last pixel */
  48.130 +	if (src1[-1] == src0[0] && src2[0] != src0[0])
  48.131 +		dst[0] = src0[0];
  48.132 +	else
  48.133 +		dst[0] = src1[0];
  48.134 +	dst[1] = src1[0];
  48.135 +}
  48.136 +
  48.137 +#ifdef MMX
  48.138 +static void internal_scale2x_16_mmx_single(u16 *dst, const u16 *src0, const u16 *src1, const u16 *src2, unsigned count)
  48.139 +{
  48.140 +	/* always do the first and last run */
  48.141 +	count -= 2 * 4;
  48.142 +
  48.143 +#ifdef __GNUC__
  48.144 +	__asm__ __volatile__ (
  48.145 +	    /* first run */
  48.146 +	    /* set the current, current_pre, current_next registers */
  48.147 +	    "movq 0(%1), %%mm0\n"
  48.148 +	    "movq 0(%1),%%mm7\n"
  48.149 +	    "movq 8(%1),%%mm1\n"
  48.150 +	    "psllq $48,%%mm0\n"
  48.151 +	    "psllq $48,%%mm1\n"
  48.152 +	    "psrlq $48, %%mm0\n"
  48.153 +	    "movq %%mm7,%%mm2\n"
  48.154 +	    "movq %%mm7,%%mm3\n"
  48.155 +	    "psllq $16,%%mm2\n"
  48.156 +	    "psrlq $16,%%mm3\n"
  48.157 +	    "por %%mm2,%%mm0\n"
  48.158 +	    "por %%mm3,%%mm1\n"
  48.159 +
  48.160 +	    /* current_upper */
  48.161 +	    "movq (%0),%%mm6\n"
  48.162 +
  48.163 +	    /* compute the upper-left pixel for dst on %%mm2 */
  48.164 +	    /* compute the upper-right pixel for dst on %%mm4 */
  48.165 +	    "movq %%mm0,%%mm2\n"
  48.166 +	    "movq %%mm1,%%mm4\n"
  48.167 +	    "movq %%mm0,%%mm3\n"
  48.168 +	    "movq %%mm1,%%mm5\n"
  48.169 +	    "pcmpeqw %%mm6,%%mm2\n"
  48.170 +	    "pcmpeqw %%mm6,%%mm4\n"
  48.171 +	    "pcmpeqw (%2),%%mm3\n"
  48.172 +	    "pcmpeqw (%2),%%mm5\n"
  48.173 +	    "pandn %%mm2,%%mm3\n"
  48.174 +	    "pandn %%mm4,%%mm5\n"
  48.175 +	    "movq %%mm0,%%mm2\n"
  48.176 +	    "movq %%mm1,%%mm4\n"
  48.177 +	    "pcmpeqw %%mm1,%%mm2\n"
  48.178 +	    "pcmpeqw %%mm0,%%mm4\n"
  48.179 +	    "pandn %%mm3,%%mm2\n"
  48.180 +	    "pandn %%mm5,%%mm4\n"
  48.181 +	    "movq %%mm2,%%mm3\n"
  48.182 +	    "movq %%mm4,%%mm5\n"
  48.183 +	    "pand %%mm6,%%mm2\n"
  48.184 +	    "pand %%mm6,%%mm4\n"
  48.185 +	    "pandn %%mm7,%%mm3\n"
  48.186 +	    "pandn %%mm7,%%mm5\n"
  48.187 +	    "por %%mm3,%%mm2\n"
  48.188 +	    "por %%mm5,%%mm4\n"
  48.189 +
  48.190 +	    /* set *dst */
  48.191 +	    "movq %%mm2,%%mm3\n"
  48.192 +	    "punpcklwd %%mm4,%%mm2\n"
  48.193 +	    "punpckhwd %%mm4,%%mm3\n"
  48.194 +	    "movq %%mm2,(%3)\n"
  48.195 +	    "movq %%mm3,8(%3)\n"
  48.196 +
  48.197 +	    /* next */
  48.198 +	    "addl $8,%0\n"
  48.199 +	    "addl $8,%1\n"
  48.200 +	    "addl $8,%2\n"
  48.201 +	    "addl $16,%3\n"
  48.202 +
  48.203 +	    /* central runs */
  48.204 +	    "shrl $2,%4\n"
  48.205 +	    "jz 1f\n"
  48.206 +
  48.207 +	    "0:\n"
  48.208 +
  48.209 +	    /* set the current, current_pre, current_next registers */
  48.210 +	    "movq -8(%1),%%mm0\n"
  48.211 +	    "movq (%1),%%mm7\n"
  48.212 +	    "movq 8(%1),%%mm1\n"
  48.213 +	    "psrlq $48,%%mm0\n"
  48.214 +	    "psllq $48,%%mm1\n"
  48.215 +	    "movq %%mm7,%%mm2\n"
  48.216 +	    "movq %%mm7,%%mm3\n"
  48.217 +	    "psllq $16,%%mm2\n"
  48.218 +	    "psrlq $16,%%mm3\n"
  48.219 +	    "por %%mm2,%%mm0\n"
  48.220 +	    "por %%mm3,%%mm1\n"
  48.221 +
  48.222 +	    /* current_upper */
  48.223 +	    "movq (%0),%%mm6\n"
  48.224 +
  48.225 +	    /* compute the upper-left pixel for dst on %%mm2 */
  48.226 +	    /* compute the upper-right pixel for dst on %%mm4 */
  48.227 +	    "movq %%mm0,%%mm2\n"
  48.228 +	    "movq %%mm1,%%mm4\n"
  48.229 +	    "movq %%mm0,%%mm3\n"
  48.230 +	    "movq %%mm1,%%mm5\n"
  48.231 +	    "pcmpeqw %%mm6,%%mm2\n"
  48.232 +	    "pcmpeqw %%mm6,%%mm4\n"
  48.233 +	    "pcmpeqw (%2),%%mm3\n"
  48.234 +	    "pcmpeqw (%2),%%mm5\n"
  48.235 +	    "pandn %%mm2,%%mm3\n"
  48.236 +	    "pandn %%mm4,%%mm5\n"
  48.237 +	    "movq %%mm0,%%mm2\n"
  48.238 +	    "movq %%mm1,%%mm4\n"
  48.239 +	    "pcmpeqw %%mm1,%%mm2\n"
  48.240 +	    "pcmpeqw %%mm0,%%mm4\n"
  48.241 +	    "pandn %%mm3,%%mm2\n"
  48.242 +	    "pandn %%mm5,%%mm4\n"
  48.243 +	    "movq %%mm2,%%mm3\n"
  48.244 +	    "movq %%mm4,%%mm5\n"
  48.245 +	    "pand %%mm6,%%mm2\n"
  48.246 +	    "pand %%mm6,%%mm4\n"
  48.247 +	    "pandn %%mm7,%%mm3\n"
  48.248 +	    "pandn %%mm7,%%mm5\n"
  48.249 +	    "por %%mm3,%%mm2\n"
  48.250 +	    "por %%mm5,%%mm4\n"
  48.251 +
  48.252 +	    /* set *dst */
  48.253 +	    "movq %%mm2,%%mm3\n"
  48.254 +	    "punpcklwd %%mm4,%%mm2\n"
  48.255 +	    "punpckhwd %%mm4,%%mm3\n"
  48.256 +	    "movq %%mm2,(%3)\n"
  48.257 +	    "movq %%mm3,8(%3)\n"
  48.258 +
  48.259 +	    /* next */
  48.260 +	    "addl $8,%0\n"
  48.261 +	    "addl $8,%1\n"
  48.262 +	    "addl $8,%2\n"
  48.263 +	    "addl $16,%3\n"
  48.264 +
  48.265 +	    "decl %4\n"
  48.266 +	    "jnz 0b\n"
  48.267 +	    "1:\n"
  48.268 +
  48.269 +	    /* final run */
  48.270 +	    /* set the current, current_pre, current_next registers */
  48.271 +	    "movq (%1),%%mm1\n"
  48.272 +	    "movq (%1),%%mm7\n"
  48.273 +	    "movq -8(%1),%%mm0\n"
  48.274 +	    "psrlq $48,%%mm1\n"
  48.275 +	    "psrlq $48,%%mm0\n"
  48.276 +	    "psllq $48,%%mm1\n"
  48.277 +	    "movq %%mm7,%%mm2\n"
  48.278 +	    "movq %%mm7,%%mm3\n"
  48.279 +	    "psllq $16,%%mm2\n"
  48.280 +	    "psrlq $16,%%mm3\n"
  48.281 +	    "por %%mm2,%%mm0\n"
  48.282 +	    "por %%mm3,%%mm1\n"
  48.283 +
  48.284 +	    /* current_upper */
  48.285 +	    "movq (%0),%%mm6\n"
  48.286 +
  48.287 +	    /* compute the upper-left pixel for dst on %%mm2 */
  48.288 +	    /* compute the upper-right pixel for dst on %%mm4 */
  48.289 +	    "movq %%mm0,%%mm2\n"
  48.290 +	    "movq %%mm1,%%mm4\n"
  48.291 +	    "movq %%mm0,%%mm3\n"
  48.292 +	    "movq %%mm1,%%mm5\n"
  48.293 +	    "pcmpeqw %%mm6,%%mm2\n"
  48.294 +	    "pcmpeqw %%mm6,%%mm4\n"
  48.295 +	    "pcmpeqw (%2),%%mm3\n"
  48.296 +	    "pcmpeqw (%2),%%mm5\n"
  48.297 +	    "pandn %%mm2,%%mm3\n"
  48.298 +	    "pandn %%mm4,%%mm5\n"
  48.299 +	    "movq %%mm0,%%mm2\n"
  48.300 +	    "movq %%mm1,%%mm4\n"
  48.301 +	    "pcmpeqw %%mm1,%%mm2\n"
  48.302 +	    "pcmpeqw %%mm0,%%mm4\n"
  48.303 +	    "pandn %%mm3,%%mm2\n"
  48.304 +	    "pandn %%mm5,%%mm4\n"
  48.305 +	    "movq %%mm2,%%mm3\n"
  48.306 +	    "movq %%mm4,%%mm5\n"
  48.307 +	    "pand %%mm6,%%mm2\n"
  48.308 +	    "pand %%mm6,%%mm4\n"
  48.309 +	    "pandn %%mm7,%%mm3\n"
  48.310 +	    "pandn %%mm7,%%mm5\n"
  48.311 +	    "por %%mm3,%%mm2\n"
  48.312 +	    "por %%mm5,%%mm4\n"
  48.313 +
  48.314 +	    /* set *dst */
  48.315 +	    "movq %%mm2,%%mm3\n"
  48.316 +	    "punpcklwd %%mm4,%%mm2\n"
  48.317 +	    "punpckhwd %%mm4,%%mm3\n"
  48.318 +	    "movq %%mm2,(%3)\n"
  48.319 +	    "movq %%mm3,8(%3)\n"
  48.320 +	    "emms\n"
  48.321 +
  48.322 +		: "+r" (src0), "+r" (src1), "+r" (src2), "+r" (dst), "+r" (count)
  48.323 +		:
  48.324 +		: "cc"
  48.325 +	    );
  48.326 +#else
  48.327 +	__asm {
  48.328 +		mov eax, src0;
  48.329 +		mov ebx, src1;
  48.330 +		mov ecx, src2;
  48.331 +		mov edx, dst;
  48.332 +		mov esi, count;
  48.333 +
  48.334 +		/* first run */
  48.335 +		/* set the current, current_pre, current_next registers */
  48.336 +		movq  mm0, qword ptr [ebx];
  48.337 +		movq  mm7, qword ptr [ebx];
  48.338 +		movq  mm1, qword ptr [ebx + 8];
  48.339 +		psllq mm0, 48;
  48.340 +		psllq mm1, 48;
  48.341 +		psrlq mm0, 48;
  48.342 +		movq  mm2, mm7;
  48.343 +		movq  mm3, mm7;
  48.344 +		psllq mm2, 16;
  48.345 +		psrlq mm3, 16;
  48.346 +		por	  mm0, mm2;
  48.347 +		por	  mm1, mm3;
  48.348 +
  48.349 +		/* current_upper */
  48.350 +		movq mm6, qword ptr [eax];
  48.351 +
  48.352 +		/* compute the upper-left pixel for dst on %%mm2 */
  48.353 +		/* compute the upper-right pixel for dst on %%mm4 */
  48.354 +		movq	mm2, mm0;
  48.355 +		movq	mm4, mm1;
  48.356 +		movq	mm3, mm0;
  48.357 +		movq	mm5, mm1;
  48.358 +		pcmpeqw mm2, mm6;
  48.359 +		pcmpeqw mm4, mm6;
  48.360 +		pcmpeqw mm3, qword ptr [ecx];
  48.361 +		pcmpeqw mm5, qword ptr [ecx];
  48.362 +		pandn	mm3, mm2;
  48.363 +		pandn	mm5, mm4;
  48.364 +		movq	mm2, mm0;
  48.365 +		movq	mm4, mm1;
  48.366 +		pcmpeqw mm2, mm1;
  48.367 +		pcmpeqw mm4, mm0;
  48.368 +		pandn	mm2, mm3;
  48.369 +		pandn	mm4, mm5;
  48.370 +		movq	mm3, mm2;
  48.371 +		movq	mm5, mm4;
  48.372 +		pand	mm2, mm6;
  48.373 +		pand	mm4, mm6;
  48.374 +		pandn	mm3, mm7;
  48.375 +		pandn	mm5, mm7;
  48.376 +		por		mm2, mm3;
  48.377 +		por		mm4, mm5;
  48.378 +
  48.379 +		/* set *dst0 */
  48.380 +		movq	   mm3, mm2;
  48.381 +		punpcklwd  mm2, mm4;
  48.382 +		punpckhwd  mm3, mm4;
  48.383 +		movq qword ptr [edx], mm2;
  48.384 +		movq qword ptr [edx + 8], mm3;
  48.385 +
  48.386 +		/* next */
  48.387 +		add eax, 8;
  48.388 +		add ebx, 8;
  48.389 +		add ecx, 8;
  48.390 +		add edx, 16;
  48.391 +
  48.392 +		/* central runs */
  48.393 +		shr esi, 2;
  48.394 +		jz	label1;
  48.395 +		align 4;
  48.396 +label0:
  48.397 +
  48.398 +		/* set the current, current_pre, current_next registers */
  48.399 +		movq mm0, qword ptr [ebx - 8];
  48.400 +		movq  mm7, qword ptr [ebx];
  48.401 +		movq  mm1, qword ptr [ebx + 8];
  48.402 +		psrlq mm0, 48;
  48.403 +		psllq mm1, 48;
  48.404 +		movq  mm2, mm7;
  48.405 +		movq  mm3, mm7;
  48.406 +		psllq mm2, 16;
  48.407 +		psrlq mm3, 16;
  48.408 +		por	  mm0, mm2;
  48.409 +		por	  mm1, mm3;
  48.410 +
  48.411 +		/* current_upper */
  48.412 +		movq mm6, qword ptr [eax];
  48.413 +
  48.414 +		/* compute the upper-left pixel for dst on %%mm2 */
  48.415 +		/* compute the upper-right pixel for dst on %%mm4 */
  48.416 +		movq	mm2, mm0;
  48.417 +		movq	mm4, mm1;
  48.418 +		movq	mm3, mm0;
  48.419 +		movq	mm5, mm1;
  48.420 +		pcmpeqw mm2, mm6;
  48.421 +		pcmpeqw mm4, mm6;
  48.422 +		pcmpeqw mm3, qword ptr [ecx];
  48.423 +		pcmpeqw mm5, qword ptr [ecx];
  48.424 +		pandn	mm3, mm2;
  48.425 +		pandn	mm5, mm4;
  48.426 +		movq	mm2, mm0;
  48.427 +		movq	mm4, mm1;
  48.428 +		pcmpeqw mm2, mm1;
  48.429 +		pcmpeqw mm4, mm0;
  48.430 +		pandn	mm2, mm3;
  48.431 +		pandn	mm4, mm5;
  48.432 +		movq	mm3, mm2;
  48.433 +		movq	mm5, mm4;
  48.434 +		pand	mm2, mm6;
  48.435 +		pand	mm4, mm6;
  48.436 +		pandn	mm3, mm7;
  48.437 +		pandn	mm5, mm7;
  48.438 +		por		mm2, mm3;
  48.439 +		por		mm4, mm5;
  48.440 +
  48.441 +		/* set *dst */
  48.442 +		movq	   mm3, mm2;
  48.443 +		punpcklwd  mm2, mm4;
  48.444 +		punpckhwd  mm3, mm4;
  48.445 +		movq qword ptr [edx], mm2;
  48.446 +		movq qword ptr [edx + 8], mm3;
  48.447 +
  48.448 +		/* next */
  48.449 +		add eax, 8;
  48.450 +		add ebx, 8;
  48.451 +		add ecx, 8;
  48.452 +		add edx, 16;
  48.453 +
  48.454 +		dec esi;
  48.455 +		jnz label0;
  48.456 +label1:
  48.457 +
  48.458 +		/* final run */
  48.459 +		/* set the current, current_pre, current_next registers */
  48.460 +		movq mm1, qword ptr [ebx];
  48.461 +		movq  mm7, qword ptr [ebx];
  48.462 +		movq  mm0, qword ptr [ebx - 8];
  48.463 +		psrlq mm1, 48;
  48.464 +		psrlq mm0, 48;
  48.465 +		psllq mm1, 48;
  48.466 +		movq  mm2, mm7;
  48.467 +		movq  mm3, mm7;
  48.468 +		psllq mm2, 16;
  48.469 +		psrlq mm3, 16;
  48.470 +		por	  mm0, mm2;
  48.471 +		por	  mm1, mm3;
  48.472 +
  48.473 +		/* current_upper */
  48.474 +		movq mm6, qword ptr [eax];
  48.475 +
  48.476 +		/* compute the upper-left pixel for dst on %%mm2 */
  48.477 +		/* compute the upper-right pixel for dst on %%mm4 */
  48.478 +		movq	mm2, mm0;
  48.479 +		movq	mm4, mm1;
  48.480 +		movq	mm3, mm0;
  48.481 +		movq	mm5, mm1;
  48.482 +		pcmpeqw mm2, mm6;
  48.483 +		pcmpeqw mm4, mm6;
  48.484 +		pcmpeqw mm3, qword ptr [ecx];
  48.485 +		pcmpeqw mm5, qword ptr [ecx];
  48.486 +		pandn	mm3, mm2;
  48.487 +		pandn	mm5, mm4;
  48.488 +		movq	mm2, mm0;
  48.489 +		movq	mm4, mm1;
  48.490 +		pcmpeqw mm2, mm1;
  48.491 +		pcmpeqw mm4, mm0;
  48.492 +		pandn	mm2, mm3;
  48.493 +		pandn	mm4, mm5;
  48.494 +		movq	mm3, mm2;
  48.495 +		movq	mm5, mm4;
  48.496 +		pand	mm2, mm6;
  48.497 +		pand	mm4, mm6;
  48.498 +		pandn	mm3, mm7;
  48.499 +		pandn	mm5, mm7;
  48.500 +		por		mm2, mm3;
  48.501 +		por		mm4, mm5;
  48.502 +
  48.503 +		/* set *dst */
  48.504 +		movq	   mm3, mm2;
  48.505 +		punpcklwd  mm2, mm4;
  48.506 +		punpckhwd  mm3, mm4;
  48.507 +		movq qword ptr [edx], mm2;
  48.508 +		movq qword ptr [edx + 8], mm3;
  48.509 +
  48.510 +		mov src0, eax;
  48.511 +		mov src1, ebx;
  48.512 +		mov src2, ecx;
  48.513 +		mov dst, edx;
  48.514 +		mov count, esi;
  48.515 +
  48.516 +		emms;
  48.517 +	}
  48.518 +#endif
  48.519 +}
  48.520 +
  48.521 +static void internal_scale2x_32_mmx_single(u32 *dst, const u32 *src0, const u32 *src1, const u32 *src2, unsigned count)
  48.522 +{
  48.523 +	/* always do the first and last run */
  48.524 +	count -= 2 * 2;
  48.525 +
  48.526 +#ifdef __GNUC__
  48.527 +	__asm__ __volatile__ (
  48.528 +	    /* first run */
  48.529 +	    /* set the current, current_pre, current_next registers */
  48.530 +	    "movq 0(%1),%%mm0\n"
  48.531 +	    "movq 0(%1),%%mm7\n"
  48.532 +	    "movq 8(%1),%%mm1\n"
  48.533 +	    "psllq $32,%%mm0\n"
  48.534 +	    "psllq $32,%%mm1\n"
  48.535 +	    "psrlq $32,%%mm0\n"
  48.536 +	    "movq %%mm7,%%mm2\n"
  48.537 +	    "movq %%mm7,%%mm3\n"
  48.538 +	    "psllq $32,%%mm2\n"
  48.539 +	    "psrlq $32,%%mm3\n"
  48.540 +	    "por %%mm2,%%mm0\n"
  48.541 +	    "por %%mm3,%%mm1\n"
  48.542 +
  48.543 +	    /* current_upper */
  48.544 +	    "movq (%0),%%mm6\n"
  48.545 +
  48.546 +	    /* compute the upper-left pixel for dst on %%mm2 */
  48.547 +	    /* compute the upper-right pixel for dst on %%mm4 */
  48.548 +	    "movq %%mm0,%%mm2\n"
  48.549 +	    "movq %%mm1,%%mm4\n"
  48.550 +	    "movq %%mm0,%%mm3\n"
  48.551 +	    "movq %%mm1,%%mm5\n"
  48.552 +	    "pcmpeqd %%mm6,%%mm2\n"
  48.553 +	    "pcmpeqd %%mm6,%%mm4\n"
  48.554 +	    "pcmpeqd (%2),%%mm3\n"
  48.555 +	    "pcmpeqd (%2),%%mm5\n"
  48.556 +	    "pandn %%mm2,%%mm3\n"
  48.557 +	    "pandn %%mm4,%%mm5\n"
  48.558 +	    "movq %%mm0,%%mm2\n"
  48.559 +	    "movq %%mm1,%%mm4\n"
  48.560 +	    "pcmpeqd %%mm1,%%mm2\n"
  48.561 +	    "pcmpeqd %%mm0,%%mm4\n"
  48.562 +	    "pandn %%mm3,%%mm2\n"
  48.563 +	    "pandn %%mm5,%%mm4\n"
  48.564 +	    "movq %%mm2,%%mm3\n"
  48.565 +	    "movq %%mm4,%%mm5\n"
  48.566 +	    "pand %%mm6,%%mm2\n"
  48.567 +	    "pand %%mm6,%%mm4\n"
  48.568 +	    "pandn %%mm7,%%mm3\n"
  48.569 +	    "pandn %%mm7,%%mm5\n"
  48.570 +	    "por %%mm3,%%mm2\n"
  48.571 +	    "por %%mm5,%%mm4\n"
  48.572 +
  48.573 +	    /* set *dst */
  48.574 +	    "movq %%mm2,%%mm3\n"
  48.575 +	    "punpckldq %%mm4,%%mm2\n"
  48.576 +	    "punpckhdq %%mm4,%%mm3\n"
  48.577 +	    "movq %%mm2,(%3)\n"
  48.578 +	    "movq %%mm3, 8(%3)\n"
  48.579 +
  48.580 +	    /* next */
  48.581 +	    "addl $8,%0\n"
  48.582 +	    "addl $8,%1\n"
  48.583 +	    "addl $8,%2\n"
  48.584 +	    "addl $16,%3\n"
  48.585 +
  48.586 +	    /* central runs */
  48.587 +	    "shrl $1,%4\n"
  48.588 +	    "jz 1f\n"
  48.589 +
  48.590 +	    "0:\n"
  48.591 +
  48.592 +	    /* set the current, current_pre, current_next registers */
  48.593 +	    "movq -8(%1),%%mm0\n"
  48.594 +	    "movq (%1),%%mm7\n"
  48.595 +	    "movq 8(%1),%%mm1\n"
  48.596 +	    "psrlq $32,%%mm0\n"
  48.597 +	    "psllq $32,%%mm1\n"
  48.598 +	    "movq %%mm7,%%mm2\n"
  48.599 +	    "movq %%mm7,%%mm3\n"
  48.600 +	    "psllq $32,%%mm2\n"
  48.601 +	    "psrlq $32,%%mm3\n"
  48.602 +	    "por %%mm2,%%mm0\n"
  48.603 +	    "por %%mm3,%%mm1\n"
  48.604 +
  48.605 +	    /* current_upper */
  48.606 +	    "movq (%0),%%mm6\n"
  48.607 +
  48.608 +	    /* compute the upper-left pixel for dst on %%mm2 */
  48.609 +	    /* compute the upper-right pixel for dst on %%mm4 */
  48.610 +	    "movq %%mm0,%%mm2\n"
  48.611 +	    "movq %%mm1,%%mm4\n"
  48.612 +	    "movq %%mm0,%%mm3\n"
  48.613 +	    "movq %%mm1,%%mm5\n"
  48.614 +	    "pcmpeqd %%mm6,%%mm2\n"
  48.615 +	    "pcmpeqd %%mm6,%%mm4\n"
  48.616 +	    "pcmpeqd (%2),%%mm3\n"
  48.617 +	    "pcmpeqd (%2),%%mm5\n"
  48.618 +	    "pandn %%mm2,%%mm3\n"
  48.619 +	    "pandn %%mm4,%%mm5\n"
  48.620 +	    "movq %%mm0,%%mm2\n"
  48.621 +	    "movq %%mm1,%%mm4\n"
  48.622 +	    "pcmpeqd %%mm1,%%mm2\n"
  48.623 +	    "pcmpeqd %%mm0,%%mm4\n"
  48.624 +	    "pandn %%mm3,%%mm2\n"
  48.625 +	    "pandn %%mm5,%%mm4\n"
  48.626 +	    "movq %%mm2,%%mm3\n"
  48.627 +	    "movq %%mm4,%%mm5\n"
  48.628 +	    "pand %%mm6,%%mm2\n"
  48.629 +	    "pand %%mm6,%%mm4\n"
  48.630 +	    "pandn %%mm7,%%mm3\n"
  48.631 +	    "pandn %%mm7,%%mm5\n"
  48.632 +	    "por %%mm3,%%mm2\n"
  48.633 +	    "por %%mm5,%%mm4\n"
  48.634 +
  48.635 +	    /* set *dst */
  48.636 +	    "movq %%mm2,%%mm3\n"
  48.637 +	    "punpckldq %%mm4,%%mm2\n"
  48.638 +	    "punpckhdq %%mm4,%%mm3\n"
  48.639 +	    "movq %%mm2,(%3)\n"
  48.640 +	    "movq %%mm3,8(%3)\n"
  48.641 +
  48.642 +	    /* next */
  48.643 +	    "addl $8,%0\n"
  48.644 +	    "addl $8,%1\n"
  48.645 +	    "addl $8,%2\n"
  48.646 +	    "addl $16,%3\n"
  48.647 +
  48.648 +	    "decl %4\n"
  48.649 +	    "jnz 0b\n"
  48.650 +	    "1:\n"
  48.651 +
  48.652 +	    /* final run */
  48.653 +	    /* set the current, current_pre, current_next registers */
  48.654 +	    "movq (%1),%%mm1\n"
  48.655 +	    "movq (%1),%%mm7\n"
  48.656 +	    "movq -8(%1), %%mm0\n"
  48.657 +	    "psrlq $32,%%mm1\n"
  48.658 +	    "psrlq $32,%%mm0\n"
  48.659 +	    "psllq $32,%%mm1\n"
  48.660 +	    "movq %%mm7,%%mm2\n"
  48.661 +	    "movq %%mm7,%%mm3\n"
  48.662 +	    "psllq $32,%%mm2\n"
  48.663 +	    "psrlq $32,%%mm3\n"
  48.664 +	    "por %%mm2,%%mm0\n"
  48.665 +	    "por %%mm3,%%mm1\n"
  48.666 +
  48.667 +	    /* current_upper */
  48.668 +	    "movq (%0),%%mm6\n"
  48.669 +
  48.670 +	    /* compute the upper-left pixel for dst on %%mm2 */
  48.671 +	    /* compute the upper-right pixel for dst on %%mm4 */
  48.672 +	    "movq %%mm0,%%mm2\n"
  48.673 +	    "movq %%mm1,%%mm4\n"
  48.674 +	    "movq %%mm0,%%mm3\n"
  48.675 +	    "movq %%mm1,%%mm5\n"
  48.676 +	    "pcmpeqd %%mm6,%%mm2\n"
  48.677 +	    "pcmpeqd %%mm6,%%mm4\n"
  48.678 +	    "pcmpeqd (%2),%%mm3\n"
  48.679 +	    "pcmpeqd (%2),%%mm5\n"
  48.680 +	    "pandn %%mm2,%%mm3\n"
  48.681 +	    "pandn %%mm4,%%mm5\n"
  48.682 +	    "movq %%mm0,%%mm2\n"
  48.683 +	    "movq %%mm1,%%mm4\n"
  48.684 +	    "pcmpeqd %%mm1,%%mm2\n"
  48.685 +	    "pcmpeqd %%mm0,%%mm4\n"
  48.686 +	    "pandn %%mm3,%%mm2\n"
  48.687 +	    "pandn %%mm5,%%mm4\n"
  48.688 +	    "movq %%mm2,%%mm3\n"
  48.689 +	    "movq %%mm4,%%mm5\n"
  48.690 +	    "pand %%mm6,%%mm2\n"
  48.691 +	    "pand %%mm6,%%mm4\n"
  48.692 +	    "pandn %%mm7,%%mm3\n"
  48.693 +	    "pandn %%mm7,%%mm5\n"
  48.694 +	    "por %%mm3,%%mm2\n"
  48.695 +	    "por %%mm5,%%mm4\n"
  48.696 +
  48.697 +	    /* set *dst */
  48.698 +	    "movq %%mm2,%%mm3\n"
  48.699 +	    "punpckldq %%mm4,%%mm2\n"
  48.700 +	    "punpckhdq %%mm4,%%mm3\n"
  48.701 +	    "movq %%mm2,(%3)\n"
  48.702 +	    "movq %%mm3,8(%3)\n"
  48.703 +	    "emms\n"
  48.704 +
  48.705 +		: "+r" (src0), "+r" (src1), "+r" (src2), "+r" (dst), "+r" (count)
  48.706 +		:
  48.707 +		: "cc"
  48.708 +	    );
  48.709 +#else
  48.710 +	__asm {
  48.711 +		mov eax, src0;
  48.712 +		mov ebx, src1;
  48.713 +		mov ecx, src2;
  48.714 +		mov edx, dst;
  48.715 +		mov esi, count;
  48.716 +
  48.717 +		/* first run */
  48.718 +		/* set the current, current_pre, current_next registers */
  48.719 +		movq  mm0, qword ptr [ebx];
  48.720 +		movq  mm7, qword ptr [ebx];
  48.721 +		movq  mm1, qword ptr [ebx + 8];
  48.722 +		psllq mm0, 32;
  48.723 +		psllq mm1, 32;
  48.724 +		psrlq mm0, 32;
  48.725 +		movq  mm2, mm7;
  48.726 +		movq  mm3, mm7;
  48.727 +		psllq mm2, 32;
  48.728 +		psrlq mm3, 32;
  48.729 +		por	  mm0, mm2;
  48.730 +		por	  mm1, mm3;
  48.731 +
  48.732 +		/* current_upper */
  48.733 +		movq mm6, qword ptr [eax];
  48.734 +
  48.735 +		/* compute the upper-left pixel for dst on %%mm2 */
  48.736 +		/* compute the upper-right pixel for dst on %%mm4 */
  48.737 +		movq	mm2, mm0;
  48.738 +		movq	mm4, mm1;
  48.739 +		movq	mm3, mm0;
  48.740 +		movq	mm5, mm1;
  48.741 +		pcmpeqd mm2, mm6;
  48.742 +		pcmpeqd mm4, mm6;
  48.743 +		pcmpeqd mm3, qword ptr [ecx];
  48.744 +		pcmpeqd mm5, qword ptr [ecx];
  48.745 +		pandn	mm3, mm2;
  48.746 +		pandn	mm5, mm4;
  48.747 +		movq	mm2, mm0;
  48.748 +		movq	mm4, mm1;
  48.749 +		pcmpeqd mm2, mm1;
  48.750 +		pcmpeqd mm4, mm0;
  48.751 +		pandn	mm2, mm3;
  48.752 +		pandn	mm4, mm5;
  48.753 +		movq	mm3, mm2;
  48.754 +		movq	mm5, mm4;
  48.755 +		pand	mm2, mm6;
  48.756 +		pand	mm4, mm6;
  48.757 +		pandn	mm3, mm7;
  48.758 +		pandn	mm5, mm7;
  48.759 +		por		mm2, mm3;
  48.760 +		por		mm4, mm5;
  48.761 +
  48.762 +		/* set *dst */
  48.763 +		movq	   mm3, mm2;
  48.764 +		punpckldq  mm2, mm4;
  48.765 +		punpckhdq  mm3, mm4;
  48.766 +		movq qword ptr [edx], mm2;
  48.767 +		movq qword ptr [edx + 8], mm3;
  48.768 +
  48.769 +		/* next */
  48.770 +		add eax, 8;
  48.771 +		add ebx, 8;
  48.772 +		add ecx, 8;
  48.773 +		add edx, 16;
  48.774 +
  48.775 +		/* central runs */
  48.776 +		shr esi, 1;
  48.777 +		jz	label1;
  48.778 +label0:
  48.779 +
  48.780 +		/* set the current, current_pre, current_next registers */
  48.781 +		movq mm0, qword ptr [ebx - 8];
  48.782 +		movq  mm7, qword ptr [ebx];
  48.783 +		movq  mm1, qword ptr [ebx + 8];
  48.784 +		psrlq mm0, 32;
  48.785 +		psllq mm1, 32;
  48.786 +		movq  mm2, mm7;
  48.787 +		movq  mm3, mm7;
  48.788 +		psllq mm2, 32;
  48.789 +		psrlq mm3, 32;
  48.790 +		por	  mm0, mm2;
  48.791 +		por	  mm1, mm3;
  48.792 +
  48.793 +		/* current_upper */
  48.794 +		movq mm6, qword ptr[eax];
  48.795 +
  48.796 +		/* compute the upper-left pixel for dst on %%mm2 */
  48.797 +		/* compute the upper-right pixel for dst on %%mm4 */
  48.798 +		movq	mm2, mm0;
  48.799 +		movq	mm4, mm1;
  48.800 +		movq	mm3, mm0;
  48.801 +		movq	mm5, mm1;
  48.802 +		pcmpeqd mm2, mm6;
  48.803 +		pcmpeqd mm4, mm6;
  48.804 +		pcmpeqd mm3, qword ptr[ecx];
  48.805 +		pcmpeqd mm5, qword ptr[ecx];
  48.806 +		pandn	mm3, mm2;
  48.807 +		pandn	mm5, mm4;
  48.808 +		movq	mm2, mm0;
  48.809 +		movq	mm4, mm1;
  48.810 +		pcmpeqd mm2, mm1;
  48.811 +		pcmpeqd mm4, mm0;
  48.812 +		pandn	mm2, mm3;
  48.813 +		pandn	mm4, mm5;
  48.814 +		movq	mm3, mm2;
  48.815 +		movq	mm5, mm4;
  48.816 +		pand	mm2, mm6;
  48.817 +		pand	mm4, mm6;
  48.818 +		pandn	mm3, mm7;
  48.819 +		pandn	mm5, mm7;
  48.820 +		por		mm2, mm3;
  48.821 +		por		mm4, mm5;
  48.822 +
  48.823 +		/* set *dst */
  48.824 +		movq	   mm3, mm2;
  48.825 +		punpckldq  mm2, mm4;
  48.826 +		punpckhdq  mm3, mm4;
  48.827 +		movq qword ptr [edx], mm2;
  48.828 +		movq qword ptr [edx + 8], mm3;
  48.829 +
  48.830 +		/* next */
  48.831 +		add eax, 8;
  48.832 +		add ebx, 8;
  48.833 +		add ecx, 8;
  48.834 +		add edx, 16;
  48.835 +
  48.836 +		dec esi;
  48.837 +		jnz label0;
  48.838 +label1:
  48.839 +
  48.840 +		/* final run */
  48.841 +		/* set the current, current_pre, current_next registers */
  48.842 +		movq mm1, qword ptr [ebx];
  48.843 +		movq  mm7, qword ptr [ebx];
  48.844 +		movq  mm0, qword ptr [ebx - 8];
  48.845 +		psrlq mm1, 32;
  48.846 +		psrlq mm0, 32;
  48.847 +		psllq mm1, 32;
  48.848 +		movq  mm2, mm7;
  48.849 +		movq  mm3, mm7;
  48.850 +		psllq mm2, 32;
  48.851 +		psrlq mm3, 32;
  48.852 +		por	  mm0, mm2;
  48.853 +		por	  mm1, mm3;
  48.854 +
  48.855 +		/* current_upper */
  48.856 +		movq mm6, qword ptr [eax];
  48.857 +
  48.858 +		/* compute the upper-left pixel for dst on %%mm2 */
  48.859 +		/* compute the upper-right pixel for dst on %%mm4 */
  48.860 +		movq	mm2, mm0;
  48.861 +		movq	mm4, mm1;
  48.862 +		movq	mm3, mm0;
  48.863 +		movq	mm5, mm1;
  48.864 +		pcmpeqd mm2, mm6;
  48.865 +		pcmpeqd mm4, mm6;
  48.866 +		pcmpeqd mm3, qword ptr [ecx];
  48.867 +		pcmpeqd mm5, qword ptr [ecx];
  48.868 +		pandn	mm3, mm2;
  48.869 +		pandn	mm5, mm4;
  48.870 +		movq	mm2, mm0;
  48.871 +		movq	mm4, mm1;
  48.872 +		pcmpeqd mm2, mm1;
  48.873 +		pcmpeqd mm4, mm0;
  48.874 +		pandn	mm2, mm3;
  48.875 +		pandn	mm4, mm5;
  48.876 +		movq	mm3, mm2;
  48.877 +		movq	mm5, mm4;
  48.878 +		pand	mm2, mm6;
  48.879 +		pand	mm4, mm6;
  48.880 +		pandn	mm3, mm7;
  48.881 +		pandn	mm5, mm7;
  48.882 +		por		mm2, mm3;
  48.883 +		por		mm4, mm5;
  48.884 +
  48.885 +		/* set *dst */
  48.886 +		movq	   mm3, mm2;
  48.887 +		punpckldq  mm2, mm4;
  48.888 +		punpckhdq  mm3, mm4;
  48.889 +		movq qword ptr [edx], mm2;
  48.890 +		movq qword ptr [edx + 8], mm3;
  48.891 +
  48.892 +		mov src0, eax;
  48.893 +		mov src1, ebx;
  48.894 +		mov src2, ecx;
  48.895 +		mov dst, edx;
  48.896 +		mov count, esi;
  48.897 +
  48.898 +		emms;
  48.899 +	}
  48.900 +#endif
  48.901 +}
  48.902 +
  48.903 +static void internal_scale2x_16_mmx(u16 *dst0, u16 *dst1, const u16 *src0, const u16 *src1, const u16 *src2, unsigned count)
  48.904 +{
  48.905 +	//	assert( count >= 2*4 );
  48.906 +	internal_scale2x_16_mmx_single(dst0, src0, src1, src2, count);
  48.907 +	internal_scale2x_16_mmx_single(dst1, src2, src1, src0, count);
  48.908 +}
  48.909 +
  48.910 +static void internal_scale2x_32_mmx(u32 *dst0, u32 *dst1, const u32 *src0, const u32 *src1, const u32 *src2, unsigned count)
  48.911 +{
  48.912 +	//	assert( count >= 2*2 );
  48.913 +	internal_scale2x_32_mmx_single(dst0, src0, src1, src2, count);
  48.914 +	internal_scale2x_32_mmx_single(dst1, src2, src1, src0, count);
  48.915 +}
  48.916 +
  48.917 +#endif
  48.918 +
  48.919 +void AdMame2x(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  48.920 +              u8 *dstPtr, u32 dstPitch, int width, int height)
  48.921 +{
  48.922 +	u16 *dst0 = (u16 *)dstPtr;
  48.923 +	u16 *dst1 = dst0 + (dstPitch >> 1);
  48.924 +
  48.925 +	u16 *src0 = (u16 *)srcPtr;
  48.926 +	u16 *src1 = src0 + (srcPitch >> 1);
  48.927 +	u16 *src2 = src1 + (srcPitch >> 1);
  48.928 +#ifdef MMX
  48.929 +	if (cpu_mmx)
  48.930 +	{
  48.931 +		internal_scale2x_16_mmx(dst0, dst1, src0, src0, src1, width);
  48.932 +
  48.933 +		int count = height;
  48.934 +
  48.935 +		count -= 2;
  48.936 +		while (count)
  48.937 +		{
  48.938 +			dst0 += dstPitch;
  48.939 +			dst1 += dstPitch;
  48.940 +			internal_scale2x_16_mmx(dst0, dst1, src0, src1, src2, width);
  48.941 +			src0  = src1;
  48.942 +			src1  = src2;
  48.943 +			src2 += srcPitch >> 1;
  48.944 +			--count;
  48.945 +		}
  48.946 +		dst0 += dstPitch;
  48.947 +		dst1 += dstPitch;
  48.948 +		internal_scale2x_16_mmx(dst0, dst1, src0, src1, src1, width);
  48.949 +	}
  48.950 +	else
  48.951 +	{
  48.952 +#endif
  48.953 +	internal_scale2x_16_def(dst0, src0, src0, src1, width);
  48.954 +	internal_scale2x_16_def(dst1, src1, src0, src0, width);
  48.955 +
  48.956 +	int count = height;
  48.957 +
  48.958 +	count -= 2;
  48.959 +	while (count)
  48.960 +	{
  48.961 +		dst0 += dstPitch;
  48.962 +		dst1 += dstPitch;
  48.963 +		internal_scale2x_16_def(dst0, src0, src1, src2, width);
  48.964 +		internal_scale2x_16_def(dst1, src2, src1, src0, width);
  48.965 +		src0  = src1;
  48.966 +		src1  = src2;
  48.967 +		src2 += srcPitch >> 1;
  48.968 +		--count;
  48.969 +	}
  48.970 +	dst0 += dstPitch;
  48.971 +	dst1 += dstPitch;
  48.972 +	internal_scale2x_16_def(dst0, src0, src1, src1, width);
  48.973 +	internal_scale2x_16_def(dst1, src1, src1, src0, width);
  48.974 +#ifdef MMX
  48.975 +}
  48.976 +
  48.977 +#endif
  48.978 +}
  48.979 +
  48.980 +void AdMame2x32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  48.981 +                u8 *dstPtr, u32 dstPitch, int width, int height)
  48.982 +{
  48.983 +	u32 *dst0 = (u32 *)dstPtr;
  48.984 +	u32 *dst1 = dst0 + (dstPitch >> 2);
  48.985 +
  48.986 +	u32 *src0 = (u32 *)srcPtr;
  48.987 +	u32 *src1 = src0 + (srcPitch >> 2);
  48.988 +	u32 *src2 = src1 + (srcPitch >> 2);
  48.989 +#ifdef MMX
  48.990 +	if (cpu_mmx)
  48.991 +	{
  48.992 +		internal_scale2x_32_mmx(dst0, dst1, src0, src0, src1, width);
  48.993 +
  48.994 +		int count = height;
  48.995 +
  48.996 +		count -= 2;
  48.997 +		while (count)
  48.998 +		{
  48.999 +			dst0 += dstPitch >> 1;
 48.1000 +			dst1 += dstPitch >> 1;
 48.1001 +			internal_scale2x_32_mmx(dst0, dst1, src0, src1, src2, width);
 48.1002 +			src0  = src1;
 48.1003 +			src1  = src2;
 48.1004 +			src2 += srcPitch >> 2;
 48.1005 +			--count;
 48.1006 +		}
 48.1007 +		dst0 += dstPitch >> 1;
 48.1008 +		dst1 += dstPitch >> 1;
 48.1009 +		internal_scale2x_32_mmx(dst0, dst1, src0, src1, src1, width);
 48.1010 +	}
 48.1011 +	else
 48.1012 +	{
 48.1013 +#endif
 48.1014 +	internal_scale2x_32_def(dst0, src0, src0, src1, width);
 48.1015 +	internal_scale2x_32_def(dst1, src1, src0, src0, width);
 48.1016 +
 48.1017 +	int count = height;
 48.1018 +
 48.1019 +	count -= 2;
 48.1020 +	while (count)
 48.1021 +	{
 48.1022 +		dst0 += dstPitch >> 1;
 48.1023 +		dst1 += dstPitch >> 1;
 48.1024 +		internal_scale2x_32_def(dst0, src0, src1, src2, width);
 48.1025 +		internal_scale2x_32_def(dst1, src2, src1, src0, width);
 48.1026 +		src0  = src1;
 48.1027 +		src1  = src2;
 48.1028 +		src2 += srcPitch >> 2;
 48.1029 +		--count;
 48.1030 +	}
 48.1031 +	dst0 += dstPitch >> 1;
 48.1032 +	dst1 += dstPitch >> 1;
 48.1033 +	internal_scale2x_32_def(dst0, src0, src1, src1, width);
 48.1034 +	internal_scale2x_32_def(dst1, src1, src1, src0, width);
 48.1035 +#ifdef MMX
 48.1036 +}
 48.1037 +
 48.1038 +#endif
 48.1039 +}
    49.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.2 +++ b/src/filters/bilinear.cpp	Sat Mar 03 10:31:27 2012 -0600
    49.3 @@ -0,0 +1,418 @@
    49.4 +/**     Code adapted from Exult source code by Forgotten
    49.5 +**	Scale.cc - Trying to scale with bilinear interpolation.
    49.6 +**
    49.7 +**	Written: 6/14/00 - JSF
    49.8 +**/
    49.9 +
   49.10 +#include "../common/System.h"
   49.11 +
   49.12 +static u8 row_cur[3 * 322];
   49.13 +static u8 row_next[3 * 322];
   49.14 +
   49.15 +static u8 *rgb_row_cur	= row_cur;
   49.16 +static u8 *rgb_row_next = row_next;
   49.17 +
   49.18 +#ifdef RGB
   49.19 +#undef RGB  // wingdi.h has it
   49.20 +#endif
   49.21 +#define RGB(r, g, b) \
   49.22 +    ((r) >> 3) << systemRedShift | \
   49.23 +    ((g) >> 3) << systemGreenShift | \
   49.24 +    ((b) >> 3) << systemBlueShift \
   49.25 +
   49.26 +static void fill_rgb_row_16(u16 *from, int src_width, u8 *row, int width)
   49.27 +{
   49.28 +	u8 *copy_start = row + src_width * 3;
   49.29 +	u8 *all_stop   = row + width * 3;
   49.30 +	while (row < copy_start)
   49.31 +	{
   49.32 +		u16 color = *from++;
   49.33 +		*row++ = ((color >> systemRedShift) & 0x1f) << 3;
   49.34 +		*row++ = ((color >> systemGreenShift) & 0x1f) << 3;
   49.35 +		*row++ = ((color >> systemBlueShift) & 0x1f) << 3;
   49.36 +	}
   49.37 +	// any remaining elements to be written to 'row' are a replica of the
   49.38 +	// preceding pixel
   49.39 +	u8 *p = row - 3;
   49.40 +	while (row < all_stop)
   49.41 +	{
   49.42 +		// we're guaranteed three elements per pixel; could unroll the loop
   49.43 +		// further, especially with a Duff's Device, but the gains would be
   49.44 +		// probably limited (judging by profiler output)
   49.45 +		*row++ = *p++;
   49.46 +		*row++ = *p++;
   49.47 +		*row++ = *p++;
   49.48 +	}
   49.49 +}
   49.50 +
   49.51 +static void fill_rgb_row_32(u32 *from, int src_width, u8 *row, int width)
   49.52 +{
   49.53 +	u8 *copy_start = row + src_width * 3;
   49.54 +	u8 *all_stop   = row + width * 3;
   49.55 +	while (row < copy_start)
   49.56 +	{
   49.57 +		u32 color = *from++;
   49.58 +		*row++ = ((color >> systemRedShift) & 0x1f) << 3;
   49.59 +		*row++ = ((color >> systemGreenShift) & 0x1f) << 3;
   49.60 +		*row++ = ((color >> systemBlueShift) & 0x1f) << 3;
   49.61 +	}
   49.62 +	// any remaining elements to be written to 'row' are a replica of the
   49.63 +	// preceding pixel
   49.64 +	u8 *p = row - 3;
   49.65 +	while (row < all_stop)
   49.66 +	{
   49.67 +		// we're guaranteed three elements per pixel; could unroll the loop
   49.68 +		// further, especially with a Duff's Device, but the gains would be
   49.69 +		// probably limited (judging by profiler output)
   49.70 +		*row++ = *p++;
   49.71 +		*row++ = *p++;
   49.72 +		*row++ = *p++;
   49.73 +	}
   49.74 +}
   49.75 +
   49.76 +void Bilinear(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
   49.77 +              u8 *dstPtr, u32 dstPitch, int width, int height)
   49.78 +{
   49.79 +	u16 *to		= (u16 *)dstPtr;
   49.80 +	u16 *to_odd = (u16 *)(dstPtr + dstPitch);
   49.81 +
   49.82 +	int	 from_width = width;
   49.83 +	u16 *from		= (u16 *)srcPtr;
   49.84 +	fill_rgb_row_16(from, from_width, rgb_row_cur, width + 1);
   49.85 +
   49.86 +	for (int y = 0; y < height; y++)
   49.87 +	{
   49.88 +		u16 *from_orig = from;
   49.89 +		u16 *to_orig   = to;
   49.90 +
   49.91 +		if (y + 1 < height)
   49.92 +			fill_rgb_row_16(from + width + 2, from_width, rgb_row_next,
   49.93 +			                width + 1);
   49.94 +		else
   49.95 +			fill_rgb_row_16(from, from_width, rgb_row_next, width + 1);
   49.96 +
   49.97 +		// every pixel in the src region, is extended to 4 pixels in the
   49.98 +		// destination, arranged in a square 'quad'; if the current src
   49.99 +		// pixel is 'a', then in what follows 'b' is the src pixel to the
  49.100 +		// right, 'c' is the src pixel below, and 'd' is the src pixel to
  49.101 +		// the right and down
  49.102 +		u8 *cur_row	 = rgb_row_cur;
  49.103 +		u8 *next_row = rgb_row_next;
  49.104 +		u8 *ar		 = cur_row++;
  49.105 +		u8 *ag		 = cur_row++;
  49.106 +		u8 *ab		 = cur_row++;
  49.107 +		u8 *cr		 = next_row++;
  49.108 +		u8 *cg		 = next_row++;
  49.109 +		u8 *cb		 = next_row++;
  49.110 +		for (int x = 0; x < width; x++)
  49.111 +		{
  49.112 +			u8 *br = cur_row++;
  49.113 +			u8 *bg = cur_row++;
  49.114 +			u8 *bb = cur_row++;
  49.115 +			u8 *dr = next_row++;
  49.116 +			u8 *dg = next_row++;
  49.117 +			u8 *db = next_row++;
  49.118 +
  49.119 +			// upper left pixel in quad: just copy it in
  49.120 +			*to++ = RGB(*ar, *ag, *ab);
  49.121 +
  49.122 +			// upper right
  49.123 +			*to++ = RGB((*ar + *br) >> 1, (*ag + *bg) >> 1, (*ab + *bb) >> 1);
  49.124 +
  49.125 +			// lower left
  49.126 +			*to_odd++ = RGB((*ar + *cr) >> 1, (*ag + *cg) >> 1, (*ab + *cb) >> 1);
  49.127 +
  49.128 +			// lower right
  49.129 +			*to_odd++ = RGB((*ar + *br + *cr + *dr) >> 2,
  49.130 +			                (*ag + *bg + *cg + *dg) >> 2,
  49.131 +			                (*ab + *bb + *cb + *db) >> 2);
  49.132 +
  49.133 +			// 'b' becomes 'a', 'd' becomes 'c'
  49.134 +			ar = br;
  49.135 +			ag = bg;
  49.136 +			ab = bb;
  49.137 +			cr = dr;
  49.138 +			cg = dg;
  49.139 +			cb = db;
  49.140 +		}
  49.141 +
  49.142 +		// the "next" rgb row becomes the current; the old current rgb row is
  49.143 +		// recycled and serves as the new "next" row
  49.144 +		u8 *temp;
  49.145 +		temp		 = rgb_row_cur;
  49.146 +		rgb_row_cur	 = rgb_row_next;
  49.147 +		rgb_row_next = temp;
  49.148 +
  49.149 +		// update the pointers for start of next pair of lines
  49.150 +		from   = (u16 *)((u8 *)from_orig + srcPitch);
  49.151 +		to	   = (u16 *)((u8 *)to_orig + (dstPitch << 1));
  49.152 +		to_odd = (u16 *)((u8 *)to + dstPitch);
  49.153 +	}
  49.154 +}
  49.155 +
  49.156 +void BilinearPlus(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  49.157 +                  u8 *dstPtr, u32 dstPitch, int width, int height)
  49.158 +{
  49.159 +	u16 *to		= (u16 *)dstPtr;
  49.160 +	u16 *to_odd = (u16 *)(dstPtr + dstPitch);
  49.161 +
  49.162 +	int	 from_width = width;
  49.163 +	u16 *from		= (u16 *)srcPtr;
  49.164 +	fill_rgb_row_16(from, from_width, rgb_row_cur, width + 1);
  49.165 +
  49.166 +	for (int y = 0; y < height; y++)
  49.167 +	{
  49.168 +		u16 *from_orig = from;
  49.169 +		u16 *to_orig   = to;
  49.170 +
  49.171 +		if (y + 1 < height)
  49.172 +			fill_rgb_row_16(from + width + 2, from_width, rgb_row_next,
  49.173 +			                width + 1);
  49.174 +		else
  49.175 +			fill_rgb_row_16(from, from_width, rgb_row_next, width + 1);
  49.176 +
  49.177 +		// every pixel in the src region, is extended to 4 pixels in the
  49.178 +		// destination, arranged in a square 'quad'; if the current src
  49.179 +		// pixel is 'a', then in what follows 'b' is the src pixel to the
  49.180 +		// right, 'c' is the src pixel below, and 'd' is the src pixel to
  49.181 +		// the right and down
  49.182 +		u8 *cur_row	 = rgb_row_cur;
  49.183 +		u8 *next_row = rgb_row_next;
  49.184 +		u8 *ar		 = cur_row++;
  49.185 +		u8 *ag		 = cur_row++;
  49.186 +		u8 *ab		 = cur_row++;
  49.187 +		u8 *cr		 = next_row++;
  49.188 +		u8 *cg		 = next_row++;
  49.189 +		u8 *cb		 = next_row++;
  49.190 +		for (int x = 0; x < width; x++)
  49.191 +		{
  49.192 +			u8 *br = cur_row++;
  49.193 +			u8 *bg = cur_row++;
  49.194 +			u8 *bb = cur_row++;
  49.195 +			u8 *dr = next_row++;
  49.196 +			u8 *dg = next_row++;
  49.197 +			u8 *db = next_row++;
  49.198 +
  49.199 +			// upper left pixel in quad: just copy it in
  49.200 +			//*to++ = manip.rgb(*ar, *ag, *ab);
  49.201 +#ifdef USE_ORIGINAL_BILINEAR_PLUS
  49.202 +			*to++ = RGB(
  49.203 +			    (((*ar) << 2) + ((*ar)) + (*cr + *br + *br)) >> 3,
  49.204 +			    (((*ag) << 2) + ((*ag)) + (*cg + *bg + *bg)) >> 3,
  49.205 +			    (((*ab) << 2) + ((*ab)) + (*cb + *bb + *bb)) >> 3);
  49.206 +#else
  49.207 +			*to++ = RGB(
  49.208 +			    (((*ar) << 3) + ((*ar) << 1) + (*cr + *br + *br + *cr)) >> 4,
  49.209 +			    (((*ag) << 3) + ((*ag) << 1) + (*cg + *bg + *bg + *cg)) >> 4,
  49.210 +			    (((*ab) << 3) + ((*ab) << 1) + (*cb + *bb + *bb + *cb)) >> 4);
  49.211 +#endif
  49.212 +
  49.213 +			// upper right
  49.214 +			*to++ = RGB((*ar + *br) >> 1, (*ag + *bg) >> 1, (*ab + *bb) >> 1);
  49.215 +
  49.216 +			// lower left
  49.217 +			*to_odd++ = RGB((*ar + *cr) >> 1, (*ag + *cg) >> 1, (*ab + *cb) >> 1);
  49.218 +
  49.219 +			// lower right
  49.220 +			*to_odd++ = RGB((*ar + *br + *cr + *dr) >> 2,
  49.221 +			                (*ag + *bg + *cg + *dg) >> 2,
  49.222 +			                (*ab + *bb + *cb + *db) >> 2);
  49.223 +
  49.224 +			// 'b' becomes 'a', 'd' becomes 'c'
  49.225 +			ar = br;
  49.226 +			ag = bg;
  49.227 +			ab = bb;
  49.228 +			cr = dr;
  49.229 +			cg = dg;
  49.230 +			cb = db;
  49.231 +		}
  49.232 +
  49.233 +		// the "next" rgb row becomes the current; the old current rgb row is
  49.234 +		// recycled and serves as the new "next" row
  49.235 +		u8 *temp;
  49.236 +		temp		 = rgb_row_cur;
  49.237 +		rgb_row_cur	 = rgb_row_next;
  49.238 +		rgb_row_next = temp;
  49.239 +
  49.240 +		// update the pointers for start of next pair of lines
  49.241 +		from   = (u16 *)((u8 *)from_orig + srcPitch);
  49.242 +		to	   = (u16 *)((u8 *)to_orig + (dstPitch << 1));
  49.243 +		to_odd = (u16 *)((u8 *)to + dstPitch);
  49.244 +	}
  49.245 +}
  49.246 +
  49.247 +void Bilinear32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  49.248 +                u8 *dstPtr, u32 dstPitch, int width, int height)
  49.249 +{
  49.250 +	u32 *to		= (u32 *)dstPtr;
  49.251 +	u32 *to_odd = (u32 *)(dstPtr + dstPitch);
  49.252 +
  49.253 +	int from_width = width;
  49.254 +	if (width + 1 < from_width)
  49.255 +		from_width = width + 1;
  49.256 +	u32 *from = (u32 *)srcPtr;
  49.257 +	fill_rgb_row_32(from, from_width, rgb_row_cur, width + 1);
  49.258 +
  49.259 +	for (int y = 0; y < height; y++)
  49.260 +	{
  49.261 +		u32 *from_orig = from;
  49.262 +		u32 *to_orig   = to;
  49.263 +
  49.264 +		if (y + 1 < height)
  49.265 +			fill_rgb_row_32(from + width + 1, from_width, rgb_row_next,
  49.266 +			                width + 1);
  49.267 +		else
  49.268 +			fill_rgb_row_32(from, from_width, rgb_row_next, width + 1);
  49.269 +
  49.270 +		// every pixel in the src region, is extended to 4 pixels in the
  49.271 +		// destination, arranged in a square 'quad'; if the current src
  49.272 +		// pixel is 'a', then in what follows 'b' is the src pixel to the
  49.273 +		// right, 'c' is the src pixel below, and 'd' is the src pixel to
  49.274 +		// the right and down
  49.275 +		u8 *cur_row	 = rgb_row_cur;
  49.276 +		u8 *next_row = rgb_row_next;
  49.277 +		u8 *ar		 = cur_row++;
  49.278 +		u8 *ag		 = cur_row++;
  49.279 +		u8 *ab		 = cur_row++;
  49.280 +		u8 *cr		 = next_row++;
  49.281 +		u8 *cg		 = next_row++;
  49.282 +		u8 *cb		 = next_row++;
  49.283 +		for (int x = 0; x < width; x++)
  49.284 +		{
  49.285 +			u8 *br = cur_row++;
  49.286 +			u8 *bg = cur_row++;
  49.287 +			u8 *bb = cur_row++;
  49.288 +			u8 *dr = next_row++;
  49.289 +			u8 *dg = next_row++;
  49.290 +			u8 *db = next_row++;
  49.291 +
  49.292 +			// upper left pixel in quad: just copy it in
  49.293 +			*to++ = RGB(*ar, *ag, *ab);
  49.294 +
  49.295 +			// upper right
  49.296 +			*to++ = RGB((*ar + *br) >> 1, (*ag + *bg) >> 1, (*ab + *bb) >> 1);
  49.297 +
  49.298 +			// lower left
  49.299 +			*to_odd++ = RGB((*ar + *cr) >> 1, (*ag + *cg) >> 1, (*ab + *cb) >> 1);
  49.300 +
  49.301 +			// lower right
  49.302 +			*to_odd++ = RGB((*ar + *br + *cr + *dr) >> 2,
  49.303 +			                (*ag + *bg + *cg + *dg) >> 2,
  49.304 +			                (*ab + *bb + *cb + *db) >> 2);
  49.305 +
  49.306 +			// 'b' becomes 'a', 'd' becomes 'c'
  49.307 +			ar = br;
  49.308 +			ag = bg;
  49.309 +			ab = bb;
  49.310 +			cr = dr;
  49.311 +			cg = dg;
  49.312 +			cb = db;
  49.313 +		}
  49.314 +
  49.315 +		// the "next" rgb row becomes the current; the old current rgb row is
  49.316 +		// recycled and serves as the new "next" row
  49.317 +		u8 *temp;
  49.318 +		temp		 = rgb_row_cur;
  49.319 +		rgb_row_cur	 = rgb_row_next;
  49.320 +		rgb_row_next = temp;
  49.321 +
  49.322 +		// update the pointers for start of next pair of lines
  49.323 +		from   = (u32 *)((u8 *)from_orig + srcPitch);
  49.324 +		to	   = (u32 *)((u8 *)to_orig + (dstPitch << 1));
  49.325 +		to_odd = (u32 *)((u8 *)to + dstPitch);
  49.326 +	}
  49.327 +}
  49.328 +
  49.329 +void BilinearPlus32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  49.330 +                    u8 *dstPtr, u32 dstPitch, int width, int height)
  49.331 +{
  49.332 +	u32 *to		= (u32 *)dstPtr;
  49.333 +	u32 *to_odd = (u32 *)(dstPtr + dstPitch);
  49.334 +
  49.335 +	int from_width = width;
  49.336 +	if (width + 1 < from_width)
  49.337 +		from_width = width + 1;
  49.338 +	u32 *from = (u32 *)srcPtr;
  49.339 +	fill_rgb_row_32(from, from_width, rgb_row_cur, width + 1);
  49.340 +
  49.341 +	for (int y = 0; y < height; y++)
  49.342 +	{
  49.343 +		u32 *from_orig = from;
  49.344 +		u32 *to_orig   = to;
  49.345 +
  49.346 +		if (y + 1 < height)
  49.347 +			fill_rgb_row_32(from + width + 1, from_width, rgb_row_next,
  49.348 +			                width + 1);
  49.349 +		else
  49.350 +			fill_rgb_row_32(from, from_width, rgb_row_next, width + 1);
  49.351 +
  49.352 +		// every pixel in the src region, is extended to 4 pixels in the
  49.353 +		// destination, arranged in a square 'quad'; if the current src
  49.354 +		// pixel is 'a', then in what follows 'b' is the src pixel to the
  49.355 +		// right, 'c' is the src pixel below, and 'd' is the src pixel to
  49.356 +		// the right and down
  49.357 +		u8 *cur_row	 = rgb_row_cur;
  49.358 +		u8 *next_row = rgb_row_next;
  49.359 +		u8 *ar		 = cur_row++;
  49.360 +		u8 *ag		 = cur_row++;
  49.361 +		u8 *ab		 = cur_row++;
  49.362 +		u8 *cr		 = next_row++;
  49.363 +		u8 *cg		 = next_row++;
  49.364 +		u8 *cb		 = next_row++;
  49.365 +		for (int x = 0; x < width; x++)
  49.366 +		{
  49.367 +			u8 *br = cur_row++;
  49.368 +			u8 *bg = cur_row++;
  49.369 +			u8 *bb = cur_row++;
  49.370 +			u8 *dr = next_row++;
  49.371 +			u8 *dg = next_row++;
  49.372 +			u8 *db = next_row++;
  49.373 +
  49.374 +			// upper left pixel in quad: just copy it in
  49.375 +			//*to++ = manip.rgb(*ar, *ag, *ab);
  49.376 +#ifdef USE_ORIGINAL_BILINEAR_PLUS
  49.377 +			*to++ = RGB(
  49.378 +			    (((*ar) << 2) + ((*ar)) + (*cr + *br + *br)) >> 3,
  49.379 +			    (((*ag) << 2) + ((*ag)) + (*cg + *bg + *bg)) >> 3,
  49.380 +			    (((*ab) << 2) + ((*ab)) + (*cb + *bb + *bb)) >> 3);
  49.381 +#else
  49.382 +			*to++ = RGB(
  49.383 +			    (((*ar) << 3) + ((*ar) << 1) + (*cr + *br + *br + *cr)) >> 4,
  49.384 +			    (((*ag) << 3) + ((*ag) << 1) + (*cg + *bg + *bg + *cg)) >> 4,
  49.385 +			    (((*ab) << 3) + ((*ab) << 1) + (*cb + *bb + *bb + *cb)) >> 4);
  49.386 +#endif
  49.387 +
  49.388 +			// upper right
  49.389 +			*to++ = RGB((*ar + *br) >> 1, (*ag + *bg) >> 1, (*ab + *bb) >> 1);
  49.390 +
  49.391 +			// lower left
  49.392 +			*to_odd++ = RGB((*ar + *cr) >> 1, (*ag + *cg) >> 1, (*ab + *cb) >> 1);
  49.393 +
  49.394 +			// lower right
  49.395 +			*to_odd++ = RGB((*ar + *br + *cr + *dr) >> 2,
  49.396 +			                (*ag + *bg + *cg + *dg) >> 2,
  49.397 +			                (*ab + *bb + *cb + *db) >> 2);
  49.398 +
  49.399 +			// 'b' becomes 'a', 'd' becomes 'c'
  49.400 +			ar = br;
  49.401 +			ag = bg;
  49.402 +			ab = bb;
  49.403 +			cr = dr;
  49.404 +			cg = dg;
  49.405 +			cb = db;
  49.406 +		}
  49.407 +
  49.408 +		// the "next" rgb row becomes the current; the old current rgb row is
  49.409 +		// recycled and serves as the new "next" row
  49.410 +		u8 *temp;
  49.411 +		temp		 = rgb_row_cur;
  49.412 +		rgb_row_cur	 = rgb_row_next;
  49.413 +		rgb_row_next = temp;
  49.414 +
  49.415 +		// update the pointers for start of next pair of lines
  49.416 +		from   = (u32 *)((u8 *)from_orig + srcPitch);
  49.417 +		to	   = (u32 *)((u8 *)to_orig + (dstPitch << 1));
  49.418 +		to_odd = (u32 *)((u8 *)to + dstPitch);
  49.419 +	}
  49.420 +}
  49.421 +
    50.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.2 +++ b/src/filters/filters.h	Sat Mar 03 10:31:27 2012 -0600
    50.3 @@ -0,0 +1,58 @@
    50.4 +
    50.5 +#ifndef VBA_FILTERS_H
    50.6 +#define VBA_FILTERS_H
    50.7 +
    50.8 +#if _MSC_VER > 1000
    50.9 +#pragma once
   50.10 +#endif // _MSC_VER > 1000
   50.11 +
   50.12 +extern void Pixelate2x16(u8*, u32, u8*, u8*, u32, int, int);
   50.13 +extern void Pixelate2x32(u8*, u32, u8*, u8*, u32, int, int);
   50.14 +extern void (*Pixelate3x16)(u8*, u32, u8*, u8*, u32, int, int);
   50.15 +extern void (*Pixelate3x32)(u8*, u32, u8*, u8*, u32, int, int);
   50.16 +extern void (*Pixelate4x16)(u8*, u32, u8*, u8*, u32, int, int);
   50.17 +extern void (*Pixelate4x32)(u8*, u32, u8*, u8*, u32, int, int);
   50.18 +extern void MotionBlur(u8*, u32, u8*, u8*, u32, int, int);
   50.19 +extern void MotionBlur32(u8*, u32, u8*, u8*, u32, int, int);
   50.20 +extern void _2xSaI(u8*, u32, u8*, u8*, u32, int, int);
   50.21 +extern void _2xSaI32(u8*, u32, u8*, u8*, u32, int, int);
   50.22 +extern void Super2xSaI(u8*, u32, u8*, u8*, u32, int, int);
   50.23 +extern void Super2xSaI32(u8*, u32, u8*, u8*, u32, int, int);
   50.24 +extern void SuperEagle(u8*, u32, u8*, u8*, u32, int, int);
   50.25 +extern void SuperEagle32(u8*, u32, u8*, u8*, u32, int, int);
   50.26 +extern void AdMame2x(u8*, u32, u8*, u8*, u32, int, int);
   50.27 +extern void AdMame2x32(u8*, u32, u8*, u8*, u32, int, int);
   50.28 +extern void Simple2x16(u8*, u32, u8*, u8*, u32, int, int);
   50.29 +extern void Simple2x32(u8*, u32, u8*, u8*, u32, int, int);
   50.30 +extern void (*Simple3x16)(u8*, u32, u8*, u8*, u32, int, int);
   50.31 +extern void (*Simple3x32)(u8*, u32, u8*, u8*, u32, int, int);
   50.32 +extern void (*Simple4x16)(u8*, u32, u8*, u8*, u32, int, int);
   50.33 +extern void (*Simple4x32)(u8*, u32, u8*, u8*, u32, int, int);
   50.34 +extern void Bilinear(u8*, u32, u8*, u8*, u32, int, int);
   50.35 +extern void Bilinear32(u8*, u32, u8*, u8*, u32, int, int);
   50.36 +extern void BilinearPlus(u8*, u32, u8*, u8*, u32, int, int);
   50.37 +extern void BilinearPlus32(u8*, u32, u8*, u8*, u32, int, int);
   50.38 +extern void Scanlines(u8*, u32, u8*, u8*, u32, int, int);
   50.39 +extern void Scanlines32(u8*, u32, u8*, u8*, u32, int, int);
   50.40 +extern void ScanlinesTV(u8*, u32, u8*, u8*, u32, int, int);
   50.41 +extern void ScanlinesTV32(u8*, u32, u8*, u8*, u32, int, int);
   50.42 +extern void hq2x(u8*, u32, u8*, u8*, u32, int, int);
   50.43 +extern void hq2x32(u8*, u32, u8*, u8*, u32, int, int);
   50.44 +extern void hq2xS(u8*, u32, u8*, u8*, u32, int, int);
   50.45 +extern void hq2xS32(u8*, u32, u8*, u8*, u32, int, int);
   50.46 +extern void lq2x(u8*, u32, u8*, u8*, u32, int, int);
   50.47 +extern void lq2x32(u8*, u32, u8*, u8*, u32, int, int);
   50.48 +extern void hq3x(u8*, u32, u8*, u8*, u32, int, int);
   50.49 +extern void hq3x32(u8*, u32, u8*, u8*, u32, int, int);
   50.50 +extern void hq3xS(u8*, u32, u8*, u8*, u32, int, int);
   50.51 +extern void hq3xS32(u8*, u32, u8*, u8*, u32, int, int);
   50.52 +
   50.53 +extern void SmartIB(u8*, u32, int, int);
   50.54 +extern void SmartIB32(u8*, u32, int, int);
   50.55 +extern void MotionBlurIB(u8*, u32, int, int);
   50.56 +extern void InterlaceIB(u8*, u32, int, int);
   50.57 +extern void MotionBlurIB32(u8*, u32, int, int);
   50.58 +
   50.59 +extern void InterframeCleanup();
   50.60 +
   50.61 +#endif // VBA_FILTERS_H
    51.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.2 +++ b/src/filters/hq2x.cpp	Sat Mar 03 10:31:27 2012 -0600
    51.3 @@ -0,0 +1,966 @@
    51.4 +/*
    51.5 + * This file is part of the Advance project.
    51.6 + *
    51.7 + * Copyright (C) 2003 Andrea Mazzoleni
    51.8 + *
    51.9 + * This program is free software; you can redistribute it and/or modify
   51.10 + * it under the terms of the GNU General Public License as published by
   51.11 + * the Free Software Foundation; either version 2 of the License, or
   51.12 + * (at your option) any later version.
   51.13 + *
   51.14 + * This program is distributed in the hope that it will be useful,
   51.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   51.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   51.17 + * GNU General Public License for more details.
   51.18 + *
   51.19 + * You should have received a copy of the GNU General Public License
   51.20 + * along with this program; if not, write to the Free Software
   51.21 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   51.22 + *
   51.23 + * In addition, as a special exception, Andrea Mazzoleni
   51.24 + * gives permission to link the code of this program with
   51.25 + * the MAME library (or with modified versions of MAME that use the
   51.26 + * same license as MAME), and distribute linked combinations including
   51.27 + * the two.  You must obey the GNU General Public License in all
   51.28 + * respects for all of the code used other than MAME.  If you modify
   51.29 + * this file, you may extend this exception to your version of the
   51.30 + * file, but you are not obligated to do so.  If you do not wish to
   51.31 + * do so, delete this exception statement from your version.
   51.32 + */
   51.33 +#include "../Port.h"
   51.34 +#include "interp.h"
   51.35 +
   51.36 +unsigned interp_mask[2];
   51.37 +unsigned interp_bits_per_pixel;
   51.38 +
   51.39 +/***************************************************************************/
   51.40 +/* HQ2x C implementation */
   51.41 +
   51.42 +/*
   51.43 + * This effect is a rewritten implementation of the hq2x effect made by Maxim Stepin
   51.44 + */
   51.45 +
   51.46 +static void hq2x_16_def(u16 *dst0, u16 *dst1, const u16 *src0, const u16 *src1, const u16 *src2, unsigned count)
   51.47 +{
   51.48 +	unsigned i;
   51.49 +
   51.50 +	for (i = 0; i < count; ++i)
   51.51 +	{
   51.52 +		unsigned char mask;
   51.53 +
   51.54 +		u16 c[9];
   51.55 +
   51.56 +		c[1] = src0[0];
   51.57 +		c[4] = src1[0];
   51.58 +		c[7] = src2[0];
   51.59 +
   51.60 +		if (i > 0)
   51.61 +		{
   51.62 +			c[0] = src0[-1];
   51.63 +			c[3] = src1[-1];
   51.64 +			c[6] = src2[-1];
   51.65 +		}
   51.66 +		else
   51.67 +		{
   51.68 +			c[0] = c[1];
   51.69 +			c[3] = c[4];
   51.70 +			c[6] = c[7];
   51.71 +		}
   51.72 +
   51.73 +		if (i < count - 1)
   51.74 +		{
   51.75 +			c[2] = src0[1];
   51.76 +			c[5] = src1[1];
   51.77 +			c[8] = src2[1];
   51.78 +		}
   51.79 +		else
   51.80 +		{
   51.81 +			c[2] = c[1];
   51.82 +			c[5] = c[4];
   51.83 +			c[8] = c[7];
   51.84 +		}
   51.85 +
   51.86 +		mask = 0;
   51.87 +
   51.88 +		if (interp_16_diff(c[0], c[4]))
   51.89 +			mask |= 1 << 0;
   51.90 +		if (interp_16_diff(c[1], c[4]))
   51.91 +			mask |= 1 << 1;
   51.92 +		if (interp_16_diff(c[2], c[4]))
   51.93 +			mask |= 1 << 2;
   51.94 +		if (interp_16_diff(c[3], c[4]))
   51.95 +			mask |= 1 << 3;
   51.96 +		if (interp_16_diff(c[5], c[4]))
   51.97 +			mask |= 1 << 4;
   51.98 +		if (interp_16_diff(c[6], c[4]))
   51.99 +			mask |= 1 << 5;
  51.100 +		if (interp_16_diff(c[7], c[4]))
  51.101 +			mask |= 1 << 6;
  51.102 +		if (interp_16_diff(c[8], c[4]))
  51.103 +			mask |= 1 << 7;
  51.104 +
  51.105 +#define P0 dst0[0]
  51.106 +#define P1 dst0[1]
  51.107 +#define P2 dst1[0]
  51.108 +#define P3 dst1[1]
  51.109 +#define MUR interp_16_diff(c[1], c[5]) // top-right
  51.110 +#define MDR interp_16_diff(c[5], c[7]) // bottom-right
  51.111 +#define MDL interp_16_diff(c[7], c[3]) // bottom-left
  51.112 +#define MUL interp_16_diff(c[3], c[1]) // top-left
  51.113 +#define IC(p0) c[p0]
  51.114 +#define I11(p0, p1) interp_16_11(c[p0], c[p1])
  51.115 +#define I211(p0, p1, p2) interp_16_211(c[p0], c[p1], c[p2])
  51.116 +#define I31(p0, p1) interp_16_31(c[p0], c[p1])
  51.117 +#define I332(p0, p1, p2) interp_16_332(c[p0], c[p1], c[p2])
  51.118 +#define I431(p0, p1, p2) interp_16_431(c[p0], c[p1], c[p2])
  51.119 +#define I521(p0, p1, p2) interp_16_521(c[p0], c[p1], c[p2])
  51.120 +#define I53(p0, p1) interp_16_53(c[p0], c[p1])
  51.121 +#define I611(p0, p1, p2) interp_16_611(c[p0], c[p1], c[p2])
  51.122 +#define I71(p0, p1) interp_16_71(c[p0], c[p1])
  51.123 +#define I772(p0, p1, p2) interp_16_772(c[p0], c[p1], c[p2])
  51.124 +#define I97(p0, p1) interp_16_97(c[p0], c[p1])
  51.125 +#define I1411(p0, p1, p2) interp_16_1411(c[p0], c[p1], c[p2])
  51.126 +#define I151(p0, p1) interp_16_151(c[p0], c[p1])
  51.127 +
  51.128 +		switch (mask)
  51.129 +		{
  51.130 +#include "hq2x.h"
  51.131 +		}
  51.132 +
  51.133 +#undef P0
  51.134 +#undef P1
  51.135 +#undef P2
  51.136 +#undef P3
  51.137 +#undef MUR
  51.138 +#undef MDR
  51.139 +#undef MDL
  51.140 +#undef MUL
  51.141 +#undef IC
  51.142 +#undef I11
  51.143 +#undef I211
  51.144 +#undef I31
  51.145 +#undef I332
  51.146 +#undef I431
  51.147 +#undef I521
  51.148 +#undef I53
  51.149 +#undef I611
  51.150 +#undef I71
  51.151 +#undef I772
  51.152 +#undef I97
  51.153 +#undef I1411
  51.154 +#undef I151
  51.155 +
  51.156 +		src0 += 1;
  51.157 +		src1 += 1;
  51.158 +		src2 += 1;
  51.159 +		dst0 += 2;
  51.160 +		dst1 += 2;
  51.161 +	}
  51.162 +}
  51.163 +
  51.164 +static void hq2x_32_def(u32 *dst0, u32 *dst1, const u32 *src0, const u32 *src1, const u32 *src2, unsigned count)
  51.165 +{
  51.166 +	unsigned i;
  51.167 +
  51.168 +	for (i = 0; i < count; ++i)
  51.169 +	{
  51.170 +		unsigned char mask;
  51.171 +
  51.172 +		u32 c[9];
  51.173 +
  51.174 +		c[1] = src0[0];
  51.175 +		c[4] = src1[0];
  51.176 +		c[7] = src2[0];
  51.177 +
  51.178 +		if (i > 0)
  51.179 +		{
  51.180 +			c[0] = src0[-1];
  51.181 +			c[3] = src1[-1];
  51.182 +			c[6] = src2[-1];
  51.183 +		}
  51.184 +		else
  51.185 +		{
  51.186 +			c[0] = c[1];
  51.187 +			c[3] = c[4];
  51.188 +			c[6] = c[7];
  51.189 +		}
  51.190 +
  51.191 +		if (i < count - 1)
  51.192 +		{
  51.193 +			c[2] = src0[1];
  51.194 +			c[5] = src1[1];
  51.195 +			c[8] = src2[1];
  51.196 +		}
  51.197 +		else
  51.198 +		{
  51.199 +			c[2] = c[1];
  51.200 +			c[5] = c[4];
  51.201 +			c[8] = c[7];
  51.202 +		}
  51.203 +
  51.204 +		mask = 0;
  51.205 +
  51.206 +		if (interp_32_diff(c[0], c[4]))
  51.207 +			mask |= 1 << 0;
  51.208 +		if (interp_32_diff(c[1], c[4]))
  51.209 +			mask |= 1 << 1;
  51.210 +		if (interp_32_diff(c[2], c[4]))
  51.211 +			mask |= 1 << 2;
  51.212 +		if (interp_32_diff(c[3], c[4]))
  51.213 +			mask |= 1 << 3;
  51.214 +		if (interp_32_diff(c[5], c[4]))
  51.215 +			mask |= 1 << 4;
  51.216 +		if (interp_32_diff(c[6], c[4]))
  51.217 +			mask |= 1 << 5;
  51.218 +		if (interp_32_diff(c[7], c[4]))
  51.219 +			mask |= 1 << 6;
  51.220 +		if (interp_32_diff(c[8], c[4]))
  51.221 +			mask |= 1 << 7;
  51.222 +
  51.223 +#define P0 dst0[0]
  51.224 +#define P1 dst0[1]
  51.225 +#define P2 dst1[0]
  51.226 +#define P3 dst1[1]
  51.227 +#define MUR interp_32_diff(c[1], c[5]) // top-right
  51.228 +#define MDR interp_32_diff(c[5], c[7]) // bottom-right
  51.229 +#define MDL interp_32_diff(c[7], c[3]) // bottom-left
  51.230 +#define MUL interp_32_diff(c[3], c[1]) // top-left
  51.231 +#define IC(p0) c[p0]
  51.232 +#define I11(p0, p1) interp_32_11(c[p0], c[p1])
  51.233 +#define I211(p0, p1, p2) interp_32_211(c[p0], c[p1], c[p2])
  51.234 +#define I31(p0, p1) interp_32_31(c[p0], c[p1])
  51.235 +#define I332(p0, p1, p2) interp_32_332(c[p0], c[p1], c[p2])
  51.236 +#define I431(p0, p1, p2) interp_32_431(c[p0], c[p1], c[p2])
  51.237 +#define I521(p0, p1, p2) interp_32_521(c[p0], c[p1], c[p2])
  51.238 +#define I53(p0, p1) interp_32_53(c[p0], c[p1])
  51.239 +#define I611(p0, p1, p2) interp_32_611(c[p0], c[p1], c[p2])
  51.240 +#define I71(p0, p1) interp_32_71(c[p0], c[p1])
  51.241 +#define I772(p0, p1, p2) interp_32_772(c[p0], c[p1], c[p2])
  51.242 +#define I97(p0, p1) interp_32_97(c[p0], c[p1])
  51.243 +#define I1411(p0, p1, p2) interp_32_1411(c[p0], c[p1], c[p2])
  51.244 +#define I151(p0, p1) interp_32_151(c[p0], c[p1])
  51.245 +
  51.246 +		switch (mask)
  51.247 +		{
  51.248 +#include "hq2x.h"
  51.249 +		}
  51.250 +
  51.251 +#undef P0
  51.252 +#undef P1
  51.253 +#undef P2
  51.254 +#undef P3
  51.255 +#undef MUR
  51.256 +#undef MDR
  51.257 +#undef MDL
  51.258 +#undef MUL
  51.259 +#undef IC
  51.260 +#undef I11
  51.261 +#undef I211
  51.262 +#undef I31
  51.263 +#undef I332
  51.264 +#undef I431
  51.265 +#undef I521
  51.266 +#undef I53
  51.267 +#undef I611
  51.268 +#undef I71
  51.269 +#undef I772
  51.270 +#undef I97
  51.271 +#undef I1411
  51.272 +#undef I151
  51.273 +
  51.274 +		src0 += 1;
  51.275 +		src1 += 1;
  51.276 +		src2 += 1;
  51.277 +		dst0 += 2;
  51.278 +		dst1 += 2;
  51.279 +	}
  51.280 +}
  51.281 +
  51.282 +/***************************************************************************/
  51.283 +/* HQ2xS C implementation */
  51.284 +
  51.285 +/*
  51.286 + * This effect is derived from the hq2x effect made by Maxim Stepin
  51.287 + */
  51.288 +
  51.289 +static void hq2xS_16_def(u16 *dst0, u16 *dst1, const u16 *src0, const u16 *src1, const u16 *src2, unsigned count)
  51.290 +{
  51.291 +	unsigned i;
  51.292 +
  51.293 +	for (i = 0; i < count; ++i)
  51.294 +	{
  51.295 +		unsigned char mask;
  51.296 +
  51.297 +		u16 c[9];
  51.298 +
  51.299 +		c[1] = src0[0];
  51.300 +		c[4] = src1[0];
  51.301 +		c[7] = src2[0];
  51.302 +
  51.303 +		c[0] = src0[-1];
  51.304 +		c[3] = src1[-1];
  51.305 +		c[6] = src2[-1];
  51.306 +
  51.307 +		c[2] = src0[1];
  51.308 +		c[5] = src1[1];
  51.309 +		c[8] = src2[1];
  51.310 +
  51.311 +		mask = 0;
  51.312 +
  51.313 +		// hq2xS dynamic edge detection:
  51.314 +		// simply comparing the center color against its surroundings will give bad results in many cases,
  51.315 +		// so, instead, compare the center color relative to the max difference in brightness of this 3x3 block
  51.316 +		int brightArray[9];
  51.317 +		int maxBright = 0, minBright = 999999;
  51.318 +		for (int j = 0; j < 9; j++)
  51.319 +		{
  51.320 +			int r, g, b;
  51.321 +			if (interp_bits_per_pixel == 16)
  51.322 +			{
  51.323 +				b = (int)((c[j] & 0x1F)) << 3;
  51.324 +				g = (int)((c[j] & 0x7E0)) >> 3;
  51.325 +				r = (int)((c[j] & 0xF800)) >> 8;
  51.326 +			}
  51.327 +			else
  51.328 +			{
  51.329 +				b = (int)((c[j] & 0x1F)) << 3;
  51.330 +				g = (int)((c[j] & 0x3E0)) >> 2;
  51.331 +				r = (int)((c[j] & 0x7C00)) >> 7;
  51.332 +			}
  51.333 +			const int bright = r + r + r + g + g + g + b + b;
  51.334 +			if (bright > maxBright) maxBright = bright;
  51.335 +			if (bright < minBright) minBright = bright;
  51.336 +
  51.337 +			brightArray[j] = bright;
  51.338 +		}
  51.339 +		int diffBright = ((maxBright - minBright) * 7) >> 4;
  51.340 +		if (diffBright > 7)
  51.341 +		{
  51.342 +		#define ABS(x) ((x) < 0 ? -(x) : (x))
  51.343 +
  51.344 +			const int centerBright = brightArray[4];
  51.345 +			if (ABS(brightArray[0] - centerBright) > diffBright)
  51.346 +				mask |= 1 << 0;
  51.347 +			if (ABS(brightArray[1] - centerBright) > diffBright)
  51.348 +				mask |= 1 << 1;
  51.349 +			if (ABS(brightArray[2] - centerBright) > diffBright)
  51.350 +				mask |= 1 << 2;
  51.351 +			if (ABS(brightArray[3] - centerBright) > diffBright)
  51.352 +				mask |= 1 << 3;
  51.353 +			if (ABS(brightArray[5] - centerBright) > diffBright)
  51.354 +				mask |= 1 << 4;
  51.355 +			if (ABS(brightArray[6] - centerBright) > diffBright)
  51.356 +				mask |= 1 << 5;
  51.357 +			if (ABS(brightArray[7] - centerBright) > diffBright)
  51.358 +				mask |= 1 << 6;
  51.359 +			if (ABS(brightArray[8] - centerBright) > diffBright)
  51.360 +				mask |= 1 << 7;
  51.361 +		}
  51.362 +
  51.363 +#define P0 dst0[0]
  51.364 +#define P1 dst0[1]
  51.365 +#define P2 dst1[0]
  51.366 +#define P3 dst1[1]
  51.367 +#define MUR false //(ABS(brightArray[1] - brightArray[5]) > diffBright) // top-right
  51.368 +#define MDR false //(ABS(brightArray[5] - brightArray[7]) > diffBright) // bottom-right
  51.369 +#define MDL false //(ABS(brightArray[7] - brightArray[3]) > diffBright) // bottom-left
  51.370 +#define MUL false //(ABS(brightArray[3] - brightArray[1]) > diffBright) // top-left
  51.371 +#define IC(p0) c[p0]
  51.372 +#define I11(p0, p1) interp_16_11(c[p0], c[p1])
  51.373 +#define I211(p0, p1, p2) interp_16_211(c[p0], c[p1], c[p2])
  51.374 +#define I31(p0, p1) interp_16_31(c[p0], c[p1])
  51.375 +#define I332(p0, p1, p2) interp_16_332(c[p0], c[p1], c[p2])
  51.376 +#define I431(p0, p1, p2) interp_16_431(c[p0], c[p1], c[p2])
  51.377 +#define I521(p0, p1, p2) interp_16_521(c[p0], c[p1], c[p2])
  51.378 +#define I53(p0, p1) interp_16_53(c[p0], c[p1])
  51.379 +#define I611(p0, p1, p2) interp_16_611(c[p0], c[p1], c[p2])
  51.380 +#define I71(p0, p1) interp_16_71(c[p0], c[p1])
  51.381 +#define I772(p0, p1, p2) interp_16_772(c[p0], c[p1], c[p2])
  51.382 +#define I97(p0, p1) interp_16_97(c[p0], c[p1])
  51.383 +#define I1411(p0, p1, p2) interp_16_1411(c[p0], c[p1], c[p2])
  51.384 +#define I151(p0, p1) interp_16_151(c[p0], c[p1])
  51.385 +
  51.386 +		switch (mask)
  51.387 +		{
  51.388 +#include "hq2x.h"
  51.389 +		}
  51.390 +
  51.391 +#undef P0
  51.392 +#undef P1
  51.393 +#undef P2
  51.394 +#undef P3
  51.395 +#undef MUR
  51.396 +#undef MDR
  51.397 +#undef MDL
  51.398 +#undef MUL
  51.399 +#undef IC
  51.400 +#undef I11
  51.401 +#undef I211
  51.402 +#undef I31
  51.403 +#undef I332
  51.404 +#undef I431
  51.405 +#undef I521
  51.406 +#undef I53
  51.407 +#undef I611
  51.408 +#undef I71
  51.409 +#undef I772
  51.410 +#undef I97
  51.411 +#undef I1411
  51.412 +#undef I151
  51.413 +
  51.414 +		src0 += 1;
  51.415 +		src1 += 1;
  51.416 +		src2 += 1;
  51.417 +		dst0 += 2;
  51.418 +		dst1 += 2;
  51.419 +	}
  51.420 +}
  51.421 +
  51.422 +static void hq2xS_32_def(u32 *dst0, u32 *dst1, const u32 *src0, const u32 *src1, const u32 *src2, unsigned count)
  51.423 +{
  51.424 +	unsigned i;
  51.425 +
  51.426 +	for (i = 0; i < count; ++i)
  51.427 +	{
  51.428 +		unsigned char mask;
  51.429 +
  51.430 +		u32 c[9];
  51.431 +
  51.432 +		c[1] = src0[0];
  51.433 +		c[4] = src1[0];
  51.434 +		c[7] = src2[0];
  51.435 +
  51.436 +		c[0] = src0[-1];
  51.437 +		c[3] = src1[-1];
  51.438 +		c[6] = src2[-1];
  51.439 +
  51.440 +		c[2] = src0[1];
  51.441 +		c[5] = src1[1];
  51.442 +		c[8] = src2[1];
  51.443 +
  51.444 +		mask = 0;
  51.445 +
  51.446 +		// hq2xS dynamic edge detection:
  51.447 +		// simply comparing the center color against its surroundings will give bad results in many cases,
  51.448 +		// so, instead, compare the center color relative to the max difference in brightness of this 3x3 block
  51.449 +		int brightArray[9];
  51.450 +		int maxBright = 0, minBright = 999999;
  51.451 +		for (int j = 0; j < 9; j++)
  51.452 +		{
  51.453 +			const int b		 = (int)((c[j] & 0xF8));
  51.454 +			const int g		 = (int)((c[j] & 0xF800)) >> 8;
  51.455 +			const int r		 = (int)((c[j] & 0xF80000)) >> 16;
  51.456 +			const int bright = r + r + r + g + g + g + b + b;
  51.457 +			if (bright > maxBright) maxBright = bright;
  51.458 +			if (bright < minBright) minBright = bright;
  51.459 +
  51.460 +			brightArray[j] = bright;
  51.461 +		}
  51.462 +		int diffBright = ((maxBright - minBright) * 7) >> 4;
  51.463 +		if (diffBright > 7)
  51.464 +		{
  51.465 +		#define ABS(x) ((x) < 0 ? -(x) : (x))
  51.466 +
  51.467 +			const int centerBright = brightArray[4];
  51.468 +			if (ABS(brightArray[0] - centerBright) > diffBright)
  51.469 +				mask |= 1 << 0;
  51.470 +			if (ABS(brightArray[1] - centerBright) > diffBright)
  51.471 +				mask |= 1 << 1;
  51.472 +			if (ABS(brightArray[2] - centerBright) > diffBright)
  51.473 +				mask |= 1 << 2;
  51.474 +			if (ABS(brightArray[3] - centerBright) > diffBright)
  51.475 +				mask |= 1 << 3;
  51.476 +			if (ABS(brightArray[5] - centerBright) > diffBright)
  51.477 +				mask |= 1 << 4;
  51.478 +			if (ABS(brightArray[6] - centerBright) > diffBright)
  51.479 +				mask |= 1 << 5;
  51.480 +			if (ABS(brightArray[7] - centerBright) > diffBright)
  51.481 +				mask |= 1 << 6;
  51.482 +			if (ABS(brightArray[8] - centerBright) > diffBright)
  51.483 +				mask |= 1 << 7;
  51.484 +		}
  51.485 +
  51.486 +#define P0 dst0[0]
  51.487 +#define P1 dst0[1]
  51.488 +#define P2 dst1[0]
  51.489 +#define P3 dst1[1]
  51.490 +#define MUR false //(ABS(brightArray[1] - brightArray[5]) > diffBright) // top-right
  51.491 +#define MDR false //(ABS(brightArray[5] - brightArray[7]) > diffBright) // bottom-right
  51.492 +#define MDL false //(ABS(brightArray[7] - brightArray[3]) > diffBright) // bottom-left
  51.493 +#define MUL false //(ABS(brightArray[3] - brightArray[1]) > diffBright) // top-left
  51.494 +#define IC(p0) c[p0]
  51.495 +#define I11(p0, p1) interp_32_11(c[p0], c[p1])
  51.496 +#define I211(p0, p1, p2) interp_32_211(c[p0], c[p1], c[p2])
  51.497 +#define I31(p0, p1) interp_32_31(c[p0], c[p1])
  51.498 +#define I332(p0, p1, p2) interp_32_332(c[p0], c[p1], c[p2])
  51.499 +#define I431(p0, p1, p2) interp_32_431(c[p0], c[p1], c[p2])
  51.500 +#define I521(p0, p1, p2) interp_32_521(c[p0], c[p1], c[p2])
  51.501 +#define I53(p0, p1) interp_32_53(c[p0], c[p1])
  51.502 +#define I611(p0, p1, p2) interp_32_611(c[p0], c[p1], c[p2])
  51.503 +#define I71(p0, p1) interp_32_71(c[p0], c[p1])
  51.504 +#define I772(p0, p1, p2) interp_32_772(c[p0], c[p1], c[p2])
  51.505 +#define I97(p0, p1) interp_32_97(c[p0], c[p1])
  51.506 +#define I1411(p0, p1, p2) interp_32_1411(c[p0], c[p1], c[p2])
  51.507 +#define I151(p0, p1) interp_32_151(c[p0], c[p1])
  51.508 +
  51.509 +		switch (mask)
  51.510 +		{
  51.511 +#include "hq2x.h"
  51.512 +		}
  51.513 +
  51.514 +#undef P0
  51.515 +#undef P1
  51.516 +#undef P2
  51.517 +#undef P3
  51.518 +#undef MUR
  51.519 +#undef MDR
  51.520 +#undef MDL
  51.521 +#undef MUL
  51.522 +#undef IC
  51.523 +#undef I11
  51.524 +#undef I211
  51.525 +#undef I31
  51.526 +#undef I332
  51.527 +#undef I431
  51.528 +#undef I521
  51.529 +#undef I53
  51.530 +#undef I611
  51.531 +#undef I71
  51.532 +#undef I772
  51.533 +#undef I97
  51.534 +#undef I1411
  51.535 +#undef I151
  51.536 +
  51.537 +		src0 += 1;
  51.538 +		src1 += 1;
  51.539 +		src2 += 1;
  51.540 +		dst0 += 2;
  51.541 +		dst1 += 2;
  51.542 +	}
  51.543 +}
  51.544 +
  51.545 +/***************************************************************************/
  51.546 +/* LQ2x C implementation */
  51.547 +
  51.548 +/*
  51.549 + * This effect is derived from the hq2x effect made by Maxim Stepin
  51.550 + */
  51.551 +
  51.552 +static void lq2x_16_def(u16 *dst0, u16 *dst1, const u16 *src0, const u16 *src1, const u16 *src2, unsigned count)
  51.553 +{
  51.554 +	unsigned i;
  51.555 +
  51.556 +	for (i = 0; i < count; ++i)
  51.557 +	{
  51.558 +		unsigned char mask;
  51.559 +
  51.560 +		u16 c[9];
  51.561 +
  51.562 +		c[1] = src0[0];
  51.563 +		c[4] = src1[0];
  51.564 +		c[7] = src2[0];
  51.565 +
  51.566 +		if (i > 0)
  51.567 +		{
  51.568 +			c[0] = src0[-1];
  51.569 +			c[3] = src1[-1];
  51.570 +			c[6] = src2[-1];
  51.571 +		}
  51.572 +		else
  51.573 +		{
  51.574 +			c[0] = c[1];
  51.575 +			c[3] = c[4];
  51.576 +			c[6] = c[7];
  51.577 +		}
  51.578 +
  51.579 +		if (i < count - 1)
  51.580 +		{
  51.581 +			c[2] = src0[1];
  51.582 +			c[5] = src1[1];
  51.583 +			c[8] = src2[1];
  51.584 +		}
  51.585 +		else
  51.586 +		{
  51.587 +			c[2] = c[1];
  51.588 +			c[5] = c[4];
  51.589 +			c[8] = c[7];
  51.590 +		}
  51.591 +
  51.592 +		mask = 0;
  51.593 +
  51.594 +		if (c[0] != c[4])
  51.595 +			mask |= 1 << 0;
  51.596 +		if (c[1] != c[4])
  51.597 +			mask |= 1 << 1;
  51.598 +		if (c[2] != c[4])
  51.599 +			mask |= 1 << 2;
  51.600 +		if (c[3] != c[4])
  51.601 +			mask |= 1 << 3;
  51.602 +		if (c[5] != c[4])
  51.603 +			mask |= 1 << 4;
  51.604 +		if (c[6] != c[4])
  51.605 +			mask |= 1 << 5;
  51.606 +		if (c[7] != c[4])
  51.607 +			mask |= 1 << 6;
  51.608 +		if (c[8] != c[4])
  51.609 +			mask |= 1 << 7;
  51.610 +
  51.611 +#define P0 dst0[0]
  51.612 +#define P1 dst0[1]
  51.613 +#define P2 dst1[0]
  51.614 +#define P3 dst1[1]
  51.615 +#define MUR (c[1] != c[5])
  51.616 +#define MDR (c[5] != c[7])
  51.617 +#define MDL (c[7] != c[3])
  51.618 +#define MUL (c[3] != c[1])
  51.619 +#define IC(p0) c[p0]
  51.620 +#define I11(p0, p1) interp_16_11(c[p0], c[p1])
  51.621 +#define I211(p0, p1, p2) interp_16_211(c[p0], c[p1], c[p2])
  51.622 +#define I31(p0, p1) interp_16_31(c[p0], c[p1])
  51.623 +#define I332(p0, p1, p2) interp_16_332(c[p0], c[p1], c[p2])
  51.624 +#define I431(p0, p1, p2) interp_16_431(c[p0], c[p1], c[p2])
  51.625 +#define I521(p0, p1, p2) interp_16_521(c[p0], c[p1], c[p2])
  51.626 +#define I53(p0, p1) interp_16_53(c[p0], c[p1])
  51.627 +#define I611(p0, p1, p2) interp_16_611(c[p0], c[p1], c[p2])
  51.628 +#define I71(p0, p1) interp_16_71(c[p0], c[p1])
  51.629 +#define I772(p0, p1, p2) interp_16_772(c[p0], c[p1], c[p2])
  51.630 +#define I97(p0, p1) interp_16_97(c[p0], c[p1])
  51.631 +#define I1411(p0, p1, p2) interp_16_1411(c[p0], c[p1], c[p2])
  51.632 +#define I151(p0, p1) interp_16_151(c[p0], c[p1])
  51.633 +
  51.634 +		switch (mask)
  51.635 +		{
  51.636 +#include "lq2x.h"
  51.637 +		}
  51.638 +
  51.639 +#undef P0
  51.640 +#undef P1
  51.641 +#undef P2
  51.642 +#undef P3
  51.643 +#undef MUR
  51.644 +#undef MDR
  51.645 +#undef MDL
  51.646 +#undef MUL
  51.647 +#undef IC
  51.648 +#undef I11
  51.649 +#undef I211
  51.650 +#undef I31
  51.651 +#undef I332
  51.652 +#undef I431
  51.653 +#undef I521
  51.654 +#undef I53
  51.655 +#undef I611
  51.656 +#undef I71
  51.657 +#undef I772
  51.658 +#undef I97
  51.659 +#undef I1411
  51.660 +#undef I151
  51.661 +
  51.662 +		src0 += 1;
  51.663 +		src1 += 1;
  51.664 +		src2 += 1;
  51.665 +		dst0 += 2;
  51.666 +		dst1 += 2;
  51.667 +	}
  51.668 +}
  51.669 +
  51.670 +static void lq2x_32_def(u32 *dst0, u32 *dst1, const u32 *src0, const u32 *src1, const u32 *src2, unsigned count)
  51.671 +{
  51.672 +	unsigned i;
  51.673 +
  51.674 +	for (i = 0; i < count; ++i)
  51.675 +	{
  51.676 +		unsigned char mask;
  51.677 +
  51.678 +		u32 c[9];
  51.679 +
  51.680 +		c[1] = src0[0];
  51.681 +		c[4] = src1[0];
  51.682 +		c[7] = src2[0];
  51.683 +
  51.684 +		if (i > 0)
  51.685 +		{
  51.686 +			c[0] = src0[-1];
  51.687 +			c[3] = src1[-1];
  51.688 +			c[6] = src2[-1];
  51.689 +		}
  51.690 +		else
  51.691 +		{
  51.692 +			c[0] = c[1];
  51.693 +			c[3] = c[4];
  51.694 +			c[6] = c[7];
  51.695 +		}
  51.696 +
  51.697 +		if (i < count - 1)
  51.698 +		{
  51.699 +			c[2] = src0[1];
  51.700 +			c[5] = src1[1];
  51.701 +			c[8] = src2[1];
  51.702 +		}
  51.703 +		else
  51.704 +		{
  51.705 +			c[2] = c[1];
  51.706 +			c[5] = c[4];
  51.707 +			c[8] = c[7];
  51.708 +		}
  51.709 +
  51.710 +		mask = 0;
  51.711 +
  51.712 +		if (c[0] != c[4])
  51.713 +			mask |= 1 << 0;
  51.714 +		if (c[1] != c[4])
  51.715 +			mask |= 1 << 1;
  51.716 +		if (c[2] != c[4])
  51.717 +			mask |= 1 << 2;
  51.718 +		if (c[3] != c[4])
  51.719 +			mask |= 1 << 3;
  51.720 +		if (c[5] != c[4])
  51.721 +			mask |= 1 << 4;
  51.722 +		if (c[6] != c[4])
  51.723 +			mask |= 1 << 5;
  51.724 +		if (c[7] != c[4])
  51.725 +			mask |= 1 << 6;
  51.726 +		if (c[8] != c[4])
  51.727 +			mask |= 1 << 7;
  51.728 +
  51.729 +#define P0 dst0[0]
  51.730 +#define P1 dst0[1]
  51.731 +#define P2 dst1[0]
  51.732 +#define P3 dst1[1]
  51.733 +#define MUR (c[1] != c[5])
  51.734 +#define MDR (c[5] != c[7])
  51.735 +#define MDL (c[7] != c[3])
  51.736 +#define MUL (c[3] != c[1])
  51.737 +#define IC(p0) c[p0]
  51.738 +#define I11(p0, p1) interp_32_11(c[p0], c[p1])
  51.739 +#define I211(p0, p1, p2) interp_32_211(c[p0], c[p1], c[p2])
  51.740 +#define I31(p0, p1) interp_32_31(c[p0], c[p1])
  51.741 +#define I332(p0, p1, p2) interp_32_332(c[p0], c[p1], c[p2])
  51.742 +#define I431(p0, p1, p2) interp_32_431(c[p0], c[p1], c[p2])
  51.743 +#define I521(p0, p1, p2) interp_32_521(c[p0], c[p1], c[p2])
  51.744 +#define I53(p0, p1) interp_32_53(c[p0], c[p1])
  51.745 +#define I611(p0, p1, p2) interp_32_611(c[p0], c[p1], c[p2])
  51.746 +#define I71(p0, p1) interp_32_71(c[p0], c[p1])
  51.747 +#define I772(p0, p1, p2) interp_32_772(c[p0], c[p1], c[p2])
  51.748 +#define I97(p0, p1) interp_32_97(c[p0], c[p1])
  51.749 +#define I1411(p0, p1, p2) interp_32_1411(c[p0], c[p1], c[p2])
  51.750 +#define I151(p0, p1) interp_32_151(c[p0], c[p1])
  51.751 +
  51.752 +		switch (mask)
  51.753 +		{
  51.754 +#include "lq2x.h"
  51.755 +		}
  51.756 +
  51.757 +#undef P0
  51.758 +#undef P1
  51.759 +#undef P2
  51.760 +#undef P3
  51.761 +#undef MUR
  51.762 +#undef MDR
  51.763 +#undef MDL
  51.764 +#undef MUL
  51.765 +#undef IC
  51.766 +#undef I11
  51.767 +#undef I211
  51.768 +#undef I31
  51.769 +#undef I332
  51.770 +#undef I431
  51.771 +#undef I521
  51.772 +#undef I53
  51.773 +#undef I611
  51.774 +#undef I71
  51.775 +#undef I772
  51.776 +#undef I97
  51.777 +#undef I1411
  51.778 +#undef I151
  51.779 +
  51.780 +		src0 += 1;
  51.781 +		src1 += 1;
  51.782 +		src2 += 1;
  51.783 +		dst0 += 2;
  51.784 +		dst1 += 2;
  51.785 +	}
  51.786 +}
  51.787 +
  51.788 +void hq2x(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  51.789 +          u8 *dstPtr, u32 dstPitch, int width, int height)
  51.790 +{
  51.791 +	u16 *dst0 = (u16 *)dstPtr;
  51.792 +	u16 *dst1 = dst0 + (dstPitch >> 1);
  51.793 +
  51.794 +	u16 *src0 = (u16 *)srcPtr;
  51.795 +	u16 *src1 = src0 + (srcPitch >> 1);
  51.796 +	u16 *src2 = src1 + (srcPitch >> 1);
  51.797 +
  51.798 +	hq2x_16_def(dst0, dst1, src0, src0, src1, width);
  51.799 +
  51.800 +	int count = height;
  51.801 +
  51.802 +	count -= 2;
  51.803 +	while (count)
  51.804 +	{
  51.805 +		dst0 += dstPitch;
  51.806 +		dst1 += dstPitch;
  51.807 +		hq2x_16_def(dst0, dst1, src0, src1, src2, width);
  51.808 +		src0  = src1;
  51.809 +		src1  = src2;
  51.810 +		src2 += srcPitch >> 1;
  51.811 +		--count;
  51.812 +	}
  51.813 +	dst0 += dstPitch;
  51.814 +	dst1 += dstPitch;
  51.815 +	hq2x_16_def(dst0, dst1, src0, src1, src1, width);
  51.816 +}
  51.817 +
  51.818 +void hq2x32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  51.819 +            u8 *dstPtr, u32 dstPitch, int width, int height)
  51.820 +{
  51.821 +	u32 *dst0 = (u32 *)dstPtr;
  51.822 +	u32 *dst1 = dst0 + (dstPitch >> 2);
  51.823 +
  51.824 +	u32 *src0 = (u32 *)srcPtr;
  51.825 +	u32 *src1 = src0 + (srcPitch >> 2);
  51.826 +	u32 *src2 = src1 + (srcPitch >> 2);
  51.827 +	hq2x_32_def(dst0, dst1, src0, src0, src1, width);
  51.828 +
  51.829 +	int count = height;
  51.830 +
  51.831 +	count -= 2;
  51.832 +	while (count)
  51.833 +	{
  51.834 +		dst0 += dstPitch >> 1;
  51.835 +		dst1 += dstPitch >> 1;
  51.836 +		hq2x_32_def(dst0, dst1, src0, src1, src2, width);
  51.837 +		src0  = src1;
  51.838 +		src1  = src2;
  51.839 +		src2 += srcPitch >> 2;
  51.840 +		--count;
  51.841 +	}
  51.842 +	dst0 += dstPitch >> 1;
  51.843 +	dst1 += dstPitch >> 1;
  51.844 +	hq2x_32_def(dst0, dst1, src0, src1, src1, width);
  51.845 +}
  51.846 +
  51.847 +void hq2xS(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  51.848 +           u8 *dstPtr, u32 dstPitch, int width, int height)
  51.849 +{
  51.850 +	u16 *dst0 = (u16 *)dstPtr;
  51.851 +	u16 *dst1 = dst0 + (dstPitch >> 1);
  51.852 +
  51.853 +	u16 *src0 = (u16 *)srcPtr;
  51.854 +	u16 *src1 = src0 + (srcPitch >> 1);
  51.855 +	u16 *src2 = src1 + (srcPitch >> 1);
  51.856 +
  51.857 +	hq2xS_16_def(dst0, dst1, src0, src0, src1, width);
  51.858 +
  51.859 +	int count = height;
  51.860 +
  51.861 +	count -= 2;
  51.862 +	while (count)
  51.863 +	{
  51.864 +		dst0 += dstPitch;
  51.865 +		dst1 += dstPitch;
  51.866 +		hq2xS_16_def(dst0, dst1, src0, src1, src2, width);
  51.867 +		src0  = src1;
  51.868 +		src1  = src2;
  51.869 +		src2 += srcPitch >> 1;
  51.870 +		--count;
  51.871 +	}
  51.872 +	dst0 += dstPitch;
  51.873 +	dst1 += dstPitch;
  51.874 +	hq2xS_16_def(dst0, dst1, src0, src1, src1, width);
  51.875 +}
  51.876 +
  51.877 +void hq2xS32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  51.878 +             u8 *dstPtr, u32 dstPitch, int width, int height)
  51.879 +{
  51.880 +	u32 *dst0 = (u32 *)dstPtr;
  51.881 +	u32 *dst1 = dst0 + (dstPitch >> 2);
  51.882 +
  51.883 +	u32 *src0 = (u32 *)srcPtr;
  51.884 +	u32 *src1 = src0 + (srcPitch >> 2);
  51.885 +	u32 *src2 = src1 + (srcPitch >> 2);
  51.886 +	hq2xS_32_def(dst0, dst1, src0, src0, src1, width);
  51.887 +
  51.888 +	int count = height;
  51.889 +
  51.890 +	count -= 2;
  51.891 +	while (count)
  51.892 +	{
  51.893 +		dst0 += dstPitch >> 1;
  51.894 +		dst1 += dstPitch >> 1;
  51.895 +		hq2xS_32_def(dst0, dst1, src0, src1, src2, width);
  51.896 +		src0  = src1;
  51.897 +		src1  = src2;
  51.898 +		src2 += srcPitch >> 2;
  51.899 +		--count;
  51.900 +	}
  51.901 +	dst0 += dstPitch >> 1;
  51.902 +	dst1 += dstPitch >> 1;
  51.903 +	hq2xS_32_def(dst0, dst1, src0, src1, src1, width);
  51.904 +}
  51.905 +
  51.906 +void lq2x(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  51.907 +          u8 *dstPtr, u32 dstPitch, int width, int height)
  51.908 +{
  51.909 +	u16 *dst0 = (u16 *)dstPtr;
  51.910 +	u16 *dst1 = dst0 + (dstPitch >> 1);
  51.911 +
  51.912 +	u16 *src0 = (u16 *)srcPtr;
  51.913 +	u16 *src1 = src0 + (srcPitch >> 1);
  51.914 +	u16 *src2 = src1 + (srcPitch >> 1);
  51.915 +
  51.916 +	lq2x_16_def(dst0, dst1, src0, src0, src1, width);
  51.917 +
  51.918 +	int count = height;
  51.919 +
  51.920 +	count -= 2;
  51.921 +	while (count)
  51.922 +	{
  51.923 +		dst0 += dstPitch;
  51.924 +		dst1 += dstPitch;
  51.925 +		lq2x_16_def(dst0, dst1, src0, src1, src2, width);
  51.926 +		src0  = src1;
  51.927 +		src1  = src2;
  51.928 +		src2 += srcPitch >> 1;
  51.929 +		--count;
  51.930 +	}
  51.931 +	dst0 += dstPitch;
  51.932 +	dst1 += dstPitch;
  51.933 +	lq2x_16_def(dst0, dst1, src0, src1, src1, width);
  51.934 +}
  51.935 +
  51.936 +void lq2x32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  51.937 +            u8 *dstPtr, u32 dstPitch, int width, int height)
  51.938 +{
  51.939 +	u32 *dst0 = (u32 *)dstPtr;
  51.940 +	u32 *dst1 = dst0 + (dstPitch >> 2);
  51.941 +
  51.942 +	u32 *src0 = (u32 *)srcPtr;
  51.943 +	u32 *src1 = src0 + (srcPitch >> 2);
  51.944 +	u32 *src2 = src1 + (srcPitch >> 2);
  51.945 +	lq2x_32_def(dst0, dst1, src0, src0, src1, width);
  51.946 +
  51.947 +	int count = height;
  51.948 +
  51.949 +	count -= 2;
  51.950 +	while (count)
  51.951 +	{
  51.952 +		dst0 += dstPitch >> 1;
  51.953 +		dst1 += dstPitch >> 1;
  51.954 +		lq2x_32_def(dst0, dst1, src0, src1, src2, width);
  51.955 +		src0  = src1;
  51.956 +		src1  = src2;
  51.957 +		src2 += srcPitch >> 2;
  51.958 +		--count;
  51.959 +	}
  51.960 +	dst0 += dstPitch >> 1;
  51.961 +	dst1 += dstPitch >> 1;
  51.962 +	lq2x_32_def(dst0, dst1, src0, src1, src1, width);
  51.963 +}
  51.964 +
  51.965 +void hq2x_init(unsigned bits_per_pixel)
  51.966 +{
  51.967 +	interp_set(bits_per_pixel);
  51.968 +}
  51.969 +
    52.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.2 +++ b/src/filters/hq2x.h	Sat Mar 03 10:31:27 2012 -0600
    52.3 @@ -0,0 +1,1824 @@
    52.4 +case 0 : 
    52.5 +case 1 : 
    52.6 +case 4 : 
    52.7 +case 5 : 
    52.8 +case 32 : 
    52.9 +case 33 : 
   52.10 +case 36 : 
   52.11 +case 37 : 
   52.12 +case 128 : 
   52.13 +case 129 : 
   52.14 +case 132 : 
   52.15 +case 133 : 
   52.16 +case 160 : 
   52.17 +case 161 : 
   52.18 +case 164 : 
   52.19 +case 165 : 
   52.20 +{
   52.21 +  P0 = I211(4, 1, 3);
   52.22 +  P1 = I211(4, 1, 5);
   52.23 +  P2 = I211(4, 3, 7);
   52.24 +  P3 = I211(4, 5, 7);
   52.25 +} break;
   52.26 +case 2 : 
   52.27 +case 34 : 
   52.28 +case 130 : 
   52.29 +case 162 : 
   52.30 +{
   52.31 +  P0 = I31(4, 0);
   52.32 +  P1 = I31(4, 2);
   52.33 +  P2 = I211(4, 3, 7);
   52.34 +  P3 = I211(4, 5, 7);
   52.35 +} break;
   52.36 +case 3 : 
   52.37 +case 35 : 
   52.38 +case 131 : 
   52.39 +case 163 : 
   52.40 +{
   52.41 +  P0 = I31(4, 3);
   52.42 +  P1 = I31(4, 2);
   52.43 +  P2 = I211(4, 3, 7);
   52.44 +  P3 = I211(4, 5, 7);
   52.45 +} break;
   52.46 +case 6 : 
   52.47 +case 38 : 
   52.48 +case 134 : 
   52.49 +case 166 : 
   52.50 +{
   52.51 +  P0 = I31(4, 0);
   52.52 +  P1 = I31(4, 5);
   52.53 +  P2 = I211(4, 3, 7);
   52.54 +  P3 = I211(4, 5, 7);
   52.55 +} break;
   52.56 +case 7 : 
   52.57 +case 39 : 
   52.58 +case 135 : 
   52.59 +case 167 : 
   52.60 +{
   52.61 +  P0 = I31(4, 3);
   52.62 +  P1 = I31(4, 5);
   52.63 +  P2 = I211(4, 3, 7);
   52.64 +  P3 = I211(4, 5, 7);
   52.65 +} break;
   52.66 +case 8 : 
   52.67 +case 12 : 
   52.68 +case 136 : 
   52.69 +case 140 : 
   52.70 +{
   52.71 +  P0 = I31(4, 0);
   52.72 +  P1 = I211(4, 1, 5);
   52.73 +  P2 = I31(4, 6);
   52.74 +  P3 = I211(4, 5, 7);
   52.75 +} break;
   52.76 +case 9 : 
   52.77 +case 13 : 
   52.78 +case 137 : 
   52.79 +case 141 : 
   52.80 +{
   52.81 +  P0 = I31(4, 1);
   52.82 +  P1 = I211(4, 1, 5);
   52.83 +  P2 = I31(4, 6);
   52.84 +  P3 = I211(4, 5, 7);
   52.85 +} break;
   52.86 +case 10 : 
   52.87 +case 138 : 
   52.88 +{
   52.89 +  P1 = I31(4, 2);
   52.90 +  P2 = I31(4, 6);
   52.91 +  P3 = I211(4, 5, 7);
   52.92 +  if (MUL) {
   52.93 +    P0 = I31(4, 0);
   52.94 +  } else {
   52.95 +    P0 = I211(4, 1, 3);
   52.96 +  }
   52.97 +} break;
   52.98 +case 11 : 
   52.99 +case 139 : 
  52.100 +{
  52.101 +  P1 = I31(4, 2);
  52.102 +  P2 = I31(4, 6);
  52.103 +  P3 = I211(4, 5, 7);
  52.104 +  if (MUL) {
  52.105 +    P0 = IC(4);
  52.106 +  } else {
  52.107 +    P0 = I211(4, 1, 3);
  52.108 +  }
  52.109 +} break;
  52.110 +case 14 : 
  52.111 +case 142 : 
  52.112 +{
  52.113 +  P2 = I31(4, 6);
  52.114 +  P3 = I211(4, 5, 7);
  52.115 +  if (MUL) {
  52.116 +    P0 = I31(4, 0);
  52.117 +    P1 = I31(4, 5);
  52.118 +  } else {
  52.119 +    P0 = I332(1, 3, 4);
  52.120 +    P1 = I521(4, 1, 5);
  52.121 +  }
  52.122 +} break;
  52.123 +case 15 : 
  52.124 +case 143 : 
  52.125 +{
  52.126 +  P2 = I31(4, 6);
  52.127 +  P3 = I211(4, 5, 7);
  52.128 +  if (MUL) {
  52.129 +    P0 = IC(4);
  52.130 +    P1 = I31(4, 5);
  52.131 +  } else {
  52.132 +    P0 = I332(1, 3, 4);
  52.133 +    P1 = I521(4, 1, 5);
  52.134 +  }
  52.135 +} break;
  52.136 +case 16 : 
  52.137 +case 17 : 
  52.138 +case 48 : 
  52.139 +case 49 : 
  52.140 +{
  52.141 +  P0 = I211(4, 1, 3);
  52.142 +  P1 = I31(4, 2);
  52.143 +  P2 = I211(4, 3, 7);
  52.144 +  P3 = I31(4, 8);
  52.145 +} break;
  52.146 +case 18 : 
  52.147 +case 50 : 
  52.148 +{
  52.149 +  P0 = I31(4, 0);
  52.150 +  P2 = I211(4, 3, 7);
  52.151 +  P3 = I31(4, 8);
  52.152 +  if (MUR) {
  52.153 +    P1 = I31(4, 2);
  52.154 +  } else {
  52.155 +    P1 = I211(4, 1, 5);
  52.156 +  }
  52.157 +} break;
  52.158 +case 19 : 
  52.159 +case 51 : 
  52.160 +{
  52.161 +  P2 = I211(4, 3, 7);
  52.162 +  P3 = I31(4, 8);
  52.163 +  if (MUR) {
  52.164 +    P0 = I31(4, 3);
  52.165 +    P1 = I31(4, 2);
  52.166 +  } else {
  52.167 +    P0 = I521(4, 1, 3);
  52.168 +    P1 = I332(1, 5, 4);
  52.169 +  }
  52.170 +} break;
  52.171 +case 20 : 
  52.172 +case 21 : 
  52.173 +case 52 : 
  52.174 +case 53 : 
  52.175 +{
  52.176 +  P0 = I211(4, 1, 3);
  52.177 +  P1 = I31(4, 1);
  52.178 +  P2 = I211(4, 3, 7);
  52.179 +  P3 = I31(4, 8);
  52.180 +} break;
  52.181 +case 22 : 
  52.182 +case 54 : 
  52.183 +{
  52.184 +  P0 = I31(4, 0);
  52.185 +  P2 = I211(4, 3, 7);
  52.186 +  P3 = I31(4, 8);
  52.187 +  if (MUR) {
  52.188 +    P1 = IC(4);
  52.189 +  } else {
  52.190 +    P1 = I211(4, 1, 5);
  52.191 +  }
  52.192 +} break;
  52.193 +case 23 : 
  52.194 +case 55 : 
  52.195 +{
  52.196 +  P2 = I211(4, 3, 7);
  52.197 +  P3 = I31(4, 8);
  52.198 +  if (MUR) {
  52.199 +    P0 = I31(4, 3);
  52.200 +    P1 = IC(4);
  52.201 +  } else {
  52.202 +    P0 = I521(4, 1, 3);
  52.203 +    P1 = I332(1, 5, 4);
  52.204 +  }
  52.205 +} break;
  52.206 +case 24 : 
  52.207 +case 66 : 
  52.208 +{
  52.209 +  P0 = I31(4, 0);
  52.210 +  P1 = I31(4, 2);
  52.211 +  P2 = I31(4, 6);
  52.212 +  P3 = I31(4, 8);
  52.213 +} break;
  52.214 +case 25 : 
  52.215 +{
  52.216 +  P0 = I31(4, 1);
  52.217 +  P1 = I31(4, 2);
  52.218 +  P2 = I31(4, 6);
  52.219 +  P3 = I31(4, 8);
  52.220 +} break;
  52.221 +case 26 : 
  52.222 +case 31 : 
  52.223 +case 95 : 
  52.224 +{
  52.225 +  P2 = I31(4, 6);
  52.226 +  P3 = I31(4, 8);
  52.227 +  if (MUL) {
  52.228 +    P0 = IC(4);
  52.229 +  } else {
  52.230 +    P0 = I211(4, 1, 3);
  52.231 +  }
  52.232 +  if (MUR) {
  52.233 +    P1 = IC(4);
  52.234 +  } else {
  52.235 +    P1 = I211(4, 1, 5);
  52.236 +  }
  52.237 +} break;
  52.238 +case 27 : 
  52.239 +case 75 : 
  52.240 +{
  52.241 +  P1 = I31(4, 2);
  52.242 +  P2 = I31(4, 6);
  52.243 +  P3 = I31(4, 8);
  52.244 +  if (MUL) {
  52.245 +    P0 = IC(4);
  52.246 +  } else {
  52.247 +    P0 = I211(4, 1, 3);
  52.248 +  }
  52.249 +} break;
  52.250 +case 28 : 
  52.251 +{
  52.252 +  P0 = I31(4, 0);
  52.253 +  P1 = I31(4, 1);
  52.254 +  P2 = I31(4, 6);
  52.255 +  P3 = I31(4, 8);
  52.256 +} break;
  52.257 +case 29 : 
  52.258 +{
  52.259 +  P0 = I31(4, 1);
  52.260 +  P1 = I31(4, 1);
  52.261 +  P2 = I31(4, 6);
  52.262 +  P3 = I31(4, 8);
  52.263 +} break;
  52.264 +case 30 : 
  52.265 +case 86 : 
  52.266 +{
  52.267 +  P0 = I31(4, 0);
  52.268 +  P2 = I31(4, 6);
  52.269 +  P3 = I31(4, 8);
  52.270 +  if (MUR) {
  52.271 +    P1 = IC(4);
  52.272 +  } else {
  52.273 +    P1 = I211(4, 1, 5);
  52.274 +  }
  52.275 +} break;
  52.276 +case 40 : 
  52.277 +case 44 : 
  52.278 +case 168 : 
  52.279 +case 172 : 
  52.280 +{
  52.281 +  P0 = I31(4, 0);
  52.282 +  P1 = I211(4, 1, 5);
  52.283 +  P2 = I31(4, 7);
  52.284 +  P3 = I211(4, 5, 7);
  52.285 +} break;
  52.286 +case 41 : 
  52.287 +case 45 : 
  52.288 +case 169 : 
  52.289 +case 173 : 
  52.290 +{
  52.291 +  P0 = I31(4, 1);
  52.292 +  P1 = I211(4, 1, 5);
  52.293 +  P2 = I31(4, 7);
  52.294 +  P3 = I211(4, 5, 7);
  52.295 +} break;
  52.296 +case 42 : 
  52.297 +case 170 : 
  52.298 +{
  52.299 +  P1 = I31(4, 2);
  52.300 +  P3 = I211(4, 5, 7);
  52.301 +  if (MUL) {
  52.302 +    P0 = I31(4, 0);
  52.303 +    P2 = I31(4, 7);
  52.304 +  } else {
  52.305 +    P0 = I332(1, 3, 4);
  52.306 +    P2 = I521(4, 3, 7);
  52.307 +  }
  52.308 +} break;
  52.309 +case 43 : 
  52.310 +case 171 : 
  52.311 +{
  52.312 +  P1 = I31(4, 2);
  52.313 +  P3 = I211(4, 5, 7);
  52.314 +  if (MUL) {
  52.315 +    P0 = IC(4);
  52.316 +    P2 = I31(4, 7);
  52.317 +  } else {
  52.318 +    P0 = I332(1, 3, 4);
  52.319 +    P2 = I521(4, 3, 7);
  52.320 +  }
  52.321 +} break;
  52.322 +case 46 : 
  52.323 +case 174 : 
  52.324 +{
  52.325 +  P1 = I31(4, 5);
  52.326 +  P2 = I31(4, 7);
  52.327 +  P3 = I211(4, 5, 7);
  52.328 +  if (MUL) {
  52.329 +    P0 = I31(4, 0);
  52.330 +  } else {
  52.331 +    P0 = I611(4, 1, 3);
  52.332 +  }
  52.333 +} break;
  52.334 +case 47 : 
  52.335 +case 175 : 
  52.336 +{
  52.337 +  P1 = I31(4, 5);
  52.338 +  P2 = I31(4, 7);
  52.339 +  P3 = I211(4, 5, 7);
  52.340 +  if (MUL) {
  52.341 +    P0 = IC(4);
  52.342 +  } else {
  52.343 +    P0 = I1411(4, 1, 3);
  52.344 +  }
  52.345 +} break;
  52.346 +case 56 : 
  52.347 +{
  52.348 +  P0 = I31(4, 0);
  52.349 +  P1 = I31(4, 2);
  52.350 +  P2 = I31(4, 7);
  52.351 +  P3 = I31(4, 8);
  52.352 +} break;
  52.353 +case 57 : 
  52.354 +{
  52.355 +  P0 = I31(4, 1);
  52.356 +  P1 = I31(4, 2);
  52.357 +  P2 = I31(4, 7);
  52.358 +  P3 = I31(4, 8);
  52.359 +} break;
  52.360 +case 58 : 
  52.361 +{
  52.362 +  P2 = I31(4, 7);
  52.363 +  P3 = I31(4, 8);
  52.364 +  if (MUL) {
  52.365 +    P0 = I31(4, 0);
  52.366 +  } else {
  52.367 +    P0 = I611(4, 1, 3);
  52.368 +  }
  52.369 +  if (MUR) {
  52.370 +    P1 = I31(4, 2);
  52.371 +  } else {
  52.372 +    P1 = I611(4, 1, 5);
  52.373 +  }
  52.374 +} break;
  52.375 +case 59 : 
  52.376 +{
  52.377 +  P2 = I31(4, 7);
  52.378 +  P3 = I31(4, 8);
  52.379 +  if (MUL) {
  52.380 +    P0 = IC(4);
  52.381 +  } else {
  52.382 +    P0 = I211(4, 1, 3);
  52.383 +  }
  52.384 +  if (MUR) {
  52.385 +    P1 = I31(4, 2);
  52.386 +  } else {
  52.387 +    P1 = I611(4, 1, 5);
  52.388 +  }
  52.389 +} break;
  52.390 +case 60 : 
  52.391 +{
  52.392 +  P0 = I31(4, 0);
  52.393 +  P1 = I31(4, 1);
  52.394 +  P2 = I31(4, 7);
  52.395 +  P3 = I31(4, 8);
  52.396 +} break;
  52.397 +case 61 : 
  52.398 +{
  52.399 +  P0 = I31(4, 1);
  52.400 +  P1 = I31(4, 1);
  52.401 +  P2 = I31(4, 7);
  52.402 +  P3 = I31(4, 8);
  52.403 +} break;
  52.404 +case 62 : 
  52.405 +{
  52.406 +  P0 = I31(4, 0);
  52.407 +  P2 = I31(4, 7);
  52.408 +  P3 = I31(4, 8);
  52.409 +  if (MUR) {
  52.410 +    P1 = IC(4);
  52.411 +  } else {
  52.412 +    P1 = I211(4, 1, 5);
  52.413 +  }
  52.414 +} break;
  52.415 +case 63 : 
  52.416 +{
  52.417 +  P2 = I31(4, 7);
  52.418 +  P3 = I31(4, 8);
  52.419 +  if (MUL) {
  52.420 +    P0 = IC(4);
  52.421 +  } else {
  52.422 +    P0 = I1411(4, 1, 3);
  52.423 +  }
  52.424 +  if (MUR) {
  52.425 +    P1 = IC(4);
  52.426 +  } else {
  52.427 +    P1 = I211(4, 1, 5);
  52.428 +  }
  52.429 +} break;
  52.430 +case 64 : 
  52.431 +case 65 : 
  52.432 +case 68 : 
  52.433 +case 69 : 
  52.434 +{
  52.435 +  P0 = I211(4, 1, 3);
  52.436 +  P1 = I211(4, 1, 5);
  52.437 +  P2 = I31(4, 6);
  52.438 +  P3 = I31(4, 8);
  52.439 +} break;
  52.440 +case 67 : 
  52.441 +{
  52.442 +  P0 = I31(4, 3);
  52.443 +  P1 = I31(4, 2);
  52.444 +  P2 = I31(4, 6);
  52.445 +  P3 = I31(4, 8);
  52.446 +} break;
  52.447 +case 70 : 
  52.448 +{
  52.449 +  P0 = I31(4, 0);
  52.450 +  P1 = I31(4, 5);
  52.451 +  P2 = I31(4, 6);
  52.452 +  P3 = I31(4, 8);
  52.453 +} break;
  52.454 +case 71 : 
  52.455 +{
  52.456 +  P0 = I31(4, 3);
  52.457 +  P1 = I31(4, 5);
  52.458 +  P2 = I31(4, 6);
  52.459 +  P3 = I31(4, 8);
  52.460 +} break;
  52.461 +case 72 : 
  52.462 +case 76 : 
  52.463 +{
  52.464 +  P0 = I31(4, 0);
  52.465 +  P1 = I211(4, 1, 5);
  52.466 +  P3 = I31(4, 8);
  52.467 +  if (MDL) {
  52.468 +    P2 = I31(4, 6);
  52.469 +  } else {
  52.470 +    P2 = I211(4, 3, 7);
  52.471 +  }
  52.472 +} break;
  52.473 +case 73 : 
  52.474 +case 77 : 
  52.475 +{
  52.476 +  P1 = I211(4, 1, 5);
  52.477 +  P3 = I31(4, 8);
  52.478 +  if (MDL) {
  52.479 +    P0 = I31(4, 1);
  52.480 +    P2 = I31(4, 6);
  52.481 +  } else {
  52.482 +    P0 = I521(4, 3, 1);
  52.483 +    P2 = I332(3, 7, 4);
  52.484 +  }
  52.485 +} break;
  52.486 +case 74 : 
  52.487 +case 107 : 
  52.488 +case 123 : 
  52.489 +{
  52.490 +  P1 = I31(4, 2);
  52.491 +  P3 = I31(4, 8);
  52.492 +  if (MDL) {
  52.493 +    P2 = IC(4);
  52.494 +  } else {
  52.495 +    P2 = I211(4, 3, 7);
  52.496 +  }
  52.497 +  if (MUL) {
  52.498 +    P0 = IC(4);
  52.499 +  } else {
  52.500 +    P0 = I211(4, 1, 3);
  52.501 +  }
  52.502 +} break;
  52.503 +case 78 : 
  52.504 +{
  52.505 +  P1 = I31(4, 5);
  52.506 +  P3 = I31(4, 8);
  52.507 +  if (MDL) {
  52.508 +    P2 = I31(4, 6);
  52.509 +  } else {
  52.510 +    P2 = I611(4, 3, 7);
  52.511 +  }
  52.512 +  if (MUL) {
  52.513 +    P0 = I31(4, 0);
  52.514 +  } else {
  52.515 +    P0 = I611(4, 1, 3);
  52.516 +  }
  52.517 +} break;
  52.518 +case 79 : 
  52.519 +{
  52.520 +  P1 = I31(4, 5);
  52.521 +  P3 = I31(4, 8);
  52.522 +  if (MDL) {
  52.523 +    P2 = I31(4, 6);
  52.524 +  } else {
  52.525 +    P2 = I611(4, 3, 7);
  52.526 +  }
  52.527 +  if (MUL) {
  52.528 +    P0 = IC(4);
  52.529 +  } else {
  52.530 +    P0 = I211(4, 1, 3);
  52.531 +  }
  52.532 +} break;
  52.533 +case 80 : 
  52.534 +case 81 : 
  52.535 +{
  52.536 +  P0 = I211(4, 1, 3);
  52.537 +  P1 = I31(4, 2);
  52.538 +  P2 = I31(4, 6);
  52.539 +  if (MDR) {
  52.540 +    P3 = I31(4, 8);
  52.541 +  } else {
  52.542 +    P3 = I211(4, 5, 7);
  52.543 +  }
  52.544 +} break;
  52.545 +case 82 : 
  52.546 +case 214 : 
  52.547 +case 222 : 
  52.548 +{
  52.549 +  P0 = I31(4, 0);
  52.550 +  P2 = I31(4, 6);
  52.551 +  if (MDR) {
  52.552 +    P3 = IC(4);
  52.553 +  } else {
  52.554 +    P3 = I211(4, 5, 7);
  52.555 +  }
  52.556 +  if (MUR) {
  52.557 +    P1 = IC(4);
  52.558 +  } else {
  52.559 +    P1 = I211(4, 1, 5);
  52.560 +  }
  52.561 +} break;
  52.562 +case 83 : 
  52.563 +{
  52.564 +  P0 = I31(4, 3);
  52.565 +  P2 = I31(4, 6);
  52.566 +  if (MDR) {
  52.567 +    P3 = I31(4, 8);
  52.568 +  } else {
  52.569 +    P3 = I611(4, 5, 7);
  52.570 +  }
  52.571 +  if (MUR) {
  52.572 +    P1 = I31(4, 2);
  52.573 +  } else {
  52.574 +    P1 = I611(4, 1, 5);
  52.575 +  }
  52.576 +} break;
  52.577 +case 84 : 
  52.578 +case 85 : 
  52.579 +{
  52.580 +  P0 = I211(4, 1, 3);
  52.581 +  P2 = I31(4, 6);
  52.582 +  if (MDR) {
  52.583 +    P1 = I31(4, 1);
  52.584 +    P3 = I31(4, 8);
  52.585 +  } else {
  52.586 +    P1 = I521(4, 5, 1);
  52.587 +    P3 = I332(5, 7, 4);
  52.588 +  }
  52.589 +} break;
  52.590 +case 87 : 
  52.591 +{
  52.592 +  P0 = I31(4, 3);
  52.593 +  P2 = I31(4, 6);
  52.594 +  if (MDR) {
  52.595 +    P3 = I31(4, 8);
  52.596 +  } else {
  52.597 +    P3 = I611(4, 5, 7);
  52.598 +  }
  52.599 +  if (MUR) {
  52.600 +    P1 = IC(4);
  52.601 +  } else {
  52.602 +    P1 = I211(4, 1, 5);
  52.603 +  }
  52.604 +} break;
  52.605 +case 88 : 
  52.606 +case 248 : 
  52.607 +case 250 : 
  52.608 +{
  52.609 +  P0 = I31(4, 0);
  52.610 +  P1 = I31(4, 2);
  52.611 +  if (MDL) {
  52.612 +    P2 = IC(4);
  52.613 +  } else {
  52.614 +    P2 = I211(4, 3, 7);
  52.615 +  }
  52.616 +  if (MDR) {
  52.617 +    P3 = IC(4);
  52.618 +  } else {
  52.619 +    P3 = I211(4, 5, 7);
  52.620 +  }
  52.621 +} break;
  52.622 +case 89 : 
  52.623 +{
  52.624 +  P0 = I31(4, 1);
  52.625 +  P1 = I31(4, 2);
  52.626 +  if (MDL) {
  52.627 +    P2 = I31(4, 6);
  52.628 +  } else {
  52.629 +    P2 = I611(4, 3, 7);
  52.630 +  }
  52.631 +  if (MDR) {
  52.632 +    P3 = I31(4, 8);
  52.633 +  } else {
  52.634 +    P3 = I611(4, 5, 7);
  52.635 +  }
  52.636 +} break;
  52.637 +case 90 : 
  52.638 +{
  52.639 +  if (MDL) {
  52.640 +    P2 = I31(4, 6);
  52.641 +  } else {
  52.642 +    P2 = I611(4, 3, 7);
  52.643 +  }
  52.644 +  if (MDR) {
  52.645 +    P3 = I31(4, 8);
  52.646 +  } else {
  52.647 +    P3 = I611(4, 5, 7);
  52.648 +  }
  52.649 +  if (MUL) {
  52.650 +    P0 = I31(4, 0);
  52.651 +  } else {
  52.652 +    P0 = I611(4, 1, 3);
  52.653 +  }
  52.654 +  if (MUR) {
  52.655 +    P1 = I31(4, 2);
  52.656 +  } else {
  52.657 +    P1 = I611(4, 1, 5);
  52.658 +  }
  52.659 +} break;
  52.660 +case 91 : 
  52.661 +{
  52.662 +  if (MDL) {
  52.663 +    P2 = I31(4, 6);
  52.664 +  } else {
  52.665 +    P2 = I611(4, 3, 7);
  52.666 +  }
  52.667 +  if (MDR) {
  52.668 +    P3 = I31(4, 8);
  52.669 +  } else {
  52.670 +    P3 = I611(4, 5, 7);
  52.671 +  }
  52.672 +  if (MUL) {
  52.673 +    P0 = IC(4);
  52.674 +  } else {
  52.675 +    P0 = I211(4, 1, 3);
  52.676 +  }
  52.677 +  if (MUR) {
  52.678 +    P1 = I31(4, 2);
  52.679 +  } else {
  52.680 +    P1 = I611(4, 1, 5);
  52.681 +  }
  52.682 +} break;
  52.683 +case 92 : 
  52.684 +{
  52.685 +  P0 = I31(4, 0);
  52.686 +  P1 = I31(4, 1);
  52.687 +  if (MDL) {
  52.688 +    P2 = I31(4, 6);
  52.689 +  } else {
  52.690 +    P2 = I611(4, 3, 7);
  52.691 +  }
  52.692 +  if (MDR) {
  52.693 +    P3 = I31(4, 8);
  52.694 +  } else {
  52.695 +    P3 = I611(4, 5, 7);
  52.696 +  }
  52.697 +} break;
  52.698 +case 93 : 
  52.699 +{
  52.700 +  P0 = I31(4, 1);
  52.701 +  P1 = I31(4, 1);
  52.702 +  if (MDL) {
  52.703 +    P2 = I31(4, 6);
  52.704 +  } else {
  52.705 +    P2 = I611(4, 3, 7);
  52.706 +  }
  52.707 +  if (MDR) {
  52.708 +    P3 = I31(4, 8);
  52.709 +  } else {
  52.710 +    P3 = I611(4, 5, 7);
  52.711 +  }
  52.712 +} break;
  52.713 +case 94 : 
  52.714 +{
  52.715 +  if (MDL) {
  52.716 +    P2 = I31(4, 6);
  52.717 +  } else {
  52.718 +    P2 = I611(4, 3, 7);
  52.719 +  }
  52.720 +  if (MDR) {
  52.721 +    P3 = I31(4, 8);
  52.722 +  } else {
  52.723 +    P3 = I611(4, 5, 7);
  52.724 +  }
  52.725 +  if (MUL) {
  52.726 +    P0 = I31(4, 0);
  52.727 +  } else {
  52.728 +    P0 = I611(4, 1, 3);
  52.729 +  }
  52.730 +  if (MUR) {
  52.731 +    P1 = IC(4);
  52.732 +  } else {
  52.733 +    P1 = I211(4, 1, 5);
  52.734 +  }
  52.735 +} break;
  52.736 +case 96 : 
  52.737 +case 97 : 
  52.738 +case 100 : 
  52.739 +case 101 : 
  52.740 +{
  52.741 +  P0 = I211(4, 1, 3);
  52.742 +  P1 = I211(4, 1, 5);
  52.743 +  P2 = I31(4, 3);
  52.744 +  P3 = I31(4, 8);
  52.745 +} break;
  52.746 +case 98 : 
  52.747 +{
  52.748 +  P0 = I31(4, 0);
  52.749 +  P1 = I31(4, 2);
  52.750 +  P2 = I31(4, 3);
  52.751 +  P3 = I31(4, 8);
  52.752 +} break;
  52.753 +case 99 : 
  52.754 +{
  52.755 +  P0 = I31(4, 3);
  52.756 +  P1 = I31(4, 2);
  52.757 +  P2 = I31(4, 3);
  52.758 +  P3 = I31(4, 8);
  52.759 +} break;
  52.760 +case 102 : 
  52.761 +{
  52.762 +  P0 = I31(4, 0);
  52.763 +  P1 = I31(4, 5);
  52.764 +  P2 = I31(4, 3);
  52.765 +  P3 = I31(4, 8);
  52.766 +} break;
  52.767 +case 103 : 
  52.768 +{
  52.769 +  P0 = I31(4, 3);
  52.770 +  P1 = I31(4, 5);
  52.771 +  P2 = I31(4, 3);
  52.772 +  P3 = I31(4, 8);
  52.773 +} break;
  52.774 +case 104 : 
  52.775 +case 108 : 
  52.776 +{
  52.777 +  P0 = I31(4, 0);
  52.778 +  P1 = I211(4, 1, 5);
  52.779 +  P3 = I31(4, 8);
  52.780 +  if (MDL) {
  52.781 +    P2 = IC(4);
  52.782 +  } else {
  52.783 +    P2 = I211(4, 3, 7);
  52.784 +  }
  52.785 +} break;
  52.786 +case 105 : 
  52.787 +case 109 : 
  52.788 +{
  52.789 +  P1 = I211(4, 1, 5);
  52.790 +  P3 = I31(4, 8);
  52.791 +  if (MDL) {
  52.792 +    P0 = I31(4, 1);
  52.793 +    P2 = IC(4);
  52.794 +  } else {
  52.795 +    P0 = I521(4, 3, 1);
  52.796 +    P2 = I332(3, 7, 4);
  52.797 +  }
  52.798 +} break;
  52.799 +case 106 : 
  52.800 +case 120 : 
  52.801 +{
  52.802 +  P0 = I31(4, 0);
  52.803 +  P1 = I31(4, 2);
  52.804 +  P3 = I31(4, 8);
  52.805 +  if (MDL) {
  52.806 +    P2 = IC(4);
  52.807 +  } else {
  52.808 +    P2 = I211(4, 3, 7);
  52.809 +  }
  52.810 +} break;
  52.811 +case 110 : 
  52.812 +{
  52.813 +  P0 = I31(4, 0);
  52.814 +  P1 = I31(4, 5);
  52.815 +  P3 = I31(4, 8);
  52.816 +  if (MDL) {
  52.817 +    P2 = IC(4);
  52.818 +  } else {
  52.819 +    P2 = I211(4, 3, 7);
  52.820 +  }
  52.821 +} break;
  52.822 +case 111 : 
  52.823 +{
  52.824 +  P1 = I31(4, 5);
  52.825 +  P3 = I31(4, 8);
  52.826 +  if (MDL) {
  52.827 +    P2 = IC(4);
  52.828 +  } else {
  52.829 +    P2 = I211(4, 3, 7);
  52.830 +  }
  52.831 +  if (MUL) {
  52.832 +    P0 = IC(4);
  52.833 +  } else {
  52.834 +    P0 = I1411(4, 1, 3);
  52.835 +  }
  52.836 +} break;
  52.837 +case 112 : 
  52.838 +case 113 : 
  52.839 +{
  52.840 +  P0 = I211(4, 1, 3);
  52.841 +  P1 = I31(4, 2);
  52.842 +  if (MDR) {
  52.843 +    P2 = I31(4, 3);
  52.844 +    P3 = I31(4, 8);
  52.845 +  } else {
  52.846 +    P2 = I521(4, 7, 3);
  52.847 +    P3 = I332(5, 7, 4);
  52.848 +  }
  52.849 +} break;
  52.850 +case 114 : 
  52.851 +{
  52.852 +  P0 = I31(4, 0);
  52.853 +  P2 = I31(4, 3);
  52.854 +  if (MDR) {
  52.855 +    P3 = I31(4, 8);
  52.856 +  } else {
  52.857 +    P3 = I611(4, 5, 7);
  52.858 +  }
  52.859 +  if (MUR) {
  52.860 +    P1 = I31(4, 2);
  52.861 +  } else {
  52.862 +    P1 = I611(4, 1, 5);
  52.863 +  }
  52.864 +} break;
  52.865 +case 115 : 
  52.866 +{
  52.867 +  P0 = I31(4, 3);
  52.868 +  P2 = I31(4, 3);
  52.869 +  if (MDR) {
  52.870 +    P3 = I31(4, 8);
  52.871 +  } else {
  52.872 +    P3 = I611(4, 5, 7);
  52.873 +  }
  52.874 +  if (MUR) {
  52.875 +    P1 = I31(4, 2);
  52.876 +  } else {
  52.877 +    P1 = I611(4, 1, 5);
  52.878 +  }
  52.879 +} break;
  52.880 +case 116 : 
  52.881 +case 117 : 
  52.882 +{
  52.883 +  P0 = I211(4, 1, 3);
  52.884 +  P1 = I31(4, 1);
  52.885 +  P2 = I31(4, 3);
  52.886 +  if (MDR) {
  52.887 +    P3 = I31(4, 8);
  52.888 +  } else {
  52.889 +    P3 = I611(4, 5, 7);
  52.890 +  }
  52.891 +} break;
  52.892 +case 118 : 
  52.893 +{
  52.894 +  P0 = I31(4, 0);
  52.895 +  P2 = I31(4, 3);
  52.896 +  P3 = I31(4, 8);
  52.897 +  if (MUR) {
  52.898 +    P1 = IC(4);
  52.899 +  } else {
  52.900 +    P1 = I211(4, 1, 5);
  52.901 +  }
  52.902 +} break;
  52.903 +case 119 : 
  52.904 +{
  52.905 +  P2 = I31(4, 3);
  52.906 +  P3 = I31(4, 8);
  52.907 +  if (MUR) {
  52.908 +    P0 = I31(4, 3);
  52.909 +    P1 = IC(4);
  52.910 +  } else {
  52.911 +    P0 = I521(4, 1, 3);
  52.912 +    P1 = I332(1, 5, 4);
  52.913 +  }
  52.914 +} break;
  52.915 +case 121 : 
  52.916 +{
  52.917 +  P0 = I31(4, 1);
  52.918 +  P1 = I31(4, 2);
  52.919 +  if (MDL) {
  52.920 +    P2 = IC(4);
  52.921 +  } else {
  52.922 +    P2 = I211(4, 3, 7);
  52.923 +  }
  52.924 +  if (MDR) {
  52.925 +    P3 = I31(4, 8);
  52.926 +  } else {
  52.927 +    P3 = I611(4, 5, 7);
  52.928 +  }
  52.929 +} break;
  52.930 +case 122 : 
  52.931 +{
  52.932 +  if (MDL) {
  52.933 +    P2 = IC(4);
  52.934 +  } else {
  52.935 +    P2 = I211(4, 3, 7);
  52.936 +  }
  52.937 +  if (MDR) {
  52.938 +    P3 = I31(4, 8);
  52.939 +  } else {
  52.940 +    P3 = I611(4, 5, 7);
  52.941 +  }
  52.942 +  if (MUL) {
  52.943 +    P0 = I31(4, 0);
  52.944 +  } else {
  52.945 +    P0 = I611(4, 1, 3);
  52.946 +  }
  52.947 +  if (MUR) {
  52.948 +    P1 = I31(4, 2);
  52.949 +  } else {
  52.950 +    P1 = I611(4, 1, 5);
  52.951 +  }
  52.952 +} break;
  52.953 +case 124 : 
  52.954 +{
  52.955 +  P0 = I31(4, 0);
  52.956 +  P1 = I31(4, 1);
  52.957 +  P3 = I31(4, 8);
  52.958 +  if (MDL) {
  52.959 +    P2 = IC(4);
  52.960 +  } else {
  52.961 +    P2 = I211(4, 3, 7);
  52.962 +  }
  52.963 +} break;
  52.964 +case 125 : 
  52.965 +{
  52.966 +  P1 = I31(4, 1);
  52.967 +  P3 = I31(4, 8);
  52.968 +  if (MDL) {
  52.969 +    P0 = I31(4, 1);
  52.970 +    P2 = IC(4);
  52.971 +  } else {
  52.972 +    P0 = I521(4, 3, 1);
  52.973 +    P2 = I332(3, 7, 4);
  52.974 +  }
  52.975 +} break;
  52.976 +case 126 : 
  52.977 +{
  52.978 +  P0 = I31(4, 0);
  52.979 +  P3 = I31(4, 8);
  52.980 +  if (MDL) {
  52.981 +    P2 = IC(4);
  52.982 +  } else {
  52.983 +    P2 = I211(4, 3, 7);
  52.984 +  }
  52.985 +  if (MUR) {
  52.986 +    P1 = IC(4);
  52.987 +  } else {
  52.988 +    P1 = I211(4, 1, 5);
  52.989 +  }
  52.990 +} break;
  52.991 +case 127 : 
  52.992 +{
  52.993 +  P3 = I31(4, 8);
  52.994 +  if (MDL) {
  52.995 +    P2 = IC(4);
  52.996 +  } else {
  52.997 +    P2 = I211(4, 3, 7);
  52.998 +  }
  52.999 +  if (MUL) {
 52.1000 +    P0 = IC(4);
 52.1001 +  } else {
 52.1002 +    P0 = I1411(4, 1, 3);
 52.1003 +  }
 52.1004 +  if (MUR) {
 52.1005 +    P1 = IC(4);
 52.1006 +  } else {
 52.1007 +    P1 = I211(4, 1, 5);
 52.1008 +  }
 52.1009 +} break;
 52.1010 +case 144 : 
 52.1011 +case 145 : 
 52.1012 +case 176 : 
 52.1013 +case 177 : 
 52.1014 +{
 52.1015 +  P0 = I211(4, 1, 3);
 52.1016 +  P1 = I31(4, 2);
 52.1017 +  P2 = I211(4, 3, 7);
 52.1018 +  P3 = I31(4, 7);
 52.1019 +} break;
 52.1020 +case 146 : 
 52.1021 +case 178 : 
 52.1022 +{
 52.1023 +  P0 = I31(4, 0);
 52.1024 +  P2 = I211(4, 3, 7);
 52.1025 +  if (MUR) {
 52.1026 +    P1 = I31(4, 2);
 52.1027 +    P3 = I31(4, 7);
 52.1028 +  } else {
 52.1029 +    P1 = I332(1, 5, 4);
 52.1030 +    P3 = I521(4, 5, 7);
 52.1031 +  }
 52.1032 +} break;
 52.1033 +case 147 : 
 52.1034 +case 179 : 
 52.1035 +{
 52.1036 +  P0 = I31(4, 3);
 52.1037 +  P2 = I211(4, 3, 7);
 52.1038 +  P3 = I31(4, 7);
 52.1039 +  if (MUR) {
 52.1040 +    P1 = I31(4, 2);
 52.1041 +  } else {
 52.1042 +    P1 = I611(4, 1, 5);
 52.1043 +  }
 52.1044 +} break;
 52.1045 +case 148 : 
 52.1046 +case 149 : 
 52.1047 +case 180 : 
 52.1048 +case 181 : 
 52.1049 +{
 52.1050 +  P0 = I211(4, 1, 3);
 52.1051 +  P1 = I31(4, 1);
 52.1052 +  P2 = I211(4, 3, 7);
 52.1053 +  P3 = I31(4, 7);
 52.1054 +} break;
 52.1055 +case 150 : 
 52.1056 +case 182 : 
 52.1057 +{
 52.1058 +  P0 = I31(4, 0);
 52.1059 +  P2 = I211(4, 3, 7);
 52.1060 +  if (MUR) {
 52.1061 +    P1 = IC(4);
 52.1062 +    P3 = I31(4, 7);
 52.1063 +  } else {
 52.1064 +    P1 = I332(1, 5, 4);
 52.1065 +    P3 = I521(4, 5, 7);
 52.1066 +  }
 52.1067 +} break;
 52.1068 +case 151 : 
 52.1069 +case 183 : 
 52.1070 +{
 52.1071 +  P0 = I31(4, 3);
 52.1072 +  P2 = I211(4, 3, 7);
 52.1073 +  P3 = I31(4, 7);
 52.1074 +  if (MUR) {
 52.1075 +    P1 = IC(4);
 52.1076 +  } else {
 52.1077 +    P1 = I1411(4, 1, 5);
 52.1078 +  }
 52.1079 +} break;
 52.1080 +case 152 : 
 52.1081 +{
 52.1082 +  P0 = I31(4, 0);
 52.1083 +  P1 = I31(4, 2);
 52.1084 +  P2 = I31(4, 6);
 52.1085 +  P3 = I31(4, 7);
 52.1086 +} break;
 52.1087 +case 153 : 
 52.1088 +{
 52.1089 +  P0 = I31(4, 1);
 52.1090 +  P1 = I31(4, 2);
 52.1091 +  P2 = I31(4, 6);
 52.1092 +  P3 = I31(4, 7);
 52.1093 +} break;
 52.1094 +case 154 : 
 52.1095 +{
 52.1096 +  P2 = I31(4, 6);
 52.1097 +  P3 = I31(4, 7);
 52.1098 +  if (MUL) {
 52.1099 +    P0 = I31(4, 0);
 52.1100 +  } else {
 52.1101 +    P0 = I611(4, 1, 3);
 52.1102 +  }
 52.1103 +  if (MUR) {
 52.1104 +    P1 = I31(4, 2);
 52.1105 +  } else {
 52.1106 +    P1 = I611(4, 1, 5);
 52.1107 +  }
 52.1108 +} break;
 52.1109 +case 155 : 
 52.1110 +{
 52.1111 +  P1 = I31(4, 2);
 52.1112 +  P2 = I31(4, 6);
 52.1113 +  P3 = I31(4, 7);
 52.1114 +  if (MUL) {
 52.1115 +    P0 = IC(4);
 52.1116 +  } else {
 52.1117 +    P0 = I211(4, 1, 3);
 52.1118 +  }
 52.1119 +} break;
 52.1120 +case 156 : 
 52.1121 +{
 52.1122 +  P0 = I31(4, 0);
 52.1123 +  P1 = I31(4, 1);
 52.1124 +  P2 = I31(4, 6);
 52.1125 +  P3 = I31(4, 7);
 52.1126 +} break;
 52.1127 +case 157 : 
 52.1128 +{
 52.1129 +  P0 = I31(4, 1);
 52.1130 +  P1 = I31(4, 1);
 52.1131 +  P2 = I31(4, 6);
 52.1132 +  P3 = I31(4, 7);
 52.1133 +} break;
 52.1134 +case 158 : 
 52.1135 +{
 52.1136 +  P2 = I31(4, 6);
 52.1137 +  P3 = I31(4, 7);
 52.1138 +  if (MUL) {
 52.1139 +    P0 = I31(4, 0);
 52.1140 +  } else {
 52.1141 +    P0 = I611(4, 1, 3);
 52.1142 +  }
 52.1143 +  if (MUR) {
 52.1144 +    P1 = IC(4);
 52.1145 +  } else {
 52.1146 +    P1 = I211(4, 1, 5);
 52.1147 +  }
 52.1148 +} break;
 52.1149 +case 159 : 
 52.1150 +{
 52.1151 +  P2 = I31(4, 6);
 52.1152 +  P3 = I31(4, 7);
 52.1153 +  if (MUL) {
 52.1154 +    P0 = IC(4);
 52.1155 +  } else {
 52.1156 +    P0 = I211(4, 1, 3);
 52.1157 +  }
 52.1158 +  if (MUR) {
 52.1159 +    P1 = IC(4);
 52.1160 +  } else {
 52.1161 +    P1 = I1411(4, 1, 5);
 52.1162 +  }
 52.1163 +} break;
 52.1164 +case 184 : 
 52.1165 +{
 52.1166 +  P0 = I31(4, 0);
 52.1167 +  P1 = I31(4, 2);
 52.1168 +  P2 = I31(4, 7);
 52.1169 +  P3 = I31(4, 7);
 52.1170 +} break;
 52.1171 +case 185 : 
 52.1172 +{
 52.1173 +  P0 = I31(4, 1);
 52.1174 +  P1 = I31(4, 2);
 52.1175 +  P2 = I31(4, 7);
 52.1176 +  P3 = I31(4, 7);
 52.1177 +} break;
 52.1178 +case 186 : 
 52.1179 +{
 52.1180 +  P2 = I31(4, 7);
 52.1181 +  P3 = I31(4, 7);
 52.1182 +  if (MUL) {
 52.1183 +    P0 = I31(4, 0);
 52.1184 +  } else {
 52.1185 +    P0 = I611(4, 1, 3);
 52.1186 +  }
 52.1187 +  if (MUR) {
 52.1188 +    P1 = I31(4, 2);
 52.1189 +  } else {
 52.1190 +    P1 = I611(4, 1, 5);
 52.1191 +  }
 52.1192 +} break;
 52.1193 +case 187 : 
 52.1194 +{
 52.1195 +  P1 = I31(4, 2);
 52.1196 +  P3 = I31(4, 7);
 52.1197 +  if (MUL) {
 52.1198 +    P0 = IC(4);
 52.1199 +    P2 = I31(4, 7);
 52.1200 +  } else {
 52.1201 +    P0 = I332(1, 3, 4);
 52.1202 +    P2 = I521(4, 3, 7);
 52.1203 +  }
 52.1204 +} break;
 52.1205 +case 188 : 
 52.1206 +{
 52.1207 +  P0 = I31(4, 0);
 52.1208 +  P1 = I31(4, 1);
 52.1209 +  P2 = I31(4, 7);
 52.1210 +  P3 = I31(4, 7);
 52.1211 +} break;
 52.1212 +case 189 : 
 52.1213 +{
 52.1214 +  P0 = I31(4, 1);
 52.1215 +  P1 = I31(4, 1);
 52.1216 +  P2 = I31(4, 7);
 52.1217 +  P3 = I31(4, 7);
 52.1218 +} break;
 52.1219 +case 190 : 
 52.1220 +{
 52.1221 +  P0 = I31(4, 0);
 52.1222 +  P2 = I31(4, 7);
 52.1223 +  if (MUR) {
 52.1224 +    P1 = IC(4);
 52.1225 +    P3 = I31(4, 7);
 52.1226 +  } else {
 52.1227 +    P1 = I332(1, 5, 4);
 52.1228 +    P3 = I521(4, 5, 7);
 52.1229 +  }
 52.1230 +} break;
 52.1231 +case 191 : 
 52.1232 +{
 52.1233 +  P2 = I31(4, 7);
 52.1234 +  P3 = I31(4, 7);
 52.1235 +  if (MUL) {
 52.1236 +    P0 = IC(4);
 52.1237 +  } else {
 52.1238 +    P0 = I1411(4, 1, 3);
 52.1239 +  }
 52.1240 +  if (MUR) {
 52.1241 +    P1 = IC(4);
 52.1242 +  } else {
 52.1243 +    P1 = I1411(4, 1, 5);
 52.1244 +  }
 52.1245 +} break;
 52.1246 +case 192 : 
 52.1247 +case 193 : 
 52.1248 +case 196 : 
 52.1249 +case 197 : 
 52.1250 +{
 52.1251 +  P0 = I211(4, 1, 3);
 52.1252 +  P1 = I211(4, 1, 5);
 52.1253 +  P2 = I31(4, 6);
 52.1254 +  P3 = I31(4, 5);
 52.1255 +} break;
 52.1256 +case 194 : 
 52.1257 +{
 52.1258 +  P0 = I31(4, 0);
 52.1259 +  P1 = I31(4, 2);
 52.1260 +  P2 = I31(4, 6);
 52.1261 +  P3 = I31(4, 5);
 52.1262 +} break;
 52.1263 +case 195 : 
 52.1264 +{
 52.1265 +  P0 = I31(4, 3);
 52.1266 +  P1 = I31(4, 2);
 52.1267 +  P2 = I31(4, 6);
 52.1268 +  P3 = I31(4, 5);
 52.1269 +} break;
 52.1270 +case 198 : 
 52.1271 +{
 52.1272 +  P0 = I31(4, 0);
 52.1273 +  P1 = I31(4, 5);
 52.1274 +  P2 = I31(4, 6);
 52.1275 +  P3 = I31(4, 5);
 52.1276 +} break;
 52.1277 +case 199 : 
 52.1278 +{
 52.1279 +  P0 = I31(4, 3);
 52.1280 +  P1 = I31(4, 5);
 52.1281 +  P2 = I31(4, 6);
 52.1282 +  P3 = I31(4, 5);
 52.1283 +} break;
 52.1284 +case 200 : 
 52.1285 +case 204 : 
 52.1286 +{
 52.1287 +  P0 = I31(4, 0);
 52.1288 +  P1 = I211(4, 1, 5);
 52.1289 +  if (MDL) {
 52.1290 +    P2 = I31(4, 6);
 52.1291 +    P3 = I31(4, 5);
 52.1292 +  } else {
 52.1293 +    P2 = I332(3, 7, 4);
 52.1294 +    P3 = I521(4, 7, 5);
 52.1295 +  }
 52.1296 +} break;
 52.1297 +case 201 : 
 52.1298 +case 205 : 
 52.1299 +{
 52.1300 +  P0 = I31(4, 1);
 52.1301 +  P1 = I211(4, 1, 5);
 52.1302 +  P3 = I31(4, 5);
 52.1303 +  if (MDL) {
 52.1304 +    P2 = I31(4, 6);
 52.1305 +  } else {
 52.1306 +    P2 = I611(4, 3, 7);
 52.1307 +  }
 52.1308 +} break;
 52.1309 +case 202 : 
 52.1310 +{
 52.1311 +  P1 = I31(4, 2);
 52.1312 +  P3 = I31(4, 5);
 52.1313 +  if (MDL) {
 52.1314 +    P2 = I31(4, 6);
 52.1315 +  } else {
 52.1316 +    P2 = I611(4, 3, 7);
 52.1317 +  }
 52.1318 +  if (MUL) {
 52.1319 +    P0 = I31(4, 0);
 52.1320 +  } else {
 52.1321 +    P0 = I611(4, 1, 3);
 52.1322 +  }
 52.1323 +} break;
 52.1324 +case 203 : 
 52.1325 +{
 52.1326 +  P1 = I31(4, 2);
 52.1327 +  P2 = I31(4, 6);
 52.1328 +  P3 = I31(4, 5);
 52.1329 +  if (MUL) {
 52.1330 +    P0 = IC(4);
 52.1331 +  } else {
 52.1332 +    P0 = I211(4, 1, 3);
 52.1333 +  }
 52.1334 +} break;
 52.1335 +case 206 : 
 52.1336 +{
 52.1337 +  P1 = I31(4, 5);
 52.1338 +  P3 = I31(4, 5);
 52.1339 +  if (MDL) {
 52.1340 +    P2 = I31(4, 6);
 52.1341 +  } else {
 52.1342 +    P2 = I611(4, 3, 7);
 52.1343 +  }
 52.1344 +  if (MUL) {
 52.1345 +    P0 = I31(4, 0);
 52.1346 +  } else {
 52.1347 +    P0 = I611(4, 1, 3);
 52.1348 +  }
 52.1349 +} break;
 52.1350 +case 207 : 
 52.1351 +{
 52.1352 +  P2 = I31(4, 6);
 52.1353 +  P3 = I31(4, 5);
 52.1354 +  if (MUL) {
 52.1355 +    P0 = IC(4);
 52.1356 +    P1 = I31(4, 5);
 52.1357 +  } else {
 52.1358 +    P0 = I332(1, 3, 4);
 52.1359 +    P1 = I521(4, 1, 5);
 52.1360 +  }
 52.1361 +} break;
 52.1362 +case 208 : 
 52.1363 +case 209 : 
 52.1364 +{
 52.1365 +  P0 = I211(4, 1, 3);
 52.1366 +  P1 = I31(4, 2);
 52.1367 +  P2 = I31(4, 6);
 52.1368 +  if (MDR) {
 52.1369 +    P3 = IC(4);
 52.1370 +  } else {
 52.1371 +    P3 = I211(4, 5, 7);
 52.1372 +  }
 52.1373 +} break;
 52.1374 +case 210 : 
 52.1375 +case 216 : 
 52.1376 +{
 52.1377 +  P0 = I31(4, 0);
 52.1378 +  P1 = I31(4, 2);
 52.1379 +  P2 = I31(4, 6);
 52.1380 +  if (MDR) {
 52.1381 +    P3 = IC(4);
 52.1382 +  } else {
 52.1383 +    P3 = I211(4, 5, 7);
 52.1384 +  }
 52.1385 +} break;
 52.1386 +case 211 : 
 52.1387 +{
 52.1388 +  P0 = I31(4, 3);
 52.1389 +  P1 = I31(4, 2);
 52.1390 +  P2 = I31(4, 6);
 52.1391 +  if (MDR) {
 52.1392 +    P3 = IC(4);
 52.1393 +  } else {
 52.1394 +    P3 = I211(4, 5, 7);
 52.1395 +  }
 52.1396 +} break;
 52.1397 +case 212 : 
 52.1398 +case 213 : 
 52.1399 +{
 52.1400 +  P0 = I211(4, 1, 3);
 52.1401 +  P2 = I31(4, 6);
 52.1402 +  if (MDR) {
 52.1403 +    P1 = I31(4, 1);
 52.1404 +    P3 = IC(4);
 52.1405 +  } else {
 52.1406 +    P1 = I521(4, 5, 1);
 52.1407 +    P3 = I332(5, 7, 4);
 52.1408 +  }
 52.1409 +} break;
 52.1410 +case 215 : 
 52.1411 +{
 52.1412 +  P0 = I31(4, 3);
 52.1413 +  P2 = I31(4, 6);
 52.1414 +  if (MDR) {
 52.1415 +    P3 = IC(4);
 52.1416 +  } else {
 52.1417 +    P3 = I211(4, 5, 7);
 52.1418 +  }
 52.1419 +  if (MUR) {
 52.1420 +    P1 = IC(4);
 52.1421 +  } else {
 52.1422 +    P1 = I1411(4, 1, 5);
 52.1423 +  }
 52.1424 +} break;
 52.1425 +case 217 : 
 52.1426 +{
 52.1427 +  P0 = I31(4, 1);
 52.1428 +  P1 = I31(4, 2);
 52.1429 +  P2 = I31(4, 6);
 52.1430 +  if (MDR) {
 52.1431 +    P3 = IC(4);
 52.1432 +  } else {
 52.1433 +    P3 = I211(4, 5, 7);
 52.1434 +  }
 52.1435 +} break;
 52.1436 +case 218 : 
 52.1437 +{
 52.1438 +  if (MDL) {
 52.1439 +    P2 = I31(4, 6);
 52.1440 +  } else {
 52.1441 +    P2 = I611(4, 3, 7);
 52.1442 +  }
 52.1443 +  if (MDR) {
 52.1444 +    P3 = IC(4);
 52.1445 +  } else {
 52.1446 +    P3 = I211(4, 5, 7);
 52.1447 +  }
 52.1448 +  if (MUL) {
 52.1449 +    P0 = I31(4, 0);
 52.1450 +  } else {
 52.1451 +    P0 = I611(4, 1, 3);
 52.1452 +  }
 52.1453 +  if (MUR) {
 52.1454 +    P1 = I31(4, 2);
 52.1455 +  } else {
 52.1456 +    P1 = I611(4, 1, 5);
 52.1457 +  }
 52.1458 +} break;
 52.1459 +case 219 : 
 52.1460 +{
 52.1461 +  P1 = I31(4, 2);
 52.1462 +  P2 = I31(4, 6);
 52.1463 +  if (MDR) {
 52.1464 +    P3 = IC(4);
 52.1465 +  } else {
 52.1466 +    P3 = I211(4, 5, 7);
 52.1467 +  }
 52.1468 +  if (MUL) {
 52.1469 +    P0 = IC(4);
 52.1470 +  } else {
 52.1471 +    P0 = I211(4, 1, 3);
 52.1472 +  }
 52.1473 +} break;
 52.1474 +case 220 : 
 52.1475 +{
 52.1476 +  P0 = I31(4, 0);
 52.1477 +  P1 = I31(4, 1);
 52.1478 +  if (MDL) {
 52.1479 +    P2 = I31(4, 6);
 52.1480 +  } else {
 52.1481 +    P2 = I611(4, 3, 7);
 52.1482 +  }
 52.1483 +  if (MDR) {
 52.1484 +    P3 = IC(4);
 52.1485 +  } else {
 52.1486 +    P3 = I211(4, 5, 7);
 52.1487 +  }
 52.1488 +} break;
 52.1489 +case 221 : 
 52.1490 +{
 52.1491 +  P0 = I31(4, 1);
 52.1492 +  P2 = I31(4, 6);
 52.1493 +  if (MDR) {
 52.1494 +    P1 = I31(4, 1);
 52.1495 +    P3 = IC(4);
 52.1496 +  } else {
 52.1497 +    P1 = I521(4, 5, 1);
 52.1498 +    P3 = I332(5, 7, 4);
 52.1499 +  }
 52.1500 +} break;
 52.1501 +case 223 : 
 52.1502 +{
 52.1503 +  P2 = I31(4, 6);
 52.1504 +  if (MDR) {
 52.1505 +    P3 = IC(4);
 52.1506 +  } else {
 52.1507 +    P3 = I211(4, 5, 7);
 52.1508 +  }
 52.1509 +  if (MUL) {
 52.1510 +    P0 = IC(4);
 52.1511 +  } else {
 52.1512 +    P0 = I211(4, 1, 3);
 52.1513 +  }
 52.1514 +  if (MUR) {
 52.1515 +    P1 = IC(4);
 52.1516 +  } else {
 52.1517 +    P1 = I1411(4, 1, 5);
 52.1518 +  }
 52.1519 +} break;
 52.1520 +case 224 : 
 52.1521 +case 225 : 
 52.1522 +case 228 : 
 52.1523 +case 229 : 
 52.1524 +{
 52.1525 +  P0 = I211(4, 1, 3);
 52.1526 +  P1 = I211(4, 1, 5);
 52.1527 +  P2 = I31(4, 3);
 52.1528 +  P3 = I31(4, 5);
 52.1529 +} break;
 52.1530 +case 226 : 
 52.1531 +{
 52.1532 +  P0 = I31(4, 0);
 52.1533 +  P1 = I31(4, 2);
 52.1534 +  P2 = I31(4, 3);
 52.1535 +  P3 = I31(4, 5);
 52.1536 +} break;
 52.1537 +case 227 : 
 52.1538 +{
 52.1539 +  P0 = I31(4, 3);
 52.1540 +  P1 = I31(4, 2);
 52.1541 +  P2 = I31(4, 3);
 52.1542 +  P3 = I31(4, 5);
 52.1543 +} break;
 52.1544 +case 230 : 
 52.1545 +{
 52.1546 +  P0 = I31(4, 0);
 52.1547 +  P1 = I31(4, 5);
 52.1548 +  P2 = I31(4, 3);
 52.1549 +  P3 = I31(4, 5);
 52.1550 +} break;
 52.1551 +case 231 : 
 52.1552 +{
 52.1553 +  P0 = I31(4, 3);
 52.1554 +  P1 = I31(4, 5);
 52.1555 +  P2 = I31(4, 3);
 52.1556 +  P3 = I31(4, 5);
 52.1557 +} break;
 52.1558 +case 232 : 
 52.1559 +case 236 : 
 52.1560 +{
 52.1561 +  P0 = I31(4, 0);
 52.1562 +  P1 = I211(4, 1, 5);
 52.1563 +  if (MDL) {
 52.1564 +    P2 = IC(4);
 52.1565 +    P3 = I31(4, 5);
 52.1566 +  } else {
 52.1567 +    P2 = I332(3, 7, 4);
 52.1568 +    P3 = I521(4, 7, 5);
 52.1569 +  }
 52.1570 +} break;
 52.1571 +case 233 : 
 52.1572 +case 237 : 
 52.1573 +{
 52.1574 +  P0 = I31(4, 1);
 52.1575 +  P1 = I211(4, 1, 5);
 52.1576 +  P3 = I31(4, 5);
 52.1577 +  if (MDL) {
 52.1578 +    P2 = IC(4);
 52.1579 +  } else {
 52.1580 +    P2 = I1411(4, 3, 7);
 52.1581 +  }
 52.1582 +} break;
 52.1583 +case 234 : 
 52.1584 +{
 52.1585 +  P1 = I31(4, 2);
 52.1586 +  P3 = I31(4, 5);
 52.1587 +  if (MDL) {
 52.1588 +    P2 = IC(4);
 52.1589 +  } else {
 52.1590 +    P2 = I211(4, 3, 7);
 52.1591 +  }
 52.1592 +  if (MUL) {
 52.1593 +    P0 = I31(4, 0);
 52.1594 +  } else {
 52.1595 +    P0 = I611(4, 1, 3);
 52.1596 +  }
 52.1597 +} break;
 52.1598 +case 235 : 
 52.1599 +{
 52.1600 +  P1 = I31(4, 2);
 52.1601 +  P3 = I31(4, 5);
 52.1602 +  if (MDL) {
 52.1603 +    P2 = IC(4);
 52.1604 +  } else {
 52.1605 +    P2 = I1411(4, 3, 7);
 52.1606 +  }
 52.1607 +  if (MUL) {
 52.1608 +    P0 = IC(4);
 52.1609 +  } else {
 52.1610 +    P0 = I211(4, 1, 3);
 52.1611 +  }
 52.1612 +} break;
 52.1613 +case 238 : 
 52.1614 +{
 52.1615 +  P0 = I31(4, 0);
 52.1616 +  P1 = I31(4, 5);
 52.1617 +  if (MDL) {
 52.1618 +    P2 = IC(4);
 52.1619 +    P3 = I31(4, 5);
 52.1620 +  } else {
 52.1621 +    P2 = I332(3, 7, 4);
 52.1622 +    P3 = I521(4, 7, 5);
 52.1623 +  }
 52.1624 +} break;
 52.1625 +case 239 : 
 52.1626 +{
 52.1627 +  P1 = I31(4, 5);
 52.1628 +  P3 = I31(4, 5);
 52.1629 +  if (MDL) {
 52.1630 +    P2 = IC(4);
 52.1631 +  } else {
 52.1632 +    P2 = I1411(4, 3, 7);
 52.1633 +  }
 52.1634 +  if (MUL) {
 52.1635 +    P0 = IC(4);
 52.1636 +  } else {
 52.1637 +    P0 = I1411(4, 1, 3);
 52.1638 +  }
 52.1639 +} break;
 52.1640 +case 240 : 
 52.1641 +case 241 : 
 52.1642 +{
 52.1643 +  P0 = I211(4, 1, 3);
 52.1644 +  P1 = I31(4, 2);
 52.1645 +  if (MDR) {
 52.1646 +    P2 = I31(4, 3);
 52.1647 +    P3 = IC(4);
 52.1648 +  } else {
 52.1649 +    P2 = I521(4, 7, 3);
 52.1650 +    P3 = I332(5, 7, 4);
 52.1651 +  }
 52.1652 +} break;
 52.1653 +case 242 : 
 52.1654 +{
 52.1655 +  P0 = I31(4, 0);
 52.1656 +  P2 = I31(4, 3);
 52.1657 +  if (MDR) {
 52.1658 +    P3 = IC(4);
 52.1659 +  } else {
 52.1660 +    P3 = I211(4, 5, 7);
 52.1661 +  }
 52.1662 +  if (MUR) {
 52.1663 +    P1 = I31(4, 2);
 52.1664 +  } else {
 52.1665 +    P1 = I611(4, 1, 5);
 52.1666 +  }
 52.1667 +} break;
 52.1668 +case 243 : 
 52.1669 +{
 52.1670 +  P0 = I31(4, 3);
 52.1671 +  P1 = I31(4, 2);
 52.1672 +  if (MDR) {
 52.1673 +    P2 = I31(4, 3);
 52.1674 +    P3 = IC(4);
 52.1675 +  } else {
 52.1676 +    P2 = I521(4, 7, 3);
 52.1677 +    P3 = I332(5, 7, 4);
 52.1678 +  }
 52.1679 +} break;
 52.1680 +case 244 : 
 52.1681 +case 245 : 
 52.1682 +{
 52.1683 +  P0 = I211(4, 1, 3);
 52.1684 +  P1 = I31(4, 1);
 52.1685 +  P2 = I31(4, 3);
 52.1686 +  if (MDR) {
 52.1687 +    P3 = IC(4);
 52.1688 +  } else {
 52.1689 +    P3 = I1411(4, 5, 7);
 52.1690 +  }
 52.1691 +} break;
 52.1692 +case 246 : 
 52.1693 +{
 52.1694 +  P0 = I31(4, 0);
 52.1695 +  P2 = I31(4, 3);
 52.1696 +  if (MDR) {
 52.1697 +    P3 = IC(4);
 52.1698 +  } else {
 52.1699 +    P3 = I1411(4, 5, 7);
 52.1700 +  }
 52.1701 +  if (MUR) {
 52.1702 +    P1 = IC(4);
 52.1703 +  } else {
 52.1704 +    P1 = I211(4, 1, 5);
 52.1705 +  }
 52.1706 +} break;
 52.1707 +case 247 : 
 52.1708 +{
 52.1709 +  P0 = I31(4, 3);
 52.1710 +  P2 = I31(4, 3);
 52.1711 +  if (MDR) {
 52.1712 +    P3 = IC(4);
 52.1713 +  } else {
 52.1714 +    P3 = I1411(4, 5, 7);
 52.1715 +  }
 52.1716 +  if (MUR) {
 52.1717 +    P1 = IC(4);
 52.1718 +  } else {
 52.1719 +    P1 = I1411(4, 1, 5);
 52.1720 +  }
 52.1721 +} break;
 52.1722 +case 249 : 
 52.1723 +{
 52.1724 +  P0 = I31(4, 1);
 52.1725 +  P1 = I31(4, 2);
 52.1726 +  if (MDL) {
 52.1727 +    P2 = IC(4);
 52.1728 +  } else {
 52.1729 +    P2 = I1411(4, 3, 7);
 52.1730 +  }
 52.1731 +  if (MDR) {
 52.1732 +    P3 = IC(4);
 52.1733 +  } else {
 52.1734 +    P3 = I211(4, 5, 7);
 52.1735 +  }
 52.1736 +} break;
 52.1737 +case 251 : 
 52.1738 +{
 52.1739 +  P1 = I31(4, 2);
 52.1740 +  if (MDL) {
 52.1741 +    P2 = IC(4);
 52.1742 +  } else {
 52.1743 +    P2 = I1411(4, 3, 7);
 52.1744 +  }
 52.1745 +  if (MDR) {
 52.1746 +    P3 = IC(4);
 52.1747 +  } else {
 52.1748 +    P3 = I211(4, 5, 7);
 52.1749 +  }
 52.1750 +  if (MUL) {
 52.1751 +    P0 = IC(4);
 52.1752 +  } else {
 52.1753 +    P0 = I211(4, 1, 3);
 52.1754 +  }
 52.1755 +} break;
 52.1756 +case 252 : 
 52.1757 +{
 52.1758 +  P0 = I31(4, 0);
 52.1759 +  P1 = I31(4, 1);
 52.1760 +  if (MDL) {
 52.1761 +    P2 = IC(4);
 52.1762 +  } else {
 52.1763 +    P2 = I211(4, 3, 7);
 52.1764 +  }
 52.1765 +  if (MDR) {
 52.1766 +    P3 = IC(4);
 52.1767 +  } else {
 52.1768 +    P3 = I1411(4, 5, 7);
 52.1769 +  }
 52.1770 +} break;
 52.1771 +case 253 : 
 52.1772 +{
 52.1773 +  P0 = I31(4, 1);
 52.1774 +  P1 = I31(4, 1);
 52.1775 +  if (MDL) {
 52.1776 +    P2 = IC(4);
 52.1777 +  } else {
 52.1778 +    P2 = I1411(4, 3, 7);
 52.1779 +  }
 52.1780 +  if (MDR) {
 52.1781 +    P3 = IC(4);
 52.1782 +  } else {
 52.1783 +    P3 = I1411(4, 5, 7);
 52.1784 +  }
 52.1785 +} break;
 52.1786 +case 254 : 
 52.1787 +{
 52.1788 +  P0 = I31(4, 0);
 52.1789 +  if (MDL) {
 52.1790 +    P2 = IC(4);
 52.1791 +  } else {
 52.1792 +    P2 = I211(4, 3, 7);
 52.1793 +  }
 52.1794 +  if (MDR) {
 52.1795 +    P3 = IC(4);
 52.1796 +  } else {
 52.1797 +    P3 = I1411(4, 5, 7);
 52.1798 +  }
 52.1799 +  if (MUR) {
 52.1800 +    P1 = IC(4);
 52.1801 +  } else {
 52.1802 +    P1 = I211(4, 1, 5);
 52.1803 +  }
 52.1804 +} break;
 52.1805 +case 255 : 
 52.1806 +{
 52.1807 +  if (MDL) {
 52.1808 +    P2 = IC(4);
 52.1809 +  } else {
 52.1810 +    P2 = I1411(4, 3, 7);
 52.1811 +  }
 52.1812 +  if (MDR) {
 52.1813 +    P3 = IC(4);
 52.1814 +  } else {
 52.1815 +    P3 = I1411(4, 5, 7);
 52.1816 +  }
 52.1817 +  if (MUL) {
 52.1818 +    P0 = IC(4);
 52.1819 +  } else {
 52.1820 +    P0 = I1411(4, 1, 3);
 52.1821 +  }
 52.1822 +  if (MUR) {
 52.1823 +    P1 = IC(4);
 52.1824 +  } else {
 52.1825 +    P1 = I1411(4, 1, 5);
 52.1826 +  }
 52.1827 +} break;
    53.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.2 +++ b/src/filters/hq3x32.cpp	Sat Mar 03 10:31:27 2012 -0600
    53.3 @@ -0,0 +1,445 @@
    53.4 +#include "../Port.h"
    53.5 +#include "hq_shared32.h"
    53.6 +#include "interp.h"
    53.7 +
    53.8 +#define SIZE_PIXEL 2 // 16bit = 2 bytes
    53.9 +#define PIXELTYPE unsigned short
   53.10 +#define Interp1 Interp1_16
   53.11 +#define Interp2 Interp2_16
   53.12 +#define Interp3 Interp3_16
   53.13 +#define Interp4 Interp4_16
   53.14 +#define Interp5 Interp5_16
   53.15 +
   53.16 +void hq3x(unsigned char *pIn,  unsigned int srcPitch,
   53.17 +          unsigned char *,
   53.18 +          unsigned char *pOut, unsigned int dstPitch,
   53.19 +          int Xres, int Yres)
   53.20 +{
   53.21 +	int i, j;
   53.22 +	unsigned int line;
   53.23 +	PIXELTYPE	 c[10];
   53.24 +
   53.25 +	// +----+----+----+
   53.26 +	// |    |    |    |
   53.27 +	// | c1 | c2 | c3 |
   53.28 +	// +----+----+----+
   53.29 +	// |    |    |    |
   53.30 +	// | c4 | c5 | c6 |
   53.31 +	// +----+----+----+
   53.32 +	// |    |    |    |
   53.33 +	// | c7 | c8 | c9 |
   53.34 +	// +----+----+----+
   53.35 +
   53.36 +	for (j = 0; j < Yres; j++)
   53.37 +	{
   53.38 +		if ((j > 0) || (j < Yres - 1))
   53.39 +			line = srcPitch;
   53.40 +		else
   53.41 +			line = 0;
   53.42 +
   53.43 +		for (i = 0; i < Xres; i++)
   53.44 +		{
   53.45 +			c[2] = *((PIXELTYPE *)(pIn - line));
   53.46 +			c[5] = *((PIXELTYPE *)(pIn));
   53.47 +			c[8] = *((PIXELTYPE *)(pIn + line));
   53.48 +
   53.49 +			if (i > 0)
   53.50 +			{
   53.51 +				c[1] = *((PIXELTYPE *)(pIn - line - SIZE_PIXEL));
   53.52 +				c[4] = *((PIXELTYPE *)(pIn        - SIZE_PIXEL));
   53.53 +				c[7] = *((PIXELTYPE *)(pIn + line - SIZE_PIXEL));
   53.54 +			}
   53.55 +			else
   53.56 +			{
   53.57 +				c[1] = c[2];
   53.58 +				c[4] = c[5];
   53.59 +				c[7] = c[8];
   53.60 +			}
   53.61 +
   53.62 +			if (i < Xres - 1)
   53.63 +			{
   53.64 +				c[3] = *((PIXELTYPE *)(pIn - line + SIZE_PIXEL));
   53.65 +				c[6] = *((PIXELTYPE *)(pIn        + SIZE_PIXEL));
   53.66 +				c[9] = *((PIXELTYPE *)(pIn + line + SIZE_PIXEL));
   53.67 +			}
   53.68 +			else
   53.69 +			{
   53.70 +				c[3] = c[2];
   53.71 +				c[6] = c[5];
   53.72 +				c[9] = c[8];
   53.73 +			}
   53.74 +
   53.75 +			int pattern = 0;
   53.76 +
   53.77 +			if (interp_16_diff(c[1], c[5]))
   53.78 +				pattern |= 1 << 0;
   53.79 +			if (interp_16_diff(c[2], c[5]))
   53.80 +				pattern |= 1 << 1;
   53.81 +			if (interp_16_diff(c[3], c[5]))
   53.82 +				pattern |= 1 << 2;
   53.83 +			if (interp_16_diff(c[4], c[5]))
   53.84 +				pattern |= 1 << 3;
   53.85 +			if (interp_16_diff(c[6], c[5]))
   53.86 +				pattern |= 1 << 4;
   53.87 +			if (interp_16_diff(c[7], c[5]))
   53.88 +				pattern |= 1 << 5;
   53.89 +			if (interp_16_diff(c[8], c[5]))
   53.90 +				pattern |= 1 << 6;
   53.91 +			if (interp_16_diff(c[9], c[5]))
   53.92 +				pattern |= 1 << 7;
   53.93 +
   53.94 +#define Diff interp_16_diff
   53.95 +#include "hq3x32.h"
   53.96 +#undef Diff
   53.97 +			pIn	 += SIZE_PIXEL;
   53.98 +			pOut += 3 << 1;
   53.99 +		}
  53.100 +		pIn	 += srcPitch - (Xres << 1);
  53.101 +		pOut += dstPitch - (3 * Xres << 1);
  53.102 +		pOut += dstPitch << 1;
  53.103 +		//	pIn+=SIZE_PIXEL;
  53.104 +		//	pOut+=3*SIZE_PIXEL;
  53.105 +		//}
  53.106 +		//pIn+=srcPitch-(4*Xres);
  53.107 +		//pOut+=dstPitch-(3*Xres*SIZE_PIXEL);
  53.108 +		//pOut+=2*dstPitch;
  53.109 +	}
  53.110 +}
  53.111 +
  53.112 +void hq3xS(unsigned char *pIn,  unsigned int srcPitch,
  53.113 +           unsigned char *,
  53.114 +           unsigned char *pOut, unsigned int dstPitch,
  53.115 +           int Xres, int Yres)
  53.116 +{
  53.117 +	int i, j;
  53.118 +	PIXELTYPE c[10];
  53.119 +
  53.120 +	// +----+----+----+
  53.121 +	// |    |    |    |
  53.122 +	// | c1 | c2 | c3 |
  53.123 +	// +----+----+----+
  53.124 +	// |    |    |    |
  53.125 +	// | c4 | c5 | c6 |
  53.126 +	// +----+----+----+
  53.127 +	// |    |    |    |
  53.128 +	// | c7 | c8 | c9 |
  53.129 +	// +----+----+----+
  53.130 +
  53.131 +	for (j = 0; j < Yres; j++)
  53.132 +	{
  53.133 +		for (i = 0; i < Xres; i++)
  53.134 +		{
  53.135 +			c[2] = *((PIXELTYPE *)(pIn - srcPitch));
  53.136 +			c[5] = *((PIXELTYPE *)(pIn));
  53.137 +			c[8] = *((PIXELTYPE *)(pIn + srcPitch));
  53.138 +
  53.139 +			c[1] = *((PIXELTYPE *)(pIn - srcPitch - SIZE_PIXEL));
  53.140 +			c[4] = *((PIXELTYPE *)(pIn        - SIZE_PIXEL));
  53.141 +			c[7] = *((PIXELTYPE *)(pIn + srcPitch - SIZE_PIXEL));
  53.142 +
  53.143 +			c[3] = *((PIXELTYPE *)(pIn - srcPitch + SIZE_PIXEL));
  53.144 +			c[6] = *((PIXELTYPE *)(pIn        + SIZE_PIXEL));
  53.145 +			c[9] = *((PIXELTYPE *)(pIn + srcPitch + SIZE_PIXEL));
  53.146 +
  53.147 +			int pattern = 0;
  53.148 +
  53.149 +			// hq3xS dynamic edge detection:
  53.150 +			// simply comparing the center color against its surroundings will give bad results in many cases,
  53.151 +			// so, instead, compare the center color relative to the max difference in brightness of this 3x3 block
  53.152 +			int brightArray[10];
  53.153 +			int maxBright = 0, minBright = 999999;
  53.154 +			for (int j = 1; j < 10; j++)
  53.155 +			{
  53.156 +				int r, g, b;
  53.157 +				if (interp_bits_per_pixel == 16)
  53.158 +				{
  53.159 +					b = (int)((c[j] & 0x1F)) << 3;
  53.160 +					g = (int)((c[j] & 0x7E0)) >> 3;
  53.161 +					r = (int)((c[j] & 0xF800)) >> 8;
  53.162 +				}
  53.163 +				else
  53.164 +				{
  53.165 +					b = (int)((c[j] & 0x1F)) << 3;
  53.166 +					g = (int)((c[j] & 0x3E0)) >> 2;
  53.167 +					r = (int)((c[j] & 0x7C00)) >> 7;
  53.168 +				}
  53.169 +				const int bright = r + r + r + g + g + g + b + b;
  53.170 +				if (bright > maxBright) maxBright = bright;
  53.171 +				if (bright < minBright) minBright = bright;
  53.172 +
  53.173 +				brightArray[j] = bright;
  53.174 +			}
  53.175 +			const int diffBright = ((maxBright - minBright) * 7) >> 4;
  53.176 +			if (diffBright > 7)
  53.177 +			{
  53.178 +				#define ABS(x) ((x) < 0 ? -(x) : (x))
  53.179 +
  53.180 +				const int centerBright = brightArray[5];
  53.181 +				if (ABS(brightArray[1] - centerBright) > diffBright)
  53.182 +					pattern |= 1 << 0;
  53.183 +				if (ABS(brightArray[2] - centerBright) > diffBright)
  53.184 +					pattern |= 1 << 1;
  53.185 +				if (ABS(brightArray[3] - centerBright) > diffBright)
  53.186 +					pattern |= 1 << 2;
  53.187 +				if (ABS(brightArray[4] - centerBright) > diffBright)
  53.188 +					pattern |= 1 << 3;
  53.189 +				if (ABS(brightArray[6] - centerBright) > diffBright)
  53.190 +					pattern |= 1 << 4;
  53.191 +				if (ABS(brightArray[7] - centerBright) > diffBright)
  53.192 +					pattern |= 1 << 5;
  53.193 +				if (ABS(brightArray[8] - centerBright) > diffBright)
  53.194 +					pattern |= 1 << 6;
  53.195 +				if (ABS(brightArray[9] - centerBright) > diffBright)
  53.196 +					pattern |= 1 << 7;
  53.197 +			}
  53.198 +
  53.199 +#define Diff(x, y) false //(ABS((x) - (y)) > diffBright)
  53.200 +#undef cget
  53.201 +#define cget(x) brightArray[x]
  53.202 +#include "hq3x32.h"
  53.203 +#undef cget
  53.204 +#undef Diff
  53.205 +			pIn	 += SIZE_PIXEL;
  53.206 +			pOut += 3 << 1;
  53.207 +		}
  53.208 +		pIn	 += srcPitch - (Xres << 1);
  53.209 +		pOut += dstPitch - (3 * Xres << 1);
  53.210 +		pOut += dstPitch << 1;
  53.211 +		//	pIn+=SIZE_PIXEL;
  53.212 +		//	pOut+=3*SIZE_PIXEL;
  53.213 +		//}
  53.214 +		//pIn+=srcPitch-(4*Xres);
  53.215 +		//pOut+=dstPitch-(3*Xres*SIZE_PIXEL);
  53.216 +		//pOut+=2*dstPitch;
  53.217 +	}
  53.218 +}
  53.219 +
  53.220 +#undef Interp1
  53.221 +#undef Interp2
  53.222 +#undef Interp3
  53.223 +#undef Interp4
  53.224 +#undef Interp5
  53.225 +#undef SIZE_PIXEL
  53.226 +#undef PIXELTYPE
  53.227 +#define SIZE_PIXEL 4 // 32bit = 4 bytes
  53.228 +#define PIXELTYPE unsigned int
  53.229 +
  53.230 +void hq3x32(unsigned char *pIn,  unsigned int srcPitch,
  53.231 +            unsigned char *,
  53.232 +            unsigned char *pOut, unsigned int dstPitch,
  53.233 +            int Xres, int Yres)
  53.234 +{
  53.235 +	unsigned int YUV1, YUV2;
  53.236 +	int i, j, k;
  53.237 +	unsigned int line;
  53.238 +	PIXELTYPE c[10];
  53.239 +
  53.240 +	// +----+----+----+
  53.241 +	// |    |    |    |
  53.242 +	// | c1 | c2 | c3 |
  53.243 +	// +----+----+----+
  53.244 +	// |    |    |    |
  53.245 +	// | c4 | c5 | c6 |
  53.246 +	// +----+----+----+
  53.247 +	// |    |    |    |
  53.248 +	// | c7 | c8 | c9 |
  53.249 +	// +----+----+----+
  53.250 +
  53.251 +	for (j = 0; j < Yres; j++)
  53.252 +	{
  53.253 +		if ((j > 0) && (j < Yres - 1))
  53.254 +			line = srcPitch;
  53.255 +		else
  53.256 +			line = 0;
  53.257 +
  53.258 +		for (i = 0; i < Xres; i++)
  53.259 +		{
  53.260 +			c[2] = *((PIXELTYPE *)(pIn - line));
  53.261 +			c[5] = *((PIXELTYPE *)(pIn));
  53.262 +			c[8] = *((PIXELTYPE *)(pIn + line));
  53.263 +
  53.264 +			if (i > 0)
  53.265 +			{
  53.266 +				c[1] = *((PIXELTYPE *)(pIn - line - SIZE_PIXEL));
  53.267 +				c[4] = *((PIXELTYPE *)(pIn        - SIZE_PIXEL));
  53.268 +				c[7] = *((PIXELTYPE *)(pIn + line - SIZE_PIXEL));
  53.269 +			}
  53.270 +			else
  53.271 +			{
  53.272 +				c[1] = c[2];
  53.273 +				c[4] = c[5];
  53.274 +				c[7] = c[8];
  53.275 +			}
  53.276 +
  53.277 +			if (i < Xres - 1)
  53.278 +			{
  53.279 +				c[3] = *((PIXELTYPE *)(pIn - line + SIZE_PIXEL));
  53.280 +				c[6] = *((PIXELTYPE *)(pIn        + SIZE_PIXEL));
  53.281 +				c[9] = *((PIXELTYPE *)(pIn + line + SIZE_PIXEL));
  53.282 +			}
  53.283 +			else
  53.284 +			{
  53.285 +				c[3] = c[2];
  53.286 +				c[6] = c[5];
  53.287 +				c[9] = c[8];
  53.288 +			}
  53.289 +
  53.290 +			int pattern = 0;
  53.291 +			int flag	= 1;
  53.292 +
  53.293 +			YUV1 = RGBtoYUV(c[5]);
  53.294 +
  53.295 +			for (k = 1; k <= 9; k++)
  53.296 +			{
  53.297 +				if (k == 5) continue;
  53.298 +
  53.299 +				if (c[k] != c[5])
  53.300 +				{
  53.301 +					YUV2 = RGBtoYUV(c[k]);
  53.302 +					if (
  53.303 +					    (abs32((YUV1 & Ymask) - (YUV2 & Ymask)) > trY) ||
  53.304 +					    (abs32((YUV1 & Umask) - (YUV2 & Umask)) > trU) ||
  53.305 +					    (abs32((YUV1 & Vmask) - (YUV2 & Vmask)) > trV)
  53.306 +					    )
  53.307 +						pattern |= flag;
  53.308 +				}
  53.309 +				flag <<= 1;
  53.310 +			}
  53.311 +
  53.312 +#include "hq3x32.h"
  53.313 +			pIn	 += SIZE_PIXEL;
  53.314 +			pOut += 3 << 2;
  53.315 +		}
  53.316 +		pIn	 += srcPitch - (Xres << 2);
  53.317 +		pOut += dstPitch - (3 * Xres << 2);
  53.318 +		pOut += dstPitch << 1;
  53.319 +		//	pIn+=SIZE_PIXEL;
  53.320 +		//	pOut+=3*SIZE_PIXEL;
  53.321 +		//}
  53.322 +		//pIn+=srcPitch-(4*Xres);
  53.323 +		//pOut+=dstPitch-(3*Xres*SIZE_PIXEL);
  53.324 +		//pOut+=2*dstPitch;
  53.325 +	}
  53.326 +}
  53.327 +
  53.328 +void hq3xS32(unsigned char *pIn,  unsigned int srcPitch,
  53.329 +             unsigned char *,
  53.330 +             unsigned char *pOut, unsigned int dstPitch,
  53.331 +             int Xres, int Yres)
  53.332 +{
  53.333 +	int i, j;
  53.334 +	unsigned int line;
  53.335 +	PIXELTYPE c[10];
  53.336 +
  53.337 +	// +----+----+----+
  53.338 +	// |    |    |    |
  53.339 +	// | c1 | c2 | c3 |
  53.340 +	// +----+----+----+
  53.341 +	// |    |    |    |
  53.342 +	// | c4 | c5 | c6 |
  53.343 +	// +----+----+----+
  53.344 +	// |    |    |    |
  53.345 +	// | c7 | c8 | c9 |
  53.346 +	// +----+----+----+
  53.347 +
  53.348 +	for (j = 0; j < Yres; j++)
  53.349 +	{
  53.350 +		if ((j > 0) && (j < Yres - 1))
  53.351 +			line = srcPitch;
  53.352 +		else
  53.353 +			line = 0;
  53.354 +
  53.355 +		for (i = 0; i < Xres; i++)
  53.356 +		{
  53.357 +			c[2] = *((PIXELTYPE *)(pIn - line));
  53.358 +			c[5] = *((PIXELTYPE *)(pIn));
  53.359 +			c[8] = *((PIXELTYPE *)(pIn + line));
  53.360 +
  53.361 +			if (i > 0)
  53.362 +			{
  53.363 +				c[1] = *((PIXELTYPE *)(pIn - line - SIZE_PIXEL));
  53.364 +				c[4] = *((PIXELTYPE *)(pIn        - SIZE_PIXEL));
  53.365 +				c[7] = *((PIXELTYPE *)(pIn + line - SIZE_PIXEL));
  53.366 +			}
  53.367 +			else
  53.368 +			{
  53.369 +				c[1] = c[2];
  53.370 +				c[4] = c[5];
  53.371 +				c[7] = c[8];
  53.372 +			}
  53.373 +
  53.374 +			if (i < Xres - 1)
  53.375 +			{
  53.376 +				c[3] = *((PIXELTYPE *)(pIn - line + SIZE_PIXEL));
  53.377 +				c[6] = *((PIXELTYPE *)(pIn        + SIZE_PIXEL));
  53.378 +				c[9] = *((PIXELTYPE *)(pIn + line + SIZE_PIXEL));
  53.379 +			}
  53.380 +			else
  53.381 +			{
  53.382 +				c[3] = c[2];
  53.383 +				c[6] = c[5];
  53.384 +				c[9] = c[8];
  53.385 +			}
  53.386 +
  53.387 +			int pattern = 0;
  53.388 +
  53.389 +			// hq3xS dynamic edge detection:
  53.390 +			// simply comparing the center color against its surroundings will give bad results in many cases,
  53.391 +			// so, instead, compare the center color relative to the max difference in brightness of this 3x3 block
  53.392 +			int brightArray[10];
  53.393 +			int maxBright = 0, minBright = 999999;
  53.394 +			for (int j = 1; j < 10; j++)
  53.395 +			{
  53.396 +				const int b		 = (int)((c[j] & 0xF8));
  53.397 +				const int g		 = (int)((c[j] & 0xF800)) >> 8;
  53.398 +				const int r		 = (int)((c[j] & 0xF80000)) >> 16;
  53.399 +				const int bright = r + r + r + g + g + g + b + b;
  53.400 +				if (bright > maxBright) maxBright = bright;
  53.401 +				if (bright < minBright) minBright = bright;
  53.402 +
  53.403 +				brightArray[j] = bright;
  53.404 +			}
  53.405 +			int diffBright = ((maxBright - minBright) * 7) >> 4;
  53.406 +			if (diffBright > 7)
  53.407 +			{
  53.408 +				#define ABS(x) ((x) < 0 ? -(x) : (x))
  53.409 +
  53.410 +				const int centerBright = brightArray[5];
  53.411 +				if (ABS(brightArray[1] - centerBright) > diffBright)
  53.412 +					pattern |= 1 << 0;
  53.413 +				if (ABS(brightArray[2] - centerBright) > diffBright)
  53.414 +					pattern |= 1 << 1;
  53.415 +				if (ABS(brightArray[3] - centerBright) > diffBright)
  53.416 +					pattern |= 1 << 2;
  53.417 +				if (ABS(brightArray[4] - centerBright) > diffBright)
  53.418 +					pattern |= 1 << 3;
  53.419 +				if (ABS(brightArray[6] - centerBright) > diffBright)
  53.420 +					pattern |= 1 << 4;
  53.421 +				if (ABS(brightArray[7] - centerBright) > diffBright)
  53.422 +					pattern |= 1 << 5;
  53.423 +				if (ABS(brightArray[8] - centerBright) > diffBright)
  53.424 +					pattern |= 1 << 6;
  53.425 +				if (ABS(brightArray[9] - centerBright) > diffBright)
  53.426 +					pattern |= 1 << 7;
  53.427 +			}
  53.428 +
  53.429 +#define Diff(x, y) false //(ABS((x) - (y)) > diffBright)
  53.430 +#undef cget
  53.431 +#define cget(x) brightArray[x]
  53.432 +#include "hq3x32.h"
  53.433 +#undef cget
  53.434 +#undef Diff
  53.435 +			pIn	 += SIZE_PIXEL;
  53.436 +			pOut += 3 << 2;
  53.437 +		}
  53.438 +		pIn	 += srcPitch - (Xres << 2);
  53.439 +		pOut += dstPitch - (3 * Xres << 2);
  53.440 +		pOut += dstPitch << 1;
  53.441 +		//	pIn+=SIZE_PIXEL;
  53.442 +		//	pOut+=3*SIZE_PIXEL;
  53.443 +		//}
  53.444 +		//pIn+=srcPitch-(4*Xres);
  53.445 +		//pOut+=dstPitch-(3*Xres*SIZE_PIXEL);
  53.446 +		//pOut+=2*dstPitch;
  53.447 +	}
  53.448 +}
  53.449 \ No newline at end of file
    54.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    54.2 +++ b/src/filters/hq3x32.h	Sat Mar 03 10:31:27 2012 -0600
    54.3 @@ -0,0 +1,3674 @@
    54.4 +#define PIXEL00_1M  Interp1( pOut, c[5], c[1]       );
    54.5 +#define PIXEL00_1U  Interp1( pOut, c[5], c[2]       );
    54.6 +#define PIXEL00_1L  Interp1( pOut, c[5], c[4]       );
    54.7 +#define PIXEL00_2   Interp2( pOut, c[5], c[4], c[2] );
    54.8 +#define PIXEL00_4   Interp4( pOut, c[5], c[4], c[2] );
    54.9 +#define PIXEL00_5   Interp5( pOut, c[4], c[2]       );
   54.10 +#define PIXEL00_C   *((PIXELTYPE*)(pOut)) = c[5];
   54.11 +
   54.12 +#define PIXEL01_1   Interp1( pOut+SIZE_PIXEL, c[5], c[2] );
   54.13 +#define PIXEL01_3   Interp3( pOut+SIZE_PIXEL, c[5], c[2] );
   54.14 +#define PIXEL01_6   Interp1( pOut+SIZE_PIXEL, c[2], c[5] );
   54.15 +#define PIXEL01_C   *((PIXELTYPE*)(pOut+SIZE_PIXEL)) = c[5];
   54.16 +
   54.17 +#define PIXEL02_1M  Interp1( pOut+SIZE_PIXEL+SIZE_PIXEL, c[5], c[3]       );
   54.18 +#define PIXEL02_1U  Interp1( pOut+SIZE_PIXEL+SIZE_PIXEL, c[5], c[2]       );
   54.19 +#define PIXEL02_1R  Interp1( pOut+SIZE_PIXEL+SIZE_PIXEL, c[5], c[6]       );
   54.20 +#define PIXEL02_2   Interp2( pOut+SIZE_PIXEL+SIZE_PIXEL, c[5], c[2], c[6] );
   54.21 +#define PIXEL02_4   Interp4( pOut+SIZE_PIXEL+SIZE_PIXEL, c[5], c[2], c[6] );
   54.22 +#define PIXEL02_5   Interp5( pOut+SIZE_PIXEL+SIZE_PIXEL, c[2], c[6]       );
   54.23 +#define PIXEL02_C   *((PIXELTYPE*)(pOut+SIZE_PIXEL+SIZE_PIXEL)) = c[5];
   54.24 +
   54.25 +#define PIXEL10_1   Interp1( pOut+dstPitch, c[5], c[4] );
   54.26 +#define PIXEL10_3   Interp3( pOut+dstPitch, c[5], c[4] );
   54.27 +#define PIXEL10_6   Interp1( pOut+dstPitch, c[4], c[5] );
   54.28 +#define PIXEL10_C   *((PIXELTYPE*)(pOut+dstPitch)) = c[5];
   54.29 +
   54.30 +#define PIXEL11     *((PIXELTYPE*)(pOut+dstPitch+SIZE_PIXEL)) = c[5];
   54.31 +
   54.32 +#define PIXEL12_1   Interp1( pOut+dstPitch+SIZE_PIXEL+SIZE_PIXEL, c[5], c[6] );
   54.33 +#define PIXEL12_3   Interp3( pOut+dstPitch+SIZE_PIXEL+SIZE_PIXEL, c[5], c[6] );
   54.34 +#define PIXEL12_6   Interp1( pOut+dstPitch+SIZE_PIXEL+SIZE_PIXEL, c[6], c[5] );
   54.35 +#define PIXEL12_C   *((PIXELTYPE*)(pOut+dstPitch+SIZE_PIXEL+SIZE_PIXEL)) = c[5];
   54.36 +
   54.37 +#define PIXEL20_1M  Interp1( pOut+dstPitch+dstPitch, c[5], c[7]       );
   54.38 +#define PIXEL20_1D  Interp1( pOut+dstPitch+dstPitch, c[5], c[8]       );
   54.39 +#define PIXEL20_1L  Interp1( pOut+dstPitch+dstPitch, c[5], c[4]       );
   54.40 +#define PIXEL20_2   Interp2( pOut+dstPitch+dstPitch, c[5], c[8], c[4] );
   54.41 +#define PIXEL20_4   Interp4( pOut+dstPitch+dstPitch, c[5], c[8], c[4] );
   54.42 +#define PIXEL20_5   Interp5( pOut+dstPitch+dstPitch, c[8], c[4]       );
   54.43 +#define PIXEL20_C   *((PIXELTYPE*)(pOut+dstPitch+dstPitch)) = c[5];
   54.44 +
   54.45 +#define PIXEL21_1   Interp1( pOut+dstPitch+dstPitch+SIZE_PIXEL, c[5], c[8] );
   54.46 +#define PIXEL21_3   Interp3( pOut+dstPitch+dstPitch+SIZE_PIXEL, c[5], c[8] );
   54.47 +#define PIXEL21_6   Interp1( pOut+dstPitch+dstPitch+SIZE_PIXEL, c[8], c[5] );
   54.48 +#define PIXEL21_C   *((PIXELTYPE*)(pOut+dstPitch+dstPitch+SIZE_PIXEL)) = c[5];
   54.49 +
   54.50 +#define PIXEL22_1M  Interp1( pOut+dstPitch+dstPitch+SIZE_PIXEL+SIZE_PIXEL, c[5], c[9]       );
   54.51 +#define PIXEL22_1D  Interp1( pOut+dstPitch+dstPitch+SIZE_PIXEL+SIZE_PIXEL, c[5], c[8]       );
   54.52 +#define PIXEL22_1R  Interp1( pOut+dstPitch+dstPitch+SIZE_PIXEL+SIZE_PIXEL, c[5], c[6]       );
   54.53 +#define PIXEL22_2   Interp2( pOut+dstPitch+dstPitch+SIZE_PIXEL+SIZE_PIXEL, c[5], c[6], c[8] );
   54.54 +#define PIXEL22_4   Interp4( pOut+dstPitch+dstPitch+SIZE_PIXEL+SIZE_PIXEL, c[5], c[6], c[8] );
   54.55 +#define PIXEL22_5   Interp5( pOut+dstPitch+dstPitch+SIZE_PIXEL+SIZE_PIXEL, c[6], c[8]       );
   54.56 +#define PIXEL22_C   *((PIXELTYPE*)(pOut+dstPitch+dstPitch+SIZE_PIXEL+SIZE_PIXEL)) = c[5];
   54.57 +
   54.58 +#ifndef cget
   54.59 +#define cget(x) c[x]
   54.60 +#endif
   54.61 +
   54.62 +      switch (pattern)
   54.63 +      {
   54.64 +        case 0:
   54.65 +        case 1:
   54.66 +        case 4:
   54.67 +        case 32:
   54.68 +        case 128:
   54.69 +        case 5:
   54.70 +        case 132:
   54.71 +        case 160:
   54.72 +        case 33:
   54.73 +        case 129:
   54.74 +        case 36:
   54.75 +        case 133:
   54.76 +        case 164:
   54.77 +        case 161:
   54.78 +        case 37:
   54.79 +        case 165:
   54.80 +        {
   54.81 +          PIXEL00_2
   54.82 +          PIXEL01_1
   54.83 +          PIXEL02_2
   54.84 +          PIXEL10_1
   54.85 +          PIXEL11
   54.86 +          PIXEL12_1
   54.87 +          PIXEL20_2
   54.88 +          PIXEL21_1
   54.89 +          PIXEL22_2
   54.90 +          break;
   54.91 +        }
   54.92 +        case 2:
   54.93 +        case 34:
   54.94 +        case 130:
   54.95 +        case 162:
   54.96 +        {
   54.97 +          PIXEL00_1M
   54.98 +          PIXEL01_C
   54.99 +          PIXEL02_1M
  54.100 +          PIXEL10_1
  54.101 +          PIXEL11
  54.102 +          PIXEL12_1
  54.103 +          PIXEL20_2
  54.104 +          PIXEL21_1
  54.105 +          PIXEL22_2
  54.106 +          break;
  54.107 +        }
  54.108 +        case 16:
  54.109 +        case 17:
  54.110 +        case 48:
  54.111 +        case 49:
  54.112 +        {
  54.113 +          PIXEL00_2
  54.114 +          PIXEL01_1
  54.115 +          PIXEL02_1M
  54.116 +          PIXEL10_1
  54.117 +          PIXEL11
  54.118 +          PIXEL12_C
  54.119 +          PIXEL20_2
  54.120 +          PIXEL21_1
  54.121 +          PIXEL22_1M
  54.122 +          break;
  54.123 +        }
  54.124 +        case 64:
  54.125 +        case 65:
  54.126 +        case 68:
  54.127 +        case 69:
  54.128 +        {
  54.129 +          PIXEL00_2
  54.130 +          PIXEL01_1
  54.131 +          PIXEL02_2
  54.132 +          PIXEL10_1
  54.133 +          PIXEL11
  54.134 +          PIXEL12_1
  54.135 +          PIXEL20_1M
  54.136 +          PIXEL21_C
  54.137 +          PIXEL22_1M
  54.138 +          break;
  54.139 +        }
  54.140 +        case 8:
  54.141 +        case 12:
  54.142 +        case 136:
  54.143 +        case 140:
  54.144 +        {
  54.145 +          PIXEL00_1M
  54.146 +          PIXEL01_1
  54.147 +          PIXEL02_2
  54.148 +          PIXEL10_C
  54.149 +          PIXEL11
  54.150 +          PIXEL12_1
  54.151 +          PIXEL20_1M
  54.152 +          PIXEL21_1
  54.153 +          PIXEL22_2
  54.154 +          break;
  54.155 +        }
  54.156 +        case 3:
  54.157 +        case 35:
  54.158 +        case 131:
  54.159 +        case 163:
  54.160 +        {
  54.161 +          PIXEL00_1L
  54.162 +          PIXEL01_C
  54.163 +          PIXEL02_1M
  54.164 +          PIXEL10_1
  54.165 +          PIXEL11
  54.166 +          PIXEL12_1
  54.167 +          PIXEL20_2
  54.168 +          PIXEL21_1
  54.169 +          PIXEL22_2
  54.170 +          break;
  54.171 +        }
  54.172 +        case 6:
  54.173 +        case 38:
  54.174 +        case 134:
  54.175 +        case 166:
  54.176 +        {
  54.177 +          PIXEL00_1M
  54.178 +          PIXEL01_C
  54.179 +          PIXEL02_1R
  54.180 +          PIXEL10_1
  54.181 +          PIXEL11
  54.182 +          PIXEL12_1
  54.183 +          PIXEL20_2
  54.184 +          PIXEL21_1
  54.185 +          PIXEL22_2
  54.186 +          break;
  54.187 +        }
  54.188 +        case 20:
  54.189 +        case 21:
  54.190 +        case 52:
  54.191 +        case 53:
  54.192 +        {
  54.193 +          PIXEL00_2
  54.194 +          PIXEL01_1
  54.195 +          PIXEL02_1U
  54.196 +          PIXEL10_1
  54.197 +          PIXEL11
  54.198 +          PIXEL12_C
  54.199 +          PIXEL20_2
  54.200 +          PIXEL21_1
  54.201 +          PIXEL22_1M
  54.202 +          break;
  54.203 +        }
  54.204 +        case 144:
  54.205 +        case 145:
  54.206 +        case 176:
  54.207 +        case 177:
  54.208 +        {
  54.209 +          PIXEL00_2
  54.210 +          PIXEL01_1
  54.211 +          PIXEL02_1M
  54.212 +          PIXEL10_1
  54.213 +          PIXEL11
  54.214 +          PIXEL12_C
  54.215 +          PIXEL20_2
  54.216 +          PIXEL21_1
  54.217 +          PIXEL22_1D
  54.218 +          break;
  54.219 +        }
  54.220 +        case 192:
  54.221 +        case 193:
  54.222 +        case 196:
  54.223 +        case 197:
  54.224 +        {
  54.225 +          PIXEL00_2
  54.226 +          PIXEL01_1
  54.227 +          PIXEL02_2
  54.228 +          PIXEL10_1
  54.229 +          PIXEL11
  54.230 +          PIXEL12_1
  54.231 +          PIXEL20_1M
  54.232 +          PIXEL21_C
  54.233 +          PIXEL22_1R
  54.234 +          break;
  54.235 +        }
  54.236 +        case 96:
  54.237 +        case 97:
  54.238 +        case 100:
  54.239 +        case 101:
  54.240 +        {
  54.241 +          PIXEL00_2
  54.242 +          PIXEL01_1
  54.243 +          PIXEL02_2
  54.244 +          PIXEL10_1
  54.245 +          PIXEL11
  54.246 +          PIXEL12_1
  54.247 +          PIXEL20_1L
  54.248 +          PIXEL21_C
  54.249 +          PIXEL22_1M
  54.250 +          break;
  54.251 +        }
  54.252 +        case 40:
  54.253 +        case 44:
  54.254 +        case 168:
  54.255 +        case 172:
  54.256 +        {
  54.257 +          PIXEL00_1M
  54.258 +          PIXEL01_1
  54.259 +          PIXEL02_2
  54.260 +          PIXEL10_C
  54.261 +          PIXEL11
  54.262 +          PIXEL12_1
  54.263 +          PIXEL20_1D
  54.264 +          PIXEL21_1
  54.265 +          PIXEL22_2
  54.266 +          break;
  54.267 +        }
  54.268 +        case 9:
  54.269 +        case 13:
  54.270 +        case 137:
  54.271 +        case 141:
  54.272 +        {
  54.273 +          PIXEL00_1U
  54.274 +          PIXEL01_1
  54.275 +          PIXEL02_2
  54.276 +          PIXEL10_C
  54.277 +          PIXEL11
  54.278 +          PIXEL12_1
  54.279 +          PIXEL20_1M
  54.280 +          PIXEL21_1
  54.281 +          PIXEL22_2
  54.282 +          break;
  54.283 +        }
  54.284 +        case 18:
  54.285 +        case 50:
  54.286 +        {
  54.287 +          PIXEL00_1M
  54.288 +			  
  54.289 +		if (Diff(cget(2), cget(6)))
  54.290 +          {
  54.291 +            PIXEL01_C
  54.292 +            PIXEL02_1M
  54.293 +            PIXEL12_C
  54.294 +          }
  54.295 +          else
  54.296 +          {
  54.297 +            PIXEL01_3
  54.298 +            PIXEL02_4
  54.299 +            PIXEL12_3
  54.300 +          }
  54.301 +          PIXEL10_1
  54.302 +          PIXEL11
  54.303 +          PIXEL20_2
  54.304 +          PIXEL21_1
  54.305 +          PIXEL22_1M
  54.306 +          break;
  54.307 +        }
  54.308 +        case 80:
  54.309 +        case 81:
  54.310 +        {
  54.311 +          PIXEL00_2
  54.312 +          PIXEL01_1
  54.313 +          PIXEL02_1M
  54.314 +          PIXEL10_1
  54.315 +          PIXEL11
  54.316 +          PIXEL20_1M
  54.317 +          if (Diff(cget(6), cget(8)))
  54.318 +          {
  54.319 +            PIXEL12_C
  54.320 +            PIXEL21_C
  54.321 +            PIXEL22_1M
  54.322 +          }
  54.323 +          else
  54.324 +          {
  54.325 +            PIXEL12_3
  54.326 +            PIXEL21_3
  54.327 +            PIXEL22_4
  54.328 +          }
  54.329 +          break;
  54.330 +        }
  54.331 +        case 72:
  54.332 +        case 76:
  54.333 +        {
  54.334 +          PIXEL00_1M
  54.335 +          PIXEL01_1
  54.336 +          PIXEL02_2
  54.337 +          PIXEL11
  54.338 +          PIXEL12_1
  54.339 +          if (Diff(cget(8), cget(4)))
  54.340 +          {
  54.341 +            PIXEL10_C
  54.342 +            PIXEL20_1M
  54.343 +            PIXEL21_C
  54.344 +          }
  54.345 +          else
  54.346 +          {
  54.347 +            PIXEL10_3
  54.348 +            PIXEL20_4
  54.349 +            PIXEL21_3
  54.350 +          }
  54.351 +          PIXEL22_1M
  54.352 +          break;
  54.353 +        }
  54.354 +        case 10:
  54.355 +        case 138:
  54.356 +        {
  54.357 +          if (Diff(cget(4), cget(2)))
  54.358 +          {
  54.359 +            PIXEL00_1M
  54.360 +            PIXEL01_C
  54.361 +            PIXEL10_C
  54.362 +          }
  54.363 +          else
  54.364 +          {
  54.365 +            PIXEL00_4
  54.366 +            PIXEL01_3
  54.367 +            PIXEL10_3
  54.368 +          }
  54.369 +          PIXEL02_1M
  54.370 +          PIXEL11
  54.371 +          PIXEL12_1
  54.372 +          PIXEL20_1M
  54.373 +          PIXEL21_1
  54.374 +          PIXEL22_2
  54.375 +          break;
  54.376 +        }
  54.377 +        case 66:
  54.378 +        {
  54.379 +          PIXEL00_1M
  54.380 +          PIXEL01_C
  54.381 +          PIXEL02_1M
  54.382 +          PIXEL10_1
  54.383 +          PIXEL11
  54.384 +          PIXEL12_1
  54.385 +          PIXEL20_1M
  54.386 +          PIXEL21_C
  54.387 +          PIXEL22_1M
  54.388 +          break;
  54.389 +        }
  54.390 +        case 24:
  54.391 +        {
  54.392 +          PIXEL00_1M
  54.393 +          PIXEL01_1
  54.394 +          PIXEL02_1M
  54.395 +          PIXEL10_C
  54.396 +          PIXEL11
  54.397 +          PIXEL12_C
  54.398 +          PIXEL20_1M
  54.399 +          PIXEL21_1
  54.400 +          PIXEL22_1M
  54.401 +          break;
  54.402 +        }
  54.403 +        case 7:
  54.404 +        case 39:
  54.405 +        case 135:
  54.406 +        {
  54.407 +          PIXEL00_1L
  54.408 +          PIXEL01_C
  54.409 +          PIXEL02_1R
  54.410 +          PIXEL10_1
  54.411 +          PIXEL11
  54.412 +          PIXEL12_1
  54.413 +          PIXEL20_2
  54.414 +          PIXEL21_1
  54.415 +          PIXEL22_2
  54.416 +          break;
  54.417 +        }
  54.418 +        case 148:
  54.419 +        case 149:
  54.420 +        case 180:
  54.421 +        {
  54.422 +          PIXEL00_2
  54.423 +          PIXEL01_1
  54.424 +          PIXEL02_1U
  54.425 +          PIXEL10_1
  54.426 +          PIXEL11
  54.427 +          PIXEL12_C
  54.428 +          PIXEL20_2
  54.429 +          PIXEL21_1
  54.430 +          PIXEL22_1D
  54.431 +          break;
  54.432 +        }
  54.433 +        case 224:
  54.434 +        case 228:
  54.435 +        case 225:
  54.436 +        {
  54.437 +          PIXEL00_2
  54.438 +          PIXEL01_1
  54.439 +          PIXEL02_2
  54.440 +          PIXEL10_1
  54.441 +          PIXEL11
  54.442 +          PIXEL12_1
  54.443 +          PIXEL20_1L
  54.444 +          PIXEL21_C
  54.445 +          PIXEL22_1R
  54.446 +          break;
  54.447 +        }
  54.448 +        case 41:
  54.449 +        case 169:
  54.450 +        case 45:
  54.451 +        {
  54.452 +          PIXEL00_1U
  54.453 +          PIXEL01_1
  54.454 +          PIXEL02_2
  54.455 +          PIXEL10_C
  54.456 +          PIXEL11
  54.457 +          PIXEL12_1
  54.458 +          PIXEL20_1D
  54.459 +          PIXEL21_1
  54.460 +          PIXEL22_2
  54.461 +          break;
  54.462 +        }
  54.463 +        case 22:
  54.464 +        case 54:
  54.465 +        {
  54.466 +          PIXEL00_1M
  54.467 +          if (Diff(cget(2), cget(6)))
  54.468 +          {
  54.469 +            PIXEL01_C
  54.470 +            PIXEL02_C
  54.471 +            PIXEL12_C
  54.472 +          }
  54.473 +          else
  54.474 +          {
  54.475 +            PIXEL01_3
  54.476 +            PIXEL02_4
  54.477 +            PIXEL12_3
  54.478 +          }
  54.479 +          PIXEL10_1
  54.480 +          PIXEL11
  54.481 +          PIXEL20_2
  54.482 +          PIXEL21_1
  54.483 +          PIXEL22_1M
  54.484 +          break;
  54.485 +        }
  54.486 +        case 208:
  54.487 +        case 209:
  54.488 +        {
  54.489 +          PIXEL00_2
  54.490 +          PIXEL01_1
  54.491 +          PIXEL02_1M
  54.492 +          PIXEL10_1
  54.493 +          PIXEL11
  54.494 +          PIXEL20_1M
  54.495 +          if (Diff(cget(6), cget(8)))
  54.496 +          {
  54.497 +            PIXEL12_C
  54.498 +            PIXEL21_C
  54.499 +            PIXEL22_C
  54.500 +          }
  54.501 +          else
  54.502 +          {
  54.503 +            PIXEL12_3
  54.504 +            PIXEL21_3
  54.505 +            PIXEL22_4
  54.506 +          }
  54.507 +          break;
  54.508 +        }
  54.509 +        case 104:
  54.510 +        case 108:
  54.511 +        {
  54.512 +          PIXEL00_1M
  54.513 +          PIXEL01_1
  54.514 +          PIXEL02_2
  54.515 +          PIXEL11
  54.516 +          PIXEL12_1
  54.517 +          if (Diff(cget(8), cget(4)))
  54.518 +          {
  54.519 +            PIXEL10_C
  54.520 +            PIXEL20_C
  54.521 +            PIXEL21_C
  54.522 +          }
  54.523 +          else
  54.524 +          {
  54.525 +            PIXEL10_3
  54.526 +            PIXEL20_4
  54.527 +            PIXEL21_3
  54.528 +          }
  54.529 +          PIXEL22_1M
  54.530 +          break;
  54.531 +        }
  54.532 +        case 11:
  54.533 +        case 139:
  54.534 +        {
  54.535 +          if (Diff(cget(4), cget(2)))
  54.536 +          {
  54.537 +            PIXEL00_C
  54.538 +            PIXEL01_C
  54.539 +            PIXEL10_C
  54.540 +          }
  54.541 +          else
  54.542 +          {
  54.543 +            PIXEL00_4
  54.544 +            PIXEL01_3
  54.545 +            PIXEL10_3
  54.546 +          }
  54.547 +          PIXEL02_1M
  54.548 +          PIXEL11
  54.549 +          PIXEL12_1
  54.550 +          PIXEL20_1M
  54.551 +          PIXEL21_1
  54.552 +          PIXEL22_2
  54.553 +          break;
  54.554 +        }
  54.555 +        case 19:
  54.556 +        case 51:
  54.557 +        {
  54.558 +          if (Diff(cget(2), cget(6)))
  54.559 +          {
  54.560 +            PIXEL00_1L
  54.561 +            PIXEL01_C
  54.562 +            PIXEL02_1M
  54.563 +            PIXEL12_C
  54.564 +          }
  54.565 +          else
  54.566 +          {
  54.567 +            PIXEL00_2
  54.568 +            PIXEL01_6
  54.569 +            PIXEL02_5
  54.570 +            PIXEL12_1
  54.571 +          }
  54.572 +          PIXEL10_1
  54.573 +          PIXEL11
  54.574 +          PIXEL20_2
  54.575 +          PIXEL21_1
  54.576 +          PIXEL22_1M
  54.577 +          break;
  54.578 +        }
  54.579 +        case 146:
  54.580 +        case 178:
  54.581 +        {
  54.582 +          if (Diff(cget(2), cget(6)))
  54.583 +          {
  54.584 +            PIXEL01_C
  54.585 +            PIXEL02_1M
  54.586 +            PIXEL12_C
  54.587 +            PIXEL22_1D
  54.588 +          }
  54.589 +          else
  54.590 +          {
  54.591 +            PIXEL01_1
  54.592 +            PIXEL02_5
  54.593 +            PIXEL12_6
  54.594 +            PIXEL22_2
  54.595 +          }
  54.596 +          PIXEL00_1M
  54.597 +          PIXEL10_1
  54.598 +          PIXEL11
  54.599 +          PIXEL20_2
  54.600 +          PIXEL21_1
  54.601 +          break;
  54.602 +        }
  54.603 +        case 84:
  54.604 +        case 85:
  54.605 +        {
  54.606 +          if (Diff(cget(6), cget(8)))
  54.607 +          {
  54.608 +            PIXEL02_1U
  54.609 +            PIXEL12_C
  54.610 +            PIXEL21_C
  54.611 +            PIXEL22_1M
  54.612 +          }
  54.613 +          else
  54.614 +          {
  54.615 +            PIXEL02_2
  54.616 +            PIXEL12_6
  54.617 +            PIXEL21_1
  54.618 +            PIXEL22_5
  54.619 +          }
  54.620 +          PIXEL00_2
  54.621 +          PIXEL01_1
  54.622 +          PIXEL10_1
  54.623 +          PIXEL11
  54.624 +          PIXEL20_1M
  54.625 +          break;
  54.626 +        }
  54.627 +        case 112:
  54.628 +        case 113:
  54.629 +        {
  54.630 +          if (Diff(cget(6), cget(8)))
  54.631 +          {
  54.632 +            PIXEL12_C
  54.633 +            PIXEL20_1L
  54.634 +            PIXEL21_C
  54.635 +            PIXEL22_1M
  54.636 +          }
  54.637 +          else
  54.638 +          {
  54.639 +            PIXEL12_1
  54.640 +            PIXEL20_2
  54.641 +            PIXEL21_6
  54.642 +            PIXEL22_5
  54.643 +          }
  54.644 +          PIXEL00_2
  54.645 +          PIXEL01_1
  54.646 +          PIXEL02_1M
  54.647 +          PIXEL10_1
  54.648 +          PIXEL11
  54.649 +          break;
  54.650 +        }
  54.651 +        case 200:
  54.652 +        case 204:
  54.653 +        {
  54.654 +          if (Diff(cget(8), cget(4)))
  54.655 +          {
  54.656 +            PIXEL10_C
  54.657 +            PIXEL20_1M
  54.658 +            PIXEL21_C
  54.659 +            PIXEL22_1R
  54.660 +          }
  54.661 +          else
  54.662 +          {
  54.663 +            PIXEL10_1
  54.664 +            PIXEL20_5
  54.665 +            PIXEL21_6
  54.666 +            PIXEL22_2
  54.667 +          }
  54.668 +          PIXEL00_1M
  54.669 +          PIXEL01_1
  54.670 +          PIXEL02_2
  54.671 +          PIXEL11
  54.672 +          PIXEL12_1
  54.673 +          break;
  54.674 +        }
  54.675 +        case 73:
  54.676 +        case 77:
  54.677 +        {
  54.678 +          if (Diff(cget(8), cget(4)))
  54.679 +          {
  54.680 +            PIXEL00_1U
  54.681 +            PIXEL10_C
  54.682 +            PIXEL20_1M
  54.683 +            PIXEL21_C
  54.684 +          }
  54.685 +          else
  54.686 +          {
  54.687 +            PIXEL00_2
  54.688 +            PIXEL10_6
  54.689 +            PIXEL20_5
  54.690 +            PIXEL21_1
  54.691 +          }
  54.692 +          PIXEL01_1
  54.693 +          PIXEL02_2
  54.694 +          PIXEL11
  54.695 +          PIXEL12_1
  54.696 +          PIXEL22_1M
  54.697 +          break;
  54.698 +        }
  54.699 +        case 42:
  54.700 +        case 170:
  54.701 +        {
  54.702 +          if (Diff(cget(4), cget(2)))
  54.703 +          {
  54.704 +            PIXEL00_1M
  54.705 +            PIXEL01_C
  54.706 +            PIXEL10_C
  54.707 +            PIXEL20_1D
  54.708 +          }
  54.709 +          else
  54.710 +          {
  54.711 +            PIXEL00_5
  54.712 +            PIXEL01_1
  54.713 +            PIXEL10_6
  54.714 +            PIXEL20_2
  54.715 +          }
  54.716 +          PIXEL02_1M
  54.717 +          PIXEL11
  54.718 +          PIXEL12_1
  54.719 +          PIXEL21_1
  54.720 +          PIXEL22_2
  54.721 +          break;
  54.722 +        }
  54.723 +        case 14:
  54.724 +        case 142:
  54.725 +        {
  54.726 +          if (Diff(cget(4), cget(2)))
  54.727 +          {
  54.728 +            PIXEL00_1M
  54.729 +            PIXEL01_C
  54.730 +            PIXEL02_1R
  54.731 +            PIXEL10_C
  54.732 +          }
  54.733 +          else
  54.734 +          {
  54.735 +            PIXEL00_5
  54.736 +            PIXEL01_6
  54.737 +            PIXEL02_2
  54.738 +            PIXEL10_1
  54.739 +          }
  54.740 +          PIXEL11
  54.741 +          PIXEL12_1
  54.742 +          PIXEL20_1M
  54.743 +          PIXEL21_1
  54.744 +          PIXEL22_2
  54.745 +          break;
  54.746 +        }
  54.747 +        case 67:
  54.748 +        {
  54.749 +          PIXEL00_1L
  54.750 +          PIXEL01_C
  54.751 +          PIXEL02_1M
  54.752 +          PIXEL10_1
  54.753 +          PIXEL11
  54.754 +          PIXEL12_1
  54.755 +          PIXEL20_1M
  54.756 +          PIXEL21_C
  54.757 +          PIXEL22_1M
  54.758 +          break;
  54.759 +        }
  54.760 +        case 70:
  54.761 +        {
  54.762 +          PIXEL00_1M
  54.763 +          PIXEL01_C
  54.764 +          PIXEL02_1R
  54.765 +          PIXEL10_1
  54.766 +          PIXEL11
  54.767 +          PIXEL12_1
  54.768 +          PIXEL20_1M
  54.769 +          PIXEL21_C
  54.770 +          PIXEL22_1M
  54.771 +          break;
  54.772 +        }
  54.773 +        case 28:
  54.774 +        {
  54.775 +          PIXEL00_1M
  54.776 +          PIXEL01_1
  54.777 +          PIXEL02_1U
  54.778 +          PIXEL10_C
  54.779 +          PIXEL11
  54.780 +          PIXEL12_C
  54.781 +          PIXEL20_1M
  54.782 +          PIXEL21_1
  54.783 +          PIXEL22_1M
  54.784 +          break;
  54.785 +        }
  54.786 +        case 152:
  54.787 +        {
  54.788 +          PIXEL00_1M
  54.789 +          PIXEL01_1
  54.790 +          PIXEL02_1M
  54.791 +          PIXEL10_C
  54.792 +          PIXEL11
  54.793 +          PIXEL12_C
  54.794 +          PIXEL20_1M
  54.795 +          PIXEL21_1
  54.796 +          PIXEL22_1D
  54.797 +          break;
  54.798 +        }
  54.799 +        case 194:
  54.800 +        {
  54.801 +          PIXEL00_1M
  54.802 +          PIXEL01_C
  54.803 +          PIXEL02_1M
  54.804 +          PIXEL10_1
  54.805 +          PIXEL11
  54.806 +          PIXEL12_1
  54.807 +          PIXEL20_1M
  54.808 +          PIXEL21_C
  54.809 +          PIXEL22_1R
  54.810 +          break;
  54.811 +        }
  54.812 +        case 98:
  54.813 +        {
  54.814 +          PIXEL00_1M
  54.815 +          PIXEL01_C
  54.816 +          PIXEL02_1M
  54.817 +          PIXEL10_1
  54.818 +          PIXEL11
  54.819 +          PIXEL12_1
  54.820 +          PIXEL20_1L
  54.821 +          PIXEL21_C
  54.822 +          PIXEL22_1M
  54.823 +          break;
  54.824 +        }
  54.825 +        case 56:
  54.826 +        {
  54.827 +          PIXEL00_1M
  54.828 +          PIXEL01_1
  54.829 +          PIXEL02_1M
  54.830 +          PIXEL10_C
  54.831 +          PIXEL11
  54.832 +          PIXEL12_C
  54.833 +          PIXEL20_1D
  54.834 +          PIXEL21_1
  54.835 +          PIXEL22_1M
  54.836 +          break;
  54.837 +        }
  54.838 +        case 25:
  54.839 +        {
  54.840 +          PIXEL00_1U
  54.841 +          PIXEL01_1
  54.842 +          PIXEL02_1M
  54.843 +          PIXEL10_C
  54.844 +          PIXEL11
  54.845 +          PIXEL12_C
  54.846 +          PIXEL20_1M
  54.847 +          PIXEL21_1
  54.848 +          PIXEL22_1M
  54.849 +          break;
  54.850 +        }
  54.851 +        case 26:
  54.852 +        case 31:
  54.853 +        {
  54.854 +          if (Diff(cget(4), cget(2)))
  54.855 +          {
  54.856 +            PIXEL00_C
  54.857 +            PIXEL10_C
  54.858 +          }
  54.859 +          else
  54.860 +          {
  54.861 +            PIXEL00_4
  54.862 +            PIXEL10_3
  54.863 +          }
  54.864 +          PIXEL01_C
  54.865 +          if (Diff(cget(2), cget(6)))
  54.866 +          {
  54.867 +            PIXEL02_C
  54.868 +            PIXEL12_C
  54.869 +          }
  54.870 +          else
  54.871 +          {
  54.872 +            PIXEL02_4
  54.873 +            PIXEL12_3
  54.874 +          }
  54.875 +          PIXEL11
  54.876 +          PIXEL20_1M
  54.877 +          PIXEL21_1
  54.878 +          PIXEL22_1M
  54.879 +          break;
  54.880 +        }
  54.881 +        case 82:
  54.882 +        case 214:
  54.883 +        {
  54.884 +          PIXEL00_1M
  54.885 +          if (Diff(cget(2), cget(6)))
  54.886 +          {
  54.887 +            PIXEL01_C
  54.888 +            PIXEL02_C
  54.889 +          }
  54.890 +          else
  54.891 +          {
  54.892 +            PIXEL01_3
  54.893 +            PIXEL02_4
  54.894 +          }
  54.895 +          PIXEL10_1
  54.896 +          PIXEL11
  54.897 +          PIXEL12_C
  54.898 +          PIXEL20_1M
  54.899 +          if (Diff(cget(6), cget(8)))
  54.900 +          {
  54.901 +            PIXEL21_C
  54.902 +            PIXEL22_C
  54.903 +          }
  54.904 +          else
  54.905 +          {
  54.906 +            PIXEL21_3
  54.907 +            PIXEL22_4
  54.908 +          }
  54.909 +          break;
  54.910 +        }
  54.911 +        case 88:
  54.912 +        case 248:
  54.913 +        {
  54.914 +          PIXEL00_1M
  54.915 +          PIXEL01_1
  54.916 +          PIXEL02_1M
  54.917 +          PIXEL11
  54.918 +          if (Diff(cget(8), cget(4)))
  54.919 +          {
  54.920 +            PIXEL10_C
  54.921 +            PIXEL20_C
  54.922 +          }
  54.923 +          else
  54.924 +          {
  54.925 +            PIXEL10_3
  54.926 +            PIXEL20_4
  54.927 +          }
  54.928 +          PIXEL21_C
  54.929 +          if (Diff(cget(6), cget(8)))
  54.930 +          {
  54.931 +            PIXEL12_C
  54.932 +            PIXEL22_C
  54.933 +          }
  54.934 +          else
  54.935 +          {
  54.936 +            PIXEL12_3
  54.937 +            PIXEL22_4
  54.938 +          }
  54.939 +          break;
  54.940 +        }
  54.941 +        case 74:
  54.942 +        case 107:
  54.943 +        {
  54.944 +          if (Diff(cget(4), cget(2)))
  54.945 +          {
  54.946 +            PIXEL00_C
  54.947 +            PIXEL01_C
  54.948 +          }
  54.949 +          else
  54.950 +          {
  54.951 +            PIXEL00_4
  54.952 +            PIXEL01_3
  54.953 +          }
  54.954 +          PIXEL02_1M
  54.955 +          PIXEL10_C
  54.956 +          PIXEL11
  54.957 +          PIXEL12_1
  54.958 +          if (Diff(cget(8), cget(4)))
  54.959 +          {
  54.960 +            PIXEL20_C
  54.961 +            PIXEL21_C
  54.962 +          }
  54.963 +          else
  54.964 +          {
  54.965 +            PIXEL20_4
  54.966 +            PIXEL21_3
  54.967 +          }
  54.968 +          PIXEL22_1M
  54.969 +          break;
  54.970 +        }
  54.971 +        case 27:
  54.972 +        {
  54.973 +          if (Diff(cget(4), cget(2)))
  54.974 +          {
  54.975 +            PIXEL00_C
  54.976 +            PIXEL01_C
  54.977 +            PIXEL10_C
  54.978 +          }
  54.979 +          else
  54.980 +          {
  54.981 +            PIXEL00_4
  54.982 +            PIXEL01_3
  54.983 +            PIXEL10_3
  54.984 +          }
  54.985 +          PIXEL02_1M
  54.986 +          PIXEL11
  54.987 +          PIXEL12_C
  54.988 +          PIXEL20_1M
  54.989 +          PIXEL21_1
  54.990 +          PIXEL22_1M
  54.991 +          break;
  54.992 +        }
  54.993 +        case 86:
  54.994 +        {
  54.995 +          PIXEL00_1M
  54.996 +          if (Diff(cget(2), cget(6)))
  54.997 +          {
  54.998 +            PIXEL01_C
  54.999 +            PIXEL02_C
 54.1000 +            PIXEL12_C
 54.1001 +          }
 54.1002 +          else
 54.1003 +          {
 54.1004 +            PIXEL01_3
 54.1005 +            PIXEL02_4
 54.1006 +            PIXEL12_3
 54.1007 +          }
 54.1008 +          PIXEL10_1
 54.1009 +          PIXEL11
 54.1010 +          PIXEL20_1M
 54.1011 +          PIXEL21_C
 54.1012 +          PIXEL22_1M
 54.1013 +          break;
 54.1014 +        }
 54.1015 +        case 216:
 54.1016 +        {
 54.1017 +          PIXEL00_1M
 54.1018 +          PIXEL01_1
 54.1019 +          PIXEL02_1M
 54.1020 +          PIXEL10_C
 54.1021 +          PIXEL11
 54.1022 +          PIXEL20_1M
 54.1023 +          if (Diff(cget(6), cget(8)))
 54.1024 +          {
 54.1025 +            PIXEL12_C
 54.1026 +            PIXEL21_C
 54.1027 +            PIXEL22_C
 54.1028 +          }
 54.1029 +          else
 54.1030 +          {
 54.1031 +            PIXEL12_3
 54.1032 +            PIXEL21_3
 54.1033 +            PIXEL22_4
 54.1034 +          }
 54.1035 +          break;
 54.1036 +        }
 54.1037 +        case 106:
 54.1038 +        {
 54.1039 +          PIXEL00_1M
 54.1040 +          PIXEL01_C
 54.1041 +          PIXEL02_1M
 54.1042 +          PIXEL11
 54.1043 +          PIXEL12_1
 54.1044 +          if (Diff(cget(8), cget(4)))
 54.1045 +          {
 54.1046 +            PIXEL10_C
 54.1047 +            PIXEL20_C
 54.1048 +            PIXEL21_C
 54.1049 +          }
 54.1050 +          else
 54.1051 +          {
 54.1052 +            PIXEL10_3
 54.1053 +            PIXEL20_4
 54.1054 +            PIXEL21_3
 54.1055 +          }
 54.1056 +          PIXEL22_1M
 54.1057 +          break;
 54.1058 +        }
 54.1059 +        case 30:
 54.1060 +        {
 54.1061 +          PIXEL00_1M
 54.1062 +          if (Diff(cget(2), cget(6)))
 54.1063 +          {
 54.1064 +            PIXEL01_C
 54.1065 +            PIXEL02_C
 54.1066 +            PIXEL12_C
 54.1067 +          }
 54.1068 +          else
 54.1069 +          {
 54.1070 +            PIXEL01_3
 54.1071 +            PIXEL02_4
 54.1072 +            PIXEL12_3
 54.1073 +          }
 54.1074 +          PIXEL10_C
 54.1075 +          PIXEL11
 54.1076 +          PIXEL20_1M
 54.1077 +          PIXEL21_1
 54.1078 +          PIXEL22_1M
 54.1079 +          break;
 54.1080 +        }
 54.1081 +        case 210:
 54.1082 +        {
 54.1083 +          PIXEL00_1M
 54.1084 +          PIXEL01_C
 54.1085 +          PIXEL02_1M
 54.1086 +          PIXEL10_1
 54.1087 +          PIXEL11
 54.1088 +          PIXEL20_1M
 54.1089 +          if (Diff(cget(6), cget(8)))
 54.1090 +          {
 54.1091 +            PIXEL12_C
 54.1092 +            PIXEL21_C
 54.1093 +            PIXEL22_C
 54.1094 +          }
 54.1095 +          else
 54.1096 +          {
 54.1097 +            PIXEL12_3
 54.1098 +            PIXEL21_3
 54.1099 +            PIXEL22_4
 54.1100 +          }
 54.1101 +          break;
 54.1102 +        }
 54.1103 +        case 120:
 54.1104 +        {
 54.1105 +          PIXEL00_1M
 54.1106 +          PIXEL01_1
 54.1107 +          PIXEL02_1M
 54.1108 +          PIXEL11
 54.1109 +          PIXEL12_C
 54.1110 +          if (Diff(cget(8), cget(4)))
 54.1111 +          {
 54.1112 +            PIXEL10_C
 54.1113 +            PIXEL20_C
 54.1114 +            PIXEL21_C
 54.1115 +          }
 54.1116 +          else
 54.1117 +          {
 54.1118 +            PIXEL10_3
 54.1119 +            PIXEL20_4
 54.1120 +            PIXEL21_3
 54.1121 +          }
 54.1122 +          PIXEL22_1M
 54.1123 +          break;
 54.1124 +        }
 54.1125 +        case 75:
 54.1126 +        {
 54.1127 +          if (Diff(cget(4), cget(2)))
 54.1128 +          {
 54.1129 +            PIXEL00_C
 54.1130 +            PIXEL01_C
 54.1131 +            PIXEL10_C
 54.1132 +          }
 54.1133 +          else
 54.1134 +          {
 54.1135 +            PIXEL00_4
 54.1136 +            PIXEL01_3
 54.1137 +            PIXEL10_3
 54.1138 +          }
 54.1139 +          PIXEL02_1M
 54.1140 +          PIXEL11
 54.1141 +          PIXEL12_1
 54.1142 +          PIXEL20_1M
 54.1143 +          PIXEL21_C
 54.1144 +          PIXEL22_1M
 54.1145 +          break;
 54.1146 +        }
 54.1147 +        case 29:
 54.1148 +        {
 54.1149 +          PIXEL00_1U
 54.1150 +          PIXEL01_1
 54.1151 +          PIXEL02_1U
 54.1152 +          PIXEL10_C
 54.1153 +          PIXEL11
 54.1154 +          PIXEL12_C
 54.1155 +          PIXEL20_1M
 54.1156 +          PIXEL21_1
 54.1157 +          PIXEL22_1M
 54.1158 +          break;
 54.1159 +        }
 54.1160 +        case 198:
 54.1161 +        {
 54.1162 +          PIXEL00_1M
 54.1163 +          PIXEL01_C
 54.1164 +          PIXEL02_1R
 54.1165 +          PIXEL10_1
 54.1166 +          PIXEL11
 54.1167 +          PIXEL12_1
 54.1168 +          PIXEL20_1M
 54.1169 +          PIXEL21_C
 54.1170 +          PIXEL22_1R
 54.1171 +          break;
 54.1172 +        }
 54.1173 +        case 184:
 54.1174 +        {
 54.1175 +          PIXEL00_1M
 54.1176 +          PIXEL01_1
 54.1177 +          PIXEL02_1M
 54.1178 +          PIXEL10_C
 54.1179 +          PIXEL11
 54.1180 +          PIXEL12_C
 54.1181 +          PIXEL20_1D
 54.1182 +          PIXEL21_1
 54.1183 +          PIXEL22_1D
 54.1184 +          break;
 54.1185 +        }
 54.1186 +        case 99:
 54.1187 +        {
 54.1188 +          PIXEL00_1L
 54.1189 +          PIXEL01_C
 54.1190 +          PIXEL02_1M
 54.1191 +          PIXEL10_1
 54.1192 +          PIXEL11
 54.1193 +          PIXEL12_1
 54.1194 +          PIXEL20_1L
 54.1195 +          PIXEL21_C
 54.1196 +          PIXEL22_1M
 54.1197 +          break;
 54.1198 +        }
 54.1199 +        case 57:
 54.1200 +        {
 54.1201 +          PIXEL00_1U
 54.1202 +          PIXEL01_1
 54.1203 +          PIXEL02_1M
 54.1204 +          PIXEL10_C
 54.1205 +          PIXEL11
 54.1206 +          PIXEL12_C
 54.1207 +          PIXEL20_1D
 54.1208 +          PIXEL21_1
 54.1209 +          PIXEL22_1M
 54.1210 +          break;
 54.1211 +        }
 54.1212 +        case 71:
 54.1213 +        {
 54.1214 +          PIXEL00_1L
 54.1215 +          PIXEL01_C
 54.1216 +          PIXEL02_1R
 54.1217 +          PIXEL10_1
 54.1218 +          PIXEL11
 54.1219 +          PIXEL12_1
 54.1220 +          PIXEL20_1M
 54.1221 +          PIXEL21_C
 54.1222 +          PIXEL22_1M
 54.1223 +          break;
 54.1224 +        }
 54.1225 +        case 156:
 54.1226 +        {
 54.1227 +          PIXEL00_1M
 54.1228 +          PIXEL01_1
 54.1229 +          PIXEL02_1U
 54.1230 +          PIXEL10_C
 54.1231 +          PIXEL11
 54.1232 +          PIXEL12_C
 54.1233 +          PIXEL20_1M
 54.1234 +          PIXEL21_1
 54.1235 +          PIXEL22_1D
 54.1236 +          break;
 54.1237 +        }
 54.1238 +        case 226:
 54.1239 +        {
 54.1240 +          PIXEL00_1M
 54.1241 +          PIXEL01_C
 54.1242 +          PIXEL02_1M
 54.1243 +          PIXEL10_1
 54.1244 +          PIXEL11
 54.1245 +          PIXEL12_1
 54.1246 +          PIXEL20_1L
 54.1247 +          PIXEL21_C
 54.1248 +          PIXEL22_1R
 54.1249 +          break;
 54.1250 +        }
 54.1251 +        case 60:
 54.1252 +        {
 54.1253 +          PIXEL00_1M
 54.1254 +          PIXEL01_1
 54.1255 +          PIXEL02_1U
 54.1256 +          PIXEL10_C
 54.1257 +          PIXEL11
 54.1258 +          PIXEL12_C
 54.1259 +          PIXEL20_1D
 54.1260 +          PIXEL21_1
 54.1261 +          PIXEL22_1M
 54.1262 +          break;
 54.1263 +        }
 54.1264 +        case 195:
 54.1265 +        {
 54.1266 +          PIXEL00_1L
 54.1267 +          PIXEL01_C
 54.1268 +          PIXEL02_1M
 54.1269 +          PIXEL10_1
 54.1270 +          PIXEL11
 54.1271 +          PIXEL12_1
 54.1272 +          PIXEL20_1M
 54.1273 +          PIXEL21_C
 54.1274 +          PIXEL22_1R
 54.1275 +          break;
 54.1276 +        }
 54.1277 +        case 102:
 54.1278 +        {
 54.1279 +          PIXEL00_1M
 54.1280 +          PIXEL01_C
 54.1281 +          PIXEL02_1R
 54.1282 +          PIXEL10_1
 54.1283 +          PIXEL11
 54.1284 +          PIXEL12_1
 54.1285 +          PIXEL20_1L
 54.1286 +          PIXEL21_C
 54.1287 +          PIXEL22_1M
 54.1288 +          break;
 54.1289 +        }
 54.1290 +        case 153:
 54.1291 +        {
 54.1292 +          PIXEL00_1U
 54.1293 +          PIXEL01_1
 54.1294 +          PIXEL02_1M
 54.1295 +          PIXEL10_C
 54.1296 +          PIXEL11
 54.1297 +          PIXEL12_C
 54.1298 +          PIXEL20_1M
 54.1299 +          PIXEL21_1
 54.1300 +          PIXEL22_1D
 54.1301 +          break;
 54.1302 +        }
 54.1303 +        case 58:
 54.1304 +        {
 54.1305 +          if (Diff(cget(4), cget(2)))
 54.1306 +          {
 54.1307 +            PIXEL00_1M
 54.1308 +          }
 54.1309 +          else
 54.1310 +          {
 54.1311 +            PIXEL00_2
 54.1312 +          }
 54.1313 +          PIXEL01_C
 54.1314 +          if (Diff(cget(2), cget(6)))
 54.1315 +          {
 54.1316 +            PIXEL02_1M
 54.1317 +          }
 54.1318 +          else
 54.1319 +          {
 54.1320 +            PIXEL02_2
 54.1321 +          }
 54.1322 +          PIXEL10_C
 54.1323 +          PIXEL11
 54.1324 +          PIXEL12_C
 54.1325 +          PIXEL20_1D
 54.1326 +          PIXEL21_1
 54.1327 +          PIXEL22_1M
 54.1328 +          break;
 54.1329 +        }
 54.1330 +        case 83:
 54.1331 +        {
 54.1332 +          PIXEL00_1L
 54.1333 +          PIXEL01_C
 54.1334 +          if (Diff(cget(2), cget(6)))
 54.1335 +          {
 54.1336 +            PIXEL02_1M
 54.1337 +          }
 54.1338 +          else
 54.1339 +          {
 54.1340 +            PIXEL02_2
 54.1341 +          }
 54.1342 +          PIXEL10_1
 54.1343 +          PIXEL11
 54.1344 +          PIXEL12_C
 54.1345 +          PIXEL20_1M
 54.1346 +          PIXEL21_C
 54.1347 +          if (Diff(cget(6), cget(8)))
 54.1348 +          {
 54.1349 +            PIXEL22_1M
 54.1350 +          }
 54.1351 +          else
 54.1352 +          {
 54.1353 +            PIXEL22_2
 54.1354 +          }
 54.1355 +          break;
 54.1356 +        }
 54.1357 +        case 92:
 54.1358 +        {
 54.1359 +          PIXEL00_1M
 54.1360 +          PIXEL01_1
 54.1361 +          PIXEL02_1U
 54.1362 +          PIXEL10_C
 54.1363 +          PIXEL11
 54.1364 +          PIXEL12_C
 54.1365 +          if (Diff(cget(8), cget(4)))
 54.1366 +          {
 54.1367 +            PIXEL20_1M
 54.1368 +          }
 54.1369 +          else
 54.1370 +          {
 54.1371 +            PIXEL20_2
 54.1372 +          }
 54.1373 +          PIXEL21_C
 54.1374 +          if (Diff(cget(6), cget(8)))
 54.1375 +          {
 54.1376 +            PIXEL22_1M
 54.1377 +          }
 54.1378 +          else
 54.1379 +          {
 54.1380 +            PIXEL22_2
 54.1381 +          }
 54.1382 +          break;
 54.1383 +        }
 54.1384 +        case 202:
 54.1385 +        {
 54.1386 +          if (Diff(cget(4), cget(2)))
 54.1387 +          {
 54.1388 +            PIXEL00_1M
 54.1389 +          }
 54.1390 +          else
 54.1391 +          {
 54.1392 +            PIXEL00_2
 54.1393 +          }
 54.1394 +          PIXEL01_C
 54.1395 +          PIXEL02_1M
 54.1396 +          PIXEL10_C
 54.1397 +          PIXEL11
 54.1398 +          PIXEL12_1
 54.1399 +          if (Diff(cget(8), cget(4)))
 54.1400 +          {
 54.1401 +            PIXEL20_1M
 54.1402 +          }
 54.1403 +          else
 54.1404 +          {
 54.1405 +            PIXEL20_2
 54.1406 +          }
 54.1407 +          PIXEL21_C
 54.1408 +          PIXEL22_1R
 54.1409 +          break;
 54.1410 +        }
 54.1411 +        case 78:
 54.1412 +        {
 54.1413 +          if (Diff(cget(4), cget(2)))
 54.1414 +          {
 54.1415 +            PIXEL00_1M
 54.1416 +          }
 54.1417 +          else
 54.1418 +          {
 54.1419 +            PIXEL00_2
 54.1420 +          }
 54.1421 +          PIXEL01_C
 54.1422 +          PIXEL02_1R
 54.1423 +          PIXEL10_C
 54.1424 +          PIXEL11
 54.1425 +          PIXEL12_1
 54.1426 +          if (Diff(cget(8), cget(4)))
 54.1427 +          {
 54.1428 +            PIXEL20_1M
 54.1429 +          }
 54.1430 +          else
 54.1431 +          {
 54.1432 +            PIXEL20_2
 54.1433 +          }
 54.1434 +          PIXEL21_C
 54.1435 +          PIXEL22_1M
 54.1436 +          break;
 54.1437 +        }
 54.1438 +        case 154:
 54.1439 +        {
 54.1440 +          if (Diff(cget(4), cget(2)))
 54.1441 +          {
 54.1442 +            PIXEL00_1M
 54.1443 +          }
 54.1444 +          else
 54.1445 +          {
 54.1446 +            PIXEL00_2
 54.1447 +          }
 54.1448 +          PIXEL01_C
 54.1449 +          if (Diff(cget(2), cget(6)))
 54.1450 +          {
 54.1451 +            PIXEL02_1M
 54.1452 +          }
 54.1453 +          else
 54.1454 +          {
 54.1455 +            PIXEL02_2
 54.1456 +          }
 54.1457 +          PIXEL10_C
 54.1458 +          PIXEL11
 54.1459 +          PIXEL12_C
 54.1460 +          PIXEL20_1M
 54.1461 +          PIXEL21_1
 54.1462 +          PIXEL22_1D
 54.1463 +          break;
 54.1464 +        }
 54.1465 +        case 114:
 54.1466 +        {
 54.1467 +          PIXEL00_1M
 54.1468 +          PIXEL01_C
 54.1469 +          if (Diff(cget(2), cget(6)))
 54.1470 +          {
 54.1471 +            PIXEL02_1M
 54.1472 +          }
 54.1473 +          else
 54.1474 +          {
 54.1475 +            PIXEL02_2
 54.1476 +          }
 54.1477 +          PIXEL10_1
 54.1478 +          PIXEL11
 54.1479 +          PIXEL12_C
 54.1480 +          PIXEL20_1L
 54.1481 +          PIXEL21_C
 54.1482 +          if (Diff(cget(6), cget(8)))
 54.1483 +          {
 54.1484 +            PIXEL22_1M
 54.1485 +          }
 54.1486 +          else
 54.1487 +          {
 54.1488 +            PIXEL22_2
 54.1489 +          }
 54.1490 +          break;
 54.1491 +        }
 54.1492 +        case 89:
 54.1493 +        {
 54.1494 +          PIXEL00_1U
 54.1495 +          PIXEL01_1
 54.1496 +          PIXEL02_1M
 54.1497 +          PIXEL10_C
 54.1498 +          PIXEL11
 54.1499 +          PIXEL12_C
 54.1500 +          if (Diff(cget(8), cget(4)))
 54.1501 +          {
 54.1502 +            PIXEL20_1M
 54.1503 +          }
 54.1504 +          else
 54.1505 +          {
 54.1506 +            PIXEL20_2
 54.1507 +          }
 54.1508 +          PIXEL21_C
 54.1509 +          if (Diff(cget(6), cget(8)))
 54.1510 +          {
 54.1511 +            PIXEL22_1M
 54.1512 +          }
 54.1513 +          else
 54.1514 +          {
 54.1515 +            PIXEL22_2
 54.1516 +          }
 54.1517 +          break;
 54.1518 +        }
 54.1519 +        case 90:
 54.1520 +        {
 54.1521 +          if (Diff(cget(4), cget(2)))
 54.1522 +          {
 54.1523 +            PIXEL00_1M
 54.1524 +          }
 54.1525 +          else
 54.1526 +          {
 54.1527 +            PIXEL00_2
 54.1528 +          }
 54.1529 +          PIXEL01_C
 54.1530 +          if (Diff(cget(2), cget(6)))
 54.1531 +          {
 54.1532 +            PIXEL02_1M
 54.1533 +          }
 54.1534 +          else
 54.1535 +          {
 54.1536 +            PIXEL02_2
 54.1537 +          }
 54.1538 +          PIXEL10_C
 54.1539 +          PIXEL11
 54.1540 +          PIXEL12_C
 54.1541 +          if (Diff(cget(8), cget(4)))
 54.1542 +          {
 54.1543 +            PIXEL20_1M
 54.1544 +          }
 54.1545 +          else
 54.1546 +          {
 54.1547 +            PIXEL20_2
 54.1548 +          }
 54.1549 +          PIXEL21_C
 54.1550 +          if (Diff(cget(6), cget(8)))
 54.1551 +          {
 54.1552 +            PIXEL22_1M
 54.1553 +          }
 54.1554 +          else
 54.1555 +          {
 54.1556 +            PIXEL22_2
 54.1557 +          }
 54.1558 +          break;
 54.1559 +        }
 54.1560 +        case 55:
 54.1561 +        case 23:
 54.1562 +        {
 54.1563 +          if (Diff(cget(2), cget(6)))
 54.1564 +          {
 54.1565 +            PIXEL00_1L
 54.1566 +            PIXEL01_C
 54.1567 +            PIXEL02_C
 54.1568 +            PIXEL12_C
 54.1569 +          }
 54.1570 +          else
 54.1571 +          {
 54.1572 +            PIXEL00_2
 54.1573 +            PIXEL01_6
 54.1574 +            PIXEL02_5
 54.1575 +            PIXEL12_1
 54.1576 +          }
 54.1577 +          PIXEL10_1
 54.1578 +          PIXEL11
 54.1579 +          PIXEL20_2
 54.1580 +          PIXEL21_1
 54.1581 +          PIXEL22_1M
 54.1582 +          break;
 54.1583 +        }
 54.1584 +        case 182:
 54.1585 +        case 150:
 54.1586 +        {
 54.1587 +          if (Diff(cget(2), cget(6)))
 54.1588 +          {
 54.1589 +            PIXEL01_C
 54.1590 +            PIXEL02_C
 54.1591 +            PIXEL12_C
 54.1592 +            PIXEL22_1D
 54.1593 +          }
 54.1594 +          else
 54.1595 +          {
 54.1596 +            PIXEL01_1
 54.1597 +            PIXEL02_5
 54.1598 +            PIXEL12_6
 54.1599 +            PIXEL22_2
 54.1600 +          }
 54.1601 +          PIXEL00_1M
 54.1602 +          PIXEL10_1
 54.1603 +          PIXEL11
 54.1604 +          PIXEL20_2
 54.1605 +          PIXEL21_1
 54.1606 +          break;
 54.1607 +        }
 54.1608 +        case 213:
 54.1609 +        case 212:
 54.1610 +        {
 54.1611 +          if (Diff(cget(6), cget(8)))
 54.1612 +          {
 54.1613 +            PIXEL02_1U
 54.1614 +            PIXEL12_C
 54.1615 +            PIXEL21_C
 54.1616 +            PIXEL22_C
 54.1617 +          }
 54.1618 +          else
 54.1619 +          {
 54.1620 +            PIXEL02_2
 54.1621 +            PIXEL12_6
 54.1622 +            PIXEL21_1
 54.1623 +            PIXEL22_5
 54.1624 +          }
 54.1625 +          PIXEL00_2
 54.1626 +          PIXEL01_1
 54.1627 +          PIXEL10_1
 54.1628 +          PIXEL11
 54.1629 +          PIXEL20_1M
 54.1630 +          break;
 54.1631 +        }
 54.1632 +        case 241:
 54.1633 +        case 240:
 54.1634 +        {
 54.1635 +          if (Diff(cget(6), cget(8)))
 54.1636 +          {
 54.1637 +            PIXEL12_C
 54.1638 +            PIXEL20_1L
 54.1639 +            PIXEL21_C
 54.1640 +            PIXEL22_C
 54.1641 +          }
 54.1642 +          else
 54.1643 +          {
 54.1644 +            PIXEL12_1
 54.1645 +            PIXEL20_2
 54.1646 +            PIXEL21_6
 54.1647 +            PIXEL22_5
 54.1648 +          }
 54.1649 +          PIXEL00_2
 54.1650 +          PIXEL01_1
 54.1651 +          PIXEL02_1M
 54.1652 +          PIXEL10_1
 54.1653 +          PIXEL11
 54.1654 +          break;
 54.1655 +        }
 54.1656 +        case 236:
 54.1657 +        case 232:
 54.1658 +        {
 54.1659 +          if (Diff(cget(8), cget(4)))
 54.1660 +          {
 54.1661 +            PIXEL10_C
 54.1662 +            PIXEL20_C
 54.1663 +            PIXEL21_C
 54.1664 +            PIXEL22_1R
 54.1665 +          }
 54.1666 +          else
 54.1667 +          {
 54.1668 +            PIXEL10_1
 54.1669 +            PIXEL20_5
 54.1670 +            PIXEL21_6
 54.1671 +            PIXEL22_2
 54.1672 +          }
 54.1673 +          PIXEL00_1M
 54.1674 +          PIXEL01_1
 54.1675 +          PIXEL02_2
 54.1676 +          PIXEL11
 54.1677 +          PIXEL12_1
 54.1678 +          break;
 54.1679 +        }
 54.1680 +        case 109:
 54.1681 +        case 105:
 54.1682 +        {
 54.1683 +          if (Diff(cget(8), cget(4)))
 54.1684 +          {
 54.1685 +            PIXEL00_1U
 54.1686 +            PIXEL10_C
 54.1687 +            PIXEL20_C
 54.1688 +            PIXEL21_C
 54.1689 +          }
 54.1690 +          else
 54.1691 +          {
 54.1692 +            PIXEL00_2
 54.1693 +            PIXEL10_6
 54.1694 +            PIXEL20_5
 54.1695 +            PIXEL21_1
 54.1696 +          }
 54.1697 +          PIXEL01_1
 54.1698 +          PIXEL02_2
 54.1699 +          PIXEL11
 54.1700 +          PIXEL12_1
 54.1701 +          PIXEL22_1M
 54.1702 +          break;
 54.1703 +        }
 54.1704 +        case 171:
 54.1705 +        case 43:
 54.1706 +        {
 54.1707 +          if (Diff(cget(4), cget(2)))
 54.1708 +          {
 54.1709 +            PIXEL00_C
 54.1710 +            PIXEL01_C
 54.1711 +            PIXEL10_C
 54.1712 +            PIXEL20_1D
 54.1713 +          }
 54.1714 +          else
 54.1715 +          {
 54.1716 +            PIXEL00_5
 54.1717 +            PIXEL01_1
 54.1718 +            PIXEL10_6
 54.1719 +            PIXEL20_2
 54.1720 +          }
 54.1721 +          PIXEL02_1M
 54.1722 +          PIXEL11
 54.1723 +          PIXEL12_1
 54.1724 +          PIXEL21_1
 54.1725 +          PIXEL22_2
 54.1726 +          break;
 54.1727 +        }
 54.1728 +        case 143:
 54.1729 +        case 15:
 54.1730 +        {
 54.1731 +          if (Diff(cget(4), cget(2)))
 54.1732 +          {
 54.1733 +            PIXEL00_C
 54.1734 +            PIXEL01_C
 54.1735 +            PIXEL02_1R
 54.1736 +            PIXEL10_C
 54.1737 +          }
 54.1738 +          else
 54.1739 +          {
 54.1740 +            PIXEL00_5
 54.1741 +            PIXEL01_6
 54.1742 +            PIXEL02_2
 54.1743 +            PIXEL10_1
 54.1744 +          }
 54.1745 +          PIXEL11
 54.1746 +          PIXEL12_1
 54.1747 +          PIXEL20_1M
 54.1748 +          PIXEL21_1
 54.1749 +          PIXEL22_2
 54.1750 +          break;
 54.1751 +        }
 54.1752 +        case 124:
 54.1753 +        {
 54.1754 +          PIXEL00_1M
 54.1755 +          PIXEL01_1
 54.1756 +          PIXEL02_1U
 54.1757 +          PIXEL11
 54.1758 +          PIXEL12_C
 54.1759 +          if (Diff(cget(8), cget(4)))
 54.1760 +          {
 54.1761 +            PIXEL10_C
 54.1762 +            PIXEL20_C
 54.1763 +            PIXEL21_C
 54.1764 +          }
 54.1765 +          else
 54.1766 +          {
 54.1767 +            PIXEL10_3
 54.1768 +            PIXEL20_4
 54.1769 +            PIXEL21_3
 54.1770 +          }
 54.1771 +          PIXEL22_1M
 54.1772 +          break;
 54.1773 +        }
 54.1774 +        case 203:
 54.1775 +        {
 54.1776 +          if (Diff(cget(4), cget(2)))
 54.1777 +          {
 54.1778 +            PIXEL00_C
 54.1779 +            PIXEL01_C
 54.1780 +            PIXEL10_C
 54.1781 +          }
 54.1782 +          else
 54.1783 +          {
 54.1784 +            PIXEL00_4
 54.1785 +            PIXEL01_3
 54.1786 +            PIXEL10_3
 54.1787 +          }
 54.1788 +          PIXEL02_1M
 54.1789 +          PIXEL11
 54.1790 +          PIXEL12_1
 54.1791 +          PIXEL20_1M
 54.1792 +          PIXEL21_C
 54.1793 +          PIXEL22_1R
 54.1794 +          break;
 54.1795 +        }
 54.1796 +        case 62:
 54.1797 +        {
 54.1798 +          PIXEL00_1M
 54.1799 +          if (Diff(cget(2), cget(6)))
 54.1800 +          {
 54.1801 +            PIXEL01_C
 54.1802 +            PIXEL02_C
 54.1803 +            PIXEL12_C
 54.1804 +          }
 54.1805 +          else
 54.1806 +          {
 54.1807 +            PIXEL01_3
 54.1808 +            PIXEL02_4
 54.1809 +            PIXEL12_3
 54.1810 +          }
 54.1811 +          PIXEL10_C
 54.1812 +          PIXEL11
 54.1813 +          PIXEL20_1D
 54.1814 +          PIXEL21_1
 54.1815 +          PIXEL22_1M
 54.1816 +          break;
 54.1817 +        }
 54.1818 +        case 211:
 54.1819 +        {
 54.1820 +          PIXEL00_1L
 54.1821 +          PIXEL01_C
 54.1822 +          PIXEL02_1M
 54.1823 +          PIXEL10_1
 54.1824 +          PIXEL11
 54.1825 +          PIXEL20_1M
 54.1826 +          if (Diff(cget(6), cget(8)))
 54.1827 +          {
 54.1828 +            PIXEL12_C
 54.1829 +            PIXEL21_C
 54.1830 +            PIXEL22_C
 54.1831 +          }
 54.1832 +          else
 54.1833 +          {
 54.1834 +            PIXEL12_3
 54.1835 +            PIXEL21_3
 54.1836 +            PIXEL22_4
 54.1837 +          }
 54.1838 +          break;
 54.1839 +        }
 54.1840 +        case 118:
 54.1841 +        {
 54.1842 +          PIXEL00_1M
 54.1843 +          if (Diff(cget(2), cget(6)))
 54.1844 +          {
 54.1845 +            PIXEL01_C
 54.1846 +            PIXEL02_C
 54.1847 +            PIXEL12_C
 54.1848 +          }
 54.1849 +          else
 54.1850 +          {
 54.1851 +            PIXEL01_3
 54.1852 +            PIXEL02_4
 54.1853 +            PIXEL12_3
 54.1854 +          }
 54.1855 +          PIXEL10_1
 54.1856 +          PIXEL11
 54.1857 +          PIXEL20_1L
 54.1858 +          PIXEL21_C
 54.1859 +          PIXEL22_1M
 54.1860 +          break;
 54.1861 +        }
 54.1862 +        case 217:
 54.1863 +        {
 54.1864 +          PIXEL00_1U
 54.1865 +          PIXEL01_1
 54.1866 +          PIXEL02_1M
 54.1867 +          PIXEL10_C
 54.1868 +          PIXEL11
 54.1869 +          PIXEL20_1M
 54.1870 +          if (Diff(cget(6), cget(8)))
 54.1871 +          {
 54.1872 +            PIXEL12_C
 54.1873 +            PIXEL21_C
 54.1874 +            PIXEL22_C
 54.1875 +          }
 54.1876 +          else
 54.1877 +          {
 54.1878 +            PIXEL12_3
 54.1879 +            PIXEL21_3
 54.1880 +            PIXEL22_4
 54.1881 +          }
 54.1882 +          break;
 54.1883 +        }
 54.1884 +        case 110:
 54.1885 +        {
 54.1886 +          PIXEL00_1M
 54.1887 +          PIXEL01_C
 54.1888 +          PIXEL02_1R
 54.1889 +          PIXEL11
 54.1890 +          PIXEL12_1
 54.1891 +          if (Diff(cget(8), cget(4)))
 54.1892 +          {
 54.1893 +            PIXEL10_C
 54.1894 +            PIXEL20_C
 54.1895 +            PIXEL21_C
 54.1896 +          }
 54.1897 +          else
 54.1898 +          {
 54.1899 +            PIXEL10_3
 54.1900 +            PIXEL20_4
 54.1901 +            PIXEL21_3
 54.1902 +          }
 54.1903 +          PIXEL22_1M
 54.1904 +          break;
 54.1905 +        }
 54.1906 +        case 155:
 54.1907 +        {
 54.1908 +          if (Diff(cget(4), cget(2)))
 54.1909 +          {
 54.1910 +            PIXEL00_C
 54.1911 +            PIXEL01_C
 54.1912 +            PIXEL10_C
 54.1913 +          }
 54.1914 +          else
 54.1915 +          {
 54.1916 +            PIXEL00_4
 54.1917 +            PIXEL01_3
 54.1918 +            PIXEL10_3
 54.1919 +          }
 54.1920 +          PIXEL02_1M
 54.1921 +          PIXEL11
 54.1922 +          PIXEL12_C
 54.1923 +          PIXEL20_1M
 54.1924 +          PIXEL21_1
 54.1925 +          PIXEL22_1D
 54.1926 +          break;
 54.1927 +        }
 54.1928 +        case 188:
 54.1929 +        {
 54.1930 +          PIXEL00_1M
 54.1931 +          PIXEL01_1
 54.1932 +          PIXEL02_1U
 54.1933 +          PIXEL10_C
 54.1934 +          PIXEL11
 54.1935 +          PIXEL12_C
 54.1936 +          PIXEL20_1D
 54.1937 +          PIXEL21_1
 54.1938 +          PIXEL22_1D
 54.1939 +          break;
 54.1940 +        }
 54.1941 +        case 185:
 54.1942 +        {
 54.1943 +          PIXEL00_1U
 54.1944 +          PIXEL01_1
 54.1945 +          PIXEL02_1M
 54.1946 +          PIXEL10_C
 54.1947 +          PIXEL11
 54.1948 +          PIXEL12_C
 54.1949 +          PIXEL20_1D
 54.1950 +          PIXEL21_1
 54.1951 +          PIXEL22_1D
 54.1952 +          break;
 54.1953 +        }
 54.1954 +        case 61:
 54.1955 +        {
 54.1956 +          PIXEL00_1U
 54.1957 +          PIXEL01_1
 54.1958 +          PIXEL02_1U
 54.1959 +          PIXEL10_C
 54.1960 +          PIXEL11
 54.1961 +          PIXEL12_C
 54.1962 +          PIXEL20_1D
 54.1963 +          PIXEL21_1
 54.1964 +          PIXEL22_1M
 54.1965 +          break;
 54.1966 +        }
 54.1967 +        case 157:
 54.1968 +        {
 54.1969 +          PIXEL00_1U
 54.1970 +          PIXEL01_1
 54.1971 +          PIXEL02_1U
 54.1972 +          PIXEL10_C
 54.1973 +          PIXEL11
 54.1974 +          PIXEL12_C
 54.1975 +          PIXEL20_1M
 54.1976 +          PIXEL21_1
 54.1977 +          PIXEL22_1D
 54.1978 +          break;
 54.1979 +        }
 54.1980 +        case 103:
 54.1981 +        {
 54.1982 +          PIXEL00_1L
 54.1983 +          PIXEL01_C
 54.1984 +          PIXEL02_1R
 54.1985 +          PIXEL10_1
 54.1986 +          PIXEL11
 54.1987 +          PIXEL12_1
 54.1988 +          PIXEL20_1L
 54.1989 +          PIXEL21_C
 54.1990 +          PIXEL22_1M
 54.1991 +          break;
 54.1992 +        }
 54.1993 +        case 227:
 54.1994 +        {
 54.1995 +          PIXEL00_1L
 54.1996 +          PIXEL01_C
 54.1997 +          PIXEL02_1M
 54.1998 +          PIXEL10_1
 54.1999 +          PIXEL11
 54.2000 +          PIXEL12_1
 54.2001 +          PIXEL20_1L
 54.2002 +          PIXEL21_C
 54.2003 +          PIXEL22_1R
 54.2004 +          break;
 54.2005 +        }
 54.2006 +        case 230:
 54.2007 +        {
 54.2008 +          PIXEL00_1M
 54.2009 +          PIXEL01_C
 54.2010 +          PIXEL02_1R
 54.2011 +          PIXEL10_1
 54.2012 +          PIXEL11
 54.2013 +          PIXEL12_1
 54.2014 +          PIXEL20_1L
 54.2015 +          PIXEL21_C
 54.2016 +          PIXEL22_1R
 54.2017 +          break;
 54.2018 +        }
 54.2019 +        case 199:
 54.2020 +        {
 54.2021 +          PIXEL00_1L
 54.2022 +          PIXEL01_C
 54.2023 +          PIXEL02_1R
 54.2024 +          PIXEL10_1
 54.2025 +          PIXEL11
 54.2026 +          PIXEL12_1
 54.2027 +          PIXEL20_1M
 54.2028 +          PIXEL21_C
 54.2029 +          PIXEL22_1R
 54.2030 +          break;
 54.2031 +        }
 54.2032 +        case 220:
 54.2033 +        {
 54.2034 +          PIXEL00_1M
 54.2035 +          PIXEL01_1
 54.2036 +          PIXEL02_1U
 54.2037 +          PIXEL10_C
 54.2038 +          PIXEL11
 54.2039 +          if (Diff(cget(8), cget(4)))
 54.2040 +          {
 54.2041 +            PIXEL20_1M
 54.2042 +          }
 54.2043 +          else
 54.2044 +          {
 54.2045 +            PIXEL20_2
 54.2046 +          }
 54.2047 +          if (Diff(cget(6), cget(8)))
 54.2048 +          {
 54.2049 +            PIXEL12_C
 54.2050 +            PIXEL21_C
 54.2051 +            PIXEL22_C
 54.2052 +          }
 54.2053 +          else
 54.2054 +          {
 54.2055 +            PIXEL12_3
 54.2056 +            PIXEL21_3
 54.2057 +            PIXEL22_4
 54.2058 +          }
 54.2059 +          break;
 54.2060 +        }
 54.2061 +        case 158:
 54.2062 +        {
 54.2063 +          if (Diff(cget(4), cget(2)))
 54.2064 +          {
 54.2065 +            PIXEL00_1M
 54.2066 +          }
 54.2067 +          else
 54.2068 +          {
 54.2069 +            PIXEL00_2
 54.2070 +          }
 54.2071 +          if (Diff(cget(2), cget(6)))
 54.2072 +          {
 54.2073 +            PIXEL01_C
 54.2074 +            PIXEL02_C
 54.2075 +            PIXEL12_C
 54.2076 +          }
 54.2077 +          else
 54.2078 +          {
 54.2079 +            PIXEL01_3
 54.2080 +            PIXEL02_4
 54.2081 +            PIXEL12_3
 54.2082 +          }
 54.2083 +          PIXEL10_C
 54.2084 +          PIXEL11
 54.2085 +          PIXEL20_1M
 54.2086 +          PIXEL21_1
 54.2087 +          PIXEL22_1D
 54.2088 +          break;
 54.2089 +        }
 54.2090 +        case 234:
 54.2091 +        {
 54.2092 +          if (Diff(cget(4), cget(2)))
 54.2093 +          {
 54.2094 +            PIXEL00_1M
 54.2095 +          }
 54.2096 +          else
 54.2097 +          {
 54.2098 +            PIXEL00_2
 54.2099 +          }
 54.2100 +          PIXEL01_C
 54.2101 +          PIXEL02_1M
 54.2102 +          PIXEL11
 54.2103 +          PIXEL12_1
 54.2104 +          if (Diff(cget(8), cget(4)))
 54.2105 +          {
 54.2106 +            PIXEL10_C
 54.2107 +            PIXEL20_C
 54.2108 +            PIXEL21_C
 54.2109 +          }
 54.2110 +          else
 54.2111 +          {
 54.2112 +            PIXEL10_3
 54.2113 +            PIXEL20_4
 54.2114 +            PIXEL21_3
 54.2115 +          }
 54.2116 +          PIXEL22_1R
 54.2117 +          break;
 54.2118 +        }
 54.2119 +        case 242:
 54.2120 +        {
 54.2121 +          PIXEL00_1M
 54.2122 +          PIXEL01_C
 54.2123 +          if (Diff(cget(2), cget(6)))
 54.2124 +          {
 54.2125 +            PIXEL02_1M
 54.2126 +          }
 54.2127 +          else
 54.2128 +          {
 54.2129 +            PIXEL02_2
 54.2130 +          }
 54.2131 +          PIXEL10_1
 54.2132 +          PIXEL11
 54.2133 +          PIXEL20_1L
 54.2134 +          if (Diff(cget(6), cget(8)))
 54.2135 +          {
 54.2136 +            PIXEL12_C
 54.2137 +            PIXEL21_C
 54.2138 +            PIXEL22_C
 54.2139 +          }
 54.2140 +          else
 54.2141 +          {
 54.2142 +            PIXEL12_3
 54.2143 +            PIXEL21_3
 54.2144 +            PIXEL22_4
 54.2145 +          }
 54.2146 +          break;
 54.2147 +        }
 54.2148 +        case 59:
 54.2149 +        {
 54.2150 +          if (Diff(cget(4), cget(2)))
 54.2151 +          {
 54.2152 +            PIXEL00_C
 54.2153 +            PIXEL01_C
 54.2154 +            PIXEL10_C
 54.2155 +          }
 54.2156 +          else
 54.2157 +          {
 54.2158 +            PIXEL00_4
 54.2159 +            PIXEL01_3
 54.2160 +            PIXEL10_3
 54.2161 +          }
 54.2162 +          if (Diff(cget(2), cget(6)))
 54.2163 +          {
 54.2164 +            PIXEL02_1M
 54.2165 +          }
 54.2166 +          else
 54.2167 +          {
 54.2168 +            PIXEL02_2
 54.2169 +          }
 54.2170 +          PIXEL11
 54.2171 +          PIXEL12_C
 54.2172 +          PIXEL20_1D
 54.2173 +          PIXEL21_1
 54.2174 +          PIXEL22_1M
 54.2175 +          break;
 54.2176 +        }
 54.2177 +        case 121:
 54.2178 +        {
 54.2179 +          PIXEL00_1U
 54.2180 +          PIXEL01_1
 54.2181 +          PIXEL02_1M
 54.2182 +          PIXEL11
 54.2183 +          PIXEL12_C
 54.2184 +          if (Diff(cget(8), cget(4)))
 54.2185 +          {
 54.2186 +            PIXEL10_C
 54.2187 +            PIXEL20_C
 54.2188 +            PIXEL21_C
 54.2189 +          }
 54.2190 +          else
 54.2191 +          {
 54.2192 +            PIXEL10_3
 54.2193 +            PIXEL20_4
 54.2194 +            PIXEL21_3
 54.2195 +          }
 54.2196 +          if (Diff(cget(6), cget(8)))
 54.2197 +          {
 54.2198 +            PIXEL22_1M
 54.2199 +          }
 54.2200 +          else
 54.2201 +          {
 54.2202 +            PIXEL22_2
 54.2203 +          }
 54.2204 +          break;
 54.2205 +        }
 54.2206 +        case 87:
 54.2207 +        {
 54.2208 +          PIXEL00_1L
 54.2209 +          if (Diff(cget(2), cget(6)))
 54.2210 +          {
 54.2211 +            PIXEL01_C
 54.2212 +            PIXEL02_C
 54.2213 +            PIXEL12_C
 54.2214 +          }
 54.2215 +          else
 54.2216 +          {
 54.2217 +            PIXEL01_3
 54.2218 +            PIXEL02_4
 54.2219 +            PIXEL12_3
 54.2220 +          }
 54.2221 +          PIXEL10_1
 54.2222 +          PIXEL11
 54.2223 +          PIXEL20_1M
 54.2224 +          PIXEL21_C
 54.2225 +          if (Diff(cget(6), cget(8)))
 54.2226 +          {
 54.2227 +            PIXEL22_1M
 54.2228 +          }
 54.2229 +          else
 54.2230 +          {
 54.2231 +            PIXEL22_2
 54.2232 +          }
 54.2233 +          break;
 54.2234 +        }
 54.2235 +        case 79:
 54.2236 +        {
 54.2237 +          if (Diff(cget(4), cget(2)))
 54.2238 +          {
 54.2239 +            PIXEL00_C
 54.2240 +            PIXEL01_C
 54.2241 +            PIXEL10_C
 54.2242 +          }
 54.2243 +          else
 54.2244 +          {
 54.2245 +            PIXEL00_4
 54.2246 +            PIXEL01_3
 54.2247 +            PIXEL10_3
 54.2248 +          }
 54.2249 +          PIXEL02_1R
 54.2250 +          PIXEL11
 54.2251 +          PIXEL12_1
 54.2252 +          if (Diff(cget(8), cget(4)))
 54.2253 +          {
 54.2254 +            PIXEL20_1M
 54.2255 +          }
 54.2256 +          else
 54.2257 +          {
 54.2258 +            PIXEL20_2
 54.2259 +          }
 54.2260 +          PIXEL21_C
 54.2261 +          PIXEL22_1M
 54.2262 +          break;
 54.2263 +        }
 54.2264 +        case 122:
 54.2265 +        {
 54.2266 +          if (Diff(cget(4), cget(2)))
 54.2267 +          {
 54.2268 +            PIXEL00_1M
 54.2269 +          }
 54.2270 +          else
 54.2271 +          {
 54.2272 +            PIXEL00_2
 54.2273 +          }
 54.2274 +          PIXEL01_C
 54.2275 +          if (Diff(cget(2), cget(6)))
 54.2276 +          {
 54.2277 +            PIXEL02_1M
 54.2278 +          }
 54.2279 +          else
 54.2280 +          {
 54.2281 +            PIXEL02_2
 54.2282 +          }
 54.2283 +          PIXEL11
 54.2284 +          PIXEL12_C
 54.2285 +          if (Diff(cget(8), cget(4)))
 54.2286 +          {
 54.2287 +            PIXEL10_C
 54.2288 +            PIXEL20_C
 54.2289 +            PIXEL21_C
 54.2290 +          }
 54.2291 +          else
 54.2292 +          {
 54.2293 +            PIXEL10_3
 54.2294 +            PIXEL20_4
 54.2295 +            PIXEL21_3
 54.2296 +          }
 54.2297 +          if (Diff(cget(6), cget(8)))
 54.2298 +          {
 54.2299 +            PIXEL22_1M
 54.2300 +          }
 54.2301 +          else
 54.2302 +          {
 54.2303 +            PIXEL22_2
 54.2304 +          }
 54.2305 +          break;
 54.2306 +        }
 54.2307 +        case 94:
 54.2308 +        {
 54.2309 +          if (Diff(cget(4), cget(2)))
 54.2310 +          {
 54.2311 +            PIXEL00_1M
 54.2312 +          }
 54.2313 +          else
 54.2314 +          {
 54.2315 +            PIXEL00_2
 54.2316 +          }
 54.2317 +          if (Diff(cget(2), cget(6)))
 54.2318 +          {
 54.2319 +            PIXEL01_C
 54.2320 +            PIXEL02_C
 54.2321 +            PIXEL12_C
 54.2322 +          }
 54.2323 +          else
 54.2324 +          {
 54.2325 +            PIXEL01_3
 54.2326 +            PIXEL02_4
 54.2327 +            PIXEL12_3
 54.2328 +          }
 54.2329 +          PIXEL10_C
 54.2330 +          PIXEL11
 54.2331 +          if (Diff(cget(8), cget(4)))
 54.2332 +          {
 54.2333 +            PIXEL20_1M
 54.2334 +          }
 54.2335 +          else
 54.2336 +          {
 54.2337 +            PIXEL20_2
 54.2338 +          }
 54.2339 +          PIXEL21_C
 54.2340 +          if (Diff(cget(6), cget(8)))
 54.2341 +          {
 54.2342 +            PIXEL22_1M
 54.2343 +          }
 54.2344 +          else
 54.2345 +          {
 54.2346 +            PIXEL22_2
 54.2347 +          }
 54.2348 +          break;
 54.2349 +        }
 54.2350 +        case 218:
 54.2351 +        {
 54.2352 +          if (Diff(cget(4), cget(2)))
 54.2353 +          {
 54.2354 +            PIXEL00_1M
 54.2355 +          }
 54.2356 +          else
 54.2357 +          {
 54.2358 +            PIXEL00_2
 54.2359 +          }
 54.2360 +          PIXEL01_C
 54.2361 +          if (Diff(cget(2), cget(6)))
 54.2362 +          {
 54.2363 +            PIXEL02_1M
 54.2364 +          }
 54.2365 +          else
 54.2366 +          {
 54.2367 +            PIXEL02_2
 54.2368 +          }
 54.2369 +          PIXEL10_C
 54.2370 +          PIXEL11
 54.2371 +          if (Diff(cget(8), cget(4)))
 54.2372 +          {
 54.2373 +            PIXEL20_1M
 54.2374 +          }
 54.2375 +          else
 54.2376 +          {
 54.2377 +            PIXEL20_2
 54.2378 +          }
 54.2379 +          if (Diff(cget(6), cget(8)))
 54.2380 +          {
 54.2381 +            PIXEL12_C
 54.2382 +            PIXEL21_C
 54.2383 +            PIXEL22_C
 54.2384 +          }
 54.2385 +          else
 54.2386 +          {
 54.2387 +            PIXEL12_3
 54.2388 +            PIXEL21_3
 54.2389 +            PIXEL22_4
 54.2390 +          }
 54.2391 +          break;
 54.2392 +        }
 54.2393 +        case 91:
 54.2394 +        {
 54.2395 +          if (Diff(cget(4), cget(2)))
 54.2396 +          {
 54.2397 +            PIXEL00_C
 54.2398 +            PIXEL01_C
 54.2399 +            PIXEL10_C
 54.2400 +          }
 54.2401 +          else
 54.2402 +          {
 54.2403 +            PIXEL00_4
 54.2404 +            PIXEL01_3
 54.2405 +            PIXEL10_3
 54.2406 +          }
 54.2407 +          if (Diff(cget(2), cget(6)))
 54.2408 +          {
 54.2409 +            PIXEL02_1M
 54.2410 +          }
 54.2411 +          else
 54.2412 +          {
 54.2413 +            PIXEL02_2
 54.2414 +          }
 54.2415 +          PIXEL11
 54.2416 +          PIXEL12_C
 54.2417 +          if (Diff(cget(8), cget(4)))
 54.2418 +          {
 54.2419 +            PIXEL20_1M
 54.2420 +          }
 54.2421 +          else
 54.2422 +          {
 54.2423 +            PIXEL20_2
 54.2424 +          }
 54.2425 +          PIXEL21_C
 54.2426 +          if (Diff(cget(6), cget(8)))
 54.2427 +          {
 54.2428 +            PIXEL22_1M
 54.2429 +          }
 54.2430 +          else
 54.2431 +          {
 54.2432 +            PIXEL22_2
 54.2433 +          }
 54.2434 +          break;
 54.2435 +        }
 54.2436 +        case 229:
 54.2437 +        {
 54.2438 +          PIXEL00_2
 54.2439 +          PIXEL01_1
 54.2440 +          PIXEL02_2
 54.2441 +          PIXEL10_1
 54.2442 +          PIXEL11
 54.2443 +          PIXEL12_1
 54.2444 +          PIXEL20_1L
 54.2445 +          PIXEL21_C
 54.2446 +          PIXEL22_1R
 54.2447 +          break;
 54.2448 +        }
 54.2449 +        case 167:
 54.2450 +        {
 54.2451 +          PIXEL00_1L
 54.2452 +          PIXEL01_C
 54.2453 +          PIXEL02_1R
 54.2454 +          PIXEL10_1
 54.2455 +          PIXEL11
 54.2456 +          PIXEL12_1
 54.2457 +          PIXEL20_2
 54.2458 +          PIXEL21_1
 54.2459 +          PIXEL22_2
 54.2460 +          break;
 54.2461 +        }
 54.2462 +        case 173:
 54.2463 +        {
 54.2464 +          PIXEL00_1U
 54.2465 +          PIXEL01_1
 54.2466 +          PIXEL02_2
 54.2467 +          PIXEL10_C
 54.2468 +          PIXEL11
 54.2469 +          PIXEL12_1
 54.2470 +          PIXEL20_1D
 54.2471 +          PIXEL21_1
 54.2472 +          PIXEL22_2
 54.2473 +          break;
 54.2474 +        }
 54.2475 +        case 181:
 54.2476 +        {
 54.2477 +          PIXEL00_2
 54.2478 +          PIXEL01_1
 54.2479 +          PIXEL02_1U
 54.2480 +          PIXEL10_1
 54.2481 +          PIXEL11
 54.2482 +          PIXEL12_C
 54.2483 +          PIXEL20_2
 54.2484 +          PIXEL21_1
 54.2485 +          PIXEL22_1D
 54.2486 +          break;
 54.2487 +        }
 54.2488 +        case 186:
 54.2489 +        {
 54.2490 +          if (Diff(cget(4), cget(2)))
 54.2491 +          {
 54.2492 +            PIXEL00_1M
 54.2493 +          }
 54.2494 +          else
 54.2495 +          {
 54.2496 +            PIXEL00_2
 54.2497 +          }
 54.2498 +          PIXEL01_C
 54.2499 +          if (Diff(cget(2), cget(6)))
 54.2500 +          {
 54.2501 +            PIXEL02_1M
 54.2502 +          }
 54.2503 +          else
 54.2504 +          {
 54.2505 +            PIXEL02_2
 54.2506 +          }
 54.2507 +          PIXEL10_C
 54.2508 +          PIXEL11
 54.2509 +          PIXEL12_C
 54.2510 +          PIXEL20_1D
 54.2511 +          PIXEL21_1
 54.2512 +          PIXEL22_1D
 54.2513 +          break;
 54.2514 +        }
 54.2515 +        case 115:
 54.2516 +        {
 54.2517 +          PIXEL00_1L
 54.2518 +          PIXEL01_C
 54.2519 +          if (Diff(cget(2), cget(6)))
 54.2520 +          {
 54.2521 +            PIXEL02_1M
 54.2522 +          }
 54.2523 +          else
 54.2524 +          {
 54.2525 +            PIXEL02_2
 54.2526 +          }
 54.2527 +          PIXEL10_1
 54.2528 +          PIXEL11
 54.2529 +          PIXEL12_C
 54.2530 +          PIXEL20_1L
 54.2531 +          PIXEL21_C
 54.2532 +          if (Diff(cget(6), cget(8)))
 54.2533 +          {
 54.2534 +            PIXEL22_1M
 54.2535 +          }
 54.2536 +          else
 54.2537 +          {
 54.2538 +            PIXEL22_2
 54.2539 +          }
 54.2540 +          break;
 54.2541 +        }
 54.2542 +        case 93:
 54.2543 +        {
 54.2544 +          PIXEL00_1U
 54.2545 +          PIXEL01_1
 54.2546 +          PIXEL02_1U
 54.2547 +          PIXEL10_C
 54.2548 +          PIXEL11
 54.2549 +          PIXEL12_C
 54.2550 +          if (Diff(cget(8), cget(4)))
 54.2551 +          {
 54.2552 +            PIXEL20_1M
 54.2553 +          }
 54.2554 +          else
 54.2555 +          {
 54.2556 +            PIXEL20_2
 54.2557 +          }
 54.2558 +          PIXEL21_C
 54.2559 +          if (Diff(cget(6), cget(8)))
 54.2560 +          {
 54.2561 +            PIXEL22_1M
 54.2562 +          }
 54.2563 +          else
 54.2564 +          {
 54.2565 +            PIXEL22_2
 54.2566 +          }
 54.2567 +          break;
 54.2568 +        }
 54.2569 +        case 206:
 54.2570 +        {
 54.2571 +          if (Diff(cget(4), cget(2)))
 54.2572 +          {
 54.2573 +            PIXEL00_1M
 54.2574 +          }
 54.2575 +          else
 54.2576 +          {
 54.2577 +            PIXEL00_2
 54.2578 +          }
 54.2579 +          PIXEL01_C
 54.2580 +          PIXEL02_1R
 54.2581 +          PIXEL10_C
 54.2582 +          PIXEL11
 54.2583 +          PIXEL12_1
 54.2584 +          if (Diff(cget(8), cget(4)))
 54.2585 +          {
 54.2586 +            PIXEL20_1M
 54.2587 +          }
 54.2588 +          else
 54.2589 +          {
 54.2590 +            PIXEL20_2
 54.2591 +          }
 54.2592 +          PIXEL21_C
 54.2593 +          PIXEL22_1R
 54.2594 +          break;
 54.2595 +        }
 54.2596 +        case 205:
 54.2597 +        case 201:
 54.2598 +        {
 54.2599 +          PIXEL00_1U
 54.2600 +          PIXEL01_1
 54.2601 +          PIXEL02_2
 54.2602 +          PIXEL10_C
 54.2603 +          PIXEL11
 54.2604 +          PIXEL12_1
 54.2605 +          if (Diff(cget(8), cget(4)))
 54.2606 +          {
 54.2607 +            PIXEL20_1M
 54.2608 +          }
 54.2609 +          else
 54.2610 +          {
 54.2611 +            PIXEL20_2
 54.2612 +          }
 54.2613 +          PIXEL21_C
 54.2614 +          PIXEL22_1R
 54.2615 +          break;
 54.2616 +        }
 54.2617 +        case 174:
 54.2618 +        case 46:
 54.2619 +        {
 54.2620 +          if (Diff(cget(4), cget(2)))
 54.2621 +          {
 54.2622 +            PIXEL00_1M
 54.2623 +          }
 54.2624 +          else
 54.2625 +          {
 54.2626 +            PIXEL00_2
 54.2627 +          }
 54.2628 +          PIXEL01_C
 54.2629 +          PIXEL02_1R
 54.2630 +          PIXEL10_C
 54.2631 +          PIXEL11
 54.2632 +          PIXEL12_1
 54.2633 +          PIXEL20_1D
 54.2634 +          PIXEL21_1
 54.2635 +          PIXEL22_2
 54.2636 +          break;
 54.2637 +        }
 54.2638 +        case 179:
 54.2639 +        case 147:
 54.2640 +        {
 54.2641 +          PIXEL00_1L
 54.2642 +          PIXEL01_C
 54.2643 +          if (Diff(cget(2), cget(6)))
 54.2644 +          {
 54.2645 +            PIXEL02_1M
 54.2646 +          }
 54.2647 +          else
 54.2648 +          {
 54.2649 +            PIXEL02_2
 54.2650 +          }
 54.2651 +          PIXEL10_1
 54.2652 +          PIXEL11
 54.2653 +          PIXEL12_C
 54.2654 +          PIXEL20_2
 54.2655 +          PIXEL21_1
 54.2656 +          PIXEL22_1D
 54.2657 +          break;
 54.2658 +        }
 54.2659 +        case 117:
 54.2660 +        case 116:
 54.2661 +        {
 54.2662 +          PIXEL00_2
 54.2663 +          PIXEL01_1
 54.2664 +          PIXEL02_1U
 54.2665 +          PIXEL10_1
 54.2666 +          PIXEL11
 54.2667 +          PIXEL12_C
 54.2668 +          PIXEL20_1L
 54.2669 +          PIXEL21_C
 54.2670 +          if (Diff(cget(6), cget(8)))
 54.2671 +          {
 54.2672 +            PIXEL22_1M
 54.2673 +          }
 54.2674 +          else
 54.2675 +          {
 54.2676 +            PIXEL22_2
 54.2677 +          }
 54.2678 +          break;
 54.2679 +        }
 54.2680 +        case 189:
 54.2681 +        {
 54.2682 +          PIXEL00_1U
 54.2683 +          PIXEL01_1
 54.2684 +          PIXEL02_1U
 54.2685 +          PIXEL10_C
 54.2686 +          PIXEL11
 54.2687 +          PIXEL12_C
 54.2688 +          PIXEL20_1D
 54.2689 +          PIXEL21_1
 54.2690 +          PIXEL22_1D
 54.2691 +          break;
 54.2692 +        }
 54.2693 +        case 231:
 54.2694 +        {
 54.2695 +          PIXEL00_1L
 54.2696 +          PIXEL01_C
 54.2697 +          PIXEL02_1R
 54.2698 +          PIXEL10_1
 54.2699 +          PIXEL11
 54.2700 +          PIXEL12_1
 54.2701 +          PIXEL20_1L
 54.2702 +          PIXEL21_C
 54.2703 +          PIXEL22_1R
 54.2704 +          break;
 54.2705 +        }
 54.2706 +        case 126:
 54.2707 +        {
 54.2708 +          PIXEL00_1M
 54.2709 +          if (Diff(cget(2), cget(6)))
 54.2710 +          {
 54.2711 +            PIXEL01_C
 54.2712 +            PIXEL02_C
 54.2713 +            PIXEL12_C
 54.2714 +          }
 54.2715 +          else
 54.2716 +          {
 54.2717 +            PIXEL01_3
 54.2718 +            PIXEL02_4
 54.2719 +            PIXEL12_3
 54.2720 +          }
 54.2721 +          PIXEL11
 54.2722 +          if (Diff(cget(8), cget(4)))
 54.2723 +          {
 54.2724 +            PIXEL10_C
 54.2725 +            PIXEL20_C
 54.2726 +            PIXEL21_C
 54.2727 +          }
 54.2728 +          else
 54.2729 +          {
 54.2730 +            PIXEL10_3
 54.2731 +            PIXEL20_4
 54.2732 +            PIXEL21_3
 54.2733 +          }
 54.2734 +          PIXEL22_1M
 54.2735 +          break;
 54.2736 +        }
 54.2737 +        case 219:
 54.2738 +        {
 54.2739 +          if (Diff(cget(4), cget(2)))
 54.2740 +          {
 54.2741 +            PIXEL00_C
 54.2742 +            PIXEL01_C
 54.2743 +            PIXEL10_C
 54.2744 +          }
 54.2745 +          else
 54.2746 +          {
 54.2747 +            PIXEL00_4
 54.2748 +            PIXEL01_3
 54.2749 +            PIXEL10_3
 54.2750 +          }
 54.2751 +          PIXEL02_1M
 54.2752 +          PIXEL11
 54.2753 +          PIXEL20_1M
 54.2754 +          if (Diff(cget(6), cget(8)))
 54.2755 +          {
 54.2756 +            PIXEL12_C
 54.2757 +            PIXEL21_C
 54.2758 +            PIXEL22_C
 54.2759 +          }
 54.2760 +          else
 54.2761 +          {
 54.2762 +            PIXEL12_3
 54.2763 +            PIXEL21_3
 54.2764 +            PIXEL22_4
 54.2765 +          }
 54.2766 +          break;
 54.2767 +        }
 54.2768 +        case 125:
 54.2769 +        {
 54.2770 +          if (Diff(cget(8), cget(4)))
 54.2771 +          {
 54.2772 +            PIXEL00_1U
 54.2773 +            PIXEL10_C
 54.2774 +            PIXEL20_C
 54.2775 +            PIXEL21_C
 54.2776 +          }
 54.2777 +          else
 54.2778 +          {
 54.2779 +            PIXEL00_2
 54.2780 +            PIXEL10_6
 54.2781 +            PIXEL20_5
 54.2782 +            PIXEL21_1
 54.2783 +          }
 54.2784 +          PIXEL01_1
 54.2785 +          PIXEL02_1U
 54.2786 +          PIXEL11
 54.2787 +          PIXEL12_C
 54.2788 +          PIXEL22_1M
 54.2789 +          break;
 54.2790 +        }
 54.2791 +        case 221:
 54.2792 +        {
 54.2793 +          if (Diff(cget(6), cget(8)))
 54.2794 +          {
 54.2795 +            PIXEL02_1U
 54.2796 +            PIXEL12_C
 54.2797 +            PIXEL21_C
 54.2798 +            PIXEL22_C
 54.2799 +          }
 54.2800 +          else
 54.2801 +          {
 54.2802 +            PIXEL02_2
 54.2803 +            PIXEL12_6
 54.2804 +            PIXEL21_1
 54.2805 +            PIXEL22_5
 54.2806 +          }
 54.2807 +          PIXEL00_1U
 54.2808 +          PIXEL01_1
 54.2809 +          PIXEL10_C
 54.2810 +          PIXEL11
 54.2811 +          PIXEL20_1M
 54.2812 +          break;
 54.2813 +        }
 54.2814 +        case 207:
 54.2815 +        {
 54.2816 +          if (Diff(cget(4), cget(2)))
 54.2817 +          {
 54.2818 +            PIXEL00_C
 54.2819 +            PIXEL01_C
 54.2820 +            PIXEL02_1R
 54.2821 +            PIXEL10_C
 54.2822 +          }
 54.2823 +          else
 54.2824 +          {
 54.2825 +            PIXEL00_5
 54.2826 +            PIXEL01_6
 54.2827 +            PIXEL02_2
 54.2828 +            PIXEL10_1
 54.2829 +          }
 54.2830 +          PIXEL11
 54.2831 +          PIXEL12_1
 54.2832 +          PIXEL20_1M
 54.2833 +          PIXEL21_C
 54.2834 +          PIXEL22_1R
 54.2835 +          break;
 54.2836 +        }
 54.2837 +        case 238:
 54.2838 +        {
 54.2839 +          if (Diff(cget(8), cget(4)))
 54.2840 +          {
 54.2841 +            PIXEL10_C
 54.2842 +            PIXEL20_C
 54.2843 +            PIXEL21_C
 54.2844 +            PIXEL22_1R
 54.2845 +          }
 54.2846 +          else
 54.2847 +          {
 54.2848 +            PIXEL10_1
 54.2849 +            PIXEL20_5
 54.2850 +            PIXEL21_6
 54.2851 +            PIXEL22_2
 54.2852 +          }
 54.2853 +          PIXEL00_1M
 54.2854 +          PIXEL01_C
 54.2855 +          PIXEL02_1R
 54.2856 +          PIXEL11
 54.2857 +          PIXEL12_1
 54.2858 +          break;
 54.2859 +        }
 54.2860 +        case 190:
 54.2861 +        {
 54.2862 +          if (Diff(cget(2), cget(6)))
 54.2863 +          {
 54.2864 +            PIXEL01_C
 54.2865 +            PIXEL02_C
 54.2866 +            PIXEL12_C
 54.2867 +            PIXEL22_1D
 54.2868 +          }
 54.2869 +          else
 54.2870 +          {
 54.2871 +            PIXEL01_1
 54.2872 +            PIXEL02_5
 54.2873 +            PIXEL12_6
 54.2874 +            PIXEL22_2
 54.2875 +          }
 54.2876 +          PIXEL00_1M
 54.2877 +          PIXEL10_C
 54.2878 +          PIXEL11
 54.2879 +          PIXEL20_1D
 54.2880 +          PIXEL21_1
 54.2881 +          break;
 54.2882 +        }
 54.2883 +        case 187:
 54.2884 +        {
 54.2885 +          if (Diff(cget(4), cget(2)))
 54.2886 +          {
 54.2887 +            PIXEL00_C
 54.2888 +            PIXEL01_C
 54.2889 +            PIXEL10_C
 54.2890 +            PIXEL20_1D
 54.2891 +          }
 54.2892 +          else
 54.2893 +          {
 54.2894 +            PIXEL00_5
 54.2895 +            PIXEL01_1
 54.2896 +            PIXEL10_6
 54.2897 +            PIXEL20_2
 54.2898 +          }
 54.2899 +          PIXEL02_1M
 54.2900 +          PIXEL11
 54.2901 +          PIXEL12_C
 54.2902 +          PIXEL21_1
 54.2903 +          PIXEL22_1D
 54.2904 +          break;
 54.2905 +        }
 54.2906 +        case 243:
 54.2907 +        {
 54.2908 +          if (Diff(cget(6), cget(8)))
 54.2909 +          {
 54.2910 +            PIXEL12_C
 54.2911 +            PIXEL20_1L
 54.2912 +            PIXEL21_C
 54.2913 +            PIXEL22_C
 54.2914 +          }
 54.2915 +          else
 54.2916 +          {
 54.2917 +            PIXEL12_1
 54.2918 +            PIXEL20_2
 54.2919 +            PIXEL21_6
 54.2920 +            PIXEL22_5
 54.2921 +          }
 54.2922 +          PIXEL00_1L
 54.2923 +          PIXEL01_C
 54.2924 +          PIXEL02_1M
 54.2925 +          PIXEL10_1
 54.2926 +          PIXEL11
 54.2927 +          break;
 54.2928 +        }
 54.2929 +        case 119:
 54.2930 +        {
 54.2931 +          if (Diff(cget(2), cget(6)))
 54.2932 +          {
 54.2933 +            PIXEL00_1L
 54.2934 +            PIXEL01_C
 54.2935 +            PIXEL02_C
 54.2936 +            PIXEL12_C
 54.2937 +          }
 54.2938 +          else
 54.2939 +          {
 54.2940 +            PIXEL00_2
 54.2941 +            PIXEL01_6
 54.2942 +            PIXEL02_5
 54.2943 +            PIXEL12_1
 54.2944 +          }
 54.2945 +          PIXEL10_1
 54.2946 +          PIXEL11
 54.2947 +          PIXEL20_1L
 54.2948 +          PIXEL21_C
 54.2949 +          PIXEL22_1M
 54.2950 +          break;
 54.2951 +        }
 54.2952 +        case 237:
 54.2953 +        case 233:
 54.2954 +        {
 54.2955 +          PIXEL00_1U
 54.2956 +          PIXEL01_1
 54.2957 +          PIXEL02_2
 54.2958 +          PIXEL10_C
 54.2959 +          PIXEL11
 54.2960 +          PIXEL12_1
 54.2961 +          if (Diff(cget(8), cget(4)))
 54.2962 +          {
 54.2963 +            PIXEL20_C
 54.2964 +          }
 54.2965 +          else
 54.2966 +          {
 54.2967 +            PIXEL20_2
 54.2968 +          }
 54.2969 +          PIXEL21_C
 54.2970 +          PIXEL22_1R
 54.2971 +          break;
 54.2972 +        }
 54.2973 +        case 175:
 54.2974 +        case 47:
 54.2975 +        {
 54.2976 +          if (Diff(cget(4), cget(2)))
 54.2977 +          {
 54.2978 +            PIXEL00_C
 54.2979 +          }
 54.2980 +          else
 54.2981 +          {
 54.2982 +            PIXEL00_2
 54.2983 +          }
 54.2984 +          PIXEL01_C
 54.2985 +          PIXEL02_1R
 54.2986 +          PIXEL10_C
 54.2987 +          PIXEL11
 54.2988 +          PIXEL12_1
 54.2989 +          PIXEL20_1D
 54.2990 +          PIXEL21_1
 54.2991 +          PIXEL22_2
 54.2992 +          break;
 54.2993 +        }
 54.2994 +        case 183:
 54.2995 +        case 151:
 54.2996 +        {
 54.2997 +          PIXEL00_1L
 54.2998 +          PIXEL01_C
 54.2999 +          if (Diff(cget(2), cget(6)))
 54.3000 +          {
 54.3001 +            PIXEL02_C
 54.3002 +          }
 54.3003 +          else
 54.3004 +          {
 54.3005 +            PIXEL02_2
 54.3006 +          }
 54.3007 +          PIXEL10_1
 54.3008 +          PIXEL11
 54.3009 +          PIXEL12_C
 54.3010 +          PIXEL20_2
 54.3011 +          PIXEL21_1
 54.3012 +          PIXEL22_1D
 54.3013 +          break;
 54.3014 +        }
 54.3015 +        case 245:
 54.3016 +        case 244:
 54.3017 +        {
 54.3018 +          PIXEL00_2
 54.3019 +          PIXEL01_1
 54.3020 +          PIXEL02_1U
 54.3021 +          PIXEL10_1
 54.3022 +          PIXEL11
 54.3023 +          PIXEL12_C
 54.3024 +          PIXEL20_1L
 54.3025 +          PIXEL21_C
 54.3026 +          if (Diff(cget(6), cget(8)))
 54.3027 +          {
 54.3028 +            PIXEL22_C
 54.3029 +          }
 54.3030 +          else
 54.3031 +          {
 54.3032 +            PIXEL22_2
 54.3033 +          }
 54.3034 +          break;
 54.3035 +        }
 54.3036 +        case 250:
 54.3037 +        {
 54.3038 +          PIXEL00_1M
 54.3039 +          PIXEL01_C
 54.3040 +          PIXEL02_1M
 54.3041 +          PIXEL11
 54.3042 +          if (Diff(cget(8), cget(4)))
 54.3043 +          {
 54.3044 +            PIXEL10_C
 54.3045 +            PIXEL20_C
 54.3046 +          }
 54.3047 +          else
 54.3048 +          {
 54.3049 +            PIXEL10_3
 54.3050 +            PIXEL20_4
 54.3051 +          }
 54.3052 +          PIXEL21_C
 54.3053 +          if (Diff(cget(6), cget(8)))
 54.3054 +          {
 54.3055 +            PIXEL12_C
 54.3056 +            PIXEL22_C
 54.3057 +          }
 54.3058 +          else
 54.3059 +          {
 54.3060 +            PIXEL12_3
 54.3061 +            PIXEL22_4
 54.3062 +          }
 54.3063 +          break;
 54.3064 +        }
 54.3065 +        case 123:
 54.3066 +        {
 54.3067 +          if (Diff(cget(4), cget(2)))
 54.3068 +          {
 54.3069 +            PIXEL00_C
 54.3070 +            PIXEL01_C
 54.3071 +          }
 54.3072 +          else
 54.3073 +          {
 54.3074 +            PIXEL00_4
 54.3075 +            PIXEL01_3
 54.3076 +          }
 54.3077 +          PIXEL02_1M
 54.3078 +          PIXEL10_C
 54.3079 +          PIXEL11
 54.3080 +          PIXEL12_C
 54.3081 +          if (Diff(cget(8), cget(4)))
 54.3082 +          {
 54.3083 +            PIXEL20_C
 54.3084 +            PIXEL21_C
 54.3085 +          }
 54.3086 +          else
 54.3087 +          {
 54.3088 +            PIXEL20_4
 54.3089 +            PIXEL21_3
 54.3090 +          }
 54.3091 +          PIXEL22_1M
 54.3092 +          break;
 54.3093 +        }
 54.3094 +        case 95:
 54.3095 +        {
 54.3096 +          if (Diff(cget(4), cget(2)))
 54.3097 +          {
 54.3098 +            PIXEL00_C
 54.3099 +            PIXEL10_C
 54.3100 +          }
 54.3101 +          else
 54.3102 +          {
 54.3103 +            PIXEL00_4
 54.3104 +            PIXEL10_3
 54.3105 +          }
 54.3106 +          PIXEL01_C
 54.3107 +          if (Diff(cget(2), cget(6)))
 54.3108 +          {
 54.3109 +            PIXEL02_C
 54.3110 +            PIXEL12_C
 54.3111 +          }
 54.3112 +          else
 54.3113 +          {
 54.3114 +            PIXEL02_4
 54.3115 +            PIXEL12_3
 54.3116 +          }
 54.3117 +          PIXEL11
 54.3118 +          PIXEL20_1M
 54.3119 +          PIXEL21_C
 54.3120 +          PIXEL22_1M
 54.3121 +          break;
 54.3122 +        }
 54.3123 +        case 222:
 54.3124 +        {
 54.3125 +          PIXEL00_1M
 54.3126 +          if (Diff(cget(2), cget(6)))
 54.3127 +          {
 54.3128 +            PIXEL01_C
 54.3129 +            PIXEL02_C
 54.3130 +          }
 54.3131 +          else
 54.3132 +          {
 54.3133 +            PIXEL01_3
 54.3134 +            PIXEL02_4
 54.3135 +          }
 54.3136 +          PIXEL10_C
 54.3137 +          PIXEL11
 54.3138 +          PIXEL12_C
 54.3139 +          PIXEL20_1M
 54.3140 +          if (Diff(cget(6), cget(8)))
 54.3141 +          {
 54.3142 +            PIXEL21_C
 54.3143 +            PIXEL22_C
 54.3144 +          }
 54.3145 +          else
 54.3146 +          {
 54.3147 +            PIXEL21_3
 54.3148 +            PIXEL22_4
 54.3149 +          }
 54.3150 +          break;
 54.3151 +        }
 54.3152 +        case 252:
 54.3153 +        {
 54.3154 +          PIXEL00_1M
 54.3155 +          PIXEL01_1
 54.3156 +          PIXEL02_1U
 54.3157 +          PIXEL11
 54.3158 +          PIXEL12_C
 54.3159 +          if (Diff(cget(8), cget(4)))
 54.3160 +          {
 54.3161 +            PIXEL10_C
 54.3162 +            PIXEL20_C
 54.3163 +          }
 54.3164 +          else
 54.3165 +          {
 54.3166 +            PIXEL10_3
 54.3167 +            PIXEL20_4
 54.3168 +          }
 54.3169 +          PIXEL21_C
 54.3170 +          if (Diff(cget(6), cget(8)))
 54.3171 +          {
 54.3172 +            PIXEL22_C
 54.3173 +          }
 54.3174 +          else
 54.3175 +          {
 54.3176 +            PIXEL22_2
 54.3177 +          }
 54.3178 +          break;
 54.3179 +        }
 54.3180 +        case 249:
 54.3181 +        {
 54.3182 +          PIXEL00_1U
 54.3183 +          PIXEL01_1
 54.3184 +          PIXEL02_1M
 54.3185 +          PIXEL10_C
 54.3186 +          PIXEL11
 54.3187 +          if (Diff(cget(8), cget(4)))
 54.3188 +          {
 54.3189 +            PIXEL20_C
 54.3190 +          }
 54.3191 +          else
 54.3192 +          {
 54.3193 +            PIXEL20_2
 54.3194 +          }
 54.3195 +          PIXEL21_C
 54.3196 +          if (Diff(cget(6), cget(8)))
 54.3197 +          {
 54.3198 +            PIXEL12_C
 54.3199 +            PIXEL22_C
 54.3200 +          }
 54.3201 +          else
 54.3202 +          {
 54.3203 +            PIXEL12_3
 54.3204 +            PIXEL22_4
 54.3205 +          }
 54.3206 +          break;
 54.3207 +        }
 54.3208 +        case 235:
 54.3209 +        {
 54.3210 +          if (Diff(cget(4), cget(2)))
 54.3211 +          {
 54.3212 +            PIXEL00_C
 54.3213 +            PIXEL01_C
 54.3214 +          }
 54.3215 +          else
 54.3216 +          {
 54.3217 +            PIXEL00_4
 54.3218 +            PIXEL01_3
 54.3219 +          }
 54.3220 +          PIXEL02_1M
 54.3221 +          PIXEL10_C
 54.3222 +          PIXEL11
 54.3223 +          PIXEL12_1
 54.3224 +          if (Diff(cget(8), cget(4)))
 54.3225 +          {
 54.3226 +            PIXEL20_C
 54.3227 +          }
 54.3228 +          else
 54.3229 +          {
 54.3230 +            PIXEL20_2
 54.3231 +          }
 54.3232 +          PIXEL21_C
 54.3233 +          PIXEL22_1R
 54.3234 +          break;
 54.3235 +        }
 54.3236 +        case 111:
 54.3237 +        {
 54.3238 +          if (Diff(cget(4), cget(2)))
 54.3239 +          {
 54.3240 +            PIXEL00_C
 54.3241 +          }
 54.3242 +          else
 54.3243 +          {
 54.3244 +            PIXEL00_2
 54.3245 +          }
 54.3246 +          PIXEL01_C
 54.3247 +          PIXEL02_1R
 54.3248 +          PIXEL10_C
 54.3249 +          PIXEL11
 54.3250 +          PIXEL12_1
 54.3251 +          if (Diff(cget(8), cget(4)))
 54.3252 +          {
 54.3253 +            PIXEL20_C
 54.3254 +            PIXEL21_C
 54.3255 +          }
 54.3256 +          else
 54.3257 +          {
 54.3258 +            PIXEL20_4
 54.3259 +            PIXEL21_3
 54.3260 +          }
 54.3261 +          PIXEL22_1M
 54.3262 +          break;
 54.3263 +        }
 54.3264 +        case 63:
 54.3265 +        {
 54.3266 +          if (Diff(cget(4), cget(2)))
 54.3267 +          {
 54.3268 +            PIXEL00_C
 54.3269 +          }
 54.3270 +          else
 54.3271 +          {
 54.3272 +            PIXEL00_2
 54.3273 +          }
 54.3274 +          PIXEL01_C
 54.3275 +          if (Diff(cget(2), cget(6)))
 54.3276 +          {
 54.3277 +            PIXEL02_C
 54.3278 +            PIXEL12_C
 54.3279 +          }
 54.3280 +          else
 54.3281 +          {
 54.3282 +            PIXEL02_4
 54.3283 +            PIXEL12_3
 54.3284 +          }
 54.3285 +          PIXEL10_C
 54.3286 +          PIXEL11
 54.3287 +          PIXEL20_1D
 54.3288 +          PIXEL21_1
 54.3289 +          PIXEL22_1M
 54.3290 +          break;
 54.3291 +        }
 54.3292 +        case 159:
 54.3293 +        {
 54.3294 +          if (Diff(cget(4), cget(2)))
 54.3295 +          {
 54.3296 +            PIXEL00_C
 54.3297 +            PIXEL10_C
 54.3298 +          }
 54.3299 +          else
 54.3300 +          {
 54.3301 +            PIXEL00_4
 54.3302 +            PIXEL10_3
 54.3303 +          }
 54.3304 +          PIXEL01_C
 54.3305 +          if (Diff(cget(2), cget(6)))
 54.3306 +          {
 54.3307 +            PIXEL02_C
 54.3308 +          }
 54.3309 +          else
 54.3310 +          {
 54.3311 +            PIXEL02_2
 54.3312 +          }
 54.3313 +          PIXEL11
 54.3314 +          PIXEL12_C
 54.3315 +          PIXEL20_1M
 54.3316 +          PIXEL21_1
 54.3317 +          PIXEL22_1D
 54.3318 +          break;
 54.3319 +        }
 54.3320 +        case 215:
 54.3321 +        {
 54.3322 +          PIXEL00_1L
 54.3323 +          PIXEL01_C
 54.3324 +          if (Diff(cget(2), cget(6)))
 54.3325 +          {
 54.3326 +            PIXEL02_C
 54.3327 +          }
 54.3328 +          else
 54.3329 +          {
 54.3330 +            PIXEL02_2
 54.3331 +          }
 54.3332 +          PIXEL10_1
 54.3333 +          PIXEL11
 54.3334 +          PIXEL12_C
 54.3335 +          PIXEL20_1M
 54.3336 +          if (Diff(cget(6), cget(8)))
 54.3337 +          {
 54.3338 +            PIXEL21_C
 54.3339 +            PIXEL22_C
 54.3340 +          }
 54.3341 +          else
 54.3342 +          {
 54.3343 +            PIXEL21_3
 54.3344 +            PIXEL22_4
 54.3345 +          }
 54.3346 +          break;
 54.3347 +        }
 54.3348 +        case 246:
 54.3349 +        {
 54.3350 +          PIXEL00_1M
 54.3351 +          if (Diff(cget(2), cget(6)))
 54.3352 +          {
 54.3353 +            PIXEL01_C
 54.3354 +            PIXEL02_C
 54.3355 +          }
 54.3356 +          else
 54.3357 +          {
 54.3358 +            PIXEL01_3
 54.3359 +            PIXEL02_4
 54.3360 +          }
 54.3361 +          PIXEL10_1
 54.3362 +          PIXEL11
 54.3363 +          PIXEL12_C
 54.3364 +          PIXEL20_1L
 54.3365 +          PIXEL21_C
 54.3366 +          if (Diff(cget(6), cget(8)))
 54.3367 +          {
 54.3368 +            PIXEL22_C
 54.3369 +          }
 54.3370 +          else
 54.3371 +          {
 54.3372 +            PIXEL22_2
 54.3373 +          }
 54.3374 +          break;
 54.3375 +        }
 54.3376 +        case 254:
 54.3377 +        {
 54.3378 +          PIXEL00_1M
 54.3379 +          if (Diff(cget(2), cget(6)))
 54.3380 +          {
 54.3381 +            PIXEL01_C
 54.3382 +            PIXEL02_C
 54.3383 +          }
 54.3384 +          else
 54.3385 +          {
 54.3386 +            PIXEL01_3
 54.3387 +            PIXEL02_4
 54.3388 +          }
 54.3389 +          PIXEL11
 54.3390 +          if (Diff(cget(8), cget(4)))
 54.3391 +          {
 54.3392 +            PIXEL10_C
 54.3393 +            PIXEL20_C
 54.3394 +          }
 54.3395 +          else
 54.3396 +          {
 54.3397 +            PIXEL10_3
 54.3398 +            PIXEL20_4
 54.3399 +          }
 54.3400 +          if (Diff(cget(6), cget(8)))
 54.3401 +          {
 54.3402 +            PIXEL12_C
 54.3403 +            PIXEL21_C
 54.3404 +            PIXEL22_C
 54.3405 +          }
 54.3406 +          else
 54.3407 +          {
 54.3408 +            PIXEL12_3
 54.3409 +            PIXEL21_3
 54.3410 +            PIXEL22_2
 54.3411 +          }
 54.3412 +          break;
 54.3413 +        }
 54.3414 +        case 253:
 54.3415 +        {
 54.3416 +          PIXEL00_1U
 54.3417 +          PIXEL01_1
 54.3418 +          PIXEL02_1U
 54.3419 +          PIXEL10_C
 54.3420 +          PIXEL11
 54.3421 +          PIXEL12_C
 54.3422 +          if (Diff(cget(8), cget(4)))
 54.3423 +          {
 54.3424 +            PIXEL20_C
 54.3425 +          }
 54.3426 +          else
 54.3427 +          {
 54.3428 +            PIXEL20_2
 54.3429 +          }
 54.3430 +          PIXEL21_C
 54.3431 +          if (Diff(cget(6), cget(8)))
 54.3432 +          {
 54.3433 +            PIXEL22_C
 54.3434 +          }
 54.3435 +          else
 54.3436 +          {
 54.3437 +            PIXEL22_2
 54.3438 +          }
 54.3439 +          break;
 54.3440 +        }
 54.3441 +        case 251:
 54.3442 +        {
 54.3443 +          if (Diff(cget(4), cget(2)))
 54.3444 +          {
 54.3445 +            PIXEL00_C
 54.3446 +            PIXEL01_C
 54.3447 +          }
 54.3448 +          else
 54.3449 +          {
 54.3450 +            PIXEL00_4
 54.3451 +            PIXEL01_3
 54.3452 +          }
 54.3453 +          PIXEL02_1M
 54.3454 +          PIXEL11
 54.3455 +          if (Diff(cget(8), cget(4)))
 54.3456 +          {
 54.3457 +            PIXEL10_C
 54.3458 +            PIXEL20_C
 54.3459 +            PIXEL21_C
 54.3460 +          }
 54.3461 +          else
 54.3462 +          {
 54.3463 +            PIXEL10_3
 54.3464 +            PIXEL20_2
 54.3465 +            PIXEL21_3
 54.3466 +          }
 54.3467 +          if (Diff(cget(6), cget(8)))
 54.3468 +          {
 54.3469 +            PIXEL12_C
 54.3470 +            PIXEL22_C
 54.3471 +          }
 54.3472 +          else
 54.3473 +          {
 54.3474 +            PIXEL12_3
 54.3475 +            PIXEL22_4
 54.3476 +          }
 54.3477 +          break;
 54.3478 +        }
 54.3479 +        case 239:
 54.3480 +        {
 54.3481 +          if (Diff(cget(4), cget(2)))
 54.3482 +          {
 54.3483 +            PIXEL00_C
 54.3484 +          }
 54.3485 +          else
 54.3486 +          {
 54.3487 +            PIXEL00_2
 54.3488 +          }
 54.3489 +          PIXEL01_C
 54.3490 +          PIXEL02_1R
 54.3491 +          PIXEL10_C
 54.3492 +          PIXEL11
 54.3493 +          PIXEL12_1
 54.3494 +          if (Diff(cget(8), cget(4)))
 54.3495 +          {
 54.3496 +            PIXEL20_C
 54.3497 +          }
 54.3498 +          else
 54.3499 +          {
 54.3500 +            PIXEL20_2
 54.3501 +          }
 54.3502 +          PIXEL21_C
 54.3503 +          PIXEL22_1R
 54.3504 +          break;
 54.3505 +        }
 54.3506 +        case 127:
 54.3507 +        {
 54.3508 +          if (Diff(cget(4), cget(2)))
 54.3509 +          {
 54.3510 +            PIXEL00_C
 54.3511 +            PIXEL01_C
 54.3512 +            PIXEL10_C
 54.3513 +          }
 54.3514 +          else
 54.3515 +          {
 54.3516 +            PIXEL00_2
 54.3517 +            PIXEL01_3
 54.3518 +            PIXEL10_3
 54.3519 +          }
 54.3520 +          if (Diff(cget(2), cget(6)))
 54.3521 +          {
 54.3522 +            PIXEL02_C
 54.3523 +            PIXEL12_C
 54.3524 +          }
 54.3525 +          else
 54.3526 +          {
 54.3527 +            PIXEL02_4
 54.3528 +            PIXEL12_3
 54.3529 +          }
 54.3530 +          PIXEL11
 54.3531 +          if (Diff(cget(8), cget(4)))
 54.3532 +          {
 54.3533 +            PIXEL20_C
 54.3534 +            PIXEL21_C
 54.3535 +          }
 54.3536 +          else
 54.3537 +          {
 54.3538 +            PIXEL20_4
 54.3539 +            PIXEL21_3
 54.3540 +          }
 54.3541 +          PIXEL22_1M
 54.3542 +          break;
 54.3543 +        }
 54.3544 +        case 191:
 54.3545 +        {
 54.3546 +          if (Diff(cget(4), cget(2)))
 54.3547 +          {
 54.3548 +            PIXEL00_C
 54.3549 +          }
 54.3550 +          else
 54.3551 +          {
 54.3552 +            PIXEL00_2
 54.3553 +          }
 54.3554 +          PIXEL01_C
 54.3555 +          if (Diff(cget(2), cget(6)))
 54.3556 +          {
 54.3557 +            PIXEL02_C
 54.3558 +          }
 54.3559 +          else
 54.3560 +          {
 54.3561 +            PIXEL02_2
 54.3562 +          }
 54.3563 +          PIXEL10_C
 54.3564 +          PIXEL11
 54.3565 +          PIXEL12_C
 54.3566 +          PIXEL20_1D
 54.3567 +          PIXEL21_1
 54.3568 +          PIXEL22_1D
 54.3569 +          break;
 54.3570 +        }
 54.3571 +        case 223:
 54.3572 +        {
 54.3573 +          if (Diff(cget(4), cget(2)))
 54.3574 +          {
 54.3575 +            PIXEL00_C
 54.3576 +            PIXEL10_C
 54.3577 +          }
 54.3578 +          else
 54.3579 +          {
 54.3580 +            PIXEL00_4
 54.3581 +            PIXEL10_3
 54.3582 +          }
 54.3583 +          if (Diff(cget(2), cget(6)))
 54.3584 +          {
 54.3585 +            PIXEL01_C
 54.3586 +            PIXEL02_C
 54.3587 +            PIXEL12_C
 54.3588 +          }
 54.3589 +          else
 54.3590 +          {
 54.3591 +            PIXEL01_3
 54.3592 +            PIXEL02_2
 54.3593 +            PIXEL12_3
 54.3594 +          }
 54.3595 +          PIXEL11
 54.3596 +          PIXEL20_1M
 54.3597 +          if (Diff(cget(6), cget(8)))
 54.3598 +          {
 54.3599 +            PIXEL21_C
 54.3600 +            PIXEL22_C
 54.3601 +          }
 54.3602 +          else
 54.3603 +          {
 54.3604 +            PIXEL21_3
 54.3605 +            PIXEL22_4
 54.3606 +          }
 54.3607 +          break;
 54.3608 +        }
 54.3609 +        case 247:
 54.3610 +        {
 54.3611 +          PIXEL00_1L
 54.3612 +          PIXEL01_C
 54.3613 +          if (Diff(cget(2), cget(6)))
 54.3614 +          {
 54.3615 +            PIXEL02_C
 54.3616 +          }
 54.3617 +          else
 54.3618 +          {
 54.3619 +            PIXEL02_2
 54.3620 +          }
 54.3621 +          PIXEL10_1
 54.3622 +          PIXEL11
 54.3623 +          PIXEL12_C
 54.3624 +          PIXEL20_1L
 54.3625 +          PIXEL21_C
 54.3626 +          if (Diff(cget(6), cget(8)))
 54.3627 +          {
 54.3628 +            PIXEL22_C
 54.3629 +          }
 54.3630 +          else
 54.3631 +          {
 54.3632 +            PIXEL22_2
 54.3633 +          }
 54.3634 +          break;
 54.3635 +        }
 54.3636 +        case 255:
 54.3637 +        {
 54.3638 +          if (Diff(cget(4), cget(2)))
 54.3639 +          {
 54.3640 +            PIXEL00_C
 54.3641 +          }
 54.3642 +          else
 54.3643 +          {
 54.3644 +            PIXEL00_2
 54.3645 +          }
 54.3646 +          PIXEL01_C
 54.3647 +          if (Diff(cget(2), cget(6)))
 54.3648 +          {
 54.3649 +            PIXEL02_C
 54.3650 +          }
 54.3651 +          else
 54.3652 +          {
 54.3653 +            PIXEL02_2
 54.3654 +          }
 54.3655 +          PIXEL10_C
 54.3656 +          PIXEL11
 54.3657 +          PIXEL12_C
 54.3658 +          if (Diff(cget(8), cget(4)))
 54.3659 +          {
 54.3660 +            PIXEL20_C
 54.3661 +          }
 54.3662 +          else
 54.3663 +          {
 54.3664 +            PIXEL20_2
 54.3665 +          }
 54.3666 +          PIXEL21_C
 54.3667 +          if (Diff(cget(6), cget(8)))
 54.3668 +          {
 54.3669 +            PIXEL22_C
 54.3670 +          }
 54.3671 +          else
 54.3672 +          {
 54.3673 +            PIXEL22_2
 54.3674 +          }
 54.3675 +          break;
 54.3676 +        }
 54.3677 +      }
    55.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    55.2 +++ b/src/filters/hq_shared32.cpp	Sat Mar 03 10:31:27 2012 -0600
    55.3 @@ -0,0 +1,389 @@
    55.4 +#include "../Port.h"
    55.5 +#include "hq_shared32.h"
    55.6 +#include "interp.h"
    55.7 +
    55.8 +const unsigned __int64 reg_blank = 0x0000000000000000;
    55.9 +const unsigned __int64 const7	 = 0x0000000700070007;
   55.10 +const unsigned __int64 treshold	 = 0x0000000000300706;
   55.11 +
   55.12 +void Interp1(unsigned char *pc, unsigned int c1, unsigned int c2)
   55.13 +{
   55.14 +	//*((int*)pc) = (c1*3+c2)/4;
   55.15 +
   55.16 +#ifdef MMX
   55.17 +	__asm
   55.18 +	{
   55.19 +		mov eax, pc
   55.20 +		movd mm1, c1
   55.21 +		movd mm2, c2
   55.22 +		movq mm0, mm1
   55.23 +		pslld mm0, 2
   55.24 +		psubd mm0, mm1
   55.25 +		paddd mm0, mm2
   55.26 +		psrld mm0, 2
   55.27 +		movd    [eax], mm0
   55.28 +		    EMMS
   55.29 +	}
   55.30 +#else
   55.31 +	__asm
   55.32 +	{
   55.33 +		mov eax, pc
   55.34 +		mov edx, c1
   55.35 +		shl edx, 2
   55.36 +		add edx, c2
   55.37 +		sub edx, c1
   55.38 +		shr edx, 2
   55.39 +		mov        [eax], edx
   55.40 +	}
   55.41 +#endif
   55.42 +}
   55.43 +
   55.44 +void Interp2(unsigned char *pc, unsigned int c1, unsigned int c2, unsigned int c3)
   55.45 +{
   55.46 +	//*((int*)pc) = (c1*2+c2+c3)/4;
   55.47 +
   55.48 +#ifdef MMX
   55.49 +	__asm
   55.50 +	{
   55.51 +		mov eax, pc
   55.52 +		movd mm0, c1
   55.53 +		movd mm1, c2
   55.54 +		movd mm2, c3
   55.55 +		pslld mm0, 1
   55.56 +		paddd mm0, mm1
   55.57 +		paddd mm0, mm2
   55.58 +		psrad mm0, 2
   55.59 +		movd [eax], mm0
   55.60 +		    EMMS
   55.61 +	}
   55.62 +#else
   55.63 +	__asm
   55.64 +	{
   55.65 +		mov eax, pc
   55.66 +		mov edx, c1
   55.67 +		shl edx, 1
   55.68 +		add edx, c2
   55.69 +		add edx, c3
   55.70 +		shr edx, 2
   55.71 +		mov        [eax], edx
   55.72 +	}
   55.73 +#endif
   55.74 +}
   55.75 +
   55.76 +void Interp3(unsigned char *pc, unsigned int c1, unsigned int c2)
   55.77 +{
   55.78 +	//*((int*)pc) = (c1*7+c2)/8;
   55.79 +	//*((int*)pc) = ((((c1 & 0x00FF00)*7 + (c2 & 0x00FF00) ) & 0x0007F800) +
   55.80 +	//	            (((c1 & 0xFF00FF)*7 + (c2 & 0xFF00FF) ) & 0x07F807F8)) >> 3;
   55.81 +
   55.82 +#ifdef MMX
   55.83 +	__asm
   55.84 +	{
   55.85 +		mov eax, pc
   55.86 +		movd mm1, c1
   55.87 +		movd mm2, c2
   55.88 +		punpcklbw mm1, reg_blank
   55.89 +		punpcklbw mm2, reg_blank
   55.90 +		pmullw mm1, const7
   55.91 +		paddw mm1, mm2
   55.92 +		psrlw mm1, 3
   55.93 +		packuswb mm1, reg_blank
   55.94 +		    movd       [eax], mm1
   55.95 +		    EMMS
   55.96 +	}
   55.97 +#else
   55.98 +	__asm
   55.99 +	{
  55.100 +		mov eax, c1
  55.101 +		mov ebx, c2
  55.102 +		mov ecx, eax
  55.103 +		shl ecx, 3
  55.104 +		sub ecx, eax
  55.105 +		add ecx, ebx
  55.106 +		shr ecx, 3
  55.107 +		mov eax, pc
  55.108 +		    mov     [eax], ecx
  55.109 +	}
  55.110 +#endif
  55.111 +}
  55.112 +
  55.113 +void Interp4(unsigned char *pc, unsigned int c1, unsigned int c2, unsigned int c3)
  55.114 +{
  55.115 +	//*((int*)pc) = (c1*2+(c2+c3)*7)/16;
  55.116 +	//*((int*)pc) = ((((c1 & 0x00FF00)*2 + ((c2 & 0x00FF00) + (c3 & 0x00FF00))*7 ) & 0x000FF000) +
  55.117 +	//              (((c1 & 0xFF00FF)*2 + ((c2 & 0xFF00FF) + (c3 & 0xFF00FF))*7 ) & 0x0FF00FF0)) >> 4;
  55.118 +
  55.119 +#ifdef MMX
  55.120 +	__asm
  55.121 +	{
  55.122 +		mov eax, pc
  55.123 +		movd mm1, c1
  55.124 +		movd mm2, c2
  55.125 +		movd mm3, c3
  55.126 +		punpcklbw mm1, reg_blank
  55.127 +		punpcklbw mm2, reg_blank
  55.128 +		punpcklbw mm3, reg_blank
  55.129 +		psllw mm1, 1
  55.130 +		paddw mm2, mm3
  55.131 +		pmullw mm2, const7
  55.132 +		paddw mm1, mm2
  55.133 +		psrlw mm1, 4
  55.134 +		packuswb mm1, reg_blank
  55.135 +		    movd       [eax], mm1
  55.136 +		    EMMS
  55.137 +	}
  55.138 +#else
  55.139 +
  55.140 +	__asm
  55.141 +	{
  55.142 +		mov eax, [c1]
  55.143 +		and     eax, 0FF00h
  55.144 +		shl eax, 1
  55.145 +		mov ecx, [c2]
  55.146 +		and     ecx, 0FF00h
  55.147 +		mov edx, [c3]
  55.148 +		and     edx, 0FF00h
  55.149 +		add ecx, edx
  55.150 +		imul ecx, ecx, 7
  55.151 +		add eax, ecx
  55.152 +		and     eax, 0FF000h
  55.153 +
  55.154 +		mov ebx, [c1]
  55.155 +		and     ebx, 0FF00FFh
  55.156 +		shl ebx, 1
  55.157 +		mov ecx, [c2]
  55.158 +		and     ecx, 0FF00FFh
  55.159 +		mov edx, [c3]
  55.160 +		and     edx, 0FF00FFh
  55.161 +		add ecx, edx
  55.162 +		imul ecx, ecx, 7
  55.163 +		add ebx, ecx
  55.164 +		and     ebx, 0FF00FF0h
  55.165 +
  55.166 +		add eax, ebx
  55.167 +		shr eax, 4
  55.168 +
  55.169 +		mov ebx, pc
  55.170 +		    mov     [ebx], eax
  55.171 +	}
  55.172 +#endif
  55.173 +}
  55.174 +
  55.175 +void Interp5(unsigned char *pc, unsigned int c1, unsigned int c2)
  55.176 +{
  55.177 +	//*((int*)pc) = (c1+c2)/2;
  55.178 +
  55.179 +#ifdef MMX
  55.180 +	__asm
  55.181 +	{
  55.182 +		mov eax, pc
  55.183 +		movd mm0, c1
  55.184 +		movd mm1, c2
  55.185 +		paddd mm0, mm1
  55.186 +		psrad mm0, 1
  55.187 +		movd    [eax], mm0
  55.188 +		    EMMS
  55.189 +	}
  55.190 +#else
  55.191 +	__asm
  55.192 +	{
  55.193 +		mov eax, pc
  55.194 +		mov edx, c1
  55.195 +		add edx, c2
  55.196 +		shr edx, 1
  55.197 +		mov        [eax], edx
  55.198 +	}
  55.199 +#endif
  55.200 +}
  55.201 +
  55.202 +void Interp1_16(unsigned char *pc, unsigned short c1, unsigned short c2)
  55.203 +{
  55.204 +	*((unsigned short *)pc) = interp_16_31(c1, c2);
  55.205 +	//*((int*)pc) = (c1*3+c2)/4;
  55.206 +}
  55.207 +
  55.208 +void Interp2_16(unsigned char *pc, unsigned short c1, unsigned short c2, unsigned short c3)
  55.209 +{
  55.210 +	*((unsigned short *)pc) = interp_16_211(c1, c2, c3);
  55.211 +	//*((int*)pc) = (c1*2+c2+c3)/4;
  55.212 +}
  55.213 +
  55.214 +void Interp3_16(unsigned char *pc, unsigned short c1, unsigned short c2)
  55.215 +{
  55.216 +	*((unsigned short *)pc) = interp_16_71(c1, c2);
  55.217 +//	*((unsigned short*)pc) = (c1*7+c2)/8;
  55.218 +//	*((unsigned short*)pc) = ((((c1 & 0x00FF00)*7 + (c2 & 0x00FF00) ) & 0x0007F800) +
  55.219 +//		            (((c1 & 0xFF00FF)*7 + (c2 & 0xFF00FF) ) & 0x07F807F8)) >> 3;
  55.220 +}
  55.221 +
  55.222 +void Interp4_16(unsigned char *pc, unsigned short c1, unsigned short c2, unsigned short c3)
  55.223 +{
  55.224 +	*((unsigned short *)pc) = interp_16_772(c2, c3, c1);
  55.225 +//	*((unsigned short*)pc) = (c1*2+(c2+c3)*7)/16;
  55.226 +//	*((unsigned short*)pc) = ((((c1 & 0x00FF00)*2 + ((c2 & 0x00FF00) + (c3 & 0x00FF00))*7 ) & 0x000FF000) +
  55.227 +//	              (((c1 & 0xFF00FF)*2 + ((c2 & 0xFF00FF) + (c3 & 0xFF00FF))*7 ) & 0x0FF00FF0)) >> 4;
  55.228 +}
  55.229 +
  55.230 +void Interp5_16(unsigned char *pc, unsigned short c1, unsigned short c2)
  55.231 +{
  55.232 +	*((unsigned short *)pc) = interp_16_11(c1, c2);
  55.233 +}
  55.234 +
  55.235 +bool Diff(unsigned int c1, unsigned int c2)
  55.236 +{
  55.237 +	unsigned int
  55.238 +	    YUV1 = RGBtoYUV(c1),
  55.239 +	    YUV2 = RGBtoYUV(c2);
  55.240 +
  55.241 +	if (YUV1 == YUV2) return false;  // Save some processing power
  55.242 +
  55.243 +#ifdef MMX
  55.244 +	unsigned int retval;
  55.245 +	__asm
  55.246 +	{
  55.247 +		mov eax, 0x7FFFFFFF
  55.248 +		movd mm7, eax; mm7 = ABS_MASK = 0x7FFFFFFF
  55.249 +
  55.250 +		; Copy source colors in first reg
  55.251 +		movd mm0, YUV1
  55.252 +		movd mm1, YUV2
  55.253 +
  55.254 +		mov eax, 0x00FF0000
  55.255 +		movd mm6, eax; mm6 = Ymask = 0x00FF0000
  55.256 +
  55.257 +		; Calculate color Y difference
  55.258 +		movq mm2, mm0
  55.259 +		movq mm3, mm1
  55.260 +		pand mm2, mm6
  55.261 +		pand mm3, mm6
  55.262 +		psubd mm2, mm3
  55.263 +		pand mm2, mm7
  55.264 +
  55.265 +		mov eax, 0x0000FF00
  55.266 +		movd mm6, eax; mm6 = Umask = 0x0000FF00
  55.267 +
  55.268 +		; Calculate color U difference
  55.269 +		movq mm3, mm0
  55.270 +		movq mm4, mm1
  55.271 +		pand mm3, mm6
  55.272 +		pand mm4, mm6
  55.273 +		psubd mm3, mm4
  55.274 +		pand mm3, mm7
  55.275 +
  55.276 +		mov eax, 0x000000FF
  55.277 +		movd mm6, eax; mm6 = Vmask = 0x000000FF
  55.278 +
  55.279 +		; Calculate color V difference
  55.280 +		movq mm4, mm0
  55.281 +		movq mm5, mm1
  55.282 +		pand mm4, mm6
  55.283 +		pand mm5, mm6
  55.284 +		psubd mm4, mm5
  55.285 +		pand mm4, mm7
  55.286 +
  55.287 +		mov eax, 0x00300000
  55.288 +		movd mm5, eax; mm5 = trY = 0x00300000
  55.289 +		                           mov eax, 0x00000700
  55.290 +		movd mm6, eax; mm6 = trU = 0x00000700
  55.291 +		                           mov eax, 0x00000006
  55.292 +		movd mm7, eax; mm7 = trV = 0x00000006
  55.293 +
  55.294 +		; Compare the results
  55.295 +		pcmpgtd mm2, trY
  55.296 +		pcmpgtd mm3, trU
  55.297 +		pcmpgtd mm4, trV
  55.298 +		por mm2, mm3
  55.299 +		por mm2, mm4
  55.300 +
  55.301 +		movd retval, mm2
  55.302 +
  55.303 +		        EMMS
  55.304 +	}
  55.305 +	return (retval != 0);
  55.306 +#else
  55.307 +	return
  55.308 +	    (abs32((YUV1 & Ymask) - (YUV2 & Ymask)) > trY) ||
  55.309 +	    (abs32((YUV1 & Umask) - (YUV2 & Umask)) > trU) ||
  55.310 +	    (abs32((YUV1 & Vmask) - (YUV2 & Vmask)) > trV);
  55.311 +#endif
  55.312 +}
  55.313 +
  55.314 +unsigned int RGBtoYUV(unsigned int c)
  55.315 +{   // Division through 3 slows down the emulation about 10% !!!
  55.316 +#ifdef MMX
  55.317 +	unsigned int retval;
  55.318 +	__asm
  55.319 +	{
  55.320 +		movd mm0, c
  55.321 +		movq mm1, mm0
  55.322 +		movq mm2, mm0; mm0 = mm1 = mm2 = c
  55.323 +
  55.324 +		                                 mov eax, 0x000000FF
  55.325 +		movd mm5, eax; mm5 = REDMASK = 0x000000FF
  55.326 +		                               mov eax, 0x0000FF00
  55.327 +		movd mm6, eax; mm6 = GREENMASK = 0x0000FF00
  55.328 +		                                 mov eax, 0x00FF0000
  55.329 +		movd mm7, eax; mm7 = BLUEMASK = 0x00FF0000
  55.330 +
  55.331 +		                                pand mm0, mm5
  55.332 +		pand mm1, mm6
  55.333 +		pand mm2, mm7; mm0 = R mm1 = G mm2 = B
  55.334 +
  55.335 +		                                     movq mm3, mm0
  55.336 +		paddd mm3, mm1
  55.337 +		paddd mm3, mm2
  55.338 +		;       psrld mm3, 2; mm3 = Y
  55.339 +		;       pslld mm3, 16
  55.340 +		pslld mm3, 14; mm3 = Y << 16
  55.341 +
  55.342 +		                     mov eax, 512
  55.343 +		movd mm7, eax; mm7 = 128 << 2 = 512
  55.344 +
  55.345 +		                                movq mm4, mm0
  55.346 +		psubd mm4, mm2
  55.347 +		;       psrld mm4, 2
  55.348 +		;       paddd mm4, mm7; mm4 = U
  55.349 +		;       pslld mm4, 8; mm4 = U << 8
  55.350 +		                            paddd mm4, mm7
  55.351 +		pslld mm4, 6
  55.352 +
  55.353 +		mov eax, 128
  55.354 +		movd mm7, eax; mm7 = 128
  55.355 +
  55.356 +		                     movq mm5, mm1
  55.357 +		pslld mm5, 1
  55.358 +		psubd mm5, mm0
  55.359 +		psubd mm5, mm2
  55.360 +		psrld mm5, 3
  55.361 +		paddd mm5, mm7; mm5 = V
  55.362 +
  55.363 +		                      paddd mm5, mm4
  55.364 +		paddd mm5, mm3
  55.365 +
  55.366 +		movd retval, mm5
  55.367 +
  55.368 +		EMMS
  55.369 +	}
  55.370 +	return retval;
  55.371 +#else
  55.372 +	unsigned char r, g, b, Y, u, v;
  55.373 +	r = (c & 0x000000FF);
  55.374 +	g = (c & 0x0000FF00) >> 8;
  55.375 +	b = (c & 0x00FF0000) >> 16;
  55.376 +	Y = (r + g + b) >> 2;
  55.377 +	u = 128 + ((r - b) >> 2);
  55.378 +	v = 128 + ((-r + 2 * g - b) >> 3);
  55.379 +	return (Y << 16) + (u << 8) + v;
  55.380 +
  55.381 +	// Extremely High Quality Code
  55.382 +	//unsigned char r, g, b;
  55.383 +	//r = c & 0xFF;
  55.384 +	//g = (c >> 8) & 0xFF;
  55.385 +	//b = (c >> 16) & 0xFF;
  55.386 +	//unsigned char y, u, v;
  55.387 +	//y = (0.256788 * r  +  0.504129 * g  +  0.097906 * b) + 16;
  55.388 +	//u = (-0.148223 * r  -  0.290993 * g  +  0.439216 * b) + 128;
  55.389 +	//v = (0.439216 * r  -  0.367788 * g  -  0.071427 * b) + 128;
  55.390 +	//return (y << 16) + (u << 8) + v;
  55.391 +#endif
  55.392 +}
  55.393 \ No newline at end of file
    56.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    56.2 +++ b/src/filters/hq_shared32.h	Sat Mar 03 10:31:27 2012 -0600
    56.3 @@ -0,0 +1,31 @@
    56.4 +#ifndef VBA_HQ_SHARED32_H
    56.5 +#define VBA_HQ_SHARED32_H
    56.6 +
    56.7 +#if _MSC_VER > 1000
    56.8 +#pragma once
    56.9 +#endif // _MSC_VER > 1000
   56.10 +
   56.11 +#define abs32(value) (value & 0x7FFFFFFF)
   56.12 +#define abs16(value) (value & 0x7FFF)
   56.13 +
   56.14 +const int Ymask = 0x00FF0000;
   56.15 +const int Umask = 0x0000FF00;
   56.16 +const int Vmask = 0x000000FF;
   56.17 +const int trY   = 0x00300000;
   56.18 +const int trU   = 0x00000700;
   56.19 +const int trV   = 0x00000006;
   56.20 +
   56.21 +void Interp1(unsigned char *pc, unsigned int c1, unsigned int c2);
   56.22 +void Interp2(unsigned char *pc, unsigned int c1, unsigned int c2, unsigned int c3);
   56.23 +void Interp3(unsigned char *pc, unsigned int c1, unsigned int c2);
   56.24 +void Interp4(unsigned char *pc, unsigned int c1, unsigned int c2, unsigned int c3);
   56.25 +void Interp5(unsigned char *pc, unsigned int c1, unsigned int c2);
   56.26 +void Interp1_16(unsigned char *pc, unsigned short c1, unsigned short c2);
   56.27 +void Interp2_16(unsigned char *pc, unsigned short c1, unsigned short c2, unsigned short c3);
   56.28 +void Interp3_16(unsigned char *pc, unsigned short c1, unsigned short c2);
   56.29 +void Interp4_16(unsigned char *pc, unsigned short c1, unsigned short c2, unsigned short c3);
   56.30 +void Interp5_16(unsigned char *pc, unsigned short c1, unsigned short c2);
   56.31 +bool Diff(unsigned int c1, unsigned int c2);
   56.32 +unsigned int RGBtoYUV(unsigned int c);
   56.33 +
   56.34 +#endif // VBA_HQ_SHARED32_H
    57.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.2 +++ b/src/filters/interframe.cpp	Sat Mar 03 10:31:27 2012 -0600
    57.3 @@ -0,0 +1,630 @@
    57.4 +#include <cstdlib>
    57.5 +#include <cstring>
    57.6 +#include "../Port.h"
    57.7 +
    57.8 +#ifdef MMX
    57.9 +extern "C" bool cpu_mmx;
   57.10 +#endif
   57.11 +
   57.12 +/*
   57.13 + * Thanks to Kawaks' Mr. K for the code
   57.14 +
   57.15 +   Incorporated into vba by Anthony Di Franco
   57.16 + */
   57.17 +
   57.18 +static u8 *frm1 = NULL;
   57.19 +static u8 *frm2 = NULL;
   57.20 +static u8 *frm3 = NULL;
   57.21 +
   57.22 +extern u32 RGB_LOW_BITS_MASK;
   57.23 +extern u32 qRGB_COLOR_MASK[2];
   57.24 +
   57.25 +static void Init()
   57.26 +{
   57.27 +	frm1 = (u8 *)calloc(322 * 242, 4);
   57.28 +	// 1 frame ago
   57.29 +	frm2 = (u8 *)calloc(322 * 242, 4);
   57.30 +	// 2 frames ago
   57.31 +	frm3 = (u8 *)calloc(322 * 242, 4);
   57.32 +	// 3 frames ago
   57.33 +}
   57.34 +
   57.35 +void InterframeCleanup()
   57.36 +{
   57.37 +	if (frm1)
   57.38 +		free(frm1);
   57.39 +	if (frm2)
   57.40 +		free(frm2);
   57.41 +	if (frm3)
   57.42 +		free(frm3);
   57.43 +	frm1 = frm2 = frm3 = NULL;
   57.44 +}
   57.45 +
   57.46 +#ifdef MMX
   57.47 +static void SmartIB_MMX(u8 *srcPtr, u32 srcPitch, int width, int height)
   57.48 +{
   57.49 +	u16 *src0 = (u16 *)srcPtr;
   57.50 +	u16 *src1 = (u16 *)frm1;
   57.51 +	u16 *src2 = (u16 *)frm2;
   57.52 +	u16 *src3 = (u16 *)frm3;
   57.53 +
   57.54 +	int count = width >> 2;
   57.55 +
   57.56 +	for (int i = 0; i < height; i++)
   57.57 +	{
   57.58 +#ifdef __GNUC__
   57.59 +		asm volatile (
   57.60 +		    "push %4\n"
   57.61 +		    "movq 0(%5), %%mm7\n"       // colorMask
   57.62 +		    "0:\n"
   57.63 +		    "movq 0(%0), %%mm0\n"       // src0
   57.64 +		    "movq 0(%1), %%mm1\n"       // src1
   57.65 +		    "movq 0(%2), %%mm2\n"       // src2
   57.66 +		    "movq 0(%3), %%mm3\n"       // src3
   57.67 +		    "movq %%mm0, 0(%3)\n"       // src3 = src0
   57.68 +		    "movq %%mm0, %%mm4\n"
   57.69 +		    "movq %%mm1, %%mm5\n"
   57.70 +		    "pcmpeqw %%mm2, %%mm5\n"       // src1 == src2 (A)
   57.71 +		    "pcmpeqw %%mm3, %%mm4\n"       // src3 == src0 (B)
   57.72 +		    "por %%mm5, %%mm4\n"       // A | B
   57.73 +		    "movq %%mm2, %%mm5\n"
   57.74 +		    "pcmpeqw %%mm0, %%mm5\n"       // src0 == src2 (C)
   57.75 +		    "pcmpeqw %%mm1, %%mm3\n"       // src1 == src3 (D)
   57.76 +		    "por %%mm3, %%mm5\n"       // C|D
   57.77 +		    "pandn %%mm5, %%mm4\n"       // (!(A|B))&(C|D)
   57.78 +		    "movq %%mm0, %%mm2\n"
   57.79 +		    "pand %%mm7, %%mm2\n"       // color & colorMask
   57.80 +		    "pand %%mm7, %%mm1\n"       // src1 & colorMask
   57.81 +		    "psrlw $1, %%mm2\n"       // (color & colorMask) >> 1 (E)
   57.82 +		    "psrlw $1, %%mm1\n"       // (src & colorMask) >> 1 (F)
   57.83 +		    "paddw %%mm2, %%mm1\n"       // E+F
   57.84 +		    "pand %%mm4, %%mm1\n"       // (E+F) & res
   57.85 +		    "pandn %%mm0, %%mm4\n"       // color& !res
   57.86 +
   57.87 +		    "por %%mm1, %%mm4\n"
   57.88 +		    "movq %%mm4, 0(%0)\n"       // src0 = res
   57.89 +
   57.90 +		    "addl $8, %0\n"
   57.91 +		    "addl $8, %1\n"
   57.92 +		    "addl $8, %2\n"
   57.93 +		    "addl $8, %3\n"
   57.94 +
   57.95 +		    "decl %4\n"
   57.96 +		    "jnz 0b\n"
   57.97 +		    "pop %4\n"
   57.98 +		    "emms\n"
   57.99 +			: "+r" (src0), "+r" (src1), "+r" (src2), "+r" (src3)
  57.100 +			: "r" (count), "r" (qRGB_COLOR_MASK)
  57.101 +		    );
  57.102 +#else
  57.103 +		__asm {
  57.104 +			movq mm7, qword ptr [qRGB_COLOR_MASK];
  57.105 +			mov	 eax, src0;
  57.106 +			mov	 ebx, src1;
  57.107 +			mov	 ecx, src2;
  57.108 +			mov	 edx, src3;
  57.109 +			mov	 edi, count;
  57.110 +label0:
  57.111 +			movq mm0, qword ptr [eax]; // src0
  57.112 +			movq	   mm1, qword ptr [ebx]; // src1
  57.113 +			movq	   mm2, qword ptr [ecx]; // src2
  57.114 +			movq	   mm3, qword ptr [edx]; // src3
  57.115 +			movq qword ptr [edx], mm0; // src3 = src0
  57.116 +			movq	   mm4, mm0;
  57.117 +			movq	   mm5, mm1;
  57.118 +			pcmpeqw	   mm5, mm2; // src1 == src2 (A)
  57.119 +			pcmpeqw	   mm4, mm3; // src3 == src0 (B)
  57.120 +			por		   mm4, mm5; // A | B
  57.121 +			movq	   mm5, mm2;
  57.122 +			pcmpeqw	   mm5, mm0; // src0 == src2 (C)
  57.123 +			pcmpeqw	   mm3, mm1; // src1 == src3 (D)
  57.124 +			por		   mm5, mm3; // C|D
  57.125 +			pandn	   mm4, mm5; // (!(A|B))&(C|D)
  57.126 +			movq	   mm2, mm0;
  57.127 +			pand	   mm2, mm7; // color & colorMask
  57.128 +			pand	   mm1, mm7; // src1 & colorMask
  57.129 +			psrlw	   mm2, 1; // (color & colorMask) >> 1 (E)
  57.130 +			psrlw	   mm1, 1; // (src & colorMask) >> 1 (F)
  57.131 +			paddw	   mm1, mm2; // E+F
  57.132 +			pand	   mm1, mm4; // (E+F) & res
  57.133 +			pandn	   mm4, mm0; // color & !res
  57.134 +
  57.135 +			por		   mm4, mm1;
  57.136 +			movq qword ptr [eax], mm4; // src0 = res
  57.137 +
  57.138 +			add eax, 8;
  57.139 +			add ebx, 8;
  57.140 +			add ecx, 8;
  57.141 +			add edx, 8;
  57.142 +
  57.143 +			dec edi;
  57.144 +			jnz label0;
  57.145 +			mov src0, eax;
  57.146 +			mov src1, ebx;
  57.147 +			mov src2, ecx;
  57.148 +			mov src3, edx;
  57.149 +			emms;
  57.150 +		}
  57.151 +#endif
  57.152 +		src0 += 2;
  57.153 +		src1 += 2;
  57.154 +		src2 += 2;
  57.155 +		src3 += 2;
  57.156 +	}
  57.157 +
  57.158 +	/* Swap buffers around */
  57.159 +	u8 *temp = frm1;
  57.160 +	frm1 = frm3;
  57.161 +	frm3 = frm2;
  57.162 +	frm2 = temp;
  57.163 +}
  57.164 +
  57.165 +#endif
  57.166 +
  57.167 +void SmartIB(u8 *srcPtr, u32 srcPitch, int width, int height)
  57.168 +{
  57.169 +	if (frm1 == NULL)
  57.170 +	{
  57.171 +		Init();
  57.172 +	}
  57.173 +#ifdef MMX
  57.174 +	if (cpu_mmx)
  57.175 +	{
  57.176 +		SmartIB_MMX(srcPtr, srcPitch, width, height);
  57.177 +		return;
  57.178 +	}
  57.179 +#endif
  57.180 +
  57.181 +	u16 colorMask = ~RGB_LOW_BITS_MASK;
  57.182 +
  57.183 +	u16 *src0 = (u16 *)srcPtr;
  57.184 +	u16 *src1 = (u16 *)frm1;
  57.185 +	u16 *src2 = (u16 *)frm2;
  57.186 +	u16 *src3 = (u16 *)frm3;
  57.187 +
  57.188 +	int sPitch = srcPitch >> 1;
  57.189 +
  57.190 +	int pos = 0;
  57.191 +	for (int j = 0; j < height; j++)
  57.192 +		for (int i = 0; i < sPitch; i++)
  57.193 +		{
  57.194 +			u16 color = src0[pos];
  57.195 +			src0[pos] =
  57.196 +			    (src1[pos] != src2[pos]) &&
  57.197 +			    (src3[pos] != color) &&
  57.198 +			    ((color == src2[pos]) || (src1[pos] == src3[pos]))
  57.199 +			    ? (((color & colorMask) >> 1) + ((src1[pos] & colorMask) >> 1)) :
  57.200 +			    color;
  57.201 +			src3[pos] = color; /* oldest buffer now holds newest frame */
  57.202 +			pos++;
  57.203 +		}
  57.204 +
  57.205 +	/* Swap buffers around */
  57.206 +	u8 *temp = frm1;
  57.207 +	frm1 = frm3;
  57.208 +	frm3 = frm2;
  57.209 +	frm2 = temp;
  57.210 +}
  57.211 +
  57.212 +#ifdef MMX
  57.213 +static void SmartIB32_MMX(u8 *srcPtr, u32 srcPitch, int width, int height)
  57.214 +{
  57.215 +	u32 *src0 = (u32 *)srcPtr;
  57.216 +	u32 *src1 = (u32 *)frm1;
  57.217 +	u32 *src2 = (u32 *)frm2;
  57.218 +	u32 *src3 = (u32 *)frm3;
  57.219 +
  57.220 +	int count = width >> 1;
  57.221 +
  57.222 +	for (int i = 0; i < height; i++)
  57.223 +	{
  57.224 +#ifdef __GNUC__
  57.225 +		asm volatile (
  57.226 +		    "push %4\n"
  57.227 +		    "movq 0(%5), %%mm7\n"       // colorMask
  57.228 +		    "0:\n"
  57.229 +		    "movq 0(%0), %%mm0\n"       // src0
  57.230 +		    "movq 0(%1), %%mm1\n"       // src1
  57.231 +		    "movq 0(%2), %%mm2\n"       // src2
  57.232 +		    "movq 0(%3), %%mm3\n"       // src3
  57.233 +		    "movq %%mm0, 0(%3)\n"       // src3 = src0
  57.234 +		    "movq %%mm0, %%mm4\n"
  57.235 +		    "movq %%mm1, %%mm5\n"
  57.236 +		    "pcmpeqd %%mm2, %%mm5\n"       // src1 == src2 (A)
  57.237 +		    "pcmpeqd %%mm3, %%mm4\n"       // src3 == src0 (B)
  57.238 +		    "por %%mm5, %%mm4\n"       // A | B
  57.239 +		    "movq %%mm2, %%mm5\n"
  57.240 +		    "pcmpeqd %%mm0, %%mm5\n"       // src0 == src2 (C)
  57.241 +		    "pcmpeqd %%mm1, %%mm3\n"       // src1 == src3 (D)
  57.242 +		    "por %%mm3, %%mm5\n"       // C|D
  57.243 +		    "pandn %%mm5, %%mm4\n"       // (!(A|B))&(C|D)
  57.244 +		    "movq %%mm0, %%mm2\n"
  57.245 +		    "pand %%mm7, %%mm2\n"       // color & colorMask
  57.246 +		    "pand %%mm7, %%mm1\n"       // src1 & colorMask
  57.247 +		    "psrld $1, %%mm2\n"       // (color & colorMask) >> 1 (E)
  57.248 +		    "psrld $1, %%mm1\n"       // (src & colorMask) >> 1 (F)
  57.249 +		    "paddd %%mm2, %%mm1\n"       // E+F
  57.250 +		    "pand %%mm4, %%mm1\n"       // (E+F) & res
  57.251 +		    "pandn %%mm0, %%mm4\n"       // color& !res
  57.252 +
  57.253 +		    "por %%mm1, %%mm4\n"
  57.254 +		    "movq %%mm4, 0(%0)\n"       // src0 = res
  57.255 +
  57.256 +		    "addl $8, %0\n"
  57.257 +		    "addl $8, %1\n"
  57.258 +		    "addl $8, %2\n"
  57.259 +		    "addl $8, %3\n"
  57.260 +
  57.261 +		    "decl %4\n"
  57.262 +		    "jnz 0b\n"
  57.263 +		    "pop %4\n"
  57.264 +		    "emms\n"
  57.265 +			: "+r" (src0), "+r" (src1), "+r" (src2), "+r" (src3)
  57.266 +			: "r" (count), "r" (qRGB_COLOR_MASK)
  57.267 +		    );
  57.268 +#else
  57.269 +		__asm {
  57.270 +			movq mm7, qword ptr [qRGB_COLOR_MASK];
  57.271 +			mov	 eax, src0;
  57.272 +			mov	 ebx, src1;
  57.273 +			mov	 ecx, src2;
  57.274 +			mov	 edx, src3;
  57.275 +			mov	 edi, count;
  57.276 +label0:
  57.277 +			movq mm0, qword ptr [eax]; // src0
  57.278 +			movq	   mm1, qword ptr [ebx]; // src1
  57.279 +			movq	   mm2, qword ptr [ecx]; // src2
  57.280 +			movq	   mm3, qword ptr [edx]; // src3
  57.281 +			movq qword ptr [edx], mm0; // src3 = src0
  57.282 +			movq	   mm4, mm0;
  57.283 +			movq	   mm5, mm1;
  57.284 +			pcmpeqd	   mm5, mm2; // src1 == src2 (A)
  57.285 +			pcmpeqd	   mm4, mm3; // src3 == src0 (B)
  57.286 +			por		   mm4, mm5; // A | B
  57.287 +			movq	   mm5, mm2;
  57.288 +			pcmpeqd	   mm5, mm0; // src0 == src2 (C)
  57.289 +			pcmpeqd	   mm3, mm1; // src1 == src3 (D)
  57.290 +			por		   mm5, mm3; // C|D
  57.291 +			pandn	   mm4, mm5; // (!(A|B))&(C|D)
  57.292 +			movq	   mm2, mm0;
  57.293 +			pand	   mm2, mm7; // color & colorMask
  57.294 +			pand	   mm1, mm7; // src1 & colorMask
  57.295 +			psrld	   mm2, 1; // (color & colorMask) >> 1 (E)
  57.296 +			psrld	   mm1, 1; // (src & colorMask) >> 1 (F)
  57.297 +			paddd	   mm1, mm2; // E+F
  57.298 +			pand	   mm1, mm4; // (E+F) & res
  57.299 +			pandn	   mm4, mm0; // color & !res
  57.300 +
  57.301 +			por		   mm4, mm1;
  57.302 +			movq qword ptr [eax], mm4; // src0 = res
  57.303 +
  57.304 +			add eax, 8;
  57.305 +			add ebx, 8;
  57.306 +			add ecx, 8;
  57.307 +			add edx, 8;
  57.308 +
  57.309 +			dec edi;
  57.310 +			jnz label0;
  57.311 +			mov src0, eax;
  57.312 +			mov src1, ebx;
  57.313 +			mov src2, ecx;
  57.314 +			mov src3, edx;
  57.315 +			emms;
  57.316 +		}
  57.317 +#endif
  57.318 +
  57.319 +		src0++;
  57.320 +		src1++;
  57.321 +		src2++;
  57.322 +		src3++;
  57.323 +	}
  57.324 +	/* Swap buffers around */
  57.325 +	u8 *temp = frm1;
  57.326 +	frm1 = frm3;
  57.327 +	frm3 = frm2;
  57.328 +	frm2 = temp;
  57.329 +}
  57.330 +
  57.331 +#endif
  57.332 +
  57.333 +void SmartIB32(u8 *srcPtr, u32 srcPitch, int width, int height)
  57.334 +{
  57.335 +	if (frm1 == NULL)
  57.336 +	{
  57.337 +		Init();
  57.338 +	}
  57.339 +#ifdef MMX
  57.340 +	if (cpu_mmx)
  57.341 +	{
  57.342 +		SmartIB32_MMX(srcPtr, srcPitch, width, height);
  57.343 +		return;
  57.344 +	}
  57.345 +#endif
  57.346 +
  57.347 +	u32 *src0 = (u32 *)srcPtr;
  57.348 +	u32 *src1 = (u32 *)frm1;
  57.349 +	u32 *src2 = (u32 *)frm2;
  57.350 +	u32 *src3 = (u32 *)frm3;
  57.351 +
  57.352 +	u32 colorMask = 0xfefefe;
  57.353 +
  57.354 +	int sPitch = srcPitch >> 2;
  57.355 +	int pos	   = 0;
  57.356 +
  57.357 +	for (int j = 0; j < height; j++)
  57.358 +		for (int i = 0; i < sPitch; i++)
  57.359 +		{
  57.360 +			u32 color = src0[pos];
  57.361 +			src0[pos] =
  57.362 +			    (src1[pos] != src2[pos]) &&
  57.363 +			    (src3[pos] != color) &&
  57.364 +			    ((color == src2[pos]) || (src1[pos] == src3[pos]))
  57.365 +			    ? (((color & colorMask) >> 1) + ((src1[pos] & colorMask) >> 1)) :
  57.366 +			    color;
  57.367 +			src3[pos] = color; /* oldest buffer now holds newest frame */
  57.368 +			pos++;
  57.369 +		}
  57.370 +
  57.371 +	/* Swap buffers around */
  57.372 +	u8 *temp = frm1;
  57.373 +	frm1 = frm3;
  57.374 +	frm3 = frm2;
  57.375 +	frm2 = temp;
  57.376 +}
  57.377 +
  57.378 +#ifdef MMX
  57.379 +static void MotionBlurIB_MMX(u8 *srcPtr, u32 srcPitch, int width, int height)
  57.380 +{
  57.381 +	u16 *src0 = (u16 *)srcPtr;
  57.382 +	u16 *src1 = (u16 *)frm1;
  57.383 +
  57.384 +	int count = width >> 2;
  57.385 +
  57.386 +	for (int i = 0; i < height; i++)
  57.387 +	{
  57.388 +#ifdef __GNUC__
  57.389 +		asm volatile (
  57.390 +		    "push %2\n"
  57.391 +		    "movq 0(%3), %%mm7\n"       // colorMask
  57.392 +		    "0:\n"
  57.393 +		    "movq 0(%0), %%mm0\n"       // src0
  57.394 +		    "movq 0(%1), %%mm1\n"       // src1
  57.395 +		    "movq %%mm0, 0(%1)\n"       // src1 = src0
  57.396 +		    "pand %%mm7, %%mm0\n"       // color & colorMask
  57.397 +		    "pand %%mm7, %%mm1\n"       // src1 & colorMask
  57.398 +		    "psrlw $1, %%mm0\n"       // (color & colorMask) >> 1 (E)
  57.399 +		    "psrlw $1, %%mm1\n"       // (src & colorMask) >> 1 (F)
  57.400 +		    "paddw %%mm1, %%mm0\n"       // E+F
  57.401 +
  57.402 +		    "movq %%mm0, 0(%0)\n"       // src0 = res
  57.403 +
  57.404 +		    "addl $8, %0\n"
  57.405 +		    "addl $8, %1\n"
  57.406 +
  57.407 +		    "decl %2\n"
  57.408 +		    "jnz 0b\n"
  57.409 +		    "pop %2\n"
  57.410 +		    "emms\n"
  57.411 +			: "+r" (src0), "+r" (src1)
  57.412 +			: "r" (count), "r" (qRGB_COLOR_MASK)
  57.413 +		    );
  57.414 +#else
  57.415 +		__asm {
  57.416 +			movq mm7, qword ptr [qRGB_COLOR_MASK];
  57.417 +			mov	 eax, src0;
  57.418 +			mov	 ebx, src1;
  57.419 +			mov	 edi, count;
  57.420 +label0:
  57.421 +			movq mm0, qword ptr [eax]; // src0
  57.422 +			movq	   mm1, qword ptr [ebx]; // src1
  57.423 +			movq qword ptr [ebx], mm0; // src1 = src0
  57.424 +			pand	   mm0, mm7; // color & colorMask
  57.425 +			pand	   mm1, mm7; // src1 & colorMask
  57.426 +			psrlw	   mm0, 1; // (color & colorMask) >> 1 (E)
  57.427 +			psrlw	   mm1, 1; // (src & colorMask) >> 1 (F)
  57.428 +			paddw	   mm0, mm1; // E+F
  57.429 +
  57.430 +			movq qword ptr [eax], mm0; // src0 = res
  57.431 +
  57.432 +			add eax, 8;
  57.433 +			add ebx, 8;
  57.434 +
  57.435 +			dec edi;
  57.436 +			jnz label0;
  57.437 +			mov src0, eax;
  57.438 +			mov src1, ebx;
  57.439 +			emms;
  57.440 +		}
  57.441 +#endif
  57.442 +		src0 += 2;
  57.443 +		src1 += 2;
  57.444 +	}
  57.445 +}
  57.446 +
  57.447 +#endif
  57.448 +
  57.449 +void MotionBlurIB(u8 *srcPtr, u32 srcPitch, int width, int height)
  57.450 +{
  57.451 +	if (frm1 == NULL)
  57.452 +	{
  57.453 +		Init();
  57.454 +	}
  57.455 +
  57.456 +#ifdef MMX
  57.457 +	if (cpu_mmx)
  57.458 +	{
  57.459 +		MotionBlurIB_MMX(srcPtr, srcPitch, width, height);
  57.460 +		return;
  57.461 +	}
  57.462 +#endif
  57.463 +
  57.464 +	u16 colorMask = ~RGB_LOW_BITS_MASK;
  57.465 +
  57.466 +	u16 *src0 = (u16 *)srcPtr;
  57.467 +	u16 *src1 = (u16 *)frm1;
  57.468 +
  57.469 +	int sPitch = srcPitch >> 1;
  57.470 +
  57.471 +	int pos = 0;
  57.472 +	for (int j = 0; j < height; j++)
  57.473 +		for (int i = 0; i < sPitch; i++)
  57.474 +		{
  57.475 +			u16 color = src0[pos];
  57.476 +			src0[pos] =
  57.477 +			    (((color & colorMask) >> 1) + ((src1[pos] & colorMask) >> 1));
  57.478 +			src1[pos] = color;
  57.479 +			pos++;
  57.480 +		}
  57.481 +}
  57.482 +
  57.483 +#ifdef MMX
  57.484 +static void MotionBlurIB32_MMX(u8 *srcPtr, u32 srcPitch, int width, int height)
  57.485 +{
  57.486 +	u32 *src0 = (u32 *)srcPtr;
  57.487 +	u32 *src1 = (u32 *)frm1;
  57.488 +
  57.489 +	int count = width >> 1;
  57.490 +
  57.491 +	for (int i = 0; i < height; i++)
  57.492 +	{
  57.493 +#ifdef __GNUC__
  57.494 +		asm volatile (
  57.495 +		    "push %2\n"
  57.496 +		    "movq 0(%3), %%mm7\n"       // colorMask
  57.497 +		    "0:\n"
  57.498 +		    "movq 0(%0), %%mm0\n"       // src0
  57.499 +		    "movq 0(%1), %%mm1\n"       // src1
  57.500 +		    "movq %%mm0, 0(%1)\n"       // src1 = src0
  57.501 +		    "pand %%mm7, %%mm0\n"       // color & colorMask
  57.502 +		    "pand %%mm7, %%mm1\n"       // src1 & colorMask
  57.503 +		    "psrld $1, %%mm0\n"       // (color & colorMask) >> 1 (E)
  57.504 +		    "psrld $1, %%mm1\n"       // (src & colorMask) >> 1 (F)
  57.505 +		    "paddd %%mm1, %%mm0\n"       // E+F
  57.506 +
  57.507 +		    "movq %%mm0, 0(%0)\n"       // src0 = res
  57.508 +
  57.509 +		    "addl $8, %0\n"
  57.510 +		    "addl $8, %1\n"
  57.511 +
  57.512 +		    "decl %2\n"
  57.513 +		    "jnz 0b\n"
  57.514 +		    "pop %2\n"
  57.515 +		    "emms\n"
  57.516 +			: "+r" (src0), "+r" (src1)
  57.517 +			: "r" (count), "r" (qRGB_COLOR_MASK)
  57.518 +		    );
  57.519 +#else
  57.520 +		__asm {
  57.521 +			movq mm7, qword ptr [qRGB_COLOR_MASK];
  57.522 +			mov	 eax, src0;
  57.523 +			mov	 ebx, src1;
  57.524 +			mov	 edi, count;
  57.525 +label0:
  57.526 +			movq mm0, qword ptr [eax]; // src0
  57.527 +			movq	   mm1, qword ptr [ebx]; // src1
  57.528 +			movq qword ptr [ebx], mm0; // src1 = src0
  57.529 +			pand	   mm0, mm7; // color & colorMask
  57.530 +			pand	   mm1, mm7; // src1 & colorMask
  57.531 +			psrld	   mm0, 1; // (color & colorMask) >> 1 (E)
  57.532 +			psrld	   mm1, 1; // (src & colorMask) >> 1 (F)
  57.533 +			paddd	   mm0, mm1; // E+F
  57.534 +
  57.535 +			movq qword ptr [eax], mm0; // src0 = res
  57.536 +
  57.537 +			add eax, 8;
  57.538 +			add ebx, 8;
  57.539 +
  57.540 +			dec edi;
  57.541 +			jnz label0;
  57.542 +			mov src0, eax;
  57.543 +			mov src1, ebx;
  57.544 +			emms;
  57.545 +		}
  57.546 +#endif
  57.547 +		src0++;
  57.548 +		src1++;
  57.549 +	}
  57.550 +}
  57.551 +
  57.552 +#endif
  57.553 +
  57.554 +void MotionBlurIB32(u8 *srcPtr, u32 srcPitch, int width, int height)
  57.555 +{
  57.556 +	if (frm1 == NULL)
  57.557 +	{
  57.558 +		Init();
  57.559 +	}
  57.560 +
  57.561 +#ifdef MMX
  57.562 +	if (cpu_mmx)
  57.563 +	{
  57.564 +		MotionBlurIB32_MMX(srcPtr, srcPitch, width, height);
  57.565 +		return;
  57.566 +	}
  57.567 +#endif
  57.568 +
  57.569 +	u32 *src0 = (u32 *)srcPtr;
  57.570 +	u32 *src1 = (u32 *)frm1;
  57.571 +
  57.572 +	u32 colorMask = 0xfefefe;
  57.573 +
  57.574 +	int sPitch = srcPitch >> 2;
  57.575 +	int pos	   = 0;
  57.576 +
  57.577 +	for (int j = 0; j < height; j++)
  57.578 +		for (int i = 0; i < sPitch; i++)
  57.579 +		{
  57.580 +			u32 color = src0[pos];
  57.581 +			src0[pos] = (((color & colorMask) >> 1) +
  57.582 +			             ((src1[pos] & colorMask) >> 1));
  57.583 +			src1[pos] = color;
  57.584 +			pos++;
  57.585 +		}
  57.586 +}
  57.587 +
  57.588 +static int count = 0;
  57.589 +
  57.590 +void InterlaceIB(u8 *srcPtr, u32 srcPitch, int width, int height)
  57.591 +{
  57.592 +	if (frm1 == NULL)
  57.593 +	{
  57.594 +		Init();
  57.595 +	}
  57.596 +
  57.597 +	u16 colorMask = ~RGB_LOW_BITS_MASK;
  57.598 +
  57.599 +	u16 *src0 = (u16 *)srcPtr;
  57.600 +	u16 *src1 = (u16 *)frm1;
  57.601 +
  57.602 +	int sPitch = srcPitch >> 1;
  57.603 +
  57.604 +	int pos = 0;
  57.605 +	for (int j = 0; j < height; j++)
  57.606 +	{
  57.607 +		bool render = count ? (j & 1) != 0 : (j & 1) == 0;
  57.608 +		if (render)
  57.609 +		{
  57.610 +			for (int i = 0; i < sPitch; i++)
  57.611 +			{
  57.612 +				u16 color = src0[pos];
  57.613 +				src0[pos] =
  57.614 +				    (((color & colorMask) >> 1) + ((((src1[pos] & colorMask) >> 1) & colorMask) >> 1));
  57.615 +				src1[pos] = color;
  57.616 +				pos++;
  57.617 +			}
  57.618 +		}
  57.619 +		else
  57.620 +		{
  57.621 +			for (int i = 0; i < sPitch; i++)
  57.622 +			{
  57.623 +				u16 color = src0[pos];
  57.624 +				src0[pos] =
  57.625 +				    (((((color & colorMask) >> 1) & colorMask) >> 1) + ((src1[pos] & colorMask) >> 1));
  57.626 +				src1[pos] = color;
  57.627 +				pos++;
  57.628 +			}
  57.629 +		}
  57.630 +	}
  57.631 +	count = count ^ 1;
  57.632 +}
  57.633 +
    58.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    58.2 +++ b/src/filters/interp.h	Sat Mar 03 10:31:27 2012 -0600
    58.3 @@ -0,0 +1,351 @@
    58.4 +/*
    58.5 + * This file is part of the Advance project.
    58.6 + *
    58.7 + * Copyright (C) 2003 Andrea Mazzoleni
    58.8 + *
    58.9 + * This program is free software; you can redistribute it and/or modify
   58.10 + * it under the terms of the GNU General Public License as published by
   58.11 + * the Free Software Foundation; either version 2 of the License, or
   58.12 + * (at your option) any later version.
   58.13 + *
   58.14 + * This program is distributed in the hope that it will be useful,
   58.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   58.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   58.17 + * GNU General Public License for more details.
   58.18 + *
   58.19 + * You should have received a copy of the GNU General Public License
   58.20 + * along with this program; if not, write to the Free Software
   58.21 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   58.22 + *
   58.23 + * In addition, as a special exception, Andrea Mazzoleni
   58.24 + * gives permission to link the code of this program with
   58.25 + * the MAME library (or with modified versions of MAME that use the
   58.26 + * same license as MAME), and distribute linked combinations including
   58.27 + * the two.  You must obey the GNU General Public License in all
   58.28 + * respects for all of the code used other than MAME.  If you modify
   58.29 + * this file, you may extend this exception to your version of the
   58.30 + * file, but you are not obligated to do so.  If you do not wish to
   58.31 + * do so, delete this exception statement from your version.
   58.32 + */
   58.33 +
   58.34 +#ifndef __INTERP_H
   58.35 +#define __INTERP_H
   58.36 +
   58.37 +/***************************************************************************/
   58.38 +/* Basic types */
   58.39 +
   58.40 +/***************************************************************************/
   58.41 +/* interpolation */
   58.42 +
   58.43 +extern unsigned interp_mask[2];
   58.44 +extern unsigned interp_bits_per_pixel;
   58.45 +
   58.46 +#define INTERP_16_MASK_1(v) (v & interp_mask[0])
   58.47 +#define INTERP_16_MASK_2(v) (v & interp_mask[1])
   58.48 +
   58.49 +static inline u16 interp_16_521(u16 p1, u16 p2, u16 p3)
   58.50 +{
   58.51 +  return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*5 + INTERP_16_MASK_1(p2)*2 + INTERP_16_MASK_1(p3)*1) / 8)
   58.52 +    | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*5 + INTERP_16_MASK_2(p2)*2 + INTERP_16_MASK_2(p3)*1) / 8);
   58.53 +}
   58.54 +
   58.55 +static inline u16 interp_16_332(u16 p1, u16 p2, u16 p3)
   58.56 +{
   58.57 +  return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*3 + INTERP_16_MASK_1(p2)*3 + INTERP_16_MASK_1(p3)*2) / 8)
   58.58 +    | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*3 + INTERP_16_MASK_2(p2)*3 + INTERP_16_MASK_2(p3)*2) / 8);
   58.59 +}
   58.60 +
   58.61 +static inline u16 interp_16_611(u16 p1, u16 p2, u16 p3)
   58.62 +{
   58.63 +  return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*6 + INTERP_16_MASK_1(p2) + INTERP_16_MASK_1(p3)) / 8)
   58.64 +    | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*6 + INTERP_16_MASK_2(p2) + INTERP_16_MASK_2(p3)) / 8);
   58.65 +}
   58.66 +
   58.67 +static inline u16 interp_16_71(u16 p1, u16 p2)
   58.68 +{
   58.69 +  return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*7 + INTERP_16_MASK_1(p2)) / 8)
   58.70 +    | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*7 + INTERP_16_MASK_2(p2)) / 8);
   58.71 +}
   58.72 +
   58.73 +static inline u16 interp_16_211(u16 p1, u16 p2, u16 p3)
   58.74 +{
   58.75 +  return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*2 + INTERP_16_MASK_1(p2) + INTERP_16_MASK_1(p3)) / 4)
   58.76 +    | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*2 + INTERP_16_MASK_2(p2) + INTERP_16_MASK_2(p3)) / 4);
   58.77 +}
   58.78 +
   58.79 +static inline u16 interp_16_772(u16 p1, u16 p2, u16 p3)
   58.80 +{
   58.81 +  return INTERP_16_MASK_1(((INTERP_16_MASK_1(p1) + INTERP_16_MASK_1(p2))*7 + INTERP_16_MASK_1(p3)*2) / 16)
   58.82 +    | INTERP_16_MASK_2(((INTERP_16_MASK_2(p1) + INTERP_16_MASK_2(p2))*7 + INTERP_16_MASK_2(p3)*2) / 16);
   58.83 +}
   58.84 +
   58.85 +static inline u16 interp_16_11(u16 p1, u16 p2)
   58.86 +{
   58.87 +  return INTERP_16_MASK_1((INTERP_16_MASK_1(p1) + INTERP_16_MASK_1(p2)) / 2)
   58.88 +    | INTERP_16_MASK_2((INTERP_16_MASK_2(p1) + INTERP_16_MASK_2(p2)) / 2);
   58.89 +}
   58.90 +
   58.91 +static inline u16 interp_16_31(u16 p1, u16 p2)
   58.92 +{
   58.93 +  return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*3 + INTERP_16_MASK_1(p2)) / 4)
   58.94 +    | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*3 + INTERP_16_MASK_2(p2)) / 4);
   58.95 +}
   58.96 +
   58.97 +static inline u16 interp_16_1411(u16 p1, u16 p2, u16 p3)
   58.98 +{
   58.99 +  return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*14 + INTERP_16_MASK_1(p2) + INTERP_16_MASK_1(p3)) / 16)
  58.100 +    | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*14 + INTERP_16_MASK_2(p2) + INTERP_16_MASK_2(p3)) / 16);
  58.101 +}
  58.102 +
  58.103 +static inline u16 interp_16_431(u16 p1, u16 p2, u16 p3)
  58.104 +{
  58.105 +  return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*4 + INTERP_16_MASK_1(p2)*3 + INTERP_16_MASK_1(p3)) / 8)
  58.106 +    | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*4 + INTERP_16_MASK_2(p2)*3 + INTERP_16_MASK_2(p3)) / 8);
  58.107 +}
  58.108 +
  58.109 +static inline u16 interp_16_53(u16 p1, u16 p2)
  58.110 +{
  58.111 +  return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*5 + INTERP_16_MASK_1(p2)*3) / 8)
  58.112 +    | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*5 + INTERP_16_MASK_2(p2)*3) / 8);
  58.113 +}
  58.114 +
  58.115 +static inline u16 interp_16_151(u16 p1, u16 p2)
  58.116 +{
  58.117 +  return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*15 + INTERP_16_MASK_1(p2)) / 16)
  58.118 +    | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*15 + INTERP_16_MASK_2(p2)) / 16);
  58.119 +}
  58.120 +
  58.121 +static inline u16 interp_16_97(u16 p1, u16 p2)
  58.122 +{
  58.123 +  return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*9 + INTERP_16_MASK_1(p2)*7) / 16)
  58.124 +    | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*9 + INTERP_16_MASK_2(p2)*7) / 16);
  58.125 +}
  58.126 +
  58.127 +#define INTERP_32_MASK_1(v) (v & 0xFF00FF)
  58.128 +#define INTERP_32_MASK_2(v) (v & 0x00FF00)
  58.129 +
  58.130 +static inline u32 interp_32_521(u32 p1, u32 p2, u32 p3)
  58.131 +{
  58.132 +  return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*5 + INTERP_32_MASK_1(p2)*2 + INTERP_32_MASK_1(p3)*1) / 8)
  58.133 +    | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*5 + INTERP_32_MASK_2(p2)*2 + INTERP_32_MASK_2(p3)*1) / 8);
  58.134 +}
  58.135 +
  58.136 +static inline u32 interp_32_332(u32 p1, u32 p2, u32 p3)
  58.137 +{
  58.138 +  return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*3 + INTERP_32_MASK_1(p2)*3 + INTERP_32_MASK_1(p3)*2) / 8)
  58.139 +    | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*3 + INTERP_32_MASK_2(p2)*3 + INTERP_32_MASK_2(p3)*2) / 8);
  58.140 +}
  58.141 +
  58.142 +static inline u32 interp_32_211(u32 p1, u32 p2, u32 p3)
  58.143 +{
  58.144 +  return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*2 + INTERP_32_MASK_1(p2) + INTERP_32_MASK_1(p3)) / 4)
  58.145 +    | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*2 + INTERP_32_MASK_2(p2) + INTERP_32_MASK_2(p3)) / 4);
  58.146 +}
  58.147 +
  58.148 +static inline u32 interp_32_611(u32 p1, u32 p2, u32 p3)
  58.149 +{
  58.150 +  return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*6 + INTERP_32_MASK_1(p2) + INTERP_32_MASK_1(p3)) / 8)
  58.151 +    | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*6 + INTERP_32_MASK_2(p2) + INTERP_32_MASK_2(p3)) / 8);
  58.152 +}
  58.153 +
  58.154 +static inline u32 interp_32_71(u32 p1, u32 p2)
  58.155 +{
  58.156 +  return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*7 + INTERP_32_MASK_1(p2)) / 8)
  58.157 +    | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*7 + INTERP_32_MASK_2(p2)) / 8);
  58.158 +}
  58.159 +
  58.160 +static inline u32 interp_32_772(u32 p1, u32 p2, u32 p3)
  58.161 +{
  58.162 +  return INTERP_32_MASK_1(((INTERP_32_MASK_1(p1) + INTERP_32_MASK_1(p2))*7 + INTERP_32_MASK_1(p3)*2) / 16)
  58.163 +    | INTERP_32_MASK_2(((INTERP_32_MASK_2(p1) + INTERP_32_MASK_2(p2))*7 + INTERP_32_MASK_2(p3)*2) / 16);
  58.164 +}
  58.165 +
  58.166 +static inline u32 interp_32_11(u32 p1, u32 p2)
  58.167 +{
  58.168 +  return INTERP_32_MASK_1((INTERP_32_MASK_1(p1) + INTERP_32_MASK_1(p2)) / 2)
  58.169 +    | INTERP_32_MASK_2((INTERP_32_MASK_2(p1) + INTERP_32_MASK_2(p2)) / 2);
  58.170 +}
  58.171 +
  58.172 +static inline u32 interp_32_31(u32 p1, u32 p2)
  58.173 +{
  58.174 +  return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*3 + INTERP_32_MASK_1(p2)) / 4)
  58.175 +    | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*3 + INTERP_32_MASK_2(p2)) / 4);
  58.176 +}
  58.177 +
  58.178 +static inline u32 interp_32_1411(u32 p1, u32 p2, u32 p3)
  58.179 +{
  58.180 +  return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*14 + INTERP_32_MASK_1(p2) + INTERP_32_MASK_1(p3)) / 16)
  58.181 +    | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*14 + INTERP_32_MASK_2(p2) + INTERP_32_MASK_2(p3)) / 16);
  58.182 +}
  58.183 +
  58.184 +static inline u32 interp_32_431(u32 p1, u32 p2, u32 p3)
  58.185 +{
  58.186 +  return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*4 + INTERP_32_MASK_1(p2)*3 + INTERP_32_MASK_1(p3)) / 8)
  58.187 +    | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*4 + INTERP_32_MASK_2(p2)*3 + INTERP_32_MASK_2(p3)) / 8);
  58.188 +}
  58.189 +
  58.190 +static inline u32 interp_32_53(u32 p1, u32 p2)
  58.191 +{
  58.192 +  return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*5 + INTERP_32_MASK_1(p2)*3) / 8)
  58.193 +    | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*5 + INTERP_32_MASK_2(p2)*3) / 8);
  58.194 +}
  58.195 +
  58.196 +static inline u32 interp_32_151(u32 p1, u32 p2)
  58.197 +{
  58.198 +  return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*15 + INTERP_32_MASK_1(p2)) / 16)
  58.199 +    | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*15 + INTERP_32_MASK_2(p2)) / 16);
  58.200 +}
  58.201 +
  58.202 +static inline u32 interp_32_97(u32 p1, u32 p2)
  58.203 +{
  58.204 +  return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*9 + INTERP_32_MASK_1(p2)*7) / 16)
  58.205 +    | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*9 + INTERP_32_MASK_2(p2)*7) / 16);
  58.206 +}
  58.207 +
  58.208 +/***************************************************************************/
  58.209 +/* diff */
  58.210 +
  58.211 +#define INTERP_Y_LIMIT (0x30*4)
  58.212 +#define INTERP_U_LIMIT (0x07*4)
  58.213 +#define INTERP_V_LIMIT (0x06*8)
  58.214 +
  58.215 +static int interp_16_diff(u16 p1, u16 p2)
  58.216 +{
  58.217 +  int r, g, b;
  58.218 +  int y, u, v;
  58.219 +
  58.220 +  if (p1 == p2)
  58.221 +    return 0;
  58.222 +
  58.223 +  if (interp_bits_per_pixel == 16) {
  58.224 +    b = (int)((p1 & 0x1F) - (p2 & 0x1F)) << 3;
  58.225 +    g = (int)((p1 & 0x7E0) - (p2 & 0x7E0)) >> 3;
  58.226 +    r = (int)((p1 & 0xF800) - (p2 & 0xF800)) >> 8;
  58.227 +  } else {
  58.228 +    b = (int)((p1 & 0x1F) - (p2 & 0x1F)) << 3;
  58.229 +    g = (int)((p1 & 0x3E0) - (p2 & 0x3E0)) >> 2;
  58.230 +    r = (int)((p1 & 0x7C00) - (p2 & 0x7C00)) >> 7;
  58.231 +  }
  58.232 +
  58.233 +  y = r + g + b;
  58.234 +  u = r - b;
  58.235 +  v = -r + 2*g - b;
  58.236 +
  58.237 +  if (y < -INTERP_Y_LIMIT || y > INTERP_Y_LIMIT)
  58.238 +    return 1;
  58.239 +
  58.240 +  if (u < -INTERP_U_LIMIT || u > INTERP_U_LIMIT)
  58.241 +    return 1;
  58.242 +
  58.243 +  if (v < -INTERP_V_LIMIT || v > INTERP_V_LIMIT)
  58.244 +    return 1;
  58.245 +
  58.246 +return 0;
  58.247 +}
  58.248 +
  58.249 +static int interp_32_diff(u32 p1, u32 p2)
  58.250 +{
  58.251 +  int r, g, b;
  58.252 +  int y, u, v;
  58.253 +
  58.254 +  if ((p1 & 0xF8F8F8) == (p2 & 0xF8F8F8))
  58.255 +    return 0;
  58.256 +
  58.257 +  b = (int)((p1 & 0xFF) - (p2 & 0xFF));
  58.258 +  g = (int)((p1 & 0xFF00) - (p2 & 0xFF00)) >> 8;
  58.259 +  r = (int)((p1 & 0xFF0000) - (p2 & 0xFF0000)) >> 16;
  58.260 +
  58.261 +  y = r + g + b;
  58.262 +  u = r - b;
  58.263 +  v = -r + 2*g - b;
  58.264 +
  58.265 +  if (y < -INTERP_Y_LIMIT || y > INTERP_Y_LIMIT)
  58.266 +    return 1;
  58.267 +
  58.268 +  if (u < -INTERP_U_LIMIT || u > INTERP_U_LIMIT)
  58.269 +    return 1;
  58.270 +
  58.271 +  if (v < -INTERP_V_LIMIT || v > INTERP_V_LIMIT)
  58.272 +    return 1;
  58.273 +
  58.274 +  return 0;
  58.275 +}
  58.276 +
  58.277 +
  58.278 +#define INTERP_LIMIT2 (96000)
  58.279 +#define ABS(x) ((x) < 0 ? -(x) : (x))
  58.280 +#define MAX(x,y) ((x) > (y) ? (x) : (y))
  58.281 +#define MIN(x,y) ((x) < (y) ? (x) : (y))
  58.282 +
  58.283 +static int interp_16_diff2(u16 p1, u16 p2)
  58.284 +{
  58.285 +  int r, g, b;
  58.286 +  int y, u, v;
  58.287 +
  58.288 +  if ((p1 & 0xF79E) == (p2 & 0xF79E))
  58.289 +    return 0;
  58.290 +
  58.291 +  if (interp_bits_per_pixel == 16) {
  58.292 +    b = (int)((p1 & 0x1F) - (p2 & 0x1F)) << 3;
  58.293 +    g = (int)((p1 & 0x7E0) - (p2 & 0x7E0)) >> 3;
  58.294 +    r = (int)((p1 & 0xF800) - (p2 & 0xF800)) >> 8;
  58.295 +  } else {
  58.296 +    b = (int)((p1 & 0x1F) - (p2 & 0x1F)) << 3;
  58.297 +    g = (int)((p1 & 0x3E0) - (p2 & 0x3E0)) >> 2;
  58.298 +    r = (int)((p1 & 0x7C00) - (p2 & 0x7C00)) >> 7;
  58.299 +  }
  58.300 +
  58.301 +//  yb =  30*r + 58*g + 12*b;
  58.302 +  y =  33*r + 36*g + 31*b;
  58.303 +  u = -14*r - 29*g + 44*b; 
  58.304 +  v =  62*r - 51*g - 10*b;
  58.305 +
  58.306 +  if (11*ABS(y) + 8*ABS(u) + 6*ABS(v) > INTERP_LIMIT2)
  58.307 +    return 1;
  58.308 +  return 0;
  58.309 +}
  58.310 +
  58.311 +static int interp_32_diff2(u32 p1, u32 p2)
  58.312 +{
  58.313 +  int r, g, b;
  58.314 +  int y, u, v;
  58.315 +
  58.316 +  if ((p1 & 0xF0F0F0) == (p2 & 0xF0F0F0))
  58.317 +    return 0;
  58.318 +
  58.319 +  b = (int)((p1 & 0xF8) - (p2 & 0xF8));
  58.320 +  g = (int)((p1 & 0xF800) - (p2 & 0xF800)) >> 8;
  58.321 +  r = (int)((p1 & 0xF80000) - (p2 & 0xF80000)) >> 16;
  58.322 +
  58.323 +//  y =  30*r + 58*g + 12*b;
  58.324 +  y =  33*r + 36*g + 31*b;
  58.325 +  u = -14*r - 29*g + 44*b; 
  58.326 +  v =  62*r - 51*g - 10*b;
  58.327 +
  58.328 +  if (11*ABS(y) + 8*ABS(u) + 6*ABS(v) > INTERP_LIMIT2)
  58.329 +    return 1;
  58.330 +
  58.331 +  return 0;
  58.332 +}
  58.333 +
  58.334 +static void interp_set(unsigned bits_per_pixel)
  58.335 +{
  58.336 +  interp_bits_per_pixel = bits_per_pixel;
  58.337 +
  58.338 +  switch (bits_per_pixel) {
  58.339 +  case 15 :
  58.340 +    interp_mask[0] = 0x7C1F;
  58.341 +    interp_mask[1] = 0x03E0;
  58.342 +    break;
  58.343 +  case 16 :
  58.344 +    interp_mask[0] = 0xF81F;
  58.345 +    interp_mask[1] = 0x07E0;
  58.346 +    break;
  58.347 +  case 32 :
  58.348 +    interp_mask[0] = 0xFF00FF;
  58.349 +    interp_mask[1] = 0x00FF00;
  58.350 +    break;
  58.351 +  }
  58.352 +}
  58.353 +
  58.354 +#endif
    59.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    59.2 +++ b/src/filters/lq2x.h	Sat Mar 03 10:31:27 2012 -0600
    59.3 @@ -0,0 +1,1284 @@
    59.4 +case 0 : 
    59.5 +case 2 : 
    59.6 +case 4 : 
    59.7 +case 6 : 
    59.8 +case 8 : 
    59.9 +case 12 : 
   59.10 +case 16 : 
   59.11 +case 20 : 
   59.12 +case 24 : 
   59.13 +case 28 : 
   59.14 +case 32 : 
   59.15 +case 34 : 
   59.16 +case 36 : 
   59.17 +case 38 : 
   59.18 +case 40 : 
   59.19 +case 44 : 
   59.20 +case 48 : 
   59.21 +case 52 : 
   59.22 +case 56 : 
   59.23 +case 60 : 
   59.24 +case 64 : 
   59.25 +case 66 : 
   59.26 +case 68 : 
   59.27 +case 70 : 
   59.28 +case 96 : 
   59.29 +case 98 : 
   59.30 +case 100 : 
   59.31 +case 102 : 
   59.32 +case 128 : 
   59.33 +case 130 : 
   59.34 +case 132 : 
   59.35 +case 134 : 
   59.36 +case 136 : 
   59.37 +case 140 : 
   59.38 +case 144 : 
   59.39 +case 148 : 
   59.40 +case 152 : 
   59.41 +case 156 : 
   59.42 +case 160 : 
   59.43 +case 162 : 
   59.44 +case 164 : 
   59.45 +case 166 : 
   59.46 +case 168 : 
   59.47 +case 172 : 
   59.48 +case 176 : 
   59.49 +case 180 : 
   59.50 +case 184 : 
   59.51 +case 188 : 
   59.52 +case 192 : 
   59.53 +case 194 : 
   59.54 +case 196 : 
   59.55 +case 198 : 
   59.56 +case 224 : 
   59.57 +case 226 : 
   59.58 +case 228 : 
   59.59 +case 230 : 
   59.60 +{
   59.61 +  P0 = IC(0);
   59.62 +  P1 = IC(0);
   59.63 +  P2 = IC(0);
   59.64 +  P3 = IC(0);
   59.65 +} break;
   59.66 +case 1 : 
   59.67 +case 5 : 
   59.68 +case 9 : 
   59.69 +case 13 : 
   59.70 +case 17 : 
   59.71 +case 21 : 
   59.72 +case 25 : 
   59.73 +case 29 : 
   59.74 +case 33 : 
   59.75 +case 37 : 
   59.76 +case 41 : 
   59.77 +case 45 : 
   59.78 +case 49 : 
   59.79 +case 53 : 
   59.80 +case 57 : 
   59.81 +case 61 : 
   59.82 +case 65 : 
   59.83 +case 69 : 
   59.84 +case 97 : 
   59.85 +case 101 : 
   59.86 +case 129 : 
   59.87 +case 133 : 
   59.88 +case 137 : 
   59.89 +case 141 : 
   59.90 +case 145 : 
   59.91 +case 149 : 
   59.92 +case 153 : 
   59.93 +case 157 : 
   59.94 +case 161 : 
   59.95 +case 165 : 
   59.96 +case 169 : 
   59.97 +case 173 : 
   59.98 +case 177 : 
   59.99 +case 181 : 
  59.100 +case 185 : 
  59.101 +case 189 : 
  59.102 +case 193 : 
  59.103 +case 197 : 
  59.104 +case 225 : 
  59.105 +case 229 : 
  59.106 +{
  59.107 +  P0 = IC(1);
  59.108 +  P1 = IC(1);
  59.109 +  P2 = IC(1);
  59.110 +  P3 = IC(1);
  59.111 +} break;
  59.112 +case 3 : 
  59.113 +case 35 : 
  59.114 +case 67 : 
  59.115 +case 99 : 
  59.116 +case 131 : 
  59.117 +case 163 : 
  59.118 +case 195 : 
  59.119 +case 227 : 
  59.120 +{
  59.121 +  P0 = IC(2);
  59.122 +  P1 = IC(2);
  59.123 +  P2 = IC(2);
  59.124 +  P3 = IC(2);
  59.125 +} break;
  59.126 +case 7 : 
  59.127 +case 39 : 
  59.128 +case 71 : 
  59.129 +case 103 : 
  59.130 +case 135 : 
  59.131 +case 167 : 
  59.132 +case 199 : 
  59.133 +case 231 : 
  59.134 +{
  59.135 +  P0 = IC(3);
  59.136 +  P1 = IC(3);
  59.137 +  P2 = IC(3);
  59.138 +  P3 = IC(3);
  59.139 +} break;
  59.140 +case 10 : 
  59.141 +case 138 : 
  59.142 +{
  59.143 +  P1 = IC(0);
  59.144 +  P2 = IC(0);
  59.145 +  P3 = IC(0);
  59.146 +  if (MUL) {
  59.147 +    P0 = IC(0);
  59.148 +  } else {
  59.149 +    P0 = I211(0, 1, 3);
  59.150 +  }
  59.151 +} break;
  59.152 +case 11 : 
  59.153 +case 27 : 
  59.154 +case 75 : 
  59.155 +case 139 : 
  59.156 +case 155 : 
  59.157 +case 203 : 
  59.158 +{
  59.159 +  P1 = IC(2);
  59.160 +  P2 = IC(2);
  59.161 +  P3 = IC(2);
  59.162 +  if (MUL) {
  59.163 +    P0 = IC(2);
  59.164 +  } else {
  59.165 +    P0 = I211(2, 1, 3);
  59.166 +  }
  59.167 +} break;
  59.168 +case 14 : 
  59.169 +case 142 : 
  59.170 +{
  59.171 +  P2 = IC(0);
  59.172 +  P3 = IC(0);
  59.173 +  if (MUL) {
  59.174 +    P0 = IC(0);
  59.175 +    P1 = IC(0);
  59.176 +  } else {
  59.177 +    P0 = I332(1, 3, 0);
  59.178 +    P1 = I31(0, 1);
  59.179 +  }
  59.180 +} break;
  59.181 +case 15 : 
  59.182 +case 143 : 
  59.183 +case 207 : 
  59.184 +{
  59.185 +  P2 = IC(4);
  59.186 +  P3 = IC(4);
  59.187 +  if (MUL) {
  59.188 +    P0 = IC(4);
  59.189 +    P1 = IC(4);
  59.190 +  } else {
  59.191 +    P0 = I332(1, 3, 4);
  59.192 +    P1 = I31(4, 1);
  59.193 +  }
  59.194 +} break;
  59.195 +case 18 : 
  59.196 +case 22 : 
  59.197 +case 30 : 
  59.198 +case 50 : 
  59.199 +case 54 : 
  59.200 +case 62 : 
  59.201 +case 86 : 
  59.202 +case 118 : 
  59.203 +{
  59.204 +  P0 = IC(0);
  59.205 +  P2 = IC(0);
  59.206 +  P3 = IC(0);
  59.207 +  if (MUR) {
  59.208 +    P1 = IC(0);
  59.209 +  } else {
  59.210 +    P1 = I211(0, 1, 5);
  59.211 +  }
  59.212 +} break;
  59.213 +case 19 : 
  59.214 +case 51 : 
  59.215 +{
  59.216 +  P2 = IC(2);
  59.217 +  P3 = IC(2);
  59.218 +  if (MUR) {
  59.219 +    P0 = IC(2);
  59.220 +    P1 = IC(2);
  59.221 +  } else {
  59.222 +    P0 = I31(2, 1);
  59.223 +    P1 = I332(1, 5, 2);
  59.224 +  }
  59.225 +} break;
  59.226 +case 23 : 
  59.227 +case 55 : 
  59.228 +case 119 : 
  59.229 +{
  59.230 +  P2 = IC(3);
  59.231 +  P3 = IC(3);
  59.232 +  if (MUR) {
  59.233 +    P0 = IC(3);
  59.234 +    P1 = IC(3);
  59.235 +  } else {
  59.236 +    P0 = I31(3, 1);
  59.237 +    P1 = I332(1, 5, 3);
  59.238 +  }
  59.239 +} break;
  59.240 +case 26 : 
  59.241 +{
  59.242 +  P2 = IC(0);
  59.243 +  P3 = IC(0);
  59.244 +  if (MUL) {
  59.245 +    P0 = IC(0);
  59.246 +  } else {
  59.247 +    P0 = I211(0, 1, 3);
  59.248 +  }
  59.249 +  if (MUR) {
  59.250 +    P1 = IC(0);
  59.251 +  } else {
  59.252 +    P1 = I211(0, 1, 5);
  59.253 +  }
  59.254 +} break;
  59.255 +case 31 : 
  59.256 +case 95 : 
  59.257 +{
  59.258 +  P2 = IC(4);
  59.259 +  P3 = IC(4);
  59.260 +  if (MUL) {
  59.261 +    P0 = IC(4);
  59.262 +  } else {
  59.263 +    P0 = I211(4, 1, 3);
  59.264 +  }
  59.265 +  if (MUR) {
  59.266 +    P1 = IC(4);
  59.267 +  } else {
  59.268 +    P1 = I211(4, 1, 5);
  59.269 +  }
  59.270 +} break;
  59.271 +case 42 : 
  59.272 +case 170 : 
  59.273 +{
  59.274 +  P1 = IC(0);
  59.275 +  P3 = IC(0);
  59.276 +  if (MUL) {
  59.277 +    P0 = IC(0);
  59.278 +    P2 = IC(0);
  59.279 +  } else {
  59.280 +    P0 = I332(1, 3, 0);
  59.281 +    P2 = I31(0, 3);
  59.282 +  }
  59.283 +} break;
  59.284 +case 43 : 
  59.285 +case 171 : 
  59.286 +case 187 : 
  59.287 +{
  59.288 +  P1 = IC(2);
  59.289 +  P3 = IC(2);
  59.290 +  if (MUL) {
  59.291 +    P0 = IC(2);
  59.292 +    P2 = IC(2);
  59.293 +  } else {
  59.294 +    P0 = I332(1, 3, 2);
  59.295 +    P2 = I31(2, 3);
  59.296 +  }
  59.297 +} break;
  59.298 +case 46 : 
  59.299 +case 174 : 
  59.300 +{
  59.301 +  P1 = IC(0);
  59.302 +  P2 = IC(0);
  59.303 +  P3 = IC(0);
  59.304 +  if (MUL) {
  59.305 +    P0 = IC(0);
  59.306 +  } else {
  59.307 +    P0 = I611(0, 1, 3);
  59.308 +  }
  59.309 +} break;
  59.310 +case 47 : 
  59.311 +case 175 : 
  59.312 +{
  59.313 +  P1 = IC(4);
  59.314 +  P2 = IC(4);
  59.315 +  P3 = IC(4);
  59.316 +  if (MUL) {
  59.317 +    P0 = IC(4);
  59.318 +  } else {
  59.319 +    P0 = I1411(4, 1, 3);
  59.320 +  }
  59.321 +} break;
  59.322 +case 58 : 
  59.323 +case 154 : 
  59.324 +case 186 : 
  59.325 +{
  59.326 +  P2 = IC(0);
  59.327 +  P3 = IC(0);
  59.328 +  if (MUL) {
  59.329 +    P0 = IC(0);
  59.330 +  } else {
  59.331 +    P0 = I611(0, 1, 3);
  59.332 +  }
  59.333 +  if (MUR) {
  59.334 +    P1 = IC(0);
  59.335 +  } else {
  59.336 +    P1 = I611(0, 1, 5);
  59.337 +  }
  59.338 +} break;
  59.339 +case 59 : 
  59.340 +{
  59.341 +  P2 = IC(2);
  59.342 +  P3 = IC(2);
  59.343 +  if (MUL) {
  59.344 +    P0 = IC(2);
  59.345 +  } else {
  59.346 +    P0 = I211(2, 1, 3);
  59.347 +  }
  59.348 +  if (MUR) {
  59.349 +    P1 = IC(2);
  59.350 +  } else {
  59.351 +    P1 = I611(2, 1, 5);
  59.352 +  }
  59.353 +} break;
  59.354 +case 63 : 
  59.355 +{
  59.356 +  P2 = IC(4);
  59.357 +  P3 = IC(4);
  59.358 +  if (MUL) {
  59.359 +    P0 = IC(4);
  59.360 +  } else {
  59.361 +    P0 = I1411(4, 1, 3);
  59.362 +  }
  59.363 +  if (MUR) {
  59.364 +    P1 = IC(4);
  59.365 +  } else {
  59.366 +    P1 = I211(4, 1, 5);
  59.367 +  }
  59.368 +} break;
  59.369 +case 72 : 
  59.370 +case 76 : 
  59.371 +case 104 : 
  59.372 +case 106 : 
  59.373 +case 108 : 
  59.374 +case 110 : 
  59.375 +case 120 : 
  59.376 +case 124 : 
  59.377 +{
  59.378 +  P0 = IC(0);
  59.379 +  P1 = IC(0);
  59.380 +  P3 = IC(0);
  59.381 +  if (MDL) {
  59.382 +    P2 = IC(0);
  59.383 +  } else {
  59.384 +    P2 = I211(0, 3, 7);
  59.385 +  }
  59.386 +} break;
  59.387 +case 73 : 
  59.388 +case 77 : 
  59.389 +case 105 : 
  59.390 +case 109 : 
  59.391 +case 125 : 
  59.392 +{
  59.393 +  P1 = IC(1);
  59.394 +  P3 = IC(1);
  59.395 +  if (MDL) {
  59.396 +    P0 = IC(1);
  59.397 +    P2 = IC(1);
  59.398 +  } else {
  59.399 +    P0 = I31(1, 3);
  59.400 +    P2 = I332(3, 7, 1);
  59.401 +  }
  59.402 +} break;
  59.403 +case 74 : 
  59.404 +{
  59.405 +  P1 = IC(0);
  59.406 +  P3 = IC(0);
  59.407 +  if (MDL) {
  59.408 +    P2 = IC(0);
  59.409 +  } else {
  59.410 +    P2 = I211(0, 3, 7);
  59.411 +  }
  59.412 +  if (MUL) {
  59.413 +    P0 = IC(0);
  59.414 +  } else {
  59.415 +    P0 = I211(0, 1, 3);
  59.416 +  }
  59.417 +} break;
  59.418 +case 78 : 
  59.419 +case 202 : 
  59.420 +case 206 : 
  59.421 +{
  59.422 +  P1 = IC(0);
  59.423 +  P3 = IC(0);
  59.424 +  if (MDL) {
  59.425 +    P2 = IC(0);
  59.426 +  } else {
  59.427 +    P2 = I611(0, 3, 7);
  59.428 +  }
  59.429 +  if (MUL) {
  59.430 +    P0 = IC(0);
  59.431 +  } else {
  59.432 +    P0 = I611(0, 1, 3);
  59.433 +  }
  59.434 +} break;
  59.435 +case 79 : 
  59.436 +{
  59.437 +  P1 = IC(4);
  59.438 +  P3 = IC(4);
  59.439 +  if (MDL) {
  59.440 +    P2 = IC(4);
  59.441 +  } else {
  59.442 +    P2 = I611(4, 3, 7);
  59.443 +  }
  59.444 +  if (MUL) {
  59.445 +    P0 = IC(4);
  59.446 +  } else {
  59.447 +    P0 = I211(4, 1, 3);
  59.448 +  }
  59.449 +} break;
  59.450 +case 80 : 
  59.451 +case 208 : 
  59.452 +case 210 : 
  59.453 +case 216 : 
  59.454 +{
  59.455 +  P0 = IC(0);
  59.456 +  P1 = IC(0);
  59.457 +  P2 = IC(0);
  59.458 +  if (MDR) {
  59.459 +    P3 = IC(0);
  59.460 +  } else {
  59.461 +    P3 = I211(0, 5, 7);
  59.462 +  }
  59.463 +} break;
  59.464 +case 81 : 
  59.465 +case 209 : 
  59.466 +case 217 : 
  59.467 +{
  59.468 +  P0 = IC(1);
  59.469 +  P1 = IC(1);
  59.470 +  P2 = IC(1);
  59.471 +  if (MDR) {
  59.472 +    P3 = IC(1);
  59.473 +  } else {
  59.474 +    P3 = I211(1, 5, 7);
  59.475 +  }
  59.476 +} break;
  59.477 +case 82 : 
  59.478 +case 214 : 
  59.479 +case 222 : 
  59.480 +{
  59.481 +  P0 = IC(0);
  59.482 +  P2 = IC(0);
  59.483 +  if (MDR) {
  59.484 +    P3 = IC(0);
  59.485 +  } else {
  59.486 +    P3 = I211(0, 5, 7);
  59.487 +  }
  59.488 +  if (MUR) {
  59.489 +    P1 = IC(0);
  59.490 +  } else {
  59.491 +    P1 = I211(0, 1, 5);
  59.492 +  }
  59.493 +} break;
  59.494 +case 83 : 
  59.495 +case 115 : 
  59.496 +{
  59.497 +  P0 = IC(2);
  59.498 +  P2 = IC(2);
  59.499 +  if (MDR) {
  59.500 +    P3 = IC(2);
  59.501 +  } else {
  59.502 +    P3 = I611(2, 5, 7);
  59.503 +  }
  59.504 +  if (MUR) {
  59.505 +    P1 = IC(2);
  59.506 +  } else {
  59.507 +    P1 = I611(2, 1, 5);
  59.508 +  }
  59.509 +} break;
  59.510 +case 84 : 
  59.511 +case 212 : 
  59.512 +{
  59.513 +  P0 = IC(0);
  59.514 +  P2 = IC(0);
  59.515 +  if (MDR) {
  59.516 +    P1 = IC(0);
  59.517 +    P3 = IC(0);
  59.518 +  } else {
  59.519 +    P1 = I31(0, 5);
  59.520 +    P3 = I332(5, 7, 0);
  59.521 +  }
  59.522 +} break;
  59.523 +case 85 : 
  59.524 +case 213 : 
  59.525 +case 221 : 
  59.526 +{
  59.527 +  P0 = IC(1);
  59.528 +  P2 = IC(1);
  59.529 +  if (MDR) {
  59.530 +    P1 = IC(1);
  59.531 +    P3 = IC(1);
  59.532 +  } else {
  59.533 +    P1 = I31(1, 5);
  59.534 +    P3 = I332(5, 7, 1);
  59.535 +  }
  59.536 +} break;
  59.537 +case 87 : 
  59.538 +{
  59.539 +  P0 = IC(3);
  59.540 +  P2 = IC(3);
  59.541 +  if (MDR) {
  59.542 +    P3 = IC(3);
  59.543 +  } else {
  59.544 +    P3 = I611(3, 5, 7);
  59.545 +  }
  59.546 +  if (MUR) {
  59.547 +    P1 = IC(3);
  59.548 +  } else {
  59.549 +    P1 = I211(3, 1, 5);
  59.550 +  }
  59.551 +} break;
  59.552 +case 88 : 
  59.553 +case 248 : 
  59.554 +case 250 : 
  59.555 +{
  59.556 +  P0 = IC(0);
  59.557 +  P1 = IC(0);
  59.558 +  if (MDL) {
  59.559 +    P2 = IC(0);
  59.560 +  } else {
  59.561 +    P2 = I211(0, 3, 7);
  59.562 +  }
  59.563 +  if (MDR) {
  59.564 +    P3 = IC(0);
  59.565 +  } else {
  59.566 +    P3 = I211(0, 5, 7);
  59.567 +  }
  59.568 +} break;
  59.569 +case 89 : 
  59.570 +case 93 : 
  59.571 +{
  59.572 +  P0 = IC(1);
  59.573 +  P1 = IC(1);
  59.574 +  if (MDL) {
  59.575 +    P2 = IC(1);
  59.576 +  } else {
  59.577 +    P2 = I611(1, 3, 7);
  59.578 +  }
  59.579 +  if (MDR) {
  59.580 +    P3 = IC(1);
  59.581 +  } else {
  59.582 +    P3 = I611(1, 5, 7);
  59.583 +  }
  59.584 +} break;
  59.585 +case 90 : 
  59.586 +{
  59.587 +  if (MDL) {
  59.588 +    P2 = IC(0);
  59.589 +  } else {
  59.590 +    P2 = I611(0, 3, 7);
  59.591 +  }
  59.592 +  if (MDR) {
  59.593 +    P3 = IC(0);
  59.594 +  } else {
  59.595 +    P3 = I611(0, 5, 7);
  59.596 +  }
  59.597 +  if (MUL) {
  59.598 +    P0 = IC(0);
  59.599 +  } else {
  59.600 +    P0 = I611(0, 1, 3);
  59.601 +  }
  59.602 +  if (MUR) {
  59.603 +    P1 = IC(0);
  59.604 +  } else {
  59.605 +    P1 = I611(0, 1, 5);
  59.606 +  }
  59.607 +} break;
  59.608 +case 91 : 
  59.609 +{
  59.610 +  if (MDL) {
  59.611 +    P2 = IC(2);
  59.612 +  } else {
  59.613 +    P2 = I611(2, 3, 7);
  59.614 +  }
  59.615 +  if (MDR) {
  59.616 +    P3 = IC(2);
  59.617 +  } else {
  59.618 +    P3 = I611(2, 5, 7);
  59.619 +  }
  59.620 +  if (MUL) {
  59.621 +    P0 = IC(2);
  59.622 +  } else {
  59.623 +    P0 = I211(2, 1, 3);
  59.624 +  }
  59.625 +  if (MUR) {
  59.626 +    P1 = IC(2);
  59.627 +  } else {
  59.628 +    P1 = I611(2, 1, 5);
  59.629 +  }
  59.630 +} break;
  59.631 +case 92 : 
  59.632 +{
  59.633 +  P0 = IC(0);
  59.634 +  P1 = IC(0);
  59.635 +  if (MDL) {
  59.636 +    P2 = IC(0);
  59.637 +  } else {
  59.638 +    P2 = I611(0, 3, 7);
  59.639 +  }
  59.640 +  if (MDR) {
  59.641 +    P3 = IC(0);
  59.642 +  } else {
  59.643 +    P3 = I611(0, 5, 7);
  59.644 +  }
  59.645 +} break;
  59.646 +case 94 : 
  59.647 +{
  59.648 +  if (MDL) {
  59.649 +    P2 = IC(0);
  59.650 +  } else {
  59.651 +    P2 = I611(0, 3, 7);
  59.652 +  }
  59.653 +  if (MDR) {
  59.654 +    P3 = IC(0);
  59.655 +  } else {
  59.656 +    P3 = I611(0, 5, 7);
  59.657 +  }
  59.658 +  if (MUL) {
  59.659 +    P0 = IC(0);
  59.660 +  } else {
  59.661 +    P0 = I611(0, 1, 3);
  59.662 +  }
  59.663 +  if (MUR) {
  59.664 +    P1 = IC(0);
  59.665 +  } else {
  59.666 +    P1 = I211(0, 1, 5);
  59.667 +  }
  59.668 +} break;
  59.669 +case 107 : 
  59.670 +case 123 : 
  59.671 +{
  59.672 +  P1 = IC(2);
  59.673 +  P3 = IC(2);
  59.674 +  if (MDL) {
  59.675 +    P2 = IC(2);
  59.676 +  } else {
  59.677 +    P2 = I211(2, 3, 7);
  59.678 +  }
  59.679 +  if (MUL) {
  59.680 +    P0 = IC(2);
  59.681 +  } else {
  59.682 +    P0 = I211(2, 1, 3);
  59.683 +  }
  59.684 +} break;
  59.685 +case 111 : 
  59.686 +{
  59.687 +  P1 = IC(4);
  59.688 +  P3 = IC(4);
  59.689 +  if (MDL) {
  59.690 +    P2 = IC(4);
  59.691 +  } else {
  59.692 +    P2 = I211(4, 3, 7);
  59.693 +  }
  59.694 +  if (MUL) {
  59.695 +    P0 = IC(4);
  59.696 +  } else {
  59.697 +    P0 = I1411(4, 1, 3);
  59.698 +  }
  59.699 +} break;
  59.700 +case 112 : 
  59.701 +case 240 : 
  59.702 +{
  59.703 +  P0 = IC(0);
  59.704 +  P1 = IC(0);
  59.705 +  if (MDR) {
  59.706 +    P2 = IC(0);
  59.707 +    P3 = IC(0);
  59.708 +  } else {
  59.709 +    P2 = I31(0, 7);
  59.710 +    P3 = I332(5, 7, 0);
  59.711 +  }
  59.712 +} break;
  59.713 +case 113 : 
  59.714 +case 241 : 
  59.715 +{
  59.716 +  P0 = IC(1);
  59.717 +  P1 = IC(1);
  59.718 +  if (MDR) {
  59.719 +    P2 = IC(1);
  59.720 +    P3 = IC(1);
  59.721 +  } else {
  59.722 +    P2 = I31(1, 7);
  59.723 +    P3 = I332(5, 7, 1);
  59.724 +  }
  59.725 +} break;
  59.726 +case 114 : 
  59.727 +{
  59.728 +  P0 = IC(0);
  59.729 +  P2 = IC(0);
  59.730 +  if (MDR) {
  59.731 +    P3 = IC(0);
  59.732 +  } else {
  59.733 +    P3 = I611(0, 5, 7);
  59.734 +  }
  59.735 +  if (MUR) {
  59.736 +    P1 = IC(0);
  59.737 +  } else {
  59.738 +    P1 = I611(0, 1, 5);
  59.739 +  }
  59.740 +} break;
  59.741 +case 116 : 
  59.742 +{
  59.743 +  P0 = IC(0);
  59.744 +  P1 = IC(0);
  59.745 +  P2 = IC(0);
  59.746 +  if (MDR) {
  59.747 +    P3 = IC(0);
  59.748 +  } else {
  59.749 +    P3 = I611(0, 5, 7);
  59.750 +  }
  59.751 +} break;
  59.752 +case 117 : 
  59.753 +{
  59.754 +  P0 = IC(1);
  59.755 +  P1 = IC(1);
  59.756 +  P2 = IC(1);
  59.757 +  if (MDR) {
  59.758 +    P3 = IC(1);
  59.759 +  } else {
  59.760 +    P3 = I611(1, 5, 7);
  59.761 +  }
  59.762 +} break;
  59.763 +case 121 : 
  59.764 +{
  59.765 +  P0 = IC(1);
  59.766 +  P1 = IC(1);
  59.767 +  if (MDL) {
  59.768 +    P2 = IC(1);
  59.769 +  } else {
  59.770 +    P2 = I211(1, 3, 7);
  59.771 +  }
  59.772 +  if (MDR) {
  59.773 +    P3 = IC(1);
  59.774 +  } else {
  59.775 +    P3 = I611(1, 5, 7);
  59.776 +  }
  59.777 +} break;
  59.778 +case 122 : 
  59.779 +{
  59.780 +  if (MDL) {
  59.781 +    P2 = IC(0);
  59.782 +  } else {
  59.783 +    P2 = I211(0, 3, 7);
  59.784 +  }
  59.785 +  if (MDR) {
  59.786 +    P3 = IC(0);
  59.787 +  } else {
  59.788 +    P3 = I611(0, 5, 7);
  59.789 +  }
  59.790 +  if (MUL) {
  59.791 +    P0 = IC(0);
  59.792 +  } else {
  59.793 +    P0 = I611(0, 1, 3);
  59.794 +  }
  59.795 +  if (MUR) {
  59.796 +    P1 = IC(0);
  59.797 +  } else {
  59.798 +    P1 = I611(0, 1, 5);
  59.799 +  }
  59.800 +} break;
  59.801 +case 126 : 
  59.802 +{
  59.803 +  P0 = IC(0);
  59.804 +  P3 = IC(0);
  59.805 +  if (MDL) {
  59.806 +    P2 = IC(0);
  59.807 +  } else {
  59.808 +    P2 = I211(0, 3, 7);
  59.809 +  }
  59.810 +  if (MUR) {
  59.811 +    P1 = IC(0);
  59.812 +  } else {
  59.813 +    P1 = I211(0, 1, 5);
  59.814 +  }
  59.815 +} break;
  59.816 +case 127 : 
  59.817 +{
  59.818 +  P3 = IC(4);
  59.819 +  if (MDL) {
  59.820 +    P2 = IC(4);
  59.821 +  } else {
  59.822 +    P2 = I211(4, 3, 7);
  59.823 +  }
  59.824 +  if (MUL) {
  59.825 +    P0 = IC(4);
  59.826 +  } else {
  59.827 +    P0 = I1411(4, 1, 3);
  59.828 +  }
  59.829 +  if (MUR) {
  59.830 +    P1 = IC(4);
  59.831 +  } else {
  59.832 +    P1 = I211(4, 1, 5);
  59.833 +  }
  59.834 +} break;
  59.835 +case 146 : 
  59.836 +case 150 : 
  59.837 +case 178 : 
  59.838 +case 182 : 
  59.839 +case 190 : 
  59.840 +{
  59.841 +  P0 = IC(0);
  59.842 +  P2 = IC(0);
  59.843 +  if (MUR) {
  59.844 +    P1 = IC(0);
  59.845 +    P3 = IC(0);
  59.846 +  } else {
  59.847 +    P1 = I332(1, 5, 0);
  59.848 +    P3 = I31(0, 5);
  59.849 +  }
  59.850 +} break;
  59.851 +case 147 : 
  59.852 +case 179 : 
  59.853 +{
  59.854 +  P0 = IC(2);
  59.855 +  P2 = IC(2);
  59.856 +  P3 = IC(2);
  59.857 +  if (MUR) {
  59.858 +    P1 = IC(2);
  59.859 +  } else {
  59.860 +    P1 = I611(2, 1, 5);
  59.861 +  }
  59.862 +} break;
  59.863 +case 151 : 
  59.864 +case 183 : 
  59.865 +{
  59.866 +  P0 = IC(3);
  59.867 +  P2 = IC(3);
  59.868 +  P3 = IC(3);
  59.869 +  if (MUR) {
  59.870 +    P1 = IC(3);
  59.871 +  } else {
  59.872 +    P1 = I1411(3, 1, 5);
  59.873 +  }
  59.874 +} break;
  59.875 +case 158 : 
  59.876 +{
  59.877 +  P2 = IC(0);
  59.878 +  P3 = IC(0);
  59.879 +  if (MUL) {
  59.880 +    P0 = IC(0);
  59.881 +  } else {
  59.882 +    P0 = I611(0, 1, 3);
  59.883 +  }
  59.884 +  if (MUR) {
  59.885 +    P1 = IC(0);
  59.886 +  } else {
  59.887 +    P1 = I211(0, 1, 5);
  59.888 +  }
  59.889 +} break;
  59.890 +case 159 : 
  59.891 +{
  59.892 +  P2 = IC(4);
  59.893 +  P3 = IC(4);
  59.894 +  if (MUL) {
  59.895 +    P0 = IC(4);
  59.896 +  } else {
  59.897 +    P0 = I211(4, 1, 3);
  59.898 +  }
  59.899 +  if (MUR) {
  59.900 +    P1 = IC(4);
  59.901 +  } else {
  59.902 +    P1 = I1411(4, 1, 5);
  59.903 +  }
  59.904 +} break;
  59.905 +case 191 : 
  59.906 +{
  59.907 +  P2 = IC(4);
  59.908 +  P3 = IC(4);
  59.909 +  if (MUL) {
  59.910 +    P0 = IC(4);
  59.911 +  } else {
  59.912 +    P0 = I1411(4, 1, 3);
  59.913 +  }
  59.914 +  if (MUR) {
  59.915 +    P1 = IC(4);
  59.916 +  } else {
  59.917 +    P1 = I1411(4, 1, 5);
  59.918 +  }
  59.919 +} break;
  59.920 +case 200 : 
  59.921 +case 204 : 
  59.922 +case 232 : 
  59.923 +case 236 : 
  59.924 +case 238 : 
  59.925 +{
  59.926 +  P0 = IC(0);
  59.927 +  P1 = IC(0);
  59.928 +  if (MDL) {
  59.929 +    P2 = IC(0);
  59.930 +    P3 = IC(0);
  59.931 +  } else {
  59.932 +    P2 = I332(3, 7, 0);
  59.933 +    P3 = I31(0, 7);
  59.934 +  }
  59.935 +} break;
  59.936 +case 201 : 
  59.937 +case 205 : 
  59.938 +{
  59.939 +  P0 = IC(1);
  59.940 +  P1 = IC(1);
  59.941 +  P3 = IC(1);
  59.942 +  if (MDL) {
  59.943 +    P2 = IC(1);
  59.944 +  } else {
  59.945 +    P2 = I611(1, 3, 7);
  59.946 +  }
  59.947 +} break;
  59.948 +case 211 : 
  59.949 +{
  59.950 +  P0 = IC(2);
  59.951 +  P1 = IC(2);
  59.952 +  P2 = IC(2);
  59.953 +  if (MDR) {
  59.954 +    P3 = IC(2);
  59.955 +  } else {
  59.956 +    P3 = I211(2, 5, 7);
  59.957 +  }
  59.958 +} break;
  59.959 +case 215 : 
  59.960 +{
  59.961 +  P0 = IC(3);
  59.962 +  P2 = IC(3);
  59.963 +  if (MDR) {
  59.964 +    P3 = IC(3);
  59.965 +  } else {
  59.966 +    P3 = I211(3, 5, 7);
  59.967 +  }
  59.968 +  if (MUR) {
  59.969 +    P1 = IC(3);
  59.970 +  } else {
  59.971 +    P1 = I1411(3, 1, 5);
  59.972 +  }
  59.973 +} break;
  59.974 +case 218 : 
  59.975 +{
  59.976 +  if (MDL) {
  59.977 +    P2 = IC(0);
  59.978 +  } else {
  59.979 +    P2 = I611(0, 3, 7);
  59.980 +  }
  59.981 +  if (MDR) {
  59.982 +    P3 = IC(0);
  59.983 +  } else {
  59.984 +    P3 = I211(0, 5, 7);
  59.985 +  }
  59.986 +  if (MUL) {
  59.987 +    P0 = IC(0);
  59.988 +  } else {
  59.989 +    P0 = I611(0, 1, 3);
  59.990 +  }
  59.991 +  if (MUR) {
  59.992 +    P1 = IC(0);
  59.993 +  } else {
  59.994 +    P1 = I611(0, 1, 5);
  59.995 +  }
  59.996 +} break;
  59.997 +case 219 : 
  59.998 +{
  59.999 +  P1 = IC(2);
 59.1000 +  P2 = IC(2);
 59.1001 +  if (MDR) {
 59.1002 +    P3 = IC(2);
 59.1003 +  } else {
 59.1004 +    P3 = I211(2, 5, 7);
 59.1005 +  }
 59.1006 +  if (MUL) {
 59.1007 +    P0 = IC(2);
 59.1008 +  } else {
 59.1009 +    P0 = I211(2, 1, 3);
 59.1010 +  }
 59.1011 +} break;
 59.1012 +case 220 : 
 59.1013 +{
 59.1014 +  P0 = IC(0);
 59.1015 +  P1 = IC(0);
 59.1016 +  if (MDL) {
 59.1017 +    P2 = IC(0);
 59.1018 +  } else {
 59.1019 +    P2 = I611(0, 3, 7);
 59.1020 +  }
 59.1021 +  if (MDR) {
 59.1022 +    P3 = IC(0);
 59.1023 +  } else {
 59.1024 +    P3 = I211(0, 5, 7);
 59.1025 +  }
 59.1026 +} break;
 59.1027 +case 223 : 
 59.1028 +{
 59.1029 +  P2 = IC(4);
 59.1030 +  if (MDR) {
 59.1031 +    P3 = IC(4);
 59.1032 +  } else {
 59.1033 +    P3 = I211(4, 5, 7);
 59.1034 +  }
 59.1035 +  if (MUL) {
 59.1036 +    P0 = IC(4);
 59.1037 +  } else {
 59.1038 +    P0 = I211(4, 1, 3);
 59.1039 +  }
 59.1040 +  if (MUR) {
 59.1041 +    P1 = IC(4);
 59.1042 +  } else {
 59.1043 +    P1 = I1411(4, 1, 5);
 59.1044 +  }
 59.1045 +} break;
 59.1046 +case 233 : 
 59.1047 +case 237 : 
 59.1048 +{
 59.1049 +  P0 = IC(1);
 59.1050 +  P1 = IC(1);
 59.1051 +  P3 = IC(1);
 59.1052 +  if (MDL) {
 59.1053 +    P2 = IC(1);
 59.1054 +  } else {
 59.1055 +    P2 = I1411(1, 3, 7);
 59.1056 +  }
 59.1057 +} break;
 59.1058 +case 234 : 
 59.1059 +{
 59.1060 +  P1 = IC(0);
 59.1061 +  P3 = IC(0);
 59.1062 +  if (MDL) {
 59.1063 +    P2 = IC(0);
 59.1064 +  } else {
 59.1065 +    P2 = I211(0, 3, 7);
 59.1066 +  }
 59.1067 +  if (MUL) {
 59.1068 +    P0 = IC(0);
 59.1069 +  } else {
 59.1070 +    P0 = I611(0, 1, 3);
 59.1071 +  }
 59.1072 +} break;
 59.1073 +case 235 : 
 59.1074 +{
 59.1075 +  P1 = IC(2);
 59.1076 +  P3 = IC(2);
 59.1077 +  if (MDL) {
 59.1078 +    P2 = IC(2);
 59.1079 +  } else {
 59.1080 +    P2 = I1411(2, 3, 7);
 59.1081 +  }
 59.1082 +  if (MUL) {
 59.1083 +    P0 = IC(2);
 59.1084 +  } else {
 59.1085 +    P0 = I211(2, 1, 3);
 59.1086 +  }
 59.1087 +} break;
 59.1088 +case 239 : 
 59.1089 +{
 59.1090 +  P1 = IC(4);
 59.1091 +  P3 = IC(4);
 59.1092 +  if (MDL) {
 59.1093 +    P2 = IC(4);
 59.1094 +  } else {
 59.1095 +    P2 = I1411(4, 3, 7);
 59.1096 +  }
 59.1097 +  if (MUL) {
 59.1098 +    P0 = IC(4);
 59.1099 +  } else {
 59.1100 +    P0 = I1411(4, 1, 3);
 59.1101 +  }
 59.1102 +} break;
 59.1103 +case 242 : 
 59.1104 +{
 59.1105 +  P0 = IC(0);
 59.1106 +  P2 = IC(0);
 59.1107 +  if (MDR) {
 59.1108 +    P3 = IC(0);
 59.1109 +  } else {
 59.1110 +    P3 = I211(0, 5, 7);
 59.1111 +  }
 59.1112 +  if (MUR) {
 59.1113 +    P1 = IC(0);
 59.1114 +  } else {
 59.1115 +    P1 = I611(0, 1, 5);
 59.1116 +  }
 59.1117 +} break;
 59.1118 +case 243 : 
 59.1119 +{
 59.1120 +  P0 = IC(2);
 59.1121 +  P1 = IC(2);
 59.1122 +  if (MDR) {
 59.1123 +    P2 = IC(2);
 59.1124 +    P3 = IC(2);
 59.1125 +  } else {
 59.1126 +    P2 = I31(2, 7);
 59.1127 +    P3 = I332(5, 7, 2);
 59.1128 +  }
 59.1129 +} break;
 59.1130 +case 244 : 
 59.1131 +{
 59.1132 +  P0 = IC(0);
 59.1133 +  P1 = IC(0);
 59.1134 +  P2 = IC(0);
 59.1135 +  if (MDR) {
 59.1136 +    P3 = IC(0);
 59.1137 +  } else {
 59.1138 +    P3 = I1411(0, 5, 7);
 59.1139 +  }
 59.1140 +} break;
 59.1141 +case 245 : 
 59.1142 +{
 59.1143 +  P0 = IC(1);
 59.1144 +  P1 = IC(1);
 59.1145 +  P2 = IC(1);
 59.1146 +  if (MDR) {
 59.1147 +    P3 = IC(1);
 59.1148 +  } else {
 59.1149 +    P3 = I1411(1, 5, 7);
 59.1150 +  }
 59.1151 +} break;
 59.1152 +case 246 : 
 59.1153 +{
 59.1154 +  P0 = IC(0);
 59.1155 +  P2 = IC(0);
 59.1156 +  if (MDR) {
 59.1157 +    P3 = IC(0);
 59.1158 +  } else {
 59.1159 +    P3 = I1411(0, 5, 7);
 59.1160 +  }
 59.1161 +  if (MUR) {
 59.1162 +    P1 = IC(0);
 59.1163 +  } else {
 59.1164 +    P1 = I211(0, 1, 5);
 59.1165 +  }
 59.1166 +} break;
 59.1167 +case 247 : 
 59.1168 +{
 59.1169 +  P0 = IC(3);
 59.1170 +  P2 = IC(3);
 59.1171 +  if (MDR) {
 59.1172 +    P3 = IC(3);
 59.1173 +  } else {
 59.1174 +    P3 = I1411(3, 5, 7);
 59.1175 +  }
 59.1176 +  if (MUR) {
 59.1177 +    P1 = IC(3);
 59.1178 +  } else {
 59.1179 +    P1 = I1411(3, 1, 5);
 59.1180 +  }
 59.1181 +} break;
 59.1182 +case 249 : 
 59.1183 +{
 59.1184 +  P0 = IC(1);
 59.1185 +  P1 = IC(1);
 59.1186 +  if (MDL) {
 59.1187 +    P2 = IC(1);
 59.1188 +  } else {
 59.1189 +    P2 = I1411(1, 3, 7);
 59.1190 +  }
 59.1191 +  if (MDR) {
 59.1192 +    P3 = IC(1);
 59.1193 +  } else {
 59.1194 +    P3 = I211(1, 5, 7);
 59.1195 +  }
 59.1196 +} break;
 59.1197 +case 251 : 
 59.1198 +{
 59.1199 +  P1 = IC(2);
 59.1200 +  if (MDL) {
 59.1201 +    P2 = IC(2);
 59.1202 +  } else {
 59.1203 +    P2 = I1411(2, 3, 7);
 59.1204 +  }
 59.1205 +  if (MDR) {
 59.1206 +    P3 = IC(2);
 59.1207 +  } else {
 59.1208 +    P3 = I211(2, 5, 7);
 59.1209 +  }
 59.1210 +  if (MUL) {
 59.1211 +    P0 = IC(2);
 59.1212 +  } else {
 59.1213 +    P0 = I211(2, 1, 3);
 59.1214 +  }
 59.1215 +} break;
 59.1216 +case 252 : 
 59.1217 +{
 59.1218 +  P0 = IC(0);
 59.1219 +  P1 = IC(0);
 59.1220 +  if (MDL) {
 59.1221 +    P2 = IC(0);
 59.1222 +  } else {
 59.1223 +    P2 = I211(0, 3, 7);
 59.1224 +  }
 59.1225 +  if (MDR) {
 59.1226 +    P3 = IC(0);
 59.1227 +  } else {
 59.1228 +    P3 = I1411(0, 5, 7);
 59.1229 +  }
 59.1230 +} break;
 59.1231 +case 253 : 
 59.1232 +{
 59.1233 +  P0 = IC(1);
 59.1234 +  P1 = IC(1);
 59.1235 +  if (MDL) {
 59.1236 +    P2 = IC(1);
 59.1237 +  } else {
 59.1238 +    P2 = I1411(1, 3, 7);
 59.1239 +  }
 59.1240 +  if (MDR) {
 59.1241 +    P3 = IC(1);
 59.1242 +  } else {
 59.1243 +    P3 = I1411(1, 5, 7);
 59.1244 +  }
 59.1245 +} break;
 59.1246 +case 254 : 
 59.1247 +{
 59.1248 +  P0 = IC(0);
 59.1249 +  if (MDL) {
 59.1250 +    P2 = IC(0);
 59.1251 +  } else {
 59.1252 +    P2 = I211(0, 3, 7);
 59.1253 +  }
 59.1254 +  if (MDR) {
 59.1255 +    P3 = IC(0);
 59.1256 +  } else {
 59.1257 +    P3 = I1411(0, 5, 7);
 59.1258 +  }
 59.1259 +  if (MUR) {
 59.1260 +    P1 = IC(0);
 59.1261 +  } else {
 59.1262 +    P1 = I211(0, 1, 5);
 59.1263 +  }
 59.1264 +} break;
 59.1265 +case 255 : 
 59.1266 +{
 59.1267 +  if (MDL) {
 59.1268 +    P2 = IC(4);
 59.1269 +  } else {
 59.1270 +    P2 = I1411(4, 3, 7);
 59.1271 +  }
 59.1272 +  if (MDR) {
 59.1273 +    P3 = IC(4);
 59.1274 +  } else {
 59.1275 +    P3 = I1411(4, 5, 7);
 59.1276 +  }
 59.1277 +  if (MUL) {
 59.1278 +    P0 = IC(4);
 59.1279 +  } else {
 59.1280 +    P0 = I1411(4, 1, 3);
 59.1281 +  }
 59.1282 +  if (MUR) {
 59.1283 +    P1 = IC(4);
 59.1284 +  } else {
 59.1285 +    P1 = I1411(4, 1, 5);
 59.1286 +  }
 59.1287 +} break;
    60.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    60.2 +++ b/src/filters/motionblur.cpp	Sat Mar 03 10:31:27 2012 -0600
    60.3 @@ -0,0 +1,183 @@
    60.4 +#include "../Port.h"
    60.5 +
    60.6 +extern u32 RGB_LOW_BITS_MASK;
    60.7 +
    60.8 +void MotionBlur(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
    60.9 +                u8 *dstPtr, u32 dstPitch, int width, int height)
   60.10 +{
   60.11 +	u8 *nextLine, *finish;
   60.12 +	u32 colorMask	 = ~(RGB_LOW_BITS_MASK | (RGB_LOW_BITS_MASK << 16));
   60.13 +	u32 lowPixelMask = RGB_LOW_BITS_MASK;
   60.14 +
   60.15 +	nextLine = dstPtr + dstPitch;
   60.16 +
   60.17 +	do
   60.18 +	{
   60.19 +		u32 *bP = (u32 *) srcPtr;
   60.20 +		u32 *xP = (u32 *) deltaPtr;
   60.21 +		u32 *dP = (u32 *) dstPtr;
   60.22 +		u32 *nL = (u32 *) nextLine;
   60.23 +		u32	 currentPixel;
   60.24 +		u32	 nextPixel;
   60.25 +		u32	 currentDelta;
   60.26 +		u32	 nextDelta;
   60.27 +
   60.28 +		finish	  = (u8 *) bP + ((width + 2) << 1);
   60.29 +		nextPixel = *bP++;
   60.30 +		nextDelta = *xP++;
   60.31 +
   60.32 +		do
   60.33 +		{
   60.34 +			currentPixel = nextPixel;
   60.35 +			currentDelta = nextDelta;
   60.36 +			nextPixel	 = *bP++;
   60.37 +			nextDelta	 = *xP++;
   60.38 +
   60.39 +			if (currentPixel != currentDelta)
   60.40 +			{
   60.41 +				u32 colorA, product, colorB;
   60.42 +
   60.43 +				*(xP - 2) = currentPixel;
   60.44 +#ifdef WORDS_BIGENDIAN
   60.45 +				colorA = currentPixel >> 16;
   60.46 +				colorB = currentDelta >> 16;
   60.47 +#else
   60.48 +				colorA = currentPixel & 0xffff;
   60.49 +				colorB = currentDelta & 0xffff;
   60.50 +#endif
   60.51 +
   60.52 +				product =   ((((colorA & colorMask) >> 1) +
   60.53 +				              ((colorB & colorMask) >> 1) +
   60.54 +				              (colorA & colorB & lowPixelMask)));
   60.55 +
   60.56 +				*(dP) = product | product << 16;
   60.57 +				*(nL) = product | product << 16;
   60.58 +
   60.59 +#ifdef WORDS_BIGENDIAN
   60.60 +				colorA = (currentPixel & 0xffff);
   60.61 +				colorB = (currentDelta & 0xffff);
   60.62 +#else
   60.63 +				colorA = currentPixel >> 16;
   60.64 +				colorB = currentDelta >> 16;
   60.65 +#endif
   60.66 +				product = ((((colorA & colorMask) >> 1) +
   60.67 +				            ((colorB & colorMask) >> 1) +
   60.68 +				            (colorA & colorB & lowPixelMask)));
   60.69 +
   60.70 +				*(dP + 1) = product | product << 16;
   60.71 +				*(nL + 1) = product | product << 16;
   60.72 +			}
   60.73 +			else
   60.74 +			{
   60.75 +				u32 colorA, product;
   60.76 +
   60.77 +				*(xP - 2) = currentPixel;
   60.78 +#ifdef WORDS_BIGENDIAN
   60.79 +				colorA = currentPixel >> 16;
   60.80 +#else
   60.81 +				colorA = currentPixel & 0xffff;
   60.82 +#endif
   60.83 +
   60.84 +				product = colorA;
   60.85 +
   60.86 +				*(dP) = product | product << 16;
   60.87 +				*(nL) = product | product << 16;
   60.88 +#ifdef WORDS_BIGENDIAN
   60.89 +				colorA = (currentPixel & 0xffff);
   60.90 +#else
   60.91 +				colorA = currentPixel >> 16;
   60.92 +#endif
   60.93 +				product = colorA;
   60.94 +
   60.95 +				*(dP + 1) = product | product << 16;
   60.96 +				*(nL + 1) = product | product << 16;
   60.97 +			}
   60.98 +
   60.99 +			dP += 2;
  60.100 +			nL += 2;
  60.101 +		}
  60.102 +		while ((u8 *) bP < finish);
  60.103 +
  60.104 +		deltaPtr += srcPitch;
  60.105 +		srcPtr	 += srcPitch;
  60.106 +		dstPtr	 += dstPitch << 1;
  60.107 +		nextLine += dstPitch << 1;
  60.108 +	}
  60.109 +	while (--height);
  60.110 +}
  60.111 +
  60.112 +void MotionBlur32(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
  60.113 +                  u8 *dstPtr, u32 dstPitch, int width, int height)
  60.114 +{
  60.115 +	u8 *nextLine, *finish;
  60.116 +	u32 colorMask	 = ~RGB_LOW_BITS_MASK;
  60.117 +	u32 lowPixelMask = RGB_LOW_BITS_MASK;
  60.118 +
  60.119 +	nextLine = dstPtr + dstPitch;
  60.120 +
  60.121 +	do
  60.122 +	{
  60.123 +		u32 *bP = (u32 *) srcPtr;
  60.124 +		u32 *xP = (u32 *) deltaPtr;
  60.125 +		u32 *dP = (u32 *) dstPtr;
  60.126 +		u32 *nL = (u32 *) nextLine;
  60.127 +		u32	 currentPixel;
  60.128 +		u32	 nextPixel;
  60.129 +		u32	 currentDelta;
  60.130 +		u32	 nextDelta;
  60.131 +
  60.132 +		finish	  = (u8 *) bP + ((width + 1) << 2);
  60.133 +		nextPixel = *bP++;
  60.134 +		nextDelta = *xP++;
  60.135 +
  60.136 +		do
  60.137 +		{
  60.138 +			currentPixel = nextPixel;
  60.139 +			currentDelta = nextDelta;
  60.140 +			nextPixel	 = *bP++;
  60.141 +			nextDelta	 = *xP++;
  60.142 +
  60.143 +			u32 colorA, product, colorB;
  60.144 +
  60.145 +			*(xP - 2) = currentPixel;
  60.146 +			colorA	  = currentPixel;
  60.147 +			colorB	  = currentDelta;
  60.148 +
  60.149 +			product =   ((((colorA & colorMask) >> 1) +
  60.150 +			              ((colorB & colorMask) >> 1) +
  60.151 +			              (colorA & colorB & lowPixelMask)));
  60.152 +
  60.153 +			*(dP)	  = product;
  60.154 +			*(dP + 1) = product;
  60.155 +			*(nL)	  = product;
  60.156 +			*(nL + 1) = product;
  60.157 +
  60.158 +			*(xP - 1) = nextPixel;
  60.159 +
  60.160 +			colorA = nextPixel;
  60.161 +			colorB = nextDelta;
  60.162 +
  60.163 +			product = ((((colorA & colorMask) >> 1) +
  60.164 +			            ((colorB & colorMask) >> 1) +
  60.165 +			            (colorA & colorB & lowPixelMask)));
  60.166 +
  60.167 +			*(dP + 2) = product;
  60.168 +			*(dP + 3) = product;
  60.169 +			*(nL + 2) = product;
  60.170 +			*(nL + 3) = product;
  60.171 +
  60.172 +			nextPixel = *bP++;
  60.173 +			nextDelta = *xP++;
  60.174 +
  60.175 +			dP += 4;
  60.176 +			nL += 4;
  60.177 +		}
  60.178 +		while ((u8 *) bP < finish);
  60.179 +
  60.180 +		deltaPtr += srcPitch;
  60.181 +		srcPtr	 += srcPitch;
  60.182 +		dstPtr	 += dstPitch << 1;
  60.183 +		nextLine += dstPitch << 1;
  60.184 +	}
  60.185 +	while (--height);
  60.186 +}
    61.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    61.2 +++ b/src/filters/pixel.cpp	Sat Mar 03 10:31:27 2012 -0600
    61.3 @@ -0,0 +1,196 @@
    61.4 +#include "../Port.h"
    61.5 +
    61.6 +extern u32 RGB_LOW_BITS_MASK;
    61.7 +
    61.8 +void Pixelate2x16(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
    61.9 +                  u8 *dstPtr, u32 dstPitch, int width, int height)
   61.10 +{
   61.11 +	u8 *nextLine, *finish;
   61.12 +	u32 colorMask = ~(RGB_LOW_BITS_MASK | (RGB_LOW_BITS_MASK << 16));
   61.13 +	colorMask = (colorMask >> 2) & (colorMask >> 1);
   61.14 +
   61.15 +	nextLine = dstPtr + dstPitch;
   61.16 +
   61.17 +	do
   61.18 +	{
   61.19 +		u32 *bP = (u32 *) srcPtr;
   61.20 +		u32 *xP = (u32 *) deltaPtr;
   61.21 +		u32 *dP = (u32 *) dstPtr;
   61.22 +		u32 *nL = (u32 *) nextLine;
   61.23 +		u32  currentPixel;
   61.24 +		u32  nextPixel;
   61.25 +		u32  currentDelta;
   61.26 +		u32  nextDelta;
   61.27 +
   61.28 +		finish    = (u8 *) bP + ((width+2) << 1);
   61.29 +		nextPixel = *bP++;
   61.30 +		nextDelta = *xP++;
   61.31 +
   61.32 +		do
   61.33 +		{
   61.34 +			currentPixel = nextPixel;
   61.35 +			currentDelta = nextDelta;
   61.36 +			nextPixel    = *bP++;
   61.37 +			nextDelta    = *xP++;
   61.38 +
   61.39 +			if ((nextPixel != nextDelta) || (currentPixel != currentDelta))
   61.40 +			{
   61.41 +				u32 colorA, colorB, product;
   61.42 +
   61.43 +				*(xP - 2) = currentPixel;
   61.44 +#ifdef WORDS_BIGENDIAN
   61.45 +				colorA = currentPixel >> 16;
   61.46 +				colorB = currentPixel & 0xffff;
   61.47 +#else
   61.48 +				colorA = currentPixel & 0xffff;
   61.49 +				colorB = currentPixel >> 16;
   61.50 +#endif
   61.51 +				product = (colorA >> 2) & colorMask;
   61.52 +
   61.53 +#ifdef WORDS_BIGENDIAN
   61.54 +				*(nL) = (product << 16) | (product);
   61.55 +				*(dP) = (colorA << 16) | product;
   61.56 +#else
   61.57 +				*(nL) = product | (product << 16);
   61.58 +				*(dP) = colorA | (product << 16);
   61.59 +#endif
   61.60 +
   61.61 +#ifdef WORDS_BIGENDIAN
   61.62 +				colorA = nextPixel >> 16;
   61.63 +#else
   61.64 +				colorA = nextPixel & 0xffff;
   61.65 +#endif
   61.66 +				product = (colorB >> 2) & colorMask;
   61.67 +#ifdef WORDS_BIGENDIAN
   61.68 +				*(nL + 1) = (product << 16) | (product);
   61.69 +				*(dP + 1) = (colorB << 16) | (product);
   61.70 +#else
   61.71 +				*(nL + 1) = (product) | (product << 16);
   61.72 +				*(dP + 1) = (colorB) | (product << 16);
   61.73 +#endif
   61.74 +			}
   61.75 +
   61.76 +			dP += 2;
   61.77 +			nL += 2;
   61.78 +		}
   61.79 +		while ((u8 *) bP < finish);
   61.80 +
   61.81 +		deltaPtr += srcPitch;
   61.82 +		srcPtr   += srcPitch;
   61.83 +		dstPtr   += dstPitch << 1;
   61.84 +		nextLine += dstPitch << 1;
   61.85 +	}
   61.86 +	while (--height);
   61.87 +}
   61.88 +
   61.89 +void Pixelate2x32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
   61.90 +                  u8 *dstPtr, u32 dstPitch, int width, int height)
   61.91 +{
   61.92 +	u8 *nextLine, *finish;
   61.93 +	u32 colorMask = ((u32)~RGB_LOW_BITS_MASK >> 2) & ((u32)~RGB_LOW_BITS_MASK >> 1);
   61.94 +
   61.95 +	nextLine = dstPtr + dstPitch;
   61.96 +
   61.97 +	do
   61.98 +	{
   61.99 +		u32 *bP = (u32 *) srcPtr;
  61.100 +		//    u32 *xP = (u32 *) deltaPtr;
  61.101 +		u32 *dP = (u32 *) dstPtr;
  61.102 +		u32 *nL = (u32 *) nextLine;
  61.103 +		u32  currentPixel;
  61.104 +		u32  nextPixel;
  61.105 +
  61.106 +		finish    = (u8 *) bP + ((width+1) << 2);
  61.107 +		nextPixel = *bP++;
  61.108 +
  61.109 +		do
  61.110 +		{
  61.111 +			u32 product;
  61.112 +
  61.113 +			currentPixel = nextPixel;
  61.114 +			nextPixel    = *bP++;
  61.115 +			product = (currentPixel >> 2) & colorMask;
  61.116 +			*(nL)   = product;
  61.117 +			*(nL+1) = product;
  61.118 +			*(dP)   = currentPixel;
  61.119 +			*(dP+1) = product;
  61.120 +
  61.121 +			currentPixel = nextPixel;
  61.122 +			nextPixel = *bP++;
  61.123 +			product   = (currentPixel >> 2) & colorMask;
  61.124 +			*(nL + 2) = product;
  61.125 +			*(nL + 3) = product;
  61.126 +			*(dP + 2) = currentPixel;
  61.127 +			*(dP + 3) = product;
  61.128 +
  61.129 +			dP += 4;
  61.130 +			nL += 4;
  61.131 +		}
  61.132 +		while ((u8 *) bP < finish);
  61.133 +
  61.134 +		srcPtr   += srcPitch;
  61.135 +		dstPtr   += dstPitch << 1;
  61.136 +		nextLine += dstPitch << 1;
  61.137 +	}
  61.138 +	while (--height);
  61.139 +}
  61.140 +
  61.141 +// generic Pixelate Nx magnification filter
  61.142 +template <int magnification, typename ColorType>
  61.143 +void PixelateNx(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  61.144 +                u8 *dstPtr, u32 dstPitch, int width, int height)
  61.145 +{
  61.146 +	ColorType colorMask = ((ColorType)~RGB_LOW_BITS_MASK >> 2) & ((ColorType)~RGB_LOW_BITS_MASK >> 1);
  61.147 +
  61.148 +	srcPitch      = srcPitch / sizeof(ColorType) - width;
  61.149 +	u32 dstNextP  = dstPitch / sizeof(ColorType);
  61.150 +	u32 dstNextL  = (dstNextP - width) * magnification; // skip to the next magnificated 'line'
  61.151 +	dstNextP     -= magnification;
  61.152 +
  61.153 +	u32 offset    = (dstPitch + sizeof(ColorType)) * magnification - dstPitch;
  61.154 +
  61.155 +	ColorType *src   = (ColorType *)srcPtr;
  61.156 +	ColorType *dst   = (ColorType *)dstPtr;
  61.157 +
  61.158 +	do // per src line
  61.159 +	{
  61.160 +		u8 *finishP = (u8 *)dst + offset;
  61.161 +		for (int x = 0; x < width; ++x) // per pixel in line
  61.162 +		{
  61.163 +			ColorType col    = *src;
  61.164 +			ColorType *dst2  = dst;
  61.165 +			u8 *finishM = (u8 *)(dst + magnification);
  61.166 +
  61.167 +			ColorType product = (col >> 2) & colorMask;
  61.168 +			do
  61.169 +			{
  61.170 +				*dst2 = product;
  61.171 +			} while ((u8 *)++dst2 < finishM);
  61.172 +			dst2    += dstNextP;
  61.173 +			finishM += dstPitch;
  61.174 +			do // dst magnificated pixel
  61.175 +			{
  61.176 +				*dst2++ = product;
  61.177 +				do
  61.178 +				{
  61.179 +					*dst2 = col;
  61.180 +				} while ((u8 *)++dst2 < finishM);
  61.181 +				dst2    += dstNextP;
  61.182 +				finishM += dstPitch;
  61.183 +			} while ((u8 *)dst2 < finishP);
  61.184 +
  61.185 +			++src;
  61.186 +			dst     += magnification;
  61.187 +			finishP += magnification * sizeof(ColorType);
  61.188 +		}
  61.189 +		src += srcPitch;
  61.190 +		dst += dstNextL;
  61.191 +	} while (--height);
  61.192 +}
  61.193 +
  61.194 +typedef void (*PixelateNxFP)(u8*, u32, u8*, u8*, u32, int, int);
  61.195 +
  61.196 +PixelateNxFP Pixelate3x16 = PixelateNx<3, u16>;
  61.197 +PixelateNxFP Pixelate3x32 = PixelateNx<3, u32>;
  61.198 +PixelateNxFP Pixelate4x16 = PixelateNx<4, u16>;
  61.199 +PixelateNxFP Pixelate4x32 = PixelateNx<4, u32>;
    62.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    62.2 +++ b/src/filters/scanline.cpp	Sat Mar 03 10:31:27 2012 -0600
    62.3 @@ -0,0 +1,225 @@
    62.4 +#include "../Port.h"
    62.5 +
    62.6 +extern u32 RGB_LOW_BITS_MASK;
    62.7 +
    62.8 +void Scanlines(u8 *srcPtr, u32 srcPitch, u8 *,
    62.9 +               u8 *dstPtr, u32 dstPitch, int width, int height)
   62.10 +{
   62.11 +	u8 *nextLine, *finish;
   62.12 +
   62.13 +	nextLine = dstPtr + dstPitch;
   62.14 +
   62.15 +	do
   62.16 +	{
   62.17 +		u32 *bP = (u32 *) srcPtr;
   62.18 +		u32 *dP = (u32 *) dstPtr;
   62.19 +		u32 *nL = (u32 *) nextLine;
   62.20 +		u32	 currentPixel;
   62.21 +		u32	 nextPixel;
   62.22 +
   62.23 +		finish	  = (u8 *) bP + ((width + 2) << 1);
   62.24 +		nextPixel = *bP++;
   62.25 +
   62.26 +		do
   62.27 +		{
   62.28 +			currentPixel = nextPixel;
   62.29 +			nextPixel	 = *bP++;
   62.30 +			u32 colorA, colorB;
   62.31 +
   62.32 +#ifdef WORDS_BIGENDIAN
   62.33 +			colorA = currentPixel >> 16;
   62.34 +			colorB = currentPixel & 0xffff;
   62.35 +#else
   62.36 +			colorA = currentPixel & 0xffff;
   62.37 +			colorB = currentPixel >> 16;
   62.38 +#endif
   62.39 +
   62.40 +			*(dP) = colorA | colorA << 16;
   62.41 +			*(nL) = 0;
   62.42 +
   62.43 +#ifdef WORDS_BIGENDIAN
   62.44 +			colorA = nextPixel >> 16;
   62.45 +#else
   62.46 +			colorA = nextPixel & 0xffff;
   62.47 +#endif
   62.48 +
   62.49 +			*(dP + 1) = colorB | (colorB << 16);
   62.50 +			*(nL + 1) = 0;
   62.51 +
   62.52 +			dP += 2;
   62.53 +			nL += 2;
   62.54 +		}
   62.55 +		while ((u8 *) bP < finish);
   62.56 +
   62.57 +		srcPtr	 += srcPitch;
   62.58 +		dstPtr	 += dstPitch << 1;
   62.59 +		nextLine += dstPitch << 1;
   62.60 +	}
   62.61 +	while (--height);
   62.62 +}
   62.63 +
   62.64 +void Scanlines32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
   62.65 +                 u8 *dstPtr, u32 dstPitch, int width, int height)
   62.66 +{
   62.67 +	u8 *nextLine, *finish;
   62.68 +
   62.69 +	nextLine = dstPtr + dstPitch;
   62.70 +
   62.71 +	do
   62.72 +	{
   62.73 +		u32 *bP = (u32 *) srcPtr;
   62.74 +		u32 *dP = (u32 *) dstPtr;
   62.75 +		u32 *nL = (u32 *) nextLine;
   62.76 +		u32	 currentPixel;
   62.77 +		u32	 nextPixel;
   62.78 +
   62.79 +		finish	  = (u8 *) bP + ((width + 1) << 2);
   62.80 +		nextPixel = *bP++;
   62.81 +
   62.82 +		do
   62.83 +		{
   62.84 +			currentPixel = nextPixel;
   62.85 +			nextPixel	 = *bP++;
   62.86 +
   62.87 +			u32 colorA, colorB;
   62.88 +
   62.89 +			colorA = currentPixel;
   62.90 +			colorB = nextPixel;
   62.91 +
   62.92 +			*(dP)	  = colorA;
   62.93 +			*(dP + 1) = colorA;
   62.94 +			*(nL)	  = 0;
   62.95 +			*(nL + 1) = 0;
   62.96 +
   62.97 +			*(dP + 2) = colorB;
   62.98 +			*(dP + 3) = colorB;
   62.99 +			*(nL + 2) = 0;
  62.100 +			*(nL + 3) = 0;
  62.101 +
  62.102 +			nextPixel = *bP++;
  62.103 +
  62.104 +			dP += 4;
  62.105 +			nL += 4;
  62.106 +		}
  62.107 +		while ((u8 *) bP < finish);
  62.108 +
  62.109 +		srcPtr	 += srcPitch;
  62.110 +		dstPtr	 += dstPitch << 1;
  62.111 +		nextLine += dstPitch << 1;
  62.112 +	}
  62.113 +	while (--height);
  62.114 +}
  62.115 +
  62.116 +void ScanlinesTV(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  62.117 +                 u8 *dstPtr, u32 dstPitch, int width, int height)
  62.118 +{
  62.119 +	u8 *nextLine, *finish;
  62.120 +	u32 colorMask = ~(RGB_LOW_BITS_MASK | (RGB_LOW_BITS_MASK << 16));
  62.121 +
  62.122 +	nextLine = dstPtr + dstPitch;
  62.123 +
  62.124 +	do
  62.125 +	{
  62.126 +		u32 *bP = (u32 *) srcPtr;
  62.127 +		u32 *dP = (u32 *) dstPtr;
  62.128 +		u32 *nL = (u32 *) nextLine;
  62.129 +		u32	 currentPixel;
  62.130 +		u32	 nextPixel;
  62.131 +
  62.132 +		finish	  = (u8 *) bP + ((width + 2) << 1);
  62.133 +		nextPixel = *bP++;
  62.134 +
  62.135 +		do
  62.136 +		{
  62.137 +			currentPixel = nextPixel;
  62.138 +			nextPixel	 = *bP++;
  62.139 +
  62.140 +			u32 colorA, colorB;
  62.141 +
  62.142 +#ifdef WORDS_BIGENDIAN
  62.143 +			colorA = currentPixel >> 16;
  62.144 +			colorB = currentPixel & 0xFFFF;
  62.145 +#else
  62.146 +			colorA = currentPixel & 0xFFFF;
  62.147 +			colorB = currentPixel >> 16;
  62.148 +#endif
  62.149 +
  62.150 +			*(dP) = colorA = colorA | ((((colorA & colorMask) >> 1) +
  62.151 +			                            ((colorB & colorMask) >> 1))) << 16;
  62.152 +			colorA	= ((colorA & colorMask) >> 1);
  62.153 +			colorA += ((colorA & colorMask) >> 1);
  62.154 +			*(nL)	= colorA;
  62.155 +
  62.156 +			colorA = nextPixel & 0xFFFF;
  62.157 +
  62.158 +			*(dP + 1) = colorB = colorB | ((((colorA & colorMask) >> 1) +
  62.159 +			                                ((colorB & colorMask) >> 1))) << 16;
  62.160 +			colorB	= ((colorB & colorMask) >> 1);
  62.161 +			colorB += ((colorB & colorMask) >> 1);
  62.162 +
  62.163 +			*(nL + 1) = colorB;
  62.164 +
  62.165 +			dP += 2;
  62.166 +			nL += 2;
  62.167 +		}
  62.168 +		while ((u8 *) bP < finish);
  62.169 +
  62.170 +		srcPtr	 += srcPitch;
  62.171 +		dstPtr	 += dstPitch << 1;
  62.172 +		nextLine += dstPitch << 1;
  62.173 +	}
  62.174 +	while (--height);
  62.175 +}
  62.176 +
  62.177 +void ScanlinesTV32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  62.178 +                   u8 *dstPtr, u32 dstPitch, int width, int height)
  62.179 +{
  62.180 +	u8 *nextLine, *finish;
  62.181 +	u32 colorMask = ~RGB_LOW_BITS_MASK;
  62.182 +
  62.183 +	nextLine = dstPtr + dstPitch;
  62.184 +
  62.185 +	do
  62.186 +	{
  62.187 +		u32 *bP = (u32 *) srcPtr;
  62.188 +		u32 *dP = (u32 *) dstPtr;
  62.189 +		u32 *nL = (u32 *) nextLine;
  62.190 +		u32	 currentPixel;
  62.191 +		u32	 nextPixel;
  62.192 +
  62.193 +		finish	  = (u8 *) bP + ((width + 1) << 2);
  62.194 +		nextPixel = *bP++;
  62.195 +
  62.196 +		do
  62.197 +		{
  62.198 +			currentPixel = nextPixel;
  62.199 +			nextPixel	 = *bP++;
  62.200 +
  62.201 +			u32 colorA, colorB, temp;
  62.202 +
  62.203 +			colorA = currentPixel;
  62.204 +			colorB = nextPixel;
  62.205 +
  62.206 +			*(dP)	  = colorA;
  62.207 +			*(dP + 1) = temp = ((colorA & colorMask) >> 1) +
  62.208 +			                   ((colorB & colorMask) >> 1);
  62.209 +			temp	= ((temp & colorMask) >> 1);
  62.210 +			temp   += ((temp & colorMask) >> 1);
  62.211 +			colorA	= ((colorA & colorMask) >> 1);
  62.212 +			colorA += ((colorA & colorMask) >> 1);
  62.213 +
  62.214 +			*(nL)	  = colorA;
  62.215 +			*(nL + 1) = temp;
  62.216 +
  62.217 +			dP += 2;
  62.218 +			nL += 2;
  62.219 +		}
  62.220 +		while ((u8 *) bP < finish);
  62.221 +
  62.222 +		srcPtr	 += srcPitch;
  62.223 +		dstPtr	 += dstPitch << 1;
  62.224 +		nextLine += dstPitch << 1;
  62.225 +	}
  62.226 +	while (--height);
  62.227 +}
  62.228 +
    63.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    63.2 +++ b/src/filters/simple2x.cpp	Sat Mar 03 10:31:27 2012 -0600
    63.3 @@ -0,0 +1,189 @@
    63.4 +#include "../Port.h"
    63.5 +
    63.6 +void Simple2x16(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
    63.7 +                u8 *dstPtr, u32 dstPitch, int width, int height)
    63.8 +{
    63.9 +	u8 *nextLine, *finish;
   63.10 +
   63.11 +	nextLine = dstPtr + dstPitch;
   63.12 +
   63.13 +	do
   63.14 +	{
   63.15 +		u32 *bP = (u32 *) srcPtr;
   63.16 +		u32 *dP = (u32 *) dstPtr;
   63.17 +		u32 *nL = (u32 *) nextLine;
   63.18 +		u32	 currentPixel;
   63.19 +
   63.20 +		finish		 = (u8 *) bP + ((width + 2) << 1);
   63.21 +		currentPixel = *bP++;
   63.22 +
   63.23 +		do
   63.24 +		{
   63.25 +#ifdef WORDS_BIGENDIAN
   63.26 +			u32 color = currentPixel >> 16;
   63.27 +#else
   63.28 +			u32 color = currentPixel & 0xffff;
   63.29 +#endif
   63.30 +
   63.31 +			color = color | (color << 16);
   63.32 +
   63.33 +			*(dP) = color;
   63.34 +			*(nL) = color;
   63.35 +
   63.36 +#ifdef WORDS_BIGENDIAN
   63.37 +			color = currentPixel & 0xffff;
   63.38 +#else
   63.39 +			color = currentPixel >> 16;
   63.40 +#endif
   63.41 +			color	  = color | (color << 16);
   63.42 +			*(dP + 1) = color;
   63.43 +			*(nL + 1) = color;
   63.44 +
   63.45 +			currentPixel = *bP++;
   63.46 +
   63.47 +			dP += 2;
   63.48 +			nL += 2;
   63.49 +		}
   63.50 +		while ((u8 *) bP < finish);
   63.51 +
   63.52 +		srcPtr	 += srcPitch;
   63.53 +		dstPtr	 += dstPitch << 1;
   63.54 +		nextLine += dstPitch << 1;
   63.55 +	}
   63.56 +	while (--height);
   63.57 +}
   63.58 +
   63.59 +void Simple2x32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
   63.60 +                u8 *dstPtr, u32 dstPitch, int width, int height)
   63.61 +{
   63.62 +	u8 *nextLine, *finish;
   63.63 +
   63.64 +	nextLine = dstPtr + dstPitch;
   63.65 +
   63.66 +	do
   63.67 +	{
   63.68 +		u32 *bP = (u32 *) srcPtr;
   63.69 +		u32 *dP = (u32 *) dstPtr;
   63.70 +		u32 *nL = (u32 *) nextLine;
   63.71 +		u32	 currentPixel;
   63.72 +
   63.73 +		finish		 = (u8 *) bP + ((width + 1) << 2);
   63.74 +		currentPixel = *bP++;
   63.75 +
   63.76 +		do
   63.77 +		{
   63.78 +			u32 color = currentPixel;
   63.79 +
   63.80 +			*(dP)	  = color;
   63.81 +			*(dP + 1) = color;
   63.82 +			*(nL)	  = color;
   63.83 +			*(nL + 1) = color;
   63.84 +
   63.85 +			currentPixel = *bP++;
   63.86 +
   63.87 +			dP += 2;
   63.88 +			nL += 2;
   63.89 +		}
   63.90 +		while ((u8 *) bP < finish);
   63.91 +
   63.92 +		srcPtr	 += srcPitch;
   63.93 +		dstPtr	 += dstPitch << 1;
   63.94 +		nextLine += dstPitch << 1;
   63.95 +	}
   63.96 +	while (--height);
   63.97 +}
   63.98 +
   63.99 +#if 0
  63.100 +// generic Simple Nx magnification filter
  63.101 +template <int magnification, typename ColorType>
  63.102 +void SimpleNx(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  63.103 +              u8 *dstPtr, u32 dstPitch, int width, int height)
  63.104 +{
  63.105 +	srcPitch = srcPitch / sizeof(ColorType) - width;
  63.106 +	u32 dstNextP = dstPitch / sizeof(ColorType);
  63.107 +	u32 dstNextL = (dstNextP - width) * magnification;  // skip to the next magnificated 'line'
  63.108 +	dstNextP -= magnification;
  63.109 +
  63.110 +	u32 offset = (dstPitch + sizeof(ColorType)) * magnification - dstPitch;
  63.111 +
  63.112 +	ColorType *src = (ColorType *)srcPtr;
  63.113 +	ColorType *dst = (ColorType *)dstPtr;
  63.114 +
  63.115 +	do // per src line
  63.116 +	{
  63.117 +		u8 *finishP = (u8 *)dst + offset;
  63.118 +		for (int x = 0; x < width; ++x) // per pixel in line
  63.119 +		{
  63.120 +			ColorType  col	   = *src;
  63.121 +			ColorType *dst2	   = dst;
  63.122 +			u8 *	   finishM = (u8 *)(dst + magnification);
  63.123 +			do // dst magnificated pixel
  63.124 +			{
  63.125 +				do
  63.126 +				{
  63.127 +					*dst2 = col;
  63.128 +				}
  63.129 +				while ((u8 *)++dst2 < finishM);
  63.130 +				dst2	+= dstNextP;
  63.131 +				finishM += dstPitch;
  63.132 +			}
  63.133 +			while ((u8 *)dst2 < finishP);
  63.134 +
  63.135 +			++src;
  63.136 +			dst		+= magnification;
  63.137 +			finishP += magnification * sizeof(ColorType);
  63.138 +		}
  63.139 +		src += srcPitch;
  63.140 +		dst += dstNextL;
  63.141 +	}
  63.142 +	while (--height);
  63.143 +}
  63.144 +
  63.145 +#else
  63.146 +
  63.147 +// generic Simple Nx magnification filter
  63.148 +template <int magnification, typename ColorType>
  63.149 +void SimpleNx(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  63.150 +              u8 *dstPtr, u32 dstPitch, int width, int height)
  63.151 +{
  63.152 +	srcPitch  = srcPitch / sizeof(ColorType) - width;
  63.153 +	dstPitch /= sizeof(ColorType);
  63.154 +	u32 dstBlank = (dstPitch - width) * magnification; // skip to the next magnificated 'line'
  63.155 +	dstPitch -= magnification;
  63.156 +
  63.157 +	ColorType *src = (ColorType *)srcPtr;
  63.158 +	ColorType *dst = (ColorType *)dstPtr;
  63.159 +
  63.160 +	do // per src line
  63.161 +	{
  63.162 +		for (int x = 0; x < width; ++x) // per pixel in src line
  63.163 +		{
  63.164 +			ColorType  col	= *src;
  63.165 +			ColorType *dst2 = dst;
  63.166 +			for (int dy = 0; dy < magnification; ++dy) // dst magnificated pixel
  63.167 +			{
  63.168 +				for (int dx = 0; dx < magnification; ++dx)
  63.169 +				{
  63.170 +					*dst2 = col;
  63.171 +					++dst2;
  63.172 +				}
  63.173 +				dst2 += dstPitch;
  63.174 +			}
  63.175 +
  63.176 +			++src;
  63.177 +			dst += magnification;
  63.178 +		}
  63.179 +		src += srcPitch;
  63.180 +		dst += dstBlank;
  63.181 +	}
  63.182 +	while (--height);
  63.183 +}
  63.184 +
  63.185 +#endif
  63.186 +
  63.187 +typedef void (*SimpleNxFP)(u8 *, u32, u8 *, u8 *, u32, int, int);
  63.188 +
  63.189 +SimpleNxFP Simple3x16 = SimpleNx<3, u16>;
  63.190 +SimpleNxFP Simple3x32 = SimpleNx<3, u32>;
  63.191 +SimpleNxFP Simple4x16 = SimpleNx<4, u16>;
  63.192 +SimpleNxFP Simple4x32 = SimpleNx<4, u32>;
    64.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    64.2 +++ b/src/gb/GB.cpp	Sat Mar 03 10:31:27 2012 -0600
    64.3 @@ -0,0 +1,3918 @@
    64.4 +#include <cstdio>
    64.5 +#include <cstdlib>
    64.6 +#include <cstring>
    64.7 +#include <cassert>
    64.8 +
    64.9 +#include "../Port.h"
   64.10 +#include "../NLS.h"
   64.11 +#include "GB.h"
   64.12 +#include "gbCheats.h"
   64.13 +#include "gbGlobals.h"
   64.14 +#include "gbMemory.h"
   64.15 +#include "gbSGB.h"
   64.16 +#include "gbSound.h"
   64.17 +#include "../common/unzip.h"
   64.18 +#include "../common/Util.h"
   64.19 +#include "../common/System.h"
   64.20 +#include "../common/movie.h"
   64.21 +#include "../common/vbalua.h"
   64.22 +
   64.23 +#ifdef __GNUC__
   64.24 +#define _stricmp strcasecmp
   64.25 +#endif
   64.26 +
   64.27 +// FIXME: constant (GB) or boolean (GBA)?!
   64.28 +#define C_FLAG 0x10
   64.29 +#define H_FLAG 0x20
   64.30 +#define N_FLAG 0x40
   64.31 +#define Z_FLAG 0x80
   64.32 +extern soundtick_t GB_USE_TICKS_AS;
   64.33 +
   64.34 +u8 *		 origPix = NULL;
   64.35 +extern u8 *	 pix;
   64.36 +extern u32	 extButtons;
   64.37 +extern bool8 capturePrevious;
   64.38 +extern int32 captureNumber;
   64.39 +extern bool8 speedup;
   64.40 +
   64.41 +bool gbUpdateSizes();
   64.42 +
   64.43 +// debugging
   64.44 +bool memorydebug = false;
   64.45 +char gbBuffer[2048];
   64.46 +
   64.47 +extern u16 gbLineMix[160];
   64.48 +
   64.49 +// mappers
   64.50 +void (*mapper)(u16, u8)	   = NULL;
   64.51 +void (*mapperRAM)(u16, u8) = NULL;
   64.52 +u8	 (*mapperReadRAM)(u16) = NULL;
   64.53 +
   64.54 +// registers
   64.55 +gbRegister PC;
   64.56 +gbRegister SP;
   64.57 +gbRegister AF;
   64.58 +gbRegister BC;
   64.59 +gbRegister DE;
   64.60 +gbRegister HL;
   64.61 +u16		   IFF;
   64.62 +// 0xff04
   64.63 +u8 register_DIV = 0;
   64.64 +// 0xff05
   64.65 +u8 register_TIMA = 0;
   64.66 +// 0xff06
   64.67 +u8 register_TMA = 0;
   64.68 +// 0xff07
   64.69 +u8 register_TAC = 0;
   64.70 +// 0xff0f
   64.71 +u8 register_IF = 0;
   64.72 +// 0xff40
   64.73 +u8 register_LCDC = 0;
   64.74 +// 0xff41
   64.75 +u8 register_STAT = 0;
   64.76 +// 0xff42
   64.77 +u8 register_SCY = 0;
   64.78 +// 0xff43
   64.79 +u8 register_SCX = 0;
   64.80 +// 0xff44
   64.81 +u8 register_LY = 0;
   64.82 +// 0xff45
   64.83 +u8 register_LYC = 0;
   64.84 +// 0xff46
   64.85 +u8 register_DMA = 0;
   64.86 +// 0xff4a
   64.87 +u8 register_WY = 0;
   64.88 +// 0xff4b
   64.89 +u8 register_WX = 0;
   64.90 +// 0xff4f
   64.91 +u8 register_VBK = 0;
   64.92 +// 0xff51
   64.93 +u8 register_HDMA1 = 0;
   64.94 +// 0xff52
   64.95 +u8 register_HDMA2 = 0;
   64.96 +// 0xff53
   64.97 +u8 register_HDMA3 = 0;
   64.98 +// 0xff54
   64.99 +u8 register_HDMA4 = 0;
  64.100 +// 0xff55
  64.101 +u8 register_HDMA5 = 0;
  64.102 +// 0xff70
  64.103 +u8 register_SVBK = 0;
  64.104 +// 0xffff
  64.105 +u8 register_IE = 0;
  64.106 +
  64.107 +// ticks definition
  64.108 +int32 GBDIV_CLOCK_TICKS = 64;
  64.109 +int32 GBLCD_MODE_0_CLOCK_TICKS	 = 51;
  64.110 +int32 GBLCD_MODE_1_CLOCK_TICKS	 = 1140;
  64.111 +int32 GBLCD_MODE_2_CLOCK_TICKS	 = 20;
  64.112 +int32 GBLCD_MODE_3_CLOCK_TICKS	 = 43;
  64.113 +int32 GBLY_INCREMENT_CLOCK_TICKS = 114;
  64.114 +int32 GBTIMER_MODE_0_CLOCK_TICKS = 256;
  64.115 +int32 GBTIMER_MODE_1_CLOCK_TICKS = 4;
  64.116 +int32 GBTIMER_MODE_2_CLOCK_TICKS = 16;
  64.117 +int32 GBTIMER_MODE_3_CLOCK_TICKS = 64;
  64.118 +int32 GBSERIAL_CLOCK_TICKS		 = 128;
  64.119 +int32 GBSYNCHRONIZE_CLOCK_TICKS	 = 52920;
  64.120 +
  64.121 +// state variables
  64.122 +
  64.123 +// interrupt
  64.124 +int32 gbInterrupt	  = 0;
  64.125 +int32 gbInterruptWait = 0;
  64.126 +// serial
  64.127 +int32 gbSerialOn	= 0;
  64.128 +int32 gbSerialTicks = 0;
  64.129 +int32 gbSerialBits	= 0;
  64.130 +// timer
  64.131 +int32 gbTimerOn			= 0;
  64.132 +int32 gbTimerTicks		= 0;
  64.133 +int32 gbTimerClockTicks = 0;
  64.134 +int32 gbTimerMode		= 0;
  64.135 +// lcd
  64.136 +int32 gbLcdMode	 = 2;
  64.137 +int32 gbLcdTicks = GBLCD_MODE_2_CLOCK_TICKS;
  64.138 +int32 gbLcdLYIncrementTicks = 0;
  64.139 +// div
  64.140 +int32 gbDivTicks = GBDIV_CLOCK_TICKS;
  64.141 +// cgb
  64.142 +int32 gbVramBank		= 0;
  64.143 +int32 gbWramBank		= 1;
  64.144 +int32 gbHdmaSource		= 0x0000;
  64.145 +int32 gbHdmaDestination = 0x8000;
  64.146 +int32 gbHdmaBytes		= 0x0000;
  64.147 +int32 gbHdmaOn = 0;
  64.148 +int32 gbSpeed  = 0;
  64.149 +// frame counting
  64.150 +int32 gbFrameCount	   = 0;
  64.151 +int32 gbFrameSkip	   = 0;
  64.152 +int32 gbFrameSkipCount = 0;
  64.153 +// timing
  64.154 +u32	  gbLastTime		 = 0;
  64.155 +u32	  gbElapsedTime		 = 0;
  64.156 +u32	  gbTimeNow			 = 0;
  64.157 +int32 gbSynchronizeTicks = GBSYNCHRONIZE_CLOCK_TICKS;
  64.158 +int32 gbDMASpeedVersion	 = 1;
  64.159 +// emulator features
  64.160 +int32 gbBattery	   = 0;
  64.161 +int32 gbJoymask[4] = { 0, 0, 0, 0 };
  64.162 +
  64.163 +int32 gbEchoRAMFixOn = 1;
  64.164 +
  64.165 +static bool newFrame = true;
  64.166 +static bool pauseAfterFrameAdvance = false;
  64.167 +
  64.168 +int32 gbRomSizes[] = { 0x00008000, // 32K
  64.169 +	                   0x00010000, // 64K
  64.170 +	                   0x00020000, // 128K
  64.171 +	                   0x00040000, // 256K
  64.172 +	                   0x00080000, // 512K
  64.173 +	                   0x00100000, // 1024K
  64.174 +	                   0x00200000, // 2048K
  64.175 +	                   0x00400000, // 4096K
  64.176 +	                   0x00800000 // 8192K
  64.177 +};
  64.178 +int32 gbRomSizesMasks[] = { 0x00007fff,
  64.179 +	                        0x0000ffff,
  64.180 +	                        0x0001ffff,
  64.181 +	                        0x0003ffff,
  64.182 +	                        0x0007ffff,
  64.183 +	                        0x000fffff,
  64.184 +	                        0x001fffff,
  64.185 +	                        0x003fffff,
  64.186 +	                        0x007fffff };
  64.187 +
  64.188 +int32 gbRamSizes[6] = { 0x00000000, // 0K
  64.189 +	                    0x00000800, // 2K
  64.190 +	                    0x00002000, // 8K
  64.191 +	                    0x00008000, // 32K
  64.192 +	                    0x00020000, // 128K
  64.193 +	                    0x00010000 // 64K
  64.194 +};
  64.195 +
  64.196 +int32 gbRamSizesMasks[6] = { 0x00000000,
  64.197 +	                         0x000007ff,
  64.198 +	                         0x00001fff,
  64.199 +	                         0x00007fff,
  64.200 +	                         0x0001ffff,
  64.201 +	                         0x0000ffff };
  64.202 +
  64.203 +int32 gbCycles[] =
  64.204 +{
  64.205 +//  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
  64.206 +	1, 3, 2, 2, 1, 1, 2, 1, 5, 2, 2, 2, 1, 1, 2, 1,  // 0
  64.207 +	1, 3, 2, 2, 1, 1, 2, 1, 3, 2, 2, 2, 1, 1, 2, 1,  // 1
  64.208 +	2, 3, 2, 2, 1, 1, 2, 1, 2, 2, 2, 2, 1, 1, 2, 1,  // 2
  64.209 +	2, 3, 2, 2, 3, 3, 3, 1, 2, 2, 2, 2, 1, 1, 2, 1,  // 3
  64.210 +	1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1,  // 4
  64.211 +	1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1,  // 5
  64.212 +	1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1,  // 6
  64.213 +	2, 2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1,  // 7
  64.214 +	1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1,  // 8
  64.215 +	1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1,  // 9
  64.216 +	1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1,  // a
  64.217 +	1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1,  // b
  64.218 +	2, 3, 3, 4, 3, 4, 2, 4, 2, 4, 3, 2, 3, 6, 2, 4,  // c
  64.219 +	2, 3, 3, 0, 3, 4, 2, 4, 2, 4, 3, 0, 3, 0, 2, 4,  // d
  64.220 +	3, 3, 2, 0, 0, 4, 2, 4, 4, 1, 4, 0, 0, 0, 2, 4,  // e
  64.221 +	3, 3, 2, 1, 0, 4, 2, 4, 3, 2, 4, 1, 0, 0, 2, 4   // f
  64.222 +};
  64.223 +
  64.224 +int32 gbCyclesCB[] =
  64.225 +{
  64.226 +//  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
  64.227 +	2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 4, 2,  // 0
  64.228 +	2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 4, 2,  // 1
  64.229 +	2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 4, 2,  // 2
  64.230 +	2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 4, 2,  // 3
  64.231 +	2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2,  // 4
  64.232 +	2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2,  // 5
  64.233 +	2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2,  // 6
  64.234 +	2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2,  // 7
  64.235 +	2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2,  // 8
  64.236 +	2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2,  // 9
  64.237 +	2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2,  // a
  64.238 +	2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2,  // b
  64.239 +	2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2,  // c
  64.240 +	2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2,  // d
  64.241 +	2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2,  // e
  64.242 +	2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2   // f
  64.243 +};
  64.244 +
  64.245 +u16 DAATable[] =
  64.246 +{
  64.247 +	0x0080, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, 0x0700,
  64.248 +	0x0800, 0x0900, 0x1020, 0x1120, 0x1220, 0x1320, 0x1420, 0x1520,
  64.249 +	0x1000, 0x1100, 0x1200, 0x1300, 0x1400, 0x1500, 0x1600, 0x1700,
  64.250 +	0x1800, 0x1900, 0x2020, 0x2120, 0x2220, 0x2320, 0x2420, 0x2520,
  64.251 +	0x2000, 0x2100, 0x2200, 0x2300, 0x2400, 0x2500, 0x2600, 0x2700,
  64.252 +	0x2800, 0x2900, 0x3020, 0x3120, 0x3220, 0x3320, 0x3420, 0x3520,
  64.253 +	0x3000, 0x3100, 0x3200, 0x3300, 0x3400, 0x3500, 0x3600, 0x3700,
  64.254 +	0x3800, 0x3900, 0x4020, 0x4120, 0x4220, 0x4320, 0x4420, 0x4520,
  64.255 +	0x4000, 0x4100, 0x4200, 0x4300, 0x4400, 0x4500, 0x4600, 0x4700,
  64.256 +	0x4800, 0x4900, 0x5020, 0x5120, 0x5220, 0x5320, 0x5420, 0x5520,
  64.257 +	0x5000, 0x5100, 0x5200, 0x5300, 0x5400, 0x5500, 0x5600, 0x5700,
  64.258 +	0x5800, 0x5900, 0x6020, 0x6120, 0x6220, 0x6320, 0x6420, 0x6520,
  64.259 +	0x6000, 0x6100, 0x6200, 0x6300, 0x6400, 0x6500, 0x6600, 0x6700,
  64.260 +	0x6800, 0x6900, 0x7020, 0x7120, 0x7220, 0x7320, 0x7420, 0x7520,
  64.261 +	0x7000, 0x7100, 0x7200, 0x7300, 0x7400, 0x7500, 0x7600, 0x7700,
  64.262 +	0x7800, 0x7900, 0x8020, 0x8120, 0x8220, 0x8320, 0x8420, 0x8520,
  64.263 +	0x8000, 0x8100, 0x8200, 0x8300, 0x8400, 0x8500, 0x8600, 0x8700,
  64.264 +	0x8800, 0x8900, 0x9020, 0x9120, 0x9220, 0x9320, 0x9420, 0x9520,
  64.265 +	0x9000, 0x9100, 0x9200, 0x9300, 0x9400, 0x9500, 0x9600, 0x9700,
  64.266 +	0x9800, 0x9900, 0x00B0, 0x0130, 0x0230, 0x0330, 0x0430, 0x0530,
  64.267 +	0x0090, 0x0110, 0x0210, 0x0310, 0x0410, 0x0510, 0x0610, 0x0710,
  64.268 +	0x0810, 0x0910, 0x1030, 0x1130, 0x1230, 0x1330, 0x1430, 0x1530,
  64.269 +	0x1010, 0x1110, 0x1210, 0x1310, 0x1410, 0x1510, 0x1610, 0x1710,
  64.270 +	0x1810, 0x1910, 0x2030, 0x2130, 0x2230, 0x2330, 0x2430, 0x2530,
  64.271 +	0x2010, 0x2110, 0x2210, 0x2310, 0x2410, 0x2510, 0x2610, 0x2710,
  64.272 +	0x2810, 0x2910, 0x3030, 0x3130, 0x3230, 0x3330, 0x3430, 0x3530,
  64.273 +	0x3010, 0x3110, 0x3210, 0x3310, 0x3410, 0x3510, 0x3610, 0x3710,
  64.274 +	0x3810, 0x3910, 0x4030, 0x4130, 0x4230, 0x4330, 0x4430, 0x4530,
  64.275 +	0x4010, 0x4110, 0x4210, 0x4310, 0x4410, 0x4510, 0x4610, 0x4710,
  64.276 +	0x4810, 0x4910, 0x5030, 0x5130, 0x5230, 0x5330, 0x5430, 0x5530,
  64.277 +	0x5010, 0x5110, 0x5210, 0x5310, 0x5410, 0x5510, 0x5610, 0x5710,
  64.278 +	0x5810, 0x5910, 0x6030, 0x6130, 0x6230, 0x6330, 0x6430, 0x6530,
  64.279 +	0x6010, 0x6110, 0x6210, 0x6310, 0x6410, 0x6510, 0x6610, 0x6710,
  64.280 +	0x6810, 0x6910, 0x7030, 0x7130, 0x7230, 0x7330, 0x7430, 0x7530,
  64.281 +	0x7010, 0x7110, 0x7210, 0x7310, 0x7410, 0x7510, 0x7610, 0x7710,
  64.282 +	0x7810, 0x7910, 0x8030, 0x8130, 0x8230, 0x8330, 0x8430, 0x8530,
  64.283 +	0x8010, 0x8110, 0x8210, 0x8310, 0x8410, 0x8510, 0x8610, 0x8710,
  64.284 +	0x8810, 0x8910, 0x9030, 0x9130, 0x9230, 0x9330, 0x9430, 0x9530,
  64.285 +	0x9010, 0x9110, 0x9210, 0x9310, 0x9410, 0x9510, 0x9610, 0x9710,
  64.286 +	0x9810, 0x9910, 0xA030, 0xA130, 0xA230, 0xA330, 0xA430, 0xA530,
  64.287 +	0xA010, 0xA110, 0xA210, 0xA310, 0xA410, 0xA510, 0xA610, 0xA710,
  64.288 +	0xA810, 0xA910, 0xB030, 0xB130, 0xB230, 0xB330, 0xB430, 0xB530,
  64.289 +	0xB010, 0xB110, 0xB210, 0xB310, 0xB410, 0xB510, 0xB610, 0xB710,
  64.290 +	0xB810, 0xB910, 0xC030, 0xC130, 0xC230, 0xC330, 0xC430, 0xC530,
  64.291 +	0xC010, 0xC110, 0xC210, 0xC310, 0xC410, 0xC510, 0xC610, 0xC710,
  64.292 +	0xC810, 0xC910, 0xD030, 0xD130, 0xD230, 0xD330, 0xD430, 0xD530,
  64.293 +	0xD010, 0xD110, 0xD210, 0xD310, 0xD410, 0xD510, 0xD610, 0xD710,
  64.294 +	0xD810, 0xD910, 0xE030, 0xE130, 0xE230, 0xE330, 0xE430, 0xE530,
  64.295 +	0xE010, 0xE110, 0xE210, 0xE310, 0xE410, 0xE510, 0xE610, 0xE710,
  64.296 +	0xE810, 0xE910, 0xF030, 0xF130, 0xF230, 0xF330, 0xF430, 0xF530,
  64.297 +	0xF010, 0xF110, 0xF210, 0xF310, 0xF410, 0xF510, 0xF610, 0xF710,
  64.298 +	0xF810, 0xF910, 0x00B0, 0x0130, 0x0230, 0x0330, 0x0430, 0x0530,
  64.299 +	0x0090, 0x0110, 0x0210, 0x0310, 0x0410, 0x0510, 0x0610, 0x0710,
  64.300 +	0x0810, 0x0910, 0x1030, 0x1130, 0x1230, 0x1330, 0x1430, 0x1530,
  64.301 +	0x1010, 0x1110, 0x1210, 0x1310, 0x1410, 0x1510, 0x1610, 0x1710,
  64.302 +	0x1810, 0x1910, 0x2030, 0x2130, 0x2230, 0x2330, 0x2430, 0x2530,
  64.303 +	0x2010, 0x2110, 0x2210, 0x2310, 0x2410, 0x2510, 0x2610, 0x2710,
  64.304 +	0x2810, 0x2910, 0x3030, 0x3130, 0x3230, 0x3330, 0x3430, 0x3530,
  64.305 +	0x3010, 0x3110, 0x3210, 0x3310, 0x3410, 0x3510, 0x3610, 0x3710,
  64.306 +	0x3810, 0x3910, 0x4030, 0x4130, 0x4230, 0x4330, 0x4430, 0x4530,
  64.307 +	0x4010, 0x4110, 0x4210, 0x4310, 0x4410, 0x4510, 0x4610, 0x4710,
  64.308 +	0x4810, 0x4910, 0x5030, 0x5130, 0x5230, 0x5330, 0x5430, 0x5530,
  64.309 +	0x5010, 0x5110, 0x5210, 0x5310, 0x5410, 0x5510, 0x5610, 0x5710,
  64.310 +	0x5810, 0x5910, 0x6030, 0x6130, 0x6230, 0x6330, 0x6430, 0x6530,
  64.311 +	0x0600, 0x0700, 0x0800, 0x0900, 0x0A00, 0x0B00, 0x0C00, 0x0D00,
  64.312 +	0x0E00, 0x0F00, 0x1020, 0x1120, 0x1220, 0x1320, 0x1420, 0x1520,
  64.313 +	0x1600, 0x1700, 0x1800, 0x1900, 0x1A00, 0x1B00, 0x1C00, 0x1D00,
  64.314 +	0x1E00, 0x1F00, 0x2020, 0x2120, 0x2220, 0x2320, 0x2420, 0x2520,
  64.315 +	0x2600, 0x2700, 0x2800, 0x2900, 0x2A00, 0x2B00, 0x2C00, 0x2D00,
  64.316 +	0x2E00, 0x2F00, 0x3020, 0x3120, 0x3220, 0x3320, 0x3420, 0x3520,
  64.317 +	0x3600, 0x3700, 0x3800, 0x3900, 0x3A00, 0x3B00, 0x3C00, 0x3D00,
  64.318 +	0x3E00, 0x3F00, 0x4020, 0x4120, 0x4220, 0x4320, 0x4420, 0x4520,
  64.319 +	0x4600, 0x4700, 0x4800, 0x4900, 0x4A00, 0x4B00, 0x4C00, 0x4D00,
  64.320 +	0x4E00, 0x4F00, 0x5020, 0x5120, 0x5220, 0x5320, 0x5420, 0x5520,
  64.321 +	0x5600, 0x5700, 0x5800, 0x5900, 0x5A00, 0x5B00, 0x5C00, 0x5D00,
  64.322 +	0x5E00, 0x5F00, 0x6020, 0x6120, 0x6220, 0x6320, 0x6420, 0x6520,
  64.323 +	0x6600, 0x6700, 0x6800, 0x6900, 0x6A00, 0x6B00, 0x6C00, 0x6D00,
  64.324 +	0x6E00, 0x6F00, 0x7020, 0x7120, 0x7220, 0x7320, 0x7420, 0x7520,
  64.325 +	0x7600, 0x7700, 0x7800, 0x7900, 0x7A00, 0x7B00, 0x7C00, 0x7D00,
  64.326 +	0x7E00, 0x7F00, 0x8020, 0x8120, 0x8220, 0x8320, 0x8420, 0x8520,
  64.327 +	0x8600, 0x8700, 0x8800, 0x8900, 0x8A00, 0x8B00, 0x8C00, 0x8D00,
  64.328 +	0x8E00, 0x8F00, 0x9020, 0x9120, 0x9220, 0x9320, 0x9420, 0x9520,
  64.329 +	0x9600, 0x9700, 0x9800, 0x9900, 0x9A00, 0x9B00, 0x9C00, 0x9D00,
  64.330 +	0x9E00, 0x9F00, 0x00B0, 0x0130, 0x0230, 0x0330, 0x0430, 0x0530,
  64.331 +	0x0610, 0x0710, 0x0810, 0x0910, 0x0A10, 0x0B10, 0x0C10, 0x0D10,
  64.332 +	0x0E10, 0x0F10, 0x1030, 0x1130, 0x1230, 0x1330, 0x1430, 0x1530,
  64.333 +	0x1610, 0x1710, 0x1810, 0x1910, 0x1A10, 0x1B10, 0x1C10, 0x1D10,
  64.334 +	0x1E10, 0x1F10, 0x2030, 0x2130, 0x2230, 0x2330, 0x2430, 0x2530,
  64.335 +	0x2610, 0x2710, 0x2810, 0x2910, 0x2A10, 0x2B10, 0x2C10, 0x2D10,
  64.336 +	0x2E10, 0x2F10, 0x3030, 0x3130, 0x3230, 0x3330, 0x3430, 0x3530,
  64.337 +	0x3610, 0x3710, 0x3810, 0x3910, 0x3A10, 0x3B10, 0x3C10, 0x3D10,
  64.338 +	0x3E10, 0x3F10, 0x4030, 0x4130, 0x4230, 0x4330, 0x4430, 0x4530,
  64.339 +	0x4610, 0x4710, 0x4810, 0x4910, 0x4A10, 0x4B10, 0x4C10, 0x4D10,
  64.340 +	0x4E10, 0x4F10, 0x5030, 0x5130, 0x5230, 0x5330, 0x5430, 0x5530,
  64.341 +	0x5610, 0x5710, 0x5810, 0x5910, 0x5A10, 0x5B10, 0x5C10, 0x5D10,
  64.342 +	0x5E10, 0x5F10, 0x6030, 0x6130, 0x6230, 0x6330, 0x6430, 0x6530,
  64.343 +	0x6610, 0x6710, 0x6810, 0x6910, 0x6A10, 0x6B10, 0x6C10, 0x6D10,
  64.344 +	0x6E10, 0x6F10, 0x7030, 0x7130, 0x7230, 0x7330, 0x7430, 0x7530,
  64.345 +	0x7610, 0x7710, 0x7810, 0x7910, 0x7A10, 0x7B10, 0x7C10, 0x7D10,
  64.346 +	0x7E10, 0x7F10, 0x8030, 0x8130, 0x8230, 0x8330, 0x8430, 0x8530,
  64.347 +	0x8610, 0x8710, 0x8810, 0x8910, 0x8A10, 0x8B10, 0x8C10, 0x8D10,
  64.348 +	0x8E10, 0x8F10, 0x9030, 0x9130, 0x9230, 0x9330, 0x9430, 0x9530,
  64.349 +	0x9610, 0x9710, 0x9810, 0x9910, 0x9A10, 0x9B10, 0x9C10, 0x9D10,
  64.350 +	0x9E10, 0x9F10, 0xA030, 0xA130, 0xA230, 0xA330, 0xA430, 0xA530,
  64.351 +	0xA610, 0xA710, 0xA810, 0xA910, 0xAA10, 0xAB10, 0xAC10, 0xAD10,
  64.352 +	0xAE10, 0xAF10, 0xB030, 0xB130, 0xB230, 0xB330, 0xB430, 0xB530,
  64.353 +	0xB610, 0xB710, 0xB810, 0xB910, 0xBA10, 0xBB10, 0xBC10, 0xBD10,
  64.354 +	0xBE10, 0xBF10, 0xC030, 0xC130, 0xC230, 0xC330, 0xC430, 0xC530,
  64.355 +	0xC610, 0xC710, 0xC810, 0xC910, 0xCA10, 0xCB10, 0xCC10, 0xCD10,
  64.356 +	0xCE10, 0xCF10, 0xD030, 0xD130, 0xD230, 0xD330, 0xD430, 0xD530,
  64.357 +	0xD610, 0xD710, 0xD810, 0xD910, 0xDA10, 0xDB10, 0xDC10, 0xDD10,
  64.358 +	0xDE10, 0xDF10, 0xE030, 0xE130, 0xE230, 0xE330, 0xE430, 0xE530,
  64.359 +	0xE610, 0xE710, 0xE810, 0xE910, 0xEA10, 0xEB10, 0xEC10, 0xED10,
  64.360 +	0xEE10, 0xEF10, 0xF030, 0xF130, 0xF230, 0xF330, 0xF430, 0xF530,
  64.361 +	0xF610, 0xF710, 0xF810, 0xF910, 0xFA10, 0xFB10, 0xFC10, 0xFD10,
  64.362 +	0xFE10, 0xFF10, 0x00B0, 0x0130, 0x0230, 0x0330, 0x0430, 0x0530,
  64.363 +	0x0610, 0x0710, 0x0810, 0x0910, 0x0A10, 0x0B10, 0x0C10, 0x0D10,
  64.364 +	0x0E10, 0x0F10, 0x1030, 0x1130, 0x1230, 0x1330, 0x1430, 0x1530,
  64.365 +	0x1610, 0x1710, 0x1810, 0x1910, 0x1A10, 0x1B10, 0x1C10, 0x1D10,
  64.366 +	0x1E10, 0x1F10, 0x2030, 0x2130, 0x2230, 0x2330, 0x2430, 0x2530,
  64.367 +	0x2610, 0x2710, 0x2810, 0x2910, 0x2A10, 0x2B10, 0x2C10, 0x2D10,
  64.368 +	0x2E10, 0x2F10, 0x3030, 0x3130, 0x3230, 0x3330, 0x3430, 0x3530,
  64.369 +	0x3610, 0x3710, 0x3810, 0x3910, 0x3A10, 0x3B10, 0x3C10, 0x3D10,
  64.370 +	0x3E10, 0x3F10, 0x4030, 0x4130, 0x4230, 0x4330, 0x4430, 0x4530,
  64.371 +	0x4610, 0x4710, 0x4810, 0x4910, 0x4A10, 0x4B10, 0x4C10, 0x4D10,
  64.372 +	0x4E10, 0x4F10, 0x5030, 0x5130, 0x5230, 0x5330, 0x5430, 0x5530,
  64.373 +	0x5610, 0x5710, 0x5810, 0x5910, 0x5A10, 0x5B10, 0x5C10, 0x5D10,
  64.374 +	0x5E10, 0x5F10, 0x6030, 0x6130, 0x6230, 0x6330, 0x6430, 0x6530,
  64.375 +	0x00C0, 0x0140, 0x0240, 0x0340, 0x0440, 0x0540, 0x0640, 0x0740,
  64.376 +	0x0840, 0x0940, 0x0440, 0x0540, 0x0640, 0x0740, 0x0840, 0x0940,
  64.377 +	0x1040, 0x1140, 0x1240, 0x1340, 0x1440, 0x1540, 0x1640, 0x1740,
  64.378 +	0x1840, 0x1940, 0x1440, 0x1540, 0x1640, 0x1740, 0x1840, 0x1940,
  64.379 +	0x2040, 0x2140, 0x2240, 0x2340, 0x2440, 0x2540, 0x2640, 0x2740,
  64.380 +	0x2840, 0x2940, 0x2440, 0x2540, 0x2640, 0x2740, 0x2840, 0x2940,
  64.381 +	0x3040, 0x3140, 0x3240, 0x3340, 0x3440, 0x3540, 0x3640, 0x3740,
  64.382 +	0x3840, 0x3940, 0x3440, 0x3540, 0x3640, 0x3740, 0x3840, 0x3940,
  64.383 +	0x4040, 0x4140, 0x4240, 0x4340, 0x4440, 0x4540, 0x4640, 0x4740,
  64.384 +	0x4840, 0x4940, 0x4440, 0x4540, 0x4640, 0x4740, 0x4840, 0x4940,
  64.385 +	0x5040, 0x5140, 0x5240, 0x5340, 0x5440, 0x5540, 0x5640, 0x5740,
  64.386 +	0x5840, 0x5940, 0x5440, 0x5540, 0x5640, 0x5740, 0x5840, 0x5940,
  64.387 +	0x6040, 0x6140, 0x6240, 0x6340, 0x6440, 0x6540, 0x6640, 0x6740,
  64.388 +	0x6840, 0x6940, 0x6440, 0x6540, 0x6640, 0x6740, 0x6840, 0x6940,
  64.389 +	0x7040, 0x7140, 0x7240, 0x7340, 0x7440, 0x7540, 0x7640, 0x7740,
  64.390 +	0x7840, 0x7940, 0x7440, 0x7540, 0x7640, 0x7740, 0x7840, 0x7940,
  64.391 +	0x8040, 0x8140, 0x8240, 0x8340, 0x8440, 0x8540, 0x8640, 0x8740,
  64.392 +	0x8840, 0x8940, 0x8440, 0x8540, 0x8640, 0x8740, 0x8840, 0x8940,
  64.393 +	0x9040, 0x9140, 0x9240, 0x9340, 0x9440, 0x9540, 0x9640, 0x9740,
  64.394 +	0x9840, 0x9940, 0x3450, 0x3550, 0x3650, 0x3750, 0x3850, 0x3950,
  64.395 +	0x4050, 0x4150, 0x4250, 0x4350, 0x4450, 0x4550, 0x4650, 0x4750,
  64.396 +	0x4850, 0x4950, 0x4450, 0x4550, 0x4650, 0x4750, 0x4850, 0x4950,
  64.397 +	0x5050, 0x5150, 0x5250, 0x5350, 0x5450, 0x5550, 0x5650, 0x5750,
  64.398 +	0x5850, 0x5950, 0x5450, 0x5550, 0x5650, 0x5750, 0x5850, 0x5950,
  64.399 +	0x6050, 0x6150, 0x6250, 0x6350, 0x6450, 0x6550, 0x6650, 0x6750,
  64.400 +	0x6850, 0x6950, 0x6450, 0x6550, 0x6650, 0x6750, 0x6850, 0x6950,
  64.401 +	0x7050, 0x7150, 0x7250, 0x7350, 0x7450, 0x7550, 0x7650, 0x7750,
  64.402 +	0x7850, 0x7950, 0x7450, 0x7550, 0x7650, 0x7750, 0x7850, 0x7950,
  64.403 +	0x8050, 0x8150, 0x8250, 0x8350, 0x8450, 0x8550, 0x8650, 0x8750,
  64.404 +	0x8850, 0x8950, 0x8450, 0x8550, 0x8650, 0x8750, 0x8850, 0x8950,
  64.405 +	0x9050, 0x9150, 0x9250, 0x9350, 0x9450, 0x9550, 0x9650, 0x9750,
  64.406 +	0x9850, 0x9950, 0x9450, 0x9550, 0x9650, 0x9750, 0x9850, 0x9950,
  64.407 +	0xA050, 0xA150, 0xA250, 0xA350, 0xA450, 0xA550, 0xA650, 0xA750,
  64.408 +	0xA850, 0xA950, 0xA450, 0xA550, 0xA650, 0xA750, 0xA850, 0xA950,
  64.409 +	0xB050, 0xB150, 0xB250, 0xB350, 0xB450, 0xB550, 0xB650, 0xB750,
  64.410 +	0xB850, 0xB950, 0xB450, 0xB550, 0xB650, 0xB750, 0xB850, 0xB950,
  64.411 +	0xC050, 0xC150, 0xC250, 0xC350, 0xC450, 0xC550, 0xC650, 0xC750,
  64.412 +	0xC850, 0xC950, 0xC450, 0xC550, 0xC650, 0xC750, 0xC850, 0xC950,
  64.413 +	0xD050, 0xD150, 0xD250, 0xD350, 0xD450, 0xD550, 0xD650, 0xD750,
  64.414 +	0xD850, 0xD950, 0xD450, 0xD550, 0xD650, 0xD750, 0xD850, 0xD950,
  64.415 +	0xE050, 0xE150, 0xE250, 0xE350, 0xE450, 0xE550, 0xE650, 0xE750,
  64.416 +	0xE850, 0xE950, 0xE450, 0xE550, 0xE650, 0xE750, 0xE850, 0xE950,
  64.417 +	0xF050, 0xF150, 0xF250, 0xF350, 0xF450, 0xF550, 0xF650, 0xF750,
  64.418 +	0xF850, 0xF950, 0xF450, 0xF550, 0xF650, 0xF750, 0xF850, 0xF950,
  64.419 +	0x00D0, 0x0150, 0x0250, 0x0350, 0x0450, 0x0550, 0x0650, 0x0750,
  64.420 +	0x0850, 0x0950, 0x0450, 0x0550, 0x0650, 0x0750, 0x0850, 0x0950,
  64.421 +	0x1050, 0x1150, 0x1250, 0x1350, 0x1450, 0x1550, 0x1650, 0x1750,
  64.422 +	0x1850, 0x1950, 0x1450, 0x1550, 0x1650, 0x1750, 0x1850, 0x1950,
  64.423 +	0x2050, 0x2150, 0x2250, 0x2350, 0x2450, 0x2550, 0x2650, 0x2750,
  64.424 +	0x2850, 0x2950, 0x2450, 0x2550, 0x2650, 0x2750, 0x2850, 0x2950,
  64.425 +	0x3050, 0x3150, 0x3250, 0x3350, 0x3450, 0x3550, 0x3650, 0x3750,
  64.426 +	0x3850, 0x3950, 0x3450, 0x3550, 0x3650, 0x3750, 0x3850, 0x3950,
  64.427 +	0x4050, 0x4150, 0x4250, 0x4350, 0x4450, 0x4550, 0x4650, 0x4750,
  64.428 +	0x4850, 0x4950, 0x4450, 0x4550, 0x4650, 0x4750, 0x4850, 0x4950,
  64.429 +	0x5050, 0x5150, 0x5250, 0x5350, 0x5450, 0x5550, 0x5650, 0x5750,
  64.430 +	0x5850, 0x5950, 0x5450, 0x5550, 0x5650, 0x5750, 0x5850, 0x5950,
  64.431 +	0x6050, 0x6150, 0x6250, 0x6350, 0x6450, 0x6550, 0x6650, 0x6750,
  64.432 +	0x6850, 0x6950, 0x6450, 0x6550, 0x6650, 0x6750, 0x6850, 0x6950,
  64.433 +	0x7050, 0x7150, 0x7250, 0x7350, 0x7450, 0x7550, 0x7650, 0x7750,
  64.434 +	0x7850, 0x7950, 0x7450, 0x7550, 0x7650, 0x7750, 0x7850, 0x7950,
  64.435 +	0x8050, 0x8150, 0x8250, 0x8350, 0x8450, 0x8550, 0x8650, 0x8750,
  64.436 +	0x8850, 0x8950, 0x8450, 0x8550, 0x8650, 0x8750, 0x8850, 0x8950,
  64.437 +	0x9050, 0x9150, 0x9250, 0x9350, 0x9450, 0x9550, 0x9650, 0x9750,
  64.438 +	0x9850, 0x9950, 0x9450, 0x9550, 0x9650, 0x9750, 0x9850, 0x9950,
  64.439 +	0xFA60, 0xFB60, 0xFC60, 0xFD60, 0xFE60, 0xFF60, 0x00C0, 0x0140,
  64.440 +	0x0240, 0x0340, 0x0440, 0x0540, 0x0640, 0x0740, 0x0840, 0x0940,
  64.441 +	0x0A60, 0x0B60, 0x0C60, 0x0D60, 0x0E60, 0x0F60, 0x1040, 0x1140,
  64.442 +	0x1240, 0x1340, 0x1440, 0x1540, 0x1640, 0x1740, 0x1840, 0x1940,
  64.443 +	0x1A60, 0x1B60, 0x1C60, 0x1D60, 0x1E60, 0x1F60, 0x2040, 0x2140,
  64.444 +	0x2240, 0x2340, 0x2440, 0x2540, 0x2640, 0x2740, 0x2840, 0x2940,
  64.445 +	0x2A60, 0x2B60, 0x2C60, 0x2D60, 0x2E60, 0x2F60, 0x3040, 0x3140,
  64.446 +	0x3240, 0x3340, 0x3440, 0x3540, 0x3640, 0x3740, 0x3840, 0x3940,
  64.447 +	0x3A60, 0x3B60, 0x3C60, 0x3D60, 0x3E60, 0x3F60, 0x4040, 0x4140,
  64.448 +	0x4240, 0x4340, 0x4440, 0x4540, 0x4640, 0x4740, 0x4840, 0x4940,
  64.449 +	0x4A60, 0x4B60, 0x4C60, 0x4D60, 0x4E60, 0x4F60, 0x5040, 0x5140,
  64.450 +	0x5240, 0x5340, 0x5440, 0x5540, 0x5640, 0x5740, 0x5840, 0x5940,
  64.451 +	0x5A60, 0x5B60, 0x5C60, 0x5D60, 0x5E60, 0x5F60, 0x6040, 0x6140,
  64.452 +	0x6240, 0x6340, 0x6440, 0x6540, 0x6640, 0x6740, 0x6840, 0x6940,
  64.453 +	0x6A60, 0x6B60, 0x6C60, 0x6D60, 0x6E60, 0x6F60, 0x7040, 0x7140,
  64.454 +	0x7240, 0x7340, 0x7440, 0x7540, 0x7640, 0x7740, 0x7840, 0x7940,
  64.455 +	0x7A60, 0x7B60, 0x7C60, 0x7D60, 0x7E60, 0x7F60, 0x8040, 0x8140,
  64.456 +	0x8240, 0x8340, 0x8440, 0x8540, 0x8640, 0x8740, 0x8840, 0x8940,
  64.457 +	0x8A60, 0x8B60, 0x8C60, 0x8D60, 0x8E60, 0x8F60, 0x9040, 0x9140,
  64.458 +	0x9240, 0x9340, 0x3450, 0x3550, 0x3650, 0x3750, 0x3850, 0x3950,
  64.459 +	0x3A70, 0x3B70, 0x3C70, 0x3D70, 0x3E70, 0x3F70, 0x4050, 0x4150,
  64.460 +	0x4250, 0x4350, 0x4450, 0x4550, 0x4650, 0x4750, 0x4850, 0x4950,
  64.461 +	0x4A70, 0x4B70, 0x4C70, 0x4D70, 0x4E70, 0x4F70, 0x5050, 0x5150,
  64.462 +	0x5250, 0x5350, 0x5450, 0x5550, 0x5650, 0x5750, 0x5850, 0x5950,
  64.463 +	0x5A70, 0x5B70, 0x5C70, 0x5D70, 0x5E70, 0x5F70, 0x6050, 0x6150,
  64.464 +	0x6250, 0x6350, 0x6450, 0x6550, 0x6650, 0x6750, 0x6850, 0x6950,
  64.465 +	0x6A70, 0x6B70, 0x6C70, 0x6D70, 0x6E70, 0x6F70, 0x7050, 0x7150,
  64.466 +	0x7250, 0x7350, 0x7450, 0x7550, 0x7650, 0x7750, 0x7850, 0x7950,
  64.467 +	0x7A70, 0x7B70, 0x7C70, 0x7D70, 0x7E70, 0x7F70, 0x8050, 0x8150,
  64.468 +	0x8250, 0x8350, 0x8450, 0x8550, 0x8650, 0x8750, 0x8850, 0x8950,
  64.469 +	0x8A70, 0x8B70, 0x8C70, 0x8D70, 0x8E70, 0x8F70, 0x9050, 0x9150,
  64.470 +	0x9250, 0x9350, 0x9450, 0x9550, 0x9650, 0x9750, 0x9850, 0x9950,
  64.471 +	0x9A70, 0x9B70, 0x9C70, 0x9D70, 0x9E70, 0x9F70, 0xA050, 0xA150,
  64.472 +	0xA250, 0xA350, 0xA450, 0xA550, 0xA650, 0xA750, 0xA850, 0xA950,
  64.473 +	0xAA70, 0xAB70, 0xAC70, 0xAD70, 0xAE70, 0xAF70, 0xB050, 0xB150,
  64.474 +	0xB250, 0xB350, 0xB450, 0xB550, 0xB650, 0xB750, 0xB850, 0xB950,
  64.475 +	0xBA70, 0xBB70, 0xBC70, 0xBD70, 0xBE70, 0xBF70, 0xC050, 0xC150,
  64.476 +	0xC250, 0xC350, 0xC450, 0xC550, 0xC650, 0xC750, 0xC850, 0xC950,
  64.477 +	0xCA70, 0xCB70, 0xCC70, 0xCD70, 0xCE70, 0xCF70, 0xD050, 0xD150,
  64.478 +	0xD250, 0xD350, 0xD450, 0xD550, 0xD650, 0xD750, 0xD850, 0xD950,
  64.479 +	0xDA70, 0xDB70, 0xDC70, 0xDD70, 0xDE70, 0xDF70, 0xE050, 0xE150,
  64.480 +	0xE250, 0xE350, 0xE450, 0xE550, 0xE650, 0xE750, 0xE850, 0xE950,
  64.481 +	0xEA70, 0xEB70, 0xEC70, 0xED70, 0xEE70, 0xEF70, 0xF050, 0xF150,
  64.482 +	0xF250, 0xF350, 0xF450, 0xF550, 0xF650, 0xF750, 0xF850, 0xF950,
  64.483 +	0xFA70, 0xFB70, 0xFC70, 0xFD70, 0xFE70, 0xFF70, 0x00D0, 0x0150,
  64.484 +	0x0250, 0x0350, 0x0450, 0x0550, 0x0650, 0x0750, 0x0850, 0x0950,
  64.485 +	0x0A70, 0x0B70, 0x0C70, 0x0D70, 0x0E70, 0x0F70, 0x1050, 0x1150,
  64.486 +	0x1250, 0x1350, 0x1450, 0x1550, 0x1650, 0x1750, 0x1850, 0x1950,
  64.487 +	0x1A70, 0x1B70, 0x1C70, 0x1D70, 0x1E70, 0x1F70, 0x2050, 0x2150,
  64.488 +	0x2250, 0x2350, 0x2450, 0x2550, 0x2650, 0x2750, 0x2850, 0x2950,
  64.489 +	0x2A70, 0x2B70, 0x2C70, 0x2D70, 0x2E70, 0x2F70, 0x3050, 0x3150,
  64.490 +	0x3250, 0x3350, 0x3450, 0x3550, 0x3650, 0x3750, 0x3850, 0x3950,
  64.491 +	0x3A70, 0x3B70, 0x3C70, 0x3D70, 0x3E70, 0x3F70, 0x4050, 0x4150,
  64.492 +	0x4250, 0x4350, 0x4450, 0x4550, 0x4650, 0x4750, 0x4850, 0x4950,
  64.493 +	0x4A70, 0x4B70, 0x4C70, 0x4D70, 0x4E70, 0x4F70, 0x5050, 0x5150,
  64.494 +	0x5250, 0x5350, 0x5450, 0x5550, 0x5650, 0x5750, 0x5850, 0x5950,
  64.495 +	0x5A70, 0x5B70, 0x5C70, 0x5D70, 0x5E70, 0x5F70, 0x6050, 0x6150,
  64.496 +	0x6250, 0x6350, 0x6450, 0x6550, 0x6650, 0x6750, 0x6850, 0x6950,
  64.497 +	0x6A70, 0x6B70, 0x6C70, 0x6D70, 0x6E70, 0x6F70, 0x7050, 0x7150,
  64.498 +	0x7250, 0x7350, 0x7450, 0x7550, 0x7650, 0x7750, 0x7850, 0x7950,
  64.499 +	0x7A70, 0x7B70, 0x7C70, 0x7D70, 0x7E70, 0x7F70, 0x8050, 0x8150,
  64.500 +	0x8250, 0x8350, 0x8450, 0x8550, 0x8650, 0x8750, 0x8850, 0x8950,
  64.501 +	0x8A70, 0x8B70, 0x8C70, 0x8D70, 0x8E70, 0x8F70, 0x9050, 0x9150,
  64.502 +	0x9250, 0x9350, 0x9450, 0x9550, 0x9650, 0x9750, 0x9850, 0x9950,
  64.503 +};
  64.504 +
  64.505 +u8 ZeroTable[] =
  64.506 +{
  64.507 +	0x80, 0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,
  64.508 +	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,
  64.509 +	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,
  64.510 +	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,
  64.511 +	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,
  64.512 +	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,
  64.513 +	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,
  64.514 +	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,
  64.515 +	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,
  64.516 +	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,
  64.517 +	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,
  64.518 +	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,
  64.519 +	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,
  64.520 +	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,
  64.521 +	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,
  64.522 +	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0,	0,	  0
  64.523 +};
  64.524 +
  64.525 +#define GBSAVE_GAME_VERSION_1 1
  64.526 +#define GBSAVE_GAME_VERSION_2 2
  64.527 +#define GBSAVE_GAME_VERSION_3 3
  64.528 +#define GBSAVE_GAME_VERSION_4 4
  64.529 +#define GBSAVE_GAME_VERSION_5 5
  64.530 +#define GBSAVE_GAME_VERSION_6 6
  64.531 +#define GBSAVE_GAME_VERSION_7 7
  64.532 +#define GBSAVE_GAME_VERSION_8 8
  64.533 +#define GBSAVE_GAME_VERSION_9 9
  64.534 +#define GBSAVE_GAME_VERSION_10 10
  64.535 +#define GBSAVE_GAME_VERSION_11 11
  64.536 +#define GBSAVE_GAME_VERSION_12 12
  64.537 +#define GBSAVE_GAME_VERSION_13 13
  64.538 +#define GBSAVE_GAME_VERSION GBSAVE_GAME_VERSION_13
  64.539 +
  64.540 +int inline gbGetValue(int min, int max, int v)
  64.541 +{
  64.542 +	return (int)(min + (float)(max - min) * (2.0 * (v / 31.0) - (v / 31.0) * (v / 31.0)));
  64.543 +}
  64.544 +
  64.545 +void gbGenFilter()
  64.546 +{
  64.547 +	for (int r = 0; r < 32; r++)
  64.548 +	{
  64.549 +		for (int g = 0; g < 32; g++)
  64.550 +		{
  64.551 +			for (int b = 0; b < 32; b++)
  64.552 +			{
  64.553 +				int nr = gbGetValue(gbGetValue(4, 14, g),
  64.554 +				                    gbGetValue(24, 29, g), r) - 4;
  64.555 +				int ng = gbGetValue(gbGetValue(4 + gbGetValue(0, 5, r),
  64.556 +				                               14 + gbGetValue(0, 3, r), b),
  64.557 +				                    gbGetValue(24 + gbGetValue(0, 3, r),
  64.558 +				                               29 + gbGetValue(0, 1, r), b), g) - 4;
  64.559 +				int nb = gbGetValue(gbGetValue(4 + gbGetValue(0, 5, r),
  64.560 +				                               14 + gbGetValue(0, 3, r), g),
  64.561 +				                    gbGetValue(24 + gbGetValue(0, 3, r),
  64.562 +				                               29 + gbGetValue(0, 1, r), g), b) - 4;
  64.563 +				gbColorFilter[(b << 10) | (g << 5) | r] = (nb << 10) | (ng << 5) | nr;
  64.564 +			}
  64.565 +		}
  64.566 +	}
  64.567 +}
  64.568 +
  64.569 +void gbCopyMemory(u16 d, u16 s, int count)
  64.570 +{
  64.571 +	while (count)
  64.572 +	{
  64.573 +		gbWriteMemoryQuick(d, gbReadMemoryQuick(s));
  64.574 +		s++;
  64.575 +		d++;
  64.576 +		count--;
  64.577 +	}
  64.578 +}
  64.579 +
  64.580 +void gbDoHdma()
  64.581 +{
  64.582 +	gbCopyMemory(gbHdmaDestination, gbHdmaSource, 0x10);
  64.583 +
  64.584 +	gbHdmaDestination += 0x10;
  64.585 +	gbHdmaSource	  += 0x10;
  64.586 +
  64.587 +	register_HDMA2 = (register_HDMA2 + 0x10) & 0xFF;
  64.588 +	if (register_HDMA2 == 0x00)
  64.589 +		register_HDMA1++;
  64.590 +
  64.591 +	register_HDMA4 = (register_HDMA4 + 0x10) & 0xFF;
  64.592 +	if (register_HDMA4 == 0x00)
  64.593 +		register_HDMA3++;
  64.594 +
  64.595 +	if (gbHdmaDestination == 0x96b0)
  64.596 +		gbHdmaBytes = gbHdmaBytes;
  64.597 +	gbHdmaBytes -= 0x10;
  64.598 +	register_HDMA5--;
  64.599 +	if (register_HDMA5 == 0xff)
  64.600 +		gbHdmaOn = 0;
  64.601 +}
  64.602 +
  64.603 +// fix for Harley and Lego Racers
  64.604 +void gbCompareLYToLYC()
  64.605 +{
  64.606 +	if (register_LY == register_LYC)
  64.607 +	{
  64.608 +		// mark that we have a match
  64.609 +		register_STAT |= 4;
  64.610 +
  64.611 +		// check if we need an interrupt
  64.612 +		if ((register_STAT & 0x40) && (register_IE & 2))
  64.613 +			gbInterrupt |= 2;
  64.614 +	}
  64.615 +	else   // no match
  64.616 +		register_STAT &= 0xfb;
  64.617 +}
  64.618 +
  64.619 +// FIXME: horrible kludge to workaround the frame timing bug
  64.620 +static int32 s_gbJoymask[4] = { 0, 0, 0, 0 };
  64.621 +
  64.622 +void gbWriteMemoryWrapped(register u16 address, register u8 value)
  64.623 +{
  64.624 +	if (address < 0x8000)
  64.625 +	{
  64.626 +#ifndef FINAL_VERSION
  64.627 +		if (memorydebug && (address > 0x3fff || address < 0x2000))
  64.628 +		{
  64.629 +			log("Memory register write %04x=%02x PC=%04x\n",
  64.630 +			    address,
  64.631 +			    value,
  64.632 +			    PC.W);
  64.633 +		}
  64.634 +#endif
  64.635 +		if (mapper)
  64.636 +			(*mapper)(address, value);
  64.637 +		return;
  64.638 +	}
  64.639 +
  64.640 +	if (address < 0xa000)
  64.641 +	{
  64.642 +		gbWriteMemoryQuick(address, value);
  64.643 +		return;
  64.644 +	}
  64.645 +
  64.646 +	if (address < 0xc000)
  64.647 +	{
  64.648 +#ifndef FINAL_VERSION
  64.649 +		if (memorydebug)
  64.650 +		{
  64.651 +			log("Memory register write %04x=%02x PC=%04x\n",
  64.652 +			    address,
  64.653 +			    value,
  64.654 +			    PC.W);
  64.655 +		}
  64.656 +#endif
  64.657 +
  64.658 +		if (mapper)
  64.659 +			(*mapperRAM)(address, value);
  64.660 +		return;
  64.661 +	}
  64.662 +
  64.663 +	if (address < 0xfe00)
  64.664 +	{
  64.665 +		gbWriteMemoryQuick(address, value);
  64.666 +		return;
  64.667 +	}
  64.668 +
  64.669 +	if (address < 0xff00)
  64.670 +	{
  64.671 +		gbMemory[address] = value;
  64.672 +		return;
  64.673 +	}
  64.674 +
  64.675 +	switch (address & 0x00ff)
  64.676 +	{
  64.677 +	case 0x00:
  64.678 +	{
  64.679 +		gbMemory[0xff00] = ((gbMemory[0xff00] & 0xcf) |
  64.680 +		                    (value & 0x30));
  64.681 +		if (gbSgbMode)
  64.682 +		{
  64.683 +			gbSgbDoBitTransfer(value);
  64.684 +		}
  64.685 +
  64.686 +		return;
  64.687 +	}
  64.688 +
  64.689 +	case 0x01:
  64.690 +	{
  64.691 +		gbMemory[0xff01] = value;
  64.692 +		return;
  64.693 +	}
  64.694 +
  64.695 +	// serial control
  64.696 +	case 0x02:
  64.697 +	{
  64.698 +		gbSerialOn		 = (value & 0x80);
  64.699 +		gbMemory[0xff02] = value;
  64.700 +		if (gbSerialOn)
  64.701 +		{
  64.702 +			gbSerialTicks = GBSERIAL_CLOCK_TICKS;
  64.703 +#ifdef LINK_EMULATION
  64.704 +			if (linkConnected)
  64.705 +			{
  64.706 +				if (value & 1)
  64.707 +				{
  64.708 +					linkSendByte(0x100 | gbMemory[0xFF01]);
  64.709 +					Sleep(5);
  64.710 +				}
  64.711 +			}
  64.712 +#endif
  64.713 +		}
  64.714 +
  64.715 +		gbSerialBits = 0;
  64.716 +		return;
  64.717 +	}
  64.718 +
  64.719 +	// DIV register resets on any write
  64.720 +	case 0x04:
  64.721 +	{
  64.722 +		register_DIV = 0;
  64.723 +		return;
  64.724 +	}
  64.725 +	case 0x05:
  64.726 +		register_TIMA = value;
  64.727 +		return;
  64.728 +
  64.729 +	case 0x06:
  64.730 +		register_TMA = value;
  64.731 +		return;
  64.732 +
  64.733 +	// TIMER control
  64.734 +	case 0x07:
  64.735 +	{
  64.736 +		register_TAC = value;
  64.737 +
  64.738 +		gbTimerOn	= (value & 4);
  64.739 +		gbTimerMode = value & 3;
  64.740 +		//    register_TIMA = register_TMA;
  64.741 +		switch (gbTimerMode)
  64.742 +		{
  64.743 +		case 0:
  64.744 +			gbTimerClockTicks = gbTimerTicks = GBTIMER_MODE_0_CLOCK_TICKS;
  64.745 +			break;
  64.746 +		case 1:
  64.747 +			gbTimerClockTicks = gbTimerTicks = GBTIMER_MODE_1_CLOCK_TICKS;
  64.748 +			break;
  64.749 +		case 2:
  64.750 +			gbTimerClockTicks = gbTimerTicks = GBTIMER_MODE_2_CLOCK_TICKS;
  64.751 +			break;
  64.752 +		case 3:
  64.753 +			gbTimerClockTicks = gbTimerTicks = GBTIMER_MODE_3_CLOCK_TICKS;
  64.754 +			break;
  64.755 +		}
  64.756 +		return;
  64.757 +	}
  64.758 +
  64.759 +	case 0x0f:
  64.760 +	{
  64.761 +		register_IF = value;
  64.762 +		gbInterrupt = value;
  64.763 +		return;
  64.764 +	}
  64.765 +
  64.766 +	case 0x10:
  64.767 +	case 0x11:
  64.768 +	case 0x12:
  64.769 +	case 0x13:
  64.770 +	case 0x14:
  64.771 +	case 0x15:
  64.772 +	case 0x16:
  64.773 +	case 0x17:
  64.774 +	case 0x18:
  64.775 +	case 0x19:
  64.776 +	case 0x1a:
  64.777 +	case 0x1b:
  64.778 +	case 0x1c:
  64.779 +	case 0x1d:
  64.780 +	case 0x1e:
  64.781 +	case 0x1f:
  64.782 +	case 0x20:
  64.783 +	case 0x21:
  64.784 +	case 0x22:
  64.785 +	case 0x23:
  64.786 +	case 0x24:
  64.787 +	case 0x25:
  64.788 +	case 0x26:
  64.789 +	{
  64.790 +		SOUND_EVENT(address, value);
  64.791 +		return;
  64.792 +	}
  64.793 +	case 0x40:
  64.794 +	{
  64.795 +		int lcdChange = (register_LCDC & 0x80) ^ (value & 0x80);
  64.796 +
  64.797 +		if (lcdChange)
  64.798 +		{
  64.799 +			if (value & 0x80)
  64.800 +			{
  64.801 +				gbLcdTicks	   = GBLCD_MODE_1_CLOCK_TICKS;
  64.802 +				gbLcdMode	   = 0;
  64.803 +				register_STAT &= 0xfc;
  64.804 +				register_LY	   = 0x00;
  64.805 +				// FIXME: horrible workaround
  64.806 +				if (gbNullInputHackTempEnabled && !useOldFrameTiming)
  64.807 +					memcpy(gbJoymask, s_gbJoymask, sizeof(gbJoymask));
  64.808 +			}
  64.809 +			else
  64.810 +			{
  64.811 +				gbLcdTicks	   = 0;
  64.812 +				gbLcdMode	   = 0;
  64.813 +				register_STAT &= 0xfc;
  64.814 +				register_LY	   = 0x00;
  64.815 +				// FIXME: horrible workaround
  64.816 +				memcpy(s_gbJoymask, gbJoymask, sizeof(gbJoymask));
  64.817 +				if (gbNullInputHackTempEnabled && !useOldFrameTiming)
  64.818 +					memset(gbJoymask, 0, sizeof(gbJoymask));
  64.819 +			}
  64.820 +			//      compareLYToLYC();
  64.821 +		}
  64.822 +		// don't draw the window if it was not enabled and not being drawn before
  64.823 +		if (!(register_LCDC & 0x20) && (value & 0x20) && gbWindowLine == -1 &&
  64.824 +		    register_LY > register_WY)
  64.825 +			gbWindowLine = 144;
  64.826 +
  64.827 +		register_LCDC = value;
  64.828 +
  64.829 +		return;
  64.830 +	}
  64.831 +
  64.832 +	// STAT
  64.833 +	case 0x41:
  64.834 +	{
  64.835 +		//register_STAT = (register_STAT & 0x87) |
  64.836 +		//      (value & 0x7c);
  64.837 +		register_STAT = (value & 0xf8) | (register_STAT & 0x07);     // fix ?
  64.838 +		// GB bug from Devrs FAQ
  64.839 +		if (!gbCgbMode && (register_LCDC & 0x80) && gbLcdMode < 2)
  64.840 +			gbInterrupt |= 2;
  64.841 +		return;
  64.842 +	}
  64.843 +
  64.844 +	// SCY
  64.845 +	case 0x42:
  64.846 +	{
  64.847 +		register_SCY = value;
  64.848 +		return;
  64.849 +	}
  64.850 +
  64.851 +	// SCX
  64.852 +	case 0x43:
  64.853 +	{
  64.854 +		register_SCX = value;
  64.855 +		return;
  64.856 +	}
  64.857 +
  64.858 +	// LY
  64.859 +	case 0x44:
  64.860 +	{
  64.861 +		// read only
  64.862 +		return;
  64.863 +	}
  64.864 +
  64.865 +	// LYC
  64.866 +	case 0x45:
  64.867 +	{
  64.868 +		register_LYC = value;
  64.869 +		if ((register_LCDC & 0x80))
  64.870 +		{
  64.871 +			gbCompareLYToLYC();
  64.872 +		}
  64.873 +		return;
  64.874 +	}
  64.875 +
  64.876 +	// DMA!
  64.877 +	case 0x46:
  64.878 +	{
  64.879 +		int source = value * 0x0100;
  64.880 +
  64.881 +		gbCopyMemory(0xfe00,
  64.882 +		             source,
  64.883 +		             0xa0);
  64.884 +		register_DMA = value;
  64.885 +		return;
  64.886 +	}
  64.887 +
  64.888 +	// BGP
  64.889 +	case 0x47:
  64.890 +	{
  64.891 +		gbBgp[0] = value & 0x03;
  64.892 +		gbBgp[1] = (value & 0x0c) >> 2;
  64.893 +		gbBgp[2] = (value & 0x30) >> 4;
  64.894 +		gbBgp[3] = (value & 0xc0) >> 6;
  64.895 +		break;
  64.896 +	}
  64.897 +
  64.898 +	// OBP0
  64.899 +	case 0x48:
  64.900 +	{
  64.901 +		gbObp0[0] = value & 0x03;
  64.902 +		gbObp0[1] = (value & 0x0c) >> 2;
  64.903 +		gbObp0[2] = (value & 0x30) >> 4;
  64.904 +		gbObp0[3] = (value & 0xc0) >> 6;
  64.905 +		break;
  64.906 +	}
  64.907 +
  64.908 +	// OBP1
  64.909 +	case 0x49:
  64.910 +	{
  64.911 +		gbObp1[0] = value & 0x03;
  64.912 +		gbObp1[1] = (value & 0x0c) >> 2;
  64.913 +		gbObp1[2] = (value & 0x30) >> 4;
  64.914 +		gbObp1[3] = (value & 0xc0) >> 6;
  64.915 +		break;
  64.916 +	}
  64.917 +
  64.918 +	case 0x4a:
  64.919 +		register_WY = value;
  64.920 +		return;
  64.921 +
  64.922 +	case 0x4b:
  64.923 +		register_WX = value;
  64.924 +		return;
  64.925 +
  64.926 +	// KEY1
  64.927 +	case 0x4d:
  64.928 +	{
  64.929 +		if (gbCgbMode)
  64.930 +		{
  64.931 +			gbMemory[0xff4d] = (gbMemory[0xff4d] & 0x80) | (value & 1);
  64.932 +			return;
  64.933 +		}
  64.934 +		break;
  64.935 +	}
  64.936 +
  64.937 +	// VBK
  64.938 +	case 0x4f:
  64.939 +	{
  64.940 +		if (gbCgbMode)
  64.941 +		{
  64.942 +			value = value & 1;
  64.943 +			if (value == gbVramBank)
  64.944 +				return;
  64.945 +
  64.946 +			int vramAddress = value * 0x2000;
  64.947 +			gbMemoryMap[0x08] = &gbVram[vramAddress];
  64.948 +			gbMemoryMap[0x09] = &gbVram[vramAddress + 0x1000];
  64.949 +
  64.950 +			gbVramBank	 = value;
  64.951 +			register_VBK = value;
  64.952 +		}
  64.953 +		return;
  64.954 +		break;
  64.955 +	}
  64.956 +
  64.957 +	// HDMA1
  64.958 +	case 0x51:
  64.959 +	{
  64.960 +		if (gbCgbMode)
  64.961 +		{
  64.962 +			if (value > 0x7f && value < 0xa0)
  64.963 +				value = 0;
  64.964 +
  64.965 +			gbHdmaSource = (value << 8) | (register_HDMA2 & 0xf0);
  64.966 +
  64.967 +			register_HDMA1 = value;
  64.968 +			return;
  64.969 +		}
  64.970 +		break;
  64.971 +	}
  64.972 +
  64.973 +	// HDMA2
  64.974 +	case 0x52:
  64.975 +	{
  64.976 +		if (gbCgbMode)
  64.977 +		{
  64.978 +			value = value & 0xf0;
  64.979 +
  64.980 +			gbHdmaSource = (register_HDMA1 << 8) | (value);
  64.981 +
  64.982 +			register_HDMA2 = value;
  64.983 +			return;
  64.984 +		}
  64.985 +		break;
  64.986 +	}
  64.987 +
  64.988 +	// HDMA3
  64.989 +	case 0x53:
  64.990 +	{
  64.991 +		if (gbCgbMode)
  64.992 +		{
  64.993 +			value = value & 0x1f;
  64.994 +			gbHdmaDestination  = (value << 8) | (register_HDMA4 & 0xf0);
  64.995 +			gbHdmaDestination += 0x8000;
  64.996 +			register_HDMA3	   = value;
  64.997 +			return;
  64.998 +		}
  64.999 +		break;
 64.1000 +	}
 64.1001 +
 64.1002 +	// HDMA4
 64.1003 +	case 0x54:
 64.1004 +	{
 64.1005 +		if (gbCgbMode)
 64.1006 +		{
 64.1007 +			value = value & 0xf0;
 64.1008 +			gbHdmaDestination  = ((register_HDMA3 & 0x1f) << 8) | value;
 64.1009 +			gbHdmaDestination += 0x8000;
 64.1010 +			register_HDMA4	   = value;
 64.1011 +			return;
 64.1012 +		}
 64.1013 +		break;
 64.1014 +	}
 64.1015 +
 64.1016 +	// HDMA5
 64.1017 +	case 0x55:
 64.1018 +	{
 64.1019 +		if (gbCgbMode)
 64.1020 +		{
 64.1021 +			gbHdmaBytes = 16 + (value & 0x7f) * 16;
 64.1022 +			if (gbHdmaOn)
 64.1023 +			{
 64.1024 +				if (value & 0x80)
 64.1025 +				{
 64.1026 +					register_HDMA5 = (value & 0x7f);
 64.1027 +				}
 64.1028 +				else
 64.1029 +				{
 64.1030 +					register_HDMA5 = 0xff;
 64.1031 +					gbHdmaOn	   = 0;
 64.1032 +				}
 64.1033 +			}
 64.1034 +			else
 64.1035 +			{
 64.1036 +				if (value & 0x80)
 64.1037 +				{
 64.1038 +					gbHdmaOn	   = 1;
 64.1039 +					register_HDMA5 = value & 0x7f;
 64.1040 +					if (gbLcdMode == 0)
 64.1041 +						gbDoHdma();
 64.1042 +				}
 64.1043 +				else
 64.1044 +				{
 64.1045 +					// we need to take the time it takes to complete the transfer into
 64.1046 +					// account... according to GB DEV FAQs, the setup time is the same
 64.1047 +					// for single and double speed, but the actual transfer takes the
 64.1048 +					// same time // (is that a typo?)
 64.1049 +					switch (gbDMASpeedVersion)
 64.1050 +					{
 64.1051 +					case 1:     // I believe this is more correct
 64.1052 +						// the lower 7 bits of FF55 specify the Transfer Length (divided by 16, minus 1)
 64.1053 +						// and we make gbDmaTicks twice as many cycles at double speed to make the transfer take the same time
 64.1054 +						if (gbSpeed)
 64.1055 +							gbDmaTicks = 16 * ((value & 0x7f) + 1);
 64.1056 +						else
 64.1057 +							gbDmaTicks = 8 * ((value & 0x7f) + 1);
 64.1058 +						break;
 64.1059 +					case 0:     // here for backward compatibility
 64.1060 +						// I think this was a guess that approximates the above in most but not all games
 64.1061 +						if (gbSpeed)
 64.1062 +							gbDmaTicks = 231 + 16 * (value & 0x7f);
 64.1063 +						else
 64.1064 +							gbDmaTicks = 231 + 8 * (value & 0x7f);
 64.1065 +						break;
 64.1066 +					default:     // shouldn't happen
 64.1067 +						//assert(0);
 64.1068 +						break;
 64.1069 +					}
 64.1070 +					gbCopyMemory(gbHdmaDestination, gbHdmaSource, gbHdmaBytes);
 64.1071 +					gbHdmaDestination += gbHdmaBytes;
 64.1072 +					gbHdmaSource	  += gbHdmaBytes;
 64.1073 +
 64.1074 +					register_HDMA3 = ((gbHdmaDestination - 0x8000) >> 8) & 0x1f;
 64.1075 +					register_HDMA4 = gbHdmaDestination & 0xf0;
 64.1076 +					register_HDMA1 = (gbHdmaSource >> 8) & 0xff;
 64.1077 +					register_HDMA2 = gbHdmaSource & 0xf0;
 64.1078 +				}
 64.1079 +			}
 64.1080 +			return;
 64.1081 +		}
 64.1082 +		break;
 64.1083 +	}
 64.1084 +
 64.1085 +	// BCPS
 64.1086 +	case 0x68:
 64.1087 +	{
 64.1088 +		if (gbCgbMode)
 64.1089 +		{
 64.1090 +			int paletteIndex = (value & 0x3f) >> 1;
 64.1091 +			int paletteHiLo	 = (value & 0x01);
 64.1092 +
 64.1093 +			gbMemory[0xff68] = value;
 64.1094 +			gbMemory[0xff69] = (paletteHiLo ?
 64.1095 +			                    (gbPalette[paletteIndex] >> 8) :
 64.1096 +			                    (gbPalette[paletteIndex] & 0x00ff));
 64.1097 +			return;
 64.1098 +		}
 64.1099 +		break;
 64.1100 +	}
 64.1101 +
 64.1102 +	// BCPD
 64.1103 +	case 0x69:
 64.1104 +	{
 64.1105 +		if (gbCgbMode)
 64.1106 +		{
 64.1107 +			int v = gbMemory[0xff68];
 64.1108 +			int paletteIndex = (v & 0x3f) >> 1;
 64.1109 +			int paletteHiLo	 = (v & 0x01);
 64.1110 +			gbMemory[0xff69]		= value;
 64.1111 +			gbPalette[paletteIndex] = (paletteHiLo ?
 64.1112 +			                           ((value << 8) | (gbPalette[paletteIndex] & 0xff)) :
 64.1113 +			                           ((gbPalette[paletteIndex] & 0xff00) | (value))) & 0x7fff;
 64.1114 +
 64.1115 +			if (gbMemory[0xff68] & 0x80)
 64.1116 +			{
 64.1117 +				int index = ((gbMemory[0xff68] & 0x3f) + 1) & 0x3f;
 64.1118 +
 64.1119 +				gbMemory[0xff68] = (gbMemory[0xff68] & 0x80) | index;
 64.1120 +
 64.1121 +				gbMemory[0xff69] = (index & 1 ?
 64.1122 +				                    (gbPalette[index >> 1] >> 8) :
 64.1123 +				                    (gbPalette[index >> 1] & 0x00ff));
 64.1124 +			}
 64.1125 +			return;
 64.1126 +		}
 64.1127 +		break;
 64.1128 +	}
 64.1129 +
 64.1130 +	// OCPS
 64.1131 +	case 0x6a:
 64.1132 +	{
 64.1133 +		if (gbCgbMode)
 64.1134 +		{
 64.1135 +			int paletteIndex = (value & 0x3f) >> 1;
 64.1136 +			int paletteHiLo	 = (value & 0x01);
 64.1137 +
 64.1138 +			paletteIndex += 32;
 64.1139 +
 64.1140 +			gbMemory[0xff6a] = value;
 64.1141 +			gbMemory[0xff6b] = (paletteHiLo ?
 64.1142 +			                    (gbPalette[paletteIndex] >> 8) :
 64.1143 +			                    (gbPalette[paletteIndex] & 0x00ff));
 64.1144 +			return;
 64.1145 +		}
 64.1146 +		break;
 64.1147 +	}
 64.1148 +
 64.1149 +	// OCPD
 64.1150 +	case 0x6b:
 64.1151 +	{
 64.1152 +		if (gbCgbMode)
 64.1153 +		{
 64.1154 +			int v = gbMemory[0xff6a];
 64.1155 +			int paletteIndex = (v & 0x3f) >> 1;
 64.1156 +			int paletteHiLo	 = (v & 0x01);
 64.1157 +
 64.1158 +			paletteIndex += 32;
 64.1159 +
 64.1160 +			gbMemory[0xff6b]		= value;
 64.1161 +			gbPalette[paletteIndex] = (paletteHiLo ?
 64.1162 +			                           ((value << 8) | (gbPalette[paletteIndex] & 0xff)) :
 64.1163 +			                           ((gbPalette[paletteIndex] & 0xff00) | (value))) & 0x7fff;
 64.1164 +			if (gbMemory[0xff6a] & 0x80)
 64.1165 +			{
 64.1166 +				int index = ((gbMemory[0xff6a] & 0x3f) + 1) & 0x3f;
 64.1167 +
 64.1168 +				gbMemory[0xff6a] = (gbMemory[0xff6a] & 0x80) | index;
 64.1169 +
 64.1170 +				gbMemory[0xff6b] = (index & 1 ?
 64.1171 +				                    (gbPalette[(index >> 1) + 32] >> 8) :
 64.1172 +				                    (gbPalette[(index >> 1) + 32] & 0x00ff));
 64.1173 +			}
 64.1174 +			return;
 64.1175 +		}
 64.1176 +		break;
 64.1177 +	}
 64.1178 +
 64.1179 +	// SVBK
 64.1180 +	case 0x70:
 64.1181 +	{
 64.1182 +		if (gbCgbMode)
 64.1183 +		{
 64.1184 +			value = value & 7;
 64.1185 +
 64.1186 +			int bank = value;
 64.1187 +			if (value == 0)
 64.1188 +				bank = 1;
 64.1189 +
 64.1190 +			if (bank == gbWramBank)
 64.1191 +				return;
 64.1192 +
 64.1193 +			int wramAddress = bank * 0x1000;
 64.1194 +			gbMemoryMap[0x0d] = &gbWram[wramAddress];
 64.1195 +
 64.1196 +			gbWramBank	  = bank;
 64.1197 +			register_SVBK = value;
 64.1198 +			return;
 64.1199 +		}
 64.1200 +		break;
 64.1201 +	}
 64.1202 +
 64.1203 +	case 0xff:
 64.1204 +	{
 64.1205 +		register_IE	 = value;
 64.1206 +		register_IF &= value;
 64.1207 +		return;
 64.1208 +	}
 64.1209 +	}
 64.1210 +
 64.1211 +	gbWriteMemoryQuick(address, value);
 64.1212 +}
 64.1213 +
 64.1214 +u8 gbReadOpcode(register u16 address)
 64.1215 +{
 64.1216 +	if (gbCheatMap[address])
 64.1217 +		return gbCheatRead(address);
 64.1218 +
 64.1219 +	// the following fix does more than Echo RAM fix, anyway...
 64.1220 +	switch (gbEchoRAMFixOn ? (address >> 12) & 0x000f : address & 0xf000)
 64.1221 +	{
 64.1222 +	case 0x0a:
 64.1223 +	case 0x0b:
 64.1224 +		if (mapperReadRAM)
 64.1225 +			return mapperReadRAM(address);
 64.1226 +		break;
 64.1227 +	case 0x0f:
 64.1228 +		if (address > 0xff00)
 64.1229 +		{
 64.1230 +			switch (address & 0x00ff)
 64.1231 +			{
 64.1232 +			case 0x04:
 64.1233 +				return register_DIV;
 64.1234 +			case 0x05:
 64.1235 +				return register_TIMA;
 64.1236 +			case 0x06:
 64.1237 +				return register_TMA;
 64.1238 +			case 0x07:
 64.1239 +				return (0xf8 | register_TAC);
 64.1240 +			case 0x0f:
 64.1241 +				return (0xe0 | register_IF);
 64.1242 +			case 0x40:
 64.1243 +				return register_LCDC;
 64.1244 +			case 0x41:
 64.1245 +				return (0x80 | register_STAT);
 64.1246 +			case 0x42:
 64.1247 +				return register_SCY;
 64.1248 +			case 0x43:
 64.1249 +				return register_SCX;
 64.1250 +			case 0x44:
 64.1251 +				return register_LY;
 64.1252 +			case 0x45:
 64.1253 +				return register_LYC;
 64.1254 +			case 0x46:
 64.1255 +				return register_DMA;
 64.1256 +			case 0x4a:
 64.1257 +				return register_WY;
 64.1258 +			case 0x4b:
 64.1259 +				return register_WX;
 64.1260 +			case 0x4f:
 64.1261 +				return (0xfe | register_VBK);
 64.1262 +			case 0x51:
 64.1263 +				return register_HDMA1;
 64.1264 +			case 0x52:
 64.1265 +				return register_HDMA2;
 64.1266 +			case 0x53:
 64.1267 +				return register_HDMA3;
 64.1268 +			case 0x54:
 64.1269 +				return register_HDMA4;
 64.1270 +			case 0x55:
 64.1271 +				return register_HDMA5;
 64.1272 +			case 0x70:
 64.1273 +				return (0xf8 | register_SVBK);
 64.1274 +			case 0xff:
 64.1275 +				return register_IE;
 64.1276 +			}
 64.1277 +		}
 64.1278 +		break;
 64.1279 +	}
 64.1280 +	return gbReadMemoryQuick(address);
 64.1281 +}
 64.1282 +
 64.1283 +void gbWriteMemory(register u16 address, register u8 value)
 64.1284 +{
 64.1285 +	gbWriteMemoryWrapped(address, value);
 64.1286 +	CallRegisteredLuaMemHook(address, 1, value, LUAMEMHOOK_WRITE);
 64.1287 +}
 64.1288 +
 64.1289 +u8 gbReadMemory(register u16 address)
 64.1290 +{
 64.1291 +	if (gbCheatMap[address])
 64.1292 +		return gbCheatRead(address);
 64.1293 +
 64.1294 +	if (address < 0xa000)
 64.1295 +		return gbReadMemoryQuick(address);
 64.1296 +
 64.1297 +	if (address < 0xc000)
 64.1298 +	{
 64.1299 +#ifndef FINAL_VERSION
 64.1300 +		if (memorydebug)
 64.1301 +		{
 64.1302 +			log("Memory register read %04x PC=%04x\n",
 64.1303 +			    address,
 64.1304 +			    PC.W);
 64.1305 +		}
 64.1306 +#endif
 64.1307 +
 64.1308 +		if (mapperReadRAM)
 64.1309 +			return mapperReadRAM(address);
 64.1310 +		return gbReadMemoryQuick(address);
 64.1311 +	}
 64.1312 +
 64.1313 +	if (address >= 0xff00)
 64.1314 +	{
 64.1315 +		switch (address & 0x00ff)
 64.1316 +		{
 64.1317 +		case 0x00:
 64.1318 +		{
 64.1319 +			if (gbSgbMode)
 64.1320 +			{
 64.1321 +				gbSgbReadingController |= 4;
 64.1322 +				gbSgbResetPacketState();
 64.1323 +			}
 64.1324 +
 64.1325 +			int b = gbMemory[0xff00];
 64.1326 +
 64.1327 +			if ((b & 0x30) == 0x20)
 64.1328 +			{
 64.1329 +				b &= 0xf0;
 64.1330 +
 64.1331 +				int joy = 0;
 64.1332 +				if (gbSgbMode && gbSgbMultiplayer)
 64.1333 +				{
 64.1334 +					switch (gbSgbNextController)
 64.1335 +					{
 64.1336 +					case 0x0f:
 64.1337 +						joy = 0;
 64.1338 +						break;
 64.1339 +					case 0x0e:
 64.1340 +						joy = 1;
 64.1341 +						break;
 64.1342 +					case 0x0d:
 64.1343 +						joy = 2;
 64.1344 +						break;
 64.1345 +					case 0x0c:
 64.1346 +						joy = 3;
 64.1347 +						break;
 64.1348 +					default:
 64.1349 +						joy = 0;
 64.1350 +					}
 64.1351 +				}
 64.1352 +				int joystate = gbJoymask[joy];
 64.1353 +				if (!(joystate & 128))
 64.1354 +					b |= 0x08;
 64.1355 +				if (!(joystate & 64))
 64.1356 +					b |= 0x04;
 64.1357 +				if (!(joystate & 32))
 64.1358 +					b |= 0x02;
 64.1359 +				if (!(joystate & 16))
 64.1360 +					b |= 0x01;
 64.1361 +
 64.1362 +				gbMemory[0xff00] = b;
 64.1363 +			}
 64.1364 +			else if ((b & 0x30) == 0x10)
 64.1365 +			{
 64.1366 +				b &= 0xf0;
 64.1367 +
 64.1368 +				int joy = 0;
 64.1369 +				if (gbSgbMode && gbSgbMultiplayer)
 64.1370 +				{
 64.1371 +					switch (gbSgbNextController)
 64.1372 +					{
 64.1373 +					case 0x0f:
 64.1374 +						joy = 0;
 64.1375 +						break;
 64.1376 +					case 0x0e:
 64.1377 +						joy = 1;
 64.1378 +						break;
 64.1379 +					case 0x0d:
 64.1380 +						joy = 2;
 64.1381 +						break;
 64.1382 +					case 0x0c:
 64.1383 +						joy = 3;
 64.1384 +						break;
 64.1385 +					default:
 64.1386 +						joy = 0;
 64.1387 +					}
 64.1388 +				}
 64.1389 +				int joystate = gbJoymask[joy];
 64.1390 +				if (!(joystate & 8))
 64.1391 +					b |= 0x08;
 64.1392 +				if (!(joystate & 4))
 64.1393 +					b |= 0x04;
 64.1394 +				if (!(joystate & 2))
 64.1395 +					b |= 0x02;
 64.1396 +				if (!(joystate & 1))
 64.1397 +					b |= 0x01;
 64.1398 +
 64.1399 +				gbMemory[0xff00] = b;
 64.1400 +			}
 64.1401 +			else
 64.1402 +			{
 64.1403 +				if (gbSgbMode && gbSgbMultiplayer)
 64.1404 +				{
 64.1405 +					gbMemory[0xff00] = 0xf0 | gbSgbNextController;
 64.1406 +				}
 64.1407 +				else
 64.1408 +				{
 64.1409 +					gbMemory[0xff00] = 0xff;
 64.1410 +				}
 64.1411 +			}
 64.1412 +		}
 64.1413 +			GBSystemCounters.lagged = false;
 64.1414 +			return gbMemory[0xff00];
 64.1415 +			break;
 64.1416 +		case 0x01:
 64.1417 +			return gbMemory[0xff01];
 64.1418 +		case 0x04:
 64.1419 +			return register_DIV;
 64.1420 +		case 0x05:
 64.1421 +			return register_TIMA;
 64.1422 +		case 0x06:
 64.1423 +			return register_TMA;
 64.1424 +		case 0x07:
 64.1425 +			return (0xf8 | register_TAC);
 64.1426 +		case 0x0f:
 64.1427 +			return (0xe0 | register_IF);
 64.1428 +		case 0x40:
 64.1429 +			return register_LCDC;
 64.1430 +		case 0x41:
 64.1431 +			return (0x80 | register_STAT);
 64.1432 +		case 0x42:
 64.1433 +			return register_SCY;
 64.1434 +		case 0x43:
 64.1435 +			return register_SCX;
 64.1436 +		case 0x44:
 64.1437 +			return register_LY;
 64.1438 +		case 0x45:
 64.1439 +			return register_LYC;
 64.1440 +		case 0x46:
 64.1441 +			return register_DMA;
 64.1442 +		case 0x4a:
 64.1443 +			return register_WY;
 64.1444 +		case 0x4b:
 64.1445 +			return register_WX;
 64.1446 +		case 0x4f:
 64.1447 +			return (0xfe | register_VBK);
 64.1448 +		case 0x51:
 64.1449 +			return register_HDMA1;
 64.1450 +		case 0x52:
 64.1451 +			return register_HDMA2;
 64.1452 +		case 0x53:
 64.1453 +			return register_HDMA3;
 64.1454 +		case 0x54:
 64.1455 +			return register_HDMA4;
 64.1456 +		case 0x55:
 64.1457 +			return register_HDMA5;
 64.1458 +		case 0x70:
 64.1459 +			return (0xf8 | register_SVBK);
 64.1460 +		case 0xff:
 64.1461 +			return register_IE;
 64.1462 +		}
 64.1463 +	}
 64.1464 +
 64.1465 +	return gbReadMemoryQuick(address);
 64.1466 +}
 64.1467 +
 64.1468 +void gbVblank_interrupt()
 64.1469 +{
 64.1470 +	if (IFF & 0x80)
 64.1471 +	{
 64.1472 +		PC.W++;
 64.1473 +		IFF &= 0x7f;
 64.1474 +	}
 64.1475 +	gbInterrupt &= 0xfe;
 64.1476 +
 64.1477 +	IFF			&= 0x7e;
 64.1478 +	register_IF &= 0xfe;
 64.1479 +
 64.1480 +	gbWriteMemory(--SP.W, PC.B.B1);
 64.1481 +	gbWriteMemory(--SP.W, PC.B.B0);
 64.1482 +	PC.W = 0x40;
 64.1483 +}
 64.1484 +
 64.1485 +void gbLcd_interrupt()
 64.1486 +{
 64.1487 +	if (IFF & 0x80)
 64.1488 +	{
 64.1489 +		PC.W++;
 64.1490 +		IFF &= 0x7f;
 64.1491 +	}
 64.1492 +	gbInterrupt &= 0xfd;
 64.1493 +	IFF			&= 0x7e;
 64.1494 +	register_IF &= 0xfd;
 64.1495 +
 64.1496 +	gbWriteMemory(--SP.W, PC.B.B1);
 64.1497 +	gbWriteMemory(--SP.W, PC.B.B0);
 64.1498 +
 64.1499 +	PC.W = 0x48;
 64.1500 +}
 64.1501 +
 64.1502 +void gbTimer_interrupt()
 64.1503 +{
 64.1504 +	if (IFF & 0x80)
 64.1505 +	{
 64.1506 +		PC.W++;
 64.1507 +		IFF &= 0x7f;
 64.1508 +	}
 64.1509 +	IFF			&= 0x7e;
 64.1510 +	gbInterrupt &= 0xfb;
 64.1511 +	register_IF &= 0xfb;
 64.1512 +
 64.1513 +	gbWriteMemory(--SP.W, PC.B.B1);
 64.1514 +	gbWriteMemory(--SP.W, PC.B.B0);
 64.1515 +
 64.1516 +	PC.W = 0x50;
 64.1517 +}
 64.1518 +
 64.1519 +void gbSerial_interrupt()
 64.1520 +{
 64.1521 +	if (IFF & 0x80)
 64.1522 +	{
 64.1523 +		PC.W++;
 64.1524 +		IFF &= 0x7f;
 64.1525 +	}
 64.1526 +	IFF			&= 0x7e;
 64.1527 +	gbInterrupt &= 0xf7;
 64.1528 +	register_IF &= 0xf7;
 64.1529 +
 64.1530 +	gbWriteMemory(--SP.W, PC.B.B1);
 64.1531 +	gbWriteMemory(--SP.W, PC.B.B0);
 64.1532 +
 64.1533 +	PC.W = 0x58;
 64.1534 +}
 64.1535 +
 64.1536 +void gbJoypad_interrupt()
 64.1537 +{
 64.1538 +	if (IFF & 0x80)
 64.1539 +	{
 64.1540 +		PC.W++;
 64.1541 +		IFF &= 0x7f;
 64.1542 +	}
 64.1543 +	IFF			&= 0x7e;
 64.1544 +	gbInterrupt &= 0xef;
 64.1545 +	register_IF &= 0xef;
 64.1546 +
 64.1547 +	gbWriteMemory(--SP.W, PC.B.B1);
 64.1548 +	gbWriteMemory(--SP.W, PC.B.B0);
 64.1549 +
 64.1550 +	PC.W = 0x60;
 64.1551 +}
 64.1552 +
 64.1553 +void gbSpeedSwitch()
 64.1554 +{
 64.1555 +	if (gbSpeed == 0)
 64.1556 +	{
 64.1557 +		gbSpeed = 1;
 64.1558 +		GBLCD_MODE_0_CLOCK_TICKS   = 51 * 2; //127; //51 * 2;
 64.1559 +		GBLCD_MODE_1_CLOCK_TICKS   = 1140 * 2;
 64.1560 +		GBLCD_MODE_2_CLOCK_TICKS   = 20 * 2; //52; //20 * 2;
 64.1561 +		GBLCD_MODE_3_CLOCK_TICKS   = 43 * 2; //99; //43 * 2;
 64.1562 +		GBDIV_CLOCK_TICKS		   = 64 * 2;
 64.1563 +		GBLY_INCREMENT_CLOCK_TICKS = 114 * 2;
 64.1564 +		GBTIMER_MODE_0_CLOCK_TICKS = 256; //256*2;
 64.1565 +		GBTIMER_MODE_1_CLOCK_TICKS = 4; //4*2;
 64.1566 +		GBTIMER_MODE_2_CLOCK_TICKS = 16; //16*2;
 64.1567 +		GBTIMER_MODE_3_CLOCK_TICKS = 64; //64*2;
 64.1568 +		GBSERIAL_CLOCK_TICKS	   = 128 * 2;
 64.1569 +		gbDivTicks *= 2;
 64.1570 +		gbLcdTicks *= 2;
 64.1571 +		gbLcdLYIncrementTicks *= 2;
 64.1572 +		//    timerTicks *= 2;
 64.1573 +		//    timerClockTicks *= 2;
 64.1574 +		gbSerialTicks	 *= 2;
 64.1575 +		SOUND_CLOCK_TICKS = soundQuality * GB_USE_TICKS_AS * 2;
 64.1576 +		soundTicks		 *= 2;
 64.1577 +		//    synchronizeTicks *= 2;
 64.1578 +		//    SYNCHRONIZE_CLOCK_TICKS *= 2;
 64.1579 +	}
 64.1580 +	else
 64.1581 +	{
 64.1582 +		gbSpeed = 0;
 64.1583 +		GBLCD_MODE_0_CLOCK_TICKS   = 51;
 64.1584 +		GBLCD_MODE_1_CLOCK_TICKS   = 1140;
 64.1585 +		GBLCD_MODE_2_CLOCK_TICKS   = 20;
 64.1586 +		GBLCD_MODE_3_CLOCK_TICKS   = 43;
 64.1587 +		GBDIV_CLOCK_TICKS		   = 64;
 64.1588 +		GBLY_INCREMENT_CLOCK_TICKS = 114;
 64.1589 +		GBTIMER_MODE_0_CLOCK_TICKS = 256;
 64.1590 +		GBTIMER_MODE_1_CLOCK_TICKS = 4;
 64.1591 +		GBTIMER_MODE_2_CLOCK_TICKS = 16;
 64.1592 +		GBTIMER_MODE_3_CLOCK_TICKS = 64;
 64.1593 +		GBSERIAL_CLOCK_TICKS	   = 128;
 64.1594 +		gbDivTicks /= 2;
 64.1595 +		gbLcdTicks /= 2;
 64.1596 +		gbLcdLYIncrementTicks /= 2;
 64.1597 +		//    timerTicks /= 2;
 64.1598 +		//    timerClockTicks /= 2;
 64.1599 +		gbSerialTicks	 /= 2;
 64.1600 +		SOUND_CLOCK_TICKS = soundQuality * GB_USE_TICKS_AS;
 64.1601 +		soundTicks		 /= 2;
 64.1602 +		//    synchronizeTicks /= 2;
 64.1603 +		//    SYNCHRONIZE_CLOCK_TICKS /= 2;
 64.1604 +	}
 64.1605 +}
 64.1606 +
 64.1607 +void gbGetHardwareType()
 64.1608 +{
 64.1609 +	gbCgbMode = 0;
 64.1610 +	if (gbRom[0x143] & 0x80)
 64.1611 +	{
 64.1612 +		if (gbEmulatorType == 0 ||
 64.1613 +		    gbEmulatorType == 1 ||
 64.1614 +		    gbEmulatorType == 4 ||
 64.1615 +		    gbEmulatorType == 5 ||
 64.1616 +		    (gbRom[0x146] != 0x03 && (gbEmulatorType == 2)))
 64.1617 +		{
 64.1618 +			gbCgbMode = 1;
 64.1619 +		}
 64.1620 +	}
 64.1621 +
 64.1622 +	if (gbSgbMode == 2)
 64.1623 +	{
 64.1624 +		gbSgbMode = 0;
 64.1625 +		return;
 64.1626 +	}
 64.1627 +
 64.1628 +	gbSgbMode = 0;
 64.1629 +	if (gbRom[0x146] == 0x03)
 64.1630 +	{
 64.1631 +		if (gbEmulatorType == 0 ||
 64.1632 +		    gbEmulatorType == 2 ||
 64.1633 +		    gbEmulatorType == 5 ||
 64.1634 +		    (!(gbRom[0x143] & 0x80) && (gbEmulatorType == 1 || gbEmulatorType == 4)))
 64.1635 +			gbSgbMode = 1;
 64.1636 +	}
 64.1637 +}
 64.1638 +
 64.1639 +void gbReset(bool userReset)
 64.1640 +{
 64.1641 +	// movie must be closed while opening/creating a movie
 64.1642 +	if (userReset && VBAMovieRecording())
 64.1643 +	{
 64.1644 +		VBAMovieSignalReset();
 64.1645 +		return;
 64.1646 +	}
 64.1647 +
 64.1648 +	if (!VBAMovieActive())
 64.1649 +	{
 64.1650 +		GBSystemCounters.frameCount = 0;
 64.1651 +		GBSystemCounters.lagCount	= 0;
 64.1652 +		GBSystemCounters.extraCount = 0;
 64.1653 +		GBSystemCounters.lagged		= true;
 64.1654 +		GBSystemCounters.laggedLast = true;
 64.1655 +	}
 64.1656 +
 64.1657 +	SP.W = 0xfffe;
 64.1658 +	AF.W = 0x01b0;
 64.1659 +	BC.W = 0x0013;
 64.1660 +	DE.W = 0x00d8;
 64.1661 +	HL.W = 0x014d;
 64.1662 +	PC.W = 0x0100;
 64.1663 +	IFF	 = 0;
 64.1664 +	gbInterrupt		= 1;
 64.1665 +	gbInterruptWait = 0;
 64.1666 +
 64.1667 +	register_DIV   = 0;
 64.1668 +	register_TIMA  = 0;
 64.1669 +	register_TMA   = 0;
 64.1670 +	register_TAC   = 0;
 64.1671 +	register_IF	   = 1;
 64.1672 +	register_LCDC  = 0x91;
 64.1673 +	register_STAT  = 0;
 64.1674 +	register_SCY   = 0;
 64.1675 +	register_SCX   = 0;
 64.1676 +	register_LY	   = 0;
 64.1677 +	register_LYC   = 0;
 64.1678 +	register_DMA   = 0;
 64.1679 +	register_WY	   = 0;
 64.1680 +	register_WX	   = 0;
 64.1681 +	register_VBK   = 0;
 64.1682 +	register_HDMA1 = 0;
 64.1683 +	register_HDMA2 = 0;
 64.1684 +	register_HDMA3 = 0;
 64.1685 +	register_HDMA4 = 0;
 64.1686 +	register_HDMA5 = 0;
 64.1687 +	register_SVBK  = 0;
 64.1688 +	register_IE	   = 0;
 64.1689 +
 64.1690 +	gbGetHardwareType();
 64.1691 +	if (gbCgbMode)
 64.1692 +	{
 64.1693 +		if (!gbVram)
 64.1694 +			gbVram = (u8 *)malloc(0x4000 + 4);
 64.1695 +		if (!gbWram)
 64.1696 +			gbWram = (u8 *)malloc(0x8000 + 4);
 64.1697 +		memset(gbVram, 0, 0x4000 + 4);
 64.1698 +		memset(gbWram, 0, 0x8000 + 4);
 64.1699 +	}
 64.1700 +	else
 64.1701 +	{
 64.1702 +		if (gbVram)
 64.1703 +		{
 64.1704 +			free(gbVram);
 64.1705 +			gbVram = NULL;
 64.1706 +		}
 64.1707 +		if (gbWram)
 64.1708 +		{
 64.1709 +			free(gbWram);
 64.1710 +			gbWram = NULL;
 64.1711 +		}
 64.1712 +	}
 64.1713 +
 64.1714 +	// clean LineBuffer
 64.1715 +	if (gbLineBuffer)
 64.1716 +		memset(gbLineBuffer, 0, 160 * sizeof(u16));
 64.1717 +	// clean Pix
 64.1718 +	if (pix)
 64.1719 +		memset(pix, 0, 4 * 257 * 226);
 64.1720 +
 64.1721 +	if (gbCgbMode)
 64.1722 +	{
 64.1723 +		if (gbSgbMode)
 64.1724 +		{
 64.1725 +			if (gbEmulatorType == 5)
 64.1726 +				AF.W = 0xffb0;
 64.1727 +			else
 64.1728 +				AF.W = 0x01b0;
 64.1729 +			BC.W = 0x0013;
 64.1730 +			DE.W = 0x00d8;
 64.1731 +			HL.W = 0x014d;
 64.1732 +		}
 64.1733 +		else
 64.1734 +		{
 64.1735 +			AF.W = 0x11b0;
 64.1736 +			BC.W = 0x0000;
 64.1737 +			DE.W = 0xff56;
 64.1738 +			HL.W = 0x000d;
 64.1739 +		}
 64.1740 +		if (gbEmulatorType == 4)
 64.1741 +			BC.B.B1 |= 0x01;
 64.1742 +
 64.1743 +		register_HDMA5	 = 0xff;
 64.1744 +		gbMemory[0xff68] = 0xc0;
 64.1745 +		gbMemory[0xff6a] = 0xc0;
 64.1746 +
 64.1747 +		for (int i = 0; i < 64; i++)
 64.1748 +			gbPalette[i] = 0x7fff;
 64.1749 +	}
 64.1750 +	else
 64.1751 +	{
 64.1752 +		for (int i = 0; i < 8; i++)
 64.1753 +			gbPalette[i] = systemGbPalette[gbPaletteOption * 8 + i];
 64.1754 +	}
 64.1755 +
 64.1756 +	if (gbSpeed)
 64.1757 +	{
 64.1758 +		gbSpeedSwitch();
 64.1759 +		gbMemory[0xff4d] = 0;
 64.1760 +	}
 64.1761 +
 64.1762 +	gbDivTicks = GBDIV_CLOCK_TICKS;
 64.1763 +	gbLcdMode  = 2;
 64.1764 +	gbLcdTicks = GBLCD_MODE_2_CLOCK_TICKS;
 64.1765 +	gbLcdLYIncrementTicks = 0;
 64.1766 +	gbTimerTicks		  = 0;
 64.1767 +	gbTimerClockTicks	  = 0;
 64.1768 +	gbSerialTicks		  = 0;
 64.1769 +	gbSerialBits		  = 0;
 64.1770 +	gbSerialOn			  = 0;
 64.1771 +	gbWindowLine		  = -1;
 64.1772 +	gbTimerOn			  = 0;
 64.1773 +	gbTimerMode			  = 0;
 64.1774 +	//  gbSynchronizeTicks = GBSYNCHRONIZE_CLOCK_TICKS;
 64.1775 +	gbSpeed		 = 0;
 64.1776 +	gbJoymask[0] = gbJoymask[1] = gbJoymask[2] = gbJoymask[3] = 0;
 64.1777 +
 64.1778 +	// FIXME: horrible kludge
 64.1779 +	memset(s_gbJoymask, 0, sizeof(s_gbJoymask));
 64.1780 +
 64.1781 +	if (gbCgbMode)
 64.1782 +	{
 64.1783 +		gbSpeed	 = 0;
 64.1784 +		gbHdmaOn = 0;
 64.1785 +		gbHdmaSource	  = 0x0000;
 64.1786 +		gbHdmaDestination = 0x8000;
 64.1787 +		gbVramBank		  = 0;
 64.1788 +		gbWramBank		  = 1;
 64.1789 +		register_LY		  = 0x90;
 64.1790 +		gbLcdMode		  = 1;
 64.1791 +	}
 64.1792 +
 64.1793 +	if (gbSgbMode)
 64.1794 +	{
 64.1795 +		gbSgbReset();
 64.1796 +	}
 64.1797 +
 64.1798 +	for (int i = 0; i < 4; i++)
 64.1799 +		gbBgp[i] = gbObp0[i] = gbObp1[i] = i;
 64.1800 +
 64.1801 +	memset(&gbDataMBC1, 0, sizeof(gbDataMBC1));
 64.1802 +	gbDataMBC1.mapperROMBank = 1;
 64.1803 +
 64.1804 +	gbDataMBC2.mapperRAMEnable = 0;
 64.1805 +	gbDataMBC2.mapperROMBank   = 1;
 64.1806 +
 64.1807 +	memset(&gbDataMBC3, 0, 6 * sizeof(int32));
 64.1808 +	gbDataMBC3.mapperROMBank = 1;
 64.1809 +
 64.1810 +	memset(&gbDataMBC5, 0, sizeof(gbDataMBC5));
 64.1811 +	gbDataMBC5.mapperROMBank = 1;
 64.1812 +	switch (gbRom[0x147])
 64.1813 +	{
 64.1814 +	case 0x1c:
 64.1815 +	case 0x1d:
 64.1816 +	case 0x1e:
 64.1817 +		gbDataMBC5.isRumbleCartridge = 1;
 64.1818 +	}
 64.1819 +
 64.1820 +	memset(&gbDataHuC1, 0, sizeof(gbDataHuC1));
 64.1821 +	gbDataHuC1.mapperROMBank = 1;
 64.1822 +
 64.1823 +	memset(&gbDataHuC3, 0, sizeof(gbDataHuC3));
 64.1824 +	gbDataHuC3.mapperROMBank = 1;
 64.1825 +
 64.1826 +	gbMemoryMap[0x00] = &gbRom[0x0000];
 64.1827 +	gbMemoryMap[0x01] = &gbRom[0x1000];
 64.1828 +	gbMemoryMap[0x02] = &gbRom[0x2000];
 64.1829 +	gbMemoryMap[0x03] = &gbRom[0x3000];
 64.1830 +	gbMemoryMap[0x04] = &gbRom[0x4000];
 64.1831 +	gbMemoryMap[0x05] = &gbRom[0x5000];
 64.1832 +	gbMemoryMap[0x06] = &gbRom[0x6000];
 64.1833 +	gbMemoryMap[0x07] = &gbRom[0x7000];
 64.1834 +	if (gbCgbMode)
 64.1835 +	{
 64.1836 +		gbMemoryMap[0x08] = &gbVram[0x0000];
 64.1837 +		gbMemoryMap[0x09] = &gbVram[0x1000];
 64.1838 +		gbMemoryMap[0x0a] = &gbMemory[0xa000];
 64.1839 +		gbMemoryMap[0x0b] = &gbMemory[0xb000];
 64.1840 +		gbMemoryMap[0x0c] = &gbMemory[0xc000];
 64.1841 +		gbMemoryMap[0x0d] = &gbWram[0x1000];
 64.1842 +		gbMemoryMap[0x0e] = &gbMemory[0xe000];
 64.1843 +		gbMemoryMap[0x0f] = &gbMemory[0xf000];
 64.1844 +	}
 64.1845 +	else
 64.1846 +	{
 64.1847 +		gbMemoryMap[0x08] = &gbMemory[0x8000];
 64.1848 +		gbMemoryMap[0x09] = &gbMemory[0x9000];
 64.1849 +		gbMemoryMap[0x0a] = &gbMemory[0xa000];
 64.1850 +		gbMemoryMap[0x0b] = &gbMemory[0xb000];
 64.1851 +		gbMemoryMap[0x0c] = &gbMemory[0xc000];
 64.1852 +		gbMemoryMap[0x0d] = &gbMemory[0xd000];
 64.1853 +		gbMemoryMap[0x0e] = &gbMemory[0xe000];
 64.1854 +		gbMemoryMap[0x0f] = &gbMemory[0xf000];
 64.1855 +	}
 64.1856 +
 64.1857 +	if (gbRam)
 64.1858 +	{
 64.1859 +		gbMemoryMap[0x0a] = &gbRam[0x0000];
 64.1860 +		gbMemoryMap[0x0b] = &gbRam[0x1000];
 64.1861 +	}
 64.1862 +
 64.1863 +	gbSoundReset();
 64.1864 +
 64.1865 +	systemResetSensor();
 64.1866 +
 64.1867 +	systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
 64.1868 +
 64.1869 +	gbLastTime	 = systemGetClock();
 64.1870 +	gbFrameCount = 0;
 64.1871 +
 64.1872 +	systemRefreshScreen();
 64.1873 +}
 64.1874 +
 64.1875 +void gbWriteSaveMBC1(const char *name)
 64.1876 +{
 64.1877 +	FILE *gzFile = fopen(name, "wb");
 64.1878 +
 64.1879 +	if (gzFile == NULL)
 64.1880 +	{
 64.1881 +		systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name);
 64.1882 +		return;
 64.1883 +	}
 64.1884 +
 64.1885 +	fwrite(gbRam,
 64.1886 +	       1,
 64.1887 +	       gbRamSize,
 64.1888 +	       gzFile);
 64.1889 +
 64.1890 +	fclose(gzFile);
 64.1891 +}
 64.1892 +
 64.1893 +void gbWriteSaveMBC2(const char *name)
 64.1894 +{
 64.1895 +	FILE *file = fopen(name, "wb");
 64.1896 +
 64.1897 +	if (file == NULL)
 64.1898 +	{
 64.1899 +		systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name);
 64.1900 +		return;
 64.1901 +	}
 64.1902 +
 64.1903 +	fwrite(&gbMemory[0xa000],
 64.1904 +	       1,
 64.1905 +	       256,
 64.1906 +	       file);
 64.1907 +
 64.1908 +	fclose(file);
 64.1909 +}
 64.1910 +
 64.1911 +void gbWriteSaveMBC3(const char *name, bool extendedSave)
 64.1912 +{
 64.1913 +	FILE *gzFile = fopen(name, "wb");
 64.1914 +
 64.1915 +	if (gzFile == NULL)
 64.1916 +	{
 64.1917 +		systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name);
 64.1918 +		return;
 64.1919 +	}
 64.1920 +
 64.1921 +	fwrite(gbRam,
 64.1922 +	       1,
 64.1923 +	       gbRamSize,
 64.1924 +	       gzFile);
 64.1925 +
 64.1926 +	if (extendedSave)
 64.1927 +	{
 64.1928 +		//assert(sizeof(time_t) == 4);
 64.1929 +		fwrite(&gbDataMBC3.mapperSeconds,
 64.1930 +		       1,
 64.1931 +		       10 * sizeof(int32) + /*sizeof(time_t)*/4,
 64.1932 +		       gzFile);
 64.1933 +	}
 64.1934 +
 64.1935 +	fclose(gzFile);
 64.1936 +}
 64.1937 +
 64.1938 +void gbWriteSaveMBC5(const char *name)
 64.1939 +{
 64.1940 +	FILE *gzFile = fopen(name, "wb");
 64.1941 +
 64.1942 +	if (gzFile == NULL)
 64.1943 +	{
 64.1944 +		systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name);
 64.1945 +		return;
 64.1946 +	}
 64.1947 +
 64.1948 +	fwrite(gbRam,
 64.1949 +	       1,
 64.1950 +	       gbRamSize,
 64.1951 +	       gzFile);
 64.1952 +
 64.1953 +	fclose(gzFile);
 64.1954 +}
 64.1955 +
 64.1956 +void gbWriteSaveMBC7(const char *name)
 64.1957 +{
 64.1958 +	FILE *file = fopen(name, "wb");
 64.1959 +
 64.1960 +	if (file == NULL)
 64.1961 +	{
 64.1962 +		systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name);
 64.1963 +		return;
 64.1964 +	}
 64.1965 +
 64.1966 +	fwrite(&gbMemory[0xa000],
 64.1967 +	       1,
 64.1968 +	       256,
 64.1969 +	       file);
 64.1970 +
 64.1971 +	fclose(file);
 64.1972 +}
 64.1973 +
 64.1974 +bool gbReadSaveMBC1(const char *name)
 64.1975 +{
 64.1976 +	gzFile gzFile = gzopen(name, "rb");
 64.1977 +
 64.1978 +	if (gzFile == NULL)
 64.1979 +	{
 64.1980 +		return false;
 64.1981 +	}
 64.1982 +
 64.1983 +	int read = gzread(gzFile,
 64.1984 +	                  gbRam,
 64.1985 +	                  gbRamSize);
 64.1986 +
 64.1987 +	if (read != gbRamSize)
 64.1988 +	{
 64.1989 +		systemMessage(MSG_FAILED_TO_READ_SGM, N_("Failed to read complete save game %s (%d)"), name, read);
 64.1990 +		gzclose(gzFile);
 64.1991 +		return false;
 64.1992 +	}
 64.1993 +
 64.1994 +	gzclose(gzFile);
 64.1995 +	return true;
 64.1996 +}
 64.1997 +
 64.1998 +bool gbReadSaveMBC2(const char *name)
 64.1999 +{
 64.2000 +	FILE *file = fopen(name, "rb");
 64.2001 +
 64.2002 +	if (file == NULL)
 64.2003 +	{
 64.2004 +		return false;
 64.2005 +	}
 64.2006 +
 64.2007 +	int read = fread(&gbMemory[0xa000],
 64.2008 +	                 1,
 64.2009 +	                 256,
 64.2010 +	                 file);
 64.2011 +
 64.2012 +	if (read != 256)
 64.2013 +	{
 64.2014 +		systemMessage(MSG_FAILED_TO_READ_SGM,
 64.2015 +		              N_("Failed to read complete save game %s (%d)"), name, read);
 64.2016 +		fclose(file);
 64.2017 +		return false;
 64.2018 +	}
 64.2019 +
 64.2020 +	fclose(file);
 64.2021 +	return true;
 64.2022 +}
 64.2023 +
 64.2024 +bool gbReadSaveMBC3(const char *name)
 64.2025 +{
 64.2026 +	gzFile gzFile = gzopen(name, "rb");
 64.2027 +
 64.2028 +	if (gzFile == NULL)
 64.2029 +	{
 64.2030 +		return false;
 64.2031 +	}
 64.2032 +
 64.2033 +	int read = gzread(gzFile,
 64.2034 +	                  gbRam,
 64.2035 +	                  gbRamSize);
 64.2036 +
 64.2037 +	bool res = true;
 64.2038 +
 64.2039 +	if (read != gbRamSize)
 64.2040 +	{
 64.2041 +		systemMessage(MSG_FAILED_TO_READ_SGM,
 64.2042 +		              N_("Failed to read complete save game %s (%d)"), name, read);
 64.2043 +	}
 64.2044 +	else
 64.2045 +	{
 64.2046 +		//assert(sizeof(time_t) == 4);
 64.2047 +		read = gzread(gzFile,
 64.2048 +		              &gbDataMBC3.mapperSeconds,
 64.2049 +		              sizeof(int32) * 10 + /*sizeof(time_t)*/4);
 64.2050 +
 64.2051 +		if (read != (sizeof(int32) * 10 + /*sizeof(time_t)*/4) && read != 0)
 64.2052 +		{
 64.2053 +			systemMessage(MSG_FAILED_TO_READ_RTC,
 64.2054 +			              N_("Failed to read RTC from save game %s (continuing)"),
 64.2055 +			              name);
 64.2056 +			res = false;
 64.2057 +		}
 64.2058 +	}
 64.2059 +
 64.2060 +	gzclose(gzFile);
 64.2061 +	return res;
 64.2062 +}
 64.2063 +
 64.2064 +bool gbReadSaveMBC5(const char *name)
 64.2065 +{
 64.2066 +	gzFile gzFile = gzopen(name, "rb");
 64.2067 +
 64.2068 +	if (gzFile == NULL)
 64.2069 +	{
 64.2070 +		return false;
 64.2071 +	}
 64.2072 +
 64.2073 +	int read = gzread(gzFile,
 64.2074 +	                  gbRam,
 64.2075 +	                  gbRamSize);
 64.2076 +
 64.2077 +	if (read != gbRamSize)
 64.2078 +	{
 64.2079 +		systemMessage(MSG_FAILED_TO_READ_SGM,
 64.2080 +		              N_("Failed to read complete save game %s (%d)"), name, read);
 64.2081 +		gzclose(gzFile);
 64.2082 +		return false;
 64.2083 +	}
 64.2084 +
 64.2085 +	gzclose(gzFile);
 64.2086 +	return true;
 64.2087 +}
 64.2088 +
 64.2089 +bool gbReadSaveMBC7(const char *name)
 64.2090 +{
 64.2091 +	FILE *file = fopen(name, "rb");
 64.2092 +
 64.2093 +	if (file == NULL)
 64.2094 +	{
 64.2095 +		return false;
 64.2096 +	}
 64.2097 +
 64.2098 +	int read = fread(&gbMemory[0xa000],
 64.2099 +	                 1,
 64.2100 +	                 256,
 64.2101 +	                 file);
 64.2102 +
 64.2103 +	if (read != 256)
 64.2104 +	{
 64.2105 +		systemMessage(MSG_FAILED_TO_READ_SGM,
 64.2106 +		              N_("Failed to read complete save game %s (%d)"), name, read);
 64.2107 +		fclose(file);
 64.2108 +		return false;
 64.2109 +	}
 64.2110 +
 64.2111 +	fclose(file);
 64.2112 +	return true;
 64.2113 +}
 64.2114 +
 64.2115 +#if 0
 64.2116 +bool gbLoadBIOS(const char *biosFileName, bool useBiosFile)
 64.2117 +{
 64.2118 +	useBios = false;
 64.2119 +	if (useBiosFile)
 64.2120 +	{
 64.2121 +		useBios = utilLoadBIOS(bios, biosFileName, gbEmulatorType);
 64.2122 +		if (!useBios)
 64.2123 +		{
 64.2124 +			systemMessage(MSG_INVALID_BIOS_FILE_SIZE, N_("Invalid BOOTROM file"));
 64.2125 +		}
 64.2126 +	}
 64.2127 +	return useBios;
 64.2128 +}
 64.2129 +#endif
 64.2130 +
 64.2131 +void gbInit()
 64.2132 +{
 64.2133 +	gbGenFilter();
 64.2134 +	gbSgbInit();    // calls gbSgbReset()... whatever
 64.2135 +
 64.2136 +	gbMemory = (u8 *)malloc(65536 + 4);
 64.2137 +	memset(gbMemory, 0, 65536 + 4);
 64.2138 +	memset(gbPalette, 0, 2 * 128);
 64.2139 +
 64.2140 +	// HACK: +4 at start to accomodate the 2xSaI filter reading out of bounds of the leftmost pixel
 64.2141 +	origPix = (u8 *)calloc(1, 4 * 257 * 226 + 4);
 64.2142 +	pix		= origPix + 4;
 64.2143 +
 64.2144 +	gbLineBuffer = (u16 *)malloc(160 * sizeof(u16));
 64.2145 +}
 64.2146 +
 64.2147 +bool gbWriteBatteryFile(const char *file, bool extendedSave)
 64.2148 +{
 64.2149 +	if (gbBattery)
 64.2150 +	{
 64.2151 +		int type = gbRom[0x147];
 64.2152 +
 64.2153 +		switch (type)
 64.2154 +		{
 64.2155 +		case 0x03:
 64.2156 +			gbWriteSaveMBC1(file);
 64.2157 +			break;
 64.2158 +		case 0x06:
 64.2159 +			gbWriteSaveMBC2(file);
 64.2160 +			break;
 64.2161 +		case 0x0f:
 64.2162 +		case 0x10:
 64.2163 +		case 0x13:
 64.2164 +			gbWriteSaveMBC3(file, extendedSave);
 64.2165 +			break;
 64.2166 +		case 0x1b:
 64.2167 +		case 0x1e:
 64.2168 +			gbWriteSaveMBC5(file);
 64.2169 +			break;
 64.2170 +		case 0x22:
 64.2171 +			gbWriteSaveMBC7(file);
 64.2172 +			break;
 64.2173 +		case 0xff:
 64.2174 +			gbWriteSaveMBC1(file);
 64.2175 +			break;
 64.2176 +		}
 64.2177 +	}
 64.2178 +	return true;
 64.2179 +}
 64.2180 +
 64.2181 +bool gbWriteBatteryFile(const char *file)
 64.2182 +{
 64.2183 +	gbWriteBatteryFile(file, true);
 64.2184 +	return true;
 64.2185 +}
 64.2186 +
 64.2187 +bool gbWriteBatteryToStream(gzFile gzfile)
 64.2188 +{
 64.2189 +	// the GB save code is ugly, so rather than convert it all to use gzFiles, just save it to a temp file...
 64.2190 +#define TEMP_SAVE_FNAME ("tempvbawrite.sav")
 64.2191 +	bool retVal = gbWriteBatteryFile(TEMP_SAVE_FNAME, true);
 64.2192 +
 64.2193 +	// ...open the temp file and figure out its size...
 64.2194 +	FILE *fileTemp = fopen(TEMP_SAVE_FNAME, "rb");
 64.2195 +	if (fileTemp == NULL)
 64.2196 +		return false;
 64.2197 +	fseek(fileTemp, 0, SEEK_END);
 64.2198 +	int len = (int) ftell(fileTemp);
 64.2199 +
 64.2200 +	// ...copy over the temp file...
 64.2201 +	char *temp = new char [len];
 64.2202 +	fseek(fileTemp, 0, SEEK_SET);
 64.2203 +	if (fread(temp, len, 1, fileTemp) != 1)
 64.2204 +	{
 64.2205 +		delete [] temp;
 64.2206 +		fclose(fileTemp);
 64.2207 +		return false;
 64.2208 +	}
 64.2209 +	fclose(fileTemp);
 64.2210 +	utilGzWrite(gzfile, temp, len);
 64.2211 +	delete [] temp;
 64.2212 +
 64.2213 +	// ... and delete the temp file
 64.2214 +	remove(TEMP_SAVE_FNAME);
 64.2215 +#undef TEMP_SAVE_FNAME
 64.2216 +
 64.2217 +	return retVal;
 64.2218 +}
 64.2219 +
 64.2220 +bool gbReadBatteryFile(const char *file)
 64.2221 +{
 64.2222 +	bool res = false;
 64.2223 +	if (gbBattery)
 64.2224 +	{
 64.2225 +		int type = gbRom[0x147];
 64.2226 +
 64.2227 +		switch (type)
 64.2228 +		{
 64.2229 +		case 0x03:
 64.2230 +			res = gbReadSaveMBC1(file);
 64.2231 +			break;
 64.2232 +		case 0x06:
 64.2233 +			res = gbReadSaveMBC2(file);
 64.2234 +			break;
 64.2235 +		case 0x0f:
 64.2236 +		case 0x10:
 64.2237 +		case 0x13:
 64.2238 +			if (!gbReadSaveMBC3(file))
 64.2239 +			{
 64.2240 +				struct tm *lt;
 64.2241 +				time_t tmp; //Small kludge to get it working on some systems where time_t has size 8.
 64.2242 +
 64.2243 +				if (VBAMovieActive() || VBAMovieLoading())
 64.2244 +				{
 64.2245 +					gbDataMBC3.mapperLastTime = VBAMovieGetId() + VBAMovieGetFrameCounter() / 60;
 64.2246 +					lt = gmtime(&tmp);
 64.2247 +					gbDataMBC3.mapperLastTime=(u32)tmp;
 64.2248 +				}
 64.2249 +				else
 64.2250 +				{
 64.2251 +					time(&tmp);
 64.2252 +					gbDataMBC3.mapperLastTime=(u32)tmp;
 64.2253 +					lt = localtime(&tmp);
 64.2254 +				}
 64.2255 +				systemScreenMessage(ctime(&tmp), 4);
 64.2256 +				gbDataMBC3.mapperLastTime=(u32)tmp;
 64.2257 +
 64.2258 +				gbDataMBC3.mapperSeconds = lt->tm_sec;
 64.2259 +				gbDataMBC3.mapperMinutes = lt->tm_min;
 64.2260 +				gbDataMBC3.mapperHours	 = lt->tm_hour;
 64.2261 +				gbDataMBC3.mapperDays	 = lt->tm_yday & 255;
 64.2262 +				gbDataMBC3.mapperControl = (gbDataMBC3.mapperControl & 0xfe) |
 64.2263 +				                           (lt->tm_yday > 255 ? 1 : 0);
 64.2264 +				res = false;
 64.2265 +				break;
 64.2266 +			}
 64.2267 +			time_t tmp;
 64.2268 +			systemScreenMessage(ctime(&tmp), 4);
 64.2269 +			gbDataMBC3.mapperLastTime=(u32)tmp;
 64.2270 +			res = true;
 64.2271 +			break;
 64.2272 +		case 0x1b:
 64.2273 +		case 0x1e:
 64.2274 +			res = gbReadSaveMBC5(file);
 64.2275 +			break;
 64.2276 +		case 0x22:
 64.2277 +			res = gbReadSaveMBC7(file);
 64.2278 +		case 0xff:
 64.2279 +			res = gbReadSaveMBC1(file);
 64.2280 +			break;
 64.2281 +		}
 64.2282 +	}
 64.2283 +	systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
 64.2284 +	return res;
 64.2285 +}
 64.2286 +
 64.2287 +bool gbReadBatteryFromStream(gzFile gzfile)
 64.2288 +{
 64.2289 +	// the GB save code is ugly, so rather than convert it all to use gzFiles, just copy it to temp RAM...
 64.2290 +#define TEMP_SAVE_FNAME ("tempvbaread.sav")
 64.2291 +	int	  pos	 = gztell(gzfile);
 64.2292 +	int	  buflen = 1024;
 64.2293 +	// ...make a temp file and write it there...
 64.2294 +	FILE *fileTemp = fopen(TEMP_SAVE_FNAME, "wb");
 64.2295 +	if (fileTemp == NULL)
 64.2296 +		return false;
 64.2297 +	int gzDeflated;
 64.2298 +	char *temp	 = new char [buflen];
 64.2299 +	while ((gzDeflated = utilGzRead(gzfile, temp, buflen)) != 0)
 64.2300 +	{
 64.2301 +		if (gzDeflated == -1 || fwrite(temp, gzDeflated, 1, fileTemp) != 1)
 64.2302 +		{
 64.2303 +			delete [] temp;
 64.2304 +			fclose(fileTemp);
 64.2305 +			gzseek(gzfile, pos, SEEK_SET); /// FIXME: leaves pos in gzfile before save instead of after it (everything that
 64.2306 +			                               // calls this right now does a seek afterwards so it doesn't matter for now, but it's
 64.2307 +			                               // still bad)
 64.2308 +			return false;
 64.2309 +		}
 64.2310 +	}
 64.2311 +	gzseek(gzfile, pos, SEEK_SET); /// FIXME: leaves pos in gzfile before save instead of after it (everything that calls this
 64.2312 +	                               // right now does a seek afterwards so it doesn't matter for now, but it's still bad)
 64.2313 +	fclose(fileTemp);
 64.2314 +	delete [] temp;
 64.2315 +
 64.2316 +	// ... load from the temp file...
 64.2317 +	bool retVal = gbReadBatteryFile(TEMP_SAVE_FNAME);
 64.2318 +
 64.2319 +	// ... and delete the temp file
 64.2320 +	remove(TEMP_SAVE_FNAME);
 64.2321 +#undef TEMP_SAVE_FNAME
 64.2322 +
 64.2323 +	return retVal;
 64.2324 +}
 64.2325 +
 64.2326 +bool gbReadGSASnapshot(const char *fileName)
 64.2327 +{
 64.2328 +	FILE *file = fopen(fileName, "rb");
 64.2329 +
 64.2330 +	if (!file)
 64.2331 +	{
 64.2332 +		systemMessage(MSG_CANNOT_OPEN_FILE, N_("Cannot open file %s"), fileName);
 64.2333 +		return false;
 64.2334 +	}
 64.2335 +
 64.2336 +	//  long size = ftell(file);
 64.2337 +	fseek(file, 0x4, SEEK_SET);
 64.2338 +	char buffer[16];
 64.2339 +	char buffer2[16];
 64.2340 +	fread(buffer, 1, 15, file);
 64.2341 +	buffer[15] = 0;
 64.2342 +	memcpy(buffer2, &gbRom[0x134], 15);
 64.2343 +	buffer2[15] = 0;
 64.2344 +	if (memcmp(buffer, buffer2, 15))
 64.2345 +	{
 64.2346 +		systemMessage(MSG_CANNOT_IMPORT_SNAPSHOT_FOR,
 64.2347 +		              N_("Cannot import snapshot for %s. Current game is %s"),
 64.2348 +		              buffer,
 64.2349 +		              buffer2);
 64.2350 +		fclose(file);
 64.2351 +		return false;
 64.2352 +	}
 64.2353 +	fseek(file, 0x13, SEEK_SET);
 64.2354 +	int read   = 0;
 64.2355 +	int toRead = 0;
 64.2356 +	switch (gbRom[0x147])
 64.2357 +	{
 64.2358 +	case 0x03:
 64.2359 +	case 0x0f:
 64.2360 +	case 0x10:
 64.2361 +	case 0x13:
 64.2362 +	case 0x1b:
 64.2363 +	case 0x1e:
 64.2364 +	case 0xff:
 64.2365 +		read   = fread(gbRam, 1, gbRamSize, file);
 64.2366 +		toRead = gbRamSize;
 64.2367 +		break;
 64.2368 +	case 0x06:
 64.2369 +	case 0x22:
 64.2370 +		read   = fread(&gbMemory[0xa000], 1, 256, file);
 64.2371 +		toRead = 256;
 64.2372 +		break;
 64.2373 +	default:
 64.2374 +		systemMessage(MSG_UNSUPPORTED_SNAPSHOT_FILE,
 64.2375 +		              N_("Unsupported snapshot file %s"),
 64.2376 +		              fileName);
 64.2377 +		fclose(file);
 64.2378 +		return false;
 64.2379 +	}
 64.2380 +	fclose(file);
 64.2381 +	gbReset();
 64.2382 +	return true;
 64.2383 +}
 64.2384 +
 64.2385 +variable_desc gbSaveGameStruct[] =
 64.2386 +{
 64.2387 +	{ &PC.W,					   sizeof(u16)						 },
 64.2388 +	{ &SP.W,					   sizeof(u16)						 },
 64.2389 +	{ &AF.W,					   sizeof(u16)						 },
 64.2390 +	{ &BC.W,					   sizeof(u16)						 },
 64.2391 +	{ &DE.W,					   sizeof(u16)						 },
 64.2392 +	{ &HL.W,					   sizeof(u16)						 },
 64.2393 +	{ &IFF,						   sizeof(u8)						 },
 64.2394 +	{ &GBLCD_MODE_0_CLOCK_TICKS,   sizeof(int32)					 },
 64.2395 +	{ &GBLCD_MODE_1_CLOCK_TICKS,   sizeof(int32)					 },
 64.2396 +	{ &GBLCD_MODE_2_CLOCK_TICKS,   sizeof(int32)					 },
 64.2397 +	{ &GBLCD_MODE_3_CLOCK_TICKS,   sizeof(int32)					 },
 64.2398 +	{ &GBDIV_CLOCK_TICKS,		   sizeof(int32)					 },
 64.2399 +	{ &GBLY_INCREMENT_CLOCK_TICKS, sizeof(int32)					 },
 64.2400 +	{ &GBTIMER_MODE_0_CLOCK_TICKS, sizeof(int32)					 },
 64.2401 +	{ &GBTIMER_MODE_1_CLOCK_TICKS, sizeof(int32)					 },
 64.2402 +	{ &GBTIMER_MODE_2_CLOCK_TICKS, sizeof(int32)					 },
 64.2403 +	{ &GBTIMER_MODE_3_CLOCK_TICKS, sizeof(int32)					 },
 64.2404 +	{ &GBSERIAL_CLOCK_TICKS,	   sizeof(int32)					 },
 64.2405 +	{ &GBSYNCHRONIZE_CLOCK_TICKS,  sizeof(int32)					 },
 64.2406 +	{ &gbDivTicks,				   sizeof(int32)					 },
 64.2407 +	{ &gbLcdMode,				   sizeof(int32)					 },
 64.2408 +	{ &gbLcdTicks,				   sizeof(int32)					 },
 64.2409 +	{ &gbLcdLYIncrementTicks,	   sizeof(int32)					 },
 64.2410 +	{ &gbTimerTicks,			   sizeof(int32)					 },
 64.2411 +	{ &gbTimerClockTicks,		   sizeof(int32)					 },
 64.2412 +	{ &gbSerialTicks,			   sizeof(int32)					 },
 64.2413 +	{ &gbSerialBits,			   sizeof(int32)					 },
 64.2414 +	{ &gbInterrupt,				   sizeof(int32)					 },
 64.2415 +	{ &gbInterruptWait,			   sizeof(int32)					 },
 64.2416 +	{ &gbSynchronizeTicks,		   sizeof(int32)					 },
 64.2417 +	{ &gbTimerOn,				   sizeof(int32)					 },
 64.2418 +	{ &gbTimerMode,				   sizeof(int32)					 },
 64.2419 +	{ &gbSerialOn,				   sizeof(int32)					 },
 64.2420 +	{ &gbWindowLine,			   sizeof(int32)					 },
 64.2421 +	{ &gbCgbMode,				   sizeof(int32)					 },
 64.2422 +	{ &gbVramBank,				   sizeof(int32)					 },
 64.2423 +	{ &gbWramBank,				   sizeof(int32)					 },
 64.2424 +	{ &gbHdmaSource,			   sizeof(int32)					 },
 64.2425 +	{ &gbHdmaDestination,		   sizeof(int32)					 },
 64.2426 +	{ &gbHdmaBytes,				   sizeof(int32)					 },
 64.2427 +	{ &gbHdmaOn,				   sizeof(int32)					 },
 64.2428 +	{ &gbSpeed,					   sizeof(int32)					 },
 64.2429 +	{ &gbSgbMode,				   sizeof(int32)					 },
 64.2430 +	{ &register_DIV,			   sizeof(u8)						 },
 64.2431 +	{ &register_TIMA,			   sizeof(u8)						 },
 64.2432 +	{ &register_TMA,			   sizeof(u8)						 },
 64.2433 +	{ &register_TAC,			   sizeof(u8)						 },
 64.2434 +	{ &register_IF,				   sizeof(u8)						 },
 64.2435 +	{ &register_LCDC,			   sizeof(u8)						 },
 64.2436 +	{ &register_STAT,			   sizeof(u8)						 },
 64.2437 +	{ &register_SCY,			   sizeof(u8)						 },
 64.2438 +	{ &register_SCX,			   sizeof(u8)						 },
 64.2439 +	{ &register_LY,				   sizeof(u8)						 },
 64.2440 +	{ &register_LYC,			   sizeof(u8)						 },
 64.2441 +	{ &register_DMA,			   sizeof(u8)						 },
 64.2442 +	{ &register_WY,				   sizeof(u8)						 },
 64.2443 +	{ &register_WX,				   sizeof(u8)						 },
 64.2444 +	{ &register_VBK,			   sizeof(u8)						 },
 64.2445 +	{ &register_HDMA1,			   sizeof(u8)						 },
 64.2446 +	{ &register_HDMA2,			   sizeof(u8)						 },
 64.2447 +	{ &register_HDMA3,			   sizeof(u8)						 },
 64.2448 +	{ &register_HDMA4,			   sizeof(u8)						 },
 64.2449 +	{ &register_HDMA5,			   sizeof(u8)						 },
 64.2450 +	{ &register_SVBK,			   sizeof(u8)						 },
 64.2451 +	{ &register_IE,				   sizeof(u8)						 },
 64.2452 +	{ &gbBgp[0],				   sizeof(u8)						 },
 64.2453 +	{ &gbBgp[1],				   sizeof(u8)						 },
 64.2454 +	{ &gbBgp[2],				   sizeof(u8)						 },
 64.2455 +	{ &gbBgp[3],				   sizeof(u8)						 },
 64.2456 +	{ &gbObp0[0],				   sizeof(u8)						 },
 64.2457 +	{ &gbObp0[1],				   sizeof(u8)						 },
 64.2458 +	{ &gbObp0[2],				   sizeof(u8)						 },
 64.2459 +	{ &gbObp0[3],				   sizeof(u8)						 },
 64.2460 +	{ &gbObp1[0],				   sizeof(u8)						 },
 64.2461 +	{ &gbObp1[1],				   sizeof(u8)						 },
 64.2462 +	{ &gbObp1[2],				   sizeof(u8)						 },
 64.2463 +	{ &gbObp1[3],				   sizeof(u8)						 },
 64.2464 +	{ NULL,						   0								 }
 64.2465 +};
 64.2466 +
 64.2467 +bool gbWriteSaveStateToStream(gzFile gzFile)
 64.2468 +{
 64.2469 +	utilWriteInt(gzFile, GBSAVE_GAME_VERSION);
 64.2470 +
 64.2471 +	utilGzWrite(gzFile, &gbRom[0x134], 15);
 64.2472 +
 64.2473 +	utilWriteData(gzFile, gbSaveGameStruct);
 64.2474 +
 64.2475 +	utilGzWrite(gzFile, &IFF, 2);
 64.2476 +
 64.2477 +	if (gbSgbMode)
 64.2478 +	{
 64.2479 +		gbSgbSaveGame(gzFile);
 64.2480 +	}
 64.2481 +
 64.2482 +	utilGzWrite(gzFile, &gbDataMBC1, sizeof(gbDataMBC1));
 64.2483 +	utilGzWrite(gzFile, &gbDataMBC2, sizeof(gbDataMBC2));
 64.2484 +	//assert(sizeof(time_t) == 4);
 64.2485 +	utilGzWrite(gzFile, &gbDataMBC3, sizeof(gbDataMBC3));
 64.2486 +	utilGzWrite(gzFile, &gbDataMBC5, sizeof(gbDataMBC5));
 64.2487 +	utilGzWrite(gzFile, &gbDataHuC1, sizeof(gbDataHuC1));
 64.2488 +	utilGzWrite(gzFile, &gbDataHuC3, sizeof(gbDataHuC3));
 64.2489 +
 64.2490 +	// yes, this definitely needs to be saved, or loading paused games will show a black screen
 64.2491 +	// this is also necessary to be consistent with what the GBA saving does
 64.2492 +	utilGzWrite(gzFile, pix, 4 * 257 * 226);
 64.2493 +
 64.2494 +	utilGzWrite(gzFile, gbPalette, 128 * sizeof(u16));
 64.2495 +	// todo: remove
 64.2496 +	utilGzWrite(gzFile, gbPalette, 128 * sizeof(u16));
 64.2497 +
 64.2498 +	utilGzWrite(gzFile, &gbMemory[0x8000], 0x8000);
 64.2499 +
 64.2500 +	if (gbRamSize && gbRam)
 64.2501 +	{
 64.2502 +		utilGzWrite(gzFile, gbRam, gbRamSize);
 64.2503 +	}
 64.2504 +
 64.2505 +	if (gbCgbMode)
 64.2506 +	{
 64.2507 +		utilGzWrite(gzFile, gbVram, 0x4000);
 64.2508 +		utilGzWrite(gzFile, gbWram, 0x8000);
 64.2509 +	}
 64.2510 +
 64.2511 +	gbSoundSaveGame(gzFile);
 64.2512 +
 64.2513 +	gbCheatsSaveGame(gzFile);
 64.2514 +
 64.2515 +	// new to re-recording version:
 64.2516 +	{
 64.2517 +		extern int32 sensorX, sensorY;
 64.2518 +		utilGzWrite(gzFile, &sensorX, sizeof(sensorX));
 64.2519 +		utilGzWrite(gzFile, &sensorY, sizeof(sensorY));
 64.2520 +		utilGzWrite(gzFile, gbJoymask, 4 * sizeof(*gbJoymask)); // this has to be saved or old input will incorrectly get
 64.2521 +		                                                        // carried
 64.2522 +		                                                        // back on loading a snapshot!
 64.2523 +
 64.2524 +		bool8 movieActive = VBAMovieActive();
 64.2525 +		utilGzWrite(gzFile, &movieActive, sizeof(movieActive));
 64.2526 +		if (movieActive)
 64.2527 +		{
 64.2528 +			uint8 *movie_freeze_buf	 = NULL;
 64.2529 +			uint32 movie_freeze_size = 0;
 64.2530 +
 64.2531 +			VBAMovieFreeze(&movie_freeze_buf, &movie_freeze_size);
 64.2532 +			if (movie_freeze_buf)
 64.2533 +			{
 64.2534 +				utilGzWrite(gzFile, &movie_freeze_size, sizeof(movie_freeze_size));
 64.2535 +				utilGzWrite(gzFile, movie_freeze_buf, movie_freeze_size);
 64.2536 +				delete [] movie_freeze_buf;
 64.2537 +			}
 64.2538 +			else
 64.2539 +			{
 64.2540 +				systemMessage(0, N_("Failed to save movie snapshot."));
 64.2541 +				return false;
 64.2542 +			}
 64.2543 +		}
 64.2544 +		utilGzWrite(gzFile, &GBSystemCounters.frameCount, sizeof(GBSystemCounters.frameCount));
 64.2545 +	}
 64.2546 +
 64.2547 +	// new to rerecording 19.4 wip (svn r22+):
 64.2548 +	{
 64.2549 +		utilGzWrite(gzFile, &GBSystemCounters.lagCount, sizeof(GBSystemCounters.lagCount));
 64.2550 +		utilGzWrite(gzFile, &GBSystemCounters.lagged, sizeof(GBSystemCounters.lagged));
 64.2551 +		utilGzWrite(gzFile, &GBSystemCounters.laggedLast, sizeof(GBSystemCounters.laggedLast));
 64.2552 +	}
 64.2553 +
 64.2554 +	return true;
 64.2555 +}
 64.2556 +
 64.2557 +bool gbWriteMemSaveState(char *memory, int available)
 64.2558 +{
 64.2559 +	gzFile gzFile = utilMemGzOpen(memory, available, "w");
 64.2560 +
 64.2561 +	if (gzFile == NULL)
 64.2562 +	{
 64.2563 +		return false;
 64.2564 +	}
 64.2565 +
 64.2566 +	bool res = gbWriteSaveStateToStream(gzFile);
 64.2567 +
 64.2568 +	long pos = utilGzTell(gzFile) + 8;
 64.2569 +
 64.2570 +	if (pos >= (available))
 64.2571 +		res = false;
 64.2572 +
 64.2573 +	utilGzClose(gzFile);
 64.2574 +
 64.2575 +	return res;
 64.2576 +}
 64.2577 +
 64.2578 +bool gbWriteSaveState(const char *name)
 64.2579 +{
 64.2580 +	gzFile gzFile = utilGzOpen(name, "wb");
 64.2581 +
 64.2582 +	if (gzFile == NULL)
 64.2583 +		return false;
 64.2584 +
 64.2585 +	bool res = gbWriteSaveStateToStream(gzFile);
 64.2586 +
 64.2587 +	utilGzClose(gzFile);
 64.2588 +	return res;
 64.2589 +}
 64.2590 +
 64.2591 +static int	tempStateID	  = 0;
 64.2592 +static int	tempFailCount = 0;
 64.2593 +static bool backupSafe	  = true;
 64.2594 +
 64.2595 +bool gbReadSaveStateFromStream(gzFile gzFile)
 64.2596 +{
 64.2597 +	int	 type;
 64.2598 +	char tempBackupName [128];
 64.2599 +	if (backupSafe)
 64.2600 +	{
 64.2601 +		sprintf(tempBackupName, "gbatempsave%d.sav", tempStateID++);
 64.2602 +		gbWriteSaveState(tempBackupName);
 64.2603 +	}
 64.2604 +
 64.2605 +	int version = utilReadInt(gzFile);
 64.2606 +
 64.2607 +	if (version > GBSAVE_GAME_VERSION || version < 0)
 64.2608 +	{
 64.2609 +		systemMessage(MSG_UNSUPPORTED_VB_SGM,
 64.2610 +		              N_("Unsupported VisualBoy save game version %d"), version);
 64.2611 +		goto failedLoadGB;
 64.2612 +	}
 64.2613 +
 64.2614 +	u8 romname[20];
 64.2615 +
 64.2616 +	utilGzRead(gzFile, romname, 15);
 64.2617 +
 64.2618 +	if (memcmp(&gbRom[0x134], romname, 15) != 0)
 64.2619 +	{
 64.2620 +		systemMessage(MSG_CANNOT_LOAD_SGM_FOR,
 64.2621 +		              N_("Cannot load save game for %s. Playing %s"),
 64.2622 +		              romname, &gbRom[0x134]);
 64.2623 +		goto failedLoadGB;
 64.2624 +	}
 64.2625 +
 64.2626 +	utilReadData(gzFile, gbSaveGameStruct);
 64.2627 +
 64.2628 +	if (version >= GBSAVE_GAME_VERSION_7)
 64.2629 +	{
 64.2630 +		utilGzRead(gzFile, &IFF, 2);
 64.2631 +	}
 64.2632 +
 64.2633 +	if (gbSgbMode)
 64.2634 +	{
 64.2635 +		gbSgbReadGame(gzFile, version);
 64.2636 +	}
 64.2637 +	else
 64.2638 +	{
 64.2639 +		gbSgbMask = 0; // loading a game at the wrong time causes no display
 64.2640 +	}
 64.2641 +
 64.2642 +	utilGzRead(gzFile, &gbDataMBC1, sizeof(gbDataMBC1));
 64.2643 +	utilGzRead(gzFile, &gbDataMBC2, sizeof(gbDataMBC2));
 64.2644 +	if (version < GBSAVE_GAME_VERSION_4)
 64.2645 +		// prior to version 4, there was no adjustment for the time the game
 64.2646 +		// was last played, so we have less to read. This needs update if the
 64.2647 +		// structure changes again.
 64.2648 +		utilGzRead(gzFile, &gbDataMBC3, sizeof(int32) * 10);
 64.2649 +	else
 64.2650 +	{
 64.2651 +		//assert(sizeof(time_t) == 4);
 64.2652 +		utilGzRead(gzFile, &gbDataMBC3, sizeof(gbDataMBC3));
 64.2653 +	}
 64.2654 +	utilGzRead(gzFile, &gbDataMBC5, sizeof(gbDataMBC5));
 64.2655 +	utilGzRead(gzFile, &gbDataHuC1, sizeof(gbDataHuC1));
 64.2656 +	utilGzRead(gzFile, &gbDataHuC3, sizeof(gbDataHuC3));
 64.2657 +
 64.2658 +	if (version >= GBSAVE_GAME_VERSION_12)
 64.2659 +	{
 64.2660 +		utilGzRead(gzFile, pix, 4 * 257 * 226);
 64.2661 +	}
 64.2662 +	else
 64.2663 +	{
 64.2664 +		memset(pix, 0, 257 * 226 * sizeof(u32));
 64.2665 +//		if(version < GBSAVE_GAME_VERSION_5)
 64.2666 +//			utilGzRead(gzFile, pix, 256*224*sizeof(u16));
 64.2667 +	}
 64.2668 +
 64.2669 +	if (version < GBSAVE_GAME_VERSION_6)
 64.2670 +	{
 64.2671 +		utilGzRead(gzFile, gbPalette, 64 * sizeof(u16));
 64.2672 +	}
 64.2673 +	else
 64.2674 +		utilGzRead(gzFile, gbPalette, 128 * sizeof(u16));
 64.2675 +
 64.2676 +	// todo: remove
 64.2677 +	utilGzRead(gzFile, gbPalette, 128 * sizeof(u16));
 64.2678 +
 64.2679 +	if (version < GBSAVE_GAME_VERSION_10)
 64.2680 +	{
 64.2681 +		if (!gbCgbMode && !gbSgbMode)
 64.2682 +		{
 64.2683 +			for (int i = 0; i < 8; i++)
 64.2684 +				gbPalette[i] = systemGbPalette[gbPaletteOption * 8 + i];
 64.2685 +		}
 64.2686 +	}
 64.2687 +
 64.2688 +	utilGzRead(gzFile, &gbMemory[0x8000], 0x8000);
 64.2689 +
 64.2690 +	if (gbRamSize && gbRam)
 64.2691 +	{
 64.2692 +		utilGzRead(gzFile, gbRam, gbRamSize);
 64.2693 +	}
 64.2694 +
 64.2695 +	gbMemoryMap[0x00] = &gbRom[0x0000];
 64.2696 +	gbMemoryMap[0x01] = &gbRom[0x1000];
 64.2697 +	gbMemoryMap[0x02] = &gbRom[0x2000];
 64.2698 +	gbMemoryMap[0x03] = &gbRom[0x3000];
 64.2699 +	gbMemoryMap[0x04] = &gbRom[0x4000];
 64.2700 +	gbMemoryMap[0x05] = &gbRom[0x5000];
 64.2701 +	gbMemoryMap[0x06] = &gbRom[0x6000];
 64.2702 +	gbMemoryMap[0x07] = &gbRom[0x7000];
 64.2703 +	gbMemoryMap[0x08] = &gbMemory[0x8000];
 64.2704 +	gbMemoryMap[0x09] = &gbMemory[0x9000];
 64.2705 +	gbMemoryMap[0x0a] = &gbMemory[0xa000];
 64.2706 +	gbMemoryMap[0x0b] = &gbMemory[0xb000];
 64.2707 +	gbMemoryMap[0x0c] = &gbMemory[0xc000];
 64.2708 +	gbMemoryMap[0x0d] = &gbMemory[0xd000];
 64.2709 +	gbMemoryMap[0x0e] = &gbMemory[0xe000];
 64.2710 +	gbMemoryMap[0x0f] = &gbMemory[0xf000];
 64.2711 +
 64.2712 +	type = gbRom[0x147];
 64.2713 +
 64.2714 +	switch (type)
 64.2715 +	{
 64.2716 +	case 0x00:
 64.2717 +	case 0x01:
 64.2718 +	case 0x02:
 64.2719 +	case 0x03:
 64.2720 +		// MBC 1
 64.2721 +		memoryUpdateMapMBC1();
 64.2722 +		break;
 64.2723 +	case 0x05:
 64.2724 +	case 0x06:
 64.2725 +		// MBC2
 64.2726 +		memoryUpdateMapMBC2();
 64.2727 +		break;
 64.2728 +	case 0x0f:
 64.2729 +	case 0x10:
 64.2730 +	case 0x11:
 64.2731 +	case 0x12:
 64.2732 +	case 0x13:
 64.2733 +		// MBC 3
 64.2734 +		memoryUpdateMapMBC3();
 64.2735 +		break;
 64.2736 +	case 0x19:
 64.2737 +	case 0x1a:
 64.2738 +	case 0x1b:
 64.2739 +		// MBC5
 64.2740 +		memoryUpdateMapMBC5();
 64.2741 +		break;
 64.2742 +	case 0x1c:
 64.2743 +	case 0x1d:
 64.2744 +	case 0x1e:
 64.2745 +		// MBC 5 Rumble
 64.2746 +		memoryUpdateMapMBC5();
 64.2747 +		break;
 64.2748 +	case 0x22:
 64.2749 +		// MBC 7
 64.2750 +		memoryUpdateMapMBC7();
 64.2751 +		break;
 64.2752 +	case 0xfe:
 64.2753 +		// HuC3
 64.2754 +		memoryUpdateMapHuC3();
 64.2755 +		break;
 64.2756 +	case 0xff:
 64.2757 +		// HuC1
 64.2758 +		memoryUpdateMapHuC1();
 64.2759 +		break;
 64.2760 +	}
 64.2761 +
 64.2762 +	if (gbCgbMode)
 64.2763 +	{
 64.2764 +		if (!gbVram)
 64.2765 +			gbVram = (u8 *)malloc(0x4000 + 4);
 64.2766 +		if (!gbWram)
 64.2767 +			gbWram = (u8 *)malloc(0x8000 + 4);
 64.2768 +		utilGzRead(gzFile, gbVram, 0x4000);
 64.2769 +		utilGzRead(gzFile, gbWram, 0x8000);
 64.2770 +
 64.2771 +		int value = register_SVBK;
 64.2772 +		if (value == 0)
 64.2773 +			value = 1;
 64.2774 +
 64.2775 +		gbMemoryMap[0x08] = &gbVram[register_VBK * 0x2000];
 64.2776 +		gbMemoryMap[0x09] = &gbVram[register_VBK * 0x2000 + 0x1000];
 64.2777 +		gbMemoryMap[0x0d] = &gbWram[value * 0x1000];
 64.2778 +	}
 64.2779 +	else
 64.2780 +	{
 64.2781 +		if (gbVram)
 64.2782 +		{
 64.2783 +			free(gbVram);
 64.2784 +			gbVram = NULL;
 64.2785 +		}
 64.2786 +		if (gbWram)
 64.2787 +		{
 64.2788 +			free(gbWram);
 64.2789 +			gbWram = NULL;
 64.2790 +		}
 64.2791 +	}
 64.2792 +
 64.2793 +	gbSoundReadGame(version, gzFile);
 64.2794 +
 64.2795 +#if 0
 64.2796 +	if (gbBorderOn)
 64.2797 +	{
 64.2798 +		gbSgbRenderBorder();
 64.2799 +	}
 64.2800 +
 64.2801 +	systemRefreshScreen();
 64.2802 +#endif
 64.2803 +
 64.2804 +	if (version > GBSAVE_GAME_VERSION_1)
 64.2805 +		gbCheatsReadGame(gzFile, version);
 64.2806 +
 64.2807 +	systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
 64.2808 +
 64.2809 +	if (version >= GBSAVE_GAME_VERSION_11) // new to re-recording version:
 64.2810 +	{
 64.2811 +		extern int32 sensorX, sensorY; // from SDL.cpp
 64.2812 +		utilGzRead(gzFile, &sensorX, sizeof(sensorX));
 64.2813 +		utilGzRead(gzFile, &sensorY, sizeof(sensorY));
 64.2814 +		utilGzRead(gzFile, gbJoymask, 4 * sizeof(*gbJoymask)); // this has to be saved or old input will incorrectly get carried
 64.2815 +		                                                       // back on loading a snapshot!
 64.2816 +
 64.2817 +		bool8 movieSnapshot;
 64.2818 +		utilGzRead(gzFile, &movieSnapshot, sizeof(movieSnapshot));
 64.2819 +		if (VBAMovieActive() && !movieSnapshot)
 64.2820 +		{
 64.2821 +			systemMessage(0, N_("Can't load a non-movie snapshot while a movie is active."));
 64.2822 +			goto failedLoadGB;
 64.2823 +		}
 64.2824 +
 64.2825 +		if (movieSnapshot) // even if a movie isn't active we still want to parse through this in case other stuff is added
 64.2826 +		                   // later on in the save format
 64.2827 +		{
 64.2828 +			uint32 movieInputDataSize = 0;
 64.2829 +			utilGzRead(gzFile, &movieInputDataSize, sizeof(movieInputDataSize));
 64.2830 +			uint8 *local_movie_data = new uint8 [movieInputDataSize];
 64.2831 +			int	   readBytes		= utilGzRead(gzFile, local_movie_data, movieInputDataSize);
 64.2832 +			if (readBytes != movieInputDataSize)
 64.2833 +			{
 64.2834 +				systemMessage(0, N_("Corrupt movie snapshot."));
 64.2835 +				if (local_movie_data)
 64.2836 +					delete [] local_movie_data;
 64.2837 +				goto failedLoadGB;
 64.2838 +			}
 64.2839 +			int code = VBAMovieUnfreeze(local_movie_data, movieInputDataSize);
 64.2840 +			if (local_movie_data)
 64.2841 +				delete [] local_movie_data;
 64.2842 +			if (code != MOVIE_SUCCESS && VBAMovieActive())
 64.2843 +			{
 64.2844 +				char errStr [1024];
 64.2845 +				strcpy(errStr, "Failed to load movie snapshot");
 64.2846 +				switch (code)
 64.2847 +				{
 64.2848 +				case MOVIE_NOT_FROM_THIS_MOVIE:
 64.2849 +					strcat(errStr, ";\nSnapshot not from this movie"); break;
 64.2850 +				case MOVIE_NOT_FROM_A_MOVIE:
 64.2851 +					strcat(errStr, ";\nNot a movie snapshot"); break;                    // shouldn't get here...
 64.2852 +				case MOVIE_SNAPSHOT_INCONSISTENT:
 64.2853 +					strcat(errStr, ";\nSnapshot inconsistent with movie"); break;
 64.2854 +				case MOVIE_WRONG_FORMAT:
 64.2855 +					strcat(errStr, ";\nWrong format"); break;
 64.2856 +				}
 64.2857 +				strcat(errStr, ".");
 64.2858 +				systemMessage(0, N_(errStr));
 64.2859 +				goto failedLoadGB;
 64.2860 +			}
 64.2861 +		}
 64.2862 +		utilGzRead(gzFile, &GBSystemCounters.frameCount, sizeof(GBSystemCounters.frameCount));
 64.2863 +	}
 64.2864 +
 64.2865 +	if (version >= GBSAVE_GAME_VERSION_13)   // new to rerecording 19.4 wip (svn r22+):
 64.2866 +	{
 64.2867 +		utilGzRead(gzFile, &GBSystemCounters.lagCount, sizeof(GBSystemCounters.lagCount));
 64.2868 +		utilGzRead(gzFile, &GBSystemCounters.lagged, sizeof(GBSystemCounters.lagged));
 64.2869 +		utilGzRead(gzFile, &GBSystemCounters.laggedLast, sizeof(GBSystemCounters.laggedLast));
 64.2870 +	}
 64.2871 +
 64.2872 +	if (backupSafe)
 64.2873 +	{
 64.2874 +		remove(tempBackupName);
 64.2875 +		tempFailCount = 0;
 64.2876 +	}
 64.2877 +
 64.2878 +	for (int i = 0; i < 4; ++i)
 64.2879 +		systemSetJoypad(i, gbJoymask[i] & 0xFFFF);
 64.2880 +
 64.2881 +	// FIXME: horrible kludge
 64.2882 +	memcpy(s_gbJoymask, gbJoymask, sizeof(gbJoymask));
 64.2883 +
 64.2884 +	VBAUpdateButtonPressDisplay();
 64.2885 +	VBAUpdateFrameCountDisplay();
 64.2886 +	systemRefreshScreen();
 64.2887 +	return true;
 64.2888 +
 64.2889 +failedLoadGB:
 64.2890 +	if (backupSafe)
 64.2891 +	{
 64.2892 +		tempFailCount++;
 64.2893 +		if (tempFailCount < 3) // fail no more than 2 times in a row
 64.2894 +			gbReadSaveState(tempBackupName);
 64.2895 +		remove(tempBackupName);
 64.2896 +	}
 64.2897 +	return false;
 64.2898 +}
 64.2899 +
 64.2900 +bool gbReadMemSaveState(char *memory, int available)
 64.2901 +{
 64.2902 +	gzFile gzFile = utilMemGzOpen(memory, available, "r");
 64.2903 +
 64.2904 +	backupSafe = false;
 64.2905 +	bool res = gbReadSaveStateFromStream(gzFile);
 64.2906 +	backupSafe = true;
 64.2907 +
 64.2908 +	utilGzClose(gzFile);
 64.2909 +
 64.2910 +	return res;
 64.2911 +}
 64.2912 +
 64.2913 +bool gbReadSaveState(const char *name)
 64.2914 +{
 64.2915 +	gzFile gzFile = utilGzOpen(name, "rb");
 64.2916 +
 64.2917 +	if (gzFile == NULL)
 64.2918 +	{
 64.2919 +		return false;
 64.2920 +	}
 64.2921 +
 64.2922 +	bool res = gbReadSaveStateFromStream(gzFile);
 64.2923 +
 64.2924 +	utilGzClose(gzFile);
 64.2925 +
 64.2926 +	return res;
 64.2927 +}
 64.2928 +
 64.2929 +bool gbWritePNGFile(const char *fileName)
 64.2930 +{
 64.2931 +	if (gbBorderOn)
 64.2932 +		return utilWritePNGFile(fileName, 256, 224, pix);
 64.2933 +	return utilWritePNGFile(fileName, 160, 144, pix);
 64.2934 +}
 64.2935 +
 64.2936 +bool gbWriteBMPFile(const char *fileName)
 64.2937 +{
 64.2938 +	if (gbBorderOn)
 64.2939 +		return utilWriteBMPFile(fileName, 256, 224, pix);
 64.2940 +	return utilWriteBMPFile(fileName, 160, 144, pix);
 64.2941 +}
 64.2942 +
 64.2943 +void gbCleanUp()
 64.2944 +{
 64.2945 +	newFrame	  = true;
 64.2946 +
 64.2947 +	GBSystemCounters.frameCount = 0;
 64.2948 +	GBSystemCounters.lagCount	= 0;
 64.2949 +	GBSystemCounters.extraCount = 0;
 64.2950 +	GBSystemCounters.lagged		= true;
 64.2951 +	GBSystemCounters.laggedLast = true;
 64.2952 +
 64.2953 +	if (gbRam != NULL)
 64.2954 +	{
 64.2955 +		free(gbRam);
 64.2956 +		gbRam = NULL;
 64.2957 +	}
 64.2958 +
 64.2959 +	if (gbRom != NULL)
 64.2960 +	{
 64.2961 +		free(gbRom);
 64.2962 +		gbRom = NULL;
 64.2963 +	}
 64.2964 +
 64.2965 +	if (gbMemory != NULL)
 64.2966 +	{
 64.2967 +		free(gbMemory);
 64.2968 +		gbMemory = NULL;
 64.2969 +	}
 64.2970 +
 64.2971 +	if (gbLineBuffer != NULL)
 64.2972 +	{
 64.2973 +		free(gbLineBuffer);
 64.2974 +		gbLineBuffer = NULL;
 64.2975 +	}
 64.2976 +
 64.2977 +	if (origPix != NULL)
 64.2978 +	{
 64.2979 +		free(origPix);
 64.2980 +		origPix = NULL;
 64.2981 +	}
 64.2982 +	pix = NULL;
 64.2983 +
 64.2984 +	gbSgbShutdown();
 64.2985 +
 64.2986 +	if (gbVram != NULL)
 64.2987 +	{
 64.2988 +		free(gbVram);
 64.2989 +		gbVram = NULL;
 64.2990 +	}
 64.2991 +
 64.2992 +	if (gbWram != NULL)
 64.2993 +	{
 64.2994 +		free(gbWram);
 64.2995 +		gbWram = NULL;
 64.2996 +	}
 64.2997 +
 64.2998 +	systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
 64.2999 +
 64.3000 +	memset(gbJoymask, 0, sizeof(gbJoymask));
 64.3001 +	// FIXME: horrible kludge
 64.3002 +	memset(s_gbJoymask, 0, sizeof(s_gbJoymask));
 64.3003 +
 64.3004 +	systemClearJoypads();
 64.3005 +	systemResetSensor();
 64.3006 +
 64.3007 +//	gbLastTime = gbFrameCount = 0;
 64.3008 +	systemRefreshScreen();
 64.3009 +}
 64.3010 +
 64.3011 +bool gbLoadRom(const char *szFile)
 64.3012 +{
 64.3013 +	int size = 0;
 64.3014 +
 64.3015 +	if (gbRom != NULL)
 64.3016 +	{
 64.3017 +		gbCleanUp();
 64.3018 +	}
 64.3019 +
 64.3020 +	systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
 64.3021 +
 64.3022 +	gbRom = utilLoad(szFile,
 64.3023 +	                 utilIsGBImage,
 64.3024 +	                 NULL,
 64.3025 +	                 size);
 64.3026 +	if (!gbRom)
 64.3027 +		return false;
 64.3028 +
 64.3029 +	gbRomSize = size;
 64.3030 +
 64.3031 +	return gbUpdateSizes();
 64.3032 +}
 64.3033 +
 64.3034 +bool gbUpdateSizes()
 64.3035 +{
 64.3036 +	if (gbRom[0x148] > 8)
 64.3037 +	{
 64.3038 +		systemMessage(MSG_UNSUPPORTED_ROM_SIZE,
 64.3039 +		              N_("Unsupported rom size %02x"), gbRom[0x148]);
 64.3040 +		return false;
 64.3041 +	}
 64.3042 +
 64.3043 +	if (gbRomSize < gbRomSizes[gbRom[0x148]])
 64.3044 +	{
 64.3045 +		gbRom = (u8 *)realloc(gbRom, gbRomSizes[gbRom[0x148]]);
 64.3046 +	}
 64.3047 +	gbRomSize	  = gbRomSizes[gbRom[0x148]];
 64.3048 +	gbRomSizeMask = gbRomSizesMasks[gbRom[0x148]];
 64.3049 +
 64.3050 +	if (gbRom[0x149] > 5)
 64.3051 +	{
 64.3052 +		systemMessage(MSG_UNSUPPORTED_RAM_SIZE,
 64.3053 +		              N_("Unsupported ram size %02x"), gbRom[0x149]);
 64.3054 +		return false;
 64.3055 +	}
 64.3056 +
 64.3057 +	gbRamSize	  = gbRamSizes[gbRom[0x149]];
 64.3058 +	gbRamSizeMask = gbRamSizesMasks[gbRom[0x149]];
 64.3059 +
 64.3060 +	if (gbRamSize)
 64.3061 +	{
 64.3062 +		gbRam = (u8 *)malloc(gbRamSize + 4);
 64.3063 +		memset(gbRam, 0xFF, gbRamSize + 4);
 64.3064 +	}
 64.3065 +
 64.3066 +	int type = gbRom[0x147];
 64.3067 +
 64.3068 +	mapperReadRAM = NULL;
 64.3069 +
 64.3070 +	switch (type)
 64.3071 +	{
 64.3072 +	case 0x00:
 64.3073 +	case 0x01:
 64.3074 +	case 0x02:
 64.3075 +	case 0x03:
 64.3076 +		// MBC 1
 64.3077 +		mapper	  = mapperMBC1ROM;
 64.3078 +		mapperRAM = mapperMBC1RAM;
 64.3079 +		break;
 64.3080 +	case 0x05:
 64.3081 +	case 0x06:
 64.3082 +		// MBC2
 64.3083 +		mapper		  = mapperMBC2ROM;
 64.3084 +		mapperRAM	  = mapperMBC2RAM;
 64.3085 +		gbRamSize	  = 0x200;
 64.3086 +		gbRamSizeMask = 0x1ff;
 64.3087 +		break;
 64.3088 +	case 0x0f:
 64.3089 +	case 0x10:
 64.3090 +	case 0x11:
 64.3091 +	case 0x12:
 64.3092 +	case 0x13:
 64.3093 +		// MBC 3
 64.3094 +		mapper		  = mapperMBC3ROM;
 64.3095 +		mapperRAM	  = mapperMBC3RAM;
 64.3096 +		mapperReadRAM = mapperMBC3ReadRAM;
 64.3097 +		break;
 64.3098 +	case 0x19:
 64.3099 +	case 0x1a:
 64.3100 +	case 0x1b:
 64.3101 +		// MBC5
 64.3102 +		mapper	  = mapperMBC5ROM;
 64.3103 +		mapperRAM = mapperMBC5RAM;
 64.3104 +		break;
 64.3105 +	case 0x1c:
 64.3106 +	case 0x1d:
 64.3107 +	case 0x1e:
 64.3108 +		// MBC 5 Rumble
 64.3109 +		mapper	  = mapperMBC5ROM;
 64.3110 +		mapperRAM = mapperMBC5RAM;
 64.3111 +		break;
 64.3112 +	case 0x22:
 64.3113 +		// MBC 7
 64.3114 +		mapper		  = mapperMBC7ROM;
 64.3115 +		mapperRAM	  = mapperMBC7RAM;
 64.3116 +		mapperReadRAM = mapperMBC7ReadRAM;
 64.3117 +		break;
 64.3118 +	case 0xfe:
 64.3119 +		// HuC3
 64.3120 +		mapper		  = mapperHuC3ROM;
 64.3121 +		mapperRAM	  = mapperHuC3RAM;
 64.3122 +		mapperReadRAM = mapperHuC3ReadRAM;
 64.3123 +		break;
 64.3124 +	case 0xff:
 64.3125 +		// HuC1
 64.3126 +		mapper	  = mapperHuC1ROM;
 64.3127 +		mapperRAM = mapperHuC1RAM;
 64.3128 +		break;
 64.3129 +	default:
 64.3130 +		systemMessage(MSG_UNKNOWN_CARTRIDGE_TYPE,
 64.3131 +		              N_("Unknown cartridge type %02x"), type);
 64.3132 +		return false;
 64.3133 +	}
 64.3134 +
 64.3135 +	switch (type)
 64.3136 +	{
 64.3137 +	case 0x03:
 64.3138 +	case 0x06:
 64.3139 +	case 0x0f:
 64.3140 +	case 0x10:
 64.3141 +	case 0x13:
 64.3142 +	case 0x1b:
 64.3143 +	case 0x1d:
 64.3144 +	case 0x1e:
 64.3145 +	case 0x22:
 64.3146 +	case 0xff:
 64.3147 +		gbBattery = 1;
 64.3148 +		break;
 64.3149 +	}
 64.3150 +
 64.3151 +	gbInit();
 64.3152 +	gbReset();
 64.3153 +
 64.3154 +	return true;
 64.3155 +}
 64.3156 +
 64.3157 +void gbEmulate(int ticksToStop)
 64.3158 +{
 64.3159 +	gbRegister tempRegister;
 64.3160 +	u8		   tempValue;
 64.3161 +	s8		   offset;
 64.3162 +
 64.3163 +	int clockTicks = 0;
 64.3164 +	gbDmaTicks = 0;
 64.3165 +
 64.3166 +	register int opcode = 0;
 64.3167 +
 64.3168 +	u32 newmask = 0;
 64.3169 +	if (newFrame)
 64.3170 +	{
 64.3171 +		extern void VBAOnExitingFrameBoundary();
 64.3172 +		VBAOnExitingFrameBoundary();
 64.3173 +
 64.3174 +		// update joystick information
 64.3175 +		systemReadJoypads();
 64.3176 +
 64.3177 +		bool sensor = (gbRom[0x147] == 0x22);
 64.3178 +
 64.3179 +		// read joystick
 64.3180 +		if (gbSgbMode && gbSgbMultiplayer)
 64.3181 +		{
 64.3182 +			if (gbSgbFourPlayers)
 64.3183 +			{
 64.3184 +				gbJoymask[0] = systemGetJoypad(0, sensor);
 64.3185 +				gbJoymask[1] = systemGetJoypad(1, false);
 64.3186 +				gbJoymask[2] = systemGetJoypad(2, false);
 64.3187 +				gbJoymask[3] = systemGetJoypad(3, false);
 64.3188 +			}
 64.3189 +			else
 64.3190 +			{
 64.3191 +				gbJoymask[0] = systemGetJoypad(0, sensor);
 64.3192 +				gbJoymask[1] = systemGetJoypad(1, false);
 64.3193 +			}
 64.3194 +		}
 64.3195 +		else
 64.3196 +		{
 64.3197 +			gbJoymask[0] = systemGetJoypad(0, sensor);
 64.3198 +		}
 64.3199 +
 64.3200 +		// FIXME: horrible kludge
 64.3201 +		memcpy(s_gbJoymask, gbJoymask, sizeof(gbJoymask));
 64.3202 +
 64.3203 +//		if (sensor)
 64.3204 +//			systemUpdateMotionSensor(0);
 64.3205 +
 64.3206 +		newmask = gbJoymask[0];
 64.3207 +		if (newmask & 0xFF)
 64.3208 +		{
 64.3209 +			gbInterrupt |= 16;
 64.3210 +		}
 64.3211 +
 64.3212 +		extButtons = (newmask >> 18);
 64.3213 +		speedup	   = (extButtons & 1) != 0;
 64.3214 +
 64.3215 +		VBAMovieResetIfRequested();
 64.3216 +
 64.3217 +		CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION);
 64.3218 +
 64.3219 +		newFrame = false;
 64.3220 +	}
 64.3221 +
 64.3222 +	for (;; )
 64.3223 +	{
 64.3224 +#ifndef FINAL_VERSION
 64.3225 +		if (systemDebug)
 64.3226 +		{
 64.3227 +			if (!(IFF & 0x80))
 64.3228 +			{
 64.3229 +				if (systemDebug > 1)
 64.3230 +				{
 64.3231 +					sprintf(gbBuffer, "PC=%04x AF=%04x BC=%04x DE=%04x HL=%04x SP=%04x I=%04x\n",
 64.3232 +					        PC.W, AF.W, BC.W, DE.W, HL.W, SP.W, IFF);
 64.3233 +				}
 64.3234 +				else
 64.3235 +				{
 64.3236 +					sprintf(gbBuffer, "PC=%04x I=%02x\n", PC.W, IFF);
 64.3237 +				}
 64.3238 +				log(gbBuffer);
 64.3239 +			}
 64.3240 +		}
 64.3241 +#endif
 64.3242 +		if (IFF & 0x80)
 64.3243 +		{
 64.3244 +			if (register_LCDC & 0x80)
 64.3245 +			{
 64.3246 +				clockTicks = gbLcdTicks;
 64.3247 +			}
 64.3248 +			else
 64.3249 +				clockTicks = 100;
 64.3250 +
 64.3251 +			if (gbLcdMode == 1 && (gbLcdLYIncrementTicks < clockTicks))
 64.3252 +				clockTicks = gbLcdLYIncrementTicks;
 64.3253 +
 64.3254 +			if (gbSerialOn && (gbSerialTicks < clockTicks))
 64.3255 +				clockTicks = gbSerialTicks;
 64.3256 +
 64.3257 +			if (gbTimerOn && (gbTimerTicks < clockTicks))
 64.3258 +				clockTicks = gbTimerTicks;
 64.3259 +
 64.3260 +			if (soundTicks && (soundTicks < clockTicks))
 64.3261 +				clockTicks = soundTicks;
 64.3262 +		}
 64.3263 +		else
 64.3264 +		{
 64.3265 +			opcode = gbReadOpcode(PC.W);
 64.3266 +			CallRegisteredLuaMemHook(PC.W, 1, opcode, LUAMEMHOOK_EXEC);
 64.3267 +			PC.W++;
 64.3268 +
 64.3269 +			if (IFF & 0x100)
 64.3270 +			{
 64.3271 +				IFF &= 0xff;
 64.3272 +				PC.W--;
 64.3273 +			}
 64.3274 +
 64.3275 +			clockTicks = gbCycles[opcode];
 64.3276 +
 64.3277 +			switch (opcode)
 64.3278 +			{
 64.3279 +			case 0xCB:
 64.3280 +				// extended opcode
 64.3281 +				//CallRegisteredLuaMemHook(PC.W, 1, opcode, LUAMEMHOOK_EXEC);	// is this desired?
 64.3282 +				opcode	   = gbReadOpcode(PC.W++);
 64.3283 +				clockTicks = gbCyclesCB[opcode];
 64.3284 +				switch (opcode)
 64.3285 +				{
 64.3286 +#include "gbCodesCB.h"
 64.3287 +				}
 64.3288 +				break;
 64.3289 +#include "gbCodes.h"
 64.3290 +			}
 64.3291 +		}
 64.3292 +
 64.3293 +		if (!emulating)
 64.3294 +			return;
 64.3295 +
 64.3296 +		if (gbDmaTicks)
 64.3297 +		{
 64.3298 +			clockTicks += gbDmaTicks;
 64.3299 +			gbDmaTicks	= 0;
 64.3300 +		}
 64.3301 +
 64.3302 +		if (gbSgbMode)
 64.3303 +		{
 64.3304 +			if (gbSgbPacketTimeout)
 64.3305 +			{
 64.3306 +				gbSgbPacketTimeout -= clockTicks;
 64.3307 +
 64.3308 +				if (gbSgbPacketTimeout <= 0)
 64.3309 +					gbSgbResetPacketState();
 64.3310 +			}
 64.3311 +		}
 64.3312 +
 64.3313 +		ticksToStop -= clockTicks;
 64.3314 +
 64.3315 +		// DIV register emulation
 64.3316 +		gbDivTicks -= clockTicks;
 64.3317 +		while (gbDivTicks <= 0)
 64.3318 +		{
 64.3319 +			register_DIV++;
 64.3320 +			gbDivTicks += GBDIV_CLOCK_TICKS;
 64.3321 +		}
 64.3322 +
 64.3323 +		if (register_LCDC & 0x80)
 64.3324 +		{
 64.3325 +			// LCD stuff
 64.3326 +			gbLcdTicks -= clockTicks;
 64.3327 +			if (gbLcdMode == 1)
 64.3328 +			{
 64.3329 +				// during V-BLANK,we need to increment LY at the same rate!
 64.3330 +				gbLcdLYIncrementTicks -= clockTicks;
 64.3331 +				while (gbLcdLYIncrementTicks <= 0)
 64.3332 +				{
 64.3333 +					gbLcdLYIncrementTicks += GBLY_INCREMENT_CLOCK_TICKS;
 64.3334 +
 64.3335 +					if (register_LY < 153)
 64.3336 +					{
 64.3337 +						register_LY++;
 64.3338 +
 64.3339 +						gbCompareLYToLYC();
 64.3340 +
 64.3341 +						if (register_LY >= 153)
 64.3342 +							gbLcdLYIncrementTicks = 6;
 64.3343 +					}
 64.3344 +					else
 64.3345 +					{
 64.3346 +						register_LY = 0x00;
 64.3347 +						// reset the window line
 64.3348 +						gbWindowLine = -1;
 64.3349 +						gbLcdLYIncrementTicks = GBLY_INCREMENT_CLOCK_TICKS * 2;
 64.3350 +						gbCompareLYToLYC();
 64.3351 +					}
 64.3352 +				}
 64.3353 +			}
 64.3354 +
 64.3355 +			// our counter is off, see what we need to do
 64.3356 +			while (gbLcdTicks <= 0)
 64.3357 +			{
 64.3358 +				int framesToSkip = systemFramesToSkip();
 64.3359 +
 64.3360 +				switch (gbLcdMode)
 64.3361 +				{
 64.3362 +				case 0:
 64.3363 +					// H-Blank
 64.3364 +					register_LY++;
 64.3365 +
 64.3366 +					gbCompareLYToLYC();
 64.3367 +
 64.3368 +					// check if we reached the V-Blank period
 64.3369 +					if (register_LY == 144)
 64.3370 +					{
 64.3371 +						// Yes, V-Blank
 64.3372 +						// set the LY increment counter
 64.3373 +						gbLcdLYIncrementTicks = gbLcdTicks + GBLY_INCREMENT_CLOCK_TICKS;
 64.3374 +						gbLcdTicks += GBLCD_MODE_1_CLOCK_TICKS;
 64.3375 +						gbLcdMode	= 1;
 64.3376 +						if (register_LCDC & 0x80)
 64.3377 +						{
 64.3378 +							gbInterrupt	   |= 1; // V-Blank interrupt
 64.3379 +							gbInterruptWait = 6;
 64.3380 +							if (register_STAT & 0x10)
 64.3381 +								gbInterrupt |= 2;
 64.3382 +						}
 64.3383 +
 64.3384 +						systemFrame();
 64.3385 +
 64.3386 +						++gbFrameCount;
 64.3387 +						u32 currentTime = systemGetClock();
 64.3388 +						if (currentTime - gbLastTime >= 1000)
 64.3389 +						{
 64.3390 +							systemShowSpeed(int(float(gbFrameCount) * 100000 / (float(currentTime - gbLastTime) * 60) + .5f));
 64.3391 +							gbLastTime	 = currentTime;
 64.3392 +							gbFrameCount = 0;
 64.3393 +						}
 64.3394 +
 64.3395 +						++GBSystemCounters.frameCount;
 64.3396 +						if (GBSystemCounters.lagged)
 64.3397 +						{
 64.3398 +							++GBSystemCounters.lagCount;
 64.3399 +						}
 64.3400 +						GBSystemCounters.laggedLast = GBSystemCounters.lagged;
 64.3401 +						GBSystemCounters.lagged		= true;
 64.3402 +
 64.3403 +						extern void VBAOnEnteringFrameBoundary();
 64.3404 +						VBAOnEnteringFrameBoundary();
 64.3405 +
 64.3406 +						newFrame = true;
 64.3407 +
 64.3408 +						pauseAfterFrameAdvance = systemPauseOnFrame();
 64.3409 +
 64.3410 +						if (gbFrameSkipCount >= framesToSkip || pauseAfterFrameAdvance)
 64.3411 +						{
 64.3412 +							if (gbBorderOn)
 64.3413 +								gbSgbRenderBorder();  // clear unnecessary things on border (e.g. in-game text message)
 64.3414 +
 64.3415 +							systemRenderFrame();
 64.3416 +							gbFrameSkipCount = 0;
 64.3417 +
 64.3418 +							bool capturePressed = (extButtons & 2) != 0;
 64.3419 +							if (capturePressed && !capturePrevious)
 64.3420 +							{
 64.3421 +								captureNumber = systemScreenCapture(captureNumber);
 64.3422 +							}
 64.3423 +							capturePrevious = capturePressed && !pauseAfterFrameAdvance;
 64.3424 +						}
 64.3425 +						else
 64.3426 +						{
 64.3427 +							++gbFrameSkipCount;
 64.3428 +						}
 64.3429 +
 64.3430 +						if (pauseAfterFrameAdvance)
 64.3431 +						{
 64.3432 +							systemSetPause(true);
 64.3433 +						}
 64.3434 +					}
 64.3435 +					else
 64.3436 +					{
 64.3437 +						// go the the OAM being accessed mode
 64.3438 +						gbLcdTicks += GBLCD_MODE_2_CLOCK_TICKS;
 64.3439 +						gbLcdMode	= 2;
 64.3440 +
 64.3441 +						// only one LCD interrupt per line. may need to generalize...
 64.3442 +						if (!(register_STAT & 0x40) ||
 64.3443 +						    (register_LY != register_LYC))
 64.3444 +						{
 64.3445 +							if ((register_STAT & 0x28) == 0x20)
 64.3446 +								gbInterrupt |= 2;
 64.3447 +						}
 64.3448 +					}
 64.3449 +
 64.3450 +					break;
 64.3451 +				case 1:
 64.3452 +					// V-Blank
 64.3453 +					// next mode is OAM being accessed mode
 64.3454 +					gbLcdTicks += GBLCD_MODE_2_CLOCK_TICKS;
 64.3455 +					gbLcdMode	= 2;
 64.3456 +					if (!(register_STAT & 0x40) ||
 64.3457 +					    (register_LY != register_LYC))
 64.3458 +					{
 64.3459 +						if ((register_STAT & 0x28) == 0x20)
 64.3460 +							gbInterrupt |= 2;
 64.3461 +					}
 64.3462 +					break;
 64.3463 +				case 2:
 64.3464 +					// OAM being accessed mode
 64.3465 +
 64.3466 +					// next mode is OAM and VRAM in use
 64.3467 +					gbLcdTicks += GBLCD_MODE_3_CLOCK_TICKS;
 64.3468 +					gbLcdMode	= 3;
 64.3469 +					break;
 64.3470 +				case 3:
 64.3471 +					// OAM and VRAM in use
 64.3472 +					// next mode is H-Blank
 64.3473 +					if (register_LY < 144)
 64.3474 +					{
 64.3475 +						if (!gbSgbMask)
 64.3476 +						{
 64.3477 +							if (gbFrameSkipCount >= framesToSkip || pauseAfterFrameAdvance)
 64.3478 +							{
 64.3479 +								gbRenderLine();
 64.3480 +								gbDrawSprites();
 64.3481 +
 64.3482 +								switch (systemColorDepth)
 64.3483 +								{
 64.3484 +								case 16:
 64.3485 +
 64.3486 +								{
 64.3487 +									u16 *dest = (u16 *)pix +
 64.3488 +									            (gbBorderLineSkip + 2) * (register_LY + gbBorderRowSkip + 1)
 64.3489 +									            + gbBorderColumnSkip;
 64.3490 +									for (int x = 0; x < 160; )
 64.3491 +									{
 64.3492 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3493 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3494 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3495 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3496 +
 64.3497 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3498 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3499 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3500 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3501 +
 64.3502 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3503 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3504 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3505 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3506 +
 64.3507 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3508 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3509 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3510 +										*dest++ = systemColorMap16[gbLineMix[x++]];
 64.3511 +									}
 64.3512 +									if (gbBorderOn)
 64.3513 +										dest += gbBorderColumnSkip;
 64.3514 +									*dest++ = 0;     // for filters that read one pixel more
 64.3515 +									break;
 64.3516 +								}
 64.3517 +								case 24:
 64.3518 +
 64.3519 +								{
 64.3520 +									u8 *dest = (u8 *)pix +
 64.3521 +									           3 * (gbBorderLineSkip * (register_LY + gbBorderRowSkip) +
 64.3522 +									                gbBorderColumnSkip);
 64.3523 +									for (int x = 0; x < 160; )
 64.3524 +									{
 64.3525 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3526 +										dest += 3;
 64.3527 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3528 +										dest += 3;
 64.3529 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3530 +										dest += 3;
 64.3531 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3532 +										dest += 3;
 64.3533 +
 64.3534 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3535 +										dest += 3;
 64.3536 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3537 +										dest += 3;
 64.3538 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3539 +										dest += 3;
 64.3540 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3541 +										dest += 3;
 64.3542 +
 64.3543 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3544 +										dest += 3;
 64.3545 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3546 +										dest += 3;
 64.3547 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3548 +										dest += 3;
 64.3549 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3550 +										dest += 3;
 64.3551 +
 64.3552 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3553 +										dest += 3;
 64.3554 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3555 +										dest += 3;
 64.3556 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3557 +										dest += 3;
 64.3558 +										*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
 64.3559 +										dest += 3;
 64.3560 +									}
 64.3561 +									break;
 64.3562 +								}
 64.3563 +								case 32:
 64.3564 +
 64.3565 +								{
 64.3566 +									u32 *dest = (u32 *)pix +
 64.3567 +									            (gbBorderLineSkip + 1) * (register_LY + gbBorderRowSkip + 1)
 64.3568 +									            + gbBorderColumnSkip;
 64.3569 +									for (int x = 0; x < 160; )
 64.3570 +									{
 64.3571 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3572 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3573 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3574 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3575 +
 64.3576 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3577 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3578 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3579 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3580 +
 64.3581 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3582 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3583 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3584 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3585 +
 64.3586 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3587 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3588 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3589 +										*dest++ = systemColorMap32[gbLineMix[x++]];
 64.3590 +									}
 64.3591 +									break;
 64.3592 +								}
 64.3593 +								}
 64.3594 +							}
 64.3595 +						}
 64.3596 +					}
 64.3597 +					gbLcdTicks += GBLCD_MODE_0_CLOCK_TICKS;
 64.3598 +					gbLcdMode	= 0;
 64.3599 +					// only one LCD interrupt per line. may need to generalize...
 64.3600 +					if (!(register_STAT & 0x40) ||
 64.3601 +					    (register_LY != register_LYC))
 64.3602 +					{
 64.3603 +						if (register_STAT & 0x08)
 64.3604 +							gbInterrupt |= 2;
 64.3605 +					}
 64.3606 +					if (gbHdmaOn)
 64.3607 +					{
 64.3608 +						gbDoHdma();
 64.3609 +					}
 64.3610 +					break;
 64.3611 +				}
 64.3612 +				// mark the correct lcd mode on STAT register
 64.3613 +				register_STAT = (register_STAT & 0xfc) | gbLcdMode;
 64.3614 +			}
 64.3615 +		}
 64.3616 +
 64.3617 +		// serial emulation
 64.3618 +		if (gbSerialOn)
 64.3619 +		{
 64.3620 +#ifdef LINK_EMULATION
 64.3621 +			if (linkConnected)
 64.3622 +			{
 64.3623 +				gbSerialTicks -= clockTicks;
 64.3624 +
 64.3625 +				while (gbSerialTicks <= 0)
 64.3626 +				{
 64.3627 +					// increment number of shifted bits
 64.3628 +					gbSerialBits++;
 64.3629 +					linkProc();
 64.3630 +					if (gbSerialOn && (gbMemory[0xff02] & 1))
 64.3631 +					{
 64.3632 +						if (gbSerialBits == 8)
 64.3633 +						{
 64.3634 +							gbSerialBits	  = 0;
 64.3635 +							gbMemory[0xff01]  = 0xff;
 64.3636 +							gbMemory[0xff02] &= 0x7f;
 64.3637 +							gbSerialOn		  = 0;
 64.3638 +							gbInterrupt		 |= 8;
 64.3639 +							gbSerialTicks	  = 0;
 64.3640 +						}
 64.3641 +					}
 64.3642 +					gbSerialTicks += GBSERIAL_CLOCK_TICKS;
 64.3643 +				}
 64.3644 +			}
 64.3645 +			else
 64.3646 +			{
 64.3647 +#endif
 64.3648 +			if (gbMemory[0xff02] & 1)
 64.3649 +			{
 64.3650 +				gbSerialTicks -= clockTicks;
 64.3651 +
 64.3652 +				// overflow
 64.3653 +				while (gbSerialTicks <= 0)
 64.3654 +				{
 64.3655 +					// shift serial byte to right and put a 1 bit in its place
 64.3656 +					//      gbMemory[0xff01] = 0x80 | (gbMemory[0xff01]>>1);
 64.3657 +					// increment number of shifted bits
 64.3658 +					gbSerialBits++;
 64.3659 +					if (gbSerialBits == 8)
 64.3660 +					{
 64.3661 +						// end of transmission
 64.3662 +						if (gbSerialFunction)    // external device
 64.3663 +							gbMemory[0xff01] = gbSerialFunction(gbMemory[0xff01]);
 64.3664 +						else
 64.3665 +							gbMemory[0xff01] = 0xff;
 64.3666 +						gbSerialTicks	  = 0;
 64.3667 +						gbMemory[0xff02] &= 0x7f;
 64.3668 +						gbSerialOn		  = 0;
 64.3669 +						gbInterrupt		 |= 8;
 64.3670 +						gbSerialBits	  = 0;
 64.3671 +					}
 64.3672 +					else
 64.3673 +						gbSerialTicks += GBSERIAL_CLOCK_TICKS;
 64.3674 +				}
 64.3675 +			}
 64.3676 +#ifdef LINK_EMULATION
 64.3677 +		}
 64.3678 +#endif
 64.3679 +		}
 64.3680 +
 64.3681 +		// timer emulation
 64.3682 +		if (gbTimerOn)
 64.3683 +		{
 64.3684 +			gbTimerTicks -= clockTicks;
 64.3685 +
 64.3686 +			while (gbTimerTicks <= 0)
 64.3687 +			{
 64.3688 +				register_TIMA++;
 64.3689 +
 64.3690 +				if (register_TIMA == 0)
 64.3691 +				{
 64.3692 +					// timer overflow!
 64.3693 +
 64.3694 +					// reload timer modulo
 64.3695 +					register_TIMA = register_TMA;
 64.3696 +
 64.3697 +					// flag interrupt
 64.3698 +					gbInterrupt |= 4;
 64.3699 +				}
 64.3700 +
 64.3701 +				gbTimerTicks += gbTimerClockTicks;
 64.3702 +			}
 64.3703 +		}
 64.3704 +
 64.3705 +		/*
 64.3706 +		   if(soundOffFlag)
 64.3707 +		   {
 64.3708 +		   if(synchronize && !speedup)
 64.3709 +		   {
 64.3710 +		   synchronizeTicks -= clockTicks;
 64.3711 +
 64.3712 +		   while(synchronizeTicks < 0)
 64.3713 +		   {
 64.3714 +		   synchronizeTicks += SYNCHRONIZE_CLOCK_TICKS;
 64.3715 +
 64.3716 +		   DWORD now = timeGetTime();
 64.3717 +		   gbElapsedTime += (now - timeNow);
 64.3718 +
 64.3719 +		   if(gbElapsedTime < 50)
 64.3720 +		   {
 64.3721 +		   DWORD diff = 50 - gbElapsedTime;
 64.3722 +		   Sleep(diff);
 64.3723 +		   timeNow = timeGetTime();
 64.3724 +		   elapsedTime = timeNow - now - diff;
 64.3725 +		   if((int)elapsedTime < 0)
 64.3726 +		   elapsedTime = 0;
 64.3727 +		   } else
 64.3728 +		   {
 64.3729 +		   timeNow = timeGetTime();
 64.3730 +		   elapsedTime = 0;
 64.3731 +		   }
 64.3732 +		   }
 64.3733 +		   }
 64.3734 +		   }
 64.3735 +		 */
 64.3736 +
 64.3737 +		soundTicks -= clockTicks;
 64.3738 +		while (soundTicks < 0) // must be < 1 when soundtick_t is real data type
 64.3739 +		{
 64.3740 +			soundTicks += SOUND_CLOCK_TICKS;
 64.3741 +
 64.3742 +			gbSoundTick();
 64.3743 +		}
 64.3744 +
 64.3745 +		register_IF = gbInterrupt;
 64.3746 +
 64.3747 +		if (IFF & 0x20)
 64.3748 +		{
 64.3749 +			IFF &= 0xdf;
 64.3750 +			IFF |= 0x01;
 64.3751 +			gbInterruptWait = 0;
 64.3752 +		}
 64.3753 +		else if (gbInterrupt)
 64.3754 +		{
 64.3755 +			if (gbInterruptWait == 0)
 64.3756 +			{
 64.3757 +				//        gbInterruptWait = 0;
 64.3758 +
 64.3759 +				if (IFF & 0x01)
 64.3760 +				{
 64.3761 +					if ((gbInterrupt & 1) && (register_IE & 1))
 64.3762 +					{
 64.3763 +						gbVblank_interrupt();
 64.3764 +						continue;
 64.3765 +					}
 64.3766 +
 64.3767 +					if ((gbInterrupt & 2) && (register_IE & 2))
 64.3768 +					{
 64.3769 +						gbLcd_interrupt();
 64.3770 +						continue;
 64.3771 +					}
 64.3772 +
 64.3773 +					if ((gbInterrupt & 4) && (register_IE & 4))
 64.3774 +					{
 64.3775 +						gbTimer_interrupt();
 64.3776 +						continue;
 64.3777 +					}
 64.3778 +
 64.3779 +					if ((gbInterrupt & 8) && (register_IE & 8))
 64.3780 +					{
 64.3781 +						gbSerial_interrupt();
 64.3782 +						continue;
 64.3783 +					}
 64.3784 +
 64.3785 +					if ((gbInterrupt & 16) && (register_IE & 16))
 64.3786 +					{
 64.3787 +						gbJoypad_interrupt();
 64.3788 +						continue;
 64.3789 +					}
 64.3790 +				}
 64.3791 +			}
 64.3792 +			else
 64.3793 +			{
 64.3794 +				gbInterruptWait -= clockTicks;
 64.3795 +				if (gbInterruptWait < 0)
 64.3796 +					gbInterruptWait = 0;
 64.3797 +			}
 64.3798 +		}
 64.3799 +
 64.3800 +		if (useOldFrameTiming)
 64.3801 +		{
 64.3802 +			// old timing code
 64.3803 +			if (ticksToStop > 0)
 64.3804 +				continue;
 64.3805 +		}
 64.3806 +		else
 64.3807 +		{
 64.3808 +			if (!newFrame && (register_LCDC & 0x80) != 0)
 64.3809 +				continue;
 64.3810 +		}
 64.3811 +
 64.3812 +		if (!(register_LCDC & 0x80))
 64.3813 +		{
 64.3814 +			if (!useOldFrameTiming)
 64.3815 +			{
 64.3816 +				// FIXME: since register_LY can be reset to 0 by some games, frame length is variable
 64.3817 +				// and infinite loops can occurr
 64.3818 +				// for now, it IS necessary to do something on this condition or games like
 64.3819 +				// Megaman would freeze upon low-level restart interrupt sequence (Start+Select+A+B).
 64.3820 +				// the only sensible way to fix this issue is to implement the RIGHT frame timing
 64.3821 +#ifdef WANTS_INCOMPLETE_WORKAROUND
 64.3822 +				if (systemReadJoypads())
 64.3823 +				{
 64.3824 +					if (gbSgbMode && gbSgbMultiplayer)
 64.3825 +					{
 64.3826 +						if (gbSgbFourPlayers)
 64.3827 +						{
 64.3828 +							gbJoymask[0] = systemGetJoypad(0, false);
 64.3829 +							gbJoymask[1] = systemGetJoypad(1, false);
 64.3830 +							gbJoymask[2] = systemGetJoypad(2, false);
 64.3831 +							gbJoymask[3] = systemGetJoypad(3, false);
 64.3832 +						}
 64.3833 +						else
 64.3834 +						{
 64.3835 +							gbJoymask[0] = systemGetJoypad(0, false);
 64.3836 +							gbJoymask[1] = systemGetJoypad(1, false);
 64.3837 +						}
 64.3838 +					}
 64.3839 +					else
 64.3840 +					{
 64.3841 +						gbJoymask[0] = systemGetJoypad(0, false);
 64.3842 +					}
 64.3843 +				}
 64.3844 +				else
 64.3845 +					gbJoymask[0] = gbJoymask[1] = gbJoymask[2] = gbJoymask[3] = 0;
 64.3846 +#else
 64.3847 +#endif
 64.3848 +			}
 64.3849 +		}
 64.3850 +
 64.3851 +		// makes sure frames are really divided across input sampling boundaries which occur at a constant rate
 64.3852 +		if (newFrame || useOldFrameTiming)
 64.3853 +		{
 64.3854 +///			extern void VBAOnEnteringFrameBoundary();
 64.3855 +///			VBAOnEnteringFrameBoundary();
 64.3856 +
 64.3857 +			break;
 64.3858 +		}
 64.3859 +	}
 64.3860 +}
 64.3861 +
 64.3862 +struct EmulatedSystem GBSystem =
 64.3863 +{
 64.3864 +	// emuMain
 64.3865 +	gbEmulate,
 64.3866 +	// emuReset
 64.3867 +	gbReset,
 64.3868 +	// emuCleanUp
 64.3869 +	gbCleanUp,
 64.3870 +	// emuReadBattery
 64.3871 +	gbReadBatteryFile,
 64.3872 +	// emuWriteBattery
 64.3873 +	gbWriteBatteryFile,
 64.3874 +	// emuReadBatteryFromStream
 64.3875 +	gbReadBatteryFromStream,
 64.3876 +	// emuWriteBatteryToStream
 64.3877 +	gbWriteBatteryToStream,
 64.3878 +	// emuReadState
 64.3879 +	gbReadSaveState,
 64.3880 +	// emuWriteState
 64.3881 +	gbWriteSaveState,
 64.3882 +	// emuReadStateFromStream
 64.3883 +	gbReadSaveStateFromStream,
 64.3884 +	// emuWriteStateToStream
 64.3885 +	gbWriteSaveStateToStream,
 64.3886 +	// emuReadMemState
 64.3887 +	gbReadMemSaveState,
 64.3888 +	// emuWriteMemState
 64.3889 +	gbWriteMemSaveState,
 64.3890 +	// emuWritePNG
 64.3891 +	gbWritePNGFile,
 64.3892 +	// emuWriteBMP
 64.3893 +	gbWriteBMPFile,
 64.3894 +	// emuUpdateCPSR
 64.3895 +	NULL,
 64.3896 +	// emuHasDebugger
 64.3897 +	false,
 64.3898 +	// emuCount
 64.3899 +#ifdef FINAL_VERSION
 64.3900 +	70000 / 4,
 64.3901 +#else
 64.3902 +	1000,
 64.3903 +#endif
 64.3904 +};
 64.3905 +
 64.3906 +// is there a reason to use more than one set of counters?
 64.3907 +EmulatedSystemCounters &GBSystemCounters = systemCounters;
 64.3908 +
 64.3909 +/*
 64.3910 +   EmulatedSystemCounters GBSystemCounters =
 64.3911 +   {
 64.3912 +    // frameCount
 64.3913 +    0,
 64.3914 +    // lagCount
 64.3915 +    0,
 64.3916 +    // lagged
 64.3917 +    true,
 64.3918 +    // laggedLast
 64.3919 +    true,
 64.3920 +   };
 64.3921 + */
    65.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    65.2 +++ b/src/gb/GB.h	Sat Mar 03 10:31:27 2012 -0600
    65.3 @@ -0,0 +1,50 @@
    65.4 +#ifndef VBA_GB_H
    65.5 +#define VBA_GB_H
    65.6 +
    65.7 +#if _MSC_VER > 1000
    65.8 +#pragma once
    65.9 +#endif // _MSC_VER > 1000
   65.10 +
   65.11 +#include "zlib.h"
   65.12 +#include "../Port.h"
   65.13 +
   65.14 +typedef union
   65.15 +{
   65.16 +	struct
   65.17 +	{
   65.18 +#ifdef WORDS_BIGENDIAN
   65.19 +		u8 B1, B0;
   65.20 +#else
   65.21 +		u8 B0, B1;
   65.22 +#endif
   65.23 +	} B;
   65.24 +	u16 W;
   65.25 +} gbRegister;
   65.26 +
   65.27 +extern bool gbLoadRom(const char *);
   65.28 +extern void gbEmulate(int);
   65.29 +extern bool gbIsGameboyRom(const char *);
   65.30 +extern void gbSoundReset();
   65.31 +extern void gbSoundSetQuality(int);
   65.32 +extern void gbReset(bool userReset = false);
   65.33 +extern void gbCleanUp();
   65.34 +extern bool gbWriteBatteryFile(const char *);
   65.35 +extern bool gbWriteBatteryFile(const char *, bool);
   65.36 +extern bool gbWriteBatteryToStream(gzFile);
   65.37 +extern bool gbReadBatteryFile(const char *);
   65.38 +extern bool gbReadBatteryFromStream(gzFile);
   65.39 +extern bool gbWriteSaveState(const char *);
   65.40 +extern bool gbWriteMemSaveState(char *, int);
   65.41 +extern bool gbReadSaveState(const char *);
   65.42 +extern bool gbReadMemSaveState(char *, int);
   65.43 +extern bool gbReadSaveStateFromStream(gzFile);
   65.44 +extern bool gbWriteSaveStateToStream(gzFile);
   65.45 +extern void gbSgbRenderBorder();
   65.46 +extern bool gbWritePNGFile(const char *);
   65.47 +extern bool gbWriteBMPFile(const char *);
   65.48 +extern bool gbReadGSASnapshot(const char *);
   65.49 +
   65.50 +extern struct EmulatedSystem GBSystem;
   65.51 +extern struct EmulatedSystemCounters &GBSystemCounters;
   65.52 +
   65.53 +#endif // VBA_GB_H
    66.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    66.2 +++ b/src/gb/Makefile.am	Sat Mar 03 10:31:27 2012 -0600
    66.3 @@ -0,0 +1,21 @@
    66.4 +noinst_LIBRARIES = libgb.a
    66.5 +
    66.6 +libgb_a_SOURCES = \
    66.7 +	gbCheats.cpp	\
    66.8 +	gbCheats.h	\
    66.9 +	gbCodesCB.h	\
   66.10 +	gbCodes.h	\
   66.11 +	GB.cpp		\
   66.12 +	GB.h		\
   66.13 +	gbDis.cpp	\
   66.14 +	gbGfx.cpp	\
   66.15 +	gbGlobals.cpp	\
   66.16 +	gbGlobals.h	\
   66.17 +	gbMemory.cpp	\
   66.18 +	gbMemory.h	\
   66.19 +	gbPrinter.cpp	\
   66.20 +	gbPrinter.h	\
   66.21 +	gbSGB.cpp	\
   66.22 +	gbSGB.h		\
   66.23 +	gbSound.cpp	\
   66.24 +	gbSound.h
    67.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    67.2 +++ b/src/gb/gbCheats.cpp	Sat Mar 03 10:31:27 2012 -0600
    67.3 @@ -0,0 +1,477 @@
    67.4 +#include <cstdio>
    67.5 +#include <cstdlib>
    67.6 +#include <cctype>
    67.7 +#include <cstring>
    67.8 +
    67.9 +#include "../NLS.h"
   67.10 +#include "../common/System.h"
   67.11 +#include "../common/Util.h"
   67.12 +
   67.13 +#include "gbCheats.h"
   67.14 +#include "gbGlobals.h"
   67.15 +
   67.16 +gbCheat gbCheatList[100];
   67.17 +int     gbCheatNumber = 0;
   67.18 +bool    gbCheatMap[0x10000];
   67.19 +
   67.20 +extern bool8 cheatsEnabled;
   67.21 +
   67.22 +#define GBCHEAT_IS_HEX(a) (((a) >= 'A' && (a) <= 'F') || ((a) >= '0' && (a) <= '9'))
   67.23 +#define GBCHEAT_HEX_VALUE(a) ((a) >= 'A' ? (a) - 'A' + 10 : (a) - '0')
   67.24 +
   67.25 +void gbCheatUpdateMap()
   67.26 +{
   67.27 +	memset(gbCheatMap, 0, 0x10000);
   67.28 +
   67.29 +	for (int i = 0; i < gbCheatNumber; i++)
   67.30 +	{
   67.31 +		if (gbCheatList[i].enabled)
   67.32 +			gbCheatMap[gbCheatList[i].address] = true;
   67.33 +	}
   67.34 +}
   67.35 +
   67.36 +void gbCheatsSaveGame(gzFile gzFile)
   67.37 +{
   67.38 +	utilWriteInt(gzFile, gbCheatNumber);
   67.39 +	if (gbCheatNumber)
   67.40 +		utilGzWrite(gzFile, &gbCheatList[0], sizeof(gbCheat)*gbCheatNumber);
   67.41 +}
   67.42 +
   67.43 +void gbCheatsReadGame(gzFile gzFile, int version)
   67.44 +{
   67.45 +	if (version <= 8)
   67.46 +	{
   67.47 +		int gbGgOn = utilReadInt(gzFile);
   67.48 +
   67.49 +		if (gbGgOn)
   67.50 +		{
   67.51 +			int       n = utilReadInt(gzFile);
   67.52 +			gbXxCheat tmpCheat;
   67.53 +			for (int i = 0; i < n; i++)
   67.54 +			{
   67.55 +				utilGzRead(gzFile, &tmpCheat, sizeof(gbXxCheat));
   67.56 +				gbAddGgCheat(tmpCheat.cheatCode, tmpCheat.cheatDesc);
   67.57 +			}
   67.58 +		}
   67.59 +
   67.60 +		int gbGsOn = utilReadInt(gzFile);
   67.61 +
   67.62 +		if (gbGsOn)
   67.63 +		{
   67.64 +			int       n = utilReadInt(gzFile);
   67.65 +			gbXxCheat tmpCheat;
   67.66 +			for (int i = 0; i < n; i++)
   67.67 +			{
   67.68 +				utilGzRead(gzFile, &tmpCheat, sizeof(gbXxCheat));
   67.69 +				gbAddGsCheat(tmpCheat.cheatCode, tmpCheat.cheatDesc);
   67.70 +			}
   67.71 +		}
   67.72 +	}
   67.73 +	else
   67.74 +	{
   67.75 +		gbCheatNumber = utilReadInt(gzFile);
   67.76 +
   67.77 +		if (gbCheatNumber)
   67.78 +		{
   67.79 +			utilGzRead(gzFile, &gbCheatList[0], sizeof(gbCheat)*gbCheatNumber);
   67.80 +		}
   67.81 +	}
   67.82 +
   67.83 +	gbCheatUpdateMap();
   67.84 +}
   67.85 +
   67.86 +void gbCheatsSaveCheatList(const char *file)
   67.87 +{
   67.88 +	if (gbCheatNumber == 0)
   67.89 +		return;
   67.90 +	FILE *f = fopen(file, "wb");
   67.91 +	if (f == NULL)
   67.92 +		return;
   67.93 +	int version = 1;
   67.94 +	fwrite(&version, 1, sizeof(version), f);
   67.95 +	int type = 1;
   67.96 +	fwrite(&type, 1, sizeof(type), f);
   67.97 +	fwrite(&gbCheatNumber, 1, sizeof(gbCheatNumber), f);
   67.98 +	fwrite(gbCheatList, 1, sizeof(gbCheatList), f);
   67.99 +	fclose(f);
  67.100 +}
  67.101 +
  67.102 +bool gbCheatsLoadCheatList(const char *file)
  67.103 +{
  67.104 +	gbCheatNumber = 0;
  67.105 +
  67.106 +	gbCheatUpdateMap();
  67.107 +
  67.108 +	int count = 0;
  67.109 +
  67.110 +	FILE *f = fopen(file, "rb");
  67.111 +
  67.112 +	if (f == NULL)
  67.113 +		return false;
  67.114 +
  67.115 +	int version = 0;
  67.116 +
  67.117 +	if (fread(&version, 1, sizeof(version), f) != sizeof(version))
  67.118 +	{
  67.119 +		fclose(f);
  67.120 +		return false;
  67.121 +	}
  67.122 +
  67.123 +	if (version != 1)
  67.124 +	{
  67.125 +		systemMessage(MSG_UNSUPPORTED_CHEAT_LIST_VERSION,
  67.126 +		              N_("Unsupported cheat list version %d"), version);
  67.127 +		fclose(f);
  67.128 +		return false;
  67.129 +	}
  67.130 +
  67.131 +	int type = 0;
  67.132 +	if (fread(&type, 1, sizeof(type), f) != sizeof(type))
  67.133 +	{
  67.134 +		fclose(f);
  67.135 +		return false;
  67.136 +	}
  67.137 +
  67.138 +	if (type != 1)
  67.139 +	{
  67.140 +		systemMessage(MSG_UNSUPPORTED_CHEAT_LIST_TYPE,
  67.141 +		              N_("Unsupported cheat list type %d"), type);
  67.142 +		fclose(f);
  67.143 +		return false;
  67.144 +	}
  67.145 +
  67.146 +	if (fread(&count, 1, sizeof(count), f) != sizeof(count))
  67.147 +	{
  67.148 +		fclose(f);
  67.149 +		return false;
  67.150 +	}
  67.151 +
  67.152 +	if (fread(gbCheatList, 1, sizeof(gbCheatList), f) != sizeof(gbCheatList))
  67.153 +	{
  67.154 +		fclose(f);
  67.155 +		return false;
  67.156 +	}
  67.157 +
  67.158 +	fclose(f);
  67.159 +	gbCheatNumber = count;
  67.160 +	gbCheatUpdateMap();
  67.161 +
  67.162 +	return true;
  67.163 +}
  67.164 +
  67.165 +bool gbVerifyGsCode(const char *code)
  67.166 +{
  67.167 +	int len = strlen(code);
  67.168 +
  67.169 +	if (len == 0)
  67.170 +		return true;
  67.171 +
  67.172 +	if (len != 8)
  67.173 +		return false;
  67.174 +
  67.175 +	for (int i = 0; i < 8; i++)
  67.176 +		if (!GBCHEAT_IS_HEX(code[i]))
  67.177 +			return false;
  67.178 +
  67.179 +	int address = GBCHEAT_HEX_VALUE(code[6]) << 12 |
  67.180 +	              GBCHEAT_HEX_VALUE(code[7]) << 8 |
  67.181 +	              GBCHEAT_HEX_VALUE(code[4]) << 4 |
  67.182 +	              GBCHEAT_HEX_VALUE(code[5]);
  67.183 +
  67.184 +	if (address < 0xa000 ||
  67.185 +	    address > 0xdfff)
  67.186 +		return false;
  67.187 +
  67.188 +	return true;
  67.189 +}
  67.190 +
  67.191 +void gbAddGsCheat(const char *code, const char *desc)
  67.192 +{
  67.193 +	if (gbCheatNumber > 99)
  67.194 +	{
  67.195 +		systemMessage(MSG_MAXIMUM_NUMBER_OF_CHEATS,
  67.196 +		              N_("Maximum number of cheats reached."));
  67.197 +		return;
  67.198 +	}
  67.199 +
  67.200 +	if (!gbVerifyGsCode(code))
  67.201 +	{
  67.202 +		systemMessage(MSG_INVALID_GAMESHARK_CODE,
  67.203 +		              N_("Invalid GameShark code: %s"), code);
  67.204 +		return;
  67.205 +	}
  67.206 +
  67.207 +	int i = gbCheatNumber;
  67.208 +
  67.209 +	strcpy(gbCheatList[i].cheatCode, code);
  67.210 +	strcpy(gbCheatList[i].cheatDesc, desc);
  67.211 +
  67.212 +	gbCheatList[i].code = GBCHEAT_HEX_VALUE(code[0]) << 4 |
  67.213 +	                      GBCHEAT_HEX_VALUE(code[1]);
  67.214 +
  67.215 +	gbCheatList[i].value = GBCHEAT_HEX_VALUE(code[2]) << 4 |
  67.216 +	                       GBCHEAT_HEX_VALUE(code[3]);
  67.217 +
  67.218 +	gbCheatList[i].address = GBCHEAT_HEX_VALUE(code[6]) << 12 |
  67.219 +	                         GBCHEAT_HEX_VALUE(code[7]) << 8 |
  67.220 +	                         GBCHEAT_HEX_VALUE(code[4]) << 4 |
  67.221 +	                         GBCHEAT_HEX_VALUE(code[5]);
  67.222 +
  67.223 +	gbCheatList[i].compare = 0;
  67.224 +
  67.225 +	gbCheatList[i].enabled = true;
  67.226 +
  67.227 +	gbCheatMap[gbCheatList[i].address] = true;
  67.228 +
  67.229 +	gbCheatNumber++;
  67.230 +}
  67.231 +
  67.232 +bool gbVerifyGgCode(const char *code)
  67.233 +{
  67.234 +	int len = strlen(code);
  67.235 +
  67.236 +	if (len != 11 &&
  67.237 +	    len != 7 &&
  67.238 +	    len != 6 &&
  67.239 +	    len != 0)
  67.240 +		return false;
  67.241 +
  67.242 +	if (len == 0)
  67.243 +		return true;
  67.244 +
  67.245 +	if (!GBCHEAT_IS_HEX(code[0]))
  67.246 +		return false;
  67.247 +	if (!GBCHEAT_IS_HEX(code[1]))
  67.248 +		return false;
  67.249 +	if (!GBCHEAT_IS_HEX(code[2]))
  67.250 +		return false;
  67.251 +	if (code[3] != '-')
  67.252 +		return false;
  67.253 +	if (!GBCHEAT_IS_HEX(code[4]))
  67.254 +		return false;
  67.255 +	if (!GBCHEAT_IS_HEX(code[5]))
  67.256 +		return false;
  67.257 +	if (!GBCHEAT_IS_HEX(code[6]))
  67.258 +		return false;
  67.259 +	if (code[7] != 0)
  67.260 +	{
  67.261 +		if (code[7] != '-')
  67.262 +			return false;
  67.263 +		if (code[8] != 0)
  67.264 +		{
  67.265 +			if (!GBCHEAT_IS_HEX(code[8]))
  67.266 +				return false;
  67.267 +			if (!GBCHEAT_IS_HEX(code[9]))
  67.268 +				return false;
  67.269 +			if (!GBCHEAT_IS_HEX(code[10]))
  67.270 +				return false;
  67.271 +		}
  67.272 +	}
  67.273 +
  67.274 +	//  int replace = (GBCHEAT_HEX_VALUE(code[0]) << 4) +
  67.275 +	//    GBCHEAT_HEX_VALUE(code[1]);
  67.276 +
  67.277 +	int address = (GBCHEAT_HEX_VALUE(code[2]) << 8) +
  67.278 +	              (GBCHEAT_HEX_VALUE(code[4]) << 4) +
  67.279 +	              (GBCHEAT_HEX_VALUE(code[5])) +
  67.280 +	              ((GBCHEAT_HEX_VALUE(code[6]) ^ 0x0f) << 12);
  67.281 +
  67.282 +	if (address >= 0x8000 && address <= 0x9fff)
  67.283 +		return false;
  67.284 +
  67.285 +	if (address >= 0xc000)
  67.286 +		return false;
  67.287 +
  67.288 +	if (code[7] == 0 || code[8] == '0')
  67.289 +		return true;
  67.290 +
  67.291 +	int compare = (GBCHEAT_HEX_VALUE(code[8]) << 4) +
  67.292 +	              (GBCHEAT_HEX_VALUE(code[10]));
  67.293 +	compare  = compare ^ 0xff;
  67.294 +	compare  = (compare >> 2) | ((compare << 6) & 0xc0);
  67.295 +	compare ^= 0x45;
  67.296 +
  67.297 +	int cloak = (GBCHEAT_HEX_VALUE(code[8])) ^ (GBCHEAT_HEX_VALUE(code[9]));
  67.298 +
  67.299 +	if (cloak >= 1 && cloak <= 7)
  67.300 +		return false;
  67.301 +
  67.302 +	return true;
  67.303 +}
  67.304 +
  67.305 +void gbAddGgCheat(const char *code, const char *desc)
  67.306 +{
  67.307 +	if (gbCheatNumber > 99)
  67.308 +	{
  67.309 +		systemMessage(MSG_MAXIMUM_NUMBER_OF_CHEATS,
  67.310 +		              N_("Maximum number of cheats reached."));
  67.311 +		return;
  67.312 +	}
  67.313 +
  67.314 +	if (!gbVerifyGgCode(code))
  67.315 +	{
  67.316 +		systemMessage(MSG_INVALID_GAMEGENIE_CODE,
  67.317 +		              N_("Invalid GameGenie code: %s"), code);
  67.318 +		return;
  67.319 +	}
  67.320 +
  67.321 +	int i = gbCheatNumber;
  67.322 +
  67.323 +	int len = strlen(code);
  67.324 +
  67.325 +	strcpy(gbCheatList[i].cheatCode, code);
  67.326 +	strcpy(gbCheatList[i].cheatDesc, desc);
  67.327 +
  67.328 +	gbCheatList[i].code  = 1;
  67.329 +	gbCheatList[i].value = (GBCHEAT_HEX_VALUE(code[0]) << 4) +
  67.330 +	                       GBCHEAT_HEX_VALUE(code[1]);
  67.331 +
  67.332 +	gbCheatList[i].address = (GBCHEAT_HEX_VALUE(code[2]) << 8) +
  67.333 +	                         (GBCHEAT_HEX_VALUE(code[4]) << 4) +
  67.334 +	                         (GBCHEAT_HEX_VALUE(code[5])) +
  67.335 +	                         ((GBCHEAT_HEX_VALUE(code[6]) ^ 0x0f) << 12);
  67.336 +
  67.337 +	gbCheatList[i].compare = 0;
  67.338 +
  67.339 +	if (len != 7 && len != 8)
  67.340 +	{
  67.341 +		int compare = (GBCHEAT_HEX_VALUE(code[8]) << 4) +
  67.342 +		              (GBCHEAT_HEX_VALUE(code[10]));
  67.343 +		compare  = compare ^ 0xff;
  67.344 +		compare  = (compare >> 2) | ((compare << 6) & 0xc0);
  67.345 +		compare ^= 0x45;
  67.346 +
  67.347 +		gbCheatList[i].compare = compare;
  67.348 +		gbCheatList[i].code    = 0;
  67.349 +	}
  67.350 +
  67.351 +	gbCheatList[i].enabled = true;
  67.352 +
  67.353 +	gbCheatMap[gbCheatList[i].address] = true;
  67.354 +
  67.355 +	gbCheatNumber++;
  67.356 +}
  67.357 +
  67.358 +void gbCheatRemove(int i)
  67.359 +{
  67.360 +	if (i < 0 || i >= gbCheatNumber)
  67.361 +	{
  67.362 +		systemMessage(MSG_INVALID_CHEAT_TO_REMOVE,
  67.363 +		              N_("Invalid cheat to remove %d"), i);
  67.364 +		return;
  67.365 +	}
  67.366 +
  67.367 +	if ((i+1) <  gbCheatNumber)
  67.368 +	{
  67.369 +		memcpy(&gbCheatList[i], &gbCheatList[i+1], sizeof(gbCheat)*
  67.370 +		       (gbCheatNumber-i-1));
  67.371 +	}
  67.372 +
  67.373 +	gbCheatNumber--;
  67.374 +
  67.375 +	gbCheatUpdateMap();
  67.376 +}
  67.377 +
  67.378 +void gbCheatRemoveAll()
  67.379 +{
  67.380 +	gbCheatNumber = 0;
  67.381 +	gbCheatUpdateMap();
  67.382 +}
  67.383 +
  67.384 +void gbCheatEnable(int i)
  67.385 +{
  67.386 +	if (i >= 0 && i < gbCheatNumber)
  67.387 +	{
  67.388 +		if (!gbCheatList[i].enabled)
  67.389 +		{
  67.390 +			gbCheatList[i].enabled = true;
  67.391 +			gbCheatUpdateMap();
  67.392 +		}
  67.393 +	}
  67.394 +}
  67.395 +
  67.396 +void gbCheatDisable(int i)
  67.397 +{
  67.398 +	if (i >= 0 && i < gbCheatNumber)
  67.399 +	{
  67.400 +		if (gbCheatList[i].enabled)
  67.401 +		{
  67.402 +			gbCheatList[i].enabled = false;
  67.403 +			gbCheatUpdateMap();
  67.404 +		}
  67.405 +	}
  67.406 +}
  67.407 +
  67.408 +bool gbCheatReadGSCodeFile(const char *fileName)
  67.409 +{
  67.410 +	FILE *file = fopen(fileName, "rb");
  67.411 +
  67.412 +	if (!file)
  67.413 +		return false;
  67.414 +
  67.415 +	fseek(file, 0x18, SEEK_SET);
  67.416 +	int count = 0;
  67.417 +	fread(&count, 1, 2, file);
  67.418 +	int dummy = 0;
  67.419 +	gbCheatRemoveAll();
  67.420 +	char desc[13];
  67.421 +	char code[9];
  67.422 +	int  i;
  67.423 +	for (i = 0; i < count; i++)
  67.424 +	{
  67.425 +		fread(&dummy, 1, 2, file);
  67.426 +		fread(desc, 1, 12, file);
  67.427 +		desc[12] = 0;
  67.428 +		fread(code, 1, 8, file);
  67.429 +		code[8] = 0;
  67.430 +		gbAddGsCheat(code, desc);
  67.431 +	}
  67.432 +
  67.433 +	for (i = 0; i < gbCheatNumber; i++)
  67.434 +		gbCheatDisable(i);
  67.435 +
  67.436 +	fclose(file);
  67.437 +	return true;
  67.438 +}
  67.439 +
  67.440 +u8 gbCheatRead(u16 address)
  67.441 +{
  67.442 +	if (!cheatsEnabled)
  67.443 +		return gbReadMemoryQuick(address);
  67.444 +
  67.445 +	for (int i = 0; i < gbCheatNumber; i++)
  67.446 +	{
  67.447 +		if (gbCheatList[i].enabled && gbCheatList[i].address == address)
  67.448 +		{
  67.449 +			switch (gbCheatList[i].code)
  67.450 +			{
  67.451 +			case 0x100: // GameGenie support
  67.452 +				if (gbReadMemoryQuick(address) == gbCheatList[i].compare)
  67.453 +					return gbCheatList[i].value;
  67.454 +				break;
  67.455 +			case 0x00:
  67.456 +			case 0x01:
  67.457 +			case 0x80:
  67.458 +				return gbCheatList[i].value;
  67.459 +			case 0x90:
  67.460 +			case 0x91:
  67.461 +			case 0x92:
  67.462 +			case 0x93:
  67.463 +			case 0x94:
  67.464 +			case 0x95:
  67.465 +			case 0x96:
  67.466 +			case 0x97:
  67.467 +				if (address >= 0xd000 && address < 0xe000)
  67.468 +				{
  67.469 +					if (((gbMemoryMap[0x0d] - gbWram)/0x1000) ==
  67.470 +					    (gbCheatList[i].code - 0x90))
  67.471 +						return gbCheatList[i].value;
  67.472 +				}
  67.473 +				else
  67.474 +					return gbCheatList[i].value;
  67.475 +			}
  67.476 +		}
  67.477 +	}
  67.478 +	return gbReadMemoryQuick(address);
  67.479 +}
  67.480 +
    68.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    68.2 +++ b/src/gb/gbCheats.h	Sat Mar 03 10:31:27 2012 -0600
    68.3 @@ -0,0 +1,44 @@
    68.4 +#ifndef VBA_GB_CHEATS_H
    68.5 +#define VBA_GB_CHEATS_H
    68.6 +
    68.7 +#if _MSC_VER > 1000
    68.8 +#pragma once
    68.9 +#endif // _MSC_VER > 1000
   68.10 +
   68.11 +struct gbXxCheat
   68.12 +{
   68.13 +	char cheatDesc[100];
   68.14 +	char cheatCode[20];
   68.15 +};
   68.16 +
   68.17 +struct gbCheat
   68.18 +{
   68.19 +	char cheatCode[20];
   68.20 +	char cheatDesc[32];
   68.21 +	u16  address;
   68.22 +	int  code;
   68.23 +	u8   compare;
   68.24 +	u8   value;
   68.25 +	bool enabled;
   68.26 +};
   68.27 +
   68.28 +extern void gbCheatsSaveGame(gzFile);
   68.29 +extern void gbCheatsReadGame(gzFile, int);
   68.30 +extern void gbCheatsSaveCheatList(const char *);
   68.31 +extern bool gbCheatsLoadCheatList(const char *);
   68.32 +extern bool gbCheatReadGSCodeFile(const char *);
   68.33 +
   68.34 +extern void gbAddGsCheat(const char *, const char *);
   68.35 +extern void gbAddGgCheat(const char *, const char *);
   68.36 +extern void gbCheatRemove(int);
   68.37 +extern void gbCheatRemoveAll();
   68.38 +extern void gbCheatEnable(int);
   68.39 +extern void gbCheatDisable(int);
   68.40 +extern u8 gbCheatRead(u16);
   68.41 +
   68.42 +extern int     gbCheatNumber;
   68.43 +extern gbCheat gbCheatList[100];
   68.44 +extern bool    gbCheatMap[0x10000];
   68.45 +
   68.46 +#endif // VBA_GB_CHEATS_H
   68.47 +
    69.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    69.2 +++ b/src/gb/gbCodes.h	Sat Mar 03 10:31:27 2012 -0600
    69.3 @@ -0,0 +1,1388 @@
    69.4 + case 0x00: 
    69.5 +   // NOP
    69.6 +   break;
    69.7 + case 0x01: 
    69.8 +   // LD BC, NNNN
    69.9 +   BC.B.B0=gbReadMemory(PC.W++);
   69.10 +   BC.B.B1=gbReadMemory(PC.W++);
   69.11 +   break;
   69.12 + case 0x02:
   69.13 +   // LD (BC),A
   69.14 +   gbWriteMemory(BC.W,AF.B.B1);
   69.15 +   break;
   69.16 + case 0x03:
   69.17 +   // INC BC
   69.18 +   BC.W++;
   69.19 +   break;
   69.20 + case 0x04: 
   69.21 +   // INC B
   69.22 +   BC.B.B1++; 
   69.23 +   AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[BC.B.B1]| (BC.B.B1&0x0F? 0:H_FLAG);
   69.24 +   break;
   69.25 + case 0x05:
   69.26 +   // DEC B
   69.27 +   BC.B.B1--; 
   69.28 +   AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[BC.B.B1]|
   69.29 +     ((BC.B.B1&0x0F)==0x0F? H_FLAG:0);
   69.30 +   break;
   69.31 + case 0x06:
   69.32 +   // LD B, NN
   69.33 +   BC.B.B1=gbReadOpcode(PC.W++);
   69.34 +   break;
   69.35 + case 0x07:
   69.36 +   // RLCA
   69.37 +   tempValue=AF.B.B1&0x80? C_FLAG:0;
   69.38 +   AF.B.B1=((AF.B.B1<<1)|(AF.B.B1>>7)) & 0xFF;
   69.39 +   AF.B.B0=tempValue;
   69.40 +   break;
   69.41 + case 0x08:
   69.42 +   // LD (NNNN), SP
   69.43 +   tempRegister.B.B0=gbReadOpcode(PC.W++);
   69.44 +   tempRegister.B.B1=gbReadOpcode(PC.W++);
   69.45 +   gbWriteMemory(tempRegister.W++,SP.B.B0);
   69.46 +   gbWriteMemory(tempRegister.W,SP.B.B1);
   69.47 +   break;
   69.48 + case 0x09:
   69.49 +   // ADD HL,BC
   69.50 +   tempRegister.W=(HL.W+BC.W)&0xFFFF;
   69.51 +   AF.B.B0= (AF.B.B0 & Z_FLAG)| ((HL.W^BC.W^tempRegister.W)&0x1000? H_FLAG:0)|
   69.52 +     (((long)HL.W+(long)BC.W)&0x10000? C_FLAG:0);
   69.53 +   HL.W=tempRegister.W;
   69.54 +   break;
   69.55 + case 0x0a:
   69.56 +   // LD A,(BC)
   69.57 +   AF.B.B1=gbReadMemory(BC.W);
   69.58 +   break;
   69.59 + case 0x0b:
   69.60 +   // DEC BC
   69.61 +   BC.W--;
   69.62 +   break;   
   69.63 + case 0x0c:
   69.64 +   // INC C
   69.65 +   BC.B.B0++;
   69.66 +   AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[BC.B.B0]| (BC.B.B0&0x0F? 0:H_FLAG);
   69.67 +   break;
   69.68 + case 0x0d:
   69.69 +   // DEC C
   69.70 +   BC.B.B0--;
   69.71 +   AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[BC.B.B0]|
   69.72 +     ((BC.B.B0&0x0F)==0x0F? H_FLAG:0);
   69.73 +   break;   
   69.74 + case 0x0e:
   69.75 +   // LD C, NN
   69.76 +   BC.B.B0=gbReadOpcode(PC.W++);
   69.77 +   break;
   69.78 + case 0x0f:
   69.79 +   // RRCA
   69.80 +   tempValue=AF.B.B1&0x01;
   69.81 +   AF.B.B1=(AF.B.B1>>1)|(tempValue? 0x80:0);
   69.82 +   AF.B.B0=(tempValue<<4);
   69.83 +   break;
   69.84 + case 0x10:
   69.85 +   // STOP
   69.86 +   opcode = gbReadOpcode(PC.W++);
   69.87 +   if(gbCgbMode) {
   69.88 +     if(gbReadMemoryQuick(0xff4d) & 1) {
   69.89 +       gbSpeedSwitch();
   69.90 +       
   69.91 +       if(gbSpeed == 0)
   69.92 +         gbWriteMemoryQuick(0xff4d, 0x00);
   69.93 +       else
   69.94 +         gbWriteMemoryQuick(0xff4d, 0x80);
   69.95 +     }
   69.96 +   }
   69.97 +   break;
   69.98 + case 0x11:
   69.99 +   // LD DE, NNNN
  69.100 +   DE.B.B0=gbReadMemory(PC.W++);
  69.101 +   DE.B.B1=gbReadMemory(PC.W++);
  69.102 +   break;
  69.103 + case 0x12:
  69.104 +   // LD (DE),A
  69.105 +   gbWriteMemory(DE.W,AF.B.B1);
  69.106 +   break;
  69.107 + case 0x13:
  69.108 +   // INC DE
  69.109 +   DE.W++;
  69.110 +   break;
  69.111 + case 0x14:
  69.112 +   // INC D
  69.113 +   DE.B.B1++;
  69.114 +   AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[DE.B.B1]| (DE.B.B1&0x0F? 0:H_FLAG);
  69.115 +   break;
  69.116 + case 0x15:
  69.117 +   // DEC D
  69.118 +   DE.B.B1--;
  69.119 +   AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[DE.B.B1]|
  69.120 +     ((DE.B.B1&0x0F)==0x0F? H_FLAG:0);
  69.121 +   break;
  69.122 + case 0x16:
  69.123 +   //  LD D,NN
  69.124 +   DE.B.B1=gbReadOpcode(PC.W++);
  69.125 +   break;
  69.126 + case 0x17:
  69.127 +   // RLA
  69.128 +   tempValue=AF.B.B1&0x80? C_FLAG:0;
  69.129 +   AF.B.B1=((AF.B.B1<<1)|((AF.B.B0&C_FLAG)>>4)) & 0xFF;
  69.130 +   AF.B.B0=tempValue;
  69.131 +   break;
  69.132 + case 0x18:
  69.133 +   // JR NN
  69.134 +   PC.W+=(s8)gbReadMemory(PC.W)+1;
  69.135 +   break;
  69.136 + case 0x19:
  69.137 +   // ADD HL,DE
  69.138 +   tempRegister.W=(HL.W+DE.W)&0xFFFF;
  69.139 +   AF.B.B0= (AF.B.B0 & Z_FLAG)| ((HL.W^DE.W^tempRegister.W)&0x1000? H_FLAG:0)|
  69.140 +     (((long)HL.W+(long)DE.W)&0x10000? C_FLAG:0);
  69.141 +   HL.W=tempRegister.W;
  69.142 +   break;
  69.143 + case 0x1a:
  69.144 +   // LD A,(DE)
  69.145 +   AF.B.B1=gbReadMemory(DE.W);
  69.146 +   break;   
  69.147 + case 0x1b:
  69.148 +   // DEC DE
  69.149 +   DE.W--;
  69.150 +   break;
  69.151 + case 0x1c:
  69.152 +   // INC E
  69.153 +   DE.B.B0++;
  69.154 +   AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[DE.B.B0]| (DE.B.B0&0x0F? 0:H_FLAG);
  69.155 +   break;
  69.156 + case 0x1d:
  69.157 +   // DEC E
  69.158 +   DE.B.B0--;
  69.159 +   AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[DE.B.B0]|
  69.160 +     ((DE.B.B0&0x0F)==0x0F? H_FLAG:0);
  69.161 +   break;
  69.162 + case 0x1e:
  69.163 +   // LD E,NN
  69.164 +   DE.B.B0=gbReadOpcode(PC.W++);
  69.165 +   break;   
  69.166 + case 0x1f:
  69.167 +   // RRA
  69.168 +   tempValue=AF.B.B1&0x01;
  69.169 +   AF.B.B1=(AF.B.B1>>1)|(AF.B.B0&C_FLAG? 0x80:0);
  69.170 +   AF.B.B0=(tempValue<<4);
  69.171 +   break;
  69.172 + case 0x20:
  69.173 +   // JR NZ,NN
  69.174 +   if(AF.B.B0&Z_FLAG)
  69.175 +     PC.W++;
  69.176 +   else {
  69.177 +     PC.W+=(s8)gbReadMemory(PC.W)+1;
  69.178 +     clockTicks++;
  69.179 +   }
  69.180 +   break;
  69.181 + case 0x21:
  69.182 +   // LD HL,NNNN
  69.183 +   HL.B.B0=gbReadMemory(PC.W++);
  69.184 +   HL.B.B1=gbReadMemory(PC.W++);
  69.185 +   break;   
  69.186 + case 0x22:
  69.187 +   // LDI (HL),A
  69.188 +   gbWriteMemory(HL.W++,AF.B.B1);
  69.189 +   break;
  69.190 + case 0x23:
  69.191 +   // INC HL
  69.192 +   HL.W++;
  69.193 +   break;
  69.194 + case 0x24:
  69.195 +   // INC H
  69.196 +   HL.B.B1++;
  69.197 +   AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[HL.B.B1]| (HL.B.B1&0x0F? 0:H_FLAG);
  69.198 +   break;
  69.199 + case 0x25:
  69.200 +   // DEC H
  69.201 +   HL.B.B1--;
  69.202 +   AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[HL.B.B1]|
  69.203 +     ((HL.B.B1&0x0F)==0x0F? H_FLAG:0);
  69.204 +   break;
  69.205 + case 0x26:
  69.206 +   // LD H,NN
  69.207 +   HL.B.B1=gbReadOpcode(PC.W++);
  69.208 +   break;
  69.209 + case 0x27:
  69.210 +   // DAA
  69.211 +   tempRegister.W=AF.B.B1;
  69.212 +   if(AF.B.B0&C_FLAG) tempRegister.W|=256;
  69.213 +   if(AF.B.B0&H_FLAG) tempRegister.W|=512;
  69.214 +   if(AF.B.B0&N_FLAG) tempRegister.W|=1024;
  69.215 +   AF.W=DAATable[tempRegister.W];
  69.216 +   break;
  69.217 + case 0x28:
  69.218 +   // JR Z,NN
  69.219 +   if(AF.B.B0&Z_FLAG) {
  69.220 +     PC.W+=(s8)gbReadMemory(PC.W)+1;
  69.221 +     clockTicks++;
  69.222 +   } else
  69.223 +     PC.W++;
  69.224 +   break;
  69.225 + case 0x29:
  69.226 +   // ADD HL,HL
  69.227 +   tempRegister.W=(HL.W+HL.W)&0xFFFF; AF.B.B0= (AF.B.B0 & Z_FLAG)|
  69.228 +                             ((HL.W^HL.W^tempRegister.W)&0x1000? H_FLAG:0)|
  69.229 +                             (((long)HL.W+(long)HL.W)&0x10000? C_FLAG:0);
  69.230 +   HL.W=tempRegister.W;
  69.231 +   break;
  69.232 + case 0x2a:
  69.233 +   // LDI A,(HL)
  69.234 +   AF.B.B1 = gbReadMemory(HL.W++);
  69.235 +   break;
  69.236 + case 0x2b:
  69.237 +   // DEC HL
  69.238 +   HL.W--;
  69.239 +   break;   
  69.240 + case 0x2c:
  69.241 +   // INC L
  69.242 +   HL.B.B0++;
  69.243 +   AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[HL.B.B0]| (HL.B.B0&0x0F? 0:H_FLAG);
  69.244 +   break;
  69.245 + case 0x2d:
  69.246 +   // DEC L
  69.247 +   HL.B.B0--;
  69.248 +   AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[HL.B.B0]|
  69.249 +     ((HL.B.B0&0x0F)==0x0F? H_FLAG:0);
  69.250 +   break;
  69.251 + case 0x2e:
  69.252 +   // LD L,NN
  69.253 +   HL.B.B0=gbReadOpcode(PC.W++);
  69.254 +   break;   
  69.255 + case 0x2f:
  69.256 +   // CPL
  69.257 +   AF.B.B1 ^= 255;
  69.258 +   AF.B.B0|=N_FLAG|H_FLAG;
  69.259 +   break;
  69.260 + case 0x30:
  69.261 +   // JR NC,NN
  69.262 +   if(AF.B.B0&C_FLAG)
  69.263 +     PC.W++;
  69.264 +   else {
  69.265 +     PC.W+=(s8)gbReadMemory(PC.W)+1;
  69.266 +     clockTicks++;
  69.267 +   }
  69.268 +   break;
  69.269 + case 0x31:
  69.270 +   // LD SP,NNNN
  69.271 +   SP.B.B0=gbReadMemory(PC.W++);
  69.272 +   SP.B.B1=gbReadMemory(PC.W++);
  69.273 +   break;
  69.274 + case 0x32:
  69.275 +   // LDD (HL),A
  69.276 +   gbWriteMemory(HL.W--,AF.B.B1);
  69.277 +   break;
  69.278 + case 0x33:
  69.279 +   // INC SP
  69.280 +   SP.W++;
  69.281 +   break;
  69.282 + case 0x34:
  69.283 +   // INC (HL)
  69.284 +   tempValue=(gbReadMemory(HL.W)+1) & 0xFF;
  69.285 +   AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[tempValue]| (tempValue&0x0F? 0:H_FLAG);
  69.286 +   gbWriteMemory(HL.W,tempValue);
  69.287 +   break;
  69.288 + case 0x35:
  69.289 +   // DEC (HL)
  69.290 +   tempValue=(gbReadMemory(HL.W)-1) & 0xFF;
  69.291 +   AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[tempValue]|
  69.292 +     ((tempValue&0x0F)==0x0F? H_FLAG:0);gbWriteMemory(HL.W,tempValue);
  69.293 +   break;
  69.294 + case 0x36:
  69.295 +   // LD (HL),NN
  69.296 +   gbWriteMemory(HL.W,gbReadOpcode(PC.W++));
  69.297 +   break;
  69.298 + case 0x37:
  69.299 +   // SCF
  69.300 +   AF.B.B0 = AF.B.B0 & Z_FLAG | C_FLAG;
  69.301 +   break;   
  69.302 +case 0x38:
  69.303 +  // JR C,NN
  69.304 +  if(AF.B.B0&C_FLAG) {
  69.305 +    PC.W+=(s8)gbReadMemory(PC.W)+1;
  69.306 +    clockTicks ++;
  69.307 +  } else
  69.308 +    PC.W++;
  69.309 +  break;
  69.310 + case 0x39:
  69.311 +   // ADD HL,SP
  69.312 +   tempRegister.W=(HL.W+SP.W)&0xFFFF;
  69.313 +   AF.B.B0= (AF.B.B0 & Z_FLAG)| ((HL.W^SP.W^tempRegister.W)&0x1000? H_FLAG:0)|
  69.314 +     (((long)HL.W+(long)SP.W)&0x10000? C_FLAG:0);
  69.315 +   HL.W=tempRegister.W;
  69.316 +   break;
  69.317 + case 0x3a:
  69.318 +   // LDD A,(HL)
  69.319 +   AF.B.B1 = gbReadMemory(HL.W--);
  69.320 +   break;
  69.321 + case 0x3b:
  69.322 +   // DEC SP
  69.323 +   SP.W--;
  69.324 +   break;
  69.325 + case 0x3c:
  69.326 +   // INC A
  69.327 +   AF.B.B1++;
  69.328 +   AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[AF.B.B1]| (AF.B.B1&0x0F? 0:H_FLAG);
  69.329 +   break;
  69.330 + case 0x3d:
  69.331 +   // DEC A
  69.332 +   AF.B.B1--;
  69.333 +   AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[AF.B.B1]|
  69.334 +     ((AF.B.B1&0x0F)==0x0F? H_FLAG:0);
  69.335 +   break;
  69.336 + case 0x3e:
  69.337 +   // LD A,NN
  69.338 +   AF.B.B1=gbReadOpcode(PC.W++);
  69.339 +   break;
  69.340 + case 0x3f:
  69.341 +   // CCF
  69.342 +   AF.B.B0^=C_FLAG;AF.B.B0&=~(N_FLAG|H_FLAG);
  69.343 +   break;
  69.344 + case 0x40:
  69.345 +   // LD B,B
  69.346 +   BC.B.B1=BC.B.B1;
  69.347 +   break;
  69.348 + case 0x41:
  69.349 +   // LD B,C
  69.350 +   BC.B.B1=BC.B.B0;
  69.351 +   break;
  69.352 + case 0x42:
  69.353 +   // LD B,D
  69.354 +   BC.B.B1=DE.B.B1;
  69.355 +   break;
  69.356 + case 0x43:
  69.357 +   // LD B,E
  69.358 +   BC.B.B1=DE.B.B0;
  69.359 +   break;
  69.360 + case 0x44:
  69.361 +   // LD B,H
  69.362 +   BC.B.B1=HL.B.B1;
  69.363 +   break;
  69.364 + case 0x45:
  69.365 +   // LD B,L
  69.366 +   BC.B.B1=HL.B.B0;
  69.367 +   break;
  69.368 + case 0x46:
  69.369 +   // LD B,(HL)
  69.370 +   BC.B.B1=gbReadMemory(HL.W);
  69.371 +   break;
  69.372 + case 0x47:
  69.373 +   // LD B,A
  69.374 +   BC.B.B1=AF.B.B1;
  69.375 +   break;
  69.376 + case 0x48:
  69.377 +   // LD C,B
  69.378 +   BC.B.B0=BC.B.B1;
  69.379 +   break;
  69.380 + case 0x49:
  69.381 +   // LD C,C
  69.382 +   BC.B.B0=BC.B.B0;
  69.383 +   break;
  69.384 + case 0x4a:
  69.385 +   // LD C,D
  69.386 +   BC.B.B0=DE.B.B1;
  69.387 +   break;
  69.388 + case 0x4b:
  69.389 +   // LD C,E
  69.390 +   BC.B.B0=DE.B.B0;
  69.391 +   break;
  69.392 + case 0x4c:
  69.393 +   // LD C,H
  69.394 +   BC.B.B0=HL.B.B1;
  69.395 +   break;
  69.396 + case 0x4d:
  69.397 +   // LD C,L
  69.398 +   BC.B.B0=HL.B.B0;
  69.399 +   break;
  69.400 + case 0x4e:
  69.401 +   // LD C,(HL)
  69.402 +   BC.B.B0=gbReadMemory(HL.W);
  69.403 +   break;
  69.404 + case 0x4f:
  69.405 +   // LD C,A
  69.406 +   BC.B.B0=AF.B.B1;
  69.407 +   break;
  69.408 + case 0x50:
  69.409 +   // LD D,B
  69.410 +   DE.B.B1=BC.B.B1;
  69.411 +   break;
  69.412 + case 0x51:
  69.413 +   // LD D,C
  69.414 +   DE.B.B1=BC.B.B0;
  69.415 +   break;
  69.416 + case 0x52:
  69.417 +   // LD D,D
  69.418 +   DE.B.B1=DE.B.B1;
  69.419 +   break;
  69.420 + case 0x53:
  69.421 +   // LD D,E
  69.422 +   DE.B.B1=DE.B.B0;
  69.423 +   break;
  69.424 + case 0x54:
  69.425 +   // LD D,H
  69.426 +   DE.B.B1=HL.B.B1;
  69.427 +   break;
  69.428 + case 0x55:
  69.429 +   // LD D,L
  69.430 +   DE.B.B1=HL.B.B0;
  69.431 +   break;
  69.432 + case 0x56:
  69.433 +   // LD D,(HL)
  69.434 +   DE.B.B1=gbReadMemory(HL.W);
  69.435 +   break;
  69.436 + case 0x57:
  69.437 +   // LD D,A
  69.438 +   DE.B.B1=AF.B.B1;
  69.439 +   break;
  69.440 + case 0x58:
  69.441 +   // LD E,B
  69.442 +   DE.B.B0=BC.B.B1;
  69.443 +   break;
  69.444 + case 0x59:
  69.445 +   // LD E,C
  69.446 +   DE.B.B0=BC.B.B0;
  69.447 +   break;
  69.448 + case 0x5a:
  69.449 +   // LD E,D
  69.450 +   DE.B.B0=DE.B.B1;
  69.451 +   break;
  69.452 + case 0x5b:
  69.453 +   // LD E,E
  69.454 +   DE.B.B0=DE.B.B0;
  69.455 +   break;
  69.456 + case 0x5c:
  69.457 +   // LD E,H
  69.458 +   DE.B.B0=HL.B.B1;
  69.459 +   break;
  69.460 + case 0x5d:
  69.461 +   // LD E,L
  69.462 +   DE.B.B0=HL.B.B0;
  69.463 +   break;
  69.464 + case 0x5e:
  69.465 +   // LD E,(HL)
  69.466 +   DE.B.B0=gbReadMemory(HL.W);
  69.467 +   break;
  69.468 + case 0x5f:
  69.469 +   // LD E,A
  69.470 +   DE.B.B0=AF.B.B1;
  69.471 +   break;
  69.472 + case 0x60:
  69.473 +   // LD H,B
  69.474 +   HL.B.B1=BC.B.B1;
  69.475 +   break;
  69.476 + case 0x61:
  69.477 +   // LD H,C
  69.478 +   HL.B.B1=BC.B.B0;
  69.479 +   break;
  69.480 + case 0x62:
  69.481 +   // LD H,D
  69.482 +   HL.B.B1=DE.B.B1;
  69.483 +   break;
  69.484 + case 0x63:
  69.485 +   // LD H,E
  69.486 +   HL.B.B1=DE.B.B0;
  69.487 +   break;
  69.488 + case 0x64:
  69.489 +   // LD H,H
  69.490 +   HL.B.B1=HL.B.B1;
  69.491 +   break;
  69.492 + case 0x65:
  69.493 +   // LD H,L
  69.494 +   HL.B.B1=HL.B.B0;
  69.495 +   break;
  69.496 + case 0x66:
  69.497 +   // LD H,(HL)
  69.498 +   HL.B.B1=gbReadMemory(HL.W);
  69.499 +   break;
  69.500 + case 0x67:
  69.501 +   // LD H,A
  69.502 +   HL.B.B1=AF.B.B1;
  69.503 +   break;
  69.504 + case 0x68:
  69.505 +   // LD L,B
  69.506 +   HL.B.B0=BC.B.B1;
  69.507 +   break;
  69.508 + case 0x69:
  69.509 +   // LD L,C
  69.510 +   HL.B.B0=BC.B.B0;
  69.511 +   break;
  69.512 + case 0x6a:
  69.513 +   // LD L,D
  69.514 +   HL.B.B0=DE.B.B1;
  69.515 +   break;
  69.516 + case 0x6b:
  69.517 +   // LD L,E
  69.518 +   HL.B.B0=DE.B.B0;
  69.519 +   break;
  69.520 + case 0x6c:
  69.521 +   // LD L,H
  69.522 +   HL.B.B0=HL.B.B1;
  69.523 +   break;
  69.524 + case 0x6d:
  69.525 +   // LD L,L
  69.526 +   HL.B.B0=HL.B.B0;
  69.527 +   break;
  69.528 + case 0x6e:
  69.529 +   // LD L,(HL)
  69.530 +   HL.B.B0=gbReadMemory(HL.W);
  69.531 +   break;
  69.532 + case 0x6f:
  69.533 +   // LD L,A
  69.534 +   HL.B.B0=AF.B.B1;
  69.535 +   break;
  69.536 + case 0x70:
  69.537 +   // LD (HL),B
  69.538 +   gbWriteMemory(HL.W,BC.B.B1);
  69.539 +   break;
  69.540 + case 0x71:
  69.541 +   // LD (HL),C
  69.542 +   gbWriteMemory(HL.W,BC.B.B0);
  69.543 +   break;
  69.544 + case 0x72:
  69.545 +   // LD (HL),D
  69.546 +   gbWriteMemory(HL.W,DE.B.B1);
  69.547 +   break;
  69.548 + case 0x73:
  69.549 +   // LD (HL),E
  69.550 +   gbWriteMemory(HL.W,DE.B.B0);
  69.551 +   break;
  69.552 + case 0x74:
  69.553 +   // LD (HL),H
  69.554 +   gbWriteMemory(HL.W,HL.B.B1);
  69.555 +   break;
  69.556 + case 0x75:
  69.557 +   // LD (HL),L
  69.558 +   gbWriteMemory(HL.W,HL.B.B0);
  69.559 +   break;
  69.560 + case 0x76:
  69.561 +   // HALT
  69.562 +   if(IFF & 1) {
  69.563 +     PC.W--;
  69.564 +     IFF |= 0x80;
  69.565 +   } else {
  69.566 +     if((register_IE & register_IF) > 0)
  69.567 +       IFF |= 0x100;
  69.568 +     else {
  69.569 +       PC.W--;
  69.570 +       IFF |= 0x81;
  69.571 +     }
  69.572 +   }
  69.573 +   break;
  69.574 + case 0x77:
  69.575 +   // LD (HL),A
  69.576 +   gbWriteMemory(HL.W,AF.B.B1);
  69.577 +   break;
  69.578 + case 0x78:
  69.579 +   // LD A,B
  69.580 +   AF.B.B1=BC.B.B1;
  69.581 +   break;
  69.582 + case 0x79:
  69.583 +   // LD A,C
  69.584 +   AF.B.B1=BC.B.B0;
  69.585 +   break;
  69.586 + case 0x7a:
  69.587 +   // LD A,D
  69.588 +   AF.B.B1=DE.B.B1;
  69.589 +   break;
  69.590 + case 0x7b:
  69.591 +   // LD A,E
  69.592 +   AF.B.B1=DE.B.B0;
  69.593 +   break;
  69.594 + case 0x7c:
  69.595 +   // LD A,H
  69.596 +   AF.B.B1=HL.B.B1;
  69.597 +   break;
  69.598 + case 0x7d:
  69.599 +   // LD A,L
  69.600 +   AF.B.B1=HL.B.B0;
  69.601 +   break;
  69.602 + case 0x7e:
  69.603 +   // LD A,(HL)
  69.604 +   AF.B.B1=gbReadMemory(HL.W);
  69.605 +   break;
  69.606 + case 0x7f:
  69.607 +   // LD A,A
  69.608 +   AF.B.B1=AF.B.B1;
  69.609 +   break;
  69.610 + case 0x80:
  69.611 +   // ADD B
  69.612 +   tempRegister.W=AF.B.B1+BC.B.B1;
  69.613 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.614 +     ((AF.B.B1^BC.B.B1^tempRegister.B.B0)&0x10 ? H_FLAG:0);
  69.615 +   AF.B.B1=tempRegister.B.B0;
  69.616 +   break;
  69.617 + case 0x81:
  69.618 +   // ADD C
  69.619 +   tempRegister.W=AF.B.B1+BC.B.B0;
  69.620 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.621 +     ((AF.B.B1^BC.B.B0^tempRegister.B.B0)&0x10 ? H_FLAG:0);
  69.622 +   AF.B.B1=tempRegister.B.B0;
  69.623 +   break;
  69.624 + case 0x82:
  69.625 +   // ADD D
  69.626 +   tempRegister.W=AF.B.B1+DE.B.B1;
  69.627 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.628 +     ((AF.B.B1^DE.B.B1^tempRegister.B.B0)&0x10 ? H_FLAG:0);
  69.629 +   AF.B.B1=tempRegister.B.B0;
  69.630 +   break;
  69.631 + case 0x83:
  69.632 +   // ADD E
  69.633 +   tempRegister.W=AF.B.B1+DE.B.B0;
  69.634 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.635 +     ((AF.B.B1^DE.B.B0^tempRegister.B.B0)&0x10 ? H_FLAG:0);
  69.636 +   AF.B.B1=tempRegister.B.B0;
  69.637 +   break;
  69.638 + case 0x84:
  69.639 +   // ADD H
  69.640 +   tempRegister.W=AF.B.B1+HL.B.B1;
  69.641 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.642 +     ((AF.B.B1^HL.B.B1^tempRegister.B.B0)&0x10 ? H_FLAG:0);
  69.643 +   AF.B.B1=tempRegister.B.B0;
  69.644 +   break;
  69.645 + case 0x85:
  69.646 +   // ADD L
  69.647 +   tempRegister.W=AF.B.B1+HL.B.B0;
  69.648 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.649 +     ((AF.B.B1^HL.B.B0^tempRegister.B.B0)&0x10 ? H_FLAG:0);
  69.650 +   AF.B.B1=tempRegister.B.B0;
  69.651 +   break;
  69.652 + case 0x86:
  69.653 +   // ADD (HL)
  69.654 +   tempValue=gbReadMemory(HL.W);
  69.655 +   tempRegister.W=AF.B.B1+tempValue;
  69.656 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.657 +     ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10 ? H_FLAG:0);
  69.658 +   AF.B.B1=tempRegister.B.B0;
  69.659 +   break;
  69.660 + case 0x87:
  69.661 +   // ADD A
  69.662 +   tempRegister.W=AF.B.B1+AF.B.B1;
  69.663 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.664 +     ((AF.B.B1^AF.B.B1^tempRegister.B.B0)&0x10 ? H_FLAG:0);
  69.665 +   AF.B.B1=tempRegister.B.B0;
  69.666 +   break;
  69.667 + case 0x88:
  69.668 +   // ADC B:
  69.669 +   tempRegister.W=AF.B.B1+BC.B.B1+(AF.B.B0&C_FLAG ? 1 : 0);
  69.670 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.671 +     ((AF.B.B1^BC.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.672 +   AF.B.B1=tempRegister.B.B0;
  69.673 +   break;
  69.674 + case 0x89:
  69.675 +   // ADC C
  69.676 +   tempRegister.W=AF.B.B1+BC.B.B0+(AF.B.B0&C_FLAG ? 1 : 0);
  69.677 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.678 +     ((AF.B.B1^BC.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.679 +   AF.B.B1=tempRegister.B.B0;
  69.680 +   break;
  69.681 + case 0x8a:
  69.682 +   // ADC D
  69.683 +   tempRegister.W=AF.B.B1+DE.B.B1+(AF.B.B0&C_FLAG ? 1 : 0);
  69.684 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.685 +     ((AF.B.B1^DE.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.686 +   AF.B.B1=tempRegister.B.B0;
  69.687 +   break;
  69.688 + case 0x8b:
  69.689 +   // ADC E
  69.690 +   tempRegister.W=AF.B.B1+DE.B.B0+(AF.B.B0&C_FLAG ? 1 : 0);
  69.691 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.692 +     ((AF.B.B1^DE.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.693 +   AF.B.B1=tempRegister.B.B0;
  69.694 +   break;
  69.695 + case 0x8c:
  69.696 +   // ADC H
  69.697 +   tempRegister.W=AF.B.B1+HL.B.B1+(AF.B.B0&C_FLAG ? 1 : 0);
  69.698 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.699 +     ((AF.B.B1^HL.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0); AF.B.B1=tempRegister.B.B0;
  69.700 +   break;
  69.701 + case 0x8d:
  69.702 +   // ADC L
  69.703 +   tempRegister.W=AF.B.B1+HL.B.B0+(AF.B.B0&C_FLAG ? 1 : 0);
  69.704 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.705 +     ((AF.B.B1^HL.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.706 +   AF.B.B1=tempRegister.B.B0;
  69.707 +   break;
  69.708 + case 0x8e:
  69.709 +   // ADC (HL)
  69.710 +   tempValue=gbReadMemory(HL.W);
  69.711 +   tempRegister.W=AF.B.B1+tempValue+(AF.B.B0&C_FLAG ? 1 : 0);
  69.712 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.713 +     ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.714 +   AF.B.B1=tempRegister.B.B0;
  69.715 +   break;
  69.716 + case 0x8f:
  69.717 +   // ADC A
  69.718 +   tempRegister.W=AF.B.B1+AF.B.B1+(AF.B.B0&C_FLAG ? 1 : 0);
  69.719 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.720 +     ((AF.B.B1^AF.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.721 +   AF.B.B1=tempRegister.B.B0;
  69.722 +   break;
  69.723 + case 0x90:
  69.724 +   // SUB B
  69.725 +   tempRegister.W=AF.B.B1-BC.B.B1;
  69.726 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.727 +     ((AF.B.B1^BC.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.728 +   AF.B.B1=tempRegister.B.B0;
  69.729 +   break;
  69.730 + case 0x91:
  69.731 +   // SUB C
  69.732 +   tempRegister.W=AF.B.B1-BC.B.B0;
  69.733 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.734 +     ((AF.B.B1^BC.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.735 +   AF.B.B1=tempRegister.B.B0;
  69.736 +   break;
  69.737 + case 0x92:
  69.738 +   // SUB D
  69.739 +   tempRegister.W=AF.B.B1-DE.B.B1;
  69.740 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.741 +     ((AF.B.B1^DE.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.742 +   AF.B.B1=tempRegister.B.B0;
  69.743 +   break;
  69.744 + case 0x93:
  69.745 +   // SUB E
  69.746 +   tempRegister.W=AF.B.B1-DE.B.B0;
  69.747 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.748 +     ((AF.B.B1^DE.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.749 +   AF.B.B1=tempRegister.B.B0;
  69.750 +   break;
  69.751 + case 0x94:
  69.752 +   // SUB H
  69.753 +   tempRegister.W=AF.B.B1-HL.B.B1;
  69.754 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.755 +     ((AF.B.B1^HL.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.756 +   AF.B.B1=tempRegister.B.B0;
  69.757 +   break;
  69.758 + case 0x95:
  69.759 +   // SUB L
  69.760 +   tempRegister.W=AF.B.B1-HL.B.B0;
  69.761 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.762 +     ((AF.B.B1^HL.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.763 +   AF.B.B1=tempRegister.B.B0;
  69.764 +   break;
  69.765 + case 0x96:
  69.766 +   // SUB (HL)
  69.767 +   tempValue=gbReadMemory(HL.W);
  69.768 +   tempRegister.W=AF.B.B1-tempValue;
  69.769 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.770 +     ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.771 +   AF.B.B1=tempRegister.B.B0;
  69.772 +   break;
  69.773 + case 0x97:
  69.774 +   // SUB A
  69.775 +   AF.B.B1=0;
  69.776 +   AF.B.B0=N_FLAG|Z_FLAG;
  69.777 +   break;
  69.778 + case 0x98:
  69.779 +   // SBC B
  69.780 +   tempRegister.W=AF.B.B1-BC.B.B1-(AF.B.B0&C_FLAG ? 1 : 0);
  69.781 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.782 +     ((AF.B.B1^BC.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.783 +   AF.B.B1=tempRegister.B.B0;
  69.784 +   break;
  69.785 + case 0x99:
  69.786 +   // SBC C
  69.787 +   tempRegister.W=AF.B.B1-BC.B.B0-(AF.B.B0&C_FLAG ? 1 : 0);
  69.788 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.789 +     ((AF.B.B1^BC.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.790 +   AF.B.B1=tempRegister.B.B0;
  69.791 +   break;
  69.792 + case 0x9a:
  69.793 +   // SBC D
  69.794 +   tempRegister.W=AF.B.B1-DE.B.B1-(AF.B.B0&C_FLAG ? 1 : 0);
  69.795 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.796 +     ((AF.B.B1^DE.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.797 +   AF.B.B1=tempRegister.B.B0;
  69.798 +   break;
  69.799 + case 0x9b:
  69.800 +   // SBC E
  69.801 +   tempRegister.W=AF.B.B1-DE.B.B0-(AF.B.B0&C_FLAG ? 1 : 0);
  69.802 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.803 +     ((AF.B.B1^DE.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.804 +   AF.B.B1=tempRegister.B.B0;
  69.805 +   break;
  69.806 + case 0x9c:
  69.807 +   // SBC H
  69.808 +   tempRegister.W=AF.B.B1-HL.B.B1-(AF.B.B0&C_FLAG ? 1 : 0);
  69.809 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.810 +     ((AF.B.B1^HL.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.811 +   AF.B.B1=tempRegister.B.B0;
  69.812 +   break;
  69.813 + case 0x9d:
  69.814 +   // SBC L
  69.815 +   tempRegister.W=AF.B.B1-HL.B.B0-(AF.B.B0&C_FLAG ? 1 : 0);
  69.816 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.817 +     ((AF.B.B1^HL.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.818 +   AF.B.B1=tempRegister.B.B0;
  69.819 +   break;
  69.820 + case 0x9e:
  69.821 +   // SBC (HL)
  69.822 +   tempValue=gbReadMemory(HL.W);
  69.823 +   tempRegister.W=AF.B.B1-tempValue-(AF.B.B0&C_FLAG ? 1 : 0);
  69.824 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.825 +     ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.826 +   AF.B.B1=tempRegister.B.B0;
  69.827 +   break;
  69.828 + case 0x9f:
  69.829 +   // SBC A
  69.830 +   tempRegister.W=AF.B.B1-AF.B.B1-(AF.B.B0&C_FLAG ? 1 : 0);
  69.831 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.832 +     ((AF.B.B1^AF.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.833 +   AF.B.B1=tempRegister.B.B0;
  69.834 +   break;
  69.835 + case 0xa0:
  69.836 +   // AND B
  69.837 +   AF.B.B1&=BC.B.B1;
  69.838 +   AF.B.B0=H_FLAG|ZeroTable[AF.B.B1];
  69.839 +   break;
  69.840 + case 0xa1:
  69.841 +   // AND C
  69.842 +   AF.B.B1&=BC.B.B0;
  69.843 +   AF.B.B0=H_FLAG|ZeroTable[AF.B.B1];
  69.844 +   break;
  69.845 + case 0xa2:
  69.846 +   // AND_D
  69.847 +   AF.B.B1&=DE.B.B1;
  69.848 +   AF.B.B0=H_FLAG|ZeroTable[AF.B.B1];
  69.849 +   break;
  69.850 + case 0xa3:
  69.851 +   // AND E
  69.852 +   AF.B.B1&=DE.B.B0;
  69.853 +   AF.B.B0=H_FLAG|ZeroTable[AF.B.B1];
  69.854 +   break;
  69.855 + case 0xa4:
  69.856 +   // AND H
  69.857 +   AF.B.B1&=HL.B.B1;
  69.858 +   AF.B.B0=H_FLAG|ZeroTable[AF.B.B1];
  69.859 +   break;
  69.860 + case 0xa5:
  69.861 +   // AND L
  69.862 +   AF.B.B1&=HL.B.B0;
  69.863 +   AF.B.B0=H_FLAG|ZeroTable[AF.B.B1];
  69.864 +   break;
  69.865 + case 0xa6:
  69.866 +   // AND (HL)
  69.867 +   tempValue=gbReadMemory(HL.W);
  69.868 +   AF.B.B1&=tempValue;
  69.869 +   AF.B.B0=H_FLAG|ZeroTable[AF.B.B1];
  69.870 +   break;
  69.871 + case 0xa7:
  69.872 +   // AND A
  69.873 +   AF.B.B1&=AF.B.B1;
  69.874 +   AF.B.B0=H_FLAG|ZeroTable[AF.B.B1];
  69.875 +   break;
  69.876 + case 0xa8:
  69.877 +   // XOR B
  69.878 +   AF.B.B1^=BC.B.B1;
  69.879 +   AF.B.B0=ZeroTable[AF.B.B1];
  69.880 +   break;
  69.881 + case 0xa9:
  69.882 +   // XOR C
  69.883 +   AF.B.B1^=BC.B.B0;
  69.884 +   AF.B.B0=ZeroTable[AF.B.B1];
  69.885 +   break;
  69.886 + case 0xaa:
  69.887 +   // XOR D
  69.888 +   AF.B.B1^=DE.B.B1;
  69.889 +   AF.B.B0=ZeroTable[AF.B.B1];
  69.890 +   break;
  69.891 + case 0xab:
  69.892 +   // XOR E
  69.893 +   AF.B.B1^=DE.B.B0;
  69.894 +   AF.B.B0=ZeroTable[AF.B.B1];
  69.895 +   break;
  69.896 + case 0xac:
  69.897 +   // XOR H
  69.898 +   AF.B.B1^=HL.B.B1;
  69.899 +   AF.B.B0=ZeroTable[AF.B.B1];
  69.900 +   break;
  69.901 + case 0xad:
  69.902 +   // XOR L
  69.903 +   AF.B.B1^=HL.B.B0;
  69.904 +   AF.B.B0=ZeroTable[AF.B.B1];
  69.905 +   break;
  69.906 + case 0xae:
  69.907 +   // XOR (HL)
  69.908 +   tempValue=gbReadMemory(HL.W);
  69.909 +   AF.B.B1^=tempValue;
  69.910 +   AF.B.B0=ZeroTable[AF.B.B1];
  69.911 +   break;
  69.912 + case 0xaf:
  69.913 +   // XOR A
  69.914 +   AF.B.B1=0;
  69.915 +   AF.B.B0=Z_FLAG;
  69.916 +   break;
  69.917 + case 0xb0:
  69.918 +   // OR B
  69.919 +   AF.B.B1|=BC.B.B1;
  69.920 +   AF.B.B0=ZeroTable[AF.B.B1];
  69.921 +   break;
  69.922 + case 0xb1:
  69.923 +   // OR C
  69.924 +   AF.B.B1|=BC.B.B0;
  69.925 +   AF.B.B0=ZeroTable[AF.B.B1];
  69.926 +   break;
  69.927 + case 0xb2:
  69.928 +   // OR D
  69.929 +   AF.B.B1|=DE.B.B1;
  69.930 +   AF.B.B0=ZeroTable[AF.B.B1];
  69.931 +   break;
  69.932 + case 0xb3:
  69.933 +   // OR E
  69.934 +   AF.B.B1|=DE.B.B0;
  69.935 +   AF.B.B0=ZeroTable[AF.B.B1];
  69.936 +   break;
  69.937 + case 0xb4:
  69.938 +   // OR H
  69.939 +   AF.B.B1|=HL.B.B1;
  69.940 +   AF.B.B0=ZeroTable[AF.B.B1];
  69.941 +   break;
  69.942 + case 0xb5:
  69.943 +   // OR L
  69.944 +   AF.B.B1|=HL.B.B0;
  69.945 +   AF.B.B0=ZeroTable[AF.B.B1];
  69.946 +   break;
  69.947 + case 0xb6:
  69.948 +   // OR (HL)
  69.949 +   tempValue=gbReadMemory(HL.W);
  69.950 +   AF.B.B1|=tempValue;
  69.951 +   AF.B.B0=ZeroTable[AF.B.B1];
  69.952 +   break;
  69.953 + case 0xb7:
  69.954 +   // OR A
  69.955 +   AF.B.B1|=AF.B.B1;
  69.956 +   AF.B.B0=ZeroTable[AF.B.B1];
  69.957 +   break;
  69.958 + case 0xb8:
  69.959 +   // CP B:
  69.960 +   tempRegister.W=AF.B.B1-BC.B.B1;
  69.961 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.962 +     ((AF.B.B1^BC.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.963 +   break;
  69.964 + case 0xb9:
  69.965 +   // CP C
  69.966 +   tempRegister.W=AF.B.B1-BC.B.B0;
  69.967 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.968 +     ((AF.B.B1^BC.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.969 +   break;
  69.970 + case 0xba:
  69.971 +   // CP D
  69.972 +   tempRegister.W=AF.B.B1-DE.B.B1;
  69.973 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.974 +     ((AF.B.B1^DE.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.975 +   break;
  69.976 + case 0xbb:
  69.977 +   // CP E
  69.978 +   tempRegister.W=AF.B.B1-DE.B.B0;
  69.979 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.980 +     ((AF.B.B1^DE.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.981 +   break;
  69.982 + case 0xbc:
  69.983 +   // CP H
  69.984 +   tempRegister.W=AF.B.B1-HL.B.B1;
  69.985 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.986 +     ((AF.B.B1^HL.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.987 +   break;
  69.988 + case 0xbd:
  69.989 +   // CP L
  69.990 +   tempRegister.W=AF.B.B1-HL.B.B0;
  69.991 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.992 +     ((AF.B.B1^HL.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0);
  69.993 +   break;
  69.994 + case 0xbe:
  69.995 +   // CP (HL)
  69.996 +   tempValue=gbReadMemory(HL.W);
  69.997 +   tempRegister.W=AF.B.B1-tempValue;
  69.998 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
  69.999 +     ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0);
 69.1000 +   break;
 69.1001 + case 0xbf:
 69.1002 +   // CP A
 69.1003 +   AF.B.B0=N_FLAG|Z_FLAG;
 69.1004 +   break;
 69.1005 + case 0xc0:
 69.1006 +   // RET NZ
 69.1007 +   if(!(AF.B.B0&Z_FLAG)) {
 69.1008 +     PC.B.B0=gbReadMemory(SP.W++);
 69.1009 +     PC.B.B1=gbReadMemory(SP.W++);
 69.1010 +     clockTicks += 3;
 69.1011 +   }
 69.1012 +   break;
 69.1013 + case 0xc1:
 69.1014 +   // POP BC
 69.1015 +   BC.B.B0=gbReadMemory(SP.W++);
 69.1016 +   BC.B.B1=gbReadMemory(SP.W++);
 69.1017 +   break;
 69.1018 + case 0xc2:
 69.1019 +   // JP NZ,NNNN
 69.1020 +   if(AF.B.B0&Z_FLAG)
 69.1021 +     PC.W+=2;
 69.1022 +   else {
 69.1023 +     tempRegister.B.B0=gbReadMemory(PC.W++);
 69.1024 +     tempRegister.B.B1=gbReadMemory(PC.W);
 69.1025 +     PC.W=tempRegister.W;
 69.1026 +     clockTicks++;
 69.1027 +   }
 69.1028 +   break;
 69.1029 + case 0xc3:
 69.1030 +   // JP NNNN
 69.1031 +   tempRegister.B.B0=gbReadMemory(PC.W++);
 69.1032 +   tempRegister.B.B1=gbReadMemory(PC.W);
 69.1033 +   PC.W=tempRegister.W;
 69.1034 +   break;
 69.1035 + case 0xc4:
 69.1036 +   // CALL NZ,NNNN
 69.1037 +   if(AF.B.B0&Z_FLAG)
 69.1038 +     PC.W+=2;
 69.1039 +   else {
 69.1040 +     tempRegister.B.B0=gbReadMemory(PC.W++);
 69.1041 +     tempRegister.B.B1=gbReadMemory(PC.W++);
 69.1042 +     gbWriteMemory(--SP.W,PC.B.B1);
 69.1043 +     gbWriteMemory(--SP.W,PC.B.B0);
 69.1044 +     PC.W=tempRegister.W;
 69.1045 +     clockTicks += 3;
 69.1046 +   }
 69.1047 +   break;
 69.1048 + case 0xc5:
 69.1049 +   // PUSH BC
 69.1050 +   gbWriteMemory(--SP.W,BC.B.B1);
 69.1051 +   gbWriteMemory(--SP.W,BC.B.B0);
 69.1052 +   break;
 69.1053 + case 0xc6:
 69.1054 +   // ADD NN
 69.1055 +   tempValue=gbReadOpcode(PC.W++);
 69.1056 +   tempRegister.W=AF.B.B1+tempValue;
 69.1057 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
 69.1058 +     ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10 ? H_FLAG:0);
 69.1059 +   AF.B.B1=tempRegister.B.B0;
 69.1060 +   break;
 69.1061 + case 0xc7:
 69.1062 +   // RST 00
 69.1063 +   gbWriteMemory(--SP.W,PC.B.B1);
 69.1064 +   gbWriteMemory(--SP.W,PC.B.B0);
 69.1065 +   PC.W=0x0000;
 69.1066 +   break;
 69.1067 + case 0xc8:
 69.1068 +   // RET Z
 69.1069 +   if(AF.B.B0&Z_FLAG) {
 69.1070 +     PC.B.B0=gbReadMemory(SP.W++);
 69.1071 +     PC.B.B1=gbReadMemory(SP.W++);
 69.1072 +     clockTicks += 3;
 69.1073 +   }
 69.1074 +   break;
 69.1075 + case 0xc9:
 69.1076 +   // RET
 69.1077 +   PC.B.B0=gbReadMemory(SP.W++);
 69.1078 +   PC.B.B1=gbReadMemory(SP.W++);
 69.1079 +   break;
 69.1080 + case 0xca:
 69.1081 +   // JP Z,NNNN
 69.1082 +   if(AF.B.B0&Z_FLAG) {
 69.1083 +     tempRegister.B.B0=gbReadMemory(PC.W++);
 69.1084 +     tempRegister.B.B1=gbReadMemory(PC.W);
 69.1085 +     PC.W=tempRegister.W;
 69.1086 +     clockTicks++;
 69.1087 +   } else
 69.1088 +     PC.W+=2;
 69.1089 +   break;
 69.1090 +   // CB done outside
 69.1091 + case 0xcc:
 69.1092 +   // CALL Z,NNNN
 69.1093 +   if(AF.B.B0&Z_FLAG) {
 69.1094 +     tempRegister.B.B0=gbReadMemory(PC.W++);
 69.1095 +     tempRegister.B.B1=gbReadMemory(PC.W++);
 69.1096 +     gbWriteMemory(--SP.W,PC.B.B1);
 69.1097 +     gbWriteMemory(--SP.W,PC.B.B0);
 69.1098 +     PC.W=tempRegister.W;
 69.1099 +     clockTicks += 3;
 69.1100 +   } else
 69.1101 +     PC.W+=2;
 69.1102 +   break;
 69.1103 + case 0xcd:
 69.1104 +   // CALL NNNN
 69.1105 +   tempRegister.B.B0=gbReadMemory(PC.W++);
 69.1106 +   tempRegister.B.B1=gbReadMemory(PC.W++);
 69.1107 +   gbWriteMemory(--SP.W,PC.B.B1);
 69.1108 +   gbWriteMemory(--SP.W,PC.B.B0);
 69.1109 +   PC.W=tempRegister.W;
 69.1110 +   break;
 69.1111 + case 0xce:
 69.1112 +   // ADC NN
 69.1113 +   tempValue=gbReadOpcode(PC.W++);
 69.1114 +   tempRegister.W=AF.B.B1+tempValue+(AF.B.B0&C_FLAG ? 1 : 0);
 69.1115 +   AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
 69.1116 +     ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0);
 69.1117 +   AF.B.B1=tempRegister.B.B0;
 69.1118 +   break;
 69.1119 + case 0xcf:
 69.1120 +   // RST 08
 69.1121 +   gbWriteMemory(--SP.W,PC.B.B1);
 69.1122 +   gbWriteMemory(--SP.W,PC.B.B0);
 69.1123 +   PC.W=0x0008;
 69.1124 +   break;
 69.1125 + case 0xd0:
 69.1126 +   // RET NC
 69.1127 +   if(!(AF.B.B0&C_FLAG)) {
 69.1128 +     PC.B.B0=gbReadMemory(SP.W++);
 69.1129 +     PC.B.B1=gbReadMemory(SP.W++);
 69.1130 +     clockTicks += 3;
 69.1131 +   }
 69.1132 +   break;
 69.1133 + case 0xd1:
 69.1134 +   // POP DE
 69.1135 +   DE.B.B0=gbReadMemory(SP.W++);
 69.1136 +   DE.B.B1=gbReadMemory(SP.W++);
 69.1137 +   break;
 69.1138 + case 0xd2:
 69.1139 +   // JP NC,NNNN
 69.1140 +   if(AF.B.B0&C_FLAG)
 69.1141 +     PC.W+=2;
 69.1142 +   else {
 69.1143 +     tempRegister.B.B0=gbReadMemory(PC.W++);
 69.1144 +     tempRegister.B.B1=gbReadMemory(PC.W);
 69.1145 +     PC.W=tempRegister.W;
 69.1146 +     clockTicks++;
 69.1147 +   }
 69.1148 +   break;
 69.1149 +   // D3 illegal
 69.1150 + case 0xd4:
 69.1151 +   // CALL NC,NNNN
 69.1152 +   if(AF.B.B0&C_FLAG)
 69.1153 +     PC.W+=2;
 69.1154 +   else {
 69.1155 +     tempRegister.B.B0=gbReadMemory(PC.W++);
 69.1156 +     tempRegister.B.B1=gbReadMemory(PC.W++);
 69.1157 +     gbWriteMemory(--SP.W,PC.B.B1);
 69.1158 +     gbWriteMemory(--SP.W,PC.B.B0);
 69.1159 +     PC.W=tempRegister.W;
 69.1160 +     clockTicks += 3;
 69.1161 +   }
 69.1162 +   break;
 69.1163 + case 0xd5:
 69.1164 +   // PUSH DE
 69.1165 +   gbWriteMemory(--SP.W,DE.B.B1);
 69.1166 +   gbWriteMemory(--SP.W,DE.B.B0);
 69.1167 +   break;
 69.1168 + case 0xd6:
 69.1169 +   // SUB NN
 69.1170 +   tempValue=gbReadOpcode(PC.W++);
 69.1171 +   tempRegister.W=AF.B.B1-tempValue;
 69.1172 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
 69.1173 +     ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0);
 69.1174 +   AF.B.B1=tempRegister.B.B0;
 69.1175 +   break;
 69.1176 + case 0xd7:
 69.1177 +   // RST 10
 69.1178 +   gbWriteMemory(--SP.W,PC.B.B1);
 69.1179 +   gbWriteMemory(--SP.W,PC.B.B0);
 69.1180 +   PC.W=0x0010;
 69.1181 +   break;
 69.1182 + case 0xd8:
 69.1183 +   // RET C
 69.1184 +   if(AF.B.B0&C_FLAG) {
 69.1185 +     PC.B.B0=gbReadMemory(SP.W++);
 69.1186 +     PC.B.B1=gbReadMemory(SP.W++);
 69.1187 +     clockTicks += 4;
 69.1188 +   }
 69.1189 +   break;
 69.1190 + case 0xd9:
 69.1191 +   // RETI
 69.1192 +   PC.B.B0=gbReadMemory(SP.W++);
 69.1193 +   PC.B.B1=gbReadMemory(SP.W++);
 69.1194 +   IFF |= 0x01;
 69.1195 +   break;
 69.1196 + case 0xda:
 69.1197 +   // JP C,NNNN
 69.1198 +   if(AF.B.B0&C_FLAG) {
 69.1199 +     tempRegister.B.B0=gbReadMemory(PC.W++);
 69.1200 +     tempRegister.B.B1=gbReadMemory(PC.W);
 69.1201 +     PC.W=tempRegister.W;
 69.1202 +     clockTicks++;
 69.1203 +   } else
 69.1204 +     PC.W+=2;
 69.1205 +   break;
 69.1206 +   // DB illegal
 69.1207 + case 0xdc:
 69.1208 +   // CALL C,NNNN
 69.1209 +   if(AF.B.B0&C_FLAG) {
 69.1210 +     tempRegister.B.B0=gbReadMemory(PC.W++);
 69.1211 +     tempRegister.B.B1=gbReadMemory(PC.W++);
 69.1212 +     gbWriteMemory(--SP.W,PC.B.B1);
 69.1213 +     gbWriteMemory(--SP.W,PC.B.B0);
 69.1214 +     PC.W=tempRegister.W;
 69.1215 +     clockTicks += 3;
 69.1216 +   } else
 69.1217 +     PC.W+=2;
 69.1218 +   break;
 69.1219 +   // DD illegal
 69.1220 + case 0xde:
 69.1221 +   // SBC NN
 69.1222 +   tempValue=gbReadOpcode(PC.W++);
 69.1223 +   tempRegister.W=AF.B.B1-tempValue-(AF.B.B0&C_FLAG ? 1 : 0);
 69.1224 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
 69.1225 +     ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0);
 69.1226 +   AF.B.B1=tempRegister.B.B0;
 69.1227 +   break;
 69.1228 + case 0xdf:
 69.1229 +   // RST 18
 69.1230 +   gbWriteMemory(--SP.W,PC.B.B1);
 69.1231 +   gbWriteMemory(--SP.W,PC.B.B0);
 69.1232 +   PC.W=0x0018;
 69.1233 +   break;
 69.1234 + case 0xe0:
 69.1235 +   // LD (FF00+NN),A
 69.1236 +   gbWriteMemory(0xff00 + gbReadOpcode(PC.W++),AF.B.B1);
 69.1237 +   break;
 69.1238 + case 0xe1:
 69.1239 +   // POP HL
 69.1240 +   HL.B.B0=gbReadMemory(SP.W++);
 69.1241 +   HL.B.B1=gbReadMemory(SP.W++);
 69.1242 +   break;
 69.1243 + case 0xe2:
 69.1244 +   // LD (FF00+C),A
 69.1245 +   gbWriteMemory(0xff00 + BC.B.B0,AF.B.B1);
 69.1246 +   break;
 69.1247 +   // E3 illegal
 69.1248 +   // E4 illegal
 69.1249 + case 0xe5:
 69.1250 +   // PUSH HL
 69.1251 +   gbWriteMemory(--SP.W,HL.B.B1);
 69.1252 +   gbWriteMemory(--SP.W,HL.B.B0);
 69.1253 +   break;
 69.1254 + case 0xe6:
 69.1255 +   // AND NN
 69.1256 +   tempValue=gbReadOpcode(PC.W++);
 69.1257 +   AF.B.B1&=tempValue;
 69.1258 +   AF.B.B0=H_FLAG|ZeroTable[AF.B.B1];
 69.1259 +   break;
 69.1260 + case 0xe7:
 69.1261 +   // RST 20
 69.1262 +   gbWriteMemory(--SP.W,PC.B.B1);
 69.1263 +   gbWriteMemory(--SP.W,PC.B.B0);
 69.1264 +   PC.W=0x0020;
 69.1265 +   break;
 69.1266 + case 0xe8:
 69.1267 +   // ADD SP,NN
 69.1268 +   offset = (s8)gbReadOpcode(PC.W++);
 69.1269 +   
 69.1270 +   if(offset >= 0) {
 69.1271 +     tempRegister.W = SP.W + offset;
 69.1272 +     AF.B.B0 = (SP.W > tempRegister.W ? C_FLAG : 0) |
 69.1273 +       ((SP.W^offset^tempRegister.W)&0x1000? H_FLAG:0);
 69.1274 +     SP.W = tempRegister.W;
 69.1275 +   } else {
 69.1276 +     tempRegister.W = SP.W + offset;
 69.1277 +     AF.B.B0 = (SP.W < tempRegister.W ? C_FLAG : 0) |
 69.1278 +       ((SP.W^offset^tempRegister.W)&0x1000?H_FLAG:0);
 69.1279 +     SP.W = tempRegister.W;
 69.1280 +   }
 69.1281 +   break;
 69.1282 + case 0xe9:
 69.1283 +   // LD PC,HL
 69.1284 +   PC.W=HL.W;
 69.1285 +   break;
 69.1286 + case 0xea:
 69.1287 +   // LD (NNNN),A
 69.1288 +   tempRegister.B.B0=gbReadOpcode(PC.W++);
 69.1289 +   tempRegister.B.B1=gbReadOpcode(PC.W++);
 69.1290 +   gbWriteMemory(tempRegister.W,AF.B.B1);
 69.1291 +   break;
 69.1292 +   // EB illegal
 69.1293 +   // EC illegal
 69.1294 +   // ED illegal
 69.1295 + case 0xee:
 69.1296 +   // XOR NN
 69.1297 +   tempValue=gbReadOpcode(PC.W++);
 69.1298 +   AF.B.B1^=tempValue;
 69.1299 +   AF.B.B0=ZeroTable[AF.B.B1];
 69.1300 +   break;
 69.1301 + case 0xef:
 69.1302 +   // RST 28
 69.1303 +   gbWriteMemory(--SP.W,PC.B.B1);
 69.1304 +   gbWriteMemory(--SP.W,PC.B.B0);
 69.1305 +   PC.W=0x0028;
 69.1306 +   break;
 69.1307 + case 0xf0:
 69.1308 +   // LD A,(FF00+NN)
 69.1309 +   AF.B.B1 = gbReadMemory(0xff00+gbReadOpcode(PC.W++));
 69.1310 +   break;
 69.1311 + case 0xf1:
 69.1312 +   // POP AF
 69.1313 +   AF.B.B0=gbReadMemory(SP.W++);
 69.1314 +   AF.B.B1=gbReadMemory(SP.W++);
 69.1315 +   break;
 69.1316 + case 0xf2:
 69.1317 +   // LD A,(FF00+C)
 69.1318 +   AF.B.B1 = gbReadMemory(0xff00+BC.B.B0);
 69.1319 +   break;
 69.1320 + case 0xf3:
 69.1321 +   // DI
 69.1322 + //   IFF&=0xFE;
 69.1323 +   IFF&=(~0x21);
 69.1324 +   break;
 69.1325 +   // F4 illegal
 69.1326 + case 0xf5:
 69.1327 +   // PUSH AF
 69.1328 +   gbWriteMemory(--SP.W,AF.B.B1);
 69.1329 +   gbWriteMemory(--SP.W,AF.B.B0);
 69.1330 +   break;
 69.1331 + case 0xf6:
 69.1332 +   // OR NN
 69.1333 +   tempValue=gbReadOpcode(PC.W++);
 69.1334 +   AF.B.B1|=tempValue;
 69.1335 +   AF.B.B0=ZeroTable[AF.B.B1];
 69.1336 +   break;
 69.1337 + case 0xf7:
 69.1338 +   // RST 30
 69.1339 +   gbWriteMemory(--SP.W,PC.B.B1);
 69.1340 +   gbWriteMemory(--SP.W,PC.B.B0);
 69.1341 +   PC.W=0x0030;
 69.1342 +   break;
 69.1343 + case 0xf8:
 69.1344 +   // LD HL,SP+NN
 69.1345 +   offset = (s8)gbReadOpcode(PC.W++);
 69.1346 +   if(offset >= 0) {
 69.1347 +     tempRegister.W = SP.W + offset;
 69.1348 +     AF.B.B0 = (SP.W > tempRegister.W ? C_FLAG : 0) |
 69.1349 +       ((SP.W^offset^tempRegister.W)&0x1000? H_FLAG:0);
 69.1350 +     HL.W = tempRegister.W;
 69.1351 +   } else {
 69.1352 +     tempRegister.W = SP.W + offset;
 69.1353 +     AF.B.B0 = (SP.W < tempRegister.W ? C_FLAG : 0) |
 69.1354 +       ((SP.W^offset^tempRegister.W)&0x1000?H_FLAG:0);
 69.1355 +     HL.W = tempRegister.W;
 69.1356 +   }
 69.1357 +   break;
 69.1358 + case 0xf9:
 69.1359 +   // LD SP,HL
 69.1360 +   SP.W=HL.W;
 69.1361 +   break;
 69.1362 + case 0xfa:
 69.1363 +   // LD A,(NNNN)
 69.1364 +   tempRegister.B.B0=gbReadOpcode(PC.W++);
 69.1365 +   tempRegister.B.B1=gbReadOpcode(PC.W++);
 69.1366 +   AF.B.B1=gbReadMemory(tempRegister.W);
 69.1367 +   break;
 69.1368 + case 0xfb:
 69.1369 +   // EI
 69.1370 +   IFF|=0x20;
 69.1371 +   break;
 69.1372 +   // FC illegal
 69.1373 +   // FD illegal
 69.1374 + case 0xfe:
 69.1375 +   // CP NN
 69.1376 +   tempValue=gbReadOpcode(PC.W++);
 69.1377 +   tempRegister.W=AF.B.B1-tempValue;
 69.1378 +   AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]|
 69.1379 +     ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0);
 69.1380 +   break;
 69.1381 + case 0xff:
 69.1382 +   // RST 38
 69.1383 +   gbWriteMemory(--SP.W,PC.B.B1);
 69.1384 +   gbWriteMemory(--SP.W,PC.B.B0);
 69.1385 +   PC.W=0x0038;
 69.1386 +   break;
 69.1387 + default:
 69.1388 +   systemMessage(0, N_("Unknown opcode %02x at %04x"),
 69.1389 +                 gbReadOpcode(PC.W-1),PC.W-1);
 69.1390 +   emulating = false;
 69.1391 +   return;
    70.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    70.2 +++ b/src/gb/gbCodesCB.h	Sat Mar 03 10:31:27 2012 -0600
    70.3 @@ -0,0 +1,1269 @@
    70.4 + case 0x00:
    70.5 +   // RLC B
    70.6 +   AF.B.B0 = (BC.B.B1 & 0x80)?C_FLAG:0;
    70.7 +   BC.B.B1 = ((BC.B.B1<<1) | (BC.B.B1>>7)) & 0xFF;
    70.8 +   AF.B.B0 |= ZeroTable[BC.B.B1];
    70.9 +   break;
   70.10 + case 0x01:
   70.11 +   // RLC C
   70.12 +   AF.B.B0 = (BC.B.B0 & 0x80)?C_FLAG:0;
   70.13 +   BC.B.B0 = ((BC.B.B0<<1) | (BC.B.B0>>7)) & 0xFF;
   70.14 +   AF.B.B0 |= ZeroTable[BC.B.B0];
   70.15 +   break;
   70.16 + case 0x02:
   70.17 +   // RLC D
   70.18 +   AF.B.B0 = (DE.B.B1 & 0x80)?C_FLAG:0;
   70.19 +   DE.B.B1 = ((DE.B.B1<<1) | (DE.B.B1>>7)) & 0xFF;
   70.20 +   AF.B.B0 |= ZeroTable[DE.B.B1];
   70.21 +   break;
   70.22 + case 0x03:
   70.23 +   // RLC E
   70.24 +   AF.B.B0 = (DE.B.B0 & 0x80)?C_FLAG:0;
   70.25 +   DE.B.B0 = ((DE.B.B0<<1) | (DE.B.B0>>7)) & 0xFF;
   70.26 +   AF.B.B0 |= ZeroTable[DE.B.B0];
   70.27 +   break;
   70.28 + case 0x04:
   70.29 +   // RLC H
   70.30 +   AF.B.B0 = (HL.B.B1 & 0x80)?C_FLAG:0;
   70.31 +   HL.B.B1 = ((HL.B.B1<<1) | (HL.B.B1>>7)) & 0xFF;
   70.32 +   AF.B.B0 |= ZeroTable[HL.B.B1];
   70.33 +   break;
   70.34 + case 0x05:
   70.35 +   // RLC L
   70.36 +   AF.B.B0 = (HL.B.B0 & 0x80)?C_FLAG:0;
   70.37 +   HL.B.B0 = ((HL.B.B0<<1) | (HL.B.B0>>7)) & 0xFF;
   70.38 +   AF.B.B0 |= ZeroTable[HL.B.B0];
   70.39 +   break;
   70.40 + case 0x06:
   70.41 +   // RLC (HL)
   70.42 +   tempValue=gbReadMemory(HL.W);
   70.43 +   AF.B.B0 = (tempValue & 0x80)?C_FLAG:0;
   70.44 +   tempValue = ((tempValue<<1) | (tempValue>>7)) & 0xFF;
   70.45 +   AF.B.B0 |= ZeroTable[tempValue];
   70.46 +   gbWriteMemory(HL.W,tempValue);
   70.47 +   break;
   70.48 + case 0x07:
   70.49 +   // RLC A
   70.50 +   AF.B.B0 = (AF.B.B1 & 0x80)?C_FLAG:0;
   70.51 +   AF.B.B1 = ((AF.B.B1<<1) | (AF.B.B1>>7)) & 0xFF;
   70.52 +   AF.B.B0 |= ZeroTable[AF.B.B1];
   70.53 +   break;
   70.54 + case 0x08:
   70.55 +   // RRC B
   70.56 +   AF.B.B0=(BC.B.B1&0x01 ? C_FLAG : 0);
   70.57 +   BC.B.B1=((BC.B.B1>>1)|(BC.B.B1<<7)) & 0xFF;
   70.58 +   AF.B.B0|=ZeroTable[BC.B.B1];
   70.59 +   break;
   70.60 + case 0x09:
   70.61 +   // RRC C
   70.62 +   AF.B.B0=(BC.B.B0&0x01 ? C_FLAG : 0);
   70.63 +   BC.B.B0=((BC.B.B0>>1)|(BC.B.B0<<7)) & 0xFF;
   70.64 +   AF.B.B0|=ZeroTable[BC.B.B0];
   70.65 +   break;
   70.66 + case 0x0a:
   70.67 +   // RRC D
   70.68 +   AF.B.B0=(DE.B.B1&0x01 ? C_FLAG : 0);
   70.69 +   DE.B.B1=((DE.B.B1>>1)|(DE.B.B1<<7)) & 0xFF;
   70.70 +   AF.B.B0|=ZeroTable[DE.B.B1];
   70.71 +   break;
   70.72 + case 0x0b:
   70.73 +   // RRC E
   70.74 +   AF.B.B0=(DE.B.B0&0x01 ? C_FLAG : 0);
   70.75 +   DE.B.B0=((DE.B.B0>>1)|(DE.B.B0<<7)) & 0xFF;
   70.76 +   AF.B.B0|=ZeroTable[DE.B.B0];
   70.77 +   break;
   70.78 + case 0x0c:
   70.79 +   // RRC H
   70.80 +   AF.B.B0=(HL.B.B1&0x01 ? C_FLAG : 0);
   70.81 +   HL.B.B1=((HL.B.B1>>1)|(HL.B.B1<<7)) & 0xFF;
   70.82 +   AF.B.B0|=ZeroTable[HL.B.B1];
   70.83 +   break;
   70.84 + case 0x0d:
   70.85 +   // RRC L
   70.86 +   AF.B.B0=(HL.B.B0&0x01 ? C_FLAG : 0);
   70.87 +   HL.B.B0=((HL.B.B0>>1)|(HL.B.B0<<7)) & 0xFF;
   70.88 +   AF.B.B0|=ZeroTable[HL.B.B0];
   70.89 +   break;
   70.90 + case 0x0e:
   70.91 +   // RRC (HL)
   70.92 +   tempValue=gbReadMemory(HL.W);
   70.93 +   AF.B.B0=(tempValue&0x01 ? C_FLAG : 0);
   70.94 +   tempValue=((tempValue>>1)|(tempValue<<7)) & 0xFF;
   70.95 +   AF.B.B0|=ZeroTable[tempValue];
   70.96 +   gbWriteMemory(HL.W,tempValue);
   70.97 +   break;
   70.98 + case 0x0f:
   70.99 +   // RRC A
  70.100 +   AF.B.B0=(AF.B.B1&0x01 ? C_FLAG : 0);
  70.101 +   AF.B.B1=((AF.B.B1>>1)|(AF.B.B1<<7)) & 0xFF;
  70.102 +   AF.B.B0|=ZeroTable[AF.B.B1];
  70.103 +   break;
  70.104 + case 0x10:
  70.105 +   // RL B
  70.106 +   if(BC.B.B1&0x80) {
  70.107 +     BC.B.B1=((BC.B.B1<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.108 +     AF.B.B0=ZeroTable[BC.B.B1]|C_FLAG;
  70.109 +   } else {
  70.110 +     BC.B.B1=((BC.B.B1<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.111 +     AF.B.B0=ZeroTable[BC.B.B1];
  70.112 +   }
  70.113 +   break;
  70.114 + case 0x11:
  70.115 +   // RL C
  70.116 +   if(BC.B.B0&0x80) {
  70.117 +     BC.B.B0=((BC.B.B0<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.118 +     AF.B.B0=ZeroTable[BC.B.B0]|C_FLAG;
  70.119 +   } else {
  70.120 +     BC.B.B0=((BC.B.B0<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.121 +     AF.B.B0=ZeroTable[BC.B.B0];
  70.122 +   }
  70.123 +   break;
  70.124 + case 0x12:
  70.125 +   // RL D
  70.126 +   if(DE.B.B1&0x80) {
  70.127 +     DE.B.B1=((DE.B.B1<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.128 +     AF.B.B0=ZeroTable[DE.B.B1]|C_FLAG;
  70.129 +   } else {
  70.130 +     DE.B.B1=((DE.B.B1<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.131 +     AF.B.B0=ZeroTable[DE.B.B1];
  70.132 +   }
  70.133 +   break;
  70.134 + case 0x13:
  70.135 +   // RL E
  70.136 +   if(DE.B.B0&0x80) {
  70.137 +     DE.B.B0=((DE.B.B0<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.138 +     AF.B.B0=ZeroTable[DE.B.B0]|C_FLAG;
  70.139 +   } else {
  70.140 +     DE.B.B0=((DE.B.B0<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.141 +     AF.B.B0=ZeroTable[DE.B.B0];
  70.142 +   }
  70.143 +   break;
  70.144 + case 0x14:
  70.145 +   // RL H
  70.146 +   if(HL.B.B1&0x80) {
  70.147 +     HL.B.B1=((HL.B.B1<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.148 +     AF.B.B0=ZeroTable[HL.B.B1]|C_FLAG;
  70.149 +   } else {
  70.150 +     HL.B.B1=((HL.B.B1<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.151 +     AF.B.B0=ZeroTable[HL.B.B1];
  70.152 +   }
  70.153 +   break;
  70.154 + case 0x15:
  70.155 +   // RL L
  70.156 +   if(HL.B.B0&0x80) {
  70.157 +     HL.B.B0=((HL.B.B0<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.158 +     AF.B.B0=ZeroTable[HL.B.B0]|C_FLAG;
  70.159 +   } else {
  70.160 +     HL.B.B0=((HL.B.B0<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.161 +     AF.B.B0=ZeroTable[HL.B.B0];
  70.162 +   }
  70.163 +   break;
  70.164 + case 0x16:
  70.165 +   // RL (HL)
  70.166 +   tempValue=gbReadMemory(HL.W);
  70.167 +   if(tempValue&0x80) {
  70.168 +     tempValue=((tempValue<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.169 +     AF.B.B0=ZeroTable[tempValue]|C_FLAG;
  70.170 +   } else {
  70.171 +     tempValue=((tempValue<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.172 +     AF.B.B0=ZeroTable[tempValue];
  70.173 +   }
  70.174 +   gbWriteMemory(HL.W,tempValue);
  70.175 +   break;
  70.176 + case 0x17:
  70.177 +   // RL A
  70.178 +   if(AF.B.B1&0x80) {
  70.179 +     AF.B.B1=((AF.B.B1<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.180 +     AF.B.B0=ZeroTable[AF.B.B1]|C_FLAG;
  70.181 +   } else {
  70.182 +     AF.B.B1=((AF.B.B1<<1)|(AF.B.B0&C_FLAG ? 1 : 0)) & 0xFF;
  70.183 +     AF.B.B0=ZeroTable[AF.B.B1];
  70.184 +   }
  70.185 +   break;
  70.186 + case 0x18:
  70.187 +   // RR B
  70.188 +   if(BC.B.B1&0x01) {
  70.189 +     BC.B.B1=(BC.B.B1>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.190 +     AF.B.B0=ZeroTable[BC.B.B1]|C_FLAG;
  70.191 +   } else {
  70.192 +     BC.B.B1=(BC.B.B1>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.193 +     AF.B.B0=ZeroTable[BC.B.B1];
  70.194 +   }
  70.195 +   break;
  70.196 + case 0x19:
  70.197 +   // RR C
  70.198 +   if(BC.B.B0&0x01) {
  70.199 +     BC.B.B0=(BC.B.B0>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.200 +     AF.B.B0=ZeroTable[BC.B.B0]|C_FLAG;
  70.201 +   } else {
  70.202 +     BC.B.B0=(BC.B.B0>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.203 +     AF.B.B0=ZeroTable[BC.B.B0];
  70.204 +   }
  70.205 +   break;
  70.206 + case 0x1a:
  70.207 +   // RR D
  70.208 +   if(DE.B.B1&0x01) {
  70.209 +     DE.B.B1=(DE.B.B1>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.210 +     AF.B.B0=ZeroTable[DE.B.B1]|C_FLAG;
  70.211 +   } else {
  70.212 +     DE.B.B1=(DE.B.B1>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.213 +     AF.B.B0=ZeroTable[DE.B.B1];
  70.214 +   }
  70.215 +   break;
  70.216 + case 0x1b:
  70.217 +   // RR E
  70.218 +   if(DE.B.B0&0x01) {
  70.219 +     DE.B.B0=(DE.B.B0>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.220 +     AF.B.B0=ZeroTable[DE.B.B0]|C_FLAG;
  70.221 +   } else {
  70.222 +     DE.B.B0=(DE.B.B0>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.223 +     AF.B.B0=ZeroTable[DE.B.B0];
  70.224 +   }
  70.225 +   break;
  70.226 + case 0x1c:
  70.227 +   // RR H
  70.228 +   if(HL.B.B1&0x01) {
  70.229 +     HL.B.B1=(HL.B.B1>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.230 +     AF.B.B0=ZeroTable[HL.B.B1]|C_FLAG;
  70.231 +   } else {
  70.232 +     HL.B.B1=(HL.B.B1>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.233 +     AF.B.B0=ZeroTable[HL.B.B1];
  70.234 +   }
  70.235 +   break;
  70.236 + case 0x1d:
  70.237 +   // RR L
  70.238 +   if(HL.B.B0&0x01) {
  70.239 +     HL.B.B0=(HL.B.B0>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.240 +     AF.B.B0=ZeroTable[HL.B.B0]|C_FLAG;
  70.241 +   } else {
  70.242 +     HL.B.B0=(HL.B.B0>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.243 +     AF.B.B0=ZeroTable[HL.B.B0];
  70.244 +   }
  70.245 +   break;
  70.246 + case 0x1e:
  70.247 +   // RR (HL)
  70.248 +   tempValue=gbReadMemory(HL.W);
  70.249 +   if(tempValue&0x01) {
  70.250 +     tempValue=(tempValue>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.251 +     AF.B.B0=ZeroTable[tempValue]|C_FLAG;
  70.252 +   } else {
  70.253 +     tempValue=(tempValue>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.254 +     AF.B.B0=ZeroTable[tempValue];
  70.255 +   }
  70.256 +   gbWriteMemory(HL.W,tempValue);
  70.257 +   break;
  70.258 + case 0x1f:
  70.259 +   // RR A
  70.260 +   if(AF.B.B1&0x01) {
  70.261 +     AF.B.B1=(AF.B.B1>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.262 +     AF.B.B0=ZeroTable[AF.B.B1]|C_FLAG;
  70.263 +   } else {
  70.264 +     AF.B.B1=(AF.B.B1>>1)|(AF.B.B0 & C_FLAG ? 0x80:0);
  70.265 +     AF.B.B0=ZeroTable[AF.B.B1];
  70.266 +   }
  70.267 +   break;
  70.268 + case 0x20:
  70.269 +   // SLA B
  70.270 +   AF.B.B0=(BC.B.B1&0x80?C_FLAG : 0);
  70.271 +   BC.B.B1<<=1;
  70.272 +   AF.B.B0|=ZeroTable[BC.B.B1];
  70.273 +   break;
  70.274 + case 0x21:
  70.275 +   // SLA C
  70.276 +   AF.B.B0=(BC.B.B0&0x80?C_FLAG : 0);
  70.277 +   BC.B.B0<<=1;
  70.278 +   AF.B.B0|=ZeroTable[BC.B.B0];
  70.279 +   break;
  70.280 + case 0x22:
  70.281 +   // SLA D
  70.282 +   AF.B.B0=(DE.B.B1&0x80?C_FLAG : 0);
  70.283 +   DE.B.B1<<=1;
  70.284 +   AF.B.B0|=ZeroTable[DE.B.B1];
  70.285 +   break;
  70.286 + case 0x23:
  70.287 +   // SLA E
  70.288 +   AF.B.B0=(DE.B.B0&0x80?C_FLAG : 0);
  70.289 +   DE.B.B0<<=1;
  70.290 +   AF.B.B0|=ZeroTable[DE.B.B0];
  70.291 +   break;
  70.292 + case 0x24:
  70.293 +   // SLA H
  70.294 +   AF.B.B0=(HL.B.B1&0x80?C_FLAG : 0);
  70.295 +   HL.B.B1<<=1;
  70.296 +   AF.B.B0|=ZeroTable[HL.B.B1];
  70.297 +   break;
  70.298 + case 0x25:
  70.299 +   // SLA L
  70.300 +   AF.B.B0=(HL.B.B0&0x80?C_FLAG : 0);
  70.301 +   HL.B.B0<<=1;
  70.302 +   AF.B.B0|=ZeroTable[HL.B.B0];
  70.303 +   break;
  70.304 + case 0x26:
  70.305 +   // SLA (HL)
  70.306 +   tempValue=gbReadMemory(HL.W);
  70.307 +   AF.B.B0=(tempValue&0x80?C_FLAG : 0);
  70.308 +   tempValue<<=1;
  70.309 +   AF.B.B0|=ZeroTable[tempValue];
  70.310 +   gbWriteMemory(HL.W,tempValue);
  70.311 +   break;
  70.312 + case 0x27:
  70.313 +   // SLA A
  70.314 +   AF.B.B0=(AF.B.B1&0x80?C_FLAG : 0);
  70.315 +   AF.B.B1<<=1;
  70.316 +   AF.B.B0|=ZeroTable[AF.B.B1];
  70.317 +   break;
  70.318 + case 0x28:
  70.319 +   // SRA B
  70.320 +   AF.B.B0=(BC.B.B1&0x01 ? C_FLAG: 0);
  70.321 +   BC.B.B1=(BC.B.B1>>1)|(BC.B.B1&0x80);
  70.322 +   AF.B.B0|=ZeroTable[BC.B.B1];
  70.323 +   break;
  70.324 + case 0x29:
  70.325 +   // SRA C
  70.326 +   AF.B.B0=(BC.B.B0&0x01 ? C_FLAG: 0);
  70.327 +   BC.B.B0=(BC.B.B0>>1)|(BC.B.B0&0x80);
  70.328 +   AF.B.B0|=ZeroTable[BC.B.B0];
  70.329 +   break;
  70.330 + case 0x2a:
  70.331 +   // SRA D
  70.332 +   AF.B.B0=(DE.B.B1&0x01 ? C_FLAG: 0);
  70.333 +   DE.B.B1=(DE.B.B1>>1)|(DE.B.B1&0x80);
  70.334 +   AF.B.B0|=ZeroTable[DE.B.B1];
  70.335 +   break;
  70.336 + case 0x2b:
  70.337 +   // SRA E
  70.338 +   AF.B.B0=(DE.B.B0&0x01 ? C_FLAG: 0);
  70.339 +   DE.B.B0=(DE.B.B0>>1)|(DE.B.B0&0x80);
  70.340 +   AF.B.B0|=ZeroTable[DE.B.B0];
  70.341 +   break;
  70.342 + case 0x2c:
  70.343 +   // SRA H
  70.344 +   AF.B.B0=(HL.B.B1&0x01 ? C_FLAG: 0);
  70.345 +   HL.B.B1=(HL.B.B1>>1)|(HL.B.B1&0x80);
  70.346 +   AF.B.B0|=ZeroTable[HL.B.B1];
  70.347 +   break;
  70.348 + case 0x2d:
  70.349 +   // SRA L
  70.350 +   AF.B.B0=(HL.B.B0&0x01 ? C_FLAG: 0);
  70.351 +   HL.B.B0=(HL.B.B0>>1)|(HL.B.B0&0x80);
  70.352 +   AF.B.B0|=ZeroTable[HL.B.B0];
  70.353 +   break;
  70.354 + case 0x2e:
  70.355 +   // SRA (HL)
  70.356 +   tempValue=gbReadMemory(HL.W);
  70.357 +   AF.B.B0=(tempValue&0x01 ? C_FLAG: 0);
  70.358 +   tempValue=(tempValue>>1)|(tempValue&0x80);
  70.359 +   AF.B.B0|=ZeroTable[tempValue];
  70.360 +   gbWriteMemory(HL.W,tempValue);
  70.361 +   break;
  70.362 + case 0x2f:
  70.363 +   // SRA A
  70.364 +   AF.B.B0=(AF.B.B1&0x01 ? C_FLAG: 0);
  70.365 +   AF.B.B1=(AF.B.B1>>1)|(AF.B.B1&0x80);
  70.366 +   AF.B.B0|=ZeroTable[AF.B.B1];
  70.367 +   break;
  70.368 + case 0x30:
  70.369 +   // SWAP B
  70.370 +   BC.B.B1 = (BC.B.B1&0xf0)>>4 | (BC.B.B1&0x0f)<<4;
  70.371 +   AF.B.B0 = ZeroTable[BC.B.B1];
  70.372 +   break;
  70.373 + case 0x31:
  70.374 +   // SWAP C
  70.375 +   BC.B.B0 = (BC.B.B0&0xf0)>>4 | (BC.B.B0&0x0f)<<4;
  70.376 +   AF.B.B0 = ZeroTable[BC.B.B0];
  70.377 +   break;
  70.378 + case 0x32:
  70.379 +  // SWAP D
  70.380 +  DE.B.B1 = (DE.B.B1&0xf0)>>4 | (DE.B.B1&0x0f)<<4;
  70.381 +  AF.B.B0 = ZeroTable[DE.B.B1];
  70.382 +  break;
  70.383 + case 0x33:
  70.384 +   // SWAP E
  70.385 +   DE.B.B0 = (DE.B.B0&0xf0)>>4 | (DE.B.B0&0x0f)<<4;
  70.386 +   AF.B.B0 = ZeroTable[DE.B.B0];
  70.387 +   break;
  70.388 + case 0x34:
  70.389 +   // SWAP H
  70.390 +   HL.B.B1 = (HL.B.B1&0xf0)>>4 | (HL.B.B1&0x0f)<<4;
  70.391 +   AF.B.B0 = ZeroTable[HL.B.B1];
  70.392 +   break;
  70.393 + case 0x35:
  70.394 +   // SWAP L
  70.395 +   HL.B.B0 = (HL.B.B0&0xf0)>>4 | (HL.B.B0&0x0f)<<4;
  70.396 +   AF.B.B0 = ZeroTable[HL.B.B0];
  70.397 +   break;
  70.398 + case 0x36:
  70.399 +   // SWAP (HL)
  70.400 +   tempValue=gbReadMemory(HL.W);
  70.401 +   tempValue = (tempValue&0xf0)>>4 | (tempValue&0x0f)<<4;
  70.402 +   AF.B.B0 = ZeroTable[tempValue];
  70.403 +   gbWriteMemory(HL.W,tempValue);
  70.404 +   break;
  70.405 + case 0x37:
  70.406 +   // SWAP A
  70.407 +   AF.B.B1 = (AF.B.B1&0xf0)>>4 | (AF.B.B1&0x0f)<<4;
  70.408 +   AF.B.B0 = ZeroTable[AF.B.B1];
  70.409 +   break;
  70.410 + case 0x38:
  70.411 +   // SRL B
  70.412 +   AF.B.B0=(BC.B.B1&0x01)?C_FLAG:0;
  70.413 +   BC.B.B1>>=1;
  70.414 +   AF.B.B0|=ZeroTable[BC.B.B1];
  70.415 +   break;
  70.416 + case 0x39:
  70.417 +   // SRL C
  70.418 +   AF.B.B0=(BC.B.B0&0x01)?C_FLAG:0;
  70.419 +   BC.B.B0>>=1;
  70.420 +   AF.B.B0|=ZeroTable[BC.B.B0];
  70.421 +   break;
  70.422 + case 0x3a:
  70.423 +   // SRL D
  70.424 +   AF.B.B0=(DE.B.B1&0x01)?C_FLAG:0;
  70.425 +   DE.B.B1>>=1;
  70.426 +   AF.B.B0|=ZeroTable[DE.B.B1];
  70.427 +   break;
  70.428 + case 0x3b:
  70.429 +   // SRL E
  70.430 +   AF.B.B0=(DE.B.B0&0x01)?C_FLAG:0;
  70.431 +   DE.B.B0>>=1;
  70.432 +   AF.B.B0|=ZeroTable[DE.B.B0];
  70.433 +   break;
  70.434 + case 0x3c:
  70.435 +   // SRL H
  70.436 +   AF.B.B0=(HL.B.B1&0x01)?C_FLAG:0;
  70.437 +   HL.B.B1>>=1;
  70.438 +   AF.B.B0|=ZeroTable[HL.B.B1];
  70.439 +   break;
  70.440 + case 0x3d:
  70.441 +   // SRL L
  70.442 +   AF.B.B0=(HL.B.B0&0x01)?C_FLAG:0;
  70.443 +   HL.B.B0>>=1;
  70.444 +   AF.B.B0|=ZeroTable[HL.B.B0];
  70.445 +   break;
  70.446 + case 0x3e:
  70.447 +   // SRL (HL)
  70.448 +   tempValue=gbReadMemory(HL.W);
  70.449 +   AF.B.B0=(tempValue&0x01)?C_FLAG:0;
  70.450 +   tempValue>>=1;
  70.451 +   AF.B.B0|=ZeroTable[tempValue];
  70.452 +   gbWriteMemory(HL.W,tempValue);
  70.453 +   break;
  70.454 + case 0x3f:
  70.455 +   // SRL A
  70.456 +   AF.B.B0=(AF.B.B1&0x01)?C_FLAG:0;
  70.457 +   AF.B.B1>>=1;
  70.458 +   AF.B.B0|=ZeroTable[AF.B.B1];
  70.459 +   break;
  70.460 + case 0x40:
  70.461 +   // BIT 0,B
  70.462 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B1&(1<<0)? 0:Z_FLAG);
  70.463 +   break;
  70.464 + case 0x41:
  70.465 +   // BIT 0,C
  70.466 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B0&(1<<0)? 0:Z_FLAG);
  70.467 +   break;
  70.468 + case 0x42:
  70.469 +   // BIT 0,D
  70.470 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B1&(1<<0)? 0:Z_FLAG);
  70.471 +   break;
  70.472 + case 0x43:
  70.473 +   // BIT 0,E
  70.474 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B0&(1<<0)? 0:Z_FLAG);
  70.475 +   break;
  70.476 + case 0x44:
  70.477 +   // BIT 0,H
  70.478 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B1&(1<<0)? 0:Z_FLAG);
  70.479 +   break;
  70.480 + case 0x45:
  70.481 +   // BIT 0,L
  70.482 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B0&(1<<0)? 0:Z_FLAG);
  70.483 +   break;
  70.484 + case 0x46:
  70.485 +   // BIT 0,(HL)
  70.486 +   tempValue=gbReadMemory(HL.W);
  70.487 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(tempValue&(1<<0)? 0:Z_FLAG);
  70.488 +   break;
  70.489 + case 0x47:
  70.490 +   // BIT 0,A
  70.491 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(AF.B.B1&(1<<0)? 0:Z_FLAG);
  70.492 +   break;
  70.493 + case 0x48:
  70.494 +   // BIT 1,B
  70.495 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B1&(1<<1)? 0:Z_FLAG);
  70.496 +   break;
  70.497 + case 0x49:
  70.498 +   // BIT 1,C
  70.499 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B0&(1<<1)? 0:Z_FLAG);
  70.500 +   break;
  70.501 + case 0x4a:
  70.502 +   // BIT 1,D
  70.503 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B1&(1<<1)? 0:Z_FLAG);
  70.504 +   break;
  70.505 + case 0x4b:
  70.506 +   // BIT 1,E
  70.507 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B0&(1<<1)? 0:Z_FLAG);
  70.508 +   break;
  70.509 + case 0x4c:
  70.510 +   // BIT 1,H
  70.511 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B1&(1<<1)? 0:Z_FLAG);
  70.512 +   break;
  70.513 + case 0x4d:
  70.514 +   // BIT 1,L
  70.515 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B0&(1<<1)? 0:Z_FLAG);
  70.516 +   break;
  70.517 + case 0x4e:
  70.518 +   // BIT 1,(HL)
  70.519 +   tempValue=gbReadMemory(HL.W);
  70.520 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(tempValue&(1<<1)? 0:Z_FLAG);
  70.521 +   break;
  70.522 + case 0x4f:
  70.523 +   // BIT 1,A
  70.524 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(AF.B.B1&(1<<1)? 0:Z_FLAG);
  70.525 +   break;
  70.526 + case 0x50:
  70.527 +   // BIT 2,B
  70.528 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B1&(1<<2)? 0:Z_FLAG);
  70.529 +   break;
  70.530 + case 0x51:
  70.531 +   // BIT 2,C
  70.532 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B0&(1<<2)? 0:Z_FLAG);
  70.533 +   break;
  70.534 + case 0x52:
  70.535 +   // BIT 2,D
  70.536 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B1&(1<<2)? 0:Z_FLAG);
  70.537 +   break;
  70.538 + case 0x53:
  70.539 +   // BIT 2,E
  70.540 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B0&(1<<2)? 0:Z_FLAG);
  70.541 +   break;
  70.542 + case 0x54:
  70.543 +   // BIT 2,H
  70.544 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B1&(1<<2)? 0:Z_FLAG);
  70.545 +   break;
  70.546 + case 0x55:
  70.547 +   // BIT 2,L
  70.548 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B0&(1<<2)? 0:Z_FLAG);
  70.549 +   break;
  70.550 + case 0x56:
  70.551 +   // BIT 2,(HL)
  70.552 +   tempValue=gbReadMemory(HL.W);
  70.553 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(tempValue&(1<<2)? 0:Z_FLAG);
  70.554 +   break;
  70.555 + case 0x57:
  70.556 +   // BIT 2,A
  70.557 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(AF.B.B1&(1<<2)? 0:Z_FLAG);
  70.558 +   break;
  70.559 + case 0x58:
  70.560 +   // BIT 3,B
  70.561 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B1&(1<<3)? 0:Z_FLAG);
  70.562 +   break;
  70.563 + case 0x59:
  70.564 +   // BIT 3,C
  70.565 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B0&(1<<3)? 0:Z_FLAG);
  70.566 +   break;
  70.567 + case 0x5a:
  70.568 +   // BIT 3,D
  70.569 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B1&(1<<3)? 0:Z_FLAG);
  70.570 +   break;
  70.571 + case 0x5b:
  70.572 +   // BIT 3,E
  70.573 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B0&(1<<3)? 0:Z_FLAG);
  70.574 +   break;
  70.575 + case 0x5c:
  70.576 +   // BIT 3,H
  70.577 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B1&(1<<3)? 0:Z_FLAG);
  70.578 +   break;
  70.579 + case 0x5d:
  70.580 +   // BIT 3,L
  70.581 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B0&(1<<3)? 0:Z_FLAG);
  70.582 +   break;
  70.583 + case 0x5e:
  70.584 +   // BIT 3,(HL)
  70.585 +   tempValue=gbReadMemory(HL.W);
  70.586 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(tempValue&(1<<3)? 0:Z_FLAG);
  70.587 +   break;
  70.588 + case 0x5f:
  70.589 +   // BIT 3,A
  70.590 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(AF.B.B1&(1<<3)? 0:Z_FLAG);
  70.591 +   break;
  70.592 + case 0x60:
  70.593 +   // BIT 4,B
  70.594 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B1&(1<<4)? 0:Z_FLAG);
  70.595 +   break;
  70.596 + case 0x61:
  70.597 +   // BIT 4,C
  70.598 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B0&(1<<4)? 0:Z_FLAG);
  70.599 +   break;
  70.600 + case 0x62:
  70.601 +   // BIT 4,D
  70.602 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B1&(1<<4)? 0:Z_FLAG);
  70.603 +   break;
  70.604 + case 0x63:
  70.605 +   // BIT 4,E
  70.606 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B0&(1<<4)? 0:Z_FLAG);
  70.607 +   break;
  70.608 + case 0x64:
  70.609 +   // BIT 4,H
  70.610 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B1&(1<<4)? 0:Z_FLAG);
  70.611 +   break;
  70.612 + case 0x65:
  70.613 +   // BIT 4,L
  70.614 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B0&(1<<4)? 0:Z_FLAG);
  70.615 +   break;
  70.616 + case 0x66:
  70.617 +   // BIT 4,(HL)
  70.618 +   tempValue=gbReadMemory(HL.W);
  70.619 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(tempValue&(1<<4)? 0:Z_FLAG);
  70.620 +   break;
  70.621 + case 0x67:
  70.622 +   // BIT 4,A
  70.623 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(AF.B.B1&(1<<4)? 0:Z_FLAG);
  70.624 +   break;
  70.625 + case 0x68:
  70.626 +   // BIT 5,B
  70.627 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B1&(1<<5)? 0:Z_FLAG);
  70.628 +   break;
  70.629 + case 0x69:
  70.630 +   // BIT 5,C
  70.631 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B0&(1<<5)? 0:Z_FLAG);
  70.632 +   break;
  70.633 + case 0x6a:
  70.634 +   // BIT 5,D
  70.635 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B1&(1<<5)? 0:Z_FLAG);
  70.636 +   break;
  70.637 + case 0x6b:
  70.638 +   // BIT 5,E
  70.639 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B0&(1<<5)? 0:Z_FLAG);
  70.640 +   break;
  70.641 + case 0x6c:
  70.642 +   // BIT 5,H
  70.643 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B1&(1<<5)? 0:Z_FLAG);
  70.644 +   break;
  70.645 + case 0x6d:
  70.646 +   // BIT 5,L
  70.647 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B0&(1<<5)? 0:Z_FLAG);
  70.648 +   break;
  70.649 + case 0x6e:
  70.650 +   // BIT 5,(HL)
  70.651 +   tempValue=gbReadMemory(HL.W);
  70.652 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(tempValue&(1<<5)? 0:Z_FLAG);
  70.653 +   break;
  70.654 + case 0x6f:
  70.655 +   // BIT 5,A
  70.656 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(AF.B.B1&(1<<5)? 0:Z_FLAG);
  70.657 +   break;
  70.658 + case 0x70:
  70.659 +   // BIT 6,B
  70.660 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B1&(1<<6)? 0:Z_FLAG);
  70.661 +   break;
  70.662 + case 0x71:
  70.663 +   // BIT 6,C
  70.664 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B0&(1<<6)? 0:Z_FLAG);
  70.665 +   break;
  70.666 + case 0x72:
  70.667 +   // BIT 6,D
  70.668 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B1&(1<<6)? 0:Z_FLAG);
  70.669 +   break;
  70.670 + case 0x73:
  70.671 +   // BIT 6,E
  70.672 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B0&(1<<6)? 0:Z_FLAG);
  70.673 +   break;
  70.674 + case 0x74:
  70.675 +   // BIT 6,H
  70.676 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B1&(1<<6)? 0:Z_FLAG);
  70.677 +   break;
  70.678 + case 0x75:
  70.679 +   // BIT 6,L
  70.680 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B0&(1<<6)? 0:Z_FLAG);
  70.681 +   break;
  70.682 + case 0x76:
  70.683 +   // BIT 6,(HL)
  70.684 +   tempValue=gbReadMemory(HL.W);
  70.685 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(tempValue&(1<<6)? 0:Z_FLAG);
  70.686 +   break;
  70.687 + case 0x77:
  70.688 +   // BIT 6,A
  70.689 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(AF.B.B1&(1<<6)? 0:Z_FLAG);
  70.690 +   break;
  70.691 + case 0x78:
  70.692 +   // BIT 7,B
  70.693 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B1&(1<<7)? 0:Z_FLAG);
  70.694 +   break;
  70.695 + case 0x79:
  70.696 +   // BIT 7,C
  70.697 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(BC.B.B0&(1<<7)? 0:Z_FLAG);
  70.698 +   break;
  70.699 + case 0x7a:
  70.700 +   // BIT 7,D
  70.701 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B1&(1<<7)? 0:Z_FLAG);
  70.702 +   break;
  70.703 + case 0x7b:
  70.704 +   // BIT 7,E
  70.705 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(DE.B.B0&(1<<7)? 0:Z_FLAG);
  70.706 +   break;
  70.707 + case 0x7c:
  70.708 +   // BIT 7,H
  70.709 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B1&(1<<7)? 0:Z_FLAG);
  70.710 +   break;
  70.711 + case 0x7d:
  70.712 +   // BIT 7,L
  70.713 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(HL.B.B0&(1<<7)? 0:Z_FLAG);
  70.714 +   break;
  70.715 + case 0x7e:
  70.716 +   // BIT 7,(HL)
  70.717 +   tempValue=gbReadMemory(HL.W);
  70.718 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(tempValue&(1<<7)? 0:Z_FLAG);
  70.719 +   break;
  70.720 + case 0x7f:
  70.721 +   // BIT 7,A
  70.722 +   AF.B.B0=(AF.B.B0&C_FLAG)|H_FLAG|(AF.B.B1&(1<<7)? 0:Z_FLAG);
  70.723 +   break;
  70.724 + case 0x80:
  70.725 +   // RES 0,B
  70.726 +   BC.B.B1&=~(1<<0);
  70.727 +   break;
  70.728 + case 0x81:
  70.729 +   // RES 0,C
  70.730 +   BC.B.B0&=~(1<<0);
  70.731 +   break;
  70.732 + case 0x82:
  70.733 +   // RES 0,D
  70.734 +   DE.B.B1&=~(1<<0);
  70.735 +   break;
  70.736 + case 0x83:
  70.737 +   // RES 0,E
  70.738 +   DE.B.B0&=~(1<<0);
  70.739 +   break;
  70.740 + case 0x84:
  70.741 +   // RES 0,H
  70.742 +   HL.B.B1&=~(1<<0);
  70.743 +   break;
  70.744 + case 0x85:
  70.745 +   // RES 0,L
  70.746 +   HL.B.B0&=~(1<<0);
  70.747 +   break;
  70.748 + case 0x86:
  70.749 +   // RES 0,(HL)
  70.750 +   tempValue=gbReadMemory(HL.W);
  70.751 +   tempValue&=~(1<<0);
  70.752 +   gbWriteMemory(HL.W,tempValue);
  70.753 +   break;
  70.754 + case 0x87:
  70.755 +   // RES 0,A
  70.756 +   AF.B.B1&=~(1<<0);
  70.757 +   break;
  70.758 + case 0x88:
  70.759 +   // RES 1,B
  70.760 +   BC.B.B1&=~(1<<1);
  70.761 +   break;
  70.762 + case 0x89:
  70.763 +   // RES 1,C
  70.764 +   BC.B.B0&=~(1<<1);
  70.765 +   break;
  70.766 + case 0x8a:
  70.767 +   // RES 1,D
  70.768 +   DE.B.B1&=~(1<<1);
  70.769 +   break;
  70.770 + case 0x8b:
  70.771 +   // RES 1,E
  70.772 +   DE.B.B0&=~(1<<1);
  70.773 +   break;
  70.774 + case 0x8c:
  70.775 +   // RES 1,H
  70.776 +   HL.B.B1&=~(1<<1);
  70.777 +   break;
  70.778 + case 0x8d:
  70.779 +   // RES 1,L
  70.780 +   HL.B.B0&=~(1<<1);
  70.781 +   break;
  70.782 + case 0x8e:
  70.783 +   // RES 1,(HL)
  70.784 +   tempValue=gbReadMemory(HL.W);
  70.785 +   tempValue&=~(1<<1);
  70.786 +   gbWriteMemory(HL.W,tempValue);
  70.787 +   break;
  70.788 + case 0x8f:
  70.789 +   // RES 1,A
  70.790 +   AF.B.B1&=~(1<<1);
  70.791 +   break;
  70.792 + case 0x90:
  70.793 +   // RES 2,B
  70.794 +   BC.B.B1&=~(1<<2);
  70.795 +   break;
  70.796 + case 0x91:
  70.797 +   // RES 2,C
  70.798 +   BC.B.B0&=~(1<<2);
  70.799 +   break;
  70.800 + case 0x92:
  70.801 +   // RES 2,D
  70.802 +   DE.B.B1&=~(1<<2);
  70.803 +   break;
  70.804 + case 0x93:
  70.805 +   // RES 2,E
  70.806 +   DE.B.B0&=~(1<<2);
  70.807 +   break;
  70.808 + case 0x94:
  70.809 +   // RES 2,H
  70.810 +   HL.B.B1&=~(1<<2);
  70.811 +   break;
  70.812 + case 0x95:
  70.813 +   // RES 2,L
  70.814 +   HL.B.B0&=~(1<<2);
  70.815 +   break;
  70.816 + case 0x96:
  70.817 +   // RES 2,(HL)
  70.818 +   tempValue=gbReadMemory(HL.W);
  70.819 +   tempValue&=~(1<<2);
  70.820 +   gbWriteMemory(HL.W,tempValue);
  70.821 +   break;
  70.822 + case 0x97:
  70.823 +   // RES 2,A
  70.824 +   AF.B.B1&=~(1<<2);
  70.825 +   break;
  70.826 + case 0x98:
  70.827 +   // RES 3,B
  70.828 +   BC.B.B1&=~(1<<3);
  70.829 +   break;
  70.830 + case 0x99:
  70.831 +   // RES 3,C
  70.832 +   BC.B.B0&=~(1<<3);
  70.833 +   break;
  70.834 + case 0x9a:
  70.835 +   // RES 3,D
  70.836 +   DE.B.B1&=~(1<<3);
  70.837 +   break;
  70.838 + case 0x9b:
  70.839 +   // RES 3,E
  70.840 +   DE.B.B0&=~(1<<3);
  70.841 +   break;
  70.842 + case 0x9c:
  70.843 +   // RES 3,H
  70.844 +   HL.B.B1&=~(1<<3);
  70.845 +   break;
  70.846 + case 0x9d:
  70.847 +   // RES 3,L
  70.848 +   HL.B.B0&=~(1<<3);
  70.849 +   break;
  70.850 + case 0x9e:
  70.851 +   // RES 3,(HL)
  70.852 +   tempValue=gbReadMemory(HL.W);
  70.853 +   tempValue&=~(1<<3);
  70.854 +   gbWriteMemory(HL.W,tempValue);
  70.855 +   break;
  70.856 + case 0x9f:
  70.857 +   // RES 3,A
  70.858 +   AF.B.B1&=~(1<<3);
  70.859 +   break;
  70.860 + case 0xa0:
  70.861 +   // RES 4,B
  70.862 +   BC.B.B1&=~(1<<4);
  70.863 +   break;
  70.864 + case 0xa1:
  70.865 +   // RES 4,C
  70.866 +   BC.B.B0&=~(1<<4);
  70.867 +   break;
  70.868 + case 0xa2:
  70.869 +   // RES 4,D
  70.870 +   DE.B.B1&=~(1<<4);
  70.871 +   break;
  70.872 + case 0xa3:
  70.873 +   // RES 4,E
  70.874 +   DE.B.B0&=~(1<<4);
  70.875 +   break;
  70.876 + case 0xa4:
  70.877 +   // RES 4,H
  70.878 +   HL.B.B1&=~(1<<4);
  70.879 +   break;
  70.880 + case 0xa5:
  70.881 +   // RES 4,L
  70.882 +   HL.B.B0&=~(1<<4);
  70.883 +   break;
  70.884 + case 0xa6:
  70.885 +   // RES 4,(HL)
  70.886 +   tempValue=gbReadMemory(HL.W);
  70.887 +   tempValue&=~(1<<4);
  70.888 +   gbWriteMemory(HL.W,tempValue);
  70.889 +   break;
  70.890 + case 0xa7:
  70.891 +   // RES 4,A
  70.892 +   AF.B.B1&=~(1<<4);
  70.893 +   break;
  70.894 + case 0xa8:
  70.895 +   // RES 5,B
  70.896 +   BC.B.B1&=~(1<<5);
  70.897 +   break;
  70.898 + case 0xa9:
  70.899 +   // RES 5,C
  70.900 +   BC.B.B0&=~(1<<5);
  70.901 +   break;
  70.902 + case 0xaa:
  70.903 +   // RES 5,D
  70.904 +   DE.B.B1&=~(1<<5);
  70.905 +   break;
  70.906 + case 0xab:
  70.907 +   // RES 5,E
  70.908 +   DE.B.B0&=~(1<<5);
  70.909 +   break;
  70.910 + case 0xac:
  70.911 +   // RES 5,H
  70.912 +   HL.B.B1&=~(1<<5);
  70.913 +   break;
  70.914 + case 0xad:
  70.915 +   // RES 5,L
  70.916 +   HL.B.B0&=~(1<<5);
  70.917 +   break;
  70.918 + case 0xae:
  70.919 +   // RES 5,(HL)
  70.920 +   tempValue=gbReadMemory(HL.W);
  70.921 +   tempValue&=~(1<<5);
  70.922 +   gbWriteMemory(HL.W,tempValue);
  70.923 +   break;
  70.924 + case 0xaf:
  70.925 +   // RES 5,A
  70.926 +   AF.B.B1&=~(1<<5);
  70.927 +   break;
  70.928 + case 0xb0:
  70.929 +   // RES 6,B
  70.930 +   BC.B.B1&=~(1<<6);
  70.931 +   break;
  70.932 + case 0xb1:
  70.933 +   // RES 6,C
  70.934 +   BC.B.B0&=~(1<<6);
  70.935 +   break;
  70.936 + case 0xb2:
  70.937 +   // RES 6,D
  70.938 +   DE.B.B1&=~(1<<6);
  70.939 +   break;
  70.940 + case 0xb3:
  70.941 +   // RES 6,E
  70.942 +   DE.B.B0&=~(1<<6);
  70.943 +   break;
  70.944 + case 0xb4:
  70.945 +   // RES 6,H
  70.946 +   HL.B.B1&=~(1<<6);
  70.947 +   break;
  70.948 + case 0xb5:
  70.949 +   // RES 6,L
  70.950 +   HL.B.B0&=~(1<<6);
  70.951 +   break;
  70.952 + case 0xb6:
  70.953 +   // RES 6,(HL)
  70.954 +   tempValue=gbReadMemory(HL.W);
  70.955 +   tempValue&=~(1<<6);
  70.956 +   gbWriteMemory(HL.W,tempValue);
  70.957 +   break;
  70.958 + case 0xb7:
  70.959 +   // RES 6,A
  70.960 +   AF.B.B1&=~(1<<6);
  70.961 +   break;
  70.962 + case 0xb8:
  70.963 +   // RES 7,B
  70.964 +   BC.B.B1&=~(1<<7);
  70.965 +   break;
  70.966 + case 0xb9:
  70.967 +   // RES 7,C
  70.968 +   BC.B.B0&=~(1<<7);
  70.969 +   break;
  70.970 + case 0xba:
  70.971 +   // RES 7,D
  70.972 +   DE.B.B1&=~(1<<7);
  70.973 +   break;
  70.974 + case 0xbb:
  70.975 +   // RES 7,E
  70.976 +   DE.B.B0&=~(1<<7);
  70.977 +   break;
  70.978 + case 0xbc:
  70.979 +   // RES 7,H
  70.980 +   HL.B.B1&=~(1<<7);
  70.981 +   break;
  70.982 + case 0xbd:
  70.983 +   // RES 7,L
  70.984 +   HL.B.B0&=~(1<<7);
  70.985 +   break;
  70.986 + case 0xbe:
  70.987 +   // RES 7,(HL)
  70.988 +   tempValue=gbReadMemory(HL.W);
  70.989 +   tempValue&=~(1<<7);
  70.990 +   gbWriteMemory(HL.W,tempValue);
  70.991 +   break;
  70.992 + case 0xbf:
  70.993 +   // RES 7,A
  70.994 +   AF.B.B1&=~(1<<7);
  70.995 +   break;
  70.996 + case 0xc0:
  70.997 +   // SET 0,B
  70.998 +   BC.B.B1|=1<<0;
  70.999 +   break;
 70.1000 + case 0xc1:
 70.1001 +   // SET 0,C
 70.1002 +   BC.B.B0|=1<<0;
 70.1003 +   break;
 70.1004 + case 0xc2:
 70.1005 +   // SET 0,D
 70.1006 +   DE.B.B1|=1<<0;
 70.1007 +   break;
 70.1008 + case 0xc3:
 70.1009 +   // SET 0,E
 70.1010 +   DE.B.B0|=1<<0;
 70.1011 +   break;
 70.1012 + case 0xc4:
 70.1013 +   // SET 0,H
 70.1014 +   HL.B.B1|=1<<0;
 70.1015 +   break;
 70.1016 + case 0xc5:
 70.1017 +   // SET 0,L
 70.1018 +   HL.B.B0|=1<<0;
 70.1019 +   break;
 70.1020 + case 0xc6:
 70.1021 +   // SET 0,(HL)
 70.1022 +   tempValue=gbReadMemory(HL.W);
 70.1023 +   tempValue|=1<<0;
 70.1024 +   gbWriteMemory(HL.W,tempValue);
 70.1025 +   break;
 70.1026 + case 0xc7:
 70.1027 +   // SET 0,A
 70.1028 +   AF.B.B1|=1<<0;
 70.1029 +   break;
 70.1030 + case 0xc8:
 70.1031 +   // SET 1,B
 70.1032 +   BC.B.B1|=1<<1;
 70.1033 +   break;
 70.1034 + case 0xc9:
 70.1035 +   // SET 1,C
 70.1036 +   BC.B.B0|=1<<1;
 70.1037 +   break;
 70.1038 + case 0xca:
 70.1039 +   // SET 1,D
 70.1040 +   DE.B.B1|=1<<1;
 70.1041 +   break;
 70.1042 + case 0xcb:
 70.1043 +   // SET 1,E
 70.1044 +   DE.B.B0|=1<<1;
 70.1045 +   break;
 70.1046 + case 0xcc:
 70.1047 +   // SET 1,H
 70.1048 +   HL.B.B1|=1<<1;
 70.1049 +   break;
 70.1050 + case 0xcd:
 70.1051 +   // SET 1,L
 70.1052 +   HL.B.B0|=1<<1;
 70.1053 +   break;
 70.1054 + case 0xce:
 70.1055 +   // SET 1,(HL)
 70.1056 +   tempValue=gbReadMemory(HL.W);
 70.1057 +   tempValue|=1<<1;
 70.1058 +   gbWriteMemory(HL.W,tempValue);
 70.1059 +   break;
 70.1060 + case 0xcf:
 70.1061 +   // SET 1,A
 70.1062 +   AF.B.B1|=1<<1;
 70.1063 +   break;
 70.1064 + case 0xd0:
 70.1065 +   // SET 2,B
 70.1066 +   BC.B.B1|=1<<2;
 70.1067 +   break;
 70.1068 + case 0xd1:
 70.1069 +   // SET 2,C
 70.1070 +   BC.B.B0|=1<<2;
 70.1071 +   break;
 70.1072 + case 0xd2:
 70.1073 +   // SET 2,D
 70.1074 +   DE.B.B1|=1<<2;
 70.1075 +   break;
 70.1076 + case 0xd3:
 70.1077 +   // SET 2,E
 70.1078 +   DE.B.B0|=1<<2;
 70.1079 +   break;
 70.1080 + case 0xd4:
 70.1081 +   // SET 2,H
 70.1082 +   HL.B.B1|=1<<2;
 70.1083 +   break;
 70.1084 + case 0xd5:
 70.1085 +   // SET 2,L
 70.1086 +   HL.B.B0|=1<<2;
 70.1087 +   break;
 70.1088 + case 0xd6:
 70.1089 +   // SET 2,(HL)
 70.1090 +   tempValue=gbReadMemory(HL.W);
 70.1091 +   tempValue|=1<<2;
 70.1092 +   gbWriteMemory(HL.W,tempValue);
 70.1093 +   break;
 70.1094 + case 0xd7:
 70.1095 +   // SET 2,A
 70.1096 +   AF.B.B1|=1<<2;
 70.1097 +   break;
 70.1098 + case 0xd8:
 70.1099 +   // SET 3,B
 70.1100 +   BC.B.B1|=1<<3;
 70.1101 +   break;
 70.1102 + case 0xd9:
 70.1103 +   // SET 3,C
 70.1104 +   BC.B.B0|=1<<3;
 70.1105 +   break;
 70.1106 + case 0xda:
 70.1107 +   // SET 3,D
 70.1108 +   DE.B.B1|=1<<3;
 70.1109 +   break;
 70.1110 + case 0xdb:
 70.1111 +   // SET 3,E
 70.1112 +   DE.B.B0|=1<<3;
 70.1113 +   break;
 70.1114 + case 0xdc:
 70.1115 +   // SET 3,H
 70.1116 +   HL.B.B1|=1<<3;
 70.1117 +   break;
 70.1118 + case 0xdd:
 70.1119 +   // SET 3,L
 70.1120 +   HL.B.B0|=1<<3;
 70.1121 +   break;
 70.1122 + case 0xde:
 70.1123 +   // SET 3,(HL)
 70.1124 +   tempValue=gbReadMemory(HL.W);
 70.1125 +   tempValue|=1<<3;
 70.1126 +   gbWriteMemory(HL.W,tempValue);
 70.1127 +   break;
 70.1128 + case 0xdf:
 70.1129 +   // SET 3,A
 70.1130 +   AF.B.B1|=1<<3;
 70.1131 +   break;
 70.1132 + case 0xe0:
 70.1133 +   // SET 4,B
 70.1134 +   BC.B.B1|=1<<4;
 70.1135 +   break;
 70.1136 + case 0xe1:
 70.1137 +   // SET 4,C
 70.1138 +   BC.B.B0|=1<<4;
 70.1139 +   break;
 70.1140 + case 0xe2:
 70.1141 +   // SET 4,D
 70.1142 +   DE.B.B1|=1<<4;
 70.1143 +   break;
 70.1144 + case 0xe3:
 70.1145 +   // SET 4,E
 70.1146 +   DE.B.B0|=1<<4;
 70.1147 +   break;
 70.1148 + case 0xe4:
 70.1149 +   // SET 4,H
 70.1150 +   HL.B.B1|=1<<4;
 70.1151 +   break;
 70.1152 + case 0xe5:
 70.1153 +   // SET 4,L
 70.1154 +   HL.B.B0|=1<<4;
 70.1155 +   break;
 70.1156 + case 0xe6:
 70.1157 +   // SET 4,(HL)
 70.1158 +   tempValue=gbReadMemory(HL.W);
 70.1159 +   tempValue|=1<<4;
 70.1160 +   gbWriteMemory(HL.W,tempValue);
 70.1161 +   break;
 70.1162 + case 0xe7:
 70.1163 +   // SET 4,A
 70.1164 +   AF.B.B1|=1<<4;
 70.1165 +   break;
 70.1166 + case 0xe8:
 70.1167 +   // SET 5,B
 70.1168 +   BC.B.B1|=1<<5;
 70.1169 +   break;
 70.1170 + case 0xe9:
 70.1171 +   // SET 5,C
 70.1172 +   BC.B.B0|=1<<5;
 70.1173 +   break;
 70.1174 + case 0xea:
 70.1175 +   // SET 5,D
 70.1176 +   DE.B.B1|=1<<5;
 70.1177 +   break;
 70.1178 + case 0xeb:
 70.1179 +   // SET 5,E
 70.1180 +   DE.B.B0|=1<<5;
 70.1181 +   break;
 70.1182 + case 0xec:
 70.1183 +   // SET 5,H
 70.1184 +   HL.B.B1|=1<<5;
 70.1185 +   break;
 70.1186 + case 0xed:
 70.1187 +   // SET 5,L
 70.1188 +   HL.B.B0|=1<<5;
 70.1189 +   break;
 70.1190 + case 0xee:
 70.1191 +   // SET 5,(HL)
 70.1192 +   tempValue=gbReadMemory(HL.W);
 70.1193 +   tempValue|=1<<5;
 70.1194 +   gbWriteMemory(HL.W,tempValue);
 70.1195 +   break;
 70.1196 + case 0xef:
 70.1197 +   // SET 5,A
 70.1198 +   AF.B.B1|=1<<5;
 70.1199 +   break;
 70.1200 + case 0xf0:
 70.1201 +   // SET 6,B
 70.1202 +   BC.B.B1|=1<<6;
 70.1203 +   break;
 70.1204 + case 0xf1:
 70.1205 +   // SET 6,C
 70.1206 +   BC.B.B0|=1<<6;
 70.1207 +   break;
 70.1208 + case 0xf2:
 70.1209 +   // SET 6,D
 70.1210 +   DE.B.B1|=1<<6;
 70.1211 +   break;
 70.1212 + case 0xf3:
 70.1213 +   // SET 6,E
 70.1214 +   DE.B.B0|=1<<6;
 70.1215 +   break;
 70.1216 + case 0xf4:
 70.1217 +   // SET 6,H
 70.1218 +   HL.B.B1|=1<<6;
 70.1219 +   break;
 70.1220 + case 0xf5:
 70.1221 +   // SET 6,L
 70.1222 +   HL.B.B0|=1<<6;
 70.1223 +   break;
 70.1224 + case 0xf6:
 70.1225 +   // SET 6,(HL)
 70.1226 +   tempValue=gbReadMemory(HL.W);
 70.1227 +   tempValue|=1<<6;
 70.1228 +   gbWriteMemory(HL.W,tempValue);
 70.1229 +   break;
 70.1230 + case 0xf7:
 70.1231 +   // SET 6,A
 70.1232 +   AF.B.B1|=1<<6;
 70.1233 +   break;
 70.1234 + case 0xf8:
 70.1235 +   // SET 7,B
 70.1236 +   BC.B.B1|=1<<7;
 70.1237 +   break;
 70.1238 + case 0xf9:
 70.1239 +   // SET 7,C
 70.1240 +   BC.B.B0|=1<<7;
 70.1241 +   break;
 70.1242 + case 0xfa:
 70.1243 +   // SET 7,D
 70.1244 +   DE.B.B1|=1<<7;
 70.1245 +   break;
 70.1246 + case 0xfb:
 70.1247 +   // SET 7,E
 70.1248 +   DE.B.B0|=1<<7;
 70.1249 +   break;
 70.1250 + case 0xfc:
 70.1251 +   // SET 7,H
 70.1252 +   HL.B.B1|=1<<7;
 70.1253 +   break;
 70.1254 + case 0xfd:
 70.1255 +   // SET 7,L
 70.1256 +   HL.B.B0|=1<<7;
 70.1257 +   break;
 70.1258 + case 0xfe:
 70.1259 +   // SET 7,(HL)
 70.1260 +   tempValue=gbReadMemory(HL.W);
 70.1261 +   tempValue|=1<<7;
 70.1262 +   gbWriteMemory(HL.W,tempValue);
 70.1263 +   break;
 70.1264 + case 0xff:
 70.1265 +   // SET 7,A
 70.1266 +   AF.B.B1|=1<<7;
 70.1267 +   break;
 70.1268 + default:
 70.1269 +   systemMessage(0, N_("Unknown opcode %02x at %04x"),
 70.1270 +                 gbReadOpcode(PC.W-1),PC.W-1);
 70.1271 +   emulating = false;
 70.1272 +   return;
    71.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    71.2 +++ b/src/gb/gbDis.cpp	Sat Mar 03 10:31:27 2012 -0600
    71.3 @@ -0,0 +1,239 @@
    71.4 +#include <cstdio>
    71.5 +#include <cstring>
    71.6 +
    71.7 +#include "gbGlobals.h"
    71.8 +
    71.9 +typedef struct
   71.10 +{
   71.11 +	u8    mask;
   71.12 +	u8    value;
   71.13 +	char *mnen;
   71.14 +} GBOPCODE;
   71.15 +
   71.16 +static char *registers[] =
   71.17 +{ "B", "C", "D", "E", "H", "L", "(HL)", "A" };
   71.18 +
   71.19 +static char *registers16[] =
   71.20 +{ "BC", "DE", "HL", "SP", // for some operations
   71.21 +  "BC", "DE", "HL", "AF" };   // for push/pop
   71.22 +
   71.23 +static char *cond[] =
   71.24 +{ "NZ", "Z", "NC", "C" };
   71.25 +
   71.26 +static char hexDigits[16] = {
   71.27 +	'0', '1', '2', '3', '4', '5', '6', '7',
   71.28 +	'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
   71.29 +};
   71.30 +
   71.31 +static GBOPCODE opcodes[] = {
   71.32 +	{ 0xff, 0x00, "NOP"            },
   71.33 +	{ 0xcf, 0x01, "LD %R4,%W"      },
   71.34 +	{ 0xff, 0x02, "LD (BC),A"      },
   71.35 +	{ 0xcf, 0x03, "INC %R4"        },
   71.36 +	{ 0xc7, 0x04, "INC %r3"        },
   71.37 +	{ 0xc7, 0x05, "DEC %r3"        },
   71.38 +	{ 0xc7, 0x06, "LD %r3,%B"      },
   71.39 +	{ 0xff, 0x07, "RLCA"           },
   71.40 +	{ 0xff, 0x08, "LD (%W),SP"     },
   71.41 +	{ 0xcf, 0x09, "ADD HL,%R4"     },
   71.42 +	{ 0xff, 0x0a, "LD A,(BC)"      },
   71.43 +	{ 0xcf, 0x0b, "DEC %R4"        },
   71.44 +	{ 0xff, 0x0f, "RRCA"           },
   71.45 +	{ 0xff, 0x10, "STOP"           },
   71.46 +	{ 0xff, 0x12, "LD (DE),A"      },
   71.47 +	{ 0xff, 0x17, "RLA"            },
   71.48 +	{ 0xff, 0x18, "JR %d"          },
   71.49 +	{ 0xff, 0x1a, "LD A,(DE)"      },
   71.50 +	{ 0xff, 0x1f, "RRA"            },
   71.51 +	{ 0xe7, 0x20, "JR %c3,%d"      },
   71.52 +	{ 0xff, 0x22, "LDI (HL),A"     },
   71.53 +	{ 0xff, 0x27, "DAA"            },
   71.54 +	{ 0xff, 0x2a, "LDI A,(HL)"     },
   71.55 +	{ 0xff, 0x2f, "CPL"            },
   71.56 +	{ 0xff, 0x32, "LDD (HL),A"     },
   71.57 +	{ 0xff, 0x37, "SCF"            },
   71.58 +	{ 0xff, 0x3a, "LDD A,(HL)"     },
   71.59 +	{ 0xff, 0x3f, "CCF"            },
   71.60 +	{ 0xff, 0x76, "HALT"           },
   71.61 +	{ 0xc0, 0x40, "LD %r3,%r0"     },
   71.62 +	{ 0xf8, 0x80, "ADD A,%r0"      },
   71.63 +	{ 0xf8, 0x88, "ADC A,%r0"      },
   71.64 +	{ 0xf8, 0x90, "SUB %r0"        },
   71.65 +	{ 0xf8, 0x98, "SBC A,%r0"      },
   71.66 +	{ 0xf8, 0xa0, "AND %r0"        },
   71.67 +	{ 0xf8, 0xa8, "XOR %r0"        },
   71.68 +	{ 0xf8, 0xb0, "OR %r0"         },
   71.69 +	{ 0xf8, 0xb8, "CP %r0"         },
   71.70 +	{ 0xe7, 0xc0, "RET %c3"        },
   71.71 +	{ 0xcf, 0xc1, "POP %t4"        },
   71.72 +	{ 0xe7, 0xc2, "JP %c3,%W"      },
   71.73 +	{ 0xff, 0xc3, "JP %W"          },
   71.74 +	{ 0xe7, 0xc4, "CALL %c3,%W"    },
   71.75 +	{ 0xcf, 0xc5, "PUSH %t4"       },
   71.76 +	{ 0xff, 0xc6, "ADD A,%B"       },
   71.77 +	{ 0xc7, 0xc7, "RST %P"         },
   71.78 +	{ 0xff, 0xc9, "RET"            },
   71.79 +	{ 0xff, 0xcd, "CALL %W"        },
   71.80 +	{ 0xff, 0xce, "ADC %B"         },
   71.81 +	{ 0xff, 0xd6, "SUB %B"         },
   71.82 +	{ 0xff, 0xd9, "RETI"           },
   71.83 +	{ 0xff, 0xde, "SBC %B"         },
   71.84 +	{ 0xff, 0xe0, "LD (FF%B),A"    },
   71.85 +	{ 0xff, 0xe2, "LD (FF00h+C),A" },
   71.86 +	{ 0xff, 0xe6, "AND %B"         },
   71.87 +	{ 0xff, 0xe8, "ADD SP,%D"      },
   71.88 +	{ 0xff, 0xe9, "LD PC,HL"       },
   71.89 +	{ 0xff, 0xea, "LD (%W),A"      },
   71.90 +	{ 0xff, 0xee, "XOR %B"         },
   71.91 +	{ 0xff, 0xf0, "LD A,(FF%B)"    },
   71.92 +	{ 0xff, 0xf2, "LD A,(FF00h+C)" },
   71.93 +	{ 0xff, 0xf3, "DI"             },
   71.94 +	{ 0xff, 0xf6, "OR %B"          },
   71.95 +	{ 0xff, 0xf8, "LD HL,SP%D"     },
   71.96 +	{ 0xff, 0xf9, "LD SP,HL"       },
   71.97 +	{ 0xff, 0xfa, "LD A,(%W)"      },
   71.98 +	{ 0xff, 0xfb, "EI"             },
   71.99 +	{ 0xff, 0xfe, "CP %B"          },
  71.100 +	{ 0x00, 0x00, "DB %B"          }
  71.101 +};
  71.102 +
  71.103 +static GBOPCODE cbOpcodes[] = {
  71.104 +	{ 0xf8, 0x00, "RLC %r0"    },
  71.105 +	{ 0xf8, 0x08, "RRC %r0"    },
  71.106 +	{ 0xf8, 0x10, "RL %r0"     },
  71.107 +	{ 0xf8, 0x18, "RR %r0"     },
  71.108 +	{ 0xf8, 0x20, "SLA %r0"    },
  71.109 +	{ 0xf8, 0x28, "SRA %r0"    },
  71.110 +	{ 0xf8, 0x30, "SWAP %r0"   },
  71.111 +	{ 0xf8, 0x38, "SRL %r0"    },
  71.112 +	{ 0xc0, 0x40, "BIT %b,%r0" },
  71.113 +	{ 0xc0, 0x80, "RES %b,%r0" },
  71.114 +	{ 0xc0, 0xc0, "SET %b,%r0" },
  71.115 +	{ 0x00, 0x00, "DB CBh,%B"  }
  71.116 +};
  71.117 +
  71.118 +static char *addHex(char *p, u8 value)
  71.119 +{
  71.120 +	*p++ = hexDigits[value >> 4];
  71.121 +	*p++ = hexDigits[value & 15];
  71.122 +	return p;
  71.123 +}
  71.124 +
  71.125 +static char *addHex16(char *p, u16 value)
  71.126 +{
  71.127 +	p = addHex(p, value>>8);
  71.128 +	return addHex(p, value & 255);
  71.129 +}
  71.130 +
  71.131 +static char *addStr(char *p, char *s)
  71.132 +{
  71.133 +	while (*s)
  71.134 +	{
  71.135 +		*p++ = *s++;
  71.136 +	}
  71.137 +	return p;
  71.138 +}
  71.139 +
  71.140 +int gbDis(char *buffer, u16 address)
  71.141 +{
  71.142 +	char *p     = buffer;
  71.143 +	int   instr = 1;
  71.144 +	u16   addr  = address;
  71.145 +	sprintf(p, "%04x        ", address);
  71.146 +	p += 12;
  71.147 +
  71.148 +	u8 opcode = gbReadMemoryQuick(address);
  71.149 +	address++;
  71.150 +	char *    mnen;
  71.151 +	GBOPCODE *op;
  71.152 +	if (opcode == 0xcb)
  71.153 +	{
  71.154 +		opcode = gbReadMemoryQuick(address);
  71.155 +		address++;
  71.156 +		instr++;
  71.157 +		op = cbOpcodes;
  71.158 +	}
  71.159 +	else
  71.160 +	{
  71.161 +		op = opcodes;
  71.162 +	}
  71.163 +	while (op->value != (opcode & op->mask))
  71.164 +		op++;
  71.165 +	mnen = op->mnen;
  71.166 +
  71.167 +	u8  b0, b1;
  71.168 +	s8  disp;
  71.169 +	int shift;
  71.170 +
  71.171 +	while (*mnen)
  71.172 +	{
  71.173 +		if (*mnen == '%')
  71.174 +		{
  71.175 +			mnen++;
  71.176 +			switch (*mnen++)
  71.177 +			{
  71.178 +			case 'W':
  71.179 +				b0 = gbReadMemoryQuick(address);
  71.180 +				address++;
  71.181 +				b1 = gbReadMemoryQuick(address);
  71.182 +				address++;
  71.183 +				p      = addHex16(p, b0|b1<<8);
  71.184 +				instr += 2;
  71.185 +				*p++   = 'h';
  71.186 +				break;
  71.187 +			case 'B':
  71.188 +				p    = addHex(p, gbReadMemoryQuick(address));
  71.189 +				*p++ = 'h';
  71.190 +				address++;
  71.191 +				instr++;
  71.192 +				break;
  71.193 +			case 'D':
  71.194 +				disp = gbReadMemoryQuick(address);
  71.195 +				if (disp >= 0)
  71.196 +					*p++ = '+';
  71.197 +				p += sprintf(p, "%d", disp);
  71.198 +				instr++;
  71.199 +				break;
  71.200 +			case 'd':
  71.201 +				disp = gbReadMemoryQuick(address);
  71.202 +				address++;
  71.203 +				p    = addHex16(p, address+disp);
  71.204 +				*p++ = 'h';
  71.205 +				instr++;
  71.206 +				break;
  71.207 +			case 'b':
  71.208 +				// kind of a hack, but it works :-)
  71.209 +				*p++ = hexDigits[(opcode >> 3) & 7];
  71.210 +				break;
  71.211 +			case 'r':
  71.212 +				shift = *mnen++ - '0';
  71.213 +				p     = addStr(p, registers[(opcode >> shift) & 7]);
  71.214 +				break;
  71.215 +			case 'R':
  71.216 +				shift = *mnen++ - '0';
  71.217 +				p     = addStr(p, registers16[(opcode >> shift) & 3]);
  71.218 +				break;
  71.219 +			case 't':
  71.220 +				shift = *mnen++ - '0';
  71.221 +				p     = addStr(p, registers16[4+((opcode >> shift) & 3)]);
  71.222 +				break;
  71.223 +			case 'P':
  71.224 +				p = addHex(p, ((opcode >> 3) & 7) * 8);
  71.225 +				break;
  71.226 +			case 'c':
  71.227 +				shift = *mnen++ - '0';
  71.228 +				p     = addStr(p, cond[(opcode >> shift) & 3]);
  71.229 +				break;
  71.230 +			}
  71.231 +		}
  71.232 +		else
  71.233 +			*p++ = *mnen++;
  71.234 +	}
  71.235 +	for (int i = 0; i < instr; i++)
  71.236 +	{
  71.237 +		u16 a = addr + i;
  71.238 +		addHex(buffer+5+i*2, gbReadMemoryQuick(a));
  71.239 +	}
  71.240 +	*p = 0;
  71.241 +	return instr;
  71.242 +}
    72.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    72.2 +++ b/src/gb/gbGfx.cpp	Sat Mar 03 10:31:27 2012 -0600
    72.3 @@ -0,0 +1,552 @@
    72.4 +#include <cstring>
    72.5 +
    72.6 +#include "gbGlobals.h"
    72.7 +#include "gbSGB.h"
    72.8 +
    72.9 +extern int32 layerSettings;
   72.10 +
   72.11 +u8 gbInvertTab[256] = {
   72.12 +	0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
   72.13 +	0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
   72.14 +	0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
   72.15 +	0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
   72.16 +	0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
   72.17 +	0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
   72.18 +	0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
   72.19 +	0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
   72.20 +	0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
   72.21 +	0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
   72.22 +	0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
   72.23 +	0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
   72.24 +	0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
   72.25 +	0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
   72.26 +	0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
   72.27 +	0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
   72.28 +	0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
   72.29 +	0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
   72.30 +	0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
   72.31 +	0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
   72.32 +	0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
   72.33 +	0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
   72.34 +	0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
   72.35 +	0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
   72.36 +	0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
   72.37 +	0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
   72.38 +	0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
   72.39 +	0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
   72.40 +	0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
   72.41 +	0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
   72.42 +	0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
   72.43 +	0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
   72.44 +};
   72.45 +
   72.46 +u16 gbLineMix[160];
   72.47 +
   72.48 +void gbRenderLine()
   72.49 +{
   72.50 +	u8 *bank0;
   72.51 +	u8 *bank1;
   72.52 +	if (gbCgbMode)
   72.53 +	{
   72.54 +		bank0 = &gbVram[0x0000];
   72.55 +		bank1 = &gbVram[0x2000];
   72.56 +	}
   72.57 +	else
   72.58 +	{
   72.59 +		bank0 = &gbMemory[0x8000];
   72.60 +		bank1 = NULL;
   72.61 +	}
   72.62 +
   72.63 +	int tile_map = 0x1800;
   72.64 +	if ((register_LCDC & 8) != 0)
   72.65 +		tile_map = 0x1c00;
   72.66 +
   72.67 +	int tile_pattern = 0x0800;
   72.68 +
   72.69 +	if ((register_LCDC & 16) != 0)
   72.70 +		tile_pattern = 0x0000;
   72.71 +
   72.72 +	int x = 0;
   72.73 +	int y = register_LY;
   72.74 +
   72.75 +	if (y >= 144)
   72.76 +		return;
   72.77 +
   72.78 +	//  int yLine = (y + gbBorderRowSkip) * gbBorderLineSkip;
   72.79 +
   72.80 +	int sx = register_SCX;
   72.81 +	int sy = register_SCY;
   72.82 +
   72.83 +	sy += y;
   72.84 +
   72.85 +	sy &= 255;
   72.86 +
   72.87 +	int tx = sx >> 3;
   72.88 +	int ty = sy >> 3;
   72.89 +
   72.90 +	int bx = 1 << (7 - (sx & 7));
   72.91 +	int by = sy & 7;
   72.92 +
   72.93 +	int tile_map_line_y = tile_map + ty * 32;
   72.94 +
   72.95 +	int tile_map_address = tile_map_line_y + tx;
   72.96 +
   72.97 +	u8 attrs = 0;
   72.98 +	if (bank1 != NULL)
   72.99 +		attrs = bank1[tile_map_address];
  72.100 +
  72.101 +	u8 tile = bank0[tile_map_address];
  72.102 +
  72.103 +	tile_map_address++;
  72.104 +
  72.105 +	if ((register_LCDC & 16) == 0)
  72.106 +	{
  72.107 +		if (tile < 128)
  72.108 +			tile += 128;
  72.109 +		else
  72.110 +			tile -= 128;
  72.111 +	}
  72.112 +
  72.113 +	int tile_pattern_address = tile_pattern + tile * 16 + by*2;
  72.114 +
  72.115 +	if (register_LCDC & 0x80)
  72.116 +	{
  72.117 +		if ((register_LCDC & 0x01 || gbCgbMode) && (layerSettings & 0x0100))
  72.118 +		{
  72.119 +			while (x < 160)
  72.120 +			{
  72.121 +				u8 tile_a = 0;
  72.122 +				u8 tile_b = 0;
  72.123 +
  72.124 +				if (attrs & 0x40)
  72.125 +				{
  72.126 +					tile_pattern_address = tile_pattern + tile * 16 + (7-by)*2;
  72.127 +				}
  72.128 +
  72.129 +				if (attrs & 0x08)
  72.130 +				{
  72.131 +					tile_a = bank1[tile_pattern_address++];
  72.132 +					tile_b = bank1[tile_pattern_address];
  72.133 +				}
  72.134 +				else
  72.135 +				{
  72.136 +					tile_a = bank0[tile_pattern_address++];
  72.137 +					tile_b = bank0[tile_pattern_address];
  72.138 +				}
  72.139 +
  72.140 +				if (attrs & 0x20)
  72.141 +				{
  72.142 +					tile_a = gbInvertTab[tile_a];
  72.143 +					tile_b = gbInvertTab[tile_b];
  72.144 +				}
  72.145 +
  72.146 +				while (bx > 0)
  72.147 +				{
  72.148 +					u8 c = (tile_a & bx) ? 1 : 0;
  72.149 +					c += ((tile_b & bx) ? 2 : 0);
  72.150 +
  72.151 +					gbLineBuffer[x] = c; // mark the gbLineBuffer color
  72.152 +
  72.153 +					if (attrs & 0x80)
  72.154 +						gbLineBuffer[x] |= 0x300;
  72.155 +
  72.156 +					if (gbCgbMode)
  72.157 +					{
  72.158 +						c = c + (attrs & 7)*4;
  72.159 +					}
  72.160 +					else
  72.161 +					{
  72.162 +						c = gbBgp[c];
  72.163 +						if (gbSgbMode && !gbCgbMode)
  72.164 +						{
  72.165 +							int dx = x >> 3;
  72.166 +							int dy = y >> 3;
  72.167 +
  72.168 +							int palette = gbSgbATF[dy * 20 + dx];
  72.169 +
  72.170 +							if (c == 0)
  72.171 +								palette = 0;
  72.172 +
  72.173 +							c = c + 4*palette;
  72.174 +						}
  72.175 +					}
  72.176 +					gbLineMix[x] = gbColorOption ? gbColorFilter[gbPalette[c]] :
  72.177 +					               gbPalette[c];
  72.178 +					x++;
  72.179 +					if (x >= 160)
  72.180 +						break;
  72.181 +					bx >>= 1;
  72.182 +				}
  72.183 +				tx++;
  72.184 +				if (tx == 32)
  72.185 +					tx = 0;
  72.186 +				bx = 128;
  72.187 +
  72.188 +				if (bank1)
  72.189 +					attrs = bank1[tile_map_line_y + tx];
  72.190 +
  72.191 +				tile = bank0[tile_map_line_y + tx];
  72.192 +
  72.193 +				if ((register_LCDC & 16) == 0)
  72.194 +				{
  72.195 +					if (tile < 128)
  72.196 +						tile += 128;
  72.197 +					else
  72.198 +						tile -= 128;
  72.199 +				}
  72.200 +				tile_pattern_address = tile_pattern + tile * 16 + by * 2;
  72.201 +			}
  72.202 +		}
  72.203 +		else
  72.204 +		{
  72.205 +			for (int i = 0; i < 160; i++)
  72.206 +			{
  72.207 +				gbLineMix[i]    = gbPalette[0];
  72.208 +				gbLineBuffer[i] = 0;
  72.209 +			}
  72.210 +		}
  72.211 +
  72.212 +		// do the window display
  72.213 +		if ((register_LCDC & 0x20) && (layerSettings & 0x2000))
  72.214 +		{
  72.215 +			int wy = register_WY;
  72.216 +
  72.217 +			if (y >= wy)
  72.218 +			{
  72.219 +				int wx = register_WX;
  72.220 +				wx -= 7;
  72.221 +
  72.222 +				if (wx <= 159 && gbWindowLine <= 143)
  72.223 +				{
  72.224 +					tile_map = 0x1800;
  72.225 +
  72.226 +					if ((register_LCDC & 0x40) != 0)
  72.227 +						tile_map = 0x1c00;
  72.228 +
  72.229 +					if (gbWindowLine == -1)
  72.230 +					{
  72.231 +						gbWindowLine = 0;
  72.232 +					}
  72.233 +
  72.234 +					tx = 0;
  72.235 +					ty = gbWindowLine >> 3;
  72.236 +
  72.237 +					bx = 128;
  72.238 +					by = gbWindowLine & 7;
  72.239 +
  72.240 +					if (wx < 0)
  72.241 +					{
  72.242 +						bx >>= (-wx);
  72.243 +						wx   = 0;
  72.244 +					}
  72.245 +
  72.246 +					tile_map_line_y = tile_map + ty * 32;
  72.247 +
  72.248 +					tile_map_address = tile_map_line_y + tx;
  72.249 +
  72.250 +					x = wx;
  72.251 +
  72.252 +					tile = bank0[tile_map_address];
  72.253 +					u8 attrs = 0;
  72.254 +					if (bank1)
  72.255 +						attrs = bank1[tile_map_address];
  72.256 +					tile_map_address++;
  72.257 +
  72.258 +					if ((register_LCDC & 16) == 0)
  72.259 +					{
  72.260 +						if (tile < 128)
  72.261 +							tile += 128;
  72.262 +						else
  72.263 +							tile -= 128;
  72.264 +					}
  72.265 +
  72.266 +					tile_pattern_address = tile_pattern + tile * 16 + by*2;
  72.267 +
  72.268 +					while (x < 160)
  72.269 +					{
  72.270 +						u8 tile_a = 0;
  72.271 +						u8 tile_b = 0;
  72.272 +
  72.273 +						if (attrs & 0x40)
  72.274 +						{
  72.275 +							tile_pattern_address = tile_pattern + tile * 16 + (7-by)*2;
  72.276 +						}
  72.277 +
  72.278 +						if (attrs & 0x08)
  72.279 +						{
  72.280 +							tile_a = bank1[tile_pattern_address++];
  72.281 +							tile_b = bank1[tile_pattern_address];
  72.282 +						}
  72.283 +						else
  72.284 +						{
  72.285 +							tile_a = bank0[tile_pattern_address++];
  72.286 +							tile_b = bank0[tile_pattern_address];
  72.287 +						}
  72.288 +
  72.289 +						if (attrs & 0x20)
  72.290 +						{
  72.291 +							tile_a = gbInvertTab[tile_a];
  72.292 +							tile_b = gbInvertTab[tile_b];
  72.293 +						}
  72.294 +
  72.295 +						while (bx > 0)
  72.296 +						{
  72.297 +							u8 c = (tile_a & bx) != 0 ? 1 : 0;
  72.298 +							c += ((tile_b & bx) != 0 ? 2 : 0);
  72.299 +
  72.300 +							if (attrs & 0x80)
  72.301 +								gbLineBuffer[x] = 0x300 + c;
  72.302 +							else
  72.303 +								gbLineBuffer[x] = 0x100 + c;
  72.304 +
  72.305 +							if (gbCgbMode)
  72.306 +							{
  72.307 +								c = c + (attrs & 7) * 4;
  72.308 +							}
  72.309 +							else
  72.310 +							{
  72.311 +								c = gbBgp[c];
  72.312 +								if (gbSgbMode && !gbCgbMode)
  72.313 +								{
  72.314 +									int dx = x >> 3;
  72.315 +									int dy = y >> 3;
  72.316 +
  72.317 +									int palette = gbSgbATF[dy * 20 + dx];
  72.318 +
  72.319 +									if (c == 0)
  72.320 +										palette = 0;
  72.321 +
  72.322 +									c = c + 4*palette;
  72.323 +								}
  72.324 +							}
  72.325 +							gbLineMix[x] = gbColorOption ? gbColorFilter[gbPalette[c]] :
  72.326 +							               gbPalette[c];
  72.327 +							x++;
  72.328 +							if (x >= 160)
  72.329 +								break;
  72.330 +							bx >>= 1;
  72.331 +						}
  72.332 +						tx++;
  72.333 +						if (tx == 32)
  72.334 +							tx = 0;
  72.335 +						bx   = 128;
  72.336 +						tile = bank0[tile_map_line_y + tx];
  72.337 +						if (bank1)
  72.338 +							attrs = bank1[tile_map_line_y + tx];
  72.339 +
  72.340 +						if ((register_LCDC & 16) == 0)
  72.341 +						{
  72.342 +							if (tile < 128)
  72.343 +								tile += 128;
  72.344 +							else
  72.345 +								tile -= 128;
  72.346 +						}
  72.347 +						tile_pattern_address = tile_pattern + tile * 16 + by * 2;
  72.348 +					}
  72.349 +					gbWindowLine++;
  72.350 +				}
  72.351 +			}
  72.352 +		}
  72.353 +	}
  72.354 +	else
  72.355 +	{
  72.356 +		for (int i = 0; i < 160; i++)
  72.357 +		{
  72.358 +			gbLineMix[i]    = gbPalette[0];
  72.359 +			gbLineBuffer[i] = 0;
  72.360 +		}
  72.361 +	}
  72.362 +}
  72.363 +
  72.364 +void gbDrawSpriteTile(int tile, int x, int y, int t, int flags,
  72.365 +                      int size, int spriteNumber)
  72.366 +{
  72.367 +	u8 *bank0;
  72.368 +	u8 *bank1;
  72.369 +	if (gbCgbMode)
  72.370 +	{
  72.371 +		if (register_VBK & 1)
  72.372 +		{
  72.373 +			bank0 = &gbVram[0x0000];
  72.374 +			bank1 = &gbVram[0x2000];
  72.375 +		}
  72.376 +		else
  72.377 +		{
  72.378 +			bank0 = &gbVram[0x0000];
  72.379 +			bank1 = &gbVram[0x2000];
  72.380 +		}
  72.381 +	}
  72.382 +	else
  72.383 +	{
  72.384 +		bank0 = &gbMemory[0x8000];
  72.385 +		bank1 = NULL;
  72.386 +	}
  72.387 +
  72.388 +	int init = 0x0000;
  72.389 +
  72.390 +	//  int yLine = (y+gbBorderRowSkip) * gbBorderLineSkip;
  72.391 +
  72.392 +	u8 *pal = gbObp0;
  72.393 +
  72.394 +	int flipx = (flags & 0x20);
  72.395 +	int flipy = (flags & 0x40);
  72.396 +
  72.397 +	if ((flags & 0x10))
  72.398 +		pal = gbObp1;
  72.399 +
  72.400 +	if (flipy)
  72.401 +	{
  72.402 +		t = (size ? 15 : 7) - t;
  72.403 +	}
  72.404 +
  72.405 +	int prio =  flags & 0x80;
  72.406 +
  72.407 +	int address = init + tile * 16 + 2*t;
  72.408 +	int a       = 0;
  72.409 +	int b       = 0;
  72.410 +
  72.411 +	if (gbCgbMode && flags & 0x08)
  72.412 +	{
  72.413 +		a = bank1[address++];
  72.414 +		b = bank1[address++];
  72.415 +	}
  72.416 +	else
  72.417 +	{
  72.418 +		a = bank0[address++];
  72.419 +		b = bank0[address++];
  72.420 +	}
  72.421 +
  72.422 +	for (int xx = 0; xx < 8; xx++)
  72.423 +	{
  72.424 +		u8 mask = 1 << (7-xx);
  72.425 +		u8 c    = 0;
  72.426 +		if ((a & mask))
  72.427 +			c++;
  72.428 +		if ((b & mask))
  72.429 +			c += 2;
  72.430 +
  72.431 +		if (c == 0)
  72.432 +			continue;
  72.433 +
  72.434 +		int xxx = xx+x;
  72.435 +		if (flipx)
  72.436 +			xxx = (7-xx+x);
  72.437 +
  72.438 +		if (xxx < 0 || xxx > 159)
  72.439 +			continue;
  72.440 +
  72.441 +		u16 color = gbLineBuffer[xxx];
  72.442 +
  72.443 +		if (prio)
  72.444 +		{
  72.445 +			if (color < 0x200 && ((color & 0xFF) != 0))
  72.446 +				continue;
  72.447 +		}
  72.448 +		if (color >= 0x300 && color != 0x300)
  72.449 +			continue;
  72.450 +		else if (color >= 0x200 && color < 0x300)
  72.451 +		{
  72.452 +			int sprite = color & 0xff;
  72.453 +
  72.454 +			int spriteX = gbMemory[0xfe00 + 4 * sprite + 1] - 8;
  72.455 +
  72.456 +			if (spriteX == x)
  72.457 +			{
  72.458 +				if (sprite < spriteNumber)
  72.459 +					continue;
  72.460 +			}
  72.461 +			else
  72.462 +			{
  72.463 +				if (gbCgbMode)
  72.464 +				{
  72.465 +					if (sprite < spriteNumber)
  72.466 +						continue;
  72.467 +				}
  72.468 +				else
  72.469 +				{
  72.470 +					if (spriteX < x+8)
  72.471 +						continue;
  72.472 +				}
  72.473 +			}
  72.474 +		}
  72.475 +
  72.476 +		gbLineBuffer[xxx] = 0x200 + spriteNumber;
  72.477 +
  72.478 +		// make sure that sprites will work even in CGB mode
  72.479 +		if (gbCgbMode)
  72.480 +		{
  72.481 +			c = c + (flags & 0x07)*4 + 32;
  72.482 +		}
  72.483 +		else
  72.484 +		{
  72.485 +			c = pal[c];
  72.486 +
  72.487 +			if (gbSgbMode && !gbCgbMode)
  72.488 +			{
  72.489 +				int dx = xxx >> 3;
  72.490 +				int dy = y >> 3;
  72.491 +
  72.492 +				int palette = gbSgbATF[dy * 20 + dx];
  72.493 +
  72.494 +				if (c == 0)
  72.495 +					palette = 0;
  72.496 +
  72.497 +				c = c + 4*palette;
  72.498 +			}
  72.499 +			else
  72.500 +			{
  72.501 +				c += 4;
  72.502 +			}
  72.503 +		}
  72.504 +
  72.505 +		gbLineMix[xxx] = gbColorOption ? gbColorFilter[gbPalette[c]] :
  72.506 +		                 gbPalette[c];
  72.507 +	}
  72.508 +}
  72.509 +
  72.510 +void gbDrawSprites()
  72.511 +{
  72.512 +	int x     = 0;
  72.513 +	int y     = 0;
  72.514 +	int count = 0;
  72.515 +
  72.516 +	int size = (register_LCDC & 4);
  72.517 +
  72.518 +	if (!(register_LCDC & 0x80))
  72.519 +		return;
  72.520 +
  72.521 +	if ((register_LCDC & 2) && (layerSettings & 0x1000))
  72.522 +	{
  72.523 +		int yc = register_LY;
  72.524 +
  72.525 +		int address = 0xfe00;
  72.526 +		for (int i = 0; i < 40; i++)
  72.527 +		{
  72.528 +			y = gbMemory[address++];
  72.529 +			x = gbMemory[address++];
  72.530 +			int tile = gbMemory[address++];
  72.531 +			if (size)
  72.532 +				tile &= 254;
  72.533 +			int flags = gbMemory[address++];
  72.534 +
  72.535 +			if (x > 0 && y > 0 && x < 168 && y < 160)
  72.536 +			{
  72.537 +				// check if sprite intersects current line
  72.538 +				int t = yc -y + 16;
  72.539 +				if (size && t >= 0 && t < 16)
  72.540 +				{
  72.541 +					gbDrawSpriteTile(tile, x-8, yc, t, flags, size, i);
  72.542 +					count++;
  72.543 +				}
  72.544 +				else if (!size && t >= 0 && t < 8)
  72.545 +				{
  72.546 +					gbDrawSpriteTile(tile, x-8, yc, t, flags, size, i);
  72.547 +					count++;
  72.548 +				}
  72.549 +			}
  72.550 +			// sprite limit reached!
  72.551 +			if (count >= 10)
  72.552 +				break;
  72.553 +		}
  72.554 +	}
  72.555 +}
    73.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    73.2 +++ b/src/gb/gbGlobals.cpp	Sat Mar 03 10:31:27 2012 -0600
    73.3 @@ -0,0 +1,39 @@
    73.4 +#include "../Port.h"
    73.5 +#include "GB.h"
    73.6 +
    73.7 +u8 *gbMemoryMap[16];
    73.8 +
    73.9 +int32 gbRomSizeMask = 0;
   73.10 +int32 gbRomSize     = 0;
   73.11 +int32 gbRamSizeMask = 0;
   73.12 +int32 gbRamSize     = 0;
   73.13 +
   73.14 +u8 * gbMemory     = NULL;
   73.15 +u8 * gbVram       = NULL;
   73.16 +u8 * gbRom        = NULL;
   73.17 +u8 * gbRam        = NULL;
   73.18 +u8 * gbWram       = NULL;
   73.19 +u16 *gbLineBuffer = NULL;
   73.20 +
   73.21 +u16   gbPalette[128];
   73.22 +u8    gbBgp[4] = { 0, 1, 2, 3};
   73.23 +u8    gbObp0[4] = { 0, 1, 2, 3};
   73.24 +u8    gbObp1[4] = { 0, 1, 2, 3};
   73.25 +int32 gbWindowLine = -1;
   73.26 +
   73.27 +int32 gbCgbMode = 0;
   73.28 +
   73.29 +u16   gbColorFilter[32768];
   73.30 +int32 gbColorOption      = 0;
   73.31 +int32 gbPaletteOption    = 0;
   73.32 +int32 gbEmulatorType     = 0;
   73.33 +int32 gbBorderOn         = 1;
   73.34 +int32 gbBorderAutomatic  = 0;
   73.35 +int32 gbBorderLineSkip   = 160;
   73.36 +int32 gbBorderRowSkip    = 0;
   73.37 +int32 gbBorderColumnSkip = 0;
   73.38 +int32 gbDmaTicks         = 0;
   73.39 +bool8 gbNullInputHackEnabled	 = false;
   73.40 +bool8 gbNullInputHackTempEnabled = false;
   73.41 +
   73.42 +u8 (*gbSerialFunction)(u8) = NULL;
    74.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    74.2 +++ b/src/gb/gbGlobals.h	Sat Mar 03 10:31:27 2012 -0600
    74.3 @@ -0,0 +1,95 @@
    74.4 +#ifndef VBA_GB_GLOBALS_H
    74.5 +#define VBA_GB_GLOBALS_H
    74.6 +
    74.7 +#if _MSC_VER > 1000
    74.8 +#pragma once
    74.9 +#endif // _MSC_VER > 1000
   74.10 +
   74.11 +#include "../Port.h"
   74.12 +
   74.13 +extern int32 gbRomSizeMask;
   74.14 +extern int32 gbRomSize;
   74.15 +extern int32 gbRamSize;
   74.16 +extern int32 gbRamSizeMask;
   74.17 +
   74.18 +extern u8 * gbRom;
   74.19 +extern u8 * gbRam;
   74.20 +extern u8 * gbVram;
   74.21 +extern u8 * gbWram;
   74.22 +extern u8 * gbMemory;
   74.23 +extern u16 *gbLineBuffer;
   74.24 +
   74.25 +extern u8 *gbMemoryMap[16];
   74.26 +
   74.27 +inline u8 gbReadMemoryQuick(u16 address)
   74.28 +{
   74.29 +	extern int32 gbEchoRAMFixOn;
   74.30 +	if (gbEchoRAMFixOn)
   74.31 +	{
   74.32 +		if (address >= 0xe000 && address < 0xfe00)
   74.33 +		{
   74.34 +			address -= 0x2000;
   74.35 +		}
   74.36 +	}
   74.37 +	return gbMemoryMap[address>>12][address&0xfff];
   74.38 +}
   74.39 +
   74.40 +inline void gbWriteMemoryQuick(u16 address, u8 value)
   74.41 +{
   74.42 +	extern int32 gbEchoRAMFixOn;
   74.43 +	if (gbEchoRAMFixOn)
   74.44 +	{
   74.45 +		if (address >= 0xe000 && address < 0xfe00)
   74.46 +		{
   74.47 +			address -= 0x2000;
   74.48 +		}
   74.49 +	}
   74.50 +	gbMemoryMap[address>>12][address&0xfff] = value;
   74.51 +}
   74.52 +
   74.53 +inline u8 gbReadROMQuick(u32 address)
   74.54 +{
   74.55 +	return gbRom[address];
   74.56 +}
   74.57 +
   74.58 +extern int32 gbFrameSkip;
   74.59 +extern u16   gbColorFilter[32768];
   74.60 +extern int32 gbColorOption;
   74.61 +extern int32 gbPaletteOption;
   74.62 +extern int32 gbEmulatorType;
   74.63 +extern int32 gbBorderOn;
   74.64 +extern int32 gbBorderAutomatic;
   74.65 +extern int32 gbCgbMode;
   74.66 +extern int32 gbSgbMode;
   74.67 +extern int32 gbWindowLine;
   74.68 +extern int32 gbSpeed;
   74.69 +extern u8    gbBgp[4];
   74.70 +extern u8    gbObp0[4];
   74.71 +extern u8    gbObp1[4];
   74.72 +extern u16   gbPalette[128];
   74.73 +
   74.74 +extern u8 register_LCDC;
   74.75 +extern u8 register_LY;
   74.76 +extern u8 register_SCY;
   74.77 +extern u8 register_SCX;
   74.78 +extern u8 register_WY;
   74.79 +extern u8 register_WX;
   74.80 +extern u8 register_VBK;
   74.81 +
   74.82 +extern int emulating;
   74.83 +
   74.84 +extern int32 gbBorderLineSkip;
   74.85 +extern int32 gbBorderRowSkip;
   74.86 +extern int32 gbBorderColumnSkip;
   74.87 +extern int32 gbDmaTicks;
   74.88 +
   74.89 +extern bool8 useOldFrameTiming;
   74.90 +extern bool8 gbNullInputHackEnabled;
   74.91 +extern bool8 gbNullInputHackTempEnabled;
   74.92 +
   74.93 +extern void gbRenderLine();
   74.94 +extern void gbDrawSprites();
   74.95 +
   74.96 +extern u8 (*gbSerialFunction)(u8);
   74.97 +
   74.98 +#endif // VBA_GB_GLOBALS_H
    75.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    75.2 +++ b/src/gb/gbMemory.cpp	Sat Mar 03 10:31:27 2012 -0600
    75.3 @@ -0,0 +1,1070 @@
    75.4 +#include "gbGlobals.h"
    75.5 +#include "gbMemory.h"
    75.6 +#include "../common/System.h"
    75.7 +#include "../common/movie.h"
    75.8 +
    75.9 +mapperMBC1 gbDataMBC1 = {
   75.10 +	0, // RAM enable
   75.11 +	1, // ROM bank
   75.12 +	0, // RAM bank
   75.13 +	0, // memory model
   75.14 +	0, // ROM high address
   75.15 +	0 // RAM address
   75.16 +};
   75.17 +
   75.18 +// MBC1 ROM write registers
   75.19 +void mapperMBC1ROM(u16 address, u8 value)
   75.20 +{
   75.21 +	int tmpAddress = 0;
   75.22 +
   75.23 +	switch (address & 0x6000)
   75.24 +	{
   75.25 +	case 0x0000: // RAM enable register
   75.26 +		gbDataMBC1.mapperRAMEnable = ((value & 0x0a) == 0x0a ? 1 : 0);
   75.27 +		break;
   75.28 +	case 0x2000: // ROM bank select
   75.29 +		//    value = value & 0x1f;
   75.30 +		if (value == 0)
   75.31 +			value = 1;
   75.32 +		if (value == gbDataMBC1.mapperROMBank)
   75.33 +			break;
   75.34 +
   75.35 +		tmpAddress = value << 14;
   75.36 +
   75.37 +		// check current model
   75.38 +		if (gbDataMBC1.mapperMemoryModel == 0)
   75.39 +		{
   75.40 +			// model is 16/8, so we have a high address in use
   75.41 +			tmpAddress |= (gbDataMBC1.mapperROMHighAddress) << 19;
   75.42 +		}
   75.43 +
   75.44 +		tmpAddress &= gbRomSizeMask;
   75.45 +		gbDataMBC1.mapperROMBank = value;
   75.46 +		gbMemoryMap[0x04]        = &gbRom[tmpAddress];
   75.47 +		gbMemoryMap[0x05]        = &gbRom[tmpAddress + 0x1000];
   75.48 +		gbMemoryMap[0x06]        = &gbRom[tmpAddress + 0x2000];
   75.49 +		gbMemoryMap[0x07]        = &gbRom[tmpAddress + 0x3000];
   75.50 +		break;
   75.51 +	case 0x4000: // RAM bank select
   75.52 +		if (gbDataMBC1.mapperMemoryModel == 1)
   75.53 +		{
   75.54 +			// 4/32 model, RAM bank switching provided
   75.55 +			value = value & 0x03;
   75.56 +			if (value == gbDataMBC1.mapperRAMBank)
   75.57 +				break;
   75.58 +			tmpAddress                  = value << 13;
   75.59 +			tmpAddress                 &= gbRamSizeMask;
   75.60 +			gbMemoryMap[0x0a]           = &gbRam[tmpAddress];
   75.61 +			gbMemoryMap[0x0b]           = &gbRam[tmpAddress + 0x1000];
   75.62 +			gbDataMBC1.mapperRAMBank    = value;
   75.63 +			gbDataMBC1.mapperRAMAddress = tmpAddress;
   75.64 +		}
   75.65 +		else
   75.66 +		{
   75.67 +			// 16/8, set the high address
   75.68 +			gbDataMBC1.mapperROMHighAddress = value & 0x03;
   75.69 +			tmpAddress        = gbDataMBC1.mapperROMBank << 14;
   75.70 +			tmpAddress       |= (gbDataMBC1.mapperROMHighAddress) << 19;
   75.71 +			tmpAddress       &= gbRomSizeMask;
   75.72 +			gbMemoryMap[0x04] = &gbRom[tmpAddress];
   75.73 +			gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
   75.74 +			gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
   75.75 +			gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
   75.76 +		}
   75.77 +		break;
   75.78 +	case 0x6000: // memory model select
   75.79 +		gbDataMBC1.mapperMemoryModel = value & 1;
   75.80 +		break;
   75.81 +	}
   75.82 +}
   75.83 +
   75.84 +// MBC1 RAM write
   75.85 +void mapperMBC1RAM(u16 address, u8 value)
   75.86 +{
   75.87 +	if (gbDataMBC1.mapperRAMEnable)
   75.88 +	{
   75.89 +		if (gbRamSize)
   75.90 +		{
   75.91 +			gbWriteMemoryQuick(address, value);
   75.92 +			systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
   75.93 +		}
   75.94 +	}
   75.95 +}
   75.96 +
   75.97 +void memoryUpdateMapMBC1()
   75.98 +{
   75.99 +	int tmpAddress = gbDataMBC1.mapperROMBank << 14;
  75.100 +
  75.101 +	// check current model
  75.102 +	if (gbDataMBC1.mapperMemoryModel == 1)
  75.103 +	{
  75.104 +		// model is 16/8, so we have a high address in use
  75.105 +		tmpAddress |= (gbDataMBC1.mapperROMHighAddress) << 19;
  75.106 +	}
  75.107 +
  75.108 +	tmpAddress       &= gbRomSizeMask;
  75.109 +	gbMemoryMap[0x04] = &gbRom[tmpAddress];
  75.110 +	gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
  75.111 +	gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
  75.112 +	gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
  75.113 +
  75.114 +	if (gbRamSize)
  75.115 +	{
  75.116 +		gbMemoryMap[0x0a] = &gbRam[gbDataMBC1.mapperRAMAddress];
  75.117 +		gbMemoryMap[0x0b] = &gbRam[gbDataMBC1.mapperRAMAddress + 0x1000];
  75.118 +	}
  75.119 +}
  75.120 +
  75.121 +mapperMBC2 gbDataMBC2 = {
  75.122 +	0, // RAM enable
  75.123 +	1 // ROM bank
  75.124 +};
  75.125 +
  75.126 +// MBC2 ROM write registers
  75.127 +void mapperMBC2ROM(u16 address, u8 value)
  75.128 +{
  75.129 +	switch (address & 0x6000)
  75.130 +	{
  75.131 +	case 0x0000: // RAM enable
  75.132 +		if (!(address & 0x0100))
  75.133 +		{
  75.134 +			gbDataMBC2.mapperRAMEnable = (value & 0x0f) == 0x0a;
  75.135 +		}
  75.136 +		break;
  75.137 +	case 0x2000: // ROM bank select
  75.138 +		if (address & 0x0100)
  75.139 +		{
  75.140 +			value &= 0x0f;
  75.141 +
  75.142 +			if (value == 0)
  75.143 +				value = 1;
  75.144 +			if (gbDataMBC2.mapperROMBank != value)
  75.145 +			{
  75.146 +				gbDataMBC2.mapperROMBank = value;
  75.147 +
  75.148 +				int tmpAddress = value << 14;
  75.149 +
  75.150 +				tmpAddress &= gbRomSizeMask;
  75.151 +
  75.152 +				gbMemoryMap[0x04] = &gbRom[tmpAddress];
  75.153 +				gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
  75.154 +				gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
  75.155 +				gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
  75.156 +			}
  75.157 +		}
  75.158 +		break;
  75.159 +	}
  75.160 +}
  75.161 +
  75.162 +// MBC2 RAM write
  75.163 +void mapperMBC2RAM(u16 address, u8 value)
  75.164 +{
  75.165 +	if (gbDataMBC2.mapperRAMEnable)
  75.166 +	{
  75.167 +		if (gbRamSize && address < 0xa200)
  75.168 +		{
  75.169 +			gbWriteMemoryQuick(address, value);
  75.170 +			systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
  75.171 +		}
  75.172 +	}
  75.173 +}
  75.174 +
  75.175 +void memoryUpdateMapMBC2()
  75.176 +{
  75.177 +	int tmpAddress = gbDataMBC2.mapperROMBank << 14;
  75.178 +
  75.179 +	tmpAddress &= gbRomSizeMask;
  75.180 +
  75.181 +	gbMemoryMap[0x04] = &gbRom[tmpAddress];
  75.182 +	gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
  75.183 +	gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
  75.184 +	gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
  75.185 +}
  75.186 +
  75.187 +mapperMBC3 gbDataMBC3 = {
  75.188 +	0, // RAM enable
  75.189 +	1, // ROM bank
  75.190 +	0, // RAM bank
  75.191 +	0, // RAM address
  75.192 +	0, // timer clock latch
  75.193 +	0, // timer clock register
  75.194 +	0, // timer seconds
  75.195 +	0, // timer minutes
  75.196 +	0, // timer hours
  75.197 +	0, // timer days
  75.198 +	0, // timer control
  75.199 +	0, // timer latched seconds
  75.200 +	0, // timer latched minutes
  75.201 +	0, // timer latched hours
  75.202 +	0, // timer latched days
  75.203 +	0, // timer latched control
  75.204 +	(time_t)-1 // last time
  75.205 +};
  75.206 +
  75.207 +void memoryUpdateMBC3Clock()
  75.208 +{
  75.209 +	time_t now;
  75.210 +
  75.211 +	if (VBAMovieActive() || VBAMovieLoading())
  75.212 +		now = (time_t)(VBAMovieGetId() + VBAMovieGetFrameCounter()/60); /// FIXME: is /60 the right factor?
  75.213 +	else
  75.214 +		now = time(NULL);
  75.215 +
  75.216 +	time_t diff = now - gbDataMBC3.mapperLastTime;
  75.217 +	if (diff > 0)
  75.218 +	{
  75.219 +		// update the clock according to the last update time
  75.220 +		gbDataMBC3.mapperSeconds += (int)(diff % 60);
  75.221 +		if (gbDataMBC3.mapperSeconds > 59)
  75.222 +		{
  75.223 +			gbDataMBC3.mapperSeconds -= 60;
  75.224 +			gbDataMBC3.mapperMinutes++;
  75.225 +		}
  75.226 +
  75.227 +		diff /= 60;
  75.228 +
  75.229 +		gbDataMBC3.mapperMinutes += (int)(diff % 60);
  75.230 +		if (gbDataMBC3.mapperMinutes > 60)
  75.231 +		{
  75.232 +			gbDataMBC3.mapperMinutes -= 60;
  75.233 +			gbDataMBC3.mapperHours++;
  75.234 +		}
  75.235 +
  75.236 +		diff /= 60;
  75.237 +
  75.238 +		gbDataMBC3.mapperHours += (int)(diff % 24);
  75.239 +		if (gbDataMBC3.mapperHours > 24)
  75.240 +		{
  75.241 +			gbDataMBC3.mapperHours -= 24;
  75.242 +			gbDataMBC3.mapperDays++;
  75.243 +		}
  75.244 +		diff /= 24;
  75.245 +
  75.246 +		gbDataMBC3.mapperDays += (int)diff;
  75.247 +		if (gbDataMBC3.mapperDays > 255)
  75.248 +		{
  75.249 +			if (gbDataMBC3.mapperDays > 511)
  75.250 +			{
  75.251 +				gbDataMBC3.mapperDays    %= 512;
  75.252 +				gbDataMBC3.mapperControl |= 0x80;
  75.253 +			}
  75.254 +			gbDataMBC3.mapperControl = (gbDataMBC3.mapperControl & 0xfe) |
  75.255 +			                           (gbDataMBC3.mapperDays > 255 ? 1 : 0);
  75.256 +		}
  75.257 +	}
  75.258 +	gbDataMBC3.mapperLastTime = now;
  75.259 +}
  75.260 +
  75.261 +// MBC3 ROM write registers
  75.262 +void mapperMBC3ROM(u16 address, u8 value)
  75.263 +{
  75.264 +	int tmpAddress = 0;
  75.265 +
  75.266 +	switch (address & 0x6000)
  75.267 +	{
  75.268 +	case 0x0000: // RAM enable register
  75.269 +		gbDataMBC3.mapperRAMEnable = ((value & 0x0a) == 0x0a ? 1 : 0);
  75.270 +		break;
  75.271 +	case 0x2000: // ROM bank select
  75.272 +		value = value & 0x7f;
  75.273 +		if (value == 0)
  75.274 +			value = 1;
  75.275 +		if (value == gbDataMBC3.mapperROMBank)
  75.276 +			break;
  75.277 +
  75.278 +		tmpAddress = value << 14;
  75.279 +
  75.280 +		tmpAddress &= gbRomSizeMask;
  75.281 +		gbDataMBC3.mapperROMBank = value;
  75.282 +		gbMemoryMap[0x04]        = &gbRom[tmpAddress];
  75.283 +		gbMemoryMap[0x05]        = &gbRom[tmpAddress + 0x1000];
  75.284 +		gbMemoryMap[0x06]        = &gbRom[tmpAddress + 0x2000];
  75.285 +		gbMemoryMap[0x07]        = &gbRom[tmpAddress + 0x3000];
  75.286 +
  75.287 +		break;
  75.288 +	case 0x4000: // RAM bank select
  75.289 +		if (value < 8)
  75.290 +		{
  75.291 +			if (value == gbDataMBC3.mapperRAMBank)
  75.292 +				break;
  75.293 +			tmpAddress                  = value << 13;
  75.294 +			tmpAddress                 &= gbRamSizeMask;
  75.295 +			gbMemoryMap[0x0a]           = &gbRam[tmpAddress];
  75.296 +			gbMemoryMap[0x0b]           = &gbRam[tmpAddress + 0x1000];
  75.297 +			gbDataMBC3.mapperRAMBank    = value;
  75.298 +			gbDataMBC3.mapperRAMAddress = tmpAddress;
  75.299 +		}
  75.300 +		else
  75.301 +		{
  75.302 +			if (gbDataMBC3.mapperRAMEnable)
  75.303 +			{
  75.304 +				gbDataMBC3.mapperRAMBank = -1;
  75.305 +
  75.306 +				gbDataMBC3.mapperClockRegister = value;
  75.307 +			}
  75.308 +		}
  75.309 +		break;
  75.310 +	case 0x6000: // clock latch
  75.311 +		if (gbDataMBC3.mapperClockLatch == 0 && value == 1)
  75.312 +		{
  75.313 +			memoryUpdateMBC3Clock();
  75.314 +			gbDataMBC3.mapperLSeconds = gbDataMBC3.mapperSeconds;
  75.315 +			gbDataMBC3.mapperLMinutes = gbDataMBC3.mapperMinutes;
  75.316 +			gbDataMBC3.mapperLHours   = gbDataMBC3.mapperHours;
  75.317 +			gbDataMBC3.mapperLDays    = gbDataMBC3.mapperDays;
  75.318 +			gbDataMBC3.mapperLControl = gbDataMBC3.mapperControl;
  75.319 +		}
  75.320 +		if (value == 0x00 || value == 0x01)
  75.321 +			gbDataMBC3.mapperClockLatch = value;
  75.322 +		break;
  75.323 +	}
  75.324 +}
  75.325 +
  75.326 +// MBC3 RAM write
  75.327 +void mapperMBC3RAM(u16 address, u8 value)
  75.328 +{
  75.329 +	if (gbDataMBC3.mapperRAMEnable)
  75.330 +	{
  75.331 +		if (gbDataMBC3.mapperRAMBank != -1)
  75.332 +		{
  75.333 +			if (gbRamSize)
  75.334 +			{
  75.335 +				gbWriteMemoryQuick(address, value);
  75.336 +				systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
  75.337 +			}
  75.338 +		}
  75.339 +		else
  75.340 +		{
  75.341 +			time_t tmp; //Small kludge to get it working on some 64 bit systems.
  75.342 +			if (VBAMovieActive() || VBAMovieLoading())
  75.343 +				gbDataMBC3.mapperLastTime = VBAMovieGetId() + VBAMovieGetFrameCounter()/60;
  75.344 +			else {
  75.345 +				time(&tmp);
  75.346 +				gbDataMBC3.mapperLastTime=(u32)tmp;
  75.347 +			}
  75.348 +			systemScreenMessage(ctime(&tmp), 4);
  75.349 +			gbDataMBC3.mapperLastTime=(u32)tmp;
  75.350 +
  75.351 +			switch (gbDataMBC3.mapperClockRegister)
  75.352 +			{
  75.353 +			case 0x08:
  75.354 +				gbDataMBC3.mapperSeconds = value;
  75.355 +				break;
  75.356 +			case 0x09:
  75.357 +				gbDataMBC3.mapperMinutes = value;
  75.358 +				break;
  75.359 +			case 0x0a:
  75.360 +				gbDataMBC3.mapperHours = value;
  75.361 +				break;
  75.362 +			case 0x0b:
  75.363 +				gbDataMBC3.mapperDays = value;
  75.364 +				break;
  75.365 +			case 0x0c:
  75.366 +				if (gbDataMBC3.mapperControl & 0x80)
  75.367 +					gbDataMBC3.mapperControl = 0x80 | value;
  75.368 +				else
  75.369 +					gbDataMBC3.mapperControl = value;
  75.370 +				break;
  75.371 +			}
  75.372 +		}
  75.373 +	}
  75.374 +}
  75.375 +
  75.376 +// MBC3 read RAM
  75.377 +u8 mapperMBC3ReadRAM(u16 address)
  75.378 +{
  75.379 +	if (gbDataMBC3.mapperRAMEnable)
  75.380 +	{
  75.381 +		if (gbDataMBC3.mapperRAMBank != -1)
  75.382 +		{
  75.383 +			return gbReadMemoryQuick(address);
  75.384 +		}
  75.385 +
  75.386 +		switch (gbDataMBC3.mapperClockRegister)
  75.387 +		{
  75.388 +		case 0x08:
  75.389 +			return gbDataMBC3.mapperLSeconds;
  75.390 +			break;
  75.391 +		case 0x09:
  75.392 +			return gbDataMBC3.mapperLMinutes;
  75.393 +			break;
  75.394 +		case 0x0a:
  75.395 +			return gbDataMBC3.mapperLHours;
  75.396 +			break;
  75.397 +		case 0x0b:
  75.398 +			return gbDataMBC3.mapperLDays;
  75.399 +			break;
  75.400 +		case 0x0c:
  75.401 +			return gbDataMBC3.mapperLControl;
  75.402 +		}
  75.403 +	}
  75.404 +	return 0;
  75.405 +}
  75.406 +
  75.407 +void memoryUpdateMapMBC3()
  75.408 +{
  75.409 +	int tmpAddress = gbDataMBC3.mapperROMBank << 14;
  75.410 +
  75.411 +	tmpAddress &= gbRomSizeMask;
  75.412 +
  75.413 +	gbMemoryMap[0x04] = &gbRom[tmpAddress];
  75.414 +	gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
  75.415 +	gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
  75.416 +	gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
  75.417 +
  75.418 +	if (gbDataMBC3.mapperRAMBank >= 0 && gbRamSize)
  75.419 +	{
  75.420 +		tmpAddress        = gbDataMBC3.mapperRAMBank << 13;
  75.421 +		tmpAddress       &= gbRamSizeMask;
  75.422 +		gbMemoryMap[0x0a] = &gbRam[tmpAddress];
  75.423 +		gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000];
  75.424 +	}
  75.425 +}
  75.426 +
  75.427 +mapperMBC5 gbDataMBC5 = {
  75.428 +	0, // RAM enable
  75.429 +	1, // ROM bank
  75.430 +	0, // RAM bank
  75.431 +	0, // ROM high address
  75.432 +	0, // RAM address
  75.433 +	0 // is rumble cartridge?
  75.434 +};
  75.435 +
  75.436 +// MBC5 ROM write registers
  75.437 +void mapperMBC5ROM(u16 address, u8 value)
  75.438 +{
  75.439 +	int tmpAddress = 0;
  75.440 +
  75.441 +	switch (address & 0x6000)
  75.442 +	{
  75.443 +	case 0x0000: // RAM enable register
  75.444 +		gbDataMBC5.mapperRAMEnable = ((value & 0x0a) == 0x0a ? 1 : 0);
  75.445 +		break;
  75.446 +	case 0x2000: // ROM bank select
  75.447 +		if (address < 0x3000)
  75.448 +		{
  75.449 +			value = value & 0xff;
  75.450 +			if (value == gbDataMBC5.mapperROMBank)
  75.451 +				break;
  75.452 +
  75.453 +			tmpAddress = (value << 14) | (gbDataMBC5.mapperROMHighAddress << 22) ;
  75.454 +
  75.455 +			tmpAddress &= gbRomSizeMask;
  75.456 +			gbDataMBC5.mapperROMBank = value;
  75.457 +			gbMemoryMap[0x04]        = &gbRom[tmpAddress];
  75.458 +			gbMemoryMap[0x05]        = &gbRom[tmpAddress + 0x1000];
  75.459 +			gbMemoryMap[0x06]        = &gbRom[tmpAddress + 0x2000];
  75.460 +			gbMemoryMap[0x07]        = &gbRom[tmpAddress + 0x3000];
  75.461 +		}
  75.462 +		else
  75.463 +		{
  75.464 +			value = value & 1;
  75.465 +			if (value == gbDataMBC5.mapperROMHighAddress)
  75.466 +				break;
  75.467 +
  75.468 +			tmpAddress = (gbDataMBC5.mapperROMBank << 14) | (value << 22);
  75.469 +
  75.470 +			tmpAddress &= gbRomSizeMask;
  75.471 +			gbDataMBC5.mapperROMHighAddress = value;
  75.472 +			gbMemoryMap[0x04] = &gbRom[tmpAddress];
  75.473 +			gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
  75.474 +			gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
  75.475 +			gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
  75.476 +		}
  75.477 +		break;
  75.478 +	case 0x4000: // RAM bank select
  75.479 +		if (gbDataMBC5.isRumbleCartridge)
  75.480 +			value &= 0x07;
  75.481 +		else
  75.482 +			value &= 0x0f;
  75.483 +		if (value == gbDataMBC5.mapperRAMBank)
  75.484 +			break;
  75.485 +		tmpAddress  = value << 13;
  75.486 +		tmpAddress &= gbRamSizeMask;
  75.487 +		if (gbRamSize)
  75.488 +		{
  75.489 +			gbMemoryMap[0x0a] = &gbRam[tmpAddress];
  75.490 +			gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000];
  75.491 +
  75.492 +			gbDataMBC5.mapperRAMBank    = value;
  75.493 +			gbDataMBC5.mapperRAMAddress = tmpAddress;
  75.494 +		}
  75.495 +		break;
  75.496 +	}
  75.497 +}
  75.498 +
  75.499 +// MBC5 RAM write
  75.500 +void mapperMBC5RAM(u16 address, u8 value)
  75.501 +{
  75.502 +	if (gbDataMBC5.mapperRAMEnable)
  75.503 +	{
  75.504 +		if (gbRamSize)
  75.505 +		{
  75.506 +			gbWriteMemoryQuick(address, value);
  75.507 +			systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
  75.508 +		}
  75.509 +	}
  75.510 +}
  75.511 +
  75.512 +void memoryUpdateMapMBC5()
  75.513 +{
  75.514 +	int tmpAddress = (gbDataMBC5.mapperROMBank << 14) |
  75.515 +	                 (gbDataMBC5.mapperROMHighAddress << 22) ;
  75.516 +
  75.517 +	tmpAddress       &= gbRomSizeMask;
  75.518 +	gbMemoryMap[0x04] = &gbRom[tmpAddress];
  75.519 +	gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
  75.520 +	gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
  75.521 +	gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
  75.522 +
  75.523 +	if (gbRamSize)
  75.524 +	{
  75.525 +		tmpAddress        = gbDataMBC5.mapperRAMBank << 13;
  75.526 +		tmpAddress       &= gbRamSizeMask;
  75.527 +		gbMemoryMap[0x0a] = &gbRam[tmpAddress];
  75.528 +		gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000];
  75.529 +	}
  75.530 +}
  75.531 +
  75.532 +mapperMBC7 gbDataMBC7 = {
  75.533 +	0, // RAM enable
  75.534 +	1, // ROM bank
  75.535 +	0, // RAM bank
  75.536 +	0, // RAM address
  75.537 +	0, // chip select
  75.538 +	0, // ??
  75.539 +	0, // mapper state
  75.540 +	0, // buffer for receiving serial data
  75.541 +	0, // idle state
  75.542 +	0, // count of bits received
  75.543 +	0, // command received
  75.544 +	0, // address received
  75.545 +	0, // write enable
  75.546 +	0, // value to return on ram
  75.547 +};
  75.548 +
  75.549 +// MBC7 ROM write registers
  75.550 +void mapperMBC7ROM(u16 address, u8 value)
  75.551 +{
  75.552 +	int tmpAddress = 0;
  75.553 +
  75.554 +	switch (address & 0x6000)
  75.555 +	{
  75.556 +	case 0x0000:
  75.557 +		break;
  75.558 +	case 0x2000: // ROM bank select
  75.559 +		value = value & 0x7f;
  75.560 +		if (value == 0)
  75.561 +			value = 1;
  75.562 +
  75.563 +		if (value == gbDataMBC7.mapperROMBank)
  75.564 +			break;
  75.565 +
  75.566 +		tmpAddress = (value << 14);
  75.567 +
  75.568 +		tmpAddress &= gbRomSizeMask;
  75.569 +		gbDataMBC7.mapperROMBank = value;
  75.570 +		gbMemoryMap[0x04]        = &gbRom[tmpAddress];
  75.571 +		gbMemoryMap[0x05]        = &gbRom[tmpAddress + 0x1000];
  75.572 +		gbMemoryMap[0x06]        = &gbRom[tmpAddress + 0x2000];
  75.573 +		gbMemoryMap[0x07]        = &gbRom[tmpAddress + 0x3000];
  75.574 +		break;
  75.575 +	case 0x4000: // RAM bank select/enable
  75.576 +		if (value < 8)
  75.577 +		{
  75.578 +			tmpAddress        = (value&3) << 13;
  75.579 +			tmpAddress       &= gbRamSizeMask;
  75.580 +			gbMemoryMap[0x0a] = &gbMemory[0xa000];
  75.581 +			gbMemoryMap[0x0b] = &gbMemory[0xb000];
  75.582 +
  75.583 +			gbDataMBC7.mapperRAMBank    = value;
  75.584 +			gbDataMBC7.mapperRAMAddress = tmpAddress;
  75.585 +			gbDataMBC7.mapperRAMEnable  = 0;
  75.586 +		}
  75.587 +		else
  75.588 +		{
  75.589 +			gbDataMBC7.mapperRAMEnable = 0;
  75.590 +		}
  75.591 +		break;
  75.592 +	}
  75.593 +}
  75.594 +
  75.595 +// MBC7 read RAM
  75.596 +u8 mapperMBC7ReadRAM(u16 address)
  75.597 +{
  75.598 +	switch (address & 0xa0f0)
  75.599 +	{
  75.600 +	case 0xa000:
  75.601 +	case 0xa010:
  75.602 +	case 0xa060:
  75.603 +	case 0xa070:
  75.604 +		return 0;
  75.605 +	case 0xa020:
  75.606 +		// sensor X low byte
  75.607 +		return systemGetSensorX() & 255;
  75.608 +	case 0xa030:
  75.609 +		// sensor X high byte
  75.610 +		return systemGetSensorX() >> 8;
  75.611 +	case 0xa040:
  75.612 +		// sensor Y low byte
  75.613 +		return systemGetSensorY() & 255;
  75.614 +	case 0xa050:
  75.615 +		// sensor Y high byte
  75.616 +		return systemGetSensorY() >> 8;
  75.617 +	case 0xa080:
  75.618 +		return gbDataMBC7.value;
  75.619 +	}
  75.620 +	return 0xff;
  75.621 +}
  75.622 +
  75.623 +// MBC7 RAM write
  75.624 +void mapperMBC7RAM(u16 address, u8 value)
  75.625 +{
  75.626 +	if (address == 0xa080)
  75.627 +	{
  75.628 +		// special processing needed
  75.629 +		int oldCs = gbDataMBC7.cs, oldSk = gbDataMBC7.sk;
  75.630 +
  75.631 +		gbDataMBC7.cs = value>>7;
  75.632 +		gbDataMBC7.sk = (value>>6)&1;
  75.633 +
  75.634 +		if (!oldCs && gbDataMBC7.cs)
  75.635 +		{
  75.636 +			if (gbDataMBC7.state == 5)
  75.637 +			{
  75.638 +				if (gbDataMBC7.writeEnable)
  75.639 +				{
  75.640 +					gbWriteMemoryQuick(0xa000+gbDataMBC7.address*2, gbDataMBC7.buffer>>8);
  75.641 +					gbWriteMemoryQuick(0xa000+gbDataMBC7.address*2+1, gbDataMBC7.buffer&0xff);
  75.642 +					systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
  75.643 +				}
  75.644 +				gbDataMBC7.state = 0;
  75.645 +				gbDataMBC7.value = 1;
  75.646 +			}
  75.647 +			else
  75.648 +			{
  75.649 +				gbDataMBC7.idle  = true;
  75.650 +				gbDataMBC7.state = 0;
  75.651 +			}
  75.652 +		}
  75.653 +
  75.654 +		if (!oldSk && gbDataMBC7.sk)
  75.655 +		{
  75.656 +			if (gbDataMBC7.idle)
  75.657 +			{
  75.658 +				if (value & 0x02)
  75.659 +				{
  75.660 +					gbDataMBC7.idle  = false;
  75.661 +					gbDataMBC7.count = 0;
  75.662 +					gbDataMBC7.state = 1;
  75.663 +				}
  75.664 +			}
  75.665 +			else
  75.666 +			{
  75.667 +				switch (gbDataMBC7.state)
  75.668 +				{
  75.669 +				case 1:
  75.670 +					// receiving command
  75.671 +					gbDataMBC7.buffer <<= 1;
  75.672 +					gbDataMBC7.buffer  |= (value & 0x02) ? 1 : 0;
  75.673 +					gbDataMBC7.count++;
  75.674 +					if (gbDataMBC7.count == 2)
  75.675 +					{
  75.676 +						// finished receiving command
  75.677 +						gbDataMBC7.state = 2;
  75.678 +						gbDataMBC7.count = 0;
  75.679 +						gbDataMBC7.code  = gbDataMBC7.buffer & 3;
  75.680 +					}
  75.681 +					break;
  75.682 +				case 2:
  75.683 +					// receive address
  75.684 +					gbDataMBC7.buffer <<= 1;
  75.685 +					gbDataMBC7.buffer  |= (value&0x02) ? 1 : 0;
  75.686 +					gbDataMBC7.count++;
  75.687 +					if (gbDataMBC7.count == 8)
  75.688 +					{
  75.689 +						// finish receiving
  75.690 +						gbDataMBC7.state   = 3;
  75.691 +						gbDataMBC7.count   = 0;
  75.692 +						gbDataMBC7.address = gbDataMBC7.buffer&0xff;
  75.693 +						if (gbDataMBC7.code == 0)
  75.694 +						{
  75.695 +							if ((gbDataMBC7.address>>6) == 0)
  75.696 +							{
  75.697 +								gbDataMBC7.writeEnable = 0;
  75.698 +								gbDataMBC7.state       = 0;
  75.699 +							}
  75.700 +							else if ((gbDataMBC7.address>>6) == 3)
  75.701 +							{
  75.702 +								gbDataMBC7.writeEnable = 1;
  75.703 +								gbDataMBC7.state       = 0;
  75.704 +							}
  75.705 +						}
  75.706 +					}
  75.707 +					break;
  75.708 +				case 3:
  75.709 +					gbDataMBC7.buffer <<= 1;
  75.710 +					gbDataMBC7.buffer  |= (value&0x02) ? 1 : 0;
  75.711 +					gbDataMBC7.count++;
  75.712 +
  75.713 +					switch (gbDataMBC7.code)
  75.714 +					{
  75.715 +					case 0:
  75.716 +						if (gbDataMBC7.count == 16)
  75.717 +						{
  75.718 +							if ((gbDataMBC7.address>>6) == 0)
  75.719 +							{
  75.720 +								gbDataMBC7.writeEnable = 0;
  75.721 +								gbDataMBC7.state       = 0;
  75.722 +							}
  75.723 +							else if ((gbDataMBC7.address>>6) == 1)
  75.724 +							{
  75.725 +								if (gbDataMBC7.writeEnable)
  75.726 +								{
  75.727 +									for (int i = 0; i < 256; i++)
  75.728 +									{
  75.729 +										gbWriteMemoryQuick(0xa000+i*2, gbDataMBC7.buffer >> 8);
  75.730 +										gbWriteMemoryQuick(0xa000+i*2+1, gbDataMBC7.buffer & 0xff);
  75.731 +										systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
  75.732 +									}
  75.733 +								}
  75.734 +								gbDataMBC7.state = 5;
  75.735 +							}
  75.736 +							else if ((gbDataMBC7.address>>6) == 2)
  75.737 +							{
  75.738 +								if (gbDataMBC7.writeEnable)
  75.739 +								{
  75.740 +									for (int i = 0; i < 256; i++)
  75.741 +										WRITE16LE((u16 *)&gbMemory[0xa000+i*2], 0xffff);
  75.742 +									systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
  75.743 +								}
  75.744 +								gbDataMBC7.state = 5;
  75.745 +							}
  75.746 +							else if ((gbDataMBC7.address>>6) == 3)
  75.747 +							{
  75.748 +								gbDataMBC7.writeEnable = 1;
  75.749 +								gbDataMBC7.state       = 0;
  75.750 +							}
  75.751 +							gbDataMBC7.count = 0;
  75.752 +						}
  75.753 +						break;
  75.754 +					case 1:
  75.755 +						if (gbDataMBC7.count == 16)
  75.756 +						{
  75.757 +							gbDataMBC7.count = 0;
  75.758 +							gbDataMBC7.state = 5;
  75.759 +							gbDataMBC7.value = 0;
  75.760 +						}
  75.761 +						break;
  75.762 +					case 2:
  75.763 +						if (gbDataMBC7.count == 1)
  75.764 +						{
  75.765 +							gbDataMBC7.state  = 4;
  75.766 +							gbDataMBC7.count  = 0;
  75.767 +							gbDataMBC7.buffer = (gbReadMemoryQuick(0xa000+gbDataMBC7.address*2)<<8)|
  75.768 +							                    (gbReadMemoryQuick(0xa000+gbDataMBC7.address*2+1));
  75.769 +						}
  75.770 +						break;
  75.771 +					case 3:
  75.772 +						if (gbDataMBC7.count == 16)
  75.773 +						{
  75.774 +							gbDataMBC7.count  = 0;
  75.775 +							gbDataMBC7.state  = 5;
  75.776 +							gbDataMBC7.value  = 0;
  75.777 +							gbDataMBC7.buffer = 0xffff;
  75.778 +						}
  75.779 +						break;
  75.780 +					}
  75.781 +					break;
  75.782 +				}
  75.783 +			}
  75.784 +		}
  75.785 +
  75.786 +		if (oldSk && !gbDataMBC7.sk)
  75.787 +		{
  75.788 +			if (gbDataMBC7.state == 4)
  75.789 +			{
  75.790 +				gbDataMBC7.value    = (gbDataMBC7.buffer & 0x8000) ? 1 : 0;
  75.791 +				gbDataMBC7.buffer <<= 1;
  75.792 +				gbDataMBC7.count++;
  75.793 +				if (gbDataMBC7.count == 16)
  75.794 +				{
  75.795 +					gbDataMBC7.count = 0;
  75.796 +					gbDataMBC7.state = 0;
  75.797 +				}
  75.798 +			}
  75.799 +		}
  75.800 +	}
  75.801 +}
  75.802 +
  75.803 +void memoryUpdateMapMBC7()
  75.804 +{
  75.805 +	int tmpAddress = (gbDataMBC5.mapperROMBank << 14);
  75.806 +
  75.807 +	tmpAddress       &= gbRomSizeMask;
  75.808 +	gbMemoryMap[0x04] = &gbRom[tmpAddress];
  75.809 +	gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
  75.810 +	gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
  75.811 +	gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
  75.812 +}
  75.813 +
  75.814 +mapperHuC1 gbDataHuC1 = {
  75.815 +	0, // RAM enable
  75.816 +	1, // ROM bank
  75.817 +	0, // RAM bank
  75.818 +	0, // memory model
  75.819 +	0, // ROM high address
  75.820 +	0 // RAM address
  75.821 +};
  75.822 +
  75.823 +// HuC1 ROM write registers
  75.824 +void mapperHuC1ROM(u16 address, u8 value)
  75.825 +{
  75.826 +	int tmpAddress = 0;
  75.827 +
  75.828 +	switch (address & 0x6000)
  75.829 +	{
  75.830 +	case 0x0000: // RAM enable register
  75.831 +		gbDataHuC1.mapperRAMEnable = ((value & 0x0a) == 0x0a ? 1 : 0);
  75.832 +		break;
  75.833 +	case 0x2000: // ROM bank select
  75.834 +		value = value & 0x3f;
  75.835 +		if (value == 0)
  75.836 +			value = 1;
  75.837 +		if (value == gbDataHuC1.mapperROMBank)
  75.838 +			break;
  75.839 +
  75.840 +		tmpAddress = value << 14;
  75.841 +
  75.842 +		tmpAddress &= gbRomSizeMask;
  75.843 +		gbDataHuC1.mapperROMBank = value;
  75.844 +		gbMemoryMap[0x04]        = &gbRom[tmpAddress];
  75.845 +		gbMemoryMap[0x05]        = &gbRom[tmpAddress + 0x1000];
  75.846 +		gbMemoryMap[0x06]        = &gbRom[tmpAddress + 0x2000];
  75.847 +		gbMemoryMap[0x07]        = &gbRom[tmpAddress + 0x3000];
  75.848 +		break;
  75.849 +	case 0x4000: // RAM bank select
  75.850 +		if (gbDataHuC1.mapperMemoryModel == 1)
  75.851 +		{
  75.852 +			// 4/32 model, RAM bank switching provided
  75.853 +			value = value & 0x03;
  75.854 +			if (value == gbDataHuC1.mapperRAMBank)
  75.855 +				break;
  75.856 +			tmpAddress                  = value << 13;
  75.857 +			tmpAddress                 &= gbRamSizeMask;
  75.858 +			gbMemoryMap[0x0a]           = &gbRam[tmpAddress];
  75.859 +			gbMemoryMap[0x0b]           = &gbRam[tmpAddress + 0x1000];
  75.860 +			gbDataHuC1.mapperRAMBank    = value;
  75.861 +			gbDataHuC1.mapperRAMAddress = tmpAddress;
  75.862 +		}
  75.863 +		else
  75.864 +		{
  75.865 +			// 16/8, set the high address
  75.866 +			gbDataHuC1.mapperROMHighAddress = value & 0x03;
  75.867 +			tmpAddress        = gbDataHuC1.mapperROMBank << 14;
  75.868 +			tmpAddress       |= (gbDataHuC1.mapperROMHighAddress) << 19;
  75.869 +			tmpAddress       &= gbRomSizeMask;
  75.870 +			gbMemoryMap[0x04] = &gbRom[tmpAddress];
  75.871 +			gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
  75.872 +			gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
  75.873 +			gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
  75.874 +		}
  75.875 +		break;
  75.876 +	case 0x6000: // memory model select
  75.877 +		gbDataHuC1.mapperMemoryModel = value & 1;
  75.878 +		break;
  75.879 +	}
  75.880 +}
  75.881 +
  75.882 +// HuC1 RAM write
  75.883 +void mapperHuC1RAM(u16 address, u8 value)
  75.884 +{
  75.885 +	if (gbDataHuC1.mapperRAMEnable)
  75.886 +	{
  75.887 +		if (gbRamSize)
  75.888 +		{
  75.889 +			gbWriteMemoryQuick(address, value);
  75.890 +			systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
  75.891 +		}
  75.892 +	}
  75.893 +}
  75.894 +
  75.895 +void memoryUpdateMapHuC1()
  75.896 +{
  75.897 +	int tmpAddress = gbDataHuC1.mapperROMBank << 14;
  75.898 +
  75.899 +	tmpAddress &= gbRomSizeMask;
  75.900 +
  75.901 +	gbMemoryMap[0x04] = &gbRom[tmpAddress];
  75.902 +	gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
  75.903 +	gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
  75.904 +	gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
  75.905 +
  75.906 +	if (gbRamSize)
  75.907 +	{
  75.908 +		tmpAddress        = gbDataHuC1.mapperRAMBank << 13;
  75.909 +		tmpAddress       &= gbRamSizeMask;
  75.910 +		gbMemoryMap[0x0a] = &gbRam[tmpAddress];
  75.911 +		gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000];
  75.912 +	}
  75.913 +}
  75.914 +
  75.915 +mapperHuC3 gbDataHuC3 = {
  75.916 +	0, // RAM enable
  75.917 +	1, // ROM bank
  75.918 +	0, // RAM bank
  75.919 +	0, // RAM address
  75.920 +	0, // RAM flag
  75.921 +	0 // RAM read value
  75.922 +};
  75.923 +
  75.924 +// HuC3 ROM write registers
  75.925 +void mapperHuC3ROM(u16 address, u8 value)
  75.926 +{
  75.927 +	int tmpAddress = 0;
  75.928 +
  75.929 +	switch (address & 0x6000)
  75.930 +	{
  75.931 +	case 0x0000: // RAM enable register
  75.932 +		gbDataHuC3.mapperRAMEnable = (value == 0x0a ? 1 : 0);
  75.933 +		gbDataHuC3.mapperRAMFlag   = value;
  75.934 +		if (gbDataHuC3.mapperRAMFlag != 0x0a)
  75.935 +			gbDataHuC3.mapperRAMBank = -1;
  75.936 +		break;
  75.937 +	case 0x2000: // ROM bank select
  75.938 +		value = value & 0x7f;
  75.939 +		if (value == 0)
  75.940 +			value = 1;
  75.941 +		if (value == gbDataHuC3.mapperROMBank)
  75.942 +			break;
  75.943 +
  75.944 +		tmpAddress = value << 14;
  75.945 +
  75.946 +		tmpAddress &= gbRomSizeMask;
  75.947 +		gbDataHuC3.mapperROMBank = value;
  75.948 +		gbMemoryMap[0x04]        = &gbRom[tmpAddress];
  75.949 +		gbMemoryMap[0x05]        = &gbRom[tmpAddress + 0x1000];
  75.950 +		gbMemoryMap[0x06]        = &gbRom[tmpAddress + 0x2000];
  75.951 +		gbMemoryMap[0x07]        = &gbRom[tmpAddress + 0x3000];
  75.952 +		break;
  75.953 +	case 0x4000: // RAM bank select
  75.954 +		value = value & 0x03;
  75.955 +		if (value == gbDataHuC3.mapperRAMBank)
  75.956 +			break;
  75.957 +		tmpAddress                  = value << 13;
  75.958 +		tmpAddress                 &= gbRamSizeMask;
  75.959 +		gbMemoryMap[0x0a]           = &gbRam[tmpAddress];
  75.960 +		gbMemoryMap[0x0b]           = &gbRam[tmpAddress + 0x1000];
  75.961 +		gbDataHuC3.mapperRAMBank    = value;
  75.962 +		gbDataHuC3.mapperRAMAddress = tmpAddress;
  75.963 +		break;
  75.964 +	case 0x6000: // nothing to do!
  75.965 +		break;
  75.966 +	}
  75.967 +}
  75.968 +
  75.969 +// HuC3 read RAM
  75.970 +u8 mapperHuC3ReadRAM(u16 address)
  75.971 +{
  75.972 +	if (gbDataHuC3.mapperRAMFlag > 0x0b &&
  75.973 +	    gbDataHuC3.mapperRAMFlag < 0x0e)
  75.974 +	{
  75.975 +		if (gbDataHuC3.mapperRAMFlag != 0x0c)
  75.976 +			return 1;
  75.977 +		return gbDataHuC3.mapperRAMValue;
  75.978 +	}
  75.979 +	else
  75.980 +		return gbReadMemoryQuick(address);
  75.981 +}
  75.982 +
  75.983 +// HuC3 RAM write
  75.984 +void mapperHuC3RAM(u16 address, u8 value)
  75.985 +{
  75.986 +	int32 *p;
  75.987 +
  75.988 +	if (gbDataHuC3.mapperRAMFlag < 0x0b ||
  75.989 +	    gbDataHuC3.mapperRAMFlag > 0x0e)
  75.990 +	{
  75.991 +		if (gbDataHuC3.mapperRAMEnable)
  75.992 +		{
  75.993 +			if (gbRamSize)
  75.994 +			{
  75.995 +				gbWriteMemoryQuick(address, value);
  75.996 +				systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
  75.997 +			}
  75.998 +		}
  75.999 +	}
 75.1000 +	else
 75.1001 +	{
 75.1002 +		if (gbDataHuC3.mapperRAMFlag == 0x0b)
 75.1003 +		{
 75.1004 +			if (value == 0x62)
 75.1005 +			{
 75.1006 +				gbDataHuC3.mapperRAMValue = 1;
 75.1007 +			}
 75.1008 +			else
 75.1009 +			{
 75.1010 +				switch (value & 0xf0)
 75.1011 +				{
 75.1012 +				case 0x10:
 75.1013 +					p = &gbDataHuC3.mapperRegister2;
 75.1014 +					gbDataHuC3.mapperRAMValue = *(p+gbDataHuC3.mapperRegister1++);
 75.1015 +					if (gbDataHuC3.mapperRegister1 > 6)
 75.1016 +						gbDataHuC3.mapperRegister1 = 0;
 75.1017 +					break;
 75.1018 +				case 0x30:
 75.1019 +					p = &gbDataHuC3.mapperRegister2;
 75.1020 +					*(p+gbDataHuC3.mapperRegister1++) = value & 0x0f;
 75.1021 +					if (gbDataHuC3.mapperRegister1 > 6)
 75.1022 +						gbDataHuC3.mapperRegister1 = 0;
 75.1023 +					gbDataHuC3.mapperAddress =
 75.1024 +					    (gbDataHuC3.mapperRegister6 << 24) |
 75.1025 +					    (gbDataHuC3.mapperRegister5 << 16) |
 75.1026 +					    (gbDataHuC3.mapperRegister4 <<  8) |
 75.1027 +					    (gbDataHuC3.mapperRegister3 <<  4) |
 75.1028 +					    (gbDataHuC3.mapperRegister2);
 75.1029 +					break;
 75.1030 +				case 0x40:
 75.1031 +					gbDataHuC3.mapperRegister1 = (gbDataHuC3.mapperRegister1 & 0xf0) |
 75.1032 +					                             (value & 0x0f);
 75.1033 +					gbDataHuC3.mapperRegister2 = (gbDataHuC3.mapperAddress & 0x0f);
 75.1034 +					gbDataHuC3.mapperRegister3 = ((gbDataHuC3.mapperAddress>>4)&0x0f);
 75.1035 +					gbDataHuC3.mapperRegister4 = ((gbDataHuC3.mapperAddress>>8)&0x0f);
 75.1036 +					gbDataHuC3.mapperRegister5 = ((gbDataHuC3.mapperAddress>>16)&0x0f);
 75.1037 +					gbDataHuC3.mapperRegister6 = ((gbDataHuC3.mapperAddress>>24)&0x0f);
 75.1038 +					gbDataHuC3.mapperRegister7 = 0;
 75.1039 +					gbDataHuC3.mapperRegister8 = 0;
 75.1040 +					gbDataHuC3.mapperRAMValue  = 0;
 75.1041 +					break;
 75.1042 +				case 0x50:
 75.1043 +					gbDataHuC3.mapperRegister1 = (gbDataHuC3.mapperRegister1 & 0x0f) |
 75.1044 +					                             ((value << 4)&0x0f);
 75.1045 +					break;
 75.1046 +				default:
 75.1047 +					gbDataHuC3.mapperRAMValue = 1;
 75.1048 +					break;
 75.1049 +				}
 75.1050 +			}
 75.1051 +		}
 75.1052 +	}
 75.1053 +}
 75.1054 +
 75.1055 +void memoryUpdateMapHuC3()
 75.1056 +{
 75.1057 +	int tmpAddress = gbDataHuC3.mapperROMBank << 14;
 75.1058 +
 75.1059 +	tmpAddress       &= gbRomSizeMask;
 75.1060 +	gbMemoryMap[0x04] = &gbRom[tmpAddress];
 75.1061 +	gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
 75.1062 +	gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
 75.1063 +	gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
 75.1064 +
 75.1065 +	if (gbRamSize)
 75.1066 +	{
 75.1067 +		tmpAddress        = gbDataHuC3.mapperRAMBank << 13;
 75.1068 +		tmpAddress       &= gbRamSizeMask;
 75.1069 +		gbMemoryMap[0x0a] = &gbRam[tmpAddress];
 75.1070 +		gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000];
 75.1071 +	}
 75.1072 +}
 75.1073 +
    76.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    76.2 +++ b/src/gb/gbMemory.h	Sat Mar 03 10:31:27 2012 -0600
    76.3 @@ -0,0 +1,142 @@
    76.4 +#ifndef VBA_GB_MEMORY_H
    76.5 +#define VBA_GB_MEMORY_H
    76.6 +
    76.7 +#if _MSC_VER > 1000
    76.8 +#pragma once
    76.9 +#endif // _MSC_VER > 1000
   76.10 +
   76.11 +#include "../Port.h"
   76.12 +
   76.13 +struct mapperMBC1
   76.14 +{
   76.15 +	int32 mapperRAMEnable;
   76.16 +	int32 mapperROMBank;
   76.17 +	int32 mapperRAMBank;
   76.18 +	int32 mapperMemoryModel;
   76.19 +	int32 mapperROMHighAddress;
   76.20 +	int32 mapperRAMAddress;
   76.21 +};
   76.22 +
   76.23 +struct mapperMBC2
   76.24 +{
   76.25 +	int32 mapperRAMEnable;
   76.26 +	int32 mapperROMBank;
   76.27 +};
   76.28 +
   76.29 +struct mapperMBC3
   76.30 +{
   76.31 +	int32  mapperRAMEnable;
   76.32 +	int32  mapperROMBank;
   76.33 +	int32  mapperRAMBank;
   76.34 +	int32  mapperRAMAddress;
   76.35 +	int32  mapperClockLatch;
   76.36 +	int32  mapperClockRegister;
   76.37 +	int32  mapperSeconds;
   76.38 +	int32  mapperMinutes;
   76.39 +	int32  mapperHours;
   76.40 +	int32  mapperDays;
   76.41 +	int32  mapperControl;
   76.42 +	int32  mapperLSeconds;
   76.43 +	int32  mapperLMinutes;
   76.44 +	int32  mapperLHours;
   76.45 +	int32  mapperLDays;
   76.46 +	int32  mapperLControl;
   76.47 +	//time_t mapperLastTime;
   76.48 +	u32 mapperLastTime;
   76.49 +};
   76.50 +
   76.51 +struct mapperMBC5
   76.52 +{
   76.53 +	int32 mapperRAMEnable;
   76.54 +	int32 mapperROMBank;
   76.55 +	int32 mapperRAMBank;
   76.56 +	int32 mapperROMHighAddress;
   76.57 +	int32 mapperRAMAddress;
   76.58 +	int32 isRumbleCartridge;
   76.59 +};
   76.60 +
   76.61 +struct mapperMBC7
   76.62 +{
   76.63 +	int32 mapperRAMEnable;
   76.64 +	int32 mapperROMBank;
   76.65 +	int32 mapperRAMBank;
   76.66 +	int32 mapperRAMAddress;
   76.67 +	int32 cs;
   76.68 +	int32 sk;
   76.69 +	int32 state;
   76.70 +	int32 buffer;
   76.71 +	int32 idle;
   76.72 +	int32 count;
   76.73 +	int32 code;
   76.74 +	int32 address;
   76.75 +	int32 writeEnable;
   76.76 +	int32 value;
   76.77 +};
   76.78 +
   76.79 +struct mapperHuC1
   76.80 +{
   76.81 +	int32 mapperRAMEnable;
   76.82 +	int32 mapperROMBank;
   76.83 +	int32 mapperRAMBank;
   76.84 +	int32 mapperMemoryModel;
   76.85 +	int32 mapperROMHighAddress;
   76.86 +	int32 mapperRAMAddress;
   76.87 +};
   76.88 +
   76.89 +struct mapperHuC3
   76.90 +{
   76.91 +	int32 mapperRAMEnable;
   76.92 +	int32 mapperROMBank;
   76.93 +	int32 mapperRAMBank;
   76.94 +	int32 mapperRAMAddress;
   76.95 +	int32 mapperAddress;
   76.96 +	int32 mapperRAMFlag;
   76.97 +	int32 mapperRAMValue;
   76.98 +	int32 mapperRegister1;
   76.99 +	int32 mapperRegister2;
  76.100 +	int32 mapperRegister3;
  76.101 +	int32 mapperRegister4;
  76.102 +	int32 mapperRegister5;
  76.103 +	int32 mapperRegister6;
  76.104 +	int32 mapperRegister7;
  76.105 +	int32 mapperRegister8;
  76.106 +};
  76.107 +
  76.108 +extern mapperMBC1 gbDataMBC1;
  76.109 +extern mapperMBC2 gbDataMBC2;
  76.110 +extern mapperMBC3 gbDataMBC3;
  76.111 +extern mapperMBC5 gbDataMBC5;
  76.112 +extern mapperHuC1 gbDataHuC1;
  76.113 +extern mapperHuC3 gbDataHuC3;
  76.114 +
  76.115 +void mapperMBC1ROM(u16, u8);
  76.116 +void mapperMBC1RAM(u16, u8);
  76.117 +void mapperMBC2ROM(u16, u8);
  76.118 +void mapperMBC2RAM(u16, u8);
  76.119 +void mapperMBC3ROM(u16, u8);
  76.120 +void mapperMBC3RAM(u16, u8);
  76.121 +u8   mapperMBC3ReadRAM(u16);
  76.122 +void mapperMBC5ROM(u16, u8);
  76.123 +void mapperMBC5RAM(u16, u8);
  76.124 +void mapperMBC7ROM(u16, u8);
  76.125 +void mapperMBC7RAM(u16, u8);
  76.126 +u8   mapperMBC7ReadRAM(u16);
  76.127 +void mapperHuC1ROM(u16, u8);
  76.128 +void mapperHuC1RAM(u16, u8);
  76.129 +void mapperHuC3ROM(u16, u8);
  76.130 +void mapperHuC3RAM(u16, u8);
  76.131 +u8   mapperHuC3ReadRAM(u16);
  76.132 +
  76.133 +//extern void (*mapper)(u16,u8);
  76.134 +//extern void (*mapperRAM)(u16,u8);
  76.135 +//extern u8 (*mapperReadRAM)(u16);
  76.136 +
  76.137 +extern void memoryUpdateMapMBC1();
  76.138 +extern void memoryUpdateMapMBC2();
  76.139 +extern void memoryUpdateMapMBC3();
  76.140 +extern void memoryUpdateMapMBC5();
  76.141 +extern void memoryUpdateMapMBC7();
  76.142 +extern void memoryUpdateMapHuC1();
  76.143 +extern void memoryUpdateMapHuC3();
  76.144 +
  76.145 +#endif // VBA_GB_MEMORY
    77.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    77.2 +++ b/src/gb/gbPrinter.cpp	Sat Mar 03 10:31:27 2012 -0600
    77.3 @@ -0,0 +1,234 @@
    77.4 +#include <cstdio>
    77.5 +#include <cstring>
    77.6 +
    77.7 +#include "../common/System.h"
    77.8 +#include "gbPrinter.h"
    77.9 +
   77.10 +u8  gbPrinterStatus = 0;
   77.11 +int gbPrinterState  = 0;
   77.12 +u8  gbPrinterData[0x280*9];
   77.13 +u8  gbPrinterPacket[0x400];
   77.14 +int gbPrinterCount     = 0;
   77.15 +int gbPrinterDataCount = 0;
   77.16 +int gbPrinterDataSize  = 0;
   77.17 +int gbPrinterResult    = 0;
   77.18 +
   77.19 +bool gbPrinterCheckCRC()
   77.20 +{
   77.21 +	u16 crc = 0;
   77.22 +
   77.23 +	for (int i = 2; i < (6+gbPrinterDataSize); i++)
   77.24 +	{
   77.25 +		crc += gbPrinterPacket[i];
   77.26 +	}
   77.27 +
   77.28 +	int msgCrc = gbPrinterPacket[6+gbPrinterDataSize] +
   77.29 +	             (gbPrinterPacket[7+gbPrinterDataSize]<<8);
   77.30 +
   77.31 +	return msgCrc == crc;
   77.32 +}
   77.33 +
   77.34 +void gbPrinterReset()
   77.35 +{
   77.36 +	gbPrinterState     = 0;
   77.37 +	gbPrinterDataSize  = 0;
   77.38 +	gbPrinterDataCount = 0;
   77.39 +	gbPrinterCount     = 0;
   77.40 +	gbPrinterStatus    = 0;
   77.41 +	gbPrinterResult    = 0;
   77.42 +}
   77.43 +
   77.44 +void gbPrinterShowData()
   77.45 +{
   77.46 +	systemGbPrint(gbPrinterData,
   77.47 +	              gbPrinterPacket[6],
   77.48 +	              gbPrinterPacket[7],
   77.49 +	              gbPrinterPacket[8],
   77.50 +	              gbPrinterPacket[9]);
   77.51 +	/*
   77.52 +	   allegro_init();
   77.53 +	   install_keyboard();
   77.54 +	   set_gfx_mode(GFX_AUTODETECT, 160, 144, 0, 0);
   77.55 +	   PALETTE pal;
   77.56 +	   pal[0].r = 255;
   77.57 +	   pal[0].g = 255;
   77.58 +	   pal[0].b = 255;
   77.59 +	   pal[1].r = 168;
   77.60 +	   pal[1].g = 168;
   77.61 +	   pal[1].b = 168;
   77.62 +	   pal[2].r = 96;
   77.63 +	   pal[2].g = 96;
   77.64 +	   pal[2].b = 96;
   77.65 +	   pal[3].r = 0;
   77.66 +	   pal[3].g = 0;
   77.67 +	   pal[3].b = 0;
   77.68 +	   set_palette(pal);
   77.69 +	   acquire_screen();
   77.70 +	   u8 *data = gbPrinterData;
   77.71 +	   for(int y = 0; y < 0x12; y++) {
   77.72 +	   for(int x = 0; x < 0x14; x++) {
   77.73 +	    for(int k = 0; k < 8; k++) {
   77.74 +	      int a = *data++;
   77.75 +	      int b = *data++;
   77.76 +	      for(int j = 0; j < 8; j++) {
   77.77 +	        int mask = 1 << (7-j);
   77.78 +	        int c = 0;
   77.79 +	        if(a & mask)
   77.80 +	          c++;
   77.81 +	        if(b & mask)
   77.82 +	          c+=2;
   77.83 +	        putpixel(screen, x*8+j, y*8+k, c);
   77.84 +	      }
   77.85 +	    }
   77.86 +	   }
   77.87 +	   }
   77.88 +	   release_screen();
   77.89 +	   while(!keypressed()) {
   77.90 +	   }
   77.91 +	 */
   77.92 +}
   77.93 +
   77.94 +void gbPrinterReceiveData()
   77.95 +{
   77.96 +	if (gbPrinterPacket[3]) // compressed
   77.97 +	{
   77.98 +		u8 *data = &gbPrinterPacket[6];
   77.99 +		u8 *dest = &gbPrinterData[gbPrinterDataCount];
  77.100 +		int len  = 0;
  77.101 +		while (len < gbPrinterDataSize)
  77.102 +		{
  77.103 +			u8 control = *data++;
  77.104 +			if (control & 0x80) // repeated data
  77.105 +			{
  77.106 +				control &= 0x7f;
  77.107 +				control += 2;
  77.108 +				memset(dest, *data++, control);
  77.109 +				len  += control;
  77.110 +				dest += control;
  77.111 +			}
  77.112 +			else // raw data
  77.113 +			{
  77.114 +				control++;
  77.115 +				memcpy(dest, data, control);
  77.116 +				dest += control;
  77.117 +				data += control;
  77.118 +				len  += control;
  77.119 +			}
  77.120 +		}
  77.121 +	}
  77.122 +	else
  77.123 +	{
  77.124 +		memcpy(&gbPrinterData[gbPrinterDataCount],
  77.125 +		       &gbPrinterPacket[6],
  77.126 +		       gbPrinterDataSize);
  77.127 +		gbPrinterDataCount += gbPrinterDataSize;
  77.128 +	}
  77.129 +}
  77.130 +
  77.131 +void gbPrinterCommand()
  77.132 +{
  77.133 +	switch (gbPrinterPacket[2])
  77.134 +	{
  77.135 +	case 0x01:
  77.136 +		// reset/initialize packet
  77.137 +		gbPrinterDataCount = 0;
  77.138 +		gbPrinterStatus    = 0;
  77.139 +		break;
  77.140 +	case 0x02:
  77.141 +		// print packet
  77.142 +		gbPrinterShowData();
  77.143 +		break;
  77.144 +	case 0x04:
  77.145 +		// data packet
  77.146 +		gbPrinterReceiveData();
  77.147 +		break;
  77.148 +	case 0x0f:
  77.149 +		// NUL packet
  77.150 +		break;
  77.151 +	}
  77.152 +}
  77.153 +
  77.154 +u8 gbPrinterSend(u8 byte)
  77.155 +{
  77.156 +	switch (gbPrinterState)
  77.157 +	{
  77.158 +	case 0:
  77.159 +		gbPrinterCount = 0;
  77.160 +		// receiving preamble
  77.161 +		if (byte == 0x88)
  77.162 +		{
  77.163 +			gbPrinterPacket[gbPrinterCount++] = byte;
  77.164 +			gbPrinterState++;
  77.165 +		}
  77.166 +		else
  77.167 +		{
  77.168 +			// todo: handle failure
  77.169 +			gbPrinterReset();
  77.170 +		}
  77.171 +		break;
  77.172 +	case 1:
  77.173 +		// receiving preamble
  77.174 +		if (byte == 0x33)
  77.175 +		{
  77.176 +			gbPrinterPacket[gbPrinterCount++] = byte;
  77.177 +			gbPrinterState++;
  77.178 +		}
  77.179 +		else
  77.180 +		{
  77.181 +			// todo: handle failure
  77.182 +			gbPrinterReset();
  77.183 +		}
  77.184 +		break;
  77.185 +	case 2:
  77.186 +		// receiving header
  77.187 +		gbPrinterPacket[gbPrinterCount++] = byte;
  77.188 +		if (gbPrinterCount == 6)
  77.189 +		{
  77.190 +			gbPrinterState++;
  77.191 +			gbPrinterDataSize = gbPrinterPacket[4] + (gbPrinterPacket[5]<<8);
  77.192 +		}
  77.193 +		break;
  77.194 +	case 3:
  77.195 +		// receiving data
  77.196 +		if (gbPrinterDataSize)
  77.197 +		{
  77.198 +			gbPrinterPacket[gbPrinterCount++] = byte;
  77.199 +			if (gbPrinterCount == (6+gbPrinterDataSize))
  77.200 +			{
  77.201 +				gbPrinterState++;
  77.202 +			}
  77.203 +			break;
  77.204 +		}
  77.205 +		gbPrinterState++;
  77.206 +	// intentionally move to next if no data to receive
  77.207 +	case 4:
  77.208 +		// receiving CRC
  77.209 +		gbPrinterPacket[gbPrinterCount++] = byte;
  77.210 +		gbPrinterState++;
  77.211 +		break;
  77.212 +	case 5:
  77.213 +		// receiving CRC-2
  77.214 +		gbPrinterPacket[gbPrinterCount++] = byte;
  77.215 +		if (gbPrinterCheckCRC())
  77.216 +		{
  77.217 +			gbPrinterCommand();
  77.218 +		}
  77.219 +		gbPrinterState++;
  77.220 +		break;
  77.221 +	case 6:
  77.222 +		// receiving dummy 1
  77.223 +		gbPrinterPacket[gbPrinterCount++] = byte;
  77.224 +		gbPrinterResult = 0x81;
  77.225 +		gbPrinterState++;
  77.226 +		break;
  77.227 +	case 7:
  77.228 +		// receiving dummy 2
  77.229 +		gbPrinterPacket[gbPrinterCount++] = byte;
  77.230 +		gbPrinterResult = gbPrinterStatus;
  77.231 +		gbPrinterState  = 0;
  77.232 +		gbPrinterCount  = 0;
  77.233 +		break;
  77.234 +	}
  77.235 +	return gbPrinterResult;
  77.236 +}
  77.237 +
    78.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    78.2 +++ b/src/gb/gbPrinter.h	Sat Mar 03 10:31:27 2012 -0600
    78.3 @@ -0,0 +1,10 @@
    78.4 +#ifndef VBA_GB_PRINTER_H
    78.5 +#define VBA_GB_PRINTER_H
    78.6 +
    78.7 +#if _MSC_VER > 1000
    78.8 +#pragma once
    78.9 +#endif // _MSC_VER > 1000
   78.10 +
   78.11 +extern u8 gbPrinterSend(u8 byte);
   78.12 +
   78.13 +#endif // VBA_GB_PRINTER_H
    79.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    79.2 +++ b/src/gb/gbSGB.cpp	Sat Mar 03 10:31:27 2012 -0600
    79.3 @@ -0,0 +1,997 @@
    79.4 +#include <cstdlib>
    79.5 +#include <cstring>
    79.6 +
    79.7 +#include "../common/System.h"
    79.8 +#include "../common/Util.h"
    79.9 +#include "GB.h"
   79.10 +#include "gbGlobals.h"
   79.11 +#include "../common/movie.h"
   79.12 +
   79.13 +extern u8 * pix;
   79.14 +
   79.15 +#define GBSGB_NONE            0
   79.16 +#define GBSGB_RESET           1
   79.17 +#define GBSGB_PACKET_TRANSMIT 2
   79.18 +
   79.19 +u8 gbSgbBorderChar [32 * 256];
   79.20 +u8 gbSgbBorder [2048];
   79.21 +
   79.22 +int32 gbSgbCGBSupport	   = 0;
   79.23 +int32 gbSgbMask			   = 0;
   79.24 +int32 gbSgbMode			   = 0;
   79.25 +int32 gbSgbPacketState	   = GBSGB_NONE;
   79.26 +int32 gbSgbBit			   = 0;
   79.27 +int32 gbSgbPacketTimeout   = 0;
   79.28 +int32 GBSGB_PACKET_TIMEOUT = 66666;
   79.29 +u8	  gbSgbPacket[16 * 7];
   79.30 +int32 gbSgbPacketNBits		 = 0;
   79.31 +int32 gbSgbPacketByte		 = 0;
   79.32 +int32 gbSgbPacketNumber		 = 0;
   79.33 +int32 gbSgbMultiplayer		 = 0;
   79.34 +int32 gbSgbFourPlayers		 = 0;
   79.35 +u8	  gbSgbNextController	 = 0x0f;
   79.36 +u8	  gbSgbReadingController = 0;
   79.37 +u16	  gbSgbSCPPalette[4 * 512];
   79.38 +u8	  gbSgbATF[20 * 18];
   79.39 +u8	  gbSgbATFList[45 * 20 * 18];
   79.40 +u8	  gbSgbScreenBuffer[4160];
   79.41 +
   79.42 +inline void gbSgbDraw24Bit(u8 *p, u16 v)
   79.43 +{
   79.44 +	*((u32 *) p) = systemColorMap32[v];
   79.45 +}
   79.46 +
   79.47 +inline void gbSgbDraw32Bit(u32 *p, u16 v)
   79.48 +{
   79.49 +	*p = systemColorMap32[v];
   79.50 +}
   79.51 +
   79.52 +inline void gbSgbDraw16Bit(u16 *p, u16 v)
   79.53 +{
   79.54 +	*p = systemColorMap16[v];
   79.55 +}
   79.56 +
   79.57 +void gbSgbReset()
   79.58 +{
   79.59 +	gbSgbPacketTimeout = 0;
   79.60 +	gbSgbCGBSupport	   = 0;
   79.61 +	gbSgbMask			   = 0;
   79.62 +	gbSgbPacketState	   = GBSGB_NONE;
   79.63 +	gbSgbBit			   = 0;
   79.64 +	gbSgbPacketNBits	   = 0;
   79.65 +	gbSgbPacketNumber	   = 0;
   79.66 +	gbSgbMultiplayer	   = 0;
   79.67 +	gbSgbFourPlayers	   = 0;
   79.68 +	gbSgbNextController	   = 0x0f;
   79.69 +	gbSgbReadingController = 0;
   79.70 +
   79.71 +	memset(gbSgbSCPPalette, 0, 512 * 4);
   79.72 +	memset(gbSgbATF, 0, 20 * 18);
   79.73 +	memset(gbSgbATFList, 0, 45 * 20 * 18);
   79.74 +	memset(gbSgbPacket, 0, 16 * 7);
   79.75 +	memset(gbSgbBorderChar, 0, 32 * 256);
   79.76 +	memset(gbSgbBorder, 0, 2048);
   79.77 +
   79.78 +	int i;
   79.79 +	for (i = 1; i < 2048; i += 2)
   79.80 +	{
   79.81 +		gbSgbBorder[i] = 1 << 2;
   79.82 +	}
   79.83 +
   79.84 +	for (i = 0; i < 4; i++)
   79.85 +	{
   79.86 +		gbPalette[i * 4]	 = (0x1f) | (0x1f << 5) | (0x1f << 10);
   79.87 +		gbPalette[i * 4 + 1] = (0x15) | (0x15 << 5) | (0x15 << 10);
   79.88 +		gbPalette[i * 4 + 2] = (0x0c) | (0x0c << 5) | (0x0c << 10);
   79.89 +		gbPalette[i * 4 + 3] = 0;
   79.90 +	}
   79.91 +}
   79.92 +
   79.93 +void gbSgbInit()
   79.94 +{
   79.95 +	gbSgbReset();
   79.96 +}
   79.97 +
   79.98 +void gbSgbShutdown()
   79.99 +{
  79.100 +	memset(gbSgbBorderChar, 0, 32 * 256);
  79.101 +	memset(gbSgbBorder, 0, 2048);
  79.102 +}
  79.103 +
  79.104 +void gbSgbFillScreen(u16 color)
  79.105 +{
  79.106 +	switch (systemColorDepth)
  79.107 +	{
  79.108 +	case 16:
  79.109 +	{
  79.110 +		for (int y = 0; y < 144; y++)
  79.111 +		{
  79.112 +			int yLine = (y + gbBorderRowSkip + 1) * (gbBorderLineSkip + 2) +
  79.113 +			            gbBorderColumnSkip;
  79.114 +			u16 *dest = (u16 *)pix + yLine;
  79.115 +			for (register int x = 0; x < 160; x++)
  79.116 +				gbSgbDraw16Bit(dest++, color);
  79.117 +		}
  79.118 +	}
  79.119 +	break;
  79.120 +	case 24:
  79.121 +	{
  79.122 +		for (int y = 0; y < 144; y++)
  79.123 +		{
  79.124 +			int yLine = (y + gbBorderRowSkip) * gbBorderLineSkip + gbBorderColumnSkip;
  79.125 +			u8 *dest  = (u8 *)pix + yLine * 3;
  79.126 +			for (register int x = 0; x < 160; x++)
  79.127 +			{
  79.128 +				gbSgbDraw24Bit(dest, color);
  79.129 +				dest += 3;
  79.130 +			}
  79.131 +		}
  79.132 +	}
  79.133 +	break;
  79.134 +	case 32:
  79.135 +	{
  79.136 +		for (int y = 0; y < 144; y++)
  79.137 +		{
  79.138 +			int	 yLine = (y + gbBorderRowSkip + 1) * (gbBorderLineSkip + 1) + gbBorderColumnSkip;
  79.139 +			u32 *dest  = (u32 *)pix + yLine;
  79.140 +			for (register int x = 0; x < 160; x++)
  79.141 +			{
  79.142 +				gbSgbDraw32Bit(dest++, color);
  79.143 +			}
  79.144 +		}
  79.145 +	}
  79.146 +	break;
  79.147 +	}
  79.148 +}
  79.149 +
  79.150 +void gbSgbRenderScreenToBuffer()
  79.151 +{
  79.152 +	u16 mapAddress = 0x9800;
  79.153 +
  79.154 +	if (register_LCDC & 0x08)
  79.155 +		mapAddress = 0x9c00;
  79.156 +
  79.157 +	u16 patternAddress = 0x8800;
  79.158 +
  79.159 +	int flag = 1;
  79.160 +
  79.161 +	if (register_LCDC & 0x10)
  79.162 +	{
  79.163 +		patternAddress = 0x8000;
  79.164 +		flag = 0;
  79.165 +	}
  79.166 +
  79.167 +	u8 *toAddress = gbSgbScreenBuffer;
  79.168 +
  79.169 +	for (int i = 0; i < 13; i++)
  79.170 +	{
  79.171 +		for (int j = 0; j < 20; j++)
  79.172 +		{
  79.173 +			int tile = gbReadMemoryQuick(mapAddress);
  79.174 +			mapAddress++;
  79.175 +
  79.176 +			if (flag)
  79.177 +			{
  79.178 +				if (tile > 127)
  79.179 +					tile -= 128;
  79.180 +				else
  79.181 +					tile += 128;
  79.182 +			}
  79.183 +			for (int k = 0; k < 16; k++)
  79.184 +				*toAddress++ = gbReadMemoryQuick(patternAddress + tile * 16 + k);
  79.185 +		}
  79.186 +		mapAddress += 12;
  79.187 +	}
  79.188 +}
  79.189 +
  79.190 +void gbSgbDrawBorderTile(int x, int y, int tile, int attr)
  79.191 +{
  79.192 +	u16 *dest	= (u16 *)pix + ((y + 1) * (256 + 2)) + x;
  79.193 +	u8 * dest8	= (u8 *)pix + ((y * 256) + x) * 3;
  79.194 +	u32 *dest32 = (u32 *)pix + ((y + 1) * 257) + x;
  79.195 +
  79.196 +	u8 *tileAddress	 = &gbSgbBorderChar[tile * 32];
  79.197 +	u8 *tileAddress2 = &gbSgbBorderChar[tile * 32 + 16];
  79.198 +
  79.199 +	u8 l = 8;
  79.200 +
  79.201 +	u8 palette = ((attr >> 2) & 7);
  79.202 +
  79.203 +	if (palette < 4)
  79.204 +		palette += 4;
  79.205 +
  79.206 +	palette *= 16;
  79.207 +
  79.208 +	u8 xx = 0;
  79.209 +	u8 yy = 0;
  79.210 +
  79.211 +	int flipX = attr & 0x40;
  79.212 +	int flipY = attr & 0x80;
  79.213 +
  79.214 +	while (l > 0)
  79.215 +	{
  79.216 +		u8 mask = 0x80;
  79.217 +		u8 a	= *tileAddress++;
  79.218 +		u8 b	= *tileAddress++;
  79.219 +		u8 c	= *tileAddress2++;
  79.220 +		u8 d	= *tileAddress2++;
  79.221 +
  79.222 +		while (mask > 0)
  79.223 +		{
  79.224 +			u8 color = 0;
  79.225 +			if (a & mask)
  79.226 +				color++;
  79.227 +			if (b & mask)
  79.228 +				color += 2;
  79.229 +			if (c & mask)
  79.230 +				color += 4;
  79.231 +			if (d & mask)
  79.232 +				color += 8;
  79.233 +
  79.234 +			u8 xxx = xx;
  79.235 +			u8 yyy = yy;
  79.236 +
  79.237 +			if (flipX)
  79.238 +				xxx = 7 - xx;
  79.239 +			if (flipY)
  79.240 +				yyy = 7 - yy;
  79.241 +
  79.242 +			u8 realx = x + xxx;
  79.243 +			u8 realy = y + yyy;
  79.244 +
  79.245 +			u16 c = gbPalette[palette + color];
  79.246 +			if (!color)
  79.247 +				c = gbPalette[0];
  79.248 +			if ((realy < 40 || realy >= 184) || (realx < 48 || realx >= 208))
  79.249 +			{
  79.250 +				switch (systemColorDepth)
  79.251 +				{
  79.252 +				case 16:
  79.253 +					gbSgbDraw16Bit(dest + yyy * (256 + 2) + xxx, c);
  79.254 +					break;
  79.255 +				case 24:
  79.256 +					gbSgbDraw24Bit(dest8 + (yyy * 256 + xxx) * 3, c);
  79.257 +					break;
  79.258 +				case 32:
  79.259 +					gbSgbDraw32Bit(dest32 + yyy * (256 + 1) + xxx, c);
  79.260 +					break;
  79.261 +				}
  79.262 +			}
  79.263 +
  79.264 +			mask >>= 1;
  79.265 +
  79.266 +			xx++;
  79.267 +		}
  79.268 +		yy++;
  79.269 +		xx = 0;
  79.270 +		l--;
  79.271 +		mask = 0x80;
  79.272 +	}
  79.273 +}
  79.274 +
  79.275 +void gbSgbRenderBorder()
  79.276 +{
  79.277 +	if (gbBorderOn)
  79.278 +	{
  79.279 +		u8 *fromAddress = gbSgbBorder;
  79.280 +
  79.281 +		for (u8 y = 0; y < 28; y++)
  79.282 +		{
  79.283 +			for (u8 x = 0; x < 32; x++)
  79.284 +			{
  79.285 +				u8 tile = *fromAddress++;
  79.286 +				u8 attr = *fromAddress++;
  79.287 +
  79.288 +				gbSgbDrawBorderTile(x * 8, y * 8, tile, attr);
  79.289 +			}
  79.290 +		}
  79.291 +	}
  79.292 +}
  79.293 +
  79.294 +void gbSgbPicture()
  79.295 +{
  79.296 +	gbSgbRenderScreenToBuffer();
  79.297 +
  79.298 +	memcpy(gbSgbBorder, gbSgbScreenBuffer, 2048);
  79.299 +
  79.300 +	u16 *paletteAddr = (u16 *)&gbSgbScreenBuffer[2048];
  79.301 +
  79.302 +	for (int i = 64; i < 128; i++)
  79.303 +	{
  79.304 +		gbPalette[i] = READ16LE(paletteAddr++);
  79.305 +	}
  79.306 +
  79.307 +	gbSgbCGBSupport |= 4;
  79.308 +
  79.309 +	if (gbBorderAutomatic && !gbBorderOn && gbSgbCGBSupport > 4)
  79.310 +	{
  79.311 +		gbBorderOn = 1;
  79.312 +		systemGbBorderOn();
  79.313 +	}
  79.314 +
  79.315 +	if (gbBorderOn && !gbSgbMask)
  79.316 +		gbSgbRenderBorder();
  79.317 +
  79.318 +	if (gbSgbMode && gbCgbMode && gbSgbCGBSupport > 4)
  79.319 +	{
  79.320 +		gbSgbCGBSupport = 0;
  79.321 +		gbSgbMode		= 2;
  79.322 +		gbSgbMask		= 0;
  79.323 +		gbSgbRenderBorder();
  79.324 +		gbReset();
  79.325 +	}
  79.326 +
  79.327 +	if (gbSgbCGBSupport > 4)
  79.328 +		gbSgbCGBSupport = 0;
  79.329 +}
  79.330 +
  79.331 +void gbSgbSetPalette(int a, int b, u16 *p)
  79.332 +{
  79.333 +	u16 bit00 = READ16LE(p++);
  79.334 +	int i;
  79.335 +
  79.336 +	for (i = 1; i < 4; i++)
  79.337 +	{
  79.338 +		gbPalette[a * 4 + i] = READ16LE(p++);
  79.339 +	}
  79.340 +
  79.341 +	for (i = 1; i < 4; i++)
  79.342 +	{
  79.343 +		gbPalette[b * 4 + i] = READ16LE(p++);
  79.344 +	}
  79.345 +
  79.346 +	gbPalette[0] = gbPalette[4] = gbPalette[8] = gbPalette[12] = bit00;
  79.347 +	if (gbBorderOn && !gbSgbMask)
  79.348 +		gbSgbRenderBorder();
  79.349 +}
  79.350 +
  79.351 +void gbSgbScpPalette()
  79.352 +{
  79.353 +	gbSgbRenderScreenToBuffer();
  79.354 +
  79.355 +	u16 *fromAddress = (u16 *)gbSgbScreenBuffer;
  79.356 +
  79.357 +	for (int i = 0; i < 512 * 4; i++)
  79.358 +	{
  79.359 +		gbSgbSCPPalette[i] = READ16LE(fromAddress++);
  79.360 +	}
  79.361 +}
  79.362 +
  79.363 +void gbSgbSetATF(int n)
  79.364 +{
  79.365 +	if (n < 0)
  79.366 +		n = 0;
  79.367 +	if (n > 44)
  79.368 +		n = 44;
  79.369 +	memcpy(gbSgbATF, &gbSgbATFList[n * 20 * 18], 20 * 18);
  79.370 +
  79.371 +	if (gbSgbPacket[1] & 0x40)
  79.372 +	{
  79.373 +		gbSgbMask = 0;
  79.374 +		if (gbBorderOn)
  79.375 +			gbSgbRenderBorder();
  79.376 +	}
  79.377 +}
  79.378 +
  79.379 +void gbSgbSetPalette()
  79.380 +{
  79.381 +	u16 pal = READ16LE((((u16 *)&gbSgbPacket[1]))) & 511;
  79.382 +	memcpy(&gbPalette[0], &gbSgbSCPPalette[pal * 4], 4 * sizeof(u16));
  79.383 +
  79.384 +	pal = READ16LE((((u16 *)&gbSgbPacket[3]))) & 511;
  79.385 +	memcpy(&gbPalette[4], &gbSgbSCPPalette[pal * 4], 4 * sizeof(u16));
  79.386 +
  79.387 +	pal = READ16LE((((u16 *)&gbSgbPacket[5]))) & 511;
  79.388 +	memcpy(&gbPalette[8], &gbSgbSCPPalette[pal * 4], 4 * sizeof(u16));
  79.389 +
  79.390 +	pal = READ16LE((((u16 *)&gbSgbPacket[7]))) & 511;
  79.391 +	memcpy(&gbPalette[12], &gbSgbSCPPalette[pal * 4], 4 * sizeof(u16));
  79.392 +
  79.393 +	u8 atf = gbSgbPacket[9];
  79.394 +
  79.395 +	if (atf & 0x80)
  79.396 +	{
  79.397 +		gbSgbSetATF(atf & 0x3f);
  79.398 +	}
  79.399 +
  79.400 +	if (atf & 0x40)
  79.401 +	{
  79.402 +		gbSgbMask = 0;
  79.403 +		if (gbBorderOn)
  79.404 +			gbSgbRenderBorder();
  79.405 +	}
  79.406 +}
  79.407 +
  79.408 +void gbSgbAttributeBlock()
  79.409 +{
  79.410 +	u8 *fromAddress = &gbSgbPacket[1];
  79.411 +
  79.412 +	u8 nDataSet = *fromAddress++;
  79.413 +	if (nDataSet > 12)
  79.414 +		nDataSet = 12;
  79.415 +	if (nDataSet == 0)
  79.416 +		nDataSet = 1;
  79.417 +
  79.418 +	while (nDataSet)
  79.419 +	{
  79.420 +		u8 controlCode		  = (*fromAddress++) & 7;
  79.421 +		u8 paletteDesignation = (*fromAddress++) & 0x3f;
  79.422 +		u8 startH = (*fromAddress++) & 0x1f;
  79.423 +		u8 startV = (*fromAddress++) & 0x1f;
  79.424 +		u8 endH	  = (*fromAddress++) & 0x1f;
  79.425 +		u8 endV	  = (*fromAddress++) & 0x1f;
  79.426 +
  79.427 +		u8 *toAddress = gbSgbATF;
  79.428 +
  79.429 +		for (u8 y = 0; y < 18; y++)
  79.430 +		{
  79.431 +			for (u8 x = 0; x < 20; x++)
  79.432 +			{
  79.433 +				if (x < startH || y < startV ||
  79.434 +				    x > endH || y > endV)
  79.435 +				{
  79.436 +					// outside
  79.437 +					if (controlCode & 0x04)
  79.438 +						*toAddress = (paletteDesignation >> 4) & 0x03;
  79.439 +				}
  79.440 +				else if (x > startH && x < endH &&
  79.441 +				         y > startV && y < endV)
  79.442 +				{
  79.443 +					// inside
  79.444 +					if (controlCode & 0x01)
  79.445 +						*toAddress = paletteDesignation & 0x03;
  79.446 +				}
  79.447 +				else
  79.448 +				{
  79.449 +					// surrounding line
  79.450 +					if (controlCode & 0x02)
  79.451 +						*toAddress = (paletteDesignation >> 2) & 0x03;
  79.452 +					else if (controlCode == 0x01)
  79.453 +						*toAddress = paletteDesignation & 0x03;
  79.454 +				}
  79.455 +				toAddress++;
  79.456 +			}
  79.457 +		}
  79.458 +		nDataSet--;
  79.459 +	}
  79.460 +}
  79.461 +
  79.462 +void gbSgbSetColumnPalette(u8 col, u8 p)
  79.463 +{
  79.464 +	//  if(col < 0)
  79.465 +	//    col = 0;
  79.466 +	if (col > 19)
  79.467 +		col = 19;
  79.468 +
  79.469 +	p &= 3;
  79.470 +
  79.471 +	u8 *toAddress = &gbSgbATF[col];
  79.472 +
  79.473 +	for (u8 y = 0; y < 18; y++)
  79.474 +	{
  79.475 +		*toAddress = p;
  79.476 +		toAddress += 20;
  79.477 +	}
  79.478 +}
  79.479 +
  79.480 +void gbSgbSetRowPalette(u8 row, u8 p)
  79.481 +{
  79.482 +	//  if(row < 0)
  79.483 +	//    row = 0;
  79.484 +	if (row > 17)
  79.485 +		row = 17;
  79.486 +
  79.487 +	p &= 3;
  79.488 +
  79.489 +	u8 *toAddress = &gbSgbATF[row * 20];
  79.490 +
  79.491 +	for (u8 x = 0; x < 20; x++)
  79.492 +	{
  79.493 +		*toAddress++ = p;
  79.494 +	}
  79.495 +}
  79.496 +
  79.497 +void gbSgbAttributeDivide()
  79.498 +{
  79.499 +	u8 control = gbSgbPacket[1];
  79.500 +	u8 coord   = gbSgbPacket[2];
  79.501 +	u8 colorBR = control & 3;
  79.502 +	u8 colorAL = (control >> 2) & 3;
  79.503 +	u8 colorOL = (control >> 4) & 3;
  79.504 +
  79.505 +	if (control & 0x40)
  79.506 +	{
  79.507 +		if (coord > 17)
  79.508 +			coord = 17;
  79.509 +
  79.510 +		for (u8 i = 0; i < 18; i++)
  79.511 +		{
  79.512 +			if (i < coord)
  79.513 +				gbSgbSetRowPalette(i, colorAL);
  79.514 +			else if (i > coord)
  79.515 +				gbSgbSetRowPalette(i, colorBR);
  79.516 +			else
  79.517 +				gbSgbSetRowPalette(i, colorOL);
  79.518 +		}
  79.519 +	}
  79.520 +	else
  79.521 +	{
  79.522 +		if (coord > 19)
  79.523 +			coord = 19;
  79.524 +
  79.525 +		for (u8 i = 0; i < 20; i++)
  79.526 +		{
  79.527 +			if (i < coord)
  79.528 +				gbSgbSetColumnPalette(i, colorAL);
  79.529 +			else if (i > coord)
  79.530 +				gbSgbSetColumnPalette(i, colorBR);
  79.531 +			else
  79.532 +				gbSgbSetColumnPalette(i, colorOL);
  79.533 +		}
  79.534 +	}
  79.535 +}
  79.536 +
  79.537 +void gbSgbAttributeLine()
  79.538 +{
  79.539 +	u8 *fromAddress = &gbSgbPacket[1];
  79.540 +
  79.541 +	u8 nDataSet = *fromAddress++;
  79.542 +
  79.543 +	if (nDataSet > 0x6e)
  79.544 +		nDataSet = 0x6e;
  79.545 +
  79.546 +	while (nDataSet)
  79.547 +	{
  79.548 +		u8 line = *fromAddress++;
  79.549 +		u8 num	= line & 0x1f;
  79.550 +		u8 pal	= (line >> 5) & 0x03;
  79.551 +		if (line & 0x80)
  79.552 +		{
  79.553 +			if (num > 17)
  79.554 +				num = 17;
  79.555 +			gbSgbSetRowPalette(num, pal);
  79.556 +		}
  79.557 +		else
  79.558 +		{
  79.559 +			if (num > 19)
  79.560 +				num = 19;
  79.561 +			gbSgbSetColumnPalette(num, pal);
  79.562 +		}
  79.563 +		nDataSet--;
  79.564 +	}
  79.565 +}
  79.566 +
  79.567 +void gbSgbAttributeCharacter()
  79.568 +{
  79.569 +	u8	startH	 = gbSgbPacket[1] & 0x1f;
  79.570 +	u8	startV	 = gbSgbPacket[2] & 0x1f;
  79.571 +	int nDataSet = READ16LE(((u16 *)&gbSgbPacket[3]));
  79.572 +	int style	 = gbSgbPacket[5] & 1;
  79.573 +	if (startH > 19)
  79.574 +		startH = 19;
  79.575 +	if (startV > 17)
  79.576 +		startV = 17;
  79.577 +
  79.578 +	u8	s = 6;
  79.579 +	u8 *fromAddress = &gbSgbPacket[6];
  79.580 +	u8	v = *fromAddress++;
  79.581 +
  79.582 +	if (style)
  79.583 +	{
  79.584 +		while (nDataSet)
  79.585 +		{
  79.586 +			u8 p = (v >> s) & 3;
  79.587 +			gbSgbATF[startV * 20 + startH] = p;
  79.588 +			startV++;
  79.589 +			if (startV == 18)
  79.590 +			{
  79.591 +				startV = 0;
  79.592 +				startH++;
  79.593 +				if (startH == 20)
  79.594 +					break;
  79.595 +			}
  79.596 +
  79.597 +			if (s)
  79.598 +				s -= 2;
  79.599 +			else
  79.600 +			{
  79.601 +				s = 6;
  79.602 +				v = *fromAddress++;
  79.603 +				nDataSet--;
  79.604 +			}
  79.605 +		}
  79.606 +	}
  79.607 +	else
  79.608 +	{
  79.609 +		while (nDataSet)
  79.610 +		{
  79.611 +			u8 p = (v >> s) & 3;
  79.612 +			gbSgbATF[startV * 20 + startH] = p;
  79.613 +			startH++;
  79.614 +			if (startH == 20)
  79.615 +			{
  79.616 +				startH = 0;
  79.617 +				startV++;
  79.618 +				if (startV == 18)
  79.619 +					break;
  79.620 +			}
  79.621 +
  79.622 +			if (s)
  79.623 +				s -= 2;
  79.624 +			else
  79.625 +			{
  79.626 +				s = 6;
  79.627 +				v = *fromAddress++;
  79.628 +				nDataSet--;
  79.629 +			}
  79.630 +		}
  79.631 +	}
  79.632 +}
  79.633 +
  79.634 +void gbSgbSetATFList()
  79.635 +{
  79.636 +	gbSgbRenderScreenToBuffer();
  79.637 +
  79.638 +	u8 *fromAddress = gbSgbScreenBuffer;
  79.639 +	u8 *toAddress	= gbSgbATFList;
  79.640 +
  79.641 +	for (int i = 0; i < 45; i++)
  79.642 +	{
  79.643 +		for (int j = 0; j < 90; j++)
  79.644 +		{
  79.645 +			u8 v = *fromAddress++;
  79.646 +			u8 s = 6;
  79.647 +			if (i == 2)
  79.648 +				s = 6;
  79.649 +			for (int k = 0; k < 4; k++)
  79.650 +			{
  79.651 +				*toAddress++ = (v >> s) & 0x03;
  79.652 +				s -= 2;
  79.653 +			}
  79.654 +		}
  79.655 +	}
  79.656 +}
  79.657 +
  79.658 +void gbSgbMaskEnable()
  79.659 +{
  79.660 +	int gbSgbMaskFlag = gbSgbPacket[1] & 3;
  79.661 +
  79.662 +	gbSgbMask = gbSgbMaskFlag;
  79.663 +
  79.664 +	switch (gbSgbMaskFlag)
  79.665 +	{
  79.666 +	case 1:
  79.667 +		break;
  79.668 +	case 2:
  79.669 +		gbSgbFillScreen(0x0000);
  79.670 +		//    memset(&gbPalette[0], 0, 128*sizeof(u16));
  79.671 +		break;
  79.672 +	case 3:
  79.673 +		gbSgbFillScreen(gbPalette[0]);
  79.674 +		break;
  79.675 +	}
  79.676 +	if (!gbSgbMask)
  79.677 +	{
  79.678 +		if (gbBorderOn)
  79.679 +			gbSgbRenderBorder();
  79.680 +	}
  79.681 +}
  79.682 +
  79.683 +void gbSgbChrTransfer()
  79.684 +{
  79.685 +	gbSgbRenderScreenToBuffer();
  79.686 +
  79.687 +	int address = (gbSgbPacket[1] & 1) * (128 * 32);
  79.688 +
  79.689 +	if (gbSgbPacket[1] & 1)
  79.690 +		gbSgbCGBSupport |= 2;
  79.691 +	else
  79.692 +		gbSgbCGBSupport |= 1;
  79.693 +
  79.694 +	memcpy(&gbSgbBorderChar[address], gbSgbScreenBuffer, 128 * 32);
  79.695 +
  79.696 +	if (gbBorderAutomatic && !gbBorderOn && gbSgbCGBSupport > 4)
  79.697 +	{
  79.698 +		gbBorderOn = 1;
  79.699 +		systemGbBorderOn();
  79.700 +	}
  79.701 +
  79.702 +	if (gbBorderOn && !gbSgbMask)
  79.703 +		gbSgbRenderBorder();
  79.704 +
  79.705 +	if (gbSgbMode && gbCgbMode && gbSgbCGBSupport == 7)
  79.706 +	{
  79.707 +		gbSgbCGBSupport = 0;
  79.708 +		gbSgbMode		= 2;
  79.709 +		gbSgbMask		= 0;
  79.710 +		gbSgbRenderBorder();
  79.711 +		gbReset();
  79.712 +	}
  79.713 +
  79.714 +	if (gbSgbCGBSupport > 4)
  79.715 +		gbSgbCGBSupport = 0;
  79.716 +}
  79.717 +
  79.718 +void gbSgbMultiRequest()
  79.719 +{
  79.720 +	if (gbSgbPacket[1] & 1)
  79.721 +	{
  79.722 +		gbSgbMultiplayer = 1;
  79.723 +		if (gbSgbPacket[1] & 2)
  79.724 +			gbSgbFourPlayers = 1;
  79.725 +		else
  79.726 +			gbSgbFourPlayers = 0;
  79.727 +		gbSgbNextController = 0x0e;
  79.728 +	}
  79.729 +	else
  79.730 +	{
  79.731 +		gbSgbFourPlayers	= 0;
  79.732 +		gbSgbMultiplayer	= 0;
  79.733 +		gbSgbNextController = 0x0f;
  79.734 +	}
  79.735 +}
  79.736 +
  79.737 +void gbSgbCommand()
  79.738 +{
  79.739 +	int command = gbSgbPacket[0] >> 3;
  79.740 +	//  int nPacket = gbSgbPacket[0] & 7;
  79.741 +
  79.742 +	switch (command)
  79.743 +	{
  79.744 +	case 0x00:
  79.745 +		gbSgbSetPalette(0, 1, (u16 *)&gbSgbPacket[1]);
  79.746 +		break;
  79.747 +	case 0x01:
  79.748 +		gbSgbSetPalette(2, 3, (u16 *)&gbSgbPacket[1]);
  79.749 +		break;
  79.750 +	case 0x02:
  79.751 +		gbSgbSetPalette(0, 3, (u16 *)&gbSgbPacket[1]);
  79.752 +		break;
  79.753 +	case 0x03:
  79.754 +		gbSgbSetPalette(1, 2, (u16 *)&gbSgbPacket[1]);
  79.755 +		break;
  79.756 +	case 0x04:
  79.757 +		gbSgbAttributeBlock();
  79.758 +		break;
  79.759 +	case 0x05:
  79.760 +		gbSgbAttributeLine();
  79.761 +		break;
  79.762 +	case 0x06:
  79.763 +		gbSgbAttributeDivide();
  79.764 +		break;
  79.765 +	case 0x07:
  79.766 +		gbSgbAttributeCharacter();
  79.767 +		break;
  79.768 +	case 0x0a:
  79.769 +		gbSgbSetPalette();
  79.770 +		break;
  79.771 +	case 0x0b:
  79.772 +		gbSgbScpPalette();
  79.773 +		break;
  79.774 +	case 0x11:
  79.775 +		gbSgbMultiRequest();
  79.776 +		break;
  79.777 +	case 0x13:
  79.778 +		gbSgbChrTransfer();
  79.779 +		break;
  79.780 +	case 0x14:
  79.781 +		gbSgbPicture();
  79.782 +		break;
  79.783 +	case 0x15:
  79.784 +		gbSgbSetATFList();
  79.785 +		break;
  79.786 +	case 0x16:
  79.787 +		gbSgbSetATF(gbSgbPacket[1] & 0x3f);
  79.788 +		break;
  79.789 +	case 0x17:
  79.790 +		gbSgbMaskEnable();
  79.791 +		break;
  79.792 +	}
  79.793 +}
  79.794 +
  79.795 +void gbSgbResetPacketState()
  79.796 +{
  79.797 +	gbSgbPacketState   = GBSGB_NONE;
  79.798 +	gbSgbPacketTimeout = 0;
  79.799 +}
  79.800 +
  79.801 +void gbSgbDoBitTransfer(u8 value)
  79.802 +{
  79.803 +	value = value & 0x30;
  79.804 +	switch (gbSgbPacketState)
  79.805 +	{
  79.806 +	case GBSGB_NONE:
  79.807 +		if (value == 0)
  79.808 +		{
  79.809 +			gbSgbPacketState   = GBSGB_RESET;
  79.810 +			gbSgbPacketTimeout = GBSGB_PACKET_TIMEOUT;
  79.811 +		}
  79.812 +		else if (value == 0x30)
  79.813 +		{
  79.814 +			if (gbSgbMultiplayer)
  79.815 +			{
  79.816 +				if ((gbSgbReadingController & 7) == 7)
  79.817 +				{
  79.818 +					gbSgbReadingController = 0;
  79.819 +					if (gbSgbMultiplayer)
  79.820 +					{
  79.821 +						gbSgbNextController--;
  79.822 +						if (gbSgbFourPlayers)
  79.823 +						{
  79.824 +							if (gbSgbNextController == 0x0b)
  79.825 +								gbSgbNextController = 0x0f;
  79.826 +						}
  79.827 +						else
  79.828 +						{
  79.829 +							if (gbSgbNextController == 0x0d)
  79.830 +								gbSgbNextController = 0x0f;
  79.831 +						}
  79.832 +					}
  79.833 +				}
  79.834 +				else
  79.835 +				{
  79.836 +					gbSgbReadingController &= 3;
  79.837 +				}
  79.838 +			}
  79.839 +			gbSgbPacketTimeout = 0;
  79.840 +		}
  79.841 +		else
  79.842 +		{
  79.843 +			if (value == 0x10)
  79.844 +				gbSgbReadingController |= 0x2;
  79.845 +			else if (value == 0x20)
  79.846 +				gbSgbReadingController |= 0x01;
  79.847 +			gbSgbPacketTimeout = 0;
  79.848 +		}
  79.849 +		gbSgbPacketTimeout = 0;
  79.850 +		break;
  79.851 +	case GBSGB_RESET:
  79.852 +		if (value == 0x30)
  79.853 +		{
  79.854 +			gbSgbPacketState   = GBSGB_PACKET_TRANSMIT;
  79.855 +			gbSgbPacketByte	   = 0;
  79.856 +			gbSgbPacketNBits   = 0;
  79.857 +			gbSgbPacketTimeout = GBSGB_PACKET_TIMEOUT;
  79.858 +		}
  79.859 +		else if (value == 0x00)
  79.860 +		{
  79.861 +			gbSgbPacketTimeout = GBSGB_PACKET_TIMEOUT;
  79.862 +			gbSgbPacketState   = GBSGB_RESET;
  79.863 +		}
  79.864 +		else
  79.865 +		{
  79.866 +			gbSgbPacketState   = GBSGB_NONE;
  79.867 +			gbSgbPacketTimeout = 0;
  79.868 +		}
  79.869 +		break;
  79.870 +	case GBSGB_PACKET_TRANSMIT:
  79.871 +		if (value == 0)
  79.872 +		{
  79.873 +			gbSgbPacketState   = GBSGB_RESET;
  79.874 +			gbSgbPacketTimeout = 0;
  79.875 +		}
  79.876 +		else if (value == 0x30)
  79.877 +		{
  79.878 +			if (gbSgbPacketNBits == 128)
  79.879 +			{
  79.880 +				gbSgbPacketNBits = 0;
  79.881 +				gbSgbPacketByte	 = 0;
  79.882 +				gbSgbPacketNumber++;
  79.883 +				gbSgbPacketTimeout = 0;
  79.884 +				if (gbSgbPacketNumber == (gbSgbPacket[0] & 7))
  79.885 +				{
  79.886 +					gbSgbCommand();
  79.887 +					gbSgbPacketNumber  = 0;
  79.888 +					gbSgbPacketState   = GBSGB_NONE;
  79.889 +					gbSgbPacketTimeout = 0;
  79.890 +				}
  79.891 +			}
  79.892 +			else
  79.893 +			{
  79.894 +				if (gbSgbPacketNBits < 128)
  79.895 +				{
  79.896 +					gbSgbPacket[gbSgbPacketNumber * 16 + gbSgbPacketByte] >>= 1;
  79.897 +					gbSgbPacket[gbSgbPacketNumber * 16 + gbSgbPacketByte]  |= gbSgbBit;
  79.898 +					gbSgbPacketNBits++;
  79.899 +					if (!(gbSgbPacketNBits & 7))
  79.900 +					{
  79.901 +						gbSgbPacketByte++;
  79.902 +					}
  79.903 +					gbSgbPacketTimeout = GBSGB_PACKET_TIMEOUT;
  79.904 +				}
  79.905 +			}
  79.906 +		}
  79.907 +		else
  79.908 +		{
  79.909 +			if (value == 0x20)
  79.910 +				gbSgbBit = 0x00;
  79.911 +			else
  79.912 +				gbSgbBit = 0x80;
  79.913 +			gbSgbPacketTimeout = GBSGB_PACKET_TIMEOUT;
  79.914 +		}
  79.915 +		gbSgbReadingController = 0;
  79.916 +		break;
  79.917 +	default:
  79.918 +		gbSgbPacketState   = GBSGB_NONE;
  79.919 +		gbSgbPacketTimeout = 0;
  79.920 +		break;
  79.921 +	}
  79.922 +}
  79.923 +
  79.924 +variable_desc gbSgbSaveStruct[] = {
  79.925 +	{ &gbSgbMask,			   sizeof(int32) },
  79.926 +	{ &gbSgbPacketState,	   sizeof(int32) },
  79.927 +	{ &gbSgbBit,			   sizeof(int32) },
  79.928 +	{ &gbSgbPacketNBits,	   sizeof(int32) },
  79.929 +	{ &gbSgbPacketByte,		   sizeof(int32) },
  79.930 +	{ &gbSgbPacketNumber,	   sizeof(int32) },
  79.931 +	{ &gbSgbMultiplayer,	   sizeof(int32) },
  79.932 +	{ &gbSgbNextController,	   sizeof(u8)	 },
  79.933 +	{ &gbSgbReadingController, sizeof(u8)	 },
  79.934 +	{ NULL,					   0			 }
  79.935 +};
  79.936 +
  79.937 +variable_desc gbSgbSaveStructV3[] = {
  79.938 +	{ &gbSgbMask,			   sizeof(int32) },
  79.939 +	{ &gbSgbPacketState,	   sizeof(int32) },
  79.940 +	{ &gbSgbBit,			   sizeof(int32) },
  79.941 +	{ &gbSgbPacketNBits,	   sizeof(int32) },
  79.942 +	{ &gbSgbPacketByte,		   sizeof(int32) },
  79.943 +	{ &gbSgbPacketNumber,	   sizeof(int32) },
  79.944 +	{ &gbSgbMultiplayer,	   sizeof(int32) },
  79.945 +	{ &gbSgbNextController,	   sizeof(u8)	 },
  79.946 +	{ &gbSgbReadingController, sizeof(u8)	 },
  79.947 +	{ &gbSgbFourPlayers,	   sizeof(int32) },
  79.948 +	{ NULL,					   0			 }
  79.949 +};
  79.950 +
  79.951 +void gbSgbSaveGame(gzFile gzFile)
  79.952 +{
  79.953 +	utilWriteData(gzFile, gbSgbSaveStructV3);
  79.954 +
  79.955 +	utilGzWrite(gzFile, gbSgbBorder, 2048);
  79.956 +	utilGzWrite(gzFile, gbSgbBorderChar, 32 * 256);
  79.957 +
  79.958 +	utilGzWrite(gzFile, gbSgbPacket, 16 * 7);
  79.959 +
  79.960 +	utilGzWrite(gzFile, gbSgbSCPPalette, 4 * 512 * sizeof(u16));
  79.961 +	utilGzWrite(gzFile, gbSgbATF, 20 * 18);
  79.962 +	utilGzWrite(gzFile, gbSgbATFList, 45 * 20 * 18);
  79.963 +
  79.964 +	utilGzWrite(gzFile, gbSgbScreenBuffer, 4160);
  79.965 +	utilGzWrite(gzFile, &gbSgbMode, sizeof(gbSgbMode));
  79.966 +	utilGzWrite(gzFile, &gbSgbCGBSupport, sizeof(gbSgbCGBSupport));
  79.967 +	utilGzWrite(gzFile, &gbSgbPacketTimeout, sizeof(gbSgbPacketTimeout));
  79.968 +}
  79.969 +
  79.970 +void gbSgbReadGame(gzFile gzFile, int version)
  79.971 +{
  79.972 +	if (version >= 3)
  79.973 +		utilReadData(gzFile, gbSgbSaveStructV3);
  79.974 +	else
  79.975 +	{
  79.976 +		utilReadData(gzFile, gbSgbSaveStruct);
  79.977 +		gbSgbFourPlayers = 0;
  79.978 +	}
  79.979 +
  79.980 +	if (version >= 8)
  79.981 +	{
  79.982 +		utilGzRead(gzFile, gbSgbBorder, 2048);
  79.983 +		utilGzRead(gzFile, gbSgbBorderChar, 32 * 256);
  79.984 +	}
  79.985 +
  79.986 +	utilGzRead(gzFile, gbSgbPacket, 16 * 7);
  79.987 +
  79.988 +	utilGzRead(gzFile, gbSgbSCPPalette, 4 * 512 * sizeof(u16));
  79.989 +	utilGzRead(gzFile, gbSgbATF, 20 * 18);
  79.990 +	utilGzRead(gzFile, gbSgbATFList, 45 * 20 * 18);
  79.991 +
  79.992 +	if (version >= 11)
  79.993 +	{
  79.994 +		utilGzRead(gzFile, gbSgbScreenBuffer, 4160);
  79.995 +		utilGzRead(gzFile, &gbSgbMode, sizeof(gbSgbMode));
  79.996 +		utilGzRead(gzFile, &gbSgbCGBSupport, sizeof(gbSgbCGBSupport));
  79.997 +		utilGzRead(gzFile, &gbSgbPacketTimeout, sizeof(gbSgbPacketTimeout));
  79.998 +	}
  79.999 +}
 79.1000 +
    80.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    80.2 +++ b/src/gb/gbSGB.h	Sat Mar 03 10:31:27 2012 -0600
    80.3 @@ -0,0 +1,30 @@
    80.4 +#ifndef VBA_GB_SGB_H
    80.5 +#define VBA_GB_SGB_H
    80.6 +
    80.7 +#if _MSC_VER > 1000
    80.8 +#pragma once
    80.9 +#endif // _MSC_VER > 1000
   80.10 +
   80.11 +#include "zlib.h"
   80.12 +#include "../Port.h"
   80.13 +
   80.14 +void gbSgbInit();
   80.15 +void gbSgbShutdown();
   80.16 +void gbSgbCommand();
   80.17 +void gbSgbResetPacketState();
   80.18 +void gbSgbReset();
   80.19 +void gbSgbDoBitTransfer(u8);
   80.20 +void gbSgbSaveGame(gzFile);
   80.21 +void gbSgbReadGame(gzFile, int version);
   80.22 +void gbSgbRenderBorder();
   80.23 +
   80.24 +extern u8    gbSgbATF[20*18];
   80.25 +extern int32 gbSgbMode;
   80.26 +extern int32 gbSgbMask;
   80.27 +extern int32 gbSgbMultiplayer;
   80.28 +extern u8    gbSgbNextController;
   80.29 +extern int32 gbSgbPacketTimeout;
   80.30 +extern u8    gbSgbReadingController;
   80.31 +extern int32 gbSgbFourPlayers;
   80.32 +
   80.33 +#endif // VBA_GB_SGB_H
    81.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    81.2 +++ b/src/gb/gbSound.cpp	Sat Mar 03 10:31:27 2012 -0600
    81.3 @@ -0,0 +1,1139 @@
    81.4 +#ifdef WIN32
    81.5 +#   include "../win32/stdafx.h"
    81.6 +#   include "../win32/VBA.h"
    81.7 +#endif
    81.8 +
    81.9 +#include <cstring>
   81.10 +#include <cassert>
   81.11 +
   81.12 +#include "../common/System.h"
   81.13 +#include "../common/Util.h"
   81.14 +//#include "../Blip_Buffer.h"
   81.15 +#include "gbGlobals.h"
   81.16 +#include "gbSound.h"
   81.17 +
   81.18 +#ifndef countof
   81.19 +#define countof(a)  (sizeof(a) / sizeof(a[0]))
   81.20 +#endif
   81.21 +
   81.22 +extern u8	 soundBuffer[6][735];
   81.23 +extern u16	 soundFinalWave[1470];
   81.24 +extern u16	 soundFrameSound[735 * 30 * 2];
   81.25 +extern int32 soundVolume;
   81.26 +
   81.27 +soundtick_t GB_USE_TICKS_AS = 24; // (1048576.0/44100.0); // FIXME: (4194304.0/70224.0)(fps) vs 60.0fps?
   81.28 +
   81.29 +#define SOUND_MAGIC   0x60000000
   81.30 +#define SOUND_MAGIC_2 0x30000000
   81.31 +#define NOISE_MAGIC   (2097152.0 / 44100.0)
   81.32 +
   81.33 +extern int32 speed;
   81.34 +
   81.35 +extern u8 soundWavePattern[4][32];
   81.36 +
   81.37 +extern u32		   soundBufferLen;
   81.38 +extern u32		   soundBufferTotalLen;
   81.39 +extern int32	   soundQuality;
   81.40 +extern int32	   soundPaused;
   81.41 +extern int32	   soundPlay;
   81.42 +extern soundtick_t soundTicks;
   81.43 +extern soundtick_t SOUND_CLOCK_TICKS;
   81.44 +extern u32		   soundNextPosition;
   81.45 +
   81.46 +extern int32 soundLevel1;
   81.47 +extern int32 soundLevel2;
   81.48 +extern int32 soundBalance;
   81.49 +extern int32 soundMasterOn;
   81.50 +extern u32	 soundIndex;
   81.51 +extern u32	 soundBufferIndex;
   81.52 +extern int32 soundFrameSoundWritten;
   81.53 +int32		 soundVIN = 0;
   81.54 +extern int32 soundDebug;
   81.55 +
   81.56 +extern int32 sound1On;
   81.57 +extern int32 sound1ATL;
   81.58 +extern int32 sound1Skip;
   81.59 +extern int32 sound1Index;
   81.60 +extern int32 sound1Continue;
   81.61 +extern int32 sound1EnvelopeVolume;
   81.62 +extern int32 sound1EnvelopeATL;
   81.63 +extern int32 sound1EnvelopeUpDown;
   81.64 +extern int32 sound1EnvelopeATLReload;
   81.65 +extern int32 sound1SweepATL;
   81.66 +extern int32 sound1SweepATLReload;
   81.67 +extern int32 sound1SweepSteps;
   81.68 +extern int32 sound1SweepUpDown;
   81.69 +extern int32 sound1SweepStep;
   81.70 +extern u8 *	 sound1Wave;
   81.71 +
   81.72 +extern int32 sound2On;
   81.73 +extern int32 sound2ATL;
   81.74 +extern int32 sound2Skip;
   81.75 +extern int32 sound2Index;
   81.76 +extern int32 sound2Continue;
   81.77 +extern int32 sound2EnvelopeVolume;
   81.78 +extern int32 sound2EnvelopeATL;
   81.79 +extern int32 sound2EnvelopeUpDown;
   81.80 +extern int32 sound2EnvelopeATLReload;
   81.81 +extern u8 *	 sound2Wave;
   81.82 +
   81.83 +extern int32 sound3On;
   81.84 +extern int32 sound3ATL;
   81.85 +extern int32 sound3Skip;
   81.86 +extern int32 sound3Index;
   81.87 +extern int32 sound3Continue;
   81.88 +extern int32 sound3OutputLevel;
   81.89 +extern int32 sound3Last;
   81.90 +
   81.91 +extern int32 sound4On;
   81.92 +extern int32 sound4Clock;
   81.93 +extern int32 sound4ATL;
   81.94 +extern int32 sound4Skip;
   81.95 +extern int32 sound4Index;
   81.96 +extern int32 sound4ShiftRight;
   81.97 +extern int32 sound4ShiftSkip;
   81.98 +extern int32 sound4ShiftIndex;
   81.99 +extern int32 sound4NSteps;
  81.100 +extern int32 sound4CountDown;
  81.101 +extern int32 sound4Continue;
  81.102 +extern int32 sound4EnvelopeVolume;
  81.103 +extern int32 sound4EnvelopeATL;
  81.104 +extern int32 sound4EnvelopeUpDown;
  81.105 +extern int32 sound4EnvelopeATLReload;
  81.106 +
  81.107 +extern int32 soundEnableFlag;
  81.108 +extern int32 soundMutedFlag;
  81.109 +
  81.110 +extern int32 soundFreqRatio[8];
  81.111 +extern int32 soundShiftClock[16];
  81.112 +
  81.113 +extern s16	 soundFilter[4000];
  81.114 +extern s16	 soundLeft[5];
  81.115 +extern s16	 soundRight[5];
  81.116 +extern int32 soundEchoIndex;
  81.117 +extern bool8 soundEcho;
  81.118 +extern bool8 soundLowPass;
  81.119 +extern bool8 soundReverse;
  81.120 +extern bool8 soundOffFlag;
  81.121 +
  81.122 +bool8 gbDigitalSound = false;
  81.123 +
  81.124 +void gbSoundEvent(register u16 address, register int data)
  81.125 +{
  81.126 +	int freq = 0;
  81.127 +
  81.128 +	gbMemory[address] = data;
  81.129 +
  81.130 +#ifndef FINAL_VERSION
  81.131 +	if (soundDebug)
  81.132 +	{
  81.133 +		// don't translate. debug only
  81.134 +		log("Sound event: %08lx %02x\n", address, data);
  81.135 +	}
  81.136 +#endif
  81.137 +	switch (address)
  81.138 +	{
  81.139 +	case NR10:
  81.140 +		sound1SweepATL	  = sound1SweepATLReload = 344 * ((data >> 4) & 7);
  81.141 +		sound1SweepSteps  = data & 7;
  81.142 +		sound1SweepUpDown = data & 0x08;
  81.143 +		sound1SweepStep	  = 0;
  81.144 +		break;
  81.145 +	case NR11:
  81.146 +		sound1Wave = soundWavePattern[data >> 6];
  81.147 +		sound1ATL  = 172 * (64 - (data & 0x3f));
  81.148 +		break;
  81.149 +	case NR12:
  81.150 +		sound1EnvelopeVolume	= data >> 4;
  81.151 +		sound1EnvelopeUpDown	= data & 0x08;
  81.152 +		sound1EnvelopeATLReload = sound1EnvelopeATL = 689 * (data & 7);
  81.153 +		break;
  81.154 +	case NR13:
  81.155 +		freq	  = (((int)(gbMemory[NR14] & 7)) << 8) | data;
  81.156 +		sound1ATL = 172 * (64 - (gbMemory[NR11] & 0x3f));
  81.157 +		freq	  = 2048 - freq;
  81.158 +		if (freq)
  81.159 +		{
  81.160 +			sound1Skip = SOUND_MAGIC / freq;
  81.161 +		}
  81.162 +		else
  81.163 +			sound1Skip = 0;
  81.164 +		break;
  81.165 +	case NR14:
  81.166 +		freq = (((int)(data & 7) << 8) | gbMemory[NR13]);
  81.167 +		freq = 2048 - freq;
  81.168 +		sound1ATL	   = 172 * (64 - (gbMemory[NR11] & 0x3f));
  81.169 +		sound1Continue = data & 0x40;
  81.170 +		if (freq)
  81.171 +		{
  81.172 +			sound1Skip = SOUND_MAGIC / freq;
  81.173 +		}
  81.174 +		else
  81.175 +			sound1Skip = 0;
  81.176 +		if (data & 0x80)
  81.177 +		{
  81.178 +			gbMemory[NR52]		|= 1;
  81.179 +			sound1EnvelopeVolume = gbMemory[NR12] >> 4;
  81.180 +			sound1EnvelopeUpDown = gbMemory[NR12] & 0x08;
  81.181 +			sound1ATL = 172 * (64 - (gbMemory[NR11] & 0x3f));
  81.182 +			sound1EnvelopeATLReload = sound1EnvelopeATL = 689 * (gbMemory[NR12] & 7);
  81.183 +			sound1SweepATL			= sound1SweepATLReload = 344 * ((gbMemory[NR10] >> 4) & 7);
  81.184 +			sound1SweepSteps		= gbMemory[NR10] & 7;
  81.185 +			sound1SweepUpDown		= gbMemory[NR10] & 0x08;
  81.186 +			sound1SweepStep			= 0;
  81.187 +
  81.188 +			sound1Index = 0;
  81.189 +			sound1On	= 1;
  81.190 +		}
  81.191 +		break;
  81.192 +	case NR21:
  81.193 +		sound2Wave = soundWavePattern[data >> 6];
  81.194 +		sound2ATL  = 172 * (64 - (data & 0x3f));
  81.195 +		break;
  81.196 +	case NR22:
  81.197 +		sound2EnvelopeVolume	= data >> 4;
  81.198 +		sound2EnvelopeUpDown	= data & 0x08;
  81.199 +		sound2EnvelopeATLReload = sound2EnvelopeATL = 689 * (data & 7);
  81.200 +		break;
  81.201 +	case NR23:
  81.202 +		freq	  = (((int)(gbMemory[NR24] & 7)) << 8) | data;
  81.203 +		sound2ATL = 172 * (64 - (gbMemory[NR21] & 0x3f));
  81.204 +		freq	  = 2048 - freq;
  81.205 +		if (freq)
  81.206 +		{
  81.207 +			sound2Skip = SOUND_MAGIC / freq;
  81.208 +		}
  81.209 +		else
  81.210 +			sound2Skip = 0;
  81.211 +		break;
  81.212 +	case NR24:
  81.213 +		freq = (((int)(data & 7) << 8) | gbMemory[NR23]);
  81.214 +		freq = 2048 - freq;
  81.215 +		sound2ATL	   = 172 * (64 - (gbMemory[NR21] & 0x3f));
  81.216 +		sound2Continue = data & 0x40;
  81.217 +		if (freq)
  81.218 +		{
  81.219 +			sound2Skip = SOUND_MAGIC / freq;
  81.220 +		}
  81.221 +		else
  81.222 +			sound2Skip = 0;
  81.223 +		if (data & 0x80)
  81.224 +		{
  81.225 +			gbMemory[NR52]		|= 2;
  81.226 +			sound2EnvelopeVolume = gbMemory[NR22] >> 4;
  81.227 +			sound2EnvelopeUpDown = gbMemory[NR22] & 0x08;
  81.228 +			sound2ATL = 172 * (64 - (gbMemory[NR21] & 0x3f));
  81.229 +			sound2EnvelopeATLReload = sound2EnvelopeATL = 689 * (gbMemory[NR22] & 7);
  81.230 +
  81.231 +			sound2Index = 0;
  81.232 +			sound2On	= 1;
  81.233 +		}
  81.234 +		break;
  81.235 +	case NR30:
  81.236 +		if (!(data & 0x80))
  81.237 +		{
  81.238 +			gbMemory[NR52] &= 0xfb;
  81.239 +			sound3On		= 0;
  81.240 +		}
  81.241 +		break;
  81.242 +	case NR31:
  81.243 +		sound3ATL = 172 * (256 - data);
  81.244 +		break;
  81.245 +	case NR32:
  81.246 +		sound3OutputLevel = (data >> 5) & 3;
  81.247 +		break;
  81.248 +	case NR33:
  81.249 +		freq = 2048 - (((int)(gbMemory[NR34] & 7) << 8) | data);
  81.250 +		if (freq)
  81.251 +		{
  81.252 +			sound3Skip = SOUND_MAGIC_2 / freq;
  81.253 +		}
  81.254 +		else
  81.255 +			sound3Skip = 0;
  81.256 +		break;
  81.257 +	case NR34:
  81.258 +		freq = 2048 - (((data & 7) << 8) | (int)gbMemory[NR33]);
  81.259 +		if (freq)
  81.260 +		{
  81.261 +			sound3Skip = SOUND_MAGIC_2 / freq;
  81.262 +		}
  81.263 +		else
  81.264 +		{
  81.265 +			sound3Skip = 0;
  81.266 +		}
  81.267 +		sound3Continue = data & 0x40;
  81.268 +		if ((data & 0x80) && (gbMemory[NR30] & 0x80))
  81.269 +		{
  81.270 +			gbMemory[NR52] |= 4;
  81.271 +			sound3ATL		= 172 * (256 - gbMemory[NR31]);
  81.272 +			sound3Index		= 0;
  81.273 +			sound3On		= 1;
  81.274 +		}
  81.275 +		break;
  81.276 +	case NR41:
  81.277 +		sound4ATL = 172 * (64 - (data & 0x3f));
  81.278 +		break;
  81.279 +	case NR42:
  81.280 +		sound4EnvelopeVolume	= data >> 4;
  81.281 +		sound4EnvelopeUpDown	= data & 0x08;
  81.282 +		sound4EnvelopeATLReload = sound4EnvelopeATL = 689 * (data & 7);
  81.283 +		break;
  81.284 +	case NR43:
  81.285 +		freq		 = soundFreqRatio[data & 7];
  81.286 +		sound4NSteps = data & 0x08;
  81.287 +
  81.288 +		sound4Skip = freq * NOISE_MAGIC;
  81.289 +
  81.290 +		sound4Clock = data >> 4;
  81.291 +
  81.292 +		freq = freq / soundShiftClock[sound4Clock];
  81.293 +
  81.294 +		sound4ShiftSkip = freq * NOISE_MAGIC;
  81.295 +
  81.296 +		break;
  81.297 +	case NR44:
  81.298 +		sound4Continue = data & 0x40;
  81.299 +		if (data & 0x80)
  81.300 +		{
  81.301 +			gbMemory[NR52]		|= 8;
  81.302 +			sound4EnvelopeVolume = gbMemory[NR42] >> 4;
  81.303 +			sound4EnvelopeUpDown = gbMemory[NR42] & 0x08;
  81.304 +			sound4ATL = 172 * (64 - (gbMemory[NR41] & 0x3f));
  81.305 +			sound4EnvelopeATLReload = sound4EnvelopeATL = 689 * (gbMemory[NR42] & 7);
  81.306 +
  81.307 +			sound4On = 1;
  81.308 +
  81.309 +			sound4Index		 = 0;
  81.310 +			sound4ShiftIndex = 0;
  81.311 +
  81.312 +			freq = soundFreqRatio[gbMemory[NR43] & 7];
  81.313 +
  81.314 +			sound4Skip = freq * NOISE_MAGIC;
  81.315 +
  81.316 +			sound4NSteps = gbMemory[NR43] & 0x08;
  81.317 +
  81.318 +			freq = freq / soundShiftClock[gbMemory[NR43] >> 4];
  81.319 +
  81.320 +			sound4ShiftSkip = freq * NOISE_MAGIC;
  81.321 +			if (sound4NSteps)
  81.322 +				sound4ShiftRight = 0x7f;
  81.323 +			else
  81.324 +				sound4ShiftRight = 0x7fff;
  81.325 +		}
  81.326 +		break;
  81.327 +	case NR50:
  81.328 +		soundVIN	= data & 0x88;
  81.329 +		soundLevel1 = data & 7;
  81.330 +		soundLevel2 = (data >> 4) & 7;
  81.331 +		break;
  81.332 +	case NR51:
  81.333 +		soundBalance	  = (data & soundEnableFlag);
  81.334 +		gbMemory[address] = data;
  81.335 +		break;
  81.336 +	case NR52:
  81.337 +		soundMasterOn = data & 0x80;
  81.338 +		if (!(data & 0x80))
  81.339 +		{
  81.340 +			sound1On = 0;
  81.341 +			sound2On = 0;
  81.342 +			sound3On = 0;
  81.343 +			sound4On = 0;
  81.344 +		}
  81.345 +		break;
  81.346 +	}
  81.347 +
  81.348 +	gbDigitalSound = true;
  81.349 +
  81.350 +	if (sound1On && sound1EnvelopeVolume != 0)
  81.351 +		gbDigitalSound = false;
  81.352 +	if (sound2On && sound2EnvelopeVolume != 0)
  81.353 +		gbDigitalSound = false;
  81.354 +	if (sound3On && sound3OutputLevel != 0)
  81.355 +		gbDigitalSound = false;
  81.356 +	if (sound4On && sound4EnvelopeVolume != 0)
  81.357 +		gbDigitalSound = false;
  81.358 +}
  81.359 +
  81.360 +void gbSoundChannel1()
  81.361 +{
  81.362 +	int vol = sound1EnvelopeVolume;
  81.363 +
  81.364 +	int freq = 0;
  81.365 +
  81.366 +	int value = 0;
  81.367 +
  81.368 +	if (sound1On && (sound1ATL || !sound1Continue))
  81.369 +	{
  81.370 +		sound1Index += soundQuality * sound1Skip;
  81.371 +		sound1Index &= 0x1fffffff;
  81.372 +
  81.373 +		value = ((s8)sound1Wave[sound1Index >> 24]) * vol;
  81.374 +	}
  81.375 +
  81.376 +	soundBuffer[0][soundIndex] = value;
  81.377 +
  81.378 +	if (sound1On)
  81.379 +	{
  81.380 +		if (sound1ATL)
  81.381 +		{
  81.382 +			sound1ATL -= soundQuality;
  81.383 +
  81.384 +			if (sound1ATL <= 0 && sound1Continue)
  81.385 +			{
  81.386 +				gbMemory[NR52] &= 0xfe;
  81.387 +				sound1On		= 0;
  81.388 +			}
  81.389 +		}
  81.390 +
  81.391 +		if (sound1EnvelopeATL)
  81.392 +		{
  81.393 +			sound1EnvelopeATL -= soundQuality;
  81.394 +
  81.395 +			if (sound1EnvelopeATL <= 0)
  81.396 +			{
  81.397 +				if (sound1EnvelopeUpDown)
  81.398 +				{
  81.399 +					if (sound1EnvelopeVolume < 15)
  81.400 +						sound1EnvelopeVolume++;
  81.401 +				}
  81.402 +				else
  81.403 +				{
  81.404 +					if (sound1EnvelopeVolume)
  81.405 +						sound1EnvelopeVolume--;
  81.406 +				}
  81.407 +
  81.408 +				sound1EnvelopeATL += sound1EnvelopeATLReload;
  81.409 +			}
  81.410 +		}
  81.411 +
  81.412 +		if (sound1SweepATL)
  81.413 +		{
  81.414 +			sound1SweepATL -= soundQuality;
  81.415 +
  81.416 +			if (sound1SweepATL <= 0)
  81.417 +			{
  81.418 +				freq = (((int)(gbMemory[NR14] & 7) << 8) | gbMemory[NR13]);
  81.419 +
  81.420 +				int updown = 1;
  81.421 +
  81.422 +				if (sound1SweepUpDown)
  81.423 +					updown = -1;
  81.424 +
  81.425 +				int newfreq = 0;
  81.426 +				if (sound1SweepSteps)
  81.427 +				{
  81.428 +					newfreq = freq + updown * freq / (1 << sound1SweepSteps);
  81.429 +					if (newfreq == freq)
  81.430 +						newfreq = 0;
  81.431 +				}
  81.432 +				else
  81.433 +					newfreq = freq;
  81.434 +
  81.435 +				if (newfreq < 0)
  81.436 +				{
  81.437 +					sound1SweepATL += sound1SweepATLReload;
  81.438 +				}
  81.439 +				else if (newfreq > 2047)
  81.440 +				{
  81.441 +					sound1SweepATL	= 0;
  81.442 +					sound1On		= 0;
  81.443 +					gbMemory[NR52] &= 0xfe;
  81.444 +				}
  81.445 +				else
  81.446 +				{
  81.447 +					sound1SweepATL += sound1SweepATLReload;
  81.448 +					sound1Skip		= SOUND_MAGIC / (2048 - newfreq);
  81.449 +
  81.450 +					gbMemory[NR13] = newfreq & 0xff;
  81.451 +					gbMemory[NR14] = (gbMemory[NR14] & 0xf8) | ((newfreq >> 8) & 7);
  81.452 +				}
  81.453 +			}
  81.454 +		}
  81.455 +	}
  81.456 +}
  81.457 +
  81.458 +void gbSoundChannel2()
  81.459 +{
  81.460 +	//  int freq = 0;
  81.461 +	int vol = sound2EnvelopeVolume;
  81.462 +
  81.463 +	int value = 0;
  81.464 +
  81.465 +	if (sound2On && (sound2ATL || !sound2Continue))
  81.466 +	{
  81.467 +		sound2Index += soundQuality * sound2Skip;
  81.468 +		sound2Index &= 0x1fffffff;
  81.469 +
  81.470 +		value = ((s8)sound2Wave[sound2Index >> 24]) * vol;
  81.471 +	}
  81.472 +
  81.473 +	soundBuffer[1][soundIndex] = value;
  81.474 +
  81.475 +	if (sound2On)
  81.476 +	{
  81.477 +		if (sound2ATL)
  81.478 +		{
  81.479 +			sound2ATL -= soundQuality;
  81.480 +
  81.481 +			if (sound2ATL <= 0 && sound2Continue)
  81.482 +			{
  81.483 +				gbMemory[NR52] &= 0xfd;
  81.484 +				sound2On		= 0;
  81.485 +			}
  81.486 +		}
  81.487 +
  81.488 +		if (sound2EnvelopeATL)
  81.489 +		{
  81.490 +			sound2EnvelopeATL -= soundQuality;
  81.491 +
  81.492 +			if (sound2EnvelopeATL <= 0)
  81.493 +			{
  81.494 +				if (sound2EnvelopeUpDown)
  81.495 +				{
  81.496 +					if (sound2EnvelopeVolume < 15)
  81.497 +						sound2EnvelopeVolume++;
  81.498 +				}
  81.499 +				else
  81.500 +				{
  81.501 +					if (sound2EnvelopeVolume)
  81.502 +						sound2EnvelopeVolume--;
  81.503 +				}
  81.504 +				sound2EnvelopeATL += sound2EnvelopeATLReload;
  81.505 +			}
  81.506 +		}
  81.507 +	}
  81.508 +}
  81.509 +
  81.510 +void gbSoundChannel3()
  81.511 +{
  81.512 +	int value = sound3Last;
  81.513 +
  81.514 +	if (sound3On && (sound3ATL || !sound3Continue))
  81.515 +	{
  81.516 +		sound3Index += soundQuality * sound3Skip;
  81.517 +		sound3Index &= 0x1fffffff;
  81.518 +
  81.519 +		value = gbMemory[0xff30 + (sound3Index >> 25)];
  81.520 +
  81.521 +		if ((sound3Index & 0x01000000))
  81.522 +		{
  81.523 +			value &= 0x0f;
  81.524 +		}
  81.525 +		else
  81.526 +		{
  81.527 +			value >>= 4;
  81.528 +		}
  81.529 +
  81.530 +		value -= 8;
  81.531 +		value *= 2;
  81.532 +
  81.533 +		switch (sound3OutputLevel)
  81.534 +		{
  81.535 +		case 0:
  81.536 +			value = 0;
  81.537 +			break;
  81.538 +		case 1:
  81.539 +			break;
  81.540 +		case 2:
  81.541 +			value = (value >> 1);
  81.542 +			break;
  81.543 +		case 3:
  81.544 +			value = (value >> 2);
  81.545 +			break;
  81.546 +		}
  81.547 +		//value += 1;
  81.548 +		sound3Last = value;
  81.549 +	}
  81.550 +
  81.551 +	soundBuffer[2][soundIndex] = value;
  81.552 +
  81.553 +	if (sound3On)
  81.554 +	{
  81.555 +		if (sound3ATL)
  81.556 +		{
  81.557 +			sound3ATL -= soundQuality;
  81.558 +
  81.559 +			if (sound3ATL <= 0 && sound3Continue)
  81.560 +			{
  81.561 +				gbMemory[NR52] &= 0xfb;
  81.562 +				sound3On		= 0;
  81.563 +			}
  81.564 +		}
  81.565 +	}
  81.566 +}
  81.567 +
  81.568 +void gbSoundChannel4()
  81.569 +{
  81.570 +	int vol = sound4EnvelopeVolume;
  81.571 +
  81.572 +	int value = 0;
  81.573 +
  81.574 +	if (sound4Clock <= 0x0c)
  81.575 +	{
  81.576 +		if (sound4On && (sound4ATL || !sound4Continue))
  81.577 +		{
  81.578 +	  #define NOISE_ONE_SAMP_SCALE  0x200000
  81.579 +
  81.580 +			sound4Index		 += soundQuality * sound4Skip;
  81.581 +			sound4ShiftIndex += soundQuality * sound4ShiftSkip;
  81.582 +
  81.583 +			if (sound4NSteps)
  81.584 +			{
  81.585 +				while (sound4ShiftIndex >= NOISE_ONE_SAMP_SCALE)
  81.586 +				{
  81.587 +					sound4ShiftRight = (((sound4ShiftRight << 6) ^
  81.588 +					                     (sound4ShiftRight << 5)) & 0x40) |
  81.589 +					                   (sound4ShiftRight >> 1);
  81.590 +					sound4ShiftIndex -= NOISE_ONE_SAMP_SCALE;
  81.591 +				}
  81.592 +			}
  81.593 +			else
  81.594 +			{
  81.595 +				while (sound4ShiftIndex >= NOISE_ONE_SAMP_SCALE)
  81.596 +				{
  81.597 +					sound4ShiftRight = (((sound4ShiftRight << 14) ^
  81.598 +					                     (sound4ShiftRight << 13)) & 0x4000) |
  81.599 +					                   (sound4ShiftRight >> 1);
  81.600 +
  81.601 +					sound4ShiftIndex -= NOISE_ONE_SAMP_SCALE;
  81.602 +				}
  81.603 +			}
  81.604 +
  81.605 +			sound4Index		 %= NOISE_ONE_SAMP_SCALE;
  81.606 +			sound4ShiftIndex %= NOISE_ONE_SAMP_SCALE;
  81.607 +
  81.608 +			value = ((sound4ShiftRight & 1) * 2 - 1) * vol;
  81.609 +		}
  81.610 +		else
  81.611 +		{
  81.612 +			value = 0;
  81.613 +		}
  81.614 +	}
  81.615 +
  81.616 +	soundBuffer[3][soundIndex] = value;
  81.617 +
  81.618 +	if (sound4On)
  81.619 +	{
  81.620 +		if (sound4ATL)
  81.621 +		{
  81.622 +			sound4ATL -= soundQuality;
  81.623 +
  81.624 +			if (sound4ATL <= 0 && sound4Continue)
  81.625 +			{
  81.626 +				gbMemory[NR52] &= 0xfd;
  81.627 +				sound4On		= 0;
  81.628 +			}
  81.629 +		}
  81.630 +
  81.631 +		if (sound4EnvelopeATL)
  81.632 +		{
  81.633 +			sound4EnvelopeATL -= soundQuality;
  81.634 +
  81.635 +			if (sound4EnvelopeATL <= 0)
  81.636 +			{
  81.637 +				if (sound4EnvelopeUpDown)
  81.638 +				{
  81.639 +					if (sound4EnvelopeVolume < 15)
  81.640 +						sound4EnvelopeVolume++;
  81.641 +				}
  81.642 +				else
  81.643 +				{
  81.644 +					if (sound4EnvelopeVolume)
  81.645 +						sound4EnvelopeVolume--;
  81.646 +				}
  81.647 +				sound4EnvelopeATL += sound4EnvelopeATLReload;
  81.648 +			}
  81.649 +		}
  81.650 +	}
  81.651 +}
  81.652 +
  81.653 +void gbSoundMix()
  81.654 +{
  81.655 +	int res = 0;
  81.656 +
  81.657 +	if (gbMemory)
  81.658 +		soundBalance = (gbMemory[NR51] & soundEnableFlag & ~soundMutedFlag);
  81.659 +
  81.660 +	if (soundBalance & 16)
  81.661 +	{
  81.662 +		res += ((s8)soundBuffer[0][soundIndex]);
  81.663 +	}
  81.664 +	if (soundBalance & 32)
  81.665 +	{
  81.666 +		res += ((s8)soundBuffer[1][soundIndex]);
  81.667 +	}
  81.668 +	if (soundBalance & 64)
  81.669 +	{
  81.670 +		res += ((s8)soundBuffer[2][soundIndex]);
  81.671 +	}
  81.672 +	if (soundBalance & 128)
  81.673 +	{
  81.674 +		res += ((s8)soundBuffer[3][soundIndex]);
  81.675 +	}
  81.676 +
  81.677 +	if (gbDigitalSound)
  81.678 +		res = soundLevel1 * 256;
  81.679 +	else
  81.680 +		res *= soundLevel1 * 60;
  81.681 +
  81.682 +	if (soundEcho)
  81.683 +	{
  81.684 +		res *= 2;
  81.685 +		res += soundFilter[soundEchoIndex];
  81.686 +		res /= 2;
  81.687 +		soundFilter[soundEchoIndex++] = res;
  81.688 +	}
  81.689 +
  81.690 +	if (soundLowPass)
  81.691 +	{
  81.692 +		soundLeft[4] = soundLeft[3];
  81.693 +		soundLeft[3] = soundLeft[2];
  81.694 +		soundLeft[2] = soundLeft[1];
  81.695 +		soundLeft[1] = soundLeft[0];
  81.696 +		soundLeft[0] = res;
  81.697 +		res = (soundLeft[4] + 2 * soundLeft[3] + 8 * soundLeft[2] + 2 * soundLeft[1] +
  81.698 +		       soundLeft[0]) / 14;
  81.699 +	}
  81.700 +
  81.701 +	bool noSpecialEffects = false;
  81.702 +#if (defined(WIN32) && !defined(SDL))
  81.703 +	if (theApp.soundRecording || theApp.aviRecording || theApp.nvAudioLog)
  81.704 +		noSpecialEffects = true;
  81.705 +#endif
  81.706 +
  81.707 +	if (!noSpecialEffects)
  81.708 +	{
  81.709 +		switch (soundVolume)
  81.710 +		{
  81.711 +		case 0:
  81.712 +		case 1:
  81.713 +		case 2:
  81.714 +		case 3:
  81.715 +			res *= (soundVolume + 1);
  81.716 +			break;
  81.717 +		case 4:
  81.718 +			res >>= 2;
  81.719 +			break;
  81.720 +		case 5:
  81.721 +			res >>= 1;
  81.722 +			break;
  81.723 +		}
  81.724 +	}
  81.725 +
  81.726 +	if (res > 32767)
  81.727 +		res = 32767;
  81.728 +	if (res < -32768)
  81.729 +		res = -32768;
  81.730 +
  81.731 +	if (soundReverse && !noSpecialEffects)
  81.732 +	{
  81.733 +		soundFinalWave[++soundBufferIndex] = res;
  81.734 +		if ((soundFrameSoundWritten + 1) >= countof(soundFrameSound))
  81.735 +			/*assert(false)*/;
  81.736 +		else
  81.737 +			soundFrameSound[++soundFrameSoundWritten] = res;
  81.738 +	}
  81.739 +	else
  81.740 +	{
  81.741 +		soundFinalWave[soundBufferIndex++] = res;
  81.742 +		if (soundFrameSoundWritten >= countof(soundFrameSound))
  81.743 +			/*assert(false)*/;
  81.744 +		else
  81.745 +			soundFrameSound[soundFrameSoundWritten++] = res;
  81.746 +	}
  81.747 +
  81.748 +	res = 0;
  81.749 +
  81.750 +	if (soundBalance & 1)
  81.751 +	{
  81.752 +		res += ((s8)soundBuffer[0][soundIndex]);
  81.753 +	}
  81.754 +	if (soundBalance & 2)
  81.755 +	{
  81.756 +		res += ((s8)soundBuffer[1][soundIndex]);
  81.757 +	}
  81.758 +	if (soundBalance & 4)
  81.759 +	{
  81.760 +		res += ((s8)soundBuffer[2][soundIndex]);
  81.761 +	}
  81.762 +	if (soundBalance & 8)
  81.763 +	{
  81.764 +		res += ((s8)soundBuffer[3][soundIndex]);
  81.765 +	}
  81.766 +
  81.767 +	if (gbDigitalSound)
  81.768 +		res = soundLevel2 * 256;
  81.769 +	else
  81.770 +		res *= soundLevel2 * 60;
  81.771 +
  81.772 +	if (soundEcho)
  81.773 +	{
  81.774 +		res *= 2;
  81.775 +		res += soundFilter[soundEchoIndex];
  81.776 +		res /= 2;
  81.777 +		soundFilter[soundEchoIndex++] = res;
  81.778 +
  81.779 +		if (soundEchoIndex >= 4000)
  81.780 +			soundEchoIndex = 0;
  81.781 +	}
  81.782 +
  81.783 +	if (soundLowPass)
  81.784 +	{
  81.785 +		soundRight[4] = soundRight[3];
  81.786 +		soundRight[3] = soundRight[2];
  81.787 +		soundRight[2] = soundRight[1];
  81.788 +		soundRight[1] = soundRight[0];
  81.789 +		soundRight[0] = res;
  81.790 +		res = (soundRight[4] + 2 * soundRight[3] + 8 * soundRight[2] + 2 * soundRight[1] +
  81.791 +		       soundRight[0]) / 14;
  81.792 +	}
  81.793 +
  81.794 +	if (!noSpecialEffects)
  81.795 +	{
  81.796 +		switch (soundVolume)
  81.797 +		{
  81.798 +		case 0:
  81.799 +		case 1:
  81.800 +		case 2:
  81.801 +		case 3:
  81.802 +			res *= (soundVolume + 1);
  81.803 +			break;
  81.804 +		case 4:
  81.805 +			res >>= 2;
  81.806 +			break;
  81.807 +		case 5:
  81.808 +			res >>= 1;
  81.809 +			break;
  81.810 +		}
  81.811 +	}
  81.812 +
  81.813 +	if (res > 32767)
  81.814 +		res = 32767;
  81.815 +	if (res < -32768)
  81.816 +		res = -32768;
  81.817 +
  81.818 +	if (soundReverse && !noSpecialEffects)
  81.819 +	{
  81.820 +		soundFinalWave[-1 + soundBufferIndex++]		   = res;
  81.821 +		if ((soundFrameSoundWritten) >= countof(soundFrameSound))
  81.822 +			/*assert(false)*/;
  81.823 +		else
  81.824 +			soundFrameSound[-1 + soundFrameSoundWritten++] = res;
  81.825 +	}
  81.826 +	else
  81.827 +	{
  81.828 +		soundFinalWave[soundBufferIndex++]			  = res;
  81.829 +		if ((soundFrameSoundWritten + 1) >= countof(soundFrameSound))
  81.830 +			/*assert(false)*/;
  81.831 +		else
  81.832 +			soundFrameSound[soundFrameSoundWritten++] = res;
  81.833 +	}
  81.834 +}
  81.835 +
  81.836 +void gbSoundTick()
  81.837 +{
  81.838 +	if (systemSoundOn)
  81.839 +	{
  81.840 +		if (soundMasterOn)
  81.841 +		{
  81.842 +			gbSoundChannel1();
  81.843 +			gbSoundChannel2();
  81.844 +			gbSoundChannel3();
  81.845 +			gbSoundChannel4();
  81.846 +
  81.847 +			gbSoundMix();
  81.848 +		}
  81.849 +		else
  81.850 +		{
  81.851 +			soundFinalWave[soundBufferIndex++] = 0;
  81.852 +			soundFinalWave[soundBufferIndex++] = 0;
  81.853 +			if ((soundFrameSoundWritten + 1) >= countof(soundFrameSound))
  81.854 +				/*assert(false)*/;
  81.855 +			else
  81.856 +			{
  81.857 +				soundFrameSound[soundFrameSoundWritten++] = 0;
  81.858 +				soundFrameSound[soundFrameSoundWritten++] = 0;
  81.859 +			}
  81.860 +		}
  81.861 +
  81.862 +		soundIndex++;
  81.863 +
  81.864 +		if (2 * soundBufferIndex >= soundBufferLen)
  81.865 +		{
  81.866 +			if (systemSoundOn)
  81.867 +			{
  81.868 +				if (soundPaused)
  81.869 +				{
  81.870 +					extern void soundResume();
  81.871 +					soundResume();
  81.872 +				}
  81.873 +
  81.874 +				systemSoundWriteToBuffer();
  81.875 +			}
  81.876 +			soundIndex		 = 0;
  81.877 +			soundBufferIndex = 0;
  81.878 +		}
  81.879 +	}
  81.880 +}
  81.881 +
  81.882 +void gbSoundReset()
  81.883 +{
  81.884 +	soundPaused		  = 1;
  81.885 +	soundPlay		  = 0;
  81.886 +	SOUND_CLOCK_TICKS = soundQuality * GB_USE_TICKS_AS;
  81.887 +//  soundTicks = SOUND_CLOCK_TICKS;
  81.888 +	soundTicks		  = 0;
  81.889 +	soundNextPosition = 0;
  81.890 +	soundMasterOn	  = 1;
  81.891 +	soundIndex		  = 0;
  81.892 +	soundBufferIndex  = 0;
  81.893 +	soundLevel1		  = 7;
  81.894 +	soundLevel2		  = 7;
  81.895 +	soundVIN = 0;
  81.896 +
  81.897 +	sound1On = 0;
  81.898 +	sound1ATL = 0;
  81.899 +	sound1Skip = 0;
  81.900 +	sound1Index = 0;
  81.901 +	sound1Continue = 0;
  81.902 +	sound1EnvelopeVolume	= 0;
  81.903 +	sound1EnvelopeATL		= 0;
  81.904 +	sound1EnvelopeUpDown	= 0;
  81.905 +	sound1EnvelopeATLReload = 0;
  81.906 +	sound1SweepATL			= 0;
  81.907 +	sound1SweepATLReload	= 0;
  81.908 +	sound1SweepSteps		= 0;
  81.909 +	sound1SweepUpDown		= 0;
  81.910 +	sound1SweepStep			= 0;
  81.911 +	sound1Wave				= soundWavePattern[2];
  81.912 +
  81.913 +	sound2On = 0;
  81.914 +	sound2ATL = 0;
  81.915 +	sound2Skip = 0;
  81.916 +	sound2Index = 0;
  81.917 +	sound2Continue = 0;
  81.918 +	sound2EnvelopeVolume	= 0;
  81.919 +	sound2EnvelopeATL		= 0;
  81.920 +	sound2EnvelopeUpDown	= 0;
  81.921 +	sound2EnvelopeATLReload = 0;
  81.922 +	sound2Wave				= soundWavePattern[2];
  81.923 +
  81.924 +	sound3On = 0;
  81.925 +	sound3ATL		  = 0;
  81.926 +	sound3Skip		  = 0;
  81.927 +	sound3Index		  = 0;
  81.928 +	sound3Continue	  = 0;
  81.929 +	sound3OutputLevel = 0;
  81.930 +
  81.931 +	sound4On = 0;
  81.932 +	sound4Clock = 0;
  81.933 +	sound4ATL = 0;
  81.934 +	sound4Skip = 0;
  81.935 +	sound4Index = 0;
  81.936 +	sound4ShiftRight		= 0x7f;
  81.937 +	sound4NSteps			= 0;
  81.938 +	sound4CountDown			= 0;
  81.939 +	sound4Continue			= 0;
  81.940 +	sound4EnvelopeVolume	= 0;
  81.941 +	sound4EnvelopeATL		= 0;
  81.942 +	sound4EnvelopeUpDown	= 0;
  81.943 +	sound4EnvelopeATLReload = 0;
  81.944 +
  81.945 +	// don't translate
  81.946 +	if (soundDebug)
  81.947 +	{
  81.948 +		log("*** Sound Init ***\n");
  81.949 +	}
  81.950 +
  81.951 +	gbSoundEvent(0xff10, 0x80);
  81.952 +	gbSoundEvent(0xff11, 0xbf);
  81.953 +	gbSoundEvent(0xff12, 0xf3);
  81.954 +	gbSoundEvent(0xff14, 0xbf);
  81.955 +	gbSoundEvent(0xff16, 0x3f);
  81.956 +	gbSoundEvent(0xff17, 0x00);
  81.957 +	gbSoundEvent(0xff19, 0xbf);
  81.958 +
  81.959 +	gbSoundEvent(0xff1a, 0x7f);
  81.960 +	gbSoundEvent(0xff1b, 0xff);
  81.961 +	gbSoundEvent(0xff1c, 0xbf);
  81.962 +	gbSoundEvent(0xff1e, 0xbf);
  81.963 +
  81.964 +	gbSoundEvent(0xff20, 0xff);
  81.965 +	gbSoundEvent(0xff21, 0x00);
  81.966 +	gbSoundEvent(0xff22, 0x00);
  81.967 +	gbSoundEvent(0xff23, 0xbf);
  81.968 +	gbSoundEvent(0xff24, 0x77);
  81.969 +	gbSoundEvent(0xff25, 0xf3);
  81.970 +
  81.971 +	gbSoundEvent(0xff26, 0xf0);
  81.972 +
  81.973 +	// don't translate
  81.974 +	if (soundDebug)
  81.975 +	{
  81.976 +		log("*** Sound Init Complete ***\n");
  81.977 +	}
  81.978 +
  81.979 +	sound1On = 0;
  81.980 +	sound2On = 0;
  81.981 +	sound3On = 0;
  81.982 +	sound4On = 0;
  81.983 +
  81.984 +	int addr = 0xff30;
  81.985 +
  81.986 +	while (addr < 0xff40)
  81.987 +	{
  81.988 +		gbMemory[addr++] = 0x00;
  81.989 +		gbMemory[addr++] = 0xff;
  81.990 +	}
  81.991 +
  81.992 +	memset(soundFinalWave, 0x00, soundBufferLen);
  81.993 +
  81.994 +	memset(soundFilter, 0, sizeof(soundFilter));
  81.995 +	soundEchoIndex = 0;
  81.996 +}
  81.997 +
  81.998 +extern bool soundInit();
  81.999 +extern void soundShutdown();
 81.1000 +
 81.1001 +void gbSoundSetQuality(int quality)
 81.1002 +{
 81.1003 +	if (soundQuality != quality && systemSoundCanChangeQuality())
 81.1004 +	{
 81.1005 +		if (!soundOffFlag)
 81.1006 +			soundShutdown();
 81.1007 +		soundQuality	  = quality;
 81.1008 +		soundNextPosition = 0;
 81.1009 +		if (!soundOffFlag)
 81.1010 +			soundInit();
 81.1011 +		SOUND_CLOCK_TICKS = (gbSpeed ? 2 : 1) * GB_USE_TICKS_AS * soundQuality;
 81.1012 +		soundIndex		  = 0;
 81.1013 +		soundBufferIndex  = 0;
 81.1014 +	}
 81.1015 +	else
 81.1016 +	{
 81.1017 +		soundNextPosition = 0;
 81.1018 +		SOUND_CLOCK_TICKS = (gbSpeed ? 2 : 1) * GB_USE_TICKS_AS * soundQuality;
 81.1019 +		soundIndex		  = 0;
 81.1020 +		soundBufferIndex  = 0;
 81.1021 +	}
 81.1022 +}
 81.1023 +
 81.1024 +static int32 soundTicks_int32;
 81.1025 +static int32 SOUND_CLOCK_TICKS_int32;
 81.1026 +variable_desc gbSoundSaveStruct[] = {
 81.1027 +	{ &soundPaused,				sizeof(int32)					  },
 81.1028 +	{ &soundPlay,				sizeof(int32)					  },
 81.1029 +	{ &soundTicks_int32,		sizeof(int32)					  },
 81.1030 +	{ &SOUND_CLOCK_TICKS_int32, sizeof(int32)					  },
 81.1031 +	{ &soundLevel1,				sizeof(int32)					  },
 81.1032 +	{ &soundLevel2,				sizeof(int32)					  },
 81.1033 +	{ &soundBalance,			sizeof(int32)					  },
 81.1034 +	{ &soundMasterOn,			sizeof(int32)					  },
 81.1035 +	{ &soundIndex,				sizeof(int32)					  },
 81.1036 +	{ &soundVIN,				sizeof(int32)					  },
 81.1037 +	{ &sound1On,				sizeof(int32)					  },
 81.1038 +	{ &sound1ATL,				sizeof(int32)					  },
 81.1039 +	{ &sound1Skip,				sizeof(int32)					  },
 81.1040 +	{ &sound1Index,				sizeof(int32)					  },
 81.1041 +	{ &sound1Continue,			sizeof(int32)					  },
 81.1042 +	{ &sound1EnvelopeVolume,	sizeof(int32)					  },
 81.1043 +	{ &sound1EnvelopeATL,		sizeof(int32)					  },
 81.1044 +	{ &sound1EnvelopeATLReload, sizeof(int32)					  },
 81.1045 +	{ &sound1EnvelopeUpDown,	sizeof(int32)					  },
 81.1046 +	{ &sound1SweepATL,			sizeof(int32)					  },
 81.1047 +	{ &sound1SweepATLReload,	sizeof(int32)					  },
 81.1048 +	{ &sound1SweepSteps,		sizeof(int32)					  },
 81.1049 +	{ &sound1SweepUpDown,		sizeof(int32)					  },
 81.1050 +	{ &sound1SweepStep,			sizeof(int32)					  },
 81.1051 +	{ &sound2On,				sizeof(int32)					  },
 81.1052 +	{ &sound2ATL,				sizeof(int32)					  },
 81.1053 +	{ &sound2Skip,				sizeof(int32)					  },
 81.1054 +	{ &sound2Index,				sizeof(int32)					  },
 81.1055 +	{ &sound2Continue,			sizeof(int32)					  },
 81.1056 +	{ &sound2EnvelopeVolume,	sizeof(int32)					  },
 81.1057 +	{ &sound2EnvelopeATL,		sizeof(int32)					  },
 81.1058 +	{ &sound2EnvelopeATLReload, sizeof(int32)					  },
 81.1059 +	{ &sound2EnvelopeUpDown,	sizeof(int32)					  },
 81.1060 +	{ &sound3On,				sizeof(int32)					  },
 81.1061 +	{ &sound3ATL,				sizeof(int32)					  },
 81.1062 +	{ &sound3Skip,				sizeof(int32)					  },
 81.1063 +	{ &sound3Index,				sizeof(int32)					  },
 81.1064 +	{ &sound3Continue,			sizeof(int32)					  },
 81.1065 +	{ &sound3OutputLevel,		sizeof(int32)					  },
 81.1066 +	{ &sound4On,				sizeof(int32)					  },
 81.1067 +	{ &sound4ATL,				sizeof(int32)					  },
 81.1068 +	{ &sound4Skip,				sizeof(int32)					  },
 81.1069 +	{ &sound4Index,				sizeof(int32)					  },
 81.1070 +	{ &sound4Clock,				sizeof(int32)					  },
 81.1071 +	{ &sound4ShiftRight,		sizeof(int32)					  },
 81.1072 +	{ &sound4ShiftSkip,			sizeof(int32)					  },
 81.1073 +	{ &sound4ShiftIndex,		sizeof(int32)					  },
 81.1074 +	{ &sound4NSteps,			sizeof(int32)					  },
 81.1075 +	{ &sound4CountDown,			sizeof(int32)					  },
 81.1076 +	{ &sound4Continue,			sizeof(int32)					  },
 81.1077 +	{ &sound4EnvelopeVolume,	sizeof(int32)					  },
 81.1078 +	{ &sound4EnvelopeATL,		sizeof(int32)					  },
 81.1079 +	{ &sound4EnvelopeATLReload, sizeof(int32)					  },
 81.1080 +	{ &sound4EnvelopeUpDown,	sizeof(int32)					  },
 81.1081 +	{ &soundEnableFlag,			sizeof(int32)					  },
 81.1082 +	{ NULL,						0								  }
 81.1083 +};
 81.1084 +
 81.1085 +//variable_desc gbSoundSaveStructV2[] = {
 81.1086 +//  { &soundTicks, sizeof(soundtick_t) },
 81.1087 +//  { &SOUND_CLOCK_TICKS, sizeof(soundtick_t) },
 81.1088 +//  { &GB_USE_TICKS_AS, sizeof(soundtick_t) },
 81.1089 +//  { NULL, 0 }
 81.1090 +//};
 81.1091 +
 81.1092 +void gbSoundSaveGame(gzFile gzFile)
 81.1093 +{
 81.1094 +	soundTicks_int32		= (int32) soundTicks;
 81.1095 +	SOUND_CLOCK_TICKS_int32 = (int32) SOUND_CLOCK_TICKS;
 81.1096 +
 81.1097 +	utilWriteData(gzFile, gbSoundSaveStruct);
 81.1098 +
 81.1099 +	utilGzWrite(gzFile, soundBuffer, 4 * 735);
 81.1100 +	utilGzWrite(gzFile, soundFinalWave, 2 * 735);
 81.1101 +	utilGzWrite(gzFile, &soundQuality, sizeof(int32));
 81.1102 +
 81.1103 +	//utilWriteData(gzFile, gbSoundSaveStructV2);
 81.1104 +}
 81.1105 +
 81.1106 +void gbSoundReadGame(int version, gzFile gzFile)
 81.1107 +{
 81.1108 +	int32 oldSoundPaused = soundPaused;
 81.1109 +	int32 oldSoundEnableFlag = soundEnableFlag;
 81.1110 +	utilReadData(gzFile, gbSoundSaveStruct);
 81.1111 +	soundPaused = oldSoundPaused;
 81.1112 +	soundEnableFlag = oldSoundEnableFlag;
 81.1113 +
 81.1114 +	soundBufferIndex = soundIndex * 2;
 81.1115 +
 81.1116 +	utilGzRead(gzFile, soundBuffer, 4 * 735);
 81.1117 +	utilGzRead(gzFile, soundFinalWave, 2 * 735);
 81.1118 +
 81.1119 +	if (version >= 7)
 81.1120 +	{
 81.1121 +		int quality = 1;
 81.1122 +		utilGzRead(gzFile, &quality, sizeof(int32));
 81.1123 +		gbSoundSetQuality(quality);
 81.1124 +	}
 81.1125 +	else
 81.1126 +	{
 81.1127 +		soundQuality = -1;
 81.1128 +		gbSoundSetQuality(1);
 81.1129 +	}
 81.1130 +
 81.1131 +	sound1Wave = soundWavePattern[gbMemory[NR11] >> 6];
 81.1132 +	sound2Wave = soundWavePattern[gbMemory[NR21] >> 6];
 81.1133 +
 81.1134 +	//if(version >= 14) {
 81.1135 +	//  utilReadData(gzFile, gbSoundSaveStructV2);
 81.1136 +	//}
 81.1137 +	//else {
 81.1138 +	soundTicks		  = (soundtick_t) soundTicks_int32;
 81.1139 +	SOUND_CLOCK_TICKS = (soundtick_t) SOUND_CLOCK_TICKS_int32;
 81.1140 +	//}
 81.1141 +}
 81.1142 +
    82.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    82.2 +++ b/src/gb/gbSound.h	Sat Mar 03 10:31:27 2012 -0600
    82.3 @@ -0,0 +1,51 @@
    82.4 +#ifndef VBA_GB_SOUND_H
    82.5 +#define VBA_GB_SOUND_H
    82.6 +
    82.7 +#if _MSC_VER > 1000
    82.8 +#pragma once
    82.9 +#endif // _MSC_VER > 1000
   82.10 +
   82.11 +#define NR10 0xff10
   82.12 +#define NR11 0xff11
   82.13 +#define NR12 0xff12
   82.14 +#define NR13 0xff13
   82.15 +#define NR14 0xff14
   82.16 +#define NR21 0xff16
   82.17 +#define NR22 0xff17
   82.18 +#define NR23 0xff18
   82.19 +#define NR24 0xff19
   82.20 +#define NR30 0xff1a
   82.21 +#define NR31 0xff1b
   82.22 +#define NR32 0xff1c
   82.23 +#define NR33 0xff1d
   82.24 +#define NR34 0xff1e
   82.25 +#define NR41 0xff20
   82.26 +#define NR42 0xff21
   82.27 +#define NR43 0xff22
   82.28 +#define NR44 0xff23
   82.29 +#define NR50 0xff24
   82.30 +#define NR51 0xff25
   82.31 +#define NR52 0xff26
   82.32 +
   82.33 +#define SOUND_EVENT(address, value) \
   82.34 +    gbSoundEvent(address, value)
   82.35 +
   82.36 +extern void gbSoundTick();
   82.37 +extern void gbSoundPause();
   82.38 +extern void gbSoundResume();
   82.39 +extern void gbSoundEnable(int);
   82.40 +extern void gbSoundDisable(int);
   82.41 +extern int gbSoundGetEnable();
   82.42 +extern void gbSoundReset();
   82.43 +extern void gbSoundSaveGame(gzFile);
   82.44 +extern void gbSoundReadGame(int, gzFile);
   82.45 +extern void gbSoundEvent(register u16, register int);
   82.46 +extern void gbSoundSetQuality(int);
   82.47 +
   82.48 +typedef int32 soundtick_t;
   82.49 +
   82.50 +extern soundtick_t soundTicks;
   82.51 +extern int32       soundQuality;
   82.52 +extern soundtick_t SOUND_CLOCK_TICKS;
   82.53 +
   82.54 +#endif // VBA_GB_SOUND_H
    83.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    83.2 +++ b/src/gba/EEprom.cpp	Sat Mar 03 10:31:27 2012 -0600
    83.3 @@ -0,0 +1,210 @@
    83.4 +#include <cstring>
    83.5 +
    83.6 +#include "GBA.h" // for SAVE_GAME_VERSION_3
    83.7 +#include "EEprom.h"
    83.8 +#include "../common/System.h"
    83.9 +#include "../common/Util.h"
   83.10 +
   83.11 +extern int32 cpuDmaCount;
   83.12 +
   83.13 +int32 eepromMode    = EEPROM_IDLE;
   83.14 +int32 eepromByte    = 0;
   83.15 +int32 eepromBits    = 0;
   83.16 +int32 eepromAddress = 0;
   83.17 +u8    eepromData[0x2000];
   83.18 +u8    eepromBuffer[16];
   83.19 +bool8 eepromInUse = false;
   83.20 +int32 eepromSize  = 512;
   83.21 +
   83.22 +variable_desc eepromSaveData[] = {
   83.23 +	{ &eepromMode,		sizeof(int32) },
   83.24 +	{ &eepromByte,		sizeof(int32) },
   83.25 +	{ &eepromBits,		sizeof(int32) },
   83.26 +	{ &eepromAddress,	sizeof(int32) },
   83.27 +	{ &eepromInUse,		sizeof(bool8) },
   83.28 +	{ &eepromData[0],             512 },
   83.29 +	{ &eepromBuffer[0],            16 },
   83.30 +	{ NULL,							0 }
   83.31 +};
   83.32 +
   83.33 +void eepromReset()
   83.34 +{
   83.35 +	eepromMode    = EEPROM_IDLE;
   83.36 +	eepromByte    = 0;
   83.37 +	eepromBits    = 0;
   83.38 +	eepromAddress = 0;
   83.39 +	eepromInUse   = false;
   83.40 +	eepromSize    = 512;
   83.41 +}
   83.42 +
   83.43 +void eepromErase()
   83.44 +{
   83.45 +	memset(eepromData, 0, 0x2000*sizeof(u8));
   83.46 +	eepromMode    = EEPROM_IDLE;
   83.47 +	eepromByte    = 0;
   83.48 +	eepromBits    = 0;
   83.49 +	eepromAddress = 0;
   83.50 +	memset(eepromBuffer, 0, 16*sizeof(u8));
   83.51 +	eepromInUse = false;
   83.52 +	eepromSize  = 512;
   83.53 +}
   83.54 +
   83.55 +void eepromSaveGame(gzFile gzFile)
   83.56 +{
   83.57 +	utilWriteData(gzFile, eepromSaveData);
   83.58 +	utilWriteInt(gzFile, eepromSize);
   83.59 +	utilGzWrite(gzFile, eepromData, 0x2000);
   83.60 +}
   83.61 +
   83.62 +void eepromReadGame(gzFile gzFile, int version)
   83.63 +{
   83.64 +	utilReadData(gzFile, eepromSaveData);
   83.65 +	if (version >= SAVE_GAME_VERSION_3)
   83.66 +	{
   83.67 +		eepromSize = utilReadInt(gzFile);
   83.68 +		utilGzRead(gzFile, eepromData, 0x2000);
   83.69 +	}
   83.70 +	else
   83.71 +	{
   83.72 +		// prior to 0.7.1, only 4K EEPROM was supported
   83.73 +		eepromSize = 512;
   83.74 +	}
   83.75 +}
   83.76 +
   83.77 +int eepromRead(u32 /* address */)
   83.78 +{
   83.79 +	switch (eepromMode)
   83.80 +	{
   83.81 +	case EEPROM_IDLE:
   83.82 +	case EEPROM_READADDRESS:
   83.83 +	case EEPROM_WRITEDATA:
   83.84 +		return 1;
   83.85 +	case EEPROM_READDATA:
   83.86 +	{
   83.87 +		eepromBits++;
   83.88 +		if (eepromBits == 4)
   83.89 +		{
   83.90 +			eepromMode = EEPROM_READDATA2;
   83.91 +			eepromBits = 0;
   83.92 +			eepromByte = 0;
   83.93 +		}
   83.94 +		return 0;
   83.95 +	}
   83.96 +	case EEPROM_READDATA2:
   83.97 +	{
   83.98 +		int data    = 0;
   83.99 +		int address = eepromAddress << 3;
  83.100 +		int mask    = 1 << (7 - (eepromBits & 7));
  83.101 +		data = (eepromData[address+eepromByte] & mask) ? 1 : 0;
  83.102 +		eepromBits++;
  83.103 +		if ((eepromBits & 7) == 0)
  83.104 +			eepromByte++;
  83.105 +		if (eepromBits == 0x40)
  83.106 +			eepromMode = EEPROM_IDLE;
  83.107 +		return data;
  83.108 +	}
  83.109 +	default:
  83.110 +		return 0;
  83.111 +	}
  83.112 +	return 1;
  83.113 +}
  83.114 +
  83.115 +void eepromWrite(u32 /* address */, u8 value)
  83.116 +{
  83.117 +	if (cpuDmaCount == 0)
  83.118 +		return;
  83.119 +	int bit = value & 1;
  83.120 +	switch (eepromMode)
  83.121 +	{
  83.122 +	case EEPROM_IDLE:
  83.123 +		eepromByte = 0;
  83.124 +		eepromBits = 1;
  83.125 +		eepromBuffer[eepromByte] = bit;
  83.126 +		eepromMode = EEPROM_READADDRESS;
  83.127 +		break;
  83.128 +	case EEPROM_READADDRESS:
  83.129 +		eepromBuffer[eepromByte] <<= 1;
  83.130 +		eepromBuffer[eepromByte]  |= bit;
  83.131 +		eepromBits++;
  83.132 +		if ((eepromBits & 7) == 0)
  83.133 +		{
  83.134 +			eepromByte++;
  83.135 +		}
  83.136 +		if (cpuDmaCount == 0x11 || cpuDmaCount == 0x51)
  83.137 +		{
  83.138 +			if (eepromBits == 0x11)
  83.139 +			{
  83.140 +				eepromInUse   = true;
  83.141 +				eepromSize    = 0x2000;
  83.142 +				eepromAddress = ((eepromBuffer[0] & 0x3F) << 8) |
  83.143 +				                ((eepromBuffer[1] & 0xFF));
  83.144 +				if (!(eepromBuffer[0] & 0x40))
  83.145 +				{
  83.146 +					eepromBuffer[0] = bit;
  83.147 +					eepromBits      = 1;
  83.148 +					eepromByte      = 0;
  83.149 +					eepromMode      = EEPROM_WRITEDATA;
  83.150 +				}
  83.151 +				else
  83.152 +				{
  83.153 +					eepromMode = EEPROM_READDATA;
  83.154 +					eepromByte = 0;
  83.155 +					eepromBits = 0;
  83.156 +				}
  83.157 +			}
  83.158 +		}
  83.159 +		else
  83.160 +		{
  83.161 +			if (eepromBits == 9)
  83.162 +			{
  83.163 +				eepromInUse   = true;
  83.164 +				eepromAddress = (eepromBuffer[0] & 0x3F);
  83.165 +				if (!(eepromBuffer[0] & 0x40))
  83.166 +				{
  83.167 +					eepromBuffer[0] = bit;
  83.168 +					eepromBits      = 1;
  83.169 +					eepromByte      = 0;
  83.170 +					eepromMode      = EEPROM_WRITEDATA;
  83.171 +				}
  83.172 +				else
  83.173 +				{
  83.174 +					eepromMode = EEPROM_READDATA;
  83.175 +					eepromByte = 0;
  83.176 +					eepromBits = 0;
  83.177 +				}
  83.178 +			}
  83.179 +		}
  83.180 +		break;
  83.181 +	case EEPROM_READDATA:
  83.182 +	case EEPROM_READDATA2:
  83.183 +		// should we reset here?
  83.184 +		eepromMode = EEPROM_IDLE;
  83.185 +		break;
  83.186 +	case EEPROM_WRITEDATA:
  83.187 +		eepromBuffer[eepromByte] <<= 1;
  83.188 +		eepromBuffer[eepromByte]  |= bit;
  83.189 +		eepromBits++;
  83.190 +		if ((eepromBits & 7) == 0)
  83.191 +		{
  83.192 +			eepromByte++;
  83.193 +		}
  83.194 +		if (eepromBits == 0x40)
  83.195 +		{
  83.196 +			eepromInUse = true;
  83.197 +			// write data;
  83.198 +			for (int i = 0; i < 8; i++)
  83.199 +			{
  83.200 +				eepromData[(eepromAddress << 3) + i] = eepromBuffer[i];
  83.201 +			}
  83.202 +			systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
  83.203 +		}
  83.204 +		else if (eepromBits == 0x41)
  83.205 +		{
  83.206 +			eepromMode = EEPROM_IDLE;
  83.207 +			eepromByte = 0;
  83.208 +			eepromBits = 0;
  83.209 +		}
  83.210 +		break;
  83.211 +	}
  83.212 +}
  83.213 +
    84.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    84.2 +++ b/src/gba/EEprom.h	Sat Mar 03 10:31:27 2012 -0600
    84.3 @@ -0,0 +1,27 @@
    84.4 +#ifndef VBA_EEPROM_H
    84.5 +#define VBA_EEPROM_H
    84.6 +
    84.7 +#if _MSC_VER > 1000
    84.8 +#pragma once
    84.9 +#endif // _MSC_VER > 1000
   84.10 +
   84.11 +#include "zlib.h"
   84.12 +#include "../Port.h"
   84.13 +
   84.14 +extern void eepromSaveGame(gzFile gzFile);
   84.15 +extern void eepromReadGame(gzFile gzFile, int version);
   84.16 +extern int eepromRead(u32 address);
   84.17 +extern void eepromWrite(u32 address, u8 value);
   84.18 +extern void eepromReset();
   84.19 +extern void eepromErase();
   84.20 +extern u8    eepromData[0x2000];
   84.21 +extern bool8 eepromInUse;
   84.22 +extern int32 eepromSize;
   84.23 +
   84.24 +#define EEPROM_IDLE           0
   84.25 +#define EEPROM_READADDRESS    1
   84.26 +#define EEPROM_READDATA       2
   84.27 +#define EEPROM_READDATA2      3
   84.28 +#define EEPROM_WRITEDATA      4
   84.29 +
   84.30 +#endif // VBA_EEPROM_H
    85.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    85.2 +++ b/src/gba/Flash.cpp	Sat Mar 03 10:31:27 2012 -0600
    85.3 @@ -0,0 +1,285 @@
    85.4 +#include <cstdio>
    85.5 +#include <cstring>
    85.6 +
    85.7 +#include "Flash.h"
    85.8 +#include "GBA.h"
    85.9 +#include "GBAGlobals.h"
   85.10 +#include "Sram.h"
   85.11 +#include "../common/System.h"
   85.12 +#include "../common/Util.h"
   85.13 +
   85.14 +#define FLASH_READ_ARRAY         0
   85.15 +#define FLASH_CMD_1              1
   85.16 +#define FLASH_CMD_2              2
   85.17 +#define FLASH_AUTOSELECT         3
   85.18 +#define FLASH_CMD_3              4
   85.19 +#define FLASH_CMD_4              5
   85.20 +#define FLASH_CMD_5              6
   85.21 +#define FLASH_ERASE_COMPLETE     7
   85.22 +#define FLASH_PROGRAM            8
   85.23 +#define FLASH_SETBANK            9
   85.24 +
   85.25 +u8    flashSaveMemory[0x20000 + 4];
   85.26 +int32 flashState          = FLASH_READ_ARRAY;
   85.27 +int32 flashReadState      = FLASH_READ_ARRAY;
   85.28 +int32 flashSize           = 0x10000;
   85.29 +int32 flashDeviceID       = 0x1b;
   85.30 +int32 flashManufacturerID = 0x32;
   85.31 +int32 flashBank           = 0;
   85.32 +
   85.33 +static variable_desc flashSaveData[] = {
   85.34 +	{ &flashState,         sizeof(int32) },
   85.35 +	{ &flashReadState,     sizeof(int32) },
   85.36 +	{ &flashSaveMemory[0],       0x10000 },
   85.37 +	{ NULL,                            0 }
   85.38 +};
   85.39 +
   85.40 +static variable_desc flashSaveData2[] = {
   85.41 +	{ &flashState,         sizeof(int32) },
   85.42 +	{ &flashReadState,     sizeof(int32) },
   85.43 +	{ &flashSize,          sizeof(int32) },
   85.44 +	{ &flashSaveMemory[0],       0x20000 },
   85.45 +	{ NULL,                            0 }
   85.46 +};
   85.47 +
   85.48 +static variable_desc flashSaveData3[] = {
   85.49 +	{ &flashState,         sizeof(int32) },
   85.50 +	{ &flashReadState,     sizeof(int32) },
   85.51 +	{ &flashSize,          sizeof(int32) },
   85.52 +	{ &flashBank,          sizeof(int32) },
   85.53 +	{ &flashSaveMemory[0],       0x20000 },
   85.54 +	{ NULL,                            0 }
   85.55 +};
   85.56 +
   85.57 +void flashReset()
   85.58 +{
   85.59 +	flashState     = FLASH_READ_ARRAY;
   85.60 +	flashReadState = FLASH_READ_ARRAY;
   85.61 +	flashBank      = 0;
   85.62 +}
   85.63 +
   85.64 +void flashErase()
   85.65 +{
   85.66 +	memset(flashSaveMemory, 0, 0x20000*sizeof(u8));
   85.67 +	flashState          = FLASH_READ_ARRAY;
   85.68 +	flashReadState      = FLASH_READ_ARRAY;
   85.69 +	flashSize           = 0x10000;
   85.70 +	flashDeviceID       = 0x1b;
   85.71 +	flashManufacturerID = 0x32;
   85.72 +	flashBank           = 0;
   85.73 +}
   85.74 +
   85.75 +void flashSaveGame(gzFile gzFile)
   85.76 +{
   85.77 +	utilWriteData(gzFile, flashSaveData3);
   85.78 +}
   85.79 +
   85.80 +void flashReadGame(gzFile gzFile, int version)
   85.81 +{
   85.82 +	if (version < SAVE_GAME_VERSION_5)
   85.83 +		utilReadData(gzFile, flashSaveData);
   85.84 +	else if (version < SAVE_GAME_VERSION_7)
   85.85 +	{
   85.86 +		utilReadData(gzFile, flashSaveData2);
   85.87 +		flashBank = 0;
   85.88 +		flashSetSize(flashSize);
   85.89 +	}
   85.90 +	else
   85.91 +	{
   85.92 +		utilReadData(gzFile, flashSaveData3);
   85.93 +	}
   85.94 +}
   85.95 +
   85.96 +void flashSetSize(int size)
   85.97 +{
   85.98 +	//  log("Setting flash size to %d\n", size);
   85.99 +	flashSize = size;
  85.100 +	if (size == 0x10000)
  85.101 +	{
  85.102 +		flashDeviceID       = 0x1b;
  85.103 +		flashManufacturerID = 0x32;
  85.104 +	}
  85.105 +	else
  85.106 +	{
  85.107 +		flashDeviceID       = 0x13; //0x09;
  85.108 +		flashManufacturerID = 0x62; //0xc2;
  85.109 +	}
  85.110 +}
  85.111 +
  85.112 +u8 flashRead(u32 address)
  85.113 +{
  85.114 +	//  log("Reading %08x from %08x\n", address, reg[15].I);
  85.115 +	//  log("Current read state is %d\n", flashReadState);
  85.116 +	address &= 0xFFFF;
  85.117 +
  85.118 +	switch (flashReadState)
  85.119 +	{
  85.120 +	case FLASH_READ_ARRAY:
  85.121 +		return flashSaveMemory[(flashBank << 16) + address];
  85.122 +	case FLASH_AUTOSELECT:
  85.123 +		switch (address & 0xFF)
  85.124 +		{
  85.125 +		case 0:
  85.126 +			// manufacturer ID
  85.127 +			return u8(flashManufacturerID);
  85.128 +		case 1:
  85.129 +			// device ID
  85.130 +			return u8(flashDeviceID);
  85.131 +		}
  85.132 +		break;
  85.133 +	case FLASH_ERASE_COMPLETE:
  85.134 +		flashState     = FLASH_READ_ARRAY;
  85.135 +		flashReadState = FLASH_READ_ARRAY;
  85.136 +		return 0xFF;
  85.137 +	}
  85.138 +	;
  85.139 +	return 0;
  85.140 +}
  85.141 +
  85.142 +void flashSaveDecide(u32 address, u8 byte)
  85.143 +{
  85.144 +	//  log("Deciding save type %08x\n", address);
  85.145 +	if (address == 0x0e005555)
  85.146 +	{
  85.147 +		saveType        = 2;
  85.148 +		cpuSaveGameFunc = flashWrite;
  85.149 +	}
  85.150 +	else
  85.151 +	{
  85.152 +		saveType        = 1;
  85.153 +		cpuSaveGameFunc = sramWrite;
  85.154 +	}
  85.155 +
  85.156 +	(*cpuSaveGameFunc)(address, byte);
  85.157 +}
  85.158 +
  85.159 +void flashWrite(u32 address, u8 byte)
  85.160 +{
  85.161 +	//  log("Writing %02x at %08x\n", byte, address);
  85.162 +	//  log("Current state is %d\n", flashState);
  85.163 +	address &= 0xFFFF;
  85.164 +	switch (flashState)
  85.165 +	{
  85.166 +	case FLASH_READ_ARRAY:
  85.167 +		if (address == 0x5555 && byte == 0xAA)
  85.168 +			flashState = FLASH_CMD_1;
  85.169 +		break;
  85.170 +	case FLASH_CMD_1:
  85.171 +		if (address == 0x2AAA && byte == 0x55)
  85.172 +			flashState = FLASH_CMD_2;
  85.173 +		else
  85.174 +			flashState = FLASH_READ_ARRAY;
  85.175 +		break;
  85.176 +	case FLASH_CMD_2:
  85.177 +		if (address == 0x5555)
  85.178 +		{
  85.179 +			if (byte == 0x90)
  85.180 +			{
  85.181 +				flashState     = FLASH_AUTOSELECT;
  85.182 +				flashReadState = FLASH_AUTOSELECT;
  85.183 +			}
  85.184 +			else if (byte == 0x80)
  85.185 +			{
  85.186 +				flashState = FLASH_CMD_3;
  85.187 +			}
  85.188 +			else if (byte == 0xF0)
  85.189 +			{
  85.190 +				flashState     = FLASH_READ_ARRAY;
  85.191 +				flashReadState = FLASH_READ_ARRAY;
  85.192 +			}
  85.193 +			else if (byte == 0xA0)
  85.194 +			{
  85.195 +				flashState = FLASH_PROGRAM;
  85.196 +			}
  85.197 +			else if (byte == 0xB0 && flashSize == 0x20000)
  85.198 +			{
  85.199 +				flashState = FLASH_SETBANK;
  85.200 +			}
  85.201 +			else
  85.202 +			{
  85.203 +				flashState     = FLASH_READ_ARRAY;
  85.204 +				flashReadState = FLASH_READ_ARRAY;
  85.205 +			}
  85.206 +		}
  85.207 +		else
  85.208 +		{
  85.209 +			flashState     = FLASH_READ_ARRAY;
  85.210 +			flashReadState = FLASH_READ_ARRAY;
  85.211 +		}
  85.212 +		break;
  85.213 +	case FLASH_CMD_3:
  85.214 +		if (address == 0x5555 && byte == 0xAA)
  85.215 +		{
  85.216 +			flashState = FLASH_CMD_4;
  85.217 +		}
  85.218 +		else
  85.219 +		{
  85.220 +			flashState     = FLASH_READ_ARRAY;
  85.221 +			flashReadState = FLASH_READ_ARRAY;
  85.222 +		}
  85.223 +		break;
  85.224 +	case FLASH_CMD_4:
  85.225 +		if (address == 0x2AAA && byte == 0x55)
  85.226 +		{
  85.227 +			flashState = FLASH_CMD_5;
  85.228 +		}
  85.229 +		else
  85.230 +		{
  85.231 +			flashState     = FLASH_READ_ARRAY;
  85.232 +			flashReadState = FLASH_READ_ARRAY;
  85.233 +		}
  85.234 +		break;
  85.235 +	case FLASH_CMD_5:
  85.236 +		if (byte == 0x30)
  85.237 +		{
  85.238 +			// SECTOR ERASE
  85.239 +			memset(&flashSaveMemory[(flashBank << 16) + (address & 0xF000)],
  85.240 +			       0,
  85.241 +			       0x1000);
  85.242 +			systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
  85.243 +			flashReadState = FLASH_ERASE_COMPLETE;
  85.244 +		}
  85.245 +		else if (byte == 0x10)
  85.246 +		{
  85.247 +			// CHIP ERASE
  85.248 +			memset(flashSaveMemory, 0, flashSize);
  85.249 +			systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
  85.250 +			flashReadState = FLASH_ERASE_COMPLETE;
  85.251 +		}
  85.252 +		else
  85.253 +		{
  85.254 +			flashState     = FLASH_READ_ARRAY;
  85.255 +			flashReadState = FLASH_READ_ARRAY;
  85.256 +		}
  85.257 +		break;
  85.258 +	case FLASH_AUTOSELECT:
  85.259 +		if (byte == 0xF0)
  85.260 +		{
  85.261 +			flashState     = FLASH_READ_ARRAY;
  85.262 +			flashReadState = FLASH_READ_ARRAY;
  85.263 +		}
  85.264 +		else if (address == 0x5555 && byte == 0xAA)
  85.265 +			flashState = FLASH_CMD_1;
  85.266 +		else
  85.267 +		{
  85.268 +			flashState     = FLASH_READ_ARRAY;
  85.269 +			flashReadState = FLASH_READ_ARRAY;
  85.270 +		}
  85.271 +		break;
  85.272 +	case FLASH_PROGRAM:
  85.273 +		flashSaveMemory[(flashBank<<16)+address] = byte;
  85.274 +		systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
  85.275 +		flashState     = FLASH_READ_ARRAY;
  85.276 +		flashReadState = FLASH_READ_ARRAY;
  85.277 +		break;
  85.278 +	case FLASH_SETBANK:
  85.279 +		if (address == 0)
  85.280 +		{
  85.281 +			flashBank = (byte & 1);
  85.282 +		}
  85.283 +		flashState     = FLASH_READ_ARRAY;
  85.284 +		flashReadState = FLASH_READ_ARRAY;
  85.285 +		break;
  85.286 +	}
  85.287 +}
  85.288 +
    86.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    86.2 +++ b/src/gba/Flash.h	Sat Mar 03 10:31:27 2012 -0600
    86.3 @@ -0,0 +1,23 @@
    86.4 +#ifndef VBA_FLASH_H
    86.5 +#define VBA_FLASH_H
    86.6 +
    86.7 +#if _MSC_VER > 1000
    86.8 +#pragma once
    86.9 +#endif // _MSC_VER > 1000
   86.10 +
   86.11 +#include "zlib.h"
   86.12 +#include "../Port.h"
   86.13 +
   86.14 +extern void flashSaveGame(gzFile gzFile);
   86.15 +extern void flashReadGame(gzFile gzFile, int version);
   86.16 +extern u8 flashRead(u32 address);
   86.17 +extern void flashWrite(u32 address, u8 byte);
   86.18 +extern u8 flashSaveMemory[0x20000 + 4];
   86.19 +extern void flashSaveDecide(u32 address, u8 byte);
   86.20 +extern void flashReset();
   86.21 +extern void flashErase();
   86.22 +extern void flashSetSize(int size);
   86.23 +
   86.24 +extern int32 flashSize;
   86.25 +
   86.26 +#endif // VBA_FLASH_H
    87.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    87.2 +++ b/src/gba/GBA.cpp	Sat Mar 03 10:31:27 2012 -0600
    87.3 @@ -0,0 +1,4567 @@
    87.4 +#include <cstdio>
    87.5 +#include <cstdlib>
    87.6 +#include <cstdarg>
    87.7 +#include <cstring>
    87.8 +
    87.9 +#include "../Port.h"
   87.10 +#include "../NLS.h"
   87.11 +#include "GBA.h"
   87.12 +//#include "GBAGlobals.h"
   87.13 +#include "GBACheats.h" // FIXME: SDL requires this included before "GBAinline.h"
   87.14 +#include "GBAinline.h"
   87.15 +#include "GBAGfx.h"
   87.16 +#include "GBASound.h"
   87.17 +#include "EEprom.h"
   87.18 +#include "Flash.h"
   87.19 +#include "Sram.h"
   87.20 +#include "bios.h"
   87.21 +#include "elf.h"
   87.22 +#include "agbprint.h"
   87.23 +#include "../common/unzip.h"
   87.24 +#include "../common/Util.h"
   87.25 +#include "../common/movie.h"
   87.26 +#include "../common/vbalua.h"
   87.27 +
   87.28 +#ifdef PROFILING
   87.29 +#include "../prof/prof.h"
   87.30 +#endif
   87.31 +
   87.32 +#define UPDATE_REG(address, value) WRITE16LE(((u16 *)&ioMem[address]), value)
   87.33 +
   87.34 +#ifdef __GNUC__
   87.35 +#define _stricmp strcasecmp
   87.36 +#endif
   87.37 +
   87.38 +#define CPU_BREAK_LOOP \
   87.39 +    cpuSavedTicks	 = cpuSavedTicks - *extCpuLoopTicks; \
   87.40 +    *extCpuLoopTicks = *extClockTicks;
   87.41 +
   87.42 +#define CPU_BREAK_LOOP_2 \
   87.43 +    cpuSavedTicks	 = cpuSavedTicks - *extCpuLoopTicks; \
   87.44 +    *extCpuLoopTicks = *extClockTicks; \
   87.45 +    *extTicks		 = *extClockTicks;
   87.46 +
   87.47 +int32 cpuDmaTicksToUpdate = 0;
   87.48 +int32 cpuDmaCount		  = 0;
   87.49 +bool8 cpuDmaHack		  = 0;
   87.50 +u32	  cpuDmaLast		  = 0;
   87.51 +int32 dummyAddress		  = 0;
   87.52 +
   87.53 +int32 *extCpuLoopTicks = NULL;
   87.54 +int32 *extClockTicks   = NULL;
   87.55 +int32 *extTicks		   = NULL;
   87.56 +
   87.57 +#if (defined(WIN32) && !defined(SDL))
   87.58 +HANDLE mapROM;        // shared memory handles
   87.59 +HANDLE mapWORKRAM;
   87.60 +HANDLE mapBIOS;
   87.61 +HANDLE mapIRAM;
   87.62 +HANDLE mapPALETTERAM;
   87.63 +HANDLE mapVRAM;
   87.64 +HANDLE mapOAM;
   87.65 +HANDLE mapPIX;
   87.66 +HANDLE mapIOMEM;
   87.67 +#endif
   87.68 +
   87.69 +int32 gbaSaveType = 0;      // used to remember the save type on reset
   87.70 +bool8 intState	  = false;
   87.71 +bool8 stopState	  = false;
   87.72 +bool8 holdState	  = false;
   87.73 +int32 holdType	  = 0;
   87.74 +bool8 cpuSramEnabled		 = true;
   87.75 +bool8 cpuFlashEnabled		 = true;
   87.76 +bool8 cpuEEPROMEnabled		 = true;
   87.77 +bool8 cpuEEPROMSensorEnabled = false;
   87.78 +
   87.79 +#ifdef PROFILING
   87.80 +int profilingTicks		  = 0;
   87.81 +int profilingTicksReload  = 0;
   87.82 +static char *profilBuffer = NULL;
   87.83 +static int	 profilSize	  = 0;
   87.84 +static u32	 profilLowPC  = 0;
   87.85 +static int	 profilScale  = 0;
   87.86 +#endif
   87.87 +bool8 freezeWorkRAM[0x40000];
   87.88 +bool8 freezeInternalRAM[0x8000];
   87.89 +int32 lcdTicks = 960;
   87.90 +bool8 timer0On = false;
   87.91 +int32 timer0Ticks		= 0;
   87.92 +int32 timer0Reload		= 0;
   87.93 +int32 timer0ClockReload = 0;
   87.94 +bool8 timer1On			= false;
   87.95 +int32 timer1Ticks		= 0;
   87.96 +int32 timer1Reload		= 0;
   87.97 +int32 timer1ClockReload = 0;
   87.98 +bool8 timer2On			= false;
   87.99 +int32 timer2Ticks		= 0;
  87.100 +int32 timer2Reload		= 0;
  87.101 +int32 timer2ClockReload = 0;
  87.102 +bool8 timer3On			= false;
  87.103 +int32 timer3Ticks		= 0;
  87.104 +int32 timer3Reload		= 0;
  87.105 +int32 timer3ClockReload = 0;
  87.106 +u32	  dma0Source		= 0;
  87.107 +u32	  dma0Dest			= 0;
  87.108 +u32	  dma1Source		= 0;
  87.109 +u32	  dma1Dest			= 0;
  87.110 +u32	  dma2Source		= 0;
  87.111 +u32	  dma2Dest			= 0;
  87.112 +u32	  dma3Source		= 0;
  87.113 +u32	  dma3Dest			= 0;
  87.114 +void  (*cpuSaveGameFunc)(u32, u8) = flashSaveDecide;
  87.115 +void  (*renderLine)() = mode0RenderLine;
  87.116 +bool8 fxOn = false;
  87.117 +bool8 windowOn		 = false;
  87.118 +int32 frameSkipCount = 0;
  87.119 +u32	  gbaLastTime	 = 0;
  87.120 +int32 gbaFrameCount	 = 0;
  87.121 +bool8 prefetchActive = false, prefetchPrevActive = false, prefetchApplies = false;
  87.122 +char  buffer[1024];
  87.123 +FILE *out = NULL;
  87.124 +
  87.125 +static bool newFrame = true;
  87.126 +static bool pauseAfterFrameAdvance = false;
  87.127 +
  87.128 +const int32 TIMER_TICKS[4] = {
  87.129 +	1,
  87.130 +	64,
  87.131 +	256,
  87.132 +	1024
  87.133 +};
  87.134 +
  87.135 +const int32 thumbCycles[] = {
  87.136 +//  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
  87.137 +	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  // 0
  87.138 +	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  // 1
  87.139 +	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  // 2
  87.140 +	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  // 3
  87.141 +	1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3,  // 4
  87.142 +	2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,  // 5
  87.143 +	2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,  // 6
  87.144 +	2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,  // 7
  87.145 +	2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,  // 8
  87.146 +	2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,  // 9
  87.147 +	3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,  // a
  87.148 +	1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 2, 4, 1, 1,  // b
  87.149 +	2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,  // c
  87.150 +	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3,  // d
  87.151 +	3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,  // e
  87.152 +	2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2   // f
  87.153 +};
  87.154 +
  87.155 +const int32 gamepakRamWaitState[4] = { 4, 3, 2, 8 };
  87.156 +const int32 gamepakWaitState[8] =  { 4, 3, 2, 8, 4, 3, 2, 8 };
  87.157 +const int32 gamepakWaitState0[8] = { 2, 2, 2, 2, 1, 1, 1, 1 };
  87.158 +const int32 gamepakWaitState1[8] = { 4, 4, 4, 4, 1, 1, 1, 1 };
  87.159 +const int32 gamepakWaitState2[8] = { 8, 8, 8, 8, 1, 1, 1, 1 };
  87.160 +
  87.161 +int32 memoryWait[16] =
  87.162 +{ 0, 0, 2, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 0 };
  87.163 +int32 memoryWait32[16] =
  87.164 +{ 0, 0, 9, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 0 };
  87.165 +int32 memoryWaitSeq[16] =
  87.166 +{ 0, 0, 2, 0, 0, 0, 0, 0, 2, 2, 4, 4, 8, 8, 4, 0 };
  87.167 +int32 memoryWaitSeq32[16] =
  87.168 +{ 2, 0, 3, 0, 0, 2, 2, 0, 4, 4, 8, 8, 16, 16, 8, 0 };
  87.169 +int32 memoryWaitFetch[16] =
  87.170 +{ 3, 0, 3, 0, 0, 1, 1, 0, 4, 4, 4, 4, 4, 4, 4, 0 };
  87.171 +int32 memoryWaitFetch32[16] =
  87.172 +{ 6, 0, 6, 0, 0, 2, 2, 0, 8, 8, 8, 8, 8, 8, 8, 0 };
  87.173 +
  87.174 +const int32 cpuMemoryWait[16] = {
  87.175 +	0, 0, 2, 0, 0, 0, 0, 0,
  87.176 +	2, 2, 2, 2, 2, 2, 0, 0
  87.177 +};
  87.178 +const int32 cpuMemoryWait32[16] = {
  87.179 +	0, 0, 3, 0, 0, 0, 0, 0,
  87.180 +	3, 3, 3, 3, 3, 3, 0, 0
  87.181 +};
  87.182 +
  87.183 +const bool8 memory32[16] = {
  87.184 +	true, false, false, true, true, false, false, true, false, false, false, false, false, false, true, false
  87.185 +};
  87.186 +
  87.187 +u8 biosProtected[4];
  87.188 +
  87.189 +u8 cpuBitsSet[256];
  87.190 +u8 cpuLowestBitSet[256];
  87.191 +
  87.192 +#ifdef WORDS_BIGENDIAN
  87.193 +bool8 cpuBiosSwapped = false;
  87.194 +#endif
  87.195 +
  87.196 +u32 myROM[] = {
  87.197 +	0xEA000006,
  87.198 +	0xEA000093,
  87.199 +	0xEA000006,
  87.200 +	0x00000000,
  87.201 +	0x00000000,
  87.202 +	0x00000000,
  87.203 +	0xEA000088,
  87.204 +	0x00000000,
  87.205 +	0xE3A00302,
  87.206 +	0xE1A0F000,
  87.207 +	0xE92D5800,
  87.208 +	0xE55EC002,
  87.209 +	0xE28FB03C,
  87.210 +	0xE79BC10C,
  87.211 +	0xE14FB000,
  87.212 +	0xE92D0800,
  87.213 +	0xE20BB080,
  87.214 +	0xE38BB01F,
  87.215 +	0xE129F00B,
  87.216 +	0xE92D4004,
  87.217 +	0xE1A0E00F,
  87.218 +	0xE12FFF1C,
  87.219 +	0xE8BD4004,
  87.220 +	0xE3A0C0D3,
  87.221 +	0xE129F00C,
  87.222 +	0xE8BD0800,
  87.223 +	0xE169F00B,
  87.224 +	0xE8BD5800,
  87.225 +	0xE1B0F00E,
  87.226 +	0x0000009C,
  87.227 +	0x0000009C,
  87.228 +	0x0000009C,
  87.229 +	0x0000009C,
  87.230 +	0x000001F8,
  87.231 +	0x000001F0,
  87.232 +	0x000000AC,
  87.233 +	0x000000A0,
  87.234 +	0x000000FC,
  87.235 +	0x00000168,
  87.236 +	0xE12FFF1E,
  87.237 +	0xE1A03000,
  87.238 +	0xE1A00001,
  87.239 +	0xE1A01003,
  87.240 +	0xE2113102,
  87.241 +	0x42611000,
  87.242 +	0xE033C040,
  87.243 +	0x22600000,
  87.244 +	0xE1B02001,
  87.245 +	0xE15200A0,
  87.246 +	0x91A02082,
  87.247 +	0x3AFFFFFC,
  87.248 +	0xE1500002,
  87.249 +	0xE0A33003,
  87.250 +	0x20400002,
  87.251 +	0xE1320001,
  87.252 +	0x11A020A2,
  87.253 +	0x1AFFFFF9,
  87.254 +	0xE1A01000,
  87.255 +	0xE1A00003,
  87.256 +	0xE1B0C08C,
  87.257 +	0x22600000,
  87.258 +	0x42611000,
  87.259 +	0xE12FFF1E,
  87.260 +	0xE92D0010,
  87.261 +	0xE1A0C000,
  87.262 +	0xE3A01001,
  87.263 +	0xE1500001,
  87.264 +	0x81A000A0,
  87.265 +	0x81A01081,
  87.266 +	0x8AFFFFFB,
  87.267 +	0xE1A0000C,
  87.268 +	0xE1A04001,
  87.269 +	0xE3A03000,
  87.270 +	0xE1A02001,
  87.271 +	0xE15200A0,
  87.272 +	0x91A02082,
  87.273 +	0x3AFFFFFC,
  87.274 +	0xE1500002,
  87.275 +	0xE0A33003,
  87.276 +	0x20400002,
  87.277 +	0xE1320001,
  87.278 +	0x11A020A2,
  87.279 +	0x1AFFFFF9,
  87.280 +	0xE0811003,
  87.281 +	0xE1B010A1,
  87.282 +	0xE1510004,
  87.283 +	0x3AFFFFEE,
  87.284 +	0xE1A00004,
  87.285 +	0xE8BD0010,
  87.286 +	0xE12FFF1E,
  87.287 +	0xE0010090,
  87.288 +	0xE1A01741,
  87.289 +	0xE2611000,
  87.290 +	0xE3A030A9,
  87.291 +	0xE0030391,
  87.292 +	0xE1A03743,
  87.293 +	0xE2833E39,
  87.294 +	0xE0030391,
  87.295 +	0xE1A03743,
  87.296 +	0xE2833C09,
  87.297 +	0xE283301C,
  87.298 +	0xE0030391,
  87.299 +	0xE1A03743,
  87.300 +	0xE2833C0F,
  87.301 +	0xE28330B6,
  87.302 +	0xE0030391,
  87.303 +	0xE1A03743,
  87.304 +	0xE2833C16,
  87.305 +	0xE28330AA,
  87.306 +	0xE0030391,
  87.307 +	0xE1A03743,
  87.308 +	0xE2833A02,
  87.309 +	0xE2833081,
  87.310 +	0xE0030391,
  87.311 +	0xE1A03743,
  87.312 +	0xE2833C36,
  87.313 +	0xE2833051,
  87.314 +	0xE0030391,
  87.315 +	0xE1A03743,
  87.316 +	0xE2833CA2,
  87.317 +	0xE28330F9,
  87.318 +	0xE0000093,
  87.319 +	0xE1A00840,
  87.320 +	0xE12FFF1E,
  87.321 +	0xE3A00001,
  87.322 +	0xE3A01001,
  87.323 +	0xE92D4010,
  87.324 +	0xE3A0C301,
  87.325 +	0xE3A03000,
  87.326 +	0xE3A04001,
  87.327 +	0xE3500000,
  87.328 +	0x1B000004,
  87.329 +	0xE5CC3301,
  87.330 +	0xEB000002,
  87.331 +	0x0AFFFFFC,
  87.332 +	0xE8BD4010,
  87.333 +	0xE12FFF1E,
  87.334 +	0xE5CC3208,
  87.335 +	0xE15C20B8,
  87.336 +	0xE0110002,
  87.337 +	0x10200002,
  87.338 +	0x114C00B8,
  87.339 +	0xE5CC4208,
  87.340 +	0xE12FFF1E,
  87.341 +	0xE92D500F,
  87.342 +	0xE3A00301,
  87.343 +	0xE1A0E00F,
  87.344 +	0xE510F004,
  87.345 +	0xE8BD500F,
  87.346 +	0xE25EF004,
  87.347 +	0xE59FD044,
  87.348 +	0xE92D5000,
  87.349 +	0xE14FC000,
  87.350 +	0xE10FE000,
  87.351 +	0xE92D5000,
  87.352 +	0xE3A0C302,
  87.353 +	0xE5DCE09C,
  87.354 +	0xE35E00A5,
  87.355 +	0x1A000004,
  87.356 +	0x05DCE0B4,
  87.357 +	0x021EE080,
  87.358 +	0xE28FE004,
  87.359 +	0x159FF018,
  87.360 +	0x059FF018,
  87.361 +	0xE59FD018,
  87.362 +	0xE8BD5000,
  87.363 +	0xE169F00C,
  87.364 +	0xE8BD5000,
  87.365 +	0xE25EF004,
  87.366 +	0x03007FF0,
  87.367 +	0x09FE2000,
  87.368 +	0x09FFC000,
  87.369 +	0x03007FE0
  87.370 +};
  87.371 +
  87.372 +variable_desc saveGameStruct[] = {
  87.373 +	{ &DISPCNT,			  sizeof(u16)				 },
  87.374 +	{ &DISPSTAT,		  sizeof(u16)				 },
  87.375 +	{ &VCOUNT,			  sizeof(u16)				 },
  87.376 +	{ &BG0CNT,			  sizeof(u16)				 },
  87.377 +	{ &BG1CNT,			  sizeof(u16)				 },
  87.378 +	{ &BG2CNT,			  sizeof(u16)				 },
  87.379 +	{ &BG3CNT,			  sizeof(u16)				 },
  87.380 +	{ &BG0HOFS,			  sizeof(u16)				 },
  87.381 +	{ &BG0VOFS,			  sizeof(u16)				 },
  87.382 +	{ &BG1HOFS,			  sizeof(u16)				 },
  87.383 +	{ &BG1VOFS,			  sizeof(u16)				 },
  87.384 +	{ &BG2HOFS,			  sizeof(u16)				 },
  87.385 +	{ &BG2VOFS,			  sizeof(u16)				 },
  87.386 +	{ &BG3HOFS,			  sizeof(u16)				 },
  87.387 +	{ &BG3VOFS,			  sizeof(u16)				 },
  87.388 +	{ &BG2PA,			  sizeof(u16)				 },
  87.389 +	{ &BG2PB,			  sizeof(u16)				 },
  87.390 +	{ &BG2PC,			  sizeof(u16)				 },
  87.391 +	{ &BG2PD,			  sizeof(u16)				 },
  87.392 +	{ &BG2X_L,			  sizeof(u16)				 },
  87.393 +	{ &BG2X_H,			  sizeof(u16)				 },
  87.394 +	{ &BG2Y_L,			  sizeof(u16)				 },
  87.395 +	{ &BG2Y_H,			  sizeof(u16)				 },
  87.396 +	{ &BG3PA,			  sizeof(u16)				 },
  87.397 +	{ &BG3PB,			  sizeof(u16)				 },
  87.398 +	{ &BG3PC,			  sizeof(u16)				 },
  87.399 +	{ &BG3PD,			  sizeof(u16)				 },
  87.400 +	{ &BG3X_L,			  sizeof(u16)				 },
  87.401 +	{ &BG3X_H,			  sizeof(u16)				 },
  87.402 +	{ &BG3Y_L,			  sizeof(u16)				 },
  87.403 +	{ &BG3Y_H,			  sizeof(u16)				 },
  87.404 +	{ &WIN0H,			  sizeof(u16)				 },
  87.405 +	{ &WIN1H,			  sizeof(u16)				 },
  87.406 +	{ &WIN0V,			  sizeof(u16)				 },
  87.407 +	{ &WIN1V,			  sizeof(u16)				 },
  87.408 +	{ &WININ,			  sizeof(u16)				 },
  87.409 +	{ &WINOUT,			  sizeof(u16)				 },
  87.410 +	{ &MOSAIC,			  sizeof(u16)				 },
  87.411 +	{ &BLDMOD,			  sizeof(u16)				 },
  87.412 +	{ &COLEV,			  sizeof(u16)				 },
  87.413 +	{ &COLY,			  sizeof(u16)				 },
  87.414 +	{ &DM0SAD_L,		  sizeof(u16)				 },
  87.415 +	{ &DM0SAD_H,		  sizeof(u16)				 },
  87.416 +	{ &DM0DAD_L,		  sizeof(u16)				 },
  87.417 +	{ &DM0DAD_H,		  sizeof(u16)				 },
  87.418 +	{ &DM0CNT_L,		  sizeof(u16)				 },
  87.419 +	{ &DM0CNT_H,		  sizeof(u16)				 },
  87.420 +	{ &DM1SAD_L,		  sizeof(u16)				 },
  87.421 +	{ &DM1SAD_H,		  sizeof(u16)				 },
  87.422 +	{ &DM1DAD_L,		  sizeof(u16)				 },
  87.423 +	{ &DM1DAD_H,		  sizeof(u16)				 },
  87.424 +	{ &DM1CNT_L,		  sizeof(u16)				 },
  87.425 +	{ &DM1CNT_H,		  sizeof(u16)				 },
  87.426 +	{ &DM2SAD_L,		  sizeof(u16)				 },
  87.427 +	{ &DM2SAD_H,		  sizeof(u16)				 },
  87.428 +	{ &DM2DAD_L,		  sizeof(u16)				 },
  87.429 +	{ &DM2DAD_H,		  sizeof(u16)				 },
  87.430 +	{ &DM2CNT_L,		  sizeof(u16)				 },
  87.431 +	{ &DM2CNT_H,		  sizeof(u16)				 },
  87.432 +	{ &DM3SAD_L,		  sizeof(u16)				 },
  87.433 +	{ &DM3SAD_H,		  sizeof(u16)				 },
  87.434 +	{ &DM3DAD_L,		  sizeof(u16)				 },
  87.435 +	{ &DM3DAD_H,		  sizeof(u16)				 },
  87.436 +	{ &DM3CNT_L,		  sizeof(u16)				 },
  87.437 +	{ &DM3CNT_H,		  sizeof(u16)				 },
  87.438 +	{ &TM0D,			  sizeof(u16)				 },
  87.439 +	{ &TM0CNT,			  sizeof(u16)				 },
  87.440 +	{ &TM1D,			  sizeof(u16)				 },
  87.441 +	{ &TM1CNT,			  sizeof(u16)				 },
  87.442 +	{ &TM2D,			  sizeof(u16)				 },
  87.443 +	{ &TM2CNT,			  sizeof(u16)				 },
  87.444 +	{ &TM3D,			  sizeof(u16)				 },
  87.445 +	{ &TM3CNT,			  sizeof(u16)				 },
  87.446 +	{ &P1,				  sizeof(u16)				 },
  87.447 +	{ &IE,				  sizeof(u16)				 },
  87.448 +	{ &IF,				  sizeof(u16)				 },
  87.449 +	{ &IME,				  sizeof(u16)				 },
  87.450 +	{ &holdState,		  sizeof(bool8)				 },
  87.451 +	{ &holdType,		  sizeof(int32)				 },
  87.452 +	{ &lcdTicks,		  sizeof(int32)				 },
  87.453 +	{ &timer0On,		  sizeof(bool8)				 },
  87.454 +	{ &timer0Ticks,		  sizeof(int32)				 },
  87.455 +	{ &timer0Reload,	  sizeof(int32)				 },
  87.456 +	{ &timer0ClockReload, sizeof(int32)				 },
  87.457 +	{ &timer1On,		  sizeof(bool8)				 },
  87.458 +	{ &timer1Ticks,		  sizeof(int32)				 },
  87.459 +	{ &timer1Reload,	  sizeof(int32)				 },
  87.460 +	{ &timer1ClockReload, sizeof(int32)				 },
  87.461 +	{ &timer2On,		  sizeof(bool8)				 },
  87.462 +	{ &timer2Ticks,		  sizeof(int32)				 },
  87.463 +	{ &timer2Reload,	  sizeof(int32)				 },
  87.464 +	{ &timer2ClockReload, sizeof(int32)				 },
  87.465 +	{ &timer3On,		  sizeof(bool8)				 },
  87.466 +	{ &timer3Ticks,		  sizeof(int32)				 },
  87.467 +	{ &timer3Reload,	  sizeof(int32)				 },
  87.468 +	{ &timer3ClockReload, sizeof(int32)				 },
  87.469 +	{ &dma0Source,		  sizeof(u32)				 },
  87.470 +	{ &dma0Dest,		  sizeof(u32)				 },
  87.471 +	{ &dma1Source,		  sizeof(u32)				 },
  87.472 +	{ &dma1Dest,		  sizeof(u32)				 },
  87.473 +	{ &dma2Source,		  sizeof(u32)				 },
  87.474 +	{ &dma2Dest,		  sizeof(u32)				 },
  87.475 +	{ &dma3Source,		  sizeof(u32)				 },
  87.476 +	{ &dma3Dest,		  sizeof(u32)				 },
  87.477 +	{ &fxOn,			  sizeof(bool8)				 },
  87.478 +	{ &windowOn,		  sizeof(bool8)				 },
  87.479 +	{ &N_FLAG,			  sizeof(bool8)				 },
  87.480 +	{ &C_FLAG,			  sizeof(bool8)				 },
  87.481 +	{ &Z_FLAG,			  sizeof(bool8)				 },
  87.482 +	{ &V_FLAG,			  sizeof(bool8)				 },
  87.483 +	{ &armState,		  sizeof(bool8)				 },
  87.484 +	{ &armIrqEnable,	  sizeof(bool8)				 },
  87.485 +	{ &armNextPC,		  sizeof(u32)				 },
  87.486 +	{ &armMode,			  sizeof(int32)				 },
  87.487 +	{ &saveType,		  sizeof(int32)				 },
  87.488 +	{ NULL,				  0							 }
  87.489 +};
  87.490 +
  87.491 +//int cpuLoopTicks = 0;
  87.492 +int cpuSavedTicks = 0;
  87.493 +
  87.494 +#ifdef PROFILING
  87.495 +void cpuProfil(char *buf, int size, u32 lowPC, int scale)
  87.496 +{
  87.497 +	profilBuffer = buf;
  87.498 +	profilSize	 = size;
  87.499 +	profilLowPC	 = lowPC;
  87.500 +	profilScale	 = scale;
  87.501 +}
  87.502 +
  87.503 +void cpuEnableProfiling(int hz)
  87.504 +{
  87.505 +	if (hz == 0)
  87.506 +		hz = 100;
  87.507 +	profilingTicks = profilingTicksReload = 16777216 / hz;
  87.508 +	profSetHertz(hz);
  87.509 +}
  87.510 +
  87.511 +#endif
  87.512 +
  87.513 +inline int CPUUpdateTicksAccess32(u32 address)
  87.514 +{
  87.515 +	return memoryWait32[(address >> 24) & 15];
  87.516 +}
  87.517 +
  87.518 +inline int CPUUpdateTicksAccess16(u32 address)
  87.519 +{
  87.520 +	return memoryWait[(address >> 24) & 15];
  87.521 +}
  87.522 +
  87.523 +inline int CPUUpdateTicksAccessSeq32(u32 address)
  87.524 +{
  87.525 +	return memoryWaitSeq32[(address >> 24) & 15];
  87.526 +}
  87.527 +
  87.528 +inline int CPUUpdateTicksAccessSeq16(u32 address)
  87.529 +{
  87.530 +	return memoryWaitSeq[(address >> 24) & 15];
  87.531 +}
  87.532 +
  87.533 +inline int CPUUpdateTicks()
  87.534 +{
  87.535 +	int cpuLoopTicks = lcdTicks;
  87.536 +
  87.537 +	if (soundTicks < cpuLoopTicks)
  87.538 +		cpuLoopTicks = soundTicks;
  87.539 +
  87.540 +	if (timer0On && !(TM0CNT & 4) && (timer0Ticks < cpuLoopTicks))
  87.541 +	{
  87.542 +		cpuLoopTicks = timer0Ticks;
  87.543 +	}
  87.544 +	if (timer1On && !(TM1CNT & 4) && (timer1Ticks < cpuLoopTicks))
  87.545 +	{
  87.546 +		cpuLoopTicks = timer1Ticks;
  87.547 +	}
  87.548 +	if (timer2On && !(TM2CNT & 4) && (timer2Ticks < cpuLoopTicks))
  87.549 +	{
  87.550 +		cpuLoopTicks = timer2Ticks;
  87.551 +	}
  87.552 +	if (timer3On && !(TM3CNT & 4) && (timer3Ticks < cpuLoopTicks))
  87.553 +	{
  87.554 +		cpuLoopTicks = timer3Ticks;
  87.555 +	}
  87.556 +#ifdef PROFILING
  87.557 +	if (profilingTicksReload != 0)
  87.558 +	{
  87.559 +		if (profilingTicks < cpuLoopTicks)
  87.560 +		{
  87.561 +			cpuLoopTicks = profilingTicks;
  87.562 +		}
  87.563 +	}
  87.564 +#endif
  87.565 +	cpuSavedTicks = cpuLoopTicks;
  87.566 +	return cpuLoopTicks;
  87.567 +}
  87.568 +
  87.569 +void CPUUpdateWindow0()
  87.570 +{
  87.571 +	int x00 = WIN0H >> 8;
  87.572 +	int x01 = WIN0H & 255;
  87.573 +
  87.574 +	if (x00 <= x01)
  87.575 +	{
  87.576 +		for (int i = 0; i < 240; i++)
  87.577 +		{
  87.578 +			gfxInWin0[i] = (i >= x00 && i < x01);
  87.579 +		}
  87.580 +	}
  87.581 +	else
  87.582 +	{
  87.583 +		for (int i = 0; i < 240; i++)
  87.584 +		{
  87.585 +			gfxInWin0[i] = (i >= x00 || i < x01);
  87.586 +		}
  87.587 +	}
  87.588 +}
  87.589 +
  87.590 +void CPUUpdateWindow1()
  87.591 +{
  87.592 +	int x00 = WIN1H >> 8;
  87.593 +	int x01 = WIN1H & 255;
  87.594 +
  87.595 +	if (x00 <= x01)
  87.596 +	{
  87.597 +		for (int i = 0; i < 240; i++)
  87.598 +		{
  87.599 +			gfxInWin1[i] = (i >= x00 && i < x01);
  87.600 +		}
  87.601 +	}
  87.602 +	else
  87.603 +	{
  87.604 +		for (int i = 0; i < 240; i++)
  87.605 +		{
  87.606 +			gfxInWin1[i] = (i >= x00 || i < x01);
  87.607 +		}
  87.608 +	}
  87.609 +}
  87.610 +
  87.611 +#define CLEAR_ARRAY(a) \
  87.612 +	{ \
  87.613 +		u32 *array = (a); \
  87.614 +		for (int i = 0; i < 240; i++) { \
  87.615 +			*array++ = 0x80000000; \
  87.616 +		} \
  87.617 +	} \
  87.618 +
  87.619 +void CPUUpdateRenderBuffers(bool force)
  87.620 +{
  87.621 +	if (!(layerEnable & 0x0100) || force)
  87.622 +	{
  87.623 +		CLEAR_ARRAY(line0);
  87.624 +	}
  87.625 +	if (!(layerEnable & 0x0200) || force)
  87.626 +	{
  87.627 +		CLEAR_ARRAY(line1);
  87.628 +	}
  87.629 +	if (!(layerEnable & 0x0400) || force)
  87.630 +	{
  87.631 +		CLEAR_ARRAY(line2);
  87.632 +	}
  87.633 +	if (!(layerEnable & 0x0800) || force)
  87.634 +	{
  87.635 +		CLEAR_ARRAY(line3);
  87.636 +	}
  87.637 +}
  87.638 +
  87.639 +bool CPUWriteStateToStream(gzFile gzFile)
  87.640 +{
  87.641 +	utilWriteInt(gzFile, SAVE_GAME_VERSION);
  87.642 +
  87.643 +	utilGzWrite(gzFile, &rom[0xa0], 16);
  87.644 +
  87.645 +	utilWriteInt(gzFile, useBios);
  87.646 +
  87.647 +	utilGzWrite(gzFile, &reg[0], sizeof(reg));
  87.648 +
  87.649 +	utilWriteData(gzFile, saveGameStruct);
  87.650 +
  87.651 +	// new to version 0.7.1
  87.652 +	utilWriteInt(gzFile, stopState);
  87.653 +	// new to version 0.8
  87.654 +	utilWriteInt(gzFile, intState);
  87.655 +
  87.656 +	utilGzWrite(gzFile, internalRAM, 0x8000);
  87.657 +	utilGzWrite(gzFile, paletteRAM, 0x400);
  87.658 +	utilGzWrite(gzFile, workRAM, 0x40000);
  87.659 +	utilGzWrite(gzFile, vram, 0x20000);
  87.660 +	utilGzWrite(gzFile, oam, 0x400);
  87.661 +	utilGzWrite(gzFile, pix, 4 * 241 * 162);
  87.662 +	utilGzWrite(gzFile, ioMem, 0x400);
  87.663 +
  87.664 +	eepromSaveGame(gzFile);
  87.665 +	flashSaveGame(gzFile);
  87.666 +	soundSaveGame(gzFile);
  87.667 +
  87.668 +	cheatsSaveGame(gzFile);
  87.669 +
  87.670 +	// version 1.5
  87.671 +	rtcSaveGame(gzFile);
  87.672 +
  87.673 +	// SAVE_GAME_VERSION_9 (new to re-recording version which is based on 1.72)
  87.674 +	{
  87.675 +		extern int32 sensorX, sensorY; // from SDL.cpp
  87.676 +		utilGzWrite(gzFile, &sensorX, sizeof(sensorX));
  87.677 +		utilGzWrite(gzFile, &sensorY, sizeof(sensorY));
  87.678 +		bool8 movieActive = VBAMovieActive();
  87.679 +		utilGzWrite(gzFile, &movieActive, sizeof(movieActive));
  87.680 +		if (movieActive)
  87.681 +		{
  87.682 +			uint8 *movie_freeze_buf	 = NULL;
  87.683 +			uint32 movie_freeze_size = 0;
  87.684 +
  87.685 +			VBAMovieFreeze(&movie_freeze_buf, &movie_freeze_size);
  87.686 +			if (movie_freeze_buf)
  87.687 +			{
  87.688 +				utilGzWrite(gzFile, &movie_freeze_size, sizeof(movie_freeze_size));
  87.689 +				utilGzWrite(gzFile, movie_freeze_buf, movie_freeze_size);
  87.690 +				delete [] movie_freeze_buf;
  87.691 +			}
  87.692 +			else
  87.693 +			{
  87.694 +				systemMessage(0, N_("Failed to save movie snapshot."));
  87.695 +				return false;
  87.696 +			}
  87.697 +		}
  87.698 +		utilGzWrite(gzFile, &GBASystemCounters.frameCount, sizeof(GBASystemCounters.frameCount));
  87.699 +	}
  87.700 +
  87.701 +	// SAVE_GAME_VERSION_10
  87.702 +	{
  87.703 +		utilGzWrite(gzFile, memoryWait, 16 * sizeof(int32));
  87.704 +		utilGzWrite(gzFile, memoryWait32, 16 * sizeof(int32));
  87.705 +		utilGzWrite(gzFile, memoryWaitSeq, 16 * sizeof(int32));
  87.706 +		utilGzWrite(gzFile, memoryWaitSeq32, 16 * sizeof(int32));
  87.707 +		utilGzWrite(gzFile, memoryWaitFetch, 16 * sizeof(int32));
  87.708 +		utilGzWrite(gzFile, memoryWaitFetch32, 16 * sizeof(int32));
  87.709 +	}
  87.710 +
  87.711 +	// SAVE_GAME_VERSION_11
  87.712 +	{
  87.713 +		utilGzWrite(gzFile, &prefetchActive, sizeof(bool8));
  87.714 +		utilGzWrite(gzFile, &prefetchPrevActive, sizeof(bool8));
  87.715 +		utilGzWrite(gzFile, &prefetchApplies, sizeof(bool8));
  87.716 +	}
  87.717 +
  87.718 +	// SAVE_GAME_VERSION_12
  87.719 +	{
  87.720 +		utilGzWrite(gzFile, &memLagTempEnabled, sizeof(bool8)); // necessary
  87.721 +		utilGzWrite(gzFile, &speedHack, sizeof(bool8)); // just in case it's ever used...
  87.722 +	}
  87.723 +
  87.724 +	// SAVE_GAME_VERSION_13
  87.725 +	{
  87.726 +		utilGzWrite(gzFile, &GBASystemCounters.lagCount, sizeof(GBASystemCounters.lagCount));
  87.727 +		utilGzWrite(gzFile, &GBASystemCounters.lagged, sizeof(GBASystemCounters.lagged));
  87.728 +		utilGzWrite(gzFile, &GBASystemCounters.laggedLast, sizeof(GBASystemCounters.laggedLast));
  87.729 +	}
  87.730 +
  87.731 +	return true;
  87.732 +}
  87.733 +
  87.734 +bool CPUWriteState(const char *file)
  87.735 +{
  87.736 +	gzFile gzFile = utilGzOpen(file, "wb");
  87.737 +
  87.738 +	if (gzFile == NULL)
  87.739 +	{
  87.740 +		systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), file);
  87.741 +		return false;
  87.742 +	}
  87.743 +
  87.744 +	bool res = CPUWriteStateToStream(gzFile);
  87.745 +
  87.746 +	utilGzClose(gzFile);
  87.747 +
  87.748 +	return res;
  87.749 +}
  87.750 +
  87.751 +bool CPUWriteMemState(char *memory, int available)
  87.752 +{
  87.753 +	gzFile gzFile = utilMemGzOpen(memory, available, "w");
  87.754 +
  87.755 +	if (gzFile == NULL)
  87.756 +	{
  87.757 +		return false;
  87.758 +	}
  87.759 +
  87.760 +	bool res = CPUWriteStateToStream(gzFile);
  87.761 +
  87.762 +	long pos = utilGzTell(gzFile) + 8;
  87.763 +
  87.764 +	if (pos >= (available))
  87.765 +		res = false;
  87.766 +
  87.767 +	utilGzClose(gzFile);
  87.768 +
  87.769 +	return res;
  87.770 +}
  87.771 +
  87.772 +static int	tempStateID	  = 0;
  87.773 +static int	tempFailCount = 0;
  87.774 +static bool backupSafe	  = true;
  87.775 +
  87.776 +bool CPUReadStateFromStream(gzFile gzFile)
  87.777 +{
  87.778 +	bool8 ub;
  87.779 +	char  tempBackupName [128];
  87.780 +	if (backupSafe)
  87.781 +	{
  87.782 +		sprintf(tempBackupName, "gbatempsave%d.sav", tempStateID++);
  87.783 +		CPUWriteState(tempBackupName);
  87.784 +	}
  87.785 +
  87.786 +	int version = utilReadInt(gzFile);
  87.787 +
  87.788 +	if (version > SAVE_GAME_VERSION || version < SAVE_GAME_VERSION_1)
  87.789 +	{
  87.790 +		systemMessage(MSG_UNSUPPORTED_VBA_SGM,
  87.791 +		              N_("Unsupported VisualBoyAdvance save game version %d"),
  87.792 +		              version);
  87.793 +		goto failedLoad;
  87.794 +	}
  87.795 +
  87.796 +	u8 romname[17];
  87.797 +
  87.798 +	utilGzRead(gzFile, romname, 16);
  87.799 +
  87.800 +	if (memcmp(&rom[0xa0], romname, 16) != 0)
  87.801 +	{
  87.802 +		romname[16] = 0;
  87.803 +		for (int i = 0; i < 16; i++)
  87.804 +			if (romname[i] < 32)
  87.805 +				romname[i] = 32;
  87.806 +		systemMessage(MSG_CANNOT_LOAD_SGM, N_("Cannot load save game for %s"), romname);
  87.807 +		goto failedLoad;
  87.808 +	}
  87.809 +
  87.810 +	ub = utilReadInt(gzFile) ? true : false;
  87.811 +
  87.812 +	if (ub != useBios)
  87.813 +	{
  87.814 +		if (useBios)
  87.815 +			systemMessage(MSG_SAVE_GAME_NOT_USING_BIOS,
  87.816 +			              N_("Save game is not using the BIOS files"));
  87.817 +		else
  87.818 +			systemMessage(MSG_SAVE_GAME_USING_BIOS,
  87.819 +			              N_("Save game is using the BIOS file"));
  87.820 +		goto failedLoad;
  87.821 +	}
  87.822 +
  87.823 +	utilGzRead(gzFile, &reg[0], sizeof(reg));
  87.824 +
  87.825 +	utilReadData(gzFile, saveGameStruct);
  87.826 +
  87.827 +	if (version < SAVE_GAME_VERSION_3)
  87.828 +		stopState = false;
  87.829 +	else
  87.830 +		stopState = utilReadInt(gzFile) ? true : false;
  87.831 +
  87.832 +	if (version < SAVE_GAME_VERSION_4)
  87.833 +		intState = false;
  87.834 +	else
  87.835 +		intState = utilReadInt(gzFile) ? true : false;
  87.836 +
  87.837 +	utilGzRead(gzFile, internalRAM, 0x8000);
  87.838 +	utilGzRead(gzFile, paletteRAM, 0x400);
  87.839 +	utilGzRead(gzFile, workRAM, 0x40000);
  87.840 +	utilGzRead(gzFile, vram, 0x20000);
  87.841 +	utilGzRead(gzFile, oam, 0x400);
  87.842 +	if (version < SAVE_GAME_VERSION_6)
  87.843 +		utilGzRead(gzFile, pix, 4 * 240 * 160);
  87.844 +	else
  87.845 +		utilGzRead(gzFile, pix, 4 * 241 * 162);
  87.846 +	utilGzRead(gzFile, ioMem, 0x400);
  87.847 +
  87.848 +	eepromReadGame(gzFile, version);
  87.849 +	flashReadGame(gzFile, version);
  87.850 +	soundReadGame(gzFile, version);
  87.851 +
  87.852 +	if (version > SAVE_GAME_VERSION_1)
  87.853 +	{
  87.854 +		cheatsReadGame(gzFile);
  87.855 +	}
  87.856 +	if (version > SAVE_GAME_VERSION_6)
  87.857 +	{
  87.858 +		rtcReadGame(gzFile);
  87.859 +	}
  87.860 +
  87.861 +	if (version <= SAVE_GAME_VERSION_7)
  87.862 +	{
  87.863 +		u32 temp;
  87.864 +#define SWAP(a, b, c) \
  87.865 +	temp = (a); \
  87.866 +	(a)	 = (b) << 16 | (c); \
  87.867 +	(b)	 = (temp) >> 16; \
  87.868 +	(c)	 = (temp) & 0xFFFF;
  87.869 +
  87.870 +		SWAP(dma0Source, DM0SAD_H, DM0SAD_L);
  87.871 +		SWAP(dma0Dest,   DM0DAD_H, DM0DAD_L);
  87.872 +		SWAP(dma1Source, DM1SAD_H, DM1SAD_L);
  87.873 +		SWAP(dma1Dest,   DM1DAD_H, DM1DAD_L);
  87.874 +		SWAP(dma2Source, DM2SAD_H, DM2SAD_L);
  87.875 +		SWAP(dma2Dest,   DM2DAD_H, DM2DAD_L);
  87.876 +		SWAP(dma3Source, DM3SAD_H, DM3SAD_L);
  87.877 +		SWAP(dma3Dest,   DM3DAD_H, DM3DAD_L);
  87.878 +	}
  87.879 +
  87.880 +	// set pointers!
  87.881 +	layerEnable = layerSettings & DISPCNT;
  87.882 +
  87.883 +	CPUUpdateRender();
  87.884 +	CPUUpdateRenderBuffers(true);
  87.885 +	CPUUpdateWindow0();
  87.886 +	CPUUpdateWindow1();
  87.887 +	gbaSaveType = 0;
  87.888 +	switch (saveType)
  87.889 +	{
  87.890 +	case 0:
  87.891 +		cpuSaveGameFunc = flashSaveDecide;
  87.892 +		break;
  87.893 +	case 1:
  87.894 +		cpuSaveGameFunc = sramWrite;
  87.895 +		gbaSaveType		= 1;
  87.896 +		break;
  87.897 +	case 2:
  87.898 +		cpuSaveGameFunc = flashWrite;
  87.899 +		gbaSaveType		= 2;
  87.900 +		break;
  87.901 +	default:
  87.902 +		systemMessage(MSG_UNSUPPORTED_SAVE_TYPE,
  87.903 +		              N_("Unsupported save type %d"), saveType);
  87.904 +		break;
  87.905 +	}
  87.906 +	if (eepromInUse)
  87.907 +		gbaSaveType = 3;
  87.908 +
  87.909 +	systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
  87.910 +
  87.911 +	if (version >= SAVE_GAME_VERSION_9) // new to re-recording version:
  87.912 +	{
  87.913 +		extern int32 sensorX, sensorY; // from SDL.cpp
  87.914 +		utilGzRead(gzFile, &sensorX, sizeof(sensorX));
  87.915 +		utilGzRead(gzFile, &sensorY, sizeof(sensorY));
  87.916 +
  87.917 +		bool8 movieSnapshot;
  87.918 +		utilGzRead(gzFile, &movieSnapshot, sizeof(movieSnapshot));
  87.919 +		if (VBAMovieActive() && !movieSnapshot)
  87.920 +		{
  87.921 +			systemMessage(0, N_("Can't load a non-movie snapshot while a movie is active."));
  87.922 +			goto failedLoad;
  87.923 +		}
  87.924 +
  87.925 +		if (movieSnapshot) // even if a movie isn't active we still want to parse through this in case other stuff is added
  87.926 +		                   // later on in the save format
  87.927 +		{
  87.928 +			uint32 movieInputDataSize = 0;
  87.929 +			utilGzRead(gzFile, &movieInputDataSize, sizeof(movieInputDataSize));
  87.930 +			uint8 *local_movie_data = new uint8[movieInputDataSize];
  87.931 +			int	   readBytes		= utilGzRead(gzFile, local_movie_data, movieInputDataSize);
  87.932 +			if (readBytes != movieInputDataSize)
  87.933 +			{
  87.934 +				systemMessage(0, N_("Corrupt movie snapshot."));
  87.935 +				if (local_movie_data)
  87.936 +					delete [] local_movie_data;
  87.937 +				goto failedLoad;
  87.938 +			}
  87.939 +			int code = VBAMovieUnfreeze(local_movie_data, movieInputDataSize);
  87.940 +			if (local_movie_data)
  87.941 +				delete [] local_movie_data;
  87.942 +			if (code != MOVIE_SUCCESS && VBAMovieActive())
  87.943 +			{
  87.944 +				char errStr [1024];
  87.945 +				strcpy(errStr, "Failed to load movie snapshot");
  87.946 +				switch (code)
  87.947 +				{
  87.948 +				case MOVIE_NOT_FROM_THIS_MOVIE:
  87.949 +					strcat(errStr, ";\nSnapshot not from this movie"); break;
  87.950 +				case MOVIE_NOT_FROM_A_MOVIE:
  87.951 +					strcat(errStr, ";\nNot a movie snapshot"); break;                   // shouldn't get here...
  87.952 +				case MOVIE_SNAPSHOT_INCONSISTENT:
  87.953 +					strcat(errStr, ";\nSnapshot inconsistent with movie"); break;
  87.954 +				case MOVIE_WRONG_FORMAT:
  87.955 +					strcat(errStr, ";\nWrong format"); break;
  87.956 +				}
  87.957 +				strcat(errStr, ".");
  87.958 +				systemMessage(0, N_(errStr));
  87.959 +				goto failedLoad;
  87.960 +			}
  87.961 +		}
  87.962 +		utilGzRead(gzFile, &GBASystemCounters.frameCount, sizeof(GBASystemCounters.frameCount));
  87.963 +	}
  87.964 +	if (version >= SAVE_GAME_VERSION_10)
  87.965 +	{
  87.966 +		utilGzRead(gzFile, memoryWait, 16 * sizeof(int32));
  87.967 +		utilGzRead(gzFile, memoryWait32, 16 * sizeof(int32));
  87.968 +		utilGzRead(gzFile, memoryWaitSeq, 16 * sizeof(int32));
  87.969 +		utilGzRead(gzFile, memoryWaitSeq32, 16 * sizeof(int32));
  87.970 +		utilGzRead(gzFile, memoryWaitFetch, 16 * sizeof(int32));
  87.971 +		utilGzRead(gzFile, memoryWaitFetch32, 16 * sizeof(int32));
  87.972 +	}
  87.973 +	if (version >= SAVE_GAME_VERSION_11)
  87.974 +	{
  87.975 +		utilGzRead(gzFile, &prefetchActive, sizeof(bool8));
  87.976 +		//if(prefetchActive && !prefetchPrevActive) systemScreenMessage("pre-fetch enabled",3,600);
  87.977 +		//if(!prefetchActive && prefetchPrevActive) systemScreenMessage("pre-fetch disabled",3,600);
  87.978 +		utilGzRead(gzFile, &prefetchPrevActive, sizeof(bool8));
  87.979 +		utilGzRead(gzFile, &prefetchApplies, sizeof(bool8));
  87.980 +	}
  87.981 +	if (version >= SAVE_GAME_VERSION_12)
  87.982 +	{
  87.983 +		utilGzRead(gzFile, &memLagTempEnabled, sizeof(bool8)); // necessary
  87.984 +		utilGzRead(gzFile, &speedHack, sizeof(bool8)); // just in case it's ever used...
  87.985 +	}
  87.986 +	if (version >= SAVE_GAME_VERSION_13)
  87.987 +	{
  87.988 +		utilGzRead(gzFile, &GBASystemCounters.lagCount, sizeof(GBASystemCounters.lagCount));
  87.989 +		utilGzRead(gzFile, &GBASystemCounters.lagged, sizeof(GBASystemCounters.lagged));
  87.990 +		utilGzRead(gzFile, &GBASystemCounters.laggedLast, sizeof(GBASystemCounters.laggedLast));
  87.991 +	}
  87.992 +
  87.993 +	if (backupSafe)
  87.994 +	{
  87.995 +		remove(tempBackupName);
  87.996 +		tempFailCount = 0;
  87.997 +	}
  87.998 +	systemSetJoypad(0, ~P1 & 0x3FF);
  87.999 +	VBAUpdateButtonPressDisplay();
 87.1000 +	VBAUpdateFrameCountDisplay();
 87.1001 +	systemRefreshScreen();
 87.1002 +	return true;
 87.1003 +
 87.1004 +failedLoad:
 87.1005 +	if (backupSafe)
 87.1006 +	{
 87.1007 +		tempFailCount++;
 87.1008 +		if (tempFailCount < 3) // fail no more than 2 times in a row
 87.1009 +			CPUReadState(tempBackupName);
 87.1010 +		remove(tempBackupName);
 87.1011 +	}
 87.1012 +	return false;
 87.1013 +}
 87.1014 +
 87.1015 +bool CPUReadMemState(char *memory, int available)
 87.1016 +{
 87.1017 +	gzFile gzFile = utilMemGzOpen(memory, available, "r");
 87.1018 +
 87.1019 +	backupSafe = false;
 87.1020 +	bool res = CPUReadStateFromStream(gzFile);
 87.1021 +	backupSafe = true;
 87.1022 +
 87.1023 +	utilGzClose(gzFile);
 87.1024 +
 87.1025 +	return res;
 87.1026 +}
 87.1027 +
 87.1028 +bool CPUReadState(const char *file)
 87.1029 +{
 87.1030 +	gzFile gzFile = utilGzOpen(file, "rb");
 87.1031 +
 87.1032 +	if (gzFile == NULL)
 87.1033 +		return false;
 87.1034 +
 87.1035 +	bool res = CPUReadStateFromStream(gzFile);
 87.1036 +
 87.1037 +	utilGzClose(gzFile);
 87.1038 +
 87.1039 +	return res;
 87.1040 +}
 87.1041 +
 87.1042 +bool CPUExportEepromFile(const char *fileName)
 87.1043 +{
 87.1044 +	if (eepromInUse)
 87.1045 +	{
 87.1046 +		FILE *file = fopen(fileName, "wb");
 87.1047 +
 87.1048 +		if (!file)
 87.1049 +		{
 87.1050 +			systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"),
 87.1051 +			              fileName);
 87.1052 +			return false;
 87.1053 +		}
 87.1054 +
 87.1055 +		for (int i = 0; i < eepromSize; )
 87.1056 +		{
 87.1057 +			for (int j = 0; j < 8; j++)
 87.1058 +			{
 87.1059 +				if (fwrite(&eepromData[i + 7 - j], 1, 1, file) != 1)
 87.1060 +				{
 87.1061 +					fclose(file);
 87.1062 +					return false;
 87.1063 +				}
 87.1064 +			}
 87.1065 +			i += 8;
 87.1066 +		}
 87.1067 +		fclose(file);
 87.1068 +	}
 87.1069 +	return true;
 87.1070 +}
 87.1071 +
 87.1072 +bool CPUWriteBatteryToStream(gzFile gzFile)
 87.1073 +{
 87.1074 +	if (!gzFile)
 87.1075 +		return false;
 87.1076 +
 87.1077 +	utilWriteInt(gzFile, SAVE_GAME_VERSION);
 87.1078 +
 87.1079 +	// for simplicity, we put both types of battery files should be in the stream, even if one's empty
 87.1080 +	eepromSaveGame(gzFile);
 87.1081 +	flashSaveGame(gzFile);
 87.1082 +
 87.1083 +	return true;
 87.1084 +}
 87.1085 +
 87.1086 +bool CPUWriteBatteryFile(const char *fileName)
 87.1087 +{
 87.1088 +	if (gbaSaveType == 0)
 87.1089 +	{
 87.1090 +		if (eepromInUse)
 87.1091 +			gbaSaveType = 3;
 87.1092 +		else
 87.1093 +			switch (saveType)
 87.1094 +			{
 87.1095 +			case 1:
 87.1096 +				gbaSaveType = 1;
 87.1097 +				break;
 87.1098 +			case 2:
 87.1099 +				gbaSaveType = 2;
 87.1100 +				break;
 87.1101 +			}
 87.1102 +	}
 87.1103 +
 87.1104 +	if (gbaSaveType)
 87.1105 +	{
 87.1106 +		FILE *file = fopen(fileName, "wb");
 87.1107 +
 87.1108 +		if (!file)
 87.1109 +		{
 87.1110 +			systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"),
 87.1111 +			              fileName);
 87.1112 +			return false;
 87.1113 +		}
 87.1114 +
 87.1115 +		// only save if Flash/Sram in use or EEprom in use
 87.1116 +		if (gbaSaveType != 3)
 87.1117 +		{
 87.1118 +			if (gbaSaveType == 2)
 87.1119 +			{
 87.1120 +				if (fwrite(flashSaveMemory, 1, flashSize, file) != (size_t)flashSize)
 87.1121 +				{
 87.1122 +					fclose(file);
 87.1123 +					return false;
 87.1124 +				}
 87.1125 +			}
 87.1126 +			else
 87.1127 +			{
 87.1128 +				if (fwrite(flashSaveMemory, 1, 0x10000, file) != 0x10000)
 87.1129 +				{
 87.1130 +					fclose(file);
 87.1131 +					return false;
 87.1132 +				}
 87.1133 +			}
 87.1134 +		}
 87.1135 +		else
 87.1136 +		{
 87.1137 +			if (fwrite(eepromData, 1, eepromSize, file) != (size_t)eepromSize)
 87.1138 +			{
 87.1139 +				fclose(file);
 87.1140 +				return false;
 87.1141 +			}
 87.1142 +		}
 87.1143 +		fclose(file);
 87.1144 +	}
 87.1145 +
 87.1146 +	return true;
 87.1147 +}
 87.1148 +
 87.1149 +bool CPUReadGSASnapshot(const char *fileName)
 87.1150 +{
 87.1151 +	int	  i;
 87.1152 +	FILE *file = fopen(fileName, "rb");
 87.1153 +
 87.1154 +	if (!file)
 87.1155 +	{
 87.1156 +		systemMessage(MSG_CANNOT_OPEN_FILE, N_("Cannot open file %s"), fileName);
 87.1157 +		return false;
 87.1158 +	}
 87.1159 +
 87.1160 +	// check file size to know what we should read
 87.1161 +	fseek(file, 0, SEEK_END);
 87.1162 +
 87.1163 +	// long size = ftell(file);
 87.1164 +	fseek(file, 0x0, SEEK_SET);
 87.1165 +	fread(&i, 1, 4, file);
 87.1166 +	fseek(file, i, SEEK_CUR); // Skip SharkPortSave
 87.1167 +	fseek(file, 4, SEEK_CUR); // skip some sort of flag
 87.1168 +	fread(&i, 1, 4, file); // name length
 87.1169 +	fseek(file, i, SEEK_CUR); // skip name
 87.1170 +	fread(&i, 1, 4, file); // desc length
 87.1171 +	fseek(file, i, SEEK_CUR); // skip desc
 87.1172 +	fread(&i, 1, 4, file); // notes length
 87.1173 +	fseek(file, i, SEEK_CUR); // skip notes
 87.1174 +	int saveSize;
 87.1175 +	fread(&saveSize, 1, 4, file); // read length
 87.1176 +	saveSize -= 0x1c; // remove header size
 87.1177 +	char buffer[17];
 87.1178 +	char buffer2[17];
 87.1179 +	fread(buffer, 1, 16, file);
 87.1180 +	buffer[16] = 0;
 87.1181 +	for (i = 0; i < 16; i++)
 87.1182 +		if (buffer[i] < 32)
 87.1183 +			buffer[i] = 32;
 87.1184 +	memcpy(buffer2, &rom[0xa0], 16);
 87.1185 +	buffer2[16] = 0;
 87.1186 +	for (i = 0; i < 16; i++)
 87.1187 +		if (buffer2[i] < 32)
 87.1188 +			buffer2[i] = 32;
 87.1189 +	if (memcmp(buffer, buffer2, 16))
 87.1190 +	{
 87.1191 +		systemMessage(MSG_CANNOT_IMPORT_SNAPSHOT_FOR,
 87.1192 +		              N_("Cannot import snapshot for %s. Current game is %s"),
 87.1193 +		              buffer,
 87.1194 +		              buffer2);
 87.1195 +		fclose(file);
 87.1196 +		return false;
 87.1197 +	}
 87.1198 +	fseek(file, 12, SEEK_CUR); // skip some flags
 87.1199 +	if (saveSize >= 65536)
 87.1200 +	{
 87.1201 +		if (fread(flashSaveMemory, 1, saveSize, file) != (size_t)saveSize)
 87.1202 +		{
 87.1203 +			fclose(file);
 87.1204 +			return false;
 87.1205 +		}
 87.1206 +	}
 87.1207 +	else
 87.1208 +	{
 87.1209 +		systemMessage(MSG_UNSUPPORTED_SNAPSHOT_FILE,
 87.1210 +		              N_("Unsupported snapshot file %s"),
 87.1211 +		              fileName);
 87.1212 +		fclose(file);
 87.1213 +		return false;
 87.1214 +	}
 87.1215 +	fclose(file);
 87.1216 +	CPUReset();
 87.1217 +	return true;
 87.1218 +}
 87.1219 +
 87.1220 +bool CPUWriteGSASnapshot(const char *fileName,
 87.1221 +                         const char *title,
 87.1222 +                         const char *desc,
 87.1223 +                         const char *notes)
 87.1224 +{
 87.1225 +	FILE *file = fopen(fileName, "wb");
 87.1226 +
 87.1227 +	if (!file)
 87.1228 +	{
 87.1229 +		systemMessage(MSG_CANNOT_OPEN_FILE, N_("Cannot open file %s"), fileName);
 87.1230 +		return false;
 87.1231 +	}
 87.1232 +
 87.1233 +	u8 buffer[17];
 87.1234 +
 87.1235 +	utilPutDword(buffer, 0x0d); // SharkPortSave length
 87.1236 +	fwrite(buffer, 1, 4, file);
 87.1237 +	fwrite("SharkPortSave", 1, 0x0d, file);
 87.1238 +	utilPutDword(buffer, 0x000f0000);
 87.1239 +	fwrite(buffer, 1, 4, file); // save type 0x000f0000 = GBA save
 87.1240 +	utilPutDword(buffer, strlen(title));
 87.1241 +	fwrite(buffer, 1, 4, file); // title length
 87.1242 +	fwrite(title, 1, strlen(title), file);
 87.1243 +	utilPutDword(buffer, strlen(desc));
 87.1244 +	fwrite(buffer, 1, 4, file); // desc length
 87.1245 +	fwrite(desc, 1, strlen(desc), file);
 87.1246 +	utilPutDword(buffer, strlen(notes));
 87.1247 +	fwrite(buffer, 1, 4, file); // notes length
 87.1248 +	fwrite(notes, 1, strlen(notes), file);
 87.1249 +	int saveSize = 0x10000;
 87.1250 +	if (gbaSaveType == 2)
 87.1251 +		saveSize = flashSize;
 87.1252 +	int totalSize = saveSize + 0x1c;
 87.1253 +
 87.1254 +	utilPutDword(buffer, totalSize); // length of remainder of save - CRC
 87.1255 +	fwrite(buffer, 1, 4, file);
 87.1256 +
 87.1257 +	char temp[0x2001c];
 87.1258 +	memset(temp, 0, 28);
 87.1259 +	memcpy(temp, &rom[0xa0], 16); // copy internal name
 87.1260 +	temp[0x10] = rom[0xbe]; // reserved area (old checksum)
 87.1261 +	temp[0x11] = rom[0xbf]; // reserved area (old checksum)
 87.1262 +	temp[0x12] = rom[0xbd]; // complement check
 87.1263 +	temp[0x13] = rom[0xb0]; // maker
 87.1264 +	temp[0x14] = 1; // 1 save ?
 87.1265 +	memcpy(&temp[0x1c], flashSaveMemory, saveSize); // copy save
 87.1266 +	fwrite(temp, 1, totalSize, file); // write save + header
 87.1267 +	u32 crc = 0;
 87.1268 +
 87.1269 +	for (int i = 0; i < totalSize; i++)
 87.1270 +	{
 87.1271 +		crc += ((u32)temp[i] << (crc % 0x18));
 87.1272 +	}
 87.1273 +
 87.1274 +	utilPutDword(buffer, crc);
 87.1275 +	fwrite(buffer, 1, 4, file); // CRC?
 87.1276 +
 87.1277 +	fclose(file);
 87.1278 +	return true;
 87.1279 +}
 87.1280 +
 87.1281 +bool CPUImportEepromFile(const char *fileName)
 87.1282 +{
 87.1283 +	FILE *file = fopen(fileName, "rb");
 87.1284 +
 87.1285 +	if (!file)
 87.1286 +		return false;
 87.1287 +
 87.1288 +	// check file size to know what we should read
 87.1289 +	fseek(file, 0, SEEK_END);
 87.1290 +
 87.1291 +	long size = ftell(file);
 87.1292 +	fseek(file, 0, SEEK_SET);
 87.1293 +	if (size == 512 || size == 0x2000)
 87.1294 +	{
 87.1295 +		if (fread(eepromData, 1, size, file) != (size_t)size)
 87.1296 +		{
 87.1297 +			fclose(file);
 87.1298 +			return false;
 87.1299 +		}
 87.1300 +		for (int i = 0; i < size; )
 87.1301 +		{
 87.1302 +			u8 tmp = eepromData[i];
 87.1303 +			eepromData[i]	  = eepromData[7 - i];
 87.1304 +			eepromData[7 - i] = tmp;
 87.1305 +			i++;
 87.1306 +			tmp = eepromData[i];
 87.1307 +			eepromData[i]	  = eepromData[7 - i];
 87.1308 +			eepromData[7 - i] = tmp;
 87.1309 +			i++;
 87.1310 +			tmp = eepromData[i];
 87.1311 +			eepromData[i]	  = eepromData[7 - i];
 87.1312 +			eepromData[7 - i] = tmp;
 87.1313 +			i++;
 87.1314 +			tmp = eepromData[i];
 87.1315 +			eepromData[i]	  = eepromData[7 - i];
 87.1316 +			eepromData[7 - i] = tmp;
 87.1317 +			i++;
 87.1318 +			i += 4;
 87.1319 +		}
 87.1320 +	}
 87.1321 +	else
 87.1322 +	{
 87.1323 +		fclose(file);
 87.1324 +		return false;
 87.1325 +	}
 87.1326 +	fclose(file);
 87.1327 +	return true;
 87.1328 +}
 87.1329 +
 87.1330 +bool CPUReadBatteryFromStream(gzFile gzFile)
 87.1331 +{
 87.1332 +	if (!gzFile)
 87.1333 +		return false;
 87.1334 +
 87.1335 +	int version = utilReadInt(gzFile);
 87.1336 +
 87.1337 +	// for simplicity, we put both types of battery files should be in the stream, even if one's empty
 87.1338 +	eepromReadGame(gzFile, version);
 87.1339 +	flashReadGame(gzFile, version);
 87.1340 +
 87.1341 +	return true;
 87.1342 +}
 87.1343 +
 87.1344 +bool CPUReadBatteryFile(const char *fileName)
 87.1345 +{
 87.1346 +	FILE *file = fopen(fileName, "rb");
 87.1347 +
 87.1348 +	if (!file)
 87.1349 +		return false;
 87.1350 +
 87.1351 +	// check file size to know what we should read
 87.1352 +	fseek(file, 0, SEEK_END);
 87.1353 +
 87.1354 +	long size = ftell(file);
 87.1355 +	fseek(file, 0, SEEK_SET);
 87.1356 +	systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
 87.1357 +
 87.1358 +	if (size == 512 || size == 0x2000)
 87.1359 +	{
 87.1360 +		if (fread(eepromData, 1, size, file) != (size_t)size)
 87.1361 +		{
 87.1362 +			fclose(file);
 87.1363 +			return false;
 87.1364 +		}
 87.1365 +	}
 87.1366 +	else
 87.1367 +	{
 87.1368 +		if (size == 0x20000)
 87.1369 +		{
 87.1370 +			if (fread(flashSaveMemory, 1, 0x20000, file) != 0x20000)
 87.1371 +			{
 87.1372 +				fclose(file);
 87.1373 +				return false;
 87.1374 +			}
 87.1375 +			flashSetSize(0x20000);
 87.1376 +		}
 87.1377 +		else
 87.1378 +		{
 87.1379 +			if (fread(flashSaveMemory, 1, 0x10000, file) != 0x10000)
 87.1380 +			{
 87.1381 +				fclose(file);
 87.1382 +				return false;
 87.1383 +			}
 87.1384 +			flashSetSize(0x10000);
 87.1385 +		}
 87.1386 +	}
 87.1387 +	fclose(file);
 87.1388 +	return true;
 87.1389 +}
 87.1390 +
 87.1391 +bool CPUWritePNGFile(const char *fileName)
 87.1392 +{
 87.1393 +	return utilWritePNGFile(fileName, 240, 160, pix);
 87.1394 +}
 87.1395 +
 87.1396 +bool CPUWriteBMPFile(const char *fileName)
 87.1397 +{
 87.1398 +	return utilWriteBMPFile(fileName, 240, 160, pix);
 87.1399 +}
 87.1400 +
 87.1401 +void CPUCleanUp()
 87.1402 +{
 87.1403 +	newFrame	  = true;
 87.1404 +
 87.1405 +	GBASystemCounters.frameCount = 0;
 87.1406 +	GBASystemCounters.lagCount	 = 0;
 87.1407 +	GBASystemCounters.extraCount = 0;
 87.1408 +	GBASystemCounters.lagged	 = true;
 87.1409 +	GBASystemCounters.laggedLast = true;
 87.1410 +
 87.1411 +#ifdef PROFILING
 87.1412 +	if (profilingTicksReload)
 87.1413 +	{
 87.1414 +		profCleanup();
 87.1415 +	}
 87.1416 +#endif
 87.1417 +
 87.1418 +#if (defined(WIN32) && !defined(SDL))
 87.1419 +	#define FreeMappedMem(name, mapName, offset) \
 87.1420 +	if (name != NULL) { \
 87.1421 +		UnmapViewOfFile((name) - (offset)); \
 87.1422 +		name = NULL; \
 87.1423 +		CloseHandle(mapName); \
 87.1424 +	}
 87.1425 +#else
 87.1426 +	#define FreeMappedMem(name, mapName, offset) \
 87.1427 +	if (name != NULL) { \
 87.1428 +		free(name); \
 87.1429 +		name = NULL; \
 87.1430 +	}
 87.1431 +#endif
 87.1432 +
 87.1433 +	FreeMappedMem(rom, mapROM, 0);
 87.1434 +	FreeMappedMem(vram, mapVRAM, 0);
 87.1435 +	FreeMappedMem(paletteRAM, mapPALETTERAM, 0);
 87.1436 +	FreeMappedMem(internalRAM, mapIRAM, 0);
 87.1437 +	FreeMappedMem(workRAM, mapWORKRAM, 0);
 87.1438 +	FreeMappedMem(bios, mapBIOS, 0);
 87.1439 +	FreeMappedMem(pix, mapPIX, 4);
 87.1440 +	FreeMappedMem(oam, mapOAM, 0);
 87.1441 +	FreeMappedMem(ioMem, mapIOMEM, 0);
 87.1442 +
 87.1443 +	eepromErase();
 87.1444 +	flashErase();
 87.1445 +
 87.1446 +	elfCleanUp();
 87.1447 +
 87.1448 +	systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
 87.1449 +
 87.1450 +	systemClearJoypads();
 87.1451 +	systemResetSensor();
 87.1452 +
 87.1453 +//	gbaLastTime = gbaFrameCount = 0;
 87.1454 +	systemRefreshScreen();
 87.1455 +}
 87.1456 +
 87.1457 +int CPULoadRom(const char *szFile)
 87.1458 +{
 87.1459 +	int size = 0x2000000;
 87.1460 +
 87.1461 +	if (rom != NULL)
 87.1462 +	{
 87.1463 +		CPUCleanUp();
 87.1464 +	}
 87.1465 +
 87.1466 +	systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
 87.1467 +
 87.1468 +	// size+4 is so RAM search and watch are safe to read any byte in the allocated region as a 4-byte int
 87.1469 +#if (defined(WIN32) && !defined(SDL))
 87.1470 +	#define AllocMappedMem(name, mapName, nameStr, size, useCalloc, offset) \
 87.1471 +	mapName = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (size) + (offset) + (4), nameStr); \
 87.1472 +	if ((mapName) && GetLastError() == ERROR_ALREADY_EXISTS) { \
 87.1473 +		CloseHandle(mapName); \
 87.1474 +		mapName = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (size) + (offset) + (4), NULL); \
 87.1475 +	} \
 87.1476 +	name = (u8 *)MapViewOfFile(mapName, FILE_MAP_WRITE, 0, 0, 0) + (offset); \
 87.1477 +	if ((name) == NULL) { \
 87.1478 +		systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"), nameStr); \
 87.1479 +		CPUCleanUp(); \
 87.1480 +		return 0; \
 87.1481 +	} \
 87.1482 +	memset(name, 0, size + 4);
 87.1483 +#else
 87.1484 +	#define AllocMappedMem(name, mapName, nameStr, size, useCalloc, offset) \
 87.1485 +	name = (u8 *)(useCalloc ? calloc(1, size + 4) : malloc(size + 4)); \
 87.1486 +	if ((name) == NULL) { \
 87.1487 +		systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"), nameStr); \
 87.1488 +		CPUCleanUp(); \
 87.1489 +		return 0; \
 87.1490 +	} \
 87.1491 +	memset(name, 0, size + 4);
 87.1492 +#endif
 87.1493 +
 87.1494 +	AllocMappedMem(rom, mapROM, "vbaROM", 0x2000000, false, 0);
 87.1495 +	AllocMappedMem(workRAM, mapWORKRAM, "vbaWORKRAM", 0x40000, true, 0);
 87.1496 +
 87.1497 +	u8 *whereToLoad = rom;
 87.1498 +	if (cpuIsMultiBoot)
 87.1499 +		whereToLoad = workRAM;
 87.1500 +
 87.1501 +	if (utilIsELF(szFile))
 87.1502 +	{
 87.1503 +		FILE *f = fopen(szFile, "rb");
 87.1504 +		if (!f)
 87.1505 +		{
 87.1506 +			systemMessage(MSG_ERROR_OPENING_IMAGE, N_("Error opening image %s"),
 87.1507 +			              szFile);
 87.1508 +			FreeMappedMem(rom, mapROM, 0);
 87.1509 +			FreeMappedMem(workRAM, mapWORKRAM, 0);
 87.1510 +			return 0;
 87.1511 +		}
 87.1512 +		bool res = elfRead(szFile, size, f);
 87.1513 +		if (!res || size == 0)
 87.1514 +		{
 87.1515 +			FreeMappedMem(rom, mapROM, 0);
 87.1516 +			FreeMappedMem(workRAM, mapWORKRAM, 0);
 87.1517 +			elfCleanUp();
 87.1518 +			return 0;
 87.1519 +		}
 87.1520 +	}
 87.1521 +	else if (!utilLoad(szFile,
 87.1522 +	                   utilIsGBAImage,
 87.1523 +	                   whereToLoad,
 87.1524 +	                   size))
 87.1525 +	{
 87.1526 +		FreeMappedMem(rom, mapROM, 0);
 87.1527 +		FreeMappedMem(workRAM, mapWORKRAM, 0);
 87.1528 +		return 0;
 87.1529 +	}
 87.1530 +
 87.1531 +	u16 *temp = (u16 *)(rom + ((size + 1) & ~1));
 87.1532 +	int	 i;
 87.1533 +	for (i = (size + 1) & ~1; i < 0x2000000; i += 2)
 87.1534 +	{
 87.1535 +		WRITE16LE(temp, (i >> 1) & 0xFFFF);
 87.1536 +		temp++;
 87.1537 +	}
 87.1538 +
 87.1539 +	AllocMappedMem(bios, mapBIOS, "vbaBIOS", 0x4000, true, 0);
 87.1540 +	AllocMappedMem(internalRAM, mapIRAM, "vbaIRAM", 0x8000, true, 0);
 87.1541 +	AllocMappedMem(paletteRAM, mapPALETTERAM, "vbaPALETTERAM", 0x400, true, 0);
 87.1542 +	AllocMappedMem(vram, mapVRAM, "vbaVRAM", 0x20000, true, 0);
 87.1543 +	AllocMappedMem(oam, mapOAM, "vbaOAM", 0x400, true, 0);
 87.1544 +
 87.1545 +	// HACK: +4 at start to accomodate the 2xSaI filter reading out of bounds of the leftmost pixel
 87.1546 +	AllocMappedMem(pix, mapPIX, "vbaPIX", 4 * 241 * 162, true, 4);
 87.1547 +	AllocMappedMem(ioMem, mapIOMEM, "vbaIOMEM", 0x400, true, 0);
 87.1548 +
 87.1549 +	CPUUpdateRenderBuffers(true);
 87.1550 +
 87.1551 +	return size;
 87.1552 +}
 87.1553 +
 87.1554 +void CPUUpdateRender()
 87.1555 +{
 87.1556 +	switch (DISPCNT & 7)
 87.1557 +	{
 87.1558 +	case 0:
 87.1559 +		if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) ||
 87.1560 +		    cpuDisableSfx)
 87.1561 +			renderLine = mode0RenderLine;
 87.1562 +		else if (fxOn && !windowOn && !(layerEnable & 0x8000))
 87.1563 +			renderLine = mode0RenderLineNoWindow;
 87.1564 +		else
 87.1565 +			renderLine = mode0RenderLineAll;
 87.1566 +		break;
 87.1567 +	case 1:
 87.1568 +		if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) ||
 87.1569 +		    cpuDisableSfx)
 87.1570 +			renderLine = mode1RenderLine;
 87.1571 +		else if (fxOn && !windowOn && !(layerEnable & 0x8000))
 87.1572 +			renderLine = mode1RenderLineNoWindow;
 87.1573 +		else
 87.1574 +			renderLine = mode1RenderLineAll;
 87.1575 +		break;
 87.1576 +	case 2:
 87.1577 +		if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) ||
 87.1578 +		    cpuDisableSfx)
 87.1579 +			renderLine = mode2RenderLine;
 87.1580 +		else if (fxOn && !windowOn && !(layerEnable & 0x8000))
 87.1581 +			renderLine = mode2RenderLineNoWindow;
 87.1582 +		else
 87.1583 +			renderLine = mode2RenderLineAll;
 87.1584 +		break;
 87.1585 +	case 3:
 87.1586 +		if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) ||
 87.1587 +		    cpuDisableSfx)
 87.1588 +			renderLine = mode3RenderLine;
 87.1589 +		else if (fxOn && !windowOn && !(layerEnable & 0x8000))
 87.1590 +			renderLine = mode3RenderLineNoWindow;
 87.1591 +		else
 87.1592 +			renderLine = mode3RenderLineAll;
 87.1593 +		break;
 87.1594 +	case 4:
 87.1595 +		if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) ||
 87.1596 +		    cpuDisableSfx)
 87.1597 +			renderLine = mode4RenderLine;
 87.1598 +		else if (fxOn && !windowOn && !(layerEnable & 0x8000))
 87.1599 +			renderLine = mode4RenderLineNoWindow;
 87.1600 +		else
 87.1601 +			renderLine = mode4RenderLineAll;
 87.1602 +		break;
 87.1603 +	case 5:
 87.1604 +		if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) ||
 87.1605 +		    cpuDisableSfx)
 87.1606 +			renderLine = mode5RenderLine;
 87.1607 +		else if (fxOn && !windowOn && !(layerEnable & 0x8000))
 87.1608 +			renderLine = mode5RenderLineNoWindow;
 87.1609 +		else
 87.1610 +			renderLine = mode5RenderLineAll;
 87.1611 +	default:
 87.1612 +		break;
 87.1613 +	}
 87.1614 +}
 87.1615 +
 87.1616 +void CPUUpdateCPSR()
 87.1617 +{
 87.1618 +	u32 CPSR = reg[16].I & 0x40;
 87.1619 +	if (N_FLAG)
 87.1620 +		CPSR |= 0x80000000;
 87.1621 +	if (Z_FLAG)
 87.1622 +		CPSR |= 0x40000000;
 87.1623 +	if (C_FLAG)
 87.1624 +		CPSR |= 0x20000000;
 87.1625 +	if (V_FLAG)
 87.1626 +		CPSR |= 0x10000000;
 87.1627 +	if (!armState)
 87.1628 +		CPSR |= 0x00000020;
 87.1629 +	if (!armIrqEnable)
 87.1630 +		CPSR |= 0x80;
 87.1631 +	CPSR	 |= (armMode & 0x1F);
 87.1632 +	reg[16].I = CPSR;
 87.1633 +}
 87.1634 +
 87.1635 +void CPUUpdateFlags(bool breakLoop)
 87.1636 +{
 87.1637 +	u32 CPSR = reg[16].I;
 87.1638 +
 87.1639 +	N_FLAG		 = (CPSR & 0x80000000) ? true : false;
 87.1640 +	Z_FLAG		 = (CPSR & 0x40000000) ? true : false;
 87.1641 +	C_FLAG		 = (CPSR & 0x20000000) ? true : false;
 87.1642 +	V_FLAG		 = (CPSR & 0x10000000) ? true : false;
 87.1643 +	armState	 = (CPSR & 0x20) ? false : true;
 87.1644 +	armIrqEnable = (CPSR & 0x80) ? false : true;
 87.1645 +	if (breakLoop)
 87.1646 +	{
 87.1647 +		if (armIrqEnable && (IF & IE) && (IME & 1))
 87.1648 +		{
 87.1649 +			CPU_BREAK_LOOP_2;
 87.1650 +		}
 87.1651 +	}
 87.1652 +}
 87.1653 +
 87.1654 +void CPUUpdateFlags()
 87.1655 +{
 87.1656 +	CPUUpdateFlags(true);
 87.1657 +}
 87.1658 +
 87.1659 +#ifdef WORDS_BIGENDIAN
 87.1660 +static void CPUSwap(volatile u32 *a, volatile u32 *b)
 87.1661 +{
 87.1662 +	volatile u32 c = *b;
 87.1663 +	*b = *a;
 87.1664 +	*a = c;
 87.1665 +}
 87.1666 +
 87.1667 +#else
 87.1668 +static void CPUSwap(u32 *a, u32 *b)
 87.1669 +{
 87.1670 +	u32 c = *b;
 87.1671 +	*b = *a;
 87.1672 +	*a = c;
 87.1673 +}
 87.1674 +
 87.1675 +#endif
 87.1676 +
 87.1677 +void CPUSwitchMode(int mode, bool saveState, bool breakLoop)
 87.1678 +{
 87.1679 +	//  if(armMode == mode)
 87.1680 +	//    return;
 87.1681 +
 87.1682 +	CPUUpdateCPSR();
 87.1683 +
 87.1684 +	switch (armMode)
 87.1685 +	{
 87.1686 +	case 0x10:
 87.1687 +	case 0x1F:
 87.1688 +		reg[R13_USR].I = reg[13].I;
 87.1689 +		reg[R14_USR].I = reg[14].I;
 87.1690 +		reg[17].I	   = reg[16].I;
 87.1691 +		break;
 87.1692 +	case 0x11:
 87.1693 +		CPUSwap(&reg[R8_FIQ].I, &reg[8].I);
 87.1694 +		CPUSwap(&reg[R9_FIQ].I, &reg[9].I);
 87.1695 +		CPUSwap(&reg[R10_FIQ].I, &reg[10].I);
 87.1696 +		CPUSwap(&reg[R11_FIQ].I, &reg[11].I);
 87.1697 +		CPUSwap(&reg[R12_FIQ].I, &reg[12].I);
 87.1698 +		reg[R13_FIQ].I	= reg[13].I;
 87.1699 +		reg[R14_FIQ].I	= reg[14].I;
 87.1700 +		reg[SPSR_FIQ].I = reg[17].I;
 87.1701 +		break;
 87.1702 +	case 0x12:
 87.1703 +		reg[R13_IRQ].I	= reg[13].I;
 87.1704 +		reg[R14_IRQ].I	= reg[14].I;
 87.1705 +		reg[SPSR_IRQ].I =  reg[17].I;
 87.1706 +		break;
 87.1707 +	case 0x13:
 87.1708 +		reg[R13_SVC].I	= reg[13].I;
 87.1709 +		reg[R14_SVC].I	= reg[14].I;
 87.1710 +		reg[SPSR_SVC].I =  reg[17].I;
 87.1711 +		break;
 87.1712 +	case 0x17:
 87.1713 +		reg[R13_ABT].I	= reg[13].I;
 87.1714 +		reg[R14_ABT].I	= reg[14].I;
 87.1715 +		reg[SPSR_ABT].I =  reg[17].I;
 87.1716 +		break;
 87.1717 +	case 0x1b:
 87.1718 +		reg[R13_UND].I	= reg[13].I;
 87.1719 +		reg[R14_UND].I	= reg[14].I;
 87.1720 +		reg[SPSR_UND].I =  reg[17].I;
 87.1721 +		break;
 87.1722 +	}
 87.1723 +
 87.1724 +	u32 CPSR = reg[16].I;
 87.1725 +	u32 SPSR = reg[17].I;
 87.1726 +
 87.1727 +	switch (mode)
 87.1728 +	{
 87.1729 +	case 0x10:
 87.1730 +	case 0x1F:
 87.1731 +		reg[13].I = reg[R13_USR].I;
 87.1732 +		reg[14].I = reg[R14_USR].I;
 87.1733 +		reg[16].I = SPSR;
 87.1734 +		break;
 87.1735 +	case 0x11:
 87.1736 +		CPUSwap(&reg[8].I, &reg[R8_FIQ].I);
 87.1737 +		CPUSwap(&reg[9].I, &reg[R9_FIQ].I);
 87.1738 +		CPUSwap(&reg[10].I, &reg[R10_FIQ].I);
 87.1739 +		CPUSwap(&reg[11].I, &reg[R11_FIQ].I);
 87.1740 +		CPUSwap(&reg[12].I, &reg[R12_FIQ].I);
 87.1741 +		reg[13].I = reg[R13_FIQ].I;
 87.1742 +		reg[14].I = reg[R14_FIQ].I;
 87.1743 +		if (saveState)
 87.1744 +			reg[17].I = CPSR;
 87.1745 +		else
 87.1746 +			reg[17].I = reg[SPSR_FIQ].I;
 87.1747 +		break;
 87.1748 +	case 0x12:
 87.1749 +		reg[13].I = reg[R13_IRQ].I;
 87.1750 +		reg[14].I = reg[R14_IRQ].I;
 87.1751 +		reg[16].I = SPSR;
 87.1752 +		if (saveState)
 87.1753 +			reg[17].I = CPSR;
 87.1754 +		else
 87.1755 +			reg[17].I = reg[SPSR_IRQ].I;
 87.1756 +		break;
 87.1757 +	case 0x13:
 87.1758 +		reg[13].I = reg[R13_SVC].I;
 87.1759 +		reg[14].I = reg[R14_SVC].I;
 87.1760 +		reg[16].I = SPSR;
 87.1761 +		if (saveState)
 87.1762 +			reg[17].I = CPSR;
 87.1763 +		else
 87.1764 +			reg[17].I = reg[SPSR_SVC].I;
 87.1765 +		break;
 87.1766 +	case 0x17:
 87.1767 +		reg[13].I = reg[R13_ABT].I;
 87.1768 +		reg[14].I = reg[R14_ABT].I;
 87.1769 +		reg[16].I = SPSR;
 87.1770 +		if (saveState)
 87.1771 +			reg[17].I = CPSR;
 87.1772 +		else
 87.1773 +			reg[17].I = reg[SPSR_ABT].I;
 87.1774 +		break;
 87.1775 +	case 0x1b:
 87.1776 +		reg[13].I = reg[R13_UND].I;
 87.1777 +		reg[14].I = reg[R14_UND].I;
 87.1778 +		reg[16].I = SPSR;
 87.1779 +		if (saveState)
 87.1780 +			reg[17].I = CPSR;
 87.1781 +		else
 87.1782 +			reg[17].I = reg[SPSR_UND].I;
 87.1783 +		break;
 87.1784 +	default:
 87.1785 +		systemMessage(MSG_UNSUPPORTED_ARM_MODE, N_("Unsupported ARM mode %02x"), mode);
 87.1786 +		break;
 87.1787 +	}
 87.1788 +	armMode = mode;
 87.1789 +	CPUUpdateFlags(breakLoop);
 87.1790 +	CPUUpdateCPSR();
 87.1791 +}
 87.1792 +
 87.1793 +void CPUSwitchMode(int mode, bool saveState)
 87.1794 +{
 87.1795 +	CPUSwitchMode(mode, saveState, true);
 87.1796 +}
 87.1797 +
 87.1798 +void CPUUndefinedException()
 87.1799 +{
 87.1800 +	u32	 PC = reg[15].I;
 87.1801 +	bool savedArmState = armState;
 87.1802 +	CPUSwitchMode(0x1b, true, false);
 87.1803 +	reg[14].I	 = PC - (savedArmState ? 4 : 2);
 87.1804 +	reg[15].I	 = 0x04;
 87.1805 +	armState	 = true;
 87.1806 +	armIrqEnable = false;
 87.1807 +	armNextPC	 = 0x04;
 87.1808 +	reg[15].I	+= 4;
 87.1809 +}
 87.1810 +
 87.1811 +void CPUSoftwareInterrupt()
 87.1812 +{
 87.1813 +	u32	 PC = reg[15].I;
 87.1814 +	bool savedArmState = armState;
 87.1815 +	CPUSwitchMode(0x13, true, false);
 87.1816 +	reg[14].I	 = PC - (savedArmState ? 4 : 2);
 87.1817 +	reg[15].I	 = 0x08;
 87.1818 +	armState	 = true;
 87.1819 +	armIrqEnable = false;
 87.1820 +	armNextPC	 = 0x08;
 87.1821 +	reg[15].I	+= 4;
 87.1822 +}
 87.1823 +
 87.1824 +void CPUSoftwareInterrupt(int comment)
 87.1825 +{
 87.1826 +	static bool disableMessage = false;
 87.1827 +	if (armState)
 87.1828 +		comment >>= 16;
 87.1829 +#ifdef BKPT_SUPPORT
 87.1830 +	if (comment == 0xff)
 87.1831 +	{
 87.1832 +		extern void (*dbgOutput)(char *, u32);
 87.1833 +		dbgOutput(NULL, reg[0].I);
 87.1834 +		return;
 87.1835 +	}
 87.1836 +#endif
 87.1837 +#ifdef PROFILING
 87.1838 +	if (comment == 0xfe)
 87.1839 +	{
 87.1840 +		profStartup(reg[0].I, reg[1].I);
 87.1841 +		return;
 87.1842 +	}
 87.1843 +	if (comment == 0xfd)
 87.1844 +	{
 87.1845 +		profControl(reg[0].I);
 87.1846 +		return;
 87.1847 +	}
 87.1848 +	if (comment == 0xfc)
 87.1849 +	{
 87.1850 +		profCleanup();
 87.1851 +		return;
 87.1852 +	}
 87.1853 +	if (comment == 0xfb)
 87.1854 +	{
 87.1855 +		profCount();
 87.1856 +		return;
 87.1857 +	}
 87.1858 +#endif
 87.1859 +	if (comment == 0xfa)
 87.1860 +	{
 87.1861 +		agbPrintFlush();
 87.1862 +		return;
 87.1863 +	}
 87.1864 +#ifdef SDL
 87.1865 +	if (comment == 0xf9)
 87.1866 +	{
 87.1867 +		emulating = 0;
 87.1868 +		CPU_BREAK_LOOP_2;
 87.1869 +		return;
 87.1870 +	}
 87.1871 +#endif
 87.1872 +	if (useBios)
 87.1873 +	{
 87.1874 +#ifdef GBA_LOGGING
 87.1875 +		if (systemVerbose & VERBOSE_SWI)
 87.1876 +		{
 87.1877 +			log("SWI: %08x at %08x (0x%08x,0x%08x,0x%08x,VCOUNT = %2d)\n", comment,
 87.1878 +			    armState ? armNextPC - 4 : armNextPC - 2,
 87.1879 +			    reg[0].I,
 87.1880 +			    reg[1].I,
 87.1881 +			    reg[2].I,
 87.1882 +			    VCOUNT);
 87.1883 +		}
 87.1884 +#endif
 87.1885 +		CPUSoftwareInterrupt();
 87.1886 +		return;
 87.1887 +	}
 87.1888 +	// This would be correct, but it causes problems if uncommented
 87.1889 +	//  else {
 87.1890 +	//    biosProtected = 0xe3a02004;
 87.1891 +	//  }
 87.1892 +
 87.1893 +	switch (comment)
 87.1894 +	{
 87.1895 +	case 0x00:
 87.1896 +		BIOS_SoftReset();
 87.1897 +		break;
 87.1898 +	case 0x01:
 87.1899 +		BIOS_RegisterRamReset();
 87.1900 +		break;
 87.1901 +	case 0x02:
 87.1902 +#ifdef GBA_LOGGING
 87.1903 +		if (systemVerbose & VERBOSE_SWI)
 87.1904 +		{
 87.1905 +			log("Halt: (VCOUNT = %2d)\n",
 87.1906 +			    VCOUNT);
 87.1907 +		}
 87.1908 +#endif
 87.1909 +		holdState = true;
 87.1910 +		holdType  = -1;
 87.1911 +		break;
 87.1912 +	case 0x03:
 87.1913 +#ifdef GBA_LOGGING
 87.1914 +		if (systemVerbose & VERBOSE_SWI)
 87.1915 +		{
 87.1916 +			log("Stop: (VCOUNT = %2d)\n",
 87.1917 +			    VCOUNT);
 87.1918 +		}
 87.1919 +#endif
 87.1920 +		holdState = true;
 87.1921 +		holdType  = -1;
 87.1922 +		stopState = true;
 87.1923 +		break;
 87.1924 +	case 0x04:
 87.1925 +#ifdef GBA_LOGGING
 87.1926 +		if (systemVerbose & VERBOSE_SWI)
 87.1927 +		{
 87.1928 +			log("IntrWait: 0x%08x,0x%08x (VCOUNT = %2d)\n",
 87.1929 +			    reg[0].I,
 87.1930 +			    reg[1].I,
 87.1931 +			    VCOUNT);
 87.1932 +		}
 87.1933 +#endif
 87.1934 +		CPUSoftwareInterrupt();
 87.1935 +		break;
 87.1936 +	case 0x05:
 87.1937 +#ifdef GBA_LOGGING
 87.1938 +		if (systemVerbose & VERBOSE_SWI)
 87.1939 +		{
 87.1940 +			log("VBlankIntrWait: (VCOUNT = %2d)\n",
 87.1941 +			    VCOUNT);
 87.1942 +		}
 87.1943 +#endif
 87.1944 +		CPUSoftwareInterrupt();
 87.1945 +		break;
 87.1946 +	case 0x06:
 87.1947 +		CPUSoftwareInterrupt();
 87.1948 +		break;
 87.1949 +	case 0x07:
 87.1950 +		CPUSoftwareInterrupt();
 87.1951 +		break;
 87.1952 +	case 0x08:
 87.1953 +		BIOS_Sqrt();
 87.1954 +		break;
 87.1955 +	case 0x09:
 87.1956 +		BIOS_ArcTan();
 87.1957 +		break;
 87.1958 +	case 0x0A:
 87.1959 +		BIOS_ArcTan2();
 87.1960 +		break;
 87.1961 +	case 0x0B:
 87.1962 +		BIOS_CpuSet();
 87.1963 +		break;
 87.1964 +	case 0x0C:
 87.1965 +		BIOS_CpuFastSet();
 87.1966 +		break;
 87.1967 +	case 0x0E:
 87.1968 +		BIOS_BgAffineSet();
 87.1969 +		break;
 87.1970 +	case 0x0F:
 87.1971 +		BIOS_ObjAffineSet();
 87.1972 +		break;
 87.1973 +	case 0x10:
 87.1974 +		BIOS_BitUnPack();
 87.1975 +		break;
 87.1976 +	case 0x11:
 87.1977 +		BIOS_LZ77UnCompWram();
 87.1978 +		break;
 87.1979 +	case 0x12:
 87.1980 +		BIOS_LZ77UnCompVram();
 87.1981 +		break;
 87.1982 +	case 0x13:
 87.1983 +		BIOS_HuffUnComp();
 87.1984 +		break;
 87.1985 +	case 0x14:
 87.1986 +		BIOS_RLUnCompWram();
 87.1987 +		break;
 87.1988 +	case 0x15:
 87.1989 +		BIOS_RLUnCompVram();
 87.1990 +		break;
 87.1991 +	case 0x16:
 87.1992 +		BIOS_Diff8bitUnFilterWram();
 87.1993 +		break;
 87.1994 +	case 0x17:
 87.1995 +		BIOS_Diff8bitUnFilterVram();
 87.1996 +		break;
 87.1997 +	case 0x18:
 87.1998 +		BIOS_Diff16bitUnFilter();
 87.1999 +		break;
 87.2000 +	case 0x19:
 87.2001 +#ifdef GBA_LOGGING
 87.2002 +		if (systemVerbose & VERBOSE_SWI)
 87.2003 +		{
 87.2004 +			log("SoundBiasSet: 0x%08x (VCOUNT = %2d)\n",
 87.2005 +			    reg[0].I,
 87.2006 +			    VCOUNT);
 87.2007 +		}
 87.2008 +#endif
 87.2009 +		if (reg[0].I)
 87.2010 +			soundPause();
 87.2011 +		else
 87.2012 +			soundResume();
 87.2013 +		break;
 87.2014 +	case 0x1F:
 87.2015 +		BIOS_MidiKey2Freq();
 87.2016 +		break;
 87.2017 +	case 0x2A:
 87.2018 +		BIOS_SndDriverJmpTableCopy();
 87.2019 +	// let it go, because we don't really emulate this function // FIXME (?)
 87.2020 +	default:
 87.2021 +#ifdef GBA_LOGGING
 87.2022 +		if (systemVerbose & VERBOSE_SWI)
 87.2023 +		{
 87.2024 +			log("SWI: %08x at %08x (0x%08x,0x%08x,0x%08x,VCOUNT = %2d)\n", comment,
 87.2025 +			    armState ? armNextPC - 4 : armNextPC - 2,
 87.2026 +			    reg[0].I,
 87.2027 +			    reg[1].I,
 87.2028 +			    reg[2].I,
 87.2029 +			    VCOUNT);
 87.2030 +		}
 87.2031 +#endif
 87.2032 +
 87.2033 +		if (!disableMessage)
 87.2034 +		{
 87.2035 +			systemMessage(MSG_UNSUPPORTED_BIOS_FUNCTION,
 87.2036 +			              N_(
 87.2037 +			                  "Unsupported BIOS function %02x called from %08x. A BIOS file is needed in order to get correct behaviour."),
 87.2038 +			              comment,
 87.2039 +			              armMode ? armNextPC - 4 : armNextPC - 2);
 87.2040 +			disableMessage = true;
 87.2041 +		}
 87.2042 +		break;
 87.2043 +	}
 87.2044 +}
 87.2045 +
 87.2046 +void CPUCompareVCOUNT()
 87.2047 +{
 87.2048 +	if (VCOUNT == (DISPSTAT >> 8))
 87.2049 +	{
 87.2050 +		DISPSTAT |= 4;
 87.2051 +		UPDATE_REG(0x04, DISPSTAT);
 87.2052 +
 87.2053 +		if (DISPSTAT & 0x20)
 87.2054 +		{
 87.2055 +			IF |= 4;
 87.2056 +			UPDATE_REG(0x202, IF);
 87.2057 +		}
 87.2058 +	}
 87.2059 +	else
 87.2060 +	{
 87.2061 +		DISPSTAT &= 0xFFFB;
 87.2062 +		UPDATE_REG(0x4, DISPSTAT);
 87.2063 +	}
 87.2064 +}
 87.2065 +
 87.2066 +void doDMA(u32 &s, u32 &d, u32 si, u32 di, u32 c, int transfer32)
 87.2067 +{
 87.2068 +	int sm = s >> 24;
 87.2069 +	int dm = d >> 24;
 87.2070 +
 87.2071 +	int sc = c;
 87.2072 +
 87.2073 +	cpuDmaCount = c;
 87.2074 +
 87.2075 +	if (transfer32)
 87.2076 +	{
 87.2077 +		s &= 0xFFFFFFFC;
 87.2078 +		if (s < 0x02000000 && (reg[15].I >> 24))
 87.2079 +		{
 87.2080 +			while (c != 0)
 87.2081 +			{
 87.2082 +				CPUWriteMemory(d, 0);
 87.2083 +				d += di;
 87.2084 +				c--;
 87.2085 +			}
 87.2086 +		}
 87.2087 +		else
 87.2088 +		{
 87.2089 +			while (c != 0)
 87.2090 +			{
 87.2091 +				CPUWriteMemory(d, CPUReadMemory(s));
 87.2092 +				d += di;
 87.2093 +				s += si;
 87.2094 +				c--;
 87.2095 +			}
 87.2096 +		}
 87.2097 +	}
 87.2098 +	else
 87.2099 +	{
 87.2100 +		s &= 0xFFFFFFFE;
 87.2101 +		si = (int)si >> 1;
 87.2102 +		di = (int)di >> 1;
 87.2103 +		if (s < 0x02000000 && (reg[15].I >> 24))
 87.2104 +		{
 87.2105 +			while (c != 0)
 87.2106 +			{
 87.2107 +				CPUWriteHalfWord(d, 0);
 87.2108 +				d += di;
 87.2109 +				c--;
 87.2110 +			}
 87.2111 +		}
 87.2112 +		else
 87.2113 +		{
 87.2114 +			while (c != 0)
 87.2115 +			{
 87.2116 +				cpuDmaLast = CPUReadHalfWord(s);
 87.2117 +				CPUWriteHalfWord(d, cpuDmaLast);
 87.2118 +				d += di;
 87.2119 +				s += si;
 87.2120 +				c--;
 87.2121 +			}
 87.2122 +		}
 87.2123 +	}
 87.2124 +
 87.2125 +	cpuDmaCount = 0;
 87.2126 +
 87.2127 +	int sw = 1 + memoryWaitSeq[sm & 15];
 87.2128 +	int dw = 1 + memoryWaitSeq[dm & 15];
 87.2129 +
 87.2130 +	int totalTicks = 0;
 87.2131 +
 87.2132 +	if (transfer32)
 87.2133 +	{
 87.2134 +		if (!memory32[sm & 15])
 87.2135 +			sw <<= 1;
 87.2136 +		if (!memory32[dm & 15])
 87.2137 +			dw <<= 1;
 87.2138 +	}
 87.2139 +
 87.2140 +	totalTicks = (sw + dw) * sc;
 87.2141 +
 87.2142 +	cpuDmaTicksToUpdate += totalTicks;
 87.2143 +
 87.2144 +	if (*extCpuLoopTicks >= 0)
 87.2145 +	{
 87.2146 +		CPU_BREAK_LOOP;
 87.2147 +	}
 87.2148 +}
 87.2149 +
 87.2150 +void CPUCheckDMA(int reason, int dmamask)
 87.2151 +{
 87.2152 +	cpuDmaHack = 0;
 87.2153 +	// DMA 0
 87.2154 +	if ((DM0CNT_H & 0x8000) && (dmamask & 1))
 87.2155 +	{
 87.2156 +		if (((DM0CNT_H >> 12) & 3) == reason)
 87.2157 +		{
 87.2158 +			u32 sourceIncrement = 4;
 87.2159 +			u32 destIncrement	= 4;
 87.2160 +			switch ((DM0CNT_H >> 7) & 3)
 87.2161 +			{
 87.2162 +			case 0:
 87.2163 +				break;
 87.2164 +			case 1:
 87.2165 +				sourceIncrement = (u32) - 4;
 87.2166 +				break;
 87.2167 +			case 2:
 87.2168 +				sourceIncrement = 0;
 87.2169 +				break;
 87.2170 +			}
 87.2171 +			switch ((DM0CNT_H >> 5) & 3)
 87.2172 +			{
 87.2173 +			case 0:
 87.2174 +				break;
 87.2175 +			case 1:
 87.2176 +				destIncrement = (u32) - 4;
 87.2177 +				break;
 87.2178 +			case 2:
 87.2179 +				destIncrement = 0;
 87.2180 +				break;
 87.2181 +			}
 87.2182 +#ifdef GBA_LOGGING
 87.2183 +			if (systemVerbose & VERBOSE_DMA0)
 87.2184 +			{
 87.2185 +				int count = (DM0CNT_L ? DM0CNT_L : 0x4000) << 1;
 87.2186 +				if (DM0CNT_H & 0x0400)
 87.2187 +					count <<= 1;
 87.2188 +				log("DMA0: s=%08x d=%08x c=%04x count=%08x\n", dma0Source, dma0Dest,
 87.2189 +				    DM0CNT_H,
 87.2190 +				    count);
 87.2191 +			}
 87.2192 +#endif
 87.2193 +			doDMA(dma0Source, dma0Dest, sourceIncrement, destIncrement,
 87.2194 +			      DM0CNT_L ? DM0CNT_L : 0x4000,
 87.2195 +			      DM0CNT_H & 0x0400);
 87.2196 +			cpuDmaHack = 1;
 87.2197 +			if (DM0CNT_H & 0x4000)
 87.2198 +			{
 87.2199 +				IF |= 0x0100;
 87.2200 +				UPDATE_REG(0x202, IF);
 87.2201 +			}
 87.2202 +
 87.2203 +			if (((DM0CNT_H >> 5) & 3) == 3)
 87.2204 +			{
 87.2205 +				dma0Dest = DM0DAD_L | (DM0DAD_H << 16);
 87.2206 +			}
 87.2207 +
 87.2208 +			if (!(DM0CNT_H & 0x0200) || (reason == 0))
 87.2209 +			{
 87.2210 +				DM0CNT_H &= 0x7FFF;
 87.2211 +				UPDATE_REG(0xBA, DM0CNT_H);
 87.2212 +			}
 87.2213 +		}
 87.2214 +	}
 87.2215 +
 87.2216 +	// DMA 1
 87.2217 +	if ((DM1CNT_H & 0x8000) && (dmamask & 2))
 87.2218 +	{
 87.2219 +		if (((DM1CNT_H >> 12) & 3) == reason)
 87.2220 +		{
 87.2221 +			u32 sourceIncrement = 4;
 87.2222 +			u32 destIncrement	= 4;
 87.2223 +			switch ((DM1CNT_H >> 7) & 3)
 87.2224 +			{
 87.2225 +			case 0:
 87.2226 +				break;
 87.2227 +			case 1:
 87.2228 +				sourceIncrement = (u32) - 4;
 87.2229 +				break;
 87.2230 +			case 2:
 87.2231 +				sourceIncrement = 0;
 87.2232 +				break;
 87.2233 +			}
 87.2234 +			switch ((DM1CNT_H >> 5) & 3)
 87.2235 +			{
 87.2236 +			case 0:
 87.2237 +				break;
 87.2238 +			case 1:
 87.2239 +				destIncrement = (u32) - 4;
 87.2240 +				break;
 87.2241 +			case 2:
 87.2242 +				destIncrement = 0;
 87.2243 +				break;
 87.2244 +			}
 87.2245 +			if (reason == 3)
 87.2246 +			{
 87.2247 +#ifdef GBA_LOGGING
 87.2248 +				if (systemVerbose & VERBOSE_DMA1)
 87.2249 +				{
 87.2250 +					log("DMA1: s=%08x d=%08x c=%04x count=%08x\n", dma1Source, dma1Dest,
 87.2251 +					    DM1CNT_H,
 87.2252 +					    16);
 87.2253 +				}
 87.2254 +#endif
 87.2255 +				doDMA(dma1Source, dma1Dest, sourceIncrement, 0, 4,
 87.2256 +				      0x0400);
 87.2257 +			}
 87.2258 +			else
 87.2259 +			{
 87.2260 +#ifdef GBA_LOGGING
 87.2261 +				if (systemVerbose & VERBOSE_DMA1)
 87.2262 +				{
 87.2263 +					int count = (DM1CNT_L ? DM1CNT_L : 0x4000) << 1;
 87.2264 +					if (DM1CNT_H & 0x0400)
 87.2265 +						count <<= 1;
 87.2266 +					log("DMA1: s=%08x d=%08x c=%04x count=%08x\n", dma1Source, dma1Dest,
 87.2267 +					    DM1CNT_H,
 87.2268 +					    count);
 87.2269 +				}
 87.2270 +#endif
 87.2271 +				doDMA(dma1Source, dma1Dest, sourceIncrement, destIncrement,
 87.2272 +				      DM1CNT_L ? DM1CNT_L : 0x4000,
 87.2273 +				      DM1CNT_H & 0x0400);
 87.2274 +			}
 87.2275 +			cpuDmaHack = 1;
 87.2276 +
 87.2277 +			if (DM1CNT_H & 0x4000)
 87.2278 +			{
 87.2279 +				IF |= 0x0200;
 87.2280 +				UPDATE_REG(0x202, IF);
 87.2281 +			}
 87.2282 +
 87.2283 +			if (((DM1CNT_H >> 5) & 3) == 3)
 87.2284 +			{
 87.2285 +				dma1Dest = DM1DAD_L | (DM1DAD_H << 16);
 87.2286 +			}
 87.2287 +
 87.2288 +			if (!(DM1CNT_H & 0x0200) || (reason == 0))
 87.2289 +			{
 87.2290 +				DM1CNT_H &= 0x7FFF;
 87.2291 +				UPDATE_REG(0xC6, DM1CNT_H);
 87.2292 +			}
 87.2293 +		}
 87.2294 +	}
 87.2295 +
 87.2296 +	// DMA 2
 87.2297 +	if ((DM2CNT_H & 0x8000) && (dmamask & 4))
 87.2298 +	{
 87.2299 +		if (((DM2CNT_H >> 12) & 3) == reason)
 87.2300 +		{
 87.2301 +			u32 sourceIncrement = 4;
 87.2302 +			u32 destIncrement	= 4;
 87.2303 +			switch ((DM2CNT_H >> 7) & 3)
 87.2304 +			{
 87.2305 +			case 0:
 87.2306 +				break;
 87.2307 +			case 1:
 87.2308 +				sourceIncrement = (u32) - 4;
 87.2309 +				break;
 87.2310 +			case 2:
 87.2311 +				sourceIncrement = 0;
 87.2312 +				break;
 87.2313 +			}
 87.2314 +			switch ((DM2CNT_H >> 5) & 3)
 87.2315 +			{
 87.2316 +			case 0:
 87.2317 +				break;
 87.2318 +			case 1:
 87.2319 +				destIncrement = (u32) - 4;
 87.2320 +				break;
 87.2321 +			case 2:
 87.2322 +				destIncrement = 0;
 87.2323 +				break;
 87.2324 +			}
 87.2325 +			if (reason == 3)
 87.2326 +			{
 87.2327 +#ifdef GBA_LOGGING
 87.2328 +				if (systemVerbose & VERBOSE_DMA2)
 87.2329 +				{
 87.2330 +					int count = (4) << 2;
 87.2331 +					log("DMA2: s=%08x d=%08x c=%04x count=%08x\n", dma2Source, dma2Dest,
 87.2332 +					    DM2CNT_H,
 87.2333 +					    count);
 87.2334 +				}
 87.2335 +#endif
 87.2336 +				doDMA(dma2Source, dma2Dest, sourceIncrement, 0, 4,
 87.2337 +				      0x0400);
 87.2338 +			}
 87.2339 +			else
 87.2340 +			{
 87.2341 +#ifdef GBA_LOGGING
 87.2342 +				if (systemVerbose & VERBOSE_DMA2)
 87.2343 +				{
 87.2344 +					int count = (DM2CNT_L ? DM2CNT_L : 0x4000) << 1;
 87.2345 +					if (DM2CNT_H & 0x0400)
 87.2346 +						count <<= 1;
 87.2347 +					log("DMA2: s=%08x d=%08x c=%04x count=%08x\n", dma2Source, dma2Dest,
 87.2348 +					    DM2CNT_H,
 87.2349 +					    count);
 87.2350 +				}
 87.2351 +#endif
 87.2352 +				doDMA(dma2Source, dma2Dest, sourceIncrement, destIncrement,
 87.2353 +				      DM2CNT_L ? DM2CNT_L : 0x4000,
 87.2354 +				      DM2CNT_H & 0x0400);
 87.2355 +			}
 87.2356 +			cpuDmaHack = 1;
 87.2357 +			if (DM2CNT_H & 0x4000)
 87.2358 +			{
 87.2359 +				IF |= 0x0400;
 87.2360 +				UPDATE_REG(0x202, IF);
 87.2361 +			}
 87.2362 +
 87.2363 +			if (((DM2CNT_H >> 5) & 3) == 3)
 87.2364 +			{
 87.2365 +				dma2Dest = DM2DAD_L | (DM2DAD_H << 16);
 87.2366 +			}
 87.2367 +
 87.2368 +			if (!(DM2CNT_H & 0x0200) || (reason == 0))
 87.2369 +			{
 87.2370 +				DM2CNT_H &= 0x7FFF;
 87.2371 +				UPDATE_REG(0xD2, DM2CNT_H);
 87.2372 +			}
 87.2373 +		}
 87.2374 +	}
 87.2375 +
 87.2376 +	// DMA 3
 87.2377 +	if ((DM3CNT_H & 0x8000) && (dmamask & 8))
 87.2378 +	{
 87.2379 +		if (((DM3CNT_H >> 12) & 3) == reason)
 87.2380 +		{
 87.2381 +			u32 sourceIncrement = 4;
 87.2382 +			u32 destIncrement	= 4;
 87.2383 +			switch ((DM3CNT_H >> 7) & 3)
 87.2384 +			{
 87.2385 +			case 0:
 87.2386 +				break;
 87.2387 +			case 1:
 87.2388 +				sourceIncrement = (u32) - 4;
 87.2389 +				break;
 87.2390 +			case 2:
 87.2391 +				sourceIncrement = 0;
 87.2392 +				break;
 87.2393 +			}
 87.2394 +			switch ((DM3CNT_H >> 5) & 3)
 87.2395 +			{
 87.2396 +			case 0:
 87.2397 +				break;
 87.2398 +			case 1:
 87.2399 +				destIncrement = (u32) - 4;
 87.2400 +				break;
 87.2401 +			case 2:
 87.2402 +				destIncrement = 0;
 87.2403 +				break;
 87.2404 +			}
 87.2405 +#ifdef GBA_LOGGING
 87.2406 +			if (systemVerbose & VERBOSE_DMA3)
 87.2407 +			{
 87.2408 +				int count = (DM3CNT_L ? DM3CNT_L : 0x10000) << 1;
 87.2409 +				if (DM3CNT_H & 0x0400)
 87.2410 +					count <<= 1;
 87.2411 +				log("DMA3: s=%08x d=%08x c=%04x count=%08x\n", dma3Source, dma3Dest,
 87.2412 +				    DM3CNT_H,
 87.2413 +				    count);
 87.2414 +			}
 87.2415 +#endif
 87.2416 +			doDMA(dma3Source, dma3Dest, sourceIncrement, destIncrement,
 87.2417 +			      DM3CNT_L ? DM3CNT_L : 0x10000,
 87.2418 +			      DM3CNT_H & 0x0400);
 87.2419 +			if (DM3CNT_H & 0x4000)
 87.2420 +			{
 87.2421 +				IF |= 0x0800;
 87.2422 +				UPDATE_REG(0x202, IF);
 87.2423 +			}
 87.2424 +
 87.2425 +			if (((DM3CNT_H >> 5) & 3) == 3)
 87.2426 +			{
 87.2427 +				dma3Dest = DM3DAD_L | (DM3DAD_H << 16);
 87.2428 +			}
 87.2429 +
 87.2430 +			if (!(DM3CNT_H & 0x0200) || (reason == 0))
 87.2431 +			{
 87.2432 +				DM3CNT_H &= 0x7FFF;
 87.2433 +				UPDATE_REG(0xDE, DM3CNT_H);
 87.2434 +			}
 87.2435 +		}
 87.2436 +	}
 87.2437 +	cpuDmaHack = 0;
 87.2438 +}
 87.2439 +
 87.2440 +void CPUUpdateRegister(u32 address, u16 value)
 87.2441 +{
 87.2442 +	switch (address)
 87.2443 +	{
 87.2444 +	case 0x00:
 87.2445 +	{
 87.2446 +		bool change	  = ((DISPCNT ^ value) & 0x80) ? true : false;
 87.2447 +		bool changeBG = ((DISPCNT ^ value) & 0x0F00) ? true : false;
 87.2448 +		DISPCNT = (value & 0xFFF7);
 87.2449 +		UPDATE_REG(0x00, DISPCNT);
 87.2450 +		layerEnable = layerSettings & value;
 87.2451 +		windowOn	= (layerEnable & 0x6000) ? true : false;
 87.2452 +		if (change && !((value & 0x80)))
 87.2453 +		{
 87.2454 +			if (!(DISPSTAT & 1))
 87.2455 +			{
 87.2456 +				lcdTicks = 960;
 87.2457 +				//      VCOUNT = 0;
 87.2458 +				//      UPDATE_REG(0x06, VCOUNT);
 87.2459 +				DISPSTAT &= 0xFFFC;
 87.2460 +				UPDATE_REG(0x04, DISPSTAT);
 87.2461 +				CPUCompareVCOUNT();
 87.2462 +			}
 87.2463 +			//        (*renderLine)();
 87.2464 +		}
 87.2465 +		CPUUpdateRender();
 87.2466 +		// we only care about changes in BG0-BG3
 87.2467 +		if (changeBG)
 87.2468 +			CPUUpdateRenderBuffers(false);
 87.2469 +		//      CPUUpdateTicks();
 87.2470 +		break;
 87.2471 +	}
 87.2472 +	case 0x04:
 87.2473 +		DISPSTAT = (value & 0xFF38) | (DISPSTAT & 7);
 87.2474 +		UPDATE_REG(0x04, DISPSTAT);
 87.2475 +		break;
 87.2476 +	case 0x06:
 87.2477 +		// not writable
 87.2478 +		break;
 87.2479 +	case 0x08:
 87.2480 +		BG0CNT = (value & 0xDFCF);
 87.2481 +		UPDATE_REG(0x08, BG0CNT);
 87.2482 +		break;
 87.2483 +	case 0x0A:
 87.2484 +		BG1CNT = (value & 0xDFCF);
 87.2485 +		UPDATE_REG(0x0A, BG1CNT);
 87.2486 +		break;
 87.2487 +	case 0x0C:
 87.2488 +		BG2CNT = (value & 0xFFCF);
 87.2489 +		UPDATE_REG(0x0C, BG2CNT);
 87.2490 +		break;
 87.2491 +	case 0x0E:
 87.2492 +		BG3CNT = (value & 0xFFCF);
 87.2493 +		UPDATE_REG(0x0E, BG3CNT);
 87.2494 +		break;
 87.2495 +	case 0x10:
 87.2496 +		BG0HOFS = value & 511;
 87.2497 +		UPDATE_REG(0x10, BG0HOFS);
 87.2498 +		break;
 87.2499 +	case 0x12:
 87.2500 +		BG0VOFS = value & 511;
 87.2501 +		UPDATE_REG(0x12, BG0VOFS);
 87.2502 +		break;
 87.2503 +	case 0x14:
 87.2504 +		BG1HOFS = value & 511;
 87.2505 +		UPDATE_REG(0x14, BG1HOFS);
 87.2506 +		break;
 87.2507 +	case 0x16:
 87.2508 +		BG1VOFS = value & 511;
 87.2509 +		UPDATE_REG(0x16, BG1VOFS);
 87.2510 +		break;
 87.2511 +	case 0x18:
 87.2512 +		BG2HOFS = value & 511;
 87.2513 +		UPDATE_REG(0x18, BG2HOFS);
 87.2514 +		break;
 87.2515 +	case 0x1A:
 87.2516 +		BG2VOFS = value & 511;
 87.2517 +		UPDATE_REG(0x1A, BG2VOFS);
 87.2518 +		break;
 87.2519 +	case 0x1C:
 87.2520 +		BG3HOFS = value & 511;
 87.2521 +		UPDATE_REG(0x1C, BG3HOFS);
 87.2522 +		break;
 87.2523 +	case 0x1E:
 87.2524 +		BG3VOFS = value & 511;
 87.2525 +		UPDATE_REG(0x1E, BG3VOFS);
 87.2526 +		break;
 87.2527 +	case 0x20:
 87.2528 +		BG2PA = value;
 87.2529 +		UPDATE_REG(0x20, BG2PA);
 87.2530 +		break;
 87.2531 +	case 0x22:
 87.2532 +		BG2PB = value;
 87.2533 +		UPDATE_REG(0x22, BG2PB);
 87.2534 +		break;
 87.2535 +	case 0x24:
 87.2536 +		BG2PC = value;
 87.2537 +		UPDATE_REG(0x24, BG2PC);
 87.2538 +		break;
 87.2539 +	case 0x26:
 87.2540 +		BG2PD = value;
 87.2541 +		UPDATE_REG(0x26, BG2PD);
 87.2542 +		break;
 87.2543 +	case 0x28:
 87.2544 +		BG2X_L = value;
 87.2545 +		UPDATE_REG(0x28, BG2X_L);
 87.2546 +		gfxBG2Changed |= 1;
 87.2547 +		break;
 87.2548 +	case 0x2A:
 87.2549 +		BG2X_H = (value & 0xFFF);
 87.2550 +		UPDATE_REG(0x2A, BG2X_H);
 87.2551 +		gfxBG2Changed |= 1;
 87.2552 +		break;
 87.2553 +	case 0x2C:
 87.2554 +		BG2Y_L = value;
 87.2555 +		UPDATE_REG(0x2C, BG2Y_L);
 87.2556 +		gfxBG2Changed |= 2;
 87.2557 +		break;
 87.2558 +	case 0x2E:
 87.2559 +		BG2Y_H = value & 0xFFF;
 87.2560 +		UPDATE_REG(0x2E, BG2Y_H);
 87.2561 +		gfxBG2Changed |= 2;
 87.2562 +		break;
 87.2563 +	case 0x30:
 87.2564 +		BG3PA = value;
 87.2565 +		UPDATE_REG(0x30, BG3PA);
 87.2566 +		break;
 87.2567 +	case 0x32:
 87.2568 +		BG3PB = value;
 87.2569 +		UPDATE_REG(0x32, BG3PB);
 87.2570 +		break;
 87.2571 +	case 0x34:
 87.2572 +		BG3PC = value;
 87.2573 +		UPDATE_REG(0x34, BG3PC);
 87.2574 +		break;
 87.2575 +	case 0x36:
 87.2576 +		BG3PD = value;
 87.2577 +		UPDATE_REG(0x36, BG3PD);
 87.2578 +		break;
 87.2579 +	case 0x38:
 87.2580 +		BG3X_L = value;
 87.2581 +		UPDATE_REG(0x38, BG3X_L);
 87.2582 +		gfxBG3Changed |= 1;
 87.2583 +		break;
 87.2584 +	case 0x3A:
 87.2585 +		BG3X_H = value & 0xFFF;
 87.2586 +		UPDATE_REG(0x3A, BG3X_H);
 87.2587 +		gfxBG3Changed |= 1;
 87.2588 +		break;
 87.2589 +	case 0x3C:
 87.2590 +		BG3Y_L = value;
 87.2591 +		UPDATE_REG(0x3C, BG3Y_L);
 87.2592 +		gfxBG3Changed |= 2;
 87.2593 +		break;
 87.2594 +	case 0x3E:
 87.2595 +		BG3Y_H = value & 0xFFF;
 87.2596 +		UPDATE_REG(0x3E, BG3Y_H);
 87.2597 +		gfxBG3Changed |= 2;
 87.2598 +		break;
 87.2599 +	case 0x40:
 87.2600 +		WIN0H = value;
 87.2601 +		UPDATE_REG(0x40, WIN0H);
 87.2602 +		CPUUpdateWindow0();
 87.2603 +		break;
 87.2604 +	case 0x42:
 87.2605 +		WIN1H = value;
 87.2606 +		UPDATE_REG(0x42, WIN1H);
 87.2607 +		CPUUpdateWindow1();
 87.2608 +		break;
 87.2609 +	case 0x44:
 87.2610 +		WIN0V = value;
 87.2611 +		UPDATE_REG(0x44, WIN0V);
 87.2612 +		break;
 87.2613 +	case 0x46:
 87.2614 +		WIN1V = value;
 87.2615 +		UPDATE_REG(0x46, WIN1V);
 87.2616 +		break;
 87.2617 +	case 0x48:
 87.2618 +		WININ = value & 0x3F3F;
 87.2619 +		UPDATE_REG(0x48, WININ);
 87.2620 +		break;
 87.2621 +	case 0x4A:
 87.2622 +		WINOUT = value & 0x3F3F;
 87.2623 +		UPDATE_REG(0x4A, WINOUT);
 87.2624 +		break;
 87.2625 +	case 0x4C:
 87.2626 +		MOSAIC = value;
 87.2627 +		UPDATE_REG(0x4C, MOSAIC);
 87.2628 +		break;
 87.2629 +	case 0x50:
 87.2630 +		BLDMOD = value & 0x3FFF;
 87.2631 +		UPDATE_REG(0x50, BLDMOD);
 87.2632 +		fxOn = ((BLDMOD >> 6) & 3) != 0;
 87.2633 +		CPUUpdateRender();
 87.2634 +		break;
 87.2635 +	case 0x52:
 87.2636 +		COLEV = value & 0x1F1F;
 87.2637 +		UPDATE_REG(0x52, COLEV);
 87.2638 +		break;
 87.2639 +	case 0x54:
 87.2640 +		COLY = value & 0x1F;
 87.2641 +		UPDATE_REG(0x54, COLY);
 87.2642 +		break;
 87.2643 +	case 0x60:
 87.2644 +	case 0x62:
 87.2645 +	case 0x64:
 87.2646 +	case 0x68:
 87.2647 +	case 0x6c:
 87.2648 +	case 0x70:
 87.2649 +	case 0x72:
 87.2650 +	case 0x74:
 87.2651 +	case 0x78:
 87.2652 +	case 0x7c:
 87.2653 +	case 0x80:
 87.2654 +	case 0x84:
 87.2655 +		soundEvent(address & 0xFF, (u8)(value & 0xFF));
 87.2656 +		soundEvent((address & 0xFF) + 1, (u8)(value >> 8));
 87.2657 +		break;
 87.2658 +	case 0x82:
 87.2659 +	case 0x88:
 87.2660 +	case 0xa0:
 87.2661 +	case 0xa2:
 87.2662 +	case 0xa4:
 87.2663 +	case 0xa6:
 87.2664 +	case 0x90:
 87.2665 +	case 0x92:
 87.2666 +	case 0x94:
 87.2667 +	case 0x96:
 87.2668 +	case 0x98:
 87.2669 +	case 0x9a:
 87.2670 +	case 0x9c:
 87.2671 +	case 0x9e:
 87.2672 +		soundEvent(address & 0xFF, value);
 87.2673 +		break;
 87.2674 +	case 0xB0:
 87.2675 +		DM0SAD_L = value;
 87.2676 +		UPDATE_REG(0xB0, DM0SAD_L);
 87.2677 +		break;
 87.2678 +	case 0xB2:
 87.2679 +		DM0SAD_H = value & 0x07FF;
 87.2680 +		UPDATE_REG(0xB2, DM0SAD_H);
 87.2681 +		break;
 87.2682 +	case 0xB4:
 87.2683 +		DM0DAD_L = value;
 87.2684 +		UPDATE_REG(0xB4, DM0DAD_L);
 87.2685 +		break;
 87.2686 +	case 0xB6:
 87.2687 +		DM0DAD_H = value & 0x07FF;
 87.2688 +		UPDATE_REG(0xB6, DM0DAD_H);
 87.2689 +		break;
 87.2690 +	case 0xB8:
 87.2691 +		DM0CNT_L = value & 0x3FFF;
 87.2692 +		UPDATE_REG(0xB8, 0);
 87.2693 +		break;
 87.2694 +	case 0xBA:
 87.2695 +	{
 87.2696 +		bool start = ((DM0CNT_H ^ value) & 0x8000) ? true : false;
 87.2697 +		value &= 0xF7E0;
 87.2698 +
 87.2699 +		DM0CNT_H = value;
 87.2700 +		UPDATE_REG(0xBA, DM0CNT_H);
 87.2701 +
 87.2702 +		if (start && (value & 0x8000))
 87.2703 +		{
 87.2704 +			dma0Source = DM0SAD_L | (DM0SAD_H << 16);
 87.2705 +			dma0Dest   = DM0DAD_L | (DM0DAD_H << 16);
 87.2706 +			CPUCheckDMA(0, 1);
 87.2707 +		}
 87.2708 +		break;
 87.2709 +	}
 87.2710 +	case 0xBC:
 87.2711 +		DM1SAD_L = value;
 87.2712 +		UPDATE_REG(0xBC, DM1SAD_L);
 87.2713 +		break;
 87.2714 +	case 0xBE:
 87.2715 +		DM1SAD_H = value & 0x0FFF;
 87.2716 +		UPDATE_REG(0xBE, DM1SAD_H);
 87.2717 +		break;
 87.2718 +	case 0xC0:
 87.2719 +		DM1DAD_L = value;
 87.2720 +		UPDATE_REG(0xC0, DM1DAD_L);
 87.2721 +		break;
 87.2722 +	case 0xC2:
 87.2723 +		DM1DAD_H = value & 0x07FF;
 87.2724 +		UPDATE_REG(0xC2, DM1DAD_H);
 87.2725 +		break;
 87.2726 +	case 0xC4:
 87.2727 +		DM1CNT_L = value & 0x3FFF;
 87.2728 +		UPDATE_REG(0xC4, 0);
 87.2729 +		break;
 87.2730 +	case 0xC6:
 87.2731 +	{
 87.2732 +		bool start = ((DM1CNT_H ^ value) & 0x8000) ? true : false;
 87.2733 +		value &= 0xF7E0;
 87.2734 +
 87.2735 +		DM1CNT_H = value;
 87.2736 +		UPDATE_REG(0xC6, DM1CNT_H);
 87.2737 +
 87.2738 +		if (start && (value & 0x8000))
 87.2739 +		{
 87.2740 +			dma1Source = DM1SAD_L | (DM1SAD_H << 16);
 87.2741 +			dma1Dest   = DM1DAD_L | (DM1DAD_H << 16);
 87.2742 +			CPUCheckDMA(0, 2);
 87.2743 +		}
 87.2744 +		break;
 87.2745 +	}
 87.2746 +	case 0xC8:
 87.2747 +		DM2SAD_L = value;
 87.2748 +		UPDATE_REG(0xC8, DM2SAD_L);
 87.2749 +		break;
 87.2750 +	case 0xCA:
 87.2751 +		DM2SAD_H = value & 0x0FFF;
 87.2752 +		UPDATE_REG(0xCA, DM2SAD_H);
 87.2753 +		break;
 87.2754 +	case 0xCC:
 87.2755 +		DM2DAD_L = value;
 87.2756 +		UPDATE_REG(0xCC, DM2DAD_L);
 87.2757 +		break;
 87.2758 +	case 0xCE:
 87.2759 +		DM2DAD_H = value & 0x07FF;
 87.2760 +		UPDATE_REG(0xCE, DM2DAD_H);
 87.2761 +		break;
 87.2762 +	case 0xD0:
 87.2763 +		DM2CNT_L = value & 0x3FFF;
 87.2764 +		UPDATE_REG(0xD0, 0);
 87.2765 +		break;
 87.2766 +	case 0xD2:
 87.2767 +	{
 87.2768 +		bool start = ((DM2CNT_H ^ value) & 0x8000) ? true : false;
 87.2769 +
 87.2770 +		value &= 0xF7E0;
 87.2771 +
 87.2772 +		DM2CNT_H = value;
 87.2773 +		UPDATE_REG(0xD2, DM2CNT_H);
 87.2774 +
 87.2775 +		if (start && (value & 0x8000))
 87.2776 +		{
 87.2777 +			dma2Source = DM2SAD_L | (DM2SAD_H << 16);
 87.2778 +			dma2Dest   = DM2DAD_L | (DM2DAD_H << 16);
 87.2779 +
 87.2780 +			CPUCheckDMA(0, 4);
 87.2781 +		}
 87.2782 +		break;
 87.2783 +	}
 87.2784 +	case 0xD4:
 87.2785 +		DM3SAD_L = value;
 87.2786 +		UPDATE_REG(0xD4, DM3SAD_L);
 87.2787 +		break;
 87.2788 +	case 0xD6:
 87.2789 +		DM3SAD_H = value & 0x0FFF;
 87.2790 +		UPDATE_REG(0xD6, DM3SAD_H);
 87.2791 +		break;
 87.2792 +	case 0xD8:
 87.2793 +		DM3DAD_L = value;
 87.2794 +		UPDATE_REG(0xD8, DM3DAD_L);
 87.2795 +		break;
 87.2796 +	case 0xDA:
 87.2797 +		DM3DAD_H = value & 0x0FFF;
 87.2798 +		UPDATE_REG(0xDA, DM3DAD_H);
 87.2799 +		break;
 87.2800 +	case 0xDC:
 87.2801 +		DM3CNT_L = value;
 87.2802 +		UPDATE_REG(0xDC, 0);
 87.2803 +		break;
 87.2804 +	case 0xDE:
 87.2805 +	{
 87.2806 +		bool start = ((DM3CNT_H ^ value) & 0x8000) ? true : false;
 87.2807 +
 87.2808 +		value &= 0xFFE0;
 87.2809 +
 87.2810 +		DM3CNT_H = value;
 87.2811 +		UPDATE_REG(0xDE, DM3CNT_H);
 87.2812 +
 87.2813 +		if (start && (value & 0x8000))
 87.2814 +		{
 87.2815 +			dma3Source = DM3SAD_L | (DM3SAD_H << 16);
 87.2816 +			dma3Dest   = DM3DAD_L | (DM3DAD_H << 16);
 87.2817 +			CPUCheckDMA(0, 8);
 87.2818 +		}
 87.2819 +		break;
 87.2820 +	}
 87.2821 +	case 0x100:
 87.2822 +		timer0Reload = value;
 87.2823 +		break;
 87.2824 +	case 0x102:
 87.2825 +		timer0Ticks = timer0ClockReload = TIMER_TICKS[value & 3];
 87.2826 +		if (!timer0On && (value & 0x80))
 87.2827 +		{
 87.2828 +			// reload the counter
 87.2829 +			TM0D = timer0Reload;
 87.2830 +			if (timer0ClockReload == 1)
 87.2831 +				timer0Ticks = 0x10000 - TM0D;
 87.2832 +			UPDATE_REG(0x100, TM0D);
 87.2833 +		}
 87.2834 +		timer0On = value & 0x80 ? true : false;
 87.2835 +		TM0CNT	 = value & 0xC7;
 87.2836 +		UPDATE_REG(0x102, TM0CNT);
 87.2837 +		//    CPUUpdateTicks();
 87.2838 +		break;
 87.2839 +	case 0x104:
 87.2840 +		timer1Reload = value;
 87.2841 +		break;
 87.2842 +	case 0x106:
 87.2843 +		timer1Ticks = timer1ClockReload = TIMER_TICKS[value & 3];
 87.2844 +		if (!timer1On && (value & 0x80))
 87.2845 +		{
 87.2846 +			// reload the counter
 87.2847 +			TM1D = timer1Reload;
 87.2848 +			if (timer1ClockReload == 1)
 87.2849 +				timer1Ticks = 0x10000 - TM1D;
 87.2850 +			UPDATE_REG(0x104, TM1D);
 87.2851 +		}
 87.2852 +		timer1On = value & 0x80 ? true : false;
 87.2853 +		TM1CNT	 = value & 0xC7;
 87.2854 +		UPDATE_REG(0x106, TM1CNT);
 87.2855 +		break;
 87.2856 +	case 0x108:
 87.2857 +		timer2Reload = value;
 87.2858 +		break;
 87.2859 +	case 0x10A:
 87.2860 +		timer2Ticks = timer2ClockReload = TIMER_TICKS[value & 3];
 87.2861 +		if (!timer2On && (value & 0x80))
 87.2862 +		{
 87.2863 +			// reload the counter
 87.2864 +			TM2D = timer2Reload;
 87.2865 +			if (timer2ClockReload == 1)
 87.2866 +				timer2Ticks = 0x10000 - TM2D;
 87.2867 +			UPDATE_REG(0x108, TM2D);
 87.2868 +		}
 87.2869 +		timer2On = value & 0x80 ? true : false;
 87.2870 +		TM2CNT	 = value & 0xC7;
 87.2871 +		UPDATE_REG(0x10A, TM2CNT);
 87.2872 +		break;
 87.2873 +	case 0x10C:
 87.2874 +		timer3Reload = value;
 87.2875 +		break;
 87.2876 +	case 0x10E:
 87.2877 +		timer3Ticks = timer3ClockReload = TIMER_TICKS[value & 3];
 87.2878 +		if (!timer3On && (value & 0x80))
 87.2879 +		{
 87.2880 +			// reload the counter
 87.2881 +			TM3D = timer3Reload;
 87.2882 +			if (timer3ClockReload == 1)
 87.2883 +				timer3Ticks = 0x10000 - TM3D;
 87.2884 +			UPDATE_REG(0x10C, TM3D);
 87.2885 +		}
 87.2886 +		timer3On = value & 0x80 ? true : false;
 87.2887 +		TM3CNT	 = value & 0xC7;
 87.2888 +		UPDATE_REG(0x10E, TM3CNT);
 87.2889 +		break;
 87.2890 +	case 0x128:
 87.2891 +		if (value & 0x80)
 87.2892 +		{
 87.2893 +			value &= 0xff7f;
 87.2894 +			if (value & 1 && (value & 0x4000))
 87.2895 +			{
 87.2896 +				UPDATE_REG(0x12a, 0xFF);
 87.2897 +				IF |= 0x80;
 87.2898 +				UPDATE_REG(0x202, IF);
 87.2899 +				value &= 0x7f7f;
 87.2900 +			}
 87.2901 +		}
 87.2902 +		UPDATE_REG(0x128, value);
 87.2903 +		break;
 87.2904 +	case 0x130:
 87.2905 +		P1 |= (value & 0x3FF);
 87.2906 +		UPDATE_REG(0x130, P1);
 87.2907 +		break;
 87.2908 +	case 0x132:
 87.2909 +		UPDATE_REG(0x132, value & 0xC3FF);
 87.2910 +		break;
 87.2911 +	case 0x200:
 87.2912 +		IE = value & 0x3FFF;
 87.2913 +		UPDATE_REG(0x200, IE);
 87.2914 +		if ((IME & 1) && (IF & IE) && armIrqEnable)
 87.2915 +		{
 87.2916 +			CPU_BREAK_LOOP_2;
 87.2917 +		}
 87.2918 +		break;
 87.2919 +	case 0x202:
 87.2920 +		IF ^= (value & IF);
 87.2921 +		UPDATE_REG(0x202, IF);
 87.2922 +		break;
 87.2923 +	case 0x204:
 87.2924 +	{
 87.2925 +		int i;
 87.2926 +		memoryWait[0x0e] = memoryWaitSeq[0x0e] = gamepakRamWaitState[value & 3];
 87.2927 +
 87.2928 +		if (!speedHack)
 87.2929 +		{
 87.2930 +			memoryWait[0x08]	= memoryWait[0x09] = gamepakWaitState[(value >> 2) & 7];
 87.2931 +			memoryWaitSeq[0x08] = memoryWaitSeq[0x09] =
 87.2932 +			                          gamepakWaitState0[(value >> 2) & 7];
 87.2933 +
 87.2934 +			memoryWait[0x0a]	= memoryWait[0x0b] = gamepakWaitState[(value >> 5) & 7];
 87.2935 +			memoryWaitSeq[0x0a] = memoryWaitSeq[0x0b] =
 87.2936 +			                          gamepakWaitState1[(value >> 5) & 7];
 87.2937 +
 87.2938 +			memoryWait[0x0c]	= memoryWait[0x0d] = gamepakWaitState[(value >> 8) & 7];
 87.2939 +			memoryWaitSeq[0x0c] = memoryWaitSeq[0x0d] =
 87.2940 +			                          gamepakWaitState2[(value >> 8) & 7];
 87.2941 +		}
 87.2942 +		else
 87.2943 +		{
 87.2944 +			memoryWait[0x08]	= memoryWait[0x09] = 4;
 87.2945 +			memoryWaitSeq[0x08] = memoryWaitSeq[0x09] = 2;
 87.2946 +
 87.2947 +			memoryWait[0x0a]	= memoryWait[0x0b] = 4;
 87.2948 +			memoryWaitSeq[0x0a] = memoryWaitSeq[0x0b] = 4;
 87.2949 +
 87.2950 +			memoryWait[0x0c]	= memoryWait[0x0d] = 4;
 87.2951 +			memoryWaitSeq[0x0c] = memoryWaitSeq[0x0d] = 8;
 87.2952 +		}
 87.2953 +		for (i = 0; i < 16; i++)
 87.2954 +		{
 87.2955 +			memoryWaitFetch32[i] = memoryWait32[i] = memoryWait[i] *
 87.2956 +			                                         (memory32[i] ? 1 : 2);
 87.2957 +			memoryWaitFetch[i] = memoryWait[i];
 87.2958 +		}
 87.2959 +		memoryWaitFetch32[3] += 1;
 87.2960 +		memoryWaitFetch32[2] += 3;
 87.2961 +
 87.2962 +		prefetchActive	= false;
 87.2963 +		prefetchApplies = false;
 87.2964 +		if (value & 0x4000)
 87.2965 +		{
 87.2966 +			for (i = 8; i < 16; i++)
 87.2967 +			{
 87.2968 +				memoryWaitFetch32[i] = 2 * cpuMemoryWait[i];
 87.2969 +				memoryWaitFetch[i]	 = cpuMemoryWait[i];
 87.2970 +			}
 87.2971 +			if (((value & 3) == 3))
 87.2972 +			{
 87.2973 +				if (!memLagTempEnabled)
 87.2974 +				{
 87.2975 +					memoryWaitFetch[8]--; // hack to prevent inaccurately extreme lag at some points of many games (possibly
 87.2976 +					                      // from no pre-fetch emulation)
 87.2977 +					                      /// FIXME: how correct is this? Should it set the fetch to 0 or change fetch32 or
 87.2978 +					                      // anything else?
 87.2979 +
 87.2980 +					prefetchActive = true;
 87.2981 +				}
 87.2982 +				prefetchApplies = true;
 87.2983 +			}
 87.2984 +		}
 87.2985 +		//if(prefetchActive && !prefetchPrevActive) systemScreenMessage("pre-fetch enabled",3,600);
 87.2986 +		//if(!prefetchActive && prefetchPrevActive) systemScreenMessage("pre-fetch disabled",3,600);
 87.2987 +		prefetchPrevActive = prefetchActive;
 87.2988 +
 87.2989 +		UPDATE_REG(0x204, value);
 87.2990 +		break;
 87.2991 +	}
 87.2992 +	case 0x208:
 87.2993 +		IME = value & 1;
 87.2994 +		UPDATE_REG(0x208, IME);
 87.2995 +		if ((IME & 1) && (IF & IE) && armIrqEnable)
 87.2996 +		{
 87.2997 +			CPU_BREAK_LOOP_2;
 87.2998 +		}
 87.2999 +		break;
 87.3000 +	case 0x300:
 87.3001 +		if (value != 0)
 87.3002 +			value &= 0xFFFE;
 87.3003 +		UPDATE_REG(0x300, value);
 87.3004 +		break;
 87.3005 +	default:
 87.3006 +		UPDATE_REG(address & 0x3FE, value);
 87.3007 +		break;
 87.3008 +	}
 87.3009 +}
 87.3010 +
 87.3011 +void CPUWriteHalfWordWrapped(u32 address, u16 value)
 87.3012 +{
 87.3013 +#ifdef GBA_LOGGING
 87.3014 +	if (address & 1)
 87.3015 +	{
 87.3016 +		if (systemVerbose & VERBOSE_UNALIGNED_MEMORY)
 87.3017 +		{
 87.3018 +			log("Unaligned halfword write: %04x to %08x from %08x\n",
 87.3019 +			    value,
 87.3020 +			    address,
 87.3021 +			    armMode ? armNextPC - 4 : armNextPC - 2);
 87.3022 +		}
 87.3023 +	}
 87.3024 +#endif
 87.3025 +
 87.3026 +	switch (address >> 24)
 87.3027 +	{
 87.3028 +	case 2:
 87.3029 +#ifdef SDL
 87.3030 +		if (*((u16 *)&freezeWorkRAM[address & 0x3FFFE]))
 87.3031 +			cheatsWriteHalfWord((u16 *)&workRAM[address & 0x3FFFE],
 87.3032 +			                    value,
 87.3033 +			                    *((u16 *)&freezeWorkRAM[address & 0x3FFFE]));
 87.3034 +		else
 87.3035 +#endif
 87.3036 +		WRITE16LE(((u16 *)&workRAM[address & 0x3FFFE]), value);
 87.3037 +		break;
 87.3038 +	case 3:
 87.3039 +#ifdef SDL
 87.3040 +		if (*((u16 *)&freezeInternalRAM[address & 0x7ffe]))
 87.3041 +			cheatsWriteHalfWord((u16 *)&internalRAM[address & 0x7ffe],
 87.3042 +			                    value,
 87.3043 +			                    *((u16 *)&freezeInternalRAM[address & 0x7ffe]));
 87.3044 +		else
 87.3045 +#endif
 87.3046 +		WRITE16LE(((u16 *)&internalRAM[address & 0x7ffe]), value);
 87.3047 +		break;
 87.3048 +	case 4:
 87.3049 +		CPUUpdateRegister(address & 0x3fe, value);
 87.3050 +		break;
 87.3051 +	case 5:
 87.3052 +		WRITE16LE(((u16 *)&paletteRAM[address & 0x3fe]), value);
 87.3053 +		break;
 87.3054 +	case 6:
 87.3055 +		if (address & 0x10000)
 87.3056 +			WRITE16LE(((u16 *)&vram[address & 0x17ffe]), value);
 87.3057 +		else
 87.3058 +			WRITE16LE(((u16 *)&vram[address & 0x1fffe]), value);
 87.3059 +		break;
 87.3060 +	case 7:
 87.3061 +		WRITE16LE(((u16 *)&oam[address & 0x3fe]), value);
 87.3062 +		break;
 87.3063 +	case 8:
 87.3064 +	case 9:
 87.3065 +		if (address == 0x80000c4 || address == 0x80000c6 || address == 0x80000c8)
 87.3066 +		{
 87.3067 +			if (!rtcWrite(address, value))
 87.3068 +				goto unwritable;
 87.3069 +		}
 87.3070 +		else if (!agbPrintWrite(address, value))
 87.3071 +			goto unwritable;
 87.3072 +		break;
 87.3073 +	case 13:
 87.3074 +		if (cpuEEPROMEnabled)
 87.3075 +		{
 87.3076 +			eepromWrite(address, (u8)(value & 0xFF));
 87.3077 +			break;
 87.3078 +		}
 87.3079 +		goto unwritable;
 87.3080 +	case 14:
 87.3081 +		if (!eepromInUse | cpuSramEnabled | cpuFlashEnabled)
 87.3082 +		{
 87.3083 +			(*cpuSaveGameFunc)(address, (u8)(value & 0xFF));
 87.3084 +			break;
 87.3085 +		}
 87.3086 +		goto unwritable;
 87.3087 +	default:
 87.3088 +unwritable:
 87.3089 +#ifdef GBA_LOGGING
 87.3090 +		if (systemVerbose & VERBOSE_ILLEGAL_WRITE)
 87.3091 +		{
 87.3092 +			log("Illegal halfword write: %04x to %08x from %08x\n",
 87.3093 +			    value,
 87.3094 +			    address,
 87.3095 +			    armMode ? armNextPC - 4 : armNextPC - 2);
 87.3096 +		}
 87.3097 +#endif
 87.3098 +		break;
 87.3099 +	}
 87.3100 +}
 87.3101 +
 87.3102 +void CPUWriteHalfWord(u32 address, u16 value)
 87.3103 +{
 87.3104 +	CPUWriteHalfWordWrapped(address, value);
 87.3105 +	CallRegisteredLuaMemHook(address, 2, value, LUAMEMHOOK_WRITE);
 87.3106 +}
 87.3107 +
 87.3108 +void CPUWriteByteWrapped(u32 address, u8 b)
 87.3109 +{
 87.3110 +	switch (address >> 24)
 87.3111 +	{
 87.3112 +	case 2:
 87.3113 +#ifdef SDL
 87.3114 +		if (freezeWorkRAM[address & 0x3FFFF])
 87.3115 +			cheatsWriteByte(&workRAM[address & 0x3FFFF], b);
 87.3116 +		else
 87.3117 +#endif
 87.3118 +		workRAM[address & 0x3FFFF] = b;
 87.3119 +		break;
 87.3120 +	case 3:
 87.3121 +#ifdef SDL
 87.3122 +		if (freezeInternalRAM[address & 0x7fff])
 87.3123 +			cheatsWriteByte(&internalRAM[address & 0x7fff], b);
 87.3124 +		else
 87.3125 +#endif
 87.3126 +		internalRAM[address & 0x7fff] = b;
 87.3127 +		break;
 87.3128 +	case 4:
 87.3129 +		switch (address & 0x3FF)
 87.3130 +		{
 87.3131 +		case 0x301:
 87.3132 +			if (b == 0x80)
 87.3133 +				stopState = true;
 87.3134 +			holdState = 1;
 87.3135 +			holdType  = -1;
 87.3136 +			break;
 87.3137 +		case 0x60:
 87.3138 +		case 0x61:
 87.3139 +		case 0x62:
 87.3140 +		case 0x63:
 87.3141 +		case 0x64:
 87.3142 +		case 0x65:
 87.3143 +		case 0x68:
 87.3144 +		case 0x69:
 87.3145 +		case 0x6c:
 87.3146 +		case 0x6d:
 87.3147 +		case 0x70:
 87.3148 +		case 0x71:
 87.3149 +		case 0x72:
 87.3150 +		case 0x73:
 87.3151 +		case 0x74:
 87.3152 +		case 0x75:
 87.3153 +		case 0x78:
 87.3154 +		case 0x79:
 87.3155 +		case 0x7c:
 87.3156 +		case 0x7d:
 87.3157 +		case 0x80:
 87.3158 +		case 0x81:
 87.3159 +		case 0x84:
 87.3160 +		case 0x85:
 87.3161 +		case 0x90:
 87.3162 +		case 0x91:
 87.3163 +		case 0x92:
 87.3164 +		case 0x93:
 87.3165 +		case 0x94:
 87.3166 +		case 0x95:
 87.3167 +		case 0x96:
 87.3168 +		case 0x97:
 87.3169 +		case 0x98:
 87.3170 +		case 0x99:
 87.3171 +		case 0x9a:
 87.3172 +		case 0x9b:
 87.3173 +		case 0x9c:
 87.3174 +		case 0x9d:
 87.3175 +		case 0x9e:
 87.3176 +		case 0x9f:
 87.3177 +			soundEvent(address & 0xFF, b);
 87.3178 +			break;
 87.3179 +		default:
 87.3180 +			//      if(address & 1) {
 87.3181 +			//        CPUWriteHalfWord(address-1, (CPUReadHalfWord(address-1)&0x00FF)|((int)b<<8));
 87.3182 +			//      } else
 87.3183 +			if (address & 1)
 87.3184 +				CPUUpdateRegister(address & 0x3fe,
 87.3185 +				                  ((READ16LE(((u16 *)&ioMem[address & 0x3fe])))
 87.3186 +				                   & 0x00FF) |
 87.3187 +				                  b << 8);
 87.3188 +			else
 87.3189 +				CPUUpdateRegister(address & 0x3fe,
 87.3190 +				                  ((READ16LE(((u16 *)&ioMem[address & 0x3fe])) & 0xFF00) | b));
 87.3191 +		}
 87.3192 +		break;
 87.3193 +	case 5:
 87.3194 +		// no need to switch
 87.3195 +		*((u16 *)&paletteRAM[address & 0x3FE]) = (b << 8) | b;
 87.3196 +		break;
 87.3197 +	case 6:
 87.3198 +		// no need to switch
 87.3199 +		if (address & 0x10000)
 87.3200 +			*((u16 *)&vram[address & 0x17FFE]) = (b << 8) | b;
 87.3201 +		else
 87.3202 +			*((u16 *)&vram[address & 0x1FFFE]) = (b << 8) | b;
 87.3203 +		break;
 87.3204 +	case 7:
 87.3205 +		// no need to switch
 87.3206 +		*((u16 *)&oam[address & 0x3FE]) = (b << 8) | b;
 87.3207 +		break;
 87.3208 +	case 13:
 87.3209 +		if (cpuEEPROMEnabled)
 87.3210 +		{
 87.3211 +			eepromWrite(address, b);
 87.3212 +			break;
 87.3213 +		}
 87.3214 +		goto unwritable;
 87.3215 +	case 14:
 87.3216 +		if (!eepromInUse | cpuSramEnabled | cpuFlashEnabled)
 87.3217 +		{
 87.3218 +			(*cpuSaveGameFunc)(address, b);
 87.3219 +			break;
 87.3220 +		}
 87.3221 +	// default
 87.3222 +	default:
 87.3223 +unwritable:
 87.3224 +#ifdef GBA_LOGGING
 87.3225 +		if (systemVerbose & VERBOSE_ILLEGAL_WRITE)
 87.3226 +		{
 87.3227 +			log("Illegal byte write: %02x to %08x from %08x\n",
 87.3228 +			    b,
 87.3229 +			    address,
 87.3230 +			    armMode ? armNextPC - 4 : armNextPC - 2);
 87.3231 +		}
 87.3232 +#endif
 87.3233 +		break;
 87.3234 +	}
 87.3235 +}
 87.3236 +
 87.3237 +void CPUWriteByte(u32 address, u8 b)
 87.3238 +{
 87.3239 +	CPUWriteByteWrapped(address, b);
 87.3240 +	CallRegisteredLuaMemHook(address, 1, b, LUAMEMHOOK_WRITE);
 87.3241 +}
 87.3242 +
 87.3243 +bool CPULoadBios(const char *biosFileName, bool useBiosFile)
 87.3244 +{
 87.3245 +	useBios = false;
 87.3246 +	if (useBiosFile)
 87.3247 +	{
 87.3248 +		useBios = utilLoadBIOS(bios, biosFileName, 4);
 87.3249 +		if (!useBios)
 87.3250 +		{
 87.3251 +			systemMessage(MSG_INVALID_BIOS_FILE_SIZE, N_("Invalid GBA BIOS file"));
 87.3252 +		}
 87.3253 +	}
 87.3254 +
 87.3255 +	if (!useBios)
 87.3256 +	{
 87.3257 +		// load internal BIOS
 87.3258 +		memcpy(bios, myROM, sizeof(myROM));
 87.3259 +	}
 87.3260 +
 87.3261 +	return useBios;
 87.3262 +}
 87.3263 +
 87.3264 +void CPUInit()
 87.3265 +{
 87.3266 +#ifdef WORDS_BIGENDIAN
 87.3267 +	if (!cpuBiosSwapped)
 87.3268 +	{
 87.3269 +		for (unsigned int i = 0; i < sizeof(myROM) / 4; i++)
 87.3270 +		{
 87.3271 +			WRITE32LE(&myROM[i], myROM[i]);
 87.3272 +		}
 87.3273 +		cpuBiosSwapped = true;
 87.3274 +	}
 87.3275 +#endif
 87.3276 +	gbaSaveType = 0;
 87.3277 +	eepromInUse = 0;
 87.3278 +	saveType	= 0;
 87.3279 +
 87.3280 +	if (!useBios)
 87.3281 +	{
 87.3282 +		// load internal BIOS
 87.3283 +		memcpy(bios, myROM, sizeof(myROM));
 87.3284 +	}
 87.3285 +
 87.3286 +	biosProtected[0] = 0x00;
 87.3287 +	biosProtected[1] = 0xf0;
 87.3288 +	biosProtected[2] = 0x29;
 87.3289 +	biosProtected[3] = 0xe1;
 87.3290 +
 87.3291 +	int i = 0;
 87.3292 +	for (i = 0; i < 256; i++)
 87.3293 +	{
 87.3294 +		int cpuBitSetCount = 0;
 87.3295 +		int j;
 87.3296 +		for (j = 0; j < 8; j++)
 87.3297 +			if (i & (1 << j))
 87.3298 +				cpuBitSetCount++;
 87.3299 +		cpuBitsSet[i] = cpuBitSetCount;
 87.3300 +
 87.3301 +		for (j = 0; j < 8; j++)
 87.3302 +			if (i & (1 << j))
 87.3303 +				break;
 87.3304 +		cpuLowestBitSet[i] = j;
 87.3305 +	}
 87.3306 +
 87.3307 +	for (i = 0; i < 0x400; i++)
 87.3308 +		ioReadable[i] = true;
 87.3309 +	for (i = 0x10; i < 0x48; i++)
 87.3310 +		ioReadable[i] = false;
 87.3311 +	for (i = 0x4c; i < 0x50; i++)
 87.3312 +		ioReadable[i] = false;
 87.3313 +	for (i = 0x54; i < 0x60; i++)
 87.3314 +		ioReadable[i] = false;
 87.3315 +	for (i = 0x8c; i < 0x90; i++)
 87.3316 +		ioReadable[i] = false;
 87.3317 +	for (i = 0xa0; i < 0xb8; i++)
 87.3318 +		ioReadable[i] = false;
 87.3319 +	for (i = 0xbc; i < 0xc4; i++)
 87.3320 +		ioReadable[i] = false;
 87.3321 +	for (i = 0xc8; i < 0xd0; i++)
 87.3322 +		ioReadable[i] = false;
 87.3323 +	for (i = 0xd4; i < 0xdc; i++)
 87.3324 +		ioReadable[i] = false;
 87.3325 +	for (i = 0xe0; i < 0x100; i++)
 87.3326 +		ioReadable[i] = false;
 87.3327 +	for (i = 0x110; i < 0x120; i++)
 87.3328 +		ioReadable[i] = false;
 87.3329 +	for (i = 0x12c; i < 0x130; i++)
 87.3330 +		ioReadable[i] = false;
 87.3331 +	for (i = 0x138; i < 0x140; i++)
 87.3332 +		ioReadable[i] = false;
 87.3333 +	for (i = 0x144; i < 0x150; i++)
 87.3334 +		ioReadable[i] = false;
 87.3335 +	for (i = 0x15c; i < 0x200; i++)
 87.3336 +		ioReadable[i] = false;
 87.3337 +	for (i = 0x20c; i < 0x300; i++)
 87.3338 +		ioReadable[i] = false;
 87.3339 +	for (i = 0x304; i < 0x400; i++)
 87.3340 +		ioReadable[i] = false;
 87.3341 +
 87.3342 +	*((u16 *)&rom[0x1fe209c]) = 0xdffa;  // SWI 0xFA
 87.3343 +	*((u16 *)&rom[0x1fe209e]) = 0x4770;  // BX LR
 87.3344 +
 87.3345 +	{
 87.3346 +		int32 origMemoryWaitFetch[16]	= { 3, 0, 3, 0, 0, 1, 1, 0, 4, 4, 4, 4, 4, 4, 4, 0 };
 87.3347 +		int32 origMemoryWaitFetch32[16] = { 6, 0, 6, 0, 0, 2, 2, 0, 8, 8, 8, 8, 8, 8, 8, 0 };
 87.3348 +		memcpy(memoryWaitFetch, origMemoryWaitFetch, 16 * sizeof(int32));
 87.3349 +		memcpy(memoryWaitFetch32, origMemoryWaitFetch32, 16 * sizeof(int32));
 87.3350 +	}
 87.3351 +}
 87.3352 +
 87.3353 +void CPUReset(bool userReset)
 87.3354 +{
 87.3355 +	// movie must be closed while opening/creating a movie
 87.3356 +	if (userReset && VBAMovieRecording())
 87.3357 +	{
 87.3358 +		VBAMovieSignalReset();
 87.3359 +		return;
 87.3360 +	}
 87.3361 +
 87.3362 +	if (!VBAMovieActive())
 87.3363 +	{
 87.3364 +		GBASystemCounters.frameCount = 0;
 87.3365 +		GBASystemCounters.lagCount	 = 0;
 87.3366 +		GBASystemCounters.extraCount = 0;
 87.3367 +		GBASystemCounters.lagged	 = true;
 87.3368 +		GBASystemCounters.laggedLast = true;
 87.3369 +	}
 87.3370 +
 87.3371 +	if (gbaSaveType == 0)
 87.3372 +	{
 87.3373 +		if (eepromInUse)
 87.3374 +			gbaSaveType = 3;
 87.3375 +		else
 87.3376 +			switch (saveType)
 87.3377 +			{
 87.3378 +			case 1:
 87.3379 +				gbaSaveType = 1;
 87.3380 +				break;
 87.3381 +			case 2:
 87.3382 +				gbaSaveType = 2;
 87.3383 +				break;
 87.3384 +			}
 87.3385 +	}
 87.3386 +
 87.3387 +	rtcReset();
 87.3388 +	// clean registers
 87.3389 +	memset(&reg[0], 0, sizeof(reg));
 87.3390 +	// clean OAM
 87.3391 +	memset(oam, 0, 0x400);
 87.3392 +	// clean palette
 87.3393 +	memset(paletteRAM, 0, 0x400);
 87.3394 +	// clean picture
 87.3395 +	memset(pix, 0, 4 * 241 * 162);
 87.3396 +	// clean vram
 87.3397 +	memset(vram, 0, 0x20000);
 87.3398 +	// clean io memory
 87.3399 +	memset(ioMem, 0, 0x400);
 87.3400 +	// clean RAM
 87.3401 +	memset(internalRAM, 0, 0x8000); /// FIXME: is it unsafe to erase ALL of this? Even the init code doesn't.
 87.3402 +	memset(workRAM, 0, 0x40000); /// ditto
 87.3403 +
 87.3404 +	DISPCNT	 = 0x0080;
 87.3405 +	DISPSTAT = 0x0000;
 87.3406 +	VCOUNT	 = 0x0000;
 87.3407 +	BG0CNT	 = 0x0000;
 87.3408 +	BG1CNT	 = 0x0000;
 87.3409 +	BG2CNT	 = 0x0000;
 87.3410 +	BG3CNT	 = 0x0000;
 87.3411 +	BG0HOFS	 = 0x0000;
 87.3412 +	BG0VOFS	 = 0x0000;
 87.3413 +	BG1HOFS	 = 0x0000;
 87.3414 +	BG1VOFS	 = 0x0000;
 87.3415 +	BG2HOFS	 = 0x0000;
 87.3416 +	BG2VOFS	 = 0x0000;
 87.3417 +	BG3HOFS	 = 0x0000;
 87.3418 +	BG3VOFS	 = 0x0000;
 87.3419 +	BG2PA	 = 0x0100;
 87.3420 +	BG2PB	 = 0x0000;
 87.3421 +	BG2PC	 = 0x0000;
 87.3422 +	BG2PD	 = 0x0100;
 87.3423 +	BG2X_L	 = 0x0000;
 87.3424 +	BG2X_H	 = 0x0000;
 87.3425 +	BG2Y_L	 = 0x0000;
 87.3426 +	BG2Y_H	 = 0x0000;
 87.3427 +	BG3PA	 = 0x0100;
 87.3428 +	BG3PB	 = 0x0000;
 87.3429 +	BG3PC	 = 0x0000;
 87.3430 +	BG3PD	 = 0x0100;
 87.3431 +	BG3X_L	 = 0x0000;
 87.3432 +	BG3X_H	 = 0x0000;
 87.3433 +	BG3Y_L	 = 0x0000;
 87.3434 +	BG3Y_H	 = 0x0000;
 87.3435 +	WIN0H	 = 0x0000;
 87.3436 +	WIN1H	 = 0x0000;
 87.3437 +	WIN0V	 = 0x0000;
 87.3438 +	WIN1V	 = 0x0000;
 87.3439 +	WININ	 = 0x0000;
 87.3440 +	WINOUT	 = 0x0000;
 87.3441 +	MOSAIC	 = 0x0000;
 87.3442 +	BLDMOD	 = 0x0000;
 87.3443 +	COLEV	 = 0x0000;
 87.3444 +	COLY	 = 0x0000;
 87.3445 +	DM0SAD_L = 0x0000;
 87.3446 +	DM0SAD_H = 0x0000;
 87.3447 +	DM0DAD_L = 0x0000;
 87.3448 +	DM0DAD_H = 0x0000;
 87.3449 +	DM0CNT_L = 0x0000;
 87.3450 +	DM0CNT_H = 0x0000;
 87.3451 +	DM1SAD_L = 0x0000;
 87.3452 +	DM1SAD_H = 0x0000;
 87.3453 +	DM1DAD_L = 0x0000;
 87.3454 +	DM1DAD_H = 0x0000;
 87.3455 +	DM1CNT_L = 0x0000;
 87.3456 +	DM1CNT_H = 0x0000;
 87.3457 +	DM2SAD_L = 0x0000;
 87.3458 +	DM2SAD_H = 0x0000;
 87.3459 +	DM2DAD_L = 0x0000;
 87.3460 +	DM2DAD_H = 0x0000;
 87.3461 +	DM2CNT_L = 0x0000;
 87.3462 +	DM2CNT_H = 0x0000;
 87.3463 +	DM3SAD_L = 0x0000;
 87.3464 +	DM3SAD_H = 0x0000;
 87.3465 +	DM3DAD_L = 0x0000;
 87.3466 +	DM3DAD_H = 0x0000;
 87.3467 +	DM3CNT_L = 0x0000;
 87.3468 +	DM3CNT_H = 0x0000;
 87.3469 +	TM0D	 = 0x0000;
 87.3470 +	TM0CNT	 = 0x0000;
 87.3471 +	TM1D	 = 0x0000;
 87.3472 +	TM1CNT	 = 0x0000;
 87.3473 +	TM2D	 = 0x0000;
 87.3474 +	TM2CNT	 = 0x0000;
 87.3475 +	TM3D	 = 0x0000;
 87.3476 +	TM3CNT	 = 0x0000;
 87.3477 +	P1		 = 0x03FF;
 87.3478 +	IE		 = 0x0000;
 87.3479 +	IF		 = 0x0000;
 87.3480 +	IME		 = 0x0000;
 87.3481 +
 87.3482 +	armMode = 0x1F;
 87.3483 +
 87.3484 +	if (cpuIsMultiBoot)
 87.3485 +	{
 87.3486 +		reg[13].I	   = 0x03007F00;
 87.3487 +		reg[15].I	   = 0x02000000;
 87.3488 +		reg[16].I	   = 0x00000000;
 87.3489 +		reg[R13_IRQ].I = 0x03007FA0;
 87.3490 +		reg[R13_SVC].I = 0x03007FE0;
 87.3491 +		armIrqEnable   = true;
 87.3492 +	}
 87.3493 +	else
 87.3494 +	{
 87.3495 +		if (useBios && !skipBios)
 87.3496 +		{
 87.3497 +			reg[15].I	 = 0x00000000;
 87.3498 +			armMode		 = 0x13;
 87.3499 +			armIrqEnable = false;
 87.3500 +		}
 87.3501 +		else
 87.3502 +		{
 87.3503 +			reg[13].I	   = 0x03007F00;
 87.3504 +			reg[15].I	   = 0x08000000;
 87.3505 +			reg[16].I	   = 0x00000000;
 87.3506 +			reg[R13_IRQ].I = 0x03007FA0;
 87.3507 +			reg[R13_SVC].I = 0x03007FE0;
 87.3508 +			armIrqEnable   = true;
 87.3509 +		}
 87.3510 +	}
 87.3511 +	armState = true;
 87.3512 +	C_FLAG	 = V_FLAG = N_FLAG = Z_FLAG = false;
 87.3513 +	UPDATE_REG(0x00, DISPCNT);
 87.3514 +	UPDATE_REG(0x20, BG2PA);
 87.3515 +	UPDATE_REG(0x26, BG2PD);
 87.3516 +	UPDATE_REG(0x30, BG3PA);
 87.3517 +	UPDATE_REG(0x36, BG3PD);
 87.3518 +	UPDATE_REG(0x130, P1);
 87.3519 +	UPDATE_REG(0x88, 0x200);
 87.3520 +
 87.3521 +	// disable FIQ
 87.3522 +	reg[16].I |= 0x40;
 87.3523 +	CPUUpdateCPSR();
 87.3524 +
 87.3525 +	armNextPC  = reg[15].I;
 87.3526 +	reg[15].I += 4;
 87.3527 +
 87.3528 +	// reset internal state
 87.3529 +	holdState = false;
 87.3530 +	holdType  = 0;
 87.3531 +
 87.3532 +	biosProtected[0] = 0x00;
 87.3533 +	biosProtected[1] = 0xf0;
 87.3534 +	biosProtected[2] = 0x29;
 87.3535 +	biosProtected[3] = 0xe1;
 87.3536 +
 87.3537 +	BIOS_RegisterRamReset();
 87.3538 +
 87.3539 +	lcdTicks = 960;
 87.3540 +	timer0On = false;
 87.3541 +	timer0Ticks		  = 0;
 87.3542 +	timer0Reload	  = 0;
 87.3543 +	timer0ClockReload = 0;
 87.3544 +	timer1On		  = false;
 87.3545 +	timer1Ticks		  = 0;
 87.3546 +	timer1Reload	  = 0;
 87.3547 +	timer1ClockReload = 0;
 87.3548 +	timer2On		  = false;
 87.3549 +	timer2Ticks		  = 0;
 87.3550 +	timer2Reload	  = 0;
 87.3551 +	timer2ClockReload = 0;
 87.3552 +	timer3On		  = false;
 87.3553 +	timer3Ticks		  = 0;
 87.3554 +	timer3Reload	  = 0;
 87.3555 +	timer3ClockReload = 0;
 87.3556 +	dma0Source		  = 0;
 87.3557 +	dma0Dest		  = 0;
 87.3558 +	dma1Source		  = 0;
 87.3559 +	dma1Dest		  = 0;
 87.3560 +	dma2Source		  = 0;
 87.3561 +	dma2Dest		  = 0;
 87.3562 +	dma3Source		  = 0;
 87.3563 +	dma3Dest		  = 0;
 87.3564 +	cpuSaveGameFunc	  = flashSaveDecide;
 87.3565 +	renderLine		  = mode0RenderLine;
 87.3566 +	fxOn			  = false;
 87.3567 +	windowOn		  = false;
 87.3568 +	frameSkipCount	  = 0;
 87.3569 +	saveType		  = 0;
 87.3570 +	layerEnable		  = DISPCNT & layerSettings;
 87.3571 +
 87.3572 +	CPUUpdateRenderBuffers(true);
 87.3573 +
 87.3574 +	for (int i = 0; i < 256; i++)
 87.3575 +	{
 87.3576 +		map[i].address = (u8 *)&dummyAddress;
 87.3577 +		map[i].mask	   = 0;
 87.3578 +	}
 87.3579 +
 87.3580 +	map[0].address	= bios;
 87.3581 +	map[0].mask		= 0x3FFF;
 87.3582 +	map[2].address	= workRAM;
 87.3583 +	map[2].mask		= 0x3FFFF;
 87.3584 +	map[3].address	= internalRAM;
 87.3585 +	map[3].mask		= 0x7FFF;
 87.3586 +	map[4].address	= ioMem;
 87.3587 +	map[4].mask		= 0x3FF;
 87.3588 +	map[5].address	= paletteRAM;
 87.3589 +	map[5].mask		= 0x3FF;
 87.3590 +	map[6].address	= vram;
 87.3591 +	map[6].mask		= 0x1FFFF;
 87.3592 +	map[7].address	= oam;
 87.3593 +	map[7].mask		= 0x3FF;
 87.3594 +	map[8].address	= rom;
 87.3595 +	map[8].mask		= 0x1FFFFFF;
 87.3596 +	map[9].address	= rom;
 87.3597 +	map[9].mask		= 0x1FFFFFF;
 87.3598 +	map[10].address = rom;
 87.3599 +	map[10].mask	= 0x1FFFFFF;
 87.3600 +	map[12].address = rom;
 87.3601 +	map[12].mask	= 0x1FFFFFF;
 87.3602 +	map[14].address = flashSaveMemory;
 87.3603 +	map[14].mask	= 0xFFFF;
 87.3604 +
 87.3605 +	eepromReset();
 87.3606 +	flashReset();
 87.3607 +
 87.3608 +	soundReset();
 87.3609 +
 87.3610 +	CPUUpdateWindow0();
 87.3611 +	CPUUpdateWindow1();
 87.3612 +
 87.3613 +	// make sure registers are correctly initialized if not using BIOS
 87.3614 +	if (!useBios)
 87.3615 +	{
 87.3616 +		if (cpuIsMultiBoot)
 87.3617 +			BIOS_RegisterRamReset(0xfe);
 87.3618 +		else
 87.3619 +			BIOS_RegisterRamReset(0xff);
 87.3620 +	}
 87.3621 +	else
 87.3622 +	{
 87.3623 +		if (cpuIsMultiBoot)
 87.3624 +			BIOS_RegisterRamReset(0xfe);
 87.3625 +	}
 87.3626 +
 87.3627 +	switch (cpuSaveType)
 87.3628 +	{
 87.3629 +	case 0: // automatic
 87.3630 +		cpuSramEnabled		   = true;
 87.3631 +		cpuFlashEnabled		   = true;
 87.3632 +		cpuEEPROMEnabled	   = true;
 87.3633 +		cpuEEPROMSensorEnabled = false;
 87.3634 +		break;
 87.3635 +	case 1: // EEPROM
 87.3636 +		cpuSramEnabled		   = false;
 87.3637 +		cpuFlashEnabled		   = false;
 87.3638 +		cpuEEPROMEnabled	   = true;
 87.3639 +		cpuEEPROMSensorEnabled = false;
 87.3640 +		break;
 87.3641 +	case 2: // SRAM
 87.3642 +		cpuSramEnabled		   = true;
 87.3643 +		cpuFlashEnabled		   = false;
 87.3644 +		cpuEEPROMEnabled	   = false;
 87.3645 +		cpuEEPROMSensorEnabled = false;
 87.3646 +		cpuSaveGameFunc		   = sramWrite;
 87.3647 +		break;
 87.3648 +	case 3: // FLASH
 87.3649 +		cpuSramEnabled		   = false;
 87.3650 +		cpuFlashEnabled		   = true;
 87.3651 +		cpuEEPROMEnabled	   = false;
 87.3652 +		cpuEEPROMSensorEnabled = false;
 87.3653 +		cpuSaveGameFunc		   = flashWrite;
 87.3654 +		break;
 87.3655 +	case 4: // EEPROM+Sensor
 87.3656 +		cpuSramEnabled		   = false;
 87.3657 +		cpuFlashEnabled		   = false;
 87.3658 +		cpuEEPROMEnabled	   = true;
 87.3659 +		cpuEEPROMSensorEnabled = true;
 87.3660 +		break;
 87.3661 +	case 5: // NONE
 87.3662 +		cpuSramEnabled		   = false;
 87.3663 +		cpuFlashEnabled		   = false;
 87.3664 +		cpuEEPROMEnabled	   = false;
 87.3665 +		cpuEEPROMSensorEnabled = false;
 87.3666 +		break;
 87.3667 +	}
 87.3668 +
 87.3669 +	systemResetSensor();
 87.3670 +
 87.3671 +	systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
 87.3672 +
 87.3673 +	gbaLastTime	  = systemGetClock();
 87.3674 +	gbaFrameCount = 0;
 87.3675 +
 87.3676 +	systemRefreshScreen();
 87.3677 +}
 87.3678 +
 87.3679 +void CPUInterrupt()
 87.3680 +{
 87.3681 +	u32	 PC			= reg[15].I;
 87.3682 +	bool savedState = armState;
 87.3683 +	CPUSwitchMode(0x12, true, false);
 87.3684 +	reg[14].I = PC;
 87.3685 +	if (!savedState)
 87.3686 +		reg[14].I += 2;
 87.3687 +	reg[15].I	 = 0x18;
 87.3688 +	armState	 = true;
 87.3689 +	armIrqEnable = false;
 87.3690 +
 87.3691 +	armNextPC  = reg[15].I;
 87.3692 +	reg[15].I += 4;
 87.3693 +
 87.3694 +	//  if(!holdState)
 87.3695 +	biosProtected[0] = 0x02;
 87.3696 +	biosProtected[1] = 0xc0;
 87.3697 +	biosProtected[2] = 0x5e;
 87.3698 +	biosProtected[3] = 0xe5;
 87.3699 +}
 87.3700 +
 87.3701 +void TogglePrefetchHack()
 87.3702 +{
 87.3703 +	memLagTempEnabled = !memLagTempEnabled;
 87.3704 +
 87.3705 +	if (emulating)
 87.3706 +	{
 87.3707 +		extern bool8 prefetchActive, prefetchPrevActive, prefetchApplies;
 87.3708 +		if (prefetchApplies && prefetchActive == memLagTempEnabled)
 87.3709 +		{
 87.3710 +			prefetchActive = !prefetchActive;
 87.3711 +			//if(prefetchActive && !prefetchPrevActive) systemScreenMessage("pre-fetch enabled",3,600);
 87.3712 +			//if(!prefetchActive && prefetchPrevActive) systemScreenMessage("pre-fetch disabled",3,600);
 87.3713 +			extern int32 memoryWaitFetch [16];
 87.3714 +			if (prefetchActive)
 87.3715 +				memoryWaitFetch[8]--;
 87.3716 +			else
 87.3717 +				memoryWaitFetch[8]++;
 87.3718 +			prefetchPrevActive = prefetchActive;
 87.3719 +		}
 87.3720 +	}
 87.3721 +}
 87.3722 +
 87.3723 +void SetPrefetchHack(bool set)
 87.3724 +{
 87.3725 +	if ((bool)memLagTempEnabled == set)
 87.3726 +		TogglePrefetchHack();
 87.3727 +}
 87.3728 +
 87.3729 +#ifdef SDL
 87.3730 +void log(const char *defaultMsg, ...)
 87.3731 +{
 87.3732 +	char	buffer[2048];
 87.3733 +	va_list valist;
 87.3734 +
 87.3735 +	va_start(valist, defaultMsg);
 87.3736 +	vsprintf(buffer, defaultMsg, valist);
 87.3737 +
 87.3738 +	if (out == NULL)
 87.3739 +	{
 87.3740 +		out = fopen("trace.log", "w");
 87.3741 +	}
 87.3742 +
 87.3743 +	fputs(buffer, out);
 87.3744 +
 87.3745 +	va_end(valist);
 87.3746 +}
 87.3747 +
 87.3748 +#else
 87.3749 +extern void winlog(const char *, ...);
 87.3750 +#endif
 87.3751 +
 87.3752 +void CPULoop(int _ticks)
 87.3753 +{
 87.3754 +	int32 ticks = _ticks;
 87.3755 +	int32 clockTicks;
 87.3756 +	int32 cpuLoopTicks	= 0;
 87.3757 +	int32 timerOverflow = 0;
 87.3758 +	// variables used by the CPU core
 87.3759 +
 87.3760 +	extCpuLoopTicks = &cpuLoopTicks;
 87.3761 +	extClockTicks	= &clockTicks;
 87.3762 +	extTicks		= &ticks;
 87.3763 +
 87.3764 +	cpuLoopTicks = CPUUpdateTicks();
 87.3765 +	if (cpuLoopTicks > ticks)
 87.3766 +	{
 87.3767 +		cpuLoopTicks  = ticks;
 87.3768 +		cpuSavedTicks = ticks;
 87.3769 +	}
 87.3770 +
 87.3771 +	if (intState)
 87.3772 +	{
 87.3773 +		cpuLoopTicks  = 5;
 87.3774 +		cpuSavedTicks = 5;
 87.3775 +	}
 87.3776 +
 87.3777 +	if (newFrame)
 87.3778 +	{
 87.3779 +		extern void VBAOnExitingFrameBoundary();
 87.3780 +		VBAOnExitingFrameBoundary();
 87.3781 +
 87.3782 +		// update joystick information
 87.3783 +		systemReadJoypads();
 87.3784 +
 87.3785 +		u32 joy = systemGetJoypad(0, cpuEEPROMSensorEnabled);
 87.3786 +
 87.3787 +//		if (cpuEEPROMSensorEnabled)
 87.3788 +//			systemUpdateMotionSensor(0);
 87.3789 +
 87.3790 +		P1 = 0x03FF ^ (joy & 0x3FF);
 87.3791 +		UPDATE_REG(0x130, P1);
 87.3792 +		u16 P1CNT = READ16LE(((u16 *)&ioMem[0x132]));
 87.3793 +		// this seems wrong, but there are cases where the game
 87.3794 +		// can enter the stop state without requesting an IRQ from
 87.3795 +		// the joypad.
 87.3796 +		if ((P1CNT & 0x4000) || stopState)
 87.3797 +		{
 87.3798 +			u16 p1 = (0x3FF ^ P1) & 0x3FF;
 87.3799 +			if (P1CNT & 0x8000)
 87.3800 +			{
 87.3801 +				if (p1 == (P1CNT & 0x3FF))
 87.3802 +				{
 87.3803 +					IF |= 0x1000;
 87.3804 +					UPDATE_REG(0x202, IF);
 87.3805 +				}
 87.3806 +			}
 87.3807 +			else
 87.3808 +			{
 87.3809 +				if (p1 & P1CNT)
 87.3810 +				{
 87.3811 +					IF |= 0x1000;
 87.3812 +					UPDATE_REG(0x202, IF);
 87.3813 +				}
 87.3814 +			}
 87.3815 +		}
 87.3816 +
 87.3817 +		// HACK: some special "buttons"
 87.3818 +		extButtons = (joy >> 18);
 87.3819 +		speedup	   = (extButtons & 1) != 0;
 87.3820 +
 87.3821 +		VBAMovieResetIfRequested();
 87.3822 +
 87.3823 +		CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION);
 87.3824 +
 87.3825 +		newFrame = false;
 87.3826 +	}
 87.3827 +
 87.3828 +	for (;; )
 87.3829 +	{
 87.3830 +#ifndef FINAL_VERSION
 87.3831 +		if (systemDebug)
 87.3832 +		{
 87.3833 +			if (systemDebug >= 10 && !holdState)
 87.3834 +			{
 87.3835 +				CPUUpdateCPSR();
 87.3836 +				sprintf(
 87.3837 +				    buffer,
 87.3838 +				    "R00=%08x R01=%08x R02=%08x R03=%08x R04=%08x R05=%08x R06=%08x R07=%08x R08=%08x"
 87.3839 +				    "R09=%08x R10=%08x R11=%08x R12=%08x R13=%08x R14=%08x R15=%08x R16=%08x R17=%08x\n",
 87.3840 +				    reg[0].I,
 87.3841 +				    reg[1].I,
 87.3842 +				    reg[2].I,
 87.3843 +				    reg[3].I,
 87.3844 +				    reg[4].I,
 87.3845 +				    reg[5].I,
 87.3846 +				    reg[6].I,
 87.3847 +				    reg[7].I,
 87.3848 +				    reg[8].I,
 87.3849 +				    reg[9].I,
 87.3850 +				    reg[10].I,
 87.3851 +				    reg[11].I,
 87.3852 +				    reg[12].I,
 87.3853 +				    reg[13].I,
 87.3854 +				    reg[14].I,
 87.3855 +				    reg[15].I,
 87.3856 +				    reg[16].I,
 87.3857 +				    reg[17].I);
 87.3858 +#ifdef SDL
 87.3859 +				log(buffer);
 87.3860 +#else
 87.3861 +				winlog(buffer);
 87.3862 +#endif
 87.3863 +			}
 87.3864 +			else if (!holdState)
 87.3865 +			{
 87.3866 +				sprintf(buffer, "PC=%08x\n", armNextPC);
 87.3867 +#ifdef SDL
 87.3868 +				log(buffer);
 87.3869 +#else
 87.3870 +				winlog(buffer);
 87.3871 +#endif
 87.3872 +			}
 87.3873 +		}
 87.3874 +#endif
 87.3875 +
 87.3876 +		if (!holdState)
 87.3877 +		{
 87.3878 +			if (armState)
 87.3879 +			{
 87.3880 +				CallRegisteredLuaMemHook(armNextPC, 4, CPUReadMemoryQuick(armNextPC), LUAMEMHOOK_EXEC);
 87.3881 +#include "arm-new.h"
 87.3882 +			}
 87.3883 +			else
 87.3884 +			{
 87.3885 +				CallRegisteredLuaMemHook(armNextPC, 2, CPUReadHalfWordQuick(armNextPC), LUAMEMHOOK_EXEC);
 87.3886 +#include "thumb.h"
 87.3887 +			}
 87.3888 +		}
 87.3889 +		else
 87.3890 +		{
 87.3891 +			clockTicks = lcdTicks;
 87.3892 +
 87.3893 +			if (soundTicks < clockTicks)
 87.3894 +				clockTicks = soundTicks;
 87.3895 +
 87.3896 +			if (timer0On && (timer0Ticks < clockTicks))
 87.3897 +			{
 87.3898 +				clockTicks = timer0Ticks;
 87.3899 +			}
 87.3900 +			if (timer1On && (timer1Ticks < clockTicks))
 87.3901 +			{
 87.3902 +				clockTicks = timer1Ticks;
 87.3903 +			}
 87.3904 +			if (timer2On && (timer2Ticks < clockTicks))
 87.3905 +			{
 87.3906 +				clockTicks = timer2Ticks;
 87.3907 +			}
 87.3908 +			if (timer3On && (timer3Ticks < clockTicks))
 87.3909 +			{
 87.3910 +				clockTicks = timer3Ticks;
 87.3911 +			}
 87.3912 +#ifdef PROFILING
 87.3913 +			if (profilingTicksReload != 0)
 87.3914 +			{
 87.3915 +				if (profilingTicks < clockTicks)
 87.3916 +				{
 87.3917 +					clockTicks = profilingTicks;
 87.3918 +				}
 87.3919 +			}
 87.3920 +#endif
 87.3921 +		}
 87.3922 +
 87.3923 +		cpuLoopTicks -= clockTicks;
 87.3924 +		if ((cpuLoopTicks <= 0))
 87.3925 +		{
 87.3926 +			if (cpuSavedTicks)
 87.3927 +			{
 87.3928 +				clockTicks = cpuSavedTicks; // + cpuLoopTicks;
 87.3929 +			}
 87.3930 +			cpuDmaTicksToUpdate = -cpuLoopTicks;
 87.3931 +
 87.3932 +updateLoop:
 87.3933 +			lcdTicks -= clockTicks;
 87.3934 +
 87.3935 +			if (lcdTicks <= 0)
 87.3936 +			{
 87.3937 +				if (DISPSTAT & 1) // V-BLANK
 87.3938 +				{ // if in V-Blank mode, keep computing...
 87.3939 +					if (DISPSTAT & 2)
 87.3940 +					{
 87.3941 +						lcdTicks += 960;
 87.3942 +						VCOUNT++;
 87.3943 +						UPDATE_REG(0x06, VCOUNT);
 87.3944 +						DISPSTAT &= 0xFFFD;
 87.3945 +						UPDATE_REG(0x04, DISPSTAT);
 87.3946 +						CPUCompareVCOUNT();
 87.3947 +					}
 87.3948 +					else
 87.3949 +					{
 87.3950 +						lcdTicks += 272;
 87.3951 +						DISPSTAT |= 2;
 87.3952 +						UPDATE_REG(0x04, DISPSTAT);
 87.3953 +						if (DISPSTAT & 16)
 87.3954 +						{
 87.3955 +							IF |= 2;
 87.3956 +							UPDATE_REG(0x202, IF);
 87.3957 +						}
 87.3958 +					}
 87.3959 +
 87.3960 +					if (VCOUNT >= 228)
 87.3961 +					{
 87.3962 +						DISPSTAT &= 0xFFFC;
 87.3963 +						UPDATE_REG(0x04, DISPSTAT);
 87.3964 +						VCOUNT = 0;
 87.3965 +						UPDATE_REG(0x06, VCOUNT);
 87.3966 +						CPUCompareVCOUNT();
 87.3967 +					}
 87.3968 +				}
 87.3969 +				else
 87.3970 +				{
 87.3971 +					int framesToSkip = systemFramesToSkip();
 87.3972 +
 87.3973 +					if (DISPSTAT & 2)
 87.3974 +					{
 87.3975 +						// if in H-Blank, leave it and move to drawing mode
 87.3976 +						VCOUNT++;
 87.3977 +						UPDATE_REG(0x06, VCOUNT);
 87.3978 +
 87.3979 +						lcdTicks += 960;
 87.3980 +						DISPSTAT &= 0xFFFD;
 87.3981 +						if (VCOUNT == 160)
 87.3982 +						{
 87.3983 +							DISPSTAT |= 1;
 87.3984 +							DISPSTAT &= 0xFFFD;
 87.3985 +							UPDATE_REG(0x04, DISPSTAT);
 87.3986 +							if (DISPSTAT & 0x0008)
 87.3987 +							{
 87.3988 +								IF |= 1;
 87.3989 +								UPDATE_REG(0x202, IF);
 87.3990 +							}
 87.3991 +							CPUCheckDMA(1, 0x0f);
 87.3992 +
 87.3993 +							systemFrame();
 87.3994 +
 87.3995 +							++gbaFrameCount;
 87.3996 +							u32 gbaCurrentTime = systemGetClock();
 87.3997 +							if (gbaCurrentTime - gbaLastTime >= 1000)
 87.3998 +							{
 87.3999 +								systemShowSpeed(int(float(gbaFrameCount) * 100000 / (float(gbaCurrentTime - gbaLastTime) * 60) + .5f));
 87.4000 +								gbaLastTime	  = gbaCurrentTime;
 87.4001 +								gbaFrameCount = 0;
 87.4002 +							}
 87.4003 +
 87.4004 +							++GBASystemCounters.frameCount;
 87.4005 +							if (GBASystemCounters.lagged)
 87.4006 +							{
 87.4007 +								++GBASystemCounters.lagCount;
 87.4008 +							}
 87.4009 +							GBASystemCounters.laggedLast = GBASystemCounters.lagged;
 87.4010 +							GBASystemCounters.lagged	 = true;
 87.4011 +
 87.4012 +							if (cheatsEnabled)
 87.4013 +								cheatsCheckKeys(P1 ^ 0x3FF, extButtons);
 87.4014 +
 87.4015 +							extern void VBAOnEnteringFrameBoundary();
 87.4016 +							VBAOnEnteringFrameBoundary();
 87.4017 +
 87.4018 +							newFrame = true;
 87.4019 +
 87.4020 +							pauseAfterFrameAdvance = systemPauseOnFrame();
 87.4021 +
 87.4022 +							if (frameSkipCount >= framesToSkip || pauseAfterFrameAdvance)
 87.4023 +							{
 87.4024 +								systemRenderFrame();
 87.4025 +								frameSkipCount = 0;
 87.4026 +
 87.4027 +								bool capturePressed = (extButtons & 2) != 0;
 87.4028 +								if (capturePressed && !capturePrevious)
 87.4029 +								{
 87.4030 +									captureNumber = systemScreenCapture(captureNumber);
 87.4031 +								}
 87.4032 +								capturePrevious = capturePressed && !pauseAfterFrameAdvance;
 87.4033 +							}
 87.4034 +							else
 87.4035 +							{
 87.4036 +								++frameSkipCount;
 87.4037 +							}
 87.4038 +
 87.4039 +							if (pauseAfterFrameAdvance)
 87.4040 +							{
 87.4041 +								systemSetPause(true);
 87.4042 +							}
 87.4043 +						}
 87.4044 +
 87.4045 +						UPDATE_REG(0x04, DISPSTAT);
 87.4046 +						CPUCompareVCOUNT();
 87.4047 +					}
 87.4048 +					else
 87.4049 +					{
 87.4050 +						if (frameSkipCount >= framesToSkip || pauseAfterFrameAdvance)
 87.4051 +						{
 87.4052 +							(*renderLine)();
 87.4053 +
 87.4054 +							switch (systemColorDepth)
 87.4055 +							{
 87.4056 +							case 16:
 87.4057 +							{
 87.4058 +								u16 *dest = (u16 *)pix + 242 * (VCOUNT + 1);
 87.4059 +								for (int x = 0; x < 240; )
 87.4060 +								{
 87.4061 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4062 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4063 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4064 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4065 +
 87.4066 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4067 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4068 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4069 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4070 +
 87.4071 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4072 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4073 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4074 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4075 +
 87.4076 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4077 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4078 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4079 +									*dest++ = systemColorMap16[lineMix[x++] & 0xFFFF];
 87.4080 +								}
 87.4081 +								// for filters that read past the screen
 87.4082 +								*dest++ = 0;
 87.4083 +								break;
 87.4084 +							}
 87.4085 +							case 24:
 87.4086 +							{
 87.4087 +								u8 *dest = (u8 *)pix + 240 * VCOUNT * 3;
 87.4088 +								for (int x = 0; x < 240; )
 87.4089 +								{
 87.4090 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4091 +									dest += 3;
 87.4092 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4093 +									dest += 3;
 87.4094 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4095 +									dest += 3;
 87.4096 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4097 +									dest += 3;
 87.4098 +
 87.4099 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4100 +									dest += 3;
 87.4101 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4102 +									dest += 3;
 87.4103 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4104 +									dest += 3;
 87.4105 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4106 +									dest += 3;
 87.4107 +
 87.4108 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4109 +									dest += 3;
 87.4110 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4111 +									dest += 3;
 87.4112 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4113 +									dest += 3;
 87.4114 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4115 +									dest += 3;
 87.4116 +
 87.4117 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4118 +									dest += 3;
 87.4119 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4120 +									dest += 3;
 87.4121 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4122 +									dest += 3;
 87.4123 +									*((u32 *)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4124 +									dest += 3;
 87.4125 +								}
 87.4126 +								break;
 87.4127 +							}
 87.4128 +							case 32:
 87.4129 +							{
 87.4130 +								u32 *dest = (u32 *)pix + 241 * (VCOUNT + 1);
 87.4131 +								for (int x = 0; x < 240; )
 87.4132 +								{
 87.4133 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4134 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4135 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4136 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4137 +
 87.4138 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4139 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4140 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4141 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4142 +
 87.4143 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4144 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4145 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4146 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4147 +
 87.4148 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4149 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4150 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4151 +									*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
 87.4152 +								}
 87.4153 +								break;
 87.4154 +							}
 87.4155 +							}
 87.4156 +						}
 87.4157 +						// entering H-Blank
 87.4158 +						DISPSTAT |= 2;
 87.4159 +						UPDATE_REG(0x04, DISPSTAT);
 87.4160 +						lcdTicks += 272;
 87.4161 +						CPUCheckDMA(2, 0x0f);
 87.4162 +						if (DISPSTAT & 16)
 87.4163 +						{
 87.4164 +							IF |= 2;
 87.4165 +							UPDATE_REG(0x202, IF);
 87.4166 +						}
 87.4167 +					}
 87.4168 +				}
 87.4169 +			}
 87.4170 +
 87.4171 +			if (!stopState)
 87.4172 +			{
 87.4173 +				if (timer0On)
 87.4174 +				{
 87.4175 +					if (timer0ClockReload == 1)
 87.4176 +					{
 87.4177 +						u32 tm0d = TM0D + clockTicks;
 87.4178 +						if (tm0d > 0xffff)
 87.4179 +						{
 87.4180 +							tm0d += timer0Reload;
 87.4181 +							timerOverflow |= 1;
 87.4182 +							soundTimerOverflow(0);
 87.4183 +							if (TM0CNT & 0x40)
 87.4184 +							{
 87.4185 +								IF |= 0x08;
 87.4186 +								UPDATE_REG(0x202, IF);
 87.4187 +							}
 87.4188 +						}
 87.4189 +						TM0D		= tm0d & 0xFFFF;
 87.4190 +						timer0Ticks = 0x10000 - TM0D;
 87.4191 +						UPDATE_REG(0x100, TM0D);
 87.4192 +					}
 87.4193 +					else
 87.4194 +					{
 87.4195 +						timer0Ticks -= clockTicks;
 87.4196 +						if (timer0Ticks <= 0)
 87.4197 +						{
 87.4198 +							timer0Ticks += timer0ClockReload;
 87.4199 +							TM0D++;
 87.4200 +							if (TM0D == 0)
 87.4201 +							{
 87.4202 +								TM0D = timer0Reload;
 87.4203 +								timerOverflow |= 1;
 87.4204 +								soundTimerOverflow(0);
 87.4205 +								if (TM0CNT & 0x40)
 87.4206 +								{
 87.4207 +									IF |= 0x08;
 87.4208 +									UPDATE_REG(0x202, IF);
 87.4209 +								}
 87.4210 +							}
 87.4211 +							UPDATE_REG(0x100, TM0D);
 87.4212 +						}
 87.4213 +					}
 87.4214 +				}
 87.4215 +
 87.4216 +				if (timer1On)
 87.4217 +				{
 87.4218 +					if (TM1CNT & 4)
 87.4219 +					{
 87.4220 +						if (timerOverflow & 1)
 87.4221 +						{
 87.4222 +							TM1D++;
 87.4223 +							if (TM1D == 0)
 87.4224 +							{
 87.4225 +								TM1D += timer1Reload;
 87.4226 +								timerOverflow |= 2;
 87.4227 +								soundTimerOverflow(1);
 87.4228 +								if (TM1CNT & 0x40)
 87.4229 +								{
 87.4230 +									IF |= 0x10;
 87.4231 +									UPDATE_REG(0x202, IF);
 87.4232 +								}
 87.4233 +							}
 87.4234 +							UPDATE_REG(0x104, TM1D);
 87.4235 +						}
 87.4236 +					}
 87.4237 +					else
 87.4238 +					{
 87.4239 +						if (timer1ClockReload == 1)
 87.4240 +						{
 87.4241 +							u32 tm1d = TM1D + clockTicks;
 87.4242 +							if (tm1d > 0xffff)
 87.4243 +							{
 87.4244 +								tm1d += timer1Reload;
 87.4245 +								timerOverflow |= 2;
 87.4246 +								soundTimerOverflow(1);
 87.4247 +								if (TM1CNT & 0x40)
 87.4248 +								{
 87.4249 +									IF |= 0x10;
 87.4250 +									UPDATE_REG(0x202, IF);
 87.4251 +								}
 87.4252 +							}
 87.4253 +							TM1D		= tm1d & 0xFFFF;
 87.4254 +							timer1Ticks = 0x10000 - TM1D;
 87.4255 +							UPDATE_REG(0x104, TM1D);
 87.4256 +						}
 87.4257 +						else
 87.4258 +						{
 87.4259 +							timer1Ticks -= clockTicks;
 87.4260 +							if (timer1Ticks <= 0)
 87.4261 +							{
 87.4262 +								timer1Ticks += timer1ClockReload;
 87.4263 +								TM1D++;
 87.4264 +
 87.4265 +								if (TM1D == 0)
 87.4266 +								{
 87.4267 +									TM1D = timer1Reload;
 87.4268 +									timerOverflow |= 2;
 87.4269 +									soundTimerOverflow(1);
 87.4270 +									if (TM1CNT & 0x40)
 87.4271 +									{
 87.4272 +										IF |= 0x10;
 87.4273 +										UPDATE_REG(0x202, IF);
 87.4274 +									}
 87.4275 +								}
 87.4276 +								UPDATE_REG(0x104, TM1D);
 87.4277 +							}
 87.4278 +						}
 87.4279 +					}
 87.4280 +				}
 87.4281 +
 87.4282 +				if (timer2On)
 87.4283 +				{
 87.4284 +					if (TM2CNT & 4)
 87.4285 +					{
 87.4286 +						if (timerOverflow & 2)
 87.4287 +						{
 87.4288 +							TM2D++;
 87.4289 +							if (TM2D == 0)
 87.4290 +							{
 87.4291 +								TM2D += timer2Reload;
 87.4292 +								timerOverflow |= 4;
 87.4293 +								if (TM2CNT & 0x40)
 87.4294 +								{
 87.4295 +									IF |= 0x20;
 87.4296 +									UPDATE_REG(0x202, IF);
 87.4297 +								}
 87.4298 +							}
 87.4299 +							UPDATE_REG(0x108, TM2D);
 87.4300 +						}
 87.4301 +					}
 87.4302 +					else
 87.4303 +					{
 87.4304 +						if (timer2ClockReload == 1)
 87.4305 +						{
 87.4306 +							u32 tm2d = TM2D + clockTicks;
 87.4307 +							if (tm2d > 0xffff)
 87.4308 +							{
 87.4309 +								tm2d += timer2Reload;
 87.4310 +								timerOverflow |= 4;
 87.4311 +								if (TM2CNT & 0x40)
 87.4312 +								{
 87.4313 +									IF |= 0x20;
 87.4314 +									UPDATE_REG(0x202, IF);
 87.4315 +								}
 87.4316 +							}
 87.4317 +							TM2D		= tm2d & 0xFFFF;
 87.4318 +							timer2Ticks = 0x10000 - TM2D;
 87.4319 +							UPDATE_REG(0x108, TM2D);
 87.4320 +						}
 87.4321 +						else
 87.4322 +						{
 87.4323 +							timer2Ticks -= clockTicks;
 87.4324 +							if (timer2Ticks <= 0)
 87.4325 +							{
 87.4326 +								timer2Ticks += timer2ClockReload;
 87.4327 +								TM2D++;
 87.4328 +
 87.4329 +								if (TM2D == 0)
 87.4330 +								{
 87.4331 +									TM2D = timer2Reload;
 87.4332 +									timerOverflow |= 4;
 87.4333 +									if (TM2CNT & 0x40)
 87.4334 +									{
 87.4335 +										IF |= 0x20;
 87.4336 +										UPDATE_REG(0x202, IF);
 87.4337 +									}
 87.4338 +								}
 87.4339 +								UPDATE_REG(0x108, TM2D);
 87.4340 +							}
 87.4341 +						}
 87.4342 +					}
 87.4343 +				}
 87.4344 +
 87.4345 +				if (timer3On)
 87.4346 +				{
 87.4347 +					if (TM3CNT & 4)
 87.4348 +					{
 87.4349 +						if (timerOverflow & 4)
 87.4350 +						{
 87.4351 +							TM3D++;
 87.4352 +							if (TM3D == 0)
 87.4353 +							{
 87.4354 +								TM3D += timer3Reload;
 87.4355 +								if (TM3CNT & 0x40)
 87.4356 +								{
 87.4357 +									IF |= 0x40;
 87.4358 +									UPDATE_REG(0x202, IF);
 87.4359 +								}
 87.4360 +							}
 87.4361 +							UPDATE_REG(0x10c, TM3D);
 87.4362 +						}
 87.4363 +					}
 87.4364 +					else
 87.4365 +					{
 87.4366 +						if (timer3ClockReload == 1)
 87.4367 +						{
 87.4368 +							u32 tm3d = TM3D + clockTicks;
 87.4369 +							if (tm3d > 0xffff)
 87.4370 +							{
 87.4371 +								tm3d += timer3Reload;
 87.4372 +								if (TM3CNT & 0x40)
 87.4373 +								{
 87.4374 +									IF |= 0x40;
 87.4375 +									UPDATE_REG(0x202, IF);
 87.4376 +								}
 87.4377 +							}
 87.4378 +							TM3D		= tm3d & 0xFFFF;
 87.4379 +							timer3Ticks = 0x10000 - TM3D;
 87.4380 +							UPDATE_REG(0x10C, TM3D);
 87.4381 +						}
 87.4382 +						else
 87.4383 +						{
 87.4384 +							timer3Ticks -= clockTicks;
 87.4385 +							if (timer3Ticks <= 0)
 87.4386 +							{
 87.4387 +								timer3Ticks += timer3ClockReload;
 87.4388 +								TM3D++;
 87.4389 +
 87.4390 +								if (TM3D == 0)
 87.4391 +								{
 87.4392 +									TM3D = timer3Reload;
 87.4393 +									if (TM3CNT & 0x40)
 87.4394 +									{
 87.4395 +										IF |= 0x40;
 87.4396 +										UPDATE_REG(0x202, IF);
 87.4397 +									}
 87.4398 +								}
 87.4399 +								UPDATE_REG(0x10C, TM3D);
 87.4400 +							}
 87.4401 +						}
 87.4402 +					}
 87.4403 +				}
 87.4404 +			}
 87.4405 +			// we shouldn't be doing sound in stop state, but we lose synchronization
 87.4406 +			// if sound is disabled, so in stop state, soundTick will just produce
 87.4407 +			// mute sound
 87.4408 +			soundTicks -= clockTicks;
 87.4409 +			if (soundTicks < 1)
 87.4410 +			{
 87.4411 +				soundTick();
 87.4412 +				soundTicks += SOUND_CLOCK_TICKS;
 87.4413 +			}
 87.4414 +			timerOverflow = 0;
 87.4415 +
 87.4416 +#ifdef PROFILING
 87.4417 +			profilingTicks -= clockTicks;
 87.4418 +			if (profilingTicks <= 0)
 87.4419 +			{
 87.4420 +				profilingTicks += profilingTicksReload;
 87.4421 +				if (profilBuffer && profilSize)
 87.4422 +				{
 87.4423 +					u16 *b	= (u16 *)profilBuffer;
 87.4424 +					int	 pc = ((reg[15].I - profilLowPC) * profilScale) / 0x10000;
 87.4425 +					if (pc >= 0 && pc < profilSize)
 87.4426 +					{
 87.4427 +						b[pc]++;
 87.4428 +					}
 87.4429 +				}
 87.4430 +			}
 87.4431 +#endif
 87.4432 +
 87.4433 +			ticks		-= clockTicks;
 87.4434 +			cpuLoopTicks = CPUUpdateTicks();
 87.4435 +
 87.4436 +			// FIXME: it is too bad that it is still not determined whether the loop can be exited at this point
 87.4437 +			if (cpuDmaTicksToUpdate > 0)
 87.4438 +			{
 87.4439 +				clockTicks = cpuSavedTicks;
 87.4440 +				if (clockTicks > cpuDmaTicksToUpdate)
 87.4441 +					clockTicks = cpuDmaTicksToUpdate;
 87.4442 +				cpuDmaTicksToUpdate -= clockTicks;
 87.4443 +				if (cpuDmaTicksToUpdate < 0)
 87.4444 +					cpuDmaTicksToUpdate = 0;
 87.4445 +				goto updateLoop;    // this is evil
 87.4446 +			}
 87.4447 +
 87.4448 +			if (IF && (IME & 1) && armIrqEnable)
 87.4449 +			{
 87.4450 +				int res = IF & IE;
 87.4451 +				if (stopState)
 87.4452 +					res &= 0x3080;
 87.4453 +				if (res)
 87.4454 +				{
 87.4455 +					if (intState)
 87.4456 +					{
 87.4457 +						CPUInterrupt();
 87.4458 +						intState = false;
 87.4459 +						if (holdState)
 87.4460 +						{
 87.4461 +							holdState = false;
 87.4462 +							stopState = false;
 87.4463 +						}
 87.4464 +					}
 87.4465 +					else
 87.4466 +					{
 87.4467 +						if (!holdState)
 87.4468 +						{
 87.4469 +							intState	  = true;
 87.4470 +							cpuLoopTicks  = 5;
 87.4471 +							cpuSavedTicks = 5;
 87.4472 +						}
 87.4473 +						else
 87.4474 +						{
 87.4475 +							CPUInterrupt();
 87.4476 +							if (holdState)
 87.4477 +							{
 87.4478 +								holdState = false;
 87.4479 +								stopState = false;
 87.4480 +							}
 87.4481 +						}
 87.4482 +					}
 87.4483 +				}
 87.4484 +			}
 87.4485 +
 87.4486 +			if (useOldFrameTiming)
 87.4487 +			{
 87.4488 +				if (ticks <= 0)
 87.4489 +				{
 87.4490 +					newFrame = true;
 87.4491 +					break;
 87.4492 +				}
 87.4493 +			}
 87.4494 +			else if (newFrame)
 87.4495 +			{
 87.4496 +				// FIXME: it should be enough to use frameBoundary only if there were no need for supporting the old timing
 87.4497 +				// but is there still any GBA .vbm that uses the old timing?
 87.4498 +///				extern void VBAOnEnteringFrameBoundary();
 87.4499 +///				VBAOnEnteringFrameBoundary();
 87.4500 +
 87.4501 +				break;
 87.4502 +			}
 87.4503 +		}
 87.4504 +	}
 87.4505 +}
 87.4506 +
 87.4507 +struct EmulatedSystem GBASystem =
 87.4508 +{
 87.4509 +	// emuMain
 87.4510 +	CPULoop,
 87.4511 +	// emuReset
 87.4512 +	CPUReset,
 87.4513 +	// emuCleanUp
 87.4514 +	CPUCleanUp,
 87.4515 +	// emuReadBattery
 87.4516 +	CPUReadBatteryFile,
 87.4517 +	// emuWriteBattery
 87.4518 +	CPUWriteBatteryFile,
 87.4519 +	// emuReadBatteryFromStream
 87.4520 +	CPUReadBatteryFromStream,
 87.4521 +	// emuWriteBatteryToStream
 87.4522 +	CPUWriteBatteryToStream,
 87.4523 +	// emuReadState
 87.4524 +	CPUReadState,
 87.4525 +	// emuWriteState
 87.4526 +	CPUWriteState,
 87.4527 +	// emuReadStateFromStream
 87.4528 +	CPUReadStateFromStream,
 87.4529 +	// emuWriteStateToStream
 87.4530 +	CPUWriteStateToStream,
 87.4531 +	// emuReadMemState
 87.4532 +	CPUReadMemState,
 87.4533 +	// emuWriteMemState
 87.4534 +	CPUWriteMemState,
 87.4535 +	// emuWritePNG
 87.4536 +	CPUWritePNGFile,
 87.4537 +	// emuWriteBMP
 87.4538 +	CPUWriteBMPFile,
 87.4539 +	// emuUpdateCPSR
 87.4540 +	CPUUpdateCPSR,
 87.4541 +	// emuHasDebugger
 87.4542 +	true,
 87.4543 +	// emuCount
 87.4544 +#ifdef FINAL_VERSION
 87.4545 +	250000,
 87.4546 +#else
 87.4547 +	5000,
 87.4548 +#endif
 87.4549 +};
 87.4550 +
 87.4551 +// is there a reason to use more than one set of counters?
 87.4552 +EmulatedSystemCounters &GBASystemCounters = systemCounters;
 87.4553 +
 87.4554 +/*
 87.4555 +   EmulatedSystemCounters GBASystemCounters =
 87.4556 +   {
 87.4557 +    // frameCount
 87.4558 +    0,
 87.4559 +    // lagCount
 87.4560 +    0,
 87.4561 +    // lagged
 87.4562 +    true,
 87.4563 +    // laggedLast
 87.4564 +    true,
 87.4565 +   };
 87.4566 + */
 87.4567 +
 87.4568 +
 87.4569 +#undef CPU_BREAK_LOOP
 87.4570 +#undef CPU_BREAK_LOOP2
    88.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    88.2 +++ b/src/gba/GBA.h	Sat Mar 03 10:31:27 2012 -0600
    88.3 @@ -0,0 +1,122 @@
    88.4 +#ifndef VBA_GBA_H
    88.5 +#define VBA_GBA_H
    88.6 +
    88.7 +#if _MSC_VER > 1000
    88.8 +#pragma once
    88.9 +#endif // _MSC_VER > 1000
   88.10 +
   88.11 +#include "zlib.h"
   88.12 +#include "../Port.h"
   88.13 +
   88.14 +#if (defined(WIN32) && !defined(SDL))
   88.15 +#include "../win32/stdafx.h" // for HANDLE
   88.16 +//#include <windows.h> // for HANDLE
   88.17 +// NOTE: if you get this error:
   88.18 +// #error WINDOWS.H already included.  MFC apps must not #include <windows.h>
   88.19 +// it is probably because stdafx.h is getting included at the wrong place
   88.20 +// (i.e. after anything else) in a file, or your precompiled headers are otherwise wrong
   88.21 +#endif
   88.22 +
   88.23 +#define SAVE_GAME_VERSION_1 1
   88.24 +#define SAVE_GAME_VERSION_2 2
   88.25 +#define SAVE_GAME_VERSION_3 3
   88.26 +#define SAVE_GAME_VERSION_4 4
   88.27 +#define SAVE_GAME_VERSION_5 5
   88.28 +#define SAVE_GAME_VERSION_6 6
   88.29 +#define SAVE_GAME_VERSION_7 7
   88.30 +#define SAVE_GAME_VERSION_8 8
   88.31 +#define SAVE_GAME_VERSION_9 9
   88.32 +#define SAVE_GAME_VERSION_10 10
   88.33 +#define SAVE_GAME_VERSION_11 11
   88.34 +#define SAVE_GAME_VERSION_12 12
   88.35 +#define SAVE_GAME_VERSION_13 13
   88.36 +#define SAVE_GAME_VERSION  SAVE_GAME_VERSION_13
   88.37 +
   88.38 +#if (defined(WIN32) && !defined(SDL))
   88.39 +extern HANDLE mapROM;        // shared memory handles
   88.40 +extern HANDLE mapWORKRAM;
   88.41 +extern HANDLE mapBIOS;
   88.42 +extern HANDLE mapIRAM;
   88.43 +extern HANDLE mapPALETTERAM;
   88.44 +extern HANDLE mapVRAM;
   88.45 +extern HANDLE mapOAM;
   88.46 +extern HANDLE mapPIX;
   88.47 +extern HANDLE mapIOMEM;
   88.48 +#endif
   88.49 +
   88.50 +/*
   88.51 +extern reg_pair reg[45];
   88.52 +extern u8       biosProtected[4];
   88.53 +
   88.54 +extern bool8 N_FLAG;
   88.55 +extern bool8 Z_FLAG;
   88.56 +extern bool8 C_FLAG;
   88.57 +extern bool8 V_FLAG;
   88.58 +extern bool8 armIrqEnable;
   88.59 +extern bool8 armState;
   88.60 +extern int32 armMode;
   88.61 +*/
   88.62 +extern void  (*cpuSaveGameFunc)(u32, u8);
   88.63 +
   88.64 +extern bool8 freezeWorkRAM[0x40000];
   88.65 +extern bool8 freezeInternalRAM[0x8000];
   88.66 +extern bool CPUReadGSASnapshot(const char *);
   88.67 +extern bool CPUWriteGSASnapshot(const char *, const char *, const char *, const char *);
   88.68 +extern bool CPUWriteBatteryFile(const char *);
   88.69 +extern bool CPUReadBatteryFile(const char *);
   88.70 +extern bool CPUWriteBatteryToStream(gzFile);
   88.71 +extern bool CPUReadBatteryFromStream(gzFile);
   88.72 +extern bool CPUExportEepromFile(const char *);
   88.73 +extern bool CPUImportEepromFile(const char *);
   88.74 +extern bool CPUWritePNGFile(const char *);
   88.75 +extern bool CPUWriteBMPFile(const char *);
   88.76 +extern void CPUCleanUp();
   88.77 +extern void CPUUpdateRender();
   88.78 +extern void CPUUpdateRenderBuffers(bool force);
   88.79 +extern bool CPUReadMemState(char *, int);
   88.80 +extern bool CPUReadState(const char *);
   88.81 +extern bool CPUWriteMemState(char *, int);
   88.82 +extern bool CPUWriteState(const char *);
   88.83 +extern bool CPUReadStateFromStream(gzFile);
   88.84 +extern bool CPUWriteStateToStream(gzFile);
   88.85 +extern int CPULoadRom(const char *);
   88.86 +extern void CPUUpdateRegister(u32, u16);
   88.87 +extern void CPUWriteHalfWord(u32, u16);
   88.88 +extern void CPUWriteByte(u32, u8);
   88.89 +extern bool CPULoadBios(const char *, bool);
   88.90 +extern void CPUInit();
   88.91 +extern void CPUReset(bool userReset = false);
   88.92 +extern void CPULoop(int);
   88.93 +extern void CPUCheckDMA(int, int);
   88.94 +#ifdef PROFILING
   88.95 +extern void cpuProfil(char *buffer, int, u32, int);
   88.96 +extern void cpuEnableProfiling(int hz);
   88.97 +#endif
   88.98 +
   88.99 +extern struct EmulatedSystem GBASystem;
  88.100 +extern struct EmulatedSystemCounters &GBASystemCounters;
  88.101 +
  88.102 +#define R13_IRQ  18
  88.103 +#define R14_IRQ  19
  88.104 +#define SPSR_IRQ 20
  88.105 +#define R13_USR  26
  88.106 +#define R14_USR  27
  88.107 +#define R13_SVC  28
  88.108 +#define R14_SVC  29
  88.109 +#define SPSR_SVC 30
  88.110 +#define R13_ABT  31
  88.111 +#define R14_ABT  32
  88.112 +#define SPSR_ABT 33
  88.113 +#define R13_UND  34
  88.114 +#define R14_UND  35
  88.115 +#define SPSR_UND 36
  88.116 +#define R8_FIQ   37
  88.117 +#define R9_FIQ   38
  88.118 +#define R10_FIQ  39
  88.119 +#define R11_FIQ  40
  88.120 +#define R12_FIQ  41
  88.121 +#define R13_FIQ  42
  88.122 +#define R14_FIQ  43
  88.123 +#define SPSR_FIQ 44
  88.124 +
  88.125 +#endif // VBA_GBA_H
    89.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    89.2 +++ b/src/gba/GBACheats.cpp	Sat Mar 03 10:31:27 2012 -0600
    89.3 @@ -0,0 +1,1822 @@
    89.4 +#include <cstdio>
    89.5 +#include <cctype>
    89.6 +#include <cstring>
    89.7 +
    89.8 +#include "../common/System.h"
    89.9 +#include "../common/Util.h"
   89.10 +#include "../NLS.h"
   89.11 +#include "GBACheats.h"
   89.12 +#include "GBA.h"
   89.13 +#include "GBAinline.h"
   89.14 +#include "GBAGlobals.h"
   89.15 +
   89.16 +/**
   89.17 + * Gameshark code types:
   89.18 + *
   89.19 + * NNNNNNNN 001DC0DE - ID code for the game (game 4 character name) from ROM
   89.20 + * DEADFACE XXXXXXXX - changes decryption seeds
   89.21 + * 0AAAAAAA 000000YY - 8-bit constant write
   89.22 + * 1AAAAAAA 0000YYYY - 16-bit constant write
   89.23 + * 2AAAAAAA YYYYYYYY - 32-bit constant write
   89.24 + * 3AAAAAAA YYYYYYYY - ??
   89.25 + * 6AAAAAAA 0000YYYY - 16-bit ROM Patch (address >> 1)
   89.26 + * 6AAAAAAA 1000YYYY - 16-bit ROM Patch ? (address >> 1)
   89.27 + * 6AAAAAAA 2000YYYY - 16-bit ROM Patch ? (address >> 1)
   89.28 + * 8A1AAAAA 000000YY - 8-bit button write
   89.29 + * 8A2AAAAA 0000YYYY - 16-bit button write
   89.30 + * 8A3AAAAA YYYYYYYY - 32-bit button write
   89.31 + * 80F00000 0000YYYY - button slow motion
   89.32 + * DAAAAAAA 0000YYYY - if address contains 16-bit value enable next code
   89.33 + * FAAAAAAA 0000YYYY - Master code function
   89.34 + *
   89.35 + * CodeBreaker codes types:
   89.36 + *
   89.37 + * 0000AAAA 000Y - Game CRC (Y are flags: 8 - CRC, 2 - DI)
   89.38 + * 1AAAAAAA YYYY - Master Code function (store address at ((YYYY << 0x16)
   89.39 + *                 + 0x08000100))
   89.40 + * 2AAAAAAA YYYY - 16-bit or
   89.41 + * 3AAAAAAA YYYY - 8-bit constant write
   89.42 + * 4AAAAAAA YYYY - Slide code
   89.43 + * XXXXCCCC IIII   (C is count and I is address increment, X is value incr.)
   89.44 + * 5AAAAAAA CCCC - Super code (Write bytes to address, CCCC is count)
   89.45 + * BBBBBBBB BBBB
   89.46 + * 6AAAAAAA YYYY - 16-bit and
   89.47 + * 7AAAAAAA YYYY - if address contains 16-bit value enable next code
   89.48 + * 8AAAAAAA YYYY - 16-bit constant write
   89.49 + * 9AAAAAAA YYYY - change decryption (when first code only?)
   89.50 + * AAAAAAAA YYYY - if address does not contain 16-bit value enable next code
   89.51 + * BAAAAAAA YYYY - if 16-bit < YYYY
   89.52 + * CAAAAAAA YYYY - if 16-bit > YYYY
   89.53 + * D0000020 YYYY - if button keys equal value enable next code
   89.54 + * EAAAAAAA YYYY - increase value stored in address
   89.55 + */
   89.56 +#define UNKNOWN_CODE           -1
   89.57 +#define INT_8_BIT_WRITE        0
   89.58 +#define INT_16_BIT_WRITE       1
   89.59 +#define INT_32_BIT_WRITE       2
   89.60 +#define GSA_16_BIT_ROM_PATCH   3
   89.61 +#define GSA_8_BIT_GS_WRITE     4
   89.62 +#define GSA_16_BIT_GS_WRITE    5
   89.63 +#define GSA_32_BIT_GS_WRITE    6
   89.64 +#define CBA_IF_KEYS_PRESSED    7
   89.65 +#define CBA_IF_TRUE            8
   89.66 +#define CBA_SLIDE_CODE         9
   89.67 +#define CBA_IF_FALSE           10
   89.68 +#define CBA_AND                11
   89.69 +#define GSA_8_BIT_GS_WRITE2    12
   89.70 +#define GSA_16_BIT_GS_WRITE2   13
   89.71 +#define GSA_32_BIT_GS_WRITE2   14
   89.72 +#define GSA_16_BIT_ROM_PATCH2  15
   89.73 +#define GSA_8_BIT_SLIDE        16
   89.74 +#define GSA_16_BIT_SLIDE       17
   89.75 +#define GSA_32_BIT_SLIDE       18
   89.76 +#define GSA_8_BIT_IF_TRUE      19
   89.77 +#define GSA_32_BIT_IF_TRUE     20
   89.78 +#define GSA_8_BIT_IF_FALSE     21
   89.79 +#define GSA_32_BIT_IF_FALSE    22
   89.80 +#define GSA_8_BIT_FILL         23
   89.81 +#define GSA_16_BIT_FILL        24
   89.82 +#define GSA_8_BIT_IF_TRUE2     25
   89.83 +#define GSA_16_BIT_IF_TRUE2    26
   89.84 +#define GSA_32_BIT_IF_TRUE2    27
   89.85 +#define GSA_8_BIT_IF_FALSE2    28
   89.86 +#define GSA_16_BIT_IF_FALSE2   29
   89.87 +#define GSA_32_BIT_IF_FALSE2   30
   89.88 +#define GSA_SLOWDOWN           31
   89.89 +#define CBA_ADD                32
   89.90 +#define CBA_OR                 33
   89.91 +#define CBA_LT                 34
   89.92 +#define CBA_GT                 35
   89.93 +#define CBA_SUPER              36
   89.94 +
   89.95 +CheatsData cheatsList[100];
   89.96 +int        cheatsNumber = 0;
   89.97 +
   89.98 +u8   cheatsCBASeedBuffer[0x30];
   89.99 +u32  cheatsCBASeed[4];
  89.100 +u32  cheatsCBATemporaryValue = 0;
  89.101 +u16  cheatsCBATable[256];
  89.102 +bool cheatsCBATableGenerated = false;
  89.103 +
  89.104 +u8 cheatsCBACurrentSeed[12] = {
  89.105 +	0x00, 0x00, 0x00, 0x00,
  89.106 +	0x00, 0x00, 0x00, 0x00,
  89.107 +	0x00, 0x00, 0x00, 0x00
  89.108 +};
  89.109 +
  89.110 +#define CHEAT_IS_HEX(a) (((a) >= 'A' && (a) <= 'F') || ((a) >= '0' && (a) <= '9'))
  89.111 +
  89.112 +#define CHEAT_PATCH_ROM_16BIT(a, v) \
  89.113 +    WRITE16LE(((u16 *)&rom[(a) & 0x1ffffff]), v);
  89.114 +
  89.115 +static bool isMultilineWithData(int i)
  89.116 +{
  89.117 +	// we consider it a multiline code if it has more than one line of data
  89.118 +	// otherwise, it can still be considered a single code
  89.119 +	if (i < cheatsNumber && i >= 0)
  89.120 +		switch (cheatsList[i].size)
  89.121 +		{
  89.122 +		case INT_8_BIT_WRITE:
  89.123 +		case INT_16_BIT_WRITE:
  89.124 +		case INT_32_BIT_WRITE:
  89.125 +		case GSA_16_BIT_ROM_PATCH:
  89.126 +		case GSA_8_BIT_GS_WRITE:
  89.127 +		case GSA_16_BIT_GS_WRITE:
  89.128 +		case GSA_32_BIT_GS_WRITE:
  89.129 +		case CBA_AND:
  89.130 +		case CBA_IF_KEYS_PRESSED:
  89.131 +		case CBA_IF_TRUE:
  89.132 +		case CBA_IF_FALSE:
  89.133 +		case GSA_8_BIT_IF_TRUE:
  89.134 +		case GSA_32_BIT_IF_TRUE:
  89.135 +		case GSA_8_BIT_IF_FALSE:
  89.136 +		case GSA_32_BIT_IF_FALSE:
  89.137 +		case GSA_8_BIT_FILL:
  89.138 +		case GSA_16_BIT_FILL:
  89.139 +		case GSA_8_BIT_IF_TRUE2:
  89.140 +		case GSA_16_BIT_IF_TRUE2:
  89.141 +		case GSA_32_BIT_IF_TRUE2:
  89.142 +		case GSA_8_BIT_IF_FALSE2:
  89.143 +		case GSA_16_BIT_IF_FALSE2:
  89.144 +		case GSA_32_BIT_IF_FALSE2:
  89.145 +		case GSA_SLOWDOWN:
  89.146 +		case CBA_ADD:
  89.147 +		case CBA_OR:
  89.148 +			return false;
  89.149 +		// the codes below have two lines of data
  89.150 +		case CBA_SLIDE_CODE:
  89.151 +		case GSA_8_BIT_GS_WRITE2:
  89.152 +		case GSA_16_BIT_GS_WRITE2:
  89.153 +		case GSA_32_BIT_GS_WRITE2:
  89.154 +		case GSA_16_BIT_ROM_PATCH2:
  89.155 +		case GSA_8_BIT_SLIDE:
  89.156 +		case GSA_16_BIT_SLIDE:
  89.157 +		case GSA_32_BIT_SLIDE:
  89.158 +		case CBA_LT:
  89.159 +		case CBA_GT:
  89.160 +		case CBA_SUPER:
  89.161 +			return true;
  89.162 +		}
  89.163 +	return false;
  89.164 +}
  89.165 +
  89.166 +static int getCodeLength(int num)
  89.167 +{
  89.168 +	if (num >= cheatsNumber || num < 0)
  89.169 +		return 1;
  89.170 +
  89.171 +	// this is for all the codes that are true multiline
  89.172 +	switch (cheatsList[num].size)
  89.173 +	{
  89.174 +	case INT_8_BIT_WRITE:
  89.175 +	case INT_16_BIT_WRITE:
  89.176 +	case INT_32_BIT_WRITE:
  89.177 +	case GSA_16_BIT_ROM_PATCH:
  89.178 +	case GSA_8_BIT_GS_WRITE:
  89.179 +	case GSA_16_BIT_GS_WRITE:
  89.180 +	case GSA_32_BIT_GS_WRITE:
  89.181 +	case CBA_AND:
  89.182 +	case GSA_8_BIT_FILL:
  89.183 +	case GSA_16_BIT_FILL:
  89.184 +	case GSA_SLOWDOWN:
  89.185 +	case CBA_ADD:
  89.186 +	case CBA_OR:
  89.187 +		return 1;
  89.188 +	case CBA_IF_KEYS_PRESSED:
  89.189 +	case CBA_IF_TRUE:
  89.190 +	case CBA_IF_FALSE:
  89.191 +	case CBA_SLIDE_CODE:
  89.192 +	case GSA_8_BIT_GS_WRITE2:
  89.193 +	case GSA_16_BIT_GS_WRITE2:
  89.194 +	case GSA_32_BIT_GS_WRITE2:
  89.195 +	case GSA_16_BIT_ROM_PATCH2:
  89.196 +	case GSA_8_BIT_SLIDE:
  89.197 +	case GSA_16_BIT_SLIDE:
  89.198 +	case GSA_32_BIT_SLIDE:
  89.199 +	case GSA_8_BIT_IF_TRUE:
  89.200 +	case GSA_32_BIT_IF_TRUE:
  89.201 +	case GSA_8_BIT_IF_FALSE:
  89.202 +	case GSA_32_BIT_IF_FALSE:
  89.203 +	case CBA_LT:
  89.204 +	case CBA_GT:
  89.205 +		return 2;
  89.206 +	case GSA_8_BIT_IF_TRUE2:
  89.207 +	case GSA_16_BIT_IF_TRUE2:
  89.208 +	case GSA_32_BIT_IF_TRUE2:
  89.209 +	case GSA_8_BIT_IF_FALSE2:
  89.210 +	case GSA_16_BIT_IF_FALSE2:
  89.211 +	case GSA_32_BIT_IF_FALSE2:
  89.212 +		return 3;
  89.213 +	case CBA_SUPER:
  89.214 +		return (cheatsList[num].value+5)/6;
  89.215 +	}
  89.216 +	return 1;
  89.217 +}
  89.218 +
  89.219 +int cheatsCheckKeys(u32 keys, u32 extended)
  89.220 +{
  89.221 +	int ticks = 0;
  89.222 +	for (int i = 0; i < cheatsNumber; i++)
  89.223 +	{
  89.224 +		if (!cheatsList[i].enabled)
  89.225 +		{
  89.226 +			// make sure we skip other lines in this code
  89.227 +			i += getCodeLength(i)-1;
  89.228 +			continue;
  89.229 +		}
  89.230 +		switch (cheatsList[i].size)
  89.231 +		{
  89.232 +		case INT_8_BIT_WRITE:
  89.233 +			CPUWriteByte(cheatsList[i].address, cheatsList[i].value);
  89.234 +			break;
  89.235 +		case INT_16_BIT_WRITE:
  89.236 +			CPUWriteHalfWord(cheatsList[i].address, cheatsList[i].value);
  89.237 +			break;
  89.238 +		case INT_32_BIT_WRITE:
  89.239 +			CPUWriteMemory(cheatsList[i].address, cheatsList[i].value);
  89.240 +			break;
  89.241 +		case GSA_16_BIT_ROM_PATCH:
  89.242 +			if ((cheatsList[i].status & 1) == 0)
  89.243 +			{
  89.244 +				if (CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value)
  89.245 +				{
  89.246 +					cheatsList[i].oldValue = CPUReadHalfWord(cheatsList[i].address);
  89.247 +					cheatsList[i].status  |= 1;
  89.248 +					CHEAT_PATCH_ROM_16BIT(cheatsList[i].address, cheatsList[i].value);
  89.249 +				}
  89.250 +			}
  89.251 +			break;
  89.252 +		case GSA_8_BIT_GS_WRITE:
  89.253 +			if (extended & 4)
  89.254 +			{
  89.255 +				CPUWriteByte(cheatsList[i].address, cheatsList[i].value);
  89.256 +			}
  89.257 +			break;
  89.258 +		case GSA_16_BIT_GS_WRITE:
  89.259 +			if (extended & 4)
  89.260 +			{
  89.261 +				CPUWriteHalfWord(cheatsList[i].address, cheatsList[i].value);
  89.262 +			}
  89.263 +			break;
  89.264 +		case GSA_32_BIT_GS_WRITE:
  89.265 +			if (extended & 4)
  89.266 +			{
  89.267 +				CPUWriteMemory(cheatsList[i].address, cheatsList[i].value);
  89.268 +			}
  89.269 +			break;
  89.270 +		case CBA_IF_KEYS_PRESSED:
  89.271 +		{
  89.272 +			u16 value = cheatsList[i].value;
  89.273 +			u32 addr  = cheatsList[i].address;
  89.274 +			if ((addr & 0x30) == 0x20)
  89.275 +			{
  89.276 +				if ((keys & value) != value)
  89.277 +				{
  89.278 +					i++;
  89.279 +				}
  89.280 +			}
  89.281 +			else if ((addr & 0x30) == 0x10)
  89.282 +			{
  89.283 +				if ((keys & value) == value)
  89.284 +				{
  89.285 +					i++;
  89.286 +				}
  89.287 +			}
  89.288 +			break;
  89.289 +		}
  89.290 +		case CBA_IF_TRUE:
  89.291 +			if (CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value)
  89.292 +			{
  89.293 +				i++;
  89.294 +			}
  89.295 +			break;
  89.296 +		case CBA_SLIDE_CODE:
  89.297 +		{
  89.298 +			u32 address = cheatsList[i].address;
  89.299 +			u16 value   = cheatsList[i].value;
  89.300 +			i++;
  89.301 +			if (i < cheatsNumber)
  89.302 +			{
  89.303 +				int count = (cheatsList[i].address & 0xFFFF);
  89.304 +				u16 vinc  = (cheatsList[i].address >> 16) & 0xFFFF;
  89.305 +				int inc   = cheatsList[i].value;
  89.306 +
  89.307 +				for (int x = 0; x < count; x++)
  89.308 +				{
  89.309 +					CPUWriteHalfWord(address, value);
  89.310 +					address += inc;
  89.311 +					value   += vinc;
  89.312 +				}
  89.313 +			}
  89.314 +			break;
  89.315 +		}
  89.316 +		case CBA_IF_FALSE:
  89.317 +			if (CPUReadHalfWord(cheatsList[i].address) == cheatsList[i].value)
  89.318 +			{
  89.319 +				i++;
  89.320 +			}
  89.321 +			break;
  89.322 +		case CBA_AND:
  89.323 +			CPUWriteHalfWord(cheatsList[i].address,
  89.324 +			                 CPUReadHalfWord(cheatsList[i].address) &
  89.325 +			                 cheatsList[i].value);
  89.326 +			break;
  89.327 +		case GSA_8_BIT_GS_WRITE2:
  89.328 +			i++;
  89.329 +			if (i < cheatsNumber)
  89.330 +			{
  89.331 +				if (extended & 4)
  89.332 +				{
  89.333 +					CPUWriteByte(cheatsList[i-1].value, cheatsList[i].address);
  89.334 +				}
  89.335 +			}
  89.336 +			break;
  89.337 +		case GSA_16_BIT_GS_WRITE2:
  89.338 +			i++;
  89.339 +			if (i < cheatsNumber)
  89.340 +			{
  89.341 +				if (extended & 4)
  89.342 +				{
  89.343 +					CPUWriteHalfWord(cheatsList[i-1].value, cheatsList[i].address);
  89.344 +				}
  89.345 +			}
  89.346 +			break;
  89.347 +		case GSA_32_BIT_GS_WRITE2:
  89.348 +			i++;
  89.349 +			if (i < cheatsNumber)
  89.350 +			{
  89.351 +				if (extended & 4)
  89.352 +				{
  89.353 +					CPUWriteMemory(cheatsList[i-1].value, cheatsList[i].address);
  89.354 +				}
  89.355 +			}
  89.356 +			break;
  89.357 +		case GSA_16_BIT_ROM_PATCH2:
  89.358 +			i++;
  89.359 +			if (i < cheatsNumber)
  89.360 +			{
  89.361 +				if ((cheatsList[i-1].status & 1) == 0)
  89.362 +				{
  89.363 +					u32 addr = ((cheatsList[i-1].value & 0x00FFFFFF) << 1) + 0x8000000;
  89.364 +					if (CPUReadHalfWord(addr) != (cheatsList[i].address & 0xFFFF))
  89.365 +					{
  89.366 +						cheatsList[i-1].oldValue = CPUReadHalfWord(addr);
  89.367 +						cheatsList[i-1].status  |= 1;
  89.368 +						CHEAT_PATCH_ROM_16BIT(addr, cheatsList[i].address & 0xFFFF);
  89.369 +					}
  89.370 +				}
  89.371 +			}
  89.372 +			break;
  89.373 +		case GSA_8_BIT_SLIDE:
  89.374 +			i++;
  89.375 +			if (i < cheatsNumber)
  89.376 +			{
  89.377 +				u32 addr  = cheatsList[i-1].value;
  89.378 +				u8  value = cheatsList[i].address;
  89.379 +				int vinc  = (cheatsList[i].value >> 24) & 255;
  89.380 +				int count = (cheatsList[i].value >> 16) & 255;
  89.381 +				int ainc  = (cheatsList[i].value & 0xffff);
  89.382 +				while (count > 0)
  89.383 +				{
  89.384 +					CPUWriteByte(addr, value);
  89.385 +					value += vinc;
  89.386 +					addr  += ainc;
  89.387 +					count--;
  89.388 +				}
  89.389 +			}
  89.390 +			break;
  89.391 +		case GSA_16_BIT_SLIDE:
  89.392 +			i++;
  89.393 +			if (i < cheatsNumber)
  89.394 +			{
  89.395 +				u32 addr  = cheatsList[i-1].value;
  89.396 +				u16 value = cheatsList[i].address;
  89.397 +				int vinc  = (cheatsList[i].value >> 24) & 255;
  89.398 +				int count = (cheatsList[i].value >> 16) & 255;
  89.399 +				int ainc  = (cheatsList[i].value & 0xffff)*2;
  89.400 +				while (count > 0)
  89.401 +				{
  89.402 +					CPUWriteHalfWord(addr, value);
  89.403 +					value += vinc;
  89.404 +					addr  += ainc;
  89.405 +					count--;
  89.406 +				}
  89.407 +			}
  89.408 +			break;
  89.409 +		case GSA_32_BIT_SLIDE:
  89.410 +			i++;
  89.411 +			if (i < cheatsNumber)
  89.412 +			{
  89.413 +				u32 addr  = cheatsList[i-1].value;
  89.414 +				u32 value = cheatsList[i].address;
  89.415 +				int vinc  = (cheatsList[i].value >> 24) & 255;
  89.416 +				int count = (cheatsList[i].value >> 16) & 255;
  89.417 +				int ainc  = (cheatsList[i].value & 0xffff)*4;
  89.418 +				while (count > 0)
  89.419 +				{
  89.420 +					CPUWriteMemory(addr, value);
  89.421 +					value += vinc;
  89.422 +					addr  += ainc;
  89.423 +					count--;
  89.424 +				}
  89.425 +			}
  89.426 +			break;
  89.427 +		case GSA_8_BIT_IF_TRUE:
  89.428 +			if (CPUReadByte(cheatsList[i].address) != cheatsList[i].value)
  89.429 +			{
  89.430 +				i++;
  89.431 +			}
  89.432 +			break;
  89.433 +		case GSA_32_BIT_IF_TRUE:
  89.434 +			if (CPUReadMemory(cheatsList[i].address) != cheatsList[i].value)
  89.435 +			{
  89.436 +				i++;
  89.437 +			}
  89.438 +			break;
  89.439 +		case GSA_8_BIT_IF_FALSE:
  89.440 +			if (CPUReadByte(cheatsList[i].address) == cheatsList[i].value)
  89.441 +			{
  89.442 +				i++;
  89.443 +			}
  89.444 +			break;
  89.445 +		case GSA_32_BIT_IF_FALSE:
  89.446 +			if (CPUReadMemory(cheatsList[i].address) == cheatsList[i].value)
  89.447 +			{
  89.448 +				i++;
  89.449 +			}
  89.450 +			break;
  89.451 +		case GSA_8_BIT_FILL:
  89.452 +		{
  89.453 +			u32 addr = cheatsList[i].address;
  89.454 +			u8  v    = cheatsList[i].value & 0xff;
  89.455 +			u32 end  = addr + (cheatsList[i].value >> 8);
  89.456 +			do
  89.457 +			{
  89.458 +				CPUWriteByte(addr, v);
  89.459 +				addr++;
  89.460 +			}
  89.461 +			while (addr <= end);
  89.462 +			break;
  89.463 +		}
  89.464 +		case GSA_16_BIT_FILL:
  89.465 +		{
  89.466 +			u32 addr = cheatsList[i].address;
  89.467 +			u16 v    = cheatsList[i].value & 0xffff;
  89.468 +			u32 end  = addr + ((cheatsList[i].value >> 16) << 1);
  89.469 +			do
  89.470 +			{
  89.471 +				CPUWriteHalfWord(addr, v);
  89.472 +				addr += 2;
  89.473 +			}
  89.474 +			while (addr <= end);
  89.475 +			break;
  89.476 +		}
  89.477 +		case GSA_8_BIT_IF_TRUE2:
  89.478 +			if (CPUReadByte(cheatsList[i].address) != cheatsList[i].value)
  89.479 +			{
  89.480 +				i += 2;
  89.481 +			}
  89.482 +			break;
  89.483 +		case GSA_16_BIT_IF_TRUE2:
  89.484 +			if (CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value)
  89.485 +			{
  89.486 +				i += 2;
  89.487 +			}
  89.488 +			break;
  89.489 +		case GSA_32_BIT_IF_TRUE2:
  89.490 +			if (CPUReadMemory(cheatsList[i].address) != cheatsList[i].value)
  89.491 +			{
  89.492 +				i += 2;
  89.493 +			}
  89.494 +			break;
  89.495 +		case GSA_8_BIT_IF_FALSE2:
  89.496 +			if (CPUReadByte(cheatsList[i].address) == cheatsList[i].value)
  89.497 +			{
  89.498 +				i += 2;
  89.499 +			}
  89.500 +			break;
  89.501 +		case GSA_16_BIT_IF_FALSE2:
  89.502 +			if (CPUReadHalfWord(cheatsList[i].address) == cheatsList[i].value)
  89.503 +			{
  89.504 +				i += 2;
  89.505 +			}
  89.506 +			break;
  89.507 +		case GSA_32_BIT_IF_FALSE2:
  89.508 +			if (CPUReadMemory(cheatsList[i].address) == cheatsList[i].value)
  89.509 +			{
  89.510 +				i += 2;
  89.511 +			}
  89.512 +			break;
  89.513 +		case GSA_SLOWDOWN:
  89.514 +			// check if button was pressed and released, if so toggle our state
  89.515 +			if ((cheatsList[i].status & 4) && !(extended & 4))
  89.516 +				cheatsList[i].status ^= 1;
  89.517 +			if (extended & 4)
  89.518 +				cheatsList[i].status |= 4;
  89.519 +			else
  89.520 +				cheatsList[i].status &= ~4;
  89.521 +
  89.522 +			if (cheatsList[i].status & 1)
  89.523 +				ticks += 2*256*((cheatsList[i].value >> 8) & 255);
  89.524 +			break;
  89.525 +		case CBA_ADD:
  89.526 +			CPUWriteHalfWord(cheatsList[i].address,
  89.527 +			                 CPUReadHalfWord(cheatsList[i].address) +
  89.528 +			                 (u16)cheatsList[i].value);
  89.529 +			break;
  89.530 +		case CBA_OR:
  89.531 +			CPUWriteHalfWord(cheatsList[i].address,
  89.532 +			                 CPUReadHalfWord(cheatsList[i].address) |
  89.533 +			                 cheatsList[i].value);
  89.534 +			break;
  89.535 +		case CBA_LT:
  89.536 +			if (CPUReadHalfWord(cheatsList[i].address) >= cheatsList[i].value)
  89.537 +				i++;
  89.538 +			break;
  89.539 +		case CBA_GT:
  89.540 +			if (CPUReadHalfWord(cheatsList[i].address) <= cheatsList[i].value)
  89.541 +				i++;
  89.542 +			break;
  89.543 +		case CBA_SUPER:
  89.544 +		{
  89.545 +			int count   = 2*cheatsList[i].value;
  89.546 +			u32 address = cheatsList[i].address;
  89.547 +			for (int x = 0; x < count; x++)
  89.548 +			{
  89.549 +				u8  b;
  89.550 +				int res = x % 6;
  89.551 +				if (res < 4)
  89.552 +					b = (cheatsList[i].address >> (24-8*res)) & 0xFF;
  89.553 +				else
  89.554 +					b = (cheatsList[i].value >> (8 - 8*(res-4))) & 0x0FF;
  89.555 +				CPUWriteByte(address, b);
  89.556 +				address++;
  89.557 +				if (x && !res)
  89.558 +					i++;
  89.559 +			}
  89.560 +			if (count % 6)
  89.561 +				i++;
  89.562 +			break;
  89.563 +		}
  89.564 +		}
  89.565 +	}
  89.566 +	return ticks;
  89.567 +}
  89.568 +
  89.569 +void cheatsAdd(const char *codeStr,
  89.570 +               const char *desc,
  89.571 +               u32 address,
  89.572 +               u32 value,
  89.573 +               int code,
  89.574 +               int size)
  89.575 +{
  89.576 +	if (cheatsNumber < 100)
  89.577 +	{
  89.578 +		int x = cheatsNumber;
  89.579 +		cheatsList[x].code    = code;
  89.580 +		cheatsList[x].size    = size;
  89.581 +		cheatsList[x].address = address;
  89.582 +		cheatsList[x].value   = value;
  89.583 +		strcpy(cheatsList[x].codestring, codeStr);
  89.584 +		strcpy(cheatsList[x].desc, desc);
  89.585 +		cheatsList[x].enabled = true;
  89.586 +		cheatsList[x].status  = 0;
  89.587 +
  89.588 +		// we only store the old value for this simple codes. ROM patching
  89.589 +		// is taken care when it actually patches the ROM
  89.590 +		switch (cheatsList[x].size)
  89.591 +		{
  89.592 +		case INT_8_BIT_WRITE:
  89.593 +			cheatsList[x].oldValue = CPUReadByte(address);
  89.594 +			break;
  89.595 +		case INT_16_BIT_WRITE:
  89.596 +			cheatsList[x].oldValue = CPUReadHalfWord(address);
  89.597 +			break;
  89.598 +		case INT_32_BIT_WRITE:
  89.599 +			cheatsList[x].oldValue = CPUReadMemory(address);
  89.600 +			break;
  89.601 +		}
  89.602 +		cheatsNumber++;
  89.603 +	}
  89.604 +}
  89.605 +
  89.606 +void cheatsDelete(int number, bool restore)
  89.607 +{
  89.608 +	if (number < cheatsNumber && number >= 0)
  89.609 +	{
  89.610 +		int x = number;
  89.611 +
  89.612 +		if (restore)
  89.613 +		{
  89.614 +			switch (cheatsList[x].size)
  89.615 +			{
  89.616 +			case INT_8_BIT_WRITE:
  89.617 +				CPUWriteByte(cheatsList[x].address, (u8)cheatsList[x].oldValue);
  89.618 +				break;
  89.619 +			case INT_16_BIT_WRITE:
  89.620 +				CPUWriteHalfWord(cheatsList[x].address, (u16)cheatsList[x].oldValue);
  89.621 +				break;
  89.622 +			case INT_32_BIT_WRITE:
  89.623 +				CPUWriteMemory(cheatsList[x].address, cheatsList[x].oldValue);
  89.624 +				break;
  89.625 +			case GSA_16_BIT_ROM_PATCH:
  89.626 +				if (cheatsList[x].status & 1)
  89.627 +				{
  89.628 +					cheatsList[x].status &= ~1;
  89.629 +					CHEAT_PATCH_ROM_16BIT(cheatsList[x].address,
  89.630 +					                      cheatsList[x].oldValue);
  89.631 +				}
  89.632 +				break;
  89.633 +			case GSA_16_BIT_ROM_PATCH2:
  89.634 +				if (cheatsList[x].status & 1)
  89.635 +				{
  89.636 +					cheatsList[x].status &= ~1;
  89.637 +					CHEAT_PATCH_ROM_16BIT(((cheatsList[x].value & 0x00FFFFFF) << 1)+
  89.638 +					                      0x8000000,
  89.639 +					                      cheatsList[x].oldValue);
  89.640 +				}
  89.641 +				break;
  89.642 +			}
  89.643 +		}
  89.644 +		if ((x+1) <  cheatsNumber)
  89.645 +		{
  89.646 +			memcpy(&cheatsList[x], &cheatsList[x+1], sizeof(CheatsData)*
  89.647 +			       (cheatsNumber-x-1));
  89.648 +		}
  89.649 +		cheatsNumber--;
  89.650 +	}
  89.651 +}
  89.652 +
  89.653 +void cheatsDeleteAll(bool restore)
  89.654 +{
  89.655 +	for (int i = cheatsNumber-1; i >= 0; i--)
  89.656 +	{
  89.657 +		cheatsDelete(i, restore);
  89.658 +	}
  89.659 +}
  89.660 +
  89.661 +void cheatsEnable(int i)
  89.662 +{
  89.663 +	if (i >= 0 && i < cheatsNumber)
  89.664 +	{
  89.665 +		cheatsList[i].enabled = true;
  89.666 +	}
  89.667 +}
  89.668 +
  89.669 +void cheatsDisable(int i)
  89.670 +{
  89.671 +	if (i >= 0 && i < cheatsNumber)
  89.672 +	{
  89.673 +		switch (cheatsList[i].size)
  89.674 +		{
  89.675 +		case GSA_16_BIT_ROM_PATCH:
  89.676 +			if (cheatsList[i].status & 1)
  89.677 +			{
  89.678 +				cheatsList[i].status &= ~1;
  89.679 +				CHEAT_PATCH_ROM_16BIT(cheatsList[i].address,
  89.680 +				                      cheatsList[i].oldValue);
  89.681 +			}
  89.682 +			break;
  89.683 +		case GSA_16_BIT_ROM_PATCH2:
  89.684 +			if (cheatsList[i].status & 1)
  89.685 +			{
  89.686 +				cheatsList[i].status &= ~1;
  89.687 +				CHEAT_PATCH_ROM_16BIT(((cheatsList[i].value & 0x00FFFFFF) << 1)+
  89.688 +				                      0x8000000,
  89.689 +				                      cheatsList[i].oldValue);
  89.690 +			}
  89.691 +			break;
  89.692 +		}
  89.693 +		cheatsList[i].enabled = false;
  89.694 +	}
  89.695 +}
  89.696 +
  89.697 +bool cheatsVerifyCheatCode(const char *code, const char *desc)
  89.698 +{
  89.699 +	int len = strlen(code);
  89.700 +	if (len != 11 && len != 13 && len != 17)
  89.701 +	{
  89.702 +		systemMessage(MSG_INVALID_CHEAT_CODE, N_("Invalid cheat code '%s'"), code);
  89.703 +		return false;
  89.704 +	}
  89.705 +
  89.706 +	if (code[8] != ':')
  89.707 +	{
  89.708 +		systemMessage(MSG_INVALID_CHEAT_CODE, N_("Invalid cheat code '%s'"), code);
  89.709 +		return false;
  89.710 +	}
  89.711 +
  89.712 +	int i;
  89.713 +	for (i = 0; i < 8; i++)
  89.714 +	{
  89.715 +		if (!CHEAT_IS_HEX(code[i]))
  89.716 +		{
  89.717 +			// wrong cheat
  89.718 +			systemMessage(MSG_INVALID_CHEAT_CODE,
  89.719 +			              N_("Invalid cheat code '%s'"), code);
  89.720 +			return false;
  89.721 +		}
  89.722 +	}
  89.723 +	for (i = 9; i < len; i++)
  89.724 +	{
  89.725 +		if (!CHEAT_IS_HEX(code[i]))
  89.726 +		{
  89.727 +			// wrong cheat
  89.728 +			systemMessage(MSG_INVALID_CHEAT_CODE,
  89.729 +			              N_("Invalid cheat code '%s'"), code);
  89.730 +			return false;
  89.731 +		}
  89.732 +	}
  89.733 +
  89.734 +	u32 address = 0;
  89.735 +	u32 value   = 0;
  89.736 +
  89.737 +	char buffer[10];
  89.738 +	strncpy(buffer, code, 8);
  89.739 +	buffer[8] = 0;
  89.740 +	sscanf(buffer, "%x", &address);
  89.741 +
  89.742 +	switch (address >> 24)
  89.743 +	{
  89.744 +	case 2:
  89.745 +	case 3:
  89.746 +		break;
  89.747 +	default:
  89.748 +		systemMessage(MSG_INVALID_CHEAT_CODE_ADDRESS,
  89.749 +		              N_("Invalid cheat code address: %08x"),
  89.750 +		              address);
  89.751 +		return false;
  89.752 +	}
  89.753 +
  89.754 +	strncpy(buffer, &code[9], 8);
  89.755 +	sscanf(buffer, "%x", &value);
  89.756 +	int type = 0;
  89.757 +	if (len == 13)
  89.758 +		type = 1;
  89.759 +	if (len == 17)
  89.760 +		type = 2;
  89.761 +	cheatsAdd(code, desc, address, value, type, type);
  89.762 +	return true;
  89.763 +}
  89.764 +
  89.765 +void cheatsAddCheatCode(const char *code, const char *desc)
  89.766 +{
  89.767 +	cheatsVerifyCheatCode(code, desc);
  89.768 +}
  89.769 +
  89.770 +void cheatsDecryptGSACode(u32& address, u32& value, bool v3)
  89.771 +{
  89.772 +	u32  rollingseed = 0xC6EF3720;
  89.773 +	u32  seeds_v1[]  =  { 0x09F4FBBD, 0x9681884A, 0x352027E9, 0xF3DEE5A7 };
  89.774 +	u32  seeds_v3[]  = { 0x7AA9648F, 0x7FAE6994, 0xC0EFAAD5, 0x42712C57 };
  89.775 +	u32 *seeds       = v3 ? seeds_v3 : seeds_v1;
  89.776 +
  89.777 +	int bitsleft = 32;
  89.778 +	while (bitsleft > 0)
  89.779 +	{
  89.780 +		value -= ((((address << 4) + seeds[2]) ^ (address + rollingseed)) ^
  89.781 +		          ((address >> 5) + seeds[3]));
  89.782 +		address -= ((((value << 4) + seeds[0]) ^ (value + rollingseed)) ^
  89.783 +		            ((value >> 5) + seeds[1]));
  89.784 +		rollingseed -= 0x9E3779B9;
  89.785 +		bitsleft--;
  89.786 +	}
  89.787 +}
  89.788 +
  89.789 +void cheatsAddGSACode(const char *code, const char *desc, bool v3)
  89.790 +{
  89.791 +	if (strlen(code) != 16)
  89.792 +	{
  89.793 +		// wrong cheat
  89.794 +		systemMessage(MSG_INVALID_GSA_CODE,
  89.795 +		              N_("Invalid GSA code. Format is XXXXXXXXYYYYYYYY"));
  89.796 +		return;
  89.797 +	}
  89.798 +
  89.799 +	int i;
  89.800 +	for (i = 0; i < 16; i++)
  89.801 +	{
  89.802 +		if (!CHEAT_IS_HEX(code[i]))
  89.803 +		{
  89.804 +			// wrong cheat
  89.805 +			systemMessage(MSG_INVALID_GSA_CODE,
  89.806 +			              N_("Invalid GSA code. Format is XXXXXXXXYYYYYYYY"));
  89.807 +			return;
  89.808 +		}
  89.809 +	}
  89.810 +
  89.811 +	char buffer[10];
  89.812 +	strncpy(buffer, code, 8);
  89.813 +	buffer[8] = 0;
  89.814 +	u32 address;
  89.815 +	sscanf(buffer, "%x", &address);
  89.816 +	strncpy(buffer, &code[8], 8);
  89.817 +	buffer[8] = 0;
  89.818 +	u32 value;
  89.819 +	sscanf(buffer, "%x", &value);
  89.820 +
  89.821 +	cheatsDecryptGSACode(address, value, v3);
  89.822 +
  89.823 +	if (value == 0x1DC0DE)
  89.824 +	{
  89.825 +		u32 gamecode = READ32LE(((u32 *)&rom[0xac]));
  89.826 +		if (gamecode != address)
  89.827 +		{
  89.828 +			char buffer[5];
  89.829 +			*((u32 *)buffer) = address;
  89.830 +			buffer[4]        = 0;
  89.831 +			char buffer2[5];
  89.832 +			*((u32 *)buffer2) = READ32LE(((u32 *)&rom[0xac]));
  89.833 +			buffer2[4]        = 0;
  89.834 +			systemMessage(MSG_GBA_CODE_WARNING,
  89.835 +			              N_("Warning: cheats are for game %s. Current game is %s.\nCodes may not work correctly."),
  89.836 +			              buffer, buffer2);
  89.837 +		}
  89.838 +		cheatsAdd(code, desc, address & 0x0FFFFFFF, value, v3 ? 257 : 256,
  89.839 +		          UNKNOWN_CODE);
  89.840 +		return;
  89.841 +	}
  89.842 +	if (isMultilineWithData(cheatsNumber-1))
  89.843 +	{
  89.844 +		cheatsAdd(code, desc, address, value, v3 ? 257 : 256, UNKNOWN_CODE);
  89.845 +		return;
  89.846 +	}
  89.847 +	if (v3)
  89.848 +	{
  89.849 +		int type = (address >> 25) & 127;
  89.850 +		u32 addr = (address & 0x00F00000) << 4 | (address & 0x0003FFFF);
  89.851 +		switch (type)
  89.852 +		{
  89.853 +		case 0x00:
  89.854 +			if (address == 0)
  89.855 +			{
  89.856 +				type = (value >> 25) & 127;
  89.857 +				addr = (value & 0x00F00000) << 4 | (value & 0x0003FFFF);
  89.858 +				switch (type)
  89.859 +				{
  89.860 +				case 0x04:
  89.861 +					cheatsAdd(code, desc, 0, value & 0x00FFFFFF, 257, GSA_SLOWDOWN);
  89.862 +					break;
  89.863 +				case 0x08:
  89.864 +					cheatsAdd(code, desc, 0, addr, 257, GSA_8_BIT_GS_WRITE2);
  89.865 +					break;
  89.866 +				case 0x09:
  89.867 +					cheatsAdd(code, desc, 0, addr, 257, GSA_16_BIT_GS_WRITE2);
  89.868 +					break;
  89.869 +				case 0x0a:
  89.870 +					cheatsAdd(code, desc, 0, addr, 257, GSA_32_BIT_GS_WRITE2);
  89.871 +					break;
  89.872 +				case 0x0c:
  89.873 +				case 0x0d:
  89.874 +				case 0x0e:
  89.875 +				case 0x0f:
  89.876 +					cheatsAdd(code, desc, 0, value & 0x00FFFFFF, 257, GSA_16_BIT_ROM_PATCH2);
  89.877 +					break;
  89.878 +				case 0x40:
  89.879 +					cheatsAdd(code, desc, 0, addr, 257, GSA_8_BIT_SLIDE);
  89.880 +					break;
  89.881 +				case 0x41:
  89.882 +					cheatsAdd(code, desc, 0, addr, 257, GSA_16_BIT_SLIDE);
  89.883 +					break;
  89.884 +				case 0x42:
  89.885 +					cheatsAdd(code, desc, 0, addr, 257, GSA_32_BIT_SLIDE);
  89.886 +					break;
  89.887 +				default:
  89.888 +					cheatsAdd(code, desc, address, value, 257, UNKNOWN_CODE);
  89.889 +					break;
  89.890 +				}
  89.891 +			}
  89.892 +			else
  89.893 +				cheatsAdd(code, desc, addr, value, 257, GSA_8_BIT_FILL);
  89.894 +			break;
  89.895 +		case 0x01:
  89.896 +			cheatsAdd(code, desc, addr, value, 257, GSA_16_BIT_FILL);
  89.897 +			break;
  89.898 +		case 0x02:
  89.899 +			cheatsAdd(code, desc, addr, value, 257, INT_32_BIT_WRITE);
  89.900 +			break;
  89.901 +		case 0x04:
  89.902 +			cheatsAdd(code, desc, addr, value, 257, GSA_8_BIT_IF_TRUE);
  89.903 +			break;
  89.904 +		case 0x05:
  89.905 +			cheatsAdd(code, desc, addr, value, 257, CBA_IF_TRUE);
  89.906 +			break;
  89.907 +		case 0x06:
  89.908 +			cheatsAdd(code, desc, addr, value, 257, GSA_32_BIT_IF_TRUE);
  89.909 +			break;
  89.910 +		case 0x08:
  89.911 +			cheatsAdd(code, desc, addr, value, 257, GSA_8_BIT_IF_FALSE);
  89.912 +			break;
  89.913 +		case 0x09:
  89.914 +			cheatsAdd(code, desc, addr, value, 257, CBA_IF_FALSE);
  89.915 +			break;
  89.916 +		case 0x0a:
  89.917 +			cheatsAdd(code, desc, addr, value, 257, GSA_32_BIT_IF_FALSE);
  89.918 +			break;
  89.919 +		case 0x24:
  89.920 +			cheatsAdd(code, desc, addr, value, 257, GSA_8_BIT_IF_TRUE2);
  89.921 +			break;
  89.922 +		case 0x25:
  89.923 +			cheatsAdd(code, desc, addr, value, 257, GSA_16_BIT_IF_TRUE2);
  89.924 +			break;
  89.925 +		case 0x26:
  89.926 +			cheatsAdd(code, desc, addr, value, 257, GSA_32_BIT_IF_TRUE2);
  89.927 +			break;
  89.928 +		case 0x28:
  89.929 +			cheatsAdd(code, desc, addr, value, 257, GSA_8_BIT_IF_FALSE2);
  89.930 +			break;
  89.931 +		case 0x29:
  89.932 +			cheatsAdd(code, desc, addr, value, 257, GSA_16_BIT_IF_FALSE2);
  89.933 +			break;
  89.934 +		case 0x2a:
  89.935 +			cheatsAdd(code, desc, addr, value, 257, GSA_32_BIT_IF_FALSE2);
  89.936 +			break;
  89.937 +		default:
  89.938 +			cheatsAdd(code, desc, address, value, 257, UNKNOWN_CODE);
  89.939 +			break;
  89.940 +		}
  89.941 +	}
  89.942 +	else
  89.943 +	{
  89.944 +		int type = (address >> 28) & 15;
  89.945 +		switch (type)
  89.946 +		{
  89.947 +		case 0:
  89.948 +		case 1:
  89.949 +		case 2:
  89.950 +			cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 256, type);
  89.951 +			break;
  89.952 +		case 6:
  89.953 +			address <<= 1;
  89.954 +			type      = (address >> 28) & 15;
  89.955 +			if (type == 0x0c)
  89.956 +			{
  89.957 +				cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 256,
  89.958 +				          GSA_16_BIT_ROM_PATCH);
  89.959 +				break;
  89.960 +			}
  89.961 +			// unsupported code
  89.962 +			cheatsAdd(code, desc, address, value, 256,
  89.963 +			          UNKNOWN_CODE);
  89.964 +			break;
  89.965 +		case 8:
  89.966 +			switch ((address >> 20) & 15)
  89.967 +			{
  89.968 +			case 1:
  89.969 +				cheatsAdd(code, desc, address & 0x0F0FFFFF, value, 256,
  89.970 +				          GSA_8_BIT_GS_WRITE);
  89.971 +				break;
  89.972 +			case 2:
  89.973 +				cheatsAdd(code, desc, address & 0x0F0FFFFF, value, 256,
  89.974 +				          GSA_16_BIT_GS_WRITE);
  89.975 +				break;
  89.976 +			case 3:
  89.977 +				cheatsAdd(code, desc, address & 0x0F0FFFFF, value, 256,
  89.978 +				          GSA_32_BIT_GS_WRITE);
  89.979 +			case 15:
  89.980 +				cheatsAdd(code, desc, 0, value & 0xFF00, 256, GSA_SLOWDOWN);
  89.981 +				break;
  89.982 +			default:
  89.983 +				// unsupported code
  89.984 +				cheatsAdd(code, desc, address, value, 256,
  89.985 +				          UNKNOWN_CODE);
  89.986 +				break;
  89.987 +			}
  89.988 +			break;
  89.989 +		case 0x0d:
  89.990 +			if (address != 0xDEADFACE)
  89.991 +			{
  89.992 +				cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 256,
  89.993 +				          CBA_IF_TRUE);
  89.994 +			}
  89.995 +			else
  89.996 +				cheatsAdd(code, desc, address, value, 256,
  89.997 +				          UNKNOWN_CODE);
  89.998 +			break;
  89.999 +		default:
 89.1000 +			// unsupported code
 89.1001 +			cheatsAdd(code, desc, address, value, 256,
 89.1002 +			          UNKNOWN_CODE);
 89.1003 +			break;
 89.1004 +		}
 89.1005 +	}
 89.1006 +}
 89.1007 +
 89.1008 +bool cheatsImportGSACodeFile(const char *name, int game, bool v3)
 89.1009 +{
 89.1010 +	FILE *f = fopen(name, "rb");
 89.1011 +	if (!f)
 89.1012 +		return false;
 89.1013 +
 89.1014 +	int games = 0;
 89.1015 +	int len   = 0;
 89.1016 +	fseek(f, 0x1e, SEEK_CUR);
 89.1017 +	fread(&games, 1, 4, f);
 89.1018 +	bool found = false;
 89.1019 +	int  g     = 0;
 89.1020 +	while (games > 0)
 89.1021 +	{
 89.1022 +		if (g == game)
 89.1023 +		{
 89.1024 +			found = true;
 89.1025 +			break;
 89.1026 +		}
 89.1027 +		fread(&len, 1, 4, f);
 89.1028 +		fseek(f, len, SEEK_CUR);
 89.1029 +		int codes = 0;
 89.1030 +		fread(&codes, 1, 4, f);
 89.1031 +		while (codes > 0)
 89.1032 +		{
 89.1033 +			fread(&len, 1, 4, f);
 89.1034 +			fseek(f, len, SEEK_CUR);
 89.1035 +			fseek(f, 8, SEEK_CUR);
 89.1036 +			fread(&len, 1, 4, f);
 89.1037 +			fseek(f, len*12, SEEK_CUR);
 89.1038 +			codes--;
 89.1039 +		}
 89.1040 +		games--;
 89.1041 +		g++;
 89.1042 +	}
 89.1043 +	if (found)
 89.1044 +	{
 89.1045 +		char desc[256];
 89.1046 +		char code[17];
 89.1047 +		fread(&len, 1, 4, f);
 89.1048 +		fseek(f, len, SEEK_CUR);
 89.1049 +		int codes = 0;
 89.1050 +		fread(&codes, 1, 4, f);
 89.1051 +		while (codes > 0)
 89.1052 +		{
 89.1053 +			fread(&len, 1, 4, f);
 89.1054 +			fread(desc, 1, len, f);
 89.1055 +			desc[len] = 0;
 89.1056 +			desc[31]  = 0;
 89.1057 +			fread(&len, 1, 4, f);
 89.1058 +			fseek(f, len, SEEK_CUR);
 89.1059 +			fseek(f, 4, SEEK_CUR);
 89.1060 +			fread(&len, 1, 4, f);
 89.1061 +			while (len)
 89.1062 +			{
 89.1063 +				fseek(f, 4, SEEK_CUR);
 89.1064 +				fread(code, 1, 8, f);
 89.1065 +				fseek(f, 4, SEEK_CUR);
 89.1066 +				fread(&code[8], 1, 8, f);
 89.1067 +				code[16] = 0;
 89.1068 +				cheatsAddGSACode(code, desc, v3);
 89.1069 +				len -= 2;
 89.1070 +			}
 89.1071 +			codes--;
 89.1072 +		}
 89.1073 +	}
 89.1074 +	fclose(f);
 89.1075 +	return false;
 89.1076 +}
 89.1077 +
 89.1078 +void cheatsCBAReverseArray(u8 *array, u8 *dest)
 89.1079 +{
 89.1080 +	dest[0] = array[3];
 89.1081 +	dest[1] = array[2];
 89.1082 +	dest[2] = array[1];
 89.1083 +	dest[3] = array[0];
 89.1084 +	dest[4] = array[5];
 89.1085 +	dest[5] = array[4];
 89.1086 +}
 89.1087 +
 89.1088 +void chatsCBAScramble(u8 *array, int count, u8 b)
 89.1089 +{
 89.1090 +	u8 *x  = array + (count >> 3);
 89.1091 +	u8 *y  = array + (b >> 3);
 89.1092 +	u32 z  = *x & (1 << (count & 7));
 89.1093 +	u32 x0 = (*x & (~(1 << (count & 7))));
 89.1094 +	if (z != 0)
 89.1095 +		z = 1;
 89.1096 +	if ((*y & (1 << (b & 7))) != 0)
 89.1097 +		x0 |= (1 << (count & 7));
 89.1098 +	*x = x0;
 89.1099 +	u32 temp = *y & (~(1 << (b & 7)));
 89.1100 +	if (z != 0)
 89.1101 +		temp |= (1 << (b & 7));
 89.1102 +	*y = temp;
 89.1103 +}
 89.1104 +
 89.1105 +u32 cheatsCBAGetValue(u8 *array)
 89.1106 +{
 89.1107 +	return array[0] | array[1]<<8 | array[2] << 16 | array[3]<<24;
 89.1108 +}
 89.1109 +
 89.1110 +u16 cheatsCBAGetData(u8 *array)
 89.1111 +{
 89.1112 +	return array[4] | array[5]<<8;
 89.1113 +}
 89.1114 +
 89.1115 +void cheatsCBAArrayToValue(u8 *array, u8 *dest)
 89.1116 +{
 89.1117 +	dest[0] = array[3];
 89.1118 +	dest[1] = array[2];
 89.1119 +	dest[2] = array[1];
 89.1120 +	dest[3] = array[0];
 89.1121 +	dest[4] = array[5];
 89.1122 +	dest[5] = array[4];
 89.1123 +}
 89.1124 +
 89.1125 +void cheatsCBAParseSeedCode(u32 address, u32 value, u32 *array)
 89.1126 +{
 89.1127 +	array[0] = 1;
 89.1128 +	array[1] = value & 0xFF;
 89.1129 +	array[2] = (address >> 0x10) & 0xFF;
 89.1130 +	array[3] = (value >> 8) & 0xFF;
 89.1131 +	array[4] = (address >> 0x18) & 0x0F;
 89.1132 +	array[5] = address & 0xFFFF;
 89.1133 +	array[6] = address;
 89.1134 +	array[7] = value;
 89.1135 +}
 89.1136 +
 89.1137 +u32 cheatsCBAEncWorker()
 89.1138 +{
 89.1139 +	u32 x = (cheatsCBATemporaryValue * 0x41c64e6d) + 0x3039;
 89.1140 +	u32 y = (x * 0x41c64e6d) + 0x3039;
 89.1141 +	u32 z = x >> 0x10;
 89.1142 +	x = ((y >> 0x10) & 0x7fff) << 0x0f;
 89.1143 +	z = (z << 0x1e) | x;
 89.1144 +	x = (y * 0x41c64e6d) + 0x3039;
 89.1145 +	cheatsCBATemporaryValue = x;
 89.1146 +	return z | ((x >> 0x10) & 0x7fff);
 89.1147 +}
 89.1148 +
 89.1149 +#define ROR(v, s) \
 89.1150 +    (((v) >> (s)) | (((v) & ((1 << (s))-1)) << (32 - (s))))
 89.1151 +
 89.1152 +u32 cheatsCBACalcIndex(u32 x, u32 y)
 89.1153 +{
 89.1154 +	if (y != 0)
 89.1155 +	{
 89.1156 +		if (y == 1)
 89.1157 +			x = 0;
 89.1158 +		else if (x == y)
 89.1159 +			x = 0;
 89.1160 +		if (y < 1)
 89.1161 +			return x;
 89.1162 +		else if (x < y)
 89.1163 +			return x;
 89.1164 +		u32 x0 = 1;
 89.1165 +
 89.1166 +		while (y < 0x10000000)
 89.1167 +		{
 89.1168 +			if (y < x)
 89.1169 +			{
 89.1170 +				y  = y << 4;
 89.1171 +				x0 = x0 << 4;
 89.1172 +			}
 89.1173 +			else
 89.1174 +				break;
 89.1175 +		}
 89.1176 +
 89.1177 +		while (y < 0x80000000)
 89.1178 +		{
 89.1179 +			if (y < x)
 89.1180 +			{
 89.1181 +				y  = y << 1;
 89.1182 +				x0 = x0 << 1;
 89.1183 +			}
 89.1184 +			else
 89.1185 +				break;
 89.1186 +		}
 89.1187 +
 89.1188 +loop:
 89.1189 +		u32 z = 0;
 89.1190 +		if (x >= y)
 89.1191 +			x -= y;
 89.1192 +		if (x >= (y >> 1))
 89.1193 +		{
 89.1194 +			x -= (y >> 1);
 89.1195 +			z |= ROR(x0, 1);
 89.1196 +		}
 89.1197 +		if (x >= (y >> 2))
 89.1198 +		{
 89.1199 +			x -= (y >> 2);
 89.1200 +			z |= ROR(x0, 2);
 89.1201 +		}
 89.1202 +		if (x >= (y >> 3))
 89.1203 +		{
 89.1204 +			x -= (y >> 3);
 89.1205 +			z |= ROR(x0, 3);
 89.1206 +		}
 89.1207 +
 89.1208 +		u32 temp = x0;
 89.1209 +
 89.1210 +		if (x != 0)
 89.1211 +		{
 89.1212 +			x0 = x0 >> 4;
 89.1213 +			if (x0 != 0)
 89.1214 +			{
 89.1215 +				y = y >> 4;
 89.1216 +				goto loop;
 89.1217 +			}
 89.1218 +		}
 89.1219 +
 89.1220 +		z = z & 0xe0000000;
 89.1221 +
 89.1222 +		if (z != 0)
 89.1223 +		{
 89.1224 +			if ((temp & 7) == 0)
 89.1225 +				return x;
 89.1226 +		}
 89.1227 +		else
 89.1228 +			return x;
 89.1229 +
 89.1230 +		if ((z & ROR(temp, 3)) != 0)
 89.1231 +			x += y >> 3;
 89.1232 +		if ((z & ROR(temp, 2)) != 0)
 89.1233 +			x += y >> 2;
 89.1234 +		if ((z & ROR(temp, 1)) != 0)
 89.1235 +			x += y >> 1;
 89.1236 +		return x;
 89.1237 +	}
 89.1238 +	else
 89.1239 +	{}
 89.1240 +	// should not happen in the current code
 89.1241 +	return 0;
 89.1242 +}
 89.1243 +
 89.1244 +void cheatsCBAUpdateSeedBuffer(u32 a, u8 *buffer, int count)
 89.1245 +{
 89.1246 +	int i;
 89.1247 +	for (i = 0; i < count; i++)
 89.1248 +		buffer[i] = i;
 89.1249 +	for (i = 0; (u32)i < a; i++)
 89.1250 +	{
 89.1251 +		u32 a = cheatsCBACalcIndex(cheatsCBAEncWorker(), count);
 89.1252 +		u32 b = cheatsCBACalcIndex(cheatsCBAEncWorker(), count);
 89.1253 +		u32 t = buffer[a];
 89.1254 +		buffer[a] = buffer[b];
 89.1255 +		buffer[b] = t;
 89.1256 +	}
 89.1257 +}
 89.1258 +
 89.1259 +void cheatsCBAChangeEncryption(u32 *seed)
 89.1260 +{
 89.1261 +	int i;
 89.1262 +
 89.1263 +	cheatsCBATemporaryValue = (seed[1] ^ 0x1111);
 89.1264 +	cheatsCBAUpdateSeedBuffer(0x50, cheatsCBASeedBuffer, 0x30);
 89.1265 +	cheatsCBATemporaryValue = 0x4efad1c3;
 89.1266 +
 89.1267 +	for (i = 0; (u32)i < seed[4]; i++)
 89.1268 +	{
 89.1269 +		cheatsCBATemporaryValue = cheatsCBAEncWorker();
 89.1270 +	}
 89.1271 +	cheatsCBASeed[2] = cheatsCBAEncWorker();
 89.1272 +	cheatsCBASeed[3] = cheatsCBAEncWorker();
 89.1273 +
 89.1274 +	cheatsCBATemporaryValue = seed[3] ^ 0xf254;
 89.1275 +
 89.1276 +	for (i = 0; (u32)i < seed[3]; i++)
 89.1277 +	{
 89.1278 +		cheatsCBATemporaryValue = cheatsCBAEncWorker();
 89.1279 +	}
 89.1280 +
 89.1281 +	cheatsCBASeed[0] = cheatsCBAEncWorker();
 89.1282 +	cheatsCBASeed[1] = cheatsCBAEncWorker();
 89.1283 +
 89.1284 +	*((u32 *)&cheatsCBACurrentSeed[0]) = seed[6];
 89.1285 +	*((u32 *)&cheatsCBACurrentSeed[4]) = seed[7];
 89.1286 +	*((u32 *)&cheatsCBACurrentSeed[8]) = 0;
 89.1287 +}
 89.1288 +
 89.1289 +u16 cheatsCBAGenValue(u32 x, u32 y, u32 z)
 89.1290 +{
 89.1291 +	y <<= 0x10;
 89.1292 +	z <<= 0x10;
 89.1293 +	x <<= 0x18;
 89.1294 +	u32 x0 = (int)y >> 0x10;
 89.1295 +	z = (int)z >> 0x10;
 89.1296 +	x = (int)x >> 0x10;
 89.1297 +	for (int i = 0; i < 8; i++)
 89.1298 +	{
 89.1299 +		u32 temp = z ^ x;
 89.1300 +		if ((int)temp >= 0)
 89.1301 +		{
 89.1302 +			temp = z << 0x11;
 89.1303 +		}
 89.1304 +		else
 89.1305 +		{
 89.1306 +			temp  = z << 0x01;
 89.1307 +			temp ^= x0;
 89.1308 +			temp  = temp << 0x10;
 89.1309 +		}
 89.1310 +		z    = (int)temp >> 0x10;
 89.1311 +		temp = x << 0x11;
 89.1312 +		x    = (int)temp >> 0x10;
 89.1313 +	}
 89.1314 +	return z & 0xffff;
 89.1315 +}
 89.1316 +
 89.1317 +void cheatsCBAGenTable()
 89.1318 +{
 89.1319 +	for (int i = 0; i < 0x100; i++)
 89.1320 +	{
 89.1321 +		cheatsCBATable[i] = cheatsCBAGenValue(i, 0x1021, 0);
 89.1322 +	}
 89.1323 +	cheatsCBATableGenerated = true;
 89.1324 +}
 89.1325 +
 89.1326 +u16 cheatsCBACalcCRC(u8 *rom, int count)
 89.1327 +{
 89.1328 +	u32 crc = 0xffffffff;
 89.1329 +
 89.1330 +	if (count & 3)
 89.1331 +	{
 89.1332 +		// 0x08000EAE
 89.1333 +	}
 89.1334 +	else
 89.1335 +	{
 89.1336 +		count = (count >> 2) - 1;
 89.1337 +		if (count != -1)
 89.1338 +		{
 89.1339 +			while (count != -1)
 89.1340 +			{
 89.1341 +				crc = (((crc << 0x08) ^ cheatsCBATable[(((u32)crc << 0x10) >> 0x18)
 89.1342 +				                                       ^ *rom++]) << 0x10) >> 0x10;
 89.1343 +				crc = (((crc << 0x08) ^ cheatsCBATable[(((u32)crc << 0x10) >> 0x18)
 89.1344 +				                                       ^ *rom++]) << 0x10) >> 0x10;
 89.1345 +				crc = (((crc << 0x08) ^ cheatsCBATable[(((u32)crc << 0x10) >> 0x18)
 89.1346 +				                                       ^ *rom++]) << 0x10) >> 0x10;
 89.1347 +				crc = (((crc << 0x08) ^ cheatsCBATable[(((u32)crc << 0x10) >> 0x18)
 89.1348 +				                                       ^ *rom++]) << 0x10) >> 0x10;
 89.1349 +				count--;
 89.1350 +			}
 89.1351 +		}
 89.1352 +	}
 89.1353 +	return crc & 0xffff;
 89.1354 +}
 89.1355 +
 89.1356 +void cheatsCBADecrypt(u8 *decrypt)
 89.1357 +{
 89.1358 +	u8  buffer[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
 89.1359 +	u8 *array     = &buffer[1];
 89.1360 +
 89.1361 +	cheatsCBAReverseArray(decrypt, array);
 89.1362 +
 89.1363 +	for (int count = 0x2f; count >= 0; count--)
 89.1364 +	{
 89.1365 +		chatsCBAScramble(array, count, cheatsCBASeedBuffer[count]);
 89.1366 +	}
 89.1367 +	cheatsCBAArrayToValue(array, decrypt);
 89.1368 +	*((u32 *)decrypt) = cheatsCBAGetValue(decrypt) ^
 89.1369 +	                    cheatsCBASeed[0];
 89.1370 +	*((u16 *)(decrypt+4)) = (cheatsCBAGetData(decrypt) ^
 89.1371 +	                         cheatsCBASeed[1]) & 0xffff;
 89.1372 +
 89.1373 +	cheatsCBAReverseArray(decrypt, array);
 89.1374 +
 89.1375 +	u32 cs = cheatsCBAGetValue(cheatsCBACurrentSeed);
 89.1376 +	for (int i = 0; i <= 4; i++)
 89.1377 +	{
 89.1378 +		array[i] = ((cs >> 8) ^ array[i+1]) ^ array[i] ;
 89.1379 +	}
 89.1380 +
 89.1381 +	array[5] = (cs >> 8) ^ array[5];
 89.1382 +
 89.1383 +	for (int j = 5; j >= 0; j--)
 89.1384 +	{
 89.1385 +		array[j] = (cs ^ array[j-1]) ^ array[j];
 89.1386 +	}
 89.1387 +
 89.1388 +	cheatsCBAArrayToValue(array, decrypt);
 89.1389 +
 89.1390 +	*((u32 *)decrypt) = cheatsCBAGetValue(decrypt)
 89.1391 +	                    ^ cheatsCBASeed[2];
 89.1392 +	*((u16 *)(decrypt+4)) = (cheatsCBAGetData(decrypt)
 89.1393 +	                         ^ cheatsCBASeed[3]) & 0xffff;
 89.1394 +}
 89.1395 +
 89.1396 +int cheatsCBAGetCount()
 89.1397 +{
 89.1398 +	int count = 0;
 89.1399 +	for (int i = 0; i < cheatsNumber; i++)
 89.1400 +	{
 89.1401 +		if (cheatsList[i].code == 512)
 89.1402 +			count++;
 89.1403 +	}
 89.1404 +	return count;
 89.1405 +}
 89.1406 +
 89.1407 +bool cheatsCBAShouldDecrypt()
 89.1408 +{
 89.1409 +	for (int i = 0; i < cheatsNumber; i++)
 89.1410 +	{
 89.1411 +		if (cheatsList[i].code == 512)
 89.1412 +		{
 89.1413 +			return (cheatsList[i].codestring[0] == '9');
 89.1414 +		}
 89.1415 +	}
 89.1416 +	return false;
 89.1417 +}
 89.1418 +
 89.1419 +void cheatsAddCBACode(const char *code, const char *desc)
 89.1420 +{
 89.1421 +	if (strlen(code) != 13)
 89.1422 +	{
 89.1423 +		// wrong cheat
 89.1424 +		systemMessage(MSG_INVALID_CBA_CODE,
 89.1425 +		              N_("Invalid CBA code. Format is XXXXXXXX YYYY."));
 89.1426 +		return;
 89.1427 +	}
 89.1428 +
 89.1429 +	int i;
 89.1430 +	for (i = 0; i < 8; i++)
 89.1431 +	{
 89.1432 +		if (!CHEAT_IS_HEX(code[i]))
 89.1433 +		{
 89.1434 +			// wrong cheat
 89.1435 +			systemMessage(MSG_INVALID_CBA_CODE,
 89.1436 +			              N_("Invalid CBA code. Format is XXXXXXXX YYYY."));
 89.1437 +			return;
 89.1438 +		}
 89.1439 +	}
 89.1440 +
 89.1441 +	if (code[8] != ' ')
 89.1442 +	{
 89.1443 +		systemMessage(MSG_INVALID_CBA_CODE,
 89.1444 +		              N_("Invalid CBA code. Format is XXXXXXXX YYYY."));
 89.1445 +		return;
 89.1446 +	}
 89.1447 +
 89.1448 +	for (i = 9; i < 13; i++)
 89.1449 +	{
 89.1450 +		if (!CHEAT_IS_HEX(code[i]))
 89.1451 +		{
 89.1452 +			// wrong cheat
 89.1453 +			systemMessage(MSG_INVALID_CBA_CODE,
 89.1454 +			              N_("Invalid CBA code. Format is XXXXXXXX YYYY."));
 89.1455 +			return;
 89.1456 +		}
 89.1457 +	}
 89.1458 +
 89.1459 +	char buffer[10];
 89.1460 +	strncpy(buffer, code, 8);
 89.1461 +	buffer[8] = 0;
 89.1462 +	u32 address;
 89.1463 +	sscanf(buffer, "%x", &address);
 89.1464 +	strncpy(buffer, &code[9], 4);
 89.1465 +	buffer[4] = 0;
 89.1466 +	u32 value;
 89.1467 +	sscanf(buffer, "%x", &value);
 89.1468 +
 89.1469 +	u8 array[8] = {
 89.1470 +		address &255,
 89.1471 +		(address >> 8) & 255,
 89.1472 +		(address >> 16) & 255,
 89.1473 +		(address >> 24) & 255,
 89.1474 +		(value & 255),
 89.1475 +		(value >> 8) & 255,
 89.1476 +		0,
 89.1477 +		0
 89.1478 +	};
 89.1479 +
 89.1480 +	if (cheatsCBAGetCount() == 0 &&
 89.1481 +	    (address >> 28) == 9)
 89.1482 +	{
 89.1483 +		u32 seed[8];
 89.1484 +		cheatsCBAParseSeedCode(address, value, seed);
 89.1485 +		cheatsCBAChangeEncryption(seed);
 89.1486 +		cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512, UNKNOWN_CODE);
 89.1487 +	}
 89.1488 +	else
 89.1489 +	{
 89.1490 +		if (cheatsCBAShouldDecrypt())
 89.1491 +			cheatsCBADecrypt(array);
 89.1492 +
 89.1493 +		address = READ32LE(((u32 *)array));
 89.1494 +		value   = READ16LE(((u16 *)&array[4]));
 89.1495 +
 89.1496 +		int type = (address >> 28) & 15;
 89.1497 +
 89.1498 +		if (isMultilineWithData(cheatsNumber-1))
 89.1499 +		{
 89.1500 +			cheatsAdd(code, desc, address, value, 512, UNKNOWN_CODE);
 89.1501 +			return;
 89.1502 +		}
 89.1503 +
 89.1504 +		switch (type)
 89.1505 +		{
 89.1506 +		case 0x00:
 89.1507 +		{
 89.1508 +			if (!cheatsCBATableGenerated)
 89.1509 +				cheatsCBAGenTable();
 89.1510 +			u32 crc = cheatsCBACalcCRC(rom, 0x10000);
 89.1511 +			if (crc != address)
 89.1512 +			{
 89.1513 +				systemMessage(MSG_CBA_CODE_WARNING,
 89.1514 +				              N_("Warning: Codes seem to be for a different game.\nCodes may not work correctly."));
 89.1515 +			}
 89.1516 +			cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512,
 89.1517 +			          UNKNOWN_CODE);
 89.1518 +			break;
 89.1519 +		}
 89.1520 +		case 0x02:
 89.1521 +			cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512,
 89.1522 +			          CBA_OR);
 89.1523 +			break;
 89.1524 +		case 0x03:
 89.1525 +			cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512,
 89.1526 +			          INT_8_BIT_WRITE);
 89.1527 +			break;
 89.1528 +		case 0x04:
 89.1529 +			cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512,
 89.1530 +			          CBA_SLIDE_CODE);
 89.1531 +			break;
 89.1532 +		case 0x05:
 89.1533 +			cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512,
 89.1534 +			          CBA_SUPER);
 89.1535 +			break;
 89.1536 +		case 0x06:
 89.1537 +			cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512,
 89.1538 +			          CBA_AND);
 89.1539 +			break;
 89.1540 +		case 0x07:
 89.1541 +			cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512,
 89.1542 +			          CBA_IF_TRUE);
 89.1543 +			break;
 89.1544 +		case 0x08:
 89.1545 +			cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512,
 89.1546 +			          INT_16_BIT_WRITE);
 89.1547 +			break;
 89.1548 +		case 0x0a:
 89.1549 +			cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512,
 89.1550 +			          CBA_IF_FALSE);
 89.1551 +			break;
 89.1552 +		case 0x0b:
 89.1553 +			cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512,
 89.1554 +			          CBA_LT);
 89.1555 +			break;
 89.1556 +		case 0x0c:
 89.1557 +			cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512,
 89.1558 +			          CBA_GT);
 89.1559 +			break;
 89.1560 +		case 0x0d:
 89.1561 +			cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512,
 89.1562 +			          CBA_IF_KEYS_PRESSED);
 89.1563 +			break;
 89.1564 +		case 0x0e:
 89.1565 +			cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512,
 89.1566 +			          CBA_ADD);
 89.1567 +			break;
 89.1568 +		default:
 89.1569 +			// unsupported code
 89.1570 +			cheatsAdd(code, desc, address & 0xFFFFFFFF, value, 512,
 89.1571 +			          UNKNOWN_CODE);
 89.1572 +			break;
 89.1573 +		}
 89.1574 +	}
 89.1575 +}
 89.1576 +
 89.1577 +void cheatsSaveGame(gzFile file)
 89.1578 +{
 89.1579 +	utilWriteInt(file, cheatsNumber);
 89.1580 +
 89.1581 +	utilGzWrite(file, cheatsList, sizeof(cheatsList));
 89.1582 +}
 89.1583 +
 89.1584 +void cheatsReadGame(gzFile file)
 89.1585 +{
 89.1586 +	cheatsNumber = 0;
 89.1587 +
 89.1588 +	cheatsNumber = utilReadInt(file);
 89.1589 +
 89.1590 +	utilGzRead(file, cheatsList, sizeof(cheatsList));
 89.1591 +
 89.1592 +	bool firstCodeBreaker = true;
 89.1593 +
 89.1594 +	for (int i = 0; i < cheatsNumber; i++)
 89.1595 +	{
 89.1596 +		cheatsList[i].status = 0;
 89.1597 +		if (!cheatsList[i].codestring[0])
 89.1598 +		{
 89.1599 +			switch (cheatsList[i].size)
 89.1600 +			{
 89.1601 +			case 0:
 89.1602 +				sprintf(cheatsList[i].codestring, "%08x:%02x", cheatsList[i].address,
 89.1603 +				        cheatsList[i].value);
 89.1604 +				break;
 89.1605 +			case 1:
 89.1606 +				sprintf(cheatsList[i].codestring, "%08x:%04x", cheatsList[i].address,
 89.1607 +				        cheatsList[i].value);
 89.1608 +				break;
 89.1609 +			case 2:
 89.1610 +				sprintf(cheatsList[i].codestring, "%08x:%08x", cheatsList[i].address,
 89.1611 +				        cheatsList[i].value);
 89.1612 +				break;
 89.1613 +			}
 89.1614 +		}
 89.1615 +
 89.1616 +		if (cheatsList[i].enabled)
 89.1617 +		{
 89.1618 +			cheatsEnable(i);
 89.1619 +		}
 89.1620 +
 89.1621 +		if (cheatsList[i].code == 512 && firstCodeBreaker)
 89.1622 +		{
 89.1623 +			firstCodeBreaker = false;
 89.1624 +			char buffer[10];
 89.1625 +			strncpy(buffer, cheatsList[i].codestring, 8);
 89.1626 +			buffer[8] = 0;
 89.1627 +			u32 address;
 89.1628 +			sscanf(buffer, "%x", &address);
 89.1629 +			if ((address >> 28) == 9)
 89.1630 +			{
 89.1631 +				strncpy(buffer, &cheatsList[i].codestring[9], 4);
 89.1632 +				buffer[4] = 0;
 89.1633 +				u32 value;
 89.1634 +				sscanf(buffer, "%x", &value);
 89.1635 +
 89.1636 +				u32 seed[8];
 89.1637 +				cheatsCBAParseSeedCode(address, value, seed);
 89.1638 +				cheatsCBAChangeEncryption(seed);
 89.1639 +			}
 89.1640 +		}
 89.1641 +	}
 89.1642 +}
 89.1643 +
 89.1644 +void cheatsSaveCheatList(const char *file)
 89.1645 +{
 89.1646 +	if (cheatsNumber == 0)
 89.1647 +		return;
 89.1648 +	FILE *f = fopen(file, "wb");
 89.1649 +	if (f == NULL)
 89.1650 +		return;
 89.1651 +	int version = 1;
 89.1652 +	fwrite(&version, 1, sizeof(version), f);
 89.1653 +	int type = 0;
 89.1654 +	fwrite(&type, 1, sizeof(type), f);
 89.1655 +	fwrite(&cheatsNumber, 1, sizeof(cheatsNumber), f);
 89.1656 +	fwrite(cheatsList, 1, sizeof(cheatsList), f);
 89.1657 +	fclose(f);
 89.1658 +}
 89.1659 +
 89.1660 +bool cheatsLoadCheatList(const char *file)
 89.1661 +{
 89.1662 +	cheatsNumber = 0;
 89.1663 +
 89.1664 +	int count = 0;
 89.1665 +
 89.1666 +	FILE *f = fopen(file, "rb");
 89.1667 +
 89.1668 +	if (f == NULL)
 89.1669 +		return false;
 89.1670 +
 89.1671 +	int version = 0;
 89.1672 +
 89.1673 +	if (fread(&version, 1, sizeof(version), f) != sizeof(version))
 89.1674 +	{
 89.1675 +		fclose(f);
 89.1676 +		return false;
 89.1677 +	}
 89.1678 +
 89.1679 +	if (version != 1)
 89.1680 +	{
 89.1681 +		systemMessage(MSG_UNSUPPORTED_CHEAT_LIST_VERSION,
 89.1682 +		              N_("Unsupported cheat list version %d"), version);
 89.1683 +		fclose(f);
 89.1684 +		return false;
 89.1685 +	}
 89.1686 +
 89.1687 +	int type = 0;
 89.1688 +	if (fread(&type, 1, sizeof(type), f) != sizeof(type))
 89.1689 +	{
 89.1690 +		fclose(f);
 89.1691 +		return false;
 89.1692 +	}
 89.1693 +
 89.1694 +	if (type != 0)
 89.1695 +	{
 89.1696 +		systemMessage(MSG_UNSUPPORTED_CHEAT_LIST_TYPE,
 89.1697 +		              N_("Unsupported cheat list type %d"), type);
 89.1698 +		fclose(f);
 89.1699 +		return false;
 89.1700 +	}
 89.1701 +
 89.1702 +	if (fread(&count, 1, sizeof(count), f) != sizeof(count))
 89.1703 +	{
 89.1704 +		fclose(f);
 89.1705 +		return false;
 89.1706 +	}
 89.1707 +
 89.1708 +	if (fread(cheatsList, 1, sizeof(cheatsList), f) != sizeof(cheatsList))
 89.1709 +	{
 89.1710 +		fclose(f);
 89.1711 +		return false;
 89.1712 +	}
 89.1713 +
 89.1714 +	bool firstCodeBreaker = true;
 89.1715 +
 89.1716 +	for (int i = 0; i < count; i++)
 89.1717 +	{
 89.1718 +		cheatsList[i].status = 0; // remove old status as it is not used
 89.1719 +		if (!cheatsList[i].codestring[0])
 89.1720 +		{
 89.1721 +			switch (cheatsList[i].size)
 89.1722 +			{
 89.1723 +			case 0:
 89.1724 +				sprintf(cheatsList[i].codestring, "%08x:%02x", cheatsList[i].address,
 89.1725 +				        cheatsList[i].value);
 89.1726 +				break;
 89.1727 +			case 1:
 89.1728 +				sprintf(cheatsList[i].codestring, "%08x:%04x", cheatsList[i].address,
 89.1729 +				        cheatsList[i].value);
 89.1730 +				break;
 89.1731 +			case 2:
 89.1732 +				sprintf(cheatsList[i].codestring, "%08x:%08x", cheatsList[i].address,
 89.1733 +				        cheatsList[i].value);
 89.1734 +				break;
 89.1735 +			}
 89.1736 +		}
 89.1737 +
 89.1738 +		if (cheatsList[i].code == 512 && firstCodeBreaker)
 89.1739 +		{
 89.1740 +			firstCodeBreaker = false;
 89.1741 +			char buffer[10];
 89.1742 +			strncpy(buffer, cheatsList[i].codestring, 8);
 89.1743 +			buffer[8] = 0;
 89.1744 +			u32 address;
 89.1745 +			sscanf(buffer, "%x", &address);
 89.1746 +			if ((address >> 28) == 9)
 89.1747 +			{
 89.1748 +				strncpy(buffer, &cheatsList[i].codestring[9], 4);
 89.1749 +				buffer[4] = 0;
 89.1750 +				u32 value;
 89.1751 +				sscanf(buffer, "%x", &value);
 89.1752 +
 89.1753 +				u32 seed[8];
 89.1754 +				cheatsCBAParseSeedCode(address, value, seed);
 89.1755 +				cheatsCBAChangeEncryption(seed);
 89.1756 +			}
 89.1757 +		}
 89.1758 +	}
 89.1759 +	cheatsNumber = count;
 89.1760 +	fclose(f);
 89.1761 +	return true;
 89.1762 +}
 89.1763 +
 89.1764 +extern int *extCpuLoopTicks;
 89.1765 +extern int *extClockTicks;
 89.1766 +extern int *extTicks;
 89.1767 +extern int  cpuSavedTicks;
 89.1768 +
 89.1769 +extern void debuggerBreakOnWrite(u32 *, u32, u32, int);
 89.1770 +
 89.1771 +#define CPU_BREAK_LOOP2 \
 89.1772 +    cpuSavedTicks    = cpuSavedTicks - *extCpuLoopTicks; \
 89.1773 +    *extCpuLoopTicks = *extClockTicks; \
 89.1774 +    *extTicks        = *extClockTicks;
 89.1775 +
 89.1776 +void cheatsWriteMemory(u32 *address, u32 value, u32 mask)
 89.1777 +{
 89.1778 +#ifdef BKPT_SUPPORT
 89.1779 +#ifdef SDL
 89.1780 +	if (cheatsNumber == 0)
 89.1781 +	{
 89.1782 +		debuggerBreakOnWrite(address, *address, value, 2);
 89.1783 +		CPU_BREAK_LOOP2;
 89.1784 +		*address = value;
 89.1785 +		return;
 89.1786 +	}
 89.1787 +#endif
 89.1788 +#endif
 89.1789 +}
 89.1790 +
 89.1791 +void cheatsWriteHalfWord(u16 *address, u16 value, u16 mask)
 89.1792 +{
 89.1793 +#ifdef BKPT_SUPPORT
 89.1794 +#ifdef SDL
 89.1795 +	if (cheatsNumber == 0)
 89.1796 +	{
 89.1797 +		debuggerBreakOnWrite((u32 *)address, *address, value, 1);
 89.1798 +		CPU_BREAK_LOOP2;
 89.1799 +		*address = value;
 89.1800 +		return;
 89.1801 +	}
 89.1802 +#endif
 89.1803 +#endif
 89.1804 +}
 89.1805 +
 89.1806 +#if defined BKPT_SUPPORT && defined SDL
 89.1807 +void cheatsWriteByte(u8 *address, u8 value)
 89.1808 +#else
 89.1809 +void cheatsWriteByte(u8 *, u8)
 89.1810 +#endif
 89.1811 +{
 89.1812 +#ifdef BKPT_SUPPORT
 89.1813 +#ifdef SDL
 89.1814 +	if (cheatsNumber == 0)
 89.1815 +	{
 89.1816 +		debuggerBreakOnWrite((u32 *)address, *address, value, 0);
 89.1817 +		CPU_BREAK_LOOP2;
 89.1818 +		*address = value;
 89.1819 +		return;
 89.1820 +	}
 89.1821 +#endif
 89.1822 +#endif
 89.1823 +}
 89.1824 +
 89.1825 +#undef CPU_BREAK_LOOP2
    90.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    90.2 +++ b/src/gba/GBACheats.h	Sat Mar 03 10:31:27 2012 -0600
    90.3 @@ -0,0 +1,44 @@
    90.4 +#ifndef VBA_GBA_CHEATS_H
    90.5 +#define VBA_GBA_CHEATS_H
    90.6 +
    90.7 +#if _MSC_VER > 1000
    90.8 +#pragma once
    90.9 +#endif // _MSC_VER > 1000
   90.10 +
   90.11 +#include "zlib.h"
   90.12 +#include "../Port.h"
   90.13 +
   90.14 +struct CheatsData
   90.15 +{
   90.16 +	int  code;
   90.17 +	int  size;
   90.18 +	int  status;
   90.19 +	bool enabled;
   90.20 +	u32  address;
   90.21 +	u32  value;
   90.22 +	u32  oldValue;
   90.23 +	char codestring[20];
   90.24 +	char desc[32];
   90.25 +};
   90.26 +
   90.27 +extern void cheatsAdd(const char *, const char *, u32, u32, int, int);
   90.28 +extern void cheatsAddCheatCode(const char *code, const char *desc);
   90.29 +extern void cheatsAddGSACode(const char *code, const char *desc, bool v3);
   90.30 +extern void cheatsAddCBACode(const char *code, const char *desc);
   90.31 +extern bool cheatsImportGSACodeFile(const char *name, int game, bool v3);
   90.32 +extern void cheatsDelete(int number, bool restore);
   90.33 +extern void cheatsDeleteAll(bool restore);
   90.34 +extern void cheatsEnable(int number);
   90.35 +extern void cheatsDisable(int number);
   90.36 +extern void cheatsSaveGame(gzFile file);
   90.37 +extern void cheatsReadGame(gzFile file);
   90.38 +extern void cheatsSaveCheatList(const char *file);
   90.39 +extern bool cheatsLoadCheatList(const char *file);
   90.40 +extern void       cheatsWriteMemory(u32 *, u32, u32);
   90.41 +extern void       cheatsWriteHalfWord(u16 *, u16, u16);
   90.42 +extern void       cheatsWriteByte(u8 *, u8);
   90.43 +extern int        cheatsCheckKeys(u32, u32);
   90.44 +extern int        cheatsNumber;
   90.45 +extern CheatsData cheatsList[100];
   90.46 +
   90.47 +#endif // GBA_CHEATS_H
    91.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    91.2 +++ b/src/gba/GBAGfx.cpp	Sat Mar 03 10:31:27 2012 -0600
    91.3 @@ -0,0 +1,35 @@
    91.4 +#include "../Port.h"
    91.5 +#include "GBAGfx.h"
    91.6 +
    91.7 +int coeff[32] = {
    91.8 +	0,   1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
    91.9 +	16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
   91.10 +};
   91.11 +
   91.12 +// some of the rendering code in gfx.h (such as mode 0 line 1298)
   91.13 +// renders outside the given buffer (past 239) which corrupts other memory,
   91.14 +// so rather than find all places in that code that need to be fixed,
   91.15 +// just give it enough extra scratch space to use
   91.16 +
   91.17 +u32  line0[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   91.18 +u32  line1[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   91.19 +u32  line2[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   91.20 +u32  line3[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   91.21 +u32  lineOBJ[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   91.22 +u32  lineOBJWin[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   91.23 +u32  lineMix[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   91.24 +bool gfxInWin0[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   91.25 +bool gfxInWin1[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   91.26 +
   91.27 +int gfxBG2Changed = 0;
   91.28 +int gfxBG3Changed = 0;
   91.29 +
   91.30 +int gfxBG2X       = 0;
   91.31 +int gfxBG2Y       = 0;
   91.32 +int gfxBG2LastX   = 0;
   91.33 +int gfxBG2LastY   = 0;
   91.34 +int gfxBG3X       = 0;
   91.35 +int gfxBG3Y       = 0;
   91.36 +int gfxBG3LastX   = 0;
   91.37 +int gfxBG3LastY   = 0;
   91.38 +int gfxLastVCOUNT = 0;
    92.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    92.2 +++ b/src/gba/GBAGfx.h	Sat Mar 03 10:31:27 2012 -0600
    92.3 @@ -0,0 +1,1791 @@
    92.4 +#ifndef VBA_GBA_GFX_H
    92.5 +#define VBA_GBA_GFX_H
    92.6 +
    92.7 +#if _MSC_VER > 1000
    92.8 +#pragma once
    92.9 +#endif // _MSC_VER > 1000
   92.10 +
   92.11 +#include "../Port.h"
   92.12 +#include "GBA.h"
   92.13 +#include "GBAGlobals.h"
   92.14 +
   92.15 +//#define SPRITE_DEBUG
   92.16 +
   92.17 +void gfxDrawTextScreen(u16, u16, u16, u32 *);
   92.18 +void gfxDrawRotScreen(u16,
   92.19 +                      u16, u16,
   92.20 +                      u16, u16,
   92.21 +                      u16, u16,
   92.22 +                      u16, u16,
   92.23 +                      int&, int&,
   92.24 +                      int,
   92.25 +                      u32 *);
   92.26 +void gfxDrawRotScreen16Bit(u16,
   92.27 +                           u16, u16,
   92.28 +                           u16, u16,
   92.29 +                           u16, u16,
   92.30 +                           u16, u16,
   92.31 +                           int&, int&,
   92.32 +                           int,
   92.33 +                           u32 *);
   92.34 +void gfxDrawRotScreen256(u16,
   92.35 +                         u16, u16,
   92.36 +                         u16, u16,
   92.37 +                         u16, u16,
   92.38 +                         u16, u16,
   92.39 +                         int&, int&,
   92.40 +                         int,
   92.41 +                         u32 *);
   92.42 +void gfxDrawRotScreen16Bit160(u16,
   92.43 +                              u16, u16,
   92.44 +                              u16, u16,
   92.45 +                              u16, u16,
   92.46 +                              u16, u16,
   92.47 +                              int&, int&,
   92.48 +                              int,
   92.49 +                              u32 *);
   92.50 +void gfxDrawSprites(u32 *);
   92.51 +void gfxIncreaseBrightness(u32 *line, int coeff);
   92.52 +void gfxDecreaseBrightness(u32 *line, int coeff);
   92.53 +void gfxAlphaBlend(u32 *ta, u32 *tb, int ca, int cb);
   92.54 +
   92.55 +void mode0RenderLine();
   92.56 +void mode0RenderLineNoWindow();
   92.57 +void mode0RenderLineAll();
   92.58 +
   92.59 +void mode1RenderLine();
   92.60 +void mode1RenderLineNoWindow();
   92.61 +void mode1RenderLineAll();
   92.62 +
   92.63 +void mode2RenderLine();
   92.64 +void mode2RenderLineNoWindow();
   92.65 +void mode2RenderLineAll();
   92.66 +
   92.67 +void mode3RenderLine();
   92.68 +void mode3RenderLineNoWindow();
   92.69 +void mode3RenderLineAll();
   92.70 +
   92.71 +void mode4RenderLine();
   92.72 +void mode4RenderLineNoWindow();
   92.73 +void mode4RenderLineAll();
   92.74 +
   92.75 +void mode5RenderLine();
   92.76 +void mode5RenderLineNoWindow();
   92.77 +void mode5RenderLineAll();
   92.78 +
   92.79 +extern int  coeff[32];
   92.80 +
   92.81 +#define LINE_BUFFER_OVERFLOW_LEEWAY (512-240)
   92.82 +
   92.83 +extern u32  line0[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   92.84 +extern u32  line1[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   92.85 +extern u32  line2[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   92.86 +extern u32  line3[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   92.87 +extern u32  lineOBJ[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   92.88 +extern u32  lineOBJWin[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   92.89 +extern u32  lineMix[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   92.90 +extern bool gfxInWin0[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   92.91 +extern bool gfxInWin1[240+LINE_BUFFER_OVERFLOW_LEEWAY];
   92.92 +
   92.93 +extern int gfxBG2Changed;
   92.94 +extern int gfxBG3Changed;
   92.95 +
   92.96 +extern int gfxBG2X;
   92.97 +extern int gfxBG2Y;
   92.98 +extern int gfxBG2LastX;
   92.99 +extern int gfxBG2LastY;
  92.100 +extern int gfxBG3X;
  92.101 +extern int gfxBG3Y;
  92.102 +extern int gfxBG3LastX;
  92.103 +extern int gfxBG3LastY;
  92.104 +extern int gfxLastVCOUNT;
  92.105 +
  92.106 +inline void gfxClearArray(u32 *array)
  92.107 +{
  92.108 +	for (int i = 0; i < 240; i++)
  92.109 +	{
  92.110 +		*array++ = 0x80000000;
  92.111 +	}
  92.112 +}
  92.113 +
  92.114 +inline void gfxDrawTextScreen(u16 control, u16 hofs, u16 vofs,
  92.115 +                              u32 *line)
  92.116 +{
  92.117 +	u16 *palette    = (u16 *)paletteRAM;
  92.118 +	u8 * charBase   = &vram[((control >> 2) & 0x03) * 0x4000];
  92.119 +	u16 *screenBase = (u16 *)&vram[((control >> 8) & 0x1f) * 0x800];
  92.120 +	u32  prio       = ((control & 3)<<25) + 0x1000000;
  92.121 +	int  sizeX      = 256;
  92.122 +	int  sizeY      = 256;
  92.123 +	switch ((control >> 14) & 3)
  92.124 +	{
  92.125 +	case 0:
  92.126 +		break;
  92.127 +	case 1:
  92.128 +		sizeX = 512;
  92.129 +		break;
  92.130 +	case 2:
  92.131 +		sizeY = 512;
  92.132 +		break;
  92.133 +	case 3:
  92.134 +		sizeX = 512;
  92.135 +		sizeY = 512;
  92.136 +		break;
  92.137 +	}
  92.138 +
  92.139 +	int maskX = sizeX-1;
  92.140 +	int maskY = sizeY-1;
  92.141 +
  92.142 +	bool mosaicOn = (control & 0x40) ? true : false;
  92.143 +
  92.144 +	int xxx     = hofs & maskX;
  92.145 +	int yyy     = (vofs + VCOUNT) & maskY;
  92.146 +	int mosaicX = (MOSAIC & 0x000F)+1;
  92.147 +	int mosaicY = ((MOSAIC & 0x00F0)>>4)+1;
  92.148 +
  92.149 +	if (mosaicOn)
  92.150 +	{
  92.151 +		if ((VCOUNT % mosaicY) != 0)
  92.152 +		{
  92.153 +			mosaicY = (VCOUNT / mosaicY) * mosaicY;
  92.154 +			yyy     = (vofs + mosaicY) & maskY;
  92.155 +		}
  92.156 +	}
  92.157 +
  92.158 +	if (yyy > 255 && sizeY > 256)
  92.159 +	{
  92.160 +		yyy        &= 255;
  92.161 +		screenBase += 0x400;
  92.162 +		if (sizeX > 256)
  92.163 +			screenBase += 0x400;
  92.164 +	}
  92.165 +
  92.166 +	int yshift = ((yyy>>3)<<5);
  92.167 +	if ((control) & 0x80)
  92.168 +	{
  92.169 +		u16 *screenSource = screenBase + 0x400 * (xxx>>8) + ((xxx & 255)>>3) + yshift;
  92.170 +		for (int x = 0; x < 240; x++)
  92.171 +		{
  92.172 +			u16 data = READ16LE(screenSource);
  92.173 +
  92.174 +			int tile  = data & 0x3FF;
  92.175 +			int tileX = (xxx & 7);
  92.176 +			int tileY = yyy & 7;
  92.177 +
  92.178 +			if (data & 0x0400)
  92.179 +				tileX = 7 - tileX;
  92.180 +			if (data & 0x0800)
  92.181 +				tileY = 7 - tileY;
  92.182 +
  92.183 +			u8 color = charBase[tile * 64 + tileY * 8 + tileX];
  92.184 +
  92.185 +			line[x] = color ? (READ16LE(&palette[color]) | prio) : 0x80000000;
  92.186 +
  92.187 +			if (data & 0x0400)
  92.188 +			{
  92.189 +				if (tileX == 0)
  92.190 +					screenSource++;
  92.191 +			}
  92.192 +			else if (tileX == 7)
  92.193 +				screenSource++;
  92.194 +			xxx++;
  92.195 +			if (xxx == 256)
  92.196 +			{
  92.197 +				if (sizeX > 256)
  92.198 +					screenSource = screenBase + 0x400 + yshift;
  92.199 +				else
  92.200 +				{
  92.201 +					screenSource = screenBase + yshift;
  92.202 +					xxx = 0;
  92.203 +				}
  92.204 +			}
  92.205 +			else if (xxx >= sizeX)
  92.206 +			{
  92.207 +				xxx = 0;
  92.208 +				screenSource = screenBase + yshift;
  92.209 +			}
  92.210 +		}
  92.211 +	}
  92.212 +	else
  92.213 +	{
  92.214 +		u16 *screenSource = screenBase + 0x400*(xxx>>8)+((xxx&255)>>3) +
  92.215 +		                    yshift;
  92.216 +		for (int x = 0; x < 240; x++)
  92.217 +		{
  92.218 +			u16 data = READ16LE(screenSource);
  92.219 +
  92.220 +			int tile  = data & 0x3FF;
  92.221 +			int tileX = (xxx & 7);
  92.222 +			int tileY = yyy & 7;
  92.223 +
  92.224 +			if (data & 0x0400)
  92.225 +				tileX = 7 - tileX;
  92.226 +			if (data & 0x0800)
  92.227 +				tileY = 7 - tileY;
  92.228 +
  92.229 +			u8 color = charBase[(tile<<5) + (tileY<<2) + (tileX>>1)];
  92.230 +
  92.231 +			if (tileX & 1)
  92.232 +			{
  92.233 +				color = (color >> 4);
  92.234 +			}
  92.235 +			else
  92.236 +			{
  92.237 +				color &= 0x0F;
  92.238 +			}
  92.239 +
  92.240 +			int pal = (READ16LE(screenSource)>>8) & 0xF0;
  92.241 +			line[x] = color ? (READ16LE(&palette[pal + color])|prio) : 0x80000000;
  92.242 +
  92.243 +			if (data & 0x0400)
  92.244 +			{
  92.245 +				if (tileX == 0)
  92.246 +					screenSource++;
  92.247 +			}
  92.248 +			else if (tileX == 7)
  92.249 +				screenSource++;
  92.250 +			xxx++;
  92.251 +			if (xxx == 256)
  92.252 +			{
  92.253 +				if (sizeX > 256)
  92.254 +					screenSource = screenBase + 0x400 + yshift;
  92.255 +				else
  92.256 +				{
  92.257 +					screenSource = screenBase + yshift;
  92.258 +					xxx = 0;
  92.259 +				}
  92.260 +			}
  92.261 +			else if (xxx >= sizeX)
  92.262 +			{
  92.263 +				xxx = 0;
  92.264 +				screenSource = screenBase + yshift;
  92.265 +			}
  92.266 +		}
  92.267 +	}
  92.268 +	if (mosaicOn)
  92.269 +	{
  92.270 +		if (mosaicX > 1)
  92.271 +		{
  92.272 +			int m = 1;
  92.273 +			for (int i = 0; i < 239; i++)
  92.274 +			{
  92.275 +				line[i+1] = line[i];
  92.276 +				m++;
  92.277 +				if (m == mosaicX)
  92.278 +				{
  92.279 +					m = 1;
  92.280 +					i++;
  92.281 +				}
  92.282 +			}
  92.283 +		}
  92.284 +	}
  92.285 +}
  92.286 +
  92.287 +inline void gfxDrawRotScreen(u16 control,
  92.288 +                             u16 x_l, u16 x_h,
  92.289 +                             u16 y_l, u16 y_h,
  92.290 +                             u16 pa,  u16 pb,
  92.291 +                             u16 pc,  u16 pd,
  92.292 +                             int& currentX, int& currentY,
  92.293 +                             int changed,
  92.294 +                             u32 *line)
  92.295 +{
  92.296 +	u16 *palette    = (u16 *)paletteRAM;
  92.297 +	u8 * charBase   = &vram[((control >> 2) & 0x03) * 0x4000];
  92.298 +	u8 * screenBase = (u8 *)&vram[((control >> 8) & 0x1f) * 0x800];
  92.299 +	int  prio       = ((control & 3) << 25) + 0x1000000;
  92.300 +
  92.301 +	int sizeX = 128;
  92.302 +	int sizeY = 128;
  92.303 +	switch ((control >> 14) & 3)
  92.304 +	{
  92.305 +	case 0:
  92.306 +		break;
  92.307 +	case 1:
  92.308 +		sizeX = sizeY = 256;
  92.309 +		break;
  92.310 +	case 2:
  92.311 +		sizeX = sizeY = 512;
  92.312 +		break;
  92.313 +	case 3:
  92.314 +		sizeX = sizeY = 1024;
  92.315 +		break;
  92.316 +	}
  92.317 +
  92.318 +	int dx = pa & 0x7FFF;
  92.319 +	if (pa & 0x8000)
  92.320 +		dx |= 0xFFFF8000;
  92.321 +	int dmx = pb & 0x7FFF;
  92.322 +	if (pb & 0x8000)
  92.323 +		dmx |= 0xFFFF8000;
  92.324 +	int dy = pc & 0x7FFF;
  92.325 +	if (pc & 0x8000)
  92.326 +		dy |= 0xFFFF8000;
  92.327 +	int dmy = pd & 0x7FFFF;
  92.328 +	if (pd & 0x8000)
  92.329 +		dmy |= 0xFFFF8000;
  92.330 +
  92.331 +	if (VCOUNT == 0)
  92.332 +		changed = 3;
  92.333 +
  92.334 +	if (changed & 1)
  92.335 +	{
  92.336 +		currentX = (x_l) | ((x_h & 0x07FF)<<16);
  92.337 +		if (x_h & 0x0800)
  92.338 +			currentX |= 0xF8000000;
  92.339 +	}
  92.340 +	else
  92.341 +	{
  92.342 +		currentX += dmx;
  92.343 +	}
  92.344 +
  92.345 +	if (changed & 2)
  92.346 +	{
  92.347 +		currentY = (y_l) | ((y_h & 0x07FF)<<16);
  92.348 +		if (y_h & 0x0800)
  92.349 +			currentY |= 0xF8000000;
  92.350 +	}
  92.351 +	else
  92.352 +	{
  92.353 +		currentY += dmy;
  92.354 +	}
  92.355 +
  92.356 +	int realX = currentX;
  92.357 +	int realY = currentY;
  92.358 +
  92.359 +	if (control & 0x40)
  92.360 +	{
  92.361 +		int mosaicY = ((MOSAIC & 0xF0)>>4) + 1;
  92.362 +		int y       = (VCOUNT % mosaicY);
  92.363 +		realX -= y*dmx;
  92.364 +		realY -= y*dmy;
  92.365 +	}
  92.366 +
  92.367 +	int xxx = (realX >> 8);
  92.368 +	int yyy = (realY >> 8);
  92.369 +
  92.370 +	if (control & 0x2000)
  92.371 +	{
  92.372 +		xxx %= sizeX;
  92.373 +		yyy %= sizeY;
  92.374 +		if (xxx < 0)
  92.375 +			xxx += sizeX;
  92.376 +		if (yyy < 0)
  92.377 +			yyy += sizeY;
  92.378 +	}
  92.379 +
  92.380 +	if (control & 0x80)
  92.381 +	{
  92.382 +		for (int x = 0; x < 240; x++)
  92.383 +		{
  92.384 +			if (xxx < 0 ||
  92.385 +			    yyy < 0 ||
  92.386 +			    xxx >= sizeX ||
  92.387 +			    yyy >= sizeY)
  92.388 +			{
  92.389 +				line[x] = 0x80000000;
  92.390 +			}
  92.391 +			else
  92.392 +			{
  92.393 +				int tile = screenBase[(xxx>>3) + (yyy>>3)*(sizeX>>3)];
  92.394 +
  92.395 +				int tileX = (xxx & 7);
  92.396 +				int tileY = yyy & 7;
  92.397 +
  92.398 +				u8 color = charBase[(tile<<6) + (tileY<<3) + tileX];
  92.399 +
  92.400 +				line[x] = color ? (READ16LE(&palette[color])|prio) : 0x80000000;
  92.401 +			}
  92.402 +			realX += dx;
  92.403 +			realY += dy;
  92.404 +
  92.405 +			xxx = (realX >> 8);
  92.406 +			yyy = (realY >> 8);
  92.407 +
  92.408 +			if (control & 0x2000)
  92.409 +			{
  92.410 +				xxx %= sizeX;
  92.411 +				yyy %= sizeY;
  92.412 +				if (xxx < 0)
  92.413 +					xxx += sizeX;
  92.414 +				if (yyy < 0)
  92.415 +					yyy += sizeY;
  92.416 +			}
  92.417 +		}
  92.418 +	}
  92.419 +	else
  92.420 +	{
  92.421 +		for (int x = 0; x < 240; x++)
  92.422 +		{
  92.423 +			if (xxx < 0 ||
  92.424 +			    yyy < 0 ||
  92.425 +			    xxx >= sizeX ||
  92.426 +			    yyy >= sizeY)
  92.427 +			{
  92.428 +				line[x] = 0x80000000;
  92.429 +			}
  92.430 +			else
  92.431 +			{
  92.432 +				int tile = screenBase[(xxx>>3) + (yyy>>3)*(sizeX>>3)];
  92.433 +
  92.434 +				int tileX = (xxx & 7);
  92.435 +				int tileY = yyy & 7;
  92.436 +
  92.437 +				u8 color = charBase[(tile<<6) + (tileY<<3) + tileX];
  92.438 +
  92.439 +				line[x] = color ? (READ16LE(&palette[color])|prio) : 0x80000000;
  92.440 +			}
  92.441 +			realX += dx;
  92.442 +			realY += dy;
  92.443 +
  92.444 +			xxx = (realX >> 8);
  92.445 +			yyy = (realY >> 8);
  92.446 +
  92.447 +			if (control & 0x2000)
  92.448 +			{
  92.449 +				xxx %= sizeX;
  92.450 +				yyy %= sizeY;
  92.451 +				if (xxx < 0)
  92.452 +					xxx += sizeX;
  92.453 +				if (yyy < 0)
  92.454 +					yyy += sizeY;
  92.455 +			}
  92.456 +		}
  92.457 +	}
  92.458 +
  92.459 +	if (control & 0x40)
  92.460 +	{
  92.461 +		int mosaicX = (MOSAIC & 0xF) + 1;
  92.462 +		if (mosaicX > 1)
  92.463 +		{
  92.464 +			int m = 1;
  92.465 +			for (int i = 0; i < 239; i++)
  92.466 +			{
  92.467 +				line[i+1] = line[i];
  92.468 +				m++;
  92.469 +				if (m == mosaicX)
  92.470 +				{
  92.471 +					m = 1;
  92.472 +					i++;
  92.473 +				}
  92.474 +			}
  92.475 +		}
  92.476 +	}
  92.477 +}
  92.478 +
  92.479 +inline void gfxDrawRotScreen16Bit(u16 control,
  92.480 +                                  u16 x_l, u16 x_h,
  92.481 +                                  u16 y_l, u16 y_h,
  92.482 +                                  u16 pa,  u16 pb,
  92.483 +                                  u16 pc,  u16 pd,
  92.484 +                                  int& currentX, int& currentY,
  92.485 +                                  int changed,
  92.486 +                                  u32 *line)
  92.487 +{
  92.488 +	u16 *screenBase = (u16 *)&vram[0];
  92.489 +	int  prio       = ((control & 3) << 25) + 0x1000000;
  92.490 +	int  sizeX      = 240;
  92.491 +	int  sizeY      = 160;
  92.492 +
  92.493 +	int startX = (x_l) | ((x_h & 0x07FF)<<16);
  92.494 +	if (x_h & 0x0800)
  92.495 +		startX |= 0xF8000000;
  92.496 +	int startY = (y_l) | ((y_h & 0x07FF)<<16);
  92.497 +	if (y_h & 0x0800)
  92.498 +		startY |= 0xF8000000;
  92.499 +
  92.500 +	int dx = pa & 0x7FFF;
  92.501 +	if (pa & 0x8000)
  92.502 +		dx |= 0xFFFF8000;
  92.503 +	int dmx = pb & 0x7FFF;
  92.504 +	if (pb & 0x8000)
  92.505 +		dmx |= 0xFFFF8000;
  92.506 +	int dy = pc & 0x7FFF;
  92.507 +	if (pc & 0x8000)
  92.508 +		dy |= 0xFFFF8000;
  92.509 +	int dmy = pd & 0x7FFFF;
  92.510 +	if (pd & 0x8000)
  92.511 +		dmy |= 0xFFFF8000;
  92.512 +
  92.513 +	if (VCOUNT == 0)
  92.514 +		changed = 3;
  92.515 +
  92.516 +	if (changed & 1)
  92.517 +	{
  92.518 +		currentX = (x_l) | ((x_h & 0x07FF)<<16);
  92.519 +		if (x_h & 0x0800)
  92.520 +			currentX |= 0xF8000000;
  92.521 +	}
  92.522 +	else
  92.523 +		currentX += dmx;
  92.524 +
  92.525 +	if (changed & 2)
  92.526 +	{
  92.527 +		currentY = (y_l) | ((y_h & 0x07FF)<<16);
  92.528 +		if (y_h & 0x0800)
  92.529 +			currentY |= 0xF8000000;
  92.530 +	}
  92.531 +	else
  92.532 +	{
  92.533 +		currentY += dmy;
  92.534 +	}
  92.535 +
  92.536 +	int realX = currentX;
  92.537 +	int realY = currentY;
  92.538 +
  92.539 +	if (control & 0x40)
  92.540 +	{
  92.541 +		int mosaicY = ((MOSAIC & 0xF0)>>4) + 1;
  92.542 +		int y       = (VCOUNT % mosaicY);
  92.543 +		realX -= y*dmx;
  92.544 +		realY -= y*dmy;
  92.545 +	}
  92.546 +
  92.547 +	int xxx = (realX >> 8);
  92.548 +	int yyy = (realY >> 8);
  92.549 +
  92.550 +	for (int x = 0; x < 240; x++)
  92.551 +	{
  92.552 +		if (xxx < 0 ||
  92.553 +		    yyy < 0 ||
  92.554 +		    xxx >= sizeX ||
  92.555 +		    yyy >= sizeY)
  92.556 +		{
  92.557 +			line[x] = 0x80000000;
  92.558 +		}
  92.559 +		else
  92.560 +		{
  92.561 +			line[x] = (READ16LE(&screenBase[yyy * sizeX + xxx]) | prio);
  92.562 +		}
  92.563 +		realX += dx;
  92.564 +		realY += dy;
  92.565 +
  92.566 +		xxx = (realX >> 8);
  92.567 +		yyy = (realY >> 8);
  92.568 +	}
  92.569 +
  92.570 +	if (control & 0x40)
  92.571 +	{
  92.572 +		int mosaicX = (MOSAIC & 0xF) + 1;
  92.573 +		if (mosaicX > 1)
  92.574 +		{
  92.575 +			int m = 1;
  92.576 +			for (int i = 0; i < 239; i++)
  92.577 +			{
  92.578 +				line[i+1] = line[i];
  92.579 +				m++;
  92.580 +				if (m == mosaicX)
  92.581 +				{
  92.582 +					m = 1;
  92.583 +					i++;
  92.584 +				}
  92.585 +			}
  92.586 +		}
  92.587 +	}
  92.588 +}
  92.589 +
  92.590 +inline void gfxDrawRotScreen256(u16 control,
  92.591 +                                u16 x_l, u16 x_h,
  92.592 +                                u16 y_l, u16 y_h,
  92.593 +                                u16 pa,  u16 pb,
  92.594 +                                u16 pc,  u16 pd,
  92.595 +                                int &currentX, int& currentY,
  92.596 +                                int changed,
  92.597 +                                u32 *line)
  92.598 +{
  92.599 +	u16 *palette    = (u16 *)paletteRAM;
  92.600 +	u8 * screenBase = (DISPCNT & 0x0010) ? &vram[0xA000] : &vram[0x0000];
  92.601 +	int  prio       = ((control & 3) << 25) + 0x1000000;
  92.602 +	int  sizeX      = 240;
  92.603 +	int  sizeY      = 160;
  92.604 +
  92.605 +	int startX = (x_l) | ((x_h & 0x07FF)<<16);
  92.606 +	if (x_h & 0x0800)
  92.607 +		startX |= 0xF8000000;
  92.608 +	int startY = (y_l) | ((y_h & 0x07FF)<<16);
  92.609 +	if (y_h & 0x0800)
  92.610 +		startY |= 0xF8000000;
  92.611 +
  92.612 +	int dx = pa & 0x7FFF;
  92.613 +	if (pa & 0x8000)
  92.614 +		dx |= 0xFFFF8000;
  92.615 +	int dmx = pb & 0x7FFF;
  92.616 +	if (pb & 0x8000)
  92.617 +		dmx |= 0xFFFF8000;
  92.618 +	int dy = pc & 0x7FFF;
  92.619 +	if (pc & 0x8000)
  92.620 +		dy |= 0xFFFF8000;
  92.621 +	int dmy = pd & 0x7FFFF;
  92.622 +	if (pd & 0x8000)
  92.623 +		dmy |= 0xFFFF8000;
  92.624 +
  92.625 +	if (VCOUNT == 0)
  92.626 +		changed = 3;
  92.627 +
  92.628 +	if (changed & 1)
  92.629 +	{
  92.630 +		currentX = (x_l) | ((x_h & 0x07FF)<<16);
  92.631 +		if (x_h & 0x0800)
  92.632 +			currentX |= 0xF8000000;
  92.633 +	}
  92.634 +	else
  92.635 +	{
  92.636 +		currentX += dmx;
  92.637 +	}
  92.638 +
  92.639 +	if (changed & 2)
  92.640 +	{
  92.641 +		currentY = (y_l) | ((y_h & 0x07FF)<<16);
  92.642 +		if (y_h & 0x0800)
  92.643 +			currentY |= 0xF8000000;
  92.644 +	}
  92.645 +	else
  92.646 +	{
  92.647 +		currentY += dmy;
  92.648 +	}
  92.649 +
  92.650 +	int realX = currentX;
  92.651 +	int realY = currentY;
  92.652 +
  92.653 +	if (control & 0x40)
  92.654 +	{
  92.655 +		int mosaicY = ((MOSAIC & 0xF0)>>4) + 1;
  92.656 +		int y       = (VCOUNT / mosaicY) * mosaicY;
  92.657 +		realX = startX + y*dmx;
  92.658 +		realY = startY + y*dmy;
  92.659 +	}
  92.660 +
  92.661 +	int xxx = (realX >> 8);
  92.662 +	int yyy = (realY >> 8);
  92.663 +
  92.664 +	for (int x = 0; x < 240; x++)
  92.665 +	{
  92.666 +		if (xxx < 0 ||
  92.667 +		    yyy < 0 ||
  92.668 +		    xxx >= sizeX ||
  92.669 +		    yyy >= sizeY)
  92.670 +		{
  92.671 +			line[x] = 0x80000000;
  92.672 +		}
  92.673 +		else
  92.674 +		{
  92.675 +			u8 color = screenBase[yyy * 240 + xxx];
  92.676 +
  92.677 +			line[x] = color ? (READ16LE(&palette[color])|prio) : 0x80000000;
  92.678 +		}
  92.679 +		realX += dx;
  92.680 +		realY += dy;
  92.681 +
  92.682 +		xxx = (realX >> 8);
  92.683 +		yyy = (realY >> 8);
  92.684 +	}
  92.685 +
  92.686 +	if (control & 0x40)
  92.687 +	{
  92.688 +		int mosaicX = (MOSAIC & 0xF) + 1;
  92.689 +		if (mosaicX > 1)
  92.690 +		{
  92.691 +			int m = 1;
  92.692 +			for (int i = 0; i < 239; i++)
  92.693 +			{
  92.694 +				line[i+1] = line[i];
  92.695 +				m++;
  92.696 +				if (m == mosaicX)
  92.697 +				{
  92.698 +					m = 1;
  92.699 +					i++;
  92.700 +				}
  92.701 +			}
  92.702 +		}
  92.703 +	}
  92.704 +}
  92.705 +
  92.706 +inline void gfxDrawRotScreen16Bit160(u16 control,
  92.707 +                                     u16 x_l, u16 x_h,
  92.708 +                                     u16 y_l, u16 y_h,
  92.709 +                                     u16 pa,  u16 pb,
  92.710 +                                     u16 pc,  u16 pd,
  92.711 +                                     int& currentX, int& currentY,
  92.712 +                                     int changed,
  92.713 +                                     u32 *line)
  92.714 +{
  92.715 +	u16 *screenBase = (DISPCNT & 0x0010) ? (u16 *)&vram[0xa000] :
  92.716 +	                  (u16 *)&vram[0];
  92.717 +	int prio  = ((control & 3) << 25) + 0x1000000;
  92.718 +	int sizeX = 160;
  92.719 +	int sizeY = 128;
  92.720 +
  92.721 +	int startX = (x_l) | ((x_h & 0x07FF)<<16);
  92.722 +	if (x_h & 0x0800)
  92.723 +		startX |= 0xF8000000;
  92.724 +	int startY = (y_l) | ((y_h & 0x07FF)<<16);
  92.725 +	if (y_h & 0x0800)
  92.726 +		startY |= 0xF8000000;
  92.727 +
  92.728 +	int dx = pa & 0x7FFF;
  92.729 +	if (pa & 0x8000)
  92.730 +		dx |= 0xFFFF8000;
  92.731 +	int dmx = pb & 0x7FFF;
  92.732 +	if (pb & 0x8000)
  92.733 +		dmx |= 0xFFFF8000;
  92.734 +	int dy = pc & 0x7FFF;
  92.735 +	if (pc & 0x8000)
  92.736 +		dy |= 0xFFFF8000;
  92.737 +	int dmy = pd & 0x7FFFF;
  92.738 +	if (pd & 0x8000)
  92.739 +		dmy |= 0xFFFF8000;
  92.740 +
  92.741 +	if (VCOUNT == 0)
  92.742 +		changed = 3;
  92.743 +
  92.744 +	if (changed & 1)
  92.745 +	{
  92.746 +		currentX = (x_l) | ((x_h & 0x07FF)<<16);
  92.747 +		if (x_h & 0x0800)
  92.748 +			currentX |= 0xF8000000;
  92.749 +	}
  92.750 +	else
  92.751 +	{
  92.752 +		currentX += dmx;
  92.753 +	}
  92.754 +
  92.755 +	if (changed & 2)
  92.756 +	{
  92.757 +		currentY = (y_l) | ((y_h & 0x07FF)<<16);
  92.758 +		if (y_h & 0x0800)
  92.759 +			currentY |= 0xF8000000;
  92.760 +	}
  92.761 +	else
  92.762 +	{
  92.763 +		currentY += dmy;
  92.764 +	}
  92.765 +
  92.766 +	int realX = currentX;
  92.767 +	int realY = currentY;
  92.768 +
  92.769 +	if (control & 0x40)
  92.770 +	{
  92.771 +		int mosaicY = ((MOSAIC & 0xF0)>>4) + 1;
  92.772 +		int y       = (VCOUNT / mosaicY) * mosaicY;
  92.773 +		realX = startX + y*dmx;
  92.774 +		realY = startY + y*dmy;
  92.775 +	}
  92.776 +
  92.777 +	int xxx = (realX >> 8);
  92.778 +	int yyy = (realY >> 8);
  92.779 +
  92.780 +	for (int x = 0; x < 240; x++)
  92.781 +	{
  92.782 +		if (xxx < 0 ||
  92.783 +		    yyy < 0 ||
  92.784 +		    xxx >= sizeX ||
  92.785 +		    yyy >= sizeY)
  92.786 +		{
  92.787 +			line[x] = 0x80000000;
  92.788 +		}
  92.789 +		else
  92.790 +		{
  92.791 +			line[x] = (READ16LE(&screenBase[yyy * sizeX + xxx]) | prio);
  92.792 +		}
  92.793 +		realX += dx;
  92.794 +		realY += dy;
  92.795 +
  92.796 +		xxx = (realX >> 8);
  92.797 +		yyy = (realY >> 8);
  92.798 +	}
  92.799 +
  92.800 +	if (control & 0x40)
  92.801 +	{
  92.802 +		int mosaicX = (MOSAIC & 0xF) + 1;
  92.803 +		if (mosaicX > 1)
  92.804 +		{
  92.805 +			int m = 1;
  92.806 +			for (int i = 0; i < 239; i++)
  92.807 +			{
  92.808 +				line[i+1] = line[i];
  92.809 +				m++;
  92.810 +				if (m == mosaicX)
  92.811 +				{
  92.812 +					m = 1;
  92.813 +					i++;
  92.814 +				}
  92.815 +			}
  92.816 +		}
  92.817 +	}
  92.818 +}
  92.819 +
  92.820 +inline void gfxDrawSprites(u32 *lineOBJ)
  92.821 +{
  92.822 +	int m = 0;
  92.823 +	gfxClearArray(lineOBJ);
  92.824 +	if (layerEnable & 0x1000)
  92.825 +	{
  92.826 +		u16 *sprites       = (u16 *)oam;
  92.827 +		u16 *spritePalette = &((u16 *)paletteRAM)[256];
  92.828 +		int  mosaicY       = ((MOSAIC & 0xF000)>>12) + 1;
  92.829 +		int  mosaicX       = ((MOSAIC & 0xF00)>>8) + 1;
  92.830 +		for (int x = 0; x < 128; x++)
  92.831 +		{
  92.832 +			u16 a0 = READ16LE(sprites++);
  92.833 +			u16 a1 = READ16LE(sprites++);
  92.834 +			u16 a2 = READ16LE(sprites++);
  92.835 +			sprites++;
  92.836 +
  92.837 +			// ignore OBJ-WIN
  92.838 +			if ((a0 & 0x0c00) == 0x0800)
  92.839 +				continue;
  92.840 +
  92.841 +			int sizeY = 8;
  92.842 +			int sizeX = 8;
  92.843 +
  92.844 +			switch (((a0 >>12) & 0x0c)|(a1>>14))
  92.845 +			{
  92.846 +			case 0:
  92.847 +				break;
  92.848 +			case 1:
  92.849 +				sizeX = sizeY = 16;
  92.850 +				break;
  92.851 +			case 2:
  92.852 +				sizeX = sizeY = 32;
  92.853 +				break;
  92.854 +			case 3:
  92.855 +				sizeX = sizeY = 64;
  92.856 +				break;
  92.857 +			case 4:
  92.858 +				sizeX = 16;
  92.859 +				break;
  92.860 +			case 5:
  92.861 +				sizeX = 32;
  92.862 +				break;
  92.863 +			case 6:
  92.864 +				sizeX = 32;
  92.865 +				sizeY = 16;
  92.866 +				break;
  92.867 +			case 7:
  92.868 +				sizeX = 64;
  92.869 +				sizeY = 32;
  92.870 +				break;
  92.871 +			case 8:
  92.872 +				sizeY = 16;
  92.873 +				break;
  92.874 +			case 9:
  92.875 +				sizeY = 32;
  92.876 +				break;
  92.877 +			case 10:
  92.878 +				sizeX = 16;
  92.879 +				sizeY = 32;
  92.880 +				break;
  92.881 +			case 11:
  92.882 +				sizeX = 32;
  92.883 +				sizeY = 64;
  92.884 +				break;
  92.885 +			default:
  92.886 +				continue;
  92.887 +			}
  92.888 +
  92.889 +#ifdef SPRITE_DEBUG
  92.890 +			int maskX = sizeX-1;
  92.891 +			int maskY = sizeY-1;
  92.892 +#endif
  92.893 +
  92.894 +			int sy = (a0 & 255);
  92.895 +
  92.896 +			if (sy > 160)
  92.897 +				sy -= 256;
  92.898 +
  92.899 +			if (a0 & 0x0100)
  92.900 +			{
  92.901 +				int fieldX = sizeX;
  92.902 +				int fieldY = sizeY;
  92.903 +				if (a0 & 0x0200)
  92.904 +				{
  92.905 +					fieldX <<= 1;
  92.906 +					fieldY <<= 1;
  92.907 +				}
  92.908 +
  92.909 +				int t = VCOUNT - sy;
  92.910 +				if ((t >= 0) && (t < fieldY))
  92.911 +				{
  92.912 +					int sx = (a1 & 0x1FF);
  92.913 +					if ((sx < 240) || (((sx + fieldX) & 511) < 240))
  92.914 +					{
  92.915 +						// int t2 = t - (fieldY >> 1);
  92.916 +						int  rot = (a1 >> 9) & 0x1F;
  92.917 +						u16 *OAM = (u16 *)oam;
  92.918 +						int  dx  = READ16LE(&OAM[3 + (rot << 4)]);
  92.919 +						if (dx & 0x8000)
  92.920 +							dx |= 0xFFFF8000;
  92.921 +						int dmx = READ16LE(&OAM[7 + (rot << 4)]);
  92.922 +						if (dmx & 0x8000)
  92.923 +							dmx |= 0xFFFF8000;
  92.924 +						int dy = READ16LE(&OAM[11 + (rot << 4)]);
  92.925 +						if (dy & 0x8000)
  92.926 +							dy |= 0xFFFF8000;
  92.927 +						int dmy = READ16LE(&OAM[15 + (rot << 4)]);
  92.928 +						if (dmy & 0x8000)
  92.929 +							dmy |= 0xFFFF8000;
  92.930 +
  92.931 +						if (a0 & 0x1000)
  92.932 +						{
  92.933 +							t -= (t % mosaicY);
  92.934 +						}
  92.935 +
  92.936 +						int realX = ((sizeX) << 7) - (fieldX >> 1)*dx - (fieldY>>1)*dmx
  92.937 +						            + t * dmx;
  92.938 +						int realY = ((sizeY) << 7) - (fieldX >> 1)*dy - (fieldY>>1)*dmy
  92.939 +						            + t * dmy;
  92.940 +
  92.941 +						u32 prio = (((a2 >> 10) & 3) << 25) | ((a0 & 0x0c00)<<6);
  92.942 +
  92.943 +						if (a0 & 0x2000)
  92.944 +						{
  92.945 +							int c = (a2 & 0x3FF);
  92.946 +							if ((DISPCNT & 7) > 2 && (c < 512))
  92.947 +								continue;
  92.948 +							int inc = 32;
  92.949 +							if (DISPCNT & 0x40)
  92.950 +								inc = sizeX >> 2;
  92.951 +							else
  92.952 +								c &= 0x3FE;
  92.953 +							for (int x = 0; x < fieldX; x++)
  92.954 +							{
  92.955 +								int xxx = realX >> 8;
  92.956 +								int yyy = realY >> 8;
  92.957 +
  92.958 +								if (xxx < 0 || xxx >= sizeX ||
  92.959 +								    yyy < 0 || yyy >= sizeY ||
  92.960 +								    sx >= 240)
  92.961 +									;
  92.962 +								else
  92.963 +								{
  92.964 +									u32 color = vram[0x10000 + ((((c + (yyy>>3) * inc)<<5)
  92.965 +									                             + ((yyy & 7)<<3) + ((xxx >> 3)<<6) +
  92.966 +									                             (xxx & 7))&0x7FFF)];
  92.967 +									if ((color == 0) && (((prio >> 25)&3) <
  92.968 +									                     ((lineOBJ[sx]>>25)&3)))
  92.969 +									{
  92.970 +										lineOBJ[sx] = (lineOBJ[sx] & 0xF9FFFFFF) | prio;
  92.971 +										if ((a0 & 0x1000) && m)
  92.972 +											lineOBJ[sx] = (lineOBJ[sx-1] & 0xF9FFFFFF) | prio;
  92.973 +									}
  92.974 +									else if ((color) && (prio < (lineOBJ[sx]&0xFF000000)))
  92.975 +									{
  92.976 +										lineOBJ[sx] = READ16LE(&spritePalette[color]) | prio;
  92.977 +										if ((a0 & 0x1000) && m)
  92.978 +											lineOBJ[sx] = (lineOBJ[sx-1] & 0xF9FFFFFF) | prio;
  92.979 +									}
  92.980 +
  92.981 +									if (a0 & 0x1000)
  92.982 +									{
  92.983 +										m++;
  92.984 +										if (m == mosaicX)
  92.985 +											m = 0;
  92.986 +									}
  92.987 +#ifdef SPRITE_DEBUG
  92.988 +									if (t == 0 || t == maskY || x == 0 || x == maskX)
  92.989 +										lineOBJ[sx] = 0x001F;
  92.990 +#endif
  92.991 +								}
  92.992 +								sx     = (sx+1)&511;;
  92.993 +								realX += dx;
  92.994 +								realY += dy;
  92.995 +							}
  92.996 +						}
  92.997 +						else
  92.998 +						{
  92.999 +							int c = (a2 & 0x3FF);
 92.1000 +							if ((DISPCNT & 7) > 2 && (c < 512))
 92.1001 +								continue;
 92.1002 +
 92.1003 +							int inc = 32;
 92.1004 +							if (DISPCNT & 0x40)
 92.1005 +								inc = sizeX >> 3;
 92.1006 +							int palette = (a2 >> 8) & 0xF0;
 92.1007 +							for (int x = 0; x < fieldX; x++)
 92.1008 +							{
 92.1009 +								int xxx = realX >> 8;
 92.1010 +								int yyy = realY >> 8;
 92.1011 +								if (xxx < 0 || xxx >= sizeX ||
 92.1012 +								    yyy < 0 || yyy >= sizeY ||
 92.1013 +								    sx >= 240)
 92.1014 +									;
 92.1015 +								else
 92.1016 +								{
 92.1017 +									u32 color = vram[0x10000 + ((((c + (yyy>>3) * inc)<<5)
 92.1018 +									                             + ((yyy & 7)<<2) + ((xxx >> 3)<<5) +
 92.1019 +									                             ((xxx & 7)>>1))&0x7FFF)];
 92.1020 +									if (xxx & 1)
 92.1021 +										color >>= 4;
 92.1022 +									else
 92.1023 +										color &= 0x0F;
 92.1024 +
 92.1025 +									if ((color == 0) && (((prio >> 25)&3) <
 92.1026 +									                     ((lineOBJ[sx]>>25)&3)))
 92.1027 +									{
 92.1028 +										lineOBJ[sx] = (lineOBJ[sx] & 0xF9FFFFFF) | prio;
 92.1029 +										if ((a0 & 0x1000) && m)
 92.1030 +											lineOBJ[sx] = (lineOBJ[sx-1] & 0xF9FFFFFF) | prio;
 92.1031 +									}
 92.1032 +									else if ((color) && (prio < (lineOBJ[sx]&0xFF000000)))
 92.1033 +									{
 92.1034 +										lineOBJ[sx] = READ16LE(&spritePalette[palette+color]) | prio;
 92.1035 +										if ((a0 & 0x1000) && m)
 92.1036 +											lineOBJ[sx] = (lineOBJ[sx-1] & 0xF9FFFFFF) | prio;
 92.1037 +									}
 92.1038 +								}
 92.1039 +								if ((a0 & 0x1000) && m)
 92.1040 +								{
 92.1041 +									m++;
 92.1042 +									if (m == mosaicX)
 92.1043 +										m = 0;
 92.1044 +								}
 92.1045 +
 92.1046 +#ifdef SPRITE_DEBUG
 92.1047 +								if (t == 0 || t == maskY || x == 0 || x == maskX)
 92.1048 +									lineOBJ[sx] = 0x001F;
 92.1049 +#endif
 92.1050 +								sx     = (sx+1)&511;;
 92.1051 +								realX += dx;
 92.1052 +								realY += dy;
 92.1053 +							}
 92.1054 +						}
 92.1055 +					}
 92.1056 +				}
 92.1057 +			}
 92.1058 +			else
 92.1059 +			{
 92.1060 +				int t = VCOUNT - sy;
 92.1061 +				if ((t >= 0) && (t < sizeY))
 92.1062 +				{
 92.1063 +					int sx = (a1 & 0x1FF);
 92.1064 +					if (((sx < 240) || (((sx+sizeX)&511) < 240)) && !(a0 & 0x0200))
 92.1065 +					{
 92.1066 +						if (a0 & 0x2000)
 92.1067 +						{
 92.1068 +							if (a1 & 0x2000)
 92.1069 +								t = sizeY - t - 1;
 92.1070 +							int c = (a2 & 0x3FF);
 92.1071 +							if ((DISPCNT & 7) > 2 && (c < 512))
 92.1072 +								continue;
 92.1073 +
 92.1074 +							int inc = 32;
 92.1075 +							if (DISPCNT & 0x40)
 92.1076 +							{
 92.1077 +								inc = sizeX >> 2;
 92.1078 +							}
 92.1079 +							else
 92.1080 +							{
 92.1081 +								c &= 0x3FE;
 92.1082 +							}
 92.1083 +							int xxx = 0;
 92.1084 +							if (a1 & 0x1000)
 92.1085 +								xxx = sizeX-1;
 92.1086 +
 92.1087 +							if (a0 & 0x1000)
 92.1088 +							{
 92.1089 +								t -= (t % mosaicY);
 92.1090 +							}
 92.1091 +
 92.1092 +							int address = 0x10000 + ((((c+ (t>>3) * inc) << 5)
 92.1093 +							                          + ((t & 7) << 3) + ((xxx>>3)<<6) + (xxx & 7)) & 0x7FFF);
 92.1094 +
 92.1095 +							if (a1 & 0x1000)
 92.1096 +								xxx = 7;
 92.1097 +							u32 prio = (((a2 >> 10) & 3) << 25) | ((a0 & 0x0c00)<<6);
 92.1098 +
 92.1099 +							for (int xx = 0; xx < sizeX; xx++)
 92.1100 +							{
 92.1101 +								if (sx < 240)
 92.1102 +								{
 92.1103 +									u8 color = vram[address];
 92.1104 +									if ((color == 0) && (((prio >> 25)&3) <
 92.1105 +									                     ((lineOBJ[sx]>>25)&3)))
 92.1106 +									{
 92.1107 +										lineOBJ[sx] = (lineOBJ[sx] & 0xF9FFFFFF) | prio;
 92.1108 +										if ((a0 & 0x1000) && m)
 92.1109 +											lineOBJ[sx] = (lineOBJ[sx-1] & 0xF9FFFFFF) | prio;
 92.1110 +									}
 92.1111 +									else if ((color) && (prio < (lineOBJ[sx]&0xFF000000)))
 92.1112 +									{
 92.1113 +										lineOBJ[sx] = READ16LE(&spritePalette[color]) | prio;
 92.1114 +										if ((a0 & 0x1000) && m)
 92.1115 +											lineOBJ[sx] = (lineOBJ[sx-1] & 0xF9FFFFFF) | prio;
 92.1116 +									}
 92.1117 +
 92.1118 +									if (a0 & 0x1000)
 92.1119 +									{
 92.1120 +										m++;
 92.1121 +										if (m == mosaicX)
 92.1122 +											m = 0;
 92.1123 +									}
 92.1124 +
 92.1125 +#ifdef SPRITE_DEBUG
 92.1126 +									if (t == 0 || t == maskY || xx == 0 || xx == maskX)
 92.1127 +										lineOBJ[sx] = 0x001F;
 92.1128 +#endif
 92.1129 +								}
 92.1130 +
 92.1131 +								sx = (sx+1) & 511;
 92.1132 +								if (a1 & 0x1000)
 92.1133 +								{
 92.1134 +									xxx--;
 92.1135 +									address--;
 92.1136 +									if (xxx == -1)
 92.1137 +									{
 92.1138 +										address -= 56;
 92.1139 +										xxx      = 7;
 92.1140 +									}
 92.1141 +									if (address < 0x10000)
 92.1142 +										address += 0x8000;
 92.1143 +								}
 92.1144 +								else
 92.1145 +								{
 92.1146 +									xxx++;
 92.1147 +									address++;
 92.1148 +									if (xxx == 8)
 92.1149 +									{
 92.1150 +										address += 56;
 92.1151 +										xxx      = 0;
 92.1152 +									}
 92.1153 +									if (address > 0x17fff)
 92.1154 +										address -= 0x8000;
 92.1155 +								}
 92.1156 +							}
 92.1157 +						}
 92.1158 +						else
 92.1159 +						{
 92.1160 +							if (a1 & 0x2000)
 92.1161 +								t = sizeY - t - 1;
 92.1162 +							int c = (a2 & 0x3FF);
 92.1163 +							if ((DISPCNT & 7) > 2 && (c < 512))
 92.1164 +								continue;
 92.1165 +
 92.1166 +							int inc = 32;
 92.1167 +							if (DISPCNT & 0x40)
 92.1168 +							{
 92.1169 +								inc = sizeX >> 3;
 92.1170 +							}
 92.1171 +							int xxx = 0;
 92.1172 +							if (a1 & 0x1000)
 92.1173 +								xxx = sizeX - 1;
 92.1174 +
 92.1175 +							if (a0 & 0x1000)
 92.1176 +							{
 92.1177 +								t -= (t % mosaicY);
 92.1178 +							}
 92.1179 +
 92.1180 +							int address = 0x10000 + ((((c + (t>>3) * inc)<<5)
 92.1181 +							                          + ((t & 7)<<2) + ((xxx>>3)<<5) + ((xxx & 7) >> 1))&0x7FFF);
 92.1182 +							u32 prio    = (((a2 >> 10) & 3) << 25) | ((a0 & 0x0c00)<<6);
 92.1183 +							int palette = (a2 >> 8) & 0xF0;
 92.1184 +							if (a1 & 0x1000)
 92.1185 +							{
 92.1186 +								xxx = 7;
 92.1187 +								for (int xx = sizeX - 1; xx >= 0; xx--)
 92.1188 +								{
 92.1189 +									if (sx < 240)
 92.1190 +									{
 92.1191 +										u8 color = vram[address];
 92.1192 +										if (xx & 1)
 92.1193 +										{
 92.1194 +											color = (color >> 4);
 92.1195 +										}
 92.1196 +										else
 92.1197 +											color &= 0x0F;
 92.1198 +
 92.1199 +										if ((color == 0) && (((prio >> 25)&3) <
 92.1200 +										                     ((lineOBJ[sx]>>25)&3)))
 92.1201 +										{
 92.1202 +											lineOBJ[sx] = (lineOBJ[sx] & 0xF9FFFFFF) | prio;
 92.1203 +											if ((a0 & 0x1000) && m)
 92.1204 +												lineOBJ[sx] = (lineOBJ[sx-1] & 0xF9FFFFFF) | prio;
 92.1205 +										}
 92.1206 +										else if ((color) && (prio < (lineOBJ[sx]&0xFF000000)))
 92.1207 +										{
 92.1208 +											lineOBJ[sx] = READ16LE(&spritePalette[palette + color]) | prio;
 92.1209 +											if ((a0 & 0x1000) && m)
 92.1210 +												lineOBJ[sx] = (lineOBJ[sx-1] & 0xF9FFFFFF) | prio;
 92.1211 +										}
 92.1212 +									}
 92.1213 +									if (a0 & 0x1000)
 92.1214 +									{
 92.1215 +										m++;
 92.1216 +										if (m == mosaicX)
 92.1217 +											m = 0;
 92.1218 +									}
 92.1219 +#ifdef SPRITE_DEBUG
 92.1220 +									if (t == 0 || t == maskY || xx == 0 || xx == maskX)
 92.1221 +										lineOBJ[sx] = 0x001F;
 92.1222 +#endif
 92.1223 +									sx = (sx+1) & 511;
 92.1224 +									xxx--;
 92.1225 +									if (!(xx & 1))
 92.1226 +										address--;
 92.1227 +									if (xxx == -1)
 92.1228 +									{
 92.1229 +										xxx      = 7;
 92.1230 +										address -= 28;
 92.1231 +									}
 92.1232 +									if (address < 0x10000)
 92.1233 +										address += 0x8000;
 92.1234 +								}
 92.1235 +							}
 92.1236 +							else
 92.1237 +							{
 92.1238 +								for (int xx = 0; xx < sizeX; xx++)
 92.1239 +								{
 92.1240 +									if (sx < 240)
 92.1241 +									{
 92.1242 +										u8 color = vram[address];
 92.1243 +										if (xx & 1)
 92.1244 +										{
 92.1245 +											color = (color >> 4);
 92.1246 +										}
 92.1247 +										else
 92.1248 +											color &= 0x0F;
 92.1249 +
 92.1250 +										if ((color == 0) && (((prio >> 25)&3) <
 92.1251 +										                     ((lineOBJ[sx]>>25)&3)))
 92.1252 +										{
 92.1253 +											lineOBJ[sx] = (lineOBJ[sx] & 0xF9FFFFFF) | prio;
 92.1254 +											if ((a0 & 0x1000) && m)
 92.1255 +												lineOBJ[sx] = (lineOBJ[sx-1] & 0xF9FFFFFF) | prio;
 92.1256 +										}
 92.1257 +										else if ((color) && (prio < (lineOBJ[sx]&0xFF000000)))
 92.1258 +										{
 92.1259 +											lineOBJ[sx] = READ16LE(&spritePalette[palette + color]) | prio;
 92.1260 +											if ((a0 & 0x1000) && m)
 92.1261 +												lineOBJ[sx] = (lineOBJ[sx-1] & 0xF9FFFFFF) | prio;
 92.1262 +										}
 92.1263 +									}
 92.1264 +									if (a0 & 0x1000)
 92.1265 +									{
 92.1266 +										m++;
 92.1267 +										if (m == mosaicX)
 92.1268 +											m = 0;
 92.1269 +									}
 92.1270 +#ifdef SPRITE_DEBUG
 92.1271 +									if (t == 0 || t == maskY || xx == 0 || xx == maskX)
 92.1272 +										lineOBJ[sx] = 0x001F;
 92.1273 +#endif
 92.1274 +									sx = (sx+1) & 511;
 92.1275 +									xxx++;
 92.1276 +									if (xx & 1)
 92.1277 +										address++;
 92.1278 +									if (xxx == 8)
 92.1279 +									{
 92.1280 +										address += 28;
 92.1281 +										xxx      = 0;
 92.1282 +									}
 92.1283 +									if (address > 0x17fff)
 92.1284 +										address -= 0x8000;
 92.1285 +								}
 92.1286 +							}
 92.1287 +						}
 92.1288 +					}
 92.1289 +				}
 92.1290 +			}
 92.1291 +		}
 92.1292 +	}
 92.1293 +}
 92.1294 +
 92.1295 +inline void gfxDrawOBJWin(u32 *lineOBJWin)
 92.1296 +{
 92.1297 +	gfxClearArray(lineOBJWin);
 92.1298 +	if (layerEnable & 0x8000)
 92.1299 +	{
 92.1300 +		u16 *sprites = (u16 *)oam;
 92.1301 +		// u16 *spritePalette = &((u16 *)paletteRAM)[256];
 92.1302 +		for (int x = 0; x < 128; x++)
 92.1303 +		{
 92.1304 +			u16 a0 = READ16LE(sprites++);
 92.1305 +			u16 a1 = READ16LE(sprites++);
 92.1306 +			u16 a2 = READ16LE(sprites++);
 92.1307 +			sprites++;
 92.1308 +
 92.1309 +			// ignore non OBJ-WIN
 92.1310 +			if ((a0 & 0x0c00) != 0x0800)
 92.1311 +				continue;
 92.1312 +
 92.1313 +			int sizeY = 8;
 92.1314 +			int sizeX = 8;
 92.1315 +
 92.1316 +			switch (((a0 >>12) & 0x0c)|(a1>>14))
 92.1317 +			{
 92.1318 +			case 0:
 92.1319 +				break;
 92.1320 +			case 1:
 92.1321 +				sizeX = sizeY = 16;
 92.1322 +				break;
 92.1323 +			case 2:
 92.1324 +				sizeX = sizeY = 32;
 92.1325 +				break;
 92.1326 +			case 3:
 92.1327 +				sizeX = sizeY = 64;
 92.1328 +				break;
 92.1329 +			case 4:
 92.1330 +				sizeX = 16;
 92.1331 +				break;
 92.1332 +			case 5:
 92.1333 +				sizeX = 32;
 92.1334 +				break;
 92.1335 +			case 6:
 92.1336 +				sizeX = 32;
 92.1337 +				sizeY = 16;
 92.1338 +				break;
 92.1339 +			case 7:
 92.1340 +				sizeX = 64;
 92.1341 +				sizeY = 32;
 92.1342 +				break;
 92.1343 +			case 8:
 92.1344 +				sizeY = 16;
 92.1345 +				break;
 92.1346 +			case 9:
 92.1347 +				sizeY = 32;
 92.1348 +				break;
 92.1349 +			case 10:
 92.1350 +				sizeX = 16;
 92.1351 +				sizeY = 32;
 92.1352 +				break;
 92.1353 +			case 11:
 92.1354 +				sizeX = 32;
 92.1355 +				sizeY = 64;
 92.1356 +				break;
 92.1357 +			default:
 92.1358 +				continue;
 92.1359 +			}
 92.1360 +
 92.1361 +			int sy = (a0 & 255);
 92.1362 +
 92.1363 +			if (sy > 160)
 92.1364 +				sy -= 256;
 92.1365 +
 92.1366 +			if (a0 & 0x0100)
 92.1367 +			{
 92.1368 +				int fieldX = sizeX;
 92.1369 +				int fieldY = sizeY;
 92.1370 +				if (a0 & 0x0200)
 92.1371 +				{
 92.1372 +					fieldX <<= 1;
 92.1373 +					fieldY <<= 1;
 92.1374 +				}
 92.1375 +
 92.1376 +				int t = VCOUNT - sy;
 92.1377 +				if ((t >= 0) && (t < fieldY))
 92.1378 +				{
 92.1379 +					int sx = (a1 & 0x1FF);
 92.1380 +					if ((sx < 240) || (((sx + fieldX) & 511) < 240))
 92.1381 +					{
 92.1382 +						// int t2 = t - (fieldY >> 1);
 92.1383 +						int  rot = (a1 >> 9) & 0x1F;
 92.1384 +						u16 *OAM = (u16 *)oam;
 92.1385 +						int  dx  = READ16LE(&OAM[3 + (rot << 4)]);
 92.1386 +						if (dx & 0x8000)
 92.1387 +							dx |= 0xFFFF8000;
 92.1388 +						int dmx = READ16LE(&OAM[7 + (rot << 4)]);
 92.1389 +						if (dmx & 0x8000)
 92.1390 +							dmx |= 0xFFFF8000;
 92.1391 +						int dy = READ16LE(&OAM[11 + (rot << 4)]);
 92.1392 +						if (dy & 0x8000)
 92.1393 +							dy |= 0xFFFF8000;
 92.1394 +						int dmy = READ16LE(&OAM[15 + (rot << 4)]);
 92.1395 +						if (dmy & 0x8000)
 92.1396 +							dmy |= 0xFFFF8000;
 92.1397 +
 92.1398 +						int realX = ((sizeX) << 7) - (fieldX >> 1)*dx - (fieldY>>1)*dmx
 92.1399 +						            + t * dmx;
 92.1400 +						int realY = ((sizeY) << 7) - (fieldX >> 1)*dy - (fieldY>>1)*dmy
 92.1401 +						            + t * dmy;
 92.1402 +
 92.1403 +						// u32 prio = (((a2 >> 10) & 3) << 25) | ((a0 & 0x0c00)<<6);
 92.1404 +
 92.1405 +						if (a0 & 0x2000)
 92.1406 +						{
 92.1407 +							int c = (a2 & 0x3FF);
 92.1408 +							if ((DISPCNT & 7) > 2 && (c < 512))
 92.1409 +								continue;
 92.1410 +							int inc = 32;
 92.1411 +							if (DISPCNT & 0x40)
 92.1412 +								inc = sizeX >> 2;
 92.1413 +							else
 92.1414 +								c &= 0x3FE;
 92.1415 +							for (int x = 0; x < fieldX; x++)
 92.1416 +							{
 92.1417 +								int xxx = realX >> 8;
 92.1418 +								int yyy = realY >> 8;
 92.1419 +
 92.1420 +								if (xxx < 0 || xxx >= sizeX ||
 92.1421 +								    yyy < 0 || yyy >= sizeY)
 92.1422 +								{}
 92.1423 +								else
 92.1424 +								{
 92.1425 +									u32 color = vram[0x10000 + ((((c + (yyy>>3) * inc)<<5)
 92.1426 +									                             + ((yyy & 7)<<3) + ((xxx >> 3)<<6) +
 92.1427 +									                             (xxx & 7))&0x7fff)];
 92.1428 +									if (color)
 92.1429 +									{
 92.1430 +										lineOBJWin[sx] = 1;
 92.1431 +									}
 92.1432 +								}
 92.1433 +								sx     = (sx+1)&511;;
 92.1434 +								realX += dx;
 92.1435 +								realY += dy;
 92.1436 +							}
 92.1437 +						}
 92.1438 +						else
 92.1439 +						{
 92.1440 +							int c = (a2 & 0x3FF);
 92.1441 +							if ((DISPCNT & 7) > 2 && (c < 512))
 92.1442 +								continue;
 92.1443 +
 92.1444 +							int inc = 32;
 92.1445 +							if (DISPCNT & 0x40)
 92.1446 +								inc = sizeX >> 3;
 92.1447 +							// int palette = (a2 >> 8) & 0xF0;
 92.1448 +							for (int x = 0; x < fieldX; x++)
 92.1449 +							{
 92.1450 +								int xxx = realX >> 8;
 92.1451 +								int yyy = realY >> 8;
 92.1452 +
 92.1453 +								//              if(x == 0 || x == (sizeX-1) ||
 92.1454 +								//                 t == 0 || t == (sizeY-1)) {
 92.1455 +								//                lineOBJ[sx] = 0x001F | prio;
 92.1456 +								//              } else {
 92.1457 +								if (xxx < 0 || xxx >= sizeX ||
 92.1458 +								    yyy < 0 || yyy >= sizeY)
 92.1459 +								{}
 92.1460 +								else
 92.1461 +								{
 92.1462 +									u32 color = vram[0x10000 + ((((c + (yyy>>3) * inc)<<5)
 92.1463 +									                             + ((yyy & 7)<<2) + ((xxx >> 3)<<5) +
 92.1464 +									                             ((xxx & 7)>>1))&0x7fff)];
 92.1465 +									if (xxx & 1)
 92.1466 +										color >>= 4;
 92.1467 +									else
 92.1468 +										color &= 0x0F;
 92.1469 +
 92.1470 +									if (color)
 92.1471 +									{
 92.1472 +										lineOBJWin[sx] = 1;
 92.1473 +									}
 92.1474 +								}
 92.1475 +								//            }
 92.1476 +								sx     = (sx+1)&511;;
 92.1477 +								realX += dx;
 92.1478 +								realY += dy;
 92.1479 +							}
 92.1480 +						}
 92.1481 +					}
 92.1482 +				}
 92.1483 +			}
 92.1484 +			else
 92.1485 +			{
 92.1486 +				int t = VCOUNT - sy;
 92.1487 +				if ((t >= 0) && (t < sizeY))
 92.1488 +				{
 92.1489 +					int sx = (a1 & 0x1FF);
 92.1490 +					if (((sx < 240) || (((sx+sizeX)&511) < 240)) && !(a0 & 0x0200))
 92.1491 +					{
 92.1492 +						if (a0 & 0x2000)
 92.1493 +						{
 92.1494 +							if (a1 & 0x2000)
 92.1495 +								t = sizeY - t - 1;
 92.1496 +							int c = (a2 & 0x3FF);
 92.1497 +							if ((DISPCNT & 7) > 2 && (c < 512))
 92.1498 +								continue;
 92.1499 +
 92.1500 +							int inc = 32;
 92.1501 +							if (DISPCNT & 0x40)
 92.1502 +							{
 92.1503 +								inc = sizeX >> 2;
 92.1504 +							}
 92.1505 +							else
 92.1506 +							{
 92.1507 +								c &= 0x3FE;
 92.1508 +							}
 92.1509 +							int xxx = 0;
 92.1510 +							if (a1 & 0x1000)
 92.1511 +								xxx = sizeX-1;
 92.1512 +							int address = 0x10000 + ((((c+ (t>>3) * inc) << 5)
 92.1513 +							                          + ((t & 7) << 3) + ((xxx>>3)<<6) + (xxx & 7))&0x7fff);
 92.1514 +							if (a1 & 0x1000)
 92.1515 +								xxx = 7;
 92.1516 +							// u32 prio = (((a2 >> 10) & 3) << 25) | ((a0 & 0x0c00)<<6);
 92.1517 +							for (int xx = 0; xx < sizeX; xx++)
 92.1518 +							{
 92.1519 +								if (sx < 240)
 92.1520 +								{
 92.1521 +									u8 color = vram[address];
 92.1522 +									if (color)
 92.1523 +									{
 92.1524 +										lineOBJWin[sx] = 1;
 92.1525 +									}
 92.1526 +								}
 92.1527 +
 92.1528 +								sx = (sx+1) & 511;
 92.1529 +								if (a1 & 0x1000)
 92.1530 +								{
 92.1531 +									xxx--;
 92.1532 +									address--;
 92.1533 +									if (xxx == -1)
 92.1534 +									{
 92.1535 +										address -= 56;
 92.1536 +										xxx      = 7;
 92.1537 +									}
 92.1538 +									if (address < 0x10000)
 92.1539 +										address += 0x8000;
 92.1540 +								}
 92.1541 +								else
 92.1542 +								{
 92.1543 +									xxx++;
 92.1544 +									address++;
 92.1545 +									if (xxx == 8)
 92.1546 +									{
 92.1547 +										address += 56;
 92.1548 +										xxx      = 0;
 92.1549 +									}
 92.1550 +									if (address > 0x17fff)
 92.1551 +										address -= 0x8000;
 92.1552 +								}
 92.1553 +							}
 92.1554 +						}
 92.1555 +						else
 92.1556 +						{
 92.1557 +							if (a1 & 0x2000)
 92.1558 +								t = sizeY - t - 1;
 92.1559 +							int c = (a2 & 0x3FF);
 92.1560 +							if ((DISPCNT & 7) > 2 && (c < 512))
 92.1561 +								continue;
 92.1562 +
 92.1563 +							int inc = 32;
 92.1564 +							if (DISPCNT & 0x40)
 92.1565 +							{
 92.1566 +								inc = sizeX >> 3;
 92.1567 +							}
 92.1568 +							int xxx = 0;
 92.1569 +							if (a1 & 0x1000)
 92.1570 +								xxx = sizeX - 1;
 92.1571 +							int address = 0x10000 + ((((c + (t>>3) * inc)<<5)
 92.1572 +							                          + ((t & 7)<<2) + ((xxx>>3)<<5) + ((xxx & 7) >> 1))&0x7fff);
 92.1573 +							// u32 prio = (((a2 >> 10) & 3) << 25) | ((a0 & 0x0c00)<<6);
 92.1574 +							// int palette = (a2 >> 8) & 0xF0;
 92.1575 +							if (a1 & 0x1000)
 92.1576 +							{
 92.1577 +								xxx = 7;
 92.1578 +								for (int xx = sizeX - 1; xx >= 0; xx--)
 92.1579 +								{
 92.1580 +									if (sx < 240)
 92.1581 +									{
 92.1582 +										u8 color = vram[address];
 92.1583 +										if (xx & 1)
 92.1584 +										{
 92.1585 +											color = (color >> 4);
 92.1586 +										}
 92.1587 +										else
 92.1588 +											color &= 0x0F;
 92.1589 +
 92.1590 +										if (color)
 92.1591 +										{
 92.1592 +											lineOBJWin[sx] = 1;
 92.1593 +										}
 92.1594 +									}
 92.1595 +									sx = (sx+1) & 511;
 92.1596 +									xxx--;
 92.1597 +									if (!(xx & 1))
 92.1598 +										address--;
 92.1599 +									if (xxx == -1)
 92.1600 +									{
 92.1601 +										xxx      = 7;
 92.1602 +										address -= 28;
 92.1603 +									}
 92.1604 +									if (address < 0x10000)
 92.1605 +										address += 0x8000;
 92.1606 +								}
 92.1607 +							}
 92.1608 +							else
 92.1609 +							{
 92.1610 +								for (int xx = 0; xx < sizeX; xx++)
 92.1611 +								{
 92.1612 +									if (sx < 240)
 92.1613 +									{
 92.1614 +										u8 color = vram[address];
 92.1615 +										if (xx & 1)
 92.1616 +										{
 92.1617 +											color = (color >> 4);
 92.1618 +										}
 92.1619 +										else
 92.1620 +											color &= 0x0F;
 92.1621 +
 92.1622 +										if (color)
 92.1623 +										{
 92.1624 +											lineOBJWin[sx] = 1;
 92.1625 +										}
 92.1626 +									}
 92.1627 +									sx = (sx+1) & 511;
 92.1628 +									xxx++;
 92.1629 +									if (xx & 1)
 92.1630 +										address++;
 92.1631 +									if (xxx == 8)
 92.1632 +									{
 92.1633 +										address += 28;
 92.1634 +										xxx      = 0;
 92.1635 +									}
 92.1636 +									if (address > 0x17fff)
 92.1637 +										address -= 0x8000;
 92.1638 +								}
 92.1639 +							}
 92.1640 +						}
 92.1641 +					}
 92.1642 +				}
 92.1643 +			}
 92.1644 +		}
 92.1645 +	}
 92.1646 +}
 92.1647 +
 92.1648 +inline u32 gfxIncreaseBrightness(u32 color, int coeff)
 92.1649 +{
 92.1650 +	int r = (color & 0x1F);
 92.1651 +	int g = ((color >> 5) & 0x1F);
 92.1652 +	int b = ((color >> 10) & 0x1F);
 92.1653 +
 92.1654 +	r = r + (((31 - r) * coeff) >> 4);
 92.1655 +	g = g + (((31 - g) * coeff) >> 4);
 92.1656 +	b = b + (((31 - b) * coeff) >> 4);
 92.1657 +	if (r > 31)
 92.1658 +		r = 31;
 92.1659 +	if (g > 31)
 92.1660 +		g = 31;
 92.1661 +	if (b > 31)
 92.1662 +		b = 31;
 92.1663 +	color = (color & 0xFFFF0000) | (b << 10) | (g << 5) | r;
 92.1664 +	return color;
 92.1665 +}
 92.1666 +
 92.1667 +inline void gfxIncreaseBrightness(u32 *line, int coeff)
 92.1668 +{
 92.1669 +	for (int x = 0; x < 240; x++)
 92.1670 +	{
 92.1671 +		u32 color = *line;
 92.1672 +		int r     = (color & 0x1F);
 92.1673 +		int g     = ((color >> 5) & 0x1F);
 92.1674 +		int b     = ((color >> 10) & 0x1F);
 92.1675 +
 92.1676 +		r = r + (((31 - r) * coeff) >> 4);
 92.1677 +		g = g + (((31 - g) * coeff) >> 4);
 92.1678 +		b = b + (((31 - b) * coeff) >> 4);
 92.1679 +		if (r > 31)
 92.1680 +			r = 31;
 92.1681 +		if (g > 31)
 92.1682 +			g = 31;
 92.1683 +		if (b > 31)
 92.1684 +			b = 31;
 92.1685 +		*line++ = (color & 0xFFFF0000) | (b << 10) | (g << 5) | r;
 92.1686 +	}
 92.1687 +}
 92.1688 +
 92.1689 +inline u32 gfxDecreaseBrightness(u32 color, int coeff)
 92.1690 +{
 92.1691 +	int r = (color & 0x1F);
 92.1692 +	int g = ((color >> 5) & 0x1F);
 92.1693 +	int b = ((color >> 10) & 0x1F);
 92.1694 +
 92.1695 +	r = r - ((r * coeff) >> 4);
 92.1696 +	g = g - ((g * coeff) >> 4);
 92.1697 +	b = b - ((b * coeff) >> 4);
 92.1698 +	if (r < 0)
 92.1699 +		r = 0;
 92.1700 +	if (g < 0)
 92.1701 +		g = 0;
 92.1702 +	if (b < 0)
 92.1703 +		b = 0;
 92.1704 +	color = (color & 0xFFFF0000) | (b << 10) | (g << 5) | r;
 92.1705 +
 92.1706 +	return color;
 92.1707 +}
 92.1708 +
 92.1709 +inline void gfxDecreaseBrightness(u32 *line, int coeff)
 92.1710 +{
 92.1711 +	for (int x = 0; x < 240; x++)
 92.1712 +	{
 92.1713 +		u32 color = *line;
 92.1714 +		int r     = (color & 0x1F);
 92.1715 +		int g     = ((color >> 5) & 0x1F);
 92.1716 +		int b     = ((color >> 10) & 0x1F);
 92.1717 +
 92.1718 +		r = r - ((r * coeff) >> 4);
 92.1719 +		g = g - ((g * coeff) >> 4);
 92.1720 +		b = b - ((b * coeff) >> 4);
 92.1721 +		if (r < 0)
 92.1722 +			r = 0;
 92.1723 +		if (g < 0)
 92.1724 +			g = 0;
 92.1725 +		if (b < 0)
 92.1726 +			b = 0;
 92.1727 +		*line++ = (color & 0xFFFF0000) | (b << 10) | (g << 5) | r;
 92.1728 +	}
 92.1729 +}
 92.1730 +
 92.1731 +inline u32 gfxAlphaBlend(u32 color, u32 color2, int ca, int cb)
 92.1732 +{
 92.1733 +	if (color < 0x80000000)
 92.1734 +	{
 92.1735 +		int r  = (color & 0x1F);
 92.1736 +		int g  = ((color >> 5) & 0x1F);
 92.1737 +		int b  = ((color >> 10) & 0x1F);
 92.1738 +		int r0 = (color2 & 0x1F);
 92.1739 +		int g0 = ((color2 >> 5) & 0x1F);
 92.1740 +		int b0 = ((color2 >> 10) & 0x1F);
 92.1741 +
 92.1742 +		r = ((r * ca) >> 4) + ((r0 * cb) >> 4);
 92.1743 +		g = ((g * ca) >> 4) + ((g0 * cb) >> 4);
 92.1744 +		b = ((b * ca) >> 4) + ((b0 * cb) >> 4);
 92.1745 +
 92.1746 +		if (r > 31)
 92.1747 +			r = 31;
 92.1748 +		if (g > 31)
 92.1749 +			g = 31;
 92.1750 +		if (b > 31)
 92.1751 +			b = 31;
 92.1752 +
 92.1753 +		return (color & 0xFFFF0000) | (b << 10) | (g << 5) | r;
 92.1754 +	}
 92.1755 +	return color;
 92.1756 +}
 92.1757 +
 92.1758 +inline void gfxAlphaBlend(u32 *ta, u32 *tb, int ca, int cb)
 92.1759 +{
 92.1760 +	for (int x = 0; x < 240; x++)
 92.1761 +	{
 92.1762 +		u32 color = *ta;
 92.1763 +		if (color < 0x80000000)
 92.1764 +		{
 92.1765 +			int r      = (color & 0x1F);
 92.1766 +			int g      = ((color >> 5) & 0x1F);
 92.1767 +			int b      = ((color >> 10) & 0x1F);
 92.1768 +			u32 color2 = (*tb++);
 92.1769 +			int r0     = (color2 & 0x1F);
 92.1770 +			int g0     = ((color2 >> 5) & 0x1F);
 92.1771 +			int b0     = ((color2 >> 10) & 0x1F);
 92.1772 +
 92.1773 +			r = ((r * ca) >> 4) + ((r0 * cb) >> 4);
 92.1774 +			g = ((g * ca) >> 4) + ((g0 * cb) >> 4);
 92.1775 +			b = ((b * ca) >> 4) + ((b0 * cb) >> 4);
 92.1776 +
 92.1777 +			if (r > 31)
 92.1778 +				r = 31;
 92.1779 +			if (g > 31)
 92.1780 +				g = 31;
 92.1781 +			if (b > 31)
 92.1782 +				b = 31;
 92.1783 +
 92.1784 +			*ta++ = (color & 0xFFFF0000) | (b << 10) | (g << 5) | r;
 92.1785 +		}
 92.1786 +		else
 92.1787 +		{
 92.1788 +			ta++;
 92.1789 +			tb++;
 92.1790 +		}
 92.1791 +	}
 92.1792 +}
 92.1793 +
 92.1794 +#endif // VBA_GBA_GFX_H
    93.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    93.2 +++ b/src/gba/GBAGlobals.cpp	Sat Mar 03 10:31:27 2012 -0600
    93.3 @@ -0,0 +1,123 @@
    93.4 +#include "GBAGlobals.h"
    93.5 +
    93.6 +reg_pair  reg[45];
    93.7 +memoryMap map[256];
    93.8 +bool8	  ioReadable[0x400];
    93.9 +bool8	  N_FLAG			   = 0;
   93.10 +bool8	  C_FLAG			   = 0;
   93.11 +bool8	  Z_FLAG			   = 0;
   93.12 +bool8	  V_FLAG			   = 0;
   93.13 +bool8	  armState			   = true;
   93.14 +bool8	  armIrqEnable		   = true;
   93.15 +u32		  armNextPC			   = 0x00000000;
   93.16 +int32	  armMode			   = 0x1f;
   93.17 +u32		  stop				   = 0x08000568;
   93.18 +int32	  saveType			   = 0;
   93.19 +bool8	  useBios			   = false;
   93.20 +bool8	  skipBios			   = false;
   93.21 +int32	  frameSkip			   = 1;
   93.22 +u32		  extButtons		   = 0;
   93.23 +bool8	  capturePrevious	   = false;
   93.24 +int32	  captureNumber		   = 0;
   93.25 +bool8	  speedup			   = false;
   93.26 +bool8	  synchronize		   = true;
   93.27 +bool8	  cpuDisableSfx		   = false;
   93.28 +bool8	  cpuIsMultiBoot	   = false;
   93.29 +bool8	  parseDebug		   = true;
   93.30 +int32	  layerSettings		   = 0xff00;
   93.31 +int32	  layerEnable		   = 0xff00;
   93.32 +bool8	  speedHack			   = false;
   93.33 +bool8	  memLagEnabled		   = false;
   93.34 +bool8	  memLagTempEnabled	   = false;
   93.35 +bool8	  useOldFrameTiming	   = false;
   93.36 +int32	  cpuSaveType		   = 0;
   93.37 +bool8	  cpuEnhancedDetection = true;
   93.38 +bool8	  cheatsEnabled		   = true;
   93.39 +
   93.40 +u8 *bios		= NULL;
   93.41 +u8 *rom			= NULL;
   93.42 +u8 *internalRAM = NULL;
   93.43 +u8 *workRAM		= NULL;
   93.44 +u8 *paletteRAM	= NULL;
   93.45 +u8 *vram		= NULL;
   93.46 +u8 *pix			= NULL;
   93.47 +u8 *oam			= NULL;
   93.48 +u8 *ioMem		= NULL;
   93.49 +
   93.50 +u16 DISPCNT	 = 0x0080;
   93.51 +u16 DISPSTAT = 0x0000;
   93.52 +u16 VCOUNT	 = 0x0000;
   93.53 +u16 BG0CNT	 = 0x0000;
   93.54 +u16 BG1CNT	 = 0x0000;
   93.55 +u16 BG2CNT	 = 0x0000;
   93.56 +u16 BG3CNT	 = 0x0000;
   93.57 +u16 BG0HOFS	 = 0x0000;
   93.58 +u16 BG0VOFS	 = 0x0000;
   93.59 +u16 BG1HOFS	 = 0x0000;
   93.60 +u16 BG1VOFS	 = 0x0000;
   93.61 +u16 BG2HOFS	 = 0x0000;
   93.62 +u16 BG2VOFS	 = 0x0000;
   93.63 +u16 BG3HOFS	 = 0x0000;
   93.64 +u16 BG3VOFS	 = 0x0000;
   93.65 +u16 BG2PA	 = 0x0100;
   93.66 +u16 BG2PB	 = 0x0000;
   93.67 +u16 BG2PC	 = 0x0000;
   93.68 +u16 BG2PD	 = 0x0100;
   93.69 +u16 BG2X_L	 = 0x0000;
   93.70 +u16 BG2X_H	 = 0x0000;
   93.71 +u16 BG2Y_L	 = 0x0000;
   93.72 +u16 BG2Y_H	 = 0x0000;
   93.73 +u16 BG3PA	 = 0x0100;
   93.74 +u16 BG3PB	 = 0x0000;
   93.75 +u16 BG3PC	 = 0x0000;
   93.76 +u16 BG3PD	 = 0x0100;
   93.77 +u16 BG3X_L	 = 0x0000;
   93.78 +u16 BG3X_H	 = 0x0000;
   93.79 +u16 BG3Y_L	 = 0x0000;
   93.80 +u16 BG3Y_H	 = 0x0000;
   93.81 +u16 WIN0H	 = 0x0000;
   93.82 +u16 WIN1H	 = 0x0000;
   93.83 +u16 WIN0V	 = 0x0000;
   93.84 +u16 WIN1V	 = 0x0000;
   93.85 +u16 WININ	 = 0x0000;
   93.86 +u16 WINOUT	 = 0x0000;
   93.87 +u16 MOSAIC	 = 0x0000;
   93.88 +u16 BLDMOD	 = 0x0000;
   93.89 +u16 COLEV	 = 0x0000;
   93.90 +u16 COLY	 = 0x0000;
   93.91 +u16 DM0SAD_L = 0x0000;
   93.92 +u16 DM0SAD_H = 0x0000;
   93.93 +u16 DM0DAD_L = 0x0000;
   93.94 +u16 DM0DAD_H = 0x0000;
   93.95 +u16 DM0CNT_L = 0x0000;
   93.96 +u16 DM0CNT_H = 0x0000;
   93.97 +u16 DM1SAD_L = 0x0000;
   93.98 +u16 DM1SAD_H = 0x0000;
   93.99 +u16 DM1DAD_L = 0x0000;
  93.100 +u16 DM1DAD_H = 0x0000;
  93.101 +u16 DM1CNT_L = 0x0000;
  93.102 +u16 DM1CNT_H = 0x0000;
  93.103 +u16 DM2SAD_L = 0x0000;
  93.104 +u16 DM2SAD_H = 0x0000;
  93.105 +u16 DM2DAD_L = 0x0000;
  93.106 +u16 DM2DAD_H = 0x0000;
  93.107 +u16 DM2CNT_L = 0x0000;
  93.108 +u16 DM2CNT_H = 0x0000;
  93.109 +u16 DM3SAD_L = 0x0000;
  93.110 +u16 DM3SAD_H = 0x0000;
  93.111 +u16 DM3DAD_L = 0x0000;
  93.112 +u16 DM3DAD_H = 0x0000;
  93.113 +u16 DM3CNT_L = 0x0000;
  93.114 +u16 DM3CNT_H = 0x0000;
  93.115 +u16 TM0D	 = 0x0000;
  93.116 +u16 TM0CNT	 = 0x0000;
  93.117 +u16 TM1D	 = 0x0000;
  93.118 +u16 TM1CNT	 = 0x0000;
  93.119 +u16 TM2D	 = 0x0000;
  93.120 +u16 TM2CNT	 = 0x0000;
  93.121 +u16 TM3D	 = 0x0000;
  93.122 +u16 TM3CNT	 = 0x0000;
  93.123 +u16 P1		 = 0xFFFF;
  93.124 +u16 IE		 = 0x0000;
  93.125 +u16 IF		 = 0x0000;
  93.126 +u16 IME		 = 0x0000;
    94.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    94.2 +++ b/src/gba/GBAGlobals.h	Sat Mar 03 10:31:27 2012 -0600
    94.3 @@ -0,0 +1,208 @@
    94.4 +#ifndef VBA_GBA_GLOBALS_H
    94.5 +#define VBA_GBA_GLOBALS_H
    94.6 +
    94.7 +#if _MSC_VER > 1000
    94.8 +#pragma once
    94.9 +#endif // _MSC_VER > 1000
   94.10 +
   94.11 +#include "../Port.h"
   94.12 +
   94.13 +#define VERBOSE_SWI                  1
   94.14 +#define VERBOSE_UNALIGNED_MEMORY     2
   94.15 +#define VERBOSE_ILLEGAL_WRITE        4
   94.16 +#define VERBOSE_ILLEGAL_READ         8
   94.17 +#define VERBOSE_DMA0                16
   94.18 +#define VERBOSE_DMA1                32
   94.19 +#define VERBOSE_DMA2                64
   94.20 +#define VERBOSE_DMA3               128
   94.21 +#define VERBOSE_UNDEFINED          256
   94.22 +#define VERBOSE_AGBPRINT           512
   94.23 +
   94.24 +// moved from armdis.cpp
   94.25 +#define debuggerReadMemory(addr) \
   94.26 +    READ32LE(&map[(addr) >> 24].address[(addr) & map[(addr) >> 24].mask])
   94.27 +
   94.28 +#define debuggerReadHalfWord(addr) \
   94.29 +    READ16LE(&map[(addr) >> 24].address[(addr) & map[(addr) >> 24].mask])
   94.30 +
   94.31 +#define debuggerReadByte(addr) \
   94.32 +    READ8LE(&map[(addr) >> 24].address[(addr) & map[(addr) >> 24].mask])
   94.33 +
   94.34 +#define debuggerWriteMemory(addr, value) \
   94.35 +    WRITE32LE((&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]), (value))
   94.36 +
   94.37 +#define debuggerWriteHalfWord(addr, value) \
   94.38 +    WRITE16LE((&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]), (value))
   94.39 +
   94.40 +#define debuggerWriteByte(addr, value) \
   94.41 +    WRITE8LE((&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]), (value))
   94.42 +
   94.43 +// moved from GBA.h
   94.44 +typedef struct
   94.45 +{
   94.46 +	u8 *address;
   94.47 +	u32 mask;
   94.48 +} memoryMap;
   94.49 +
   94.50 +#ifndef NO_GBA_MAP
   94.51 +extern memoryMap map[256];
   94.52 +#endif
   94.53 +
   94.54 +// moved from GBA.h
   94.55 +typedef union
   94.56 +{
   94.57 +	struct
   94.58 +	{
   94.59 +#ifdef WORDS_BIGENDIAN
   94.60 +		u8 B3;
   94.61 +		u8 B2;
   94.62 +		u8 B1;
   94.63 +		u8 B0;
   94.64 +#else
   94.65 +		u8 B0;
   94.66 +		u8 B1;
   94.67 +		u8 B2;
   94.68 +		u8 B3;
   94.69 +#endif
   94.70 +	} B;
   94.71 +	struct
   94.72 +	{
   94.73 +#ifdef WORDS_BIGENDIAN
   94.74 +		u16 W1;
   94.75 +		u16 W0;
   94.76 +#else
   94.77 +		u16 W0;
   94.78 +		u16 W1;
   94.79 +#endif
   94.80 +	} W;
   94.81 +#ifdef WORDS_BIGENDIAN
   94.82 +	volatile u32 I;
   94.83 +#else
   94.84 +	u32 I;
   94.85 +#endif
   94.86 +} reg_pair;
   94.87 +
   94.88 +extern reg_pair reg[45];
   94.89 +extern u8		biosProtected[4];
   94.90 +extern bool8	ioReadable[0x400];
   94.91 +extern bool8	N_FLAG;
   94.92 +extern bool8	C_FLAG;
   94.93 +extern bool8	Z_FLAG;
   94.94 +extern bool8	V_FLAG;
   94.95 +extern bool8	armState;
   94.96 +extern bool8	armIrqEnable;
   94.97 +extern u32		armNextPC;
   94.98 +extern int32	armMode;
   94.99 +extern u32		stop;
  94.100 +extern int32	saveType;
  94.101 +extern bool8	useBios;
  94.102 +extern bool8	skipBios;
  94.103 +extern int32	frameSkip;
  94.104 +extern u32		extButtons;
  94.105 +extern bool8	capturePrevious;
  94.106 +extern int32	captureNumber;
  94.107 +extern bool8	speedup;
  94.108 +extern bool8	synchronize;
  94.109 +extern bool8	cpuDisableSfx;
  94.110 +extern bool8	cpuIsMultiBoot;
  94.111 +extern bool8	parseDebug;
  94.112 +extern int32	layerSettings;
  94.113 +extern int32	layerEnable;
  94.114 +extern bool8	speedHack;
  94.115 +extern bool8	memLagEnabled, memLagTempEnabled;
  94.116 +extern bool8	useOldFrameTiming;
  94.117 +extern int32	cpuSaveType;
  94.118 +extern bool8	cpuEnhancedDetection;
  94.119 +extern bool8	cheatsEnabled;
  94.120 +
  94.121 +extern int emulating;
  94.122 +
  94.123 +extern u8 *bios;
  94.124 +extern u8 *rom;
  94.125 +extern u8 *internalRAM;
  94.126 +extern u8 *workRAM;
  94.127 +extern u8 *paletteRAM;
  94.128 +extern u8 *vram;
  94.129 +extern u8 *pix;
  94.130 +extern u8 *oam;
  94.131 +extern u8 *ioMem;
  94.132 +
  94.133 +extern u16 DISPCNT;
  94.134 +extern u16 DISPSTAT;
  94.135 +extern u16 VCOUNT;
  94.136 +extern u16 BG0CNT;
  94.137 +extern u16 BG1CNT;
  94.138 +extern u16 BG2CNT;
  94.139 +extern u16 BG3CNT;
  94.140 +extern u16 BG0HOFS;
  94.141 +extern u16 BG0VOFS;
  94.142 +extern u16 BG1HOFS;
  94.143 +extern u16 BG1VOFS;
  94.144 +extern u16 BG2HOFS;
  94.145 +extern u16 BG2VOFS;
  94.146 +extern u16 BG3HOFS;
  94.147 +extern u16 BG3VOFS;
  94.148 +extern u16 BG2PA;
  94.149 +extern u16 BG2PB;
  94.150 +extern u16 BG2PC;
  94.151 +extern u16 BG2PD;
  94.152 +extern u16 BG2X_L;
  94.153 +extern u16 BG2X_H;
  94.154 +extern u16 BG2Y_L;
  94.155 +extern u16 BG2Y_H;
  94.156 +extern u16 BG3PA;
  94.157 +extern u16 BG3PB;
  94.158 +extern u16 BG3PC;
  94.159 +extern u16 BG3PD;
  94.160 +extern u16 BG3X_L;
  94.161 +extern u16 BG3X_H;
  94.162 +extern u16 BG3Y_L;
  94.163 +extern u16 BG3Y_H;
  94.164 +extern u16 WIN0H;
  94.165 +extern u16 WIN1H;
  94.166 +extern u16 WIN0V;
  94.167 +extern u16 WIN1V;
  94.168 +extern u16 WININ;
  94.169 +extern u16 WINOUT;
  94.170 +extern u16 MOSAIC;
  94.171 +extern u16 BLDMOD;
  94.172 +extern u16 COLEV;
  94.173 +extern u16 COLY;
  94.174 +extern u16 DM0SAD_L;
  94.175 +extern u16 DM0SAD_H;
  94.176 +extern u16 DM0DAD_L;
  94.177 +extern u16 DM0DAD_H;
  94.178 +extern u16 DM0CNT_L;
  94.179 +extern u16 DM0CNT_H;
  94.180 +extern u16 DM1SAD_L;
  94.181 +extern u16 DM1SAD_H;
  94.182 +extern u16 DM1DAD_L;
  94.183 +extern u16 DM1DAD_H;
  94.184 +extern u16 DM1CNT_L;
  94.185 +extern u16 DM1CNT_H;
  94.186 +extern u16 DM2SAD_L;
  94.187 +extern u16 DM2SAD_H;
  94.188 +extern u16 DM2DAD_L;
  94.189 +extern u16 DM2DAD_H;
  94.190 +extern u16 DM2CNT_L;
  94.191 +extern u16 DM2CNT_H;
  94.192 +extern u16 DM3SAD_L;
  94.193 +extern u16 DM3SAD_H;
  94.194 +extern u16 DM3DAD_L;
  94.195 +extern u16 DM3DAD_H;
  94.196 +extern u16 DM3CNT_L;
  94.197 +extern u16 DM3CNT_H;
  94.198 +extern u16 TM0D;
  94.199 +extern u16 TM0CNT;
  94.200 +extern u16 TM1D;
  94.201 +extern u16 TM1CNT;
  94.202 +extern u16 TM2D;
  94.203 +extern u16 TM2CNT;
  94.204 +extern u16 TM3D;
  94.205 +extern u16 TM3CNT;
  94.206 +extern u16 P1;
  94.207 +extern u16 IE;
  94.208 +extern u16 IF;
  94.209 +extern u16 IME;
  94.210 +
  94.211 +#endif // VBA_GBA_GLOBALS_H
    95.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    95.2 +++ b/src/gba/GBASound.cpp	Sat Mar 03 10:31:27 2012 -0600
    95.3 @@ -0,0 +1,1542 @@
    95.4 +#if (defined(WIN32) && !defined(SDL))
    95.5 +#   include "../win32/stdafx.h"
    95.6 +#   include "../win32/VBA.h"
    95.7 +#endif
    95.8 +
    95.9 +#include <cstring>
   95.10 +#include <cassert>
   95.11 +
   95.12 +#include "GBASound.h"
   95.13 +#include "../common/System.h" // SDL build needs this
   95.14 +#include "../common/Util.h"
   95.15 +#include "GBA.h"
   95.16 +#include "GBAGlobals.h"
   95.17 +
   95.18 +#ifndef countof
   95.19 +#define countof(a)  (sizeof(a) / sizeof(a[0]))
   95.20 +#endif
   95.21 +
   95.22 +soundtick_t USE_TICKS_AS = 380; // (16777216.0/44100.0); // FIXME: (16777216.0/280896.0)(fps) vs 60.0fps?
   95.23 +
   95.24 +#define SOUND_MAGIC   0x60000000
   95.25 +#define SOUND_MAGIC_2 0x30000000
   95.26 +#define NOISE_MAGIC (2097152.0 / 44100.0)
   95.27 +
   95.28 +extern bool8 stopState;
   95.29 +
   95.30 +u8 soundWavePattern[4][32] = {
   95.31 +	{ 0x01, 0x01, 0x01, 0x01,
   95.32 +	  0xff, 0xff, 0xff, 0xff,
   95.33 +	  0xff, 0xff, 0xff, 0xff,
   95.34 +	  0xff, 0xff, 0xff, 0xff,
   95.35 +	  0xff, 0xff, 0xff, 0xff,
   95.36 +	  0xff, 0xff, 0xff, 0xff,
   95.37 +	  0xff, 0xff, 0xff, 0xff,
   95.38 +	  0xff, 0xff, 0xff, 0xff },
   95.39 +	{ 0x01, 0x01, 0x01, 0x01,
   95.40 +	  0x01, 0x01, 0x01, 0x01,
   95.41 +	  0xff, 0xff, 0xff, 0xff,
   95.42 +	  0xff, 0xff, 0xff, 0xff,
   95.43 +	  0xff, 0xff, 0xff, 0xff,
   95.44 +	  0xff, 0xff, 0xff, 0xff,
   95.45 +	  0xff, 0xff, 0xff, 0xff,
   95.46 +	  0xff, 0xff, 0xff, 0xff },
   95.47 +	{ 0x01, 0x01, 0x01, 0x01,
   95.48 +	  0x01, 0x01, 0x01, 0x01,
   95.49 +	  0x01, 0x01, 0x01, 0x01,
   95.50 +	  0x01, 0x01, 0x01, 0x01,
   95.51 +	  0xff, 0xff, 0xff, 0xff,
   95.52 +	  0xff, 0xff, 0xff, 0xff,
   95.53 +	  0xff, 0xff, 0xff, 0xff,
   95.54 +	  0xff, 0xff, 0xff, 0xff },
   95.55 +	{ 0x01, 0x01, 0x01, 0x01,
   95.56 +	  0x01, 0x01, 0x01, 0x01,
   95.57 +	  0x01, 0x01, 0x01, 0x01,
   95.58 +	  0x01, 0x01, 0x01, 0x01,
   95.59 +	  0x01, 0x01, 0x01, 0x01,
   95.60 +	  0x01, 0x01, 0x01, 0x01,
   95.61 +	  0xff, 0xff, 0xff, 0xff,
   95.62 +	  0xff, 0xff, 0xff, 0xff }
   95.63 +};
   95.64 +
   95.65 +int32 soundFreqRatio[8] = {
   95.66 +	1048576, // 0
   95.67 +	524288, // 1
   95.68 +	262144, // 2
   95.69 +	174763, // 3
   95.70 +	131072, // 4
   95.71 +	104858, // 5
   95.72 +	87381, // 6
   95.73 +	74898  // 7
   95.74 +};
   95.75 +
   95.76 +int32 soundShiftClock[16] = {
   95.77 +	2,   // 0
   95.78 +	4,   // 1
   95.79 +	8,   // 2
   95.80 +	16,  // 3
   95.81 +	32,  // 4
   95.82 +	64,  // 5
   95.83 +	128, // 6
   95.84 +	256, // 7
   95.85 +	512, // 8
   95.86 +	1024, // 9
   95.87 +	2048, // 10
   95.88 +	4096, // 11
   95.89 +	8192, // 12
   95.90 +	16384, // 13
   95.91 +	1,   // 14
   95.92 +	1    // 15
   95.93 +};
   95.94 +
   95.95 +int32 soundVolume = 0;
   95.96 +
   95.97 +u8	soundBuffer[6][735];
   95.98 +u16 soundFinalWave[1470];
   95.99 +u16 soundFrameSound[735 * 30 * 2]; // for avi logging
  95.100 +
  95.101 +u32			soundBufferLen		= 1470;
  95.102 +u32			soundBufferTotalLen = 14700;
  95.103 +int32		soundQuality		= 2;
  95.104 +int32		soundPaused			= 1;
  95.105 +int32		soundPlay			= 0;
  95.106 +soundtick_t soundTicks			= soundQuality * USE_TICKS_AS;
  95.107 +soundtick_t SOUND_CLOCK_TICKS	= soundQuality * USE_TICKS_AS;
  95.108 +u32			soundNextPosition	= 0;
  95.109 +
  95.110 +int32 soundLevel1 = 0;
  95.111 +int32 soundLevel2 = 0;
  95.112 +int32 soundBalance = 0;
  95.113 +int32 soundMasterOn = 0;
  95.114 +u32	  soundIndex = 0;
  95.115 +u32	  soundBufferIndex		 = 0;
  95.116 +int32 soundFrameSoundWritten = 0;
  95.117 +int32 soundDebug			 = 0;
  95.118 +bool8 soundOffFlag			 = false;
  95.119 +
  95.120 +int32 sound1On = 0;
  95.121 +int32 sound1ATL = 0;
  95.122 +int32 sound1Skip = 0;
  95.123 +int32 sound1Index = 0;
  95.124 +int32 sound1Continue = 0;
  95.125 +int32 sound1EnvelopeVolume	  = 0;
  95.126 +int32 sound1EnvelopeATL		  = 0;
  95.127 +int32 sound1EnvelopeUpDown	  = 0;
  95.128 +int32 sound1EnvelopeATLReload = 0;
  95.129 +int32 sound1SweepATL		  = 0;
  95.130 +int32 sound1SweepATLReload	  = 0;
  95.131 +int32 sound1SweepSteps		  = 0;
  95.132 +int32 sound1SweepUpDown		  = 0;
  95.133 +int32 sound1SweepStep		  = 0;
  95.134 +u8 *  sound1Wave			  = soundWavePattern[2];
  95.135 +
  95.136 +int32 sound2On = 0;
  95.137 +int32 sound2ATL = 0;
  95.138 +int32 sound2Skip = 0;
  95.139 +int32 sound2Index = 0;
  95.140 +int32 sound2Continue = 0;
  95.141 +int32 sound2EnvelopeVolume	  = 0;
  95.142 +int32 sound2EnvelopeATL		  = 0;
  95.143 +int32 sound2EnvelopeUpDown	  = 0;
  95.144 +int32 sound2EnvelopeATLReload = 0;
  95.145 +u8 *  sound2Wave			  = soundWavePattern[2];
  95.146 +
  95.147 +int32 sound3On = 0;
  95.148 +int32 sound3ATL			= 0;
  95.149 +int32 sound3Skip		= 0;
  95.150 +int32 sound3Index		= 0;
  95.151 +int32 sound3Continue	= 0;
  95.152 +int32 sound3OutputLevel = 0;
  95.153 +int32 sound3Last		= 0;
  95.154 +u8	  sound3WaveRam[0x20];
  95.155 +int32 sound3Bank		 = 0;
  95.156 +int32 sound3DataSize	 = 0;
  95.157 +int32 sound3ForcedOutput = 0;
  95.158 +
  95.159 +int32 sound4On = 0;
  95.160 +int32 sound4Clock = 0;
  95.161 +int32 sound4ATL = 0;
  95.162 +int32 sound4Skip = 0;
  95.163 +int32 sound4Index = 0;
  95.164 +int32 sound4ShiftRight		  = 0x7f;
  95.165 +int32 sound4ShiftSkip		  = 0;
  95.166 +int32 sound4ShiftIndex		  = 0;
  95.167 +int32 sound4NSteps			  = 0;
  95.168 +int32 sound4CountDown		  = 0;
  95.169 +int32 sound4Continue		  = 0;
  95.170 +int32 sound4EnvelopeVolume	  = 0;
  95.171 +int32 sound4EnvelopeATL		  = 0;
  95.172 +int32 sound4EnvelopeUpDown	  = 0;
  95.173 +int32 sound4EnvelopeATLReload = 0;
  95.174 +
  95.175 +int32 soundControl = 0;
  95.176 +
  95.177 +int32 soundDSFifoAIndex		 = 0;
  95.178 +int32 soundDSFifoACount		 = 0;
  95.179 +int32 soundDSFifoAWriteIndex = 0;
  95.180 +bool8 soundDSAEnabled		 = false;
  95.181 +int32 soundDSATimer = 0;
  95.182 +u8	  soundDSFifoA[32];
  95.183 +u8	  soundDSAValue = 0;
  95.184 +
  95.185 +int32 soundDSFifoBIndex		 = 0;
  95.186 +int32 soundDSFifoBCount		 = 0;
  95.187 +int32 soundDSFifoBWriteIndex = 0;
  95.188 +bool8 soundDSBEnabled		 = false;
  95.189 +int32 soundDSBTimer = 0;
  95.190 +u8	  soundDSFifoB[32];
  95.191 +u8	  soundDSBValue = 0;
  95.192 +
  95.193 +int32 soundEnableFlag = 0x3ff;
  95.194 +int32 soundMutedFlag  = 0;
  95.195 +
  95.196 +s16	  soundFilter[4000];
  95.197 +s16	  soundRight[5] = { 0, 0, 0, 0, 0 };
  95.198 +s16	  soundLeft[5] = { 0, 0, 0, 0, 0 };
  95.199 +int32 soundEchoIndex = 0;
  95.200 +bool8 soundEcho		 = false;
  95.201 +bool8 soundLowPass	 = false;
  95.202 +bool8 soundReverse	 = false;
  95.203 +
  95.204 +static int32  soundTicks_int32;
  95.205 +static int32  SOUND_CLOCK_TICKS_int32;
  95.206 +static int32  soundDSBValue_int32;
  95.207 +variable_desc soundSaveStruct[] = {
  95.208 +	{ &soundPaused,				sizeof(int32)					  },
  95.209 +	{ &soundPlay,				sizeof(int32)					  },
  95.210 +	{ &soundTicks_int32,		sizeof(int32)					  },
  95.211 +	{ &SOUND_CLOCK_TICKS_int32, sizeof(int32)					  },
  95.212 +	{ &soundLevel1,				sizeof(int32)					  },
  95.213 +	{ &soundLevel2,				sizeof(int32)					  },
  95.214 +	{ &soundBalance,			sizeof(int32)					  },
  95.215 +	{ &soundMasterOn,			sizeof(int32)					  },
  95.216 +	{ &soundIndex,				sizeof(int32)					  },
  95.217 +	{ &sound1On,				sizeof(int32)					  },
  95.218 +	{ &sound1ATL,				sizeof(int32)					  },
  95.219 +	{ &sound1Skip,				sizeof(int32)					  },
  95.220 +	{ &sound1Index,				sizeof(int32)					  },
  95.221 +	{ &sound1Continue,			sizeof(int32)					  },
  95.222 +	{ &sound1EnvelopeVolume,	sizeof(int32)					  },
  95.223 +	{ &sound1EnvelopeATL,		sizeof(int32)					  },
  95.224 +	{ &sound1EnvelopeATLReload, sizeof(int32)					  },
  95.225 +	{ &sound1EnvelopeUpDown,	sizeof(int32)					  },
  95.226 +	{ &sound1SweepATL,			sizeof(int32)					  },
  95.227 +	{ &sound1SweepATLReload,	sizeof(int32)					  },
  95.228 +	{ &sound1SweepSteps,		sizeof(int32)					  },
  95.229 +	{ &sound1SweepUpDown,		sizeof(int32)					  },
  95.230 +	{ &sound1SweepStep,			sizeof(int32)					  },
  95.231 +	{ &sound2On,				sizeof(int32)					  },
  95.232 +	{ &sound2ATL,				sizeof(int32)					  },
  95.233 +	{ &sound2Skip,				sizeof(int32)					  },
  95.234 +	{ &sound2Index,				sizeof(int32)					  },
  95.235 +	{ &sound2Continue,			sizeof(int32)					  },
  95.236 +	{ &sound2EnvelopeVolume,	sizeof(int32)					  },
  95.237 +	{ &sound2EnvelopeATL,		sizeof(int32)					  },
  95.238 +	{ &sound2EnvelopeATLReload, sizeof(int32)					  },
  95.239 +	{ &sound2EnvelopeUpDown,	sizeof(int32)					  },
  95.240 +	{ &sound3On,				sizeof(int32)					  },
  95.241 +	{ &sound3ATL,				sizeof(int32)					  },
  95.242 +	{ &sound3Skip,				sizeof(int32)					  },
  95.243 +	{ &sound3Index,				sizeof(int32)					  },
  95.244 +	{ &sound3Continue,			sizeof(int32)					  },
  95.245 +	{ &sound3OutputLevel,		sizeof(int32)					  },
  95.246 +	{ &sound4On,				sizeof(int32)					  },
  95.247 +	{ &sound4ATL,				sizeof(int32)					  },
  95.248 +	{ &sound4Skip,				sizeof(int32)					  },
  95.249 +	{ &sound4Index,				sizeof(int32)					  },
  95.250 +	{ &sound4Clock,				sizeof(int32)					  },
  95.251 +	{ &sound4ShiftRight,		sizeof(int32)					  },
  95.252 +	{ &sound4ShiftSkip,			sizeof(int32)					  },
  95.253 +	{ &sound4ShiftIndex,		sizeof(int32)					  },
  95.254 +	{ &sound4NSteps,			sizeof(int32)					  },
  95.255 +	{ &sound4CountDown,			sizeof(int32)					  },
  95.256 +	{ &sound4Continue,			sizeof(int32)					  },
  95.257 +	{ &sound4EnvelopeVolume,	sizeof(int32)					  },
  95.258 +	{ &sound4EnvelopeATL,		sizeof(int32)					  },
  95.259 +	{ &sound4EnvelopeATLReload, sizeof(int32)					  },
  95.260 +	{ &sound4EnvelopeUpDown,	sizeof(int32)					  },
  95.261 +	{ &soundEnableFlag,			sizeof(int32)					  },
  95.262 +	{ &soundControl,			sizeof(int32)					  },
  95.263 +	{ &soundDSFifoAIndex,		sizeof(int32)					  },
  95.264 +	{ &soundDSFifoACount,		sizeof(int32)					  },
  95.265 +	{ &soundDSFifoAWriteIndex,	sizeof(int32)					  },
  95.266 +	{ &soundDSAEnabled,			sizeof(bool8)					  },
  95.267 +	{ &soundDSATimer,			sizeof(int32)					  },
  95.268 +	{ &soundDSFifoA[0],			32								  },
  95.269 +	{ &soundDSAValue,			sizeof(u8)						  },
  95.270 +	{ &soundDSFifoBIndex,		sizeof(int32)					  },
  95.271 +	{ &soundDSFifoBCount,		sizeof(int32)					  },
  95.272 +	{ &soundDSFifoBWriteIndex,	sizeof(int32)					  },
  95.273 +	{ &soundDSBEnabled,			sizeof(int32)					  },
  95.274 +	{ &soundDSBTimer,			sizeof(int32)					  },
  95.275 +	{ &soundDSFifoB[0],			32								  },
  95.276 +	{ &soundDSBValue_int32,		sizeof(int32)					  }, // save as int32 because of a mistake of the past.
  95.277 +	{ &soundBuffer[0][0],		6 * 735							  },
  95.278 +	{ &soundFinalWave[0],		2 * 735							  },
  95.279 +	{ NULL,						0								  }
  95.280 +};
  95.281 +
  95.282 +variable_desc soundSaveStructV2[] = {
  95.283 +	{ &sound3WaveRam[0],   0x20							},
  95.284 +	{ &sound3Bank,		   sizeof(int32)				},
  95.285 +	{ &sound3DataSize,	   sizeof(int32)				},
  95.286 +	{ &sound3ForcedOutput, sizeof(int32)				},
  95.287 +	{ NULL,				   0							}
  95.288 +};
  95.289 +
  95.290 +//variable_desc soundSaveStructV3[] = {
  95.291 +//  { &soundTicks, sizeof(soundtick_t) },
  95.292 +//  { &SOUND_CLOCK_TICKS, sizeof(soundtick_t) },
  95.293 +//  { &USE_TICKS_AS, sizeof(soundtick_t) },
  95.294 +//  { NULL, 0 }
  95.295 +//};
  95.296 +
  95.297 +void soundEvent(u32 address, u8 data)
  95.298 +{
  95.299 +	int freq = 0;
  95.300 +
  95.301 +	switch (address)
  95.302 +	{
  95.303 +	case NR10:
  95.304 +		data &= 0x7f;
  95.305 +		sound1SweepATL	  = sound1SweepATLReload = 344 * ((data >> 4) & 7);
  95.306 +		sound1SweepSteps  = data & 7;
  95.307 +		sound1SweepUpDown = data & 0x08;
  95.308 +		sound1SweepStep	  = 0;
  95.309 +		ioMem[address]	  = data;
  95.310 +		break;
  95.311 +	case NR11:
  95.312 +		sound1Wave	   = soundWavePattern[data >> 6];
  95.313 +		sound1ATL	   = 172 * (64 - (data & 0x3f));
  95.314 +		ioMem[address] = data;
  95.315 +		break;
  95.316 +	case NR12:
  95.317 +		sound1EnvelopeUpDown	= data & 0x08;
  95.318 +		sound1EnvelopeATLReload = 689 * (data & 7);
  95.319 +		if ((data & 0xF8) == 0)
  95.320 +			sound1EnvelopeVolume = 0;
  95.321 +		ioMem[address] = data;
  95.322 +		break;
  95.323 +	case NR13:
  95.324 +		freq	  = (((int)(ioMem[NR14] & 7)) << 8) | data;
  95.325 +		sound1ATL = 172 * (64 - (ioMem[NR11] & 0x3f));
  95.326 +		freq	  = 2048 - freq;
  95.327 +		if (freq)
  95.328 +		{
  95.329 +			sound1Skip = SOUND_MAGIC / freq;
  95.330 +		}
  95.331 +		else
  95.332 +			sound1Skip = 0;
  95.333 +		ioMem[address] = data;
  95.334 +		break;
  95.335 +	case NR14:
  95.336 +		data &= 0xC7;
  95.337 +		freq = (((int)(data & 7) << 8) | ioMem[NR13]);
  95.338 +		freq = 2048 - freq;
  95.339 +		sound1ATL	   = 172 * (64 - (ioMem[NR11] & 0x3f));
  95.340 +		sound1Continue = data & 0x40;
  95.341 +		if (freq)
  95.342 +		{
  95.343 +			sound1Skip = SOUND_MAGIC / freq;
  95.344 +		}
  95.345 +		else
  95.346 +			sound1Skip = 0;
  95.347 +		if (data & 0x80)
  95.348 +		{
  95.349 +			ioMem[NR52] |= 1;
  95.350 +			sound1EnvelopeVolume = ioMem[NR12] >> 4;
  95.351 +			sound1EnvelopeUpDown = ioMem[NR12] & 0x08;
  95.352 +			sound1ATL = 172 * (64 - (ioMem[NR11] & 0x3f));
  95.353 +			sound1EnvelopeATLReload = sound1EnvelopeATL = 689 * (ioMem[NR12] & 7);
  95.354 +			sound1SweepATL			= sound1SweepATLReload = 344 * ((ioMem[NR10] >> 4) & 7);
  95.355 +			sound1SweepSteps		= ioMem[NR10] & 7;
  95.356 +			sound1SweepUpDown		= ioMem[NR10] & 0x08;
  95.357 +			sound1SweepStep			= 0;
  95.358 +
  95.359 +			sound1Index = 0;
  95.360 +			sound1On	= 1;
  95.361 +		}
  95.362 +		ioMem[address] = data;
  95.363 +		break;
  95.364 +	case NR21:
  95.365 +		sound2Wave	   = soundWavePattern[data >> 6];
  95.366 +		sound2ATL	   = 172 * (64 - (data & 0x3f));
  95.367 +		ioMem[address] = data;
  95.368 +		break;
  95.369 +	case NR22:
  95.370 +		sound2EnvelopeUpDown	= data & 0x08;
  95.371 +		sound2EnvelopeATLReload = 689 * (data & 7);
  95.372 +		if ((data & 0xF8) == 0)
  95.373 +			sound2EnvelopeVolume = 0;
  95.374 +		ioMem[address] = data;
  95.375 +		break;
  95.376 +	case NR23:
  95.377 +		freq	  = (((int)(ioMem[NR24] & 7)) << 8) | data;
  95.378 +		sound2ATL = 172 * (64 - (ioMem[NR21] & 0x3f));
  95.379 +		freq	  = 2048 - freq;
  95.380 +		if (freq)
  95.381 +		{
  95.382 +			sound2Skip = SOUND_MAGIC / freq;
  95.383 +		}
  95.384 +		else
  95.385 +			sound2Skip = 0;
  95.386 +		ioMem[address] = data;
  95.387 +		break;
  95.388 +	case NR24:
  95.389 +		data &= 0xC7;
  95.390 +		freq = (((int)(data & 7) << 8) | ioMem[NR23]);
  95.391 +		freq = 2048 - freq;
  95.392 +		sound2ATL	   = 172 * (64 - (ioMem[NR21] & 0x3f));
  95.393 +		sound2Continue = data & 0x40;
  95.394 +		if (freq)
  95.395 +		{
  95.396 +			sound2Skip = SOUND_MAGIC / freq;
  95.397 +		}
  95.398 +		else
  95.399 +			sound2Skip = 0;
  95.400 +		if (data & 0x80)
  95.401 +		{
  95.402 +			ioMem[NR52] |= 2;
  95.403 +			sound2EnvelopeVolume = ioMem[NR22] >> 4;
  95.404 +			sound2EnvelopeUpDown = ioMem[NR22] & 0x08;
  95.405 +			sound2ATL = 172 * (64 - (ioMem[NR21] & 0x3f));
  95.406 +			sound2EnvelopeATLReload = sound2EnvelopeATL = 689 * (ioMem[NR22] & 7);
  95.407 +
  95.408 +			sound2Index = 0;
  95.409 +			sound2On	= 1;
  95.410 +		}
  95.411 +		ioMem[address] = data;
  95.412 +		break;
  95.413 +	case NR30:
  95.414 +		data &= 0xe0;
  95.415 +		if (!(data & 0x80))
  95.416 +		{
  95.417 +			ioMem[NR52] &= 0xfb;
  95.418 +			sound3On	 = 0;
  95.419 +		}
  95.420 +		if (((data >> 6) & 1) != sound3Bank)
  95.421 +			memcpy(&ioMem[0x90], &sound3WaveRam[(((data >> 6) & 1) * 0x10) ^ 0x10],
  95.422 +			       0x10);
  95.423 +		sound3Bank	   = (data >> 6) & 1;
  95.424 +		sound3DataSize = (data >> 5) & 1;
  95.425 +		ioMem[address] = data;
  95.426 +		break;
  95.427 +	case NR31:
  95.428 +		sound3ATL	   = 172 * (256 - data);
  95.429 +		ioMem[address] = data;
  95.430 +		break;
  95.431 +	case NR32:
  95.432 +		data &= 0xe0;
  95.433 +		sound3OutputLevel  = (data >> 5) & 3;
  95.434 +		sound3ForcedOutput = (data >> 7) & 1;
  95.435 +		ioMem[address]	   = data;
  95.436 +		break;
  95.437 +	case NR33:
  95.438 +		freq = 2048 - (((int)(ioMem[NR34] & 7) << 8) | data);
  95.439 +		if (freq)
  95.440 +		{
  95.441 +			sound3Skip = SOUND_MAGIC_2 / freq;
  95.442 +		}
  95.443 +		else
  95.444 +			sound3Skip = 0;
  95.445 +		ioMem[address] = data;
  95.446 +		break;
  95.447 +	case NR34:
  95.448 +		data &= 0xc7;
  95.449 +		freq  = 2048 - (((data & 7) << 8) | (int)ioMem[NR33]);
  95.450 +		if (freq)
  95.451 +		{
  95.452 +			sound3Skip = SOUND_MAGIC_2 / freq;
  95.453 +		}
  95.454 +		else
  95.455 +		{
  95.456 +			sound3Skip = 0;
  95.457 +		}
  95.458 +		sound3Continue = data & 0x40;
  95.459 +		if ((data & 0x80) && (ioMem[NR30] & 0x80))
  95.460 +		{
  95.461 +			ioMem[NR52] |= 4;
  95.462 +			sound3ATL	 = 172 * (256 - ioMem[NR31]);
  95.463 +			sound3Index	 = 0;
  95.464 +			sound3On	 = 1;
  95.465 +		}
  95.466 +		ioMem[address] = data;
  95.467 +		break;
  95.468 +	case NR41:
  95.469 +		data &= 0x3f;
  95.470 +		sound4ATL	   = 172 * (64 - (data & 0x3f));
  95.471 +		ioMem[address] = data;
  95.472 +		break;
  95.473 +	case NR42:
  95.474 +		sound4EnvelopeUpDown	= data & 0x08;
  95.475 +		sound4EnvelopeATLReload = 689 * (data & 7);
  95.476 +		if ((data & 0xF8) == 0)
  95.477 +			sound4EnvelopeVolume = 0;
  95.478 +		ioMem[address] = data;
  95.479 +		break;
  95.480 +	case NR43:
  95.481 +		freq		 = soundFreqRatio[data & 7];
  95.482 +		sound4NSteps = data & 0x08;
  95.483 +
  95.484 +		sound4Skip = freq * NOISE_MAGIC;
  95.485 +
  95.486 +		sound4Clock = data >> 4;
  95.487 +
  95.488 +		freq = freq / soundShiftClock[sound4Clock];
  95.489 +
  95.490 +		sound4ShiftSkip = freq * NOISE_MAGIC;
  95.491 +		ioMem[address]	= data;
  95.492 +		break;
  95.493 +	case NR44:
  95.494 +		data &= 0xc0;
  95.495 +		sound4Continue = data & 0x40;
  95.496 +		if (data & 0x80)
  95.497 +		{
  95.498 +			ioMem[NR52] |= 8;
  95.499 +			sound4EnvelopeVolume = ioMem[NR42] >> 4;
  95.500 +			sound4EnvelopeUpDown = ioMem[NR42] & 0x08;
  95.501 +			sound4ATL = 172 * (64 - (ioMem[NR41] & 0x3f));
  95.502 +			sound4EnvelopeATLReload = sound4EnvelopeATL = 689 * (ioMem[NR42] & 7);
  95.503 +
  95.504 +			sound4On = 1;
  95.505 +
  95.506 +			sound4Index		 = 0;
  95.507 +			sound4ShiftIndex = 0;
  95.508 +
  95.509 +			freq = soundFreqRatio[ioMem[NR43] & 7];
  95.510 +
  95.511 +			sound4Skip = freq * NOISE_MAGIC;
  95.512 +
  95.513 +			sound4NSteps = ioMem[NR43] & 0x08;
  95.514 +
  95.515 +			freq = freq / soundShiftClock[ioMem[NR43] >> 4];
  95.516 +
  95.517 +			sound4ShiftSkip = freq * NOISE_MAGIC;
  95.518 +			if (sound4NSteps)
  95.519 +				sound4ShiftRight = 0x7f;
  95.520 +			else
  95.521 +				sound4ShiftRight = 0x7fff;
  95.522 +		}
  95.523 +		ioMem[address] = data;
  95.524 +		break;
  95.525 +	case NR50:
  95.526 +		data &= 0x77;
  95.527 +		soundLevel1	   = data & 7;
  95.528 +		soundLevel2	   = (data >> 4) & 7;
  95.529 +		ioMem[address] = data;
  95.530 +		break;
  95.531 +	case NR51:
  95.532 +		soundBalance   = (data & soundEnableFlag);
  95.533 +		ioMem[address] = data;
  95.534 +		break;
  95.535 +	case NR52:
  95.536 +		data &= 0x80;
  95.537 +		data |= ioMem[NR52] & 15;
  95.538 +		soundMasterOn = data & 0x80;
  95.539 +		if (!(data & 0x80))
  95.540 +		{
  95.541 +			sound1On = 0;
  95.542 +			sound2On = 0;
  95.543 +			sound3On = 0;
  95.544 +			sound4On = 0;
  95.545 +		}
  95.546 +		ioMem[address] = data;
  95.547 +		break;
  95.548 +	case 0x90:
  95.549 +	case 0x91:
  95.550 +	case 0x92:
  95.551 +	case 0x93:
  95.552 +	case 0x94:
  95.553 +	case 0x95:
  95.554 +	case 0x96:
  95.555 +	case 0x97:
  95.556 +	case 0x98:
  95.557 +	case 0x99:
  95.558 +	case 0x9a:
  95.559 +	case 0x9b:
  95.560 +	case 0x9c:
  95.561 +	case 0x9d:
  95.562 +	case 0x9e:
  95.563 +	case 0x9f:
  95.564 +		sound3WaveRam[(sound3Bank * 0x10) ^ 0x10 + (address & 15)] = data;
  95.565 +		break;
  95.566 +	}
  95.567 +}
  95.568 +
  95.569 +void soundEvent(u32 address, u16 data)
  95.570 +{
  95.571 +	switch (address)
  95.572 +	{
  95.573 +	case SGCNT0_H:
  95.574 +		data		&= 0xFF0F;
  95.575 +		soundControl = data & 0x770F;;
  95.576 +		if (data & 0x0800)
  95.577 +		{
  95.578 +			soundDSFifoAWriteIndex = 0;
  95.579 +			soundDSFifoAIndex	   = 0;
  95.580 +			soundDSFifoACount	   = 0;
  95.581 +			soundDSAValue = 0;
  95.582 +			memset(soundDSFifoA, 0, 32);
  95.583 +		}
  95.584 +		soundDSAEnabled = (data & 0x0300) ? true : false;
  95.585 +		soundDSATimer	= (data & 0x0400) ? 1 : 0;
  95.586 +		if (data & 0x8000)
  95.587 +		{
  95.588 +			soundDSFifoBWriteIndex = 0;
  95.589 +			soundDSFifoBIndex	   = 0;
  95.590 +			soundDSFifoBCount	   = 0;
  95.591 +			soundDSBValue = 0;
  95.592 +			memset(soundDSFifoB, 0, 32);
  95.593 +		}
  95.594 +		soundDSBEnabled = (data & 0x3000) ? true : false;
  95.595 +		soundDSBTimer	= (data & 0x4000) ? 1 : 0;
  95.596 +		*((u16 *)&ioMem[address]) = data;
  95.597 +		break;
  95.598 +	case FIFOA_L:
  95.599 +	case FIFOA_H:
  95.600 +		soundDSFifoA[soundDSFifoAWriteIndex++] = data & 0xFF;
  95.601 +		soundDSFifoA[soundDSFifoAWriteIndex++] = data >> 8;
  95.602 +		soundDSFifoACount		 += 2;
  95.603 +		soundDSFifoAWriteIndex	 &= 31;
  95.604 +		*((u16 *)&ioMem[address]) = data;
  95.605 +		break;
  95.606 +	case FIFOB_L:
  95.607 +	case FIFOB_H:
  95.608 +		soundDSFifoB[soundDSFifoBWriteIndex++] = data & 0xFF;
  95.609 +		soundDSFifoB[soundDSFifoBWriteIndex++] = data >> 8;
  95.610 +		soundDSFifoBCount		 += 2;
  95.611 +		soundDSFifoBWriteIndex	 &= 31;
  95.612 +		*((u16 *)&ioMem[address]) = data;
  95.613 +		break;
  95.614 +	case 0x88:
  95.615 +		data &= 0xC3FF;
  95.616 +		*((u16 *)&ioMem[address]) = data;
  95.617 +		break;
  95.618 +	case 0x90:
  95.619 +	case 0x92:
  95.620 +	case 0x94:
  95.621 +	case 0x96:
  95.622 +	case 0x98:
  95.623 +	case 0x9a:
  95.624 +	case 0x9c:
  95.625 +	case 0x9e:
  95.626 +		*((u16 *)&sound3WaveRam[(sound3Bank * 0x10) ^ 0x10 + (address & 14)]) = data;
  95.627 +		*((u16 *)&ioMem[address]) = data;
  95.628 +		break;
  95.629 +	}
  95.630 +}
  95.631 +
  95.632 +void soundChannel1()
  95.633 +{
  95.634 +	int vol = sound1EnvelopeVolume;
  95.635 +
  95.636 +	int freq  = 0;
  95.637 +	int value = 0;
  95.638 +
  95.639 +	if (sound1On && (sound1ATL || !sound1Continue))
  95.640 +	{
  95.641 +		sound1Index += soundQuality * sound1Skip;
  95.642 +		sound1Index &= 0x1fffffff;
  95.643 +
  95.644 +		value = ((s8)sound1Wave[sound1Index >> 24]) * vol;
  95.645 +	}
  95.646 +
  95.647 +	soundBuffer[0][soundIndex] = value;
  95.648 +
  95.649 +	if (sound1On)
  95.650 +	{
  95.651 +		if (sound1ATL)
  95.652 +		{
  95.653 +			sound1ATL -= soundQuality;
  95.654 +
  95.655 +			if (sound1ATL <= 0 && sound1Continue)
  95.656 +			{
  95.657 +				ioMem[NR52] &= 0xfe;
  95.658 +				sound1On	 = 0;
  95.659 +			}
  95.660 +		}
  95.661 +
  95.662 +		if (sound1EnvelopeATL)
  95.663 +		{
  95.664 +			sound1EnvelopeATL -= soundQuality;
  95.665 +
  95.666 +			if (sound1EnvelopeATL <= 0)
  95.667 +			{
  95.668 +				if (sound1EnvelopeUpDown)
  95.669 +				{
  95.670 +					if (sound1EnvelopeVolume < 15)
  95.671 +						sound1EnvelopeVolume++;
  95.672 +				}
  95.673 +				else
  95.674 +				{
  95.675 +					if (sound1EnvelopeVolume)
  95.676 +						sound1EnvelopeVolume--;
  95.677 +				}
  95.678 +
  95.679 +				sound1EnvelopeATL += sound1EnvelopeATLReload;
  95.680 +			}
  95.681 +		}
  95.682 +
  95.683 +		if (sound1SweepATL)
  95.684 +		{
  95.685 +			sound1SweepATL -= soundQuality;
  95.686 +
  95.687 +			if (sound1SweepATL <= 0)
  95.688 +			{
  95.689 +				freq = (((int)(ioMem[NR14] & 7) << 8) | ioMem[NR13]);
  95.690 +
  95.691 +				int updown = 1;
  95.692 +
  95.693 +				if (sound1SweepUpDown)
  95.694 +					updown = -1;
  95.695 +
  95.696 +				int newfreq = 0;
  95.697 +				if (sound1SweepSteps)
  95.698 +				{
  95.699 +					newfreq = freq + updown * freq / (1 << sound1SweepSteps);
  95.700 +					if (newfreq == freq)
  95.701 +						newfreq = 0;
  95.702 +				}
  95.703 +				else
  95.704 +					newfreq = freq;
  95.705 +
  95.706 +				if (newfreq < 0)
  95.707 +				{
  95.708 +					sound1SweepATL += sound1SweepATLReload;
  95.709 +				}
  95.710 +				else if (newfreq > 2047)
  95.711 +				{
  95.712 +					sound1SweepATL = 0;
  95.713 +					sound1On	   = 0;
  95.714 +					ioMem[NR52]	  &= 0xfe;
  95.715 +				}
  95.716 +				else
  95.717 +				{
  95.718 +					sound1SweepATL += sound1SweepATLReload;
  95.719 +					sound1Skip		= SOUND_MAGIC / (2048 - newfreq);
  95.720 +
  95.721 +					ioMem[NR13] = newfreq & 0xff;
  95.722 +					ioMem[NR14] = (ioMem[NR14] & 0xf8) | ((newfreq >> 8) & 7);
  95.723 +				}
  95.724 +			}
  95.725 +		}
  95.726 +	}
  95.727 +}
  95.728 +
  95.729 +void soundChannel2()
  95.730 +{
  95.731 +	//  int freq = 0;
  95.732 +	int vol = sound2EnvelopeVolume;
  95.733 +
  95.734 +	int value = 0;
  95.735 +
  95.736 +	if (sound2On && (sound2ATL || !sound2Continue))
  95.737 +	{
  95.738 +		sound2Index += soundQuality * sound2Skip;
  95.739 +		sound2Index &= 0x1fffffff;
  95.740 +
  95.741 +		value = ((s8)sound2Wave[sound2Index >> 24]) * vol;
  95.742 +	}
  95.743 +
  95.744 +	soundBuffer[1][soundIndex] = value;
  95.745 +
  95.746 +	if (sound2On)
  95.747 +	{
  95.748 +		if (sound2ATL)
  95.749 +		{
  95.750 +			sound2ATL -= soundQuality;
  95.751 +
  95.752 +			if (sound2ATL <= 0 && sound2Continue)
  95.753 +			{
  95.754 +				ioMem[NR52] &= 0xfd;
  95.755 +				sound2On	 = 0;
  95.756 +			}
  95.757 +		}
  95.758 +
  95.759 +		if (sound2EnvelopeATL)
  95.760 +		{
  95.761 +			sound2EnvelopeATL -= soundQuality;
  95.762 +
  95.763 +			if (sound2EnvelopeATL <= 0)
  95.764 +			{
  95.765 +				if (sound2EnvelopeUpDown)
  95.766 +				{
  95.767 +					if (sound2EnvelopeVolume < 15)
  95.768 +						sound2EnvelopeVolume++;
  95.769 +				}
  95.770 +				else
  95.771 +				{
  95.772 +					if (sound2EnvelopeVolume)
  95.773 +						sound2EnvelopeVolume--;
  95.774 +				}
  95.775 +				sound2EnvelopeATL += sound2EnvelopeATLReload;
  95.776 +			}
  95.777 +		}
  95.778 +	}
  95.779 +}
  95.780 +
  95.781 +void soundChannel3()
  95.782 +{
  95.783 +	int value = sound3Last;
  95.784 +
  95.785 +	if (sound3On && (sound3ATL || !sound3Continue))
  95.786 +	{
  95.787 +		sound3Index += soundQuality * sound3Skip;
  95.788 +		if (sound3DataSize)
  95.789 +		{
  95.790 +			sound3Index &= 0x3fffffff;
  95.791 +			value		 = sound3WaveRam[sound3Index >> 25];
  95.792 +		}
  95.793 +		else
  95.794 +		{
  95.795 +			sound3Index &= 0x1fffffff;
  95.796 +			value		 = sound3WaveRam[sound3Bank * 0x10 + (sound3Index >> 25)];
  95.797 +		}
  95.798 +
  95.799 +		if ((sound3Index & 0x01000000))
  95.800 +		{
  95.801 +			value &= 0x0f;
  95.802 +		}
  95.803 +		else
  95.804 +		{
  95.805 +			value >>= 4;
  95.806 +		}
  95.807 +
  95.808 +		value -= 8;
  95.809 +		value *= 2;
  95.810 +
  95.811 +		if (sound3ForcedOutput)
  95.812 +		{
  95.813 +			value = ((value >> 1) + value) >> 1;
  95.814 +		}
  95.815 +		else
  95.816 +		{
  95.817 +			switch (sound3OutputLevel)
  95.818 +			{
  95.819 +			case 0:
  95.820 +				value = 0;
  95.821 +				break;
  95.822 +			case 1:
  95.823 +				break;
  95.824 +			case 2:
  95.825 +				value = (value >> 1);
  95.826 +				break;
  95.827 +			case 3:
  95.828 +				value = (value >> 2);
  95.829 +				break;
  95.830 +			}
  95.831 +		}
  95.832 +		//value += 1;
  95.833 +		sound3Last = value;
  95.834 +	}
  95.835 +
  95.836 +	soundBuffer[2][soundIndex] = value;
  95.837 +
  95.838 +	if (sound3On)
  95.839 +	{
  95.840 +		if (sound3ATL)
  95.841 +		{
  95.842 +			sound3ATL -= soundQuality;
  95.843 +
  95.844 +			if (sound3ATL <= 0 && sound3Continue)
  95.845 +			{
  95.846 +				ioMem[NR52] &= 0xfb;
  95.847 +				sound3On	 = 0;
  95.848 +			}
  95.849 +		}
  95.850 +	}
  95.851 +}
  95.852 +
  95.853 +void soundChannel4()
  95.854 +{
  95.855 +	int vol = sound4EnvelopeVolume;
  95.856 +
  95.857 +	int value = 0;
  95.858 +
  95.859 +	if (sound4Clock <= 0x0c)
  95.860 +	{
  95.861 +		if (sound4On && (sound4ATL || !sound4Continue))
  95.862 +		{
  95.863 +	  #define NOISE_ONE_SAMP_SCALE  0x200000
  95.864 +
  95.865 +			sound4Index		 += soundQuality * sound4Skip;
  95.866 +			sound4ShiftIndex += soundQuality * sound4ShiftSkip;
  95.867 +
  95.868 +			if (sound4NSteps)
  95.869 +			{
  95.870 +				while (sound4ShiftIndex >= NOISE_ONE_SAMP_SCALE)
  95.871 +				{
  95.872 +					sound4ShiftRight = (((sound4ShiftRight << 6) ^
  95.873 +					                     (sound4ShiftRight << 5)) & 0x40) |
  95.874 +					                   (sound4ShiftRight >> 1);
  95.875 +					sound4ShiftIndex -= NOISE_ONE_SAMP_SCALE;
  95.876 +				}
  95.877 +			}
  95.878 +			else
  95.879 +			{
  95.880 +				while (sound4ShiftIndex >= NOISE_ONE_SAMP_SCALE)
  95.881 +				{
  95.882 +					sound4ShiftRight = (((sound4ShiftRight << 14) ^
  95.883 +					                     (sound4ShiftRight << 13)) & 0x4000) |
  95.884 +					                   (sound4ShiftRight >> 1);
  95.885 +
  95.886 +					sound4ShiftIndex -= NOISE_ONE_SAMP_SCALE;
  95.887 +				}
  95.888 +			}
  95.889 +
  95.890 +			sound4Index		 %= NOISE_ONE_SAMP_SCALE;
  95.891 +			sound4ShiftIndex %= NOISE_ONE_SAMP_SCALE;
  95.892 +
  95.893 +			value = ((sound4ShiftRight & 1) * 2 - 1) * vol;
  95.894 +		}
  95.895 +		else
  95.896 +		{
  95.897 +			value = 0;
  95.898 +		}
  95.899 +	}
  95.900 +
  95.901 +	soundBuffer[3][soundIndex] = value;
  95.902 +
  95.903 +	if (sound4On)
  95.904 +	{
  95.905 +		if (sound4ATL)
  95.906 +		{
  95.907 +			sound4ATL -= soundQuality;
  95.908 +
  95.909 +			if (sound4ATL <= 0 && sound4Continue)
  95.910 +			{
  95.911 +				ioMem[NR52] &= 0xfd;
  95.912 +				sound4On	 = 0;
  95.913 +			}
  95.914 +		}
  95.915 +
  95.916 +		if (sound4EnvelopeATL)
  95.917 +		{
  95.918 +			sound4EnvelopeATL -= soundQuality;
  95.919 +
  95.920 +			if (sound4EnvelopeATL <= 0)
  95.921 +			{
  95.922 +				if (sound4EnvelopeUpDown)
  95.923 +				{
  95.924 +					if (sound4EnvelopeVolume < 15)
  95.925 +						sound4EnvelopeVolume++;
  95.926 +				}
  95.927 +				else
  95.928 +				{
  95.929 +					if (sound4EnvelopeVolume)
  95.930 +						sound4EnvelopeVolume--;
  95.931 +				}
  95.932 +				sound4EnvelopeATL += sound4EnvelopeATLReload;
  95.933 +			}
  95.934 +		}
  95.935 +	}
  95.936 +}
  95.937 +
  95.938 +void soundDirectSoundA()
  95.939 +{
  95.940 +	soundBuffer[4][soundIndex] = soundDSAValue;
  95.941 +}
  95.942 +
  95.943 +void soundDirectSoundATimer()
  95.944 +{
  95.945 +	if (soundDSAEnabled)
  95.946 +	{
  95.947 +		if (soundDSFifoACount <= 16)
  95.948 +		{
  95.949 +			CPUCheckDMA(3, 2);
  95.950 +			if (soundDSFifoACount <= 16)
  95.951 +			{
  95.952 +				soundEvent(FIFOA_L, (u16)0);
  95.953 +				soundEvent(FIFOA_H, (u16)0);
  95.954 +				soundEvent(FIFOA_L, (u16)0);
  95.955 +				soundEvent(FIFOA_H, (u16)0);
  95.956 +				soundEvent(FIFOA_L, (u16)0);
  95.957 +				soundEvent(FIFOA_H, (u16)0);
  95.958 +				soundEvent(FIFOA_L, (u16)0);
  95.959 +				soundEvent(FIFOA_H, (u16)0);
  95.960 +			}
  95.961 +		}
  95.962 +
  95.963 +		soundDSAValue	  = (soundDSFifoA[soundDSFifoAIndex]);
  95.964 +		soundDSFifoAIndex = (++soundDSFifoAIndex) & 31;
  95.965 +		soundDSFifoACount--;
  95.966 +	}
  95.967 +	else
  95.968 +		soundDSAValue = 0;
  95.969 +}
  95.970 +
  95.971 +void soundDirectSoundB()
  95.972 +{
  95.973 +	soundBuffer[5][soundIndex] = soundDSBValue;
  95.974 +}
  95.975 +
  95.976 +void soundDirectSoundBTimer()
  95.977 +{
  95.978 +	if (soundDSBEnabled)
  95.979 +	{
  95.980 +		if (soundDSFifoBCount <= 16)
  95.981 +		{
  95.982 +			CPUCheckDMA(3, 4);
  95.983 +			if (soundDSFifoBCount <= 16)
  95.984 +			{
  95.985 +				soundEvent(FIFOB_L, (u16)0);
  95.986 +				soundEvent(FIFOB_H, (u16)0);
  95.987 +				soundEvent(FIFOB_L, (u16)0);
  95.988 +				soundEvent(FIFOB_H, (u16)0);
  95.989 +				soundEvent(FIFOB_L, (u16)0);
  95.990 +				soundEvent(FIFOB_H, (u16)0);
  95.991 +				soundEvent(FIFOB_L, (u16)0);
  95.992 +				soundEvent(FIFOB_H, (u16)0);
  95.993 +			}
  95.994 +		}
  95.995 +
  95.996 +		soundDSBValue	  = (soundDSFifoB[soundDSFifoBIndex]);
  95.997 +		soundDSFifoBIndex = (++soundDSFifoBIndex) & 31;
  95.998 +		soundDSFifoBCount--;
  95.999 +	}
 95.1000 +	else
 95.1001 +	{
 95.1002 +		soundDSBValue = 0;
 95.1003 +	}
 95.1004 +}
 95.1005 +
 95.1006 +void soundTimerOverflow(int timer)
 95.1007 +{
 95.1008 +	if (soundDSAEnabled && (soundDSATimer == timer))
 95.1009 +	{
 95.1010 +		soundDirectSoundATimer();
 95.1011 +	}
 95.1012 +	if (soundDSBEnabled && (soundDSBTimer == timer))
 95.1013 +	{
 95.1014 +		soundDirectSoundBTimer();
 95.1015 +	}
 95.1016 +}
 95.1017 +
 95.1018 +void soundMix()
 95.1019 +{
 95.1020 +	int res		 = 0;
 95.1021 +	int cgbRes	 = 0;
 95.1022 +	int ratio	 = ioMem[0x82] & 3;
 95.1023 +	int dsaRatio = ioMem[0x82] & 4;
 95.1024 +	int dsbRatio = ioMem[0x82] & 8;
 95.1025 +
 95.1026 +	if (ioMem)
 95.1027 +		soundBalance = (ioMem[NR51] & soundEnableFlag & ~soundMutedFlag);
 95.1028 +
 95.1029 +	if (soundBalance & 16)
 95.1030 +	{
 95.1031 +		cgbRes = ((s8)soundBuffer[0][soundIndex]);
 95.1032 +	}
 95.1033 +	if (soundBalance & 32)
 95.1034 +	{
 95.1035 +		cgbRes += ((s8)soundBuffer[1][soundIndex]);
 95.1036 +	}
 95.1037 +	if (soundBalance & 64)
 95.1038 +	{
 95.1039 +		cgbRes += ((s8)soundBuffer[2][soundIndex]);
 95.1040 +	}
 95.1041 +	if (soundBalance & 128)
 95.1042 +	{
 95.1043 +		cgbRes += ((s8)soundBuffer[3][soundIndex]);
 95.1044 +	}
 95.1045 +
 95.1046 +	if ((soundControl & 0x0200) && (soundEnableFlag & 0x100))
 95.1047 +	{
 95.1048 +		if (!dsaRatio)
 95.1049 +			res = ((s8)soundBuffer[4][soundIndex]) >> 1;
 95.1050 +		else
 95.1051 +			res = ((s8)soundBuffer[4][soundIndex]);
 95.1052 +	}
 95.1053 +
 95.1054 +	if ((soundControl & 0x2000) && (soundEnableFlag & 0x200))
 95.1055 +	{
 95.1056 +		if (!dsbRatio)
 95.1057 +			res += ((s8)soundBuffer[5][soundIndex]) >> 1;
 95.1058 +		else
 95.1059 +			res += ((s8)soundBuffer[5][soundIndex]);
 95.1060 +	}
 95.1061 +
 95.1062 +	res	   = (res * 170);
 95.1063 +	cgbRes = (cgbRes * 52 * soundLevel1);
 95.1064 +
 95.1065 +	switch (ratio)
 95.1066 +	{
 95.1067 +	case 0:
 95.1068 +	case 3: // prohibited, but 25%
 95.1069 +		cgbRes >>= 2;
 95.1070 +		break;
 95.1071 +	case 1:
 95.1072 +		cgbRes >>= 1;
 95.1073 +		break;
 95.1074 +	case 2:
 95.1075 +		break;
 95.1076 +	}
 95.1077 +
 95.1078 +	res += cgbRes;
 95.1079 +
 95.1080 +	if (soundEcho)
 95.1081 +	{
 95.1082 +		res *= 2;
 95.1083 +		res += soundFilter[soundEchoIndex];
 95.1084 +		res /= 2;
 95.1085 +		soundFilter[soundEchoIndex++] = res;
 95.1086 +	}
 95.1087 +
 95.1088 +	if (soundLowPass)
 95.1089 +	{
 95.1090 +		soundLeft[4] = soundLeft[3];
 95.1091 +		soundLeft[3] = soundLeft[2];
 95.1092 +		soundLeft[2] = soundLeft[1];
 95.1093 +		soundLeft[1] = soundLeft[0];
 95.1094 +		soundLeft[0] = res;
 95.1095 +		res = (soundLeft[4] + 2 * soundLeft[3] + 8 * soundLeft[2] + 2 * soundLeft[1] +
 95.1096 +		       soundLeft[0]) / 14;
 95.1097 +	}
 95.1098 +
 95.1099 +	bool noSpecialEffects = false;
 95.1100 +#if (defined(WIN32) && !defined(SDL))
 95.1101 +	if (theApp.soundRecording || theApp.aviRecording || theApp.nvAudioLog)
 95.1102 +		noSpecialEffects = true;
 95.1103 +#endif
 95.1104 +
 95.1105 +	if (!noSpecialEffects)
 95.1106 +	{
 95.1107 +		switch (soundVolume)
 95.1108 +		{
 95.1109 +		case 0:
 95.1110 +		case 1:
 95.1111 +		case 2:
 95.1112 +		case 3:
 95.1113 +			res *= (soundVolume + 1);
 95.1114 +			break;
 95.1115 +		case 4:
 95.1116 +			res >>= 2;
 95.1117 +			break;
 95.1118 +		case 5:
 95.1119 +			res >>= 1;
 95.1120 +			break;
 95.1121 +		}
 95.1122 +	}
 95.1123 +
 95.1124 +	if (res > 32767)
 95.1125 +		res = 32767;
 95.1126 +	if (res < -32768)
 95.1127 +		res = -32768;
 95.1128 +
 95.1129 +	if (soundReverse && !noSpecialEffects)
 95.1130 +	{
 95.1131 +		soundFinalWave[++soundBufferIndex] = res;
 95.1132 +		if ((soundFrameSoundWritten + 1) >= countof(soundFrameSound))
 95.1133 +			/*assert(false)*/;
 95.1134 +		else
 95.1135 +			soundFrameSound[++soundFrameSoundWritten] = res;
 95.1136 +	}
 95.1137 +	else
 95.1138 +	{
 95.1139 +		soundFinalWave[soundBufferIndex++] = res;
 95.1140 +		if (soundFrameSoundWritten >= countof(soundFrameSound))
 95.1141 +			/*assert(false)*/;
 95.1142 +		else
 95.1143 +			soundFrameSound[soundFrameSoundWritten++] = res;
 95.1144 +	}
 95.1145 +
 95.1146 +	res	   = 0;
 95.1147 +	cgbRes = 0;
 95.1148 +
 95.1149 +	if (soundBalance & 1)
 95.1150 +	{
 95.1151 +		cgbRes = ((s8)soundBuffer[0][soundIndex]);
 95.1152 +	}
 95.1153 +	if (soundBalance & 2)
 95.1154 +	{
 95.1155 +		cgbRes += ((s8)soundBuffer[1][soundIndex]);
 95.1156 +	}
 95.1157 +	if (soundBalance & 4)
 95.1158 +	{
 95.1159 +		cgbRes += ((s8)soundBuffer[2][soundIndex]);
 95.1160 +	}
 95.1161 +	if (soundBalance & 8)
 95.1162 +	{
 95.1163 +		cgbRes += ((s8)soundBuffer[3][soundIndex]);
 95.1164 +	}
 95.1165 +
 95.1166 +	if ((soundControl & 0x0100) && (soundEnableFlag & 0x100))
 95.1167 +	{
 95.1168 +		if (!dsaRatio)
 95.1169 +			res = ((s8)soundBuffer[4][soundIndex]) >> 1;
 95.1170 +		else
 95.1171 +			res = ((s8)soundBuffer[4][soundIndex]);
 95.1172 +	}
 95.1173 +
 95.1174 +	if ((soundControl & 0x1000) && (soundEnableFlag & 0x200))
 95.1175 +	{
 95.1176 +		if (!dsbRatio)
 95.1177 +			res += ((s8)soundBuffer[5][soundIndex]) >> 1;
 95.1178 +		else
 95.1179 +			res += ((s8)soundBuffer[5][soundIndex]);
 95.1180 +	}
 95.1181 +
 95.1182 +	res	   = (res * 170);
 95.1183 +	cgbRes = (cgbRes * 52 * soundLevel1);
 95.1184 +
 95.1185 +	switch (ratio)
 95.1186 +	{
 95.1187 +	case 0:
 95.1188 +	case 3: // prohibited, but 25%
 95.1189 +		cgbRes >>= 2;
 95.1190 +		break;
 95.1191 +	case 1:
 95.1192 +		cgbRes >>= 1;
 95.1193 +		break;
 95.1194 +	case 2:
 95.1195 +		break;
 95.1196 +	}
 95.1197 +
 95.1198 +	res += cgbRes;
 95.1199 +
 95.1200 +	if (soundEcho)
 95.1201 +	{
 95.1202 +		res *= 2;
 95.1203 +		res += soundFilter[soundEchoIndex];
 95.1204 +		res /= 2;
 95.1205 +		soundFilter[soundEchoIndex++] = res;
 95.1206 +
 95.1207 +		if (soundEchoIndex >= 4000)
 95.1208 +			soundEchoIndex = 0;
 95.1209 +	}
 95.1210 +
 95.1211 +	if (soundLowPass)
 95.1212 +	{
 95.1213 +		soundRight[4] = soundRight[3];
 95.1214 +		soundRight[3] = soundRight[2];
 95.1215 +		soundRight[2] = soundRight[1];
 95.1216 +		soundRight[1] = soundRight[0];
 95.1217 +		soundRight[0] = res;
 95.1218 +		res = (soundRight[4] + 2 * soundRight[3] + 8 * soundRight[2] + 2 * soundRight[1] +
 95.1219 +		       soundRight[0]) / 14;
 95.1220 +	}
 95.1221 +
 95.1222 +	if (!noSpecialEffects)
 95.1223 +	{
 95.1224 +		switch (soundVolume)
 95.1225 +		{
 95.1226 +		case 0:
 95.1227 +		case 1:
 95.1228 +		case 2:
 95.1229 +		case 3:
 95.1230 +			res *= (soundVolume + 1);
 95.1231 +			break;
 95.1232 +		case 4:
 95.1233 +			res >>= 2;
 95.1234 +			break;
 95.1235 +		case 5:
 95.1236 +			res >>= 1;
 95.1237 +			break;
 95.1238 +		}
 95.1239 +	}
 95.1240 +
 95.1241 +	if (res > 32767)
 95.1242 +		res = 32767;
 95.1243 +	if (res < -32768)
 95.1244 +		res = -32768;
 95.1245 +
 95.1246 +	if (soundReverse && !noSpecialEffects)
 95.1247 +	{
 95.1248 +		soundFinalWave[-1 + soundBufferIndex++]		   = res;
 95.1249 +		if ((soundFrameSoundWritten) >= countof(soundFrameSound))
 95.1250 +			/*assert(false)*/;
 95.1251 +		else
 95.1252 +			soundFrameSound[-1 + soundFrameSoundWritten++] = res;
 95.1253 +	}
 95.1254 +	else
 95.1255 +	{
 95.1256 +		soundFinalWave[soundBufferIndex++]			  = res;
 95.1257 +		if ((soundFrameSoundWritten + 1) >= countof(soundFrameSound))
 95.1258 +			/*assert(false)*/;
 95.1259 +		else
 95.1260 +			soundFrameSound[soundFrameSoundWritten++] = res;
 95.1261 +	}
 95.1262 +}
 95.1263 +
 95.1264 +void soundTick()
 95.1265 +{
 95.1266 +	if (systemSoundOn)
 95.1267 +	{
 95.1268 +		if (soundMasterOn && !stopState)
 95.1269 +		{
 95.1270 +			soundChannel1();
 95.1271 +			soundChannel2();
 95.1272 +			soundChannel3();
 95.1273 +			soundChannel4();
 95.1274 +			soundDirectSoundA();
 95.1275 +			soundDirectSoundB();
 95.1276 +			soundMix();
 95.1277 +		}
 95.1278 +		else
 95.1279 +		{
 95.1280 +			soundFinalWave[soundBufferIndex++] = 0;
 95.1281 +			soundFinalWave[soundBufferIndex++] = 0;
 95.1282 +			if ((soundFrameSoundWritten + 1) >= countof(soundFrameSound))
 95.1283 +				/*assert(false)*/;
 95.1284 +			else
 95.1285 +			{
 95.1286 +				soundFrameSound[soundFrameSoundWritten++] = 0;
 95.1287 +				soundFrameSound[soundFrameSoundWritten++] = 0;
 95.1288 +			}
 95.1289 +		}
 95.1290 +
 95.1291 +		soundIndex++;
 95.1292 +
 95.1293 +		if (2 * soundBufferIndex >= soundBufferLen)
 95.1294 +		{
 95.1295 +			if (systemSoundOn)
 95.1296 +			{
 95.1297 +				if (soundPaused)
 95.1298 +				{
 95.1299 +					soundResume();
 95.1300 +				}
 95.1301 +
 95.1302 +				systemSoundWriteToBuffer();
 95.1303 +			}
 95.1304 +			soundIndex		 = 0;
 95.1305 +			soundBufferIndex = 0;
 95.1306 +		}
 95.1307 +	}
 95.1308 +}
 95.1309 +
 95.1310 +void soundShutdown()
 95.1311 +{
 95.1312 +	systemSoundShutdown();
 95.1313 +}
 95.1314 +
 95.1315 +void soundPause()
 95.1316 +{
 95.1317 +	systemSoundPause();
 95.1318 +}
 95.1319 +
 95.1320 +void soundResume()
 95.1321 +{
 95.1322 +	systemSoundResume();
 95.1323 +}
 95.1324 +
 95.1325 +void soundEnableChannels(int channels)
 95.1326 +{
 95.1327 +	int c = (channels & 0x0f) << 4;
 95.1328 +	soundEnableFlag |= ((channels & 0x30f) | c);
 95.1329 +}
 95.1330 +
 95.1331 +void soundDisableChannels(int channels)
 95.1332 +{
 95.1333 +	int c = (channels & 0x0f) << 4;
 95.1334 +	soundEnableFlag &= ~((channels & 0x30f) | c);
 95.1335 +}
 95.1336 +
 95.1337 +int soundGetEnabledChannels()
 95.1338 +{
 95.1339 +	return (soundEnableFlag & 0x30f);
 95.1340 +}
 95.1341 +
 95.1342 +#if 0
 95.1343 +// unused
 95.1344 +void soundMuteChannels(int channels)
 95.1345 +{
 95.1346 +	soundMutedFlag |= channels & 0x30f;
 95.1347 +}
 95.1348 +
 95.1349 +void soundUnmuteChannels(int channels)
 95.1350 +{
 95.1351 +	soundMutedFlag &= ~(channels & 0x30f);
 95.1352 +}
 95.1353 +
 95.1354 +int soundGetMutedChannels()
 95.1355 +{
 95.1356 +	return (soundMutedFlag & 0x30f);
 95.1357 +}
 95.1358 +#endif
 95.1359 +
 95.1360 +void soundReset()
 95.1361 +{
 95.1362 +	systemSoundReset();
 95.1363 +
 95.1364 +	soundPaused		  = 1;
 95.1365 +	soundPlay		  = 0;
 95.1366 +	SOUND_CLOCK_TICKS = soundQuality * USE_TICKS_AS;
 95.1367 +	soundTicks		  = SOUND_CLOCK_TICKS;
 95.1368 +	soundNextPosition = 0;
 95.1369 +	soundMasterOn	  = 1;
 95.1370 +	soundIndex		  = 0;
 95.1371 +	soundBufferIndex  = 0;
 95.1372 +	soundLevel1		  = 7;
 95.1373 +	soundLevel2		  = 7;
 95.1374 +
 95.1375 +	sound1On = 0;
 95.1376 +	sound1ATL = 0;
 95.1377 +	sound1Skip = 0;
 95.1378 +	sound1Index = 0;
 95.1379 +	sound1Continue = 0;
 95.1380 +	sound1EnvelopeVolume	= 0;
 95.1381 +	sound1EnvelopeATL		= 0;
 95.1382 +	sound1EnvelopeUpDown	= 0;
 95.1383 +	sound1EnvelopeATLReload = 0;
 95.1384 +	sound1SweepATL			= 0;
 95.1385 +	sound1SweepATLReload	= 0;
 95.1386 +	sound1SweepSteps		= 0;
 95.1387 +	sound1SweepUpDown		= 0;
 95.1388 +	sound1SweepStep			= 0;
 95.1389 +	sound1Wave				= soundWavePattern[2];
 95.1390 +
 95.1391 +	sound2On = 0;
 95.1392 +	sound2ATL = 0;
 95.1393 +	sound2Skip = 0;
 95.1394 +	sound2Index = 0;
 95.1395 +	sound2Continue = 0;
 95.1396 +	sound2EnvelopeVolume	= 0;
 95.1397 +	sound2EnvelopeATL		= 0;
 95.1398 +	sound2EnvelopeUpDown	= 0;
 95.1399 +	sound2EnvelopeATLReload = 0;
 95.1400 +	sound2Wave				= soundWavePattern[2];
 95.1401 +
 95.1402 +	sound3On = 0;
 95.1403 +	sound3ATL = 0;
 95.1404 +	sound3Skip		   = 0;
 95.1405 +	sound3Index		   = 0;
 95.1406 +	sound3Continue	   = 0;
 95.1407 +	sound3OutputLevel  = 0;
 95.1408 +	sound3Last		   = 0;
 95.1409 +	sound3Bank		   = 0;
 95.1410 +	sound3DataSize	   = 0;
 95.1411 +	sound3ForcedOutput = 0;
 95.1412 +
 95.1413 +	sound4On = 0;
 95.1414 +	sound4Clock = 0;
 95.1415 +	sound4ATL = 0;
 95.1416 +	sound4Skip = 0;
 95.1417 +	sound4Index = 0;
 95.1418 +	sound4ShiftRight		= 0x7f;
 95.1419 +	sound4NSteps			= 0;
 95.1420 +	sound4CountDown			= 0;
 95.1421 +	sound4Continue			= 0;
 95.1422 +	sound4EnvelopeVolume	= 0;
 95.1423 +	sound4EnvelopeATL		= 0;
 95.1424 +	sound4EnvelopeUpDown	= 0;
 95.1425 +	sound4EnvelopeATLReload = 0;
 95.1426 +
 95.1427 +	sound1On = 0;
 95.1428 +	sound2On = 0;
 95.1429 +	sound3On = 0;
 95.1430 +	sound4On = 0;
 95.1431 +
 95.1432 +	int addr = 0x90;
 95.1433 +
 95.1434 +	while (addr < 0xA0)
 95.1435 +	{
 95.1436 +		ioMem[addr++] = 0x00;
 95.1437 +		ioMem[addr++] = 0xff;
 95.1438 +	}
 95.1439 +
 95.1440 +	addr = 0;
 95.1441 +	while (addr < 0x20)
 95.1442 +	{
 95.1443 +		sound3WaveRam[addr++] = 0x00;
 95.1444 +		sound3WaveRam[addr++] = 0xff;
 95.1445 +	}
 95.1446 +
 95.1447 +	memset(soundFinalWave, 0, soundBufferLen);
 95.1448 +
 95.1449 +	memset(soundFilter, 0, sizeof(soundFilter));
 95.1450 +	soundEchoIndex = 0;
 95.1451 +}
 95.1452 +
 95.1453 +bool soundInit()
 95.1454 +{
 95.1455 +	if (systemSoundInit())
 95.1456 +	{
 95.1457 +		memset(soundBuffer[0], 0, 735 * 2);
 95.1458 +		memset(soundBuffer[1], 0, 735 * 2);
 95.1459 +		memset(soundBuffer[2], 0, 735 * 2);
 95.1460 +		memset(soundBuffer[3], 0, 735 * 2);
 95.1461 +
 95.1462 +		memset(soundFinalWave, 0, soundBufferLen);
 95.1463 +
 95.1464 +		soundPaused = 1;
 95.1465 +		return true;
 95.1466 +	}
 95.1467 +	return false;
 95.1468 +}
 95.1469 +
 95.1470 +void soundSetQuality(int quality)
 95.1471 +{
 95.1472 +	if (soundQuality != quality && systemSoundCanChangeQuality())
 95.1473 +	{
 95.1474 +		if (!soundOffFlag)
 95.1475 +			soundShutdown();
 95.1476 +		soundQuality	  = quality;
 95.1477 +		soundNextPosition = 0;
 95.1478 +		if (!soundOffFlag)
 95.1479 +			soundInit();
 95.1480 +		SOUND_CLOCK_TICKS = USE_TICKS_AS * soundQuality;
 95.1481 +		soundIndex		  = 0;
 95.1482 +		soundBufferIndex  = 0;
 95.1483 +	}
 95.1484 +	else if (soundQuality != quality)
 95.1485 +	{
 95.1486 +		soundNextPosition = 0;
 95.1487 +		SOUND_CLOCK_TICKS = USE_TICKS_AS * soundQuality;
 95.1488 +		soundIndex		  = 0;
 95.1489 +		soundBufferIndex  = 0;
 95.1490 +	}
 95.1491 +}
 95.1492 +
 95.1493 +void soundSaveGame(gzFile gzFile)
 95.1494 +{
 95.1495 +	soundTicks_int32		= (int32) soundTicks;
 95.1496 +	SOUND_CLOCK_TICKS_int32 = (int32) SOUND_CLOCK_TICKS;
 95.1497 +	soundDSBValue_int32		= (int32) soundDSBValue;
 95.1498 +
 95.1499 +	utilWriteData(gzFile, soundSaveStruct);
 95.1500 +	utilWriteData(gzFile, soundSaveStructV2);
 95.1501 +
 95.1502 +	utilGzWrite(gzFile, &soundQuality, sizeof(int32));
 95.1503 +	//utilWriteData(gzFile, soundSaveStructV3);
 95.1504 +}
 95.1505 +
 95.1506 +void soundReadGame(gzFile gzFile, int version)
 95.1507 +{
 95.1508 +	int32 oldSoundPaused = soundPaused;
 95.1509 +	int32 oldSoundEnableFlag = soundEnableFlag;
 95.1510 +	utilReadData(gzFile, soundSaveStruct);
 95.1511 +	soundPaused = oldSoundPaused;
 95.1512 +	soundEnableFlag = oldSoundEnableFlag;
 95.1513 +
 95.1514 +	if (version >= SAVE_GAME_VERSION_3)
 95.1515 +	{
 95.1516 +		utilReadData(gzFile, soundSaveStructV2);
 95.1517 +	}
 95.1518 +	else
 95.1519 +	{
 95.1520 +		sound3Bank		   = (ioMem[NR30] >> 6) & 1;
 95.1521 +		sound3DataSize	   = (ioMem[NR30] >> 5) & 1;
 95.1522 +		sound3ForcedOutput = (ioMem[NR32] >> 7) & 1;
 95.1523 +		// nothing better to do here...
 95.1524 +		memcpy(&sound3WaveRam[0x00], &ioMem[0x90], 0x10);
 95.1525 +		memcpy(&sound3WaveRam[0x10], &ioMem[0x90], 0x10);
 95.1526 +	}
 95.1527 +	soundBufferIndex = soundIndex * 2;
 95.1528 +
 95.1529 +	int quality = 1;
 95.1530 +	utilGzRead(gzFile, &quality, sizeof(int32));
 95.1531 +	soundSetQuality(quality);
 95.1532 +
 95.1533 +	sound1Wave = soundWavePattern[ioMem[NR11] >> 6];
 95.1534 +	sound2Wave = soundWavePattern[ioMem[NR21] >> 6];
 95.1535 +
 95.1536 +	//if(version >= SAVE_GAME_VERSION_14) {
 95.1537 +	//  utilReadData(gzFile, soundSaveStructV3);
 95.1538 +	//}
 95.1539 +	//else {
 95.1540 +	soundTicks		  = (soundtick_t) soundTicks_int32;
 95.1541 +	SOUND_CLOCK_TICKS = (soundtick_t) SOUND_CLOCK_TICKS_int32;
 95.1542 +	//}
 95.1543 +	soundDSBValue = (u8) (soundDSBValue_int32 & 0xff);
 95.1544 +}
 95.1545 +
    96.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    96.2 +++ b/src/gba/GBASound.h	Sat Mar 03 10:31:27 2012 -0600
    96.3 @@ -0,0 +1,73 @@
    96.4 +#ifndef VBA_GBA_SOUND_H
    96.5 +#define VBA_GBA_SOUND_H
    96.6 +
    96.7 +#if _MSC_VER > 1000
    96.8 +#pragma once
    96.9 +#endif // _MSC_VER > 1000
   96.10 +
   96.11 +#include "zlib.h"
   96.12 +#include "../Port.h"
   96.13 +
   96.14 +#define NR10 0x60
   96.15 +#define NR11 0x62
   96.16 +#define NR12 0x63
   96.17 +#define NR13 0x64
   96.18 +#define NR14 0x65
   96.19 +#define NR21 0x68
   96.20 +#define NR22 0x69
   96.21 +#define NR23 0x6c
   96.22 +#define NR24 0x6d
   96.23 +#define NR30 0x70
   96.24 +#define NR31 0x72
   96.25 +#define NR32 0x73
   96.26 +#define NR33 0x74
   96.27 +#define NR34 0x75
   96.28 +#define NR41 0x78
   96.29 +#define NR42 0x79
   96.30 +#define NR43 0x7c
   96.31 +#define NR44 0x7d
   96.32 +#define NR50 0x80
   96.33 +#define NR51 0x81
   96.34 +#define NR52 0x84
   96.35 +#define SGCNT0_H 0x82
   96.36 +#define FIFOA_L 0xa0
   96.37 +#define FIFOA_H 0xa2
   96.38 +#define FIFOB_L 0xa4
   96.39 +#define FIFOB_H 0xa6
   96.40 +
   96.41 +extern void soundTick();
   96.42 +extern void soundShutdown();
   96.43 +extern bool soundInit();
   96.44 +extern void soundPause();
   96.45 +extern void soundResume();
   96.46 +extern void soundEnableChannels(int);
   96.47 +extern void soundDisableChannels(int);
   96.48 +extern int  soundGetEnabledChannels();
   96.49 +extern void soundReset();
   96.50 +extern void soundSaveGame(gzFile);
   96.51 +extern void soundReadGame(gzFile, int);
   96.52 +extern void soundEvent(u32, u8);
   96.53 +extern void soundEvent(u32, u16);
   96.54 +extern void soundTimerOverflow(int);
   96.55 +extern void soundSetQuality(int);
   96.56 +
   96.57 +typedef int32 soundtick_t;
   96.58 +
   96.59 +extern soundtick_t SOUND_CLOCK_TICKS;
   96.60 +extern soundtick_t soundTicks;
   96.61 +extern int32       soundPaused;
   96.62 +extern bool8       soundOffFlag;
   96.63 +extern int32       soundQuality;
   96.64 +extern u32         soundBufferLen;
   96.65 +extern u32         soundBufferTotalLen;
   96.66 +extern u32         soundNextPosition;
   96.67 +extern u16         soundFinalWave[1470];
   96.68 +extern u16         soundFrameSound[735*30*2];
   96.69 +extern int32       soundFrameSoundWritten;
   96.70 +extern int32       soundVolume;
   96.71 +
   96.72 +extern bool8 soundEcho;
   96.73 +extern bool8 soundLowPass;
   96.74 +extern bool8 soundReverse;
   96.75 +
   96.76 +#endif // VBA_GBA_SOUND_H
    97.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    97.2 +++ b/src/gba/GBAinline.h	Sat Mar 03 10:31:27 2012 -0600
    97.3 @@ -0,0 +1,490 @@
    97.4 +#ifndef VBA_GBAINLINE_H
    97.5 +#define VBA_GBAINLINE_H
    97.6 +
    97.7 +#if _MSC_VER > 1000
    97.8 +#pragma once
    97.9 +#endif // _MSC_VER > 1000
   97.10 +
   97.11 +#include "../Port.h"
   97.12 +#include "../common/System.h"
   97.13 +#include "../common/vbalua.h"
   97.14 +#include "GBAGlobals.h"
   97.15 +#include "EEprom.h"
   97.16 +#include "Flash.h"
   97.17 +#include "RTC.h"
   97.18 +
   97.19 +extern bool8 cpuSramEnabled;
   97.20 +extern bool8 cpuFlashEnabled;
   97.21 +extern bool8 cpuEEPROMEnabled;
   97.22 +extern bool8 cpuEEPROMSensorEnabled;
   97.23 +
   97.24 +#define CPUReadByteQuick(addr) \
   97.25 +    map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]
   97.26 +
   97.27 +#define CPUReadHalfWordQuick(addr) \
   97.28 +    READ16LE(((u16 *)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
   97.29 +
   97.30 +#define CPUReadMemoryQuick(addr) \
   97.31 +    READ32LE(((u32 *)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
   97.32 +
   97.33 +//inline u32 CPUReadMemoryQuick(u32 addr)
   97.34 +//{
   97.35 +//	u32 addrShift = (addr)>>24;
   97.36 +//	u32 rt = (addr) & map[addrShift].mask;
   97.37 +//	return READ32LE(((u32*)&map[addrShift].address[rt]));
   97.38 +//}
   97.39 +
   97.40 +inline u32 CPUReadMemory(u32 address)
   97.41 +{
   97.42 +#ifdef GBA_LOGGING
   97.43 +	if (address & 3)
   97.44 +	{
   97.45 +		if (systemVerbose & VERBOSE_UNALIGNED_MEMORY)
   97.46 +		{
   97.47 +			log("Unaligned word read: %08x at %08x\n", address, armMode ?
   97.48 +			    armNextPC - 4 : armNextPC - 2);
   97.49 +		}
   97.50 +	}
   97.51 +#endif
   97.52 +
   97.53 +	u32 value;
   97.54 +	switch (address >> 24)
   97.55 +	{
   97.56 +	case 0:
   97.57 +		if (reg[15].I >> 24)
   97.58 +		{
   97.59 +			if (address < 0x4000)
   97.60 +			{
   97.61 +#ifdef GBA_LOGGING
   97.62 +				if (systemVerbose & VERBOSE_ILLEGAL_READ)
   97.63 +				{
   97.64 +					log("Illegal word read: %08x at %08x\n", address, armMode ?
   97.65 +					    armNextPC - 4 : armNextPC - 2);
   97.66 +				}
   97.67 +#endif
   97.68 +
   97.69 +				value = READ32LE(((u32 *)&biosProtected));
   97.70 +			}
   97.71 +			else
   97.72 +				goto unreadable;
   97.73 +		}
   97.74 +		else
   97.75 +			value = READ32LE(((u32 *)&bios[address & 0x3FFC]));
   97.76 +		break;
   97.77 +	case 2:
   97.78 +		value = READ32LE(((u32 *)&workRAM[address & 0x3FFFC]));
   97.79 +		break;
   97.80 +	case 3:
   97.81 +		value = READ32LE(((u32 *)&internalRAM[address & 0x7ffC]));
   97.82 +		break;
   97.83 +	case 4:
   97.84 +		if ((address < 0x4000400) && ioReadable[address & 0x3fc])
   97.85 +		{
   97.86 +			if (ioReadable[(address & 0x3fc) + 2])
   97.87 +			{
   97.88 +				if (address >= 0x400012d && address <= 0x4000131)
   97.89 +					GBASystemCounters.lagged = false;
   97.90 +				value = READ32LE(((u32 *)&ioMem[address & 0x3fC]));
   97.91 +			}
   97.92 +			else
   97.93 +			{
   97.94 +				if (address >= 0x400012f && address <= 0x4000131)
   97.95 +					GBASystemCounters.lagged = false;
   97.96 +				value = READ16LE(((u16 *)&ioMem[address & 0x3fc]));
   97.97 +			}
   97.98 +		}
   97.99 +		else
  97.100 +			goto unreadable;
  97.101 +		break;
  97.102 +	case 5:
  97.103 +		value = READ32LE(((u32 *)&paletteRAM[address & 0x3fC]));
  97.104 +		break;
  97.105 +	case 6:
  97.106 +		value = READ32LE(((u32 *)&vram[address & 0x1fffc]));
  97.107 +		break;
  97.108 +	case 7:
  97.109 +		value = READ32LE(((u32 *)&oam[address & 0x3FC]));
  97.110 +		break;
  97.111 +	case 8:
  97.112 +	case 9:
  97.113 +	case 10:
  97.114 +	case 11:
  97.115 +	case 12:
  97.116 +		value = READ32LE(((u32 *)&rom[address&0x1FFFFFC]));
  97.117 +		break;
  97.118 +	case 13:
  97.119 +		if (cpuEEPROMEnabled)
  97.120 +			// no need to swap this
  97.121 +			return eepromRead(address);
  97.122 +		goto unreadable;
  97.123 +	case 14:
  97.124 +		if (cpuFlashEnabled | cpuSramEnabled)
  97.125 +			// no need to swap this
  97.126 +			return flashRead(address);
  97.127 +	// default
  97.128 +	default:
  97.129 +unreadable:
  97.130 +#ifdef GBA_LOGGING
  97.131 +		if (systemVerbose & VERBOSE_ILLEGAL_READ)
  97.132 +		{
  97.133 +			log("Illegal word read: %08x at %08x\n", address, armMode ?
  97.134 +			    armNextPC - 4 : armNextPC - 2);
  97.135 +		}
  97.136 +#endif
  97.137 +
  97.138 +		//    if(ioMem[0x205] & 0x40) {
  97.139 +		if (armState)
  97.140 +		{
  97.141 +			value = CPUReadMemoryQuick(reg[15].I);
  97.142 +		}
  97.143 +		else
  97.144 +		{
  97.145 +			value = CPUReadHalfWordQuick(reg[15].I) |
  97.146 +			        CPUReadHalfWordQuick(reg[15].I) << 16;
  97.147 +		}
  97.148 +		//  } else {
  97.149 +		//      value = *((u32 *)&bios[address & 0x3ffc]);
  97.150 +		//    }
  97.151 +		//        return 0xFFFFFFFF;
  97.152 +	}
  97.153 +
  97.154 +	if (address & 3)
  97.155 +	{
  97.156 +#ifdef C_CORE
  97.157 +		int shift = (address & 3) << 3;
  97.158 +		value = (value >> shift) | (value << (32 - shift));
  97.159 +#else
  97.160 +#ifdef __GNUC__
  97.161 +		asm ("and $3, %%ecx;"
  97.162 +		     "shl $3 ,%%ecx;"
  97.163 +		     "ror %%cl, %0"
  97.164 +			 : "=r" (value)
  97.165 +			 : "r" (value), "c" (address));
  97.166 +#else
  97.167 +		__asm {
  97.168 +			mov ecx, address;
  97.169 +			and ecx, 3;
  97.170 +			shl ecx, 3;
  97.171 +			ror [dword ptr value], cl;
  97.172 +		}
  97.173 +#endif
  97.174 +#endif
  97.175 +	}
  97.176 +	return value;
  97.177 +}
  97.178 +
  97.179 +extern u32 myROM[];
  97.180 +
  97.181 +inline u32 CPUReadHalfWord(u32 address)
  97.182 +{
  97.183 +#ifdef GBA_LOGGING
  97.184 +	if (address & 1)
  97.185 +	{
  97.186 +		if (systemVerbose & VERBOSE_UNALIGNED_MEMORY)
  97.187 +		{
  97.188 +			log("Unaligned halfword read: %08x at %08x\n", address, armMode ?
  97.189 +			    armNextPC - 4 : armNextPC - 2);
  97.190 +		}
  97.191 +	}
  97.192 +#endif
  97.193 +
  97.194 +	u32 value;
  97.195 +
  97.196 +	switch (address >> 24)
  97.197 +	{
  97.198 +	case 0:
  97.199 +		if (reg[15].I >> 24)
  97.200 +		{
  97.201 +			if (address < 0x4000)
  97.202 +			{
  97.203 +#ifdef GBA_LOGGING
  97.204 +				if (systemVerbose & VERBOSE_ILLEGAL_READ)
  97.205 +				{
  97.206 +					log("Illegal halfword read: %08x at %08x\n", address, armMode ?
  97.207 +					    armNextPC - 4 : armNextPC - 2);
  97.208 +				}
  97.209 +#endif
  97.210 +				value = READ16LE(((u16 *)&biosProtected[address&2]));
  97.211 +			}
  97.212 +			else
  97.213 +				goto unreadable;
  97.214 +		}
  97.215 +		else
  97.216 +			value = READ16LE(((u16 *)&bios[address & 0x3FFE]));
  97.217 +		break;
  97.218 +	case 2:
  97.219 +		value = READ16LE(((u16 *)&workRAM[address & 0x3FFFE]));
  97.220 +		break;
  97.221 +	case 3:
  97.222 +		value = READ16LE(((u16 *)&internalRAM[address & 0x7ffe]));
  97.223 +		break;
  97.224 +	case 4:
  97.225 +		if ((address < 0x4000400) && ioReadable[address & 0x3fe])
  97.226 +		{
  97.227 +			if (address >= 0x400012f && address <= 0x4000131)
  97.228 +				GBASystemCounters.lagged = false;
  97.229 +			value =  READ16LE(((u16 *)&ioMem[address & 0x3fe]));
  97.230 +		}
  97.231 +		else
  97.232 +			goto unreadable;
  97.233 +		break;
  97.234 +	case 5:
  97.235 +		value = READ16LE(((u16 *)&paletteRAM[address & 0x3fe]));
  97.236 +		break;
  97.237 +	case 6:
  97.238 +		value = READ16LE(((u16 *)&vram[address & 0x1fffe]));
  97.239 +		break;
  97.240 +	case 7:
  97.241 +		value = READ16LE(((u16 *)&oam[address & 0x3fe]));
  97.242 +		break;
  97.243 +	case 8:
  97.244 +	case 9:
  97.245 +	case 10:
  97.246 +	case 11:
  97.247 +	case 12:
  97.248 +		if (address == 0x80000c4 || address == 0x80000c6 || address == 0x80000c8)
  97.249 +			value = rtcRead(address);
  97.250 +		else
  97.251 +			value = READ16LE(((u16 *)&rom[address & 0x1FFFFFE]));
  97.252 +		break;
  97.253 +	case 13:
  97.254 +		if (cpuEEPROMEnabled)
  97.255 +			// no need to swap this
  97.256 +			return eepromRead(address);
  97.257 +		goto unreadable;
  97.258 +	case 14:
  97.259 +		if (cpuFlashEnabled | cpuSramEnabled)
  97.260 +			// no need to swap this
  97.261 +			return flashRead(address);
  97.262 +	// default
  97.263 +	default:
  97.264 +unreadable:
  97.265 +#ifdef GBA_LOGGING
  97.266 +		if (systemVerbose & VERBOSE_ILLEGAL_READ)
  97.267 +		{
  97.268 +			log("Illegal halfword read: %08x at %08x\n", address, armMode ?
  97.269 +			    armNextPC - 4 : armNextPC - 2);
  97.270 +		}
  97.271 +#endif
  97.272 +		extern bool8 cpuDmaHack;
  97.273 +		extern u32   cpuDmaLast;
  97.274 +		extern int32 cpuDmaCount;
  97.275 +		if (cpuDmaHack && cpuDmaCount)
  97.276 +		{
  97.277 +			value = (u16)cpuDmaLast;
  97.278 +		}
  97.279 +		else
  97.280 +		{
  97.281 +			if (armState)
  97.282 +			{
  97.283 +				value = CPUReadHalfWordQuick(reg[15].I + (address & 2));
  97.284 +			}
  97.285 +			else
  97.286 +			{
  97.287 +				value = CPUReadHalfWordQuick(reg[15].I);
  97.288 +			}
  97.289 +		}
  97.290 +		//    return value;
  97.291 +		//    if(address & 1)
  97.292 +		//      value = (value >> 8) | ((value & 0xFF) << 24);
  97.293 +		//    return 0xFFFF;
  97.294 +		break;
  97.295 +	}
  97.296 +
  97.297 +	if (address & 1)
  97.298 +	{
  97.299 +		value = (value >> 8) | (value << 24);
  97.300 +	}
  97.301 +
  97.302 +	return value;
  97.303 +}
  97.304 +
  97.305 +inline u16 CPUReadHalfWordSigned(u32 address)
  97.306 +{
  97.307 +	u16 value = CPUReadHalfWord(address);
  97.308 +	if ((address & 1))
  97.309 +		value = (s8)value;
  97.310 +	return value;
  97.311 +}
  97.312 +
  97.313 +inline u8 CPUReadByte(u32 address)
  97.314 +{
  97.315 +	switch (address >> 24)
  97.316 +	{
  97.317 +	case 0:
  97.318 +		if (reg[15].I >> 24)
  97.319 +		{
  97.320 +			if (address < 0x4000)
  97.321 +			{
  97.322 +#ifdef GBA_LOGGING
  97.323 +				if (systemVerbose & VERBOSE_ILLEGAL_READ)
  97.324 +				{
  97.325 +					log("Illegal byte read: %08x at %08x\n", address, armMode ?
  97.326 +					    armNextPC - 4 : armNextPC - 2);
  97.327 +				}
  97.328 +#endif
  97.329 +				return biosProtected[address & 3];
  97.330 +			}
  97.331 +			else
  97.332 +				goto unreadable;
  97.333 +		}
  97.334 +		return bios[address & 0x3FFF];
  97.335 +	case 2:
  97.336 +		return workRAM[address & 0x3FFFF];
  97.337 +	case 3:
  97.338 +		return internalRAM[address & 0x7fff];
  97.339 +	case 4:
  97.340 +		if ((address < 0x4000400) && ioReadable[address & 0x3ff])
  97.341 +		{
  97.342 +			if (address == 0x4000130 || address == 0x4000131)
  97.343 +				GBASystemCounters.lagged = false;
  97.344 +			return ioMem[address & 0x3ff];
  97.345 +		}
  97.346 +		else
  97.347 +			goto unreadable;
  97.348 +	case 5:
  97.349 +		return paletteRAM[address & 0x3ff];
  97.350 +	case 6:
  97.351 +		return vram[address & 0x1ffff];
  97.352 +	case 7:
  97.353 +		return oam[address & 0x3ff];
  97.354 +	case 8:
  97.355 +	case 9:
  97.356 +	case 10:
  97.357 +	case 11:
  97.358 +	case 12:
  97.359 +		return rom[address & 0x1FFFFFF];
  97.360 +	case 13:
  97.361 +		if (cpuEEPROMEnabled)
  97.362 +			return eepromRead(address);
  97.363 +		goto unreadable;
  97.364 +	case 14:
  97.365 +		if (cpuSramEnabled | cpuFlashEnabled)
  97.366 +			return flashRead(address);
  97.367 +		if (cpuEEPROMSensorEnabled)
  97.368 +		{
  97.369 +			switch (address & 0x00008f00)
  97.370 +			{
  97.371 +			case 0x8200:
  97.372 +				return systemGetSensorX() & 255;
  97.373 +			case 0x8300:
  97.374 +				return (systemGetSensorX() >> 8)|0x80;
  97.375 +			case 0x8400:
  97.376 +				return systemGetSensorY() & 255;
  97.377 +			case 0x8500:
  97.378 +				return systemGetSensorY() >> 8;
  97.379 +			}
  97.380 +		}
  97.381 +	// default
  97.382 +	default:
  97.383 +unreadable:
  97.384 +#ifdef GBA_LOGGING
  97.385 +		if (systemVerbose & VERBOSE_ILLEGAL_READ)
  97.386 +		{
  97.387 +			log("Illegal byte read: %08x at %08x\n", address, armMode ?
  97.388 +			    armNextPC - 4 : armNextPC - 2);
  97.389 +		}
  97.390 +#endif
  97.391 +
  97.392 +		if (armState)
  97.393 +		{
  97.394 +			return CPUReadByteQuick(reg[15].I+(address & 3));
  97.395 +		}
  97.396 +		else
  97.397 +		{
  97.398 +			return CPUReadByteQuick(reg[15].I+(address & 1));
  97.399 +		}
  97.400 +		//    return 0xFF;
  97.401 +		break;
  97.402 +	}
  97.403 +}
  97.404 +
  97.405 +inline void CPUWriteMemoryWrapped(u32 address, u32 value)
  97.406 +{
  97.407 +#ifdef GBA_LOGGING
  97.408 +	if (address & 3)
  97.409 +	{
  97.410 +		if (systemVerbose & VERBOSE_UNALIGNED_MEMORY)
  97.411 +		{
  97.412 +			log("Unaliagned word write: %08x to %08x from %08x\n",
  97.413 +			    value,
  97.414 +			    address,
  97.415 +			    armMode ? armNextPC - 4 : armNextPC - 2);
  97.416 +		}
  97.417 +	}
  97.418 +#endif
  97.419 +
  97.420 +	switch (address >> 24)
  97.421 +	{
  97.422 +	case 0x02:
  97.423 +#ifdef SDL
  97.424 +		if (*((u32 *)&freezeWorkRAM[address & 0x3FFFC]))
  97.425 +			cheatsWriteMemory((u32 *)&workRAM[address & 0x3FFFC],
  97.426 +			                  value,
  97.427 +			                  *((u32 *)&freezeWorkRAM[address & 0x3FFFC]));
  97.428 +		else
  97.429 +#endif
  97.430 +		WRITE32LE(((u32 *)&workRAM[address & 0x3FFFC]), value);
  97.431 +		break;
  97.432 +	case 0x03:
  97.433 +#ifdef SDL
  97.434 +		if (*((u32 *)&freezeInternalRAM[address & 0x7ffc]))
  97.435 +			cheatsWriteMemory((u32 *)&internalRAM[address & 0x7FFC],
  97.436 +			                  value,
  97.437 +			                  *((u32 *)&freezeInternalRAM[address & 0x7ffc]));
  97.438 +		else
  97.439 +#endif
  97.440 +		WRITE32LE(((u32 *)&internalRAM[address & 0x7ffC]), value);
  97.441 +		break;
  97.442 +	case 0x04:
  97.443 +		CPUUpdateRegister((address & 0x3FC), value & 0xFFFF);
  97.444 +		CPUUpdateRegister((address & 0x3FC) + 2, (value >> 16));
  97.445 +		break;
  97.446 +	case 0x05:
  97.447 +		WRITE32LE(((u32 *)&paletteRAM[address & 0x3FC]), value);
  97.448 +		break;
  97.449 +	case 0x06:
  97.450 +		if (address & 0x10000)
  97.451 +			WRITE32LE(((u32 *)&vram[address & 0x17ffc]), value);
  97.452 +		else
  97.453 +			WRITE32LE(((u32 *)&vram[address & 0x1fffc]), value);
  97.454 +		break;
  97.455 +	case 0x07:
  97.456 +		WRITE32LE(((u32 *)&oam[address & 0x3fc]), value);
  97.457 +		break;
  97.458 +	case 0x0D:
  97.459 +		if (cpuEEPROMEnabled)
  97.460 +		{
  97.461 +			eepromWrite(address, value);
  97.462 +			break;
  97.463 +		}
  97.464 +		goto unwritable;
  97.465 +	case 0x0E:
  97.466 +		if (!eepromInUse | cpuSramEnabled | cpuFlashEnabled)
  97.467 +		{
  97.468 +			(*cpuSaveGameFunc)(address, (u8)value);
  97.469 +			break;
  97.470 +		}
  97.471 +	// default
  97.472 +	default:
  97.473 +unwritable:
  97.474 +#ifdef GBA_LOGGING
  97.475 +		if (systemVerbose & VERBOSE_ILLEGAL_WRITE)
  97.476 +		{
  97.477 +			log("Illegal word write: %08x to %08x from %08x\n",
  97.478 +			    value,
  97.479 +			    address,
  97.480 +			    armMode ? armNextPC - 4 : armNextPC - 2);
  97.481 +		}
  97.482 +#endif
  97.483 +		break;
  97.484 +	}
  97.485 +}
  97.486 +
  97.487 +inline void CPUWriteMemory(u32 address, u32 value)
  97.488 +{
  97.489 +	CPUWriteMemoryWrapped(address, value);
  97.490 +	CallRegisteredLuaMemHook(address, 4, value, LUAMEMHOOK_WRITE);
  97.491 +}
  97.492 +
  97.493 +#endif // VBA_GBAINLINE_H
    98.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    98.2 +++ b/src/gba/Makefile.am	Sat Mar 03 10:31:27 2012 -0600
    98.3 @@ -0,0 +1,46 @@
    98.4 +noinst_LIBRARIES = libgba.a
    98.5 +
    98.6 +libgba_a_SOURCES = \
    98.7 +	agbprint.cpp		\
    98.8 +	agbprint.h		\
    98.9 +	arm-new.h		\
   98.10 +	armdis.cpp		\
   98.11 +	armdis.h		\
   98.12 +	bios.cpp		\
   98.13 +	bios.h			\
   98.14 +	elf.cpp			\
   98.15 +	elf.h			\
   98.16 +	Cheats.cpp		\
   98.17 +	Cheats.h		\
   98.18 +	EEprom.cpp		\
   98.19 +	EEprom.h		\
   98.20 +	Flash.cpp		\
   98.21 +	Flash.h			\
   98.22 +	GBA.cpp			\
   98.23 +	GBA.h			\
   98.24 +	GBAinline.h		\
   98.25 +	GBAGfx.cpp		\
   98.26 +	GBAGfx.h		\
   98.27 +	Globals.cpp		\
   98.28 +	Globals.h		\
   98.29 +	Mode0.cpp		\
   98.30 +	Mode1.cpp		\
   98.31 +	Mode2.cpp		\
   98.32 +	Mode3.cpp		\
   98.33 +	Mode4.cpp		\
   98.34 +	Mode5.cpp		\
   98.35 +	remote.cpp		\
   98.36 +	RTC.cpp			\
   98.37 +	RTC.h			\
   98.38 +	Sound.cpp		\
   98.39 +	Sound.h			\
   98.40 +	Sram.cpp		\
   98.41 +	Sram.h			\
   98.42 +	thumb.h
   98.43 +
   98.44 +AM_CPPFLAGS = \
   98.45 +	-I$(top_srcdir)/src		\
   98.46 +	-DSDL				\
   98.47 +	-DSYSCONFDIR=\"$(sysconfdir)\"
   98.48 +
   98.49 +AM_CXXFLAGS = -fno-exceptions @SDL_CFLAGS@
    99.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    99.2 +++ b/src/gba/Mode0.cpp	Sat Mar 03 10:31:27 2012 -0600
    99.3 @@ -0,0 +1,633 @@
    99.4 +#include "GBAGfx.h"
    99.5 +#include "GBAGlobals.h"
    99.6 +
    99.7 +void mode0RenderLine()
    99.8 +{
    99.9 +	u16 *palette = (u16 *)paletteRAM;
   99.10 +
   99.11 +	if (DISPCNT & 0x80)
   99.12 +	{
   99.13 +		for (int x = 0; x < 240; x++)
   99.14 +		{
   99.15 +			lineMix[x] = 0x7fff;
   99.16 +		}
   99.17 +		return;
   99.18 +	}
   99.19 +
   99.20 +	if (layerEnable & 0x0100)
   99.21 +	{
   99.22 +		gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0);
   99.23 +	}
   99.24 +
   99.25 +	if (layerEnable & 0x0200)
   99.26 +	{
   99.27 +		gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1);
   99.28 +	}
   99.29 +
   99.30 +	if (layerEnable & 0x0400)
   99.31 +	{
   99.32 +		gfxDrawTextScreen(BG2CNT, BG2HOFS, BG2VOFS, line2);
   99.33 +	}
   99.34 +
   99.35 +	if (layerEnable & 0x0800)
   99.36 +	{
   99.37 +		gfxDrawTextScreen(BG3CNT, BG3HOFS, BG3VOFS, line3);
   99.38 +	}
   99.39 +
   99.40 +	gfxDrawSprites(lineOBJ);
   99.41 +
   99.42 +	u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
   99.43 +
   99.44 +	for (int x = 0; x < 240; x++)
   99.45 +	{
   99.46 +		u32 color = backdrop;
   99.47 +		u8  top   = 0x20;
   99.48 +
   99.49 +		if (line0[x] < color)
   99.50 +		{
   99.51 +			color = line0[x];
   99.52 +			top   = 0x01;
   99.53 +		}
   99.54 +
   99.55 +		if ((u8)(line1[x]>>24) < (u8)(color >> 24))
   99.56 +		{
   99.57 +			color = line1[x];
   99.58 +			top   = 0x02;
   99.59 +		}
   99.60 +
   99.61 +		if ((u8)(line2[x]>>24) < (u8)(color >> 24))
   99.62 +		{
   99.63 +			color = line2[x];
   99.64 +			top   = 0x04;
   99.65 +		}
   99.66 +
   99.67 +		if ((u8)(line3[x]>>24) < (u8)(color >> 24))
   99.68 +		{
   99.69 +			color = line3[x];
   99.70 +			top   = 0x08;
   99.71 +		}
   99.72 +
   99.73 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))
   99.74 +		{
   99.75 +			color = lineOBJ[x];
   99.76 +			top   = 0x10;
   99.77 +		}
   99.78 +
   99.79 +		if ((top & 0x10) && (color & 0x00010000))
   99.80 +		{
   99.81 +			// semi-transparent OBJ
   99.82 +			u32 back = backdrop;
   99.83 +			u8  top2 = 0x20;
   99.84 +
   99.85 +			if ((u8)(line0[x]>>24) < (u8)(back >> 24))
   99.86 +			{
   99.87 +				back = line0[x];
   99.88 +				top2 = 0x01;
   99.89 +			}
   99.90 +
   99.91 +			if ((u8)(line1[x]>>24) < (u8)(back >> 24))
   99.92 +			{
   99.93 +				back = line1[x];
   99.94 +				top2 = 0x02;
   99.95 +			}
   99.96 +
   99.97 +			if ((u8)(line2[x]>>24) < (u8)(back >> 24))
   99.98 +			{
   99.99 +				back = line2[x];
  99.100 +				top2 = 0x04;
  99.101 +			}
  99.102 +
  99.103 +			if ((u8)(line3[x]>>24) < (u8)(back >> 24))
  99.104 +			{
  99.105 +				back = line3[x];
  99.106 +				top2 = 0x08;
  99.107 +			}
  99.108 +
  99.109 +			if (top2 & (BLDMOD>>8))
  99.110 +				color = gfxAlphaBlend(color, back,
  99.111 +				                      coeff[COLEV & 0x1F],
  99.112 +				                      coeff[(COLEV >> 8) & 0x1F]);
  99.113 +			else
  99.114 +			{
  99.115 +				switch ((BLDMOD >> 6) & 3)
  99.116 +				{
  99.117 +				case 2:
  99.118 +					if (BLDMOD & top)
  99.119 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
  99.120 +					break;
  99.121 +				case 3:
  99.122 +					if (BLDMOD & top)
  99.123 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
  99.124 +					break;
  99.125 +				}
  99.126 +			}
  99.127 +		}
  99.128 +
  99.129 +		lineMix[x] = color;
  99.130 +	}
  99.131 +}
  99.132 +
  99.133 +void mode0RenderLineNoWindow()
  99.134 +{
  99.135 +	u16 *palette = (u16 *)paletteRAM;
  99.136 +
  99.137 +	if (DISPCNT & 0x80)
  99.138 +	{
  99.139 +		for (int x = 0; x < 240; x++)
  99.140 +		{
  99.141 +			lineMix[x] = 0x7fff;
  99.142 +		}
  99.143 +		return;
  99.144 +	}
  99.145 +
  99.146 +	if (layerEnable & 0x0100)
  99.147 +	{
  99.148 +		gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0);
  99.149 +	}
  99.150 +
  99.151 +	if (layerEnable & 0x0200)
  99.152 +	{
  99.153 +		gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1);
  99.154 +	}
  99.155 +
  99.156 +	if (layerEnable & 0x0400)
  99.157 +	{
  99.158 +		gfxDrawTextScreen(BG2CNT, BG2HOFS, BG2VOFS, line2);
  99.159 +	}
  99.160 +
  99.161 +	if (layerEnable & 0x0800)
  99.162 +	{
  99.163 +		gfxDrawTextScreen(BG3CNT, BG3HOFS, BG3VOFS, line3);
  99.164 +	}
  99.165 +
  99.166 +	gfxDrawSprites(lineOBJ);
  99.167 +
  99.168 +	u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
  99.169 +
  99.170 +	int effect = (BLDMOD >> 6) & 3;
  99.171 +
  99.172 +	for (int x = 0; x < 240; x++)
  99.173 +	{
  99.174 +		u32 color = backdrop;
  99.175 +		u8  top   = 0x20;
  99.176 +
  99.177 +		if (line0[x] < color)
  99.178 +		{
  99.179 +			color = line0[x];
  99.180 +			top   = 0x01;
  99.181 +		}
  99.182 +
  99.183 +		if (line1[x] < (color & 0xFF000000))
  99.184 +		{
  99.185 +			color = line1[x];
  99.186 +			top   = 0x02;
  99.187 +		}
  99.188 +
  99.189 +		if (line2[x] < (color & 0xFF000000))
  99.190 +		{
  99.191 +			color = line2[x];
  99.192 +			top   = 0x04;
  99.193 +		}
  99.194 +
  99.195 +		if (line3[x] < (color & 0xFF000000))
  99.196 +		{
  99.197 +			color = line3[x];
  99.198 +			top   = 0x08;
  99.199 +		}
  99.200 +
  99.201 +		if (lineOBJ[x] < (color & 0xFF000000))
  99.202 +		{
  99.203 +			color = lineOBJ[x];
  99.204 +			top   = 0x10;
  99.205 +		}
  99.206 +
  99.207 +		if (!(color & 0x00010000))
  99.208 +		{
  99.209 +			switch (effect)
  99.210 +			{
  99.211 +			case 0:
  99.212 +				break;
  99.213 +			case 1:
  99.214 +			{
  99.215 +				if (top & BLDMOD)
  99.216 +				{
  99.217 +					u32 back = backdrop;
  99.218 +					u8  top2 = 0x20;
  99.219 +					if (line0[x] < back)
  99.220 +					{
  99.221 +						if (top != 0x01)
  99.222 +						{
  99.223 +							back = line0[x];
  99.224 +							top2 = 0x01;
  99.225 +						}
  99.226 +					}
  99.227 +
  99.228 +					if (line1[x] < (back & 0xFF000000))
  99.229 +					{
  99.230 +						if (top != 0x02)
  99.231 +						{
  99.232 +							back = line1[x];
  99.233 +							top2 = 0x02;
  99.234 +						}
  99.235 +					}
  99.236 +
  99.237 +					if (line2[x] < (back & 0xFF000000))
  99.238 +					{
  99.239 +						if (top != 0x04)
  99.240 +						{
  99.241 +							back = line2[x];
  99.242 +							top2 = 0x04;
  99.243 +						}
  99.244 +					}
  99.245 +
  99.246 +					if (line3[x] < (back & 0xFF000000))
  99.247 +					{
  99.248 +						if (top != 0x08)
  99.249 +						{
  99.250 +							back = line3[x];
  99.251 +							top2 = 0x08;
  99.252 +						}
  99.253 +					}
  99.254 +
  99.255 +					if (lineOBJ[x] < (back & 0xFF000000))
  99.256 +					{
  99.257 +						if (top != 0x10)
  99.258 +						{
  99.259 +							back = lineOBJ[x];
  99.260 +							top2 = 0x10;
  99.261 +						}
  99.262 +					}
  99.263 +
  99.264 +					if (top2 & (BLDMOD>>8))
  99.265 +						color = gfxAlphaBlend(color, back,
  99.266 +						                      coeff[COLEV & 0x1F],
  99.267 +						                      coeff[(COLEV >> 8) & 0x1F]);
  99.268 +				}
  99.269 +				break;
  99.270 +			}
  99.271 +			case 2:
  99.272 +				if (BLDMOD & top)
  99.273 +					color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
  99.274 +				break;
  99.275 +			case 3:
  99.276 +				if (BLDMOD & top)
  99.277 +					color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
  99.278 +				break;
  99.279 +			}
  99.280 +		}
  99.281 +		else
  99.282 +		{
  99.283 +			// semi-transparent OBJ
  99.284 +			u32 back = backdrop;
  99.285 +			u8  top2 = 0x20;
  99.286 +
  99.287 +			if (line0[x] < back)
  99.288 +			{
  99.289 +				back = line0[x];
  99.290 +				top2 = 0x01;
  99.291 +			}
  99.292 +
  99.293 +			if (line1[x] < (back & 0xFF000000))
  99.294 +			{
  99.295 +				back = line1[x];
  99.296 +				top2 = 0x02;
  99.297 +			}
  99.298 +
  99.299 +			if (line2[x] < (back & 0xFF000000))
  99.300 +			{
  99.301 +				back = line2[x];
  99.302 +				top2 = 0x04;
  99.303 +			}
  99.304 +
  99.305 +			if (line3[x] < (back & 0xFF000000))
  99.306 +			{
  99.307 +				back = line3[x];
  99.308 +				top2 = 0x08;
  99.309 +			}
  99.310 +
  99.311 +			if (top2 & (BLDMOD>>8))
  99.312 +				color = gfxAlphaBlend(color, back,
  99.313 +				                      coeff[COLEV & 0x1F],
  99.314 +				                      coeff[(COLEV >> 8) & 0x1F]);
  99.315 +			else
  99.316 +			{
  99.317 +				switch ((BLDMOD >> 6) & 3)
  99.318 +				{
  99.319 +				case 2:
  99.320 +					if (BLDMOD & top)
  99.321 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
  99.322 +					break;
  99.323 +				case 3:
  99.324 +					if (BLDMOD & top)
  99.325 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
  99.326 +					break;
  99.327 +				}
  99.328 +			}
  99.329 +		}
  99.330 +
  99.331 +		lineMix[x] = color;
  99.332 +	}
  99.333 +}
  99.334 +
  99.335 +void mode0RenderLineAll()
  99.336 +{
  99.337 +	u16 *palette = (u16 *)paletteRAM;
  99.338 +
  99.339 +	if (DISPCNT & 0x80)
  99.340 +	{
  99.341 +		for (int x = 0; x < 240; x++)
  99.342 +		{
  99.343 +			lineMix[x] = 0x7fff;
  99.344 +		}
  99.345 +		return;
  99.346 +	}
  99.347 +
  99.348 +	bool inWindow0 = false;
  99.349 +	bool inWindow1 = false;
  99.350 +
  99.351 +	if (layerEnable & 0x2000)
  99.352 +	{
  99.353 +		u8 v0 = WIN0V >> 8;
  99.354 +		u8 v1 = WIN0V & 255;
  99.355 +		inWindow0 = ((v0 == v1) && (v0 >= 0xe8));
  99.356 +		if (v1 >= v0)
  99.357 +			inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1);
  99.358 +		else
  99.359 +			inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
  99.360 +	}
  99.361 +	if (layerEnable & 0x4000)
  99.362 +	{
  99.363 +		u8 v0 = WIN1V >> 8;
  99.364 +		u8 v1 = WIN1V & 255;
  99.365 +		inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
  99.366 +		if (v1 >= v0)
  99.367 +			inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1);
  99.368 +		else
  99.369 +			inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
  99.370 +	}
  99.371 +
  99.372 +	if ((layerEnable & 0x0100))
  99.373 +	{
  99.374 +		gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0);
  99.375 +	}
  99.376 +
  99.377 +	if ((layerEnable & 0x0200))
  99.378 +	{
  99.379 +		gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1);
  99.380 +	}
  99.381 +
  99.382 +	if ((layerEnable & 0x0400))
  99.383 +	{
  99.384 +		gfxDrawTextScreen(BG2CNT, BG2HOFS, BG2VOFS, line2);
  99.385 +	}
  99.386 +
  99.387 +	if ((layerEnable & 0x0800))
  99.388 +	{
  99.389 +		gfxDrawTextScreen(BG3CNT, BG3HOFS, BG3VOFS, line3);
  99.390 +	}
  99.391 +
  99.392 +	gfxDrawSprites(lineOBJ);
  99.393 +	gfxDrawOBJWin(lineOBJWin);
  99.394 +
  99.395 +	u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
  99.396 +
  99.397 +	u8 inWin0Mask = WININ & 0xFF;
  99.398 +	u8 inWin1Mask = WININ >> 8;
  99.399 +	u8 outMask    = WINOUT & 0xFF;
  99.400 +
  99.401 +	for (int x = 0; x < 240; x++)
  99.402 +	{
  99.403 +		u32 color = backdrop;
  99.404 +		u8  top   = 0x20;
  99.405 +		u8  mask  = outMask;
  99.406 +
  99.407 +		if (!(lineOBJWin[x] & 0x80000000))
  99.408 +		{
  99.409 +			mask = WINOUT >> 8;
  99.410 +		}
  99.411 +
  99.412 +		if (inWindow1)
  99.413 +		{
  99.414 +			if (gfxInWin1[x])
  99.415 +				mask = inWin1Mask;
  99.416 +		}
  99.417 +
  99.418 +		if (inWindow0)
  99.419 +		{
  99.420 +			if (gfxInWin0[x])
  99.421 +			{
  99.422 +				mask = inWin0Mask;
  99.423 +			}
  99.424 +		}
  99.425 +
  99.426 +		if ((mask & 1) && (line0[x] < color))
  99.427 +		{
  99.428 +			color = line0[x];
  99.429 +			top   = 0x01;
  99.430 +		}
  99.431 +
  99.432 +		if ((mask & 2) && ((u8)(line1[x]>>24) < (u8)(color >> 24)))
  99.433 +		{
  99.434 +			color = line1[x];
  99.435 +			top   = 0x02;
  99.436 +		}
  99.437 +
  99.438 +		if ((mask & 4) && ((u8)(line2[x]>>24) < (u8)(color >> 24)))
  99.439 +		{
  99.440 +			color = line2[x];
  99.441 +			top   = 0x04;
  99.442 +		}
  99.443 +
  99.444 +		if ((mask & 8) && ((u8)(line3[x]>>24) < (u8)(color >> 24)))
  99.445 +		{
  99.446 +			color = line3[x];
  99.447 +			top   = 0x08;
  99.448 +		}
  99.449 +
  99.450 +		if ((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)))
  99.451 +		{
  99.452 +			color = lineOBJ[x];
  99.453 +			top   = 0x10;
  99.454 +		}
  99.455 +
  99.456 +		// special FX on in the window
  99.457 +		if (mask & 32)
  99.458 +		{
  99.459 +			if (!(color & 0x00010000))
  99.460 +			{
  99.461 +				switch ((BLDMOD >> 6) & 3)
  99.462 +				{
  99.463 +				case 0:
  99.464 +					break;
  99.465 +				case 1:
  99.466 +				{
  99.467 +					if (top & BLDMOD)
  99.468 +					{
  99.469 +						u32 back = backdrop;
  99.470 +						u8  top2 = 0x20;
  99.471 +						if ((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24))
  99.472 +						{
  99.473 +							if (top != 0x01)
  99.474 +							{
  99.475 +								back = line0[x];
  99.476 +								top2 = 0x01;
  99.477 +							}
  99.478 +						}
  99.479 +
  99.480 +						if ((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24))
  99.481 +						{
  99.482 +							if (top != 0x02)
  99.483 +							{
  99.484 +								back = line1[x];
  99.485 +								top2 = 0x02;
  99.486 +							}
  99.487 +						}
  99.488 +
  99.489 +						if ((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24))
  99.490 +						{
  99.491 +							if (top != 0x04)
  99.492 +							{
  99.493 +								back = line2[x];
  99.494 +								top2 = 0x04;
  99.495 +							}
  99.496 +						}
  99.497 +
  99.498 +						if ((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24))
  99.499 +						{
  99.500 +							if (top != 0x08)
  99.501 +							{
  99.502 +								back = line3[x];
  99.503 +								top2 = 0x08;
  99.504 +							}
  99.505 +						}
  99.506 +
  99.507 +						if ((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
  99.508 +						{
  99.509 +							if (top != 0x10)
  99.510 +							{
  99.511 +								back = lineOBJ[x];
  99.512 +								top2 = 0x10;
  99.513 +							}
  99.514 +						}
  99.515 +
  99.516 +						if (top2 & (BLDMOD>>8))
  99.517 +							color = gfxAlphaBlend(color, back,
  99.518 +							                      coeff[COLEV & 0x1F],
  99.519 +							                      coeff[(COLEV >> 8) & 0x1F]);
  99.520 +					}
  99.521 +					break;
  99.522 +				}
  99.523 +				case 2:
  99.524 +					if (BLDMOD & top)
  99.525 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
  99.526 +					break;
  99.527 +				case 3:
  99.528 +					if (BLDMOD & top)
  99.529 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
  99.530 +					break;
  99.531 +				}
  99.532 +			}
  99.533 +			else
  99.534 +			{
  99.535 +				// semi-transparent OBJ
  99.536 +				u32 back = backdrop;
  99.537 +				u8  top2 = 0x20;
  99.538 +
  99.539 +				if ((mask & 1) && ((u8)(line0[x]>>24) < (u8)(back >> 24)))
  99.540 +				{
  99.541 +					back = line0[x];
  99.542 +					top2 = 0x01;
  99.543 +				}
  99.544 +
  99.545 +				if ((mask & 2) && ((u8)(line1[x]>>24) < (u8)(back >> 24)))
  99.546 +				{
  99.547 +					back = line1[x];
  99.548 +					top2 = 0x02;
  99.549 +				}
  99.550 +
  99.551 +				if ((mask & 4) && ((u8)(line2[x]>>24) < (u8)(back >> 24)))
  99.552 +				{
  99.553 +					back = line2[x];
  99.554 +					top2 = 0x04;
  99.555 +				}
  99.556 +
  99.557 +				if ((mask & 8) && ((u8)(line3[x]>>24) < (u8)(back >> 24)))
  99.558 +				{
  99.559 +					back = line3[x];
  99.560 +					top2 = 0x08;
  99.561 +				}
  99.562 +
  99.563 +				if (top2 & (BLDMOD>>8))
  99.564 +					color = gfxAlphaBlend(color, back,
  99.565 +					                      coeff[COLEV & 0x1F],
  99.566 +					                      coeff[(COLEV >> 8) & 0x1F]);
  99.567 +				else
  99.568 +				{
  99.569 +					switch ((BLDMOD >> 6) & 3)
  99.570 +					{
  99.571 +					case 2:
  99.572 +						if (BLDMOD & top)
  99.573 +							color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
  99.574 +						break;
  99.575 +					case 3:
  99.576 +						if (BLDMOD & top)
  99.577 +							color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
  99.578 +						break;
  99.579 +					}
  99.580 +				}
  99.581 +			}
  99.582 +		}
  99.583 +		else if (color & 0x00010000)
  99.584 +		{
  99.585 +			// semi-transparent OBJ
  99.586 +			u32 back = backdrop;
  99.587 +			u8  top2 = 0x20;
  99.588 +
  99.589 +			if ((mask & 1) && ((u8)(line0[x]>>24) < (u8)(back >> 24)))
  99.590 +			{
  99.591 +				back = line0[x];
  99.592 +				top2 = 0x01;
  99.593 +			}
  99.594 +
  99.595 +			if ((mask & 2) && ((u8)(line1[x]>>24) < (u8)(back >> 24)))
  99.596 +			{
  99.597 +				back = line1[x];
  99.598 +				top2 = 0x02;
  99.599 +			}
  99.600 +
  99.601 +			if ((mask & 4) && ((u8)(line2[x]>>24) < (u8)(back >> 24)))
  99.602 +			{
  99.603 +				back = line2[x];
  99.604 +				top2 = 0x04;
  99.605 +			}
  99.606 +
  99.607 +			if ((mask & 8) && ((u8)(line3[x]>>24) < (u8)(back >> 24)))
  99.608 +			{
  99.609 +				back = line3[x];
  99.610 +				top2 = 0x08;
  99.611 +			}
  99.612 +
  99.613 +			if (top2 & (BLDMOD>>8))
  99.614 +				color = gfxAlphaBlend(color, back,
  99.615 +				                      coeff[COLEV & 0x1F],
  99.616 +				                      coeff[(COLEV >> 8) & 0x1F]);
  99.617 +			else
  99.618 +			{
  99.619 +				switch ((BLDMOD >> 6) & 3)
  99.620 +				{
  99.621 +				case 2:
  99.622 +					if (BLDMOD & top)
  99.623 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
  99.624 +					break;
  99.625 +				case 3:
  99.626 +					if (BLDMOD & top)
  99.627 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
  99.628 +					break;
  99.629 +				}
  99.630 +			}
  99.631 +		}
  99.632 +
  99.633 +		lineMix[x] = color;
  99.634 +	}
  99.635 +}
  99.636 +
   100.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   100.2 +++ b/src/gba/Mode1.cpp	Sat Mar 03 10:31:27 2012 -0600
   100.3 @@ -0,0 +1,580 @@
   100.4 +#include "GBAGfx.h"
   100.5 +#include "GBAGlobals.h"
   100.6 +
   100.7 +void mode1RenderLine()
   100.8 +{
   100.9 +	u16 *palette = (u16 *)paletteRAM;
  100.10 +
  100.11 +	if (DISPCNT & 0x80)
  100.12 +	{
  100.13 +		for (int x = 0; x < 240; x++)
  100.14 +		{
  100.15 +			lineMix[x] = 0x7fff;
  100.16 +		}
  100.17 +		gfxLastVCOUNT = VCOUNT;
  100.18 +		return;
  100.19 +	}
  100.20 +
  100.21 +	if (layerEnable & 0x0100)
  100.22 +	{
  100.23 +		gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0);
  100.24 +	}
  100.25 +
  100.26 +	if (layerEnable & 0x0200)
  100.27 +	{
  100.28 +		gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1);
  100.29 +	}
  100.30 +
  100.31 +	if (layerEnable & 0x0400)
  100.32 +	{
  100.33 +		int changed = gfxBG2Changed;
  100.34 +		if (gfxLastVCOUNT > VCOUNT)
  100.35 +			changed = 3;
  100.36 +		gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
  100.37 +		                 BG2PA, BG2PB, BG2PC, BG2PD,
  100.38 +		                 gfxBG2X, gfxBG2Y, changed, line2);
  100.39 +	}
  100.40 +
  100.41 +	gfxDrawSprites(lineOBJ);
  100.42 +
  100.43 +	u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
  100.44 +
  100.45 +	for (int x = 0; x < 240; x++)
  100.46 +	{
  100.47 +		u32 color = backdrop;
  100.48 +		u8  top   = 0x20;
  100.49 +
  100.50 +		if (line0[x] < color)
  100.51 +		{
  100.52 +			color = line0[x];
  100.53 +			top   = 0x01;
  100.54 +		}
  100.55 +
  100.56 +		if ((u8)(line1[x]>>24) < (u8)(color >> 24))
  100.57 +		{
  100.58 +			color = line1[x];
  100.59 +			top   = 0x02;
  100.60 +		}
  100.61 +
  100.62 +		if ((u8)(line2[x]>>24) < (u8)(color >> 24))
  100.63 +		{
  100.64 +			color = line2[x];
  100.65 +			top   = 0x04;
  100.66 +		}
  100.67 +
  100.68 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))
  100.69 +		{
  100.70 +			color = lineOBJ[x];
  100.71 +			top   = 0x10;
  100.72 +		}
  100.73 +
  100.74 +		if ((top & 0x10) && (color & 0x00010000))
  100.75 +		{
  100.76 +			// semi-transparent OBJ
  100.77 +			u32 back = backdrop;
  100.78 +			u8  top2 = 0x20;
  100.79 +
  100.80 +			if ((u8)(line0[x]>>24) < (u8)(back >> 24))
  100.81 +			{
  100.82 +				back = line0[x];
  100.83 +				top2 = 0x01;
  100.84 +			}
  100.85 +
  100.86 +			if ((u8)(line1[x]>>24) < (u8)(back >> 24))
  100.87 +			{
  100.88 +				back = line1[x];
  100.89 +				top2 = 0x02;
  100.90 +			}
  100.91 +
  100.92 +			if ((u8)(line2[x]>>24) < (u8)(back >> 24))
  100.93 +			{
  100.94 +				back = line2[x];
  100.95 +				top2 = 0x04;
  100.96 +			}
  100.97 +
  100.98 +			if (top2 & (BLDMOD>>8))
  100.99 +				color = gfxAlphaBlend(color, back,
 100.100 +				                      coeff[COLEV & 0x1F],
 100.101 +				                      coeff[(COLEV >> 8) & 0x1F]);
 100.102 +			else
 100.103 +			{
 100.104 +				switch ((BLDMOD >> 6) & 3)
 100.105 +				{
 100.106 +				case 2:
 100.107 +					if (BLDMOD & top)
 100.108 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 100.109 +					break;
 100.110 +				case 3:
 100.111 +					if (BLDMOD & top)
 100.112 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 100.113 +					break;
 100.114 +				}
 100.115 +			}
 100.116 +		}
 100.117 +
 100.118 +		lineMix[x] = color;
 100.119 +	}
 100.120 +	gfxBG2Changed = 0;
 100.121 +	gfxLastVCOUNT = VCOUNT;
 100.122 +}
 100.123 +
 100.124 +void mode1RenderLineNoWindow()
 100.125 +{
 100.126 +	u16 *palette = (u16 *)paletteRAM;
 100.127 +
 100.128 +	if (DISPCNT & 0x80)
 100.129 +	{
 100.130 +		for (int x = 0; x < 240; x++)
 100.131 +		{
 100.132 +			lineMix[x] = 0x7fff;
 100.133 +		}
 100.134 +		gfxLastVCOUNT = VCOUNT;
 100.135 +		return;
 100.136 +	}
 100.137 +
 100.138 +	if (layerEnable & 0x0100)
 100.139 +	{
 100.140 +		gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0);
 100.141 +	}
 100.142 +
 100.143 +	if (layerEnable & 0x0200)
 100.144 +	{
 100.145 +		gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1);
 100.146 +	}
 100.147 +
 100.148 +	if (layerEnable & 0x0400)
 100.149 +	{
 100.150 +		int changed = gfxBG2Changed;
 100.151 +		if (gfxLastVCOUNT > VCOUNT)
 100.152 +			changed = 3;
 100.153 +		gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
 100.154 +		                 BG2PA, BG2PB, BG2PC, BG2PD,
 100.155 +		                 gfxBG2X, gfxBG2Y, changed, line2);
 100.156 +	}
 100.157 +
 100.158 +	gfxDrawSprites(lineOBJ);
 100.159 +
 100.160 +	u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
 100.161 +
 100.162 +	for (int x = 0; x < 240; x++)
 100.163 +	{
 100.164 +		u32 color = backdrop;
 100.165 +		u8  top   = 0x20;
 100.166 +
 100.167 +		if (line0[x] < color)
 100.168 +		{
 100.169 +			color = line0[x];
 100.170 +			top   = 0x01;
 100.171 +		}
 100.172 +
 100.173 +		if ((u8)(line1[x]>>24) < (u8)(color >> 24))
 100.174 +		{
 100.175 +			color = line1[x];
 100.176 +			top   = 0x02;
 100.177 +		}
 100.178 +
 100.179 +		if ((u8)(line2[x]>>24) < (u8)(color >> 24))
 100.180 +		{
 100.181 +			color = line2[x];
 100.182 +			top   = 0x04;
 100.183 +		}
 100.184 +
 100.185 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))
 100.186 +		{
 100.187 +			color = lineOBJ[x];
 100.188 +			top   = 0x10;
 100.189 +		}
 100.190 +
 100.191 +		if (!(color & 0x00010000))
 100.192 +		{
 100.193 +			switch ((BLDMOD >> 6) & 3)
 100.194 +			{
 100.195 +			case 0:
 100.196 +				break;
 100.197 +			case 1:
 100.198 +			{
 100.199 +				if (top & BLDMOD)
 100.200 +				{
 100.201 +					u32 back = backdrop;
 100.202 +					u8  top2 = 0x20;
 100.203 +					if ((u8)(line0[x]>>24) < (u8)(back >> 24))
 100.204 +					{
 100.205 +						if (top != 0x01)
 100.206 +						{
 100.207 +							back = line0[x];
 100.208 +							top2 = 0x01;
 100.209 +						}
 100.210 +					}
 100.211 +
 100.212 +					if ((u8)(line1[x]>>24) < (u8)(back >> 24))
 100.213 +					{
 100.214 +						if (top != 0x02)
 100.215 +						{
 100.216 +							back = line1[x];
 100.217 +							top2 = 0x02;
 100.218 +						}
 100.219 +					}
 100.220 +
 100.221 +					if ((u8)(line2[x]>>24) < (u8)(back >> 24))
 100.222 +					{
 100.223 +						if (top != 0x04)
 100.224 +						{
 100.225 +							back = line2[x];
 100.226 +							top2 = 0x04;
 100.227 +						}
 100.228 +					}
 100.229 +
 100.230 +					if ((u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
 100.231 +					{
 100.232 +						if (top != 0x10)
 100.233 +						{
 100.234 +							back = lineOBJ[x];
 100.235 +							top2 = 0x10;
 100.236 +						}
 100.237 +					}
 100.238 +
 100.239 +					if (top2 & (BLDMOD>>8))
 100.240 +						color = gfxAlphaBlend(color, back,
 100.241 +						                      coeff[COLEV & 0x1F],
 100.242 +						                      coeff[(COLEV >> 8) & 0x1F]);
 100.243 +				}
 100.244 +				break;
 100.245 +			}
 100.246 +			case 2:
 100.247 +				if (BLDMOD & top)
 100.248 +					color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 100.249 +				break;
 100.250 +			case 3:
 100.251 +				if (BLDMOD & top)
 100.252 +					color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 100.253 +				break;
 100.254 +			}
 100.255 +		}
 100.256 +		else
 100.257 +		{
 100.258 +			// semi-transparent OBJ
 100.259 +			u32 back = backdrop;
 100.260 +			u8  top2 = 0x20;
 100.261 +
 100.262 +			if ((u8)(line0[x]>>24) < (u8)(back >> 24))
 100.263 +			{
 100.264 +				back = line0[x];
 100.265 +				top2 = 0x01;
 100.266 +			}
 100.267 +
 100.268 +			if ((u8)(line1[x]>>24) < (u8)(back >> 24))
 100.269 +			{
 100.270 +				back = line1[x];
 100.271 +				top2 = 0x02;
 100.272 +			}
 100.273 +
 100.274 +			if ((u8)(line2[x]>>24) < (u8)(back >> 24))
 100.275 +			{
 100.276 +				back = line2[x];
 100.277 +				top2 = 0x04;
 100.278 +			}
 100.279 +
 100.280 +			if (top2 & (BLDMOD>>8))
 100.281 +				color = gfxAlphaBlend(color, back,
 100.282 +				                      coeff[COLEV & 0x1F],
 100.283 +				                      coeff[(COLEV >> 8) & 0x1F]);
 100.284 +			else
 100.285 +			{
 100.286 +				switch ((BLDMOD >> 6) & 3)
 100.287 +				{
 100.288 +				case 2:
 100.289 +					if (BLDMOD & top)
 100.290 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 100.291 +					break;
 100.292 +				case 3:
 100.293 +					if (BLDMOD & top)
 100.294 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 100.295 +					break;
 100.296 +				}
 100.297 +			}
 100.298 +		}
 100.299 +
 100.300 +		lineMix[x] = color;
 100.301 +	}
 100.302 +	gfxBG2Changed = 0;
 100.303 +	gfxLastVCOUNT = VCOUNT;
 100.304 +}
 100.305 +
 100.306 +void mode1RenderLineAll()
 100.307 +{
 100.308 +	u16 *palette = (u16 *)paletteRAM;
 100.309 +
 100.310 +	if (DISPCNT & 0x80)
 100.311 +	{
 100.312 +		for (int x = 0; x < 240; x++)
 100.313 +		{
 100.314 +			lineMix[x] = 0x7fff;
 100.315 +		}
 100.316 +		gfxLastVCOUNT = VCOUNT;
 100.317 +		return;
 100.318 +	}
 100.319 +
 100.320 +	bool inWindow0 = false;
 100.321 +	bool inWindow1 = false;
 100.322 +
 100.323 +	if (layerEnable & 0x2000)
 100.324 +	{
 100.325 +		u8 v0 = WIN0V >> 8;
 100.326 +		u8 v1 = WIN0V & 255;
 100.327 +		inWindow0 = ((v0 == v1) && (v0 >= 0xe8));
 100.328 +		if (v1 >= v0)
 100.329 +			inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1);
 100.330 +		else
 100.331 +			inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
 100.332 +	}
 100.333 +	if (layerEnable & 0x4000)
 100.334 +	{
 100.335 +		u8 v0 = WIN1V >> 8;
 100.336 +		u8 v1 = WIN1V & 255;
 100.337 +		inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
 100.338 +		if (v1 >= v0)
 100.339 +			inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1);
 100.340 +		else
 100.341 +			inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
 100.342 +	}
 100.343 +
 100.344 +	if (layerEnable & 0x0100)
 100.345 +	{
 100.346 +		gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0);
 100.347 +	}
 100.348 +
 100.349 +	if (layerEnable & 0x0200)
 100.350 +	{
 100.351 +		gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1);
 100.352 +	}
 100.353 +
 100.354 +	if (layerEnable & 0x0400)
 100.355 +	{
 100.356 +		int changed = gfxBG2Changed;
 100.357 +		if (gfxLastVCOUNT > VCOUNT)
 100.358 +			changed = 3;
 100.359 +		gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
 100.360 +		                 BG2PA, BG2PB, BG2PC, BG2PD,
 100.361 +		                 gfxBG2X, gfxBG2Y, changed, line2);
 100.362 +	}
 100.363 +
 100.364 +	gfxDrawSprites(lineOBJ);
 100.365 +	gfxDrawOBJWin(lineOBJWin);
 100.366 +
 100.367 +	u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
 100.368 +
 100.369 +	u8 inWin0Mask = WININ & 0xFF;
 100.370 +	u8 inWin1Mask = WININ >> 8;
 100.371 +	u8 outMask    = WINOUT & 0xFF;
 100.372 +
 100.373 +	for (int x = 0; x < 240; x++)
 100.374 +	{
 100.375 +		u32 color = backdrop;
 100.376 +		u8  top   = 0x20;
 100.377 +		u8  mask  = outMask;
 100.378 +
 100.379 +		if (!(lineOBJWin[x] & 0x80000000))
 100.380 +		{
 100.381 +			mask = WINOUT >> 8;
 100.382 +		}
 100.383 +
 100.384 +		if (inWindow1)
 100.385 +		{
 100.386 +			if (gfxInWin1[x])
 100.387 +				mask = inWin1Mask;
 100.388 +		}
 100.389 +
 100.390 +		if (inWindow0)
 100.391 +		{
 100.392 +			if (gfxInWin0[x])
 100.393 +			{
 100.394 +				mask = inWin0Mask;
 100.395 +			}
 100.396 +		}
 100.397 +
 100.398 +		if (line0[x] < color && (mask & 1))
 100.399 +		{
 100.400 +			color = line0[x];
 100.401 +			top   = 0x01;
 100.402 +		}
 100.403 +
 100.404 +		if ((u8)(line1[x]>>24) < (u8)(color >> 24) && (mask & 2))
 100.405 +		{
 100.406 +			color = line1[x];
 100.407 +			top   = 0x02;
 100.408 +		}
 100.409 +
 100.410 +		if ((u8)(line2[x]>>24) < (u8)(color >> 24) && (mask & 4))
 100.411 +		{
 100.412 +			color = line2[x];
 100.413 +			top   = 0x04;
 100.414 +		}
 100.415 +
 100.416 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24) && (mask & 16))
 100.417 +		{
 100.418 +			color = lineOBJ[x];
 100.419 +			top   = 0x10;
 100.420 +		}
 100.421 +
 100.422 +		// special FX on the window
 100.423 +		if (mask & 32)
 100.424 +		{
 100.425 +			if (!(color & 0x00010000))
 100.426 +			{
 100.427 +				switch ((BLDMOD >> 6) & 3)
 100.428 +				{
 100.429 +				case 0:
 100.430 +					break;
 100.431 +				case 1:
 100.432 +				{
 100.433 +					if (top & BLDMOD)
 100.434 +					{
 100.435 +						u32 back = backdrop;
 100.436 +						u8  top2 = 0x20;
 100.437 +						if ((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24))
 100.438 +						{
 100.439 +							if (top != 0x01)
 100.440 +							{
 100.441 +								back = line0[x];
 100.442 +								top2 = 0x01;
 100.443 +							}
 100.444 +						}
 100.445 +
 100.446 +						if ((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24))
 100.447 +						{
 100.448 +							if (top != 0x02)
 100.449 +							{
 100.450 +								back = line1[x];
 100.451 +								top2 = 0x02;
 100.452 +							}
 100.453 +						}
 100.454 +
 100.455 +						if ((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24))
 100.456 +						{
 100.457 +							if (top != 0x04)
 100.458 +							{
 100.459 +								back = line2[x];
 100.460 +								top2 = 0x04;
 100.461 +							}
 100.462 +						}
 100.463 +
 100.464 +						if ((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
 100.465 +						{
 100.466 +							if (top != 0x10)
 100.467 +							{
 100.468 +								back = lineOBJ[x];
 100.469 +								top2 = 0x10;
 100.470 +							}
 100.471 +						}
 100.472 +
 100.473 +						if (top2 & (BLDMOD>>8))
 100.474 +							color = gfxAlphaBlend(color, back,
 100.475 +							                      coeff[COLEV & 0x1F],
 100.476 +							                      coeff[(COLEV >> 8) & 0x1F]);
 100.477 +					}
 100.478 +					break;
 100.479 +				}
 100.480 +				case 2:
 100.481 +					if (BLDMOD & top)
 100.482 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 100.483 +					break;
 100.484 +				case 3:
 100.485 +					if (BLDMOD & top)
 100.486 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 100.487 +					break;
 100.488 +				}
 100.489 +			}
 100.490 +			else
 100.491 +			{
 100.492 +				// semi-transparent OBJ
 100.493 +				u32 back = backdrop;
 100.494 +				u8  top2 = 0x20;
 100.495 +
 100.496 +				if ((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24))
 100.497 +				{
 100.498 +					back = line0[x];
 100.499 +					top2 = 0x01;
 100.500 +				}
 100.501 +
 100.502 +				if ((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24))
 100.503 +				{
 100.504 +					back = line1[x];
 100.505 +					top2 = 0x02;
 100.506 +				}
 100.507 +
 100.508 +				if ((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24))
 100.509 +				{
 100.510 +					back = line2[x];
 100.511 +					top2 = 0x04;
 100.512 +				}
 100.513 +
 100.514 +				if (top2 & (BLDMOD>>8))
 100.515 +					color = gfxAlphaBlend(color, back,
 100.516 +					                      coeff[COLEV & 0x1F],
 100.517 +					                      coeff[(COLEV >> 8) & 0x1F]);
 100.518 +				else
 100.519 +				{
 100.520 +					switch ((BLDMOD >> 6) & 3)
 100.521 +					{
 100.522 +					case 2:
 100.523 +						if (BLDMOD & top)
 100.524 +							color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 100.525 +						break;
 100.526 +					case 3:
 100.527 +						if (BLDMOD & top)
 100.528 +							color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 100.529 +						break;
 100.530 +					}
 100.531 +				}
 100.532 +			}
 100.533 +		}
 100.534 +		else if (color & 0x00010000)
 100.535 +		{
 100.536 +			// semi-transparent OBJ
 100.537 +			u32 back = backdrop;
 100.538 +			u8  top2 = 0x20;
 100.539 +
 100.540 +			if ((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24))
 100.541 +			{
 100.542 +				back = line0[x];
 100.543 +				top2 = 0x01;
 100.544 +			}
 100.545 +
 100.546 +			if ((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24))
 100.547 +			{
 100.548 +				back = line1[x];
 100.549 +				top2 = 0x02;
 100.550 +			}
 100.551 +
 100.552 +			if ((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24))
 100.553 +			{
 100.554 +				back = line2[x];
 100.555 +				top2 = 0x04;
 100.556 +			}
 100.557 +
 100.558 +			if (top2 & (BLDMOD>>8))
 100.559 +				color = gfxAlphaBlend(color, back,
 100.560 +				                      coeff[COLEV & 0x1F],
 100.561 +				                      coeff[(COLEV >> 8) & 0x1F]);
 100.562 +			else
 100.563 +			{
 100.564 +				switch ((BLDMOD >> 6) & 3)
 100.565 +				{
 100.566 +				case 2:
 100.567 +					if (BLDMOD & top)
 100.568 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 100.569 +					break;
 100.570 +				case 3:
 100.571 +					if (BLDMOD & top)
 100.572 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 100.573 +					break;
 100.574 +				}
 100.575 +			}
 100.576 +		}
 100.577 +
 100.578 +		lineMix[x] = color;
 100.579 +	}
 100.580 +	gfxBG2Changed = 0;
 100.581 +	gfxLastVCOUNT = VCOUNT;
 100.582 +}
 100.583 +
   101.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   101.2 +++ b/src/gba/Mode2.cpp	Sat Mar 03 10:31:27 2012 -0600
   101.3 @@ -0,0 +1,530 @@
   101.4 +#include "GBAGfx.h"
   101.5 +#include "GBAGlobals.h"
   101.6 +
   101.7 +void mode2RenderLine()
   101.8 +{
   101.9 +	u16 *palette = (u16 *)paletteRAM;
  101.10 +
  101.11 +	if (DISPCNT & 0x80)
  101.12 +	{
  101.13 +		for (int x = 0; x < 240; x++)
  101.14 +		{
  101.15 +			lineMix[x] = 0x7fff;
  101.16 +		}
  101.17 +		gfxLastVCOUNT = VCOUNT;
  101.18 +		return;
  101.19 +	}
  101.20 +
  101.21 +	if (layerEnable & 0x0400)
  101.22 +	{
  101.23 +		int changed = gfxBG2Changed;
  101.24 +		if (gfxLastVCOUNT > VCOUNT)
  101.25 +			changed = 3;
  101.26 +
  101.27 +		gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
  101.28 +		                 BG2PA, BG2PB, BG2PC, BG2PD, gfxBG2X, gfxBG2Y,
  101.29 +		                 changed, line2);
  101.30 +	}
  101.31 +
  101.32 +	if (layerEnable & 0x0800)
  101.33 +	{
  101.34 +		int changed = gfxBG3Changed;
  101.35 +		if (gfxLastVCOUNT > VCOUNT)
  101.36 +			changed = 3;
  101.37 +
  101.38 +		gfxDrawRotScreen(BG3CNT, BG3X_L, BG3X_H, BG3Y_L, BG3Y_H,
  101.39 +		                 BG3PA, BG3PB, BG3PC, BG3PD, gfxBG3X, gfxBG3Y,
  101.40 +		                 changed, line3);
  101.41 +	}
  101.42 +
  101.43 +	gfxDrawSprites(lineOBJ);
  101.44 +
  101.45 +	u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
  101.46 +
  101.47 +	for (int x = 0; x < 240; x++)
  101.48 +	{
  101.49 +		u32 color = backdrop;
  101.50 +		u8  top   = 0x20;
  101.51 +
  101.52 +		if ((u8)(line2[x]>>24) < (u8)(color >> 24))
  101.53 +		{
  101.54 +			color = line2[x];
  101.55 +			top   = 0x04;
  101.56 +		}
  101.57 +
  101.58 +		if ((u8)(line3[x]>>24) < (u8)(color >> 24))
  101.59 +		{
  101.60 +			color = line3[x];
  101.61 +			top   = 0x08;
  101.62 +		}
  101.63 +
  101.64 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))
  101.65 +		{
  101.66 +			color = lineOBJ[x];
  101.67 +			top   = 0x10;
  101.68 +		}
  101.69 +
  101.70 +		if ((top & 0x10) && (color & 0x00010000))
  101.71 +		{
  101.72 +			// semi-transparent OBJ
  101.73 +			u32 back = backdrop;
  101.74 +			u8  top2 = 0x20;
  101.75 +
  101.76 +			if ((u8)(line2[x]>>24) < (u8)(back >> 24))
  101.77 +			{
  101.78 +				back = line2[x];
  101.79 +				top2 = 0x04;
  101.80 +			}
  101.81 +
  101.82 +			if ((u8)(line3[x]>>24) < (u8)(back >> 24))
  101.83 +			{
  101.84 +				back = line3[x];
  101.85 +				top2 = 0x08;
  101.86 +			}
  101.87 +
  101.88 +			if (top2 & (BLDMOD>>8))
  101.89 +				color = gfxAlphaBlend(color, back,
  101.90 +				                      coeff[COLEV & 0x1F],
  101.91 +				                      coeff[(COLEV >> 8) & 0x1F]);
  101.92 +			else
  101.93 +			{
  101.94 +				switch ((BLDMOD >> 6) & 3)
  101.95 +				{
  101.96 +				case 2:
  101.97 +					if (BLDMOD & top)
  101.98 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
  101.99 +					break;
 101.100 +				case 3:
 101.101 +					if (BLDMOD & top)
 101.102 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 101.103 +					break;
 101.104 +				}
 101.105 +			}
 101.106 +		}
 101.107 +
 101.108 +		lineMix[x] = color;
 101.109 +	}
 101.110 +	gfxBG2Changed = 0;
 101.111 +	gfxBG3Changed = 0;
 101.112 +	gfxLastVCOUNT = VCOUNT;
 101.113 +}
 101.114 +
 101.115 +void mode2RenderLineNoWindow()
 101.116 +{
 101.117 +	u16 *palette = (u16 *)paletteRAM;
 101.118 +
 101.119 +	if (DISPCNT & 0x80)
 101.120 +	{
 101.121 +		for (int x = 0; x < 240; x++)
 101.122 +		{
 101.123 +			lineMix[x] = 0x7fff;
 101.124 +		}
 101.125 +		gfxLastVCOUNT = VCOUNT;
 101.126 +		return;
 101.127 +	}
 101.128 +
 101.129 +	if (layerEnable & 0x0400)
 101.130 +	{
 101.131 +		int changed = gfxBG2Changed;
 101.132 +		if (gfxLastVCOUNT > VCOUNT)
 101.133 +			changed = 3;
 101.134 +
 101.135 +		gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
 101.136 +		                 BG2PA, BG2PB, BG2PC, BG2PD, gfxBG2X, gfxBG2Y,
 101.137 +		                 changed, line2);
 101.138 +	}
 101.139 +
 101.140 +	if (layerEnable & 0x0800)
 101.141 +	{
 101.142 +		int changed = gfxBG3Changed;
 101.143 +		if (gfxLastVCOUNT > VCOUNT)
 101.144 +			changed = 3;
 101.145 +
 101.146 +		gfxDrawRotScreen(BG3CNT, BG3X_L, BG3X_H, BG3Y_L, BG3Y_H,
 101.147 +		                 BG3PA, BG3PB, BG3PC, BG3PD, gfxBG3X, gfxBG3Y,
 101.148 +		                 changed, line3);
 101.149 +	}
 101.150 +
 101.151 +	gfxDrawSprites(lineOBJ);
 101.152 +
 101.153 +	u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
 101.154 +
 101.155 +	for (int x = 0; x < 240; x++)
 101.156 +	{
 101.157 +		u32 color = backdrop;
 101.158 +		u8  top   = 0x20;
 101.159 +
 101.160 +		if ((u8)(line2[x]>>24) < (u8)(color >> 24))
 101.161 +		{
 101.162 +			color = line2[x];
 101.163 +			top   = 0x04;
 101.164 +		}
 101.165 +
 101.166 +		if ((u8)(line3[x]>>24) < (u8)(color >> 24))
 101.167 +		{
 101.168 +			color = line3[x];
 101.169 +			top   = 0x08;
 101.170 +		}
 101.171 +
 101.172 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))
 101.173 +		{
 101.174 +			color = lineOBJ[x];
 101.175 +			top   = 0x10;
 101.176 +		}
 101.177 +
 101.178 +		if (!(color & 0x00010000))
 101.179 +		{
 101.180 +			switch ((BLDMOD >> 6) & 3)
 101.181 +			{
 101.182 +			case 0:
 101.183 +				break;
 101.184 +			case 1:
 101.185 +			{
 101.186 +				if (top & BLDMOD)
 101.187 +				{
 101.188 +					u32 back = backdrop;
 101.189 +					u8  top2 = 0x20;
 101.190 +
 101.191 +					if ((u8)(line2[x]>>24) < (u8)(back >> 24))
 101.192 +					{
 101.193 +						if (top != 0x04)
 101.194 +						{
 101.195 +							back = line2[x];
 101.196 +							top2 = 0x04;
 101.197 +						}
 101.198 +					}
 101.199 +
 101.200 +					if ((u8)(line3[x]>>24) < (u8)(back >> 24))
 101.201 +					{
 101.202 +						if (top != 0x08)
 101.203 +						{
 101.204 +							back = line3[x];
 101.205 +							top2 = 0x08;
 101.206 +						}
 101.207 +					}
 101.208 +
 101.209 +					if ((u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
 101.210 +					{
 101.211 +						if (top != 0x10)
 101.212 +						{
 101.213 +							back = lineOBJ[x];
 101.214 +							top2 = 0x10;
 101.215 +						}
 101.216 +					}
 101.217 +
 101.218 +					if (top2 & (BLDMOD>>8))
 101.219 +						color = gfxAlphaBlend(color, back,
 101.220 +						                      coeff[COLEV & 0x1F],
 101.221 +						                      coeff[(COLEV >> 8) & 0x1F]);
 101.222 +				}
 101.223 +				break;
 101.224 +			}
 101.225 +			case 2:
 101.226 +				if (BLDMOD & top)
 101.227 +					color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 101.228 +				break;
 101.229 +			case 3:
 101.230 +				if (BLDMOD & top)
 101.231 +					color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 101.232 +				break;
 101.233 +			}
 101.234 +		}
 101.235 +		else
 101.236 +		{
 101.237 +			// semi-transparent OBJ
 101.238 +			u32 back = backdrop;
 101.239 +			u8  top2 = 0x20;
 101.240 +
 101.241 +			if ((u8)(line2[x]>>24) < (u8)(back >> 24))
 101.242 +			{
 101.243 +				back = line2[x];
 101.244 +				top2 = 0x04;
 101.245 +			}
 101.246 +
 101.247 +			if ((u8)(line3[x]>>24) < (u8)(back >> 24))
 101.248 +			{
 101.249 +				back = line3[x];
 101.250 +				top2 = 0x08;
 101.251 +			}
 101.252 +
 101.253 +			if (top2 & (BLDMOD>>8))
 101.254 +				color = gfxAlphaBlend(color, back,
 101.255 +				                      coeff[COLEV & 0x1F],
 101.256 +				                      coeff[(COLEV >> 8) & 0x1F]);
 101.257 +			else
 101.258 +			{
 101.259 +				switch ((BLDMOD >> 6) & 3)
 101.260 +				{
 101.261 +				case 2:
 101.262 +					if (BLDMOD & top)
 101.263 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 101.264 +					break;
 101.265 +				case 3:
 101.266 +					if (BLDMOD & top)
 101.267 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 101.268 +					break;
 101.269 +				}
 101.270 +			}
 101.271 +		}
 101.272 +
 101.273 +		lineMix[x] = color;
 101.274 +	}
 101.275 +	gfxBG2Changed = 0;
 101.276 +	gfxBG3Changed = 0;
 101.277 +	gfxLastVCOUNT = VCOUNT;
 101.278 +}
 101.279 +
 101.280 +void mode2RenderLineAll()
 101.281 +{
 101.282 +	u16 *palette = (u16 *)paletteRAM;
 101.283 +
 101.284 +	if (DISPCNT & 0x80)
 101.285 +	{
 101.286 +		for (int x = 0; x < 240; x++)
 101.287 +		{
 101.288 +			lineMix[x] = 0x7fff;
 101.289 +		}
 101.290 +		gfxLastVCOUNT = VCOUNT;
 101.291 +		return;
 101.292 +	}
 101.293 +
 101.294 +	bool inWindow0 = false;
 101.295 +	bool inWindow1 = false;
 101.296 +
 101.297 +	if (layerEnable & 0x2000)
 101.298 +	{
 101.299 +		u8 v0 = WIN0V >> 8;
 101.300 +		u8 v1 = WIN0V & 255;
 101.301 +		inWindow0 = ((v0 == v1) && (v0 >= 0xe8));
 101.302 +		if (v1 >= v0)
 101.303 +			inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1);
 101.304 +		else
 101.305 +			inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
 101.306 +	}
 101.307 +	if (layerEnable & 0x4000)
 101.308 +	{
 101.309 +		u8 v0 = WIN1V >> 8;
 101.310 +		u8 v1 = WIN1V & 255;
 101.311 +		inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
 101.312 +		if (v1 >= v0)
 101.313 +			inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1);
 101.314 +		else
 101.315 +			inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
 101.316 +	}
 101.317 +
 101.318 +	if (layerEnable & 0x0400)
 101.319 +	{
 101.320 +		int changed = gfxBG2Changed;
 101.321 +		if (gfxLastVCOUNT > VCOUNT)
 101.322 +			changed = 3;
 101.323 +
 101.324 +		gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
 101.325 +		                 BG2PA, BG2PB, BG2PC, BG2PD, gfxBG2X, gfxBG2Y,
 101.326 +		                 changed, line2);
 101.327 +	}
 101.328 +
 101.329 +	if (layerEnable & 0x0800)
 101.330 +	{
 101.331 +		int changed = gfxBG3Changed;
 101.332 +		if (gfxLastVCOUNT > VCOUNT)
 101.333 +			changed = 3;
 101.334 +
 101.335 +		gfxDrawRotScreen(BG3CNT, BG3X_L, BG3X_H, BG3Y_L, BG3Y_H,
 101.336 +		                 BG3PA, BG3PB, BG3PC, BG3PD, gfxBG3X, gfxBG3Y,
 101.337 +		                 changed, line3);
 101.338 +	}
 101.339 +
 101.340 +	gfxDrawSprites(lineOBJ);
 101.341 +	gfxDrawOBJWin(lineOBJWin);
 101.342 +
 101.343 +	u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
 101.344 +
 101.345 +	u8 inWin0Mask = WININ & 0xFF;
 101.346 +	u8 inWin1Mask = WININ >> 8;
 101.347 +	u8 outMask    = WINOUT & 0xFF;
 101.348 +
 101.349 +	for (int x = 0; x < 240; x++)
 101.350 +	{
 101.351 +		u32 color = backdrop;
 101.352 +		u8  top   = 0x20;
 101.353 +		u8  mask  = outMask;
 101.354 +
 101.355 +		if (!(lineOBJWin[x] & 0x80000000))
 101.356 +		{
 101.357 +			mask = WINOUT >> 8;
 101.358 +		}
 101.359 +
 101.360 +		if (inWindow1)
 101.361 +		{
 101.362 +			if (gfxInWin1[x])
 101.363 +				mask = inWin1Mask;
 101.364 +		}
 101.365 +
 101.366 +		if (inWindow0)
 101.367 +		{
 101.368 +			if (gfxInWin0[x])
 101.369 +			{
 101.370 +				mask = inWin0Mask;
 101.371 +			}
 101.372 +		}
 101.373 +
 101.374 +		if (line2[x] < color && (mask & 4))
 101.375 +		{
 101.376 +			color = line2[x];
 101.377 +			top   = 0x04;
 101.378 +		}
 101.379 +
 101.380 +		if ((u8)(line3[x]>>24) < (u8)(color >> 24) && (mask & 8))
 101.381 +		{
 101.382 +			color = line3[x];
 101.383 +			top   = 0x08;
 101.384 +		}
 101.385 +
 101.386 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24) && (mask & 16))
 101.387 +		{
 101.388 +			color = lineOBJ[x];
 101.389 +			top   = 0x10;
 101.390 +		}
 101.391 +
 101.392 +		if (mask & 32)
 101.393 +		{
 101.394 +			if (!(color & 0x00010000))
 101.395 +			{
 101.396 +				switch ((BLDMOD >> 6) & 3)
 101.397 +				{
 101.398 +				case 0:
 101.399 +					break;
 101.400 +				case 1:
 101.401 +				{
 101.402 +					if (top & BLDMOD)
 101.403 +					{
 101.404 +						u32 back = backdrop;
 101.405 +						u8  top2 = 0x20;
 101.406 +
 101.407 +						if ((mask & 4) && line2[x] < back)
 101.408 +						{
 101.409 +							if (top != 0x04)
 101.410 +							{
 101.411 +								back = line2[x];
 101.412 +								top2 = 0x04;
 101.413 +							}
 101.414 +						}
 101.415 +
 101.416 +						if ((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24))
 101.417 +						{
 101.418 +							if (top != 0x08)
 101.419 +							{
 101.420 +								back = line3[x];
 101.421 +								top2 = 0x08;
 101.422 +							}
 101.423 +						}
 101.424 +
 101.425 +						if ((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
 101.426 +						{
 101.427 +							if (top != 0x10)
 101.428 +							{
 101.429 +								back = lineOBJ[x];
 101.430 +								top2 = 0x10;
 101.431 +							}
 101.432 +						}
 101.433 +
 101.434 +						if (top2 & (BLDMOD>>8))
 101.435 +							color = gfxAlphaBlend(color, back,
 101.436 +							                      coeff[COLEV & 0x1F],
 101.437 +							                      coeff[(COLEV >> 8) & 0x1F]);
 101.438 +					}
 101.439 +					break;
 101.440 +				}
 101.441 +				case 2:
 101.442 +					if (BLDMOD & top)
 101.443 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 101.444 +					break;
 101.445 +				case 3:
 101.446 +					if (BLDMOD & top)
 101.447 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 101.448 +					break;
 101.449 +				}
 101.450 +			}
 101.451 +			else
 101.452 +			{
 101.453 +				// semi-transparent OBJ
 101.454 +				u32 back = backdrop;
 101.455 +				u8  top2 = 0x20;
 101.456 +
 101.457 +				if ((mask & 4) && line2[x] < back)
 101.458 +				{
 101.459 +					back = line2[x];
 101.460 +					top2 = 0x04;
 101.461 +				}
 101.462 +
 101.463 +				if ((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24))
 101.464 +				{
 101.465 +					back = line3[x];
 101.466 +					top2 = 0x08;
 101.467 +				}
 101.468 +
 101.469 +				if (top2 & (BLDMOD>>8))
 101.470 +					color = gfxAlphaBlend(color, back,
 101.471 +					                      coeff[COLEV & 0x1F],
 101.472 +					                      coeff[(COLEV >> 8) & 0x1F]);
 101.473 +				else
 101.474 +				{
 101.475 +					switch ((BLDMOD >> 6) & 3)
 101.476 +					{
 101.477 +					case 2:
 101.478 +						if (BLDMOD & top)
 101.479 +							color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 101.480 +						break;
 101.481 +					case 3:
 101.482 +						if (BLDMOD & top)
 101.483 +							color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 101.484 +						break;
 101.485 +					}
 101.486 +				}
 101.487 +			}
 101.488 +		}
 101.489 +		else if (color & 0x00010000)
 101.490 +		{
 101.491 +			// semi-transparent OBJ
 101.492 +			u32 back = backdrop;
 101.493 +			u8  top2 = 0x20;
 101.494 +
 101.495 +			if ((mask & 4) && line2[x] < back)
 101.496 +			{
 101.497 +				back = line2[x];
 101.498 +				top2 = 0x04;
 101.499 +			}
 101.500 +
 101.501 +			if ((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24))
 101.502 +			{
 101.503 +				back = line3[x];
 101.504 +				top2 = 0x08;
 101.505 +			}
 101.506 +
 101.507 +			if (top2 & (BLDMOD>>8))
 101.508 +				color = gfxAlphaBlend(color, back,
 101.509 +				                      coeff[COLEV & 0x1F],
 101.510 +				                      coeff[(COLEV >> 8) & 0x1F]);
 101.511 +			else
 101.512 +			{
 101.513 +				switch ((BLDMOD >> 6) & 3)
 101.514 +				{
 101.515 +				case 2:
 101.516 +					if (BLDMOD & top)
 101.517 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 101.518 +					break;
 101.519 +				case 3:
 101.520 +					if (BLDMOD & top)
 101.521 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 101.522 +					break;
 101.523 +				}
 101.524 +			}
 101.525 +		}
 101.526 +
 101.527 +		lineMix[x] = color;
 101.528 +	}
 101.529 +	gfxBG2Changed = 0;
 101.530 +	gfxBG3Changed = 0;
 101.531 +	gfxLastVCOUNT = VCOUNT;
 101.532 +}
 101.533 +
   102.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   102.2 +++ b/src/gba/Mode3.cpp	Sat Mar 03 10:31:27 2012 -0600
   102.3 @@ -0,0 +1,443 @@
   102.4 +#include "GBAGfx.h"
   102.5 +#include "GBAGlobals.h"
   102.6 +
   102.7 +void mode3RenderLine()
   102.8 +{
   102.9 +	u16 *palette = (u16 *)paletteRAM;
  102.10 +
  102.11 +	if (DISPCNT & 0x80)
  102.12 +	{
  102.13 +		for (int x = 0; x < 240; x++)
  102.14 +		{
  102.15 +			lineMix[x] = 0x7fff;
  102.16 +		}
  102.17 +		gfxLastVCOUNT = VCOUNT;
  102.18 +		return;
  102.19 +	}
  102.20 +
  102.21 +	if (layerEnable & 0x0400)
  102.22 +	{
  102.23 +		int changed = gfxBG2Changed;
  102.24 +
  102.25 +		if (gfxLastVCOUNT > VCOUNT)
  102.26 +			changed = 3;
  102.27 +
  102.28 +		gfxDrawRotScreen16Bit(BG2CNT, BG2X_L, BG2X_H,
  102.29 +		                      BG2Y_L, BG2Y_H, BG2PA, BG2PB,
  102.30 +		                      BG2PC, BG2PD,
  102.31 +		                      gfxBG2X, gfxBG2Y, changed,
  102.32 +		                      line2);
  102.33 +	}
  102.34 +
  102.35 +	gfxDrawSprites(lineOBJ);
  102.36 +
  102.37 +	u32 background = (READ16LE(&palette[0]) | 0x30000000);
  102.38 +
  102.39 +	for (int x = 0; x < 240; x++)
  102.40 +	{
  102.41 +		u32 color = background;
  102.42 +		u8  top   = 0x20;
  102.43 +
  102.44 +		if (line2[x] < color)
  102.45 +		{
  102.46 +			color = line2[x];
  102.47 +			top   = 0x04;
  102.48 +		}
  102.49 +
  102.50 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >>24))
  102.51 +		{
  102.52 +			color = lineOBJ[x];
  102.53 +			top   = 0x10;
  102.54 +		}
  102.55 +
  102.56 +		if ((top & 0x10) && (color & 0x00010000))
  102.57 +		{
  102.58 +			// semi-transparent OBJ
  102.59 +			u32 back = background;
  102.60 +			u8  top2 = 0x20;
  102.61 +
  102.62 +			if (line2[x] < back)
  102.63 +			{
  102.64 +				back = line2[x];
  102.65 +				top2 = 0x04;
  102.66 +			}
  102.67 +
  102.68 +			if (top2 & (BLDMOD>>8))
  102.69 +				color = gfxAlphaBlend(color, back,
  102.70 +				                      coeff[COLEV & 0x1F],
  102.71 +				                      coeff[(COLEV >> 8) & 0x1F]);
  102.72 +			else
  102.73 +			{
  102.74 +				switch ((BLDMOD >> 6) & 3)
  102.75 +				{
  102.76 +				case 2:
  102.77 +					if (BLDMOD & top)
  102.78 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
  102.79 +					break;
  102.80 +				case 3:
  102.81 +					if (BLDMOD & top)
  102.82 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
  102.83 +					break;
  102.84 +				}
  102.85 +			}
  102.86 +		}
  102.87 +
  102.88 +		lineMix[x] = color;
  102.89 +	}
  102.90 +	gfxBG2Changed = 0;
  102.91 +	gfxLastVCOUNT = VCOUNT;
  102.92 +}
  102.93 +
  102.94 +void mode3RenderLineNoWindow()
  102.95 +{
  102.96 +	u16 *palette = (u16 *)paletteRAM;
  102.97 +
  102.98 +	if (DISPCNT & 0x80)
  102.99 +	{
 102.100 +		for (int x = 0; x < 240; x++)
 102.101 +		{
 102.102 +			lineMix[x] = 0x7fff;
 102.103 +		}
 102.104 +		gfxLastVCOUNT = VCOUNT;
 102.105 +		return;
 102.106 +	}
 102.107 +
 102.108 +	if (layerEnable & 0x0400)
 102.109 +	{
 102.110 +		int changed = gfxBG2Changed;
 102.111 +
 102.112 +		if (gfxLastVCOUNT > VCOUNT)
 102.113 +			changed = 3;
 102.114 +
 102.115 +		gfxDrawRotScreen16Bit(BG2CNT, BG2X_L, BG2X_H,
 102.116 +		                      BG2Y_L, BG2Y_H, BG2PA, BG2PB,
 102.117 +		                      BG2PC, BG2PD,
 102.118 +		                      gfxBG2X, gfxBG2Y, changed,
 102.119 +		                      line2);
 102.120 +	}
 102.121 +
 102.122 +	gfxDrawSprites(lineOBJ);
 102.123 +
 102.124 +	u32 background = (READ16LE(&palette[0]) | 0x30000000);
 102.125 +
 102.126 +	for (int x = 0; x < 240; x++)
 102.127 +	{
 102.128 +		u32 color = background;
 102.129 +		u8  top   = 0x20;
 102.130 +
 102.131 +		if (line2[x] < color)
 102.132 +		{
 102.133 +			color = line2[x];
 102.134 +			top   = 0x04;
 102.135 +		}
 102.136 +
 102.137 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >>24))
 102.138 +		{
 102.139 +			color = lineOBJ[x];
 102.140 +			top   = 0x10;
 102.141 +		}
 102.142 +
 102.143 +		if (!(color & 0x00010000))
 102.144 +		{
 102.145 +			switch ((BLDMOD >> 6) & 3)
 102.146 +			{
 102.147 +			case 0:
 102.148 +				break;
 102.149 +			case 1:
 102.150 +			{
 102.151 +				if (top & BLDMOD)
 102.152 +				{
 102.153 +					u32 back = background;
 102.154 +					u8  top2 = 0x20;
 102.155 +
 102.156 +					if (line2[x] < back)
 102.157 +					{
 102.158 +						if (top != 0x04)
 102.159 +						{
 102.160 +							back = line2[x];
 102.161 +							top2 = 0x04;
 102.162 +						}
 102.163 +					}
 102.164 +
 102.165 +					if ((u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
 102.166 +					{
 102.167 +						if (top != 0x10)
 102.168 +						{
 102.169 +							back = lineOBJ[x];
 102.170 +							top2 = 0x10;
 102.171 +						}
 102.172 +					}
 102.173 +
 102.174 +					if (top2 & (BLDMOD>>8))
 102.175 +						color = gfxAlphaBlend(color, back,
 102.176 +						                      coeff[COLEV & 0x1F],
 102.177 +						                      coeff[(COLEV >> 8) & 0x1F]);
 102.178 +				}
 102.179 +				break;
 102.180 +			}
 102.181 +			case 2:
 102.182 +				if (BLDMOD & top)
 102.183 +					color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 102.184 +				break;
 102.185 +			case 3:
 102.186 +				if (BLDMOD & top)
 102.187 +					color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 102.188 +				break;
 102.189 +			}
 102.190 +		}
 102.191 +		else
 102.192 +		{
 102.193 +			// semi-transparent OBJ
 102.194 +			u32 back = background;
 102.195 +			u8  top2 = 0x20;
 102.196 +
 102.197 +			if (line2[x] < back)
 102.198 +			{
 102.199 +				back = line2[x];
 102.200 +				top2 = 0x04;
 102.201 +			}
 102.202 +
 102.203 +			if (top2 & (BLDMOD>>8))
 102.204 +				color = gfxAlphaBlend(color, back,
 102.205 +				                      coeff[COLEV & 0x1F],
 102.206 +				                      coeff[(COLEV >> 8) & 0x1F]);
 102.207 +			else
 102.208 +			{
 102.209 +				switch ((BLDMOD >> 6) & 3)
 102.210 +				{
 102.211 +				case 2:
 102.212 +					if (BLDMOD & top)
 102.213 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 102.214 +					break;
 102.215 +				case 3:
 102.216 +					if (BLDMOD & top)
 102.217 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 102.218 +					break;
 102.219 +				}
 102.220 +			}
 102.221 +		}
 102.222 +
 102.223 +		lineMix[x] = color;
 102.224 +	}
 102.225 +	gfxBG2Changed = 0;
 102.226 +	gfxLastVCOUNT = VCOUNT;
 102.227 +}
 102.228 +
 102.229 +void mode3RenderLineAll()
 102.230 +{
 102.231 +	u16 *palette = (u16 *)paletteRAM;
 102.232 +
 102.233 +	if (DISPCNT & 0x80)
 102.234 +	{
 102.235 +		for (int x = 0; x < 240; x++)
 102.236 +		{
 102.237 +			lineMix[x] = 0x7fff;
 102.238 +		}
 102.239 +		gfxLastVCOUNT = VCOUNT;
 102.240 +		return;
 102.241 +	}
 102.242 +
 102.243 +	bool inWindow0 = false;
 102.244 +	bool inWindow1 = false;
 102.245 +
 102.246 +	if (layerEnable & 0x2000)
 102.247 +	{
 102.248 +		u8 v0 = WIN0V >> 8;
 102.249 +		u8 v1 = WIN0V & 255;
 102.250 +		inWindow0 = ((v0 == v1) && (v0 >= 0xe8));
 102.251 +		if (v1 >= v0)
 102.252 +			inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1);
 102.253 +		else
 102.254 +			inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
 102.255 +	}
 102.256 +	if (layerEnable & 0x4000)
 102.257 +	{
 102.258 +		u8 v0 = WIN1V >> 8;
 102.259 +		u8 v1 = WIN1V & 255;
 102.260 +		inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
 102.261 +		if (v1 >= v0)
 102.262 +			inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1);
 102.263 +		else
 102.264 +			inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
 102.265 +	}
 102.266 +
 102.267 +	if (layerEnable & 0x0400)
 102.268 +	{
 102.269 +		int changed = gfxBG2Changed;
 102.270 +
 102.271 +		if (gfxLastVCOUNT > VCOUNT)
 102.272 +			changed = 3;
 102.273 +
 102.274 +		gfxDrawRotScreen16Bit(BG2CNT, BG2X_L, BG2X_H,
 102.275 +		                      BG2Y_L, BG2Y_H, BG2PA, BG2PB,
 102.276 +		                      BG2PC, BG2PD,
 102.277 +		                      gfxBG2X, gfxBG2Y, changed,
 102.278 +		                      line2);
 102.279 +	}
 102.280 +
 102.281 +	gfxDrawSprites(lineOBJ);
 102.282 +	gfxDrawOBJWin(lineOBJWin);
 102.283 +
 102.284 +	u8 inWin0Mask = WININ & 0xFF;
 102.285 +	u8 inWin1Mask = WININ >> 8;
 102.286 +	u8 outMask    = WINOUT & 0xFF;
 102.287 +
 102.288 +	u32 background = (READ16LE(&palette[0]) | 0x30000000);
 102.289 +
 102.290 +	for (int x = 0; x < 240; x++)
 102.291 +	{
 102.292 +		u32 color = background;
 102.293 +		u8  top   = 0x20;
 102.294 +		u8  mask  = outMask;
 102.295 +
 102.296 +		if (!(lineOBJWin[x] & 0x80000000))
 102.297 +		{
 102.298 +			mask = WINOUT >> 8;
 102.299 +		}
 102.300 +
 102.301 +		if (inWindow1)
 102.302 +		{
 102.303 +			if (gfxInWin1[x])
 102.304 +				mask = inWin1Mask;
 102.305 +		}
 102.306 +
 102.307 +		if (inWindow0)
 102.308 +		{
 102.309 +			if (gfxInWin0[x])
 102.310 +			{
 102.311 +				mask = inWin0Mask;
 102.312 +			}
 102.313 +		}
 102.314 +
 102.315 +		if ((mask & 4) && (line2[x] < color))
 102.316 +		{
 102.317 +			color = line2[x];
 102.318 +			top   = 0x04;
 102.319 +		}
 102.320 +
 102.321 +		if ((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24)))
 102.322 +		{
 102.323 +			color = lineOBJ[x];
 102.324 +			top   = 0x10;
 102.325 +		}
 102.326 +
 102.327 +		if (mask & 32)
 102.328 +		{
 102.329 +			if (!(color & 0x00010000))
 102.330 +			{
 102.331 +				switch ((BLDMOD >> 6) & 3)
 102.332 +				{
 102.333 +				case 0:
 102.334 +					break;
 102.335 +				case 1:
 102.336 +				{
 102.337 +					if (top & BLDMOD)
 102.338 +					{
 102.339 +						u32 back = background;
 102.340 +						u8  top2 = 0x20;
 102.341 +
 102.342 +						if ((mask & 4) && line2[x] < back)
 102.343 +						{
 102.344 +							if (top != 0x04)
 102.345 +							{
 102.346 +								back = line2[x];
 102.347 +								top2 = 0x04;
 102.348 +							}
 102.349 +						}
 102.350 +
 102.351 +						if ((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
 102.352 +						{
 102.353 +							if (top != 0x10)
 102.354 +							{
 102.355 +								back = lineOBJ[x];
 102.356 +								top2 = 0x10;
 102.357 +							}
 102.358 +						}
 102.359 +
 102.360 +						if (top2 & (BLDMOD>>8))
 102.361 +							color = gfxAlphaBlend(color, back,
 102.362 +							                      coeff[COLEV & 0x1F],
 102.363 +							                      coeff[(COLEV >> 8) & 0x1F]);
 102.364 +					}
 102.365 +					break;
 102.366 +				}
 102.367 +				case 2:
 102.368 +					if (BLDMOD & top)
 102.369 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 102.370 +					break;
 102.371 +				case 3:
 102.372 +					if (BLDMOD & top)
 102.373 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 102.374 +					break;
 102.375 +				}
 102.376 +			}
 102.377 +			else
 102.378 +			{
 102.379 +				// semi-transparent OBJ
 102.380 +				u32 back = background;
 102.381 +				u8  top2 = 0x20;
 102.382 +
 102.383 +				if ((mask & 4) && line2[x] < back)
 102.384 +				{
 102.385 +					back = line2[x];
 102.386 +					top2 = 0x04;
 102.387 +				}
 102.388 +
 102.389 +				if (top2 & (BLDMOD>>8))
 102.390 +					color = gfxAlphaBlend(color, back,
 102.391 +					                      coeff[COLEV & 0x1F],
 102.392 +					                      coeff[(COLEV >> 8) & 0x1F]);
 102.393 +				else
 102.394 +				{
 102.395 +					switch ((BLDMOD >> 6) & 3)
 102.396 +					{
 102.397 +					case 2:
 102.398 +						if (BLDMOD & top)
 102.399 +							color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 102.400 +						break;
 102.401 +					case 3:
 102.402 +						if (BLDMOD & top)
 102.403 +							color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 102.404 +						break;
 102.405 +					}
 102.406 +				}
 102.407 +			}
 102.408 +		}
 102.409 +		else if (color & 0x00010000)
 102.410 +		{
 102.411 +			// semi-transparent OBJ
 102.412 +			u32 back = background;
 102.413 +			u8  top2 = 0x20;
 102.414 +
 102.415 +			if ((mask & 4) && line2[x] < back)
 102.416 +			{
 102.417 +				back = line2[x];
 102.418 +				top2 = 0x04;
 102.419 +			}
 102.420 +
 102.421 +			if (top2 & (BLDMOD>>8))
 102.422 +				color = gfxAlphaBlend(color, back,
 102.423 +				                      coeff[COLEV & 0x1F],
 102.424 +				                      coeff[(COLEV >> 8) & 0x1F]);
 102.425 +			else
 102.426 +			{
 102.427 +				switch ((BLDMOD >> 6) & 3)
 102.428 +				{
 102.429 +				case 2:
 102.430 +					if (BLDMOD & top)
 102.431 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 102.432 +					break;
 102.433 +				case 3:
 102.434 +					if (BLDMOD & top)
 102.435 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 102.436 +					break;
 102.437 +				}
 102.438 +			}
 102.439 +		}
 102.440 +
 102.441 +		lineMix[x] = color;
 102.442 +	}
 102.443 +	gfxBG2Changed = 0;
 102.444 +	gfxLastVCOUNT = VCOUNT;
 102.445 +}
 102.446 +
   103.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   103.2 +++ b/src/gba/Mode4.cpp	Sat Mar 03 10:31:27 2012 -0600
   103.3 @@ -0,0 +1,440 @@
   103.4 +#include "GBAGfx.h"
   103.5 +#include "GBAGlobals.h"
   103.6 +
   103.7 +void mode4RenderLine()
   103.8 +{
   103.9 +	u16 *palette = (u16 *)paletteRAM;
  103.10 +
  103.11 +	if (DISPCNT & 0x0080)
  103.12 +	{
  103.13 +		for (int x = 0; x < 240; x++)
  103.14 +		{
  103.15 +			lineMix[x] = 0x7fff;
  103.16 +		}
  103.17 +		gfxLastVCOUNT = VCOUNT;
  103.18 +		return;
  103.19 +	}
  103.20 +
  103.21 +	if (layerEnable & 0x400)
  103.22 +	{
  103.23 +		int changed = gfxBG2Changed;
  103.24 +
  103.25 +		if (gfxLastVCOUNT > VCOUNT)
  103.26 +			changed = 3;
  103.27 +
  103.28 +		gfxDrawRotScreen256(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
  103.29 +		                    BG2PA, BG2PB, BG2PC, BG2PD,
  103.30 +		                    gfxBG2X, gfxBG2Y, changed,
  103.31 +		                    line2);
  103.32 +	}
  103.33 +
  103.34 +	gfxDrawSprites(lineOBJ);
  103.35 +
  103.36 +	u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
  103.37 +
  103.38 +	for (int x = 0; x < 240; x++)
  103.39 +	{
  103.40 +		u32 color = backdrop;
  103.41 +		u8  top   = 0x20;
  103.42 +
  103.43 +		if (line2[x] < color)
  103.44 +		{
  103.45 +			color = line2[x];
  103.46 +			top   = 0x04;
  103.47 +		}
  103.48 +
  103.49 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))
  103.50 +		{
  103.51 +			color = lineOBJ[x];
  103.52 +			top   = 0x10;
  103.53 +		}
  103.54 +
  103.55 +		if ((top & 0x10) && (color & 0x00010000))
  103.56 +		{
  103.57 +			// semi-transparent OBJ
  103.58 +			u32 back = backdrop;
  103.59 +			u8  top2 = 0x20;
  103.60 +
  103.61 +			if (line2[x] < back)
  103.62 +			{
  103.63 +				back = line2[x];
  103.64 +				top2 = 0x04;
  103.65 +			}
  103.66 +
  103.67 +			if (top2 & (BLDMOD>>8))
  103.68 +				color = gfxAlphaBlend(color, back,
  103.69 +				                      coeff[COLEV & 0x1F],
  103.70 +				                      coeff[(COLEV >> 8) & 0x1F]);
  103.71 +			else
  103.72 +			{
  103.73 +				switch ((BLDMOD >> 6) & 3)
  103.74 +				{
  103.75 +				case 2:
  103.76 +					if (BLDMOD & top)
  103.77 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
  103.78 +					break;
  103.79 +				case 3:
  103.80 +					if (BLDMOD & top)
  103.81 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
  103.82 +					break;
  103.83 +				}
  103.84 +			}
  103.85 +		}
  103.86 +
  103.87 +		lineMix[x] = color;
  103.88 +	}
  103.89 +	gfxBG2Changed = 0;
  103.90 +	gfxLastVCOUNT = VCOUNT;
  103.91 +}
  103.92 +
  103.93 +void mode4RenderLineNoWindow()
  103.94 +{
  103.95 +	u16 *palette = (u16 *)paletteRAM;
  103.96 +
  103.97 +	if (DISPCNT & 0x0080)
  103.98 +	{
  103.99 +		for (int x = 0; x < 240; x++)
 103.100 +		{
 103.101 +			lineMix[x] = 0x7fff;
 103.102 +		}
 103.103 +		gfxLastVCOUNT = VCOUNT;
 103.104 +		return;
 103.105 +	}
 103.106 +
 103.107 +	if (layerEnable & 0x400)
 103.108 +	{
 103.109 +		int changed = gfxBG2Changed;
 103.110 +
 103.111 +		if (gfxLastVCOUNT > VCOUNT)
 103.112 +			changed = 3;
 103.113 +
 103.114 +		gfxDrawRotScreen256(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
 103.115 +		                    BG2PA, BG2PB, BG2PC, BG2PD,
 103.116 +		                    gfxBG2X, gfxBG2Y, changed,
 103.117 +		                    line2);
 103.118 +	}
 103.119 +
 103.120 +	gfxDrawSprites(lineOBJ);
 103.121 +
 103.122 +	u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
 103.123 +
 103.124 +	for (int x = 0; x < 240; x++)
 103.125 +	{
 103.126 +		u32 color = backdrop;
 103.127 +		u8  top   = 0x20;
 103.128 +
 103.129 +		if (line2[x] < color)
 103.130 +		{
 103.131 +			color = line2[x];
 103.132 +			top   = 0x04;
 103.133 +		}
 103.134 +
 103.135 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))
 103.136 +		{
 103.137 +			color = lineOBJ[x];
 103.138 +			top   = 0x10;
 103.139 +		}
 103.140 +
 103.141 +		if (!(color & 0x00010000))
 103.142 +		{
 103.143 +			switch ((BLDMOD >> 6) & 3)
 103.144 +			{
 103.145 +			case 0:
 103.146 +				break;
 103.147 +			case 1:
 103.148 +			{
 103.149 +				if (top & BLDMOD)
 103.150 +				{
 103.151 +					u32 back = backdrop;
 103.152 +					u8  top2 = 0x20;
 103.153 +
 103.154 +					if (line2[x] < back)
 103.155 +					{
 103.156 +						if (top != 0x04)
 103.157 +						{
 103.158 +							back = line2[x];
 103.159 +							top2 = 0x04;
 103.160 +						}
 103.161 +					}
 103.162 +
 103.163 +					if ((u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
 103.164 +					{
 103.165 +						if (top != 0x10)
 103.166 +						{
 103.167 +							back = lineOBJ[x];
 103.168 +							top2 = 0x10;
 103.169 +						}
 103.170 +					}
 103.171 +
 103.172 +					if (top2 & (BLDMOD>>8))
 103.173 +						color = gfxAlphaBlend(color, back,
 103.174 +						                      coeff[COLEV & 0x1F],
 103.175 +						                      coeff[(COLEV >> 8) & 0x1F]);
 103.176 +				}
 103.177 +				break;
 103.178 +			}
 103.179 +			case 2:
 103.180 +				if (BLDMOD & top)
 103.181 +					color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 103.182 +				break;
 103.183 +			case 3:
 103.184 +				if (BLDMOD & top)
 103.185 +					color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 103.186 +				break;
 103.187 +			}
 103.188 +		}
 103.189 +		else
 103.190 +		{
 103.191 +			// semi-transparent OBJ
 103.192 +			u32 back = backdrop;
 103.193 +			u8  top2 = 0x20;
 103.194 +
 103.195 +			if (line2[x] < back)
 103.196 +			{
 103.197 +				back = line2[x];
 103.198 +				top2 = 0x04;
 103.199 +			}
 103.200 +
 103.201 +			if (top2 & (BLDMOD>>8))
 103.202 +				color = gfxAlphaBlend(color, back,
 103.203 +				                      coeff[COLEV & 0x1F],
 103.204 +				                      coeff[(COLEV >> 8) & 0x1F]);
 103.205 +			else
 103.206 +			{
 103.207 +				switch ((BLDMOD >> 6) & 3)
 103.208 +				{
 103.209 +				case 2:
 103.210 +					if (BLDMOD & top)
 103.211 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 103.212 +					break;
 103.213 +				case 3:
 103.214 +					if (BLDMOD & top)
 103.215 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 103.216 +					break;
 103.217 +				}
 103.218 +			}
 103.219 +		}
 103.220 +
 103.221 +		lineMix[x] = color;
 103.222 +	}
 103.223 +	gfxBG2Changed = 0;
 103.224 +	gfxLastVCOUNT = VCOUNT;
 103.225 +}
 103.226 +
 103.227 +void mode4RenderLineAll()
 103.228 +{
 103.229 +	u16 *palette = (u16 *)paletteRAM;
 103.230 +
 103.231 +	if (DISPCNT & 0x0080)
 103.232 +	{
 103.233 +		for (int x = 0; x < 240; x++)
 103.234 +		{
 103.235 +			lineMix[x] = 0x7fff;
 103.236 +		}
 103.237 +		gfxLastVCOUNT = VCOUNT;
 103.238 +		return;
 103.239 +	}
 103.240 +
 103.241 +	bool inWindow0 = false;
 103.242 +	bool inWindow1 = false;
 103.243 +
 103.244 +	if (layerEnable & 0x2000)
 103.245 +	{
 103.246 +		u8 v0 = WIN0V >> 8;
 103.247 +		u8 v1 = WIN0V & 255;
 103.248 +		inWindow0 = ((v0 == v1) && (v0 >= 0xe8));
 103.249 +		if (v1 >= v0)
 103.250 +			inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1);
 103.251 +		else
 103.252 +			inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
 103.253 +	}
 103.254 +	if (layerEnable & 0x4000)
 103.255 +	{
 103.256 +		u8 v0 = WIN1V >> 8;
 103.257 +		u8 v1 = WIN1V & 255;
 103.258 +		inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
 103.259 +		if (v1 >= v0)
 103.260 +			inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1);
 103.261 +		else
 103.262 +			inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
 103.263 +	}
 103.264 +
 103.265 +	if (layerEnable & 0x400)
 103.266 +	{
 103.267 +		int changed = gfxBG2Changed;
 103.268 +
 103.269 +		if (gfxLastVCOUNT > VCOUNT)
 103.270 +			changed = 3;
 103.271 +
 103.272 +		gfxDrawRotScreen256(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
 103.273 +		                    BG2PA, BG2PB, BG2PC, BG2PD,
 103.274 +		                    gfxBG2X, gfxBG2Y, changed,
 103.275 +		                    line2);
 103.276 +	}
 103.277 +
 103.278 +	gfxDrawSprites(lineOBJ);
 103.279 +	gfxDrawOBJWin(lineOBJWin);
 103.280 +
 103.281 +	u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
 103.282 +
 103.283 +	u8 inWin0Mask = WININ & 0xFF;
 103.284 +	u8 inWin1Mask = WININ >> 8;
 103.285 +	u8 outMask    = WINOUT & 0xFF;
 103.286 +
 103.287 +	for (int x = 0; x < 240; x++)
 103.288 +	{
 103.289 +		u32 color = backdrop;
 103.290 +		u8  top   = 0x20;
 103.291 +		u8  mask  = outMask;
 103.292 +
 103.293 +		if (!(lineOBJWin[x] & 0x80000000))
 103.294 +		{
 103.295 +			mask = WINOUT >> 8;
 103.296 +		}
 103.297 +
 103.298 +		if (inWindow1)
 103.299 +		{
 103.300 +			if (gfxInWin1[x])
 103.301 +				mask = inWin1Mask;
 103.302 +		}
 103.303 +
 103.304 +		if (inWindow0)
 103.305 +		{
 103.306 +			if (gfxInWin0[x])
 103.307 +			{
 103.308 +				mask = inWin0Mask;
 103.309 +			}
 103.310 +		}
 103.311 +
 103.312 +		if ((mask & 4) && (line2[x] < color))
 103.313 +		{
 103.314 +			color = line2[x];
 103.315 +			top   = 0x04;
 103.316 +		}
 103.317 +
 103.318 +		if ((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24)))
 103.319 +		{
 103.320 +			color = lineOBJ[x];
 103.321 +			top   = 0x10;
 103.322 +		}
 103.323 +
 103.324 +		if (mask & 32)
 103.325 +		{
 103.326 +			if (!(color & 0x00010000))
 103.327 +			{
 103.328 +				switch ((BLDMOD >> 6) & 3)
 103.329 +				{
 103.330 +				case 0:
 103.331 +					break;
 103.332 +				case 1:
 103.333 +				{
 103.334 +					if (top & BLDMOD)
 103.335 +					{
 103.336 +						u32 back = backdrop;
 103.337 +						u8  top2 = 0x20;
 103.338 +
 103.339 +						if ((mask & 4) && line2[x] < back)
 103.340 +						{
 103.341 +							if (top != 0x04)
 103.342 +							{
 103.343 +								back = line2[x];
 103.344 +								top2 = 0x04;
 103.345 +							}
 103.346 +						}
 103.347 +
 103.348 +						if ((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
 103.349 +						{
 103.350 +							if (top != 0x10)
 103.351 +							{
 103.352 +								back = lineOBJ[x];
 103.353 +								top2 = 0x10;
 103.354 +							}
 103.355 +						}
 103.356 +
 103.357 +						if (top2 & (BLDMOD>>8))
 103.358 +							color = gfxAlphaBlend(color, back,
 103.359 +							                      coeff[COLEV & 0x1F],
 103.360 +							                      coeff[(COLEV >> 8) & 0x1F]);
 103.361 +					}
 103.362 +					break;
 103.363 +				}
 103.364 +				case 2:
 103.365 +					if (BLDMOD & top)
 103.366 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 103.367 +					break;
 103.368 +				case 3:
 103.369 +					if (BLDMOD & top)
 103.370 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 103.371 +					break;
 103.372 +				}
 103.373 +			}
 103.374 +			else
 103.375 +			{
 103.376 +				// semi-transparent OBJ
 103.377 +				u32 back = backdrop;
 103.378 +				u8  top2 = 0x20;
 103.379 +
 103.380 +				if ((mask & 4) && line2[x] < back)
 103.381 +				{
 103.382 +					back = line2[x];
 103.383 +					top2 = 0x04;
 103.384 +				}
 103.385 +
 103.386 +				if (top2 & (BLDMOD>>8))
 103.387 +					color = gfxAlphaBlend(color, back,
 103.388 +					                      coeff[COLEV & 0x1F],
 103.389 +					                      coeff[(COLEV >> 8) & 0x1F]);
 103.390 +				else
 103.391 +				{
 103.392 +					switch ((BLDMOD >> 6) & 3)
 103.393 +					{
 103.394 +					case 2:
 103.395 +						if (BLDMOD & top)
 103.396 +							color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 103.397 +						break;
 103.398 +					case 3:
 103.399 +						if (BLDMOD & top)
 103.400 +							color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 103.401 +						break;
 103.402 +					}
 103.403 +				}
 103.404 +			}
 103.405 +		}
 103.406 +		else if (color & 0x00010000)
 103.407 +		{
 103.408 +			// semi-transparent OBJ
 103.409 +			u32 back = backdrop;
 103.410 +			u8  top2 = 0x20;
 103.411 +
 103.412 +			if ((mask & 4) && line2[x] < back)
 103.413 +			{
 103.414 +				back = line2[x];
 103.415 +				top2 = 0x04;
 103.416 +			}
 103.417 +
 103.418 +			if (top2 & (BLDMOD>>8))
 103.419 +				color = gfxAlphaBlend(color, back,
 103.420 +				                      coeff[COLEV & 0x1F],
 103.421 +				                      coeff[(COLEV >> 8) & 0x1F]);
 103.422 +			else
 103.423 +			{
 103.424 +				switch ((BLDMOD >> 6) & 3)
 103.425 +				{
 103.426 +				case 2:
 103.427 +					if (BLDMOD & top)
 103.428 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 103.429 +					break;
 103.430 +				case 3:
 103.431 +					if (BLDMOD & top)
 103.432 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 103.433 +					break;
 103.434 +				}
 103.435 +			}
 103.436 +		}
 103.437 +
 103.438 +		lineMix[x] = color;
 103.439 +	}
 103.440 +	gfxBG2Changed = 0;
 103.441 +	gfxLastVCOUNT = VCOUNT;
 103.442 +}
 103.443 +
   104.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   104.2 +++ b/src/gba/Mode5.cpp	Sat Mar 03 10:31:27 2012 -0600
   104.3 @@ -0,0 +1,443 @@
   104.4 +#include "GBAGfx.h"
   104.5 +#include "GBAGlobals.h"
   104.6 +
   104.7 +void mode5RenderLine()
   104.8 +{
   104.9 +	if (DISPCNT & 0x0080)
  104.10 +	{
  104.11 +		for (int x = 0; x < 240; x++)
  104.12 +		{
  104.13 +			lineMix[x] = 0x7fff;
  104.14 +		}
  104.15 +		gfxLastVCOUNT = VCOUNT;
  104.16 +		return;
  104.17 +	}
  104.18 +
  104.19 +	u16 *palette = (u16 *)paletteRAM;
  104.20 +
  104.21 +	if (layerEnable & 0x0400)
  104.22 +	{
  104.23 +		int changed = gfxBG2Changed;
  104.24 +
  104.25 +		if (gfxLastVCOUNT > VCOUNT)
  104.26 +			changed = 3;
  104.27 +
  104.28 +		gfxDrawRotScreen16Bit160(BG2CNT, BG2X_L, BG2X_H,
  104.29 +		                         BG2Y_L, BG2Y_H, BG2PA, BG2PB,
  104.30 +		                         BG2PC, BG2PD,
  104.31 +		                         gfxBG2X, gfxBG2Y, changed,
  104.32 +		                         line2);
  104.33 +	}
  104.34 +
  104.35 +	gfxDrawSprites(lineOBJ);
  104.36 +
  104.37 +	u32 background = (READ16LE(&palette[0]) | 0x30000000);
  104.38 +
  104.39 +	for (int x = 0; x < 240; x++)
  104.40 +	{
  104.41 +		u32 color = background;
  104.42 +		u8  top   = 0x20;
  104.43 +
  104.44 +		if (line2[x] < color)
  104.45 +		{
  104.46 +			color = line2[x];
  104.47 +			top   = 0x04;
  104.48 +		}
  104.49 +
  104.50 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >>24))
  104.51 +		{
  104.52 +			color = lineOBJ[x];
  104.53 +			top   = 0x10;
  104.54 +		}
  104.55 +
  104.56 +		if ((top & 0x10) && (color & 0x00010000))
  104.57 +		{
  104.58 +			// semi-transparent OBJ
  104.59 +			u32 back = background;
  104.60 +			u8  top2 = 0x20;
  104.61 +
  104.62 +			if (line2[x] < back)
  104.63 +			{
  104.64 +				back = line2[x];
  104.65 +				top2 = 0x04;
  104.66 +			}
  104.67 +
  104.68 +			if (top2 & (BLDMOD>>8))
  104.69 +				color = gfxAlphaBlend(color, back,
  104.70 +				                      coeff[COLEV & 0x1F],
  104.71 +				                      coeff[(COLEV >> 8) & 0x1F]);
  104.72 +			else
  104.73 +			{
  104.74 +				switch ((BLDMOD >> 6) & 3)
  104.75 +				{
  104.76 +				case 2:
  104.77 +					if (BLDMOD & top)
  104.78 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
  104.79 +					break;
  104.80 +				case 3:
  104.81 +					if (BLDMOD & top)
  104.82 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
  104.83 +					break;
  104.84 +				}
  104.85 +			}
  104.86 +		}
  104.87 +
  104.88 +		lineMix[x] = color;
  104.89 +	}
  104.90 +	gfxBG2Changed = 0;
  104.91 +	gfxLastVCOUNT = VCOUNT;
  104.92 +}
  104.93 +
  104.94 +void mode5RenderLineNoWindow()
  104.95 +{
  104.96 +	if (DISPCNT & 0x0080)
  104.97 +	{
  104.98 +		for (int x = 0; x < 240; x++)
  104.99 +		{
 104.100 +			lineMix[x] = 0x7fff;
 104.101 +		}
 104.102 +		gfxLastVCOUNT = VCOUNT;
 104.103 +		return;
 104.104 +	}
 104.105 +
 104.106 +	u16 *palette = (u16 *)paletteRAM;
 104.107 +
 104.108 +	if (layerEnable & 0x0400)
 104.109 +	{
 104.110 +		int changed = gfxBG2Changed;
 104.111 +
 104.112 +		if (gfxLastVCOUNT > VCOUNT)
 104.113 +			changed = 3;
 104.114 +
 104.115 +		gfxDrawRotScreen16Bit160(BG2CNT, BG2X_L, BG2X_H,
 104.116 +		                         BG2Y_L, BG2Y_H, BG2PA, BG2PB,
 104.117 +		                         BG2PC, BG2PD,
 104.118 +		                         gfxBG2X, gfxBG2Y, changed,
 104.119 +		                         line2);
 104.120 +	}
 104.121 +
 104.122 +	gfxDrawSprites(lineOBJ);
 104.123 +
 104.124 +	u32 background = (READ16LE(&palette[0]) | 0x30000000);
 104.125 +
 104.126 +	for (int x = 0; x < 240; x++)
 104.127 +	{
 104.128 +		u32 color = background;
 104.129 +		u8  top   = 0x20;
 104.130 +
 104.131 +		if (line2[x] < color)
 104.132 +		{
 104.133 +			color = line2[x];
 104.134 +			top   = 0x04;
 104.135 +		}
 104.136 +
 104.137 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >>24))
 104.138 +		{
 104.139 +			color = lineOBJ[x];
 104.140 +			top   = 0x10;
 104.141 +		}
 104.142 +
 104.143 +		if (!(color & 0x00010000))
 104.144 +		{
 104.145 +			switch ((BLDMOD >> 6) & 3)
 104.146 +			{
 104.147 +			case 0:
 104.148 +				break;
 104.149 +			case 1:
 104.150 +			{
 104.151 +				if (top & BLDMOD)
 104.152 +				{
 104.153 +					u32 back = background;
 104.154 +					u8  top2 = 0x20;
 104.155 +
 104.156 +					if (line2[x] < back)
 104.157 +					{
 104.158 +						if (top != 0x04)
 104.159 +						{
 104.160 +							back = line2[x];
 104.161 +							top2 = 0x04;
 104.162 +						}
 104.163 +					}
 104.164 +
 104.165 +					if ((u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
 104.166 +					{
 104.167 +						if (top != 0x10)
 104.168 +						{
 104.169 +							back = lineOBJ[x];
 104.170 +							top2 = 0x10;
 104.171 +						}
 104.172 +					}
 104.173 +
 104.174 +					if (top2 & (BLDMOD>>8))
 104.175 +						color = gfxAlphaBlend(color, back,
 104.176 +						                      coeff[COLEV & 0x1F],
 104.177 +						                      coeff[(COLEV >> 8) & 0x1F]);
 104.178 +				}
 104.179 +				break;
 104.180 +			}
 104.181 +			case 2:
 104.182 +				if (BLDMOD & top)
 104.183 +					color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 104.184 +				break;
 104.185 +			case 3:
 104.186 +				if (BLDMOD & top)
 104.187 +					color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 104.188 +				break;
 104.189 +			}
 104.190 +		}
 104.191 +		else
 104.192 +		{
 104.193 +			// semi-transparent OBJ
 104.194 +			u32 back = background;
 104.195 +			u8  top2 = 0x20;
 104.196 +
 104.197 +			if (line2[x] < back)
 104.198 +			{
 104.199 +				back = line2[x];
 104.200 +				top2 = 0x04;
 104.201 +			}
 104.202 +
 104.203 +			if (top2 & (BLDMOD>>8))
 104.204 +				color = gfxAlphaBlend(color, back,
 104.205 +				                      coeff[COLEV & 0x1F],
 104.206 +				                      coeff[(COLEV >> 8) & 0x1F]);
 104.207 +			else
 104.208 +			{
 104.209 +				switch ((BLDMOD >> 6) & 3)
 104.210 +				{
 104.211 +				case 2:
 104.212 +					if (BLDMOD & top)
 104.213 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 104.214 +					break;
 104.215 +				case 3:
 104.216 +					if (BLDMOD & top)
 104.217 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 104.218 +					break;
 104.219 +				}
 104.220 +			}
 104.221 +		}
 104.222 +
 104.223 +		lineMix[x] = color;
 104.224 +	}
 104.225 +	gfxBG2Changed = 0;
 104.226 +	gfxLastVCOUNT = VCOUNT;
 104.227 +}
 104.228 +
 104.229 +void mode5RenderLineAll()
 104.230 +{
 104.231 +	if (DISPCNT & 0x0080)
 104.232 +	{
 104.233 +		for (int x = 0; x < 240; x++)
 104.234 +		{
 104.235 +			lineMix[x] = 0x7fff;
 104.236 +		}
 104.237 +		gfxLastVCOUNT = VCOUNT;
 104.238 +		return;
 104.239 +	}
 104.240 +
 104.241 +	u16 *palette = (u16 *)paletteRAM;
 104.242 +
 104.243 +	if (layerEnable & 0x0400)
 104.244 +	{
 104.245 +		int changed = gfxBG2Changed;
 104.246 +
 104.247 +		if (gfxLastVCOUNT > VCOUNT)
 104.248 +			changed = 3;
 104.249 +
 104.250 +		gfxDrawRotScreen16Bit160(BG2CNT, BG2X_L, BG2X_H,
 104.251 +		                         BG2Y_L, BG2Y_H, BG2PA, BG2PB,
 104.252 +		                         BG2PC, BG2PD,
 104.253 +		                         gfxBG2X, gfxBG2Y, changed,
 104.254 +		                         line2);
 104.255 +	}
 104.256 +
 104.257 +	gfxDrawSprites(lineOBJ);
 104.258 +	gfxDrawOBJWin(lineOBJWin);
 104.259 +
 104.260 +	bool inWindow0 = false;
 104.261 +	bool inWindow1 = false;
 104.262 +
 104.263 +	if (layerEnable & 0x2000)
 104.264 +	{
 104.265 +		u8 v0 = WIN0V >> 8;
 104.266 +		u8 v1 = WIN0V & 255;
 104.267 +		inWindow0 = ((v0 == v1) && (v0 >= 0xe8));
 104.268 +		if (v1 >= v0)
 104.269 +			inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1);
 104.270 +		else
 104.271 +			inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
 104.272 +	}
 104.273 +	if (layerEnable & 0x4000)
 104.274 +	{
 104.275 +		u8 v0 = WIN1V >> 8;
 104.276 +		u8 v1 = WIN1V & 255;
 104.277 +		inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
 104.278 +		if (v1 >= v0)
 104.279 +			inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1);
 104.280 +		else
 104.281 +			inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
 104.282 +	}
 104.283 +
 104.284 +	u8 inWin0Mask = WININ & 0xFF;
 104.285 +	u8 inWin1Mask = WININ >> 8;
 104.286 +	u8 outMask    = WINOUT & 0xFF;
 104.287 +
 104.288 +	u32 background = (READ16LE(&palette[0]) | 0x30000000);
 104.289 +
 104.290 +	for (int x = 0; x < 240; x++)
 104.291 +	{
 104.292 +		u32 color = background;
 104.293 +		u8  top   = 0x20;
 104.294 +		u8  mask  = outMask;
 104.295 +
 104.296 +		if (!(lineOBJWin[x] & 0x80000000))
 104.297 +		{
 104.298 +			mask = WINOUT >> 8;
 104.299 +		}
 104.300 +
 104.301 +		if (inWindow1)
 104.302 +		{
 104.303 +			if (gfxInWin1[x])
 104.304 +				mask = inWin1Mask;
 104.305 +		}
 104.306 +
 104.307 +		if (inWindow0)
 104.308 +		{
 104.309 +			if (gfxInWin0[x])
 104.310 +			{
 104.311 +				mask = inWin0Mask;
 104.312 +			}
 104.313 +		}
 104.314 +
 104.315 +		if ((mask & 4) && (line2[x] < color))
 104.316 +		{
 104.317 +			color = line2[x];
 104.318 +			top   = 0x04;
 104.319 +		}
 104.320 +
 104.321 +		if ((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24)))
 104.322 +		{
 104.323 +			color = lineOBJ[x];
 104.324 +			top   = 0x10;
 104.325 +		}
 104.326 +
 104.327 +		if (mask & 32)
 104.328 +		{
 104.329 +			if (!(color & 0x00010000))
 104.330 +			{
 104.331 +				switch ((BLDMOD >> 6) & 3)
 104.332 +				{
 104.333 +				case 0:
 104.334 +					break;
 104.335 +				case 1:
 104.336 +				{
 104.337 +					if (top & BLDMOD)
 104.338 +					{
 104.339 +						u32 back = background;
 104.340 +						u8  top2 = 0x20;
 104.341 +
 104.342 +						if ((mask & 4) && line2[x] < back)
 104.343 +						{
 104.344 +							if (top != 0x04)
 104.345 +							{
 104.346 +								back = line2[x];
 104.347 +								top2 = 0x04;
 104.348 +							}
 104.349 +						}
 104.350 +
 104.351 +						if ((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
 104.352 +						{
 104.353 +							if (top != 0x10)
 104.354 +							{
 104.355 +								back = lineOBJ[x];
 104.356 +								top2 = 0x10;
 104.357 +							}
 104.358 +						}
 104.359 +
 104.360 +						if (top2 & (BLDMOD>>8))
 104.361 +							color = gfxAlphaBlend(color, back,
 104.362 +							                      coeff[COLEV & 0x1F],
 104.363 +							                      coeff[(COLEV >> 8) & 0x1F]);
 104.364 +					}
 104.365 +					break;
 104.366 +				}
 104.367 +				case 2:
 104.368 +					if (BLDMOD & top)
 104.369 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 104.370 +					break;
 104.371 +				case 3:
 104.372 +					if (BLDMOD & top)
 104.373 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 104.374 +					break;
 104.375 +				}
 104.376 +			}
 104.377 +			else
 104.378 +			{
 104.379 +				// semi-transparent OBJ
 104.380 +				u32 back = background;
 104.381 +				u8  top2 = 0x20;
 104.382 +
 104.383 +				if ((mask & 4) && line2[x] < back)
 104.384 +				{
 104.385 +					back = line2[x];
 104.386 +					top2 = 0x04;
 104.387 +				}
 104.388 +
 104.389 +				if (top2 & (BLDMOD>>8))
 104.390 +					color = gfxAlphaBlend(color, back,
 104.391 +					                      coeff[COLEV & 0x1F],
 104.392 +					                      coeff[(COLEV >> 8) & 0x1F]);
 104.393 +				else
 104.394 +				{
 104.395 +					switch ((BLDMOD >> 6) & 3)
 104.396 +					{
 104.397 +					case 2:
 104.398 +						if (BLDMOD & top)
 104.399 +							color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 104.400 +						break;
 104.401 +					case 3:
 104.402 +						if (BLDMOD & top)
 104.403 +							color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 104.404 +						break;
 104.405 +					}
 104.406 +				}
 104.407 +			}
 104.408 +		}
 104.409 +		else if (color & 0x00010000)
 104.410 +		{
 104.411 +			// semi-transparent OBJ
 104.412 +			u32 back = background;
 104.413 +			u8  top2 = 0x20;
 104.414 +
 104.415 +			if ((mask & 4) && line2[x] < back)
 104.416 +			{
 104.417 +				back = line2[x];
 104.418 +				top2 = 0x04;
 104.419 +			}
 104.420 +
 104.421 +			if (top2 & (BLDMOD>>8))
 104.422 +				color = gfxAlphaBlend(color, back,
 104.423 +				                      coeff[COLEV & 0x1F],
 104.424 +				                      coeff[(COLEV >> 8) & 0x1F]);
 104.425 +			else
 104.426 +			{
 104.427 +				switch ((BLDMOD >> 6) & 3)
 104.428 +				{
 104.429 +				case 2:
 104.430 +					if (BLDMOD & top)
 104.431 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
 104.432 +					break;
 104.433 +				case 3:
 104.434 +					if (BLDMOD & top)
 104.435 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
 104.436 +					break;
 104.437 +				}
 104.438 +			}
 104.439 +		}
 104.440 +
 104.441 +		lineMix[x] = color;
 104.442 +	}
 104.443 +	gfxBG2Changed = 0;
 104.444 +	gfxLastVCOUNT = VCOUNT;
 104.445 +}
 104.446 +
   105.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   105.2 +++ b/src/gba/RTC.cpp	Sat Mar 03 10:31:27 2012 -0600
   105.3 @@ -0,0 +1,240 @@
   105.4 +#include <cstring>
   105.5 +
   105.6 +#include "../Port.h"
   105.7 +#include "../NLS.h"
   105.8 +#include "../common/System.h" // systemMessage
   105.9 +#include "../common/Util.h"
  105.10 +#include "../common/movie.h"
  105.11 +#include "GBAGlobals.h"
  105.12 +
  105.13 +enum RTCSTATE { IDLE, COMMAND, DATA, READDATA };
  105.14 +
  105.15 +typedef struct
  105.16 +{
  105.17 +	u8       byte0;
  105.18 +	u8       byte1;
  105.19 +	u8       byte2;
  105.20 +	u8       command;
  105.21 +	int      dataLen;
  105.22 +	int      bits;
  105.23 +	RTCSTATE state;
  105.24 +	u8       data[12];
  105.25 +	// reserved variables for future
  105.26 +	u8   reserved[12];
  105.27 +	bool reserved2;
  105.28 +	u32  reserved3;
  105.29 +} RTCCLOCKDATA;
  105.30 +
  105.31 +static RTCCLOCKDATA rtcClockData;
  105.32 +static bool         rtcEnabled = false;
  105.33 +
  105.34 +void rtcEnable(bool enable)
  105.35 +{
  105.36 +	rtcEnabled = enable;
  105.37 +}
  105.38 +
  105.39 +bool rtcIsEnabled()
  105.40 +{
  105.41 +	return rtcEnabled;
  105.42 +}
  105.43 +
  105.44 +u16 rtcRead(u32 address)
  105.45 +{
  105.46 +	if (rtcEnabled)
  105.47 +	{
  105.48 +		if (address == 0x80000c8)
  105.49 +			return rtcClockData.byte2;
  105.50 +		else if (address == 0x80000c6)
  105.51 +			return rtcClockData.byte1;
  105.52 +		else if (address == 0x80000c4)
  105.53 +		{
  105.54 +			return rtcClockData.byte0;
  105.55 +		}
  105.56 +	}
  105.57 +
  105.58 +	return READ16LE((&rom[address & 0x1FFFFFE]));
  105.59 +}
  105.60 +
  105.61 +static u8 toBCD(u8 value)
  105.62 +{
  105.63 +	value = value % 100;
  105.64 +	int l = value % 10;
  105.65 +	int h = value / 10;
  105.66 +	return h * 16 + l;
  105.67 +}
  105.68 +
  105.69 +bool rtcWrite(u32 address, u16 value)
  105.70 +{
  105.71 +	if (!rtcEnabled)
  105.72 +		return false;
  105.73 +
  105.74 +	if (address == 0x80000c8)
  105.75 +	{
  105.76 +		rtcClockData.byte2 = (u8)value; // enable ?
  105.77 +	}
  105.78 +	else if (address == 0x80000c6)
  105.79 +	{
  105.80 +		rtcClockData.byte1 = (u8)value; // read/write
  105.81 +	}
  105.82 +	else if (address == 0x80000c4)
  105.83 +	{
  105.84 +		if (rtcClockData.byte2 & 1)
  105.85 +		{
  105.86 +			if (rtcClockData.state == IDLE && rtcClockData.byte0 == 1 && value == 5)
  105.87 +			{
  105.88 +				rtcClockData.state   = COMMAND;
  105.89 +				rtcClockData.bits    = 0;
  105.90 +				rtcClockData.command = 0;
  105.91 +			}
  105.92 +			else if (!(rtcClockData.byte0 & 1) && (value & 1)) // bit transfer
  105.93 +			{
  105.94 +				rtcClockData.byte0 = (u8)value;
  105.95 +				switch (rtcClockData.state)
  105.96 +				{
  105.97 +				case COMMAND:
  105.98 +					rtcClockData.command |= ((value & 2) >> 1) << (7-rtcClockData.bits);
  105.99 +					rtcClockData.bits++;
 105.100 +					if (rtcClockData.bits == 8)
 105.101 +					{
 105.102 +						rtcClockData.bits = 0;
 105.103 +						switch (rtcClockData.command)
 105.104 +						{
 105.105 +						case 0x60:
 105.106 +							// not sure what this command does but it doesn't take parameters
 105.107 +							// maybe it is a reset or stop
 105.108 +							rtcClockData.state = IDLE;
 105.109 +							rtcClockData.bits  = 0;
 105.110 +							break;
 105.111 +						case 0x62:
 105.112 +							// this sets the control state but not sure what those values are
 105.113 +							rtcClockData.state   = READDATA;
 105.114 +							rtcClockData.dataLen = 1;
 105.115 +							break;
 105.116 +						case 0x63:
 105.117 +							rtcClockData.dataLen = 1;
 105.118 +							rtcClockData.data[0] = 0x40;
 105.119 +							rtcClockData.state   = DATA;
 105.120 +							break;
 105.121 +						case 0x65:
 105.122 +						{
 105.123 +							struct tm *newtime;
 105.124 +							time_t     long_time;
 105.125 +
 105.126 +							if (VBAMovieActive() || VBAMovieLoading())
 105.127 +							{
 105.128 +								long_time = VBAMovieGetId() + VBAMovieGetFrameCounter()/60;
 105.129 +								newtime   = gmtime(&long_time);
 105.130 +							}
 105.131 +							else
 105.132 +							{
 105.133 +								time(&long_time);      /* Get time as long integer. */
 105.134 +								newtime = localtime(&long_time); /* Convert to local time. */
 105.135 +							}
 105.136 +
 105.137 +							rtcClockData.dataLen = 7;
 105.138 +							rtcClockData.data[0] = toBCD(newtime->tm_year);
 105.139 +							rtcClockData.data[1] = toBCD(newtime->tm_mon+1);
 105.140 +							rtcClockData.data[2] = toBCD(newtime->tm_mday);
 105.141 +							rtcClockData.data[3] = 0;
 105.142 +							rtcClockData.data[4] = toBCD(newtime->tm_hour);
 105.143 +							rtcClockData.data[5] = toBCD(newtime->tm_min);
 105.144 +							rtcClockData.data[6] = toBCD(newtime->tm_sec);
 105.145 +							rtcClockData.state   = DATA;
 105.146 +							break;
 105.147 +						}
 105.148 +						case 0x67:
 105.149 +						{
 105.150 +							struct tm *newtime;
 105.151 +							time_t     long_time;
 105.152 +
 105.153 +							if (VBAMovieActive() || VBAMovieLoading())
 105.154 +							{
 105.155 +								long_time = VBAMovieGetId() + VBAMovieGetFrameCounter()/60;
 105.156 +								newtime   = gmtime(&long_time);
 105.157 +							}
 105.158 +							else
 105.159 +							{
 105.160 +								time(&long_time);      /* Get time as long integer. */
 105.161 +								newtime = localtime(&long_time); /* Convert to local time. */
 105.162 +							}
 105.163 +
 105.164 +							rtcClockData.dataLen = 3;
 105.165 +							rtcClockData.data[0] = toBCD(newtime->tm_hour);
 105.166 +							rtcClockData.data[1] = toBCD(newtime->tm_min);
 105.167 +							rtcClockData.data[2] = toBCD(newtime->tm_sec);
 105.168 +							rtcClockData.state   = DATA;
 105.169 +							break;
 105.170 +						}
 105.171 +						default:
 105.172 +							systemMessage(0, N_("Unknown RTC command %02x"), rtcClockData.command);
 105.173 +							rtcClockData.state = IDLE;
 105.174 +							break;
 105.175 +						}
 105.176 +					}
 105.177 +					break;
 105.178 +				case DATA:
 105.179 +					if (rtcClockData.byte1 & 2)
 105.180 +					{}
 105.181 +					else
 105.182 +					{
 105.183 +						rtcClockData.byte0 = (rtcClockData.byte0 & ~2) |
 105.184 +						                     ((rtcClockData.data[rtcClockData.bits >> 3] >>
 105.185 +						                       (rtcClockData.bits & 7)) & 1)*2;
 105.186 +						rtcClockData.bits++;
 105.187 +						if (rtcClockData.bits == 8*rtcClockData.dataLen)
 105.188 +						{
 105.189 +							rtcClockData.bits  = 0;
 105.190 +							rtcClockData.state = IDLE;
 105.191 +						}
 105.192 +					}
 105.193 +					break;
 105.194 +				case READDATA:
 105.195 +					if (!(rtcClockData.byte1 & 2))
 105.196 +					{}
 105.197 +					else
 105.198 +					{
 105.199 +						rtcClockData.data[rtcClockData.bits >> 3] =
 105.200 +						    (rtcClockData.data[rtcClockData.bits >> 3] >> 1) |
 105.201 +						    ((value << 6) & 128);
 105.202 +						rtcClockData.bits++;
 105.203 +						if (rtcClockData.bits == 8*rtcClockData.dataLen)
 105.204 +						{
 105.205 +							rtcClockData.bits  = 0;
 105.206 +							rtcClockData.state = IDLE;
 105.207 +						}
 105.208 +					}
 105.209 +					break;
 105.210 +				default:
 105.211 +					break;
 105.212 +				}
 105.213 +			}
 105.214 +			else
 105.215 +				rtcClockData.byte0 = (u8)value;
 105.216 +		}
 105.217 +	}
 105.218 +	return true;
 105.219 +}
 105.220 +
 105.221 +void rtcReset()
 105.222 +{
 105.223 +	memset(&rtcClockData, 0, sizeof(rtcClockData));
 105.224 +
 105.225 +	rtcClockData.byte0   = 0;
 105.226 +	rtcClockData.byte1   = 0;
 105.227 +	rtcClockData.byte2   = 0;
 105.228 +	rtcClockData.command = 0;
 105.229 +	rtcClockData.dataLen = 0;
 105.230 +	rtcClockData.bits    = 0;
 105.231 +	rtcClockData.state   = IDLE;
 105.232 +}
 105.233 +
 105.234 +void rtcSaveGame(gzFile gzFile)
 105.235 +{
 105.236 +	utilGzWrite(gzFile, &rtcClockData, sizeof(rtcClockData));
 105.237 +}
 105.238 +
 105.239 +void rtcReadGame(gzFile gzFile)
 105.240 +{
 105.241 +	utilGzRead(gzFile, &rtcClockData, sizeof(rtcClockData));
 105.242 +}
 105.243 +
   106.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   106.2 +++ b/src/gba/RTC.h	Sat Mar 03 10:31:27 2012 -0600
   106.3 @@ -0,0 +1,17 @@
   106.4 +#ifndef VBA_RTC_H
   106.5 +#define VBA_RTC_H
   106.6 +
   106.7 +#if _MSC_VER > 1000
   106.8 +#pragma once
   106.9 +#endif // _MSC_VER > 1000
  106.10 +
  106.11 +extern u16 rtcRead(u32 address);
  106.12 +extern bool rtcWrite(u32 address, u16 value);
  106.13 +extern void rtcEnable(bool);
  106.14 +extern bool rtcIsEnabled();
  106.15 +extern void rtcReset();
  106.16 +
  106.17 +extern void rtcReadGame(gzFile gzFile);
  106.18 +extern void rtcSaveGame(gzFile gzFile);
  106.19 +
  106.20 +#endif // VBA_RTC_H
   107.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   107.2 +++ b/src/gba/Sram.cpp	Sat Mar 03 10:31:27 2012 -0600
   107.3 @@ -0,0 +1,15 @@
   107.4 +#include "../common/System.h"
   107.5 +#include "Flash.h"
   107.6 +#include "Sram.h"
   107.7 +
   107.8 +u8 sramRead(u32 address)
   107.9 +{
  107.10 +	return flashSaveMemory[address & 0xFFFF];
  107.11 +}
  107.12 +
  107.13 +void sramWrite(u32 address, u8 byte)
  107.14 +{
  107.15 +	flashSaveMemory[address & 0xFFFF] = byte;
  107.16 +	systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
  107.17 +}
  107.18 +
   108.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   108.2 +++ b/src/gba/Sram.h	Sat Mar 03 10:31:27 2012 -0600
   108.3 @@ -0,0 +1,11 @@
   108.4 +#ifndef VBA_SRAM_H
   108.5 +#define VBA_SRAM_H
   108.6 +
   108.7 +#if _MSC_VER > 1000
   108.8 +#pragma once
   108.9 +#endif // _MSC_VER > 1000
  108.10 +
  108.11 +extern u8 sramRead(u32 address);
  108.12 +extern void sramWrite(u32 address, u8 byte);
  108.13 +
  108.14 +#endif // VBA_SRAM_H
   109.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   109.2 +++ b/src/gba/agbprint.cpp	Sat Mar 03 10:31:27 2012 -0600
   109.3 @@ -0,0 +1,82 @@
   109.4 +#include <cstdio>
   109.5 +#include <cstring>
   109.6 +
   109.7 +#include "GBAGlobals.h"
   109.8 +
   109.9 +extern void (*dbgOutput)(char *, u32);
  109.10 +extern int systemVerbose;
  109.11 +
  109.12 +static bool agbPrintEnabled = false;
  109.13 +static bool agbPrintProtect = false;
  109.14 +
  109.15 +bool agbPrintWrite(u32 address, u16 value)
  109.16 +{
  109.17 +	if (agbPrintEnabled)
  109.18 +	{
  109.19 +		if (address == 0x9fe2ffe) // protect
  109.20 +		{
  109.21 +			agbPrintProtect = (value != 0);
  109.22 +			debuggerWriteHalfWord(address, value);
  109.23 +			return true;
  109.24 +		}
  109.25 +		else
  109.26 +		{
  109.27 +			if (agbPrintProtect &&
  109.28 +			    ((address >= 0x9fe20f8 && address <= 0x9fe20ff) // control structure
  109.29 +			     || (address >= 0x8fd0000 && address <= 0x8fdffff)
  109.30 +			     || (address >= 0x9fd0000 && address <= 0x9fdffff)))
  109.31 +			{
  109.32 +				debuggerWriteHalfWord(address, value);
  109.33 +				return true;
  109.34 +			}
  109.35 +		}
  109.36 +	}
  109.37 +	return false;
  109.38 +}
  109.39 +
  109.40 +void agbPrintReset()
  109.41 +{
  109.42 +	agbPrintProtect = false;
  109.43 +}
  109.44 +
  109.45 +void agbPrintEnable(bool enable)
  109.46 +{
  109.47 +	agbPrintEnabled = enable;
  109.48 +}
  109.49 +
  109.50 +bool agbPrintIsEnabled()
  109.51 +{
  109.52 +	return agbPrintEnabled;
  109.53 +}
  109.54 +
  109.55 +void agbPrintFlush()
  109.56 +{
  109.57 +	u16 get = debuggerReadHalfWord(0x9fe20fc);
  109.58 +	u16 put = debuggerReadHalfWord(0x9fe20fe);
  109.59 +
  109.60 +	u32 address = (debuggerReadHalfWord(0x9fe20fa) << 16);
  109.61 +	if (address != 0xfd0000 && address != 0x1fd0000)
  109.62 +	{
  109.63 +		dbgOutput("Did you forget to call AGBPrintInit?\n", 0);
  109.64 +		// get rid of the text otherwise we will continue to be called
  109.65 +		debuggerWriteHalfWord(0x9fe20fc, put);
  109.66 +		return;
  109.67 +	}
  109.68 +
  109.69 +	u8 *data = &rom[address];
  109.70 +
  109.71 +	while (get != put)
  109.72 +	{
  109.73 +		char c = data[get++];
  109.74 +		char s[2];
  109.75 +		s[0] = c;
  109.76 +		s[1] = 0;
  109.77 +
  109.78 +		if (systemVerbose & VERBOSE_AGBPRINT)
  109.79 +			dbgOutput(s, 0);
  109.80 +		if (c == '\n')
  109.81 +			break;
  109.82 +	}
  109.83 +	debuggerWriteHalfWord(0x9fe20fc, get);
  109.84 +}
  109.85 +
   110.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   110.2 +++ b/src/gba/agbprint.h	Sat Mar 03 10:31:27 2012 -0600
   110.3 @@ -0,0 +1,14 @@
   110.4 +#ifndef VBA_AGBPRINT_H
   110.5 +#define VBA_AGBPRINT_H
   110.6 +
   110.7 +#if _MSC_VER > 1000
   110.8 +#pragma once
   110.9 +#endif // _MSC_VER > 1000
  110.10 +
  110.11 +extern void agbPrintEnable(bool);
  110.12 +extern bool agbPrintIsEnabled();
  110.13 +extern void agbPrintReset();
  110.14 +extern bool agbPrintWrite(u32, u16);
  110.15 +extern void agbPrintFlush();
  110.16 +
  110.17 +#endif // VBA_AGBPRINT_H
   111.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   111.2 +++ b/src/gba/arm-new.h	Sat Mar 03 10:31:27 2012 -0600
   111.3 @@ -0,0 +1,7453 @@
   111.4 +#ifdef BKPT_SUPPORT
   111.5 +#define CONSOLE_OUTPUT(a, b) \
   111.6 +    extern void (*dbgOutput)(char *, u32); \
   111.7 +    if ((opcode == 0xe0000000) && (reg[0].I == 0xC0DED00D)) { \
   111.8 +		dbgOutput((a), (b)); \
   111.9 +	}
  111.10 +#else
  111.11 +#define CONSOLE_OUTPUT(a, b)
  111.12 +#endif
  111.13 +
  111.14 +#define OP_AND \
  111.15 +    reg[dest].I = reg[(opcode >> 16) & 15].I & value; \
  111.16 +    CONSOLE_OUTPUT(NULL, reg[2].I);
  111.17 +
  111.18 +#define OP_ANDS \
  111.19 +    reg[dest].I = reg[(opcode >> 16) & 15].I & value; \
  111.20 +      \
  111.21 +    N_FLAG = (reg[dest].I & 0x80000000) ? true : false; \
  111.22 +    Z_FLAG = (reg[dest].I) ? false : true; \
  111.23 +    C_FLAG = C_OUT;
  111.24 +
  111.25 +#define OP_EOR \
  111.26 +    reg[dest].I = reg[(opcode >> 16) & 15].I ^ value;
  111.27 +
  111.28 +#define OP_EORS \
  111.29 +    reg[dest].I = reg[(opcode >> 16) & 15].I ^ value; \
  111.30 +      \
  111.31 +    N_FLAG = (reg[dest].I & 0x80000000) ? true : false; \
  111.32 +    Z_FLAG = (reg[dest].I) ? false : true; \
  111.33 +    C_FLAG = C_OUT;
  111.34 +#ifdef C_CORE
  111.35 +#define NEG(i) ((i) >> 31)
  111.36 +#define POS(i) ((~(i)) >> 31)
  111.37 +#define ADDCARRY(a, b, c) \
  111.38 +    C_FLAG = ((NEG(a) & NEG(b)) | \
  111.39 +              (NEG(a) & POS(c)) | \
  111.40 +              (NEG(b) & POS(c))) ? true : false;
  111.41 +#define ADDOVERFLOW(a, b, c) \
  111.42 +    V_FLAG = ((NEG(a) & NEG(b) & POS(c)) | \
  111.43 +              (POS(a) & POS(b) & NEG(c))) ? true : false;
  111.44 +#define SUBCARRY(a, b, c) \
  111.45 +    C_FLAG = ((NEG(a) & POS(b)) | \
  111.46 +              (NEG(a) & POS(c)) | \
  111.47 +              (POS(b) & POS(c))) ? true : false;
  111.48 +#define SUBOVERFLOW(a, b, c) \
  111.49 +    V_FLAG = ((NEG(a) & POS(b) & POS(c)) | \
  111.50 +              (POS(a) & NEG(b) & NEG(c))) ? true : false;
  111.51 +#define OP_SUB \
  111.52 +	{ \
  111.53 +		reg[dest].I = reg[base].I - value; \
  111.54 +	}
  111.55 +#define OP_SUBS \
  111.56 +	{ \
  111.57 +		u32 lhs = reg[base].I; \
  111.58 +		u32 rhs = value; \
  111.59 +		u32 res = lhs - rhs; \
  111.60 +		reg[dest].I = res; \
  111.61 +		Z_FLAG		= (res == 0) ? true : false; \
  111.62 +		N_FLAG		= NEG(res) ? true : false; \
  111.63 +		SUBCARRY(lhs, rhs, res); \
  111.64 +		SUBOVERFLOW(lhs, rhs, res); \
  111.65 +	}
  111.66 +#define OP_RSB \
  111.67 +	{ \
  111.68 +		reg[dest].I = value - reg[base].I; \
  111.69 +	}
  111.70 +#define OP_RSBS \
  111.71 +	{ \
  111.72 +		u32 lhs = reg[base].I; \
  111.73 +		u32 rhs = value; \
  111.74 +		u32 res = rhs - lhs; \
  111.75 +		reg[dest].I = res; \
  111.76 +		Z_FLAG		= (res == 0) ? true : false; \
  111.77 +		N_FLAG		= NEG(res) ? true : false; \
  111.78 +		SUBCARRY(rhs, lhs, res); \
  111.79 +		SUBOVERFLOW(rhs, lhs, res); \
  111.80 +	}
  111.81 +#define OP_ADD \
  111.82 +	{ \
  111.83 +		reg[dest].I = reg[base].I + value; \
  111.84 +	}
  111.85 +#define OP_ADDS \
  111.86 +	{ \
  111.87 +		u32 lhs = reg[base].I; \
  111.88 +		u32 rhs = value; \
  111.89 +		u32 res = lhs + rhs; \
  111.90 +		reg[dest].I = res; \
  111.91 +		Z_FLAG		= (res == 0) ? true : false; \
  111.92 +		N_FLAG		= NEG(res) ? true : false; \
  111.93 +		ADDCARRY(lhs, rhs, res); \
  111.94 +		ADDOVERFLOW(lhs, rhs, res); \
  111.95 +	}
  111.96 +#define OP_ADC \
  111.97 +	{ \
  111.98 +		reg[dest].I = reg[base].I + value + (u32)C_FLAG; \
  111.99 +	}
 111.100 +#define OP_ADCS \
 111.101 +	{ \
 111.102 +		u32 lhs = reg[base].I; \
 111.103 +		u32 rhs = value; \
 111.104 +		u32 res = lhs + rhs + (u32)C_FLAG; \
 111.105 +		reg[dest].I = res; \
 111.106 +		Z_FLAG		= (res == 0) ? true : false; \
 111.107 +		N_FLAG		= NEG(res) ? true : false; \
 111.108 +		ADDCARRY(lhs, rhs, res); \
 111.109 +		ADDOVERFLOW(lhs, rhs, res); \
 111.110 +	}
 111.111 +#define OP_SBC \
 111.112 +	{ \
 111.113 +		reg[dest].I = reg[base].I - value - !((u32)C_FLAG); \
 111.114 +	}
 111.115 +#define OP_SBCS \
 111.116 +	{ \
 111.117 +		u32 lhs = reg[base].I; \
 111.118 +		u32 rhs = value; \
 111.119 +		u32 res = lhs - rhs - !((u32)C_FLAG); \
 111.120 +		reg[dest].I = res; \
 111.121 +		Z_FLAG		= (res == 0) ? true : false; \
 111.122 +		N_FLAG		= NEG(res) ? true : false; \
 111.123 +		SUBCARRY(lhs, rhs, res); \
 111.124 +		SUBOVERFLOW(lhs, rhs, res); \
 111.125 +	}
 111.126 +#define OP_RSC \
 111.127 +	{ \
 111.128 +		reg[dest].I = value - reg[base].I - !((u32)C_FLAG); \
 111.129 +	}
 111.130 +#define OP_RSCS \
 111.131 +	{ \
 111.132 +		u32 lhs = reg[base].I; \
 111.133 +		u32 rhs = value; \
 111.134 +		u32 res = rhs - lhs - !((u32)C_FLAG); \
 111.135 +		reg[dest].I = res; \
 111.136 +		Z_FLAG		= (res == 0) ? true : false; \
 111.137 +		N_FLAG		= NEG(res) ? true : false; \
 111.138 +		SUBCARRY(rhs, lhs, res); \
 111.139 +		SUBOVERFLOW(rhs, lhs, res); \
 111.140 +	}
 111.141 +#define OP_CMP \
 111.142 +	{ \
 111.143 +		u32 lhs = reg[base].I; \
 111.144 +		u32 rhs = value; \
 111.145 +		u32 res = lhs - rhs; \
 111.146 +		Z_FLAG = (res == 0) ? true : false; \
 111.147 +		N_FLAG = NEG(res) ? true : false; \
 111.148 +		SUBCARRY(lhs, rhs, res); \
 111.149 +		SUBOVERFLOW(lhs, rhs, res); \
 111.150 +	}
 111.151 +#define OP_CMN \
 111.152 +	{ \
 111.153 +		u32 lhs = reg[base].I; \
 111.154 +		u32 rhs = value; \
 111.155 +		u32 res = lhs + rhs; \
 111.156 +		Z_FLAG = (res == 0) ? true : false; \
 111.157 +		N_FLAG = NEG(res) ? true : false; \
 111.158 +		ADDCARRY(lhs, rhs, res); \
 111.159 +		ADDOVERFLOW(lhs, rhs, res); \
 111.160 +	}
 111.161 +
 111.162 +#define LOGICAL_LSL_REG \
 111.163 +	{ \
 111.164 +		u32 v = reg[opcode & 0x0f].I; \
 111.165 +		C_OUT = (v >> (32 - shift)) & 1 ? true : false; \
 111.166 +		value = v << shift; \
 111.167 +	}
 111.168 +#define LOGICAL_LSR_REG \
 111.169 +	{ \
 111.170 +		u32 v = reg[opcode & 0x0f].I; \
 111.171 +		C_OUT = (v >> (shift - 1)) & 1 ? true : false; \
 111.172 +		value = v >> shift; \
 111.173 +	}
 111.174 +#define LOGICAL_ASR_REG \
 111.175 +	{ \
 111.176 +		u32 v = reg[opcode & 0x0f].I; \
 111.177 +		C_OUT = ((s32)v >> (int)(shift - 1)) & 1 ? true : false; \
 111.178 +		value = (s32)v >> (int)shift; \
 111.179 +	}
 111.180 +#define LOGICAL_ROR_REG \
 111.181 +	{ \
 111.182 +		u32 v = reg[opcode & 0x0f].I; \
 111.183 +		C_OUT = (v >> (shift - 1)) & 1 ? true : false; \
 111.184 +		value = ((v << (32 - shift)) | \
 111.185 +		         (v >> shift)); \
 111.186 +	}
 111.187 +#define LOGICAL_RRX_REG \
 111.188 +	{ \
 111.189 +		u32 v = reg[opcode & 0x0f].I; \
 111.190 +		shift = (int)C_FLAG; \
 111.191 +		C_OUT = (v  & 1) ? true : false; \
 111.192 +		value = ((v >> 1) | \
 111.193 +		         (shift << 31)); \
 111.194 +	}
 111.195 +#define LOGICAL_ROR_IMM \
 111.196 +	{ \
 111.197 +		u32 v = opcode & 0xff; \
 111.198 +		C_OUT = (v >> (shift - 1)) & 1 ? true : false; \
 111.199 +		value = ((v << (32 - shift)) | \
 111.200 +		         (v >> shift)); \
 111.201 +	}
 111.202 +#define ARITHMETIC_LSL_REG \
 111.203 +	{ \
 111.204 +		u32 v = reg[opcode & 0x0f].I; \
 111.205 +		value = v << shift; \
 111.206 +	}
 111.207 +#define ARITHMETIC_LSR_REG \
 111.208 +	{ \
 111.209 +		u32 v = reg[opcode & 0x0f].I; \
 111.210 +		value = v >> shift; \
 111.211 +	}
 111.212 +#define ARITHMETIC_ASR_REG \
 111.213 +	{ \
 111.214 +		u32 v = reg[opcode & 0x0f].I; \
 111.215 +		value = (s32)v >> (int)shift; \
 111.216 +	}
 111.217 +#define ARITHMETIC_ROR_REG \
 111.218 +	{ \
 111.219 +		u32 v = reg[opcode & 0x0f].I; \
 111.220 +		value = ((v << (32 - shift)) | \
 111.221 +		         (v >> shift)); \
 111.222 +	}
 111.223 +#define ARITHMETIC_RRX_REG \
 111.224 +	{ \
 111.225 +		u32 v = reg[opcode & 0x0f].I; \
 111.226 +		shift = (int)C_FLAG; \
 111.227 +		value = ((v >> 1) | \
 111.228 +		         (shift << 31)); \
 111.229 +	}
 111.230 +#define ARITHMETIC_ROR_IMM \
 111.231 +	{ \
 111.232 +		u32 v = opcode & 0xff; \
 111.233 +		value = ((v << (32 - shift)) | \
 111.234 +		         (v >> shift)); \
 111.235 +	}
 111.236 +#define ROR_IMM_MSR \
 111.237 +	{ \
 111.238 +		u32 v = opcode & 0xff; \
 111.239 +		value = ((v << (32 - shift)) | \
 111.240 +		         (v >> shift)); \
 111.241 +	}
 111.242 +#define ROR_VALUE \
 111.243 +	{ \
 111.244 +		value = ((value << (32 - shift)) | \
 111.245 +		         (value >> shift)); \
 111.246 +	}
 111.247 +#define RCR_VALUE \
 111.248 +	{ \
 111.249 +		shift = (int)C_FLAG; \
 111.250 +		value = ((value >> 1) | \
 111.251 +		         (shift << 31)); \
 111.252 +	}
 111.253 +#else
 111.254 +#ifdef __GNUC__
 111.255 +		#ifdef __POWERPC__
 111.256 +			#define OP_SUB \
 111.257 +	{ \
 111.258 +		reg[dest].I = reg[base].I - value; \
 111.259 +	}
 111.260 +			#define OP_SUBS \
 111.261 +	{ \
 111.262 +		register int Flags;                             \
 111.263 +		register int Result;                            \
 111.264 +		asm volatile ("subco. %0, %2, %3\n"              \
 111.265 +		              "mcrxr cr1\n"                       \
 111.266 +		              "mfcr %1\n"                         \
 111.267 +					  : "=r" (Result),                    \
 111.268 +		              "=r" (Flags)                      \
 111.269 +					  : "r" (reg[base].I),                \
 111.270 +		              "r" (value)                       \
 111.271 +		              );                                  \
 111.272 +		reg[dest].I = Result;                           \
 111.273 +		Z_FLAG		= (Flags >> 29) & 1;                     \
 111.274 +		N_FLAG		= (Flags >> 31) & 1;                     \
 111.275 +		C_FLAG		= (Flags >> 25) & 1;                     \
 111.276 +		V_FLAG		= (Flags >> 26) & 1;                     \
 111.277 +	}
 111.278 +			#define OP_RSB \
 111.279 +	{ \
 111.280 +		reg[dest].I = value - reg[base].I; \
 111.281 +	}
 111.282 +			#define OP_RSBS \
 111.283 +	{ \
 111.284 +		register int Flags;                             \
 111.285 +		register int Result;                            \
 111.286 +		asm volatile ("subfco. %0, %2, %3\n"             \
 111.287 +		              "mcrxr cr1\n"                       \
 111.288 +		              "mfcr %1\n"                         \
 111.289 +					  : "=r" (Result),                    \
 111.290 +		              "=r" (Flags)                      \
 111.291 +					  : "r" (reg[base].I),                \
 111.292 +		              "r" (value)                       \
 111.293 +		              );                                  \
 111.294 +		reg[dest].I = Result;                           \
 111.295 +		Z_FLAG		= (Flags >> 29) & 1;                     \
 111.296 +		N_FLAG		= (Flags >> 31) & 1;                     \
 111.297 +		C_FLAG		= (Flags >> 25) & 1;                     \
 111.298 +		V_FLAG		= (Flags >> 26) & 1;                     \
 111.299 +	}
 111.300 +			#define OP_ADD \
 111.301 +	{ \
 111.302 +		reg[dest].I = reg[base].I + value; \
 111.303 +	}
 111.304 +
 111.305 +			#define OP_ADDS \
 111.306 +	{ \
 111.307 +		register int Flags;                             \
 111.308 +		register int Result;                            \
 111.309 +		asm volatile ("addco. %0, %2, %3\n"              \
 111.310 +		              "mcrxr cr1\n"                       \
 111.311 +		              "mfcr %1\n"                         \
 111.312 +					  : "=r" (Result),                    \
 111.313 +		              "=r" (Flags)                      \
 111.314 +					  : "r" (reg[base].I),                \
 111.315 +		              "r" (value)                       \
 111.316 +		              );                                  \
 111.317 +		reg[dest].I = Result;                           \
 111.318 +		Z_FLAG		= (Flags >> 29) & 1;                     \
 111.319 +		N_FLAG		= (Flags >> 31) & 1;                     \
 111.320 +		C_FLAG		= (Flags >> 25) & 1;                     \
 111.321 +		V_FLAG		= (Flags >> 26) & 1;                     \
 111.322 +	}
 111.323 +			#define OP_ADC \
 111.324 +	{ \
 111.325 +		reg[dest].I = reg[base].I + value + (u32)C_FLAG; \
 111.326 +	}
 111.327 +			#define OP_ADCS \
 111.328 +	{ \
 111.329 +		register int Flags;                             \
 111.330 +		register int Result;                            \
 111.331 +		asm volatile ("mtspr xer, %4\n"                  \
 111.332 +		              "addeo. %0, %2, %3\n"              \
 111.333 +		              "mcrxr cr1\n"                      \
 111.334 +		              "mfcr      %1\n"                   \
 111.335 +					  : "=r" (Result),                   \
 111.336 +		              "=r" (Flags)                     \
 111.337 +					  : "r" (reg[base].I),               \
 111.338 +		              "r" (value),                     \
 111.339 +		              "r" (C_FLAG << 29)               \
 111.340 +		              );                                 \
 111.341 +		reg[dest].I = Result;                           \
 111.342 +		Z_FLAG		= (Flags >> 29) & 1;                     \
 111.343 +		N_FLAG		= (Flags >> 31) & 1;                     \
 111.344 +		C_FLAG		= (Flags >> 25) & 1;                     \
 111.345 +		V_FLAG		= (Flags >> 26) & 1;                     \
 111.346 +	}
 111.347 +			#define OP_SBC \
 111.348 +	{ \
 111.349 +		reg[dest].I = reg[base].I - value - (C_FLAG ^ 1); \
 111.350 +	}
 111.351 +			#define OP_SBCS \
 111.352 +	{ \
 111.353 +		register int Flags;                             \
 111.354 +		register int Result;                            \
 111.355 +		asm volatile ("mtspr xer, %4\n"                  \
 111.356 +		              "subfeo. %0, %3, %2\n"             \
 111.357 +		              "mcrxr cr1\n"                      \
 111.358 +		              "mfcr      %1\n"                   \
 111.359 +					  : "=r" (Result),                   \
 111.360 +		              "=r" (Flags)                     \
 111.361 +					  : "r" (reg[base].I),               \
 111.362 +		              "r" (value),                     \
 111.363 +		              "r" (C_FLAG << 29)               \
 111.364 +		              );                                 \
 111.365 +		reg[dest].I = Result;                           \
 111.366 +		Z_FLAG		= (Flags >> 29) & 1;                     \
 111.367 +		N_FLAG		= (Flags >> 31) & 1;                     \
 111.368 +		C_FLAG		= (Flags >> 25) & 1;                     \
 111.369 +		V_FLAG		= (Flags >> 26) & 1;                     \
 111.370 +	}
 111.371 +			#define OP_RSC \
 111.372 +	{ \
 111.373 +		reg[dest].I = value - reg[base].I - (C_FLAG ^ 1); \
 111.374 +	}
 111.375 +			#define OP_RSCS \
 111.376 +	{ \
 111.377 +		register int Flags;                             \
 111.378 +		register int Result;                            \
 111.379 +		asm volatile ("mtspr xer, %4\n"                  \
 111.380 +		              "subfeo. %0, %2, %3\n"             \
 111.381 +		              "mcrxr cr1\n"                      \
 111.382 +		              "mfcr      %1\n"                   \
 111.383 +					  : "=r" (Result),                   \
 111.384 +		              "=r" (Flags)                     \
 111.385 +					  : "r" (reg[base].I),               \
 111.386 +		              "r" (value),                     \
 111.387 +		              "r" (C_FLAG << 29)               \
 111.388 +		              );                                 \
 111.389 +		reg[dest].I = Result;                           \
 111.390 +		Z_FLAG		= (Flags >> 29) & 1;                     \
 111.391 +		N_FLAG		= (Flags >> 31) & 1;                     \
 111.392 +		C_FLAG		= (Flags >> 25) & 1;                     \
 111.393 +		V_FLAG		= (Flags >> 26) & 1;                     \
 111.394 +	}
 111.395 +			#define OP_CMP \
 111.396 +	{ \
 111.397 +		register int Flags;                             \
 111.398 +		register int Result;                            \
 111.399 +		asm volatile ("subco. %0, %2, %3\n"              \
 111.400 +		              "mcrxr cr1\n"                       \
 111.401 +		              "mfcr %1\n"                         \
 111.402 +					  : "=r" (Result),                    \
 111.403 +		              "=r" (Flags)                      \
 111.404 +					  : "r" (reg[base].I),                \
 111.405 +		              "r" (value)                       \
 111.406 +		              );                                  \
 111.407 +		Z_FLAG = (Flags >> 29) & 1;                     \
 111.408 +		N_FLAG = (Flags >> 31) & 1;                     \
 111.409 +		C_FLAG = (Flags >> 25) & 1;                     \
 111.410 +		V_FLAG = (Flags >> 26) & 1;                     \
 111.411 +	}
 111.412 +			#define OP_CMN \
 111.413 +	{ \
 111.414 +		register int Flags;                             \
 111.415 +		register int Result;                            \
 111.416 +		asm volatile ("addco. %0, %2, %3\n"              \
 111.417 +		              "mcrxr cr1\n"                       \
 111.418 +		              "mfcr %1\n"                         \
 111.419 +					  : "=r" (Result),                    \
 111.420 +		              "=r" (Flags)                      \
 111.421 +					  : "r" (reg[base].I),                \
 111.422 +		              "r" (value)                       \
 111.423 +		              );                                  \
 111.424 +		Z_FLAG = (Flags >> 29) & 1;                     \
 111.425 +		N_FLAG = (Flags >> 31) & 1;                     \
 111.426 +		C_FLAG = (Flags >> 25) & 1;                     \
 111.427 +		V_FLAG = (Flags >> 26) & 1;                     \
 111.428 +	}
 111.429 +
 111.430 +			#define LOGICAL_LSL_REG \
 111.431 +	{ \
 111.432 +		u32 v = reg[opcode & 0x0f].I; \
 111.433 +		C_OUT = (v >> (32 - shift)) & 1 ? true : false; \
 111.434 +		value = v << shift; \
 111.435 +	}
 111.436 +			#define LOGICAL_LSR_REG \
 111.437 +	{ \
 111.438 +		u32 v = reg[opcode & 0x0f].I; \
 111.439 +		C_OUT = (v >> (shift - 1)) & 1 ? true : false; \
 111.440 +		value = v >> shift; \
 111.441 +	}
 111.442 +			#define LOGICAL_ASR_REG \
 111.443 +	{ \
 111.444 +		u32 v = reg[opcode & 0x0f].I; \
 111.445 +		C_OUT = ((s32)v >> (int)(shift - 1)) & 1 ? true : false; \
 111.446 +		value = (s32)v >> (int)shift; \
 111.447 +	}
 111.448 +			#define LOGICAL_ROR_REG \
 111.449 +	{ \
 111.450 +		u32 v = reg[opcode & 0x0f].I; \
 111.451 +		C_OUT = (v >> (shift - 1)) & 1 ? true : false; \
 111.452 +		value = ((v << (32 - shift)) | \
 111.453 +		         (v >> shift)); \
 111.454 +	}
 111.455 +			#define LOGICAL_RRX_REG \
 111.456 +	{ \
 111.457 +		u32 v = reg[opcode & 0x0f].I; \
 111.458 +		shift = (int)C_FLAG; \
 111.459 +		C_OUT = (v  & 1) ? true : false; \
 111.460 +		value = ((v >> 1) | \
 111.461 +		         (shift << 31)); \
 111.462 +	}
 111.463 +			#define LOGICAL_ROR_IMM \
 111.464 +	{ \
 111.465 +		u32 v = opcode & 0xff; \
 111.466 +		C_OUT = (v >> (shift - 1)) & 1 ? true : false; \
 111.467 +		value = ((v << (32 - shift)) | \
 111.468 +		         (v >> shift)); \
 111.469 +	}
 111.470 +			#define ARITHMETIC_LSL_REG \
 111.471 +	{ \
 111.472 +		u32 v = reg[opcode & 0x0f].I; \
 111.473 +		value = v << shift; \
 111.474 +	}
 111.475 +			#define ARITHMETIC_LSR_REG \
 111.476 +	{ \
 111.477 +		u32 v = reg[opcode & 0x0f].I; \
 111.478 +		value = v >> shift; \
 111.479 +	}
 111.480 +			#define ARITHMETIC_ASR_REG \
 111.481 +	{ \
 111.482 +		u32 v = reg[opcode & 0x0f].I; \
 111.483 +		value = (s32)v >> (int)shift; \
 111.484 +	}
 111.485 +			#define ARITHMETIC_ROR_REG \
 111.486 +	{ \
 111.487 +		u32 v = reg[opcode & 0x0f].I; \
 111.488 +		value = ((v << (32 - shift)) | \
 111.489 +		         (v >> shift)); \
 111.490 +	}
 111.491 +			#define ARITHMETIC_RRX_REG \
 111.492 +	{ \
 111.493 +		u32 v = reg[opcode & 0x0f].I; \
 111.494 +		shift = (int)C_FLAG; \
 111.495 +		value = ((v >> 1) | \
 111.496 +		         (shift << 31)); \
 111.497 +	}
 111.498 +			#define ARITHMETIC_ROR_IMM \
 111.499 +	{ \
 111.500 +		u32 v = opcode & 0xff; \
 111.501 +		value = ((v << (32 - shift)) | \
 111.502 +		         (v >> shift)); \
 111.503 +	}
 111.504 +			#define ROR_IMM_MSR \
 111.505 +	{ \
 111.506 +		u32 v = opcode & 0xff; \
 111.507 +		value = ((v << (32 - shift)) | \
 111.508 +		         (v >> shift)); \
 111.509 +	}
 111.510 +			#define ROR_VALUE \
 111.511 +	{ \
 111.512 +		value = ((value << (32 - shift)) | \
 111.513 +		         (value >> shift)); \
 111.514 +	}
 111.515 +			#define RCR_VALUE \
 111.516 +	{ \
 111.517 +		shift = (int)C_FLAG; \
 111.518 +		value = ((value >> 1) | \
 111.519 +		         (shift << 31)); \
 111.520 +	}
 111.521 +#else
 111.522 +#define OP_SUB \
 111.523 +    asm ("sub %1, %%ebx;" \
 111.524 +		 : "=b" (reg[dest].I) \
 111.525 +		 : "r" (value), "b" (reg[base].I));
 111.526 +
 111.527 +#define OP_SUBS \
 111.528 +    asm ("sub %1, %%ebx;" \
 111.529 +         "setsb N_FLAG;" \
 111.530 +         "setzb Z_FLAG;" \
 111.531 +         "setncb C_FLAG;" \
 111.532 +         "setob V_FLAG;" \
 111.533 +		 : "=b" (reg[dest].I) \
 111.534 +		 : "r" (value), "b" (reg[base].I));
 111.535 +
 111.536 +#define OP_RSB \
 111.537 +    asm  ("sub %1, %%ebx;" \
 111.538 +		  : "=b" (reg[dest].I) \
 111.539 +		  : "r" (reg[base].I), "b" (value));
 111.540 +
 111.541 +#define OP_RSBS \
 111.542 +    asm  ("sub %1, %%ebx;" \
 111.543 +          "setsb N_FLAG;" \
 111.544 +          "setzb Z_FLAG;" \
 111.545 +          "setncb C_FLAG;" \
 111.546 +          "setob V_FLAG;" \
 111.547 +		  : "=b" (reg[dest].I) \
 111.548 +		  : "r" (reg[base].I), "b" (value));
 111.549 +
 111.550 +#define OP_ADD \
 111.551 +    asm  ("add %1, %%ebx;" \
 111.552 +		  : "=b" (reg[dest].I) \
 111.553 +		  : "r" (value), "b" (reg[base].I));
 111.554 +
 111.555 +#define OP_ADDS \
 111.556 +    asm  ("add %1, %%ebx;" \
 111.557 +          "setsb N_FLAG;" \
 111.558 +          "setzb Z_FLAG;" \
 111.559 +          "setcb C_FLAG;" \
 111.560 +          "setob V_FLAG;" \
 111.561 +		  : "=b" (reg[dest].I) \
 111.562 +		  : "r" (value), "b" (reg[base].I));
 111.563 +
 111.564 +#define OP_ADC \
 111.565 +    asm  ("bt $0, C_FLAG;" \
 111.566 +          "adc %1, %%ebx;" \
 111.567 +		  : "=b" (reg[dest].I) \
 111.568 +		  : "r" (value), "b" (reg[base].I));
 111.569 +
 111.570 +#define OP_ADCS \
 111.571 +    asm  ("bt $0, C_FLAG;" \
 111.572 +          "adc %1, %%ebx;" \
 111.573 +          "setsb N_FLAG;" \
 111.574 +          "setzb Z_FLAG;" \
 111.575 +          "setcb C_FLAG;" \
 111.576 +          "setob V_FLAG;" \
 111.577 +		  : "=b" (reg[dest].I) \
 111.578 +		  : "r" (value), "b" (reg[base].I));
 111.579 +
 111.580 +#define OP_SBC \
 111.581 +    asm  ("bt $0, C_FLAG;" \
 111.582 +          "cmc;" \
 111.583 +          "sbb %1, %%ebx;" \
 111.584 +		  : "=b" (reg[dest].I) \
 111.585 +		  : "r" (value), "b" (reg[base].I));
 111.586 +
 111.587 +#define OP_SBCS \
 111.588 +    asm  ("bt $0, C_FLAG;" \
 111.589 +          "cmc;" \
 111.590 +          "sbb %1, %%ebx;" \
 111.591 +          "setsb N_FLAG;" \
 111.592 +          "setzb Z_FLAG;" \
 111.593 +          "setncb C_FLAG;" \
 111.594 +          "setob V_FLAG;" \
 111.595 +		  : "=b" (reg[dest].I) \
 111.596 +		  : "r" (value), "b" (reg[base].I));
 111.597 +#define OP_RSC \
 111.598 +    asm  ("bt $0, C_FLAG;" \
 111.599 +          "cmc;" \
 111.600 +          "sbb %1, %%ebx;" \
 111.601 +		  : "=b" (reg[dest].I) \
 111.602 +		  : "r" (reg[base].I), "b" (value));
 111.603 +
 111.604 +#define OP_RSCS \
 111.605 +    asm  ("bt $0, C_FLAG;" \
 111.606 +          "cmc;" \
 111.607 +          "sbb %1, %%ebx;" \
 111.608 +          "setsb N_FLAG;" \
 111.609 +          "setzb Z_FLAG;" \
 111.610 +          "setncb C_FLAG;" \
 111.611 +          "setob V_FLAG;" \
 111.612 +		  : "=b" (reg[dest].I) \
 111.613 +		  : "r" (reg[base].I), "b" (value));
 111.614 +#define OP_CMP \
 111.615 +    asm  ("sub %0, %1;" \
 111.616 +          "setsb N_FLAG;" \
 111.617 +          "setzb Z_FLAG;" \
 111.618 +          "setncb C_FLAG;" \
 111.619 +          "setob V_FLAG;" \
 111.620 +		  : \
 111.621 +		  : "r" (value), "r" (reg[base].I));
 111.622 +
 111.623 +#define OP_CMN \
 111.624 +    asm  ("add %0, %1;" \
 111.625 +          "setsb N_FLAG;" \
 111.626 +          "setzb Z_FLAG;" \
 111.627 +          "setcb C_FLAG;" \
 111.628 +          "setob V_FLAG;" \
 111.629 +		  : \
 111.630 +		  : "r" (value), "r" (reg[base].I));
 111.631 +#define LOGICAL_LSL_REG \
 111.632 +    asm ("shl %%cl, %%eax;" \
 111.633 +         "setcb %%cl;" \
 111.634 +		 : "=a" (value), "=c" (C_OUT) \
 111.635 +		 : "a" (reg[opcode & 0x0f].I), "c" (shift));
 111.636 +
 111.637 +#define LOGICAL_LSR_REG \
 111.638 +    asm ("shr %%cl, %%eax;" \
 111.639 +         "setcb %%cl;" \
 111.640 +		 : "=a" (value), "=c" (C_OUT) \
 111.641 +		 : "a" (reg[opcode & 0x0f].I), "c" (shift));
 111.642 +
 111.643 +#define LOGICAL_ASR_REG \
 111.644 +    asm ("sar %%cl, %%eax;" \
 111.645 +         "setcb %%cl;" \
 111.646 +		 : "=a" (value), "=c" (C_OUT) \
 111.647 +		 : "a" (reg[opcode & 0x0f].I), "c" (shift));
 111.648 +
 111.649 +#define LOGICAL_ROR_REG \
 111.650 +    asm ("ror %%cl, %%eax;" \
 111.651 +         "setcb %%cl;" \
 111.652 +		 : "=a" (value), "=c" (C_OUT) \
 111.653 +		 : "a" (reg[opcode & 0x0f].I), "c" (shift));
 111.654 +
 111.655 +#define LOGICAL_RRX_REG \
 111.656 +    asm ("bt $0, C_FLAG;" \
 111.657 +         "rcr $1, %%eax;" \
 111.658 +         "setcb %%cl;" \
 111.659 +		 : "=a" (value), "=c" (C_OUT) \
 111.660 +		 : "a" (reg[opcode & 0x0f].I));
 111.661 +
 111.662 +#define LOGICAL_ROR_IMM \
 111.663 +    asm ("ror %%cl, %%eax;" \
 111.664 +         "setcb %%cl;" \
 111.665 +		 : "=a" (value), "=c" (C_OUT) \
 111.666 +		 : "a" (opcode & 0xff), "c" (shift));
 111.667 +#define ARITHMETIC_LSL_REG \
 111.668 +    asm ("\
 111.669 +             shl %%cl, %%eax;" \
 111.670 +		 : "=a" (value) \
 111.671 +		 : "a" (reg[opcode & 0x0f].I), "c" (shift));
 111.672 +
 111.673 +#define ARITHMETIC_LSR_REG \
 111.674 +    asm ("\
 111.675 +             shr %%cl, %%eax;" \
 111.676 +		 : "=a" (value) \
 111.677 +		 : "a" (reg[opcode & 0x0f].I), "c" (shift));
 111.678 +
 111.679 +#define ARITHMETIC_ASR_REG \
 111.680 +    asm ("\
 111.681 +             sar %%cl, %%eax;" \
 111.682 +		 : "=a" (value) \
 111.683 +		 : "a" (reg[opcode & 0x0f].I), "c" (shift));
 111.684 +
 111.685 +#define ARITHMETIC_ROR_REG \
 111.686 +    asm ("\
 111.687 +             ror %%cl, %%eax;" \
 111.688 +		 : "=a" (value) \
 111.689 +		 : "a" (reg[opcode & 0x0f].I), "c" (shift));
 111.690 +
 111.691 +#define ARITHMETIC_RRX_REG \
 111.692 +    asm ("\
 111.693 +             bt $0, C_FLAG;\
 111.694 +             rcr $1, %%eax;" \
 111.695 +		 : "=a" (value) \
 111.696 +		 : "a" (reg[opcode & 0x0f].I));
 111.697 +
 111.698 +#define ARITHMETIC_ROR_IMM \
 111.699 +    asm ("\
 111.700 +             ror %%cl, %%eax;" \
 111.701 +		 : "=a" (value) \
 111.702 +		 : "a" (opcode & 0xff), "c" (shift));
 111.703 +#define ROR_IMM_MSR \
 111.704 +    asm ("ror %%cl, %%eax;" \
 111.705 +		 : "=a" (value) \
 111.706 +		 : "a" (opcode & 0xFF), "c" (shift));
 111.707 +#define ROR_VALUE \
 111.708 +    asm ("ror %%cl, %0" \
 111.709 +		 : "=r" (value) \
 111.710 +		 : "r" (value), "c" (shift));
 111.711 +#define RCR_VALUE \
 111.712 +    asm ("bt $0, C_FLAG;" \
 111.713 +         "rcr $1, %0" \
 111.714 +		 : "=r" (value) \
 111.715 +		 : "r" (value));
 111.716 +#endif
 111.717 +#else
 111.718 +#define OP_SUB \
 111.719 +	{ \
 111.720 +		__asm mov ebx, base \
 111.721 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * ebx] \
 111.722 +		__asm sub ebx, value \
 111.723 +		__asm mov eax, dest \
 111.724 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 111.725 +	}
 111.726 +
 111.727 +#define OP_SUBS \
 111.728 +	{ \
 111.729 +		__asm mov ebx, base \
 111.730 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * ebx] \
 111.731 +		__asm sub ebx, value \
 111.732 +		__asm mov eax, dest \
 111.733 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 111.734 +		__asm sets byte ptr N_FLAG \
 111.735 +		__asm setz byte ptr Z_FLAG \
 111.736 +		__asm setnc byte ptr C_FLAG \
 111.737 +		__asm seto byte ptr V_FLAG \
 111.738 +	}
 111.739 +
 111.740 +#define OP_RSB \
 111.741 +	{ \
 111.742 +		__asm mov ebx, base \
 111.743 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * ebx] \
 111.744 +		__asm mov eax, value \
 111.745 +		__asm sub eax, ebx \
 111.746 +		__asm mov ebx, dest \
 111.747 +		__asm mov dword ptr [OFFSET reg + 4 * ebx], eax \
 111.748 +	}
 111.749 +
 111.750 +#define OP_RSBS \
 111.751 +	{ \
 111.752 +		__asm mov ebx, base \
 111.753 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * ebx] \
 111.754 +		__asm mov eax, value \
 111.755 +		__asm sub eax, ebx \
 111.756 +		__asm mov ebx, dest \
 111.757 +		__asm mov dword ptr [OFFSET reg + 4 * ebx], eax \
 111.758 +		__asm sets byte ptr N_FLAG \
 111.759 +		__asm setz byte ptr Z_FLAG \
 111.760 +		__asm setnc byte ptr C_FLAG \
 111.761 +		__asm seto byte ptr V_FLAG \
 111.762 +	}
 111.763 +
 111.764 +#define OP_ADD \
 111.765 +	{ \
 111.766 +		__asm mov ebx, base \
 111.767 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * ebx] \
 111.768 +		__asm add ebx, value \
 111.769 +		__asm mov eax, dest \
 111.770 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 111.771 +	}
 111.772 +
 111.773 +#define OP_ADDS \
 111.774 +	{ \
 111.775 +		__asm mov ebx, base \
 111.776 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * ebx] \
 111.777 +		__asm add ebx, value \
 111.778 +		__asm mov eax, dest \
 111.779 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 111.780 +		__asm sets byte ptr N_FLAG \
 111.781 +		__asm setz byte ptr Z_FLAG \
 111.782 +		__asm setc byte ptr C_FLAG \
 111.783 +		__asm seto byte ptr V_FLAG \
 111.784 +	}
 111.785 +
 111.786 +#define OP_ADC \
 111.787 +	{ \
 111.788 +		__asm mov ebx, base \
 111.789 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * ebx] \
 111.790 +		__asm bt word ptr C_FLAG, 0 \
 111.791 +		__asm adc ebx, value \
 111.792 +		__asm mov eax, dest \
 111.793 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 111.794 +	}
 111.795 +
 111.796 +#define OP_ADCS \
 111.797 +	{ \
 111.798 +		__asm mov ebx, base \
 111.799 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * ebx] \
 111.800 +		__asm bt word ptr C_FLAG, 0 \
 111.801 +		__asm adc ebx, value \
 111.802 +		__asm mov eax, dest \
 111.803 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 111.804 +		__asm sets byte ptr N_FLAG \
 111.805 +		__asm setz byte ptr Z_FLAG \
 111.806 +		__asm setc byte ptr C_FLAG \
 111.807 +		__asm seto byte ptr V_FLAG \
 111.808 +	}
 111.809 +
 111.810 +#define OP_SBC \
 111.811 +	{ \
 111.812 +		__asm mov ebx, base \
 111.813 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * ebx] \
 111.814 +		__asm mov eax, value \
 111.815 +		__asm bt word ptr C_FLAG, 0 \
 111.816 +		__asm cmc \
 111.817 +		__asm sbb ebx, eax \
 111.818 +		__asm mov eax, dest \
 111.819 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 111.820 +	}
 111.821 +
 111.822 +#define OP_SBCS \
 111.823 +	{ \
 111.824 +		__asm mov ebx, base \
 111.825 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * ebx] \
 111.826 +		__asm mov eax, value \
 111.827 +		__asm bt word ptr C_FLAG, 0 \
 111.828 +		__asm cmc \
 111.829 +		__asm sbb ebx, eax \
 111.830 +		__asm mov eax, dest \
 111.831 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 111.832 +		__asm sets byte ptr N_FLAG \
 111.833 +		__asm setz byte ptr Z_FLAG \
 111.834 +		__asm setnc byte ptr C_FLAG \
 111.835 +		__asm seto byte ptr V_FLAG \
 111.836 +	}
 111.837 +#define OP_RSC \
 111.838 +	{ \
 111.839 +		__asm mov ebx, value \
 111.840 +		__asm mov eax, base \
 111.841 +		__asm mov eax, dword ptr[OFFSET reg + 4 * eax] \
 111.842 +		__asm bt word ptr C_FLAG, 0 \
 111.843 +		__asm cmc \
 111.844 +		__asm sbb ebx, eax \
 111.845 +		__asm mov eax, dest \
 111.846 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 111.847 +	}
 111.848 +
 111.849 +#define OP_RSCS \
 111.850 +	{ \
 111.851 +		__asm mov ebx, value \
 111.852 +		__asm mov eax, base \
 111.853 +		__asm mov eax, dword ptr[OFFSET reg + 4 * eax] \
 111.854 +		__asm bt word ptr C_FLAG, 0 \
 111.855 +		__asm cmc \
 111.856 +		__asm sbb ebx, eax \
 111.857 +		__asm mov eax, dest \
 111.858 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 111.859 +		__asm sets byte ptr N_FLAG \
 111.860 +		__asm setz byte ptr Z_FLAG \
 111.861 +		__asm setnc byte ptr C_FLAG \
 111.862 +		__asm seto byte ptr V_FLAG \
 111.863 +	}
 111.864 +#define OP_CMP \
 111.865 +	{ \
 111.866 +		__asm mov eax, base \
 111.867 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * eax] \
 111.868 +		__asm sub ebx, value \
 111.869 +		__asm sets byte ptr N_FLAG \
 111.870 +		__asm setz byte ptr Z_FLAG \
 111.871 +		__asm setnc byte ptr C_FLAG \
 111.872 +		__asm seto byte ptr V_FLAG \
 111.873 +	}
 111.874 +
 111.875 +#define OP_CMN \
 111.876 +	{ \
 111.877 +		__asm mov eax, base \
 111.878 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * eax] \
 111.879 +		__asm add ebx, value \
 111.880 +		__asm sets byte ptr N_FLAG \
 111.881 +		__asm setz byte ptr Z_FLAG \
 111.882 +		__asm setc byte ptr C_FLAG \
 111.883 +		__asm seto byte ptr V_FLAG \
 111.884 +	}
 111.885 +#define LOGICAL_LSL_REG \
 111.886 +    __asm mov eax, opcode \
 111.887 +    __asm and eax, 0x0f \
 111.888 +    __asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 111.889 +    __asm mov cl, byte ptr shift \
 111.890 +    __asm shl eax, cl \
 111.891 +    __asm mov value, eax \
 111.892 +    __asm setc byte ptr C_OUT
 111.893 +
 111.894 +#define LOGICAL_LSR_REG \
 111.895 +    __asm mov eax, opcode \
 111.896 +    __asm and eax, 0x0f \
 111.897 +    __asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 111.898 +    __asm mov cl, byte ptr shift \
 111.899 +    __asm shr eax, cl \
 111.900 +    __asm mov value, eax \
 111.901 +    __asm setc byte ptr C_OUT
 111.902 +
 111.903 +#define LOGICAL_ASR_REG \
 111.904 +    __asm mov eax, opcode \
 111.905 +    __asm and eax, 0x0f \
 111.906 +    __asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 111.907 +    __asm mov cl, byte ptr shift \
 111.908 +    __asm sar eax, cl \
 111.909 +    __asm mov value, eax \
 111.910 +    __asm setc byte ptr C_OUT
 111.911 +
 111.912 +#define LOGICAL_ROR_REG \
 111.913 +    __asm mov eax, opcode \
 111.914 +    __asm and eax, 0x0F \
 111.915 +    __asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 111.916 +    __asm mov cl, byte ptr shift \
 111.917 +    __asm ror eax, cl \
 111.918 +    __asm mov value, eax \
 111.919 +    __asm setc byte ptr C_OUT
 111.920 +
 111.921 +#define LOGICAL_RRX_REG \
 111.922 +    __asm mov eax, opcode \
 111.923 +    __asm and eax, 0x0F \
 111.924 +    __asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 111.925 +    __asm bt word ptr C_OUT, 0 \
 111.926 +    __asm rcr eax, 1 \
 111.927 +    __asm mov value, eax \
 111.928 +    __asm setc byte ptr C_OUT
 111.929 +
 111.930 +#define LOGICAL_ROR_IMM \
 111.931 +    __asm mov eax, opcode \
 111.932 +    __asm and eax, 0xff \
 111.933 +    __asm mov cl, byte ptr shift \
 111.934 +    __asm ror eax, cl \
 111.935 +    __asm mov value, eax \
 111.936 +    __asm setc byte ptr C_OUT
 111.937 +#define ARITHMETIC_LSL_REG \
 111.938 +    __asm mov eax, opcode \
 111.939 +    __asm and eax, 0x0f \
 111.940 +    __asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 111.941 +    __asm mov cl, byte ptr shift \
 111.942 +    __asm shl eax, cl \
 111.943 +    __asm mov value, eax
 111.944 +
 111.945 +#define ARITHMETIC_LSR_REG \
 111.946 +    __asm mov eax, opcode \
 111.947 +    __asm and eax, 0x0f \
 111.948 +    __asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 111.949 +    __asm mov cl, byte ptr shift \
 111.950 +    __asm shr eax, cl \
 111.951 +    __asm mov value, eax
 111.952 +
 111.953 +#define ARITHMETIC_ASR_REG \
 111.954 +    __asm mov eax, opcode \
 111.955 +    __asm and eax, 0x0f \
 111.956 +    __asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 111.957 +    __asm mov cl, byte ptr shift \
 111.958 +    __asm sar eax, cl \
 111.959 +    __asm mov value, eax
 111.960 +
 111.961 +#define ARITHMETIC_ROR_REG \
 111.962 +    __asm mov eax, opcode \
 111.963 +    __asm and eax, 0x0F \
 111.964 +    __asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 111.965 +    __asm mov cl, byte ptr shift \
 111.966 +    __asm ror eax, cl \
 111.967 +    __asm mov value, eax
 111.968 +
 111.969 +#define ARITHMETIC_RRX_REG \
 111.970 +    __asm mov eax, opcode \
 111.971 +    __asm and eax, 0x0F \
 111.972 +    __asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 111.973 +    __asm bt word ptr C_FLAG, 0 \
 111.974 +    __asm rcr eax, 1 \
 111.975 +    __asm mov value, eax
 111.976 +
 111.977 +#define ARITHMETIC_ROR_IMM \
 111.978 +    __asm mov eax, opcode \
 111.979 +    __asm and eax, 0xff \
 111.980 +    __asm mov cl, byte ptr shift \
 111.981 +    __asm ror eax, cl \
 111.982 +    __asm mov value, eax
 111.983 +#define ROR_IMM_MSR \
 111.984 +	{ \
 111.985 +		__asm mov eax, opcode \
 111.986 +		          __asm and eax, 0xff \
 111.987 +		__asm mov cl, byte ptr shift \
 111.988 +		__asm ror eax, CL \
 111.989 +		__asm mov value, eax \
 111.990 +	}
 111.991 +#define ROR_VALUE \
 111.992 +	{ \
 111.993 +		__asm mov cl, byte ptr shift \
 111.994 +		__asm ror dword ptr value, cl \
 111.995 +	}
 111.996 +#define RCR_VALUE \
 111.997 +	{ \
 111.998 +		__asm mov cl, byte ptr shift \
 111.999 +		__asm bt word ptr C_FLAG, 0 \
111.1000 +		__asm rcr dword ptr value, 1 \
111.1001 +	}
111.1002 +#endif
111.1003 +#endif
111.1004 +
111.1005 +#define OP_TST \
111.1006 +    u32 res = reg[base].I & value; \
111.1007 +    N_FLAG	= (res & 0x80000000) ? true : false; \
111.1008 +    Z_FLAG	= (res) ? false : true; \
111.1009 +    C_FLAG	= C_OUT;
111.1010 +
111.1011 +#define OP_TEQ \
111.1012 +    u32 res = reg[base].I ^ value; \
111.1013 +    N_FLAG	= (res & 0x80000000) ? true : false; \
111.1014 +    Z_FLAG	= (res) ? false : true; \
111.1015 +    C_FLAG	= C_OUT;
111.1016 +
111.1017 +#define OP_ORR \
111.1018 +    reg[dest].I = reg[base].I | value;
111.1019 +
111.1020 +#define OP_ORRS \
111.1021 +    reg[dest].I = reg[base].I | value; \
111.1022 +    N_FLAG		= (reg[dest].I & 0x80000000) ? true : false; \
111.1023 +    Z_FLAG		= (reg[dest].I) ? false : true; \
111.1024 +    C_FLAG		= C_OUT;
111.1025 +
111.1026 +#define OP_MOV \
111.1027 +    reg[dest].I = value;
111.1028 +
111.1029 +#define OP_MOVS \
111.1030 +    reg[dest].I = value; \
111.1031 +    N_FLAG		= (reg[dest].I & 0x80000000) ? true : false; \
111.1032 +    Z_FLAG		= (reg[dest].I) ? false : true; \
111.1033 +    C_FLAG		= C_OUT;
111.1034 +
111.1035 +#define OP_BIC \
111.1036 +    reg[dest].I = reg[base].I & (~value);
111.1037 +
111.1038 +#define OP_BICS \
111.1039 +    reg[dest].I = reg[base].I & (~value); \
111.1040 +    N_FLAG		= (reg[dest].I & 0x80000000) ? true : false; \
111.1041 +    Z_FLAG		= (reg[dest].I) ? false : true; \
111.1042 +    C_FLAG		= C_OUT;
111.1043 +
111.1044 +#define OP_MVN \
111.1045 +    reg[dest].I = ~value;
111.1046 +
111.1047 +#define OP_MVNS \
111.1048 +    reg[dest].I = ~value; \
111.1049 +    N_FLAG		= (reg[dest].I & 0x80000000) ? true : false; \
111.1050 +    Z_FLAG		= (reg[dest].I) ? false : true; \
111.1051 +    C_FLAG		= C_OUT;
111.1052 +
111.1053 +#define CASE_16(BASE) \
111.1054 +case BASE: \
111.1055 +case BASE + 1: \
111.1056 +case BASE + 2: \
111.1057 +case BASE + 3: \
111.1058 +case BASE + 4: \
111.1059 +case BASE + 5: \
111.1060 +case BASE + 6: \
111.1061 +case BASE + 7: \
111.1062 +case BASE + 8: \
111.1063 +case BASE + 9: \
111.1064 +case BASE + 10: \
111.1065 +case BASE + 11: \
111.1066 +case BASE + 12: \
111.1067 +case BASE + 13: \
111.1068 +case BASE + 14: \
111.1069 +case BASE + 15:
111.1070 +
111.1071 +#define CASE_256(BASE) \
111.1072 +    CASE_16(BASE) \
111.1073 +    CASE_16(BASE + 0x10) \
111.1074 +    CASE_16(BASE + 0x20) \
111.1075 +    CASE_16(BASE + 0x30) \
111.1076 +    CASE_16(BASE + 0x40) \
111.1077 +    CASE_16(BASE + 0x50) \
111.1078 +    CASE_16(BASE + 0x60) \
111.1079 +    CASE_16(BASE + 0x70) \
111.1080 +    CASE_16(BASE + 0x80) \
111.1081 +    CASE_16(BASE + 0x90) \
111.1082 +    CASE_16(BASE + 0xa0) \
111.1083 +    CASE_16(BASE + 0xb0) \
111.1084 +    CASE_16(BASE + 0xc0) \
111.1085 +    CASE_16(BASE + 0xd0) \
111.1086 +    CASE_16(BASE + 0xe0) \
111.1087 +    CASE_16(BASE + 0xf0)
111.1088 +
111.1089 +#define LOGICAL_DATA_OPCODE(OPCODE, OPCODE2, BASE) \
111.1090 +case BASE: \
111.1091 +case BASE + 8: \
111.1092 +{ \
111.1093 +	/* OP Rd,Rb,Rm LSL # */ \
111.1094 +	int	 base  = (opcode >> 16) & 0x0F; \
111.1095 +	int	 shift = (opcode >> 7) & 0x1F; \
111.1096 +	int	 dest  = (opcode >> 12) & 15; \
111.1097 +	bool C_OUT = C_FLAG; \
111.1098 +	u32	 value; \
111.1099 +      \
111.1100 +	if (shift) { \
111.1101 +		LOGICAL_LSL_REG \
111.1102 +	} else { \
111.1103 +		value = reg[opcode & 0x0F].I; \
111.1104 +	} \
111.1105 +	if (dest == 15) { \
111.1106 +		OPCODE2 \
111.1107 +		/* todo */ \
111.1108 +		if (opcode & 0x00100000) { \
111.1109 +			clockTicks++; \
111.1110 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1111 +		} \
111.1112 +		if (armState) { \
111.1113 +			reg[15].I &= 0xFFFFFFFC; \
111.1114 +			armNextPC  = reg[15].I; \
111.1115 +			reg[15].I += 4; \
111.1116 +		} else { \
111.1117 +			reg[15].I &= 0xFFFFFFFE; \
111.1118 +			armNextPC  = reg[15].I; \
111.1119 +			reg[15].I += 2; \
111.1120 +		} \
111.1121 +	} else { \
111.1122 +		OPCODE \
111.1123 +	} \
111.1124 +} \
111.1125 +break; \
111.1126 +case BASE + 2: \
111.1127 +case BASE + 10: \
111.1128 +{ \
111.1129 +	/* OP Rd,Rb,Rm LSR # */ \
111.1130 +	int	 base  = (opcode >> 16) & 0x0F; \
111.1131 +	int	 shift = (opcode >> 7) & 0x1F; \
111.1132 +	int	 dest  = (opcode >> 12) & 15; \
111.1133 +	bool C_OUT = C_FLAG; \
111.1134 +	u32	 value; \
111.1135 +	if (shift) { \
111.1136 +		LOGICAL_LSR_REG \
111.1137 +	} else { \
111.1138 +		value = 0; \
111.1139 +		C_OUT = (reg[opcode & 0x0F].I & 0x80000000) ? true : false; \
111.1140 +	} \
111.1141 +      \
111.1142 +	if (dest == 15) { \
111.1143 +		OPCODE2 \
111.1144 +		/* todo */ \
111.1145 +		if (opcode & 0x00100000) { \
111.1146 +			clockTicks++; \
111.1147 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1148 +		} \
111.1149 +		if (armState) { \
111.1150 +			reg[15].I &= 0xFFFFFFFC; \
111.1151 +			armNextPC  = reg[15].I; \
111.1152 +			reg[15].I += 4; \
111.1153 +		} else { \
111.1154 +			reg[15].I &= 0xFFFFFFFE; \
111.1155 +			armNextPC  = reg[15].I; \
111.1156 +			reg[15].I += 2; \
111.1157 +		} \
111.1158 +	} else { \
111.1159 +		OPCODE \
111.1160 +	} \
111.1161 +} \
111.1162 +break; \
111.1163 +case BASE + 4: \
111.1164 +case BASE + 12: \
111.1165 +{ \
111.1166 +	/* OP Rd,Rb,Rm ASR # */ \
111.1167 +	int	 base  = (opcode >> 16) & 0x0F; \
111.1168 +	int	 shift = (opcode >> 7) & 0x1F; \
111.1169 +	int	 dest  = (opcode >> 12) & 15; \
111.1170 +	bool C_OUT = C_FLAG; \
111.1171 +	u32	 value; \
111.1172 +	if (shift) { \
111.1173 +		LOGICAL_ASR_REG \
111.1174 +	} else { \
111.1175 +		if (reg[opcode & 0x0F].I & 0x80000000) { \
111.1176 +			value = 0xFFFFFFFF; \
111.1177 +			C_OUT = true; \
111.1178 +		} else { \
111.1179 +			value = 0; \
111.1180 +			C_OUT = false; \
111.1181 +		}                   \
111.1182 +	} \
111.1183 +      \
111.1184 +	if (dest == 15) { \
111.1185 +		OPCODE2 \
111.1186 +		/* todo */ \
111.1187 +		if (opcode & 0x00100000) { \
111.1188 +			clockTicks++; \
111.1189 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1190 +		} \
111.1191 +		if (armState) { \
111.1192 +			reg[15].I &= 0xFFFFFFFC; \
111.1193 +			armNextPC  = reg[15].I; \
111.1194 +			reg[15].I += 4; \
111.1195 +		} else { \
111.1196 +			reg[15].I &= 0xFFFFFFFE; \
111.1197 +			armNextPC  = reg[15].I; \
111.1198 +			reg[15].I += 2; \
111.1199 +		} \
111.1200 +	} else { \
111.1201 +		OPCODE \
111.1202 +	} \
111.1203 +} \
111.1204 +break; \
111.1205 +case BASE + 6: \
111.1206 +case BASE + 14: \
111.1207 +{ \
111.1208 +	/* OP Rd,Rb,Rm ROR # */ \
111.1209 +	int	 base  = (opcode >> 16) & 0x0F; \
111.1210 +	int	 shift = (opcode >> 7) & 0x1F; \
111.1211 +	int	 dest  = (opcode >> 12) & 15; \
111.1212 +	bool C_OUT = C_FLAG; \
111.1213 +	u32	 value; \
111.1214 +	if (shift) { \
111.1215 +		LOGICAL_ROR_REG \
111.1216 +	} else { \
111.1217 +		LOGICAL_RRX_REG \
111.1218 +	} \
111.1219 +	if (dest == 15) { \
111.1220 +		OPCODE2 \
111.1221 +		/* todo */ \
111.1222 +		if (opcode & 0x00100000) { \
111.1223 +			clockTicks++; \
111.1224 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1225 +		} \
111.1226 +		if (armState) { \
111.1227 +			reg[15].I &= 0xFFFFFFFC; \
111.1228 +			armNextPC  = reg[15].I; \
111.1229 +			reg[15].I += 4; \
111.1230 +		} else { \
111.1231 +			reg[15].I &= 0xFFFFFFFE; \
111.1232 +			armNextPC  = reg[15].I; \
111.1233 +			reg[15].I += 2; \
111.1234 +		} \
111.1235 +	} else { \
111.1236 +		OPCODE \
111.1237 +	} \
111.1238 +} \
111.1239 +break; \
111.1240 +case BASE + 1: \
111.1241 +{ \
111.1242 +	/* OP Rd,Rb,Rm LSL Rs */ \
111.1243 +	clockTicks++; \
111.1244 +	int	 base  = (opcode >> 16) & 0x0F; \
111.1245 +	int	 shift = reg[(opcode >> 8) & 15].B.B0; \
111.1246 +	int	 dest  = (opcode >> 12) & 15; \
111.1247 +	bool C_OUT = C_FLAG; \
111.1248 +	u32	 value; \
111.1249 +	if (shift) { \
111.1250 +		if (shift == 32) { \
111.1251 +			value = 0; \
111.1252 +			C_OUT = (reg[opcode & 0x0F].I & 1 ? true : false); \
111.1253 +		} else if (shift < 32) { \
111.1254 +			LOGICAL_LSL_REG \
111.1255 +		} else { \
111.1256 +			value = 0; \
111.1257 +			C_OUT = false; \
111.1258 +		} \
111.1259 +	} else { \
111.1260 +		value = reg[opcode & 0x0F].I; \
111.1261 +	} \
111.1262 +	if (dest == 15) { \
111.1263 +		OPCODE2 \
111.1264 +		/* todo */ \
111.1265 +		if (opcode & 0x00100000) { \
111.1266 +			clockTicks++; \
111.1267 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1268 +		} \
111.1269 +		if (armState) { \
111.1270 +			reg[15].I &= 0xFFFFFFFC; \
111.1271 +			armNextPC  = reg[15].I; \
111.1272 +			reg[15].I += 4; \
111.1273 +		} else { \
111.1274 +			reg[15].I &= 0xFFFFFFFE; \
111.1275 +			armNextPC  = reg[15].I; \
111.1276 +			reg[15].I += 2; \
111.1277 +		} \
111.1278 +	} else { \
111.1279 +		OPCODE \
111.1280 +	} \
111.1281 +} \
111.1282 +break; \
111.1283 +case BASE + 3: \
111.1284 +{ \
111.1285 +	/* OP Rd,Rb,Rm LSR Rs */ \
111.1286 +	clockTicks++; \
111.1287 +	int	 base  = (opcode >> 16) & 0x0F; \
111.1288 +	int	 shift = reg[(opcode >> 8) & 15].B.B0; \
111.1289 +	int	 dest  = (opcode >> 12) & 15; \
111.1290 +	bool C_OUT = C_FLAG; \
111.1291 +	u32	 value; \
111.1292 +	if (shift) { \
111.1293 +		if (shift == 32) { \
111.1294 +			value = 0; \
111.1295 +			C_OUT = (reg[opcode & 0x0F].I & 0x80000000 ? true : false); \
111.1296 +		} else if (shift < 32) { \
111.1297 +			LOGICAL_LSR_REG \
111.1298 +		} else { \
111.1299 +			value = 0; \
111.1300 +			C_OUT = false; \
111.1301 +		} \
111.1302 +	} else { \
111.1303 +		value = reg[opcode & 0x0F].I; \
111.1304 +	} \
111.1305 +	if (dest == 15) { \
111.1306 +		OPCODE2 \
111.1307 +		/* todo */ \
111.1308 +		if (opcode & 0x00100000) { \
111.1309 +			clockTicks++; \
111.1310 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1311 +		} \
111.1312 +		if (armState) { \
111.1313 +			reg[15].I &= 0xFFFFFFFC; \
111.1314 +			armNextPC  = reg[15].I; \
111.1315 +			reg[15].I += 4; \
111.1316 +		} else { \
111.1317 +			reg[15].I &= 0xFFFFFFFE; \
111.1318 +			armNextPC  = reg[15].I; \
111.1319 +			reg[15].I += 2; \
111.1320 +		} \
111.1321 +	} else { \
111.1322 +		OPCODE \
111.1323 +	} \
111.1324 +} \
111.1325 +break; \
111.1326 +case BASE + 5: \
111.1327 +{ \
111.1328 +	/* OP Rd,Rb,Rm ASR Rs */ \
111.1329 +	clockTicks++; \
111.1330 +	int	 base  = (opcode >> 16) & 0x0F; \
111.1331 +	int	 shift = reg[(opcode >> 8) & 15].B.B0; \
111.1332 +	int	 dest  = (opcode >> 12) & 15; \
111.1333 +	bool C_OUT = C_FLAG; \
111.1334 +	u32	 value; \
111.1335 +	if (shift < 32) { \
111.1336 +		if (shift) { \
111.1337 +			LOGICAL_ASR_REG \
111.1338 +		} else { \
111.1339 +			value = reg[opcode & 0x0F].I; \
111.1340 +		} \
111.1341 +	} else { \
111.1342 +		if (reg[opcode & 0x0F].I & 0x80000000) { \
111.1343 +			value = 0xFFFFFFFF; \
111.1344 +			C_OUT = true; \
111.1345 +		} else { \
111.1346 +			value = 0; \
111.1347 +			C_OUT = false; \
111.1348 +		} \
111.1349 +	} \
111.1350 +	if (dest == 15) { \
111.1351 +		OPCODE2 \
111.1352 +		/* todo */ \
111.1353 +		if (opcode & 0x00100000) { \
111.1354 +			clockTicks++; \
111.1355 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1356 +		} \
111.1357 +		if (armState) { \
111.1358 +			reg[15].I &= 0xFFFFFFFC; \
111.1359 +			armNextPC  = reg[15].I; \
111.1360 +			reg[15].I += 4; \
111.1361 +		} else { \
111.1362 +			reg[15].I &= 0xFFFFFFFE; \
111.1363 +			armNextPC  = reg[15].I; \
111.1364 +			reg[15].I += 2; \
111.1365 +		} \
111.1366 +	} else { \
111.1367 +		OPCODE \
111.1368 +	} \
111.1369 +} \
111.1370 +break; \
111.1371 +case BASE + 7: \
111.1372 +{ \
111.1373 +	/* OP Rd,Rb,Rm ROR Rs */ \
111.1374 +	clockTicks++; \
111.1375 +	int	 base  = (opcode >> 16) & 0x0F; \
111.1376 +	int	 shift = reg[(opcode >> 8) & 15].B.B0; \
111.1377 +	int	 dest  = (opcode >> 12) & 15; \
111.1378 +	bool C_OUT = C_FLAG; \
111.1379 +	u32	 value; \
111.1380 +	if (shift) { \
111.1381 +		shift &= 0x1f; \
111.1382 +		if (shift) { \
111.1383 +			LOGICAL_ROR_REG \
111.1384 +		} else { \
111.1385 +			value = reg[opcode & 0x0F].I; \
111.1386 +			C_OUT = (value & 0x80000000 ? true : false); \
111.1387 +		} \
111.1388 +	} else { \
111.1389 +		value = reg[opcode & 0x0F].I; \
111.1390 +		C_OUT = (value & 0x80000000 ? true : false); \
111.1391 +	} \
111.1392 +	if (dest == 15) { \
111.1393 +		OPCODE2 \
111.1394 +		/* todo */ \
111.1395 +		if (opcode & 0x00100000) { \
111.1396 +			clockTicks++; \
111.1397 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1398 +		} \
111.1399 +		if (armState) { \
111.1400 +			reg[15].I &= 0xFFFFFFFC; \
111.1401 +			armNextPC  = reg[15].I; \
111.1402 +			reg[15].I += 4; \
111.1403 +		} else { \
111.1404 +			reg[15].I &= 0xFFFFFFFE; \
111.1405 +			armNextPC  = reg[15].I; \
111.1406 +			reg[15].I += 2; \
111.1407 +		} \
111.1408 +	} else { \
111.1409 +		OPCODE \
111.1410 +	} \
111.1411 +} \
111.1412 +break; \
111.1413 +case BASE + 0x200: \
111.1414 +case BASE + 0x201: \
111.1415 +case BASE + 0x202: \
111.1416 +case BASE + 0x203: \
111.1417 +case BASE + 0x204: \
111.1418 +case BASE + 0x205: \
111.1419 +case BASE + 0x206: \
111.1420 +case BASE + 0x207: \
111.1421 +case BASE + 0x208: \
111.1422 +case BASE + 0x209: \
111.1423 +case BASE + 0x20a: \
111.1424 +case BASE + 0x20b: \
111.1425 +case BASE + 0x20c: \
111.1426 +case BASE + 0x20d: \
111.1427 +case BASE + 0x20e: \
111.1428 +case BASE + 0x20f: \
111.1429 +{ \
111.1430 +	int	 shift = (opcode & 0xF00) >> 7; \
111.1431 +	int	 base  = (opcode >> 16) & 0x0F; \
111.1432 +	int	 dest  = (opcode >> 12) & 0x0F; \
111.1433 +	bool C_OUT = C_FLAG; \
111.1434 +	u32	 value; \
111.1435 +	if (shift) { \
111.1436 +		LOGICAL_ROR_IMM \
111.1437 +	} else { \
111.1438 +		value = opcode & 0xff; \
111.1439 +	} \
111.1440 +	if (dest == 15) { \
111.1441 +		OPCODE2 \
111.1442 +		/* todo */ \
111.1443 +		if (opcode & 0x00100000) { \
111.1444 +			clockTicks++; \
111.1445 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1446 +		} \
111.1447 +		if (armState) { \
111.1448 +			reg[15].I &= 0xFFFFFFFC; \
111.1449 +			armNextPC  = reg[15].I; \
111.1450 +			reg[15].I += 4; \
111.1451 +		} else { \
111.1452 +			reg[15].I &= 0xFFFFFFFE; \
111.1453 +			armNextPC  = reg[15].I; \
111.1454 +			reg[15].I += 2; \
111.1455 +		} \
111.1456 +	} else { \
111.1457 +		OPCODE \
111.1458 +	} \
111.1459 +} \
111.1460 +break;
111.1461 +
111.1462 +#define LOGICAL_DATA_OPCODE_WITHOUT_base(OPCODE, OPCODE2, BASE) \
111.1463 +case BASE: \
111.1464 +case BASE + 8: \
111.1465 +{ \
111.1466 +	/* OP Rd,Rb,Rm LSL # */ \
111.1467 +	int	 shift = (opcode >> 7) & 0x1F; \
111.1468 +	int	 dest  = (opcode >> 12) & 15; \
111.1469 +	bool C_OUT = C_FLAG; \
111.1470 +	u32	 value; \
111.1471 +      \
111.1472 +	if (shift) { \
111.1473 +		LOGICAL_LSL_REG \
111.1474 +	} else { \
111.1475 +		value = reg[opcode & 0x0F].I; \
111.1476 +	} \
111.1477 +	if (dest == 15) { \
111.1478 +		OPCODE2 \
111.1479 +		/* todo */ \
111.1480 +		if (opcode & 0x00100000) { \
111.1481 +			clockTicks++; \
111.1482 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1483 +		} \
111.1484 +		if (armState) { \
111.1485 +			reg[15].I &= 0xFFFFFFFC; \
111.1486 +			armNextPC  = reg[15].I; \
111.1487 +			reg[15].I += 4; \
111.1488 +		} else { \
111.1489 +			reg[15].I &= 0xFFFFFFFE; \
111.1490 +			armNextPC  = reg[15].I; \
111.1491 +			reg[15].I += 2; \
111.1492 +		} \
111.1493 +	} else { \
111.1494 +		OPCODE \
111.1495 +	} \
111.1496 +} \
111.1497 +break; \
111.1498 +case BASE + 2: \
111.1499 +case BASE + 10: \
111.1500 +{ \
111.1501 +	/* OP Rd,Rb,Rm LSR # */ \
111.1502 +	int	 shift = (opcode >> 7) & 0x1F; \
111.1503 +	int	 dest  = (opcode >> 12) & 15; \
111.1504 +	bool C_OUT = C_FLAG; \
111.1505 +	u32	 value; \
111.1506 +	if (shift) { \
111.1507 +		LOGICAL_LSR_REG \
111.1508 +	} else { \
111.1509 +		value = 0; \
111.1510 +		C_OUT = (reg[opcode & 0x0F].I & 0x80000000) ? true : false; \
111.1511 +	} \
111.1512 +      \
111.1513 +	if (dest == 15) { \
111.1514 +		OPCODE2 \
111.1515 +		/* todo */ \
111.1516 +		if (opcode & 0x00100000) { \
111.1517 +			clockTicks++; \
111.1518 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1519 +		} \
111.1520 +		if (armState) { \
111.1521 +			reg[15].I &= 0xFFFFFFFC; \
111.1522 +			armNextPC  = reg[15].I; \
111.1523 +			reg[15].I += 4; \
111.1524 +		} else { \
111.1525 +			reg[15].I &= 0xFFFFFFFE; \
111.1526 +			armNextPC  = reg[15].I; \
111.1527 +			reg[15].I += 2; \
111.1528 +		} \
111.1529 +	} else { \
111.1530 +		OPCODE \
111.1531 +	} \
111.1532 +} \
111.1533 +break; \
111.1534 +case BASE + 4: \
111.1535 +case BASE + 12: \
111.1536 +{ \
111.1537 +	/* OP Rd,Rb,Rm ASR # */ \
111.1538 +	int	 shift = (opcode >> 7) & 0x1F; \
111.1539 +	int	 dest  = (opcode >> 12) & 15; \
111.1540 +	bool C_OUT = C_FLAG; \
111.1541 +	u32	 value; \
111.1542 +	if (shift) { \
111.1543 +		LOGICAL_ASR_REG \
111.1544 +	} else { \
111.1545 +		if (reg[opcode & 0x0F].I & 0x80000000) { \
111.1546 +			value = 0xFFFFFFFF; \
111.1547 +			C_OUT = true; \
111.1548 +		} else { \
111.1549 +			value = 0; \
111.1550 +			C_OUT = false; \
111.1551 +		}                   \
111.1552 +	} \
111.1553 +      \
111.1554 +	if (dest == 15) { \
111.1555 +		OPCODE2 \
111.1556 +		/* todo */ \
111.1557 +		if (opcode & 0x00100000) { \
111.1558 +			clockTicks++; \
111.1559 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1560 +		} \
111.1561 +		if (armState) { \
111.1562 +			reg[15].I &= 0xFFFFFFFC; \
111.1563 +			armNextPC  = reg[15].I; \
111.1564 +			reg[15].I += 4; \
111.1565 +		} else { \
111.1566 +			reg[15].I &= 0xFFFFFFFE; \
111.1567 +			armNextPC  = reg[15].I; \
111.1568 +			reg[15].I += 2; \
111.1569 +		} \
111.1570 +	} else { \
111.1571 +		OPCODE \
111.1572 +	} \
111.1573 +} \
111.1574 +break; \
111.1575 +case BASE + 6: \
111.1576 +case BASE + 14: \
111.1577 +{ \
111.1578 +	/* OP Rd,Rb,Rm ROR # */ \
111.1579 +	int	 shift = (opcode >> 7) & 0x1F; \
111.1580 +	int	 dest  = (opcode >> 12) & 15; \
111.1581 +	bool C_OUT = C_FLAG; \
111.1582 +	u32	 value; \
111.1583 +	if (shift) { \
111.1584 +		LOGICAL_ROR_REG \
111.1585 +	} else { \
111.1586 +		LOGICAL_RRX_REG \
111.1587 +	} \
111.1588 +	if (dest == 15) { \
111.1589 +		OPCODE2 \
111.1590 +		/* todo */ \
111.1591 +		if (opcode & 0x00100000) { \
111.1592 +			clockTicks++; \
111.1593 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1594 +		} \
111.1595 +		if (armState) { \
111.1596 +			reg[15].I &= 0xFFFFFFFC; \
111.1597 +			armNextPC  = reg[15].I; \
111.1598 +			reg[15].I += 4; \
111.1599 +		} else { \
111.1600 +			reg[15].I &= 0xFFFFFFFE; \
111.1601 +			armNextPC  = reg[15].I; \
111.1602 +			reg[15].I += 2; \
111.1603 +		} \
111.1604 +	} else { \
111.1605 +		OPCODE \
111.1606 +	} \
111.1607 +} \
111.1608 +break; \
111.1609 +case BASE + 1: \
111.1610 +{ \
111.1611 +	/* OP Rd,Rb,Rm LSL Rs */ \
111.1612 +	clockTicks++; \
111.1613 +	int	 shift = reg[(opcode >> 8) & 15].B.B0; \
111.1614 +	int	 dest  = (opcode >> 12) & 15; \
111.1615 +	bool C_OUT = C_FLAG; \
111.1616 +	u32	 value; \
111.1617 +	if (shift) { \
111.1618 +		if (shift == 32) { \
111.1619 +			value = 0; \
111.1620 +			C_OUT = (reg[opcode & 0x0F].I & 1 ? true : false); \
111.1621 +		} else if (shift < 32) { \
111.1622 +			LOGICAL_LSL_REG \
111.1623 +		} else { \
111.1624 +			value = 0; \
111.1625 +			C_OUT = false; \
111.1626 +		} \
111.1627 +	} else { \
111.1628 +		value = reg[opcode & 0x0F].I; \
111.1629 +	} \
111.1630 +	if (dest == 15) { \
111.1631 +		OPCODE2 \
111.1632 +		/* todo */ \
111.1633 +		if (opcode & 0x00100000) { \
111.1634 +			clockTicks++; \
111.1635 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1636 +		} \
111.1637 +		if (armState) { \
111.1638 +			reg[15].I &= 0xFFFFFFFC; \
111.1639 +			armNextPC  = reg[15].I; \
111.1640 +			reg[15].I += 4; \
111.1641 +		} else { \
111.1642 +			reg[15].I &= 0xFFFFFFFE; \
111.1643 +			armNextPC  = reg[15].I; \
111.1644 +			reg[15].I += 2; \
111.1645 +		} \
111.1646 +	} else { \
111.1647 +		OPCODE \
111.1648 +	} \
111.1649 +} \
111.1650 +break; \
111.1651 +case BASE + 3: \
111.1652 +{ \
111.1653 +	/* OP Rd,Rb,Rm LSR Rs */ \
111.1654 +	clockTicks++; \
111.1655 +	int	 shift = reg[(opcode >> 8) & 15].B.B0; \
111.1656 +	int	 dest  = (opcode >> 12) & 15; \
111.1657 +	bool C_OUT = C_FLAG; \
111.1658 +	u32	 value; \
111.1659 +	if (shift) { \
111.1660 +		if (shift == 32) { \
111.1661 +			value = 0; \
111.1662 +			C_OUT = (reg[opcode & 0x0F].I & 0x80000000 ? true : false); \
111.1663 +		} else if (shift < 32) { \
111.1664 +			LOGICAL_LSR_REG \
111.1665 +		} else { \
111.1666 +			value = 0; \
111.1667 +			C_OUT = false; \
111.1668 +		} \
111.1669 +	} else { \
111.1670 +		value = reg[opcode & 0x0F].I; \
111.1671 +	} \
111.1672 +	if (dest == 15) { \
111.1673 +		OPCODE2 \
111.1674 +		/* todo */ \
111.1675 +		if (opcode & 0x00100000) { \
111.1676 +			clockTicks++; \
111.1677 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1678 +		} \
111.1679 +		if (armState) { \
111.1680 +			reg[15].I &= 0xFFFFFFFC; \
111.1681 +			armNextPC  = reg[15].I; \
111.1682 +			reg[15].I += 4; \
111.1683 +		} else { \
111.1684 +			reg[15].I &= 0xFFFFFFFE; \
111.1685 +			armNextPC  = reg[15].I; \
111.1686 +			reg[15].I += 2; \
111.1687 +		} \
111.1688 +	} else { \
111.1689 +		OPCODE \
111.1690 +	} \
111.1691 +} \
111.1692 +break; \
111.1693 +case BASE + 5: \
111.1694 +{ \
111.1695 +	/* OP Rd,Rb,Rm ASR Rs */ \
111.1696 +	clockTicks++; \
111.1697 +	int	 shift = reg[(opcode >> 8) & 15].B.B0; \
111.1698 +	int	 dest  = (opcode >> 12) & 15; \
111.1699 +	bool C_OUT = C_FLAG; \
111.1700 +	u32	 value; \
111.1701 +	if (shift < 32) { \
111.1702 +		if (shift) { \
111.1703 +			LOGICAL_ASR_REG \
111.1704 +		} else { \
111.1705 +			value = reg[opcode & 0x0F].I; \
111.1706 +		} \
111.1707 +	} else { \
111.1708 +		if (reg[opcode & 0x0F].I & 0x80000000) { \
111.1709 +			value = 0xFFFFFFFF; \
111.1710 +			C_OUT = true; \
111.1711 +		} else { \
111.1712 +			value = 0; \
111.1713 +			C_OUT = false; \
111.1714 +		} \
111.1715 +	} \
111.1716 +	if (dest == 15) { \
111.1717 +		OPCODE2 \
111.1718 +		/* todo */ \
111.1719 +		if (opcode & 0x00100000) { \
111.1720 +			clockTicks++; \
111.1721 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1722 +		} \
111.1723 +		if (armState) { \
111.1724 +			reg[15].I &= 0xFFFFFFFC; \
111.1725 +			armNextPC  = reg[15].I; \
111.1726 +			reg[15].I += 4; \
111.1727 +		} else { \
111.1728 +			reg[15].I &= 0xFFFFFFFE; \
111.1729 +			armNextPC  = reg[15].I; \
111.1730 +			reg[15].I += 2; \
111.1731 +		} \
111.1732 +	} else { \
111.1733 +		OPCODE \
111.1734 +	} \
111.1735 +} \
111.1736 +break; \
111.1737 +case BASE + 7: \
111.1738 +{ \
111.1739 +	/* OP Rd,Rb,Rm ROR Rs */ \
111.1740 +	clockTicks++; \
111.1741 +	int	 shift = reg[(opcode >> 8) & 15].B.B0; \
111.1742 +	int	 dest  = (opcode >> 12) & 15; \
111.1743 +	bool C_OUT = C_FLAG; \
111.1744 +	u32	 value; \
111.1745 +	if (shift) { \
111.1746 +		shift &= 0x1f; \
111.1747 +		if (shift) { \
111.1748 +			LOGICAL_ROR_REG \
111.1749 +		} else { \
111.1750 +			value = reg[opcode & 0x0F].I; \
111.1751 +			C_OUT = (value & 0x80000000 ? true : false); \
111.1752 +		} \
111.1753 +	} else { \
111.1754 +		value = reg[opcode & 0x0F].I; \
111.1755 +		C_OUT = (value & 0x80000000 ? true : false); \
111.1756 +	} \
111.1757 +	if (dest == 15) { \
111.1758 +		OPCODE2 \
111.1759 +		/* todo */ \
111.1760 +		if (opcode & 0x00100000) { \
111.1761 +			clockTicks++; \
111.1762 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1763 +		} \
111.1764 +		if (armState) { \
111.1765 +			reg[15].I &= 0xFFFFFFFC; \
111.1766 +			armNextPC  = reg[15].I; \
111.1767 +			reg[15].I += 4; \
111.1768 +		} else { \
111.1769 +			reg[15].I &= 0xFFFFFFFE; \
111.1770 +			armNextPC  = reg[15].I; \
111.1771 +			reg[15].I += 2; \
111.1772 +		} \
111.1773 +	} else { \
111.1774 +		OPCODE \
111.1775 +	} \
111.1776 +} \
111.1777 +break; \
111.1778 +case BASE + 0x200: \
111.1779 +case BASE + 0x201: \
111.1780 +case BASE + 0x202: \
111.1781 +case BASE + 0x203: \
111.1782 +case BASE + 0x204: \
111.1783 +case BASE + 0x205: \
111.1784 +case BASE + 0x206: \
111.1785 +case BASE + 0x207: \
111.1786 +case BASE + 0x208: \
111.1787 +case BASE + 0x209: \
111.1788 +case BASE + 0x20a: \
111.1789 +case BASE + 0x20b: \
111.1790 +case BASE + 0x20c: \
111.1791 +case BASE + 0x20d: \
111.1792 +case BASE + 0x20e: \
111.1793 +case BASE + 0x20f: \
111.1794 +{ \
111.1795 +	int	 shift = (opcode & 0xF00) >> 7; \
111.1796 +	int	 dest  = (opcode >> 12) & 0x0F; \
111.1797 +	bool C_OUT = C_FLAG; \
111.1798 +	u32	 value; \
111.1799 +	if (shift) { \
111.1800 +		LOGICAL_ROR_IMM \
111.1801 +	} else { \
111.1802 +		value = opcode & 0xff; \
111.1803 +	} \
111.1804 +	if (dest == 15) { \
111.1805 +		OPCODE2 \
111.1806 +		/* todo */ \
111.1807 +		if (opcode & 0x00100000) { \
111.1808 +			clockTicks++; \
111.1809 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1810 +		} \
111.1811 +		if (armState) { \
111.1812 +			reg[15].I &= 0xFFFFFFFC; \
111.1813 +			armNextPC  = reg[15].I; \
111.1814 +			reg[15].I += 4; \
111.1815 +		} else { \
111.1816 +			reg[15].I &= 0xFFFFFFFE; \
111.1817 +			armNextPC  = reg[15].I; \
111.1818 +			reg[15].I += 2; \
111.1819 +		} \
111.1820 +	} else { \
111.1821 +		OPCODE \
111.1822 +	} \
111.1823 +} \
111.1824 +break;
111.1825 +
111.1826 +#define ARITHMETIC_DATA_OPCODE(OPCODE, OPCODE2, BASE) \
111.1827 +case BASE: \
111.1828 +case BASE + 8: \
111.1829 +{ \
111.1830 +	/* OP Rd,Rb,Rm LSL # */ \
111.1831 +	int base  = (opcode >> 16) & 0x0F; \
111.1832 +	int shift = (opcode >> 7) & 0x1F; \
111.1833 +	int dest  = (opcode >> 12) & 15; \
111.1834 +	u32 value; \
111.1835 +	if (shift) { \
111.1836 +		ARITHMETIC_LSL_REG \
111.1837 +	} else { \
111.1838 +		value = reg[opcode & 0x0F].I; \
111.1839 +	} \
111.1840 +	if (dest == 15) { \
111.1841 +		OPCODE2 \
111.1842 +		/* todo */ \
111.1843 +		if (opcode & 0x00100000) { \
111.1844 +			clockTicks++; \
111.1845 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1846 +		} \
111.1847 +		if (armState) { \
111.1848 +			reg[15].I &= 0xFFFFFFFC; \
111.1849 +			armNextPC  = reg[15].I; \
111.1850 +			reg[15].I += 4; \
111.1851 +		} else { \
111.1852 +			reg[15].I &= 0xFFFFFFFE; \
111.1853 +			armNextPC  = reg[15].I; \
111.1854 +			reg[15].I += 2; \
111.1855 +		} \
111.1856 +	} else { \
111.1857 +		OPCODE \
111.1858 +	} \
111.1859 +} \
111.1860 +break; \
111.1861 +case BASE + 2: \
111.1862 +case BASE + 10: \
111.1863 +{ \
111.1864 +	/* OP Rd,Rb,Rm LSR # */ \
111.1865 +	int base  = (opcode >> 16) & 0x0F; \
111.1866 +	int shift = (opcode >> 7) & 0x1F; \
111.1867 +	int dest  = (opcode >> 12) & 15; \
111.1868 +	u32 value; \
111.1869 +	if (shift) { \
111.1870 +		ARITHMETIC_LSR_REG \
111.1871 +	} else { \
111.1872 +		value = 0; \
111.1873 +	} \
111.1874 +	if (dest == 15) { \
111.1875 +		OPCODE2 \
111.1876 +		/* todo */ \
111.1877 +		if (opcode & 0x00100000) { \
111.1878 +			clockTicks++; \
111.1879 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1880 +		} \
111.1881 +		if (armState) { \
111.1882 +			reg[15].I &= 0xFFFFFFFC; \
111.1883 +			armNextPC  = reg[15].I; \
111.1884 +			reg[15].I += 4; \
111.1885 +		} else { \
111.1886 +			reg[15].I &= 0xFFFFFFFE; \
111.1887 +			armNextPC  = reg[15].I; \
111.1888 +			reg[15].I += 2; \
111.1889 +		} \
111.1890 +	} else { \
111.1891 +		OPCODE \
111.1892 +	} \
111.1893 +} \
111.1894 +break; \
111.1895 +case BASE + 4: \
111.1896 +case BASE + 12: \
111.1897 +{ \
111.1898 +	/* OP Rd,Rb,Rm ASR # */ \
111.1899 +	int base  = (opcode >> 16) & 0x0F; \
111.1900 +	int shift = (opcode >> 7) & 0x1F; \
111.1901 +	int dest  = (opcode >> 12) & 15; \
111.1902 +	u32 value; \
111.1903 +	if (shift) { \
111.1904 +		ARITHMETIC_ASR_REG \
111.1905 +	} else { \
111.1906 +		if (reg[opcode & 0x0F].I & 0x80000000) { \
111.1907 +			value = 0xFFFFFFFF; \
111.1908 +		} else value = 0; \
111.1909 +	} \
111.1910 +	if (dest == 15) { \
111.1911 +		OPCODE2 \
111.1912 +		/* todo */ \
111.1913 +		if (opcode & 0x00100000) { \
111.1914 +			clockTicks++; \
111.1915 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1916 +		} \
111.1917 +		if (armState) { \
111.1918 +			reg[15].I &= 0xFFFFFFFC; \
111.1919 +			armNextPC  = reg[15].I; \
111.1920 +			reg[15].I += 4; \
111.1921 +		} else { \
111.1922 +			reg[15].I &= 0xFFFFFFFE; \
111.1923 +			armNextPC  = reg[15].I; \
111.1924 +			reg[15].I += 2; \
111.1925 +		} \
111.1926 +	} else { \
111.1927 +		OPCODE \
111.1928 +	} \
111.1929 +} \
111.1930 +break; \
111.1931 +case BASE + 6: \
111.1932 +case BASE + 14: \
111.1933 +{ \
111.1934 +	/* OP Rd,Rb,Rm ROR # */ \
111.1935 +	int base  = (opcode >> 16) & 0x0F; \
111.1936 +	int shift = (opcode >> 7) & 0x1F; \
111.1937 +	int dest  = (opcode >> 12) & 15; \
111.1938 +	u32 value; \
111.1939 +	if (shift) { \
111.1940 +		ARITHMETIC_ROR_REG \
111.1941 +	} else { \
111.1942 +		ARITHMETIC_RRX_REG \
111.1943 +	} \
111.1944 +	if (dest == 15) { \
111.1945 +		OPCODE2 \
111.1946 +		/* todo */ \
111.1947 +		if (opcode & 0x00100000) { \
111.1948 +			clockTicks++; \
111.1949 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1950 +		} \
111.1951 +		if (armState) { \
111.1952 +			reg[15].I &= 0xFFFFFFFC; \
111.1953 +			armNextPC  = reg[15].I; \
111.1954 +			reg[15].I += 4; \
111.1955 +		} else { \
111.1956 +			reg[15].I &= 0xFFFFFFFE; \
111.1957 +			armNextPC  = reg[15].I; \
111.1958 +			reg[15].I += 2; \
111.1959 +		} \
111.1960 +	} else { \
111.1961 +		OPCODE \
111.1962 +	} \
111.1963 +} \
111.1964 +break; \
111.1965 +case BASE + 1: \
111.1966 +{ \
111.1967 +	/* OP Rd,Rb,Rm LSL Rs */ \
111.1968 +	clockTicks++; \
111.1969 +	int base  = (opcode >> 16) & 0x0F; \
111.1970 +	int shift = reg[(opcode >> 8) & 15].B.B0; \
111.1971 +	int dest  = (opcode >> 12) & 15; \
111.1972 +	u32 value; \
111.1973 +	if (shift) { \
111.1974 +		if (shift == 32) { \
111.1975 +			value = 0; \
111.1976 +		} else if (shift < 32) { \
111.1977 +			ARITHMETIC_LSL_REG \
111.1978 +		} else value = 0; \
111.1979 +	} else { \
111.1980 +		value = reg[opcode & 0x0F].I; \
111.1981 +	} \
111.1982 +	if (dest == 15) { \
111.1983 +		OPCODE2 \
111.1984 +		/* todo */ \
111.1985 +		if (opcode & 0x00100000) { \
111.1986 +			clockTicks++; \
111.1987 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.1988 +		} \
111.1989 +		if (armState) { \
111.1990 +			reg[15].I &= 0xFFFFFFFC; \
111.1991 +			armNextPC  = reg[15].I; \
111.1992 +			reg[15].I += 4; \
111.1993 +		} else { \
111.1994 +			reg[15].I &= 0xFFFFFFFE; \
111.1995 +			armNextPC  = reg[15].I; \
111.1996 +			reg[15].I += 2; \
111.1997 +		} \
111.1998 +	} else { \
111.1999 +		OPCODE \
111.2000 +	} \
111.2001 +} \
111.2002 +break; \
111.2003 +case BASE + 3: \
111.2004 +{ \
111.2005 +	/* OP Rd,Rb,Rm LSR Rs */ \
111.2006 +	clockTicks++; \
111.2007 +	int base  = (opcode >> 16) & 0x0F; \
111.2008 +	int shift = reg[(opcode >> 8) & 15].B.B0; \
111.2009 +	int dest  = (opcode >> 12) & 15; \
111.2010 +	u32 value; \
111.2011 +	if (shift) { \
111.2012 +		if (shift == 32) { \
111.2013 +			value = 0; \
111.2014 +		} else if (shift < 32) { \
111.2015 +			ARITHMETIC_LSR_REG \
111.2016 +		} else value = 0; \
111.2017 +	} else { \
111.2018 +		value = reg[opcode & 0x0F].I; \
111.2019 +	} \
111.2020 +	if (dest == 15) { \
111.2021 +		OPCODE2 \
111.2022 +		/* todo */ \
111.2023 +		if (opcode & 0x00100000) { \
111.2024 +			clockTicks++; \
111.2025 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.2026 +		} \
111.2027 +		if (armState) { \
111.2028 +			reg[15].I &= 0xFFFFFFFC; \
111.2029 +			armNextPC  = reg[15].I; \
111.2030 +			reg[15].I += 4; \
111.2031 +		} else { \
111.2032 +			reg[15].I &= 0xFFFFFFFE; \
111.2033 +			armNextPC  = reg[15].I; \
111.2034 +			reg[15].I += 2; \
111.2035 +		} \
111.2036 +	} else { \
111.2037 +		OPCODE \
111.2038 +	} \
111.2039 +} \
111.2040 +break; \
111.2041 +case BASE + 5: \
111.2042 +{ \
111.2043 +	/* OP Rd,Rb,Rm ASR Rs */ \
111.2044 +	clockTicks++; \
111.2045 +	int base  = (opcode >> 16) & 0x0F; \
111.2046 +	int shift = reg[(opcode >> 8) & 15].B.B0; \
111.2047 +	int dest  = (opcode >> 12) & 15; \
111.2048 +	u32 value; \
111.2049 +	if (shift < 32) { \
111.2050 +		if (shift) { \
111.2051 +			ARITHMETIC_ASR_REG \
111.2052 +		} else { \
111.2053 +			value = reg[opcode & 0x0F].I; \
111.2054 +		} \
111.2055 +	} else { \
111.2056 +		if (reg[opcode & 0x0F].I & 0x80000000) { \
111.2057 +			value = 0xFFFFFFFF; \
111.2058 +		} else value = 0; \
111.2059 +	} \
111.2060 +	if (dest == 15) { \
111.2061 +		OPCODE2 \
111.2062 +		/* todo */ \
111.2063 +		if (opcode & 0x00100000) { \
111.2064 +			clockTicks++; \
111.2065 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.2066 +		} \
111.2067 +		if (armState) { \
111.2068 +			reg[15].I &= 0xFFFFFFFC; \
111.2069 +			armNextPC  = reg[15].I; \
111.2070 +			reg[15].I += 4; \
111.2071 +		} else { \
111.2072 +			reg[15].I &= 0xFFFFFFFE; \
111.2073 +			armNextPC  = reg[15].I; \
111.2074 +			reg[15].I += 2; \
111.2075 +		} \
111.2076 +	} else { \
111.2077 +		OPCODE \
111.2078 +	} \
111.2079 +} \
111.2080 +break; \
111.2081 +case BASE + 7: \
111.2082 +{ \
111.2083 +	/* OP Rd,Rb,Rm ROR Rs */ \
111.2084 +	clockTicks++; \
111.2085 +	int base  = (opcode >> 16) & 0x0F; \
111.2086 +	int shift = reg[(opcode >> 8) & 15].B.B0; \
111.2087 +	int dest  = (opcode >> 12) & 15; \
111.2088 +	u32 value; \
111.2089 +	if (shift) { \
111.2090 +		shift &= 0x1f; \
111.2091 +		if (shift) { \
111.2092 +			ARITHMETIC_ROR_REG \
111.2093 +		} else { \
111.2094 +			value = reg[opcode & 0x0F].I; \
111.2095 +		} \
111.2096 +	} else { \
111.2097 +		value = reg[opcode & 0x0F].I; \
111.2098 +	} \
111.2099 +	if (dest == 15) { \
111.2100 +		OPCODE2 \
111.2101 +		/* todo */ \
111.2102 +		if (opcode & 0x00100000) { \
111.2103 +			clockTicks++; \
111.2104 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.2105 +		} \
111.2106 +		if (armState) { \
111.2107 +			reg[15].I &= 0xFFFFFFFC; \
111.2108 +			armNextPC  = reg[15].I; \
111.2109 +			reg[15].I += 4; \
111.2110 +		} else { \
111.2111 +			reg[15].I &= 0xFFFFFFFE; \
111.2112 +			armNextPC  = reg[15].I; \
111.2113 +			reg[15].I += 2; \
111.2114 +		} \
111.2115 +	} else { \
111.2116 +		OPCODE \
111.2117 +	} \
111.2118 +} \
111.2119 +break; \
111.2120 +case BASE + 0x200: \
111.2121 +case BASE + 0x201: \
111.2122 +case BASE + 0x202: \
111.2123 +case BASE + 0x203: \
111.2124 +case BASE + 0x204: \
111.2125 +case BASE + 0x205: \
111.2126 +case BASE + 0x206: \
111.2127 +case BASE + 0x207: \
111.2128 +case BASE + 0x208: \
111.2129 +case BASE + 0x209: \
111.2130 +case BASE + 0x20a: \
111.2131 +case BASE + 0x20b: \
111.2132 +case BASE + 0x20c: \
111.2133 +case BASE + 0x20d: \
111.2134 +case BASE + 0x20e: \
111.2135 +case BASE + 0x20f: \
111.2136 +{ \
111.2137 +	int shift = (opcode & 0xF00) >> 7; \
111.2138 +	int base  = (opcode >> 16) & 0x0F; \
111.2139 +	int dest  = (opcode >> 12) & 0x0F; \
111.2140 +	u32 value; \
111.2141 +	{ \
111.2142 +		ARITHMETIC_ROR_IMM \
111.2143 +	} \
111.2144 +	if (dest == 15) { \
111.2145 +		OPCODE2 \
111.2146 +		/* todo */ \
111.2147 +		if (opcode & 0x00100000) { \
111.2148 +			clockTicks++; \
111.2149 +			CPUSwitchMode(reg[17].I & 0x1f, false); \
111.2150 +		} \
111.2151 +		if (armState) { \
111.2152 +			reg[15].I &= 0xFFFFFFFC; \
111.2153 +			armNextPC  = reg[15].I; \
111.2154 +			reg[15].I += 4; \
111.2155 +		} else { \
111.2156 +			reg[15].I &= 0xFFFFFFFE; \
111.2157 +			armNextPC  = reg[15].I; \
111.2158 +			reg[15].I += 2; \
111.2159 +		} \
111.2160 +	} else { \
111.2161 +		OPCODE \
111.2162 +	} \
111.2163 +} \
111.2164 +break;
111.2165 +
111.2166 +u32 opcode = CPUReadMemoryQuick(armNextPC);
111.2167 +
111.2168 +clockTicks = memoryWaitFetch32[(armNextPC >> 24) & 15];
111.2169 +
111.2170 +#ifndef FINAL_VERSION
111.2171 +if (armNextPC == stop)
111.2172 +{
111.2173 +	armNextPC++;
111.2174 +}
111.2175 +#endif
111.2176 +
111.2177 +armNextPC  = reg[15].I;
111.2178 +reg[15].I += 4;
111.2179 +int cond = opcode >> 28;
111.2180 +// suggested optimization for frequent cases
111.2181 +bool cond_res;
111.2182 +if (cond == 0x0e)
111.2183 +{
111.2184 +	cond_res = true;
111.2185 +}
111.2186 +else
111.2187 +{
111.2188 +	switch (cond)
111.2189 +	{
111.2190 +	case 0x00: // EQ
111.2191 +		cond_res = Z_FLAG;
111.2192 +		break;
111.2193 +	case 0x01: // NE
111.2194 +		cond_res = !Z_FLAG;
111.2195 +		break;
111.2196 +	case 0x02: // CS
111.2197 +		cond_res = C_FLAG;
111.2198 +		break;
111.2199 +	case 0x03: // CC
111.2200 +		cond_res = !C_FLAG;
111.2201 +		break;
111.2202 +	case 0x04: // MI
111.2203 +		cond_res = N_FLAG;
111.2204 +		break;
111.2205 +	case 0x05: // PL
111.2206 +		cond_res = !N_FLAG;
111.2207 +		break;
111.2208 +	case 0x06: // VS
111.2209 +		cond_res = V_FLAG;
111.2210 +		break;
111.2211 +	case 0x07: // VC
111.2212 +		cond_res = !V_FLAG;
111.2213 +		break;
111.2214 +	case 0x08: // HI
111.2215 +		cond_res = C_FLAG && !Z_FLAG;
111.2216 +		break;
111.2217 +	case 0x09: // LS
111.2218 +		cond_res = !C_FLAG || Z_FLAG;
111.2219 +		break;
111.2220 +	case 0x0A: // GE
111.2221 +		cond_res = N_FLAG == V_FLAG;
111.2222 +		break;
111.2223 +	case 0x0B: // LT
111.2224 +		cond_res = N_FLAG != V_FLAG;
111.2225 +		break;
111.2226 +	case 0x0C: // GT
111.2227 +		cond_res = !Z_FLAG && (N_FLAG == V_FLAG);
111.2228 +		break;
111.2229 +	case 0x0D: // LE
111.2230 +		cond_res = Z_FLAG || (N_FLAG != V_FLAG);
111.2231 +		break;
111.2232 +	case 0x0E:
111.2233 +		cond_res = true;
111.2234 +		break;
111.2235 +	case 0x0F:
111.2236 +	default:
111.2237 +		// ???
111.2238 +		cond_res = false;
111.2239 +		break;
111.2240 +	}
111.2241 +}
111.2242 +
111.2243 +if (cond_res)
111.2244 +{
111.2245 +	switch (((opcode >> 16) & 0xFF0) | ((opcode >> 4) & 0x0F))
111.2246 +	{
111.2247 +		LOGICAL_DATA_OPCODE_WITHOUT_base(OP_AND,  OP_AND, 0x000);
111.2248 +		LOGICAL_DATA_OPCODE_WITHOUT_base(OP_ANDS, OP_AND, 0x010);
111.2249 +	case 0x009:
111.2250 +	{
111.2251 +		// MUL Rd, Rm, Rs
111.2252 +		int dest = (opcode >> 16) & 0x0F;
111.2253 +		int mult = (opcode & 0x0F);
111.2254 +		u32 rs	 = reg[(opcode >> 8) & 0x0F].I;
111.2255 +		reg[dest].I = reg[mult].I * rs;
111.2256 +		if (((s32)rs) < 0)
111.2257 +			rs = ~rs;
111.2258 +		if ((rs & 0xFFFFFF00) == 0)
111.2259 +			clockTicks += 2;
111.2260 +		else if ((rs & 0xFFFF0000) == 0)
111.2261 +			clockTicks += 3;
111.2262 +		else if ((rs & 0xFF000000) == 0)
111.2263 +			clockTicks += 4;
111.2264 +		else
111.2265 +			clockTicks += 5;
111.2266 +	}
111.2267 +	break;
111.2268 +	case 0x019:
111.2269 +	{
111.2270 +		// MULS Rd, Rm, Rs
111.2271 +		int dest = (opcode >> 16) & 0x0F;
111.2272 +		int mult = (opcode & 0x0F);
111.2273 +		u32 rs	 = reg[(opcode >> 8) & 0x0F].I;
111.2274 +		reg[dest].I = reg[mult].I * rs;
111.2275 +		N_FLAG		= (reg[dest].I & 0x80000000) ? true : false;
111.2276 +		Z_FLAG		= (reg[dest].I) ? false : true;
111.2277 +		if (((s32)rs) < 0)
111.2278 +			rs = ~rs;
111.2279 +		if ((rs & 0xFFFFFF00) == 0)
111.2280 +			clockTicks += 2;
111.2281 +		else if ((rs & 0xFFFF0000) == 0)
111.2282 +			clockTicks += 3;
111.2283 +		else if ((rs & 0xFF000000) == 0)
111.2284 +			clockTicks += 4;
111.2285 +		else
111.2286 +			clockTicks += 5;
111.2287 +	}
111.2288 +	break;
111.2289 +	case 0x00b:
111.2290 +	case 0x02b:
111.2291 +	{
111.2292 +		// STRH Rd, [Rn], -Rm
111.2293 +		int base	= (opcode >> 16) & 0x0F;
111.2294 +		int dest	= (opcode >> 12) & 0x0F;
111.2295 +		u32 address = reg[base].I;
111.2296 +		int offset	= reg[opcode & 0x0F].I;
111.2297 +		clockTicks += 4 + CPUUpdateTicksAccess16(address);
111.2298 +		CPUWriteHalfWord(address, reg[dest].W.W0);
111.2299 +		address	   -= offset;
111.2300 +		reg[base].I = address;
111.2301 +	}
111.2302 +	break;
111.2303 +	case 0x04b:
111.2304 +	case 0x06b:
111.2305 +	{
111.2306 +		// STRH Rd, [Rn], #-offset
111.2307 +		int base	= (opcode >> 16) & 0x0F;
111.2308 +		int dest	= (opcode >> 12) & 0x0F;
111.2309 +		u32 address = reg[base].I;
111.2310 +		int offset	= (opcode & 0x0F) | ((opcode >> 4) & 0xF0);
111.2311 +		clockTicks += 4 + CPUUpdateTicksAccess16(address);
111.2312 +		CPUWriteHalfWord(address, reg[dest].W.W0);
111.2313 +		address	   -= offset;
111.2314 +		reg[base].I = address;
111.2315 +	}
111.2316 +	break;
111.2317 +	case 0x08b:
111.2318 +	case 0x0ab:
111.2319 +	{
111.2320 +		// STRH Rd, [Rn], Rm
111.2321 +		int base	= (opcode >> 16) & 0x0F;
111.2322 +		int dest	= (opcode >> 12) & 0x0F;
111.2323 +		u32 address = reg[base].I;
111.2324 +		int offset	= reg[opcode & 0x0F].I;
111.2325 +		clockTicks += 4 + CPUUpdateTicksAccess16(address);
111.2326 +		CPUWriteHalfWord(address, reg[dest].W.W0);
111.2327 +		address	   += offset;
111.2328 +		reg[base].I = address;
111.2329 +	}
111.2330 +	break;
111.2331 +	case 0x0cb:
111.2332 +	case 0x0eb:
111.2333 +	{
111.2334 +		// STRH Rd, [Rn], #offset
111.2335 +		int base	= (opcode >> 16) & 0x0F;
111.2336 +		int dest	= (opcode >> 12) & 0x0F;
111.2337 +		u32 address = reg[base].I;
111.2338 +		int offset	= (opcode & 0x0F) | ((opcode >> 4) & 0xF0);
111.2339 +		clockTicks += 4 + CPUUpdateTicksAccess16(address);
111.2340 +		CPUWriteHalfWord(address, reg[dest].W.W0);
111.2341 +		address	   += offset;
111.2342 +		reg[base].I = address;
111.2343 +	}
111.2344 +	break;
111.2345 +	case 0x10b:
111.2346 +	{
111.2347 +		// STRH Rd, [Rn, -Rm]
111.2348 +		int base	= (opcode >> 16) & 0x0F;
111.2349 +		int dest	= (opcode >> 12) & 0x0F;
111.2350 +		u32 address = reg[base].I - reg[opcode & 0x0F].I;
111.2351 +		clockTicks += 4 + CPUUpdateTicksAccess16(address);
111.2352 +		CPUWriteHalfWord(address, reg[dest].W.W0);
111.2353 +	}
111.2354 +	break;
111.2355 +	case 0x12b:
111.2356 +	{
111.2357 +		// STRH Rd, [Rn, -Rm]!
111.2358 +		int base	= (opcode >> 16) & 0x0F;
111.2359 +		int dest	= (opcode >> 12) & 0x0F;
111.2360 +		u32 address = reg[base].I - reg[opcode & 0x0F].I;
111.2361 +		clockTicks += 4 + CPUUpdateTicksAccess16(address);
111.2362 +		CPUWriteHalfWord(address, reg[dest].W.W0);
111.2363 +		reg[base].I = address;
111.2364 +	}
111.2365 +	break;
111.2366 +	case 0x14b:
111.2367 +	{
111.2368 +		// STRH Rd, [Rn, -#offset]
111.2369 +		int base	= (opcode >> 16) & 0x0F;
111.2370 +		int dest	= (opcode >> 12) & 0x0F;
111.2371 +		u32 address = reg[base].I - ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2372 +		clockTicks += 4 + CPUUpdateTicksAccess16(address);
111.2373 +		CPUWriteHalfWord(address, reg[dest].W.W0);
111.2374 +	}
111.2375 +	break;
111.2376 +	case 0x16b:
111.2377 +	{
111.2378 +		// STRH Rd, [Rn, -#offset]!
111.2379 +		int base	= (opcode >> 16) & 0x0F;
111.2380 +		int dest	= (opcode >> 12) & 0x0F;
111.2381 +		u32 address = reg[base].I - ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2382 +		clockTicks += 4 + CPUUpdateTicksAccess16(address);
111.2383 +		CPUWriteHalfWord(address, reg[dest].W.W0);
111.2384 +		reg[base].I = address;
111.2385 +	}
111.2386 +	break;
111.2387 +	case 0x18b:
111.2388 +	{
111.2389 +		// STRH Rd, [Rn, Rm]
111.2390 +		int base	= (opcode >> 16) & 0x0F;
111.2391 +		int dest	= (opcode >> 12) & 0x0F;
111.2392 +		u32 address = reg[base].I + reg[opcode & 0x0F].I;
111.2393 +		clockTicks += 4 + CPUUpdateTicksAccess16(address);
111.2394 +		CPUWriteHalfWord(address, reg[dest].W.W0);
111.2395 +	}
111.2396 +	break;
111.2397 +	case 0x1ab:
111.2398 +	{
111.2399 +		// STRH Rd, [Rn, Rm]!
111.2400 +		int base	= (opcode >> 16) & 0x0F;
111.2401 +		int dest	= (opcode >> 12) & 0x0F;
111.2402 +		u32 address = reg[base].I + reg[opcode & 0x0F].I;
111.2403 +		clockTicks += 4 + CPUUpdateTicksAccess16(address);
111.2404 +		CPUWriteHalfWord(address, reg[dest].W.W0);
111.2405 +		reg[base].I = address;
111.2406 +	}
111.2407 +	break;
111.2408 +	case 0x1cb:
111.2409 +	{
111.2410 +		// STRH Rd, [Rn, #offset]
111.2411 +		int base	= (opcode >> 16) & 0x0F;
111.2412 +		int dest	= (opcode >> 12) & 0x0F;
111.2413 +		u32 address = reg[base].I + ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2414 +		clockTicks += 4 + CPUUpdateTicksAccess16(address);
111.2415 +		CPUWriteHalfWord(address, reg[dest].W.W0);
111.2416 +	}
111.2417 +	break;
111.2418 +	case 0x1eb:
111.2419 +	{
111.2420 +		// STRH Rd, [Rn, #offset]!
111.2421 +		int base	= (opcode >> 16) & 0x0F;
111.2422 +		int dest	= (opcode >> 12) & 0x0F;
111.2423 +		u32 address = reg[base].I + ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2424 +		clockTicks += 4 + CPUUpdateTicksAccess16(address);
111.2425 +		CPUWriteHalfWord(address, reg[dest].W.W0);
111.2426 +		reg[base].I = address;
111.2427 +	}
111.2428 +	break;
111.2429 +	case 0x01b:
111.2430 +	case 0x03b:
111.2431 +	{
111.2432 +		// LDRH Rd, [Rn], -Rm
111.2433 +		int base	= (opcode >> 16) & 0x0F;
111.2434 +		int dest	= (opcode >> 12) & 0x0F;
111.2435 +		u32 address = reg[base].I;
111.2436 +		int offset	= reg[opcode & 0x0F].I;
111.2437 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2438 +		reg[dest].I = CPUReadHalfWord(address);
111.2439 +		if (dest != base)
111.2440 +		{
111.2441 +			address	   -= offset;
111.2442 +			reg[base].I = address;
111.2443 +		}
111.2444 +	}
111.2445 +	break;
111.2446 +	case 0x05b:
111.2447 +	case 0x07b:
111.2448 +	{
111.2449 +		// LDRH Rd, [Rn], #-offset
111.2450 +		int base	= (opcode >> 16) & 0x0F;
111.2451 +		int dest	= (opcode >> 12) & 0x0F;
111.2452 +		u32 address = reg[base].I;
111.2453 +		int offset	= (opcode & 0x0F) | ((opcode >> 4) & 0xF0);
111.2454 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2455 +		reg[dest].I = CPUReadHalfWord(address);
111.2456 +		if (dest != base)
111.2457 +		{
111.2458 +			address	   -= offset;
111.2459 +			reg[base].I = address;
111.2460 +		}
111.2461 +	}
111.2462 +	break;
111.2463 +	case 0x09b:
111.2464 +	case 0x0bb:
111.2465 +	{
111.2466 +		// LDRH Rd, [Rn], Rm
111.2467 +		int base	= (opcode >> 16) & 0x0F;
111.2468 +		int dest	= (opcode >> 12) & 0x0F;
111.2469 +		u32 address = reg[base].I;
111.2470 +		int offset	= reg[opcode & 0x0F].I;
111.2471 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2472 +		reg[dest].I = CPUReadHalfWord(address);
111.2473 +		if (dest != base)
111.2474 +		{
111.2475 +			address	   += offset;
111.2476 +			reg[base].I = address;
111.2477 +		}
111.2478 +	}
111.2479 +	break;
111.2480 +	case 0x0db:
111.2481 +	case 0x0fb:
111.2482 +	{
111.2483 +		// LDRH Rd, [Rn], #offset
111.2484 +		int base	= (opcode >> 16) & 0x0F;
111.2485 +		int dest	= (opcode >> 12) & 0x0F;
111.2486 +		u32 address = reg[base].I;
111.2487 +		int offset	= (opcode & 0x0F) | ((opcode >> 4) & 0xF0);
111.2488 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2489 +		reg[dest].I = CPUReadHalfWord(address);
111.2490 +		if (dest != base)
111.2491 +		{
111.2492 +			address	   += offset;
111.2493 +			reg[base].I = address;
111.2494 +		}
111.2495 +	}
111.2496 +	break;
111.2497 +	case 0x11b:
111.2498 +	{
111.2499 +		// LDRH Rd, [Rn, -Rm]
111.2500 +		int base	= (opcode >> 16) & 0x0F;
111.2501 +		int dest	= (opcode >> 12) & 0x0F;
111.2502 +		u32 address = reg[base].I - reg[opcode & 0x0F].I;
111.2503 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2504 +		reg[dest].I = CPUReadHalfWord(address);
111.2505 +	}
111.2506 +	break;
111.2507 +	case 0x13b:
111.2508 +	{
111.2509 +		// LDRH Rd, [Rn, -Rm]!
111.2510 +		int base	= (opcode >> 16) & 0x0F;
111.2511 +		int dest	= (opcode >> 12) & 0x0F;
111.2512 +		u32 address = reg[base].I - reg[opcode & 0x0F].I;
111.2513 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2514 +		reg[dest].I = CPUReadHalfWord(address);
111.2515 +		if (dest != base)
111.2516 +			reg[base].I = address;
111.2517 +	}
111.2518 +	break;
111.2519 +	case 0x15b:
111.2520 +	{
111.2521 +		// LDRH Rd, [Rn, -#offset]
111.2522 +		int base	= (opcode >> 16) & 0x0F;
111.2523 +		int dest	= (opcode >> 12) & 0x0F;
111.2524 +		u32 address = reg[base].I - ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2525 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2526 +		reg[dest].I = CPUReadHalfWord(address);
111.2527 +	}
111.2528 +	break;
111.2529 +	case 0x17b:
111.2530 +	{
111.2531 +		// LDRH Rd, [Rn, -#offset]!
111.2532 +		int base	= (opcode >> 16) & 0x0F;
111.2533 +		int dest	= (opcode >> 12) & 0x0F;
111.2534 +		u32 address = reg[base].I - ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2535 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2536 +		reg[dest].I = CPUReadHalfWord(address);
111.2537 +		if (dest != base)
111.2538 +			reg[base].I = address;
111.2539 +	}
111.2540 +	break;
111.2541 +	case 0x19b:
111.2542 +	{
111.2543 +		// LDRH Rd, [Rn, Rm]
111.2544 +		int base	= (opcode >> 16) & 0x0F;
111.2545 +		int dest	= (opcode >> 12) & 0x0F;
111.2546 +		u32 address = reg[base].I + reg[opcode & 0x0F].I;
111.2547 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2548 +		reg[dest].I = CPUReadHalfWord(address);
111.2549 +	}
111.2550 +	break;
111.2551 +	case 0x1bb:
111.2552 +	{
111.2553 +		// LDRH Rd, [Rn, Rm]!
111.2554 +		int base	= (opcode >> 16) & 0x0F;
111.2555 +		int dest	= (opcode >> 12) & 0x0F;
111.2556 +		u32 address = reg[base].I + reg[opcode & 0x0F].I;
111.2557 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2558 +		reg[dest].I = CPUReadHalfWord(address);
111.2559 +		if (dest != base)
111.2560 +			reg[base].I = address;
111.2561 +	}
111.2562 +	break;
111.2563 +	case 0x1db:
111.2564 +	{
111.2565 +		// LDRH Rd, [Rn, #offset]
111.2566 +		int base	= (opcode >> 16) & 0x0F;
111.2567 +		int dest	= (opcode >> 12) & 0x0F;
111.2568 +		u32 address = reg[base].I + ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2569 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2570 +		reg[dest].I = CPUReadHalfWord(address);
111.2571 +	}
111.2572 +	break;
111.2573 +	case 0x1fb:
111.2574 +	{
111.2575 +		// LDRH Rd, [Rn, #offset]!
111.2576 +		int base	= (opcode >> 16) & 0x0F;
111.2577 +		int dest	= (opcode >> 12) & 0x0F;
111.2578 +		u32 address = reg[base].I + ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2579 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2580 +		reg[dest].I = CPUReadHalfWord(address);
111.2581 +		if (dest != base)
111.2582 +			reg[base].I = address;
111.2583 +	}
111.2584 +	break;
111.2585 +	case 0x01d:
111.2586 +	case 0x03d:
111.2587 +	{
111.2588 +		// LDRSB Rd, [Rn], -Rm
111.2589 +		int base	= (opcode >> 16) & 0x0F;
111.2590 +		int dest	= (opcode >> 12) & 0x0F;
111.2591 +		u32 address = reg[base].I;
111.2592 +		int offset	= reg[opcode & 0x0F].I;
111.2593 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2594 +		reg[dest].I = (s8)CPUReadByte(address);
111.2595 +		if (dest != base)
111.2596 +		{
111.2597 +			address	   -= offset;
111.2598 +			reg[base].I = address;
111.2599 +		}
111.2600 +	}
111.2601 +	break;
111.2602 +	case 0x05d:
111.2603 +	case 0x07d:
111.2604 +	{
111.2605 +		// LDRSB Rd, [Rn], #-offset
111.2606 +		int base	= (opcode >> 16) & 0x0F;
111.2607 +		int dest	= (opcode >> 12) & 0x0F;
111.2608 +		u32 address = reg[base].I;
111.2609 +		int offset	= (opcode & 0x0F) | ((opcode >> 4) & 0xF0);
111.2610 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2611 +		reg[dest].I = (s8)CPUReadByte(address);
111.2612 +		if (dest != base)
111.2613 +		{
111.2614 +			address	   -= offset;
111.2615 +			reg[base].I = address;
111.2616 +		}
111.2617 +	}
111.2618 +	break;
111.2619 +	case 0x09d:
111.2620 +	case 0x0bd:
111.2621 +	{
111.2622 +		// LDRSB Rd, [Rn], Rm
111.2623 +		int base	= (opcode >> 16) & 0x0F;
111.2624 +		int dest	= (opcode >> 12) & 0x0F;
111.2625 +		u32 address = reg[base].I;
111.2626 +		int offset	= reg[opcode & 0x0F].I;
111.2627 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2628 +		reg[dest].I = (s8)CPUReadByte(address);
111.2629 +		if (dest != base)
111.2630 +		{
111.2631 +			address	   += offset;
111.2632 +			reg[base].I = address;
111.2633 +		}
111.2634 +	}
111.2635 +	break;
111.2636 +	case 0x0dd:
111.2637 +	case 0x0fd:
111.2638 +	{
111.2639 +		// LDRSB Rd, [Rn], #offset
111.2640 +		int base	= (opcode >> 16) & 0x0F;
111.2641 +		int dest	= (opcode >> 12) & 0x0F;
111.2642 +		u32 address = reg[base].I;
111.2643 +		int offset	= (opcode & 0x0F) | ((opcode >> 4) & 0xF0);
111.2644 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2645 +		reg[dest].I = (s8)CPUReadByte(address);
111.2646 +		if (dest != base)
111.2647 +		{
111.2648 +			address	   += offset;
111.2649 +			reg[base].I = address;
111.2650 +		}
111.2651 +	}
111.2652 +	break;
111.2653 +	case 0x11d:
111.2654 +	{
111.2655 +		// LDRSB Rd, [Rn, -Rm]
111.2656 +		int base	= (opcode >> 16) & 0x0F;
111.2657 +		int dest	= (opcode >> 12) & 0x0F;
111.2658 +		u32 address = reg[base].I - reg[opcode & 0x0F].I;
111.2659 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2660 +		reg[dest].I = (s8)CPUReadByte(address);
111.2661 +	}
111.2662 +	break;
111.2663 +	case 0x13d:
111.2664 +	{
111.2665 +		// LDRSB Rd, [Rn, -Rm]!
111.2666 +		int base	= (opcode >> 16) & 0x0F;
111.2667 +		int dest	= (opcode >> 12) & 0x0F;
111.2668 +		u32 address = reg[base].I - reg[opcode & 0x0F].I;
111.2669 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2670 +		reg[dest].I = (s8)CPUReadByte(address);
111.2671 +		if (dest != base)
111.2672 +			reg[base].I = address;
111.2673 +	}
111.2674 +	break;
111.2675 +	case 0x15d:
111.2676 +	{
111.2677 +		// LDRSB Rd, [Rn, -#offset]
111.2678 +		int base	= (opcode >> 16) & 0x0F;
111.2679 +		int dest	= (opcode >> 12) & 0x0F;
111.2680 +		u32 address = reg[base].I - ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2681 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2682 +		reg[dest].I = (s8)CPUReadByte(address);
111.2683 +	}
111.2684 +	break;
111.2685 +	case 0x17d:
111.2686 +	{
111.2687 +		// LDRSB Rd, [Rn, -#offset]!
111.2688 +		int base	= (opcode >> 16) & 0x0F;
111.2689 +		int dest	= (opcode >> 12) & 0x0F;
111.2690 +		u32 address = reg[base].I - ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2691 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2692 +		reg[dest].I = (s8)CPUReadByte(address);
111.2693 +		if (dest != base)
111.2694 +			reg[base].I = address;
111.2695 +	}
111.2696 +	break;
111.2697 +	case 0x19d:
111.2698 +	{
111.2699 +		// LDRSB Rd, [Rn, Rm]
111.2700 +		int base	= (opcode >> 16) & 0x0F;
111.2701 +		int dest	= (opcode >> 12) & 0x0F;
111.2702 +		u32 address = reg[base].I + reg[opcode & 0x0F].I;
111.2703 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2704 +		reg[dest].I = (s8)CPUReadByte(address);
111.2705 +	}
111.2706 +	break;
111.2707 +	case 0x1bd:
111.2708 +	{
111.2709 +		// LDRSB Rd, [Rn, Rm]!
111.2710 +		int base	= (opcode >> 16) & 0x0F;
111.2711 +		int dest	= (opcode >> 12) & 0x0F;
111.2712 +		u32 address = reg[base].I + reg[opcode & 0x0F].I;
111.2713 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2714 +		reg[dest].I = (s8)CPUReadByte(address);
111.2715 +		if (dest != base)
111.2716 +			reg[base].I = address;
111.2717 +	}
111.2718 +	break;
111.2719 +	case 0x1dd:
111.2720 +	{
111.2721 +		// LDRSB Rd, [Rn, #offset]
111.2722 +		int base	= (opcode >> 16) & 0x0F;
111.2723 +		int dest	= (opcode >> 12) & 0x0F;
111.2724 +		u32 address = reg[base].I + ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2725 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2726 +		reg[dest].I = (s8)CPUReadByte(address);
111.2727 +	}
111.2728 +	break;
111.2729 +	case 0x1fd:
111.2730 +	{
111.2731 +		// LDRSB Rd, [Rn, #offset]!
111.2732 +		int base	= (opcode >> 16) & 0x0F;
111.2733 +		int dest	= (opcode >> 12) & 0x0F;
111.2734 +		u32 address = reg[base].I + ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2735 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2736 +		reg[dest].I = (s8)CPUReadByte(address);
111.2737 +		if (dest != base)
111.2738 +			reg[base].I = address;
111.2739 +	}
111.2740 +	break;
111.2741 +	case 0x01f:
111.2742 +	case 0x03f:
111.2743 +	{
111.2744 +		// LDRSH Rd, [Rn], -Rm
111.2745 +		int base	= (opcode >> 16) & 0x0F;
111.2746 +		int dest	= (opcode >> 12) & 0x0F;
111.2747 +		u32 address = reg[base].I;
111.2748 +		int offset	= reg[opcode & 0x0F].I;
111.2749 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2750 +		reg[dest].I = (s16)CPUReadHalfWordSigned(address);
111.2751 +		if (dest != base)
111.2752 +		{
111.2753 +			address	   -= offset;
111.2754 +			reg[base].I = address;
111.2755 +		}
111.2756 +	}
111.2757 +	break;
111.2758 +	case 0x05f:
111.2759 +	case 0x07f:
111.2760 +	{
111.2761 +		// LDRSH Rd, [Rn], #-offset
111.2762 +		int base	= (opcode >> 16) & 0x0F;
111.2763 +		int dest	= (opcode >> 12) & 0x0F;
111.2764 +		u32 address = reg[base].I;
111.2765 +		int offset	= (opcode & 0x0F) | ((opcode >> 4) & 0xF0);
111.2766 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2767 +		reg[dest].I = (s16)CPUReadHalfWordSigned(address);
111.2768 +		if (dest != base)
111.2769 +		{
111.2770 +			address	   -= offset;
111.2771 +			reg[base].I = address;
111.2772 +		}
111.2773 +	}
111.2774 +	break;
111.2775 +	case 0x09f:
111.2776 +	case 0x0bf:
111.2777 +	{
111.2778 +		// LDRSH Rd, [Rn], Rm
111.2779 +		int base	= (opcode >> 16) & 0x0F;
111.2780 +		int dest	= (opcode >> 12) & 0x0F;
111.2781 +		u32 address = reg[base].I;
111.2782 +		int offset	= reg[opcode & 0x0F].I;
111.2783 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2784 +		reg[dest].I = (s16)CPUReadHalfWordSigned(address);
111.2785 +		if (dest != base)
111.2786 +		{
111.2787 +			address	   += offset;
111.2788 +			reg[base].I = address;
111.2789 +		}
111.2790 +	}
111.2791 +	break;
111.2792 +	case 0x0df:
111.2793 +	case 0x0ff:
111.2794 +	{
111.2795 +		// LDRSH Rd, [Rn], #offset
111.2796 +		int base	= (opcode >> 16) & 0x0F;
111.2797 +		int dest	= (opcode >> 12) & 0x0F;
111.2798 +		u32 address = reg[base].I;
111.2799 +		int offset	= (opcode & 0x0F) | ((opcode >> 4) & 0xF0);
111.2800 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2801 +		reg[dest].I = (s16)CPUReadHalfWordSigned(address);
111.2802 +		if (dest != base)
111.2803 +		{
111.2804 +			address	   += offset;
111.2805 +			reg[base].I = address;
111.2806 +		}
111.2807 +	}
111.2808 +	break;
111.2809 +	case 0x11f:
111.2810 +	{
111.2811 +		// LDRSH Rd, [Rn, -Rm]
111.2812 +		int base	= (opcode >> 16) & 0x0F;
111.2813 +		int dest	= (opcode >> 12) & 0x0F;
111.2814 +		u32 address = reg[base].I - reg[opcode & 0x0F].I;
111.2815 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2816 +		reg[dest].I = (s16)CPUReadHalfWordSigned(address);
111.2817 +	}
111.2818 +	break;
111.2819 +	case 0x13f:
111.2820 +	{
111.2821 +		// LDRSH Rd, [Rn, -Rm]!
111.2822 +		int base	= (opcode >> 16) & 0x0F;
111.2823 +		int dest	= (opcode >> 12) & 0x0F;
111.2824 +		u32 address = reg[base].I - reg[opcode & 0x0F].I;
111.2825 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2826 +		reg[dest].I = (s16)CPUReadHalfWordSigned(address);
111.2827 +		if (dest != base)
111.2828 +			reg[base].I = address;
111.2829 +	}
111.2830 +	break;
111.2831 +	case 0x15f:
111.2832 +	{
111.2833 +		// LDRSH Rd, [Rn, -#offset]
111.2834 +		int base	= (opcode >> 16) & 0x0F;
111.2835 +		int dest	= (opcode >> 12) & 0x0F;
111.2836 +		u32 address = reg[base].I - ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2837 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2838 +		reg[dest].I = (s16)CPUReadHalfWordSigned(address);
111.2839 +	}
111.2840 +	break;
111.2841 +	case 0x17f:
111.2842 +	{
111.2843 +		// LDRSH Rd, [Rn, -#offset]!
111.2844 +		int base	= (opcode >> 16) & 0x0F;
111.2845 +		int dest	= (opcode >> 12) & 0x0F;
111.2846 +		u32 address = reg[base].I - ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2847 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2848 +		reg[dest].I = (s16)CPUReadHalfWordSigned(address);
111.2849 +		if (dest != base)
111.2850 +			reg[base].I = address;
111.2851 +	}
111.2852 +	break;
111.2853 +	case 0x19f:
111.2854 +	{
111.2855 +		// LDRSH Rd, [Rn, Rm]
111.2856 +		int base	= (opcode >> 16) & 0x0F;
111.2857 +		int dest	= (opcode >> 12) & 0x0F;
111.2858 +		u32 address = reg[base].I + reg[opcode & 0x0F].I;
111.2859 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2860 +		reg[dest].I = (s16)CPUReadHalfWordSigned(address);
111.2861 +	}
111.2862 +	break;
111.2863 +	case 0x1bf:
111.2864 +	{
111.2865 +		// LDRSH Rd, [Rn, Rm]!
111.2866 +		int base	= (opcode >> 16) & 0x0F;
111.2867 +		int dest	= (opcode >> 12) & 0x0F;
111.2868 +		u32 address = reg[base].I + reg[opcode & 0x0F].I;
111.2869 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2870 +		reg[dest].I = (s16)CPUReadHalfWordSigned(address);
111.2871 +		if (dest != base)
111.2872 +			reg[base].I = address;
111.2873 +	}
111.2874 +	break;
111.2875 +	case 0x1df:
111.2876 +	{
111.2877 +		// LDRSH Rd, [Rn, #offset]
111.2878 +		int base	= (opcode >> 16) & 0x0F;
111.2879 +		int dest	= (opcode >> 12) & 0x0F;
111.2880 +		u32 address = reg[base].I + ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2881 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2882 +		reg[dest].I = (s16)CPUReadHalfWordSigned(address);
111.2883 +	}
111.2884 +	break;
111.2885 +	case 0x1ff:
111.2886 +	{
111.2887 +		// LDRSH Rd, [Rn, #offset]!
111.2888 +		int base	= (opcode >> 16) & 0x0F;
111.2889 +		int dest	= (opcode >> 12) & 0x0F;
111.2890 +		u32 address = reg[base].I + ((opcode & 0x0F) | ((opcode >> 4) & 0xF0));
111.2891 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.2892 +		reg[dest].I = (s16)CPUReadHalfWordSigned(address);
111.2893 +		if (dest != base)
111.2894 +			reg[base].I = address;
111.2895 +	}
111.2896 +	break;
111.2897 +		LOGICAL_DATA_OPCODE_WITHOUT_base(OP_EOR,  OP_EOR, 0x020);
111.2898 +		LOGICAL_DATA_OPCODE_WITHOUT_base(OP_EORS, OP_EOR, 0x030);
111.2899 +	case 0x029:
111.2900 +	{
111.2901 +		// MLA Rd, Rm, Rs, Rn
111.2902 +		int dest = (opcode >> 16) & 0x0F;
111.2903 +		int mult = (opcode & 0x0F);
111.2904 +		u32 rs	 = reg[(opcode >> 8) & 0x0F].I;
111.2905 +		reg[dest].I = reg[mult].I * rs + reg[(opcode >> 12) & 0x0f].I;
111.2906 +		if (((s32)rs) < 0)
111.2907 +			rs = ~rs;
111.2908 +		if ((rs & 0xFFFFFF00) == 0)
111.2909 +			clockTicks += 3;
111.2910 +		else if ((rs & 0xFFFF0000) == 0)
111.2911 +			clockTicks += 4;
111.2912 +		else if ((rs & 0xFF000000) == 0)
111.2913 +			clockTicks += 5;
111.2914 +		else
111.2915 +			clockTicks += 6;
111.2916 +	}
111.2917 +	break;
111.2918 +	case 0x039:
111.2919 +	{
111.2920 +		// MLAS Rd, Rm, Rs, Rn
111.2921 +		int dest = (opcode >> 16) & 0x0F;
111.2922 +		int mult = (opcode & 0x0F);
111.2923 +		u32 rs	 = reg[(opcode >> 8) & 0x0F].I;
111.2924 +		reg[dest].I = reg[mult].I * rs + reg[(opcode >> 12) & 0x0f].I;
111.2925 +		N_FLAG		= (reg[dest].I & 0x80000000) ? true : false;
111.2926 +		Z_FLAG		= (reg[dest].I) ? false : true;
111.2927 +		if (((s32)rs) < 0)
111.2928 +			rs = ~rs;
111.2929 +		if ((rs & 0xFFFFFF00) == 0)
111.2930 +			clockTicks += 3;
111.2931 +		else if ((rs & 0xFFFF0000) == 0)
111.2932 +			clockTicks += 4;
111.2933 +		else if ((rs & 0xFF000000) == 0)
111.2934 +			clockTicks += 5;
111.2935 +		else
111.2936 +			clockTicks += 6;
111.2937 +	}
111.2938 +	break;
111.2939 +		ARITHMETIC_DATA_OPCODE(OP_SUB,  OP_SUB, 0x040);
111.2940 +		ARITHMETIC_DATA_OPCODE(OP_SUBS, OP_SUB, 0x050);
111.2941 +		ARITHMETIC_DATA_OPCODE(OP_RSB,  OP_RSB, 0x060);
111.2942 +		ARITHMETIC_DATA_OPCODE(OP_RSBS, OP_RSB, 0x070);
111.2943 +		ARITHMETIC_DATA_OPCODE(OP_ADD,  OP_ADD, 0x080);
111.2944 +		ARITHMETIC_DATA_OPCODE(OP_ADDS, OP_ADD, 0x090);
111.2945 +	case 0x089:
111.2946 +	{
111.2947 +		// UMULL RdLo, RdHi, Rn, Rs
111.2948 +		u32 umult	= reg[(opcode & 0x0F)].I;
111.2949 +		u32 usource = reg[(opcode >> 8) & 0x0F].I;
111.2950 +		int destLo	= (opcode >> 12) & 0x0F;
111.2951 +		int destHi	= (opcode >> 16) & 0x0F;
111.2952 +		u64 uTemp	= ((u64)umult) * ((u64)usource);
111.2953 +		reg[destLo].I = (u32)(uTemp & 0xFFFFFFFF);
111.2954 +		reg[destHi].I = (u32)(uTemp >> 32);
111.2955 +		if ((usource & 0xFFFFFF00) == 0)
111.2956 +			clockTicks += 2;
111.2957 +		else if ((usource & 0xFFFF0000) == 0)
111.2958 +			clockTicks += 3;
111.2959 +		else if ((usource & 0xFF000000) == 0)
111.2960 +			clockTicks += 4;
111.2961 +		else
111.2962 +			clockTicks += 5;
111.2963 +	}
111.2964 +	break;
111.2965 +	case 0x099:
111.2966 +	{
111.2967 +		// UMULLS RdLo, RdHi, Rn, Rs
111.2968 +		u32 umult	= reg[(opcode & 0x0F)].I;
111.2969 +		u32 usource = reg[(opcode >> 8) & 0x0F].I;
111.2970 +		int destLo	= (opcode >> 12) & 0x0F;
111.2971 +		int destHi	= (opcode >> 16) & 0x0F;
111.2972 +		u64 uTemp	= ((u64)umult) * ((u64)usource);
111.2973 +		reg[destLo].I = (u32)(uTemp & 0xFFFFFFFF);
111.2974 +		reg[destHi].I = (u32)(uTemp >> 32);
111.2975 +		Z_FLAG		  = (uTemp) ? false : true;
111.2976 +		N_FLAG		  = (reg[destHi].I & 0x80000000) ? true : false;
111.2977 +		if ((usource & 0xFFFFFF00) == 0)
111.2978 +			clockTicks += 2;
111.2979 +		else if ((usource & 0xFFFF0000) == 0)
111.2980 +			clockTicks += 3;
111.2981 +		else if ((usource & 0xFF000000) == 0)
111.2982 +			clockTicks += 4;
111.2983 +		else
111.2984 +			clockTicks += 5;
111.2985 +	}
111.2986 +	break;
111.2987 +		ARITHMETIC_DATA_OPCODE(OP_ADC,  OP_ADC, 0x0a0);
111.2988 +		ARITHMETIC_DATA_OPCODE(OP_ADCS, OP_ADC, 0x0b0);
111.2989 +	case 0x0a9:
111.2990 +	{
111.2991 +		// UMLAL RdLo, RdHi, Rn, Rs
111.2992 +		u32 umult	= reg[(opcode & 0x0F)].I;
111.2993 +		u32 usource = reg[(opcode >> 8) & 0x0F].I;
111.2994 +		int destLo	= (opcode >> 12) & 0x0F;
111.2995 +		int destHi	= (opcode >> 16) & 0x0F;
111.2996 +		u64 uTemp	= (u64)reg[destHi].I;
111.2997 +		uTemp		<<= 32;
111.2998 +		uTemp		 |= (u64)reg[destLo].I;
111.2999 +		uTemp		 += ((u64)umult) * ((u64)usource);
111.3000 +		reg[destLo].I = (u32)(uTemp & 0xFFFFFFFF);
111.3001 +		reg[destHi].I = (u32)(uTemp >> 32);
111.3002 +		if ((usource & 0xFFFFFF00) == 0)
111.3003 +			clockTicks += 3;
111.3004 +		else if ((usource & 0xFFFF0000) == 0)
111.3005 +			clockTicks += 4;
111.3006 +		else if ((usource & 0xFF000000) == 0)
111.3007 +			clockTicks += 5;
111.3008 +		else
111.3009 +			clockTicks += 6;
111.3010 +	}
111.3011 +	break;
111.3012 +	case 0x0b9:
111.3013 +	{
111.3014 +		// UMLALS RdLo, RdHi, Rn, Rs
111.3015 +		u32 umult	= reg[(opcode & 0x0F)].I;
111.3016 +		u32 usource = reg[(opcode >> 8) & 0x0F].I;
111.3017 +		int destLo	= (opcode >> 12) & 0x0F;
111.3018 +		int destHi	= (opcode >> 16) & 0x0F;
111.3019 +		u64 uTemp	= (u64)reg[destHi].I;
111.3020 +		uTemp		<<= 32;
111.3021 +		uTemp		 |= (u64)reg[destLo].I;
111.3022 +		uTemp		 += ((u64)umult) * ((u64)usource);
111.3023 +		reg[destLo].I = (u32)(uTemp & 0xFFFFFFFF);
111.3024 +		reg[destHi].I = (u32)(uTemp >> 32);
111.3025 +		Z_FLAG		  = (uTemp) ? false : true;
111.3026 +		N_FLAG		  = (reg[destHi].I & 0x80000000) ? true : false;
111.3027 +		if ((usource & 0xFFFFFF00) == 0)
111.3028 +			clockTicks += 3;
111.3029 +		else if ((usource & 0xFFFF0000) == 0)
111.3030 +			clockTicks += 4;
111.3031 +		else if ((usource & 0xFF000000) == 0)
111.3032 +			clockTicks += 5;
111.3033 +		else
111.3034 +			clockTicks += 6;
111.3035 +	}
111.3036 +	break;
111.3037 +		ARITHMETIC_DATA_OPCODE(OP_SBC,  OP_SBC, 0x0c0);
111.3038 +		ARITHMETIC_DATA_OPCODE(OP_SBCS, OP_SBC, 0x0d0);
111.3039 +	case 0x0c9:
111.3040 +	{
111.3041 +		// SMULL RdLo, RdHi, Rm, Rs
111.3042 +		int destLo = (opcode >> 12) & 0x0F;
111.3043 +		int destHi = (opcode >> 16) & 0x0F;
111.3044 +		u32 rs	   = reg[(opcode >> 8) & 0x0F].I;
111.3045 +		s64 m	   = (s32)reg[(opcode & 0x0F)].I;
111.3046 +		s64 s	   = (s32)rs;
111.3047 +		s64 sTemp  = m * s;
111.3048 +		reg[destLo].I = (u32)(sTemp & 0xFFFFFFFF);
111.3049 +		reg[destHi].I = (u32)(sTemp >> 32);
111.3050 +		if (((s32)rs) < 0)
111.3051 +			rs = ~rs;
111.3052 +		if ((rs & 0xFFFFFF00) == 0)
111.3053 +			clockTicks += 2;
111.3054 +		else if ((rs & 0xFFFF0000) == 0)
111.3055 +			clockTicks += 3;
111.3056 +		else if ((rs & 0xFF000000) == 0)
111.3057 +			clockTicks += 4;
111.3058 +		else
111.3059 +			clockTicks += 5;
111.3060 +	}
111.3061 +	break;
111.3062 +	case 0x0d9:
111.3063 +	{
111.3064 +		// SMULLS RdLo, RdHi, Rm, Rs
111.3065 +		int destLo = (opcode >> 12) & 0x0F;
111.3066 +		int destHi = (opcode >> 16) & 0x0F;
111.3067 +		u32 rs	   = reg[(opcode >> 8) & 0x0F].I;
111.3068 +		s64 m	   = (s32)reg[(opcode & 0x0F)].I;
111.3069 +		s64 s	   = (s32)rs;
111.3070 +		s64 sTemp  = m * s;
111.3071 +		reg[destLo].I = (u32)(sTemp & 0xFFFFFFFF);
111.3072 +		reg[destHi].I = (u32)(sTemp >> 32);
111.3073 +		Z_FLAG		  = (sTemp) ? false : true;
111.3074 +		N_FLAG		  = (sTemp < 0) ? true : false;
111.3075 +		if (((s32)rs) < 0)
111.3076 +			rs = ~rs;
111.3077 +		if ((rs & 0xFFFFFF00) == 0)
111.3078 +			clockTicks += 2;
111.3079 +		else if ((rs & 0xFFFF0000) == 0)
111.3080 +			clockTicks += 3;
111.3081 +		else if ((rs & 0xFF000000) == 0)
111.3082 +			clockTicks += 4;
111.3083 +		else
111.3084 +			clockTicks += 5;
111.3085 +	}
111.3086 +	break;
111.3087 +		ARITHMETIC_DATA_OPCODE(OP_RSC,  OP_RSC, 0x0e0);
111.3088 +		ARITHMETIC_DATA_OPCODE(OP_RSCS, OP_RSC, 0x0f0);
111.3089 +	case 0x0e9:
111.3090 +	{
111.3091 +		// SMLAL RdLo, RdHi, Rm, Rs
111.3092 +		int destLo = (opcode >> 12) & 0x0F;
111.3093 +		int destHi = (opcode >> 16) & 0x0F;
111.3094 +		u32 rs	   = reg[(opcode >> 8) & 0x0F].I;
111.3095 +		s64 m	   = (s32)reg[(opcode & 0x0F)].I;
111.3096 +		s64 s	   = (s32)rs;
111.3097 +		s64 sTemp  = (u64)reg[destHi].I;
111.3098 +		sTemp		<<= 32;
111.3099 +		sTemp		 |= (u64)reg[destLo].I;
111.3100 +		sTemp		 += m * s;
111.3101 +		reg[destLo].I = (u32)(sTemp & 0xFFFFFFFF);
111.3102 +		reg[destHi].I = (u32)(sTemp >> 32);
111.3103 +		if (((s32)rs) < 0)
111.3104 +			rs = ~rs;
111.3105 +		if ((rs & 0xFFFFFF00) == 0)
111.3106 +			clockTicks += 3;
111.3107 +		else if ((rs & 0xFFFF0000) == 0)
111.3108 +			clockTicks += 4;
111.3109 +		else if ((rs & 0xFF000000) == 0)
111.3110 +			clockTicks += 5;
111.3111 +		else
111.3112 +			clockTicks += 6;
111.3113 +	}
111.3114 +	break;
111.3115 +	case 0x0f9:
111.3116 +	{
111.3117 +		// SMLALS RdLo, RdHi, Rm, Rs
111.3118 +		int destLo = (opcode >> 12) & 0x0F;
111.3119 +		int destHi = (opcode >> 16) & 0x0F;
111.3120 +		u32 rs	   = reg[(opcode >> 8) & 0x0F].I;
111.3121 +		s64 m	   = (s32)reg[(opcode & 0x0F)].I;
111.3122 +		s64 s	   = (s32)rs;
111.3123 +		s64 sTemp  = (u64)reg[destHi].I;
111.3124 +		sTemp		<<= 32;
111.3125 +		sTemp		 |= (u64)reg[destLo].I;
111.3126 +		sTemp		 += m * s;
111.3127 +		reg[destLo].I = (u32)(sTemp & 0xFFFFFFFF);
111.3128 +		reg[destHi].I = (u32)(sTemp >> 32);
111.3129 +		Z_FLAG		  = (sTemp) ? false : true;
111.3130 +		N_FLAG		  = (sTemp < 0) ? true : false;
111.3131 +		if (((s32)rs) < 0)
111.3132 +			rs = ~rs;
111.3133 +		if ((rs & 0xFFFFFF00) == 0)
111.3134 +			clockTicks += 3;
111.3135 +		else if ((rs & 0xFFFF0000) == 0)
111.3136 +			clockTicks += 4;
111.3137 +		else if ((rs & 0xFF000000) == 0)
111.3138 +			clockTicks += 5;
111.3139 +		else
111.3140 +			clockTicks += 6;
111.3141 +	}
111.3142 +	break;
111.3143 +		LOGICAL_DATA_OPCODE(OP_TST, OP_TST, 0x110);
111.3144 +	case 0x100:
111.3145 +		// MRS Rd, CPSR
111.3146 +		// TODO: check if right instruction....
111.3147 +		CPUUpdateCPSR();
111.3148 +		reg[(opcode >> 12) & 0x0F].I = reg[16].I;
111.3149 +		break;
111.3150 +	case 0x109:
111.3151 +	{
111.3152 +		// SWP Rd, Rm, [Rn]
111.3153 +		u32 address = reg[(opcode >> 16) & 15].I;
111.3154 +		u32 temp	= CPUReadMemory(address);
111.3155 +		CPUWriteMemory(address, reg[opcode & 15].I);
111.3156 +		reg[(opcode >> 12) & 15].I = temp;
111.3157 +	}
111.3158 +	break;
111.3159 +		LOGICAL_DATA_OPCODE(OP_TEQ, OP_TEQ, 0x130);
111.3160 +	case 0x120:
111.3161 +	{
111.3162 +		// MSR CPSR_fields, Rm
111.3163 +		CPUUpdateCPSR();
111.3164 +		u32 value	 = reg[opcode & 15].I;
111.3165 +		u32 newValue = reg[16].I;
111.3166 +		if (armMode > 0x10)
111.3167 +		{
111.3168 +			if (opcode & 0x00010000)
111.3169 +				newValue = (newValue & 0xFFFFFF00) | (value & 0x000000FF);
111.3170 +			if (opcode & 0x00020000)
111.3171 +				newValue = (newValue & 0xFFFF00FF) | (value & 0x0000FF00);
111.3172 +			if (opcode & 0x00040000)
111.3173 +				newValue = (newValue & 0xFF00FFFF) | (value & 0x00FF0000);
111.3174 +		}
111.3175 +		if (opcode & 0x00080000)
111.3176 +			newValue = (newValue & 0x00FFFFFF) | (value & 0xFF000000);
111.3177 +		newValue |= 0x10;
111.3178 +		CPUSwitchMode(newValue & 0x1f, false);
111.3179 +		reg[16].I = newValue;
111.3180 +		CPUUpdateFlags();
111.3181 +	}
111.3182 +	break;
111.3183 +	case 0x121:
111.3184 +	{
111.3185 +		// BX Rm
111.3186 +		// TODO: check if right instruction...
111.3187 +		clockTicks += 3;
111.3188 +		int base = opcode & 0x0F;
111.3189 +		armState = reg[base].I & 1 ? false : true;
111.3190 +		if (armState)
111.3191 +		{
111.3192 +			reg[15].I  = reg[base].I & 0xFFFFFFFC;
111.3193 +			armNextPC  = reg[15].I;
111.3194 +			reg[15].I += 4;
111.3195 +		}
111.3196 +		else
111.3197 +		{
111.3198 +			reg[15].I  = reg[base].I & 0xFFFFFFFE;
111.3199 +			armNextPC  = reg[15].I;
111.3200 +			reg[15].I += 2;
111.3201 +		}
111.3202 +	}
111.3203 +	break;
111.3204 +		ARITHMETIC_DATA_OPCODE(OP_CMP, OP_CMP, 0x150);
111.3205 +	case 0x140:
111.3206 +		// MRS Rd, SPSR
111.3207 +		// TODO: check if right instruction...
111.3208 +		reg[(opcode >> 12) & 0x0F].I = reg[17].I;
111.3209 +		break;
111.3210 +	case 0x149:
111.3211 +	{
111.3212 +		// SWPB Rd, Rm, [Rn]
111.3213 +		u32 address = reg[(opcode >> 16) & 15].I;
111.3214 +		u32 temp	= CPUReadByte(address);
111.3215 +		CPUWriteByte(address, reg[opcode & 15].B.B0);
111.3216 +		reg[(opcode >> 12) & 15].I = temp;
111.3217 +	}
111.3218 +	break;
111.3219 +		ARITHMETIC_DATA_OPCODE(OP_CMN, OP_CMN, 0x170);
111.3220 +	case 0x160:
111.3221 +	{
111.3222 +		// MSR SPSR_fields, Rm
111.3223 +		u32 value = reg[opcode & 15].I;
111.3224 +		if (armMode > 0x10 && armMode < 0x1f)
111.3225 +		{
111.3226 +			if (opcode & 0x00010000)
111.3227 +				reg[17].I = (reg[17].I & 0xFFFFFF00) | (value & 0x000000FF);
111.3228 +			if (opcode & 0x00020000)
111.3229 +				reg[17].I = (reg[17].I & 0xFFFF00FF) | (value & 0x0000FF00);
111.3230 +			if (opcode & 0x00040000)
111.3231 +				reg[17].I = (reg[17].I & 0xFF00FFFF) | (value & 0x00FF0000);
111.3232 +			if (opcode & 0x00080000)
111.3233 +				reg[17].I = (reg[17].I & 0x00FFFFFF) | (value & 0xFF000000);
111.3234 +		}
111.3235 +	}
111.3236 +	break;
111.3237 +		LOGICAL_DATA_OPCODE(OP_ORR,  OP_ORR, 0x180);
111.3238 +		LOGICAL_DATA_OPCODE(OP_ORRS, OP_ORR, 0x190);
111.3239 +		LOGICAL_DATA_OPCODE_WITHOUT_base(OP_MOV,  OP_MOV, 0x1a0);
111.3240 +		LOGICAL_DATA_OPCODE_WITHOUT_base(OP_MOVS, OP_MOV, 0x1b0);
111.3241 +		LOGICAL_DATA_OPCODE(OP_BIC,  OP_BIC, 0x1c0);
111.3242 +		LOGICAL_DATA_OPCODE(OP_BICS, OP_BIC, 0x1d0);
111.3243 +		LOGICAL_DATA_OPCODE_WITHOUT_base(OP_MVN,  OP_MVN, 0x1e0);
111.3244 +		LOGICAL_DATA_OPCODE_WITHOUT_base(OP_MVNS, OP_MVN, 0x1f0);
111.3245 +#ifdef BKPT_SUPPORT
111.3246 +	case 0x127:
111.3247 +	case 0x7ff: // for GDB support
111.3248 +		extern void (*dbgSignal)(int, int);
111.3249 +		reg[15].I -= 4;
111.3250 +		armNextPC -= 4;
111.3251 +		dbgSignal(5, (opcode & 0x0f) | ((opcode >> 4) & 0xfff0));
111.3252 +		return;
111.3253 +#endif
111.3254 +	case 0x320:
111.3255 +	case 0x321:
111.3256 +	case 0x322:
111.3257 +	case 0x323:
111.3258 +	case 0x324:
111.3259 +	case 0x325:
111.3260 +	case 0x326:
111.3261 +	case 0x327:
111.3262 +	case 0x328:
111.3263 +	case 0x329:
111.3264 +	case 0x32a:
111.3265 +	case 0x32b:
111.3266 +	case 0x32c:
111.3267 +	case 0x32d:
111.3268 +	case 0x32e:
111.3269 +	case 0x32f:
111.3270 +	{
111.3271 +		// MSR CPSR_fields, #
111.3272 +		CPUUpdateCPSR();
111.3273 +		u32 value = opcode & 0xFF;
111.3274 +		int shift = (opcode & 0xF00) >> 7;
111.3275 +		if (shift)
111.3276 +		{
111.3277 +			ROR_IMM_MSR;
111.3278 +		}
111.3279 +		u32 newValue = reg[16].I;
111.3280 +		if (armMode > 0x10)
111.3281 +		{
111.3282 +			if (opcode & 0x00010000)
111.3283 +				newValue = (newValue & 0xFFFFFF00) | (value & 0x000000FF);
111.3284 +			if (opcode & 0x00020000)
111.3285 +				newValue = (newValue & 0xFFFF00FF) | (value & 0x0000FF00);
111.3286 +			if (opcode & 0x00040000)
111.3287 +				newValue = (newValue & 0xFF00FFFF) | (value & 0x00FF0000);
111.3288 +		}
111.3289 +		if (opcode & 0x00080000)
111.3290 +			newValue = (newValue & 0x00FFFFFF) | (value & 0xFF000000);
111.3291 +
111.3292 +		newValue |= 0x10;
111.3293 +
111.3294 +		CPUSwitchMode(newValue & 0x1f, false);
111.3295 +		reg[16].I = newValue;
111.3296 +		CPUUpdateFlags();
111.3297 +	}
111.3298 +	break;
111.3299 +	case 0x360:
111.3300 +	case 0x361:
111.3301 +	case 0x362:
111.3302 +	case 0x363:
111.3303 +	case 0x364:
111.3304 +	case 0x365:
111.3305 +	case 0x366:
111.3306 +	case 0x367:
111.3307 +	case 0x368:
111.3308 +	case 0x369:
111.3309 +	case 0x36a:
111.3310 +	case 0x36b:
111.3311 +	case 0x36c:
111.3312 +	case 0x36d:
111.3313 +	case 0x36e:
111.3314 +	case 0x36f:
111.3315 +	{
111.3316 +		// MSR SPSR_fields, #
111.3317 +		if (armMode > 0x10 && armMode < 0x1f)
111.3318 +		{
111.3319 +			u32 value = opcode & 0xFF;
111.3320 +			int shift = (opcode & 0xF00) >> 7;
111.3321 +			if (shift)
111.3322 +			{
111.3323 +				ROR_IMM_MSR;
111.3324 +			}
111.3325 +			if (opcode & 0x00010000)
111.3326 +				reg[17].I = (reg[17].I & 0xFFFFFF00) | (value & 0x000000FF);
111.3327 +			if (opcode & 0x00020000)
111.3328 +				reg[17].I = (reg[17].I & 0xFFFF00FF) | (value & 0x0000FF00);
111.3329 +			if (opcode & 0x00040000)
111.3330 +				reg[17].I = (reg[17].I & 0xFF00FFFF) | (value & 0x00FF0000);
111.3331 +			if (opcode & 0x00080000)
111.3332 +				reg[17].I = (reg[17].I & 0x00FFFFFF) | (value & 0xFF000000);
111.3333 +		}
111.3334 +	}
111.3335 +	break;
111.3336 +		CASE_16(0x400)
111.3337 +		// T versions shouldn't be different on GBA
111.3338 +		CASE_16(0x420)
111.3339 +		{
111.3340 +			// STR Rd, [Rn], -#
111.3341 +			int offset	= opcode & 0xFFF;
111.3342 +			int dest	= (opcode >> 12) & 15;
111.3343 +			int base	= (opcode >> 16) & 15;
111.3344 +			u32 address = reg[base].I;
111.3345 +			CPUWriteMemory(address, reg[dest].I);
111.3346 +			reg[base].I = address - offset;
111.3347 +			clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3348 +		}
111.3349 +		break;
111.3350 +		CASE_16(0x480)
111.3351 +		// T versions shouldn't be different on GBA
111.3352 +		CASE_16(0x4a0)
111.3353 +		{
111.3354 +			// STR Rd, [Rn], #
111.3355 +			int offset	= opcode & 0xFFF;
111.3356 +			int dest	= (opcode >> 12) & 15;
111.3357 +			int base	= (opcode >> 16) & 15;
111.3358 +			u32 address = reg[base].I;
111.3359 +			CPUWriteMemory(address, reg[dest].I);
111.3360 +			reg[base].I = address + offset;
111.3361 +			clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3362 +		}
111.3363 +		break;
111.3364 +		CASE_16(0x500)
111.3365 +		{
111.3366 +			// STR Rd, [Rn, -#]
111.3367 +			int offset	= opcode & 0xFFF;
111.3368 +			int dest	= (opcode >> 12) & 15;
111.3369 +			int base	= (opcode >> 16) & 15;
111.3370 +			u32 address = reg[base].I - offset;
111.3371 +			CPUWriteMemory(address, reg[dest].I);
111.3372 +			clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3373 +		}
111.3374 +		break;
111.3375 +		CASE_16(0x520)
111.3376 +		{
111.3377 +			// STR Rd, [Rn, -#]!
111.3378 +			int offset	= opcode & 0xFFF;
111.3379 +			int dest	= (opcode >> 12) & 15;
111.3380 +			int base	= (opcode >> 16) & 15;
111.3381 +			u32 address = reg[base].I - offset;
111.3382 +			reg[base].I = address;
111.3383 +			CPUWriteMemory(address, reg[dest].I);
111.3384 +			clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3385 +		}
111.3386 +		break;
111.3387 +		CASE_16(0x580)
111.3388 +		{
111.3389 +			// STR Rd, [Rn, #]
111.3390 +			int offset	= opcode & 0xFFF;
111.3391 +			int dest	= (opcode >> 12) & 15;
111.3392 +			int base	= (opcode >> 16) & 15;
111.3393 +			u32 address = reg[base].I + offset;
111.3394 +			CPUWriteMemory(address, reg[dest].I);
111.3395 +			clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3396 +		}
111.3397 +		break;
111.3398 +		CASE_16(0x5a0)
111.3399 +		{
111.3400 +			// STR Rd, [Rn, #]!
111.3401 +			int offset	= opcode & 0xFFF;
111.3402 +			int dest	= (opcode >> 12) & 15;
111.3403 +			int base	= (opcode >> 16) & 15;
111.3404 +			u32 address = reg[base].I + offset;
111.3405 +			reg[base].I = address;
111.3406 +			CPUWriteMemory(address, reg[dest].I);
111.3407 +			clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3408 +		}
111.3409 +		break;
111.3410 +		CASE_16(0x410)
111.3411 +		{
111.3412 +			// LDR Rd, [Rn], -#
111.3413 +			int offset	= opcode & 0xFFF;
111.3414 +			int dest	= (opcode >> 12) & 15;
111.3415 +			int base	= (opcode >> 16) & 15;
111.3416 +			u32 address = reg[base].I;
111.3417 +			reg[dest].I = CPUReadMemory(address);
111.3418 +			if (dest != base)
111.3419 +				reg[base].I -= offset;
111.3420 +			clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.3421 +			if (dest == 15)
111.3422 +			{
111.3423 +				clockTicks += 2;
111.3424 +				reg[15].I  &= 0xFFFFFFFC;
111.3425 +				armNextPC	= reg[15].I;
111.3426 +				reg[15].I  += 4;
111.3427 +			}
111.3428 +		}
111.3429 +		break;
111.3430 +		CASE_16(0x430)
111.3431 +		{
111.3432 +			// LDRT Rd, [Rn], -#
111.3433 +			int offset	= opcode & 0xFFF;
111.3434 +			int dest	= (opcode >> 12) & 15;
111.3435 +			int base	= (opcode >> 16) & 15;
111.3436 +			u32 address = reg[base].I;
111.3437 +			reg[dest].I = CPUReadMemory(address);
111.3438 +			if (dest != base)
111.3439 +				reg[base].I -= offset;
111.3440 +			clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.3441 +		}
111.3442 +		break;
111.3443 +		CASE_16(0x490)
111.3444 +		{
111.3445 +			// LDR Rd, [Rn], #
111.3446 +			int offset	= opcode & 0xFFF;
111.3447 +			int dest	= (opcode >> 12) & 15;
111.3448 +			int base	= (opcode >> 16) & 15;
111.3449 +			u32 address = reg[base].I;
111.3450 +			reg[dest].I = CPUReadMemory(address);
111.3451 +			if (dest != base)
111.3452 +				reg[base].I += offset;
111.3453 +			clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.3454 +			if (dest == 15)
111.3455 +			{
111.3456 +				clockTicks += 2;
111.3457 +				reg[15].I  &= 0xFFFFFFFC;
111.3458 +				armNextPC	= reg[15].I;
111.3459 +				reg[15].I  += 4;
111.3460 +			}
111.3461 +		}
111.3462 +		break;
111.3463 +		CASE_16(0x4b0)
111.3464 +		{
111.3465 +			// LDRT Rd, [Rn], #
111.3466 +			int offset	= opcode & 0xFFF;
111.3467 +			int dest	= (opcode >> 12) & 15;
111.3468 +			int base	= (opcode >> 16) & 15;
111.3469 +			u32 address = reg[base].I;
111.3470 +			reg[dest].I = CPUReadMemory(address);
111.3471 +			if (dest != base)
111.3472 +				reg[base].I += offset;
111.3473 +			clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.3474 +		}
111.3475 +		break;
111.3476 +		CASE_16(0x510)
111.3477 +		{
111.3478 +			// LDR Rd, [Rn, -#]
111.3479 +			int offset	= opcode & 0xFFF;
111.3480 +			int dest	= (opcode >> 12) & 15;
111.3481 +			int base	= (opcode >> 16) & 15;
111.3482 +			u32 address = reg[base].I - offset;
111.3483 +			reg[dest].I = CPUReadMemory(address);
111.3484 +			clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.3485 +			if (dest == 15)
111.3486 +			{
111.3487 +				clockTicks += 2;
111.3488 +				reg[15].I  &= 0xFFFFFFFC;
111.3489 +				armNextPC	= reg[15].I;
111.3490 +				reg[15].I  += 4;
111.3491 +			}
111.3492 +		}
111.3493 +		break;
111.3494 +		CASE_16(0x530)
111.3495 +		{
111.3496 +			// LDR Rd, [Rn, -#]!
111.3497 +			int offset	= opcode & 0xFFF;
111.3498 +			int dest	= (opcode >> 12) & 15;
111.3499 +			int base	= (opcode >> 16) & 15;
111.3500 +			u32 address = reg[base].I - offset;
111.3501 +			reg[dest].I = CPUReadMemory(address);
111.3502 +			if (dest != base)
111.3503 +				reg[base].I = address;
111.3504 +			clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.3505 +			if (dest == 15)
111.3506 +			{
111.3507 +				clockTicks += 2;
111.3508 +				reg[15].I  &= 0xFFFFFFFC;
111.3509 +				armNextPC	= reg[15].I;
111.3510 +				reg[15].I  += 4;
111.3511 +			}
111.3512 +		}
111.3513 +		break;
111.3514 +		CASE_16(0x590)
111.3515 +		{
111.3516 +			// LDR Rd, [Rn, #]
111.3517 +			int offset	= opcode & 0xFFF;
111.3518 +			int dest	= (opcode >> 12) & 15;
111.3519 +			int base	= (opcode >> 16) & 15;
111.3520 +			u32 address = reg[base].I + offset;
111.3521 +			reg[dest].I = CPUReadMemory(address);
111.3522 +			clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.3523 +			if (dest == 15)
111.3524 +			{
111.3525 +				clockTicks += 2;
111.3526 +				reg[15].I  &= 0xFFFFFFFC;
111.3527 +				armNextPC	= reg[15].I;
111.3528 +				reg[15].I  += 4;
111.3529 +			}
111.3530 +		}
111.3531 +		break;
111.3532 +		CASE_16(0x5b0)
111.3533 +		{
111.3534 +			// LDR Rd, [Rn, #]!
111.3535 +			int offset	= opcode & 0xFFF;
111.3536 +			int dest	= (opcode >> 12) & 15;
111.3537 +			int base	= (opcode >> 16) & 15;
111.3538 +			u32 address = reg[base].I + offset;
111.3539 +			reg[dest].I = CPUReadMemory(address);
111.3540 +			if (dest != base)
111.3541 +				reg[base].I = address;
111.3542 +			clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.3543 +			if (dest == 15)
111.3544 +			{
111.3545 +				clockTicks += 2;
111.3546 +				reg[15].I  &= 0xFFFFFFFC;
111.3547 +				armNextPC	= reg[15].I;
111.3548 +				reg[15].I  += 4;
111.3549 +			}
111.3550 +		}
111.3551 +		break;
111.3552 +		CASE_16(0x440)
111.3553 +		// T versions shouldn't be different on GBA
111.3554 +		CASE_16(0x460)
111.3555 +		{
111.3556 +			// STRB Rd, [Rn], -#
111.3557 +			int offset	= opcode & 0xFFF;
111.3558 +			int dest	= (opcode >> 12) & 15;
111.3559 +			int base	= (opcode >> 16) & 15;
111.3560 +			u32 address = reg[base].I;
111.3561 +			CPUWriteByte(address, reg[dest].B.B0);
111.3562 +			reg[base].I = address - offset;
111.3563 +			clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.3564 +		}
111.3565 +		break;
111.3566 +		CASE_16(0x4c0)
111.3567 +		// T versions shouldn't be different on GBA
111.3568 +		CASE_16(0x4e0)
111.3569 +		// STRB Rd, [Rn], #
111.3570 +		{
111.3571 +			int offset	= opcode & 0xFFF;
111.3572 +			int dest	= (opcode >> 12) & 15;
111.3573 +			int base	= (opcode >> 16) & 15;
111.3574 +			u32 address = reg[base].I;
111.3575 +			CPUWriteByte(address, reg[dest].B.B0);
111.3576 +			reg[base].I = address + offset;
111.3577 +			clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.3578 +		}
111.3579 +		break;
111.3580 +		CASE_16(0x540)
111.3581 +		{
111.3582 +			// STRB Rd, [Rn, -#]
111.3583 +			int offset	= opcode & 0xFFF;
111.3584 +			int dest	= (opcode >> 12) & 15;
111.3585 +			int base	= (opcode >> 16) & 15;
111.3586 +			u32 address = reg[base].I - offset;
111.3587 +			CPUWriteByte(address, reg[dest].B.B0);
111.3588 +			clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.3589 +		}
111.3590 +		break;
111.3591 +		CASE_16(0x560)
111.3592 +		{
111.3593 +			// STRB Rd, [Rn, -#]!
111.3594 +			int offset	= opcode & 0xFFF;
111.3595 +			int dest	= (opcode >> 12) & 15;
111.3596 +			int base	= (opcode >> 16) & 15;
111.3597 +			u32 address = reg[base].I - offset;
111.3598 +			reg[base].I = address;
111.3599 +			CPUWriteByte(address, reg[dest].B.B0);
111.3600 +			clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.3601 +		}
111.3602 +		break;
111.3603 +		CASE_16(0x5c0)
111.3604 +		{
111.3605 +			// STRB Rd, [Rn, #]
111.3606 +			int offset	= opcode & 0xFFF;
111.3607 +			int dest	= (opcode >> 12) & 15;
111.3608 +			int base	= (opcode >> 16) & 15;
111.3609 +			u32 address = reg[base].I + offset;
111.3610 +			CPUWriteByte(address, reg[dest].B.B0);
111.3611 +			clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.3612 +		}
111.3613 +		break;
111.3614 +		CASE_16(0x5e0)
111.3615 +		{
111.3616 +			// STRB Rd, [Rn, #]!
111.3617 +			int offset	= opcode & 0xFFF;
111.3618 +			int dest	= (opcode >> 12) & 15;
111.3619 +			int base	= (opcode >> 16) & 15;
111.3620 +			u32 address = reg[base].I + offset;
111.3621 +			reg[base].I = address;
111.3622 +			CPUWriteByte(address, reg[dest].I);
111.3623 +			clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.3624 +		}
111.3625 +		break;
111.3626 +		CASE_16(0x450)
111.3627 +		// T versions shouldn't be different
111.3628 +		CASE_16(0x470)
111.3629 +		{
111.3630 +			// LDRB Rd, [Rn], -#
111.3631 +			int offset	= opcode & 0xFFF;
111.3632 +			int dest	= (opcode >> 12) & 15;
111.3633 +			int base	= (opcode >> 16) & 15;
111.3634 +			u32 address = reg[base].I;
111.3635 +			reg[dest].I = CPUReadByte(address);
111.3636 +			if (dest != base)
111.3637 +				reg[base].I -= offset;
111.3638 +			clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.3639 +		}
111.3640 +		break;
111.3641 +		CASE_16(0x4d0)
111.3642 +		CASE_16(0x4f0) // T versions should not be different
111.3643 +		{
111.3644 +			// LDRB Rd, [Rn], #
111.3645 +			int offset	= opcode & 0xFFF;
111.3646 +			int dest	= (opcode >> 12) & 15;
111.3647 +			int base	= (opcode >> 16) & 15;
111.3648 +			u32 address = reg[base].I;
111.3649 +			reg[dest].I = CPUReadByte(address);
111.3650 +			if (dest != base)
111.3651 +				reg[base].I += offset;
111.3652 +			clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.3653 +		}
111.3654 +		break;
111.3655 +		CASE_16(0x550)
111.3656 +		{
111.3657 +			// LDRB Rd, [Rn, -#]
111.3658 +			int offset	= opcode & 0xFFF;
111.3659 +			int dest	= (opcode >> 12) & 15;
111.3660 +			int base	= (opcode >> 16) & 15;
111.3661 +			u32 address = reg[base].I - offset;
111.3662 +			reg[dest].I = CPUReadByte(address);
111.3663 +			clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.3664 +		}
111.3665 +		break;
111.3666 +		CASE_16(0x570)
111.3667 +		{
111.3668 +			// LDRB Rd, [Rn, -#]!
111.3669 +			int offset	= opcode & 0xFFF;
111.3670 +			int dest	= (opcode >> 12) & 15;
111.3671 +			int base	= (opcode >> 16) & 15;
111.3672 +			u32 address = reg[base].I - offset;
111.3673 +			reg[dest].I = CPUReadByte(address);
111.3674 +			if (dest != base)
111.3675 +				reg[base].I = address;
111.3676 +			clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.3677 +		}
111.3678 +		break;
111.3679 +		CASE_16(0x5d0)
111.3680 +		{
111.3681 +			// LDRB Rd, [Rn, #]
111.3682 +			int offset	= opcode & 0xFFF;
111.3683 +			int dest	= (opcode >> 12) & 15;
111.3684 +			int base	= (opcode >> 16) & 15;
111.3685 +			u32 address = reg[base].I + offset;
111.3686 +			reg[dest].I = CPUReadByte(address);
111.3687 +			clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.3688 +		}
111.3689 +		break;
111.3690 +		CASE_16(0x5f0)
111.3691 +		{
111.3692 +			// LDRB Rd, [Rn, #]!
111.3693 +			int offset	= opcode & 0xFFF;
111.3694 +			int dest	= (opcode >> 12) & 15;
111.3695 +			int base	= (opcode >> 16) & 15;
111.3696 +			u32 address = reg[base].I + offset;
111.3697 +			reg[dest].I = CPUReadByte(address);
111.3698 +			if (dest != base)
111.3699 +				reg[base].I = address;
111.3700 +			clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.3701 +		}
111.3702 +		break;
111.3703 +	case 0x600:
111.3704 +	case 0x608:
111.3705 +	// T versions are the same
111.3706 +	case 0x620:
111.3707 +	case 0x628:
111.3708 +	{
111.3709 +		// STR Rd, [Rn], -Rm, LSL #
111.3710 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.3711 +		int dest	= (opcode >> 12) & 15;
111.3712 +		int base	= (opcode >> 16) & 15;
111.3713 +		u32 address = reg[base].I;
111.3714 +		CPUWriteMemory(address, reg[dest].I);
111.3715 +		reg[base].I = address - offset;
111.3716 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3717 +	}
111.3718 +	break;
111.3719 +	case 0x602:
111.3720 +	case 0x60a:
111.3721 +	// T versions are the same
111.3722 +	case 0x622:
111.3723 +	case 0x62a:
111.3724 +	{
111.3725 +		// STR Rd, [Rn], -Rm, LSR #
111.3726 +		int shift	= (opcode >> 7) & 31;
111.3727 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.3728 +		int dest	= (opcode >> 12) & 15;
111.3729 +		int base	= (opcode >> 16) & 15;
111.3730 +		u32 address = reg[base].I;
111.3731 +		CPUWriteMemory(address, reg[dest].I);
111.3732 +		reg[base].I = address - offset;
111.3733 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3734 +	}
111.3735 +	break;
111.3736 +	case 0x604:
111.3737 +	case 0x60c:
111.3738 +	// T versions are the same
111.3739 +	case 0x624:
111.3740 +	case 0x62c:
111.3741 +	{
111.3742 +		// STR Rd, [Rn], -Rm, ASR #
111.3743 +		int shift = (opcode >> 7) & 31;
111.3744 +		int offset;
111.3745 +		if (shift)
111.3746 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.3747 +		else if (reg[opcode & 15].I & 0x80000000)
111.3748 +			offset = 0xFFFFFFFF;
111.3749 +		else
111.3750 +			offset = 0;
111.3751 +		int dest	= (opcode >> 12) & 15;
111.3752 +		int base	= (opcode >> 16) & 15;
111.3753 +		u32 address = reg[base].I;
111.3754 +		CPUWriteMemory(address, reg[dest].I);
111.3755 +		reg[base].I = address - offset;
111.3756 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3757 +	}
111.3758 +	break;
111.3759 +	case 0x606:
111.3760 +	case 0x60e:
111.3761 +	// T versions are the same
111.3762 +	case 0x626:
111.3763 +	case 0x62e:
111.3764 +	{
111.3765 +		// STR Rd, [Rn], -Rm, ROR #
111.3766 +		int shift = (opcode >> 7) & 31;
111.3767 +		u32 value = reg[opcode & 15].I;
111.3768 +		if (shift)
111.3769 +		{
111.3770 +			ROR_VALUE;
111.3771 +		}
111.3772 +		else
111.3773 +		{
111.3774 +			RCR_VALUE;
111.3775 +		}
111.3776 +		int dest	= (opcode >> 12) & 15;
111.3777 +		int base	= (opcode >> 16) & 15;
111.3778 +		u32 address = reg[base].I;
111.3779 +		CPUWriteMemory(address, reg[dest].I);
111.3780 +		reg[base].I = address - value;
111.3781 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3782 +	}
111.3783 +	break;
111.3784 +	case 0x680:
111.3785 +	case 0x688:
111.3786 +	// T versions are the same
111.3787 +	case 0x6a0:
111.3788 +	case 0x6a8:
111.3789 +	{
111.3790 +		// STR Rd, [Rn], Rm, LSL #
111.3791 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.3792 +		int dest	= (opcode >> 12) & 15;
111.3793 +		int base	= (opcode >> 16) & 15;
111.3794 +		u32 address = reg[base].I;
111.3795 +		CPUWriteMemory(address, reg[dest].I);
111.3796 +		reg[base].I = address + offset;
111.3797 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3798 +	}
111.3799 +	break;
111.3800 +	case 0x682:
111.3801 +	case 0x68a:
111.3802 +	// T versions are the same
111.3803 +	case 0x6a2:
111.3804 +	case 0x6aa:
111.3805 +	{
111.3806 +		// STR Rd, [Rn], Rm, LSR #
111.3807 +		int shift	= (opcode >> 7) & 31;
111.3808 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.3809 +		int dest	= (opcode >> 12) & 15;
111.3810 +		int base	= (opcode >> 16) & 15;
111.3811 +		u32 address = reg[base].I;
111.3812 +		CPUWriteMemory(address, reg[dest].I);
111.3813 +		reg[base].I = address + offset;
111.3814 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3815 +	}
111.3816 +	break;
111.3817 +	case 0x684:
111.3818 +	case 0x68c:
111.3819 +	// T versions are the same
111.3820 +	case 0x6a4:
111.3821 +	case 0x6ac:
111.3822 +	{
111.3823 +		// STR Rd, [Rn], Rm, ASR #
111.3824 +		int shift = (opcode >> 7) & 31;
111.3825 +		int offset;
111.3826 +		if (shift)
111.3827 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.3828 +		else if (reg[opcode & 15].I & 0x80000000)
111.3829 +			offset = 0xFFFFFFFF;
111.3830 +		else
111.3831 +			offset = 0;
111.3832 +		int dest	= (opcode >> 12) & 15;
111.3833 +		int base	= (opcode >> 16) & 15;
111.3834 +		u32 address = reg[base].I;
111.3835 +		CPUWriteMemory(address, reg[dest].I);
111.3836 +		reg[base].I = address + offset;
111.3837 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3838 +	}
111.3839 +	break;
111.3840 +	case 0x686:
111.3841 +	case 0x68e:
111.3842 +	// T versions are the same
111.3843 +	case 0x6a6:
111.3844 +	case 0x6ae:
111.3845 +	{
111.3846 +		// STR Rd, [Rn], Rm, ROR #
111.3847 +		int shift = (opcode >> 7) & 31;
111.3848 +		u32 value = reg[opcode & 15].I;
111.3849 +		if (shift)
111.3850 +		{
111.3851 +			ROR_VALUE;
111.3852 +		}
111.3853 +		else
111.3854 +		{
111.3855 +			RCR_VALUE;
111.3856 +		}
111.3857 +		int dest	= (opcode >> 12) & 15;
111.3858 +		int base	= (opcode >> 16) & 15;
111.3859 +		u32 address = reg[base].I;
111.3860 +		CPUWriteMemory(address, reg[dest].I);
111.3861 +		reg[base].I = address + value;
111.3862 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3863 +	}
111.3864 +	break;
111.3865 +	case 0x700:
111.3866 +	case 0x708:
111.3867 +	{
111.3868 +		// STR Rd, [Rn, -Rm, LSL #]
111.3869 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.3870 +		int dest	= (opcode >> 12) & 15;
111.3871 +		int base	= (opcode >> 16) & 15;
111.3872 +		u32 address = reg[base].I - offset;
111.3873 +		CPUWriteMemory(address, reg[dest].I);
111.3874 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3875 +	}
111.3876 +	break;
111.3877 +	case 0x702:
111.3878 +	case 0x70a:
111.3879 +	{
111.3880 +		// STR Rd, [Rn, -Rm, LSR #]
111.3881 +		int shift	= (opcode >> 7) & 31;
111.3882 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.3883 +		int dest	= (opcode >> 12) & 15;
111.3884 +		int base	= (opcode >> 16) & 15;
111.3885 +		u32 address = reg[base].I - offset;
111.3886 +		CPUWriteMemory(address, reg[dest].I);
111.3887 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3888 +	}
111.3889 +	break;
111.3890 +	case 0x704:
111.3891 +	case 0x70c:
111.3892 +	{
111.3893 +		// STR Rd, [Rn, -Rm, ASR #]
111.3894 +		int shift = (opcode >> 7) & 31;
111.3895 +		int offset;
111.3896 +		if (shift)
111.3897 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.3898 +		else if (reg[opcode & 15].I & 0x80000000)
111.3899 +			offset = 0xFFFFFFFF;
111.3900 +		else
111.3901 +			offset = 0;
111.3902 +		int dest	= (opcode >> 12) & 15;
111.3903 +		int base	= (opcode >> 16) & 15;
111.3904 +		u32 address = reg[base].I - offset;
111.3905 +		CPUWriteMemory(address, reg[dest].I);
111.3906 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3907 +	}
111.3908 +	break;
111.3909 +	case 0x706:
111.3910 +	case 0x70e:
111.3911 +	{
111.3912 +		// STR Rd, [Rn, -Rm, ROR #]
111.3913 +		int shift = (opcode >> 7) & 31;
111.3914 +		u32 value = reg[opcode & 15].I;
111.3915 +		if (shift)
111.3916 +		{
111.3917 +			ROR_VALUE;
111.3918 +		}
111.3919 +		else
111.3920 +		{
111.3921 +			RCR_VALUE;
111.3922 +		}
111.3923 +		int dest	= (opcode >> 12) & 15;
111.3924 +		int base	= (opcode >> 16) & 15;
111.3925 +		u32 address = reg[base].I - value;
111.3926 +		CPUWriteMemory(address, reg[dest].I);
111.3927 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3928 +	}
111.3929 +	break;
111.3930 +	case 0x720:
111.3931 +	case 0x728:
111.3932 +	{
111.3933 +		// STR Rd, [Rn, -Rm, LSL #]!
111.3934 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.3935 +		int dest	= (opcode >> 12) & 15;
111.3936 +		int base	= (opcode >> 16) & 15;
111.3937 +		u32 address = reg[base].I - offset;
111.3938 +		reg[base].I = address;
111.3939 +		CPUWriteMemory(address, reg[dest].I);
111.3940 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3941 +	}
111.3942 +	break;
111.3943 +	case 0x722:
111.3944 +	case 0x72a:
111.3945 +	{
111.3946 +		// STR Rd, [Rn, -Rm, LSR #]!
111.3947 +		int shift	= (opcode >> 7) & 31;
111.3948 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.3949 +		int dest	= (opcode >> 12) & 15;
111.3950 +		int base	= (opcode >> 16) & 15;
111.3951 +		u32 address = reg[base].I - offset;
111.3952 +		reg[base].I = address;
111.3953 +		CPUWriteMemory(address, reg[dest].I);
111.3954 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3955 +	}
111.3956 +	break;
111.3957 +	case 0x724:
111.3958 +	case 0x72c:
111.3959 +	{
111.3960 +		// STR Rd, [Rn, -Rm, ASR #]!
111.3961 +		int shift = (opcode >> 7) & 31;
111.3962 +		int offset;
111.3963 +		if (shift)
111.3964 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.3965 +		else if (reg[opcode & 15].I & 0x80000000)
111.3966 +			offset = 0xFFFFFFFF;
111.3967 +		else
111.3968 +			offset = 0;
111.3969 +		int dest	= (opcode >> 12) & 15;
111.3970 +		int base	= (opcode >> 16) & 15;
111.3971 +		u32 address = reg[base].I - offset;
111.3972 +		reg[base].I = address;
111.3973 +		CPUWriteMemory(address, reg[dest].I);
111.3974 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3975 +	}
111.3976 +	break;
111.3977 +	case 0x726:
111.3978 +	case 0x72e:
111.3979 +	{
111.3980 +		// STR Rd, [Rn, -Rm, ROR #]!
111.3981 +		int shift = (opcode >> 7) & 31;
111.3982 +		u32 value = reg[opcode & 15].I;
111.3983 +		if (shift)
111.3984 +		{
111.3985 +			ROR_VALUE;
111.3986 +		}
111.3987 +		else
111.3988 +		{
111.3989 +			RCR_VALUE;
111.3990 +		}
111.3991 +		int dest	= (opcode >> 12) & 15;
111.3992 +		int base	= (opcode >> 16) & 15;
111.3993 +		u32 address = reg[base].I - value;
111.3994 +		reg[base].I = address;
111.3995 +		CPUWriteMemory(address, reg[dest].I);
111.3996 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.3997 +	}
111.3998 +	break;
111.3999 +	case 0x780:
111.4000 +	case 0x788:
111.4001 +	{
111.4002 +		// STR Rd, [Rn, Rm, LSL #]
111.4003 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.4004 +		int dest	= (opcode >> 12) & 15;
111.4005 +		int base	= (opcode >> 16) & 15;
111.4006 +		u32 address = reg[base].I + offset;
111.4007 +		CPUWriteMemory(address, reg[dest].I);
111.4008 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.4009 +	}
111.4010 +	break;
111.4011 +	case 0x782:
111.4012 +	case 0x78a:
111.4013 +	{
111.4014 +		// STR Rd, [Rn, Rm, LSR #]
111.4015 +		int shift	= (opcode >> 7) & 31;
111.4016 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.4017 +		int dest	= (opcode >> 12) & 15;
111.4018 +		int base	= (opcode >> 16) & 15;
111.4019 +		u32 address = reg[base].I + offset;
111.4020 +		CPUWriteMemory(address, reg[dest].I);
111.4021 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.4022 +	}
111.4023 +	break;
111.4024 +	case 0x784:
111.4025 +	case 0x78c:
111.4026 +	{
111.4027 +		// STR Rd, [Rn, Rm, ASR #]
111.4028 +		int shift = (opcode >> 7) & 31;
111.4029 +		int offset;
111.4030 +		if (shift)
111.4031 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.4032 +		else if (reg[opcode & 15].I & 0x80000000)
111.4033 +			offset = 0xFFFFFFFF;
111.4034 +		else
111.4035 +			offset = 0;
111.4036 +		int dest	= (opcode >> 12) & 15;
111.4037 +		int base	= (opcode >> 16) & 15;
111.4038 +		u32 address = reg[base].I + offset;
111.4039 +		CPUWriteMemory(address, reg[dest].I);
111.4040 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.4041 +	}
111.4042 +	break;
111.4043 +	case 0x786:
111.4044 +	case 0x78e:
111.4045 +	{
111.4046 +		// STR Rd, [Rn, Rm, ROR #]
111.4047 +		int shift = (opcode >> 7) & 31;
111.4048 +		u32 value = reg[opcode & 15].I;
111.4049 +		if (shift)
111.4050 +		{
111.4051 +			ROR_VALUE;
111.4052 +		}
111.4053 +		else
111.4054 +		{
111.4055 +			RCR_VALUE;
111.4056 +		}
111.4057 +		int dest	= (opcode >> 12) & 15;
111.4058 +		int base	= (opcode >> 16) & 15;
111.4059 +		u32 address = reg[base].I + value;
111.4060 +		CPUWriteMemory(address, reg[dest].I);
111.4061 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.4062 +	}
111.4063 +	break;
111.4064 +	case 0x7a0:
111.4065 +	case 0x7a8:
111.4066 +	{
111.4067 +		// STR Rd, [Rn, Rm, LSL #]!
111.4068 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.4069 +		int dest	= (opcode >> 12) & 15;
111.4070 +		int base	= (opcode >> 16) & 15;
111.4071 +		u32 address = reg[base].I + offset;
111.4072 +		reg[base].I = address;
111.4073 +		CPUWriteMemory(address, reg[dest].I);
111.4074 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.4075 +	}
111.4076 +	break;
111.4077 +	case 0x7a2:
111.4078 +	case 0x7aa:
111.4079 +	{
111.4080 +		// STR Rd, [Rn, Rm, LSR #]!
111.4081 +		int shift	= (opcode >> 7) & 31;
111.4082 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.4083 +		int dest	= (opcode >> 12) & 15;
111.4084 +		int base	= (opcode >> 16) & 15;
111.4085 +		u32 address = reg[base].I + offset;
111.4086 +		reg[base].I = address;
111.4087 +		CPUWriteMemory(address, reg[dest].I);
111.4088 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.4089 +	}
111.4090 +	break;
111.4091 +	case 0x7a4:
111.4092 +	case 0x7ac:
111.4093 +	{
111.4094 +		// STR Rd, [Rn, Rm, ASR #]!
111.4095 +		int shift = (opcode >> 7) & 31;
111.4096 +		int offset;
111.4097 +		if (shift)
111.4098 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.4099 +		else if (reg[opcode & 15].I & 0x80000000)
111.4100 +			offset = 0xFFFFFFFF;
111.4101 +		else
111.4102 +			offset = 0;
111.4103 +		int dest	= (opcode >> 12) & 15;
111.4104 +		int base	= (opcode >> 16) & 15;
111.4105 +		u32 address = reg[base].I + offset;
111.4106 +		reg[base].I = address;
111.4107 +		CPUWriteMemory(address, reg[dest].I);
111.4108 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.4109 +	}
111.4110 +	break;
111.4111 +	case 0x7a6:
111.4112 +	case 0x7ae:
111.4113 +	{
111.4114 +		// STR Rd, [Rn, Rm, ROR #]!
111.4115 +		int shift = (opcode >> 7) & 31;
111.4116 +		u32 value = reg[opcode & 15].I;
111.4117 +		if (shift)
111.4118 +		{
111.4119 +			ROR_VALUE;
111.4120 +		}
111.4121 +		else
111.4122 +		{
111.4123 +			RCR_VALUE;
111.4124 +		}
111.4125 +		int dest	= (opcode >> 12) & 15;
111.4126 +		int base	= (opcode >> 16) & 15;
111.4127 +		u32 address = reg[base].I + value;
111.4128 +		reg[base].I = address;
111.4129 +		CPUWriteMemory(address, reg[dest].I);
111.4130 +		clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.4131 +	}
111.4132 +	break;
111.4133 +	case 0x610:
111.4134 +	case 0x618:
111.4135 +	// T versions are the same
111.4136 +	case 0x630:
111.4137 +	case 0x638:
111.4138 +	{
111.4139 +		// LDR Rd, [Rn], -Rm, LSL #
111.4140 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.4141 +		int dest	= (opcode >> 12) & 15;
111.4142 +		int base	= (opcode >> 16) & 15;
111.4143 +		u32 address = reg[base].I;
111.4144 +		reg[dest].I = CPUReadMemory(address);
111.4145 +		if (dest != base)
111.4146 +			reg[base].I = address - offset;
111.4147 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4148 +		if (dest == 15)
111.4149 +		{
111.4150 +			clockTicks += 2;
111.4151 +			reg[15].I  &= 0xFFFFFFFC;
111.4152 +			armNextPC	= reg[15].I;
111.4153 +			reg[15].I  += 4;
111.4154 +		}
111.4155 +	}
111.4156 +	break;
111.4157 +	case 0x612:
111.4158 +	case 0x61a:
111.4159 +	// T versions are the same
111.4160 +	case 0x632:
111.4161 +	case 0x63a:
111.4162 +	{
111.4163 +		// LDR Rd, [Rn], -Rm, LSR #
111.4164 +		int shift	= (opcode >> 7) & 31;
111.4165 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.4166 +		int dest	= (opcode >> 12) & 15;
111.4167 +		int base	= (opcode >> 16) & 15;
111.4168 +		u32 address = reg[base].I;
111.4169 +		reg[dest].I = CPUReadMemory(address);
111.4170 +		if (dest != base)
111.4171 +			reg[base].I = address - offset;
111.4172 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4173 +		if (dest == 15)
111.4174 +		{
111.4175 +			clockTicks += 2;
111.4176 +			reg[15].I  &= 0xFFFFFFFC;
111.4177 +			armNextPC	= reg[15].I;
111.4178 +			reg[15].I  += 4;
111.4179 +		}
111.4180 +	}
111.4181 +	break;
111.4182 +	case 0x614:
111.4183 +	case 0x61c:
111.4184 +	// T versions are the same
111.4185 +	case 0x634:
111.4186 +	case 0x63c:
111.4187 +	{
111.4188 +		// LDR Rd, [Rn], -Rm, ASR #
111.4189 +		int shift = (opcode >> 7) & 31;
111.4190 +		int offset;
111.4191 +		if (shift)
111.4192 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.4193 +		else if (reg[opcode & 15].I & 0x80000000)
111.4194 +			offset = 0xFFFFFFFF;
111.4195 +		else
111.4196 +			offset = 0;
111.4197 +		int dest	= (opcode >> 12) & 15;
111.4198 +		int base	= (opcode >> 16) & 15;
111.4199 +		u32 address = reg[base].I;
111.4200 +		reg[dest].I = CPUReadMemory(address);
111.4201 +		if (dest != base)
111.4202 +			reg[base].I = address - offset;
111.4203 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4204 +		if (dest == 15)
111.4205 +		{
111.4206 +			clockTicks += 2;
111.4207 +			reg[15].I  &= 0xFFFFFFFC;
111.4208 +			armNextPC	= reg[15].I;
111.4209 +			reg[15].I  += 4;
111.4210 +		}
111.4211 +	}
111.4212 +	break;
111.4213 +	case 0x616:
111.4214 +	case 0x61e:
111.4215 +	// T versions are the same
111.4216 +	case 0x636:
111.4217 +	case 0x63e:
111.4218 +	{
111.4219 +		// LDR Rd, [Rn], -Rm, ROR #
111.4220 +		int shift = (opcode >> 7) & 31;
111.4221 +		u32 value = reg[opcode & 15].I;
111.4222 +		if (shift)
111.4223 +		{
111.4224 +			ROR_VALUE;
111.4225 +		}
111.4226 +		else
111.4227 +		{
111.4228 +			RCR_VALUE;
111.4229 +		}
111.4230 +		int dest	= (opcode >> 12) & 15;
111.4231 +		int base	= (opcode >> 16) & 15;
111.4232 +		u32 address = reg[base].I;
111.4233 +		reg[dest].I = CPUReadMemory(address);
111.4234 +		if (dest != base)
111.4235 +			reg[base].I = address - value;
111.4236 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4237 +		if (dest == 15)
111.4238 +		{
111.4239 +			clockTicks += 2;
111.4240 +			reg[15].I  &= 0xFFFFFFFC;
111.4241 +			armNextPC	= reg[15].I;
111.4242 +			reg[15].I  += 4;
111.4243 +		}
111.4244 +	}
111.4245 +	break;
111.4246 +	case 0x690:
111.4247 +	case 0x698:
111.4248 +	// T versions are the same
111.4249 +	case 0x6b0:
111.4250 +	case 0x6b8:
111.4251 +	{
111.4252 +		// LDR Rd, [Rn], Rm, LSL #
111.4253 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.4254 +		int dest	= (opcode >> 12) & 15;
111.4255 +		int base	= (opcode >> 16) & 15;
111.4256 +		u32 address = reg[base].I;
111.4257 +		reg[dest].I = CPUReadMemory(address);
111.4258 +		if (dest != base)
111.4259 +			reg[base].I = address + offset;
111.4260 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4261 +		if (dest == 15)
111.4262 +		{
111.4263 +			clockTicks += 2;
111.4264 +			reg[15].I  &= 0xFFFFFFFC;
111.4265 +			armNextPC	= reg[15].I;
111.4266 +			reg[15].I  += 4;
111.4267 +		}
111.4268 +	}
111.4269 +	break;
111.4270 +	case 0x692:
111.4271 +	case 0x69a:
111.4272 +	// T versions are the same
111.4273 +	case 0x6b2:
111.4274 +	case 0x6ba:
111.4275 +	{
111.4276 +		// LDR Rd, [Rn], Rm, LSR #
111.4277 +		int shift	= (opcode >> 7) & 31;
111.4278 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.4279 +		int dest	= (opcode >> 12) & 15;
111.4280 +		int base	= (opcode >> 16) & 15;
111.4281 +		u32 address = reg[base].I;
111.4282 +		reg[dest].I = CPUReadMemory(address);
111.4283 +		if (dest != base)
111.4284 +			reg[base].I = address + offset;
111.4285 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4286 +		if (dest == 15)
111.4287 +		{
111.4288 +			clockTicks += 2;
111.4289 +			reg[15].I  &= 0xFFFFFFFC;
111.4290 +			armNextPC	= reg[15].I;
111.4291 +			reg[15].I  += 4;
111.4292 +		}
111.4293 +	}
111.4294 +	break;
111.4295 +	case 0x694:
111.4296 +	case 0x69c:
111.4297 +	// T versions are the same
111.4298 +	case 0x6b4:
111.4299 +	case 0x6bc:
111.4300 +	{
111.4301 +		// LDR Rd, [Rn], Rm, ASR #
111.4302 +		int shift = (opcode >> 7) & 31;
111.4303 +		int offset;
111.4304 +		if (shift)
111.4305 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.4306 +		else if (reg[opcode & 15].I & 0x80000000)
111.4307 +			offset = 0xFFFFFFFF;
111.4308 +		else
111.4309 +			offset = 0;
111.4310 +		int dest	= (opcode >> 12) & 15;
111.4311 +		int base	= (opcode >> 16) & 15;
111.4312 +		u32 address = reg[base].I;
111.4313 +		reg[dest].I = CPUReadMemory(address);
111.4314 +		if (dest != base)
111.4315 +			reg[base].I = address + offset;
111.4316 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4317 +		if (dest == 15)
111.4318 +		{
111.4319 +			clockTicks += 2;
111.4320 +			reg[15].I  &= 0xFFFFFFFC;
111.4321 +			armNextPC	= reg[15].I;
111.4322 +			reg[15].I  += 4;
111.4323 +		}
111.4324 +	}
111.4325 +	break;
111.4326 +	case 0x696:
111.4327 +	case 0x69e:
111.4328 +	// T versions are the same
111.4329 +	case 0x6b6:
111.4330 +	case 0x6be:
111.4331 +	{
111.4332 +		// LDR Rd, [Rn], Rm, ROR #
111.4333 +		int shift = (opcode >> 7) & 31;
111.4334 +		u32 value = reg[opcode & 15].I;
111.4335 +		if (shift)
111.4336 +		{
111.4337 +			ROR_VALUE;
111.4338 +		}
111.4339 +		else
111.4340 +		{
111.4341 +			RCR_VALUE;
111.4342 +		}
111.4343 +		int dest	= (opcode >> 12) & 15;
111.4344 +		int base	= (opcode >> 16) & 15;
111.4345 +		u32 address = reg[base].I;
111.4346 +		reg[dest].I = CPUReadMemory(address);
111.4347 +		if (dest != base)
111.4348 +			reg[base].I = address + value;
111.4349 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4350 +		if (dest == 15)
111.4351 +		{
111.4352 +			clockTicks += 2;
111.4353 +			reg[15].I  &= 0xFFFFFFFC;
111.4354 +			armNextPC	= reg[15].I;
111.4355 +			reg[15].I  += 4;
111.4356 +		}
111.4357 +	}
111.4358 +	break;
111.4359 +	case 0x710:
111.4360 +	case 0x718:
111.4361 +	{
111.4362 +		// LDR Rd, [Rn, -Rm, LSL #]
111.4363 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.4364 +		int dest	= (opcode >> 12) & 15;
111.4365 +		int base	= (opcode >> 16) & 15;
111.4366 +		u32 address = reg[base].I - offset;
111.4367 +		reg[dest].I = CPUReadMemory(address);
111.4368 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4369 +		if (dest == 15)
111.4370 +		{
111.4371 +			clockTicks += 2;
111.4372 +			reg[15].I  &= 0xFFFFFFFC;
111.4373 +			armNextPC	= reg[15].I;
111.4374 +			reg[15].I  += 4;
111.4375 +		}
111.4376 +	}
111.4377 +	break;
111.4378 +	case 0x712:
111.4379 +	case 0x71a:
111.4380 +	{
111.4381 +		// LDR Rd, [Rn, -Rm, LSR #]
111.4382 +		int shift	= (opcode >> 7) & 31;
111.4383 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.4384 +		int dest	= (opcode >> 12) & 15;
111.4385 +		int base	= (opcode >> 16) & 15;
111.4386 +		u32 address = reg[base].I - offset;
111.4387 +		reg[dest].I = CPUReadMemory(address);
111.4388 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4389 +		if (dest == 15)
111.4390 +		{
111.4391 +			clockTicks += 2;
111.4392 +			reg[15].I  &= 0xFFFFFFFC;
111.4393 +			armNextPC	= reg[15].I;
111.4394 +			reg[15].I  += 4;
111.4395 +		}
111.4396 +	}
111.4397 +	break;
111.4398 +	case 0x714:
111.4399 +	case 0x71c:
111.4400 +	{
111.4401 +		// LDR Rd, [Rn, -Rm, ASR #]
111.4402 +		int shift = (opcode >> 7) & 31;
111.4403 +		int offset;
111.4404 +		if (shift)
111.4405 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.4406 +		else if (reg[opcode & 15].I & 0x80000000)
111.4407 +			offset = 0xFFFFFFFF;
111.4408 +		else
111.4409 +			offset = 0;
111.4410 +		int dest	= (opcode >> 12) & 15;
111.4411 +		int base	= (opcode >> 16) & 15;
111.4412 +		u32 address = reg[base].I - offset;
111.4413 +		reg[dest].I = CPUReadMemory(address);
111.4414 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4415 +		if (dest == 15)
111.4416 +		{
111.4417 +			clockTicks += 2;
111.4418 +			reg[15].I  &= 0xFFFFFFFC;
111.4419 +			armNextPC	= reg[15].I;
111.4420 +			reg[15].I  += 4;
111.4421 +		}
111.4422 +	}
111.4423 +	break;
111.4424 +	case 0x716:
111.4425 +	case 0x71e:
111.4426 +	{
111.4427 +		// LDR Rd, [Rn, -Rm, ROR #]
111.4428 +		int shift = (opcode >> 7) & 31;
111.4429 +		u32 value = reg[opcode & 15].I;
111.4430 +		if (shift)
111.4431 +		{
111.4432 +			ROR_VALUE;
111.4433 +		}
111.4434 +		else
111.4435 +		{
111.4436 +			RCR_VALUE;
111.4437 +		}
111.4438 +		int dest	= (opcode >> 12) & 15;
111.4439 +		int base	= (opcode >> 16) & 15;
111.4440 +		u32 address = reg[base].I - value;
111.4441 +		reg[dest].I = CPUReadMemory(address);
111.4442 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4443 +		if (dest == 15)
111.4444 +		{
111.4445 +			clockTicks += 2;
111.4446 +			reg[15].I  &= 0xFFFFFFFC;
111.4447 +			armNextPC	= reg[15].I;
111.4448 +			reg[15].I  += 4;
111.4449 +		}
111.4450 +	}
111.4451 +	break;
111.4452 +	case 0x730:
111.4453 +	case 0x738:
111.4454 +	{
111.4455 +		// LDR Rd, [Rn, -Rm, LSL #]!
111.4456 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.4457 +		int dest	= (opcode >> 12) & 15;
111.4458 +		int base	= (opcode >> 16) & 15;
111.4459 +		u32 address = reg[base].I - offset;
111.4460 +		reg[dest].I = CPUReadMemory(address);
111.4461 +		if (dest != base)
111.4462 +			reg[base].I = address;
111.4463 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4464 +		if (dest == 15)
111.4465 +		{
111.4466 +			clockTicks += 2;
111.4467 +			reg[15].I  &= 0xFFFFFFFC;
111.4468 +			armNextPC	= reg[15].I;
111.4469 +			reg[15].I  += 4;
111.4470 +		}
111.4471 +	}
111.4472 +	break;
111.4473 +	case 0x732:
111.4474 +	case 0x73a:
111.4475 +	{
111.4476 +		// LDR Rd, [Rn, -Rm, LSR #]!
111.4477 +		int shift	= (opcode >> 7) & 31;
111.4478 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.4479 +		int dest	= (opcode >> 12) & 15;
111.4480 +		int base	= (opcode >> 16) & 15;
111.4481 +		u32 address = reg[base].I - offset;
111.4482 +		reg[dest].I = CPUReadMemory(address);
111.4483 +		if (dest != base)
111.4484 +			reg[base].I = address;
111.4485 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4486 +		if (dest == 15)
111.4487 +		{
111.4488 +			clockTicks += 2;
111.4489 +			reg[15].I  &= 0xFFFFFFFC;
111.4490 +			armNextPC	= reg[15].I;
111.4491 +			reg[15].I  += 4;
111.4492 +		}
111.4493 +	}
111.4494 +	break;
111.4495 +	case 0x734:
111.4496 +	case 0x73c:
111.4497 +	{
111.4498 +		// LDR Rd, [Rn, -Rm, ASR #]!
111.4499 +		int shift = (opcode >> 7) & 31;
111.4500 +		int offset;
111.4501 +		if (shift)
111.4502 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.4503 +		else if (reg[opcode & 15].I & 0x80000000)
111.4504 +			offset = 0xFFFFFFFF;
111.4505 +		else
111.4506 +			offset = 0;
111.4507 +		int dest	= (opcode >> 12) & 15;
111.4508 +		int base	= (opcode >> 16) & 15;
111.4509 +		u32 address = reg[base].I - offset;
111.4510 +		reg[dest].I = CPUReadMemory(address);
111.4511 +		if (dest != base)
111.4512 +			reg[base].I = address;
111.4513 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4514 +		if (dest == 15)
111.4515 +		{
111.4516 +			clockTicks += 2;
111.4517 +			reg[15].I  &= 0xFFFFFFFC;
111.4518 +			armNextPC	= reg[15].I;
111.4519 +			reg[15].I  += 4;
111.4520 +		}
111.4521 +	}
111.4522 +	break;
111.4523 +	case 0x736:
111.4524 +	case 0x73e:
111.4525 +	{
111.4526 +		// LDR Rd, [Rn, -Rm, ROR #]!
111.4527 +		int shift = (opcode >> 7) & 31;
111.4528 +		u32 value = reg[opcode & 15].I;
111.4529 +		if (shift)
111.4530 +		{
111.4531 +			ROR_VALUE;
111.4532 +		}
111.4533 +		else
111.4534 +		{
111.4535 +			RCR_VALUE;
111.4536 +		}
111.4537 +		int dest	= (opcode >> 12) & 15;
111.4538 +		int base	= (opcode >> 16) & 15;
111.4539 +		u32 address = reg[base].I - value;
111.4540 +		reg[dest].I = CPUReadMemory(address);
111.4541 +		if (dest != base)
111.4542 +			reg[base].I = address;
111.4543 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4544 +		if (dest == 15)
111.4545 +		{
111.4546 +			clockTicks += 2;
111.4547 +			reg[15].I  &= 0xFFFFFFFC;
111.4548 +			armNextPC	= reg[15].I;
111.4549 +			reg[15].I  += 4;
111.4550 +		}
111.4551 +	}
111.4552 +	break;
111.4553 +	case 0x790:
111.4554 +	case 0x798:
111.4555 +	{
111.4556 +		// LDR Rd, [Rn, Rm, LSL #]
111.4557 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.4558 +		int dest	= (opcode >> 12) & 15;
111.4559 +		int base	= (opcode >> 16) & 15;
111.4560 +		u32 address = reg[base].I + offset;
111.4561 +		reg[dest].I = CPUReadMemory(address);
111.4562 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4563 +		if (dest == 15)
111.4564 +		{
111.4565 +			clockTicks += 2;
111.4566 +			reg[15].I  &= 0xFFFFFFFC;
111.4567 +			armNextPC	= reg[15].I;
111.4568 +			reg[15].I  += 4;
111.4569 +		}
111.4570 +	}
111.4571 +	break;
111.4572 +	case 0x792:
111.4573 +	case 0x79a:
111.4574 +	{
111.4575 +		// LDR Rd, [Rn, Rm, LSR #]
111.4576 +		int shift	= (opcode >> 7) & 31;
111.4577 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.4578 +		int dest	= (opcode >> 12) & 15;
111.4579 +		int base	= (opcode >> 16) & 15;
111.4580 +		u32 address = reg[base].I + offset;
111.4581 +		reg[dest].I = CPUReadMemory(address);
111.4582 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4583 +		if (dest == 15)
111.4584 +		{
111.4585 +			clockTicks += 2;
111.4586 +			reg[15].I  &= 0xFFFFFFFC;
111.4587 +			armNextPC	= reg[15].I;
111.4588 +			reg[15].I  += 4;
111.4589 +		}
111.4590 +	}
111.4591 +	break;
111.4592 +	case 0x794:
111.4593 +	case 0x79c:
111.4594 +	{
111.4595 +		// LDR Rd, [Rn, Rm, ASR #]
111.4596 +		int shift = (opcode >> 7) & 31;
111.4597 +		int offset;
111.4598 +		if (shift)
111.4599 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.4600 +		else if (reg[opcode & 15].I & 0x80000000)
111.4601 +			offset = 0xFFFFFFFF;
111.4602 +		else
111.4603 +			offset = 0;
111.4604 +		int dest	= (opcode >> 12) & 15;
111.4605 +		int base	= (opcode >> 16) & 15;
111.4606 +		u32 address = reg[base].I + offset;
111.4607 +		reg[dest].I = CPUReadMemory(address);
111.4608 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4609 +		if (dest == 15)
111.4610 +		{
111.4611 +			clockTicks += 2;
111.4612 +			reg[15].I  &= 0xFFFFFFFC;
111.4613 +			armNextPC	= reg[15].I;
111.4614 +			reg[15].I  += 4;
111.4615 +		}
111.4616 +	}
111.4617 +	break;
111.4618 +	case 0x796:
111.4619 +	case 0x79e:
111.4620 +	{
111.4621 +		// LDR Rd, [Rn, Rm, ROR #]
111.4622 +		int shift = (opcode >> 7) & 31;
111.4623 +		u32 value = reg[opcode & 15].I;
111.4624 +		if (shift)
111.4625 +		{
111.4626 +			ROR_VALUE;
111.4627 +		}
111.4628 +		else
111.4629 +		{
111.4630 +			RCR_VALUE;
111.4631 +		}
111.4632 +		int dest	= (opcode >> 12) & 15;
111.4633 +		int base	= (opcode >> 16) & 15;
111.4634 +		u32 address = reg[base].I + value;
111.4635 +		reg[dest].I = CPUReadMemory(address);
111.4636 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4637 +		if (dest == 15)
111.4638 +		{
111.4639 +			clockTicks += 2;
111.4640 +			reg[15].I  &= 0xFFFFFFFC;
111.4641 +			armNextPC	= reg[15].I;
111.4642 +			reg[15].I  += 4;
111.4643 +		}
111.4644 +	}
111.4645 +	break;
111.4646 +	case 0x7b0:
111.4647 +	case 0x7b8:
111.4648 +	{
111.4649 +		// LDR Rd, [Rn, Rm, LSL #]!
111.4650 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.4651 +		int dest	= (opcode >> 12) & 15;
111.4652 +		int base	= (opcode >> 16) & 15;
111.4653 +		u32 address = reg[base].I + offset;
111.4654 +		reg[dest].I = CPUReadMemory(address);
111.4655 +		if (dest != base)
111.4656 +			reg[base].I = address;
111.4657 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4658 +		if (dest == 15)
111.4659 +		{
111.4660 +			clockTicks += 2;
111.4661 +			reg[15].I  &= 0xFFFFFFFC;
111.4662 +			armNextPC	= reg[15].I;
111.4663 +			reg[15].I  += 4;
111.4664 +		}
111.4665 +	}
111.4666 +	break;
111.4667 +	case 0x7b2:
111.4668 +	case 0x7ba:
111.4669 +	{
111.4670 +		// LDR Rd, [Rn, Rm, LSR #]!
111.4671 +		int shift	= (opcode >> 7) & 31;
111.4672 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.4673 +		int dest	= (opcode >> 12) & 15;
111.4674 +		int base	= (opcode >> 16) & 15;
111.4675 +		u32 address = reg[base].I + offset;
111.4676 +		reg[dest].I = CPUReadMemory(address);
111.4677 +		if (dest != base)
111.4678 +			reg[base].I = address;
111.4679 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4680 +		if (dest == 15)
111.4681 +		{
111.4682 +			clockTicks += 2;
111.4683 +			reg[15].I  &= 0xFFFFFFFC;
111.4684 +			armNextPC	= reg[15].I;
111.4685 +			reg[15].I  += 4;
111.4686 +		}
111.4687 +	}
111.4688 +	break;
111.4689 +	case 0x7b4:
111.4690 +	case 0x7bc:
111.4691 +	{
111.4692 +		// LDR Rd, [Rn, Rm, ASR #]!
111.4693 +		int shift = (opcode >> 7) & 31;
111.4694 +		int offset;
111.4695 +		if (shift)
111.4696 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.4697 +		else if (reg[opcode & 15].I & 0x80000000)
111.4698 +			offset = 0xFFFFFFFF;
111.4699 +		else
111.4700 +			offset = 0;
111.4701 +		int dest	= (opcode >> 12) & 15;
111.4702 +		int base	= (opcode >> 16) & 15;
111.4703 +		u32 address = reg[base].I + offset;
111.4704 +		reg[dest].I = CPUReadMemory(address);
111.4705 +		if (dest != base)
111.4706 +			reg[base].I = address;
111.4707 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4708 +		if (dest == 15)
111.4709 +		{
111.4710 +			clockTicks += 2;
111.4711 +			reg[15].I  &= 0xFFFFFFFC;
111.4712 +			armNextPC	= reg[15].I;
111.4713 +			reg[15].I  += 4;
111.4714 +		}
111.4715 +	}
111.4716 +	break;
111.4717 +	case 0x7b6:
111.4718 +	case 0x7be:
111.4719 +	{
111.4720 +		// LDR Rd, [Rn, Rm, ROR #]!
111.4721 +		int shift = (opcode >> 7) & 31;
111.4722 +		u32 value = reg[opcode & 15].I;
111.4723 +		if (shift)
111.4724 +		{
111.4725 +			ROR_VALUE;
111.4726 +		}
111.4727 +		else
111.4728 +		{
111.4729 +			RCR_VALUE;
111.4730 +		}
111.4731 +		int dest	= (opcode >> 12) & 15;
111.4732 +		int base	= (opcode >> 16) & 15;
111.4733 +		u32 address = reg[base].I + value;
111.4734 +		reg[dest].I = CPUReadMemory(address);
111.4735 +		if (dest != base)
111.4736 +			reg[base].I = address;
111.4737 +		clockTicks += 3 + CPUUpdateTicksAccess32(address);
111.4738 +		if (dest == 15)
111.4739 +		{
111.4740 +			clockTicks += 2;
111.4741 +			reg[15].I  &= 0xFFFFFFFC;
111.4742 +			armNextPC	= reg[15].I;
111.4743 +			reg[15].I  += 4;
111.4744 +		}
111.4745 +	}
111.4746 +	break;
111.4747 +	case 0x640:
111.4748 +	case 0x648:
111.4749 +	// T versions are the same
111.4750 +	case 0x660:
111.4751 +	case 0x668:
111.4752 +	{
111.4753 +		// STRB Rd, [Rn], -Rm, LSL #
111.4754 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.4755 +		int dest	= (opcode >> 12) & 15;
111.4756 +		int base	= (opcode >> 16) & 15;
111.4757 +		u32 address = reg[base].I;
111.4758 +		CPUWriteByte(address, reg[dest].B.B0);
111.4759 +		reg[base].I = address - offset;
111.4760 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.4761 +	}
111.4762 +	break;
111.4763 +	case 0x642:
111.4764 +	case 0x64a:
111.4765 +	// T versions are the same
111.4766 +	case 0x662:
111.4767 +	case 0x66a:
111.4768 +	{
111.4769 +		// STRB Rd, [Rn], -Rm, LSR #
111.4770 +		int shift	= (opcode >> 7) & 31;
111.4771 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.4772 +		int dest	= (opcode >> 12) & 15;
111.4773 +		int base	= (opcode >> 16) & 15;
111.4774 +		u32 address = reg[base].I;
111.4775 +		CPUWriteByte(address, reg[dest].B.B0);
111.4776 +		reg[base].I = address - offset;
111.4777 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.4778 +	}
111.4779 +	break;
111.4780 +	case 0x644:
111.4781 +	case 0x64c:
111.4782 +	// T versions are the same
111.4783 +	case 0x664:
111.4784 +	case 0x66c:
111.4785 +	{
111.4786 +		// STRB Rd, [Rn], -Rm, ASR #
111.4787 +		int shift = (opcode >> 7) & 31;
111.4788 +		int offset;
111.4789 +		if (shift)
111.4790 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.4791 +		else if (reg[opcode & 15].I & 0x80000000)
111.4792 +			offset = 0xFFFFFFFF;
111.4793 +		else
111.4794 +			offset = 0;
111.4795 +		int dest	= (opcode >> 12) & 15;
111.4796 +		int base	= (opcode >> 16) & 15;
111.4797 +		u32 address = reg[base].I;
111.4798 +		CPUWriteByte(address, reg[dest].B.B0);
111.4799 +		reg[base].I = address - offset;
111.4800 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.4801 +	}
111.4802 +	break;
111.4803 +	case 0x646:
111.4804 +	case 0x64e:
111.4805 +	// T versions are the same
111.4806 +	case 0x666:
111.4807 +	case 0x66e:
111.4808 +	{
111.4809 +		// STRB Rd, [Rn], -Rm, ROR #
111.4810 +		int shift = (opcode >> 7) & 31;
111.4811 +		u32 value = reg[opcode & 15].I;
111.4812 +		if (shift)
111.4813 +		{
111.4814 +			ROR_VALUE;
111.4815 +		}
111.4816 +		else
111.4817 +		{
111.4818 +			RCR_VALUE;
111.4819 +		}
111.4820 +		int dest	= (opcode >> 12) & 15;
111.4821 +		int base	= (opcode >> 16) & 15;
111.4822 +		u32 address = reg[base].I;
111.4823 +		CPUWriteByte(address, reg[dest].B.B0);
111.4824 +		reg[base].I = address - value;
111.4825 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.4826 +	}
111.4827 +	break;
111.4828 +	case 0x6c0:
111.4829 +	case 0x6c8:
111.4830 +	// T versions are the same
111.4831 +	case 0x6e0:
111.4832 +	case 0x6e8:
111.4833 +	{
111.4834 +		// STRB Rd, [Rn], Rm, LSL #
111.4835 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.4836 +		int dest	= (opcode >> 12) & 15;
111.4837 +		int base	= (opcode >> 16) & 15;
111.4838 +		u32 address = reg[base].I;
111.4839 +		CPUWriteByte(address, reg[dest].B.B0);
111.4840 +		reg[base].I = address + offset;
111.4841 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.4842 +	}
111.4843 +	break;
111.4844 +	case 0x6c2:
111.4845 +	case 0x6ca:
111.4846 +	// T versions are the same
111.4847 +	case 0x6e2:
111.4848 +	case 0x6ea:
111.4849 +	{
111.4850 +		// STRB Rd, [Rn], Rm, LSR #
111.4851 +		int shift	= (opcode >> 7) & 31;
111.4852 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.4853 +		int dest	= (opcode >> 12) & 15;
111.4854 +		int base	= (opcode >> 16) & 15;
111.4855 +		u32 address = reg[base].I;
111.4856 +		CPUWriteByte(address, reg[dest].B.B0);
111.4857 +		reg[base].I = address + offset;
111.4858 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.4859 +	}
111.4860 +	break;
111.4861 +	case 0x6c4:
111.4862 +	case 0x6cc:
111.4863 +	// T versions are the same
111.4864 +	case 0x6e4:
111.4865 +	case 0x6ec:
111.4866 +	{
111.4867 +		// STR Rd, [Rn], Rm, ASR #
111.4868 +		int shift = (opcode >> 7) & 31;
111.4869 +		int offset;
111.4870 +		if (shift)
111.4871 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.4872 +		else if (reg[opcode & 15].I & 0x80000000)
111.4873 +			offset = 0xFFFFFFFF;
111.4874 +		else
111.4875 +			offset = 0;
111.4876 +		int dest	= (opcode >> 12) & 15;
111.4877 +		int base	= (opcode >> 16) & 15;
111.4878 +		u32 address = reg[base].I;
111.4879 +		CPUWriteByte(address, reg[dest].B.B0);
111.4880 +		reg[base].I = address + offset;
111.4881 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.4882 +	}
111.4883 +	break;
111.4884 +	case 0x6c6:
111.4885 +	case 0x6ce:
111.4886 +	// T versions are the same
111.4887 +	case 0x6e6:
111.4888 +	case 0x6ee:
111.4889 +	{
111.4890 +		// STRB Rd, [Rn], Rm, ROR #
111.4891 +		int shift = (opcode >> 7) & 31;
111.4892 +		u32 value = reg[opcode & 15].I;
111.4893 +		if (shift)
111.4894 +		{
111.4895 +			ROR_VALUE;
111.4896 +		}
111.4897 +		else
111.4898 +		{
111.4899 +			RCR_VALUE;
111.4900 +		}
111.4901 +		int dest	= (opcode >> 12) & 15;
111.4902 +		int base	= (opcode >> 16) & 15;
111.4903 +		u32 address = reg[base].I;
111.4904 +		CPUWriteByte(address, reg[dest].B.B0);
111.4905 +		reg[base].I = address + value;
111.4906 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.4907 +	}
111.4908 +	break;
111.4909 +	case 0x740:
111.4910 +	case 0x748:
111.4911 +	{
111.4912 +		// STRB Rd, [Rn, -Rm, LSL #]
111.4913 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.4914 +		int dest	= (opcode >> 12) & 15;
111.4915 +		int base	= (opcode >> 16) & 15;
111.4916 +		u32 address = reg[base].I - offset;
111.4917 +		CPUWriteByte(address, reg[dest].B.B0);
111.4918 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.4919 +	}
111.4920 +	break;
111.4921 +	case 0x742:
111.4922 +	case 0x74a:
111.4923 +	{
111.4924 +		// STRB Rd, [Rn, -Rm, LSR #]
111.4925 +		int shift	= (opcode >> 7) & 31;
111.4926 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.4927 +		int dest	= (opcode >> 12) & 15;
111.4928 +		int base	= (opcode >> 16) & 15;
111.4929 +		u32 address = reg[base].I - offset;
111.4930 +		CPUWriteByte(address, reg[dest].B.B0);
111.4931 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.4932 +	}
111.4933 +	break;
111.4934 +	case 0x744:
111.4935 +	case 0x74c:
111.4936 +	{
111.4937 +		// STRB Rd, [Rn, -Rm, ASR #]
111.4938 +		int shift = (opcode >> 7) & 31;
111.4939 +		int offset;
111.4940 +		if (shift)
111.4941 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.4942 +		else if (reg[opcode & 15].I & 0x80000000)
111.4943 +			offset = 0xFFFFFFFF;
111.4944 +		else
111.4945 +			offset = 0;
111.4946 +		int dest	= (opcode >> 12) & 15;
111.4947 +		int base	= (opcode >> 16) & 15;
111.4948 +		u32 address = reg[base].I - offset;
111.4949 +		CPUWriteByte(address, reg[dest].B.B0);
111.4950 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.4951 +	}
111.4952 +	break;
111.4953 +	case 0x746:
111.4954 +	case 0x74e:
111.4955 +	{
111.4956 +		// STRB Rd, [Rn, -Rm, ROR #]
111.4957 +		int shift = (opcode >> 7) & 31;
111.4958 +		u32 value = reg[opcode & 15].I;
111.4959 +		if (shift)
111.4960 +		{
111.4961 +			ROR_VALUE;
111.4962 +		}
111.4963 +		else
111.4964 +		{
111.4965 +			RCR_VALUE;
111.4966 +		}
111.4967 +		int dest	= (opcode >> 12) & 15;
111.4968 +		int base	= (opcode >> 16) & 15;
111.4969 +		u32 address = reg[base].I - value;
111.4970 +		CPUWriteByte(address, reg[dest].B.B0);
111.4971 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.4972 +	}
111.4973 +	break;
111.4974 +	case 0x760:
111.4975 +	case 0x768:
111.4976 +	{
111.4977 +		// STRB Rd, [Rn, -Rm, LSL #]!
111.4978 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.4979 +		int dest	= (opcode >> 12) & 15;
111.4980 +		int base	= (opcode >> 16) & 15;
111.4981 +		u32 address = reg[base].I - offset;
111.4982 +		reg[base].I = address;
111.4983 +		CPUWriteByte(address, reg[dest].B.B0);
111.4984 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.4985 +	}
111.4986 +	break;
111.4987 +	case 0x762:
111.4988 +	case 0x76a:
111.4989 +	{
111.4990 +		// STRB Rd, [Rn, -Rm, LSR #]!
111.4991 +		int shift	= (opcode >> 7) & 31;
111.4992 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.4993 +		int dest	= (opcode >> 12) & 15;
111.4994 +		int base	= (opcode >> 16) & 15;
111.4995 +		u32 address = reg[base].I - offset;
111.4996 +		reg[base].I = address;
111.4997 +		CPUWriteByte(address, reg[dest].B.B0);
111.4998 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.4999 +	}
111.5000 +	break;
111.5001 +	case 0x764:
111.5002 +	case 0x76c:
111.5003 +	{
111.5004 +		// STRB Rd, [Rn, -Rm, ASR #]!
111.5005 +		int shift = (opcode >> 7) & 31;
111.5006 +		int offset;
111.5007 +		if (shift)
111.5008 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.5009 +		else if (reg[opcode & 15].I & 0x80000000)
111.5010 +			offset = 0xFFFFFFFF;
111.5011 +		else
111.5012 +			offset = 0;
111.5013 +		int dest	= (opcode >> 12) & 15;
111.5014 +		int base	= (opcode >> 16) & 15;
111.5015 +		u32 address = reg[base].I - offset;
111.5016 +		reg[base].I = address;
111.5017 +		CPUWriteByte(address, reg[dest].B.B0);
111.5018 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.5019 +	}
111.5020 +	break;
111.5021 +	case 0x766:
111.5022 +	case 0x76e:
111.5023 +	{
111.5024 +		// STRB Rd, [Rn, -Rm, ROR #]!
111.5025 +		int shift = (opcode >> 7) & 31;
111.5026 +		u32 value = reg[opcode & 15].I;
111.5027 +		if (shift)
111.5028 +		{
111.5029 +			ROR_VALUE;
111.5030 +		}
111.5031 +		else
111.5032 +		{
111.5033 +			RCR_VALUE;
111.5034 +		}
111.5035 +		int dest	= (opcode >> 12) & 15;
111.5036 +		int base	= (opcode >> 16) & 15;
111.5037 +		u32 address = reg[base].I - value;
111.5038 +		reg[base].I = address;
111.5039 +		CPUWriteByte(address, reg[dest].B.B0);
111.5040 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.5041 +	}
111.5042 +	break;
111.5043 +	case 0x7c0:
111.5044 +	case 0x7c8:
111.5045 +	{
111.5046 +		// STRB Rd, [Rn, Rm, LSL #]
111.5047 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.5048 +		int dest	= (opcode >> 12) & 15;
111.5049 +		int base	= (opcode >> 16) & 15;
111.5050 +		u32 address = reg[base].I + offset;
111.5051 +		CPUWriteByte(address, reg[dest].B.B0);
111.5052 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.5053 +	}
111.5054 +	break;
111.5055 +	case 0x7c2:
111.5056 +	case 0x7ca:
111.5057 +	{
111.5058 +		// STRB Rd, [Rn, Rm, LSR #]
111.5059 +		int shift	= (opcode >> 7) & 31;
111.5060 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.5061 +		int dest	= (opcode >> 12) & 15;
111.5062 +		int base	= (opcode >> 16) & 15;
111.5063 +		u32 address = reg[base].I + offset;
111.5064 +		CPUWriteByte(address, reg[dest].B.B0);
111.5065 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.5066 +	}
111.5067 +	break;
111.5068 +	case 0x7c4:
111.5069 +	case 0x7cc:
111.5070 +	{
111.5071 +		// STRB Rd, [Rn, Rm, ASR #]
111.5072 +		int shift = (opcode >> 7) & 31;
111.5073 +		int offset;
111.5074 +		if (shift)
111.5075 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.5076 +		else if (reg[opcode & 15].I & 0x80000000)
111.5077 +			offset = 0xFFFFFFFF;
111.5078 +		else
111.5079 +			offset = 0;
111.5080 +		int dest	= (opcode >> 12) & 15;
111.5081 +		int base	= (opcode >> 16) & 15;
111.5082 +		u32 address = reg[base].I + offset;
111.5083 +		CPUWriteByte(address, reg[dest].B.B0);
111.5084 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.5085 +	}
111.5086 +	break;
111.5087 +	case 0x7c6:
111.5088 +	case 0x7ce:
111.5089 +	{
111.5090 +		// STRB Rd, [Rn, Rm, ROR #]
111.5091 +		int shift = (opcode >> 7) & 31;
111.5092 +		u32 value = reg[opcode & 15].I;
111.5093 +		if (shift)
111.5094 +		{
111.5095 +			ROR_VALUE;
111.5096 +		}
111.5097 +		else
111.5098 +		{
111.5099 +			RCR_VALUE;
111.5100 +		}
111.5101 +		int dest	= (opcode >> 12) & 15;
111.5102 +		int base	= (opcode >> 16) & 15;
111.5103 +		u32 address = reg[base].I + value;
111.5104 +		CPUWriteByte(address, reg[dest].B.B0);
111.5105 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.5106 +	}
111.5107 +	break;
111.5108 +	case 0x7e0:
111.5109 +	case 0x7e8:
111.5110 +	{
111.5111 +		// STRB Rd, [Rn, Rm, LSL #]!
111.5112 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.5113 +		int dest	= (opcode >> 12) & 15;
111.5114 +		int base	= (opcode >> 16) & 15;
111.5115 +		u32 address = reg[base].I + offset;
111.5116 +		reg[base].I = address;
111.5117 +		CPUWriteByte(address, reg[dest].B.B0);
111.5118 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.5119 +	}
111.5120 +	break;
111.5121 +	case 0x7e2:
111.5122 +	case 0x7ea:
111.5123 +	{
111.5124 +		// STRB Rd, [Rn, Rm, LSR #]!
111.5125 +		int shift	= (opcode >> 7) & 31;
111.5126 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.5127 +		int dest	= (opcode >> 12) & 15;
111.5128 +		int base	= (opcode >> 16) & 15;
111.5129 +		u32 address = reg[base].I + offset;
111.5130 +		reg[base].I = address;
111.5131 +		CPUWriteByte(address, reg[dest].B.B0);
111.5132 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.5133 +	}
111.5134 +	break;
111.5135 +	case 0x7e4:
111.5136 +	case 0x7ec:
111.5137 +	{
111.5138 +		// STRB Rd, [Rn, Rm, ASR #]!
111.5139 +		int shift = (opcode >> 7) & 31;
111.5140 +		int offset;
111.5141 +		if (shift)
111.5142 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.5143 +		else if (reg[opcode & 15].I & 0x80000000)
111.5144 +			offset = 0xFFFFFFFF;
111.5145 +		else
111.5146 +			offset = 0;
111.5147 +		int dest	= (opcode >> 12) & 15;
111.5148 +		int base	= (opcode >> 16) & 15;
111.5149 +		u32 address = reg[base].I + offset;
111.5150 +		reg[base].I = address;
111.5151 +		CPUWriteByte(address, reg[dest].B.B0);
111.5152 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.5153 +	}
111.5154 +	break;
111.5155 +	case 0x7e6:
111.5156 +	case 0x7ee:
111.5157 +	{
111.5158 +		// STRB Rd, [Rn, Rm, ROR #]!
111.5159 +		int shift = (opcode >> 7) & 31;
111.5160 +		u32 value = reg[opcode & 15].I;
111.5161 +		if (shift)
111.5162 +		{
111.5163 +			ROR_VALUE;
111.5164 +		}
111.5165 +		else
111.5166 +		{
111.5167 +			RCR_VALUE;
111.5168 +		}
111.5169 +		int dest	= (opcode >> 12) & 15;
111.5170 +		int base	= (opcode >> 16) & 15;
111.5171 +		u32 address = reg[base].I + value;
111.5172 +		reg[base].I = address;
111.5173 +		CPUWriteByte(address, reg[dest].B.B0);
111.5174 +		clockTicks += 2 + CPUUpdateTicksAccess16(address);
111.5175 +	}
111.5176 +	break;
111.5177 +	case 0x650:
111.5178 +	case 0x658:
111.5179 +	// T versions are the same
111.5180 +	case 0x670:
111.5181 +	case 0x678:
111.5182 +	{
111.5183 +		// LDRB Rd, [Rn], -Rm, LSL #
111.5184 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.5185 +		int dest	= (opcode >> 12) & 15;
111.5186 +		int base	= (opcode >> 16) & 15;
111.5187 +		u32 address = reg[base].I;
111.5188 +		reg[dest].I = CPUReadByte(address);
111.5189 +		if (dest != base)
111.5190 +			reg[base].I = address - offset;
111.5191 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5192 +	}
111.5193 +	break;
111.5194 +	case 0x652:
111.5195 +	case 0x65a:
111.5196 +	// T versions are the same
111.5197 +	case 0x672:
111.5198 +	case 0x67a:
111.5199 +	{
111.5200 +		// LDRB Rd, [Rn], -Rm, LSR #
111.5201 +		int shift	= (opcode >> 7) & 31;
111.5202 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.5203 +		int dest	= (opcode >> 12) & 15;
111.5204 +		int base	= (opcode >> 16) & 15;
111.5205 +		u32 address = reg[base].I;
111.5206 +		reg[dest].I = CPUReadByte(address);
111.5207 +		if (dest != base)
111.5208 +			reg[base].I = address - offset;
111.5209 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5210 +	}
111.5211 +	break;
111.5212 +	case 0x654:
111.5213 +	case 0x65c:
111.5214 +	// T versions are the same
111.5215 +	case 0x674:
111.5216 +	case 0x67c:
111.5217 +	{
111.5218 +		// LDRB Rd, [Rn], -Rm, ASR #
111.5219 +		int shift = (opcode >> 7) & 31;
111.5220 +		int offset;
111.5221 +		if (shift)
111.5222 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.5223 +		else if (reg[opcode & 15].I & 0x80000000)
111.5224 +			offset = 0xFFFFFFFF;
111.5225 +		else
111.5226 +			offset = 0;
111.5227 +		int dest	= (opcode >> 12) & 15;
111.5228 +		int base	= (opcode >> 16) & 15;
111.5229 +		u32 address = reg[base].I;
111.5230 +		reg[dest].I = CPUReadByte(address);
111.5231 +		if (dest != base)
111.5232 +			reg[base].I = address - offset;
111.5233 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5234 +	}
111.5235 +	break;
111.5236 +	case 0x656:
111.5237 +	case 0x65e:
111.5238 +	// T versions are the same
111.5239 +	case 0x676:
111.5240 +	case 0x67e:
111.5241 +	{
111.5242 +		// LDRB Rd, [Rn], -Rm, ROR #
111.5243 +		int shift = (opcode >> 7) & 31;
111.5244 +		u32 value = reg[opcode & 15].I;
111.5245 +		if (shift)
111.5246 +		{
111.5247 +			ROR_VALUE;
111.5248 +		}
111.5249 +		else
111.5250 +		{
111.5251 +			RCR_VALUE;
111.5252 +		}
111.5253 +		int dest	= (opcode >> 12) & 15;
111.5254 +		int base	= (opcode >> 16) & 15;
111.5255 +		u32 address = reg[base].I;
111.5256 +		reg[dest].I = CPUReadByte(address);
111.5257 +		if (dest != base)
111.5258 +			reg[base].I = address - value;
111.5259 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5260 +	}
111.5261 +	break;
111.5262 +	case 0x6d0:
111.5263 +	case 0x6d8:
111.5264 +	// T versions are the same
111.5265 +	case 0x6f0:
111.5266 +	case 0x6f8:
111.5267 +	{
111.5268 +		// LDRB Rd, [Rn], Rm, LSL #
111.5269 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.5270 +		int dest	= (opcode >> 12) & 15;
111.5271 +		int base	= (opcode >> 16) & 15;
111.5272 +		u32 address = reg[base].I;
111.5273 +		reg[dest].I = CPUReadByte(address);
111.5274 +		if (dest != base)
111.5275 +			reg[base].I = address + offset;
111.5276 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5277 +	}
111.5278 +	break;
111.5279 +	case 0x6d2:
111.5280 +	case 0x6da:
111.5281 +	// T versions are the same
111.5282 +	case 0x6f2:
111.5283 +	case 0x6fa:
111.5284 +	{
111.5285 +		// LDRB Rd, [Rn], Rm, LSR #
111.5286 +		int shift	= (opcode >> 7) & 31;
111.5287 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.5288 +		int dest	= (opcode >> 12) & 15;
111.5289 +		int base	= (opcode >> 16) & 15;
111.5290 +		u32 address = reg[base].I;
111.5291 +		reg[dest].I = CPUReadByte(address);
111.5292 +		if (dest != base)
111.5293 +			reg[base].I = address + offset;
111.5294 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5295 +	}
111.5296 +	break;
111.5297 +	case 0x6d4:
111.5298 +	case 0x6dc:
111.5299 +	// T versions are the same
111.5300 +	case 0x6f4:
111.5301 +	case 0x6fc:
111.5302 +	{
111.5303 +		// LDRB Rd, [Rn], Rm, ASR #
111.5304 +		int shift = (opcode >> 7) & 31;
111.5305 +		int offset;
111.5306 +		if (shift)
111.5307 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.5308 +		else if (reg[opcode & 15].I & 0x80000000)
111.5309 +			offset = 0xFFFFFFFF;
111.5310 +		else
111.5311 +			offset = 0;
111.5312 +		int dest	= (opcode >> 12) & 15;
111.5313 +		int base	= (opcode >> 16) & 15;
111.5314 +		u32 address = reg[base].I;
111.5315 +		reg[dest].I = CPUReadByte(address);
111.5316 +		if (dest != base)
111.5317 +			reg[base].I = address + offset;
111.5318 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5319 +	}
111.5320 +	break;
111.5321 +	case 0x6d6:
111.5322 +	case 0x6de:
111.5323 +	// T versions are the same
111.5324 +	case 0x6f6:
111.5325 +	case 0x6fe:
111.5326 +	{
111.5327 +		// LDRB Rd, [Rn], Rm, ROR #
111.5328 +		int shift = (opcode >> 7) & 31;
111.5329 +		u32 value = reg[opcode & 15].I;
111.5330 +		if (shift)
111.5331 +		{
111.5332 +			ROR_VALUE;
111.5333 +		}
111.5334 +		else
111.5335 +		{
111.5336 +			RCR_VALUE;
111.5337 +		}
111.5338 +		int dest	= (opcode >> 12) & 15;
111.5339 +		int base	= (opcode >> 16) & 15;
111.5340 +		u32 address = reg[base].I;
111.5341 +		reg[dest].I = CPUReadByte(address);
111.5342 +		if (dest != base)
111.5343 +			reg[base].I = address + value;
111.5344 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5345 +	}
111.5346 +	break;
111.5347 +	case 0x750:
111.5348 +	case 0x758:
111.5349 +	{
111.5350 +		// LDRB Rd, [Rn, -Rm, LSL #]
111.5351 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.5352 +		int dest	= (opcode >> 12) & 15;
111.5353 +		int base	= (opcode >> 16) & 15;
111.5354 +		u32 address = reg[base].I - offset;
111.5355 +		reg[dest].I = CPUReadByte(address);
111.5356 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5357 +	}
111.5358 +	break;
111.5359 +	case 0x752:
111.5360 +	case 0x75a:
111.5361 +	{
111.5362 +		// LDRB Rd, [Rn, -Rm, LSR #]
111.5363 +		int shift	= (opcode >> 7) & 31;
111.5364 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.5365 +		int dest	= (opcode >> 12) & 15;
111.5366 +		int base	= (opcode >> 16) & 15;
111.5367 +		u32 address = reg[base].I - offset;
111.5368 +		reg[dest].I = CPUReadByte(address);
111.5369 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5370 +	}
111.5371 +	break;
111.5372 +	case 0x754:
111.5373 +	case 0x75c:
111.5374 +	{
111.5375 +		// LDRB Rd, [Rn, -Rm, ASR #]
111.5376 +		int shift = (opcode >> 7) & 31;
111.5377 +		int offset;
111.5378 +		if (shift)
111.5379 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.5380 +		else if (reg[opcode & 15].I & 0x80000000)
111.5381 +			offset = 0xFFFFFFFF;
111.5382 +		else
111.5383 +			offset = 0;
111.5384 +		int dest	= (opcode >> 12) & 15;
111.5385 +		int base	= (opcode >> 16) & 15;
111.5386 +		u32 address = reg[base].I - offset;
111.5387 +		reg[dest].I = CPUReadByte(address);
111.5388 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5389 +	}
111.5390 +	break;
111.5391 +	case 0x756:
111.5392 +	case 0x75e:
111.5393 +	{
111.5394 +		// LDRB Rd, [Rn, -Rm, ROR #]
111.5395 +		int shift = (opcode >> 7) & 31;
111.5396 +		u32 value = reg[opcode & 15].I;
111.5397 +		if (shift)
111.5398 +		{
111.5399 +			ROR_VALUE;
111.5400 +		}
111.5401 +		else
111.5402 +		{
111.5403 +			RCR_VALUE;
111.5404 +		}
111.5405 +		int dest	= (opcode >> 12) & 15;
111.5406 +		int base	= (opcode >> 16) & 15;
111.5407 +		u32 address = reg[base].I - value;
111.5408 +		reg[dest].I = CPUReadByte(address);
111.5409 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5410 +	}
111.5411 +	break;
111.5412 +	case 0x770:
111.5413 +	case 0x778:
111.5414 +	{
111.5415 +		// LDRB Rd, [Rn, -Rm, LSL #]!
111.5416 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.5417 +		int dest	= (opcode >> 12) & 15;
111.5418 +		int base	= (opcode >> 16) & 15;
111.5419 +		u32 address = reg[base].I - offset;
111.5420 +		reg[dest].I = CPUReadByte(address);
111.5421 +		if (dest != base)
111.5422 +			reg[base].I = address;
111.5423 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5424 +	}
111.5425 +	break;
111.5426 +	case 0x772:
111.5427 +	case 0x77a:
111.5428 +	{
111.5429 +		// LDRB Rd, [Rn, -Rm, LSR #]!
111.5430 +		int shift	= (opcode >> 7) & 31;
111.5431 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.5432 +		int dest	= (opcode >> 12) & 15;
111.5433 +		int base	= (opcode >> 16) & 15;
111.5434 +		u32 address = reg[base].I - offset;
111.5435 +		reg[dest].I = CPUReadByte(address);
111.5436 +		if (dest != base)
111.5437 +			reg[base].I = address;
111.5438 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5439 +	}
111.5440 +	break;
111.5441 +	case 0x774:
111.5442 +	case 0x77c:
111.5443 +	{
111.5444 +		// LDRB Rd, [Rn, -Rm, ASR #]!
111.5445 +		int shift = (opcode >> 7) & 31;
111.5446 +		int offset;
111.5447 +		if (shift)
111.5448 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.5449 +		else if (reg[opcode & 15].I & 0x80000000)
111.5450 +			offset = 0xFFFFFFFF;
111.5451 +		else
111.5452 +			offset = 0;
111.5453 +		int dest	= (opcode >> 12) & 15;
111.5454 +		int base	= (opcode >> 16) & 15;
111.5455 +		u32 address = reg[base].I - offset;
111.5456 +		reg[dest].I = CPUReadByte(address);
111.5457 +		if (dest != base)
111.5458 +			reg[base].I = address;
111.5459 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5460 +	}
111.5461 +	break;
111.5462 +	case 0x776:
111.5463 +	case 0x77e:
111.5464 +	{
111.5465 +		// LDRB Rd, [Rn, -Rm, ROR #]!
111.5466 +		int shift = (opcode >> 7) & 31;
111.5467 +		u32 value = reg[opcode & 15].I;
111.5468 +		if (shift)
111.5469 +		{
111.5470 +			ROR_VALUE;
111.5471 +		}
111.5472 +		else
111.5473 +		{
111.5474 +			RCR_VALUE;
111.5475 +		}
111.5476 +		int dest	= (opcode >> 12) & 15;
111.5477 +		int base	= (opcode >> 16) & 15;
111.5478 +		u32 address = reg[base].I - value;
111.5479 +		reg[dest].I = CPUReadByte(address);
111.5480 +		if (dest != base)
111.5481 +			reg[base].I = address;
111.5482 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5483 +	}
111.5484 +	break;
111.5485 +	case 0x7d0:
111.5486 +	case 0x7d8:
111.5487 +	{
111.5488 +		// LDRB Rd, [Rn, Rm, LSL #]
111.5489 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.5490 +		int dest	= (opcode >> 12) & 15;
111.5491 +		int base	= (opcode >> 16) & 15;
111.5492 +		u32 address = reg[base].I + offset;
111.5493 +		reg[dest].I = CPUReadByte(address);
111.5494 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5495 +	}
111.5496 +	break;
111.5497 +	case 0x7d2:
111.5498 +	case 0x7da:
111.5499 +	{
111.5500 +		// LDRB Rd, [Rn, Rm, LSR #]
111.5501 +		int shift	= (opcode >> 7) & 31;
111.5502 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.5503 +		int dest	= (opcode >> 12) & 15;
111.5504 +		int base	= (opcode >> 16) & 15;
111.5505 +		u32 address = reg[base].I + offset;
111.5506 +		reg[dest].I = CPUReadByte(address);
111.5507 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5508 +	}
111.5509 +	break;
111.5510 +	case 0x7d4:
111.5511 +	case 0x7dc:
111.5512 +	{
111.5513 +		// LDRB Rd, [Rn, Rm, ASR #]
111.5514 +		int shift = (opcode >> 7) & 31;
111.5515 +		int offset;
111.5516 +		if (shift)
111.5517 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.5518 +		else if (reg[opcode & 15].I & 0x80000000)
111.5519 +			offset = 0xFFFFFFFF;
111.5520 +		else
111.5521 +			offset = 0;
111.5522 +		int dest	= (opcode >> 12) & 15;
111.5523 +		int base	= (opcode >> 16) & 15;
111.5524 +		u32 address = reg[base].I + offset;
111.5525 +		reg[dest].I = CPUReadByte(address);
111.5526 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5527 +	}
111.5528 +	break;
111.5529 +	case 0x7d6:
111.5530 +	case 0x7de:
111.5531 +	{
111.5532 +		// LDRB Rd, [Rn, Rm, ROR #]
111.5533 +		int shift = (opcode >> 7) & 31;
111.5534 +		u32 value = reg[opcode & 15].I;
111.5535 +		if (shift)
111.5536 +		{
111.5537 +			ROR_VALUE;
111.5538 +		}
111.5539 +		else
111.5540 +		{
111.5541 +			RCR_VALUE;
111.5542 +		}
111.5543 +		int dest	= (opcode >> 12) & 15;
111.5544 +		int base	= (opcode >> 16) & 15;
111.5545 +		u32 address = reg[base].I + value;
111.5546 +		reg[dest].I = CPUReadByte(address);
111.5547 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5548 +	}
111.5549 +	break;
111.5550 +	case 0x7f0:
111.5551 +	case 0x7f8:
111.5552 +	{
111.5553 +		// LDRB Rd, [Rn, Rm, LSL #]!
111.5554 +		int offset	= reg[opcode & 15].I << ((opcode >> 7) & 31);
111.5555 +		int dest	= (opcode >> 12) & 15;
111.5556 +		int base	= (opcode >> 16) & 15;
111.5557 +		u32 address = reg[base].I + offset;
111.5558 +		reg[dest].I = CPUReadByte(address);
111.5559 +		if (dest != base)
111.5560 +			reg[base].I = address;
111.5561 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5562 +	}
111.5563 +	break;
111.5564 +	case 0x7f2:
111.5565 +	case 0x7fa:
111.5566 +	{
111.5567 +		// LDRB Rd, [Rn, Rm, LSR #]!
111.5568 +		int shift	= (opcode >> 7) & 31;
111.5569 +		int offset	= shift ? reg[opcode & 15].I >> shift : 0;
111.5570 +		int dest	= (opcode >> 12) & 15;
111.5571 +		int base	= (opcode >> 16) & 15;
111.5572 +		u32 address = reg[base].I + offset;
111.5573 +		reg[dest].I = CPUReadByte(address);
111.5574 +		if (dest != base)
111.5575 +			reg[base].I = address;
111.5576 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5577 +	}
111.5578 +	break;
111.5579 +	case 0x7f4:
111.5580 +	case 0x7fc:
111.5581 +	{
111.5582 +		// LDRB Rd, [Rn, Rm, ASR #]!
111.5583 +		int shift = (opcode >> 7) & 31;
111.5584 +		int offset;
111.5585 +		if (shift)
111.5586 +			offset = (int)((s32)reg[opcode & 15].I >> shift);
111.5587 +		else if (reg[opcode & 15].I & 0x80000000)
111.5588 +			offset = 0xFFFFFFFF;
111.5589 +		else
111.5590 +			offset = 0;
111.5591 +		int dest	= (opcode >> 12) & 15;
111.5592 +		int base	= (opcode >> 16) & 15;
111.5593 +		u32 address = reg[base].I + offset;
111.5594 +		reg[dest].I = CPUReadByte(address);
111.5595 +		if (dest != base)
111.5596 +			reg[base].I = address;
111.5597 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5598 +	}
111.5599 +	break;
111.5600 +	case 0x7f6:
111.5601 +	case 0x7fe:
111.5602 +	{
111.5603 +		// LDRB Rd, [Rn, Rm, ROR #]!
111.5604 +		int shift = (opcode >> 7) & 31;
111.5605 +		u32 value = reg[opcode & 15].I;
111.5606 +		if (shift)
111.5607 +		{
111.5608 +			ROR_VALUE;
111.5609 +		}
111.5610 +		else
111.5611 +		{
111.5612 +			RCR_VALUE;
111.5613 +		}
111.5614 +		int dest	= (opcode >> 12) & 15;
111.5615 +		int base	= (opcode >> 16) & 15;
111.5616 +		u32 address = reg[base].I + value;
111.5617 +		reg[dest].I = CPUReadByte(address);
111.5618 +		if (dest != base)
111.5619 +			reg[base].I = address;
111.5620 +		clockTicks += 3 + CPUUpdateTicksAccess16(address);
111.5621 +	}
111.5622 +	break;
111.5623 +#define STMW_REG(val, num) \
111.5624 +	if (opcode & (val)) { \
111.5625 +		CPUWriteMemory(address, reg[(num)].I); \
111.5626 +		if (!offset) { \
111.5627 +			reg[base].I = temp; \
111.5628 +			clockTicks += 1 + CPUUpdateTicksAccess32(address); \
111.5629 +			offset		= 1; \
111.5630 +		} else { \
111.5631 +			clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); \
111.5632 +		} \
111.5633 +		address += 4; \
111.5634 +	}
111.5635 +#define STM_REG(val, num) \
111.5636 +	if (opcode & (val)) { \
111.5637 +		CPUWriteMemory(address, reg[(num)].I); \
111.5638 +		if (!offset) { \
111.5639 +			clockTicks += 1 + CPUUpdateTicksAccess32(address); \
111.5640 +			offset		= 1; \
111.5641 +		} else { \
111.5642 +			clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); \
111.5643 +		} \
111.5644 +		address += 4; \
111.5645 +	}
111.5646 +
111.5647 +		CASE_16(0x800)
111.5648 +		// STMDA Rn, {Rlist}
111.5649 +		{
111.5650 +			int base = (opcode & 0x000F0000) >> 16;
111.5651 +			u32 temp = reg[base].I -
111.5652 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.5653 +			u32 address = (temp + 4) & 0xFFFFFFFC;
111.5654 +			clockTicks += 2;
111.5655 +			int offset = 0;
111.5656 +			STM_REG(1, 0);
111.5657 +			STM_REG(2, 1);
111.5658 +			STM_REG(4, 2);
111.5659 +			STM_REG(8, 3);
111.5660 +			STM_REG(16, 4);
111.5661 +			STM_REG(32, 5);
111.5662 +			STM_REG(64, 6);
111.5663 +			STM_REG(128, 7);
111.5664 +			STM_REG(256, 8);
111.5665 +			STM_REG(512, 9);
111.5666 +			STM_REG(1024, 10);
111.5667 +			STM_REG(2048, 11);
111.5668 +			STM_REG(4096, 12);
111.5669 +			STM_REG(8192, 13);
111.5670 +			STM_REG(16384, 14);
111.5671 +			if (opcode & 32768)
111.5672 +			{
111.5673 +				CPUWriteMemory(address, reg[15].I + 4);
111.5674 +				if (!offset)
111.5675 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.5676 +				else
111.5677 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.5678 +			}
111.5679 +		}
111.5680 +		break;
111.5681 +		CASE_16(0x820)
111.5682 +		{
111.5683 +			// STMDA Rn!, {Rlist}
111.5684 +			int base = (opcode & 0x000F0000) >> 16;
111.5685 +			u32 temp = reg[base].I -
111.5686 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.5687 +			u32 address = (temp + 4) & 0xFFFFFFFC;
111.5688 +			clockTicks += 2;
111.5689 +			int offset = 0;
111.5690 +
111.5691 +			STMW_REG(1, 0);
111.5692 +			STMW_REG(2, 1);
111.5693 +			STMW_REG(4, 2);
111.5694 +			STMW_REG(8, 3);
111.5695 +			STMW_REG(16, 4);
111.5696 +			STMW_REG(32, 5);
111.5697 +			STMW_REG(64, 6);
111.5698 +			STMW_REG(128, 7);
111.5699 +			STMW_REG(256, 8);
111.5700 +			STMW_REG(512, 9);
111.5701 +			STMW_REG(1024, 10);
111.5702 +			STMW_REG(2048, 11);
111.5703 +			STMW_REG(4096, 12);
111.5704 +			STMW_REG(8192, 13);
111.5705 +			STMW_REG(16384, 14);
111.5706 +			if (opcode & 32768)
111.5707 +			{
111.5708 +				CPUWriteMemory(address, reg[15].I + 4);
111.5709 +				if (!offset)
111.5710 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.5711 +				else
111.5712 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.5713 +				reg[base].I = temp;
111.5714 +			}
111.5715 +		}
111.5716 +		break;
111.5717 +		CASE_16(0x840)
111.5718 +		{
111.5719 +			// STMDA Rn, {Rlist}^
111.5720 +			int base = (opcode & 0x000F0000) >> 16;
111.5721 +			u32 temp = reg[base].I -
111.5722 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.5723 +			u32 address = (temp + 4) & 0xFFFFFFFC;
111.5724 +			clockTicks += 2;
111.5725 +			int offset = 0;
111.5726 +
111.5727 +			STM_REG(1, 0);
111.5728 +			STM_REG(2, 1);
111.5729 +			STM_REG(4, 2);
111.5730 +			STM_REG(8, 3);
111.5731 +			STM_REG(16, 4);
111.5732 +			STM_REG(32, 5);
111.5733 +			STM_REG(64, 6);
111.5734 +			STM_REG(128, 7);
111.5735 +
111.5736 +			if (armMode == 0x11)
111.5737 +			{
111.5738 +				STM_REG(256, R8_FIQ);
111.5739 +				STM_REG(512, R9_FIQ);
111.5740 +				STM_REG(1024, R10_FIQ);
111.5741 +				STM_REG(2048, R11_FIQ);
111.5742 +				STM_REG(4096, R12_FIQ);
111.5743 +			}
111.5744 +			else
111.5745 +			{
111.5746 +				STM_REG(256, 8);
111.5747 +				STM_REG(512, 9);
111.5748 +				STM_REG(1024, 10);
111.5749 +				STM_REG(2048, 11);
111.5750 +				STM_REG(4096, 12);
111.5751 +			}
111.5752 +
111.5753 +			if (armMode != 0x10 && armMode != 0x1f)
111.5754 +			{
111.5755 +				STM_REG(8192, R13_USR);
111.5756 +				STM_REG(16384, R14_USR);
111.5757 +			}
111.5758 +			else
111.5759 +			{
111.5760 +				STM_REG(8192, 13);
111.5761 +				STM_REG(16384, 14);
111.5762 +			}
111.5763 +
111.5764 +			if (opcode & 32768)
111.5765 +			{
111.5766 +				CPUWriteMemory(address, reg[15].I + 4);
111.5767 +				if (!offset)
111.5768 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.5769 +				else
111.5770 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.5771 +			}
111.5772 +		}
111.5773 +		break;
111.5774 +		CASE_16(0x860)
111.5775 +		{
111.5776 +			// STMDA Rn!, {Rlist}^
111.5777 +			int base = (opcode & 0x000F0000) >> 16;
111.5778 +			u32 temp = reg[base].I -
111.5779 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.5780 +			u32 address = (temp + 4) & 0xFFFFFFFC;
111.5781 +			clockTicks += 2;
111.5782 +			int offset = 0;
111.5783 +
111.5784 +			STMW_REG(1, 0);
111.5785 +			STMW_REG(2, 1);
111.5786 +			STMW_REG(4, 2);
111.5787 +			STMW_REG(8, 3);
111.5788 +			STMW_REG(16, 4);
111.5789 +			STMW_REG(32, 5);
111.5790 +			STMW_REG(64, 6);
111.5791 +			STMW_REG(128, 7);
111.5792 +
111.5793 +			if (armMode == 0x11)
111.5794 +			{
111.5795 +				STMW_REG(256, R8_FIQ);
111.5796 +				STMW_REG(512, R9_FIQ);
111.5797 +				STMW_REG(1024, R10_FIQ);
111.5798 +				STMW_REG(2048, R11_FIQ);
111.5799 +				STMW_REG(4096, R12_FIQ);
111.5800 +			}
111.5801 +			else
111.5802 +			{
111.5803 +				STMW_REG(256, 8);
111.5804 +				STMW_REG(512, 9);
111.5805 +				STMW_REG(1024, 10);
111.5806 +				STMW_REG(2048, 11);
111.5807 +				STMW_REG(4096, 12);
111.5808 +			}
111.5809 +
111.5810 +			if (armMode != 0x10 && armMode != 0x1f)
111.5811 +			{
111.5812 +				STMW_REG(8192, R13_USR);
111.5813 +				STMW_REG(16384, R14_USR);
111.5814 +			}
111.5815 +			else
111.5816 +			{
111.5817 +				STMW_REG(8192, 13);
111.5818 +				STMW_REG(16384, 14);
111.5819 +			}
111.5820 +
111.5821 +			if (opcode & 32768)
111.5822 +			{
111.5823 +				CPUWriteMemory(address, reg[15].I + 4);
111.5824 +				if (!offset)
111.5825 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.5826 +				else
111.5827 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.5828 +				reg[base].I = temp;
111.5829 +			}
111.5830 +		}
111.5831 +		break;
111.5832 +
111.5833 +		CASE_16(0x880)
111.5834 +		{
111.5835 +			// STMIA Rn, {Rlist}
111.5836 +			int base	= (opcode & 0x000F0000) >> 16;
111.5837 +			u32 address = reg[base].I & 0xFFFFFFFC;
111.5838 +			clockTicks += 2;
111.5839 +			int offset = 0;
111.5840 +			STM_REG(1, 0);
111.5841 +			STM_REG(2, 1);
111.5842 +			STM_REG(4, 2);
111.5843 +			STM_REG(8, 3);
111.5844 +			STM_REG(16, 4);
111.5845 +			STM_REG(32, 5);
111.5846 +			STM_REG(64, 6);
111.5847 +			STM_REG(128, 7);
111.5848 +			STM_REG(256, 8);
111.5849 +			STM_REG(512, 9);
111.5850 +			STM_REG(1024, 10);
111.5851 +			STM_REG(2048, 11);
111.5852 +			STM_REG(4096, 12);
111.5853 +			STM_REG(8192, 13);
111.5854 +			STM_REG(16384, 14);
111.5855 +			if (opcode & 32768)
111.5856 +			{
111.5857 +				CPUWriteMemory(address, reg[15].I + 4);
111.5858 +				if (!offset)
111.5859 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.5860 +				else
111.5861 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.5862 +			}
111.5863 +		}
111.5864 +		break;
111.5865 +		CASE_16(0x8a0)
111.5866 +		{
111.5867 +			// STMIA Rn!, {Rlist}
111.5868 +			int base	= (opcode & 0x000F0000) >> 16;
111.5869 +			u32 address = reg[base].I & 0xFFFFFFFC;
111.5870 +			clockTicks += 2;
111.5871 +			int offset = 0;
111.5872 +			u32 temp   = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] +
111.5873 +			                                cpuBitsSet[(opcode >> 8) & 255]);
111.5874 +			STMW_REG(1, 0);
111.5875 +			STMW_REG(2, 1);
111.5876 +			STMW_REG(4, 2);
111.5877 +			STMW_REG(8, 3);
111.5878 +			STMW_REG(16, 4);
111.5879 +			STMW_REG(32, 5);
111.5880 +			STMW_REG(64, 6);
111.5881 +			STMW_REG(128, 7);
111.5882 +			STMW_REG(256, 8);
111.5883 +			STMW_REG(512, 9);
111.5884 +			STMW_REG(1024, 10);
111.5885 +			STMW_REG(2048, 11);
111.5886 +			STMW_REG(4096, 12);
111.5887 +			STMW_REG(8192, 13);
111.5888 +			STMW_REG(16384, 14);
111.5889 +			if (opcode & 32768)
111.5890 +			{
111.5891 +				CPUWriteMemory(address, reg[15].I + 4);
111.5892 +				if (!offset)
111.5893 +				{
111.5894 +					reg[base].I = temp;
111.5895 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.5896 +				}
111.5897 +				else
111.5898 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.5899 +			}
111.5900 +		}
111.5901 +		break;
111.5902 +		CASE_16(0x8c0)
111.5903 +		{
111.5904 +			// STMIA Rn, {Rlist}^
111.5905 +			int base	= (opcode & 0x000F0000) >> 16;
111.5906 +			u32 address = reg[base].I & 0xFFFFFFFC;
111.5907 +			clockTicks += 2;
111.5908 +			int offset = 0;
111.5909 +			STM_REG(1, 0);
111.5910 +			STM_REG(2, 1);
111.5911 +			STM_REG(4, 2);
111.5912 +			STM_REG(8, 3);
111.5913 +			STM_REG(16, 4);
111.5914 +			STM_REG(32, 5);
111.5915 +			STM_REG(64, 6);
111.5916 +			STM_REG(128, 7);
111.5917 +			if (armMode == 0x11)
111.5918 +			{
111.5919 +				STM_REG(256, R8_FIQ);
111.5920 +				STM_REG(512, R9_FIQ);
111.5921 +				STM_REG(1024, R10_FIQ);
111.5922 +				STM_REG(2048, R11_FIQ);
111.5923 +				STM_REG(4096, R12_FIQ);
111.5924 +			}
111.5925 +			else
111.5926 +			{
111.5927 +				STM_REG(256, 8);
111.5928 +				STM_REG(512, 9);
111.5929 +				STM_REG(1024, 10);
111.5930 +				STM_REG(2048, 11);
111.5931 +				STM_REG(4096, 12);
111.5932 +			}
111.5933 +			if (armMode != 0x10 && armMode != 0x1f)
111.5934 +			{
111.5935 +				STM_REG(8192, R13_USR);
111.5936 +				STM_REG(16384, R14_USR);
111.5937 +			}
111.5938 +			else
111.5939 +			{
111.5940 +				STM_REG(8192, 13);
111.5941 +				STM_REG(16384, 14);
111.5942 +			}
111.5943 +			if (opcode & 32768)
111.5944 +			{
111.5945 +				CPUWriteMemory(address, reg[15].I + 4);
111.5946 +				if (!offset)
111.5947 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.5948 +				else
111.5949 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.5950 +			}
111.5951 +		}
111.5952 +		break;
111.5953 +		CASE_16(0x8e0)
111.5954 +		{
111.5955 +			// STMIA Rn!, {Rlist}^
111.5956 +			int base	= (opcode & 0x000F0000) >> 16;
111.5957 +			u32 address = reg[base].I & 0xFFFFFFFC;
111.5958 +			clockTicks += 2;
111.5959 +			int offset = 0;
111.5960 +			u32 temp   = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] +
111.5961 +			                                cpuBitsSet[(opcode >> 8) & 255]);
111.5962 +			STMW_REG(1, 0);
111.5963 +			STMW_REG(2, 1);
111.5964 +			STMW_REG(4, 2);
111.5965 +			STMW_REG(8, 3);
111.5966 +			STMW_REG(16, 4);
111.5967 +			STMW_REG(32, 5);
111.5968 +			STMW_REG(64, 6);
111.5969 +			STMW_REG(128, 7);
111.5970 +			if (armMode == 0x11)
111.5971 +			{
111.5972 +				STMW_REG(256, R8_FIQ);
111.5973 +				STMW_REG(512, R9_FIQ);
111.5974 +				STMW_REG(1024, R10_FIQ);
111.5975 +				STMW_REG(2048, R11_FIQ);
111.5976 +				STMW_REG(4096, R12_FIQ);
111.5977 +			}
111.5978 +			else
111.5979 +			{
111.5980 +				STMW_REG(256, 8);
111.5981 +				STMW_REG(512, 9);
111.5982 +				STMW_REG(1024, 10);
111.5983 +				STMW_REG(2048, 11);
111.5984 +				STMW_REG(4096, 12);
111.5985 +			}
111.5986 +			if (armMode != 0x10 && armMode != 0x1f)
111.5987 +			{
111.5988 +				STMW_REG(8192, R13_USR);
111.5989 +				STMW_REG(16384, R14_USR);
111.5990 +			}
111.5991 +			else
111.5992 +			{
111.5993 +				STMW_REG(8192, 13);
111.5994 +				STMW_REG(16384, 14);
111.5995 +			}
111.5996 +			if (opcode & 32768)
111.5997 +			{
111.5998 +				CPUWriteMemory(address, reg[15].I + 4);
111.5999 +				if (!offset)
111.6000 +				{
111.6001 +					reg[base].I = temp;
111.6002 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.6003 +				}
111.6004 +				else
111.6005 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.6006 +			}
111.6007 +		}
111.6008 +		break;
111.6009 +
111.6010 +		CASE_16(0x900)
111.6011 +		{
111.6012 +			// STMDB Rn, {Rlist}
111.6013 +			int base = (opcode & 0x000F0000) >> 16;
111.6014 +			u32 temp = reg[base].I -
111.6015 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.6016 +			u32 address = temp & 0xFFFFFFFC;
111.6017 +			clockTicks += 2;
111.6018 +			int offset = 0;
111.6019 +			STM_REG(1, 0);
111.6020 +			STM_REG(2, 1);
111.6021 +			STM_REG(4, 2);
111.6022 +			STM_REG(8, 3);
111.6023 +			STM_REG(16, 4);
111.6024 +			STM_REG(32, 5);
111.6025 +			STM_REG(64, 6);
111.6026 +			STM_REG(128, 7);
111.6027 +			STM_REG(256, 8);
111.6028 +			STM_REG(512, 9);
111.6029 +			STM_REG(1024, 10);
111.6030 +			STM_REG(2048, 11);
111.6031 +			STM_REG(4096, 12);
111.6032 +			STM_REG(8192, 13);
111.6033 +			STM_REG(16384, 14);
111.6034 +			if (opcode & 32768)
111.6035 +			{
111.6036 +				CPUWriteMemory(address, reg[15].I + 4);
111.6037 +				if (!offset)
111.6038 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.6039 +				else
111.6040 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.6041 +			}
111.6042 +		}
111.6043 +		break;
111.6044 +		CASE_16(0x920)
111.6045 +		{
111.6046 +			// STMDB Rn!, {Rlist}
111.6047 +			int base = (opcode & 0x000F0000) >> 16;
111.6048 +			u32 temp = reg[base].I -
111.6049 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.6050 +			u32 address = temp & 0xFFFFFFFC;
111.6051 +			clockTicks += 2;
111.6052 +			int offset = 0;
111.6053 +
111.6054 +			STMW_REG(1, 0);
111.6055 +			STMW_REG(2, 1);
111.6056 +			STMW_REG(4, 2);
111.6057 +			STMW_REG(8, 3);
111.6058 +			STMW_REG(16, 4);
111.6059 +			STMW_REG(32, 5);
111.6060 +			STMW_REG(64, 6);
111.6061 +			STMW_REG(128, 7);
111.6062 +			STMW_REG(256, 8);
111.6063 +			STMW_REG(512, 9);
111.6064 +			STMW_REG(1024, 10);
111.6065 +			STMW_REG(2048, 11);
111.6066 +			STMW_REG(4096, 12);
111.6067 +			STMW_REG(8192, 13);
111.6068 +			STMW_REG(16384, 14);
111.6069 +			if (opcode & 32768)
111.6070 +			{
111.6071 +				CPUWriteMemory(address, reg[15].I + 4);
111.6072 +				if (!offset)
111.6073 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.6074 +				else
111.6075 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.6076 +				reg[base].I = temp;
111.6077 +			}
111.6078 +		}
111.6079 +		break;
111.6080 +		CASE_16(0x940)
111.6081 +		{
111.6082 +			// STMDB Rn, {Rlist}^
111.6083 +			int base = (opcode & 0x000F0000) >> 16;
111.6084 +			u32 temp = reg[base].I -
111.6085 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.6086 +			u32 address = temp & 0xFFFFFFFC;
111.6087 +			clockTicks += 2;
111.6088 +			int offset = 0;
111.6089 +
111.6090 +			STM_REG(1, 0);
111.6091 +			STM_REG(2, 1);
111.6092 +			STM_REG(4, 2);
111.6093 +			STM_REG(8, 3);
111.6094 +			STM_REG(16, 4);
111.6095 +			STM_REG(32, 5);
111.6096 +			STM_REG(64, 6);
111.6097 +			STM_REG(128, 7);
111.6098 +
111.6099 +			if (armMode == 0x11)
111.6100 +			{
111.6101 +				STM_REG(256, R8_FIQ);
111.6102 +				STM_REG(512, R9_FIQ);
111.6103 +				STM_REG(1024, R10_FIQ);
111.6104 +				STM_REG(2048, R11_FIQ);
111.6105 +				STM_REG(4096, R12_FIQ);
111.6106 +			}
111.6107 +			else
111.6108 +			{
111.6109 +				STM_REG(256, 8);
111.6110 +				STM_REG(512, 9);
111.6111 +				STM_REG(1024, 10);
111.6112 +				STM_REG(2048, 11);
111.6113 +				STM_REG(4096, 12);
111.6114 +			}
111.6115 +
111.6116 +			if (armMode != 0x10 && armMode != 0x1f)
111.6117 +			{
111.6118 +				STM_REG(8192, R13_USR);
111.6119 +				STM_REG(16384, R14_USR);
111.6120 +			}
111.6121 +			else
111.6122 +			{
111.6123 +				STM_REG(8192, 13);
111.6124 +				STM_REG(16384, 14);
111.6125 +			}
111.6126 +
111.6127 +			if (opcode & 32768)
111.6128 +			{
111.6129 +				CPUWriteMemory(address, reg[15].I + 4);
111.6130 +				if (!offset)
111.6131 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.6132 +				else
111.6133 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.6134 +			}
111.6135 +		}
111.6136 +		break;
111.6137 +		CASE_16(0x960)
111.6138 +		{
111.6139 +			// STMDB Rn!, {Rlist}^
111.6140 +			int base = (opcode & 0x000F0000) >> 16;
111.6141 +			u32 temp = reg[base].I -
111.6142 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.6143 +			u32 address = temp & 0xFFFFFFFC;
111.6144 +			clockTicks += 2;
111.6145 +			int offset = 0;
111.6146 +
111.6147 +			STMW_REG(1, 0);
111.6148 +			STMW_REG(2, 1);
111.6149 +			STMW_REG(4, 2);
111.6150 +			STMW_REG(8, 3);
111.6151 +			STMW_REG(16, 4);
111.6152 +			STMW_REG(32, 5);
111.6153 +			STMW_REG(64, 6);
111.6154 +			STMW_REG(128, 7);
111.6155 +
111.6156 +			if (armMode == 0x11)
111.6157 +			{
111.6158 +				STMW_REG(256, R8_FIQ);
111.6159 +				STMW_REG(512, R9_FIQ);
111.6160 +				STMW_REG(1024, R10_FIQ);
111.6161 +				STMW_REG(2048, R11_FIQ);
111.6162 +				STMW_REG(4096, R12_FIQ);
111.6163 +			}
111.6164 +			else
111.6165 +			{
111.6166 +				STMW_REG(256, 8);
111.6167 +				STMW_REG(512, 9);
111.6168 +				STMW_REG(1024, 10);
111.6169 +				STMW_REG(2048, 11);
111.6170 +				STMW_REG(4096, 12);
111.6171 +			}
111.6172 +
111.6173 +			if (armMode != 0x10 && armMode != 0x1f)
111.6174 +			{
111.6175 +				STMW_REG(8192, R13_USR);
111.6176 +				STMW_REG(16384, R14_USR);
111.6177 +			}
111.6178 +			else
111.6179 +			{
111.6180 +				STMW_REG(8192, 13);
111.6181 +				STMW_REG(16384, 14);
111.6182 +			}
111.6183 +
111.6184 +			if (opcode & 32768)
111.6185 +			{
111.6186 +				CPUWriteMemory(address, reg[15].I + 4);
111.6187 +				if (!offset)
111.6188 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.6189 +				else
111.6190 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.6191 +				reg[base].I = temp;
111.6192 +			}
111.6193 +		}
111.6194 +		break;
111.6195 +
111.6196 +		CASE_16(0x980)
111.6197 +		// STMIB Rn, {Rlist}
111.6198 +		{
111.6199 +			int base	= (opcode & 0x000F0000) >> 16;
111.6200 +			u32 address = (reg[base].I + 4) & 0xFFFFFFFC;
111.6201 +			clockTicks += 2;
111.6202 +			int offset = 0;
111.6203 +			STM_REG(1, 0);
111.6204 +			STM_REG(2, 1);
111.6205 +			STM_REG(4, 2);
111.6206 +			STM_REG(8, 3);
111.6207 +			STM_REG(16, 4);
111.6208 +			STM_REG(32, 5);
111.6209 +			STM_REG(64, 6);
111.6210 +			STM_REG(128, 7);
111.6211 +			STM_REG(256, 8);
111.6212 +			STM_REG(512, 9);
111.6213 +			STM_REG(1024, 10);
111.6214 +			STM_REG(2048, 11);
111.6215 +			STM_REG(4096, 12);
111.6216 +			STM_REG(8192, 13);
111.6217 +			STM_REG(16384, 14);
111.6218 +			if (opcode & 32768)
111.6219 +			{
111.6220 +				CPUWriteMemory(address, reg[15].I + 4);
111.6221 +				if (!offset)
111.6222 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.6223 +				else
111.6224 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.6225 +			}
111.6226 +		}
111.6227 +		break;
111.6228 +		CASE_16(0x9a0)
111.6229 +		{
111.6230 +			// STMIB Rn!, {Rlist}
111.6231 +			int base	= (opcode & 0x000F0000) >> 16;
111.6232 +			u32 address = (reg[base].I + 4) & 0xFFFFFFFC;
111.6233 +			clockTicks += 2;
111.6234 +			int offset = 0;
111.6235 +			u32 temp   = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] +
111.6236 +			                                cpuBitsSet[(opcode >> 8) & 255]);
111.6237 +			STMW_REG(1, 0);
111.6238 +			STMW_REG(2, 1);
111.6239 +			STMW_REG(4, 2);
111.6240 +			STMW_REG(8, 3);
111.6241 +			STMW_REG(16, 4);
111.6242 +			STMW_REG(32, 5);
111.6243 +			STMW_REG(64, 6);
111.6244 +			STMW_REG(128, 7);
111.6245 +			STMW_REG(256, 8);
111.6246 +			STMW_REG(512, 9);
111.6247 +			STMW_REG(1024, 10);
111.6248 +			STMW_REG(2048, 11);
111.6249 +			STMW_REG(4096, 12);
111.6250 +			STMW_REG(8192, 13);
111.6251 +			STMW_REG(16384, 14);
111.6252 +			if (opcode & 32768)
111.6253 +			{
111.6254 +				CPUWriteMemory(address, reg[15].I + 4);
111.6255 +				if (!offset)
111.6256 +				{
111.6257 +					reg[base].I = temp;
111.6258 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.6259 +				}
111.6260 +				else
111.6261 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.6262 +			}
111.6263 +		}
111.6264 +		break;
111.6265 +		CASE_16(0x9c0)
111.6266 +		{
111.6267 +			// STMIB Rn, {Rlist}^
111.6268 +			int base	= (opcode & 0x000F0000) >> 16;
111.6269 +			u32 address = (reg[base].I + 4) & 0xFFFFFFFC;
111.6270 +			clockTicks += 2;
111.6271 +			int offset = 0;
111.6272 +			STM_REG(1, 0);
111.6273 +			STM_REG(2, 1);
111.6274 +			STM_REG(4, 2);
111.6275 +			STM_REG(8, 3);
111.6276 +			STM_REG(16, 4);
111.6277 +			STM_REG(32, 5);
111.6278 +			STM_REG(64, 6);
111.6279 +			STM_REG(128, 7);
111.6280 +			if (armMode == 0x11)
111.6281 +			{
111.6282 +				STM_REG(256, R8_FIQ);
111.6283 +				STM_REG(512, R9_FIQ);
111.6284 +				STM_REG(1024, R10_FIQ);
111.6285 +				STM_REG(2048, R11_FIQ);
111.6286 +				STM_REG(4096, R12_FIQ);
111.6287 +			}
111.6288 +			else
111.6289 +			{
111.6290 +				STM_REG(256, 8);
111.6291 +				STM_REG(512, 9);
111.6292 +				STM_REG(1024, 10);
111.6293 +				STM_REG(2048, 11);
111.6294 +				STM_REG(4096, 12);
111.6295 +			}
111.6296 +			if (armMode != 0x10 && armMode != 0x1f)
111.6297 +			{
111.6298 +				STM_REG(8192, R13_USR);
111.6299 +				STM_REG(16384, R14_USR);
111.6300 +			}
111.6301 +			else
111.6302 +			{
111.6303 +				STM_REG(8192, 13);
111.6304 +				STM_REG(16384, 14);
111.6305 +			}
111.6306 +			if (opcode & 32768)
111.6307 +			{
111.6308 +				CPUWriteMemory(address, reg[15].I + 4);
111.6309 +				if (!offset)
111.6310 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.6311 +				else
111.6312 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.6313 +			}
111.6314 +		}
111.6315 +		break;
111.6316 +		CASE_16(0x9e0)
111.6317 +		{
111.6318 +			// STMIB Rn!, {Rlist}^
111.6319 +			int base	= (opcode & 0x000F0000) >> 16;
111.6320 +			u32 address = (reg[base].I + 4) & 0xFFFFFFFC;
111.6321 +			clockTicks += 2;
111.6322 +			int offset = 0;
111.6323 +			u32 temp   = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] +
111.6324 +			                                cpuBitsSet[(opcode >> 8) & 255]);
111.6325 +			STMW_REG(1, 0);
111.6326 +			STMW_REG(2, 1);
111.6327 +			STMW_REG(4, 2);
111.6328 +			STMW_REG(8, 3);
111.6329 +			STMW_REG(16, 4);
111.6330 +			STMW_REG(32, 5);
111.6331 +			STMW_REG(64, 6);
111.6332 +			STMW_REG(128, 7);
111.6333 +			if (armMode == 0x11)
111.6334 +			{
111.6335 +				STMW_REG(256, R8_FIQ);
111.6336 +				STMW_REG(512, R9_FIQ);
111.6337 +				STMW_REG(1024, R10_FIQ);
111.6338 +				STMW_REG(2048, R11_FIQ);
111.6339 +				STMW_REG(4096, R12_FIQ);
111.6340 +			}
111.6341 +			else
111.6342 +			{
111.6343 +				STMW_REG(256, 8);
111.6344 +				STMW_REG(512, 9);
111.6345 +				STMW_REG(1024, 10);
111.6346 +				STMW_REG(2048, 11);
111.6347 +				STMW_REG(4096, 12);
111.6348 +			}
111.6349 +			if (armMode != 0x10 && armMode != 0x1f)
111.6350 +			{
111.6351 +				STMW_REG(8192, R13_USR);
111.6352 +				STMW_REG(16384, R14_USR);
111.6353 +			}
111.6354 +			else
111.6355 +			{
111.6356 +				STMW_REG(8192, 13);
111.6357 +				STMW_REG(16384, 14);
111.6358 +			}
111.6359 +			if (opcode & 32768)
111.6360 +			{
111.6361 +				CPUWriteMemory(address, reg[15].I + 4);
111.6362 +				if (!offset)
111.6363 +				{
111.6364 +					reg[base].I = temp;
111.6365 +					clockTicks += 1 + CPUUpdateTicksAccess32(address);
111.6366 +				}
111.6367 +				else
111.6368 +					clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);
111.6369 +			}
111.6370 +		}
111.6371 +		break;
111.6372 +
111.6373 +#define LDM_REG(val, num) \
111.6374 +	if (opcode & (val)) { \
111.6375 +		reg[(num)].I = CPUReadMemory(address); \
111.6376 +		if (offset) \
111.6377 +			clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); \
111.6378 +		else { \
111.6379 +			clockTicks += 1 + CPUUpdateTicksAccess32(address); \
111.6380 +			offset		= 1; \
111.6381 +		} \
111.6382 +		address += 4; \
111.6383 +	}
111.6384 +
111.6385 +		CASE_16(0x810)
111.6386 +		{
111.6387 +			// LDMDA Rn, {Rlist}
111.6388 +			int base = (opcode & 0x000F0000) >> 16;
111.6389 +			u32 temp = reg[base].I -
111.6390 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.6391 +			u32 address = (temp + 4) & 0xFFFFFFFC;
111.6392 +			clockTicks += 2;
111.6393 +			int offset = 0;
111.6394 +			LDM_REG(1, 0);
111.6395 +			LDM_REG(2, 1);
111.6396 +			LDM_REG(4, 2);
111.6397 +			LDM_REG(8, 3);
111.6398 +			LDM_REG(16, 4);
111.6399 +			LDM_REG(32, 5);
111.6400 +			LDM_REG(64, 6);
111.6401 +			LDM_REG(128, 7);
111.6402 +			LDM_REG(256, 8);
111.6403 +			LDM_REG(512, 9);
111.6404 +			LDM_REG(1024, 10);
111.6405 +			LDM_REG(2048, 11);
111.6406 +			LDM_REG(4096, 12);
111.6407 +			LDM_REG(8192, 13);
111.6408 +			LDM_REG(16384, 14);
111.6409 +			if (opcode & 32768)
111.6410 +			{
111.6411 +				reg[15].I = CPUReadMemory(address);
111.6412 +				if (!offset)
111.6413 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.6414 +				else
111.6415 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.6416 +				armNextPC  = reg[15].I;
111.6417 +				reg[15].I += 4;
111.6418 +			}
111.6419 +		}
111.6420 +		break;
111.6421 +		CASE_16(0x830)
111.6422 +		{
111.6423 +			// LDMDA Rn!, {Rlist}
111.6424 +			int base = (opcode & 0x000F0000) >> 16;
111.6425 +			u32 temp = reg[base].I -
111.6426 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.6427 +			u32 address = (temp + 4) & 0xFFFFFFFC;
111.6428 +			clockTicks += 2;
111.6429 +			int offset = 0;
111.6430 +			LDM_REG(1, 0);
111.6431 +			LDM_REG(2, 1);
111.6432 +			LDM_REG(4, 2);
111.6433 +			LDM_REG(8, 3);
111.6434 +			LDM_REG(16, 4);
111.6435 +			LDM_REG(32, 5);
111.6436 +			LDM_REG(64, 6);
111.6437 +			LDM_REG(128, 7);
111.6438 +			LDM_REG(256, 8);
111.6439 +			LDM_REG(512, 9);
111.6440 +			LDM_REG(1024, 10);
111.6441 +			LDM_REG(2048, 11);
111.6442 +			LDM_REG(4096, 12);
111.6443 +			LDM_REG(8192, 13);
111.6444 +			LDM_REG(16384, 14);
111.6445 +			if (opcode & 32768)
111.6446 +			{
111.6447 +				reg[15].I = CPUReadMemory(address);
111.6448 +				if (!offset)
111.6449 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.6450 +				else
111.6451 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.6452 +				armNextPC  = reg[15].I;
111.6453 +				reg[15].I += 4;
111.6454 +			}
111.6455 +			if (!(opcode & (1 << base)))
111.6456 +				reg[base].I = temp;
111.6457 +		}
111.6458 +		break;
111.6459 +		CASE_16(0x850)
111.6460 +		{
111.6461 +			// LDMDA Rn, {Rlist}^
111.6462 +			int base = (opcode & 0x000F0000) >> 16;
111.6463 +			u32 temp = reg[base].I -
111.6464 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.6465 +			u32 address = (temp + 4) & 0xFFFFFFFC;
111.6466 +			clockTicks += 2;
111.6467 +			int offset = 0;
111.6468 +			if (opcode & 0x8000)
111.6469 +			{
111.6470 +				LDM_REG(1, 0);
111.6471 +				LDM_REG(2, 1);
111.6472 +				LDM_REG(4, 2);
111.6473 +				LDM_REG(8, 3);
111.6474 +				LDM_REG(16, 4);
111.6475 +				LDM_REG(32, 5);
111.6476 +				LDM_REG(64, 6);
111.6477 +				LDM_REG(128, 7);
111.6478 +				LDM_REG(256, 8);
111.6479 +				LDM_REG(512, 9);
111.6480 +				LDM_REG(1024, 10);
111.6481 +				LDM_REG(2048, 11);
111.6482 +				LDM_REG(4096, 12);
111.6483 +				LDM_REG(8192, 13);
111.6484 +				LDM_REG(16384, 14);
111.6485 +
111.6486 +				reg[15].I = CPUReadMemory(address);
111.6487 +				if (!offset)
111.6488 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.6489 +				else
111.6490 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.6491 +
111.6492 +				CPUSwitchMode(reg[17].I & 0x1f, false);
111.6493 +				if (armState)
111.6494 +				{
111.6495 +					armNextPC = reg[15].I & 0xFFFFFFFC;
111.6496 +					reg[15].I = armNextPC + 4;
111.6497 +				}
111.6498 +				else
111.6499 +				{
111.6500 +					armNextPC = reg[15].I & 0xFFFFFFFE;
111.6501 +					reg[15].I = armNextPC + 2;
111.6502 +				}
111.6503 +			}
111.6504 +			else
111.6505 +			{
111.6506 +				LDM_REG(1, 0);
111.6507 +				LDM_REG(2, 1);
111.6508 +				LDM_REG(4, 2);
111.6509 +				LDM_REG(8, 3);
111.6510 +				LDM_REG(16, 4);
111.6511 +				LDM_REG(32, 5);
111.6512 +				LDM_REG(64, 6);
111.6513 +				LDM_REG(128, 7);
111.6514 +
111.6515 +				if (armMode == 0x11)
111.6516 +				{
111.6517 +					LDM_REG(256, R8_FIQ);
111.6518 +					LDM_REG(512, R9_FIQ);
111.6519 +					LDM_REG(1024, R10_FIQ);
111.6520 +					LDM_REG(2048, R11_FIQ);
111.6521 +					LDM_REG(4096, R12_FIQ);
111.6522 +				}
111.6523 +				else
111.6524 +				{
111.6525 +					LDM_REG(256, 8);
111.6526 +					LDM_REG(512, 9);
111.6527 +					LDM_REG(1024, 10);
111.6528 +					LDM_REG(2048, 11);
111.6529 +					LDM_REG(4096, 12);
111.6530 +				}
111.6531 +
111.6532 +				if (armMode != 0x10 && armMode != 0x1f)
111.6533 +				{
111.6534 +					LDM_REG(8192, R13_USR);
111.6535 +					LDM_REG(16384, R14_USR);
111.6536 +				}
111.6537 +				else
111.6538 +				{
111.6539 +					LDM_REG(8192, 13);
111.6540 +					LDM_REG(16384, 14);
111.6541 +				}
111.6542 +			}
111.6543 +		}
111.6544 +		break;
111.6545 +		CASE_16(0x870)
111.6546 +		{
111.6547 +			// LDMDA Rn!, {Rlist}^
111.6548 +			int base = (opcode & 0x000F0000) >> 16;
111.6549 +			u32 temp = reg[base].I -
111.6550 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.6551 +			u32 address = (temp + 4) & 0xFFFFFFFC;
111.6552 +			clockTicks += 2;
111.6553 +			int offset = 0;
111.6554 +			if (opcode & 0x8000)
111.6555 +			{
111.6556 +				LDM_REG(1, 0);
111.6557 +				LDM_REG(2, 1);
111.6558 +				LDM_REG(4, 2);
111.6559 +				LDM_REG(8, 3);
111.6560 +				LDM_REG(16, 4);
111.6561 +				LDM_REG(32, 5);
111.6562 +				LDM_REG(64, 6);
111.6563 +				LDM_REG(128, 7);
111.6564 +				LDM_REG(256, 8);
111.6565 +				LDM_REG(512, 9);
111.6566 +				LDM_REG(1024, 10);
111.6567 +				LDM_REG(2048, 11);
111.6568 +				LDM_REG(4096, 12);
111.6569 +				LDM_REG(8192, 13);
111.6570 +				LDM_REG(16384, 14);
111.6571 +
111.6572 +				reg[15].I = CPUReadMemory(address);
111.6573 +				if (!offset)
111.6574 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.6575 +				else
111.6576 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.6577 +
111.6578 +				if (!(opcode & (1 << base)))
111.6579 +					reg[base].I = temp;
111.6580 +
111.6581 +				CPUSwitchMode(reg[17].I & 0x1f, false);
111.6582 +				if (armState)
111.6583 +				{
111.6584 +					armNextPC = reg[15].I & 0xFFFFFFFC;
111.6585 +					reg[15].I = armNextPC + 4;
111.6586 +				}
111.6587 +				else
111.6588 +				{
111.6589 +					armNextPC = reg[15].I & 0xFFFFFFFE;
111.6590 +					reg[15].I = armNextPC + 2;
111.6591 +				}
111.6592 +			}
111.6593 +			else
111.6594 +			{
111.6595 +				LDM_REG(1, 0);
111.6596 +				LDM_REG(2, 1);
111.6597 +				LDM_REG(4, 2);
111.6598 +				LDM_REG(8, 3);
111.6599 +				LDM_REG(16, 4);
111.6600 +				LDM_REG(32, 5);
111.6601 +				LDM_REG(64, 6);
111.6602 +				LDM_REG(128, 7);
111.6603 +
111.6604 +				if (armMode == 0x11)
111.6605 +				{
111.6606 +					LDM_REG(256, R8_FIQ);
111.6607 +					LDM_REG(512, R9_FIQ);
111.6608 +					LDM_REG(1024, R10_FIQ);
111.6609 +					LDM_REG(2048, R11_FIQ);
111.6610 +					LDM_REG(4096, R12_FIQ);
111.6611 +				}
111.6612 +				else
111.6613 +				{
111.6614 +					LDM_REG(256, 8);
111.6615 +					LDM_REG(512, 9);
111.6616 +					LDM_REG(1024, 10);
111.6617 +					LDM_REG(2048, 11);
111.6618 +					LDM_REG(4096, 12);
111.6619 +				}
111.6620 +
111.6621 +				if (armMode != 0x10 && armMode != 0x1f)
111.6622 +				{
111.6623 +					LDM_REG(8192, R13_USR);
111.6624 +					LDM_REG(16384, R14_USR);
111.6625 +				}
111.6626 +				else
111.6627 +				{
111.6628 +					LDM_REG(8192, 13);
111.6629 +					LDM_REG(16384, 14);
111.6630 +				}
111.6631 +
111.6632 +				if (!(opcode & (1 << base)))
111.6633 +					reg[base].I = temp;
111.6634 +			}
111.6635 +		}
111.6636 +		break;
111.6637 +
111.6638 +		CASE_16(0x890)
111.6639 +		{
111.6640 +			// LDMIA Rn, {Rlist}
111.6641 +			int base	= (opcode & 0x000F0000) >> 16;
111.6642 +			u32 address = reg[base].I & 0xFFFFFFFC;
111.6643 +			clockTicks += 2;
111.6644 +			int offset = 0;
111.6645 +			LDM_REG(1, 0);
111.6646 +			LDM_REG(2, 1);
111.6647 +			LDM_REG(4, 2);
111.6648 +			LDM_REG(8, 3);
111.6649 +			LDM_REG(16, 4);
111.6650 +			LDM_REG(32, 5);
111.6651 +			LDM_REG(64, 6);
111.6652 +			LDM_REG(128, 7);
111.6653 +			LDM_REG(256, 8);
111.6654 +			LDM_REG(512, 9);
111.6655 +			LDM_REG(1024, 10);
111.6656 +			LDM_REG(2048, 11);
111.6657 +			LDM_REG(4096, 12);
111.6658 +			LDM_REG(8192, 13);
111.6659 +			LDM_REG(16384, 14);
111.6660 +			if (opcode & 32768)
111.6661 +			{
111.6662 +				reg[15].I = CPUReadMemory(address);
111.6663 +				if (!offset)
111.6664 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.6665 +				else
111.6666 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.6667 +				armNextPC  = reg[15].I;
111.6668 +				reg[15].I += 4;
111.6669 +			}
111.6670 +		}
111.6671 +		break;
111.6672 +		CASE_16(0x8b0)
111.6673 +		{
111.6674 +			// LDMIA Rn!, {Rlist}
111.6675 +			int base = (opcode & 0x000F0000) >> 16;
111.6676 +			u32 temp = reg[base].I +
111.6677 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.6678 +			u32 address = reg[base].I & 0xFFFFFFFC;
111.6679 +			clockTicks += 2;
111.6680 +			int offset = 0;
111.6681 +			LDM_REG(1, 0);
111.6682 +			LDM_REG(2, 1);
111.6683 +			LDM_REG(4, 2);
111.6684 +			LDM_REG(8, 3);
111.6685 +			LDM_REG(16, 4);
111.6686 +			LDM_REG(32, 5);
111.6687 +			LDM_REG(64, 6);
111.6688 +			LDM_REG(128, 7);
111.6689 +			LDM_REG(256, 8);
111.6690 +			LDM_REG(512, 9);
111.6691 +			LDM_REG(1024, 10);
111.6692 +			LDM_REG(2048, 11);
111.6693 +			LDM_REG(4096, 12);
111.6694 +			LDM_REG(8192, 13);
111.6695 +			LDM_REG(16384, 14);
111.6696 +			if (opcode & 32768)
111.6697 +			{
111.6698 +				reg[15].I = CPUReadMemory(address);
111.6699 +				if (!offset)
111.6700 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.6701 +				else
111.6702 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.6703 +				armNextPC  = reg[15].I;
111.6704 +				reg[15].I += 4;
111.6705 +			}
111.6706 +			if (!(opcode & (1 << base)))
111.6707 +				reg[base].I = temp;
111.6708 +		}
111.6709 +		break;
111.6710 +		CASE_16(0x8d0)
111.6711 +		{
111.6712 +			// LDMIA Rn, {Rlist}^
111.6713 +			int base	= (opcode & 0x000F0000) >> 16;
111.6714 +			u32 address = reg[base].I & 0xFFFFFFFC;
111.6715 +			clockTicks += 2;
111.6716 +			int offset = 0;
111.6717 +			if (opcode & 0x8000)
111.6718 +			{
111.6719 +				LDM_REG(1, 0);
111.6720 +				LDM_REG(2, 1);
111.6721 +				LDM_REG(4, 2);
111.6722 +				LDM_REG(8, 3);
111.6723 +				LDM_REG(16, 4);
111.6724 +				LDM_REG(32, 5);
111.6725 +				LDM_REG(64, 6);
111.6726 +				LDM_REG(128, 7);
111.6727 +				LDM_REG(256, 8);
111.6728 +				LDM_REG(512, 9);
111.6729 +				LDM_REG(1024, 10);
111.6730 +				LDM_REG(2048, 11);
111.6731 +				LDM_REG(4096, 12);
111.6732 +				LDM_REG(8192, 13);
111.6733 +				LDM_REG(16384, 14);
111.6734 +
111.6735 +				reg[15].I = CPUReadMemory(address);
111.6736 +				if (!offset)
111.6737 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.6738 +				else
111.6739 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.6740 +
111.6741 +				CPUSwitchMode(reg[17].I & 0x1f, false);
111.6742 +				if (armState)
111.6743 +				{
111.6744 +					armNextPC = reg[15].I & 0xFFFFFFFC;
111.6745 +					reg[15].I = armNextPC + 4;
111.6746 +				}
111.6747 +				else
111.6748 +				{
111.6749 +					armNextPC = reg[15].I & 0xFFFFFFFE;
111.6750 +					reg[15].I = armNextPC + 2;
111.6751 +				}
111.6752 +			}
111.6753 +			else
111.6754 +			{
111.6755 +				LDM_REG(1, 0);
111.6756 +				LDM_REG(2, 1);
111.6757 +				LDM_REG(4, 2);
111.6758 +				LDM_REG(8, 3);
111.6759 +				LDM_REG(16, 4);
111.6760 +				LDM_REG(32, 5);
111.6761 +				LDM_REG(64, 6);
111.6762 +				LDM_REG(128, 7);
111.6763 +
111.6764 +				if (armMode == 0x11)
111.6765 +				{
111.6766 +					LDM_REG(256, R8_FIQ);
111.6767 +					LDM_REG(512, R9_FIQ);
111.6768 +					LDM_REG(1024, R10_FIQ);
111.6769 +					LDM_REG(2048, R11_FIQ);
111.6770 +					LDM_REG(4096, R12_FIQ);
111.6771 +				}
111.6772 +				else
111.6773 +				{
111.6774 +					LDM_REG(256, 8);
111.6775 +					LDM_REG(512, 9);
111.6776 +					LDM_REG(1024, 10);
111.6777 +					LDM_REG(2048, 11);
111.6778 +					LDM_REG(4096, 12);
111.6779 +				}
111.6780 +
111.6781 +				if (armMode != 0x10 && armMode != 0x1f)
111.6782 +				{
111.6783 +					LDM_REG(8192, R13_USR);
111.6784 +					LDM_REG(16384, R14_USR);
111.6785 +				}
111.6786 +				else
111.6787 +				{
111.6788 +					LDM_REG(8192, 13);
111.6789 +					LDM_REG(16384, 14);
111.6790 +				}
111.6791 +			}
111.6792 +		}
111.6793 +		break;
111.6794 +		CASE_16(0x8f0)
111.6795 +		{
111.6796 +			// LDMIA Rn!, {Rlist}^
111.6797 +			int base = (opcode & 0x000F0000) >> 16;
111.6798 +			u32 temp = reg[base].I +
111.6799 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.6800 +			u32 address = reg[base].I & 0xFFFFFFFC;
111.6801 +			clockTicks += 2;
111.6802 +			int offset = 0;
111.6803 +			if (opcode & 0x8000)
111.6804 +			{
111.6805 +				LDM_REG(1, 0);
111.6806 +				LDM_REG(2, 1);
111.6807 +				LDM_REG(4, 2);
111.6808 +				LDM_REG(8, 3);
111.6809 +				LDM_REG(16, 4);
111.6810 +				LDM_REG(32, 5);
111.6811 +				LDM_REG(64, 6);
111.6812 +				LDM_REG(128, 7);
111.6813 +				LDM_REG(256, 8);
111.6814 +				LDM_REG(512, 9);
111.6815 +				LDM_REG(1024, 10);
111.6816 +				LDM_REG(2048, 11);
111.6817 +				LDM_REG(4096, 12);
111.6818 +				LDM_REG(8192, 13);
111.6819 +				LDM_REG(16384, 14);
111.6820 +
111.6821 +				reg[15].I = CPUReadMemory(address);
111.6822 +				if (!offset)
111.6823 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.6824 +				else
111.6825 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.6826 +
111.6827 +				if (!(opcode & (1 << base)))
111.6828 +					reg[base].I = temp;
111.6829 +
111.6830 +				CPUSwitchMode(reg[17].I & 0x1f, false);
111.6831 +				if (armState)
111.6832 +				{
111.6833 +					armNextPC = reg[15].I & 0xFFFFFFFC;
111.6834 +					reg[15].I = armNextPC + 4;
111.6835 +				}
111.6836 +				else
111.6837 +				{
111.6838 +					armNextPC = reg[15].I & 0xFFFFFFFE;
111.6839 +					reg[15].I = armNextPC + 2;
111.6840 +				}
111.6841 +			}
111.6842 +			else
111.6843 +			{
111.6844 +				LDM_REG(1, 0);
111.6845 +				LDM_REG(2, 1);
111.6846 +				LDM_REG(4, 2);
111.6847 +				LDM_REG(8, 3);
111.6848 +				LDM_REG(16, 4);
111.6849 +				LDM_REG(32, 5);
111.6850 +				LDM_REG(64, 6);
111.6851 +				LDM_REG(128, 7);
111.6852 +
111.6853 +				if (armMode == 0x11)
111.6854 +				{
111.6855 +					LDM_REG(256, R8_FIQ);
111.6856 +					LDM_REG(512, R9_FIQ);
111.6857 +					LDM_REG(1024, R10_FIQ);
111.6858 +					LDM_REG(2048, R11_FIQ);
111.6859 +					LDM_REG(4096, R12_FIQ);
111.6860 +				}
111.6861 +				else
111.6862 +				{
111.6863 +					LDM_REG(256, 8);
111.6864 +					LDM_REG(512, 9);
111.6865 +					LDM_REG(1024, 10);
111.6866 +					LDM_REG(2048, 11);
111.6867 +					LDM_REG(4096, 12);
111.6868 +				}
111.6869 +
111.6870 +				if (armMode != 0x10 && armMode != 0x1f)
111.6871 +				{
111.6872 +					LDM_REG(8192, R13_USR);
111.6873 +					LDM_REG(16384, R14_USR);
111.6874 +				}
111.6875 +				else
111.6876 +				{
111.6877 +					LDM_REG(8192, 13);
111.6878 +					LDM_REG(16384, 14);
111.6879 +				}
111.6880 +
111.6881 +				if (!(opcode & (1 << base)))
111.6882 +					reg[base].I = temp;
111.6883 +			}
111.6884 +		}
111.6885 +		break;
111.6886 +
111.6887 +		CASE_16(0x910)
111.6888 +		{
111.6889 +			// LDMDB Rn, {Rlist}
111.6890 +			int base = (opcode & 0x000F0000) >> 16;
111.6891 +			u32 temp = reg[base].I -
111.6892 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.6893 +			u32 address = temp & 0xFFFFFFFC;
111.6894 +			clockTicks += 2;
111.6895 +			int offset = 0;
111.6896 +			LDM_REG(1, 0);
111.6897 +			LDM_REG(2, 1);
111.6898 +			LDM_REG(4, 2);
111.6899 +			LDM_REG(8, 3);
111.6900 +			LDM_REG(16, 4);
111.6901 +			LDM_REG(32, 5);
111.6902 +			LDM_REG(64, 6);
111.6903 +			LDM_REG(128, 7);
111.6904 +			LDM_REG(256, 8);
111.6905 +			LDM_REG(512, 9);
111.6906 +			LDM_REG(1024, 10);
111.6907 +			LDM_REG(2048, 11);
111.6908 +			LDM_REG(4096, 12);
111.6909 +			LDM_REG(8192, 13);
111.6910 +			LDM_REG(16384, 14);
111.6911 +			if (opcode & 32768)
111.6912 +			{
111.6913 +				reg[15].I = CPUReadMemory(address);
111.6914 +				if (!offset)
111.6915 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.6916 +				else
111.6917 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.6918 +				armNextPC  = reg[15].I;
111.6919 +				reg[15].I += 4;
111.6920 +			}
111.6921 +		}
111.6922 +		break;
111.6923 +		CASE_16(0x930)
111.6924 +		{
111.6925 +			// LDMDB Rn!, {Rlist}
111.6926 +			int base = (opcode & 0x000F0000) >> 16;
111.6927 +			u32 temp = reg[base].I -
111.6928 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.6929 +			u32 address = temp & 0xFFFFFFFC;
111.6930 +			clockTicks += 2;
111.6931 +			int offset = 0;
111.6932 +			LDM_REG(1, 0);
111.6933 +			LDM_REG(2, 1);
111.6934 +			LDM_REG(4, 2);
111.6935 +			LDM_REG(8, 3);
111.6936 +			LDM_REG(16, 4);
111.6937 +			LDM_REG(32, 5);
111.6938 +			LDM_REG(64, 6);
111.6939 +			LDM_REG(128, 7);
111.6940 +			LDM_REG(256, 8);
111.6941 +			LDM_REG(512, 9);
111.6942 +			LDM_REG(1024, 10);
111.6943 +			LDM_REG(2048, 11);
111.6944 +			LDM_REG(4096, 12);
111.6945 +			LDM_REG(8192, 13);
111.6946 +			LDM_REG(16384, 14);
111.6947 +			if (opcode & 32768)
111.6948 +			{
111.6949 +				reg[15].I = CPUReadMemory(address);
111.6950 +				if (!offset)
111.6951 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.6952 +				else
111.6953 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.6954 +				armNextPC  = reg[15].I;
111.6955 +				reg[15].I += 4;
111.6956 +			}
111.6957 +			if (!(opcode & (1 << base)))
111.6958 +				reg[base].I = temp;
111.6959 +		}
111.6960 +		break;
111.6961 +		CASE_16(0x950)
111.6962 +		{
111.6963 +			// LDMDB Rn, {Rlist}^
111.6964 +			int base = (opcode & 0x000F0000) >> 16;
111.6965 +			u32 temp = reg[base].I -
111.6966 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.6967 +			u32 address = temp & 0xFFFFFFFC;
111.6968 +			clockTicks += 2;
111.6969 +			int offset = 0;
111.6970 +			if (opcode & 0x8000)
111.6971 +			{
111.6972 +				LDM_REG(1, 0);
111.6973 +				LDM_REG(2, 1);
111.6974 +				LDM_REG(4, 2);
111.6975 +				LDM_REG(8, 3);
111.6976 +				LDM_REG(16, 4);
111.6977 +				LDM_REG(32, 5);
111.6978 +				LDM_REG(64, 6);
111.6979 +				LDM_REG(128, 7);
111.6980 +				LDM_REG(256, 8);
111.6981 +				LDM_REG(512, 9);
111.6982 +				LDM_REG(1024, 10);
111.6983 +				LDM_REG(2048, 11);
111.6984 +				LDM_REG(4096, 12);
111.6985 +				LDM_REG(8192, 13);
111.6986 +				LDM_REG(16384, 14);
111.6987 +
111.6988 +				reg[15].I = CPUReadMemory(address);
111.6989 +				if (!offset)
111.6990 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.6991 +				else
111.6992 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.6993 +
111.6994 +				CPUSwitchMode(reg[17].I & 0x1f, false);
111.6995 +				if (armState)
111.6996 +				{
111.6997 +					armNextPC = reg[15].I & 0xFFFFFFFC;
111.6998 +					reg[15].I = armNextPC + 4;
111.6999 +				}
111.7000 +				else
111.7001 +				{
111.7002 +					armNextPC = reg[15].I & 0xFFFFFFFE;
111.7003 +					reg[15].I = armNextPC + 2;
111.7004 +				}
111.7005 +			}
111.7006 +			else
111.7007 +			{
111.7008 +				LDM_REG(1, 0);
111.7009 +				LDM_REG(2, 1);
111.7010 +				LDM_REG(4, 2);
111.7011 +				LDM_REG(8, 3);
111.7012 +				LDM_REG(16, 4);
111.7013 +				LDM_REG(32, 5);
111.7014 +				LDM_REG(64, 6);
111.7015 +				LDM_REG(128, 7);
111.7016 +
111.7017 +				if (armMode == 0x11)
111.7018 +				{
111.7019 +					LDM_REG(256, R8_FIQ);
111.7020 +					LDM_REG(512, R9_FIQ);
111.7021 +					LDM_REG(1024, R10_FIQ);
111.7022 +					LDM_REG(2048, R11_FIQ);
111.7023 +					LDM_REG(4096, R12_FIQ);
111.7024 +				}
111.7025 +				else
111.7026 +				{
111.7027 +					LDM_REG(256, 8);
111.7028 +					LDM_REG(512, 9);
111.7029 +					LDM_REG(1024, 10);
111.7030 +					LDM_REG(2048, 11);
111.7031 +					LDM_REG(4096, 12);
111.7032 +				}
111.7033 +
111.7034 +				if (armMode != 0x10 && armMode != 0x1f)
111.7035 +				{
111.7036 +					LDM_REG(8192, R13_USR);
111.7037 +					LDM_REG(16384, R14_USR);
111.7038 +				}
111.7039 +				else
111.7040 +				{
111.7041 +					LDM_REG(8192, 13);
111.7042 +					LDM_REG(16384, 14);
111.7043 +				}
111.7044 +			}
111.7045 +		}
111.7046 +		break;
111.7047 +		CASE_16(0x970)
111.7048 +		{
111.7049 +			// LDMDB Rn!, {Rlist}^
111.7050 +			int base = (opcode & 0x000F0000) >> 16;
111.7051 +			u32 temp = reg[base].I -
111.7052 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.7053 +			u32 address = temp & 0xFFFFFFFC;
111.7054 +			clockTicks += 2;
111.7055 +			int offset = 0;
111.7056 +			if (opcode & 0x8000)
111.7057 +			{
111.7058 +				LDM_REG(1, 0);
111.7059 +				LDM_REG(2, 1);
111.7060 +				LDM_REG(4, 2);
111.7061 +				LDM_REG(8, 3);
111.7062 +				LDM_REG(16, 4);
111.7063 +				LDM_REG(32, 5);
111.7064 +				LDM_REG(64, 6);
111.7065 +				LDM_REG(128, 7);
111.7066 +				LDM_REG(256, 8);
111.7067 +				LDM_REG(512, 9);
111.7068 +				LDM_REG(1024, 10);
111.7069 +				LDM_REG(2048, 11);
111.7070 +				LDM_REG(4096, 12);
111.7071 +				LDM_REG(8192, 13);
111.7072 +				LDM_REG(16384, 14);
111.7073 +
111.7074 +				reg[15].I = CPUReadMemory(address);
111.7075 +				if (!offset)
111.7076 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.7077 +				else
111.7078 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.7079 +
111.7080 +				if (!(opcode & (1 << base)))
111.7081 +					reg[base].I = temp;
111.7082 +
111.7083 +				CPUSwitchMode(reg[17].I & 0x1f, false);
111.7084 +				if (armState)
111.7085 +				{
111.7086 +					armNextPC = reg[15].I & 0xFFFFFFFC;
111.7087 +					reg[15].I = armNextPC + 4;
111.7088 +				}
111.7089 +				else
111.7090 +				{
111.7091 +					armNextPC = reg[15].I & 0xFFFFFFFE;
111.7092 +					reg[15].I = armNextPC + 2;
111.7093 +				}
111.7094 +			}
111.7095 +			else
111.7096 +			{
111.7097 +				LDM_REG(1, 0);
111.7098 +				LDM_REG(2, 1);
111.7099 +				LDM_REG(4, 2);
111.7100 +				LDM_REG(8, 3);
111.7101 +				LDM_REG(16, 4);
111.7102 +				LDM_REG(32, 5);
111.7103 +				LDM_REG(64, 6);
111.7104 +				LDM_REG(128, 7);
111.7105 +
111.7106 +				if (armMode == 0x11)
111.7107 +				{
111.7108 +					LDM_REG(256, R8_FIQ);
111.7109 +					LDM_REG(512, R9_FIQ);
111.7110 +					LDM_REG(1024, R10_FIQ);
111.7111 +					LDM_REG(2048, R11_FIQ);
111.7112 +					LDM_REG(4096, R12_FIQ);
111.7113 +				}
111.7114 +				else
111.7115 +				{
111.7116 +					LDM_REG(256, 8);
111.7117 +					LDM_REG(512, 9);
111.7118 +					LDM_REG(1024, 10);
111.7119 +					LDM_REG(2048, 11);
111.7120 +					LDM_REG(4096, 12);
111.7121 +				}
111.7122 +
111.7123 +				if (armMode != 0x10 && armMode != 0x1f)
111.7124 +				{
111.7125 +					LDM_REG(8192, R13_USR);
111.7126 +					LDM_REG(16384, R14_USR);
111.7127 +				}
111.7128 +				else
111.7129 +				{
111.7130 +					LDM_REG(8192, 13);
111.7131 +					LDM_REG(16384, 14);
111.7132 +				}
111.7133 +
111.7134 +				if (!(opcode & (1 << base)))
111.7135 +					reg[base].I = temp;
111.7136 +			}
111.7137 +		}
111.7138 +		break;
111.7139 +
111.7140 +		CASE_16(0x990)
111.7141 +		{
111.7142 +			// LDMIB Rn, {Rlist}
111.7143 +			int base	= (opcode & 0x000F0000) >> 16;
111.7144 +			u32 address = (reg[base].I + 4) & 0xFFFFFFFC;
111.7145 +			clockTicks += 2;
111.7146 +			int offset = 0;
111.7147 +			LDM_REG(1, 0);
111.7148 +			LDM_REG(2, 1);
111.7149 +			LDM_REG(4, 2);
111.7150 +			LDM_REG(8, 3);
111.7151 +			LDM_REG(16, 4);
111.7152 +			LDM_REG(32, 5);
111.7153 +			LDM_REG(64, 6);
111.7154 +			LDM_REG(128, 7);
111.7155 +			LDM_REG(256, 8);
111.7156 +			LDM_REG(512, 9);
111.7157 +			LDM_REG(1024, 10);
111.7158 +			LDM_REG(2048, 11);
111.7159 +			LDM_REG(4096, 12);
111.7160 +			LDM_REG(8192, 13);
111.7161 +			LDM_REG(16384, 14);
111.7162 +			if (opcode & 32768)
111.7163 +			{
111.7164 +				reg[15].I = CPUReadMemory(address);
111.7165 +				if (!offset)
111.7166 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.7167 +				else
111.7168 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.7169 +				armNextPC  = reg[15].I;
111.7170 +				reg[15].I += 4;
111.7171 +			}
111.7172 +		}
111.7173 +		break;
111.7174 +		CASE_16(0x9b0)
111.7175 +		{
111.7176 +			// LDMIB Rn!, {Rlist}
111.7177 +			int base = (opcode & 0x000F0000) >> 16;
111.7178 +			u32 temp = reg[base].I +
111.7179 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.7180 +			u32 address = (reg[base].I + 4) & 0xFFFFFFFC;
111.7181 +			clockTicks += 2;
111.7182 +			int offset = 0;
111.7183 +			LDM_REG(1, 0);
111.7184 +			LDM_REG(2, 1);
111.7185 +			LDM_REG(4, 2);
111.7186 +			LDM_REG(8, 3);
111.7187 +			LDM_REG(16, 4);
111.7188 +			LDM_REG(32, 5);
111.7189 +			LDM_REG(64, 6);
111.7190 +			LDM_REG(128, 7);
111.7191 +			LDM_REG(256, 8);
111.7192 +			LDM_REG(512, 9);
111.7193 +			LDM_REG(1024, 10);
111.7194 +			LDM_REG(2048, 11);
111.7195 +			LDM_REG(4096, 12);
111.7196 +			LDM_REG(8192, 13);
111.7197 +			LDM_REG(16384, 14);
111.7198 +			if (opcode & 32768)
111.7199 +			{
111.7200 +				reg[15].I = CPUReadMemory(address);
111.7201 +				if (!offset)
111.7202 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.7203 +				else
111.7204 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.7205 +				armNextPC  = reg[15].I;
111.7206 +				reg[15].I += 4;
111.7207 +			}
111.7208 +			if (!(opcode & (1 << base)))
111.7209 +				reg[base].I = temp;
111.7210 +		}
111.7211 +		break;
111.7212 +		CASE_16(0x9d0)
111.7213 +		{
111.7214 +			// LDMIB Rn, {Rlist}^
111.7215 +			int base	= (opcode & 0x000F0000) >> 16;
111.7216 +			u32 address = (reg[base].I + 4) & 0xFFFFFFFC;
111.7217 +			clockTicks += 2;
111.7218 +			int offset = 0;
111.7219 +			if (opcode & 0x8000)
111.7220 +			{
111.7221 +				LDM_REG(1, 0);
111.7222 +				LDM_REG(2, 1);
111.7223 +				LDM_REG(4, 2);
111.7224 +				LDM_REG(8, 3);
111.7225 +				LDM_REG(16, 4);
111.7226 +				LDM_REG(32, 5);
111.7227 +				LDM_REG(64, 6);
111.7228 +				LDM_REG(128, 7);
111.7229 +				LDM_REG(256, 8);
111.7230 +				LDM_REG(512, 9);
111.7231 +				LDM_REG(1024, 10);
111.7232 +				LDM_REG(2048, 11);
111.7233 +				LDM_REG(4096, 12);
111.7234 +				LDM_REG(8192, 13);
111.7235 +				LDM_REG(16384, 14);
111.7236 +
111.7237 +				reg[15].I = CPUReadMemory(address);
111.7238 +				if (!offset)
111.7239 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.7240 +				else
111.7241 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.7242 +
111.7243 +				CPUSwitchMode(reg[17].I & 0x1f, false);
111.7244 +				if (armState)
111.7245 +				{
111.7246 +					armNextPC = reg[15].I & 0xFFFFFFFC;
111.7247 +					reg[15].I = armNextPC + 4;
111.7248 +				}
111.7249 +				else
111.7250 +				{
111.7251 +					armNextPC = reg[15].I & 0xFFFFFFFE;
111.7252 +					reg[15].I = armNextPC + 2;
111.7253 +				}
111.7254 +			}
111.7255 +			else
111.7256 +			{
111.7257 +				LDM_REG(1, 0);
111.7258 +				LDM_REG(2, 1);
111.7259 +				LDM_REG(4, 2);
111.7260 +				LDM_REG(8, 3);
111.7261 +				LDM_REG(16, 4);
111.7262 +				LDM_REG(32, 5);
111.7263 +				LDM_REG(64, 6);
111.7264 +				LDM_REG(128, 7);
111.7265 +
111.7266 +				if (armMode == 0x11)
111.7267 +				{
111.7268 +					LDM_REG(256, R8_FIQ);
111.7269 +					LDM_REG(512, R9_FIQ);
111.7270 +					LDM_REG(1024, R10_FIQ);
111.7271 +					LDM_REG(2048, R11_FIQ);
111.7272 +					LDM_REG(4096, R12_FIQ);
111.7273 +				}
111.7274 +				else
111.7275 +				{
111.7276 +					LDM_REG(256, 8);
111.7277 +					LDM_REG(512, 9);
111.7278 +					LDM_REG(1024, 10);
111.7279 +					LDM_REG(2048, 11);
111.7280 +					LDM_REG(4096, 12);
111.7281 +				}
111.7282 +
111.7283 +				if (armMode != 0x10 && armMode != 0x1f)
111.7284 +				{
111.7285 +					LDM_REG(8192, R13_USR);
111.7286 +					LDM_REG(16384, R14_USR);
111.7287 +				}
111.7288 +				else
111.7289 +				{
111.7290 +					LDM_REG(8192, 13);
111.7291 +					LDM_REG(16384, 14);
111.7292 +				}
111.7293 +			}
111.7294 +		}
111.7295 +		break;
111.7296 +		CASE_16(0x9f0)
111.7297 +		{
111.7298 +			// LDMIB Rn!, {Rlist}^
111.7299 +			int base = (opcode & 0x000F0000) >> 16;
111.7300 +			u32 temp = reg[base].I +
111.7301 +			           4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
111.7302 +			u32 address = (reg[base].I + 4) & 0xFFFFFFFC;
111.7303 +			clockTicks += 2;
111.7304 +			int offset = 0;
111.7305 +			if (opcode & 0x8000)
111.7306 +			{
111.7307 +				LDM_REG(1, 0);
111.7308 +				LDM_REG(2, 1);
111.7309 +				LDM_REG(4, 2);
111.7310 +				LDM_REG(8, 3);
111.7311 +				LDM_REG(16, 4);
111.7312 +				LDM_REG(32, 5);
111.7313 +				LDM_REG(64, 6);
111.7314 +				LDM_REG(128, 7);
111.7315 +				LDM_REG(256, 8);
111.7316 +				LDM_REG(512, 9);
111.7317 +				LDM_REG(1024, 10);
111.7318 +				LDM_REG(2048, 11);
111.7319 +				LDM_REG(4096, 12);
111.7320 +				LDM_REG(8192, 13);
111.7321 +				LDM_REG(16384, 14);
111.7322 +
111.7323 +				reg[15].I = CPUReadMemory(address);
111.7324 +				if (!offset)
111.7325 +					clockTicks += 2 + CPUUpdateTicksAccess32(address);
111.7326 +				else
111.7327 +					clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);
111.7328 +
111.7329 +				if (!(opcode & (1 << base)))
111.7330 +					reg[base].I = temp;
111.7331 +
111.7332 +				CPUSwitchMode(reg[17].I & 0x1f, false);
111.7333 +				if (armState)
111.7334 +				{
111.7335 +					armNextPC = reg[15].I & 0xFFFFFFFC;
111.7336 +					reg[15].I = armNextPC + 4;
111.7337 +				}
111.7338 +				else
111.7339 +				{
111.7340 +					armNextPC = reg[15].I & 0xFFFFFFFE;
111.7341 +					reg[15].I = armNextPC + 2;
111.7342 +				}
111.7343 +			}
111.7344 +			else
111.7345 +			{
111.7346 +				LDM_REG(1, 0);
111.7347 +				LDM_REG(2, 1);
111.7348 +				LDM_REG(4, 2);
111.7349 +				LDM_REG(8, 3);
111.7350 +				LDM_REG(16, 4);
111.7351 +				LDM_REG(32, 5);
111.7352 +				LDM_REG(64, 6);
111.7353 +				LDM_REG(128, 7);
111.7354 +
111.7355 +				if (armMode == 0x11)
111.7356 +				{
111.7357 +					LDM_REG(256, R8_FIQ);
111.7358 +					LDM_REG(512, R9_FIQ);
111.7359 +					LDM_REG(1024, R10_FIQ);
111.7360 +					LDM_REG(2048, R11_FIQ);
111.7361 +					LDM_REG(4096, R12_FIQ);
111.7362 +				}
111.7363 +				else
111.7364 +				{
111.7365 +					LDM_REG(256, 8);
111.7366 +					LDM_REG(512, 9);
111.7367 +					LDM_REG(1024, 10);
111.7368 +					LDM_REG(2048, 11);
111.7369 +					LDM_REG(4096, 12);
111.7370 +				}
111.7371 +
111.7372 +				if (armMode != 0x10 && armMode != 0x1f)
111.7373 +				{
111.7374 +					LDM_REG(8192, R13_USR);
111.7375 +					LDM_REG(16384, R14_USR);
111.7376 +				}
111.7377 +				else
111.7378 +				{
111.7379 +					LDM_REG(8192, 13);
111.7380 +					LDM_REG(16384, 14);
111.7381 +				}
111.7382 +
111.7383 +				if (!(opcode & (1 << base)))
111.7384 +					reg[base].I = temp;
111.7385 +			}
111.7386 +		}
111.7387 +		break;
111.7388 +		CASE_256(0xa00)
111.7389 +		{
111.7390 +			// B <offset>
111.7391 +			clockTicks += 3;
111.7392 +			int offset = opcode & 0x00FFFFFF;
111.7393 +			if (offset & 0x00800000)
111.7394 +			{
111.7395 +				offset |= 0xFF000000;
111.7396 +			}
111.7397 +			offset	 <<= 2;
111.7398 +			reg[15].I += offset;
111.7399 +			armNextPC  = reg[15].I;
111.7400 +			reg[15].I += 4;
111.7401 +		}
111.7402 +		break;
111.7403 +		CASE_256(0xb00)
111.7404 +		{
111.7405 +			// BL <offset>
111.7406 +			clockTicks += 3;
111.7407 +			int offset = opcode & 0x00FFFFFF;
111.7408 +			if (offset & 0x00800000)
111.7409 +			{
111.7410 +				offset |= 0xFF000000;
111.7411 +			}
111.7412 +			offset	 <<= 2;
111.7413 +			reg[14].I  = reg[15].I - 4;
111.7414 +			reg[15].I += offset;
111.7415 +			armNextPC  = reg[15].I;
111.7416 +			reg[15].I += 4;
111.7417 +		}
111.7418 +		break;
111.7419 +		CASE_256(0xf00)
111.7420 +		// SWI <comment>
111.7421 +		clockTicks += 3;
111.7422 +		CPUSoftwareInterrupt(opcode & 0x00FFFFFF);
111.7423 +		break;
111.7424 +#ifdef GP_SUPPORT
111.7425 +	case 0xe11:
111.7426 +	case 0xe13:
111.7427 +	case 0xe15:
111.7428 +	case 0xe17:
111.7429 +	case 0xe19:
111.7430 +	case 0xe1b:
111.7431 +	case 0xe1d:
111.7432 +	case 0xe1f:
111.7433 +		// MRC
111.7434 +		break;
111.7435 +	case 0xe01:
111.7436 +	case 0xe03:
111.7437 +	case 0xe05:
111.7438 +	case 0xe07:
111.7439 +	case 0xe09:
111.7440 +	case 0xe0b:
111.7441 +	case 0xe0d:
111.7442 +	case 0xe0f:
111.7443 +		// MRC
111.7444 +		break;
111.7445 +#endif
111.7446 +	default:
111.7447 +#ifdef GBA_LOGGING
111.7448 +		if (systemVerbose & VERBOSE_UNDEFINED)
111.7449 +			log("Undefined ARM instruction %08x at %08x\n", opcode,
111.7450 +			    armNextPC - 4);
111.7451 +#endif
111.7452 +		CPUUndefinedException();
111.7453 +		break;
111.7454 +		// END
111.7455 +	}
111.7456 +}
   112.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   112.2 +++ b/src/gba/armdis.cpp	Sat Mar 03 10:31:27 2012 -0600
   112.3 @@ -0,0 +1,774 @@
   112.4 +/************************************************************************/
   112.5 +/* Arm/Thumb command set disassembler                                   */
   112.6 +/************************************************************************/
   112.7 +#include <cstdio>
   112.8 +
   112.9 +#include "GBAGlobals.h"
  112.10 +#include "armdis.h"
  112.11 +#include "elf.h"
  112.12 +
  112.13 +struct Opcodes
  112.14 +{
  112.15 +	u32 mask;
  112.16 +	u32 cval;
  112.17 +	const char *mnemonic;
  112.18 +};
  112.19 +
  112.20 +const char hdig[] = "0123456789abcdef";
  112.21 +
  112.22 +const char *decVals[16] = {
  112.23 +	"0", "1",  "2",	 "3",  "4",	 "5",  "6", "7", "8",
  112.24 +	"9", "10", "11", "12", "13", "14", "15"
  112.25 +};
  112.26 +
  112.27 +const char *regs[16] = {
  112.28 +	"r0", "r1", "r2",  "r3",  "r4",	 "r5", "r6", "r7",
  112.29 +	"r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc"
  112.30 +};
  112.31 +
  112.32 +const char *conditions[16] = {
  112.33 +	"eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
  112.34 +	"hi", "ls", "ge", "lt", "gt", "le", "",	  "nv"
  112.35 +};
  112.36 +
  112.37 +const char *shifts[5] = {
  112.38 +	"lsl", "lsr", "asr", "ror", "rrx"
  112.39 +};
  112.40 +
  112.41 +const char *armMultLoadStore[12] = {
  112.42 +	// non-stack
  112.43 +	"da", "ia", "db", "ib",
  112.44 +	// stack store
  112.45 +	"ed", "ea", "fd", "fa",
  112.46 +	// stack load
  112.47 +	"fa", "fd", "ea", "ed"
  112.48 +};
  112.49 +
  112.50 +const Opcodes thumbOpcodes[] = {
  112.51 +	// Format 1
  112.52 +	{ 0xf800, 0x0000, "lsl %r0, %r3, %o"	  },
  112.53 +	{ 0xf800, 0x0800, "lsr %r0, %r3, %o"	  },
  112.54 +	{ 0xf800, 0x1000, "asr %r0, %r3, %o"	  },
  112.55 +	// Format 2
  112.56 +	{ 0xfe00, 0x1800, "add %r0, %r3, %r6"	  },
  112.57 +	{ 0xfe00, 0x1a00, "sub %r0, %r3, %r6"	  },
  112.58 +	{ 0xfe00, 0x1c00, "add %r0, %r3, %i"	  },
  112.59 +	{ 0xfe00, 0x1e00, "sub %r0, %r3, %i"	  },
  112.60 +	// Format 3
  112.61 +	{ 0xf800, 0x2000, "mov %r8, %O"			  },
  112.62 +	{ 0xf800, 0x2800, "cmp %r8, %O"			  },
  112.63 +	{ 0xf800, 0x3000, "add %r8, %O"			  },
  112.64 +	{ 0xf800, 0x3800, "sub %r8, %O"			  },
  112.65 +	// Format 4
  112.66 +	{ 0xffc0, 0x4000, "and %r0, %r3"		  },
  112.67 +	{ 0xffc0, 0x4040, "eor %r0, %r3"		  },
  112.68 +	{ 0xffc0, 0x4080, "lsl %r0, %r3"		  },
  112.69 +	{ 0xffc0, 0x40c0, "lsr %r0, %r3"		  },
  112.70 +	{ 0xffc0, 0x4100, "asr %r0, %r3"		  },
  112.71 +	{ 0xffc0, 0x4140, "adc %r0, %r3"		  },
  112.72 +	{ 0xffc0, 0x4180, "sbc %r0, %r3"		  },
  112.73 +	{ 0xffc0, 0x41c0, "ror %r0, %r3"		  },
  112.74 +	{ 0xffc0, 0x4200, "tst %r0, %r3"		  },
  112.75 +	{ 0xffc0, 0x4240, "neg %r0, %r3"		  },
  112.76 +	{ 0xffc0, 0x4280, "cmp %r0, %r3"		  },
  112.77 +	{ 0xffc0, 0x42c0, "cmn %r0, %r3"		  },
  112.78 +	{ 0xffc0, 0x4300, "orr %r0, %r3"		  },
  112.79 +	{ 0xffc0, 0x4340, "mul %r0, %r3"		  },
  112.80 +	{ 0xffc0, 0x4380, "bic %r0, %r3"		  },
  112.81 +	{ 0xffc0, 0x43c0, "mvn %r0, %r3"		  },
  112.82 +	// Format 5
  112.83 +	{ 0xff80, 0x4700, "bx %h36"				  },
  112.84 +	{ 0xfcc0, 0x4400, "[ ??? ]"				  },
  112.85 +	{ 0xff00, 0x4400, "add %h07, %h36"		  },
  112.86 +	{ 0xff00, 0x4500, "cmp %h07, %h36"		  },
  112.87 +	{ 0xff00, 0x4600, "mov %h07, %h36"		  },
  112.88 +	// Format 6
  112.89 +	{ 0xf800, 0x4800, "ldr %r8, [%I] (=%J)"	  },
  112.90 +	// Format 7
  112.91 +	{ 0xfa00, 0x5000, "str%b %r0, [%r3, %r6]" },
  112.92 +	{ 0xfa00, 0x5800, "ldr%b %r0, [%r3, %r6]" },
  112.93 +	// Format 8
  112.94 +	{ 0xfe00, 0x5200, "strh %r0, [%r3, %r6]"  },
  112.95 +	{ 0xfe00, 0x5600, "ldsb %r0, [%r3, %r6]"  },
  112.96 +	{ 0xfe00, 0x5a00, "ldrh %r0, [%r3, %r6]"  },
  112.97 +	{ 0xfe00, 0x5e00, "ldsh %r0, [%r3, %r6]"  },
  112.98 +	// Format 9
  112.99 +	{ 0xe800, 0x6000, "str%B %r0, [%r3, %p]"  },
 112.100 +	{ 0xe800, 0x6800, "ldr%B %r0, [%r3, %p]"  },
 112.101 +	// Format 10
 112.102 +	{ 0xf800, 0x8000, "strh %r0, [%r3, %e]"	  },
 112.103 +	{ 0xf800, 0x8800, "ldrh %r0, [%r3, %e]"	  },
 112.104 +	// Format 11
 112.105 +	{ 0xf800, 0x9000, "str %r8, [sp, %w]"	  },
 112.106 +	{ 0xf800, 0x9800, "ldr %r8, [sp, %w]"	  },
 112.107 +	// Format 12
 112.108 +	{ 0xf800, 0xa000, "add %r8, pc, %w (=%K)" },
 112.109 +	{ 0xf800, 0xa800, "add %r8, sp, %w"		  },
 112.110 +	// Format 13
 112.111 +	{ 0xff00, 0xb000, "add sp, %s"			  },
 112.112 +	// Format 14
 112.113 +	{ 0xffff, 0xb500, "push {lr}"			  },
 112.114 +	{ 0xff00, 0xb400, "push {%l}"			  },
 112.115 +	{ 0xff00, 0xb500, "push {%l,lr}"		  },
 112.116 +	{ 0xffff, 0xbd00, "pop {pc}"			  },
 112.117 +	{ 0xff00, 0xbd00, "pop {%l,pc}"			  },
 112.118 +	{ 0xff00, 0xbc00, "pop {%l}"			  },
 112.119 +	// Format 15
 112.120 +	{ 0xf800, 0xc000, "stmia %r8!, {%l}"	  },
 112.121 +	{ 0xf800, 0xc800, "ldmia %r8!, {%l}"	  },
 112.122 +	// Format 17
 112.123 +	{ 0xff00, 0xdf00, "swi %m"				  },
 112.124 +	// Format 16
 112.125 +	{ 0xf000, 0xd000, "b%c %W"				  },
 112.126 +	// Format 18
 112.127 +	{ 0xf800, 0xe000, "b %a"				  },
 112.128 +	// Format 19
 112.129 +	{ 0xf800, 0xf000, "bl %A"				  },
 112.130 +	{ 0xf800, 0xf800, "blh %Z"				  },
 112.131 +	{ 0xff00, 0xbe00, "bkpt %O"				  },
 112.132 +	// Unknown
 112.133 +	{ 0x0000, 0x0000, "[ ??? ]"				  }
 112.134 +};
 112.135 +
 112.136 +const Opcodes armOpcodes[] = {
 112.137 +	// Undefined
 112.138 +	{ 0x0e000010, 0x06000010, "[ undefined ]"				  },
 112.139 +	// Branch instructions
 112.140 +	{ 0x0ff000f0, 0x01200010, "bx%c %r0"					  },
 112.141 +	{ 0x0f000000, 0x0a000000, "b%c %o"						  },
 112.142 +	{ 0x0f000000, 0x0b000000, "bl%c %o"						  },
 112.143 +	{ 0x0f000000, 0x0f000000, "swi%c %q"					  },
 112.144 +	// PSR transfer
 112.145 +	{ 0x0fbf0fff, 0x010f0000, "mrs%c %r3, %p"				  },
 112.146 +	{ 0x0db0f000, 0x0120f000, "msr%c %p, %i"				  },
 112.147 +	// Multiply instructions
 112.148 +	{ 0x0fe000f0, 0x00000090, "mul%c%s %r4, %r0, %r2"		  },
 112.149 +	{ 0x0fe000f0, 0x00200090, "mla%c%s %r4, %r0, %r2, %r3"	  },
 112.150 +	{ 0x0fa000f0, 0x00800090, "%umull%c%s %r3, %r4, %r0, %r2" },
 112.151 +	{ 0x0fa000f0, 0x00a00090, "%umlal%c%s %r3, %r4, %r0, %r2" },
 112.152 +	// Load/Store instructions
 112.153 +	{ 0x0fb00ff0, 0x01000090, "swp%c%b %r3, %r0, [%r4]"		  },
 112.154 +	{ 0x0fb000f0, 0x01000090, "[ ??? ]"						  },
 112.155 +	{ 0x0c100000, 0x04000000, "str%c%b%t %r3, %a"			  },
 112.156 +	{ 0x0c100000, 0x04100000, "ldr%c%b%t %r3, %a"			  },
 112.157 +	{ 0x0e100090, 0x00000090, "str%c%h %r3, %a"				  },
 112.158 +	{ 0x0e100090, 0x00100090, "ldr%c%h %r3, %a"				  },
 112.159 +	{ 0x0e100000, 0x08000000, "stm%c%m %r4%l"				  },
 112.160 +	{ 0x0e100000, 0x08100000, "ldm%c%m %r4%l"				  },
 112.161 +	// Data processing
 112.162 +	{ 0x0de00000, 0x00000000, "and%c%s %r3, %r4, %i"		  },
 112.163 +	{ 0x0de00000, 0x00200000, "eor%c%s %r3, %r4, %i"		  },
 112.164 +	{ 0x0de00000, 0x00400000, "sub%c%s %r3, %r4, %i"		  },
 112.165 +	{ 0x0de00000, 0x00600000, "rsb%c%s %r3, %r4, %i"		  },
 112.166 +	{ 0x0de00000, 0x00800000, "add%c%s %r3, %r4, %i"		  },
 112.167 +	{ 0x0de00000, 0x00a00000, "adc%c%s %r3, %r4, %i"		  },
 112.168 +	{ 0x0de00000, 0x00c00000, "sbc%c%s %r3, %r4, %i"		  },
 112.169 +	{ 0x0de00000, 0x00e00000, "rsc%c%s %r3, %r4, %i"		  },
 112.170 +	{ 0x0de00000, 0x01000000, "tst%c%s %r4, %i"				  },
 112.171 +	{ 0x0de00000, 0x01200000, "teq%c%s %r4, %i"				  },
 112.172 +	{ 0x0de00000, 0x01400000, "cmp%c%s %r4, %i"				  },
 112.173 +	{ 0x0de00000, 0x01600000, "cmn%c%s %r4, %i"				  },
 112.174 +	{ 0x0de00000, 0x01800000, "orr%c%s %r3, %r4, %i"		  },
 112.175 +	{ 0x0de00000, 0x01a00000, "mov%c%s %r3, %i"				  },
 112.176 +	{ 0x0de00000, 0x01c00000, "bic%c%s %r3, %r4, %i"		  },
 112.177 +	{ 0x0de00000, 0x01e00000, "mvn%c%s %r3, %i"				  },
 112.178 +	// Coprocessor operations
 112.179 +	{ 0x0f000010, 0x0e000000, "cdp%c %P, %N, %r3, %R4, %R0%V" },
 112.180 +	{ 0x0e100000, 0x0c000000, "stc%c%L %P, %r3, %A"			  },
 112.181 +	{ 0x0f100010, 0x0e000010, "mcr%c %P, %N, %r3, %R4, %R0%V" },
 112.182 +	{ 0x0f100010, 0x0e100010, "mrc%c %P, %N, %r3, %R4, %R0%V" },
 112.183 +	// Unknown
 112.184 +	{ 0x00000000, 0x00000000, "[ ??? ]"						  }
 112.185 +};
 112.186 +
 112.187 +char *addStr(char *dest, const char *src)
 112.188 +{
 112.189 +	while (*src)
 112.190 +	{
 112.191 +		*dest++ = *src++;
 112.192 +	}
 112.193 +	return dest;
 112.194 +}
 112.195 +
 112.196 +char *addHex(char *dest, int siz, u32 val)
 112.197 +{
 112.198 +	if (siz == 0)
 112.199 +	{
 112.200 +		siz = 28;
 112.201 +		while ((((val >> siz) & 15) == 0) && (siz >= 4))
 112.202 +			siz -= 4;
 112.203 +		siz += 4;
 112.204 +	}
 112.205 +	while (siz > 0)
 112.206 +	{
 112.207 +		siz	   -= 4;
 112.208 +		*dest++ = hdig[(val >> siz) & 15];
 112.209 +	}
 112.210 +	return dest;
 112.211 +}
 112.212 +
 112.213 +int disArm(u32 offset, char *dest, int flags)
 112.214 +{
 112.215 +	u32 opcode = debuggerReadMemory(offset);
 112.216 +
 112.217 +	const Opcodes *sp = armOpcodes;
 112.218 +	while (sp->cval != (opcode & sp->mask))
 112.219 +		sp++;
 112.220 +
 112.221 +	if (flags & DIS_VIEW_ADDRESS)
 112.222 +	{
 112.223 +		dest	= addHex(dest, 32, offset);
 112.224 +		*dest++ = ' ';
 112.225 +	}
 112.226 +	if (flags & DIS_VIEW_CODE)
 112.227 +	{
 112.228 +		dest	= addHex(dest, 32, opcode);
 112.229 +		*dest++ = ' ';
 112.230 +	}
 112.231 +
 112.232 +	const char *src = sp->mnemonic;
 112.233 +	while (*src)
 112.234 +	{
 112.235 +		if (*src != '%')
 112.236 +			*dest++ = *src++;
 112.237 +		else
 112.238 +		{
 112.239 +			src++;
 112.240 +			switch (*src)
 112.241 +			{
 112.242 +			case 'c':
 112.243 +				dest = addStr(dest, conditions[opcode >> 28]);
 112.244 +				break;
 112.245 +			case 'r':
 112.246 +				dest = addStr(dest, regs[(opcode >> ((*(++src) - '0') * 4)) & 15]);
 112.247 +				break;
 112.248 +			case 'o':
 112.249 +			{
 112.250 +				*dest++ = '$';
 112.251 +				int off = opcode & 0xffffff;
 112.252 +				if (off & 0x800000)
 112.253 +					off |= 0xff000000;
 112.254 +				off <<= 2;
 112.255 +				dest  = addHex(dest, 32, offset + 8 + off);
 112.256 +			}
 112.257 +			break;
 112.258 +			case 'i':
 112.259 +				if (opcode & (1 << 25))
 112.260 +				{
 112.261 +					dest = addStr(dest, "#0x");
 112.262 +					int imm = opcode & 0xff;
 112.263 +					int rot = (opcode & 0xf00) >> 7;
 112.264 +					int val = (imm << (32 - rot)) | (imm >> rot);
 112.265 +					dest = addHex(dest, 0, val);
 112.266 +				}
 112.267 +				else
 112.268 +				{
 112.269 +					dest = addStr(dest, regs[opcode & 0x0f]);
 112.270 +					int shi = (opcode >> 5) & 3;
 112.271 +					int sdw = (opcode >> 7) & 0x1f;
 112.272 +					if ((sdw == 0) && (shi == 3))
 112.273 +						shi = 4;
 112.274 +					if ((sdw) || (opcode & 0x10) || (shi))
 112.275 +					{
 112.276 +						dest = addStr(dest, ", ");
 112.277 +						dest = addStr(dest, shifts[shi]);
 112.278 +						if (opcode & 0x10)
 112.279 +						{
 112.280 +							*dest++ = ' ';
 112.281 +							dest	= addStr(dest, regs[(opcode >> 8) & 15]);
 112.282 +						}
 112.283 +						else
 112.284 +						{
 112.285 +							if (sdw == 0 && ((shi == 1) || (shi == 2)))
 112.286 +								sdw = 32;
 112.287 +							if (shi != 4)
 112.288 +							{
 112.289 +								dest = addStr(dest, " #0x");
 112.290 +								dest = addHex(dest, 8, sdw);
 112.291 +							}
 112.292 +						}
 112.293 +					}
 112.294 +				}
 112.295 +				break;
 112.296 +			case 'p':
 112.297 +				if (opcode & (1 << 22))
 112.298 +					dest = addStr(dest, "spsr");
 112.299 +				else
 112.300 +					dest = addStr(dest, "cpsr");
 112.301 +				if (opcode & 0x00F00000)
 112.302 +				{
 112.303 +					*dest++ = '_';
 112.304 +					if (opcode & 0x00080000)
 112.305 +						*dest++ = 'f';
 112.306 +					if (opcode & 0x00040000)
 112.307 +						*dest++ = 's';
 112.308 +					if (opcode & 0x00020000)
 112.309 +						*dest++ = 'x';
 112.310 +					if (opcode & 0x00010000)
 112.311 +						*dest++ = 'c';
 112.312 +				}
 112.313 +				break;
 112.314 +			case 's':
 112.315 +				if (opcode & (1 << 20))
 112.316 +					*dest++ = 's';
 112.317 +				break;
 112.318 +			case 'S':
 112.319 +				if (opcode & (1 << 22))
 112.320 +					*dest++ = 's';
 112.321 +				break;
 112.322 +			case 'u':
 112.323 +				if (opcode & (1 << 22))
 112.324 +					*dest++ = 's';
 112.325 +				else
 112.326 +					*dest++ = 'u';
 112.327 +				break;
 112.328 +			case 'b':
 112.329 +				if (opcode & (1 << 22))
 112.330 +					*dest++ = 'b';
 112.331 +				break;
 112.332 +			case 'a':
 112.333 +				if ((opcode & 0x076f0000) == 0x004f0000)
 112.334 +				{
 112.335 +					*dest++ = '[';
 112.336 +					*dest++ = '$';
 112.337 +					int adr = offset + 8;
 112.338 +					int add = (opcode & 15) | ((opcode >> 8) & 0xf0);
 112.339 +					if (opcode & (1 << 23))
 112.340 +						adr += add;
 112.341 +					else
 112.342 +						adr -= add;
 112.343 +					dest	= addHex(dest, 32, adr);
 112.344 +					*dest++ = ']';
 112.345 +					dest	= addStr(dest, " (=");
 112.346 +					*dest++ = '$';
 112.347 +					dest	= addHex(dest, 32, debuggerReadMemory(adr));
 112.348 +					*dest++ = ')';
 112.349 +				}
 112.350 +				if ((opcode & 0x072f0000) == 0x050f0000)
 112.351 +				{
 112.352 +					*dest++ = '[';
 112.353 +					*dest++ = '$';
 112.354 +					int adr = offset + 8;
 112.355 +					if (opcode & (1 << 23))
 112.356 +						adr += opcode & 0xfff;
 112.357 +					else
 112.358 +						adr -= opcode & 0xfff;
 112.359 +					dest	= addHex(dest, 32, adr);
 112.360 +					*dest++ = ']';
 112.361 +					dest	= addStr(dest, " (=");
 112.362 +					*dest++ = '$';
 112.363 +					dest	= addHex(dest, 32, debuggerReadMemory(adr));
 112.364 +					*dest++ = ')';
 112.365 +				}
 112.366 +				else
 112.367 +				{
 112.368 +					int reg = (opcode >> 16) & 15;
 112.369 +					*dest++ = '[';
 112.370 +					dest	= addStr(dest, regs[reg]);
 112.371 +					if (!(opcode & (1 << 24)))
 112.372 +						*dest++ = ']';
 112.373 +					if (((opcode & (1 << 25)) && (opcode & (1 << 26))) || (!(opcode & (1 << 22)) && !(opcode & (1 << 26))))
 112.374 +					{
 112.375 +						dest = addStr(dest, ", ");
 112.376 +						if (!(opcode & (1 << 23)))
 112.377 +							*dest++ = '-';
 112.378 +						dest = addStr(dest, regs[opcode & 0x0f]);
 112.379 +						int shi = (opcode >> 5) & 3;
 112.380 +						if (opcode & (1 << 26))
 112.381 +						{
 112.382 +							if (((opcode >> 7) & 0x1f) || (opcode & 0x10) || (shi == 1) || (shi == 2))
 112.383 +							{
 112.384 +								dest = addStr(dest, ", ");
 112.385 +								dest = addStr(dest, shifts[shi]);
 112.386 +								if (opcode & 0x10)
 112.387 +								{
 112.388 +									*dest++ = ' ';
 112.389 +									dest	= addStr(dest, regs[(opcode >> 8) & 15]);
 112.390 +								}
 112.391 +								else
 112.392 +								{
 112.393 +									int sdw = (opcode >> 7) & 0x1f;
 112.394 +									if (sdw == 0 && ((shi == 1) || (shi == 2)))
 112.395 +										sdw = 32;
 112.396 +									dest = addStr(dest, " #0x");
 112.397 +									dest = addHex(dest, 8, sdw);
 112.398 +								}
 112.399 +							}
 112.400 +						}
 112.401 +					}
 112.402 +					else
 112.403 +					{
 112.404 +						int off;
 112.405 +						if (opcode & (1 << 26))
 112.406 +							off = opcode & 0xfff;
 112.407 +						else
 112.408 +							off = (opcode & 15) | ((opcode >> 4) & 0xf0);
 112.409 +						if (off)
 112.410 +						{
 112.411 +							dest = addStr(dest, ", ");
 112.412 +							if (!(opcode & (1 << 23)))
 112.413 +								*dest++ = '-';
 112.414 +							dest = addStr(dest, "#0x");
 112.415 +							dest = addHex(dest, 0, off);
 112.416 +						}
 112.417 +					}
 112.418 +					if (opcode & (1 << 24))
 112.419 +					{
 112.420 +						*dest++ = ']';
 112.421 +						if (opcode & (1 << 21))
 112.422 +							*dest++ = '!';
 112.423 +					}
 112.424 +				}
 112.425 +				break;
 112.426 +			case 't':
 112.427 +				if ((opcode & 0x01200000) == 0x01200000)
 112.428 +					*dest++ = 't';
 112.429 +				break;
 112.430 +			case 'h':
 112.431 +				if (opcode & (1 << 6))
 112.432 +					*dest++ = 's';
 112.433 +				if (opcode & (1 << 5))
 112.434 +					*dest++ = 'h';
 112.435 +				else
 112.436 +					*dest++ = 'b';
 112.437 +				break;
 112.438 +			case 'm':
 112.439 +				if (((opcode >> 16) & 15) == 13)
 112.440 +				{
 112.441 +					if (opcode & 0x00100000)
 112.442 +						dest = addStr(dest, armMultLoadStore[8 + ((opcode >> 23) & 3)]);
 112.443 +					else
 112.444 +						dest = addStr(dest, armMultLoadStore[4 + ((opcode >> 23) & 3)]);
 112.445 +				}
 112.446 +				else
 112.447 +					dest = addStr(dest, armMultLoadStore[(opcode >> 23) & 3]);
 112.448 +				break;
 112.449 +			case 'l':
 112.450 +				if (opcode & (1 << 21))
 112.451 +					*dest++ = '!';
 112.452 +				dest = addStr(dest, ", {");
 112.453 +				{
 112.454 +					int rlst	  = opcode & 0xffff;
 112.455 +					int msk		  = 0;
 112.456 +					int not_first = 0;
 112.457 +					while (msk < 16)
 112.458 +					{
 112.459 +						if (rlst & (1 << msk))
 112.460 +						{
 112.461 +							int fr = msk;
 112.462 +							while (rlst & (1 << msk))
 112.463 +								msk++;
 112.464 +							int to = msk - 1;
 112.465 +							if (not_first)
 112.466 +								//dest = addStr(dest, ", ");
 112.467 +								*dest++ = ',';
 112.468 +							dest = addStr(dest, regs[fr]);
 112.469 +							if (fr != to)
 112.470 +							{
 112.471 +								if (fr == to - 1)
 112.472 +									//dest = addStr(", ");
 112.473 +									*dest++ = ',';
 112.474 +								else
 112.475 +									*dest++ = '-';
 112.476 +								dest = addStr(dest, regs[to]);
 112.477 +							}
 112.478 +							not_first = 1;
 112.479 +						}
 112.480 +						else
 112.481 +							msk++;
 112.482 +					}
 112.483 +					*dest++ = '}';
 112.484 +					if (opcode & (1 << 22))
 112.485 +						*dest++ = '^';
 112.486 +				}
 112.487 +				break;
 112.488 +			case 'q':
 112.489 +				*dest++ = '$';
 112.490 +				dest	= addHex(dest, 24, opcode & 0xffffff);
 112.491 +				break;
 112.492 +			case 'P':
 112.493 +				*dest++ = 'p';
 112.494 +				dest	= addStr(dest, decVals[(opcode >> 8) & 15]);
 112.495 +				break;
 112.496 +			case 'N':
 112.497 +				if (opcode & 0x10)
 112.498 +					dest = addStr(dest, decVals[(opcode >> 21) & 7]);
 112.499 +				else
 112.500 +					dest = addStr(dest, decVals[(opcode >> 20) & 15]);
 112.501 +				break;
 112.502 +			case 'R':
 112.503 +			{
 112.504 +				src++;
 112.505 +				int reg = 4 * (*src - '0');
 112.506 +				*dest++ = 'c';
 112.507 +				dest	= addStr(dest, decVals[(opcode >> reg) & 15]);
 112.508 +			}
 112.509 +			break;
 112.510 +			case 'V':
 112.511 +			{
 112.512 +				int val = (opcode >> 5) & 7;
 112.513 +				if (val)
 112.514 +				{
 112.515 +					dest = addStr(dest, ", ");
 112.516 +					dest = addStr(dest, decVals[val]);
 112.517 +				}
 112.518 +			}
 112.519 +			break;
 112.520 +			case 'L':
 112.521 +				if (opcode & (1 << 22))
 112.522 +					*dest++ = 'l';
 112.523 +				break;
 112.524 +			case 'A':
 112.525 +				if ((opcode & 0x012f0000) == 0x010f0000)
 112.526 +				{
 112.527 +					int adr = offset + 8;
 112.528 +					int add = (opcode & 0xff) << 2;
 112.529 +					if (opcode & (1 << 23))
 112.530 +						adr += add;
 112.531 +					else
 112.532 +						adr -= add;
 112.533 +					*dest++ = '$';
 112.534 +					addHex(dest, 32, adr);
 112.535 +				}
 112.536 +				else
 112.537 +				{
 112.538 +					*dest++ = '[';
 112.539 +					dest	= addStr(dest, regs[(opcode >> 16) & 15]);
 112.540 +					if (!(opcode & (1 << 24)))
 112.541 +						*dest++ = ']';
 112.542 +					int off = (opcode & 0xff) << 2;
 112.543 +					if (off)
 112.544 +					{
 112.545 +						dest = addStr(dest, ", ");
 112.546 +						if (!(opcode & (1 << 23)))
 112.547 +							*dest++ = '-';
 112.548 +						dest = addStr(dest, "#0x");
 112.549 +						dest = addHex(dest, 0, off);
 112.550 +					}
 112.551 +					if (opcode & (1 << 24))
 112.552 +					{
 112.553 +						*dest++ = ']';
 112.554 +						if (opcode & (1 << 21))
 112.555 +							*dest++ = '!';
 112.556 +					}
 112.557 +				}
 112.558 +				break;
 112.559 +			}
 112.560 +			src++;
 112.561 +		}
 112.562 +	}
 112.563 +	*dest++ = 0;
 112.564 +
 112.565 +	return 4;
 112.566 +}
 112.567 +
 112.568 +int disThumb(u32 offset, char *dest, int flags)
 112.569 +{
 112.570 +	u32 opcode = debuggerReadHalfWord(offset);
 112.571 +
 112.572 +	const Opcodes *sp = thumbOpcodes;
 112.573 +	int ret = 2;
 112.574 +	while (sp->cval != (opcode & sp->mask))
 112.575 +		sp++;
 112.576 +
 112.577 +	if (flags & DIS_VIEW_ADDRESS)
 112.578 +	{
 112.579 +		dest	= addHex(dest, 32, offset);
 112.580 +		*dest++ = ' ';
 112.581 +	}
 112.582 +	if (flags & DIS_VIEW_CODE)
 112.583 +	{
 112.584 +		dest	= addHex(dest, 16, opcode);
 112.585 +		*dest++ = ' ';
 112.586 +	}
 112.587 +
 112.588 +	const char *src = sp->mnemonic;
 112.589 +	while (*src)
 112.590 +	{
 112.591 +		if (*src != '%')
 112.592 +			*dest++ = *src++;
 112.593 +		else
 112.594 +		{
 112.595 +			src++;
 112.596 +			switch (*src)
 112.597 +			{
 112.598 +			case 'r':
 112.599 +				src++;
 112.600 +				dest = addStr(dest, regs[(opcode >> (*src - '0')) & 7]);
 112.601 +				break;
 112.602 +			case 'o':
 112.603 +				dest = addStr(dest, "#0x");
 112.604 +				{
 112.605 +					int val = (opcode >> 6) & 0x1f;
 112.606 +					dest = addHex(dest, 8, val);
 112.607 +				}
 112.608 +				break;
 112.609 +			case 'p':
 112.610 +				dest = addStr(dest, "#0x");
 112.611 +				{
 112.612 +					int val = (opcode >> 6) & 0x1f;
 112.613 +					if (!(opcode & (1 << 12)))
 112.614 +						val <<= 2;
 112.615 +					dest = addHex(dest, 0, val);
 112.616 +				}
 112.617 +				break;
 112.618 +			case 'e':
 112.619 +				dest = addStr(dest, "#0x");
 112.620 +				dest = addHex(dest, 0, ((opcode >> 6) & 0x1f) << 1);
 112.621 +				break;
 112.622 +			case 'i':
 112.623 +				dest = addStr(dest, "#0x");
 112.624 +				dest = addHex(dest, 0, (opcode >> 6) & 7);
 112.625 +				break;
 112.626 +			case 'h':
 112.627 +			{
 112.628 +				src++;
 112.629 +				int reg = (opcode >> (*src - '0')) & 7;
 112.630 +				src++;
 112.631 +				if (opcode & (1 << (*src - '0')))
 112.632 +					reg += 8;
 112.633 +				dest = addStr(dest, regs[reg]);
 112.634 +			}
 112.635 +			break;
 112.636 +			case 'O':
 112.637 +				dest = addStr(dest, "#0x");
 112.638 +				dest = addHex(dest, 0, (opcode & 0xff));
 112.639 +				break;
 112.640 +			case 'I':
 112.641 +				*dest++ = '$';
 112.642 +				dest	= addHex(dest, 32, (offset & 0xfffffffc) + 4 + ((opcode & 0xff) << 2));
 112.643 +				break;
 112.644 +			case 'J':
 112.645 +			{
 112.646 +				u32 value = debuggerReadMemory((offset & 0xfffffffc) + 4 +
 112.647 +				                               ((opcode & 0xff) << 2));
 112.648 +				*dest++ = '$';
 112.649 +				dest	= addHex(dest, 32, value);
 112.650 +				const char *s = elfGetAddressSymbol(value);
 112.651 +				if (*s)
 112.652 +				{
 112.653 +					*dest++ = ' ';
 112.654 +					dest	= addStr(dest, s);
 112.655 +				}
 112.656 +			}
 112.657 +			break;
 112.658 +			case 'K':
 112.659 +			{
 112.660 +				u32 value = (offset & 0xfffffffc) + 4 + ((opcode & 0xff) << 2);
 112.661 +				*dest++ = '$';
 112.662 +				dest	= addHex(dest, 32, value);
 112.663 +				const char *s = elfGetAddressSymbol(value);
 112.664 +				if (*s)
 112.665 +				{
 112.666 +					*dest++ = ' ';
 112.667 +					dest	= addStr(dest, s);
 112.668 +				}
 112.669 +			}
 112.670 +			break;
 112.671 +			case 'b':
 112.672 +				if (opcode & (1 << 10))
 112.673 +					*dest++ = 'b';
 112.674 +				break;
 112.675 +			case 'B':
 112.676 +				if (opcode & (1 << 12))
 112.677 +					*dest++ = 'b';
 112.678 +				break;
 112.679 +			case 'w':
 112.680 +				dest = addStr(dest, "#0x");
 112.681 +				dest = addHex(dest, 0, (opcode & 0xff) << 2);
 112.682 +				break;
 112.683 +			case 'W':
 112.684 +				*dest++ = '$';
 112.685 +				{
 112.686 +					int add = opcode & 0xff;
 112.687 +					if (add & 0x80)
 112.688 +						add |= 0xffffff00;
 112.689 +					dest = addHex(dest, 32, (offset & 0xfffffffe) + 4 + (add << 1));
 112.690 +				}
 112.691 +				break;
 112.692 +			case 'c':
 112.693 +				dest = addStr(dest, conditions[(opcode >> 8) & 15]);
 112.694 +				break;
 112.695 +			case 's':
 112.696 +				if (opcode & (1 << 7))
 112.697 +					*dest++ = '-';
 112.698 +				dest = addStr(dest, "#0x");
 112.699 +				dest = addHex(dest, 0, (opcode & 0x7f) << 2);
 112.700 +				break;
 112.701 +			case 'l':
 112.702 +			{
 112.703 +				int rlst	  = opcode & 0xff;
 112.704 +				int msk		  = 0;
 112.705 +				int not_first = 0;
 112.706 +				while (msk < 8)
 112.707 +				{
 112.708 +					if (rlst & (1 << msk))
 112.709 +					{
 112.710 +						int fr = msk;
 112.711 +						while (rlst & (1 << msk))
 112.712 +							msk++;
 112.713 +						int to = msk - 1;
 112.714 +						if (not_first)
 112.715 +							*dest++ = ',';
 112.716 +						dest = addStr(dest, regs[fr]);
 112.717 +						if (fr != to)
 112.718 +						{
 112.719 +							if (fr == to - 1)
 112.720 +								*dest++ = ',';
 112.721 +							else
 112.722 +								*dest++ = '-';
 112.723 +							dest = addStr(dest, regs[to]);
 112.724 +						}
 112.725 +						not_first = 1;
 112.726 +					}
 112.727 +					else
 112.728 +						msk++;
 112.729 +				}
 112.730 +			}
 112.731 +			break;
 112.732 +			case 'm':
 112.733 +				*dest++ = '$';
 112.734 +				dest	= addHex(dest, 8, opcode & 0xff);
 112.735 +				break;
 112.736 +			case 'Z':
 112.737 +				*dest++ = '$';
 112.738 +				dest	= addHex(dest, 16, (opcode & 0x7ff) << 1);
 112.739 +				break;
 112.740 +			case 'a':
 112.741 +				*dest++ = '$';
 112.742 +				{
 112.743 +					int add = opcode & 0x07ff;
 112.744 +					if (add & 0x400)
 112.745 +						add |= 0xfffff800;
 112.746 +					add <<= 1;
 112.747 +					dest  = addHex(dest, 32, offset + 4 + add);
 112.748 +				}
 112.749 +				break;
 112.750 +			case 'A':
 112.751 +			{
 112.752 +				int nopcode = debuggerReadHalfWord(offset + 2);
 112.753 +				int add		= opcode & 0x7ff;
 112.754 +				if (add & 0x400)
 112.755 +					add |= 0xfff800;
 112.756 +				add		= (add << 12) | ((nopcode & 0x7ff) << 1);
 112.757 +				*dest++ = '$';
 112.758 +				dest	= addHex(dest, 32, offset + 4 + add);
 112.759 +				const char *s = elfGetAddressSymbol(offset + 4 + add);
 112.760 +				if (*s)
 112.761 +				{
 112.762 +					*dest++ = ' ';
 112.763 +					*dest++ = '(';
 112.764 +					dest	= addStr(dest, s);
 112.765 +					*dest++ = ')';
 112.766 +				}
 112.767 +				ret = 4;
 112.768 +			}
 112.769 +			break;
 112.770 +			}
 112.771 +			src++;
 112.772 +		}
 112.773 +	}
 112.774 +	*dest++ = 0;
 112.775 +	return ret;
 112.776 +}
 112.777 +
   113.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   113.2 +++ b/src/gba/armdis.h	Sat Mar 03 10:31:27 2012 -0600
   113.3 @@ -0,0 +1,14 @@
   113.4 +#ifndef VBA_GBA_ARMDIS_H
   113.5 +#define VBA_GBA_ARMDIS_H
   113.6 +
   113.7 +#if _MSC_VER > 1000
   113.8 +#pragma once
   113.9 +#endif // _MSC_VER > 1000
  113.10 +
  113.11 +#define DIS_VIEW_ADDRESS 1
  113.12 +#define DIS_VIEW_CODE 2
  113.13 +
  113.14 +int disThumb(u32 offset, char *dest, int flags);
  113.15 +int disArm(u32 offset, char *dest, int flags);
  113.16 +
  113.17 +#endif // VBA_GBA_ARMDIS_H
   114.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   114.2 +++ b/src/gba/bios.cpp	Sat Mar 03 10:31:27 2012 -0600
   114.3 @@ -0,0 +1,1278 @@
   114.4 +#include <cmath>
   114.5 +#include <cstdlib>
   114.6 +#include <cstring>
   114.7 +
   114.8 +#include "bios.h"
   114.9 +#include "../common/System.h"
  114.10 +#include "GBA.h"
  114.11 +#include "GBACheats.h" // FIXME: SDL build requires this
  114.12 +#include "GBAinline.h"
  114.13 +#include "GBAGlobals.h"
  114.14 +
  114.15 +s16 sineTable[256] = {
  114.16 +	(s16)0x0000, (s16)0x0192, (s16)0x0323, (s16)0x04B5, (s16)0x0645, (s16)0x07D5, (s16)0x0964, (s16)0x0AF1,
  114.17 +	(s16)0x0C7C, (s16)0x0E05, (s16)0x0F8C, (s16)0x1111, (s16)0x1294, (s16)0x1413, (s16)0x158F, (s16)0x1708,
  114.18 +	(s16)0x187D, (s16)0x19EF, (s16)0x1B5D, (s16)0x1CC6, (s16)0x1E2B, (s16)0x1F8B, (s16)0x20E7, (s16)0x223D,
  114.19 +	(s16)0x238E, (s16)0x24DA, (s16)0x261F, (s16)0x275F, (s16)0x2899, (s16)0x29CD, (s16)0x2AFA, (s16)0x2C21,
  114.20 +	(s16)0x2D41, (s16)0x2E5A, (s16)0x2F6B, (s16)0x3076, (s16)0x3179, (s16)0x3274, (s16)0x3367, (s16)0x3453,
  114.21 +	(s16)0x3536, (s16)0x3612, (s16)0x36E5, (s16)0x37AF, (s16)0x3871, (s16)0x392A, (s16)0x39DA, (s16)0x3A82,
  114.22 +	(s16)0x3B20, (s16)0x3BB6, (s16)0x3C42, (s16)0x3CC5, (s16)0x3D3E, (s16)0x3DAE, (s16)0x3E14, (s16)0x3E71,
  114.23 +	(s16)0x3EC5, (s16)0x3F0E, (s16)0x3F4E, (s16)0x3F84, (s16)0x3FB1, (s16)0x3FD3, (s16)0x3FEC, (s16)0x3FFB,
  114.24 +	(s16)0x4000, (s16)0x3FFB, (s16)0x3FEC, (s16)0x3FD3, (s16)0x3FB1, (s16)0x3F84, (s16)0x3F4E, (s16)0x3F0E,
  114.25 +	(s16)0x3EC5, (s16)0x3E71, (s16)0x3E14, (s16)0x3DAE, (s16)0x3D3E, (s16)0x3CC5, (s16)0x3C42, (s16)0x3BB6,
  114.26 +	(s16)0x3B20, (s16)0x3A82, (s16)0x39DA, (s16)0x392A, (s16)0x3871, (s16)0x37AF, (s16)0x36E5, (s16)0x3612,
  114.27 +	(s16)0x3536, (s16)0x3453, (s16)0x3367, (s16)0x3274, (s16)0x3179, (s16)0x3076, (s16)0x2F6B, (s16)0x2E5A,
  114.28 +	(s16)0x2D41, (s16)0x2C21, (s16)0x2AFA, (s16)0x29CD, (s16)0x2899, (s16)0x275F, (s16)0x261F, (s16)0x24DA,
  114.29 +	(s16)0x238E, (s16)0x223D, (s16)0x20E7, (s16)0x1F8B, (s16)0x1E2B, (s16)0x1CC6, (s16)0x1B5D, (s16)0x19EF,
  114.30 +	(s16)0x187D, (s16)0x1708, (s16)0x158F, (s16)0x1413, (s16)0x1294, (s16)0x1111, (s16)0x0F8C, (s16)0x0E05,
  114.31 +	(s16)0x0C7C, (s16)0x0AF1, (s16)0x0964, (s16)0x07D5, (s16)0x0645, (s16)0x04B5, (s16)0x0323, (s16)0x0192,
  114.32 +	(s16)0x0000, (s16)0xFE6E, (s16)0xFCDD, (s16)0xFB4B, (s16)0xF9BB, (s16)0xF82B, (s16)0xF69C, (s16)0xF50F,
  114.33 +	(s16)0xF384, (s16)0xF1FB, (s16)0xF074, (s16)0xEEEF, (s16)0xED6C, (s16)0xEBED, (s16)0xEA71, (s16)0xE8F8,
  114.34 +	(s16)0xE783, (s16)0xE611, (s16)0xE4A3, (s16)0xE33A, (s16)0xE1D5, (s16)0xE075, (s16)0xDF19, (s16)0xDDC3,
  114.35 +	(s16)0xDC72, (s16)0xDB26, (s16)0xD9E1, (s16)0xD8A1, (s16)0xD767, (s16)0xD633, (s16)0xD506, (s16)0xD3DF,
  114.36 +	(s16)0xD2BF, (s16)0xD1A6, (s16)0xD095, (s16)0xCF8A, (s16)0xCE87, (s16)0xCD8C, (s16)0xCC99, (s16)0xCBAD,
  114.37 +	(s16)0xCACA, (s16)0xC9EE, (s16)0xC91B, (s16)0xC851, (s16)0xC78F, (s16)0xC6D6, (s16)0xC626, (s16)0xC57E,
  114.38 +	(s16)0xC4E0, (s16)0xC44A, (s16)0xC3BE, (s16)0xC33B, (s16)0xC2C2, (s16)0xC252, (s16)0xC1EC, (s16)0xC18F,
  114.39 +	(s16)0xC13B, (s16)0xC0F2, (s16)0xC0B2, (s16)0xC07C, (s16)0xC04F, (s16)0xC02D, (s16)0xC014, (s16)0xC005,
  114.40 +	(s16)0xC000, (s16)0xC005, (s16)0xC014, (s16)0xC02D, (s16)0xC04F, (s16)0xC07C, (s16)0xC0B2, (s16)0xC0F2,
  114.41 +	(s16)0xC13B, (s16)0xC18F, (s16)0xC1EC, (s16)0xC252, (s16)0xC2C2, (s16)0xC33B, (s16)0xC3BE, (s16)0xC44A,
  114.42 +	(s16)0xC4E0, (s16)0xC57E, (s16)0xC626, (s16)0xC6D6, (s16)0xC78F, (s16)0xC851, (s16)0xC91B, (s16)0xC9EE,
  114.43 +	(s16)0xCACA, (s16)0xCBAD, (s16)0xCC99, (s16)0xCD8C, (s16)0xCE87, (s16)0xCF8A, (s16)0xD095, (s16)0xD1A6,
  114.44 +	(s16)0xD2BF, (s16)0xD3DF, (s16)0xD506, (s16)0xD633, (s16)0xD767, (s16)0xD8A1, (s16)0xD9E1, (s16)0xDB26,
  114.45 +	(s16)0xDC72, (s16)0xDDC3, (s16)0xDF19, (s16)0xE075, (s16)0xE1D5, (s16)0xE33A, (s16)0xE4A3, (s16)0xE611,
  114.46 +	(s16)0xE783, (s16)0xE8F8, (s16)0xEA71, (s16)0xEBED, (s16)0xED6C, (s16)0xEEEF, (s16)0xF074, (s16)0xF1FB,
  114.47 +	(s16)0xF384, (s16)0xF50F, (s16)0xF69C, (s16)0xF82B, (s16)0xF9BB, (s16)0xFB4B, (s16)0xFCDD, (s16)0xFE6E
  114.48 +};
  114.49 +
  114.50 +void BIOS_ArcTan()
  114.51 +{
  114.52 +#ifdef GBA_LOGGING
  114.53 +	if (systemVerbose & VERBOSE_SWI)
  114.54 +	{
  114.55 +		log("ArcTan: %08x (VCOUNT=%2d)\n",
  114.56 +		    reg[0].I,
  114.57 +		    VCOUNT);
  114.58 +	}
  114.59 +#endif
  114.60 +
  114.61 +	s32 a = -((s32)(reg[0].I * reg[0].I)) >> 14;
  114.62 +	s32 b = ((0xA9 * a) >> 14) + 0x390;
  114.63 +	b        = ((b * a) >> 14) + 0x91C;
  114.64 +	b        = ((b * a) >> 14) + 0xFB6;
  114.65 +	b        = ((b * a) >> 14) + 0x16AA;
  114.66 +	b        = ((b * a) >> 14) + 0x2081;
  114.67 +	b        = ((b * a) >> 14) + 0x3651;
  114.68 +	b        = ((b * a) >> 14) + 0xA2F9;
  114.69 +	reg[0].I = (reg[0].I * b) >> 16;
  114.70 +
  114.71 +#ifdef GBA_LOGGING
  114.72 +	if (systemVerbose & VERBOSE_SWI)
  114.73 +	{
  114.74 +		log("ArcTan: return=%08x\n",
  114.75 +		    reg[0].I);
  114.76 +	}
  114.77 +#endif
  114.78 +}
  114.79 +
  114.80 +void BIOS_ArcTan2()
  114.81 +{
  114.82 +#ifdef GBA_LOGGING
  114.83 +	if (systemVerbose & VERBOSE_SWI)
  114.84 +	{
  114.85 +		log("ArcTan2: %08x,%08x (VCOUNT=%2d)\n",
  114.86 +		    reg[0].I,
  114.87 +		    reg[1].I,
  114.88 +		    VCOUNT);
  114.89 +	}
  114.90 +#endif
  114.91 +
  114.92 +	s16 x = reg[0].I;
  114.93 +	s16 y = reg[1].I;
  114.94 +
  114.95 +	if (y == 0)
  114.96 +	{
  114.97 +		reg[0].I = 0x8000 & x;
  114.98 +		reg[3].I = 0x170;
  114.99 +	}
 114.100 +	else
 114.101 +	{
 114.102 +		if (x == 0)
 114.103 +		{
 114.104 +			reg[0].I = (0x8000 & y) + 0x4000;
 114.105 +			reg[3].I = 0x170;
 114.106 +		}
 114.107 +		else
 114.108 +		{
 114.109 +			if (abs(x) > abs(y))
 114.110 +			{
 114.111 +				reg[1].I = x;
 114.112 +				reg[0].I = y << 14;
 114.113 +				BIOS_Div();
 114.114 +				BIOS_ArcTan();
 114.115 +				if (x < 0)
 114.116 +					reg[0].I = 0x8000 + reg[0].I;
 114.117 +				else
 114.118 +					reg[0].I = ((y & 0x8000) << 1) + reg[0].I;
 114.119 +				reg[3].I = 0x170;
 114.120 +			}
 114.121 +			else
 114.122 +			{
 114.123 +				reg[0].I = x << 14;
 114.124 +				BIOS_Div();
 114.125 +				BIOS_ArcTan();
 114.126 +				reg[0].I = (0x4000 + (y & 0x8000)) - reg[0].I;
 114.127 +				reg[3].I = 0x170;
 114.128 +			}
 114.129 +		}
 114.130 +	}
 114.131 +
 114.132 +#ifdef GBA_LOGGING
 114.133 +	if (systemVerbose & VERBOSE_SWI)
 114.134 +	{
 114.135 +		log("ArcTan2: return=%08x\n",
 114.136 +		    reg[0].I);
 114.137 +	}
 114.138 +#endif
 114.139 +}
 114.140 +
 114.141 +void BIOS_BitUnPack()
 114.142 +{
 114.143 +#ifdef GBA_LOGGING
 114.144 +	if (systemVerbose & VERBOSE_SWI)
 114.145 +	{
 114.146 +		log("BitUnPack: %08x,%08x,%08x (VCOUNT=%2d)\n",
 114.147 +		    reg[0].I,
 114.148 +		    reg[1].I,
 114.149 +		    reg[2].I,
 114.150 +		    VCOUNT);
 114.151 +	}
 114.152 +#endif
 114.153 +
 114.154 +	u32 source = reg[0].I;
 114.155 +	u32 dest   = reg[1].I;
 114.156 +	u32 header = reg[2].I;
 114.157 +
 114.158 +	int len = CPUReadHalfWord(header);
 114.159 +	// check address
 114.160 +	int bits    = CPUReadByte(header+2);
 114.161 +	int revbits = 8 - bits;
 114.162 +	// u32 value = 0;
 114.163 +	u32  base    = CPUReadMemory(header+4);
 114.164 +	bool addBase = (base & 0x80000000) ? true : false;
 114.165 +	base &= 0x7fffffff;
 114.166 +	int dataSize = CPUReadByte(header+3);
 114.167 +
 114.168 +	int data = 0;
 114.169 +	int bitwritecount = 0;
 114.170 +	while (1)
 114.171 +	{
 114.172 +		len -= 1;
 114.173 +		if (len < 0)
 114.174 +			break;
 114.175 +		int mask = 0xff >> revbits;
 114.176 +		u8  b    = CPUReadByte(source);
 114.177 +		source++;
 114.178 +		int bitcount = 0;
 114.179 +		while (1)
 114.180 +		{
 114.181 +			if (bitcount >= 8)
 114.182 +				break;
 114.183 +			u32 d    = b & mask;
 114.184 +			u32 temp = d >> bitcount;
 114.185 +			if (!temp && addBase)
 114.186 +			{
 114.187 +				temp += base;
 114.188 +			}
 114.189 +			data |= temp << bitwritecount;
 114.190 +			bitwritecount += dataSize;
 114.191 +			if (bitwritecount >= 32)
 114.192 +			{
 114.193 +				CPUWriteMemory(dest, data);
 114.194 +				dest += 4;
 114.195 +				data  = 0;
 114.196 +				bitwritecount = 0;
 114.197 +			}
 114.198 +			mask    <<= bits;
 114.199 +			bitcount += bits;
 114.200 +		}
 114.201 +	}
 114.202 +}
 114.203 +
 114.204 +void BIOS_BgAffineSet()
 114.205 +{
 114.206 +#ifdef GBA_LOGGING
 114.207 +	if (systemVerbose & VERBOSE_SWI)
 114.208 +	{
 114.209 +		log("BgAffineSet: %08x,%08x,%08x (VCOUNT=%2d)\n",
 114.210 +		    reg[0].I,
 114.211 +		    reg[1].I,
 114.212 +		    reg[2].I,
 114.213 +		    VCOUNT);
 114.214 +	}
 114.215 +#endif
 114.216 +
 114.217 +	u32 src  = reg[0].I;
 114.218 +	u32 dest = reg[1].I;
 114.219 +	int num  = reg[2].I;
 114.220 +
 114.221 +	for (int i = 0; i < num; i++)
 114.222 +	{
 114.223 +		s32 cx = CPUReadMemory(src);
 114.224 +		src += 4;
 114.225 +		s32 cy = CPUReadMemory(src);
 114.226 +		src += 4;
 114.227 +		s16 dispx = CPUReadHalfWord(src);
 114.228 +		src += 2;
 114.229 +		s16 dispy = CPUReadHalfWord(src);
 114.230 +		src += 2;
 114.231 +		s16 rx = CPUReadHalfWord(src);
 114.232 +		src += 2;
 114.233 +		s16 ry = CPUReadHalfWord(src);
 114.234 +		src += 2;
 114.235 +		u16 theta = CPUReadHalfWord(src)>>8;
 114.236 +		src += 4; // keep structure alignment
 114.237 +		s32 a = (s32)sineTable[(theta+0x40)&255];
 114.238 +		s32 b = (s32)sineTable[theta];
 114.239 +
 114.240 +		s16 dx  =  (s16)((rx * a)>>14);
 114.241 +		s16 dmx = (s16)((rx * b)>>14);
 114.242 +		s16 dy  =  (s16)((ry * b)>>14);
 114.243 +		s16 dmy = (s16)((ry * a)>>14);
 114.244 +
 114.245 +		CPUWriteHalfWord(dest, dx);
 114.246 +		dest += 2;
 114.247 +		CPUWriteHalfWord(dest, -dmx);
 114.248 +		dest += 2;
 114.249 +		CPUWriteHalfWord(dest, dy);
 114.250 +		dest += 2;
 114.251 +		CPUWriteHalfWord(dest, dmy);
 114.252 +		dest += 2;
 114.253 +
 114.254 +		s32 startx = cx - dx * dispx + dmx * dispy;
 114.255 +		s32 starty = cy - dy * dispx - dmy * dispy;
 114.256 +
 114.257 +		CPUWriteMemory(dest, startx);
 114.258 +		dest += 4;
 114.259 +		CPUWriteMemory(dest, starty);
 114.260 +		dest += 4;
 114.261 +	}
 114.262 +}
 114.263 +
 114.264 +void BIOS_CpuSet()
 114.265 +{
 114.266 +#ifdef GBA_LOGGING
 114.267 +	if (systemVerbose & VERBOSE_SWI)
 114.268 +	{
 114.269 +		log("CpuSet: 0x%08x,0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I, reg[1].I,
 114.270 +		    reg[2].I, VCOUNT);
 114.271 +	}
 114.272 +#endif
 114.273 +
 114.274 +	u32 source = reg[0].I;
 114.275 +	u32 dest   = reg[1].I;
 114.276 +	u32 cnt    = reg[2].I;
 114.277 +
 114.278 +	if (((source & 0xe000000) == 0) ||
 114.279 +	    ((source + (((cnt << 11)>>9) & 0x1fffff)) & 0xe000000) == 0)
 114.280 +		return;
 114.281 +
 114.282 +	int count = cnt & 0x1FFFFF;
 114.283 +
 114.284 +	// 32-bit ?
 114.285 +	if ((cnt >> 26) & 1)
 114.286 +	{
 114.287 +		// needed for 32-bit mode!
 114.288 +		source &= 0xFFFFFFFC;
 114.289 +		dest   &= 0xFFFFFFFC;
 114.290 +		// fill ?
 114.291 +		if ((cnt >> 24) & 1)
 114.292 +		{
 114.293 +			u32 value = CPUReadMemory(source);
 114.294 +			while (count)
 114.295 +			{
 114.296 +				CPUWriteMemory(dest, value);
 114.297 +				dest += 4;
 114.298 +				count--;
 114.299 +			}
 114.300 +		}
 114.301 +		else
 114.302 +		{
 114.303 +			// copy
 114.304 +			while (count)
 114.305 +			{
 114.306 +				CPUWriteMemory(dest, CPUReadMemory(source));
 114.307 +				source += 4;
 114.308 +				dest   += 4;
 114.309 +				count--;
 114.310 +			}
 114.311 +		}
 114.312 +	}
 114.313 +	else
 114.314 +	{
 114.315 +		// 16-bit fill?
 114.316 +		if ((cnt >> 24) & 1)
 114.317 +		{
 114.318 +			u16 value = CPUReadHalfWord(source);
 114.319 +			while (count)
 114.320 +			{
 114.321 +				CPUWriteHalfWord(dest, value);
 114.322 +				dest += 2;
 114.323 +				count--;
 114.324 +			}
 114.325 +		}
 114.326 +		else
 114.327 +		{
 114.328 +			// copy
 114.329 +			while (count)
 114.330 +			{
 114.331 +				CPUWriteHalfWord(dest, CPUReadHalfWord(source));
 114.332 +				source += 2;
 114.333 +				dest   += 2;
 114.334 +				count--;
 114.335 +			}
 114.336 +		}
 114.337 +	}
 114.338 +}
 114.339 +
 114.340 +void BIOS_CpuFastSet()
 114.341 +{
 114.342 +#ifdef GBA_LOGGING
 114.343 +	if (systemVerbose & VERBOSE_SWI)
 114.344 +	{
 114.345 +		log("CpuFastSet: 0x%08x,0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I, reg[1].I,
 114.346 +		    reg[2].I, VCOUNT);
 114.347 +	}
 114.348 +#endif
 114.349 +
 114.350 +	u32 source = reg[0].I;
 114.351 +	u32 dest   = reg[1].I;
 114.352 +	u32 cnt    = reg[2].I;
 114.353 +
 114.354 +	if (((source & 0xe000000) == 0) ||
 114.355 +	    ((source + (((cnt << 11)>>9) & 0x1fffff)) & 0xe000000) == 0)
 114.356 +		return;
 114.357 +
 114.358 +	// needed for 32-bit mode!
 114.359 +	source &= 0xFFFFFFFC;
 114.360 +	dest   &= 0xFFFFFFFC;
 114.361 +
 114.362 +	int count = cnt & 0x1FFFFF;
 114.363 +
 114.364 +	// fill?
 114.365 +	if ((cnt >> 24) & 1)
 114.366 +	{
 114.367 +		while (count > 0)
 114.368 +		{
 114.369 +			// BIOS always transfers 32 bytes at a time
 114.370 +			u32 value = CPUReadMemory(source);
 114.371 +			for (int i = 0; i < 8; i++)
 114.372 +			{
 114.373 +				CPUWriteMemory(dest, value);
 114.374 +				dest += 4;
 114.375 +			}
 114.376 +			count -= 8;
 114.377 +		}
 114.378 +	}
 114.379 +	else
 114.380 +	{
 114.381 +		// copy
 114.382 +		while (count > 0)
 114.383 +		{
 114.384 +			// BIOS always transfers 32 bytes at a time
 114.385 +			for (int i = 0; i < 8; i++)
 114.386 +			{
 114.387 +				CPUWriteMemory(dest, CPUReadMemory(source));
 114.388 +				source += 4;
 114.389 +				dest   += 4;
 114.390 +			}
 114.391 +			count -= 8;
 114.392 +		}
 114.393 +	}
 114.394 +}
 114.395 +
 114.396 +void BIOS_Diff8bitUnFilterWram()
 114.397 +{
 114.398 +#ifdef GBA_LOGGING
 114.399 +	if (systemVerbose & VERBOSE_SWI)
 114.400 +	{
 114.401 +		log("Diff8bitUnFilterWram: 0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I,
 114.402 +		    reg[1].I, VCOUNT);
 114.403 +	}
 114.404 +#endif
 114.405 +
 114.406 +	u32 source = reg[0].I;
 114.407 +	u32 dest   = reg[1].I;
 114.408 +
 114.409 +	u32 header = CPUReadMemory(source);
 114.410 +	source += 4;
 114.411 +
 114.412 +	if (((source & 0xe000000) == 0) ||
 114.413 +	    ((source + ((header >> 8) & 0x1fffff) & 0xe000000) == 0))
 114.414 +		return;
 114.415 +
 114.416 +	int len = header >> 8;
 114.417 +
 114.418 +	u8 data = CPUReadByte(source++);
 114.419 +	CPUWriteByte(dest++, data);
 114.420 +	len--;
 114.421 +
 114.422 +	while (len > 0)
 114.423 +	{
 114.424 +		u8 diff = CPUReadByte(source++);
 114.425 +		data += diff;
 114.426 +		CPUWriteByte(dest++, data);
 114.427 +		len--;
 114.428 +	}
 114.429 +}
 114.430 +
 114.431 +void BIOS_Diff8bitUnFilterVram()
 114.432 +{
 114.433 +#ifdef GBA_LOGGING
 114.434 +	if (systemVerbose & VERBOSE_SWI)
 114.435 +	{
 114.436 +		log("Diff8bitUnFilterVram: 0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I,
 114.437 +		    reg[1].I, VCOUNT);
 114.438 +	}
 114.439 +#endif
 114.440 +
 114.441 +	u32 source = reg[0].I;
 114.442 +	u32 dest   = reg[1].I;
 114.443 +
 114.444 +	u32 header = CPUReadMemory(source);
 114.445 +	source += 4;
 114.446 +
 114.447 +	if (((source & 0xe000000) == 0) ||
 114.448 +	    ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
 114.449 +		return;
 114.450 +
 114.451 +	int len = header >> 8;
 114.452 +
 114.453 +	u8  data      = CPUReadByte(source++);
 114.454 +	u16 writeData = data;
 114.455 +	int shift     = 8;
 114.456 +	int bytes     = 1;
 114.457 +
 114.458 +	while (len >= 2)
 114.459 +	{
 114.460 +		u8 diff = CPUReadByte(source++);
 114.461 +		data      += diff;
 114.462 +		writeData |= (data << shift);
 114.463 +		bytes++;
 114.464 +		shift += 8;
 114.465 +		if (bytes == 2)
 114.466 +		{
 114.467 +			CPUWriteHalfWord(dest, writeData);
 114.468 +			dest     += 2;
 114.469 +			len      -= 2;
 114.470 +			bytes     = 0;
 114.471 +			writeData = 0;
 114.472 +			shift     = 0;
 114.473 +		}
 114.474 +	}
 114.475 +}
 114.476 +
 114.477 +void BIOS_Diff16bitUnFilter()
 114.478 +{
 114.479 +#ifdef GBA_LOGGING
 114.480 +	if (systemVerbose & VERBOSE_SWI)
 114.481 +	{
 114.482 +		log("Diff16bitUnFilter: 0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I,
 114.483 +		    reg[1].I, VCOUNT);
 114.484 +	}
 114.485 +#endif
 114.486 +
 114.487 +	u32 source = reg[0].I;
 114.488 +	u32 dest   = reg[1].I;
 114.489 +
 114.490 +	u32 header = CPUReadMemory(source);
 114.491 +	source += 4;
 114.492 +
 114.493 +	if (((source & 0xe000000) == 0) ||
 114.494 +	    ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
 114.495 +		return;
 114.496 +
 114.497 +	int len = header >> 8;
 114.498 +
 114.499 +	u16 data = CPUReadHalfWord(source);
 114.500 +	source += 2;
 114.501 +	CPUWriteHalfWord(dest, data);
 114.502 +	dest += 2;
 114.503 +	len  -= 2;
 114.504 +
 114.505 +	while (len >= 2)
 114.506 +	{
 114.507 +		u16 diff = CPUReadHalfWord(source);
 114.508 +		source += 2;
 114.509 +		data   += diff;
 114.510 +		CPUWriteHalfWord(dest, data);
 114.511 +		dest += 2;
 114.512 +		len  -= 2;
 114.513 +	}
 114.514 +}
 114.515 +
 114.516 +void BIOS_Div()
 114.517 +{
 114.518 +#ifdef GBA_LOGGING
 114.519 +	if (systemVerbose & VERBOSE_SWI)
 114.520 +	{
 114.521 +		log("Div: 0x%08x,0x%08x (VCOUNT=%d)\n",
 114.522 +		    reg[0].I,
 114.523 +		    reg[1].I,
 114.524 +		    VCOUNT);
 114.525 +	}
 114.526 +#endif
 114.527 +
 114.528 +	int number = reg[0].I;
 114.529 +	int denom  = reg[1].I;
 114.530 +
 114.531 +	if (denom != 0)
 114.532 +	{
 114.533 +		reg[0].I = number / denom;
 114.534 +		reg[1].I = number % denom;
 114.535 +		s32 temp = (s32)reg[0].I;
 114.536 +		reg[3].I = temp < 0 ? (u32)-temp : (u32)temp;
 114.537 +	}
 114.538 +#ifdef GBA_LOGGING
 114.539 +	if (systemVerbose & VERBOSE_SWI)
 114.540 +	{
 114.541 +		log("Div: return=0x%08x,0x%08x,0x%08x\n",
 114.542 +		    reg[0].I,
 114.543 +		    reg[1].I,
 114.544 +		    reg[3].I);
 114.545 +	}
 114.546 +#endif
 114.547 +}
 114.548 +
 114.549 +void BIOS_DivARM()
 114.550 +{
 114.551 +#ifdef GBA_LOGGING
 114.552 +	if (systemVerbose & VERBOSE_SWI)
 114.553 +	{
 114.554 +		log("DivARM: 0x%08x, (VCOUNT=%d)\n",
 114.555 +		    reg[0].I,
 114.556 +		    VCOUNT);
 114.557 +	}
 114.558 +#endif
 114.559 +
 114.560 +	u32 temp = reg[0].I;
 114.561 +	reg[0].I = reg[1].I;
 114.562 +	reg[1].I = temp;
 114.563 +	BIOS_Div();
 114.564 +}
 114.565 +
 114.566 +void BIOS_HuffUnComp()
 114.567 +{
 114.568 +#ifdef GBA_LOGGING
 114.569 +	if (systemVerbose & VERBOSE_SWI)
 114.570 +	{
 114.571 +		log("HuffUnComp: 0x%08x,0x%08x (VCOUNT=%d)\n",
 114.572 +		    reg[0].I,
 114.573 +		    reg[1].I,
 114.574 +		    VCOUNT);
 114.575 +	}
 114.576 +#endif
 114.577 +
 114.578 +	u32 source = reg[0].I;
 114.579 +	u32 dest   = reg[1].I;
 114.580 +
 114.581 +	u32 header = CPUReadMemory(source);
 114.582 +	source += 4;
 114.583 +
 114.584 +	if (((source & 0xe000000) == 0) ||
 114.585 +	    ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
 114.586 +		return;
 114.587 +
 114.588 +	u8 treeSize = CPUReadByte(source++);
 114.589 +
 114.590 +	u32 treeStart = source;
 114.591 +
 114.592 +	source += (treeSize<<1) + 1;
 114.593 +
 114.594 +	int len = header >> 8;
 114.595 +
 114.596 +	u32 mask = 0x80000000;
 114.597 +	u32 data = CPUReadMemory(source);
 114.598 +	source += 4;
 114.599 +
 114.600 +	int  pos         = 0;
 114.601 +	u8   rootNode    = CPUReadByte(treeStart);
 114.602 +	u8   currentNode = rootNode;
 114.603 +	bool writeData   = false;
 114.604 +	int  byteShift   = 0;
 114.605 +	int  byteCount   = 0;
 114.606 +	u32  writeValue  = 0;
 114.607 +
 114.608 +	if ((header & 0x0F) == 8)
 114.609 +	{
 114.610 +		while (len > 0)
 114.611 +		{
 114.612 +			// take left
 114.613 +			if (pos == 0)
 114.614 +				pos++;
 114.615 +			else
 114.616 +				pos += (((currentNode & 0x3F)+1)<<1);
 114.617 +
 114.618 +			if (data & mask)
 114.619 +			{
 114.620 +				// right
 114.621 +				if (currentNode & 0x40)
 114.622 +					writeData = true;
 114.623 +				currentNode = CPUReadByte(treeStart+pos+1);
 114.624 +			}
 114.625 +			else
 114.626 +			{
 114.627 +				// left
 114.628 +				if (currentNode & 0x80)
 114.629 +					writeData = true;
 114.630 +				currentNode = CPUReadByte(treeStart+pos);
 114.631 +			}
 114.632 +
 114.633 +			if (writeData)
 114.634 +			{
 114.635 +				writeValue |= (currentNode << byteShift);
 114.636 +				byteCount++;
 114.637 +				byteShift += 8;
 114.638 +
 114.639 +				pos         = 0;
 114.640 +				currentNode = rootNode;
 114.641 +				writeData   = false;
 114.642 +
 114.643 +				if (byteCount == 4)
 114.644 +				{
 114.645 +					byteCount = 0;
 114.646 +					byteShift = 0;
 114.647 +					CPUWriteMemory(dest, writeValue);
 114.648 +					writeValue = 0;
 114.649 +					dest      += 4;
 114.650 +					len       -= 4;
 114.651 +				}
 114.652 +			}
 114.653 +			mask >>= 1;
 114.654 +			if (mask == 0)
 114.655 +			{
 114.656 +				mask    = 0x80000000;
 114.657 +				data    = CPUReadMemory(source);
 114.658 +				source += 4;
 114.659 +			}
 114.660 +		}
 114.661 +	}
 114.662 +	else
 114.663 +	{
 114.664 +		int halfLen = 0;
 114.665 +		int value   = 0;
 114.666 +		while (len > 0)
 114.667 +		{
 114.668 +			// take left
 114.669 +			if (pos == 0)
 114.670 +				pos++;
 114.671 +			else
 114.672 +				pos += (((currentNode & 0x3F)+1)<<1);
 114.673 +
 114.674 +			if ((data & mask))
 114.675 +			{
 114.676 +				// right
 114.677 +				if (currentNode & 0x40)
 114.678 +					writeData = true;
 114.679 +				currentNode = CPUReadByte(treeStart+pos+1);
 114.680 +			}
 114.681 +			else
 114.682 +			{
 114.683 +				// left
 114.684 +				if (currentNode & 0x80)
 114.685 +					writeData = true;
 114.686 +				currentNode = CPUReadByte(treeStart+pos);
 114.687 +			}
 114.688 +
 114.689 +			if (writeData)
 114.690 +			{
 114.691 +				if (halfLen == 0)
 114.692 +					value |= currentNode;
 114.693 +				else
 114.694 +					value |= (currentNode<<4);
 114.695 +
 114.696 +				halfLen += 4;
 114.697 +				if (halfLen == 8)
 114.698 +				{
 114.699 +					writeValue |= (value << byteShift);
 114.700 +					byteCount++;
 114.701 +					byteShift += 8;
 114.702 +
 114.703 +					halfLen = 0;
 114.704 +					value   = 0;
 114.705 +
 114.706 +					if (byteCount == 4)
 114.707 +					{
 114.708 +						byteCount = 0;
 114.709 +						byteShift = 0;
 114.710 +						CPUWriteMemory(dest, writeValue);
 114.711 +						dest      += 4;
 114.712 +						writeValue = 0;
 114.713 +						len       -= 4;
 114.714 +					}
 114.715 +				}
 114.716 +				pos         = 0;
 114.717 +				currentNode = rootNode;
 114.718 +				writeData   = false;
 114.719 +			}
 114.720 +			mask >>= 1;
 114.721 +			if (mask == 0)
 114.722 +			{
 114.723 +				mask    = 0x80000000;
 114.724 +				data    = CPUReadMemory(source);
 114.725 +				source += 4;
 114.726 +			}
 114.727 +		}
 114.728 +	}
 114.729 +}
 114.730 +
 114.731 +void BIOS_LZ77UnCompVram()
 114.732 +{
 114.733 +#ifdef GBA_LOGGING
 114.734 +	if (systemVerbose & VERBOSE_SWI)
 114.735 +	{
 114.736 +		log("LZ77UnCompVram: 0x%08x,0x%08x (VCOUNT=%d)\n",
 114.737 +		    reg[0].I,
 114.738 +		    reg[1].I,
 114.739 +		    VCOUNT);
 114.740 +	}
 114.741 +#endif
 114.742 +
 114.743 +	u32 source = reg[0].I;
 114.744 +	u32 dest   = reg[1].I;
 114.745 +
 114.746 +	u32 header = CPUReadMemory(source);
 114.747 +	source += 4;
 114.748 +
 114.749 +	if (((source & 0xe000000) == 0) ||
 114.750 +	    ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
 114.751 +		return;
 114.752 +
 114.753 +	int byteCount  = 0;
 114.754 +	int byteShift  = 0;
 114.755 +	u32 writeValue = 0;
 114.756 +
 114.757 +	int len = header >> 8;
 114.758 +
 114.759 +	while (len > 0)
 114.760 +	{
 114.761 +		u8 d = CPUReadByte(source++);
 114.762 +
 114.763 +		if (d)
 114.764 +		{
 114.765 +			for (int i = 0; i < 8; i++)
 114.766 +			{
 114.767 +				if (d & 0x80)
 114.768 +				{
 114.769 +					u16 data = CPUReadByte(source++) << 8;
 114.770 +					data |= CPUReadByte(source++);
 114.771 +					int length       = (data >> 12) + 3;
 114.772 +					int offset       = (data & 0x0FFF);
 114.773 +					u32 windowOffset = dest + byteCount - offset - 1;
 114.774 +					for (int i = 0; i < length; i++)
 114.775 +					{
 114.776 +						writeValue |= (CPUReadByte(windowOffset++) << byteShift);
 114.777 +						byteShift  += 8;
 114.778 +						byteCount++;
 114.779 +
 114.780 +						if (byteCount == 2)
 114.781 +						{
 114.782 +							CPUWriteHalfWord(dest, writeValue);
 114.783 +							dest      += 2;
 114.784 +							byteCount  = 0;
 114.785 +							byteShift  = 0;
 114.786 +							writeValue = 0;
 114.787 +						}
 114.788 +						len--;
 114.789 +						if (len == 0)
 114.790 +							return;
 114.791 +					}
 114.792 +				}
 114.793 +				else
 114.794 +				{
 114.795 +					writeValue |= (CPUReadByte(source++) << byteShift);
 114.796 +					byteShift  += 8;
 114.797 +					byteCount++;
 114.798 +					if (byteCount == 2)
 114.799 +					{
 114.800 +						CPUWriteHalfWord(dest, writeValue);
 114.801 +						dest      += 2;
 114.802 +						byteCount  = 0;
 114.803 +						byteShift  = 0;
 114.804 +						writeValue = 0;
 114.805 +					}
 114.806 +					len--;
 114.807 +					if (len == 0)
 114.808 +						return;
 114.809 +				}
 114.810 +				d <<= 1;
 114.811 +			}
 114.812 +		}
 114.813 +		else
 114.814 +		{
 114.815 +			for (int i = 0; i < 8; i++)
 114.816 +			{
 114.817 +				writeValue |= (CPUReadByte(source++) << byteShift);
 114.818 +				byteShift  += 8;
 114.819 +				byteCount++;
 114.820 +				if (byteCount == 2)
 114.821 +				{
 114.822 +					CPUWriteHalfWord(dest, writeValue);
 114.823 +					dest      += 2;
 114.824 +					byteShift  = 0;
 114.825 +					byteCount  = 0;
 114.826 +					writeValue = 0;
 114.827 +				}
 114.828 +				len--;
 114.829 +				if (len == 0)
 114.830 +					return;
 114.831 +			}
 114.832 +		}
 114.833 +	}
 114.834 +}
 114.835 +
 114.836 +void BIOS_LZ77UnCompWram()
 114.837 +{
 114.838 +#ifdef GBA_LOGGING
 114.839 +	if (systemVerbose & VERBOSE_SWI)
 114.840 +	{
 114.841 +		log("LZ77UnCompWram: 0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I, reg[1].I,
 114.842 +		    VCOUNT);
 114.843 +	}
 114.844 +#endif
 114.845 +
 114.846 +	u32 source = reg[0].I;
 114.847 +	u32 dest   = reg[1].I;
 114.848 +
 114.849 +	u32 header = CPUReadMemory(source);
 114.850 +	source += 4;
 114.851 +
 114.852 +	if (((source & 0xe000000) == 0) ||
 114.853 +	    ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
 114.854 +		return;
 114.855 +
 114.856 +	int len = header >> 8;
 114.857 +
 114.858 +	while (len > 0)
 114.859 +	{
 114.860 +		u8 d = CPUReadByte(source++);
 114.861 +
 114.862 +		if (d)
 114.863 +		{
 114.864 +			for (int i = 0; i < 8; i++)
 114.865 +			{
 114.866 +				if (d & 0x80)
 114.867 +				{
 114.868 +					u16 data = CPUReadByte(source++) << 8;
 114.869 +					data |= CPUReadByte(source++);
 114.870 +					int length       = (data >> 12) + 3;
 114.871 +					int offset       = (data & 0x0FFF);
 114.872 +					u32 windowOffset = dest - offset - 1;
 114.873 +					for (int i = 0; i < length; i++)
 114.874 +					{
 114.875 +						CPUWriteByte(dest++, CPUReadByte(windowOffset++));
 114.876 +						len--;
 114.877 +						if (len == 0)
 114.878 +							return;
 114.879 +					}
 114.880 +				}
 114.881 +				else
 114.882 +				{
 114.883 +					CPUWriteByte(dest++, CPUReadByte(source++));
 114.884 +					len--;
 114.885 +					if (len == 0)
 114.886 +						return;
 114.887 +				}
 114.888 +				d <<= 1;
 114.889 +			}
 114.890 +		}
 114.891 +		else
 114.892 +		{
 114.893 +			for (int i = 0; i < 8; i++)
 114.894 +			{
 114.895 +				CPUWriteByte(dest++, CPUReadByte(source++));
 114.896 +				len--;
 114.897 +				if (len == 0)
 114.898 +					return;
 114.899 +			}
 114.900 +		}
 114.901 +	}
 114.902 +}
 114.903 +
 114.904 +void BIOS_ObjAffineSet()
 114.905 +{
 114.906 +#ifdef GBA_LOGGING
 114.907 +	if (systemVerbose & VERBOSE_SWI)
 114.908 +	{
 114.909 +		log("ObjAffineSet: 0x%08x,0x%08x,0x%08x,0x%08x (VCOUNT=%d)\n",
 114.910 +		    reg[0].I,
 114.911 +		    reg[1].I,
 114.912 +		    reg[2].I,
 114.913 +		    reg[3].I,
 114.914 +		    VCOUNT);
 114.915 +	}
 114.916 +#endif
 114.917 +
 114.918 +	u32 src    = reg[0].I;
 114.919 +	u32 dest   = reg[1].I;
 114.920 +	int num    = reg[2].I;
 114.921 +	int offset = reg[3].I;
 114.922 +
 114.923 +	for (int i = 0; i < num; i++)
 114.924 +	{
 114.925 +		s16 rx = CPUReadHalfWord(src);
 114.926 +		src += 2;
 114.927 +		s16 ry = CPUReadHalfWord(src);
 114.928 +		src += 2;
 114.929 +		u16 theta = CPUReadHalfWord(src)>>8;
 114.930 +		src += 4; // keep structure alignment
 114.931 +
 114.932 +		s32 a = (s32)sineTable[(theta+0x40)&255];
 114.933 +		s32 b = (s32)sineTable[theta];
 114.934 +
 114.935 +		s16 dx  =  (s16)((rx * a)>>14);
 114.936 +		s16 dmx = (s16)((rx * b)>>14);
 114.937 +		s16 dy  =  (s16)((ry * b)>>14);
 114.938 +		s16 dmy = (s16)((ry * a)>>14);
 114.939 +
 114.940 +		CPUWriteHalfWord(dest, dx);
 114.941 +		dest += offset;
 114.942 +		CPUWriteHalfWord(dest, -dmx);
 114.943 +		dest += offset;
 114.944 +		CPUWriteHalfWord(dest, dy);
 114.945 +		dest += offset;
 114.946 +		CPUWriteHalfWord(dest, dmy);
 114.947 +		dest += offset;
 114.948 +	}
 114.949 +}
 114.950 +
 114.951 +void BIOS_RegisterRamReset(u32 flags)
 114.952 +{
 114.953 +	// no need to trace here. this is only called directly from GBA.cpp
 114.954 +	// to emulate bios initialization
 114.955 +
 114.956 +	if (flags)
 114.957 +	{
 114.958 +		if (flags & 0x01)
 114.959 +		{
 114.960 +			// clear work RAM
 114.961 +			memset(workRAM, 0, 0x40000);
 114.962 +		}
 114.963 +		if (flags & 0x02)
 114.964 +		{
 114.965 +			// clear internal RAM
 114.966 +			memset(internalRAM, 0, 0x7e00); // don't clear 0x7e00-0x7fff
 114.967 +		}
 114.968 +		if (flags & 0x04)
 114.969 +		{
 114.970 +			// clear palette RAM
 114.971 +			memset(paletteRAM, 0, 0x400);
 114.972 +		}
 114.973 +		if (flags & 0x08)
 114.974 +		{
 114.975 +			// clear VRAM
 114.976 +			memset(vram, 0, 0x18000);
 114.977 +		}
 114.978 +		if (flags & 0x10)
 114.979 +		{
 114.980 +			// clean OAM
 114.981 +			memset(oam, 0, 0x400);
 114.982 +		}
 114.983 +
 114.984 +		if (flags & 0x80)
 114.985 +		{
 114.986 +			int i;
 114.987 +			for (i = 0; i < 8; i++)
 114.988 +				CPUUpdateRegister(0x200+i*2, 0);
 114.989 +
 114.990 +			CPUUpdateRegister(0x202, 0xFFFF);
 114.991 +
 114.992 +			for (i = 0; i < 8; i++)
 114.993 +				CPUUpdateRegister(0x4+i*2, 0);
 114.994 +
 114.995 +			for (i = 0; i < 16; i++)
 114.996 +				CPUUpdateRegister(0x20+i*2, 0);
 114.997 +
 114.998 +			for (i = 0; i < 24; i++)
 114.999 +				CPUUpdateRegister(0xb0+i*2, 0);
114.1000 +
114.1001 +			CPUUpdateRegister(0x130, 0);
114.1002 +			CPUUpdateRegister(0x20, 0x100);
114.1003 +			CPUUpdateRegister(0x30, 0x100);
114.1004 +			CPUUpdateRegister(0x26, 0x100);
114.1005 +			CPUUpdateRegister(0x36, 0x100);
114.1006 +		}
114.1007 +
114.1008 +		if (flags & 0x20)
114.1009 +		{
114.1010 +			int i;
114.1011 +			for (i = 0; i < 8; i++)
114.1012 +				CPUUpdateRegister(0x110+i*2, 0);
114.1013 +			CPUUpdateRegister(0x134, 0x8000);
114.1014 +			for (i = 0; i < 7; i++)
114.1015 +				CPUUpdateRegister(0x140+i*2, 0);
114.1016 +		}
114.1017 +
114.1018 +		if (flags & 0x40)
114.1019 +		{
114.1020 +			int i;
114.1021 +			CPUWriteByte(0x4000084, 0);
114.1022 +			CPUWriteByte(0x4000084, 0x80);
114.1023 +			CPUWriteMemory(0x4000080, 0x880e0000);
114.1024 +			CPUUpdateRegister(0x88, CPUReadHalfWord(0x4000088)&0x3ff);
114.1025 +			CPUWriteByte(0x4000070, 0x70);
114.1026 +			for (i = 0; i < 8; i++)
114.1027 +				CPUUpdateRegister(0x90+i*2, 0);
114.1028 +			CPUWriteByte(0x4000070, 0);
114.1029 +			for (i = 0; i < 8; i++)
114.1030 +				CPUUpdateRegister(0x90+i*2, 0);
114.1031 +			CPUWriteByte(0x4000084, 0);
114.1032 +		}
114.1033 +	}
114.1034 +}
114.1035 +
114.1036 +void BIOS_RegisterRamReset()
114.1037 +{
114.1038 +#ifdef GBA_LOGGING
114.1039 +	if (systemVerbose & VERBOSE_SWI)
114.1040 +	{
114.1041 +		log("RegisterRamReset: 0x%08x (VCOUNT=%d)\n",
114.1042 +		    reg[0].I,
114.1043 +		    VCOUNT);
114.1044 +	}
114.1045 +#endif
114.1046 +
114.1047 +	BIOS_RegisterRamReset(reg[0].I);
114.1048 +}
114.1049 +
114.1050 +void BIOS_RLUnCompVram()
114.1051 +{
114.1052 +#ifdef GBA_LOGGING
114.1053 +	if (systemVerbose & VERBOSE_SWI)
114.1054 +	{
114.1055 +		log("RLUnCompVram: 0x%08x,0x%08x (VCOUNT=%d)\n",
114.1056 +		    reg[0].I,
114.1057 +		    reg[1].I,
114.1058 +		    VCOUNT);
114.1059 +	}
114.1060 +#endif
114.1061 +
114.1062 +	u32 source = reg[0].I;
114.1063 +	u32 dest   = reg[1].I;
114.1064 +
114.1065 +	u32 header = CPUReadMemory(source);
114.1066 +	source += 4;
114.1067 +
114.1068 +	if (((source & 0xe000000) == 0) ||
114.1069 +	    ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
114.1070 +		return;
114.1071 +
114.1072 +	int len        = header >> 8;
114.1073 +	int byteCount  = 0;
114.1074 +	int byteShift  = 0;
114.1075 +	u32 writeValue = 0;
114.1076 +
114.1077 +	while (len > 0)
114.1078 +	{
114.1079 +		u8  d = CPUReadByte(source++);
114.1080 +		int l = d & 0x7F;
114.1081 +		if (d & 0x80)
114.1082 +		{
114.1083 +			u8 data = CPUReadByte(source++);
114.1084 +			l += 3;
114.1085 +			for (int i = 0; i < l; i++)
114.1086 +			{
114.1087 +				writeValue |= (data << byteShift);
114.1088 +				byteShift  += 8;
114.1089 +				byteCount++;
114.1090 +
114.1091 +				if (byteCount == 2)
114.1092 +				{
114.1093 +					CPUWriteHalfWord(dest, writeValue);
114.1094 +					dest      += 2;
114.1095 +					byteCount  = 0;
114.1096 +					byteShift  = 0;
114.1097 +					writeValue = 0;
114.1098 +				}
114.1099 +				len--;
114.1100 +				if (len == 0)
114.1101 +					return;
114.1102 +			}
114.1103 +		}
114.1104 +		else
114.1105 +		{
114.1106 +			l++;
114.1107 +			for (int i = 0; i < l; i++)
114.1108 +			{
114.1109 +				writeValue |= (CPUReadByte(source++) << byteShift);
114.1110 +				byteShift  += 8;
114.1111 +				byteCount++;
114.1112 +				if (byteCount == 2)
114.1113 +				{
114.1114 +					CPUWriteHalfWord(dest, writeValue);
114.1115 +					dest      += 2;
114.1116 +					byteCount  = 0;
114.1117 +					byteShift  = 0;
114.1118 +					writeValue = 0;
114.1119 +				}
114.1120 +				len--;
114.1121 +				if (len == 0)
114.1122 +					return;
114.1123 +			}
114.1124 +		}
114.1125 +	}
114.1126 +}
114.1127 +
114.1128 +void BIOS_RLUnCompWram()
114.1129 +{
114.1130 +#ifdef GBA_LOGGING
114.1131 +	if (systemVerbose & VERBOSE_SWI)
114.1132 +	{
114.1133 +		log("RLUnCompWram: 0x%08x,0x%08x (VCOUNT=%d)\n",
114.1134 +		    reg[0].I,
114.1135 +		    reg[1].I,
114.1136 +		    VCOUNT);
114.1137 +	}
114.1138 +#endif
114.1139 +
114.1140 +	u32 source = reg[0].I;
114.1141 +	u32 dest   = reg[1].I;
114.1142 +
114.1143 +	u32 header = CPUReadMemory(source);
114.1144 +	source += 4;
114.1145 +
114.1146 +	if (((source & 0xe000000) == 0) ||
114.1147 +	    ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
114.1148 +		return;
114.1149 +
114.1150 +	int len = header >> 8;
114.1151 +
114.1152 +	while (len > 0)
114.1153 +	{
114.1154 +		u8  d = CPUReadByte(source++);
114.1155 +		int l = d & 0x7F;
114.1156 +		if (d & 0x80)
114.1157 +		{
114.1158 +			u8 data = CPUReadByte(source++);
114.1159 +			l += 3;
114.1160 +			for (int i = 0; i < l; i++)
114.1161 +			{
114.1162 +				CPUWriteByte(dest++, data);
114.1163 +				len--;
114.1164 +				if (len == 0)
114.1165 +					return;
114.1166 +			}
114.1167 +		}
114.1168 +		else
114.1169 +		{
114.1170 +			l++;
114.1171 +			for (int i = 0; i < l; i++)
114.1172 +			{
114.1173 +				CPUWriteByte(dest++,  CPUReadByte(source++));
114.1174 +				len--;
114.1175 +				if (len == 0)
114.1176 +					return;
114.1177 +			}
114.1178 +		}
114.1179 +	}
114.1180 +}
114.1181 +
114.1182 +void BIOS_SoftReset()
114.1183 +{
114.1184 +#ifdef GBA_LOGGING
114.1185 +	if (systemVerbose & VERBOSE_SWI)
114.1186 +	{
114.1187 +		log("SoftReset: (VCOUNT=%d)\n", VCOUNT);
114.1188 +	}
114.1189 +#endif
114.1190 +
114.1191 +	armState        = true;
114.1192 +	armMode         = 0x1F;
114.1193 +	armIrqEnable    = false;
114.1194 +	C_FLAG          = V_FLAG = N_FLAG = Z_FLAG = false;
114.1195 +	reg[13].I       = 0x03007F00;
114.1196 +	reg[14].I       = 0x00000000;
114.1197 +	reg[16].I       = 0x00000000;
114.1198 +	reg[R13_IRQ].I  = 0x03007FA0;
114.1199 +	reg[R14_IRQ].I  = 0x00000000;
114.1200 +	reg[SPSR_IRQ].I = 0x00000000;
114.1201 +	reg[R13_SVC].I  = 0x03007FE0;
114.1202 +	reg[R14_SVC].I  = 0x00000000;
114.1203 +	reg[SPSR_SVC].I = 0x00000000;
114.1204 +	u8 b = internalRAM[0x7ffa];
114.1205 +
114.1206 +	memset(&internalRAM[0x7e00], 0, 0x200);
114.1207 +
114.1208 +	if (b)
114.1209 +	{
114.1210 +		armNextPC = 0x02000000;
114.1211 +		reg[15].I = 0x02000004;
114.1212 +	}
114.1213 +	else
114.1214 +	{
114.1215 +		armNextPC = 0x08000000;
114.1216 +		reg[15].I = 0x08000004;
114.1217 +	}
114.1218 +}
114.1219 +
114.1220 +void BIOS_Sqrt()
114.1221 +{
114.1222 +#ifdef GBA_LOGGING
114.1223 +	if (systemVerbose & VERBOSE_SWI)
114.1224 +	{
114.1225 +		log("Sqrt: %08x (VCOUNT=%2d)\n",
114.1226 +		    reg[0].I,
114.1227 +		    VCOUNT);
114.1228 +	}
114.1229 +#endif
114.1230 +	reg[0].I = (u32)sqrt((double)reg[0].I);
114.1231 +#ifdef GBA_LOGGING
114.1232 +	if (systemVerbose & VERBOSE_SWI)
114.1233 +	{
114.1234 +		log("Sqrt: return=%08x\n",
114.1235 +		    reg[0].I);
114.1236 +	}
114.1237 +#endif
114.1238 +}
114.1239 +
114.1240 +void BIOS_MidiKey2Freq()
114.1241 +{
114.1242 +#ifdef GBA_LOGGING
114.1243 +	if (systemVerbose & VERBOSE_SWI)
114.1244 +	{
114.1245 +		log("MidiKey2Freq: WaveData=%08x mk=%08x fp=%08x\n",
114.1246 +		    reg[0].I,
114.1247 +		    reg[1].I,
114.1248 +		    reg[2].I);
114.1249 +	}
114.1250 +#endif
114.1251 +	int    freq = CPUReadMemory(reg[0].I+4);
114.1252 +	double tmp;
114.1253 +	tmp      = ((double)(180 - reg[1].I)) - ((double)reg[2].I / 256.f);
114.1254 +	tmp      = pow((double)2.f, tmp / 12.f);
114.1255 +	reg[0].I = (int)((double)freq / tmp);
114.1256 +
114.1257 +#ifdef GBA_LOGGING
114.1258 +	if (systemVerbose & VERBOSE_SWI)
114.1259 +	{
114.1260 +		log("MidiKey2Freq: return %08x\n",
114.1261 +		    reg[0].I);
114.1262 +	}
114.1263 +#endif
114.1264 +}
114.1265 +
114.1266 +void BIOS_SndDriverJmpTableCopy()
114.1267 +{
114.1268 +#ifdef GBA_LOGGING
114.1269 +	if (systemVerbose & VERBOSE_SWI)
114.1270 +	{
114.1271 +		log("SndDriverJmpTableCopy: dest=%08x\n",
114.1272 +		    reg[0].I);
114.1273 +	}
114.1274 +#endif
114.1275 +	for (int i = 0; i < 0x24; i++)
114.1276 +	{
114.1277 +		CPUWriteMemory(reg[0].I, 0x9c);
114.1278 +		reg[0].I += 4;
114.1279 +	}
114.1280 +}
114.1281 +
   115.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   115.2 +++ b/src/gba/bios.h	Sat Mar 03 10:31:27 2012 -0600
   115.3 @@ -0,0 +1,34 @@
   115.4 +#ifndef VBA_BIOS_H
   115.5 +#define VBA_BIOS_H
   115.6 +
   115.7 +#if _MSC_VER > 1000
   115.8 +#pragma once
   115.9 +#endif // _MSC_VER > 1000
  115.10 +
  115.11 +#include "../Port.h"
  115.12 +
  115.13 +extern void BIOS_ArcTan();
  115.14 +extern void BIOS_ArcTan2();
  115.15 +extern void BIOS_BitUnPack();
  115.16 +extern void BIOS_BgAffineSet();
  115.17 +extern void BIOS_CpuSet();
  115.18 +extern void BIOS_CpuFastSet();
  115.19 +extern void BIOS_Diff8bitUnFilterWram();
  115.20 +extern void BIOS_Diff8bitUnFilterVram();
  115.21 +extern void BIOS_Diff16bitUnFilter();
  115.22 +extern void BIOS_Div();
  115.23 +extern void BIOS_DivARM();
  115.24 +extern void BIOS_HuffUnComp();
  115.25 +extern void BIOS_LZ77UnCompVram();
  115.26 +extern void BIOS_LZ77UnCompWram();
  115.27 +extern void BIOS_ObjAffineSet();
  115.28 +extern void BIOS_RegisterRamReset();
  115.29 +extern void BIOS_RegisterRamReset(u32);
  115.30 +extern void BIOS_RLUnCompVram();
  115.31 +extern void BIOS_RLUnCompWram();
  115.32 +extern void BIOS_SoftReset();
  115.33 +extern void BIOS_Sqrt();
  115.34 +extern void BIOS_MidiKey2Freq();
  115.35 +extern void BIOS_SndDriverJmpTableCopy();
  115.36 +
  115.37 +#endif // VBA_BIOS_H
   116.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   116.2 +++ b/src/gba/elf.cpp	Sat Mar 03 10:31:27 2012 -0600
   116.3 @@ -0,0 +1,3229 @@
   116.4 +#include <cstdio>
   116.5 +#include <cstdlib>
   116.6 +#include <cstring>
   116.7 +
   116.8 +#include "../Port.h"
   116.9 +#include "../NLS.h"
  116.10 +#include "../common/System.h" // systemMessage
  116.11 +#include "GBAGlobals.h"
  116.12 +#include "elf.h"
  116.13 +
  116.14 +#define elfReadMemory(addr) \
  116.15 +    READ32LE((&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
  116.16 +
  116.17 +#define DW_TAG_array_type             0x01
  116.18 +#define DW_TAG_enumeration_type       0x04
  116.19 +#define DW_TAG_formal_parameter       0x05
  116.20 +#define DW_TAG_label                  0x0a
  116.21 +#define DW_TAG_lexical_block          0x0b
  116.22 +#define DW_TAG_member                 0x0d
  116.23 +#define DW_TAG_pointer_type           0x0f
  116.24 +#define DW_TAG_reference_type         0x10
  116.25 +#define DW_TAG_compile_unit           0x11
  116.26 +#define DW_TAG_structure_type         0x13
  116.27 +#define DW_TAG_subroutine_type        0x15
  116.28 +#define DW_TAG_typedef                0x16
  116.29 +#define DW_TAG_union_type             0x17
  116.30 +#define DW_TAG_unspecified_parameters 0x18
  116.31 +#define DW_TAG_inheritance            0x1c
  116.32 +#define DW_TAG_inlined_subroutine     0x1d
  116.33 +#define DW_TAG_subrange_type          0x21
  116.34 +#define DW_TAG_base_type              0x24
  116.35 +#define DW_TAG_const_type             0x26
  116.36 +#define DW_TAG_enumerator             0x28
  116.37 +#define DW_TAG_subprogram             0x2e
  116.38 +#define DW_TAG_variable               0x34
  116.39 +#define DW_TAG_volatile_type          0x35
  116.40 +
  116.41 +#define DW_AT_sibling              0x01
  116.42 +#define DW_AT_location             0x02
  116.43 +#define DW_AT_name                 0x03
  116.44 +#define DW_AT_byte_size            0x0b
  116.45 +#define DW_AT_bit_offset           0x0c
  116.46 +#define DW_AT_bit_size             0x0d
  116.47 +#define DW_AT_stmt_list            0x10
  116.48 +#define DW_AT_low_pc               0x11
  116.49 +#define DW_AT_high_pc              0x12
  116.50 +#define DW_AT_language             0x13
  116.51 +#define DW_AT_compdir              0x1b
  116.52 +#define DW_AT_const_value          0x1c
  116.53 +#define DW_AT_containing_type      0x1d
  116.54 +#define DW_AT_inline               0x20
  116.55 +#define DW_AT_producer             0x25
  116.56 +#define DW_AT_prototyped           0x27
  116.57 +#define DW_AT_upper_bound          0x2f
  116.58 +#define DW_AT_abstract_origin      0x31
  116.59 +#define DW_AT_accessibility        0x32
  116.60 +#define DW_AT_artificial           0x34
  116.61 +#define DW_AT_data_member_location 0x38
  116.62 +#define DW_AT_decl_file            0x3a
  116.63 +#define DW_AT_decl_line            0x3b
  116.64 +#define DW_AT_declaration          0x3c
  116.65 +#define DW_AT_encoding             0x3e
  116.66 +#define DW_AT_external             0x3f
  116.67 +#define DW_AT_frame_base           0x40
  116.68 +#define DW_AT_macro_info           0x43
  116.69 +#define DW_AT_specification        0x47
  116.70 +#define DW_AT_type                 0x49
  116.71 +#define DW_AT_virtuality           0x4c
  116.72 +#define DW_AT_vtable_elem_location 0x4d
  116.73 +// DWARF 2.1/3.0 extensions
  116.74 +#define DW_AT_entry_pc             0x52
  116.75 +#define DW_AT_ranges               0x55
  116.76 +// ARM Compiler extensions
  116.77 +#define DW_AT_proc_body            0x2000
  116.78 +#define DW_AT_save_offset          0x2001
  116.79 +#define DW_AT_user_2002            0x2002
  116.80 +// MIPS extensions
  116.81 +#define DW_AT_MIPS_linkage_name    0x2007
  116.82 +
  116.83 +#define DW_FORM_addr      0x01
  116.84 +#define DW_FORM_data2     0x05
  116.85 +#define DW_FORM_data4     0x06
  116.86 +#define DW_FORM_string    0x08
  116.87 +#define DW_FORM_block     0x09
  116.88 +#define DW_FORM_block1    0x0a
  116.89 +#define DW_FORM_data1     0x0b
  116.90 +#define DW_FORM_flag      0x0c
  116.91 +#define DW_FORM_sdata     0x0d
  116.92 +#define DW_FORM_strp      0x0e
  116.93 +#define DW_FORM_udata     0x0f
  116.94 +#define DW_FORM_ref_addr  0x10
  116.95 +#define DW_FORM_ref4      0x13
  116.96 +#define DW_FORM_ref_udata 0x15
  116.97 +#define DW_FORM_indirect  0x16
  116.98 +
  116.99 +#define DW_OP_addr        0x03
 116.100 +#define DW_OP_plus_uconst 0x23
 116.101 +#define DW_OP_reg0        0x50
 116.102 +#define DW_OP_reg1        0x51
 116.103 +#define DW_OP_reg2        0x52
 116.104 +#define DW_OP_reg3        0x53
 116.105 +#define DW_OP_reg4        0x54
 116.106 +#define DW_OP_reg5        0x55
 116.107 +#define DW_OP_reg6        0x56
 116.108 +#define DW_OP_reg7        0x57
 116.109 +#define DW_OP_reg8        0x58
 116.110 +#define DW_OP_reg9        0x59
 116.111 +#define DW_OP_reg10       0x5a
 116.112 +#define DW_OP_reg11       0x5b
 116.113 +#define DW_OP_reg12       0x5c
 116.114 +#define DW_OP_reg13       0x5d
 116.115 +#define DW_OP_reg14       0x5e
 116.116 +#define DW_OP_reg15       0x5f
 116.117 +#define DW_OP_fbreg       0x91
 116.118 +
 116.119 +#define DW_LNS_extended_op      0x00
 116.120 +#define DW_LNS_copy             0x01
 116.121 +#define DW_LNS_advance_pc       0x02
 116.122 +#define DW_LNS_advance_line     0x03
 116.123 +#define DW_LNS_set_file         0x04
 116.124 +#define DW_LNS_set_column       0x05
 116.125 +#define DW_LNS_negate_stmt      0x06
 116.126 +#define DW_LNS_set_basic_block  0x07
 116.127 +#define DW_LNS_const_add_pc     0x08
 116.128 +#define DW_LNS_fixed_advance_pc 0x09
 116.129 +
 116.130 +#define DW_LNE_end_sequence 0x01
 116.131 +#define DW_LNE_set_address  0x02
 116.132 +#define DW_LNE_define_file  0x03
 116.133 +
 116.134 +#define DW_CFA_advance_loc      0x01
 116.135 +#define DW_CFA_offset           0x02
 116.136 +#define DW_CFA_restore          0x03
 116.137 +#define DW_CFA_set_loc          0x01
 116.138 +#define DW_CFA_advance_loc1     0x02
 116.139 +#define DW_CFA_advance_loc2     0x03
 116.140 +#define DW_CFA_advance_loc4     0x04
 116.141 +#define DW_CFA_offset_extended  0x05
 116.142 +#define DW_CFA_restore_extended 0x06
 116.143 +#define DW_CFA_undefined        0x07
 116.144 +#define DW_CFA_same_value       0x08
 116.145 +#define DW_CFA_register         0x09
 116.146 +#define DW_CFA_remember_state   0x0a
 116.147 +#define DW_CFA_restore_state    0x0b
 116.148 +#define DW_CFA_def_cfa          0x0c
 116.149 +#define DW_CFA_def_cfa_register 0x0d
 116.150 +#define DW_CFA_def_cfa_offset   0x0e
 116.151 +#define DW_CFA_nop              0x00
 116.152 +
 116.153 +#define CASE_TYPE_TAG \
 116.154 +case DW_TAG_const_type: \
 116.155 +case DW_TAG_volatile_type: \
 116.156 +case DW_TAG_pointer_type: \
 116.157 +case DW_TAG_base_type: \
 116.158 +case DW_TAG_array_type: \
 116.159 +case DW_TAG_structure_type: \
 116.160 +case DW_TAG_union_type: \
 116.161 +case DW_TAG_typedef: \
 116.162 +case DW_TAG_subroutine_type: \
 116.163 +case DW_TAG_enumeration_type: \
 116.164 +case DW_TAG_enumerator: \
 116.165 +case DW_TAG_reference_type
 116.166 +
 116.167 +struct ELFcie
 116.168 +{
 116.169 +	ELFcie *next;
 116.170 +	u32     offset;
 116.171 +	u8 *    augmentation;
 116.172 +	u32     codeAlign;
 116.173 +	s32     dataAlign;
 116.174 +	int     returnAddress;
 116.175 +	u8 *    data;
 116.176 +	u32     dataLen;
 116.177 +};
 116.178 +
 116.179 +struct ELFfde
 116.180 +{
 116.181 +	ELFcie *cie;
 116.182 +	u32     address;
 116.183 +	u32     end;
 116.184 +	u8 *    data;
 116.185 +	u32     dataLen;
 116.186 +};
 116.187 +
 116.188 +enum ELFRegMode
 116.189 +{
 116.190 +	REG_NOT_SET,
 116.191 +	REG_OFFSET,
 116.192 +	REG_REGISTER
 116.193 +};
 116.194 +
 116.195 +struct ELFFrameStateRegister
 116.196 +{
 116.197 +	ELFRegMode mode;
 116.198 +	int        reg;
 116.199 +	s32        offset;
 116.200 +};
 116.201 +
 116.202 +struct ELFFrameStateRegisters
 116.203 +{
 116.204 +	ELFFrameStateRegister   regs[16];
 116.205 +	ELFFrameStateRegisters *previous;
 116.206 +};
 116.207 +
 116.208 +enum ELFCfaMode
 116.209 +{
 116.210 +	CFA_NOT_SET,
 116.211 +	CFA_REG_OFFSET
 116.212 +};
 116.213 +
 116.214 +struct ELFFrameState
 116.215 +{
 116.216 +	ELFFrameStateRegisters registers;
 116.217 +
 116.218 +	ELFCfaMode cfaMode;
 116.219 +	int        cfaRegister;
 116.220 +	s32        cfaOffset;
 116.221 +
 116.222 +	u32 pc;
 116.223 +
 116.224 +	int dataAlign;
 116.225 +	int codeAlign;
 116.226 +	int returnAddress;
 116.227 +};
 116.228 +
 116.229 +extern bool8 cpuIsMultiBoot;
 116.230 +
 116.231 +Symbol *elfSymbols       = NULL;
 116.232 +char *  elfSymbolsStrTab = NULL;
 116.233 +int     elfSymbolsCount  = 0;
 116.234 +
 116.235 +ELFSectionHeader **elfSectionHeaders = NULL;
 116.236 +char *elfSectionHeadersStringTable   = NULL;
 116.237 +int   elfSectionHeadersCount         = 0;
 116.238 +u8 *  elfFileData = NULL;
 116.239 +
 116.240 +CompileUnit *elfCompileUnits = NULL;
 116.241 +DebugInfo *  elfDebugInfo    = NULL;
 116.242 +char *       elfDebugStrings = NULL;
 116.243 +
 116.244 +ELFcie * elfCies     = NULL;
 116.245 +ELFfde **elfFdes     = NULL;
 116.246 +int      elfFdeCount = 0;
 116.247 +
 116.248 +CompileUnit *elfCurrentUnit = NULL;
 116.249 +
 116.250 +u32 elfRead4Bytes(u8 *);
 116.251 +u16 elfRead2Bytes(u8 *);
 116.252 +
 116.253 +CompileUnit *elfGetCompileUnit(u32 addr)
 116.254 +{
 116.255 +	if (elfCompileUnits)
 116.256 +	{
 116.257 +		CompileUnit *unit = elfCompileUnits;
 116.258 +		while (unit)
 116.259 +		{
 116.260 +			if (unit->lowPC)
 116.261 +			{
 116.262 +				if (addr >= unit->lowPC && addr < unit->highPC)
 116.263 +					return unit;
 116.264 +			}
 116.265 +			else
 116.266 +			{
 116.267 +				ARanges *r = unit->ranges;
 116.268 +				if (r)
 116.269 +				{
 116.270 +					int count = r->count;
 116.271 +					for (int j = 0; j < count; j++)
 116.272 +					{
 116.273 +						if (addr >= r->ranges[j].lowPC && addr < r->ranges[j].highPC)
 116.274 +							return unit;
 116.275 +					}
 116.276 +				}
 116.277 +			}
 116.278 +			unit = unit->next;
 116.279 +		}
 116.280 +	}
 116.281 +	return NULL;
 116.282 +}
 116.283 +
 116.284 +char *elfGetAddressSymbol(u32 addr)
 116.285 +{
 116.286 +	static char buffer[256];
 116.287 +
 116.288 +	CompileUnit *unit = elfGetCompileUnit(addr);
 116.289 +	// found unit, need to find function
 116.290 +	if (unit)
 116.291 +	{
 116.292 +		Function *func = unit->functions;
 116.293 +		while (func)
 116.294 +		{
 116.295 +			if (addr >= func->lowPC && addr < func->highPC)
 116.296 +			{
 116.297 +				int   offset = addr - func->lowPC;
 116.298 +				char *name   = func->name;
 116.299 +				if (!name)
 116.300 +					name = "";
 116.301 +				if (offset)
 116.302 +					sprintf(buffer, "%s+%d", name, offset);
 116.303 +				else
 116.304 +					strcpy(buffer, name);
 116.305 +				return buffer;
 116.306 +			}
 116.307 +			func = func->next;
 116.308 +		}
 116.309 +	}
 116.310 +
 116.311 +	if (elfSymbolsCount)
 116.312 +	{
 116.313 +		for (int i = 0; i < elfSymbolsCount; i++)
 116.314 +		{
 116.315 +			Symbol *s = &elfSymbols[i];
 116.316 +			if ((addr >= s->value)  && addr < (s->value+s->size))
 116.317 +			{
 116.318 +				int   offset = addr-s->value;
 116.319 +				char *name   = s->name;
 116.320 +				if (name == NULL)
 116.321 +					name = "";
 116.322 +				if (offset)
 116.323 +					sprintf(buffer, "%s+%d", name, addr-s->value);
 116.324 +				else
 116.325 +					strcpy(buffer, name);
 116.326 +				return buffer;
 116.327 +			}
 116.328 +			else if (addr == s->value)
 116.329 +			{
 116.330 +				if (s->name)
 116.331 +					strcpy(buffer, s->name);
 116.332 +				else
 116.333 +					strcpy(buffer, "");
 116.334 +				return buffer;
 116.335 +			}
 116.336 +		}
 116.337 +	}
 116.338 +
 116.339 +	return "";
 116.340 +}
 116.341 +
 116.342 +bool elfFindLineInModule(u32 *addr, char *name, int line)
 116.343 +{
 116.344 +	CompileUnit *unit = elfCompileUnits;
 116.345 +
 116.346 +	while (unit)
 116.347 +	{
 116.348 +		if (unit->lineInfoTable)
 116.349 +		{
 116.350 +			int   i;
 116.351 +			int   count = unit->lineInfoTable->fileCount;
 116.352 +			char *found = NULL;
 116.353 +			for (i = 0; i < count; i++)
 116.354 +			{
 116.355 +				if (strcmp(name, unit->lineInfoTable->files[i]) == 0)
 116.356 +				{
 116.357 +					found = unit->lineInfoTable->files[i];
 116.358 +					break;
 116.359 +				}
 116.360 +			}
 116.361 +			// found a matching filename... try to find line now
 116.362 +			if (found)
 116.363 +			{
 116.364 +				LineInfoItem *table = unit->lineInfoTable->lines;
 116.365 +				count = unit->lineInfoTable->number;
 116.366 +				for (i = 0; i < count; i++)
 116.367 +				{
 116.368 +					if (table[i].file == found && table[i].line == line)
 116.369 +					{
 116.370 +						*addr = table[i].address;
 116.371 +						return true;
 116.372 +					}
 116.373 +				}
 116.374 +				// we can only find a single match
 116.375 +				return false;
 116.376 +			}
 116.377 +		}
 116.378 +		unit = unit->next;
 116.379 +	}
 116.380 +	return false;
 116.381 +}
 116.382 +
 116.383 +int elfFindLine(CompileUnit *unit, Function * /* func */, u32 addr, char **f)
 116.384 +{
 116.385 +	int currentLine = -1;
 116.386 +	if (unit->hasLineInfo)
 116.387 +	{
 116.388 +		int count = unit->lineInfoTable->number;
 116.389 +		LineInfoItem *table = unit->lineInfoTable->lines;
 116.390 +		int i;
 116.391 +		for (i = 0; i < count; i++)
 116.392 +		{
 116.393 +			if (addr <= table[i].address)
 116.394 +				break;
 116.395 +		}
 116.396 +		if (i == count)
 116.397 +			i--;
 116.398 +		*f = table[i].file;
 116.399 +		currentLine = table[i].line;
 116.400 +	}
 116.401 +	return currentLine;
 116.402 +}
 116.403 +
 116.404 +bool elfFindLineInUnit(u32 *addr, CompileUnit *unit, int line)
 116.405 +{
 116.406 +	if (unit->hasLineInfo)
 116.407 +	{
 116.408 +		int count = unit->lineInfoTable->number;
 116.409 +		LineInfoItem *table = unit->lineInfoTable->lines;
 116.410 +		int i;
 116.411 +		for (i = 0; i < count; i++)
 116.412 +		{
 116.413 +			if (line == table[i].line)
 116.414 +			{
 116.415 +				*addr = table[i].address;
 116.416 +				return true;
 116.417 +			}
 116.418 +		}
 116.419 +	}
 116.420 +	return false;
 116.421 +}
 116.422 +
 116.423 +bool elfGetCurrentFunction(u32 addr, Function **f, CompileUnit **u)
 116.424 +{
 116.425 +	CompileUnit *unit = elfGetCompileUnit(addr);
 116.426 +	// found unit, need to find function
 116.427 +	if (unit)
 116.428 +	{
 116.429 +		Function *func = unit->functions;
 116.430 +		while (func)
 116.431 +		{
 116.432 +			if (addr >= func->lowPC && addr < func->highPC)
 116.433 +			{
 116.434 +				*f = func;
 116.435 +				*u = unit;
 116.436 +				return true;
 116.437 +			}
 116.438 +			func = func->next;
 116.439 +		}
 116.440 +	}
 116.441 +	return false;
 116.442 +}
 116.443 +
 116.444 +bool elfGetObject(char *name, Function *f, CompileUnit *u, Object **o)
 116.445 +{
 116.446 +	if (f && u)
 116.447 +	{
 116.448 +		Object *v = f->variables;
 116.449 +
 116.450 +		while (v)
 116.451 +		{
 116.452 +			if (strcmp(name, v->name) == 0)
 116.453 +			{
 116.454 +				*o = v;
 116.455 +				return true;
 116.456 +			}
 116.457 +			v = v->next;
 116.458 +		}
 116.459 +		v = f->parameters;
 116.460 +		while (v)
 116.461 +		{
 116.462 +			if (strcmp(name, v->name) == 0)
 116.463 +			{
 116.464 +				*o = v;
 116.465 +				return true;
 116.466 +			}
 116.467 +			v = v->next;
 116.468 +		}
 116.469 +		v = u->variables;
 116.470 +		while (v)
 116.471 +		{
 116.472 +			if (strcmp(name, v->name) == 0)
 116.473 +			{
 116.474 +				*o = v;
 116.475 +				return true;
 116.476 +			}
 116.477 +			v = v->next;
 116.478 +		}
 116.479 +	}
 116.480 +
 116.481 +	CompileUnit *c = elfCompileUnits;
 116.482 +
 116.483 +	while (c)
 116.484 +	{
 116.485 +		if (c != u)
 116.486 +		{
 116.487 +			Object *v = c->variables;
 116.488 +			while (v)
 116.489 +			{
 116.490 +				if (strcmp(name, v->name) == 0)
 116.491 +				{
 116.492 +					*o = v;
 116.493 +					return true;
 116.494 +				}
 116.495 +				v = v->next;
 116.496 +			}
 116.497 +		}
 116.498 +		c = c->next;
 116.499 +	}
 116.500 +
 116.501 +	return false;
 116.502 +}
 116.503 +
 116.504 +char *elfGetSymbol(int i, u32 *value, u32 *size, int *type)
 116.505 +{
 116.506 +	if (i < elfSymbolsCount)
 116.507 +	{
 116.508 +		Symbol *s = &elfSymbols[i];
 116.509 +		*value = s->value;
 116.510 +		*size  = s->size;
 116.511 +		*type  = s->type;
 116.512 +		return s->name;
 116.513 +	}
 116.514 +	return NULL;
 116.515 +}
 116.516 +
 116.517 +bool elfGetSymbolAddress(char *sym, u32 *addr, u32 *size, int *type)
 116.518 +{
 116.519 +	if (elfSymbolsCount)
 116.520 +	{
 116.521 +		for (int i = 0; i < elfSymbolsCount; i++)
 116.522 +		{
 116.523 +			Symbol *s = &elfSymbols[i];
 116.524 +			if (strcmp(sym, s->name) == 0)
 116.525 +			{
 116.526 +				*addr = s->value;
 116.527 +				*size = s->size;
 116.528 +				*type = s->type;
 116.529 +				return true;
 116.530 +			}
 116.531 +		}
 116.532 +	}
 116.533 +	return false;
 116.534 +}
 116.535 +
 116.536 +ELFfde *elfGetFde(u32 address)
 116.537 +{
 116.538 +	if (elfFdes)
 116.539 +	{
 116.540 +		int i;
 116.541 +		for (i = 0; i < elfFdeCount; i++)
 116.542 +		{
 116.543 +			if (address >= elfFdes[i]->address &&
 116.544 +			    address < elfFdes[i]->end)
 116.545 +			{
 116.546 +				return elfFdes[i];
 116.547 +			}
 116.548 +		}
 116.549 +	}
 116.550 +
 116.551 +	return NULL;
 116.552 +}
 116.553 +
 116.554 +void elfExecuteCFAInstructions(ELFFrameState *state, u8 *data, u32 len,
 116.555 +                               u32 pc)
 116.556 +{
 116.557 +	u8 *end = data + len;
 116.558 +	int bytes;
 116.559 +	int reg;
 116.560 +	ELFFrameStateRegisters *fs;
 116.561 +
 116.562 +	while (data < end && state->pc < pc)
 116.563 +	{
 116.564 +		u8 op = *data++;
 116.565 +
 116.566 +		switch (op >> 6)
 116.567 +		{
 116.568 +		case DW_CFA_advance_loc:
 116.569 +			state->pc += (op & 0x3f) * state->codeAlign;
 116.570 +			break;
 116.571 +		case DW_CFA_offset:
 116.572 +			reg = op & 0x3f;
 116.573 +			state->registers.regs[reg].mode   = REG_OFFSET;
 116.574 +			state->registers.regs[reg].offset = state->dataAlign *
 116.575 +			                                    (s32)elfReadLEB128(data, &bytes);
 116.576 +			data += bytes;
 116.577 +			break;
 116.578 +		case DW_CFA_restore:
 116.579 +			// we don't care much about the other possible settings,
 116.580 +			// so just setting to unset is enough for now
 116.581 +			state->registers.regs[op & 0x3f].mode = REG_NOT_SET;
 116.582 +			break;
 116.583 +		case 0:
 116.584 +			switch (op & 0x3f)
 116.585 +			{
 116.586 +			case DW_CFA_nop:
 116.587 +				break;
 116.588 +			case DW_CFA_advance_loc1:
 116.589 +				state->pc += state->codeAlign * (*data++);
 116.590 +				break;
 116.591 +			case DW_CFA_advance_loc2:
 116.592 +				state->pc += state->codeAlign * elfRead2Bytes(data);
 116.593 +				data      += 2;
 116.594 +				break;
 116.595 +			case DW_CFA_advance_loc4:
 116.596 +				state->pc += state->codeAlign * elfRead4Bytes(data);
 116.597 +				data      += 4;
 116.598 +				break;
 116.599 +			case DW_CFA_offset_extended:
 116.600 +				reg   = elfReadLEB128(data, &bytes);
 116.601 +				data += bytes;
 116.602 +				state->registers.regs[reg].mode   = REG_OFFSET;
 116.603 +				state->registers.regs[reg].offset = state->dataAlign *
 116.604 +				                                    (s32)elfReadLEB128(data, &bytes);
 116.605 +				data += bytes;
 116.606 +				break;
 116.607 +			case DW_CFA_restore_extended:
 116.608 +			case DW_CFA_undefined:
 116.609 +			case DW_CFA_same_value:
 116.610 +				reg   = elfReadLEB128(data, &bytes);
 116.611 +				data += bytes;
 116.612 +				state->registers.regs[reg].mode = REG_NOT_SET;
 116.613 +				break;
 116.614 +			case DW_CFA_register:
 116.615 +				reg   = elfReadLEB128(data, &bytes);
 116.616 +				data += bytes;
 116.617 +				state->registers.regs[reg].mode = REG_REGISTER;
 116.618 +				state->registers.regs[reg].reg  = elfReadLEB128(data, &bytes);
 116.619 +				data += bytes;
 116.620 +				break;
 116.621 +			case DW_CFA_remember_state:
 116.622 +				fs = (ELFFrameStateRegisters *)calloc(1,
 116.623 +				                                      sizeof(ELFFrameStateRegisters));
 116.624 +				memcpy(fs, &state->registers, sizeof(ELFFrameStateRegisters));
 116.625 +				state->registers.previous = fs;
 116.626 +				break;
 116.627 +			case DW_CFA_restore_state:
 116.628 +				if (state->registers.previous == NULL)
 116.629 +				{
 116.630 +					printf("Error: previous frame state is NULL.\n");
 116.631 +					return;
 116.632 +				}
 116.633 +				fs = state->registers.previous;
 116.634 +				memcpy(&state->registers, fs, sizeof(ELFFrameStateRegisters));
 116.635 +				free(fs);
 116.636 +				break;
 116.637 +			case DW_CFA_def_cfa:
 116.638 +				state->cfaRegister = elfReadLEB128(data, &bytes);
 116.639 +				data += bytes;
 116.640 +				state->cfaOffset = (s32)elfReadLEB128(data, &bytes);
 116.641 +				data += bytes;
 116.642 +				state->cfaMode = CFA_REG_OFFSET;
 116.643 +				break;
 116.644 +			case DW_CFA_def_cfa_register:
 116.645 +				state->cfaRegister = elfReadLEB128(data, &bytes);
 116.646 +				data += bytes;
 116.647 +				state->cfaMode = CFA_REG_OFFSET;
 116.648 +				break;
 116.649 +			case DW_CFA_def_cfa_offset:
 116.650 +				state->cfaOffset = (s32)elfReadLEB128(data, &bytes);
 116.651 +				data += bytes;
 116.652 +				state->cfaMode = CFA_REG_OFFSET;
 116.653 +				break;
 116.654 +			default:
 116.655 +				printf("Unknown CFA opcode %08x\n", op);
 116.656 +				return;
 116.657 +			}
 116.658 +			break;
 116.659 +		default:
 116.660 +			printf("Unknown CFA opcode %08x\n", op);
 116.661 +			return;
 116.662 +		}
 116.663 +	}
 116.664 +}
 116.665 +
 116.666 +ELFFrameState *elfGetFrameState(ELFfde *fde, u32 address)
 116.667 +{
 116.668 +	ELFFrameState *state = (ELFFrameState *)calloc(1, sizeof(ELFFrameState));
 116.669 +	state->pc            = fde->address;
 116.670 +	state->dataAlign     = fde->cie->dataAlign;
 116.671 +	state->codeAlign     = fde->cie->codeAlign;
 116.672 +	state->returnAddress = fde->cie->returnAddress;
 116.673 +
 116.674 +	elfExecuteCFAInstructions(state,
 116.675 +	                          fde->cie->data,
 116.676 +	                          fde->cie->dataLen,
 116.677 +	                          0xffffffff);
 116.678 +	elfExecuteCFAInstructions(state,
 116.679 +	                          fde->data,
 116.680 +	                          fde->dataLen,
 116.681 +	                          address);
 116.682 +
 116.683 +	return state;
 116.684 +}
 116.685 +
 116.686 +void elfPrintCallChain(u32 address)
 116.687 +{
 116.688 +	int count = 1;
 116.689 +
 116.690 +	reg_pair regs[15];
 116.691 +	reg_pair newRegs[15];
 116.692 +
 116.693 +	memcpy(&regs[0], &reg[0], sizeof(reg_pair) * 15);
 116.694 +
 116.695 +	while (count < 20)
 116.696 +	{
 116.697 +		char *addr = elfGetAddressSymbol(address);
 116.698 +		if (*addr == 0)
 116.699 +			addr = "???";
 116.700 +
 116.701 +		printf("%08x %s\n", address, addr);
 116.702 +
 116.703 +		ELFfde *fde = elfGetFde(address);
 116.704 +
 116.705 +		if (fde == NULL)
 116.706 +		{
 116.707 +			break;
 116.708 +		}
 116.709 +
 116.710 +		ELFFrameState *state = elfGetFrameState(fde, address);
 116.711 +
 116.712 +		if (!state)
 116.713 +		{
 116.714 +			break;
 116.715 +		}
 116.716 +
 116.717 +		if (state->cfaMode == CFA_REG_OFFSET)
 116.718 +		{
 116.719 +			memcpy(&newRegs[0], &regs[0], sizeof(reg_pair) * 15);
 116.720 +			u32 addr = 0;
 116.721 +			for (int i = 0; i < 15; i++)
 116.722 +			{
 116.723 +				ELFFrameStateRegister *r = &state->registers.
 116.724 +				                           regs[i];
 116.725 +
 116.726 +				switch (r->mode)
 116.727 +				{
 116.728 +				case REG_NOT_SET:
 116.729 +					newRegs[i].I = regs[i].I;
 116.730 +					break;
 116.731 +				case REG_OFFSET:
 116.732 +					newRegs[i].I = elfReadMemory(regs[state->cfaRegister].I +
 116.733 +					                             state->cfaOffset +
 116.734 +					                             r->offset);
 116.735 +					break;
 116.736 +				case REG_REGISTER:
 116.737 +					newRegs[i].I = regs[r->reg].I;
 116.738 +					break;
 116.739 +				default:
 116.740 +					printf("Unknown register mode: %d\n", r->mode);
 116.741 +					break;
 116.742 +				}
 116.743 +			}
 116.744 +			memcpy(regs, newRegs, sizeof(reg_pair)*15);
 116.745 +			addr    = newRegs[14].I;
 116.746 +			addr   &= 0xfffffffe;
 116.747 +			address = addr;
 116.748 +			count++;
 116.749 +		}
 116.750 +		else
 116.751 +		{
 116.752 +			printf("CFA not set\n");
 116.753 +			break;
 116.754 +		}
 116.755 +		if (state->registers.previous)
 116.756 +		{
 116.757 +			ELFFrameStateRegisters *prev = state->registers.previous;
 116.758 +
 116.759 +			while (prev)
 116.760 +			{
 116.761 +				ELFFrameStateRegisters *p = prev->previous;
 116.762 +				free(prev);
 116.763 +				prev = p;
 116.764 +			}
 116.765 +		}
 116.766 +		free(state);
 116.767 +	}
 116.768 +}
 116.769 +
 116.770 +u32 elfDecodeLocation(Function *f, ELFBlock *o, LocationType *type, u32 base)
 116.771 +{
 116.772 +	u32 framebase = 0;
 116.773 +	if (f && f->frameBase)
 116.774 +	{
 116.775 +		ELFBlock *b = f->frameBase;
 116.776 +		switch (*b->data)
 116.777 +		{
 116.778 +		case DW_OP_reg0:
 116.779 +		case DW_OP_reg1:
 116.780 +		case DW_OP_reg2:
 116.781 +		case DW_OP_reg3:
 116.782 +		case DW_OP_reg4:
 116.783 +		case DW_OP_reg5:
 116.784 +		case DW_OP_reg6:
 116.785 +		case DW_OP_reg7:
 116.786 +		case DW_OP_reg8:
 116.787 +		case DW_OP_reg9:
 116.788 +		case DW_OP_reg10:
 116.789 +		case DW_OP_reg11:
 116.790 +		case DW_OP_reg12:
 116.791 +		case DW_OP_reg13:
 116.792 +		case DW_OP_reg14:
 116.793 +		case DW_OP_reg15:
 116.794 +			framebase = reg[*b->data-0x50].I;
 116.795 +			break;
 116.796 +		default:
 116.797 +			fprintf(stderr, "Unknown frameBase %02x\n", *b->data);
 116.798 +			break;
 116.799 +		}
 116.800 +	}
 116.801 +
 116.802 +	ELFBlock *loc      = o;
 116.803 +	u32       location = 0;
 116.804 +	int       bytes    = 0;
 116.805 +	if (loc)
 116.806 +	{
 116.807 +		switch (*loc->data)
 116.808 +		{
 116.809 +		case DW_OP_addr:
 116.810 +			location = elfRead4Bytes(loc->data+1);
 116.811 +			*type    = LOCATION_memory;
 116.812 +			break;
 116.813 +		case DW_OP_plus_uconst:
 116.814 +			location = base + elfReadLEB128(loc->data+1, &bytes);
 116.815 +			*type    = LOCATION_memory;
 116.816 +			break;
 116.817 +		case DW_OP_reg0:
 116.818 +		case DW_OP_reg1:
 116.819 +		case DW_OP_reg2:
 116.820 +		case DW_OP_reg3:
 116.821 +		case DW_OP_reg4:
 116.822 +		case DW_OP_reg5:
 116.823 +		case DW_OP_reg6:
 116.824 +		case DW_OP_reg7:
 116.825 +		case DW_OP_reg8:
 116.826 +		case DW_OP_reg9:
 116.827 +		case DW_OP_reg10:
 116.828 +		case DW_OP_reg11:
 116.829 +		case DW_OP_reg12:
 116.830 +		case DW_OP_reg13:
 116.831 +		case DW_OP_reg14:
 116.832 +		case DW_OP_reg15:
 116.833 +			location = *loc->data - 0x50;
 116.834 +			*type    = LOCATION_register;
 116.835 +			break;
 116.836 +		case DW_OP_fbreg:
 116.837 +		{
 116.838 +			int bytes;
 116.839 +			s32 off = elfReadSignedLEB128(loc->data+1, &bytes);
 116.840 +			location = framebase + off;
 116.841 +			*type    = LOCATION_memory;
 116.842 +			break;
 116.843 +		}
 116.844 +		default:
 116.845 +			fprintf(stderr, "Unknown location %02x\n", *loc->data);
 116.846 +			break;
 116.847 +		}
 116.848 +	}
 116.849 +	return location;
 116.850 +}
 116.851 +
 116.852 +u32 elfDecodeLocation(Function *f, ELFBlock *o, LocationType *type)
 116.853 +{
 116.854 +	return elfDecodeLocation(f, o, type, 0);
 116.855 +}
 116.856 +
 116.857 +// reading function
 116.858 +
 116.859 +u32 elfRead4Bytes(u8 *data)
 116.860 +{
 116.861 +	u32 value = *data++;
 116.862 +	value |= (*data++ << 8);
 116.863 +	value |= (*data++ << 16);
 116.864 +	value |= (*data << 24);
 116.865 +	return value;
 116.866 +}
 116.867 +
 116.868 +u16 elfRead2Bytes(u8 *data)
 116.869 +{
 116.870 +	u16 value = *data++;
 116.871 +	value |= (*data << 8);
 116.872 +	return value;
 116.873 +}
 116.874 +
 116.875 +char *elfReadString(u8 *data, int *bytesRead)
 116.876 +{
 116.877 +	if (*data == 0)
 116.878 +	{
 116.879 +		*bytesRead = 1;
 116.880 +		return NULL;
 116.881 +	}
 116.882 +	*bytesRead = strlen((char *)data) + 1;
 116.883 +	return (char *)data;
 116.884 +}
 116.885 +
 116.886 +s32 elfReadSignedLEB128(u8 *data, int *bytesRead)
 116.887 +{
 116.888 +	s32 result = 0;
 116.889 +	int shift  = 0;
 116.890 +	int count  = 0;
 116.891 +
 116.892 +	u8 byte;
 116.893 +	do
 116.894 +	{
 116.895 +		byte = *data++;
 116.896 +		count++;
 116.897 +		result |= (byte & 0x7f) << shift;
 116.898 +		shift  += 7;
 116.899 +	}
 116.900 +	while (byte & 0x80);
 116.901 +	if ((shift < 32) && (byte & 0x40))
 116.902 +		result |= -(1 << shift);
 116.903 +	*bytesRead = count;
 116.904 +	return result;
 116.905 +}
 116.906 +
 116.907 +u32 elfReadLEB128(u8 *data, int *bytesRead)
 116.908 +{
 116.909 +	u32 result = 0;
 116.910 +	int shift  = 0;
 116.911 +	int count  = 0;
 116.912 +	u8  byte;
 116.913 +	do
 116.914 +	{
 116.915 +		byte = *data++;
 116.916 +		count++;
 116.917 +		result |= (byte & 0x7f) << shift;
 116.918 +		shift  += 7;
 116.919 +	}
 116.920 +	while (byte & 0x80);
 116.921 +	*bytesRead = count;
 116.922 +	return result;
 116.923 +}
 116.924 +
 116.925 +u8 *elfReadSection(u8 *data, ELFSectionHeader *sh)
 116.926 +{
 116.927 +	return data + READ32LE(&sh->offset);
 116.928 +}
 116.929 +
 116.930 +ELFSectionHeader *elfGetSectionByName(char *name)
 116.931 +{
 116.932 +	for (int i = 0; i < elfSectionHeadersCount; i++)
 116.933 +	{
 116.934 +		if (strcmp(name,
 116.935 +		           &elfSectionHeadersStringTable[READ32LE(&elfSectionHeaders[i]->
 116.936 +		                                                  name)]) == 0)
 116.937 +		{
 116.938 +			return elfSectionHeaders[i];
 116.939 +		}
 116.940 +	}
 116.941 +	return NULL;
 116.942 +}
 116.943 +
 116.944 +ELFSectionHeader *elfGetSectionByNumber(int number)
 116.945 +{
 116.946 +	if (number < elfSectionHeadersCount)
 116.947 +	{
 116.948 +		return elfSectionHeaders[number];
 116.949 +	}
 116.950 +	return NULL;
 116.951 +}
 116.952 +
 116.953 +CompileUnit *elfGetCompileUnitForData(u8 *data)
 116.954 +{
 116.955 +	u8 *end = elfCurrentUnit->top + 4 + elfCurrentUnit->length;
 116.956 +
 116.957 +	if (data >= elfCurrentUnit->top && data < end)
 116.958 +		return elfCurrentUnit;
 116.959 +
 116.960 +	CompileUnit *unit = elfCompileUnits;
 116.961 +
 116.962 +	while (unit)
 116.963 +	{
 116.964 +		end = unit->top + 4 + unit->length;
 116.965 +
 116.966 +		if (data >= unit->top && data < end)
 116.967 +			return unit;
 116.968 +
 116.969 +		unit = unit->next;
 116.970 +	}
 116.971 +
 116.972 +	printf("Error: cannot find reference to compile unit at offset %08x\n",
 116.973 +	       (int)(data - elfDebugInfo->infodata));
 116.974 +	exit(-1);
 116.975 +}
 116.976 +
 116.977 +u8 *elfReadAttribute(u8 *data, ELFAttr *attr)
 116.978 +{
 116.979 +	int bytes;
 116.980 +	int form = attr->form;
 116.981 +start:
 116.982 +	switch (form)
 116.983 +	{
 116.984 +	case DW_FORM_addr:
 116.985 +		attr->value = elfRead4Bytes(data);
 116.986 +		data       += 4;
 116.987 +		break;
 116.988 +	case DW_FORM_data2:
 116.989 +		attr->value = elfRead2Bytes(data);
 116.990 +		data       += 2;
 116.991 +		break;
 116.992 +	case DW_FORM_data4:
 116.993 +		attr->value = elfRead4Bytes(data);
 116.994 +		data       += 4;
 116.995 +		break;
 116.996 +	case DW_FORM_string:
 116.997 +		attr->string = (char *)data;
 116.998 +		data        += strlen(attr->string)+1;
 116.999 +		break;
116.1000 +	case DW_FORM_strp:
116.1001 +		attr->string = elfDebugStrings + elfRead4Bytes(data);
116.1002 +		data        += 4;
116.1003 +		break;
116.1004 +	case DW_FORM_block:
116.1005 +		attr->block         = (ELFBlock *)malloc(sizeof(ELFBlock));
116.1006 +		attr->block->length = elfReadLEB128(data, &bytes);
116.1007 +		data += bytes;
116.1008 +		attr->block->data = data;
116.1009 +		data += attr->block->length;
116.1010 +		break;
116.1011 +	case DW_FORM_block1:
116.1012 +		attr->block         = (ELFBlock *)malloc(sizeof(ELFBlock));
116.1013 +		attr->block->length = *data++;
116.1014 +		attr->block->data   = data;
116.1015 +		data += attr->block->length;
116.1016 +		break;
116.1017 +	case DW_FORM_data1:
116.1018 +		attr->value = *data++;
116.1019 +		break;
116.1020 +	case DW_FORM_flag:
116.1021 +		attr->flag = (*data++) ? true : false;
116.1022 +		break;
116.1023 +	case DW_FORM_sdata:
116.1024 +		attr->value = elfReadSignedLEB128(data, &bytes);
116.1025 +		data       += bytes;
116.1026 +		break;
116.1027 +	case DW_FORM_udata:
116.1028 +		attr->value = elfReadLEB128(data, &bytes);
116.1029 +		data       += bytes;
116.1030 +		break;
116.1031 +	case DW_FORM_ref_addr:
116.1032 +		attr->value = (elfDebugInfo->infodata + elfRead4Bytes(data)) -
116.1033 +		              elfGetCompileUnitForData(data)->top;
116.1034 +		data += 4;
116.1035 +		break;
116.1036 +	case DW_FORM_ref4:
116.1037 +		attr->value = elfRead4Bytes(data);
116.1038 +		data       += 4;
116.1039 +		break;
116.1040 +	case DW_FORM_ref_udata:
116.1041 +		attr->value = (elfDebugInfo->infodata +
116.1042 +		               (elfGetCompileUnitForData(data)->top -
116.1043 +		                elfDebugInfo->infodata) +
116.1044 +		               elfReadLEB128(data, &bytes)) -
116.1045 +		              elfCurrentUnit->top;
116.1046 +		data += bytes;
116.1047 +		break;
116.1048 +	case DW_FORM_indirect:
116.1049 +		form  = elfReadLEB128(data, &bytes);
116.1050 +		data += bytes;
116.1051 +		goto start;
116.1052 +	default:
116.1053 +		fprintf(stderr, "Unsupported FORM %02x\n", form);
116.1054 +		exit(-1);
116.1055 +	}
116.1056 +	return data;
116.1057 +}
116.1058 +
116.1059 +ELFAbbrev *elfGetAbbrev(ELFAbbrev **table, u32 number)
116.1060 +{
116.1061 +	int hash = number % 121;
116.1062 +
116.1063 +	ELFAbbrev *abbrev = table[hash];
116.1064 +
116.1065 +	while (abbrev)
116.1066 +	{
116.1067 +		if (abbrev->number == number)
116.1068 +			return abbrev;
116.1069 +		abbrev = abbrev->next;
116.1070 +	}
116.1071 +	return NULL;
116.1072 +}
116.1073 +
116.1074 +ELFAbbrev * *elfReadAbbrevs(u8 *data, u32 offset)
116.1075 +{
116.1076 +	data += offset;
116.1077 +	ELFAbbrev **abbrevs = (ELFAbbrev * *)calloc(sizeof(ELFAbbrev *)*121, 1);
116.1078 +	int         bytes   = 0;
116.1079 +	u32         number  = elfReadLEB128(data, &bytes);
116.1080 +	data += bytes;
116.1081 +	while (number)
116.1082 +	{
116.1083 +		ELFAbbrev *abbrev = (ELFAbbrev *)calloc(sizeof(ELFAbbrev), 1);
116.1084 +
116.1085 +		// read tag information
116.1086 +		abbrev->number = number;
116.1087 +		abbrev->tag    = elfReadLEB128(data, &bytes);
116.1088 +		data += bytes;
116.1089 +		abbrev->hasChildren = *data++ ? true : false;
116.1090 +
116.1091 +		// read attributes
116.1092 +		int name = elfReadLEB128(data, &bytes);
116.1093 +		data += bytes;
116.1094 +		int form = elfReadLEB128(data, &bytes);
116.1095 +		data += bytes;
116.1096 +
116.1097 +		while (name)
116.1098 +		{
116.1099 +			if ((abbrev->numAttrs % 4) == 0)
116.1100 +			{
116.1101 +				abbrev->attrs = (ELFAttr *)realloc(abbrev->attrs,
116.1102 +				                                   (abbrev->numAttrs + 4) *
116.1103 +				                                   sizeof(ELFAttr));
116.1104 +			}
116.1105 +			abbrev->attrs[abbrev->numAttrs].name   = name;
116.1106 +			abbrev->attrs[abbrev->numAttrs++].form = form;
116.1107 +
116.1108 +			name  = elfReadLEB128(data, &bytes);
116.1109 +			data += bytes;
116.1110 +			form  = elfReadLEB128(data, &bytes);
116.1111 +			data += bytes;
116.1112 +		}
116.1113 +
116.1114 +		int hash = number % 121;
116.1115 +		abbrev->next  = abbrevs[hash];
116.1116 +		abbrevs[hash] = abbrev;
116.1117 +
116.1118 +		number = elfReadLEB128(data, &bytes);
116.1119 +		data  += bytes;
116.1120 +
116.1121 +		if (elfGetAbbrev(abbrevs, number) != NULL)
116.1122 +			break;
116.1123 +	}
116.1124 +
116.1125 +	return abbrevs;
116.1126 +}
116.1127 +
116.1128 +void elfParseCFA(u8 *top)
116.1129 +{
116.1130 +	ELFSectionHeader *h = elfGetSectionByName(".debug_frame");
116.1131 +
116.1132 +	if (h == NULL)
116.1133 +	{
116.1134 +		return;
116.1135 +	}
116.1136 +
116.1137 +	u8 *data = elfReadSection(top, h);
116.1138 +
116.1139 +	u8 *topOffset = data;
116.1140 +
116.1141 +	u8 *end = data + READ32LE(&h->size);
116.1142 +
116.1143 +	ELFcie *cies = NULL;
116.1144 +
116.1145 +	while (data < end)
116.1146 +	{
116.1147 +		u32 offset = data - topOffset;
116.1148 +		u32 len    = elfRead4Bytes(data);
116.1149 +		data += 4;
116.1150 +
116.1151 +		u8 *dataEnd = data + len;
116.1152 +
116.1153 +		u32 id = elfRead4Bytes(data);
116.1154 +		data += 4;
116.1155 +
116.1156 +		if (id == 0xffffffff)
116.1157 +		{
116.1158 +			// skip version
116.1159 +			*data++;
116.1160 +
116.1161 +			ELFcie *cie = (ELFcie *)calloc(1, sizeof(ELFcie));
116.1162 +
116.1163 +			cie->next = cies;
116.1164 +			cies      = cie;
116.1165 +
116.1166 +			cie->offset = offset;
116.1167 +
116.1168 +			cie->augmentation = data;
116.1169 +			while (*data)
116.1170 +				data++;
116.1171 +			data++;
116.1172 +
116.1173 +			if (*cie->augmentation)
116.1174 +			{
116.1175 +				fprintf(stderr, "Error: augmentation not supported\n");
116.1176 +				exit(-1);
116.1177 +			}
116.1178 +
116.1179 +			int bytes;
116.1180 +			cie->codeAlign = elfReadLEB128(data, &bytes);
116.1181 +			data += bytes;
116.1182 +
116.1183 +			cie->dataAlign = elfReadSignedLEB128(data, &bytes);
116.1184 +			data += bytes;
116.1185 +
116.1186 +			cie->returnAddress = *data++;
116.1187 +
116.1188 +			cie->data    = data;
116.1189 +			cie->dataLen = dataEnd - data;
116.1190 +		}
116.1191 +		else
116.1192 +		{
116.1193 +			ELFfde *fde = (ELFfde *)calloc(1, sizeof(ELFfde));
116.1194 +
116.1195 +			ELFcie *cie = cies;
116.1196 +
116.1197 +			while (cie != NULL)
116.1198 +			{
116.1199 +				if (cie->offset == id)
116.1200 +					break;
116.1201 +				cie = cie->next;
116.1202 +			}
116.1203 +
116.1204 +			if (!cie)
116.1205 +			{
116.1206 +				fprintf(stderr, "Cannot find CIE %08x\n", id);
116.1207 +				exit(-1);
116.1208 +			}
116.1209 +
116.1210 +			fde->cie = cie;
116.1211 +
116.1212 +			fde->address = elfRead4Bytes(data);
116.1213 +			data        += 4;
116.1214 +
116.1215 +			fde->end = fde->address + elfRead4Bytes(data);
116.1216 +			data    += 4;
116.1217 +
116.1218 +			fde->data    = data;
116.1219 +			fde->dataLen = dataEnd - data;
116.1220 +
116.1221 +			if ((elfFdeCount %10) == 0)
116.1222 +			{
116.1223 +				elfFdes = (ELFfde * *)realloc(elfFdes, (elfFdeCount+10) *
116.1224 +				                              sizeof(ELFfde *));
116.1225 +			}
116.1226 +			elfFdes[elfFdeCount++] = fde;
116.1227 +		}
116.1228 +		data = dataEnd;
116.1229 +	}
116.1230 +
116.1231 +	elfCies = cies;
116.1232 +}
116.1233 +
116.1234 +void elfAddLine(LineInfo *l, u32 a, int file, int line, int *max)
116.1235 +{
116.1236 +	if (l->number == *max)
116.1237 +	{
116.1238 +		*max    += 1000;
116.1239 +		l->lines = (LineInfoItem *)realloc(l->lines, *max*sizeof(LineInfoItem));
116.1240 +	}
116.1241 +	LineInfoItem *li = &l->lines[l->number];
116.1242 +	li->file    = l->files[file-1];
116.1243 +	li->address = a;
116.1244 +	li->line    = line;
116.1245 +	l->number++;
116.1246 +}
116.1247 +
116.1248 +void elfParseLineInfo(CompileUnit *unit, u8 *top)
116.1249 +{
116.1250 +	ELFSectionHeader *h = elfGetSectionByName(".debug_line");
116.1251 +	if (h == NULL)
116.1252 +	{
116.1253 +		fprintf(stderr, "No line information found\n");
116.1254 +		return;
116.1255 +	}
116.1256 +	LineInfo *l = unit->lineInfoTable = (LineInfo *)calloc(1, sizeof(LineInfo));
116.1257 +	l->number = 0;
116.1258 +	int max = 1000;
116.1259 +	l->lines = (LineInfoItem *)malloc(1000*sizeof(LineInfoItem));
116.1260 +
116.1261 +	u8 *data = elfReadSection(top, h);
116.1262 +	data += unit->lineInfo;
116.1263 +	u32 totalLen = elfRead4Bytes(data);
116.1264 +	data += 4;
116.1265 +	u8 *end = data + totalLen;
116.1266 +	//  u16 version = elfRead2Bytes(data);
116.1267 +	data += 2;
116.1268 +	//  u32 offset = elfRead4Bytes(data);
116.1269 +	data += 4;
116.1270 +	int minInstrSize  = *data++;
116.1271 +	int defaultIsStmt = *data++;
116.1272 +	int lineBase      = (s8)*data++;
116.1273 +	int lineRange     = *data++;
116.1274 +	int opcodeBase    = *data++;
116.1275 +	u8 *stdOpLen      = (u8 *)malloc(opcodeBase * sizeof(u8));
116.1276 +	stdOpLen[0] = 1;
116.1277 +	int i;
116.1278 +	for (i = 1; i < opcodeBase; i++)
116.1279 +		stdOpLen[i] = *data++;
116.1280 +
116.1281 +	free(stdOpLen); // todo
116.1282 +	int bytes = 0;
116.1283 +
116.1284 +	char *s;
116.1285 +	while ((s = elfReadString(data, &bytes)) != NULL)
116.1286 +	{
116.1287 +		data += bytes;
116.1288 +		//    fprintf(stderr, "Directory is %s\n", s);
116.1289 +	}
116.1290 +	data += bytes;
116.1291 +	int count = 4;
116.1292 +	int index = 0;
116.1293 +	l->files = (char * *)malloc(sizeof(char *)*count);
116.1294 +
116.1295 +	while ((s = elfReadString(data, &bytes)) != NULL)
116.1296 +	{
116.1297 +		l->files[index++] = s;
116.1298 +
116.1299 +		data += bytes;
116.1300 +		// directory
116.1301 +		elfReadLEB128(data, &bytes);
116.1302 +		data += bytes;
116.1303 +		// time
116.1304 +		elfReadLEB128(data, &bytes);
116.1305 +		data += bytes;
116.1306 +		// size
116.1307 +		elfReadLEB128(data, &bytes);
116.1308 +		data += bytes;
116.1309 +		//    fprintf(stderr, "File is %s\n", s);
116.1310 +		if (index == count)
116.1311 +		{
116.1312 +			count   += 4;
116.1313 +			l->files = (char * *)realloc(l->files, sizeof(char *)*count);
116.1314 +		}
116.1315 +	}
116.1316 +	l->fileCount = index;
116.1317 +	data        += bytes;
116.1318 +
116.1319 +	while (data < end)
116.1320 +	{
116.1321 +		u32 address    = 0;
116.1322 +		int file       = 1;
116.1323 +		int line       = 1;
116.1324 +		int col        = 0;
116.1325 +		int isStmt     = defaultIsStmt;
116.1326 +		int basicBlock = 0;
116.1327 +		int endSeq     = 0;
116.1328 +
116.1329 +		while (!endSeq)
116.1330 +		{
116.1331 +			int op = *data++;
116.1332 +			switch (op)
116.1333 +			{
116.1334 +			case DW_LNS_extended_op:
116.1335 +			{
116.1336 +				data++;
116.1337 +				op = *data++;
116.1338 +				switch (op)
116.1339 +				{
116.1340 +				case DW_LNE_end_sequence:
116.1341 +					endSeq = 1;
116.1342 +					break;
116.1343 +				case DW_LNE_set_address:
116.1344 +					address = elfRead4Bytes(data);
116.1345 +					data   += 4;
116.1346 +					break;
116.1347 +				default:
116.1348 +					fprintf(stderr, "Unknown extended LINE opcode %02x\n", op);
116.1349 +					exit(-1);
116.1350 +				}
116.1351 +				break;
116.1352 +			}
116.1353 +			case DW_LNS_copy:
116.1354 +				//      fprintf(stderr, "Address %08x line %d (%d)\n", address, line, file);
116.1355 +				elfAddLine(l, address, file, line, &max);
116.1356 +				basicBlock = 0;
116.1357 +				break;
116.1358 +			case DW_LNS_advance_pc:
116.1359 +				address += minInstrSize * elfReadLEB128(data, &bytes);
116.1360 +				data    += bytes;
116.1361 +				break;
116.1362 +			case DW_LNS_advance_line:
116.1363 +				line += elfReadSignedLEB128(data, &bytes);
116.1364 +				data += bytes;
116.1365 +				break;
116.1366 +			case DW_LNS_set_file:
116.1367 +				file  = elfReadLEB128(data, &bytes);
116.1368 +				data += bytes;
116.1369 +				break;
116.1370 +			case DW_LNS_set_column:
116.1371 +				col   = elfReadLEB128(data, &bytes);
116.1372 +				data += bytes;
116.1373 +				break;
116.1374 +			case DW_LNS_negate_stmt:
116.1375 +				isStmt = !isStmt;
116.1376 +				break;
116.1377 +			case DW_LNS_set_basic_block:
116.1378 +				basicBlock = 1;
116.1379 +				break;
116.1380 +			case DW_LNS_const_add_pc:
116.1381 +				address += (minInstrSize *((255 - opcodeBase)/lineRange));
116.1382 +				break;
116.1383 +			case DW_LNS_fixed_advance_pc:
116.1384 +				address += elfRead2Bytes(data);
116.1385 +				data    += 2;
116.1386 +				break;
116.1387 +			default:
116.1388 +				op       = op - opcodeBase;
116.1389 +				address += (op / lineRange) * minInstrSize;
116.1390 +				line    += lineBase + (op % lineRange);
116.1391 +				elfAddLine(l, address, file, line, &max);
116.1392 +				//        fprintf(stderr, "Address %08x line %d (%d)\n", address, line,file);
116.1393 +				basicBlock = 1;
116.1394 +				break;
116.1395 +			}
116.1396 +		}
116.1397 +	}
116.1398 +	l->lines = (LineInfoItem *)realloc(l->lines, l->number*sizeof(LineInfoItem));
116.1399 +}
116.1400 +
116.1401 +u8 *elfSkipData(u8 *data, ELFAbbrev *abbrev, ELFAbbrev **abbrevs)
116.1402 +{
116.1403 +	int i;
116.1404 +	int bytes;
116.1405 +
116.1406 +	for (i = 0; i < abbrev->numAttrs; i++)
116.1407 +	{
116.1408 +		data = elfReadAttribute(data,  &abbrev->attrs[i]);
116.1409 +		if (abbrev->attrs[i].form == DW_FORM_block1)
116.1410 +			free(abbrev->attrs[i].block);
116.1411 +	}
116.1412 +
116.1413 +	if (abbrev->hasChildren)
116.1414 +	{
116.1415 +		int nesting = 1;
116.1416 +		while (nesting)
116.1417 +		{
116.1418 +			u32 abbrevNum = elfReadLEB128(data, &bytes);
116.1419 +			data += bytes;
116.1420 +
116.1421 +			if (!abbrevNum)
116.1422 +			{
116.1423 +				nesting--;
116.1424 +				continue;
116.1425 +			}
116.1426 +
116.1427 +			abbrev = elfGetAbbrev(abbrevs, abbrevNum);
116.1428 +
116.1429 +			for (i = 0; i < abbrev->numAttrs; i++)
116.1430 +			{
116.1431 +				data = elfReadAttribute(data,  &abbrev->attrs[i]);
116.1432 +				if (abbrev->attrs[i].form == DW_FORM_block1)
116.1433 +					free(abbrev->attrs[i].block);
116.1434 +			}
116.1435 +
116.1436 +			if (abbrev->hasChildren)
116.1437 +			{
116.1438 +				nesting++;
116.1439 +			}
116.1440 +		}
116.1441 +	}
116.1442 +	return data;
116.1443 +}
116.1444 +
116.1445 +Type *elfParseType(CompileUnit *unit, u32);
116.1446 +u8 *elfParseObject(u8 *data, ELFAbbrev *abbrev, CompileUnit *unit,
116.1447 +                   Object **object);
116.1448 +u8 *elfParseFunction(u8 *data, ELFAbbrev *abbrev, CompileUnit *unit,
116.1449 +                     Function **function);
116.1450 +void elfCleanUp(Function *);
116.1451 +
116.1452 +void elfAddType(Type *type, CompileUnit *unit, u32 offset)
116.1453 +{
116.1454 +	if (type->next == NULL)
116.1455 +	{
116.1456 +		if (unit->types != type && type->offset == 0)
116.1457 +		{
116.1458 +			type->offset = offset;
116.1459 +			type->next   = unit->types;
116.1460 +			unit->types  = type;
116.1461 +		}
116.1462 +	}
116.1463 +}
116.1464 +
116.1465 +void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
116.1466 +                  Type **type)
116.1467 +{
116.1468 +	switch (abbrev->tag)
116.1469 +	{
116.1470 +	case DW_TAG_typedef:
116.1471 +	{
116.1472 +		u32   typeref = 0;
116.1473 +		char *name    = NULL;
116.1474 +		for (int i = 0; i < abbrev->numAttrs; i++)
116.1475 +		{
116.1476 +			ELFAttr *attr = &abbrev->attrs[i];
116.1477 +			data = elfReadAttribute(data, attr);
116.1478 +			switch (attr->name)
116.1479 +			{
116.1480 +			case DW_AT_name:
116.1481 +				name = attr->string;
116.1482 +				break;
116.1483 +			case DW_AT_type:
116.1484 +				typeref = attr->value;
116.1485 +				break;
116.1486 +			case DW_AT_decl_file:
116.1487 +			case DW_AT_decl_line:
116.1488 +				break;
116.1489 +			default:
116.1490 +				fprintf(stderr, "Unknown attribute for typedef %02x\n", attr->name);
116.1491 +				break;
116.1492 +			}
116.1493 +		}
116.1494 +		if (abbrev->hasChildren)
116.1495 +			fprintf(stderr, "Unexpected children for typedef\n");
116.1496 +		*type = elfParseType(unit, typeref);
116.1497 +		if (name)
116.1498 +			(*type)->name = name;
116.1499 +		return;
116.1500 +		break;
116.1501 +	}
116.1502 +	case DW_TAG_union_type:
116.1503 +	case DW_TAG_structure_type:
116.1504 +	{
116.1505 +		Type *t = (Type *)calloc(sizeof(Type), 1);
116.1506 +		if (abbrev->tag == DW_TAG_structure_type)
116.1507 +			t->type = TYPE_struct;
116.1508 +		else
116.1509 +			t->type = TYPE_union;
116.1510 +
116.1511 +		Struct *s = (Struct *)calloc(sizeof(Struct), 1);
116.1512 +		t->structure = s;
116.1513 +		elfAddType(t, unit, offset);
116.1514 +
116.1515 +		for (int i = 0; i < abbrev->numAttrs; i++)
116.1516 +		{
116.1517 +			ELFAttr *attr = &abbrev->attrs[i];
116.1518 +			data = elfReadAttribute(data, attr);
116.1519 +			switch (attr->name)
116.1520 +			{
116.1521 +			case DW_AT_name:
116.1522 +				t->name = attr->string;
116.1523 +				break;
116.1524 +			case DW_AT_byte_size:
116.1525 +				t->size = attr->value;
116.1526 +				break;
116.1527 +			case DW_AT_decl_file:
116.1528 +			case DW_AT_decl_line:
116.1529 +			case DW_AT_sibling:
116.1530 +			case DW_AT_containing_type: // todo?
116.1531 +			case DW_AT_declaration:
116.1532 +			case DW_AT_specification: // TODO:
116.1533 +				break;
116.1534 +			default:
116.1535 +				fprintf(stderr, "Unknown attribute for struct %02x\n", attr->name);
116.1536 +				break;
116.1537 +			}
116.1538 +		}
116.1539 +		if (abbrev->hasChildren)
116.1540 +		{
116.1541 +			int bytes;
116.1542 +			u32 num = elfReadLEB128(data, &bytes);
116.1543 +			data += bytes;
116.1544 +			int index = 0;
116.1545 +			while (num)
116.1546 +			{
116.1547 +				ELFAbbrev *abbr = elfGetAbbrev(unit->abbrevs, num);
116.1548 +
116.1549 +				switch (abbr->tag)
116.1550 +				{
116.1551 +				case DW_TAG_member:
116.1552 +				{
116.1553 +					if ((index % 4) == 0)
116.1554 +						s->members = (Member *)realloc(s->members,
116.1555 +						                               sizeof(Member)*(index+4));
116.1556 +					Member *m = &s->members[index];
116.1557 +					m->location  = NULL;
116.1558 +					m->bitOffset = 0;
116.1559 +					m->bitSize   = 0;
116.1560 +					m->byteSize  = 0;
116.1561 +					for (int i = 0; i < abbr->numAttrs; i++)
116.1562 +					{
116.1563 +						ELFAttr *attr = &abbr->attrs[i];
116.1564 +						data = elfReadAttribute(data, attr);
116.1565 +						switch (attr->name)
116.1566 +						{
116.1567 +						case DW_AT_name:
116.1568 +							m->name = attr->string;
116.1569 +							break;
116.1570 +						case DW_AT_type:
116.1571 +							m->type = elfParseType(unit, attr->value);
116.1572 +							break;
116.1573 +						case DW_AT_data_member_location:
116.1574 +							m->location = attr->block;
116.1575 +							break;
116.1576 +						case DW_AT_byte_size:
116.1577 +							m->byteSize = attr->value;
116.1578 +							break;
116.1579 +						case DW_AT_bit_offset:
116.1580 +							m->bitOffset = attr->value;
116.1581 +							break;
116.1582 +						case DW_AT_bit_size:
116.1583 +							m->bitSize = attr->value;
116.1584 +							break;
116.1585 +						case DW_AT_decl_file:
116.1586 +						case DW_AT_decl_line:
116.1587 +						case DW_AT_accessibility:
116.1588 +						case DW_AT_artificial: // todo?
116.1589 +							break;
116.1590 +						default:
116.1591 +							fprintf(stderr, "Unknown member attribute %02x\n",
116.1592 +							        attr->name);
116.1593 +						}
116.1594 +					}
116.1595 +					index++;
116.1596 +					break;
116.1597 +				}
116.1598 +				case DW_TAG_subprogram:
116.1599 +				{
116.1600 +					Function *fnc = NULL;
116.1601 +					data = elfParseFunction(data, abbr, unit, &fnc);
116.1602 +					if (fnc != NULL)
116.1603 +					{
116.1604 +						if (unit->lastFunction)
116.1605 +							unit->lastFunction->next = fnc;
116.1606 +						else
116.1607 +							unit->functions = fnc;
116.1608 +						unit->lastFunction = fnc;
116.1609 +					}
116.1610 +					break;
116.1611 +				}
116.1612 +				case DW_TAG_inheritance:
116.1613 +					// TODO: add support
116.1614 +					data = elfSkipData(data, abbr, unit->abbrevs);
116.1615 +					break;
116.1616 +CASE_TYPE_TAG:
116.1617 +					// skip types... parsed only when used
116.1618 +					data = elfSkipData(data, abbr, unit->abbrevs);
116.1619 +					break;
116.1620 +				case DW_TAG_variable:
116.1621 +					data = elfSkipData(data, abbr, unit->abbrevs);
116.1622 +					break;
116.1623 +				default:
116.1624 +					fprintf(stderr, "Unknown struct tag %02x %s\n", abbr->tag, t->name);
116.1625 +					data = elfSkipData(data, abbr, unit->abbrevs);
116.1626 +					break;
116.1627 +				}
116.1628 +				num   = elfReadLEB128(data, &bytes);
116.1629 +				data += bytes;
116.1630 +			}
116.1631 +			s->memberCount = index;
116.1632 +		}
116.1633 +		*type = t;
116.1634 +		return;
116.1635 +		break;
116.1636 +	}
116.1637 +	case DW_TAG_base_type:
116.1638 +	{
116.1639 +		Type *t = (Type *)calloc(sizeof(Type), 1);
116.1640 +
116.1641 +		t->type = TYPE_base;
116.1642 +		elfAddType(t, unit, offset);
116.1643 +		for (int i = 0; i < abbrev->numAttrs; i++)
116.1644 +		{
116.1645 +			ELFAttr *attr = &abbrev->attrs[i];
116.1646 +			data = elfReadAttribute(data, attr);
116.1647 +			switch (attr->name)
116.1648 +			{
116.1649 +			case DW_AT_name:
116.1650 +				t->name = attr->string;
116.1651 +				break;
116.1652 +			case DW_AT_encoding:
116.1653 +				t->encoding = attr->value;
116.1654 +				break;
116.1655 +			case DW_AT_byte_size:
116.1656 +				t->size = attr->value;
116.1657 +				break;
116.1658 +			case DW_AT_bit_size:
116.1659 +				t->bitSize = attr->value;
116.1660 +				break;
116.1661 +			default:
116.1662 +				fprintf(stderr, "Unknown attribute for base type %02x\n",
116.1663 +				        attr->name);
116.1664 +				break;
116.1665 +			}
116.1666 +		}
116.1667 +		if (abbrev->hasChildren)
116.1668 +			fprintf(stderr, "Unexpected children for base type\n");
116.1669 +		*type = t;
116.1670 +		return;
116.1671 +		break;
116.1672 +	}
116.1673 +	case DW_TAG_pointer_type:
116.1674 +	{
116.1675 +		Type *t = (Type *)calloc(sizeof(Type), 1);
116.1676 +
116.1677 +		t->type = TYPE_pointer;
116.1678 +
116.1679 +		elfAddType(t, unit, offset);
116.1680 +
116.1681 +		for (int i = 0; i < abbrev->numAttrs; i++)
116.1682 +		{
116.1683 +			ELFAttr *attr = &abbrev->attrs[i];
116.1684 +			data = elfReadAttribute(data, attr);
116.1685 +			switch (attr->name)
116.1686 +			{
116.1687 +			case DW_AT_type:
116.1688 +				t->pointer = elfParseType(unit, attr->value);
116.1689 +				break;
116.1690 +			case DW_AT_byte_size:
116.1691 +				t->size = attr->value;
116.1692 +				break;
116.1693 +			default:
116.1694 +				fprintf(stderr, "Unknown pointer type attribute %02x\n", attr->name);
116.1695 +				break;
116.1696 +			}
116.1697 +		}
116.1698 +		if (abbrev->hasChildren)
116.1699 +			fprintf(stderr, "Unexpected children for pointer type\n");
116.1700 +		*type = t;
116.1701 +		return;
116.1702 +		break;
116.1703 +	}
116.1704 +	case DW_TAG_reference_type:
116.1705 +	{
116.1706 +		Type *t = (Type *)calloc(sizeof(Type), 1);
116.1707 +
116.1708 +		t->type = TYPE_reference;
116.1709 +
116.1710 +		elfAddType(t, unit, offset);
116.1711 +
116.1712 +		for (int i = 0; i < abbrev->numAttrs; i++)
116.1713 +		{
116.1714 +			ELFAttr *attr = &abbrev->attrs[i];
116.1715 +			data = elfReadAttribute(data, attr);
116.1716 +			switch (attr->name)
116.1717 +			{
116.1718 +			case DW_AT_type:
116.1719 +				t->pointer = elfParseType(unit, attr->value);
116.1720 +				break;
116.1721 +			case DW_AT_byte_size:
116.1722 +				t->size = attr->value;
116.1723 +				break;
116.1724 +			default:
116.1725 +				fprintf(stderr, "Unknown ref type attribute %02x\n", attr->name);
116.1726 +				break;
116.1727 +			}
116.1728 +		}
116.1729 +		if (abbrev->hasChildren)
116.1730 +			fprintf(stderr, "Unexpected children for ref type\n");
116.1731 +		*type = t;
116.1732 +		return;
116.1733 +		break;
116.1734 +	}
116.1735 +	case DW_TAG_volatile_type:
116.1736 +	{
116.1737 +		u32 typeref = 0;
116.1738 +
116.1739 +		for (int i = 0; i < abbrev->numAttrs; i++)
116.1740 +		{
116.1741 +			ELFAttr *attr = &abbrev->attrs[i];
116.1742 +			data = elfReadAttribute(data, attr);
116.1743 +			switch (attr->name)
116.1744 +			{
116.1745 +			case DW_AT_type:
116.1746 +				typeref = attr->value;
116.1747 +				break;
116.1748 +			default:
116.1749 +				fprintf(stderr, "Unknown volatile attribute for type %02x\n",
116.1750 +				        attr->name);
116.1751 +				break;
116.1752 +			}
116.1753 +		}
116.1754 +		if (abbrev->hasChildren)
116.1755 +			fprintf(stderr, "Unexpected children for volatile type\n");
116.1756 +		*type = elfParseType(unit, typeref);
116.1757 +		return;
116.1758 +		break;
116.1759 +	}
116.1760 +	case DW_TAG_const_type:
116.1761 +	{
116.1762 +		u32 typeref = 0;
116.1763 +
116.1764 +		for (int i = 0; i < abbrev->numAttrs; i++)
116.1765 +		{
116.1766 +			ELFAttr *attr = &abbrev->attrs[i];
116.1767 +			data = elfReadAttribute(data, attr);
116.1768 +			switch (attr->name)
116.1769 +			{
116.1770 +			case DW_AT_type:
116.1771 +				typeref = attr->value;
116.1772 +				break;
116.1773 +			default:
116.1774 +				fprintf(stderr, "Unknown const attribute for type %02x\n",
116.1775 +				        attr->name);
116.1776 +				break;
116.1777 +			}
116.1778 +		}
116.1779 +		if (abbrev->hasChildren)
116.1780 +			fprintf(stderr, "Unexpected children for const type\n");
116.1781 +		*type = elfParseType(unit, typeref);
116.1782 +		return;
116.1783 +		break;
116.1784 +	}
116.1785 +	case DW_TAG_enumeration_type:
116.1786 +	{
116.1787 +		Type *t = (Type *)calloc(sizeof(Type), 1);
116.1788 +		t->type = TYPE_enum;
116.1789 +		Enum *e = (Enum *)calloc(sizeof(Enum), 1);
116.1790 +		t->enumeration = e;
116.1791 +		elfAddType(t, unit, offset);
116.1792 +		int count = 0;
116.1793 +		for (int i = 0; i < abbrev->numAttrs; i++)
116.1794 +		{
116.1795 +			ELFAttr *attr = &abbrev->attrs[i];
116.1796 +			data = elfReadAttribute(data, attr);
116.1797 +			switch (attr->name)
116.1798 +			{
116.1799 +			case DW_AT_name:
116.1800 +				t->name = attr->string;
116.1801 +				break;
116.1802 +			case DW_AT_byte_size:
116.1803 +				t->size = attr->value;
116.1804 +				break;
116.1805 +			case DW_AT_sibling:
116.1806 +			case DW_AT_decl_file:
116.1807 +			case DW_AT_decl_line:
116.1808 +				break;
116.1809 +			default:
116.1810 +				fprintf(stderr, "Unknown enum attribute %02x\n", attr->name);
116.1811 +			}
116.1812 +		}
116.1813 +		if (abbrev->hasChildren)
116.1814 +		{
116.1815 +			int bytes;
116.1816 +			u32 num = elfReadLEB128(data, &bytes);
116.1817 +			data += bytes;
116.1818 +			while (num)
116.1819 +			{
116.1820 +				ELFAbbrev *abbr = elfGetAbbrev(unit->abbrevs, num);
116.1821 +
116.1822 +				switch (abbr->tag)
116.1823 +				{
116.1824 +				case DW_TAG_enumerator:
116.1825 +				{
116.1826 +					count++;
116.1827 +					e->members = (EnumMember *)realloc(e->members,
116.1828 +					                                   count*sizeof(EnumMember));
116.1829 +					EnumMember *m = &e->members[count-1];
116.1830 +					for (int i = 0; i < abbr->numAttrs; i++)
116.1831 +					{
116.1832 +						ELFAttr *attr = &abbr->attrs[i];
116.1833 +						data = elfReadAttribute(data, attr);
116.1834 +						switch (attr->name)
116.1835 +						{
116.1836 +						case DW_AT_name:
116.1837 +							m->name = attr->string;
116.1838 +							break;
116.1839 +						case DW_AT_const_value:
116.1840 +							m->value = attr->value;
116.1841 +							break;
116.1842 +						default:
116.1843 +							fprintf(stderr, "Unknown sub param attribute %02x\n",
116.1844 +							        attr->name);
116.1845 +						}
116.1846 +					}
116.1847 +					break;
116.1848 +				}
116.1849 +				default:
116.1850 +					fprintf(stderr, "Unknown enum tag %02x\n", abbr->tag);
116.1851 +					data = elfSkipData(data, abbr, unit->abbrevs);
116.1852 +					break;
116.1853 +				}
116.1854 +				num   = elfReadLEB128(data, &bytes);
116.1855 +				data += bytes;
116.1856 +			}
116.1857 +		}
116.1858 +		e->count = count;
116.1859 +		*type    = t;
116.1860 +		return;
116.1861 +		break;
116.1862 +	}
116.1863 +	case DW_TAG_subroutine_type:
116.1864 +	{
116.1865 +		Type *t = (Type *)calloc(sizeof(Type), 1);
116.1866 +		t->type = TYPE_function;
116.1867 +		FunctionType *f = (FunctionType *)calloc(sizeof(FunctionType), 1);
116.1868 +		t->function = f;
116.1869 +		elfAddType(t, unit, offset);
116.1870 +		for (int i = 0; i < abbrev->numAttrs; i++)
116.1871 +		{
116.1872 +			ELFAttr *attr = &abbrev->attrs[i];
116.1873 +			data = elfReadAttribute(data, attr);
116.1874 +			switch (attr->name)
116.1875 +			{
116.1876 +			case DW_AT_prototyped:
116.1877 +			case DW_AT_sibling:
116.1878 +				break;
116.1879 +			case DW_AT_type:
116.1880 +				f->returnType = elfParseType(unit, attr->value);
116.1881 +				break;
116.1882 +			default:
116.1883 +				fprintf(stderr, "Unknown subroutine attribute %02x\n", attr->name);
116.1884 +			}
116.1885 +		}
116.1886 +		if (abbrev->hasChildren)
116.1887 +		{
116.1888 +			int bytes;
116.1889 +			u32 num = elfReadLEB128(data, &bytes);
116.1890 +			data += bytes;
116.1891 +			Object *lastVar = NULL;
116.1892 +			while (num)
116.1893 +			{
116.1894 +				ELFAbbrev *abbr = elfGetAbbrev(unit->abbrevs, num);
116.1895 +
116.1896 +				switch (abbr->tag)
116.1897 +				{
116.1898 +				case DW_TAG_formal_parameter:
116.1899 +				{
116.1900 +					Object *o;
116.1901 +					data = elfParseObject(data, abbr, unit, &o);
116.1902 +					if (f->args)
116.1903 +						lastVar->next = o;
116.1904 +					else
116.1905 +						f->args = o;
116.1906 +					lastVar = o;
116.1907 +					break;
116.1908 +				}
116.1909 +				case DW_TAG_unspecified_parameters:
116.1910 +					// no use in the debugger yet
116.1911 +					data = elfSkipData(data, abbr, unit->abbrevs);
116.1912 +					break;
116.1913 +CASE_TYPE_TAG:
116.1914 +					// skip types... parsed only when used
116.1915 +					data = elfSkipData(data, abbr, unit->abbrevs);
116.1916 +					break;
116.1917 +				default:
116.1918 +					fprintf(stderr, "Unknown subroutine tag %02x\n", abbr->tag);
116.1919 +					data = elfSkipData(data, abbr, unit->abbrevs);
116.1920 +					break;
116.1921 +				}
116.1922 +				num   = elfReadLEB128(data, &bytes);
116.1923 +				data += bytes;
116.1924 +			}
116.1925 +		}
116.1926 +		*type = t;
116.1927 +		return;
116.1928 +		break;
116.1929 +	}
116.1930 +	case DW_TAG_array_type:
116.1931 +	{
116.1932 +		u32    typeref = 0;
116.1933 +		int    i;
116.1934 +		Array *array = (Array *)calloc(sizeof(Array), 1);
116.1935 +		Type * t     = (Type *)calloc(sizeof(Type), 1);
116.1936 +		t->type = TYPE_array;
116.1937 +		elfAddType(t, unit, offset);
116.1938 +
116.1939 +		for (i = 0; i < abbrev->numAttrs; i++)
116.1940 +		{
116.1941 +			ELFAttr *attr = &abbrev->attrs[i];
116.1942 +			data = elfReadAttribute(data, attr);
116.1943 +			switch (attr->name)
116.1944 +			{
116.1945 +			case DW_AT_sibling:
116.1946 +				break;
116.1947 +			case DW_AT_type:
116.1948 +				typeref     = attr->value;
116.1949 +				array->type = elfParseType(unit, typeref);
116.1950 +				break;
116.1951 +			default:
116.1952 +				fprintf(stderr, "Unknown array attribute %02x\n", attr->name);
116.1953 +			}
116.1954 +		}
116.1955 +		if (abbrev->hasChildren)
116.1956 +		{
116.1957 +			int bytes;
116.1958 +			u32 num = elfReadLEB128(data, &bytes);
116.1959 +			data += bytes;
116.1960 +			int index     = 0;
116.1961 +			int maxBounds = 0;
116.1962 +			while (num)
116.1963 +			{
116.1964 +				ELFAbbrev *abbr = elfGetAbbrev(unit->abbrevs, num);
116.1965 +
116.1966 +				switch (abbr->tag)
116.1967 +				{
116.1968 +				case DW_TAG_subrange_type:
116.1969 +				{
116.1970 +					if (maxBounds == index)
116.1971 +					{
116.1972 +						maxBounds    += 4;
116.1973 +						array->bounds = (int *)realloc(array->bounds,
116.1974 +						                               sizeof(int)*maxBounds);
116.1975 +					}
116.1976 +					for (int i = 0; i < abbr->numAttrs; i++)
116.1977 +					{
116.1978 +						ELFAttr *attr = &abbr->attrs[i];
116.1979 +						data = elfReadAttribute(data, attr);
116.1980 +						switch (attr->name)
116.1981 +						{
116.1982 +						case DW_AT_upper_bound:
116.1983 +							array->bounds[index] = attr->value+1;
116.1984 +							break;
116.1985 +						case DW_AT_type: // ignore
116.1986 +							break;
116.1987 +						default:
116.1988 +							fprintf(stderr, "Unknown subrange attribute %02x\n",
116.1989 +							        attr->name);
116.1990 +						}
116.1991 +					}
116.1992 +					index++;
116.1993 +					break;
116.1994 +				}
116.1995 +				default:
116.1996 +					fprintf(stderr, "Unknown array tag %02x\n", abbr->tag);
116.1997 +					data = elfSkipData(data, abbr, unit->abbrevs);
116.1998 +					break;
116.1999 +				}
116.2000 +				num   = elfReadLEB128(data, &bytes);
116.2001 +				data += bytes;
116.2002 +			}
116.2003 +			array->maxBounds = index;
116.2004 +		}
116.2005 +		t->size = array->type->size;
116.2006 +		for (i = 0; i < array->maxBounds; i++)
116.2007 +			t->size *= array->bounds[i];
116.2008 +		t->array = array;
116.2009 +		*type    = t;
116.2010 +		return;
116.2011 +		break;
116.2012 +	}
116.2013 +	default:
116.2014 +		fprintf(stderr, "Unknown type TAG %02x\n", abbrev->tag);
116.2015 +		exit(-1);
116.2016 +	}
116.2017 +}
116.2018 +
116.2019 +Type *elfParseType(CompileUnit *unit, u32 offset)
116.2020 +{
116.2021 +	Type *t = unit->types;
116.2022 +
116.2023 +	while (t)
116.2024 +	{
116.2025 +		if (t->offset == offset)
116.2026 +			return t;
116.2027 +		t = t->next;
116.2028 +	}
116.2029 +	if (offset == 0)
116.2030 +	{
116.2031 +		Type *t = (Type *)calloc(sizeof(Type), 1);
116.2032 +		t->type   = TYPE_void;
116.2033 +		t->offset = 0;
116.2034 +		elfAddType(t, unit, 0);
116.2035 +		return t;
116.2036 +	}
116.2037 +	u8 *data = unit->top + offset;
116.2038 +	int bytes;
116.2039 +	int abbrevNum = elfReadLEB128(data, &bytes);
116.2040 +	data += bytes;
116.2041 +	Type *type = NULL;
116.2042 +
116.2043 +	ELFAbbrev *abbrev = elfGetAbbrev(unit->abbrevs, abbrevNum);
116.2044 +
116.2045 +	elfParseType(data, offset, abbrev, unit, &type);
116.2046 +	return type;
116.2047 +}
116.2048 +
116.2049 +void elfGetObjectAttributes(CompileUnit *unit, u32 offset, Object *o)
116.2050 +{
116.2051 +	u8 *data = unit->top + offset;
116.2052 +	int bytes;
116.2053 +	u32 abbrevNum = elfReadLEB128(data, &bytes);
116.2054 +	data += bytes;
116.2055 +
116.2056 +	if (!abbrevNum)
116.2057 +	{
116.2058 +		return;
116.2059 +	}
116.2060 +
116.2061 +	ELFAbbrev *abbrev = elfGetAbbrev(unit->abbrevs, abbrevNum);
116.2062 +
116.2063 +	for (int i = 0; i < abbrev->numAttrs; i++)
116.2064 +	{
116.2065 +		ELFAttr *attr = &abbrev->attrs[i];
116.2066 +		data = elfReadAttribute(data, attr);
116.2067 +		switch (attr->name)
116.2068 +		{
116.2069 +		case DW_AT_location:
116.2070 +			o->location = attr->block;
116.2071 +			break;
116.2072 +		case DW_AT_name:
116.2073 +			if (o->name == NULL)
116.2074 +				o->name = attr->string;
116.2075 +			break;
116.2076 +		case DW_AT_MIPS_linkage_name:
116.2077 +			o->name = attr->string;
116.2078 +			break;
116.2079 +		case DW_AT_decl_file:
116.2080 +			o->file = attr->value;
116.2081 +			break;
116.2082 +		case DW_AT_decl_line:
116.2083 +			o->line = attr->value;
116.2084 +			break;
116.2085 +		case DW_AT_type:
116.2086 +			o->type = elfParseType(unit, attr->value);
116.2087 +			break;
116.2088 +		case DW_AT_external:
116.2089 +			o->external = attr->flag;
116.2090 +			break;
116.2091 +		case DW_AT_const_value:
116.2092 +		case DW_AT_abstract_origin:
116.2093 +		case DW_AT_declaration:
116.2094 +		case DW_AT_artificial:
116.2095 +			// todo
116.2096 +			break;
116.2097 +		case DW_AT_specification:
116.2098 +			// TODO:
116.2099 +			break;
116.2100 +		default:
116.2101 +			fprintf(stderr, "Unknown object attribute %02x\n", attr->name);
116.2102 +			break;
116.2103 +		}
116.2104 +	}
116.2105 +}
116.2106 +
116.2107 +u8 *elfParseObject(u8 *data, ELFAbbrev *abbrev, CompileUnit *unit,
116.2108 +                   Object **object)
116.2109 +{
116.2110 +	Object *o = (Object *)calloc(sizeof(Object), 1);
116.2111 +
116.2112 +	o->next = NULL;
116.2113 +
116.2114 +	for (int i = 0; i < abbrev->numAttrs; i++)
116.2115 +	{
116.2116 +		ELFAttr *attr = &abbrev->attrs[i];
116.2117 +		data = elfReadAttribute(data, attr);
116.2118 +		switch (attr->name)
116.2119 +		{
116.2120 +		case DW_AT_location:
116.2121 +			o->location = attr->block;
116.2122 +			break;
116.2123 +		case DW_AT_name:
116.2124 +			if (o->name == NULL)
116.2125 +				o->name = attr->string;
116.2126 +			break;
116.2127 +		case DW_AT_MIPS_linkage_name:
116.2128 +			o->name = attr->string;
116.2129 +			break;
116.2130 +		case DW_AT_decl_file:
116.2131 +			o->file = attr->value;
116.2132 +			break;
116.2133 +		case DW_AT_decl_line:
116.2134 +			o->line = attr->value;
116.2135 +			break;
116.2136 +		case DW_AT_type:
116.2137 +			o->type = elfParseType(unit, attr->value);
116.2138 +			break;
116.2139 +		case DW_AT_external:
116.2140 +			o->external = attr->flag;
116.2141 +			break;
116.2142 +		case DW_AT_abstract_origin:
116.2143 +			elfGetObjectAttributes(unit, attr->value, o);
116.2144 +			break;
116.2145 +		case DW_AT_const_value:
116.2146 +		case DW_AT_declaration:
116.2147 +		case DW_AT_artificial:
116.2148 +			break;
116.2149 +		case DW_AT_specification:
116.2150 +			// TODO:
116.2151 +			break;
116.2152 +		default:
116.2153 +			fprintf(stderr, "Unknown object attribute %02x\n", attr->name);
116.2154 +			break;
116.2155 +		}
116.2156 +	}
116.2157 +	*object = o;
116.2158 +	return data;
116.2159 +}
116.2160 +
116.2161 +u8 *elfParseBlock(u8 *data, ELFAbbrev *abbrev, CompileUnit *unit,
116.2162 +                  Function *func, Object **lastVar)
116.2163 +{
116.2164 +	int bytes;
116.2165 +	u32 start = func->lowPC;
116.2166 +	u32 end   = func->highPC;
116.2167 +
116.2168 +	for (int i = 0; i < abbrev->numAttrs; i++)
116.2169 +	{
116.2170 +		ELFAttr *attr = &abbrev->attrs[i];
116.2171 +		data = elfReadAttribute(data, attr);
116.2172 +		switch (attr->name)
116.2173 +		{
116.2174 +		case DW_AT_sibling:
116.2175 +			break;
116.2176 +		case DW_AT_low_pc:
116.2177 +			start = attr->value;
116.2178 +			break;
116.2179 +		case DW_AT_high_pc:
116.2180 +			end = attr->value;
116.2181 +			break;
116.2182 +		case DW_AT_ranges: // ignore for now
116.2183 +			break;
116.2184 +		default:
116.2185 +			fprintf(stderr, "Unknown block attribute %02x\n", attr->name);
116.2186 +			break;
116.2187 +		}
116.2188 +	}
116.2189 +
116.2190 +	if (abbrev->hasChildren)
116.2191 +	{
116.2192 +		int nesting = 1;
116.2193 +
116.2194 +		while (nesting)
116.2195 +		{
116.2196 +			u32 abbrevNum = elfReadLEB128(data, &bytes);
116.2197 +			data += bytes;
116.2198 +
116.2199 +			if (!abbrevNum)
116.2200 +			{
116.2201 +				nesting--;
116.2202 +				continue;
116.2203 +			}
116.2204 +
116.2205 +			abbrev = elfGetAbbrev(unit->abbrevs, abbrevNum);
116.2206 +
116.2207 +			switch (abbrev->tag)
116.2208 +			{
116.2209 +CASE_TYPE_TAG:       // types only parsed when used
116.2210 +			case DW_TAG_label: // not needed
116.2211 +				data = elfSkipData(data, abbrev, unit->abbrevs);
116.2212 +				break;
116.2213 +			case DW_TAG_lexical_block:
116.2214 +				data = elfParseBlock(data, abbrev, unit, func, lastVar);
116.2215 +				break;
116.2216 +			case DW_TAG_subprogram:
116.2217 +			{
116.2218 +				Function *f = NULL;
116.2219 +				data = elfParseFunction(data, abbrev, unit, &f);
116.2220 +				if (f != NULL)
116.2221 +				{
116.2222 +					if (unit->lastFunction)
116.2223 +						unit->lastFunction->next = f;
116.2224 +					else
116.2225 +						unit->functions = f;
116.2226 +					unit->lastFunction = f;
116.2227 +				}
116.2228 +				break;
116.2229 +			}
116.2230 +			case DW_TAG_variable:
116.2231 +			{
116.2232 +				Object *o;
116.2233 +				data = elfParseObject(data, abbrev, unit, &o);
116.2234 +				if (o->startScope == 0)
116.2235 +					o->startScope = start;
116.2236 +				if (o->endScope == 0)
116.2237 +					o->endScope = 0;
116.2238 +				if (func->variables)
116.2239 +					(*lastVar)->next = o;
116.2240 +				else
116.2241 +					func->variables = o;
116.2242 +				*lastVar = o;
116.2243 +				break;
116.2244 +			}
116.2245 +			case DW_TAG_inlined_subroutine:
116.2246 +				// TODO:
116.2247 +				data = elfSkipData(data, abbrev, unit->abbrevs);
116.2248 +				break;
116.2249 +			default:
116.2250 +			{
116.2251 +				fprintf(stderr, "Unknown block TAG %02x\n", abbrev->tag);
116.2252 +				data = elfSkipData(data, abbrev, unit->abbrevs);
116.2253 +				break;
116.2254 +			}
116.2255 +			}
116.2256 +		}
116.2257 +	}
116.2258 +	return data;
116.2259 +}
116.2260 +
116.2261 +void elfGetFunctionAttributes(CompileUnit *unit, u32 offset, Function *func)
116.2262 +{
116.2263 +	u8 *data = unit->top + offset;
116.2264 +	int bytes;
116.2265 +	u32 abbrevNum = elfReadLEB128(data, &bytes);
116.2266 +	data += bytes;
116.2267 +
116.2268 +	if (!abbrevNum)
116.2269 +	{
116.2270 +		return;
116.2271 +	}
116.2272 +
116.2273 +	ELFAbbrev *abbrev = elfGetAbbrev(unit->abbrevs, abbrevNum);
116.2274 +
116.2275 +	for (int i = 0; i < abbrev->numAttrs; i++)
116.2276 +	{
116.2277 +		ELFAttr *attr = &abbrev->attrs[i];
116.2278 +		data = elfReadAttribute(data, attr);
116.2279 +
116.2280 +		switch (attr->name)
116.2281 +		{
116.2282 +		case DW_AT_sibling:
116.2283 +			break;
116.2284 +		case DW_AT_name:
116.2285 +			if (func->name == NULL)
116.2286 +				func->name = attr->string;
116.2287 +			break;
116.2288 +		case DW_AT_MIPS_linkage_name:
116.2289 +			func->name = attr->string;
116.2290 +			break;
116.2291 +		case DW_AT_low_pc:
116.2292 +			func->lowPC = attr->value;
116.2293 +			break;
116.2294 +		case DW_AT_high_pc:
116.2295 +			func->highPC = attr->value;
116.2296 +			break;
116.2297 +		case DW_AT_decl_file:
116.2298 +			func->file = attr->value;
116.2299 +			break;
116.2300 +		case DW_AT_decl_line:
116.2301 +			func->line = attr->value;
116.2302 +			break;
116.2303 +		case DW_AT_external:
116.2304 +			func->external = attr->flag;
116.2305 +			break;
116.2306 +		case DW_AT_frame_base:
116.2307 +			func->frameBase = attr->block;
116.2308 +			break;
116.2309 +		case DW_AT_type:
116.2310 +			func->returnType = elfParseType(unit, attr->value);
116.2311 +			break;
116.2312 +		case DW_AT_inline:
116.2313 +		case DW_AT_specification:
116.2314 +		case DW_AT_declaration:
116.2315 +		case DW_AT_artificial:
116.2316 +		case DW_AT_prototyped:
116.2317 +		case DW_AT_proc_body:
116.2318 +		case DW_AT_save_offset:
116.2319 +		case DW_AT_user_2002:
116.2320 +		case DW_AT_virtuality:
116.2321 +		case DW_AT_containing_type:
116.2322 +		case DW_AT_accessibility:
116.2323 +			// todo;
116.2324 +			break;
116.2325 +		case DW_AT_vtable_elem_location:
116.2326 +			free(attr->block);
116.2327 +			break;
116.2328 +		default:
116.2329 +			fprintf(stderr, "Unknown function attribute %02x\n", attr->name);
116.2330 +			break;
116.2331 +		}
116.2332 +	}
116.2333 +
116.2334 +	return;
116.2335 +}
116.2336 +
116.2337 +u8 *elfParseFunction(u8 *data, ELFAbbrev *abbrev, CompileUnit *unit,
116.2338 +                     Function **f)
116.2339 +{
116.2340 +	Function *func = (Function *)calloc(sizeof(Function), 1);
116.2341 +	*f = func;
116.2342 +
116.2343 +	int  bytes;
116.2344 +	bool mangled     = false;
116.2345 +	bool declaration = false;
116.2346 +	for (int i = 0; i < abbrev->numAttrs; i++)
116.2347 +	{
116.2348 +		ELFAttr *attr = &abbrev->attrs[i];
116.2349 +		data = elfReadAttribute(data, attr);
116.2350 +		switch (attr->name)
116.2351 +		{
116.2352 +		case DW_AT_sibling:
116.2353 +			break;
116.2354 +		case DW_AT_name:
116.2355 +			if (func->name == NULL)
116.2356 +				func->name = attr->string;
116.2357 +			break;
116.2358 +		case DW_AT_MIPS_linkage_name:
116.2359 +			func->name = attr->string;
116.2360 +			mangled    = true;
116.2361 +			break;
116.2362 +		case DW_AT_low_pc:
116.2363 +			func->lowPC = attr->value;
116.2364 +			break;
116.2365 +		case DW_AT_high_pc:
116.2366 +			func->highPC = attr->value;
116.2367 +			break;
116.2368 +		case DW_AT_prototyped:
116.2369 +			break;
116.2370 +		case DW_AT_decl_file:
116.2371 +			func->file = attr->value;
116.2372 +			break;
116.2373 +		case DW_AT_decl_line:
116.2374 +			func->line = attr->value;
116.2375 +			break;
116.2376 +		case DW_AT_external:
116.2377 +			func->external = attr->flag;
116.2378 +			break;
116.2379 +		case DW_AT_frame_base:
116.2380 +			func->frameBase = attr->block;
116.2381 +			break;
116.2382 +		case DW_AT_type:
116.2383 +			func->returnType = elfParseType(unit, attr->value);
116.2384 +			break;
116.2385 +		case DW_AT_abstract_origin:
116.2386 +			elfGetFunctionAttributes(unit, attr->value, func);
116.2387 +			break;
116.2388 +		case DW_AT_declaration:
116.2389 +			declaration = attr->flag;
116.2390 +			break;
116.2391 +		case DW_AT_inline:
116.2392 +		case DW_AT_specification:
116.2393 +		case DW_AT_artificial:
116.2394 +		case DW_AT_proc_body:
116.2395 +		case DW_AT_save_offset:
116.2396 +		case DW_AT_user_2002:
116.2397 +		case DW_AT_virtuality:
116.2398 +		case DW_AT_containing_type:
116.2399 +		case DW_AT_accessibility:
116.2400 +			// todo;
116.2401 +			break;
116.2402 +		case DW_AT_vtable_elem_location:
116.2403 +			free(attr->block);
116.2404 +			break;
116.2405 +		default:
116.2406 +			fprintf(stderr, "Unknown function attribute %02x\n", attr->name);
116.2407 +			break;
116.2408 +		}
116.2409 +	}
116.2410 +
116.2411 +	if (declaration)
116.2412 +	{
116.2413 +		elfCleanUp(func);
116.2414 +		free(func);
116.2415 +		*f = NULL;
116.2416 +
116.2417 +		while (1)
116.2418 +		{
116.2419 +			u32 abbrevNum = elfReadLEB128(data, &bytes);
116.2420 +			data += bytes;
116.2421 +
116.2422 +			if (!abbrevNum)
116.2423 +			{
116.2424 +				return data;
116.2425 +			}
116.2426 +
116.2427 +			abbrev = elfGetAbbrev(unit->abbrevs, abbrevNum);
116.2428 +
116.2429 +			data = elfSkipData(data, abbrev, unit->abbrevs);
116.2430 +		}
116.2431 +	}
116.2432 +
116.2433 +	if (abbrev->hasChildren)
116.2434 +	{
116.2435 +		int     nesting   = 1;
116.2436 +		Object *lastParam = NULL;
116.2437 +		Object *lastVar   = NULL;
116.2438 +
116.2439 +		while (nesting)
116.2440 +		{
116.2441 +			u32 abbrevNum = elfReadLEB128(data, &bytes);
116.2442 +			data += bytes;
116.2443 +
116.2444 +			if (!abbrevNum)
116.2445 +			{
116.2446 +				nesting--;
116.2447 +				continue;
116.2448 +			}
116.2449 +
116.2450 +			abbrev = elfGetAbbrev(unit->abbrevs, abbrevNum);
116.2451 +
116.2452 +			switch (abbrev->tag)
116.2453 +			{
116.2454 +CASE_TYPE_TAG:       // no need to parse types. only parsed when used
116.2455 +			case DW_TAG_label: // not needed
116.2456 +				data = elfSkipData(data, abbrev, unit->abbrevs);
116.2457 +				break;
116.2458 +			case DW_TAG_subprogram:
116.2459 +			{
116.2460 +				Function *fnc = NULL;
116.2461 +				data = elfParseFunction(data, abbrev, unit, &fnc);
116.2462 +				if (fnc != NULL)
116.2463 +				{
116.2464 +					if (unit->lastFunction == NULL)
116.2465 +						unit->functions = fnc;
116.2466 +					else
116.2467 +						unit->lastFunction->next = fnc;
116.2468 +					unit->lastFunction = fnc;
116.2469 +				}
116.2470 +				break;
116.2471 +			}
116.2472 +			case DW_TAG_lexical_block:
116.2473 +			{
116.2474 +				data = elfParseBlock(data, abbrev, unit, func, &lastVar);
116.2475 +				break;
116.2476 +			}
116.2477 +			case DW_TAG_formal_parameter:
116.2478 +			{
116.2479 +				Object *o;
116.2480 +				data = elfParseObject(data, abbrev, unit, &o);
116.2481 +				if (func->parameters)
116.2482 +					lastParam->next = o;
116.2483 +				else
116.2484 +					func->parameters = o;
116.2485 +				lastParam = o;
116.2486 +				break;
116.2487 +			}
116.2488 +			case DW_TAG_variable:
116.2489 +			{
116.2490 +				Object *o;
116.2491 +				data = elfParseObject(data, abbrev, unit, &o);
116.2492 +				if (func->variables)
116.2493 +					lastVar->next = o;
116.2494 +				else
116.2495 +					func->variables = o;
116.2496 +				lastVar = o;
116.2497 +				break;
116.2498 +			}
116.2499 +			case DW_TAG_unspecified_parameters:
116.2500 +			case DW_TAG_inlined_subroutine:
116.2501 +			{
116.2502 +				// todo
116.2503 +				for (int i = 0; i < abbrev->numAttrs; i++)
116.2504 +				{
116.2505 +					data = elfReadAttribute(data,  &abbrev->attrs[i]);
116.2506 +					if (abbrev->attrs[i].form == DW_FORM_block1)
116.2507 +						free(abbrev->attrs[i].block);
116.2508 +				}
116.2509 +
116.2510 +				if (abbrev->hasChildren)
116.2511 +					nesting++;
116.2512 +				break;
116.2513 +			}
116.2514 +			default:
116.2515 +			{
116.2516 +				fprintf(stderr, "Unknown function TAG %02x\n", abbrev->tag);
116.2517 +				data = elfSkipData(data, abbrev, unit->abbrevs);
116.2518 +				break;
116.2519 +			}
116.2520 +			}
116.2521 +		}
116.2522 +	}
116.2523 +	return data;
116.2524 +}
116.2525 +
116.2526 +u8 *elfParseUnknownData(u8 *data, ELFAbbrev *abbrev, ELFAbbrev **abbrevs)
116.2527 +{
116.2528 +	int i;
116.2529 +	int bytes;
116.2530 +	//  switch(abbrev->tag) {
116.2531 +	//  default:
116.2532 +	fprintf(stderr, "Unknown TAG %02x\n", abbrev->tag);
116.2533 +
116.2534 +	for (i = 0; i < abbrev->numAttrs; i++)
116.2535 +	{
116.2536 +		data = elfReadAttribute(data,  &abbrev->attrs[i]);
116.2537 +		if (abbrev->attrs[i].form == DW_FORM_block1)
116.2538 +			free(abbrev->attrs[i].block);
116.2539 +	}
116.2540 +
116.2541 +	if (abbrev->hasChildren)
116.2542 +	{
116.2543 +		int nesting = 1;
116.2544 +		while (nesting)
116.2545 +		{
116.2546 +			u32 abbrevNum = elfReadLEB128(data, &bytes);
116.2547 +			data += bytes;
116.2548 +
116.2549 +			if (!abbrevNum)
116.2550 +			{
116.2551 +				nesting--;
116.2552 +				continue;
116.2553 +			}
116.2554 +
116.2555 +			abbrev = elfGetAbbrev(abbrevs, abbrevNum);
116.2556 +
116.2557 +			fprintf(stderr, "Unknown TAG %02x\n", abbrev->tag);
116.2558 +
116.2559 +			for (i = 0; i < abbrev->numAttrs; i++)
116.2560 +			{
116.2561 +				data = elfReadAttribute(data,  &abbrev->attrs[i]);
116.2562 +				if (abbrev->attrs[i].form == DW_FORM_block1)
116.2563 +					free(abbrev->attrs[i].block);
116.2564 +			}
116.2565 +
116.2566 +			if (abbrev->hasChildren)
116.2567 +			{
116.2568 +				nesting++;
116.2569 +			}
116.2570 +		}
116.2571 +	}
116.2572 +	//  }
116.2573 +	return data;
116.2574 +}
116.2575 +
116.2576 +u8 *elfParseCompileUnitChildren(u8 *data, CompileUnit *unit)
116.2577 +{
116.2578 +	int bytes;
116.2579 +	u32 abbrevNum = elfReadLEB128(data, &bytes);
116.2580 +	data += bytes;
116.2581 +	Object *lastObj = NULL;
116.2582 +	while (abbrevNum)
116.2583 +	{
116.2584 +		ELFAbbrev *abbrev = elfGetAbbrev(unit->abbrevs, abbrevNum);
116.2585 +		switch (abbrev->tag)
116.2586 +		{
116.2587 +		case DW_TAG_subprogram:
116.2588 +		{
116.2589 +			Function *func = NULL;
116.2590 +			data = elfParseFunction(data, abbrev, unit, &func);
116.2591 +			if (func != NULL)
116.2592 +			{
116.2593 +				if (unit->lastFunction)
116.2594 +					unit->lastFunction->next = func;
116.2595 +				else
116.2596 +					unit->functions = func;
116.2597 +				unit->lastFunction = func;
116.2598 +			}
116.2599 +			break;
116.2600 +		}
116.2601 +CASE_TYPE_TAG:
116.2602 +			data = elfSkipData(data, abbrev, unit->abbrevs);
116.2603 +			break;
116.2604 +		case DW_TAG_variable:
116.2605 +		{
116.2606 +			Object *var = NULL;
116.2607 +			data = elfParseObject(data, abbrev, unit, &var);
116.2608 +			if (lastObj)
116.2609 +				lastObj->next = var;
116.2610 +			else
116.2611 +				unit->variables = var;
116.2612 +			lastObj = var;
116.2613 +			break;
116.2614 +		}
116.2615 +		default:
116.2616 +			data = elfParseUnknownData(data, abbrev, unit->abbrevs);
116.2617 +			break;
116.2618 +		}
116.2619 +
116.2620 +		abbrevNum = elfReadLEB128(data, &bytes);
116.2621 +		data     += bytes;
116.2622 +	}
116.2623 +	return data;
116.2624 +}
116.2625 +
116.2626 +CompileUnit *elfParseCompUnit(u8 *data, u8 *abbrevData)
116.2627 +{
116.2628 +	int bytes;
116.2629 +	u8 *top = data;
116.2630 +
116.2631 +	u32 length = elfRead4Bytes(data);
116.2632 +	data += 4;
116.2633 +
116.2634 +	u16 version = elfRead2Bytes(data);
116.2635 +	data += 2;
116.2636 +
116.2637 +	u32 offset = elfRead4Bytes(data);
116.2638 +	data += 4;
116.2639 +
116.2640 +	u8 addrSize = *data++;
116.2641 +
116.2642 +	if (version != 2)
116.2643 +	{
116.2644 +		fprintf(stderr, "Unsupported debugging information version %d\n", version);
116.2645 +		return NULL;
116.2646 +	}
116.2647 +
116.2648 +	if (addrSize != 4)
116.2649 +	{
116.2650 +		fprintf(stderr, "Unsupported address size %d\n", addrSize);
116.2651 +		return NULL;
116.2652 +	}
116.2653 +
116.2654 +	ELFAbbrev **abbrevs = elfReadAbbrevs(abbrevData, offset);
116.2655 +
116.2656 +	u32 abbrevNum = elfReadLEB128(data, &bytes);
116.2657 +	data += bytes;
116.2658 +
116.2659 +	ELFAbbrev *abbrev = elfGetAbbrev(abbrevs, abbrevNum);
116.2660 +
116.2661 +	CompileUnit *unit = (CompileUnit *)calloc(sizeof(CompileUnit), 1);
116.2662 +	unit->top     = top;
116.2663 +	unit->length  = length;
116.2664 +	unit->abbrevs = abbrevs;
116.2665 +	unit->next    = NULL;
116.2666 +
116.2667 +	elfCurrentUnit = unit;
116.2668 +
116.2669 +	int i;
116.2670 +
116.2671 +	for (i = 0; i < abbrev->numAttrs; i++)
116.2672 +	{
116.2673 +		ELFAttr *attr = &abbrev->attrs[i];
116.2674 +		data = elfReadAttribute(data, attr);
116.2675 +
116.2676 +		switch (attr->name)
116.2677 +		{
116.2678 +		case DW_AT_name:
116.2679 +			unit->name = attr->string;
116.2680 +			break;
116.2681 +		case DW_AT_stmt_list:
116.2682 +			unit->hasLineInfo = true;
116.2683 +			unit->lineInfo    = attr->value;
116.2684 +			break;
116.2685 +		case DW_AT_low_pc:
116.2686 +			unit->lowPC = attr->value;
116.2687 +			break;
116.2688 +		case DW_AT_high_pc:
116.2689 +			unit->highPC = attr->value;
116.2690 +			break;
116.2691 +		case DW_AT_compdir:
116.2692 +			unit->compdir = attr->string;
116.2693 +			break;
116.2694 +		// ignore
116.2695 +		case DW_AT_language:
116.2696 +		case DW_AT_producer:
116.2697 +		case DW_AT_macro_info:
116.2698 +		case DW_AT_entry_pc:
116.2699 +			break;
116.2700 +		default:
116.2701 +			fprintf(stderr, "Unknown attribute %02x\n", attr->name);
116.2702 +			break;
116.2703 +		}
116.2704 +	}
116.2705 +
116.2706 +	if (abbrev->hasChildren)
116.2707 +		elfParseCompileUnitChildren(data, unit);
116.2708 +
116.2709 +	return unit;
116.2710 +}
116.2711 +
116.2712 +void elfParseAranges(u8 *data)
116.2713 +{
116.2714 +	ELFSectionHeader *sh = elfGetSectionByName(".debug_aranges");
116.2715 +	if (sh == NULL)
116.2716 +	{
116.2717 +		fprintf(stderr, "No aranges found\n");
116.2718 +		return;
116.2719 +	}
116.2720 +
116.2721 +	data = elfReadSection(data, sh);
116.2722 +	u8 *end = data + READ32LE(&sh->size);
116.2723 +
116.2724 +	int      max    = 4;
116.2725 +	ARanges *ranges = (ARanges *)calloc(sizeof(ARanges), 4);
116.2726 +
116.2727 +	int index = 0;
116.2728 +
116.2729 +	while (data < end)
116.2730 +	{
116.2731 +		u32 len = elfRead4Bytes(data);
116.2732 +		data += 4;
116.2733 +		//    u16 version = elfRead2Bytes(data);
116.2734 +		data += 2;
116.2735 +		u32 offset = elfRead4Bytes(data);
116.2736 +		data += 4;
116.2737 +		//    u8 addrSize = *data++;
116.2738 +		//    u8 segSize = *data++;
116.2739 +		data += 2; // remove if uncommenting above
116.2740 +		data += 4;
116.2741 +		ranges[index].count  = (len-20)/8;
116.2742 +		ranges[index].offset = offset;
116.2743 +		ranges[index].ranges = (ARange *)calloc(sizeof(ARange), (len-20)/8);
116.2744 +		int i = 0;
116.2745 +		while (true)
116.2746 +		{
116.2747 +			u32 addr = elfRead4Bytes(data);
116.2748 +			data += 4;
116.2749 +			u32 len = elfRead4Bytes(data);
116.2750 +			data += 4;
116.2751 +			if (addr == 0 && len == 0)
116.2752 +				break;
116.2753 +			ranges[index].ranges[i].lowPC  = addr;
116.2754 +			ranges[index].ranges[i].highPC = addr+len;
116.2755 +			i++;
116.2756 +		}
116.2757 +		index++;
116.2758 +		if (index == max)
116.2759 +		{
116.2760 +			max   += 4;
116.2761 +			ranges = (ARanges *)realloc(ranges, max*sizeof(ARanges));
116.2762 +		}
116.2763 +	}
116.2764 +	elfDebugInfo->numRanges = index;
116.2765 +	elfDebugInfo->ranges    = ranges;
116.2766 +}
116.2767 +
116.2768 +void elfReadSymtab(u8 *data)
116.2769 +{
116.2770 +	ELFSectionHeader *sh = elfGetSectionByName(".symtab");
116.2771 +	int table = READ32LE(&sh->link);
116.2772 +
116.2773 +	char *strtable = (char *)elfReadSection(data, elfGetSectionByNumber(table));
116.2774 +
116.2775 +	ELFSymbol *symtab = (ELFSymbol *)elfReadSection(data, sh);
116.2776 +
116.2777 +	int count = READ32LE(&sh->size) / sizeof(ELFSymbol);
116.2778 +	elfSymbolsCount = 0;
116.2779 +
116.2780 +	elfSymbols = (Symbol *)malloc(sizeof(Symbol)*count);
116.2781 +
116.2782 +	int i;
116.2783 +
116.2784 +	for (i = 0; i < count; i++)
116.2785 +	{
116.2786 +		ELFSymbol *s       = &symtab[i];
116.2787 +		int        type    = s->info & 15;
116.2788 +		int        binding = s->info >> 4;
116.2789 +
116.2790 +		if (binding)
116.2791 +		{
116.2792 +			Symbol *sym = &elfSymbols[elfSymbolsCount];
116.2793 +			sym->name    = &strtable[READ32LE(&s->name)];
116.2794 +			sym->binding = binding;
116.2795 +			sym->type    = type;
116.2796 +			sym->value   = READ32LE(&s->value);
116.2797 +			sym->size    = READ32LE(&s->size);
116.2798 +			elfSymbolsCount++;
116.2799 +		}
116.2800 +	}
116.2801 +	for (i = 0; i < count; i++)
116.2802 +	{
116.2803 +		ELFSymbol *s    = &symtab[i];
116.2804 +		int        bind = s->info>>4;
116.2805 +		int        type = s->info & 15;
116.2806 +
116.2807 +		if (!bind)
116.2808 +		{
116.2809 +			Symbol *sym = &elfSymbols[elfSymbolsCount];
116.2810 +			sym->name    = &strtable[READ32LE(&s->name)];
116.2811 +			sym->binding = (s->info >> 4);
116.2812 +			sym->type    = type;
116.2813 +			sym->value   = READ32LE(&s->value);
116.2814 +			sym->size    = READ32LE(&s->size);
116.2815 +			elfSymbolsCount++;
116.2816 +		}
116.2817 +	}
116.2818 +	elfSymbolsStrTab = strtable;
116.2819 +	//  free(symtab);
116.2820 +}
116.2821 +
116.2822 +bool elfReadProgram(ELFHeader *eh, u8 *data, int& size, bool parseDebug)
116.2823 +{
116.2824 +	int count = READ16LE(&eh->e_phnum);
116.2825 +	int i;
116.2826 +
116.2827 +	if (READ32LE(&eh->e_entry) == 0x2000000)
116.2828 +		cpuIsMultiBoot = true;
116.2829 +
116.2830 +	// read program headers... should probably move this code down
116.2831 +	u8 *p = data + READ32LE(&eh->e_phoff);
116.2832 +	size = 0;
116.2833 +	for (i = 0; i < count; i++)
116.2834 +	{
116.2835 +		ELFProgramHeader *ph = (ELFProgramHeader *)p;
116.2836 +		p += sizeof(ELFProgramHeader);
116.2837 +		if (READ16LE(&eh->e_phentsize) != sizeof(ELFProgramHeader))
116.2838 +		{
116.2839 +			p += READ16LE(&eh->e_phentsize) - sizeof(ELFProgramHeader);
116.2840 +		}
116.2841 +
116.2842 +		//    printf("PH %d %08x %08x %08x %08x %08x %08x %08x %08x\n",
116.2843 +		//     i, ph->type, ph->offset, ph->vaddr, ph->paddr,
116.2844 +		//     ph->filesz, ph->memsz, ph->flags, ph->align);
116.2845 +		if (cpuIsMultiBoot)
116.2846 +		{
116.2847 +			if (READ32LE(&ph->paddr) >= 0x2000000 &&
116.2848 +			    READ32LE(&ph->paddr) <= 0x203ffff)
116.2849 +			{
116.2850 +				memcpy(&workRAM[READ32LE(&ph->paddr) & 0x3ffff],
116.2851 +				       data + READ32LE(&ph->offset),
116.2852 +				       READ32LE(&ph->filesz));
116.2853 +			}
116.2854 +		}
116.2855 +		else
116.2856 +		{
116.2857 +			if (READ32LE(&ph->paddr) >= 0x8000000 &&
116.2858 +			    READ32LE(&ph->paddr) <= 0x9ffffff)
116.2859 +			{
116.2860 +				memcpy(&rom[READ32LE(&ph->paddr) & 0x1ffffff],
116.2861 +				       data + READ32LE(&ph->offset),
116.2862 +				       READ32LE(&ph->filesz));
116.2863 +				size += READ32LE(&ph->filesz);
116.2864 +			}
116.2865 +		}
116.2866 +	}
116.2867 +
116.2868 +	char *stringTable = NULL;
116.2869 +
116.2870 +	// read section headers
116.2871 +	p     = data + READ32LE(&eh->e_shoff);
116.2872 +	count = READ16LE(&eh->e_shnum);
116.2873 +
116.2874 +	ELFSectionHeader **sh = (ELFSectionHeader * *)
116.2875 +	                        malloc(sizeof(ELFSectionHeader *) * count);
116.2876 +
116.2877 +	for (i = 0; i < count; i++)
116.2878 +	{
116.2879 +		sh[i] = (ELFSectionHeader *)p;
116.2880 +		p    += sizeof(ELFSectionHeader);
116.2881 +		if (READ16LE(&eh->e_shentsize) != sizeof(ELFSectionHeader))
116.2882 +			p += READ16LE(&eh->e_shentsize) - sizeof(ELFSectionHeader);
116.2883 +	}
116.2884 +
116.2885 +	if (READ16LE(&eh->e_shstrndx) != 0)
116.2886 +	{
116.2887 +		stringTable = (char *)elfReadSection(data,
116.2888 +		                                     sh[READ16LE(&eh->e_shstrndx)]);
116.2889 +	}
116.2890 +
116.2891 +	elfSectionHeaders = sh;
116.2892 +	elfSectionHeadersStringTable = stringTable;
116.2893 +	elfSectionHeadersCount       = count;
116.2894 +
116.2895 +	for (i = 0; i < count; i++)
116.2896 +	{
116.2897 +		//    printf("SH %d %-20s %08x %08x %08x %08x %08x %08x %08x %08x\n",
116.2898 +		//   i, &stringTable[sh[i]->name], sh[i]->name, sh[i]->type,
116.2899 +		//   sh[i]->flags, sh[i]->addr, sh[i]->offset, sh[i]->size,
116.2900 +		//   sh[i]->link, sh[i]->info);
116.2901 +		if (READ32LE(&sh[i]->flags) & 2) // load section
116.2902 +		{
116.2903 +			if (cpuIsMultiBoot)
116.2904 +			{
116.2905 +				if (READ32LE(&sh[i]->addr) >= 0x2000000 &&
116.2906 +				    READ32LE(&sh[i]->addr) <= 0x203ffff)
116.2907 +				{
116.2908 +					memcpy(&workRAM[READ32LE(&sh[i]->addr) & 0x3ffff], data +
116.2909 +					       READ32LE(&sh[i]->offset),
116.2910 +					       READ32LE(&sh[i]->size));
116.2911 +				}
116.2912 +			}
116.2913 +			else
116.2914 +			{
116.2915 +				if (READ32LE(&sh[i]->addr) >= 0x8000000 &&
116.2916 +				    READ32LE(&sh[i]->addr) <= 0x9ffffff)
116.2917 +				{
116.2918 +					memcpy(&rom[READ32LE(&sh[i]->addr) & 0x1ffffff],
116.2919 +					       data + READ32LE(&sh[i]->offset),
116.2920 +					       READ32LE(&sh[i]->size));
116.2921 +					size += READ32LE(&sh[i]->size);
116.2922 +				}
116.2923 +			}
116.2924 +		}
116.2925 +	}
116.2926 +
116.2927 +	if (parseDebug)
116.2928 +	{
116.2929 +		fprintf(stderr, "Parsing debug info\n");
116.2930 +
116.2931 +		ELFSectionHeader *dbgHeader = elfGetSectionByName(".debug_info");
116.2932 +		if (dbgHeader == NULL)
116.2933 +		{
116.2934 +			fprintf(stderr, "Cannot find debug information\n");
116.2935 +			goto end;
116.2936 +		}
116.2937 +
116.2938 +		ELFSectionHeader *h = elfGetSectionByName(".debug_abbrev");
116.2939 +		if (h == NULL)
116.2940 +		{
116.2941 +			fprintf(stderr, "Cannot find abbreviation table\n");
116.2942 +			goto end;
116.2943 +		}
116.2944 +
116.2945 +		elfDebugInfo = (DebugInfo *)calloc(sizeof(DebugInfo), 1);
116.2946 +		u8 *abbrevdata = elfReadSection(data, h);
116.2947 +
116.2948 +		h = elfGetSectionByName(".debug_str");
116.2949 +
116.2950 +		if (h == NULL)
116.2951 +			elfDebugStrings = NULL;
116.2952 +		else
116.2953 +			elfDebugStrings = (char *)elfReadSection(data, h);
116.2954 +
116.2955 +		u8 *debugdata = elfReadSection(data, dbgHeader);
116.2956 +
116.2957 +		elfDebugInfo->debugdata = data;
116.2958 +		elfDebugInfo->infodata  = debugdata;
116.2959 +
116.2960 +		u32 total = READ32LE(&dbgHeader->size);
116.2961 +		u8 *end   = debugdata + total;
116.2962 +		u8 *ddata = debugdata;
116.2963 +
116.2964 +		CompileUnit *last = NULL;
116.2965 +		CompileUnit *unit = NULL;
116.2966 +
116.2967 +		while (ddata < end)
116.2968 +		{
116.2969 +			unit         = elfParseCompUnit(ddata, abbrevdata);
116.2970 +			unit->offset = ddata-debugdata;
116.2971 +			elfParseLineInfo(unit, data);
116.2972 +			if (last == NULL)
116.2973 +				elfCompileUnits = unit;
116.2974 +			else
116.2975 +				last->next = unit;
116.2976 +			last   = unit;
116.2977 +			ddata += 4 + unit->length;
116.2978 +		}
116.2979 +		elfParseAranges(data);
116.2980 +		CompileUnit *comp = elfCompileUnits;
116.2981 +		while (comp)
116.2982 +		{
116.2983 +			ARanges *r = elfDebugInfo->ranges;
116.2984 +			for (int i = 0; i < elfDebugInfo->numRanges; i++)
116.2985 +				if (r[i].offset == comp->offset)
116.2986 +				{
116.2987 +					comp->ranges = &r[i];
116.2988 +					break;
116.2989 +				}
116.2990 +			comp = comp->next;
116.2991 +		}
116.2992 +		elfParseCFA(data);
116.2993 +		elfReadSymtab(data);
116.2994 +	}
116.2995 +end:
116.2996 +	if (sh)
116.2997 +	{
116.2998 +		free(sh);
116.2999 +	}
116.3000 +
116.3001 +	elfSectionHeaders = NULL;
116.3002 +	elfSectionHeadersStringTable = NULL;
116.3003 +	elfSectionHeadersCount       = 0;
116.3004 +
116.3005 +	return true;
116.3006 +}
116.3007 +
116.3008 +extern bool8 parseDebug;
116.3009 +
116.3010 +bool elfRead(const char *name, int& siz, FILE *f)
116.3011 +{
116.3012 +	fseek(f, 0, SEEK_END);
116.3013 +	long size = ftell(f);
116.3014 +	elfFileData = (u8 *)malloc(size);
116.3015 +	fseek(f, 0, SEEK_SET);
116.3016 +	fread(elfFileData, 1, size, f);
116.3017 +	fclose(f);
116.3018 +
116.3019 +	ELFHeader *header = (ELFHeader *)elfFileData;
116.3020 +
116.3021 +	if (READ32LE(&header->magic) != 0x464C457F ||
116.3022 +	    READ16LE(&header->e_machine) != 40 ||
116.3023 +	    header->clazz != 1)
116.3024 +	{
116.3025 +		systemMessage(0, N_("Not a valid ELF file %s"), name);
116.3026 +		free(elfFileData);
116.3027 +		elfFileData = NULL;
116.3028 +		return false;
116.3029 +	}
116.3030 +
116.3031 +	if (!elfReadProgram(header, elfFileData, siz, parseDebug))
116.3032 +	{
116.3033 +		free(elfFileData);
116.3034 +		elfFileData = NULL;
116.3035 +		return false;
116.3036 +	}
116.3037 +
116.3038 +	return true;
116.3039 +}
116.3040 +
116.3041 +void elfCleanUp(Object *o)
116.3042 +{
116.3043 +	free(o->location);
116.3044 +}
116.3045 +
116.3046 +void elfCleanUp(Function *func)
116.3047 +{
116.3048 +	Object *o = func->parameters;
116.3049 +	while (o)
116.3050 +	{
116.3051 +		elfCleanUp(o);
116.3052 +		Object *next = o->next;
116.3053 +		free(o);
116.3054 +		o = next;
116.3055 +	}
116.3056 +
116.3057 +	o = func->variables;
116.3058 +	while (o)
116.3059 +	{
116.3060 +		elfCleanUp(o);
116.3061 +		Object *next = o->next;
116.3062 +		free(o);
116.3063 +		o = next;
116.3064 +	}
116.3065 +	free(func->frameBase);
116.3066 +}
116.3067 +
116.3068 +void elfCleanUp(ELFAbbrev **abbrevs)
116.3069 +{
116.3070 +	for (int i = 0; i < 121; i++)
116.3071 +	{
116.3072 +		ELFAbbrev *abbrev = abbrevs[i];
116.3073 +
116.3074 +		while (abbrev)
116.3075 +		{
116.3076 +			free(abbrev->attrs);
116.3077 +			ELFAbbrev *next = abbrev->next;
116.3078 +			free(abbrev);
116.3079 +
116.3080 +			abbrev = next;
116.3081 +		}
116.3082 +	}
116.3083 +}
116.3084 +
116.3085 +void elfCleanUp(Type *t)
116.3086 +{
116.3087 +	switch (t->type)
116.3088 +	{
116.3089 +	case TYPE_function:
116.3090 +		if (t->function)
116.3091 +		{
116.3092 +			Object *o = t->function->args;
116.3093 +			while (o)
116.3094 +			{
116.3095 +				elfCleanUp(o);
116.3096 +				Object *next = o->next;
116.3097 +				free(o);
116.3098 +				o = next;
116.3099 +			}
116.3100 +			free(t->function);
116.3101 +		}
116.3102 +		break;
116.3103 +	case TYPE_array:
116.3104 +		if (t->array)
116.3105 +		{
116.3106 +			free(t->array->bounds);
116.3107 +			free(t->array);
116.3108 +		}
116.3109 +		break;
116.3110 +	case TYPE_struct:
116.3111 +	case TYPE_union:
116.3112 +		if (t->structure)
116.3113 +		{
116.3114 +			for (int i = 0; i < t->structure->memberCount; i++)
116.3115 +			{
116.3116 +				free(t->structure->members[i].location);
116.3117 +			}
116.3118 +			free(t->structure->members);
116.3119 +			free(t->structure);
116.3120 +		}
116.3121 +		break;
116.3122 +	case TYPE_enum:
116.3123 +		if (t->enumeration)
116.3124 +		{
116.3125 +			free(t->enumeration->members);
116.3126 +			free(t->enumeration);
116.3127 +		}
116.3128 +		break;
116.3129 +	case TYPE_base:
116.3130 +	case TYPE_pointer:
116.3131 +	case TYPE_void:
116.3132 +	case TYPE_reference:
116.3133 +		break; // nothing to do
116.3134 +	}
116.3135 +}
116.3136 +
116.3137 +void elfCleanUp(CompileUnit *comp)
116.3138 +{
116.3139 +	elfCleanUp(comp->abbrevs);
116.3140 +	free(comp->abbrevs);
116.3141 +	Function *func = comp->functions;
116.3142 +	while (func)
116.3143 +	{
116.3144 +		elfCleanUp(func);
116.3145 +		Function *next = func->next;
116.3146 +		free(func);
116.3147 +		func = next;
116.3148 +	}
116.3149 +	Type *t = comp->types;
116.3150 +	while (t)
116.3151 +	{
116.3152 +		elfCleanUp(t);
116.3153 +		Type *next = t->next;
116.3154 +		free(t);
116.3155 +		t = next;
116.3156 +	}
116.3157 +	Object *o = comp->variables;
116.3158 +	while (o)
116.3159 +	{
116.3160 +		elfCleanUp(o);
116.3161 +		Object *next = o->next;
116.3162 +		free(o);
116.3163 +		o = next;
116.3164 +	}
116.3165 +	if (comp->lineInfoTable)
116.3166 +	{
116.3167 +		free(comp->lineInfoTable->lines);
116.3168 +		free(comp->lineInfoTable->files);
116.3169 +		free(comp->lineInfoTable);
116.3170 +	}
116.3171 +}
116.3172 +
116.3173 +void elfCleanUp()
116.3174 +{
116.3175 +	CompileUnit *comp = elfCompileUnits;
116.3176 +
116.3177 +	while (comp)
116.3178 +	{
116.3179 +		elfCleanUp(comp);
116.3180 +		CompileUnit *next = comp->next;
116.3181 +		free(comp);
116.3182 +		comp = next;
116.3183 +	}
116.3184 +	elfCompileUnits = NULL;
116.3185 +	free(elfSymbols);
116.3186 +	elfSymbols = NULL;
116.3187 +	//  free(elfSymbolsStrTab);
116.3188 +	elfSymbolsStrTab = NULL;
116.3189 +
116.3190 +	elfDebugStrings = NULL;
116.3191 +	if (elfDebugInfo)
116.3192 +	{
116.3193 +		int num = elfDebugInfo->numRanges;
116.3194 +		int i;
116.3195 +		for (i = 0; i < num; i++)
116.3196 +		{
116.3197 +			free(elfDebugInfo->ranges[i].ranges);
116.3198 +		}
116.3199 +		free(elfDebugInfo->ranges);
116.3200 +		free(elfDebugInfo);
116.3201 +		elfDebugInfo = NULL;
116.3202 +	}
116.3203 +
116.3204 +	if (elfFdes)
116.3205 +	{
116.3206 +		if (elfFdeCount)
116.3207 +		{
116.3208 +			for (int i = 0; i < elfFdeCount; i++)
116.3209 +				free(elfFdes[i]);
116.3210 +		}
116.3211 +		free(elfFdes);
116.3212 +
116.3213 +		elfFdes     = NULL;
116.3214 +		elfFdeCount = 0;
116.3215 +	}
116.3216 +
116.3217 +	ELFcie *cie = elfCies;
116.3218 +	while (cie)
116.3219 +	{
116.3220 +		ELFcie *next = cie->next;
116.3221 +		free(cie);
116.3222 +		cie = next;
116.3223 +	}
116.3224 +	elfCies = NULL;
116.3225 +
116.3226 +	if (elfFileData)
116.3227 +	{
116.3228 +		free(elfFileData);
116.3229 +		elfFileData = NULL;
116.3230 +	}
116.3231 +}
116.3232 +
   117.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   117.2 +++ b/src/gba/elf.h	Sat Mar 03 10:31:27 2012 -0600
   117.3 @@ -0,0 +1,296 @@
   117.4 +#ifndef VBA_ELF_H
   117.5 +#define VBA_ELF_H
   117.6 +
   117.7 +#if _MSC_VER > 1000
   117.8 +#pragma once
   117.9 +#endif // _MSC_VER > 1000
  117.10 +
  117.11 +enum LocationType
  117.12 +{
  117.13 +	LOCATION_register,
  117.14 +	LOCATION_memory,
  117.15 +	LOCATION_value
  117.16 +};
  117.17 +
  117.18 +#define DW_ATE_boolean       0x02
  117.19 +#define DW_ATE_signed        0x05
  117.20 +#define DW_ATE_unsigned      0x07
  117.21 +#define DW_ATE_unsigned_char 0x08
  117.22 +
  117.23 +struct ELFHeader
  117.24 +{
  117.25 +	u32 magic;
  117.26 +	u8  clazz;
  117.27 +	u8  data;
  117.28 +	u8  version;
  117.29 +	u8  pad[9];
  117.30 +	u16 e_type;
  117.31 +	u16 e_machine;
  117.32 +	u32 e_version;
  117.33 +	u32 e_entry;
  117.34 +	u32 e_phoff;
  117.35 +	u32 e_shoff;
  117.36 +	u32 e_flags;
  117.37 +	u16 e_ehsize;
  117.38 +	u16 e_phentsize;
  117.39 +	u16 e_phnum;
  117.40 +	u16 e_shentsize;
  117.41 +	u16 e_shnum;
  117.42 +	u16 e_shstrndx;
  117.43 +};
  117.44 +
  117.45 +struct ELFProgramHeader
  117.46 +{
  117.47 +	u32 type;
  117.48 +	u32 offset;
  117.49 +	u32 vaddr;
  117.50 +	u32 paddr;
  117.51 +	u32 filesz;
  117.52 +	u32 memsz;
  117.53 +	u32 flags;
  117.54 +	u32 align;
  117.55 +};
  117.56 +
  117.57 +struct ELFSectionHeader
  117.58 +{
  117.59 +	u32 name;
  117.60 +	u32 type;
  117.61 +	u32 flags;
  117.62 +	u32 addr;
  117.63 +	u32 offset;
  117.64 +	u32 size;
  117.65 +	u32 link;
  117.66 +	u32 info;
  117.67 +	u32 addralign;
  117.68 +	u32 entsize;
  117.69 +};
  117.70 +
  117.71 +struct ELFSymbol
  117.72 +{
  117.73 +	u32 name;
  117.74 +	u32 value;
  117.75 +	u32 size;
  117.76 +	u8  info;
  117.77 +	u8  other;
  117.78 +	u16 shndx;
  117.79 +};
  117.80 +
  117.81 +struct ELFBlock
  117.82 +{
  117.83 +	int length;
  117.84 +	u8 *data;
  117.85 +};
  117.86 +
  117.87 +struct ELFAttr
  117.88 +{
  117.89 +	u32 name;
  117.90 +	u32 form;
  117.91 +	union
  117.92 +	{
  117.93 +		u32       value;
  117.94 +		char *    string;
  117.95 +		u8 *      data;
  117.96 +		bool      flag;
  117.97 +		ELFBlock *block;
  117.98 +	};
  117.99 +};
 117.100 +
 117.101 +struct ELFAbbrev
 117.102 +{
 117.103 +	u32        number;
 117.104 +	u32        tag;
 117.105 +	bool       hasChildren;
 117.106 +	int        numAttrs;
 117.107 +	ELFAttr *  attrs;
 117.108 +	ELFAbbrev *next;
 117.109 +};
 117.110 +
 117.111 +enum TypeEnum
 117.112 +{
 117.113 +	TYPE_base,
 117.114 +	TYPE_pointer,
 117.115 +	TYPE_function,
 117.116 +	TYPE_void,
 117.117 +	TYPE_array,
 117.118 +	TYPE_struct,
 117.119 +	TYPE_reference,
 117.120 +	TYPE_enum,
 117.121 +	TYPE_union
 117.122 +};
 117.123 +
 117.124 +struct Type;
 117.125 +struct Object;
 117.126 +
 117.127 +struct FunctionType
 117.128 +{
 117.129 +	Type *  returnType;
 117.130 +	Object *args;
 117.131 +};
 117.132 +
 117.133 +struct Member
 117.134 +{
 117.135 +	char *    name;
 117.136 +	Type *    type;
 117.137 +	int       bitSize;
 117.138 +	int       bitOffset;
 117.139 +	int       byteSize;
 117.140 +	ELFBlock *location;
 117.141 +};
 117.142 +
 117.143 +struct Struct
 117.144 +{
 117.145 +	int     memberCount;
 117.146 +	Member *members;
 117.147 +};
 117.148 +
 117.149 +struct Array
 117.150 +{
 117.151 +	Type *type;
 117.152 +	int   maxBounds;
 117.153 +	int * bounds;
 117.154 +};
 117.155 +
 117.156 +struct EnumMember
 117.157 +{
 117.158 +	char *name;
 117.159 +	u32   value;
 117.160 +};
 117.161 +
 117.162 +struct Enum
 117.163 +{
 117.164 +	int         count;
 117.165 +	EnumMember *members;
 117.166 +};
 117.167 +
 117.168 +struct Type
 117.169 +{
 117.170 +	u32      offset;
 117.171 +	TypeEnum type;
 117.172 +	char *   name;
 117.173 +	int      encoding;
 117.174 +	int      size;
 117.175 +	int      bitSize;
 117.176 +	union
 117.177 +	{
 117.178 +		Type *        pointer;
 117.179 +		FunctionType *function;
 117.180 +		Array *       array;
 117.181 +		Struct *      structure;
 117.182 +		Enum *        enumeration;
 117.183 +	};
 117.184 +	Type *next;
 117.185 +};
 117.186 +
 117.187 +struct Object
 117.188 +{
 117.189 +	char *    name;
 117.190 +	int       file;
 117.191 +	int       line;
 117.192 +	bool      external;
 117.193 +	Type *    type;
 117.194 +	ELFBlock *location;
 117.195 +	u32       startScope;
 117.196 +	u32       endScope;
 117.197 +	Object *  next;
 117.198 +};
 117.199 +
 117.200 +struct Function
 117.201 +{
 117.202 +	char *    name;
 117.203 +	u32       lowPC;
 117.204 +	u32       highPC;
 117.205 +	int       file;
 117.206 +	int       line;
 117.207 +	bool      external;
 117.208 +	Type *    returnType;
 117.209 +	Object *  parameters;
 117.210 +	Object *  variables;
 117.211 +	ELFBlock *frameBase;
 117.212 +	Function *next;
 117.213 +};
 117.214 +
 117.215 +struct LineInfoItem
 117.216 +{
 117.217 +	u32   address;
 117.218 +	char *file;
 117.219 +	int   line;
 117.220 +};
 117.221 +
 117.222 +struct LineInfo
 117.223 +{
 117.224 +	int           fileCount;
 117.225 +	char **       files;
 117.226 +	int           number;
 117.227 +	LineInfoItem *lines;
 117.228 +};
 117.229 +
 117.230 +struct ARange
 117.231 +{
 117.232 +	u32 lowPC;
 117.233 +	u32 highPC;
 117.234 +};
 117.235 +
 117.236 +struct ARanges
 117.237 +{
 117.238 +	u32     offset;
 117.239 +	int     count;
 117.240 +	ARange *ranges;
 117.241 +};
 117.242 +
 117.243 +struct CompileUnit
 117.244 +{
 117.245 +	u32          length;
 117.246 +	u8 *         top;
 117.247 +	u32          offset;
 117.248 +	ELFAbbrev ** abbrevs;
 117.249 +	ARanges *    ranges;
 117.250 +	char *       name;
 117.251 +	char *       compdir;
 117.252 +	u32          lowPC;
 117.253 +	u32          highPC;
 117.254 +	bool         hasLineInfo;
 117.255 +	u32          lineInfo;
 117.256 +	LineInfo *   lineInfoTable;
 117.257 +	Function *   functions;
 117.258 +	Function *   lastFunction;
 117.259 +	Object *     variables;
 117.260 +	Type *       types;
 117.261 +	CompileUnit *next;
 117.262 +};
 117.263 +
 117.264 +struct DebugInfo
 117.265 +{
 117.266 +	u8 *     debugfile;
 117.267 +	u8 *     abbrevdata;
 117.268 +	u8 *     debugdata;
 117.269 +	u8 *     infodata;
 117.270 +	int      numRanges;
 117.271 +	ARanges *ranges;
 117.272 +};
 117.273 +
 117.274 +struct Symbol
 117.275 +{
 117.276 +	char *name;
 117.277 +	int   type;
 117.278 +	int   binding;
 117.279 +	u32   address;
 117.280 +	u32   value;
 117.281 +	u32   size;
 117.282 +};
 117.283 +
 117.284 +extern u32 elfReadLEB128(u8 *, int *);
 117.285 +extern s32 elfReadSignedLEB128(u8 *, int *);
 117.286 +extern bool elfRead(const char *, int &, FILE *f);
 117.287 +extern bool elfGetSymbolAddress(char *, u32 *, u32 *, int *);
 117.288 +extern char *elfGetAddressSymbol(u32);
 117.289 +extern char *elfGetSymbol(int, u32 *, u32 *, int *);
 117.290 +extern void elfCleanUp();
 117.291 +extern bool elfGetCurrentFunction(u32, Function **, CompileUnit **c);
 117.292 +extern bool elfGetObject(char *, Function *, CompileUnit *, Object * *);
 117.293 +extern bool elfFindLineInUnit(u32 *, CompileUnit *, int);
 117.294 +extern bool elfFindLineInModule(u32 *, char *, int);
 117.295 +u32 elfDecodeLocation(Function *, ELFBlock *, LocationType *);
 117.296 +u32 elfDecodeLocation(Function *, ELFBlock *, LocationType *, u32);
 117.297 +int elfFindLine(CompileUnit *unit, Function *func, u32 addr, char * *);
 117.298 +
 117.299 +#endif // VBA_ELF_H
   118.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   118.2 +++ b/src/gba/remote.cpp	Sat Mar 03 10:31:27 2012 -0600
   118.3 @@ -0,0 +1,712 @@
   118.4 +#include <cstdlib>
   118.5 +#include <cstdio>
   118.6 +#include <cstring>
   118.7 +
   118.8 +#ifndef WIN32
   118.9 +# include <unistd.h>
  118.10 +# include <sys/socket.h>
  118.11 +# include <netdb.h>
  118.12 +# ifdef HAVE_NETINET_IN_H
  118.13 +#  include <netinet/in.h>
  118.14 +# endif // HAVE_NETINET_IN_H
  118.15 +# ifdef HAVE_ARPA_INET_H
  118.16 +#  include <arpa/inet.h>
  118.17 +# else // ! HAVE_ARPA_INET_H
  118.18 +#  define socklen_t int
  118.19 +# endif // ! HAVE_ARPA_INET_H
  118.20 +#else // WIN32
  118.21 +# include "../win32/stdafx.h"
  118.22 +# include <winsock.h>
  118.23 +# include <io.h>
  118.24 +# define socklen_t int
  118.25 +# define close closesocket
  118.26 +# define read _read
  118.27 +# define write _write
  118.28 +#endif // WIN32
  118.29 +
  118.30 +#include "GBA.h"
  118.31 +#include "GBAGlobals.h"
  118.32 +
  118.33 +extern bool debugger;
  118.34 +extern void CPUUpdateCPSR();
  118.35 +#ifdef SDL
  118.36 +extern void (*dbgMain)();
  118.37 +extern void (*dbgSignal)(int, int);
  118.38 +extern void debuggerMain();
  118.39 +extern void debuggerSignal(int, int);
  118.40 +#endif
  118.41 +
  118.42 +int  remotePort         = 55555;
  118.43 +int  remoteSignal       = 5;
  118.44 +int  remoteSocket       = -1;
  118.45 +int  remoteListenSocket = -1;
  118.46 +bool remoteConnected    = false;
  118.47 +bool remoteResumed      = false;
  118.48 +
  118.49 +int  (*remoteSendFnc)(char *, int) = NULL;
  118.50 +int  (*remoteRecvFnc)(char *, int) = NULL;
  118.51 +bool (*remoteInitFnc)()    = NULL;
  118.52 +void (*remoteCleanUpFnc)() = NULL;
  118.53 +
  118.54 +#if (defined WIN32 && !defined SDL)
  118.55 +void remoteSetSockets(SOCKET l, SOCKET r)
  118.56 +{
  118.57 +	remoteSocket       = r;
  118.58 +	remoteListenSocket = l;
  118.59 +}
  118.60 +
  118.61 +#endif
  118.62 +
  118.63 +int remoteTcpSend(char *data, int len)
  118.64 +{
  118.65 +	return send(remoteSocket, data, len, 0);
  118.66 +}
  118.67 +
  118.68 +int remoteTcpRecv(char *data, int len)
  118.69 +{
  118.70 +	return recv(remoteSocket, data, len, 0);
  118.71 +}
  118.72 +
  118.73 +bool remoteTcpInit()
  118.74 +{
  118.75 +	if (remoteSocket == -1)
  118.76 +	{
  118.77 +#ifdef WIN32
  118.78 +		WSADATA wsaData;
  118.79 +		int     error = WSAStartup(MAKEWORD(1, 1), &wsaData);
  118.80 +#endif // WIN32
  118.81 +		int s = socket(PF_INET, SOCK_STREAM, 0);
  118.82 +
  118.83 +		remoteListenSocket = s;
  118.84 +
  118.85 +		if (s < 0)
  118.86 +		{
  118.87 +			fprintf(stderr, "Error opening socket\n");
  118.88 +			exit(-1);
  118.89 +		}
  118.90 +		int tmp = 1;
  118.91 +		setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp, sizeof(tmp));
  118.92 +
  118.93 +		//    char hostname[256];
  118.94 +		//    gethostname(hostname, 256);
  118.95 +
  118.96 +		//    hostent *ent = gethostbyname(hostname);
  118.97 +		//    unsigned long a = *((unsigned long *)ent->h_addr);
  118.98 +
  118.99 +		sockaddr_in addr;
 118.100 +		addr.sin_family      = AF_INET;
 118.101 +		addr.sin_port        = htons(remotePort);
 118.102 +		addr.sin_addr.s_addr = htonl(0);
 118.103 +		int count = 0;
 118.104 +		while (count < 3)
 118.105 +		{
 118.106 +			if (bind(s, (sockaddr *)&addr, sizeof(addr)))
 118.107 +			{
 118.108 +				addr.sin_port = htons(ntohs(addr.sin_port)+1);
 118.109 +			}
 118.110 +			else
 118.111 +				break;
 118.112 +		}
 118.113 +		if (count == 3)
 118.114 +		{
 118.115 +			fprintf(stderr, "Error binding \n");
 118.116 +			exit(-1);
 118.117 +		}
 118.118 +
 118.119 +		fprintf(stderr, "Listening for a connection at port %d\n",
 118.120 +		        ntohs(addr.sin_port));
 118.121 +
 118.122 +		if (listen(s, 1))
 118.123 +		{
 118.124 +			fprintf(stderr, "Error listening\n");
 118.125 +			exit(-1);
 118.126 +		}
 118.127 +		socklen_t len = sizeof(addr);
 118.128 +
 118.129 +#ifdef WIN32
 118.130 +		int flag = 0;
 118.131 +		ioctlsocket(s, FIONBIO, (unsigned long *)&flag);
 118.132 +#endif // WIN32
 118.133 +		int s2 = accept(s, (sockaddr *)&addr, &len);
 118.134 +		if (s2 > 0)
 118.135 +		{
 118.136 +			fprintf(stderr, "Got a connection from %s %d\n",
 118.137 +			        inet_ntoa((in_addr)addr.sin_addr),
 118.138 +			        ntohs(addr.sin_port));
 118.139 +		}
 118.140 +		else
 118.141 +		{
 118.142 +#ifdef WIN32
 118.143 +			int error = WSAGetLastError();
 118.144 +#endif // WIN32
 118.145 +		}
 118.146 +		char dummy;
 118.147 +		recv(s2, &dummy, 1, 0);
 118.148 +		if (dummy != '+')
 118.149 +		{
 118.150 +			fprintf(stderr, "ACK not received\n");
 118.151 +			exit(-1);
 118.152 +		}
 118.153 +		remoteSocket = s2;
 118.154 +		//    close(s);
 118.155 +	}
 118.156 +	return true;
 118.157 +}
 118.158 +
 118.159 +void remoteTcpCleanUp()
 118.160 +{
 118.161 +	if (remoteSocket > 0)
 118.162 +	{
 118.163 +		fprintf(stderr, "Closing remote socket\n");
 118.164 +		close(remoteSocket);
 118.165 +		remoteSocket = -1;
 118.166 +	}
 118.167 +	if (remoteListenSocket > 0)
 118.168 +	{
 118.169 +		fprintf(stderr, "Closing listen socket\n");
 118.170 +		close(remoteListenSocket);
 118.171 +		remoteListenSocket = -1;
 118.172 +	}
 118.173 +}
 118.174 +
 118.175 +int remotePipeSend(char *data, int len)
 118.176 +{
 118.177 +	int res = write(1, data, len);
 118.178 +	return res;
 118.179 +}
 118.180 +
 118.181 +int remotePipeRecv(char *data, int len)
 118.182 +{
 118.183 +	int res = read(0, data, len);
 118.184 +	return res;
 118.185 +}
 118.186 +
 118.187 +bool remotePipeInit()
 118.188 +{
 118.189 +	char dummy;
 118.190 +	read(0, &dummy, 1);
 118.191 +	if (dummy != '+')
 118.192 +	{
 118.193 +		fprintf(stderr, "ACK not received\n");
 118.194 +		exit(-1);
 118.195 +	}
 118.196 +
 118.197 +	return true;
 118.198 +}
 118.199 +
 118.200 +void remotePipeCleanUp()
 118.201 +{}
 118.202 +
 118.203 +void remoteSetPort(int port)
 118.204 +{
 118.205 +	remotePort = port;
 118.206 +}
 118.207 +
 118.208 +void remoteSetProtocol(int p)
 118.209 +{
 118.210 +	if (p == 0)
 118.211 +	{
 118.212 +		remoteSendFnc    = remoteTcpSend;
 118.213 +		remoteRecvFnc    = remoteTcpRecv;
 118.214 +		remoteInitFnc    = remoteTcpInit;
 118.215 +		remoteCleanUpFnc = remoteTcpCleanUp;
 118.216 +	}
 118.217 +	else
 118.218 +	{
 118.219 +		remoteSendFnc    = remotePipeSend;
 118.220 +		remoteRecvFnc    = remotePipeRecv;
 118.221 +		remoteInitFnc    = remotePipeInit;
 118.222 +		remoteCleanUpFnc = remotePipeCleanUp;
 118.223 +	}
 118.224 +}
 118.225 +
 118.226 +void remoteInit()
 118.227 +{
 118.228 +	if (remoteInitFnc)
 118.229 +		remoteInitFnc();
 118.230 +}
 118.231 +
 118.232 +void remotePutPacket(char *packet)
 118.233 +{
 118.234 +	char *hex = "0123456789abcdef";
 118.235 +	char  buffer[1024];
 118.236 +
 118.237 +	int count = strlen(packet);
 118.238 +
 118.239 +	unsigned char csum = 0;
 118.240 +
 118.241 +	char *p = buffer;
 118.242 +	*p++ = '$';
 118.243 +
 118.244 +	for (int i = 0; i < count; i++)
 118.245 +	{
 118.246 +		csum += packet[i];
 118.247 +		*p++  = packet[i];
 118.248 +	}
 118.249 +	*p++ = '#';
 118.250 +	*p++ = hex[csum>>4];
 118.251 +	*p++ = hex[csum & 15];
 118.252 +	*p++ = 0;
 118.253 +	//  printf("Sending %s\n", buffer);
 118.254 +	remoteSendFnc(buffer, count + 4);
 118.255 +
 118.256 +	char c = 0;
 118.257 +	remoteRecvFnc(&c, 1);
 118.258 +	/*
 118.259 +	   if(c == '+')
 118.260 +	   printf("ACK\n");
 118.261 +	   else if(c=='-')
 118.262 +	   printf("NACK\n");
 118.263 +	 */
 118.264 +}
 118.265 +
 118.266 +void remoteOutput(char *s, u32 addr)
 118.267 +{
 118.268 +	char buffer[16384];
 118.269 +
 118.270 +	char *d = buffer;
 118.271 +	*d++ = 'O';
 118.272 +
 118.273 +	if (s)
 118.274 +	{
 118.275 +		char c = *s++;
 118.276 +		while (c)
 118.277 +		{
 118.278 +			sprintf(d, "%02x", c);
 118.279 +			d += 2;
 118.280 +			c  = *s++;
 118.281 +		}
 118.282 +	}
 118.283 +	else
 118.284 +	{
 118.285 +		char c = debuggerReadByte(addr);
 118.286 +		addr++;
 118.287 +		while (c)
 118.288 +		{
 118.289 +			sprintf(d, "%02x", c);
 118.290 +			d += 2;
 118.291 +			c  = debuggerReadByte(addr);
 118.292 +			addr++;
 118.293 +		}
 118.294 +	}
 118.295 +	remotePutPacket(buffer);
 118.296 +	//  fprintf(stderr, "Output sent %s\n", buffer);
 118.297 +}
 118.298 +
 118.299 +void remoteSendSignal()
 118.300 +{
 118.301 +	char buffer[1024];
 118.302 +	sprintf(buffer, "S%02x", remoteSignal);
 118.303 +	remotePutPacket(buffer);
 118.304 +}
 118.305 +
 118.306 +void remoteSendStatus()
 118.307 +{
 118.308 +	char buffer[1024];
 118.309 +	sprintf(buffer, "T%02x", remoteSignal);
 118.310 +	char *s = buffer;
 118.311 +	s += 3;
 118.312 +	for (int i = 0; i < 15; i++)
 118.313 +	{
 118.314 +		u32 v = reg[i].I;
 118.315 +		sprintf(s, "%02x:%02x%02x%02x%02x;", i,
 118.316 +		        (v & 255),
 118.317 +		        (v >> 8) & 255,
 118.318 +		        (v >> 16) & 255,
 118.319 +		        (v >> 24) & 255);
 118.320 +		s += 12;
 118.321 +	}
 118.322 +	u32 v = armNextPC;
 118.323 +	sprintf(s, "0f:%02x%02x%02x%02x;", (v & 255),
 118.324 +	        (v >> 8) & 255,
 118.325 +	        (v >> 16) & 255,
 118.326 +	        (v >> 24) & 255);
 118.327 +	s += 12;
 118.328 +	CPUUpdateCPSR();
 118.329 +	v = reg[16].I;
 118.330 +	sprintf(s, "19:%02x%02x%02x%02x;", (v & 255),
 118.331 +	        (v >> 8) & 255,
 118.332 +	        (v >> 16) & 255,
 118.333 +	        (v >> 24) & 255);
 118.334 +	s += 12;
 118.335 +	*s = 0;
 118.336 +	//  printf("Sending %s\n", buffer);
 118.337 +	remotePutPacket(buffer);
 118.338 +}
 118.339 +
 118.340 +void remoteBinaryWrite(char *p)
 118.341 +{
 118.342 +	u32 address;
 118.343 +	int count;
 118.344 +	sscanf(p, "%x,%x:", &address, &count);
 118.345 +	//  printf("Binary write for %08x %d\n", address, count);
 118.346 +
 118.347 +	p = strchr(p, ':');
 118.348 +	p++;
 118.349 +	for (int i = 0; i < count; i++)
 118.350 +	{
 118.351 +		u8 b = *p++;
 118.352 +		switch (b)
 118.353 +		{
 118.354 +		case 0x7d:
 118.355 +			b = *p++;
 118.356 +			debuggerWriteByte(address, (b^0x20));
 118.357 +			address++;
 118.358 +			break;
 118.359 +		default:
 118.360 +			debuggerWriteByte(address, b);
 118.361 +			address++;
 118.362 +			break;
 118.363 +		}
 118.364 +	}
 118.365 +	//  printf("ROM is %08x\n", debuggerReadMemory(0x8000254));
 118.366 +	remotePutPacket("OK");
 118.367 +}
 118.368 +
 118.369 +void remoteMemoryWrite(char *p)
 118.370 +{
 118.371 +	u32 address;
 118.372 +	int count;
 118.373 +	sscanf(p, "%x,%x:", &address, &count);
 118.374 +	//  printf("Memory write for %08x %d\n", address, count);
 118.375 +
 118.376 +	p = strchr(p, ':');
 118.377 +	p++;
 118.378 +	for (int i = 0; i < count; i++)
 118.379 +	{
 118.380 +		u8   v = 0;
 118.381 +		char c = *p++;
 118.382 +		if (c <= '9')
 118.383 +			v = (c - '0') << 4;
 118.384 +		else
 118.385 +			v = (c + 10 - 'a') << 4;
 118.386 +		c = *p++;
 118.387 +		if (c <= '9')
 118.388 +			v += (c - '0');
 118.389 +		else
 118.390 +			v += (c + 10 - 'a');
 118.391 +		debuggerWriteByte(address, v);
 118.392 +		address++;
 118.393 +	}
 118.394 +	//  printf("ROM is %08x\n", debuggerReadMemory(0x8000254));
 118.395 +	remotePutPacket("OK");
 118.396 +}
 118.397 +
 118.398 +void remoteMemoryRead(char *p)
 118.399 +{
 118.400 +	u32 address;
 118.401 +	int count;
 118.402 +	sscanf(p, "%x,%x:", &address, &count);
 118.403 +	//  printf("Memory read for %08x %d\n", address, count);
 118.404 +
 118.405 +	char buffer[1024];
 118.406 +
 118.407 +	char *s = buffer;
 118.408 +	for (int i = 0; i < count; i++)
 118.409 +	{
 118.410 +		u8 b = debuggerReadByte(address);
 118.411 +		sprintf(s, "%02x", b);
 118.412 +		address++;
 118.413 +		s += 2;
 118.414 +	}
 118.415 +	*s = 0;
 118.416 +	remotePutPacket(buffer);
 118.417 +}
 118.418 +
 118.419 +void remoteStepOverRange(char *p)
 118.420 +{
 118.421 +	u32 address;
 118.422 +	u32 final;
 118.423 +	sscanf(p, "%x,%x", &address, &final);
 118.424 +
 118.425 +	remotePutPacket("OK");
 118.426 +
 118.427 +	remoteResumed = true;
 118.428 +	do
 118.429 +	{
 118.430 +		CPULoop(1);
 118.431 +		if (debugger)
 118.432 +			break;
 118.433 +	}
 118.434 +	while (armNextPC >= address && armNextPC < final);
 118.435 +
 118.436 +	remoteResumed = false;
 118.437 +
 118.438 +	remoteSendStatus();
 118.439 +}
 118.440 +
 118.441 +void remoteWriteWatch(char *p, bool active)
 118.442 +{
 118.443 +	u32 address;
 118.444 +	int count;
 118.445 +	sscanf(p, ",%x,%x#", &address, &count);
 118.446 +
 118.447 +	fprintf(stderr, "Write watch for %08x %d\n", address, count);
 118.448 +
 118.449 +	if (address < 0x2000000 || address > 0x3007fff)
 118.450 +	{
 118.451 +		remotePutPacket("E01");
 118.452 +		return;
 118.453 +	}
 118.454 +
 118.455 +	if (address > 0x203ffff && address < 0x3000000)
 118.456 +	{
 118.457 +		remotePutPacket("E01");
 118.458 +		return;
 118.459 +	}
 118.460 +
 118.461 +	u32 final = address + count;
 118.462 +
 118.463 +	if (address < 0x2040000 && final > 0x2040000)
 118.464 +	{
 118.465 +		remotePutPacket("E01");
 118.466 +		return;
 118.467 +	}
 118.468 +	else if (address < 0x3008000 && final > 0x3008000)
 118.469 +	{
 118.470 +		remotePutPacket("E01");
 118.471 +		return;
 118.472 +	}
 118.473 +
 118.474 +	for (int i = 0; i < count; i++)
 118.475 +	{
 118.476 +		if ((address >> 24) == 2)
 118.477 +			freezeWorkRAM[address & 0x3ffff] = active;
 118.478 +		else
 118.479 +			freezeInternalRAM[address & 0x7fff] = active;
 118.480 +		address++;
 118.481 +	}
 118.482 +
 118.483 +	remotePutPacket("OK");
 118.484 +}
 118.485 +
 118.486 +void remoteReadRegisters(char *p)
 118.487 +{
 118.488 +	char buffer[1024];
 118.489 +
 118.490 +	char *s = buffer;
 118.491 +	int   i;
 118.492 +	// regular registers
 118.493 +	for (i = 0; i < 15; i++)
 118.494 +	{
 118.495 +		u32 v = reg[i].I;
 118.496 +		sprintf(s, "%02x%02x%02x%02x",  v & 255, (v >> 8) & 255,
 118.497 +		        (v >> 16) & 255, (v >> 24) & 255);
 118.498 +		s += 8;
 118.499 +	}
 118.500 +	// PC
 118.501 +	u32 pc = armNextPC;
 118.502 +	sprintf(s, "%02x%02x%02x%02x", pc & 255, (pc >> 8) & 255,
 118.503 +	        (pc >> 16) & 255, (pc >> 24) & 255);
 118.504 +	s += 8;
 118.505 +
 118.506 +	// floating point registers (24-bit)
 118.507 +	for (i = 0; i < 8; i++)
 118.508 +	{
 118.509 +		sprintf(s, "000000000000000000000000");
 118.510 +		s += 24;
 118.511 +	}
 118.512 +
 118.513 +	// FP status register
 118.514 +	sprintf(s, "00000000");
 118.515 +	s += 8;
 118.516 +	// CPSR
 118.517 +	CPUUpdateCPSR();
 118.518 +	u32 v = reg[16].I;
 118.519 +	sprintf(s, "%02x%02x%02x%02x",  v & 255, (v >> 8) & 255,
 118.520 +	        (v >> 16) & 255, (v >> 24) & 255);
 118.521 +	s += 8;
 118.522 +	*s = 0;
 118.523 +	remotePutPacket(buffer);
 118.524 +}
 118.525 +
 118.526 +void remoteWriteRegister(char *p)
 118.527 +{
 118.528 +	int r;
 118.529 +
 118.530 +	sscanf(p, "%x=", &r);
 118.531 +
 118.532 +	p = strchr(p, '=');
 118.533 +	p++;
 118.534 +
 118.535 +	char c = *p++;
 118.536 +
 118.537 +	u32 v = 0;
 118.538 +
 118.539 +	u8 data[4] = {0, 0, 0, 0};
 118.540 +
 118.541 +	int i = 0;
 118.542 +
 118.543 +	while (c != '#')
 118.544 +	{
 118.545 +		u8 b = 0;
 118.546 +		if (c <= '9')
 118.547 +			b = (c - '0') << 4;
 118.548 +		else
 118.549 +			b = (c + 10 - 'a') << 4;
 118.550 +		c = *p++;
 118.551 +		if (c <= '9')
 118.552 +			b += (c - '0');
 118.553 +		else
 118.554 +			b += (c + 10 - 'a');
 118.555 +		data[i++] = b;
 118.556 +		c         = *p++;
 118.557 +	}
 118.558 +
 118.559 +	v = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
 118.560 +
 118.561 +	//  printf("Write register %d=%08x\n", r, v);
 118.562 +	reg[r].I = v;
 118.563 +	if (r == 15)
 118.564 +	{
 118.565 +		armNextPC = v;
 118.566 +		if (armState)
 118.567 +			reg[15].I = v + 4;
 118.568 +		else
 118.569 +			reg[15].I = v + 2;
 118.570 +	}
 118.571 +	remotePutPacket("OK");
 118.572 +}
 118.573 +
 118.574 +void remoteStubMain()
 118.575 +{
 118.576 +	if (!debugger)
 118.577 +		return;
 118.578 +
 118.579 +	if (remoteResumed)
 118.580 +	{
 118.581 +		remoteSendStatus();
 118.582 +		remoteResumed = false;
 118.583 +	}
 118.584 +
 118.585 +	while (true)
 118.586 +	{
 118.587 +		char buffer[1024];
 118.588 +		int  res = remoteRecvFnc(buffer, 1024);
 118.589 +
 118.590 +		if (res == -1)
 118.591 +		{
 118.592 +			fprintf(stderr, "GDB connection lost\n");
 118.593 +#ifdef SDL
 118.594 +			dbgMain   = debuggerMain;
 118.595 +			dbgSignal = debuggerSignal;
 118.596 +#endif
 118.597 +			debugger = false;
 118.598 +			break;
 118.599 +		}
 118.600 +
 118.601 +		//    fprintf(stderr, "Received %s\n", buffer);
 118.602 +		char *p  = buffer;
 118.603 +		char  c  = *p++;
 118.604 +		char  pp = '+';
 118.605 +		remoteSendFnc(&pp, 1);
 118.606 +
 118.607 +		if (c != '$')
 118.608 +			continue;
 118.609 +		c = *p++;
 118.610 +		switch (c)
 118.611 +		{
 118.612 +		case '?':
 118.613 +			remoteSendSignal();
 118.614 +			break;
 118.615 +		case 'D':
 118.616 +			remotePutPacket("OK");
 118.617 +#ifdef SDL
 118.618 +			dbgMain   = debuggerMain;
 118.619 +			dbgSignal = debuggerSignal;
 118.620 +#endif
 118.621 +			remoteResumed = true;
 118.622 +			debugger      = false;
 118.623 +			return;
 118.624 +		case 'e':
 118.625 +			remoteStepOverRange(p);
 118.626 +			break;
 118.627 +		case 'k':
 118.628 +			remotePutPacket("OK");
 118.629 +#ifdef SDL
 118.630 +			dbgMain   = debuggerMain;
 118.631 +			dbgSignal = debuggerSignal;
 118.632 +#endif
 118.633 +			debugger  = false;
 118.634 +			emulating = false;
 118.635 +			return;
 118.636 +		case 'C':
 118.637 +			remoteResumed = true;
 118.638 +			debugger      = false;
 118.639 +			return;
 118.640 +		case 'c':
 118.641 +			remoteResumed = true;
 118.642 +			debugger      = false;
 118.643 +			return;
 118.644 +		case 's':
 118.645 +			remoteResumed = true;
 118.646 +			remoteSignal  = 5;
 118.647 +			CPULoop(1);
 118.648 +			if (remoteResumed)
 118.649 +			{
 118.650 +				remoteResumed = false;
 118.651 +				remoteSendStatus();
 118.652 +			}
 118.653 +			break;
 118.654 +		case 'g':
 118.655 +			remoteReadRegisters(p);
 118.656 +			break;
 118.657 +		case 'P':
 118.658 +			remoteWriteRegister(p);
 118.659 +			break;
 118.660 +		case 'M':
 118.661 +			remoteMemoryWrite(p);
 118.662 +			break;
 118.663 +		case 'm':
 118.664 +			remoteMemoryRead(p);
 118.665 +			break;
 118.666 +		case 'X':
 118.667 +			remoteBinaryWrite(p);
 118.668 +			break;
 118.669 +		case 'H':
 118.670 +			remotePutPacket("OK");
 118.671 +			break;
 118.672 +		case 'q':
 118.673 +			remotePutPacket("");
 118.674 +			break;
 118.675 +		case 'Z':
 118.676 +			if (*p++ == '2')
 118.677 +			{
 118.678 +				remoteWriteWatch(p, true);
 118.679 +			}
 118.680 +			else
 118.681 +				remotePutPacket("");
 118.682 +			break;
 118.683 +		case 'z':
 118.684 +			if (*p++ == '2')
 118.685 +			{
 118.686 +				remoteWriteWatch(p, false);
 118.687 +			}
 118.688 +			else
 118.689 +				remotePutPacket("");
 118.690 +			break;
 118.691 +		default:
 118.692 +		{
 118.693 +			*(strchr(p, '#') + 3) = 0;
 118.694 +			fprintf(stderr, "Unknown packet %s\n", --p);
 118.695 +			remotePutPacket("");
 118.696 +			break;
 118.697 +		}
 118.698 +		}
 118.699 +	}
 118.700 +}
 118.701 +
 118.702 +void remoteStubSignal(int sig, int number)
 118.703 +{
 118.704 +	remoteSignal  = sig;
 118.705 +	remoteResumed = false;
 118.706 +	remoteSendStatus();
 118.707 +	debugger = true;
 118.708 +}
 118.709 +
 118.710 +void remoteCleanUp()
 118.711 +{
 118.712 +	if (remoteCleanUpFnc)
 118.713 +		remoteCleanUpFnc();
 118.714 +}
 118.715 +
   119.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   119.2 +++ b/src/gba/thumb.h	Sat Mar 03 10:31:27 2012 -0600
   119.3 @@ -0,0 +1,2524 @@
   119.4 +#ifdef C_CORE
   119.5 +#define NEG(i) ((i) >> 31)
   119.6 +#define POS(i) ((~(i)) >> 31)
   119.7 +#define ADDCARRY(a, b, c) \
   119.8 +    C_FLAG = ((NEG(a) & NEG(b)) | \
   119.9 +              (NEG(a) & POS(c)) | \
  119.10 +              (NEG(b) & POS(c))) ? true : false;
  119.11 +#define ADDOVERFLOW(a, b, c) \
  119.12 +    V_FLAG = ((NEG(a) & NEG(b) & POS(c)) | \
  119.13 +              (POS(a) & POS(b) & NEG(c))) ? true : false;
  119.14 +#define SUBCARRY(a, b, c) \
  119.15 +    C_FLAG = ((NEG(a) & POS(b)) | \
  119.16 +              (NEG(a) & POS(c)) | \
  119.17 +              (POS(b) & POS(c))) ? true : false;
  119.18 +#define SUBOVERFLOW(a, b, c) \
  119.19 +    V_FLAG = ((NEG(a) & POS(b) & POS(c)) | \
  119.20 +              (POS(a) & NEG(b) & NEG(c))) ? true : false;
  119.21 +#define ADD_RD_RS_RN \
  119.22 +	{ \
  119.23 +		u32 lhs = reg[source].I; \
  119.24 +		u32 rhs = value; \
  119.25 +		u32 res = lhs + rhs; \
  119.26 +		reg[dest].I = res; \
  119.27 +		Z_FLAG		= (res == 0) ? true : false; \
  119.28 +		N_FLAG		= NEG(res) ? true : false; \
  119.29 +		ADDCARRY(lhs, rhs, res); \
  119.30 +		ADDOVERFLOW(lhs, rhs, res); \
  119.31 +	}
  119.32 +#define ADD_RD_RS_O3 \
  119.33 +	{ \
  119.34 +		u32 lhs = reg[source].I; \
  119.35 +		u32 rhs = value; \
  119.36 +		u32 res = lhs + rhs; \
  119.37 +		reg[dest].I = res; \
  119.38 +		Z_FLAG		= (res == 0) ? true : false; \
  119.39 +		N_FLAG		= NEG(res) ? true : false; \
  119.40 +		ADDCARRY(lhs, rhs, res); \
  119.41 +		ADDOVERFLOW(lhs, rhs, res); \
  119.42 +	}
  119.43 +#define ADD_RN_O8(d) \
  119.44 +	{ \
  119.45 +		u32 lhs = reg[(d)].I; \
  119.46 +		u32 rhs = (opcode & 255); \
  119.47 +		u32 res = lhs + rhs; \
  119.48 +		reg[(d)].I = res; \
  119.49 +		Z_FLAG	   = (res == 0) ? true : false; \
  119.50 +		N_FLAG	   = NEG(res) ? true : false; \
  119.51 +		ADDCARRY(lhs, rhs, res); \
  119.52 +		ADDOVERFLOW(lhs, rhs, res); \
  119.53 +	}
  119.54 +#define CMN_RD_RS \
  119.55 +	{ \
  119.56 +		u32 lhs = reg[dest].I; \
  119.57 +		u32 rhs = value; \
  119.58 +		u32 res = lhs + rhs; \
  119.59 +		Z_FLAG = (res == 0) ? true : false; \
  119.60 +		N_FLAG = NEG(res) ? true : false; \
  119.61 +		ADDCARRY(lhs, rhs, res); \
  119.62 +		ADDOVERFLOW(lhs, rhs, res); \
  119.63 +	}
  119.64 +#define ADC_RD_RS \
  119.65 +	{ \
  119.66 +		u32 lhs = reg[dest].I; \
  119.67 +		u32 rhs = value; \
  119.68 +		u32 res = lhs + rhs + (u32)C_FLAG; \
  119.69 +		reg[dest].I = res; \
  119.70 +		Z_FLAG		= (res == 0) ? true : false; \
  119.71 +		N_FLAG		= NEG(res) ? true : false; \
  119.72 +		ADDCARRY(lhs, rhs, res); \
  119.73 +		ADDOVERFLOW(lhs, rhs, res); \
  119.74 +	}
  119.75 +#define SUB_RD_RS_RN \
  119.76 +	{ \
  119.77 +		u32 lhs = reg[source].I; \
  119.78 +		u32 rhs = value; \
  119.79 +		u32 res = lhs - rhs; \
  119.80 +		reg[dest].I = res; \
  119.81 +		Z_FLAG		= (res == 0) ? true : false; \
  119.82 +		N_FLAG		= NEG(res) ? true : false; \
  119.83 +		SUBCARRY(lhs, rhs, res); \
  119.84 +		SUBOVERFLOW(lhs, rhs, res); \
  119.85 +	}
  119.86 +#define SUB_RD_RS_O3 \
  119.87 +	{ \
  119.88 +		u32 lhs = reg[source].I; \
  119.89 +		u32 rhs = value; \
  119.90 +		u32 res = lhs - rhs; \
  119.91 +		reg[dest].I = res; \
  119.92 +		Z_FLAG		= (res == 0) ? true : false; \
  119.93 +		N_FLAG		= NEG(res) ? true : false; \
  119.94 +		SUBCARRY(lhs, rhs, res); \
  119.95 +		SUBOVERFLOW(lhs, rhs, res); \
  119.96 +	}
  119.97 +#define SUB_RN_O8(d) \
  119.98 +	{ \
  119.99 +		u32 lhs = reg[(d)].I; \
 119.100 +		u32 rhs = (opcode & 255); \
 119.101 +		u32 res = lhs - rhs; \
 119.102 +		reg[(d)].I = res; \
 119.103 +		Z_FLAG	   = (res == 0) ? true : false; \
 119.104 +		N_FLAG	   = NEG(res) ? true : false; \
 119.105 +		SUBCARRY(lhs, rhs, res); \
 119.106 +		SUBOVERFLOW(lhs, rhs, res); \
 119.107 +	}
 119.108 +#define CMP_RN_O8(d) \
 119.109 +	{ \
 119.110 +		u32 lhs = reg[(d)].I; \
 119.111 +		u32 rhs = (opcode & 255); \
 119.112 +		u32 res = lhs - rhs; \
 119.113 +		Z_FLAG = (res == 0) ? true : false; \
 119.114 +		N_FLAG = NEG(res) ? true : false; \
 119.115 +		SUBCARRY(lhs, rhs, res); \
 119.116 +		SUBOVERFLOW(lhs, rhs, res); \
 119.117 +	}
 119.118 +#define SBC_RD_RS \
 119.119 +	{ \
 119.120 +		u32 lhs = reg[dest].I; \
 119.121 +		u32 rhs = value; \
 119.122 +		u32 res = lhs - rhs - !((u32)C_FLAG); \
 119.123 +		reg[dest].I = res; \
 119.124 +		Z_FLAG		= (res == 0) ? true : false; \
 119.125 +		N_FLAG		= NEG(res) ? true : false; \
 119.126 +		SUBCARRY(lhs, rhs, res); \
 119.127 +		SUBOVERFLOW(lhs, rhs, res); \
 119.128 +	}
 119.129 +#define LSL_RD_RM_I5 \
 119.130 +	{ \
 119.131 +		C_FLAG = (reg[source].I >> (32 - shift)) & 1 ? true : false; \
 119.132 +		value  = reg[source].I << shift; \
 119.133 +	}
 119.134 +#define LSL_RD_RS \
 119.135 +	{ \
 119.136 +		C_FLAG = (reg[dest].I >> (32 - value)) & 1 ? true : false; \
 119.137 +		value  = reg[dest].I << value; \
 119.138 +	}
 119.139 +#define LSR_RD_RM_I5 \
 119.140 +	{ \
 119.141 +		C_FLAG = (reg[source].I >> (shift - 1)) & 1 ? true : false; \
 119.142 +		value  = reg[source].I >> shift; \
 119.143 +	}
 119.144 +#define LSR_RD_RS \
 119.145 +	{ \
 119.146 +		C_FLAG = (reg[dest].I >> (value - 1)) & 1 ? true : false; \
 119.147 +		value  = reg[dest].I >> value; \
 119.148 +	}
 119.149 +#define ASR_RD_RM_I5 \
 119.150 +	{ \
 119.151 +		C_FLAG = ((s32)reg[source].I >> (int)(shift - 1)) & 1 ? true : false; \
 119.152 +		value  = (s32)reg[source].I >> (int)shift; \
 119.153 +	}
 119.154 +#define ASR_RD_RS \
 119.155 +	{ \
 119.156 +		C_FLAG = ((s32)reg[dest].I >> (int)(value - 1)) & 1 ? true : false; \
 119.157 +		value  = (s32)reg[dest].I >> (int)value; \
 119.158 +	}
 119.159 +#define ROR_RD_RS \
 119.160 +	{ \
 119.161 +		C_FLAG = (reg[dest].I >> (value - 1)) & 1 ? true : false; \
 119.162 +		value  = ((reg[dest].I << (32 - value)) | \
 119.163 +		          (reg[dest].I >> value)); \
 119.164 +	}
 119.165 +#define NEG_RD_RS \
 119.166 +	{ \
 119.167 +		u32 lhs = reg[source].I; \
 119.168 +		u32 rhs = 0; \
 119.169 +		u32 res = rhs - lhs; \
 119.170 +		reg[dest].I = res; \
 119.171 +		Z_FLAG		= (res == 0) ? true : false; \
 119.172 +		N_FLAG		= NEG(res) ? true : false; \
 119.173 +		SUBCARRY(rhs, lhs, res); \
 119.174 +		SUBOVERFLOW(rhs, lhs, res); \
 119.175 +	}
 119.176 +#define CMP_RD_RS \
 119.177 +	{ \
 119.178 +		u32 lhs = reg[dest].I; \
 119.179 +		u32 rhs = value; \
 119.180 +		u32 res = lhs - rhs; \
 119.181 +		Z_FLAG = (res == 0) ? true : false; \
 119.182 +		N_FLAG = NEG(res) ? true : false; \
 119.183 +		SUBCARRY(lhs, rhs, res); \
 119.184 +		SUBOVERFLOW(lhs, rhs, res); \
 119.185 +	}
 119.186 +#else
 119.187 +#ifdef __GNUC__
 119.188 +#ifdef __POWERPC__
 119.189 +			#define ADD_RD_RS_RN \
 119.190 +	{                                       \
 119.191 +		register int Flags;                 \
 119.192 +		register int Result;                \
 119.193 +		asm volatile ("addco. %0, %2, %3\n"  \
 119.194 +		              "mcrxr cr1\n"           \
 119.195 +		              "mfcr %1\n"             \
 119.196 +					  : "=r" (Result),        \
 119.197 +		              "=r" (Flags)          \
 119.198 +					  : "r" (reg[source].I),  \
 119.199 +		              "r" (value)           \
 119.200 +		              );                      \
 119.201 +		reg[dest].I = Result;               \
 119.202 +		Z_FLAG		= (Flags >> 29) & 1;         \
 119.203 +		N_FLAG		= (Flags >> 31) & 1;         \
 119.204 +		C_FLAG		= (Flags >> 25) & 1;         \
 119.205 +		V_FLAG		= (Flags >> 26) & 1;         \
 119.206 +	}
 119.207 +			#define ADD_RD_RS_O3 ADD_RD_RS_RN
 119.208 +			#define ADD_RN_O8(d) \
 119.209 +	{ \
 119.210 +		register int Flags;                 \
 119.211 +		register int Result;                \
 119.212 +		asm volatile ("addco. %0, %2, %3\n"  \
 119.213 +		              "mcrxr cr1\n"           \
 119.214 +		              "mfcr %1\n"             \
 119.215 +					  : "=r" (Result),        \
 119.216 +		              "=r" (Flags)          \
 119.217 +					  : "r" (reg[(d)].I),     \
 119.218 +		              "r" (opcode & 255)    \
 119.219 +		              );                      \
 119.220 +		reg[(d)].I = Result;                \
 119.221 +		Z_FLAG	   = (Flags >> 29) & 1;         \
 119.222 +		N_FLAG	   = (Flags >> 31) & 1;         \
 119.223 +		C_FLAG	   = (Flags >> 25) & 1;         \
 119.224 +		V_FLAG	   = (Flags >> 26) & 1;         \
 119.225 +	}
 119.226 +			#define CMN_RD_RS \
 119.227 +	{ \
 119.228 +		register int Flags;                 \
 119.229 +		register int Result;                \
 119.230 +		asm volatile ("addco. %0, %2, %3\n"  \
 119.231 +		              "mcrxr cr1\n"           \
 119.232 +		              "mfcr %1\n"             \
 119.233 +					  : "=r" (Result),        \
 119.234 +		              "=r" (Flags)          \
 119.235 +					  : "r" (reg[dest].I),    \
 119.236 +		              "r" (value)           \
 119.237 +		              );                      \
 119.238 +		Z_FLAG = (Flags >> 29) & 1;         \
 119.239 +		N_FLAG = (Flags >> 31) & 1;         \
 119.240 +		C_FLAG = (Flags >> 25) & 1;         \
 119.241 +		V_FLAG = (Flags >> 26) & 1;         \
 119.242 +	}
 119.243 +			#define ADC_RD_RS \
 119.244 +	{ \
 119.245 +		register int Flags;                 \
 119.246 +		register int Result;                \
 119.247 +		asm volatile ("mtspr xer, %4\n"      \
 119.248 +		              "addeo. %0, %2, %3\n"  \
 119.249 +		              "mcrxr cr1\n"          \
 119.250 +		              "mfcr	%1\n"            \
 119.251 +					  : "=r" (Result),       \
 119.252 +		              "=r" (Flags)         \
 119.253 +					  : "r" (reg[dest].I),   \
 119.254 +		              "r" (value),         \
 119.255 +		              "r" (C_FLAG << 29)   \
 119.256 +		              );                     \
 119.257 +		reg[dest].I = Result;               \
 119.258 +		Z_FLAG		= (Flags >> 29) & 1;         \
 119.259 +		N_FLAG		= (Flags >> 31) & 1;         \
 119.260 +		C_FLAG		= (Flags >> 25) & 1;         \
 119.261 +		V_FLAG		= (Flags >> 26) & 1;         \
 119.262 +	}
 119.263 +			#define SUB_RD_RS_RN \
 119.264 +	{ \
 119.265 +		register int Flags;                 \
 119.266 +		register int Result;                \
 119.267 +		asm volatile ("subco. %0, %2, %3\n"  \
 119.268 +		              "mcrxr cr1\n"           \
 119.269 +		              "mfcr %1\n"             \
 119.270 +					  : "=r" (Result),        \
 119.271 +		              "=r" (Flags)          \
 119.272 +					  : "r" (reg[source].I),  \
 119.273 +		              "r" (value)           \
 119.274 +		              );                      \
 119.275 +		reg[dest].I = Result;               \
 119.276 +		Z_FLAG		= (Flags >> 29) & 1;         \
 119.277 +		N_FLAG		= (Flags >> 31) & 1;         \
 119.278 +		C_FLAG		= (Flags >> 25) & 1;         \
 119.279 +		V_FLAG		= (Flags >> 26) & 1;         \
 119.280 +	}
 119.281 +			#define SUB_RD_RS_O3 SUB_RD_RS_RN
 119.282 +			#define SUB_RN_O8(d) \
 119.283 +	{ \
 119.284 +		register int Flags;                 \
 119.285 +		register int Result;                \
 119.286 +		asm volatile ("subco. %0, %2, %3\n"  \
 119.287 +		              "mcrxr cr1\n"           \
 119.288 +		              "mfcr %1\n"             \
 119.289 +					  : "=r" (Result),        \
 119.290 +		              "=r" (Flags)          \
 119.291 +					  : "r" (reg[(d)].I),     \
 119.292 +		              "r" (opcode & 255)    \
 119.293 +		              );                      \
 119.294 +		reg[(d)].I = Result;                \
 119.295 +		Z_FLAG	   = (Flags >> 29) & 1;         \
 119.296 +		N_FLAG	   = (Flags >> 31) & 1;         \
 119.297 +		C_FLAG	   = (Flags >> 25) & 1;         \
 119.298 +		V_FLAG	   = (Flags >> 26) & 1;         \
 119.299 +	}
 119.300 +			#define CMP_RN_O8(d) \
 119.301 +	{ \
 119.302 +		register int Flags;                 \
 119.303 +		register int Result;                \
 119.304 +		asm volatile ("subco. %0, %2, %3\n"  \
 119.305 +		              "mcrxr cr1\n"           \
 119.306 +		              "mfcr %1\n"             \
 119.307 +					  : "=r" (Result),        \
 119.308 +		              "=r" (Flags)          \
 119.309 +					  : "r" (reg[(d)].I),     \
 119.310 +		              "r" (opcode & 255)    \
 119.311 +		              );                      \
 119.312 +		Z_FLAG = (Flags >> 29) & 1;         \
 119.313 +		N_FLAG = (Flags >> 31) & 1;         \
 119.314 +		C_FLAG = (Flags >> 25) & 1;         \
 119.315 +		V_FLAG = (Flags >> 26) & 1;         \
 119.316 +	}
 119.317 +			#define SBC_RD_RS \
 119.318 +	{ \
 119.319 +		register int Flags;                 \
 119.320 +		register int Result;                \
 119.321 +		asm volatile ("mtspr xer, %4\n"      \
 119.322 +		              "subfeo. %0, %3, %2\n" \
 119.323 +		              "mcrxr cr1\n"          \
 119.324 +		              "mfcr	%1\n"            \
 119.325 +					  : "=r" (Result),       \
 119.326 +		              "=r" (Flags)         \
 119.327 +					  : "r" (reg[dest].I),   \
 119.328 +		              "r" (value),         \
 119.329 +		              "r" (C_FLAG << 29)   \
 119.330 +		              );                     \
 119.331 +		reg[dest].I = Result;               \
 119.332 +		Z_FLAG		= (Flags >> 29) & 1;         \
 119.333 +		N_FLAG		= (Flags >> 31) & 1;         \
 119.334 +		C_FLAG		= (Flags >> 25) & 1;         \
 119.335 +		V_FLAG		= (Flags >> 26) & 1;         \
 119.336 +	}
 119.337 +			#define LSL_RD_RM_I5 \
 119.338 +	{ \
 119.339 +		C_FLAG = (reg[source].I >> (32 - shift)) & 1 ? true : false; \
 119.340 +		value  = reg[source].I << shift; \
 119.341 +	}
 119.342 +			#define LSL_RD_RS \
 119.343 +	{ \
 119.344 +		C_FLAG = (reg[dest].I >> (32 - value)) & 1 ? true : false; \
 119.345 +		value  = reg[dest].I << value; \
 119.346 +	}
 119.347 +			#define LSR_RD_RM_I5 \
 119.348 +	{ \
 119.349 +		C_FLAG = (reg[source].I >> (shift - 1)) & 1 ? true : false; \
 119.350 +		value  = reg[source].I >> shift; \
 119.351 +	}
 119.352 +			#define LSR_RD_RS \
 119.353 +	{ \
 119.354 +		C_FLAG = (reg[dest].I >> (value - 1)) & 1 ? true : false; \
 119.355 +		value  = reg[dest].I >> value; \
 119.356 +	}
 119.357 +			#define ASR_RD_RM_I5 \
 119.358 +	{ \
 119.359 +		C_FLAG = ((s32)reg[source].I >> (int)(shift - 1)) & 1 ? true : false; \
 119.360 +		value  = (s32)reg[source].I >> (int)shift; \
 119.361 +	}
 119.362 +			#define ASR_RD_RS \
 119.363 +	{ \
 119.364 +		C_FLAG = ((s32)reg[dest].I >> (int)(value - 1)) & 1 ? true : false; \
 119.365 +		value  = (s32)reg[dest].I >> (int)value; \
 119.366 +	}
 119.367 +			#define ROR_RD_RS \
 119.368 +	{ \
 119.369 +		C_FLAG = (reg[dest].I >> (value - 1)) & 1 ? true : false; \
 119.370 +		value  = ((reg[dest].I << (32 - value)) | \
 119.371 +		          (reg[dest].I >> value)); \
 119.372 +	}
 119.373 +			#define NEG_RD_RS \
 119.374 +	{ \
 119.375 +		register int Flags;                 \
 119.376 +		register int Result;                \
 119.377 +		asm volatile ("subfco. %0, %2, %3\n" \
 119.378 +		              "mcrxr cr1\n"           \
 119.379 +		              "mfcr %1\n"             \
 119.380 +					  : "=r" (Result),        \
 119.381 +		              "=r" (Flags)          \
 119.382 +					  : "r" (reg[source].I),  \
 119.383 +		              "r" (0)               \
 119.384 +		              );                      \
 119.385 +		reg[dest].I = Result;               \
 119.386 +		Z_FLAG		= (Flags >> 29) & 1;         \
 119.387 +		N_FLAG		= (Flags >> 31) & 1;         \
 119.388 +		C_FLAG		= (Flags >> 25) & 1;         \
 119.389 +		V_FLAG		= (Flags >> 26) & 1;         \
 119.390 +	}
 119.391 +			#define CMP_RD_RS \
 119.392 +	{ \
 119.393 +		register int Flags;                 \
 119.394 +		register int Result;                \
 119.395 +		asm volatile ("subco. %0, %2, %3\n"  \
 119.396 +		              "mcrxr cr1\n"           \
 119.397 +		              "mfcr %1\n"             \
 119.398 +					  : "=r" (Result),        \
 119.399 +		              "=r" (Flags)          \
 119.400 +					  : "r" (reg[dest].I),    \
 119.401 +		              "r" (value)           \
 119.402 +		              );                      \
 119.403 +		Z_FLAG = (Flags >> 29) & 1;         \
 119.404 +		N_FLAG = (Flags >> 31) & 1;         \
 119.405 +		C_FLAG = (Flags >> 25) & 1;         \
 119.406 +		V_FLAG = (Flags >> 26) & 1;         \
 119.407 +	}
 119.408 +#else
 119.409 +#define ADD_RD_RS_RN \
 119.410 +    asm ("add %1, %%ebx;" \
 119.411 +         "setsb N_FLAG;" \
 119.412 +         "setzb Z_FLAG;" \
 119.413 +         "setcb C_FLAG;" \
 119.414 +         "setob V_FLAG;" \
 119.415 +		 : "=b" (reg[dest].I) \
 119.416 +		 : "r" (value), "b" (reg[source].I));
 119.417 +#define ADD_RD_RS_O3 \
 119.418 +    asm ("add %1, %%ebx;" \
 119.419 +         "setsb N_FLAG;" \
 119.420 +         "setzb Z_FLAG;" \
 119.421 +         "setcb C_FLAG;" \
 119.422 +         "setob V_FLAG;" \
 119.423 +		 : "=b" (reg[dest].I) \
 119.424 +		 : "r" (value), "b" (reg[source].I));
 119.425 +#define ADD_RN_O8(d) \
 119.426 +    asm ("add %1, %%ebx;" \
 119.427 +         "setsb N_FLAG;" \
 119.428 +         "setzb Z_FLAG;" \
 119.429 +         "setcb C_FLAG;" \
 119.430 +         "setob V_FLAG;" \
 119.431 +		 : "=b" (reg[(d)].I) \
 119.432 +		 : "r" (opcode & 255), "b" (reg[(d)].I));
 119.433 +#define CMN_RD_RS \
 119.434 +    asm ("add %0, %1;" \
 119.435 +         "setsb N_FLAG;" \
 119.436 +         "setzb Z_FLAG;" \
 119.437 +         "setcb C_FLAG;" \
 119.438 +         "setob V_FLAG;" \
 119.439 +		 : \
 119.440 +		 : "r" (value), "r" (reg[dest].I) : "1");
 119.441 +#define ADC_RD_RS \
 119.442 +    asm ("bt $0, C_FLAG;" \
 119.443 +         "adc %1, %%ebx;" \
 119.444 +         "setsb N_FLAG;" \
 119.445 +         "setzb Z_FLAG;" \
 119.446 +         "setcb C_FLAG;" \
 119.447 +         "setob V_FLAG;" \
 119.448 +		 : "=b" (reg[dest].I) \
 119.449 +		 : "r" (value), "b" (reg[dest].I));
 119.450 +#define SUB_RD_RS_RN \
 119.451 +    asm ("sub %1, %%ebx;" \
 119.452 +         "setsb N_FLAG;" \
 119.453 +         "setzb Z_FLAG;" \
 119.454 +         "setncb C_FLAG;" \
 119.455 +         "setob V_FLAG;" \
 119.456 +		 : "=b" (reg[dest].I) \
 119.457 +		 : "r" (value), "b" (reg[source].I));
 119.458 +#define SUB_RD_RS_O3 \
 119.459 +    asm ("sub %1, %%ebx;" \
 119.460 +         "setsb N_FLAG;" \
 119.461 +         "setzb Z_FLAG;" \
 119.462 +         "setncb C_FLAG;" \
 119.463 +         "setob V_FLAG;" \
 119.464 +		 : "=b" (reg[dest].I) \
 119.465 +		 : "r" (value), "b" (reg[source].I));
 119.466 +#define SUB_RN_O8(d) \
 119.467 +    asm ("sub %1, %%ebx;" \
 119.468 +         "setsb N_FLAG;" \
 119.469 +         "setzb Z_FLAG;" \
 119.470 +         "setncb C_FLAG;" \
 119.471 +         "setob V_FLAG;" \
 119.472 +		 : "=b" (reg[(d)].I) \
 119.473 +		 : "r" (opcode & 255), "b" (reg[(d)].I));
 119.474 +#define CMP_RN_O8(d) \
 119.475 +    asm ("sub %0, %1;" \
 119.476 +         "setsb N_FLAG;" \
 119.477 +         "setzb Z_FLAG;" \
 119.478 +         "setncb C_FLAG;" \
 119.479 +         "setob V_FLAG;" \
 119.480 +		 : \
 119.481 +		 : "r" (opcode & 255), "r" (reg[(d)].I) : "1");
 119.482 +#define SBC_RD_RS \
 119.483 +    asm volatile ("bt $0, C_FLAG;" \
 119.484 +                  "cmc;" \
 119.485 +                  "sbb %1, %%ebx;" \
 119.486 +                  "setsb N_FLAG;" \
 119.487 +                  "setzb Z_FLAG;" \
 119.488 +                  "setncb C_FLAG;" \
 119.489 +                  "setob V_FLAG;" \
 119.490 +				  : "=b" (reg[dest].I) \
 119.491 +				  : "r" (value), "b" (reg[dest].I) : "cc", "memory");
 119.492 +#define LSL_RD_RM_I5 \
 119.493 +    asm ("shl %%cl, %%eax;" \
 119.494 +         "setcb C_FLAG;" \
 119.495 +		 : "=a" (value) \
 119.496 +		 : "a" (reg[source].I), "c" (shift));
 119.497 +#define LSL_RD_RS \
 119.498 +    asm ("shl %%cl, %%eax;" \
 119.499 +         "setcb C_FLAG;" \
 119.500 +		 : "=a" (value) \
 119.501 +		 : "a" (reg[dest].I), "c" (value));
 119.502 +#define LSR_RD_RM_I5 \
 119.503 +    asm ("shr %%cl, %%eax;" \
 119.504 +         "setcb C_FLAG;" \
 119.505 +		 : "=a" (value) \
 119.506 +		 : "a" (reg[source].I), "c" (shift));
 119.507 +#define LSR_RD_RS \
 119.508 +    asm ("shr %%cl, %%eax;" \
 119.509 +         "setcb C_FLAG;" \
 119.510 +		 : "=a" (value) \
 119.511 +		 : "a" (reg[dest].I), "c" (value));
 119.512 +#define ASR_RD_RM_I5 \
 119.513 +    asm ("sar %%cl, %%eax;" \
 119.514 +         "setcb C_FLAG;" \
 119.515 +		 : "=a" (value) \
 119.516 +		 : "a" (reg[source].I), "c" (shift));
 119.517 +#define ASR_RD_RS \
 119.518 +    asm ("sar %%cl, %%eax;" \
 119.519 +         "setcb C_FLAG;" \
 119.520 +		 : "=a" (value) \
 119.521 +		 : "a" (reg[dest].I), "c" (value));
 119.522 +#define ROR_RD_RS \
 119.523 +    asm ("ror %%cl, %%eax;" \
 119.524 +         "setcb C_FLAG;" \
 119.525 +		 : "=a" (value) \
 119.526 +		 : "a" (reg[dest].I), "c" (value));
 119.527 +#define NEG_RD_RS \
 119.528 +    asm ("neg %%ebx;" \
 119.529 +         "setsb N_FLAG;" \
 119.530 +         "setzb Z_FLAG;" \
 119.531 +         "setncb C_FLAG;" \
 119.532 +         "setob V_FLAG;" \
 119.533 +		 : "=b" (reg[dest].I) \
 119.534 +		 : "b" (reg[source].I));
 119.535 +#define CMP_RD_RS \
 119.536 +    asm ("sub %0, %1;" \
 119.537 +         "setsb N_FLAG;" \
 119.538 +         "setzb Z_FLAG;" \
 119.539 +         "setncb C_FLAG;" \
 119.540 +         "setob V_FLAG;" \
 119.541 +		 : \
 119.542 +		 : "r" (value), "r" (reg[dest].I) : "1");
 119.543 +#endif
 119.544 +#else
 119.545 +#define ADD_RD_RS_RN \
 119.546 +	{ \
 119.547 +		__asm mov eax, source \
 119.548 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * eax] \
 119.549 +		__asm add ebx, value \
 119.550 +		__asm mov eax, dest \
 119.551 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 119.552 +		__asm sets byte ptr N_FLAG \
 119.553 +		__asm setz byte ptr Z_FLAG \
 119.554 +		__asm setc byte ptr C_FLAG \
 119.555 +		__asm seto byte ptr V_FLAG \
 119.556 +	}
 119.557 +#define ADD_RD_RS_O3 \
 119.558 +	{ \
 119.559 +		__asm mov eax, source \
 119.560 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * eax] \
 119.561 +		__asm add ebx, value \
 119.562 +		__asm mov eax, dest \
 119.563 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 119.564 +		__asm sets byte ptr N_FLAG \
 119.565 +		__asm setz byte ptr Z_FLAG \
 119.566 +		__asm setc byte ptr C_FLAG \
 119.567 +		__asm seto byte ptr V_FLAG \
 119.568 +	}
 119.569 +#define ADD_RN_O8(d) \
 119.570 +	{ \
 119.571 +		__asm mov ebx, opcode \
 119.572 +		          __asm and ebx, 255 \
 119.573 +		__asm add dword ptr [OFFSET reg + 4 * (d)], ebx \
 119.574 +		__asm sets byte ptr N_FLAG \
 119.575 +		__asm setz byte ptr Z_FLAG \
 119.576 +		__asm setc byte ptr C_FLAG \
 119.577 +		__asm seto byte ptr V_FLAG \
 119.578 +	}
 119.579 +#define CMN_RD_RS \
 119.580 +	{ \
 119.581 +		__asm mov eax, dest \
 119.582 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * eax] \
 119.583 +		__asm add ebx, value \
 119.584 +		__asm sets byte ptr N_FLAG \
 119.585 +		__asm setz byte ptr Z_FLAG \
 119.586 +		__asm setc byte ptr C_FLAG \
 119.587 +		__asm seto byte ptr V_FLAG \
 119.588 +	}
 119.589 +#define ADC_RD_RS \
 119.590 +	{ \
 119.591 +		__asm mov ebx, dest \
 119.592 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * ebx] \
 119.593 +		__asm bt word ptr C_FLAG, 0 \
 119.594 +		__asm adc ebx, value \
 119.595 +		__asm mov eax, dest \
 119.596 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 119.597 +		__asm sets byte ptr N_FLAG \
 119.598 +		__asm setz byte ptr Z_FLAG \
 119.599 +		__asm setc byte ptr C_FLAG \
 119.600 +		__asm seto byte ptr V_FLAG \
 119.601 +	}
 119.602 +#define SUB_RD_RS_RN \
 119.603 +	{ \
 119.604 +		__asm mov eax, source \
 119.605 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * eax] \
 119.606 +		__asm sub ebx, value \
 119.607 +		__asm mov eax, dest \
 119.608 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 119.609 +		__asm sets byte ptr N_FLAG \
 119.610 +		__asm setz byte ptr Z_FLAG \
 119.611 +		__asm setnc byte ptr C_FLAG \
 119.612 +		__asm seto byte ptr V_FLAG \
 119.613 +	}
 119.614 +#define SUB_RD_RS_O3 \
 119.615 +	{ \
 119.616 +		__asm mov eax, source \
 119.617 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * eax] \
 119.618 +		__asm sub ebx, value \
 119.619 +		__asm mov eax, dest \
 119.620 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 119.621 +		__asm sets byte ptr N_FLAG \
 119.622 +		__asm setz byte ptr Z_FLAG \
 119.623 +		__asm setnc byte ptr C_FLAG \
 119.624 +		__asm seto byte ptr V_FLAG \
 119.625 +	}
 119.626 +#define SUB_RN_O8(d) \
 119.627 +	{ \
 119.628 +		__asm mov ebx, opcode \
 119.629 +		          __asm and ebx, 255 \
 119.630 +		__asm sub dword ptr [OFFSET reg + 4 * (d)], ebx \
 119.631 +		__asm sets byte ptr N_FLAG \
 119.632 +		__asm setz byte ptr Z_FLAG \
 119.633 +		__asm setnc byte ptr C_FLAG \
 119.634 +		__asm seto byte ptr V_FLAG \
 119.635 +	}
 119.636 +#define CMP_RN_O8(d) \
 119.637 +	{ \
 119.638 +		__asm mov eax, dword ptr [OFFSET reg + 4 * (d)] \
 119.639 +		__asm mov ebx, opcode \
 119.640 +		          __asm and ebx, 255 \
 119.641 +		__asm sub eax, ebx \
 119.642 +		__asm sets byte ptr N_FLAG \
 119.643 +		__asm setz byte ptr Z_FLAG \
 119.644 +		__asm setnc byte ptr C_FLAG \
 119.645 +		__asm seto byte ptr V_FLAG \
 119.646 +	}
 119.647 +#define SBC_RD_RS \
 119.648 +	{ \
 119.649 +		__asm mov ebx, dest \
 119.650 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * ebx] \
 119.651 +		__asm mov eax, value \
 119.652 +		__asm bt word ptr C_FLAG, 0 \
 119.653 +		__asm cmc \
 119.654 +		__asm sbb ebx, eax \
 119.655 +		__asm mov eax, dest \
 119.656 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 119.657 +		__asm sets byte ptr N_FLAG \
 119.658 +		__asm setz byte ptr Z_FLAG \
 119.659 +		__asm setnc byte ptr C_FLAG \
 119.660 +		__asm seto byte ptr V_FLAG \
 119.661 +	}
 119.662 +#define LSL_RD_RM_I5 \
 119.663 +	{ \
 119.664 +		__asm mov eax, source \
 119.665 +		__asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 119.666 +		__asm mov cl, byte ptr shift \
 119.667 +		__asm shl eax, cl \
 119.668 +		__asm mov value, eax \
 119.669 +		__asm setc byte ptr C_FLAG \
 119.670 +	}
 119.671 +#define LSL_RD_RS \
 119.672 +	{ \
 119.673 +		__asm mov eax, dest \
 119.674 +		__asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 119.675 +		__asm mov cl, byte ptr value \
 119.676 +		__asm shl eax, cl \
 119.677 +		__asm mov value, eax \
 119.678 +		__asm setc byte ptr C_FLAG \
 119.679 +	}
 119.680 +#define LSR_RD_RM_I5 \
 119.681 +	{ \
 119.682 +		__asm mov eax, source \
 119.683 +		__asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 119.684 +		__asm mov cl, byte ptr shift \
 119.685 +		__asm shr eax, cl \
 119.686 +		__asm mov value, eax \
 119.687 +		__asm setc byte ptr C_FLAG \
 119.688 +	}
 119.689 +#define LSR_RD_RS \
 119.690 +	{ \
 119.691 +		__asm mov eax, dest \
 119.692 +		__asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 119.693 +		__asm mov cl, byte ptr value \
 119.694 +		__asm shr eax, cl \
 119.695 +		__asm mov value, eax \
 119.696 +		__asm setc byte ptr C_FLAG \
 119.697 +	}
 119.698 +#define ASR_RD_RM_I5 \
 119.699 +	{ \
 119.700 +		__asm mov eax, source \
 119.701 +		__asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 119.702 +		__asm mov cl, byte ptr shift \
 119.703 +		__asm sar eax, cl \
 119.704 +		__asm mov value, eax \
 119.705 +		__asm setc byte ptr C_FLAG \
 119.706 +	}
 119.707 +#define ASR_RD_RS \
 119.708 +	{ \
 119.709 +		__asm mov eax, dest \
 119.710 +		__asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 119.711 +		__asm mov cl, byte ptr value \
 119.712 +		__asm sar eax, cl \
 119.713 +		__asm mov value, eax \
 119.714 +		__asm setc byte ptr C_FLAG \
 119.715 +	}
 119.716 +#define ROR_RD_RS \
 119.717 +	{ \
 119.718 +		__asm mov eax, dest \
 119.719 +		__asm mov eax, dword ptr [OFFSET reg + 4 * eax] \
 119.720 +		__asm mov cl, byte ptr value \
 119.721 +		__asm ror eax, cl \
 119.722 +		__asm mov value, eax \
 119.723 +		__asm setc byte ptr C_FLAG \
 119.724 +	}
 119.725 +#define NEG_RD_RS \
 119.726 +	{ \
 119.727 +		__asm mov ebx, source \
 119.728 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * ebx] \
 119.729 +		__asm neg ebx \
 119.730 +		__asm mov eax, dest \
 119.731 +		__asm mov dword ptr [OFFSET reg + 4 * eax], ebx \
 119.732 +		__asm sets byte ptr N_FLAG \
 119.733 +		__asm setz byte ptr Z_FLAG \
 119.734 +		__asm setnc byte ptr C_FLAG \
 119.735 +		__asm seto byte ptr V_FLAG \
 119.736 +	}
 119.737 +#define CMP_RD_RS \
 119.738 +	{ \
 119.739 +		__asm mov eax, dest \
 119.740 +		__asm mov ebx, dword ptr [OFFSET reg + 4 * eax] \
 119.741 +		__asm sub ebx, value \
 119.742 +		__asm sets byte ptr N_FLAG \
 119.743 +		__asm setz byte ptr Z_FLAG \
 119.744 +		__asm setnc byte ptr C_FLAG \
 119.745 +		__asm seto byte ptr V_FLAG \
 119.746 +	}
 119.747 +#endif
 119.748 +#endif
 119.749 +
 119.750 +u32 opcode = CPUReadHalfWordQuick(armNextPC);
 119.751 +clockTicks = thumbCycles[opcode >> 8] + memoryWaitFetch[(armNextPC >> 24) & 15];
 119.752 +#ifndef FINAL_VERSION
 119.753 +if (armNextPC == stop)
 119.754 +{
 119.755 +	armNextPC = armNextPC++;
 119.756 +}
 119.757 +#endif
 119.758 +
 119.759 +armNextPC  = reg[15].I;
 119.760 +reg[15].I += 2;
 119.761 +
 119.762 +switch (opcode >> 8)
 119.763 +{
 119.764 +case 0x00:
 119.765 +case 0x01:
 119.766 +case 0x02:
 119.767 +case 0x03:
 119.768 +case 0x04:
 119.769 +case 0x05:
 119.770 +case 0x06:
 119.771 +case 0x07:
 119.772 +{
 119.773 +	// LSL Rd, Rm, #Imm 5
 119.774 +	int dest   = opcode & 0x07;
 119.775 +	int source = (opcode >> 3) & 0x07;
 119.776 +	int shift  = (opcode >> 6) & 0x1f;
 119.777 +	u32 value;
 119.778 +
 119.779 +	if (shift)
 119.780 +	{
 119.781 +		LSL_RD_RM_I5;
 119.782 +	}
 119.783 +	else
 119.784 +	{
 119.785 +		value = reg[source].I;
 119.786 +	}
 119.787 +	reg[dest].I = value;
 119.788 +	// C_FLAG set above
 119.789 +	N_FLAG = (value & 0x80000000 ? true : false);
 119.790 +	Z_FLAG = (value ? false : true);
 119.791 +}
 119.792 +break;
 119.793 +case 0x08:
 119.794 +case 0x09:
 119.795 +case 0x0a:
 119.796 +case 0x0b:
 119.797 +case 0x0c:
 119.798 +case 0x0d:
 119.799 +case 0x0e:
 119.800 +case 0x0f:
 119.801 +{
 119.802 +	// LSR Rd, Rm, #Imm 5
 119.803 +	int dest   = opcode & 0x07;
 119.804 +	int source = (opcode >> 3) & 0x07;
 119.805 +	int shift  = (opcode >> 6) & 0x1f;
 119.806 +	u32 value;
 119.807 +
 119.808 +	if (shift)
 119.809 +	{
 119.810 +		LSR_RD_RM_I5;
 119.811 +	}
 119.812 +	else
 119.813 +	{
 119.814 +		C_FLAG = reg[source].I & 0x80000000 ? true : false;
 119.815 +		value  = 0;
 119.816 +	}
 119.817 +	reg[dest].I = value;
 119.818 +	// C_FLAG set above
 119.819 +	N_FLAG = (value & 0x80000000 ? true : false);
 119.820 +	Z_FLAG = (value ? false : true);
 119.821 +}
 119.822 +break;
 119.823 +case 0x10:
 119.824 +case 0x11:
 119.825 +case 0x12:
 119.826 +case 0x13:
 119.827 +case 0x14:
 119.828 +case 0x15:
 119.829 +case 0x16:
 119.830 +case 0x17:
 119.831 +{
 119.832 +	// ASR Rd, Rm, #Imm 5
 119.833 +	int dest   = opcode & 0x07;
 119.834 +	int source = (opcode >> 3) & 0x07;
 119.835 +	int shift  = (opcode >> 6) & 0x1f;
 119.836 +	u32 value;
 119.837 +
 119.838 +	if (shift)
 119.839 +	{
 119.840 +		ASR_RD_RM_I5;
 119.841 +	}
 119.842 +	else
 119.843 +	{
 119.844 +		if (reg[source].I & 0x80000000)
 119.845 +		{
 119.846 +			value  = 0xFFFFFFFF;
 119.847 +			C_FLAG = true;
 119.848 +		}
 119.849 +		else
 119.850 +		{
 119.851 +			value  = 0;
 119.852 +			C_FLAG = false;
 119.853 +		}
 119.854 +	}
 119.855 +	reg[dest].I = value;
 119.856 +	// C_FLAG set above
 119.857 +	N_FLAG = (value & 0x80000000 ? true : false);
 119.858 +	Z_FLAG = (value ? false : true);
 119.859 +}
 119.860 +break;
 119.861 +case 0x18:
 119.862 +case 0x19:
 119.863 +{
 119.864 +	// ADD Rd, Rs, Rn
 119.865 +	int dest   = opcode & 0x07;
 119.866 +	int source = (opcode >> 3) & 0x07;
 119.867 +	u32 value  = reg[(opcode >> 6) & 0x07].I;
 119.868 +	ADD_RD_RS_RN;
 119.869 +}
 119.870 +break;
 119.871 +case 0x1a:
 119.872 +case 0x1b:
 119.873 +{
 119.874 +	// SUB Rd, Rs, Rn
 119.875 +	int dest   = opcode & 0x07;
 119.876 +	int source = (opcode >> 3) & 0x07;
 119.877 +	u32 value  = reg[(opcode >> 6) & 0x07].I;
 119.878 +	SUB_RD_RS_RN;
 119.879 +}
 119.880 +break;
 119.881 +case 0x1c:
 119.882 +case 0x1d:
 119.883 +{
 119.884 +	// ADD Rd, Rs, #Offset3
 119.885 +	int dest   = opcode & 0x07;
 119.886 +	int source = (opcode >> 3) & 0x07;
 119.887 +	u32 value  = (opcode >> 6) & 7;
 119.888 +	ADD_RD_RS_O3;
 119.889 +}
 119.890 +break;
 119.891 +case 0x1e:
 119.892 +case 0x1f:
 119.893 +{
 119.894 +	// SUB Rd, Rs, #Offset3
 119.895 +	int dest   = opcode & 0x07;
 119.896 +	int source = (opcode >> 3) & 0x07;
 119.897 +	u32 value  = (opcode >> 6) & 7;
 119.898 +	SUB_RD_RS_O3;
 119.899 +}
 119.900 +break;
 119.901 +case 0x20:
 119.902 +	// MOV R0, #Offset8
 119.903 +	reg[0].I = opcode & 255;
 119.904 +	N_FLAG	 = false;
 119.905 +	Z_FLAG	 = (reg[0].I ? false : true);
 119.906 +	break;
 119.907 +case 0x21:
 119.908 +	// MOV R1, #Offset8
 119.909 +	reg[1].I = opcode & 255;
 119.910 +	N_FLAG	 = false;
 119.911 +	Z_FLAG	 = (reg[1].I ? false : true);
 119.912 +	break;
 119.913 +case 0x22:
 119.914 +	// MOV R2, #Offset8
 119.915 +	reg[2].I = opcode & 255;
 119.916 +	N_FLAG	 = false;
 119.917 +	Z_FLAG	 = (reg[2].I ? false : true);
 119.918 +	break;
 119.919 +case 0x23:
 119.920 +	// MOV R3, #Offset8
 119.921 +	reg[3].I = opcode & 255;
 119.922 +	N_FLAG	 = false;
 119.923 +	Z_FLAG	 = (reg[3].I ? false : true);
 119.924 +	break;
 119.925 +case 0x24:
 119.926 +	// MOV R4, #Offset8
 119.927 +	reg[4].I = opcode & 255;
 119.928 +	N_FLAG	 = false;
 119.929 +	Z_FLAG	 = (reg[4].I ? false : true);
 119.930 +	break;
 119.931 +case 0x25:
 119.932 +	// MOV R5, #Offset8
 119.933 +	reg[5].I = opcode & 255;
 119.934 +	N_FLAG	 = false;
 119.935 +	Z_FLAG	 = (reg[5].I ? false : true);
 119.936 +	break;
 119.937 +case 0x26:
 119.938 +	// MOV R6, #Offset8
 119.939 +	reg[6].I = opcode & 255;
 119.940 +	N_FLAG	 = false;
 119.941 +	Z_FLAG	 = (reg[6].I ? false : true);
 119.942 +	break;
 119.943 +case 0x27:
 119.944 +	// MOV R7, #Offset8
 119.945 +	reg[7].I = opcode & 255;
 119.946 +	N_FLAG	 = false;
 119.947 +	Z_FLAG	 = (reg[7].I ? false : true);
 119.948 +	break;
 119.949 +case 0x28:
 119.950 +	// CMP R0, #Offset8
 119.951 +	CMP_RN_O8(0);
 119.952 +	break;
 119.953 +case 0x29:
 119.954 +	// CMP R1, #Offset8
 119.955 +	CMP_RN_O8(1);
 119.956 +	break;
 119.957 +case 0x2a:
 119.958 +	// CMP R2, #Offset8
 119.959 +	CMP_RN_O8(2);
 119.960 +	break;
 119.961 +case 0x2b:
 119.962 +	// CMP R3, #Offset8
 119.963 +	CMP_RN_O8(3);
 119.964 +	break;
 119.965 +case 0x2c:
 119.966 +	// CMP R4, #Offset8
 119.967 +	CMP_RN_O8(4);
 119.968 +	break;
 119.969 +case 0x2d:
 119.970 +	// CMP R5, #Offset8
 119.971 +	CMP_RN_O8(5);
 119.972 +	break;
 119.973 +case 0x2e:
 119.974 +	// CMP R6, #Offset8
 119.975 +	CMP_RN_O8(6);
 119.976 +	break;
 119.977 +case 0x2f:
 119.978 +	// CMP R7, #Offset8
 119.979 +	CMP_RN_O8(7);
 119.980 +	break;
 119.981 +case 0x30:
 119.982 +	// ADD R0,#Offset8
 119.983 +	ADD_RN_O8(0);
 119.984 +	break;
 119.985 +case 0x31:
 119.986 +	// ADD R1,#Offset8
 119.987 +	ADD_RN_O8(1);
 119.988 +	break;
 119.989 +case 0x32:
 119.990 +	// ADD R2,#Offset8
 119.991 +	ADD_RN_O8(2);
 119.992 +	break;
 119.993 +case 0x33:
 119.994 +	// ADD R3,#Offset8
 119.995 +	ADD_RN_O8(3);
 119.996 +	break;
 119.997 +case 0x34:
 119.998 +	// ADD R4,#Offset8
 119.999 +	ADD_RN_O8(4);
119.1000 +	break;
119.1001 +case 0x35:
119.1002 +	// ADD R5,#Offset8
119.1003 +	ADD_RN_O8(5);
119.1004 +	break;
119.1005 +case 0x36:
119.1006 +	// ADD R6,#Offset8
119.1007 +	ADD_RN_O8(6);
119.1008 +	break;
119.1009 +case 0x37:
119.1010 +	// ADD R7,#Offset8
119.1011 +	ADD_RN_O8(7);
119.1012 +	break;
119.1013 +case 0x38:
119.1014 +	// SUB R0,#Offset8
119.1015 +	SUB_RN_O8(0);
119.1016 +	break;
119.1017 +case 0x39:
119.1018 +	// SUB R1,#Offset8
119.1019 +	SUB_RN_O8(1);
119.1020 +	break;
119.1021 +case 0x3a:
119.1022 +	// SUB R2,#Offset8
119.1023 +	SUB_RN_O8(2);
119.1024 +	break;
119.1025 +case 0x3b:
119.1026 +	// SUB R3,#Offset8
119.1027 +	SUB_RN_O8(3);
119.1028 +	break;
119.1029 +case 0x3c:
119.1030 +	// SUB R4,#Offset8
119.1031 +	SUB_RN_O8(4);
119.1032 +	break;
119.1033 +case 0x3d:
119.1034 +	// SUB R5,#Offset8
119.1035 +	SUB_RN_O8(5);
119.1036 +	break;
119.1037 +case 0x3e:
119.1038 +	// SUB R6,#Offset8
119.1039 +	SUB_RN_O8(6);
119.1040 +	break;
119.1041 +case 0x3f:
119.1042 +	// SUB R7,#Offset8
119.1043 +	SUB_RN_O8(7);
119.1044 +	break;
119.1045 +case 0x40:
119.1046 +	switch ((opcode >> 6) & 3)
119.1047 +	{
119.1048 +	case 0x00:
119.1049 +	{
119.1050 +		// AND Rd, Rs
119.1051 +		int dest = opcode & 7;
119.1052 +		reg[dest].I &= reg[(opcode >> 3) & 7].I;
119.1053 +		N_FLAG		 = reg[dest].I & 0x80000000 ? true : false;
119.1054 +		Z_FLAG		 = reg[dest].I ? false : true;
119.1055 +#ifdef BKPT_SUPPORT
119.1056 +#define THUMB_CONSOLE_OUTPUT(a, b) \
119.1057 +	if ((opcode == 0x4000) && (reg[0].I == 0xC0DED00D)) { \
119.1058 +		extern void (*dbgOutput)(char *, u32); \
119.1059 +		dbgOutput((a), (b)); \
119.1060 +	}
119.1061 +#else
119.1062 +#define THUMB_CONSOLE_OUTPUT(a, b)
119.1063 +#endif
119.1064 +		THUMB_CONSOLE_OUTPUT(NULL, reg[2].I);
119.1065 +	}
119.1066 +	break;
119.1067 +	case 0x01:
119.1068 +		// EOR Rd, Rs
119.1069 +	{
119.1070 +		int dest = opcode & 7;
119.1071 +		reg[dest].I ^= reg[(opcode >> 3) & 7].I;
119.1072 +		N_FLAG		 = reg[dest].I & 0x80000000 ? true : false;
119.1073 +		Z_FLAG		 = reg[dest].I ? false : true;
119.1074 +	}
119.1075 +	break;
119.1076 +	case 0x02:
119.1077 +		// LSL Rd, Rs
119.1078 +	{
119.1079 +		int dest  = opcode & 7;
119.1080 +		u32 value = reg[(opcode >> 3) & 7].B.B0;
119.1081 +		if (value)
119.1082 +		{
119.1083 +			if (value == 32)
119.1084 +			{
119.1085 +				value  = 0;
119.1086 +				C_FLAG = (reg[dest].I & 1 ? true : false);
119.1087 +			}
119.1088 +			else if (value < 32)
119.1089 +			{
119.1090 +				LSL_RD_RS;
119.1091 +			}
119.1092 +			else
119.1093 +			{
119.1094 +				value  = 0;
119.1095 +				C_FLAG = false;
119.1096 +			}
119.1097 +			reg[dest].I = value;
119.1098 +		}
119.1099 +		N_FLAG = reg[dest].I & 0x80000000 ? true : false;
119.1100 +		Z_FLAG = reg[dest].I ? false : true;
119.1101 +		clockTicks++;
119.1102 +	}
119.1103 +	break;
119.1104 +	case 0x03:
119.1105 +	{
119.1106 +		// LSR Rd, Rs
119.1107 +		int dest  = opcode & 7;
119.1108 +		u32 value = reg[(opcode >> 3) & 7].B.B0;
119.1109 +		if (value)
119.1110 +		{
119.1111 +			if (value == 32)
119.1112 +			{
119.1113 +				value  = 0;
119.1114 +				C_FLAG = (reg[dest].I & 0x80000000 ? true : false);
119.1115 +			}
119.1116 +			else if (value < 32)
119.1117 +			{
119.1118 +				LSR_RD_RS;
119.1119 +			}
119.1120 +			else
119.1121 +			{
119.1122 +				value  = 0;
119.1123 +				C_FLAG = false;
119.1124 +			}
119.1125 +			reg[dest].I = value;
119.1126 +		}
119.1127 +		N_FLAG = reg[dest].I & 0x80000000 ? true : false;
119.1128 +		Z_FLAG = reg[dest].I ? false : true;
119.1129 +		clockTicks++;
119.1130 +	}
119.1131 +	break;
119.1132 +	}
119.1133 +	break;
119.1134 +case 0x41:
119.1135 +	switch ((opcode >> 6) & 3)
119.1136 +	{
119.1137 +	case 0x00:
119.1138 +	{
119.1139 +		// ASR Rd, Rs
119.1140 +		int dest  = opcode & 7;
119.1141 +		u32 value = reg[(opcode >> 3) & 7].B.B0;
119.1142 +		// ASR
119.1143 +		if (value)
119.1144 +		{
119.1145 +			if (value < 32)
119.1146 +			{
119.1147 +				ASR_RD_RS;
119.1148 +				reg[dest].I = value;
119.1149 +			}
119.1150 +			else
119.1151 +			{
119.1152 +				if (reg[dest].I & 0x80000000)
119.1153 +				{
119.1154 +					reg[dest].I = 0xFFFFFFFF;
119.1155 +					C_FLAG		= true;
119.1156 +				}
119.1157 +				else
119.1158 +				{
119.1159 +					reg[dest].I = 0x00000000;
119.1160 +					C_FLAG		= false;
119.1161 +				}
119.1162 +			}
119.1163 +		}
119.1164 +		N_FLAG = reg[dest].I & 0x80000000 ? true : false;
119.1165 +		Z_FLAG = reg[dest].I ? false : true;
119.1166 +		clockTicks++;
119.1167 +	}
119.1168 +	break;
119.1169 +	case 0x01:
119.1170 +	{
119.1171 +		// ADC Rd, Rs
119.1172 +		int dest  = opcode & 0x07;
119.1173 +		u32 value = reg[(opcode >> 3) & 7].I;
119.1174 +		// ADC
119.1175 +		ADC_RD_RS;
119.1176 +	}
119.1177 +	break;
119.1178 +	case 0x02:
119.1179 +	{
119.1180 +		// SBC Rd, Rs
119.1181 +		int dest  = opcode & 0x07;
119.1182 +		u32 value = reg[(opcode >> 3) & 7].I;
119.1183 +
119.1184 +		// SBC
119.1185 +		SBC_RD_RS;
119.1186 +	}
119.1187 +	break;
119.1188 +	case 0x03:
119.1189 +		// ROR Rd, Rs
119.1190 +	{
119.1191 +		int dest  = opcode & 7;
119.1192 +		u32 value = reg[(opcode >> 3) & 7].B.B0;
119.1193 +
119.1194 +		if (value)
119.1195 +		{
119.1196 +			value = value & 0x1f;
119.1197 +			if (value == 0)
119.1198 +			{
119.1199 +				C_FLAG = (reg[dest].I & 0x80000000 ? true : false);
119.1200 +			}
119.1201 +			else
119.1202 +			{
119.1203 +				ROR_RD_RS;
119.1204 +				reg[dest].I = value;
119.1205 +			}
119.1206 +		}
119.1207 +		clockTicks++;
119.1208 +		N_FLAG = reg[dest].I & 0x80000000 ? true : false;
119.1209 +		Z_FLAG = reg[dest].I ? false : true;
119.1210 +	}
119.1211 +	break;
119.1212 +	}
119.1213 +	break;
119.1214 +case 0x42:
119.1215 +	switch ((opcode >> 6) & 3)
119.1216 +	{
119.1217 +	case 0x00:
119.1218 +	{
119.1219 +		// TST Rd, Rs
119.1220 +		u32 value = reg[opcode & 7].I & reg[(opcode >> 3) & 7].I;
119.1221 +		N_FLAG = value & 0x80000000 ? true : false;
119.1222 +		Z_FLAG = value ? false : true;
119.1223 +	}
119.1224 +	break;
119.1225 +	case 0x01:
119.1226 +	{
119.1227 +		// NEG Rd, Rs
119.1228 +		int dest   = opcode & 7;
119.1229 +		int source = (opcode >> 3) & 7;
119.1230 +		NEG_RD_RS;
119.1231 +	}
119.1232 +	break;
119.1233 +	case 0x02:
119.1234 +	{
119.1235 +		// CMP Rd, Rs
119.1236 +		int dest  = opcode & 7;
119.1237 +		u32 value = reg[(opcode >> 3) & 7].I;
119.1238 +		CMP_RD_RS;
119.1239 +	}
119.1240 +	break;
119.1241 +	case 0x03:
119.1242 +	{
119.1243 +		// CMN Rd, Rs
119.1244 +		int dest  = opcode & 7;
119.1245 +		u32 value = reg[(opcode >> 3) & 7].I;
119.1246 +		// CMN
119.1247 +		CMN_RD_RS;
119.1248 +	}
119.1249 +	break;
119.1250 +	}
119.1251 +	break;
119.1252 +case 0x43:
119.1253 +	switch ((opcode >> 6) & 3)
119.1254 +	{
119.1255 +	case 0x00:
119.1256 +	{
119.1257 +		// ORR Rd, Rs
119.1258 +		int dest = opcode & 7;
119.1259 +		reg[dest].I |= reg[(opcode >> 3) & 7].I;
119.1260 +		Z_FLAG		 = reg[dest].I ? false : true;
119.1261 +		N_FLAG		 = reg[dest].I & 0x80000000 ? true : false;
119.1262 +	}
119.1263 +	break;
119.1264 +	case 0x01:
119.1265 +	{
119.1266 +		// MUL Rd, Rs
119.1267 +		int dest = opcode & 7;
119.1268 +		u32 rm	 = reg[(opcode >> 3) & 7].I;
119.1269 +		reg[dest].I = reg[dest].I * rm;
119.1270 +		if (((s32)rm) < 0)
119.1271 +			rm = ~rm;
119.1272 +		if ((rm & 0xFFFFFF00) == 0)
119.1273 +			clockTicks += 1;
119.1274 +		else if ((rm & 0xFFFF0000) == 0)
119.1275 +			clockTicks += 2;
119.1276 +		else if ((rm & 0xFF000000) == 0)
119.1277 +			clockTicks += 3;
119.1278 +		else
119.1279 +			clockTicks += 4;
119.1280 +		Z_FLAG = reg[dest].I ? false : true;
119.1281 +		N_FLAG = reg[dest].I & 0x80000000 ? true : false;
119.1282 +	}
119.1283 +	break;
119.1284 +	case 0x02:
119.1285 +	{
119.1286 +		// BIC Rd, Rs
119.1287 +		int dest = opcode & 7;
119.1288 +		reg[dest].I &= (~reg[(opcode >> 3) & 7].I);
119.1289 +		Z_FLAG		 = reg[dest].I ? false : true;
119.1290 +		N_FLAG		 = reg[dest].I & 0x80000000 ? true : false;
119.1291 +	}
119.1292 +	break;
119.1293 +	case 0x03:
119.1294 +	{
119.1295 +		// MVN Rd, Rs
119.1296 +		int dest = opcode & 7;
119.1297 +		reg[dest].I = ~reg[(opcode >> 3) & 7].I;
119.1298 +		Z_FLAG		= reg[dest].I ? false : true;
119.1299 +		N_FLAG		= reg[dest].I & 0x80000000 ? true : false;
119.1300 +	}
119.1301 +	break;
119.1302 +	}
119.1303 +	break;
119.1304 +case 0x44:
119.1305 +{
119.1306 +	int dest = opcode & 7;
119.1307 +	int base = (opcode >> 3) & 7;
119.1308 +	switch ((opcode >> 6) & 3)
119.1309 +	{
119.1310 +	default:
119.1311 +		goto unknown_thumb;
119.1312 +	case 1:
119.1313 +		// ADD Rd, Hs
119.1314 +		reg[dest].I += reg[base + 8].I;
119.1315 +		break;
119.1316 +	case 2:
119.1317 +		// ADD Hd, Rs
119.1318 +		reg[dest + 8].I += reg[base].I;
119.1319 +		if (dest == 7)
119.1320 +		{
119.1321 +			reg[15].I &= 0xFFFFFFFE;
119.1322 +			armNextPC  = reg[15].I;
119.1323 +			reg[15].I += 2;
119.1324 +			clockTicks++;
119.1325 +		}
119.1326 +		break;
119.1327 +	case 3:
119.1328 +		// ADD Hd, Hs
119.1329 +		reg[dest + 8].I += reg[base + 8].I;
119.1330 +		if (dest == 7)
119.1331 +		{
119.1332 +			reg[15].I &= 0xFFFFFFFE;
119.1333 +			armNextPC  = reg[15].I;
119.1334 +			reg[15].I += 2;
119.1335 +			clockTicks++;
119.1336 +		}
119.1337 +		break;
119.1338 +	}
119.1339 +}
119.1340 +break;
119.1341 +case 0x45:
119.1342 +{
119.1343 +	int dest = opcode & 7;
119.1344 +	int base = (opcode >> 3) & 7;
119.1345 +	u32 value;
119.1346 +	switch ((opcode >> 6) & 3)
119.1347 +	{
119.1348 +	case 0:
119.1349 +		// CMP Rd, Hs
119.1350 +		value = reg[base].I;
119.1351 +		CMP_RD_RS;
119.1352 +		break;
119.1353 +	case 1:
119.1354 +		// CMP Rd, Hs
119.1355 +		value = reg[base + 8].I;
119.1356 +		CMP_RD_RS;
119.1357 +		break;
119.1358 +	case 2:
119.1359 +		// CMP Hd, Rs
119.1360 +		value = reg[base].I;
119.1361 +		dest += 8;
119.1362 +		CMP_RD_RS;
119.1363 +		break;
119.1364 +	case 3:
119.1365 +		// CMP Hd, Hs
119.1366 +		value = reg[base + 8].I;
119.1367 +		dest += 8;
119.1368 +		CMP_RD_RS;
119.1369 +		break;
119.1370 +	}
119.1371 +}
119.1372 +break;
119.1373 +case 0x46:
119.1374 +{
119.1375 +	int dest = opcode & 7;
119.1376 +	int base = (opcode >> 3) & 7;
119.1377 +	switch ((opcode >> 6) & 3)
119.1378 +	{
119.1379 +	case 0:
119.1380 +		// this form should not be used...
119.1381 +		// MOV Rd, Rs
119.1382 +		reg[dest].I = reg[base].I;
119.1383 +		break;
119.1384 +	case 1:
119.1385 +		// MOV Rd, Hs
119.1386 +		reg[dest].I = reg[base + 8].I;
119.1387 +		break;
119.1388 +	case 2:
119.1389 +		// MOV Hd, Rs
119.1390 +		reg[dest + 8].I = reg[base].I;
119.1391 +		if (dest == 7)
119.1392 +		{
119.1393 +			reg[15].I &= 0xFFFFFFFE;
119.1394 +			armNextPC  = reg[15].I;
119.1395 +			reg[15].I += 2;
119.1396 +			clockTicks++;
119.1397 +		}
119.1398 +		break;
119.1399 +	case 3:
119.1400 +		// MOV Hd, Hs
119.1401 +		reg[dest + 8].I = reg[base + 8].I;
119.1402 +		if (dest == 7)
119.1403 +		{
119.1404 +			reg[15].I &= 0xFFFFFFFE;
119.1405 +			armNextPC  = reg[15].I;
119.1406 +			reg[15].I += 2;
119.1407 +			clockTicks++;
119.1408 +		}
119.1409 +		break;
119.1410 +	}
119.1411 +}
119.1412 +break;
119.1413 +case 0x47:
119.1414 +{
119.1415 +	int base = (opcode >> 3) & 7;
119.1416 +	switch ((opcode >> 6) & 3)
119.1417 +	{
119.1418 +	case 0:
119.1419 +		// BX Rs
119.1420 +		reg[15].I = (reg[base].I) & 0xFFFFFFFE;
119.1421 +		if (reg[base].I & 1)
119.1422 +		{
119.1423 +			armState   = false;
119.1424 +			armNextPC  = reg[15].I;
119.1425 +			reg[15].I += 2;
119.1426 +		}
119.1427 +		else
119.1428 +		{
119.1429 +			armState   = true;
119.1430 +			reg[15].I &= 0xFFFFFFFC;
119.1431 +			armNextPC  = reg[15].I;
119.1432 +			reg[15].I += 4;
119.1433 +		}
119.1434 +		break;
119.1435 +	case 1:
119.1436 +		// BX Hs
119.1437 +		reg[15].I = (reg[8 + base].I) & 0xFFFFFFFE;
119.1438 +		if (reg[8 + base].I & 1)
119.1439 +		{
119.1440 +			armState   = false;
119.1441 +			armNextPC  = reg[15].I;
119.1442 +			reg[15].I += 2;
119.1443 +		}
119.1444 +		else
119.1445 +		{
119.1446 +			armState   = true;
119.1447 +			reg[15].I &= 0xFFFFFFFC;
119.1448 +			armNextPC  = reg[15].I;
119.1449 +			reg[15].I += 4;
119.1450 +		}
119.1451 +		break;
119.1452 +	default:
119.1453 +		goto unknown_thumb;
119.1454 +	}
119.1455 +}
119.1456 +break;
119.1457 +case 0x48:
119.1458 +	// LDR R0,[PC, #Imm]
119.1459 +{
119.1460 +	u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2);
119.1461 +	reg[0].I	= CPUReadMemoryQuick(address);
119.1462 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1463 +}
119.1464 +break;
119.1465 +case 0x49:
119.1466 +	// LDR R1,[PC, #Imm]
119.1467 +{
119.1468 +	u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2);
119.1469 +	reg[1].I	= CPUReadMemoryQuick(address);
119.1470 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1471 +}
119.1472 +break;
119.1473 +case 0x4a:
119.1474 +	// LDR R2,[PC, #Imm]
119.1475 +{
119.1476 +	u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2);
119.1477 +	reg[2].I	= CPUReadMemoryQuick(address);
119.1478 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1479 +}
119.1480 +break;
119.1481 +case 0x4b:
119.1482 +	// LDR R3,[PC, #Imm]
119.1483 +{
119.1484 +	u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2);
119.1485 +	reg[3].I	= CPUReadMemoryQuick(address);
119.1486 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1487 +}
119.1488 +break;
119.1489 +case 0x4c:
119.1490 +	// LDR R4,[PC, #Imm]
119.1491 +{
119.1492 +	u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2);
119.1493 +	reg[4].I	= CPUReadMemoryQuick(address);
119.1494 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1495 +}
119.1496 +break;
119.1497 +case 0x4d:
119.1498 +	// LDR R5,[PC, #Imm]
119.1499 +{
119.1500 +	u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2);
119.1501 +	reg[5].I	= CPUReadMemoryQuick(address);
119.1502 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1503 +}
119.1504 +break;
119.1505 +case 0x4e:
119.1506 +	// LDR R6,[PC, #Imm]
119.1507 +{
119.1508 +	u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2);
119.1509 +	reg[6].I	= CPUReadMemoryQuick(address);
119.1510 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1511 +}
119.1512 +break;
119.1513 +case 0x4f:
119.1514 +	// LDR R7,[PC, #Imm]
119.1515 +{
119.1516 +	u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2);
119.1517 +	reg[7].I	= CPUReadMemoryQuick(address);
119.1518 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1519 +}
119.1520 +break;
119.1521 +case 0x50:
119.1522 +case 0x51:
119.1523 +	// STR Rd, [Rs, Rn]
119.1524 +{
119.1525 +	u32
119.1526 +	    address = reg[(opcode >> 3) & 7].I + reg[(opcode >> 6) & 7].I;
119.1527 +	CPUWriteMemory(address,
119.1528 +	               reg[opcode & 7].I);
119.1529 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1530 +}
119.1531 +break;
119.1532 +case 0x52:
119.1533 +case 0x53:
119.1534 +	// STRH Rd, [Rs, Rn]
119.1535 +{
119.1536 +	u32 address = reg[(opcode >> 3) & 7].I + reg[(opcode >> 6) & 7].I;
119.1537 +	CPUWriteHalfWord(address,
119.1538 +	                 reg[opcode & 7].W.W0);
119.1539 +	clockTicks += CPUUpdateTicksAccess16(address);
119.1540 +}
119.1541 +break;
119.1542 +case 0x54:
119.1543 +case 0x55:
119.1544 +	// STRB Rd, [Rs, Rn]
119.1545 +{
119.1546 +	u32 address = reg[(opcode >> 3) & 7].I + reg[(opcode >> 6) & 7].I;
119.1547 +	CPUWriteByte(address,
119.1548 +	             reg[opcode & 7].B.B0);
119.1549 +	clockTicks += CPUUpdateTicksAccess16(address);
119.1550 +}
119.1551 +break;
119.1552 +case 0x56:
119.1553 +case 0x57:
119.1554 +	// LDSB Rd, [Rs, Rn]
119.1555 +{
119.1556 +	u32 address = reg[(opcode >> 3) & 7].I + reg[(opcode >> 6) & 7].I;
119.1557 +	reg[opcode & 7].I = (s8)CPUReadByte(address);
119.1558 +	clockTicks		 += CPUUpdateTicksAccess16(address);
119.1559 +}
119.1560 +break;
119.1561 +case 0x58:
119.1562 +case 0x59:
119.1563 +	// LDR Rd, [Rs, Rn]
119.1564 +{
119.1565 +	u32 address = reg[(opcode >> 3) & 7].I + reg[(opcode >> 6) & 7].I;
119.1566 +	reg[opcode & 7].I = CPUReadMemory(address);
119.1567 +	clockTicks		 += CPUUpdateTicksAccess32(address);
119.1568 +}
119.1569 +break;
119.1570 +case 0x5a:
119.1571 +case 0x5b:
119.1572 +	// LDRH Rd, [Rs, Rn]
119.1573 +{
119.1574 +	u32 address = reg[(opcode >> 3) & 7].I + reg[(opcode >> 6) & 7].I;
119.1575 +	reg[opcode & 7].I = CPUReadHalfWord(address);
119.1576 +	clockTicks		 += CPUUpdateTicksAccess16(address);
119.1577 +}
119.1578 +break;
119.1579 +case 0x5c:
119.1580 +case 0x5d:
119.1581 +	// LDRB Rd, [Rs, Rn]
119.1582 +{
119.1583 +	u32 address = reg[(opcode >> 3) & 7].I + reg[(opcode >> 6) & 7].I;
119.1584 +	reg[opcode & 7].I = CPUReadByte(address);
119.1585 +	clockTicks		 += CPUUpdateTicksAccess16(address);
119.1586 +}
119.1587 +break;
119.1588 +case 0x5e:
119.1589 +case 0x5f:
119.1590 +	// LDSH Rd, [Rs, Rn]
119.1591 +{
119.1592 +	u32 address = reg[(opcode >> 3) & 7].I + reg[(opcode >> 6) & 7].I;
119.1593 +	reg[opcode & 7].I = (s16)CPUReadHalfWordSigned(address);
119.1594 +	clockTicks		 += CPUUpdateTicksAccess16(address);
119.1595 +}
119.1596 +break;
119.1597 +case 0x60:
119.1598 +case 0x61:
119.1599 +case 0x62:
119.1600 +case 0x63:
119.1601 +case 0x64:
119.1602 +case 0x65:
119.1603 +case 0x66:
119.1604 +case 0x67:
119.1605 +	// STR Rd, [Rs, #Imm]
119.1606 +{
119.1607 +	u32 address = reg[(opcode >> 3) & 7].I + (((opcode >> 6) & 31) << 2);
119.1608 +	CPUWriteMemory(address,
119.1609 +	               reg[opcode & 7].I);
119.1610 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1611 +}
119.1612 +break;
119.1613 +case 0x68:
119.1614 +case 0x69:
119.1615 +case 0x6a:
119.1616 +case 0x6b:
119.1617 +case 0x6c:
119.1618 +case 0x6d:
119.1619 +case 0x6e:
119.1620 +case 0x6f:
119.1621 +	// LDR Rd, [Rs, #Imm]
119.1622 +{
119.1623 +	u32 address = reg[(opcode >> 3) & 7].I + (((opcode >> 6) & 31) << 2);
119.1624 +	reg[opcode & 7].I = CPUReadMemory(address);
119.1625 +	clockTicks		 += CPUUpdateTicksAccess32(address);
119.1626 +}
119.1627 +break;
119.1628 +case 0x70:
119.1629 +case 0x71:
119.1630 +case 0x72:
119.1631 +case 0x73:
119.1632 +case 0x74:
119.1633 +case 0x75:
119.1634 +case 0x76:
119.1635 +case 0x77:
119.1636 +	// STRB Rd, [Rs, #Imm]
119.1637 +{
119.1638 +	u32 address = reg[(opcode >> 3) & 7].I + (((opcode >> 6) & 31));
119.1639 +	CPUWriteByte(address,
119.1640 +	             reg[opcode & 7].B.B0);
119.1641 +	clockTicks += CPUUpdateTicksAccess16(address);
119.1642 +}
119.1643 +break;
119.1644 +case 0x78:
119.1645 +case 0x79:
119.1646 +case 0x7a:
119.1647 +case 0x7b:
119.1648 +case 0x7c:
119.1649 +case 0x7d:
119.1650 +case 0x7e:
119.1651 +case 0x7f:
119.1652 +	// LDRB Rd, [Rs, #Imm]
119.1653 +{
119.1654 +	u32 address = reg[(opcode >> 3) & 7].I + (((opcode >> 6) & 31));
119.1655 +	reg[opcode & 7].I = CPUReadByte(address);
119.1656 +	clockTicks		 += CPUUpdateTicksAccess16(address);
119.1657 +}
119.1658 +break;
119.1659 +case 0x80:
119.1660 +case 0x81:
119.1661 +case 0x82:
119.1662 +case 0x83:
119.1663 +case 0x84:
119.1664 +case 0x85:
119.1665 +case 0x86:
119.1666 +case 0x87:
119.1667 +	// STRH Rd, [Rs, #Imm]
119.1668 +{
119.1669 +	u32 address = reg[(opcode >> 3) & 7].I + (((opcode >> 6) & 31) << 1);
119.1670 +	CPUWriteHalfWord(address,
119.1671 +	                 reg[opcode & 7].W.W0);
119.1672 +	clockTicks += CPUUpdateTicksAccess16(address);
119.1673 +}
119.1674 +break;
119.1675 +case 0x88:
119.1676 +case 0x89:
119.1677 +case 0x8a:
119.1678 +case 0x8b:
119.1679 +case 0x8c:
119.1680 +case 0x8d:
119.1681 +case 0x8e:
119.1682 +case 0x8f:
119.1683 +	// LDRH Rd, [Rs, #Imm]
119.1684 +{
119.1685 +	u32 address = reg[(opcode >> 3) & 7].I + (((opcode >> 6) & 31) << 1);
119.1686 +	reg[opcode & 7].I = CPUReadHalfWord(address);
119.1687 +	clockTicks		 += CPUUpdateTicksAccess16(address);
119.1688 +}
119.1689 +break;
119.1690 +case 0x90:
119.1691 +	// STR R0, [SP, #Imm]
119.1692 +{
119.1693 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1694 +	CPUWriteMemory(address, reg[0].I);
119.1695 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1696 +}
119.1697 +break;
119.1698 +case 0x91:
119.1699 +	// STR R1, [SP, #Imm]
119.1700 +{
119.1701 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1702 +	CPUWriteMemory(address, reg[1].I);
119.1703 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1704 +}
119.1705 +break;
119.1706 +case 0x92:
119.1707 +	// STR R2, [SP, #Imm]
119.1708 +{
119.1709 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1710 +	CPUWriteMemory(address, reg[2].I);
119.1711 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1712 +}
119.1713 +break;
119.1714 +case 0x93:
119.1715 +	// STR R3, [SP, #Imm]
119.1716 +{
119.1717 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1718 +	CPUWriteMemory(address, reg[3].I);
119.1719 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1720 +}
119.1721 +break;
119.1722 +case 0x94:
119.1723 +	// STR R4, [SP, #Imm]
119.1724 +{
119.1725 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1726 +	CPUWriteMemory(address, reg[4].I);
119.1727 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1728 +}
119.1729 +break;
119.1730 +case 0x95:
119.1731 +	// STR R5, [SP, #Imm]
119.1732 +{
119.1733 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1734 +	CPUWriteMemory(address, reg[5].I);
119.1735 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1736 +}
119.1737 +break;
119.1738 +case 0x96:
119.1739 +	// STR R6, [SP, #Imm]
119.1740 +{
119.1741 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1742 +	CPUWriteMemory(address, reg[6].I);
119.1743 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1744 +}
119.1745 +break;
119.1746 +case 0x97:
119.1747 +	// STR R7, [SP, #Imm]
119.1748 +{
119.1749 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1750 +	CPUWriteMemory(address, reg[7].I);
119.1751 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1752 +}
119.1753 +break;
119.1754 +case 0x98:
119.1755 +	// LDR R0, [SP, #Imm]
119.1756 +{
119.1757 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1758 +	reg[0].I	= CPUReadMemoryQuick(address);
119.1759 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1760 +}
119.1761 +break;
119.1762 +case 0x99:
119.1763 +	// LDR R1, [SP, #Imm]
119.1764 +{
119.1765 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1766 +	reg[1].I	= CPUReadMemoryQuick(address);
119.1767 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1768 +}
119.1769 +break;
119.1770 +case 0x9a:
119.1771 +	// LDR R2, [SP, #Imm]
119.1772 +{
119.1773 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1774 +	reg[2].I	= CPUReadMemoryQuick(address);
119.1775 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1776 +}
119.1777 +break;
119.1778 +case 0x9b:
119.1779 +	// LDR R3, [SP, #Imm]
119.1780 +{
119.1781 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1782 +	reg[3].I	= CPUReadMemoryQuick(address);
119.1783 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1784 +}
119.1785 +break;
119.1786 +case 0x9c:
119.1787 +	// LDR R4, [SP, #Imm]
119.1788 +{
119.1789 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1790 +	reg[4].I	= CPUReadMemoryQuick(address);
119.1791 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1792 +}
119.1793 +break;
119.1794 +case 0x9d:
119.1795 +	// LDR R5, [SP, #Imm]
119.1796 +{
119.1797 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1798 +	reg[5].I	= CPUReadMemoryQuick(address);
119.1799 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1800 +}
119.1801 +break;
119.1802 +case 0x9e:
119.1803 +	// LDR R6, [SP, #Imm]
119.1804 +{
119.1805 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1806 +	reg[6].I	= CPUReadMemoryQuick(address);
119.1807 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1808 +}
119.1809 +break;
119.1810 +case 0x9f:
119.1811 +	// LDR R7, [SP, #Imm]
119.1812 +{
119.1813 +	u32 address = reg[13].I + ((opcode & 255) << 2);
119.1814 +	reg[7].I	= CPUReadMemoryQuick(address);
119.1815 +	clockTicks += CPUUpdateTicksAccess32(address);
119.1816 +}
119.1817 +break;
119.1818 +case 0xa0:
119.1819 +	// ADD R0, PC, Imm
119.1820 +	reg[0].I = (reg[15].I & 0xFFFFFFFC) + ((opcode & 255) << 2);
119.1821 +	break;
119.1822 +case 0xa1:
119.1823 +	// ADD R1, PC, Imm
119.1824 +	reg[1].I = (reg[15].I & 0xFFFFFFFC) + ((opcode & 255) << 2);
119.1825 +	break;
119.1826 +case 0xa2:
119.1827 +	// ADD R2, PC, Imm
119.1828 +	reg[2].I = (reg[15].I & 0xFFFFFFFC) + ((opcode & 255) << 2);
119.1829 +	break;
119.1830 +case 0xa3:
119.1831 +	// ADD R3, PC, Imm
119.1832 +	reg[3].I = (reg[15].I & 0xFFFFFFFC) + ((opcode & 255) << 2);
119.1833 +	break;
119.1834 +case 0xa4:
119.1835 +	// ADD R4, PC, Imm
119.1836 +	reg[4].I = (reg[15].I & 0xFFFFFFFC) + ((opcode & 255) << 2);
119.1837 +	break;
119.1838 +case 0xa5:
119.1839 +	// ADD R5, PC, Imm
119.1840 +	reg[5].I = (reg[15].I & 0xFFFFFFFC) + ((opcode & 255) << 2);
119.1841 +	break;
119.1842 +case 0xa6:
119.1843 +	// ADD R6, PC, Imm
119.1844 +	reg[6].I = (reg[15].I & 0xFFFFFFFC) + ((opcode & 255) << 2);
119.1845 +	break;
119.1846 +case 0xa7:
119.1847 +	// ADD R7, PC, Imm
119.1848 +	reg[7].I = (reg[15].I & 0xFFFFFFFC) + ((opcode & 255) << 2);
119.1849 +	break;
119.1850 +case 0xa8:
119.1851 +	// ADD R0, SP, Imm
119.1852 +	reg[0].I = reg[13].I + ((opcode & 255) << 2);
119.1853 +	break;
119.1854 +case 0xa9:
119.1855 +	// ADD R1, SP, Imm
119.1856 +	reg[1].I = reg[13].I + ((opcode & 255) << 2);
119.1857 +	break;
119.1858 +case 0xaa:
119.1859 +	// ADD R2, SP, Imm
119.1860 +	reg[2].I = reg[13].I + ((opcode & 255) << 2);
119.1861 +	break;
119.1862 +case 0xab:
119.1863 +	// ADD R3, SP, Imm
119.1864 +	reg[3].I = reg[13].I + ((opcode & 255) << 2);
119.1865 +	break;
119.1866 +case 0xac:
119.1867 +	// ADD R4, SP, Imm
119.1868 +	reg[4].I = reg[13].I + ((opcode & 255) << 2);
119.1869 +	break;
119.1870 +case 0xad:
119.1871 +	// ADD R5, SP, Imm
119.1872 +	reg[5].I = reg[13].I + ((opcode & 255) << 2);
119.1873 +	break;
119.1874 +case 0xae:
119.1875 +	// ADD R6, SP, Imm
119.1876 +	reg[6].I = reg[13].I + ((opcode & 255) << 2);
119.1877 +	break;
119.1878 +case 0xaf:
119.1879 +	// ADD R7, SP, Imm
119.1880 +	reg[7].I = reg[13].I + ((opcode & 255) << 2);
119.1881 +	break;
119.1882 +case 0xb0:
119.1883 +{
119.1884 +	// ADD SP, Imm
119.1885 +	int offset = (opcode & 127) << 2;
119.1886 +	if (opcode & 0x80)
119.1887 +		offset = -offset;
119.1888 +	reg[13].I += offset;
119.1889 +}
119.1890 +break;
119.1891 +#define PUSH_REG(val, r) \
119.1892 +	if (opcode & (val)) { \
119.1893 +		CPUWriteMemory(address, reg[(r)].I); \
119.1894 +		if (offset) \
119.1895 +			clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); \
119.1896 +		else \
119.1897 +			clockTicks += 1 + CPUUpdateTicksAccess32(address); \
119.1898 +		offset	 = 1; \
119.1899 +		address += 4; \
119.1900 +	}
119.1901 +case 0xb4:
119.1902 +	// PUSH {Rlist}
119.1903 +{
119.1904 +	int offset	= 0;
119.1905 +	u32 temp	= reg[13].I - 4 * cpuBitsSet[opcode & 0xff];
119.1906 +	u32 address = temp & 0xFFFFFFFC;
119.1907 +	PUSH_REG(1, 0);
119.1908 +	PUSH_REG(2, 1);
119.1909 +	PUSH_REG(4, 2);
119.1910 +	PUSH_REG(8, 3);
119.1911 +	PUSH_REG(16, 4);
119.1912 +	PUSH_REG(32, 5);
119.1913 +	PUSH_REG(64, 6);
119.1914 +	PUSH_REG(128, 7);
119.1915 +	reg[13].I = temp;
119.1916 +}
119.1917 +break;
119.1918 +case 0xb5:
119.1919 +	// PUSH {Rlist, LR}
119.1920 +{
119.1921 +	int offset	= 0;
119.1922 +	u32 temp	= reg[13].I - 4 - 4 * cpuBitsSet[opcode & 0xff];
119.1923 +	u32 address = temp & 0xFFFFFFFC;
119.1924 +	PUSH_REG(1, 0);
119.1925 +	PUSH_REG(2, 1);
119.1926 +	PUSH_REG(4, 2);
119.1927 +	PUSH_REG(8, 3);
119.1928 +	PUSH_REG(16, 4);
119.1929 +	PUSH_REG(32, 5);
119.1930 +	PUSH_REG(64, 6);
119.1931 +	PUSH_REG(128, 7);
119.1932 +	PUSH_REG(256, 14);
119.1933 +	reg[13].I = temp;
119.1934 +}
119.1935 +break;
119.1936 +#define POP_REG(val, r) \
119.1937 +	if (opcode & (val)) { \
119.1938 +		reg[(r)].I = CPUReadMemory(address); \
119.1939 +		if (offset) \
119.1940 +			clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); \
119.1941 +		else \
119.1942 +			clockTicks += 2 + CPUUpdateTicksAccess32(address); \
119.1943 +		offset	 = 1; \
119.1944 +		address += 4; \
119.1945 +	}
119.1946 +case 0xbc:
119.1947 +	// POP {Rlist}
119.1948 +{
119.1949 +	int offset	= 0;
119.1950 +	u32 address = reg[13].I & 0xFFFFFFFC;
119.1951 +	u32 temp	= reg[13].I + 4 * cpuBitsSet[opcode & 0xFF];
119.1952 +	POP_REG(1, 0);
119.1953 +	POP_REG(2, 1);
119.1954 +	POP_REG(4, 2);
119.1955 +	POP_REG(8, 3);
119.1956 +	POP_REG(16, 4);
119.1957 +	POP_REG(32, 5);
119.1958 +	POP_REG(64, 6);
119.1959 +	POP_REG(128, 7);
119.1960 +	reg[13].I = temp;
119.1961 +}
119.1962 +break;
119.1963 +case 0xbd:
119.1964 +	// POP {Rlist, PC}
119.1965 +{
119.1966 +	int offset	= 0;
119.1967 +	u32 address = reg[13].I & 0xFFFFFFFC;
119.1968 +	u32 temp	= reg[13].I + 4 + 4 * cpuBitsSet[opcode & 0xFF];
119.1969 +	POP_REG(1, 0);
119.1970 +	POP_REG(2, 1);
119.1971 +	POP_REG(4, 2);
119.1972 +	POP_REG(8, 3);
119.1973 +	POP_REG(16, 4);
119.1974 +	POP_REG(32, 5);
119.1975 +	POP_REG(64, 6);
119.1976 +	POP_REG(128, 7);
119.1977 +	reg[15].I = (CPUReadMemory(address) & 0xFFFFFFFE);
119.1978 +	if (offset)
119.1979 +		clockTicks += CPUUpdateTicksAccessSeq32(address);
119.1980 +	else
119.1981 +		clockTicks += CPUUpdateTicksAccess32(address);
119.1982 +	armNextPC  = reg[15].I;
119.1983 +	reg[15].I += 2;
119.1984 +	reg[13].I  = temp;
119.1985 +}
119.1986 +break;
119.1987 +#define THUMB_STM_REG(val, r, b) \
119.1988 +	if (opcode & (val)) { \
119.1989 +		CPUWriteMemory(address, reg[(r)].I); \
119.1990 +		if (!offset) { \
119.1991 +			reg[(b)].I	= temp; \
119.1992 +			clockTicks += 1 + CPUUpdateTicksAccess32(address); \
119.1993 +		} else \
119.1994 +			clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); \
119.1995 +		offset	 = 1; \
119.1996 +		address += 4; \
119.1997 +	}
119.1998 +case 0xc0:
119.1999 +{
119.2000 +	// STM R0!, {Rlist}
119.2001 +	u32 address = reg[0].I & 0xFFFFFFFC;
119.2002 +	u32 temp	= reg[0].I + 4 * cpuBitsSet[opcode & 0xff];
119.2003 +	int offset	= 0;
119.2004 +	// store
119.2005 +	THUMB_STM_REG(1, 0, 0);
119.2006 +	THUMB_STM_REG(2, 1, 0);
119.2007 +	THUMB_STM_REG(4, 2, 0);
119.2008 +	THUMB_STM_REG(8, 3, 0);
119.2009 +	THUMB_STM_REG(16, 4, 0);
119.2010 +	THUMB_STM_REG(32, 5, 0);
119.2011 +	THUMB_STM_REG(64, 6, 0);
119.2012 +	THUMB_STM_REG(128, 7, 0);
119.2013 +}
119.2014 +break;
119.2015 +case 0xc1:
119.2016 +{
119.2017 +	// STM R1!, {Rlist}
119.2018 +	u32 address = reg[1].I & 0xFFFFFFFC;
119.2019 +	u32 temp	= reg[1].I + 4 * cpuBitsSet[opcode & 0xff];
119.2020 +	int offset	= 0;
119.2021 +	// store
119.2022 +	THUMB_STM_REG(1, 0, 1);
119.2023 +	THUMB_STM_REG(2, 1, 1);
119.2024 +	THUMB_STM_REG(4, 2, 1);
119.2025 +	THUMB_STM_REG(8, 3, 1);
119.2026 +	THUMB_STM_REG(16, 4, 1);
119.2027 +	THUMB_STM_REG(32, 5, 1);
119.2028 +	THUMB_STM_REG(64, 6, 1);
119.2029 +	THUMB_STM_REG(128, 7, 1);
119.2030 +}
119.2031 +break;
119.2032 +case 0xc2:
119.2033 +{
119.2034 +	// STM R2!, {Rlist}
119.2035 +	u32 address = reg[2].I & 0xFFFFFFFC;
119.2036 +	u32 temp	= reg[2].I + 4 * cpuBitsSet[opcode & 0xff];
119.2037 +	int offset	= 0;
119.2038 +	// store
119.2039 +	THUMB_STM_REG(1, 0, 2);
119.2040 +	THUMB_STM_REG(2, 1, 2);
119.2041 +	THUMB_STM_REG(4, 2, 2);
119.2042 +	THUMB_STM_REG(8, 3, 2);
119.2043 +	THUMB_STM_REG(16, 4, 2);
119.2044 +	THUMB_STM_REG(32, 5, 2);
119.2045 +	THUMB_STM_REG(64, 6, 2);
119.2046 +	THUMB_STM_REG(128, 7, 2);
119.2047 +}
119.2048 +break;
119.2049 +case 0xc3:
119.2050 +{
119.2051 +	// STM R3!, {Rlist}
119.2052 +	u32 address = reg[3].I & 0xFFFFFFFC;
119.2053 +	u32 temp	= reg[3].I + 4 * cpuBitsSet[opcode & 0xff];
119.2054 +	int offset	= 0;
119.2055 +	// store
119.2056 +	THUMB_STM_REG(1, 0, 3);
119.2057 +	THUMB_STM_REG(2, 1, 3);
119.2058 +	THUMB_STM_REG(4, 2, 3);
119.2059 +	THUMB_STM_REG(8, 3, 3);
119.2060 +	THUMB_STM_REG(16, 4, 3);
119.2061 +	THUMB_STM_REG(32, 5, 3);
119.2062 +	THUMB_STM_REG(64, 6, 3);
119.2063 +	THUMB_STM_REG(128, 7, 3);
119.2064 +}
119.2065 +break;
119.2066 +case 0xc4:
119.2067 +{
119.2068 +	// STM R4!, {Rlist}
119.2069 +	u32 address = reg[4].I & 0xFFFFFFFC;
119.2070 +	u32 temp	= reg[4].I + 4 * cpuBitsSet[opcode & 0xff];
119.2071 +	int offset	= 0;
119.2072 +	// store
119.2073 +	THUMB_STM_REG(1, 0, 4);
119.2074 +	THUMB_STM_REG(2, 1, 4);
119.2075 +	THUMB_STM_REG(4, 2, 4);
119.2076 +	THUMB_STM_REG(8, 3, 4);
119.2077 +	THUMB_STM_REG(16, 4, 4);
119.2078 +	THUMB_STM_REG(32, 5, 4);
119.2079 +	THUMB_STM_REG(64, 6, 4);
119.2080 +	THUMB_STM_REG(128, 7, 4);
119.2081 +}
119.2082 +break;
119.2083 +case 0xc5:
119.2084 +{
119.2085 +	// STM R5!, {Rlist}
119.2086 +	u32 address = reg[5].I & 0xFFFFFFFC;
119.2087 +	u32 temp	= reg[5].I + 4 * cpuBitsSet[opcode & 0xff];
119.2088 +	int offset	= 0;
119.2089 +	// store
119.2090 +	THUMB_STM_REG(1, 0, 5);
119.2091 +	THUMB_STM_REG(2, 1, 5);
119.2092 +	THUMB_STM_REG(4, 2, 5);
119.2093 +	THUMB_STM_REG(8, 3, 5);
119.2094 +	THUMB_STM_REG(16, 4, 5);
119.2095 +	THUMB_STM_REG(32, 5, 5);
119.2096 +	THUMB_STM_REG(64, 6, 5);
119.2097 +	THUMB_STM_REG(128, 7, 5);
119.2098 +}
119.2099 +break;
119.2100 +case 0xc6:
119.2101 +{
119.2102 +	// STM R6!, {Rlist}
119.2103 +	u32 address = reg[6].I & 0xFFFFFFFC;
119.2104 +	u32 temp	= reg[6].I + 4 * cpuBitsSet[opcode & 0xff];
119.2105 +	int offset	= 0;
119.2106 +	// store
119.2107 +	THUMB_STM_REG(1, 0, 6);
119.2108 +	THUMB_STM_REG(2, 1, 6);
119.2109 +	THUMB_STM_REG(4, 2, 6);
119.2110 +	THUMB_STM_REG(8, 3, 6);
119.2111 +	THUMB_STM_REG(16, 4, 6);
119.2112 +	THUMB_STM_REG(32, 5, 6);
119.2113 +	THUMB_STM_REG(64, 6, 6);
119.2114 +	THUMB_STM_REG(128, 7, 6);
119.2115 +}
119.2116 +break;
119.2117 +case 0xc7:
119.2118 +{
119.2119 +	// STM R7!, {Rlist}
119.2120 +	u32 address = reg[7].I & 0xFFFFFFFC;
119.2121 +	u32 temp	= reg[7].I + 4 * cpuBitsSet[opcode & 0xff];
119.2122 +	int offset	= 0;
119.2123 +	// store
119.2124 +	THUMB_STM_REG(1, 0, 7);
119.2125 +	THUMB_STM_REG(2, 1, 7);
119.2126 +	THUMB_STM_REG(4, 2, 7);
119.2127 +	THUMB_STM_REG(8, 3, 7);
119.2128 +	THUMB_STM_REG(16, 4, 7);
119.2129 +	THUMB_STM_REG(32, 5, 7);
119.2130 +	THUMB_STM_REG(64, 6, 7);
119.2131 +	THUMB_STM_REG(128, 7, 7);
119.2132 +}
119.2133 +break;
119.2134 +#define THUMB_LDM_REG(val, r) \
119.2135 +	if (opcode & (val)) { \
119.2136 +		reg[(r)].I = CPUReadMemory(address); \
119.2137 +		if (offset) \
119.2138 +			clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); \
119.2139 +		else \
119.2140 +			clockTicks += 2 + CPUUpdateTicksAccess32(address); \
119.2141 +		offset	 = 1; \
119.2142 +		address += 4; \
119.2143 +	}
119.2144 +case 0xc8:
119.2145 +{
119.2146 +	// LDM R0!, {Rlist}
119.2147 +	u32 address = reg[0].I & 0xFFFFFFFC;
119.2148 +	u32 temp	= reg[0].I + 4 * cpuBitsSet[opcode & 0xFF];
119.2149 +	int offset	= 0;
119.2150 +	// load
119.2151 +	THUMB_LDM_REG(1, 0);
119.2152 +	THUMB_LDM_REG(2, 1);
119.2153 +	THUMB_LDM_REG(4, 2);
119.2154 +	THUMB_LDM_REG(8, 3);
119.2155 +	THUMB_LDM_REG(16, 4);
119.2156 +	THUMB_LDM_REG(32, 5);
119.2157 +	THUMB_LDM_REG(64, 6);
119.2158 +	THUMB_LDM_REG(128, 7);
119.2159 +	if (!(opcode & 1))
119.2160 +		reg[0].I = temp;
119.2161 +}
119.2162 +break;
119.2163 +case 0xc9:
119.2164 +{
119.2165 +	// LDM R1!, {Rlist}
119.2166 +	u32 address = reg[1].I & 0xFFFFFFFC;
119.2167 +	u32 temp	= reg[1].I + 4 * cpuBitsSet[opcode & 0xFF];
119.2168 +	int offset	= 0;
119.2169 +	// load
119.2170 +	THUMB_LDM_REG(1, 0);
119.2171 +	THUMB_LDM_REG(2, 1);
119.2172 +	THUMB_LDM_REG(4, 2);
119.2173 +	THUMB_LDM_REG(8, 3);
119.2174 +	THUMB_LDM_REG(16, 4);
119.2175 +	THUMB_LDM_REG(32, 5);
119.2176 +	THUMB_LDM_REG(64, 6);
119.2177 +	THUMB_LDM_REG(128, 7);
119.2178 +	if (!(opcode & 2))
119.2179 +		reg[1].I = temp;
119.2180 +}
119.2181 +break;
119.2182 +case 0xca:
119.2183 +{
119.2184 +	// LDM R2!, {Rlist}
119.2185 +	u32 address = reg[2].I & 0xFFFFFFFC;
119.2186 +	u32 temp	= reg[2].I + 4 * cpuBitsSet[opcode & 0xFF];
119.2187 +	int offset	= 0;
119.2188 +	// load
119.2189 +	THUMB_LDM_REG(1, 0);
119.2190 +	THUMB_LDM_REG(2, 1);
119.2191 +	THUMB_LDM_REG(4, 2);
119.2192 +	THUMB_LDM_REG(8, 3);
119.2193 +	THUMB_LDM_REG(16, 4);
119.2194 +	THUMB_LDM_REG(32, 5);
119.2195 +	THUMB_LDM_REG(64, 6);
119.2196 +	THUMB_LDM_REG(128, 7);
119.2197 +	if (!(opcode & 4))
119.2198 +		reg[2].I = temp;
119.2199 +}
119.2200 +break;
119.2201 +case 0xcb:
119.2202 +{
119.2203 +	// LDM R3!, {Rlist}
119.2204 +	u32 address = reg[3].I & 0xFFFFFFFC;
119.2205 +	u32 temp	= reg[3].I + 4 * cpuBitsSet[opcode & 0xFF];
119.2206 +	int offset	= 0;
119.2207 +	// load
119.2208 +	THUMB_LDM_REG(1, 0);
119.2209 +	THUMB_LDM_REG(2, 1);
119.2210 +	THUMB_LDM_REG(4, 2);
119.2211 +	THUMB_LDM_REG(8, 3);
119.2212 +	THUMB_LDM_REG(16, 4);
119.2213 +	THUMB_LDM_REG(32, 5);
119.2214 +	THUMB_LDM_REG(64, 6);
119.2215 +	THUMB_LDM_REG(128, 7);
119.2216 +	if (!(opcode & 8))
119.2217 +		reg[3].I = temp;
119.2218 +}
119.2219 +break;
119.2220 +case 0xcc:
119.2221 +{
119.2222 +	// LDM R4!, {Rlist}
119.2223 +	u32 address = reg[4].I & 0xFFFFFFFC;
119.2224 +	u32 temp	= reg[4].I + 4 * cpuBitsSet[opcode & 0xFF];
119.2225 +	int offset	= 0;
119.2226 +	// load
119.2227 +	THUMB_LDM_REG(1, 0);
119.2228 +	THUMB_LDM_REG(2, 1);
119.2229 +	THUMB_LDM_REG(4, 2);
119.2230 +	THUMB_LDM_REG(8, 3);
119.2231 +	THUMB_LDM_REG(16, 4);
119.2232 +	THUMB_LDM_REG(32, 5);
119.2233 +	THUMB_LDM_REG(64, 6);
119.2234 +	THUMB_LDM_REG(128, 7);
119.2235 +	if (!(opcode & 16))
119.2236 +		reg[4].I = temp;
119.2237 +}
119.2238 +break;
119.2239 +case 0xcd:
119.2240 +{
119.2241 +	// LDM R5!, {Rlist}
119.2242 +	u32 address = reg[5].I & 0xFFFFFFFC;
119.2243 +	u32 temp	= reg[5].I + 4 * cpuBitsSet[opcode & 0xFF];
119.2244 +	int offset	= 0;
119.2245 +	// load
119.2246 +	THUMB_LDM_REG(1, 0);
119.2247 +	THUMB_LDM_REG(2, 1);
119.2248 +	THUMB_LDM_REG(4, 2);
119.2249 +	THUMB_LDM_REG(8, 3);
119.2250 +	THUMB_LDM_REG(16, 4);
119.2251 +	THUMB_LDM_REG(32, 5);
119.2252 +	THUMB_LDM_REG(64, 6);
119.2253 +	THUMB_LDM_REG(128, 7);
119.2254 +	if (!(opcode & 32))
119.2255 +		reg[5].I = temp;
119.2256 +}
119.2257 +break;
119.2258 +case 0xce:
119.2259 +{
119.2260 +	// LDM R6!, {Rlist}
119.2261 +	u32 address = reg[6].I & 0xFFFFFFFC;
119.2262 +	u32 temp	= reg[6].I + 4 * cpuBitsSet[opcode & 0xFF];
119.2263 +	int offset	= 0;
119.2264 +	// load
119.2265 +	THUMB_LDM_REG(1, 0);
119.2266 +	THUMB_LDM_REG(2, 1);
119.2267 +	THUMB_LDM_REG(4, 2);
119.2268 +	THUMB_LDM_REG(8, 3);
119.2269 +	THUMB_LDM_REG(16, 4);
119.2270 +	THUMB_LDM_REG(32, 5);
119.2271 +	THUMB_LDM_REG(64, 6);
119.2272 +	THUMB_LDM_REG(128, 7);
119.2273 +	if (!(opcode & 64))
119.2274 +		reg[6].I = temp;
119.2275 +}
119.2276 +break;
119.2277 +case 0xcf:
119.2278 +{
119.2279 +	// LDM R7!, {Rlist}
119.2280 +	u32 address = reg[7].I & 0xFFFFFFFC;
119.2281 +	u32 temp	= reg[7].I + 4 * cpuBitsSet[opcode & 0xFF];
119.2282 +	int offset	= 0;
119.2283 +	// load
119.2284 +	THUMB_LDM_REG(1, 0);
119.2285 +	THUMB_LDM_REG(2, 1);
119.2286 +	THUMB_LDM_REG(4, 2);
119.2287 +	THUMB_LDM_REG(8, 3);
119.2288 +	THUMB_LDM_REG(16, 4);
119.2289 +	THUMB_LDM_REG(32, 5);
119.2290 +	THUMB_LDM_REG(64, 6);
119.2291 +	THUMB_LDM_REG(128, 7);
119.2292 +	if (!(opcode & 128))
119.2293 +		reg[7].I = temp;
119.2294 +}
119.2295 +break;
119.2296 +case 0xd0:
119.2297 +	// BEQ offset
119.2298 +	if (Z_FLAG)
119.2299 +	{
119.2300 +		reg[15].I += ((s8)(opcode & 0xFF)) << 1;
119.2301 +		armNextPC  = reg[15].I;
119.2302 +		reg[15].I += 2;
119.2303 +		clockTicks = 3;
119.2304 +	}
119.2305 +	break;
119.2306 +case 0xd1:
119.2307 +	// BNE offset
119.2308 +	if (!Z_FLAG)
119.2309 +	{
119.2310 +		reg[15].I += ((s8)(opcode & 0xFF)) << 1;
119.2311 +		armNextPC  = reg[15].I;
119.2312 +		reg[15].I += 2;
119.2313 +		clockTicks = 3;
119.2314 +	}
119.2315 +	break;
119.2316 +case 0xd2:
119.2317 +	// BCS offset
119.2318 +	if (C_FLAG)
119.2319 +	{
119.2320 +		reg[15].I += ((s8)(opcode & 0xFF)) << 1;
119.2321 +		armNextPC  = reg[15].I;
119.2322 +		reg[15].I += 2;
119.2323 +		clockTicks = 3;
119.2324 +	}
119.2325 +	break;
119.2326 +case 0xd3:
119.2327 +	// BCC offset
119.2328 +	if (!C_FLAG)
119.2329 +	{
119.2330 +		reg[15].I += ((s8)(opcode & 0xFF)) << 1;
119.2331 +		armNextPC  = reg[15].I;
119.2332 +		reg[15].I += 2;
119.2333 +		clockTicks = 3;
119.2334 +	}
119.2335 +	break;
119.2336 +case 0xd4:
119.2337 +	// BMI offset
119.2338 +	if (N_FLAG)
119.2339 +	{
119.2340 +		reg[15].I += ((s8)(opcode & 0xFF)) << 1;
119.2341 +		armNextPC  = reg[15].I;
119.2342 +		reg[15].I += 2;
119.2343 +		clockTicks = 3;
119.2344 +	}
119.2345 +	break;
119.2346 +case 0xd5:
119.2347 +	// BPL offset
119.2348 +	if (!N_FLAG)
119.2349 +	{
119.2350 +		reg[15].I += ((s8)(opcode & 0xFF)) << 1;
119.2351 +		armNextPC  = reg[15].I;
119.2352 +		reg[15].I += 2;
119.2353 +		clockTicks = 3;
119.2354 +	}
119.2355 +	break;
119.2356 +case 0xd6:
119.2357 +	// BVS offset
119.2358 +	if (V_FLAG)
119.2359 +	{
119.2360 +		reg[15].I += ((s8)(opcode & 0xFF)) << 1;
119.2361 +		armNextPC  = reg[15].I;
119.2362 +		reg[15].I += 2;
119.2363 +		clockTicks = 3;
119.2364 +	}
119.2365 +	break;
119.2366 +case 0xd7:
119.2367 +	// BVC offset
119.2368 +	if (!V_FLAG)
119.2369 +	{
119.2370 +		reg[15].I += ((s8)(opcode & 0xFF)) << 1;
119.2371 +		armNextPC  = reg[15].I;
119.2372 +		reg[15].I += 2;
119.2373 +		clockTicks = 3;
119.2374 +	}
119.2375 +	break;
119.2376 +case 0xd8:
119.2377 +	// BHI offset
119.2378 +	if (C_FLAG && !Z_FLAG)
119.2379 +	{
119.2380 +		reg[15].I += ((s8)(opcode & 0xFF)) << 1;
119.2381 +		armNextPC  = reg[15].I;
119.2382 +		reg[15].I += 2;
119.2383 +		clockTicks = 3;
119.2384 +	}
119.2385 +	break;
119.2386 +case 0xd9:
119.2387 +	// BLS offset
119.2388 +	if (!C_FLAG || Z_FLAG)
119.2389 +	{
119.2390 +		reg[15].I += ((s8)(opcode & 0xFF)) << 1;
119.2391 +		armNextPC  = reg[15].I;
119.2392 +		reg[15].I += 2;
119.2393 +		clockTicks = 3;
119.2394 +	}
119.2395 +	break;
119.2396 +case 0xda:
119.2397 +	// BGE offset
119.2398 +	if (N_FLAG == V_FLAG)
119.2399 +	{
119.2400 +		reg[15].I += ((s8)(opcode & 0xFF)) << 1;
119.2401 +		armNextPC  = reg[15].I;
119.2402 +		reg[15].I += 2;
119.2403 +		clockTicks = 3;
119.2404 +	}
119.2405 +	break;
119.2406 +case 0xdb:
119.2407 +	// BLT offset
119.2408 +	if (N_FLAG != V_FLAG)
119.2409 +	{
119.2410 +		reg[15].I += ((s8)(opcode & 0xFF)) << 1;
119.2411 +		armNextPC  = reg[15].I;
119.2412 +		reg[15].I += 2;
119.2413 +		clockTicks = 3;
119.2414 +	}
119.2415 +	break;
119.2416 +case 0xdc:
119.2417 +	// BGT offset
119.2418 +	if (!Z_FLAG && (N_FLAG == V_FLAG))
119.2419 +	{
119.2420 +		reg[15].I += ((s8)(opcode & 0xFF)) << 1;
119.2421 +		armNextPC  = reg[15].I;
119.2422 +		reg[15].I += 2;
119.2423 +		clockTicks = 3;
119.2424 +	}
119.2425 +	break;
119.2426 +case 0xdd:
119.2427 +	// BLE offset
119.2428 +	if (Z_FLAG || (N_FLAG != V_FLAG))
119.2429 +	{
119.2430 +		reg[15].I += ((s8)(opcode & 0xFF)) << 1;
119.2431 +		armNextPC  = reg[15].I;
119.2432 +		reg[15].I += 2;
119.2433 +		clockTicks = 3;
119.2434 +	}
119.2435 +	break;
119.2436 +case 0xdf:
119.2437 +	// SWI #comment
119.2438 +	CPUSoftwareInterrupt(opcode & 0xFF);
119.2439 +	break;
119.2440 +case 0xe0:
119.2441 +case 0xe1:
119.2442 +case 0xe2:
119.2443 +case 0xe3:
119.2444 +case 0xe4:
119.2445 +case 0xe5:
119.2446 +case 0xe6:
119.2447 +case 0xe7:
119.2448 +{
119.2449 +	// B offset
119.2450 +	int offset = (opcode & 0x3FF) << 1;
119.2451 +	if (opcode & 0x0400)
119.2452 +		offset |= 0xFFFFF800;
119.2453 +	reg[15].I += offset;
119.2454 +	armNextPC  = reg[15].I;
119.2455 +	reg[15].I += 2;
119.2456 +}
119.2457 +break;
119.2458 +case 0xf0:
119.2459 +case 0xf1:
119.2460 +case 0xf2:
119.2461 +case 0xf3:
119.2462 +{
119.2463 +	// BLL #offset
119.2464 +	int offset = (opcode & 0x7FF);
119.2465 +	reg[14].I = reg[15].I + (offset << 12);
119.2466 +}
119.2467 +break;
119.2468 +case 0xf4:
119.2469 +case 0xf5:
119.2470 +case 0xf6:
119.2471 +case 0xf7:
119.2472 +{
119.2473 +	// BLL #offset
119.2474 +	int offset = (opcode & 0x7FF);
119.2475 +	reg[14].I = reg[15].I + ((offset << 12) | 0xFF800000);
119.2476 +}
119.2477 +break;
119.2478 +case 0xf8:
119.2479 +case 0xf9:
119.2480 +case 0xfa:
119.2481 +case 0xfb:
119.2482 +case 0xfc:
119.2483 +case 0xfd:
119.2484 +case 0xfe:
119.2485 +case 0xff:
119.2486 +{
119.2487 +	// BLH #offset
119.2488 +	int offset = (opcode & 0x7FF);
119.2489 +	u32 temp   = reg[15].I - 2;
119.2490 +	reg[15].I  = (reg[14].I + (offset << 1)) & 0xFFFFFFFE;
119.2491 +	armNextPC  = reg[15].I;
119.2492 +	reg[15].I += 2;
119.2493 +	reg[14].I  = temp | 1;
119.2494 +}
119.2495 +break;
119.2496 +#ifdef BKPT_SUPPORT
119.2497 +case 0xbe:
119.2498 +	// BKPT #comment
119.2499 +	extern void (*dbgSignal)(int, int);
119.2500 +	reg[15].I -= 2;
119.2501 +	armNextPC -= 2;
119.2502 +	dbgSignal(5, opcode & 255);
119.2503 +	return;
119.2504 +#endif
119.2505 +case 0xb1:
119.2506 +case 0xb2:
119.2507 +case 0xb3:
119.2508 +case 0xb6:
119.2509 +case 0xb7:
119.2510 +case 0xb8:
119.2511 +case 0xb9:
119.2512 +case 0xba:
119.2513 +case 0xbb:
119.2514 +#ifndef BKPT_SUPPORT
119.2515 +case 0xbe:
119.2516 +#endif
119.2517 +case 0xbf:
119.2518 +case 0xde:
119.2519 +default:
119.2520 +unknown_thumb:
119.2521 +#ifdef GBA_LOGGING
119.2522 +	if (systemVerbose & VERBOSE_UNDEFINED)
119.2523 +		log("Undefined THUMB instruction %04x at %08x\n", opcode, armNextPC - 2);
119.2524 +#endif
119.2525 +	CPUUndefinedException();
119.2526 +	break;
119.2527 +}
   120.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   120.2 +++ b/src/gtk/.deps/gvba-configfile.Po	Sat Mar 03 10:31:27 2012 -0600
   120.3 @@ -0,0 +1,1 @@
   120.4 +# dummy
   121.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   121.2 +++ b/src/gtk/.deps/gvba-filters.Po	Sat Mar 03 10:31:27 2012 -0600
   121.3 @@ -0,0 +1,1 @@
   121.4 +# dummy
   122.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   122.2 +++ b/src/gtk/.deps/gvba-input.Po	Sat Mar 03 10:31:27 2012 -0600
   122.3 @@ -0,0 +1,1 @@
   122.4 +# dummy
   123.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   123.2 +++ b/src/gtk/.deps/gvba-joypadconfig.Po	Sat Mar 03 10:31:27 2012 -0600
   123.3 @@ -0,0 +1,1 @@
   123.4 +# dummy
   124.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   124.2 +++ b/src/gtk/.deps/gvba-main.Po	Sat Mar 03 10:31:27 2012 -0600
   124.3 @@ -0,0 +1,1 @@
   124.4 +# dummy
   125.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   125.2 +++ b/src/gtk/.deps/gvba-screenarea.Po	Sat Mar 03 10:31:27 2012 -0600
   125.3 @@ -0,0 +1,1 @@
   125.4 +# dummy
   126.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   126.2 +++ b/src/gtk/.deps/gvba-system.Po	Sat Mar 03 10:31:27 2012 -0600
   126.3 @@ -0,0 +1,1 @@
   126.4 +# dummy
   127.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   127.2 +++ b/src/gtk/.deps/gvba-tools.Po	Sat Mar 03 10:31:27 2012 -0600
   127.3 @@ -0,0 +1,1 @@
   127.4 +# dummy
   128.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   128.2 +++ b/src/gtk/.deps/gvba-window.Po	Sat Mar 03 10:31:27 2012 -0600
   128.3 @@ -0,0 +1,1 @@
   128.4 +# dummy
   129.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   129.2 +++ b/src/gtk/.deps/gvba-windowcallbacks.Po	Sat Mar 03 10:31:27 2012 -0600
   129.3 @@ -0,0 +1,1 @@
   129.4 +# dummy
   130.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   130.2 +++ b/src/gtk/Makefile	Sat Mar 03 10:31:27 2012 -0600
   130.3 @@ -0,0 +1,817 @@
   130.4 +# Makefile.in generated by automake 1.10.1 from Makefile.am.
   130.5 +# src/gtk/Makefile.  Generated from Makefile.in by configure.
   130.6 +
   130.7 +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
   130.8 +# 2003, 2004, 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
   130.9 +# This Makefile.in is free software; the Free Software Foundation
  130.10 +# gives unlimited permission to copy and/or distribute it,
  130.11 +# with or without modifications, as long as this notice is preserved.
  130.12 +
  130.13 +# This program is distributed in the hope that it will be useful,
  130.14 +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
  130.15 +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  130.16 +# PARTICULAR PURPOSE.
  130.17 +
  130.18 +
  130.19 +
  130.20 +
  130.21 +
  130.22 +
  130.23 +pkgdatadir = $(datadir)/VisualBoyAdvance
  130.24 +pkglibdir = $(libdir)/VisualBoyAdvance
  130.25 +pkgincludedir = $(includedir)/VisualBoyAdvance
  130.26 +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
  130.27 +install_sh_DATA = $(install_sh) -c -m 644
  130.28 +install_sh_PROGRAM = $(install_sh) -c
  130.29 +install_sh_SCRIPT = $(install_sh) -c
  130.30 +INSTALL_HEADER = $(INSTALL_DATA)
  130.31 +transform = $(program_transform_name)
  130.32 +NORMAL_INSTALL = :
  130.33 +PRE_INSTALL = :
  130.34 +POST_INSTALL = :
  130.35 +NORMAL_UNINSTALL = :
  130.36 +PRE_UNINSTALL = :
  130.37 +POST_UNINSTALL = :
  130.38 +build_triplet = x86_64-unknown-linux-gnu
  130.39 +host_triplet = x86_64-unknown-linux-gnu
  130.40 +target_triplet = x86_64-unknown-linux-gnu
  130.41 +bin_PROGRAMS = gvba$(EXEEXT)
  130.42 +subdir = src/gtk
  130.43 +DIST_COMMON = $(dist_pkgdata_DATA) $(srcdir)/Makefile.am \
  130.44 +	$(srcdir)/Makefile.in
  130.45 +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
  130.46 +am__aclocal_m4_deps = $(top_srcdir)/m4/gettext.m4 \
  130.47 +	$(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/lib-ld.m4 \
  130.48 +	$(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
  130.49 +	$(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/po.m4 \
  130.50 +	$(top_srcdir)/m4/progtest.m4 $(top_srcdir)/acinclude.m4 \
  130.51 +	$(top_srcdir)/configure.in
  130.52 +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
  130.53 +	$(ACLOCAL_M4)
  130.54 +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
  130.55 +CONFIG_CLEAN_FILES =
  130.56 +LIBRARIES = $(noinst_LIBRARIES)
  130.57 +AR = ar
  130.58 +ARFLAGS = cru
  130.59 +libgvba_a_AR = $(AR) $(ARFLAGS)
  130.60 +libgvba_a_LIBADD =
  130.61 +am_libgvba_a_OBJECTS =
  130.62 +libgvba_a_OBJECTS = $(am_libgvba_a_OBJECTS)
  130.63 +am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(pkgdatadir)"
  130.64 +binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
  130.65 +PROGRAMS = $(bin_PROGRAMS)
  130.66 +am_gvba_OBJECTS = gvba-configfile.$(OBJEXT) gvba-filters.$(OBJEXT) \
  130.67 +	gvba-input.$(OBJEXT) gvba-joypadconfig.$(OBJEXT) \
  130.68 +	gvba-main.$(OBJEXT) gvba-screenarea.$(OBJEXT) \
  130.69 +	gvba-system.$(OBJEXT) gvba-tools.$(OBJEXT) \
  130.70 +	gvba-windowcallbacks.$(OBJEXT) gvba-window.$(OBJEXT)
  130.71 +gvba_OBJECTS = $(am_gvba_OBJECTS)
  130.72 +gvba_LINK = $(CXXLD) $(gvba_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \
  130.73 +	$(LDFLAGS) -o $@
  130.74 +DEFAULT_INCLUDES = -I.
  130.75 +depcomp = $(SHELL) $(top_srcdir)/depcomp
  130.76 +am__depfiles_maybe = depfiles
  130.77 +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
  130.78 +	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
  130.79 +CXXLD = $(CXX)
  130.80 +CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
  130.81 +	-o $@
  130.82 +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
  130.83 +	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
  130.84 +CCLD = $(CC)
  130.85 +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
  130.86 +SOURCES = $(libgvba_a_SOURCES) $(gvba_SOURCES)
  130.87 +DIST_SOURCES = $(libgvba_a_SOURCES) $(gvba_SOURCES)
  130.88 +RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
  130.89 +	html-recursive info-recursive install-data-recursive \
  130.90 +	install-dvi-recursive install-exec-recursive \
  130.91 +	install-html-recursive install-info-recursive \
  130.92 +	install-pdf-recursive install-ps-recursive install-recursive \
  130.93 +	installcheck-recursive installdirs-recursive pdf-recursive \
  130.94 +	ps-recursive uninstall-recursive
  130.95 +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
  130.96 +am__vpath_adj = case $$p in \
  130.97 +    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
  130.98 +    *) f=$$p;; \
  130.99 +  esac;
 130.100 +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
 130.101 +dist_pkgdataDATA_INSTALL = $(INSTALL_DATA)
 130.102 +DATA = $(dist_pkgdata_DATA)
 130.103 +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive	\
 130.104 +  distclean-recursive maintainer-clean-recursive
 130.105 +ETAGS = etags
 130.106 +CTAGS = ctags
 130.107 +DIST_SUBDIRS = $(SUBDIRS)
 130.108 +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 130.109 +ACLOCAL = ${SHELL} /home/r/proj/vba/trunk/missing --run aclocal-1.10
 130.110 +AMTAR = ${SHELL} /home/r/proj/vba/trunk/missing --run tar
 130.111 +AUTOCONF = ${SHELL} /home/r/proj/vba/trunk/missing --run autoconf
 130.112 +AUTOHEADER = ${SHELL} /home/r/proj/vba/trunk/missing --run autoheader
 130.113 +AUTOMAKE = ${SHELL} /home/r/proj/vba/trunk/missing --run automake-1.10
 130.114 +AWK = gawk
 130.115 +CC = gcc
 130.116 +CCDEPMODE = depmode=gcc3
 130.117 +CFLAGS = -g -O2
 130.118 +CPP = gcc -E
 130.119 +CPPFLAGS = 
 130.120 +CXX = g++
 130.121 +CXXDEPMODE = depmode=gcc3
 130.122 +CXXFLAGS = -g -O2 -DC_CORE -DPROFILING -DDEV_VERSION
 130.123 +CYGPATH_W = echo
 130.124 +DEFS = -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"VisualBoyAdvance\" -DVERSION=\"1.7.2\" -DYYTEXT_POINTER=1 -DHAVE_LIBZ=1 -DHAVE_LIBPNG=1 -DHAVE_LIBPTHREAD=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_MALLOC_H=1 -DHAVE_STRINGS_H=1 -DHAVE_UNISTD_H=1 -DHAVE_ARPA_INET_H=1 -DHAVE_NETINET_IN_H=1
 130.125 +DEPDIR = .deps
 130.126 +ECHO_C = 
 130.127 +ECHO_N = -n
 130.128 +ECHO_T = 
 130.129 +EGREP = /bin/grep -E
 130.130 +EXEEXT = 
 130.131 +GETTEXT_PACKAGE = 
 130.132 +GMSGFMT = 
 130.133 +GREP = /bin/grep
 130.134 +GTKMM_CFLAGS = 
 130.135 +GTKMM_CPPFLAGS = 
 130.136 +GTKMM_LIBS = 
 130.137 +INSTALL = /usr/bin/install -c
 130.138 +INSTALL_DATA = ${INSTALL} -m 644
 130.139 +INSTALL_PROGRAM = ${INSTALL}
 130.140 +INSTALL_SCRIPT = ${INSTALL}
 130.141 +INSTALL_STRIP_PROGRAM = $(install_sh) -c -s
 130.142 +INTLLIBS = 
 130.143 +LDFLAGS = 
 130.144 +LEX = flex
 130.145 +LEXLIB = -lfl
 130.146 +LEX_OUTPUT_ROOT = lex.yy
 130.147 +LIBICONV = 
 130.148 +LIBINTL = 
 130.149 +LIBOBJS = 
 130.150 +LIBS = -lpthread -lpng -lz 
 130.151 +LTLIBICONV = 
 130.152 +LTLIBINTL = 
 130.153 +LTLIBOBJS = 
 130.154 +MAKEINFO = ${SHELL} /home/r/proj/vba/trunk/missing --run makeinfo
 130.155 +MKDIR_P = /bin/mkdir -p
 130.156 +MKINSTALLDIRS = 
 130.157 +MSGFMT = 
 130.158 +MSGMERGE = 
 130.159 +NASM = /usr/bin/nasm
 130.160 +OBJEXT = o
 130.161 +PACKAGE = VisualBoyAdvance
 130.162 +PACKAGE_BUGREPORT = 
 130.163 +PACKAGE_NAME = 
 130.164 +PACKAGE_STRING = 
 130.165 +PACKAGE_TARNAME = 
 130.166 +PACKAGE_VERSION = 
 130.167 +PATH_SEPARATOR = :
 130.168 +PKG_CONFIG = 
 130.169 +POSUB = 
 130.170 +RANLIB = ranlib
 130.171 +SDL_CFLAGS = -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT
 130.172 +SDL_CONFIG = /usr/bin/sdl-config
 130.173 +SDL_LIBS = -L/usr/lib -Wl,-rpath,/usr/lib -lSDL -lpthread
 130.174 +SET_MAKE = 
 130.175 +SHELL = /bin/sh
 130.176 +STRIP = 
 130.177 +USE_NLS = 
 130.178 +VBA_EXTRA = 
 130.179 +VBA_LIBS = ../gba/libgba.a ../gb/libgb.a ../common/libgbcom.a ../filters/libfilter.a ../lua/libgblua.a ../prof/libprof.a
 130.180 +VBA_SRC_EXTRA =  lua prof sdl
 130.181 +VERSION = 1.7.2
 130.182 +XGETTEXT = 
 130.183 +XMKMF = 
 130.184 +YACC = bison -y
 130.185 +YFLAGS = 
 130.186 +abs_builddir = /home/r/proj/vba/trunk/src/gtk
 130.187 +abs_srcdir = /home/r/proj/vba/trunk/src/gtk
 130.188 +abs_top_builddir = /home/r/proj/vba/trunk
 130.189 +abs_top_srcdir = /home/r/proj/vba/trunk
 130.190 +ac_ct_CC = gcc
 130.191 +ac_ct_CXX = g++
 130.192 +am__include = include
 130.193 +am__leading_dot = .
 130.194 +am__quote = 
 130.195 +am__tar = ${AMTAR} chof - "$$tardir"
 130.196 +am__untar = ${AMTAR} xf -
 130.197 +bindir = ${exec_prefix}/bin
 130.198 +build = x86_64-unknown-linux-gnu
 130.199 +build_alias = 
 130.200 +build_cpu = x86_64
 130.201 +build_os = linux-gnu
 130.202 +build_vendor = unknown
 130.203 +builddir = .
 130.204 +datadir = ${datarootdir}
 130.205 +datarootdir = ${prefix}/share
 130.206 +docdir = ${datarootdir}/doc/${PACKAGE}
 130.207 +dvidir = ${docdir}
 130.208 +exec_prefix = ${prefix}
 130.209 +host = x86_64-unknown-linux-gnu
 130.210 +host_alias = 
 130.211 +host_cpu = x86_64
 130.212 +host_os = linux-gnu
 130.213 +host_vendor = unknown
 130.214 +htmldir = ${docdir}
 130.215 +includedir = ${prefix}/include
 130.216 +infodir = ${datarootdir}/info
 130.217 +install_sh = $(SHELL) /home/r/proj/vba/trunk/install-sh
 130.218 +libdir = ${exec_prefix}/lib
 130.219 +libexecdir = ${exec_prefix}/libexec
 130.220 +localedir = ${datarootdir}/locale
 130.221 +localstatedir = ${prefix}/var
 130.222 +mandir = ${datarootdir}/man
 130.223 +mkdir_p = /bin/mkdir -p
 130.224 +oldincludedir = /usr/include
 130.225 +pdfdir = ${docdir}
 130.226 +prefix = /usr/local
 130.227 +program_transform_name = s,x,x,
 130.228 +psdir = ${docdir}
 130.229 +sbindir = ${exec_prefix}/sbin
 130.230 +sharedstatedir = ${prefix}/com
 130.231 +srcdir = .
 130.232 +sysconfdir = ${prefix}/etc
 130.233 +target = x86_64-unknown-linux-gnu
 130.234 +target_alias = 
 130.235 +target_cpu = x86_64
 130.236 +target_os = linux-gnu
 130.237 +target_vendor = unknown
 130.238 +top_builddir = ../..
 130.239 +top_srcdir = ../..
 130.240 +SUBDIRS = images
 130.241 +noinst_LIBRARIES = libgvba.a
 130.242 +gvba_SOURCES = \
 130.243 +	configfile.cpp		\
 130.244 +	configfile.h		\
 130.245 +	filters.cpp		\
 130.246 +	filters.h		\
 130.247 +	input.cpp		\
 130.248 +	input.h			\
 130.249 +	intl.h			\
 130.250 +	joypadconfig.cpp	\
 130.251 +	joypadconfig.h		\
 130.252 +	main.cpp		\
 130.253 +	menuitem.h		\
 130.254 +	screenarea.cpp		\
 130.255 +	screenarea.h		\
 130.256 +	sigccompat.h		\
 130.257 +	system.cpp		\
 130.258 +	tools.cpp		\
 130.259 +	tools.h			\
 130.260 +	windowcallbacks.cpp	\
 130.261 +	window.cpp		\
 130.262 +	window.h
 130.263 +
 130.264 +gvba_LDADD = libgvba.a ../gba/libgba.a ../gb/libgb.a ../common/libgbcom.a ../filters/libfilter.a ../lua/libgblua.a ../prof/libprof.a   -L/usr/lib -Wl,-rpath,/usr/lib -lSDL -lpthread
 130.265 +gvba_DEPENDENCIES = libgvba.a ../gba/libgba.a ../gb/libgb.a ../common/libgbcom.a ../filters/libfilter.a ../lua/libgblua.a ../prof/libprof.a
 130.266 +gvba_CPPFLAGS = \
 130.267 +	-DPKGDATADIR=\"$(pkgdatadir)\"			\
 130.268 +	-DLOCALEDIR=\"$(datadir)/locale\"		\
 130.269 +	-DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\"	\
 130.270 +	$(GTKMM_CPPFLAGS)
 130.271 +
 130.272 +gvba_CXXFLAGS =  -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT
 130.273 +libgvba_a_SOURCES = \
 130.274 +	../AutoBuild.h		\
 130.275 +	../NLS.h		\
 130.276 +	../Port.h
 130.277 +
 130.278 +libgvba_a_CPPFLAGS = -DSDL
 130.279 +libgvba_a_CXXFLAGS = -fno-exceptions
 130.280 +dist_pkgdata_DATA = vba.glade
 130.281 +all: all-recursive
 130.282 +
 130.283 +.SUFFIXES:
 130.284 +.SUFFIXES: .cpp .o .obj
 130.285 +$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
 130.286 +	@for dep in $?; do \
 130.287 +	  case '$(am__configure_deps)' in \
 130.288 +	    *$$dep*) \
 130.289 +	      cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
 130.290 +		&& exit 0; \
 130.291 +	      exit 1;; \
 130.292 +	  esac; \
 130.293 +	done; \
 130.294 +	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu  src/gtk/Makefile'; \
 130.295 +	cd $(top_srcdir) && \
 130.296 +	  $(AUTOMAKE) --gnu  src/gtk/Makefile
 130.297 +.PRECIOUS: Makefile
 130.298 +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 130.299 +	@case '$?' in \
 130.300 +	  *config.status*) \
 130.301 +	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 130.302 +	  *) \
 130.303 +	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
 130.304 +	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
 130.305 +	esac;
 130.306 +
 130.307 +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
 130.308 +	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 130.309 +
 130.310 +$(top_srcdir)/configure:  $(am__configure_deps)
 130.311 +	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 130.312 +$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
 130.313 +	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 130.314 +
 130.315 +clean-noinstLIBRARIES:
 130.316 +	-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
 130.317 +libgvba.a: $(libgvba_a_OBJECTS) $(libgvba_a_DEPENDENCIES) 
 130.318 +	-rm -f libgvba.a
 130.319 +	$(libgvba_a_AR) libgvba.a $(libgvba_a_OBJECTS) $(libgvba_a_LIBADD)
 130.320 +	$(RANLIB) libgvba.a
 130.321 +install-binPROGRAMS: $(bin_PROGRAMS)
 130.322 +	@$(NORMAL_INSTALL)
 130.323 +	test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
 130.324 +	@list='$(bin_PROGRAMS)'; for p in $$list; do \
 130.325 +	  p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
 130.326 +	  if test -f $$p \
 130.327 +	  ; then \
 130.328 +	    f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
 130.329 +	   echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
 130.330 +	   $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
 130.331 +	  else :; fi; \
 130.332 +	done
 130.333 +
 130.334 +uninstall-binPROGRAMS:
 130.335 +	@$(NORMAL_UNINSTALL)
 130.336 +	@list='$(bin_PROGRAMS)'; for p in $$list; do \
 130.337 +	  f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
 130.338 +	  echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
 130.339 +	  rm -f "$(DESTDIR)$(bindir)/$$f"; \
 130.340 +	done
 130.341 +
 130.342 +clean-binPROGRAMS:
 130.343 +	-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
 130.344 +gvba$(EXEEXT): $(gvba_OBJECTS) $(gvba_DEPENDENCIES) 
 130.345 +	@rm -f gvba$(EXEEXT)
 130.346 +	$(gvba_LINK) $(gvba_OBJECTS) $(gvba_LDADD) $(LIBS)
 130.347 +
 130.348 +mostlyclean-compile:
 130.349 +	-rm -f *.$(OBJEXT)
 130.350 +
 130.351 +distclean-compile:
 130.352 +	-rm -f *.tab.c
 130.353 +
 130.354 +include ./$(DEPDIR)/gvba-configfile.Po
 130.355 +include ./$(DEPDIR)/gvba-filters.Po
 130.356 +include ./$(DEPDIR)/gvba-input.Po
 130.357 +include ./$(DEPDIR)/gvba-joypadconfig.Po
 130.358 +include ./$(DEPDIR)/gvba-main.Po
 130.359 +include ./$(DEPDIR)/gvba-screenarea.Po
 130.360 +include ./$(DEPDIR)/gvba-system.Po
 130.361 +include ./$(DEPDIR)/gvba-tools.Po
 130.362 +include ./$(DEPDIR)/gvba-window.Po
 130.363 +include ./$(DEPDIR)/gvba-windowcallbacks.Po
 130.364 +
 130.365 +.cpp.o:
 130.366 +	$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
 130.367 +	mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
 130.368 +#	source='$<' object='$@' libtool=no \
 130.369 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.370 +#	$(CXXCOMPILE) -c -o $@ $<
 130.371 +
 130.372 +.cpp.obj:
 130.373 +	$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
 130.374 +	mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
 130.375 +#	source='$<' object='$@' libtool=no \
 130.376 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.377 +#	$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
 130.378 +
 130.379 +gvba-configfile.o: configfile.cpp
 130.380 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-configfile.o -MD -MP -MF $(DEPDIR)/gvba-configfile.Tpo -c -o gvba-configfile.o `test -f 'configfile.cpp' || echo '$(srcdir)/'`configfile.cpp
 130.381 +	mv -f $(DEPDIR)/gvba-configfile.Tpo $(DEPDIR)/gvba-configfile.Po
 130.382 +#	source='configfile.cpp' object='gvba-configfile.o' libtool=no \
 130.383 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.384 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-configfile.o `test -f 'configfile.cpp' || echo '$(srcdir)/'`configfile.cpp
 130.385 +
 130.386 +gvba-configfile.obj: configfile.cpp
 130.387 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-configfile.obj -MD -MP -MF $(DEPDIR)/gvba-configfile.Tpo -c -o gvba-configfile.obj `if test -f 'configfile.cpp'; then $(CYGPATH_W) 'configfile.cpp'; else $(CYGPATH_W) '$(srcdir)/configfile.cpp'; fi`
 130.388 +	mv -f $(DEPDIR)/gvba-configfile.Tpo $(DEPDIR)/gvba-configfile.Po
 130.389 +#	source='configfile.cpp' object='gvba-configfile.obj' libtool=no \
 130.390 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.391 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-configfile.obj `if test -f 'configfile.cpp'; then $(CYGPATH_W) 'configfile.cpp'; else $(CYGPATH_W) '$(srcdir)/configfile.cpp'; fi`
 130.392 +
 130.393 +gvba-filters.o: filters.cpp
 130.394 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-filters.o -MD -MP -MF $(DEPDIR)/gvba-filters.Tpo -c -o gvba-filters.o `test -f 'filters.cpp' || echo '$(srcdir)/'`filters.cpp
 130.395 +	mv -f $(DEPDIR)/gvba-filters.Tpo $(DEPDIR)/gvba-filters.Po
 130.396 +#	source='filters.cpp' object='gvba-filters.o' libtool=no \
 130.397 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.398 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-filters.o `test -f 'filters.cpp' || echo '$(srcdir)/'`filters.cpp
 130.399 +
 130.400 +gvba-filters.obj: filters.cpp
 130.401 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-filters.obj -MD -MP -MF $(DEPDIR)/gvba-filters.Tpo -c -o gvba-filters.obj `if test -f 'filters.cpp'; then $(CYGPATH_W) 'filters.cpp'; else $(CYGPATH_W) '$(srcdir)/filters.cpp'; fi`
 130.402 +	mv -f $(DEPDIR)/gvba-filters.Tpo $(DEPDIR)/gvba-filters.Po
 130.403 +#	source='filters.cpp' object='gvba-filters.obj' libtool=no \
 130.404 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.405 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-filters.obj `if test -f 'filters.cpp'; then $(CYGPATH_W) 'filters.cpp'; else $(CYGPATH_W) '$(srcdir)/filters.cpp'; fi`
 130.406 +
 130.407 +gvba-input.o: input.cpp
 130.408 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-input.o -MD -MP -MF $(DEPDIR)/gvba-input.Tpo -c -o gvba-input.o `test -f 'input.cpp' || echo '$(srcdir)/'`input.cpp
 130.409 +	mv -f $(DEPDIR)/gvba-input.Tpo $(DEPDIR)/gvba-input.Po
 130.410 +#	source='input.cpp' object='gvba-input.o' libtool=no \
 130.411 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.412 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-input.o `test -f 'input.cpp' || echo '$(srcdir)/'`input.cpp
 130.413 +
 130.414 +gvba-input.obj: input.cpp
 130.415 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-input.obj -MD -MP -MF $(DEPDIR)/gvba-input.Tpo -c -o gvba-input.obj `if test -f 'input.cpp'; then $(CYGPATH_W) 'input.cpp'; else $(CYGPATH_W) '$(srcdir)/input.cpp'; fi`
 130.416 +	mv -f $(DEPDIR)/gvba-input.Tpo $(DEPDIR)/gvba-input.Po
 130.417 +#	source='input.cpp' object='gvba-input.obj' libtool=no \
 130.418 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.419 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-input.obj `if test -f 'input.cpp'; then $(CYGPATH_W) 'input.cpp'; else $(CYGPATH_W) '$(srcdir)/input.cpp'; fi`
 130.420 +
 130.421 +gvba-joypadconfig.o: joypadconfig.cpp
 130.422 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-joypadconfig.o -MD -MP -MF $(DEPDIR)/gvba-joypadconfig.Tpo -c -o gvba-joypadconfig.o `test -f 'joypadconfig.cpp' || echo '$(srcdir)/'`joypadconfig.cpp
 130.423 +	mv -f $(DEPDIR)/gvba-joypadconfig.Tpo $(DEPDIR)/gvba-joypadconfig.Po
 130.424 +#	source='joypadconfig.cpp' object='gvba-joypadconfig.o' libtool=no \
 130.425 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.426 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-joypadconfig.o `test -f 'joypadconfig.cpp' || echo '$(srcdir)/'`joypadconfig.cpp
 130.427 +
 130.428 +gvba-joypadconfig.obj: joypadconfig.cpp
 130.429 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-joypadconfig.obj -MD -MP -MF $(DEPDIR)/gvba-joypadconfig.Tpo -c -o gvba-joypadconfig.obj `if test -f 'joypadconfig.cpp'; then $(CYGPATH_W) 'joypadconfig.cpp'; else $(CYGPATH_W) '$(srcdir)/joypadconfig.cpp'; fi`
 130.430 +	mv -f $(DEPDIR)/gvba-joypadconfig.Tpo $(DEPDIR)/gvba-joypadconfig.Po
 130.431 +#	source='joypadconfig.cpp' object='gvba-joypadconfig.obj' libtool=no \
 130.432 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.433 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-joypadconfig.obj `if test -f 'joypadconfig.cpp'; then $(CYGPATH_W) 'joypadconfig.cpp'; else $(CYGPATH_W) '$(srcdir)/joypadconfig.cpp'; fi`
 130.434 +
 130.435 +gvba-main.o: main.cpp
 130.436 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-main.o -MD -MP -MF $(DEPDIR)/gvba-main.Tpo -c -o gvba-main.o `test -f 'main.cpp' || echo '$(srcdir)/'`main.cpp
 130.437 +	mv -f $(DEPDIR)/gvba-main.Tpo $(DEPDIR)/gvba-main.Po
 130.438 +#	source='main.cpp' object='gvba-main.o' libtool=no \
 130.439 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.440 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-main.o `test -f 'main.cpp' || echo '$(srcdir)/'`main.cpp
 130.441 +
 130.442 +gvba-main.obj: main.cpp
 130.443 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-main.obj -MD -MP -MF $(DEPDIR)/gvba-main.Tpo -c -o gvba-main.obj `if test -f 'main.cpp'; then $(CYGPATH_W) 'main.cpp'; else $(CYGPATH_W) '$(srcdir)/main.cpp'; fi`
 130.444 +	mv -f $(DEPDIR)/gvba-main.Tpo $(DEPDIR)/gvba-main.Po
 130.445 +#	source='main.cpp' object='gvba-main.obj' libtool=no \
 130.446 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.447 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-main.obj `if test -f 'main.cpp'; then $(CYGPATH_W) 'main.cpp'; else $(CYGPATH_W) '$(srcdir)/main.cpp'; fi`
 130.448 +
 130.449 +gvba-screenarea.o: screenarea.cpp
 130.450 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-screenarea.o -MD -MP -MF $(DEPDIR)/gvba-screenarea.Tpo -c -o gvba-screenarea.o `test -f 'screenarea.cpp' || echo '$(srcdir)/'`screenarea.cpp
 130.451 +	mv -f $(DEPDIR)/gvba-screenarea.Tpo $(DEPDIR)/gvba-screenarea.Po
 130.452 +#	source='screenarea.cpp' object='gvba-screenarea.o' libtool=no \
 130.453 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.454 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-screenarea.o `test -f 'screenarea.cpp' || echo '$(srcdir)/'`screenarea.cpp
 130.455 +
 130.456 +gvba-screenarea.obj: screenarea.cpp
 130.457 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-screenarea.obj -MD -MP -MF $(DEPDIR)/gvba-screenarea.Tpo -c -o gvba-screenarea.obj `if test -f 'screenarea.cpp'; then $(CYGPATH_W) 'screenarea.cpp'; else $(CYGPATH_W) '$(srcdir)/screenarea.cpp'; fi`
 130.458 +	mv -f $(DEPDIR)/gvba-screenarea.Tpo $(DEPDIR)/gvba-screenarea.Po
 130.459 +#	source='screenarea.cpp' object='gvba-screenarea.obj' libtool=no \
 130.460 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.461 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-screenarea.obj `if test -f 'screenarea.cpp'; then $(CYGPATH_W) 'screenarea.cpp'; else $(CYGPATH_W) '$(srcdir)/screenarea.cpp'; fi`
 130.462 +
 130.463 +gvba-system.o: system.cpp
 130.464 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-system.o -MD -MP -MF $(DEPDIR)/gvba-system.Tpo -c -o gvba-system.o `test -f 'system.cpp' || echo '$(srcdir)/'`system.cpp
 130.465 +	mv -f $(DEPDIR)/gvba-system.Tpo $(DEPDIR)/gvba-system.Po
 130.466 +#	source='system.cpp' object='gvba-system.o' libtool=no \
 130.467 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.468 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-system.o `test -f 'system.cpp' || echo '$(srcdir)/'`system.cpp
 130.469 +
 130.470 +gvba-system.obj: system.cpp
 130.471 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-system.obj -MD -MP -MF $(DEPDIR)/gvba-system.Tpo -c -o gvba-system.obj `if test -f 'system.cpp'; then $(CYGPATH_W) 'system.cpp'; else $(CYGPATH_W) '$(srcdir)/system.cpp'; fi`
 130.472 +	mv -f $(DEPDIR)/gvba-system.Tpo $(DEPDIR)/gvba-system.Po
 130.473 +#	source='system.cpp' object='gvba-system.obj' libtool=no \
 130.474 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.475 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-system.obj `if test -f 'system.cpp'; then $(CYGPATH_W) 'system.cpp'; else $(CYGPATH_W) '$(srcdir)/system.cpp'; fi`
 130.476 +
 130.477 +gvba-tools.o: tools.cpp
 130.478 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-tools.o -MD -MP -MF $(DEPDIR)/gvba-tools.Tpo -c -o gvba-tools.o `test -f 'tools.cpp' || echo '$(srcdir)/'`tools.cpp
 130.479 +	mv -f $(DEPDIR)/gvba-tools.Tpo $(DEPDIR)/gvba-tools.Po
 130.480 +#	source='tools.cpp' object='gvba-tools.o' libtool=no \
 130.481 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.482 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-tools.o `test -f 'tools.cpp' || echo '$(srcdir)/'`tools.cpp
 130.483 +
 130.484 +gvba-tools.obj: tools.cpp
 130.485 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-tools.obj -MD -MP -MF $(DEPDIR)/gvba-tools.Tpo -c -o gvba-tools.obj `if test -f 'tools.cpp'; then $(CYGPATH_W) 'tools.cpp'; else $(CYGPATH_W) '$(srcdir)/tools.cpp'; fi`
 130.486 +	mv -f $(DEPDIR)/gvba-tools.Tpo $(DEPDIR)/gvba-tools.Po
 130.487 +#	source='tools.cpp' object='gvba-tools.obj' libtool=no \
 130.488 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.489 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-tools.obj `if test -f 'tools.cpp'; then $(CYGPATH_W) 'tools.cpp'; else $(CYGPATH_W) '$(srcdir)/tools.cpp'; fi`
 130.490 +
 130.491 +gvba-windowcallbacks.o: windowcallbacks.cpp
 130.492 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-windowcallbacks.o -MD -MP -MF $(DEPDIR)/gvba-windowcallbacks.Tpo -c -o gvba-windowcallbacks.o `test -f 'windowcallbacks.cpp' || echo '$(srcdir)/'`windowcallbacks.cpp
 130.493 +	mv -f $(DEPDIR)/gvba-windowcallbacks.Tpo $(DEPDIR)/gvba-windowcallbacks.Po
 130.494 +#	source='windowcallbacks.cpp' object='gvba-windowcallbacks.o' libtool=no \
 130.495 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.496 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-windowcallbacks.o `test -f 'windowcallbacks.cpp' || echo '$(srcdir)/'`windowcallbacks.cpp
 130.497 +
 130.498 +gvba-windowcallbacks.obj: windowcallbacks.cpp
 130.499 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-windowcallbacks.obj -MD -MP -MF $(DEPDIR)/gvba-windowcallbacks.Tpo -c -o gvba-windowcallbacks.obj `if test -f 'windowcallbacks.cpp'; then $(CYGPATH_W) 'windowcallbacks.cpp'; else $(CYGPATH_W) '$(srcdir)/windowcallbacks.cpp'; fi`
 130.500 +	mv -f $(DEPDIR)/gvba-windowcallbacks.Tpo $(DEPDIR)/gvba-windowcallbacks.Po
 130.501 +#	source='windowcallbacks.cpp' object='gvba-windowcallbacks.obj' libtool=no \
 130.502 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.503 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-windowcallbacks.obj `if test -f 'windowcallbacks.cpp'; then $(CYGPATH_W) 'windowcallbacks.cpp'; else $(CYGPATH_W) '$(srcdir)/windowcallbacks.cpp'; fi`
 130.504 +
 130.505 +gvba-window.o: window.cpp
 130.506 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-window.o -MD -MP -MF $(DEPDIR)/gvba-window.Tpo -c -o gvba-window.o `test -f 'window.cpp' || echo '$(srcdir)/'`window.cpp
 130.507 +	mv -f $(DEPDIR)/gvba-window.Tpo $(DEPDIR)/gvba-window.Po
 130.508 +#	source='window.cpp' object='gvba-window.o' libtool=no \
 130.509 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.510 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-window.o `test -f 'window.cpp' || echo '$(srcdir)/'`window.cpp
 130.511 +
 130.512 +gvba-window.obj: window.cpp
 130.513 +	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -MT gvba-window.obj -MD -MP -MF $(DEPDIR)/gvba-window.Tpo -c -o gvba-window.obj `if test -f 'window.cpp'; then $(CYGPATH_W) 'window.cpp'; else $(CYGPATH_W) '$(srcdir)/window.cpp'; fi`
 130.514 +	mv -f $(DEPDIR)/gvba-window.Tpo $(DEPDIR)/gvba-window.Po
 130.515 +#	source='window.cpp' object='gvba-window.obj' libtool=no \
 130.516 +#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 130.517 +#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(gvba_CPPFLAGS) $(CPPFLAGS) $(gvba_CXXFLAGS) $(CXXFLAGS) -c -o gvba-window.obj `if test -f 'window.cpp'; then $(CYGPATH_W) 'window.cpp'; else $(CYGPATH_W) '$(srcdir)/window.cpp'; fi`
 130.518 +install-dist_pkgdataDATA: $(dist_pkgdata_DATA)
 130.519 +	@$(NORMAL_INSTALL)
 130.520 +	test -z "$(pkgdatadir)" || $(MKDIR_P) "$(DESTDIR)$(pkgdatadir)"
 130.521 +	@list='$(dist_pkgdata_DATA)'; for p in $$list; do \
 130.522 +	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
 130.523 +	  f=$(am__strip_dir) \
 130.524 +	  echo " $(dist_pkgdataDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(pkgdatadir)/$$f'"; \
 130.525 +	  $(dist_pkgdataDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(pkgdatadir)/$$f"; \
 130.526 +	done
 130.527 +
 130.528 +uninstall-dist_pkgdataDATA:
 130.529 +	@$(NORMAL_UNINSTALL)
 130.530 +	@list='$(dist_pkgdata_DATA)'; for p in $$list; do \
 130.531 +	  f=$(am__strip_dir) \
 130.532 +	  echo " rm -f '$(DESTDIR)$(pkgdatadir)/$$f'"; \
 130.533 +	  rm -f "$(DESTDIR)$(pkgdatadir)/$$f"; \
 130.534 +	done
 130.535 +
 130.536 +# This directory's subdirectories are mostly independent; you can cd
 130.537 +# into them and run `make' without going through this Makefile.
 130.538 +# To change the values of `make' variables: instead of editing Makefiles,
 130.539 +# (1) if the variable is set in `config.status', edit `config.status'
 130.540 +#     (which will cause the Makefiles to be regenerated when you run `make');
 130.541 +# (2) otherwise, pass the desired values on the `make' command line.
 130.542 +$(RECURSIVE_TARGETS):
 130.543 +	@failcom='exit 1'; \
 130.544 +	for f in x $$MAKEFLAGS; do \
 130.545 +	  case $$f in \
 130.546 +	    *=* | --[!k]*);; \
 130.547 +	    *k*) failcom='fail=yes';; \
 130.548 +	  esac; \
 130.549 +	done; \
 130.550 +	dot_seen=no; \
 130.551 +	target=`echo $@ | sed s/-recursive//`; \
 130.552 +	list='$(SUBDIRS)'; for subdir in $$list; do \
 130.553 +	  echo "Making $$target in $$subdir"; \
 130.554 +	  if test "$$subdir" = "."; then \
 130.555 +	    dot_seen=yes; \
 130.556 +	    local_target="$$target-am"; \
 130.557 +	  else \
 130.558 +	    local_target="$$target"; \
 130.559 +	  fi; \
 130.560 +	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
 130.561 +	  || eval $$failcom; \
 130.562 +	done; \
 130.563 +	if test "$$dot_seen" = "no"; then \
 130.564 +	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
 130.565 +	fi; test -z "$$fail"
 130.566 +
 130.567 +$(RECURSIVE_CLEAN_TARGETS):
 130.568 +	@failcom='exit 1'; \
 130.569 +	for f in x $$MAKEFLAGS; do \
 130.570 +	  case $$f in \
 130.571 +	    *=* | --[!k]*);; \
 130.572 +	    *k*) failcom='fail=yes';; \
 130.573 +	  esac; \
 130.574 +	done; \
 130.575 +	dot_seen=no; \
 130.576 +	case "$@" in \
 130.577 +	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
 130.578 +	  *) list='$(SUBDIRS)' ;; \
 130.579 +	esac; \
 130.580 +	rev=''; for subdir in $$list; do \
 130.581 +	  if test "$$subdir" = "."; then :; else \
 130.582 +	    rev="$$subdir $$rev"; \
 130.583 +	  fi; \
 130.584 +	done; \
 130.585 +	rev="$$rev ."; \
 130.586 +	target=`echo $@ | sed s/-recursive//`; \
 130.587 +	for subdir in $$rev; do \
 130.588 +	  echo "Making $$target in $$subdir"; \
 130.589 +	  if test "$$subdir" = "."; then \
 130.590 +	    local_target="$$target-am"; \
 130.591 +	  else \
 130.592 +	    local_target="$$target"; \
 130.593 +	  fi; \
 130.594 +	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
 130.595 +	  || eval $$failcom; \
 130.596 +	done && test -z "$$fail"
 130.597 +tags-recursive:
 130.598 +	list='$(SUBDIRS)'; for subdir in $$list; do \
 130.599 +	  test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
 130.600 +	done
 130.601 +ctags-recursive:
 130.602 +	list='$(SUBDIRS)'; for subdir in $$list; do \
 130.603 +	  test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
 130.604 +	done
 130.605 +
 130.606 +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
 130.607 +	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
 130.608 +	unique=`for i in $$list; do \
 130.609 +	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
 130.610 +	  done | \
 130.611 +	  $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
 130.612 +	      END { if (nonempty) { for (i in files) print i; }; }'`; \
 130.613 +	mkid -fID $$unique
 130.614 +tags: TAGS
 130.615 +
 130.616 +TAGS: tags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
 130.617 +		$(TAGS_FILES) $(LISP)
 130.618 +	tags=; \
 130.619 +	here=`pwd`; \
 130.620 +	if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
 130.621 +	  include_option=--etags-include; \
 130.622 +	  empty_fix=.; \
 130.623 +	else \
 130.624 +	  include_option=--include; \
 130.625 +	  empty_fix=; \
 130.626 +	fi; \
 130.627 +	list='$(SUBDIRS)'; for subdir in $$list; do \
 130.628 +	  if test "$$subdir" = .; then :; else \
 130.629 +	    test ! -f $$subdir/TAGS || \
 130.630 +	      tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \
 130.631 +	  fi; \
 130.632 +	done; \
 130.633 +	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
 130.634 +	unique=`for i in $$list; do \
 130.635 +	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
 130.636 +	  done | \
 130.637 +	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
 130.638 +	      END { if (nonempty) { for (i in files) print i; }; }'`; \
 130.639 +	if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
 130.640 +	  test -n "$$unique" || unique=$$empty_fix; \
 130.641 +	  $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
 130.642 +	    $$tags $$unique; \
 130.643 +	fi
 130.644 +ctags: CTAGS
 130.645 +CTAGS: ctags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
 130.646 +		$(TAGS_FILES) $(LISP)
 130.647 +	tags=; \
 130.648 +	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
 130.649 +	unique=`for i in $$list; do \
 130.650 +	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
 130.651 +	  done | \
 130.652 +	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
 130.653 +	      END { if (nonempty) { for (i in files) print i; }; }'`; \
 130.654 +	test -z "$(CTAGS_ARGS)$$tags$$unique" \
 130.655 +	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
 130.656 +	     $$tags $$unique
 130.657 +
 130.658 +GTAGS:
 130.659 +	here=`$(am__cd) $(top_builddir) && pwd` \
 130.660 +	  && cd $(top_srcdir) \
 130.661 +	  && gtags -i $(GTAGS_ARGS) $$here
 130.662 +
 130.663 +distclean-tags:
 130.664 +	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 130.665 +
 130.666 +distdir: $(DISTFILES)
 130.667 +	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 130.668 +	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 130.669 +	list='$(DISTFILES)'; \
 130.670 +	  dist_files=`for file in $$list; do echo $$file; done | \
 130.671 +	  sed -e "s|^$$srcdirstrip/||;t" \
 130.672 +	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
 130.673 +	case $$dist_files in \
 130.674 +	  */*) $(MKDIR_P) `echo "$$dist_files" | \
 130.675 +			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
 130.676 +			   sort -u` ;; \
 130.677 +	esac; \
 130.678 +	for file in $$dist_files; do \
 130.679 +	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
 130.680 +	  if test -d $$d/$$file; then \
 130.681 +	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
 130.682 +	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
 130.683 +	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
 130.684 +	    fi; \
 130.685 +	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
 130.686 +	  else \
 130.687 +	    test -f $(distdir)/$$file \
 130.688 +	    || cp -p $$d/$$file $(distdir)/$$file \
 130.689 +	    || exit 1; \
 130.690 +	  fi; \
 130.691 +	done
 130.692 +	list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
 130.693 +	  if test "$$subdir" = .; then :; else \
 130.694 +	    test -d "$(distdir)/$$subdir" \
 130.695 +	    || $(MKDIR_P) "$(distdir)/$$subdir" \
 130.696 +	    || exit 1; \
 130.697 +	    distdir=`$(am__cd) $(distdir) && pwd`; \
 130.698 +	    top_distdir=`$(am__cd) $(top_distdir) && pwd`; \
 130.699 +	    (cd $$subdir && \
 130.700 +	      $(MAKE) $(AM_MAKEFLAGS) \
 130.701 +	        top_distdir="$$top_distdir" \
 130.702 +	        distdir="$$distdir/$$subdir" \
 130.703 +		am__remove_distdir=: \
 130.704 +		am__skip_length_check=: \
 130.705 +	        distdir) \
 130.706 +	      || exit 1; \
 130.707 +	  fi; \
 130.708 +	done
 130.709 +check-am: all-am
 130.710 +check: check-recursive
 130.711 +all-am: Makefile $(LIBRARIES) $(PROGRAMS) $(DATA)
 130.712 +installdirs: installdirs-recursive
 130.713 +installdirs-am:
 130.714 +	for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(pkgdatadir)"; do \
 130.715 +	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
 130.716 +	done
 130.717 +install: install-recursive
 130.718 +install-exec: install-exec-recursive
 130.719 +install-data: install-data-recursive
 130.720 +uninstall: uninstall-recursive
 130.721 +
 130.722 +install-am: all-am
 130.723 +	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
 130.724 +
 130.725 +installcheck: installcheck-recursive
 130.726 +install-strip:
 130.727 +	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
 130.728 +	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
 130.729 +	  `test -z '$(STRIP)' || \
 130.730 +	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
 130.731 +mostlyclean-generic:
 130.732 +
 130.733 +clean-generic:
 130.734 +
 130.735 +distclean-generic:
 130.736 +	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
 130.737 +
 130.738 +maintainer-clean-generic:
 130.739 +	@echo "This command is intended for maintainers to use"
 130.740 +	@echo "it deletes files that may require special tools to rebuild."
 130.741 +clean: clean-recursive
 130.742 +
 130.743 +clean-am: clean-binPROGRAMS clean-generic clean-noinstLIBRARIES \
 130.744 +	mostlyclean-am
 130.745 +
 130.746 +distclean: distclean-recursive
 130.747 +	-rm -rf ./$(DEPDIR)
 130.748 +	-rm -f Makefile
 130.749 +distclean-am: clean-am distclean-compile distclean-generic \
 130.750 +	distclean-tags
 130.751 +
 130.752 +dvi: dvi-recursive
 130.753 +
 130.754 +dvi-am:
 130.755 +
 130.756 +html: html-recursive
 130.757 +
 130.758 +info: info-recursive
 130.759 +
 130.760 +info-am:
 130.761 +
 130.762 +install-data-am: install-dist_pkgdataDATA
 130.763 +
 130.764 +install-dvi: install-dvi-recursive
 130.765 +
 130.766 +install-exec-am: install-binPROGRAMS
 130.767 +
 130.768 +install-html: install-html-recursive
 130.769 +
 130.770 +install-info: install-info-recursive
 130.771 +
 130.772 +install-man:
 130.773 +
 130.774 +install-pdf: install-pdf-recursive
 130.775 +
 130.776 +install-ps: install-ps-recursive
 130.777 +
 130.778 +installcheck-am:
 130.779 +
 130.780 +maintainer-clean: maintainer-clean-recursive
 130.781 +	-rm -rf ./$(DEPDIR)
 130.782 +	-rm -f Makefile
 130.783 +maintainer-clean-am: distclean-am maintainer-clean-generic
 130.784 +
 130.785 +mostlyclean: mostlyclean-recursive
 130.786 +
 130.787 +mostlyclean-am: mostlyclean-compile mostlyclean-generic
 130.788 +
 130.789 +pdf: pdf-recursive
 130.790 +
 130.791 +pdf-am:
 130.792 +
 130.793 +ps: ps-recursive
 130.794 +
 130.795 +ps-am:
 130.796 +
 130.797 +uninstall-am: uninstall-binPROGRAMS uninstall-dist_pkgdataDATA
 130.798 +
 130.799 +.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) install-am \
 130.800 +	install-strip
 130.801 +
 130.802 +.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
 130.803 +	all all-am check check-am clean clean-binPROGRAMS \
 130.804 +	clean-generic clean-noinstLIBRARIES ctags ctags-recursive \
 130.805 +	distclean distclean-compile distclean-generic distclean-tags \
 130.806 +	distdir dvi dvi-am html html-am info info-am install \
 130.807 +	install-am install-binPROGRAMS install-data install-data-am \
 130.808 +	install-dist_pkgdataDATA install-dvi install-dvi-am \
 130.809 +	install-exec install-exec-am install-html install-html-am \
 130.810 +	install-info install-info-am install-man install-pdf \
 130.811 +	install-pdf-am install-ps install-ps-am install-strip \
 130.812 +	installcheck installcheck-am installdirs installdirs-am \
 130.813 +	maintainer-clean maintainer-clean-generic mostlyclean \
 130.814 +	mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \
 130.815 +	tags tags-recursive uninstall uninstall-am \
 130.816 +	uninstall-binPROGRAMS uninstall-dist_pkgdataDATA
 130.817 +
 130.818 +# Tell versions [3.59,3.63) of GNU make to not export all variables.
 130.819 +# Otherwise a system limit (for SysV at least) may be exceeded.
 130.820 +.NOEXPORT:
   131.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   131.2 +++ b/src/gtk/Makefile.am	Sat Mar 03 10:31:27 2012 -0600
   131.3 @@ -0,0 +1,50 @@
   131.4 +SUBDIRS = images
   131.5 +
   131.6 +bin_PROGRAMS = gvba
   131.7 +
   131.8 +noinst_LIBRARIES = libgvba.a
   131.9 +
  131.10 +gvba_SOURCES = \
  131.11 +	configfile.cpp		\
  131.12 +	configfile.h		\
  131.13 +	filters.cpp		\
  131.14 +	filters.h		\
  131.15 +	input.cpp		\
  131.16 +	input.h			\
  131.17 +	intl.h			\
  131.18 +	joypadconfig.cpp	\
  131.19 +	joypadconfig.h		\
  131.20 +	main.cpp		\
  131.21 +	menuitem.h		\
  131.22 +	screenarea.cpp		\
  131.23 +	screenarea.h		\
  131.24 +	sigccompat.h		\
  131.25 +	system.cpp		\
  131.26 +	tools.cpp		\
  131.27 +	tools.h			\
  131.28 +	windowcallbacks.cpp	\
  131.29 +	window.cpp		\
  131.30 +	window.h
  131.31 +
  131.32 +gvba_LDADD = libgvba.a @VBA_LIBS@ @GTKMM_LIBS@ @LIBINTL@ @SDL_LIBS@
  131.33 +
  131.34 +gvba_DEPENDENCIES = libgvba.a @VBA_LIBS@
  131.35 +
  131.36 +gvba_CPPFLAGS = \
  131.37 +	-DPKGDATADIR=\"$(pkgdatadir)\"			\
  131.38 +	-DLOCALEDIR=\"$(datadir)/locale\"		\
  131.39 +	-DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\"	\
  131.40 +	$(GTKMM_CPPFLAGS)
  131.41 +
  131.42 +gvba_CXXFLAGS = @GTKMM_CFLAGS@ @SDL_CFLAGS@
  131.43 +
  131.44 +libgvba_a_SOURCES = \
  131.45 +	../AutoBuild.h		\
  131.46 +	../NLS.h		\
  131.47 +	../Port.h
  131.48 +
  131.49 +libgvba_a_CPPFLAGS = -DSDL
  131.50 +
  131.51 +libgvba_a_CXXFLAGS = -fno-exceptions
  131.52 +
  131.53 +dist_pkgdata_DATA = vba.glade
   132.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   132.2 +++ b/src/gtk/configfile.cpp	Sat Mar 03 10:31:27 2012 -0600
   132.3 @@ -0,0 +1,262 @@
   132.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   132.5 +// Copyright (C) 1999-2003 Forgotten
   132.6 +// Copyright (C) 2004 Forgotten and the VBA development team
   132.7 +
   132.8 +// This program is free software; you can redistribute it and/or modify
   132.9 +// it under the terms of the GNU General Public License as published by
  132.10 +// the Free Software Foundation; either version 2, or(at your option)
  132.11 +// any later version.
  132.12 +//
  132.13 +// This program is distributed in the hope that it will be useful,
  132.14 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  132.15 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  132.16 +// GNU General Public License for more details.
  132.17 +//
  132.18 +// You should have received a copy of the GNU General Public License
  132.19 +// along with this program; if not, write to the Free Software Foundation,
  132.20 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  132.21 +
  132.22 +#include "configfile.h"
  132.23 +
  132.24 +#include <string.h>
  132.25 +#include <glib.h>
  132.26 +
  132.27 +#include <glibmm/fileutils.h>
  132.28 +#include <glibmm/iochannel.h>
  132.29 +
  132.30 +namespace VBA
  132.31 +{
  132.32 +namespace Config
  132.33 +{
  132.34 +
  132.35 +using std::string;
  132.36 +using Glib::IOChannel;
  132.37 +
  132.38 +Line::Line(const string & _rsKey, const string & _rsValue) :
  132.39 +  m_sKey(_rsKey),
  132.40 +  m_sValue(_rsValue)
  132.41 +{
  132.42 +}
  132.43 +
  132.44 +Section::Section(const string & _rsName) :
  132.45 +  m_sName(_rsName)
  132.46 +{
  132.47 +}
  132.48 +
  132.49 +bool Section::bKeyExists(const string & _rsKey)
  132.50 +{
  132.51 +  for (iterator it = begin(); it != end(); it++)
  132.52 +  {
  132.53 +    if (it->m_sKey == _rsKey)
  132.54 +    {
  132.55 +      return true;
  132.56 +    }
  132.57 +  }
  132.58 +  return false;
  132.59 +}
  132.60 +
  132.61 +void Section::vSetKey(const string & _rsKey, const string & _rsValue)
  132.62 +{
  132.63 +  for (iterator it = begin(); it != end(); it++)
  132.64 +  {
  132.65 +    if (it->m_sKey == _rsKey)
  132.66 +    {
  132.67 +      it->m_sValue = _rsValue;
  132.68 +      return;
  132.69 +    }
  132.70 +  }
  132.71 +  push_back(Line(_rsKey, _rsValue));
  132.72 +}
  132.73 +
  132.74 +string Section::sGetKey(const string & _rsKey) const
  132.75 +{
  132.76 +  for (const_iterator it = begin(); it != end(); it++)
  132.77 +  {
  132.78 +    if (it->m_sKey == _rsKey)
  132.79 +    {
  132.80 +      return it->m_sValue;
  132.81 +    }
  132.82 +  }
  132.83 +  throw KeyNotFound(m_sName, _rsKey);
  132.84 +}
  132.85 +
  132.86 +void Section::vRemoveKey(const string & _rsKey)
  132.87 +{
  132.88 +  for (iterator it = begin(); it != end(); it++)
  132.89 +  {
  132.90 +    if (it->m_sKey == _rsKey)
  132.91 +    {
  132.92 +      erase(it);
  132.93 +      return;
  132.94 +    }
  132.95 +  }
  132.96 +}
  132.97 +
  132.98 +File::File()
  132.99 +{
 132.100 +}
 132.101 +
 132.102 +File::File(const string & _rsFile)
 132.103 +{
 132.104 +  vLoad(_rsFile);
 132.105 +}
 132.106 +
 132.107 +File::~File()
 132.108 +{
 132.109 +}
 132.110 +
 132.111 +bool File::bSectionExists(const string & _rsName)
 132.112 +{
 132.113 +  for (iterator it = begin(); it != end(); it++)
 132.114 +  {
 132.115 +    if (it->sGetName() == _rsName)
 132.116 +    {
 132.117 +      return true;
 132.118 +    }
 132.119 +  }
 132.120 +  return false;
 132.121 +}
 132.122 +
 132.123 +Section * File::poAddSection(const string & _rsName)
 132.124 +{
 132.125 +  Section * poSection = NULL;
 132.126 +  for (iterator it = begin(); it != end(); it++)
 132.127 +  {
 132.128 +    if (it->sGetName() == _rsName)
 132.129 +    {
 132.130 +      poSection = &(*it);
 132.131 +    }
 132.132 +  }
 132.133 +  if (poSection == NULL)
 132.134 +  {
 132.135 +    push_back(Section(_rsName));
 132.136 +    poSection = &back();
 132.137 +  }
 132.138 +  return poSection;
 132.139 +}
 132.140 +
 132.141 +Section * File::poGetSection(const string & _rsName)
 132.142 +{
 132.143 +  for (iterator it = begin(); it != end(); it++)
 132.144 +  {
 132.145 +    if (it->sGetName() == _rsName)
 132.146 +    {
 132.147 +      return &(*it);
 132.148 +    }
 132.149 +  }
 132.150 +  throw SectionNotFound(_rsName);
 132.151 +}
 132.152 +
 132.153 +void File::vRemoveSection(const string & _rsName)
 132.154 +{
 132.155 +  for (iterator it = begin(); it != end(); it++)
 132.156 +  {
 132.157 +    if (it->sGetName() == _rsName)
 132.158 +    {
 132.159 +      erase(it);
 132.160 +      return;
 132.161 +    }
 132.162 +  }
 132.163 +}
 132.164 +
 132.165 +void File::vLoad(const string & _rsFile,
 132.166 +                 bool _bAddSection,
 132.167 +                 bool _bAddKey)
 132.168 +{
 132.169 +  string sBuffer = Glib::file_get_contents(_rsFile);
 132.170 +  Section * poSection = NULL;
 132.171 +  char ** lines = g_strsplit(sBuffer.c_str(), "\n", 0);
 132.172 +  char * tmp;
 132.173 +  int i = 0;
 132.174 +  while (lines[i])
 132.175 +  {
 132.176 +    if (lines[i][0] == '[')
 132.177 +    {
 132.178 +      if ((tmp = strchr(lines[i], ']')))
 132.179 +      {
 132.180 +        *tmp = '\0';
 132.181 +        if (_bAddSection)
 132.182 +        {
 132.183 +          poSection = poAddSection(&lines[i][1]);
 132.184 +        }
 132.185 +        else
 132.186 +        {
 132.187 +          try
 132.188 +          {
 132.189 +            poSection = poGetSection(&lines[i][1]);
 132.190 +          }
 132.191 +          catch (...)
 132.192 +          {
 132.193 +            poSection = NULL;
 132.194 +          }
 132.195 +        }
 132.196 +      }
 132.197 +    }
 132.198 +    else if (lines[i][0] != '#' && poSection != NULL)
 132.199 +    {
 132.200 +      if ((tmp = strchr(lines[i], '=')))
 132.201 +      {
 132.202 +        *tmp = '\0';
 132.203 +        tmp++;
 132.204 +        if (_bAddKey || poSection->bKeyExists(lines[i]))
 132.205 +        {
 132.206 +          poSection->vSetKey(lines[i], tmp);
 132.207 +        }
 132.208 +      }
 132.209 +    }
 132.210 +    i++;
 132.211 +  }
 132.212 +  g_strfreev(lines);
 132.213 +}
 132.214 +
 132.215 +void File::vSave(const string & _rsFile)
 132.216 +{
 132.217 +  Glib::RefPtr<IOChannel> poFile = IOChannel::create_from_file(_rsFile, "w");
 132.218 +  poFile->set_encoding("");
 132.219 +
 132.220 +  for (const_iterator poSection = begin();
 132.221 +       poSection != end();
 132.222 +       poSection++)
 132.223 +  {
 132.224 +    string sName = "[" + poSection->sGetName() + "]\n";
 132.225 +    poFile->write(sName);
 132.226 +
 132.227 +    for (Section::const_iterator poLine = poSection->begin();
 132.228 +         poLine != poSection->end();
 132.229 +         poLine++)
 132.230 +    {
 132.231 +      string sLine = poLine->m_sKey + "=" + poLine->m_sValue + "\n";
 132.232 +      poFile->write(sLine);
 132.233 +    }
 132.234 +    poFile->write("\n");
 132.235 +  }
 132.236 +}
 132.237 +
 132.238 +void File::vClear()
 132.239 +{
 132.240 +  clear();
 132.241 +}
 132.242 +
 132.243 +std::ostream & operator<<(std::ostream & _roOut, const File & _roFile)
 132.244 +{
 132.245 +  for (File::const_iterator poSection = _roFile.begin();
 132.246 +       poSection != _roFile.end();
 132.247 +       poSection++)
 132.248 +  {
 132.249 +    string sName = "[" + poSection->sGetName() + "]\n";
 132.250 +    _roOut << sName;
 132.251 +
 132.252 +    for (Section::const_iterator poLine = poSection->begin();
 132.253 +         poLine != poSection->end();
 132.254 +         poLine++)
 132.255 +    {
 132.256 +      string sLine = poLine->m_sKey + "=" + poLine->m_sValue + "\n";
 132.257 +      _roOut << sLine;
 132.258 +    }
 132.259 +    _roOut << "\n";
 132.260 +  }
 132.261 +  return _roOut;
 132.262 +}
 132.263 +
 132.264 +} // namespace Config
 132.265 +} // namespace VBA
   133.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   133.2 +++ b/src/gtk/configfile.h	Sat Mar 03 10:31:27 2012 -0600
   133.3 @@ -0,0 +1,204 @@
   133.4 +// -*- C++ -*-
   133.5 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   133.6 +// Copyright (C) 1999-2003 Forgotten
   133.7 +// Copyright (C) 2004 Forgotten and the VBA development team
   133.8 +
   133.9 +// This program is free software; you can redistribute it and/or modify
  133.10 +// it under the terms of the GNU General Public License as published by
  133.11 +// the Free Software Foundation; either version 2, or(at your option)
  133.12 +// any later version.
  133.13 +//
  133.14 +// This program is distributed in the hope that it will be useful,
  133.15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  133.16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  133.17 +// GNU General Public License for more details.
  133.18 +//
  133.19 +// You should have received a copy of the GNU General Public License
  133.20 +// along with this program; if not, write to the Free Software Foundation,
  133.21 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  133.22 +
  133.23 +#ifndef __VBA_CONFIGFILE_H__
  133.24 +#define __VBA_CONFIGFILE_H__
  133.25 +
  133.26 +#include <list>
  133.27 +#include <string>
  133.28 +#include <sstream>
  133.29 +#include <ostream>
  133.30 +
  133.31 +namespace VBA
  133.32 +{
  133.33 +namespace Config
  133.34 +{
  133.35 +
  133.36 +class NotFound
  133.37 +{
  133.38 +public:
  133.39 +  virtual ~NotFound() {}
  133.40 +
  133.41 +protected:
  133.42 +  NotFound() {}
  133.43 +};
  133.44 +
  133.45 +class SectionNotFound : public NotFound
  133.46 +{
  133.47 +public:
  133.48 +  SectionNotFound(const std::string & _rsName) :
  133.49 +    m_sName(_rsName)
  133.50 +    {
  133.51 +    }
  133.52 +  virtual ~SectionNotFound() {}
  133.53 +
  133.54 +  inline std::string sGetName() const { return m_sName; }
  133.55 +
  133.56 +private:
  133.57 +  std::string m_sName;
  133.58 +};
  133.59 +
  133.60 +class KeyNotFound : public NotFound
  133.61 +{
  133.62 +public:
  133.63 +  KeyNotFound(const std::string & _rsSection, const std::string & _rsKey) :
  133.64 +    m_sSection(_rsSection),
  133.65 +    m_sKey(_rsKey)
  133.66 +    {
  133.67 +    }
  133.68 +  virtual ~KeyNotFound() {}
  133.69 +
  133.70 +  inline std::string sGetSection() const { return m_sSection; }
  133.71 +  inline std::string sGetKey() const { return m_sKey; }
  133.72 +
  133.73 +private:
  133.74 +  std::string m_sSection;
  133.75 +  std::string m_sKey;
  133.76 +};
  133.77 +
  133.78 +class Line
  133.79 +{
  133.80 +public:
  133.81 +  Line(const std::string & _rsKey, const std::string & _rsValue);
  133.82 +
  133.83 +  std::string m_sKey;
  133.84 +  std::string m_sValue;
  133.85 +};
  133.86 +
  133.87 +class Section : private std::list<Line>
  133.88 +{
  133.89 +public:
  133.90 +  explicit Section(const std::string & _rsName);
  133.91 +
  133.92 +  inline std::string sGetName() const { return m_sName; }
  133.93 +
  133.94 +  bool bKeyExists(const std::string & _rsKey);
  133.95 +  void vSetKey(const std::string & _rsKey, const std::string & _rsValue);
  133.96 +  std::string sGetKey(const std::string & _rsKey) const;
  133.97 +  void vRemoveKey(const std::string & _rsKey);
  133.98 +
  133.99 +  template<typename T>
 133.100 +  void vSetKey(const std::string & _rsKey, const T & _rValue);
 133.101 +
 133.102 +  template<typename T>
 133.103 +  T oGetKey(const std::string & _rsKey) const;
 133.104 +
 133.105 +  // read only
 133.106 +  typedef std::list<Line>::const_iterator const_iterator;
 133.107 +  inline const_iterator begin() const
 133.108 +    {
 133.109 +      return std::list<Line>::begin();
 133.110 +    }
 133.111 +  inline const_iterator end() const
 133.112 +    {
 133.113 +      return std::list<Line>::end();
 133.114 +    }
 133.115 +
 133.116 +private:
 133.117 +  inline iterator begin()
 133.118 +    {
 133.119 +      return std::list<Line>::begin();
 133.120 +    }
 133.121 +  inline iterator end()
 133.122 +    {
 133.123 +      return std::list<Line>::end();
 133.124 +    }
 133.125 +
 133.126 +  std::string m_sName;
 133.127 +};
 133.128 +
 133.129 +class File : private std::list<Section>
 133.130 +{
 133.131 +public:
 133.132 +  File();
 133.133 +  File(const std::string & _rsFile);
 133.134 +  virtual ~File();
 133.135 +
 133.136 +  bool bSectionExists(const std::string & _rsName);
 133.137 +  Section * poAddSection(const std::string & _rsName);
 133.138 +  Section * poGetSection(const std::string & _rsName);
 133.139 +  void vRemoveSection(const std::string & _rsName);
 133.140 +  void vLoad(const std::string & _rsFile,
 133.141 +             bool _bAddSection = true,
 133.142 +             bool _bAddKey = true);
 133.143 +  void vSave(const std::string & _rsFile);
 133.144 +  void vClear();
 133.145 +
 133.146 +  // read only
 133.147 +  typedef std::list<Section>::const_iterator const_iterator;
 133.148 +  inline const_iterator begin() const
 133.149 +    {
 133.150 +      return std::list<Section>::begin();
 133.151 +    }
 133.152 +  inline const_iterator end() const
 133.153 +    {
 133.154 +      return std::list<Section>::end();
 133.155 +    }
 133.156 +
 133.157 +private:
 133.158 +  inline iterator begin()
 133.159 +    {
 133.160 +      return std::list<Section>::begin();
 133.161 +    }
 133.162 +  inline iterator end()
 133.163 +    {
 133.164 +      return std::list<Section>::end();
 133.165 +    }
 133.166 +};
 133.167 +
 133.168 +// debug
 133.169 +std::ostream & operator<<(std::ostream & _roOut, const File & _roConfig);
 133.170 +
 133.171 +template<typename T>
 133.172 +void Section::vSetKey(const std::string & _rsKey, const T & _rValue)
 133.173 +{
 133.174 +  std::ostringstream oOut;
 133.175 +  oOut << _rValue;
 133.176 +  for (iterator it = begin(); it != end(); it++)
 133.177 +  {
 133.178 +    if (it->m_sKey == _rsKey)
 133.179 +    {
 133.180 +      it->m_sValue = oOut.str();
 133.181 +      return;
 133.182 +    }
 133.183 +  }
 133.184 +  push_back(Line(_rsKey, oOut.str()));
 133.185 +}
 133.186 +
 133.187 +template<typename T>
 133.188 +T Section::oGetKey(const std::string & _rsKey) const
 133.189 +{
 133.190 +  T oValue;
 133.191 +  for (const_iterator it = begin(); it != end(); it++)
 133.192 +  {
 133.193 +    if (it->m_sKey == _rsKey)
 133.194 +    {
 133.195 +      std::istringstream oIn(it->m_sValue);
 133.196 +      oIn >> oValue;
 133.197 +      return oValue;
 133.198 +    }
 133.199 +  }
 133.200 +  throw KeyNotFound(m_sName, _rsKey);
 133.201 +}
 133.202 +
 133.203 +} // namespace Config
 133.204 +} // namespace VBA
 133.205 +
 133.206 +
 133.207 +#endif // __VBA_CONFIGFILE_H__
   134.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   134.2 +++ b/src/gtk/filters.cpp	Sat Mar 03 10:31:27 2012 -0600
   134.3 @@ -0,0 +1,59 @@
   134.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   134.5 +// Copyright (C) 1999-2003 Forgotten
   134.6 +// Copyright (C) 2004 Forgotten and the VBA development team
   134.7 +
   134.8 +// This program is free software; you can redistribute it and/or modify
   134.9 +// it under the terms of the GNU General Public License as published by
  134.10 +// the Free Software Foundation; either version 2, or(at your option)
  134.11 +// any later version.
  134.12 +//
  134.13 +// This program is distributed in the hope that it will be useful,
  134.14 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  134.15 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  134.16 +// GNU General Public License for more details.
  134.17 +//
  134.18 +// You should have received a copy of the GNU General Public License
  134.19 +// along with this program; if not, write to the Free Software Foundation,
  134.20 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  134.21 +
  134.22 +#include "filters.h"
  134.23 +
  134.24 +namespace VBA
  134.25 +{
  134.26 +
  134.27 +static const Filter2x apvFilters2x[][2] =
  134.28 +{
  134.29 +  { NULL,         NULL           },
  134.30 +  { _2xSaI,       _2xSaI32       },
  134.31 +  { Super2xSaI,   Super2xSaI32   },
  134.32 +  { SuperEagle,   SuperEagle32   },
  134.33 +  { Pixelate2x16, Pixelate2x32   },
  134.34 +  { MotionBlur,   MotionBlur32   },
  134.35 +  { AdMame2x,     AdMame2x32     },
  134.36 +  { Simple2x16,   Simple2x32     },
  134.37 +  { Bilinear,     Bilinear32     },
  134.38 +  { BilinearPlus, BilinearPlus32 },
  134.39 +  { Scanlines,    Scanlines32    },
  134.40 +  { ScanlinesTV,  ScanlinesTV32  },
  134.41 +  { hq2x,         hq2x32         },
  134.42 +  { lq2x,         lq2x32         }
  134.43 +};
  134.44 +
  134.45 +static const FilterIB apvFiltersIB[][2] =
  134.46 +{
  134.47 +  { NULL,         NULL           },
  134.48 +  { SmartIB,      SmartIB32      },
  134.49 +  { MotionBlurIB, MotionBlurIB32 }
  134.50 +};
  134.51 +
  134.52 +Filter2x pvGetFilter2x(EFilter2x _eFilter2x, EFilterDepth _eDepth)
  134.53 +{
  134.54 +  return apvFilters2x[_eFilter2x][_eDepth];
  134.55 +}
  134.56 +
  134.57 +FilterIB pvGetFilterIB(EFilterIB _eFilterIB, EFilterDepth _eDepth)
  134.58 +{
  134.59 +  return apvFiltersIB[_eFilterIB][_eDepth];
  134.60 +}
  134.61 +
  134.62 +} // namespace VBA
   135.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   135.2 +++ b/src/gtk/filters.h	Sat Mar 03 10:31:27 2012 -0600
   135.3 @@ -0,0 +1,106 @@
   135.4 +// -*- C++ -*-
   135.5 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   135.6 +// Copyright (C) 1999-2003 Forgotten
   135.7 +// Copyright (C) 2004 Forgotten and the VBA development team
   135.8 +
   135.9 +// This program is free software; you can redistribute it and/or modify
  135.10 +// it under the terms of the GNU General Public License as published by
  135.11 +// the Free Software Foundation; either version 2, or(at your option)
  135.12 +// any later version.
  135.13 +//
  135.14 +// This program is distributed in the hope that it will be useful,
  135.15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  135.16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  135.17 +// GNU General Public License for more details.
  135.18 +//
  135.19 +// You should have received a copy of the GNU General Public License
  135.20 +// along with this program; if not, write to the Free Software Foundation,
  135.21 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  135.22 +
  135.23 +#ifndef __VBA_FILTERS_H__
  135.24 +#define __VBA_FILTERS_H__
  135.25 +
  135.26 +#include "../common/System.h"
  135.27 +
  135.28 +int Init_2xSaI(u32);
  135.29 +
  135.30 +void _2xSaI        (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.31 +void _2xSaI32      (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.32 +void Super2xSaI    (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.33 +void Super2xSaI32  (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.34 +void SuperEagle    (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.35 +void SuperEagle32  (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.36 +void Pixelate2x16  (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.37 +void Pixelate2x32  (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.38 +void MotionBlur    (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.39 +void MotionBlur32  (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.40 +void AdMame2x      (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.41 +void AdMame2x32    (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.42 +void Simple2x16    (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.43 +void Simple2x32    (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.44 +void Bilinear      (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.45 +void Bilinear32    (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.46 +void BilinearPlus  (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.47 +void BilinearPlus32(u8 *, u32, u8 *, u8 *, u32, int, int);
  135.48 +void Scanlines     (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.49 +void Scanlines32   (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.50 +void ScanlinesTV   (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.51 +void ScanlinesTV32 (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.52 +void hq2x          (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.53 +void hq2x32        (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.54 +void lq2x          (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.55 +void lq2x32        (u8 *, u32, u8 *, u8 *, u32, int, int);
  135.56 +
  135.57 +void SmartIB       (u8 *, u32, int, int);
  135.58 +void SmartIB32     (u8 *, u32, int, int);
  135.59 +void MotionBlurIB  (u8 *, u32, int, int);
  135.60 +void MotionBlurIB32(u8 *, u32, int, int);
  135.61 +
  135.62 +namespace VBA
  135.63 +{
  135.64 +
  135.65 +typedef void (*Filter2x)(u8 *, u32, u8 *, u8 *, u32, int, int);
  135.66 +typedef void (*FilterIB)(u8 *, u32, int, int);
  135.67 +
  135.68 +enum EFilter2x
  135.69 +{
  135.70 +  FirstFilter,
  135.71 +  FilterNone = FirstFilter,
  135.72 +  Filter2xSaI,
  135.73 +  FilterSuper2xSaI,
  135.74 +  FilterSuperEagle,
  135.75 +  FilterPixelate,
  135.76 +  FilterMotionBlur,
  135.77 +  FilterAdMame2x,
  135.78 +  FilterSimple2x,
  135.79 +  FilterBilinear,
  135.80 +  FilterBilinearPlus,
  135.81 +  FilterScanlines,
  135.82 +  FilterScanlinesTV,
  135.83 +  FilterHq2x,
  135.84 +  FilterLq2x,
  135.85 +  LastFilter = FilterLq2x
  135.86 +};
  135.87 +
  135.88 +enum EFilterIB
  135.89 +{
  135.90 +  FirstFilterIB,
  135.91 +  FilterIBNone = FirstFilterIB,
  135.92 +  FilterIBSmart,
  135.93 +  FilterIBMotionBlur,
  135.94 +  LastFilterIB = FilterIBMotionBlur
  135.95 +};
  135.96 +
  135.97 +enum EFilterDepth
  135.98 +{
  135.99 +  FilterDepth16,
 135.100 +  FilterDepth32
 135.101 +};
 135.102 +
 135.103 +Filter2x pvGetFilter2x(EFilter2x _eFilter2x, EFilterDepth _eDepth);
 135.104 +FilterIB pvGetFilterIB(EFilterIB _eFilterIB, EFilterDepth _eDepth);
 135.105 +
 135.106 +} // namespace VBA
 135.107 +
 135.108 +
 135.109 +#endif // __VBA_FILTERS_H__
   136.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   136.2 +++ b/src/gtk/images/Makefile	Sat Mar 03 10:31:27 2012 -0600
   136.3 @@ -0,0 +1,396 @@
   136.4 +# Makefile.in generated by automake 1.10.1 from Makefile.am.
   136.5 +# src/gtk/images/Makefile.  Generated from Makefile.in by configure.
   136.6 +
   136.7 +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
   136.8 +# 2003, 2004, 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
   136.9 +# This Makefile.in is free software; the Free Software Foundation
  136.10 +# gives unlimited permission to copy and/or distribute it,
  136.11 +# with or without modifications, as long as this notice is preserved.
  136.12 +
  136.13 +# This program is distributed in the hope that it will be useful,
  136.14 +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
  136.15 +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  136.16 +# PARTICULAR PURPOSE.
  136.17 +
  136.18 +
  136.19 +
  136.20 +
  136.21 +pkgdatadir = $(datadir)/VisualBoyAdvance
  136.22 +pkglibdir = $(libdir)/VisualBoyAdvance
  136.23 +pkgincludedir = $(includedir)/VisualBoyAdvance
  136.24 +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
  136.25 +install_sh_DATA = $(install_sh) -c -m 644
  136.26 +install_sh_PROGRAM = $(install_sh) -c
  136.27 +install_sh_SCRIPT = $(install_sh) -c
  136.28 +INSTALL_HEADER = $(INSTALL_DATA)
  136.29 +transform = $(program_transform_name)
  136.30 +NORMAL_INSTALL = :
  136.31 +PRE_INSTALL = :
  136.32 +POST_INSTALL = :
  136.33 +NORMAL_UNINSTALL = :
  136.34 +PRE_UNINSTALL = :
  136.35 +POST_UNINSTALL = :
  136.36 +build_triplet = x86_64-unknown-linux-gnu
  136.37 +host_triplet = x86_64-unknown-linux-gnu
  136.38 +target_triplet = x86_64-unknown-linux-gnu
  136.39 +subdir = src/gtk/images
  136.40 +DIST_COMMON = $(dist_pkgdata_DATA) $(srcdir)/Makefile.am \
  136.41 +	$(srcdir)/Makefile.in
  136.42 +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
  136.43 +am__aclocal_m4_deps = $(top_srcdir)/m4/gettext.m4 \
  136.44 +	$(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/lib-ld.m4 \
  136.45 +	$(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
  136.46 +	$(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/po.m4 \
  136.47 +	$(top_srcdir)/m4/progtest.m4 $(top_srcdir)/acinclude.m4 \
  136.48 +	$(top_srcdir)/configure.in
  136.49 +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
  136.50 +	$(ACLOCAL_M4)
  136.51 +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
  136.52 +CONFIG_CLEAN_FILES =
  136.53 +SOURCES =
  136.54 +DIST_SOURCES =
  136.55 +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
  136.56 +am__vpath_adj = case $$p in \
  136.57 +    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
  136.58 +    *) f=$$p;; \
  136.59 +  esac;
  136.60 +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
  136.61 +am__installdirs = "$(DESTDIR)$(pkgdatadir)"
  136.62 +dist_pkgdataDATA_INSTALL = $(INSTALL_DATA)
  136.63 +DATA = $(dist_pkgdata_DATA) $(noinst_DATA)
  136.64 +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
  136.65 +ACLOCAL = ${SHELL} /home/r/proj/vba/trunk/missing --run aclocal-1.10
  136.66 +AMTAR = ${SHELL} /home/r/proj/vba/trunk/missing --run tar
  136.67 +AUTOCONF = ${SHELL} /home/r/proj/vba/trunk/missing --run autoconf
  136.68 +AUTOHEADER = ${SHELL} /home/r/proj/vba/trunk/missing --run autoheader
  136.69 +AUTOMAKE = ${SHELL} /home/r/proj/vba/trunk/missing --run automake-1.10
  136.70 +AWK = gawk
  136.71 +CC = gcc
  136.72 +CCDEPMODE = depmode=gcc3
  136.73 +CFLAGS = -g -O2
  136.74 +CPP = gcc -E
  136.75 +CPPFLAGS = 
  136.76 +CXX = g++
  136.77 +CXXDEPMODE = depmode=gcc3
  136.78 +CXXFLAGS = -g -O2 -DC_CORE -DPROFILING -DDEV_VERSION
  136.79 +CYGPATH_W = echo
  136.80 +DEFS = -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"VisualBoyAdvance\" -DVERSION=\"1.7.2\" -DYYTEXT_POINTER=1 -DHAVE_LIBZ=1 -DHAVE_LIBPNG=1 -DHAVE_LIBPTHREAD=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_MALLOC_H=1 -DHAVE_STRINGS_H=1 -DHAVE_UNISTD_H=1 -DHAVE_ARPA_INET_H=1 -DHAVE_NETINET_IN_H=1
  136.81 +DEPDIR = .deps
  136.82 +ECHO_C = 
  136.83 +ECHO_N = -n
  136.84 +ECHO_T = 
  136.85 +EGREP = /bin/grep -E
  136.86 +EXEEXT = 
  136.87 +GETTEXT_PACKAGE = 
  136.88 +GMSGFMT = 
  136.89 +GREP = /bin/grep
  136.90 +GTKMM_CFLAGS = 
  136.91 +GTKMM_CPPFLAGS = 
  136.92 +GTKMM_LIBS = 
  136.93 +INSTALL = /usr/bin/install -c
  136.94 +INSTALL_DATA = ${INSTALL} -m 644
  136.95 +INSTALL_PROGRAM = ${INSTALL}
  136.96 +INSTALL_SCRIPT = ${INSTALL}
  136.97 +INSTALL_STRIP_PROGRAM = $(install_sh) -c -s
  136.98 +INTLLIBS = 
  136.99 +LDFLAGS = 
 136.100 +LEX = flex
 136.101 +LEXLIB = -lfl
 136.102 +LEX_OUTPUT_ROOT = lex.yy
 136.103 +LIBICONV = 
 136.104 +LIBINTL = 
 136.105 +LIBOBJS = 
 136.106 +LIBS = -lpthread -lpng -lz 
 136.107 +LTLIBICONV = 
 136.108 +LTLIBINTL = 
 136.109 +LTLIBOBJS = 
 136.110 +MAKEINFO = ${SHELL} /home/r/proj/vba/trunk/missing --run makeinfo
 136.111 +MKDIR_P = /bin/mkdir -p
 136.112 +MKINSTALLDIRS = 
 136.113 +MSGFMT = 
 136.114 +MSGMERGE = 
 136.115 +NASM = /usr/bin/nasm
 136.116 +OBJEXT = o
 136.117 +PACKAGE = VisualBoyAdvance
 136.118 +PACKAGE_BUGREPORT = 
 136.119 +PACKAGE_NAME = 
 136.120 +PACKAGE_STRING = 
 136.121 +PACKAGE_TARNAME = 
 136.122 +PACKAGE_VERSION = 
 136.123 +PATH_SEPARATOR = :
 136.124 +PKG_CONFIG = 
 136.125 +POSUB = 
 136.126 +RANLIB = ranlib
 136.127 +SDL_CFLAGS = -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT
 136.128 +SDL_CONFIG = /usr/bin/sdl-config
 136.129 +SDL_LIBS = -L/usr/lib -Wl,-rpath,/usr/lib -lSDL -lpthread
 136.130 +SET_MAKE = 
 136.131 +SHELL = /bin/sh
 136.132 +STRIP = 
 136.133 +USE_NLS = 
 136.134 +VBA_EXTRA = 
 136.135 +VBA_LIBS = ../gba/libgba.a ../gb/libgb.a ../common/libgbcom.a ../filters/libfilter.a ../lua/libgblua.a ../prof/libprof.a
 136.136 +VBA_SRC_EXTRA =  lua prof sdl
 136.137 +VERSION = 1.7.2
 136.138 +XGETTEXT = 
 136.139 +XMKMF = 
 136.140 +YACC = bison -y
 136.141 +YFLAGS = 
 136.142 +abs_builddir = /home/r/proj/vba/trunk/src/gtk/images
 136.143 +abs_srcdir = /home/r/proj/vba/trunk/src/gtk/images
 136.144 +abs_top_builddir = /home/r/proj/vba/trunk
 136.145 +abs_top_srcdir = /home/r/proj/vba/trunk
 136.146 +ac_ct_CC = gcc
 136.147 +ac_ct_CXX = g++
 136.148 +am__include = include
 136.149 +am__leading_dot = .
 136.150 +am__quote = 
 136.151 +am__tar = ${AMTAR} chof - "$$tardir"
 136.152 +am__untar = ${AMTAR} xf -
 136.153 +bindir = ${exec_prefix}/bin
 136.154 +build = x86_64-unknown-linux-gnu
 136.155 +build_alias = 
 136.156 +build_cpu = x86_64
 136.157 +build_os = linux-gnu
 136.158 +build_vendor = unknown
 136.159 +builddir = .
 136.160 +datadir = ${datarootdir}
 136.161 +datarootdir = ${prefix}/share
 136.162 +docdir = ${datarootdir}/doc/${PACKAGE}
 136.163 +dvidir = ${docdir}
 136.164 +exec_prefix = ${prefix}
 136.165 +host = x86_64-unknown-linux-gnu
 136.166 +host_alias = 
 136.167 +host_cpu = x86_64
 136.168 +host_os = linux-gnu
 136.169 +host_vendor = unknown
 136.170 +htmldir = ${docdir}
 136.171 +includedir = ${prefix}/include
 136.172 +infodir = ${datarootdir}/info
 136.173 +install_sh = $(SHELL) /home/r/proj/vba/trunk/install-sh
 136.174 +libdir = ${exec_prefix}/lib
 136.175 +libexecdir = ${exec_prefix}/libexec
 136.176 +localedir = ${datarootdir}/locale
 136.177 +localstatedir = ${prefix}/var
 136.178 +mandir = ${datarootdir}/man
 136.179 +mkdir_p = /bin/mkdir -p
 136.180 +oldincludedir = /usr/include
 136.181 +pdfdir = ${docdir}
 136.182 +prefix = /usr/local
 136.183 +program_transform_name = s,x,x,
 136.184 +psdir = ${docdir}
 136.185 +sbindir = ${exec_prefix}/sbin
 136.186 +sharedstatedir = ${prefix}/com
 136.187 +srcdir = .
 136.188 +sysconfdir = ${prefix}/etc
 136.189 +target = x86_64-unknown-linux-gnu
 136.190 +target_alias = 
 136.191 +target_cpu = x86_64
 136.192 +target_os = linux-gnu
 136.193 +target_vendor = unknown
 136.194 +top_builddir = ../../..
 136.195 +top_srcdir = ../../..
 136.196 +VBA_WM_IMAGES = \
 136.197 +	stock-vba-wm-16.png	\
 136.198 +	stock-vba-wm-32.png	\
 136.199 +	stock-vba-wm-48.png	\
 136.200 +	stock-vba-wm-64.png
 136.201 +
 136.202 +VBA_WM_VARIABLES = \
 136.203 +	stock_vba_wm_16  $(srcdir)/stock-vba-wm-16.png	\
 136.204 +	stock_vba_wm_32  $(srcdir)/stock-vba-wm-32.png	\
 136.205 +	stock_vba_wm_48  $(srcdir)/stock-vba-wm-48.png	\
 136.206 +	stock_vba_wm_64  $(srcdir)/stock-vba-wm-64.png
 136.207 +
 136.208 +EXTRA_DIST = $(VBA_WM_IMAGES)
 136.209 +noinst_DATA = vba-wm-pixbufs.h
 136.210 +dist_pkgdata_DATA = vba-64.png
 136.211 +CLEANFILES = $(noinst_DATA)
 136.212 +all: all-am
 136.213 +
 136.214 +.SUFFIXES:
 136.215 +$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
 136.216 +	@for dep in $?; do \
 136.217 +	  case '$(am__configure_deps)' in \
 136.218 +	    *$$dep*) \
 136.219 +	      cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
 136.220 +		&& exit 0; \
 136.221 +	      exit 1;; \
 136.222 +	  esac; \
 136.223 +	done; \
 136.224 +	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu  src/gtk/images/Makefile'; \
 136.225 +	cd $(top_srcdir) && \
 136.226 +	  $(AUTOMAKE) --gnu  src/gtk/images/Makefile
 136.227 +.PRECIOUS: Makefile
 136.228 +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 136.229 +	@case '$?' in \
 136.230 +	  *config.status*) \
 136.231 +	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 136.232 +	  *) \
 136.233 +	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
 136.234 +	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
 136.235 +	esac;
 136.236 +
 136.237 +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
 136.238 +	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 136.239 +
 136.240 +$(top_srcdir)/configure:  $(am__configure_deps)
 136.241 +	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 136.242 +$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
 136.243 +	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 136.244 +install-dist_pkgdataDATA: $(dist_pkgdata_DATA)
 136.245 +	@$(NORMAL_INSTALL)
 136.246 +	test -z "$(pkgdatadir)" || $(MKDIR_P) "$(DESTDIR)$(pkgdatadir)"
 136.247 +	@list='$(dist_pkgdata_DATA)'; for p in $$list; do \
 136.248 +	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
 136.249 +	  f=$(am__strip_dir) \
 136.250 +	  echo " $(dist_pkgdataDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(pkgdatadir)/$$f'"; \
 136.251 +	  $(dist_pkgdataDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(pkgdatadir)/$$f"; \
 136.252 +	done
 136.253 +
 136.254 +uninstall-dist_pkgdataDATA:
 136.255 +	@$(NORMAL_UNINSTALL)
 136.256 +	@list='$(dist_pkgdata_DATA)'; for p in $$list; do \
 136.257 +	  f=$(am__strip_dir) \
 136.258 +	  echo " rm -f '$(DESTDIR)$(pkgdatadir)/$$f'"; \
 136.259 +	  rm -f "$(DESTDIR)$(pkgdatadir)/$$f"; \
 136.260 +	done
 136.261 +tags: TAGS
 136.262 +TAGS:
 136.263 +
 136.264 +ctags: CTAGS
 136.265 +CTAGS:
 136.266 +
 136.267 +
 136.268 +distdir: $(DISTFILES)
 136.269 +	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 136.270 +	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 136.271 +	list='$(DISTFILES)'; \
 136.272 +	  dist_files=`for file in $$list; do echo $$file; done | \
 136.273 +	  sed -e "s|^$$srcdirstrip/||;t" \
 136.274 +	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
 136.275 +	case $$dist_files in \
 136.276 +	  */*) $(MKDIR_P) `echo "$$dist_files" | \
 136.277 +			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
 136.278 +			   sort -u` ;; \
 136.279 +	esac; \
 136.280 +	for file in $$dist_files; do \
 136.281 +	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
 136.282 +	  if test -d $$d/$$file; then \
 136.283 +	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
 136.284 +	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
 136.285 +	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
 136.286 +	    fi; \
 136.287 +	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
 136.288 +	  else \
 136.289 +	    test -f $(distdir)/$$file \
 136.290 +	    || cp -p $$d/$$file $(distdir)/$$file \
 136.291 +	    || exit 1; \
 136.292 +	  fi; \
 136.293 +	done
 136.294 +check-am: all-am
 136.295 +check: check-am
 136.296 +all-am: Makefile $(DATA)
 136.297 +installdirs:
 136.298 +	for dir in "$(DESTDIR)$(pkgdatadir)"; do \
 136.299 +	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
 136.300 +	done
 136.301 +install: install-am
 136.302 +install-exec: install-exec-am
 136.303 +install-data: install-data-am
 136.304 +uninstall: uninstall-am
 136.305 +
 136.306 +install-am: all-am
 136.307 +	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
 136.308 +
 136.309 +installcheck: installcheck-am
 136.310 +install-strip:
 136.311 +	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
 136.312 +	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
 136.313 +	  `test -z '$(STRIP)' || \
 136.314 +	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
 136.315 +mostlyclean-generic:
 136.316 +
 136.317 +clean-generic:
 136.318 +	-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
 136.319 +
 136.320 +distclean-generic:
 136.321 +	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
 136.322 +
 136.323 +maintainer-clean-generic:
 136.324 +	@echo "This command is intended for maintainers to use"
 136.325 +	@echo "it deletes files that may require special tools to rebuild."
 136.326 +clean: clean-am
 136.327 +
 136.328 +clean-am: clean-generic mostlyclean-am
 136.329 +
 136.330 +distclean: distclean-am
 136.331 +	-rm -f Makefile
 136.332 +distclean-am: clean-am distclean-generic
 136.333 +
 136.334 +dvi: dvi-am
 136.335 +
 136.336 +dvi-am:
 136.337 +
 136.338 +html: html-am
 136.339 +
 136.340 +info: info-am
 136.341 +
 136.342 +info-am:
 136.343 +
 136.344 +install-data-am: install-dist_pkgdataDATA
 136.345 +
 136.346 +install-dvi: install-dvi-am
 136.347 +
 136.348 +install-exec-am:
 136.349 +
 136.350 +install-html: install-html-am
 136.351 +
 136.352 +install-info: install-info-am
 136.353 +
 136.354 +install-man:
 136.355 +
 136.356 +install-pdf: install-pdf-am
 136.357 +
 136.358 +install-ps: install-ps-am
 136.359 +
 136.360 +installcheck-am:
 136.361 +
 136.362 +maintainer-clean: maintainer-clean-am
 136.363 +	-rm -f Makefile
 136.364 +maintainer-clean-am: distclean-am maintainer-clean-generic
 136.365 +
 136.366 +mostlyclean: mostlyclean-am
 136.367 +
 136.368 +mostlyclean-am: mostlyclean-generic
 136.369 +
 136.370 +pdf: pdf-am
 136.371 +
 136.372 +pdf-am:
 136.373 +
 136.374 +ps: ps-am
 136.375 +
 136.376 +ps-am:
 136.377 +
 136.378 +uninstall-am: uninstall-dist_pkgdataDATA
 136.379 +
 136.380 +.MAKE: install-am install-strip
 136.381 +
 136.382 +.PHONY: all all-am check check-am clean clean-generic distclean \
 136.383 +	distclean-generic distdir dvi dvi-am html html-am info info-am \
 136.384 +	install install-am install-data install-data-am \
 136.385 +	install-dist_pkgdataDATA install-dvi install-dvi-am \
 136.386 +	install-exec install-exec-am install-html install-html-am \
 136.387 +	install-info install-info-am install-man install-pdf \
 136.388 +	install-pdf-am install-ps install-ps-am install-strip \
 136.389 +	installcheck installcheck-am installdirs maintainer-clean \
 136.390 +	maintainer-clean-generic mostlyclean mostlyclean-generic pdf \
 136.391 +	pdf-am ps ps-am uninstall uninstall-am \
 136.392 +	uninstall-dist_pkgdataDATA
 136.393 +
 136.394 +
 136.395 +$(srcdir)/vba-wm-pixbufs.h: $(VBA_WM_IMAGES) Makefile.am
 136.396 +	gdk-pixbuf-csource --raw --build-list $(VBA_WM_VARIABLES) > $(@F)
 136.397 +# Tell versions [3.59,3.63) of GNU make to not export all variables.
 136.398 +# Otherwise a system limit (for SysV at least) may be exceeded.
 136.399 +.NOEXPORT:
   137.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   137.2 +++ b/src/gtk/images/Makefile.am	Sat Mar 03 10:31:27 2012 -0600
   137.3 @@ -0,0 +1,22 @@
   137.4 +VBA_WM_IMAGES = \
   137.5 +	stock-vba-wm-16.png	\
   137.6 +	stock-vba-wm-32.png	\
   137.7 +	stock-vba-wm-48.png	\
   137.8 +	stock-vba-wm-64.png
   137.9 +
  137.10 +VBA_WM_VARIABLES = \
  137.11 +	stock_vba_wm_16  $(srcdir)/stock-vba-wm-16.png	\
  137.12 +	stock_vba_wm_32  $(srcdir)/stock-vba-wm-32.png	\
  137.13 +	stock_vba_wm_48  $(srcdir)/stock-vba-wm-48.png	\
  137.14 +	stock_vba_wm_64  $(srcdir)/stock-vba-wm-64.png
  137.15 +
  137.16 +EXTRA_DIST = $(VBA_WM_IMAGES)
  137.17 +
  137.18 +noinst_DATA = vba-wm-pixbufs.h
  137.19 +
  137.20 +dist_pkgdata_DATA = vba-64.png
  137.21 +
  137.22 +CLEANFILES = $(noinst_DATA)
  137.23 +
  137.24 +$(srcdir)/vba-wm-pixbufs.h: $(VBA_WM_IMAGES) Makefile.am
  137.25 +	gdk-pixbuf-csource --raw --build-list $(VBA_WM_VARIABLES) > $(@F)
   138.1 Binary file src/gtk/images/stock-vba-wm-16.png has changed
   139.1 Binary file src/gtk/images/stock-vba-wm-32.png has changed
   140.1 Binary file src/gtk/images/stock-vba-wm-48.png has changed
   141.1 Binary file src/gtk/images/stock-vba-wm-64.png has changed
   142.1 Binary file src/gtk/images/vba-64.png has changed
   143.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   143.2 +++ b/src/gtk/input.cpp	Sat Mar 03 10:31:27 2012 -0600
   143.3 @@ -0,0 +1,53 @@
   143.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   143.5 +// Copyright (C) 1999-2003 Forgotten
   143.6 +// Copyright (C) 2004 Forgotten and the VBA development team
   143.7 +
   143.8 +// This program is free software; you can redistribute it and/or modify
   143.9 +// it under the terms of the GNU General Public License as published by
  143.10 +// the Free Software Foundation; either version 2, or(at your option)
  143.11 +// any later version.
  143.12 +//
  143.13 +// This program is distributed in the hope that it will be useful,
  143.14 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  143.15 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  143.16 +// GNU General Public License for more details.
  143.17 +//
  143.18 +// You should have received a copy of the GNU General Public License
  143.19 +// along with this program; if not, write to the Free Software Foundation,
  143.20 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  143.21 +
  143.22 +#include "input.h"
  143.23 +
  143.24 +#include <new>
  143.25 +
  143.26 +namespace VBA
  143.27 +{
  143.28 +
  143.29 +Keymap::Keymap()
  143.30 +{
  143.31 +  m_pstTable = g_hash_table_new(g_direct_hash, g_direct_equal);
  143.32 +  if (m_pstTable == NULL)
  143.33 +  {
  143.34 +    throw std::bad_alloc();
  143.35 +  }
  143.36 +}
  143.37 +
  143.38 +Keymap::~Keymap()
  143.39 +{
  143.40 +  g_hash_table_destroy(m_pstTable);
  143.41 +}
  143.42 +
  143.43 +void Keymap::vRegister(guint _uiVal, EKey _eKey)
  143.44 +{
  143.45 +  g_hash_table_insert(m_pstTable,
  143.46 +                      GUINT_TO_POINTER(_uiVal),
  143.47 +                      GUINT_TO_POINTER(_eKey));
  143.48 +}
  143.49 +
  143.50 +void Keymap::vClear()
  143.51 +{
  143.52 +  g_hash_table_destroy(m_pstTable);
  143.53 +  m_pstTable = g_hash_table_new(g_direct_hash, g_direct_equal);
  143.54 +}
  143.55 +
  143.56 +} // namespace VBA
   144.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   144.2 +++ b/src/gtk/input.h	Sat Mar 03 10:31:27 2012 -0600
   144.3 @@ -0,0 +1,92 @@
   144.4 +// -*- C++ -*-
   144.5 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   144.6 +// Copyright (C) 1999-2003 Forgotten
   144.7 +// Copyright (C) 2004 Forgotten and the VBA development team
   144.8 +
   144.9 +// This program is free software; you can redistribute it and/or modify
  144.10 +// it under the terms of the GNU General Public License as published by
  144.11 +// the Free Software Foundation; either version 2, or(at your option)
  144.12 +// any later version.
  144.13 +//
  144.14 +// This program is distributed in the hope that it will be useful,
  144.15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  144.16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  144.17 +// GNU General Public License for more details.
  144.18 +//
  144.19 +// You should have received a copy of the GNU General Public License
  144.20 +// along with this program; if not, write to the Free Software Foundation,
  144.21 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  144.22 +
  144.23 +#ifndef __VBA_INPUT_H__
  144.24 +#define __VBA_INPUT_H__
  144.25 +
  144.26 +#include <glib.h>
  144.27 +
  144.28 +namespace VBA
  144.29 +{
  144.30 +
  144.31 +enum EKey
  144.32 +{
  144.33 +  KeyNone,
  144.34 +  // GBA keys
  144.35 +  KeyA,
  144.36 +  KeyB,
  144.37 +  KeySelect,
  144.38 +  KeyStart,
  144.39 +  KeyRight,
  144.40 +  KeyLeft,
  144.41 +  KeyUp,
  144.42 +  KeyDown,
  144.43 +  KeyR,
  144.44 +  KeyL,
  144.45 +  // VBA extension
  144.46 +  KeySpeed,
  144.47 +  KeyCapture
  144.48 +};
  144.49 +
  144.50 +enum EKeyFlag
  144.51 +{
  144.52 +  // GBA keys
  144.53 +  KeyFlagA       = 1 << 0,
  144.54 +  KeyFlagB       = 1 << 1,
  144.55 +  KeyFlagSelect  = 1 << 2,
  144.56 +  KeyFlagStart   = 1 << 3,
  144.57 +  KeyFlagRight   = 1 << 4,
  144.58 +  KeyFlagLeft    = 1 << 5,
  144.59 +  KeyFlagUp      = 1 << 6,
  144.60 +  KeyFlagDown    = 1 << 7,
  144.61 +  KeyFlagR       = 1 << 8,
  144.62 +  KeyFlagL       = 1 << 9,
  144.63 +  // VBA extension
  144.64 +  KeyFlagSpeed   = 1 << 10,
  144.65 +  KeyFlagCapture = 1 << 11,
  144.66 +};
  144.67 +
  144.68 +class Keymap
  144.69 +{
  144.70 + public:
  144.71 +  Keymap();
  144.72 +  ~Keymap();
  144.73 +
  144.74 +  void vRegister(guint _uiVal, EKey _eKey);
  144.75 +  void vClear();
  144.76 +  inline EKey eGetKey(guint _uiVal);
  144.77 +
  144.78 + private:
  144.79 +  GHashTable * m_pstTable;
  144.80 +
  144.81 +  // noncopyable
  144.82 +  Keymap(const Keymap &);
  144.83 +  Keymap & operator=(const Keymap &);
  144.84 +};
  144.85 +
  144.86 +inline EKey Keymap::eGetKey(guint _uiVal)
  144.87 +{
  144.88 +  return (EKey)GPOINTER_TO_UINT(g_hash_table_lookup(m_pstTable,
  144.89 +                                                    GUINT_TO_POINTER(_uiVal)));
  144.90 +}
  144.91 +
  144.92 +} // namespace VBA
  144.93 +
  144.94 +
  144.95 +#endif // __VBA_INPUT_H__
   145.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   145.2 +++ b/src/gtk/intl.h	Sat Mar 03 10:31:27 2012 -0600
   145.3 @@ -0,0 +1,42 @@
   145.4 +// -*- C++ -*-
   145.5 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   145.6 +// Copyright (C) 1999-2003 Forgotten
   145.7 +// Copyright (C) 2004 Forgotten and the VBA development team
   145.8 +
   145.9 +// This program is free software; you can redistribute it and/or modify
  145.10 +// it under the terms of the GNU General Public License as published by
  145.11 +// the Free Software Foundation; either version 2, or(at your option)
  145.12 +// any later version.
  145.13 +//
  145.14 +// This program is distributed in the hope that it will be useful,
  145.15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  145.16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  145.17 +// GNU General Public License for more details.
  145.18 +//
  145.19 +// You should have received a copy of the GNU General Public License
  145.20 +// along with this program; if not, write to the Free Software Foundation,
  145.21 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  145.22 +
  145.23 +#ifndef __VBA_INTL_H__
  145.24 +#define __VBA_INTL_H__
  145.25 +
  145.26 +#ifndef GETTEXT_PACKAGE
  145.27 +# error "GETTEXT_PACKAGE must be defined"
  145.28 +#endif
  145.29 +
  145.30 +#ifdef ENABLE_NLS
  145.31 +# include <libintl.h>
  145.32 +# define _(String) gettext(String)
  145.33 +# define N_(String) (String)
  145.34 +#else
  145.35 +# define _(String) (String)
  145.36 +# define N_(String) (String)
  145.37 +# define textdomain(String) (String)
  145.38 +# define gettext(String) (String)
  145.39 +# define dgettext(Domain,String) (String)
  145.40 +# define dcgettext(Domain,String,Type) (String)
  145.41 +# define bindtextdomain(Domain,Directory) (Domain) 
  145.42 +#endif
  145.43 +
  145.44 +
  145.45 +#endif // __VBA_INTL_H__
   146.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   146.2 +++ b/src/gtk/joypadconfig.cpp	Sat Mar 03 10:31:27 2012 -0600
   146.3 @@ -0,0 +1,276 @@
   146.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   146.5 +// Copyright (C) 1999-2003 Forgotten
   146.6 +// Copyright (C) 2004 Forgotten and the VBA development team
   146.7 +
   146.8 +// This program is free software; you can redistribute it and/or modify
   146.9 +// it under the terms of the GNU General Public License as published by
  146.10 +// the Free Software Foundation; either version 2, or(at your option)
  146.11 +// any later version.
  146.12 +//
  146.13 +// This program is distributed in the hope that it will be useful,
  146.14 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  146.15 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  146.16 +// GNU General Public License for more details.
  146.17 +//
  146.18 +// You should have received a copy of the GNU General Public License
  146.19 +// along with this program; if not, write to the Free Software Foundation,
  146.20 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  146.21 +
  146.22 +#include "joypadconfig.h"
  146.23 +
  146.24 +#include <string.h>
  146.25 +
  146.26 +#include "intl.h"
  146.27 +
  146.28 +namespace VBA
  146.29 +{
  146.30 +
  146.31 +guint * JoypadConfig::puiAt(int _iIndex)
  146.32 +{
  146.33 +  guint * puiMember;
  146.34 +
  146.35 +  switch (_iIndex)
  146.36 +  {
  146.37 +  case 0:
  146.38 +    puiMember = &m_uiUp;
  146.39 +    break;
  146.40 +  case 1:
  146.41 +    puiMember = &m_uiDown;
  146.42 +    break;
  146.43 +  case 2:
  146.44 +    puiMember = &m_uiLeft;
  146.45 +    break;
  146.46 +  case 3:
  146.47 +    puiMember = &m_uiRight;
  146.48 +    break;
  146.49 +  case 4:
  146.50 +    puiMember = &m_uiA;
  146.51 +    break;
  146.52 +  case 5:
  146.53 +    puiMember = &m_uiB;
  146.54 +    break;
  146.55 +  case 6:
  146.56 +    puiMember = &m_uiL;
  146.57 +    break;
  146.58 +  case 7:
  146.59 +    puiMember = &m_uiR;
  146.60 +    break;
  146.61 +  case 8:
  146.62 +    puiMember = &m_uiSelect;
  146.63 +    break;
  146.64 +  case 9:
  146.65 +    puiMember = &m_uiStart;
  146.66 +    break;
  146.67 +  case 10:
  146.68 +    puiMember = &m_uiSpeed;
  146.69 +    break;
  146.70 +  case 11:
  146.71 +    puiMember = &m_uiCapture;
  146.72 +    break;
  146.73 +  default:
  146.74 +    puiMember = NULL;
  146.75 +  }
  146.76 +
  146.77 +  return puiMember;
  146.78 +}
  146.79 +
  146.80 +int JoypadConfig::iFind(guint _uiKeycode)
  146.81 +{
  146.82 +  for (guint i = 0; i < 12; i++)
  146.83 +  {
  146.84 +    if (*puiAt(i) == _uiKeycode)
  146.85 +    {
  146.86 +      return i;
  146.87 +    }
  146.88 +  }
  146.89 +
  146.90 +  return -1;
  146.91 +}
  146.92 +
  146.93 +void JoypadConfig::vSetDefault()
  146.94 +{
  146.95 +  guint auiKeyval[] =
  146.96 +  {
  146.97 +    GDK_Up, GDK_Down, GDK_Left, GDK_Right,
  146.98 +    GDK_z, GDK_x, GDK_a, GDK_s,
  146.99 +    GDK_BackSpace, GDK_Return,
 146.100 +    GDK_space, GDK_F12
 146.101 +  };
 146.102 +
 146.103 +  for (guint i = 0; i < G_N_ELEMENTS(auiKeyval); i++)
 146.104 +  {
 146.105 +    GdkKeymapKey * pstKeys;
 146.106 +    int iKeys;
 146.107 +
 146.108 +    if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(),
 146.109 +                                          auiKeyval[i],
 146.110 +                                          &pstKeys,
 146.111 +                                          &iKeys))
 146.112 +    {
 146.113 +      *puiAt(i) = pstKeys[0].keycode;
 146.114 +      g_free(pstKeys);
 146.115 +    }
 146.116 +    else
 146.117 +    {
 146.118 +      *puiAt(i) = 0;
 146.119 +    }
 146.120 +  }
 146.121 +}
 146.122 +
 146.123 +Keymap * JoypadConfig::poCreateKeymap() const
 146.124 +{
 146.125 +  Keymap * poKeymap = new Keymap();
 146.126 +
 146.127 +  poKeymap->vRegister(m_uiUp,      KeyUp      );
 146.128 +  poKeymap->vRegister(m_uiDown,    KeyDown    );
 146.129 +  poKeymap->vRegister(m_uiLeft,    KeyLeft    );
 146.130 +  poKeymap->vRegister(m_uiRight,   KeyRight   );
 146.131 +  poKeymap->vRegister(m_uiA,       KeyA       );
 146.132 +  poKeymap->vRegister(m_uiB,       KeyB       );
 146.133 +  poKeymap->vRegister(m_uiL,       KeyL       );
 146.134 +  poKeymap->vRegister(m_uiR,       KeyR       );
 146.135 +  poKeymap->vRegister(m_uiSelect,  KeySelect  );
 146.136 +  poKeymap->vRegister(m_uiStart,   KeyStart   );
 146.137 +  poKeymap->vRegister(m_uiSpeed,   KeySpeed   );
 146.138 +  poKeymap->vRegister(m_uiCapture, KeyCapture );
 146.139 +
 146.140 +  return poKeymap;
 146.141 +}
 146.142 +
 146.143 +JoypadConfigDialog::JoypadConfigDialog(GtkDialog * _pstDialog,
 146.144 +                                       const Glib::RefPtr<Gnome::Glade::Xml> & _poXml) :
 146.145 +  Gtk::Dialog(_pstDialog)
 146.146 +{
 146.147 +  m_puiCurrentKeyCode = NULL;
 146.148 +
 146.149 +  memset(&m_oConfig, 0, sizeof(m_oConfig));
 146.150 +
 146.151 +  m_poOkButton = dynamic_cast<Gtk::Button *>(_poXml->get_widget("JoypadOkButton"));
 146.152 +
 146.153 +  m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadUpEntry")));
 146.154 +  m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadDownEntry")));
 146.155 +  m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadLeftEntry")));
 146.156 +  m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadRightEntry")));
 146.157 +  m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadAEntry")));
 146.158 +  m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadBEntry")));
 146.159 +  m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadLEntry")));
 146.160 +  m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadREntry")));
 146.161 +  m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadSelectEntry")));
 146.162 +  m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadStartEntry")));
 146.163 +  m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadSpeedEntry")));
 146.164 +  m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadCaptureEntry")));
 146.165 +
 146.166 +  for (guint i = 0; i < m_oEntries.size(); i++)
 146.167 +  {
 146.168 +    Gtk::Entry * poEntry = m_oEntries[i];
 146.169 +
 146.170 +    poEntry->signal_focus_in_event().connect(SigC::bind<guint>(
 146.171 +                                               SigC::slot(*this, &JoypadConfigDialog::bOnEntryFocusIn),
 146.172 +                                               i));
 146.173 +    poEntry->signal_focus_out_event().connect(SigC::slot(*this, &JoypadConfigDialog::bOnEntryFocusOut));
 146.174 +  }
 146.175 +
 146.176 +  vUpdateEntries();
 146.177 +}
 146.178 +
 146.179 +JoypadConfigDialog::~JoypadConfigDialog()
 146.180 +{
 146.181 +}
 146.182 +
 146.183 +void JoypadConfigDialog::vSetConfig(const JoypadConfig & _roConfig)
 146.184 +{
 146.185 +  m_oConfig = _roConfig;
 146.186 +  vUpdateEntries();
 146.187 +}
 146.188 +
 146.189 +void JoypadConfigDialog::vUpdateEntries()
 146.190 +{
 146.191 +  for (guint i = 0; i < m_oEntries.size(); i++)
 146.192 +  {
 146.193 +    guint uiKeyval = 0;
 146.194 +    gdk_keymap_translate_keyboard_state(gdk_keymap_get_default(),
 146.195 +                                        *m_oConfig.puiAt(i),
 146.196 +                                        (GdkModifierType)0,
 146.197 +                                        0,
 146.198 +                                        &uiKeyval,
 146.199 +                                        NULL,
 146.200 +                                        NULL,
 146.201 +                                        NULL);
 146.202 +    const char * csName = gdk_keyval_name(uiKeyval);
 146.203 +    if (csName == NULL)
 146.204 +    {
 146.205 +      m_oEntries[i]->set_text(_("<Undefined>"));
 146.206 +    }
 146.207 +    else
 146.208 +    {
 146.209 +      m_oEntries[i]->set_text(csName);
 146.210 +    }
 146.211 +  }
 146.212 +}
 146.213 +
 146.214 +bool JoypadConfigDialog::bOnEntryFocusIn(GdkEventFocus * _pstEvent,
 146.215 +                                         guint           _uiEntry)
 146.216 +{
 146.217 +  m_uiCurrentEntry    = _uiEntry;
 146.218 +  m_puiCurrentKeyCode = m_oConfig.puiAt(_uiEntry);
 146.219 +
 146.220 +  return false;
 146.221 +}
 146.222 +
 146.223 +bool JoypadConfigDialog::bOnEntryFocusOut(GdkEventFocus * _pstEvent)
 146.224 +{
 146.225 +  m_puiCurrentKeyCode = NULL;
 146.226 +
 146.227 +  return false;
 146.228 +}
 146.229 +
 146.230 +bool JoypadConfigDialog::on_key_press_event(GdkEventKey * _pstEvent)
 146.231 +{
 146.232 +  if (m_puiCurrentKeyCode == NULL)
 146.233 +  {
 146.234 +    return Gtk::Dialog::on_key_press_event(_pstEvent);
 146.235 +  }
 146.236 +
 146.237 +  *m_puiCurrentKeyCode = 0;
 146.238 +  int iFound = m_oConfig.iFind(_pstEvent->hardware_keycode);
 146.239 +  if (iFound >= 0)
 146.240 +  {
 146.241 +    *m_oConfig.puiAt(iFound) = 0;
 146.242 +    m_oEntries[iFound]->set_text(_("<Undefined>"));
 146.243 +  }
 146.244 +
 146.245 +  *m_puiCurrentKeyCode = _pstEvent->hardware_keycode;
 146.246 +
 146.247 +  guint uiKeyval = 0;
 146.248 +  gdk_keymap_translate_keyboard_state(gdk_keymap_get_default(),
 146.249 +                                      _pstEvent->hardware_keycode,
 146.250 +                                      (GdkModifierType)0,
 146.251 +                                      0,
 146.252 +                                      &uiKeyval,
 146.253 +                                      NULL,
 146.254 +                                      NULL,
 146.255 +                                      NULL);
 146.256 +
 146.257 +  const char * csName = gdk_keyval_name(uiKeyval);
 146.258 +  if (csName == NULL)
 146.259 +  {
 146.260 +    m_oEntries[m_uiCurrentEntry]->set_text(_("<Undefined>"));
 146.261 +  }
 146.262 +  else
 146.263 +  {
 146.264 +    m_oEntries[m_uiCurrentEntry]->set_text(csName);
 146.265 +  }
 146.266 +
 146.267 +  if (m_uiCurrentEntry + 1 < m_oEntries.size())
 146.268 +  {
 146.269 +    m_oEntries[m_uiCurrentEntry + 1]->grab_focus();
 146.270 +  }
 146.271 +  else
 146.272 +  {
 146.273 +    m_poOkButton->grab_focus();
 146.274 +  }
 146.275 +
 146.276 +  return true;
 146.277 +}
 146.278 +
 146.279 +} // namespace VBA
   147.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   147.2 +++ b/src/gtk/joypadconfig.h	Sat Mar 03 10:31:27 2012 -0600
   147.3 @@ -0,0 +1,88 @@
   147.4 +// -*- C++ -*-
   147.5 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   147.6 +// Copyright (C) 1999-2003 Forgotten
   147.7 +// Copyright (C) 2004 Forgotten and the VBA development team
   147.8 +
   147.9 +// This program is free software; you can redistribute it and/or modify
  147.10 +// it under the terms of the GNU General Public License as published by
  147.11 +// the Free Software Foundation; either version 2, or(at your option)
  147.12 +// any later version.
  147.13 +//
  147.14 +// This program is distributed in the hope that it will be useful,
  147.15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  147.16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  147.17 +// GNU General Public License for more details.
  147.18 +//
  147.19 +// You should have received a copy of the GNU General Public License
  147.20 +// along with this program; if not, write to the Free Software Foundation,
  147.21 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  147.22 +
  147.23 +#ifndef __VBA_JOYPADCONFIG_H__
  147.24 +#define __VBA_JOYPADCONFIG_H__
  147.25 +
  147.26 +#include <vector>
  147.27 +
  147.28 +#include <libglademm.h>
  147.29 +#include <gtkmm.h>
  147.30 +
  147.31 +#ifndef GTKMM20
  147.32 +# include "sigccompat.h"
  147.33 +#endif // ! GTKMM20
  147.34 +
  147.35 +#include "input.h"
  147.36 +
  147.37 +namespace VBA
  147.38 +{
  147.39 +
  147.40 +class JoypadConfig
  147.41 +{
  147.42 +public:
  147.43 +  guint m_uiUp;
  147.44 +  guint m_uiDown;
  147.45 +  guint m_uiLeft;
  147.46 +  guint m_uiRight;
  147.47 +  guint m_uiA;
  147.48 +  guint m_uiB;
  147.49 +  guint m_uiL;
  147.50 +  guint m_uiR;
  147.51 +  guint m_uiSelect;
  147.52 +  guint m_uiStart;
  147.53 +  guint m_uiSpeed;
  147.54 +  guint m_uiCapture;
  147.55 +
  147.56 +  guint *  puiAt(int _iIndex);
  147.57 +  int      iFind(guint _uiKeycode);
  147.58 +  void     vSetDefault();
  147.59 +  Keymap * poCreateKeymap() const;
  147.60 +};
  147.61 +
  147.62 +class JoypadConfigDialog : public Gtk::Dialog
  147.63 +{
  147.64 +public:
  147.65 +  JoypadConfigDialog(GtkDialog * _pstDialog,
  147.66 +                     const Glib::RefPtr<Gnome::Glade::Xml> & _poXml);
  147.67 +  virtual ~JoypadConfigDialog();
  147.68 +
  147.69 +  void vSetConfig(const JoypadConfig & _roConfig);
  147.70 +  inline JoypadConfig stGetConfig() const { return m_oConfig; }
  147.71 +
  147.72 +protected:
  147.73 +  bool bOnEntryFocusIn(GdkEventFocus * _pstEvent, guint _uiEntry);
  147.74 +  bool bOnEntryFocusOut(GdkEventFocus * _pstEvent);
  147.75 +
  147.76 +  bool on_key_press_event(GdkEventKey * _pstEvent);
  147.77 +
  147.78 +private:
  147.79 +  JoypadConfig              m_oConfig;
  147.80 +  Gtk::Button *             m_poOkButton;
  147.81 +  std::vector<Gtk::Entry *> m_oEntries;
  147.82 +  guint *                   m_puiCurrentKeyCode;
  147.83 +  guint                     m_uiCurrentEntry;
  147.84 +
  147.85 +  void vUpdateEntries();
  147.86 +};
  147.87 +
  147.88 +} // namespace VBA
  147.89 +
  147.90 +
  147.91 +#endif // __VBA_JOYPADCONFIG_H__
   148.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   148.2 +++ b/src/gtk/main.cpp	Sat Mar 03 10:31:27 2012 -0600
   148.3 @@ -0,0 +1,177 @@
   148.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   148.5 +// Copyright (C) 1999-2003 Forgotten
   148.6 +// Copyright (C) 2004 Forgotten and the VBA development team
   148.7 +
   148.8 +// This program is free software; you can redistribute it and/or modify
   148.9 +// it under the terms of the GNU General Public License as published by
  148.10 +// the Free Software Foundation; either version 2, or(at your option)
  148.11 +// any later version.
  148.12 +//
  148.13 +// This program is distributed in the hope that it will be useful,
  148.14 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  148.15 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  148.16 +// GNU General Public License for more details.
  148.17 +//
  148.18 +// You should have received a copy of the GNU General Public License
  148.19 +// along with this program; if not, write to the Free Software Foundation,
  148.20 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  148.21 +
  148.22 +#include <limits.h>
  148.23 +#include <stdlib.h>
  148.24 +#include "../getopt.h"
  148.25 +
  148.26 +#include <list>
  148.27 +
  148.28 +#include <libglademm.h>
  148.29 +#include <gtkmm/main.h>
  148.30 +#include <gtkmm/window.h>
  148.31 +#include <gtkmm/messagedialog.h>
  148.32 +
  148.33 +#include "images/vba-wm-pixbufs.h"
  148.34 +
  148.35 +#include "window.h"
  148.36 +#include "intl.h"
  148.37 +
  148.38 +using Gnome::Glade::Xml;
  148.39 +
  148.40 +static const char * csProgramName;
  148.41 +
  148.42 +static int iShowHelp;
  148.43 +static int iShowVersion;
  148.44 +
  148.45 +// Non-characters used for long options that have no equivalent short option
  148.46 +enum
  148.47 +{
  148.48 +  IGNORED_OPTION = CHAR_MAX + 1
  148.49 +};
  148.50 +
  148.51 +static const char csShortOptions[] = "V";
  148.52 +
  148.53 +static const struct option astLongOptions[] =
  148.54 +{
  148.55 +  { "help",    no_argument, &iShowHelp, IGNORED_OPTION },
  148.56 +  { "version", no_argument, NULL,       'V'            },
  148.57 +  { 0, 0, 0, 0 }
  148.58 +};
  148.59 +
  148.60 +static void vUsage(int iStatus)
  148.61 +{
  148.62 +  if (iStatus != 0)
  148.63 +  {
  148.64 +    g_printerr(_("Try `%s --help' for more information.\n"), csProgramName);
  148.65 +  }
  148.66 +  else
  148.67 +  {
  148.68 +    g_print(_("Usage: %s [option ...] [file]\n"), csProgramName);
  148.69 +    g_print(_("\
  148.70 +\n\
  148.71 +Options:\n\
  148.72 +      --help            Output this help.\n\
  148.73 +  -V, --version         Output version information.\n\
  148.74 +"));
  148.75 +  }
  148.76 +
  148.77 +  exit(iStatus);
  148.78 +}
  148.79 +
  148.80 +static void vSetDefaultWindowIcon()
  148.81 +{
  148.82 +  const guint8 * apuiInlinePixbuf[] =
  148.83 +  {
  148.84 +    stock_vba_wm_16,
  148.85 +    stock_vba_wm_32,
  148.86 +    stock_vba_wm_48,
  148.87 +    stock_vba_wm_64
  148.88 +  };
  148.89 +
  148.90 +  std::list<Glib::RefPtr<Gdk::Pixbuf> > listPixbuf;
  148.91 +  for (guint i = 0; i < G_N_ELEMENTS(apuiInlinePixbuf); i++)
  148.92 +  {
  148.93 +    listPixbuf.push_back(
  148.94 +      Gdk::Pixbuf::create_from_inline(-1, apuiInlinePixbuf[i]));
  148.95 +  }
  148.96 +
  148.97 +  Gtk::Window::set_default_icon_list(listPixbuf);
  148.98 +}
  148.99 +
 148.100 +int main(int argc, char * argv[])
 148.101 +{
 148.102 +  csProgramName = argv[0];
 148.103 +
 148.104 +#ifdef ENABLE_NLS
 148.105 +  setlocale(LC_ALL, "");
 148.106 +  bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 148.107 +  textdomain(GETTEXT_PACKAGE);
 148.108 +  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 148.109 +#endif // ENABLE_NLS
 148.110 +
 148.111 +  Gtk::Main oKit(argc, argv);
 148.112 +
 148.113 +  int iOpt;
 148.114 +  while ((iOpt = getopt_long(argc, argv, csShortOptions, astLongOptions, NULL))
 148.115 +         != -1)
 148.116 +  {
 148.117 +    switch (iOpt)
 148.118 +    {
 148.119 +    case 'V':
 148.120 +      iShowVersion = 1;
 148.121 +      break;
 148.122 +    case 0:
 148.123 +      // Long options
 148.124 +      break;
 148.125 +    default:
 148.126 +      vUsage(1);
 148.127 +      break;
 148.128 +    }
 148.129 +  }
 148.130 +
 148.131 +  if (iShowVersion)
 148.132 +  {
 148.133 +    g_print(_("VisualBoyAdvance version %s [GTK+]\n"), VERSION);
 148.134 +    exit(0);
 148.135 +  }
 148.136 +
 148.137 +  if (iShowHelp)
 148.138 +  {
 148.139 +    vUsage(0);
 148.140 +  }
 148.141 +
 148.142 +  vSetDefaultWindowIcon();
 148.143 +
 148.144 +  Glib::RefPtr<Xml> poXml;
 148.145 +  try
 148.146 +  {
 148.147 +    poXml = Xml::create(PKGDATADIR "/vba.glade", "MainWindow");
 148.148 +  }
 148.149 +  catch (const Xml::Error & e)
 148.150 +  {
 148.151 +    Gtk::MessageDialog oDialog(e.what(),
 148.152 +#ifndef GTKMM20
 148.153 +                               false,
 148.154 +#endif // ! GTKMM20
 148.155 +                               Gtk::MESSAGE_ERROR,
 148.156 +                               Gtk::BUTTONS_OK);
 148.157 +    oDialog.run();
 148.158 +    return 1;
 148.159 +  }
 148.160 +
 148.161 +  VBA::Window * poWindow = NULL;
 148.162 +  poXml->get_widget_derived<VBA::Window>("MainWindow", poWindow);
 148.163 +
 148.164 +  if (optind < argc)
 148.165 +  {
 148.166 +    // Display the window before loading the file
 148.167 +    poWindow->show();
 148.168 +    while (Gtk::Main::events_pending())
 148.169 +    {
 148.170 +      Gtk::Main::iteration();
 148.171 +    }
 148.172 +
 148.173 +    poWindow->bLoadROM(argv[optind]);
 148.174 +  }
 148.175 +
 148.176 +  Gtk::Main::run(*poWindow);
 148.177 +  delete poWindow;
 148.178 +
 148.179 +  return 0;
 148.180 +}
   149.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   149.2 +++ b/src/gtk/menuitem.h	Sat Mar 03 10:31:27 2012 -0600
   149.3 @@ -0,0 +1,80 @@
   149.4 +// -*- C++ -*-
   149.5 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   149.6 +// Copyright (C) 1999-2003 Forgotten
   149.7 +// Copyright (C) 2004 Forgotten and the VBA development team
   149.8 +
   149.9 +// This program is free software; you can redistribute it and/or modify
  149.10 +// it under the terms of the GNU General Public License as published by
  149.11 +// the Free Software Foundation; either version 2, or(at your option)
  149.12 +// any later version.
  149.13 +//
  149.14 +// This program is distributed in the hope that it will be useful,
  149.15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  149.16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  149.17 +// GNU General Public License for more details.
  149.18 +//
  149.19 +// You should have received a copy of the GNU General Public License
  149.20 +// along with this program; if not, write to the Free Software Foundation,
  149.21 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  149.22 +
  149.23 +#ifndef __VBA_MENUITEM_H__
  149.24 +#define __VBA_MENUITEM_H__
  149.25 +
  149.26 +#include <gtkmm/menuitem.h>
  149.27 +#include <gtkmm/imagemenuitem.h>
  149.28 +
  149.29 +#ifdef GTKMM20
  149.30 +namespace Gtk { typedef Gtk::Menu_Helpers::AccelKey AccelKey; }
  149.31 +#endif // GTKMM20
  149.32 +
  149.33 +namespace VBA
  149.34 +{
  149.35 +
  149.36 +class MenuItem : public Gtk::MenuItem
  149.37 +{
  149.38 +public:
  149.39 +  MenuItem()
  149.40 +    {}
  149.41 +
  149.42 +  MenuItem(Gtk::Widget & _roWidget) :
  149.43 +    Gtk::MenuItem(_roWidget)
  149.44 +    {}
  149.45 +
  149.46 +  MenuItem(const Glib::ustring & _rsLabel, bool _bMnemonic = false) :
  149.47 +    Gtk::MenuItem(_rsLabel, _bMnemonic)
  149.48 +    {}
  149.49 +
  149.50 +  inline void set_accel_key(const Gtk::AccelKey & _roAccelKey)
  149.51 +    {
  149.52 +      Gtk::MenuItem::set_accel_key(_roAccelKey);
  149.53 +    }
  149.54 +};
  149.55 +
  149.56 +class ImageMenuItem : public Gtk::ImageMenuItem
  149.57 +{
  149.58 +public:
  149.59 +  ImageMenuItem()
  149.60 +    {}
  149.61 +
  149.62 +  ImageMenuItem(Widget & _roImage, const Glib::ustring & _rsLabel, bool _bMnemonic = false) :
  149.63 +    Gtk::ImageMenuItem(_roImage, _rsLabel, _bMnemonic)
  149.64 +    {}
  149.65 +
  149.66 +  ImageMenuItem(const Glib::ustring & _rsLabel, bool _bMnemonic = false) :
  149.67 +    Gtk::ImageMenuItem(_rsLabel, _bMnemonic)
  149.68 +    {}
  149.69 +
  149.70 +  ImageMenuItem(const Gtk::StockID & _roId) :
  149.71 +    Gtk::ImageMenuItem(_roId)
  149.72 +    {}
  149.73 +
  149.74 +  inline void set_accel_key(const Gtk::AccelKey & _roAccelKey)
  149.75 +    {
  149.76 +      Gtk::MenuItem::set_accel_key(_roAccelKey);
  149.77 +    }
  149.78 +};
  149.79 +
  149.80 +} // namespace VBA
  149.81 +
  149.82 +
  149.83 +#endif // __VBA_MENUITEM_H__
   150.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   150.2 +++ b/src/gtk/screenarea.cpp	Sat Mar 03 10:31:27 2012 -0600
   150.3 @@ -0,0 +1,293 @@
   150.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   150.5 +// Copyright (C) 1999-2003 Forgotten
   150.6 +// Copyright (C) 2004 Forgotten and the VBA development team
   150.7 +
   150.8 +// This program is free software; you can redistribute it and/or modify
   150.9 +// it under the terms of the GNU General Public License as published by
  150.10 +// the Free Software Foundation; either version 2, or(at your option)
  150.11 +// any later version.
  150.12 +//
  150.13 +// This program is distributed in the hope that it will be useful,
  150.14 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  150.15 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  150.16 +// GNU General Public License for more details.
  150.17 +//
  150.18 +// You should have received a copy of the GNU General Public License
  150.19 +// along with this program; if not, write to the Free Software Foundation,
  150.20 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  150.21 +
  150.22 +#include "screenarea.h"
  150.23 +
  150.24 +#include <string.h>
  150.25 +
  150.26 +namespace VBA
  150.27 +{
  150.28 +
  150.29 +ScreenArea::ScreenArea(int _iWidth, int _iHeight, int _iScale) :
  150.30 +  m_puiPixels(NULL),
  150.31 +  m_puiDelta(NULL),
  150.32 +  m_vFilter2x(NULL),
  150.33 +  m_vFilterIB(NULL),
  150.34 +  m_bShowCursor(true)
  150.35 +{
  150.36 +  g_assert(_iWidth >= 1 && _iHeight >= 1 && _iScale >= 1);
  150.37 +
  150.38 +  m_iWidth  = _iWidth;
  150.39 +  m_iHeight = _iHeight;
  150.40 +  m_iScale  = _iScale;
  150.41 +  vUpdateSize();
  150.42 +
  150.43 +  set_events(Gdk::EXPOSURE_MASK
  150.44 +             | Gdk::POINTER_MOTION_MASK
  150.45 +             | Gdk::ENTER_NOTIFY_MASK
  150.46 +             | Gdk::LEAVE_NOTIFY_MASK);
  150.47 +
  150.48 +  char aiEmptyData[8];
  150.49 +  memset(aiEmptyData, 0, sizeof(aiEmptyData));
  150.50 +  Glib::RefPtr<Gdk::Bitmap> poSource = Gdk::Bitmap::create(aiEmptyData, 8, 8);
  150.51 +  Glib::RefPtr<Gdk::Bitmap> poMask = Gdk::Bitmap::create(aiEmptyData, 8, 8);
  150.52 +  Gdk::Color oFg;
  150.53 +  Gdk::Color oBg;
  150.54 +  oFg.set_rgb(0, 0, 0);
  150.55 +  oBg.set_rgb(0, 0, 0);
  150.56 +
  150.57 +  m_poEmptyCursor = new Gdk::Cursor(poSource, poMask, oFg, oBg, 0, 0);
  150.58 +}
  150.59 +
  150.60 +ScreenArea::~ScreenArea()
  150.61 +{
  150.62 +  if (m_puiPixels != NULL)
  150.63 +  {
  150.64 +    delete[] m_puiPixels;
  150.65 +  }
  150.66 +
  150.67 +  if (m_puiDelta != NULL)
  150.68 +  {
  150.69 +    delete[] m_puiDelta;
  150.70 +  }
  150.71 +
  150.72 +  if (m_poEmptyCursor != NULL)
  150.73 +  {
  150.74 +    delete m_poEmptyCursor;
  150.75 +  }
  150.76 +}
  150.77 +
  150.78 +void ScreenArea::vSetSize(int _iWidth, int _iHeight)
  150.79 +{
  150.80 +  g_return_if_fail(_iWidth >= 1 && _iHeight >= 1);
  150.81 +
  150.82 +  if (_iWidth != m_iWidth || _iHeight != m_iHeight)
  150.83 +  {
  150.84 +    m_iWidth  = _iWidth;
  150.85 +    m_iHeight = _iHeight;
  150.86 +    vUpdateSize();
  150.87 +  }
  150.88 +}
  150.89 +
  150.90 +void ScreenArea::vSetScale(int _iScale)
  150.91 +{
  150.92 +  g_return_if_fail(_iScale >= 1);
  150.93 +
  150.94 +  if (_iScale != m_iScale)
  150.95 +  {
  150.96 +    m_iScale = _iScale;
  150.97 +    vUpdateSize();
  150.98 +  }
  150.99 +}
 150.100 +
 150.101 +void ScreenArea::vSetFilter2x(EFilter2x _eFilter2x)
 150.102 +{
 150.103 +  m_vFilter2x = pvGetFilter2x(_eFilter2x, FilterDepth32);
 150.104 +}
 150.105 +
 150.106 +void ScreenArea::vSetFilterIB(EFilterIB _eFilterIB)
 150.107 +{
 150.108 +  m_vFilterIB = pvGetFilterIB(_eFilterIB, FilterDepth32);
 150.109 +}
 150.110 +
 150.111 +void ScreenArea::vDrawPixels(u8 * _puiData)
 150.112 +{
 150.113 +  if (m_vFilterIB != NULL)
 150.114 +  {
 150.115 +    m_vFilterIB(_puiData + m_iAreaWidth * 2 + 4,
 150.116 +                m_iAreaWidth * 2 + 4,
 150.117 +                m_iWidth,
 150.118 +                m_iHeight);
 150.119 +  }
 150.120 +
 150.121 +  if (m_iScale == 1)
 150.122 +  {
 150.123 +    u32 * puiSrc = (u32 *)_puiData + m_iWidth + 1;
 150.124 +    u32 * puiPixel = m_puiPixels;
 150.125 +    for (int y = 0; y < m_iHeight; y++)
 150.126 +    {
 150.127 +      for (int x = 0; x < m_iWidth; x++)
 150.128 +      {
 150.129 +        *puiPixel++ = *puiSrc++;
 150.130 +      }
 150.131 +      puiSrc++;
 150.132 +    }
 150.133 +  }
 150.134 +  else if (m_iScale == 2 && m_vFilter2x != NULL)
 150.135 +  {
 150.136 +    m_vFilter2x(_puiData + m_iAreaWidth * 2 + 4,
 150.137 +                m_iAreaWidth * 2 + 4,
 150.138 +                m_puiDelta,
 150.139 +                (u8 *)m_puiPixels,
 150.140 +                m_iRowStride,
 150.141 +                m_iWidth,
 150.142 +                m_iHeight);
 150.143 +  }
 150.144 +  else
 150.145 +  {
 150.146 +    u32 * puiSrc = (u32 *)_puiData + m_iWidth + 1;
 150.147 +    u32 * puiSrc2;
 150.148 +    u32 * puiPixel = m_puiPixels;
 150.149 +    for (int y = 0; y < m_iHeight; y++)
 150.150 +    {
 150.151 +      for (int j = 0; j < m_iScale; j++)
 150.152 +      {
 150.153 +        puiSrc2 = puiSrc;
 150.154 +        for (int x = 0; x < m_iWidth; x++)
 150.155 +        {
 150.156 +          for (int i = 0; i < m_iScale; i++)
 150.157 +          {
 150.158 +            *puiPixel++ = *puiSrc2;
 150.159 +          }
 150.160 +          puiSrc2++;
 150.161 +        }
 150.162 +      }
 150.163 +      puiSrc = puiSrc2 + 1;
 150.164 +    }
 150.165 +  }
 150.166 +
 150.167 +  queue_draw_area(0, 0, m_iAreaWidth, m_iAreaHeight);
 150.168 +}
 150.169 +
 150.170 +void ScreenArea::vDrawColor(u32 _uiColor)
 150.171 +{
 150.172 +  _uiColor = GUINT32_TO_BE(_uiColor) << 8;
 150.173 +
 150.174 +  u32 * puiPixel = m_puiPixels;
 150.175 +  u32 * puiEnd   = m_puiPixels + m_iAreaWidth * m_iAreaHeight;
 150.176 +  while (puiPixel != puiEnd)
 150.177 +  {
 150.178 +    *puiPixel++ = _uiColor;
 150.179 +  }
 150.180 +
 150.181 +  queue_draw_area(0, 0, m_iAreaWidth, m_iAreaHeight);
 150.182 +}
 150.183 +
 150.184 +void ScreenArea::vUpdateSize()
 150.185 +{
 150.186 +  if (m_puiPixels != NULL)
 150.187 +  {
 150.188 +    delete[] m_puiPixels;
 150.189 +  }
 150.190 +
 150.191 +  if (m_puiDelta != NULL)
 150.192 +  {
 150.193 +    delete[] m_puiDelta;
 150.194 +  }
 150.195 +
 150.196 +  m_iAreaWidth  = m_iScale * m_iWidth;
 150.197 +  m_iAreaHeight = m_iScale * m_iHeight;
 150.198 +  m_iRowStride  = m_iAreaWidth * 4;
 150.199 +
 150.200 +  m_puiPixels = new u32[m_iAreaWidth * m_iAreaHeight];
 150.201 +
 150.202 +  m_puiDelta = new u8[(m_iWidth + 2) * (m_iHeight + 2) * 4];
 150.203 +  memset(m_puiDelta, 255, (m_iWidth + 2) * (m_iHeight + 2) * 4);
 150.204 +
 150.205 +  set_size_request(m_iAreaWidth, m_iAreaHeight);
 150.206 +}
 150.207 +
 150.208 +void ScreenArea::vStartCursorTimeout()
 150.209 +{
 150.210 +  m_oCursorSig.disconnect();
 150.211 +  m_oCursorSig = Glib::signal_timeout().connect(
 150.212 +    SigC::slot(*this, &ScreenArea::bOnCursorTimeout),
 150.213 +    2000);
 150.214 +}
 150.215 +
 150.216 +void ScreenArea::vStopCursorTimeout()
 150.217 +{
 150.218 +  m_oCursorSig.disconnect();
 150.219 +}
 150.220 +
 150.221 +void ScreenArea::vHideCursor()
 150.222 +{
 150.223 +  get_window()->set_cursor(*m_poEmptyCursor);
 150.224 +  m_bShowCursor = false;
 150.225 +}
 150.226 +
 150.227 +void ScreenArea::vShowCursor()
 150.228 +{
 150.229 +  get_window()->set_cursor();
 150.230 +  m_bShowCursor = true;
 150.231 +}
 150.232 +
 150.233 +bool ScreenArea::on_expose_event(GdkEventExpose * _pstEvent)
 150.234 +{
 150.235 +  if (_pstEvent->area.x + _pstEvent->area.width > m_iAreaWidth
 150.236 +      || _pstEvent->area.y + _pstEvent->area.height > m_iAreaHeight)
 150.237 +  {
 150.238 +    return false;
 150.239 +  }
 150.240 +
 150.241 +  guchar * puiAreaPixels = (guchar *)m_puiPixels;
 150.242 +
 150.243 +  if (_pstEvent->area.x != 0)
 150.244 +  {
 150.245 +    puiAreaPixels += _pstEvent->area.x << 2;
 150.246 +  }
 150.247 +
 150.248 +  if (_pstEvent->area.y != 0)
 150.249 +  {
 150.250 +    puiAreaPixels += _pstEvent->area.y * m_iRowStride;
 150.251 +  }
 150.252 +
 150.253 +  get_window()->draw_rgb_32_image(get_style()->get_fg_gc(get_state()),
 150.254 +                                  _pstEvent->area.x,
 150.255 +                                  _pstEvent->area.y,
 150.256 +                                  _pstEvent->area.width,
 150.257 +                                  _pstEvent->area.height,
 150.258 +                                  Gdk::RGB_DITHER_MAX,
 150.259 +                                  puiAreaPixels,
 150.260 +                                  m_iRowStride);
 150.261 +  return true;
 150.262 +}
 150.263 +
 150.264 +bool ScreenArea::on_motion_notify_event(GdkEventMotion * _pstEvent)
 150.265 +{
 150.266 +  if (! m_bShowCursor)
 150.267 +  {
 150.268 +    vShowCursor();
 150.269 +  }
 150.270 +  vStartCursorTimeout();
 150.271 +  return false;
 150.272 +}
 150.273 +
 150.274 +bool ScreenArea::on_enter_notify_event(GdkEventCrossing * _pstEvent)
 150.275 +{
 150.276 +  vStartCursorTimeout();
 150.277 +  return false;
 150.278 +}
 150.279 +
 150.280 +bool ScreenArea::on_leave_notify_event(GdkEventCrossing * _pstEvent)
 150.281 +{
 150.282 +  vStopCursorTimeout();
 150.283 +  if (! m_bShowCursor)
 150.284 +  {
 150.285 +    vShowCursor();
 150.286 +  }
 150.287 +  return false;
 150.288 +}
 150.289 +
 150.290 +bool ScreenArea::bOnCursorTimeout()
 150.291 +{
 150.292 +  vHideCursor();
 150.293 +  return false;
 150.294 +}
 150.295 +
 150.296 +} // namespace VBA
   151.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   151.2 +++ b/src/gtk/screenarea.h	Sat Mar 03 10:31:27 2012 -0600
   151.3 @@ -0,0 +1,81 @@
   151.4 +// -*- C++ -*-
   151.5 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   151.6 +// Copyright (C) 1999-2003 Forgotten
   151.7 +// Copyright (C) 2004 Forgotten and the VBA development team
   151.8 +
   151.9 +// This program is free software; you can redistribute it and/or modify
  151.10 +// it under the terms of the GNU General Public License as published by
  151.11 +// the Free Software Foundation; either version 2, or(at your option)
  151.12 +// any later version.
  151.13 +//
  151.14 +// This program is distributed in the hope that it will be useful,
  151.15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  151.16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  151.17 +// GNU General Public License for more details.
  151.18 +//
  151.19 +// You should have received a copy of the GNU General Public License
  151.20 +// along with this program; if not, write to the Free Software Foundation,
  151.21 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  151.22 +
  151.23 +#ifndef __VBA_SCREENAREA_H__
  151.24 +#define __VBA_SCREENAREA_H__
  151.25 +
  151.26 +#include <gtkmm/drawingarea.h>
  151.27 +#include <gdkmm/cursor.h>
  151.28 +
  151.29 +#ifndef GTKMM20
  151.30 +# include "sigccompat.h"
  151.31 +#endif // ! GTKMM20
  151.32 +
  151.33 +#include "filters.h"
  151.34 +
  151.35 +namespace VBA
  151.36 +{
  151.37 +
  151.38 +class ScreenArea : public Gtk::DrawingArea
  151.39 +{
  151.40 +public:
  151.41 +  ScreenArea(int _iWidth, int _iHeight, int _iScale = 1);
  151.42 +  virtual ~ScreenArea();
  151.43 +
  151.44 +  void vSetSize(int _iWidth, int _iHeight);
  151.45 +  void vSetScale(int _iScale);
  151.46 +  void vSetFilter2x(EFilter2x _eFilter2x);
  151.47 +  void vSetFilterIB(EFilterIB _eFilterIB);
  151.48 +  void vDrawPixels(u8 * _puiData);
  151.49 +  void vDrawColor(u32 _uiColor); // 0xRRGGBB
  151.50 +
  151.51 +protected:
  151.52 +  virtual bool on_expose_event(GdkEventExpose * _pstEvent);
  151.53 +  virtual bool on_motion_notify_event(GdkEventMotion * _pstEvent);
  151.54 +  virtual bool on_enter_notify_event(GdkEventCrossing * _pstEvent);
  151.55 +  virtual bool on_leave_notify_event(GdkEventCrossing * _pstEvent);
  151.56 +  virtual bool bOnCursorTimeout();
  151.57 +
  151.58 +private:
  151.59 +  int      m_iWidth;
  151.60 +  int      m_iHeight;
  151.61 +  int      m_iScale;
  151.62 +  int      m_iAreaWidth;
  151.63 +  int      m_iAreaHeight;
  151.64 +  int      m_iRowStride;
  151.65 +  u32 *    m_puiPixels;
  151.66 +  u8 *     m_puiDelta;
  151.67 +  Filter2x m_vFilter2x;
  151.68 +  FilterIB m_vFilterIB;
  151.69 +
  151.70 +  bool             m_bShowCursor;
  151.71 +  Gdk::Cursor *    m_poEmptyCursor;
  151.72 +  SigC::connection m_oCursorSig;
  151.73 +
  151.74 +  void vUpdateSize();
  151.75 +  void vStartCursorTimeout();
  151.76 +  void vStopCursorTimeout();
  151.77 +  void vHideCursor();
  151.78 +  void vShowCursor();
  151.79 +};
  151.80 +
  151.81 +} // namespace VBA
  151.82 +
  151.83 +
  151.84 +#endif // __VBA_SCREENAREA_H__
   152.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   152.2 +++ b/src/gtk/sigccompat.h	Sat Mar 03 10:31:27 2012 -0600
   152.3 @@ -0,0 +1,57 @@
   152.4 +// -*- C++ -*-
   152.5 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   152.6 +// Copyright (C) 1999-2003 Forgotten
   152.7 +// Copyright (C) 2004 Forgotten and the VBA development team
   152.8 +
   152.9 +// This program is free software; you can redistribute it and/or modify
  152.10 +// it under the terms of the GNU General Public License as published by
  152.11 +// the Free Software Foundation; either version 2, or(at your option)
  152.12 +// any later version.
  152.13 +//
  152.14 +// This program is distributed in the hope that it will be useful,
  152.15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  152.16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  152.17 +// GNU General Public License for more details.
  152.18 +//
  152.19 +// You should have received a copy of the GNU General Public License
  152.20 +// along with this program; if not, write to the Free Software Foundation,
  152.21 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  152.22 +
  152.23 +#ifndef __VBA_SIGCCOMPAT_H__
  152.24 +#define __VBA_SIGCCOMPAT_H__
  152.25 +
  152.26 +#undef LIBSIGC_DISABLE_DEPRECATED
  152.27 +#include <sigc++/bind.h>
  152.28 +#include <sigc++/connection.h>
  152.29 +
  152.30 +#include <sigc++/slot.h>
  152.31 +#include <sigc++/object.h>
  152.32 +#include <sigc++/functors/mem_fun.h>
  152.33 +
  152.34 +namespace SigC
  152.35 +{
  152.36 +
  152.37 +using namespace sigc;
  152.38 +
  152.39 +template <class T_return, class T_obj1, class T_obj2>
  152.40 +inline slot0<T_return>
  152.41 +slot( T_obj1& _A_obj, T_return (T_obj2::*_A_func)() )
  152.42 +{ return ::sigc::bound_mem_functor0<T_return, T_obj2>
  152.43 +             (dynamic_cast< T_obj1&>(_A_obj), _A_func); }
  152.44 +
  152.45 +template <class T_return, class T_arg1, class T_obj1, class T_obj2>
  152.46 +inline slot1<T_return, T_arg1>
  152.47 +slot( T_obj1& _A_obj, T_return (T_obj2::*_A_func)(T_arg1) )
  152.48 +{ return ::sigc::bound_mem_functor1<T_return, T_obj2, T_arg1>
  152.49 +             (dynamic_cast< T_obj1&>(_A_obj), _A_func); }
  152.50 +
  152.51 +template <class T_return, class T_arg1,class T_arg2, class T_obj1, class T_obj2>
  152.52 +inline slot2<T_return, T_arg1,T_arg2>
  152.53 +slot( T_obj1& _A_obj, T_return (T_obj2::*_A_func)(T_arg1,T_arg2) )
  152.54 +{ return ::sigc::bound_mem_functor2<T_return, T_obj2, T_arg1,T_arg2>
  152.55 +             (dynamic_cast< T_obj1&>(_A_obj), _A_func); }
  152.56 +
  152.57 +} // namespace SigC
  152.58 +
  152.59 +
  152.60 +#endif // __VBA_SIGCCOMPAT_H__
   153.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   153.2 +++ b/src/gtk/system.cpp	Sat Mar 03 10:31:27 2012 -0600
   153.3 @@ -0,0 +1,469 @@
   153.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   153.5 +// Copyright (C) 1999-2003 Forgotten
   153.6 +// Copyright (C) 2004 Forgotten and the VBA development team
   153.7 +
   153.8 +// This program is free software; you can redistribute it and/or modify
   153.9 +// it under the terms of the GNU General Public License as published by
  153.10 +// the Free Software Foundation; either version 2, or(at your option)
  153.11 +// any later version.
  153.12 +//
  153.13 +// This program is distributed in the hope that it will be useful,
  153.14 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  153.15 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  153.16 +// GNU General Public License for more details.
  153.17 +//
  153.18 +// You should have received a copy of the GNU General Public License
  153.19 +// along with this program; if not, write to the Free Software Foundation,
  153.20 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  153.21 +
  153.22 +#include <stdio.h>
  153.23 +#include <stdarg.h>
  153.24 +#include <string.h>
  153.25 +
  153.26 +#include <SDL.h>
  153.27 +#include <SDL_thread.h>
  153.28 +
  153.29 +#include "../common/System.h"
  153.30 +#include "../common/Util.h"
  153.31 +#include "../gba/GBAGlobals.h"
  153.32 +#include "../gb/gbGlobals.h"
  153.33 +#include "../gba/GBASound.h"
  153.34 +
  153.35 +#include "window.h"
  153.36 +#include "intl.h"
  153.37 +
  153.38 +// Required vars, used by the emulator core
  153.39 +//
  153.40 +int  systemRedShift;
  153.41 +int  systemGreenShift;
  153.42 +int  systemBlueShift;
  153.43 +int  systemColorDepth;
  153.44 +int  systemDebug;
  153.45 +int  systemVerbose;
  153.46 +int  systemSaveUpdateCounter;
  153.47 +int  systemFrameSkip;
  153.48 +u32  systemColorMap32[0x10000];
  153.49 +u16  systemColorMap16[0x10000];
  153.50 +u16  systemGbPalette[24];
  153.51 +bool systemSoundOn;
  153.52 +
  153.53 +char filename[2048];
  153.54 +char biosFileName[2048];
  153.55 +//char captureDir[2048];
  153.56 +char saveDir[2048];
  153.57 +char batteryDir[2048];
  153.58 +
  153.59 +int sensorX = 2047;
  153.60 +int sensorY = 2047;
  153.61 +bool sensorOn = false;
  153.62 +
  153.63 +int  emulating;
  153.64 +bool debugger;
  153.65 +int  RGB_LOW_BITS_MASK;
  153.66 +
  153.67 +int cartridgeType = 3;
  153.68 +int sizeOption = 0;
  153.69 +int captureFormat = 0;
  153.70 +int throttle = 0;
  153.71 +bool paused = false;
  153.72 +bool removeIntros = false;
  153.73 +int sdlFlashSize = 0;
  153.74 +int sdlRtcEnable = 0;
  153.75 +
  153.76 +int sdlDefaultJoypad = 0;
  153.77 +
  153.78 +SDL_Joystick **sdlDevices = NULL;
  153.79 +
  153.80 +u16 motion[4] = {
  153.81 +  SDLK_KP4, SDLK_KP6, SDLK_KP8, SDLK_KP2
  153.82 +};
  153.83 +
  153.84 +struct EmulatedSystem emulator = {
  153.85 +  NULL,
  153.86 +  NULL,
  153.87 +  NULL,
  153.88 +  NULL,
  153.89 +  NULL,
  153.90 +  NULL,
  153.91 +  NULL,
  153.92 +  NULL,
  153.93 +  NULL,
  153.94 +  NULL,
  153.95 +  NULL,
  153.96 +  NULL,
  153.97 +  false,
  153.98 +  0
  153.99 +};
 153.100 +
 153.101 +// Extra vars, only used for the GUI
 153.102 +//
 153.103 +int systemRenderedFrames;
 153.104 +int systemFPS;
 153.105 +
 153.106 +// Sound stuff
 153.107 +//
 153.108 +const  int         iSoundSamples  = 2048;
 153.109 +const  int         iSoundTotalLen = iSoundSamples * 4;
 153.110 +static u8          auiSoundBuffer[iSoundTotalLen];
 153.111 +static int         iSoundLen;
 153.112 +static SDL_cond *  pstSoundCond;
 153.113 +static SDL_mutex * pstSoundMutex;
 153.114 +
 153.115 +inline VBA::Window * GUI()
 153.116 +{
 153.117 +  return VBA::Window::poGetInstance();
 153.118 +}
 153.119 +
 153.120 +void systemMessage(int _iId, const char * _csFormat, ...)
 153.121 +{
 153.122 +  va_list args;
 153.123 +  va_start(args, _csFormat);
 153.124 +
 153.125 +  GUI()->vPopupErrorV(_(_csFormat), args);
 153.126 +
 153.127 +  va_end(args);
 153.128 +}
 153.129 +
 153.130 +void systemDrawScreen()
 153.131 +{
 153.132 +  GUI()->vDrawScreen();
 153.133 +  systemRenderedFrames++;
 153.134 +}
 153.135 +
 153.136 +bool systemReadJoypads()
 153.137 +{
 153.138 +  return true;
 153.139 +}
 153.140 +
 153.141 +u32 systemReadJoypad(int,bool)
 153.142 +{
 153.143 +  return GUI()->uiReadJoypad();
 153.144 +}
 153.145 +
 153.146 +void systemShowSpeed(int _iSpeed)
 153.147 +{
 153.148 +  systemFPS = systemRenderedFrames;
 153.149 +  systemRenderedFrames = 0;
 153.150 +
 153.151 +  GUI()->vShowSpeed(_iSpeed);
 153.152 +}
 153.153 +
 153.154 +void system10Frames(int _iRate)
 153.155 +{
 153.156 +  GUI()->vComputeFrameskip(_iRate);
 153.157 +}
 153.158 +
 153.159 +void systemFrame(int)
 153.160 +{
 153.161 +}
 153.162 +
 153.163 +void systemSetTitle(const char * _csTitle)
 153.164 +{
 153.165 +  GUI()->set_title(_csTitle);
 153.166 +}
 153.167 +
 153.168 +int systemScreenCapture(int _iNum)
 153.169 +{
 153.170 +  GUI()->vCaptureScreen(_iNum);
 153.171 +}
 153.172 +
 153.173 +void systemSoundWriteToBuffer()
 153.174 +{
 153.175 +  if (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING)
 153.176 +  {
 153.177 +    SDL_PauseAudio(0);
 153.178 +  }
 153.179 +
 153.180 +  bool bWait = true;
 153.181 +  while (bWait && ! speedup && GUI()->iGetThrottle() == 0)
 153.182 +  {
 153.183 +    SDL_mutexP(pstSoundMutex);
 153.184 +    if (iSoundLen < iSoundTotalLen)
 153.185 +    {
 153.186 +      bWait = false;
 153.187 +    }
 153.188 +    SDL_mutexV(pstSoundMutex);
 153.189 +  }
 153.190 +
 153.191 +  int iLen = soundBufferLen;
 153.192 +  int iCopied = 0;
 153.193 +  if (iSoundLen + iLen >= iSoundTotalLen)
 153.194 +  {
 153.195 +    iCopied = iSoundTotalLen - iSoundLen;
 153.196 +    memcpy(&auiSoundBuffer[iSoundLen], soundFinalWave, iCopied);
 153.197 +
 153.198 +    iSoundLen = iSoundTotalLen;
 153.199 +    SDL_CondSignal(pstSoundCond);
 153.200 +
 153.201 +    bWait = true;
 153.202 +    if (! speedup && GUI()->iGetThrottle() == 0)
 153.203 +    {
 153.204 +      while(bWait)
 153.205 +      {
 153.206 +        SDL_mutexP(pstSoundMutex);
 153.207 +        if (iSoundLen < iSoundTotalLen)
 153.208 +        {
 153.209 +          bWait = false;
 153.210 +        }
 153.211 +        SDL_mutexV(pstSoundMutex);
 153.212 +      }
 153.213 +
 153.214 +      memcpy(auiSoundBuffer, ((u8 *)soundFinalWave) + iCopied,
 153.215 +             soundBufferLen - iCopied);
 153.216 +
 153.217 +      iSoundLen = soundBufferLen - iCopied;
 153.218 +    }
 153.219 +    else
 153.220 +    {
 153.221 +      memcpy(auiSoundBuffer, ((u8 *)soundFinalWave) + iCopied,
 153.222 +             soundBufferLen);
 153.223 +    }
 153.224 +  }
 153.225 +  else
 153.226 +  {
 153.227 +    memcpy(&auiSoundBuffer[iSoundLen], soundFinalWave, soundBufferLen);
 153.228 +    iSoundLen += soundBufferLen;
 153.229 +  }
 153.230 +}
 153.231 +
 153.232 +static void vSoundCallback(void * _pvUserData, u8 * _puiStream, int _iLen)
 153.233 +{
 153.234 +  if (! emulating)
 153.235 +  {
 153.236 +    return;
 153.237 +  }
 153.238 +
 153.239 +  SDL_mutexP(pstSoundMutex);
 153.240 +  if (! speedup && GUI()->iGetThrottle() == 0)
 153.241 +  {
 153.242 +    while (iSoundLen < iSoundTotalLen && emulating)
 153.243 +    {
 153.244 +      SDL_CondWait(pstSoundCond, pstSoundMutex);
 153.245 +    }
 153.246 +  }
 153.247 +  if (emulating)
 153.248 +  {
 153.249 +    memcpy(_puiStream, auiSoundBuffer, _iLen);
 153.250 +  }
 153.251 +  iSoundLen = 0;
 153.252 +  SDL_mutexV(pstSoundMutex);
 153.253 +}
 153.254 +
 153.255 +bool systemSoundInit()
 153.256 +{
 153.257 +  SDL_AudioSpec stAudio;
 153.258 +
 153.259 +  switch (soundQuality)
 153.260 +  {
 153.261 +  case 1:
 153.262 +    stAudio.freq = 44100;
 153.263 +    soundBufferLen = 1470 * 2;
 153.264 +    break;
 153.265 +  case 2:
 153.266 +    stAudio.freq = 22050;
 153.267 +    soundBufferLen = 736 * 2;
 153.268 +    break;
 153.269 +  case 4:
 153.270 +    stAudio.freq = 11025;
 153.271 +    soundBufferLen = 368 * 2;
 153.272 +    break;
 153.273 +  }
 153.274 +
 153.275 +  stAudio.format   = AUDIO_S16SYS;
 153.276 +  stAudio.channels = 2;
 153.277 +  stAudio.samples  = iSoundSamples;
 153.278 +  stAudio.callback = vSoundCallback;
 153.279 +  stAudio.userdata = NULL;
 153.280 +
 153.281 +  if (SDL_OpenAudio(&stAudio, NULL) < 0)
 153.282 +  {
 153.283 +    fprintf(stderr, "Failed to open audio: %s\n", SDL_GetError());
 153.284 +    return false;
 153.285 +  }
 153.286 +
 153.287 +  pstSoundCond  = SDL_CreateCond();
 153.288 +  pstSoundMutex = SDL_CreateMutex();
 153.289 +
 153.290 +  soundBufferTotalLen = soundBufferLen * 10;
 153.291 +  iSoundLen = 0;
 153.292 +  systemSoundOn = true;
 153.293 +
 153.294 +  return true;
 153.295 +}
 153.296 +
 153.297 +void systemSoundShutdown()
 153.298 +{
 153.299 +  SDL_mutexP(pstSoundMutex);
 153.300 +  int iSave = emulating;
 153.301 +  emulating = 0;
 153.302 +  SDL_CondSignal(pstSoundCond);
 153.303 +  SDL_mutexV(pstSoundMutex);
 153.304 +
 153.305 +  SDL_DestroyCond(pstSoundCond);
 153.306 +  pstSoundCond = NULL;
 153.307 +
 153.308 +  SDL_DestroyMutex(pstSoundMutex);
 153.309 +  pstSoundMutex = NULL;
 153.310 +
 153.311 +  SDL_CloseAudio();
 153.312 +
 153.313 +  emulating = iSave;
 153.314 +  systemSoundOn = false;
 153.315 +}
 153.316 +
 153.317 +void systemSoundPause()
 153.318 +{
 153.319 +  SDL_PauseAudio(1);
 153.320 +}
 153.321 +
 153.322 +void systemSoundResume()
 153.323 +{
 153.324 +  SDL_PauseAudio(0);
 153.325 +}
 153.326 +
 153.327 +void systemSoundReset()
 153.328 +{
 153.329 +}
 153.330 +
 153.331 +u32 systemGetClock()
 153.332 +{
 153.333 +  return SDL_GetTicks();
 153.334 +}
 153.335 +
 153.336 +void systemUpdateMotionSensor()
 153.337 +{
 153.338 +}
 153.339 +
 153.340 +int systemGetSensorX()
 153.341 +{
 153.342 +  return 0;
 153.343 +}
 153.344 +
 153.345 +int systemGetSensorY()
 153.346 +{
 153.347 +  return 0;
 153.348 +}
 153.349 +
 153.350 +void systemGbPrint(u8 * _puiData,
 153.351 +                   int  _iPages,
 153.352 +                   int  _iFeed,
 153.353 +                   int  _iPalette,
 153.354 +                   int  _iContrast)
 153.355 +{
 153.356 +}
 153.357 +
 153.358 +void systemScreenMessage(const char * _csMsg, int slot, int duration, const char *colorList)
 153.359 +{
 153.360 +}
 153.361 +
 153.362 +bool systemCanChangeSoundQuality()
 153.363 +{
 153.364 +  return true;
 153.365 +}
 153.366 +
 153.367 +bool systemPauseOnFrame()
 153.368 +{
 153.369 +  return false;
 153.370 +}
 153.371 +
 153.372 +void systemGbBorderOn()
 153.373 +{
 153.374 +}
 153.375 +
 153.376 +void debuggerMain()
 153.377 +{
 153.378 +}
 153.379 +
 153.380 +void debuggerSignal(int, int)
 153.381 +{
 153.382 +}
 153.383 +
 153.384 +void debuggerOutput(char *, u32)
 153.385 +{
 153.386 +}
 153.387 +
 153.388 +char *sdlGetFilename(char *name)
 153.389 +{
 153.390 +  static char filebuffer[2048];
 153.391 +
 153.392 +  int len = strlen(name);
 153.393 +  
 153.394 +  char *p = name + len - 1;
 153.395 +  
 153.396 +  while(true) {
 153.397 +    if(*p == '/' ||
 153.398 +       *p == '\\') {
 153.399 +      p++;
 153.400 +      break;
 153.401 +    }
 153.402 +    len--;
 153.403 +    p--;
 153.404 +    if(len == 0)
 153.405 +      break;
 153.406 +  }
 153.407 +  
 153.408 +  if(len == 0)
 153.409 +    strcpy(filebuffer, name);
 153.410 +  else
 153.411 +    strcpy(filebuffer, p);
 153.412 +  return filebuffer;
 153.413 +}
 153.414 +
 153.415 +bool sdlCheckJoyKey(int key)
 153.416 +{
 153.417 +  int dev = (key >> 12) - 1;
 153.418 +  int what = key & 0xfff;
 153.419 +
 153.420 +  if(what >= 128) {
 153.421 +    // joystick button
 153.422 +    int button = what - 128;
 153.423 +
 153.424 +    if(button >= SDL_JoystickNumButtons(sdlDevices[dev]))
 153.425 +      return false;
 153.426 +  } else if (what < 0x20) {
 153.427 +    // joystick axis    
 153.428 +    what >>= 1;
 153.429 +    if(what >= SDL_JoystickNumAxes(sdlDevices[dev]))
 153.430 +      return false;
 153.431 +  } else if (what < 0x30) {
 153.432 +    // joystick hat
 153.433 +    what = (what & 15);
 153.434 +    what >>= 2;
 153.435 +    if(what >= SDL_JoystickNumHats(sdlDevices[dev]))
 153.436 +      return false;
 153.437 +  }
 153.438 +
 153.439 +  // no problem found
 153.440 +  return true;
 153.441 +}
 153.442 +
 153.443 +u16 checksumBIOS()
 153.444 +{
 153.445 +	bool hasBIOS = false;
 153.446 +	u8 * tempBIOS;
 153.447 +	if(useBios)
 153.448 +	{
 153.449 +		tempBIOS = (u8 *)malloc(0x4000);
 153.450 +		int size = 0x4000;
 153.451 +		if(utilLoad(biosFileName,
 153.452 +					utilIsGBABios,
 153.453 +					tempBIOS,
 153.454 +					size)) {
 153.455 +		if(size == 0x4000)
 153.456 +			hasBIOS = true;
 153.457 +		}
 153.458 +	}
 153.459 +
 153.460 +	u16 biosCheck = 0;
 153.461 +	if(hasBIOS) {
 153.462 +		for(int i = 0; i < 0x4000; i += 4)
 153.463 +			biosCheck += *((u32 *)&tempBIOS[i]);
 153.464 +		free(tempBIOS);
 153.465 +	}
 153.466 +
 153.467 +	return biosCheck;
 153.468 +}
 153.469 +
 153.470 +void (*dbgMain)() = debuggerMain;
 153.471 +void (*dbgSignal)(int, int) = debuggerSignal;
 153.472 +void (*dbgOutput)(char *, u32) = debuggerOutput;
   154.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   154.2 +++ b/src/gtk/tools.cpp	Sat Mar 03 10:31:27 2012 -0600
   154.3 @@ -0,0 +1,65 @@
   154.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   154.5 +// Copyright (C) 1999-2003 Forgotten
   154.6 +// Copyright (C) 2004 Forgotten and the VBA development team
   154.7 +
   154.8 +// This program is free software; you can redistribute it and/or modify
   154.9 +// it under the terms of the GNU General Public License as published by
  154.10 +// the Free Software Foundation; either version 2, or(at your option)
  154.11 +// any later version.
  154.12 +//
  154.13 +// This program is distributed in the hope that it will be useful,
  154.14 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  154.15 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  154.16 +// GNU General Public License for more details.
  154.17 +//
  154.18 +// You should have received a copy of the GNU General Public License
  154.19 +// along with this program; if not, write to the Free Software Foundation,
  154.20 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  154.21 +
  154.22 +#include "tools.h"
  154.23 +
  154.24 +namespace VBA
  154.25 +{
  154.26 +
  154.27 +std::string sCutSuffix(const std::string & _rsString,
  154.28 +                       const std::string & _rsSep)
  154.29 +{
  154.30 +  return _rsString.substr(0, _rsString.find_last_of(_rsSep));
  154.31 +}
  154.32 +
  154.33 +Glib::ustring sCutSuffix(const Glib::ustring & _rsString,
  154.34 +                         const Glib::ustring & _rsSep)
  154.35 +{
  154.36 +  return _rsString.substr(0, _rsString.find_last_of(_rsSep));
  154.37 +}
  154.38 +
  154.39 +bool bHasSuffix(const Glib::ustring & _rsString,
  154.40 +                const Glib::ustring & _rsSuffix,
  154.41 +                bool _bCaseSensitive)
  154.42 +{
  154.43 +  if (_rsSuffix.size() > _rsString.size())
  154.44 +  {
  154.45 +    return false;
  154.46 +  }
  154.47 +
  154.48 +  Glib::ustring sEnd = _rsString.substr(_rsString.size() - _rsSuffix.size());
  154.49 +
  154.50 +  if (_bCaseSensitive)
  154.51 +  {
  154.52 +    if (_rsSuffix == sEnd)
  154.53 +    {
  154.54 +      return true;
  154.55 +    }
  154.56 +  }
  154.57 +  else
  154.58 +  {
  154.59 +    if (_rsSuffix.lowercase() == sEnd.lowercase())
  154.60 +    {
  154.61 +      return true;
  154.62 +    }
  154.63 +  }
  154.64 +
  154.65 +  return false;
  154.66 +}
  154.67 +
  154.68 +} // namespace VBA
   155.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   155.2 +++ b/src/gtk/tools.h	Sat Mar 03 10:31:27 2012 -0600
   155.3 @@ -0,0 +1,42 @@
   155.4 +// -*- C++ -*-
   155.5 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   155.6 +// Copyright (C) 1999-2003 Forgotten
   155.7 +// Copyright (C) 2004 Forgotten and the VBA development team
   155.8 +
   155.9 +// This program is free software; you can redistribute it and/or modify
  155.10 +// it under the terms of the GNU General Public License as published by
  155.11 +// the Free Software Foundation; either version 2, or(at your option)
  155.12 +// any later version.
  155.13 +//
  155.14 +// This program is distributed in the hope that it will be useful,
  155.15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  155.16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  155.17 +// GNU General Public License for more details.
  155.18 +//
  155.19 +// You should have received a copy of the GNU General Public License
  155.20 +// along with this program; if not, write to the Free Software Foundation,
  155.21 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  155.22 +
  155.23 +#ifndef __VBA_TOOLS_H__
  155.24 +#define __VBA_TOOLS_H__
  155.25 +
  155.26 +#include <string>
  155.27 +#include <glibmm/ustring.h>
  155.28 +
  155.29 +namespace VBA
  155.30 +{
  155.31 +
  155.32 +std::string sCutSuffix(const std::string & _rsString,
  155.33 +                       const std::string & _rsSep = ".");
  155.34 +
  155.35 +Glib::ustring sCutSuffix(const Glib::ustring & _rsString,
  155.36 +                         const Glib::ustring & _rsSep = ".");
  155.37 +
  155.38 +bool bHasSuffix(const Glib::ustring & _rsString,
  155.39 +                const Glib::ustring & _rsSuffix,
  155.40 +                bool _bCaseSensitive = true);
  155.41 +
  155.42 +}
  155.43 +
  155.44 +
  155.45 +#endif // __VBA_TOOLS_H__
   156.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   156.2 +++ b/src/gtk/vba.glade	Sat Mar 03 10:31:27 2012 -0600
   156.3 @@ -0,0 +1,3597 @@
   156.4 +<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
   156.5 +<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
   156.6 +
   156.7 +<glade-interface>
   156.8 +
   156.9 +<widget class="GtkWindow" id="MainWindow">
  156.10 +  <property name="title" translatable="yes">VBA</property>
  156.11 +  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  156.12 +  <property name="window_position">GTK_WIN_POS_NONE</property>
  156.13 +  <property name="modal">False</property>
  156.14 +  <property name="resizable">True</property>
  156.15 +  <property name="destroy_with_parent">False</property>
  156.16 +  <property name="skip_taskbar_hint">False</property>
  156.17 +  <property name="skip_pager_hint">False</property>
  156.18 +  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
  156.19 +
  156.20 +  <child>
  156.21 +    <widget class="GtkVBox" id="vbox1">
  156.22 +      <property name="visible">True</property>
  156.23 +      <property name="homogeneous">False</property>
  156.24 +      <property name="spacing">0</property>
  156.25 +
  156.26 +      <child>
  156.27 +	<widget class="GtkHandleBox" id="handlebox1">
  156.28 +	  <property name="visible">True</property>
  156.29 +	  <property name="shadow_type">GTK_SHADOW_OUT</property>
  156.30 +	  <property name="handle_position">GTK_POS_LEFT</property>
  156.31 +	  <property name="snap_edge">GTK_POS_TOP</property>
  156.32 +
  156.33 +	  <child>
  156.34 +	    <widget class="GtkMenuBar" id="MenuBar">
  156.35 +	      <property name="visible">True</property>
  156.36 +
  156.37 +	      <child>
  156.38 +		<widget class="GtkMenuItem" id="FileMenu">
  156.39 +		  <property name="visible">True</property>
  156.40 +		  <property name="label" translatable="yes">_File</property>
  156.41 +		  <property name="use_underline">True</property>
  156.42 +
  156.43 +		  <child>
  156.44 +		    <widget class="GtkMenu" id="FileMenu_menu">
  156.45 +
  156.46 +		      <child>
  156.47 +			<widget class="GtkImageMenuItem" id="FileOpen">
  156.48 +			  <property name="visible">True</property>
  156.49 +			  <property name="label" translatable="yes">_Open...</property>
  156.50 +			  <property name="use_underline">True</property>
  156.51 +			  <accelerator key="O" modifiers="GDK_CONTROL_MASK" signal="activate"/>
  156.52 +
  156.53 +			  <child internal-child="image">
  156.54 +			    <widget class="GtkImage" id="image128">
  156.55 +			      <property name="visible">True</property>
  156.56 +			      <property name="stock">gtk-open</property>
  156.57 +			      <property name="icon_size">1</property>
  156.58 +			      <property name="xalign">0.5</property>
  156.59 +			      <property name="yalign">0.5</property>
  156.60 +			      <property name="xpad">0</property>
  156.61 +			      <property name="ypad">0</property>
  156.62 +			    </widget>
  156.63 +			  </child>
  156.64 +			</widget>
  156.65 +		      </child>
  156.66 +
  156.67 +		      <child>
  156.68 +			<widget class="GtkSeparatorMenuItem" id="separator1">
  156.69 +			  <property name="visible">True</property>
  156.70 +			</widget>
  156.71 +		      </child>
  156.72 +
  156.73 +		      <child>
  156.74 +			<widget class="GtkMenuItem" id="FileLoad">
  156.75 +			  <property name="visible">True</property>
  156.76 +			  <property name="label" translatable="yes">_Load...</property>
  156.77 +			  <property name="use_underline">True</property>
  156.78 +			  <accelerator key="L" modifiers="GDK_CONTROL_MASK" signal="activate"/>
  156.79 +			</widget>
  156.80 +		      </child>
  156.81 +
  156.82 +		      <child>
  156.83 +			<widget class="GtkMenuItem" id="FileSave">
  156.84 +			  <property name="visible">True</property>
  156.85 +			  <property name="label" translatable="yes">_Save...</property>
  156.86 +			  <property name="use_underline">True</property>
  156.87 +			  <accelerator key="S" modifiers="GDK_CONTROL_MASK" signal="activate"/>
  156.88 +			</widget>
  156.89 +		      </child>
  156.90 +
  156.91 +		      <child>
  156.92 +			<widget class="GtkMenuItem" id="LoadGameMenu">
  156.93 +			  <property name="visible">True</property>
  156.94 +			  <property name="label" translatable="yes">Loa_d game</property>
  156.95 +			  <property name="use_underline">True</property>
  156.96 +
  156.97 +			  <child>
  156.98 +			    <widget class="GtkMenu" id="LoadGameMenu_menu">
  156.99 +
 156.100 +			      <child>
 156.101 +				<widget class="GtkMenuItem" id="LoadGameMostRecent">
 156.102 +				  <property name="visible">True</property>
 156.103 +				  <property name="label" translatable="yes">Most recent</property>
 156.104 +				  <property name="use_underline">True</property>
 156.105 +				</widget>
 156.106 +			      </child>
 156.107 +
 156.108 +			      <child>
 156.109 +				<widget class="GtkCheckMenuItem" id="LoadGameAuto">
 156.110 +				  <property name="visible">True</property>
 156.111 +				  <property name="label" translatable="yes">Auto load most recent</property>
 156.112 +				  <property name="use_underline">True</property>
 156.113 +				  <property name="active">False</property>
 156.114 +				</widget>
 156.115 +			      </child>
 156.116 +
 156.117 +			      <child>
 156.118 +				<widget class="GtkSeparatorMenuItem" id="separator28">
 156.119 +				  <property name="visible">True</property>
 156.120 +				</widget>
 156.121 +			      </child>
 156.122 +
 156.123 +			      <child>
 156.124 +				<widget class="GtkMenuItem" id="LoadGameSlot1">
 156.125 +				  <property name="visible">True</property>
 156.126 +				  <property name="label" translatable="yes">Slot1</property>
 156.127 +				  <property name="use_underline">True</property>
 156.128 +				  <accelerator key="F1" modifiers="0" signal="activate"/>
 156.129 +				</widget>
 156.130 +			      </child>
 156.131 +
 156.132 +			      <child>
 156.133 +				<widget class="GtkMenuItem" id="LoadGameSlot2">
 156.134 +				  <property name="visible">True</property>
 156.135 +				  <property name="label" translatable="yes">Slot2</property>
 156.136 +				  <property name="use_underline">True</property>
 156.137 +				  <accelerator key="F2" modifiers="0" signal="activate"/>
 156.138 +				</widget>
 156.139 +			      </child>
 156.140 +
 156.141 +			      <child>
 156.142 +				<widget class="GtkMenuItem" id="LoadGameSlot3">
 156.143 +				  <property name="visible">True</property>
 156.144 +				  <property name="label" translatable="yes">Slot3</property>
 156.145 +				  <property name="use_underline">True</property>
 156.146 +				  <accelerator key="F3" modifiers="0" signal="activate"/>
 156.147 +				</widget>
 156.148 +			      </child>
 156.149 +
 156.150 +			      <child>
 156.151 +				<widget class="GtkMenuItem" id="LoadGameSlot4">
 156.152 +				  <property name="visible">True</property>
 156.153 +				  <property name="label" translatable="yes">Slot4</property>
 156.154 +				  <property name="use_underline">True</property>
 156.155 +				  <accelerator key="F4" modifiers="0" signal="activate"/>
 156.156 +				</widget>
 156.157 +			      </child>
 156.158 +
 156.159 +			      <child>
 156.160 +				<widget class="GtkMenuItem" id="LoadGameSlot5">
 156.161 +				  <property name="visible">True</property>
 156.162 +				  <property name="label" translatable="yes">Slot5</property>
 156.163 +				  <property name="use_underline">True</property>
 156.164 +				  <accelerator key="F5" modifiers="0" signal="activate"/>
 156.165 +				</widget>
 156.166 +			      </child>
 156.167 +
 156.168 +			      <child>
 156.169 +				<widget class="GtkMenuItem" id="LoadGameSlot6">
 156.170 +				  <property name="visible">True</property>
 156.171 +				  <property name="label" translatable="yes">Slot6</property>
 156.172 +				  <property name="use_underline">True</property>
 156.173 +				  <accelerator key="F6" modifiers="0" signal="activate"/>
 156.174 +				</widget>
 156.175 +			      </child>
 156.176 +
 156.177 +			      <child>
 156.178 +				<widget class="GtkMenuItem" id="LoadGameSlot7">
 156.179 +				  <property name="visible">True</property>
 156.180 +				  <property name="label" translatable="yes">Slot7</property>
 156.181 +				  <property name="use_underline">True</property>
 156.182 +				  <accelerator key="F7" modifiers="0" signal="activate"/>
 156.183 +				</widget>
 156.184 +			      </child>
 156.185 +
 156.186 +			      <child>
 156.187 +				<widget class="GtkMenuItem" id="LoadGameSlot8">
 156.188 +				  <property name="visible">True</property>
 156.189 +				  <property name="label" translatable="yes">Slot8</property>
 156.190 +				  <property name="use_underline">True</property>
 156.191 +				  <accelerator key="F8" modifiers="0" signal="activate"/>
 156.192 +				</widget>
 156.193 +			      </child>
 156.194 +
 156.195 +			      <child>
 156.196 +				<widget class="GtkMenuItem" id="LoadGameSlot9">
 156.197 +				  <property name="visible">True</property>
 156.198 +				  <property name="label" translatable="yes">Slot9</property>
 156.199 +				  <property name="use_underline">True</property>
 156.200 +				  <accelerator key="F9" modifiers="0" signal="activate"/>
 156.201 +				</widget>
 156.202 +			      </child>
 156.203 +
 156.204 +			      <child>
 156.205 +				<widget class="GtkMenuItem" id="LoadGameSlot10">
 156.206 +				  <property name="visible">True</property>
 156.207 +				  <property name="label" translatable="yes">Slot10</property>
 156.208 +				  <property name="use_underline">True</property>
 156.209 +				  <accelerator key="F10" modifiers="0" signal="activate"/>
 156.210 +				</widget>
 156.211 +			      </child>
 156.212 +			    </widget>
 156.213 +			  </child>
 156.214 +			</widget>
 156.215 +		      </child>
 156.216 +
 156.217 +		      <child>
 156.218 +			<widget class="GtkMenuItem" id="SaveGameMenu">
 156.219 +			  <property name="visible">True</property>
 156.220 +			  <property name="label" translatable="yes">S_ave game</property>
 156.221 +			  <property name="use_underline">True</property>
 156.222 +
 156.223 +			  <child>
 156.224 +			    <widget class="GtkMenu" id="SaveGameMenu_menu">
 156.225 +
 156.226 +			      <child>
 156.227 +				<widget class="GtkMenuItem" id="SaveGameOldest">
 156.228 +				  <property name="visible">True</property>
 156.229 +				  <property name="label" translatable="yes">Oldest slot</property>
 156.230 +				  <property name="use_underline">True</property>
 156.231 +				</widget>
 156.232 +			      </child>
 156.233 +
 156.234 +			      <child>
 156.235 +				<widget class="GtkSeparatorMenuItem" id="separator27">
 156.236 +				  <property name="visible">True</property>
 156.237 +				</widget>
 156.238 +			      </child>
 156.239 +
 156.240 +			      <child>
 156.241 +				<widget class="GtkMenuItem" id="SaveGameSlot1">
 156.242 +				  <property name="visible">True</property>
 156.243 +				  <property name="label" translatable="yes">Slot1</property>
 156.244 +				  <property name="use_underline">True</property>
 156.245 +				  <accelerator key="F1" modifiers="GDK_SHIFT_MASK" signal="activate"/>
 156.246 +				</widget>
 156.247 +			      </child>
 156.248 +
 156.249 +			      <child>
 156.250 +				<widget class="GtkMenuItem" id="SaveGameSlot2">
 156.251 +				  <property name="visible">True</property>
 156.252 +				  <property name="label" translatable="yes">Slot2</property>
 156.253 +				  <property name="use_underline">True</property>
 156.254 +				  <accelerator key="F2" modifiers="GDK_SHIFT_MASK" signal="activate"/>
 156.255 +				</widget>
 156.256 +			      </child>
 156.257 +
 156.258 +			      <child>
 156.259 +				<widget class="GtkMenuItem" id="SaveGameSlot3">
 156.260 +				  <property name="visible">True</property>
 156.261 +				  <property name="label" translatable="yes">Slot3</property>
 156.262 +				  <property name="use_underline">True</property>
 156.263 +				  <accelerator key="F3" modifiers="GDK_SHIFT_MASK" signal="activate"/>
 156.264 +				</widget>
 156.265 +			      </child>
 156.266 +
 156.267 +			      <child>
 156.268 +				<widget class="GtkMenuItem" id="SaveGameSlot4">
 156.269 +				  <property name="visible">True</property>
 156.270 +				  <property name="label" translatable="yes">Slot4</property>
 156.271 +				  <property name="use_underline">True</property>
 156.272 +				  <accelerator key="F4" modifiers="GDK_SHIFT_MASK" signal="activate"/>
 156.273 +				</widget>
 156.274 +			      </child>
 156.275 +
 156.276 +			      <child>
 156.277 +				<widget class="GtkMenuItem" id="SaveGameSlot5">
 156.278 +				  <property name="visible">True</property>
 156.279 +				  <property name="label" translatable="yes">Slot5</property>
 156.280 +				  <property name="use_underline">True</property>
 156.281 +				  <accelerator key="F5" modifiers="GDK_SHIFT_MASK" signal="activate"/>
 156.282 +				</widget>
 156.283 +			      </child>
 156.284 +
 156.285 +			      <child>
 156.286 +				<widget class="GtkMenuItem" id="SaveGameSlot6">
 156.287 +				  <property name="visible">True</property>
 156.288 +				  <property name="label" translatable="yes">Slot6</property>
 156.289 +				  <property name="use_underline">True</property>
 156.290 +				  <accelerator key="F6" modifiers="GDK_SHIFT_MASK" signal="activate"/>
 156.291 +				</widget>
 156.292 +			      </child>
 156.293 +
 156.294 +			      <child>
 156.295 +				<widget class="GtkMenuItem" id="SaveGameSlot7">
 156.296 +				  <property name="visible">True</property>
 156.297 +				  <property name="label" translatable="yes">Slot7</property>
 156.298 +				  <property name="use_underline">True</property>
 156.299 +				  <accelerator key="F7" modifiers="GDK_SHIFT_MASK" signal="activate"/>
 156.300 +				</widget>
 156.301 +			      </child>
 156.302 +
 156.303 +			      <child>
 156.304 +				<widget class="GtkMenuItem" id="SaveGameSlot8">
 156.305 +				  <property name="visible">True</property>
 156.306 +				  <property name="label" translatable="yes">Slot8</property>
 156.307 +				  <property name="use_underline">True</property>
 156.308 +				  <accelerator key="F8" modifiers="GDK_SHIFT_MASK" signal="activate"/>
 156.309 +				</widget>
 156.310 +			      </child>
 156.311 +
 156.312 +			      <child>
 156.313 +				<widget class="GtkMenuItem" id="SaveGameSlot9">
 156.314 +				  <property name="visible">True</property>
 156.315 +				  <property name="label" translatable="yes">Slot9</property>
 156.316 +				  <property name="use_underline">True</property>
 156.317 +				  <accelerator key="F9" modifiers="GDK_SHIFT_MASK" signal="activate"/>
 156.318 +				</widget>
 156.319 +			      </child>
 156.320 +
 156.321 +			      <child>
 156.322 +				<widget class="GtkMenuItem" id="SaveGameSlot10">
 156.323 +				  <property name="visible">True</property>
 156.324 +				  <property name="label" translatable="yes">Slot10</property>
 156.325 +				  <property name="use_underline">True</property>
 156.326 +				  <accelerator key="F10" modifiers="GDK_SHIFT_MASK" signal="activate"/>
 156.327 +				</widget>
 156.328 +			      </child>
 156.329 +			    </widget>
 156.330 +			  </child>
 156.331 +			</widget>
 156.332 +		      </child>
 156.333 +
 156.334 +		      <child>
 156.335 +			<widget class="GtkSeparatorMenuItem" id="separator2">
 156.336 +			  <property name="visible">True</property>
 156.337 +			</widget>
 156.338 +		      </child>
 156.339 +
 156.340 +		      <child>
 156.341 +			<widget class="GtkCheckMenuItem" id="FilePause">
 156.342 +			  <property name="visible">True</property>
 156.343 +			  <property name="label" translatable="yes">_Pause</property>
 156.344 +			  <property name="use_underline">True</property>
 156.345 +			  <property name="active">False</property>
 156.346 +			  <accelerator key="P" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 156.347 +			</widget>
 156.348 +		      </child>
 156.349 +
 156.350 +		      <child>
 156.351 +			<widget class="GtkMenuItem" id="FileReset">
 156.352 +			  <property name="visible">True</property>
 156.353 +			  <property name="label" translatable="yes">_Reset</property>
 156.354 +			  <property name="use_underline">True</property>
 156.355 +			  <accelerator key="R" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 156.356 +			</widget>
 156.357 +		      </child>
 156.358 +
 156.359 +		      <child>
 156.360 +			<widget class="GtkSeparatorMenuItem" id="separator3">
 156.361 +			  <property name="visible">True</property>
 156.362 +			</widget>
 156.363 +		      </child>
 156.364 +
 156.365 +		      <child>
 156.366 +			<widget class="GtkMenuItem" id="RecentMenu">
 156.367 +			  <property name="visible">True</property>
 156.368 +			  <property name="label" translatable="yes">Rece_nt</property>
 156.369 +			  <property name="use_underline">True</property>
 156.370 +
 156.371 +			  <child>
 156.372 +			    <widget class="GtkMenu" id="RecentMenu_menu">
 156.373 +
 156.374 +			      <child>
 156.375 +				<widget class="GtkMenuItem" id="RecentReset">
 156.376 +				  <property name="visible">True</property>
 156.377 +				  <property name="label" translatable="yes">_Reset</property>
 156.378 +				  <property name="use_underline">True</property>
 156.379 +				</widget>
 156.380 +			      </child>
 156.381 +
 156.382 +			      <child>
 156.383 +				<widget class="GtkCheckMenuItem" id="RecentFreeze">
 156.384 +				  <property name="visible">True</property>
 156.385 +				  <property name="label" translatable="yes">_Freeze</property>
 156.386 +				  <property name="use_underline">True</property>
 156.387 +				  <property name="active">False</property>
 156.388 +				</widget>
 156.389 +			      </child>
 156.390 +
 156.391 +			      <child>
 156.392 +				<widget class="GtkSeparatorMenuItem" id="separator29">
 156.393 +				  <property name="visible">True</property>
 156.394 +				</widget>
 156.395 +			      </child>
 156.396 +			    </widget>
 156.397 +			  </child>
 156.398 +			</widget>
 156.399 +		      </child>
 156.400 +
 156.401 +		      <child>
 156.402 +			<widget class="GtkSeparatorMenuItem" id="separator4">
 156.403 +			  <property name="visible">True</property>
 156.404 +			</widget>
 156.405 +		      </child>
 156.406 +
 156.407 +		      <child>
 156.408 +			<widget class="GtkMenuItem" id="ImportMenu">
 156.409 +			  <property name="visible">True</property>
 156.410 +			  <property name="label" translatable="yes">_Import</property>
 156.411 +			  <property name="use_underline">True</property>
 156.412 +
 156.413 +			  <child>
 156.414 +			    <widget class="GtkMenu" id="ImportMenu_menu">
 156.415 +
 156.416 +			      <child>
 156.417 +				<widget class="GtkMenuItem" id="ImportBatteryFile">
 156.418 +				  <property name="visible">True</property>
 156.419 +				  <property name="label" translatable="yes">_Battery file...</property>
 156.420 +				  <property name="use_underline">True</property>
 156.421 +				</widget>
 156.422 +			      </child>
 156.423 +			    </widget>
 156.424 +			  </child>
 156.425 +			</widget>
 156.426 +		      </child>
 156.427 +
 156.428 +		      <child>
 156.429 +			<widget class="GtkMenuItem" id="ExportMenu">
 156.430 +			  <property name="visible">True</property>
 156.431 +			  <property name="label" translatable="yes">E_xport</property>
 156.432 +			  <property name="use_underline">True</property>
 156.433 +
 156.434 +			  <child>
 156.435 +			    <widget class="GtkMenu" id="ExportMenu_menu">
 156.436 +
 156.437 +			      <child>
 156.438 +				<widget class="GtkMenuItem" id="ExportBatteryFile">
 156.439 +				  <property name="visible">True</property>
 156.440 +				  <property name="label" translatable="yes">_Battery file...</property>
 156.441 +				  <property name="use_underline">True</property>
 156.442 +				</widget>
 156.443 +			      </child>
 156.444 +			    </widget>
 156.445 +			  </child>
 156.446 +			</widget>
 156.447 +		      </child>
 156.448 +
 156.449 +		      <child>
 156.450 +			<widget class="GtkSeparatorMenuItem" id="separator5">
 156.451 +			  <property name="visible">True</property>
 156.452 +			</widget>
 156.453 +		      </child>
 156.454 +
 156.455 +		      <child>
 156.456 +			<widget class="GtkMenuItem" id="FileScreenCapture">
 156.457 +			  <property name="visible">True</property>
 156.458 +			  <property name="label" translatable="yes">Screen capt_ure...</property>
 156.459 +			  <property name="use_underline">True</property>
 156.460 +			</widget>
 156.461 +		      </child>
 156.462 +
 156.463 +		      <child>
 156.464 +			<widget class="GtkSeparatorMenuItem" id="separator6">
 156.465 +			  <property name="visible">True</property>
 156.466 +			</widget>
 156.467 +		      </child>
 156.468 +
 156.469 +		      <child>
 156.470 +			<widget class="GtkImageMenuItem" id="FileClose">
 156.471 +			  <property name="visible">True</property>
 156.472 +			  <property name="label" translatable="yes">_Close</property>
 156.473 +			  <property name="use_underline">True</property>
 156.474 +
 156.475 +			  <child internal-child="image">
 156.476 +			    <widget class="GtkImage" id="image129">
 156.477 +			      <property name="visible">True</property>
 156.478 +			      <property name="stock">gtk-close</property>
 156.479 +			      <property name="icon_size">1</property>
 156.480 +			      <property name="xalign">0.5</property>
 156.481 +			      <property name="yalign">0.5</property>
 156.482 +			      <property name="xpad">0</property>
 156.483 +			      <property name="ypad">0</property>
 156.484 +			    </widget>
 156.485 +			  </child>
 156.486 +			</widget>
 156.487 +		      </child>
 156.488 +
 156.489 +		      <child>
 156.490 +			<widget class="GtkImageMenuItem" id="FileExit">
 156.491 +			  <property name="visible">True</property>
 156.492 +			  <property name="label" translatable="yes">_Exit</property>
 156.493 +			  <property name="use_underline">True</property>
 156.494 +			  <accelerator key="X" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 156.495 +
 156.496 +			  <child internal-child="image">
 156.497 +			    <widget class="GtkImage" id="image130">
 156.498 +			      <property name="visible">True</property>
 156.499 +			      <property name="stock">gtk-quit</property>
 156.500 +			      <property name="icon_size">1</property>
 156.501 +			      <property name="xalign">0.5</property>
 156.502 +			      <property name="yalign">0.5</property>
 156.503 +			      <property name="xpad">0</property>
 156.504 +			      <property name="ypad">0</property>
 156.505 +			    </widget>
 156.506 +			  </child>
 156.507 +			</widget>
 156.508 +		      </child>
 156.509 +		    </widget>
 156.510 +		  </child>
 156.511 +		</widget>
 156.512 +	      </child>
 156.513 +
 156.514 +	      <child>
 156.515 +		<widget class="GtkMenuItem" id="OptionsMenu">
 156.516 +		  <property name="visible">True</property>
 156.517 +		  <property name="label" translatable="yes">_Options</property>
 156.518 +		  <property name="use_underline">True</property>
 156.519 +
 156.520 +		  <child>
 156.521 +		    <widget class="GtkMenu" id="OptionsMenu_menu">
 156.522 +
 156.523 +		      <child>
 156.524 +			<widget class="GtkMenuItem" id="FrameskipMenu">
 156.525 +			  <property name="visible">True</property>
 156.526 +			  <property name="label" translatable="yes">_Frameskip</property>
 156.527 +			  <property name="use_underline">True</property>
 156.528 +
 156.529 +			  <child>
 156.530 +			    <widget class="GtkMenu" id="FrameskipMenu_menu">
 156.531 +
 156.532 +			      <child>
 156.533 +				<widget class="GtkMenuItem" id="ThrottleMenu">
 156.534 +				  <property name="visible">True</property>
 156.535 +				  <property name="label" translatable="yes">_Throttle</property>
 156.536 +				  <property name="use_underline">True</property>
 156.537 +
 156.538 +				  <child>
 156.539 +				    <widget class="GtkMenu" id="ThrottleMenu_menu">
 156.540 +
 156.541 +				      <child>
 156.542 +					<widget class="GtkRadioMenuItem" id="ThrottleNoThrottle">
 156.543 +					  <property name="visible">True</property>
 156.544 +					  <property name="label" translatable="yes">_No throttle</property>
 156.545 +					  <property name="use_underline">True</property>
 156.546 +					  <property name="active">True</property>
 156.547 +					</widget>
 156.548 +				      </child>
 156.549 +
 156.550 +				      <child>
 156.551 +					<widget class="GtkRadioMenuItem" id="Throttle25">
 156.552 +					  <property name="visible">True</property>
 156.553 +					  <property name="label" translatable="yes">25%</property>
 156.554 +					  <property name="use_underline">True</property>
 156.555 +					  <property name="active">False</property>
 156.556 +					  <property name="group">ThrottleNoThrottle</property>
 156.557 +					</widget>
 156.558 +				      </child>
 156.559 +
 156.560 +				      <child>
 156.561 +					<widget class="GtkRadioMenuItem" id="Throttle50">
 156.562 +					  <property name="visible">True</property>
 156.563 +					  <property name="label" translatable="yes">50%</property>
 156.564 +					  <property name="use_underline">True</property>
 156.565 +					  <property name="active">False</property>
 156.566 +					  <property name="group">ThrottleNoThrottle</property>
 156.567 +					</widget>
 156.568 +				      </child>
 156.569 +
 156.570 +				      <child>
 156.571 +					<widget class="GtkRadioMenuItem" id="Throttle100">
 156.572 +					  <property name="visible">True</property>
 156.573 +					  <property name="label" translatable="yes">100%</property>
 156.574 +					  <property name="use_underline">True</property>
 156.575 +					  <property name="active">False</property>
 156.576 +					  <property name="group">ThrottleNoThrottle</property>
 156.577 +					</widget>
 156.578 +				      </child>
 156.579 +
 156.580 +				      <child>
 156.581 +					<widget class="GtkRadioMenuItem" id="Throttle150">
 156.582 +					  <property name="visible">True</property>
 156.583 +					  <property name="label" translatable="yes">150%</property>
 156.584 +					  <property name="use_underline">True</property>
 156.585 +					  <property name="active">False</property>
 156.586 +					  <property name="group">ThrottleNoThrottle</property>
 156.587 +					</widget>
 156.588 +				      </child>
 156.589 +
 156.590 +				      <child>
 156.591 +					<widget class="GtkRadioMenuItem" id="Throttle200">
 156.592 +					  <property name="visible">True</property>
 156.593 +					  <property name="label" translatable="yes">200%</property>
 156.594 +					  <property name="use_underline">True</property>
 156.595 +					  <property name="active">False</property>
 156.596 +					  <property name="group">ThrottleNoThrottle</property>
 156.597 +					</widget>
 156.598 +				      </child>
 156.599 +
 156.600 +				      <child>
 156.601 +					<widget class="GtkRadioMenuItem" id="ThrottleOther">
 156.602 +					  <property name="visible">True</property>
 156.603 +					  <property name="label" translatable="yes">_Other...</property>
 156.604 +					  <property name="use_underline">True</property>
 156.605 +					  <property name="active">False</property>
 156.606 +					  <property name="group">ThrottleNoThrottle</property>
 156.607 +					</widget>
 156.608 +				      </child>
 156.609 +				    </widget>
 156.610 +				  </child>
 156.611 +				</widget>
 156.612 +			      </child>
 156.613 +
 156.614 +			      <child>
 156.615 +				<widget class="GtkSeparatorMenuItem" id="separator19">
 156.616 +				  <property name="visible">True</property>
 156.617 +				</widget>
 156.618 +			      </child>
 156.619 +
 156.620 +			      <child>
 156.621 +				<widget class="GtkRadioMenuItem" id="FrameskipAutomatic">
 156.622 +				  <property name="visible">True</property>
 156.623 +				  <property name="label" translatable="yes">_Automatic</property>
 156.624 +				  <property name="use_underline">True</property>
 156.625 +				  <property name="active">True</property>
 156.626 +				</widget>
 156.627 +			      </child>
 156.628 +
 156.629 +			      <child>
 156.630 +				<widget class="GtkRadioMenuItem" id="Frameskip0">
 156.631 +				  <property name="visible">True</property>
 156.632 +				  <property name="label" translatable="yes">_0</property>
 156.633 +				  <property name="use_underline">True</property>
 156.634 +				  <property name="active">False</property>
 156.635 +				  <property name="group">FrameskipAutomatic</property>
 156.636 +				</widget>
 156.637 +			      </child>
 156.638 +
 156.639 +			      <child>
 156.640 +				<widget class="GtkRadioMenuItem" id="Frameskip1">
 156.641 +				  <property name="visible">True</property>
 156.642 +				  <property name="label" translatable="yes">_1</property>
 156.643 +				  <property name="use_underline">True</property>
 156.644 +				  <property name="active">False</property>
 156.645 +				  <property name="group">FrameskipAutomatic</property>
 156.646 +				</widget>
 156.647 +			      </child>
 156.648 +
 156.649 +			      <child>
 156.650 +				<widget class="GtkRadioMenuItem" id="Frameskip2">
 156.651 +				  <property name="visible">True</property>
 156.652 +				  <property name="label" translatable="yes">_2</property>
 156.653 +				  <property name="use_underline">True</property>
 156.654 +				  <property name="active">False</property>
 156.655 +				  <property name="group">FrameskipAutomatic</property>
 156.656 +				</widget>
 156.657 +			      </child>
 156.658 +
 156.659 +			      <child>
 156.660 +				<widget class="GtkRadioMenuItem" id="Frameskip3">
 156.661 +				  <property name="visible">True</property>
 156.662 +				  <property name="label" translatable="yes">_3</property>
 156.663 +				  <property name="use_underline">True</property>
 156.664 +				  <property name="active">False</property>
 156.665 +				  <property name="group">FrameskipAutomatic</property>
 156.666 +				</widget>
 156.667 +			      </child>
 156.668 +
 156.669 +			      <child>
 156.670 +				<widget class="GtkRadioMenuItem" id="Frameskip4">
 156.671 +				  <property name="visible">True</property>
 156.672 +				  <property name="label" translatable="yes">_4</property>
 156.673 +				  <property name="use_underline">True</property>
 156.674 +				  <property name="active">False</property>
 156.675 +				  <property name="group">FrameskipAutomatic</property>
 156.676 +				</widget>
 156.677 +			      </child>
 156.678 +
 156.679 +			      <child>
 156.680 +				<widget class="GtkRadioMenuItem" id="Frameskip5">
 156.681 +				  <property name="visible">True</property>
 156.682 +				  <property name="label" translatable="yes">_5</property>
 156.683 +				  <property name="use_underline">True</property>
 156.684 +				  <property name="active">False</property>
 156.685 +				  <property name="group">FrameskipAutomatic</property>
 156.686 +				</widget>
 156.687 +			      </child>
 156.688 +
 156.689 +			      <child>
 156.690 +				<widget class="GtkRadioMenuItem" id="Frameskip6">
 156.691 +				  <property name="visible">True</property>
 156.692 +				  <property name="label" translatable="yes">_6</property>
 156.693 +				  <property name="use_underline">True</property>
 156.694 +				  <property name="active">False</property>
 156.695 +				  <property name="group">FrameskipAutomatic</property>
 156.696 +				</widget>
 156.697 +			      </child>
 156.698 +
 156.699 +			      <child>
 156.700 +				<widget class="GtkRadioMenuItem" id="Frameskip7">
 156.701 +				  <property name="visible">True</property>
 156.702 +				  <property name="label" translatable="yes">_7</property>
 156.703 +				  <property name="use_underline">True</property>
 156.704 +				  <property name="active">False</property>
 156.705 +				  <property name="group">FrameskipAutomatic</property>
 156.706 +				</widget>
 156.707 +			      </child>
 156.708 +
 156.709 +			      <child>
 156.710 +				<widget class="GtkRadioMenuItem" id="Frameskip8">
 156.711 +				  <property name="visible">True</property>
 156.712 +				  <property name="label" translatable="yes">_8</property>
 156.713 +				  <property name="use_underline">True</property>
 156.714 +				  <property name="active">False</property>
 156.715 +				  <property name="group">FrameskipAutomatic</property>
 156.716 +				</widget>
 156.717 +			      </child>
 156.718 +
 156.719 +			      <child>
 156.720 +				<widget class="GtkRadioMenuItem" id="Frameskip9">
 156.721 +				  <property name="visible">True</property>
 156.722 +				  <property name="label" translatable="yes">_9</property>
 156.723 +				  <property name="use_underline">True</property>
 156.724 +				  <property name="active">False</property>
 156.725 +				  <property name="group">FrameskipAutomatic</property>
 156.726 +				</widget>
 156.727 +			      </child>
 156.728 +			    </widget>
 156.729 +			  </child>
 156.730 +			</widget>
 156.731 +		      </child>
 156.732 +
 156.733 +		      <child>
 156.734 +			<widget class="GtkMenuItem" id="VideoMenu">
 156.735 +			  <property name="visible">True</property>
 156.736 +			  <property name="label" translatable="yes">_Video</property>
 156.737 +			  <property name="use_underline">True</property>
 156.738 +
 156.739 +			  <child>
 156.740 +			    <widget class="GtkMenu" id="VideoMenu_menu">
 156.741 +
 156.742 +			      <child>
 156.743 +				<widget class="GtkRadioMenuItem" id="Video1x">
 156.744 +				  <property name="visible">True</property>
 156.745 +				  <property name="label" translatable="yes">_1x</property>
 156.746 +				  <property name="use_underline">True</property>
 156.747 +				  <property name="active">True</property>
 156.748 +				</widget>
 156.749 +			      </child>
 156.750 +
 156.751 +			      <child>
 156.752 +				<widget class="GtkRadioMenuItem" id="Video2x">
 156.753 +				  <property name="visible">True</property>
 156.754 +				  <property name="label" translatable="yes">_2x</property>
 156.755 +				  <property name="use_underline">True</property>
 156.756 +				  <property name="active">False</property>
 156.757 +				  <property name="group">Video1x</property>
 156.758 +				</widget>
 156.759 +			      </child>
 156.760 +
 156.761 +			      <child>
 156.762 +				<widget class="GtkRadioMenuItem" id="Video3x">
 156.763 +				  <property name="visible">True</property>
 156.764 +				  <property name="label" translatable="yes">_3x</property>
 156.765 +				  <property name="use_underline">True</property>
 156.766 +				  <property name="active">False</property>
 156.767 +				  <property name="group">Video1x</property>
 156.768 +				</widget>
 156.769 +			      </child>
 156.770 +
 156.771 +			      <child>
 156.772 +				<widget class="GtkRadioMenuItem" id="Video4x">
 156.773 +				  <property name="visible">True</property>
 156.774 +				  <property name="label" translatable="yes">_4x</property>
 156.775 +				  <property name="use_underline">True</property>
 156.776 +				  <property name="active">False</property>
 156.777 +				  <property name="group">Video1x</property>
 156.778 +				</widget>
 156.779 +			      </child>
 156.780 +
 156.781 +			      <child>
 156.782 +				<widget class="GtkRadioMenuItem" id="Video5x">
 156.783 +				  <property name="visible">True</property>
 156.784 +				  <property name="label" translatable="yes">_5x</property>
 156.785 +				  <property name="use_underline">True</property>
 156.786 +				  <property name="active">False</property>
 156.787 +				  <property name="group">Video1x</property>
 156.788 +				</widget>
 156.789 +			      </child>
 156.790 +
 156.791 +			      <child>
 156.792 +				<widget class="GtkRadioMenuItem" id="Video6x">
 156.793 +				  <property name="visible">True</property>
 156.794 +				  <property name="label" translatable="yes">_6x</property>
 156.795 +				  <property name="use_underline">True</property>
 156.796 +				  <property name="active">False</property>
 156.797 +				  <property name="group">Video1x</property>
 156.798 +				</widget>
 156.799 +			      </child>
 156.800 +
 156.801 +			      <child>
 156.802 +				<widget class="GtkSeparatorMenuItem" id="separator9">
 156.803 +				  <property name="visible">True</property>
 156.804 +				</widget>
 156.805 +			      </child>
 156.806 +
 156.807 +			      <child>
 156.808 +				<widget class="GtkMenuItem" id="LayersMenu">
 156.809 +				  <property name="visible">True</property>
 156.810 +				  <property name="label" translatable="yes">_Layers</property>
 156.811 +				  <property name="use_underline">True</property>
 156.812 +
 156.813 +				  <child>
 156.814 +				    <widget class="GtkMenu" id="LayersMenu_menu">
 156.815 +
 156.816 +				      <child>
 156.817 +					<widget class="GtkCheckMenuItem" id="LayersBg0">
 156.818 +					  <property name="visible">True</property>
 156.819 +					  <property name="label" translatable="yes">BG0</property>
 156.820 +					  <property name="use_underline">True</property>
 156.821 +					  <property name="active">False</property>
 156.822 +					  <accelerator key="1" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 156.823 +					</widget>
 156.824 +				      </child>
 156.825 +
 156.826 +				      <child>
 156.827 +					<widget class="GtkCheckMenuItem" id="LayersBg1">
 156.828 +					  <property name="visible">True</property>
 156.829 +					  <property name="label" translatable="yes">BG1</property>
 156.830 +					  <property name="use_underline">True</property>
 156.831 +					  <property name="active">False</property>
 156.832 +					  <accelerator key="2" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 156.833 +					</widget>
 156.834 +				      </child>
 156.835 +
 156.836 +				      <child>
 156.837 +					<widget class="GtkCheckMenuItem" id="LayersBg2">
 156.838 +					  <property name="visible">True</property>
 156.839 +					  <property name="label" translatable="yes">BG2</property>
 156.840 +					  <property name="use_underline">True</property>
 156.841 +					  <property name="active">False</property>
 156.842 +					  <accelerator key="3" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 156.843 +					</widget>
 156.844 +				      </child>
 156.845 +
 156.846 +				      <child>
 156.847 +					<widget class="GtkCheckMenuItem" id="LayersBg3">
 156.848 +					  <property name="visible">True</property>
 156.849 +					  <property name="label" translatable="yes">BG3</property>
 156.850 +					  <property name="use_underline">True</property>
 156.851 +					  <property name="active">False</property>
 156.852 +					  <accelerator key="4" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 156.853 +					</widget>
 156.854 +				      </child>
 156.855 +
 156.856 +				      <child>
 156.857 +					<widget class="GtkCheckMenuItem" id="LayersObj">
 156.858 +					  <property name="visible">True</property>
 156.859 +					  <property name="label" translatable="yes">OBJ</property>
 156.860 +					  <property name="use_underline">True</property>
 156.861 +					  <property name="active">False</property>
 156.862 +					  <accelerator key="5" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 156.863 +					</widget>
 156.864 +				      </child>
 156.865 +
 156.866 +				      <child>
 156.867 +					<widget class="GtkCheckMenuItem" id="LayersWin0">
 156.868 +					  <property name="visible">True</property>
 156.869 +					  <property name="label" translatable="yes">WIN0</property>
 156.870 +					  <property name="use_underline">True</property>
 156.871 +					  <property name="active">False</property>
 156.872 +					  <accelerator key="6" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 156.873 +					</widget>
 156.874 +				      </child>
 156.875 +
 156.876 +				      <child>
 156.877 +					<widget class="GtkCheckMenuItem" id="LayersWin1">
 156.878 +					  <property name="visible">True</property>
 156.879 +					  <property name="label" translatable="yes">WIN1</property>
 156.880 +					  <property name="use_underline">True</property>
 156.881 +					  <property name="active">False</property>
 156.882 +					  <accelerator key="7" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 156.883 +					</widget>
 156.884 +				      </child>
 156.885 +
 156.886 +				      <child>
 156.887 +					<widget class="GtkCheckMenuItem" id="LayersObjWin">
 156.888 +					  <property name="visible">True</property>
 156.889 +					  <property name="label" translatable="yes">OBJWIN</property>
 156.890 +					  <property name="use_underline">True</property>
 156.891 +					  <property name="active">False</property>
 156.892 +					  <accelerator key="8" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 156.893 +					</widget>
 156.894 +				      </child>
 156.895 +				    </widget>
 156.896 +				  </child>
 156.897 +				</widget>
 156.898 +			      </child>
 156.899 +			    </widget>
 156.900 +			  </child>
 156.901 +			</widget>
 156.902 +		      </child>
 156.903 +
 156.904 +		      <child>
 156.905 +			<widget class="GtkMenuItem" id="EmulatorMenu">
 156.906 +			  <property name="visible">True</property>
 156.907 +			  <property name="label" translatable="yes">_Emulator</property>
 156.908 +			  <property name="use_underline">True</property>
 156.909 +
 156.910 +			  <child>
 156.911 +			    <widget class="GtkMenu" id="EmulatorMenu_menu">
 156.912 +
 156.913 +			      <child>
 156.914 +				<widget class="GtkMenuItem" id="EmulatorDirectories">
 156.915 +				  <property name="visible">True</property>
 156.916 +				  <property name="label" translatable="yes">Directories...</property>
 156.917 +				  <property name="use_underline">True</property>
 156.918 +				</widget>
 156.919 +			      </child>
 156.920 +
 156.921 +			      <child>
 156.922 +				<widget class="GtkCheckMenuItem" id="EmulatorPauseWhenInactive">
 156.923 +				  <property name="visible">True</property>
 156.924 +				  <property name="label" translatable="yes">Pause when inactive window</property>
 156.925 +				  <property name="use_underline">True</property>
 156.926 +				  <property name="active">False</property>
 156.927 +				</widget>
 156.928 +			      </child>
 156.929 +
 156.930 +			      <child>
 156.931 +				<widget class="GtkMenuItem" id="ShowSpeedMenu">
 156.932 +				  <property name="visible">True</property>
 156.933 +				  <property name="label" translatable="yes">Show speed</property>
 156.934 +				  <property name="use_underline">True</property>
 156.935 +
 156.936 +				  <child>
 156.937 +				    <widget class="GtkMenu" id="ShowSpeedMenu_menu">
 156.938 +
 156.939 +				      <child>
 156.940 +					<widget class="GtkRadioMenuItem" id="ShowSpeedNone">
 156.941 +					  <property name="visible">True</property>
 156.942 +					  <property name="label" translatable="yes">None</property>
 156.943 +					  <property name="use_underline">True</property>
 156.944 +					  <property name="active">True</property>
 156.945 +					</widget>
 156.946 +				      </child>
 156.947 +
 156.948 +				      <child>
 156.949 +					<widget class="GtkRadioMenuItem" id="ShowSpeedPercentage">
 156.950 +					  <property name="visible">True</property>
 156.951 +					  <property name="label" translatable="yes">Percentage</property>
 156.952 +					  <property name="use_underline">True</property>
 156.953 +					  <property name="active">False</property>
 156.954 +					  <property name="group">ShowSpeedNone</property>
 156.955 +					</widget>
 156.956 +				      </child>
 156.957 +
 156.958 +				      <child>
 156.959 +					<widget class="GtkRadioMenuItem" id="ShowSpeedDetailed">
 156.960 +					  <property name="visible">True</property>
 156.961 +					  <property name="label" translatable="yes">Detailed</property>
 156.962 +					  <property name="use_underline">True</property>
 156.963 +					  <property name="active">False</property>
 156.964 +					  <property name="group">ShowSpeedNone</property>
 156.965 +					</widget>
 156.966 +				      </child>
 156.967 +				    </widget>
 156.968 +				  </child>
 156.969 +				</widget>
 156.970 +			      </child>
 156.971 +
 156.972 +			      <child>
 156.973 +				<widget class="GtkMenuItem" id="SaveTypeMenu">
 156.974 +				  <property name="visible">True</property>
 156.975 +				  <property name="label" translatable="yes">Save type</property>
 156.976 +				  <property name="use_underline">True</property>
 156.977 +
 156.978 +				  <child>
 156.979 +				    <widget class="GtkMenu" id="SaveTypeMenu_menu">
 156.980 +
 156.981 +				      <child>
 156.982 +					<widget class="GtkRadioMenuItem" id="SaveTypeAutomatic">
 156.983 +					  <property name="visible">True</property>
 156.984 +					  <property name="label" translatable="yes">_Automatic</property>
 156.985 +					  <property name="use_underline">True</property>
 156.986 +					  <property name="active">True</property>
 156.987 +					</widget>
 156.988 +				      </child>
 156.989 +
 156.990 +				      <child>
 156.991 +					<widget class="GtkRadioMenuItem" id="SaveTypeEeprom">
 156.992 +					  <property name="visible">True</property>
 156.993 +					  <property name="label" translatable="yes">EEPROM</property>
 156.994 +					  <property name="use_underline">True</property>
 156.995 +					  <property name="active">False</property>
 156.996 +					  <property name="group">SaveTypeAutomatic</property>
 156.997 +					</widget>
 156.998 +				      </child>
 156.999 +
156.1000 +				      <child>
156.1001 +					<widget class="GtkRadioMenuItem" id="SaveTypeSram">
156.1002 +					  <property name="visible">True</property>
156.1003 +					  <property name="label" translatable="yes">SRAM</property>
156.1004 +					  <property name="use_underline">True</property>
156.1005 +					  <property name="active">False</property>
156.1006 +					  <property name="group">SaveTypeAutomatic</property>
156.1007 +					</widget>
156.1008 +				      </child>
156.1009 +
156.1010 +				      <child>
156.1011 +					<widget class="GtkRadioMenuItem" id="SaveTypeFlash">
156.1012 +					  <property name="visible">True</property>
156.1013 +					  <property name="label" translatable="yes">Flash</property>
156.1014 +					  <property name="use_underline">True</property>
156.1015 +					  <property name="active">False</property>
156.1016 +					  <property name="group">SaveTypeAutomatic</property>
156.1017 +					</widget>
156.1018 +				      </child>
156.1019 +
156.1020 +				      <child>
156.1021 +					<widget class="GtkRadioMenuItem" id="SaveTypeEepromSensor">
156.1022 +					  <property name="visible">True</property>
156.1023 +					  <property name="label" translatable="yes">EEPROM+Sensor</property>
156.1024 +					  <property name="use_underline">True</property>
156.1025 +					  <property name="active">False</property>
156.1026 +					  <property name="group">SaveTypeAutomatic</property>
156.1027 +					</widget>
156.1028 +				      </child>
156.1029 +
156.1030 +				      <child>
156.1031 +					<widget class="GtkRadioMenuItem" id="SaveTypeNone">
156.1032 +					  <property name="visible">True</property>
156.1033 +					  <property name="label" translatable="yes">None</property>
156.1034 +					  <property name="use_underline">True</property>
156.1035 +					  <property name="active">False</property>
156.1036 +					  <property name="group">SaveTypeAutomatic</property>
156.1037 +					</widget>
156.1038 +				      </child>
156.1039 +
156.1040 +				      <child>
156.1041 +					<widget class="GtkSeparatorMenuItem" id="separator10">
156.1042 +					  <property name="visible">True</property>
156.1043 +					</widget>
156.1044 +				      </child>
156.1045 +
156.1046 +				      <child>
156.1047 +					<widget class="GtkRadioMenuItem" id="SaveTypeFlash64K">
156.1048 +					  <property name="visible">True</property>
156.1049 +					  <property name="label" translatable="yes">Flash 64K</property>
156.1050 +					  <property name="use_underline">True</property>
156.1051 +					  <property name="active">True</property>
156.1052 +					</widget>
156.1053 +				      </child>
156.1054 +
156.1055 +				      <child>
156.1056 +					<widget class="GtkRadioMenuItem" id="SaveTypeFlash128K">
156.1057 +					  <property name="visible">True</property>
156.1058 +					  <property name="label" translatable="yes">Flash 128K</property>
156.1059 +					  <property name="use_underline">True</property>
156.1060 +					  <property name="active">False</property>
156.1061 +					  <property name="group">SaveTypeFlash64K</property>
156.1062 +					</widget>
156.1063 +				      </child>
156.1064 +				    </widget>
156.1065 +				  </child>
156.1066 +				</widget>
156.1067 +			      </child>
156.1068 +
156.1069 +			      <child>
156.1070 +				<widget class="GtkSeparatorMenuItem" id="separator31">
156.1071 +				  <property name="visible">True</property>
156.1072 +				</widget>
156.1073 +			      </child>
156.1074 +
156.1075 +			      <child>
156.1076 +				<widget class="GtkMenuItem" id="EmulatorSelectBios">
156.1077 +				  <property name="visible">True</property>
156.1078 +				  <property name="label" translatable="yes">_Select BIOS file...</property>
156.1079 +				  <property name="use_underline">True</property>
156.1080 +				</widget>
156.1081 +			      </child>
156.1082 +
156.1083 +			      <child>
156.1084 +				<widget class="GtkCheckMenuItem" id="EmulatorUseBios">
156.1085 +				  <property name="visible">True</property>
156.1086 +				  <property name="label" translatable="yes">_Use BIOS file</property>
156.1087 +				  <property name="use_underline">True</property>
156.1088 +				  <property name="active">False</property>
156.1089 +				</widget>
156.1090 +			      </child>
156.1091 +
156.1092 +			      <child>
156.1093 +				<widget class="GtkSeparatorMenuItem" id="separator30">
156.1094 +				  <property name="visible">True</property>
156.1095 +				</widget>
156.1096 +			      </child>
156.1097 +
156.1098 +			      <child>
156.1099 +				<widget class="GtkMenuItem" id="ScreenshotFormatMenu">
156.1100 +				  <property name="visible">True</property>
156.1101 +				  <property name="label" translatable="yes">Screenshot format</property>
156.1102 +				  <property name="use_underline">True</property>
156.1103 +
156.1104 +				  <child>
156.1105 +				    <widget class="GtkMenu" id="ScreenshotFormatMenu_menu">
156.1106 +
156.1107 +				      <child>
156.1108 +					<widget class="GtkRadioMenuItem" id="ScreenshotFormatPNG">
156.1109 +					  <property name="visible">True</property>
156.1110 +					  <property name="label" translatable="yes">_PNG</property>
156.1111 +					  <property name="use_underline">True</property>
156.1112 +					  <property name="active">True</property>
156.1113 +					</widget>
156.1114 +				      </child>
156.1115 +
156.1116 +				      <child>
156.1117 +					<widget class="GtkRadioMenuItem" id="ScreenshotFormatBMP">
156.1118 +					  <property name="visible">True</property>
156.1119 +					  <property name="label" translatable="yes">_BMP</property>
156.1120 +					  <property name="use_underline">True</property>
156.1121 +					  <property name="active">False</property>
156.1122 +					  <property name="group">ScreenshotFormatPNG</property>
156.1123 +					</widget>
156.1124 +				      </child>
156.1125 +				    </widget>
156.1126 +				  </child>
156.1127 +				</widget>
156.1128 +			      </child>
156.1129 +			    </widget>
156.1130 +			  </child>
156.1131 +			</widget>
156.1132 +		      </child>
156.1133 +
156.1134 +		      <child>
156.1135 +			<widget class="GtkMenuItem" id="SoundMenu">
156.1136 +			  <property name="visible">True</property>
156.1137 +			  <property name="label" translatable="yes">_Sound</property>
156.1138 +			  <property name="use_underline">True</property>
156.1139 +
156.1140 +			  <child>
156.1141 +			    <widget class="GtkMenu" id="SoundMenu_menu">
156.1142 +
156.1143 +			      <child>
156.1144 +				<widget class="GtkRadioMenuItem" id="SoundOff">
156.1145 +				  <property name="visible">True</property>
156.1146 +				  <property name="label" translatable="yes">O_ff</property>
156.1147 +				  <property name="use_underline">True</property>
156.1148 +				  <property name="active">True</property>
156.1149 +				</widget>
156.1150 +			      </child>
156.1151 +
156.1152 +			      <child>
156.1153 +				<widget class="GtkRadioMenuItem" id="SoundMute">
156.1154 +				  <property name="visible">True</property>
156.1155 +				  <property name="label" translatable="yes">_Mute</property>
156.1156 +				  <property name="use_underline">True</property>
156.1157 +				  <property name="active">False</property>
156.1158 +				  <property name="group">SoundOff</property>
156.1159 +				</widget>
156.1160 +			      </child>
156.1161 +
156.1162 +			      <child>
156.1163 +				<widget class="GtkRadioMenuItem" id="SoundOn">
156.1164 +				  <property name="visible">True</property>
156.1165 +				  <property name="label" translatable="yes">_On</property>
156.1166 +				  <property name="use_underline">True</property>
156.1167 +				  <property name="active">False</property>
156.1168 +				  <property name="group">SoundOff</property>
156.1169 +				</widget>
156.1170 +			      </child>
156.1171 +
156.1172 +			      <child>
156.1173 +				<widget class="GtkSeparatorMenuItem" id="separator11">
156.1174 +				  <property name="visible">True</property>
156.1175 +				</widget>
156.1176 +			      </child>
156.1177 +
156.1178 +			      <child>
156.1179 +				<widget class="GtkCheckMenuItem" id="SoundEcho">
156.1180 +				  <property name="visible">True</property>
156.1181 +				  <property name="label" translatable="yes">Echo</property>
156.1182 +				  <property name="use_underline">True</property>
156.1183 +				  <property name="active">False</property>
156.1184 +				</widget>
156.1185 +			      </child>
156.1186 +
156.1187 +			      <child>
156.1188 +				<widget class="GtkCheckMenuItem" id="SoundLowPass">
156.1189 +				  <property name="visible">True</property>
156.1190 +				  <property name="label" translatable="yes">Low pass filter</property>
156.1191 +				  <property name="use_underline">True</property>
156.1192 +				  <property name="active">False</property>
156.1193 +				</widget>
156.1194 +			      </child>
156.1195 +
156.1196 +			      <child>
156.1197 +				<widget class="GtkCheckMenuItem" id="SoundReverseStereo">
156.1198 +				  <property name="visible">True</property>
156.1199 +				  <property name="label" translatable="yes">Reverse stereo</property>
156.1200 +				  <property name="use_underline">True</property>
156.1201 +				  <property name="active">False</property>
156.1202 +				</widget>
156.1203 +			      </child>
156.1204 +
156.1205 +			      <child>
156.1206 +				<widget class="GtkSeparatorMenuItem" id="separator13">
156.1207 +				  <property name="visible">True</property>
156.1208 +				</widget>
156.1209 +			      </child>
156.1210 +
156.1211 +			      <child>
156.1212 +				<widget class="GtkCheckMenuItem" id="SoundChannel1">
156.1213 +				  <property name="visible">True</property>
156.1214 +				  <property name="label" translatable="yes">Channel _1</property>
156.1215 +				  <property name="use_underline">True</property>
156.1216 +				  <property name="active">False</property>
156.1217 +				</widget>
156.1218 +			      </child>
156.1219 +
156.1220 +			      <child>
156.1221 +				<widget class="GtkCheckMenuItem" id="SoundChannel2">
156.1222 +				  <property name="visible">True</property>
156.1223 +				  <property name="label" translatable="yes">Channel _2</property>
156.1224 +				  <property name="use_underline">True</property>
156.1225 +				  <property name="active">False</property>
156.1226 +				</widget>
156.1227 +			      </child>
156.1228 +
156.1229 +			      <child>
156.1230 +				<widget class="GtkCheckMenuItem" id="SoundChannel3">
156.1231 +				  <property name="visible">True</property>
156.1232 +				  <property name="label" translatable="yes">Channel _3</property>
156.1233 +				  <property name="use_underline">True</property>
156.1234 +				  <property name="active">False</property>
156.1235 +				</widget>
156.1236 +			      </child>
156.1237 +
156.1238 +			      <child>
156.1239 +				<widget class="GtkCheckMenuItem" id="SoundChannel4">
156.1240 +				  <property name="visible">True</property>
156.1241 +				  <property name="label" translatable="yes">Channel _4</property>
156.1242 +				  <property name="use_underline">True</property>
156.1243 +				  <property name="active">False</property>
156.1244 +				</widget>
156.1245 +			      </child>
156.1246 +
156.1247 +			      <child>
156.1248 +				<widget class="GtkCheckMenuItem" id="SoundChannelA">
156.1249 +				  <property name="visible">True</property>
156.1250 +				  <property name="label" translatable="yes">Channel _A</property>
156.1251 +				  <property name="use_underline">True</property>
156.1252 +				  <property name="active">False</property>
156.1253 +				</widget>
156.1254 +			      </child>
156.1255 +
156.1256 +			      <child>
156.1257 +				<widget class="GtkCheckMenuItem" id="SoundChannelB">
156.1258 +				  <property name="visible">True</property>
156.1259 +				  <property name="label" translatable="yes">Channel _B</property>
156.1260 +				  <property name="use_underline">True</property>
156.1261 +				  <property name="active">False</property>
156.1262 +				</widget>
156.1263 +			      </child>
156.1264 +
156.1265 +			      <child>
156.1266 +				<widget class="GtkSeparatorMenuItem" id="separator14">
156.1267 +				  <property name="visible">True</property>
156.1268 +				</widget>
156.1269 +			      </child>
156.1270 +
156.1271 +			      <child>
156.1272 +				<widget class="GtkRadioMenuItem" id="Sound11Khz">
156.1273 +				  <property name="visible">True</property>
156.1274 +				  <property name="label" translatable="yes">11 _Khz</property>
156.1275 +				  <property name="use_underline">True</property>
156.1276 +				  <property name="active">True</property>
156.1277 +				</widget>
156.1278 +			      </child>
156.1279 +
156.1280 +			      <child>
156.1281 +				<widget class="GtkRadioMenuItem" id="Sound22Khz">
156.1282 +				  <property name="visible">True</property>
156.1283 +				  <property name="label" translatable="yes">22 K_hz</property>
156.1284 +				  <property name="use_underline">True</property>
156.1285 +				  <property name="active">False</property>
156.1286 +				  <property name="group">Sound11Khz</property>
156.1287 +				</widget>
156.1288 +			      </child>
156.1289 +
156.1290 +			      <child>
156.1291 +				<widget class="GtkRadioMenuItem" id="Sound44Khz">
156.1292 +				  <property name="visible">True</property>
156.1293 +				  <property name="label" translatable="yes">44 Kh_z</property>
156.1294 +				  <property name="use_underline">True</property>
156.1295 +				  <property name="active">False</property>
156.1296 +				  <property name="group">Sound11Khz</property>
156.1297 +				</widget>
156.1298 +			      </child>
156.1299 +
156.1300 +			      <child>
156.1301 +				<widget class="GtkSeparatorMenuItem" id="separator15">
156.1302 +				  <property name="visible">True</property>
156.1303 +				</widget>
156.1304 +			      </child>
156.1305 +
156.1306 +			      <child>
156.1307 +				<widget class="GtkMenuItem" id="VolumeMenu">
156.1308 +				  <property name="visible">True</property>
156.1309 +				  <property name="label" translatable="yes">_Volume</property>
156.1310 +				  <property name="use_underline">True</property>
156.1311 +
156.1312 +				  <child>
156.1313 +				    <widget class="GtkMenu" id="VolumeMenu_menu">
156.1314 +
156.1315 +				      <child>
156.1316 +					<widget class="GtkRadioMenuItem" id="Volume25">
156.1317 +					  <property name="visible">True</property>
156.1318 +					  <property name="label" translatable="yes">25%</property>
156.1319 +					  <property name="use_underline">True</property>
156.1320 +					  <property name="active">True</property>
156.1321 +					</widget>
156.1322 +				      </child>
156.1323 +
156.1324 +				      <child>
156.1325 +					<widget class="GtkRadioMenuItem" id="Volume50">
156.1326 +					  <property name="visible">True</property>
156.1327 +					  <property name="label" translatable="yes">50%</property>
156.1328 +					  <property name="use_underline">True</property>
156.1329 +					  <property name="active">False</property>
156.1330 +					  <property name="group">Volume25</property>
156.1331 +					</widget>
156.1332 +				      </child>
156.1333 +
156.1334 +				      <child>
156.1335 +					<widget class="GtkRadioMenuItem" id="Volume100">
156.1336 +					  <property name="visible">True</property>
156.1337 +					  <property name="label" translatable="yes">100%</property>
156.1338 +					  <property name="use_underline">True</property>
156.1339 +					  <property name="active">False</property>
156.1340 +					  <property name="group">Volume25</property>
156.1341 +					</widget>
156.1342 +				      </child>
156.1343 +
156.1344 +				      <child>
156.1345 +					<widget class="GtkRadioMenuItem" id="Volume200">
156.1346 +					  <property name="visible">True</property>
156.1347 +					  <property name="label" translatable="yes">200%</property>
156.1348 +					  <property name="use_underline">True</property>
156.1349 +					  <property name="active">False</property>
156.1350 +					  <property name="group">Volume25</property>
156.1351 +					</widget>
156.1352 +				      </child>
156.1353 +
156.1354 +				      <child>
156.1355 +					<widget class="GtkRadioMenuItem" id="Volume300">
156.1356 +					  <property name="visible">True</property>
156.1357 +					  <property name="label" translatable="yes">300%</property>
156.1358 +					  <property name="use_underline">True</property>
156.1359 +					  <property name="active">False</property>
156.1360 +					  <property name="group">Volume25</property>
156.1361 +					</widget>
156.1362 +				      </child>
156.1363 +
156.1364 +				      <child>
156.1365 +					<widget class="GtkRadioMenuItem" id="Volume400">
156.1366 +					  <property name="visible">True</property>
156.1367 +					  <property name="label" translatable="yes">400%</property>
156.1368 +					  <property name="use_underline">True</property>
156.1369 +					  <property name="active">False</property>
156.1370 +					  <property name="group">Volume25</property>
156.1371 +					</widget>
156.1372 +				      </child>
156.1373 +				    </widget>
156.1374 +				  </child>
156.1375 +				</widget>
156.1376 +			      </child>
156.1377 +			    </widget>
156.1378 +			  </child>
156.1379 +			</widget>
156.1380 +		      </child>
156.1381 +
156.1382 +		      <child>
156.1383 +			<widget class="GtkMenuItem" id="GameboyMenu">
156.1384 +			  <property name="visible">True</property>
156.1385 +			  <property name="label" translatable="yes">_Gameboy</property>
156.1386 +			  <property name="use_underline">True</property>
156.1387 +
156.1388 +			  <child>
156.1389 +			    <widget class="GtkMenu" id="GameboyMenu_menu">
156.1390 +
156.1391 +			      <child>
156.1392 +				<widget class="GtkCheckMenuItem" id="GameboyBorder">
156.1393 +				  <property name="visible">True</property>
156.1394 +				  <property name="label" translatable="yes">_Border</property>
156.1395 +				  <property name="use_underline">True</property>
156.1396 +				  <property name="active">False</property>
156.1397 +				</widget>
156.1398 +			      </child>
156.1399 +
156.1400 +			      <child>
156.1401 +				<widget class="GtkCheckMenuItem" id="GameboyPrinter">
156.1402 +				  <property name="visible">True</property>
156.1403 +				  <property name="label" translatable="yes">_Printer</property>
156.1404 +				  <property name="use_underline">True</property>
156.1405 +				  <property name="active">False</property>
156.1406 +				</widget>
156.1407 +			      </child>
156.1408 +
156.1409 +			      <child>
156.1410 +				<widget class="GtkSeparatorMenuItem" id="separator16">
156.1411 +				  <property name="visible">True</property>
156.1412 +				</widget>
156.1413 +			      </child>
156.1414 +
156.1415 +			      <child>
156.1416 +				<widget class="GtkRadioMenuItem" id="GameboyAutomatic">
156.1417 +				  <property name="visible">True</property>
156.1418 +				  <property name="label" translatable="yes">_Automatic</property>
156.1419 +				  <property name="use_underline">True</property>
156.1420 +				  <property name="active">True</property>
156.1421 +				</widget>
156.1422 +			      </child>
156.1423 +
156.1424 +			      <child>
156.1425 +				<widget class="GtkRadioMenuItem" id="GameboyGba">
156.1426 +				  <property name="visible">True</property>
156.1427 +				  <property name="label" translatable="yes">_GBA</property>
156.1428 +				  <property name="use_underline">True</property>
156.1429 +				  <property name="active">False</property>
156.1430 +				  <property name="group">GameboyAutomatic</property>
156.1431 +				</widget>
156.1432 +			      </child>
156.1433 +
156.1434 +			      <child>
156.1435 +				<widget class="GtkRadioMenuItem" id="GameboyCgb">
156.1436 +				  <property name="visible">True</property>
156.1437 +				  <property name="label" translatable="yes">_CGB/GBC</property>
156.1438 +				  <property name="use_underline">True</property>
156.1439 +				  <property name="active">False</property>
156.1440 +				  <property name="group">GameboyAutomatic</property>
156.1441 +				</widget>
156.1442 +			      </child>
156.1443 +
156.1444 +			      <child>
156.1445 +				<widget class="GtkRadioMenuItem" id="GameboySgb">
156.1446 +				  <property name="visible">True</property>
156.1447 +				  <property name="label" translatable="yes">_SGB</property>
156.1448 +				  <property name="use_underline">True</property>
156.1449 +				  <property name="active">False</property>
156.1450 +				  <property name="group">GameboyAutomatic</property>
156.1451 +				</widget>
156.1452 +			      </child>
156.1453 +
156.1454 +			      <child>
156.1455 +				<widget class="GtkRadioMenuItem" id="GameboySgb2">
156.1456 +				  <property name="visible">True</property>
156.1457 +				  <property name="label" translatable="yes">SGB_2</property>
156.1458 +				  <property name="use_underline">True</property>
156.1459 +				  <property name="active">False</property>
156.1460 +				  <property name="group">GameboyAutomatic</property>
156.1461 +				</widget>
156.1462 +			      </child>
156.1463 +
156.1464 +			      <child>
156.1465 +				<widget class="GtkRadioMenuItem" id="GameboyGb">
156.1466 +				  <property name="visible">True</property>
156.1467 +				  <property name="label" translatable="yes">G_B</property>
156.1468 +				  <property name="use_underline">True</property>
156.1469 +				  <property name="active">False</property>
156.1470 +				  <property name="group">GameboyAutomatic</property>
156.1471 +				</widget>
156.1472 +			      </child>
156.1473 +			    </widget>
156.1474 +			  </child>
156.1475 +			</widget>
156.1476 +		      </child>
156.1477 +
156.1478 +		      <child>
156.1479 +			<widget class="GtkMenuItem" id="FilterMenu">
156.1480 +			  <property name="visible">True</property>
156.1481 +			  <property name="label" translatable="yes">F_ilter</property>
156.1482 +			  <property name="use_underline">True</property>
156.1483 +
156.1484 +			  <child>
156.1485 +			    <widget class="GtkMenu" id="FilterMenu_menu">
156.1486 +
156.1487 +			      <child>
156.1488 +				<widget class="GtkMenuItem" id="InterframeBlendingMenu">
156.1489 +				  <property name="visible">True</property>
156.1490 +				  <property name="label" translatable="yes">Interframe _blending</property>
156.1491 +				  <property name="use_underline">True</property>
156.1492 +
156.1493 +				  <child>
156.1494 +				    <widget class="GtkMenu" id="InterframeBlendingMenu_menu">
156.1495 +
156.1496 +				      <child>
156.1497 +					<widget class="GtkRadioMenuItem" id="IFBNone">
156.1498 +					  <property name="visible">True</property>
156.1499 +					  <property name="label" translatable="yes">_None</property>
156.1500 +					  <property name="use_underline">True</property>
156.1501 +					  <property name="active">True</property>
156.1502 +					</widget>
156.1503 +				      </child>
156.1504 +
156.1505 +				      <child>
156.1506 +					<widget class="GtkRadioMenuItem" id="IFBSmart">
156.1507 +					  <property name="visible">True</property>
156.1508 +					  <property name="label" translatable="yes">_Smart</property>
156.1509 +					  <property name="use_underline">True</property>
156.1510 +					  <property name="active">False</property>
156.1511 +					  <property name="group">IFBNone</property>
156.1512 +					</widget>
156.1513 +				      </child>
156.1514 +
156.1515 +				      <child>
156.1516 +					<widget class="GtkRadioMenuItem" id="IFBMotionBlur">
156.1517 +					  <property name="visible">True</property>
156.1518 +					  <property name="label" translatable="yes">_Motion Blur</property>
156.1519 +					  <property name="use_underline">True</property>
156.1520 +					  <property name="active">False</property>
156.1521 +					  <property name="group">IFBNone</property>
156.1522 +					</widget>
156.1523 +				      </child>
156.1524 +				    </widget>
156.1525 +				  </child>
156.1526 +				</widget>
156.1527 +			      </child>
156.1528 +
156.1529 +			      <child>
156.1530 +				<widget class="GtkSeparatorMenuItem" id="separator20">
156.1531 +				  <property name="visible">True</property>
156.1532 +				</widget>
156.1533 +			      </child>
156.1534 +
156.1535 +			      <child>
156.1536 +				<widget class="GtkRadioMenuItem" id="FilterNone">
156.1537 +				  <property name="visible">True</property>
156.1538 +				  <property name="label" translatable="yes">_None</property>
156.1539 +				  <property name="use_underline">True</property>
156.1540 +				  <property name="active">True</property>
156.1541 +				</widget>
156.1542 +			      </child>
156.1543 +
156.1544 +			      <child>
156.1545 +				<widget class="GtkRadioMenuItem" id="FilterTVMode">
156.1546 +				  <property name="visible">True</property>
156.1547 +				  <property name="label" translatable="yes">_TV Mode</property>
156.1548 +				  <property name="use_underline">True</property>
156.1549 +				  <property name="active">False</property>
156.1550 +				  <property name="group">FilterNone</property>
156.1551 +				</widget>
156.1552 +			      </child>
156.1553 +
156.1554 +			      <child>
156.1555 +				<widget class="GtkRadioMenuItem" id="Filter2xSaI">
156.1556 +				  <property name="visible">True</property>
156.1557 +				  <property name="label" translatable="yes">_2xSaI</property>
156.1558 +				  <property name="use_underline">True</property>
156.1559 +				  <property name="active">False</property>
156.1560 +				  <property name="group">FilterNone</property>
156.1561 +				</widget>
156.1562 +			      </child>
156.1563 +
156.1564 +			      <child>
156.1565 +				<widget class="GtkRadioMenuItem" id="FilterSuper2xSaI">
156.1566 +				  <property name="visible">True</property>
156.1567 +				  <property name="label" translatable="yes">_Super 2xSaI</property>
156.1568 +				  <property name="use_underline">True</property>
156.1569 +				  <property name="active">False</property>
156.1570 +				  <property name="group">FilterNone</property>
156.1571 +				</widget>
156.1572 +			      </child>
156.1573 +
156.1574 +			      <child>
156.1575 +				<widget class="GtkRadioMenuItem" id="FilterSuperEagle">
156.1576 +				  <property name="visible">True</property>
156.1577 +				  <property name="label" translatable="yes">Super _Eagle</property>
156.1578 +				  <property name="use_underline">True</property>
156.1579 +				  <property name="active">False</property>
156.1580 +				  <property name="group">FilterNone</property>
156.1581 +				</widget>
156.1582 +			      </child>
156.1583 +
156.1584 +			      <child>
156.1585 +				<widget class="GtkRadioMenuItem" id="FilterPixelate">
156.1586 +				  <property name="visible">True</property>
156.1587 +				  <property name="label" translatable="yes">_Pixelate</property>
156.1588 +				  <property name="use_underline">True</property>
156.1589 +				  <property name="active">False</property>
156.1590 +				  <property name="group">FilterNone</property>
156.1591 +				</widget>
156.1592 +			      </child>
156.1593 +
156.1594 +			      <child>
156.1595 +				<widget class="GtkRadioMenuItem" id="FilterMotionBlur">
156.1596 +				  <property name="visible">True</property>
156.1597 +				  <property name="label" translatable="yes">_Motion Blur</property>
156.1598 +				  <property name="use_underline">True</property>
156.1599 +				  <property name="active">False</property>
156.1600 +				  <property name="group">FilterNone</property>
156.1601 +				</widget>
156.1602 +			      </child>
156.1603 +
156.1604 +			      <child>
156.1605 +				<widget class="GtkRadioMenuItem" id="FilterAdvanceMame2x">
156.1606 +				  <property name="visible">True</property>
156.1607 +				  <property name="label" translatable="yes">_AdvanceMAME 2x</property>
156.1608 +				  <property name="use_underline">True</property>
156.1609 +				  <property name="active">False</property>
156.1610 +				  <property name="group">FilterNone</property>
156.1611 +				</widget>
156.1612 +			      </child>
156.1613 +
156.1614 +			      <child>
156.1615 +				<widget class="GtkRadioMenuItem" id="FilterSimple2x">
156.1616 +				  <property name="visible">True</property>
156.1617 +				  <property name="label" translatable="yes">S_imple 2x</property>
156.1618 +				  <property name="use_underline">True</property>
156.1619 +				  <property name="active">False</property>
156.1620 +				  <property name="group">FilterNone</property>
156.1621 +				</widget>
156.1622 +			      </child>
156.1623 +
156.1624 +			      <child>
156.1625 +				<widget class="GtkRadioMenuItem" id="FilterBilinear">
156.1626 +				  <property name="visible">True</property>
156.1627 +				  <property name="label" translatable="yes">Bilinea_r</property>
156.1628 +				  <property name="use_underline">True</property>
156.1629 +				  <property name="active">False</property>
156.1630 +				  <property name="group">FilterNone</property>
156.1631 +				</widget>
156.1632 +			      </child>
156.1633 +
156.1634 +			      <child>
156.1635 +				<widget class="GtkRadioMenuItem" id="FilterBilinearPlus">
156.1636 +				  <property name="visible">True</property>
156.1637 +				  <property name="label" translatable="yes">Bilinear Pl_us</property>
156.1638 +				  <property name="use_underline">True</property>
156.1639 +				  <property name="active">False</property>
156.1640 +				  <property name="group">FilterNone</property>
156.1641 +				</widget>
156.1642 +			      </child>
156.1643 +
156.1644 +			      <child>
156.1645 +				<widget class="GtkRadioMenuItem" id="FilterScanlines">
156.1646 +				  <property name="visible">True</property>
156.1647 +				  <property name="label" translatable="yes">S_canlines</property>
156.1648 +				  <property name="use_underline">True</property>
156.1649 +				  <property name="active">False</property>
156.1650 +				  <property name="group">FilterNone</property>
156.1651 +				</widget>
156.1652 +			      </child>
156.1653 +
156.1654 +			      <child>
156.1655 +				<widget class="GtkRadioMenuItem" id="FilterHq2x">
156.1656 +				  <property name="visible">True</property>
156.1657 +				  <property name="label" translatable="yes">h_q2x</property>
156.1658 +				  <property name="use_underline">True</property>
156.1659 +				  <property name="active">False</property>
156.1660 +				  <property name="group">FilterNone</property>
156.1661 +				</widget>
156.1662 +			      </child>
156.1663 +
156.1664 +			      <child>
156.1665 +				<widget class="GtkRadioMenuItem" id="FilterLq2x">
156.1666 +				  <property name="visible">True</property>
156.1667 +				  <property name="label" translatable="yes">_lq2x</property>
156.1668 +				  <property name="use_underline">True</property>
156.1669 +				  <property name="active">False</property>
156.1670 +				  <property name="group">FilterNone</property>
156.1671 +				</widget>
156.1672 +			      </child>
156.1673 +
156.1674 +			      <child>
156.1675 +				<widget class="GtkSeparatorMenuItem" id="separator17">
156.1676 +				  <property name="visible">True</property>
156.1677 +				</widget>
156.1678 +			      </child>
156.1679 +
156.1680 +			      <child>
156.1681 +				<widget class="GtkCheckMenuItem" id="FilterDisableMmx">
156.1682 +				  <property name="visible">True</property>
156.1683 +				  <property name="label" translatable="yes">_Disable MMX</property>
156.1684 +				  <property name="use_underline">True</property>
156.1685 +				  <property name="active">False</property>
156.1686 +				</widget>
156.1687 +			      </child>
156.1688 +			    </widget>
156.1689 +			  </child>
156.1690 +			</widget>
156.1691 +		      </child>
156.1692 +
156.1693 +		      <child>
156.1694 +			<widget class="GtkMenuItem" id="JoypadMenu">
156.1695 +			  <property name="visible">True</property>
156.1696 +			  <property name="label" translatable="yes">_Joypad</property>
156.1697 +			  <property name="use_underline">True</property>
156.1698 +
156.1699 +			  <child>
156.1700 +			    <widget class="GtkMenu" id="JoypadMenu_menu">
156.1701 +
156.1702 +			      <child>
156.1703 +				<widget class="GtkMenuItem" id="JoypadConfigureMenu">
156.1704 +				  <property name="visible">True</property>
156.1705 +				  <property name="label" translatable="yes">_Configure</property>
156.1706 +				  <property name="use_underline">True</property>
156.1707 +
156.1708 +				  <child>
156.1709 +				    <widget class="GtkMenu" id="JoypadConfigureMenu_menu">
156.1710 +
156.1711 +				      <child>
156.1712 +					<widget class="GtkMenuItem" id="JoypadConfigure1">
156.1713 +					  <property name="visible">True</property>
156.1714 +					  <property name="label" translatable="yes">_1...</property>
156.1715 +					  <property name="use_underline">True</property>
156.1716 +					</widget>
156.1717 +				      </child>
156.1718 +
156.1719 +				      <child>
156.1720 +					<widget class="GtkMenuItem" id="JoypadConfigure2">
156.1721 +					  <property name="visible">True</property>
156.1722 +					  <property name="label" translatable="yes">_2...</property>
156.1723 +					  <property name="use_underline">True</property>
156.1724 +					</widget>
156.1725 +				      </child>
156.1726 +
156.1727 +				      <child>
156.1728 +					<widget class="GtkMenuItem" id="JoypadConfigure3">
156.1729 +					  <property name="visible">True</property>
156.1730 +					  <property name="label" translatable="yes">_3...</property>
156.1731 +					  <property name="use_underline">True</property>
156.1732 +					</widget>
156.1733 +				      </child>
156.1734 +
156.1735 +				      <child>
156.1736 +					<widget class="GtkMenuItem" id="JoypadConfigure4">
156.1737 +					  <property name="visible">True</property>
156.1738 +					  <property name="label" translatable="yes">_4...</property>
156.1739 +					  <property name="use_underline">True</property>
156.1740 +					</widget>
156.1741 +				      </child>
156.1742 +				    </widget>
156.1743 +				  </child>
156.1744 +				</widget>
156.1745 +			      </child>
156.1746 +
156.1747 +			      <child>
156.1748 +				<widget class="GtkSeparatorMenuItem" id="separator18">
156.1749 +				  <property name="visible">True</property>
156.1750 +				</widget>
156.1751 +			      </child>
156.1752 +
156.1753 +			      <child>
156.1754 +				<widget class="GtkRadioMenuItem" id="Joypad1">
156.1755 +				  <property name="visible">True</property>
156.1756 +				  <property name="label" translatable="yes">_1</property>
156.1757 +				  <property name="use_underline">True</property>
156.1758 +				  <property name="active">True</property>
156.1759 +				</widget>
156.1760 +			      </child>
156.1761 +
156.1762 +			      <child>
156.1763 +				<widget class="GtkRadioMenuItem" id="Joypad2">
156.1764 +				  <property name="visible">True</property>
156.1765 +				  <property name="label" translatable="yes">_2</property>
156.1766 +				  <property name="use_underline">True</property>
156.1767 +				  <property name="active">False</property>
156.1768 +				  <property name="group">Joypad1</property>
156.1769 +				</widget>
156.1770 +			      </child>
156.1771 +
156.1772 +			      <child>
156.1773 +				<widget class="GtkRadioMenuItem" id="Joypad3">
156.1774 +				  <property name="visible">True</property>
156.1775 +				  <property name="label" translatable="yes">_3</property>
156.1776 +				  <property name="use_underline">True</property>
156.1777 +				  <property name="active">False</property>
156.1778 +				  <property name="group">Joypad1</property>
156.1779 +				</widget>
156.1780 +			      </child>
156.1781 +
156.1782 +			      <child>
156.1783 +				<widget class="GtkRadioMenuItem" id="Joypad4">
156.1784 +				  <property name="visible">True</property>
156.1785 +				  <property name="label" translatable="yes">_4</property>
156.1786 +				  <property name="use_underline">True</property>
156.1787 +				  <property name="active">False</property>
156.1788 +				  <property name="group">Joypad1</property>
156.1789 +				</widget>
156.1790 +			      </child>
156.1791 +
156.1792 +			      <child>
156.1793 +				<widget class="GtkSeparatorMenuItem" id="separator24">
156.1794 +				  <property name="visible">True</property>
156.1795 +				</widget>
156.1796 +			      </child>
156.1797 +
156.1798 +			      <child>
156.1799 +				<widget class="GtkMenuItem" id="AutofireMenu">
156.1800 +				  <property name="visible">True</property>
156.1801 +				  <property name="label" translatable="yes">_Autofire</property>
156.1802 +				  <property name="use_underline">True</property>
156.1803 +
156.1804 +				  <child>
156.1805 +				    <widget class="GtkMenu" id="AutofireMenu_menu">
156.1806 +
156.1807 +				      <child>
156.1808 +					<widget class="GtkCheckMenuItem" id="AutofireA">
156.1809 +					  <property name="visible">True</property>
156.1810 +					  <property name="label" translatable="yes">_A</property>
156.1811 +					  <property name="use_underline">True</property>
156.1812 +					  <property name="active">False</property>
156.1813 +					  <accelerator key="1" modifiers="GDK_MOD1_MASK" signal="activate"/>
156.1814 +					</widget>
156.1815 +				      </child>
156.1816 +
156.1817 +				      <child>
156.1818 +					<widget class="GtkCheckMenuItem" id="AutofireB">
156.1819 +					  <property name="visible">True</property>
156.1820 +					  <property name="label" translatable="yes">_B</property>
156.1821 +					  <property name="use_underline">True</property>
156.1822 +					  <property name="active">False</property>
156.1823 +					  <accelerator key="2" modifiers="GDK_MOD1_MASK" signal="activate"/>
156.1824 +					</widget>
156.1825 +				      </child>
156.1826 +
156.1827 +				      <child>
156.1828 +					<widget class="GtkCheckMenuItem" id="AutofireL">
156.1829 +					  <property name="visible">True</property>
156.1830 +					  <property name="label" translatable="yes">_L</property>
156.1831 +					  <property name="use_underline">True</property>
156.1832 +					  <property name="active">False</property>
156.1833 +					  <accelerator key="3" modifiers="GDK_MOD1_MASK" signal="activate"/>
156.1834 +					</widget>
156.1835 +				      </child>
156.1836 +
156.1837 +				      <child>
156.1838 +					<widget class="GtkCheckMenuItem" id="AutofireR">
156.1839 +					  <property name="visible">True</property>
156.1840 +					  <property name="label" translatable="yes">_R</property>
156.1841 +					  <property name="use_underline">True</property>
156.1842 +					  <property name="active">False</property>
156.1843 +					  <accelerator key="4" modifiers="GDK_MOD1_MASK" signal="activate"/>
156.1844 +					</widget>
156.1845 +				      </child>
156.1846 +				    </widget>
156.1847 +				  </child>
156.1848 +				</widget>
156.1849 +			      </child>
156.1850 +			    </widget>
156.1851 +			  </child>
156.1852 +			</widget>
156.1853 +		      </child>
156.1854 +		    </widget>
156.1855 +		  </child>
156.1856 +		</widget>
156.1857 +	      </child>
156.1858 +
156.1859 +	      <child>
156.1860 +		<widget class="GtkMenuItem" id="ToolsMenu">
156.1861 +		  <property name="visible">True</property>
156.1862 +		  <property name="label" translatable="yes">_Tools</property>
156.1863 +		  <property name="use_underline">True</property>
156.1864 +
156.1865 +		  <child>
156.1866 +		    <widget class="GtkMenu" id="ToolsMenu_menu">
156.1867 +
156.1868 +		      <child>
156.1869 +			<widget class="GtkMenuItem" id="GdbMenu">
156.1870 +			  <property name="visible">True</property>
156.1871 +			  <property name="label" translatable="yes">_GDB</property>
156.1872 +			  <property name="use_underline">True</property>
156.1873 +
156.1874 +			  <child>
156.1875 +			    <widget class="GtkMenu" id="GdbMenu_menu">
156.1876 +
156.1877 +			      <child>
156.1878 +				<widget class="GtkMenuItem" id="GdbWait">
156.1879 +				  <property name="visible">True</property>
156.1880 +				  <property name="label" translatable="yes">_Wait connection...</property>
156.1881 +				  <property name="use_underline">True</property>
156.1882 +				</widget>
156.1883 +			      </child>
156.1884 +
156.1885 +			      <child>
156.1886 +				<widget class="GtkMenuItem" id="GdbLoadAndWait">
156.1887 +				  <property name="visible">True</property>
156.1888 +				  <property name="label" translatable="yes">_Load and wait...</property>
156.1889 +				  <property name="use_underline">True</property>
156.1890 +				</widget>
156.1891 +			      </child>
156.1892 +
156.1893 +			      <child>
156.1894 +				<widget class="GtkMenuItem" id="GdbBreak">
156.1895 +				  <property name="visible">True</property>
156.1896 +				  <property name="label" translatable="yes">_Break</property>
156.1897 +				  <property name="use_underline">True</property>
156.1898 +				</widget>
156.1899 +			      </child>
156.1900 +
156.1901 +			      <child>
156.1902 +				<widget class="GtkMenuItem" id="GdbDisconnect">
156.1903 +				  <property name="visible">True</property>
156.1904 +				  <property name="label" translatable="yes">_Disconnect</property>
156.1905 +				  <property name="use_underline">True</property>
156.1906 +				</widget>
156.1907 +			      </child>
156.1908 +			    </widget>
156.1909 +			  </child>
156.1910 +			</widget>
156.1911 +		      </child>
156.1912 +		    </widget>
156.1913 +		  </child>
156.1914 +		</widget>
156.1915 +	      </child>
156.1916 +
156.1917 +	      <child>
156.1918 +		<widget class="GtkMenuItem" id="HelpMenu">
156.1919 +		  <property name="visible">True</property>
156.1920 +		  <property name="label" translatable="yes">_Help</property>
156.1921 +		  <property name="use_underline">True</property>
156.1922 +
156.1923 +		  <child>
156.1924 +		    <widget class="GtkMenu" id="HelpMenu_menu">
156.1925 +
156.1926 +		      <child>
156.1927 +			<widget class="GtkMenuItem" id="HelpAbout">
156.1928 +			  <property name="visible">True</property>
156.1929 +			  <property name="label" translatable="yes">_About</property>
156.1930 +			  <property name="use_underline">True</property>
156.1931 +			</widget>
156.1932 +		      </child>
156.1933 +		    </widget>
156.1934 +		  </child>
156.1935 +		</widget>
156.1936 +	      </child>
156.1937 +	    </widget>
156.1938 +	  </child>
156.1939 +	</widget>
156.1940 +	<packing>
156.1941 +	  <property name="padding">0</property>
156.1942 +	  <property name="expand">False</property>
156.1943 +	  <property name="fill">True</property>
156.1944 +	</packing>
156.1945 +      </child>
156.1946 +
156.1947 +      <child>
156.1948 +	<widget class="GtkAlignment" id="ScreenContainer">
156.1949 +	  <property name="visible">True</property>
156.1950 +	  <property name="xalign">0.5</property>
156.1951 +	  <property name="yalign">0.5</property>
156.1952 +	  <property name="xscale">0</property>
156.1953 +	  <property name="yscale">0</property>
156.1954 +
156.1955 +	  <child>
156.1956 +	    <placeholder/>
156.1957 +	  </child>
156.1958 +	</widget>
156.1959 +	<packing>
156.1960 +	  <property name="padding">0</property>
156.1961 +	  <property name="expand">True</property>
156.1962 +	  <property name="fill">True</property>
156.1963 +	</packing>
156.1964 +      </child>
156.1965 +    </widget>
156.1966 +  </child>
156.1967 +</widget>
156.1968 +
156.1969 +<widget class="GtkDialog" id="AboutDialog">
156.1970 +  <property name="title" translatable="yes">About VBA</property>
156.1971 +  <property name="type">GTK_WINDOW_TOPLEVEL</property>
156.1972 +  <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
156.1973 +  <property name="modal">False</property>
156.1974 +  <property name="resizable">True</property>
156.1975 +  <property name="destroy_with_parent">True</property>
156.1976 +  <property name="skip_taskbar_hint">False</property>
156.1977 +  <property name="skip_pager_hint">False</property>
156.1978 +  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
156.1979 +  <property name="has_separator">True</property>
156.1980 +
156.1981 +  <child internal-child="vbox">
156.1982 +    <widget class="GtkVBox" id="dialog-vbox1">
156.1983 +      <property name="visible">True</property>
156.1984 +      <property name="homogeneous">False</property>
156.1985 +      <property name="spacing">0</property>
156.1986 +
156.1987 +      <child internal-child="action_area">
156.1988 +	<widget class="GtkHButtonBox" id="dialog-action_area1">
156.1989 +	  <property name="visible">True</property>
156.1990 +	  <property name="layout_style">GTK_BUTTONBOX_END</property>
156.1991 +
156.1992 +	  <child>
156.1993 +	    <widget class="GtkButton" id="closebutton1">
156.1994 +	      <property name="visible">True</property>
156.1995 +	      <property name="can_default">True</property>
156.1996 +	      <property name="can_focus">True</property>
156.1997 +	      <property name="label">gtk-close</property>
156.1998 +	      <property name="use_stock">True</property>
156.1999 +	      <property name="relief">GTK_RELIEF_NORMAL</property>
156.2000 +	      <property name="response_id">-7</property>
156.2001 +	    </widget>
156.2002 +	  </child>
156.2003 +	</widget>
156.2004 +	<packing>
156.2005 +	  <property name="padding">0</property>
156.2006 +	  <property name="expand">False</property>
156.2007 +	  <property name="fill">True</property>
156.2008 +	  <property name="pack_type">GTK_PACK_END</property>
156.2009 +	</packing>
156.2010 +      </child>
156.2011 +
156.2012 +      <child>
156.2013 +	<widget class="GtkAlignment" id="AboutIconContainer">
156.2014 +	  <property name="visible">True</property>
156.2015 +	  <property name="xalign">0.5</property>
156.2016 +	  <property name="yalign">0.5</property>
156.2017 +	  <property name="xscale">0</property>
156.2018 +	  <property name="yscale">0</property>
156.2019 +
156.2020 +	  <child>
156.2021 +	    <placeholder/>
156.2022 +	  </child>
156.2023 +	</widget>
156.2024 +	<packing>
156.2025 +	  <property name="padding">0</property>
156.2026 +	  <property name="expand">True</property>
156.2027 +	  <property name="fill">True</property>
156.2028 +	</packing>
156.2029 +      </child>
156.2030 +
156.2031 +      <child>
156.2032 +	<widget class="GtkLabel" id="VersionLabel">
156.2033 +	  <property name="visible">True</property>
156.2034 +	  <property name="can_focus">True</property>
156.2035 +	  <property name="label" translatable="yes"></property>
156.2036 +	  <property name="use_underline">False</property>
156.2037 +	  <property name="use_markup">True</property>
156.2038 +	  <property name="justify">GTK_JUSTIFY_CENTER</property>
156.2039 +	  <property name="wrap">False</property>
156.2040 +	  <property name="selectable">True</property>
156.2041 +	  <property name="xalign">0.5</property>
156.2042 +	  <property name="yalign">0.5</property>
156.2043 +	  <property name="xpad">5</property>
156.2044 +	  <property name="ypad">5</property>
156.2045 +	</widget>
156.2046 +	<packing>
156.2047 +	  <property name="padding">0</property>
156.2048 +	  <property name="expand">True</property>
156.2049 +	  <property name="fill">False</property>
156.2050 +	</packing>
156.2051 +      </child>
156.2052 +
156.2053 +      <child>
156.2054 +	<widget class="GtkLabel" id="label2">
156.2055 +	  <property name="visible">True</property>
156.2056 +	  <property name="can_focus">True</property>
156.2057 +	  <property name="label" translatable="yes">An emulator for Gameboy(TM) and GameboyAdvance(TM).</property>
156.2058 +	  <property name="use_underline">False</property>
156.2059 +	  <property name="use_markup">False</property>
156.2060 +	  <property name="justify">GTK_JUSTIFY_CENTER</property>
156.2061 +	  <property name="wrap">True</property>
156.2062 +	  <property name="selectable">True</property>
156.2063 +	  <property name="xalign">0.5</property>
156.2064 +	  <property name="yalign">0.5</property>
156.2065 +	  <property name="xpad">5</property>
156.2066 +	  <property name="ypad">5</property>
156.2067 +	</widget>
156.2068 +	<packing>
156.2069 +	  <property name="padding">0</property>
156.2070 +	  <property name="expand">True</property>
156.2071 +	  <property name="fill">False</property>
156.2072 +	</packing>
156.2073 +      </child>
156.2074 +
156.2075 +      <child>
156.2076 +	<widget class="GtkLabel" id="label24">
156.2077 +	  <property name="visible">True</property>
156.2078 +	  <property name="can_focus">True</property>
156.2079 +	  <property name="label" translatable="yes">&lt;i&gt;Special thanks to Yann Parmentier aka &quot;kohai&quot; for the icons.&lt;/i&gt;</property>
156.2080 +	  <property name="use_underline">False</property>
156.2081 +	  <property name="use_markup">True</property>
156.2082 +	  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.2083 +	  <property name="wrap">False</property>
156.2084 +	  <property name="selectable">True</property>
156.2085 +	  <property name="xalign">0.5</property>
156.2086 +	  <property name="yalign">0.5</property>
156.2087 +	  <property name="xpad">5</property>
156.2088 +	  <property name="ypad">5</property>
156.2089 +	</widget>
156.2090 +	<packing>
156.2091 +	  <property name="padding">0</property>
156.2092 +	  <property name="expand">True</property>
156.2093 +	  <property name="fill">False</property>
156.2094 +	</packing>
156.2095 +      </child>
156.2096 +
156.2097 +      <child>
156.2098 +	<widget class="GtkLabel" id="label3">
156.2099 +	  <property name="visible">True</property>
156.2100 +	  <property name="can_focus">True</property>
156.2101 +	  <property name="label" translatable="yes">&lt;small&gt;Copyright (C) 2004 Forgotten and the VBA development team&lt;/small&gt;</property>
156.2102 +	  <property name="use_underline">False</property>
156.2103 +	  <property name="use_markup">True</property>
156.2104 +	  <property name="justify">GTK_JUSTIFY_CENTER</property>
156.2105 +	  <property name="wrap">True</property>
156.2106 +	  <property name="selectable">True</property>
156.2107 +	  <property name="xalign">0.5</property>
156.2108 +	  <property name="yalign">0.5</property>
156.2109 +	  <property name="xpad">5</property>
156.2110 +	  <property name="ypad">5</property>
156.2111 +	</widget>
156.2112 +	<packing>
156.2113 +	  <property name="padding">0</property>
156.2114 +	  <property name="expand">True</property>
156.2115 +	  <property name="fill">False</property>
156.2116 +	</packing>
156.2117 +      </child>
156.2118 +    </widget>
156.2119 +  </child>
156.2120 +</widget>
156.2121 +
156.2122 +<widget class="GtkDialog" id="ThrottleDialog">
156.2123 +  <property name="title" translatable="yes">Throttle</property>
156.2124 +  <property name="type">GTK_WINDOW_TOPLEVEL</property>
156.2125 +  <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
156.2126 +  <property name="modal">False</property>
156.2127 +  <property name="resizable">True</property>
156.2128 +  <property name="destroy_with_parent">True</property>
156.2129 +  <property name="skip_taskbar_hint">False</property>
156.2130 +  <property name="skip_pager_hint">False</property>
156.2131 +  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
156.2132 +  <property name="has_separator">True</property>
156.2133 +
156.2134 +  <child internal-child="vbox">
156.2135 +    <widget class="GtkVBox" id="dialog-vbox2">
156.2136 +      <property name="visible">True</property>
156.2137 +      <property name="homogeneous">False</property>
156.2138 +      <property name="spacing">0</property>
156.2139 +
156.2140 +      <child internal-child="action_area">
156.2141 +	<widget class="GtkHButtonBox" id="dialog-action_area2">
156.2142 +	  <property name="visible">True</property>
156.2143 +	  <property name="layout_style">GTK_BUTTONBOX_END</property>
156.2144 +
156.2145 +	  <child>
156.2146 +	    <widget class="GtkButton" id="cancelbutton1">
156.2147 +	      <property name="visible">True</property>
156.2148 +	      <property name="can_default">True</property>
156.2149 +	      <property name="can_focus">True</property>
156.2150 +	      <property name="label">gtk-cancel</property>
156.2151 +	      <property name="use_stock">True</property>
156.2152 +	      <property name="relief">GTK_RELIEF_NORMAL</property>
156.2153 +	      <property name="response_id">-6</property>
156.2154 +	    </widget>
156.2155 +	  </child>
156.2156 +
156.2157 +	  <child>
156.2158 +	    <widget class="GtkButton" id="okbutton1">
156.2159 +	      <property name="visible">True</property>
156.2160 +	      <property name="can_default">True</property>
156.2161 +	      <property name="can_focus">True</property>
156.2162 +	      <property name="label">gtk-ok</property>
156.2163 +	      <property name="use_stock">True</property>
156.2164 +	      <property name="relief">GTK_RELIEF_NORMAL</property>
156.2165 +	      <property name="response_id">-5</property>
156.2166 +	    </widget>
156.2167 +	  </child>
156.2168 +	</widget>
156.2169 +	<packing>
156.2170 +	  <property name="padding">0</property>
156.2171 +	  <property name="expand">False</property>
156.2172 +	  <property name="fill">True</property>
156.2173 +	  <property name="pack_type">GTK_PACK_END</property>
156.2174 +	</packing>
156.2175 +      </child>
156.2176 +
156.2177 +      <child>
156.2178 +	<widget class="GtkAlignment" id="alignment4">
156.2179 +	  <property name="visible">True</property>
156.2180 +	  <property name="xalign">0.5</property>
156.2181 +	  <property name="yalign">0.5</property>
156.2182 +	  <property name="xscale">0</property>
156.2183 +	  <property name="yscale">0</property>
156.2184 +
156.2185 +	  <child>
156.2186 +	    <widget class="GtkHBox" id="hbox1">
156.2187 +	      <property name="visible">True</property>
156.2188 +	      <property name="homogeneous">False</property>
156.2189 +	      <property name="spacing">0</property>
156.2190 +
156.2191 +	      <child>
156.2192 +		<widget class="GtkLabel" id="label4">
156.2193 +		  <property name="visible">True</property>
156.2194 +		  <property name="label" translatable="yes">Throttle : </property>
156.2195 +		  <property name="use_underline">False</property>
156.2196 +		  <property name="use_markup">False</property>
156.2197 +		  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.2198 +		  <property name="wrap">False</property>
156.2199 +		  <property name="selectable">False</property>
156.2200 +		  <property name="xalign">1</property>
156.2201 +		  <property name="yalign">0.5</property>
156.2202 +		  <property name="xpad">0</property>
156.2203 +		  <property name="ypad">0</property>
156.2204 +		</widget>
156.2205 +		<packing>
156.2206 +		  <property name="padding">0</property>
156.2207 +		  <property name="expand">True</property>
156.2208 +		  <property name="fill">True</property>
156.2209 +		</packing>
156.2210 +	      </child>
156.2211 +
156.2212 +	      <child>
156.2213 +		<widget class="GtkSpinButton" id="ThrottleSpin">
156.2214 +		  <property name="visible">True</property>
156.2215 +		  <property name="can_focus">True</property>
156.2216 +		  <property name="climb_rate">1</property>
156.2217 +		  <property name="digits">0</property>
156.2218 +		  <property name="numeric">True</property>
156.2219 +		  <property name="update_policy">GTK_UPDATE_ALWAYS</property>
156.2220 +		  <property name="snap_to_ticks">True</property>
156.2221 +		  <property name="wrap">True</property>
156.2222 +		  <property name="adjustment">100 5 1000 1 25 25</property>
156.2223 +		</widget>
156.2224 +		<packing>
156.2225 +		  <property name="padding">0</property>
156.2226 +		  <property name="expand">True</property>
156.2227 +		  <property name="fill">True</property>
156.2228 +		</packing>
156.2229 +	      </child>
156.2230 +
156.2231 +	      <child>
156.2232 +		<widget class="GtkLabel" id="label5">
156.2233 +		  <property name="visible">True</property>
156.2234 +		  <property name="label" translatable="yes"> %</property>
156.2235 +		  <property name="use_underline">False</property>
156.2236 +		  <property name="use_markup">False</property>
156.2237 +		  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.2238 +		  <property name="wrap">False</property>
156.2239 +		  <property name="selectable">False</property>
156.2240 +		  <property name="xalign">0</property>
156.2241 +		  <property name="yalign">0.5</property>
156.2242 +		  <property name="xpad">0</property>
156.2243 +		  <property name="ypad">0</property>
156.2244 +		</widget>
156.2245 +		<packing>
156.2246 +		  <property name="padding">0</property>
156.2247 +		  <property name="expand">True</property>
156.2248 +		  <property name="fill">True</property>
156.2249 +		</packing>
156.2250 +	      </child>
156.2251 +	    </widget>
156.2252 +	  </child>
156.2253 +	</widget>
156.2254 +	<packing>
156.2255 +	  <property name="padding">0</property>
156.2256 +	  <property name="expand">True</property>
156.2257 +	  <property name="fill">True</property>
156.2258 +	</packing>
156.2259 +      </child>
156.2260 +    </widget>
156.2261 +  </child>
156.2262 +</widget>
156.2263 +
156.2264 +<widget class="GtkDialog" id="DirectoriesDialog">
156.2265 +  <property name="title" translatable="yes">Directories</property>
156.2266 +  <property name="type">GTK_WINDOW_TOPLEVEL</property>
156.2267 +  <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
156.2268 +  <property name="modal">False</property>
156.2269 +  <property name="resizable">True</property>
156.2270 +  <property name="destroy_with_parent">True</property>
156.2271 +  <property name="skip_taskbar_hint">False</property>
156.2272 +  <property name="skip_pager_hint">False</property>
156.2273 +  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
156.2274 +  <property name="has_separator">True</property>
156.2275 +
156.2276 +  <child internal-child="vbox">
156.2277 +    <widget class="GtkVBox" id="dialog-vbox3">
156.2278 +      <property name="visible">True</property>
156.2279 +      <property name="homogeneous">False</property>
156.2280 +      <property name="spacing">0</property>
156.2281 +
156.2282 +      <child internal-child="action_area">
156.2283 +	<widget class="GtkHButtonBox" id="dialog-action_area3">
156.2284 +	  <property name="visible">True</property>
156.2285 +	  <property name="layout_style">GTK_BUTTONBOX_END</property>
156.2286 +
156.2287 +	  <child>
156.2288 +	    <widget class="GtkButton" id="cancelbutton2">
156.2289 +	      <property name="visible">True</property>
156.2290 +	      <property name="can_default">True</property>
156.2291 +	      <property name="can_focus">True</property>
156.2292 +	      <property name="label">gtk-cancel</property>
156.2293 +	      <property name="use_stock">True</property>
156.2294 +	      <property name="relief">GTK_RELIEF_NORMAL</property>
156.2295 +	      <property name="response_id">-6</property>
156.2296 +	    </widget>
156.2297 +	  </child>
156.2298 +
156.2299 +	  <child>
156.2300 +	    <widget class="GtkButton" id="okbutton2">
156.2301 +	      <property name="visible">True</property>
156.2302 +	      <property name="can_default">True</property>
156.2303 +	      <property name="can_focus">True</property>
156.2304 +	      <property name="label">gtk-ok</property>
156.2305 +	      <property name="use_stock">True</property>
156.2306 +	      <property name="relief">GTK_RELIEF_NORMAL</property>
156.2307 +	      <property name="response_id">-5</property>
156.2308 +	    </widget>
156.2309 +	  </child>
156.2310 +	</widget>
156.2311 +	<packing>
156.2312 +	  <property name="padding">0</property>
156.2313 +	  <property name="expand">False</property>
156.2314 +	  <property name="fill">True</property>
156.2315 +	  <property name="pack_type">GTK_PACK_END</property>
156.2316 +	</packing>
156.2317 +      </child>
156.2318 +
156.2319 +      <child>
156.2320 +	<widget class="GtkTable" id="table1">
156.2321 +	  <property name="visible">True</property>
156.2322 +	  <property name="n_rows">5</property>
156.2323 +	  <property name="n_columns">4</property>
156.2324 +	  <property name="homogeneous">False</property>
156.2325 +	  <property name="row_spacing">0</property>
156.2326 +	  <property name="column_spacing">0</property>
156.2327 +
156.2328 +	  <child>
156.2329 +	    <widget class="GtkLabel" id="label6">
156.2330 +	      <property name="visible">True</property>
156.2331 +	      <property name="label" translatable="yes">GBA roms : </property>
156.2332 +	      <property name="use_underline">False</property>
156.2333 +	      <property name="use_markup">False</property>
156.2334 +	      <property name="justify">GTK_JUSTIFY_LEFT</property>
156.2335 +	      <property name="wrap">False</property>
156.2336 +	      <property name="selectable">False</property>
156.2337 +	      <property name="xalign">1</property>
156.2338 +	      <property name="yalign">0.5</property>
156.2339 +	      <property name="xpad">0</property>
156.2340 +	      <property name="ypad">0</property>
156.2341 +	    </widget>
156.2342 +	    <packing>
156.2343 +	      <property name="left_attach">0</property>
156.2344 +	      <property name="right_attach">1</property>
156.2345 +	      <property name="top_attach">0</property>
156.2346 +	      <property name="bottom_attach">1</property>
156.2347 +	      <property name="x_options">fill</property>
156.2348 +	      <property name="y_options">expand</property>
156.2349 +	    </packing>
156.2350 +	  </child>
156.2351 +
156.2352 +	  <child>
156.2353 +	    <widget class="GtkEntry" id="GBARomsDirEntry">
156.2354 +	      <property name="visible">True</property>
156.2355 +	      <property name="can_focus">True</property>
156.2356 +	      <property name="editable">True</property>
156.2357 +	      <property name="visibility">True</property>
156.2358 +	      <property name="max_length">0</property>
156.2359 +	      <property name="text" translatable="yes"></property>
156.2360 +	      <property name="has_frame">True</property>
156.2361 +	      <property name="invisible_char" translatable="yes">*</property>
156.2362 +	      <property name="activates_default">False</property>
156.2363 +	    </widget>
156.2364 +	    <packing>
156.2365 +	      <property name="left_attach">1</property>
156.2366 +	      <property name="right_attach">2</property>
156.2367 +	      <property name="top_attach">0</property>
156.2368 +	      <property name="bottom_attach">1</property>
156.2369 +	      <property name="y_options">expand</property>
156.2370 +	    </packing>
156.2371 +	  </child>
156.2372 +
156.2373 +	  <child>
156.2374 +	    <widget class="GtkButton" id="GBARomsDirResetButton">
156.2375 +	      <property name="visible">True</property>
156.2376 +	      <property name="can_focus">True</property>
156.2377 +	      <property name="relief">GTK_RELIEF_NONE</property>
156.2378 +
156.2379 +	      <child>
156.2380 +		<widget class="GtkImage" id="image83">
156.2381 +		  <property name="visible">True</property>
156.2382 +		  <property name="stock">gtk-cancel</property>
156.2383 +		  <property name="icon_size">4</property>
156.2384 +		  <property name="xalign">0.5</property>
156.2385 +		  <property name="yalign">0.5</property>
156.2386 +		  <property name="xpad">0</property>
156.2387 +		  <property name="ypad">0</property>
156.2388 +		</widget>
156.2389 +	      </child>
156.2390 +	    </widget>
156.2391 +	    <packing>
156.2392 +	      <property name="left_attach">2</property>
156.2393 +	      <property name="right_attach">3</property>
156.2394 +	      <property name="top_attach">0</property>
156.2395 +	      <property name="bottom_attach">1</property>
156.2396 +	      <property name="x_options">fill</property>
156.2397 +	      <property name="y_options">expand</property>
156.2398 +	    </packing>
156.2399 +	  </child>
156.2400 +
156.2401 +	  <child>
156.2402 +	    <widget class="GtkButton" id="GBARomsDirSelectButton">
156.2403 +	      <property name="visible">True</property>
156.2404 +	      <property name="can_focus">True</property>
156.2405 +	      <property name="relief">GTK_RELIEF_NONE</property>
156.2406 +
156.2407 +	      <child>
156.2408 +		<widget class="GtkImage" id="image84">
156.2409 +		  <property name="visible">True</property>
156.2410 +		  <property name="stock">gtk-open</property>
156.2411 +		  <property name="icon_size">4</property>
156.2412 +		  <property name="xalign">0.5</property>
156.2413 +		  <property name="yalign">0.5</property>
156.2414 +		  <property name="xpad">0</property>
156.2415 +		  <property name="ypad">0</property>
156.2416 +		</widget>
156.2417 +	      </child>
156.2418 +	    </widget>
156.2419 +	    <packing>
156.2420 +	      <property name="left_attach">3</property>
156.2421 +	      <property name="right_attach">4</property>
156.2422 +	      <property name="top_attach">0</property>
156.2423 +	      <property name="bottom_attach">1</property>
156.2424 +	      <property name="x_options">fill</property>
156.2425 +	      <property name="y_options">expand</property>
156.2426 +	    </packing>
156.2427 +	  </child>
156.2428 +
156.2429 +	  <child>
156.2430 +	    <widget class="GtkLabel" id="label7">
156.2431 +	      <property name="visible">True</property>
156.2432 +	      <property name="label" translatable="yes">GB roms : </property>
156.2433 +	      <property name="use_underline">False</property>
156.2434 +	      <property name="use_markup">False</property>
156.2435 +	      <property name="justify">GTK_JUSTIFY_LEFT</property>
156.2436 +	      <property name="wrap">False</property>
156.2437 +	      <property name="selectable">False</property>
156.2438 +	      <property name="xalign">1</property>
156.2439 +	      <property name="yalign">0.5</property>
156.2440 +	      <property name="xpad">0</property>
156.2441 +	      <property name="ypad">0</property>
156.2442 +	    </widget>
156.2443 +	    <packing>
156.2444 +	      <property name="left_attach">0</property>
156.2445 +	      <property name="right_attach">1</property>
156.2446 +	      <property name="top_attach">1</property>
156.2447 +	      <property name="bottom_attach">2</property>
156.2448 +	      <property name="x_options">fill</property>
156.2449 +	      <property name="y_options">expand</property>
156.2450 +	    </packing>
156.2451 +	  </child>
156.2452 +
156.2453 +	  <child>
156.2454 +	    <widget class="GtkButton" id="GBRomsDirSelectButton">
156.2455 +	      <property name="visible">True</property>
156.2456 +	      <property name="can_focus">True</property>
156.2457 +	      <property name="relief">GTK_RELIEF_NONE</property>
156.2458 +
156.2459 +	      <child>
156.2460 +		<widget class="GtkImage" id="image94">
156.2461 +		  <property name="visible">True</property>
156.2462 +		  <property name="stock">gtk-open</property>
156.2463 +		  <property name="icon_size">4</property>
156.2464 +		  <property name="xalign">0.5</property>
156.2465 +		  <property name="yalign">0.5</property>
156.2466 +		  <property name="xpad">0</property>
156.2467 +		  <property name="ypad">0</property>
156.2468 +		</widget>
156.2469 +	      </child>
156.2470 +	    </widget>
156.2471 +	    <packing>
156.2472 +	      <property name="left_attach">3</property>
156.2473 +	      <property name="right_attach">4</property>
156.2474 +	      <property name="top_attach">1</property>
156.2475 +	      <property name="bottom_attach">2</property>
156.2476 +	      <property name="x_options">fill</property>
156.2477 +	      <property name="y_options">expand</property>
156.2478 +	    </packing>
156.2479 +	  </child>
156.2480 +
156.2481 +	  <child>
156.2482 +	    <widget class="GtkLabel" id="label8">
156.2483 +	      <property name="visible">True</property>
156.2484 +	      <property name="label" translatable="yes">Batteries : </property>
156.2485 +	      <property name="use_underline">False</property>
156.2486 +	      <property name="use_markup">False</property>
156.2487 +	      <property name="justify">GTK_JUSTIFY_LEFT</property>
156.2488 +	      <property name="wrap">False</property>
156.2489 +	      <property name="selectable">False</property>
156.2490 +	      <property name="xalign">1</property>
156.2491 +	      <property name="yalign">0.5</property>
156.2492 +	      <property name="xpad">0</property>
156.2493 +	      <property name="ypad">0</property>
156.2494 +	    </widget>
156.2495 +	    <packing>
156.2496 +	      <property name="left_attach">0</property>
156.2497 +	      <property name="right_attach">1</property>
156.2498 +	      <property name="top_attach">2</property>
156.2499 +	      <property name="bottom_attach">3</property>
156.2500 +	      <property name="x_options">fill</property>
156.2501 +	      <property name="y_options">expand</property>
156.2502 +	    </packing>
156.2503 +	  </child>
156.2504 +
156.2505 +	  <child>
156.2506 +	    <widget class="GtkEntry" id="BatteriesDirEntry">
156.2507 +	      <property name="visible">True</property>
156.2508 +	      <property name="can_focus">True</property>
156.2509 +	      <property name="editable">True</property>
156.2510 +	      <property name="visibility">True</property>
156.2511 +	      <property name="max_length">0</property>
156.2512 +	      <property name="text" translatable="yes"></property>
156.2513 +	      <property name="has_frame">True</property>
156.2514 +	      <property name="invisible_char" translatable="yes">*</property>
156.2515 +	      <property name="activates_default">False</property>
156.2516 +	    </widget>
156.2517 +	    <packing>
156.2518 +	      <property name="left_attach">1</property>
156.2519 +	      <property name="right_attach">2</property>
156.2520 +	      <property name="top_attach">2</property>
156.2521 +	      <property name="bottom_attach">3</property>
156.2522 +	      <property name="y_options">expand</property>
156.2523 +	    </packing>
156.2524 +	  </child>
156.2525 +
156.2526 +	  <child>
156.2527 +	    <widget class="GtkButton" id="BatteriesDirSelectButton">
156.2528 +	      <property name="visible">True</property>
156.2529 +	      <property name="can_focus">True</property>
156.2530 +	      <property name="relief">GTK_RELIEF_NONE</property>
156.2531 +
156.2532 +	      <child>
156.2533 +		<widget class="GtkImage" id="image98">
156.2534 +		  <property name="visible">True</property>
156.2535 +		  <property name="stock">gtk-open</property>
156.2536 +		  <property name="icon_size">4</property>
156.2537 +		  <property name="xalign">0.5</property>
156.2538 +		  <property name="yalign">0.5</property>
156.2539 +		  <property name="xpad">0</property>
156.2540 +		  <property name="ypad">0</property>
156.2541 +		</widget>
156.2542 +	      </child>
156.2543 +	    </widget>
156.2544 +	    <packing>
156.2545 +	      <property name="left_attach">3</property>
156.2546 +	      <property name="right_attach">4</property>
156.2547 +	      <property name="top_attach">2</property>
156.2548 +	      <property name="bottom_attach">3</property>
156.2549 +	      <property name="x_options">fill</property>
156.2550 +	      <property name="y_options">expand</property>
156.2551 +	    </packing>
156.2552 +	  </child>
156.2553 +
156.2554 +	  <child>
156.2555 +	    <widget class="GtkButton" id="BatteriesDirResetButton">
156.2556 +	      <property name="visible">True</property>
156.2557 +	      <property name="can_focus">True</property>
156.2558 +	      <property name="relief">GTK_RELIEF_NONE</property>
156.2559 +
156.2560 +	      <child>
156.2561 +		<widget class="GtkImage" id="image95">
156.2562 +		  <property name="visible">True</property>
156.2563 +		  <property name="stock">gtk-cancel</property>
156.2564 +		  <property name="icon_size">4</property>
156.2565 +		  <property name="xalign">0.5</property>
156.2566 +		  <property name="yalign">0.5</property>
156.2567 +		  <property name="xpad">0</property>
156.2568 +		  <property name="ypad">0</property>
156.2569 +		</widget>
156.2570 +	      </child>
156.2571 +	    </widget>
156.2572 +	    <packing>
156.2573 +	      <property name="left_attach">2</property>
156.2574 +	      <property name="right_attach">3</property>
156.2575 +	      <property name="top_attach">2</property>
156.2576 +	      <property name="bottom_attach">3</property>
156.2577 +	      <property name="x_options">fill</property>
156.2578 +	      <property name="y_options">expand</property>
156.2579 +	    </packing>
156.2580 +	  </child>
156.2581 +
156.2582 +	  <child>
156.2583 +	    <widget class="GtkLabel" id="label9">
156.2584 +	      <property name="visible">True</property>
156.2585 +	      <property name="label" translatable="yes">Saves : </property>
156.2586 +	      <property name="use_underline">False</property>
156.2587 +	      <property name="use_markup">False</property>
156.2588 +	      <property name="justify">GTK_JUSTIFY_LEFT</property>
156.2589 +	      <property name="wrap">False</property>
156.2590 +	      <property name="selectable">False</property>
156.2591 +	      <property name="xalign">1</property>
156.2592 +	      <property name="yalign">0.5</property>
156.2593 +	      <property name="xpad">0</property>
156.2594 +	      <property name="ypad">0</property>
156.2595 +	    </widget>
156.2596 +	    <packing>
156.2597 +	      <property name="left_attach">0</property>
156.2598 +	      <property name="right_attach">1</property>
156.2599 +	      <property name="top_attach">3</property>
156.2600 +	      <property name="bottom_attach">4</property>
156.2601 +	      <property name="x_options">fill</property>
156.2602 +	      <property name="y_options">expand</property>
156.2603 +	    </packing>
156.2604 +	  </child>
156.2605 +
156.2606 +	  <child>
156.2607 +	    <widget class="GtkEntry" id="SavesDirEntry">
156.2608 +	      <property name="visible">True</property>
156.2609 +	      <property name="can_focus">True</property>
156.2610 +	      <property name="editable">True</property>
156.2611 +	      <property name="visibility">True</property>
156.2612 +	      <property name="max_length">0</property>
156.2613 +	      <property name="text" translatable="yes"></property>
156.2614 +	      <property name="has_frame">True</property>
156.2615 +	      <property name="invisible_char" translatable="yes">*</property>
156.2616 +	      <property name="activates_default">False</property>
156.2617 +	    </widget>
156.2618 +	    <packing>
156.2619 +	      <property name="left_attach">1</property>
156.2620 +	      <property name="right_attach">2</property>
156.2621 +	      <property name="top_attach">3</property>
156.2622 +	      <property name="bottom_attach">4</property>
156.2623 +	      <property name="y_options">expand</property>
156.2624 +	    </packing>
156.2625 +	  </child>
156.2626 +
156.2627 +	  <child>
156.2628 +	    <widget class="GtkButton" id="SavesDirResetButton">
156.2629 +	      <property name="visible">True</property>
156.2630 +	      <property name="can_focus">True</property>
156.2631 +	      <property name="relief">GTK_RELIEF_NONE</property>
156.2632 +
156.2633 +	      <child>
156.2634 +		<widget class="GtkImage" id="image96">
156.2635 +		  <property name="visible">True</property>
156.2636 +		  <property name="stock">gtk-cancel</property>
156.2637 +		  <property name="icon_size">4</property>
156.2638 +		  <property name="xalign">0.5</property>
156.2639 +		  <property name="yalign">0.5</property>
156.2640 +		  <property name="xpad">0</property>
156.2641 +		  <property name="ypad">0</property>
156.2642 +		</widget>
156.2643 +	      </child>
156.2644 +	    </widget>
156.2645 +	    <packing>
156.2646 +	      <property name="left_attach">2</property>
156.2647 +	      <property name="right_attach">3</property>
156.2648 +	      <property name="top_attach">3</property>
156.2649 +	      <property name="bottom_attach">4</property>
156.2650 +	      <property name="x_options">fill</property>
156.2651 +	      <property name="y_options">expand</property>
156.2652 +	    </packing>
156.2653 +	  </child>
156.2654 +
156.2655 +	  <child>
156.2656 +	    <widget class="GtkButton" id="SavesDirSelectButton">
156.2657 +	      <property name="visible">True</property>
156.2658 +	      <property name="can_focus">True</property>
156.2659 +	      <property name="relief">GTK_RELIEF_NONE</property>
156.2660 +
156.2661 +	      <child>
156.2662 +		<widget class="GtkImage" id="image99">
156.2663 +		  <property name="visible">True</property>
156.2664 +		  <property name="stock">gtk-open</property>
156.2665 +		  <property name="icon_size">4</property>
156.2666 +		  <property name="xalign">0.5</property>
156.2667 +		  <property name="yalign">0.5</property>
156.2668 +		  <property name="xpad">0</property>
156.2669 +		  <property name="ypad">0</property>
156.2670 +		</widget>
156.2671 +	      </child>
156.2672 +	    </widget>
156.2673 +	    <packing>
156.2674 +	      <property name="left_attach">3</property>
156.2675 +	      <property name="right_attach">4</property>
156.2676 +	      <property name="top_attach">3</property>
156.2677 +	      <property name="bottom_attach">4</property>
156.2678 +	      <property name="x_options">fill</property>
156.2679 +	      <property name="y_options">expand</property>
156.2680 +	    </packing>
156.2681 +	  </child>
156.2682 +
156.2683 +	  <child>
156.2684 +	    <widget class="GtkLabel" id="label10">
156.2685 +	      <property name="visible">True</property>
156.2686 +	      <property name="label" translatable="yes">Captures : </property>
156.2687 +	      <property name="use_underline">False</property>
156.2688 +	      <property name="use_markup">False</property>
156.2689 +	      <property name="justify">GTK_JUSTIFY_LEFT</property>
156.2690 +	      <property name="wrap">False</property>
156.2691 +	      <property name="selectable">False</property>
156.2692 +	      <property name="xalign">1</property>
156.2693 +	      <property name="yalign">0.5</property>
156.2694 +	      <property name="xpad">0</property>
156.2695 +	      <property name="ypad">0</property>
156.2696 +	    </widget>
156.2697 +	    <packing>
156.2698 +	      <property name="left_attach">0</property>
156.2699 +	      <property name="right_attach">1</property>
156.2700 +	      <property name="top_attach">4</property>
156.2701 +	      <property name="bottom_attach">5</property>
156.2702 +	      <property name="x_options">fill</property>
156.2703 +	      <property name="y_options">expand</property>
156.2704 +	    </packing>
156.2705 +	  </child>
156.2706 +
156.2707 +	  <child>
156.2708 +	    <widget class="GtkEntry" id="CapturesDirEntry">
156.2709 +	      <property name="visible">True</property>
156.2710 +	      <property name="can_focus">True</property>
156.2711 +	      <property name="editable">True</property>
156.2712 +	      <property name="visibility">True</property>
156.2713 +	      <property name="max_length">0</property>
156.2714 +	      <property name="text" translatable="yes"></property>
156.2715 +	      <property name="has_frame">True</property>
156.2716 +	      <property name="invisible_char" translatable="yes">*</property>
156.2717 +	      <property name="activates_default">False</property>
156.2718 +	    </widget>
156.2719 +	    <packing>
156.2720 +	      <property name="left_attach">1</property>
156.2721 +	      <property name="right_attach">2</property>
156.2722 +	      <property name="top_attach">4</property>
156.2723 +	      <property name="bottom_attach">5</property>
156.2724 +	      <property name="y_options">expand</property>
156.2725 +	    </packing>
156.2726 +	  </child>
156.2727 +
156.2728 +	  <child>
156.2729 +	    <widget class="GtkButton" id="CapturesDirResetButton">
156.2730 +	      <property name="visible">True</property>
156.2731 +	      <property name="can_focus">True</property>
156.2732 +	      <property name="relief">GTK_RELIEF_NONE</property>
156.2733 +
156.2734 +	      <child>
156.2735 +		<widget class="GtkImage" id="image97">
156.2736 +		  <property name="visible">True</property>
156.2737 +		  <property name="stock">gtk-cancel</property>
156.2738 +		  <property name="icon_size">4</property>
156.2739 +		  <property name="xalign">0.5</property>
156.2740 +		  <property name="yalign">0.5</property>
156.2741 +		  <property name="xpad">0</property>
156.2742 +		  <property name="ypad">0</property>
156.2743 +		</widget>
156.2744 +	      </child>
156.2745 +	    </widget>
156.2746 +	    <packing>
156.2747 +	      <property name="left_attach">2</property>
156.2748 +	      <property name="right_attach">3</property>
156.2749 +	      <property name="top_attach">4</property>
156.2750 +	      <property name="bottom_attach">5</property>
156.2751 +	      <property name="x_options">fill</property>
156.2752 +	      <property name="y_options">expand</property>
156.2753 +	    </packing>
156.2754 +	  </child>
156.2755 +
156.2756 +	  <child>
156.2757 +	    <widget class="GtkButton" id="CapturesDirSelectButton">
156.2758 +	      <property name="visible">True</property>
156.2759 +	      <property name="can_focus">True</property>
156.2760 +	      <property name="relief">GTK_RELIEF_NONE</property>
156.2761 +
156.2762 +	      <child>
156.2763 +		<widget class="GtkImage" id="image100">
156.2764 +		  <property name="visible">True</property>
156.2765 +		  <property name="stock">gtk-open</property>
156.2766 +		  <property name="icon_size">4</property>
156.2767 +		  <property name="xalign">0.5</property>
156.2768 +		  <property name="yalign">0.5</property>
156.2769 +		  <property name="xpad">0</property>
156.2770 +		  <property name="ypad">0</property>
156.2771 +		</widget>
156.2772 +	      </child>
156.2773 +	    </widget>
156.2774 +	    <packing>
156.2775 +	      <property name="left_attach">3</property>
156.2776 +	      <property name="right_attach">4</property>
156.2777 +	      <property name="top_attach">4</property>
156.2778 +	      <property name="bottom_attach">5</property>
156.2779 +	      <property name="x_options">fill</property>
156.2780 +	      <property name="y_options">expand</property>
156.2781 +	    </packing>
156.2782 +	  </child>
156.2783 +
156.2784 +	  <child>
156.2785 +	    <widget class="GtkEntry" id="GBRomsDirEntry">
156.2786 +	      <property name="visible">True</property>
156.2787 +	      <property name="can_focus">True</property>
156.2788 +	      <property name="editable">True</property>
156.2789 +	      <property name="visibility">True</property>
156.2790 +	      <property name="max_length">0</property>
156.2791 +	      <property name="text" translatable="yes"></property>
156.2792 +	      <property name="has_frame">True</property>
156.2793 +	      <property name="invisible_char" translatable="yes">*</property>
156.2794 +	      <property name="activates_default">False</property>
156.2795 +	    </widget>
156.2796 +	    <packing>
156.2797 +	      <property name="left_attach">1</property>
156.2798 +	      <property name="right_attach">2</property>
156.2799 +	      <property name="top_attach">1</property>
156.2800 +	      <property name="bottom_attach">2</property>
156.2801 +	      <property name="y_options">expand</property>
156.2802 +	    </packing>
156.2803 +	  </child>
156.2804 +
156.2805 +	  <child>
156.2806 +	    <widget class="GtkButton" id="GBRomsDirResetButton">
156.2807 +	      <property name="visible">True</property>
156.2808 +	      <property name="can_focus">True</property>
156.2809 +	      <property name="relief">GTK_RELIEF_NONE</property>
156.2810 +
156.2811 +	      <child>
156.2812 +		<widget class="GtkImage" id="image101">
156.2813 +		  <property name="visible">True</property>
156.2814 +		  <property name="stock">gtk-cancel</property>
156.2815 +		  <property name="icon_size">4</property>
156.2816 +		  <property name="xalign">0.5</property>
156.2817 +		  <property name="yalign">0.5</property>
156.2818 +		  <property name="xpad">0</property>
156.2819 +		  <property name="ypad">0</property>
156.2820 +		</widget>
156.2821 +	      </child>
156.2822 +	    </widget>
156.2823 +	    <packing>
156.2824 +	      <property name="left_attach">2</property>
156.2825 +	      <property name="right_attach">3</property>
156.2826 +	      <property name="top_attach">1</property>
156.2827 +	      <property name="bottom_attach">2</property>
156.2828 +	      <property name="x_options">fill</property>
156.2829 +	      <property name="y_options">expand</property>
156.2830 +	    </packing>
156.2831 +	  </child>
156.2832 +	</widget>
156.2833 +	<packing>
156.2834 +	  <property name="padding">0</property>
156.2835 +	  <property name="expand">True</property>
156.2836 +	  <property name="fill">True</property>
156.2837 +	</packing>
156.2838 +      </child>
156.2839 +    </widget>
156.2840 +  </child>
156.2841 +</widget>
156.2842 +
156.2843 +<widget class="GtkDialog" id="JoypadConfigDialog">
156.2844 +  <property name="title" translatable="yes">Joypad config</property>
156.2845 +  <property name="type">GTK_WINDOW_TOPLEVEL</property>
156.2846 +  <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
156.2847 +  <property name="modal">False</property>
156.2848 +  <property name="resizable">True</property>
156.2849 +  <property name="destroy_with_parent">True</property>
156.2850 +  <property name="skip_taskbar_hint">False</property>
156.2851 +  <property name="skip_pager_hint">False</property>
156.2852 +  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
156.2853 +  <property name="has_separator">True</property>
156.2854 +
156.2855 +  <child internal-child="vbox">
156.2856 +    <widget class="GtkVBox" id="dialog-vbox4">
156.2857 +      <property name="visible">True</property>
156.2858 +      <property name="homogeneous">False</property>
156.2859 +      <property name="spacing">0</property>
156.2860 +
156.2861 +      <child internal-child="action_area">
156.2862 +	<widget class="GtkHButtonBox" id="dialog-action_area4">
156.2863 +	  <property name="visible">True</property>
156.2864 +	  <property name="layout_style">GTK_BUTTONBOX_END</property>
156.2865 +
156.2866 +	  <child>
156.2867 +	    <widget class="GtkButton" id="cancelbutton3">
156.2868 +	      <property name="visible">True</property>
156.2869 +	      <property name="can_default">True</property>
156.2870 +	      <property name="can_focus">True</property>
156.2871 +	      <property name="label">gtk-cancel</property>
156.2872 +	      <property name="use_stock">True</property>
156.2873 +	      <property name="relief">GTK_RELIEF_NORMAL</property>
156.2874 +	      <property name="response_id">-6</property>
156.2875 +	    </widget>
156.2876 +	  </child>
156.2877 +
156.2878 +	  <child>
156.2879 +	    <widget class="GtkButton" id="JoypadOkButton">
156.2880 +	      <property name="visible">True</property>
156.2881 +	      <property name="can_default">True</property>
156.2882 +	      <property name="can_focus">True</property>
156.2883 +	      <property name="label">gtk-ok</property>
156.2884 +	      <property name="use_stock">True</property>
156.2885 +	      <property name="relief">GTK_RELIEF_NORMAL</property>
156.2886 +	      <property name="response_id">-5</property>
156.2887 +	    </widget>
156.2888 +	  </child>
156.2889 +	</widget>
156.2890 +	<packing>
156.2891 +	  <property name="padding">0</property>
156.2892 +	  <property name="expand">False</property>
156.2893 +	  <property name="fill">True</property>
156.2894 +	  <property name="pack_type">GTK_PACK_END</property>
156.2895 +	</packing>
156.2896 +      </child>
156.2897 +
156.2898 +      <child>
156.2899 +	<widget class="GtkAlignment" id="alignment1">
156.2900 +	  <property name="visible">True</property>
156.2901 +	  <property name="xalign">0.5</property>
156.2902 +	  <property name="yalign">0.5</property>
156.2903 +	  <property name="xscale">0</property>
156.2904 +	  <property name="yscale">1</property>
156.2905 +
156.2906 +	  <child>
156.2907 +	    <widget class="GtkTable" id="table2">
156.2908 +	      <property name="visible">True</property>
156.2909 +	      <property name="n_rows">12</property>
156.2910 +	      <property name="n_columns">2</property>
156.2911 +	      <property name="homogeneous">False</property>
156.2912 +	      <property name="row_spacing">5</property>
156.2913 +	      <property name="column_spacing">0</property>
156.2914 +
156.2915 +	      <child>
156.2916 +		<widget class="GtkEntry" id="JoypadUpEntry">
156.2917 +		  <property name="visible">True</property>
156.2918 +		  <property name="can_focus">True</property>
156.2919 +		  <property name="editable">False</property>
156.2920 +		  <property name="visibility">True</property>
156.2921 +		  <property name="max_length">0</property>
156.2922 +		  <property name="text" translatable="yes"></property>
156.2923 +		  <property name="has_frame">True</property>
156.2924 +		  <property name="invisible_char" translatable="yes">*</property>
156.2925 +		  <property name="activates_default">False</property>
156.2926 +		</widget>
156.2927 +		<packing>
156.2928 +		  <property name="left_attach">1</property>
156.2929 +		  <property name="right_attach">2</property>
156.2930 +		  <property name="top_attach">0</property>
156.2931 +		  <property name="bottom_attach">1</property>
156.2932 +		  <property name="x_options">fill</property>
156.2933 +		  <property name="y_options">expand</property>
156.2934 +		</packing>
156.2935 +	      </child>
156.2936 +
156.2937 +	      <child>
156.2938 +		<widget class="GtkLabel" id="label12">
156.2939 +		  <property name="visible">True</property>
156.2940 +		  <property name="label" translatable="yes">Down : </property>
156.2941 +		  <property name="use_underline">False</property>
156.2942 +		  <property name="use_markup">False</property>
156.2943 +		  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.2944 +		  <property name="wrap">False</property>
156.2945 +		  <property name="selectable">False</property>
156.2946 +		  <property name="xalign">1</property>
156.2947 +		  <property name="yalign">0.5</property>
156.2948 +		  <property name="xpad">0</property>
156.2949 +		  <property name="ypad">0</property>
156.2950 +		</widget>
156.2951 +		<packing>
156.2952 +		  <property name="left_attach">0</property>
156.2953 +		  <property name="right_attach">1</property>
156.2954 +		  <property name="top_attach">1</property>
156.2955 +		  <property name="bottom_attach">2</property>
156.2956 +		  <property name="x_options">fill</property>
156.2957 +		  <property name="y_options">expand</property>
156.2958 +		</packing>
156.2959 +	      </child>
156.2960 +
156.2961 +	      <child>
156.2962 +		<widget class="GtkLabel" id="label13">
156.2963 +		  <property name="visible">True</property>
156.2964 +		  <property name="label" translatable="yes">Left : </property>
156.2965 +		  <property name="use_underline">False</property>
156.2966 +		  <property name="use_markup">False</property>
156.2967 +		  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.2968 +		  <property name="wrap">False</property>
156.2969 +		  <property name="selectable">False</property>
156.2970 +		  <property name="xalign">1</property>
156.2971 +		  <property name="yalign">0.5</property>
156.2972 +		  <property name="xpad">0</property>
156.2973 +		  <property name="ypad">0</property>
156.2974 +		</widget>
156.2975 +		<packing>
156.2976 +		  <property name="left_attach">0</property>
156.2977 +		  <property name="right_attach">1</property>
156.2978 +		  <property name="top_attach">2</property>
156.2979 +		  <property name="bottom_attach">3</property>
156.2980 +		  <property name="x_options">fill</property>
156.2981 +		  <property name="y_options">expand</property>
156.2982 +		</packing>
156.2983 +	      </child>
156.2984 +
156.2985 +	      <child>
156.2986 +		<widget class="GtkLabel" id="label14">
156.2987 +		  <property name="visible">True</property>
156.2988 +		  <property name="label" translatable="yes">Right : </property>
156.2989 +		  <property name="use_underline">False</property>
156.2990 +		  <property name="use_markup">False</property>
156.2991 +		  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.2992 +		  <property name="wrap">False</property>
156.2993 +		  <property name="selectable">False</property>
156.2994 +		  <property name="xalign">1</property>
156.2995 +		  <property name="yalign">0.5</property>
156.2996 +		  <property name="xpad">0</property>
156.2997 +		  <property name="ypad">0</property>
156.2998 +		</widget>
156.2999 +		<packing>
156.3000 +		  <property name="left_attach">0</property>
156.3001 +		  <property name="right_attach">1</property>
156.3002 +		  <property name="top_attach">3</property>
156.3003 +		  <property name="bottom_attach">4</property>
156.3004 +		  <property name="x_options">fill</property>
156.3005 +		  <property name="y_options">expand</property>
156.3006 +		</packing>
156.3007 +	      </child>
156.3008 +
156.3009 +	      <child>
156.3010 +		<widget class="GtkLabel" id="label15">
156.3011 +		  <property name="visible">True</property>
156.3012 +		  <property name="label" translatable="yes">Button A : </property>
156.3013 +		  <property name="use_underline">False</property>
156.3014 +		  <property name="use_markup">False</property>
156.3015 +		  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.3016 +		  <property name="wrap">False</property>
156.3017 +		  <property name="selectable">False</property>
156.3018 +		  <property name="xalign">1</property>
156.3019 +		  <property name="yalign">0.5</property>
156.3020 +		  <property name="xpad">0</property>
156.3021 +		  <property name="ypad">0</property>
156.3022 +		</widget>
156.3023 +		<packing>
156.3024 +		  <property name="left_attach">0</property>
156.3025 +		  <property name="right_attach">1</property>
156.3026 +		  <property name="top_attach">4</property>
156.3027 +		  <property name="bottom_attach">5</property>
156.3028 +		  <property name="x_options">fill</property>
156.3029 +		  <property name="y_options">expand</property>
156.3030 +		</packing>
156.3031 +	      </child>
156.3032 +
156.3033 +	      <child>
156.3034 +		<widget class="GtkLabel" id="label16">
156.3035 +		  <property name="visible">True</property>
156.3036 +		  <property name="label" translatable="yes">Button B : </property>
156.3037 +		  <property name="use_underline">False</property>
156.3038 +		  <property name="use_markup">False</property>
156.3039 +		  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.3040 +		  <property name="wrap">False</property>
156.3041 +		  <property name="selectable">False</property>
156.3042 +		  <property name="xalign">1</property>
156.3043 +		  <property name="yalign">0.5</property>
156.3044 +		  <property name="xpad">0</property>
156.3045 +		  <property name="ypad">0</property>
156.3046 +		</widget>
156.3047 +		<packing>
156.3048 +		  <property name="left_attach">0</property>
156.3049 +		  <property name="right_attach">1</property>
156.3050 +		  <property name="top_attach">5</property>
156.3051 +		  <property name="bottom_attach">6</property>
156.3052 +		  <property name="x_options">fill</property>
156.3053 +		  <property name="y_options">expand</property>
156.3054 +		</packing>
156.3055 +	      </child>
156.3056 +
156.3057 +	      <child>
156.3058 +		<widget class="GtkLabel" id="label17">
156.3059 +		  <property name="visible">True</property>
156.3060 +		  <property name="label" translatable="yes">Button L : </property>
156.3061 +		  <property name="use_underline">False</property>
156.3062 +		  <property name="use_markup">False</property>
156.3063 +		  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.3064 +		  <property name="wrap">False</property>
156.3065 +		  <property name="selectable">False</property>
156.3066 +		  <property name="xalign">1</property>
156.3067 +		  <property name="yalign">0.5</property>
156.3068 +		  <property name="xpad">0</property>
156.3069 +		  <property name="ypad">0</property>
156.3070 +		</widget>
156.3071 +		<packing>
156.3072 +		  <property name="left_attach">0</property>
156.3073 +		  <property name="right_attach">1</property>
156.3074 +		  <property name="top_attach">6</property>
156.3075 +		  <property name="bottom_attach">7</property>
156.3076 +		  <property name="x_options">fill</property>
156.3077 +		  <property name="y_options">expand</property>
156.3078 +		</packing>
156.3079 +	      </child>
156.3080 +
156.3081 +	      <child>
156.3082 +		<widget class="GtkLabel" id="label18">
156.3083 +		  <property name="visible">True</property>
156.3084 +		  <property name="label" translatable="yes">Button R : </property>
156.3085 +		  <property name="use_underline">False</property>
156.3086 +		  <property name="use_markup">False</property>
156.3087 +		  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.3088 +		  <property name="wrap">False</property>
156.3089 +		  <property name="selectable">False</property>
156.3090 +		  <property name="xalign">1</property>
156.3091 +		  <property name="yalign">0.5</property>
156.3092 +		  <property name="xpad">0</property>
156.3093 +		  <property name="ypad">0</property>
156.3094 +		</widget>
156.3095 +		<packing>
156.3096 +		  <property name="left_attach">0</property>
156.3097 +		  <property name="right_attach">1</property>
156.3098 +		  <property name="top_attach">7</property>
156.3099 +		  <property name="bottom_attach">8</property>
156.3100 +		  <property name="x_options">fill</property>
156.3101 +		  <property name="y_options">expand</property>
156.3102 +		</packing>
156.3103 +	      </child>
156.3104 +
156.3105 +	      <child>
156.3106 +		<widget class="GtkLabel" id="label19">
156.3107 +		  <property name="visible">True</property>
156.3108 +		  <property name="label" translatable="yes">Select : </property>
156.3109 +		  <property name="use_underline">False</property>
156.3110 +		  <property name="use_markup">False</property>
156.3111 +		  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.3112 +		  <property name="wrap">False</property>
156.3113 +		  <property name="selectable">False</property>
156.3114 +		  <property name="xalign">1</property>
156.3115 +		  <property name="yalign">0.5</property>
156.3116 +		  <property name="xpad">0</property>
156.3117 +		  <property name="ypad">0</property>
156.3118 +		</widget>
156.3119 +		<packing>
156.3120 +		  <property name="left_attach">0</property>
156.3121 +		  <property name="right_attach">1</property>
156.3122 +		  <property name="top_attach">8</property>
156.3123 +		  <property name="bottom_attach">9</property>
156.3124 +		  <property name="x_options">fill</property>
156.3125 +		  <property name="y_options">expand</property>
156.3126 +		</packing>
156.3127 +	      </child>
156.3128 +
156.3129 +	      <child>
156.3130 +		<widget class="GtkLabel" id="label20">
156.3131 +		  <property name="visible">True</property>
156.3132 +		  <property name="label" translatable="yes">Start : </property>
156.3133 +		  <property name="use_underline">False</property>
156.3134 +		  <property name="use_markup">False</property>
156.3135 +		  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.3136 +		  <property name="wrap">False</property>
156.3137 +		  <property name="selectable">False</property>
156.3138 +		  <property name="xalign">1</property>
156.3139 +		  <property name="yalign">0.5</property>
156.3140 +		  <property name="xpad">0</property>
156.3141 +		  <property name="ypad">0</property>
156.3142 +		</widget>
156.3143 +		<packing>
156.3144 +		  <property name="left_attach">0</property>
156.3145 +		  <property name="right_attach">1</property>
156.3146 +		  <property name="top_attach">9</property>
156.3147 +		  <property name="bottom_attach">10</property>
156.3148 +		  <property name="x_options">fill</property>
156.3149 +		  <property name="y_options">expand</property>
156.3150 +		</packing>
156.3151 +	      </child>
156.3152 +
156.3153 +	      <child>
156.3154 +		<widget class="GtkLabel" id="label21">
156.3155 +		  <property name="visible">True</property>
156.3156 +		  <property name="label" translatable="yes">Speed : </property>
156.3157 +		  <property name="use_underline">False</property>
156.3158 +		  <property name="use_markup">False</property>
156.3159 +		  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.3160 +		  <property name="wrap">False</property>
156.3161 +		  <property name="selectable">False</property>
156.3162 +		  <property name="xalign">1</property>
156.3163 +		  <property name="yalign">0.5</property>
156.3164 +		  <property name="xpad">0</property>
156.3165 +		  <property name="ypad">0</property>
156.3166 +		</widget>
156.3167 +		<packing>
156.3168 +		  <property name="left_attach">0</property>
156.3169 +		  <property name="right_attach">1</property>
156.3170 +		  <property name="top_attach">10</property>
156.3171 +		  <property name="bottom_attach">11</property>
156.3172 +		  <property name="x_options">fill</property>
156.3173 +		  <property name="y_options">expand</property>
156.3174 +		</packing>
156.3175 +	      </child>
156.3176 +
156.3177 +	      <child>
156.3178 +		<widget class="GtkLabel" id="label22">
156.3179 +		  <property name="visible">True</property>
156.3180 +		  <property name="label" translatable="yes">Capture : </property>
156.3181 +		  <property name="use_underline">False</property>
156.3182 +		  <property name="use_markup">False</property>
156.3183 +		  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.3184 +		  <property name="wrap">False</property>
156.3185 +		  <property name="selectable">False</property>
156.3186 +		  <property name="xalign">1</property>
156.3187 +		  <property name="yalign">0.5</property>
156.3188 +		  <property name="xpad">0</property>
156.3189 +		  <property name="ypad">0</property>
156.3190 +		</widget>
156.3191 +		<packing>
156.3192 +		  <property name="left_attach">0</property>
156.3193 +		  <property name="right_attach">1</property>
156.3194 +		  <property name="top_attach">11</property>
156.3195 +		  <property name="bottom_attach">12</property>
156.3196 +		  <property name="x_options">fill</property>
156.3197 +		  <property name="y_options">expand</property>
156.3198 +		</packing>
156.3199 +	      </child>
156.3200 +
156.3201 +	      <child>
156.3202 +		<widget class="GtkEntry" id="JoypadDownEntry">
156.3203 +		  <property name="visible">True</property>
156.3204 +		  <property name="can_focus">True</property>
156.3205 +		  <property name="editable">False</property>
156.3206 +		  <property name="visibility">True</property>
156.3207 +		  <property name="max_length">0</property>
156.3208 +		  <property name="text" translatable="yes"></property>
156.3209 +		  <property name="has_frame">True</property>
156.3210 +		  <property name="invisible_char" translatable="yes">*</property>
156.3211 +		  <property name="activates_default">False</property>
156.3212 +		</widget>
156.3213 +		<packing>
156.3214 +		  <property name="left_attach">1</property>
156.3215 +		  <property name="right_attach">2</property>
156.3216 +		  <property name="top_attach">1</property>
156.3217 +		  <property name="bottom_attach">2</property>
156.3218 +		  <property name="x_options">fill</property>
156.3219 +		  <property name="y_options">expand</property>
156.3220 +		</packing>
156.3221 +	      </child>
156.3222 +
156.3223 +	      <child>
156.3224 +		<widget class="GtkEntry" id="JoypadLeftEntry">
156.3225 +		  <property name="visible">True</property>
156.3226 +		  <property name="can_focus">True</property>
156.3227 +		  <property name="editable">False</property>
156.3228 +		  <property name="visibility">True</property>
156.3229 +		  <property name="max_length">0</property>
156.3230 +		  <property name="text" translatable="yes"></property>
156.3231 +		  <property name="has_frame">True</property>
156.3232 +		  <property name="invisible_char" translatable="yes">*</property>
156.3233 +		  <property name="activates_default">False</property>
156.3234 +		</widget>
156.3235 +		<packing>
156.3236 +		  <property name="left_attach">1</property>
156.3237 +		  <property name="right_attach">2</property>
156.3238 +		  <property name="top_attach">2</property>
156.3239 +		  <property name="bottom_attach">3</property>
156.3240 +		  <property name="x_options">fill</property>
156.3241 +		  <property name="y_options">expand</property>
156.3242 +		</packing>
156.3243 +	      </child>
156.3244 +
156.3245 +	      <child>
156.3246 +		<widget class="GtkEntry" id="JoypadRightEntry">
156.3247 +		  <property name="visible">True</property>
156.3248 +		  <property name="can_focus">True</property>
156.3249 +		  <property name="editable">False</property>
156.3250 +		  <property name="visibility">True</property>
156.3251 +		  <property name="max_length">0</property>
156.3252 +		  <property name="text" translatable="yes"></property>
156.3253 +		  <property name="has_frame">True</property>
156.3254 +		  <property name="invisible_char" translatable="yes">*</property>
156.3255 +		  <property name="activates_default">False</property>
156.3256 +		</widget>
156.3257 +		<packing>
156.3258 +		  <property name="left_attach">1</property>
156.3259 +		  <property name="right_attach">2</property>
156.3260 +		  <property name="top_attach">3</property>
156.3261 +		  <property name="bottom_attach">4</property>
156.3262 +		  <property name="x_options">fill</property>
156.3263 +		  <property name="y_options">expand</property>
156.3264 +		</packing>
156.3265 +	      </child>
156.3266 +
156.3267 +	      <child>
156.3268 +		<widget class="GtkEntry" id="JoypadAEntry">
156.3269 +		  <property name="visible">True</property>
156.3270 +		  <property name="can_focus">True</property>
156.3271 +		  <property name="editable">False</property>
156.3272 +		  <property name="visibility">True</property>
156.3273 +		  <property name="max_length">0</property>
156.3274 +		  <property name="text" translatable="yes"></property>
156.3275 +		  <property name="has_frame">True</property>
156.3276 +		  <property name="invisible_char" translatable="yes">*</property>
156.3277 +		  <property name="activates_default">False</property>
156.3278 +		</widget>
156.3279 +		<packing>
156.3280 +		  <property name="left_attach">1</property>
156.3281 +		  <property name="right_attach">2</property>
156.3282 +		  <property name="top_attach">4</property>
156.3283 +		  <property name="bottom_attach">5</property>
156.3284 +		  <property name="x_options">fill</property>
156.3285 +		  <property name="y_options">expand</property>
156.3286 +		</packing>
156.3287 +	      </child>
156.3288 +
156.3289 +	      <child>
156.3290 +		<widget class="GtkEntry" id="JoypadBEntry">
156.3291 +		  <property name="visible">True</property>
156.3292 +		  <property name="can_focus">True</property>
156.3293 +		  <property name="editable">False</property>
156.3294 +		  <property name="visibility">True</property>
156.3295 +		  <property name="max_length">0</property>
156.3296 +		  <property name="text" translatable="yes"></property>
156.3297 +		  <property name="has_frame">True</property>
156.3298 +		  <property name="invisible_char" translatable="yes">*</property>
156.3299 +		  <property name="activates_default">False</property>
156.3300 +		</widget>
156.3301 +		<packing>
156.3302 +		  <property name="left_attach">1</property>
156.3303 +		  <property name="right_attach">2</property>
156.3304 +		  <property name="top_attach">5</property>
156.3305 +		  <property name="bottom_attach">6</property>
156.3306 +		  <property name="x_options">fill</property>
156.3307 +		  <property name="y_options">expand</property>
156.3308 +		</packing>
156.3309 +	      </child>
156.3310 +
156.3311 +	      <child>
156.3312 +		<widget class="GtkEntry" id="JoypadLEntry">
156.3313 +		  <property name="visible">True</property>
156.3314 +		  <property name="can_focus">True</property>
156.3315 +		  <property name="editable">False</property>
156.3316 +		  <property name="visibility">True</property>
156.3317 +		  <property name="max_length">0</property>
156.3318 +		  <property name="text" translatable="yes"></property>
156.3319 +		  <property name="has_frame">True</property>
156.3320 +		  <property name="invisible_char" translatable="yes">*</property>
156.3321 +		  <property name="activates_default">False</property>
156.3322 +		</widget>
156.3323 +		<packing>
156.3324 +		  <property name="left_attach">1</property>
156.3325 +		  <property name="right_attach">2</property>
156.3326 +		  <property name="top_attach">6</property>
156.3327 +		  <property name="bottom_attach">7</property>
156.3328 +		  <property name="x_options">fill</property>
156.3329 +		  <property name="y_options">expand</property>
156.3330 +		</packing>
156.3331 +	      </child>
156.3332 +
156.3333 +	      <child>
156.3334 +		<widget class="GtkEntry" id="JoypadREntry">
156.3335 +		  <property name="visible">True</property>
156.3336 +		  <property name="can_focus">True</property>
156.3337 +		  <property name="editable">False</property>
156.3338 +		  <property name="visibility">True</property>
156.3339 +		  <property name="max_length">0</property>
156.3340 +		  <property name="text" translatable="yes"></property>
156.3341 +		  <property name="has_frame">True</property>
156.3342 +		  <property name="invisible_char" translatable="yes">*</property>
156.3343 +		  <property name="activates_default">False</property>
156.3344 +		</widget>
156.3345 +		<packing>
156.3346 +		  <property name="left_attach">1</property>
156.3347 +		  <property name="right_attach">2</property>
156.3348 +		  <property name="top_attach">7</property>
156.3349 +		  <property name="bottom_attach">8</property>
156.3350 +		  <property name="x_options">fill</property>
156.3351 +		  <property name="y_options">expand</property>
156.3352 +		</packing>
156.3353 +	      </child>
156.3354 +
156.3355 +	      <child>
156.3356 +		<widget class="GtkEntry" id="JoypadSelectEntry">
156.3357 +		  <property name="visible">True</property>
156.3358 +		  <property name="can_focus">True</property>
156.3359 +		  <property name="editable">False</property>
156.3360 +		  <property name="visibility">True</property>
156.3361 +		  <property name="max_length">0</property>
156.3362 +		  <property name="text" translatable="yes"></property>
156.3363 +		  <property name="has_frame">True</property>
156.3364 +		  <property name="invisible_char" translatable="yes">*</property>
156.3365 +		  <property name="activates_default">False</property>
156.3366 +		</widget>
156.3367 +		<packing>
156.3368 +		  <property name="left_attach">1</property>
156.3369 +		  <property name="right_attach">2</property>
156.3370 +		  <property name="top_attach">8</property>
156.3371 +		  <property name="bottom_attach">9</property>
156.3372 +		  <property name="x_options">fill</property>
156.3373 +		  <property name="y_options">expand</property>
156.3374 +		</packing>
156.3375 +	      </child>
156.3376 +
156.3377 +	      <child>
156.3378 +		<widget class="GtkEntry" id="JoypadStartEntry">
156.3379 +		  <property name="visible">True</property>
156.3380 +		  <property name="can_focus">True</property>
156.3381 +		  <property name="editable">False</property>
156.3382 +		  <property name="visibility">True</property>
156.3383 +		  <property name="max_length">0</property>
156.3384 +		  <property name="text" translatable="yes"></property>
156.3385 +		  <property name="has_frame">True</property>
156.3386 +		  <property name="invisible_char" translatable="yes">*</property>
156.3387 +		  <property name="activates_default">False</property>
156.3388 +		</widget>
156.3389 +		<packing>
156.3390 +		  <property name="left_attach">1</property>
156.3391 +		  <property name="right_attach">2</property>
156.3392 +		  <property name="top_attach">9</property>
156.3393 +		  <property name="bottom_attach">10</property>
156.3394 +		  <property name="x_options">fill</property>
156.3395 +		  <property name="y_options">expand</property>
156.3396 +		</packing>
156.3397 +	      </child>
156.3398 +
156.3399 +	      <child>
156.3400 +		<widget class="GtkEntry" id="JoypadSpeedEntry">
156.3401 +		  <property name="visible">True</property>
156.3402 +		  <property name="can_focus">True</property>
156.3403 +		  <property name="editable">False</property>
156.3404 +		  <property name="visibility">True</property>
156.3405 +		  <property name="max_length">0</property>
156.3406 +		  <property name="text" translatable="yes"></property>
156.3407 +		  <property name="has_frame">True</property>
156.3408 +		  <property name="invisible_char" translatable="yes">*</property>
156.3409 +		  <property name="activates_default">False</property>
156.3410 +		</widget>
156.3411 +		<packing>
156.3412 +		  <property name="left_attach">1</property>
156.3413 +		  <property name="right_attach">2</property>
156.3414 +		  <property name="top_attach">10</property>
156.3415 +		  <property name="bottom_attach">11</property>
156.3416 +		  <property name="x_options">fill</property>
156.3417 +		  <property name="y_options">expand</property>
156.3418 +		</packing>
156.3419 +	      </child>
156.3420 +
156.3421 +	      <child>
156.3422 +		<widget class="GtkEntry" id="JoypadCaptureEntry">
156.3423 +		  <property name="visible">True</property>
156.3424 +		  <property name="can_focus">True</property>
156.3425 +		  <property name="editable">False</property>
156.3426 +		  <property name="visibility">True</property>
156.3427 +		  <property name="max_length">0</property>
156.3428 +		  <property name="text" translatable="yes"></property>
156.3429 +		  <property name="has_frame">True</property>
156.3430 +		  <property name="invisible_char" translatable="yes">*</property>
156.3431 +		  <property name="activates_default">False</property>
156.3432 +		</widget>
156.3433 +		<packing>
156.3434 +		  <property name="left_attach">1</property>
156.3435 +		  <property name="right_attach">2</property>
156.3436 +		  <property name="top_attach">11</property>
156.3437 +		  <property name="bottom_attach">12</property>
156.3438 +		  <property name="x_options">fill</property>
156.3439 +		  <property name="y_options">expand</property>
156.3440 +		</packing>
156.3441 +	      </child>
156.3442 +
156.3443 +	      <child>
156.3444 +		<widget class="GtkLabel" id="label11">
156.3445 +		  <property name="visible">True</property>
156.3446 +		  <property name="label" translatable="yes">Up : </property>
156.3447 +		  <property name="use_underline">False</property>
156.3448 +		  <property name="use_markup">False</property>
156.3449 +		  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.3450 +		  <property name="wrap">False</property>
156.3451 +		  <property name="selectable">False</property>
156.3452 +		  <property name="xalign">1</property>
156.3453 +		  <property name="yalign">0.5</property>
156.3454 +		  <property name="xpad">0</property>
156.3455 +		  <property name="ypad">0</property>
156.3456 +		</widget>
156.3457 +		<packing>
156.3458 +		  <property name="left_attach">0</property>
156.3459 +		  <property name="right_attach">1</property>
156.3460 +		  <property name="top_attach">0</property>
156.3461 +		  <property name="bottom_attach">1</property>
156.3462 +		  <property name="x_options">fill</property>
156.3463 +		  <property name="y_options">expand</property>
156.3464 +		</packing>
156.3465 +	      </child>
156.3466 +	    </widget>
156.3467 +	  </child>
156.3468 +	</widget>
156.3469 +	<packing>
156.3470 +	  <property name="padding">0</property>
156.3471 +	  <property name="expand">True</property>
156.3472 +	  <property name="fill">True</property>
156.3473 +	</packing>
156.3474 +      </child>
156.3475 +    </widget>
156.3476 +  </child>
156.3477 +</widget>
156.3478 +
156.3479 +<widget class="GtkDialog" id="TcpPortDialog">
156.3480 +  <property name="title" translatable="yes">TCP port</property>
156.3481 +  <property name="type">GTK_WINDOW_TOPLEVEL</property>
156.3482 +  <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
156.3483 +  <property name="modal">False</property>
156.3484 +  <property name="resizable">True</property>
156.3485 +  <property name="destroy_with_parent">True</property>
156.3486 +  <property name="skip_taskbar_hint">False</property>
156.3487 +  <property name="skip_pager_hint">False</property>
156.3488 +  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
156.3489 +  <property name="has_separator">True</property>
156.3490 +
156.3491 +  <child internal-child="vbox">
156.3492 +    <widget class="GtkVBox" id="dialog-vbox5">
156.3493 +      <property name="visible">True</property>
156.3494 +      <property name="homogeneous">False</property>
156.3495 +      <property name="spacing">0</property>
156.3496 +
156.3497 +      <child internal-child="action_area">
156.3498 +	<widget class="GtkHButtonBox" id="dialog-action_area5">
156.3499 +	  <property name="visible">True</property>
156.3500 +	  <property name="layout_style">GTK_BUTTONBOX_END</property>
156.3501 +
156.3502 +	  <child>
156.3503 +	    <widget class="GtkButton" id="cancelbutton4">
156.3504 +	      <property name="visible">True</property>
156.3505 +	      <property name="can_default">True</property>
156.3506 +	      <property name="can_focus">True</property>
156.3507 +	      <property name="label">gtk-cancel</property>
156.3508 +	      <property name="use_stock">True</property>
156.3509 +	      <property name="relief">GTK_RELIEF_NORMAL</property>
156.3510 +	      <property name="response_id">-6</property>
156.3511 +	    </widget>
156.3512 +	  </child>
156.3513 +
156.3514 +	  <child>
156.3515 +	    <widget class="GtkButton" id="okbutton4">
156.3516 +	      <property name="visible">True</property>
156.3517 +	      <property name="can_default">True</property>
156.3518 +	      <property name="can_focus">True</property>
156.3519 +	      <property name="label">gtk-ok</property>
156.3520 +	      <property name="use_stock">True</property>
156.3521 +	      <property name="relief">GTK_RELIEF_NORMAL</property>
156.3522 +	      <property name="response_id">-5</property>
156.3523 +	    </widget>
156.3524 +	  </child>
156.3525 +	</widget>
156.3526 +	<packing>
156.3527 +	  <property name="padding">0</property>
156.3528 +	  <property name="expand">False</property>
156.3529 +	  <property name="fill">True</property>
156.3530 +	  <property name="pack_type">GTK_PACK_END</property>
156.3531 +	</packing>
156.3532 +      </child>
156.3533 +
156.3534 +      <child>
156.3535 +	<widget class="GtkAlignment" id="alignment3">
156.3536 +	  <property name="visible">True</property>
156.3537 +	  <property name="xalign">0.5</property>
156.3538 +	  <property name="yalign">0.5</property>
156.3539 +	  <property name="xscale">0</property>
156.3540 +	  <property name="yscale">0</property>
156.3541 +
156.3542 +	  <child>
156.3543 +	    <widget class="GtkHBox" id="hbox2">
156.3544 +	      <property name="visible">True</property>
156.3545 +	      <property name="homogeneous">False</property>
156.3546 +	      <property name="spacing">0</property>
156.3547 +
156.3548 +	      <child>
156.3549 +		<widget class="GtkLabel" id="label23">
156.3550 +		  <property name="visible">True</property>
156.3551 +		  <property name="label" translatable="yes">Port : </property>
156.3552 +		  <property name="use_underline">False</property>
156.3553 +		  <property name="use_markup">False</property>
156.3554 +		  <property name="justify">GTK_JUSTIFY_LEFT</property>
156.3555 +		  <property name="wrap">False</property>
156.3556 +		  <property name="selectable">False</property>
156.3557 +		  <property name="xalign">1</property>
156.3558 +		  <property name="yalign">0.5</property>
156.3559 +		  <property name="xpad">0</property>
156.3560 +		  <property name="ypad">0</property>
156.3561 +		</widget>
156.3562 +		<packing>
156.3563 +		  <property name="padding">0</property>
156.3564 +		  <property name="expand">True</property>
156.3565 +		  <property name="fill">True</property>
156.3566 +		</packing>
156.3567 +	      </child>
156.3568 +
156.3569 +	      <child>
156.3570 +		<widget class="GtkSpinButton" id="TcpPortSpin">
156.3571 +		  <property name="visible">True</property>
156.3572 +		  <property name="can_focus">True</property>
156.3573 +		  <property name="climb_rate">1</property>
156.3574 +		  <property name="digits">0</property>
156.3575 +		  <property name="numeric">True</property>
156.3576 +		  <property name="update_policy">GTK_UPDATE_ALWAYS</property>
156.3577 +		  <property name="snap_to_ticks">True</property>
156.3578 +		  <property name="wrap">True</property>
156.3579 +		  <property name="adjustment">55555 1 65535 1 100 100</property>
156.3580 +		</widget>
156.3581 +		<packing>
156.3582 +		  <property name="padding">0</property>
156.3583 +		  <property name="expand">True</property>
156.3584 +		  <property name="fill">True</property>
156.3585 +		</packing>
156.3586 +	      </child>
156.3587 +	    </widget>
156.3588 +	  </child>
156.3589 +	</widget>
156.3590 +	<packing>
156.3591 +	  <property name="padding">0</property>
156.3592 +	  <property name="expand">True</property>
156.3593 +	  <property name="fill">True</property>
156.3594 +	</packing>
156.3595 +      </child>
156.3596 +    </widget>
156.3597 +  </child>
156.3598 +</widget>
156.3599 +
156.3600 +</glade-interface>
   157.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   157.2 +++ b/src/gtk/window.cpp	Sat Mar 03 10:31:27 2012 -0600
   157.3 @@ -0,0 +1,1944 @@
   157.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   157.5 +// Copyright (C) 1999-2003 Forgotten
   157.6 +// Copyright (C) 2004 Forgotten and the VBA development team
   157.7 +
   157.8 +// This program is free software; you can redistribute it and/or modify
   157.9 +// it under the terms of the GNU General Public License as published by
  157.10 +// the Free Software Foundation; either version 2, or(at your option)
  157.11 +// any later version.
  157.12 +//
  157.13 +// This program is distributed in the hope that it will be useful,
  157.14 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  157.15 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  157.16 +// GNU General Public License for more details.
  157.17 +//
  157.18 +// You should have received a copy of the GNU General Public License
  157.19 +// along with this program; if not, write to the Free Software Foundation,
  157.20 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  157.21 +
  157.22 +#include "window.h"
  157.23 +
  157.24 +#include <sys/stat.h>
  157.25 +
  157.26 +#include <stdio.h>
  157.27 +#include <time.h>
  157.28 +
  157.29 +#include <SDL.h>
  157.30 +
  157.31 +#include "../gba/GBA.h"
  157.32 +#include "../gba/GBAGlobals.h"
  157.33 +#include "../gba/GBASound.h"
  157.34 +#include "../gb/GB.h"
  157.35 +#include "../gb/gbGlobals.h"
  157.36 +#include "../gb/gbPrinter.h"
  157.37 +#include "../common/Util.h"
  157.38 +
  157.39 +#include "menuitem.h"
  157.40 +#include "tools.h"
  157.41 +#include "intl.h"
  157.42 +
  157.43 +extern int systemRenderedFrames;
  157.44 +extern int systemFPS;
  157.45 +extern bool debugger;
  157.46 +extern int RGB_LOW_BITS_MASK;
  157.47 +extern void (*dbgMain)();
  157.48 +extern void (*dbgSignal)(int, int);
  157.49 +extern void (*dbgOutput)(char *, u32);
  157.50 +extern void remoteInit();
  157.51 +extern void remoteCleanUp();
  157.52 +extern void remoteStubMain();
  157.53 +extern void remoteStubSignal(int, int);
  157.54 +extern void remoteOutput(char *, u32);
  157.55 +extern void remoteSetProtocol(int);
  157.56 +extern void remoteSetPort(int);
  157.57 +
  157.58 +#ifdef MMX
  157.59 +extern "C" bool cpu_mmx;
  157.60 +#endif // MMX
  157.61 +
  157.62 +namespace VBA
  157.63 +{
  157.64 +
  157.65 +using Gnome::Glade::Xml;
  157.66 +
  157.67 +Window * Window::m_poInstance = NULL;
  157.68 +
  157.69 +Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
  157.70 +  Gtk::Window       (_pstWindow),
  157.71 +  m_iGBScreenWidth  (160),
  157.72 +  m_iGBScreenHeight (144),
  157.73 +  m_iSGBScreenWidth (256),
  157.74 +  m_iSGBScreenHeight(224),
  157.75 +  m_iGBAScreenWidth (240),
  157.76 +  m_iGBAScreenHeight(160),
  157.77 +  m_iFrameskipMin   (0),
  157.78 +  m_iFrameskipMax   (9),
  157.79 +  m_iThrottleMin    (5),
  157.80 +  m_iThrottleMax    (1000),
  157.81 +  m_iScaleMin       (1),
  157.82 +  m_iScaleMax       (6),
  157.83 +  m_iShowSpeedMin   (ShowNone),
  157.84 +  m_iShowSpeedMax   (ShowDetailed),
  157.85 +  m_iSaveTypeMin    (SaveAuto),
  157.86 +  m_iSaveTypeMax    (SaveNone),
  157.87 +  m_iSoundQualityMin(Sound44K),
  157.88 +  m_iSoundQualityMax(Sound11K),
  157.89 +  m_iSoundVolumeMin (Sound100),
  157.90 +  m_iSoundVolumeMax (Sound50),
  157.91 +  m_iEmulatorTypeMin(EmulatorAuto),
  157.92 +  m_iEmulatorTypeMax(EmulatorSGB2),
  157.93 +  m_iFilter2xMin    (FirstFilter),
  157.94 +  m_iFilter2xMax    (LastFilter),
  157.95 +  m_iFilterIBMin    (FirstFilterIB),
  157.96 +  m_iFilterIBMax    (LastFilterIB),
  157.97 +  m_iJoypadMin      (1),
  157.98 +  m_iJoypadMax      (4)
  157.99 +{
 157.100 +  m_poXml            = _poXml;
 157.101 +  m_poFileOpenDialog = NULL;
 157.102 +  m_iScreenWidth     = m_iGBAScreenWidth;
 157.103 +  m_iScreenHeight    = m_iGBAScreenHeight;
 157.104 +  m_eCartridge       = CartridgeNone;
 157.105 +  m_uiJoypadState    = 0;
 157.106 +
 157.107 +  vInitSystem();
 157.108 +  vInitSDL();
 157.109 +
 157.110 +  Gtk::Container * poC;
 157.111 +  poC = dynamic_cast<Gtk::Container *>(_poXml->get_widget("ScreenContainer"));
 157.112 +  m_poScreenArea = Gtk::manage(new ScreenArea(m_iScreenWidth, m_iScreenHeight));
 157.113 +  poC->add(*m_poScreenArea);
 157.114 +  vDrawDefaultScreen();
 157.115 +  m_poScreenArea->show();
 157.116 +
 157.117 +  // Get config
 157.118 +  //
 157.119 +  vInitConfig();
 157.120 +
 157.121 +  m_sUserDataDir = Glib::get_home_dir() + "/.gvba";
 157.122 +  m_sConfigFile  = m_sUserDataDir + "/config";
 157.123 +
 157.124 +  if (! Glib::file_test(m_sUserDataDir, Glib::FILE_TEST_EXISTS))
 157.125 +  {
 157.126 +    mkdir(m_sUserDataDir.c_str(), 0777);
 157.127 +  }
 157.128 +  if (Glib::file_test(m_sConfigFile, Glib::FILE_TEST_EXISTS))
 157.129 +  {
 157.130 +    vLoadConfig(m_sConfigFile);
 157.131 +    vCheckConfig();
 157.132 +  }
 157.133 +  else
 157.134 +  {
 157.135 +    vSaveConfig(m_sConfigFile);
 157.136 +  }
 157.137 +
 157.138 +  vCreateFileOpenDialog();
 157.139 +  vLoadHistoryFromConfig();
 157.140 +  vLoadJoypadsFromConfig();
 157.141 +
 157.142 +  Gtk::MenuItem *      poMI;
 157.143 +  Gtk::CheckMenuItem * poCMI;
 157.144 +
 157.145 +  // File menu
 157.146 +  //
 157.147 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("FileOpen"));
 157.148 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnFileOpen));
 157.149 +
 157.150 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("FileLoad"));
 157.151 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnFileLoad));
 157.152 +  m_listSensitiveWhenPlaying.push_back(poMI);
 157.153 +
 157.154 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("FileSave"));
 157.155 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnFileSave));
 157.156 +  m_listSensitiveWhenPlaying.push_back(poMI);
 157.157 +
 157.158 +  for (int i = 0; i < 10; i++)
 157.159 +  {
 157.160 +    char csName[20];
 157.161 +    snprintf(csName, 20, "LoadGameSlot%d", i + 1);
 157.162 +    m_apoLoadGameItem[i] = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget(csName));
 157.163 +    snprintf(csName, 20, "SaveGameSlot%d", i + 1);
 157.164 +    m_apoSaveGameItem[i] = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget(csName));
 157.165 +
 157.166 +    m_apoLoadGameItem[i]->signal_activate().connect(SigC::bind<int>(
 157.167 +                                                      SigC::slot(*this, &Window::vOnLoadGame),
 157.168 +                                                      i + 1));
 157.169 +    m_apoSaveGameItem[i]->signal_activate().connect(SigC::bind<int>(
 157.170 +                                                      SigC::slot(*this, &Window::vOnSaveGame),
 157.171 +                                                      i + 1));
 157.172 +  }
 157.173 +  vUpdateGameSlots();
 157.174 +
 157.175 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("LoadGameMostRecent"));
 157.176 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnLoadGameMostRecent));
 157.177 +  m_listSensitiveWhenPlaying.push_back(poMI);
 157.178 +
 157.179 +  poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("LoadGameAuto"));
 157.180 +  poCMI->set_active(m_poCoreConfig->oGetKey<bool>("load_game_auto"));
 157.181 +  vOnLoadGameAutoToggled(poCMI);
 157.182 +  poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *>(
 157.183 +                                    SigC::slot(*this, &Window::vOnLoadGameAutoToggled),
 157.184 +                                    poCMI));
 157.185 +
 157.186 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("SaveGameOldest"));
 157.187 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnSaveGameOldest));
 157.188 +  m_listSensitiveWhenPlaying.push_back(poMI);
 157.189 +
 157.190 +  m_poFilePauseItem = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("FilePause"));
 157.191 +  m_poFilePauseItem->set_active(false);
 157.192 +  vOnFilePauseToggled(m_poFilePauseItem);
 157.193 +  m_poFilePauseItem->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *>(
 157.194 +                                                SigC::slot(*this, &Window::vOnFilePauseToggled),
 157.195 +                                                m_poFilePauseItem));
 157.196 +  m_listSensitiveWhenPlaying.push_back(m_poFilePauseItem);
 157.197 +
 157.198 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("FileReset"));
 157.199 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnFileReset));
 157.200 +  m_listSensitiveWhenPlaying.push_back(poMI);
 157.201 +
 157.202 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("FileScreenCapture"));
 157.203 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnFileScreenCapture));
 157.204 +  m_listSensitiveWhenPlaying.push_back(poMI);
 157.205 +
 157.206 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("FileClose"));
 157.207 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnFileClose));
 157.208 +  m_listSensitiveWhenPlaying.push_back(poMI);
 157.209 +
 157.210 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("FileExit"));
 157.211 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnFileExit));
 157.212 +
 157.213 +  // Recent menu
 157.214 +  //
 157.215 +  m_poRecentMenu = dynamic_cast<Gtk::Menu *>(_poXml->get_widget("RecentMenu_menu"));
 157.216 +  vUpdateHistoryMenu();
 157.217 +
 157.218 +  m_poRecentResetItem = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("RecentReset"));
 157.219 +  m_poRecentResetItem->signal_activate().connect(SigC::slot(*this, &Window::vOnRecentReset));
 157.220 +
 157.221 +  poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("RecentFreeze"));
 157.222 +  poCMI->set_active(m_poHistoryConfig->oGetKey<bool>("freeze"));
 157.223 +  vOnRecentFreezeToggled(poCMI);
 157.224 +  poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *>(
 157.225 +                                    SigC::slot(*this, &Window::vOnRecentFreezeToggled),
 157.226 +                                    poCMI));
 157.227 +
 157.228 +  // Import menu
 157.229 +  //
 157.230 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("ImportBatteryFile"));
 157.231 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnImportBatteryFile));
 157.232 +  m_listSensitiveWhenPlaying.push_back(poMI);
 157.233 +
 157.234 +  // Export menu
 157.235 +  //
 157.236 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("ExportBatteryFile"));
 157.237 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnExportBatteryFile));
 157.238 +  m_listSensitiveWhenPlaying.push_back(poMI);
 157.239 +
 157.240 +  // Frameskip menu
 157.241 +  //
 157.242 +  struct
 157.243 +  {
 157.244 +    const char * m_csName;
 157.245 +    const int    m_iFrameskip;
 157.246 +  }
 157.247 +  astFrameskip[] =
 157.248 +  {
 157.249 +    { "FrameskipAutomatic", -1 },
 157.250 +    { "Frameskip0",          0 },
 157.251 +    { "Frameskip1",          1 },
 157.252 +    { "Frameskip2",          2 },
 157.253 +    { "Frameskip3",          3 },
 157.254 +    { "Frameskip4",          4 },
 157.255 +    { "Frameskip5",          5 },
 157.256 +    { "Frameskip6",          6 },
 157.257 +    { "Frameskip7",          7 },
 157.258 +    { "Frameskip8",          8 },
 157.259 +    { "Frameskip9",          9 }
 157.260 +  };
 157.261 +  int iDefaultFrameskip;
 157.262 +  if (m_poCoreConfig->sGetKey("frameskip") == "auto")
 157.263 +  {
 157.264 +    iDefaultFrameskip = -1;
 157.265 +  }
 157.266 +  else
 157.267 +  {
 157.268 +    iDefaultFrameskip = m_poCoreConfig->oGetKey<int>("frameskip");
 157.269 +  }
 157.270 +  for (guint i = 0; i < G_N_ELEMENTS(astFrameskip); i++)
 157.271 +  {
 157.272 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astFrameskip[i].m_csName));
 157.273 +    if (astFrameskip[i].m_iFrameskip == iDefaultFrameskip)
 157.274 +    {
 157.275 +      poCMI->set_active();
 157.276 +      vOnFrameskipToggled(poCMI, iDefaultFrameskip);
 157.277 +    }
 157.278 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.279 +                                      SigC::slot(*this, &Window::vOnFrameskipToggled),
 157.280 +                                      poCMI, astFrameskip[i].m_iFrameskip));
 157.281 +  }
 157.282 +
 157.283 +  // Throttle menu
 157.284 +  //
 157.285 +  struct
 157.286 +  {
 157.287 +    const char * m_csName;
 157.288 +    const int    m_iThrottle;
 157.289 +  }
 157.290 +  astThrottle[] =
 157.291 +  {
 157.292 +    { "ThrottleNoThrottle",   0 },
 157.293 +    { "Throttle25",          25 },
 157.294 +    { "Throttle50",          50 },
 157.295 +    { "Throttle100",        100 },
 157.296 +    { "Throttle150",        150 },
 157.297 +    { "Throttle200",        200 }
 157.298 +  };
 157.299 +  poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("ThrottleOther"));
 157.300 +  poCMI->set_active();
 157.301 +  poCMI->signal_activate().connect(SigC::bind<Gtk::CheckMenuItem *>(
 157.302 +                                     SigC::slot(*this, &Window::vOnThrottleOther),
 157.303 +                                     poCMI));
 157.304 +
 157.305 +  int iDefaultThrottle = m_poCoreConfig->oGetKey<int>("throttle");
 157.306 +  for (guint i = 0; i < G_N_ELEMENTS(astThrottle); i++)
 157.307 +  {
 157.308 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astThrottle[i].m_csName));
 157.309 +    if (astThrottle[i].m_iThrottle == iDefaultThrottle)
 157.310 +    {
 157.311 +      poCMI->set_active();
 157.312 +    }
 157.313 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.314 +                                      SigC::slot(*this, &Window::vOnThrottleToggled),
 157.315 +                                      poCMI, astThrottle[i].m_iThrottle));
 157.316 +  }
 157.317 +  vSetThrottle(iDefaultThrottle);
 157.318 +
 157.319 +  // Video menu
 157.320 +  //
 157.321 +  struct
 157.322 +  {
 157.323 +    const char * m_csName;
 157.324 +    const int    m_iScale;
 157.325 +  }
 157.326 +  astVideoScale[] =
 157.327 +  {
 157.328 +    { "Video1x", 1 },
 157.329 +    { "Video2x", 2 },
 157.330 +    { "Video3x", 3 },
 157.331 +    { "Video4x", 4 },
 157.332 +    { "Video5x", 5 },
 157.333 +    { "Video6x", 6 }
 157.334 +  };
 157.335 +  int iDefaultScale = m_poDisplayConfig->oGetKey<int>("scale");
 157.336 +  for (guint i = 0; i < G_N_ELEMENTS(astVideoScale); i++)
 157.337 +  {
 157.338 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astVideoScale[i].m_csName));
 157.339 +    if (astVideoScale[i].m_iScale == iDefaultScale)
 157.340 +    {
 157.341 +      poCMI->set_active();
 157.342 +      vOnVideoScaleToggled(poCMI, iDefaultScale);
 157.343 +    }
 157.344 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.345 +                                      SigC::slot(*this, &Window::vOnVideoScaleToggled),
 157.346 +                                      poCMI, astVideoScale[i].m_iScale));
 157.347 +  }
 157.348 +
 157.349 +  // Layers menu
 157.350 +  //
 157.351 +  struct
 157.352 +  {
 157.353 +    const char * m_csName;
 157.354 +    const char * m_csKey;
 157.355 +    const int    m_iLayer;
 157.356 +  }
 157.357 +  astLayer[] =
 157.358 +  {
 157.359 +    { "LayersBg0",    "layer_bg0",    0 },
 157.360 +    { "LayersBg1",    "layer_bg1",    1 },
 157.361 +    { "LayersBg2",    "layer_bg2",    2 },
 157.362 +    { "LayersBg3",    "layer_bg3",    3 },
 157.363 +    { "LayersObj",    "layer_obj",    4 },
 157.364 +    { "LayersWin0",   "layer_win0",   5 },
 157.365 +    { "LayersWin1",   "layer_win1",   6 },
 157.366 +    { "LayersObjWin", "layer_objwin", 7 }
 157.367 +  };
 157.368 +  for (guint i = 0; i < G_N_ELEMENTS(astLayer); i++)
 157.369 +  {
 157.370 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astLayer[i].m_csName));
 157.371 +    poCMI->set_active(m_poCoreConfig->oGetKey<bool>(astLayer[i].m_csKey));
 157.372 +    vOnLayerToggled(poCMI, astLayer[i].m_iLayer);
 157.373 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.374 +                                      SigC::slot(*this, &Window::vOnLayerToggled),
 157.375 +                                      poCMI, astLayer[i].m_iLayer));
 157.376 +  }
 157.377 +
 157.378 +  // Emulator menu
 157.379 +  //
 157.380 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("EmulatorDirectories"));
 157.381 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnDirectories));
 157.382 +
 157.383 +  poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("EmulatorPauseWhenInactive"));
 157.384 +  poCMI->set_active(m_poDisplayConfig->oGetKey<bool>("pause_when_inactive"));
 157.385 +  vOnPauseWhenInactiveToggled(poCMI);
 157.386 +  poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *>(
 157.387 +                                    SigC::slot(*this, &Window::vOnPauseWhenInactiveToggled),
 157.388 +                                    poCMI));
 157.389 +
 157.390 +  m_poUseBiosItem = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("EmulatorUseBios"));
 157.391 +  m_poUseBiosItem->set_active(m_poCoreConfig->oGetKey<bool>("use_bios_file"));
 157.392 +  if (m_poCoreConfig->sGetKey("bios_file") == "")
 157.393 +  {
 157.394 +    m_poUseBiosItem->set_sensitive(false);
 157.395 +  }
 157.396 +  m_poUseBiosItem->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *>(
 157.397 +                                              SigC::slot(*this, &Window::vOnUseBiosToggled),
 157.398 +                                              m_poUseBiosItem));
 157.399 +
 157.400 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("EmulatorSelectBios"));
 157.401 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnSelectBios));
 157.402 +
 157.403 +  // Show speed menu
 157.404 +  //
 157.405 +  struct
 157.406 +  {
 157.407 +    const char *     m_csName;
 157.408 +    const EShowSpeed m_eShowSpeed;
 157.409 +  }
 157.410 +  astShowSpeed[] =
 157.411 +  {
 157.412 +    { "ShowSpeedNone",       ShowNone       },
 157.413 +    { "ShowSpeedPercentage", ShowPercentage },
 157.414 +    { "ShowSpeedDetailed",   ShowDetailed   }
 157.415 +  };
 157.416 +  EShowSpeed eDefaultShowSpeed = (EShowSpeed)m_poDisplayConfig->oGetKey<int>("show_speed");
 157.417 +  for (guint i = 0; i < G_N_ELEMENTS(astShowSpeed); i++)
 157.418 +  {
 157.419 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astShowSpeed[i].m_csName));
 157.420 +    if (astShowSpeed[i].m_eShowSpeed == eDefaultShowSpeed)
 157.421 +    {
 157.422 +      poCMI->set_active();
 157.423 +      vOnShowSpeedToggled(poCMI, eDefaultShowSpeed);
 157.424 +    }
 157.425 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.426 +                                      SigC::slot(*this, &Window::vOnShowSpeedToggled),
 157.427 +                                      poCMI, astShowSpeed[i].m_eShowSpeed));
 157.428 +  }
 157.429 +
 157.430 +  // Save type menu
 157.431 +  //
 157.432 +  struct
 157.433 +  {
 157.434 +    const char *    m_csName;
 157.435 +    const ESaveType m_eSaveType;
 157.436 +  }
 157.437 +  astSaveType[] =
 157.438 +  {
 157.439 +    { "SaveTypeAutomatic",    SaveAuto         },
 157.440 +    { "SaveTypeEeprom",       SaveEEPROM       },
 157.441 +    { "SaveTypeSram",         SaveSRAM         },
 157.442 +    { "SaveTypeFlash",        SaveFlash        },
 157.443 +    { "SaveTypeEepromSensor", SaveEEPROMSensor },
 157.444 +    { "SaveTypeNone",         SaveNone         }
 157.445 +  };
 157.446 +  ESaveType eDefaultSaveType = (ESaveType)m_poCoreConfig->oGetKey<int>("save_type");
 157.447 +  for (guint i = 0; i < G_N_ELEMENTS(astSaveType); i++)
 157.448 +  {
 157.449 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astSaveType[i].m_csName));
 157.450 +    if (astSaveType[i].m_eSaveType == eDefaultSaveType)
 157.451 +    {
 157.452 +      poCMI->set_active();
 157.453 +      vOnSaveTypeToggled(poCMI, eDefaultSaveType);
 157.454 +    }
 157.455 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.456 +                                      SigC::slot(*this, &Window::vOnSaveTypeToggled),
 157.457 +                                      poCMI, astSaveType[i].m_eSaveType));
 157.458 +  }
 157.459 +
 157.460 +  // Flash size menu
 157.461 +  //
 157.462 +  struct
 157.463 +  {
 157.464 +    const char * m_csName;
 157.465 +    const int    m_iFlashSize;
 157.466 +  }
 157.467 +  astFlashSize[] =
 157.468 +  {
 157.469 +    { "SaveTypeFlash64K",   64 },
 157.470 +    { "SaveTypeFlash128K", 128 }
 157.471 +  };
 157.472 +  int iDefaultFlashSize = m_poCoreConfig->oGetKey<int>("flash_size");
 157.473 +  for (guint i = 0; i < G_N_ELEMENTS(astFlashSize); i++)
 157.474 +  {
 157.475 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astFlashSize[i].m_csName));
 157.476 +    if (astFlashSize[i].m_iFlashSize == iDefaultFlashSize)
 157.477 +    {
 157.478 +      poCMI->set_active();
 157.479 +      vOnFlashSizeToggled(poCMI, iDefaultFlashSize);
 157.480 +    }
 157.481 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.482 +                                      SigC::slot(*this, &Window::vOnFlashSizeToggled),
 157.483 +                                      poCMI, astFlashSize[i].m_iFlashSize));
 157.484 +  }
 157.485 +
 157.486 +  // Screenshot format menu
 157.487 +  //
 157.488 +  struct
 157.489 +  {
 157.490 +    const char * m_csName;
 157.491 +    const char * m_csScreenshotFormat;
 157.492 +  }
 157.493 +  astScreenshotFormat[] =
 157.494 +  {
 157.495 +    { "ScreenshotFormatPNG", "png" },
 157.496 +    { "ScreenshotFormatBMP", "bmp" }
 157.497 +  };
 157.498 +  std::string sDefaultScreenshotFormat = m_poCoreConfig->sGetKey("screenshot_format");
 157.499 +  for (guint i = 0; i < G_N_ELEMENTS(astScreenshotFormat); i++)
 157.500 +  {
 157.501 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astScreenshotFormat[i].m_csName));
 157.502 +    if (astScreenshotFormat[i].m_csScreenshotFormat == sDefaultScreenshotFormat)
 157.503 +    {
 157.504 +      poCMI->set_active();
 157.505 +      vOnScreenshotFormatToggled(poCMI, sDefaultScreenshotFormat);
 157.506 +    }
 157.507 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, std::string>(
 157.508 +                                      SigC::slot(*this, &Window::vOnScreenshotFormatToggled),
 157.509 +                                      poCMI, std::string(astScreenshotFormat[i].m_csScreenshotFormat)));
 157.510 +  }
 157.511 +
 157.512 +  // Sound menu
 157.513 +  //
 157.514 +  std::string sDefaultSoundStatus = m_poSoundConfig->sGetKey("status");
 157.515 +
 157.516 +  poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("SoundOff"));
 157.517 +  if (sDefaultSoundStatus == "off")
 157.518 +  {
 157.519 +    poCMI->set_active();
 157.520 +    vOnSoundStatusToggled(poCMI, SoundOff);
 157.521 +  }
 157.522 +  poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.523 +                                    SigC::slot(*this, &Window::vOnSoundStatusToggled),
 157.524 +                                    poCMI, SoundOff));
 157.525 +  m_poSoundOffItem = poCMI;
 157.526 +
 157.527 +  poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("SoundMute"));
 157.528 +  if (sDefaultSoundStatus == "mute")
 157.529 +  {
 157.530 +    poCMI->set_active();
 157.531 +    vOnSoundStatusToggled(poCMI, SoundMute);
 157.532 +  }
 157.533 +  poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.534 +                                    SigC::slot(*this, &Window::vOnSoundStatusToggled),
 157.535 +                                    poCMI, SoundMute));
 157.536 +
 157.537 +  poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("SoundOn"));
 157.538 +  if (sDefaultSoundStatus == "on")
 157.539 +  {
 157.540 +    poCMI->set_active();
 157.541 +    vOnSoundStatusToggled(poCMI, SoundOn);
 157.542 +  }
 157.543 +  poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.544 +                                    SigC::slot(*this, &Window::vOnSoundStatusToggled),
 157.545 +                                    poCMI, SoundOn));
 157.546 +
 157.547 +  poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("SoundEcho"));
 157.548 +  poCMI->set_active(m_poSoundConfig->oGetKey<bool>("echo"));
 157.549 +  vOnSoundEchoToggled(poCMI);
 157.550 +  poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *>(
 157.551 +                                    SigC::slot(*this, &Window::vOnSoundEchoToggled),
 157.552 +                                    poCMI));
 157.553 +
 157.554 +  poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("SoundLowPass"));
 157.555 +  poCMI->set_active(m_poSoundConfig->oGetKey<bool>("low_pass"));
 157.556 +  vOnSoundLowPassToggled(poCMI);
 157.557 +  poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *>(
 157.558 +                                    SigC::slot(*this, &Window::vOnSoundLowPassToggled),
 157.559 +                                    poCMI));
 157.560 +
 157.561 +  poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("SoundReverseStereo"));
 157.562 +  poCMI->set_active(m_poSoundConfig->oGetKey<bool>("reverse_stereo"));
 157.563 +  vOnSoundReverseToggled(poCMI);
 157.564 +  poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *>(
 157.565 +                                    SigC::slot(*this, &Window::vOnSoundReverseToggled),
 157.566 +                                    poCMI));
 157.567 +
 157.568 +  struct
 157.569 +  {
 157.570 +    const char * m_csName;
 157.571 +    const char * m_csKey;
 157.572 +    const int    m_iSoundChannel;
 157.573 +  }
 157.574 +  astSoundChannel[] =
 157.575 +  {
 157.576 +    { "SoundChannel1", "channel_1", 0 },
 157.577 +    { "SoundChannel2", "channel_2", 1 },
 157.578 +    { "SoundChannel3", "channel_3", 2 },
 157.579 +    { "SoundChannel4", "channel_4", 3 },
 157.580 +    { "SoundChannelA", "channel_A", 4 },
 157.581 +    { "SoundChannelB", "channel_B", 5 }
 157.582 +  };
 157.583 +  for (guint i = 0; i < G_N_ELEMENTS(astSoundChannel); i++)
 157.584 +  {
 157.585 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astSoundChannel[i].m_csName));
 157.586 +    poCMI->set_active(m_poSoundConfig->oGetKey<bool>(astSoundChannel[i].m_csKey));
 157.587 +    vOnSoundChannelToggled(poCMI, astSoundChannel[i].m_iSoundChannel);
 157.588 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.589 +                                      SigC::slot(*this, &Window::vOnSoundChannelToggled),
 157.590 +                                      poCMI, astSoundChannel[i].m_iSoundChannel));
 157.591 +  }
 157.592 +
 157.593 +  struct
 157.594 +  {
 157.595 +    const char *        m_csName;
 157.596 +    const ESoundQuality m_eSoundQuality;
 157.597 +  }
 157.598 +  astSoundQuality[] =
 157.599 +  {
 157.600 +    { "Sound11Khz", Sound11K },
 157.601 +    { "Sound22Khz", Sound22K },
 157.602 +    { "Sound44Khz", Sound44K }
 157.603 +  };
 157.604 +  ESoundQuality eDefaultSoundQuality = (ESoundQuality)m_poSoundConfig->oGetKey<int>("quality");
 157.605 +  for (guint i = 0; i < G_N_ELEMENTS(astSoundQuality); i++)
 157.606 +  {
 157.607 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astSoundQuality[i].m_csName));
 157.608 +    if (astSoundQuality[i].m_eSoundQuality == eDefaultSoundQuality)
 157.609 +    {
 157.610 +      poCMI->set_active();
 157.611 +      vOnSoundQualityToggled(poCMI, eDefaultSoundQuality);
 157.612 +    }
 157.613 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.614 +                                      SigC::slot(*this, &Window::vOnSoundQualityToggled),
 157.615 +                                      poCMI, astSoundQuality[i].m_eSoundQuality));
 157.616 +  }
 157.617 +
 157.618 +  // Volume menu
 157.619 +  //
 157.620 +  struct
 157.621 +  {
 157.622 +    const char *       m_csName;
 157.623 +    const ESoundVolume m_eSoundVolume;
 157.624 +  }
 157.625 +  astSoundVolume[] =
 157.626 +  {
 157.627 +    { "Volume25",   Sound25  },
 157.628 +    { "Volume50",   Sound50  },
 157.629 +    { "Volume100",  Sound100 },
 157.630 +    { "Volume200",  Sound200 },
 157.631 +    { "Volume300",  Sound300 },
 157.632 +    { "Volume400",  Sound400 }
 157.633 +  };
 157.634 +  ESoundVolume eDefaultSoundVolume = (ESoundVolume)m_poSoundConfig->oGetKey<int>("volume");
 157.635 +  for (guint i = 0; i < G_N_ELEMENTS(astSoundVolume); i++)
 157.636 +  {
 157.637 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astSoundVolume[i].m_csName));
 157.638 +    if (astSoundVolume[i].m_eSoundVolume == eDefaultSoundVolume)
 157.639 +    {
 157.640 +      poCMI->set_active();
 157.641 +      vOnSoundVolumeToggled(poCMI, eDefaultSoundVolume);
 157.642 +    }
 157.643 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.644 +                                      SigC::slot(*this, &Window::vOnSoundVolumeToggled),
 157.645 +                                      poCMI, astSoundVolume[i].m_eSoundVolume));
 157.646 +  }
 157.647 +
 157.648 +  // Gameboy menu
 157.649 +  //
 157.650 +  poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("GameboyBorder"));
 157.651 +  poCMI->set_active(m_poCoreConfig->oGetKey<bool>("gb_border"));
 157.652 +  vOnGBBorderToggled(poCMI);
 157.653 +  poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *>(
 157.654 +                                    SigC::slot(*this, &Window::vOnGBBorderToggled),
 157.655 +                                    poCMI));
 157.656 +
 157.657 +  poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("GameboyPrinter"));
 157.658 +  poCMI->set_active(m_poCoreConfig->oGetKey<bool>("gb_printer"));
 157.659 +  vOnGBPrinterToggled(poCMI);
 157.660 +  poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *>(
 157.661 +                                    SigC::slot(*this, &Window::vOnGBPrinterToggled),
 157.662 +                                    poCMI));
 157.663 +
 157.664 +  struct
 157.665 +  {
 157.666 +    const char *        m_csName;
 157.667 +    const EEmulatorType m_eEmulatorType;
 157.668 +  }
 157.669 +  astEmulatorType[] =
 157.670 +  {
 157.671 +    { "GameboyAutomatic", EmulatorAuto },
 157.672 +    { "GameboyGba",       EmulatorGBA  },
 157.673 +    { "GameboyCgb",       EmulatorCGB  },
 157.674 +    { "GameboySgb",       EmulatorSGB  },
 157.675 +    { "GameboySgb2",      EmulatorSGB2 },
 157.676 +    { "GameboyGb",        EmulatorGB   }
 157.677 +  };
 157.678 +  EEmulatorType eDefaultEmulatorType = (EEmulatorType)m_poCoreConfig->oGetKey<int>("emulator_type");
 157.679 +  for (guint i = 0; i < G_N_ELEMENTS(astEmulatorType); i++)
 157.680 +  {
 157.681 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astEmulatorType[i].m_csName));
 157.682 +    if (astEmulatorType[i].m_eEmulatorType == eDefaultEmulatorType)
 157.683 +    {
 157.684 +      poCMI->set_active();
 157.685 +      vOnEmulatorTypeToggled(poCMI, eDefaultEmulatorType);
 157.686 +    }
 157.687 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.688 +                                      SigC::slot(*this, &Window::vOnEmulatorTypeToggled),
 157.689 +                                      poCMI, astEmulatorType[i].m_eEmulatorType));
 157.690 +  }
 157.691 +
 157.692 +  // Filter menu
 157.693 +  //
 157.694 +  struct
 157.695 +  {
 157.696 +    const char *    m_csName;
 157.697 +    const EFilter2x m_eFilter2x;
 157.698 +  }
 157.699 +  astFilter2x[] =
 157.700 +  {
 157.701 +    { "FilterNone",          FilterNone         },
 157.702 +    { "FilterTVMode",        FilterScanlinesTV  },
 157.703 +    { "Filter2xSaI",         Filter2xSaI        },
 157.704 +    { "FilterSuper2xSaI",    FilterSuper2xSaI   },
 157.705 +    { "FilterSuperEagle",    FilterSuperEagle   },
 157.706 +    { "FilterPixelate",      FilterPixelate     },
 157.707 +    { "FilterMotionBlur",    FilterMotionBlur   },
 157.708 +    { "FilterAdvanceMame2x", FilterAdMame2x     },
 157.709 +    { "FilterSimple2x",      FilterSimple2x     },
 157.710 +    { "FilterBilinear",      FilterBilinear     },
 157.711 +    { "FilterBilinearPlus",  FilterBilinearPlus },
 157.712 +    { "FilterScanlines",     FilterScanlines    },
 157.713 +    { "FilterHq2x",          FilterHq2x         },
 157.714 +    { "FilterLq2x",          FilterLq2x         }
 157.715 +  };
 157.716 +  EFilter2x eDefaultFilter2x = (EFilter2x)m_poDisplayConfig->oGetKey<int>("filter2x");
 157.717 +  for (guint i = 0; i < G_N_ELEMENTS(astFilter2x); i++)
 157.718 +  {
 157.719 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astFilter2x[i].m_csName));
 157.720 +    if (astFilter2x[i].m_eFilter2x == eDefaultFilter2x)
 157.721 +    {
 157.722 +      poCMI->set_active();
 157.723 +      vOnFilter2xToggled(poCMI, eDefaultFilter2x);
 157.724 +    }
 157.725 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.726 +                                      SigC::slot(*this, &Window::vOnFilter2xToggled),
 157.727 +                                      poCMI, astFilter2x[i].m_eFilter2x));
 157.728 +  }
 157.729 +
 157.730 +  poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("FilterDisableMmx"));
 157.731 +#ifdef MMX
 157.732 +  poCMI->set_active(m_poDisplayConfig->oGetKey<bool>("filter_disable_mmx"));
 157.733 +  vOnDisableMMXToggled(poCMI);
 157.734 +  poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *>(
 157.735 +                                    SigC::slot(*this, &Window::vOnDisableMMXToggled),
 157.736 +                                    poCMI));
 157.737 +#else // ! MMX
 157.738 +  poCMI->set_active();
 157.739 +  poCMI->set_sensitive(false);
 157.740 +#endif // ! MMX
 157.741 +
 157.742 +  // Interframe blending menu
 157.743 +  //
 157.744 +  struct
 157.745 +  {
 157.746 +    const char *    m_csName;
 157.747 +    const EFilterIB m_eFilterIB;
 157.748 +  }
 157.749 +  astFilterIB[] =
 157.750 +  {
 157.751 +    { "IFBNone",       FilterIBNone       },
 157.752 +    { "IFBSmart",      FilterIBSmart      },
 157.753 +    { "IFBMotionBlur", FilterIBMotionBlur }
 157.754 +  };
 157.755 +  EFilterIB eDefaultFilterIB = (EFilterIB)m_poDisplayConfig->oGetKey<int>("filterIB");
 157.756 +  for (guint i = 0; i < G_N_ELEMENTS(astFilterIB); i++)
 157.757 +  {
 157.758 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astFilterIB[i].m_csName));
 157.759 +    if (astFilterIB[i].m_eFilterIB == eDefaultFilterIB)
 157.760 +    {
 157.761 +      poCMI->set_active();
 157.762 +      vOnFilterIBToggled(poCMI, eDefaultFilterIB);
 157.763 +    }
 157.764 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.765 +                                      SigC::slot(*this, &Window::vOnFilterIBToggled),
 157.766 +                                      poCMI, astFilterIB[i].m_eFilterIB));
 157.767 +  }
 157.768 +
 157.769 +  // Joypad menu
 157.770 +  //
 157.771 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("JoypadConfigure1"));
 157.772 +  poMI->signal_activate().connect(SigC::bind<int>(
 157.773 +                                    SigC::slot(*this, &Window::vOnJoypadConfigure), 1));
 157.774 +
 157.775 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("JoypadConfigure2"));
 157.776 +  poMI->signal_activate().connect(SigC::bind<int>(
 157.777 +                                    SigC::slot(*this, &Window::vOnJoypadConfigure), 2));
 157.778 +
 157.779 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("JoypadConfigure3"));
 157.780 +  poMI->signal_activate().connect(SigC::bind<int>(
 157.781 +                                    SigC::slot(*this, &Window::vOnJoypadConfigure), 3));
 157.782 +
 157.783 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("JoypadConfigure4"));
 157.784 +  poMI->signal_activate().connect(SigC::bind<int>(
 157.785 +                                    SigC::slot(*this, &Window::vOnJoypadConfigure), 4));
 157.786 +
 157.787 +  int iDefaultJoypad = m_poInputConfig->oGetKey<int>("active_joypad");
 157.788 +  for (int i = m_iJoypadMin; i <= m_iJoypadMax; i++)
 157.789 +  {
 157.790 +    char csName[20];
 157.791 +    snprintf(csName, sizeof(csName), "Joypad%d", i);
 157.792 +
 157.793 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(csName));
 157.794 +    if (i == iDefaultJoypad)
 157.795 +    {
 157.796 +      poCMI->set_active();
 157.797 +      vOnJoypadToggled(poCMI, iDefaultJoypad);
 157.798 +    }
 157.799 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, int>(
 157.800 +                                      SigC::slot(*this, &Window::vOnJoypadToggled),
 157.801 +                                      poCMI, i));
 157.802 +  }
 157.803 +
 157.804 +  // Autofire menu
 157.805 +  //
 157.806 +  struct
 157.807 +  {
 157.808 +    const char *   m_csName;
 157.809 +    const char *   m_csKey;
 157.810 +    const EKeyFlag m_eKeyFlag;
 157.811 +  }
 157.812 +  astAutofire[] =
 157.813 +  {
 157.814 +    { "AutofireA", "autofire_A", KeyFlagA },
 157.815 +    { "AutofireB", "autofire_B", KeyFlagB },
 157.816 +    { "AutofireL", "autofire_L", KeyFlagL },
 157.817 +    { "AutofireR", "autofire_R", KeyFlagR }
 157.818 +  };
 157.819 +  for (guint i = 0; i < G_N_ELEMENTS(astAutofire); i++)
 157.820 +  {
 157.821 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astAutofire[i].m_csName));
 157.822 +    poCMI->set_active(m_poInputConfig->oGetKey<bool>(astAutofire[i].m_csKey));
 157.823 +    vOnAutofireToggled(poCMI, astAutofire[i].m_eKeyFlag);
 157.824 +    poCMI->signal_toggled().connect(SigC::bind<Gtk::CheckMenuItem *, u32>(
 157.825 +                                      SigC::slot(*this, &Window::vOnAutofireToggled),
 157.826 +                                      poCMI, astAutofire[i].m_eKeyFlag));
 157.827 +  }
 157.828 +
 157.829 +  // GDB menu
 157.830 +  //
 157.831 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("GdbWait"));
 157.832 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnGDBWait));
 157.833 +
 157.834 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("GdbLoadAndWait"));
 157.835 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnGDBLoadAndWait));
 157.836 +
 157.837 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("GdbBreak"));
 157.838 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnGDBBreak));
 157.839 +
 157.840 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("GdbDisconnect"));
 157.841 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnGDBDisconnect));
 157.842 +
 157.843 +  // Help menu
 157.844 +  //
 157.845 +  poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("HelpAbout"));
 157.846 +  poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnHelpAbout));
 157.847 +
 157.848 +  // Init widgets sensitivity
 157.849 +  for (std::list<Gtk::Widget *>::iterator it = m_listSensitiveWhenPlaying.begin();
 157.850 +       it != m_listSensitiveWhenPlaying.end();
 157.851 +       it++)
 157.852 +  {
 157.853 +    (*it)->set_sensitive(false);
 157.854 +  }
 157.855 +
 157.856 +  if (m_poInstance == NULL)
 157.857 +  {
 157.858 +    m_poInstance = this;
 157.859 +  }
 157.860 +  else
 157.861 +  {
 157.862 +    abort();
 157.863 +  }
 157.864 +}
 157.865 +
 157.866 +Window::~Window()
 157.867 +{
 157.868 +  vOnFileClose();
 157.869 +  vSaveHistoryToConfig();
 157.870 +  vSaveJoypadsToConfig();
 157.871 +  vSaveConfig(m_sConfigFile);
 157.872 +
 157.873 +  if (m_poFileOpenDialog != NULL)
 157.874 +  {
 157.875 +    delete m_poFileOpenDialog;
 157.876 +  }
 157.877 +
 157.878 +  if (m_poKeymap != NULL)
 157.879 +  {
 157.880 +    delete m_poKeymap;
 157.881 +  }
 157.882 +
 157.883 +  m_poInstance = NULL;
 157.884 +}
 157.885 +
 157.886 +void Window::vInitSystem()
 157.887 +{
 157.888 +#if G_BYTE_ORDER == G_LITTLE_ENDIAN
 157.889 +  systemRedShift    = 3;
 157.890 +  systemGreenShift  = 11;
 157.891 +  systemBlueShift   = 19;
 157.892 +  RGB_LOW_BITS_MASK = 0x00010101;
 157.893 +#else
 157.894 +  systemRedShift    = 27;
 157.895 +  systemGreenShift  = 19;
 157.896 +  systemBlueShift   = 11;
 157.897 +  RGB_LOW_BITS_MASK = 0x01010100;
 157.898 +#endif
 157.899 +
 157.900 +  systemColorDepth = 32;
 157.901 +  systemDebug = 0;
 157.902 +  systemVerbose = 0;
 157.903 +  systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
 157.904 +  systemFrameSkip = 0;
 157.905 +  systemSoundOn = false;
 157.906 +  soundOffFlag = true;
 157.907 +
 157.908 +  systemRenderedFrames = 0;
 157.909 +  systemFPS = 0;
 157.910 +
 157.911 +  emulating = 0;
 157.912 +  debugger = false;
 157.913 +
 157.914 +  for (int i = 0; i < 0x10000; i++)
 157.915 +  {
 157.916 +#if G_BYTE_ORDER == G_LITTLE_ENDIAN
 157.917 +    systemColorMap32[i] = (((i & 0x1f) << systemRedShift)
 157.918 +                           | (((i & 0x3e0) >> 5) << systemGreenShift)
 157.919 +                           | (((i & 0x7c00) >> 10) << systemBlueShift));
 157.920 +#else
 157.921 +    systemColorMap32[i] = (((i & 0x1f) << systemRedShift)
 157.922 +                           | (((i & 0x3e0) >> 5) << systemGreenShift)
 157.923 +                           | (((i & 0x7c00) >> 10) << systemBlueShift));
 157.924 +#endif
 157.925 +  }
 157.926 +
 157.927 +  gbFrameSkip = 0;
 157.928 +
 157.929 +  for (int i = 0; i < 24; )
 157.930 +  {
 157.931 +    systemGbPalette[i++] = (0x1f) | (0x1f << 5) | (0x1f << 10);
 157.932 +    systemGbPalette[i++] = (0x15) | (0x15 << 5) | (0x15 << 10);
 157.933 +    systemGbPalette[i++] = (0x0c) | (0x0c << 5) | (0x0c << 10);
 157.934 +    systemGbPalette[i++] = 0;
 157.935 +  }
 157.936 +
 157.937 +  Init_2xSaI(32);
 157.938 +}
 157.939 +
 157.940 +void Window::vInitSDL()
 157.941 +{
 157.942 +  static bool bDone = false;
 157.943 +
 157.944 +  if (bDone)
 157.945 +    return;
 157.946 +
 157.947 +  int iFlags = (SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
 157.948 +
 157.949 +  if (SDL_Init(iFlags) < 0)
 157.950 +  {
 157.951 +    fprintf(stderr, "Failed to init SDL: %s", SDL_GetError());
 157.952 +    abort();
 157.953 +  }
 157.954 +
 157.955 +  bDone = true;
 157.956 +}
 157.957 +
 157.958 +void Window::vInitConfig()
 157.959 +{
 157.960 +  m_oConfig.vClear();
 157.961 +
 157.962 +  // History section
 157.963 +  //
 157.964 +  m_poHistoryConfig = m_oConfig.poAddSection("History");
 157.965 +  m_poHistoryConfig->vSetKey("freeze", false );
 157.966 +  m_poHistoryConfig->vSetKey("0",      ""    );
 157.967 +  m_poHistoryConfig->vSetKey("1",      ""    );
 157.968 +  m_poHistoryConfig->vSetKey("2",      ""    );
 157.969 +  m_poHistoryConfig->vSetKey("3",      ""    );
 157.970 +  m_poHistoryConfig->vSetKey("4",      ""    );
 157.971 +  m_poHistoryConfig->vSetKey("5",      ""    );
 157.972 +  m_poHistoryConfig->vSetKey("6",      ""    );
 157.973 +  m_poHistoryConfig->vSetKey("7",      ""    );
 157.974 +  m_poHistoryConfig->vSetKey("8",      ""    );
 157.975 +  m_poHistoryConfig->vSetKey("9",      ""    );
 157.976 +
 157.977 +  // Directories section
 157.978 +  //
 157.979 +  m_poDirConfig = m_oConfig.poAddSection("Directories");
 157.980 +  m_poDirConfig->vSetKey("gb_roms",   "" );
 157.981 +  m_poDirConfig->vSetKey("gba_roms",  "" );
 157.982 +  m_poDirConfig->vSetKey("batteries", "" );
 157.983 +  m_poDirConfig->vSetKey("saves",     "" );
 157.984 +  m_poDirConfig->vSetKey("captures",  "" );
 157.985 +
 157.986 +  // Core section
 157.987 +  //
 157.988 +  m_poCoreConfig = m_oConfig.poAddSection("Core");
 157.989 +  m_poCoreConfig->vSetKey("load_game_auto",    false        );
 157.990 +  m_poCoreConfig->vSetKey("frameskip",         "auto"       );
 157.991 +  m_poCoreConfig->vSetKey("throttle",          0            );
 157.992 +  m_poCoreConfig->vSetKey("layer_bg0",         true         );
 157.993 +  m_poCoreConfig->vSetKey("layer_bg1",         true         );
 157.994 +  m_poCoreConfig->vSetKey("layer_bg2",         true         );
 157.995 +  m_poCoreConfig->vSetKey("layer_bg3",         true         );
 157.996 +  m_poCoreConfig->vSetKey("layer_obj",         true         );
 157.997 +  m_poCoreConfig->vSetKey("layer_win0",        true         );
 157.998 +  m_poCoreConfig->vSetKey("layer_win1",        true         );
 157.999 +  m_poCoreConfig->vSetKey("layer_objwin",      true         );
157.1000 +  m_poCoreConfig->vSetKey("use_bios_file",     false        );
157.1001 +  m_poCoreConfig->vSetKey("bios_file",         ""           );
157.1002 +  m_poCoreConfig->vSetKey("save_type",         SaveAuto     );
157.1003 +  m_poCoreConfig->vSetKey("flash_size",        64           );
157.1004 +  m_poCoreConfig->vSetKey("gb_border",         true         );
157.1005 +  m_poCoreConfig->vSetKey("gb_printer",        false        );
157.1006 +  m_poCoreConfig->vSetKey("emulator_type",     EmulatorAuto );
157.1007 +  m_poCoreConfig->vSetKey("screenshot_format", "png"        );
157.1008 +
157.1009 +  // Display section
157.1010 +  //
157.1011 +  m_poDisplayConfig = m_oConfig.poAddSection("Display");
157.1012 +  m_poDisplayConfig->vSetKey("scale",               1              );
157.1013 +  m_poDisplayConfig->vSetKey("show_speed",          ShowPercentage );
157.1014 +  m_poDisplayConfig->vSetKey("pause_when_inactive", true           );
157.1015 +  m_poDisplayConfig->vSetKey("filter2x",            FilterNone     );
157.1016 +  m_poDisplayConfig->vSetKey("filterIB",            FilterIBNone   );
157.1017 +#ifdef MMX
157.1018 +  m_poDisplayConfig->vSetKey("filter_disable_mmx",  false          );
157.1019 +#endif // MMX
157.1020 +
157.1021 +  // Sound section
157.1022 +  //
157.1023 +  m_poSoundConfig = m_oConfig.poAddSection("Sound");
157.1024 +  m_poSoundConfig->vSetKey("status",         "on"     );
157.1025 +  m_poSoundConfig->vSetKey("echo",           false    );
157.1026 +  m_poSoundConfig->vSetKey("low_pass",       false    );
157.1027 +  m_poSoundConfig->vSetKey("reverse_stereo", false    );
157.1028 +  m_poSoundConfig->vSetKey("channel_1",      true     );
157.1029 +  m_poSoundConfig->vSetKey("channel_2",      true     );
157.1030 +  m_poSoundConfig->vSetKey("channel_3",      true     );
157.1031 +  m_poSoundConfig->vSetKey("channel_4",      true     );
157.1032 +  m_poSoundConfig->vSetKey("channel_A",      true     );
157.1033 +  m_poSoundConfig->vSetKey("channel_B",      true     );
157.1034 +  m_poSoundConfig->vSetKey("quality",        Sound22K );
157.1035 +  m_poSoundConfig->vSetKey("volume",         Sound100 );
157.1036 +
157.1037 +  // Input section
157.1038 +  //
157.1039 +  JoypadConfig oJoypadConfig;
157.1040 +  oJoypadConfig.vSetDefault();
157.1041 +  m_poInputConfig = m_oConfig.poAddSection("Input");
157.1042 +  m_poInputConfig->vSetKey("active_joypad", m_iJoypadMin );
157.1043 +  for (int i = m_iJoypadMin; i <= m_iJoypadMax; i++)
157.1044 +  {
157.1045 +    char csPrefix[20];
157.1046 +    snprintf(csPrefix, sizeof(csPrefix), "joypad%d_", i);
157.1047 +    std::string sPrefix(csPrefix);
157.1048 +    m_poInputConfig->vSetKey(sPrefix + "up",      oJoypadConfig.m_uiUp      );
157.1049 +    m_poInputConfig->vSetKey(sPrefix + "down",    oJoypadConfig.m_uiDown    );
157.1050 +    m_poInputConfig->vSetKey(sPrefix + "left",    oJoypadConfig.m_uiLeft    );
157.1051 +    m_poInputConfig->vSetKey(sPrefix + "right",   oJoypadConfig.m_uiRight   );
157.1052 +    m_poInputConfig->vSetKey(sPrefix + "A",       oJoypadConfig.m_uiA       );
157.1053 +    m_poInputConfig->vSetKey(sPrefix + "B",       oJoypadConfig.m_uiB       );
157.1054 +    m_poInputConfig->vSetKey(sPrefix + "L",       oJoypadConfig.m_uiL       );
157.1055 +    m_poInputConfig->vSetKey(sPrefix + "R",       oJoypadConfig.m_uiR       );
157.1056 +    m_poInputConfig->vSetKey(sPrefix + "select",  oJoypadConfig.m_uiSelect  );
157.1057 +    m_poInputConfig->vSetKey(sPrefix + "start",   oJoypadConfig.m_uiStart   );
157.1058 +    m_poInputConfig->vSetKey(sPrefix + "speed",   oJoypadConfig.m_uiSpeed   );
157.1059 +    m_poInputConfig->vSetKey(sPrefix + "capture", oJoypadConfig.m_uiCapture );
157.1060 +  }
157.1061 +  m_poInputConfig->vSetKey("autofire_A", false );
157.1062 +  m_poInputConfig->vSetKey("autofire_B", false );
157.1063 +  m_poInputConfig->vSetKey("autofire_L", false );
157.1064 +  m_poInputConfig->vSetKey("autofire_R", false );
157.1065 +}
157.1066 +
157.1067 +void Window::vCheckConfig()
157.1068 +{
157.1069 +  int iValue;
157.1070 +  int iAdjusted;
157.1071 +  std::string sValue;
157.1072 +
157.1073 +  // Directories section
157.1074 +  //
157.1075 +  sValue = m_poDirConfig->sGetKey("gb_roms");
157.1076 +  if (sValue != "" && ! Glib::file_test(sValue, Glib::FILE_TEST_IS_DIR))
157.1077 +  {
157.1078 +    m_poDirConfig->vSetKey("gb_roms", "");
157.1079 +  }
157.1080 +  sValue = m_poDirConfig->sGetKey("gba_roms");
157.1081 +  if (sValue != "" && ! Glib::file_test(sValue, Glib::FILE_TEST_IS_DIR))
157.1082 +  {
157.1083 +    m_poDirConfig->vSetKey("gba_roms", "");
157.1084 +  }
157.1085 +  sValue = m_poDirConfig->sGetKey("batteries");
157.1086 +  if (sValue != "" && ! Glib::file_test(sValue, Glib::FILE_TEST_IS_DIR))
157.1087 +  {
157.1088 +    m_poDirConfig->vSetKey("batteries", "");
157.1089 +  }
157.1090 +  sValue = m_poDirConfig->sGetKey("saves");
157.1091 +  if (sValue != "" && ! Glib::file_test(sValue, Glib::FILE_TEST_IS_DIR))
157.1092 +  {
157.1093 +    m_poDirConfig->vSetKey("saves", "");
157.1094 +  }
157.1095 +  sValue = m_poDirConfig->sGetKey("captures");
157.1096 +  if (sValue != "" && ! Glib::file_test(sValue, Glib::FILE_TEST_IS_DIR))
157.1097 +  {
157.1098 +    m_poDirConfig->vSetKey("captures", "");
157.1099 +  }
157.1100 +
157.1101 +  // Core section
157.1102 +  //
157.1103 +  if (m_poCoreConfig->sGetKey("frameskip") != "auto")
157.1104 +  {
157.1105 +    iValue = m_poCoreConfig->oGetKey<int>("frameskip");
157.1106 +    iAdjusted = CLAMP(iValue, m_iFrameskipMin, m_iFrameskipMax);
157.1107 +    if (iValue != iAdjusted)
157.1108 +    {
157.1109 +      m_poCoreConfig->vSetKey("frameskip", iAdjusted);
157.1110 +    }
157.1111 +  }
157.1112 +
157.1113 +  iValue = m_poCoreConfig->oGetKey<int>("throttle");
157.1114 +  if (iValue != 0)
157.1115 +  {
157.1116 +    iAdjusted = CLAMP(iValue, m_iThrottleMin, m_iThrottleMax);
157.1117 +    if (iValue != iAdjusted)
157.1118 +    {
157.1119 +      m_poCoreConfig->vSetKey("throttle", iAdjusted);
157.1120 +    }
157.1121 +  }
157.1122 +
157.1123 +  sValue = m_poCoreConfig->sGetKey("bios_file");
157.1124 +  if (sValue != "" && ! Glib::file_test(sValue, Glib::FILE_TEST_IS_REGULAR))
157.1125 +  {
157.1126 +    m_poCoreConfig->vSetKey("bios_file", "");
157.1127 +  }
157.1128 +  if (m_poCoreConfig->sGetKey("bios_file") == "")
157.1129 +  {
157.1130 +    m_poCoreConfig->vSetKey("use_bios_file", false);
157.1131 +  }
157.1132 +
157.1133 +  iValue = m_poCoreConfig->oGetKey<int>("save_type");
157.1134 +  if (iValue != 0)
157.1135 +  {
157.1136 +    iAdjusted = CLAMP(iValue, m_iSaveTypeMin, m_iSaveTypeMax);
157.1137 +    if (iValue != iAdjusted)
157.1138 +    {
157.1139 +      m_poCoreConfig->vSetKey("save_type", iAdjusted);
157.1140 +    }
157.1141 +  }
157.1142 +
157.1143 +  iValue = m_poCoreConfig->oGetKey<int>("flash_size");
157.1144 +  if (iValue != 64 && iValue != 128)
157.1145 +  {
157.1146 +    m_poCoreConfig->vSetKey("flash_size", 64);
157.1147 +  }
157.1148 +
157.1149 +  iValue = m_poCoreConfig->oGetKey<int>("emulator_type");
157.1150 +  iAdjusted = CLAMP(iValue, m_iEmulatorTypeMin, m_iEmulatorTypeMax);
157.1151 +  if (iValue != iAdjusted)
157.1152 +  {
157.1153 +    m_poCoreConfig->vSetKey("emulator_type", iAdjusted);
157.1154 +  }
157.1155 +
157.1156 +  sValue = m_poCoreConfig->sGetKey("screenshot_format");
157.1157 +  if (sValue != "png" && sValue != "bmp")
157.1158 +  {
157.1159 +    sValue = "png";
157.1160 +  }
157.1161 +
157.1162 +  // Display section
157.1163 +  //
157.1164 +  iValue = m_poDisplayConfig->oGetKey<int>("scale");
157.1165 +  iAdjusted = CLAMP(iValue, m_iScaleMin, m_iScaleMax);
157.1166 +  if (iValue != iAdjusted)
157.1167 +  {
157.1168 +    m_poDisplayConfig->vSetKey("scale", iAdjusted);
157.1169 +  }
157.1170 +
157.1171 +  iValue = m_poDisplayConfig->oGetKey<int>("show_speed");
157.1172 +  iAdjusted = CLAMP(iValue, m_iShowSpeedMin, m_iShowSpeedMax);
157.1173 +  if (iValue != iAdjusted)
157.1174 +  {
157.1175 +    m_poDisplayConfig->vSetKey("show_speed", iAdjusted);
157.1176 +  }
157.1177 +
157.1178 +  iValue = m_poDisplayConfig->oGetKey<int>("filter2x");
157.1179 +  iAdjusted = CLAMP(iValue, m_iFilter2xMin, m_iFilter2xMax);
157.1180 +  if (iValue != iAdjusted)
157.1181 +  {
157.1182 +    m_poDisplayConfig->vSetKey("filter2x", iAdjusted);
157.1183 +  }
157.1184 +
157.1185 +  iValue = m_poDisplayConfig->oGetKey<int>("filterIB");
157.1186 +  iAdjusted = CLAMP(iValue, m_iFilterIBMin, m_iFilterIBMax);
157.1187 +  if (iValue != iAdjusted)
157.1188 +  {
157.1189 +    m_poDisplayConfig->vSetKey("filterIB", iAdjusted);
157.1190 +  }
157.1191 +
157.1192 +  // Sound section
157.1193 +  //
157.1194 +  sValue = m_poSoundConfig->sGetKey("status");
157.1195 +  if (sValue != "off" && sValue != "on" && sValue != "mute")
157.1196 +  {
157.1197 +    m_poSoundConfig->vSetKey("status", "on");
157.1198 +  }
157.1199 +
157.1200 +  iValue = m_poSoundConfig->oGetKey<int>("quality");
157.1201 +  iAdjusted = CLAMP(iValue, m_iSoundQualityMin, m_iSoundQualityMax);
157.1202 +  if (iValue != iAdjusted)
157.1203 +  {
157.1204 +    m_poSoundConfig->vSetKey("quality", iAdjusted);
157.1205 +  }
157.1206 +
157.1207 +  iValue = m_poSoundConfig->oGetKey<int>("volume");
157.1208 +  iAdjusted = CLAMP(iValue, m_iSoundVolumeMin, m_iSoundVolumeMax);
157.1209 +  if (iValue != iAdjusted)
157.1210 +  {
157.1211 +    m_poSoundConfig->vSetKey("volume", iAdjusted);
157.1212 +  }
157.1213 +
157.1214 +  // Input section
157.1215 +  //
157.1216 +  iValue = m_poInputConfig->oGetKey<int>("active_joypad");
157.1217 +  iAdjusted = CLAMP(iValue, m_iJoypadMin, m_iJoypadMax);
157.1218 +  if (iValue != iAdjusted)
157.1219 +  {
157.1220 +    m_poInputConfig->vSetKey("active_joypad", iAdjusted);
157.1221 +  }
157.1222 +}
157.1223 +
157.1224 +void Window::vLoadConfig(const std::string & _rsFile)
157.1225 +{
157.1226 +  try
157.1227 +  {
157.1228 +    m_oConfig.vLoad(_rsFile, false, false);
157.1229 +  }
157.1230 +  catch (const Glib::Error & e)
157.1231 +  {
157.1232 +    vPopupError(e.what().c_str());
157.1233 +  }
157.1234 +}
157.1235 +
157.1236 +void Window::vSaveConfig(const std::string & _rsFile)
157.1237 +{
157.1238 +  try
157.1239 +  {
157.1240 +    m_oConfig.vSave(_rsFile);
157.1241 +  }
157.1242 +  catch (const Glib::Error & e)
157.1243 +  {
157.1244 +    vPopupError(e.what().c_str());
157.1245 +  }
157.1246 +}
157.1247 +
157.1248 +void Window::vLoadHistoryFromConfig()
157.1249 +{
157.1250 +  char csKey[] = "0";
157.1251 +  for (int i = 0; i < 10; i++, csKey[0]++)
157.1252 +  {
157.1253 +    std::string sFile = m_poHistoryConfig->sGetKey(csKey);
157.1254 +    if (sFile == "")
157.1255 +    {
157.1256 +      break;
157.1257 +    }
157.1258 +    m_listHistory.push_back(sFile);
157.1259 +  }
157.1260 +}
157.1261 +
157.1262 +void Window::vSaveHistoryToConfig()
157.1263 +{
157.1264 +  char csKey[] = "0";
157.1265 +  for (std::list<std::string>::const_iterator it = m_listHistory.begin();
157.1266 +       it != m_listHistory.end();
157.1267 +       it++, csKey[0]++)
157.1268 +  {
157.1269 +    m_poHistoryConfig->vSetKey(csKey, *it);
157.1270 +  }
157.1271 +}
157.1272 +
157.1273 +void Window::vHistoryAdd(const std::string & _rsFile)
157.1274 +{
157.1275 +  if (m_poHistoryConfig->oGetKey<bool>("freeze"))
157.1276 +  {
157.1277 +    return;
157.1278 +  }
157.1279 +
157.1280 +  m_listHistory.remove(_rsFile);
157.1281 +  m_listHistory.push_front(_rsFile);
157.1282 +  if (m_listHistory.size() > 10)
157.1283 +  {
157.1284 +    m_listHistory.pop_back();
157.1285 +  }
157.1286 +
157.1287 +  vUpdateHistoryMenu();
157.1288 +}
157.1289 +
157.1290 +void Window::vClearHistoryMenu()
157.1291 +{
157.1292 +  Gtk::Menu_Helpers::MenuList::iterator it = m_poRecentMenu->items().begin();
157.1293 +  for (int i = 0; i < 3; i++, it++)
157.1294 +    ;
157.1295 +
157.1296 +  m_poRecentMenu->items().erase(it, m_poRecentMenu->items().end());
157.1297 +}
157.1298 +
157.1299 +void Window::vUpdateHistoryMenu()
157.1300 +{
157.1301 +  vClearHistoryMenu();
157.1302 +
157.1303 +  guint uiAccelKey = GDK_F1;
157.1304 +  for (std::list<std::string>::const_iterator it = m_listHistory.begin();
157.1305 +       it != m_listHistory.end();
157.1306 +       it++, uiAccelKey++)
157.1307 +  {
157.1308 +    Gtk::Image * poImage = Gtk::manage(new Gtk::Image(Gtk::Stock::OPEN, Gtk::ICON_SIZE_MENU));
157.1309 +    Glib::ustring sLabel = Glib::path_get_basename(*it);
157.1310 +    VBA::ImageMenuItem * poIMI = Gtk::manage(new VBA::ImageMenuItem(*poImage, sLabel));
157.1311 +
157.1312 +    m_oTooltips.set_tip(*poIMI, *it);
157.1313 +
157.1314 +    poIMI->signal_activate().connect(SigC::bind<std::string>(
157.1315 +                                      SigC::slot(*this, &Window::vOnRecentFile),
157.1316 +                                      *it));
157.1317 +
157.1318 +    poIMI->set_accel_key(Gtk::AccelKey(uiAccelKey, Gdk::CONTROL_MASK));
157.1319 +    poIMI->accelerate(*this);
157.1320 +
157.1321 +    poIMI->show();
157.1322 +    m_poRecentMenu->items().push_back(*poIMI);
157.1323 +  }
157.1324 +}
157.1325 +
157.1326 +void Window::vLoadJoypadsFromConfig()
157.1327 +{
157.1328 +  m_oJoypads.clear();
157.1329 +
157.1330 +  for (int i = m_iJoypadMin; i <= m_iJoypadMax; i++)
157.1331 +  {
157.1332 +    char csPrefix[20];
157.1333 +    snprintf(csPrefix, sizeof(csPrefix), "joypad%d_", i);
157.1334 +    std::string sPrefix(csPrefix);
157.1335 +
157.1336 +    JoypadConfig oJoypadConfig;
157.1337 +    oJoypadConfig.m_uiUp      = m_poInputConfig->oGetKey<guint>(sPrefix + "up");
157.1338 +    oJoypadConfig.m_uiDown    = m_poInputConfig->oGetKey<guint>(sPrefix + "down");
157.1339 +    oJoypadConfig.m_uiLeft    = m_poInputConfig->oGetKey<guint>(sPrefix + "left");
157.1340 +    oJoypadConfig.m_uiRight   = m_poInputConfig->oGetKey<guint>(sPrefix + "right");
157.1341 +    oJoypadConfig.m_uiA       = m_poInputConfig->oGetKey<guint>(sPrefix + "A");
157.1342 +    oJoypadConfig.m_uiB       = m_poInputConfig->oGetKey<guint>(sPrefix + "B");
157.1343 +    oJoypadConfig.m_uiL       = m_poInputConfig->oGetKey<guint>(sPrefix + "L");
157.1344 +    oJoypadConfig.m_uiR       = m_poInputConfig->oGetKey<guint>(sPrefix + "R");
157.1345 +    oJoypadConfig.m_uiSelect  = m_poInputConfig->oGetKey<guint>(sPrefix + "select");
157.1346 +    oJoypadConfig.m_uiStart   = m_poInputConfig->oGetKey<guint>(sPrefix + "start");
157.1347 +    oJoypadConfig.m_uiSpeed   = m_poInputConfig->oGetKey<guint>(sPrefix + "speed");
157.1348 +    oJoypadConfig.m_uiCapture = m_poInputConfig->oGetKey<guint>(sPrefix + "capture");
157.1349 +
157.1350 +    m_oJoypads.push_back(oJoypadConfig);
157.1351 +  }
157.1352 +}
157.1353 +
157.1354 +void Window::vSaveJoypadsToConfig()
157.1355 +{
157.1356 +  for (int i = m_iJoypadMin; i <= m_iJoypadMax; i++)
157.1357 +  {
157.1358 +    char csPrefix[20];
157.1359 +    snprintf(csPrefix, sizeof(csPrefix), "joypad%d_", i);
157.1360 +    std::string sPrefix(csPrefix);
157.1361 +
157.1362 +    m_poInputConfig->vSetKey(sPrefix + "up",      m_oJoypads[i - 1].m_uiUp      );
157.1363 +    m_poInputConfig->vSetKey(sPrefix + "down",    m_oJoypads[i - 1].m_uiDown    );
157.1364 +    m_poInputConfig->vSetKey(sPrefix + "left",    m_oJoypads[i - 1].m_uiLeft    );
157.1365 +    m_poInputConfig->vSetKey(sPrefix + "right",   m_oJoypads[i - 1].m_uiRight   );
157.1366 +    m_poInputConfig->vSetKey(sPrefix + "A",       m_oJoypads[i - 1].m_uiA       );
157.1367 +    m_poInputConfig->vSetKey(sPrefix + "B",       m_oJoypads[i - 1].m_uiB       );
157.1368 +    m_poInputConfig->vSetKey(sPrefix + "L",       m_oJoypads[i - 1].m_uiL       );
157.1369 +    m_poInputConfig->vSetKey(sPrefix + "R",       m_oJoypads[i - 1].m_uiR       );
157.1370 +    m_poInputConfig->vSetKey(sPrefix + "select",  m_oJoypads[i - 1].m_uiSelect  );
157.1371 +    m_poInputConfig->vSetKey(sPrefix + "start",   m_oJoypads[i - 1].m_uiStart   );
157.1372 +    m_poInputConfig->vSetKey(sPrefix + "speed",   m_oJoypads[i - 1].m_uiSpeed   );
157.1373 +    m_poInputConfig->vSetKey(sPrefix + "capture", m_oJoypads[i - 1].m_uiCapture );
157.1374 +  }
157.1375 +}
157.1376 +
157.1377 +void Window::vUpdateScreen()
157.1378 +{
157.1379 +  if (m_eCartridge == CartridgeGB)
157.1380 +  {
157.1381 +    if (gbBorderOn)
157.1382 +    {
157.1383 +      m_iScreenWidth     = m_iSGBScreenWidth;
157.1384 +      m_iScreenHeight    = m_iSGBScreenHeight;
157.1385 +      gbBorderLineSkip   = m_iSGBScreenWidth;
157.1386 +      gbBorderColumnSkip = (m_iSGBScreenWidth - m_iGBScreenWidth) / 2;
157.1387 +      gbBorderRowSkip    = (m_iSGBScreenHeight - m_iGBScreenHeight) / 2;
157.1388 +    }
157.1389 +    else
157.1390 +    {
157.1391 +      m_iScreenWidth     = m_iGBScreenWidth;
157.1392 +      m_iScreenHeight    = m_iGBScreenHeight;
157.1393 +      gbBorderLineSkip   = m_iGBScreenWidth;
157.1394 +      gbBorderColumnSkip = 0;
157.1395 +      gbBorderRowSkip    = 0;
157.1396 +    }
157.1397 +  }
157.1398 +  else if (m_eCartridge == CartridgeGBA)
157.1399 +  {
157.1400 +    m_iScreenWidth  = m_iGBAScreenWidth;
157.1401 +    m_iScreenHeight = m_iGBAScreenHeight;
157.1402 +  }
157.1403 +
157.1404 +  g_return_if_fail(m_iScreenWidth >= 1 && m_iScreenHeight >= 1);
157.1405 +
157.1406 +  m_poScreenArea->vSetSize(m_iScreenWidth, m_iScreenHeight);
157.1407 +  m_poScreenArea->vSetScale(m_poDisplayConfig->oGetKey<int>("scale"));
157.1408 +
157.1409 +  resize(1, 1);
157.1410 +
157.1411 +  if (emulating)
157.1412 +  {
157.1413 +    vDrawScreen();
157.1414 +  }
157.1415 +  else
157.1416 +  {
157.1417 +    vDrawDefaultScreen();
157.1418 +  }
157.1419 +}
157.1420 +
157.1421 +bool Window::bLoadROM(const std::string & _rsFile)
157.1422 +{
157.1423 +  vOnFileClose();
157.1424 +
157.1425 +  m_sRomFile = _rsFile;
157.1426 +  const char * csFile = _rsFile.c_str();
157.1427 +
157.1428 +  IMAGE_TYPE eType = utilFindType(csFile);
157.1429 +  if (eType == IMAGE_UNKNOWN)
157.1430 +  {
157.1431 +    vPopupError(_("Unknown file type %s"), csFile);
157.1432 +    return false;
157.1433 +  }
157.1434 +
157.1435 +  bool bLoaded = false;
157.1436 +  if (eType == IMAGE_GB)
157.1437 +  {
157.1438 +    bLoaded = gbLoadRom(csFile);
157.1439 +    if (bLoaded)
157.1440 +    {
157.1441 +      m_eCartridge = CartridgeGB;
157.1442 +      m_stEmulator = GBSystem;
157.1443 +    }
157.1444 +  }
157.1445 +  else if (eType == IMAGE_GBA)
157.1446 +  {
157.1447 +    int iSize = CPULoadRom(csFile);
157.1448 +    bLoaded = (iSize > 0);
157.1449 +    if (bLoaded)
157.1450 +    {
157.1451 +      m_eCartridge = CartridgeGBA;
157.1452 +      m_stEmulator = GBASystem;
157.1453 +
157.1454 +      useBios = m_poCoreConfig->oGetKey<bool>("use_bios_file");
157.1455 +      //CPUInit(m_poCoreConfig->sGetKey("bios_file").c_str(), useBios);
157.1456 +      CPUInit();
157.1457 +      CPUReset();
157.1458 +
157.1459 +      // If the bios file was rejected by CPUInit
157.1460 +      if (m_poCoreConfig->oGetKey<bool>("use_bios_file") && ! useBios)
157.1461 +      {
157.1462 +        m_poUseBiosItem->set_active(false);
157.1463 +        m_poUseBiosItem->set_sensitive(false);
157.1464 +        m_poCoreConfig->vSetKey("bios_file", "");
157.1465 +      }
157.1466 +    }
157.1467 +  }
157.1468 +
157.1469 +  if (! bLoaded)
157.1470 +  {
157.1471 +    return false;
157.1472 +  }
157.1473 +
157.1474 +  vLoadBattery();
157.1475 +  vUpdateScreen();
157.1476 +
157.1477 +  debugger = false; // May cause conflicts
157.1478 +  emulating = 1;
157.1479 +  m_bWasEmulating = false;
157.1480 +  m_uiThrottleDelay = 0;
157.1481 +
157.1482 +  if (m_eCartridge == CartridgeGBA)
157.1483 +  {
157.1484 +    soundSetQuality(m_eSoundQuality);
157.1485 +  }
157.1486 +  else
157.1487 +  {
157.1488 +    gbSoundSetQuality(m_eSoundQuality);
157.1489 +  }
157.1490 +
157.1491 +  vUpdateGameSlots();
157.1492 +  vHistoryAdd(_rsFile);
157.1493 +
157.1494 +  for (std::list<Gtk::Widget *>::iterator it = m_listSensitiveWhenPlaying.begin();
157.1495 +       it != m_listSensitiveWhenPlaying.end();
157.1496 +       it++)
157.1497 +  {
157.1498 +    (*it)->set_sensitive();
157.1499 +  }
157.1500 +
157.1501 +  if (m_poCoreConfig->oGetKey<bool>("load_game_auto"))
157.1502 +  {
157.1503 +    vOnLoadGameMostRecent();
157.1504 +  }
157.1505 +
157.1506 +  vStartEmu();
157.1507 +
157.1508 +  return true;
157.1509 +}
157.1510 +
157.1511 +void Window::vPopupError(const char * _csFormat, ...)
157.1512 +{
157.1513 +  va_list args;
157.1514 +  va_start(args, _csFormat);
157.1515 +  char * csMsg = g_strdup_vprintf(_csFormat, args);
157.1516 +  va_end(args);
157.1517 +
157.1518 +  Gtk::MessageDialog oDialog(*this,
157.1519 +                             csMsg,
157.1520 +#ifndef GTKMM20
157.1521 +                             false,
157.1522 +#endif // ! GTKMM20
157.1523 +                             Gtk::MESSAGE_ERROR,
157.1524 +                             Gtk::BUTTONS_OK);
157.1525 +  oDialog.run();
157.1526 +  g_free(csMsg);
157.1527 +}
157.1528 +
157.1529 +void Window::vPopupErrorV(const char * _csFormat, va_list _args)
157.1530 +{
157.1531 +  char * csMsg = g_strdup_vprintf(_csFormat, _args);
157.1532 +
157.1533 +  Gtk::MessageDialog oDialog(*this,
157.1534 +                             csMsg,
157.1535 +#ifndef GTKMM20
157.1536 +                             false,
157.1537 +#endif // ! GTKMM20
157.1538 +                             Gtk::MESSAGE_ERROR,
157.1539 +                             Gtk::BUTTONS_OK);
157.1540 +  oDialog.run();
157.1541 +  g_free(csMsg);
157.1542 +}
157.1543 +
157.1544 +void Window::vDrawScreen()
157.1545 +{
157.1546 +  m_poScreenArea->vDrawPixels(pix);
157.1547 +}
157.1548 +
157.1549 +void Window::vDrawDefaultScreen()
157.1550 +{
157.1551 +  m_poScreenArea->vDrawColor(0x000000); // Black
157.1552 +}
157.1553 +
157.1554 +void Window::vSetDefaultTitle()
157.1555 +{
157.1556 +  set_title("VBA");
157.1557 +}
157.1558 +
157.1559 +void Window::vShowSpeed(int _iSpeed)
157.1560 +{
157.1561 +  char csTitle[50];
157.1562 +
157.1563 +  if (m_eShowSpeed == ShowPercentage)
157.1564 +  {
157.1565 +    snprintf(csTitle, 50, "VBA - %d%%", _iSpeed);
157.1566 +    set_title(csTitle);
157.1567 +  }
157.1568 +  else if (m_eShowSpeed == ShowDetailed)
157.1569 +  {
157.1570 +    snprintf(csTitle, 50, "VBA - %d%% (%d, %d fps)",
157.1571 +             _iSpeed, systemFrameSkip, systemFPS);
157.1572 +    set_title(csTitle);
157.1573 +  }
157.1574 +}
157.1575 +
157.1576 +void Window::vComputeFrameskip(int _iRate)
157.1577 +{
157.1578 +  static u32 uiLastTime = 0;
157.1579 +  static int iFrameskipAdjust = 0;
157.1580 +
157.1581 +  u32 uiTime = SDL_GetTicks();
157.1582 +
157.1583 +  if (m_bWasEmulating)
157.1584 +  {
157.1585 +    int iWantedSpeed = 100;
157.1586 +
157.1587 +    if (m_iThrottle > 0)
157.1588 +    {
157.1589 +      if (! speedup)
157.1590 +      {
157.1591 +        u32 uiDiff  = uiTime - m_uiThrottleLastTime;
157.1592 +        int iTarget = 1000000 / (_iRate * m_iThrottle);
157.1593 +        int iDelay  = iTarget - uiDiff;
157.1594 +        if (iDelay > 0)
157.1595 +        {
157.1596 +          m_uiThrottleDelay = iDelay;
157.1597 +        }
157.1598 +      }
157.1599 +      iWantedSpeed = m_iThrottle;
157.1600 +    }
157.1601 +
157.1602 +    if (m_bAutoFrameskip)
157.1603 +    {
157.1604 +      u32 uiDiff = uiTime - uiLastTime;
157.1605 +      int iSpeed = iWantedSpeed;
157.1606 +
157.1607 +      if (uiDiff != 0)
157.1608 +      {
157.1609 +        iSpeed = (1000000 / _iRate) / uiDiff;
157.1610 +      }
157.1611 +
157.1612 +      if (iSpeed >= iWantedSpeed - 2)
157.1613 +      {
157.1614 +        iFrameskipAdjust++;
157.1615 +        if (iFrameskipAdjust >= 3)
157.1616 +        {
157.1617 +          iFrameskipAdjust = 0;
157.1618 +          if (systemFrameSkip > 0)
157.1619 +          {
157.1620 +            systemFrameSkip--;
157.1621 +          }
157.1622 +        }
157.1623 +      }
157.1624 +      else
157.1625 +      {
157.1626 +        if (iSpeed < iWantedSpeed - 20)
157.1627 +        {
157.1628 +          iFrameskipAdjust -= ((iWantedSpeed - 10) - iSpeed) / 5;
157.1629 +        }
157.1630 +        else if (systemFrameSkip < 9)
157.1631 +        {
157.1632 +          iFrameskipAdjust--;
157.1633 +        }
157.1634 +
157.1635 +        if (iFrameskipAdjust <= -2)
157.1636 +        {
157.1637 +          iFrameskipAdjust += 2;
157.1638 +          if (systemFrameSkip < 9)
157.1639 +          {
157.1640 +            systemFrameSkip++;
157.1641 +          }
157.1642 +        }
157.1643 +      }
157.1644 +    }
157.1645 +  }
157.1646 +  else
157.1647 +  {
157.1648 +    m_bWasEmulating = true;
157.1649 +  }
157.1650 +
157.1651 +  uiLastTime = uiTime;
157.1652 +  m_uiThrottleLastTime = uiTime;
157.1653 +}
157.1654 +
157.1655 +void Window::vCaptureScreen(int _iNum)
157.1656 +{
157.1657 +  std::string sBaseName;
157.1658 +  std::string sCaptureDir = m_poDirConfig->sGetKey("captures");
157.1659 +  if (sCaptureDir == "")
157.1660 +  {
157.1661 +    sBaseName = sCutSuffix(m_sRomFile);
157.1662 +  }
157.1663 +  else
157.1664 +  {
157.1665 +    sBaseName = sCaptureDir + "/" + sCutSuffix(Glib::path_get_basename(m_sRomFile));
157.1666 +  }
157.1667 +  std::string sFormat = m_poCoreConfig->sGetKey("screenshot_format");
157.1668 +
157.1669 +  char * csFile = g_strdup_printf("%s_%02d.%s",
157.1670 +                                  sBaseName.c_str(),
157.1671 +                                  _iNum,
157.1672 +                                  sFormat.c_str());
157.1673 +  if (sFormat == "png")
157.1674 +  {
157.1675 +    m_stEmulator.emuWritePNG(csFile);
157.1676 +  }
157.1677 +  else
157.1678 +  {
157.1679 +    m_stEmulator.emuWriteBMP(csFile);
157.1680 +  }
157.1681 +  g_free(csFile);
157.1682 +}
157.1683 +
157.1684 +u32 Window::uiReadJoypad()
157.1685 +{
157.1686 +  u32 uiJoypad = m_uiJoypadState;
157.1687 +
157.1688 +  if (m_uiAutofireState != 0)
157.1689 +  {
157.1690 +    uiJoypad &= ~m_uiAutofireState;
157.1691 +    if (m_bAutofireToggle)
157.1692 +    {
157.1693 +      uiJoypad |= m_uiAutofireState;
157.1694 +    }
157.1695 +    m_bAutofireToggle = ! m_bAutofireToggle;
157.1696 +  }
157.1697 +
157.1698 +  return uiJoypad;
157.1699 +}
157.1700 +
157.1701 +void Window::vCreateFileOpenDialog()
157.1702 +{
157.1703 +  if (m_poFileOpenDialog != NULL)
157.1704 +  {
157.1705 +    return;
157.1706 +  }
157.1707 +
157.1708 +  std::string sGBDir  = m_poDirConfig->sGetKey("gb_roms");
157.1709 +  std::string sGBADir = m_poDirConfig->sGetKey("gba_roms");
157.1710 +
157.1711 +#ifdef GTKMM20
157.1712 +
157.1713 +  Gtk::FileSelection * poDialog = new Gtk::FileSelection(_("Open"));
157.1714 +  poDialog->set_transient_for(*this);
157.1715 +
157.1716 +  if (sGBADir != "")
157.1717 +  {
157.1718 +    poDialog->set_filename(sGBADir + "/");
157.1719 +  }
157.1720 +  else if (sGBDir != "")
157.1721 +  {
157.1722 +    poDialog->set_filename(sGBDir + "/");
157.1723 +  }
157.1724 +
157.1725 +#else // ! GTKMM20
157.1726 +
157.1727 +  Gtk::FileChooserDialog * poDialog = new Gtk::FileChooserDialog(*this, _("Open"));
157.1728 +  poDialog->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
157.1729 +  poDialog->add_button(Gtk::Stock::OPEN,   Gtk::RESPONSE_OK);
157.1730 +
157.1731 +  if (sGBDir != "")
157.1732 +  {
157.1733 +    poDialog->add_shortcut_folder(sGBDir);
157.1734 +    poDialog->set_current_folder(sGBDir);
157.1735 +  }
157.1736 +
157.1737 +  if (sGBADir != "" && sGBADir != sGBDir)
157.1738 +  {
157.1739 +    poDialog->add_shortcut_folder(sGBADir);
157.1740 +    poDialog->set_current_folder(sGBADir);
157.1741 +  }
157.1742 +
157.1743 +  const char * acsPattern[] =
157.1744 +  {
157.1745 +    // GBA
157.1746 +    "*.[bB][iI][nN]", "*.[aA][gG][bB]", "*.[gG][bB][aA]",
157.1747 +    // GB
157.1748 +    "*.[gG][bB]", "*.[sS][gG][bB]", "*.[cC][gG][bB]", "*.[gG][bB][cC]",
157.1749 +    // Both
157.1750 +    "*.[mM][bB]", "*.[eE][lL][fF]", "*.[zZ][iI][pP]", "*.[zZ]", "*.[gG][zZ]"
157.1751 +  };
157.1752 +
157.1753 +  Gtk::FileFilter oAllGBAFilter;
157.1754 +  oAllGBAFilter.set_name(_("All Gameboy Advance files"));
157.1755 +  for (guint i = 0; i < G_N_ELEMENTS(acsPattern); i++)
157.1756 +  {
157.1757 +    oAllGBAFilter.add_pattern(acsPattern[i]);
157.1758 +  }
157.1759 +
157.1760 +  Gtk::FileFilter oGBAFilter;
157.1761 +  oGBAFilter.set_name(_("Gameboy Advance files"));
157.1762 +  for (int i = 0; i < 3; i++)
157.1763 +  {
157.1764 +    oGBAFilter.add_pattern(acsPattern[i]);
157.1765 +  }
157.1766 +
157.1767 +  Gtk::FileFilter oGBFilter;
157.1768 +  oGBFilter.set_name(_("Gameboy files"));
157.1769 +  for (int i = 3; i < 7; i++)
157.1770 +  {
157.1771 +    oGBFilter.add_pattern(acsPattern[i]);
157.1772 +  }
157.1773 +
157.1774 +  poDialog->add_filter(oAllGBAFilter);
157.1775 +  poDialog->add_filter(oGBAFilter);
157.1776 +  poDialog->add_filter(oGBFilter);
157.1777 +
157.1778 +#endif // ! GTKMM20
157.1779 +
157.1780 +  m_poFileOpenDialog = poDialog;
157.1781 +}
157.1782 +
157.1783 +void Window::vLoadBattery()
157.1784 +{
157.1785 +  std::string sBattery;
157.1786 +  std::string sDir = m_poDirConfig->sGetKey("batteries");
157.1787 +  if (sDir == "")
157.1788 +  {
157.1789 +    sBattery = sCutSuffix(m_sRomFile) + ".sav";
157.1790 +  }
157.1791 +  else
157.1792 +  {
157.1793 +    sBattery = sDir + "/" + sCutSuffix(Glib::path_get_basename(m_sRomFile)) + ".sav";
157.1794 +  }
157.1795 +
157.1796 +  if (m_stEmulator.emuReadBattery(sBattery.c_str()))
157.1797 +  {
157.1798 +    systemScreenMessage(_("Loaded battery"));
157.1799 +  }
157.1800 +}
157.1801 +
157.1802 +void Window::vSaveBattery()
157.1803 +{
157.1804 +  std::string sBattery;
157.1805 +  std::string sDir = m_poDirConfig->sGetKey("batteries");
157.1806 +  if (sDir == "")
157.1807 +  {
157.1808 +    sBattery = sCutSuffix(m_sRomFile) + ".sav";
157.1809 +  }
157.1810 +  else
157.1811 +  {
157.1812 +    sBattery = sDir + "/" + sCutSuffix(Glib::path_get_basename(m_sRomFile)) + ".sav";
157.1813 +  }
157.1814 +
157.1815 +  if (m_stEmulator.emuWriteBattery(sBattery.c_str()))
157.1816 +  {
157.1817 +    systemScreenMessage(_("Saved battery"));
157.1818 +  }
157.1819 +}
157.1820 +
157.1821 +void Window::vStartEmu()
157.1822 +{
157.1823 +  if (m_oEmuSig.connected())
157.1824 +  {
157.1825 +    return;
157.1826 +  }
157.1827 +
157.1828 +  m_oEmuSig = Glib::signal_idle().connect(SigC::slot(*this, &Window::bOnEmuIdle),
157.1829 +                                          Glib::PRIORITY_DEFAULT_IDLE);
157.1830 +}
157.1831 +
157.1832 +void Window::vStopEmu()
157.1833 +{
157.1834 +  m_oEmuSig.disconnect();
157.1835 +  m_bWasEmulating = false;
157.1836 +}
157.1837 +
157.1838 +void Window::vSetThrottle(int _iPercent)
157.1839 +{
157.1840 +  m_iThrottle = _iPercent;
157.1841 +  m_poCoreConfig->vSetKey("throttle", _iPercent);
157.1842 +}
157.1843 +
157.1844 +void Window::vSelectBestThrottleItem()
157.1845 +{
157.1846 +  struct
157.1847 +  {
157.1848 +    const char * m_csName;
157.1849 +    const int    m_iThrottle;
157.1850 +  }
157.1851 +  astThrottle[] =
157.1852 +  {
157.1853 +    { "ThrottleNoThrottle",   0 },
157.1854 +    { "Throttle25",          25 },
157.1855 +    { "Throttle50",          50 },
157.1856 +    { "Throttle100",        100 },
157.1857 +    { "Throttle150",        150 },
157.1858 +    { "Throttle200",        200 }
157.1859 +  };
157.1860 +  for (guint i = 0; i < G_N_ELEMENTS(astThrottle); i++)
157.1861 +  {
157.1862 +    Gtk::CheckMenuItem * poCMI;
157.1863 +    poCMI = dynamic_cast<Gtk::CheckMenuItem *>(m_poXml->get_widget(astThrottle[i].m_csName));
157.1864 +    if (astThrottle[i].m_iThrottle == m_iThrottle)
157.1865 +    {
157.1866 +      poCMI->set_active();
157.1867 +    }
157.1868 +  }
157.1869 +}
157.1870 +
157.1871 +void Window::vUpdateGameSlots()
157.1872 +{
157.1873 +  if (m_eCartridge == CartridgeNone)
157.1874 +  {
157.1875 +    std::string sDateTime = _("----/--/-- --:--:--");
157.1876 +
157.1877 +    for (int i = 0; i < 10; i++)
157.1878 +    {
157.1879 +      char csPrefix[10];
157.1880 +      snprintf(csPrefix, sizeof(csPrefix), "%2d ", i + 1);
157.1881 +
157.1882 +      Gtk::Label * poLabel;
157.1883 +      poLabel = dynamic_cast<Gtk::Label *>(m_apoLoadGameItem[i]->get_child());
157.1884 +      poLabel->set_text(csPrefix + sDateTime);
157.1885 +      m_apoLoadGameItem[i]->set_sensitive(false);
157.1886 +
157.1887 +      poLabel = dynamic_cast<Gtk::Label *>(m_apoSaveGameItem[i]->get_child());
157.1888 +      poLabel->set_text(csPrefix + sDateTime);
157.1889 +      m_apoSaveGameItem[i]->set_sensitive(false);
157.1890 +
157.1891 +      m_astGameSlot[i].m_bEmpty = true;
157.1892 +    }
157.1893 +  }
157.1894 +  else
157.1895 +  {
157.1896 +    std::string sFileBase;
157.1897 +    std::string sDir = m_poDirConfig->sGetKey("saves");
157.1898 +    if (sDir == "")
157.1899 +    {
157.1900 +      sFileBase = sCutSuffix(m_sRomFile);
157.1901 +    }
157.1902 +    else
157.1903 +    {
157.1904 +      sFileBase = sDir + "/" + sCutSuffix(Glib::path_get_basename(m_sRomFile));
157.1905 +    }
157.1906 +
157.1907 +    const char * csDateFormat = _("%Y/%m/%d %H:%M:%S");
157.1908 +
157.1909 +    for (int i = 0; i < 10; i++)
157.1910 +    {
157.1911 +      char csPrefix[10];
157.1912 +      snprintf(csPrefix, sizeof(csPrefix), "%2d ", i + 1);
157.1913 +
157.1914 +      char csSlot[10];
157.1915 +      snprintf(csSlot, sizeof(csSlot), "%d", i + 1);
157.1916 +      m_astGameSlot[i].m_sFile = sFileBase + csSlot + ".sgm";
157.1917 +
157.1918 +      std::string sDateTime;
157.1919 +      struct stat stStat;
157.1920 +      if (stat(m_astGameSlot[i].m_sFile.c_str(), &stStat) == -1)
157.1921 +      {
157.1922 +        sDateTime = _("----/--/-- --:--:--");
157.1923 +        m_astGameSlot[i].m_bEmpty = true;
157.1924 +      }
157.1925 +      else
157.1926 +      {
157.1927 +        char csDateTime[30];
157.1928 +        strftime(csDateTime, sizeof(csDateTime), csDateFormat,
157.1929 +                 localtime(&stStat.st_mtime));
157.1930 +        sDateTime = csDateTime;
157.1931 +        m_astGameSlot[i].m_bEmpty = false;
157.1932 +        m_astGameSlot[i].m_uiTime = stStat.st_mtime;
157.1933 +      }
157.1934 +
157.1935 +      Gtk::Label * poLabel;
157.1936 +      poLabel = dynamic_cast<Gtk::Label *>(m_apoLoadGameItem[i]->get_child());
157.1937 +      poLabel->set_text(csPrefix + sDateTime);
157.1938 +      m_apoLoadGameItem[i]->set_sensitive(! m_astGameSlot[i].m_bEmpty);
157.1939 +
157.1940 +      poLabel = dynamic_cast<Gtk::Label *>(m_apoSaveGameItem[i]->get_child());
157.1941 +      poLabel->set_text(csPrefix + sDateTime);
157.1942 +      m_apoSaveGameItem[i]->set_sensitive();
157.1943 +    }
157.1944 +  }
157.1945 +}
157.1946 +
157.1947 +} // VBA namespace
   158.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   158.2 +++ b/src/gtk/window.h	Sat Mar 03 10:31:27 2012 -0600
   158.3 @@ -0,0 +1,322 @@
   158.4 +// -*- C++ -*-
   158.5 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   158.6 +// Copyright (C) 1999-2003 Forgotten
   158.7 +// Copyright (C) 2004 Forgotten and the VBA development team
   158.8 +
   158.9 +// This program is free software; you can redistribute it and/or modify
  158.10 +// it under the terms of the GNU General Public License as published by
  158.11 +// the Free Software Foundation; either version 2, or(at your option)
  158.12 +// any later version.
  158.13 +//
  158.14 +// This program is distributed in the hope that it will be useful,
  158.15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  158.16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  158.17 +// GNU General Public License for more details.
  158.18 +//
  158.19 +// You should have received a copy of the GNU General Public License
  158.20 +// along with this program; if not, write to the Free Software Foundation,
  158.21 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  158.22 +
  158.23 +#ifndef __VBA_WINDOW_H__
  158.24 +#define __VBA_WINDOW_H__
  158.25 +
  158.26 +#include <sys/types.h>
  158.27 +#include <stdarg.h>
  158.28 +
  158.29 +#include <libglademm.h>
  158.30 +#include <gtkmm.h>
  158.31 +
  158.32 +#ifndef GTKMM20
  158.33 +# include "sigccompat.h"
  158.34 +#endif // ! GTKMM20
  158.35 +
  158.36 +#include <string>
  158.37 +#include <vector>
  158.38 +#include <list>
  158.39 +
  158.40 +#include "../common/System.h"
  158.41 +
  158.42 +#include "configfile.h"
  158.43 +#include "screenarea.h"
  158.44 +#include "filters.h"
  158.45 +#include "input.h"
  158.46 +#include "joypadconfig.h"
  158.47 +
  158.48 +namespace VBA
  158.49 +{
  158.50 +
  158.51 +class Window : public Gtk::Window
  158.52 +{
  158.53 +  friend class Gnome::Glade::Xml;
  158.54 +
  158.55 +public:
  158.56 +  virtual ~Window();
  158.57 +
  158.58 +  inline static Window * poGetInstance() { return m_poInstance; }
  158.59 +
  158.60 +  enum ECartridge
  158.61 +  {
  158.62 +    CartridgeNone,
  158.63 +    CartridgeGB,
  158.64 +    CartridgeGBA
  158.65 +  };
  158.66 +
  158.67 +  // GB/GBA screen sizes
  158.68 +  const int m_iGBScreenWidth;
  158.69 +  const int m_iGBScreenHeight;
  158.70 +  const int m_iSGBScreenWidth;
  158.71 +  const int m_iSGBScreenHeight;
  158.72 +  const int m_iGBAScreenWidth;
  158.73 +  const int m_iGBAScreenHeight;
  158.74 +
  158.75 +  bool bLoadROM(const std::string & _rsFile);
  158.76 +  void vPopupError(const char * _csFormat, ...);
  158.77 +  void vPopupErrorV(const char * _csFormat, va_list _args);
  158.78 +  void vDrawScreen();
  158.79 +  void vComputeFrameskip(int _iRate);
  158.80 +  void vShowSpeed(int _iSpeed);
  158.81 +  void vCaptureScreen(int _iNum);
  158.82 +  u32  uiReadJoypad();
  158.83 +
  158.84 +  inline ECartridge eGetCartridge() const { return m_eCartridge; }
  158.85 +  inline int        iGetThrottle()  const { return m_iThrottle; }
  158.86 +
  158.87 +protected:
  158.88 +  Window(GtkWindow * _pstWindow,
  158.89 +         const Glib::RefPtr<Gnome::Glade::Xml> & _poXml);
  158.90 +
  158.91 +  enum EShowSpeed
  158.92 +  {
  158.93 +    ShowNone,
  158.94 +    ShowPercentage,
  158.95 +    ShowDetailed
  158.96 +  };
  158.97 +
  158.98 +  enum ESaveType
  158.99 +  {
 158.100 +    SaveAuto,
 158.101 +    SaveEEPROM,
 158.102 +    SaveSRAM,
 158.103 +    SaveFlash,
 158.104 +    SaveEEPROMSensor,
 158.105 +    SaveNone
 158.106 +  };
 158.107 +
 158.108 +  enum ESoundStatus
 158.109 +  {
 158.110 +    SoundOff,
 158.111 +    SoundMute,
 158.112 +    SoundOn
 158.113 +  };
 158.114 +
 158.115 +  enum ESoundQuality
 158.116 +  {
 158.117 +    Sound44K = 1,
 158.118 +    Sound22K = 2,
 158.119 +    Sound11K = 4
 158.120 +  };
 158.121 +
 158.122 +  enum ESoundVolume
 158.123 +  {
 158.124 +    Sound100,
 158.125 +    Sound200,
 158.126 +    Sound300,
 158.127 +    Sound400,
 158.128 +    Sound25,
 158.129 +    Sound50
 158.130 +  };
 158.131 +
 158.132 +  enum EEmulatorType
 158.133 +  {
 158.134 +    EmulatorAuto,
 158.135 +    EmulatorCGB,
 158.136 +    EmulatorSGB,
 158.137 +    EmulatorGB,
 158.138 +    EmulatorGBA,
 158.139 +    EmulatorSGB2
 158.140 +  };
 158.141 +
 158.142 +  virtual void vOnFileOpen();
 158.143 +  virtual void vOnFileLoad();
 158.144 +  virtual void vOnFileSave();
 158.145 +  virtual void vOnLoadGameMostRecent();
 158.146 +  virtual void vOnLoadGameAutoToggled(Gtk::CheckMenuItem * _poCMI);
 158.147 +  virtual void vOnLoadGame(int _iSlot);
 158.148 +  virtual void vOnSaveGameOldest();
 158.149 +  virtual void vOnSaveGame(int _iSlot);
 158.150 +  virtual void vOnFilePauseToggled(Gtk::CheckMenuItem * _poCMI);
 158.151 +  virtual void vOnFileReset();
 158.152 +  virtual void vOnRecentReset();
 158.153 +  virtual void vOnRecentFreezeToggled(Gtk::CheckMenuItem * _poCMI);
 158.154 +  virtual void vOnRecentFile(std::string _sFile);
 158.155 +  virtual void vOnImportBatteryFile();
 158.156 +  virtual void vOnExportBatteryFile();
 158.157 +  virtual void vOnFileScreenCapture();
 158.158 +  virtual void vOnFileClose();
 158.159 +  virtual void vOnFileExit();
 158.160 +  virtual void vOnFrameskipToggled(Gtk::CheckMenuItem * _poCMI, int _iValue);
 158.161 +  virtual void vOnThrottleToggled(Gtk::CheckMenuItem * _poCMI, int _iPercent);
 158.162 +  virtual void vOnThrottleOther(Gtk::CheckMenuItem * _poCMI);
 158.163 +  virtual void vOnVideoScaleToggled(Gtk::CheckMenuItem * _poCMI, int _iScale);
 158.164 +  virtual void vOnLayerToggled(Gtk::CheckMenuItem * _poCMI, int _iLayer);
 158.165 +  virtual void vOnDirectories();
 158.166 +  virtual void vOnDirectoryReset(Gtk::Entry * _poEntry);
 158.167 +  virtual void vOnDirectorySelect(Gtk::Entry * _poEntry);
 158.168 +  virtual void vOnPauseWhenInactiveToggled(Gtk::CheckMenuItem * _poCMI);
 158.169 +  virtual void vOnSelectBios();
 158.170 +  virtual void vOnUseBiosToggled(Gtk::CheckMenuItem * _poCMI);
 158.171 +  virtual void vOnShowSpeedToggled(Gtk::CheckMenuItem * _poCMI, int _iShowSpeed);
 158.172 +  virtual void vOnSaveTypeToggled(Gtk::CheckMenuItem * _poCMI, int _iSaveType);
 158.173 +  virtual void vOnFlashSizeToggled(Gtk::CheckMenuItem * _poCMI, int _iFlashSize);
 158.174 +  virtual void vOnScreenshotFormatToggled(Gtk::CheckMenuItem * _poCMI, std::string _sFormat);
 158.175 +  virtual void vOnSoundStatusToggled(Gtk::CheckMenuItem * _poCMI, int _iSoundStatus);
 158.176 +  virtual void vOnSoundEchoToggled(Gtk::CheckMenuItem * _poCMI);
 158.177 +  virtual void vOnSoundLowPassToggled(Gtk::CheckMenuItem * _poCMI);
 158.178 +  virtual void vOnSoundReverseToggled(Gtk::CheckMenuItem * _poCMI);
 158.179 +  virtual void vOnSoundChannelToggled(Gtk::CheckMenuItem * _poCMI, int _iSoundChannel);
 158.180 +  virtual void vOnSoundQualityToggled(Gtk::CheckMenuItem * _poCMI, int _iSoundQuality);
 158.181 +  virtual void vOnSoundVolumeToggled(Gtk::CheckMenuItem * _poCMI, int _iSoundVolume);
 158.182 +  virtual void vOnGBBorderToggled(Gtk::CheckMenuItem * _poCMI);
 158.183 +  virtual void vOnGBPrinterToggled(Gtk::CheckMenuItem * _poCMI);
 158.184 +  virtual void vOnEmulatorTypeToggled(Gtk::CheckMenuItem * _poCMI, int _iEmulatorType);
 158.185 +  virtual void vOnFilter2xToggled(Gtk::CheckMenuItem * _poCMI, int _iFilter2x);
 158.186 +  virtual void vOnFilterIBToggled(Gtk::CheckMenuItem * _poCMI, int _iFilterIB);
 158.187 +#ifdef MMX
 158.188 +  virtual void vOnDisableMMXToggled(Gtk::CheckMenuItem * _poCMI);
 158.189 +#endif // MMX
 158.190 +  virtual void vOnJoypadConfigure(int _iJoypad);
 158.191 +  virtual void vOnJoypadToggled(Gtk::CheckMenuItem * _poCMI, int _iJoypad);
 158.192 +  virtual void vOnAutofireToggled(Gtk::CheckMenuItem * _poCMI, u32 _uiKeyFlag);
 158.193 +  virtual void vOnGDBWait();
 158.194 +  virtual void vOnGDBLoadAndWait();
 158.195 +  virtual void vOnGDBBreak();
 158.196 +  virtual void vOnGDBDisconnect();
 158.197 +  virtual void vOnHelpAbout();
 158.198 +  virtual bool bOnEmuIdle();
 158.199 +
 158.200 +  virtual bool on_focus_in_event(GdkEventFocus * _pstEvent);
 158.201 +  virtual bool on_focus_out_event(GdkEventFocus * _pstEvent);
 158.202 +  virtual bool on_key_press_event(GdkEventKey * _pstEvent);
 158.203 +  virtual bool on_key_release_event(GdkEventKey * _pstEvent);
 158.204 +
 158.205 +private:
 158.206 +  // Config limits
 158.207 +  const int m_iFrameskipMin;
 158.208 +  const int m_iFrameskipMax;
 158.209 +  const int m_iThrottleMin;
 158.210 +  const int m_iThrottleMax;
 158.211 +  const int m_iScaleMin;
 158.212 +  const int m_iScaleMax;
 158.213 +  const int m_iShowSpeedMin;
 158.214 +  const int m_iShowSpeedMax;
 158.215 +  const int m_iSaveTypeMin;
 158.216 +  const int m_iSaveTypeMax;
 158.217 +  const int m_iSoundQualityMin;
 158.218 +  const int m_iSoundQualityMax;
 158.219 +  const int m_iSoundVolumeMin;
 158.220 +  const int m_iSoundVolumeMax;
 158.221 +  const int m_iEmulatorTypeMin;
 158.222 +  const int m_iEmulatorTypeMax;
 158.223 +  const int m_iFilter2xMin;
 158.224 +  const int m_iFilter2xMax;
 158.225 +  const int m_iFilterIBMin;
 158.226 +  const int m_iFilterIBMax;
 158.227 +  const int m_iJoypadMin;
 158.228 +  const int m_iJoypadMax;
 158.229 +
 158.230 +  static Window * m_poInstance;
 158.231 +
 158.232 +  Glib::RefPtr<Gnome::Glade::Xml> m_poXml;
 158.233 +
 158.234 +  std::string       m_sUserDataDir;
 158.235 +  std::string       m_sConfigFile;
 158.236 +  Config::File      m_oConfig;
 158.237 +  Config::Section * m_poHistoryConfig;
 158.238 +  Config::Section * m_poDirConfig;
 158.239 +  Config::Section * m_poCoreConfig;
 158.240 +  Config::Section * m_poDisplayConfig;
 158.241 +  Config::Section * m_poSoundConfig;
 158.242 +  Config::Section * m_poInputConfig;
 158.243 +
 158.244 +#ifdef GTKMM20
 158.245 +  Gtk::FileSelection * m_poFileOpenDialog;
 158.246 +#else // ! GTKMM20
 158.247 +  Gtk::FileChooserDialog * m_poFileOpenDialog;
 158.248 +#endif // ! GTKMM20
 158.249 +  ScreenArea *         m_poScreenArea;
 158.250 +  Gtk::Menu *          m_poRecentMenu;
 158.251 +  Gtk::MenuItem *      m_poRecentResetItem;
 158.252 +  Gtk::CheckMenuItem * m_poFilePauseItem;
 158.253 +  Gtk::CheckMenuItem * m_poUseBiosItem;
 158.254 +  Gtk::CheckMenuItem * m_poSoundOffItem;
 158.255 +
 158.256 +  struct SGameSlot
 158.257 +  {
 158.258 +    bool        m_bEmpty;
 158.259 +    std::string m_sFile;
 158.260 +    time_t      m_uiTime;
 158.261 +  };
 158.262 +
 158.263 +  Gtk::MenuItem * m_apoLoadGameItem[10];
 158.264 +  Gtk::MenuItem * m_apoSaveGameItem[10];
 158.265 +  SGameSlot       m_astGameSlot[10];
 158.266 +
 158.267 +  std::list<std::string> m_listHistory;
 158.268 +
 158.269 +  std::list<Gtk::Widget *> m_listSensitiveWhenPlaying;
 158.270 +
 158.271 +  Gtk::Tooltips m_oTooltips;
 158.272 +
 158.273 +  SigC::connection m_oEmuSig;
 158.274 +
 158.275 +  std::vector<JoypadConfig> m_oJoypads;
 158.276 +  Keymap * m_poKeymap;
 158.277 +
 158.278 +  int m_iScreenWidth;
 158.279 +  int m_iScreenHeight;
 158.280 +
 158.281 +  std::string    m_sRomFile;
 158.282 +  ECartridge     m_eCartridge;
 158.283 +  EmulatedSystem m_stEmulator;
 158.284 +  u32            m_uiJoypadState;
 158.285 +  u32            m_uiAutofireState;
 158.286 +  bool           m_bAutofireToggle;
 158.287 +  bool           m_bPaused;
 158.288 +  bool           m_bWasEmulating;
 158.289 +  bool           m_bAutoFrameskip;
 158.290 +  int            m_iThrottle;
 158.291 +  u32            m_uiThrottleLastTime;
 158.292 +  u32            m_uiThrottleDelay;
 158.293 +  EShowSpeed     m_eShowSpeed;
 158.294 +  ESoundQuality  m_eSoundQuality;
 158.295 +
 158.296 +  void vInitSystem();
 158.297 +  void vInitSDL();
 158.298 +  void vInitConfig();
 158.299 +  void vCheckConfig();
 158.300 +  void vLoadConfig(const std::string & _rsFile);
 158.301 +  void vSaveConfig(const std::string & _rsFile);
 158.302 +  void vLoadHistoryFromConfig();
 158.303 +  void vSaveHistoryToConfig();
 158.304 +  void vHistoryAdd(const std::string & _rsFile);
 158.305 +  void vClearHistoryMenu();
 158.306 +  void vUpdateHistoryMenu();
 158.307 +  void vLoadJoypadsFromConfig();
 158.308 +  void vSaveJoypadsToConfig();
 158.309 +  void vUpdateScreen();
 158.310 +  void vDrawDefaultScreen();
 158.311 +  void vSetDefaultTitle();
 158.312 +  void vCreateFileOpenDialog();
 158.313 +  void vLoadBattery();
 158.314 +  void vSaveBattery();
 158.315 +  void vStartEmu();
 158.316 +  void vStopEmu();
 158.317 +  void vSetThrottle(int _iPercent);
 158.318 +  void vSelectBestThrottleItem();
 158.319 +  void vUpdateGameSlots();
 158.320 +};
 158.321 +
 158.322 +} // namespace VBA
 158.323 +
 158.324 +
 158.325 +#endif // __VBA_WINDOW_H__
   159.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   159.2 +++ b/src/gtk/windowcallbacks.cpp	Sat Mar 03 10:31:27 2012 -0600
   159.3 @@ -0,0 +1,1582 @@
   159.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   159.5 +// Copyright (C) 1999-2003 Forgotten
   159.6 +// Copyright (C) 2004 Forgotten and the VBA development team
   159.7 +
   159.8 +// This program is free software; you can redistribute it and/or modify
   159.9 +// it under the terms of the GNU General Public License as published by
  159.10 +// the Free Software Foundation; either version 2, or(at your option)
  159.11 +// any later version.
  159.12 +//
  159.13 +// This program is distributed in the hope that it will be useful,
  159.14 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  159.15 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  159.16 +// GNU General Public License for more details.
  159.17 +//
  159.18 +// You should have received a copy of the GNU General Public License
  159.19 +// along with this program; if not, write to the Free Software Foundation,
  159.20 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  159.21 +
  159.22 +#include "window.h"
  159.23 +
  159.24 +#include <sys/stat.h>
  159.25 +
  159.26 +#include <stdio.h>
  159.27 +#include <time.h>
  159.28 +
  159.29 +#include <SDL.h>
  159.30 +
  159.31 +#include "../gba/GBA.h"
  159.32 +#include "../gba/GBAGlobals.h"
  159.33 +#include "../gba/Flash.h"
  159.34 +#include "../gba/GBASound.h"
  159.35 +#include "../gb/GB.h"
  159.36 +#include "../gb/gbGlobals.h"
  159.37 +#include "../gb/gbPrinter.h"
  159.38 +#include "../common/Util.h"
  159.39 +
  159.40 +#include "tools.h"
  159.41 +#include "intl.h"
  159.42 +
  159.43 +extern int systemRenderedFrames;
  159.44 +extern int systemFPS;
  159.45 +extern bool debugger;
  159.46 +extern int RGB_LOW_BITS_MASK;
  159.47 +extern void (*dbgMain)();
  159.48 +extern void (*dbgSignal)(int, int);
  159.49 +extern void (*dbgOutput)(char *, u32);
  159.50 +extern void remoteInit();
  159.51 +extern void remoteCleanUp();
  159.52 +extern void remoteStubMain();
  159.53 +extern void remoteStubSignal(int, int);
  159.54 +extern void remoteOutput(char *, u32);
  159.55 +extern void remoteSetProtocol(int);
  159.56 +extern void remoteSetPort(int);
  159.57 +
  159.58 +#ifdef MMX
  159.59 +extern "C" bool cpu_mmx;
  159.60 +#endif // MMX
  159.61 +
  159.62 +namespace VBA
  159.63 +{
  159.64 +
  159.65 +using Gnome::Glade::Xml;
  159.66 +
  159.67 +void Window::vOnFileOpen()
  159.68 +{
  159.69 +  while (m_poFileOpenDialog->run() == Gtk::RESPONSE_OK)
  159.70 +  {
  159.71 +    if (bLoadROM(m_poFileOpenDialog->get_filename()))
  159.72 +    {
  159.73 +      break;
  159.74 +    }
  159.75 +  }
  159.76 +  m_poFileOpenDialog->hide();
  159.77 +}
  159.78 +
  159.79 +void Window::vOnFileLoad()
  159.80 +{
  159.81 +  std::string sSaveDir = m_poDirConfig->sGetKey("saves");
  159.82 +
  159.83 +#ifdef GTKMM20
  159.84 +
  159.85 +  Gtk::FileSelection oDialog(_("Load game"));
  159.86 +  oDialog.set_transient_for(*this);
  159.87 +
  159.88 +  if (sSaveDir == "")
  159.89 +  {
  159.90 +    oDialog.set_filename(Glib::path_get_dirname(m_sRomFile) + "/");
  159.91 +  }
  159.92 +  else
  159.93 +  {
  159.94 +    oDialog.set_filename(sSaveDir + "/");
  159.95 +  }
  159.96 +
  159.97 +#else // ! GTKMM20
  159.98 +
  159.99 +  Gtk::FileChooserDialog oDialog(*this, _("Load game"));
 159.100 +  oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
 159.101 +  oDialog.add_button(Gtk::Stock::OPEN,   Gtk::RESPONSE_OK);
 159.102 +
 159.103 +  if (sSaveDir == "")
 159.104 +  {
 159.105 +    oDialog.set_current_folder(Glib::path_get_dirname(m_sRomFile));
 159.106 +  }
 159.107 +  else
 159.108 +  {
 159.109 +    oDialog.set_current_folder(sSaveDir);
 159.110 +    oDialog.add_shortcut_folder(sSaveDir);
 159.111 +  }
 159.112 +
 159.113 +  Gtk::FileFilter oSaveFilter;
 159.114 +  oSaveFilter.set_name(_("VisualBoyAdvance save game"));
 159.115 +  oSaveFilter.add_pattern("*.[sS][gG][mM]");
 159.116 +
 159.117 +  oDialog.add_filter(oSaveFilter);
 159.118 +
 159.119 +#endif // ! GTKMM20
 159.120 +
 159.121 +  while (oDialog.run() == Gtk::RESPONSE_OK)
 159.122 +  {
 159.123 +    if (m_stEmulator.emuReadState(oDialog.get_filename().c_str()))
 159.124 +    {
 159.125 +      break;
 159.126 +    }
 159.127 +  }
 159.128 +}
 159.129 +
 159.130 +void Window::vOnFileSave()
 159.131 +{
 159.132 +  Glib::ustring sSaveDir = m_poDirConfig->sGetKey("saves");
 159.133 +
 159.134 +#ifdef GTKMM20
 159.135 +
 159.136 +  Gtk::FileSelection oDialog(_("Save game"));
 159.137 +  oDialog.set_transient_for(*this);
 159.138 +
 159.139 +  if (sSaveDir == "")
 159.140 +  {
 159.141 +    oDialog.set_filename(sCutSuffix(m_sRomFile));
 159.142 +  }
 159.143 +  else
 159.144 +  {
 159.145 +    oDialog.set_filename(sSaveDir + "/" +
 159.146 +                         sCutSuffix(Glib::path_get_basename(m_sRomFile)));
 159.147 +  }
 159.148 +
 159.149 +#else // ! GTKMM20
 159.150 +
 159.151 +  Gtk::FileChooserDialog oDialog(*this, _("Save game"),
 159.152 +                                 Gtk::FILE_CHOOSER_ACTION_SAVE);
 159.153 +  oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
 159.154 +  oDialog.add_button(Gtk::Stock::SAVE,   Gtk::RESPONSE_OK);
 159.155 +
 159.156 +  if (sSaveDir == "")
 159.157 +  {
 159.158 +    oDialog.set_current_folder(Glib::path_get_dirname(m_sRomFile));
 159.159 +  }
 159.160 +  else
 159.161 +  {
 159.162 +    oDialog.set_current_folder(sSaveDir);
 159.163 +    oDialog.add_shortcut_folder(sSaveDir);
 159.164 +  }
 159.165 +  oDialog.set_current_name(sCutSuffix(Glib::path_get_basename(m_sRomFile)));
 159.166 +
 159.167 +  Gtk::FileFilter oSaveFilter;
 159.168 +  oSaveFilter.set_name(_("VisualBoyAdvance save game"));
 159.169 +  oSaveFilter.add_pattern("*.[sS][gG][mM]");
 159.170 +
 159.171 +  oDialog.add_filter(oSaveFilter);
 159.172 +
 159.173 +#endif // ! GTKMM20
 159.174 +
 159.175 +  while (oDialog.run() == Gtk::RESPONSE_OK)
 159.176 +  {
 159.177 +    Glib::ustring sFile = oDialog.get_filename();
 159.178 +    if (! bHasSuffix(sFile, ".sgm", false))
 159.179 +    {
 159.180 +      sFile += ".sgm";
 159.181 +    }
 159.182 +
 159.183 +    if (Glib::file_test(sFile, Glib::FILE_TEST_EXISTS))
 159.184 +    {
 159.185 +      Gtk::MessageDialog oConfirmDialog(*this,
 159.186 +                                        _("File already exists. Overwrite it?"),
 159.187 +#ifndef GTKMM20
 159.188 +                                        false,
 159.189 +#endif // ! GTKMM20
 159.190 +                                        Gtk::MESSAGE_QUESTION,
 159.191 +                                        Gtk::BUTTONS_YES_NO);
 159.192 +      if (oConfirmDialog.run() != Gtk::RESPONSE_YES)
 159.193 +      {
 159.194 +        continue;
 159.195 +      }
 159.196 +    }
 159.197 +
 159.198 +    if (m_stEmulator.emuWriteState(sFile.c_str()))
 159.199 +    {
 159.200 +      break;
 159.201 +    }
 159.202 +  }
 159.203 +}
 159.204 +
 159.205 +void Window::vOnLoadGameMostRecent()
 159.206 +{
 159.207 +  int    iMostRecent = -1;
 159.208 +  time_t uiTimeMax;
 159.209 +
 159.210 +  for (int i = 0; i < 10; i++)
 159.211 +  {
 159.212 +    if (! m_astGameSlot[i].m_bEmpty
 159.213 +        && (iMostRecent < 0 || m_astGameSlot[i].m_uiTime > uiTimeMax))
 159.214 +    {
 159.215 +      iMostRecent = i;
 159.216 +      uiTimeMax = m_astGameSlot[i].m_uiTime;
 159.217 +    }
 159.218 +  }
 159.219 +
 159.220 +  if (iMostRecent >= 0)
 159.221 +  {
 159.222 +    vOnLoadGame(iMostRecent + 1);
 159.223 +  }
 159.224 +}
 159.225 +
 159.226 +void Window::vOnLoadGameAutoToggled(Gtk::CheckMenuItem * _poCMI)
 159.227 +{
 159.228 +  m_poCoreConfig->vSetKey("load_game_auto", _poCMI->get_active());
 159.229 +}
 159.230 +
 159.231 +void Window::vOnLoadGame(int _iSlot)
 159.232 +{
 159.233 +  int i = _iSlot - 1;
 159.234 +  if (! m_astGameSlot[i].m_bEmpty)
 159.235 +  {
 159.236 +    m_stEmulator.emuReadState(m_astGameSlot[i].m_sFile.c_str());
 159.237 +    m_poFilePauseItem->set_active(false);
 159.238 +  }
 159.239 +}
 159.240 +
 159.241 +void Window::vOnSaveGameOldest()
 159.242 +{
 159.243 +  int    iOldest = -1;
 159.244 +  time_t uiTimeMin;
 159.245 +
 159.246 +  for (int i = 0; i < 10; i++)
 159.247 +  {
 159.248 +    if (! m_astGameSlot[i].m_bEmpty
 159.249 +        && (iOldest < 0 || m_astGameSlot[i].m_uiTime < uiTimeMin))
 159.250 +    {
 159.251 +      iOldest = i;
 159.252 +      uiTimeMin = m_astGameSlot[i].m_uiTime;
 159.253 +    }
 159.254 +  }
 159.255 +
 159.256 +  if (iOldest >= 0)
 159.257 +  {
 159.258 +    vOnSaveGame(iOldest + 1);
 159.259 +  }
 159.260 +  else
 159.261 +  {
 159.262 +    vOnSaveGame(1);
 159.263 +  }
 159.264 +}
 159.265 +
 159.266 +void Window::vOnSaveGame(int _iSlot)
 159.267 +{
 159.268 +  int i = _iSlot - 1;
 159.269 +  m_stEmulator.emuWriteState(m_astGameSlot[i].m_sFile.c_str());
 159.270 +  vUpdateGameSlots();
 159.271 +}
 159.272 +
 159.273 +void Window::vOnFilePauseToggled(Gtk::CheckMenuItem * _poCMI)
 159.274 +{
 159.275 +  m_bPaused = _poCMI->get_active();
 159.276 +  if (emulating)
 159.277 +  {
 159.278 +    if (m_bPaused)
 159.279 +    {
 159.280 +      vStopEmu();
 159.281 +      soundPause();
 159.282 +    }
 159.283 +    else
 159.284 +    {
 159.285 +      vStartEmu();
 159.286 +      soundResume();
 159.287 +    }
 159.288 +  }
 159.289 +}
 159.290 +
 159.291 +void Window::vOnFileReset()
 159.292 +{
 159.293 +  if (emulating)
 159.294 +  {
 159.295 +    m_stEmulator.emuReset(true);
 159.296 +    m_poFilePauseItem->set_active(false);
 159.297 +  }
 159.298 +}
 159.299 +
 159.300 +void Window::vOnRecentReset()
 159.301 +{
 159.302 +  m_listHistory.clear();
 159.303 +  vClearHistoryMenu();
 159.304 +}
 159.305 +
 159.306 +void Window::vOnRecentFreezeToggled(Gtk::CheckMenuItem * _poCMI)
 159.307 +{
 159.308 +  m_poRecentResetItem->set_sensitive(! _poCMI->get_active());
 159.309 +  m_poHistoryConfig->vSetKey("freeze", _poCMI->get_active());
 159.310 +}
 159.311 +
 159.312 +void Window::vOnRecentFile(std::string _sFile)
 159.313 +{
 159.314 +  bLoadROM(_sFile);
 159.315 +}
 159.316 +
 159.317 +void Window::vOnImportBatteryFile()
 159.318 +{
 159.319 +  std::string BatteryDir = m_poDirConfig->sGetKey("batteries");
 159.320 +
 159.321 +#ifdef GTKMM20
 159.322 +
 159.323 +  Gtk::FileSelection oDialog(_("Import battery file"));
 159.324 +  oDialog.set_transient_for(*this);
 159.325 +
 159.326 +  if (BatteryDir == "")
 159.327 +  {
 159.328 +    oDialog.set_filename(Glib::path_get_dirname(m_sRomFile) + "/");
 159.329 +  }
 159.330 +  else
 159.331 +  {
 159.332 +    oDialog.set_filename(BatteryDir + "/");
 159.333 +  }
 159.334 +
 159.335 +#else // ! GTKMM20
 159.336 +
 159.337 +  Gtk::FileChooserDialog oDialog(*this, _("Import battery file"));
 159.338 +  oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
 159.339 +  oDialog.add_button(Gtk::Stock::OPEN,   Gtk::RESPONSE_OK);
 159.340 +
 159.341 +  if (BatteryDir == "")
 159.342 +  {
 159.343 +    oDialog.set_current_folder(Glib::path_get_dirname(m_sRomFile));
 159.344 +  }
 159.345 +  else
 159.346 +  {
 159.347 +    oDialog.set_current_folder(BatteryDir);
 159.348 +    oDialog.add_shortcut_folder(BatteryDir);
 159.349 +  }
 159.350 +
 159.351 +  Gtk::FileFilter oBatteryFilter;
 159.352 +  oBatteryFilter.set_name(_("Battery file"));
 159.353 +  oBatteryFilter.add_pattern("*.[sS][aA][vV]");
 159.354 +
 159.355 +  Gtk::FileFilter oFlashFilter;
 159.356 +  oFlashFilter.set_name(_("Flash save"));
 159.357 +  oFlashFilter.add_pattern("*.[dD][aA][tT]");
 159.358 +
 159.359 +  oDialog.add_filter(oBatteryFilter);
 159.360 +  oDialog.add_filter(oFlashFilter);
 159.361 +
 159.362 +#endif // ! GTKMM20
 159.363 +
 159.364 +  while (oDialog.run() == Gtk::RESPONSE_OK)
 159.365 +  {
 159.366 +    Gtk::MessageDialog oConfirmDialog(*this,
 159.367 +                                      _("Importing a battery file will erase any saved games and reset the emulator. Do you want to continue?"),
 159.368 +#ifndef GTKMM20
 159.369 +                                      false,
 159.370 +#endif // ! GTKMM20
 159.371 +                                      Gtk::MESSAGE_QUESTION,
 159.372 +                                      Gtk::BUTTONS_YES_NO);
 159.373 +    if (oConfirmDialog.run() != Gtk::RESPONSE_YES)
 159.374 +    {
 159.375 +      continue;
 159.376 +    }
 159.377 +
 159.378 +    if (m_stEmulator.emuReadBattery(oDialog.get_filename().c_str()))
 159.379 +    {
 159.380 +      m_stEmulator.emuReset(false);
 159.381 +      break;
 159.382 +    }
 159.383 +    else
 159.384 +    {
 159.385 +      vPopupError(_("Failed to import battery file %s."),
 159.386 +                  oDialog.get_filename().c_str());
 159.387 +    }
 159.388 +  }
 159.389 +}
 159.390 +
 159.391 +void Window::vOnExportBatteryFile()
 159.392 +{
 159.393 +  std::string sBatteryDir = m_poDirConfig->sGetKey("batteries");
 159.394 +
 159.395 +#ifdef GTKMM20
 159.396 +
 159.397 +  Gtk::FileSelection oDialog(_("Export battery file"));
 159.398 +  oDialog.set_transient_for(*this);
 159.399 +
 159.400 +  if (sBatteryDir == "")
 159.401 +  {
 159.402 +    oDialog.set_filename(sCutSuffix(m_sRomFile));
 159.403 +  }
 159.404 +  else
 159.405 +  {
 159.406 +    oDialog.set_filename(sBatteryDir + "/" +
 159.407 +                         sCutSuffix(Glib::path_get_basename(m_sRomFile)));
 159.408 +  }
 159.409 +
 159.410 +#else // ! GTKMM20
 159.411 +
 159.412 +  Gtk::FileChooserDialog oDialog(*this, _("Export battery file"),
 159.413 +                                 Gtk::FILE_CHOOSER_ACTION_SAVE);
 159.414 +  oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
 159.415 +  oDialog.add_button(Gtk::Stock::SAVE,   Gtk::RESPONSE_OK);
 159.416 +
 159.417 +  if (sBatteryDir == "")
 159.418 +  {
 159.419 +    oDialog.set_current_folder(Glib::path_get_dirname(m_sRomFile));
 159.420 +  }
 159.421 +  else
 159.422 +  {
 159.423 +    oDialog.set_current_folder(sBatteryDir);
 159.424 +    oDialog.add_shortcut_folder(sBatteryDir);
 159.425 +  }
 159.426 +  oDialog.set_current_name(sCutSuffix(Glib::path_get_basename(m_sRomFile)));
 159.427 +
 159.428 +  Gtk::FileFilter oBatteryFilter;
 159.429 +  oBatteryFilter.set_name(_("Battery file"));
 159.430 +  oBatteryFilter.add_pattern("*.[sS][aA][vV]");
 159.431 +
 159.432 +  Gtk::FileFilter oFlashFilter;
 159.433 +  oFlashFilter.set_name(_("Flash save"));
 159.434 +  oFlashFilter.add_pattern("*.[dD][aA][tT]");
 159.435 +
 159.436 +  oDialog.add_filter(oBatteryFilter);
 159.437 +  oDialog.add_filter(oFlashFilter);
 159.438 +
 159.439 +#endif // ! GTKMM20
 159.440 +
 159.441 +  while (oDialog.run() == Gtk::RESPONSE_OK)
 159.442 +  {
 159.443 +    Glib::ustring sFile = oDialog.get_filename();
 159.444 +    Glib::ustring sExt;
 159.445 +
 159.446 +#ifdef GTKMM20
 159.447 +
 159.448 +    sExt = ".sav";
 159.449 +
 159.450 +#else // ! GTKMM20
 159.451 +
 159.452 +    if (oDialog.get_filter() == &oBatteryFilter)
 159.453 +    {
 159.454 +      sExt = ".sav";
 159.455 +    }
 159.456 +    else
 159.457 +    {
 159.458 +      sExt = ".dat";
 159.459 +    }
 159.460 +
 159.461 +#endif // ! GTKMM20
 159.462 +
 159.463 +    if (! bHasSuffix(sFile, sExt, false))
 159.464 +    {
 159.465 +      sFile += sExt;
 159.466 +    }
 159.467 +
 159.468 +    if (Glib::file_test(sFile, Glib::FILE_TEST_EXISTS))
 159.469 +    {
 159.470 +      Gtk::MessageDialog oConfirmDialog(*this,
 159.471 +                                        _("File already exists. Overwrite it?"),
 159.472 +#ifndef GTKMM20
 159.473 +                                        false,
 159.474 +#endif // ! GTKMM20
 159.475 +                                        Gtk::MESSAGE_QUESTION,
 159.476 +                                        Gtk::BUTTONS_YES_NO);
 159.477 +      if (oConfirmDialog.run() != Gtk::RESPONSE_YES)
 159.478 +      {
 159.479 +        continue;
 159.480 +      }
 159.481 +    }
 159.482 +
 159.483 +    bool bResult;
 159.484 +    if (m_eCartridge == CartridgeGB)
 159.485 +    {
 159.486 +      bResult = gbWriteBatteryFile(sFile.c_str(), false);
 159.487 +    }
 159.488 +    else
 159.489 +    {
 159.490 +      bResult = m_stEmulator.emuWriteBattery(sFile.c_str());
 159.491 +    }
 159.492 +
 159.493 +    if (bResult)
 159.494 +    {
 159.495 +      break;
 159.496 +    }
 159.497 +    else
 159.498 +    {
 159.499 +      vPopupError(_("Failed to export battery file %s."),
 159.500 +                  sFile.c_str());
 159.501 +    }
 159.502 +  }
 159.503 +}
 159.504 +
 159.505 +void Window::vOnFileScreenCapture()
 159.506 +{
 159.507 +  std::string sCaptureDir = m_poDirConfig->sGetKey("captures");
 159.508 +
 159.509 +#ifdef GTKMM20
 159.510 +
 159.511 +  Gtk::FileSelection oDialog(_("Save screenshot"));
 159.512 +  oDialog.set_transient_for(*this);
 159.513 +
 159.514 +  if (sCaptureDir == "")
 159.515 +  {
 159.516 +    oDialog.set_filename(sCutSuffix(m_sRomFile));
 159.517 +  }
 159.518 +  else
 159.519 +  {
 159.520 +    oDialog.set_filename(sCaptureDir + "/" +
 159.521 +                         sCutSuffix(Glib::path_get_basename(m_sRomFile)));
 159.522 +  }
 159.523 +
 159.524 +#else // ! GTKMM20
 159.525 +
 159.526 +  Gtk::FileChooserDialog oDialog(*this, _("Save screenshot"),
 159.527 +                                 Gtk::FILE_CHOOSER_ACTION_SAVE);
 159.528 +  oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
 159.529 +  oDialog.add_button(Gtk::Stock::SAVE,   Gtk::RESPONSE_OK);
 159.530 +
 159.531 +  if (sCaptureDir == "")
 159.532 +  {
 159.533 +    oDialog.set_current_folder(Glib::path_get_dirname(m_sRomFile));
 159.534 +  }
 159.535 +  else
 159.536 +  {
 159.537 +    oDialog.set_current_folder(sCaptureDir);
 159.538 +    oDialog.add_shortcut_folder(sCaptureDir);
 159.539 +  }
 159.540 +  oDialog.set_current_name(sCutSuffix(Glib::path_get_basename(m_sRomFile)));
 159.541 +
 159.542 +  Gtk::FileFilter oPngFilter;
 159.543 +  oPngFilter.set_name(_("PNG image"));
 159.544 +  oPngFilter.add_pattern("*.[pP][nN][gG]");
 159.545 +
 159.546 +  Gtk::FileFilter oBmpFilter;
 159.547 +  oBmpFilter.set_name(_("BMP image"));
 159.548 +  oBmpFilter.add_pattern("*.[bB][mM][pP]");
 159.549 +
 159.550 +  oDialog.add_filter(oPngFilter);
 159.551 +  oDialog.add_filter(oBmpFilter);
 159.552 +
 159.553 +  if (m_poCoreConfig->sGetKey("screenshot_format") == "bmp")
 159.554 +  {
 159.555 +    oDialog.set_filter(oBmpFilter);
 159.556 +  }
 159.557 +
 159.558 +#endif // ! GTKMM20
 159.559 +
 159.560 +  while (oDialog.run() == Gtk::RESPONSE_OK)
 159.561 +  {
 159.562 +    Glib::ustring sFile = oDialog.get_filename();
 159.563 +    Glib::ustring sExt;
 159.564 +
 159.565 +#ifdef GTKMM20
 159.566 +
 159.567 +    sExt = "." + m_poCoreConfig->sGetKey("screenshot_format");
 159.568 +
 159.569 +#else // ! GTKMM20
 159.570 +
 159.571 +    if (oDialog.get_filter() == &oPngFilter)
 159.572 +    {
 159.573 +      sExt = ".png";
 159.574 +    }
 159.575 +    else
 159.576 +    {
 159.577 +      sExt = ".bmp";
 159.578 +    }
 159.579 +
 159.580 +#endif // ! GTKMM20
 159.581 +
 159.582 +    if (! bHasSuffix(sFile, sExt, false))
 159.583 +    {
 159.584 +      sFile += sExt;
 159.585 +    }
 159.586 +
 159.587 +    if (Glib::file_test(sFile, Glib::FILE_TEST_EXISTS))
 159.588 +    {
 159.589 +      Gtk::MessageDialog oConfirmDialog(*this,
 159.590 +                                        _("File already exists. Overwrite it?"),
 159.591 +#ifndef GTKMM20
 159.592 +                                        false,
 159.593 +#endif // ! GTKMM20
 159.594 +                                        Gtk::MESSAGE_QUESTION,
 159.595 +                                        Gtk::BUTTONS_YES_NO);
 159.596 +      if (oConfirmDialog.run() != Gtk::RESPONSE_YES)
 159.597 +      {
 159.598 +        continue;
 159.599 +      }
 159.600 +    }
 159.601 +
 159.602 +    bool bResult;
 159.603 +    if (sExt == ".png")
 159.604 +    {
 159.605 +      bResult = m_stEmulator.emuWritePNG(sFile.c_str());
 159.606 +    }
 159.607 +    else
 159.608 +    {
 159.609 +      bResult = m_stEmulator.emuWriteBMP(sFile.c_str());
 159.610 +    }
 159.611 +
 159.612 +    if (bResult)
 159.613 +    {
 159.614 +      break;
 159.615 +    }
 159.616 +  }
 159.617 +}
 159.618 +
 159.619 +void Window::vOnFileClose()
 159.620 +{
 159.621 +  if (m_eCartridge != CartridgeNone)
 159.622 +  {
 159.623 +    soundPause();
 159.624 +    vStopEmu();
 159.625 +    vSetDefaultTitle();
 159.626 +    vDrawDefaultScreen();
 159.627 +    vSaveBattery();
 159.628 +    m_stEmulator.emuCleanUp();
 159.629 +    m_eCartridge = CartridgeNone;
 159.630 +    emulating = 0;
 159.631 +
 159.632 +    vUpdateGameSlots();
 159.633 +
 159.634 +    for (std::list<Gtk::Widget *>::iterator it = m_listSensitiveWhenPlaying.begin();
 159.635 +         it != m_listSensitiveWhenPlaying.end();
 159.636 +         it++)
 159.637 +    {
 159.638 +      (*it)->set_sensitive(false);
 159.639 +    }
 159.640 +
 159.641 +    m_poFilePauseItem->set_active(false);
 159.642 +  }
 159.643 +}
 159.644 +
 159.645 +void Window::vOnFileExit()
 159.646 +{
 159.647 +  hide();
 159.648 +}
 159.649 +
 159.650 +void Window::vOnFrameskipToggled(Gtk::CheckMenuItem * _poCMI, int _iValue)
 159.651 +{
 159.652 +  if (! _poCMI->get_active())
 159.653 +  {
 159.654 +    return;
 159.655 +  }
 159.656 +
 159.657 +  if (_iValue >= 0 && _iValue <= 9)
 159.658 +  {
 159.659 +    m_poCoreConfig->vSetKey("frameskip", _iValue);
 159.660 +    gbFrameSkip      = _iValue;
 159.661 +    systemFrameSkip  = _iValue;
 159.662 +    m_bAutoFrameskip = false;
 159.663 +  }
 159.664 +  else
 159.665 +  {
 159.666 +    m_poCoreConfig->vSetKey("frameskip", "auto");
 159.667 +    gbFrameSkip      = 0;
 159.668 +    systemFrameSkip  = 0;
 159.669 +    m_bAutoFrameskip = true;
 159.670 +  }
 159.671 +}
 159.672 +
 159.673 +void Window::vOnThrottleToggled(Gtk::CheckMenuItem * _poCMI, int _iPercent)
 159.674 +{
 159.675 +  if (! _poCMI->get_active())
 159.676 +  {
 159.677 +    return;
 159.678 +  }
 159.679 +
 159.680 +  vSetThrottle(_iPercent);
 159.681 +
 159.682 +  // Initialize the frameskip adjustment each time throttle is changed
 159.683 +  if (m_bAutoFrameskip)
 159.684 +  {
 159.685 +    systemFrameSkip = 0;
 159.686 +  }
 159.687 +}
 159.688 +
 159.689 +void Window::vOnThrottleOther(Gtk::CheckMenuItem * _poCMI)
 159.690 +{
 159.691 +  if (! _poCMI->get_active())
 159.692 +  {
 159.693 +    return;
 159.694 +  }
 159.695 +
 159.696 +  Glib::RefPtr<Xml> poXml;
 159.697 +  poXml = Xml::create(PKGDATADIR "/vba.glade", "ThrottleDialog");
 159.698 +
 159.699 +  Gtk::Dialog * poDialog = dynamic_cast<Gtk::Dialog *>(poXml->get_widget("ThrottleDialog"));
 159.700 +  Gtk::SpinButton * poSpin = dynamic_cast<Gtk::SpinButton *>(poXml->get_widget("ThrottleSpin"));
 159.701 +
 159.702 +  poDialog->set_transient_for(*this);
 159.703 +
 159.704 +  if (m_iThrottle != 0)
 159.705 +  {
 159.706 +    poSpin->set_value(m_iThrottle);
 159.707 +  }
 159.708 +  else
 159.709 +  {
 159.710 +    poSpin->set_value(100);
 159.711 +  }
 159.712 +
 159.713 +  if (poDialog->run() == Gtk::RESPONSE_OK)
 159.714 +  {
 159.715 +    vSetThrottle(poSpin->get_value_as_int());
 159.716 +  }
 159.717 +
 159.718 +  delete poDialog;
 159.719 +  vSelectBestThrottleItem();
 159.720 +}
 159.721 +
 159.722 +void Window::vOnVideoScaleToggled(Gtk::CheckMenuItem * _poCMI, int _iScale)
 159.723 +{
 159.724 +  if (! _poCMI->get_active())
 159.725 +  {
 159.726 +    return;
 159.727 +  }
 159.728 +
 159.729 +  m_poDisplayConfig->vSetKey("scale", _iScale);
 159.730 +  vUpdateScreen();
 159.731 +}
 159.732 +
 159.733 +void Window::vOnLayerToggled(Gtk::CheckMenuItem * _poCMI, int _iLayer)
 159.734 +{
 159.735 +  int iMask = (0x0100 << _iLayer);
 159.736 +  if (_poCMI->get_active())
 159.737 +  {
 159.738 +    layerSettings |= iMask;
 159.739 +  }
 159.740 +  else
 159.741 +  {
 159.742 +    layerSettings &= ~iMask;
 159.743 +  }
 159.744 +  layerEnable = DISPCNT & layerSettings;
 159.745 +
 159.746 +  const char * acsLayers[] =
 159.747 +  {
 159.748 +    "layer_bg0",
 159.749 +    "layer_bg1",
 159.750 +    "layer_bg2",
 159.751 +    "layer_bg3",
 159.752 +    "layer_obj",
 159.753 +    "layer_win0",
 159.754 +    "layer_win1",
 159.755 +    "layer_objwin"
 159.756 +  };
 159.757 +  m_poCoreConfig->vSetKey(acsLayers[_iLayer], _poCMI->get_active());
 159.758 +}
 159.759 +
 159.760 +void Window::vOnDirectories()
 159.761 +{
 159.762 +  Glib::RefPtr<Xml> poXml;
 159.763 +  poXml = Xml::create(PKGDATADIR "/vba.glade", "DirectoriesDialog");
 159.764 +
 159.765 +  struct
 159.766 +  {
 159.767 +    const char * m_csKey;
 159.768 +    const char * m_csEntry;
 159.769 +    const char * m_csResetButton;
 159.770 +    const char * m_csSelectButton;
 159.771 +  }
 159.772 +  astRow[] =
 159.773 +  {
 159.774 +    { "gba_roms",  "GBARomsDirEntry",   "GBARomsDirResetButton",   "GBARomsDirSelectButton"   },
 159.775 +    { "gb_roms",   "GBRomsDirEntry",    "GBRomsDirResetButton",    "GBRomsDirSelectButton"    },
 159.776 +    { "batteries", "BatteriesDirEntry", "BatteriesDirResetButton", "BatteriesDirSelectButton" },
 159.777 +    { "saves",     "SavesDirEntry",     "SavesDirResetButton",     "SavesDirSelectButton"     },
 159.778 +    { "captures",  "CapturesDirEntry",  "CapturesDirResetButton",  "CapturesDirSelectButton"  }
 159.779 +  };
 159.780 +
 159.781 +  for (guint i = 0; i < G_N_ELEMENTS(astRow); i++)
 159.782 +  {
 159.783 +    Gtk::Entry *  poEntry  = dynamic_cast<Gtk::Entry *>(poXml->get_widget(astRow[i].m_csEntry));
 159.784 +    Gtk::Button * poReset  = dynamic_cast<Gtk::Button *>(poXml->get_widget(astRow[i].m_csResetButton));
 159.785 +    Gtk::Button * poSelect = dynamic_cast<Gtk::Button *>(poXml->get_widget(astRow[i].m_csSelectButton));
 159.786 +
 159.787 +    poEntry->set_text(m_poDirConfig->sGetKey(astRow[i].m_csKey));
 159.788 +
 159.789 +    poReset->signal_clicked().connect(SigC::bind<Gtk::Entry *>(
 159.790 +                                        SigC::slot(*this, &Window::vOnDirectoryReset),
 159.791 +                                        poEntry));
 159.792 +    poSelect->signal_clicked().connect(SigC::bind<Gtk::Entry *>(
 159.793 +                                         SigC::slot(*this, &Window::vOnDirectorySelect),
 159.794 +                                         poEntry));
 159.795 +  }
 159.796 +
 159.797 +  Gtk::Dialog * poDialog = dynamic_cast<Gtk::Dialog *>(poXml->get_widget("DirectoriesDialog"));
 159.798 +  poDialog->set_transient_for(*this);
 159.799 +
 159.800 +  if (poDialog->run() == Gtk::RESPONSE_OK)
 159.801 +  {
 159.802 +    for (guint i = 0; i < G_N_ELEMENTS(astRow); i++)
 159.803 +    {
 159.804 +      Gtk::Entry * poEntry = dynamic_cast<Gtk::Entry *>(poXml->get_widget(astRow[i].m_csEntry));
 159.805 +      Glib::ustring sDir = poEntry->get_text();
 159.806 +      if (! Glib::file_test(sDir, Glib::FILE_TEST_IS_DIR))
 159.807 +      {
 159.808 +        sDir = "";
 159.809 +      }
 159.810 +      m_poDirConfig->vSetKey(astRow[i].m_csKey, sDir);
 159.811 +    }
 159.812 +
 159.813 +    // Needed if saves dir changed
 159.814 +    vUpdateGameSlots();
 159.815 +  }
 159.816 +
 159.817 +  delete poDialog;
 159.818 +}
 159.819 +
 159.820 +void Window::vOnDirectoryReset(Gtk::Entry * _poEntry)
 159.821 +{
 159.822 +  _poEntry->set_text("");
 159.823 +}
 159.824 +
 159.825 +void Window::vOnDirectorySelect(Gtk::Entry * _poEntry)
 159.826 +{
 159.827 +#ifdef GTKMM20
 159.828 +
 159.829 +  Gtk::FileSelection oDialog(_("Select directory"));
 159.830 +  oDialog.set_transient_for(*this);
 159.831 +
 159.832 +  if (_poEntry->get_text() != "")
 159.833 +  {
 159.834 +    oDialog.set_filename(_poEntry->get_text() + "/");
 159.835 +  }
 159.836 +
 159.837 +  if (oDialog.run() == Gtk::RESPONSE_OK)
 159.838 +  {
 159.839 +    std::string sFile = oDialog.get_filename();
 159.840 +    if (! Glib::file_test(sFile, Glib::FILE_TEST_IS_DIR))
 159.841 +    {
 159.842 +      sFile = Glib::path_get_dirname(sFile);
 159.843 +    }
 159.844 +    _poEntry->set_text(sFile);
 159.845 +  }
 159.846 +
 159.847 +#else // ! GTKMM20
 159.848 +
 159.849 +  Gtk::FileChooserDialog oDialog(*this, _("Select directory"),
 159.850 +                                 Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
 159.851 +  oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
 159.852 +  oDialog.add_button(Gtk::Stock::OK,     Gtk::RESPONSE_OK);
 159.853 +
 159.854 +  if (_poEntry->get_text() != "")
 159.855 +  {
 159.856 +    oDialog.add_shortcut_folder(_poEntry->get_text());
 159.857 +    oDialog.set_current_folder(_poEntry->get_text());
 159.858 +  }
 159.859 +
 159.860 +  if (oDialog.run() == Gtk::RESPONSE_OK)
 159.861 +  {
 159.862 +    _poEntry->set_text(oDialog.get_filename());
 159.863 +  }
 159.864 +
 159.865 +#endif // ! GTKMM20
 159.866 +}
 159.867 +
 159.868 +void Window::vOnPauseWhenInactiveToggled(Gtk::CheckMenuItem * _poCMI)
 159.869 +{
 159.870 +  m_poDisplayConfig->vSetKey("pause_when_inactive", _poCMI->get_active());
 159.871 +}
 159.872 +
 159.873 +void Window::vOnSelectBios()
 159.874 +{
 159.875 +#ifdef GTKMM20
 159.876 +
 159.877 +  Gtk::FileSelection oDialog(_("Select BIOS file"));
 159.878 +  oDialog.set_transient_for(*this);
 159.879 +
 159.880 +  if (m_poCoreConfig->sGetKey("bios_file") != "")
 159.881 +  {
 159.882 +    oDialog.set_filename(m_poCoreConfig->sGetKey("bios_file"));
 159.883 +  }
 159.884 +
 159.885 +#else // ! GTKMM20
 159.886 +
 159.887 +  Gtk::FileChooserDialog oDialog(*this, _("Select BIOS file"));
 159.888 +  oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
 159.889 +  oDialog.add_button(Gtk::Stock::OPEN,   Gtk::RESPONSE_OK);
 159.890 +
 159.891 +  if (m_poCoreConfig->sGetKey("bios_file") != "")
 159.892 +  {
 159.893 +    oDialog.set_filename(m_poCoreConfig->sGetKey("bios_file"));
 159.894 +  }
 159.895 +
 159.896 +  const char * acsPattern[] =
 159.897 +  {
 159.898 +    "*.[bB][iI][nN]", "*.[aA][gG][bB]", "*.[gG][bB][aA]",
 159.899 +    "*.[bB][iI][oO][sS]", "*.[zZ][iI][pP]", "*.[zZ]", "*.[gG][zZ]"
 159.900 +  };
 159.901 +
 159.902 +  Gtk::FileFilter oAllFilter;
 159.903 +  oAllFilter.set_name(_("All files"));
 159.904 +  oAllFilter.add_pattern("*");
 159.905 +
 159.906 +  Gtk::FileFilter oBiosFilter;
 159.907 +  oBiosFilter.set_name(_("Gameboy Advance BIOS"));
 159.908 +  for (guint i = 0; i < G_N_ELEMENTS(acsPattern); i++)
 159.909 +  {
 159.910 +    oBiosFilter.add_pattern(acsPattern[i]);
 159.911 +  }
 159.912 +
 159.913 +  oDialog.add_filter(oAllFilter);
 159.914 +  oDialog.add_filter(oBiosFilter);
 159.915 +
 159.916 +  oDialog.set_filter(oBiosFilter);
 159.917 +
 159.918 +#endif // ! GTKMM20
 159.919 +
 159.920 +  while (oDialog.run() == Gtk::RESPONSE_OK)
 159.921 +  {
 159.922 +    if (Glib::file_test(oDialog.get_filename(), Glib::FILE_TEST_IS_REGULAR))
 159.923 +    {
 159.924 +      m_poCoreConfig->vSetKey("bios_file", oDialog.get_filename());
 159.925 +      m_poUseBiosItem->set_sensitive();
 159.926 +      break;
 159.927 +    }
 159.928 +  }
 159.929 +}
 159.930 +
 159.931 +void Window::vOnUseBiosToggled(Gtk::CheckMenuItem * _poCMI)
 159.932 +{
 159.933 +  m_poCoreConfig->vSetKey("use_bios_file", _poCMI->get_active());
 159.934 +}
 159.935 +
 159.936 +void Window::vOnShowSpeedToggled(Gtk::CheckMenuItem * _poCMI, int _iShowSpeed)
 159.937 +{
 159.938 +  if (! _poCMI->get_active())
 159.939 +  {
 159.940 +    return;
 159.941 +  }
 159.942 +
 159.943 +  m_eShowSpeed = (EShowSpeed)_iShowSpeed;
 159.944 +  if (m_eShowSpeed == ShowNone)
 159.945 +  {
 159.946 +    vSetDefaultTitle();
 159.947 +  }
 159.948 +  m_poDisplayConfig->vSetKey("show_speed", _iShowSpeed);
 159.949 +}
 159.950 +
 159.951 +void Window::vOnSaveTypeToggled(Gtk::CheckMenuItem * _poCMI, int _iSaveType)
 159.952 +{
 159.953 +  if (! _poCMI->get_active())
 159.954 +  {
 159.955 +    return;
 159.956 +  }
 159.957 +
 159.958 +  cpuSaveType = _iSaveType;
 159.959 +  m_poCoreConfig->vSetKey("save_type", _iSaveType);
 159.960 +}
 159.961 +
 159.962 +void Window::vOnFlashSizeToggled(Gtk::CheckMenuItem * _poCMI, int _iFlashSize)
 159.963 +{
 159.964 +  if (! _poCMI->get_active())
 159.965 +  {
 159.966 +    return;
 159.967 +  }
 159.968 +
 159.969 +  if (_iFlashSize == 64)
 159.970 +  {
 159.971 +    flashSetSize(0x10000);
 159.972 +  }
 159.973 +  else
 159.974 +  {
 159.975 +    flashSetSize(0x20000);
 159.976 +  }
 159.977 +  m_poCoreConfig->vSetKey("flash_size", _iFlashSize);
 159.978 +}
 159.979 +
 159.980 +void Window::vOnScreenshotFormatToggled(Gtk::CheckMenuItem * _poCMI, std::string _sFormat)
 159.981 +{
 159.982 +  if (! _poCMI->get_active())
 159.983 +  {
 159.984 +    return;
 159.985 +  }
 159.986 +
 159.987 +  m_poCoreConfig->vSetKey("screenshot_format", _sFormat);
 159.988 +}
 159.989 +
 159.990 +void Window::vOnSoundStatusToggled(Gtk::CheckMenuItem * _poCMI, int _iSoundStatus)
 159.991 +{
 159.992 +  if (! _poCMI->get_active())
 159.993 +  {
 159.994 +    return;
 159.995 +  }
 159.996 +
 159.997 +  std::string sSoundStatus;
 159.998 +  switch (_iSoundStatus)
 159.999 +  {
159.1000 +  case SoundOff:
159.1001 +    soundOffFlag = true;
159.1002 +    if (systemSoundOn)
159.1003 +    {
159.1004 +      soundShutdown();
159.1005 +    }
159.1006 +    sSoundStatus = "off";
159.1007 +    break;
159.1008 +  case SoundMute:
159.1009 +    soundDisableChannels(0x30f);
159.1010 +    sSoundStatus = "mute";
159.1011 +    break;
159.1012 +  case SoundOn:
159.1013 +    if (soundOffFlag)
159.1014 +    {
159.1015 +      soundOffFlag = false;
159.1016 +      if (! soundInit())
159.1017 +      {
159.1018 +        m_poSoundOffItem->set_active();
159.1019 +        return;
159.1020 +      }
159.1021 +    }
159.1022 +    soundEnableChannels(0x30f);
159.1023 +    sSoundStatus = "on";
159.1024 +    break;
159.1025 +  }
159.1026 +  m_poSoundConfig->vSetKey("status", sSoundStatus);
159.1027 +}
159.1028 +
159.1029 +void Window::vOnSoundEchoToggled(Gtk::CheckMenuItem * _poCMI)
159.1030 +{
159.1031 +  soundEcho = _poCMI->get_active();
159.1032 +  m_poSoundConfig->vSetKey("echo", soundEcho);
159.1033 +}
159.1034 +
159.1035 +void Window::vOnSoundLowPassToggled(Gtk::CheckMenuItem * _poCMI)
159.1036 +{
159.1037 +  soundLowPass = _poCMI->get_active();
159.1038 +  m_poSoundConfig->vSetKey("low_pass", soundLowPass);
159.1039 +}
159.1040 +
159.1041 +void Window::vOnSoundReverseToggled(Gtk::CheckMenuItem * _poCMI)
159.1042 +{
159.1043 +  soundReverse = _poCMI->get_active();
159.1044 +  m_poSoundConfig->vSetKey("reverse_stereo", soundReverse);
159.1045 +}
159.1046 +
159.1047 +void Window::vOnSoundChannelToggled(Gtk::CheckMenuItem * _poCMI, int _iSoundChannel)
159.1048 +{
159.1049 +  int iShift = _iSoundChannel;
159.1050 +  if (_iSoundChannel > 3)
159.1051 +  {
159.1052 +    iShift += 4;
159.1053 +  }
159.1054 +  int iFlag = 1 << iShift;
159.1055 +  int iActive = soundGetEnabledChannels() & 0x30f;
159.1056 +  if (_poCMI->get_active())
159.1057 +  {
159.1058 +    iActive |= iFlag;
159.1059 +  }
159.1060 +  else
159.1061 +  {
159.1062 +    iActive &= ~iFlag;
159.1063 +  }
159.1064 +  soundEnableChannels(iActive);
159.1065 +  soundDisableChannels(~iActive & 0x30f);
159.1066 +
159.1067 +  const char * acsChannels[] =
159.1068 +  {
159.1069 +    "channel_1",
159.1070 +    "channel_2",
159.1071 +    "channel_3",
159.1072 +    "channel_4",
159.1073 +    "channel_A",
159.1074 +    "channel_B"
159.1075 +  };
159.1076 +  m_poSoundConfig->vSetKey(acsChannels[_iSoundChannel], _poCMI->get_active());
159.1077 +}
159.1078 +
159.1079 +void Window::vOnSoundQualityToggled(Gtk::CheckMenuItem * _poCMI, int _iSoundQuality)
159.1080 +{
159.1081 +  if (! _poCMI->get_active())
159.1082 +  {
159.1083 +    return;
159.1084 +  }
159.1085 +
159.1086 +  m_eSoundQuality = (ESoundQuality)_iSoundQuality;
159.1087 +  if (m_eCartridge == CartridgeGBA)
159.1088 +  {
159.1089 +    soundSetQuality(_iSoundQuality);
159.1090 +  }
159.1091 +  else if (m_eCartridge == CartridgeGB)
159.1092 +  {
159.1093 +    gbSoundSetQuality(_iSoundQuality);
159.1094 +  }
159.1095 +  m_poSoundConfig->vSetKey("quality", _iSoundQuality);
159.1096 +}
159.1097 +
159.1098 +void Window::vOnSoundVolumeToggled(Gtk::CheckMenuItem * _poCMI, int _iSoundVolume)
159.1099 +{
159.1100 +  if (! _poCMI->get_active())
159.1101 +  {
159.1102 +    return;
159.1103 +  }
159.1104 +
159.1105 +  soundVolume = _iSoundVolume;
159.1106 +  m_poSoundConfig->vSetKey("volume", _iSoundVolume);
159.1107 +}
159.1108 +
159.1109 +void Window::vOnGBBorderToggled(Gtk::CheckMenuItem * _poCMI)
159.1110 +{
159.1111 +  gbBorderOn = _poCMI->get_active();
159.1112 +  if (emulating && m_eCartridge == CartridgeGB && _poCMI->get_active())
159.1113 +  {
159.1114 +    gbSgbRenderBorder();
159.1115 +  }
159.1116 +  vUpdateScreen();
159.1117 +  m_poCoreConfig->vSetKey("gb_border", _poCMI->get_active());
159.1118 +}
159.1119 +
159.1120 +void Window::vOnGBPrinterToggled(Gtk::CheckMenuItem * _poCMI)
159.1121 +{
159.1122 +  if (_poCMI->get_active())
159.1123 +  {
159.1124 +    gbSerialFunction = gbPrinterSend;
159.1125 +  }
159.1126 +  else
159.1127 +  {
159.1128 +    gbSerialFunction = NULL;
159.1129 +  }
159.1130 +  m_poCoreConfig->vSetKey("gb_printer", _poCMI->get_active());
159.1131 +}
159.1132 +
159.1133 +void Window::vOnEmulatorTypeToggled(Gtk::CheckMenuItem * _poCMI, int _iEmulatorType)
159.1134 +{
159.1135 +  gbEmulatorType = _iEmulatorType;
159.1136 +  m_poCoreConfig->vSetKey("emulator_type", _iEmulatorType);
159.1137 +}
159.1138 +
159.1139 +void Window::vOnFilter2xToggled(Gtk::CheckMenuItem * _poCMI, int _iFilter2x)
159.1140 +{
159.1141 +  if (! _poCMI->get_active())
159.1142 +  {
159.1143 +    return;
159.1144 +  }
159.1145 +
159.1146 +  m_poScreenArea->vSetFilter2x((EFilter2x)_iFilter2x);
159.1147 +  if (emulating)
159.1148 +  {
159.1149 +    vDrawScreen();
159.1150 +  }
159.1151 +  m_poDisplayConfig->vSetKey("filter2x", _iFilter2x);
159.1152 +}
159.1153 +
159.1154 +void Window::vOnFilterIBToggled(Gtk::CheckMenuItem * _poCMI, int _iFilterIB)
159.1155 +{
159.1156 +  if (! _poCMI->get_active())
159.1157 +  {
159.1158 +    return;
159.1159 +  }
159.1160 +
159.1161 +  m_poScreenArea->vSetFilterIB((EFilterIB)_iFilterIB);
159.1162 +  if (emulating)
159.1163 +  {
159.1164 +    vDrawScreen();
159.1165 +  }
159.1166 +  m_poDisplayConfig->vSetKey("filterIB", _iFilterIB);
159.1167 +}
159.1168 +
159.1169 +#ifdef MMX
159.1170 +void Window::vOnDisableMMXToggled(Gtk::CheckMenuItem * _poCMI)
159.1171 +{
159.1172 +  cpu_mmx = ! _poCMI->get_active();
159.1173 +  m_poDisplayConfig->vSetKey("filter_disable_mmx", _poCMI->get_active());
159.1174 +}
159.1175 +#endif // MMX
159.1176 +
159.1177 +void Window::vOnJoypadConfigure(int _iJoypad)
159.1178 +{
159.1179 +  Glib::RefPtr<Xml> poXml;
159.1180 +  poXml = Xml::create(PKGDATADIR "/vba.glade", "JoypadConfigDialog");
159.1181 +
159.1182 +  JoypadConfigDialog * poDialog = NULL;
159.1183 +  poXml->get_widget_derived<JoypadConfigDialog>("JoypadConfigDialog", poDialog);
159.1184 +  poDialog->set_transient_for(*this);
159.1185 +  poDialog->vSetConfig(m_oJoypads[_iJoypad - 1]);
159.1186 +
159.1187 +  if (poDialog->run() == Gtk::RESPONSE_OK)
159.1188 +  {
159.1189 +    m_oJoypads[_iJoypad - 1] = poDialog->stGetConfig();
159.1190 +    if (_iJoypad == m_poInputConfig->oGetKey<int>("active_joypad"))
159.1191 +    {
159.1192 +      if (m_poKeymap != NULL)
159.1193 +      {
159.1194 +        delete m_poKeymap;
159.1195 +      }
159.1196 +      m_poKeymap = m_oJoypads[_iJoypad - 1].poCreateKeymap();
159.1197 +    }
159.1198 +  }
159.1199 +
159.1200 +  delete poDialog;
159.1201 +}
159.1202 +
159.1203 +void Window::vOnJoypadToggled(Gtk::CheckMenuItem * _poCMI, int _iJoypad)
159.1204 +{
159.1205 +  if (! _poCMI->get_active())
159.1206 +  {
159.1207 +    return;
159.1208 +  }
159.1209 +
159.1210 +  if (m_poKeymap != NULL)
159.1211 +  {
159.1212 +    delete m_poKeymap;
159.1213 +  }
159.1214 +  m_poKeymap = m_oJoypads[_iJoypad - 1].poCreateKeymap();
159.1215 +
159.1216 +  m_poInputConfig->vSetKey("active_joypad", _iJoypad);
159.1217 +}
159.1218 +
159.1219 +void Window::vOnAutofireToggled(Gtk::CheckMenuItem * _poCMI, u32 _uiKeyFlag)
159.1220 +{
159.1221 +  if (_poCMI->get_active())
159.1222 +  {
159.1223 +    m_uiAutofireState |= _uiKeyFlag;
159.1224 +  }
159.1225 +  else
159.1226 +  {
159.1227 +    m_uiAutofireState &= ~_uiKeyFlag;
159.1228 +  }
159.1229 +
159.1230 +  std::string sKey;
159.1231 +  if (_uiKeyFlag == KeyFlagA)
159.1232 +  {
159.1233 +    sKey = "autofire_A";
159.1234 +  }
159.1235 +  else if (_uiKeyFlag == KeyFlagB)
159.1236 +  {
159.1237 +    sKey = "autofire_B";
159.1238 +  }
159.1239 +  else if (_uiKeyFlag == KeyFlagL)
159.1240 +  {
159.1241 +    sKey = "autofire_L";
159.1242 +  }
159.1243 +  else if (_uiKeyFlag == KeyFlagR)
159.1244 +  {
159.1245 +    sKey = "autofire_R";
159.1246 +  }
159.1247 +  m_poInputConfig->vSetKey(sKey, _poCMI->get_active());
159.1248 +}
159.1249 +
159.1250 +void Window::vOnGDBWait()
159.1251 +{
159.1252 +  Glib::RefPtr<Xml> poXml;
159.1253 +  poXml = Xml::create(PKGDATADIR "/vba.glade", "TcpPortDialog");
159.1254 +
159.1255 +  Gtk::Dialog * poDialog = dynamic_cast<Gtk::Dialog *>(poXml->get_widget("TcpPortDialog"));
159.1256 +  Gtk::SpinButton * poSpin = dynamic_cast<Gtk::SpinButton *>(poXml->get_widget("TcpPortSpin"));
159.1257 +
159.1258 +  poDialog->set_transient_for(*this);
159.1259 +
159.1260 +  int iPort = 55555;
159.1261 +  poSpin->set_value(iPort);  
159.1262 +
159.1263 +  bool bOk = false;
159.1264 +  if (poDialog->run() == Gtk::RESPONSE_OK)
159.1265 +  {
159.1266 +    bOk = true;
159.1267 +    iPort = poSpin->get_value_as_int();
159.1268 +  }
159.1269 +  delete poDialog;
159.1270 +
159.1271 +  if (! bOk)
159.1272 +  {
159.1273 +    return;
159.1274 +  }
159.1275 +
159.1276 +  m_eCartridge = CartridgeGBA;
159.1277 +  m_sRomFile   = "gnu_stub";
159.1278 +  m_stEmulator = GBASystem;
159.1279 +
159.1280 +  rom         = (u8 *) malloc(0x2000000);
159.1281 +  workRAM     = (u8 *) calloc(1, 0x40000);
159.1282 +  bios        = (u8 *) calloc(1, 0x4000);
159.1283 +  internalRAM = (u8 *) calloc(1, 0x8000);
159.1284 +  paletteRAM  = (u8 *) calloc(1, 0x400);
159.1285 +  vram        = (u8 *) calloc(1, 0x20000);
159.1286 +  oam         = (u8 *) calloc(1, 0x400);
159.1287 +  pix         = (u8 *) calloc(1, 4 * m_iGBAScreenWidth * m_iGBAScreenHeight);
159.1288 +  ioMem       = (u8 *) calloc(1, 0x400);
159.1289 +
159.1290 +  useBios = m_poCoreConfig->oGetKey<bool>("use_bios_file");
159.1291 +  //CPUInit(m_poCoreConfig->sGetKey("bios_file").c_str(), useBios);
159.1292 +  CPUInit();
159.1293 +  CPUReset();
159.1294 +
159.1295 +  for (std::list<Gtk::Widget *>::iterator it = m_listSensitiveWhenPlaying.begin();
159.1296 +       it != m_listSensitiveWhenPlaying.end();
159.1297 +       it++)
159.1298 +  {
159.1299 +    (*it)->set_sensitive();
159.1300 +  }
159.1301 +
159.1302 +  if (m_poCoreConfig->oGetKey<bool>("load_game_auto"))
159.1303 +  {
159.1304 +    vOnLoadGameMostRecent();
159.1305 +  }
159.1306 +
159.1307 +  vStartEmu();
159.1308 +
159.1309 +  emulating = 1;
159.1310 +
159.1311 +  dbgMain   = remoteStubMain;
159.1312 +  dbgSignal = remoteStubSignal;
159.1313 +  dbgOutput = remoteOutput;
159.1314 +  debugger  = true;
159.1315 +
159.1316 +  remoteSetProtocol(0);
159.1317 +  remoteSetPort(iPort);
159.1318 +  remoteInit();
159.1319 +}
159.1320 +
159.1321 +void Window::vOnGDBLoadAndWait()
159.1322 +{
159.1323 +  bool bLoaded = false;
159.1324 +
159.1325 +  while (m_poFileOpenDialog->run() == Gtk::RESPONSE_OK)
159.1326 +  {
159.1327 +    if (bLoadROM(m_poFileOpenDialog->get_filename()))
159.1328 +    {
159.1329 +      bLoaded = true;
159.1330 +      break;
159.1331 +    }
159.1332 +  }
159.1333 +  m_poFileOpenDialog->hide();
159.1334 +
159.1335 +  if (! bLoaded)
159.1336 +  {
159.1337 +    return;
159.1338 +  }
159.1339 +
159.1340 +  if (m_eCartridge != CartridgeGBA)
159.1341 +  {
159.1342 +    vPopupError(_("Only GBA images are supported."));
159.1343 +    vOnFileClose();
159.1344 +    return;
159.1345 +  }
159.1346 +
159.1347 +  Glib::RefPtr<Xml> poXml;
159.1348 +  poXml = Xml::create(PKGDATADIR "/vba.glade", "TcpPortDialog");
159.1349 +
159.1350 +  Gtk::Dialog * poDialog = dynamic_cast<Gtk::Dialog *>(poXml->get_widget("TcpPortDialog"));
159.1351 +  Gtk::SpinButton * poSpin = dynamic_cast<Gtk::SpinButton *>(poXml->get_widget("TcpPortSpin"));
159.1352 +
159.1353 +  poDialog->set_transient_for(*this);
159.1354 +
159.1355 +  int iPort = 55555;
159.1356 +  poSpin->set_value(iPort);  
159.1357 +
159.1358 +  bool bOk = false;
159.1359 +  if (poDialog->run() == Gtk::RESPONSE_OK)
159.1360 +  {
159.1361 +    bOk = true;
159.1362 +    iPort = poSpin->get_value_as_int();
159.1363 +  }
159.1364 +  delete poDialog;
159.1365 +
159.1366 +  if (! bOk)
159.1367 +  {
159.1368 +    return;
159.1369 +  }
159.1370 +
159.1371 +  dbgMain   = remoteStubMain;
159.1372 +  dbgSignal = remoteStubSignal;
159.1373 +  dbgOutput = remoteOutput;
159.1374 +  debugger  = true;
159.1375 +
159.1376 +  remoteSetProtocol(0);
159.1377 +  remoteSetPort(iPort);
159.1378 +  remoteInit();
159.1379 +}
159.1380 +
159.1381 +void Window::vOnGDBBreak()
159.1382 +{
159.1383 +  if (armState)
159.1384 +  {
159.1385 +    armNextPC -= 4;
159.1386 +    reg[15].I -= 4;
159.1387 +  }
159.1388 +  else
159.1389 +  {
159.1390 +    armNextPC -= 2;
159.1391 +    reg[15].I -= 2;
159.1392 +  }
159.1393 +
159.1394 +  debugger = true;
159.1395 +}
159.1396 +
159.1397 +void Window::vOnGDBDisconnect()
159.1398 +{
159.1399 +  remoteCleanUp();
159.1400 +  debugger = false;
159.1401 +}
159.1402 +
159.1403 +void Window::vOnHelpAbout()
159.1404 +{
159.1405 +  Glib::RefPtr<Xml> poXml;
159.1406 +  poXml = Xml::create(PKGDATADIR "/vba.glade", "AboutDialog");
159.1407 +
159.1408 +  Gtk::Dialog * poDialog = dynamic_cast<Gtk::Dialog *>(poXml->get_widget("AboutDialog"));
159.1409 +  poDialog->set_transient_for(*this);
159.1410 +
159.1411 +  Gtk::Image oIcon(PKGDATADIR "/vba-64.png");
159.1412 +  oIcon.show();
159.1413 +  Gtk::Container * poIconContainer = dynamic_cast<Gtk::Container *>(poXml->get_widget("AboutIconContainer"));
159.1414 +  poIconContainer->add(oIcon);
159.1415 +
159.1416 +  Gtk::Label * poLabel  = dynamic_cast<Gtk::Label *>(poXml->get_widget("VersionLabel"));
159.1417 +  poLabel->set_markup("<b><big>" PACKAGE " " VERSION "</big></b>");
159.1418 +
159.1419 +  poDialog->run();
159.1420 +  delete poDialog;
159.1421 +}
159.1422 +
159.1423 +bool Window::bOnEmuIdle()
159.1424 +{
159.1425 +  if (debugger && m_stEmulator.emuHasDebugger)
159.1426 +  {
159.1427 +    dbgMain();
159.1428 +    return true;
159.1429 +  }
159.1430 +
159.1431 +  if (m_uiThrottleDelay != 0)
159.1432 +  {
159.1433 +    u32 uiTime = SDL_GetTicks();
159.1434 +    if (uiTime - m_uiThrottleLastTime >= m_uiThrottleDelay)
159.1435 +    {
159.1436 +      m_uiThrottleDelay = 0;
159.1437 +      m_uiThrottleLastTime = uiTime;
159.1438 +    }
159.1439 +    else
159.1440 +    {
159.1441 +      return true;
159.1442 +    }
159.1443 +  }
159.1444 +
159.1445 +  m_stEmulator.emuMain(m_stEmulator.emuCount);
159.1446 +  return true;
159.1447 +}
159.1448 +
159.1449 +bool Window::on_focus_in_event(GdkEventFocus * _pstEvent)
159.1450 +{
159.1451 +  if (emulating
159.1452 +      && ! m_bPaused
159.1453 +      && m_poDisplayConfig->oGetKey<bool>("pause_when_inactive"))
159.1454 +  {
159.1455 +    vStartEmu();
159.1456 +    soundResume();
159.1457 +  }
159.1458 +  return false;
159.1459 +}
159.1460 +
159.1461 +bool Window::on_focus_out_event(GdkEventFocus * _pstEvent)
159.1462 +{
159.1463 +  if (emulating
159.1464 +      && ! m_bPaused
159.1465 +      && m_poDisplayConfig->oGetKey<bool>("pause_when_inactive"))
159.1466 +  {
159.1467 +    vStopEmu();
159.1468 +    soundPause();
159.1469 +  }
159.1470 +  return false;
159.1471 +}
159.1472 +
159.1473 +bool Window::on_key_press_event(GdkEventKey * _pstEvent)
159.1474 +{
159.1475 +  EKey eKey;
159.1476 +
159.1477 +  if ((_pstEvent->state & Gtk::AccelGroup::get_default_mod_mask())
159.1478 +      || (eKey = m_poKeymap->eGetKey(_pstEvent->hardware_keycode)) == KeyNone)
159.1479 +  {
159.1480 +    return Gtk::Window::on_key_press_event(_pstEvent);
159.1481 +  }
159.1482 +
159.1483 +  switch (eKey)
159.1484 +  {
159.1485 +  case KeyA:
159.1486 +    m_uiJoypadState |= KeyFlagA;
159.1487 +    break;
159.1488 +  case KeyB:
159.1489 +    m_uiJoypadState |= KeyFlagB;
159.1490 +    break;
159.1491 +  case KeySelect:
159.1492 +    m_uiJoypadState |= KeyFlagSelect;
159.1493 +    break;
159.1494 +  case KeyStart:
159.1495 +    m_uiJoypadState |= KeyFlagStart;
159.1496 +    break;
159.1497 +  case KeyRight:
159.1498 +    m_uiJoypadState |= KeyFlagRight;
159.1499 +    m_uiJoypadState &= ~KeyFlagLeft;
159.1500 +    break;
159.1501 +  case KeyLeft:
159.1502 +    m_uiJoypadState |= KeyFlagLeft;
159.1503 +    m_uiJoypadState &= ~KeyFlagRight;
159.1504 +    break;
159.1505 +  case KeyUp:
159.1506 +    m_uiJoypadState |= KeyFlagUp;
159.1507 +    m_uiJoypadState &= ~KeyFlagDown;
159.1508 +    break;
159.1509 +  case KeyDown:
159.1510 +    m_uiJoypadState |= KeyFlagDown;
159.1511 +    m_uiJoypadState &= ~KeyFlagUp;
159.1512 +    break;
159.1513 +  case KeyR:
159.1514 +    m_uiJoypadState |= KeyFlagR;
159.1515 +    break;
159.1516 +  case KeyL:
159.1517 +    m_uiJoypadState |= KeyFlagL;
159.1518 +    break;
159.1519 +  case KeySpeed:
159.1520 +    m_uiJoypadState |= KeyFlagSpeed;
159.1521 +    break;
159.1522 +  case KeyCapture:
159.1523 +    m_uiJoypadState |= KeyFlagCapture;
159.1524 +    break;
159.1525 +  case KeyNone:
159.1526 +    break;
159.1527 +  }
159.1528 +  return true;
159.1529 +}
159.1530 +
159.1531 +bool Window::on_key_release_event(GdkEventKey * _pstEvent)
159.1532 +{
159.1533 +  EKey eKey;
159.1534 +
159.1535 +  if ((_pstEvent->state & Gtk::AccelGroup::get_default_mod_mask())
159.1536 +      || (eKey = m_poKeymap->eGetKey(_pstEvent->hardware_keycode)) == KeyNone)
159.1537 +  {
159.1538 +    return Gtk::Window::on_key_release_event(_pstEvent);
159.1539 +  }
159.1540 +
159.1541 +  switch (eKey)
159.1542 +  {
159.1543 +  case KeyA:
159.1544 +    m_uiJoypadState &= ~KeyFlagA;
159.1545 +    break;
159.1546 +  case KeyB:
159.1547 +    m_uiJoypadState &= ~KeyFlagB;
159.1548 +    break;
159.1549 +  case KeySelect:
159.1550 +    m_uiJoypadState &= ~KeyFlagSelect;
159.1551 +    break;
159.1552 +  case KeyStart:
159.1553 +    m_uiJoypadState &= ~KeyFlagStart;
159.1554 +    break;
159.1555 +  case KeyRight:
159.1556 +    m_uiJoypadState &= ~KeyFlagRight;
159.1557 +    break;
159.1558 +  case KeyLeft:
159.1559 +    m_uiJoypadState &= ~KeyFlagLeft;
159.1560 +    break;
159.1561 +  case KeyUp:
159.1562 +    m_uiJoypadState &= ~KeyFlagUp;
159.1563 +    break;
159.1564 +  case KeyDown:
159.1565 +    m_uiJoypadState &= ~KeyFlagDown;
159.1566 +    break;
159.1567 +  case KeyR:
159.1568 +    m_uiJoypadState &= ~KeyFlagR;
159.1569 +    break;
159.1570 +  case KeyL:
159.1571 +    m_uiJoypadState &= ~KeyFlagL;
159.1572 +    break;
159.1573 +  case KeySpeed:
159.1574 +    m_uiJoypadState &= ~KeyFlagSpeed;
159.1575 +    break;
159.1576 +  case KeyCapture:
159.1577 +    m_uiJoypadState &= ~KeyFlagCapture;
159.1578 +    break;
159.1579 +  case KeyNone:
159.1580 +    break;
159.1581 +  }
159.1582 +  return true;
159.1583 +}
159.1584 +
159.1585 +} // namespace VBA
   160.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   160.2 +++ b/src/lua/Makefile.am	Sat Mar 03 10:31:27 2012 -0600
   160.3 @@ -0,0 +1,56 @@
   160.4 +noinst_LIBRARIES = libgblua.a
   160.5 +
   160.6 +libgblua_a_SOURCES = \
   160.7 +	src/lapi.c	\
   160.8 +	src/lapi.h	\
   160.9 +	src/lauxlib.c	\
  160.10 +	src/lauxlib.h	\
  160.11 +	src/lbaselib.c	\
  160.12 +	src/lcode.c	\
  160.13 +	src/lcode.h	\
  160.14 +	src/ldblib.c	\
  160.15 +	src/ldebug.c	\
  160.16 +	src/ldebug.h	\
  160.17 +	src/ldo.c	\
  160.18 +	src/ldo.h	\
  160.19 +	src/ldump.c	\
  160.20 +	src/lfunc.c	\
  160.21 +	src/lfunc.h	\
  160.22 +	src/lgc.c	\
  160.23 +	src/lgc.h	\
  160.24 +	src/linit.c	\
  160.25 +	src/liolib.c	\
  160.26 +	src/llex.c	\
  160.27 +	src/llex.h	\
  160.28 +	src/llimit.h	\
  160.29 +	src/lmathlib.c	\
  160.30 +	src/lmem.c	\
  160.31 +	src/lmem.h	\
  160.32 +	src/loadlib.c	\
  160.33 +	src/lobject.c	\
  160.34 +	src/lobject.h	\
  160.35 +	src/lopcodes.c	\
  160.36 +	src/lopcodes.h	\
  160.37 +	src/loslib.c	\
  160.38 +	src/lparser.c	\
  160.39 +	src/lparser.h	\
  160.40 +	src/lstate.c	\
  160.41 +	src/lstate.h	\
  160.42 +	src/lstring.c	\
  160.43 +	src/lstring.h	\
  160.44 +	src/lstrlib.c	\
  160.45 +	src/ltable.c	\
  160.46 +	src/ltable.h	\
  160.47 +	src/ltablib.c	\
  160.48 +	src/ltm.c	\
  160.49 +	src/ltm.h	\
  160.50 +	src/lua.h	\
  160.51 +	src/luaconf.h	\
  160.52 +	src/lualib.h	\
  160.53 +	src/lundump.c	\
  160.54 +	src/lundump.h	\
  160.55 +	src/lvm.c	\
  160.56 +	src/lvm.h	\
  160.57 +	src/lzio.c	\
  160.58 +	src/lzio.h	\
  160.59 +	src/print.c
   161.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   161.2 +++ b/src/lua/src/lapi.c	Sat Mar 03 10:31:27 2012 -0600
   161.3 @@ -0,0 +1,1087 @@
   161.4 +/*
   161.5 +** $Id: lapi.c,v 2.55.1.5 2008/07/04 18:41:18 roberto Exp $
   161.6 +** Lua API
   161.7 +** See Copyright Notice in lua.h
   161.8 +*/
   161.9 +
  161.10 +
  161.11 +#include <assert.h>
  161.12 +#include <math.h>
  161.13 +#include <stdarg.h>
  161.14 +#include <string.h>
  161.15 +
  161.16 +#define lapi_c
  161.17 +#define LUA_CORE
  161.18 +
  161.19 +#include "lua.h"
  161.20 +
  161.21 +#include "lapi.h"
  161.22 +#include "ldebug.h"
  161.23 +#include "ldo.h"
  161.24 +#include "lfunc.h"
  161.25 +#include "lgc.h"
  161.26 +#include "lmem.h"
  161.27 +#include "lobject.h"
  161.28 +#include "lstate.h"
  161.29 +#include "lstring.h"
  161.30 +#include "ltable.h"
  161.31 +#include "ltm.h"
  161.32 +#include "lundump.h"
  161.33 +#include "lvm.h"
  161.34 +
  161.35 +
  161.36 +
  161.37 +const char lua_ident[] =
  161.38 +  "$Lua: " LUA_RELEASE " " LUA_COPYRIGHT " $\n"
  161.39 +  "$Authors: " LUA_AUTHORS " $\n"
  161.40 +  "$URL: www.lua.org $\n";
  161.41 +
  161.42 +
  161.43 +
  161.44 +#define api_checknelems(L, n)	api_check(L, (n) <= (L->top - L->base))
  161.45 +
  161.46 +#define api_checkvalidindex(L, i)	api_check(L, (i) != luaO_nilobject)
  161.47 +
  161.48 +#define api_incr_top(L)   {api_check(L, L->top < L->ci->top); L->top++;}
  161.49 +
  161.50 +
  161.51 +
  161.52 +static TValue *index2adr (lua_State *L, int idx) {
  161.53 +  if (idx > 0) {
  161.54 +    TValue *o = L->base + (idx - 1);
  161.55 +    api_check(L, idx <= L->ci->top - L->base);
  161.56 +    if (o >= L->top) return cast(TValue *, luaO_nilobject);
  161.57 +    else return o;
  161.58 +  }
  161.59 +  else if (idx > LUA_REGISTRYINDEX) {
  161.60 +    api_check(L, idx != 0 && -idx <= L->top - L->base);
  161.61 +    return L->top + idx;
  161.62 +  }
  161.63 +  else switch (idx) {  /* pseudo-indices */
  161.64 +    case LUA_REGISTRYINDEX: return registry(L);
  161.65 +    case LUA_ENVIRONINDEX: {
  161.66 +      Closure *func = curr_func(L);
  161.67 +      sethvalue(L, &L->env, func->c.env);
  161.68 +      return &L->env;
  161.69 +    }
  161.70 +    case LUA_GLOBALSINDEX: return gt(L);
  161.71 +    default: {
  161.72 +      Closure *func = curr_func(L);
  161.73 +      idx = LUA_GLOBALSINDEX - idx;
  161.74 +      return (idx <= func->c.nupvalues)
  161.75 +                ? &func->c.upvalue[idx-1]
  161.76 +                : cast(TValue *, luaO_nilobject);
  161.77 +    }
  161.78 +  }
  161.79 +}
  161.80 +
  161.81 +
  161.82 +static Table *getcurrenv (lua_State *L) {
  161.83 +  if (L->ci == L->base_ci)  /* no enclosing function? */
  161.84 +    return hvalue(gt(L));  /* use global table as environment */
  161.85 +  else {
  161.86 +    Closure *func = curr_func(L);
  161.87 +    return func->c.env;
  161.88 +  }
  161.89 +}
  161.90 +
  161.91 +
  161.92 +void luaA_pushobject (lua_State *L, const TValue *o) {
  161.93 +  setobj2s(L, L->top, o);
  161.94 +  api_incr_top(L);
  161.95 +}
  161.96 +
  161.97 +
  161.98 +LUA_API int lua_checkstack (lua_State *L, int size) {
  161.99 +  int res = 1;
 161.100 +  lua_lock(L);
 161.101 +  if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK)
 161.102 +    res = 0;  /* stack overflow */
 161.103 +  else if (size > 0) {
 161.104 +    luaD_checkstack(L, size);
 161.105 +    if (L->ci->top < L->top + size)
 161.106 +      L->ci->top = L->top + size;
 161.107 +  }
 161.108 +  lua_unlock(L);
 161.109 +  return res;
 161.110 +}
 161.111 +
 161.112 +
 161.113 +LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {
 161.114 +  int i;
 161.115 +  if (from == to) return;
 161.116 +  lua_lock(to);
 161.117 +  api_checknelems(from, n);
 161.118 +  api_check(from, G(from) == G(to));
 161.119 +  api_check(from, to->ci->top - to->top >= n);
 161.120 +  from->top -= n;
 161.121 +  for (i = 0; i < n; i++) {
 161.122 +    setobj2s(to, to->top++, from->top + i);
 161.123 +  }
 161.124 +  lua_unlock(to);
 161.125 +}
 161.126 +
 161.127 +
 161.128 +LUA_API void lua_setlevel (lua_State *from, lua_State *to) {
 161.129 +  to->nCcalls = from->nCcalls;
 161.130 +}
 161.131 +
 161.132 +
 161.133 +LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {
 161.134 +  lua_CFunction old;
 161.135 +  lua_lock(L);
 161.136 +  old = G(L)->panic;
 161.137 +  G(L)->panic = panicf;
 161.138 +  lua_unlock(L);
 161.139 +  return old;
 161.140 +}
 161.141 +
 161.142 +
 161.143 +LUA_API lua_State *lua_newthread (lua_State *L) {
 161.144 +  lua_State *L1;
 161.145 +  lua_lock(L);
 161.146 +  luaC_checkGC(L);
 161.147 +  L1 = luaE_newthread(L);
 161.148 +  setthvalue(L, L->top, L1);
 161.149 +  api_incr_top(L);
 161.150 +  lua_unlock(L);
 161.151 +  luai_userstatethread(L, L1);
 161.152 +  return L1;
 161.153 +}
 161.154 +
 161.155 +
 161.156 +
 161.157 +/*
 161.158 +** basic stack manipulation
 161.159 +*/
 161.160 +
 161.161 +
 161.162 +LUA_API int lua_gettop (lua_State *L) {
 161.163 +  return cast_int(L->top - L->base);
 161.164 +}
 161.165 +
 161.166 +
 161.167 +LUA_API void lua_settop (lua_State *L, int idx) {
 161.168 +  lua_lock(L);
 161.169 +  if (idx >= 0) {
 161.170 +    api_check(L, idx <= L->stack_last - L->base);
 161.171 +    while (L->top < L->base + idx)
 161.172 +      setnilvalue(L->top++);
 161.173 +    L->top = L->base + idx;
 161.174 +  }
 161.175 +  else {
 161.176 +    api_check(L, -(idx+1) <= (L->top - L->base));
 161.177 +    L->top += idx+1;  /* `subtract' index (index is negative) */
 161.178 +  }
 161.179 +  lua_unlock(L);
 161.180 +}
 161.181 +
 161.182 +
 161.183 +LUA_API void lua_remove (lua_State *L, int idx) {
 161.184 +  StkId p;
 161.185 +  lua_lock(L);
 161.186 +  p = index2adr(L, idx);
 161.187 +  api_checkvalidindex(L, p);
 161.188 +  while (++p < L->top) setobjs2s(L, p-1, p);
 161.189 +  L->top--;
 161.190 +  lua_unlock(L);
 161.191 +}
 161.192 +
 161.193 +
 161.194 +LUA_API void lua_insert (lua_State *L, int idx) {
 161.195 +  StkId p;
 161.196 +  StkId q;
 161.197 +  lua_lock(L);
 161.198 +  p = index2adr(L, idx);
 161.199 +  api_checkvalidindex(L, p);
 161.200 +  for (q = L->top; q>p; q--) setobjs2s(L, q, q-1);
 161.201 +  setobjs2s(L, p, L->top);
 161.202 +  lua_unlock(L);
 161.203 +}
 161.204 +
 161.205 +
 161.206 +LUA_API void lua_replace (lua_State *L, int idx) {
 161.207 +  StkId o;
 161.208 +  lua_lock(L);
 161.209 +  /* explicit test for incompatible code */
 161.210 +  if (idx == LUA_ENVIRONINDEX && L->ci == L->base_ci)
 161.211 +    luaG_runerror(L, "no calling environment");
 161.212 +  api_checknelems(L, 1);
 161.213 +  o = index2adr(L, idx);
 161.214 +  api_checkvalidindex(L, o);
 161.215 +  if (idx == LUA_ENVIRONINDEX) {
 161.216 +    Closure *func = curr_func(L);
 161.217 +    api_check(L, ttistable(L->top - 1)); 
 161.218 +    func->c.env = hvalue(L->top - 1);
 161.219 +    luaC_barrier(L, func, L->top - 1);
 161.220 +  }
 161.221 +  else {
 161.222 +    setobj(L, o, L->top - 1);
 161.223 +    if (idx < LUA_GLOBALSINDEX)  /* function upvalue? */
 161.224 +      luaC_barrier(L, curr_func(L), L->top - 1);
 161.225 +  }
 161.226 +  L->top--;
 161.227 +  lua_unlock(L);
 161.228 +}
 161.229 +
 161.230 +
 161.231 +LUA_API void lua_pushvalue (lua_State *L, int idx) {
 161.232 +  lua_lock(L);
 161.233 +  setobj2s(L, L->top, index2adr(L, idx));
 161.234 +  api_incr_top(L);
 161.235 +  lua_unlock(L);
 161.236 +}
 161.237 +
 161.238 +
 161.239 +
 161.240 +/*
 161.241 +** access functions (stack -> C)
 161.242 +*/
 161.243 +
 161.244 +
 161.245 +LUA_API int lua_type (lua_State *L, int idx) {
 161.246 +  StkId o = index2adr(L, idx);
 161.247 +  return (o == luaO_nilobject) ? LUA_TNONE : ttype(o);
 161.248 +}
 161.249 +
 161.250 +
 161.251 +LUA_API const char *lua_typename (lua_State *L, int t) {
 161.252 +  UNUSED(L);
 161.253 +  return (t == LUA_TNONE) ? "no value" : luaT_typenames[t];
 161.254 +}
 161.255 +
 161.256 +
 161.257 +LUA_API int lua_iscfunction (lua_State *L, int idx) {
 161.258 +  StkId o = index2adr(L, idx);
 161.259 +  return iscfunction(o);
 161.260 +}
 161.261 +
 161.262 +
 161.263 +LUA_API int lua_isnumber (lua_State *L, int idx) {
 161.264 +  TValue n;
 161.265 +  const TValue *o = index2adr(L, idx);
 161.266 +  return tonumber(o, &n);
 161.267 +}
 161.268 +
 161.269 +
 161.270 +LUA_API int lua_isstring (lua_State *L, int idx) {
 161.271 +  int t = lua_type(L, idx);
 161.272 +  return (t == LUA_TSTRING || t == LUA_TNUMBER);
 161.273 +}
 161.274 +
 161.275 +
 161.276 +LUA_API int lua_isuserdata (lua_State *L, int idx) {
 161.277 +  const TValue *o = index2adr(L, idx);
 161.278 +  return (ttisuserdata(o) || ttislightuserdata(o));
 161.279 +}
 161.280 +
 161.281 +
 161.282 +LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
 161.283 +  StkId o1 = index2adr(L, index1);
 161.284 +  StkId o2 = index2adr(L, index2);
 161.285 +  return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
 161.286 +         : luaO_rawequalObj(o1, o2);
 161.287 +}
 161.288 +
 161.289 +
 161.290 +LUA_API int lua_equal (lua_State *L, int index1, int index2) {
 161.291 +  StkId o1, o2;
 161.292 +  int i;
 161.293 +  lua_lock(L);  /* may call tag method */
 161.294 +  o1 = index2adr(L, index1);
 161.295 +  o2 = index2adr(L, index2);
 161.296 +  i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2);
 161.297 +  lua_unlock(L);
 161.298 +  return i;
 161.299 +}
 161.300 +
 161.301 +
 161.302 +LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
 161.303 +  StkId o1, o2;
 161.304 +  int i;
 161.305 +  lua_lock(L);  /* may call tag method */
 161.306 +  o1 = index2adr(L, index1);
 161.307 +  o2 = index2adr(L, index2);
 161.308 +  i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
 161.309 +       : luaV_lessthan(L, o1, o2);
 161.310 +  lua_unlock(L);
 161.311 +  return i;
 161.312 +}
 161.313 +
 161.314 +
 161.315 +
 161.316 +LUA_API lua_Number lua_tonumber (lua_State *L, int idx) {
 161.317 +  TValue n;
 161.318 +  const TValue *o = index2adr(L, idx);
 161.319 +  if (tonumber(o, &n))
 161.320 +    return nvalue(o);
 161.321 +  else
 161.322 +    return 0;
 161.323 +}
 161.324 +
 161.325 +
 161.326 +LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) {
 161.327 +  TValue n;
 161.328 +  const TValue *o = index2adr(L, idx);
 161.329 +  if (tonumber(o, &n)) {
 161.330 +    lua_Integer res;
 161.331 +    lua_Number num = nvalue(o);
 161.332 +    lua_number2integer(res, num);
 161.333 +    return res;
 161.334 +  }
 161.335 +  else
 161.336 +    return 0;
 161.337 +}
 161.338 +
 161.339 +
 161.340 +LUA_API int lua_toboolean (lua_State *L, int idx) {
 161.341 +  const TValue *o = index2adr(L, idx);
 161.342 +  return !l_isfalse(o);
 161.343 +}
 161.344 +
 161.345 +
 161.346 +LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
 161.347 +  StkId o = index2adr(L, idx);
 161.348 +  if (!ttisstring(o)) {
 161.349 +    lua_lock(L);  /* `luaV_tostring' may create a new string */
 161.350 +    if (!luaV_tostring(L, o)) {  /* conversion failed? */
 161.351 +      if (len != NULL) *len = 0;
 161.352 +      lua_unlock(L);
 161.353 +      return NULL;
 161.354 +    }
 161.355 +    luaC_checkGC(L);
 161.356 +    o = index2adr(L, idx);  /* previous call may reallocate the stack */
 161.357 +    lua_unlock(L);
 161.358 +  }
 161.359 +  if (len != NULL) *len = tsvalue(o)->len;
 161.360 +  return svalue(o);
 161.361 +}
 161.362 +
 161.363 +
 161.364 +LUA_API size_t lua_objlen (lua_State *L, int idx) {
 161.365 +  StkId o = index2adr(L, idx);
 161.366 +  switch (ttype(o)) {
 161.367 +    case LUA_TSTRING: return tsvalue(o)->len;
 161.368 +    case LUA_TUSERDATA: return uvalue(o)->len;
 161.369 +    case LUA_TTABLE: return luaH_getn(hvalue(o));
 161.370 +    case LUA_TNUMBER: {
 161.371 +      size_t l;
 161.372 +      lua_lock(L);  /* `luaV_tostring' may create a new string */
 161.373 +      l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0);
 161.374 +      lua_unlock(L);
 161.375 +      return l;
 161.376 +    }
 161.377 +    default: return 0;
 161.378 +  }
 161.379 +}
 161.380 +
 161.381 +
 161.382 +LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {
 161.383 +  StkId o = index2adr(L, idx);
 161.384 +  return (!iscfunction(o)) ? NULL : clvalue(o)->c.f;
 161.385 +}
 161.386 +
 161.387 +
 161.388 +LUA_API void *lua_touserdata (lua_State *L, int idx) {
 161.389 +  StkId o = index2adr(L, idx);
 161.390 +  switch (ttype(o)) {
 161.391 +    case LUA_TUSERDATA: return (rawuvalue(o) + 1);
 161.392 +    case LUA_TLIGHTUSERDATA: return pvalue(o);
 161.393 +    default: return NULL;
 161.394 +  }
 161.395 +}
 161.396 +
 161.397 +
 161.398 +LUA_API lua_State *lua_tothread (lua_State *L, int idx) {
 161.399 +  StkId o = index2adr(L, idx);
 161.400 +  return (!ttisthread(o)) ? NULL : thvalue(o);
 161.401 +}
 161.402 +
 161.403 +
 161.404 +LUA_API const void *lua_topointer (lua_State *L, int idx) {
 161.405 +  StkId o = index2adr(L, idx);
 161.406 +  switch (ttype(o)) {
 161.407 +    case LUA_TTABLE: return hvalue(o);
 161.408 +    case LUA_TFUNCTION: return clvalue(o);
 161.409 +    case LUA_TTHREAD: return thvalue(o);
 161.410 +    case LUA_TUSERDATA:
 161.411 +    case LUA_TLIGHTUSERDATA:
 161.412 +      return lua_touserdata(L, idx);
 161.413 +    default: return NULL;
 161.414 +  }
 161.415 +}
 161.416 +
 161.417 +
 161.418 +
 161.419 +/*
 161.420 +** push functions (C -> stack)
 161.421 +*/
 161.422 +
 161.423 +
 161.424 +LUA_API void lua_pushnil (lua_State *L) {
 161.425 +  lua_lock(L);
 161.426 +  setnilvalue(L->top);
 161.427 +  api_incr_top(L);
 161.428 +  lua_unlock(L);
 161.429 +}
 161.430 +
 161.431 +
 161.432 +LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
 161.433 +  lua_lock(L);
 161.434 +  setnvalue(L->top, n);
 161.435 +  api_incr_top(L);
 161.436 +  lua_unlock(L);
 161.437 +}
 161.438 +
 161.439 +
 161.440 +LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
 161.441 +  lua_lock(L);
 161.442 +  setnvalue(L->top, cast_num(n));
 161.443 +  api_incr_top(L);
 161.444 +  lua_unlock(L);
 161.445 +}
 161.446 +
 161.447 +
 161.448 +LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {
 161.449 +  lua_lock(L);
 161.450 +  luaC_checkGC(L);
 161.451 +  setsvalue2s(L, L->top, luaS_newlstr(L, s, len));
 161.452 +  api_incr_top(L);
 161.453 +  lua_unlock(L);
 161.454 +}
 161.455 +
 161.456 +
 161.457 +LUA_API void lua_pushstring (lua_State *L, const char *s) {
 161.458 +  if (s == NULL)
 161.459 +    lua_pushnil(L);
 161.460 +  else
 161.461 +    lua_pushlstring(L, s, strlen(s));
 161.462 +}
 161.463 +
 161.464 +
 161.465 +LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,
 161.466 +                                      va_list argp) {
 161.467 +  const char *ret;
 161.468 +  lua_lock(L);
 161.469 +  luaC_checkGC(L);
 161.470 +  ret = luaO_pushvfstring(L, fmt, argp);
 161.471 +  lua_unlock(L);
 161.472 +  return ret;
 161.473 +}
 161.474 +
 161.475 +
 161.476 +LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {
 161.477 +  const char *ret;
 161.478 +  va_list argp;
 161.479 +  lua_lock(L);
 161.480 +  luaC_checkGC(L);
 161.481 +  va_start(argp, fmt);
 161.482 +  ret = luaO_pushvfstring(L, fmt, argp);
 161.483 +  va_end(argp);
 161.484 +  lua_unlock(L);
 161.485 +  return ret;
 161.486 +}
 161.487 +
 161.488 +
 161.489 +LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
 161.490 +  Closure *cl;
 161.491 +  lua_lock(L);
 161.492 +  luaC_checkGC(L);
 161.493 +  api_checknelems(L, n);
 161.494 +  cl = luaF_newCclosure(L, n, getcurrenv(L));
 161.495 +  cl->c.f = fn;
 161.496 +  L->top -= n;
 161.497 +  while (n--)
 161.498 +    setobj2n(L, &cl->c.upvalue[n], L->top+n);
 161.499 +  setclvalue(L, L->top, cl);
 161.500 +  lua_assert(iswhite(obj2gco(cl)));
 161.501 +  api_incr_top(L);
 161.502 +  lua_unlock(L);
 161.503 +}
 161.504 +
 161.505 +
 161.506 +LUA_API void lua_pushboolean (lua_State *L, int b) {
 161.507 +  lua_lock(L);
 161.508 +  setbvalue(L->top, (b != 0));  /* ensure that true is 1 */
 161.509 +  api_incr_top(L);
 161.510 +  lua_unlock(L);
 161.511 +}
 161.512 +
 161.513 +
 161.514 +LUA_API void lua_pushlightuserdata (lua_State *L, void *p) {
 161.515 +  lua_lock(L);
 161.516 +  setpvalue(L->top, p);
 161.517 +  api_incr_top(L);
 161.518 +  lua_unlock(L);
 161.519 +}
 161.520 +
 161.521 +
 161.522 +LUA_API int lua_pushthread (lua_State *L) {
 161.523 +  lua_lock(L);
 161.524 +  setthvalue(L, L->top, L);
 161.525 +  api_incr_top(L);
 161.526 +  lua_unlock(L);
 161.527 +  return (G(L)->mainthread == L);
 161.528 +}
 161.529 +
 161.530 +
 161.531 +
 161.532 +/*
 161.533 +** get functions (Lua -> stack)
 161.534 +*/
 161.535 +
 161.536 +
 161.537 +LUA_API void lua_gettable (lua_State *L, int idx) {
 161.538 +  StkId t;
 161.539 +  lua_lock(L);
 161.540 +  t = index2adr(L, idx);
 161.541 +  api_checkvalidindex(L, t);
 161.542 +  luaV_gettable(L, t, L->top - 1, L->top - 1);
 161.543 +  lua_unlock(L);
 161.544 +}
 161.545 +
 161.546 +
 161.547 +LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
 161.548 +  StkId t;
 161.549 +  TValue key;
 161.550 +  lua_lock(L);
 161.551 +  t = index2adr(L, idx);
 161.552 +  api_checkvalidindex(L, t);
 161.553 +  setsvalue(L, &key, luaS_new(L, k));
 161.554 +  luaV_gettable(L, t, &key, L->top);
 161.555 +  api_incr_top(L);
 161.556 +  lua_unlock(L);
 161.557 +}
 161.558 +
 161.559 +
 161.560 +LUA_API void lua_rawget (lua_State *L, int idx) {
 161.561 +  StkId t;
 161.562 +  lua_lock(L);
 161.563 +  t = index2adr(L, idx);
 161.564 +  api_check(L, ttistable(t));
 161.565 +  setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));
 161.566 +  lua_unlock(L);
 161.567 +}
 161.568 +
 161.569 +
 161.570 +LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
 161.571 +  StkId o;
 161.572 +  lua_lock(L);
 161.573 +  o = index2adr(L, idx);
 161.574 +  api_check(L, ttistable(o));
 161.575 +  setobj2s(L, L->top, luaH_getnum(hvalue(o), n));
 161.576 +  api_incr_top(L);
 161.577 +  lua_unlock(L);
 161.578 +}
 161.579 +
 161.580 +
 161.581 +LUA_API void lua_createtable (lua_State *L, int narray, int nrec) {
 161.582 +  lua_lock(L);
 161.583 +  luaC_checkGC(L);
 161.584 +  sethvalue(L, L->top, luaH_new(L, narray, nrec));
 161.585 +  api_incr_top(L);
 161.586 +  lua_unlock(L);
 161.587 +}
 161.588 +
 161.589 +
 161.590 +LUA_API int lua_getmetatable (lua_State *L, int objindex) {
 161.591 +  const TValue *obj;
 161.592 +  Table *mt = NULL;
 161.593 +  int res;
 161.594 +  lua_lock(L);
 161.595 +  obj = index2adr(L, objindex);
 161.596 +  switch (ttype(obj)) {
 161.597 +    case LUA_TTABLE:
 161.598 +      mt = hvalue(obj)->metatable;
 161.599 +      break;
 161.600 +    case LUA_TUSERDATA:
 161.601 +      mt = uvalue(obj)->metatable;
 161.602 +      break;
 161.603 +    default:
 161.604 +      mt = G(L)->mt[ttype(obj)];
 161.605 +      break;
 161.606 +  }
 161.607 +  if (mt == NULL)
 161.608 +    res = 0;
 161.609 +  else {
 161.610 +    sethvalue(L, L->top, mt);
 161.611 +    api_incr_top(L);
 161.612 +    res = 1;
 161.613 +  }
 161.614 +  lua_unlock(L);
 161.615 +  return res;
 161.616 +}
 161.617 +
 161.618 +
 161.619 +LUA_API void lua_getfenv (lua_State *L, int idx) {
 161.620 +  StkId o;
 161.621 +  lua_lock(L);
 161.622 +  o = index2adr(L, idx);
 161.623 +  api_checkvalidindex(L, o);
 161.624 +  switch (ttype(o)) {
 161.625 +    case LUA_TFUNCTION:
 161.626 +      sethvalue(L, L->top, clvalue(o)->c.env);
 161.627 +      break;
 161.628 +    case LUA_TUSERDATA:
 161.629 +      sethvalue(L, L->top, uvalue(o)->env);
 161.630 +      break;
 161.631 +    case LUA_TTHREAD:
 161.632 +      setobj2s(L, L->top,  gt(thvalue(o)));
 161.633 +      break;
 161.634 +    default:
 161.635 +      setnilvalue(L->top);
 161.636 +      break;
 161.637 +  }
 161.638 +  api_incr_top(L);
 161.639 +  lua_unlock(L);
 161.640 +}
 161.641 +
 161.642 +
 161.643 +/*
 161.644 +** set functions (stack -> Lua)
 161.645 +*/
 161.646 +
 161.647 +
 161.648 +LUA_API void lua_settable (lua_State *L, int idx) {
 161.649 +  StkId t;
 161.650 +  lua_lock(L);
 161.651 +  api_checknelems(L, 2);
 161.652 +  t = index2adr(L, idx);
 161.653 +  api_checkvalidindex(L, t);
 161.654 +  luaV_settable(L, t, L->top - 2, L->top - 1);
 161.655 +  L->top -= 2;  /* pop index and value */
 161.656 +  lua_unlock(L);
 161.657 +}
 161.658 +
 161.659 +
 161.660 +LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
 161.661 +  StkId t;
 161.662 +  TValue key;
 161.663 +  lua_lock(L);
 161.664 +  api_checknelems(L, 1);
 161.665 +  t = index2adr(L, idx);
 161.666 +  api_checkvalidindex(L, t);
 161.667 +  setsvalue(L, &key, luaS_new(L, k));
 161.668 +  luaV_settable(L, t, &key, L->top - 1);
 161.669 +  L->top--;  /* pop value */
 161.670 +  lua_unlock(L);
 161.671 +}
 161.672 +
 161.673 +
 161.674 +LUA_API void lua_rawset (lua_State *L, int idx) {
 161.675 +  StkId t;
 161.676 +  lua_lock(L);
 161.677 +  api_checknelems(L, 2);
 161.678 +  t = index2adr(L, idx);
 161.679 +  api_check(L, ttistable(t));
 161.680 +  setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
 161.681 +  luaC_barriert(L, hvalue(t), L->top-1);
 161.682 +  L->top -= 2;
 161.683 +  lua_unlock(L);
 161.684 +}
 161.685 +
 161.686 +
 161.687 +LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
 161.688 +  StkId o;
 161.689 +  lua_lock(L);
 161.690 +  api_checknelems(L, 1);
 161.691 +  o = index2adr(L, idx);
 161.692 +  api_check(L, ttistable(o));
 161.693 +  setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1);
 161.694 +  luaC_barriert(L, hvalue(o), L->top-1);
 161.695 +  L->top--;
 161.696 +  lua_unlock(L);
 161.697 +}
 161.698 +
 161.699 +
 161.700 +LUA_API int lua_setmetatable (lua_State *L, int objindex) {
 161.701 +  TValue *obj;
 161.702 +  Table *mt;
 161.703 +  lua_lock(L);
 161.704 +  api_checknelems(L, 1);
 161.705 +  obj = index2adr(L, objindex);
 161.706 +  api_checkvalidindex(L, obj);
 161.707 +  if (ttisnil(L->top - 1))
 161.708 +    mt = NULL;
 161.709 +  else {
 161.710 +    api_check(L, ttistable(L->top - 1));
 161.711 +    mt = hvalue(L->top - 1);
 161.712 +  }
 161.713 +  switch (ttype(obj)) {
 161.714 +    case LUA_TTABLE: {
 161.715 +      hvalue(obj)->metatable = mt;
 161.716 +      if (mt)
 161.717 +        luaC_objbarriert(L, hvalue(obj), mt);
 161.718 +      break;
 161.719 +    }
 161.720 +    case LUA_TUSERDATA: {
 161.721 +      uvalue(obj)->metatable = mt;
 161.722 +      if (mt)
 161.723 +        luaC_objbarrier(L, rawuvalue(obj), mt);
 161.724 +      break;
 161.725 +    }
 161.726 +    default: {
 161.727 +      G(L)->mt[ttype(obj)] = mt;
 161.728 +      break;
 161.729 +    }
 161.730 +  }
 161.731 +  L->top--;
 161.732 +  lua_unlock(L);
 161.733 +  return 1;
 161.734 +}
 161.735 +
 161.736 +
 161.737 +LUA_API int lua_setfenv (lua_State *L, int idx) {
 161.738 +  StkId o;
 161.739 +  int res = 1;
 161.740 +  lua_lock(L);
 161.741 +  api_checknelems(L, 1);
 161.742 +  o = index2adr(L, idx);
 161.743 +  api_checkvalidindex(L, o);
 161.744 +  api_check(L, ttistable(L->top - 1));
 161.745 +  switch (ttype(o)) {
 161.746 +    case LUA_TFUNCTION:
 161.747 +      clvalue(o)->c.env = hvalue(L->top - 1);
 161.748 +      break;
 161.749 +    case LUA_TUSERDATA:
 161.750 +      uvalue(o)->env = hvalue(L->top - 1);
 161.751 +      break;
 161.752 +    case LUA_TTHREAD:
 161.753 +      sethvalue(L, gt(thvalue(o)), hvalue(L->top - 1));
 161.754 +      break;
 161.755 +    default:
 161.756 +      res = 0;
 161.757 +      break;
 161.758 +  }
 161.759 +  if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
 161.760 +  L->top--;
 161.761 +  lua_unlock(L);
 161.762 +  return res;
 161.763 +}
 161.764 +
 161.765 +
 161.766 +/*
 161.767 +** `load' and `call' functions (run Lua code)
 161.768 +*/
 161.769 +
 161.770 +
 161.771 +#define adjustresults(L,nres) \
 161.772 +    { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; }
 161.773 +
 161.774 +
 161.775 +#define checkresults(L,na,nr) \
 161.776 +     api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)))
 161.777 +	
 161.778 +
 161.779 +LUA_API void lua_call (lua_State *L, int nargs, int nresults) {
 161.780 +  StkId func;
 161.781 +  lua_lock(L);
 161.782 +  api_checknelems(L, nargs+1);
 161.783 +  checkresults(L, nargs, nresults);
 161.784 +  func = L->top - (nargs+1);
 161.785 +  luaD_call(L, func, nresults);
 161.786 +  adjustresults(L, nresults);
 161.787 +  lua_unlock(L);
 161.788 +}
 161.789 +
 161.790 +
 161.791 +
 161.792 +/*
 161.793 +** Execute a protected call.
 161.794 +*/
 161.795 +struct CallS {  /* data to `f_call' */
 161.796 +  StkId func;
 161.797 +  int nresults;
 161.798 +};
 161.799 +
 161.800 +
 161.801 +static void f_call (lua_State *L, void *ud) {
 161.802 +  struct CallS *c = cast(struct CallS *, ud);
 161.803 +  luaD_call(L, c->func, c->nresults);
 161.804 +}
 161.805 +
 161.806 +
 161.807 +
 161.808 +LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) {
 161.809 +  struct CallS c;
 161.810 +  int status;
 161.811 +  ptrdiff_t func;
 161.812 +  lua_lock(L);
 161.813 +  api_checknelems(L, nargs+1);
 161.814 +  checkresults(L, nargs, nresults);
 161.815 +  if (errfunc == 0)
 161.816 +    func = 0;
 161.817 +  else {
 161.818 +    StkId o = index2adr(L, errfunc);
 161.819 +    api_checkvalidindex(L, o);
 161.820 +    func = savestack(L, o);
 161.821 +  }
 161.822 +  c.func = L->top - (nargs+1);  /* function to be called */
 161.823 +  c.nresults = nresults;
 161.824 +  status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
 161.825 +  adjustresults(L, nresults);
 161.826 +  lua_unlock(L);
 161.827 +  return status;
 161.828 +}
 161.829 +
 161.830 +
 161.831 +/*
 161.832 +** Execute a protected C call.
 161.833 +*/
 161.834 +struct CCallS {  /* data to `f_Ccall' */
 161.835 +  lua_CFunction func;
 161.836 +  void *ud;
 161.837 +};
 161.838 +
 161.839 +
 161.840 +static void f_Ccall (lua_State *L, void *ud) {
 161.841 +  struct CCallS *c = cast(struct CCallS *, ud);
 161.842 +  Closure *cl;
 161.843 +  cl = luaF_newCclosure(L, 0, getcurrenv(L));
 161.844 +  cl->c.f = c->func;
 161.845 +  setclvalue(L, L->top, cl);  /* push function */
 161.846 +  api_incr_top(L);
 161.847 +  setpvalue(L->top, c->ud);  /* push only argument */
 161.848 +  api_incr_top(L);
 161.849 +  luaD_call(L, L->top - 2, 0);
 161.850 +}
 161.851 +
 161.852 +
 161.853 +LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) {
 161.854 +  struct CCallS c;
 161.855 +  int status;
 161.856 +  lua_lock(L);
 161.857 +  c.func = func;
 161.858 +  c.ud = ud;
 161.859 +  status = luaD_pcall(L, f_Ccall, &c, savestack(L, L->top), 0);
 161.860 +  lua_unlock(L);
 161.861 +  return status;
 161.862 +}
 161.863 +
 161.864 +
 161.865 +LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
 161.866 +                      const char *chunkname) {
 161.867 +  ZIO z;
 161.868 +  int status;
 161.869 +  lua_lock(L);
 161.870 +  if (!chunkname) chunkname = "?";
 161.871 +  luaZ_init(L, &z, reader, data);
 161.872 +  status = luaD_protectedparser(L, &z, chunkname);
 161.873 +  lua_unlock(L);
 161.874 +  return status;
 161.875 +}
 161.876 +
 161.877 +
 161.878 +LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) {
 161.879 +  int status;
 161.880 +  TValue *o;
 161.881 +  lua_lock(L);
 161.882 +  api_checknelems(L, 1);
 161.883 +  o = L->top - 1;
 161.884 +  if (isLfunction(o))
 161.885 +    status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0);
 161.886 +  else
 161.887 +    status = 1;
 161.888 +  lua_unlock(L);
 161.889 +  return status;
 161.890 +}
 161.891 +
 161.892 +
 161.893 +LUA_API int  lua_status (lua_State *L) {
 161.894 +  return L->status;
 161.895 +}
 161.896 +
 161.897 +
 161.898 +/*
 161.899 +** Garbage-collection function
 161.900 +*/
 161.901 +
 161.902 +LUA_API int lua_gc (lua_State *L, int what, int data) {
 161.903 +  int res = 0;
 161.904 +  global_State *g;
 161.905 +  lua_lock(L);
 161.906 +  g = G(L);
 161.907 +  switch (what) {
 161.908 +    case LUA_GCSTOP: {
 161.909 +      g->GCthreshold = MAX_LUMEM;
 161.910 +      break;
 161.911 +    }
 161.912 +    case LUA_GCRESTART: {
 161.913 +      g->GCthreshold = g->totalbytes;
 161.914 +      break;
 161.915 +    }
 161.916 +    case LUA_GCCOLLECT: {
 161.917 +      luaC_fullgc(L);
 161.918 +      break;
 161.919 +    }
 161.920 +    case LUA_GCCOUNT: {
 161.921 +      /* GC values are expressed in Kbytes: #bytes/2^10 */
 161.922 +      res = cast_int(g->totalbytes >> 10);
 161.923 +      break;
 161.924 +    }
 161.925 +    case LUA_GCCOUNTB: {
 161.926 +      res = cast_int(g->totalbytes & 0x3ff);
 161.927 +      break;
 161.928 +    }
 161.929 +    case LUA_GCSTEP: {
 161.930 +      lu_mem a = (cast(lu_mem, data) << 10);
 161.931 +      if (a <= g->totalbytes)
 161.932 +        g->GCthreshold = g->totalbytes - a;
 161.933 +      else
 161.934 +        g->GCthreshold = 0;
 161.935 +      while (g->GCthreshold <= g->totalbytes) {
 161.936 +        luaC_step(L);
 161.937 +        if (g->gcstate == GCSpause) {  /* end of cycle? */
 161.938 +          res = 1;  /* signal it */
 161.939 +          break;
 161.940 +        }
 161.941 +      }
 161.942 +      break;
 161.943 +    }
 161.944 +    case LUA_GCSETPAUSE: {
 161.945 +      res = g->gcpause;
 161.946 +      g->gcpause = data;
 161.947 +      break;
 161.948 +    }
 161.949 +    case LUA_GCSETSTEPMUL: {
 161.950 +      res = g->gcstepmul;
 161.951 +      g->gcstepmul = data;
 161.952 +      break;
 161.953 +    }
 161.954 +    default: res = -1;  /* invalid option */
 161.955 +  }
 161.956 +  lua_unlock(L);
 161.957 +  return res;
 161.958 +}
 161.959 +
 161.960 +
 161.961 +
 161.962 +/*
 161.963 +** miscellaneous functions
 161.964 +*/
 161.965 +
 161.966 +
 161.967 +LUA_API int lua_error (lua_State *L) {
 161.968 +  lua_lock(L);
 161.969 +  api_checknelems(L, 1);
 161.970 +  luaG_errormsg(L);
 161.971 +  lua_unlock(L);
 161.972 +  return 0;  /* to avoid warnings */
 161.973 +}
 161.974 +
 161.975 +
 161.976 +LUA_API int lua_next (lua_State *L, int idx) {
 161.977 +  StkId t;
 161.978 +  int more;
 161.979 +  lua_lock(L);
 161.980 +  t = index2adr(L, idx);
 161.981 +  api_check(L, ttistable(t));
 161.982 +  more = luaH_next(L, hvalue(t), L->top - 1);
 161.983 +  if (more) {
 161.984 +    api_incr_top(L);
 161.985 +  }
 161.986 +  else  /* no more elements */
 161.987 +    L->top -= 1;  /* remove key */
 161.988 +  lua_unlock(L);
 161.989 +  return more;
 161.990 +}
 161.991 +
 161.992 +
 161.993 +LUA_API void lua_concat (lua_State *L, int n) {
 161.994 +  lua_lock(L);
 161.995 +  api_checknelems(L, n);
 161.996 +  if (n >= 2) {
 161.997 +    luaC_checkGC(L);
 161.998 +    luaV_concat(L, n, cast_int(L->top - L->base) - 1);
 161.999 +    L->top -= (n-1);
161.1000 +  }
161.1001 +  else if (n == 0) {  /* push empty string */
161.1002 +    setsvalue2s(L, L->top, luaS_newlstr(L, "", 0));
161.1003 +    api_incr_top(L);
161.1004 +  }
161.1005 +  /* else n == 1; nothing to do */
161.1006 +  lua_unlock(L);
161.1007 +}
161.1008 +
161.1009 +
161.1010 +LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {
161.1011 +  lua_Alloc f;
161.1012 +  lua_lock(L);
161.1013 +  if (ud) *ud = G(L)->ud;
161.1014 +  f = G(L)->frealloc;
161.1015 +  lua_unlock(L);
161.1016 +  return f;
161.1017 +}
161.1018 +
161.1019 +
161.1020 +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {
161.1021 +  lua_lock(L);
161.1022 +  G(L)->ud = ud;
161.1023 +  G(L)->frealloc = f;
161.1024 +  lua_unlock(L);
161.1025 +}
161.1026 +
161.1027 +
161.1028 +LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
161.1029 +  Udata *u;
161.1030 +  lua_lock(L);
161.1031 +  luaC_checkGC(L);
161.1032 +  u = luaS_newudata(L, size, getcurrenv(L));
161.1033 +  setuvalue(L, L->top, u);
161.1034 +  api_incr_top(L);
161.1035 +  lua_unlock(L);
161.1036 +  return u + 1;
161.1037 +}
161.1038 +
161.1039 +
161.1040 +
161.1041 +
161.1042 +static const char *aux_upvalue (StkId fi, int n, TValue **val) {
161.1043 +  Closure *f;
161.1044 +  if (!ttisfunction(fi)) return NULL;
161.1045 +  f = clvalue(fi);
161.1046 +  if (f->c.isC) {
161.1047 +    if (!(1 <= n && n <= f->c.nupvalues)) return NULL;
161.1048 +    *val = &f->c.upvalue[n-1];
161.1049 +    return "";
161.1050 +  }
161.1051 +  else {
161.1052 +    Proto *p = f->l.p;
161.1053 +    if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
161.1054 +    *val = f->l.upvals[n-1]->v;
161.1055 +    return getstr(p->upvalues[n-1]);
161.1056 +  }
161.1057 +}
161.1058 +
161.1059 +
161.1060 +LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {
161.1061 +  const char *name;
161.1062 +  TValue *val;
161.1063 +  lua_lock(L);
161.1064 +  name = aux_upvalue(index2adr(L, funcindex), n, &val);
161.1065 +  if (name) {
161.1066 +    setobj2s(L, L->top, val);
161.1067 +    api_incr_top(L);
161.1068 +  }
161.1069 +  lua_unlock(L);
161.1070 +  return name;
161.1071 +}
161.1072 +
161.1073 +
161.1074 +LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
161.1075 +  const char *name;
161.1076 +  TValue *val;
161.1077 +  StkId fi;
161.1078 +  lua_lock(L);
161.1079 +  fi = index2adr(L, funcindex);
161.1080 +  api_checknelems(L, 1);
161.1081 +  name = aux_upvalue(fi, n, &val);
161.1082 +  if (name) {
161.1083 +    L->top--;
161.1084 +    setobj(L, val, L->top);
161.1085 +    luaC_barrier(L, clvalue(fi), L->top);
161.1086 +  }
161.1087 +  lua_unlock(L);
161.1088 +  return name;
161.1089 +}
161.1090 +
   162.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   162.2 +++ b/src/lua/src/lapi.h	Sat Mar 03 10:31:27 2012 -0600
   162.3 @@ -0,0 +1,16 @@
   162.4 +/*
   162.5 +** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $
   162.6 +** Auxiliary functions from Lua API
   162.7 +** See Copyright Notice in lua.h
   162.8 +*/
   162.9 +
  162.10 +#ifndef lapi_h
  162.11 +#define lapi_h
  162.12 +
  162.13 +
  162.14 +#include "lobject.h"
  162.15 +
  162.16 +
  162.17 +LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o);
  162.18 +
  162.19 +#endif
   163.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   163.2 +++ b/src/lua/src/lauxlib.c	Sat Mar 03 10:31:27 2012 -0600
   163.3 @@ -0,0 +1,652 @@
   163.4 +/*
   163.5 +** $Id: lauxlib.c,v 1.159.1.3 2008/01/21 13:20:51 roberto Exp $
   163.6 +** Auxiliary functions for building Lua libraries
   163.7 +** See Copyright Notice in lua.h
   163.8 +*/
   163.9 +
  163.10 +
  163.11 +#include <ctype.h>
  163.12 +#include <errno.h>
  163.13 +#include <stdarg.h>
  163.14 +#include <stdio.h>
  163.15 +#include <stdlib.h>
  163.16 +#include <string.h>
  163.17 +
  163.18 +
  163.19 +/* This file uses only the official API of Lua.
  163.20 +** Any function declared here could be written as an application function.
  163.21 +*/
  163.22 +
  163.23 +#define lauxlib_c
  163.24 +#define LUA_LIB
  163.25 +
  163.26 +#include "lua.h"
  163.27 +
  163.28 +#include "lauxlib.h"
  163.29 +
  163.30 +
  163.31 +#define FREELIST_REF	0	/* free list of references */
  163.32 +
  163.33 +
  163.34 +/* convert a stack index to positive */
  163.35 +#define abs_index(L, i)		((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \
  163.36 +					lua_gettop(L) + (i) + 1)
  163.37 +
  163.38 +
  163.39 +/*
  163.40 +** {======================================================
  163.41 +** Error-report functions
  163.42 +** =======================================================
  163.43 +*/
  163.44 +
  163.45 +
  163.46 +LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
  163.47 +  lua_Debug ar;
  163.48 +  if (!lua_getstack(L, 0, &ar))  /* no stack frame? */
  163.49 +    return luaL_error(L, "bad argument #%d (%s)", narg, extramsg);
  163.50 +  lua_getinfo(L, "n", &ar);
  163.51 +  if (strcmp(ar.namewhat, "method") == 0) {
  163.52 +    narg--;  /* do not count `self' */
  163.53 +    if (narg == 0)  /* error is in the self argument itself? */
  163.54 +      return luaL_error(L, "calling " LUA_QS " on bad self (%s)",
  163.55 +                           ar.name, extramsg);
  163.56 +  }
  163.57 +  if (ar.name == NULL)
  163.58 +    ar.name = "?";
  163.59 +  return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)",
  163.60 +                        narg, ar.name, extramsg);
  163.61 +}
  163.62 +
  163.63 +
  163.64 +LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) {
  163.65 +  const char *msg = lua_pushfstring(L, "%s expected, got %s",
  163.66 +                                    tname, luaL_typename(L, narg));
  163.67 +  return luaL_argerror(L, narg, msg);
  163.68 +}
  163.69 +
  163.70 +
  163.71 +static void tag_error (lua_State *L, int narg, int tag) {
  163.72 +  luaL_typerror(L, narg, lua_typename(L, tag));
  163.73 +}
  163.74 +
  163.75 +
  163.76 +LUALIB_API void luaL_where (lua_State *L, int level) {
  163.77 +  lua_Debug ar;
  163.78 +  if (lua_getstack(L, level, &ar)) {  /* check function at level */
  163.79 +    lua_getinfo(L, "Sl", &ar);  /* get info about it */
  163.80 +    if (ar.currentline > 0) {  /* is there info? */
  163.81 +      lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline);
  163.82 +      return;
  163.83 +    }
  163.84 +  }
  163.85 +  lua_pushliteral(L, "");  /* else, no information available... */
  163.86 +}
  163.87 +
  163.88 +
  163.89 +LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {
  163.90 +  va_list argp;
  163.91 +  va_start(argp, fmt);
  163.92 +  luaL_where(L, 1);
  163.93 +  lua_pushvfstring(L, fmt, argp);
  163.94 +  va_end(argp);
  163.95 +  lua_concat(L, 2);
  163.96 +  return lua_error(L);
  163.97 +}
  163.98 +
  163.99 +/* }====================================================== */
 163.100 +
 163.101 +
 163.102 +LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def,
 163.103 +                                 const char *const lst[]) {
 163.104 +  const char *name = (def) ? luaL_optstring(L, narg, def) :
 163.105 +                             luaL_checkstring(L, narg);
 163.106 +  int i;
 163.107 +  for (i=0; lst[i]; i++)
 163.108 +    if (strcmp(lst[i], name) == 0)
 163.109 +      return i;
 163.110 +  return luaL_argerror(L, narg,
 163.111 +                       lua_pushfstring(L, "invalid option " LUA_QS, name));
 163.112 +}
 163.113 +
 163.114 +
 163.115 +LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {
 163.116 +  lua_getfield(L, LUA_REGISTRYINDEX, tname);  /* get registry.name */
 163.117 +  if (!lua_isnil(L, -1))  /* name already in use? */
 163.118 +    return 0;  /* leave previous value on top, but return 0 */
 163.119 +  lua_pop(L, 1);
 163.120 +  lua_newtable(L);  /* create metatable */
 163.121 +  lua_pushvalue(L, -1);
 163.122 +  lua_setfield(L, LUA_REGISTRYINDEX, tname);  /* registry.name = metatable */
 163.123 +  return 1;
 163.124 +}
 163.125 +
 163.126 +
 163.127 +LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
 163.128 +  void *p = lua_touserdata(L, ud);
 163.129 +  if (p != NULL) {  /* value is a userdata? */
 163.130 +    if (lua_getmetatable(L, ud)) {  /* does it have a metatable? */
 163.131 +      lua_getfield(L, LUA_REGISTRYINDEX, tname);  /* get correct metatable */
 163.132 +      if (lua_rawequal(L, -1, -2)) {  /* does it have the correct mt? */
 163.133 +        lua_pop(L, 2);  /* remove both metatables */
 163.134 +        return p;
 163.135 +      }
 163.136 +    }
 163.137 +  }
 163.138 +  luaL_typerror(L, ud, tname);  /* else error */
 163.139 +  return NULL;  /* to avoid warnings */
 163.140 +}
 163.141 +
 163.142 +
 163.143 +LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) {
 163.144 +  if (!lua_checkstack(L, space))
 163.145 +    luaL_error(L, "stack overflow (%s)", mes);
 163.146 +}
 163.147 +
 163.148 +
 163.149 +LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) {
 163.150 +  if (lua_type(L, narg) != t)
 163.151 +    tag_error(L, narg, t);
 163.152 +}
 163.153 +
 163.154 +
 163.155 +LUALIB_API void luaL_checkany (lua_State *L, int narg) {
 163.156 +  if (lua_type(L, narg) == LUA_TNONE)
 163.157 +    luaL_argerror(L, narg, "value expected");
 163.158 +}
 163.159 +
 163.160 +
 163.161 +LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) {
 163.162 +  const char *s = lua_tolstring(L, narg, len);
 163.163 +  if (!s) tag_error(L, narg, LUA_TSTRING);
 163.164 +  return s;
 163.165 +}
 163.166 +
 163.167 +
 163.168 +LUALIB_API const char *luaL_optlstring (lua_State *L, int narg,
 163.169 +                                        const char *def, size_t *len) {
 163.170 +  if (lua_isnoneornil(L, narg)) {
 163.171 +    if (len)
 163.172 +      *len = (def ? strlen(def) : 0);
 163.173 +    return def;
 163.174 +  }
 163.175 +  else return luaL_checklstring(L, narg, len);
 163.176 +}
 163.177 +
 163.178 +
 163.179 +LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) {
 163.180 +  lua_Number d = lua_tonumber(L, narg);
 163.181 +  if (d == 0 && !lua_isnumber(L, narg))  /* avoid extra test when d is not 0 */
 163.182 +    tag_error(L, narg, LUA_TNUMBER);
 163.183 +  return d;
 163.184 +}
 163.185 +
 163.186 +
 163.187 +LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) {
 163.188 +  return luaL_opt(L, luaL_checknumber, narg, def);
 163.189 +}
 163.190 +
 163.191 +
 163.192 +LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) {
 163.193 +  lua_Integer d = lua_tointeger(L, narg);
 163.194 +  if (d == 0 && !lua_isnumber(L, narg))  /* avoid extra test when d is not 0 */
 163.195 +    tag_error(L, narg, LUA_TNUMBER);
 163.196 +  return d;
 163.197 +}
 163.198 +
 163.199 +
 163.200 +LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,
 163.201 +                                                      lua_Integer def) {
 163.202 +  return luaL_opt(L, luaL_checkinteger, narg, def);
 163.203 +}
 163.204 +
 163.205 +
 163.206 +LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {
 163.207 +  if (!lua_getmetatable(L, obj))  /* no metatable? */
 163.208 +    return 0;
 163.209 +  lua_pushstring(L, event);
 163.210 +  lua_rawget(L, -2);
 163.211 +  if (lua_isnil(L, -1)) {
 163.212 +    lua_pop(L, 2);  /* remove metatable and metafield */
 163.213 +    return 0;
 163.214 +  }
 163.215 +  else {
 163.216 +    lua_remove(L, -2);  /* remove only metatable */
 163.217 +    return 1;
 163.218 +  }
 163.219 +}
 163.220 +
 163.221 +
 163.222 +LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {
 163.223 +  obj = abs_index(L, obj);
 163.224 +  if (!luaL_getmetafield(L, obj, event))  /* no metafield? */
 163.225 +    return 0;
 163.226 +  lua_pushvalue(L, obj);
 163.227 +  lua_call(L, 1, 1);
 163.228 +  return 1;
 163.229 +}
 163.230 +
 163.231 +
 163.232 +LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
 163.233 +                                const luaL_Reg *l) {
 163.234 +  luaI_openlib(L, libname, l, 0);
 163.235 +}
 163.236 +
 163.237 +
 163.238 +static int libsize (const luaL_Reg *l) {
 163.239 +  int size = 0;
 163.240 +  for (; l->name; l++) size++;
 163.241 +  return size;
 163.242 +}
 163.243 +
 163.244 +
 163.245 +LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
 163.246 +                              const luaL_Reg *l, int nup) {
 163.247 +  if (libname) {
 163.248 +    int size = libsize(l);
 163.249 +    /* check whether lib already exists */
 163.250 +    luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1);
 163.251 +    lua_getfield(L, -1, libname);  /* get _LOADED[libname] */
 163.252 +    if (!lua_istable(L, -1)) {  /* not found? */
 163.253 +      lua_pop(L, 1);  /* remove previous result */
 163.254 +      /* try global variable (and create one if it does not exist) */
 163.255 +      if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)
 163.256 +        luaL_error(L, "name conflict for module " LUA_QS, libname);
 163.257 +      lua_pushvalue(L, -1);
 163.258 +      lua_setfield(L, -3, libname);  /* _LOADED[libname] = new table */
 163.259 +    }
 163.260 +    lua_remove(L, -2);  /* remove _LOADED table */
 163.261 +    lua_insert(L, -(nup+1));  /* move library table to below upvalues */
 163.262 +  }
 163.263 +  for (; l->name; l++) {
 163.264 +    int i;
 163.265 +    for (i=0; i<nup; i++)  /* copy upvalues to the top */
 163.266 +      lua_pushvalue(L, -nup);
 163.267 +    lua_pushcclosure(L, l->func, nup);
 163.268 +    lua_setfield(L, -(nup+2), l->name);
 163.269 +  }
 163.270 +  lua_pop(L, nup);  /* remove upvalues */
 163.271 +}
 163.272 +
 163.273 +
 163.274 +
 163.275 +/*
 163.276 +** {======================================================
 163.277 +** getn-setn: size for arrays
 163.278 +** =======================================================
 163.279 +*/
 163.280 +
 163.281 +#if defined(LUA_COMPAT_GETN)
 163.282 +
 163.283 +static int checkint (lua_State *L, int topop) {
 163.284 +  int n = (lua_type(L, -1) == LUA_TNUMBER) ? lua_tointeger(L, -1) : -1;
 163.285 +  lua_pop(L, topop);
 163.286 +  return n;
 163.287 +}
 163.288 +
 163.289 +
 163.290 +static void getsizes (lua_State *L) {
 163.291 +  lua_getfield(L, LUA_REGISTRYINDEX, "LUA_SIZES");
 163.292 +  if (lua_isnil(L, -1)) {  /* no `size' table? */
 163.293 +    lua_pop(L, 1);  /* remove nil */
 163.294 +    lua_newtable(L);  /* create it */
 163.295 +    lua_pushvalue(L, -1);  /* `size' will be its own metatable */
 163.296 +    lua_setmetatable(L, -2);
 163.297 +    lua_pushliteral(L, "kv");
 163.298 +    lua_setfield(L, -2, "__mode");  /* metatable(N).__mode = "kv" */
 163.299 +    lua_pushvalue(L, -1);
 163.300 +    lua_setfield(L, LUA_REGISTRYINDEX, "LUA_SIZES");  /* store in register */
 163.301 +  }
 163.302 +}
 163.303 +
 163.304 +
 163.305 +LUALIB_API void luaL_setn (lua_State *L, int t, int n) {
 163.306 +  t = abs_index(L, t);
 163.307 +  lua_pushliteral(L, "n");
 163.308 +  lua_rawget(L, t);
 163.309 +  if (checkint(L, 1) >= 0) {  /* is there a numeric field `n'? */
 163.310 +    lua_pushliteral(L, "n");  /* use it */
 163.311 +    lua_pushinteger(L, n);
 163.312 +    lua_rawset(L, t);
 163.313 +  }
 163.314 +  else {  /* use `sizes' */
 163.315 +    getsizes(L);
 163.316 +    lua_pushvalue(L, t);
 163.317 +    lua_pushinteger(L, n);
 163.318 +    lua_rawset(L, -3);  /* sizes[t] = n */
 163.319 +    lua_pop(L, 1);  /* remove `sizes' */
 163.320 +  }
 163.321 +}
 163.322 +
 163.323 +
 163.324 +LUALIB_API int luaL_getn (lua_State *L, int t) {
 163.325 +  int n;
 163.326 +  t = abs_index(L, t);
 163.327 +  lua_pushliteral(L, "n");  /* try t.n */
 163.328 +  lua_rawget(L, t);
 163.329 +  if ((n = checkint(L, 1)) >= 0) return n;
 163.330 +  getsizes(L);  /* else try sizes[t] */
 163.331 +  lua_pushvalue(L, t);
 163.332 +  lua_rawget(L, -2);
 163.333 +  if ((n = checkint(L, 2)) >= 0) return n;
 163.334 +  return (int)lua_objlen(L, t);
 163.335 +}
 163.336 +
 163.337 +#endif
 163.338 +
 163.339 +/* }====================================================== */
 163.340 +
 163.341 +
 163.342 +
 163.343 +LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
 163.344 +                                                               const char *r) {
 163.345 +  const char *wild;
 163.346 +  size_t l = strlen(p);
 163.347 +  luaL_Buffer b;
 163.348 +  luaL_buffinit(L, &b);
 163.349 +  while ((wild = strstr(s, p)) != NULL) {
 163.350 +    luaL_addlstring(&b, s, wild - s);  /* push prefix */
 163.351 +    luaL_addstring(&b, r);  /* push replacement in place of pattern */
 163.352 +    s = wild + l;  /* continue after `p' */
 163.353 +  }
 163.354 +  luaL_addstring(&b, s);  /* push last suffix */
 163.355 +  luaL_pushresult(&b);
 163.356 +  return lua_tostring(L, -1);
 163.357 +}
 163.358 +
 163.359 +
 163.360 +LUALIB_API const char *luaL_findtable (lua_State *L, int idx,
 163.361 +                                       const char *fname, int szhint) {
 163.362 +  const char *e;
 163.363 +  lua_pushvalue(L, idx);
 163.364 +  do {
 163.365 +    e = strchr(fname, '.');
 163.366 +    if (e == NULL) e = fname + strlen(fname);
 163.367 +    lua_pushlstring(L, fname, e - fname);
 163.368 +    lua_rawget(L, -2);
 163.369 +    if (lua_isnil(L, -1)) {  /* no such field? */
 163.370 +      lua_pop(L, 1);  /* remove this nil */
 163.371 +      lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
 163.372 +      lua_pushlstring(L, fname, e - fname);
 163.373 +      lua_pushvalue(L, -2);
 163.374 +      lua_settable(L, -4);  /* set new table into field */
 163.375 +    }
 163.376 +    else if (!lua_istable(L, -1)) {  /* field has a non-table value? */
 163.377 +      lua_pop(L, 2);  /* remove table and value */
 163.378 +      return fname;  /* return problematic part of the name */
 163.379 +    }
 163.380 +    lua_remove(L, -2);  /* remove previous table */
 163.381 +    fname = e + 1;
 163.382 +  } while (*e == '.');
 163.383 +  return NULL;
 163.384 +}
 163.385 +
 163.386 +
 163.387 +
 163.388 +/*
 163.389 +** {======================================================
 163.390 +** Generic Buffer manipulation
 163.391 +** =======================================================
 163.392 +*/
 163.393 +
 163.394 +
 163.395 +#define bufflen(B)	((B)->p - (B)->buffer)
 163.396 +#define bufffree(B)	((size_t)(LUAL_BUFFERSIZE - bufflen(B)))
 163.397 +
 163.398 +#define LIMIT	(LUA_MINSTACK/2)
 163.399 +
 163.400 +
 163.401 +static int emptybuffer (luaL_Buffer *B) {
 163.402 +  size_t l = bufflen(B);
 163.403 +  if (l == 0) return 0;  /* put nothing on stack */
 163.404 +  else {
 163.405 +    lua_pushlstring(B->L, B->buffer, l);
 163.406 +    B->p = B->buffer;
 163.407 +    B->lvl++;
 163.408 +    return 1;
 163.409 +  }
 163.410 +}
 163.411 +
 163.412 +
 163.413 +static void adjuststack (luaL_Buffer *B) {
 163.414 +  if (B->lvl > 1) {
 163.415 +    lua_State *L = B->L;
 163.416 +    int toget = 1;  /* number of levels to concat */
 163.417 +    size_t toplen = lua_strlen(L, -1);
 163.418 +    do {
 163.419 +      size_t l = lua_strlen(L, -(toget+1));
 163.420 +      if (B->lvl - toget + 1 >= LIMIT || toplen > l) {
 163.421 +        toplen += l;
 163.422 +        toget++;
 163.423 +      }
 163.424 +      else break;
 163.425 +    } while (toget < B->lvl);
 163.426 +    lua_concat(L, toget);
 163.427 +    B->lvl = B->lvl - toget + 1;
 163.428 +  }
 163.429 +}
 163.430 +
 163.431 +
 163.432 +LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) {
 163.433 +  if (emptybuffer(B))
 163.434 +    adjuststack(B);
 163.435 +  return B->buffer;
 163.436 +}
 163.437 +
 163.438 +
 163.439 +LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
 163.440 +  while (l--)
 163.441 +    luaL_addchar(B, *s++);
 163.442 +}
 163.443 +
 163.444 +
 163.445 +LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {
 163.446 +  luaL_addlstring(B, s, strlen(s));
 163.447 +}
 163.448 +
 163.449 +
 163.450 +LUALIB_API void luaL_pushresult (luaL_Buffer *B) {
 163.451 +  emptybuffer(B);
 163.452 +  lua_concat(B->L, B->lvl);
 163.453 +  B->lvl = 1;
 163.454 +}
 163.455 +
 163.456 +
 163.457 +LUALIB_API void luaL_addvalue (luaL_Buffer *B) {
 163.458 +  lua_State *L = B->L;
 163.459 +  size_t vl;
 163.460 +  const char *s = lua_tolstring(L, -1, &vl);
 163.461 +  if (vl <= bufffree(B)) {  /* fit into buffer? */
 163.462 +    memcpy(B->p, s, vl);  /* put it there */
 163.463 +    B->p += vl;
 163.464 +    lua_pop(L, 1);  /* remove from stack */
 163.465 +  }
 163.466 +  else {
 163.467 +    if (emptybuffer(B))
 163.468 +      lua_insert(L, -2);  /* put buffer before new value */
 163.469 +    B->lvl++;  /* add new value into B stack */
 163.470 +    adjuststack(B);
 163.471 +  }
 163.472 +}
 163.473 +
 163.474 +
 163.475 +LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {
 163.476 +  B->L = L;
 163.477 +  B->p = B->buffer;
 163.478 +  B->lvl = 0;
 163.479 +}
 163.480 +
 163.481 +/* }====================================================== */
 163.482 +
 163.483 +
 163.484 +LUALIB_API int luaL_ref (lua_State *L, int t) {
 163.485 +  int ref;
 163.486 +  t = abs_index(L, t);
 163.487 +  if (lua_isnil(L, -1)) {
 163.488 +    lua_pop(L, 1);  /* remove from stack */
 163.489 +    return LUA_REFNIL;  /* `nil' has a unique fixed reference */
 163.490 +  }
 163.491 +  lua_rawgeti(L, t, FREELIST_REF);  /* get first free element */
 163.492 +  ref = (int)lua_tointeger(L, -1);  /* ref = t[FREELIST_REF] */
 163.493 +  lua_pop(L, 1);  /* remove it from stack */
 163.494 +  if (ref != 0) {  /* any free element? */
 163.495 +    lua_rawgeti(L, t, ref);  /* remove it from list */
 163.496 +    lua_rawseti(L, t, FREELIST_REF);  /* (t[FREELIST_REF] = t[ref]) */
 163.497 +  }
 163.498 +  else {  /* no free elements */
 163.499 +    ref = (int)lua_objlen(L, t);
 163.500 +    ref++;  /* create new reference */
 163.501 +  }
 163.502 +  lua_rawseti(L, t, ref);
 163.503 +  return ref;
 163.504 +}
 163.505 +
 163.506 +
 163.507 +LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
 163.508 +  if (ref >= 0) {
 163.509 +    t = abs_index(L, t);
 163.510 +    lua_rawgeti(L, t, FREELIST_REF);
 163.511 +    lua_rawseti(L, t, ref);  /* t[ref] = t[FREELIST_REF] */
 163.512 +    lua_pushinteger(L, ref);
 163.513 +    lua_rawseti(L, t, FREELIST_REF);  /* t[FREELIST_REF] = ref */
 163.514 +  }
 163.515 +}
 163.516 +
 163.517 +
 163.518 +
 163.519 +/*
 163.520 +** {======================================================
 163.521 +** Load functions
 163.522 +** =======================================================
 163.523 +*/
 163.524 +
 163.525 +typedef struct LoadF {
 163.526 +  int extraline;
 163.527 +  FILE *f;
 163.528 +  char buff[LUAL_BUFFERSIZE];
 163.529 +} LoadF;
 163.530 +
 163.531 +
 163.532 +static const char *getF (lua_State *L, void *ud, size_t *size) {
 163.533 +  LoadF *lf = (LoadF *)ud;
 163.534 +  (void)L;
 163.535 +  if (lf->extraline) {
 163.536 +    lf->extraline = 0;
 163.537 +    *size = 1;
 163.538 +    return "\n";
 163.539 +  }
 163.540 +  if (feof(lf->f)) return NULL;
 163.541 +  *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);
 163.542 +  return (*size > 0) ? lf->buff : NULL;
 163.543 +}
 163.544 +
 163.545 +
 163.546 +static int errfile (lua_State *L, const char *what, int fnameindex) {
 163.547 +  const char *serr = strerror(errno);
 163.548 +  const char *filename = lua_tostring(L, fnameindex) + 1;
 163.549 +  lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
 163.550 +  lua_remove(L, fnameindex);
 163.551 +  return LUA_ERRFILE;
 163.552 +}
 163.553 +
 163.554 +
 163.555 +LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
 163.556 +  LoadF lf;
 163.557 +  int status, readstatus;
 163.558 +  int c;
 163.559 +  int fnameindex = lua_gettop(L) + 1;  /* index of filename on the stack */
 163.560 +  lf.extraline = 0;
 163.561 +  if (filename == NULL) {
 163.562 +    lua_pushliteral(L, "=stdin");
 163.563 +    lf.f = stdin;
 163.564 +  }
 163.565 +  else {
 163.566 +    lua_pushfstring(L, "@%s", filename);
 163.567 +    lf.f = fopen(filename, "r");
 163.568 +    if (lf.f == NULL) return errfile(L, "open", fnameindex);
 163.569 +  }
 163.570 +  c = getc(lf.f);
 163.571 +  if (c == '#') {  /* Unix exec. file? */
 163.572 +    lf.extraline = 1;
 163.573 +    while ((c = getc(lf.f)) != EOF && c != '\n') ;  /* skip first line */
 163.574 +    if (c == '\n') c = getc(lf.f);
 163.575 +  }
 163.576 +  if (c == LUA_SIGNATURE[0] && filename) {  /* binary file? */
 163.577 +    lf.f = freopen(filename, "rb", lf.f);  /* reopen in binary mode */
 163.578 +    if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
 163.579 +    /* skip eventual `#!...' */
 163.580 +   while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
 163.581 +    lf.extraline = 0;
 163.582 +  }
 163.583 +  ungetc(c, lf.f);
 163.584 +  status = lua_load(L, getF, &lf, lua_tostring(L, -1));
 163.585 +  readstatus = ferror(lf.f);
 163.586 +  if (filename) fclose(lf.f);  /* close file (even in case of errors) */
 163.587 +  if (readstatus) {
 163.588 +    lua_settop(L, fnameindex);  /* ignore results from `lua_load' */
 163.589 +    return errfile(L, "read", fnameindex);
 163.590 +  }
 163.591 +  lua_remove(L, fnameindex);
 163.592 +  return status;
 163.593 +}
 163.594 +
 163.595 +
 163.596 +typedef struct LoadS {
 163.597 +  const char *s;
 163.598 +  size_t size;
 163.599 +} LoadS;
 163.600 +
 163.601 +
 163.602 +static const char *getS (lua_State *L, void *ud, size_t *size) {
 163.603 +  LoadS *ls = (LoadS *)ud;
 163.604 +  (void)L;
 163.605 +  if (ls->size == 0) return NULL;
 163.606 +  *size = ls->size;
 163.607 +  ls->size = 0;
 163.608 +  return ls->s;
 163.609 +}
 163.610 +
 163.611 +
 163.612 +LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size,
 163.613 +                                const char *name) {
 163.614 +  LoadS ls;
 163.615 +  ls.s = buff;
 163.616 +  ls.size = size;
 163.617 +  return lua_load(L, getS, &ls, name);
 163.618 +}
 163.619 +
 163.620 +
 163.621 +LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) {
 163.622 +  return luaL_loadbuffer(L, s, strlen(s), s);
 163.623 +}
 163.624 +
 163.625 +
 163.626 +
 163.627 +/* }====================================================== */
 163.628 +
 163.629 +
 163.630 +static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
 163.631 +  (void)ud;
 163.632 +  (void)osize;
 163.633 +  if (nsize == 0) {
 163.634 +    free(ptr);
 163.635 +    return NULL;
 163.636 +  }
 163.637 +  else
 163.638 +    return realloc(ptr, nsize);
 163.639 +}
 163.640 +
 163.641 +
 163.642 +static int panic (lua_State *L) {
 163.643 +  (void)L;  /* to avoid warnings */
 163.644 +  fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n",
 163.645 +                   lua_tostring(L, -1));
 163.646 +  return 0;
 163.647 +}
 163.648 +
 163.649 +
 163.650 +LUALIB_API lua_State *luaL_newstate (void) {
 163.651 +  lua_State *L = lua_newstate(l_alloc, NULL);
 163.652 +  if (L) lua_atpanic(L, &panic);
 163.653 +  return L;
 163.654 +}
 163.655 +
   164.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   164.2 +++ b/src/lua/src/lauxlib.h	Sat Mar 03 10:31:27 2012 -0600
   164.3 @@ -0,0 +1,174 @@
   164.4 +/*
   164.5 +** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $
   164.6 +** Auxiliary functions for building Lua libraries
   164.7 +** See Copyright Notice in lua.h
   164.8 +*/
   164.9 +
  164.10 +
  164.11 +#ifndef lauxlib_h
  164.12 +#define lauxlib_h
  164.13 +
  164.14 +
  164.15 +#include <stddef.h>
  164.16 +#include <stdio.h>
  164.17 +
  164.18 +#include "lua.h"
  164.19 +
  164.20 +
  164.21 +#if defined(LUA_COMPAT_GETN)
  164.22 +LUALIB_API int (luaL_getn) (lua_State *L, int t);
  164.23 +LUALIB_API void (luaL_setn) (lua_State *L, int t, int n);
  164.24 +#else
  164.25 +#define luaL_getn(L,i)          ((int)lua_objlen(L, i))
  164.26 +#define luaL_setn(L,i,j)        ((void)0)  /* no op! */
  164.27 +#endif
  164.28 +
  164.29 +#if defined(LUA_COMPAT_OPENLIB)
  164.30 +#define luaI_openlib	luaL_openlib
  164.31 +#endif
  164.32 +
  164.33 +
  164.34 +/* extra error code for `luaL_load' */
  164.35 +#define LUA_ERRFILE     (LUA_ERRERR+1)
  164.36 +
  164.37 +
  164.38 +typedef struct luaL_Reg {
  164.39 +  const char *name;
  164.40 +  lua_CFunction func;
  164.41 +} luaL_Reg;
  164.42 +
  164.43 +
  164.44 +
  164.45 +LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname,
  164.46 +                                const luaL_Reg *l, int nup);
  164.47 +LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
  164.48 +                                const luaL_Reg *l);
  164.49 +LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
  164.50 +LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
  164.51 +LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);
  164.52 +LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
  164.53 +LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
  164.54 +                                                          size_t *l);
  164.55 +LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,
  164.56 +                                          const char *def, size_t *l);
  164.57 +LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);
  164.58 +LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);
  164.59 +
  164.60 +LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
  164.61 +LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
  164.62 +                                          lua_Integer def);
  164.63 +
  164.64 +LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
  164.65 +LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
  164.66 +LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
  164.67 +
  164.68 +LUALIB_API int   (luaL_newmetatable) (lua_State *L, const char *tname);
  164.69 +LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
  164.70 +
  164.71 +LUALIB_API void (luaL_where) (lua_State *L, int lvl);
  164.72 +LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
  164.73 +
  164.74 +LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
  164.75 +                                   const char *const lst[]);
  164.76 +
  164.77 +LUALIB_API int (luaL_ref) (lua_State *L, int t);
  164.78 +LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
  164.79 +
  164.80 +LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);
  164.81 +LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,
  164.82 +                                  const char *name);
  164.83 +LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
  164.84 +
  164.85 +LUALIB_API lua_State *(luaL_newstate) (void);
  164.86 +
  164.87 +
  164.88 +LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
  164.89 +                                                  const char *r);
  164.90 +
  164.91 +LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
  164.92 +                                         const char *fname, int szhint);
  164.93 +
  164.94 +
  164.95 +
  164.96 +
  164.97 +/*
  164.98 +** ===============================================================
  164.99 +** some useful macros
 164.100 +** ===============================================================
 164.101 +*/
 164.102 +
 164.103 +#define luaL_argcheck(L, cond,numarg,extramsg)	\
 164.104 +		((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
 164.105 +#define luaL_checkstring(L,n)	(luaL_checklstring(L, (n), NULL))
 164.106 +#define luaL_optstring(L,n,d)	(luaL_optlstring(L, (n), (d), NULL))
 164.107 +#define luaL_checkint(L,n)	((int)luaL_checkinteger(L, (n)))
 164.108 +#define luaL_optint(L,n,d)	((int)luaL_optinteger(L, (n), (d)))
 164.109 +#define luaL_checklong(L,n)	((long)luaL_checkinteger(L, (n)))
 164.110 +#define luaL_optlong(L,n,d)	((long)luaL_optinteger(L, (n), (d)))
 164.111 +
 164.112 +#define luaL_typename(L,i)	lua_typename(L, lua_type(L,(i)))
 164.113 +
 164.114 +#define luaL_dofile(L, fn) \
 164.115 +	(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
 164.116 +
 164.117 +#define luaL_dostring(L, s) \
 164.118 +	(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
 164.119 +
 164.120 +#define luaL_getmetatable(L,n)	(lua_getfield(L, LUA_REGISTRYINDEX, (n)))
 164.121 +
 164.122 +#define luaL_opt(L,f,n,d)	(lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
 164.123 +
 164.124 +/*
 164.125 +** {======================================================
 164.126 +** Generic Buffer manipulation
 164.127 +** =======================================================
 164.128 +*/
 164.129 +
 164.130 +
 164.131 +
 164.132 +typedef struct luaL_Buffer {
 164.133 +  char *p;			/* current position in buffer */
 164.134 +  int lvl;  /* number of strings in the stack (level) */
 164.135 +  lua_State *L;
 164.136 +  char buffer[LUAL_BUFFERSIZE];
 164.137 +} luaL_Buffer;
 164.138 +
 164.139 +#define luaL_addchar(B,c) \
 164.140 +  ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \
 164.141 +   (*(B)->p++ = (char)(c)))
 164.142 +
 164.143 +/* compatibility only */
 164.144 +#define luaL_putchar(B,c)	luaL_addchar(B,c)
 164.145 +
 164.146 +#define luaL_addsize(B,n)	((B)->p += (n))
 164.147 +
 164.148 +LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
 164.149 +LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B);
 164.150 +LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
 164.151 +LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
 164.152 +LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
 164.153 +LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
 164.154 +
 164.155 +
 164.156 +/* }====================================================== */
 164.157 +
 164.158 +
 164.159 +/* compatibility with ref system */
 164.160 +
 164.161 +/* pre-defined references */
 164.162 +#define LUA_NOREF       (-2)
 164.163 +#define LUA_REFNIL      (-1)
 164.164 +
 164.165 +#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \
 164.166 +      (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0))
 164.167 +
 164.168 +#define lua_unref(L,ref)        luaL_unref(L, LUA_REGISTRYINDEX, (ref))
 164.169 +
 164.170 +#define lua_getref(L,ref)       lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))
 164.171 +
 164.172 +
 164.173 +#define luaL_reg	luaL_Reg
 164.174 +
 164.175 +#endif
 164.176 +
 164.177 +
   165.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   165.2 +++ b/src/lua/src/lbaselib.c	Sat Mar 03 10:31:27 2012 -0600
   165.3 @@ -0,0 +1,653 @@
   165.4 +/*
   165.5 +** $Id: lbaselib.c,v 1.191.1.6 2008/02/14 16:46:22 roberto Exp $
   165.6 +** Basic library
   165.7 +** See Copyright Notice in lua.h
   165.8 +*/
   165.9 +
  165.10 +
  165.11 +
  165.12 +#include <ctype.h>
  165.13 +#include <stdio.h>
  165.14 +#include <stdlib.h>
  165.15 +#include <string.h>
  165.16 +
  165.17 +#define lbaselib_c
  165.18 +#define LUA_LIB
  165.19 +
  165.20 +#include "lua.h"
  165.21 +
  165.22 +#include "lauxlib.h"
  165.23 +#include "lualib.h"
  165.24 +
  165.25 +
  165.26 +
  165.27 +
  165.28 +/*
  165.29 +** If your system does not support `stdout', you can just remove this function.
  165.30 +** If you need, you can define your own `print' function, following this
  165.31 +** model but changing `fputs' to put the strings at a proper place
  165.32 +** (a console window or a log file, for instance).
  165.33 +*/
  165.34 +static int luaB_print (lua_State *L) {
  165.35 +  int n = lua_gettop(L);  /* number of arguments */
  165.36 +  int i;
  165.37 +  lua_getglobal(L, "tostring");
  165.38 +  for (i=1; i<=n; i++) {
  165.39 +    const char *s;
  165.40 +    lua_pushvalue(L, -1);  /* function to be called */
  165.41 +    lua_pushvalue(L, i);   /* value to print */
  165.42 +    lua_call(L, 1, 1);
  165.43 +    s = lua_tostring(L, -1);  /* get result */
  165.44 +    if (s == NULL)
  165.45 +      return luaL_error(L, LUA_QL("tostring") " must return a string to "
  165.46 +                           LUA_QL("print"));
  165.47 +    if (i>1) fputs("\t", stdout);
  165.48 +    fputs(s, stdout);
  165.49 +    lua_pop(L, 1);  /* pop result */
  165.50 +  }
  165.51 +  fputs("\n", stdout);
  165.52 +  return 0;
  165.53 +}
  165.54 +
  165.55 +
  165.56 +static int luaB_tonumber (lua_State *L) {
  165.57 +  int base = luaL_optint(L, 2, 10);
  165.58 +  if (base == 10) {  /* standard conversion */
  165.59 +    luaL_checkany(L, 1);
  165.60 +    if (lua_isnumber(L, 1)) {
  165.61 +      lua_pushnumber(L, lua_tonumber(L, 1));
  165.62 +      return 1;
  165.63 +    }
  165.64 +  }
  165.65 +  else {
  165.66 +    const char *s1 = luaL_checkstring(L, 1);
  165.67 +    char *s2;
  165.68 +    unsigned long n;
  165.69 +    luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
  165.70 +    n = strtoul(s1, &s2, base);
  165.71 +    if (s1 != s2) {  /* at least one valid digit? */
  165.72 +      while (isspace((unsigned char)(*s2))) s2++;  /* skip trailing spaces */
  165.73 +      if (*s2 == '\0') {  /* no invalid trailing characters? */
  165.74 +        lua_pushnumber(L, (lua_Number)n);
  165.75 +        return 1;
  165.76 +      }
  165.77 +    }
  165.78 +  }
  165.79 +  lua_pushnil(L);  /* else not a number */
  165.80 +  return 1;
  165.81 +}
  165.82 +
  165.83 +
  165.84 +static int luaB_error (lua_State *L) {
  165.85 +  int level = luaL_optint(L, 2, 1);
  165.86 +  lua_settop(L, 1);
  165.87 +  if (lua_isstring(L, 1) && level > 0) {  /* add extra information? */
  165.88 +    luaL_where(L, level);
  165.89 +    lua_pushvalue(L, 1);
  165.90 +    lua_concat(L, 2);
  165.91 +  }
  165.92 +  return lua_error(L);
  165.93 +}
  165.94 +
  165.95 +
  165.96 +static int luaB_getmetatable (lua_State *L) {
  165.97 +  luaL_checkany(L, 1);
  165.98 +  if (!lua_getmetatable(L, 1)) {
  165.99 +    lua_pushnil(L);
 165.100 +    return 1;  /* no metatable */
 165.101 +  }
 165.102 +  luaL_getmetafield(L, 1, "__metatable");
 165.103 +  return 1;  /* returns either __metatable field (if present) or metatable */
 165.104 +}
 165.105 +
 165.106 +
 165.107 +static int luaB_setmetatable (lua_State *L) {
 165.108 +  int t = lua_type(L, 2);
 165.109 +  luaL_checktype(L, 1, LUA_TTABLE);
 165.110 +  luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
 165.111 +                    "nil or table expected");
 165.112 +  if (luaL_getmetafield(L, 1, "__metatable"))
 165.113 +    luaL_error(L, "cannot change a protected metatable");
 165.114 +  lua_settop(L, 2);
 165.115 +  lua_setmetatable(L, 1);
 165.116 +  return 1;
 165.117 +}
 165.118 +
 165.119 +
 165.120 +static void getfunc (lua_State *L, int opt) {
 165.121 +  if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
 165.122 +  else {
 165.123 +    lua_Debug ar;
 165.124 +    int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1);
 165.125 +    luaL_argcheck(L, level >= 0, 1, "level must be non-negative");
 165.126 +    if (lua_getstack(L, level, &ar) == 0)
 165.127 +      luaL_argerror(L, 1, "invalid level");
 165.128 +    lua_getinfo(L, "f", &ar);
 165.129 +    if (lua_isnil(L, -1))
 165.130 +      luaL_error(L, "no function environment for tail call at level %d",
 165.131 +                    level);
 165.132 +  }
 165.133 +}
 165.134 +
 165.135 +
 165.136 +static int luaB_getfenv (lua_State *L) {
 165.137 +  getfunc(L, 1);
 165.138 +  if (lua_iscfunction(L, -1))  /* is a C function? */
 165.139 +    lua_pushvalue(L, LUA_GLOBALSINDEX);  /* return the thread's global env. */
 165.140 +  else
 165.141 +    lua_getfenv(L, -1);
 165.142 +  return 1;
 165.143 +}
 165.144 +
 165.145 +
 165.146 +static int luaB_setfenv (lua_State *L) {
 165.147 +  luaL_checktype(L, 2, LUA_TTABLE);
 165.148 +  getfunc(L, 0);
 165.149 +  lua_pushvalue(L, 2);
 165.150 +  if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) {
 165.151 +    /* change environment of current thread */
 165.152 +    lua_pushthread(L);
 165.153 +    lua_insert(L, -2);
 165.154 +    lua_setfenv(L, -2);
 165.155 +    return 0;
 165.156 +  }
 165.157 +  else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0)
 165.158 +    luaL_error(L,
 165.159 +          LUA_QL("setfenv") " cannot change environment of given object");
 165.160 +  return 1;
 165.161 +}
 165.162 +
 165.163 +
 165.164 +static int luaB_rawequal (lua_State *L) {
 165.165 +  luaL_checkany(L, 1);
 165.166 +  luaL_checkany(L, 2);
 165.167 +  lua_pushboolean(L, lua_rawequal(L, 1, 2));
 165.168 +  return 1;
 165.169 +}
 165.170 +
 165.171 +
 165.172 +static int luaB_rawget (lua_State *L) {
 165.173 +  luaL_checktype(L, 1, LUA_TTABLE);
 165.174 +  luaL_checkany(L, 2);
 165.175 +  lua_settop(L, 2);
 165.176 +  lua_rawget(L, 1);
 165.177 +  return 1;
 165.178 +}
 165.179 +
 165.180 +static int luaB_rawset (lua_State *L) {
 165.181 +  luaL_checktype(L, 1, LUA_TTABLE);
 165.182 +  luaL_checkany(L, 2);
 165.183 +  luaL_checkany(L, 3);
 165.184 +  lua_settop(L, 3);
 165.185 +  lua_rawset(L, 1);
 165.186 +  return 1;
 165.187 +}
 165.188 +
 165.189 +
 165.190 +static int luaB_gcinfo (lua_State *L) {
 165.191 +  lua_pushinteger(L, lua_getgccount(L));
 165.192 +  return 1;
 165.193 +}
 165.194 +
 165.195 +
 165.196 +static int luaB_collectgarbage (lua_State *L) {
 165.197 +  static const char *const opts[] = {"stop", "restart", "collect",
 165.198 +    "count", "step", "setpause", "setstepmul", NULL};
 165.199 +  static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
 165.200 +    LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL};
 165.201 +  int o = luaL_checkoption(L, 1, "collect", opts);
 165.202 +  int ex = luaL_optint(L, 2, 0);
 165.203 +  int res = lua_gc(L, optsnum[o], ex);
 165.204 +  switch (optsnum[o]) {
 165.205 +    case LUA_GCCOUNT: {
 165.206 +      int b = lua_gc(L, LUA_GCCOUNTB, 0);
 165.207 +      lua_pushnumber(L, res + ((lua_Number)b/1024));
 165.208 +      return 1;
 165.209 +    }
 165.210 +    case LUA_GCSTEP: {
 165.211 +      lua_pushboolean(L, res);
 165.212 +      return 1;
 165.213 +    }
 165.214 +    default: {
 165.215 +      lua_pushnumber(L, res);
 165.216 +      return 1;
 165.217 +    }
 165.218 +  }
 165.219 +}
 165.220 +
 165.221 +
 165.222 +static int luaB_type (lua_State *L) {
 165.223 +  luaL_checkany(L, 1);
 165.224 +  lua_pushstring(L, luaL_typename(L, 1));
 165.225 +  return 1;
 165.226 +}
 165.227 +
 165.228 +
 165.229 +static int luaB_next (lua_State *L) {
 165.230 +  luaL_checktype(L, 1, LUA_TTABLE);
 165.231 +  lua_settop(L, 2);  /* create a 2nd argument if there isn't one */
 165.232 +  if (lua_next(L, 1))
 165.233 +    return 2;
 165.234 +  else {
 165.235 +    lua_pushnil(L);
 165.236 +    return 1;
 165.237 +  }
 165.238 +}
 165.239 +
 165.240 +
 165.241 +static int luaB_pairs (lua_State *L) {
 165.242 +  luaL_checktype(L, 1, LUA_TTABLE);
 165.243 +  lua_pushvalue(L, lua_upvalueindex(1));  /* return generator, */
 165.244 +  lua_pushvalue(L, 1);  /* state, */
 165.245 +  lua_pushnil(L);  /* and initial value */
 165.246 +  return 3;
 165.247 +}
 165.248 +
 165.249 +
 165.250 +static int ipairsaux (lua_State *L) {
 165.251 +  int i = luaL_checkint(L, 2);
 165.252 +  luaL_checktype(L, 1, LUA_TTABLE);
 165.253 +  i++;  /* next value */
 165.254 +  lua_pushinteger(L, i);
 165.255 +  lua_rawgeti(L, 1, i);
 165.256 +  return (lua_isnil(L, -1)) ? 0 : 2;
 165.257 +}
 165.258 +
 165.259 +
 165.260 +static int luaB_ipairs (lua_State *L) {
 165.261 +  luaL_checktype(L, 1, LUA_TTABLE);
 165.262 +  lua_pushvalue(L, lua_upvalueindex(1));  /* return generator, */
 165.263 +  lua_pushvalue(L, 1);  /* state, */
 165.264 +  lua_pushinteger(L, 0);  /* and initial value */
 165.265 +  return 3;
 165.266 +}
 165.267 +
 165.268 +
 165.269 +static int load_aux (lua_State *L, int status) {
 165.270 +  if (status == 0)  /* OK? */
 165.271 +    return 1;
 165.272 +  else {
 165.273 +    lua_pushnil(L);
 165.274 +    lua_insert(L, -2);  /* put before error message */
 165.275 +    return 2;  /* return nil plus error message */
 165.276 +  }
 165.277 +}
 165.278 +
 165.279 +
 165.280 +static int luaB_loadstring (lua_State *L) {
 165.281 +  size_t l;
 165.282 +  const char *s = luaL_checklstring(L, 1, &l);
 165.283 +  const char *chunkname = luaL_optstring(L, 2, s);
 165.284 +  return load_aux(L, luaL_loadbuffer(L, s, l, chunkname));
 165.285 +}
 165.286 +
 165.287 +
 165.288 +static int luaB_loadfile (lua_State *L) {
 165.289 +  const char *fname = luaL_optstring(L, 1, NULL);
 165.290 +  return load_aux(L, luaL_loadfile(L, fname));
 165.291 +}
 165.292 +
 165.293 +
 165.294 +/*
 165.295 +** Reader for generic `load' function: `lua_load' uses the
 165.296 +** stack for internal stuff, so the reader cannot change the
 165.297 +** stack top. Instead, it keeps its resulting string in a
 165.298 +** reserved slot inside the stack.
 165.299 +*/
 165.300 +static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
 165.301 +  (void)ud;  /* to avoid warnings */
 165.302 +  luaL_checkstack(L, 2, "too many nested functions");
 165.303 +  lua_pushvalue(L, 1);  /* get function */
 165.304 +  lua_call(L, 0, 1);  /* call it */
 165.305 +  if (lua_isnil(L, -1)) {
 165.306 +    *size = 0;
 165.307 +    return NULL;
 165.308 +  }
 165.309 +  else if (lua_isstring(L, -1)) {
 165.310 +    lua_replace(L, 3);  /* save string in a reserved stack slot */
 165.311 +    return lua_tolstring(L, 3, size);
 165.312 +  }
 165.313 +  else luaL_error(L, "reader function must return a string");
 165.314 +  return NULL;  /* to avoid warnings */
 165.315 +}
 165.316 +
 165.317 +
 165.318 +static int luaB_load (lua_State *L) {
 165.319 +  int status;
 165.320 +  const char *cname = luaL_optstring(L, 2, "=(load)");
 165.321 +  luaL_checktype(L, 1, LUA_TFUNCTION);
 165.322 +  lua_settop(L, 3);  /* function, eventual name, plus one reserved slot */
 165.323 +  status = lua_load(L, generic_reader, NULL, cname);
 165.324 +  return load_aux(L, status);
 165.325 +}
 165.326 +
 165.327 +
 165.328 +static int luaB_dofile (lua_State *L) {
 165.329 +  const char *fname = luaL_optstring(L, 1, NULL);
 165.330 +  int n = lua_gettop(L);
 165.331 +  if (luaL_loadfile(L, fname) != 0) lua_error(L);
 165.332 +  lua_call(L, 0, LUA_MULTRET);
 165.333 +  return lua_gettop(L) - n;
 165.334 +}
 165.335 +
 165.336 +
 165.337 +static int luaB_assert (lua_State *L) {
 165.338 +  luaL_checkany(L, 1);
 165.339 +  if (!lua_toboolean(L, 1))
 165.340 +    return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!"));
 165.341 +  return lua_gettop(L);
 165.342 +}
 165.343 +
 165.344 +
 165.345 +static int luaB_unpack (lua_State *L) {
 165.346 +  int i, e, n;
 165.347 +  luaL_checktype(L, 1, LUA_TTABLE);
 165.348 +  i = luaL_optint(L, 2, 1);
 165.349 +  e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1));
 165.350 +  if (i > e) return 0;  /* empty range */
 165.351 +  n = e - i + 1;  /* number of elements */
 165.352 +  if (n <= 0 || !lua_checkstack(L, n))  /* n <= 0 means arith. overflow */
 165.353 +    return luaL_error(L, "too many results to unpack");
 165.354 +  lua_rawgeti(L, 1, i);  /* push arg[i] (avoiding overflow problems) */
 165.355 +  while (i++ < e)  /* push arg[i + 1...e] */
 165.356 +    lua_rawgeti(L, 1, i);
 165.357 +  return n;
 165.358 +}
 165.359 +
 165.360 +
 165.361 +static int luaB_select (lua_State *L) {
 165.362 +  int n = lua_gettop(L);
 165.363 +  if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {
 165.364 +    lua_pushinteger(L, n-1);
 165.365 +    return 1;
 165.366 +  }
 165.367 +  else {
 165.368 +    int i = luaL_checkint(L, 1);
 165.369 +    if (i < 0) i = n + i;
 165.370 +    else if (i > n) i = n;
 165.371 +    luaL_argcheck(L, 1 <= i, 1, "index out of range");
 165.372 +    return n - i;
 165.373 +  }
 165.374 +}
 165.375 +
 165.376 +
 165.377 +static int luaB_pcall (lua_State *L) {
 165.378 +  int status;
 165.379 +  luaL_checkany(L, 1);
 165.380 +  status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0);
 165.381 +  lua_pushboolean(L, (status == 0));
 165.382 +  lua_insert(L, 1);
 165.383 +  return lua_gettop(L);  /* return status + all results */
 165.384 +}
 165.385 +
 165.386 +
 165.387 +static int luaB_xpcall (lua_State *L) {
 165.388 +  int status;
 165.389 +  luaL_checkany(L, 2);
 165.390 +  lua_settop(L, 2);
 165.391 +  lua_insert(L, 1);  /* put error function under function to be called */
 165.392 +  status = lua_pcall(L, 0, LUA_MULTRET, 1);
 165.393 +  lua_pushboolean(L, (status == 0));
 165.394 +  lua_replace(L, 1);
 165.395 +  return lua_gettop(L);  /* return status + all results */
 165.396 +}
 165.397 +
 165.398 +
 165.399 +static int luaB_tostring (lua_State *L) {
 165.400 +  luaL_checkany(L, 1);
 165.401 +  if (luaL_callmeta(L, 1, "__tostring"))  /* is there a metafield? */
 165.402 +    return 1;  /* use its value */
 165.403 +  switch (lua_type(L, 1)) {
 165.404 +    case LUA_TNUMBER:
 165.405 +      lua_pushstring(L, lua_tostring(L, 1));
 165.406 +      break;
 165.407 +    case LUA_TSTRING:
 165.408 +      lua_pushvalue(L, 1);
 165.409 +      break;
 165.410 +    case LUA_TBOOLEAN:
 165.411 +      lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false"));
 165.412 +      break;
 165.413 +    case LUA_TNIL:
 165.414 +      lua_pushliteral(L, "nil");
 165.415 +      break;
 165.416 +    default:
 165.417 +      lua_pushfstring(L, "%s: %p", luaL_typename(L, 1), lua_topointer(L, 1));
 165.418 +      break;
 165.419 +  }
 165.420 +  return 1;
 165.421 +}
 165.422 +
 165.423 +
 165.424 +static int luaB_newproxy (lua_State *L) {
 165.425 +  lua_settop(L, 1);
 165.426 +  lua_newuserdata(L, 0);  /* create proxy */
 165.427 +  if (lua_toboolean(L, 1) == 0)
 165.428 +    return 1;  /* no metatable */
 165.429 +  else if (lua_isboolean(L, 1)) {
 165.430 +    lua_newtable(L);  /* create a new metatable `m' ... */
 165.431 +    lua_pushvalue(L, -1);  /* ... and mark `m' as a valid metatable */
 165.432 +    lua_pushboolean(L, 1);
 165.433 +    lua_rawset(L, lua_upvalueindex(1));  /* weaktable[m] = true */
 165.434 +  }
 165.435 +  else {
 165.436 +    int validproxy = 0;  /* to check if weaktable[metatable(u)] == true */
 165.437 +    if (lua_getmetatable(L, 1)) {
 165.438 +      lua_rawget(L, lua_upvalueindex(1));
 165.439 +      validproxy = lua_toboolean(L, -1);
 165.440 +      lua_pop(L, 1);  /* remove value */
 165.441 +    }
 165.442 +    luaL_argcheck(L, validproxy, 1, "boolean or proxy expected");
 165.443 +    lua_getmetatable(L, 1);  /* metatable is valid; get it */
 165.444 +  }
 165.445 +  lua_setmetatable(L, 2);
 165.446 +  return 1;
 165.447 +}
 165.448 +
 165.449 +
 165.450 +static const luaL_Reg base_funcs[] = {
 165.451 +  {"assert", luaB_assert},
 165.452 +  {"collectgarbage", luaB_collectgarbage},
 165.453 +  {"dofile", luaB_dofile},
 165.454 +  {"error", luaB_error},
 165.455 +  {"gcinfo", luaB_gcinfo},
 165.456 +  {"getfenv", luaB_getfenv},
 165.457 +  {"getmetatable", luaB_getmetatable},
 165.458 +  {"loadfile", luaB_loadfile},
 165.459 +  {"load", luaB_load},
 165.460 +  {"loadstring", luaB_loadstring},
 165.461 +  {"next", luaB_next},
 165.462 +  {"pcall", luaB_pcall},
 165.463 +  {"print", luaB_print},
 165.464 +  {"rawequal", luaB_rawequal},
 165.465 +  {"rawget", luaB_rawget},
 165.466 +  {"rawset", luaB_rawset},
 165.467 +  {"select", luaB_select},
 165.468 +  {"setfenv", luaB_setfenv},
 165.469 +  {"setmetatable", luaB_setmetatable},
 165.470 +  {"tonumber", luaB_tonumber},
 165.471 +  {"tostring", luaB_tostring},
 165.472 +  {"type", luaB_type},
 165.473 +  {"unpack", luaB_unpack},
 165.474 +  {"xpcall", luaB_xpcall},
 165.475 +  {NULL, NULL}
 165.476 +};
 165.477 +
 165.478 +
 165.479 +/*
 165.480 +** {======================================================
 165.481 +** Coroutine library
 165.482 +** =======================================================
 165.483 +*/
 165.484 +
 165.485 +#define CO_RUN	0	/* running */
 165.486 +#define CO_SUS	1	/* suspended */
 165.487 +#define CO_NOR	2	/* 'normal' (it resumed another coroutine) */
 165.488 +#define CO_DEAD	3
 165.489 +
 165.490 +static const char *const statnames[] =
 165.491 +    {"running", "suspended", "normal", "dead"};
 165.492 +
 165.493 +static int costatus (lua_State *L, lua_State *co) {
 165.494 +  if (L == co) return CO_RUN;
 165.495 +  switch (lua_status(co)) {
 165.496 +    case LUA_YIELD:
 165.497 +      return CO_SUS;
 165.498 +    case 0: {
 165.499 +      lua_Debug ar;
 165.500 +      if (lua_getstack(co, 0, &ar) > 0)  /* does it have frames? */
 165.501 +        return CO_NOR;  /* it is running */
 165.502 +      else if (lua_gettop(co) == 0)
 165.503 +          return CO_DEAD;
 165.504 +      else
 165.505 +        return CO_SUS;  /* initial state */
 165.506 +    }
 165.507 +    default:  /* some error occured */
 165.508 +      return CO_DEAD;
 165.509 +  }
 165.510 +}
 165.511 +
 165.512 +
 165.513 +static int luaB_costatus (lua_State *L) {
 165.514 +  lua_State *co = lua_tothread(L, 1);
 165.515 +  luaL_argcheck(L, co, 1, "coroutine expected");
 165.516 +  lua_pushstring(L, statnames[costatus(L, co)]);
 165.517 +  return 1;
 165.518 +}
 165.519 +
 165.520 +
 165.521 +static int auxresume (lua_State *L, lua_State *co, int narg) {
 165.522 +  int status = costatus(L, co);
 165.523 +  if (!lua_checkstack(co, narg))
 165.524 +    luaL_error(L, "too many arguments to resume");
 165.525 +  if (status != CO_SUS) {
 165.526 +    lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]);
 165.527 +    return -1;  /* error flag */
 165.528 +  }
 165.529 +  lua_xmove(L, co, narg);
 165.530 +  lua_setlevel(L, co);
 165.531 +  status = lua_resume(co, narg);
 165.532 +  if (status == 0 || status == LUA_YIELD) {
 165.533 +    int nres = lua_gettop(co);
 165.534 +    if (!lua_checkstack(L, nres + 1))
 165.535 +      luaL_error(L, "too many results to resume");
 165.536 +    lua_xmove(co, L, nres);  /* move yielded values */
 165.537 +    return nres;
 165.538 +  }
 165.539 +  else {
 165.540 +    lua_xmove(co, L, 1);  /* move error message */
 165.541 +    return -1;  /* error flag */
 165.542 +  }
 165.543 +}
 165.544 +
 165.545 +
 165.546 +static int luaB_coresume (lua_State *L) {
 165.547 +  lua_State *co = lua_tothread(L, 1);
 165.548 +  int r;
 165.549 +  luaL_argcheck(L, co, 1, "coroutine expected");
 165.550 +  r = auxresume(L, co, lua_gettop(L) - 1);
 165.551 +  if (r < 0) {
 165.552 +    lua_pushboolean(L, 0);
 165.553 +    lua_insert(L, -2);
 165.554 +    return 2;  /* return false + error message */
 165.555 +  }
 165.556 +  else {
 165.557 +    lua_pushboolean(L, 1);
 165.558 +    lua_insert(L, -(r + 1));
 165.559 +    return r + 1;  /* return true + `resume' returns */
 165.560 +  }
 165.561 +}
 165.562 +
 165.563 +
 165.564 +static int luaB_auxwrap (lua_State *L) {
 165.565 +  lua_State *co = lua_tothread(L, lua_upvalueindex(1));
 165.566 +  int r = auxresume(L, co, lua_gettop(L));
 165.567 +  if (r < 0) {
 165.568 +    if (lua_isstring(L, -1)) {  /* error object is a string? */
 165.569 +      luaL_where(L, 1);  /* add extra info */
 165.570 +      lua_insert(L, -2);
 165.571 +      lua_concat(L, 2);
 165.572 +    }
 165.573 +    lua_error(L);  /* propagate error */
 165.574 +  }
 165.575 +  return r;
 165.576 +}
 165.577 +
 165.578 +
 165.579 +static int luaB_cocreate (lua_State *L) {
 165.580 +  lua_State *NL = lua_newthread(L);
 165.581 +  luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1,
 165.582 +    "Lua function expected");
 165.583 +  lua_pushvalue(L, 1);  /* move function to top */
 165.584 +  lua_xmove(L, NL, 1);  /* move function from L to NL */
 165.585 +  return 1;
 165.586 +}
 165.587 +
 165.588 +
 165.589 +static int luaB_cowrap (lua_State *L) {
 165.590 +  luaB_cocreate(L);
 165.591 +  lua_pushcclosure(L, luaB_auxwrap, 1);
 165.592 +  return 1;
 165.593 +}
 165.594 +
 165.595 +
 165.596 +static int luaB_yield (lua_State *L) {
 165.597 +  return lua_yield(L, lua_gettop(L));
 165.598 +}
 165.599 +
 165.600 +
 165.601 +static int luaB_corunning (lua_State *L) {
 165.602 +  if (lua_pushthread(L))
 165.603 +    lua_pushnil(L);  /* main thread is not a coroutine */
 165.604 +  return 1;
 165.605 +}
 165.606 +
 165.607 +
 165.608 +static const luaL_Reg co_funcs[] = {
 165.609 +  {"create", luaB_cocreate},
 165.610 +  {"resume", luaB_coresume},
 165.611 +  {"running", luaB_corunning},
 165.612 +  {"status", luaB_costatus},
 165.613 +  {"wrap", luaB_cowrap},
 165.614 +  {"yield", luaB_yield},
 165.615 +  {NULL, NULL}
 165.616 +};
 165.617 +
 165.618 +/* }====================================================== */
 165.619 +
 165.620 +
 165.621 +static void auxopen (lua_State *L, const char *name,
 165.622 +                     lua_CFunction f, lua_CFunction u) {
 165.623 +  lua_pushcfunction(L, u);
 165.624 +  lua_pushcclosure(L, f, 1);
 165.625 +  lua_setfield(L, -2, name);
 165.626 +}
 165.627 +
 165.628 +
 165.629 +static void base_open (lua_State *L) {
 165.630 +  /* set global _G */
 165.631 +  lua_pushvalue(L, LUA_GLOBALSINDEX);
 165.632 +  lua_setglobal(L, "_G");
 165.633 +  /* open lib into global table */
 165.634 +  luaL_register(L, "_G", base_funcs);
 165.635 +  lua_pushliteral(L, LUA_VERSION);
 165.636 +  lua_setglobal(L, "_VERSION");  /* set global _VERSION */
 165.637 +  /* `ipairs' and `pairs' need auxliliary functions as upvalues */
 165.638 +  auxopen(L, "ipairs", luaB_ipairs, ipairsaux);
 165.639 +  auxopen(L, "pairs", luaB_pairs, luaB_next);
 165.640 +  /* `newproxy' needs a weaktable as upvalue */
 165.641 +  lua_createtable(L, 0, 1);  /* new table `w' */
 165.642 +  lua_pushvalue(L, -1);  /* `w' will be its own metatable */
 165.643 +  lua_setmetatable(L, -2);
 165.644 +  lua_pushliteral(L, "kv");
 165.645 +  lua_setfield(L, -2, "__mode");  /* metatable(w).__mode = "kv" */
 165.646 +  lua_pushcclosure(L, luaB_newproxy, 1);
 165.647 +  lua_setglobal(L, "newproxy");  /* set global `newproxy' */
 165.648 +}
 165.649 +
 165.650 +
 165.651 +LUALIB_API int luaopen_base (lua_State *L) {
 165.652 +  base_open(L);
 165.653 +  luaL_register(L, LUA_COLIBNAME, co_funcs);
 165.654 +  return 2;
 165.655 +}
 165.656 +
   166.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   166.2 +++ b/src/lua/src/lcode.c	Sat Mar 03 10:31:27 2012 -0600
   166.3 @@ -0,0 +1,839 @@
   166.4 +/*
   166.5 +** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $
   166.6 +** Code generator for Lua
   166.7 +** See Copyright Notice in lua.h
   166.8 +*/
   166.9 +
  166.10 +
  166.11 +#include <stdlib.h>
  166.12 +
  166.13 +#define lcode_c
  166.14 +#define LUA_CORE
  166.15 +
  166.16 +#include "lua.h"
  166.17 +
  166.18 +#include "lcode.h"
  166.19 +#include "ldebug.h"
  166.20 +#include "ldo.h"
  166.21 +#include "lgc.h"
  166.22 +#include "llex.h"
  166.23 +#include "lmem.h"
  166.24 +#include "lobject.h"
  166.25 +#include "lopcodes.h"
  166.26 +#include "lparser.h"
  166.27 +#include "ltable.h"
  166.28 +
  166.29 +
  166.30 +#define hasjumps(e)	((e)->t != (e)->f)
  166.31 +
  166.32 +
  166.33 +static int isnumeral(expdesc *e) {
  166.34 +  return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP);
  166.35 +}
  166.36 +
  166.37 +
  166.38 +void luaK_nil (FuncState *fs, int from, int n) {
  166.39 +  Instruction *previous;
  166.40 +  if (fs->pc > fs->lasttarget) {  /* no jumps to current position? */
  166.41 +    if (fs->pc == 0) {  /* function start? */
  166.42 +      if (from >= fs->nactvar)
  166.43 +        return;  /* positions are already clean */
  166.44 +    }
  166.45 +    else {
  166.46 +      previous = &fs->f->code[fs->pc-1];
  166.47 +      if (GET_OPCODE(*previous) == OP_LOADNIL) {
  166.48 +        int pfrom = GETARG_A(*previous);
  166.49 +        int pto = GETARG_B(*previous);
  166.50 +        if (pfrom <= from && from <= pto+1) {  /* can connect both? */
  166.51 +          if (from+n-1 > pto)
  166.52 +            SETARG_B(*previous, from+n-1);
  166.53 +          return;
  166.54 +        }
  166.55 +      }
  166.56 +    }
  166.57 +  }
  166.58 +  luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0);  /* else no optimization */
  166.59 +}
  166.60 +
  166.61 +
  166.62 +int luaK_jump (FuncState *fs) {
  166.63 +  int jpc = fs->jpc;  /* save list of jumps to here */
  166.64 +  int j;
  166.65 +  fs->jpc = NO_JUMP;
  166.66 +  j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);
  166.67 +  luaK_concat(fs, &j, jpc);  /* keep them on hold */
  166.68 +  return j;
  166.69 +}
  166.70 +
  166.71 +
  166.72 +void luaK_ret (FuncState *fs, int first, int nret) {
  166.73 +  luaK_codeABC(fs, OP_RETURN, first, nret+1, 0);
  166.74 +}
  166.75 +
  166.76 +
  166.77 +static int condjump (FuncState *fs, OpCode op, int A, int B, int C) {
  166.78 +  luaK_codeABC(fs, op, A, B, C);
  166.79 +  return luaK_jump(fs);
  166.80 +}
  166.81 +
  166.82 +
  166.83 +static void fixjump (FuncState *fs, int pc, int dest) {
  166.84 +  Instruction *jmp = &fs->f->code[pc];
  166.85 +  int offset = dest-(pc+1);
  166.86 +  lua_assert(dest != NO_JUMP);
  166.87 +  if (abs(offset) > MAXARG_sBx)
  166.88 +    luaX_syntaxerror(fs->ls, "control structure too long");
  166.89 +  SETARG_sBx(*jmp, offset);
  166.90 +}
  166.91 +
  166.92 +
  166.93 +/*
  166.94 +** returns current `pc' and marks it as a jump target (to avoid wrong
  166.95 +** optimizations with consecutive instructions not in the same basic block).
  166.96 +*/
  166.97 +int luaK_getlabel (FuncState *fs) {
  166.98 +  fs->lasttarget = fs->pc;
  166.99 +  return fs->pc;
 166.100 +}
 166.101 +
 166.102 +
 166.103 +static int getjump (FuncState *fs, int pc) {
 166.104 +  int offset = GETARG_sBx(fs->f->code[pc]);
 166.105 +  if (offset == NO_JUMP)  /* point to itself represents end of list */
 166.106 +    return NO_JUMP;  /* end of list */
 166.107 +  else
 166.108 +    return (pc+1)+offset;  /* turn offset into absolute position */
 166.109 +}
 166.110 +
 166.111 +
 166.112 +static Instruction *getjumpcontrol (FuncState *fs, int pc) {
 166.113 +  Instruction *pi = &fs->f->code[pc];
 166.114 +  if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))
 166.115 +    return pi-1;
 166.116 +  else
 166.117 +    return pi;
 166.118 +}
 166.119 +
 166.120 +
 166.121 +/*
 166.122 +** check whether list has any jump that do not produce a value
 166.123 +** (or produce an inverted value)
 166.124 +*/
 166.125 +static int need_value (FuncState *fs, int list) {
 166.126 +  for (; list != NO_JUMP; list = getjump(fs, list)) {
 166.127 +    Instruction i = *getjumpcontrol(fs, list);
 166.128 +    if (GET_OPCODE(i) != OP_TESTSET) return 1;
 166.129 +  }
 166.130 +  return 0;  /* not found */
 166.131 +}
 166.132 +
 166.133 +
 166.134 +static int patchtestreg (FuncState *fs, int node, int reg) {
 166.135 +  Instruction *i = getjumpcontrol(fs, node);
 166.136 +  if (GET_OPCODE(*i) != OP_TESTSET)
 166.137 +    return 0;  /* cannot patch other instructions */
 166.138 +  if (reg != NO_REG && reg != GETARG_B(*i))
 166.139 +    SETARG_A(*i, reg);
 166.140 +  else  /* no register to put value or register already has the value */
 166.141 +    *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));
 166.142 +
 166.143 +  return 1;
 166.144 +}
 166.145 +
 166.146 +
 166.147 +static void removevalues (FuncState *fs, int list) {
 166.148 +  for (; list != NO_JUMP; list = getjump(fs, list))
 166.149 +      patchtestreg(fs, list, NO_REG);
 166.150 +}
 166.151 +
 166.152 +
 166.153 +static void patchlistaux (FuncState *fs, int list, int vtarget, int reg,
 166.154 +                          int dtarget) {
 166.155 +  while (list != NO_JUMP) {
 166.156 +    int next = getjump(fs, list);
 166.157 +    if (patchtestreg(fs, list, reg))
 166.158 +      fixjump(fs, list, vtarget);
 166.159 +    else
 166.160 +      fixjump(fs, list, dtarget);  /* jump to default target */
 166.161 +    list = next;
 166.162 +  }
 166.163 +}
 166.164 +
 166.165 +
 166.166 +static void dischargejpc (FuncState *fs) {
 166.167 +  patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);
 166.168 +  fs->jpc = NO_JUMP;
 166.169 +}
 166.170 +
 166.171 +
 166.172 +void luaK_patchlist (FuncState *fs, int list, int target) {
 166.173 +  if (target == fs->pc)
 166.174 +    luaK_patchtohere(fs, list);
 166.175 +  else {
 166.176 +    lua_assert(target < fs->pc);
 166.177 +    patchlistaux(fs, list, target, NO_REG, target);
 166.178 +  }
 166.179 +}
 166.180 +
 166.181 +
 166.182 +void luaK_patchtohere (FuncState *fs, int list) {
 166.183 +  luaK_getlabel(fs);
 166.184 +  luaK_concat(fs, &fs->jpc, list);
 166.185 +}
 166.186 +
 166.187 +
 166.188 +void luaK_concat (FuncState *fs, int *l1, int l2) {
 166.189 +  if (l2 == NO_JUMP) return;
 166.190 +  else if (*l1 == NO_JUMP)
 166.191 +    *l1 = l2;
 166.192 +  else {
 166.193 +    int list = *l1;
 166.194 +    int next;
 166.195 +    while ((next = getjump(fs, list)) != NO_JUMP)  /* find last element */
 166.196 +      list = next;
 166.197 +    fixjump(fs, list, l2);
 166.198 +  }
 166.199 +}
 166.200 +
 166.201 +
 166.202 +void luaK_checkstack (FuncState *fs, int n) {
 166.203 +  int newstack = fs->freereg + n;
 166.204 +  if (newstack > fs->f->maxstacksize) {
 166.205 +    if (newstack >= MAXSTACK)
 166.206 +      luaX_syntaxerror(fs->ls, "function or expression too complex");
 166.207 +    fs->f->maxstacksize = cast_byte(newstack);
 166.208 +  }
 166.209 +}
 166.210 +
 166.211 +
 166.212 +void luaK_reserveregs (FuncState *fs, int n) {
 166.213 +  luaK_checkstack(fs, n);
 166.214 +  fs->freereg += n;
 166.215 +}
 166.216 +
 166.217 +
 166.218 +static void freereg (FuncState *fs, int reg) {
 166.219 +  if (!ISK(reg) && reg >= fs->nactvar) {
 166.220 +    fs->freereg--;
 166.221 +    lua_assert(reg == fs->freereg);
 166.222 +  }
 166.223 +}
 166.224 +
 166.225 +
 166.226 +static void freeexp (FuncState *fs, expdesc *e) {
 166.227 +  if (e->k == VNONRELOC)
 166.228 +    freereg(fs, e->u.s.info);
 166.229 +}
 166.230 +
 166.231 +
 166.232 +static int addk (FuncState *fs, TValue *k, TValue *v) {
 166.233 +  lua_State *L = fs->L;
 166.234 +  TValue *idx = luaH_set(L, fs->h, k);
 166.235 +  Proto *f = fs->f;
 166.236 +  int oldsize = f->sizek;
 166.237 +  if (ttisnumber(idx)) {
 166.238 +    lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v));
 166.239 +    return cast_int(nvalue(idx));
 166.240 +  }
 166.241 +  else {  /* constant not found; create a new entry */
 166.242 +    setnvalue(idx, cast_num(fs->nk));
 166.243 +    luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,
 166.244 +                    MAXARG_Bx, "constant table overflow");
 166.245 +    while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
 166.246 +    setobj(L, &f->k[fs->nk], v);
 166.247 +    luaC_barrier(L, f, v);
 166.248 +    return fs->nk++;
 166.249 +  }
 166.250 +}
 166.251 +
 166.252 +
 166.253 +int luaK_stringK (FuncState *fs, TString *s) {
 166.254 +  TValue o;
 166.255 +  setsvalue(fs->L, &o, s);
 166.256 +  return addk(fs, &o, &o);
 166.257 +}
 166.258 +
 166.259 +
 166.260 +int luaK_numberK (FuncState *fs, lua_Number r) {
 166.261 +  TValue o;
 166.262 +  setnvalue(&o, r);
 166.263 +  return addk(fs, &o, &o);
 166.264 +}
 166.265 +
 166.266 +
 166.267 +static int boolK (FuncState *fs, int b) {
 166.268 +  TValue o;
 166.269 +  setbvalue(&o, b);
 166.270 +  return addk(fs, &o, &o);
 166.271 +}
 166.272 +
 166.273 +
 166.274 +static int nilK (FuncState *fs) {
 166.275 +  TValue k, v;
 166.276 +  setnilvalue(&v);
 166.277 +  /* cannot use nil as key; instead use table itself to represent nil */
 166.278 +  sethvalue(fs->L, &k, fs->h);
 166.279 +  return addk(fs, &k, &v);
 166.280 +}
 166.281 +
 166.282 +
 166.283 +void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {
 166.284 +  if (e->k == VCALL) {  /* expression is an open function call? */
 166.285 +    SETARG_C(getcode(fs, e), nresults+1);
 166.286 +  }
 166.287 +  else if (e->k == VVARARG) {
 166.288 +    SETARG_B(getcode(fs, e), nresults+1);
 166.289 +    SETARG_A(getcode(fs, e), fs->freereg);
 166.290 +    luaK_reserveregs(fs, 1);
 166.291 +  }
 166.292 +}
 166.293 +
 166.294 +
 166.295 +void luaK_setoneret (FuncState *fs, expdesc *e) {
 166.296 +  if (e->k == VCALL) {  /* expression is an open function call? */
 166.297 +    e->k = VNONRELOC;
 166.298 +    e->u.s.info = GETARG_A(getcode(fs, e));
 166.299 +  }
 166.300 +  else if (e->k == VVARARG) {
 166.301 +    SETARG_B(getcode(fs, e), 2);
 166.302 +    e->k = VRELOCABLE;  /* can relocate its simple result */
 166.303 +  }
 166.304 +}
 166.305 +
 166.306 +
 166.307 +void luaK_dischargevars (FuncState *fs, expdesc *e) {
 166.308 +  switch (e->k) {
 166.309 +    case VLOCAL: {
 166.310 +      e->k = VNONRELOC;
 166.311 +      break;
 166.312 +    }
 166.313 +    case VUPVAL: {
 166.314 +      e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0);
 166.315 +      e->k = VRELOCABLE;
 166.316 +      break;
 166.317 +    }
 166.318 +    case VGLOBAL: {
 166.319 +      e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info);
 166.320 +      e->k = VRELOCABLE;
 166.321 +      break;
 166.322 +    }
 166.323 +    case VINDEXED: {
 166.324 +      freereg(fs, e->u.s.aux);
 166.325 +      freereg(fs, e->u.s.info);
 166.326 +      e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux);
 166.327 +      e->k = VRELOCABLE;
 166.328 +      break;
 166.329 +    }
 166.330 +    case VVARARG:
 166.331 +    case VCALL: {
 166.332 +      luaK_setoneret(fs, e);
 166.333 +      break;
 166.334 +    }
 166.335 +    default: break;  /* there is one value available (somewhere) */
 166.336 +  }
 166.337 +}
 166.338 +
 166.339 +
 166.340 +static int code_label (FuncState *fs, int A, int b, int jump) {
 166.341 +  luaK_getlabel(fs);  /* those instructions may be jump targets */
 166.342 +  return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);
 166.343 +}
 166.344 +
 166.345 +
 166.346 +static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
 166.347 +  luaK_dischargevars(fs, e);
 166.348 +  switch (e->k) {
 166.349 +    case VNIL: {
 166.350 +      luaK_nil(fs, reg, 1);
 166.351 +      break;
 166.352 +    }
 166.353 +    case VFALSE:  case VTRUE: {
 166.354 +      luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);
 166.355 +      break;
 166.356 +    }
 166.357 +    case VK: {
 166.358 +      luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info);
 166.359 +      break;
 166.360 +    }
 166.361 +    case VKNUM: {
 166.362 +      luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval));
 166.363 +      break;
 166.364 +    }
 166.365 +    case VRELOCABLE: {
 166.366 +      Instruction *pc = &getcode(fs, e);
 166.367 +      SETARG_A(*pc, reg);
 166.368 +      break;
 166.369 +    }
 166.370 +    case VNONRELOC: {
 166.371 +      if (reg != e->u.s.info)
 166.372 +        luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0);
 166.373 +      break;
 166.374 +    }
 166.375 +    default: {
 166.376 +      lua_assert(e->k == VVOID || e->k == VJMP);
 166.377 +      return;  /* nothing to do... */
 166.378 +    }
 166.379 +  }
 166.380 +  e->u.s.info = reg;
 166.381 +  e->k = VNONRELOC;
 166.382 +}
 166.383 +
 166.384 +
 166.385 +static void discharge2anyreg (FuncState *fs, expdesc *e) {
 166.386 +  if (e->k != VNONRELOC) {
 166.387 +    luaK_reserveregs(fs, 1);
 166.388 +    discharge2reg(fs, e, fs->freereg-1);
 166.389 +  }
 166.390 +}
 166.391 +
 166.392 +
 166.393 +static void exp2reg (FuncState *fs, expdesc *e, int reg) {
 166.394 +  discharge2reg(fs, e, reg);
 166.395 +  if (e->k == VJMP)
 166.396 +    luaK_concat(fs, &e->t, e->u.s.info);  /* put this jump in `t' list */
 166.397 +  if (hasjumps(e)) {
 166.398 +    int final;  /* position after whole expression */
 166.399 +    int p_f = NO_JUMP;  /* position of an eventual LOAD false */
 166.400 +    int p_t = NO_JUMP;  /* position of an eventual LOAD true */
 166.401 +    if (need_value(fs, e->t) || need_value(fs, e->f)) {
 166.402 +      int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);
 166.403 +      p_f = code_label(fs, reg, 0, 1);
 166.404 +      p_t = code_label(fs, reg, 1, 0);
 166.405 +      luaK_patchtohere(fs, fj);
 166.406 +    }
 166.407 +    final = luaK_getlabel(fs);
 166.408 +    patchlistaux(fs, e->f, final, reg, p_f);
 166.409 +    patchlistaux(fs, e->t, final, reg, p_t);
 166.410 +  }
 166.411 +  e->f = e->t = NO_JUMP;
 166.412 +  e->u.s.info = reg;
 166.413 +  e->k = VNONRELOC;
 166.414 +}
 166.415 +
 166.416 +
 166.417 +void luaK_exp2nextreg (FuncState *fs, expdesc *e) {
 166.418 +  luaK_dischargevars(fs, e);
 166.419 +  freeexp(fs, e);
 166.420 +  luaK_reserveregs(fs, 1);
 166.421 +  exp2reg(fs, e, fs->freereg - 1);
 166.422 +}
 166.423 +
 166.424 +
 166.425 +int luaK_exp2anyreg (FuncState *fs, expdesc *e) {
 166.426 +  luaK_dischargevars(fs, e);
 166.427 +  if (e->k == VNONRELOC) {
 166.428 +    if (!hasjumps(e)) return e->u.s.info;  /* exp is already in a register */
 166.429 +    if (e->u.s.info >= fs->nactvar) {  /* reg. is not a local? */
 166.430 +      exp2reg(fs, e, e->u.s.info);  /* put value on it */
 166.431 +      return e->u.s.info;
 166.432 +    }
 166.433 +  }
 166.434 +  luaK_exp2nextreg(fs, e);  /* default */
 166.435 +  return e->u.s.info;
 166.436 +}
 166.437 +
 166.438 +
 166.439 +void luaK_exp2val (FuncState *fs, expdesc *e) {
 166.440 +  if (hasjumps(e))
 166.441 +    luaK_exp2anyreg(fs, e);
 166.442 +  else
 166.443 +    luaK_dischargevars(fs, e);
 166.444 +}
 166.445 +
 166.446 +
 166.447 +int luaK_exp2RK (FuncState *fs, expdesc *e) {
 166.448 +  luaK_exp2val(fs, e);
 166.449 +  switch (e->k) {
 166.450 +    case VKNUM:
 166.451 +    case VTRUE:
 166.452 +    case VFALSE:
 166.453 +    case VNIL: {
 166.454 +      if (fs->nk <= MAXINDEXRK) {  /* constant fit in RK operand? */
 166.455 +        e->u.s.info = (e->k == VNIL)  ? nilK(fs) :
 166.456 +                      (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) :
 166.457 +                                        boolK(fs, (e->k == VTRUE));
 166.458 +        e->k = VK;
 166.459 +        return RKASK(e->u.s.info);
 166.460 +      }
 166.461 +      else break;
 166.462 +    }
 166.463 +    case VK: {
 166.464 +      if (e->u.s.info <= MAXINDEXRK)  /* constant fit in argC? */
 166.465 +        return RKASK(e->u.s.info);
 166.466 +      else break;
 166.467 +    }
 166.468 +    default: break;
 166.469 +  }
 166.470 +  /* not a constant in the right range: put it in a register */
 166.471 +  return luaK_exp2anyreg(fs, e);
 166.472 +}
 166.473 +
 166.474 +
 166.475 +void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
 166.476 +  switch (var->k) {
 166.477 +    case VLOCAL: {
 166.478 +      freeexp(fs, ex);
 166.479 +      exp2reg(fs, ex, var->u.s.info);
 166.480 +      return;
 166.481 +    }
 166.482 +    case VUPVAL: {
 166.483 +      int e = luaK_exp2anyreg(fs, ex);
 166.484 +      luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0);
 166.485 +      break;
 166.486 +    }
 166.487 +    case VGLOBAL: {
 166.488 +      int e = luaK_exp2anyreg(fs, ex);
 166.489 +      luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info);
 166.490 +      break;
 166.491 +    }
 166.492 +    case VINDEXED: {
 166.493 +      int e = luaK_exp2RK(fs, ex);
 166.494 +      luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e);
 166.495 +      break;
 166.496 +    }
 166.497 +    default: {
 166.498 +      lua_assert(0);  /* invalid var kind to store */
 166.499 +      break;
 166.500 +    }
 166.501 +  }
 166.502 +  freeexp(fs, ex);
 166.503 +}
 166.504 +
 166.505 +
 166.506 +void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
 166.507 +  int func;
 166.508 +  luaK_exp2anyreg(fs, e);
 166.509 +  freeexp(fs, e);
 166.510 +  func = fs->freereg;
 166.511 +  luaK_reserveregs(fs, 2);
 166.512 +  luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key));
 166.513 +  freeexp(fs, key);
 166.514 +  e->u.s.info = func;
 166.515 +  e->k = VNONRELOC;
 166.516 +}
 166.517 +
 166.518 +
 166.519 +static void invertjump (FuncState *fs, expdesc *e) {
 166.520 +  Instruction *pc = getjumpcontrol(fs, e->u.s.info);
 166.521 +  lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&
 166.522 +                                           GET_OPCODE(*pc) != OP_TEST);
 166.523 +  SETARG_A(*pc, !(GETARG_A(*pc)));
 166.524 +}
 166.525 +
 166.526 +
 166.527 +static int jumponcond (FuncState *fs, expdesc *e, int cond) {
 166.528 +  if (e->k == VRELOCABLE) {
 166.529 +    Instruction ie = getcode(fs, e);
 166.530 +    if (GET_OPCODE(ie) == OP_NOT) {
 166.531 +      fs->pc--;  /* remove previous OP_NOT */
 166.532 +      return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);
 166.533 +    }
 166.534 +    /* else go through */
 166.535 +  }
 166.536 +  discharge2anyreg(fs, e);
 166.537 +  freeexp(fs, e);
 166.538 +  return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond);
 166.539 +}
 166.540 +
 166.541 +
 166.542 +void luaK_goiftrue (FuncState *fs, expdesc *e) {
 166.543 +  int pc;  /* pc of last jump */
 166.544 +  luaK_dischargevars(fs, e);
 166.545 +  switch (e->k) {
 166.546 +    case VK: case VKNUM: case VTRUE: {
 166.547 +      pc = NO_JUMP;  /* always true; do nothing */
 166.548 +      break;
 166.549 +    }
 166.550 +    case VFALSE: {
 166.551 +      pc = luaK_jump(fs);  /* always jump */
 166.552 +      break;
 166.553 +    }
 166.554 +    case VJMP: {
 166.555 +      invertjump(fs, e);
 166.556 +      pc = e->u.s.info;
 166.557 +      break;
 166.558 +    }
 166.559 +    default: {
 166.560 +      pc = jumponcond(fs, e, 0);
 166.561 +      break;
 166.562 +    }
 166.563 +  }
 166.564 +  luaK_concat(fs, &e->f, pc);  /* insert last jump in `f' list */
 166.565 +  luaK_patchtohere(fs, e->t);
 166.566 +  e->t = NO_JUMP;
 166.567 +}
 166.568 +
 166.569 +
 166.570 +static void luaK_goiffalse (FuncState *fs, expdesc *e) {
 166.571 +  int pc;  /* pc of last jump */
 166.572 +  luaK_dischargevars(fs, e);
 166.573 +  switch (e->k) {
 166.574 +    case VNIL: case VFALSE: {
 166.575 +      pc = NO_JUMP;  /* always false; do nothing */
 166.576 +      break;
 166.577 +    }
 166.578 +    case VTRUE: {
 166.579 +      pc = luaK_jump(fs);  /* always jump */
 166.580 +      break;
 166.581 +    }
 166.582 +    case VJMP: {
 166.583 +      pc = e->u.s.info;
 166.584 +      break;
 166.585 +    }
 166.586 +    default: {
 166.587 +      pc = jumponcond(fs, e, 1);
 166.588 +      break;
 166.589 +    }
 166.590 +  }
 166.591 +  luaK_concat(fs, &e->t, pc);  /* insert last jump in `t' list */
 166.592 +  luaK_patchtohere(fs, e->f);
 166.593 +  e->f = NO_JUMP;
 166.594 +}
 166.595 +
 166.596 +
 166.597 +static void codenot (FuncState *fs, expdesc *e) {
 166.598 +  luaK_dischargevars(fs, e);
 166.599 +  switch (e->k) {
 166.600 +    case VNIL: case VFALSE: {
 166.601 +      e->k = VTRUE;
 166.602 +      break;
 166.603 +    }
 166.604 +    case VK: case VKNUM: case VTRUE: {
 166.605 +      e->k = VFALSE;
 166.606 +      break;
 166.607 +    }
 166.608 +    case VJMP: {
 166.609 +      invertjump(fs, e);
 166.610 +      break;
 166.611 +    }
 166.612 +    case VRELOCABLE:
 166.613 +    case VNONRELOC: {
 166.614 +      discharge2anyreg(fs, e);
 166.615 +      freeexp(fs, e);
 166.616 +      e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0);
 166.617 +      e->k = VRELOCABLE;
 166.618 +      break;
 166.619 +    }
 166.620 +    default: {
 166.621 +      lua_assert(0);  /* cannot happen */
 166.622 +      break;
 166.623 +    }
 166.624 +  }
 166.625 +  /* interchange true and false lists */
 166.626 +  { int temp = e->f; e->f = e->t; e->t = temp; }
 166.627 +  removevalues(fs, e->f);
 166.628 +  removevalues(fs, e->t);
 166.629 +}
 166.630 +
 166.631 +
 166.632 +void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
 166.633 +  t->u.s.aux = luaK_exp2RK(fs, k);
 166.634 +  t->k = VINDEXED;
 166.635 +}
 166.636 +
 166.637 +
 166.638 +static int constfolding (OpCode op, expdesc *e1, expdesc *e2) {
 166.639 +  lua_Number v1, v2, r;
 166.640 +  if (!isnumeral(e1) || !isnumeral(e2)) return 0;
 166.641 +  v1 = e1->u.nval;
 166.642 +  v2 = e2->u.nval;
 166.643 +  switch (op) {
 166.644 +    case OP_ADD: r = luai_numadd(v1, v2); break;
 166.645 +    case OP_SUB: r = luai_numsub(v1, v2); break;
 166.646 +    case OP_MUL: r = luai_nummul(v1, v2); break;
 166.647 +    case OP_DIV:
 166.648 +      if (v2 == 0) return 0;  /* do not attempt to divide by 0 */
 166.649 +      r = luai_numdiv(v1, v2); break;
 166.650 +    case OP_MOD:
 166.651 +      if (v2 == 0) return 0;  /* do not attempt to divide by 0 */
 166.652 +      r = luai_nummod(v1, v2); break;
 166.653 +    case OP_POW: r = luai_numpow(v1, v2); break;
 166.654 +    case OP_UNM: r = luai_numunm(v1); break;
 166.655 +    case OP_LEN: return 0;  /* no constant folding for 'len' */
 166.656 +    default: lua_assert(0); r = 0; break;
 166.657 +  }
 166.658 +  if (luai_numisnan(r)) return 0;  /* do not attempt to produce NaN */
 166.659 +  e1->u.nval = r;
 166.660 +  return 1;
 166.661 +}
 166.662 +
 166.663 +
 166.664 +static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {
 166.665 +  if (constfolding(op, e1, e2))
 166.666 +    return;
 166.667 +  else {
 166.668 +    int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
 166.669 +    int o1 = luaK_exp2RK(fs, e1);
 166.670 +    if (o1 > o2) {
 166.671 +      freeexp(fs, e1);
 166.672 +      freeexp(fs, e2);
 166.673 +    }
 166.674 +    else {
 166.675 +      freeexp(fs, e2);
 166.676 +      freeexp(fs, e1);
 166.677 +    }
 166.678 +    e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
 166.679 +    e1->k = VRELOCABLE;
 166.680 +  }
 166.681 +}
 166.682 +
 166.683 +
 166.684 +static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1,
 166.685 +                                                          expdesc *e2) {
 166.686 +  int o1 = luaK_exp2RK(fs, e1);
 166.687 +  int o2 = luaK_exp2RK(fs, e2);
 166.688 +  freeexp(fs, e2);
 166.689 +  freeexp(fs, e1);
 166.690 +  if (cond == 0 && op != OP_EQ) {
 166.691 +    int temp;  /* exchange args to replace by `<' or `<=' */
 166.692 +    temp = o1; o1 = o2; o2 = temp;  /* o1 <==> o2 */
 166.693 +    cond = 1;
 166.694 +  }
 166.695 +  e1->u.s.info = condjump(fs, op, cond, o1, o2);
 166.696 +  e1->k = VJMP;
 166.697 +}
 166.698 +
 166.699 +
 166.700 +void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) {
 166.701 +  expdesc e2;
 166.702 +  e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
 166.703 +  switch (op) {
 166.704 +    case OPR_MINUS: {
 166.705 +      if (!isnumeral(e))
 166.706 +        luaK_exp2anyreg(fs, e);  /* cannot operate on non-numeric constants */
 166.707 +      codearith(fs, OP_UNM, e, &e2);
 166.708 +      break;
 166.709 +    }
 166.710 +    case OPR_NOT: codenot(fs, e); break;
 166.711 +    case OPR_LEN: {
 166.712 +      luaK_exp2anyreg(fs, e);  /* cannot operate on constants */
 166.713 +      codearith(fs, OP_LEN, e, &e2);
 166.714 +      break;
 166.715 +    }
 166.716 +    default: lua_assert(0);
 166.717 +  }
 166.718 +}
 166.719 +
 166.720 +
 166.721 +void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
 166.722 +  switch (op) {
 166.723 +    case OPR_AND: {
 166.724 +      luaK_goiftrue(fs, v);
 166.725 +      break;
 166.726 +    }
 166.727 +    case OPR_OR: {
 166.728 +      luaK_goiffalse(fs, v);
 166.729 +      break;
 166.730 +    }
 166.731 +    case OPR_CONCAT: {
 166.732 +      luaK_exp2nextreg(fs, v);  /* operand must be on the `stack' */
 166.733 +      break;
 166.734 +    }
 166.735 +    case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
 166.736 +    case OPR_MOD: case OPR_POW: {
 166.737 +      if (!isnumeral(v)) luaK_exp2RK(fs, v);
 166.738 +      break;
 166.739 +    }
 166.740 +    default: {
 166.741 +      luaK_exp2RK(fs, v);
 166.742 +      break;
 166.743 +    }
 166.744 +  }
 166.745 +}
 166.746 +
 166.747 +
 166.748 +void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
 166.749 +  switch (op) {
 166.750 +    case OPR_AND: {
 166.751 +      lua_assert(e1->t == NO_JUMP);  /* list must be closed */
 166.752 +      luaK_dischargevars(fs, e2);
 166.753 +      luaK_concat(fs, &e2->f, e1->f);
 166.754 +      *e1 = *e2;
 166.755 +      break;
 166.756 +    }
 166.757 +    case OPR_OR: {
 166.758 +      lua_assert(e1->f == NO_JUMP);  /* list must be closed */
 166.759 +      luaK_dischargevars(fs, e2);
 166.760 +      luaK_concat(fs, &e2->t, e1->t);
 166.761 +      *e1 = *e2;
 166.762 +      break;
 166.763 +    }
 166.764 +    case OPR_CONCAT: {
 166.765 +      luaK_exp2val(fs, e2);
 166.766 +      if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {
 166.767 +        lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1);
 166.768 +        freeexp(fs, e1);
 166.769 +        SETARG_B(getcode(fs, e2), e1->u.s.info);
 166.770 +        e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info;
 166.771 +      }
 166.772 +      else {
 166.773 +        luaK_exp2nextreg(fs, e2);  /* operand must be on the 'stack' */
 166.774 +        codearith(fs, OP_CONCAT, e1, e2);
 166.775 +      }
 166.776 +      break;
 166.777 +    }
 166.778 +    case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break;
 166.779 +    case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break;
 166.780 +    case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break;
 166.781 +    case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break;
 166.782 +    case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break;
 166.783 +    case OPR_POW: codearith(fs, OP_POW, e1, e2); break;
 166.784 +    case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break;
 166.785 +    case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break;
 166.786 +    case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break;
 166.787 +    case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break;
 166.788 +    case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break;
 166.789 +    case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break;
 166.790 +    default: lua_assert(0);
 166.791 +  }
 166.792 +}
 166.793 +
 166.794 +
 166.795 +void luaK_fixline (FuncState *fs, int line) {
 166.796 +  fs->f->lineinfo[fs->pc - 1] = line;
 166.797 +}
 166.798 +
 166.799 +
 166.800 +static int luaK_code (FuncState *fs, Instruction i, int line) {
 166.801 +  Proto *f = fs->f;
 166.802 +  dischargejpc(fs);  /* `pc' will change */
 166.803 +  /* put new instruction in code array */
 166.804 +  luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction,
 166.805 +                  MAX_INT, "code size overflow");
 166.806 +  f->code[fs->pc] = i;
 166.807 +  /* save corresponding line information */
 166.808 +  luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
 166.809 +                  MAX_INT, "code size overflow");
 166.810 +  f->lineinfo[fs->pc] = line;
 166.811 +  return fs->pc++;
 166.812 +}
 166.813 +
 166.814 +
 166.815 +int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) {
 166.816 +  lua_assert(getOpMode(o) == iABC);
 166.817 +  lua_assert(getBMode(o) != OpArgN || b == 0);
 166.818 +  lua_assert(getCMode(o) != OpArgN || c == 0);
 166.819 +  return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline);
 166.820 +}
 166.821 +
 166.822 +
 166.823 +int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {
 166.824 +  lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);
 166.825 +  lua_assert(getCMode(o) == OpArgN);
 166.826 +  return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline);
 166.827 +}
 166.828 +
 166.829 +
 166.830 +void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) {
 166.831 +  int c =  (nelems - 1)/LFIELDS_PER_FLUSH + 1;
 166.832 +  int b = (tostore == LUA_MULTRET) ? 0 : tostore;
 166.833 +  lua_assert(tostore != 0);
 166.834 +  if (c <= MAXARG_C)
 166.835 +    luaK_codeABC(fs, OP_SETLIST, base, b, c);
 166.836 +  else {
 166.837 +    luaK_codeABC(fs, OP_SETLIST, base, b, 0);
 166.838 +    luaK_code(fs, cast(Instruction, c), fs->ls->lastline);
 166.839 +  }
 166.840 +  fs->freereg = base + 1;  /* free registers with list values */
 166.841 +}
 166.842 +
   167.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   167.2 +++ b/src/lua/src/lcode.h	Sat Mar 03 10:31:27 2012 -0600
   167.3 @@ -0,0 +1,76 @@
   167.4 +/*
   167.5 +** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $
   167.6 +** Code generator for Lua
   167.7 +** See Copyright Notice in lua.h
   167.8 +*/
   167.9 +
  167.10 +#ifndef lcode_h
  167.11 +#define lcode_h
  167.12 +
  167.13 +#include "llex.h"
  167.14 +#include "lobject.h"
  167.15 +#include "lopcodes.h"
  167.16 +#include "lparser.h"
  167.17 +
  167.18 +
  167.19 +/*
  167.20 +** Marks the end of a patch list. It is an invalid value both as an absolute
  167.21 +** address, and as a list link (would link an element to itself).
  167.22 +*/
  167.23 +#define NO_JUMP (-1)
  167.24 +
  167.25 +
  167.26 +/*
  167.27 +** grep "ORDER OPR" if you change these enums
  167.28 +*/
  167.29 +typedef enum BinOpr {
  167.30 +  OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,
  167.31 +  OPR_CONCAT,
  167.32 +  OPR_NE, OPR_EQ,
  167.33 +  OPR_LT, OPR_LE, OPR_GT, OPR_GE,
  167.34 +  OPR_AND, OPR_OR,
  167.35 +  OPR_NOBINOPR
  167.36 +} BinOpr;
  167.37 +
  167.38 +
  167.39 +typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
  167.40 +
  167.41 +
  167.42 +#define getcode(fs,e)	((fs)->f->code[(e)->u.s.info])
  167.43 +
  167.44 +#define luaK_codeAsBx(fs,o,A,sBx)	luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)
  167.45 +
  167.46 +#define luaK_setmultret(fs,e)	luaK_setreturns(fs, e, LUA_MULTRET)
  167.47 +
  167.48 +LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
  167.49 +LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);
  167.50 +LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
  167.51 +LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);
  167.52 +LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);
  167.53 +LUAI_FUNC void luaK_checkstack (FuncState *fs, int n);
  167.54 +LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s);
  167.55 +LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r);
  167.56 +LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);
  167.57 +LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);
  167.58 +LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);
  167.59 +LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);
  167.60 +LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);
  167.61 +LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
  167.62 +LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
  167.63 +LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);
  167.64 +LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);
  167.65 +LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);
  167.66 +LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);
  167.67 +LUAI_FUNC int luaK_jump (FuncState *fs);
  167.68 +LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);
  167.69 +LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);
  167.70 +LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);
  167.71 +LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);
  167.72 +LUAI_FUNC int luaK_getlabel (FuncState *fs);
  167.73 +LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v);
  167.74 +LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);
  167.75 +LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2);
  167.76 +LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
  167.77 +
  167.78 +
  167.79 +#endif
   168.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   168.2 +++ b/src/lua/src/ldblib.c	Sat Mar 03 10:31:27 2012 -0600
   168.3 @@ -0,0 +1,397 @@
   168.4 +/*
   168.5 +** $Id: ldblib.c,v 1.104.1.3 2008/01/21 13:11:21 roberto Exp $
   168.6 +** Interface from Lua to its debug API
   168.7 +** See Copyright Notice in lua.h
   168.8 +*/
   168.9 +
  168.10 +
  168.11 +#include <stdio.h>
  168.12 +#include <stdlib.h>
  168.13 +#include <string.h>
  168.14 +
  168.15 +#define ldblib_c
  168.16 +#define LUA_LIB
  168.17 +
  168.18 +#include "lua.h"
  168.19 +
  168.20 +#include "lauxlib.h"
  168.21 +#include "lualib.h"
  168.22 +
  168.23 +
  168.24 +
  168.25 +static int db_getregistry (lua_State *L) {
  168.26 +  lua_pushvalue(L, LUA_REGISTRYINDEX);
  168.27 +  return 1;
  168.28 +}
  168.29 +
  168.30 +
  168.31 +static int db_getmetatable (lua_State *L) {
  168.32 +  luaL_checkany(L, 1);
  168.33 +  if (!lua_getmetatable(L, 1)) {
  168.34 +    lua_pushnil(L);  /* no metatable */
  168.35 +  }
  168.36 +  return 1;
  168.37 +}
  168.38 +
  168.39 +
  168.40 +static int db_setmetatable (lua_State *L) {
  168.41 +  int t = lua_type(L, 2);
  168.42 +  luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
  168.43 +                    "nil or table expected");
  168.44 +  lua_settop(L, 2);
  168.45 +  lua_pushboolean(L, lua_setmetatable(L, 1));
  168.46 +  return 1;
  168.47 +}
  168.48 +
  168.49 +
  168.50 +static int db_getfenv (lua_State *L) {
  168.51 +  lua_getfenv(L, 1);
  168.52 +  return 1;
  168.53 +}
  168.54 +
  168.55 +
  168.56 +static int db_setfenv (lua_State *L) {
  168.57 +  luaL_checktype(L, 2, LUA_TTABLE);
  168.58 +  lua_settop(L, 2);
  168.59 +  if (lua_setfenv(L, 1) == 0)
  168.60 +    luaL_error(L, LUA_QL("setfenv")
  168.61 +                  " cannot change environment of given object");
  168.62 +  return 1;
  168.63 +}
  168.64 +
  168.65 +
  168.66 +static void settabss (lua_State *L, const char *i, const char *v) {
  168.67 +  lua_pushstring(L, v);
  168.68 +  lua_setfield(L, -2, i);
  168.69 +}
  168.70 +
  168.71 +
  168.72 +static void settabsi (lua_State *L, const char *i, int v) {
  168.73 +  lua_pushinteger(L, v);
  168.74 +  lua_setfield(L, -2, i);
  168.75 +}
  168.76 +
  168.77 +
  168.78 +static lua_State *getthread (lua_State *L, int *arg) {
  168.79 +  if (lua_isthread(L, 1)) {
  168.80 +    *arg = 1;
  168.81 +    return lua_tothread(L, 1);
  168.82 +  }
  168.83 +  else {
  168.84 +    *arg = 0;
  168.85 +    return L;
  168.86 +  }
  168.87 +}
  168.88 +
  168.89 +
  168.90 +static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {
  168.91 +  if (L == L1) {
  168.92 +    lua_pushvalue(L, -2);
  168.93 +    lua_remove(L, -3);
  168.94 +  }
  168.95 +  else
  168.96 +    lua_xmove(L1, L, 1);
  168.97 +  lua_setfield(L, -2, fname);
  168.98 +}
  168.99 +
 168.100 +
 168.101 +static int db_getinfo (lua_State *L) {
 168.102 +  lua_Debug ar;
 168.103 +  int arg;
 168.104 +  lua_State *L1 = getthread(L, &arg);
 168.105 +  const char *options = luaL_optstring(L, arg+2, "flnSu");
 168.106 +  if (lua_isnumber(L, arg+1)) {
 168.107 +    if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {
 168.108 +      lua_pushnil(L);  /* level out of range */
 168.109 +      return 1;
 168.110 +    }
 168.111 +  }
 168.112 +  else if (lua_isfunction(L, arg+1)) {
 168.113 +    lua_pushfstring(L, ">%s", options);
 168.114 +    options = lua_tostring(L, -1);
 168.115 +    lua_pushvalue(L, arg+1);
 168.116 +    lua_xmove(L, L1, 1);
 168.117 +  }
 168.118 +  else
 168.119 +    return luaL_argerror(L, arg+1, "function or level expected");
 168.120 +  if (!lua_getinfo(L1, options, &ar))
 168.121 +    return luaL_argerror(L, arg+2, "invalid option");
 168.122 +  lua_createtable(L, 0, 2);
 168.123 +  if (strchr(options, 'S')) {
 168.124 +    settabss(L, "source", ar.source);
 168.125 +    settabss(L, "short_src", ar.short_src);
 168.126 +    settabsi(L, "linedefined", ar.linedefined);
 168.127 +    settabsi(L, "lastlinedefined", ar.lastlinedefined);
 168.128 +    settabss(L, "what", ar.what);
 168.129 +  }
 168.130 +  if (strchr(options, 'l'))
 168.131 +    settabsi(L, "currentline", ar.currentline);
 168.132 +  if (strchr(options, 'u'))
 168.133 +    settabsi(L, "nups", ar.nups);
 168.134 +  if (strchr(options, 'n')) {
 168.135 +    settabss(L, "name", ar.name);
 168.136 +    settabss(L, "namewhat", ar.namewhat);
 168.137 +  }
 168.138 +  if (strchr(options, 'L'))
 168.139 +    treatstackoption(L, L1, "activelines");
 168.140 +  if (strchr(options, 'f'))
 168.141 +    treatstackoption(L, L1, "func");
 168.142 +  return 1;  /* return table */
 168.143 +}
 168.144 +    
 168.145 +
 168.146 +static int db_getlocal (lua_State *L) {
 168.147 +  int arg;
 168.148 +  lua_State *L1 = getthread(L, &arg);
 168.149 +  lua_Debug ar;
 168.150 +  const char *name;
 168.151 +  if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar))  /* out of range? */
 168.152 +    return luaL_argerror(L, arg+1, "level out of range");
 168.153 +  name = lua_getlocal(L1, &ar, luaL_checkint(L, arg+2));
 168.154 +  if (name) {
 168.155 +    lua_xmove(L1, L, 1);
 168.156 +    lua_pushstring(L, name);
 168.157 +    lua_pushvalue(L, -2);
 168.158 +    return 2;
 168.159 +  }
 168.160 +  else {
 168.161 +    lua_pushnil(L);
 168.162 +    return 1;
 168.163 +  }
 168.164 +}
 168.165 +
 168.166 +
 168.167 +static int db_setlocal (lua_State *L) {
 168.168 +  int arg;
 168.169 +  lua_State *L1 = getthread(L, &arg);
 168.170 +  lua_Debug ar;
 168.171 +  if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar))  /* out of range? */
 168.172 +    return luaL_argerror(L, arg+1, "level out of range");
 168.173 +  luaL_checkany(L, arg+3);
 168.174 +  lua_settop(L, arg+3);
 168.175 +  lua_xmove(L, L1, 1);
 168.176 +  lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2)));
 168.177 +  return 1;
 168.178 +}
 168.179 +
 168.180 +
 168.181 +static int auxupvalue (lua_State *L, int get) {
 168.182 +  const char *name;
 168.183 +  int n = luaL_checkint(L, 2);
 168.184 +  luaL_checktype(L, 1, LUA_TFUNCTION);
 168.185 +  if (lua_iscfunction(L, 1)) return 0;  /* cannot touch C upvalues from Lua */
 168.186 +  name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);
 168.187 +  if (name == NULL) return 0;
 168.188 +  lua_pushstring(L, name);
 168.189 +  lua_insert(L, -(get+1));
 168.190 +  return get + 1;
 168.191 +}
 168.192 +
 168.193 +
 168.194 +static int db_getupvalue (lua_State *L) {
 168.195 +  return auxupvalue(L, 1);
 168.196 +}
 168.197 +
 168.198 +
 168.199 +static int db_setupvalue (lua_State *L) {
 168.200 +  luaL_checkany(L, 3);
 168.201 +  return auxupvalue(L, 0);
 168.202 +}
 168.203 +
 168.204 +
 168.205 +
 168.206 +static const char KEY_HOOK = 'h';
 168.207 +
 168.208 +
 168.209 +static void hookf (lua_State *L, lua_Debug *ar) {
 168.210 +  static const char *const hooknames[] =
 168.211 +    {"call", "return", "line", "count", "tail return"};
 168.212 +  lua_pushlightuserdata(L, (void *)&KEY_HOOK);
 168.213 +  lua_rawget(L, LUA_REGISTRYINDEX);
 168.214 +  lua_pushlightuserdata(L, L);
 168.215 +  lua_rawget(L, -2);
 168.216 +  if (lua_isfunction(L, -1)) {
 168.217 +    lua_pushstring(L, hooknames[(int)ar->event]);
 168.218 +    if (ar->currentline >= 0)
 168.219 +      lua_pushinteger(L, ar->currentline);
 168.220 +    else lua_pushnil(L);
 168.221 +    lua_assert(lua_getinfo(L, "lS", ar));
 168.222 +    lua_call(L, 2, 0);
 168.223 +  }
 168.224 +}
 168.225 +
 168.226 +
 168.227 +static int makemask (const char *smask, int count) {
 168.228 +  int mask = 0;
 168.229 +  if (strchr(smask, 'c')) mask |= LUA_MASKCALL;
 168.230 +  if (strchr(smask, 'r')) mask |= LUA_MASKRET;
 168.231 +  if (strchr(smask, 'l')) mask |= LUA_MASKLINE;
 168.232 +  if (count > 0) mask |= LUA_MASKCOUNT;
 168.233 +  return mask;
 168.234 +}
 168.235 +
 168.236 +
 168.237 +static char *unmakemask (int mask, char *smask) {
 168.238 +  int i = 0;
 168.239 +  if (mask & LUA_MASKCALL) smask[i++] = 'c';
 168.240 +  if (mask & LUA_MASKRET) smask[i++] = 'r';
 168.241 +  if (mask & LUA_MASKLINE) smask[i++] = 'l';
 168.242 +  smask[i] = '\0';
 168.243 +  return smask;
 168.244 +}
 168.245 +
 168.246 +
 168.247 +static void gethooktable (lua_State *L) {
 168.248 +  lua_pushlightuserdata(L, (void *)&KEY_HOOK);
 168.249 +  lua_rawget(L, LUA_REGISTRYINDEX);
 168.250 +  if (!lua_istable(L, -1)) {
 168.251 +    lua_pop(L, 1);
 168.252 +    lua_createtable(L, 0, 1);
 168.253 +    lua_pushlightuserdata(L, (void *)&KEY_HOOK);
 168.254 +    lua_pushvalue(L, -2);
 168.255 +    lua_rawset(L, LUA_REGISTRYINDEX);
 168.256 +  }
 168.257 +}
 168.258 +
 168.259 +
 168.260 +static int db_sethook (lua_State *L) {
 168.261 +  int arg, mask, count;
 168.262 +  lua_Hook func;
 168.263 +  lua_State *L1 = getthread(L, &arg);
 168.264 +  if (lua_isnoneornil(L, arg+1)) {
 168.265 +    lua_settop(L, arg+1);
 168.266 +    func = NULL; mask = 0; count = 0;  /* turn off hooks */
 168.267 +  }
 168.268 +  else {
 168.269 +    const char *smask = luaL_checkstring(L, arg+2);
 168.270 +    luaL_checktype(L, arg+1, LUA_TFUNCTION);
 168.271 +    count = luaL_optint(L, arg+3, 0);
 168.272 +    func = hookf; mask = makemask(smask, count);
 168.273 +  }
 168.274 +  gethooktable(L);
 168.275 +  lua_pushlightuserdata(L, L1);
 168.276 +  lua_pushvalue(L, arg+1);
 168.277 +  lua_rawset(L, -3);  /* set new hook */
 168.278 +  lua_pop(L, 1);  /* remove hook table */
 168.279 +  lua_sethook(L1, func, mask, count);  /* set hooks */
 168.280 +  return 0;
 168.281 +}
 168.282 +
 168.283 +
 168.284 +static int db_gethook (lua_State *L) {
 168.285 +  int arg;
 168.286 +  lua_State *L1 = getthread(L, &arg);
 168.287 +  char buff[5];
 168.288 +  int mask = lua_gethookmask(L1);
 168.289 +  lua_Hook hook = lua_gethook(L1);
 168.290 +  if (hook != NULL && hook != hookf)  /* external hook? */
 168.291 +    lua_pushliteral(L, "external hook");
 168.292 +  else {
 168.293 +    gethooktable(L);
 168.294 +    lua_pushlightuserdata(L, L1);
 168.295 +    lua_rawget(L, -2);   /* get hook */
 168.296 +    lua_remove(L, -2);  /* remove hook table */
 168.297 +  }
 168.298 +  lua_pushstring(L, unmakemask(mask, buff));
 168.299 +  lua_pushinteger(L, lua_gethookcount(L1));
 168.300 +  return 3;
 168.301 +}
 168.302 +
 168.303 +
 168.304 +static int db_debug (lua_State *L) {
 168.305 +  for (;;) {
 168.306 +    char buffer[250];
 168.307 +    fputs("lua_debug> ", stderr);
 168.308 +    if (fgets(buffer, sizeof(buffer), stdin) == 0 ||
 168.309 +        strcmp(buffer, "cont\n") == 0)
 168.310 +      return 0;
 168.311 +    if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
 168.312 +        lua_pcall(L, 0, 0, 0)) {
 168.313 +      fputs(lua_tostring(L, -1), stderr);
 168.314 +      fputs("\n", stderr);
 168.315 +    }
 168.316 +    lua_settop(L, 0);  /* remove eventual returns */
 168.317 +  }
 168.318 +}
 168.319 +
 168.320 +
 168.321 +#define LEVELS1	12	/* size of the first part of the stack */
 168.322 +#define LEVELS2	10	/* size of the second part of the stack */
 168.323 +
 168.324 +static int db_errorfb (lua_State *L) {
 168.325 +  int level;
 168.326 +  int firstpart = 1;  /* still before eventual `...' */
 168.327 +  int arg;
 168.328 +  lua_State *L1 = getthread(L, &arg);
 168.329 +  lua_Debug ar;
 168.330 +  if (lua_isnumber(L, arg+2)) {
 168.331 +    level = (int)lua_tointeger(L, arg+2);
 168.332 +    lua_pop(L, 1);
 168.333 +  }
 168.334 +  else
 168.335 +    level = (L == L1) ? 1 : 0;  /* level 0 may be this own function */
 168.336 +  if (lua_gettop(L) == arg)
 168.337 +    lua_pushliteral(L, "");
 168.338 +  else if (!lua_isstring(L, arg+1)) return 1;  /* message is not a string */
 168.339 +  else lua_pushliteral(L, "\n");
 168.340 +  lua_pushliteral(L, "stack traceback:");
 168.341 +  while (lua_getstack(L1, level++, &ar)) {
 168.342 +    if (level > LEVELS1 && firstpart) {
 168.343 +      /* no more than `LEVELS2' more levels? */
 168.344 +      if (!lua_getstack(L1, level+LEVELS2, &ar))
 168.345 +        level--;  /* keep going */
 168.346 +      else {
 168.347 +        lua_pushliteral(L, "\n\t...");  /* too many levels */
 168.348 +        while (lua_getstack(L1, level+LEVELS2, &ar))  /* find last levels */
 168.349 +          level++;
 168.350 +      }
 168.351 +      firstpart = 0;
 168.352 +      continue;
 168.353 +    }
 168.354 +    lua_pushliteral(L, "\n\t");
 168.355 +    lua_getinfo(L1, "Snl", &ar);
 168.356 +    lua_pushfstring(L, "%s:", ar.short_src);
 168.357 +    if (ar.currentline > 0)
 168.358 +      lua_pushfstring(L, "%d:", ar.currentline);
 168.359 +    if (*ar.namewhat != '\0')  /* is there a name? */
 168.360 +        lua_pushfstring(L, " in function " LUA_QS, ar.name);
 168.361 +    else {
 168.362 +      if (*ar.what == 'm')  /* main? */
 168.363 +        lua_pushfstring(L, " in main chunk");
 168.364 +      else if (*ar.what == 'C' || *ar.what == 't')
 168.365 +        lua_pushliteral(L, " ?");  /* C function or tail call */
 168.366 +      else
 168.367 +        lua_pushfstring(L, " in function <%s:%d>",
 168.368 +                           ar.short_src, ar.linedefined);
 168.369 +    }
 168.370 +    lua_concat(L, lua_gettop(L) - arg);
 168.371 +  }
 168.372 +  lua_concat(L, lua_gettop(L) - arg);
 168.373 +  return 1;
 168.374 +}
 168.375 +
 168.376 +
 168.377 +static const luaL_Reg dblib[] = {
 168.378 +  {"debug", db_debug},
 168.379 +  {"getfenv", db_getfenv},
 168.380 +  {"gethook", db_gethook},
 168.381 +  {"getinfo", db_getinfo},
 168.382 +  {"getlocal", db_getlocal},
 168.383 +  {"getregistry", db_getregistry},
 168.384 +  {"getmetatable", db_getmetatable},
 168.385 +  {"getupvalue", db_getupvalue},
 168.386 +  {"setfenv", db_setfenv},
 168.387 +  {"sethook", db_sethook},
 168.388 +  {"setlocal", db_setlocal},
 168.389 +  {"setmetatable", db_setmetatable},
 168.390 +  {"setupvalue", db_setupvalue},
 168.391 +  {"traceback", db_errorfb},
 168.392 +  {NULL, NULL}
 168.393 +};
 168.394 +
 168.395 +
 168.396 +LUALIB_API int luaopen_debug (lua_State *L) {
 168.397 +  luaL_register(L, LUA_DBLIBNAME, dblib);
 168.398 +  return 1;
 168.399 +}
 168.400 +
   169.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   169.2 +++ b/src/lua/src/ldebug.c	Sat Mar 03 10:31:27 2012 -0600
   169.3 @@ -0,0 +1,638 @@
   169.4 +/*
   169.5 +** $Id: ldebug.c,v 2.29.1.6 2008/05/08 16:56:26 roberto Exp $
   169.6 +** Debug Interface
   169.7 +** See Copyright Notice in lua.h
   169.8 +*/
   169.9 +
  169.10 +
  169.11 +#include <stdarg.h>
  169.12 +#include <stddef.h>
  169.13 +#include <string.h>
  169.14 +
  169.15 +
  169.16 +#define ldebug_c
  169.17 +#define LUA_CORE
  169.18 +
  169.19 +#include "lua.h"
  169.20 +
  169.21 +#include "lapi.h"
  169.22 +#include "lcode.h"
  169.23 +#include "ldebug.h"
  169.24 +#include "ldo.h"
  169.25 +#include "lfunc.h"
  169.26 +#include "lobject.h"
  169.27 +#include "lopcodes.h"
  169.28 +#include "lstate.h"
  169.29 +#include "lstring.h"
  169.30 +#include "ltable.h"
  169.31 +#include "ltm.h"
  169.32 +#include "lvm.h"
  169.33 +
  169.34 +
  169.35 +
  169.36 +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);
  169.37 +
  169.38 +
  169.39 +static int currentpc (lua_State *L, CallInfo *ci) {
  169.40 +  if (!isLua(ci)) return -1;  /* function is not a Lua function? */
  169.41 +  if (ci == L->ci)
  169.42 +    ci->savedpc = L->savedpc;
  169.43 +  return pcRel(ci->savedpc, ci_func(ci)->l.p);
  169.44 +}
  169.45 +
  169.46 +
  169.47 +static int currentline (lua_State *L, CallInfo *ci) {
  169.48 +  int pc = currentpc(L, ci);
  169.49 +  if (pc < 0)
  169.50 +    return -1;  /* only active lua functions have current-line information */
  169.51 +  else
  169.52 +    return getline(ci_func(ci)->l.p, pc);
  169.53 +}
  169.54 +
  169.55 +
  169.56 +/*
  169.57 +** this function can be called asynchronous (e.g. during a signal)
  169.58 +*/
  169.59 +LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {
  169.60 +  if (func == NULL || mask == 0) {  /* turn off hooks? */
  169.61 +    mask = 0;
  169.62 +    func = NULL;
  169.63 +  }
  169.64 +  L->hook = func;
  169.65 +  L->basehookcount = count;
  169.66 +  resethookcount(L);
  169.67 +  L->hookmask = cast_byte(mask);
  169.68 +  return 1;
  169.69 +}
  169.70 +
  169.71 +
  169.72 +LUA_API lua_Hook lua_gethook (lua_State *L) {
  169.73 +  return L->hook;
  169.74 +}
  169.75 +
  169.76 +
  169.77 +LUA_API int lua_gethookmask (lua_State *L) {
  169.78 +  return L->hookmask;
  169.79 +}
  169.80 +
  169.81 +
  169.82 +LUA_API int lua_gethookcount (lua_State *L) {
  169.83 +  return L->basehookcount;
  169.84 +}
  169.85 +
  169.86 +
  169.87 +LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
  169.88 +  int status;
  169.89 +  CallInfo *ci;
  169.90 +  lua_lock(L);
  169.91 +  for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) {
  169.92 +    level--;
  169.93 +    if (f_isLua(ci))  /* Lua function? */
  169.94 +      level -= ci->tailcalls;  /* skip lost tail calls */
  169.95 +  }
  169.96 +  if (level == 0 && ci > L->base_ci) {  /* level found? */
  169.97 +    status = 1;
  169.98 +    ar->i_ci = cast_int(ci - L->base_ci);
  169.99 +  }
 169.100 +  else if (level < 0) {  /* level is of a lost tail call? */
 169.101 +    status = 1;
 169.102 +    ar->i_ci = 0;
 169.103 +  }
 169.104 +  else status = 0;  /* no such level */
 169.105 +  lua_unlock(L);
 169.106 +  return status;
 169.107 +}
 169.108 +
 169.109 +
 169.110 +static Proto *getluaproto (CallInfo *ci) {
 169.111 +  return (isLua(ci) ? ci_func(ci)->l.p : NULL);
 169.112 +}
 169.113 +
 169.114 +
 169.115 +static const char *findlocal (lua_State *L, CallInfo *ci, int n) {
 169.116 +  const char *name;
 169.117 +  Proto *fp = getluaproto(ci);
 169.118 +  if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL)
 169.119 +    return name;  /* is a local variable in a Lua function */
 169.120 +  else {
 169.121 +    StkId limit = (ci == L->ci) ? L->top : (ci+1)->func;
 169.122 +    if (limit - ci->base >= n && n > 0)  /* is 'n' inside 'ci' stack? */
 169.123 +      return "(*temporary)";
 169.124 +    else
 169.125 +      return NULL;
 169.126 +  }
 169.127 +}
 169.128 +
 169.129 +
 169.130 +LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
 169.131 +  CallInfo *ci = L->base_ci + ar->i_ci;
 169.132 +  const char *name = findlocal(L, ci, n);
 169.133 +  lua_lock(L);
 169.134 +  if (name)
 169.135 +      luaA_pushobject(L, ci->base + (n - 1));
 169.136 +  lua_unlock(L);
 169.137 +  return name;
 169.138 +}
 169.139 +
 169.140 +
 169.141 +LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
 169.142 +  CallInfo *ci = L->base_ci + ar->i_ci;
 169.143 +  const char *name = findlocal(L, ci, n);
 169.144 +  lua_lock(L);
 169.145 +  if (name)
 169.146 +      setobjs2s(L, ci->base + (n - 1), L->top - 1);
 169.147 +  L->top--;  /* pop value */
 169.148 +  lua_unlock(L);
 169.149 +  return name;
 169.150 +}
 169.151 +
 169.152 +
 169.153 +static void funcinfo (lua_Debug *ar, Closure *cl) {
 169.154 +  if (cl->c.isC) {
 169.155 +    ar->source = "=[C]";
 169.156 +    ar->linedefined = -1;
 169.157 +    ar->lastlinedefined = -1;
 169.158 +    ar->what = "C";
 169.159 +  }
 169.160 +  else {
 169.161 +    ar->source = getstr(cl->l.p->source);
 169.162 +    ar->linedefined = cl->l.p->linedefined;
 169.163 +    ar->lastlinedefined = cl->l.p->lastlinedefined;
 169.164 +    ar->what = (ar->linedefined == 0) ? "main" : "Lua";
 169.165 +  }
 169.166 +  luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);
 169.167 +}
 169.168 +
 169.169 +
 169.170 +static void info_tailcall (lua_Debug *ar) {
 169.171 +  ar->name = ar->namewhat = "";
 169.172 +  ar->what = "tail";
 169.173 +  ar->lastlinedefined = ar->linedefined = ar->currentline = -1;
 169.174 +  ar->source = "=(tail call)";
 169.175 +  luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);
 169.176 +  ar->nups = 0;
 169.177 +}
 169.178 +
 169.179 +
 169.180 +static void collectvalidlines (lua_State *L, Closure *f) {
 169.181 +  if (f == NULL || f->c.isC) {
 169.182 +    setnilvalue(L->top);
 169.183 +  }
 169.184 +  else {
 169.185 +    Table *t = luaH_new(L, 0, 0);
 169.186 +    int *lineinfo = f->l.p->lineinfo;
 169.187 +    int i;
 169.188 +    for (i=0; i<f->l.p->sizelineinfo; i++)
 169.189 +      setbvalue(luaH_setnum(L, t, lineinfo[i]), 1);
 169.190 +    sethvalue(L, L->top, t); 
 169.191 +  }
 169.192 +  incr_top(L);
 169.193 +}
 169.194 +
 169.195 +
 169.196 +static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
 169.197 +                    Closure *f, CallInfo *ci) {
 169.198 +  int status = 1;
 169.199 +  if (f == NULL) {
 169.200 +    info_tailcall(ar);
 169.201 +    return status;
 169.202 +  }
 169.203 +  for (; *what; what++) {
 169.204 +    switch (*what) {
 169.205 +      case 'S': {
 169.206 +        funcinfo(ar, f);
 169.207 +        break;
 169.208 +      }
 169.209 +      case 'l': {
 169.210 +        ar->currentline = (ci) ? currentline(L, ci) : -1;
 169.211 +        break;
 169.212 +      }
 169.213 +      case 'u': {
 169.214 +        ar->nups = f->c.nupvalues;
 169.215 +        break;
 169.216 +      }
 169.217 +      case 'n': {
 169.218 +        ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL;
 169.219 +        if (ar->namewhat == NULL) {
 169.220 +          ar->namewhat = "";  /* not found */
 169.221 +          ar->name = NULL;
 169.222 +        }
 169.223 +        break;
 169.224 +      }
 169.225 +      case 'L':
 169.226 +      case 'f':  /* handled by lua_getinfo */
 169.227 +        break;
 169.228 +      default: status = 0;  /* invalid option */
 169.229 +    }
 169.230 +  }
 169.231 +  return status;
 169.232 +}
 169.233 +
 169.234 +
 169.235 +LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
 169.236 +  int status;
 169.237 +  Closure *f = NULL;
 169.238 +  CallInfo *ci = NULL;
 169.239 +  lua_lock(L);
 169.240 +  if (*what == '>') {
 169.241 +    StkId func = L->top - 1;
 169.242 +    luai_apicheck(L, ttisfunction(func));
 169.243 +    what++;  /* skip the '>' */
 169.244 +    f = clvalue(func);
 169.245 +    L->top--;  /* pop function */
 169.246 +  }
 169.247 +  else if (ar->i_ci != 0) {  /* no tail call? */
 169.248 +    ci = L->base_ci + ar->i_ci;
 169.249 +    lua_assert(ttisfunction(ci->func));
 169.250 +    f = clvalue(ci->func);
 169.251 +  }
 169.252 +  status = auxgetinfo(L, what, ar, f, ci);
 169.253 +  if (strchr(what, 'f')) {
 169.254 +    if (f == NULL) setnilvalue(L->top);
 169.255 +    else setclvalue(L, L->top, f);
 169.256 +    incr_top(L);
 169.257 +  }
 169.258 +  if (strchr(what, 'L'))
 169.259 +    collectvalidlines(L, f);
 169.260 +  lua_unlock(L);
 169.261 +  return status;
 169.262 +}
 169.263 +
 169.264 +
 169.265 +/*
 169.266 +** {======================================================
 169.267 +** Symbolic Execution and code checker
 169.268 +** =======================================================
 169.269 +*/
 169.270 +
 169.271 +#define check(x)		if (!(x)) return 0;
 169.272 +
 169.273 +#define checkjump(pt,pc)	check(0 <= pc && pc < pt->sizecode)
 169.274 +
 169.275 +#define checkreg(pt,reg)	check((reg) < (pt)->maxstacksize)
 169.276 +
 169.277 +
 169.278 +
 169.279 +static int precheck (const Proto *pt) {
 169.280 +  check(pt->maxstacksize <= MAXSTACK);
 169.281 +  check(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize);
 169.282 +  check(!(pt->is_vararg & VARARG_NEEDSARG) ||
 169.283 +              (pt->is_vararg & VARARG_HASARG));
 169.284 +  check(pt->sizeupvalues <= pt->nups);
 169.285 +  check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0);
 169.286 +  check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN);
 169.287 +  return 1;
 169.288 +}
 169.289 +
 169.290 +
 169.291 +#define checkopenop(pt,pc)	luaG_checkopenop((pt)->code[(pc)+1])
 169.292 +
 169.293 +int luaG_checkopenop (Instruction i) {
 169.294 +  switch (GET_OPCODE(i)) {
 169.295 +    case OP_CALL:
 169.296 +    case OP_TAILCALL:
 169.297 +    case OP_RETURN:
 169.298 +    case OP_SETLIST: {
 169.299 +      check(GETARG_B(i) == 0);
 169.300 +      return 1;
 169.301 +    }
 169.302 +    default: return 0;  /* invalid instruction after an open call */
 169.303 +  }
 169.304 +}
 169.305 +
 169.306 +
 169.307 +static int checkArgMode (const Proto *pt, int r, enum OpArgMask mode) {
 169.308 +  switch (mode) {
 169.309 +    case OpArgN: check(r == 0); break;
 169.310 +    case OpArgU: break;
 169.311 +    case OpArgR: checkreg(pt, r); break;
 169.312 +    case OpArgK:
 169.313 +      check(ISK(r) ? INDEXK(r) < pt->sizek : r < pt->maxstacksize);
 169.314 +      break;
 169.315 +  }
 169.316 +  return 1;
 169.317 +}
 169.318 +
 169.319 +
 169.320 +static Instruction symbexec (const Proto *pt, int lastpc, int reg) {
 169.321 +  int pc;
 169.322 +  int last;  /* stores position of last instruction that changed `reg' */
 169.323 +  last = pt->sizecode-1;  /* points to final return (a `neutral' instruction) */
 169.324 +  check(precheck(pt));
 169.325 +  for (pc = 0; pc < lastpc; pc++) {
 169.326 +    Instruction i = pt->code[pc];
 169.327 +    OpCode op = GET_OPCODE(i);
 169.328 +    int a = GETARG_A(i);
 169.329 +    int b = 0;
 169.330 +    int c = 0;
 169.331 +    check(op < NUM_OPCODES);
 169.332 +    checkreg(pt, a);
 169.333 +    switch (getOpMode(op)) {
 169.334 +      case iABC: {
 169.335 +        b = GETARG_B(i);
 169.336 +        c = GETARG_C(i);
 169.337 +        check(checkArgMode(pt, b, getBMode(op)));
 169.338 +        check(checkArgMode(pt, c, getCMode(op)));
 169.339 +        break;
 169.340 +      }
 169.341 +      case iABx: {
 169.342 +        b = GETARG_Bx(i);
 169.343 +        if (getBMode(op) == OpArgK) check(b < pt->sizek);
 169.344 +        break;
 169.345 +      }
 169.346 +      case iAsBx: {
 169.347 +        b = GETARG_sBx(i);
 169.348 +        if (getBMode(op) == OpArgR) {
 169.349 +          int dest = pc+1+b;
 169.350 +          check(0 <= dest && dest < pt->sizecode);
 169.351 +          if (dest > 0) {
 169.352 +            int j;
 169.353 +            /* check that it does not jump to a setlist count; this
 169.354 +               is tricky, because the count from a previous setlist may
 169.355 +               have the same value of an invalid setlist; so, we must
 169.356 +               go all the way back to the first of them (if any) */
 169.357 +            for (j = 0; j < dest; j++) {
 169.358 +              Instruction d = pt->code[dest-1-j];
 169.359 +              if (!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)) break;
 169.360 +            }
 169.361 +            /* if 'j' is even, previous value is not a setlist (even if
 169.362 +               it looks like one) */
 169.363 +            check((j&1) == 0);
 169.364 +          }
 169.365 +        }
 169.366 +        break;
 169.367 +      }
 169.368 +    }
 169.369 +    if (testAMode(op)) {
 169.370 +      if (a == reg) last = pc;  /* change register `a' */
 169.371 +    }
 169.372 +    if (testTMode(op)) {
 169.373 +      check(pc+2 < pt->sizecode);  /* check skip */
 169.374 +      check(GET_OPCODE(pt->code[pc+1]) == OP_JMP);
 169.375 +    }
 169.376 +    switch (op) {
 169.377 +      case OP_LOADBOOL: {
 169.378 +        if (c == 1) {  /* does it jump? */
 169.379 +          check(pc+2 < pt->sizecode);  /* check its jump */
 169.380 +          check(GET_OPCODE(pt->code[pc+1]) != OP_SETLIST ||
 169.381 +                GETARG_C(pt->code[pc+1]) != 0);
 169.382 +        }
 169.383 +        break;
 169.384 +      }
 169.385 +      case OP_LOADNIL: {
 169.386 +        if (a <= reg && reg <= b)
 169.387 +          last = pc;  /* set registers from `a' to `b' */
 169.388 +        break;
 169.389 +      }
 169.390 +      case OP_GETUPVAL:
 169.391 +      case OP_SETUPVAL: {
 169.392 +        check(b < pt->nups);
 169.393 +        break;
 169.394 +      }
 169.395 +      case OP_GETGLOBAL:
 169.396 +      case OP_SETGLOBAL: {
 169.397 +        check(ttisstring(&pt->k[b]));
 169.398 +        break;
 169.399 +      }
 169.400 +      case OP_SELF: {
 169.401 +        checkreg(pt, a+1);
 169.402 +        if (reg == a+1) last = pc;
 169.403 +        break;
 169.404 +      }
 169.405 +      case OP_CONCAT: {
 169.406 +        check(b < c);  /* at least two operands */
 169.407 +        break;
 169.408 +      }
 169.409 +      case OP_TFORLOOP: {
 169.410 +        check(c >= 1);  /* at least one result (control variable) */
 169.411 +        checkreg(pt, a+2+c);  /* space for results */
 169.412 +        if (reg >= a+2) last = pc;  /* affect all regs above its base */
 169.413 +        break;
 169.414 +      }
 169.415 +      case OP_FORLOOP:
 169.416 +      case OP_FORPREP:
 169.417 +        checkreg(pt, a+3);
 169.418 +        /* go through */
 169.419 +      case OP_JMP: {
 169.420 +        int dest = pc+1+b;
 169.421 +        /* not full check and jump is forward and do not skip `lastpc'? */
 169.422 +        if (reg != NO_REG && pc < dest && dest <= lastpc)
 169.423 +          pc += b;  /* do the jump */
 169.424 +        break;
 169.425 +      }
 169.426 +      case OP_CALL:
 169.427 +      case OP_TAILCALL: {
 169.428 +        if (b != 0) {
 169.429 +          checkreg(pt, a+b-1);
 169.430 +        }
 169.431 +        c--;  /* c = num. returns */
 169.432 +        if (c == LUA_MULTRET) {
 169.433 +          check(checkopenop(pt, pc));
 169.434 +        }
 169.435 +        else if (c != 0)
 169.436 +          checkreg(pt, a+c-1);
 169.437 +        if (reg >= a) last = pc;  /* affect all registers above base */
 169.438 +        break;
 169.439 +      }
 169.440 +      case OP_RETURN: {
 169.441 +        b--;  /* b = num. returns */
 169.442 +        if (b > 0) checkreg(pt, a+b-1);
 169.443 +        break;
 169.444 +      }
 169.445 +      case OP_SETLIST: {
 169.446 +        if (b > 0) checkreg(pt, a + b);
 169.447 +        if (c == 0) {
 169.448 +          pc++;
 169.449 +          check(pc < pt->sizecode - 1);
 169.450 +        }
 169.451 +        break;
 169.452 +      }
 169.453 +      case OP_CLOSURE: {
 169.454 +        int nup, j;
 169.455 +        check(b < pt->sizep);
 169.456 +        nup = pt->p[b]->nups;
 169.457 +        check(pc + nup < pt->sizecode);
 169.458 +        for (j = 1; j <= nup; j++) {
 169.459 +          OpCode op1 = GET_OPCODE(pt->code[pc + j]);
 169.460 +          check(op1 == OP_GETUPVAL || op1 == OP_MOVE);
 169.461 +        }
 169.462 +        if (reg != NO_REG)  /* tracing? */
 169.463 +          pc += nup;  /* do not 'execute' these pseudo-instructions */
 169.464 +        break;
 169.465 +      }
 169.466 +      case OP_VARARG: {
 169.467 +        check((pt->is_vararg & VARARG_ISVARARG) &&
 169.468 +             !(pt->is_vararg & VARARG_NEEDSARG));
 169.469 +        b--;
 169.470 +        if (b == LUA_MULTRET) check(checkopenop(pt, pc));
 169.471 +        checkreg(pt, a+b-1);
 169.472 +        break;
 169.473 +      }
 169.474 +      default: break;
 169.475 +    }
 169.476 +  }
 169.477 +  return pt->code[last];
 169.478 +}
 169.479 +
 169.480 +#undef check
 169.481 +#undef checkjump
 169.482 +#undef checkreg
 169.483 +
 169.484 +/* }====================================================== */
 169.485 +
 169.486 +
 169.487 +int luaG_checkcode (const Proto *pt) {
 169.488 +  return (symbexec(pt, pt->sizecode, NO_REG) != 0);
 169.489 +}
 169.490 +
 169.491 +
 169.492 +static const char *kname (Proto *p, int c) {
 169.493 +  if (ISK(c) && ttisstring(&p->k[INDEXK(c)]))
 169.494 +    return svalue(&p->k[INDEXK(c)]);
 169.495 +  else
 169.496 +    return "?";
 169.497 +}
 169.498 +
 169.499 +
 169.500 +static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos,
 169.501 +                               const char **name) {
 169.502 +  if (isLua(ci)) {  /* a Lua function? */
 169.503 +    Proto *p = ci_func(ci)->l.p;
 169.504 +    int pc = currentpc(L, ci);
 169.505 +    Instruction i;
 169.506 +    *name = luaF_getlocalname(p, stackpos+1, pc);
 169.507 +    if (*name)  /* is a local? */
 169.508 +      return "local";
 169.509 +    i = symbexec(p, pc, stackpos);  /* try symbolic execution */
 169.510 +    lua_assert(pc != -1);
 169.511 +    switch (GET_OPCODE(i)) {
 169.512 +      case OP_GETGLOBAL: {
 169.513 +        int g = GETARG_Bx(i);  /* global index */
 169.514 +        lua_assert(ttisstring(&p->k[g]));
 169.515 +        *name = svalue(&p->k[g]);
 169.516 +        return "global";
 169.517 +      }
 169.518 +      case OP_MOVE: {
 169.519 +        int a = GETARG_A(i);
 169.520 +        int b = GETARG_B(i);  /* move from `b' to `a' */
 169.521 +        if (b < a)
 169.522 +          return getobjname(L, ci, b, name);  /* get name for `b' */
 169.523 +        break;
 169.524 +      }
 169.525 +      case OP_GETTABLE: {
 169.526 +        int k = GETARG_C(i);  /* key index */
 169.527 +        *name = kname(p, k);
 169.528 +        return "field";
 169.529 +      }
 169.530 +      case OP_GETUPVAL: {
 169.531 +        int u = GETARG_B(i);  /* upvalue index */
 169.532 +        *name = p->upvalues ? getstr(p->upvalues[u]) : "?";
 169.533 +        return "upvalue";
 169.534 +      }
 169.535 +      case OP_SELF: {
 169.536 +        int k = GETARG_C(i);  /* key index */
 169.537 +        *name = kname(p, k);
 169.538 +        return "method";
 169.539 +      }
 169.540 +      default: break;
 169.541 +    }
 169.542 +  }
 169.543 +  return NULL;  /* no useful name found */
 169.544 +}
 169.545 +
 169.546 +
 169.547 +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
 169.548 +  Instruction i;
 169.549 +  if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1))
 169.550 +    return NULL;  /* calling function is not Lua (or is unknown) */
 169.551 +  ci--;  /* calling function */
 169.552 +  i = ci_func(ci)->l.p->code[currentpc(L, ci)];
 169.553 +  if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL ||
 169.554 +      GET_OPCODE(i) == OP_TFORLOOP)
 169.555 +    return getobjname(L, ci, GETARG_A(i), name);
 169.556 +  else
 169.557 +    return NULL;  /* no useful name can be found */
 169.558 +}
 169.559 +
 169.560 +
 169.561 +/* only ANSI way to check whether a pointer points to an array */
 169.562 +static int isinstack (CallInfo *ci, const TValue *o) {
 169.563 +  StkId p;
 169.564 +  for (p = ci->base; p < ci->top; p++)
 169.565 +    if (o == p) return 1;
 169.566 +  return 0;
 169.567 +}
 169.568 +
 169.569 +
 169.570 +void luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
 169.571 +  const char *name = NULL;
 169.572 +  const char *t = luaT_typenames[ttype(o)];
 169.573 +  const char *kind = (isinstack(L->ci, o)) ?
 169.574 +                         getobjname(L, L->ci, cast_int(o - L->base), &name) :
 169.575 +                         NULL;
 169.576 +  if (kind)
 169.577 +    luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)",
 169.578 +                op, kind, name, t);
 169.579 +  else
 169.580 +    luaG_runerror(L, "attempt to %s a %s value", op, t);
 169.581 +}
 169.582 +
 169.583 +
 169.584 +void luaG_concaterror (lua_State *L, StkId p1, StkId p2) {
 169.585 +  if (ttisstring(p1) || ttisnumber(p1)) p1 = p2;
 169.586 +  lua_assert(!ttisstring(p1) && !ttisnumber(p1));
 169.587 +  luaG_typeerror(L, p1, "concatenate");
 169.588 +}
 169.589 +
 169.590 +
 169.591 +void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) {
 169.592 +  TValue temp;
 169.593 +  if (luaV_tonumber(p1, &temp) == NULL)
 169.594 +    p2 = p1;  /* first operand is wrong */
 169.595 +  luaG_typeerror(L, p2, "perform arithmetic on");
 169.596 +}
 169.597 +
 169.598 +
 169.599 +int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
 169.600 +  const char *t1 = luaT_typenames[ttype(p1)];
 169.601 +  const char *t2 = luaT_typenames[ttype(p2)];
 169.602 +  if (t1[2] == t2[2])
 169.603 +    luaG_runerror(L, "attempt to compare two %s values", t1);
 169.604 +  else
 169.605 +    luaG_runerror(L, "attempt to compare %s with %s", t1, t2);
 169.606 +  return 0;
 169.607 +}
 169.608 +
 169.609 +
 169.610 +static void addinfo (lua_State *L, const char *msg) {
 169.611 +  CallInfo *ci = L->ci;
 169.612 +  if (isLua(ci)) {  /* is Lua code? */
 169.613 +    char buff[LUA_IDSIZE];  /* add file:line information */
 169.614 +    int line = currentline(L, ci);
 169.615 +    luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE);
 169.616 +    luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
 169.617 +  }
 169.618 +}
 169.619 +
 169.620 +
 169.621 +void luaG_errormsg (lua_State *L) {
 169.622 +  if (L->errfunc != 0) {  /* is there an error handling function? */
 169.623 +    StkId errfunc = restorestack(L, L->errfunc);
 169.624 +    if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
 169.625 +    setobjs2s(L, L->top, L->top - 1);  /* move argument */
 169.626 +    setobjs2s(L, L->top - 1, errfunc);  /* push function */
 169.627 +    incr_top(L);
 169.628 +    luaD_call(L, L->top - 2, 1);  /* call it */
 169.629 +  }
 169.630 +  luaD_throw(L, LUA_ERRRUN);
 169.631 +}
 169.632 +
 169.633 +
 169.634 +void luaG_runerror (lua_State *L, const char *fmt, ...) {
 169.635 +  va_list argp;
 169.636 +  va_start(argp, fmt);
 169.637 +  addinfo(L, luaO_pushvfstring(L, fmt, argp));
 169.638 +  va_end(argp);
 169.639 +  luaG_errormsg(L);
 169.640 +}
 169.641 +
   170.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   170.2 +++ b/src/lua/src/ldebug.h	Sat Mar 03 10:31:27 2012 -0600
   170.3 @@ -0,0 +1,33 @@
   170.4 +/*
   170.5 +** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $
   170.6 +** Auxiliary functions from Debug Interface module
   170.7 +** See Copyright Notice in lua.h
   170.8 +*/
   170.9 +
  170.10 +#ifndef ldebug_h
  170.11 +#define ldebug_h
  170.12 +
  170.13 +
  170.14 +#include "lstate.h"
  170.15 +
  170.16 +
  170.17 +#define pcRel(pc, p)	(cast(int, (pc) - (p)->code) - 1)
  170.18 +
  170.19 +#define getline(f,pc)	(((f)->lineinfo) ? (f)->lineinfo[pc] : 0)
  170.20 +
  170.21 +#define resethookcount(L)	(L->hookcount = L->basehookcount)
  170.22 +
  170.23 +
  170.24 +LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o,
  170.25 +                                             const char *opname);
  170.26 +LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
  170.27 +LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1,
  170.28 +                                              const TValue *p2);
  170.29 +LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1,
  170.30 +                                             const TValue *p2);
  170.31 +LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...);
  170.32 +LUAI_FUNC void luaG_errormsg (lua_State *L);
  170.33 +LUAI_FUNC int luaG_checkcode (const Proto *pt);
  170.34 +LUAI_FUNC int luaG_checkopenop (Instruction i);
  170.35 +
  170.36 +#endif
   171.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   171.2 +++ b/src/lua/src/ldo.c	Sat Mar 03 10:31:27 2012 -0600
   171.3 @@ -0,0 +1,518 @@
   171.4 +/*
   171.5 +** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $
   171.6 +** Stack and Call structure of Lua
   171.7 +** See Copyright Notice in lua.h
   171.8 +*/
   171.9 +
  171.10 +
  171.11 +#include <setjmp.h>
  171.12 +#include <stdlib.h>
  171.13 +#include <string.h>
  171.14 +
  171.15 +#define ldo_c
  171.16 +#define LUA_CORE
  171.17 +
  171.18 +#include "lua.h"
  171.19 +
  171.20 +#include "ldebug.h"
  171.21 +#include "ldo.h"
  171.22 +#include "lfunc.h"
  171.23 +#include "lgc.h"
  171.24 +#include "lmem.h"
  171.25 +#include "lobject.h"
  171.26 +#include "lopcodes.h"
  171.27 +#include "lparser.h"
  171.28 +#include "lstate.h"
  171.29 +#include "lstring.h"
  171.30 +#include "ltable.h"
  171.31 +#include "ltm.h"
  171.32 +#include "lundump.h"
  171.33 +#include "lvm.h"
  171.34 +#include "lzio.h"
  171.35 +
  171.36 +
  171.37 +
  171.38 +
  171.39 +/*
  171.40 +** {======================================================
  171.41 +** Error-recovery functions
  171.42 +** =======================================================
  171.43 +*/
  171.44 +
  171.45 +
  171.46 +/* chain list of long jump buffers */
  171.47 +struct lua_longjmp {
  171.48 +  struct lua_longjmp *previous;
  171.49 +  luai_jmpbuf b;
  171.50 +  volatile int status;  /* error code */
  171.51 +};
  171.52 +
  171.53 +
  171.54 +void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {
  171.55 +  switch (errcode) {
  171.56 +    case LUA_ERRMEM: {
  171.57 +      setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG));
  171.58 +      break;
  171.59 +    }
  171.60 +    case LUA_ERRERR: {
  171.61 +      setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling"));
  171.62 +      break;
  171.63 +    }
  171.64 +    case LUA_ERRSYNTAX:
  171.65 +    case LUA_ERRRUN: {
  171.66 +      setobjs2s(L, oldtop, L->top - 1);  /* error message on current top */
  171.67 +      break;
  171.68 +    }
  171.69 +  }
  171.70 +  L->top = oldtop + 1;
  171.71 +}
  171.72 +
  171.73 +
  171.74 +static void restore_stack_limit (lua_State *L) {
  171.75 +  lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);
  171.76 +  if (L->size_ci > LUAI_MAXCALLS) {  /* there was an overflow? */
  171.77 +    int inuse = cast_int(L->ci - L->base_ci);
  171.78 +    if (inuse + 1 < LUAI_MAXCALLS)  /* can `undo' overflow? */
  171.79 +      luaD_reallocCI(L, LUAI_MAXCALLS);
  171.80 +  }
  171.81 +}
  171.82 +
  171.83 +
  171.84 +static void resetstack (lua_State *L, int status) {
  171.85 +  L->ci = L->base_ci;
  171.86 +  L->base = L->ci->base;
  171.87 +  luaF_close(L, L->base);  /* close eventual pending closures */
  171.88 +  luaD_seterrorobj(L, status, L->base);
  171.89 +  L->nCcalls = L->baseCcalls;
  171.90 +  L->allowhook = 1;
  171.91 +  restore_stack_limit(L);
  171.92 +  L->errfunc = 0;
  171.93 +  L->errorJmp = NULL;
  171.94 +}
  171.95 +
  171.96 +
  171.97 +void luaD_throw (lua_State *L, int errcode) {
  171.98 +  if (L->errorJmp) {
  171.99 +    L->errorJmp->status = errcode;
 171.100 +    LUAI_THROW(L, L->errorJmp);
 171.101 +  }
 171.102 +  else {
 171.103 +    L->status = cast_byte(errcode);
 171.104 +    if (G(L)->panic) {
 171.105 +      resetstack(L, errcode);
 171.106 +      lua_unlock(L);
 171.107 +      G(L)->panic(L);
 171.108 +    }
 171.109 +    exit(EXIT_FAILURE);
 171.110 +  }
 171.111 +}
 171.112 +
 171.113 +
 171.114 +int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
 171.115 +  struct lua_longjmp lj;
 171.116 +  lj.status = 0;
 171.117 +  lj.previous = L->errorJmp;  /* chain new error handler */
 171.118 +  L->errorJmp = &lj;
 171.119 +  LUAI_TRY(L, &lj,
 171.120 +    (*f)(L, ud);
 171.121 +  );
 171.122 +  L->errorJmp = lj.previous;  /* restore old error handler */
 171.123 +  return lj.status;
 171.124 +}
 171.125 +
 171.126 +/* }====================================================== */
 171.127 +
 171.128 +
 171.129 +static void correctstack (lua_State *L, TValue *oldstack) {
 171.130 +  CallInfo *ci;
 171.131 +  GCObject *up;
 171.132 +  L->top = (L->top - oldstack) + L->stack;
 171.133 +  for (up = L->openupval; up != NULL; up = up->gch.next)
 171.134 +    gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack;
 171.135 +  for (ci = L->base_ci; ci <= L->ci; ci++) {
 171.136 +    ci->top = (ci->top - oldstack) + L->stack;
 171.137 +    ci->base = (ci->base - oldstack) + L->stack;
 171.138 +    ci->func = (ci->func - oldstack) + L->stack;
 171.139 +  }
 171.140 +  L->base = (L->base - oldstack) + L->stack;
 171.141 +}
 171.142 +
 171.143 +
 171.144 +void luaD_reallocstack (lua_State *L, int newsize) {
 171.145 +  TValue *oldstack = L->stack;
 171.146 +  int realsize = newsize + 1 + EXTRA_STACK;
 171.147 +  lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);
 171.148 +  luaM_reallocvector(L, L->stack, L->stacksize, realsize, TValue);
 171.149 +  L->stacksize = realsize;
 171.150 +  L->stack_last = L->stack+newsize;
 171.151 +  correctstack(L, oldstack);
 171.152 +}
 171.153 +
 171.154 +
 171.155 +void luaD_reallocCI (lua_State *L, int newsize) {
 171.156 +  CallInfo *oldci = L->base_ci;
 171.157 +  luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo);
 171.158 +  L->size_ci = newsize;
 171.159 +  L->ci = (L->ci - oldci) + L->base_ci;
 171.160 +  L->end_ci = L->base_ci + L->size_ci - 1;
 171.161 +}
 171.162 +
 171.163 +
 171.164 +void luaD_growstack (lua_State *L, int n) {
 171.165 +  if (n <= L->stacksize)  /* double size is enough? */
 171.166 +    luaD_reallocstack(L, 2*L->stacksize);
 171.167 +  else
 171.168 +    luaD_reallocstack(L, L->stacksize + n);
 171.169 +}
 171.170 +
 171.171 +
 171.172 +static CallInfo *growCI (lua_State *L) {
 171.173 +  if (L->size_ci > LUAI_MAXCALLS)  /* overflow while handling overflow? */
 171.174 +    luaD_throw(L, LUA_ERRERR);
 171.175 +  else {
 171.176 +    luaD_reallocCI(L, 2*L->size_ci);
 171.177 +    if (L->size_ci > LUAI_MAXCALLS)
 171.178 +      luaG_runerror(L, "stack overflow");
 171.179 +  }
 171.180 +  return ++L->ci;
 171.181 +}
 171.182 +
 171.183 +
 171.184 +void luaD_callhook (lua_State *L, int event, int line) {
 171.185 +  lua_Hook hook = L->hook;
 171.186 +  if (hook && L->allowhook) {
 171.187 +    ptrdiff_t top = savestack(L, L->top);
 171.188 +    ptrdiff_t ci_top = savestack(L, L->ci->top);
 171.189 +    lua_Debug ar;
 171.190 +    ar.event = event;
 171.191 +    ar.currentline = line;
 171.192 +    if (event == LUA_HOOKTAILRET)
 171.193 +      ar.i_ci = 0;  /* tail call; no debug information about it */
 171.194 +    else
 171.195 +      ar.i_ci = cast_int(L->ci - L->base_ci);
 171.196 +    luaD_checkstack(L, LUA_MINSTACK);  /* ensure minimum stack size */
 171.197 +    L->ci->top = L->top + LUA_MINSTACK;
 171.198 +    lua_assert(L->ci->top <= L->stack_last);
 171.199 +    L->allowhook = 0;  /* cannot call hooks inside a hook */
 171.200 +    lua_unlock(L);
 171.201 +    (*hook)(L, &ar);
 171.202 +    lua_lock(L);
 171.203 +    lua_assert(!L->allowhook);
 171.204 +    L->allowhook = 1;
 171.205 +    L->ci->top = restorestack(L, ci_top);
 171.206 +    L->top = restorestack(L, top);
 171.207 +  }
 171.208 +}
 171.209 +
 171.210 +
 171.211 +static StkId adjust_varargs (lua_State *L, Proto *p, int actual) {
 171.212 +  int i;
 171.213 +  int nfixargs = p->numparams;
 171.214 +  Table *htab = NULL;
 171.215 +  StkId base, fixed;
 171.216 +  for (; actual < nfixargs; ++actual)
 171.217 +    setnilvalue(L->top++);
 171.218 +#if defined(LUA_COMPAT_VARARG)
 171.219 +  if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */
 171.220 +    int nvar = actual - nfixargs;  /* number of extra arguments */
 171.221 +    lua_assert(p->is_vararg & VARARG_HASARG);
 171.222 +    luaC_checkGC(L);
 171.223 +    htab = luaH_new(L, nvar, 1);  /* create `arg' table */
 171.224 +    for (i=0; i<nvar; i++)  /* put extra arguments into `arg' table */
 171.225 +      setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i);
 171.226 +    /* store counter in field `n' */
 171.227 +    setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar));
 171.228 +  }
 171.229 +#endif
 171.230 +  /* move fixed parameters to final position */
 171.231 +  fixed = L->top - actual;  /* first fixed argument */
 171.232 +  base = L->top;  /* final position of first argument */
 171.233 +  for (i=0; i<nfixargs; i++) {
 171.234 +    setobjs2s(L, L->top++, fixed+i);
 171.235 +    setnilvalue(fixed+i);
 171.236 +  }
 171.237 +  /* add `arg' parameter */
 171.238 +  if (htab) {
 171.239 +    sethvalue(L, L->top++, htab);
 171.240 +    lua_assert(iswhite(obj2gco(htab)));
 171.241 +  }
 171.242 +  return base;
 171.243 +}
 171.244 +
 171.245 +
 171.246 +static StkId tryfuncTM (lua_State *L, StkId func) {
 171.247 +  const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL);
 171.248 +  StkId p;
 171.249 +  ptrdiff_t funcr = savestack(L, func);
 171.250 +  if (!ttisfunction(tm))
 171.251 +    luaG_typeerror(L, func, "call");
 171.252 +  /* Open a hole inside the stack at `func' */
 171.253 +  for (p = L->top; p > func; p--) setobjs2s(L, p, p-1);
 171.254 +  incr_top(L);
 171.255 +  func = restorestack(L, funcr);  /* previous call may change stack */
 171.256 +  setobj2s(L, func, tm);  /* tag method is the new function to be called */
 171.257 +  return func;
 171.258 +}
 171.259 +
 171.260 +
 171.261 +
 171.262 +#define inc_ci(L) \
 171.263 +  ((L->ci == L->end_ci) ? growCI(L) : \
 171.264 +   (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci))
 171.265 +
 171.266 +
 171.267 +int luaD_precall (lua_State *L, StkId func, int nresults) {
 171.268 +  LClosure *cl;
 171.269 +  ptrdiff_t funcr;
 171.270 +  if (!ttisfunction(func)) /* `func' is not a function? */
 171.271 +    func = tryfuncTM(L, func);  /* check the `function' tag method */
 171.272 +  funcr = savestack(L, func);
 171.273 +  cl = &clvalue(func)->l;
 171.274 +  L->ci->savedpc = L->savedpc;
 171.275 +  if (!cl->isC) {  /* Lua function? prepare its call */
 171.276 +    CallInfo *ci;
 171.277 +    StkId st, base;
 171.278 +    Proto *p = cl->p;
 171.279 +    luaD_checkstack(L, p->maxstacksize);
 171.280 +    func = restorestack(L, funcr);
 171.281 +    if (!p->is_vararg) {  /* no varargs? */
 171.282 +      base = func + 1;
 171.283 +      if (L->top > base + p->numparams)
 171.284 +        L->top = base + p->numparams;
 171.285 +    }
 171.286 +    else {  /* vararg function */
 171.287 +      int nargs = cast_int(L->top - func) - 1;
 171.288 +      base = adjust_varargs(L, p, nargs);
 171.289 +      func = restorestack(L, funcr);  /* previous call may change the stack */
 171.290 +    }
 171.291 +    ci = inc_ci(L);  /* now `enter' new function */
 171.292 +    ci->func = func;
 171.293 +    L->base = ci->base = base;
 171.294 +    ci->top = L->base + p->maxstacksize;
 171.295 +    lua_assert(ci->top <= L->stack_last);
 171.296 +    L->savedpc = p->code;  /* starting point */
 171.297 +    ci->tailcalls = 0;
 171.298 +    ci->nresults = nresults;
 171.299 +    for (st = L->top; st < ci->top; st++)
 171.300 +      setnilvalue(st);
 171.301 +    L->top = ci->top;
 171.302 +    if (L->hookmask & LUA_MASKCALL) {
 171.303 +      L->savedpc++;  /* hooks assume 'pc' is already incremented */
 171.304 +      luaD_callhook(L, LUA_HOOKCALL, -1);
 171.305 +      L->savedpc--;  /* correct 'pc' */
 171.306 +    }
 171.307 +    return PCRLUA;
 171.308 +  }
 171.309 +  else {  /* if is a C function, call it */
 171.310 +    CallInfo *ci;
 171.311 +    int n;
 171.312 +    luaD_checkstack(L, LUA_MINSTACK);  /* ensure minimum stack size */
 171.313 +    ci = inc_ci(L);  /* now `enter' new function */
 171.314 +    ci->func = restorestack(L, funcr);
 171.315 +    L->base = ci->base = ci->func + 1;
 171.316 +    ci->top = L->top + LUA_MINSTACK;
 171.317 +    lua_assert(ci->top <= L->stack_last);
 171.318 +    ci->nresults = nresults;
 171.319 +    if (L->hookmask & LUA_MASKCALL)
 171.320 +      luaD_callhook(L, LUA_HOOKCALL, -1);
 171.321 +    lua_unlock(L);
 171.322 +    n = (*curr_func(L)->c.f)(L);  /* do the actual call */
 171.323 +    lua_lock(L);
 171.324 +    if (n < 0)  /* yielding? */
 171.325 +      return PCRYIELD;
 171.326 +    else {
 171.327 +      luaD_poscall(L, L->top - n);
 171.328 +      return PCRC;
 171.329 +    }
 171.330 +  }
 171.331 +}
 171.332 +
 171.333 +
 171.334 +static StkId callrethooks (lua_State *L, StkId firstResult) {
 171.335 +  ptrdiff_t fr = savestack(L, firstResult);  /* next call may change stack */
 171.336 +  luaD_callhook(L, LUA_HOOKRET, -1);
 171.337 +  if (f_isLua(L->ci)) {  /* Lua function? */
 171.338 +    while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */
 171.339 +      luaD_callhook(L, LUA_HOOKTAILRET, -1);
 171.340 +  }
 171.341 +  return restorestack(L, fr);
 171.342 +}
 171.343 +
 171.344 +
 171.345 +int luaD_poscall (lua_State *L, StkId firstResult) {
 171.346 +  StkId res;
 171.347 +  int wanted, i;
 171.348 +  CallInfo *ci;
 171.349 +  if (L->hookmask & LUA_MASKRET)
 171.350 +    firstResult = callrethooks(L, firstResult);
 171.351 +  ci = L->ci--;
 171.352 +  res = ci->func;  /* res == final position of 1st result */
 171.353 +  wanted = ci->nresults;
 171.354 +  L->base = (ci - 1)->base;  /* restore base */
 171.355 +  L->savedpc = (ci - 1)->savedpc;  /* restore savedpc */
 171.356 +  /* move results to correct place */
 171.357 +  for (i = wanted; i != 0 && firstResult < L->top; i--)
 171.358 +    setobjs2s(L, res++, firstResult++);
 171.359 +  while (i-- > 0)
 171.360 +    setnilvalue(res++);
 171.361 +  L->top = res;
 171.362 +  return (wanted - LUA_MULTRET);  /* 0 iff wanted == LUA_MULTRET */
 171.363 +}
 171.364 +
 171.365 +
 171.366 +/*
 171.367 +** Call a function (C or Lua). The function to be called is at *func.
 171.368 +** The arguments are on the stack, right after the function.
 171.369 +** When returns, all the results are on the stack, starting at the original
 171.370 +** function position.
 171.371 +*/ 
 171.372 +void luaD_call (lua_State *L, StkId func, int nResults) {
 171.373 +  if (++L->nCcalls >= LUAI_MAXCCALLS) {
 171.374 +    if (L->nCcalls == LUAI_MAXCCALLS)
 171.375 +      luaG_runerror(L, "C stack overflow");
 171.376 +    else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))
 171.377 +      luaD_throw(L, LUA_ERRERR);  /* error while handing stack error */
 171.378 +  }
 171.379 +  if (luaD_precall(L, func, nResults) == PCRLUA)  /* is a Lua function? */
 171.380 +    luaV_execute(L, 1);  /* call it */
 171.381 +  L->nCcalls--;
 171.382 +  luaC_checkGC(L);
 171.383 +}
 171.384 +
 171.385 +
 171.386 +static void resume (lua_State *L, void *ud) {
 171.387 +  StkId firstArg = cast(StkId, ud);
 171.388 +  CallInfo *ci = L->ci;
 171.389 +  if (L->status == 0) {  /* start coroutine? */
 171.390 +    lua_assert(ci == L->base_ci && firstArg > L->base);
 171.391 +    if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA)
 171.392 +      return;
 171.393 +  }
 171.394 +  else {  /* resuming from previous yield */
 171.395 +    lua_assert(L->status == LUA_YIELD);
 171.396 +    L->status = 0;
 171.397 +    if (!f_isLua(ci)) {  /* `common' yield? */
 171.398 +      /* finish interrupted execution of `OP_CALL' */
 171.399 +      lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL ||
 171.400 +                 GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL);
 171.401 +      if (luaD_poscall(L, firstArg))  /* complete it... */
 171.402 +        L->top = L->ci->top;  /* and correct top if not multiple results */
 171.403 +    }
 171.404 +    else  /* yielded inside a hook: just continue its execution */
 171.405 +      L->base = L->ci->base;
 171.406 +  }
 171.407 +  luaV_execute(L, cast_int(L->ci - L->base_ci));
 171.408 +}
 171.409 +
 171.410 +
 171.411 +static int resume_error (lua_State *L, const char *msg) {
 171.412 +  L->top = L->ci->base;
 171.413 +  setsvalue2s(L, L->top, luaS_new(L, msg));
 171.414 +  incr_top(L);
 171.415 +  lua_unlock(L);
 171.416 +  return LUA_ERRRUN;
 171.417 +}
 171.418 +
 171.419 +
 171.420 +LUA_API int lua_resume (lua_State *L, int nargs) {
 171.421 +  int status;
 171.422 +  lua_lock(L);
 171.423 +  if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci))
 171.424 +      return resume_error(L, "cannot resume non-suspended coroutine");
 171.425 +  if (L->nCcalls >= LUAI_MAXCCALLS)
 171.426 +    return resume_error(L, "C stack overflow");
 171.427 +  luai_userstateresume(L, nargs);
 171.428 +  lua_assert(L->errfunc == 0);
 171.429 +  L->baseCcalls = ++L->nCcalls;
 171.430 +  status = luaD_rawrunprotected(L, resume, L->top - nargs);
 171.431 +  if (status != 0) {  /* error? */
 171.432 +    L->status = cast_byte(status);  /* mark thread as `dead' */
 171.433 +    luaD_seterrorobj(L, status, L->top);
 171.434 +    L->ci->top = L->top;
 171.435 +  }
 171.436 +  else {
 171.437 +    lua_assert(L->nCcalls == L->baseCcalls);
 171.438 +    status = L->status;
 171.439 +  }
 171.440 +  --L->nCcalls;
 171.441 +  lua_unlock(L);
 171.442 +  return status;
 171.443 +}
 171.444 +
 171.445 +
 171.446 +LUA_API int lua_yield (lua_State *L, int nresults) {
 171.447 +  luai_userstateyield(L, nresults);
 171.448 +  lua_lock(L);
 171.449 +  if (L->nCcalls > L->baseCcalls)
 171.450 +    luaG_runerror(L, "attempt to yield across metamethod/C-call boundary");
 171.451 +  L->base = L->top - nresults;  /* protect stack slots below */
 171.452 +  L->status = LUA_YIELD;
 171.453 +  lua_unlock(L);
 171.454 +  return -1;
 171.455 +}
 171.456 +
 171.457 +
 171.458 +int luaD_pcall (lua_State *L, Pfunc func, void *u,
 171.459 +                ptrdiff_t old_top, ptrdiff_t ef) {
 171.460 +  int status;
 171.461 +  unsigned short oldnCcalls = L->nCcalls;
 171.462 +  ptrdiff_t old_ci = saveci(L, L->ci);
 171.463 +  lu_byte old_allowhooks = L->allowhook;
 171.464 +  ptrdiff_t old_errfunc = L->errfunc;
 171.465 +  L->errfunc = ef;
 171.466 +  status = luaD_rawrunprotected(L, func, u);
 171.467 +  if (status != 0) {  /* an error occurred? */
 171.468 +    StkId oldtop = restorestack(L, old_top);
 171.469 +    luaF_close(L, oldtop);  /* close eventual pending closures */
 171.470 +    luaD_seterrorobj(L, status, oldtop);
 171.471 +    L->nCcalls = oldnCcalls;
 171.472 +    L->ci = restoreci(L, old_ci);
 171.473 +    L->base = L->ci->base;
 171.474 +    L->savedpc = L->ci->savedpc;
 171.475 +    L->allowhook = old_allowhooks;
 171.476 +    restore_stack_limit(L);
 171.477 +  }
 171.478 +  L->errfunc = old_errfunc;
 171.479 +  return status;
 171.480 +}
 171.481 +
 171.482 +
 171.483 +
 171.484 +/*
 171.485 +** Execute a protected parser.
 171.486 +*/
 171.487 +struct SParser {  /* data to `f_parser' */
 171.488 +  ZIO *z;
 171.489 +  Mbuffer buff;  /* buffer to be used by the scanner */
 171.490 +  const char *name;
 171.491 +};
 171.492 +
 171.493 +static void f_parser (lua_State *L, void *ud) {
 171.494 +  int i;
 171.495 +  Proto *tf;
 171.496 +  Closure *cl;
 171.497 +  struct SParser *p = cast(struct SParser *, ud);
 171.498 +  int c = luaZ_lookahead(p->z);
 171.499 +  luaC_checkGC(L);
 171.500 +  tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z,
 171.501 +                                                             &p->buff, p->name);
 171.502 +  cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L)));
 171.503 +  cl->l.p = tf;
 171.504 +  for (i = 0; i < tf->nups; i++)  /* initialize eventual upvalues */
 171.505 +    cl->l.upvals[i] = luaF_newupval(L);
 171.506 +  setclvalue(L, L->top, cl);
 171.507 +  incr_top(L);
 171.508 +}
 171.509 +
 171.510 +
 171.511 +int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) {
 171.512 +  struct SParser p;
 171.513 +  int status;
 171.514 +  p.z = z; p.name = name;
 171.515 +  luaZ_initbuffer(L, &p.buff);
 171.516 +  status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);
 171.517 +  luaZ_freebuffer(L, &p.buff);
 171.518 +  return status;
 171.519 +}
 171.520 +
 171.521 +
   172.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   172.2 +++ b/src/lua/src/ldo.h	Sat Mar 03 10:31:27 2012 -0600
   172.3 @@ -0,0 +1,57 @@
   172.4 +/*
   172.5 +** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $
   172.6 +** Stack and Call structure of Lua
   172.7 +** See Copyright Notice in lua.h
   172.8 +*/
   172.9 +
  172.10 +#ifndef ldo_h
  172.11 +#define ldo_h
  172.12 +
  172.13 +
  172.14 +#include "lobject.h"
  172.15 +#include "lstate.h"
  172.16 +#include "lzio.h"
  172.17 +
  172.18 +
  172.19 +#define luaD_checkstack(L,n)	\
  172.20 +  if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \
  172.21 +    luaD_growstack(L, n); \
  172.22 +  else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1));
  172.23 +
  172.24 +
  172.25 +#define incr_top(L) {luaD_checkstack(L,1); L->top++;}
  172.26 +
  172.27 +#define savestack(L,p)		((char *)(p) - (char *)L->stack)
  172.28 +#define restorestack(L,n)	((TValue *)((char *)L->stack + (n)))
  172.29 +
  172.30 +#define saveci(L,p)		((char *)(p) - (char *)L->base_ci)
  172.31 +#define restoreci(L,n)		((CallInfo *)((char *)L->base_ci + (n)))
  172.32 +
  172.33 +
  172.34 +/* results from luaD_precall */
  172.35 +#define PCRLUA		0	/* initiated a call to a Lua function */
  172.36 +#define PCRC		1	/* did a call to a C function */
  172.37 +#define PCRYIELD	2	/* C funtion yielded */
  172.38 +
  172.39 +
  172.40 +/* type of protected functions, to be ran by `runprotected' */
  172.41 +typedef void (*Pfunc) (lua_State *L, void *ud);
  172.42 +
  172.43 +LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name);
  172.44 +LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line);
  172.45 +LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults);
  172.46 +LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
  172.47 +LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
  172.48 +                                        ptrdiff_t oldtop, ptrdiff_t ef);
  172.49 +LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult);
  172.50 +LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize);
  172.51 +LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);
  172.52 +LUAI_FUNC void luaD_growstack (lua_State *L, int n);
  172.53 +
  172.54 +LUAI_FUNC void luaD_throw (lua_State *L, int errcode);
  172.55 +LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
  172.56 +
  172.57 +LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
  172.58 +
  172.59 +#endif
  172.60 +
   173.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   173.2 +++ b/src/lua/src/ldump.c	Sat Mar 03 10:31:27 2012 -0600
   173.3 @@ -0,0 +1,164 @@
   173.4 +/*
   173.5 +** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
   173.6 +** save precompiled Lua chunks
   173.7 +** See Copyright Notice in lua.h
   173.8 +*/
   173.9 +
  173.10 +#include <stddef.h>
  173.11 +
  173.12 +#define ldump_c
  173.13 +#define LUA_CORE
  173.14 +
  173.15 +#include "lua.h"
  173.16 +
  173.17 +#include "lobject.h"
  173.18 +#include "lstate.h"
  173.19 +#include "lundump.h"
  173.20 +
  173.21 +typedef struct {
  173.22 + lua_State* L;
  173.23 + lua_Writer writer;
  173.24 + void* data;
  173.25 + int strip;
  173.26 + int status;
  173.27 +} DumpState;
  173.28 +
  173.29 +#define DumpMem(b,n,size,D)	DumpBlock(b,(n)*(size),D)
  173.30 +#define DumpVar(x,D)	 	DumpMem(&x,1,sizeof(x),D)
  173.31 +
  173.32 +static void DumpBlock(const void* b, size_t size, DumpState* D)
  173.33 +{
  173.34 + if (D->status==0)
  173.35 + {
  173.36 +  lua_unlock(D->L);
  173.37 +  D->status=(*D->writer)(D->L,b,size,D->data);
  173.38 +  lua_lock(D->L);
  173.39 + }
  173.40 +}
  173.41 +
  173.42 +static void DumpChar(int y, DumpState* D)
  173.43 +{
  173.44 + char x=(char)y;
  173.45 + DumpVar(x,D);
  173.46 +}
  173.47 +
  173.48 +static void DumpInt(int x, DumpState* D)
  173.49 +{
  173.50 + DumpVar(x,D);
  173.51 +}
  173.52 +
  173.53 +static void DumpNumber(lua_Number x, DumpState* D)
  173.54 +{
  173.55 + DumpVar(x,D);
  173.56 +}
  173.57 +
  173.58 +static void DumpVector(const void* b, int n, size_t size, DumpState* D)
  173.59 +{
  173.60 + DumpInt(n,D);
  173.61 + DumpMem(b,n,size,D);
  173.62 +}
  173.63 +
  173.64 +static void DumpString(const TString* s, DumpState* D)
  173.65 +{
  173.66 + if (s==NULL || getstr(s)==NULL)
  173.67 + {
  173.68 +  size_t size=0;
  173.69 +  DumpVar(size,D);
  173.70 + }
  173.71 + else
  173.72 + {
  173.73 +  size_t size=s->tsv.len+1;		/* include trailing '\0' */
  173.74 +  DumpVar(size,D);
  173.75 +  DumpBlock(getstr(s),size,D);
  173.76 + }
  173.77 +}
  173.78 +
  173.79 +#define DumpCode(f,D)	 DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
  173.80 +
  173.81 +static void DumpFunction(const Proto* f, const TString* p, DumpState* D);
  173.82 +
  173.83 +static void DumpConstants(const Proto* f, DumpState* D)
  173.84 +{
  173.85 + int i,n=f->sizek;
  173.86 + DumpInt(n,D);
  173.87 + for (i=0; i<n; i++)
  173.88 + {
  173.89 +  const TValue* o=&f->k[i];
  173.90 +  DumpChar(ttype(o),D);
  173.91 +  switch (ttype(o))
  173.92 +  {
  173.93 +   case LUA_TNIL:
  173.94 +	break;
  173.95 +   case LUA_TBOOLEAN:
  173.96 +	DumpChar(bvalue(o),D);
  173.97 +	break;
  173.98 +   case LUA_TNUMBER:
  173.99 +	DumpNumber(nvalue(o),D);
 173.100 +	break;
 173.101 +   case LUA_TSTRING:
 173.102 +	DumpString(rawtsvalue(o),D);
 173.103 +	break;
 173.104 +   default:
 173.105 +	lua_assert(0);			/* cannot happen */
 173.106 +	break;
 173.107 +  }
 173.108 + }
 173.109 + n=f->sizep;
 173.110 + DumpInt(n,D);
 173.111 + for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D);
 173.112 +}
 173.113 +
 173.114 +static void DumpDebug(const Proto* f, DumpState* D)
 173.115 +{
 173.116 + int i,n;
 173.117 + n= (D->strip) ? 0 : f->sizelineinfo;
 173.118 + DumpVector(f->lineinfo,n,sizeof(int),D);
 173.119 + n= (D->strip) ? 0 : f->sizelocvars;
 173.120 + DumpInt(n,D);
 173.121 + for (i=0; i<n; i++)
 173.122 + {
 173.123 +  DumpString(f->locvars[i].varname,D);
 173.124 +  DumpInt(f->locvars[i].startpc,D);
 173.125 +  DumpInt(f->locvars[i].endpc,D);
 173.126 + }
 173.127 + n= (D->strip) ? 0 : f->sizeupvalues;
 173.128 + DumpInt(n,D);
 173.129 + for (i=0; i<n; i++) DumpString(f->upvalues[i],D);
 173.130 +}
 173.131 +
 173.132 +static void DumpFunction(const Proto* f, const TString* p, DumpState* D)
 173.133 +{
 173.134 + DumpString((f->source==p || D->strip) ? NULL : f->source,D);
 173.135 + DumpInt(f->linedefined,D);
 173.136 + DumpInt(f->lastlinedefined,D);
 173.137 + DumpChar(f->nups,D);
 173.138 + DumpChar(f->numparams,D);
 173.139 + DumpChar(f->is_vararg,D);
 173.140 + DumpChar(f->maxstacksize,D);
 173.141 + DumpCode(f,D);
 173.142 + DumpConstants(f,D);
 173.143 + DumpDebug(f,D);
 173.144 +}
 173.145 +
 173.146 +static void DumpHeader(DumpState* D)
 173.147 +{
 173.148 + char h[LUAC_HEADERSIZE];
 173.149 + luaU_header(h);
 173.150 + DumpBlock(h,LUAC_HEADERSIZE,D);
 173.151 +}
 173.152 +
 173.153 +/*
 173.154 +** dump Lua function as precompiled chunk
 173.155 +*/
 173.156 +int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip)
 173.157 +{
 173.158 + DumpState D;
 173.159 + D.L=L;
 173.160 + D.writer=w;
 173.161 + D.data=data;
 173.162 + D.strip=strip;
 173.163 + D.status=0;
 173.164 + DumpHeader(&D);
 173.165 + DumpFunction(f,NULL,&D);
 173.166 + return D.status;
 173.167 +}
   174.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   174.2 +++ b/src/lua/src/lfunc.c	Sat Mar 03 10:31:27 2012 -0600
   174.3 @@ -0,0 +1,174 @@
   174.4 +/*
   174.5 +** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $
   174.6 +** Auxiliary functions to manipulate prototypes and closures
   174.7 +** See Copyright Notice in lua.h
   174.8 +*/
   174.9 +
  174.10 +
  174.11 +#include <stddef.h>
  174.12 +
  174.13 +#define lfunc_c
  174.14 +#define LUA_CORE
  174.15 +
  174.16 +#include "lua.h"
  174.17 +
  174.18 +#include "lfunc.h"
  174.19 +#include "lgc.h"
  174.20 +#include "lmem.h"
  174.21 +#include "lobject.h"
  174.22 +#include "lstate.h"
  174.23 +
  174.24 +
  174.25 +
  174.26 +Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) {
  174.27 +  Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems)));
  174.28 +  luaC_link(L, obj2gco(c), LUA_TFUNCTION);
  174.29 +  c->c.isC = 1;
  174.30 +  c->c.env = e;
  174.31 +  c->c.nupvalues = cast_byte(nelems);
  174.32 +  return c;
  174.33 +}
  174.34 +
  174.35 +
  174.36 +Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) {
  174.37 +  Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems)));
  174.38 +  luaC_link(L, obj2gco(c), LUA_TFUNCTION);
  174.39 +  c->l.isC = 0;
  174.40 +  c->l.env = e;
  174.41 +  c->l.nupvalues = cast_byte(nelems);
  174.42 +  while (nelems--) c->l.upvals[nelems] = NULL;
  174.43 +  return c;
  174.44 +}
  174.45 +
  174.46 +
  174.47 +UpVal *luaF_newupval (lua_State *L) {
  174.48 +  UpVal *uv = luaM_new(L, UpVal);
  174.49 +  luaC_link(L, obj2gco(uv), LUA_TUPVAL);
  174.50 +  uv->v = &uv->u.value;
  174.51 +  setnilvalue(uv->v);
  174.52 +  return uv;
  174.53 +}
  174.54 +
  174.55 +
  174.56 +UpVal *luaF_findupval (lua_State *L, StkId level) {
  174.57 +  global_State *g = G(L);
  174.58 +  GCObject **pp = &L->openupval;
  174.59 +  UpVal *p;
  174.60 +  UpVal *uv;
  174.61 +  while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) {
  174.62 +    lua_assert(p->v != &p->u.value);
  174.63 +    if (p->v == level) {  /* found a corresponding upvalue? */
  174.64 +      if (isdead(g, obj2gco(p)))  /* is it dead? */
  174.65 +        changewhite(obj2gco(p));  /* ressurect it */
  174.66 +      return p;
  174.67 +    }
  174.68 +    pp = &p->next;
  174.69 +  }
  174.70 +  uv = luaM_new(L, UpVal);  /* not found: create a new one */
  174.71 +  uv->tt = LUA_TUPVAL;
  174.72 +  uv->marked = luaC_white(g);
  174.73 +  uv->v = level;  /* current value lives in the stack */
  174.74 +  uv->next = *pp;  /* chain it in the proper position */
  174.75 +  *pp = obj2gco(uv);
  174.76 +  uv->u.l.prev = &g->uvhead;  /* double link it in `uvhead' list */
  174.77 +  uv->u.l.next = g->uvhead.u.l.next;
  174.78 +  uv->u.l.next->u.l.prev = uv;
  174.79 +  g->uvhead.u.l.next = uv;
  174.80 +  lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
  174.81 +  return uv;
  174.82 +}
  174.83 +
  174.84 +
  174.85 +static void unlinkupval (UpVal *uv) {
  174.86 +  lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
  174.87 +  uv->u.l.next->u.l.prev = uv->u.l.prev;  /* remove from `uvhead' list */
  174.88 +  uv->u.l.prev->u.l.next = uv->u.l.next;
  174.89 +}
  174.90 +
  174.91 +
  174.92 +void luaF_freeupval (lua_State *L, UpVal *uv) {
  174.93 +  if (uv->v != &uv->u.value)  /* is it open? */
  174.94 +    unlinkupval(uv);  /* remove from open list */
  174.95 +  luaM_free(L, uv);  /* free upvalue */
  174.96 +}
  174.97 +
  174.98 +
  174.99 +void luaF_close (lua_State *L, StkId level) {
 174.100 +  UpVal *uv;
 174.101 +  global_State *g = G(L);
 174.102 +  while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) {
 174.103 +    GCObject *o = obj2gco(uv);
 174.104 +    lua_assert(!isblack(o) && uv->v != &uv->u.value);
 174.105 +    L->openupval = uv->next;  /* remove from `open' list */
 174.106 +    if (isdead(g, o))
 174.107 +      luaF_freeupval(L, uv);  /* free upvalue */
 174.108 +    else {
 174.109 +      unlinkupval(uv);
 174.110 +      setobj(L, &uv->u.value, uv->v);
 174.111 +      uv->v = &uv->u.value;  /* now current value lives here */
 174.112 +      luaC_linkupval(L, uv);  /* link upvalue into `gcroot' list */
 174.113 +    }
 174.114 +  }
 174.115 +}
 174.116 +
 174.117 +
 174.118 +Proto *luaF_newproto (lua_State *L) {
 174.119 +  Proto *f = luaM_new(L, Proto);
 174.120 +  luaC_link(L, obj2gco(f), LUA_TPROTO);
 174.121 +  f->k = NULL;
 174.122 +  f->sizek = 0;
 174.123 +  f->p = NULL;
 174.124 +  f->sizep = 0;
 174.125 +  f->code = NULL;
 174.126 +  f->sizecode = 0;
 174.127 +  f->sizelineinfo = 0;
 174.128 +  f->sizeupvalues = 0;
 174.129 +  f->nups = 0;
 174.130 +  f->upvalues = NULL;
 174.131 +  f->numparams = 0;
 174.132 +  f->is_vararg = 0;
 174.133 +  f->maxstacksize = 0;
 174.134 +  f->lineinfo = NULL;
 174.135 +  f->sizelocvars = 0;
 174.136 +  f->locvars = NULL;
 174.137 +  f->linedefined = 0;
 174.138 +  f->lastlinedefined = 0;
 174.139 +  f->source = NULL;
 174.140 +  return f;
 174.141 +}
 174.142 +
 174.143 +
 174.144 +void luaF_freeproto (lua_State *L, Proto *f) {
 174.145 +  luaM_freearray(L, f->code, f->sizecode, Instruction);
 174.146 +  luaM_freearray(L, f->p, f->sizep, Proto *);
 174.147 +  luaM_freearray(L, f->k, f->sizek, TValue);
 174.148 +  luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
 174.149 +  luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
 174.150 +  luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
 174.151 +  luaM_free(L, f);
 174.152 +}
 174.153 +
 174.154 +
 174.155 +void luaF_freeclosure (lua_State *L, Closure *c) {
 174.156 +  int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) :
 174.157 +                          sizeLclosure(c->l.nupvalues);
 174.158 +  luaM_freemem(L, c, size);
 174.159 +}
 174.160 +
 174.161 +
 174.162 +/*
 174.163 +** Look for n-th local variable at line `line' in function `func'.
 174.164 +** Returns NULL if not found.
 174.165 +*/
 174.166 +const char *luaF_getlocalname (const Proto *f, int local_number, int pc) {
 174.167 +  int i;
 174.168 +  for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {
 174.169 +    if (pc < f->locvars[i].endpc) {  /* is variable active? */
 174.170 +      local_number--;
 174.171 +      if (local_number == 0)
 174.172 +        return getstr(f->locvars[i].varname);
 174.173 +    }
 174.174 +  }
 174.175 +  return NULL;  /* not found */
 174.176 +}
 174.177 +
   175.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   175.2 +++ b/src/lua/src/lfunc.h	Sat Mar 03 10:31:27 2012 -0600
   175.3 @@ -0,0 +1,34 @@
   175.4 +/*
   175.5 +** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $
   175.6 +** Auxiliary functions to manipulate prototypes and closures
   175.7 +** See Copyright Notice in lua.h
   175.8 +*/
   175.9 +
  175.10 +#ifndef lfunc_h
  175.11 +#define lfunc_h
  175.12 +
  175.13 +
  175.14 +#include "lobject.h"
  175.15 +
  175.16 +
  175.17 +#define sizeCclosure(n)	(cast(int, sizeof(CClosure)) + \
  175.18 +                         cast(int, sizeof(TValue)*((n)-1)))
  175.19 +
  175.20 +#define sizeLclosure(n)	(cast(int, sizeof(LClosure)) + \
  175.21 +                         cast(int, sizeof(TValue *)*((n)-1)))
  175.22 +
  175.23 +
  175.24 +LUAI_FUNC Proto *luaF_newproto (lua_State *L);
  175.25 +LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e);
  175.26 +LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e);
  175.27 +LUAI_FUNC UpVal *luaF_newupval (lua_State *L);
  175.28 +LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
  175.29 +LUAI_FUNC void luaF_close (lua_State *L, StkId level);
  175.30 +LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
  175.31 +LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c);
  175.32 +LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv);
  175.33 +LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
  175.34 +                                         int pc);
  175.35 +
  175.36 +
  175.37 +#endif
   176.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   176.2 +++ b/src/lua/src/lgc.c	Sat Mar 03 10:31:27 2012 -0600
   176.3 @@ -0,0 +1,711 @@
   176.4 +/*
   176.5 +** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $
   176.6 +** Garbage Collector
   176.7 +** See Copyright Notice in lua.h
   176.8 +*/
   176.9 +
  176.10 +#include <string.h>
  176.11 +
  176.12 +#define lgc_c
  176.13 +#define LUA_CORE
  176.14 +
  176.15 +#include "lua.h"
  176.16 +
  176.17 +#include "ldebug.h"
  176.18 +#include "ldo.h"
  176.19 +#include "lfunc.h"
  176.20 +#include "lgc.h"
  176.21 +#include "lmem.h"
  176.22 +#include "lobject.h"
  176.23 +#include "lstate.h"
  176.24 +#include "lstring.h"
  176.25 +#include "ltable.h"
  176.26 +#include "ltm.h"
  176.27 +
  176.28 +
  176.29 +#define GCSTEPSIZE	1024u
  176.30 +#define GCSWEEPMAX	40
  176.31 +#define GCSWEEPCOST	10
  176.32 +#define GCFINALIZECOST	100
  176.33 +
  176.34 +
  176.35 +#define maskmarks	cast_byte(~(bitmask(BLACKBIT)|WHITEBITS))
  176.36 +
  176.37 +#define makewhite(g,x)	\
  176.38 +   ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g)))
  176.39 +
  176.40 +#define white2gray(x)	reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
  176.41 +#define black2gray(x)	resetbit((x)->gch.marked, BLACKBIT)
  176.42 +
  176.43 +#define stringmark(s)	reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT)
  176.44 +
  176.45 +
  176.46 +#define isfinalized(u)		testbit((u)->marked, FINALIZEDBIT)
  176.47 +#define markfinalized(u)	l_setbit((u)->marked, FINALIZEDBIT)
  176.48 +
  176.49 +
  176.50 +#define KEYWEAK         bitmask(KEYWEAKBIT)
  176.51 +#define VALUEWEAK       bitmask(VALUEWEAKBIT)
  176.52 +
  176.53 +
  176.54 +
  176.55 +#define markvalue(g,o) { checkconsistency(o); \
  176.56 +  if (iscollectable(o) && iswhite(gcvalue(o))) reallymarkobject(g,gcvalue(o)); }
  176.57 +
  176.58 +#define markobject(g,t) { if (iswhite(obj2gco(t))) \
  176.59 +		reallymarkobject(g, obj2gco(t)); }
  176.60 +
  176.61 +
  176.62 +#define setthreshold(g)  (g->GCthreshold = (g->estimate/100) * g->gcpause)
  176.63 +
  176.64 +
  176.65 +static void removeentry (Node *n) {
  176.66 +  lua_assert(ttisnil(gval(n)));
  176.67 +  if (iscollectable(gkey(n)))
  176.68 +    setttype(gkey(n), LUA_TDEADKEY);  /* dead key; remove it */
  176.69 +}
  176.70 +
  176.71 +
  176.72 +static void reallymarkobject (global_State *g, GCObject *o) {
  176.73 +  lua_assert(iswhite(o) && !isdead(g, o));
  176.74 +  white2gray(o);
  176.75 +  switch (o->gch.tt) {
  176.76 +    case LUA_TSTRING: {
  176.77 +      return;
  176.78 +    }
  176.79 +    case LUA_TUSERDATA: {
  176.80 +      Table *mt = gco2u(o)->metatable;
  176.81 +      gray2black(o);  /* udata are never gray */
  176.82 +      if (mt) markobject(g, mt);
  176.83 +      markobject(g, gco2u(o)->env);
  176.84 +      return;
  176.85 +    }
  176.86 +    case LUA_TUPVAL: {
  176.87 +      UpVal *uv = gco2uv(o);
  176.88 +      markvalue(g, uv->v);
  176.89 +      if (uv->v == &uv->u.value)  /* closed? */
  176.90 +        gray2black(o);  /* open upvalues are never black */
  176.91 +      return;
  176.92 +    }
  176.93 +    case LUA_TFUNCTION: {
  176.94 +      gco2cl(o)->c.gclist = g->gray;
  176.95 +      g->gray = o;
  176.96 +      break;
  176.97 +    }
  176.98 +    case LUA_TTABLE: {
  176.99 +      gco2h(o)->gclist = g->gray;
 176.100 +      g->gray = o;
 176.101 +      break;
 176.102 +    }
 176.103 +    case LUA_TTHREAD: {
 176.104 +      gco2th(o)->gclist = g->gray;
 176.105 +      g->gray = o;
 176.106 +      break;
 176.107 +    }
 176.108 +    case LUA_TPROTO: {
 176.109 +      gco2p(o)->gclist = g->gray;
 176.110 +      g->gray = o;
 176.111 +      break;
 176.112 +    }
 176.113 +    default: lua_assert(0);
 176.114 +  }
 176.115 +}
 176.116 +
 176.117 +
 176.118 +static void marktmu (global_State *g) {
 176.119 +  GCObject *u = g->tmudata;
 176.120 +  if (u) {
 176.121 +    do {
 176.122 +      u = u->gch.next;
 176.123 +      makewhite(g, u);  /* may be marked, if left from previous GC */
 176.124 +      reallymarkobject(g, u);
 176.125 +    } while (u != g->tmudata);
 176.126 +  }
 176.127 +}
 176.128 +
 176.129 +
 176.130 +/* move `dead' udata that need finalization to list `tmudata' */
 176.131 +size_t luaC_separateudata (lua_State *L, int all) {
 176.132 +  global_State *g = G(L);
 176.133 +  size_t deadmem = 0;
 176.134 +  GCObject **p = &g->mainthread->next;
 176.135 +  GCObject *curr;
 176.136 +  while ((curr = *p) != NULL) {
 176.137 +    if (!(iswhite(curr) || all) || isfinalized(gco2u(curr)))
 176.138 +      p = &curr->gch.next;  /* don't bother with them */
 176.139 +    else if (fasttm(L, gco2u(curr)->metatable, TM_GC) == NULL) {
 176.140 +      markfinalized(gco2u(curr));  /* don't need finalization */
 176.141 +      p = &curr->gch.next;
 176.142 +    }
 176.143 +    else {  /* must call its gc method */
 176.144 +      deadmem += sizeudata(gco2u(curr));
 176.145 +      markfinalized(gco2u(curr));
 176.146 +      *p = curr->gch.next;
 176.147 +      /* link `curr' at the end of `tmudata' list */
 176.148 +      if (g->tmudata == NULL)  /* list is empty? */
 176.149 +        g->tmudata = curr->gch.next = curr;  /* creates a circular list */
 176.150 +      else {
 176.151 +        curr->gch.next = g->tmudata->gch.next;
 176.152 +        g->tmudata->gch.next = curr;
 176.153 +        g->tmudata = curr;
 176.154 +      }
 176.155 +    }
 176.156 +  }
 176.157 +  return deadmem;
 176.158 +}
 176.159 +
 176.160 +
 176.161 +static int traversetable (global_State *g, Table *h) {
 176.162 +  int i;
 176.163 +  int weakkey = 0;
 176.164 +  int weakvalue = 0;
 176.165 +  const TValue *mode;
 176.166 +  if (h->metatable)
 176.167 +    markobject(g, h->metatable);
 176.168 +  mode = gfasttm(g, h->metatable, TM_MODE);
 176.169 +  if (mode && ttisstring(mode)) {  /* is there a weak mode? */
 176.170 +    weakkey = (strchr(svalue(mode), 'k') != NULL);
 176.171 +    weakvalue = (strchr(svalue(mode), 'v') != NULL);
 176.172 +    if (weakkey || weakvalue) {  /* is really weak? */
 176.173 +      h->marked &= ~(KEYWEAK | VALUEWEAK);  /* clear bits */
 176.174 +      h->marked |= cast_byte((weakkey << KEYWEAKBIT) |
 176.175 +                             (weakvalue << VALUEWEAKBIT));
 176.176 +      h->gclist = g->weak;  /* must be cleared after GC, ... */
 176.177 +      g->weak = obj2gco(h);  /* ... so put in the appropriate list */
 176.178 +    }
 176.179 +  }
 176.180 +  if (weakkey && weakvalue) return 1;
 176.181 +  if (!weakvalue) {
 176.182 +    i = h->sizearray;
 176.183 +    while (i--)
 176.184 +      markvalue(g, &h->array[i]);
 176.185 +  }
 176.186 +  i = sizenode(h);
 176.187 +  while (i--) {
 176.188 +    Node *n = gnode(h, i);
 176.189 +    lua_assert(ttype(gkey(n)) != LUA_TDEADKEY || ttisnil(gval(n)));
 176.190 +    if (ttisnil(gval(n)))
 176.191 +      removeentry(n);  /* remove empty entries */
 176.192 +    else {
 176.193 +      lua_assert(!ttisnil(gkey(n)));
 176.194 +      if (!weakkey) markvalue(g, gkey(n));
 176.195 +      if (!weakvalue) markvalue(g, gval(n));
 176.196 +    }
 176.197 +  }
 176.198 +  return weakkey || weakvalue;
 176.199 +}
 176.200 +
 176.201 +
 176.202 +/*
 176.203 +** All marks are conditional because a GC may happen while the
 176.204 +** prototype is still being created
 176.205 +*/
 176.206 +static void traverseproto (global_State *g, Proto *f) {
 176.207 +  int i;
 176.208 +  if (f->source) stringmark(f->source);
 176.209 +  for (i=0; i<f->sizek; i++)  /* mark literals */
 176.210 +    markvalue(g, &f->k[i]);
 176.211 +  for (i=0; i<f->sizeupvalues; i++) {  /* mark upvalue names */
 176.212 +    if (f->upvalues[i])
 176.213 +      stringmark(f->upvalues[i]);
 176.214 +  }
 176.215 +  for (i=0; i<f->sizep; i++) {  /* mark nested protos */
 176.216 +    if (f->p[i])
 176.217 +      markobject(g, f->p[i]);
 176.218 +  }
 176.219 +  for (i=0; i<f->sizelocvars; i++) {  /* mark local-variable names */
 176.220 +    if (f->locvars[i].varname)
 176.221 +      stringmark(f->locvars[i].varname);
 176.222 +  }
 176.223 +}
 176.224 +
 176.225 +
 176.226 +
 176.227 +static void traverseclosure (global_State *g, Closure *cl) {
 176.228 +  markobject(g, cl->c.env);
 176.229 +  if (cl->c.isC) {
 176.230 +    int i;
 176.231 +    for (i=0; i<cl->c.nupvalues; i++)  /* mark its upvalues */
 176.232 +      markvalue(g, &cl->c.upvalue[i]);
 176.233 +  }
 176.234 +  else {
 176.235 +    int i;
 176.236 +    lua_assert(cl->l.nupvalues == cl->l.p->nups);
 176.237 +    markobject(g, cl->l.p);
 176.238 +    for (i=0; i<cl->l.nupvalues; i++)  /* mark its upvalues */
 176.239 +      markobject(g, cl->l.upvals[i]);
 176.240 +  }
 176.241 +}
 176.242 +
 176.243 +
 176.244 +static void checkstacksizes (lua_State *L, StkId max) {
 176.245 +  int ci_used = cast_int(L->ci - L->base_ci);  /* number of `ci' in use */
 176.246 +  int s_used = cast_int(max - L->stack);  /* part of stack in use */
 176.247 +  if (L->size_ci > LUAI_MAXCALLS)  /* handling overflow? */
 176.248 +    return;  /* do not touch the stacks */
 176.249 +  if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)
 176.250 +    luaD_reallocCI(L, L->size_ci/2);  /* still big enough... */
 176.251 +  condhardstacktests(luaD_reallocCI(L, ci_used + 1));
 176.252 +  if (4*s_used < L->stacksize &&
 176.253 +      2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize)
 176.254 +    luaD_reallocstack(L, L->stacksize/2);  /* still big enough... */
 176.255 +  condhardstacktests(luaD_reallocstack(L, s_used));
 176.256 +}
 176.257 +
 176.258 +
 176.259 +static void traversestack (global_State *g, lua_State *l) {
 176.260 +  StkId o, lim;
 176.261 +  CallInfo *ci;
 176.262 +  markvalue(g, gt(l));
 176.263 +  lim = l->top;
 176.264 +  for (ci = l->base_ci; ci <= l->ci; ci++) {
 176.265 +    lua_assert(ci->top <= l->stack_last);
 176.266 +    if (lim < ci->top) lim = ci->top;
 176.267 +  }
 176.268 +  for (o = l->stack; o < l->top; o++)
 176.269 +    markvalue(g, o);
 176.270 +  for (; o <= lim; o++)
 176.271 +    setnilvalue(o);
 176.272 +  checkstacksizes(l, lim);
 176.273 +}
 176.274 +
 176.275 +
 176.276 +/*
 176.277 +** traverse one gray object, turning it to black.
 176.278 +** Returns `quantity' traversed.
 176.279 +*/
 176.280 +static l_mem propagatemark (global_State *g) {
 176.281 +  GCObject *o = g->gray;
 176.282 +  lua_assert(isgray(o));
 176.283 +  gray2black(o);
 176.284 +  switch (o->gch.tt) {
 176.285 +    case LUA_TTABLE: {
 176.286 +      Table *h = gco2h(o);
 176.287 +      g->gray = h->gclist;
 176.288 +      if (traversetable(g, h))  /* table is weak? */
 176.289 +        black2gray(o);  /* keep it gray */
 176.290 +      return sizeof(Table) + sizeof(TValue) * h->sizearray +
 176.291 +                             sizeof(Node) * sizenode(h);
 176.292 +    }
 176.293 +    case LUA_TFUNCTION: {
 176.294 +      Closure *cl = gco2cl(o);
 176.295 +      g->gray = cl->c.gclist;
 176.296 +      traverseclosure(g, cl);
 176.297 +      return (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) :
 176.298 +                           sizeLclosure(cl->l.nupvalues);
 176.299 +    }
 176.300 +    case LUA_TTHREAD: {
 176.301 +      lua_State *th = gco2th(o);
 176.302 +      g->gray = th->gclist;
 176.303 +      th->gclist = g->grayagain;
 176.304 +      g->grayagain = o;
 176.305 +      black2gray(o);
 176.306 +      traversestack(g, th);
 176.307 +      return sizeof(lua_State) + sizeof(TValue) * th->stacksize +
 176.308 +                                 sizeof(CallInfo) * th->size_ci;
 176.309 +    }
 176.310 +    case LUA_TPROTO: {
 176.311 +      Proto *p = gco2p(o);
 176.312 +      g->gray = p->gclist;
 176.313 +      traverseproto(g, p);
 176.314 +      return sizeof(Proto) + sizeof(Instruction) * p->sizecode +
 176.315 +                             sizeof(Proto *) * p->sizep +
 176.316 +                             sizeof(TValue) * p->sizek + 
 176.317 +                             sizeof(int) * p->sizelineinfo +
 176.318 +                             sizeof(LocVar) * p->sizelocvars +
 176.319 +                             sizeof(TString *) * p->sizeupvalues;
 176.320 +    }
 176.321 +    default: lua_assert(0); return 0;
 176.322 +  }
 176.323 +}
 176.324 +
 176.325 +
 176.326 +static size_t propagateall (global_State *g) {
 176.327 +  size_t m = 0;
 176.328 +  while (g->gray) m += propagatemark(g);
 176.329 +  return m;
 176.330 +}
 176.331 +
 176.332 +
 176.333 +/*
 176.334 +** The next function tells whether a key or value can be cleared from
 176.335 +** a weak table. Non-collectable objects are never removed from weak
 176.336 +** tables. Strings behave as `values', so are never removed too. for
 176.337 +** other objects: if really collected, cannot keep them; for userdata
 176.338 +** being finalized, keep them in keys, but not in values
 176.339 +*/
 176.340 +static int iscleared (const TValue *o, int iskey) {
 176.341 +  if (!iscollectable(o)) return 0;
 176.342 +  if (ttisstring(o)) {
 176.343 +    stringmark(rawtsvalue(o));  /* strings are `values', so are never weak */
 176.344 +    return 0;
 176.345 +  }
 176.346 +  return iswhite(gcvalue(o)) ||
 176.347 +    (ttisuserdata(o) && (!iskey && isfinalized(uvalue(o))));
 176.348 +}
 176.349 +
 176.350 +
 176.351 +/*
 176.352 +** clear collected entries from weaktables
 176.353 +*/
 176.354 +static void cleartable (GCObject *l) {
 176.355 +  while (l) {
 176.356 +    Table *h = gco2h(l);
 176.357 +    int i = h->sizearray;
 176.358 +    lua_assert(testbit(h->marked, VALUEWEAKBIT) ||
 176.359 +               testbit(h->marked, KEYWEAKBIT));
 176.360 +    if (testbit(h->marked, VALUEWEAKBIT)) {
 176.361 +      while (i--) {
 176.362 +        TValue *o = &h->array[i];
 176.363 +        if (iscleared(o, 0))  /* value was collected? */
 176.364 +          setnilvalue(o);  /* remove value */
 176.365 +      }
 176.366 +    }
 176.367 +    i = sizenode(h);
 176.368 +    while (i--) {
 176.369 +      Node *n = gnode(h, i);
 176.370 +      if (!ttisnil(gval(n)) &&  /* non-empty entry? */
 176.371 +          (iscleared(key2tval(n), 1) || iscleared(gval(n), 0))) {
 176.372 +        setnilvalue(gval(n));  /* remove value ... */
 176.373 +        removeentry(n);  /* remove entry from table */
 176.374 +      }
 176.375 +    }
 176.376 +    l = h->gclist;
 176.377 +  }
 176.378 +}
 176.379 +
 176.380 +
 176.381 +static void freeobj (lua_State *L, GCObject *o) {
 176.382 +  switch (o->gch.tt) {
 176.383 +    case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;
 176.384 +    case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break;
 176.385 +    case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break;
 176.386 +    case LUA_TTABLE: luaH_free(L, gco2h(o)); break;
 176.387 +    case LUA_TTHREAD: {
 176.388 +      lua_assert(gco2th(o) != L && gco2th(o) != G(L)->mainthread);
 176.389 +      luaE_freethread(L, gco2th(o));
 176.390 +      break;
 176.391 +    }
 176.392 +    case LUA_TSTRING: {
 176.393 +      G(L)->strt.nuse--;
 176.394 +      luaM_freemem(L, o, sizestring(gco2ts(o)));
 176.395 +      break;
 176.396 +    }
 176.397 +    case LUA_TUSERDATA: {
 176.398 +      luaM_freemem(L, o, sizeudata(gco2u(o)));
 176.399 +      break;
 176.400 +    }
 176.401 +    default: lua_assert(0);
 176.402 +  }
 176.403 +}
 176.404 +
 176.405 +
 176.406 +
 176.407 +#define sweepwholelist(L,p)	sweeplist(L,p,MAX_LUMEM)
 176.408 +
 176.409 +
 176.410 +static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {
 176.411 +  GCObject *curr;
 176.412 +  global_State *g = G(L);
 176.413 +  int deadmask = otherwhite(g);
 176.414 +  while ((curr = *p) != NULL && count-- > 0) {
 176.415 +    if (curr->gch.tt == LUA_TTHREAD)  /* sweep open upvalues of each thread */
 176.416 +      sweepwholelist(L, &gco2th(curr)->openupval);
 176.417 +    if ((curr->gch.marked ^ WHITEBITS) & deadmask) {  /* not dead? */
 176.418 +      lua_assert(!isdead(g, curr) || testbit(curr->gch.marked, FIXEDBIT));
 176.419 +      makewhite(g, curr);  /* make it white (for next cycle) */
 176.420 +      p = &curr->gch.next;
 176.421 +    }
 176.422 +    else {  /* must erase `curr' */
 176.423 +      lua_assert(isdead(g, curr) || deadmask == bitmask(SFIXEDBIT));
 176.424 +      *p = curr->gch.next;
 176.425 +      if (curr == g->rootgc)  /* is the first element of the list? */
 176.426 +        g->rootgc = curr->gch.next;  /* adjust first */
 176.427 +      freeobj(L, curr);
 176.428 +    }
 176.429 +  }
 176.430 +  return p;
 176.431 +}
 176.432 +
 176.433 +
 176.434 +static void checkSizes (lua_State *L) {
 176.435 +  global_State *g = G(L);
 176.436 +  /* check size of string hash */
 176.437 +  if (g->strt.nuse < cast(lu_int32, g->strt.size/4) &&
 176.438 +      g->strt.size > MINSTRTABSIZE*2)
 176.439 +    luaS_resize(L, g->strt.size/2);  /* table is too big */
 176.440 +  /* check size of buffer */
 176.441 +  if (luaZ_sizebuffer(&g->buff) > LUA_MINBUFFER*2) {  /* buffer too big? */
 176.442 +    size_t newsize = luaZ_sizebuffer(&g->buff) / 2;
 176.443 +    luaZ_resizebuffer(L, &g->buff, newsize);
 176.444 +  }
 176.445 +}
 176.446 +
 176.447 +
 176.448 +static void GCTM (lua_State *L) {
 176.449 +  global_State *g = G(L);
 176.450 +  GCObject *o = g->tmudata->gch.next;  /* get first element */
 176.451 +  Udata *udata = rawgco2u(o);
 176.452 +  const TValue *tm;
 176.453 +  /* remove udata from `tmudata' */
 176.454 +  if (o == g->tmudata)  /* last element? */
 176.455 +    g->tmudata = NULL;
 176.456 +  else
 176.457 +    g->tmudata->gch.next = udata->uv.next;
 176.458 +  udata->uv.next = g->mainthread->next;  /* return it to `root' list */
 176.459 +  g->mainthread->next = o;
 176.460 +  makewhite(g, o);
 176.461 +  tm = fasttm(L, udata->uv.metatable, TM_GC);
 176.462 +  if (tm != NULL) {
 176.463 +    lu_byte oldah = L->allowhook;
 176.464 +    lu_mem oldt = g->GCthreshold;
 176.465 +    L->allowhook = 0;  /* stop debug hooks during GC tag method */
 176.466 +    g->GCthreshold = 2*g->totalbytes;  /* avoid GC steps */
 176.467 +    setobj2s(L, L->top, tm);
 176.468 +    setuvalue(L, L->top+1, udata);
 176.469 +    L->top += 2;
 176.470 +    luaD_call(L, L->top - 2, 0);
 176.471 +    L->allowhook = oldah;  /* restore hooks */
 176.472 +    g->GCthreshold = oldt;  /* restore threshold */
 176.473 +  }
 176.474 +}
 176.475 +
 176.476 +
 176.477 +/*
 176.478 +** Call all GC tag methods
 176.479 +*/
 176.480 +void luaC_callGCTM (lua_State *L) {
 176.481 +  while (G(L)->tmudata)
 176.482 +    GCTM(L);
 176.483 +}
 176.484 +
 176.485 +
 176.486 +void luaC_freeall (lua_State *L) {
 176.487 +  global_State *g = G(L);
 176.488 +  int i;
 176.489 +  g->currentwhite = WHITEBITS | bitmask(SFIXEDBIT);  /* mask to collect all elements */
 176.490 +  sweepwholelist(L, &g->rootgc);
 176.491 +  for (i = 0; i < g->strt.size; i++)  /* free all string lists */
 176.492 +    sweepwholelist(L, &g->strt.hash[i]);
 176.493 +}
 176.494 +
 176.495 +
 176.496 +static void markmt (global_State *g) {
 176.497 +  int i;
 176.498 +  for (i=0; i<NUM_TAGS; i++)
 176.499 +    if (g->mt[i]) markobject(g, g->mt[i]);
 176.500 +}
 176.501 +
 176.502 +
 176.503 +/* mark root set */
 176.504 +static void markroot (lua_State *L) {
 176.505 +  global_State *g = G(L);
 176.506 +  g->gray = NULL;
 176.507 +  g->grayagain = NULL;
 176.508 +  g->weak = NULL;
 176.509 +  markobject(g, g->mainthread);
 176.510 +  /* make global table be traversed before main stack */
 176.511 +  markvalue(g, gt(g->mainthread));
 176.512 +  markvalue(g, registry(L));
 176.513 +  markmt(g);
 176.514 +  g->gcstate = GCSpropagate;
 176.515 +}
 176.516 +
 176.517 +
 176.518 +static void remarkupvals (global_State *g) {
 176.519 +  UpVal *uv;
 176.520 +  for (uv = g->uvhead.u.l.next; uv != &g->uvhead; uv = uv->u.l.next) {
 176.521 +    lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
 176.522 +    if (isgray(obj2gco(uv)))
 176.523 +      markvalue(g, uv->v);
 176.524 +  }
 176.525 +}
 176.526 +
 176.527 +
 176.528 +static void atomic (lua_State *L) {
 176.529 +  global_State *g = G(L);
 176.530 +  size_t udsize;  /* total size of userdata to be finalized */
 176.531 +  /* remark occasional upvalues of (maybe) dead threads */
 176.532 +  remarkupvals(g);
 176.533 +  /* traverse objects cautch by write barrier and by 'remarkupvals' */
 176.534 +  propagateall(g);
 176.535 +  /* remark weak tables */
 176.536 +  g->gray = g->weak;
 176.537 +  g->weak = NULL;
 176.538 +  lua_assert(!iswhite(obj2gco(g->mainthread)));
 176.539 +  markobject(g, L);  /* mark running thread */
 176.540 +  markmt(g);  /* mark basic metatables (again) */
 176.541 +  propagateall(g);
 176.542 +  /* remark gray again */
 176.543 +  g->gray = g->grayagain;
 176.544 +  g->grayagain = NULL;
 176.545 +  propagateall(g);
 176.546 +  udsize = luaC_separateudata(L, 0);  /* separate userdata to be finalized */
 176.547 +  marktmu(g);  /* mark `preserved' userdata */
 176.548 +  udsize += propagateall(g);  /* remark, to propagate `preserveness' */
 176.549 +  cleartable(g->weak);  /* remove collected objects from weak tables */
 176.550 +  /* flip current white */
 176.551 +  g->currentwhite = cast_byte(otherwhite(g));
 176.552 +  g->sweepstrgc = 0;
 176.553 +  g->sweepgc = &g->rootgc;
 176.554 +  g->gcstate = GCSsweepstring;
 176.555 +  g->estimate = g->totalbytes - udsize;  /* first estimate */
 176.556 +}
 176.557 +
 176.558 +
 176.559 +static l_mem singlestep (lua_State *L) {
 176.560 +  global_State *g = G(L);
 176.561 +  /*lua_checkmemory(L);*/
 176.562 +  switch (g->gcstate) {
 176.563 +    case GCSpause: {
 176.564 +      markroot(L);  /* start a new collection */
 176.565 +      return 0;
 176.566 +    }
 176.567 +    case GCSpropagate: {
 176.568 +      if (g->gray)
 176.569 +        return propagatemark(g);
 176.570 +      else {  /* no more `gray' objects */
 176.571 +        atomic(L);  /* finish mark phase */
 176.572 +        return 0;
 176.573 +      }
 176.574 +    }
 176.575 +    case GCSsweepstring: {
 176.576 +      lu_mem old = g->totalbytes;
 176.577 +      sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]);
 176.578 +      if (g->sweepstrgc >= g->strt.size)  /* nothing more to sweep? */
 176.579 +        g->gcstate = GCSsweep;  /* end sweep-string phase */
 176.580 +      lua_assert(old >= g->totalbytes);
 176.581 +      g->estimate -= old - g->totalbytes;
 176.582 +      return GCSWEEPCOST;
 176.583 +    }
 176.584 +    case GCSsweep: {
 176.585 +      lu_mem old = g->totalbytes;
 176.586 +      g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
 176.587 +      if (*g->sweepgc == NULL) {  /* nothing more to sweep? */
 176.588 +        checkSizes(L);
 176.589 +        g->gcstate = GCSfinalize;  /* end sweep phase */
 176.590 +      }
 176.591 +      lua_assert(old >= g->totalbytes);
 176.592 +      g->estimate -= old - g->totalbytes;
 176.593 +      return GCSWEEPMAX*GCSWEEPCOST;
 176.594 +    }
 176.595 +    case GCSfinalize: {
 176.596 +      if (g->tmudata) {
 176.597 +        GCTM(L);
 176.598 +        if (g->estimate > GCFINALIZECOST)
 176.599 +          g->estimate -= GCFINALIZECOST;
 176.600 +        return GCFINALIZECOST;
 176.601 +      }
 176.602 +      else {
 176.603 +        g->gcstate = GCSpause;  /* end collection */
 176.604 +        g->gcdept = 0;
 176.605 +        return 0;
 176.606 +      }
 176.607 +    }
 176.608 +    default: lua_assert(0); return 0;
 176.609 +  }
 176.610 +}
 176.611 +
 176.612 +
 176.613 +void luaC_step (lua_State *L) {
 176.614 +  global_State *g = G(L);
 176.615 +  l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul;
 176.616 +  if (lim == 0)
 176.617 +    lim = (MAX_LUMEM-1)/2;  /* no limit */
 176.618 +  g->gcdept += g->totalbytes - g->GCthreshold;
 176.619 +  do {
 176.620 +    lim -= singlestep(L);
 176.621 +    if (g->gcstate == GCSpause)
 176.622 +      break;
 176.623 +  } while (lim > 0);
 176.624 +  if (g->gcstate != GCSpause) {
 176.625 +    if (g->gcdept < GCSTEPSIZE)
 176.626 +      g->GCthreshold = g->totalbytes + GCSTEPSIZE;  /* - lim/g->gcstepmul;*/
 176.627 +    else {
 176.628 +      g->gcdept -= GCSTEPSIZE;
 176.629 +      g->GCthreshold = g->totalbytes;
 176.630 +    }
 176.631 +  }
 176.632 +  else {
 176.633 +    lua_assert(g->totalbytes >= g->estimate);
 176.634 +    setthreshold(g);
 176.635 +  }
 176.636 +}
 176.637 +
 176.638 +
 176.639 +void luaC_fullgc (lua_State *L) {
 176.640 +  global_State *g = G(L);
 176.641 +  if (g->gcstate <= GCSpropagate) {
 176.642 +    /* reset sweep marks to sweep all elements (returning them to white) */
 176.643 +    g->sweepstrgc = 0;
 176.644 +    g->sweepgc = &g->rootgc;
 176.645 +    /* reset other collector lists */
 176.646 +    g->gray = NULL;
 176.647 +    g->grayagain = NULL;
 176.648 +    g->weak = NULL;
 176.649 +    g->gcstate = GCSsweepstring;
 176.650 +  }
 176.651 +  lua_assert(g->gcstate != GCSpause && g->gcstate != GCSpropagate);
 176.652 +  /* finish any pending sweep phase */
 176.653 +  while (g->gcstate != GCSfinalize) {
 176.654 +    lua_assert(g->gcstate == GCSsweepstring || g->gcstate == GCSsweep);
 176.655 +    singlestep(L);
 176.656 +  }
 176.657 +  markroot(L);
 176.658 +  while (g->gcstate != GCSpause) {
 176.659 +    singlestep(L);
 176.660 +  }
 176.661 +  setthreshold(g);
 176.662 +}
 176.663 +
 176.664 +
 176.665 +void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) {
 176.666 +  global_State *g = G(L);
 176.667 +  lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
 176.668 +  lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);
 176.669 +  lua_assert(ttype(&o->gch) != LUA_TTABLE);
 176.670 +  /* must keep invariant? */
 176.671 +  if (g->gcstate == GCSpropagate)
 176.672 +    reallymarkobject(g, v);  /* restore invariant */
 176.673 +  else  /* don't mind */
 176.674 +    makewhite(g, o);  /* mark as white just to avoid other barriers */
 176.675 +}
 176.676 +
 176.677 +
 176.678 +void luaC_barrierback (lua_State *L, Table *t) {
 176.679 +  global_State *g = G(L);
 176.680 +  GCObject *o = obj2gco(t);
 176.681 +  lua_assert(isblack(o) && !isdead(g, o));
 176.682 +  lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);
 176.683 +  black2gray(o);  /* make table gray (again) */
 176.684 +  t->gclist = g->grayagain;
 176.685 +  g->grayagain = o;
 176.686 +}
 176.687 +
 176.688 +
 176.689 +void luaC_link (lua_State *L, GCObject *o, lu_byte tt) {
 176.690 +  global_State *g = G(L);
 176.691 +  o->gch.next = g->rootgc;
 176.692 +  g->rootgc = o;
 176.693 +  o->gch.marked = luaC_white(g);
 176.694 +  o->gch.tt = tt;
 176.695 +}
 176.696 +
 176.697 +
 176.698 +void luaC_linkupval (lua_State *L, UpVal *uv) {
 176.699 +  global_State *g = G(L);
 176.700 +  GCObject *o = obj2gco(uv);
 176.701 +  o->gch.next = g->rootgc;  /* link upvalue into `rootgc' list */
 176.702 +  g->rootgc = o;
 176.703 +  if (isgray(o)) { 
 176.704 +    if (g->gcstate == GCSpropagate) {
 176.705 +      gray2black(o);  /* closed upvalues need barrier */
 176.706 +      luaC_barrier(L, uv, uv->v);
 176.707 +    }
 176.708 +    else {  /* sweep phase: sweep it (turning it into white) */
 176.709 +      makewhite(g, o);
 176.710 +      lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);
 176.711 +    }
 176.712 +  }
 176.713 +}
 176.714 +
   177.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   177.2 +++ b/src/lua/src/lgc.h	Sat Mar 03 10:31:27 2012 -0600
   177.3 @@ -0,0 +1,110 @@
   177.4 +/*
   177.5 +** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $
   177.6 +** Garbage Collector
   177.7 +** See Copyright Notice in lua.h
   177.8 +*/
   177.9 +
  177.10 +#ifndef lgc_h
  177.11 +#define lgc_h
  177.12 +
  177.13 +
  177.14 +#include "lobject.h"
  177.15 +
  177.16 +
  177.17 +/*
  177.18 +** Possible states of the Garbage Collector
  177.19 +*/
  177.20 +#define GCSpause	0
  177.21 +#define GCSpropagate	1
  177.22 +#define GCSsweepstring	2
  177.23 +#define GCSsweep	3
  177.24 +#define GCSfinalize	4
  177.25 +
  177.26 +
  177.27 +/*
  177.28 +** some userful bit tricks
  177.29 +*/
  177.30 +#define resetbits(x,m)	((x) &= cast(lu_byte, ~(m)))
  177.31 +#define setbits(x,m)	((x) |= (m))
  177.32 +#define testbits(x,m)	((x) & (m))
  177.33 +#define bitmask(b)	(1<<(b))
  177.34 +#define bit2mask(b1,b2)	(bitmask(b1) | bitmask(b2))
  177.35 +#define l_setbit(x,b)	setbits(x, bitmask(b))
  177.36 +#define resetbit(x,b)	resetbits(x, bitmask(b))
  177.37 +#define testbit(x,b)	testbits(x, bitmask(b))
  177.38 +#define set2bits(x,b1,b2)	setbits(x, (bit2mask(b1, b2)))
  177.39 +#define reset2bits(x,b1,b2)	resetbits(x, (bit2mask(b1, b2)))
  177.40 +#define test2bits(x,b1,b2)	testbits(x, (bit2mask(b1, b2)))
  177.41 +
  177.42 +
  177.43 +
  177.44 +/*
  177.45 +** Layout for bit use in `marked' field:
  177.46 +** bit 0 - object is white (type 0)
  177.47 +** bit 1 - object is white (type 1)
  177.48 +** bit 2 - object is black
  177.49 +** bit 3 - for userdata: has been finalized
  177.50 +** bit 3 - for tables: has weak keys
  177.51 +** bit 4 - for tables: has weak values
  177.52 +** bit 5 - object is fixed (should not be collected)
  177.53 +** bit 6 - object is "super" fixed (only the main thread)
  177.54 +*/
  177.55 +
  177.56 +
  177.57 +#define WHITE0BIT	0
  177.58 +#define WHITE1BIT	1
  177.59 +#define BLACKBIT	2
  177.60 +#define FINALIZEDBIT	3
  177.61 +#define KEYWEAKBIT	3
  177.62 +#define VALUEWEAKBIT	4
  177.63 +#define FIXEDBIT	5
  177.64 +#define SFIXEDBIT	6
  177.65 +#define WHITEBITS	bit2mask(WHITE0BIT, WHITE1BIT)
  177.66 +
  177.67 +
  177.68 +#define iswhite(x)      test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
  177.69 +#define isblack(x)      testbit((x)->gch.marked, BLACKBIT)
  177.70 +#define isgray(x)	(!isblack(x) && !iswhite(x))
  177.71 +
  177.72 +#define otherwhite(g)	(g->currentwhite ^ WHITEBITS)
  177.73 +#define isdead(g,v)	((v)->gch.marked & otherwhite(g) & WHITEBITS)
  177.74 +
  177.75 +#define changewhite(x)	((x)->gch.marked ^= WHITEBITS)
  177.76 +#define gray2black(x)	l_setbit((x)->gch.marked, BLACKBIT)
  177.77 +
  177.78 +#define valiswhite(x)	(iscollectable(x) && iswhite(gcvalue(x)))
  177.79 +
  177.80 +#define luaC_white(g)	cast(lu_byte, (g)->currentwhite & WHITEBITS)
  177.81 +
  177.82 +
  177.83 +#define luaC_checkGC(L) { \
  177.84 +  condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \
  177.85 +  if (G(L)->totalbytes >= G(L)->GCthreshold) \
  177.86 +	luaC_step(L); }
  177.87 +
  177.88 +
  177.89 +#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p)))  \
  177.90 +	luaC_barrierf(L,obj2gco(p),gcvalue(v)); }
  177.91 +
  177.92 +#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t)))  \
  177.93 +	luaC_barrierback(L,t); }
  177.94 +
  177.95 +#define luaC_objbarrier(L,p,o)  \
  177.96 +	{ if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
  177.97 +		luaC_barrierf(L,obj2gco(p),obj2gco(o)); }
  177.98 +
  177.99 +#define luaC_objbarriert(L,t,o)  \
 177.100 +   { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }
 177.101 +
 177.102 +LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all);
 177.103 +LUAI_FUNC void luaC_callGCTM (lua_State *L);
 177.104 +LUAI_FUNC void luaC_freeall (lua_State *L);
 177.105 +LUAI_FUNC void luaC_step (lua_State *L);
 177.106 +LUAI_FUNC void luaC_fullgc (lua_State *L);
 177.107 +LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
 177.108 +LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv);
 177.109 +LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v);
 177.110 +LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t);
 177.111 +
 177.112 +
 177.113 +#endif
   178.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   178.2 +++ b/src/lua/src/linit.c	Sat Mar 03 10:31:27 2012 -0600
   178.3 @@ -0,0 +1,38 @@
   178.4 +/*
   178.5 +** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $
   178.6 +** Initialization of libraries for lua.c
   178.7 +** See Copyright Notice in lua.h
   178.8 +*/
   178.9 +
  178.10 +
  178.11 +#define linit_c
  178.12 +#define LUA_LIB
  178.13 +
  178.14 +#include "lua.h"
  178.15 +
  178.16 +#include "lualib.h"
  178.17 +#include "lauxlib.h"
  178.18 +
  178.19 +
  178.20 +static const luaL_Reg lualibs[] = {
  178.21 +  {"", luaopen_base},
  178.22 +  {LUA_LOADLIBNAME, luaopen_package},
  178.23 +  {LUA_TABLIBNAME, luaopen_table},
  178.24 +  {LUA_IOLIBNAME, luaopen_io},
  178.25 +  {LUA_OSLIBNAME, luaopen_os},
  178.26 +  {LUA_STRLIBNAME, luaopen_string},
  178.27 +  {LUA_MATHLIBNAME, luaopen_math},
  178.28 +  {LUA_DBLIBNAME, luaopen_debug},
  178.29 +  {NULL, NULL}
  178.30 +};
  178.31 +
  178.32 +
  178.33 +LUALIB_API void luaL_openlibs (lua_State *L) {
  178.34 +  const luaL_Reg *lib = lualibs;
  178.35 +  for (; lib->func; lib++) {
  178.36 +    lua_pushcfunction(L, lib->func);
  178.37 +    lua_pushstring(L, lib->name);
  178.38 +    lua_call(L, 1, 0);
  178.39 +  }
  178.40 +}
  178.41 +
   179.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   179.2 +++ b/src/lua/src/liolib.c	Sat Mar 03 10:31:27 2012 -0600
   179.3 @@ -0,0 +1,553 @@
   179.4 +/*
   179.5 +** $Id: liolib.c,v 2.73.1.3 2008/01/18 17:47:43 roberto Exp $
   179.6 +** Standard I/O (and system) library
   179.7 +** See Copyright Notice in lua.h
   179.8 +*/
   179.9 +
  179.10 +
  179.11 +#include <errno.h>
  179.12 +#include <stdio.h>
  179.13 +#include <stdlib.h>
  179.14 +#include <string.h>
  179.15 +
  179.16 +#define liolib_c
  179.17 +#define LUA_LIB
  179.18 +
  179.19 +#include "lua.h"
  179.20 +
  179.21 +#include "lauxlib.h"
  179.22 +#include "lualib.h"
  179.23 +
  179.24 +
  179.25 +
  179.26 +#define IO_INPUT	1
  179.27 +#define IO_OUTPUT	2
  179.28 +
  179.29 +
  179.30 +static const char *const fnames[] = {"input", "output"};
  179.31 +
  179.32 +
  179.33 +static int pushresult (lua_State *L, int i, const char *filename) {
  179.34 +  int en = errno;  /* calls to Lua API may change this value */
  179.35 +  if (i) {
  179.36 +    lua_pushboolean(L, 1);
  179.37 +    return 1;
  179.38 +  }
  179.39 +  else {
  179.40 +    lua_pushnil(L);
  179.41 +    if (filename)
  179.42 +      lua_pushfstring(L, "%s: %s", filename, strerror(en));
  179.43 +    else
  179.44 +      lua_pushfstring(L, "%s", strerror(en));
  179.45 +    lua_pushinteger(L, en);
  179.46 +    return 3;
  179.47 +  }
  179.48 +}
  179.49 +
  179.50 +
  179.51 +static void fileerror (lua_State *L, int arg, const char *filename) {
  179.52 +  lua_pushfstring(L, "%s: %s", filename, strerror(errno));
  179.53 +  luaL_argerror(L, arg, lua_tostring(L, -1));
  179.54 +}
  179.55 +
  179.56 +
  179.57 +#define tofilep(L)	((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE))
  179.58 +
  179.59 +
  179.60 +static int io_type (lua_State *L) {
  179.61 +  void *ud;
  179.62 +  luaL_checkany(L, 1);
  179.63 +  ud = lua_touserdata(L, 1);
  179.64 +  lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE);
  179.65 +  if (ud == NULL || !lua_getmetatable(L, 1) || !lua_rawequal(L, -2, -1))
  179.66 +    lua_pushnil(L);  /* not a file */
  179.67 +  else if (*((FILE **)ud) == NULL)
  179.68 +    lua_pushliteral(L, "closed file");
  179.69 +  else
  179.70 +    lua_pushliteral(L, "file");
  179.71 +  return 1;
  179.72 +}
  179.73 +
  179.74 +
  179.75 +static FILE *tofile (lua_State *L) {
  179.76 +  FILE **f = tofilep(L);
  179.77 +  if (*f == NULL)
  179.78 +    luaL_error(L, "attempt to use a closed file");
  179.79 +  return *f;
  179.80 +}
  179.81 +
  179.82 +
  179.83 +
  179.84 +/*
  179.85 +** When creating file handles, always creates a `closed' file handle
  179.86 +** before opening the actual file; so, if there is a memory error, the
  179.87 +** file is not left opened.
  179.88 +*/
  179.89 +static FILE **newfile (lua_State *L) {
  179.90 +  FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *));
  179.91 +  *pf = NULL;  /* file handle is currently `closed' */
  179.92 +  luaL_getmetatable(L, LUA_FILEHANDLE);
  179.93 +  lua_setmetatable(L, -2);
  179.94 +  return pf;
  179.95 +}
  179.96 +
  179.97 +
  179.98 +/*
  179.99 +** function to (not) close the standard files stdin, stdout, and stderr
 179.100 +*/
 179.101 +static int io_noclose (lua_State *L) {
 179.102 +  lua_pushnil(L);
 179.103 +  lua_pushliteral(L, "cannot close standard file");
 179.104 +  return 2;
 179.105 +}
 179.106 +
 179.107 +
 179.108 +/*
 179.109 +** function to close 'popen' files
 179.110 +*/
 179.111 +static int io_pclose (lua_State *L) {
 179.112 +  FILE **p = tofilep(L);
 179.113 +  int ok = lua_pclose(L, *p);
 179.114 +  *p = NULL;
 179.115 +  return pushresult(L, ok, NULL);
 179.116 +}
 179.117 +
 179.118 +
 179.119 +/*
 179.120 +** function to close regular files
 179.121 +*/
 179.122 +static int io_fclose (lua_State *L) {
 179.123 +  FILE **p = tofilep(L);
 179.124 +  int ok = (fclose(*p) == 0);
 179.125 +  *p = NULL;
 179.126 +  return pushresult(L, ok, NULL);
 179.127 +}
 179.128 +
 179.129 +
 179.130 +static int aux_close (lua_State *L) {
 179.131 +  lua_getfenv(L, 1);
 179.132 +  lua_getfield(L, -1, "__close");
 179.133 +  return (lua_tocfunction(L, -1))(L);
 179.134 +}
 179.135 +
 179.136 +
 179.137 +static int io_close (lua_State *L) {
 179.138 +  if (lua_isnone(L, 1))
 179.139 +    lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT);
 179.140 +  tofile(L);  /* make sure argument is a file */
 179.141 +  return aux_close(L);
 179.142 +}
 179.143 +
 179.144 +
 179.145 +static int io_gc (lua_State *L) {
 179.146 +  FILE *f = *tofilep(L);
 179.147 +  /* ignore closed files */
 179.148 +  if (f != NULL)
 179.149 +    aux_close(L);
 179.150 +  return 0;
 179.151 +}
 179.152 +
 179.153 +
 179.154 +static int io_tostring (lua_State *L) {
 179.155 +  FILE *f = *tofilep(L);
 179.156 +  if (f == NULL)
 179.157 +    lua_pushliteral(L, "file (closed)");
 179.158 +  else
 179.159 +    lua_pushfstring(L, "file (%p)", f);
 179.160 +  return 1;
 179.161 +}
 179.162 +
 179.163 +
 179.164 +static int io_open (lua_State *L) {
 179.165 +  const char *filename = luaL_checkstring(L, 1);
 179.166 +  const char *mode = luaL_optstring(L, 2, "r");
 179.167 +  FILE **pf = newfile(L);
 179.168 +  *pf = fopen(filename, mode);
 179.169 +  return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
 179.170 +}
 179.171 +
 179.172 +
 179.173 +/*
 179.174 +** this function has a separated environment, which defines the
 179.175 +** correct __close for 'popen' files
 179.176 +*/
 179.177 +static int io_popen (lua_State *L) {
 179.178 +  const char *filename = luaL_checkstring(L, 1);
 179.179 +  const char *mode = luaL_optstring(L, 2, "r");
 179.180 +  FILE **pf = newfile(L);
 179.181 +  *pf = lua_popen(L, filename, mode);
 179.182 +  return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
 179.183 +}
 179.184 +
 179.185 +
 179.186 +static int io_tmpfile (lua_State *L) {
 179.187 +  FILE **pf = newfile(L);
 179.188 +  *pf = tmpfile();
 179.189 +  return (*pf == NULL) ? pushresult(L, 0, NULL) : 1;
 179.190 +}
 179.191 +
 179.192 +
 179.193 +static FILE *getiofile (lua_State *L, int findex) {
 179.194 +  FILE *f;
 179.195 +  lua_rawgeti(L, LUA_ENVIRONINDEX, findex);
 179.196 +  f = *(FILE **)lua_touserdata(L, -1);
 179.197 +  if (f == NULL)
 179.198 +    luaL_error(L, "standard %s file is closed", fnames[findex - 1]);
 179.199 +  return f;
 179.200 +}
 179.201 +
 179.202 +
 179.203 +static int g_iofile (lua_State *L, int f, const char *mode) {
 179.204 +  if (!lua_isnoneornil(L, 1)) {
 179.205 +    const char *filename = lua_tostring(L, 1);
 179.206 +    if (filename) {
 179.207 +      FILE **pf = newfile(L);
 179.208 +      *pf = fopen(filename, mode);
 179.209 +      if (*pf == NULL)
 179.210 +        fileerror(L, 1, filename);
 179.211 +    }
 179.212 +    else {
 179.213 +      tofile(L);  /* check that it's a valid file handle */
 179.214 +      lua_pushvalue(L, 1);
 179.215 +    }
 179.216 +    lua_rawseti(L, LUA_ENVIRONINDEX, f);
 179.217 +  }
 179.218 +  /* return current value */
 179.219 +  lua_rawgeti(L, LUA_ENVIRONINDEX, f);
 179.220 +  return 1;
 179.221 +}
 179.222 +
 179.223 +
 179.224 +static int io_input (lua_State *L) {
 179.225 +  return g_iofile(L, IO_INPUT, "r");
 179.226 +}
 179.227 +
 179.228 +
 179.229 +static int io_output (lua_State *L) {
 179.230 +  return g_iofile(L, IO_OUTPUT, "w");
 179.231 +}
 179.232 +
 179.233 +
 179.234 +static int io_readline (lua_State *L);
 179.235 +
 179.236 +
 179.237 +static void aux_lines (lua_State *L, int idx, int toclose) {
 179.238 +  lua_pushvalue(L, idx);
 179.239 +  lua_pushboolean(L, toclose);  /* close/not close file when finished */
 179.240 +  lua_pushcclosure(L, io_readline, 2);
 179.241 +}
 179.242 +
 179.243 +
 179.244 +static int f_lines (lua_State *L) {
 179.245 +  tofile(L);  /* check that it's a valid file handle */
 179.246 +  aux_lines(L, 1, 0);
 179.247 +  return 1;
 179.248 +}
 179.249 +
 179.250 +
 179.251 +static int io_lines (lua_State *L) {
 179.252 +  if (lua_isnoneornil(L, 1)) {  /* no arguments? */
 179.253 +    /* will iterate over default input */
 179.254 +    lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT);
 179.255 +    return f_lines(L);
 179.256 +  }
 179.257 +  else {
 179.258 +    const char *filename = luaL_checkstring(L, 1);
 179.259 +    FILE **pf = newfile(L);
 179.260 +    *pf = fopen(filename, "r");
 179.261 +    if (*pf == NULL)
 179.262 +      fileerror(L, 1, filename);
 179.263 +    aux_lines(L, lua_gettop(L), 1);
 179.264 +    return 1;
 179.265 +  }
 179.266 +}
 179.267 +
 179.268 +
 179.269 +/*
 179.270 +** {======================================================
 179.271 +** READ
 179.272 +** =======================================================
 179.273 +*/
 179.274 +
 179.275 +
 179.276 +static int read_number (lua_State *L, FILE *f) {
 179.277 +  lua_Number d;
 179.278 +  if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {
 179.279 +    lua_pushnumber(L, d);
 179.280 +    return 1;
 179.281 +  }
 179.282 +  else return 0;  /* read fails */
 179.283 +}
 179.284 +
 179.285 +
 179.286 +static int test_eof (lua_State *L, FILE *f) {
 179.287 +  int c = getc(f);
 179.288 +  ungetc(c, f);
 179.289 +  lua_pushlstring(L, NULL, 0);
 179.290 +  return (c != EOF);
 179.291 +}
 179.292 +
 179.293 +
 179.294 +static int read_line (lua_State *L, FILE *f) {
 179.295 +  luaL_Buffer b;
 179.296 +  luaL_buffinit(L, &b);
 179.297 +  for (;;) {
 179.298 +    size_t l;
 179.299 +    char *p = luaL_prepbuffer(&b);
 179.300 +    if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) {  /* eof? */
 179.301 +      luaL_pushresult(&b);  /* close buffer */
 179.302 +      return (lua_objlen(L, -1) > 0);  /* check whether read something */
 179.303 +    }
 179.304 +    l = strlen(p);
 179.305 +    if (l == 0 || p[l-1] != '\n')
 179.306 +      luaL_addsize(&b, l);
 179.307 +    else {
 179.308 +      luaL_addsize(&b, l - 1);  /* do not include `eol' */
 179.309 +      luaL_pushresult(&b);  /* close buffer */
 179.310 +      return 1;  /* read at least an `eol' */
 179.311 +    }
 179.312 +  }
 179.313 +}
 179.314 +
 179.315 +
 179.316 +static int read_chars (lua_State *L, FILE *f, size_t n) {
 179.317 +  size_t rlen;  /* how much to read */
 179.318 +  size_t nr;  /* number of chars actually read */
 179.319 +  luaL_Buffer b;
 179.320 +  luaL_buffinit(L, &b);
 179.321 +  rlen = LUAL_BUFFERSIZE;  /* try to read that much each time */
 179.322 +  do {
 179.323 +    char *p = luaL_prepbuffer(&b);
 179.324 +    if (rlen > n) rlen = n;  /* cannot read more than asked */
 179.325 +    nr = fread(p, sizeof(char), rlen, f);
 179.326 +    luaL_addsize(&b, nr);
 179.327 +    n -= nr;  /* still have to read `n' chars */
 179.328 +  } while (n > 0 && nr == rlen);  /* until end of count or eof */
 179.329 +  luaL_pushresult(&b);  /* close buffer */
 179.330 +  return (n == 0 || lua_objlen(L, -1) > 0);
 179.331 +}
 179.332 +
 179.333 +
 179.334 +static int g_read (lua_State *L, FILE *f, int first) {
 179.335 +  int nargs = lua_gettop(L) - 1;
 179.336 +  int success;
 179.337 +  int n;
 179.338 +  clearerr(f);
 179.339 +  if (nargs == 0) {  /* no arguments? */
 179.340 +    success = read_line(L, f);
 179.341 +    n = first+1;  /* to return 1 result */
 179.342 +  }
 179.343 +  else {  /* ensure stack space for all results and for auxlib's buffer */
 179.344 +    luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
 179.345 +    success = 1;
 179.346 +    for (n = first; nargs-- && success; n++) {
 179.347 +      if (lua_type(L, n) == LUA_TNUMBER) {
 179.348 +        size_t l = (size_t)lua_tointeger(L, n);
 179.349 +        success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
 179.350 +      }
 179.351 +      else {
 179.352 +        const char *p = lua_tostring(L, n);
 179.353 +        luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
 179.354 +        switch (p[1]) {
 179.355 +          case 'n':  /* number */
 179.356 +            success = read_number(L, f);
 179.357 +            break;
 179.358 +          case 'l':  /* line */
 179.359 +            success = read_line(L, f);
 179.360 +            break;
 179.361 +          case 'a':  /* file */
 179.362 +            read_chars(L, f, ~((size_t)0));  /* read MAX_SIZE_T chars */
 179.363 +            success = 1; /* always success */
 179.364 +            break;
 179.365 +          default:
 179.366 +            return luaL_argerror(L, n, "invalid format");
 179.367 +        }
 179.368 +      }
 179.369 +    }
 179.370 +  }
 179.371 +  if (ferror(f))
 179.372 +    return pushresult(L, 0, NULL);
 179.373 +  if (!success) {
 179.374 +    lua_pop(L, 1);  /* remove last result */
 179.375 +    lua_pushnil(L);  /* push nil instead */
 179.376 +  }
 179.377 +  return n - first;
 179.378 +}
 179.379 +
 179.380 +
 179.381 +static int io_read (lua_State *L) {
 179.382 +  return g_read(L, getiofile(L, IO_INPUT), 1);
 179.383 +}
 179.384 +
 179.385 +
 179.386 +static int f_read (lua_State *L) {
 179.387 +  return g_read(L, tofile(L), 2);
 179.388 +}
 179.389 +
 179.390 +
 179.391 +static int io_readline (lua_State *L) {
 179.392 +  FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1));
 179.393 +  int sucess;
 179.394 +  if (f == NULL)  /* file is already closed? */
 179.395 +    luaL_error(L, "file is already closed");
 179.396 +  sucess = read_line(L, f);
 179.397 +  if (ferror(f))
 179.398 +    return luaL_error(L, "%s", strerror(errno));
 179.399 +  if (sucess) return 1;
 179.400 +  else {  /* EOF */
 179.401 +    if (lua_toboolean(L, lua_upvalueindex(2))) {  /* generator created file? */
 179.402 +      lua_settop(L, 0);
 179.403 +      lua_pushvalue(L, lua_upvalueindex(1));
 179.404 +      aux_close(L);  /* close it */
 179.405 +    }
 179.406 +    return 0;
 179.407 +  }
 179.408 +}
 179.409 +
 179.410 +/* }====================================================== */
 179.411 +
 179.412 +
 179.413 +static int g_write (lua_State *L, FILE *f, int arg) {
 179.414 +  int nargs = lua_gettop(L) - 1;
 179.415 +  int status = 1;
 179.416 +  for (; nargs--; arg++) {
 179.417 +    if (lua_type(L, arg) == LUA_TNUMBER) {
 179.418 +      /* optimization: could be done exactly as for strings */
 179.419 +      status = status &&
 179.420 +          fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0;
 179.421 +    }
 179.422 +    else {
 179.423 +      size_t l;
 179.424 +      const char *s = luaL_checklstring(L, arg, &l);
 179.425 +      status = status && (fwrite(s, sizeof(char), l, f) == l);
 179.426 +    }
 179.427 +  }
 179.428 +  return pushresult(L, status, NULL);
 179.429 +}
 179.430 +
 179.431 +
 179.432 +static int io_write (lua_State *L) {
 179.433 +  return g_write(L, getiofile(L, IO_OUTPUT), 1);
 179.434 +}
 179.435 +
 179.436 +
 179.437 +static int f_write (lua_State *L) {
 179.438 +  return g_write(L, tofile(L), 2);
 179.439 +}
 179.440 +
 179.441 +
 179.442 +static int f_seek (lua_State *L) {
 179.443 +  static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
 179.444 +  static const char *const modenames[] = {"set", "cur", "end", NULL};
 179.445 +  FILE *f = tofile(L);
 179.446 +  int op = luaL_checkoption(L, 2, "cur", modenames);
 179.447 +  long offset = luaL_optlong(L, 3, 0);
 179.448 +  op = fseek(f, offset, mode[op]);
 179.449 +  if (op)
 179.450 +    return pushresult(L, 0, NULL);  /* error */
 179.451 +  else {
 179.452 +    lua_pushinteger(L, ftell(f));
 179.453 +    return 1;
 179.454 +  }
 179.455 +}
 179.456 +
 179.457 +
 179.458 +static int f_setvbuf (lua_State *L) {
 179.459 +  static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
 179.460 +  static const char *const modenames[] = {"no", "full", "line", NULL};
 179.461 +  FILE *f = tofile(L);
 179.462 +  int op = luaL_checkoption(L, 2, NULL, modenames);
 179.463 +  lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);
 179.464 +  int res = setvbuf(f, NULL, mode[op], sz);
 179.465 +  return pushresult(L, res == 0, NULL);
 179.466 +}
 179.467 +
 179.468 +
 179.469 +
 179.470 +static int io_flush (lua_State *L) {
 179.471 +  return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);
 179.472 +}
 179.473 +
 179.474 +
 179.475 +static int f_flush (lua_State *L) {
 179.476 +  return pushresult(L, fflush(tofile(L)) == 0, NULL);
 179.477 +}
 179.478 +
 179.479 +
 179.480 +static const luaL_Reg iolib[] = {
 179.481 +  {"close", io_close},
 179.482 +  {"flush", io_flush},
 179.483 +  {"input", io_input},
 179.484 +  {"lines", io_lines},
 179.485 +  {"open", io_open},
 179.486 +  {"output", io_output},
 179.487 +  {"popen", io_popen},
 179.488 +  {"read", io_read},
 179.489 +  {"tmpfile", io_tmpfile},
 179.490 +  {"type", io_type},
 179.491 +  {"write", io_write},
 179.492 +  {NULL, NULL}
 179.493 +};
 179.494 +
 179.495 +
 179.496 +static const luaL_Reg flib[] = {
 179.497 +  {"close", io_close},
 179.498 +  {"flush", f_flush},
 179.499 +  {"lines", f_lines},
 179.500 +  {"read", f_read},
 179.501 +  {"seek", f_seek},
 179.502 +  {"setvbuf", f_setvbuf},
 179.503 +  {"write", f_write},
 179.504 +  {"__gc", io_gc},
 179.505 +  {"__tostring", io_tostring},
 179.506 +  {NULL, NULL}
 179.507 +};
 179.508 +
 179.509 +
 179.510 +static void createmeta (lua_State *L) {
 179.511 +  luaL_newmetatable(L, LUA_FILEHANDLE);  /* create metatable for file handles */
 179.512 +  lua_pushvalue(L, -1);  /* push metatable */
 179.513 +  lua_setfield(L, -2, "__index");  /* metatable.__index = metatable */
 179.514 +  luaL_register(L, NULL, flib);  /* file methods */
 179.515 +}
 179.516 +
 179.517 +
 179.518 +static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {
 179.519 +  *newfile(L) = f;
 179.520 +  if (k > 0) {
 179.521 +    lua_pushvalue(L, -1);
 179.522 +    lua_rawseti(L, LUA_ENVIRONINDEX, k);
 179.523 +  }
 179.524 +  lua_pushvalue(L, -2);  /* copy environment */
 179.525 +  lua_setfenv(L, -2);  /* set it */
 179.526 +  lua_setfield(L, -3, fname);
 179.527 +}
 179.528 +
 179.529 +
 179.530 +static void newfenv (lua_State *L, lua_CFunction cls) {
 179.531 +  lua_createtable(L, 0, 1);
 179.532 +  lua_pushcfunction(L, cls);
 179.533 +  lua_setfield(L, -2, "__close");
 179.534 +}
 179.535 +
 179.536 +
 179.537 +LUALIB_API int luaopen_io (lua_State *L) {
 179.538 +  createmeta(L);
 179.539 +  /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */
 179.540 +  newfenv(L, io_fclose);
 179.541 +  lua_replace(L, LUA_ENVIRONINDEX);
 179.542 +  /* open library */
 179.543 +  luaL_register(L, LUA_IOLIBNAME, iolib);
 179.544 +  /* create (and set) default files */
 179.545 +  newfenv(L, io_noclose);  /* close function for default files */
 179.546 +  createstdfile(L, stdin, IO_INPUT, "stdin");
 179.547 +  createstdfile(L, stdout, IO_OUTPUT, "stdout");
 179.548 +  createstdfile(L, stderr, 0, "stderr");
 179.549 +  lua_pop(L, 1);  /* pop environment for default files */
 179.550 +  lua_getfield(L, -1, "popen");
 179.551 +  newfenv(L, io_pclose);  /* create environment for 'popen' */
 179.552 +  lua_setfenv(L, -2);  /* set fenv for 'popen' */
 179.553 +  lua_pop(L, 1);  /* pop 'popen' */
 179.554 +  return 1;
 179.555 +}
 179.556 +
   180.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   180.2 +++ b/src/lua/src/llex.c	Sat Mar 03 10:31:27 2012 -0600
   180.3 @@ -0,0 +1,461 @@
   180.4 +/*
   180.5 +** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $
   180.6 +** Lexical Analyzer
   180.7 +** See Copyright Notice in lua.h
   180.8 +*/
   180.9 +
  180.10 +
  180.11 +#include <ctype.h>
  180.12 +#include <locale.h>
  180.13 +#include <string.h>
  180.14 +
  180.15 +#define llex_c
  180.16 +#define LUA_CORE
  180.17 +
  180.18 +#include "lua.h"
  180.19 +
  180.20 +#include "ldo.h"
  180.21 +#include "llex.h"
  180.22 +#include "lobject.h"
  180.23 +#include "lparser.h"
  180.24 +#include "lstate.h"
  180.25 +#include "lstring.h"
  180.26 +#include "ltable.h"
  180.27 +#include "lzio.h"
  180.28 +
  180.29 +
  180.30 +
  180.31 +#define next(ls) (ls->current = zgetc(ls->z))
  180.32 +
  180.33 +
  180.34 +
  180.35 +
  180.36 +#define currIsNewline(ls)	(ls->current == '\n' || ls->current == '\r')
  180.37 +
  180.38 +
  180.39 +/* ORDER RESERVED */
  180.40 +const char *const luaX_tokens [] = {
  180.41 +    "and", "break", "do", "else", "elseif",
  180.42 +    "end", "false", "for", "function", "if",
  180.43 +    "in", "local", "nil", "not", "or", "repeat",
  180.44 +    "return", "then", "true", "until", "while",
  180.45 +    "..", "...", "==", ">=", "<=", "~=",
  180.46 +    "<number>", "<name>", "<string>", "<eof>",
  180.47 +    NULL
  180.48 +};
  180.49 +
  180.50 +
  180.51 +#define save_and_next(ls) (save(ls, ls->current), next(ls))
  180.52 +
  180.53 +
  180.54 +static void save (LexState *ls, int c) {
  180.55 +  Mbuffer *b = ls->buff;
  180.56 +  if (b->n + 1 > b->buffsize) {
  180.57 +    size_t newsize;
  180.58 +    if (b->buffsize >= MAX_SIZET/2)
  180.59 +      luaX_lexerror(ls, "lexical element too long", 0);
  180.60 +    newsize = b->buffsize * 2;
  180.61 +    luaZ_resizebuffer(ls->L, b, newsize);
  180.62 +  }
  180.63 +  b->buffer[b->n++] = cast(char, c);
  180.64 +}
  180.65 +
  180.66 +
  180.67 +void luaX_init (lua_State *L) {
  180.68 +  int i;
  180.69 +  for (i=0; i<NUM_RESERVED; i++) {
  180.70 +    TString *ts = luaS_new(L, luaX_tokens[i]);
  180.71 +    luaS_fix(ts);  /* reserved words are never collected */
  180.72 +    lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN);
  180.73 +    ts->tsv.reserved = cast_byte(i+1);  /* reserved word */
  180.74 +  }
  180.75 +}
  180.76 +
  180.77 +
  180.78 +#define MAXSRC          80
  180.79 +
  180.80 +
  180.81 +const char *luaX_token2str (LexState *ls, int token) {
  180.82 +  if (token < FIRST_RESERVED) {
  180.83 +    lua_assert(token == cast(unsigned char, token));
  180.84 +    return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) :
  180.85 +                              luaO_pushfstring(ls->L, "%c", token);
  180.86 +  }
  180.87 +  else
  180.88 +    return luaX_tokens[token-FIRST_RESERVED];
  180.89 +}
  180.90 +
  180.91 +
  180.92 +static const char *txtToken (LexState *ls, int token) {
  180.93 +  switch (token) {
  180.94 +    case TK_NAME:
  180.95 +    case TK_STRING:
  180.96 +    case TK_NUMBER:
  180.97 +      save(ls, '\0');
  180.98 +      return luaZ_buffer(ls->buff);
  180.99 +    default:
 180.100 +      return luaX_token2str(ls, token);
 180.101 +  }
 180.102 +}
 180.103 +
 180.104 +
 180.105 +void luaX_lexerror (LexState *ls, const char *msg, int token) {
 180.106 +  char buff[MAXSRC];
 180.107 +  luaO_chunkid(buff, getstr(ls->source), MAXSRC);
 180.108 +  msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg);
 180.109 +  if (token)
 180.110 +    luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token));
 180.111 +  luaD_throw(ls->L, LUA_ERRSYNTAX);
 180.112 +}
 180.113 +
 180.114 +
 180.115 +void luaX_syntaxerror (LexState *ls, const char *msg) {
 180.116 +  luaX_lexerror(ls, msg, ls->t.token);
 180.117 +}
 180.118 +
 180.119 +
 180.120 +TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
 180.121 +  lua_State *L = ls->L;
 180.122 +  TString *ts = luaS_newlstr(L, str, l);
 180.123 +  TValue *o = luaH_setstr(L, ls->fs->h, ts);  /* entry for `str' */
 180.124 +  if (ttisnil(o))
 180.125 +    setbvalue(o, 1);  /* make sure `str' will not be collected */
 180.126 +  return ts;
 180.127 +}
 180.128 +
 180.129 +
 180.130 +static void inclinenumber (LexState *ls) {
 180.131 +  int old = ls->current;
 180.132 +  lua_assert(currIsNewline(ls));
 180.133 +  next(ls);  /* skip `\n' or `\r' */
 180.134 +  if (currIsNewline(ls) && ls->current != old)
 180.135 +    next(ls);  /* skip `\n\r' or `\r\n' */
 180.136 +  if (++ls->linenumber >= MAX_INT)
 180.137 +    luaX_syntaxerror(ls, "chunk has too many lines");
 180.138 +}
 180.139 +
 180.140 +
 180.141 +void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
 180.142 +  ls->decpoint = '.';
 180.143 +  ls->L = L;
 180.144 +  ls->lookahead.token = TK_EOS;  /* no look-ahead token */
 180.145 +  ls->z = z;
 180.146 +  ls->fs = NULL;
 180.147 +  ls->linenumber = 1;
 180.148 +  ls->lastline = 1;
 180.149 +  ls->source = source;
 180.150 +  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */
 180.151 +  next(ls);  /* read first char */
 180.152 +}
 180.153 +
 180.154 +
 180.155 +
 180.156 +/*
 180.157 +** =======================================================
 180.158 +** LEXICAL ANALYZER
 180.159 +** =======================================================
 180.160 +*/
 180.161 +
 180.162 +
 180.163 +
 180.164 +static int check_next (LexState *ls, const char *set) {
 180.165 +  if (!strchr(set, ls->current))
 180.166 +    return 0;
 180.167 +  save_and_next(ls);
 180.168 +  return 1;
 180.169 +}
 180.170 +
 180.171 +
 180.172 +static void buffreplace (LexState *ls, char from, char to) {
 180.173 +  size_t n = luaZ_bufflen(ls->buff);
 180.174 +  char *p = luaZ_buffer(ls->buff);
 180.175 +  while (n--)
 180.176 +    if (p[n] == from) p[n] = to;
 180.177 +}
 180.178 +
 180.179 +
 180.180 +static void trydecpoint (LexState *ls, SemInfo *seminfo) {
 180.181 +  /* format error: try to update decimal point separator */
 180.182 +  struct lconv *cv = localeconv();
 180.183 +  char old = ls->decpoint;
 180.184 +  ls->decpoint = (cv ? cv->decimal_point[0] : '.');
 180.185 +  buffreplace(ls, old, ls->decpoint);  /* try updated decimal separator */
 180.186 +  if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) {
 180.187 +    /* format error with correct decimal point: no more options */
 180.188 +    buffreplace(ls, ls->decpoint, '.');  /* undo change (for error message) */
 180.189 +    luaX_lexerror(ls, "malformed number", TK_NUMBER);
 180.190 +  }
 180.191 +}
 180.192 +
 180.193 +
 180.194 +/* LUA_NUMBER */
 180.195 +static void read_numeral (LexState *ls, SemInfo *seminfo) {
 180.196 +  lua_assert(isdigit(ls->current));
 180.197 +  do {
 180.198 +    save_and_next(ls);
 180.199 +  } while (isdigit(ls->current) || ls->current == '.');
 180.200 +  if (check_next(ls, "Ee"))  /* `E'? */
 180.201 +    check_next(ls, "+-");  /* optional exponent sign */
 180.202 +  while (isalnum(ls->current) || ls->current == '_')
 180.203 +    save_and_next(ls);
 180.204 +  save(ls, '\0');
 180.205 +  buffreplace(ls, '.', ls->decpoint);  /* follow locale for decimal point */
 180.206 +  if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r))  /* format error? */
 180.207 +    trydecpoint(ls, seminfo); /* try to update decimal point separator */
 180.208 +}
 180.209 +
 180.210 +
 180.211 +static int skip_sep (LexState *ls) {
 180.212 +  int count = 0;
 180.213 +  int s = ls->current;
 180.214 +  lua_assert(s == '[' || s == ']');
 180.215 +  save_and_next(ls);
 180.216 +  while (ls->current == '=') {
 180.217 +    save_and_next(ls);
 180.218 +    count++;
 180.219 +  }
 180.220 +  return (ls->current == s) ? count : (-count) - 1;
 180.221 +}
 180.222 +
 180.223 +
 180.224 +static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
 180.225 +  int cont = 0;
 180.226 +  (void)(cont);  /* avoid warnings when `cont' is not used */
 180.227 +  save_and_next(ls);  /* skip 2nd `[' */
 180.228 +  if (currIsNewline(ls))  /* string starts with a newline? */
 180.229 +    inclinenumber(ls);  /* skip it */
 180.230 +  for (;;) {
 180.231 +    switch (ls->current) {
 180.232 +      case EOZ:
 180.233 +        luaX_lexerror(ls, (seminfo) ? "unfinished long string" :
 180.234 +                                   "unfinished long comment", TK_EOS);
 180.235 +        break;  /* to avoid warnings */
 180.236 +#if defined(LUA_COMPAT_LSTR)
 180.237 +      case '[': {
 180.238 +        if (skip_sep(ls) == sep) {
 180.239 +          save_and_next(ls);  /* skip 2nd `[' */
 180.240 +          cont++;
 180.241 +#if LUA_COMPAT_LSTR == 1
 180.242 +          if (sep == 0)
 180.243 +            luaX_lexerror(ls, "nesting of [[...]] is deprecated", '[');
 180.244 +#endif
 180.245 +        }
 180.246 +        break;
 180.247 +      }
 180.248 +#endif
 180.249 +      case ']': {
 180.250 +        if (skip_sep(ls) == sep) {
 180.251 +          save_and_next(ls);  /* skip 2nd `]' */
 180.252 +#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2
 180.253 +          cont--;
 180.254 +          if (sep == 0 && cont >= 0) break;
 180.255 +#endif
 180.256 +          goto endloop;
 180.257 +        }
 180.258 +        break;
 180.259 +      }
 180.260 +      case '\n':
 180.261 +      case '\r': {
 180.262 +        save(ls, '\n');
 180.263 +        inclinenumber(ls);
 180.264 +        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */
 180.265 +        break;
 180.266 +      }
 180.267 +      default: {
 180.268 +        if (seminfo) save_and_next(ls);
 180.269 +        else next(ls);
 180.270 +      }
 180.271 +    }
 180.272 +  } endloop:
 180.273 +  if (seminfo)
 180.274 +    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),
 180.275 +                                     luaZ_bufflen(ls->buff) - 2*(2 + sep));
 180.276 +}
 180.277 +
 180.278 +
 180.279 +static void read_string (LexState *ls, int del, SemInfo *seminfo) {
 180.280 +  save_and_next(ls);
 180.281 +  while (ls->current != del) {
 180.282 +    switch (ls->current) {
 180.283 +      case EOZ:
 180.284 +        luaX_lexerror(ls, "unfinished string", TK_EOS);
 180.285 +        continue;  /* to avoid warnings */
 180.286 +      case '\n':
 180.287 +      case '\r':
 180.288 +        luaX_lexerror(ls, "unfinished string", TK_STRING);
 180.289 +        continue;  /* to avoid warnings */
 180.290 +      case '\\': {
 180.291 +        int c;
 180.292 +        next(ls);  /* do not save the `\' */
 180.293 +        switch (ls->current) {
 180.294 +          case 'a': c = '\a'; break;
 180.295 +          case 'b': c = '\b'; break;
 180.296 +          case 'f': c = '\f'; break;
 180.297 +          case 'n': c = '\n'; break;
 180.298 +          case 'r': c = '\r'; break;
 180.299 +          case 't': c = '\t'; break;
 180.300 +          case 'v': c = '\v'; break;
 180.301 +          case '\n':  /* go through */
 180.302 +          case '\r': save(ls, '\n'); inclinenumber(ls); continue;
 180.303 +          case EOZ: continue;  /* will raise an error next loop */
 180.304 +          default: {
 180.305 +            if (!isdigit(ls->current))
 180.306 +              save_and_next(ls);  /* handles \\, \", \', and \? */
 180.307 +            else {  /* \xxx */
 180.308 +              int i = 0;
 180.309 +              c = 0;
 180.310 +              do {
 180.311 +                c = 10*c + (ls->current-'0');
 180.312 +                next(ls);
 180.313 +              } while (++i<3 && isdigit(ls->current));
 180.314 +              if (c > UCHAR_MAX)
 180.315 +                luaX_lexerror(ls, "escape sequence too large", TK_STRING);
 180.316 +              save(ls, c);
 180.317 +            }
 180.318 +            continue;
 180.319 +          }
 180.320 +        }
 180.321 +        save(ls, c);
 180.322 +        next(ls);
 180.323 +        continue;
 180.324 +      }
 180.325 +      default:
 180.326 +        save_and_next(ls);
 180.327 +    }
 180.328 +  }
 180.329 +  save_and_next(ls);  /* skip delimiter */
 180.330 +  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
 180.331 +                                   luaZ_bufflen(ls->buff) - 2);
 180.332 +}
 180.333 +
 180.334 +
 180.335 +static int llex (LexState *ls, SemInfo *seminfo) {
 180.336 +  luaZ_resetbuffer(ls->buff);
 180.337 +  for (;;) {
 180.338 +    switch (ls->current) {
 180.339 +      case '\n':
 180.340 +      case '\r': {
 180.341 +        inclinenumber(ls);
 180.342 +        continue;
 180.343 +      }
 180.344 +      case '-': {
 180.345 +        next(ls);
 180.346 +        if (ls->current != '-') return '-';
 180.347 +        /* else is a comment */
 180.348 +        next(ls);
 180.349 +        if (ls->current == '[') {
 180.350 +          int sep = skip_sep(ls);
 180.351 +          luaZ_resetbuffer(ls->buff);  /* `skip_sep' may dirty the buffer */
 180.352 +          if (sep >= 0) {
 180.353 +            read_long_string(ls, NULL, sep);  /* long comment */
 180.354 +            luaZ_resetbuffer(ls->buff);
 180.355 +            continue;
 180.356 +          }
 180.357 +        }
 180.358 +        /* else short comment */
 180.359 +        while (!currIsNewline(ls) && ls->current != EOZ)
 180.360 +          next(ls);
 180.361 +        continue;
 180.362 +      }
 180.363 +      case '[': {
 180.364 +        int sep = skip_sep(ls);
 180.365 +        if (sep >= 0) {
 180.366 +          read_long_string(ls, seminfo, sep);
 180.367 +          return TK_STRING;
 180.368 +        }
 180.369 +        else if (sep == -1) return '[';
 180.370 +        else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING);
 180.371 +      }
 180.372 +      case '=': {
 180.373 +        next(ls);
 180.374 +        if (ls->current != '=') return '=';
 180.375 +        else { next(ls); return TK_EQ; }
 180.376 +      }
 180.377 +      case '<': {
 180.378 +        next(ls);
 180.379 +        if (ls->current != '=') return '<';
 180.380 +        else { next(ls); return TK_LE; }
 180.381 +      }
 180.382 +      case '>': {
 180.383 +        next(ls);
 180.384 +        if (ls->current != '=') return '>';
 180.385 +        else { next(ls); return TK_GE; }
 180.386 +      }
 180.387 +      case '~': {
 180.388 +        next(ls);
 180.389 +        if (ls->current != '=') return '~';
 180.390 +        else { next(ls); return TK_NE; }
 180.391 +      }
 180.392 +      case '"':
 180.393 +      case '\'': {
 180.394 +        read_string(ls, ls->current, seminfo);
 180.395 +        return TK_STRING;
 180.396 +      }
 180.397 +      case '.': {
 180.398 +        save_and_next(ls);
 180.399 +        if (check_next(ls, ".")) {
 180.400 +          if (check_next(ls, "."))
 180.401 +            return TK_DOTS;   /* ... */
 180.402 +          else return TK_CONCAT;   /* .. */
 180.403 +        }
 180.404 +        else if (!isdigit(ls->current)) return '.';
 180.405 +        else {
 180.406 +          read_numeral(ls, seminfo);
 180.407 +          return TK_NUMBER;
 180.408 +        }
 180.409 +      }
 180.410 +      case EOZ: {
 180.411 +        return TK_EOS;
 180.412 +      }
 180.413 +      default: {
 180.414 +        if (isspace(ls->current)) {
 180.415 +          lua_assert(!currIsNewline(ls));
 180.416 +          next(ls);
 180.417 +          continue;
 180.418 +        }
 180.419 +        else if (isdigit(ls->current)) {
 180.420 +          read_numeral(ls, seminfo);
 180.421 +          return TK_NUMBER;
 180.422 +        }
 180.423 +        else if (isalpha(ls->current) || ls->current == '_') {
 180.424 +          /* identifier or reserved word */
 180.425 +          TString *ts;
 180.426 +          do {
 180.427 +            save_and_next(ls);
 180.428 +          } while (isalnum(ls->current) || ls->current == '_');
 180.429 +          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
 180.430 +                                  luaZ_bufflen(ls->buff));
 180.431 +          if (ts->tsv.reserved > 0)  /* reserved word? */
 180.432 +            return ts->tsv.reserved - 1 + FIRST_RESERVED;
 180.433 +          else {
 180.434 +            seminfo->ts = ts;
 180.435 +            return TK_NAME;
 180.436 +          }
 180.437 +        }
 180.438 +        else {
 180.439 +          int c = ls->current;
 180.440 +          next(ls);
 180.441 +          return c;  /* single-char tokens (+ - / ...) */
 180.442 +        }
 180.443 +      }
 180.444 +    }
 180.445 +  }
 180.446 +}
 180.447 +
 180.448 +
 180.449 +void luaX_next (LexState *ls) {
 180.450 +  ls->lastline = ls->linenumber;
 180.451 +  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */
 180.452 +    ls->t = ls->lookahead;  /* use this one */
 180.453 +    ls->lookahead.token = TK_EOS;  /* and discharge it */
 180.454 +  }
 180.455 +  else
 180.456 +    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */
 180.457 +}
 180.458 +
 180.459 +
 180.460 +void luaX_lookahead (LexState *ls) {
 180.461 +  lua_assert(ls->lookahead.token == TK_EOS);
 180.462 +  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
 180.463 +}
 180.464 +
   181.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   181.2 +++ b/src/lua/src/llex.h	Sat Mar 03 10:31:27 2012 -0600
   181.3 @@ -0,0 +1,81 @@
   181.4 +/*
   181.5 +** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $
   181.6 +** Lexical Analyzer
   181.7 +** See Copyright Notice in lua.h
   181.8 +*/
   181.9 +
  181.10 +#ifndef llex_h
  181.11 +#define llex_h
  181.12 +
  181.13 +#include "lobject.h"
  181.14 +#include "lzio.h"
  181.15 +
  181.16 +
  181.17 +#define FIRST_RESERVED	257
  181.18 +
  181.19 +/* maximum length of a reserved word */
  181.20 +#define TOKEN_LEN	(sizeof("function")/sizeof(char))
  181.21 +
  181.22 +
  181.23 +/*
  181.24 +* WARNING: if you change the order of this enumeration,
  181.25 +* grep "ORDER RESERVED"
  181.26 +*/
  181.27 +enum RESERVED {
  181.28 +  /* terminal symbols denoted by reserved words */
  181.29 +  TK_AND = FIRST_RESERVED, TK_BREAK,
  181.30 +  TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
  181.31 +  TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
  181.32 +  TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
  181.33 +  /* other terminal symbols */
  181.34 +  TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,
  181.35 +  TK_NAME, TK_STRING, TK_EOS
  181.36 +};
  181.37 +
  181.38 +/* number of reserved words */
  181.39 +#define NUM_RESERVED	(cast(int, TK_WHILE-FIRST_RESERVED+1))
  181.40 +
  181.41 +
  181.42 +/* array with token `names' */
  181.43 +LUAI_DATA const char *const luaX_tokens [];
  181.44 +
  181.45 +
  181.46 +typedef union {
  181.47 +  lua_Number r;
  181.48 +  TString *ts;
  181.49 +} SemInfo;  /* semantics information */
  181.50 +
  181.51 +
  181.52 +typedef struct Token {
  181.53 +  int token;
  181.54 +  SemInfo seminfo;
  181.55 +} Token;
  181.56 +
  181.57 +
  181.58 +typedef struct LexState {
  181.59 +  int current;  /* current character (charint) */
  181.60 +  int linenumber;  /* input line counter */
  181.61 +  int lastline;  /* line of last token `consumed' */
  181.62 +  Token t;  /* current token */
  181.63 +  Token lookahead;  /* look ahead token */
  181.64 +  struct FuncState *fs;  /* `FuncState' is private to the parser */
  181.65 +  struct lua_State *L;
  181.66 +  ZIO *z;  /* input stream */
  181.67 +  Mbuffer *buff;  /* buffer for tokens */
  181.68 +  TString *source;  /* current source name */
  181.69 +  char decpoint;  /* locale decimal point */
  181.70 +} LexState;
  181.71 +
  181.72 +
  181.73 +LUAI_FUNC void luaX_init (lua_State *L);
  181.74 +LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,
  181.75 +                              TString *source);
  181.76 +LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);
  181.77 +LUAI_FUNC void luaX_next (LexState *ls);
  181.78 +LUAI_FUNC void luaX_lookahead (LexState *ls);
  181.79 +LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token);
  181.80 +LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s);
  181.81 +LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
  181.82 +
  181.83 +
  181.84 +#endif
   182.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   182.2 +++ b/src/lua/src/llimits.h	Sat Mar 03 10:31:27 2012 -0600
   182.3 @@ -0,0 +1,128 @@
   182.4 +/*
   182.5 +** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $
   182.6 +** Limits, basic types, and some other `installation-dependent' definitions
   182.7 +** See Copyright Notice in lua.h
   182.8 +*/
   182.9 +
  182.10 +#ifndef llimits_h
  182.11 +#define llimits_h
  182.12 +
  182.13 +
  182.14 +#include <limits.h>
  182.15 +#include <stddef.h>
  182.16 +
  182.17 +
  182.18 +#include "lua.h"
  182.19 +
  182.20 +
  182.21 +typedef LUAI_UINT32 lu_int32;
  182.22 +
  182.23 +typedef LUAI_UMEM lu_mem;
  182.24 +
  182.25 +typedef LUAI_MEM l_mem;
  182.26 +
  182.27 +
  182.28 +
  182.29 +/* chars used as small naturals (so that `char' is reserved for characters) */
  182.30 +typedef unsigned char lu_byte;
  182.31 +
  182.32 +
  182.33 +#define MAX_SIZET	((size_t)(~(size_t)0)-2)
  182.34 +
  182.35 +#define MAX_LUMEM	((lu_mem)(~(lu_mem)0)-2)
  182.36 +
  182.37 +
  182.38 +#define MAX_INT (INT_MAX-2)  /* maximum value of an int (-2 for safety) */
  182.39 +
  182.40 +/*
  182.41 +** conversion of pointer to integer
  182.42 +** this is for hashing only; there is no problem if the integer
  182.43 +** cannot hold the whole pointer value
  182.44 +*/
  182.45 +#define IntPoint(p)  ((unsigned int)(lu_mem)(p))
  182.46 +
  182.47 +
  182.48 +
  182.49 +/* type to ensure maximum alignment */
  182.50 +typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
  182.51 +
  182.52 +
  182.53 +/* result of a `usual argument conversion' over lua_Number */
  182.54 +typedef LUAI_UACNUMBER l_uacNumber;
  182.55 +
  182.56 +
  182.57 +/* internal assertions for in-house debugging */
  182.58 +#ifdef lua_assert
  182.59 +
  182.60 +#define check_exp(c,e)		(lua_assert(c), (e))
  182.61 +#define api_check(l,e)		lua_assert(e)
  182.62 +
  182.63 +#else
  182.64 +
  182.65 +#define lua_assert(c)		((void)0)
  182.66 +#define check_exp(c,e)		(e)
  182.67 +#define api_check		luai_apicheck
  182.68 +
  182.69 +#endif
  182.70 +
  182.71 +
  182.72 +#ifndef UNUSED
  182.73 +#define UNUSED(x)	((void)(x))	/* to avoid warnings */
  182.74 +#endif
  182.75 +
  182.76 +
  182.77 +#ifndef cast
  182.78 +#define cast(t, exp)	((t)(exp))
  182.79 +#endif
  182.80 +
  182.81 +#define cast_byte(i)	cast(lu_byte, (i))
  182.82 +#define cast_num(i)	cast(lua_Number, (i))
  182.83 +#define cast_int(i)	cast(int, (i))
  182.84 +
  182.85 +
  182.86 +
  182.87 +/*
  182.88 +** type for virtual-machine instructions
  182.89 +** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
  182.90 +*/
  182.91 +typedef lu_int32 Instruction;
  182.92 +
  182.93 +
  182.94 +
  182.95 +/* maximum stack for a Lua function */
  182.96 +#define MAXSTACK	250
  182.97 +
  182.98 +
  182.99 +
 182.100 +/* minimum size for the string table (must be power of 2) */
 182.101 +#ifndef MINSTRTABSIZE
 182.102 +#define MINSTRTABSIZE	32
 182.103 +#endif
 182.104 +
 182.105 +
 182.106 +/* minimum size for string buffer */
 182.107 +#ifndef LUA_MINBUFFER
 182.108 +#define LUA_MINBUFFER	32
 182.109 +#endif
 182.110 +
 182.111 +
 182.112 +#ifndef lua_lock
 182.113 +#define lua_lock(L)     ((void) 0) 
 182.114 +#define lua_unlock(L)   ((void) 0)
 182.115 +#endif
 182.116 +
 182.117 +#ifndef luai_threadyield
 182.118 +#define luai_threadyield(L)     {lua_unlock(L); lua_lock(L);}
 182.119 +#endif
 182.120 +
 182.121 +
 182.122 +/*
 182.123 +** macro to control inclusion of some hard tests on stack reallocation
 182.124 +*/ 
 182.125 +#ifndef HARDSTACKTESTS
 182.126 +#define condhardstacktests(x)	((void)0)
 182.127 +#else
 182.128 +#define condhardstacktests(x)	x
 182.129 +#endif
 182.130 +
 182.131 +#endif
   183.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   183.2 +++ b/src/lua/src/lmathlib.c	Sat Mar 03 10:31:27 2012 -0600
   183.3 @@ -0,0 +1,263 @@
   183.4 +/*
   183.5 +** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $
   183.6 +** Standard mathematical library
   183.7 +** See Copyright Notice in lua.h
   183.8 +*/
   183.9 +
  183.10 +
  183.11 +#include <stdlib.h>
  183.12 +#include <math.h>
  183.13 +
  183.14 +#define lmathlib_c
  183.15 +#define LUA_LIB
  183.16 +
  183.17 +#include "lua.h"
  183.18 +
  183.19 +#include "lauxlib.h"
  183.20 +#include "lualib.h"
  183.21 +
  183.22 +
  183.23 +#undef PI
  183.24 +#define PI (3.14159265358979323846)
  183.25 +#define RADIANS_PER_DEGREE (PI/180.0)
  183.26 +
  183.27 +
  183.28 +
  183.29 +static int math_abs (lua_State *L) {
  183.30 +  lua_pushnumber(L, fabs(luaL_checknumber(L, 1)));
  183.31 +  return 1;
  183.32 +}
  183.33 +
  183.34 +static int math_sin (lua_State *L) {
  183.35 +  lua_pushnumber(L, sin(luaL_checknumber(L, 1)));
  183.36 +  return 1;
  183.37 +}
  183.38 +
  183.39 +static int math_sinh (lua_State *L) {
  183.40 +  lua_pushnumber(L, sinh(luaL_checknumber(L, 1)));
  183.41 +  return 1;
  183.42 +}
  183.43 +
  183.44 +static int math_cos (lua_State *L) {
  183.45 +  lua_pushnumber(L, cos(luaL_checknumber(L, 1)));
  183.46 +  return 1;
  183.47 +}
  183.48 +
  183.49 +static int math_cosh (lua_State *L) {
  183.50 +  lua_pushnumber(L, cosh(luaL_checknumber(L, 1)));
  183.51 +  return 1;
  183.52 +}
  183.53 +
  183.54 +static int math_tan (lua_State *L) {
  183.55 +  lua_pushnumber(L, tan(luaL_checknumber(L, 1)));
  183.56 +  return 1;
  183.57 +}
  183.58 +
  183.59 +static int math_tanh (lua_State *L) {
  183.60 +  lua_pushnumber(L, tanh(luaL_checknumber(L, 1)));
  183.61 +  return 1;
  183.62 +}
  183.63 +
  183.64 +static int math_asin (lua_State *L) {
  183.65 +  lua_pushnumber(L, asin(luaL_checknumber(L, 1)));
  183.66 +  return 1;
  183.67 +}
  183.68 +
  183.69 +static int math_acos (lua_State *L) {
  183.70 +  lua_pushnumber(L, acos(luaL_checknumber(L, 1)));
  183.71 +  return 1;
  183.72 +}
  183.73 +
  183.74 +static int math_atan (lua_State *L) {
  183.75 +  lua_pushnumber(L, atan(luaL_checknumber(L, 1)));
  183.76 +  return 1;
  183.77 +}
  183.78 +
  183.79 +static int math_atan2 (lua_State *L) {
  183.80 +  lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
  183.81 +  return 1;
  183.82 +}
  183.83 +
  183.84 +static int math_ceil (lua_State *L) {
  183.85 +  lua_pushnumber(L, ceil(luaL_checknumber(L, 1)));
  183.86 +  return 1;
  183.87 +}
  183.88 +
  183.89 +static int math_floor (lua_State *L) {
  183.90 +  lua_pushnumber(L, floor(luaL_checknumber(L, 1)));
  183.91 +  return 1;
  183.92 +}
  183.93 +
  183.94 +static int math_fmod (lua_State *L) {
  183.95 +  lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
  183.96 +  return 1;
  183.97 +}
  183.98 +
  183.99 +static int math_modf (lua_State *L) {
 183.100 +  double ip;
 183.101 +  double fp = modf(luaL_checknumber(L, 1), &ip);
 183.102 +  lua_pushnumber(L, ip);
 183.103 +  lua_pushnumber(L, fp);
 183.104 +  return 2;
 183.105 +}
 183.106 +
 183.107 +static int math_sqrt (lua_State *L) {
 183.108 +  lua_pushnumber(L, sqrt(luaL_checknumber(L, 1)));
 183.109 +  return 1;
 183.110 +}
 183.111 +
 183.112 +static int math_pow (lua_State *L) {
 183.113 +  lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
 183.114 +  return 1;
 183.115 +}
 183.116 +
 183.117 +static int math_log (lua_State *L) {
 183.118 +  lua_pushnumber(L, log(luaL_checknumber(L, 1)));
 183.119 +  return 1;
 183.120 +}
 183.121 +
 183.122 +static int math_log10 (lua_State *L) {
 183.123 +  lua_pushnumber(L, log10(luaL_checknumber(L, 1)));
 183.124 +  return 1;
 183.125 +}
 183.126 +
 183.127 +static int math_exp (lua_State *L) {
 183.128 +  lua_pushnumber(L, exp(luaL_checknumber(L, 1)));
 183.129 +  return 1;
 183.130 +}
 183.131 +
 183.132 +static int math_deg (lua_State *L) {
 183.133 +  lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE);
 183.134 +  return 1;
 183.135 +}
 183.136 +
 183.137 +static int math_rad (lua_State *L) {
 183.138 +  lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE);
 183.139 +  return 1;
 183.140 +}
 183.141 +
 183.142 +static int math_frexp (lua_State *L) {
 183.143 +  int e;
 183.144 +  lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e));
 183.145 +  lua_pushinteger(L, e);
 183.146 +  return 2;
 183.147 +}
 183.148 +
 183.149 +static int math_ldexp (lua_State *L) {
 183.150 +  lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));
 183.151 +  return 1;
 183.152 +}
 183.153 +
 183.154 +
 183.155 +
 183.156 +static int math_min (lua_State *L) {
 183.157 +  int n = lua_gettop(L);  /* number of arguments */
 183.158 +  lua_Number dmin = luaL_checknumber(L, 1);
 183.159 +  int i;
 183.160 +  for (i=2; i<=n; i++) {
 183.161 +    lua_Number d = luaL_checknumber(L, i);
 183.162 +    if (d < dmin)
 183.163 +      dmin = d;
 183.164 +  }
 183.165 +  lua_pushnumber(L, dmin);
 183.166 +  return 1;
 183.167 +}
 183.168 +
 183.169 +
 183.170 +static int math_max (lua_State *L) {
 183.171 +  int n = lua_gettop(L);  /* number of arguments */
 183.172 +  lua_Number dmax = luaL_checknumber(L, 1);
 183.173 +  int i;
 183.174 +  for (i=2; i<=n; i++) {
 183.175 +    lua_Number d = luaL_checknumber(L, i);
 183.176 +    if (d > dmax)
 183.177 +      dmax = d;
 183.178 +  }
 183.179 +  lua_pushnumber(L, dmax);
 183.180 +  return 1;
 183.181 +}
 183.182 +
 183.183 +
 183.184 +static int math_random (lua_State *L) {
 183.185 +  /* the `%' avoids the (rare) case of r==1, and is needed also because on
 183.186 +     some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */
 183.187 +  lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;
 183.188 +  switch (lua_gettop(L)) {  /* check number of arguments */
 183.189 +    case 0: {  /* no arguments */
 183.190 +      lua_pushnumber(L, r);  /* Number between 0 and 1 */
 183.191 +      break;
 183.192 +    }
 183.193 +    case 1: {  /* only upper limit */
 183.194 +      int u = luaL_checkint(L, 1);
 183.195 +      luaL_argcheck(L, 1<=u, 1, "interval is empty");
 183.196 +      lua_pushnumber(L, floor(r*u)+1);  /* int between 1 and `u' */
 183.197 +      break;
 183.198 +    }
 183.199 +    case 2: {  /* lower and upper limits */
 183.200 +      int l = luaL_checkint(L, 1);
 183.201 +      int u = luaL_checkint(L, 2);
 183.202 +      luaL_argcheck(L, l<=u, 2, "interval is empty");
 183.203 +      lua_pushnumber(L, floor(r*(u-l+1))+l);  /* int between `l' and `u' */
 183.204 +      break;
 183.205 +    }
 183.206 +    default: return luaL_error(L, "wrong number of arguments");
 183.207 +  }
 183.208 +  return 1;
 183.209 +}
 183.210 +
 183.211 +
 183.212 +static int math_randomseed (lua_State *L) {
 183.213 +  srand(luaL_checkint(L, 1));
 183.214 +  return 0;
 183.215 +}
 183.216 +
 183.217 +
 183.218 +static const luaL_Reg mathlib[] = {
 183.219 +  {"abs",   math_abs},
 183.220 +  {"acos",  math_acos},
 183.221 +  {"asin",  math_asin},
 183.222 +  {"atan2", math_atan2},
 183.223 +  {"atan",  math_atan},
 183.224 +  {"ceil",  math_ceil},
 183.225 +  {"cosh",   math_cosh},
 183.226 +  {"cos",   math_cos},
 183.227 +  {"deg",   math_deg},
 183.228 +  {"exp",   math_exp},
 183.229 +  {"floor", math_floor},
 183.230 +  {"fmod",   math_fmod},
 183.231 +  {"frexp", math_frexp},
 183.232 +  {"ldexp", math_ldexp},
 183.233 +  {"log10", math_log10},
 183.234 +  {"log",   math_log},
 183.235 +  {"max",   math_max},
 183.236 +  {"min",   math_min},
 183.237 +  {"modf",   math_modf},
 183.238 +  {"pow",   math_pow},
 183.239 +  {"rad",   math_rad},
 183.240 +  {"random",     math_random},
 183.241 +  {"randomseed", math_randomseed},
 183.242 +  {"sinh",   math_sinh},
 183.243 +  {"sin",   math_sin},
 183.244 +  {"sqrt",  math_sqrt},
 183.245 +  {"tanh",   math_tanh},
 183.246 +  {"tan",   math_tan},
 183.247 +  {NULL, NULL}
 183.248 +};
 183.249 +
 183.250 +
 183.251 +/*
 183.252 +** Open math library
 183.253 +*/
 183.254 +LUALIB_API int luaopen_math (lua_State *L) {
 183.255 +  luaL_register(L, LUA_MATHLIBNAME, mathlib);
 183.256 +  lua_pushnumber(L, PI);
 183.257 +  lua_setfield(L, -2, "pi");
 183.258 +  lua_pushnumber(L, HUGE_VAL);
 183.259 +  lua_setfield(L, -2, "huge");
 183.260 +#if defined(LUA_COMPAT_MOD)
 183.261 +  lua_getfield(L, -1, "fmod");
 183.262 +  lua_setfield(L, -2, "mod");
 183.263 +#endif
 183.264 +  return 1;
 183.265 +}
 183.266 +
   184.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   184.2 +++ b/src/lua/src/lmem.c	Sat Mar 03 10:31:27 2012 -0600
   184.3 @@ -0,0 +1,86 @@
   184.4 +/*
   184.5 +** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $
   184.6 +** Interface to Memory Manager
   184.7 +** See Copyright Notice in lua.h
   184.8 +*/
   184.9 +
  184.10 +
  184.11 +#include <stddef.h>
  184.12 +
  184.13 +#define lmem_c
  184.14 +#define LUA_CORE
  184.15 +
  184.16 +#include "lua.h"
  184.17 +
  184.18 +#include "ldebug.h"
  184.19 +#include "ldo.h"
  184.20 +#include "lmem.h"
  184.21 +#include "lobject.h"
  184.22 +#include "lstate.h"
  184.23 +
  184.24 +
  184.25 +
  184.26 +/*
  184.27 +** About the realloc function:
  184.28 +** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);
  184.29 +** (`osize' is the old size, `nsize' is the new size)
  184.30 +**
  184.31 +** Lua ensures that (ptr == NULL) iff (osize == 0).
  184.32 +**
  184.33 +** * frealloc(ud, NULL, 0, x) creates a new block of size `x'
  184.34 +**
  184.35 +** * frealloc(ud, p, x, 0) frees the block `p'
  184.36 +** (in this specific case, frealloc must return NULL).
  184.37 +** particularly, frealloc(ud, NULL, 0, 0) does nothing
  184.38 +** (which is equivalent to free(NULL) in ANSI C)
  184.39 +**
  184.40 +** frealloc returns NULL if it cannot create or reallocate the area
  184.41 +** (any reallocation to an equal or smaller size cannot fail!)
  184.42 +*/
  184.43 +
  184.44 +
  184.45 +
  184.46 +#define MINSIZEARRAY	4
  184.47 +
  184.48 +
  184.49 +void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,
  184.50 +                     int limit, const char *errormsg) {
  184.51 +  void *newblock;
  184.52 +  int newsize;
  184.53 +  if (*size >= limit/2) {  /* cannot double it? */
  184.54 +    if (*size >= limit)  /* cannot grow even a little? */
  184.55 +      luaG_runerror(L, errormsg);
  184.56 +    newsize = limit;  /* still have at least one free place */
  184.57 +  }
  184.58 +  else {
  184.59 +    newsize = (*size)*2;
  184.60 +    if (newsize < MINSIZEARRAY)
  184.61 +      newsize = MINSIZEARRAY;  /* minimum size */
  184.62 +  }
  184.63 +  newblock = luaM_reallocv(L, block, *size, newsize, size_elems);
  184.64 +  *size = newsize;  /* update only when everything else is OK */
  184.65 +  return newblock;
  184.66 +}
  184.67 +
  184.68 +
  184.69 +void *luaM_toobig (lua_State *L) {
  184.70 +  luaG_runerror(L, "memory allocation error: block too big");
  184.71 +  return NULL;  /* to avoid warnings */
  184.72 +}
  184.73 +
  184.74 +
  184.75 +
  184.76 +/*
  184.77 +** generic allocation routine.
  184.78 +*/
  184.79 +void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
  184.80 +  global_State *g = G(L);
  184.81 +  lua_assert((osize == 0) == (block == NULL));
  184.82 +  block = (*g->frealloc)(g->ud, block, osize, nsize);
  184.83 +  if (block == NULL && nsize > 0)
  184.84 +    luaD_throw(L, LUA_ERRMEM);
  184.85 +  lua_assert((nsize == 0) == (block == NULL));
  184.86 +  g->totalbytes = (g->totalbytes - osize) + nsize;
  184.87 +  return block;
  184.88 +}
  184.89 +
   185.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   185.2 +++ b/src/lua/src/lmem.h	Sat Mar 03 10:31:27 2012 -0600
   185.3 @@ -0,0 +1,49 @@
   185.4 +/*
   185.5 +** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $
   185.6 +** Interface to Memory Manager
   185.7 +** See Copyright Notice in lua.h
   185.8 +*/
   185.9 +
  185.10 +#ifndef lmem_h
  185.11 +#define lmem_h
  185.12 +
  185.13 +
  185.14 +#include <stddef.h>
  185.15 +
  185.16 +#include "llimits.h"
  185.17 +#include "lua.h"
  185.18 +
  185.19 +#define MEMERRMSG	"not enough memory"
  185.20 +
  185.21 +
  185.22 +#define luaM_reallocv(L,b,on,n,e) \
  185.23 +	((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ?  /* +1 to avoid warnings */ \
  185.24 +		luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \
  185.25 +		luaM_toobig(L))
  185.26 +
  185.27 +#define luaM_freemem(L, b, s)	luaM_realloc_(L, (b), (s), 0)
  185.28 +#define luaM_free(L, b)		luaM_realloc_(L, (b), sizeof(*(b)), 0)
  185.29 +#define luaM_freearray(L, b, n, t)   luaM_reallocv(L, (b), n, 0, sizeof(t))
  185.30 +
  185.31 +#define luaM_malloc(L,t)	luaM_realloc_(L, NULL, 0, (t))
  185.32 +#define luaM_new(L,t)		cast(t *, luaM_malloc(L, sizeof(t)))
  185.33 +#define luaM_newvector(L,n,t) \
  185.34 +		cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
  185.35 +
  185.36 +#define luaM_growvector(L,v,nelems,size,t,limit,e) \
  185.37 +          if ((nelems)+1 > (size)) \
  185.38 +            ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
  185.39 +
  185.40 +#define luaM_reallocvector(L, v,oldn,n,t) \
  185.41 +   ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
  185.42 +
  185.43 +
  185.44 +LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
  185.45 +                                                          size_t size);
  185.46 +LUAI_FUNC void *luaM_toobig (lua_State *L);
  185.47 +LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
  185.48 +                               size_t size_elem, int limit,
  185.49 +                               const char *errormsg);
  185.50 +
  185.51 +#endif
  185.52 +
   186.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   186.2 +++ b/src/lua/src/loadlib.c	Sat Mar 03 10:31:27 2012 -0600
   186.3 @@ -0,0 +1,666 @@
   186.4 +/*
   186.5 +** $Id: loadlib.c,v 1.52.1.3 2008/08/06 13:29:28 roberto Exp $
   186.6 +** Dynamic library loader for Lua
   186.7 +** See Copyright Notice in lua.h
   186.8 +**
   186.9 +** This module contains an implementation of loadlib for Unix systems
  186.10 +** that have dlfcn, an implementation for Darwin (Mac OS X), an
  186.11 +** implementation for Windows, and a stub for other systems.
  186.12 +*/
  186.13 +
  186.14 +
  186.15 +#include <stdlib.h>
  186.16 +#include <string.h>
  186.17 +
  186.18 +
  186.19 +#define loadlib_c
  186.20 +#define LUA_LIB
  186.21 +
  186.22 +#include "lua.h"
  186.23 +
  186.24 +#include "lauxlib.h"
  186.25 +#include "lualib.h"
  186.26 +
  186.27 +
  186.28 +/* prefix for open functions in C libraries */
  186.29 +#define LUA_POF		"luaopen_"
  186.30 +
  186.31 +/* separator for open functions in C libraries */
  186.32 +#define LUA_OFSEP	"_"
  186.33 +
  186.34 +
  186.35 +#define LIBPREFIX	"LOADLIB: "
  186.36 +
  186.37 +#define POF		LUA_POF
  186.38 +#define LIB_FAIL	"open"
  186.39 +
  186.40 +
  186.41 +/* error codes for ll_loadfunc */
  186.42 +#define ERRLIB		1
  186.43 +#define ERRFUNC		2
  186.44 +
  186.45 +#define setprogdir(L)		((void)0)
  186.46 +
  186.47 +
  186.48 +static void ll_unloadlib (void *lib);
  186.49 +static void *ll_load (lua_State *L, const char *path);
  186.50 +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym);
  186.51 +
  186.52 +
  186.53 +
  186.54 +#if defined(LUA_DL_DLOPEN)
  186.55 +/*
  186.56 +** {========================================================================
  186.57 +** This is an implementation of loadlib based on the dlfcn interface.
  186.58 +** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,
  186.59 +** NetBSD, AIX 4.2, HPUX 11, and  probably most other Unix flavors, at least
  186.60 +** as an emulation layer on top of native functions.
  186.61 +** =========================================================================
  186.62 +*/
  186.63 +
  186.64 +#include <dlfcn.h>
  186.65 +
  186.66 +static void ll_unloadlib (void *lib) {
  186.67 +  dlclose(lib);
  186.68 +}
  186.69 +
  186.70 +
  186.71 +static void *ll_load (lua_State *L, const char *path) {
  186.72 +  void *lib = dlopen(path, RTLD_NOW);
  186.73 +  if (lib == NULL) lua_pushstring(L, dlerror());
  186.74 +  return lib;
  186.75 +}
  186.76 +
  186.77 +
  186.78 +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
  186.79 +  lua_CFunction f = (lua_CFunction)dlsym(lib, sym);
  186.80 +  if (f == NULL) lua_pushstring(L, dlerror());
  186.81 +  return f;
  186.82 +}
  186.83 +
  186.84 +/* }====================================================== */
  186.85 +
  186.86 +
  186.87 +
  186.88 +#elif defined(LUA_DL_DLL)
  186.89 +/*
  186.90 +** {======================================================================
  186.91 +** This is an implementation of loadlib for Windows using native functions.
  186.92 +** =======================================================================
  186.93 +*/
  186.94 +
  186.95 +#include <windows.h>
  186.96 +
  186.97 +
  186.98 +#undef setprogdir
  186.99 +
 186.100 +static void setprogdir (lua_State *L) {
 186.101 +  char buff[MAX_PATH + 1];
 186.102 +  char *lb;
 186.103 +  DWORD nsize = sizeof(buff)/sizeof(char);
 186.104 +  DWORD n = GetModuleFileNameA(NULL, buff, nsize);
 186.105 +  if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL)
 186.106 +    luaL_error(L, "unable to get ModuleFileName");
 186.107 +  else {
 186.108 +    *lb = '\0';
 186.109 +    luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff);
 186.110 +    lua_remove(L, -2);  /* remove original string */
 186.111 +  }
 186.112 +}
 186.113 +
 186.114 +
 186.115 +static void pusherror (lua_State *L) {
 186.116 +  int error = GetLastError();
 186.117 +  char buffer[128];
 186.118 +  if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
 186.119 +      NULL, error, 0, buffer, sizeof(buffer), NULL))
 186.120 +    lua_pushstring(L, buffer);
 186.121 +  else
 186.122 +    lua_pushfstring(L, "system error %d\n", error);
 186.123 +}
 186.124 +
 186.125 +static void ll_unloadlib (void *lib) {
 186.126 +  FreeLibrary((HINSTANCE)lib);
 186.127 +}
 186.128 +
 186.129 +
 186.130 +static void *ll_load (lua_State *L, const char *path) {
 186.131 +  HINSTANCE lib = LoadLibraryA(path);
 186.132 +  if (lib == NULL) pusherror(L);
 186.133 +  return lib;
 186.134 +}
 186.135 +
 186.136 +
 186.137 +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
 186.138 +  lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym);
 186.139 +  if (f == NULL) pusherror(L);
 186.140 +  return f;
 186.141 +}
 186.142 +
 186.143 +/* }====================================================== */
 186.144 +
 186.145 +
 186.146 +
 186.147 +#elif defined(LUA_DL_DYLD)
 186.148 +/*
 186.149 +** {======================================================================
 186.150 +** Native Mac OS X / Darwin Implementation
 186.151 +** =======================================================================
 186.152 +*/
 186.153 +
 186.154 +#include <mach-o/dyld.h>
 186.155 +
 186.156 +
 186.157 +/* Mac appends a `_' before C function names */
 186.158 +#undef POF
 186.159 +#define POF	"_" LUA_POF
 186.160 +
 186.161 +
 186.162 +static void pusherror (lua_State *L) {
 186.163 +  const char *err_str;
 186.164 +  const char *err_file;
 186.165 +  NSLinkEditErrors err;
 186.166 +  int err_num;
 186.167 +  NSLinkEditError(&err, &err_num, &err_file, &err_str);
 186.168 +  lua_pushstring(L, err_str);
 186.169 +}
 186.170 +
 186.171 +
 186.172 +static const char *errorfromcode (NSObjectFileImageReturnCode ret) {
 186.173 +  switch (ret) {
 186.174 +    case NSObjectFileImageInappropriateFile:
 186.175 +      return "file is not a bundle";
 186.176 +    case NSObjectFileImageArch:
 186.177 +      return "library is for wrong CPU type";
 186.178 +    case NSObjectFileImageFormat:
 186.179 +      return "bad format";
 186.180 +    case NSObjectFileImageAccess:
 186.181 +      return "cannot access file";
 186.182 +    case NSObjectFileImageFailure:
 186.183 +    default:
 186.184 +      return "unable to load library";
 186.185 +  }
 186.186 +}
 186.187 +
 186.188 +
 186.189 +static void ll_unloadlib (void *lib) {
 186.190 +  NSUnLinkModule((NSModule)lib, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES);
 186.191 +}
 186.192 +
 186.193 +
 186.194 +static void *ll_load (lua_State *L, const char *path) {
 186.195 +  NSObjectFileImage img;
 186.196 +  NSObjectFileImageReturnCode ret;
 186.197 +  /* this would be a rare case, but prevents crashing if it happens */
 186.198 +  if(!_dyld_present()) {
 186.199 +    lua_pushliteral(L, "dyld not present");
 186.200 +    return NULL;
 186.201 +  }
 186.202 +  ret = NSCreateObjectFileImageFromFile(path, &img);
 186.203 +  if (ret == NSObjectFileImageSuccess) {
 186.204 +    NSModule mod = NSLinkModule(img, path, NSLINKMODULE_OPTION_PRIVATE |
 186.205 +                       NSLINKMODULE_OPTION_RETURN_ON_ERROR);
 186.206 +    NSDestroyObjectFileImage(img);
 186.207 +    if (mod == NULL) pusherror(L);
 186.208 +    return mod;
 186.209 +  }
 186.210 +  lua_pushstring(L, errorfromcode(ret));
 186.211 +  return NULL;
 186.212 +}
 186.213 +
 186.214 +
 186.215 +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
 186.216 +  NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym);
 186.217 +  if (nss == NULL) {
 186.218 +    lua_pushfstring(L, "symbol " LUA_QS " not found", sym);
 186.219 +    return NULL;
 186.220 +  }
 186.221 +  return (lua_CFunction)NSAddressOfSymbol(nss);
 186.222 +}
 186.223 +
 186.224 +/* }====================================================== */
 186.225 +
 186.226 +
 186.227 +
 186.228 +#else
 186.229 +/*
 186.230 +** {======================================================
 186.231 +** Fallback for other systems
 186.232 +** =======================================================
 186.233 +*/
 186.234 +
 186.235 +#undef LIB_FAIL
 186.236 +#define LIB_FAIL	"absent"
 186.237 +
 186.238 +
 186.239 +#define DLMSG	"dynamic libraries not enabled; check your Lua installation"
 186.240 +
 186.241 +
 186.242 +static void ll_unloadlib (void *lib) {
 186.243 +  (void)lib;  /* to avoid warnings */
 186.244 +}
 186.245 +
 186.246 +
 186.247 +static void *ll_load (lua_State *L, const char *path) {
 186.248 +  (void)path;  /* to avoid warnings */
 186.249 +  lua_pushliteral(L, DLMSG);
 186.250 +  return NULL;
 186.251 +}
 186.252 +
 186.253 +
 186.254 +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
 186.255 +  (void)lib; (void)sym;  /* to avoid warnings */
 186.256 +  lua_pushliteral(L, DLMSG);
 186.257 +  return NULL;
 186.258 +}
 186.259 +
 186.260 +/* }====================================================== */
 186.261 +#endif
 186.262 +
 186.263 +
 186.264 +
 186.265 +static void **ll_register (lua_State *L, const char *path) {
 186.266 +  void **plib;
 186.267 +  lua_pushfstring(L, "%s%s", LIBPREFIX, path);
 186.268 +  lua_gettable(L, LUA_REGISTRYINDEX);  /* check library in registry? */
 186.269 +  if (!lua_isnil(L, -1))  /* is there an entry? */
 186.270 +    plib = (void **)lua_touserdata(L, -1);
 186.271 +  else {  /* no entry yet; create one */
 186.272 +    lua_pop(L, 1);
 186.273 +    plib = (void **)lua_newuserdata(L, sizeof(const void *));
 186.274 +    *plib = NULL;
 186.275 +    luaL_getmetatable(L, "_LOADLIB");
 186.276 +    lua_setmetatable(L, -2);
 186.277 +    lua_pushfstring(L, "%s%s", LIBPREFIX, path);
 186.278 +    lua_pushvalue(L, -2);
 186.279 +    lua_settable(L, LUA_REGISTRYINDEX);
 186.280 +  }
 186.281 +  return plib;
 186.282 +}
 186.283 +
 186.284 +
 186.285 +/*
 186.286 +** __gc tag method: calls library's `ll_unloadlib' function with the lib
 186.287 +** handle
 186.288 +*/
 186.289 +static int gctm (lua_State *L) {
 186.290 +  void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB");
 186.291 +  if (*lib) ll_unloadlib(*lib);
 186.292 +  *lib = NULL;  /* mark library as closed */
 186.293 +  return 0;
 186.294 +}
 186.295 +
 186.296 +
 186.297 +static int ll_loadfunc (lua_State *L, const char *path, const char *sym) {
 186.298 +  void **reg = ll_register(L, path);
 186.299 +  if (*reg == NULL) *reg = ll_load(L, path);
 186.300 +  if (*reg == NULL)
 186.301 +    return ERRLIB;  /* unable to load library */
 186.302 +  else {
 186.303 +    lua_CFunction f = ll_sym(L, *reg, sym);
 186.304 +    if (f == NULL)
 186.305 +      return ERRFUNC;  /* unable to find function */
 186.306 +    lua_pushcfunction(L, f);
 186.307 +    return 0;  /* return function */
 186.308 +  }
 186.309 +}
 186.310 +
 186.311 +
 186.312 +static int ll_loadlib (lua_State *L) {
 186.313 +  const char *path = luaL_checkstring(L, 1);
 186.314 +  const char *init = luaL_checkstring(L, 2);
 186.315 +  int stat = ll_loadfunc(L, path, init);
 186.316 +  if (stat == 0)  /* no errors? */
 186.317 +    return 1;  /* return the loaded function */
 186.318 +  else {  /* error; error message is on stack top */
 186.319 +    lua_pushnil(L);
 186.320 +    lua_insert(L, -2);
 186.321 +    lua_pushstring(L, (stat == ERRLIB) ?  LIB_FAIL : "init");
 186.322 +    return 3;  /* return nil, error message, and where */
 186.323 +  }
 186.324 +}
 186.325 +
 186.326 +
 186.327 +
 186.328 +/*
 186.329 +** {======================================================
 186.330 +** 'require' function
 186.331 +** =======================================================
 186.332 +*/
 186.333 +
 186.334 +
 186.335 +static int readable (const char *filename) {
 186.336 +  FILE *f = fopen(filename, "r");  /* try to open file */
 186.337 +  if (f == NULL) return 0;  /* open failed */
 186.338 +  fclose(f);
 186.339 +  return 1;
 186.340 +}
 186.341 +
 186.342 +
 186.343 +static const char *pushnexttemplate (lua_State *L, const char *path) {
 186.344 +  const char *l;
 186.345 +  while (*path == *LUA_PATHSEP) path++;  /* skip separators */
 186.346 +  if (*path == '\0') return NULL;  /* no more templates */
 186.347 +  l = strchr(path, *LUA_PATHSEP);  /* find next separator */
 186.348 +  if (l == NULL) l = path + strlen(path);
 186.349 +  lua_pushlstring(L, path, l - path);  /* template */
 186.350 +  return l;
 186.351 +}
 186.352 +
 186.353 +
 186.354 +static const char *findfile (lua_State *L, const char *name,
 186.355 +                                           const char *pname) {
 186.356 +  const char *path;
 186.357 +  name = luaL_gsub(L, name, ".", LUA_DIRSEP);
 186.358 +  lua_getfield(L, LUA_ENVIRONINDEX, pname);
 186.359 +  path = lua_tostring(L, -1);
 186.360 +  if (path == NULL)
 186.361 +    luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
 186.362 +  lua_pushliteral(L, "");  /* error accumulator */
 186.363 +  while ((path = pushnexttemplate(L, path)) != NULL) {
 186.364 +    const char *filename;
 186.365 +    filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);
 186.366 +    lua_remove(L, -2);  /* remove path template */
 186.367 +    if (readable(filename))  /* does file exist and is readable? */
 186.368 +      return filename;  /* return that file name */
 186.369 +    lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
 186.370 +    lua_remove(L, -2);  /* remove file name */
 186.371 +    lua_concat(L, 2);  /* add entry to possible error message */
 186.372 +  }
 186.373 +  return NULL;  /* not found */
 186.374 +}
 186.375 +
 186.376 +
 186.377 +static void loaderror (lua_State *L, const char *filename) {
 186.378 +  luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s",
 186.379 +                lua_tostring(L, 1), filename, lua_tostring(L, -1));
 186.380 +}
 186.381 +
 186.382 +
 186.383 +static int loader_Lua (lua_State *L) {
 186.384 +  const char *filename;
 186.385 +  const char *name = luaL_checkstring(L, 1);
 186.386 +  filename = findfile(L, name, "path");
 186.387 +  if (filename == NULL) return 1;  /* library not found in this path */
 186.388 +  if (luaL_loadfile(L, filename) != 0)
 186.389 +    loaderror(L, filename);
 186.390 +  return 1;  /* library loaded successfully */
 186.391 +}
 186.392 +
 186.393 +
 186.394 +static const char *mkfuncname (lua_State *L, const char *modname) {
 186.395 +  const char *funcname;
 186.396 +  const char *mark = strchr(modname, *LUA_IGMARK);
 186.397 +  if (mark) modname = mark + 1;
 186.398 +  funcname = luaL_gsub(L, modname, ".", LUA_OFSEP);
 186.399 +  funcname = lua_pushfstring(L, POF"%s", funcname);
 186.400 +  lua_remove(L, -2);  /* remove 'gsub' result */
 186.401 +  return funcname;
 186.402 +}
 186.403 +
 186.404 +
 186.405 +static int loader_C (lua_State *L) {
 186.406 +  const char *funcname;
 186.407 +  const char *name = luaL_checkstring(L, 1);
 186.408 +  const char *filename = findfile(L, name, "cpath");
 186.409 +  if (filename == NULL) return 1;  /* library not found in this path */
 186.410 +  funcname = mkfuncname(L, name);
 186.411 +  if (ll_loadfunc(L, filename, funcname) != 0)
 186.412 +    loaderror(L, filename);
 186.413 +  return 1;  /* library loaded successfully */
 186.414 +}
 186.415 +
 186.416 +
 186.417 +static int loader_Croot (lua_State *L) {
 186.418 +  const char *funcname;
 186.419 +  const char *filename;
 186.420 +  const char *name = luaL_checkstring(L, 1);
 186.421 +  const char *p = strchr(name, '.');
 186.422 +  int stat;
 186.423 +  if (p == NULL) return 0;  /* is root */
 186.424 +  lua_pushlstring(L, name, p - name);
 186.425 +  filename = findfile(L, lua_tostring(L, -1), "cpath");
 186.426 +  if (filename == NULL) return 1;  /* root not found */
 186.427 +  funcname = mkfuncname(L, name);
 186.428 +  if ((stat = ll_loadfunc(L, filename, funcname)) != 0) {
 186.429 +    if (stat != ERRFUNC) loaderror(L, filename);  /* real error */
 186.430 +    lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
 186.431 +                       name, filename);
 186.432 +    return 1;  /* function not found */
 186.433 +  }
 186.434 +  return 1;
 186.435 +}
 186.436 +
 186.437 +
 186.438 +static int loader_preload (lua_State *L) {
 186.439 +  const char *name = luaL_checkstring(L, 1);
 186.440 +  lua_getfield(L, LUA_ENVIRONINDEX, "preload");
 186.441 +  if (!lua_istable(L, -1))
 186.442 +    luaL_error(L, LUA_QL("package.preload") " must be a table");
 186.443 +  lua_getfield(L, -1, name);
 186.444 +  if (lua_isnil(L, -1))  /* not found? */
 186.445 +    lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
 186.446 +  return 1;
 186.447 +}
 186.448 +
 186.449 +
 186.450 +static const int sentinel_ = 0;
 186.451 +#define sentinel	((void *)&sentinel_)
 186.452 +
 186.453 +
 186.454 +static int ll_require (lua_State *L) {
 186.455 +  const char *name = luaL_checkstring(L, 1);
 186.456 +  int i;
 186.457 +  lua_settop(L, 1);  /* _LOADED table will be at index 2 */
 186.458 +  lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
 186.459 +  lua_getfield(L, 2, name);
 186.460 +  if (lua_toboolean(L, -1)) {  /* is it there? */
 186.461 +    if (lua_touserdata(L, -1) == sentinel)  /* check loops */
 186.462 +      luaL_error(L, "loop or previous error loading module " LUA_QS, name);
 186.463 +    return 1;  /* package is already loaded */
 186.464 +  }
 186.465 +  /* else must load it; iterate over available loaders */
 186.466 +  lua_getfield(L, LUA_ENVIRONINDEX, "loaders");
 186.467 +  if (!lua_istable(L, -1))
 186.468 +    luaL_error(L, LUA_QL("package.loaders") " must be a table");
 186.469 +  lua_pushliteral(L, "");  /* error message accumulator */
 186.470 +  for (i=1; ; i++) {
 186.471 +    lua_rawgeti(L, -2, i);  /* get a loader */
 186.472 +    if (lua_isnil(L, -1))
 186.473 +      luaL_error(L, "module " LUA_QS " not found:%s",
 186.474 +                    name, lua_tostring(L, -2));
 186.475 +    lua_pushstring(L, name);
 186.476 +    lua_call(L, 1, 1);  /* call it */
 186.477 +    if (lua_isfunction(L, -1))  /* did it find module? */
 186.478 +      break;  /* module loaded successfully */
 186.479 +    else if (lua_isstring(L, -1))  /* loader returned error message? */
 186.480 +      lua_concat(L, 2);  /* accumulate it */
 186.481 +    else
 186.482 +      lua_pop(L, 1);
 186.483 +  }
 186.484 +  lua_pushlightuserdata(L, sentinel);
 186.485 +  lua_setfield(L, 2, name);  /* _LOADED[name] = sentinel */
 186.486 +  lua_pushstring(L, name);  /* pass name as argument to module */
 186.487 +  lua_call(L, 1, 1);  /* run loaded module */
 186.488 +  if (!lua_isnil(L, -1))  /* non-nil return? */
 186.489 +    lua_setfield(L, 2, name);  /* _LOADED[name] = returned value */
 186.490 +  lua_getfield(L, 2, name);
 186.491 +  if (lua_touserdata(L, -1) == sentinel) {   /* module did not set a value? */
 186.492 +    lua_pushboolean(L, 1);  /* use true as result */
 186.493 +    lua_pushvalue(L, -1);  /* extra copy to be returned */
 186.494 +    lua_setfield(L, 2, name);  /* _LOADED[name] = true */
 186.495 +  }
 186.496 +  return 1;
 186.497 +}
 186.498 +
 186.499 +/* }====================================================== */
 186.500 +
 186.501 +
 186.502 +
 186.503 +/*
 186.504 +** {======================================================
 186.505 +** 'module' function
 186.506 +** =======================================================
 186.507 +*/
 186.508 +  
 186.509 +
 186.510 +static void setfenv (lua_State *L) {
 186.511 +  lua_Debug ar;
 186.512 +  if (lua_getstack(L, 1, &ar) == 0 ||
 186.513 +      lua_getinfo(L, "f", &ar) == 0 ||  /* get calling function */
 186.514 +      lua_iscfunction(L, -1))
 186.515 +    luaL_error(L, LUA_QL("module") " not called from a Lua function");
 186.516 +  lua_pushvalue(L, -2);
 186.517 +  lua_setfenv(L, -2);
 186.518 +  lua_pop(L, 1);
 186.519 +}
 186.520 +
 186.521 +
 186.522 +static void dooptions (lua_State *L, int n) {
 186.523 +  int i;
 186.524 +  for (i = 2; i <= n; i++) {
 186.525 +    lua_pushvalue(L, i);  /* get option (a function) */
 186.526 +    lua_pushvalue(L, -2);  /* module */
 186.527 +    lua_call(L, 1, 0);
 186.528 +  }
 186.529 +}
 186.530 +
 186.531 +
 186.532 +static void modinit (lua_State *L, const char *modname) {
 186.533 +  const char *dot;
 186.534 +  lua_pushvalue(L, -1);
 186.535 +  lua_setfield(L, -2, "_M");  /* module._M = module */
 186.536 +  lua_pushstring(L, modname);
 186.537 +  lua_setfield(L, -2, "_NAME");
 186.538 +  dot = strrchr(modname, '.');  /* look for last dot in module name */
 186.539 +  if (dot == NULL) dot = modname;
 186.540 +  else dot++;
 186.541 +  /* set _PACKAGE as package name (full module name minus last part) */
 186.542 +  lua_pushlstring(L, modname, dot - modname);
 186.543 +  lua_setfield(L, -2, "_PACKAGE");
 186.544 +}
 186.545 +
 186.546 +
 186.547 +static int ll_module (lua_State *L) {
 186.548 +  const char *modname = luaL_checkstring(L, 1);
 186.549 +  int loaded = lua_gettop(L) + 1;  /* index of _LOADED table */
 186.550 +  lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
 186.551 +  lua_getfield(L, loaded, modname);  /* get _LOADED[modname] */
 186.552 +  if (!lua_istable(L, -1)) {  /* not found? */
 186.553 +    lua_pop(L, 1);  /* remove previous result */
 186.554 +    /* try global variable (and create one if it does not exist) */
 186.555 +    if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL)
 186.556 +      return luaL_error(L, "name conflict for module " LUA_QS, modname);
 186.557 +    lua_pushvalue(L, -1);
 186.558 +    lua_setfield(L, loaded, modname);  /* _LOADED[modname] = new table */
 186.559 +  }
 186.560 +  /* check whether table already has a _NAME field */
 186.561 +  lua_getfield(L, -1, "_NAME");
 186.562 +  if (!lua_isnil(L, -1))  /* is table an initialized module? */
 186.563 +    lua_pop(L, 1);
 186.564 +  else {  /* no; initialize it */
 186.565 +    lua_pop(L, 1);
 186.566 +    modinit(L, modname);
 186.567 +  }
 186.568 +  lua_pushvalue(L, -1);
 186.569 +  setfenv(L);
 186.570 +  dooptions(L, loaded - 1);
 186.571 +  return 0;
 186.572 +}
 186.573 +
 186.574 +
 186.575 +static int ll_seeall (lua_State *L) {
 186.576 +  luaL_checktype(L, 1, LUA_TTABLE);
 186.577 +  if (!lua_getmetatable(L, 1)) {
 186.578 +    lua_createtable(L, 0, 1); /* create new metatable */
 186.579 +    lua_pushvalue(L, -1);
 186.580 +    lua_setmetatable(L, 1);
 186.581 +  }
 186.582 +  lua_pushvalue(L, LUA_GLOBALSINDEX);
 186.583 +  lua_setfield(L, -2, "__index");  /* mt.__index = _G */
 186.584 +  return 0;
 186.585 +}
 186.586 +
 186.587 +
 186.588 +/* }====================================================== */
 186.589 +
 186.590 +
 186.591 +
 186.592 +/* auxiliary mark (for internal use) */
 186.593 +#define AUXMARK		"\1"
 186.594 +
 186.595 +static void setpath (lua_State *L, const char *fieldname, const char *envname,
 186.596 +                                   const char *def) {
 186.597 +  const char *path = getenv(envname);
 186.598 +  if (path == NULL)  /* no environment variable? */
 186.599 +    lua_pushstring(L, def);  /* use default */
 186.600 +  else {
 186.601 +    /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
 186.602 +    path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,
 186.603 +                              LUA_PATHSEP AUXMARK LUA_PATHSEP);
 186.604 +    luaL_gsub(L, path, AUXMARK, def);
 186.605 +    lua_remove(L, -2);
 186.606 +  }
 186.607 +  setprogdir(L);
 186.608 +  lua_setfield(L, -2, fieldname);
 186.609 +}
 186.610 +
 186.611 +
 186.612 +static const luaL_Reg pk_funcs[] = {
 186.613 +  {"loadlib", ll_loadlib},
 186.614 +  {"seeall", ll_seeall},
 186.615 +  {NULL, NULL}
 186.616 +};
 186.617 +
 186.618 +
 186.619 +static const luaL_Reg ll_funcs[] = {
 186.620 +  {"module", ll_module},
 186.621 +  {"require", ll_require},
 186.622 +  {NULL, NULL}
 186.623 +};
 186.624 +
 186.625 +
 186.626 +static const lua_CFunction loaders[] =
 186.627 +  {loader_preload, loader_Lua, loader_C, loader_Croot, NULL};
 186.628 +
 186.629 +
 186.630 +LUALIB_API int luaopen_package (lua_State *L) {
 186.631 +  int i;
 186.632 +  /* create new type _LOADLIB */
 186.633 +  luaL_newmetatable(L, "_LOADLIB");
 186.634 +  lua_pushcfunction(L, gctm);
 186.635 +  lua_setfield(L, -2, "__gc");
 186.636 +  /* create `package' table */
 186.637 +  luaL_register(L, LUA_LOADLIBNAME, pk_funcs);
 186.638 +#if defined(LUA_COMPAT_LOADLIB) 
 186.639 +  lua_getfield(L, -1, "loadlib");
 186.640 +  lua_setfield(L, LUA_GLOBALSINDEX, "loadlib");
 186.641 +#endif
 186.642 +  lua_pushvalue(L, -1);
 186.643 +  lua_replace(L, LUA_ENVIRONINDEX);
 186.644 +  /* create `loaders' table */
 186.645 +  lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1);
 186.646 +  /* fill it with pre-defined loaders */
 186.647 +  for (i=0; loaders[i] != NULL; i++) {
 186.648 +    lua_pushcfunction(L, loaders[i]);
 186.649 +    lua_rawseti(L, -2, i+1);
 186.650 +  }
 186.651 +  lua_setfield(L, -2, "loaders");  /* put it in field `loaders' */
 186.652 +  setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT);  /* set field `path' */
 186.653 +  setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */
 186.654 +  /* store config information */
 186.655 +  lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n"
 186.656 +                     LUA_EXECDIR "\n" LUA_IGMARK);
 186.657 +  lua_setfield(L, -2, "config");
 186.658 +  /* set field `loaded' */
 186.659 +  luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2);
 186.660 +  lua_setfield(L, -2, "loaded");
 186.661 +  /* set field `preload' */
 186.662 +  lua_newtable(L);
 186.663 +  lua_setfield(L, -2, "preload");
 186.664 +  lua_pushvalue(L, LUA_GLOBALSINDEX);
 186.665 +  luaL_register(L, NULL, ll_funcs);  /* open lib into global table */
 186.666 +  lua_pop(L, 1);
 186.667 +  return 1;  /* return 'package' table */
 186.668 +}
 186.669 +
   187.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   187.2 +++ b/src/lua/src/lobject.c	Sat Mar 03 10:31:27 2012 -0600
   187.3 @@ -0,0 +1,214 @@
   187.4 +/*
   187.5 +** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $
   187.6 +** Some generic functions over Lua objects
   187.7 +** See Copyright Notice in lua.h
   187.8 +*/
   187.9 +
  187.10 +#include <ctype.h>
  187.11 +#include <stdarg.h>
  187.12 +#include <stdio.h>
  187.13 +#include <stdlib.h>
  187.14 +#include <string.h>
  187.15 +
  187.16 +#define lobject_c
  187.17 +#define LUA_CORE
  187.18 +
  187.19 +#include "lua.h"
  187.20 +
  187.21 +#include "ldo.h"
  187.22 +#include "lmem.h"
  187.23 +#include "lobject.h"
  187.24 +#include "lstate.h"
  187.25 +#include "lstring.h"
  187.26 +#include "lvm.h"
  187.27 +
  187.28 +
  187.29 +
  187.30 +const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL};
  187.31 +
  187.32 +
  187.33 +/*
  187.34 +** converts an integer to a "floating point byte", represented as
  187.35 +** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if
  187.36 +** eeeee != 0 and (xxx) otherwise.
  187.37 +*/
  187.38 +int luaO_int2fb (unsigned int x) {
  187.39 +  int e = 0;  /* expoent */
  187.40 +  while (x >= 16) {
  187.41 +    x = (x+1) >> 1;
  187.42 +    e++;
  187.43 +  }
  187.44 +  if (x < 8) return x;
  187.45 +  else return ((e+1) << 3) | (cast_int(x) - 8);
  187.46 +}
  187.47 +
  187.48 +
  187.49 +/* converts back */
  187.50 +int luaO_fb2int (int x) {
  187.51 +  int e = (x >> 3) & 31;
  187.52 +  if (e == 0) return x;
  187.53 +  else return ((x & 7)+8) << (e - 1);
  187.54 +}
  187.55 +
  187.56 +
  187.57 +int luaO_log2 (unsigned int x) {
  187.58 +  static const lu_byte log_2[256] = {
  187.59 +    0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
  187.60 +    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
  187.61 +    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
  187.62 +    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
  187.63 +    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
  187.64 +    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
  187.65 +    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
  187.66 +    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
  187.67 +  };
  187.68 +  int l = -1;
  187.69 +  while (x >= 256) { l += 8; x >>= 8; }
  187.70 +  return l + log_2[x];
  187.71 +
  187.72 +}
  187.73 +
  187.74 +
  187.75 +int luaO_rawequalObj (const TValue *t1, const TValue *t2) {
  187.76 +  if (ttype(t1) != ttype(t2)) return 0;
  187.77 +  else switch (ttype(t1)) {
  187.78 +    case LUA_TNIL:
  187.79 +      return 1;
  187.80 +    case LUA_TNUMBER:
  187.81 +      return luai_numeq(nvalue(t1), nvalue(t2));
  187.82 +    case LUA_TBOOLEAN:
  187.83 +      return bvalue(t1) == bvalue(t2);  /* boolean true must be 1 !! */
  187.84 +    case LUA_TLIGHTUSERDATA:
  187.85 +      return pvalue(t1) == pvalue(t2);
  187.86 +    default:
  187.87 +      lua_assert(iscollectable(t1));
  187.88 +      return gcvalue(t1) == gcvalue(t2);
  187.89 +  }
  187.90 +}
  187.91 +
  187.92 +
  187.93 +int luaO_str2d (const char *s, lua_Number *result) {
  187.94 +  char *endptr;
  187.95 +  *result = lua_str2number(s, &endptr);
  187.96 +  if (endptr == s) return 0;  /* conversion failed */
  187.97 +  if (*endptr == 'x' || *endptr == 'X')  /* maybe an hexadecimal constant? */
  187.98 +    *result = cast_num(strtoul(s, &endptr, 16));
  187.99 +  if (*endptr == '\0') return 1;  /* most common case */
 187.100 +  while (isspace(cast(unsigned char, *endptr))) endptr++;
 187.101 +  if (*endptr != '\0') return 0;  /* invalid trailing characters? */
 187.102 +  return 1;
 187.103 +}
 187.104 +
 187.105 +
 187.106 +
 187.107 +static void pushstr (lua_State *L, const char *str) {
 187.108 +  setsvalue2s(L, L->top, luaS_new(L, str));
 187.109 +  incr_top(L);
 187.110 +}
 187.111 +
 187.112 +
 187.113 +/* this function handles only `%d', `%c', %f, %p, and `%s' formats */
 187.114 +const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
 187.115 +  int n = 1;
 187.116 +  pushstr(L, "");
 187.117 +  for (;;) {
 187.118 +    const char *e = strchr(fmt, '%');
 187.119 +    if (e == NULL) break;
 187.120 +    setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt));
 187.121 +    incr_top(L);
 187.122 +    switch (*(e+1)) {
 187.123 +      case 's': {
 187.124 +        const char *s = va_arg(argp, char *);
 187.125 +        if (s == NULL) s = "(null)";
 187.126 +        pushstr(L, s);
 187.127 +        break;
 187.128 +      }
 187.129 +      case 'c': {
 187.130 +        char buff[2];
 187.131 +        buff[0] = cast(char, va_arg(argp, int));
 187.132 +        buff[1] = '\0';
 187.133 +        pushstr(L, buff);
 187.134 +        break;
 187.135 +      }
 187.136 +      case 'd': {
 187.137 +        setnvalue(L->top, cast_num(va_arg(argp, int)));
 187.138 +        incr_top(L);
 187.139 +        break;
 187.140 +      }
 187.141 +      case 'f': {
 187.142 +        setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));
 187.143 +        incr_top(L);
 187.144 +        break;
 187.145 +      }
 187.146 +      case 'p': {
 187.147 +        char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */
 187.148 +        sprintf(buff, "%p", va_arg(argp, void *));
 187.149 +        pushstr(L, buff);
 187.150 +        break;
 187.151 +      }
 187.152 +      case '%': {
 187.153 +        pushstr(L, "%");
 187.154 +        break;
 187.155 +      }
 187.156 +      default: {
 187.157 +        char buff[3];
 187.158 +        buff[0] = '%';
 187.159 +        buff[1] = *(e+1);
 187.160 +        buff[2] = '\0';
 187.161 +        pushstr(L, buff);
 187.162 +        break;
 187.163 +      }
 187.164 +    }
 187.165 +    n += 2;
 187.166 +    fmt = e+2;
 187.167 +  }
 187.168 +  pushstr(L, fmt);
 187.169 +  luaV_concat(L, n+1, cast_int(L->top - L->base) - 1);
 187.170 +  L->top -= n;
 187.171 +  return svalue(L->top - 1);
 187.172 +}
 187.173 +
 187.174 +
 187.175 +const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {
 187.176 +  const char *msg;
 187.177 +  va_list argp;
 187.178 +  va_start(argp, fmt);
 187.179 +  msg = luaO_pushvfstring(L, fmt, argp);
 187.180 +  va_end(argp);
 187.181 +  return msg;
 187.182 +}
 187.183 +
 187.184 +
 187.185 +void luaO_chunkid (char *out, const char *source, size_t bufflen) {
 187.186 +  if (*source == '=') {
 187.187 +    strncpy(out, source+1, bufflen);  /* remove first char */
 187.188 +    out[bufflen-1] = '\0';  /* ensures null termination */
 187.189 +  }
 187.190 +  else {  /* out = "source", or "...source" */
 187.191 +    if (*source == '@') {
 187.192 +      size_t l;
 187.193 +      source++;  /* skip the `@' */
 187.194 +      bufflen -= sizeof(" '...' ");
 187.195 +      l = strlen(source);
 187.196 +      strcpy(out, "");
 187.197 +      if (l > bufflen) {
 187.198 +        source += (l-bufflen);  /* get last part of file name */
 187.199 +        strcat(out, "...");
 187.200 +      }
 187.201 +      strcat(out, source);
 187.202 +    }
 187.203 +    else {  /* out = [string "string"] */
 187.204 +      size_t len = strcspn(source, "\n\r");  /* stop at first newline */
 187.205 +      bufflen -= sizeof(" [string \"...\"] ");
 187.206 +      if (len > bufflen) len = bufflen;
 187.207 +      strcpy(out, "[string \"");
 187.208 +      if (source[len] != '\0') {  /* must truncate? */
 187.209 +        strncat(out, source, len);
 187.210 +        strcat(out, "...");
 187.211 +      }
 187.212 +      else
 187.213 +        strcat(out, source);
 187.214 +      strcat(out, "\"]");
 187.215 +    }
 187.216 +  }
 187.217 +}
   188.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   188.2 +++ b/src/lua/src/lobject.h	Sat Mar 03 10:31:27 2012 -0600
   188.3 @@ -0,0 +1,381 @@
   188.4 +/*
   188.5 +** $Id: lobject.h,v 2.20.1.2 2008/08/06 13:29:48 roberto Exp $
   188.6 +** Type definitions for Lua objects
   188.7 +** See Copyright Notice in lua.h
   188.8 +*/
   188.9 +
  188.10 +
  188.11 +#ifndef lobject_h
  188.12 +#define lobject_h
  188.13 +
  188.14 +
  188.15 +#include <stdarg.h>
  188.16 +
  188.17 +
  188.18 +#include "llimits.h"
  188.19 +#include "lua.h"
  188.20 +
  188.21 +
  188.22 +/* tags for values visible from Lua */
  188.23 +#define LAST_TAG	LUA_TTHREAD
  188.24 +
  188.25 +#define NUM_TAGS	(LAST_TAG+1)
  188.26 +
  188.27 +
  188.28 +/*
  188.29 +** Extra tags for non-values
  188.30 +*/
  188.31 +#define LUA_TPROTO	(LAST_TAG+1)
  188.32 +#define LUA_TUPVAL	(LAST_TAG+2)
  188.33 +#define LUA_TDEADKEY	(LAST_TAG+3)
  188.34 +
  188.35 +
  188.36 +/*
  188.37 +** Union of all collectable objects
  188.38 +*/
  188.39 +typedef union GCObject GCObject;
  188.40 +
  188.41 +
  188.42 +/*
  188.43 +** Common Header for all collectable objects (in macro form, to be
  188.44 +** included in other objects)
  188.45 +*/
  188.46 +#define CommonHeader	GCObject *next; lu_byte tt; lu_byte marked
  188.47 +
  188.48 +
  188.49 +/*
  188.50 +** Common header in struct form
  188.51 +*/
  188.52 +typedef struct GCheader {
  188.53 +  CommonHeader;
  188.54 +} GCheader;
  188.55 +
  188.56 +
  188.57 +
  188.58 +
  188.59 +/*
  188.60 +** Union of all Lua values
  188.61 +*/
  188.62 +typedef union {
  188.63 +  GCObject *gc;
  188.64 +  void *p;
  188.65 +  lua_Number n;
  188.66 +  int b;
  188.67 +} Value;
  188.68 +
  188.69 +
  188.70 +/*
  188.71 +** Tagged Values
  188.72 +*/
  188.73 +
  188.74 +#define TValuefields	Value value; int tt
  188.75 +
  188.76 +typedef struct lua_TValue {
  188.77 +  TValuefields;
  188.78 +} TValue;
  188.79 +
  188.80 +
  188.81 +/* Macros to test type */
  188.82 +#define ttisnil(o)	(ttype(o) == LUA_TNIL)
  188.83 +#define ttisnumber(o)	(ttype(o) == LUA_TNUMBER)
  188.84 +#define ttisstring(o)	(ttype(o) == LUA_TSTRING)
  188.85 +#define ttistable(o)	(ttype(o) == LUA_TTABLE)
  188.86 +#define ttisfunction(o)	(ttype(o) == LUA_TFUNCTION)
  188.87 +#define ttisboolean(o)	(ttype(o) == LUA_TBOOLEAN)
  188.88 +#define ttisuserdata(o)	(ttype(o) == LUA_TUSERDATA)
  188.89 +#define ttisthread(o)	(ttype(o) == LUA_TTHREAD)
  188.90 +#define ttislightuserdata(o)	(ttype(o) == LUA_TLIGHTUSERDATA)
  188.91 +
  188.92 +/* Macros to access values */
  188.93 +#define ttype(o)	((o)->tt)
  188.94 +#define gcvalue(o)	check_exp(iscollectable(o), (o)->value.gc)
  188.95 +#define pvalue(o)	check_exp(ttislightuserdata(o), (o)->value.p)
  188.96 +#define nvalue(o)	check_exp(ttisnumber(o), (o)->value.n)
  188.97 +#define rawtsvalue(o)	check_exp(ttisstring(o), &(o)->value.gc->ts)
  188.98 +#define tsvalue(o)	(&rawtsvalue(o)->tsv)
  188.99 +#define rawuvalue(o)	check_exp(ttisuserdata(o), &(o)->value.gc->u)
 188.100 +#define uvalue(o)	(&rawuvalue(o)->uv)
 188.101 +#define clvalue(o)	check_exp(ttisfunction(o), &(o)->value.gc->cl)
 188.102 +#define hvalue(o)	check_exp(ttistable(o), &(o)->value.gc->h)
 188.103 +#define bvalue(o)	check_exp(ttisboolean(o), (o)->value.b)
 188.104 +#define thvalue(o)	check_exp(ttisthread(o), &(o)->value.gc->th)
 188.105 +
 188.106 +#define l_isfalse(o)	(ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
 188.107 +
 188.108 +/*
 188.109 +** for internal debug only
 188.110 +*/
 188.111 +#define checkconsistency(obj) \
 188.112 +  lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt))
 188.113 +
 188.114 +#define checkliveness(g,obj) \
 188.115 +  lua_assert(!iscollectable(obj) || \
 188.116 +  ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc)))
 188.117 +
 188.118 +
 188.119 +/* Macros to set values */
 188.120 +#define setnilvalue(obj) ((obj)->tt=LUA_TNIL)
 188.121 +
 188.122 +#define setnvalue(obj,x) \
 188.123 +  { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; }
 188.124 +
 188.125 +#define setpvalue(obj,x) \
 188.126 +  { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; }
 188.127 +
 188.128 +#define setbvalue(obj,x) \
 188.129 +  { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; }
 188.130 +
 188.131 +#define setsvalue(L,obj,x) \
 188.132 +  { TValue *i_o=(obj); \
 188.133 +    i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \
 188.134 +    checkliveness(G(L),i_o); }
 188.135 +
 188.136 +#define setuvalue(L,obj,x) \
 188.137 +  { TValue *i_o=(obj); \
 188.138 +    i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \
 188.139 +    checkliveness(G(L),i_o); }
 188.140 +
 188.141 +#define setthvalue(L,obj,x) \
 188.142 +  { TValue *i_o=(obj); \
 188.143 +    i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \
 188.144 +    checkliveness(G(L),i_o); }
 188.145 +
 188.146 +#define setclvalue(L,obj,x) \
 188.147 +  { TValue *i_o=(obj); \
 188.148 +    i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \
 188.149 +    checkliveness(G(L),i_o); }
 188.150 +
 188.151 +#define sethvalue(L,obj,x) \
 188.152 +  { TValue *i_o=(obj); \
 188.153 +    i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \
 188.154 +    checkliveness(G(L),i_o); }
 188.155 +
 188.156 +#define setptvalue(L,obj,x) \
 188.157 +  { TValue *i_o=(obj); \
 188.158 +    i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \
 188.159 +    checkliveness(G(L),i_o); }
 188.160 +
 188.161 +
 188.162 +
 188.163 +
 188.164 +#define setobj(L,obj1,obj2) \
 188.165 +  { const TValue *o2=(obj2); TValue *o1=(obj1); \
 188.166 +    o1->value = o2->value; o1->tt=o2->tt; \
 188.167 +    checkliveness(G(L),o1); }
 188.168 +
 188.169 +
 188.170 +/*
 188.171 +** different types of sets, according to destination
 188.172 +*/
 188.173 +
 188.174 +/* from stack to (same) stack */
 188.175 +#define setobjs2s	setobj
 188.176 +/* to stack (not from same stack) */
 188.177 +#define setobj2s	setobj
 188.178 +#define setsvalue2s	setsvalue
 188.179 +#define sethvalue2s	sethvalue
 188.180 +#define setptvalue2s	setptvalue
 188.181 +/* from table to same table */
 188.182 +#define setobjt2t	setobj
 188.183 +/* to table */
 188.184 +#define setobj2t	setobj
 188.185 +/* to new object */
 188.186 +#define setobj2n	setobj
 188.187 +#define setsvalue2n	setsvalue
 188.188 +
 188.189 +#define setttype(obj, tt) (ttype(obj) = (tt))
 188.190 +
 188.191 +
 188.192 +#define iscollectable(o)	(ttype(o) >= LUA_TSTRING)
 188.193 +
 188.194 +
 188.195 +
 188.196 +typedef TValue *StkId;  /* index to stack elements */
 188.197 +
 188.198 +
 188.199 +/*
 188.200 +** String headers for string table
 188.201 +*/
 188.202 +typedef union TString {
 188.203 +  L_Umaxalign dummy;  /* ensures maximum alignment for strings */
 188.204 +  struct {
 188.205 +    CommonHeader;
 188.206 +    lu_byte reserved;
 188.207 +    unsigned int hash;
 188.208 +    size_t len;
 188.209 +  } tsv;
 188.210 +} TString;
 188.211 +
 188.212 +
 188.213 +#define getstr(ts)	cast(const char *, (ts) + 1)
 188.214 +#define svalue(o)       getstr(rawtsvalue(o))
 188.215 +
 188.216 +
 188.217 +
 188.218 +typedef union Udata {
 188.219 +  L_Umaxalign dummy;  /* ensures maximum alignment for `local' udata */
 188.220 +  struct {
 188.221 +    CommonHeader;
 188.222 +    struct Table *metatable;
 188.223 +    struct Table *env;
 188.224 +    size_t len;
 188.225 +  } uv;
 188.226 +} Udata;
 188.227 +
 188.228 +
 188.229 +
 188.230 +
 188.231 +/*
 188.232 +** Function Prototypes
 188.233 +*/
 188.234 +typedef struct Proto {
 188.235 +  CommonHeader;
 188.236 +  TValue *k;  /* constants used by the function */
 188.237 +  Instruction *code;
 188.238 +  struct Proto **p;  /* functions defined inside the function */
 188.239 +  int *lineinfo;  /* map from opcodes to source lines */
 188.240 +  struct LocVar *locvars;  /* information about local variables */
 188.241 +  TString **upvalues;  /* upvalue names */
 188.242 +  TString  *source;
 188.243 +  int sizeupvalues;
 188.244 +  int sizek;  /* size of `k' */
 188.245 +  int sizecode;
 188.246 +  int sizelineinfo;
 188.247 +  int sizep;  /* size of `p' */
 188.248 +  int sizelocvars;
 188.249 +  int linedefined;
 188.250 +  int lastlinedefined;
 188.251 +  GCObject *gclist;
 188.252 +  lu_byte nups;  /* number of upvalues */
 188.253 +  lu_byte numparams;
 188.254 +  lu_byte is_vararg;
 188.255 +  lu_byte maxstacksize;
 188.256 +} Proto;
 188.257 +
 188.258 +
 188.259 +/* masks for new-style vararg */
 188.260 +#define VARARG_HASARG		1
 188.261 +#define VARARG_ISVARARG		2
 188.262 +#define VARARG_NEEDSARG		4
 188.263 +
 188.264 +
 188.265 +typedef struct LocVar {
 188.266 +  TString *varname;
 188.267 +  int startpc;  /* first point where variable is active */
 188.268 +  int endpc;    /* first point where variable is dead */
 188.269 +} LocVar;
 188.270 +
 188.271 +
 188.272 +
 188.273 +/*
 188.274 +** Upvalues
 188.275 +*/
 188.276 +
 188.277 +typedef struct UpVal {
 188.278 +  CommonHeader;
 188.279 +  TValue *v;  /* points to stack or to its own value */
 188.280 +  union {
 188.281 +    TValue value;  /* the value (when closed) */
 188.282 +    struct {  /* double linked list (when open) */
 188.283 +      struct UpVal *prev;
 188.284 +      struct UpVal *next;
 188.285 +    } l;
 188.286 +  } u;
 188.287 +} UpVal;
 188.288 +
 188.289 +
 188.290 +/*
 188.291 +** Closures
 188.292 +*/
 188.293 +
 188.294 +#define ClosureHeader \
 188.295 +	CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \
 188.296 +	struct Table *env
 188.297 +
 188.298 +typedef struct CClosure {
 188.299 +  ClosureHeader;
 188.300 +  lua_CFunction f;
 188.301 +  TValue upvalue[1];
 188.302 +} CClosure;
 188.303 +
 188.304 +
 188.305 +typedef struct LClosure {
 188.306 +  ClosureHeader;
 188.307 +  struct Proto *p;
 188.308 +  UpVal *upvals[1];
 188.309 +} LClosure;
 188.310 +
 188.311 +
 188.312 +typedef union Closure {
 188.313 +  CClosure c;
 188.314 +  LClosure l;
 188.315 +} Closure;
 188.316 +
 188.317 +
 188.318 +#define iscfunction(o)	(ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC)
 188.319 +#define isLfunction(o)	(ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC)
 188.320 +
 188.321 +
 188.322 +/*
 188.323 +** Tables
 188.324 +*/
 188.325 +
 188.326 +typedef union TKey {
 188.327 +  struct {
 188.328 +    TValuefields;
 188.329 +    struct Node *next;  /* for chaining */
 188.330 +  } nk;
 188.331 +  TValue tvk;
 188.332 +} TKey;
 188.333 +
 188.334 +
 188.335 +typedef struct Node {
 188.336 +  TValue i_val;
 188.337 +  TKey i_key;
 188.338 +} Node;
 188.339 +
 188.340 +
 188.341 +typedef struct Table {
 188.342 +  CommonHeader;
 188.343 +  lu_byte flags;  /* 1<<p means tagmethod(p) is not present */ 
 188.344 +  lu_byte lsizenode;  /* log2 of size of `node' array */
 188.345 +  struct Table *metatable;
 188.346 +  TValue *array;  /* array part */
 188.347 +  Node *node;
 188.348 +  Node *lastfree;  /* any free position is before this position */
 188.349 +  GCObject *gclist;
 188.350 +  int sizearray;  /* size of `array' array */
 188.351 +} Table;
 188.352 +
 188.353 +
 188.354 +
 188.355 +/*
 188.356 +** `module' operation for hashing (size is always a power of 2)
 188.357 +*/
 188.358 +#define lmod(s,size) \
 188.359 +	(check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))))
 188.360 +
 188.361 +
 188.362 +#define twoto(x)	(1<<(x))
 188.363 +#define sizenode(t)	(twoto((t)->lsizenode))
 188.364 +
 188.365 +
 188.366 +#define luaO_nilobject		(&luaO_nilobject_)
 188.367 +
 188.368 +LUAI_DATA const TValue luaO_nilobject_;
 188.369 +
 188.370 +#define ceillog2(x)	(luaO_log2((x)-1) + 1)
 188.371 +
 188.372 +LUAI_FUNC int luaO_log2 (unsigned int x);
 188.373 +LUAI_FUNC int luaO_int2fb (unsigned int x);
 188.374 +LUAI_FUNC int luaO_fb2int (int x);
 188.375 +LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2);
 188.376 +LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result);
 188.377 +LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,
 188.378 +                                                       va_list argp);
 188.379 +LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);
 188.380 +LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);
 188.381 +
 188.382 +
 188.383 +#endif
 188.384 +
   189.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   189.2 +++ b/src/lua/src/lopcodes.c	Sat Mar 03 10:31:27 2012 -0600
   189.3 @@ -0,0 +1,102 @@
   189.4 +/*
   189.5 +** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $
   189.6 +** See Copyright Notice in lua.h
   189.7 +*/
   189.8 +
   189.9 +
  189.10 +#define lopcodes_c
  189.11 +#define LUA_CORE
  189.12 +
  189.13 +
  189.14 +#include "lopcodes.h"
  189.15 +
  189.16 +
  189.17 +/* ORDER OP */
  189.18 +
  189.19 +const char *const luaP_opnames[NUM_OPCODES+1] = {
  189.20 +  "MOVE",
  189.21 +  "LOADK",
  189.22 +  "LOADBOOL",
  189.23 +  "LOADNIL",
  189.24 +  "GETUPVAL",
  189.25 +  "GETGLOBAL",
  189.26 +  "GETTABLE",
  189.27 +  "SETGLOBAL",
  189.28 +  "SETUPVAL",
  189.29 +  "SETTABLE",
  189.30 +  "NEWTABLE",
  189.31 +  "SELF",
  189.32 +  "ADD",
  189.33 +  "SUB",
  189.34 +  "MUL",
  189.35 +  "DIV",
  189.36 +  "MOD",
  189.37 +  "POW",
  189.38 +  "UNM",
  189.39 +  "NOT",
  189.40 +  "LEN",
  189.41 +  "CONCAT",
  189.42 +  "JMP",
  189.43 +  "EQ",
  189.44 +  "LT",
  189.45 +  "LE",
  189.46 +  "TEST",
  189.47 +  "TESTSET",
  189.48 +  "CALL",
  189.49 +  "TAILCALL",
  189.50 +  "RETURN",
  189.51 +  "FORLOOP",
  189.52 +  "FORPREP",
  189.53 +  "TFORLOOP",
  189.54 +  "SETLIST",
  189.55 +  "CLOSE",
  189.56 +  "CLOSURE",
  189.57 +  "VARARG",
  189.58 +  NULL
  189.59 +};
  189.60 +
  189.61 +
  189.62 +#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m))
  189.63 +
  189.64 +const lu_byte luaP_opmodes[NUM_OPCODES] = {
  189.65 +/*       T  A    B       C     mode		   opcode	*/
  189.66 +  opmode(0, 1, OpArgR, OpArgN, iABC) 		/* OP_MOVE */
  189.67 + ,opmode(0, 1, OpArgK, OpArgN, iABx)		/* OP_LOADK */
  189.68 + ,opmode(0, 1, OpArgU, OpArgU, iABC)		/* OP_LOADBOOL */
  189.69 + ,opmode(0, 1, OpArgR, OpArgN, iABC)		/* OP_LOADNIL */
  189.70 + ,opmode(0, 1, OpArgU, OpArgN, iABC)		/* OP_GETUPVAL */
  189.71 + ,opmode(0, 1, OpArgK, OpArgN, iABx)		/* OP_GETGLOBAL */
  189.72 + ,opmode(0, 1, OpArgR, OpArgK, iABC)		/* OP_GETTABLE */
  189.73 + ,opmode(0, 0, OpArgK, OpArgN, iABx)		/* OP_SETGLOBAL */
  189.74 + ,opmode(0, 0, OpArgU, OpArgN, iABC)		/* OP_SETUPVAL */
  189.75 + ,opmode(0, 0, OpArgK, OpArgK, iABC)		/* OP_SETTABLE */
  189.76 + ,opmode(0, 1, OpArgU, OpArgU, iABC)		/* OP_NEWTABLE */
  189.77 + ,opmode(0, 1, OpArgR, OpArgK, iABC)		/* OP_SELF */
  189.78 + ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_ADD */
  189.79 + ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_SUB */
  189.80 + ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_MUL */
  189.81 + ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_DIV */
  189.82 + ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_MOD */
  189.83 + ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_POW */
  189.84 + ,opmode(0, 1, OpArgR, OpArgN, iABC)		/* OP_UNM */
  189.85 + ,opmode(0, 1, OpArgR, OpArgN, iABC)		/* OP_NOT */
  189.86 + ,opmode(0, 1, OpArgR, OpArgN, iABC)		/* OP_LEN */
  189.87 + ,opmode(0, 1, OpArgR, OpArgR, iABC)		/* OP_CONCAT */
  189.88 + ,opmode(0, 0, OpArgR, OpArgN, iAsBx)		/* OP_JMP */
  189.89 + ,opmode(1, 0, OpArgK, OpArgK, iABC)		/* OP_EQ */
  189.90 + ,opmode(1, 0, OpArgK, OpArgK, iABC)		/* OP_LT */
  189.91 + ,opmode(1, 0, OpArgK, OpArgK, iABC)		/* OP_LE */
  189.92 + ,opmode(1, 1, OpArgR, OpArgU, iABC)		/* OP_TEST */
  189.93 + ,opmode(1, 1, OpArgR, OpArgU, iABC)		/* OP_TESTSET */
  189.94 + ,opmode(0, 1, OpArgU, OpArgU, iABC)		/* OP_CALL */
  189.95 + ,opmode(0, 1, OpArgU, OpArgU, iABC)		/* OP_TAILCALL */
  189.96 + ,opmode(0, 0, OpArgU, OpArgN, iABC)		/* OP_RETURN */
  189.97 + ,opmode(0, 1, OpArgR, OpArgN, iAsBx)		/* OP_FORLOOP */
  189.98 + ,opmode(0, 1, OpArgR, OpArgN, iAsBx)		/* OP_FORPREP */
  189.99 + ,opmode(1, 0, OpArgN, OpArgU, iABC)		/* OP_TFORLOOP */
 189.100 + ,opmode(0, 0, OpArgU, OpArgU, iABC)		/* OP_SETLIST */
 189.101 + ,opmode(0, 0, OpArgN, OpArgN, iABC)		/* OP_CLOSE */
 189.102 + ,opmode(0, 1, OpArgU, OpArgN, iABx)		/* OP_CLOSURE */
 189.103 + ,opmode(0, 1, OpArgU, OpArgN, iABC)		/* OP_VARARG */
 189.104 +};
 189.105 +
   190.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   190.2 +++ b/src/lua/src/lopcodes.h	Sat Mar 03 10:31:27 2012 -0600
   190.3 @@ -0,0 +1,268 @@
   190.4 +/*
   190.5 +** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $
   190.6 +** Opcodes for Lua virtual machine
   190.7 +** See Copyright Notice in lua.h
   190.8 +*/
   190.9 +
  190.10 +#ifndef lopcodes_h
  190.11 +#define lopcodes_h
  190.12 +
  190.13 +#include "llimits.h"
  190.14 +
  190.15 +
  190.16 +/*===========================================================================
  190.17 +  We assume that instructions are unsigned numbers.
  190.18 +  All instructions have an opcode in the first 6 bits.
  190.19 +  Instructions can have the following fields:
  190.20 +	`A' : 8 bits
  190.21 +	`B' : 9 bits
  190.22 +	`C' : 9 bits
  190.23 +	`Bx' : 18 bits (`B' and `C' together)
  190.24 +	`sBx' : signed Bx
  190.25 +
  190.26 +  A signed argument is represented in excess K; that is, the number
  190.27 +  value is the unsigned value minus K. K is exactly the maximum value
  190.28 +  for that argument (so that -max is represented by 0, and +max is
  190.29 +  represented by 2*max), which is half the maximum for the corresponding
  190.30 +  unsigned argument.
  190.31 +===========================================================================*/
  190.32 +
  190.33 +
  190.34 +enum OpMode {iABC, iABx, iAsBx};  /* basic instruction format */
  190.35 +
  190.36 +
  190.37 +/*
  190.38 +** size and position of opcode arguments.
  190.39 +*/
  190.40 +#define SIZE_C		9
  190.41 +#define SIZE_B		9
  190.42 +#define SIZE_Bx		(SIZE_C + SIZE_B)
  190.43 +#define SIZE_A		8
  190.44 +
  190.45 +#define SIZE_OP		6
  190.46 +
  190.47 +#define POS_OP		0
  190.48 +#define POS_A		(POS_OP + SIZE_OP)
  190.49 +#define POS_C		(POS_A + SIZE_A)
  190.50 +#define POS_B		(POS_C + SIZE_C)
  190.51 +#define POS_Bx		POS_C
  190.52 +
  190.53 +
  190.54 +/*
  190.55 +** limits for opcode arguments.
  190.56 +** we use (signed) int to manipulate most arguments,
  190.57 +** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)
  190.58 +*/
  190.59 +#if SIZE_Bx < LUAI_BITSINT-1
  190.60 +#define MAXARG_Bx        ((1<<SIZE_Bx)-1)
  190.61 +#define MAXARG_sBx        (MAXARG_Bx>>1)         /* `sBx' is signed */
  190.62 +#else
  190.63 +#define MAXARG_Bx        MAX_INT
  190.64 +#define MAXARG_sBx        MAX_INT
  190.65 +#endif
  190.66 +
  190.67 +
  190.68 +#define MAXARG_A        ((1<<SIZE_A)-1)
  190.69 +#define MAXARG_B        ((1<<SIZE_B)-1)
  190.70 +#define MAXARG_C        ((1<<SIZE_C)-1)
  190.71 +
  190.72 +
  190.73 +/* creates a mask with `n' 1 bits at position `p' */
  190.74 +#define MASK1(n,p)	((~((~(Instruction)0)<<n))<<p)
  190.75 +
  190.76 +/* creates a mask with `n' 0 bits at position `p' */
  190.77 +#define MASK0(n,p)	(~MASK1(n,p))
  190.78 +
  190.79 +/*
  190.80 +** the following macros help to manipulate instructions
  190.81 +*/
  190.82 +
  190.83 +#define GET_OPCODE(i)	(cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))
  190.84 +#define SET_OPCODE(i,o)	((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
  190.85 +		((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))
  190.86 +
  190.87 +#define GETARG_A(i)	(cast(int, ((i)>>POS_A) & MASK1(SIZE_A,0)))
  190.88 +#define SETARG_A(i,u)	((i) = (((i)&MASK0(SIZE_A,POS_A)) | \
  190.89 +		((cast(Instruction, u)<<POS_A)&MASK1(SIZE_A,POS_A))))
  190.90 +
  190.91 +#define GETARG_B(i)	(cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0)))
  190.92 +#define SETARG_B(i,b)	((i) = (((i)&MASK0(SIZE_B,POS_B)) | \
  190.93 +		((cast(Instruction, b)<<POS_B)&MASK1(SIZE_B,POS_B))))
  190.94 +
  190.95 +#define GETARG_C(i)	(cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0)))
  190.96 +#define SETARG_C(i,b)	((i) = (((i)&MASK0(SIZE_C,POS_C)) | \
  190.97 +		((cast(Instruction, b)<<POS_C)&MASK1(SIZE_C,POS_C))))
  190.98 +
  190.99 +#define GETARG_Bx(i)	(cast(int, ((i)>>POS_Bx) & MASK1(SIZE_Bx,0)))
 190.100 +#define SETARG_Bx(i,b)	((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \
 190.101 +		((cast(Instruction, b)<<POS_Bx)&MASK1(SIZE_Bx,POS_Bx))))
 190.102 +
 190.103 +#define GETARG_sBx(i)	(GETARG_Bx(i)-MAXARG_sBx)
 190.104 +#define SETARG_sBx(i,b)	SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))
 190.105 +
 190.106 +
 190.107 +#define CREATE_ABC(o,a,b,c)	((cast(Instruction, o)<<POS_OP) \
 190.108 +			| (cast(Instruction, a)<<POS_A) \
 190.109 +			| (cast(Instruction, b)<<POS_B) \
 190.110 +			| (cast(Instruction, c)<<POS_C))
 190.111 +
 190.112 +#define CREATE_ABx(o,a,bc)	((cast(Instruction, o)<<POS_OP) \
 190.113 +			| (cast(Instruction, a)<<POS_A) \
 190.114 +			| (cast(Instruction, bc)<<POS_Bx))
 190.115 +
 190.116 +
 190.117 +/*
 190.118 +** Macros to operate RK indices
 190.119 +*/
 190.120 +
 190.121 +/* this bit 1 means constant (0 means register) */
 190.122 +#define BITRK		(1 << (SIZE_B - 1))
 190.123 +
 190.124 +/* test whether value is a constant */
 190.125 +#define ISK(x)		((x) & BITRK)
 190.126 +
 190.127 +/* gets the index of the constant */
 190.128 +#define INDEXK(r)	((int)(r) & ~BITRK)
 190.129 +
 190.130 +#define MAXINDEXRK	(BITRK - 1)
 190.131 +
 190.132 +/* code a constant index as a RK value */
 190.133 +#define RKASK(x)	((x) | BITRK)
 190.134 +
 190.135 +
 190.136 +/*
 190.137 +** invalid register that fits in 8 bits
 190.138 +*/
 190.139 +#define NO_REG		MAXARG_A
 190.140 +
 190.141 +
 190.142 +/*
 190.143 +** R(x) - register
 190.144 +** Kst(x) - constant (in constant table)
 190.145 +** RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x)
 190.146 +*/
 190.147 +
 190.148 +
 190.149 +/*
 190.150 +** grep "ORDER OP" if you change these enums
 190.151 +*/
 190.152 +
 190.153 +typedef enum {
 190.154 +/*----------------------------------------------------------------------
 190.155 +name		args	description
 190.156 +------------------------------------------------------------------------*/
 190.157 +OP_MOVE,/*	A B	R(A) := R(B)					*/
 190.158 +OP_LOADK,/*	A Bx	R(A) := Kst(Bx)					*/
 190.159 +OP_LOADBOOL,/*	A B C	R(A) := (Bool)B; if (C) pc++			*/
 190.160 +OP_LOADNIL,/*	A B	R(A) := ... := R(B) := nil			*/
 190.161 +OP_GETUPVAL,/*	A B	R(A) := UpValue[B]				*/
 190.162 +
 190.163 +OP_GETGLOBAL,/*	A Bx	R(A) := Gbl[Kst(Bx)]				*/
 190.164 +OP_GETTABLE,/*	A B C	R(A) := R(B)[RK(C)]				*/
 190.165 +
 190.166 +OP_SETGLOBAL,/*	A Bx	Gbl[Kst(Bx)] := R(A)				*/
 190.167 +OP_SETUPVAL,/*	A B	UpValue[B] := R(A)				*/
 190.168 +OP_SETTABLE,/*	A B C	R(A)[RK(B)] := RK(C)				*/
 190.169 +
 190.170 +OP_NEWTABLE,/*	A B C	R(A) := {} (size = B,C)				*/
 190.171 +
 190.172 +OP_SELF,/*	A B C	R(A+1) := R(B); R(A) := R(B)[RK(C)]		*/
 190.173 +
 190.174 +OP_ADD,/*	A B C	R(A) := RK(B) + RK(C)				*/
 190.175 +OP_SUB,/*	A B C	R(A) := RK(B) - RK(C)				*/
 190.176 +OP_MUL,/*	A B C	R(A) := RK(B) * RK(C)				*/
 190.177 +OP_DIV,/*	A B C	R(A) := RK(B) / RK(C)				*/
 190.178 +OP_MOD,/*	A B C	R(A) := RK(B) % RK(C)				*/
 190.179 +OP_POW,/*	A B C	R(A) := RK(B) ^ RK(C)				*/
 190.180 +OP_UNM,/*	A B	R(A) := -R(B)					*/
 190.181 +OP_NOT,/*	A B	R(A) := not R(B)				*/
 190.182 +OP_LEN,/*	A B	R(A) := length of R(B)				*/
 190.183 +
 190.184 +OP_CONCAT,/*	A B C	R(A) := R(B).. ... ..R(C)			*/
 190.185 +
 190.186 +OP_JMP,/*	sBx	pc+=sBx					*/
 190.187 +
 190.188 +OP_EQ,/*	A B C	if ((RK(B) == RK(C)) ~= A) then pc++		*/
 190.189 +OP_LT,/*	A B C	if ((RK(B) <  RK(C)) ~= A) then pc++  		*/
 190.190 +OP_LE,/*	A B C	if ((RK(B) <= RK(C)) ~= A) then pc++  		*/
 190.191 +
 190.192 +OP_TEST,/*	A C	if not (R(A) <=> C) then pc++			*/ 
 190.193 +OP_TESTSET,/*	A B C	if (R(B) <=> C) then R(A) := R(B) else pc++	*/ 
 190.194 +
 190.195 +OP_CALL,/*	A B C	R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */
 190.196 +OP_TAILCALL,/*	A B C	return R(A)(R(A+1), ... ,R(A+B-1))		*/
 190.197 +OP_RETURN,/*	A B	return R(A), ... ,R(A+B-2)	(see note)	*/
 190.198 +
 190.199 +OP_FORLOOP,/*	A sBx	R(A)+=R(A+2);
 190.200 +			if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/
 190.201 +OP_FORPREP,/*	A sBx	R(A)-=R(A+2); pc+=sBx				*/
 190.202 +
 190.203 +OP_TFORLOOP,/*	A C	R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); 
 190.204 +                        if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++	*/ 
 190.205 +OP_SETLIST,/*	A B C	R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B	*/
 190.206 +
 190.207 +OP_CLOSE,/*	A 	close all variables in the stack up to (>=) R(A)*/
 190.208 +OP_CLOSURE,/*	A Bx	R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n))	*/
 190.209 +
 190.210 +OP_VARARG/*	A B	R(A), R(A+1), ..., R(A+B-1) = vararg		*/
 190.211 +} OpCode;
 190.212 +
 190.213 +
 190.214 +#define NUM_OPCODES	(cast(int, OP_VARARG) + 1)
 190.215 +
 190.216 +
 190.217 +
 190.218 +/*===========================================================================
 190.219 +  Notes:
 190.220 +  (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1,
 190.221 +      and can be 0: OP_CALL then sets `top' to last_result+1, so
 190.222 +      next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'.
 190.223 +
 190.224 +  (*) In OP_VARARG, if (B == 0) then use actual number of varargs and
 190.225 +      set top (like in OP_CALL with C == 0).
 190.226 +
 190.227 +  (*) In OP_RETURN, if (B == 0) then return up to `top'
 190.228 +
 190.229 +  (*) In OP_SETLIST, if (B == 0) then B = `top';
 190.230 +      if (C == 0) then next `instruction' is real C
 190.231 +
 190.232 +  (*) For comparisons, A specifies what condition the test should accept
 190.233 +      (true or false).
 190.234 +
 190.235 +  (*) All `skips' (pc++) assume that next instruction is a jump
 190.236 +===========================================================================*/
 190.237 +
 190.238 +
 190.239 +/*
 190.240 +** masks for instruction properties. The format is:
 190.241 +** bits 0-1: op mode
 190.242 +** bits 2-3: C arg mode
 190.243 +** bits 4-5: B arg mode
 190.244 +** bit 6: instruction set register A
 190.245 +** bit 7: operator is a test
 190.246 +*/  
 190.247 +
 190.248 +enum OpArgMask {
 190.249 +  OpArgN,  /* argument is not used */
 190.250 +  OpArgU,  /* argument is used */
 190.251 +  OpArgR,  /* argument is a register or a jump offset */
 190.252 +  OpArgK   /* argument is a constant or register/constant */
 190.253 +};
 190.254 +
 190.255 +LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES];
 190.256 +
 190.257 +#define getOpMode(m)	(cast(enum OpMode, luaP_opmodes[m] & 3))
 190.258 +#define getBMode(m)	(cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))
 190.259 +#define getCMode(m)	(cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))
 190.260 +#define testAMode(m)	(luaP_opmodes[m] & (1 << 6))
 190.261 +#define testTMode(m)	(luaP_opmodes[m] & (1 << 7))
 190.262 +
 190.263 +
 190.264 +LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1];  /* opcode names */
 190.265 +
 190.266 +
 190.267 +/* number of list items to accumulate before a SETLIST instruction */
 190.268 +#define LFIELDS_PER_FLUSH	50
 190.269 +
 190.270 +
 190.271 +#endif
   191.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   191.2 +++ b/src/lua/src/loslib.c	Sat Mar 03 10:31:27 2012 -0600
   191.3 @@ -0,0 +1,243 @@
   191.4 +/*
   191.5 +** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $
   191.6 +** Standard Operating System library
   191.7 +** See Copyright Notice in lua.h
   191.8 +*/
   191.9 +
  191.10 +
  191.11 +#include <errno.h>
  191.12 +#include <locale.h>
  191.13 +#include <stdlib.h>
  191.14 +#include <string.h>
  191.15 +#include <time.h>
  191.16 +
  191.17 +#define loslib_c
  191.18 +#define LUA_LIB
  191.19 +
  191.20 +#include "lua.h"
  191.21 +
  191.22 +#include "lauxlib.h"
  191.23 +#include "lualib.h"
  191.24 +
  191.25 +
  191.26 +static int os_pushresult (lua_State *L, int i, const char *filename) {
  191.27 +  int en = errno;  /* calls to Lua API may change this value */
  191.28 +  if (i) {
  191.29 +    lua_pushboolean(L, 1);
  191.30 +    return 1;
  191.31 +  }
  191.32 +  else {
  191.33 +    lua_pushnil(L);
  191.34 +    lua_pushfstring(L, "%s: %s", filename, strerror(en));
  191.35 +    lua_pushinteger(L, en);
  191.36 +    return 3;
  191.37 +  }
  191.38 +}
  191.39 +
  191.40 +
  191.41 +static int os_execute (lua_State *L) {
  191.42 +  lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
  191.43 +  return 1;
  191.44 +}
  191.45 +
  191.46 +
  191.47 +static int os_remove (lua_State *L) {
  191.48 +  const char *filename = luaL_checkstring(L, 1);
  191.49 +  return os_pushresult(L, remove(filename) == 0, filename);
  191.50 +}
  191.51 +
  191.52 +
  191.53 +static int os_rename (lua_State *L) {
  191.54 +  const char *fromname = luaL_checkstring(L, 1);
  191.55 +  const char *toname = luaL_checkstring(L, 2);
  191.56 +  return os_pushresult(L, rename(fromname, toname) == 0, fromname);
  191.57 +}
  191.58 +
  191.59 +
  191.60 +static int os_tmpname (lua_State *L) {
  191.61 +  char buff[LUA_TMPNAMBUFSIZE];
  191.62 +  int err;
  191.63 +  lua_tmpnam(buff, err);
  191.64 +  if (err)
  191.65 +    return luaL_error(L, "unable to generate a unique filename");
  191.66 +  lua_pushstring(L, buff);
  191.67 +  return 1;
  191.68 +}
  191.69 +
  191.70 +
  191.71 +static int os_getenv (lua_State *L) {
  191.72 +  lua_pushstring(L, getenv(luaL_checkstring(L, 1)));  /* if NULL push nil */
  191.73 +  return 1;
  191.74 +}
  191.75 +
  191.76 +
  191.77 +static int os_clock (lua_State *L) {
  191.78 +  lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);
  191.79 +  return 1;
  191.80 +}
  191.81 +
  191.82 +
  191.83 +/*
  191.84 +** {======================================================
  191.85 +** Time/Date operations
  191.86 +** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S,
  191.87 +**   wday=%w+1, yday=%j, isdst=? }
  191.88 +** =======================================================
  191.89 +*/
  191.90 +
  191.91 +static void setfield (lua_State *L, const char *key, int value) {
  191.92 +  lua_pushinteger(L, value);
  191.93 +  lua_setfield(L, -2, key);
  191.94 +}
  191.95 +
  191.96 +static void setboolfield (lua_State *L, const char *key, int value) {
  191.97 +  if (value < 0)  /* undefined? */
  191.98 +    return;  /* does not set field */
  191.99 +  lua_pushboolean(L, value);
 191.100 +  lua_setfield(L, -2, key);
 191.101 +}
 191.102 +
 191.103 +static int getboolfield (lua_State *L, const char *key) {
 191.104 +  int res;
 191.105 +  lua_getfield(L, -1, key);
 191.106 +  res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1);
 191.107 +  lua_pop(L, 1);
 191.108 +  return res;
 191.109 +}
 191.110 +
 191.111 +
 191.112 +static int getfield (lua_State *L, const char *key, int d) {
 191.113 +  int res;
 191.114 +  lua_getfield(L, -1, key);
 191.115 +  if (lua_isnumber(L, -1))
 191.116 +    res = (int)lua_tointeger(L, -1);
 191.117 +  else {
 191.118 +    if (d < 0)
 191.119 +      return luaL_error(L, "field " LUA_QS " missing in date table", key);
 191.120 +    res = d;
 191.121 +  }
 191.122 +  lua_pop(L, 1);
 191.123 +  return res;
 191.124 +}
 191.125 +
 191.126 +
 191.127 +static int os_date (lua_State *L) {
 191.128 +  const char *s = luaL_optstring(L, 1, "%c");
 191.129 +  time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL));
 191.130 +  struct tm *stm;
 191.131 +  if (*s == '!') {  /* UTC? */
 191.132 +    stm = gmtime(&t);
 191.133 +    s++;  /* skip `!' */
 191.134 +  }
 191.135 +  else
 191.136 +    stm = localtime(&t);
 191.137 +  if (stm == NULL)  /* invalid date? */
 191.138 +    lua_pushnil(L);
 191.139 +  else if (strcmp(s, "*t") == 0) {
 191.140 +    lua_createtable(L, 0, 9);  /* 9 = number of fields */
 191.141 +    setfield(L, "sec", stm->tm_sec);
 191.142 +    setfield(L, "min", stm->tm_min);
 191.143 +    setfield(L, "hour", stm->tm_hour);
 191.144 +    setfield(L, "day", stm->tm_mday);
 191.145 +    setfield(L, "month", stm->tm_mon+1);
 191.146 +    setfield(L, "year", stm->tm_year+1900);
 191.147 +    setfield(L, "wday", stm->tm_wday+1);
 191.148 +    setfield(L, "yday", stm->tm_yday+1);
 191.149 +    setboolfield(L, "isdst", stm->tm_isdst);
 191.150 +  }
 191.151 +  else {
 191.152 +    char cc[3];
 191.153 +    luaL_Buffer b;
 191.154 +    cc[0] = '%'; cc[2] = '\0';
 191.155 +    luaL_buffinit(L, &b);
 191.156 +    for (; *s; s++) {
 191.157 +      if (*s != '%' || *(s + 1) == '\0')  /* no conversion specifier? */
 191.158 +        luaL_addchar(&b, *s);
 191.159 +      else {
 191.160 +        size_t reslen;
 191.161 +        char buff[200];  /* should be big enough for any conversion result */
 191.162 +        cc[1] = *(++s);
 191.163 +        reslen = strftime(buff, sizeof(buff), cc, stm);
 191.164 +        luaL_addlstring(&b, buff, reslen);
 191.165 +      }
 191.166 +    }
 191.167 +    luaL_pushresult(&b);
 191.168 +  }
 191.169 +  return 1;
 191.170 +}
 191.171 +
 191.172 +
 191.173 +static int os_time (lua_State *L) {
 191.174 +  time_t t;
 191.175 +  if (lua_isnoneornil(L, 1))  /* called without args? */
 191.176 +    t = time(NULL);  /* get current time */
 191.177 +  else {
 191.178 +    struct tm ts;
 191.179 +    luaL_checktype(L, 1, LUA_TTABLE);
 191.180 +    lua_settop(L, 1);  /* make sure table is at the top */
 191.181 +    ts.tm_sec = getfield(L, "sec", 0);
 191.182 +    ts.tm_min = getfield(L, "min", 0);
 191.183 +    ts.tm_hour = getfield(L, "hour", 12);
 191.184 +    ts.tm_mday = getfield(L, "day", -1);
 191.185 +    ts.tm_mon = getfield(L, "month", -1) - 1;
 191.186 +    ts.tm_year = getfield(L, "year", -1) - 1900;
 191.187 +    ts.tm_isdst = getboolfield(L, "isdst");
 191.188 +    t = mktime(&ts);
 191.189 +  }
 191.190 +  if (t == (time_t)(-1))
 191.191 +    lua_pushnil(L);
 191.192 +  else
 191.193 +    lua_pushnumber(L, (lua_Number)t);
 191.194 +  return 1;
 191.195 +}
 191.196 +
 191.197 +
 191.198 +static int os_difftime (lua_State *L) {
 191.199 +  lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),
 191.200 +                             (time_t)(luaL_optnumber(L, 2, 0))));
 191.201 +  return 1;
 191.202 +}
 191.203 +
 191.204 +/* }====================================================== */
 191.205 +
 191.206 +
 191.207 +static int os_setlocale (lua_State *L) {
 191.208 +  static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
 191.209 +                      LC_NUMERIC, LC_TIME};
 191.210 +  static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
 191.211 +     "numeric", "time", NULL};
 191.212 +  const char *l = luaL_optstring(L, 1, NULL);
 191.213 +  int op = luaL_checkoption(L, 2, "all", catnames);
 191.214 +  lua_pushstring(L, setlocale(cat[op], l));
 191.215 +  return 1;
 191.216 +}
 191.217 +
 191.218 +
 191.219 +static int os_exit (lua_State *L) {
 191.220 +  exit(luaL_optint(L, 1, EXIT_SUCCESS));
 191.221 +}
 191.222 +
 191.223 +static const luaL_Reg syslib[] = {
 191.224 +  {"clock",     os_clock},
 191.225 +  {"date",      os_date},
 191.226 +  {"difftime",  os_difftime},
 191.227 +  {"execute",   os_execute},
 191.228 +  {"exit",      os_exit},
 191.229 +  {"getenv",    os_getenv},
 191.230 +  {"remove",    os_remove},
 191.231 +  {"rename",    os_rename},
 191.232 +  {"setlocale", os_setlocale},
 191.233 +  {"time",      os_time},
 191.234 +  {"tmpname",   os_tmpname},
 191.235 +  {NULL, NULL}
 191.236 +};
 191.237 +
 191.238 +/* }====================================================== */
 191.239 +
 191.240 +
 191.241 +
 191.242 +LUALIB_API int luaopen_os (lua_State *L) {
 191.243 +  luaL_register(L, LUA_OSLIBNAME, syslib);
 191.244 +  return 1;
 191.245 +}
 191.246 +
   192.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   192.2 +++ b/src/lua/src/lparser.c	Sat Mar 03 10:31:27 2012 -0600
   192.3 @@ -0,0 +1,1339 @@
   192.4 +/*
   192.5 +** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $
   192.6 +** Lua Parser
   192.7 +** See Copyright Notice in lua.h
   192.8 +*/
   192.9 +
  192.10 +
  192.11 +#include <string.h>
  192.12 +
  192.13 +#define lparser_c
  192.14 +#define LUA_CORE
  192.15 +
  192.16 +#include "lua.h"
  192.17 +
  192.18 +#include "lcode.h"
  192.19 +#include "ldebug.h"
  192.20 +#include "ldo.h"
  192.21 +#include "lfunc.h"
  192.22 +#include "llex.h"
  192.23 +#include "lmem.h"
  192.24 +#include "lobject.h"
  192.25 +#include "lopcodes.h"
  192.26 +#include "lparser.h"
  192.27 +#include "lstate.h"
  192.28 +#include "lstring.h"
  192.29 +#include "ltable.h"
  192.30 +
  192.31 +
  192.32 +
  192.33 +#define hasmultret(k)		((k) == VCALL || (k) == VVARARG)
  192.34 +
  192.35 +#define getlocvar(fs, i)	((fs)->f->locvars[(fs)->actvar[i]])
  192.36 +
  192.37 +#define luaY_checklimit(fs,v,l,m)	if ((v)>(l)) errorlimit(fs,l,m)
  192.38 +
  192.39 +
  192.40 +/*
  192.41 +** nodes for block list (list of active blocks)
  192.42 +*/
  192.43 +typedef struct BlockCnt {
  192.44 +  struct BlockCnt *previous;  /* chain */
  192.45 +  int breaklist;  /* list of jumps out of this loop */
  192.46 +  lu_byte nactvar;  /* # active locals outside the breakable structure */
  192.47 +  lu_byte upval;  /* true if some variable in the block is an upvalue */
  192.48 +  lu_byte isbreakable;  /* true if `block' is a loop */
  192.49 +} BlockCnt;
  192.50 +
  192.51 +
  192.52 +
  192.53 +/*
  192.54 +** prototypes for recursive non-terminal functions
  192.55 +*/
  192.56 +static void chunk (LexState *ls);
  192.57 +static void expr (LexState *ls, expdesc *v);
  192.58 +
  192.59 +
  192.60 +static void anchor_token (LexState *ls) {
  192.61 +  if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) {
  192.62 +    TString *ts = ls->t.seminfo.ts;
  192.63 +    luaX_newstring(ls, getstr(ts), ts->tsv.len);
  192.64 +  }
  192.65 +}
  192.66 +
  192.67 +
  192.68 +static void error_expected (LexState *ls, int token) {
  192.69 +  luaX_syntaxerror(ls,
  192.70 +      luaO_pushfstring(ls->L, LUA_QS " expected", luaX_token2str(ls, token)));
  192.71 +}
  192.72 +
  192.73 +
  192.74 +static void errorlimit (FuncState *fs, int limit, const char *what) {
  192.75 +  const char *msg = (fs->f->linedefined == 0) ?
  192.76 +    luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) :
  192.77 +    luaO_pushfstring(fs->L, "function at line %d has more than %d %s",
  192.78 +                            fs->f->linedefined, limit, what);
  192.79 +  luaX_lexerror(fs->ls, msg, 0);
  192.80 +}
  192.81 +
  192.82 +
  192.83 +static int testnext (LexState *ls, int c) {
  192.84 +  if (ls->t.token == c) {
  192.85 +    luaX_next(ls);
  192.86 +    return 1;
  192.87 +  }
  192.88 +  else return 0;
  192.89 +}
  192.90 +
  192.91 +
  192.92 +static void check (LexState *ls, int c) {
  192.93 +  if (ls->t.token != c)
  192.94 +    error_expected(ls, c);
  192.95 +}
  192.96 +
  192.97 +static void checknext (LexState *ls, int c) {
  192.98 +  check(ls, c);
  192.99 +  luaX_next(ls);
 192.100 +}
 192.101 +
 192.102 +
 192.103 +#define check_condition(ls,c,msg)	{ if (!(c)) luaX_syntaxerror(ls, msg); }
 192.104 +
 192.105 +
 192.106 +
 192.107 +static void check_match (LexState *ls, int what, int who, int where) {
 192.108 +  if (!testnext(ls, what)) {
 192.109 +    if (where == ls->linenumber)
 192.110 +      error_expected(ls, what);
 192.111 +    else {
 192.112 +      luaX_syntaxerror(ls, luaO_pushfstring(ls->L,
 192.113 +             LUA_QS " expected (to close " LUA_QS " at line %d)",
 192.114 +              luaX_token2str(ls, what), luaX_token2str(ls, who), where));
 192.115 +    }
 192.116 +  }
 192.117 +}
 192.118 +
 192.119 +
 192.120 +static TString *str_checkname (LexState *ls) {
 192.121 +  TString *ts;
 192.122 +  check(ls, TK_NAME);
 192.123 +  ts = ls->t.seminfo.ts;
 192.124 +  luaX_next(ls);
 192.125 +  return ts;
 192.126 +}
 192.127 +
 192.128 +
 192.129 +static void init_exp (expdesc *e, expkind k, int i) {
 192.130 +  e->f = e->t = NO_JUMP;
 192.131 +  e->k = k;
 192.132 +  e->u.s.info = i;
 192.133 +}
 192.134 +
 192.135 +
 192.136 +static void codestring (LexState *ls, expdesc *e, TString *s) {
 192.137 +  init_exp(e, VK, luaK_stringK(ls->fs, s));
 192.138 +}
 192.139 +
 192.140 +
 192.141 +static void checkname(LexState *ls, expdesc *e) {
 192.142 +  codestring(ls, e, str_checkname(ls));
 192.143 +}
 192.144 +
 192.145 +
 192.146 +static int registerlocalvar (LexState *ls, TString *varname) {
 192.147 +  FuncState *fs = ls->fs;
 192.148 +  Proto *f = fs->f;
 192.149 +  int oldsize = f->sizelocvars;
 192.150 +  luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,
 192.151 +                  LocVar, SHRT_MAX, "too many local variables");
 192.152 +  while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL;
 192.153 +  f->locvars[fs->nlocvars].varname = varname;
 192.154 +  luaC_objbarrier(ls->L, f, varname);
 192.155 +  return fs->nlocvars++;
 192.156 +}
 192.157 +
 192.158 +
 192.159 +#define new_localvarliteral(ls,v,n) \
 192.160 +  new_localvar(ls, luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char))-1), n)
 192.161 +
 192.162 +
 192.163 +static void new_localvar (LexState *ls, TString *name, int n) {
 192.164 +  FuncState *fs = ls->fs;
 192.165 +  luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables");
 192.166 +  fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name));
 192.167 +}
 192.168 +
 192.169 +
 192.170 +static void adjustlocalvars (LexState *ls, int nvars) {
 192.171 +  FuncState *fs = ls->fs;
 192.172 +  fs->nactvar = cast_byte(fs->nactvar + nvars);
 192.173 +  for (; nvars; nvars--) {
 192.174 +    getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc;
 192.175 +  }
 192.176 +}
 192.177 +
 192.178 +
 192.179 +static void removevars (LexState *ls, int tolevel) {
 192.180 +  FuncState *fs = ls->fs;
 192.181 +  while (fs->nactvar > tolevel)
 192.182 +    getlocvar(fs, --fs->nactvar).endpc = fs->pc;
 192.183 +}
 192.184 +
 192.185 +
 192.186 +static int indexupvalue (FuncState *fs, TString *name, expdesc *v) {
 192.187 +  int i;
 192.188 +  Proto *f = fs->f;
 192.189 +  int oldsize = f->sizeupvalues;
 192.190 +  for (i=0; i<f->nups; i++) {
 192.191 +    if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) {
 192.192 +      lua_assert(f->upvalues[i] == name);
 192.193 +      return i;
 192.194 +    }
 192.195 +  }
 192.196 +  /* new one */
 192.197 +  luaY_checklimit(fs, f->nups + 1, LUAI_MAXUPVALUES, "upvalues");
 192.198 +  luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues,
 192.199 +                  TString *, MAX_INT, "");
 192.200 +  while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL;
 192.201 +  f->upvalues[f->nups] = name;
 192.202 +  luaC_objbarrier(fs->L, f, name);
 192.203 +  lua_assert(v->k == VLOCAL || v->k == VUPVAL);
 192.204 +  fs->upvalues[f->nups].k = cast_byte(v->k);
 192.205 +  fs->upvalues[f->nups].info = cast_byte(v->u.s.info);
 192.206 +  return f->nups++;
 192.207 +}
 192.208 +
 192.209 +
 192.210 +static int searchvar (FuncState *fs, TString *n) {
 192.211 +  int i;
 192.212 +  for (i=fs->nactvar-1; i >= 0; i--) {
 192.213 +    if (n == getlocvar(fs, i).varname)
 192.214 +      return i;
 192.215 +  }
 192.216 +  return -1;  /* not found */
 192.217 +}
 192.218 +
 192.219 +
 192.220 +static void markupval (FuncState *fs, int level) {
 192.221 +  BlockCnt *bl = fs->bl;
 192.222 +  while (bl && bl->nactvar > level) bl = bl->previous;
 192.223 +  if (bl) bl->upval = 1;
 192.224 +}
 192.225 +
 192.226 +
 192.227 +static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {
 192.228 +  if (fs == NULL) {  /* no more levels? */
 192.229 +    init_exp(var, VGLOBAL, NO_REG);  /* default is global variable */
 192.230 +    return VGLOBAL;
 192.231 +  }
 192.232 +  else {
 192.233 +    int v = searchvar(fs, n);  /* look up at current level */
 192.234 +    if (v >= 0) {
 192.235 +      init_exp(var, VLOCAL, v);
 192.236 +      if (!base)
 192.237 +        markupval(fs, v);  /* local will be used as an upval */
 192.238 +      return VLOCAL;
 192.239 +    }
 192.240 +    else {  /* not found at current level; try upper one */
 192.241 +      if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL)
 192.242 +        return VGLOBAL;
 192.243 +      var->u.s.info = indexupvalue(fs, n, var);  /* else was LOCAL or UPVAL */
 192.244 +      var->k = VUPVAL;  /* upvalue in this level */
 192.245 +      return VUPVAL;
 192.246 +    }
 192.247 +  }
 192.248 +}
 192.249 +
 192.250 +
 192.251 +static void singlevar (LexState *ls, expdesc *var) {
 192.252 +  TString *varname = str_checkname(ls);
 192.253 +  FuncState *fs = ls->fs;
 192.254 +  if (singlevaraux(fs, varname, var, 1) == VGLOBAL)
 192.255 +    var->u.s.info = luaK_stringK(fs, varname);  /* info points to global name */
 192.256 +}
 192.257 +
 192.258 +
 192.259 +static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
 192.260 +  FuncState *fs = ls->fs;
 192.261 +  int extra = nvars - nexps;
 192.262 +  if (hasmultret(e->k)) {
 192.263 +    extra++;  /* includes call itself */
 192.264 +    if (extra < 0) extra = 0;
 192.265 +    luaK_setreturns(fs, e, extra);  /* last exp. provides the difference */
 192.266 +    if (extra > 1) luaK_reserveregs(fs, extra-1);
 192.267 +  }
 192.268 +  else {
 192.269 +    if (e->k != VVOID) luaK_exp2nextreg(fs, e);  /* close last expression */
 192.270 +    if (extra > 0) {
 192.271 +      int reg = fs->freereg;
 192.272 +      luaK_reserveregs(fs, extra);
 192.273 +      luaK_nil(fs, reg, extra);
 192.274 +    }
 192.275 +  }
 192.276 +}
 192.277 +
 192.278 +
 192.279 +static void enterlevel (LexState *ls) {
 192.280 +  if (++ls->L->nCcalls > LUAI_MAXCCALLS)
 192.281 +	luaX_lexerror(ls, "chunk has too many syntax levels", 0);
 192.282 +}
 192.283 +
 192.284 +
 192.285 +#define leavelevel(ls)	((ls)->L->nCcalls--)
 192.286 +
 192.287 +
 192.288 +static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isbreakable) {
 192.289 +  bl->breaklist = NO_JUMP;
 192.290 +  bl->isbreakable = isbreakable;
 192.291 +  bl->nactvar = fs->nactvar;
 192.292 +  bl->upval = 0;
 192.293 +  bl->previous = fs->bl;
 192.294 +  fs->bl = bl;
 192.295 +  lua_assert(fs->freereg == fs->nactvar);
 192.296 +}
 192.297 +
 192.298 +
 192.299 +static void leaveblock (FuncState *fs) {
 192.300 +  BlockCnt *bl = fs->bl;
 192.301 +  fs->bl = bl->previous;
 192.302 +  removevars(fs->ls, bl->nactvar);
 192.303 +  if (bl->upval)
 192.304 +    luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);
 192.305 +  /* a block either controls scope or breaks (never both) */
 192.306 +  lua_assert(!bl->isbreakable || !bl->upval);
 192.307 +  lua_assert(bl->nactvar == fs->nactvar);
 192.308 +  fs->freereg = fs->nactvar;  /* free registers */
 192.309 +  luaK_patchtohere(fs, bl->breaklist);
 192.310 +}
 192.311 +
 192.312 +
 192.313 +static void pushclosure (LexState *ls, FuncState *func, expdesc *v) {
 192.314 +  FuncState *fs = ls->fs;
 192.315 +  Proto *f = fs->f;
 192.316 +  int oldsize = f->sizep;
 192.317 +  int i;
 192.318 +  luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *,
 192.319 +                  MAXARG_Bx, "constant table overflow");
 192.320 +  while (oldsize < f->sizep) f->p[oldsize++] = NULL;
 192.321 +  f->p[fs->np++] = func->f;
 192.322 +  luaC_objbarrier(ls->L, f, func->f);
 192.323 +  init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1));
 192.324 +  for (i=0; i<func->f->nups; i++) {
 192.325 +    OpCode o = (func->upvalues[i].k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;
 192.326 +    luaK_codeABC(fs, o, 0, func->upvalues[i].info, 0);
 192.327 +  }
 192.328 +}
 192.329 +
 192.330 +
 192.331 +static void open_func (LexState *ls, FuncState *fs) {
 192.332 +  lua_State *L = ls->L;
 192.333 +  Proto *f = luaF_newproto(L);
 192.334 +  fs->f = f;
 192.335 +  fs->prev = ls->fs;  /* linked list of funcstates */
 192.336 +  fs->ls = ls;
 192.337 +  fs->L = L;
 192.338 +  ls->fs = fs;
 192.339 +  fs->pc = 0;
 192.340 +  fs->lasttarget = -1;
 192.341 +  fs->jpc = NO_JUMP;
 192.342 +  fs->freereg = 0;
 192.343 +  fs->nk = 0;
 192.344 +  fs->np = 0;
 192.345 +  fs->nlocvars = 0;
 192.346 +  fs->nactvar = 0;
 192.347 +  fs->bl = NULL;
 192.348 +  f->source = ls->source;
 192.349 +  f->maxstacksize = 2;  /* registers 0/1 are always valid */
 192.350 +  fs->h = luaH_new(L, 0, 0);
 192.351 +  /* anchor table of constants and prototype (to avoid being collected) */
 192.352 +  sethvalue2s(L, L->top, fs->h);
 192.353 +  incr_top(L);
 192.354 +  setptvalue2s(L, L->top, f);
 192.355 +  incr_top(L);
 192.356 +}
 192.357 +
 192.358 +
 192.359 +static void close_func (LexState *ls) {
 192.360 +  lua_State *L = ls->L;
 192.361 +  FuncState *fs = ls->fs;
 192.362 +  Proto *f = fs->f;
 192.363 +  removevars(ls, 0);
 192.364 +  luaK_ret(fs, 0, 0);  /* final return */
 192.365 +  luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
 192.366 +  f->sizecode = fs->pc;
 192.367 +  luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
 192.368 +  f->sizelineinfo = fs->pc;
 192.369 +  luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);
 192.370 +  f->sizek = fs->nk;
 192.371 +  luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);
 192.372 +  f->sizep = fs->np;
 192.373 +  luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);
 192.374 +  f->sizelocvars = fs->nlocvars;
 192.375 +  luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *);
 192.376 +  f->sizeupvalues = f->nups;
 192.377 +  lua_assert(luaG_checkcode(f));
 192.378 +  lua_assert(fs->bl == NULL);
 192.379 +  ls->fs = fs->prev;
 192.380 +  L->top -= 2;  /* remove table and prototype from the stack */
 192.381 +  /* last token read was anchored in defunct function; must reanchor it */
 192.382 +  if (fs) anchor_token(ls);
 192.383 +}
 192.384 +
 192.385 +
 192.386 +Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
 192.387 +  struct LexState lexstate;
 192.388 +  struct FuncState funcstate;
 192.389 +  lexstate.buff = buff;
 192.390 +  luaX_setinput(L, &lexstate, z, luaS_new(L, name));
 192.391 +  open_func(&lexstate, &funcstate);
 192.392 +  funcstate.f->is_vararg = VARARG_ISVARARG;  /* main func. is always vararg */
 192.393 +  luaX_next(&lexstate);  /* read first token */
 192.394 +  chunk(&lexstate);
 192.395 +  check(&lexstate, TK_EOS);
 192.396 +  close_func(&lexstate);
 192.397 +  lua_assert(funcstate.prev == NULL);
 192.398 +  lua_assert(funcstate.f->nups == 0);
 192.399 +  lua_assert(lexstate.fs == NULL);
 192.400 +  return funcstate.f;
 192.401 +}
 192.402 +
 192.403 +
 192.404 +
 192.405 +/*============================================================*/
 192.406 +/* GRAMMAR RULES */
 192.407 +/*============================================================*/
 192.408 +
 192.409 +
 192.410 +static void field (LexState *ls, expdesc *v) {
 192.411 +  /* field -> ['.' | ':'] NAME */
 192.412 +  FuncState *fs = ls->fs;
 192.413 +  expdesc key;
 192.414 +  luaK_exp2anyreg(fs, v);
 192.415 +  luaX_next(ls);  /* skip the dot or colon */
 192.416 +  checkname(ls, &key);
 192.417 +  luaK_indexed(fs, v, &key);
 192.418 +}
 192.419 +
 192.420 +
 192.421 +static void yindex (LexState *ls, expdesc *v) {
 192.422 +  /* index -> '[' expr ']' */
 192.423 +  luaX_next(ls);  /* skip the '[' */
 192.424 +  expr(ls, v);
 192.425 +  luaK_exp2val(ls->fs, v);
 192.426 +  checknext(ls, ']');
 192.427 +}
 192.428 +
 192.429 +
 192.430 +/*
 192.431 +** {======================================================================
 192.432 +** Rules for Constructors
 192.433 +** =======================================================================
 192.434 +*/
 192.435 +
 192.436 +
 192.437 +struct ConsControl {
 192.438 +  expdesc v;  /* last list item read */
 192.439 +  expdesc *t;  /* table descriptor */
 192.440 +  int nh;  /* total number of `record' elements */
 192.441 +  int na;  /* total number of array elements */
 192.442 +  int tostore;  /* number of array elements pending to be stored */
 192.443 +};
 192.444 +
 192.445 +
 192.446 +static void recfield (LexState *ls, struct ConsControl *cc) {
 192.447 +  /* recfield -> (NAME | `['exp1`]') = exp1 */
 192.448 +  FuncState *fs = ls->fs;
 192.449 +  int reg = ls->fs->freereg;
 192.450 +  expdesc key, val;
 192.451 +  int rkkey;
 192.452 +  if (ls->t.token == TK_NAME) {
 192.453 +    luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
 192.454 +    checkname(ls, &key);
 192.455 +  }
 192.456 +  else  /* ls->t.token == '[' */
 192.457 +    yindex(ls, &key);
 192.458 +  cc->nh++;
 192.459 +  checknext(ls, '=');
 192.460 +  rkkey = luaK_exp2RK(fs, &key);
 192.461 +  expr(ls, &val);
 192.462 +  luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val));
 192.463 +  fs->freereg = reg;  /* free registers */
 192.464 +}
 192.465 +
 192.466 +
 192.467 +static void closelistfield (FuncState *fs, struct ConsControl *cc) {
 192.468 +  if (cc->v.k == VVOID) return;  /* there is no list item */
 192.469 +  luaK_exp2nextreg(fs, &cc->v);
 192.470 +  cc->v.k = VVOID;
 192.471 +  if (cc->tostore == LFIELDS_PER_FLUSH) {
 192.472 +    luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore);  /* flush */
 192.473 +    cc->tostore = 0;  /* no more items pending */
 192.474 +  }
 192.475 +}
 192.476 +
 192.477 +
 192.478 +static void lastlistfield (FuncState *fs, struct ConsControl *cc) {
 192.479 +  if (cc->tostore == 0) return;
 192.480 +  if (hasmultret(cc->v.k)) {
 192.481 +    luaK_setmultret(fs, &cc->v);
 192.482 +    luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET);
 192.483 +    cc->na--;  /* do not count last expression (unknown number of elements) */
 192.484 +  }
 192.485 +  else {
 192.486 +    if (cc->v.k != VVOID)
 192.487 +      luaK_exp2nextreg(fs, &cc->v);
 192.488 +    luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore);
 192.489 +  }
 192.490 +}
 192.491 +
 192.492 +
 192.493 +static void listfield (LexState *ls, struct ConsControl *cc) {
 192.494 +  expr(ls, &cc->v);
 192.495 +  luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor");
 192.496 +  cc->na++;
 192.497 +  cc->tostore++;
 192.498 +}
 192.499 +
 192.500 +
 192.501 +static void constructor (LexState *ls, expdesc *t) {
 192.502 +  /* constructor -> ?? */
 192.503 +  FuncState *fs = ls->fs;
 192.504 +  int line = ls->linenumber;
 192.505 +  int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);
 192.506 +  struct ConsControl cc;
 192.507 +  cc.na = cc.nh = cc.tostore = 0;
 192.508 +  cc.t = t;
 192.509 +  init_exp(t, VRELOCABLE, pc);
 192.510 +  init_exp(&cc.v, VVOID, 0);  /* no value (yet) */
 192.511 +  luaK_exp2nextreg(ls->fs, t);  /* fix it at stack top (for gc) */
 192.512 +  checknext(ls, '{');
 192.513 +  do {
 192.514 +    lua_assert(cc.v.k == VVOID || cc.tostore > 0);
 192.515 +    if (ls->t.token == '}') break;
 192.516 +    closelistfield(fs, &cc);
 192.517 +    switch(ls->t.token) {
 192.518 +      case TK_NAME: {  /* may be listfields or recfields */
 192.519 +        luaX_lookahead(ls);
 192.520 +        if (ls->lookahead.token != '=')  /* expression? */
 192.521 +          listfield(ls, &cc);
 192.522 +        else
 192.523 +          recfield(ls, &cc);
 192.524 +        break;
 192.525 +      }
 192.526 +      case '[': {  /* constructor_item -> recfield */
 192.527 +        recfield(ls, &cc);
 192.528 +        break;
 192.529 +      }
 192.530 +      default: {  /* constructor_part -> listfield */
 192.531 +        listfield(ls, &cc);
 192.532 +        break;
 192.533 +      }
 192.534 +    }
 192.535 +  } while (testnext(ls, ',') || testnext(ls, ';'));
 192.536 +  check_match(ls, '}', '{', line);
 192.537 +  lastlistfield(fs, &cc);
 192.538 +  SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */
 192.539 +  SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh));  /* set initial table size */
 192.540 +}
 192.541 +
 192.542 +/* }====================================================================== */
 192.543 +
 192.544 +
 192.545 +
 192.546 +static void parlist (LexState *ls) {
 192.547 +  /* parlist -> [ param { `,' param } ] */
 192.548 +  FuncState *fs = ls->fs;
 192.549 +  Proto *f = fs->f;
 192.550 +  int nparams = 0;
 192.551 +  f->is_vararg = 0;
 192.552 +  if (ls->t.token != ')') {  /* is `parlist' not empty? */
 192.553 +    do {
 192.554 +      switch (ls->t.token) {
 192.555 +        case TK_NAME: {  /* param -> NAME */
 192.556 +          new_localvar(ls, str_checkname(ls), nparams++);
 192.557 +          break;
 192.558 +        }
 192.559 +        case TK_DOTS: {  /* param -> `...' */
 192.560 +          luaX_next(ls);
 192.561 +#if defined(LUA_COMPAT_VARARG)
 192.562 +          /* use `arg' as default name */
 192.563 +          new_localvarliteral(ls, "arg", nparams++);
 192.564 +          f->is_vararg = VARARG_HASARG | VARARG_NEEDSARG;
 192.565 +#endif
 192.566 +          f->is_vararg |= VARARG_ISVARARG;
 192.567 +          break;
 192.568 +        }
 192.569 +        default: luaX_syntaxerror(ls, "<name> or " LUA_QL("...") " expected");
 192.570 +      }
 192.571 +    } while (!f->is_vararg && testnext(ls, ','));
 192.572 +  }
 192.573 +  adjustlocalvars(ls, nparams);
 192.574 +  f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG));
 192.575 +  luaK_reserveregs(fs, fs->nactvar);  /* reserve register for parameters */
 192.576 +}
 192.577 +
 192.578 +
 192.579 +static void body (LexState *ls, expdesc *e, int needself, int line) {
 192.580 +  /* body ->  `(' parlist `)' chunk END */
 192.581 +  FuncState new_fs;
 192.582 +  open_func(ls, &new_fs);
 192.583 +  new_fs.f->linedefined = line;
 192.584 +  checknext(ls, '(');
 192.585 +  if (needself) {
 192.586 +    new_localvarliteral(ls, "self", 0);
 192.587 +    adjustlocalvars(ls, 1);
 192.588 +  }
 192.589 +  parlist(ls);
 192.590 +  checknext(ls, ')');
 192.591 +  chunk(ls);
 192.592 +  new_fs.f->lastlinedefined = ls->linenumber;
 192.593 +  check_match(ls, TK_END, TK_FUNCTION, line);
 192.594 +  close_func(ls);
 192.595 +  pushclosure(ls, &new_fs, e);
 192.596 +}
 192.597 +
 192.598 +
 192.599 +static int explist1 (LexState *ls, expdesc *v) {
 192.600 +  /* explist1 -> expr { `,' expr } */
 192.601 +  int n = 1;  /* at least one expression */
 192.602 +  expr(ls, v);
 192.603 +  while (testnext(ls, ',')) {
 192.604 +    luaK_exp2nextreg(ls->fs, v);
 192.605 +    expr(ls, v);
 192.606 +    n++;
 192.607 +  }
 192.608 +  return n;
 192.609 +}
 192.610 +
 192.611 +
 192.612 +static void funcargs (LexState *ls, expdesc *f) {
 192.613 +  FuncState *fs = ls->fs;
 192.614 +  expdesc args;
 192.615 +  int base, nparams;
 192.616 +  int line = ls->linenumber;
 192.617 +  switch (ls->t.token) {
 192.618 +    case '(': {  /* funcargs -> `(' [ explist1 ] `)' */
 192.619 +      if (line != ls->lastline)
 192.620 +        luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)");
 192.621 +      luaX_next(ls);
 192.622 +      if (ls->t.token == ')')  /* arg list is empty? */
 192.623 +        args.k = VVOID;
 192.624 +      else {
 192.625 +        explist1(ls, &args);
 192.626 +        luaK_setmultret(fs, &args);
 192.627 +      }
 192.628 +      check_match(ls, ')', '(', line);
 192.629 +      break;
 192.630 +    }
 192.631 +    case '{': {  /* funcargs -> constructor */
 192.632 +      constructor(ls, &args);
 192.633 +      break;
 192.634 +    }
 192.635 +    case TK_STRING: {  /* funcargs -> STRING */
 192.636 +      codestring(ls, &args, ls->t.seminfo.ts);
 192.637 +      luaX_next(ls);  /* must use `seminfo' before `next' */
 192.638 +      break;
 192.639 +    }
 192.640 +    default: {
 192.641 +      luaX_syntaxerror(ls, "function arguments expected");
 192.642 +      return;
 192.643 +    }
 192.644 +  }
 192.645 +  lua_assert(f->k == VNONRELOC);
 192.646 +  base = f->u.s.info;  /* base register for call */
 192.647 +  if (hasmultret(args.k))
 192.648 +    nparams = LUA_MULTRET;  /* open call */
 192.649 +  else {
 192.650 +    if (args.k != VVOID)
 192.651 +      luaK_exp2nextreg(fs, &args);  /* close last argument */
 192.652 +    nparams = fs->freereg - (base+1);
 192.653 +  }
 192.654 +  init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));
 192.655 +  luaK_fixline(fs, line);
 192.656 +  fs->freereg = base+1;  /* call remove function and arguments and leaves
 192.657 +                            (unless changed) one result */
 192.658 +}
 192.659 +
 192.660 +
 192.661 +
 192.662 +
 192.663 +/*
 192.664 +** {======================================================================
 192.665 +** Expression parsing
 192.666 +** =======================================================================
 192.667 +*/
 192.668 +
 192.669 +
 192.670 +static void prefixexp (LexState *ls, expdesc *v) {
 192.671 +  /* prefixexp -> NAME | '(' expr ')' */
 192.672 +  switch (ls->t.token) {
 192.673 +    case '(': {
 192.674 +      int line = ls->linenumber;
 192.675 +      luaX_next(ls);
 192.676 +      expr(ls, v);
 192.677 +      check_match(ls, ')', '(', line);
 192.678 +      luaK_dischargevars(ls->fs, v);
 192.679 +      return;
 192.680 +    }
 192.681 +    case TK_NAME: {
 192.682 +      singlevar(ls, v);
 192.683 +      return;
 192.684 +    }
 192.685 +    default: {
 192.686 +      luaX_syntaxerror(ls, "unexpected symbol");
 192.687 +      return;
 192.688 +    }
 192.689 +  }
 192.690 +}
 192.691 +
 192.692 +
 192.693 +static void primaryexp (LexState *ls, expdesc *v) {
 192.694 +  /* primaryexp ->
 192.695 +        prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */
 192.696 +  FuncState *fs = ls->fs;
 192.697 +  prefixexp(ls, v);
 192.698 +  for (;;) {
 192.699 +    switch (ls->t.token) {
 192.700 +      case '.': {  /* field */
 192.701 +        field(ls, v);
 192.702 +        break;
 192.703 +      }
 192.704 +      case '[': {  /* `[' exp1 `]' */
 192.705 +        expdesc key;
 192.706 +        luaK_exp2anyreg(fs, v);
 192.707 +        yindex(ls, &key);
 192.708 +        luaK_indexed(fs, v, &key);
 192.709 +        break;
 192.710 +      }
 192.711 +      case ':': {  /* `:' NAME funcargs */
 192.712 +        expdesc key;
 192.713 +        luaX_next(ls);
 192.714 +        checkname(ls, &key);
 192.715 +        luaK_self(fs, v, &key);
 192.716 +        funcargs(ls, v);
 192.717 +        break;
 192.718 +      }
 192.719 +      case '(': case TK_STRING: case '{': {  /* funcargs */
 192.720 +        luaK_exp2nextreg(fs, v);
 192.721 +        funcargs(ls, v);
 192.722 +        break;
 192.723 +      }
 192.724 +      default: return;
 192.725 +    }
 192.726 +  }
 192.727 +}
 192.728 +
 192.729 +
 192.730 +static void simpleexp (LexState *ls, expdesc *v) {
 192.731 +  /* simpleexp -> NUMBER | STRING | NIL | true | false | ... |
 192.732 +                  constructor | FUNCTION body | primaryexp */
 192.733 +  switch (ls->t.token) {
 192.734 +    case TK_NUMBER: {
 192.735 +      init_exp(v, VKNUM, 0);
 192.736 +      v->u.nval = ls->t.seminfo.r;
 192.737 +      break;
 192.738 +    }
 192.739 +    case TK_STRING: {
 192.740 +      codestring(ls, v, ls->t.seminfo.ts);
 192.741 +      break;
 192.742 +    }
 192.743 +    case TK_NIL: {
 192.744 +      init_exp(v, VNIL, 0);
 192.745 +      break;
 192.746 +    }
 192.747 +    case TK_TRUE: {
 192.748 +      init_exp(v, VTRUE, 0);
 192.749 +      break;
 192.750 +    }
 192.751 +    case TK_FALSE: {
 192.752 +      init_exp(v, VFALSE, 0);
 192.753 +      break;
 192.754 +    }
 192.755 +    case TK_DOTS: {  /* vararg */
 192.756 +      FuncState *fs = ls->fs;
 192.757 +      check_condition(ls, fs->f->is_vararg,
 192.758 +                      "cannot use " LUA_QL("...") " outside a vararg function");
 192.759 +      fs->f->is_vararg &= ~VARARG_NEEDSARG;  /* don't need 'arg' */
 192.760 +      init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));
 192.761 +      break;
 192.762 +    }
 192.763 +    case '{': {  /* constructor */
 192.764 +      constructor(ls, v);
 192.765 +      return;
 192.766 +    }
 192.767 +    case TK_FUNCTION: {
 192.768 +      luaX_next(ls);
 192.769 +      body(ls, v, 0, ls->linenumber);
 192.770 +      return;
 192.771 +    }
 192.772 +    default: {
 192.773 +      primaryexp(ls, v);
 192.774 +      return;
 192.775 +    }
 192.776 +  }
 192.777 +  luaX_next(ls);
 192.778 +}
 192.779 +
 192.780 +
 192.781 +static UnOpr getunopr (int op) {
 192.782 +  switch (op) {
 192.783 +    case TK_NOT: return OPR_NOT;
 192.784 +    case '-': return OPR_MINUS;
 192.785 +    case '#': return OPR_LEN;
 192.786 +    default: return OPR_NOUNOPR;
 192.787 +  }
 192.788 +}
 192.789 +
 192.790 +
 192.791 +static BinOpr getbinopr (int op) {
 192.792 +  switch (op) {
 192.793 +    case '+': return OPR_ADD;
 192.794 +    case '-': return OPR_SUB;
 192.795 +    case '*': return OPR_MUL;
 192.796 +    case '/': return OPR_DIV;
 192.797 +    case '%': return OPR_MOD;
 192.798 +    case '^': return OPR_POW;
 192.799 +    case TK_CONCAT: return OPR_CONCAT;
 192.800 +    case TK_NE: return OPR_NE;
 192.801 +    case TK_EQ: return OPR_EQ;
 192.802 +    case '<': return OPR_LT;
 192.803 +    case TK_LE: return OPR_LE;
 192.804 +    case '>': return OPR_GT;
 192.805 +    case TK_GE: return OPR_GE;
 192.806 +    case TK_AND: return OPR_AND;
 192.807 +    case TK_OR: return OPR_OR;
 192.808 +    default: return OPR_NOBINOPR;
 192.809 +  }
 192.810 +}
 192.811 +
 192.812 +
 192.813 +static const struct {
 192.814 +  lu_byte left;  /* left priority for each binary operator */
 192.815 +  lu_byte right; /* right priority */
 192.816 +} priority[] = {  /* ORDER OPR */
 192.817 +   {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7},  /* `+' `-' `/' `%' */
 192.818 +   {10, 9}, {5, 4},                 /* power and concat (right associative) */
 192.819 +   {3, 3}, {3, 3},                  /* equality and inequality */
 192.820 +   {3, 3}, {3, 3}, {3, 3}, {3, 3},  /* order */
 192.821 +   {2, 2}, {1, 1}                   /* logical (and/or) */
 192.822 +};
 192.823 +
 192.824 +#define UNARY_PRIORITY	8  /* priority for unary operators */
 192.825 +
 192.826 +
 192.827 +/*
 192.828 +** subexpr -> (simpleexp | unop subexpr) { binop subexpr }
 192.829 +** where `binop' is any binary operator with a priority higher than `limit'
 192.830 +*/
 192.831 +static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) {
 192.832 +  BinOpr op;
 192.833 +  UnOpr uop;
 192.834 +  enterlevel(ls);
 192.835 +  uop = getunopr(ls->t.token);
 192.836 +  if (uop != OPR_NOUNOPR) {
 192.837 +    luaX_next(ls);
 192.838 +    subexpr(ls, v, UNARY_PRIORITY);
 192.839 +    luaK_prefix(ls->fs, uop, v);
 192.840 +  }
 192.841 +  else simpleexp(ls, v);
 192.842 +  /* expand while operators have priorities higher than `limit' */
 192.843 +  op = getbinopr(ls->t.token);
 192.844 +  while (op != OPR_NOBINOPR && priority[op].left > limit) {
 192.845 +    expdesc v2;
 192.846 +    BinOpr nextop;
 192.847 +    luaX_next(ls);
 192.848 +    luaK_infix(ls->fs, op, v);
 192.849 +    /* read sub-expression with higher priority */
 192.850 +    nextop = subexpr(ls, &v2, priority[op].right);
 192.851 +    luaK_posfix(ls->fs, op, v, &v2);
 192.852 +    op = nextop;
 192.853 +  }
 192.854 +  leavelevel(ls);
 192.855 +  return op;  /* return first untreated operator */
 192.856 +}
 192.857 +
 192.858 +
 192.859 +static void expr (LexState *ls, expdesc *v) {
 192.860 +  subexpr(ls, v, 0);
 192.861 +}
 192.862 +
 192.863 +/* }==================================================================== */
 192.864 +
 192.865 +
 192.866 +
 192.867 +/*
 192.868 +** {======================================================================
 192.869 +** Rules for Statements
 192.870 +** =======================================================================
 192.871 +*/
 192.872 +
 192.873 +
 192.874 +static int block_follow (int token) {
 192.875 +  switch (token) {
 192.876 +    case TK_ELSE: case TK_ELSEIF: case TK_END:
 192.877 +    case TK_UNTIL: case TK_EOS:
 192.878 +      return 1;
 192.879 +    default: return 0;
 192.880 +  }
 192.881 +}
 192.882 +
 192.883 +
 192.884 +static void block (LexState *ls) {
 192.885 +  /* block -> chunk */
 192.886 +  FuncState *fs = ls->fs;
 192.887 +  BlockCnt bl;
 192.888 +  enterblock(fs, &bl, 0);
 192.889 +  chunk(ls);
 192.890 +  lua_assert(bl.breaklist == NO_JUMP);
 192.891 +  leaveblock(fs);
 192.892 +}
 192.893 +
 192.894 +
 192.895 +/*
 192.896 +** structure to chain all variables in the left-hand side of an
 192.897 +** assignment
 192.898 +*/
 192.899 +struct LHS_assign {
 192.900 +  struct LHS_assign *prev;
 192.901 +  expdesc v;  /* variable (global, local, upvalue, or indexed) */
 192.902 +};
 192.903 +
 192.904 +
 192.905 +/*
 192.906 +** check whether, in an assignment to a local variable, the local variable
 192.907 +** is needed in a previous assignment (to a table). If so, save original
 192.908 +** local value in a safe place and use this safe copy in the previous
 192.909 +** assignment.
 192.910 +*/
 192.911 +static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
 192.912 +  FuncState *fs = ls->fs;
 192.913 +  int extra = fs->freereg;  /* eventual position to save local variable */
 192.914 +  int conflict = 0;
 192.915 +  for (; lh; lh = lh->prev) {
 192.916 +    if (lh->v.k == VINDEXED) {
 192.917 +      if (lh->v.u.s.info == v->u.s.info) {  /* conflict? */
 192.918 +        conflict = 1;
 192.919 +        lh->v.u.s.info = extra;  /* previous assignment will use safe copy */
 192.920 +      }
 192.921 +      if (lh->v.u.s.aux == v->u.s.info) {  /* conflict? */
 192.922 +        conflict = 1;
 192.923 +        lh->v.u.s.aux = extra;  /* previous assignment will use safe copy */
 192.924 +      }
 192.925 +    }
 192.926 +  }
 192.927 +  if (conflict) {
 192.928 +    luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.s.info, 0);  /* make copy */
 192.929 +    luaK_reserveregs(fs, 1);
 192.930 +  }
 192.931 +}
 192.932 +
 192.933 +
 192.934 +static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
 192.935 +  expdesc e;
 192.936 +  check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED,
 192.937 +                      "syntax error");
 192.938 +  if (testnext(ls, ',')) {  /* assignment -> `,' primaryexp assignment */
 192.939 +    struct LHS_assign nv;
 192.940 +    nv.prev = lh;
 192.941 +    primaryexp(ls, &nv.v);
 192.942 +    if (nv.v.k == VLOCAL)
 192.943 +      check_conflict(ls, lh, &nv.v);
 192.944 +    luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls,
 192.945 +                    "variables in assignment");
 192.946 +    assignment(ls, &nv, nvars+1);
 192.947 +  }
 192.948 +  else {  /* assignment -> `=' explist1 */
 192.949 +    int nexps;
 192.950 +    checknext(ls, '=');
 192.951 +    nexps = explist1(ls, &e);
 192.952 +    if (nexps != nvars) {
 192.953 +      adjust_assign(ls, nvars, nexps, &e);
 192.954 +      if (nexps > nvars)
 192.955 +        ls->fs->freereg -= nexps - nvars;  /* remove extra values */
 192.956 +    }
 192.957 +    else {
 192.958 +      luaK_setoneret(ls->fs, &e);  /* close last expression */
 192.959 +      luaK_storevar(ls->fs, &lh->v, &e);
 192.960 +      return;  /* avoid default */
 192.961 +    }
 192.962 +  }
 192.963 +  init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */
 192.964 +  luaK_storevar(ls->fs, &lh->v, &e);
 192.965 +}
 192.966 +
 192.967 +
 192.968 +static int cond (LexState *ls) {
 192.969 +  /* cond -> exp */
 192.970 +  expdesc v;
 192.971 +  expr(ls, &v);  /* read condition */
 192.972 +  if (v.k == VNIL) v.k = VFALSE;  /* `falses' are all equal here */
 192.973 +  luaK_goiftrue(ls->fs, &v);
 192.974 +  return v.f;
 192.975 +}
 192.976 +
 192.977 +
 192.978 +static void breakstat (LexState *ls) {
 192.979 +  FuncState *fs = ls->fs;
 192.980 +  BlockCnt *bl = fs->bl;
 192.981 +  int upval = 0;
 192.982 +  while (bl && !bl->isbreakable) {
 192.983 +    upval |= bl->upval;
 192.984 +    bl = bl->previous;
 192.985 +  }
 192.986 +  if (!bl)
 192.987 +    luaX_syntaxerror(ls, "no loop to break");
 192.988 +  if (upval)
 192.989 +    luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);
 192.990 +  luaK_concat(fs, &bl->breaklist, luaK_jump(fs));
 192.991 +}
 192.992 +
 192.993 +
 192.994 +static void whilestat (LexState *ls, int line) {
 192.995 +  /* whilestat -> WHILE cond DO block END */
 192.996 +  FuncState *fs = ls->fs;
 192.997 +  int whileinit;
 192.998 +  int condexit;
 192.999 +  BlockCnt bl;
192.1000 +  luaX_next(ls);  /* skip WHILE */
192.1001 +  whileinit = luaK_getlabel(fs);
192.1002 +  condexit = cond(ls);
192.1003 +  enterblock(fs, &bl, 1);
192.1004 +  checknext(ls, TK_DO);
192.1005 +  block(ls);
192.1006 +  luaK_patchlist(fs, luaK_jump(fs), whileinit);
192.1007 +  check_match(ls, TK_END, TK_WHILE, line);
192.1008 +  leaveblock(fs);
192.1009 +  luaK_patchtohere(fs, condexit);  /* false conditions finish the loop */
192.1010 +}
192.1011 +
192.1012 +
192.1013 +static void repeatstat (LexState *ls, int line) {
192.1014 +  /* repeatstat -> REPEAT block UNTIL cond */
192.1015 +  int condexit;
192.1016 +  FuncState *fs = ls->fs;
192.1017 +  int repeat_init = luaK_getlabel(fs);
192.1018 +  BlockCnt bl1, bl2;
192.1019 +  enterblock(fs, &bl1, 1);  /* loop block */
192.1020 +  enterblock(fs, &bl2, 0);  /* scope block */
192.1021 +  luaX_next(ls);  /* skip REPEAT */
192.1022 +  chunk(ls);
192.1023 +  check_match(ls, TK_UNTIL, TK_REPEAT, line);
192.1024 +  condexit = cond(ls);  /* read condition (inside scope block) */
192.1025 +  if (!bl2.upval) {  /* no upvalues? */
192.1026 +    leaveblock(fs);  /* finish scope */
192.1027 +    luaK_patchlist(ls->fs, condexit, repeat_init);  /* close the loop */
192.1028 +  }
192.1029 +  else {  /* complete semantics when there are upvalues */
192.1030 +    breakstat(ls);  /* if condition then break */
192.1031 +    luaK_patchtohere(ls->fs, condexit);  /* else... */
192.1032 +    leaveblock(fs);  /* finish scope... */
192.1033 +    luaK_patchlist(ls->fs, luaK_jump(fs), repeat_init);  /* and repeat */
192.1034 +  }
192.1035 +  leaveblock(fs);  /* finish loop */
192.1036 +}
192.1037 +
192.1038 +
192.1039 +static int exp1 (LexState *ls) {
192.1040 +  expdesc e;
192.1041 +  int k;
192.1042 +  expr(ls, &e);
192.1043 +  k = e.k;
192.1044 +  luaK_exp2nextreg(ls->fs, &e);
192.1045 +  return k;
192.1046 +}
192.1047 +
192.1048 +
192.1049 +static void forbody (LexState *ls, int base, int line, int nvars, int isnum) {
192.1050 +  /* forbody -> DO block */
192.1051 +  BlockCnt bl;
192.1052 +  FuncState *fs = ls->fs;
192.1053 +  int prep, endfor;
192.1054 +  adjustlocalvars(ls, 3);  /* control variables */
192.1055 +  checknext(ls, TK_DO);
192.1056 +  prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);
192.1057 +  enterblock(fs, &bl, 0);  /* scope for declared variables */
192.1058 +  adjustlocalvars(ls, nvars);
192.1059 +  luaK_reserveregs(fs, nvars);
192.1060 +  block(ls);
192.1061 +  leaveblock(fs);  /* end of scope for declared variables */
192.1062 +  luaK_patchtohere(fs, prep);
192.1063 +  endfor = (isnum) ? luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP) :
192.1064 +                     luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars);
192.1065 +  luaK_fixline(fs, line);  /* pretend that `OP_FOR' starts the loop */
192.1066 +  luaK_patchlist(fs, (isnum ? endfor : luaK_jump(fs)), prep + 1);
192.1067 +}
192.1068 +
192.1069 +
192.1070 +static void fornum (LexState *ls, TString *varname, int line) {
192.1071 +  /* fornum -> NAME = exp1,exp1[,exp1] forbody */
192.1072 +  FuncState *fs = ls->fs;
192.1073 +  int base = fs->freereg;
192.1074 +  new_localvarliteral(ls, "(for index)", 0);
192.1075 +  new_localvarliteral(ls, "(for limit)", 1);
192.1076 +  new_localvarliteral(ls, "(for step)", 2);
192.1077 +  new_localvar(ls, varname, 3);
192.1078 +  checknext(ls, '=');
192.1079 +  exp1(ls);  /* initial value */
192.1080 +  checknext(ls, ',');
192.1081 +  exp1(ls);  /* limit */
192.1082 +  if (testnext(ls, ','))
192.1083 +    exp1(ls);  /* optional step */
192.1084 +  else {  /* default step = 1 */
192.1085 +    luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1));
192.1086 +    luaK_reserveregs(fs, 1);
192.1087 +  }
192.1088 +  forbody(ls, base, line, 1, 1);
192.1089 +}
192.1090 +
192.1091 +
192.1092 +static void forlist (LexState *ls, TString *indexname) {
192.1093 +  /* forlist -> NAME {,NAME} IN explist1 forbody */
192.1094 +  FuncState *fs = ls->fs;
192.1095 +  expdesc e;
192.1096 +  int nvars = 0;
192.1097 +  int line;
192.1098 +  int base = fs->freereg;
192.1099 +  /* create control variables */
192.1100 +  new_localvarliteral(ls, "(for generator)", nvars++);
192.1101 +  new_localvarliteral(ls, "(for state)", nvars++);
192.1102 +  new_localvarliteral(ls, "(for control)", nvars++);
192.1103 +  /* create declared variables */
192.1104 +  new_localvar(ls, indexname, nvars++);
192.1105 +  while (testnext(ls, ','))
192.1106 +    new_localvar(ls, str_checkname(ls), nvars++);
192.1107 +  checknext(ls, TK_IN);
192.1108 +  line = ls->linenumber;
192.1109 +  adjust_assign(ls, 3, explist1(ls, &e), &e);
192.1110 +  luaK_checkstack(fs, 3);  /* extra space to call generator */
192.1111 +  forbody(ls, base, line, nvars - 3, 0);
192.1112 +}
192.1113 +
192.1114 +
192.1115 +static void forstat (LexState *ls, int line) {
192.1116 +  /* forstat -> FOR (fornum | forlist) END */
192.1117 +  FuncState *fs = ls->fs;
192.1118 +  TString *varname;
192.1119 +  BlockCnt bl;
192.1120 +  enterblock(fs, &bl, 1);  /* scope for loop and control variables */
192.1121 +  luaX_next(ls);  /* skip `for' */
192.1122 +  varname = str_checkname(ls);  /* first variable name */
192.1123 +  switch (ls->t.token) {
192.1124 +    case '=': fornum(ls, varname, line); break;
192.1125 +    case ',': case TK_IN: forlist(ls, varname); break;
192.1126 +    default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected");
192.1127 +  }
192.1128 +  check_match(ls, TK_END, TK_FOR, line);
192.1129 +  leaveblock(fs);  /* loop scope (`break' jumps to this point) */
192.1130 +}
192.1131 +
192.1132 +
192.1133 +static int test_then_block (LexState *ls) {
192.1134 +  /* test_then_block -> [IF | ELSEIF] cond THEN block */
192.1135 +  int condexit;
192.1136 +  luaX_next(ls);  /* skip IF or ELSEIF */
192.1137 +  condexit = cond(ls);
192.1138 +  checknext(ls, TK_THEN);
192.1139 +  block(ls);  /* `then' part */
192.1140 +  return condexit;
192.1141 +}
192.1142 +
192.1143 +
192.1144 +static void ifstat (LexState *ls, int line) {
192.1145 +  /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */
192.1146 +  FuncState *fs = ls->fs;
192.1147 +  int flist;
192.1148 +  int escapelist = NO_JUMP;
192.1149 +  flist = test_then_block(ls);  /* IF cond THEN block */
192.1150 +  while (ls->t.token == TK_ELSEIF) {
192.1151 +    luaK_concat(fs, &escapelist, luaK_jump(fs));
192.1152 +    luaK_patchtohere(fs, flist);
192.1153 +    flist = test_then_block(ls);  /* ELSEIF cond THEN block */
192.1154 +  }
192.1155 +  if (ls->t.token == TK_ELSE) {
192.1156 +    luaK_concat(fs, &escapelist, luaK_jump(fs));
192.1157 +    luaK_patchtohere(fs, flist);
192.1158 +    luaX_next(ls);  /* skip ELSE (after patch, for correct line info) */
192.1159 +    block(ls);  /* `else' part */
192.1160 +  }
192.1161 +  else
192.1162 +    luaK_concat(fs, &escapelist, flist);
192.1163 +  luaK_patchtohere(fs, escapelist);
192.1164 +  check_match(ls, TK_END, TK_IF, line);
192.1165 +}
192.1166 +
192.1167 +
192.1168 +static void localfunc (LexState *ls) {
192.1169 +  expdesc v, b;
192.1170 +  FuncState *fs = ls->fs;
192.1171 +  new_localvar(ls, str_checkname(ls), 0);
192.1172 +  init_exp(&v, VLOCAL, fs->freereg);
192.1173 +  luaK_reserveregs(fs, 1);
192.1174 +  adjustlocalvars(ls, 1);
192.1175 +  body(ls, &b, 0, ls->linenumber);
192.1176 +  luaK_storevar(fs, &v, &b);
192.1177 +  /* debug information will only see the variable after this point! */
192.1178 +  getlocvar(fs, fs->nactvar - 1).startpc = fs->pc;
192.1179 +}
192.1180 +
192.1181 +
192.1182 +static void localstat (LexState *ls) {
192.1183 +  /* stat -> LOCAL NAME {`,' NAME} [`=' explist1] */
192.1184 +  int nvars = 0;
192.1185 +  int nexps;
192.1186 +  expdesc e;
192.1187 +  do {
192.1188 +    new_localvar(ls, str_checkname(ls), nvars++);
192.1189 +  } while (testnext(ls, ','));
192.1190 +  if (testnext(ls, '='))
192.1191 +    nexps = explist1(ls, &e);
192.1192 +  else {
192.1193 +    e.k = VVOID;
192.1194 +    nexps = 0;
192.1195 +  }
192.1196 +  adjust_assign(ls, nvars, nexps, &e);
192.1197 +  adjustlocalvars(ls, nvars);
192.1198 +}
192.1199 +
192.1200 +
192.1201 +static int funcname (LexState *ls, expdesc *v) {
192.1202 +  /* funcname -> NAME {field} [`:' NAME] */
192.1203 +  int needself = 0;
192.1204 +  singlevar(ls, v);
192.1205 +  while (ls->t.token == '.')
192.1206 +    field(ls, v);
192.1207 +  if (ls->t.token == ':') {
192.1208 +    needself = 1;
192.1209 +    field(ls, v);
192.1210 +  }
192.1211 +  return needself;
192.1212 +}
192.1213 +
192.1214 +
192.1215 +static void funcstat (LexState *ls, int line) {
192.1216 +  /* funcstat -> FUNCTION funcname body */
192.1217 +  int needself;
192.1218 +  expdesc v, b;
192.1219 +  luaX_next(ls);  /* skip FUNCTION */
192.1220 +  needself = funcname(ls, &v);
192.1221 +  body(ls, &b, needself, line);
192.1222 +  luaK_storevar(ls->fs, &v, &b);
192.1223 +  luaK_fixline(ls->fs, line);  /* definition `happens' in the first line */
192.1224 +}
192.1225 +
192.1226 +
192.1227 +static void exprstat (LexState *ls) {
192.1228 +  /* stat -> func | assignment */
192.1229 +  FuncState *fs = ls->fs;
192.1230 +  struct LHS_assign v;
192.1231 +  primaryexp(ls, &v.v);
192.1232 +  if (v.v.k == VCALL)  /* stat -> func */
192.1233 +    SETARG_C(getcode(fs, &v.v), 1);  /* call statement uses no results */
192.1234 +  else {  /* stat -> assignment */
192.1235 +    v.prev = NULL;
192.1236 +    assignment(ls, &v, 1);
192.1237 +  }
192.1238 +}
192.1239 +
192.1240 +
192.1241 +static void retstat (LexState *ls) {
192.1242 +  /* stat -> RETURN explist */
192.1243 +  FuncState *fs = ls->fs;
192.1244 +  expdesc e;
192.1245 +  int first, nret;  /* registers with returned values */
192.1246 +  luaX_next(ls);  /* skip RETURN */
192.1247 +  if (block_follow(ls->t.token) || ls->t.token == ';')
192.1248 +    first = nret = 0;  /* return no values */
192.1249 +  else {
192.1250 +    nret = explist1(ls, &e);  /* optional return values */
192.1251 +    if (hasmultret(e.k)) {
192.1252 +      luaK_setmultret(fs, &e);
192.1253 +      if (e.k == VCALL && nret == 1) {  /* tail call? */
192.1254 +        SET_OPCODE(getcode(fs,&e), OP_TAILCALL);
192.1255 +        lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar);
192.1256 +      }
192.1257 +      first = fs->nactvar;
192.1258 +      nret = LUA_MULTRET;  /* return all values */
192.1259 +    }
192.1260 +    else {
192.1261 +      if (nret == 1)  /* only one single value? */
192.1262 +        first = luaK_exp2anyreg(fs, &e);
192.1263 +      else {
192.1264 +        luaK_exp2nextreg(fs, &e);  /* values must go to the `stack' */
192.1265 +        first = fs->nactvar;  /* return all `active' values */
192.1266 +        lua_assert(nret == fs->freereg - first);
192.1267 +      }
192.1268 +    }
192.1269 +  }
192.1270 +  luaK_ret(fs, first, nret);
192.1271 +}
192.1272 +
192.1273 +
192.1274 +static int statement (LexState *ls) {
192.1275 +  int line = ls->linenumber;  /* may be needed for error messages */
192.1276 +  switch (ls->t.token) {
192.1277 +    case TK_IF: {  /* stat -> ifstat */
192.1278 +      ifstat(ls, line);
192.1279 +      return 0;
192.1280 +    }
192.1281 +    case TK_WHILE: {  /* stat -> whilestat */
192.1282 +      whilestat(ls, line);
192.1283 +      return 0;
192.1284 +    }
192.1285 +    case TK_DO: {  /* stat -> DO block END */
192.1286 +      luaX_next(ls);  /* skip DO */
192.1287 +      block(ls);
192.1288 +      check_match(ls, TK_END, TK_DO, line);
192.1289 +      return 0;
192.1290 +    }
192.1291 +    case TK_FOR: {  /* stat -> forstat */
192.1292 +      forstat(ls, line);
192.1293 +      return 0;
192.1294 +    }
192.1295 +    case TK_REPEAT: {  /* stat -> repeatstat */
192.1296 +      repeatstat(ls, line);
192.1297 +      return 0;
192.1298 +    }
192.1299 +    case TK_FUNCTION: {
192.1300 +      funcstat(ls, line);  /* stat -> funcstat */
192.1301 +      return 0;
192.1302 +    }
192.1303 +    case TK_LOCAL: {  /* stat -> localstat */
192.1304 +      luaX_next(ls);  /* skip LOCAL */
192.1305 +      if (testnext(ls, TK_FUNCTION))  /* local function? */
192.1306 +        localfunc(ls);
192.1307 +      else
192.1308 +        localstat(ls);
192.1309 +      return 0;
192.1310 +    }
192.1311 +    case TK_RETURN: {  /* stat -> retstat */
192.1312 +      retstat(ls);
192.1313 +      return 1;  /* must be last statement */
192.1314 +    }
192.1315 +    case TK_BREAK: {  /* stat -> breakstat */
192.1316 +      luaX_next(ls);  /* skip BREAK */
192.1317 +      breakstat(ls);
192.1318 +      return 1;  /* must be last statement */
192.1319 +    }
192.1320 +    default: {
192.1321 +      exprstat(ls);
192.1322 +      return 0;  /* to avoid warnings */
192.1323 +    }
192.1324 +  }
192.1325 +}
192.1326 +
192.1327 +
192.1328 +static void chunk (LexState *ls) {
192.1329 +  /* chunk -> { stat [`;'] } */
192.1330 +  int islast = 0;
192.1331 +  enterlevel(ls);
192.1332 +  while (!islast && !block_follow(ls->t.token)) {
192.1333 +    islast = statement(ls);
192.1334 +    testnext(ls, ';');
192.1335 +    lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg &&
192.1336 +               ls->fs->freereg >= ls->fs->nactvar);
192.1337 +    ls->fs->freereg = ls->fs->nactvar;  /* free registers */
192.1338 +  }
192.1339 +  leavelevel(ls);
192.1340 +}
192.1341 +
192.1342 +/* }====================================================================== */
   193.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   193.2 +++ b/src/lua/src/lparser.h	Sat Mar 03 10:31:27 2012 -0600
   193.3 @@ -0,0 +1,82 @@
   193.4 +/*
   193.5 +** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $
   193.6 +** Lua Parser
   193.7 +** See Copyright Notice in lua.h
   193.8 +*/
   193.9 +
  193.10 +#ifndef lparser_h
  193.11 +#define lparser_h
  193.12 +
  193.13 +#include "llimits.h"
  193.14 +#include "lobject.h"
  193.15 +#include "lzio.h"
  193.16 +
  193.17 +
  193.18 +/*
  193.19 +** Expression descriptor
  193.20 +*/
  193.21 +
  193.22 +typedef enum {
  193.23 +  VVOID,	/* no value */
  193.24 +  VNIL,
  193.25 +  VTRUE,
  193.26 +  VFALSE,
  193.27 +  VK,		/* info = index of constant in `k' */
  193.28 +  VKNUM,	/* nval = numerical value */
  193.29 +  VLOCAL,	/* info = local register */
  193.30 +  VUPVAL,       /* info = index of upvalue in `upvalues' */
  193.31 +  VGLOBAL,	/* info = index of table; aux = index of global name in `k' */
  193.32 +  VINDEXED,	/* info = table register; aux = index register (or `k') */
  193.33 +  VJMP,		/* info = instruction pc */
  193.34 +  VRELOCABLE,	/* info = instruction pc */
  193.35 +  VNONRELOC,	/* info = result register */
  193.36 +  VCALL,	/* info = instruction pc */
  193.37 +  VVARARG	/* info = instruction pc */
  193.38 +} expkind;
  193.39 +
  193.40 +typedef struct expdesc {
  193.41 +  expkind k;
  193.42 +  union {
  193.43 +    struct { int info, aux; } s;
  193.44 +    lua_Number nval;
  193.45 +  } u;
  193.46 +  int t;  /* patch list of `exit when true' */
  193.47 +  int f;  /* patch list of `exit when false' */
  193.48 +} expdesc;
  193.49 +
  193.50 +
  193.51 +typedef struct upvaldesc {
  193.52 +  lu_byte k;
  193.53 +  lu_byte info;
  193.54 +} upvaldesc;
  193.55 +
  193.56 +
  193.57 +struct BlockCnt;  /* defined in lparser.c */
  193.58 +
  193.59 +
  193.60 +/* state needed to generate code for a given function */
  193.61 +typedef struct FuncState {
  193.62 +  Proto *f;  /* current function header */
  193.63 +  Table *h;  /* table to find (and reuse) elements in `k' */
  193.64 +  struct FuncState *prev;  /* enclosing function */
  193.65 +  struct LexState *ls;  /* lexical state */
  193.66 +  struct lua_State *L;  /* copy of the Lua state */
  193.67 +  struct BlockCnt *bl;  /* chain of current blocks */
  193.68 +  int pc;  /* next position to code (equivalent to `ncode') */
  193.69 +  int lasttarget;   /* `pc' of last `jump target' */
  193.70 +  int jpc;  /* list of pending jumps to `pc' */
  193.71 +  int freereg;  /* first free register */
  193.72 +  int nk;  /* number of elements in `k' */
  193.73 +  int np;  /* number of elements in `p' */
  193.74 +  short nlocvars;  /* number of elements in `locvars' */
  193.75 +  lu_byte nactvar;  /* number of active local variables */
  193.76 +  upvaldesc upvalues[LUAI_MAXUPVALUES];  /* upvalues */
  193.77 +  unsigned short actvar[LUAI_MAXVARS];  /* declared-variable stack */
  193.78 +} FuncState;
  193.79 +
  193.80 +
  193.81 +LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
  193.82 +                                            const char *name);
  193.83 +
  193.84 +
  193.85 +#endif
   194.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   194.2 +++ b/src/lua/src/lstate.c	Sat Mar 03 10:31:27 2012 -0600
   194.3 @@ -0,0 +1,214 @@
   194.4 +/*
   194.5 +** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $
   194.6 +** Global State
   194.7 +** See Copyright Notice in lua.h
   194.8 +*/
   194.9 +
  194.10 +
  194.11 +#include <stddef.h>
  194.12 +
  194.13 +#define lstate_c
  194.14 +#define LUA_CORE
  194.15 +
  194.16 +#include "lua.h"
  194.17 +
  194.18 +#include "ldebug.h"
  194.19 +#include "ldo.h"
  194.20 +#include "lfunc.h"
  194.21 +#include "lgc.h"
  194.22 +#include "llex.h"
  194.23 +#include "lmem.h"
  194.24 +#include "lstate.h"
  194.25 +#include "lstring.h"
  194.26 +#include "ltable.h"
  194.27 +#include "ltm.h"
  194.28 +
  194.29 +
  194.30 +#define state_size(x)	(sizeof(x) + LUAI_EXTRASPACE)
  194.31 +#define fromstate(l)	(cast(lu_byte *, (l)) - LUAI_EXTRASPACE)
  194.32 +#define tostate(l)   (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))
  194.33 +
  194.34 +
  194.35 +/*
  194.36 +** Main thread combines a thread state and the global state
  194.37 +*/
  194.38 +typedef struct LG {
  194.39 +  lua_State l;
  194.40 +  global_State g;
  194.41 +} LG;
  194.42 +  
  194.43 +
  194.44 +
  194.45 +static void stack_init (lua_State *L1, lua_State *L) {
  194.46 +  /* initialize CallInfo array */
  194.47 +  L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo);
  194.48 +  L1->ci = L1->base_ci;
  194.49 +  L1->size_ci = BASIC_CI_SIZE;
  194.50 +  L1->end_ci = L1->base_ci + L1->size_ci - 1;
  194.51 +  /* initialize stack array */
  194.52 +  L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue);
  194.53 +  L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK;
  194.54 +  L1->top = L1->stack;
  194.55 +  L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1;
  194.56 +  /* initialize first ci */
  194.57 +  L1->ci->func = L1->top;
  194.58 +  setnilvalue(L1->top++);  /* `function' entry for this `ci' */
  194.59 +  L1->base = L1->ci->base = L1->top;
  194.60 +  L1->ci->top = L1->top + LUA_MINSTACK;
  194.61 +}
  194.62 +
  194.63 +
  194.64 +static void freestack (lua_State *L, lua_State *L1) {
  194.65 +  luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo);
  194.66 +  luaM_freearray(L, L1->stack, L1->stacksize, TValue);
  194.67 +}
  194.68 +
  194.69 +
  194.70 +/*
  194.71 +** open parts that may cause memory-allocation errors
  194.72 +*/
  194.73 +static void f_luaopen (lua_State *L, void *ud) {
  194.74 +  global_State *g = G(L);
  194.75 +  UNUSED(ud);
  194.76 +  stack_init(L, L);  /* init stack */
  194.77 +  sethvalue(L, gt(L), luaH_new(L, 0, 2));  /* table of globals */
  194.78 +  sethvalue(L, registry(L), luaH_new(L, 0, 2));  /* registry */
  194.79 +  luaS_resize(L, MINSTRTABSIZE);  /* initial size of string table */
  194.80 +  luaT_init(L);
  194.81 +  luaX_init(L);
  194.82 +  luaS_fix(luaS_newliteral(L, MEMERRMSG));
  194.83 +  g->GCthreshold = 4*g->totalbytes;
  194.84 +}
  194.85 +
  194.86 +
  194.87 +static void preinit_state (lua_State *L, global_State *g) {
  194.88 +  G(L) = g;
  194.89 +  L->stack = NULL;
  194.90 +  L->stacksize = 0;
  194.91 +  L->errorJmp = NULL;
  194.92 +  L->hook = NULL;
  194.93 +  L->hookmask = 0;
  194.94 +  L->basehookcount = 0;
  194.95 +  L->allowhook = 1;
  194.96 +  resethookcount(L);
  194.97 +  L->openupval = NULL;
  194.98 +  L->size_ci = 0;
  194.99 +  L->nCcalls = L->baseCcalls = 0;
 194.100 +  L->status = 0;
 194.101 +  L->base_ci = L->ci = NULL;
 194.102 +  L->savedpc = NULL;
 194.103 +  L->errfunc = 0;
 194.104 +  setnilvalue(gt(L));
 194.105 +}
 194.106 +
 194.107 +
 194.108 +static void close_state (lua_State *L) {
 194.109 +  global_State *g = G(L);
 194.110 +  luaF_close(L, L->stack);  /* close all upvalues for this thread */
 194.111 +  luaC_freeall(L);  /* collect all objects */
 194.112 +  lua_assert(g->rootgc == obj2gco(L));
 194.113 +  lua_assert(g->strt.nuse == 0);
 194.114 +  luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *);
 194.115 +  luaZ_freebuffer(L, &g->buff);
 194.116 +  freestack(L, L);
 194.117 +  lua_assert(g->totalbytes == sizeof(LG));
 194.118 +  (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0);
 194.119 +}
 194.120 +
 194.121 +
 194.122 +lua_State *luaE_newthread (lua_State *L) {
 194.123 +  lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State)));
 194.124 +  luaC_link(L, obj2gco(L1), LUA_TTHREAD);
 194.125 +  preinit_state(L1, G(L));
 194.126 +  stack_init(L1, L);  /* init stack */
 194.127 +  setobj2n(L, gt(L1), gt(L));  /* share table of globals */
 194.128 +  L1->hookmask = L->hookmask;
 194.129 +  L1->basehookcount = L->basehookcount;
 194.130 +  L1->hook = L->hook;
 194.131 +  resethookcount(L1);
 194.132 +  lua_assert(iswhite(obj2gco(L1)));
 194.133 +  return L1;
 194.134 +}
 194.135 +
 194.136 +
 194.137 +void luaE_freethread (lua_State *L, lua_State *L1) {
 194.138 +  luaF_close(L1, L1->stack);  /* close all upvalues for this thread */
 194.139 +  lua_assert(L1->openupval == NULL);
 194.140 +  luai_userstatefree(L1);
 194.141 +  freestack(L, L1);
 194.142 +  luaM_freemem(L, fromstate(L1), state_size(lua_State));
 194.143 +}
 194.144 +
 194.145 +
 194.146 +LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
 194.147 +  int i;
 194.148 +  lua_State *L;
 194.149 +  global_State *g;
 194.150 +  void *l = (*f)(ud, NULL, 0, state_size(LG));
 194.151 +  if (l == NULL) return NULL;
 194.152 +  L = tostate(l);
 194.153 +  g = &((LG *)L)->g;
 194.154 +  L->next = NULL;
 194.155 +  L->tt = LUA_TTHREAD;
 194.156 +  g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);
 194.157 +  L->marked = luaC_white(g);
 194.158 +  set2bits(L->marked, FIXEDBIT, SFIXEDBIT);
 194.159 +  preinit_state(L, g);
 194.160 +  g->frealloc = f;
 194.161 +  g->ud = ud;
 194.162 +  g->mainthread = L;
 194.163 +  g->uvhead.u.l.prev = &g->uvhead;
 194.164 +  g->uvhead.u.l.next = &g->uvhead;
 194.165 +  g->GCthreshold = 0;  /* mark it as unfinished state */
 194.166 +  g->strt.size = 0;
 194.167 +  g->strt.nuse = 0;
 194.168 +  g->strt.hash = NULL;
 194.169 +  setnilvalue(registry(L));
 194.170 +  luaZ_initbuffer(L, &g->buff);
 194.171 +  g->panic = NULL;
 194.172 +  g->gcstate = GCSpause;
 194.173 +  g->rootgc = obj2gco(L);
 194.174 +  g->sweepstrgc = 0;
 194.175 +  g->sweepgc = &g->rootgc;
 194.176 +  g->gray = NULL;
 194.177 +  g->grayagain = NULL;
 194.178 +  g->weak = NULL;
 194.179 +  g->tmudata = NULL;
 194.180 +  g->totalbytes = sizeof(LG);
 194.181 +  g->gcpause = LUAI_GCPAUSE;
 194.182 +  g->gcstepmul = LUAI_GCMUL;
 194.183 +  g->gcdept = 0;
 194.184 +  for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;
 194.185 +  if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
 194.186 +    /* memory allocation error: free partial state */
 194.187 +    close_state(L);
 194.188 +    L = NULL;
 194.189 +  }
 194.190 +  else
 194.191 +    luai_userstateopen(L);
 194.192 +  return L;
 194.193 +}
 194.194 +
 194.195 +
 194.196 +static void callallgcTM (lua_State *L, void *ud) {
 194.197 +  UNUSED(ud);
 194.198 +  luaC_callGCTM(L);  /* call GC metamethods for all udata */
 194.199 +}
 194.200 +
 194.201 +
 194.202 +LUA_API void lua_close (lua_State *L) {
 194.203 +  L = G(L)->mainthread;  /* only the main thread can be closed */
 194.204 +  lua_lock(L);
 194.205 +  luaF_close(L, L->stack);  /* close all upvalues for this thread */
 194.206 +  luaC_separateudata(L, 1);  /* separate udata that have GC metamethods */
 194.207 +  L->errfunc = 0;  /* no error function during GC metamethods */
 194.208 +  do {  /* repeat until no more errors */
 194.209 +    L->ci = L->base_ci;
 194.210 +    L->base = L->top = L->ci->base;
 194.211 +    L->nCcalls = L->baseCcalls = 0;
 194.212 +  } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
 194.213 +  lua_assert(G(L)->tmudata == NULL);
 194.214 +  luai_userstateclose(L);
 194.215 +  close_state(L);
 194.216 +}
 194.217 +
   195.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   195.2 +++ b/src/lua/src/lstate.h	Sat Mar 03 10:31:27 2012 -0600
   195.3 @@ -0,0 +1,169 @@
   195.4 +/*
   195.5 +** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $
   195.6 +** Global State
   195.7 +** See Copyright Notice in lua.h
   195.8 +*/
   195.9 +
  195.10 +#ifndef lstate_h
  195.11 +#define lstate_h
  195.12 +
  195.13 +#include "lua.h"
  195.14 +
  195.15 +#include "lobject.h"
  195.16 +#include "ltm.h"
  195.17 +#include "lzio.h"
  195.18 +
  195.19 +
  195.20 +
  195.21 +struct lua_longjmp;  /* defined in ldo.c */
  195.22 +
  195.23 +
  195.24 +/* table of globals */
  195.25 +#define gt(L)	(&L->l_gt)
  195.26 +
  195.27 +/* registry */
  195.28 +#define registry(L)	(&G(L)->l_registry)
  195.29 +
  195.30 +
  195.31 +/* extra stack space to handle TM calls and some other extras */
  195.32 +#define EXTRA_STACK   5
  195.33 +
  195.34 +
  195.35 +#define BASIC_CI_SIZE           8
  195.36 +
  195.37 +#define BASIC_STACK_SIZE        (2*LUA_MINSTACK)
  195.38 +
  195.39 +
  195.40 +
  195.41 +typedef struct stringtable {
  195.42 +  GCObject **hash;
  195.43 +  lu_int32 nuse;  /* number of elements */
  195.44 +  int size;
  195.45 +} stringtable;
  195.46 +
  195.47 +
  195.48 +/*
  195.49 +** informations about a call
  195.50 +*/
  195.51 +typedef struct CallInfo {
  195.52 +  StkId base;  /* base for this function */
  195.53 +  StkId func;  /* function index in the stack */
  195.54 +  StkId	top;  /* top for this function */
  195.55 +  const Instruction *savedpc;
  195.56 +  int nresults;  /* expected number of results from this function */
  195.57 +  int tailcalls;  /* number of tail calls lost under this entry */
  195.58 +} CallInfo;
  195.59 +
  195.60 +
  195.61 +
  195.62 +#define curr_func(L)	(clvalue(L->ci->func))
  195.63 +#define ci_func(ci)	(clvalue((ci)->func))
  195.64 +#define f_isLua(ci)	(!ci_func(ci)->c.isC)
  195.65 +#define isLua(ci)	(ttisfunction((ci)->func) && f_isLua(ci))
  195.66 +
  195.67 +
  195.68 +/*
  195.69 +** `global state', shared by all threads of this state
  195.70 +*/
  195.71 +typedef struct global_State {
  195.72 +  stringtable strt;  /* hash table for strings */
  195.73 +  lua_Alloc frealloc;  /* function to reallocate memory */
  195.74 +  void *ud;         /* auxiliary data to `frealloc' */
  195.75 +  lu_byte currentwhite;
  195.76 +  lu_byte gcstate;  /* state of garbage collector */
  195.77 +  int sweepstrgc;  /* position of sweep in `strt' */
  195.78 +  GCObject *rootgc;  /* list of all collectable objects */
  195.79 +  GCObject **sweepgc;  /* position of sweep in `rootgc' */
  195.80 +  GCObject *gray;  /* list of gray objects */
  195.81 +  GCObject *grayagain;  /* list of objects to be traversed atomically */
  195.82 +  GCObject *weak;  /* list of weak tables (to be cleared) */
  195.83 +  GCObject *tmudata;  /* last element of list of userdata to be GC */
  195.84 +  Mbuffer buff;  /* temporary buffer for string concatentation */
  195.85 +  lu_mem GCthreshold;
  195.86 +  lu_mem totalbytes;  /* number of bytes currently allocated */
  195.87 +  lu_mem estimate;  /* an estimate of number of bytes actually in use */
  195.88 +  lu_mem gcdept;  /* how much GC is `behind schedule' */
  195.89 +  int gcpause;  /* size of pause between successive GCs */
  195.90 +  int gcstepmul;  /* GC `granularity' */
  195.91 +  lua_CFunction panic;  /* to be called in unprotected errors */
  195.92 +  TValue l_registry;
  195.93 +  struct lua_State *mainthread;
  195.94 +  UpVal uvhead;  /* head of double-linked list of all open upvalues */
  195.95 +  struct Table *mt[NUM_TAGS];  /* metatables for basic types */
  195.96 +  TString *tmname[TM_N];  /* array with tag-method names */
  195.97 +} global_State;
  195.98 +
  195.99 +
 195.100 +/*
 195.101 +** `per thread' state
 195.102 +*/
 195.103 +struct lua_State {
 195.104 +  CommonHeader;
 195.105 +  lu_byte status;
 195.106 +  StkId top;  /* first free slot in the stack */
 195.107 +  StkId base;  /* base of current function */
 195.108 +  global_State *l_G;
 195.109 +  CallInfo *ci;  /* call info for current function */
 195.110 +  const Instruction *savedpc;  /* `savedpc' of current function */
 195.111 +  StkId stack_last;  /* last free slot in the stack */
 195.112 +  StkId stack;  /* stack base */
 195.113 +  CallInfo *end_ci;  /* points after end of ci array*/
 195.114 +  CallInfo *base_ci;  /* array of CallInfo's */
 195.115 +  int stacksize;
 195.116 +  int size_ci;  /* size of array `base_ci' */
 195.117 +  unsigned short nCcalls;  /* number of nested C calls */
 195.118 +  unsigned short baseCcalls;  /* nested C calls when resuming coroutine */
 195.119 +  lu_byte hookmask;
 195.120 +  lu_byte allowhook;
 195.121 +  int basehookcount;
 195.122 +  int hookcount;
 195.123 +  lua_Hook hook;
 195.124 +  TValue l_gt;  /* table of globals */
 195.125 +  TValue env;  /* temporary place for environments */
 195.126 +  GCObject *openupval;  /* list of open upvalues in this stack */
 195.127 +  GCObject *gclist;
 195.128 +  struct lua_longjmp *errorJmp;  /* current error recover point */
 195.129 +  ptrdiff_t errfunc;  /* current error handling function (stack index) */
 195.130 +};
 195.131 +
 195.132 +
 195.133 +#define G(L)	(L->l_G)
 195.134 +
 195.135 +
 195.136 +/*
 195.137 +** Union of all collectable objects
 195.138 +*/
 195.139 +union GCObject {
 195.140 +  GCheader gch;
 195.141 +  union TString ts;
 195.142 +  union Udata u;
 195.143 +  union Closure cl;
 195.144 +  struct Table h;
 195.145 +  struct Proto p;
 195.146 +  struct UpVal uv;
 195.147 +  struct lua_State th;  /* thread */
 195.148 +};
 195.149 +
 195.150 +
 195.151 +/* macros to convert a GCObject into a specific value */
 195.152 +#define rawgco2ts(o)	check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
 195.153 +#define gco2ts(o)	(&rawgco2ts(o)->tsv)
 195.154 +#define rawgco2u(o)	check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
 195.155 +#define gco2u(o)	(&rawgco2u(o)->uv)
 195.156 +#define gco2cl(o)	check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
 195.157 +#define gco2h(o)	check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
 195.158 +#define gco2p(o)	check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
 195.159 +#define gco2uv(o)	check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
 195.160 +#define ngcotouv(o) \
 195.161 +	check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
 195.162 +#define gco2th(o)	check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
 195.163 +
 195.164 +/* macro to convert any Lua object into a GCObject */
 195.165 +#define obj2gco(v)	(cast(GCObject *, (v)))
 195.166 +
 195.167 +
 195.168 +LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
 195.169 +LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
 195.170 +
 195.171 +#endif
 195.172 +
   196.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   196.2 +++ b/src/lua/src/lstring.c	Sat Mar 03 10:31:27 2012 -0600
   196.3 @@ -0,0 +1,111 @@
   196.4 +/*
   196.5 +** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
   196.6 +** String table (keeps all strings handled by Lua)
   196.7 +** See Copyright Notice in lua.h
   196.8 +*/
   196.9 +
  196.10 +
  196.11 +#include <string.h>
  196.12 +
  196.13 +#define lstring_c
  196.14 +#define LUA_CORE
  196.15 +
  196.16 +#include "lua.h"
  196.17 +
  196.18 +#include "lmem.h"
  196.19 +#include "lobject.h"
  196.20 +#include "lstate.h"
  196.21 +#include "lstring.h"
  196.22 +
  196.23 +
  196.24 +
  196.25 +void luaS_resize (lua_State *L, int newsize) {
  196.26 +  GCObject **newhash;
  196.27 +  stringtable *tb;
  196.28 +  int i;
  196.29 +  if (G(L)->gcstate == GCSsweepstring)
  196.30 +    return;  /* cannot resize during GC traverse */
  196.31 +  newhash = luaM_newvector(L, newsize, GCObject *);
  196.32 +  tb = &G(L)->strt;
  196.33 +  for (i=0; i<newsize; i++) newhash[i] = NULL;
  196.34 +  /* rehash */
  196.35 +  for (i=0; i<tb->size; i++) {
  196.36 +    GCObject *p = tb->hash[i];
  196.37 +    while (p) {  /* for each node in the list */
  196.38 +      GCObject *next = p->gch.next;  /* save next */
  196.39 +      unsigned int h = gco2ts(p)->hash;
  196.40 +      int h1 = lmod(h, newsize);  /* new position */
  196.41 +      lua_assert(cast_int(h%newsize) == lmod(h, newsize));
  196.42 +      p->gch.next = newhash[h1];  /* chain it */
  196.43 +      newhash[h1] = p;
  196.44 +      p = next;
  196.45 +    }
  196.46 +  }
  196.47 +  luaM_freearray(L, tb->hash, tb->size, TString *);
  196.48 +  tb->size = newsize;
  196.49 +  tb->hash = newhash;
  196.50 +}
  196.51 +
  196.52 +
  196.53 +static TString *newlstr (lua_State *L, const char *str, size_t l,
  196.54 +                                       unsigned int h) {
  196.55 +  TString *ts;
  196.56 +  stringtable *tb;
  196.57 +  if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
  196.58 +    luaM_toobig(L);
  196.59 +  ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString)));
  196.60 +  ts->tsv.len = l;
  196.61 +  ts->tsv.hash = h;
  196.62 +  ts->tsv.marked = luaC_white(G(L));
  196.63 +  ts->tsv.tt = LUA_TSTRING;
  196.64 +  ts->tsv.reserved = 0;
  196.65 +  memcpy(ts+1, str, l*sizeof(char));
  196.66 +  ((char *)(ts+1))[l] = '\0';  /* ending 0 */
  196.67 +  tb = &G(L)->strt;
  196.68 +  h = lmod(h, tb->size);
  196.69 +  ts->tsv.next = tb->hash[h];  /* chain new entry */
  196.70 +  tb->hash[h] = obj2gco(ts);
  196.71 +  tb->nuse++;
  196.72 +  if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)
  196.73 +    luaS_resize(L, tb->size*2);  /* too crowded */
  196.74 +  return ts;
  196.75 +}
  196.76 +
  196.77 +
  196.78 +TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
  196.79 +  GCObject *o;
  196.80 +  unsigned int h = cast(unsigned int, l);  /* seed */
  196.81 +  size_t step = (l>>5)+1;  /* if string is too long, don't hash all its chars */
  196.82 +  size_t l1;
  196.83 +  for (l1=l; l1>=step; l1-=step)  /* compute hash */
  196.84 +    h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1]));
  196.85 +  for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
  196.86 +       o != NULL;
  196.87 +       o = o->gch.next) {
  196.88 +    TString *ts = rawgco2ts(o);
  196.89 +    if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) {
  196.90 +      /* string may be dead */
  196.91 +      if (isdead(G(L), o)) changewhite(o);
  196.92 +      return ts;
  196.93 +    }
  196.94 +  }
  196.95 +  return newlstr(L, str, l, h);  /* not found */
  196.96 +}
  196.97 +
  196.98 +
  196.99 +Udata *luaS_newudata (lua_State *L, size_t s, Table *e) {
 196.100 +  Udata *u;
 196.101 +  if (s > MAX_SIZET - sizeof(Udata))
 196.102 +    luaM_toobig(L);
 196.103 +  u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata)));
 196.104 +  u->uv.marked = luaC_white(G(L));  /* is not finalized */
 196.105 +  u->uv.tt = LUA_TUSERDATA;
 196.106 +  u->uv.len = s;
 196.107 +  u->uv.metatable = NULL;
 196.108 +  u->uv.env = e;
 196.109 +  /* chain it on udata list (after main thread) */
 196.110 +  u->uv.next = G(L)->mainthread->next;
 196.111 +  G(L)->mainthread->next = obj2gco(u);
 196.112 +  return u;
 196.113 +}
 196.114 +
   197.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   197.2 +++ b/src/lua/src/lstring.h	Sat Mar 03 10:31:27 2012 -0600
   197.3 @@ -0,0 +1,31 @@
   197.4 +/*
   197.5 +** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $
   197.6 +** String table (keep all strings handled by Lua)
   197.7 +** See Copyright Notice in lua.h
   197.8 +*/
   197.9 +
  197.10 +#ifndef lstring_h
  197.11 +#define lstring_h
  197.12 +
  197.13 +
  197.14 +#include "lgc.h"
  197.15 +#include "lobject.h"
  197.16 +#include "lstate.h"
  197.17 +
  197.18 +
  197.19 +#define sizestring(s)	(sizeof(union TString)+((s)->len+1)*sizeof(char))
  197.20 +
  197.21 +#define sizeudata(u)	(sizeof(union Udata)+(u)->len)
  197.22 +
  197.23 +#define luaS_new(L, s)	(luaS_newlstr(L, s, strlen(s)))
  197.24 +#define luaS_newliteral(L, s)	(luaS_newlstr(L, "" s, \
  197.25 +                                 (sizeof(s)/sizeof(char))-1))
  197.26 +
  197.27 +#define luaS_fix(s)	l_setbit((s)->tsv.marked, FIXEDBIT)
  197.28 +
  197.29 +LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
  197.30 +LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
  197.31 +LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
  197.32 +
  197.33 +
  197.34 +#endif
   198.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   198.2 +++ b/src/lua/src/lstrlib.c	Sat Mar 03 10:31:27 2012 -0600
   198.3 @@ -0,0 +1,869 @@
   198.4 +/*
   198.5 +** $Id: lstrlib.c,v 1.132.1.4 2008/07/11 17:27:21 roberto Exp $
   198.6 +** Standard library for string operations and pattern-matching
   198.7 +** See Copyright Notice in lua.h
   198.8 +*/
   198.9 +
  198.10 +
  198.11 +#include <ctype.h>
  198.12 +#include <stddef.h>
  198.13 +#include <stdio.h>
  198.14 +#include <stdlib.h>
  198.15 +#include <string.h>
  198.16 +
  198.17 +#define lstrlib_c
  198.18 +#define LUA_LIB
  198.19 +
  198.20 +#include "lua.h"
  198.21 +
  198.22 +#include "lauxlib.h"
  198.23 +#include "lualib.h"
  198.24 +
  198.25 +
  198.26 +/* macro to `unsign' a character */
  198.27 +#define uchar(c)        ((unsigned char)(c))
  198.28 +
  198.29 +
  198.30 +
  198.31 +static int str_len (lua_State *L) {
  198.32 +  size_t l;
  198.33 +  luaL_checklstring(L, 1, &l);
  198.34 +  lua_pushinteger(L, l);
  198.35 +  return 1;
  198.36 +}
  198.37 +
  198.38 +
  198.39 +static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) {
  198.40 +  /* relative string position: negative means back from end */
  198.41 +  if (pos < 0) pos += (ptrdiff_t)len + 1;
  198.42 +  return (pos >= 0) ? pos : 0;
  198.43 +}
  198.44 +
  198.45 +
  198.46 +static int str_sub (lua_State *L) {
  198.47 +  size_t l;
  198.48 +  const char *s = luaL_checklstring(L, 1, &l);
  198.49 +  ptrdiff_t start = posrelat(luaL_checkinteger(L, 2), l);
  198.50 +  ptrdiff_t end = posrelat(luaL_optinteger(L, 3, -1), l);
  198.51 +  if (start < 1) start = 1;
  198.52 +  if (end > (ptrdiff_t)l) end = (ptrdiff_t)l;
  198.53 +  if (start <= end)
  198.54 +    lua_pushlstring(L, s+start-1, end-start+1);
  198.55 +  else lua_pushliteral(L, "");
  198.56 +  return 1;
  198.57 +}
  198.58 +
  198.59 +
  198.60 +static int str_reverse (lua_State *L) {
  198.61 +  size_t l;
  198.62 +  luaL_Buffer b;
  198.63 +  const char *s = luaL_checklstring(L, 1, &l);
  198.64 +  luaL_buffinit(L, &b);
  198.65 +  while (l--) luaL_addchar(&b, s[l]);
  198.66 +  luaL_pushresult(&b);
  198.67 +  return 1;
  198.68 +}
  198.69 +
  198.70 +
  198.71 +static int str_lower (lua_State *L) {
  198.72 +  size_t l;
  198.73 +  size_t i;
  198.74 +  luaL_Buffer b;
  198.75 +  const char *s = luaL_checklstring(L, 1, &l);
  198.76 +  luaL_buffinit(L, &b);
  198.77 +  for (i=0; i<l; i++)
  198.78 +    luaL_addchar(&b, tolower(uchar(s[i])));
  198.79 +  luaL_pushresult(&b);
  198.80 +  return 1;
  198.81 +}
  198.82 +
  198.83 +
  198.84 +static int str_upper (lua_State *L) {
  198.85 +  size_t l;
  198.86 +  size_t i;
  198.87 +  luaL_Buffer b;
  198.88 +  const char *s = luaL_checklstring(L, 1, &l);
  198.89 +  luaL_buffinit(L, &b);
  198.90 +  for (i=0; i<l; i++)
  198.91 +    luaL_addchar(&b, toupper(uchar(s[i])));
  198.92 +  luaL_pushresult(&b);
  198.93 +  return 1;
  198.94 +}
  198.95 +
  198.96 +static int str_rep (lua_State *L) {
  198.97 +  size_t l;
  198.98 +  luaL_Buffer b;
  198.99 +  const char *s = luaL_checklstring(L, 1, &l);
 198.100 +  int n = luaL_checkint(L, 2);
 198.101 +  luaL_buffinit(L, &b);
 198.102 +  while (n-- > 0)
 198.103 +    luaL_addlstring(&b, s, l);
 198.104 +  luaL_pushresult(&b);
 198.105 +  return 1;
 198.106 +}
 198.107 +
 198.108 +
 198.109 +static int str_byte (lua_State *L) {
 198.110 +  size_t l;
 198.111 +  const char *s = luaL_checklstring(L, 1, &l);
 198.112 +  ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l);
 198.113 +  ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l);
 198.114 +  int n, i;
 198.115 +  if (posi <= 0) posi = 1;
 198.116 +  if ((size_t)pose > l) pose = l;
 198.117 +  if (posi > pose) return 0;  /* empty interval; return no values */
 198.118 +  n = (int)(pose -  posi + 1);
 198.119 +  if (posi + n <= pose)  /* overflow? */
 198.120 +    luaL_error(L, "string slice too long");
 198.121 +  luaL_checkstack(L, n, "string slice too long");
 198.122 +  for (i=0; i<n; i++)
 198.123 +    lua_pushinteger(L, uchar(s[posi+i-1]));
 198.124 +  return n;
 198.125 +}
 198.126 +
 198.127 +
 198.128 +static int str_char (lua_State *L) {
 198.129 +  int n = lua_gettop(L);  /* number of arguments */
 198.130 +  int i;
 198.131 +  luaL_Buffer b;
 198.132 +  luaL_buffinit(L, &b);
 198.133 +  for (i=1; i<=n; i++) {
 198.134 +    int c = luaL_checkint(L, i);
 198.135 +    luaL_argcheck(L, uchar(c) == c, i, "invalid value");
 198.136 +    luaL_addchar(&b, uchar(c));
 198.137 +  }
 198.138 +  luaL_pushresult(&b);
 198.139 +  return 1;
 198.140 +}
 198.141 +
 198.142 +
 198.143 +static int writer (lua_State *L, const void* b, size_t size, void* B) {
 198.144 +  (void)L;
 198.145 +  luaL_addlstring((luaL_Buffer*) B, (const char *)b, size);
 198.146 +  return 0;
 198.147 +}
 198.148 +
 198.149 +
 198.150 +static int str_dump (lua_State *L) {
 198.151 +  luaL_Buffer b;
 198.152 +  luaL_checktype(L, 1, LUA_TFUNCTION);
 198.153 +  lua_settop(L, 1);
 198.154 +  luaL_buffinit(L,&b);
 198.155 +  if (lua_dump(L, writer, &b) != 0)
 198.156 +    luaL_error(L, "unable to dump given function");
 198.157 +  luaL_pushresult(&b);
 198.158 +  return 1;
 198.159 +}
 198.160 +
 198.161 +
 198.162 +
 198.163 +/*
 198.164 +** {======================================================
 198.165 +** PATTERN MATCHING
 198.166 +** =======================================================
 198.167 +*/
 198.168 +
 198.169 +
 198.170 +#define CAP_UNFINISHED	(-1)
 198.171 +#define CAP_POSITION	(-2)
 198.172 +
 198.173 +typedef struct MatchState {
 198.174 +  const char *src_init;  /* init of source string */
 198.175 +  const char *src_end;  /* end (`\0') of source string */
 198.176 +  lua_State *L;
 198.177 +  int level;  /* total number of captures (finished or unfinished) */
 198.178 +  struct {
 198.179 +    const char *init;
 198.180 +    ptrdiff_t len;
 198.181 +  } capture[LUA_MAXCAPTURES];
 198.182 +} MatchState;
 198.183 +
 198.184 +
 198.185 +#define L_ESC		'%'
 198.186 +#define SPECIALS	"^$*+?.([%-"
 198.187 +
 198.188 +
 198.189 +static int check_capture (MatchState *ms, int l) {
 198.190 +  l -= '1';
 198.191 +  if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)
 198.192 +    return luaL_error(ms->L, "invalid capture index");
 198.193 +  return l;
 198.194 +}
 198.195 +
 198.196 +
 198.197 +static int capture_to_close (MatchState *ms) {
 198.198 +  int level = ms->level;
 198.199 +  for (level--; level>=0; level--)
 198.200 +    if (ms->capture[level].len == CAP_UNFINISHED) return level;
 198.201 +  return luaL_error(ms->L, "invalid pattern capture");
 198.202 +}
 198.203 +
 198.204 +
 198.205 +static const char *classend (MatchState *ms, const char *p) {
 198.206 +  switch (*p++) {
 198.207 +    case L_ESC: {
 198.208 +      if (*p == '\0')
 198.209 +        luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")");
 198.210 +      return p+1;
 198.211 +    }
 198.212 +    case '[': {
 198.213 +      if (*p == '^') p++;
 198.214 +      do {  /* look for a `]' */
 198.215 +        if (*p == '\0')
 198.216 +          luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")");
 198.217 +        if (*(p++) == L_ESC && *p != '\0')
 198.218 +          p++;  /* skip escapes (e.g. `%]') */
 198.219 +      } while (*p != ']');
 198.220 +      return p+1;
 198.221 +    }
 198.222 +    default: {
 198.223 +      return p;
 198.224 +    }
 198.225 +  }
 198.226 +}
 198.227 +
 198.228 +
 198.229 +static int match_class (int c, int cl) {
 198.230 +  int res;
 198.231 +  switch (tolower(cl)) {
 198.232 +    case 'a' : res = isalpha(c); break;
 198.233 +    case 'c' : res = iscntrl(c); break;
 198.234 +    case 'd' : res = isdigit(c); break;
 198.235 +    case 'l' : res = islower(c); break;
 198.236 +    case 'p' : res = ispunct(c); break;
 198.237 +    case 's' : res = isspace(c); break;
 198.238 +    case 'u' : res = isupper(c); break;
 198.239 +    case 'w' : res = isalnum(c); break;
 198.240 +    case 'x' : res = isxdigit(c); break;
 198.241 +    case 'z' : res = (c == 0); break;
 198.242 +    default: return (cl == c);
 198.243 +  }
 198.244 +  return (islower(cl) ? res : !res);
 198.245 +}
 198.246 +
 198.247 +
 198.248 +static int matchbracketclass (int c, const char *p, const char *ec) {
 198.249 +  int sig = 1;
 198.250 +  if (*(p+1) == '^') {
 198.251 +    sig = 0;
 198.252 +    p++;  /* skip the `^' */
 198.253 +  }
 198.254 +  while (++p < ec) {
 198.255 +    if (*p == L_ESC) {
 198.256 +      p++;
 198.257 +      if (match_class(c, uchar(*p)))
 198.258 +        return sig;
 198.259 +    }
 198.260 +    else if ((*(p+1) == '-') && (p+2 < ec)) {
 198.261 +      p+=2;
 198.262 +      if (uchar(*(p-2)) <= c && c <= uchar(*p))
 198.263 +        return sig;
 198.264 +    }
 198.265 +    else if (uchar(*p) == c) return sig;
 198.266 +  }
 198.267 +  return !sig;
 198.268 +}
 198.269 +
 198.270 +
 198.271 +static int singlematch (int c, const char *p, const char *ep) {
 198.272 +  switch (*p) {
 198.273 +    case '.': return 1;  /* matches any char */
 198.274 +    case L_ESC: return match_class(c, uchar(*(p+1)));
 198.275 +    case '[': return matchbracketclass(c, p, ep-1);
 198.276 +    default:  return (uchar(*p) == c);
 198.277 +  }
 198.278 +}
 198.279 +
 198.280 +
 198.281 +static const char *match (MatchState *ms, const char *s, const char *p);
 198.282 +
 198.283 +
 198.284 +static const char *matchbalance (MatchState *ms, const char *s,
 198.285 +                                   const char *p) {
 198.286 +  if (*p == 0 || *(p+1) == 0)
 198.287 +    luaL_error(ms->L, "unbalanced pattern");
 198.288 +  if (*s != *p) return NULL;
 198.289 +  else {
 198.290 +    int b = *p;
 198.291 +    int e = *(p+1);
 198.292 +    int cont = 1;
 198.293 +    while (++s < ms->src_end) {
 198.294 +      if (*s == e) {
 198.295 +        if (--cont == 0) return s+1;
 198.296 +      }
 198.297 +      else if (*s == b) cont++;
 198.298 +    }
 198.299 +  }
 198.300 +  return NULL;  /* string ends out of balance */
 198.301 +}
 198.302 +
 198.303 +
 198.304 +static const char *max_expand (MatchState *ms, const char *s,
 198.305 +                                 const char *p, const char *ep) {
 198.306 +  ptrdiff_t i = 0;  /* counts maximum expand for item */
 198.307 +  while ((s+i)<ms->src_end && singlematch(uchar(*(s+i)), p, ep))
 198.308 +    i++;
 198.309 +  /* keeps trying to match with the maximum repetitions */
 198.310 +  while (i>=0) {
 198.311 +    const char *res = match(ms, (s+i), ep+1);
 198.312 +    if (res) return res;
 198.313 +    i--;  /* else didn't match; reduce 1 repetition to try again */
 198.314 +  }
 198.315 +  return NULL;
 198.316 +}
 198.317 +
 198.318 +
 198.319 +static const char *min_expand (MatchState *ms, const char *s,
 198.320 +                                 const char *p, const char *ep) {
 198.321 +  for (;;) {
 198.322 +    const char *res = match(ms, s, ep+1);
 198.323 +    if (res != NULL)
 198.324 +      return res;
 198.325 +    else if (s<ms->src_end && singlematch(uchar(*s), p, ep))
 198.326 +      s++;  /* try with one more repetition */
 198.327 +    else return NULL;
 198.328 +  }
 198.329 +}
 198.330 +
 198.331 +
 198.332 +static const char *start_capture (MatchState *ms, const char *s,
 198.333 +                                    const char *p, int what) {
 198.334 +  const char *res;
 198.335 +  int level = ms->level;
 198.336 +  if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures");
 198.337 +  ms->capture[level].init = s;
 198.338 +  ms->capture[level].len = what;
 198.339 +  ms->level = level+1;
 198.340 +  if ((res=match(ms, s, p)) == NULL)  /* match failed? */
 198.341 +    ms->level--;  /* undo capture */
 198.342 +  return res;
 198.343 +}
 198.344 +
 198.345 +
 198.346 +static const char *end_capture (MatchState *ms, const char *s,
 198.347 +                                  const char *p) {
 198.348 +  int l = capture_to_close(ms);
 198.349 +  const char *res;
 198.350 +  ms->capture[l].len = s - ms->capture[l].init;  /* close capture */
 198.351 +  if ((res = match(ms, s, p)) == NULL)  /* match failed? */
 198.352 +    ms->capture[l].len = CAP_UNFINISHED;  /* undo capture */
 198.353 +  return res;
 198.354 +}
 198.355 +
 198.356 +
 198.357 +static const char *match_capture (MatchState *ms, const char *s, int l) {
 198.358 +  size_t len;
 198.359 +  l = check_capture(ms, l);
 198.360 +  len = ms->capture[l].len;
 198.361 +  if ((size_t)(ms->src_end-s) >= len &&
 198.362 +      memcmp(ms->capture[l].init, s, len) == 0)
 198.363 +    return s+len;
 198.364 +  else return NULL;
 198.365 +}
 198.366 +
 198.367 +
 198.368 +static const char *match (MatchState *ms, const char *s, const char *p) {
 198.369 +  init: /* using goto's to optimize tail recursion */
 198.370 +  switch (*p) {
 198.371 +    case '(': {  /* start capture */
 198.372 +      if (*(p+1) == ')')  /* position capture? */
 198.373 +        return start_capture(ms, s, p+2, CAP_POSITION);
 198.374 +      else
 198.375 +        return start_capture(ms, s, p+1, CAP_UNFINISHED);
 198.376 +    }
 198.377 +    case ')': {  /* end capture */
 198.378 +      return end_capture(ms, s, p+1);
 198.379 +    }
 198.380 +    case L_ESC: {
 198.381 +      switch (*(p+1)) {
 198.382 +        case 'b': {  /* balanced string? */
 198.383 +          s = matchbalance(ms, s, p+2);
 198.384 +          if (s == NULL) return NULL;
 198.385 +          p+=4; goto init;  /* else return match(ms, s, p+4); */
 198.386 +        }
 198.387 +        case 'f': {  /* frontier? */
 198.388 +          const char *ep; char previous;
 198.389 +          p += 2;
 198.390 +          if (*p != '[')
 198.391 +            luaL_error(ms->L, "missing " LUA_QL("[") " after "
 198.392 +                               LUA_QL("%%f") " in pattern");
 198.393 +          ep = classend(ms, p);  /* points to what is next */
 198.394 +          previous = (s == ms->src_init) ? '\0' : *(s-1);
 198.395 +          if (matchbracketclass(uchar(previous), p, ep-1) ||
 198.396 +             !matchbracketclass(uchar(*s), p, ep-1)) return NULL;
 198.397 +          p=ep; goto init;  /* else return match(ms, s, ep); */
 198.398 +        }
 198.399 +        default: {
 198.400 +          if (isdigit(uchar(*(p+1)))) {  /* capture results (%0-%9)? */
 198.401 +            s = match_capture(ms, s, uchar(*(p+1)));
 198.402 +            if (s == NULL) return NULL;
 198.403 +            p+=2; goto init;  /* else return match(ms, s, p+2) */
 198.404 +          }
 198.405 +          goto dflt;  /* case default */
 198.406 +        }
 198.407 +      }
 198.408 +    }
 198.409 +    case '\0': {  /* end of pattern */
 198.410 +      return s;  /* match succeeded */
 198.411 +    }
 198.412 +    case '$': {
 198.413 +      if (*(p+1) == '\0')  /* is the `$' the last char in pattern? */
 198.414 +        return (s == ms->src_end) ? s : NULL;  /* check end of string */
 198.415 +      else goto dflt;
 198.416 +    }
 198.417 +    default: dflt: {  /* it is a pattern item */
 198.418 +      const char *ep = classend(ms, p);  /* points to what is next */
 198.419 +      int m = s<ms->src_end && singlematch(uchar(*s), p, ep);
 198.420 +      switch (*ep) {
 198.421 +        case '?': {  /* optional */
 198.422 +          const char *res;
 198.423 +          if (m && ((res=match(ms, s+1, ep+1)) != NULL))
 198.424 +            return res;
 198.425 +          p=ep+1; goto init;  /* else return match(ms, s, ep+1); */
 198.426 +        }
 198.427 +        case '*': {  /* 0 or more repetitions */
 198.428 +          return max_expand(ms, s, p, ep);
 198.429 +        }
 198.430 +        case '+': {  /* 1 or more repetitions */
 198.431 +          return (m ? max_expand(ms, s+1, p, ep) : NULL);
 198.432 +        }
 198.433 +        case '-': {  /* 0 or more repetitions (minimum) */
 198.434 +          return min_expand(ms, s, p, ep);
 198.435 +        }
 198.436 +        default: {
 198.437 +          if (!m) return NULL;
 198.438 +          s++; p=ep; goto init;  /* else return match(ms, s+1, ep); */
 198.439 +        }
 198.440 +      }
 198.441 +    }
 198.442 +  }
 198.443 +}
 198.444 +
 198.445 +
 198.446 +
 198.447 +static const char *lmemfind (const char *s1, size_t l1,
 198.448 +                               const char *s2, size_t l2) {
 198.449 +  if (l2 == 0) return s1;  /* empty strings are everywhere */
 198.450 +  else if (l2 > l1) return NULL;  /* avoids a negative `l1' */
 198.451 +  else {
 198.452 +    const char *init;  /* to search for a `*s2' inside `s1' */
 198.453 +    l2--;  /* 1st char will be checked by `memchr' */
 198.454 +    l1 = l1-l2;  /* `s2' cannot be found after that */
 198.455 +    while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {
 198.456 +      init++;   /* 1st char is already checked */
 198.457 +      if (memcmp(init, s2+1, l2) == 0)
 198.458 +        return init-1;
 198.459 +      else {  /* correct `l1' and `s1' to try again */
 198.460 +        l1 -= init-s1;
 198.461 +        s1 = init;
 198.462 +      }
 198.463 +    }
 198.464 +    return NULL;  /* not found */
 198.465 +  }
 198.466 +}
 198.467 +
 198.468 +
 198.469 +static void push_onecapture (MatchState *ms, int i, const char *s,
 198.470 +                                                    const char *e) {
 198.471 +  if (i >= ms->level) {
 198.472 +    if (i == 0)  /* ms->level == 0, too */
 198.473 +      lua_pushlstring(ms->L, s, e - s);  /* add whole match */
 198.474 +    else
 198.475 +      luaL_error(ms->L, "invalid capture index");
 198.476 +  }
 198.477 +  else {
 198.478 +    ptrdiff_t l = ms->capture[i].len;
 198.479 +    if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture");
 198.480 +    if (l == CAP_POSITION)
 198.481 +      lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);
 198.482 +    else
 198.483 +      lua_pushlstring(ms->L, ms->capture[i].init, l);
 198.484 +  }
 198.485 +}
 198.486 +
 198.487 +
 198.488 +static int push_captures (MatchState *ms, const char *s, const char *e) {
 198.489 +  int i;
 198.490 +  int nlevels = (ms->level == 0 && s) ? 1 : ms->level;
 198.491 +  luaL_checkstack(ms->L, nlevels, "too many captures");
 198.492 +  for (i = 0; i < nlevels; i++)
 198.493 +    push_onecapture(ms, i, s, e);
 198.494 +  return nlevels;  /* number of strings pushed */
 198.495 +}
 198.496 +
 198.497 +
 198.498 +static int str_find_aux (lua_State *L, int find) {
 198.499 +  size_t l1, l2;
 198.500 +  const char *s = luaL_checklstring(L, 1, &l1);
 198.501 +  const char *p = luaL_checklstring(L, 2, &l2);
 198.502 +  ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1;
 198.503 +  if (init < 0) init = 0;
 198.504 +  else if ((size_t)(init) > l1) init = (ptrdiff_t)l1;
 198.505 +  if (find && (lua_toboolean(L, 4) ||  /* explicit request? */
 198.506 +      strpbrk(p, SPECIALS) == NULL)) {  /* or no special characters? */
 198.507 +    /* do a plain search */
 198.508 +    const char *s2 = lmemfind(s+init, l1-init, p, l2);
 198.509 +    if (s2) {
 198.510 +      lua_pushinteger(L, s2-s+1);
 198.511 +      lua_pushinteger(L, s2-s+l2);
 198.512 +      return 2;
 198.513 +    }
 198.514 +  }
 198.515 +  else {
 198.516 +    MatchState ms;
 198.517 +    int anchor = (*p == '^') ? (p++, 1) : 0;
 198.518 +    const char *s1=s+init;
 198.519 +    ms.L = L;
 198.520 +    ms.src_init = s;
 198.521 +    ms.src_end = s+l1;
 198.522 +    do {
 198.523 +      const char *res;
 198.524 +      ms.level = 0;
 198.525 +      if ((res=match(&ms, s1, p)) != NULL) {
 198.526 +        if (find) {
 198.527 +          lua_pushinteger(L, s1-s+1);  /* start */
 198.528 +          lua_pushinteger(L, res-s);   /* end */
 198.529 +          return push_captures(&ms, NULL, 0) + 2;
 198.530 +        }
 198.531 +        else
 198.532 +          return push_captures(&ms, s1, res);
 198.533 +      }
 198.534 +    } while (s1++ < ms.src_end && !anchor);
 198.535 +  }
 198.536 +  lua_pushnil(L);  /* not found */
 198.537 +  return 1;
 198.538 +}
 198.539 +
 198.540 +
 198.541 +static int str_find (lua_State *L) {
 198.542 +  return str_find_aux(L, 1);
 198.543 +}
 198.544 +
 198.545 +
 198.546 +static int str_match (lua_State *L) {
 198.547 +  return str_find_aux(L, 0);
 198.548 +}
 198.549 +
 198.550 +
 198.551 +static int gmatch_aux (lua_State *L) {
 198.552 +  MatchState ms;
 198.553 +  size_t ls;
 198.554 +  const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
 198.555 +  const char *p = lua_tostring(L, lua_upvalueindex(2));
 198.556 +  const char *src;
 198.557 +  ms.L = L;
 198.558 +  ms.src_init = s;
 198.559 +  ms.src_end = s+ls;
 198.560 +  for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3));
 198.561 +       src <= ms.src_end;
 198.562 +       src++) {
 198.563 +    const char *e;
 198.564 +    ms.level = 0;
 198.565 +    if ((e = match(&ms, src, p)) != NULL) {
 198.566 +      lua_Integer newstart = e-s;
 198.567 +      if (e == src) newstart++;  /* empty match? go at least one position */
 198.568 +      lua_pushinteger(L, newstart);
 198.569 +      lua_replace(L, lua_upvalueindex(3));
 198.570 +      return push_captures(&ms, src, e);
 198.571 +    }
 198.572 +  }
 198.573 +  return 0;  /* not found */
 198.574 +}
 198.575 +
 198.576 +
 198.577 +static int gmatch (lua_State *L) {
 198.578 +  luaL_checkstring(L, 1);
 198.579 +  luaL_checkstring(L, 2);
 198.580 +  lua_settop(L, 2);
 198.581 +  lua_pushinteger(L, 0);
 198.582 +  lua_pushcclosure(L, gmatch_aux, 3);
 198.583 +  return 1;
 198.584 +}
 198.585 +
 198.586 +
 198.587 +static int gfind_nodef (lua_State *L) {
 198.588 +  return luaL_error(L, LUA_QL("string.gfind") " was renamed to "
 198.589 +                       LUA_QL("string.gmatch"));
 198.590 +}
 198.591 +
 198.592 +
 198.593 +static void add_s (MatchState *ms, luaL_Buffer *b, const char *s,
 198.594 +                                                   const char *e) {
 198.595 +  size_t l, i;
 198.596 +  const char *news = lua_tolstring(ms->L, 3, &l);
 198.597 +  for (i = 0; i < l; i++) {
 198.598 +    if (news[i] != L_ESC)
 198.599 +      luaL_addchar(b, news[i]);
 198.600 +    else {
 198.601 +      i++;  /* skip ESC */
 198.602 +      if (!isdigit(uchar(news[i])))
 198.603 +        luaL_addchar(b, news[i]);
 198.604 +      else if (news[i] == '0')
 198.605 +          luaL_addlstring(b, s, e - s);
 198.606 +      else {
 198.607 +        push_onecapture(ms, news[i] - '1', s, e);
 198.608 +        luaL_addvalue(b);  /* add capture to accumulated result */
 198.609 +      }
 198.610 +    }
 198.611 +  }
 198.612 +}
 198.613 +
 198.614 +
 198.615 +static void add_value (MatchState *ms, luaL_Buffer *b, const char *s,
 198.616 +                                                       const char *e) {
 198.617 +  lua_State *L = ms->L;
 198.618 +  switch (lua_type(L, 3)) {
 198.619 +    case LUA_TNUMBER:
 198.620 +    case LUA_TSTRING: {
 198.621 +      add_s(ms, b, s, e);
 198.622 +      return;
 198.623 +    }
 198.624 +    case LUA_TFUNCTION: {
 198.625 +      int n;
 198.626 +      lua_pushvalue(L, 3);
 198.627 +      n = push_captures(ms, s, e);
 198.628 +      lua_call(L, n, 1);
 198.629 +      break;
 198.630 +    }
 198.631 +    case LUA_TTABLE: {
 198.632 +      push_onecapture(ms, 0, s, e);
 198.633 +      lua_gettable(L, 3);
 198.634 +      break;
 198.635 +    }
 198.636 +  }
 198.637 +  if (!lua_toboolean(L, -1)) {  /* nil or false? */
 198.638 +    lua_pop(L, 1);
 198.639 +    lua_pushlstring(L, s, e - s);  /* keep original text */
 198.640 +  }
 198.641 +  else if (!lua_isstring(L, -1))
 198.642 +    luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1)); 
 198.643 +  luaL_addvalue(b);  /* add result to accumulator */
 198.644 +}
 198.645 +
 198.646 +
 198.647 +static int str_gsub (lua_State *L) {
 198.648 +  size_t srcl;
 198.649 +  const char *src = luaL_checklstring(L, 1, &srcl);
 198.650 +  const char *p = luaL_checkstring(L, 2);
 198.651 +  int  tr = lua_type(L, 3);
 198.652 +  int max_s = luaL_optint(L, 4, srcl+1);
 198.653 +  int anchor = (*p == '^') ? (p++, 1) : 0;
 198.654 +  int n = 0;
 198.655 +  MatchState ms;
 198.656 +  luaL_Buffer b;
 198.657 +  luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||
 198.658 +                   tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,
 198.659 +                      "string/function/table expected");
 198.660 +  luaL_buffinit(L, &b);
 198.661 +  ms.L = L;
 198.662 +  ms.src_init = src;
 198.663 +  ms.src_end = src+srcl;
 198.664 +  while (n < max_s) {
 198.665 +    const char *e;
 198.666 +    ms.level = 0;
 198.667 +    e = match(&ms, src, p);
 198.668 +    if (e) {
 198.669 +      n++;
 198.670 +      add_value(&ms, &b, src, e);
 198.671 +    }
 198.672 +    if (e && e>src) /* non empty match? */
 198.673 +      src = e;  /* skip it */
 198.674 +    else if (src < ms.src_end)
 198.675 +      luaL_addchar(&b, *src++);
 198.676 +    else break;
 198.677 +    if (anchor) break;
 198.678 +  }
 198.679 +  luaL_addlstring(&b, src, ms.src_end-src);
 198.680 +  luaL_pushresult(&b);
 198.681 +  lua_pushinteger(L, n);  /* number of substitutions */
 198.682 +  return 2;
 198.683 +}
 198.684 +
 198.685 +/* }====================================================== */
 198.686 +
 198.687 +
 198.688 +/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */
 198.689 +#define MAX_ITEM	512
 198.690 +/* valid flags in a format specification */
 198.691 +#define FLAGS	"-+ #0"
 198.692 +/*
 198.693 +** maximum size of each format specification (such as '%-099.99d')
 198.694 +** (+10 accounts for %99.99x plus margin of error)
 198.695 +*/
 198.696 +#define MAX_FORMAT	(sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)
 198.697 +
 198.698 +
 198.699 +static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
 198.700 +  size_t l;
 198.701 +  const char *s = luaL_checklstring(L, arg, &l);
 198.702 +  luaL_addchar(b, '"');
 198.703 +  while (l--) {
 198.704 +    switch (*s) {
 198.705 +      case '"': case '\\': case '\n': {
 198.706 +        luaL_addchar(b, '\\');
 198.707 +        luaL_addchar(b, *s);
 198.708 +        break;
 198.709 +      }
 198.710 +      case '\r': {
 198.711 +        luaL_addlstring(b, "\\r", 2);
 198.712 +        break;
 198.713 +      }
 198.714 +      case '\0': {
 198.715 +        luaL_addlstring(b, "\\000", 4);
 198.716 +        break;
 198.717 +      }
 198.718 +      default: {
 198.719 +        luaL_addchar(b, *s);
 198.720 +        break;
 198.721 +      }
 198.722 +    }
 198.723 +    s++;
 198.724 +  }
 198.725 +  luaL_addchar(b, '"');
 198.726 +}
 198.727 +
 198.728 +static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
 198.729 +  const char *p = strfrmt;
 198.730 +  while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++;  /* skip flags */
 198.731 +  if ((size_t)(p - strfrmt) >= sizeof(FLAGS))
 198.732 +    luaL_error(L, "invalid format (repeated flags)");
 198.733 +  if (isdigit(uchar(*p))) p++;  /* skip width */
 198.734 +  if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */
 198.735 +  if (*p == '.') {
 198.736 +    p++;
 198.737 +    if (isdigit(uchar(*p))) p++;  /* skip precision */
 198.738 +    if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */
 198.739 +  }
 198.740 +  if (isdigit(uchar(*p)))
 198.741 +    luaL_error(L, "invalid format (width or precision too long)");
 198.742 +  *(form++) = '%';
 198.743 +  strncpy(form, strfrmt, p - strfrmt + 1);
 198.744 +  form += p - strfrmt + 1;
 198.745 +  *form = '\0';
 198.746 +  return p;
 198.747 +}
 198.748 +
 198.749 +
 198.750 +static void addintlen (char *form) {
 198.751 +  size_t l = strlen(form);
 198.752 +  char spec = form[l - 1];
 198.753 +  strcpy(form + l - 1, LUA_INTFRMLEN);
 198.754 +  form[l + sizeof(LUA_INTFRMLEN) - 2] = spec;
 198.755 +  form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0';
 198.756 +}
 198.757 +
 198.758 +
 198.759 +static int str_format (lua_State *L) {
 198.760 +  int arg = 1;
 198.761 +  size_t sfl;
 198.762 +  const char *strfrmt = luaL_checklstring(L, arg, &sfl);
 198.763 +  const char *strfrmt_end = strfrmt+sfl;
 198.764 +  luaL_Buffer b;
 198.765 +  luaL_buffinit(L, &b);
 198.766 +  while (strfrmt < strfrmt_end) {
 198.767 +    if (*strfrmt != L_ESC)
 198.768 +      luaL_addchar(&b, *strfrmt++);
 198.769 +    else if (*++strfrmt == L_ESC)
 198.770 +      luaL_addchar(&b, *strfrmt++);  /* %% */
 198.771 +    else { /* format item */
 198.772 +      char form[MAX_FORMAT];  /* to store the format (`%...') */
 198.773 +      char buff[MAX_ITEM];  /* to store the formatted item */
 198.774 +      arg++;
 198.775 +      strfrmt = scanformat(L, strfrmt, form);
 198.776 +      switch (*strfrmt++) {
 198.777 +        case 'c': {
 198.778 +          sprintf(buff, form, (int)luaL_checknumber(L, arg));
 198.779 +          break;
 198.780 +        }
 198.781 +        case 'd':  case 'i': {
 198.782 +          addintlen(form);
 198.783 +          sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
 198.784 +          break;
 198.785 +        }
 198.786 +        case 'o':  case 'u':  case 'x':  case 'X': {
 198.787 +          addintlen(form);
 198.788 +          sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
 198.789 +          break;
 198.790 +        }
 198.791 +        case 'e':  case 'E': case 'f':
 198.792 +        case 'g': case 'G': {
 198.793 +          sprintf(buff, form, (double)luaL_checknumber(L, arg));
 198.794 +          break;
 198.795 +        }
 198.796 +        case 'q': {
 198.797 +          addquoted(L, &b, arg);
 198.798 +          continue;  /* skip the 'addsize' at the end */
 198.799 +        }
 198.800 +        case 's': {
 198.801 +          size_t l;
 198.802 +          const char *s = luaL_checklstring(L, arg, &l);
 198.803 +          if (!strchr(form, '.') && l >= 100) {
 198.804 +            /* no precision and string is too long to be formatted;
 198.805 +               keep original string */
 198.806 +            lua_pushvalue(L, arg);
 198.807 +            luaL_addvalue(&b);
 198.808 +            continue;  /* skip the `addsize' at the end */
 198.809 +          }
 198.810 +          else {
 198.811 +            sprintf(buff, form, s);
 198.812 +            break;
 198.813 +          }
 198.814 +        }
 198.815 +        default: {  /* also treat cases `pnLlh' */
 198.816 +          return luaL_error(L, "invalid option " LUA_QL("%%%c") " to "
 198.817 +                               LUA_QL("format"), *(strfrmt - 1));
 198.818 +        }
 198.819 +      }
 198.820 +      luaL_addlstring(&b, buff, strlen(buff));
 198.821 +    }
 198.822 +  }
 198.823 +  luaL_pushresult(&b);
 198.824 +  return 1;
 198.825 +}
 198.826 +
 198.827 +
 198.828 +static const luaL_Reg strlib[] = {
 198.829 +  {"byte", str_byte},
 198.830 +  {"char", str_char},
 198.831 +  {"dump", str_dump},
 198.832 +  {"find", str_find},
 198.833 +  {"format", str_format},
 198.834 +  {"gfind", gfind_nodef},
 198.835 +  {"gmatch", gmatch},
 198.836 +  {"gsub", str_gsub},
 198.837 +  {"len", str_len},
 198.838 +  {"lower", str_lower},
 198.839 +  {"match", str_match},
 198.840 +  {"rep", str_rep},
 198.841 +  {"reverse", str_reverse},
 198.842 +  {"sub", str_sub},
 198.843 +  {"upper", str_upper},
 198.844 +  {NULL, NULL}
 198.845 +};
 198.846 +
 198.847 +
 198.848 +static void createmetatable (lua_State *L) {
 198.849 +  lua_createtable(L, 0, 1);  /* create metatable for strings */
 198.850 +  lua_pushliteral(L, "");  /* dummy string */
 198.851 +  lua_pushvalue(L, -2);
 198.852 +  lua_setmetatable(L, -2);  /* set string metatable */
 198.853 +  lua_pop(L, 1);  /* pop dummy string */
 198.854 +  lua_pushvalue(L, -2);  /* string library... */
 198.855 +  lua_setfield(L, -2, "__index");  /* ...is the __index metamethod */
 198.856 +  lua_pop(L, 1);  /* pop metatable */
 198.857 +}
 198.858 +
 198.859 +
 198.860 +/*
 198.861 +** Open string library
 198.862 +*/
 198.863 +LUALIB_API int luaopen_string (lua_State *L) {
 198.864 +  luaL_register(L, LUA_STRLIBNAME, strlib);
 198.865 +#if defined(LUA_COMPAT_GFIND)
 198.866 +  lua_getfield(L, -1, "gmatch");
 198.867 +  lua_setfield(L, -2, "gfind");
 198.868 +#endif
 198.869 +  createmetatable(L);
 198.870 +  return 1;
 198.871 +}
 198.872 +
   199.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   199.2 +++ b/src/lua/src/ltable.c	Sat Mar 03 10:31:27 2012 -0600
   199.3 @@ -0,0 +1,588 @@
   199.4 +/*
   199.5 +** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $
   199.6 +** Lua tables (hash)
   199.7 +** See Copyright Notice in lua.h
   199.8 +*/
   199.9 +
  199.10 +
  199.11 +/*
  199.12 +** Implementation of tables (aka arrays, objects, or hash tables).
  199.13 +** Tables keep its elements in two parts: an array part and a hash part.
  199.14 +** Non-negative integer keys are all candidates to be kept in the array
  199.15 +** part. The actual size of the array is the largest `n' such that at
  199.16 +** least half the slots between 0 and n are in use.
  199.17 +** Hash uses a mix of chained scatter table with Brent's variation.
  199.18 +** A main invariant of these tables is that, if an element is not
  199.19 +** in its main position (i.e. the `original' position that its hash gives
  199.20 +** to it), then the colliding element is in its own main position.
  199.21 +** Hence even when the load factor reaches 100%, performance remains good.
  199.22 +*/
  199.23 +
  199.24 +#include <math.h>
  199.25 +#include <string.h>
  199.26 +
  199.27 +#define ltable_c
  199.28 +#define LUA_CORE
  199.29 +
  199.30 +#include "lua.h"
  199.31 +
  199.32 +#include "ldebug.h"
  199.33 +#include "ldo.h"
  199.34 +#include "lgc.h"
  199.35 +#include "lmem.h"
  199.36 +#include "lobject.h"
  199.37 +#include "lstate.h"
  199.38 +#include "ltable.h"
  199.39 +
  199.40 +
  199.41 +/*
  199.42 +** max size of array part is 2^MAXBITS
  199.43 +*/
  199.44 +#if LUAI_BITSINT > 26
  199.45 +#define MAXBITS		26
  199.46 +#else
  199.47 +#define MAXBITS		(LUAI_BITSINT-2)
  199.48 +#endif
  199.49 +
  199.50 +#define MAXASIZE	(1 << MAXBITS)
  199.51 +
  199.52 +
  199.53 +#define hashpow2(t,n)      (gnode(t, lmod((n), sizenode(t))))
  199.54 +  
  199.55 +#define hashstr(t,str)  hashpow2(t, (str)->tsv.hash)
  199.56 +#define hashboolean(t,p)        hashpow2(t, p)
  199.57 +
  199.58 +
  199.59 +/*
  199.60 +** for some types, it is better to avoid modulus by power of 2, as
  199.61 +** they tend to have many 2 factors.
  199.62 +*/
  199.63 +#define hashmod(t,n)	(gnode(t, ((n) % ((sizenode(t)-1)|1))))
  199.64 +
  199.65 +
  199.66 +#define hashpointer(t,p)	hashmod(t, IntPoint(p))
  199.67 +
  199.68 +
  199.69 +/*
  199.70 +** number of ints inside a lua_Number
  199.71 +*/
  199.72 +#define numints		cast_int(sizeof(lua_Number)/sizeof(int))
  199.73 +
  199.74 +
  199.75 +
  199.76 +#define dummynode		(&dummynode_)
  199.77 +
  199.78 +static const Node dummynode_ = {
  199.79 +  {{NULL}, LUA_TNIL},  /* value */
  199.80 +  {{{NULL}, LUA_TNIL, NULL}}  /* key */
  199.81 +};
  199.82 +
  199.83 +
  199.84 +/*
  199.85 +** hash for lua_Numbers
  199.86 +*/
  199.87 +static Node *hashnum (const Table *t, lua_Number n) {
  199.88 +  unsigned int a[numints];
  199.89 +  int i;
  199.90 +  if (luai_numeq(n, 0))  /* avoid problems with -0 */
  199.91 +    return gnode(t, 0);
  199.92 +  memcpy(a, &n, sizeof(a));
  199.93 +  for (i = 1; i < numints; i++) a[0] += a[i];
  199.94 +  return hashmod(t, a[0]);
  199.95 +}
  199.96 +
  199.97 +
  199.98 +
  199.99 +/*
 199.100 +** returns the `main' position of an element in a table (that is, the index
 199.101 +** of its hash value)
 199.102 +*/
 199.103 +static Node *mainposition (const Table *t, const TValue *key) {
 199.104 +  switch (ttype(key)) {
 199.105 +    case LUA_TNUMBER:
 199.106 +      return hashnum(t, nvalue(key));
 199.107 +    case LUA_TSTRING:
 199.108 +      return hashstr(t, rawtsvalue(key));
 199.109 +    case LUA_TBOOLEAN:
 199.110 +      return hashboolean(t, bvalue(key));
 199.111 +    case LUA_TLIGHTUSERDATA:
 199.112 +      return hashpointer(t, pvalue(key));
 199.113 +    default:
 199.114 +      return hashpointer(t, gcvalue(key));
 199.115 +  }
 199.116 +}
 199.117 +
 199.118 +
 199.119 +/*
 199.120 +** returns the index for `key' if `key' is an appropriate key to live in
 199.121 +** the array part of the table, -1 otherwise.
 199.122 +*/
 199.123 +static int arrayindex (const TValue *key) {
 199.124 +  if (ttisnumber(key)) {
 199.125 +    lua_Number n = nvalue(key);
 199.126 +    int k;
 199.127 +    lua_number2int(k, n);
 199.128 +    if (luai_numeq(cast_num(k), n))
 199.129 +      return k;
 199.130 +  }
 199.131 +  return -1;  /* `key' did not match some condition */
 199.132 +}
 199.133 +
 199.134 +
 199.135 +/*
 199.136 +** returns the index of a `key' for table traversals. First goes all
 199.137 +** elements in the array part, then elements in the hash part. The
 199.138 +** beginning of a traversal is signalled by -1.
 199.139 +*/
 199.140 +static int findindex (lua_State *L, Table *t, StkId key) {
 199.141 +  int i;
 199.142 +  if (ttisnil(key)) return -1;  /* first iteration */
 199.143 +  i = arrayindex(key);
 199.144 +  if (0 < i && i <= t->sizearray)  /* is `key' inside array part? */
 199.145 +    return i-1;  /* yes; that's the index (corrected to C) */
 199.146 +  else {
 199.147 +    Node *n = mainposition(t, key);
 199.148 +    do {  /* check whether `key' is somewhere in the chain */
 199.149 +      /* key may be dead already, but it is ok to use it in `next' */
 199.150 +      if (luaO_rawequalObj(key2tval(n), key) ||
 199.151 +            (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) &&
 199.152 +             gcvalue(gkey(n)) == gcvalue(key))) {
 199.153 +        i = cast_int(n - gnode(t, 0));  /* key index in hash table */
 199.154 +        /* hash elements are numbered after array ones */
 199.155 +        return i + t->sizearray;
 199.156 +      }
 199.157 +      else n = gnext(n);
 199.158 +    } while (n);
 199.159 +    luaG_runerror(L, "invalid key to " LUA_QL("next"));  /* key not found */
 199.160 +    return 0;  /* to avoid warnings */
 199.161 +  }
 199.162 +}
 199.163 +
 199.164 +
 199.165 +int luaH_next (lua_State *L, Table *t, StkId key) {
 199.166 +  int i = findindex(L, t, key);  /* find original element */
 199.167 +  for (i++; i < t->sizearray; i++) {  /* try first array part */
 199.168 +    if (!ttisnil(&t->array[i])) {  /* a non-nil value? */
 199.169 +      setnvalue(key, cast_num(i+1));
 199.170 +      setobj2s(L, key+1, &t->array[i]);
 199.171 +      return 1;
 199.172 +    }
 199.173 +  }
 199.174 +  for (i -= t->sizearray; i < sizenode(t); i++) {  /* then hash part */
 199.175 +    if (!ttisnil(gval(gnode(t, i)))) {  /* a non-nil value? */
 199.176 +      setobj2s(L, key, key2tval(gnode(t, i)));
 199.177 +      setobj2s(L, key+1, gval(gnode(t, i)));
 199.178 +      return 1;
 199.179 +    }
 199.180 +  }
 199.181 +  return 0;  /* no more elements */
 199.182 +}
 199.183 +
 199.184 +
 199.185 +/*
 199.186 +** {=============================================================
 199.187 +** Rehash
 199.188 +** ==============================================================
 199.189 +*/
 199.190 +
 199.191 +
 199.192 +static int computesizes (int nums[], int *narray) {
 199.193 +  int i;
 199.194 +  int twotoi;  /* 2^i */
 199.195 +  int a = 0;  /* number of elements smaller than 2^i */
 199.196 +  int na = 0;  /* number of elements to go to array part */
 199.197 +  int n = 0;  /* optimal size for array part */
 199.198 +  for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) {
 199.199 +    if (nums[i] > 0) {
 199.200 +      a += nums[i];
 199.201 +      if (a > twotoi/2) {  /* more than half elements present? */
 199.202 +        n = twotoi;  /* optimal size (till now) */
 199.203 +        na = a;  /* all elements smaller than n will go to array part */
 199.204 +      }
 199.205 +    }
 199.206 +    if (a == *narray) break;  /* all elements already counted */
 199.207 +  }
 199.208 +  *narray = n;
 199.209 +  lua_assert(*narray/2 <= na && na <= *narray);
 199.210 +  return na;
 199.211 +}
 199.212 +
 199.213 +
 199.214 +static int countint (const TValue *key, int *nums) {
 199.215 +  int k = arrayindex(key);
 199.216 +  if (0 < k && k <= MAXASIZE) {  /* is `key' an appropriate array index? */
 199.217 +    nums[ceillog2(k)]++;  /* count as such */
 199.218 +    return 1;
 199.219 +  }
 199.220 +  else
 199.221 +    return 0;
 199.222 +}
 199.223 +
 199.224 +
 199.225 +static int numusearray (const Table *t, int *nums) {
 199.226 +  int lg;
 199.227 +  int ttlg;  /* 2^lg */
 199.228 +  int ause = 0;  /* summation of `nums' */
 199.229 +  int i = 1;  /* count to traverse all array keys */
 199.230 +  for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) {  /* for each slice */
 199.231 +    int lc = 0;  /* counter */
 199.232 +    int lim = ttlg;
 199.233 +    if (lim > t->sizearray) {
 199.234 +      lim = t->sizearray;  /* adjust upper limit */
 199.235 +      if (i > lim)
 199.236 +        break;  /* no more elements to count */
 199.237 +    }
 199.238 +    /* count elements in range (2^(lg-1), 2^lg] */
 199.239 +    for (; i <= lim; i++) {
 199.240 +      if (!ttisnil(&t->array[i-1]))
 199.241 +        lc++;
 199.242 +    }
 199.243 +    nums[lg] += lc;
 199.244 +    ause += lc;
 199.245 +  }
 199.246 +  return ause;
 199.247 +}
 199.248 +
 199.249 +
 199.250 +static int numusehash (const Table *t, int *nums, int *pnasize) {
 199.251 +  int totaluse = 0;  /* total number of elements */
 199.252 +  int ause = 0;  /* summation of `nums' */
 199.253 +  int i = sizenode(t);
 199.254 +  while (i--) {
 199.255 +    Node *n = &t->node[i];
 199.256 +    if (!ttisnil(gval(n))) {
 199.257 +      ause += countint(key2tval(n), nums);
 199.258 +      totaluse++;
 199.259 +    }
 199.260 +  }
 199.261 +  *pnasize += ause;
 199.262 +  return totaluse;
 199.263 +}
 199.264 +
 199.265 +
 199.266 +static void setarrayvector (lua_State *L, Table *t, int size) {
 199.267 +  int i;
 199.268 +  luaM_reallocvector(L, t->array, t->sizearray, size, TValue);
 199.269 +  for (i=t->sizearray; i<size; i++)
 199.270 +     setnilvalue(&t->array[i]);
 199.271 +  t->sizearray = size;
 199.272 +}
 199.273 +
 199.274 +
 199.275 +static void setnodevector (lua_State *L, Table *t, int size) {
 199.276 +  int lsize;
 199.277 +  if (size == 0) {  /* no elements to hash part? */
 199.278 +    t->node = cast(Node *, dummynode);  /* use common `dummynode' */
 199.279 +    lsize = 0;
 199.280 +  }
 199.281 +  else {
 199.282 +    int i;
 199.283 +    lsize = ceillog2(size);
 199.284 +    if (lsize > MAXBITS)
 199.285 +      luaG_runerror(L, "table overflow");
 199.286 +    size = twoto(lsize);
 199.287 +    t->node = luaM_newvector(L, size, Node);
 199.288 +    for (i=0; i<size; i++) {
 199.289 +      Node *n = gnode(t, i);
 199.290 +      gnext(n) = NULL;
 199.291 +      setnilvalue(gkey(n));
 199.292 +      setnilvalue(gval(n));
 199.293 +    }
 199.294 +  }
 199.295 +  t->lsizenode = cast_byte(lsize);
 199.296 +  t->lastfree = gnode(t, size);  /* all positions are free */
 199.297 +}
 199.298 +
 199.299 +
 199.300 +static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
 199.301 +  int i;
 199.302 +  int oldasize = t->sizearray;
 199.303 +  int oldhsize = t->lsizenode;
 199.304 +  Node *nold = t->node;  /* save old hash ... */
 199.305 +  if (nasize > oldasize)  /* array part must grow? */
 199.306 +    setarrayvector(L, t, nasize);
 199.307 +  /* create new hash part with appropriate size */
 199.308 +  setnodevector(L, t, nhsize);  
 199.309 +  if (nasize < oldasize) {  /* array part must shrink? */
 199.310 +    t->sizearray = nasize;
 199.311 +    /* re-insert elements from vanishing slice */
 199.312 +    for (i=nasize; i<oldasize; i++) {
 199.313 +      if (!ttisnil(&t->array[i]))
 199.314 +        setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]);
 199.315 +    }
 199.316 +    /* shrink array */
 199.317 +    luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
 199.318 +  }
 199.319 +  /* re-insert elements from hash part */
 199.320 +  for (i = twoto(oldhsize) - 1; i >= 0; i--) {
 199.321 +    Node *old = nold+i;
 199.322 +    if (!ttisnil(gval(old)))
 199.323 +      setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old));
 199.324 +  }
 199.325 +  if (nold != dummynode)
 199.326 +    luaM_freearray(L, nold, twoto(oldhsize), Node);  /* free old array */
 199.327 +}
 199.328 +
 199.329 +
 199.330 +void luaH_resizearray (lua_State *L, Table *t, int nasize) {
 199.331 +  int nsize = (t->node == dummynode) ? 0 : sizenode(t);
 199.332 +  resize(L, t, nasize, nsize);
 199.333 +}
 199.334 +
 199.335 +
 199.336 +static void rehash (lua_State *L, Table *t, const TValue *ek) {
 199.337 +  int nasize, na;
 199.338 +  int nums[MAXBITS+1];  /* nums[i] = number of keys between 2^(i-1) and 2^i */
 199.339 +  int i;
 199.340 +  int totaluse;
 199.341 +  for (i=0; i<=MAXBITS; i++) nums[i] = 0;  /* reset counts */
 199.342 +  nasize = numusearray(t, nums);  /* count keys in array part */
 199.343 +  totaluse = nasize;  /* all those keys are integer keys */
 199.344 +  totaluse += numusehash(t, nums, &nasize);  /* count keys in hash part */
 199.345 +  /* count extra key */
 199.346 +  nasize += countint(ek, nums);
 199.347 +  totaluse++;
 199.348 +  /* compute new size for array part */
 199.349 +  na = computesizes(nums, &nasize);
 199.350 +  /* resize the table to new computed sizes */
 199.351 +  resize(L, t, nasize, totaluse - na);
 199.352 +}
 199.353 +
 199.354 +
 199.355 +
 199.356 +/*
 199.357 +** }=============================================================
 199.358 +*/
 199.359 +
 199.360 +
 199.361 +Table *luaH_new (lua_State *L, int narray, int nhash) {
 199.362 +  Table *t = luaM_new(L, Table);
 199.363 +  luaC_link(L, obj2gco(t), LUA_TTABLE);
 199.364 +  t->metatable = NULL;
 199.365 +  t->flags = cast_byte(~0);
 199.366 +  /* temporary values (kept only if some malloc fails) */
 199.367 +  t->array = NULL;
 199.368 +  t->sizearray = 0;
 199.369 +  t->lsizenode = 0;
 199.370 +  t->node = cast(Node *, dummynode);
 199.371 +  setarrayvector(L, t, narray);
 199.372 +  setnodevector(L, t, nhash);
 199.373 +  return t;
 199.374 +}
 199.375 +
 199.376 +
 199.377 +void luaH_free (lua_State *L, Table *t) {
 199.378 +  if (t->node != dummynode)
 199.379 +    luaM_freearray(L, t->node, sizenode(t), Node);
 199.380 +  luaM_freearray(L, t->array, t->sizearray, TValue);
 199.381 +  luaM_free(L, t);
 199.382 +}
 199.383 +
 199.384 +
 199.385 +static Node *getfreepos (Table *t) {
 199.386 +  while (t->lastfree-- > t->node) {
 199.387 +    if (ttisnil(gkey(t->lastfree)))
 199.388 +      return t->lastfree;
 199.389 +  }
 199.390 +  return NULL;  /* could not find a free place */
 199.391 +}
 199.392 +
 199.393 +
 199.394 +
 199.395 +/*
 199.396 +** inserts a new key into a hash table; first, check whether key's main 
 199.397 +** position is free. If not, check whether colliding node is in its main 
 199.398 +** position or not: if it is not, move colliding node to an empty place and 
 199.399 +** put new key in its main position; otherwise (colliding node is in its main 
 199.400 +** position), new key goes to an empty position. 
 199.401 +*/
 199.402 +static TValue *newkey (lua_State *L, Table *t, const TValue *key) {
 199.403 +  Node *mp = mainposition(t, key);
 199.404 +  if (!ttisnil(gval(mp)) || mp == dummynode) {
 199.405 +    Node *othern;
 199.406 +    Node *n = getfreepos(t);  /* get a free place */
 199.407 +    if (n == NULL) {  /* cannot find a free place? */
 199.408 +      rehash(L, t, key);  /* grow table */
 199.409 +      return luaH_set(L, t, key);  /* re-insert key into grown table */
 199.410 +    }
 199.411 +    lua_assert(n != dummynode);
 199.412 +    othern = mainposition(t, key2tval(mp));
 199.413 +    if (othern != mp) {  /* is colliding node out of its main position? */
 199.414 +      /* yes; move colliding node into free position */
 199.415 +      while (gnext(othern) != mp) othern = gnext(othern);  /* find previous */
 199.416 +      gnext(othern) = n;  /* redo the chain with `n' in place of `mp' */
 199.417 +      *n = *mp;  /* copy colliding node into free pos. (mp->next also goes) */
 199.418 +      gnext(mp) = NULL;  /* now `mp' is free */
 199.419 +      setnilvalue(gval(mp));
 199.420 +    }
 199.421 +    else {  /* colliding node is in its own main position */
 199.422 +      /* new node will go into free position */
 199.423 +      gnext(n) = gnext(mp);  /* chain new position */
 199.424 +      gnext(mp) = n;
 199.425 +      mp = n;
 199.426 +    }
 199.427 +  }
 199.428 +  gkey(mp)->value = key->value; gkey(mp)->tt = key->tt;
 199.429 +  luaC_barriert(L, t, key);
 199.430 +  lua_assert(ttisnil(gval(mp)));
 199.431 +  return gval(mp);
 199.432 +}
 199.433 +
 199.434 +
 199.435 +/*
 199.436 +** search function for integers
 199.437 +*/
 199.438 +const TValue *luaH_getnum (Table *t, int key) {
 199.439 +  /* (1 <= key && key <= t->sizearray) */
 199.440 +  if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
 199.441 +    return &t->array[key-1];
 199.442 +  else {
 199.443 +    lua_Number nk = cast_num(key);
 199.444 +    Node *n = hashnum(t, nk);
 199.445 +    do {  /* check whether `key' is somewhere in the chain */
 199.446 +      if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))
 199.447 +        return gval(n);  /* that's it */
 199.448 +      else n = gnext(n);
 199.449 +    } while (n);
 199.450 +    return luaO_nilobject;
 199.451 +  }
 199.452 +}
 199.453 +
 199.454 +
 199.455 +/*
 199.456 +** search function for strings
 199.457 +*/
 199.458 +const TValue *luaH_getstr (Table *t, TString *key) {
 199.459 +  Node *n = hashstr(t, key);
 199.460 +  do {  /* check whether `key' is somewhere in the chain */
 199.461 +    if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key)
 199.462 +      return gval(n);  /* that's it */
 199.463 +    else n = gnext(n);
 199.464 +  } while (n);
 199.465 +  return luaO_nilobject;
 199.466 +}
 199.467 +
 199.468 +
 199.469 +/*
 199.470 +** main search function
 199.471 +*/
 199.472 +const TValue *luaH_get (Table *t, const TValue *key) {
 199.473 +  switch (ttype(key)) {
 199.474 +    case LUA_TNIL: return luaO_nilobject;
 199.475 +    case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key));
 199.476 +    case LUA_TNUMBER: {
 199.477 +      int k;
 199.478 +      lua_Number n = nvalue(key);
 199.479 +      lua_number2int(k, n);
 199.480 +      if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */
 199.481 +        return luaH_getnum(t, k);  /* use specialized version */
 199.482 +      /* else go through */
 199.483 +    }
 199.484 +    default: {
 199.485 +      Node *n = mainposition(t, key);
 199.486 +      do {  /* check whether `key' is somewhere in the chain */
 199.487 +        if (luaO_rawequalObj(key2tval(n), key))
 199.488 +          return gval(n);  /* that's it */
 199.489 +        else n = gnext(n);
 199.490 +      } while (n);
 199.491 +      return luaO_nilobject;
 199.492 +    }
 199.493 +  }
 199.494 +}
 199.495 +
 199.496 +
 199.497 +TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
 199.498 +  const TValue *p = luaH_get(t, key);
 199.499 +  t->flags = 0;
 199.500 +  if (p != luaO_nilobject)
 199.501 +    return cast(TValue *, p);
 199.502 +  else {
 199.503 +    if (ttisnil(key)) luaG_runerror(L, "table index is nil");
 199.504 +    else if (ttisnumber(key) && luai_numisnan(nvalue(key)))
 199.505 +      luaG_runerror(L, "table index is NaN");
 199.506 +    return newkey(L, t, key);
 199.507 +  }
 199.508 +}
 199.509 +
 199.510 +
 199.511 +TValue *luaH_setnum (lua_State *L, Table *t, int key) {
 199.512 +  const TValue *p = luaH_getnum(t, key);
 199.513 +  if (p != luaO_nilobject)
 199.514 +    return cast(TValue *, p);
 199.515 +  else {
 199.516 +    TValue k;
 199.517 +    setnvalue(&k, cast_num(key));
 199.518 +    return newkey(L, t, &k);
 199.519 +  }
 199.520 +}
 199.521 +
 199.522 +
 199.523 +TValue *luaH_setstr (lua_State *L, Table *t, TString *key) {
 199.524 +  const TValue *p = luaH_getstr(t, key);
 199.525 +  if (p != luaO_nilobject)
 199.526 +    return cast(TValue *, p);
 199.527 +  else {
 199.528 +    TValue k;
 199.529 +    setsvalue(L, &k, key);
 199.530 +    return newkey(L, t, &k);
 199.531 +  }
 199.532 +}
 199.533 +
 199.534 +
 199.535 +static int unbound_search (Table *t, unsigned int j) {
 199.536 +  unsigned int i = j;  /* i is zero or a present index */
 199.537 +  j++;
 199.538 +  /* find `i' and `j' such that i is present and j is not */
 199.539 +  while (!ttisnil(luaH_getnum(t, j))) {
 199.540 +    i = j;
 199.541 +    j *= 2;
 199.542 +    if (j > cast(unsigned int, MAX_INT)) {  /* overflow? */
 199.543 +      /* table was built with bad purposes: resort to linear search */
 199.544 +      i = 1;
 199.545 +      while (!ttisnil(luaH_getnum(t, i))) i++;
 199.546 +      return i - 1;
 199.547 +    }
 199.548 +  }
 199.549 +  /* now do a binary search between them */
 199.550 +  while (j - i > 1) {
 199.551 +    unsigned int m = (i+j)/2;
 199.552 +    if (ttisnil(luaH_getnum(t, m))) j = m;
 199.553 +    else i = m;
 199.554 +  }
 199.555 +  return i;
 199.556 +}
 199.557 +
 199.558 +
 199.559 +/*
 199.560 +** Try to find a boundary in table `t'. A `boundary' is an integer index
 199.561 +** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).
 199.562 +*/
 199.563 +int luaH_getn (Table *t) {
 199.564 +  unsigned int j = t->sizearray;
 199.565 +  if (j > 0 && ttisnil(&t->array[j - 1])) {
 199.566 +    /* there is a boundary in the array part: (binary) search for it */
 199.567 +    unsigned int i = 0;
 199.568 +    while (j - i > 1) {
 199.569 +      unsigned int m = (i+j)/2;
 199.570 +      if (ttisnil(&t->array[m - 1])) j = m;
 199.571 +      else i = m;
 199.572 +    }
 199.573 +    return i;
 199.574 +  }
 199.575 +  /* else must find a boundary in hash part */
 199.576 +  else if (t->node == dummynode)  /* hash part is empty? */
 199.577 +    return j;  /* that is easy... */
 199.578 +  else return unbound_search(t, j);
 199.579 +}
 199.580 +
 199.581 +
 199.582 +
 199.583 +#if defined(LUA_DEBUG)
 199.584 +
 199.585 +Node *luaH_mainposition (const Table *t, const TValue *key) {
 199.586 +  return mainposition(t, key);
 199.587 +}
 199.588 +
 199.589 +int luaH_isdummy (Node *n) { return n == dummynode; }
 199.590 +
 199.591 +#endif
   200.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   200.2 +++ b/src/lua/src/ltable.h	Sat Mar 03 10:31:27 2012 -0600
   200.3 @@ -0,0 +1,40 @@
   200.4 +/*
   200.5 +** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $
   200.6 +** Lua tables (hash)
   200.7 +** See Copyright Notice in lua.h
   200.8 +*/
   200.9 +
  200.10 +#ifndef ltable_h
  200.11 +#define ltable_h
  200.12 +
  200.13 +#include "lobject.h"
  200.14 +
  200.15 +
  200.16 +#define gnode(t,i)	(&(t)->node[i])
  200.17 +#define gkey(n)		(&(n)->i_key.nk)
  200.18 +#define gval(n)		(&(n)->i_val)
  200.19 +#define gnext(n)	((n)->i_key.nk.next)
  200.20 +
  200.21 +#define key2tval(n)	(&(n)->i_key.tvk)
  200.22 +
  200.23 +
  200.24 +LUAI_FUNC const TValue *luaH_getnum (Table *t, int key);
  200.25 +LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key);
  200.26 +LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
  200.27 +LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key);
  200.28 +LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
  200.29 +LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
  200.30 +LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash);
  200.31 +LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize);
  200.32 +LUAI_FUNC void luaH_free (lua_State *L, Table *t);
  200.33 +LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
  200.34 +LUAI_FUNC int luaH_getn (Table *t);
  200.35 +
  200.36 +
  200.37 +#if defined(LUA_DEBUG)
  200.38 +LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
  200.39 +LUAI_FUNC int luaH_isdummy (Node *n);
  200.40 +#endif
  200.41 +
  200.42 +
  200.43 +#endif
   201.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   201.2 +++ b/src/lua/src/ltablib.c	Sat Mar 03 10:31:27 2012 -0600
   201.3 @@ -0,0 +1,287 @@
   201.4 +/*
   201.5 +** $Id: ltablib.c,v 1.38.1.3 2008/02/14 16:46:58 roberto Exp $
   201.6 +** Library for Table Manipulation
   201.7 +** See Copyright Notice in lua.h
   201.8 +*/
   201.9 +
  201.10 +
  201.11 +#include <stddef.h>
  201.12 +
  201.13 +#define ltablib_c
  201.14 +#define LUA_LIB
  201.15 +
  201.16 +#include "lua.h"
  201.17 +
  201.18 +#include "lauxlib.h"
  201.19 +#include "lualib.h"
  201.20 +
  201.21 +
  201.22 +#define aux_getn(L,n)	(luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n))
  201.23 +
  201.24 +
  201.25 +static int foreachi (lua_State *L) {
  201.26 +  int i;
  201.27 +  int n = aux_getn(L, 1);
  201.28 +  luaL_checktype(L, 2, LUA_TFUNCTION);
  201.29 +  for (i=1; i <= n; i++) {
  201.30 +    lua_pushvalue(L, 2);  /* function */
  201.31 +    lua_pushinteger(L, i);  /* 1st argument */
  201.32 +    lua_rawgeti(L, 1, i);  /* 2nd argument */
  201.33 +    lua_call(L, 2, 1);
  201.34 +    if (!lua_isnil(L, -1))
  201.35 +      return 1;
  201.36 +    lua_pop(L, 1);  /* remove nil result */
  201.37 +  }
  201.38 +  return 0;
  201.39 +}
  201.40 +
  201.41 +
  201.42 +static int foreach (lua_State *L) {
  201.43 +  luaL_checktype(L, 1, LUA_TTABLE);
  201.44 +  luaL_checktype(L, 2, LUA_TFUNCTION);
  201.45 +  lua_pushnil(L);  /* first key */
  201.46 +  while (lua_next(L, 1)) {
  201.47 +    lua_pushvalue(L, 2);  /* function */
  201.48 +    lua_pushvalue(L, -3);  /* key */
  201.49 +    lua_pushvalue(L, -3);  /* value */
  201.50 +    lua_call(L, 2, 1);
  201.51 +    if (!lua_isnil(L, -1))
  201.52 +      return 1;
  201.53 +    lua_pop(L, 2);  /* remove value and result */
  201.54 +  }
  201.55 +  return 0;
  201.56 +}
  201.57 +
  201.58 +
  201.59 +static int maxn (lua_State *L) {
  201.60 +  lua_Number max = 0;
  201.61 +  luaL_checktype(L, 1, LUA_TTABLE);
  201.62 +  lua_pushnil(L);  /* first key */
  201.63 +  while (lua_next(L, 1)) {
  201.64 +    lua_pop(L, 1);  /* remove value */
  201.65 +    if (lua_type(L, -1) == LUA_TNUMBER) {
  201.66 +      lua_Number v = lua_tonumber(L, -1);
  201.67 +      if (v > max) max = v;
  201.68 +    }
  201.69 +  }
  201.70 +  lua_pushnumber(L, max);
  201.71 +  return 1;
  201.72 +}
  201.73 +
  201.74 +
  201.75 +static int getn (lua_State *L) {
  201.76 +  lua_pushinteger(L, aux_getn(L, 1));
  201.77 +  return 1;
  201.78 +}
  201.79 +
  201.80 +
  201.81 +static int setn (lua_State *L) {
  201.82 +  luaL_checktype(L, 1, LUA_TTABLE);
  201.83 +#ifndef luaL_setn
  201.84 +  luaL_setn(L, 1, luaL_checkint(L, 2));
  201.85 +#else
  201.86 +  luaL_error(L, LUA_QL("setn") " is obsolete");
  201.87 +#endif
  201.88 +  lua_pushvalue(L, 1);
  201.89 +  return 1;
  201.90 +}
  201.91 +
  201.92 +
  201.93 +static int tinsert (lua_State *L) {
  201.94 +  int e = aux_getn(L, 1) + 1;  /* first empty element */
  201.95 +  int pos;  /* where to insert new element */
  201.96 +  switch (lua_gettop(L)) {
  201.97 +    case 2: {  /* called with only 2 arguments */
  201.98 +      pos = e;  /* insert new element at the end */
  201.99 +      break;
 201.100 +    }
 201.101 +    case 3: {
 201.102 +      int i;
 201.103 +      pos = luaL_checkint(L, 2);  /* 2nd argument is the position */
 201.104 +      if (pos > e) e = pos;  /* `grow' array if necessary */
 201.105 +      for (i = e; i > pos; i--) {  /* move up elements */
 201.106 +        lua_rawgeti(L, 1, i-1);
 201.107 +        lua_rawseti(L, 1, i);  /* t[i] = t[i-1] */
 201.108 +      }
 201.109 +      break;
 201.110 +    }
 201.111 +    default: {
 201.112 +      return luaL_error(L, "wrong number of arguments to " LUA_QL("insert"));
 201.113 +    }
 201.114 +  }
 201.115 +  luaL_setn(L, 1, e);  /* new size */
 201.116 +  lua_rawseti(L, 1, pos);  /* t[pos] = v */
 201.117 +  return 0;
 201.118 +}
 201.119 +
 201.120 +
 201.121 +static int tremove (lua_State *L) {
 201.122 +  int e = aux_getn(L, 1);
 201.123 +  int pos = luaL_optint(L, 2, e);
 201.124 +  if (!(1 <= pos && pos <= e))  /* position is outside bounds? */
 201.125 +   return 0;  /* nothing to remove */
 201.126 +  luaL_setn(L, 1, e - 1);  /* t.n = n-1 */
 201.127 +  lua_rawgeti(L, 1, pos);  /* result = t[pos] */
 201.128 +  for ( ;pos<e; pos++) {
 201.129 +    lua_rawgeti(L, 1, pos+1);
 201.130 +    lua_rawseti(L, 1, pos);  /* t[pos] = t[pos+1] */
 201.131 +  }
 201.132 +  lua_pushnil(L);
 201.133 +  lua_rawseti(L, 1, e);  /* t[e] = nil */
 201.134 +  return 1;
 201.135 +}
 201.136 +
 201.137 +
 201.138 +static void addfield (lua_State *L, luaL_Buffer *b, int i) {
 201.139 +  lua_rawgeti(L, 1, i);
 201.140 +  if (!lua_isstring(L, -1))
 201.141 +    luaL_error(L, "invalid value (%s) at index %d in table for "
 201.142 +                  LUA_QL("concat"), luaL_typename(L, -1), i);
 201.143 +    luaL_addvalue(b);
 201.144 +}
 201.145 +
 201.146 +
 201.147 +static int tconcat (lua_State *L) {
 201.148 +  luaL_Buffer b;
 201.149 +  size_t lsep;
 201.150 +  int i, last;
 201.151 +  const char *sep = luaL_optlstring(L, 2, "", &lsep);
 201.152 +  luaL_checktype(L, 1, LUA_TTABLE);
 201.153 +  i = luaL_optint(L, 3, 1);
 201.154 +  last = luaL_opt(L, luaL_checkint, 4, luaL_getn(L, 1));
 201.155 +  luaL_buffinit(L, &b);
 201.156 +  for (; i < last; i++) {
 201.157 +    addfield(L, &b, i);
 201.158 +    luaL_addlstring(&b, sep, lsep);
 201.159 +  }
 201.160 +  if (i == last)  /* add last value (if interval was not empty) */
 201.161 +    addfield(L, &b, i);
 201.162 +  luaL_pushresult(&b);
 201.163 +  return 1;
 201.164 +}
 201.165 +
 201.166 +
 201.167 +
 201.168 +/*
 201.169 +** {======================================================
 201.170 +** Quicksort
 201.171 +** (based on `Algorithms in MODULA-3', Robert Sedgewick;
 201.172 +**  Addison-Wesley, 1993.)
 201.173 +*/
 201.174 +
 201.175 +
 201.176 +static void set2 (lua_State *L, int i, int j) {
 201.177 +  lua_rawseti(L, 1, i);
 201.178 +  lua_rawseti(L, 1, j);
 201.179 +}
 201.180 +
 201.181 +static int sort_comp (lua_State *L, int a, int b) {
 201.182 +  if (!lua_isnil(L, 2)) {  /* function? */
 201.183 +    int res;
 201.184 +    lua_pushvalue(L, 2);
 201.185 +    lua_pushvalue(L, a-1);  /* -1 to compensate function */
 201.186 +    lua_pushvalue(L, b-2);  /* -2 to compensate function and `a' */
 201.187 +    lua_call(L, 2, 1);
 201.188 +    res = lua_toboolean(L, -1);
 201.189 +    lua_pop(L, 1);
 201.190 +    return res;
 201.191 +  }
 201.192 +  else  /* a < b? */
 201.193 +    return lua_lessthan(L, a, b);
 201.194 +}
 201.195 +
 201.196 +static void auxsort (lua_State *L, int l, int u) {
 201.197 +  while (l < u) {  /* for tail recursion */
 201.198 +    int i, j;
 201.199 +    /* sort elements a[l], a[(l+u)/2] and a[u] */
 201.200 +    lua_rawgeti(L, 1, l);
 201.201 +    lua_rawgeti(L, 1, u);
 201.202 +    if (sort_comp(L, -1, -2))  /* a[u] < a[l]? */
 201.203 +      set2(L, l, u);  /* swap a[l] - a[u] */
 201.204 +    else
 201.205 +      lua_pop(L, 2);
 201.206 +    if (u-l == 1) break;  /* only 2 elements */
 201.207 +    i = (l+u)/2;
 201.208 +    lua_rawgeti(L, 1, i);
 201.209 +    lua_rawgeti(L, 1, l);
 201.210 +    if (sort_comp(L, -2, -1))  /* a[i]<a[l]? */
 201.211 +      set2(L, i, l);
 201.212 +    else {
 201.213 +      lua_pop(L, 1);  /* remove a[l] */
 201.214 +      lua_rawgeti(L, 1, u);
 201.215 +      if (sort_comp(L, -1, -2))  /* a[u]<a[i]? */
 201.216 +        set2(L, i, u);
 201.217 +      else
 201.218 +        lua_pop(L, 2);
 201.219 +    }
 201.220 +    if (u-l == 2) break;  /* only 3 elements */
 201.221 +    lua_rawgeti(L, 1, i);  /* Pivot */
 201.222 +    lua_pushvalue(L, -1);
 201.223 +    lua_rawgeti(L, 1, u-1);
 201.224 +    set2(L, i, u-1);
 201.225 +    /* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */
 201.226 +    i = l; j = u-1;
 201.227 +    for (;;) {  /* invariant: a[l..i] <= P <= a[j..u] */
 201.228 +      /* repeat ++i until a[i] >= P */
 201.229 +      while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {
 201.230 +        if (i>u) luaL_error(L, "invalid order function for sorting");
 201.231 +        lua_pop(L, 1);  /* remove a[i] */
 201.232 +      }
 201.233 +      /* repeat --j until a[j] <= P */
 201.234 +      while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {
 201.235 +        if (j<l) luaL_error(L, "invalid order function for sorting");
 201.236 +        lua_pop(L, 1);  /* remove a[j] */
 201.237 +      }
 201.238 +      if (j<i) {
 201.239 +        lua_pop(L, 3);  /* pop pivot, a[i], a[j] */
 201.240 +        break;
 201.241 +      }
 201.242 +      set2(L, i, j);
 201.243 +    }
 201.244 +    lua_rawgeti(L, 1, u-1);
 201.245 +    lua_rawgeti(L, 1, i);
 201.246 +    set2(L, u-1, i);  /* swap pivot (a[u-1]) with a[i] */
 201.247 +    /* a[l..i-1] <= a[i] == P <= a[i+1..u] */
 201.248 +    /* adjust so that smaller half is in [j..i] and larger one in [l..u] */
 201.249 +    if (i-l < u-i) {
 201.250 +      j=l; i=i-1; l=i+2;
 201.251 +    }
 201.252 +    else {
 201.253 +      j=i+1; i=u; u=j-2;
 201.254 +    }
 201.255 +    auxsort(L, j, i);  /* call recursively the smaller one */
 201.256 +  }  /* repeat the routine for the larger one */
 201.257 +}
 201.258 +
 201.259 +static int sort (lua_State *L) {
 201.260 +  int n = aux_getn(L, 1);
 201.261 +  luaL_checkstack(L, 40, "");  /* assume array is smaller than 2^40 */
 201.262 +  if (!lua_isnoneornil(L, 2))  /* is there a 2nd argument? */
 201.263 +    luaL_checktype(L, 2, LUA_TFUNCTION);
 201.264 +  lua_settop(L, 2);  /* make sure there is two arguments */
 201.265 +  auxsort(L, 1, n);
 201.266 +  return 0;
 201.267 +}
 201.268 +
 201.269 +/* }====================================================== */
 201.270 +
 201.271 +
 201.272 +static const luaL_Reg tab_funcs[] = {
 201.273 +  {"concat", tconcat},
 201.274 +  {"foreach", foreach},
 201.275 +  {"foreachi", foreachi},
 201.276 +  {"getn", getn},
 201.277 +  {"maxn", maxn},
 201.278 +  {"insert", tinsert},
 201.279 +  {"remove", tremove},
 201.280 +  {"setn", setn},
 201.281 +  {"sort", sort},
 201.282 +  {NULL, NULL}
 201.283 +};
 201.284 +
 201.285 +
 201.286 +LUALIB_API int luaopen_table (lua_State *L) {
 201.287 +  luaL_register(L, LUA_TABLIBNAME, tab_funcs);
 201.288 +  return 1;
 201.289 +}
 201.290 +
   202.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   202.2 +++ b/src/lua/src/ltm.c	Sat Mar 03 10:31:27 2012 -0600
   202.3 @@ -0,0 +1,75 @@
   202.4 +/*
   202.5 +** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
   202.6 +** Tag methods
   202.7 +** See Copyright Notice in lua.h
   202.8 +*/
   202.9 +
  202.10 +
  202.11 +#include <string.h>
  202.12 +
  202.13 +#define ltm_c
  202.14 +#define LUA_CORE
  202.15 +
  202.16 +#include "lua.h"
  202.17 +
  202.18 +#include "lobject.h"
  202.19 +#include "lstate.h"
  202.20 +#include "lstring.h"
  202.21 +#include "ltable.h"
  202.22 +#include "ltm.h"
  202.23 +
  202.24 +
  202.25 +
  202.26 +const char *const luaT_typenames[] = {
  202.27 +  "nil", "boolean", "userdata", "number",
  202.28 +  "string", "table", "function", "userdata", "thread",
  202.29 +  "proto", "upval"
  202.30 +};
  202.31 +
  202.32 +
  202.33 +void luaT_init (lua_State *L) {
  202.34 +  static const char *const luaT_eventname[] = {  /* ORDER TM */
  202.35 +    "__index", "__newindex",
  202.36 +    "__gc", "__mode", "__eq",
  202.37 +    "__add", "__sub", "__mul", "__div", "__mod",
  202.38 +    "__pow", "__unm", "__len", "__lt", "__le",
  202.39 +    "__concat", "__call"
  202.40 +  };
  202.41 +  int i;
  202.42 +  for (i=0; i<TM_N; i++) {
  202.43 +    G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);
  202.44 +    luaS_fix(G(L)->tmname[i]);  /* never collect these names */
  202.45 +  }
  202.46 +}
  202.47 +
  202.48 +
  202.49 +/*
  202.50 +** function to be used with macro "fasttm": optimized for absence of
  202.51 +** tag methods
  202.52 +*/
  202.53 +const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
  202.54 +  const TValue *tm = luaH_getstr(events, ename);
  202.55 +  lua_assert(event <= TM_EQ);
  202.56 +  if (ttisnil(tm)) {  /* no tag method? */
  202.57 +    events->flags |= cast_byte(1u<<event);  /* cache this fact */
  202.58 +    return NULL;
  202.59 +  }
  202.60 +  else return tm;
  202.61 +}
  202.62 +
  202.63 +
  202.64 +const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
  202.65 +  Table *mt;
  202.66 +  switch (ttype(o)) {
  202.67 +    case LUA_TTABLE:
  202.68 +      mt = hvalue(o)->metatable;
  202.69 +      break;
  202.70 +    case LUA_TUSERDATA:
  202.71 +      mt = uvalue(o)->metatable;
  202.72 +      break;
  202.73 +    default:
  202.74 +      mt = G(L)->mt[ttype(o)];
  202.75 +  }
  202.76 +  return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
  202.77 +}
  202.78 +
   203.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   203.2 +++ b/src/lua/src/ltm.h	Sat Mar 03 10:31:27 2012 -0600
   203.3 @@ -0,0 +1,54 @@
   203.4 +/*
   203.5 +** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $
   203.6 +** Tag methods
   203.7 +** See Copyright Notice in lua.h
   203.8 +*/
   203.9 +
  203.10 +#ifndef ltm_h
  203.11 +#define ltm_h
  203.12 +
  203.13 +
  203.14 +#include "lobject.h"
  203.15 +
  203.16 +
  203.17 +/*
  203.18 +* WARNING: if you change the order of this enumeration,
  203.19 +* grep "ORDER TM"
  203.20 +*/
  203.21 +typedef enum {
  203.22 +  TM_INDEX,
  203.23 +  TM_NEWINDEX,
  203.24 +  TM_GC,
  203.25 +  TM_MODE,
  203.26 +  TM_EQ,  /* last tag method with `fast' access */
  203.27 +  TM_ADD,
  203.28 +  TM_SUB,
  203.29 +  TM_MUL,
  203.30 +  TM_DIV,
  203.31 +  TM_MOD,
  203.32 +  TM_POW,
  203.33 +  TM_UNM,
  203.34 +  TM_LEN,
  203.35 +  TM_LT,
  203.36 +  TM_LE,
  203.37 +  TM_CONCAT,
  203.38 +  TM_CALL,
  203.39 +  TM_N		/* number of elements in the enum */
  203.40 +} TMS;
  203.41 +
  203.42 +
  203.43 +
  203.44 +#define gfasttm(g,et,e) ((et) == NULL ? NULL : \
  203.45 +  ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))
  203.46 +
  203.47 +#define fasttm(l,et,e)	gfasttm(G(l), et, e)
  203.48 +
  203.49 +LUAI_DATA const char *const luaT_typenames[];
  203.50 +
  203.51 +
  203.52 +LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);
  203.53 +LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,
  203.54 +                                                       TMS event);
  203.55 +LUAI_FUNC void luaT_init (lua_State *L);
  203.56 +
  203.57 +#endif
   204.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   204.2 +++ b/src/lua/src/lua.h	Sat Mar 03 10:31:27 2012 -0600
   204.3 @@ -0,0 +1,388 @@
   204.4 +/*
   204.5 +** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $
   204.6 +** Lua - An Extensible Extension Language
   204.7 +** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
   204.8 +** See Copyright Notice at the end of this file
   204.9 +*/
  204.10 +
  204.11 +
  204.12 +#ifndef lua_h
  204.13 +#define lua_h
  204.14 +
  204.15 +#include <stdarg.h>
  204.16 +#include <stddef.h>
  204.17 +
  204.18 +
  204.19 +#include "luaconf.h"
  204.20 +
  204.21 +
  204.22 +#define LUA_VERSION	"Lua 5.1"
  204.23 +#define LUA_RELEASE	"Lua 5.1.4"
  204.24 +#define LUA_VERSION_NUM	501
  204.25 +#define LUA_COPYRIGHT	"Copyright (C) 1994-2008 Lua.org, PUC-Rio"
  204.26 +#define LUA_AUTHORS 	"R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
  204.27 +
  204.28 +
  204.29 +/* mark for precompiled code (`<esc>Lua') */
  204.30 +#define	LUA_SIGNATURE	"\033Lua"
  204.31 +
  204.32 +/* option for multiple returns in `lua_pcall' and `lua_call' */
  204.33 +#define LUA_MULTRET	(-1)
  204.34 +
  204.35 +
  204.36 +/*
  204.37 +** pseudo-indices
  204.38 +*/
  204.39 +#define LUA_REGISTRYINDEX	(-10000)
  204.40 +#define LUA_ENVIRONINDEX	(-10001)
  204.41 +#define LUA_GLOBALSINDEX	(-10002)
  204.42 +#define lua_upvalueindex(i)	(LUA_GLOBALSINDEX-(i))
  204.43 +
  204.44 +
  204.45 +/* thread status; 0 is OK */
  204.46 +#define LUA_YIELD	1
  204.47 +#define LUA_ERRRUN	2
  204.48 +#define LUA_ERRSYNTAX	3
  204.49 +#define LUA_ERRMEM	4
  204.50 +#define LUA_ERRERR	5
  204.51 +
  204.52 +
  204.53 +typedef struct lua_State lua_State;
  204.54 +
  204.55 +typedef int (*lua_CFunction) (lua_State *L);
  204.56 +
  204.57 +
  204.58 +/*
  204.59 +** functions that read/write blocks when loading/dumping Lua chunks
  204.60 +*/
  204.61 +typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
  204.62 +
  204.63 +typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
  204.64 +
  204.65 +
  204.66 +/*
  204.67 +** prototype for memory-allocation functions
  204.68 +*/
  204.69 +typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
  204.70 +
  204.71 +
  204.72 +/*
  204.73 +** basic types
  204.74 +*/
  204.75 +#define LUA_TNONE		(-1)
  204.76 +
  204.77 +#define LUA_TNIL		0
  204.78 +#define LUA_TBOOLEAN		1
  204.79 +#define LUA_TLIGHTUSERDATA	2
  204.80 +#define LUA_TNUMBER		3
  204.81 +#define LUA_TSTRING		4
  204.82 +#define LUA_TTABLE		5
  204.83 +#define LUA_TFUNCTION		6
  204.84 +#define LUA_TUSERDATA		7
  204.85 +#define LUA_TTHREAD		8
  204.86 +
  204.87 +
  204.88 +
  204.89 +/* minimum Lua stack available to a C function */
  204.90 +#define LUA_MINSTACK	20
  204.91 +
  204.92 +
  204.93 +/*
  204.94 +** generic extra include file
  204.95 +*/
  204.96 +#if defined(LUA_USER_H)
  204.97 +#include LUA_USER_H
  204.98 +#endif
  204.99 +
 204.100 +
 204.101 +/* type of numbers in Lua */
 204.102 +typedef LUA_NUMBER lua_Number;
 204.103 +
 204.104 +
 204.105 +/* type for integer functions */
 204.106 +typedef LUA_INTEGER lua_Integer;
 204.107 +
 204.108 +
 204.109 +
 204.110 +/*
 204.111 +** state manipulation
 204.112 +*/
 204.113 +LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
 204.114 +LUA_API void       (lua_close) (lua_State *L);
 204.115 +LUA_API lua_State *(lua_newthread) (lua_State *L);
 204.116 +
 204.117 +LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
 204.118 +
 204.119 +
 204.120 +/*
 204.121 +** basic stack manipulation
 204.122 +*/
 204.123 +LUA_API int   (lua_gettop) (lua_State *L);
 204.124 +LUA_API void  (lua_settop) (lua_State *L, int idx);
 204.125 +LUA_API void  (lua_pushvalue) (lua_State *L, int idx);
 204.126 +LUA_API void  (lua_remove) (lua_State *L, int idx);
 204.127 +LUA_API void  (lua_insert) (lua_State *L, int idx);
 204.128 +LUA_API void  (lua_replace) (lua_State *L, int idx);
 204.129 +LUA_API int   (lua_checkstack) (lua_State *L, int sz);
 204.130 +
 204.131 +LUA_API void  (lua_xmove) (lua_State *from, lua_State *to, int n);
 204.132 +
 204.133 +
 204.134 +/*
 204.135 +** access functions (stack -> C)
 204.136 +*/
 204.137 +
 204.138 +LUA_API int             (lua_isnumber) (lua_State *L, int idx);
 204.139 +LUA_API int             (lua_isstring) (lua_State *L, int idx);
 204.140 +LUA_API int             (lua_iscfunction) (lua_State *L, int idx);
 204.141 +LUA_API int             (lua_isuserdata) (lua_State *L, int idx);
 204.142 +LUA_API int             (lua_type) (lua_State *L, int idx);
 204.143 +LUA_API const char     *(lua_typename) (lua_State *L, int tp);
 204.144 +
 204.145 +LUA_API int            (lua_equal) (lua_State *L, int idx1, int idx2);
 204.146 +LUA_API int            (lua_rawequal) (lua_State *L, int idx1, int idx2);
 204.147 +LUA_API int            (lua_lessthan) (lua_State *L, int idx1, int idx2);
 204.148 +
 204.149 +LUA_API lua_Number      (lua_tonumber) (lua_State *L, int idx);
 204.150 +LUA_API lua_Integer     (lua_tointeger) (lua_State *L, int idx);
 204.151 +LUA_API int             (lua_toboolean) (lua_State *L, int idx);
 204.152 +LUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);
 204.153 +LUA_API size_t          (lua_objlen) (lua_State *L, int idx);
 204.154 +LUA_API lua_CFunction   (lua_tocfunction) (lua_State *L, int idx);
 204.155 +LUA_API void	       *(lua_touserdata) (lua_State *L, int idx);
 204.156 +LUA_API lua_State      *(lua_tothread) (lua_State *L, int idx);
 204.157 +LUA_API const void     *(lua_topointer) (lua_State *L, int idx);
 204.158 +
 204.159 +
 204.160 +/*
 204.161 +** push functions (C -> stack)
 204.162 +*/
 204.163 +LUA_API void  (lua_pushnil) (lua_State *L);
 204.164 +LUA_API void  (lua_pushnumber) (lua_State *L, lua_Number n);
 204.165 +LUA_API void  (lua_pushinteger) (lua_State *L, lua_Integer n);
 204.166 +LUA_API void  (lua_pushlstring) (lua_State *L, const char *s, size_t l);
 204.167 +LUA_API void  (lua_pushstring) (lua_State *L, const char *s);
 204.168 +LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
 204.169 +                                                      va_list argp);
 204.170 +LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
 204.171 +LUA_API void  (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
 204.172 +LUA_API void  (lua_pushboolean) (lua_State *L, int b);
 204.173 +LUA_API void  (lua_pushlightuserdata) (lua_State *L, void *p);
 204.174 +LUA_API int   (lua_pushthread) (lua_State *L);
 204.175 +
 204.176 +
 204.177 +/*
 204.178 +** get functions (Lua -> stack)
 204.179 +*/
 204.180 +LUA_API void  (lua_gettable) (lua_State *L, int idx);
 204.181 +LUA_API void  (lua_getfield) (lua_State *L, int idx, const char *k);
 204.182 +LUA_API void  (lua_rawget) (lua_State *L, int idx);
 204.183 +LUA_API void  (lua_rawgeti) (lua_State *L, int idx, int n);
 204.184 +LUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);
 204.185 +LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
 204.186 +LUA_API int   (lua_getmetatable) (lua_State *L, int objindex);
 204.187 +LUA_API void  (lua_getfenv) (lua_State *L, int idx);
 204.188 +
 204.189 +
 204.190 +/*
 204.191 +** set functions (stack -> Lua)
 204.192 +*/
 204.193 +LUA_API void  (lua_settable) (lua_State *L, int idx);
 204.194 +LUA_API void  (lua_setfield) (lua_State *L, int idx, const char *k);
 204.195 +LUA_API void  (lua_rawset) (lua_State *L, int idx);
 204.196 +LUA_API void  (lua_rawseti) (lua_State *L, int idx, int n);
 204.197 +LUA_API int   (lua_setmetatable) (lua_State *L, int objindex);
 204.198 +LUA_API int   (lua_setfenv) (lua_State *L, int idx);
 204.199 +
 204.200 +
 204.201 +/*
 204.202 +** `load' and `call' functions (load and run Lua code)
 204.203 +*/
 204.204 +LUA_API void  (lua_call) (lua_State *L, int nargs, int nresults);
 204.205 +LUA_API int   (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
 204.206 +LUA_API int   (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
 204.207 +LUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,
 204.208 +                                        const char *chunkname);
 204.209 +
 204.210 +LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
 204.211 +
 204.212 +
 204.213 +/*
 204.214 +** coroutine functions
 204.215 +*/
 204.216 +LUA_API int  (lua_yield) (lua_State *L, int nresults);
 204.217 +LUA_API int  (lua_resume) (lua_State *L, int narg);
 204.218 +LUA_API int  (lua_status) (lua_State *L);
 204.219 +
 204.220 +/*
 204.221 +** garbage-collection function and options
 204.222 +*/
 204.223 +
 204.224 +#define LUA_GCSTOP		0
 204.225 +#define LUA_GCRESTART		1
 204.226 +#define LUA_GCCOLLECT		2
 204.227 +#define LUA_GCCOUNT		3
 204.228 +#define LUA_GCCOUNTB		4
 204.229 +#define LUA_GCSTEP		5
 204.230 +#define LUA_GCSETPAUSE		6
 204.231 +#define LUA_GCSETSTEPMUL	7
 204.232 +
 204.233 +LUA_API int (lua_gc) (lua_State *L, int what, int data);
 204.234 +
 204.235 +
 204.236 +/*
 204.237 +** miscellaneous functions
 204.238 +*/
 204.239 +
 204.240 +LUA_API int   (lua_error) (lua_State *L);
 204.241 +
 204.242 +LUA_API int   (lua_next) (lua_State *L, int idx);
 204.243 +
 204.244 +LUA_API void  (lua_concat) (lua_State *L, int n);
 204.245 +
 204.246 +LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
 204.247 +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
 204.248 +
 204.249 +
 204.250 +
 204.251 +/* 
 204.252 +** ===============================================================
 204.253 +** some useful macros
 204.254 +** ===============================================================
 204.255 +*/
 204.256 +
 204.257 +#define lua_pop(L,n)		lua_settop(L, -(n)-1)
 204.258 +
 204.259 +#define lua_newtable(L)		lua_createtable(L, 0, 0)
 204.260 +
 204.261 +#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
 204.262 +
 204.263 +#define lua_pushcfunction(L,f)	lua_pushcclosure(L, (f), 0)
 204.264 +
 204.265 +#define lua_strlen(L,i)		lua_objlen(L, (i))
 204.266 +
 204.267 +#define lua_isfunction(L,n)	(lua_type(L, (n)) == LUA_TFUNCTION)
 204.268 +#define lua_istable(L,n)	(lua_type(L, (n)) == LUA_TTABLE)
 204.269 +#define lua_islightuserdata(L,n)	(lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
 204.270 +#define lua_isnil(L,n)		(lua_type(L, (n)) == LUA_TNIL)
 204.271 +#define lua_isboolean(L,n)	(lua_type(L, (n)) == LUA_TBOOLEAN)
 204.272 +#define lua_isthread(L,n)	(lua_type(L, (n)) == LUA_TTHREAD)
 204.273 +#define lua_isnone(L,n)		(lua_type(L, (n)) == LUA_TNONE)
 204.274 +#define lua_isnoneornil(L, n)	(lua_type(L, (n)) <= 0)
 204.275 +
 204.276 +#define lua_pushliteral(L, s)	\
 204.277 +	lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
 204.278 +
 204.279 +#define lua_setglobal(L,s)	lua_setfield(L, LUA_GLOBALSINDEX, (s))
 204.280 +#define lua_getglobal(L,s)	lua_getfield(L, LUA_GLOBALSINDEX, (s))
 204.281 +
 204.282 +#define lua_tostring(L,i)	lua_tolstring(L, (i), NULL)
 204.283 +
 204.284 +
 204.285 +
 204.286 +/*
 204.287 +** compatibility macros and functions
 204.288 +*/
 204.289 +
 204.290 +#define lua_open()	luaL_newstate()
 204.291 +
 204.292 +#define lua_getregistry(L)	lua_pushvalue(L, LUA_REGISTRYINDEX)
 204.293 +
 204.294 +#define lua_getgccount(L)	lua_gc(L, LUA_GCCOUNT, 0)
 204.295 +
 204.296 +#define lua_Chunkreader		lua_Reader
 204.297 +#define lua_Chunkwriter		lua_Writer
 204.298 +
 204.299 +
 204.300 +/* hack */
 204.301 +LUA_API void lua_setlevel	(lua_State *from, lua_State *to);
 204.302 +
 204.303 +
 204.304 +/*
 204.305 +** {======================================================================
 204.306 +** Debug API
 204.307 +** =======================================================================
 204.308 +*/
 204.309 +
 204.310 +
 204.311 +/*
 204.312 +** Event codes
 204.313 +*/
 204.314 +#define LUA_HOOKCALL	0
 204.315 +#define LUA_HOOKRET	1
 204.316 +#define LUA_HOOKLINE	2
 204.317 +#define LUA_HOOKCOUNT	3
 204.318 +#define LUA_HOOKTAILRET 4
 204.319 +
 204.320 +
 204.321 +/*
 204.322 +** Event masks
 204.323 +*/
 204.324 +#define LUA_MASKCALL	(1 << LUA_HOOKCALL)
 204.325 +#define LUA_MASKRET	(1 << LUA_HOOKRET)
 204.326 +#define LUA_MASKLINE	(1 << LUA_HOOKLINE)
 204.327 +#define LUA_MASKCOUNT	(1 << LUA_HOOKCOUNT)
 204.328 +
 204.329 +typedef struct lua_Debug lua_Debug;  /* activation record */
 204.330 +
 204.331 +
 204.332 +/* Functions to be called by the debuger in specific events */
 204.333 +typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
 204.334 +
 204.335 +
 204.336 +LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
 204.337 +LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
 204.338 +LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
 204.339 +LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
 204.340 +LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);
 204.341 +LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);
 204.342 +
 204.343 +LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
 204.344 +LUA_API lua_Hook lua_gethook (lua_State *L);
 204.345 +LUA_API int lua_gethookmask (lua_State *L);
 204.346 +LUA_API int lua_gethookcount (lua_State *L);
 204.347 +
 204.348 +
 204.349 +struct lua_Debug {
 204.350 +  int event;
 204.351 +  const char *name;	/* (n) */
 204.352 +  const char *namewhat;	/* (n) `global', `local', `field', `method' */
 204.353 +  const char *what;	/* (S) `Lua', `C', `main', `tail' */
 204.354 +  const char *source;	/* (S) */
 204.355 +  int currentline;	/* (l) */
 204.356 +  int nups;		/* (u) number of upvalues */
 204.357 +  int linedefined;	/* (S) */
 204.358 +  int lastlinedefined;	/* (S) */
 204.359 +  char short_src[LUA_IDSIZE]; /* (S) */
 204.360 +  /* private part */
 204.361 +  int i_ci;  /* active function */
 204.362 +};
 204.363 +
 204.364 +/* }====================================================================== */
 204.365 +
 204.366 +
 204.367 +/******************************************************************************
 204.368 +* Copyright (C) 1994-2008 Lua.org, PUC-Rio.  All rights reserved.
 204.369 +*
 204.370 +* Permission is hereby granted, free of charge, to any person obtaining
 204.371 +* a copy of this software and associated documentation files (the
 204.372 +* "Software"), to deal in the Software without restriction, including
 204.373 +* without limitation the rights to use, copy, modify, merge, publish,
 204.374 +* distribute, sublicense, and/or sell copies of the Software, and to
 204.375 +* permit persons to whom the Software is furnished to do so, subject to
 204.376 +* the following conditions:
 204.377 +*
 204.378 +* The above copyright notice and this permission notice shall be
 204.379 +* included in all copies or substantial portions of the Software.
 204.380 +*
 204.381 +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 204.382 +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 204.383 +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 204.384 +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 204.385 +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 204.386 +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 204.387 +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 204.388 +******************************************************************************/
 204.389 +
 204.390 +
 204.391 +#endif
   205.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   205.2 +++ b/src/lua/src/luaconf.h	Sat Mar 03 10:31:27 2012 -0600
   205.3 @@ -0,0 +1,763 @@
   205.4 +/*
   205.5 +** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $
   205.6 +** Configuration file for Lua
   205.7 +** See Copyright Notice in lua.h
   205.8 +*/
   205.9 +
  205.10 +
  205.11 +#ifndef lconfig_h
  205.12 +#define lconfig_h
  205.13 +
  205.14 +#include <limits.h>
  205.15 +#include <stddef.h>
  205.16 +
  205.17 +
  205.18 +/*
  205.19 +** ==================================================================
  205.20 +** Search for "@@" to find all configurable definitions.
  205.21 +** ===================================================================
  205.22 +*/
  205.23 +
  205.24 +
  205.25 +/*
  205.26 +@@ LUA_ANSI controls the use of non-ansi features.
  205.27 +** CHANGE it (define it) if you want Lua to avoid the use of any
  205.28 +** non-ansi feature or library.
  205.29 +*/
  205.30 +#if defined(__STRICT_ANSI__)
  205.31 +#define LUA_ANSI
  205.32 +#endif
  205.33 +
  205.34 +
  205.35 +#if !defined(LUA_ANSI) && defined(_WIN32)
  205.36 +#define LUA_WIN
  205.37 +#endif
  205.38 +
  205.39 +#if defined(LUA_USE_LINUX)
  205.40 +#define LUA_USE_POSIX
  205.41 +#define LUA_USE_DLOPEN		/* needs an extra library: -ldl */
  205.42 +#define LUA_USE_READLINE	/* needs some extra libraries */
  205.43 +#endif
  205.44 +
  205.45 +#if defined(LUA_USE_MACOSX)
  205.46 +#define LUA_USE_POSIX
  205.47 +#define LUA_DL_DYLD		/* does not need extra library */
  205.48 +#endif
  205.49 +
  205.50 +
  205.51 +
  205.52 +/*
  205.53 +@@ LUA_USE_POSIX includes all functionallity listed as X/Open System
  205.54 +@* Interfaces Extension (XSI).
  205.55 +** CHANGE it (define it) if your system is XSI compatible.
  205.56 +*/
  205.57 +#if defined(LUA_USE_POSIX)
  205.58 +#define LUA_USE_MKSTEMP
  205.59 +#define LUA_USE_ISATTY
  205.60 +#define LUA_USE_POPEN
  205.61 +#define LUA_USE_ULONGJMP
  205.62 +#endif
  205.63 +
  205.64 +
  205.65 +/*
  205.66 +@@ LUA_PATH and LUA_CPATH are the names of the environment variables that
  205.67 +@* Lua check to set its paths.
  205.68 +@@ LUA_INIT is the name of the environment variable that Lua
  205.69 +@* checks for initialization code.
  205.70 +** CHANGE them if you want different names.
  205.71 +*/
  205.72 +#define LUA_PATH        "LUA_PATH"
  205.73 +#define LUA_CPATH       "LUA_CPATH"
  205.74 +#define LUA_INIT	"LUA_INIT"
  205.75 +
  205.76 +
  205.77 +/*
  205.78 +@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
  205.79 +@* Lua libraries.
  205.80 +@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
  205.81 +@* C libraries.
  205.82 +** CHANGE them if your machine has a non-conventional directory
  205.83 +** hierarchy or if you want to install your libraries in
  205.84 +** non-conventional directories.
  205.85 +*/
  205.86 +#if defined(_WIN32)
  205.87 +/*
  205.88 +** In Windows, any exclamation mark ('!') in the path is replaced by the
  205.89 +** path of the directory of the executable file of the current process.
  205.90 +*/
  205.91 +#define LUA_LDIR	"!\\lua\\"
  205.92 +#define LUA_CDIR	"!\\"
  205.93 +#define LUA_PATH_DEFAULT  \
  205.94 +		".\\?.lua;"  LUA_LDIR"?.lua;"  LUA_LDIR"?\\init.lua;" \
  205.95 +		             LUA_CDIR"?.lua;"  LUA_CDIR"?\\init.lua"
  205.96 +#define LUA_CPATH_DEFAULT \
  205.97 +	".\\?.dll;"  LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
  205.98 +
  205.99 +#else
 205.100 +#define LUA_ROOT	"/usr/local/"
 205.101 +#define LUA_LDIR	LUA_ROOT "share/lua/5.1/"
 205.102 +#define LUA_CDIR	LUA_ROOT "lib/lua/5.1/"
 205.103 +#define LUA_PATH_DEFAULT  \
 205.104 +		"./?.lua;"  LUA_LDIR"?.lua;"  LUA_LDIR"?/init.lua;" \
 205.105 +		            LUA_CDIR"?.lua;"  LUA_CDIR"?/init.lua"
 205.106 +#define LUA_CPATH_DEFAULT \
 205.107 +	"./?.so;"  LUA_CDIR"?.so;" LUA_CDIR"loadall.so"
 205.108 +#endif
 205.109 +
 205.110 +
 205.111 +/*
 205.112 +@@ LUA_DIRSEP is the directory separator (for submodules).
 205.113 +** CHANGE it if your machine does not use "/" as the directory separator
 205.114 +** and is not Windows. (On Windows Lua automatically uses "\".)
 205.115 +*/
 205.116 +#if defined(_WIN32)
 205.117 +#define LUA_DIRSEP	"\\"
 205.118 +#else
 205.119 +#define LUA_DIRSEP	"/"
 205.120 +#endif
 205.121 +
 205.122 +
 205.123 +/*
 205.124 +@@ LUA_PATHSEP is the character that separates templates in a path.
 205.125 +@@ LUA_PATH_MARK is the string that marks the substitution points in a
 205.126 +@* template.
 205.127 +@@ LUA_EXECDIR in a Windows path is replaced by the executable's
 205.128 +@* directory.
 205.129 +@@ LUA_IGMARK is a mark to ignore all before it when bulding the
 205.130 +@* luaopen_ function name.
 205.131 +** CHANGE them if for some reason your system cannot use those
 205.132 +** characters. (E.g., if one of those characters is a common character
 205.133 +** in file/directory names.) Probably you do not need to change them.
 205.134 +*/
 205.135 +#define LUA_PATHSEP	";"
 205.136 +#define LUA_PATH_MARK	"?"
 205.137 +#define LUA_EXECDIR	"!"
 205.138 +#define LUA_IGMARK	"-"
 205.139 +
 205.140 +
 205.141 +/*
 205.142 +@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
 205.143 +** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
 205.144 +** machines, ptrdiff_t gives a good choice between int or long.)
 205.145 +*/
 205.146 +#define LUA_INTEGER	ptrdiff_t
 205.147 +
 205.148 +
 205.149 +/*
 205.150 +@@ LUA_API is a mark for all core API functions.
 205.151 +@@ LUALIB_API is a mark for all standard library functions.
 205.152 +** CHANGE them if you need to define those functions in some special way.
 205.153 +** For instance, if you want to create one Windows DLL with the core and
 205.154 +** the libraries, you may want to use the following definition (define
 205.155 +** LUA_BUILD_AS_DLL to get it).
 205.156 +*/
 205.157 +#if defined(LUA_BUILD_AS_DLL)
 205.158 +
 205.159 +#if defined(LUA_CORE) || defined(LUA_LIB)
 205.160 +#define LUA_API __declspec(dllexport)
 205.161 +#else
 205.162 +#define LUA_API __declspec(dllimport)
 205.163 +#endif
 205.164 +
 205.165 +#else
 205.166 +
 205.167 +#define LUA_API		extern
 205.168 +
 205.169 +#endif
 205.170 +
 205.171 +/* more often than not the libs go together with the core */
 205.172 +#define LUALIB_API	LUA_API
 205.173 +
 205.174 +
 205.175 +/*
 205.176 +@@ LUAI_FUNC is a mark for all extern functions that are not to be
 205.177 +@* exported to outside modules.
 205.178 +@@ LUAI_DATA is a mark for all extern (const) variables that are not to
 205.179 +@* be exported to outside modules.
 205.180 +** CHANGE them if you need to mark them in some special way. Elf/gcc
 205.181 +** (versions 3.2 and later) mark them as "hidden" to optimize access
 205.182 +** when Lua is compiled as a shared library.
 205.183 +*/
 205.184 +#if defined(luaall_c)
 205.185 +#define LUAI_FUNC	static
 205.186 +#define LUAI_DATA	/* empty */
 205.187 +
 205.188 +#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
 205.189 +      defined(__ELF__)
 205.190 +#define LUAI_FUNC	__attribute__((visibility("hidden"))) extern
 205.191 +#define LUAI_DATA	LUAI_FUNC
 205.192 +
 205.193 +#else
 205.194 +#define LUAI_FUNC	extern
 205.195 +#define LUAI_DATA	extern
 205.196 +#endif
 205.197 +
 205.198 +
 205.199 +
 205.200 +/*
 205.201 +@@ LUA_QL describes how error messages quote program elements.
 205.202 +** CHANGE it if you want a different appearance.
 205.203 +*/
 205.204 +#define LUA_QL(x)	"'" x "'"
 205.205 +#define LUA_QS		LUA_QL("%s")
 205.206 +
 205.207 +
 205.208 +/*
 205.209 +@@ LUA_IDSIZE gives the maximum size for the description of the source
 205.210 +@* of a function in debug information.
 205.211 +** CHANGE it if you want a different size.
 205.212 +*/
 205.213 +#define LUA_IDSIZE	60
 205.214 +
 205.215 +
 205.216 +/*
 205.217 +** {==================================================================
 205.218 +** Stand-alone configuration
 205.219 +** ===================================================================
 205.220 +*/
 205.221 +
 205.222 +#if defined(lua_c) || defined(luaall_c)
 205.223 +
 205.224 +/*
 205.225 +@@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that
 205.226 +@* is, whether we're running lua interactively).
 205.227 +** CHANGE it if you have a better definition for non-POSIX/non-Windows
 205.228 +** systems.
 205.229 +*/
 205.230 +#if defined(LUA_USE_ISATTY)
 205.231 +#include <unistd.h>
 205.232 +#define lua_stdin_is_tty()	isatty(0)
 205.233 +#elif defined(LUA_WIN)
 205.234 +#include <io.h>
 205.235 +#include <stdio.h>
 205.236 +#define lua_stdin_is_tty()	_isatty(_fileno(stdin))
 205.237 +#else
 205.238 +#define lua_stdin_is_tty()	1  /* assume stdin is a tty */
 205.239 +#endif
 205.240 +
 205.241 +
 205.242 +/*
 205.243 +@@ LUA_PROMPT is the default prompt used by stand-alone Lua.
 205.244 +@@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.
 205.245 +** CHANGE them if you want different prompts. (You can also change the
 205.246 +** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
 205.247 +*/
 205.248 +#define LUA_PROMPT		"> "
 205.249 +#define LUA_PROMPT2		">> "
 205.250 +
 205.251 +
 205.252 +/*
 205.253 +@@ LUA_PROGNAME is the default name for the stand-alone Lua program.
 205.254 +** CHANGE it if your stand-alone interpreter has a different name and
 205.255 +** your system is not able to detect that name automatically.
 205.256 +*/
 205.257 +#define LUA_PROGNAME		"lua"
 205.258 +
 205.259 +
 205.260 +/*
 205.261 +@@ LUA_MAXINPUT is the maximum length for an input line in the
 205.262 +@* stand-alone interpreter.
 205.263 +** CHANGE it if you need longer lines.
 205.264 +*/
 205.265 +#define LUA_MAXINPUT	512
 205.266 +
 205.267 +
 205.268 +/*
 205.269 +@@ lua_readline defines how to show a prompt and then read a line from
 205.270 +@* the standard input.
 205.271 +@@ lua_saveline defines how to "save" a read line in a "history".
 205.272 +@@ lua_freeline defines how to free a line read by lua_readline.
 205.273 +** CHANGE them if you want to improve this functionality (e.g., by using
 205.274 +** GNU readline and history facilities).
 205.275 +*/
 205.276 +#if defined(LUA_USE_READLINE)
 205.277 +#include <stdio.h>
 205.278 +#include <readline/readline.h>
 205.279 +#include <readline/history.h>
 205.280 +#define lua_readline(L,b,p)	((void)L, ((b)=readline(p)) != NULL)
 205.281 +#define lua_saveline(L,idx) \
 205.282 +	if (lua_strlen(L,idx) > 0)  /* non-empty line? */ \
 205.283 +	  add_history(lua_tostring(L, idx));  /* add it to history */
 205.284 +#define lua_freeline(L,b)	((void)L, free(b))
 205.285 +#else
 205.286 +#define lua_readline(L,b,p)	\
 205.287 +	((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \
 205.288 +	fgets(b, LUA_MAXINPUT, stdin) != NULL)  /* get line */
 205.289 +#define lua_saveline(L,idx)	{ (void)L; (void)idx; }
 205.290 +#define lua_freeline(L,b)	{ (void)L; (void)b; }
 205.291 +#endif
 205.292 +
 205.293 +#endif
 205.294 +
 205.295 +/* }================================================================== */
 205.296 +
 205.297 +
 205.298 +/*
 205.299 +@@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles
 205.300 +@* as a percentage.
 205.301 +** CHANGE it if you want the GC to run faster or slower (higher values
 205.302 +** mean larger pauses which mean slower collection.) You can also change
 205.303 +** this value dynamically.
 205.304 +*/
 205.305 +#define LUAI_GCPAUSE	200  /* 200% (wait memory to double before next GC) */
 205.306 +
 205.307 +
 205.308 +/*
 205.309 +@@ LUAI_GCMUL defines the default speed of garbage collection relative to
 205.310 +@* memory allocation as a percentage.
 205.311 +** CHANGE it if you want to change the granularity of the garbage
 205.312 +** collection. (Higher values mean coarser collections. 0 represents
 205.313 +** infinity, where each step performs a full collection.) You can also
 205.314 +** change this value dynamically.
 205.315 +*/
 205.316 +#define LUAI_GCMUL	200 /* GC runs 'twice the speed' of memory allocation */
 205.317 +
 205.318 +
 205.319 +
 205.320 +/*
 205.321 +@@ LUA_COMPAT_GETN controls compatibility with old getn behavior.
 205.322 +** CHANGE it (define it) if you want exact compatibility with the
 205.323 +** behavior of setn/getn in Lua 5.0.
 205.324 +*/
 205.325 +#undef LUA_COMPAT_GETN
 205.326 +
 205.327 +/*
 205.328 +@@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib.
 205.329 +** CHANGE it to undefined as soon as you do not need a global 'loadlib'
 205.330 +** function (the function is still available as 'package.loadlib').
 205.331 +*/
 205.332 +#undef LUA_COMPAT_LOADLIB
 205.333 +
 205.334 +/*
 205.335 +@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature.
 205.336 +** CHANGE it to undefined as soon as your programs use only '...' to
 205.337 +** access vararg parameters (instead of the old 'arg' table).
 205.338 +*/
 205.339 +#define LUA_COMPAT_VARARG
 205.340 +
 205.341 +/*
 205.342 +@@ LUA_COMPAT_MOD controls compatibility with old math.mod function.
 205.343 +** CHANGE it to undefined as soon as your programs use 'math.fmod' or
 205.344 +** the new '%' operator instead of 'math.mod'.
 205.345 +*/
 205.346 +#define LUA_COMPAT_MOD
 205.347 +
 205.348 +/*
 205.349 +@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting
 205.350 +@* facility.
 205.351 +** CHANGE it to 2 if you want the old behaviour, or undefine it to turn
 205.352 +** off the advisory error when nesting [[...]].
 205.353 +*/
 205.354 +#define LUA_COMPAT_LSTR		1
 205.355 +
 205.356 +/*
 205.357 +@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.
 205.358 +** CHANGE it to undefined as soon as you rename 'string.gfind' to
 205.359 +** 'string.gmatch'.
 205.360 +*/
 205.361 +#define LUA_COMPAT_GFIND
 205.362 +
 205.363 +/*
 205.364 +@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
 205.365 +@* behavior.
 205.366 +** CHANGE it to undefined as soon as you replace to 'luaL_register'
 205.367 +** your uses of 'luaL_openlib'
 205.368 +*/
 205.369 +#define LUA_COMPAT_OPENLIB
 205.370 +
 205.371 +
 205.372 +
 205.373 +/*
 205.374 +@@ luai_apicheck is the assert macro used by the Lua-C API.
 205.375 +** CHANGE luai_apicheck if you want Lua to perform some checks in the
 205.376 +** parameters it gets from API calls. This may slow down the interpreter
 205.377 +** a bit, but may be quite useful when debugging C code that interfaces
 205.378 +** with Lua. A useful redefinition is to use assert.h.
 205.379 +*/
 205.380 +#if defined(LUA_USE_APICHECK)
 205.381 +#include <assert.h>
 205.382 +#define luai_apicheck(L,o)	{ (void)L; assert(o); }
 205.383 +#else
 205.384 +#define luai_apicheck(L,o)	{ (void)L; }
 205.385 +#endif
 205.386 +
 205.387 +
 205.388 +/*
 205.389 +@@ LUAI_BITSINT defines the number of bits in an int.
 205.390 +** CHANGE here if Lua cannot automatically detect the number of bits of
 205.391 +** your machine. Probably you do not need to change this.
 205.392 +*/
 205.393 +/* avoid overflows in comparison */
 205.394 +#if INT_MAX-20 < 32760
 205.395 +#define LUAI_BITSINT	16
 205.396 +#elif INT_MAX > 2147483640L
 205.397 +/* int has at least 32 bits */
 205.398 +#define LUAI_BITSINT	32
 205.399 +#else
 205.400 +#error "you must define LUA_BITSINT with number of bits in an integer"
 205.401 +#endif
 205.402 +
 205.403 +
 205.404 +/*
 205.405 +@@ LUAI_UINT32 is an unsigned integer with at least 32 bits.
 205.406 +@@ LUAI_INT32 is an signed integer with at least 32 bits.
 205.407 +@@ LUAI_UMEM is an unsigned integer big enough to count the total
 205.408 +@* memory used by Lua.
 205.409 +@@ LUAI_MEM is a signed integer big enough to count the total memory
 205.410 +@* used by Lua.
 205.411 +** CHANGE here if for some weird reason the default definitions are not
 205.412 +** good enough for your machine. (The definitions in the 'else'
 205.413 +** part always works, but may waste space on machines with 64-bit
 205.414 +** longs.) Probably you do not need to change this.
 205.415 +*/
 205.416 +#if LUAI_BITSINT >= 32
 205.417 +#define LUAI_UINT32	unsigned int
 205.418 +#define LUAI_INT32	int
 205.419 +#define LUAI_MAXINT32	INT_MAX
 205.420 +#define LUAI_UMEM	size_t
 205.421 +#define LUAI_MEM	ptrdiff_t
 205.422 +#else
 205.423 +/* 16-bit ints */
 205.424 +#define LUAI_UINT32	unsigned long
 205.425 +#define LUAI_INT32	long
 205.426 +#define LUAI_MAXINT32	LONG_MAX
 205.427 +#define LUAI_UMEM	unsigned long
 205.428 +#define LUAI_MEM	long
 205.429 +#endif
 205.430 +
 205.431 +
 205.432 +/*
 205.433 +@@ LUAI_MAXCALLS limits the number of nested calls.
 205.434 +** CHANGE it if you need really deep recursive calls. This limit is
 205.435 +** arbitrary; its only purpose is to stop infinite recursion before
 205.436 +** exhausting memory.
 205.437 +*/
 205.438 +#define LUAI_MAXCALLS	20000
 205.439 +
 205.440 +
 205.441 +/*
 205.442 +@@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function
 205.443 +@* can use.
 205.444 +** CHANGE it if you need lots of (Lua) stack space for your C
 205.445 +** functions. This limit is arbitrary; its only purpose is to stop C
 205.446 +** functions to consume unlimited stack space. (must be smaller than
 205.447 +** -LUA_REGISTRYINDEX)
 205.448 +*/
 205.449 +#define LUAI_MAXCSTACK	8000
 205.450 +
 205.451 +
 205.452 +
 205.453 +/*
 205.454 +** {==================================================================
 205.455 +** CHANGE (to smaller values) the following definitions if your system
 205.456 +** has a small C stack. (Or you may want to change them to larger
 205.457 +** values if your system has a large C stack and these limits are
 205.458 +** too rigid for you.) Some of these constants control the size of
 205.459 +** stack-allocated arrays used by the compiler or the interpreter, while
 205.460 +** others limit the maximum number of recursive calls that the compiler
 205.461 +** or the interpreter can perform. Values too large may cause a C stack
 205.462 +** overflow for some forms of deep constructs.
 205.463 +** ===================================================================
 205.464 +*/
 205.465 +
 205.466 +
 205.467 +/*
 205.468 +@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and
 205.469 +@* syntactical nested non-terminals in a program.
 205.470 +*/
 205.471 +#define LUAI_MAXCCALLS		200
 205.472 +
 205.473 +
 205.474 +/*
 205.475 +@@ LUAI_MAXVARS is the maximum number of local variables per function
 205.476 +@* (must be smaller than 250).
 205.477 +*/
 205.478 +#define LUAI_MAXVARS		200
 205.479 +
 205.480 +
 205.481 +/*
 205.482 +@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function
 205.483 +@* (must be smaller than 250).
 205.484 +*/
 205.485 +#define LUAI_MAXUPVALUES	60
 205.486 +
 205.487 +
 205.488 +/*
 205.489 +@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
 205.490 +*/
 205.491 +#define LUAL_BUFFERSIZE		BUFSIZ
 205.492 +
 205.493 +/* }================================================================== */
 205.494 +
 205.495 +
 205.496 +
 205.497 +
 205.498 +/*
 205.499 +** {==================================================================
 205.500 +@@ LUA_NUMBER is the type of numbers in Lua.
 205.501 +** CHANGE the following definitions only if you want to build Lua
 205.502 +** with a number type different from double. You may also need to
 205.503 +** change lua_number2int & lua_number2integer.
 205.504 +** ===================================================================
 205.505 +*/
 205.506 +
 205.507 +#define LUA_NUMBER_DOUBLE
 205.508 +#define LUA_NUMBER	double
 205.509 +
 205.510 +/*
 205.511 +@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
 205.512 +@* over a number.
 205.513 +*/
 205.514 +#define LUAI_UACNUMBER	double
 205.515 +
 205.516 +
 205.517 +/*
 205.518 +@@ LUA_NUMBER_SCAN is the format for reading numbers.
 205.519 +@@ LUA_NUMBER_FMT is the format for writing numbers.
 205.520 +@@ lua_number2str converts a number to a string.
 205.521 +@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
 205.522 +@@ lua_str2number converts a string to a number.
 205.523 +*/
 205.524 +#define LUA_NUMBER_SCAN		"%lf"
 205.525 +#define LUA_NUMBER_FMT		"%.14g"
 205.526 +#define lua_number2str(s,n)	sprintf((s), LUA_NUMBER_FMT, (n))
 205.527 +#define LUAI_MAXNUMBER2STR	32 /* 16 digits, sign, point, and \0 */
 205.528 +#define lua_str2number(s,p)	strtod((s), (p))
 205.529 +
 205.530 +
 205.531 +/*
 205.532 +@@ The luai_num* macros define the primitive operations over numbers.
 205.533 +*/
 205.534 +#if defined(LUA_CORE)
 205.535 +#include <math.h>
 205.536 +#define luai_numadd(a,b)	((a)+(b))
 205.537 +#define luai_numsub(a,b)	((a)-(b))
 205.538 +#define luai_nummul(a,b)	((a)*(b))
 205.539 +#define luai_numdiv(a,b)	((a)/(b))
 205.540 +#define luai_nummod(a,b)	((a) - floor((a)/(b))*(b))
 205.541 +#define luai_numpow(a,b)	(pow(a,b))
 205.542 +#define luai_numunm(a)		(-(a))
 205.543 +#define luai_numeq(a,b)		((a)==(b))
 205.544 +#define luai_numlt(a,b)		((a)<(b))
 205.545 +#define luai_numle(a,b)		((a)<=(b))
 205.546 +#define luai_numisnan(a)	(!luai_numeq((a), (a)))
 205.547 +#endif
 205.548 +
 205.549 +
 205.550 +/*
 205.551 +@@ lua_number2int is a macro to convert lua_Number to int.
 205.552 +@@ lua_number2integer is a macro to convert lua_Number to lua_Integer.
 205.553 +** CHANGE them if you know a faster way to convert a lua_Number to
 205.554 +** int (with any rounding method and without throwing errors) in your
 205.555 +** system. In Pentium machines, a naive typecast from double to int
 205.556 +** in C is extremely slow, so any alternative is worth trying.
 205.557 +*/
 205.558 +
 205.559 +/* On a Pentium, resort to a trick */
 205.560 +#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \
 205.561 +    (defined(__i386) || defined (_M_IX86) || defined(__i386__))
 205.562 +
 205.563 +/* On a Microsoft compiler, use assembler */
 205.564 +#if 0//defined(_MSC_VER) // nitsuja: the "using assembly" method doesn't correctly handle integers between 0xFF000000 and and 0xFFFFFFFF, while the other branch does handle it correctly and it's not slower.
 205.565 +
 205.566 +#define lua_number2int(i,d)   __asm fld d   __asm fistp i
 205.567 +#define lua_number2integer(i,n)		lua_number2int(i, n)
 205.568 +
 205.569 +/* the next trick should work on any Pentium, but sometimes clashes
 205.570 +   with a DirectX idiosyncrasy */
 205.571 +#else
 205.572 +
 205.573 +union luai_Cast { double l_d; long l_l; };
 205.574 +#define lua_number2int(i,d) \
 205.575 +  { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
 205.576 +#define lua_number2integer(i,n)		lua_number2int(i, n)
 205.577 +
 205.578 +#endif
 205.579 +
 205.580 +
 205.581 +/* this option always works, but may be slow */
 205.582 +#else
 205.583 +#define lua_number2int(i,d)	((i)=(int)(d))
 205.584 +#define lua_number2integer(i,d)	((i)=(lua_Integer)(d))
 205.585 +
 205.586 +#endif
 205.587 +
 205.588 +/* }================================================================== */
 205.589 +
 205.590 +
 205.591 +/*
 205.592 +@@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment.
 205.593 +** CHANGE it if your system requires alignments larger than double. (For
 205.594 +** instance, if your system supports long doubles and they must be
 205.595 +** aligned in 16-byte boundaries, then you should add long double in the
 205.596 +** union.) Probably you do not need to change this.
 205.597 +*/
 205.598 +#define LUAI_USER_ALIGNMENT_T	union { double u; void *s; long l; }
 205.599 +
 205.600 +
 205.601 +/*
 205.602 +@@ LUAI_THROW/LUAI_TRY define how Lua does exception handling.
 205.603 +** CHANGE them if you prefer to use longjmp/setjmp even with C++
 205.604 +** or if want/don't to use _longjmp/_setjmp instead of regular
 205.605 +** longjmp/setjmp. By default, Lua handles errors with exceptions when
 205.606 +** compiling as C++ code, with _longjmp/_setjmp when asked to use them,
 205.607 +** and with longjmp/setjmp otherwise.
 205.608 +*/
 205.609 +#if defined(__cplusplus)
 205.610 +/* C++ exceptions */
 205.611 +#define LUAI_THROW(L,c)	throw(c)
 205.612 +#define LUAI_TRY(L,c,a)	try { a } catch(...) \
 205.613 +	{ if ((c)->status == 0) (c)->status = -1; }
 205.614 +#define luai_jmpbuf	int  /* dummy variable */
 205.615 +
 205.616 +#elif defined(LUA_USE_ULONGJMP)
 205.617 +/* in Unix, try _longjmp/_setjmp (more efficient) */
 205.618 +#define LUAI_THROW(L,c)	_longjmp((c)->b, 1)
 205.619 +#define LUAI_TRY(L,c,a)	if (_setjmp((c)->b) == 0) { a }
 205.620 +#define luai_jmpbuf	jmp_buf
 205.621 +
 205.622 +#else
 205.623 +/* default handling with long jumps */
 205.624 +#define LUAI_THROW(L,c)	longjmp((c)->b, 1)
 205.625 +#define LUAI_TRY(L,c,a)	if (setjmp((c)->b) == 0) { a }
 205.626 +#define luai_jmpbuf	jmp_buf
 205.627 +
 205.628 +#endif
 205.629 +
 205.630 +
 205.631 +/*
 205.632 +@@ LUA_MAXCAPTURES is the maximum number of captures that a pattern
 205.633 +@* can do during pattern-matching.
 205.634 +** CHANGE it if you need more captures. This limit is arbitrary.
 205.635 +*/
 205.636 +#define LUA_MAXCAPTURES		32
 205.637 +
 205.638 +
 205.639 +/*
 205.640 +@@ lua_tmpnam is the function that the OS library uses to create a
 205.641 +@* temporary name.
 205.642 +@@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam.
 205.643 +** CHANGE them if you have an alternative to tmpnam (which is considered
 205.644 +** insecure) or if you want the original tmpnam anyway.  By default, Lua
 205.645 +** uses tmpnam except when POSIX is available, where it uses mkstemp.
 205.646 +*/
 205.647 +#if defined(loslib_c) || defined(luaall_c)
 205.648 +
 205.649 +#if defined(LUA_USE_MKSTEMP)
 205.650 +#include <unistd.h>
 205.651 +#define LUA_TMPNAMBUFSIZE	32
 205.652 +#define lua_tmpnam(b,e)	{ \
 205.653 +	strcpy(b, "/tmp/lua_XXXXXX"); \
 205.654 +	e = mkstemp(b); \
 205.655 +	if (e != -1) close(e); \
 205.656 +	e = (e == -1); }
 205.657 +
 205.658 +#else
 205.659 +#define LUA_TMPNAMBUFSIZE	L_tmpnam
 205.660 +#define lua_tmpnam(b,e)		{ e = (tmpnam(b) == NULL); }
 205.661 +#endif
 205.662 +
 205.663 +#endif
 205.664 +
 205.665 +
 205.666 +/*
 205.667 +@@ lua_popen spawns a new process connected to the current one through
 205.668 +@* the file streams.
 205.669 +** CHANGE it if you have a way to implement it in your system.
 205.670 +*/
 205.671 +#if defined(LUA_USE_POPEN)
 205.672 +
 205.673 +#define lua_popen(L,c,m)	((void)L, fflush(NULL), popen(c,m))
 205.674 +#define lua_pclose(L,file)	((void)L, (pclose(file) != -1))
 205.675 +
 205.676 +#elif defined(LUA_WIN)
 205.677 +
 205.678 +#define lua_popen(L,c,m)	((void)L, _popen(c,m))
 205.679 +#define lua_pclose(L,file)	((void)L, (_pclose(file) != -1))
 205.680 +
 205.681 +#else
 205.682 +
 205.683 +#define lua_popen(L,c,m)	((void)((void)c, m),  \
 205.684 +		luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
 205.685 +#define lua_pclose(L,file)		((void)((void)L, file), 0)
 205.686 +
 205.687 +#endif
 205.688 +
 205.689 +/*
 205.690 +@@ LUA_DL_* define which dynamic-library system Lua should use.
 205.691 +** CHANGE here if Lua has problems choosing the appropriate
 205.692 +** dynamic-library system for your platform (either Windows' DLL, Mac's
 205.693 +** dyld, or Unix's dlopen). If your system is some kind of Unix, there
 205.694 +** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for
 205.695 +** it.  To use dlopen you also need to adapt the src/Makefile (probably
 205.696 +** adding -ldl to the linker options), so Lua does not select it
 205.697 +** automatically.  (When you change the makefile to add -ldl, you must
 205.698 +** also add -DLUA_USE_DLOPEN.)
 205.699 +** If you do not want any kind of dynamic library, undefine all these
 205.700 +** options.
 205.701 +** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD.
 205.702 +*/
 205.703 +#if defined(LUA_USE_DLOPEN)
 205.704 +#define LUA_DL_DLOPEN
 205.705 +#endif
 205.706 +
 205.707 +#if defined(LUA_WIN)
 205.708 +#define LUA_DL_DLL
 205.709 +#endif
 205.710 +
 205.711 +
 205.712 +/*
 205.713 +@@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State
 205.714 +@* (the data goes just *before* the lua_State pointer).
 205.715 +** CHANGE (define) this if you really need that. This value must be
 205.716 +** a multiple of the maximum alignment required for your machine.
 205.717 +*/
 205.718 +#define LUAI_EXTRASPACE		0
 205.719 +
 205.720 +
 205.721 +/*
 205.722 +@@ luai_userstate* allow user-specific actions on threads.
 205.723 +** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
 205.724 +** extra when a thread is created/deleted/resumed/yielded.
 205.725 +*/
 205.726 +#define luai_userstateopen(L)		((void)L)
 205.727 +#define luai_userstateclose(L)		((void)L)
 205.728 +#define luai_userstatethread(L,L1)	((void)L)
 205.729 +#define luai_userstatefree(L)		((void)L)
 205.730 +#define luai_userstateresume(L,n)	((void)L)
 205.731 +#define luai_userstateyield(L,n)	((void)L)
 205.732 +
 205.733 +
 205.734 +/*
 205.735 +@@ LUA_INTFRMLEN is the length modifier for integer conversions
 205.736 +@* in 'string.format'.
 205.737 +@@ LUA_INTFRM_T is the integer type correspoding to the previous length
 205.738 +@* modifier.
 205.739 +** CHANGE them if your system supports long long or does not support long.
 205.740 +*/
 205.741 +
 205.742 +#if defined(LUA_USELONGLONG)
 205.743 +
 205.744 +#define LUA_INTFRMLEN		"ll"
 205.745 +#define LUA_INTFRM_T		long long
 205.746 +
 205.747 +#else
 205.748 +
 205.749 +#define LUA_INTFRMLEN		"l"
 205.750 +#define LUA_INTFRM_T		long
 205.751 +
 205.752 +#endif
 205.753 +
 205.754 +
 205.755 +
 205.756 +/* =================================================================== */
 205.757 +
 205.758 +/*
 205.759 +** Local configuration. You can use this space to add your redefinitions
 205.760 +** without modifying the main part of the file.
 205.761 +*/
 205.762 +
 205.763 +
 205.764 +
 205.765 +#endif
 205.766 +
   206.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   206.2 +++ b/src/lua/src/lualib.h	Sat Mar 03 10:31:27 2012 -0600
   206.3 @@ -0,0 +1,53 @@
   206.4 +/*
   206.5 +** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $
   206.6 +** Lua standard libraries
   206.7 +** See Copyright Notice in lua.h
   206.8 +*/
   206.9 +
  206.10 +
  206.11 +#ifndef lualib_h
  206.12 +#define lualib_h
  206.13 +
  206.14 +#include "lua.h"
  206.15 +
  206.16 +
  206.17 +/* Key to file-handle type */
  206.18 +#define LUA_FILEHANDLE		"FILE*"
  206.19 +
  206.20 +
  206.21 +#define LUA_COLIBNAME	"coroutine"
  206.22 +LUALIB_API int (luaopen_base) (lua_State *L);
  206.23 +
  206.24 +#define LUA_TABLIBNAME	"table"
  206.25 +LUALIB_API int (luaopen_table) (lua_State *L);
  206.26 +
  206.27 +#define LUA_IOLIBNAME	"io"
  206.28 +LUALIB_API int (luaopen_io) (lua_State *L);
  206.29 +
  206.30 +#define LUA_OSLIBNAME	"os"
  206.31 +LUALIB_API int (luaopen_os) (lua_State *L);
  206.32 +
  206.33 +#define LUA_STRLIBNAME	"string"
  206.34 +LUALIB_API int (luaopen_string) (lua_State *L);
  206.35 +
  206.36 +#define LUA_MATHLIBNAME	"math"
  206.37 +LUALIB_API int (luaopen_math) (lua_State *L);
  206.38 +
  206.39 +#define LUA_DBLIBNAME	"debug"
  206.40 +LUALIB_API int (luaopen_debug) (lua_State *L);
  206.41 +
  206.42 +#define LUA_LOADLIBNAME	"package"
  206.43 +LUALIB_API int (luaopen_package) (lua_State *L);
  206.44 +
  206.45 +
  206.46 +/* open all previous libraries */
  206.47 +LUALIB_API void (luaL_openlibs) (lua_State *L); 
  206.48 +
  206.49 +
  206.50 +
  206.51 +#ifndef lua_assert
  206.52 +#define lua_assert(x)	((void)0)
  206.53 +#endif
  206.54 +
  206.55 +
  206.56 +#endif
   207.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   207.2 +++ b/src/lua/src/lundump.c	Sat Mar 03 10:31:27 2012 -0600
   207.3 @@ -0,0 +1,227 @@
   207.4 +/*
   207.5 +** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $
   207.6 +** load precompiled Lua chunks
   207.7 +** See Copyright Notice in lua.h
   207.8 +*/
   207.9 +
  207.10 +#include <string.h>
  207.11 +
  207.12 +#define lundump_c
  207.13 +#define LUA_CORE
  207.14 +
  207.15 +#include "lua.h"
  207.16 +
  207.17 +#include "ldebug.h"
  207.18 +#include "ldo.h"
  207.19 +#include "lfunc.h"
  207.20 +#include "lmem.h"
  207.21 +#include "lobject.h"
  207.22 +#include "lstring.h"
  207.23 +#include "lundump.h"
  207.24 +#include "lzio.h"
  207.25 +
  207.26 +typedef struct {
  207.27 + lua_State* L;
  207.28 + ZIO* Z;
  207.29 + Mbuffer* b;
  207.30 + const char* name;
  207.31 +} LoadState;
  207.32 +
  207.33 +#ifdef LUAC_TRUST_BINARIES
  207.34 +#define IF(c,s)
  207.35 +#define error(S,s)
  207.36 +#else
  207.37 +#define IF(c,s)		if (c) error(S,s)
  207.38 +
  207.39 +static void error(LoadState* S, const char* why)
  207.40 +{
  207.41 + luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why);
  207.42 + luaD_throw(S->L,LUA_ERRSYNTAX);
  207.43 +}
  207.44 +#endif
  207.45 +
  207.46 +#define LoadMem(S,b,n,size)	LoadBlock(S,b,(n)*(size))
  207.47 +#define	LoadByte(S)		(lu_byte)LoadChar(S)
  207.48 +#define LoadVar(S,x)		LoadMem(S,&x,1,sizeof(x))
  207.49 +#define LoadVector(S,b,n,size)	LoadMem(S,b,n,size)
  207.50 +
  207.51 +static void LoadBlock(LoadState* S, void* b, size_t size)
  207.52 +{
  207.53 + size_t r=luaZ_read(S->Z,b,size);
  207.54 + IF (r!=0, "unexpected end");
  207.55 +}
  207.56 +
  207.57 +static int LoadChar(LoadState* S)
  207.58 +{
  207.59 + char x;
  207.60 + LoadVar(S,x);
  207.61 + return x;
  207.62 +}
  207.63 +
  207.64 +static int LoadInt(LoadState* S)
  207.65 +{
  207.66 + int x;
  207.67 + LoadVar(S,x);
  207.68 + IF (x<0, "bad integer");
  207.69 + return x;
  207.70 +}
  207.71 +
  207.72 +static lua_Number LoadNumber(LoadState* S)
  207.73 +{
  207.74 + lua_Number x;
  207.75 + LoadVar(S,x);
  207.76 + return x;
  207.77 +}
  207.78 +
  207.79 +static TString* LoadString(LoadState* S)
  207.80 +{
  207.81 + size_t size;
  207.82 + LoadVar(S,size);
  207.83 + if (size==0)
  207.84 +  return NULL;
  207.85 + else
  207.86 + {
  207.87 +  char* s=luaZ_openspace(S->L,S->b,size);
  207.88 +  LoadBlock(S,s,size);
  207.89 +  return luaS_newlstr(S->L,s,size-1);		/* remove trailing '\0' */
  207.90 + }
  207.91 +}
  207.92 +
  207.93 +static void LoadCode(LoadState* S, Proto* f)
  207.94 +{
  207.95 + int n=LoadInt(S);
  207.96 + f->code=luaM_newvector(S->L,n,Instruction);
  207.97 + f->sizecode=n;
  207.98 + LoadVector(S,f->code,n,sizeof(Instruction));
  207.99 +}
 207.100 +
 207.101 +static Proto* LoadFunction(LoadState* S, TString* p);
 207.102 +
 207.103 +static void LoadConstants(LoadState* S, Proto* f)
 207.104 +{
 207.105 + int i,n;
 207.106 + n=LoadInt(S);
 207.107 + f->k=luaM_newvector(S->L,n,TValue);
 207.108 + f->sizek=n;
 207.109 + for (i=0; i<n; i++) setnilvalue(&f->k[i]);
 207.110 + for (i=0; i<n; i++)
 207.111 + {
 207.112 +  TValue* o=&f->k[i];
 207.113 +  int t=LoadChar(S);
 207.114 +  switch (t)
 207.115 +  {
 207.116 +   case LUA_TNIL:
 207.117 +   	setnilvalue(o);
 207.118 +	break;
 207.119 +   case LUA_TBOOLEAN:
 207.120 +   	setbvalue(o,LoadChar(S)!=0);
 207.121 +	break;
 207.122 +   case LUA_TNUMBER:
 207.123 +	setnvalue(o,LoadNumber(S));
 207.124 +	break;
 207.125 +   case LUA_TSTRING:
 207.126 +	setsvalue2n(S->L,o,LoadString(S));
 207.127 +	break;
 207.128 +   default:
 207.129 +	error(S,"bad constant");
 207.130 +	break;
 207.131 +  }
 207.132 + }
 207.133 + n=LoadInt(S);
 207.134 + f->p=luaM_newvector(S->L,n,Proto*);
 207.135 + f->sizep=n;
 207.136 + for (i=0; i<n; i++) f->p[i]=NULL;
 207.137 + for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source);
 207.138 +}
 207.139 +
 207.140 +static void LoadDebug(LoadState* S, Proto* f)
 207.141 +{
 207.142 + int i,n;
 207.143 + n=LoadInt(S);
 207.144 + f->lineinfo=luaM_newvector(S->L,n,int);
 207.145 + f->sizelineinfo=n;
 207.146 + LoadVector(S,f->lineinfo,n,sizeof(int));
 207.147 + n=LoadInt(S);
 207.148 + f->locvars=luaM_newvector(S->L,n,LocVar);
 207.149 + f->sizelocvars=n;
 207.150 + for (i=0; i<n; i++) f->locvars[i].varname=NULL;
 207.151 + for (i=0; i<n; i++)
 207.152 + {
 207.153 +  f->locvars[i].varname=LoadString(S);
 207.154 +  f->locvars[i].startpc=LoadInt(S);
 207.155 +  f->locvars[i].endpc=LoadInt(S);
 207.156 + }
 207.157 + n=LoadInt(S);
 207.158 + f->upvalues=luaM_newvector(S->L,n,TString*);
 207.159 + f->sizeupvalues=n;
 207.160 + for (i=0; i<n; i++) f->upvalues[i]=NULL;
 207.161 + for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);
 207.162 +}
 207.163 +
 207.164 +static Proto* LoadFunction(LoadState* S, TString* p)
 207.165 +{
 207.166 + Proto* f;
 207.167 + if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep");
 207.168 + f=luaF_newproto(S->L);
 207.169 + setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
 207.170 + f->source=LoadString(S); if (f->source==NULL) f->source=p;
 207.171 + f->linedefined=LoadInt(S);
 207.172 + f->lastlinedefined=LoadInt(S);
 207.173 + f->nups=LoadByte(S);
 207.174 + f->numparams=LoadByte(S);
 207.175 + f->is_vararg=LoadByte(S);
 207.176 + f->maxstacksize=LoadByte(S);
 207.177 + LoadCode(S,f);
 207.178 + LoadConstants(S,f);
 207.179 + LoadDebug(S,f);
 207.180 + IF (!luaG_checkcode(f), "bad code");
 207.181 + S->L->top--;
 207.182 + S->L->nCcalls--;
 207.183 + return f;
 207.184 +}
 207.185 +
 207.186 +static void LoadHeader(LoadState* S)
 207.187 +{
 207.188 + char h[LUAC_HEADERSIZE];
 207.189 + char s[LUAC_HEADERSIZE];
 207.190 + luaU_header(h);
 207.191 + LoadBlock(S,s,LUAC_HEADERSIZE);
 207.192 + IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
 207.193 +}
 207.194 +
 207.195 +/*
 207.196 +** load precompiled chunk
 207.197 +*/
 207.198 +Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
 207.199 +{
 207.200 + LoadState S;
 207.201 + if (*name=='@' || *name=='=')
 207.202 +  S.name=name+1;
 207.203 + else if (*name==LUA_SIGNATURE[0])
 207.204 +  S.name="binary string";
 207.205 + else
 207.206 +  S.name=name;
 207.207 + S.L=L;
 207.208 + S.Z=Z;
 207.209 + S.b=buff;
 207.210 + LoadHeader(&S);
 207.211 + return LoadFunction(&S,luaS_newliteral(L,"=?"));
 207.212 +}
 207.213 +
 207.214 +/*
 207.215 +* make header
 207.216 +*/
 207.217 +void luaU_header (char* h)
 207.218 +{
 207.219 + int x=1;
 207.220 + memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
 207.221 + h+=sizeof(LUA_SIGNATURE)-1;
 207.222 + *h++=(char)LUAC_VERSION;
 207.223 + *h++=(char)LUAC_FORMAT;
 207.224 + *h++=(char)*(char*)&x;				/* endianness */
 207.225 + *h++=(char)sizeof(int);
 207.226 + *h++=(char)sizeof(size_t);
 207.227 + *h++=(char)sizeof(Instruction);
 207.228 + *h++=(char)sizeof(lua_Number);
 207.229 + *h++=(char)(((lua_Number)0.5)==0);		/* is lua_Number integral? */
 207.230 +}
   208.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   208.2 +++ b/src/lua/src/lundump.h	Sat Mar 03 10:31:27 2012 -0600
   208.3 @@ -0,0 +1,36 @@
   208.4 +/*
   208.5 +** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $
   208.6 +** load precompiled Lua chunks
   208.7 +** See Copyright Notice in lua.h
   208.8 +*/
   208.9 +
  208.10 +#ifndef lundump_h
  208.11 +#define lundump_h
  208.12 +
  208.13 +#include "lobject.h"
  208.14 +#include "lzio.h"
  208.15 +
  208.16 +/* load one chunk; from lundump.c */
  208.17 +LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name);
  208.18 +
  208.19 +/* make header; from lundump.c */
  208.20 +LUAI_FUNC void luaU_header (char* h);
  208.21 +
  208.22 +/* dump one chunk; from ldump.c */
  208.23 +LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
  208.24 +
  208.25 +#ifdef luac_c
  208.26 +/* print one chunk; from print.c */
  208.27 +LUAI_FUNC void luaU_print (const Proto* f, int full);
  208.28 +#endif
  208.29 +
  208.30 +/* for header of binary files -- this is Lua 5.1 */
  208.31 +#define LUAC_VERSION		0x51
  208.32 +
  208.33 +/* for header of binary files -- this is the official format */
  208.34 +#define LUAC_FORMAT		0
  208.35 +
  208.36 +/* size of header of binary files */
  208.37 +#define LUAC_HEADERSIZE		12
  208.38 +
  208.39 +#endif
   209.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   209.2 +++ b/src/lua/src/lvm.c	Sat Mar 03 10:31:27 2012 -0600
   209.3 @@ -0,0 +1,763 @@
   209.4 +/*
   209.5 +** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $
   209.6 +** Lua virtual machine
   209.7 +** See Copyright Notice in lua.h
   209.8 +*/
   209.9 +
  209.10 +
  209.11 +#include <stdio.h>
  209.12 +#include <stdlib.h>
  209.13 +#include <string.h>
  209.14 +
  209.15 +#define lvm_c
  209.16 +#define LUA_CORE
  209.17 +
  209.18 +#include "lua.h"
  209.19 +
  209.20 +#include "ldebug.h"
  209.21 +#include "ldo.h"
  209.22 +#include "lfunc.h"
  209.23 +#include "lgc.h"
  209.24 +#include "lobject.h"
  209.25 +#include "lopcodes.h"
  209.26 +#include "lstate.h"
  209.27 +#include "lstring.h"
  209.28 +#include "ltable.h"
  209.29 +#include "ltm.h"
  209.30 +#include "lvm.h"
  209.31 +
  209.32 +
  209.33 +
  209.34 +/* limit for table tag-method chains (to avoid loops) */
  209.35 +#define MAXTAGLOOP	100
  209.36 +
  209.37 +
  209.38 +const TValue *luaV_tonumber (const TValue *obj, TValue *n) {
  209.39 +  lua_Number num;
  209.40 +  if (ttisnumber(obj)) return obj;
  209.41 +  if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) {
  209.42 +    setnvalue(n, num);
  209.43 +    return n;
  209.44 +  }
  209.45 +  else
  209.46 +    return NULL;
  209.47 +}
  209.48 +
  209.49 +
  209.50 +int luaV_tostring (lua_State *L, StkId obj) {
  209.51 +  if (!ttisnumber(obj))
  209.52 +    return 0;
  209.53 +  else {
  209.54 +    char s[LUAI_MAXNUMBER2STR];
  209.55 +    lua_Number n = nvalue(obj);
  209.56 +    lua_number2str(s, n);
  209.57 +    setsvalue2s(L, obj, luaS_new(L, s));
  209.58 +    return 1;
  209.59 +  }
  209.60 +}
  209.61 +
  209.62 +
  209.63 +static void traceexec (lua_State *L, const Instruction *pc) {
  209.64 +  lu_byte mask = L->hookmask;
  209.65 +  const Instruction *oldpc = L->savedpc;
  209.66 +  L->savedpc = pc;
  209.67 +  if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) {
  209.68 +    resethookcount(L);
  209.69 +    luaD_callhook(L, LUA_HOOKCOUNT, -1);
  209.70 +  }
  209.71 +  if (mask & LUA_MASKLINE) {
  209.72 +    Proto *p = ci_func(L->ci)->l.p;
  209.73 +    int npc = pcRel(pc, p);
  209.74 +    int newline = getline(p, npc);
  209.75 +    /* call linehook when enter a new function, when jump back (loop),
  209.76 +       or when enter a new line */
  209.77 +    if (npc == 0 || pc <= oldpc || newline != getline(p, pcRel(oldpc, p)))
  209.78 +      luaD_callhook(L, LUA_HOOKLINE, newline);
  209.79 +  }
  209.80 +}
  209.81 +
  209.82 +
  209.83 +static void callTMres (lua_State *L, StkId res, const TValue *f,
  209.84 +                        const TValue *p1, const TValue *p2) {
  209.85 +  ptrdiff_t result = savestack(L, res);
  209.86 +  setobj2s(L, L->top, f);  /* push function */
  209.87 +  setobj2s(L, L->top+1, p1);  /* 1st argument */
  209.88 +  setobj2s(L, L->top+2, p2);  /* 2nd argument */
  209.89 +  luaD_checkstack(L, 3);
  209.90 +  L->top += 3;
  209.91 +  luaD_call(L, L->top - 3, 1);
  209.92 +  res = restorestack(L, result);
  209.93 +  L->top--;
  209.94 +  setobjs2s(L, res, L->top);
  209.95 +}
  209.96 +
  209.97 +
  209.98 +
  209.99 +static void callTM (lua_State *L, const TValue *f, const TValue *p1,
 209.100 +                    const TValue *p2, const TValue *p3) {
 209.101 +  setobj2s(L, L->top, f);  /* push function */
 209.102 +  setobj2s(L, L->top+1, p1);  /* 1st argument */
 209.103 +  setobj2s(L, L->top+2, p2);  /* 2nd argument */
 209.104 +  setobj2s(L, L->top+3, p3);  /* 3th argument */
 209.105 +  luaD_checkstack(L, 4);
 209.106 +  L->top += 4;
 209.107 +  luaD_call(L, L->top - 4, 0);
 209.108 +}
 209.109 +
 209.110 +
 209.111 +void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
 209.112 +  int loop;
 209.113 +  for (loop = 0; loop < MAXTAGLOOP; loop++) {
 209.114 +    const TValue *tm;
 209.115 +    if (ttistable(t)) {  /* `t' is a table? */
 209.116 +      Table *h = hvalue(t);
 209.117 +      const TValue *res = luaH_get(h, key); /* do a primitive get */
 209.118 +      if (!ttisnil(res) ||  /* result is no nil? */
 209.119 +          (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
 209.120 +        setobj2s(L, val, res);
 209.121 +        return;
 209.122 +      }
 209.123 +      /* else will try the tag method */
 209.124 +    }
 209.125 +    else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
 209.126 +      luaG_typeerror(L, t, "index");
 209.127 +    if (ttisfunction(tm)) {
 209.128 +      callTMres(L, val, tm, t, key);
 209.129 +      return;
 209.130 +    }
 209.131 +    t = tm;  /* else repeat with `tm' */ 
 209.132 +  }
 209.133 +  luaG_runerror(L, "loop in gettable");
 209.134 +}
 209.135 +
 209.136 +
 209.137 +void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
 209.138 +  int loop;
 209.139 +  for (loop = 0; loop < MAXTAGLOOP; loop++) {
 209.140 +    const TValue *tm;
 209.141 +    if (ttistable(t)) {  /* `t' is a table? */
 209.142 +      Table *h = hvalue(t);
 209.143 +      TValue *oldval = luaH_set(L, h, key); /* do a primitive set */
 209.144 +      if (!ttisnil(oldval) ||  /* result is no nil? */
 209.145 +          (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */
 209.146 +        setobj2t(L, oldval, val);
 209.147 +        luaC_barriert(L, h, val);
 209.148 +        return;
 209.149 +      }
 209.150 +      /* else will try the tag method */
 209.151 +    }
 209.152 +    else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
 209.153 +      luaG_typeerror(L, t, "index");
 209.154 +    if (ttisfunction(tm)) {
 209.155 +      callTM(L, tm, t, key, val);
 209.156 +      return;
 209.157 +    }
 209.158 +    t = tm;  /* else repeat with `tm' */ 
 209.159 +  }
 209.160 +  luaG_runerror(L, "loop in settable");
 209.161 +}
 209.162 +
 209.163 +
 209.164 +static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2,
 209.165 +                       StkId res, TMS event) {
 209.166 +  const TValue *tm = luaT_gettmbyobj(L, p1, event);  /* try first operand */
 209.167 +  if (ttisnil(tm))
 209.168 +    tm = luaT_gettmbyobj(L, p2, event);  /* try second operand */
 209.169 +  if (ttisnil(tm)) return 0;
 209.170 +  callTMres(L, res, tm, p1, p2);
 209.171 +  return 1;
 209.172 +}
 209.173 +
 209.174 +
 209.175 +static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2,
 209.176 +                                  TMS event) {
 209.177 +  const TValue *tm1 = fasttm(L, mt1, event);
 209.178 +  const TValue *tm2;
 209.179 +  if (tm1 == NULL) return NULL;  /* no metamethod */
 209.180 +  if (mt1 == mt2) return tm1;  /* same metatables => same metamethods */
 209.181 +  tm2 = fasttm(L, mt2, event);
 209.182 +  if (tm2 == NULL) return NULL;  /* no metamethod */
 209.183 +  if (luaO_rawequalObj(tm1, tm2))  /* same metamethods? */
 209.184 +    return tm1;
 209.185 +  return NULL;
 209.186 +}
 209.187 +
 209.188 +
 209.189 +static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2,
 209.190 +                         TMS event) {
 209.191 +  const TValue *tm1 = luaT_gettmbyobj(L, p1, event);
 209.192 +  const TValue *tm2;
 209.193 +  if (ttisnil(tm1)) return -1;  /* no metamethod? */
 209.194 +  tm2 = luaT_gettmbyobj(L, p2, event);
 209.195 +  if (!luaO_rawequalObj(tm1, tm2))  /* different metamethods? */
 209.196 +    return -1;
 209.197 +  callTMres(L, L->top, tm1, p1, p2);
 209.198 +  return !l_isfalse(L->top);
 209.199 +}
 209.200 +
 209.201 +
 209.202 +static int l_strcmp (const TString *ls, const TString *rs) {
 209.203 +  const char *l = getstr(ls);
 209.204 +  size_t ll = ls->tsv.len;
 209.205 +  const char *r = getstr(rs);
 209.206 +  size_t lr = rs->tsv.len;
 209.207 +  for (;;) {
 209.208 +    int temp = strcoll(l, r);
 209.209 +    if (temp != 0) return temp;
 209.210 +    else {  /* strings are equal up to a `\0' */
 209.211 +      size_t len = strlen(l);  /* index of first `\0' in both strings */
 209.212 +      if (len == lr)  /* r is finished? */
 209.213 +        return (len == ll) ? 0 : 1;
 209.214 +      else if (len == ll)  /* l is finished? */
 209.215 +        return -1;  /* l is smaller than r (because r is not finished) */
 209.216 +      /* both strings longer than `len'; go on comparing (after the `\0') */
 209.217 +      len++;
 209.218 +      l += len; ll -= len; r += len; lr -= len;
 209.219 +    }
 209.220 +  }
 209.221 +}
 209.222 +
 209.223 +
 209.224 +int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
 209.225 +  int res;
 209.226 +  if (ttype(l) != ttype(r))
 209.227 +    return luaG_ordererror(L, l, r);
 209.228 +  else if (ttisnumber(l))
 209.229 +    return luai_numlt(nvalue(l), nvalue(r));
 209.230 +  else if (ttisstring(l))
 209.231 +    return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
 209.232 +  else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
 209.233 +    return res;
 209.234 +  return luaG_ordererror(L, l, r);
 209.235 +}
 209.236 +
 209.237 +
 209.238 +static int lessequal (lua_State *L, const TValue *l, const TValue *r) {
 209.239 +  int res;
 209.240 +  if (ttype(l) != ttype(r))
 209.241 +    return luaG_ordererror(L, l, r);
 209.242 +  else if (ttisnumber(l))
 209.243 +    return luai_numle(nvalue(l), nvalue(r));
 209.244 +  else if (ttisstring(l))
 209.245 +    return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
 209.246 +  else if ((res = call_orderTM(L, l, r, TM_LE)) != -1)  /* first try `le' */
 209.247 +    return res;
 209.248 +  else if ((res = call_orderTM(L, r, l, TM_LT)) != -1)  /* else try `lt' */
 209.249 +    return !res;
 209.250 +  return luaG_ordererror(L, l, r);
 209.251 +}
 209.252 +
 209.253 +
 209.254 +int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) {
 209.255 +  const TValue *tm;
 209.256 +  lua_assert(ttype(t1) == ttype(t2));
 209.257 +  switch (ttype(t1)) {
 209.258 +    case LUA_TNIL: return 1;
 209.259 +    case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2));
 209.260 +    case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2);  /* true must be 1 !! */
 209.261 +    case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
 209.262 +    case LUA_TUSERDATA: {
 209.263 +      if (uvalue(t1) == uvalue(t2)) return 1;
 209.264 +      tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable,
 209.265 +                         TM_EQ);
 209.266 +      break;  /* will try TM */
 209.267 +    }
 209.268 +    case LUA_TTABLE: {
 209.269 +      if (hvalue(t1) == hvalue(t2)) return 1;
 209.270 +      tm = get_compTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ);
 209.271 +      break;  /* will try TM */
 209.272 +    }
 209.273 +    default: return gcvalue(t1) == gcvalue(t2);
 209.274 +  }
 209.275 +  if (tm == NULL) return 0;  /* no TM? */
 209.276 +  callTMres(L, L->top, tm, t1, t2);  /* call TM */
 209.277 +  return !l_isfalse(L->top);
 209.278 +}
 209.279 +
 209.280 +
 209.281 +void luaV_concat (lua_State *L, int total, int last) {
 209.282 +  do {
 209.283 +    StkId top = L->base + last + 1;
 209.284 +    int n = 2;  /* number of elements handled in this pass (at least 2) */
 209.285 +    if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
 209.286 +      if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
 209.287 +        luaG_concaterror(L, top-2, top-1);
 209.288 +    } else if (tsvalue(top-1)->len == 0)  /* second op is empty? */
 209.289 +      (void)tostring(L, top - 2);  /* result is first op (as string) */
 209.290 +    else {
 209.291 +      /* at least two string values; get as many as possible */
 209.292 +      size_t tl = tsvalue(top-1)->len;
 209.293 +      char *buffer;
 209.294 +      int i;
 209.295 +      /* collect total length */
 209.296 +      for (n = 1; n < total && tostring(L, top-n-1); n++) {
 209.297 +        size_t l = tsvalue(top-n-1)->len;
 209.298 +        if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow");
 209.299 +        tl += l;
 209.300 +      }
 209.301 +      buffer = luaZ_openspace(L, &G(L)->buff, tl);
 209.302 +      tl = 0;
 209.303 +      for (i=n; i>0; i--) {  /* concat all strings */
 209.304 +        size_t l = tsvalue(top-i)->len;
 209.305 +        memcpy(buffer+tl, svalue(top-i), l);
 209.306 +        tl += l;
 209.307 +      }
 209.308 +      setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
 209.309 +    }
 209.310 +    total -= n-1;  /* got `n' strings to create 1 new */
 209.311 +    last -= n-1;
 209.312 +  } while (total > 1);  /* repeat until only 1 result left */
 209.313 +}
 209.314 +
 209.315 +
 209.316 +static void Arith (lua_State *L, StkId ra, const TValue *rb,
 209.317 +                   const TValue *rc, TMS op) {
 209.318 +  TValue tempb, tempc;
 209.319 +  const TValue *b, *c;
 209.320 +  if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
 209.321 +      (c = luaV_tonumber(rc, &tempc)) != NULL) {
 209.322 +    lua_Number nb = nvalue(b), nc = nvalue(c);
 209.323 +    switch (op) {
 209.324 +      case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break;
 209.325 +      case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break;
 209.326 +      case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break;
 209.327 +      case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break;
 209.328 +      case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break;
 209.329 +      case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break;
 209.330 +      case TM_UNM: setnvalue(ra, luai_numunm(nb)); break;
 209.331 +      default: lua_assert(0); break;
 209.332 +    }
 209.333 +  }
 209.334 +  else if (!call_binTM(L, rb, rc, ra, op))
 209.335 +    luaG_aritherror(L, rb, rc);
 209.336 +}
 209.337 +
 209.338 +
 209.339 +
 209.340 +/*
 209.341 +** some macros for common tasks in `luaV_execute'
 209.342 +*/
 209.343 +
 209.344 +#define runtime_check(L, c)	{ if (!(c)) break; }
 209.345 +
 209.346 +#define RA(i)	(base+GETARG_A(i))
 209.347 +/* to be used after possible stack reallocation */
 209.348 +#define RB(i)	check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))
 209.349 +#define RC(i)	check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))
 209.350 +#define RKB(i)	check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \
 209.351 +	ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))
 209.352 +#define RKC(i)	check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \
 209.353 +	ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))
 209.354 +#define KBx(i)	check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i))
 209.355 +
 209.356 +
 209.357 +#define dojump(L,pc,i)	{(pc) += (i); luai_threadyield(L);}
 209.358 +
 209.359 +
 209.360 +#define Protect(x)	{ L->savedpc = pc; {x;}; base = L->base; }
 209.361 +
 209.362 +
 209.363 +#define arith_op(op,tm) { \
 209.364 +        TValue *rb = RKB(i); \
 209.365 +        TValue *rc = RKC(i); \
 209.366 +        if (ttisnumber(rb) && ttisnumber(rc)) { \
 209.367 +          lua_Number nb = nvalue(rb), nc = nvalue(rc); \
 209.368 +          setnvalue(ra, op(nb, nc)); \
 209.369 +        } \
 209.370 +        else \
 209.371 +          Protect(Arith(L, ra, rb, rc, tm)); \
 209.372 +      }
 209.373 +
 209.374 +
 209.375 +
 209.376 +void luaV_execute (lua_State *L, int nexeccalls) {
 209.377 +  LClosure *cl;
 209.378 +  StkId base;
 209.379 +  TValue *k;
 209.380 +  const Instruction *pc;
 209.381 + reentry:  /* entry point */
 209.382 +  lua_assert(isLua(L->ci));
 209.383 +  pc = L->savedpc;
 209.384 +  cl = &clvalue(L->ci->func)->l;
 209.385 +  base = L->base;
 209.386 +  k = cl->p->k;
 209.387 +  /* main loop of interpreter */
 209.388 +  for (;;) {
 209.389 +    const Instruction i = *pc++;
 209.390 +    StkId ra;
 209.391 +    if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
 209.392 +        (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
 209.393 +      traceexec(L, pc);
 209.394 +      if (L->status == LUA_YIELD) {  /* did hook yield? */
 209.395 +        L->savedpc = pc - 1;
 209.396 +        return;
 209.397 +      }
 209.398 +      base = L->base;
 209.399 +    }
 209.400 +    /* warning!! several calls may realloc the stack and invalidate `ra' */
 209.401 +    ra = RA(i);
 209.402 +    lua_assert(base == L->base && L->base == L->ci->base);
 209.403 +    lua_assert(base <= L->top && L->top <= L->stack + L->stacksize);
 209.404 +    lua_assert(L->top == L->ci->top || luaG_checkopenop(i));
 209.405 +    switch (GET_OPCODE(i)) {
 209.406 +      case OP_MOVE: {
 209.407 +        setobjs2s(L, ra, RB(i));
 209.408 +        continue;
 209.409 +      }
 209.410 +      case OP_LOADK: {
 209.411 +        setobj2s(L, ra, KBx(i));
 209.412 +        continue;
 209.413 +      }
 209.414 +      case OP_LOADBOOL: {
 209.415 +        setbvalue(ra, GETARG_B(i));
 209.416 +        if (GETARG_C(i)) pc++;  /* skip next instruction (if C) */
 209.417 +        continue;
 209.418 +      }
 209.419 +      case OP_LOADNIL: {
 209.420 +        TValue *rb = RB(i);
 209.421 +        do {
 209.422 +          setnilvalue(rb--);
 209.423 +        } while (rb >= ra);
 209.424 +        continue;
 209.425 +      }
 209.426 +      case OP_GETUPVAL: {
 209.427 +        int b = GETARG_B(i);
 209.428 +        setobj2s(L, ra, cl->upvals[b]->v);
 209.429 +        continue;
 209.430 +      }
 209.431 +      case OP_GETGLOBAL: {
 209.432 +        TValue g;
 209.433 +        TValue *rb = KBx(i);
 209.434 +        sethvalue(L, &g, cl->env);
 209.435 +        lua_assert(ttisstring(rb));
 209.436 +        Protect(luaV_gettable(L, &g, rb, ra));
 209.437 +        continue;
 209.438 +      }
 209.439 +      case OP_GETTABLE: {
 209.440 +        Protect(luaV_gettable(L, RB(i), RKC(i), ra));
 209.441 +        continue;
 209.442 +      }
 209.443 +      case OP_SETGLOBAL: {
 209.444 +        TValue g;
 209.445 +        sethvalue(L, &g, cl->env);
 209.446 +        lua_assert(ttisstring(KBx(i)));
 209.447 +        Protect(luaV_settable(L, &g, KBx(i), ra));
 209.448 +        continue;
 209.449 +      }
 209.450 +      case OP_SETUPVAL: {
 209.451 +        UpVal *uv = cl->upvals[GETARG_B(i)];
 209.452 +        setobj(L, uv->v, ra);
 209.453 +        luaC_barrier(L, uv, ra);
 209.454 +        continue;
 209.455 +      }
 209.456 +      case OP_SETTABLE: {
 209.457 +        Protect(luaV_settable(L, ra, RKB(i), RKC(i)));
 209.458 +        continue;
 209.459 +      }
 209.460 +      case OP_NEWTABLE: {
 209.461 +        int b = GETARG_B(i);
 209.462 +        int c = GETARG_C(i);
 209.463 +        sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c)));
 209.464 +        Protect(luaC_checkGC(L));
 209.465 +        continue;
 209.466 +      }
 209.467 +      case OP_SELF: {
 209.468 +        StkId rb = RB(i);
 209.469 +        setobjs2s(L, ra+1, rb);
 209.470 +        Protect(luaV_gettable(L, rb, RKC(i), ra));
 209.471 +        continue;
 209.472 +      }
 209.473 +      case OP_ADD: {
 209.474 +        arith_op(luai_numadd, TM_ADD);
 209.475 +        continue;
 209.476 +      }
 209.477 +      case OP_SUB: {
 209.478 +        arith_op(luai_numsub, TM_SUB);
 209.479 +        continue;
 209.480 +      }
 209.481 +      case OP_MUL: {
 209.482 +        arith_op(luai_nummul, TM_MUL);
 209.483 +        continue;
 209.484 +      }
 209.485 +      case OP_DIV: {
 209.486 +        arith_op(luai_numdiv, TM_DIV);
 209.487 +        continue;
 209.488 +      }
 209.489 +      case OP_MOD: {
 209.490 +        arith_op(luai_nummod, TM_MOD);
 209.491 +        continue;
 209.492 +      }
 209.493 +      case OP_POW: {
 209.494 +        arith_op(luai_numpow, TM_POW);
 209.495 +        continue;
 209.496 +      }
 209.497 +      case OP_UNM: {
 209.498 +        TValue *rb = RB(i);
 209.499 +        if (ttisnumber(rb)) {
 209.500 +          lua_Number nb = nvalue(rb);
 209.501 +          setnvalue(ra, luai_numunm(nb));
 209.502 +        }
 209.503 +        else {
 209.504 +          Protect(Arith(L, ra, rb, rb, TM_UNM));
 209.505 +        }
 209.506 +        continue;
 209.507 +      }
 209.508 +      case OP_NOT: {
 209.509 +        int res = l_isfalse(RB(i));  /* next assignment may change this value */
 209.510 +        setbvalue(ra, res);
 209.511 +        continue;
 209.512 +      }
 209.513 +      case OP_LEN: {
 209.514 +        const TValue *rb = RB(i);
 209.515 +        switch (ttype(rb)) {
 209.516 +          case LUA_TTABLE: {
 209.517 +            setnvalue(ra, cast_num(luaH_getn(hvalue(rb))));
 209.518 +            break;
 209.519 +          }
 209.520 +          case LUA_TSTRING: {
 209.521 +            setnvalue(ra, cast_num(tsvalue(rb)->len));
 209.522 +            break;
 209.523 +          }
 209.524 +          default: {  /* try metamethod */
 209.525 +            Protect(
 209.526 +              if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN))
 209.527 +                luaG_typeerror(L, rb, "get length of");
 209.528 +            )
 209.529 +          }
 209.530 +        }
 209.531 +        continue;
 209.532 +      }
 209.533 +      case OP_CONCAT: {
 209.534 +        int b = GETARG_B(i);
 209.535 +        int c = GETARG_C(i);
 209.536 +        Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L));
 209.537 +        setobjs2s(L, RA(i), base+b);
 209.538 +        continue;
 209.539 +      }
 209.540 +      case OP_JMP: {
 209.541 +        dojump(L, pc, GETARG_sBx(i));
 209.542 +        continue;
 209.543 +      }
 209.544 +      case OP_EQ: {
 209.545 +        TValue *rb = RKB(i);
 209.546 +        TValue *rc = RKC(i);
 209.547 +        Protect(
 209.548 +          if (equalobj(L, rb, rc) == GETARG_A(i))
 209.549 +            dojump(L, pc, GETARG_sBx(*pc));
 209.550 +        )
 209.551 +        pc++;
 209.552 +        continue;
 209.553 +      }
 209.554 +      case OP_LT: {
 209.555 +        Protect(
 209.556 +          if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i))
 209.557 +            dojump(L, pc, GETARG_sBx(*pc));
 209.558 +        )
 209.559 +        pc++;
 209.560 +        continue;
 209.561 +      }
 209.562 +      case OP_LE: {
 209.563 +        Protect(
 209.564 +          if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i))
 209.565 +            dojump(L, pc, GETARG_sBx(*pc));
 209.566 +        )
 209.567 +        pc++;
 209.568 +        continue;
 209.569 +      }
 209.570 +      case OP_TEST: {
 209.571 +        if (l_isfalse(ra) != GETARG_C(i))
 209.572 +          dojump(L, pc, GETARG_sBx(*pc));
 209.573 +        pc++;
 209.574 +        continue;
 209.575 +      }
 209.576 +      case OP_TESTSET: {
 209.577 +        TValue *rb = RB(i);
 209.578 +        if (l_isfalse(rb) != GETARG_C(i)) {
 209.579 +          setobjs2s(L, ra, rb);
 209.580 +          dojump(L, pc, GETARG_sBx(*pc));
 209.581 +        }
 209.582 +        pc++;
 209.583 +        continue;
 209.584 +      }
 209.585 +      case OP_CALL: {
 209.586 +        int b = GETARG_B(i);
 209.587 +        int nresults = GETARG_C(i) - 1;
 209.588 +        if (b != 0) L->top = ra+b;  /* else previous instruction set top */
 209.589 +        L->savedpc = pc;
 209.590 +        switch (luaD_precall(L, ra, nresults)) {
 209.591 +          case PCRLUA: {
 209.592 +            nexeccalls++;
 209.593 +            goto reentry;  /* restart luaV_execute over new Lua function */
 209.594 +          }
 209.595 +          case PCRC: {
 209.596 +            /* it was a C function (`precall' called it); adjust results */
 209.597 +            if (nresults >= 0) L->top = L->ci->top;
 209.598 +            base = L->base;
 209.599 +            continue;
 209.600 +          }
 209.601 +          default: {
 209.602 +            return;  /* yield */
 209.603 +          }
 209.604 +        }
 209.605 +      }
 209.606 +      case OP_TAILCALL: {
 209.607 +        int b = GETARG_B(i);
 209.608 +        if (b != 0) L->top = ra+b;  /* else previous instruction set top */
 209.609 +        L->savedpc = pc;
 209.610 +        lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);
 209.611 +        switch (luaD_precall(L, ra, LUA_MULTRET)) {
 209.612 +          case PCRLUA: {
 209.613 +            /* tail call: put new frame in place of previous one */
 209.614 +            CallInfo *ci = L->ci - 1;  /* previous frame */
 209.615 +            int aux;
 209.616 +            StkId func = ci->func;
 209.617 +            StkId pfunc = (ci+1)->func;  /* previous function index */
 209.618 +            if (L->openupval) luaF_close(L, ci->base);
 209.619 +            L->base = ci->base = ci->func + ((ci+1)->base - pfunc);
 209.620 +            for (aux = 0; pfunc+aux < L->top; aux++)  /* move frame down */
 209.621 +              setobjs2s(L, func+aux, pfunc+aux);
 209.622 +            ci->top = L->top = func+aux;  /* correct top */
 209.623 +            lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize);
 209.624 +            ci->savedpc = L->savedpc;
 209.625 +            ci->tailcalls++;  /* one more call lost */
 209.626 +            L->ci--;  /* remove new frame */
 209.627 +            goto reentry;
 209.628 +          }
 209.629 +          case PCRC: {  /* it was a C function (`precall' called it) */
 209.630 +            base = L->base;
 209.631 +            continue;
 209.632 +          }
 209.633 +          default: {
 209.634 +            return;  /* yield */
 209.635 +          }
 209.636 +        }
 209.637 +      }
 209.638 +      case OP_RETURN: {
 209.639 +        int b = GETARG_B(i);
 209.640 +        if (b != 0) L->top = ra+b-1;
 209.641 +        if (L->openupval) luaF_close(L, base);
 209.642 +        L->savedpc = pc;
 209.643 +        b = luaD_poscall(L, ra);
 209.644 +        if (--nexeccalls == 0)  /* was previous function running `here'? */
 209.645 +          return;  /* no: return */
 209.646 +        else {  /* yes: continue its execution */
 209.647 +          if (b) L->top = L->ci->top;
 209.648 +          lua_assert(isLua(L->ci));
 209.649 +          lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL);
 209.650 +          goto reentry;
 209.651 +        }
 209.652 +      }
 209.653 +      case OP_FORLOOP: {
 209.654 +        lua_Number step = nvalue(ra+2);
 209.655 +        lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */
 209.656 +        lua_Number limit = nvalue(ra+1);
 209.657 +        if (luai_numlt(0, step) ? luai_numle(idx, limit)
 209.658 +                                : luai_numle(limit, idx)) {
 209.659 +          dojump(L, pc, GETARG_sBx(i));  /* jump back */
 209.660 +          setnvalue(ra, idx);  /* update internal index... */
 209.661 +          setnvalue(ra+3, idx);  /* ...and external index */
 209.662 +        }
 209.663 +        continue;
 209.664 +      }
 209.665 +      case OP_FORPREP: {
 209.666 +        const TValue *init = ra;
 209.667 +        const TValue *plimit = ra+1;
 209.668 +        const TValue *pstep = ra+2;
 209.669 +        L->savedpc = pc;  /* next steps may throw errors */
 209.670 +        if (!tonumber(init, ra))
 209.671 +          luaG_runerror(L, LUA_QL("for") " initial value must be a number");
 209.672 +        else if (!tonumber(plimit, ra+1))
 209.673 +          luaG_runerror(L, LUA_QL("for") " limit must be a number");
 209.674 +        else if (!tonumber(pstep, ra+2))
 209.675 +          luaG_runerror(L, LUA_QL("for") " step must be a number");
 209.676 +        setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep)));
 209.677 +        dojump(L, pc, GETARG_sBx(i));
 209.678 +        continue;
 209.679 +      }
 209.680 +      case OP_TFORLOOP: {
 209.681 +        StkId cb = ra + 3;  /* call base */
 209.682 +        setobjs2s(L, cb+2, ra+2);
 209.683 +        setobjs2s(L, cb+1, ra+1);
 209.684 +        setobjs2s(L, cb, ra);
 209.685 +        L->top = cb+3;  /* func. + 2 args (state and index) */
 209.686 +        Protect(luaD_call(L, cb, GETARG_C(i)));
 209.687 +        L->top = L->ci->top;
 209.688 +        cb = RA(i) + 3;  /* previous call may change the stack */
 209.689 +        if (!ttisnil(cb)) {  /* continue loop? */
 209.690 +          setobjs2s(L, cb-1, cb);  /* save control variable */
 209.691 +          dojump(L, pc, GETARG_sBx(*pc));  /* jump back */
 209.692 +        }
 209.693 +        pc++;
 209.694 +        continue;
 209.695 +      }
 209.696 +      case OP_SETLIST: {
 209.697 +        int n = GETARG_B(i);
 209.698 +        int c = GETARG_C(i);
 209.699 +        int last;
 209.700 +        Table *h;
 209.701 +        if (n == 0) {
 209.702 +          n = cast_int(L->top - ra) - 1;
 209.703 +          L->top = L->ci->top;
 209.704 +        }
 209.705 +        if (c == 0) c = cast_int(*pc++);
 209.706 +        runtime_check(L, ttistable(ra));
 209.707 +        h = hvalue(ra);
 209.708 +        last = ((c-1)*LFIELDS_PER_FLUSH) + n;
 209.709 +        if (last > h->sizearray)  /* needs more space? */
 209.710 +          luaH_resizearray(L, h, last);  /* pre-alloc it at once */
 209.711 +        for (; n > 0; n--) {
 209.712 +          TValue *val = ra+n;
 209.713 +          setobj2t(L, luaH_setnum(L, h, last--), val);
 209.714 +          luaC_barriert(L, h, val);
 209.715 +        }
 209.716 +        continue;
 209.717 +      }
 209.718 +      case OP_CLOSE: {
 209.719 +        luaF_close(L, ra);
 209.720 +        continue;
 209.721 +      }
 209.722 +      case OP_CLOSURE: {
 209.723 +        Proto *p;
 209.724 +        Closure *ncl;
 209.725 +        int nup, j;
 209.726 +        p = cl->p->p[GETARG_Bx(i)];
 209.727 +        nup = p->nups;
 209.728 +        ncl = luaF_newLclosure(L, nup, cl->env);
 209.729 +        ncl->l.p = p;
 209.730 +        for (j=0; j<nup; j++, pc++) {
 209.731 +          if (GET_OPCODE(*pc) == OP_GETUPVAL)
 209.732 +            ncl->l.upvals[j] = cl->upvals[GETARG_B(*pc)];
 209.733 +          else {
 209.734 +            lua_assert(GET_OPCODE(*pc) == OP_MOVE);
 209.735 +            ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc));
 209.736 +          }
 209.737 +        }
 209.738 +        setclvalue(L, ra, ncl);
 209.739 +        Protect(luaC_checkGC(L));
 209.740 +        continue;
 209.741 +      }
 209.742 +      case OP_VARARG: {
 209.743 +        int b = GETARG_B(i) - 1;
 209.744 +        int j;
 209.745 +        CallInfo *ci = L->ci;
 209.746 +        int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1;
 209.747 +        if (b == LUA_MULTRET) {
 209.748 +          Protect(luaD_checkstack(L, n));
 209.749 +          ra = RA(i);  /* previous call may change the stack */
 209.750 +          b = n;
 209.751 +          L->top = ra + n;
 209.752 +        }
 209.753 +        for (j = 0; j < b; j++) {
 209.754 +          if (j < n) {
 209.755 +            setobjs2s(L, ra + j, ci->base - n + j);
 209.756 +          }
 209.757 +          else {
 209.758 +            setnilvalue(ra + j);
 209.759 +          }
 209.760 +        }
 209.761 +        continue;
 209.762 +      }
 209.763 +    }
 209.764 +  }
 209.765 +}
 209.766 +
   210.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   210.2 +++ b/src/lua/src/lvm.h	Sat Mar 03 10:31:27 2012 -0600
   210.3 @@ -0,0 +1,36 @@
   210.4 +/*
   210.5 +** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $
   210.6 +** Lua virtual machine
   210.7 +** See Copyright Notice in lua.h
   210.8 +*/
   210.9 +
  210.10 +#ifndef lvm_h
  210.11 +#define lvm_h
  210.12 +
  210.13 +
  210.14 +#include "ldo.h"
  210.15 +#include "lobject.h"
  210.16 +#include "ltm.h"
  210.17 +
  210.18 +
  210.19 +#define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o)))
  210.20 +
  210.21 +#define tonumber(o,n)	(ttype(o) == LUA_TNUMBER || \
  210.22 +                         (((o) = luaV_tonumber(o,n)) != NULL))
  210.23 +
  210.24 +#define equalobj(L,o1,o2) \
  210.25 +	(ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2))
  210.26 +
  210.27 +
  210.28 +LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
  210.29 +LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2);
  210.30 +LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n);
  210.31 +LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj);
  210.32 +LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key,
  210.33 +                                            StkId val);
  210.34 +LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key,
  210.35 +                                            StkId val);
  210.36 +LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls);
  210.37 +LUAI_FUNC void luaV_concat (lua_State *L, int total, int last);
  210.38 +
  210.39 +#endif
   211.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   211.2 +++ b/src/lua/src/lzio.c	Sat Mar 03 10:31:27 2012 -0600
   211.3 @@ -0,0 +1,82 @@
   211.4 +/*
   211.5 +** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $
   211.6 +** a generic input stream interface
   211.7 +** See Copyright Notice in lua.h
   211.8 +*/
   211.9 +
  211.10 +
  211.11 +#include <string.h>
  211.12 +
  211.13 +#define lzio_c
  211.14 +#define LUA_CORE
  211.15 +
  211.16 +#include "lua.h"
  211.17 +
  211.18 +#include "llimits.h"
  211.19 +#include "lmem.h"
  211.20 +#include "lstate.h"
  211.21 +#include "lzio.h"
  211.22 +
  211.23 +
  211.24 +int luaZ_fill (ZIO *z) {
  211.25 +  size_t size;
  211.26 +  lua_State *L = z->L;
  211.27 +  const char *buff;
  211.28 +  lua_unlock(L);
  211.29 +  buff = z->reader(L, z->data, &size);
  211.30 +  lua_lock(L);
  211.31 +  if (buff == NULL || size == 0) return EOZ;
  211.32 +  z->n = size - 1;
  211.33 +  z->p = buff;
  211.34 +  return char2int(*(z->p++));
  211.35 +}
  211.36 +
  211.37 +
  211.38 +int luaZ_lookahead (ZIO *z) {
  211.39 +  if (z->n == 0) {
  211.40 +    if (luaZ_fill(z) == EOZ)
  211.41 +      return EOZ;
  211.42 +    else {
  211.43 +      z->n++;  /* luaZ_fill removed first byte; put back it */
  211.44 +      z->p--;
  211.45 +    }
  211.46 +  }
  211.47 +  return char2int(*z->p);
  211.48 +}
  211.49 +
  211.50 +
  211.51 +void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
  211.52 +  z->L = L;
  211.53 +  z->reader = reader;
  211.54 +  z->data = data;
  211.55 +  z->n = 0;
  211.56 +  z->p = NULL;
  211.57 +}
  211.58 +
  211.59 +
  211.60 +/* --------------------------------------------------------------- read --- */
  211.61 +size_t luaZ_read (ZIO *z, void *b, size_t n) {
  211.62 +  while (n) {
  211.63 +    size_t m;
  211.64 +    if (luaZ_lookahead(z) == EOZ)
  211.65 +      return n;  /* return number of missing bytes */
  211.66 +    m = (n <= z->n) ? n : z->n;  /* min. between n and z->n */
  211.67 +    memcpy(b, z->p, m);
  211.68 +    z->n -= m;
  211.69 +    z->p += m;
  211.70 +    b = (char *)b + m;
  211.71 +    n -= m;
  211.72 +  }
  211.73 +  return 0;
  211.74 +}
  211.75 +
  211.76 +/* ------------------------------------------------------------------------ */
  211.77 +char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) {
  211.78 +  if (n > buff->buffsize) {
  211.79 +    if (n < LUA_MINBUFFER) n = LUA_MINBUFFER;
  211.80 +    luaZ_resizebuffer(L, buff, n);
  211.81 +  }
  211.82 +  return buff->buffer;
  211.83 +}
  211.84 +
  211.85 +
   212.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   212.2 +++ b/src/lua/src/lzio.h	Sat Mar 03 10:31:27 2012 -0600
   212.3 @@ -0,0 +1,67 @@
   212.4 +/*
   212.5 +** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $
   212.6 +** Buffered streams
   212.7 +** See Copyright Notice in lua.h
   212.8 +*/
   212.9 +
  212.10 +
  212.11 +#ifndef lzio_h
  212.12 +#define lzio_h
  212.13 +
  212.14 +#include "lua.h"
  212.15 +
  212.16 +#include "lmem.h"
  212.17 +
  212.18 +
  212.19 +#define EOZ	(-1)			/* end of stream */
  212.20 +
  212.21 +typedef struct Zio ZIO;
  212.22 +
  212.23 +#define char2int(c)	cast(int, cast(unsigned char, (c)))
  212.24 +
  212.25 +#define zgetc(z)  (((z)->n--)>0 ?  char2int(*(z)->p++) : luaZ_fill(z))
  212.26 +
  212.27 +typedef struct Mbuffer {
  212.28 +  char *buffer;
  212.29 +  size_t n;
  212.30 +  size_t buffsize;
  212.31 +} Mbuffer;
  212.32 +
  212.33 +#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
  212.34 +
  212.35 +#define luaZ_buffer(buff)	((buff)->buffer)
  212.36 +#define luaZ_sizebuffer(buff)	((buff)->buffsize)
  212.37 +#define luaZ_bufflen(buff)	((buff)->n)
  212.38 +
  212.39 +#define luaZ_resetbuffer(buff) ((buff)->n = 0)
  212.40 +
  212.41 +
  212.42 +#define luaZ_resizebuffer(L, buff, size) \
  212.43 +	(luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
  212.44 +	(buff)->buffsize = size)
  212.45 +
  212.46 +#define luaZ_freebuffer(L, buff)	luaZ_resizebuffer(L, buff, 0)
  212.47 +
  212.48 +
  212.49 +LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
  212.50 +LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
  212.51 +                                        void *data);
  212.52 +LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n);	/* read next n bytes */
  212.53 +LUAI_FUNC int luaZ_lookahead (ZIO *z);
  212.54 +
  212.55 +
  212.56 +
  212.57 +/* --------- Private Part ------------------ */
  212.58 +
  212.59 +struct Zio {
  212.60 +  size_t n;			/* bytes still unread */
  212.61 +  const char *p;		/* current position in buffer */
  212.62 +  lua_Reader reader;
  212.63 +  void* data;			/* additional data */
  212.64 +  lua_State *L;			/* Lua state (for reader) */
  212.65 +};
  212.66 +
  212.67 +
  212.68 +LUAI_FUNC int luaZ_fill (ZIO *z);
  212.69 +
  212.70 +#endif
   213.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   213.2 +++ b/src/lua/src/print.c	Sat Mar 03 10:31:27 2012 -0600
   213.3 @@ -0,0 +1,227 @@
   213.4 +/*
   213.5 +** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $
   213.6 +** print bytecodes
   213.7 +** See Copyright Notice in lua.h
   213.8 +*/
   213.9 +
  213.10 +#include <ctype.h>
  213.11 +#include <stdio.h>
  213.12 +
  213.13 +#define luac_c
  213.14 +#define LUA_CORE
  213.15 +
  213.16 +#include "ldebug.h"
  213.17 +#include "lobject.h"
  213.18 +#include "lopcodes.h"
  213.19 +#include "lundump.h"
  213.20 +
  213.21 +#define PrintFunction	luaU_print
  213.22 +
  213.23 +#define Sizeof(x)	((int)sizeof(x))
  213.24 +#define VOID(p)		((const void*)(p))
  213.25 +
  213.26 +static void PrintString(const TString* ts)
  213.27 +{
  213.28 + const char* s=getstr(ts);
  213.29 + size_t i,n=ts->tsv.len;
  213.30 + putchar('"');
  213.31 + for (i=0; i<n; i++)
  213.32 + {
  213.33 +  int c=s[i];
  213.34 +  switch (c)
  213.35 +  {
  213.36 +   case '"': printf("\\\""); break;
  213.37 +   case '\\': printf("\\\\"); break;
  213.38 +   case '\a': printf("\\a"); break;
  213.39 +   case '\b': printf("\\b"); break;
  213.40 +   case '\f': printf("\\f"); break;
  213.41 +   case '\n': printf("\\n"); break;
  213.42 +   case '\r': printf("\\r"); break;
  213.43 +   case '\t': printf("\\t"); break;
  213.44 +   case '\v': printf("\\v"); break;
  213.45 +   default:	if (isprint((unsigned char)c))
  213.46 +   			putchar(c);
  213.47 +		else
  213.48 +			printf("\\%03u",(unsigned char)c);
  213.49 +  }
  213.50 + }
  213.51 + putchar('"');
  213.52 +}
  213.53 +
  213.54 +static void PrintConstant(const Proto* f, int i)
  213.55 +{
  213.56 + const TValue* o=&f->k[i];
  213.57 + switch (ttype(o))
  213.58 + {
  213.59 +  case LUA_TNIL:
  213.60 +	printf("nil");
  213.61 +	break;
  213.62 +  case LUA_TBOOLEAN:
  213.63 +	printf(bvalue(o) ? "true" : "false");
  213.64 +	break;
  213.65 +  case LUA_TNUMBER:
  213.66 +	printf(LUA_NUMBER_FMT,nvalue(o));
  213.67 +	break;
  213.68 +  case LUA_TSTRING:
  213.69 +	PrintString(rawtsvalue(o));
  213.70 +	break;
  213.71 +  default:				/* cannot happen */
  213.72 +	printf("? type=%d",ttype(o));
  213.73 +	break;
  213.74 + }
  213.75 +}
  213.76 +
  213.77 +static void PrintCode(const Proto* f)
  213.78 +{
  213.79 + const Instruction* code=f->code;
  213.80 + int pc,n=f->sizecode;
  213.81 + for (pc=0; pc<n; pc++)
  213.82 + {
  213.83 +  Instruction i=code[pc];
  213.84 +  OpCode o=GET_OPCODE(i);
  213.85 +  int a=GETARG_A(i);
  213.86 +  int b=GETARG_B(i);
  213.87 +  int c=GETARG_C(i);
  213.88 +  int bx=GETARG_Bx(i);
  213.89 +  int sbx=GETARG_sBx(i);
  213.90 +  int line=getline(f,pc);
  213.91 +  printf("\t%d\t",pc+1);
  213.92 +  if (line>0) printf("[%d]\t",line); else printf("[-]\t");
  213.93 +  printf("%-9s\t",luaP_opnames[o]);
  213.94 +  switch (getOpMode(o))
  213.95 +  {
  213.96 +   case iABC:
  213.97 +    printf("%d",a);
  213.98 +    if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b);
  213.99 +    if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c);
 213.100 +    break;
 213.101 +   case iABx:
 213.102 +    if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx);
 213.103 +    break;
 213.104 +   case iAsBx:
 213.105 +    if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx);
 213.106 +    break;
 213.107 +  }
 213.108 +  switch (o)
 213.109 +  {
 213.110 +   case OP_LOADK:
 213.111 +    printf("\t; "); PrintConstant(f,bx);
 213.112 +    break;
 213.113 +   case OP_GETUPVAL:
 213.114 +   case OP_SETUPVAL:
 213.115 +    printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-");
 213.116 +    break;
 213.117 +   case OP_GETGLOBAL:
 213.118 +   case OP_SETGLOBAL:
 213.119 +    printf("\t; %s",svalue(&f->k[bx]));
 213.120 +    break;
 213.121 +   case OP_GETTABLE:
 213.122 +   case OP_SELF:
 213.123 +    if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
 213.124 +    break;
 213.125 +   case OP_SETTABLE:
 213.126 +   case OP_ADD:
 213.127 +   case OP_SUB:
 213.128 +   case OP_MUL:
 213.129 +   case OP_DIV:
 213.130 +   case OP_POW:
 213.131 +   case OP_EQ:
 213.132 +   case OP_LT:
 213.133 +   case OP_LE:
 213.134 +    if (ISK(b) || ISK(c))
 213.135 +    {
 213.136 +     printf("\t; ");
 213.137 +     if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
 213.138 +     printf(" ");
 213.139 +     if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
 213.140 +    }
 213.141 +    break;
 213.142 +   case OP_JMP:
 213.143 +   case OP_FORLOOP:
 213.144 +   case OP_FORPREP:
 213.145 +    printf("\t; to %d",sbx+pc+2);
 213.146 +    break;
 213.147 +   case OP_CLOSURE:
 213.148 +    printf("\t; %p",VOID(f->p[bx]));
 213.149 +    break;
 213.150 +   case OP_SETLIST:
 213.151 +    if (c==0) printf("\t; %d",(int)code[++pc]);
 213.152 +    else printf("\t; %d",c);
 213.153 +    break;
 213.154 +   default:
 213.155 +    break;
 213.156 +  }
 213.157 +  printf("\n");
 213.158 + }
 213.159 +}
 213.160 +
 213.161 +#define SS(x)	(x==1)?"":"s"
 213.162 +#define S(x)	x,SS(x)
 213.163 +
 213.164 +static void PrintHeader(const Proto* f)
 213.165 +{
 213.166 + const char* s=getstr(f->source);
 213.167 + if (*s=='@' || *s=='=')
 213.168 +  s++;
 213.169 + else if (*s==LUA_SIGNATURE[0])
 213.170 +  s="(bstring)";
 213.171 + else
 213.172 +  s="(string)";
 213.173 + printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n",
 213.174 + 	(f->linedefined==0)?"main":"function",s,
 213.175 +	f->linedefined,f->lastlinedefined,
 213.176 +	S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f));
 213.177 + printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
 213.178 +	f->numparams,f->is_vararg?"+":"",SS(f->numparams),
 213.179 +	S(f->maxstacksize),S(f->nups));
 213.180 + printf("%d local%s, %d constant%s, %d function%s\n",
 213.181 +	S(f->sizelocvars),S(f->sizek),S(f->sizep));
 213.182 +}
 213.183 +
 213.184 +static void PrintConstants(const Proto* f)
 213.185 +{
 213.186 + int i,n=f->sizek;
 213.187 + printf("constants (%d) for %p:\n",n,VOID(f));
 213.188 + for (i=0; i<n; i++)
 213.189 + {
 213.190 +  printf("\t%d\t",i+1);
 213.191 +  PrintConstant(f,i);
 213.192 +  printf("\n");
 213.193 + }
 213.194 +}
 213.195 +
 213.196 +static void PrintLocals(const Proto* f)
 213.197 +{
 213.198 + int i,n=f->sizelocvars;
 213.199 + printf("locals (%d) for %p:\n",n,VOID(f));
 213.200 + for (i=0; i<n; i++)
 213.201 + {
 213.202 +  printf("\t%d\t%s\t%d\t%d\n",
 213.203 +  i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);
 213.204 + }
 213.205 +}
 213.206 +
 213.207 +static void PrintUpvalues(const Proto* f)
 213.208 +{
 213.209 + int i,n=f->sizeupvalues;
 213.210 + printf("upvalues (%d) for %p:\n",n,VOID(f));
 213.211 + if (f->upvalues==NULL) return;
 213.212 + for (i=0; i<n; i++)
 213.213 + {
 213.214 +  printf("\t%d\t%s\n",i,getstr(f->upvalues[i]));
 213.215 + }
 213.216 +}
 213.217 +
 213.218 +void PrintFunction(const Proto* f, int full)
 213.219 +{
 213.220 + int i,n=f->sizep;
 213.221 + PrintHeader(f);
 213.222 + PrintCode(f);
 213.223 + if (full)
 213.224 + {
 213.225 +  PrintConstants(f);
 213.226 +  PrintLocals(f);
 213.227 +  PrintUpvalues(f);
 213.228 + }
 213.229 + for (i=0; i<n; i++) PrintFunction(f->p[i],full);
 213.230 +}
   214.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   214.2 +++ b/src/prof/Makefile.am	Sat Mar 03 10:31:27 2012 -0600
   214.3 @@ -0,0 +1,7 @@
   214.4 +noinst_LIBRARIES = libprof.a
   214.5 +
   214.6 +libprof_a_SOURCES = \
   214.7 +	gmon.h		\
   214.8 +	gmon_out.h	\
   214.9 +	prof.cpp	\
  214.10 +	prof.h
   215.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   215.2 +++ b/src/prof/gmon.h	Sat Mar 03 10:31:27 2012 -0600
   215.3 @@ -0,0 +1,151 @@
   215.4 +/*
   215.5 + * Copyright (c) 1983, 1991, 1993, 2001
   215.6 + *      The Regents of the University of California.  All rights reserved.
   215.7 + *
   215.8 + * Redistribution and use in source and binary forms, with or without
   215.9 + * modification, are permitted provided that the following conditions
  215.10 + * are met:
  215.11 + * 1. Redistributions of source code must retain the above copyright
  215.12 + *    notice, this list of conditions and the following disclaimer.
  215.13 + * 2. Redistributions in binary form must reproduce the above copyright
  215.14 + *    notice, this list of conditions and the following disclaimer in the
  215.15 + *    documentation and/or other materials provided with the distribution.
  215.16 + * 3. Neither the name of the University nor the names of its contributors
  215.17 + *    may be used to endorse or promote products derived from this software
  215.18 + *    without specific prior written permission.
  215.19 + *
  215.20 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  215.21 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  215.22 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  215.23 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  215.24 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  215.25 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  215.26 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  215.27 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  215.28 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  215.29 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  215.30 + * SUCH DAMAGE.
  215.31 + */
  215.32 +#ifndef gmon_h
  215.33 +#define gmon_h
  215.34 +
  215.35 +#include <stdint.h>
  215.36 +typedef uint32_t u32;
  215.37 +
  215.38 +/* Size of the 4.4BSD gmon header */
  215.39 +#define GMON_HDRSIZE_BSD44_32 (4 + 4 + 4 + 4 + 4 + (3 * 4))
  215.40 +#define GMON_HDRSIZE_BSD44_64 (8 + 8 + 4 + 4 + 4 + (3 * 4))
  215.41 +
  215.42 +#if 0 /* For documentation purposes only.  */
  215.43 +  struct raw_phdr
  215.44 +    {
  215.45 +      char low_pc[sizeof(void *)]; /* base pc address of sample buffer */
  215.46 +      char high_pc[sizeof(void *)];/* max pc address of sampled buffer */
  215.47 +      char ncnt[4];		   /* size of sample buffer (plus this
  215.48 +				      header) */
  215.49 +
  215.50 +      char version[4];		   /* version number */
  215.51 +      char profrate[4];		   /* profiling clock rate */
  215.52 +      char spare[3*4];		   /* reserved */
  215.53 +    };
  215.54 +#endif
  215.55 +
  215.56 +#define GMONVERSION     0x00051879
  215.57 +
  215.58 +/* Size of the old BSD gmon header */
  215.59 +#define GMON_HDRSIZE_OLDBSD_32 (4 + 4 + 4) 
  215.60 +
  215.61 +/* FIXME: Checking host compiler defines here means that we can't
  215.62 +   use a cross gprof alpha OSF.  */
  215.63 +#if defined(__alpha__) && defined (__osf__) 
  215.64 +#define GMON_HDRSIZE_OLDBSD_64 (8 + 8 + 4 + 4)
  215.65 +#else
  215.66 +#define GMON_HDRSIZE_OLDBSD_64 (8 + 8 + 4)
  215.67 +#endif
  215.68 +
  215.69 +#if 0 /* For documentation purposes only.  */
  215.70 +  struct old_raw_phdr
  215.71 +    {
  215.72 +      char low_pc[sizeof(void *)]; /* base pc address of sample buffer */
  215.73 +      char high_pc[sizeof(void *)];/* max pc address of sampled buffer */
  215.74 +      char ncnt[4];		   /* size of sample buffer (plus this
  215.75 +				      header) */
  215.76 +#if defined (__alpha__) && defined (__osf__)
  215.77 +      /*
  215.78 +       * DEC's OSF v3.0 uses 4 bytes of padding to bring the header to
  215.79 +       * a size that is a multiple of 8.
  215.80 +       */
  215.81 +      char pad[4];
  215.82 +#endif
  215.83 +    };
  215.84 +#endif
  215.85 +
  215.86 +/*
  215.87 + * Histogram counters are unsigned shorts:
  215.88 + */
  215.89 +#define	HISTCOUNTER unsigned short
  215.90 +
  215.91 +/*
  215.92 + * Fraction of text space to allocate for histogram counters here, 1/2:
  215.93 + */
  215.94 +#define	HISTFRACTION	2
  215.95 +
  215.96 +/*
  215.97 + * Fraction of text space to allocate for from hash buckets.  The
  215.98 + * value of HASHFRACTION is based on the minimum number of bytes of
  215.99 + * separation between two subroutine call points in the object code.
 215.100 + * Given MIN_SUBR_SEPARATION bytes of separation the value of
 215.101 + * HASHFRACTION is calculated as:
 215.102 + *
 215.103 + *      HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1);
 215.104 + *
 215.105 + * For the VAX, the shortest two call sequence is:
 215.106 + *
 215.107 + *      calls   $0,(r0)
 215.108 + *      calls   $0,(r0)
 215.109 + *
 215.110 + * which is separated by only three bytes, thus HASHFRACTION is
 215.111 + * calculated as:
 215.112 + *
 215.113 + *      HASHFRACTION = 3 / (2 * 2 - 1) = 1
 215.114 + *
 215.115 + * Note that the division above rounds down, thus if MIN_SUBR_FRACTION
 215.116 + * is less than three, this algorithm will not work!
 215.117 + */
 215.118 +#define	HASHFRACTION 1
 215.119 +
 215.120 +/*
 215.121 + * Percent of text space to allocate for tostructs with a minimum:
 215.122 + */
 215.123 +#define ARCDENSITY	2
 215.124 +#define MINARCS		50
 215.125 +
 215.126 +struct tostruct
 215.127 +  {
 215.128 +    u32 selfpc;
 215.129 +    int count;
 215.130 +    unsigned short link;
 215.131 +  };
 215.132 +
 215.133 +/*
 215.134 + * A raw arc, with pointers to the calling site and the called site
 215.135 + * and a count.  Everything is defined in terms of characters so
 215.136 + * as to get a packed representation (otherwise, different compilers
 215.137 + * might introduce different padding):
 215.138 + */
 215.139 +#if 0 /* For documentation purposes only.  */
 215.140 +  struct raw_arc
 215.141 +    {
 215.142 +      char from_pc[sizeof(void *)];
 215.143 +      char self_pc[sizeof(void *)];
 215.144 +      char count[sizeof(long)];
 215.145 +    };
 215.146 +#endif
 215.147 +
 215.148 +/*
 215.149 + * General rounding functions:
 215.150 + */
 215.151 +#define ROUNDDOWN(x,y)	(((x)/(y))*(y))
 215.152 +#define ROUNDUP(x,y)	((((x)+(y)-1)/(y))*(y))
 215.153 +
 215.154 +#endif /* gmon_h */
   216.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   216.2 +++ b/src/prof/gmon_out.h	Sat Mar 03 10:31:27 2012 -0600
   216.3 @@ -0,0 +1,45 @@
   216.4 +/* gmon_out.h
   216.5 +
   216.6 +   Copyright 2000, 2001 Free Software Foundation, Inc.
   216.7 +
   216.8 +This file is part of GNU Binutils.
   216.9 +
  216.10 +This program is free software; you can redistribute it and/or modify
  216.11 +it under the terms of the GNU General Public License as published by
  216.12 +the Free Software Foundation; either version 2 of the License, or
  216.13 +(at your option) any later version.
  216.14 +
  216.15 +This program is distributed in the hope that it will be useful,
  216.16 +but WITHOUT ANY WARRANTY; without even the implied warranty of
  216.17 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  216.18 +GNU General Public License for more details.
  216.19 +
  216.20 +You should have received a copy of the GNU General Public License
  216.21 +along with this program; if not, write to the Free Software
  216.22 +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  216.23 +
  216.24 +/* A gmon.out file consists of a header (defined by gmon_hdr) followed
  216.25 +   by a sequence of records.  Each record starts with a one-byte tag
  216.26 +   identifying the type of records, followed by records specific data.  */
  216.27 +#ifndef gmon_out_h
  216.28 +#define gmon_out_h
  216.29 +
  216.30 +#define	GMON_MAGIC	"gmon"	/* magic cookie */
  216.31 +#define GMON_VERSION	1	/* version number */
  216.32 +
  216.33 +/* Raw header as it appears on file (without padding).  */
  216.34 +struct gmon_hdr
  216.35 +  {
  216.36 +    char cookie[4];
  216.37 +    char version[4];
  216.38 +    char spare[3 * 4];
  216.39 +  };
  216.40 +
  216.41 +/* Types of records in this file.  */
  216.42 +typedef enum
  216.43 +  {
  216.44 +    GMON_TAG_TIME_HIST = 0, GMON_TAG_CG_ARC = 1, GMON_TAG_BB_COUNT = 2
  216.45 +  }
  216.46 +GMON_Record_Tag;
  216.47 +
  216.48 +#endif /* gmon_out_h */
   217.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   217.2 +++ b/src/prof/prof.cpp	Sat Mar 03 10:31:27 2012 -0600
   217.3 @@ -0,0 +1,405 @@
   217.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   217.5 +// Copyright (C) 1999-2003 Forgotten
   217.6 +// Copyright (C) 2004 Forgotten and the VBA development team
   217.7 +
   217.8 +// This program is free software; you can redistribute it and/or modify
   217.9 +// it under the terms of the GNU General Public License as published by
  217.10 +// the Free Software Foundation; either version 2, or(at your option)
  217.11 +// any later version.
  217.12 +//
  217.13 +// This program is distributed in the hope that it will be useful,
  217.14 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  217.15 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  217.16 +// GNU General Public License for more details.
  217.17 +//
  217.18 +// You should have received a copy of the GNU General Public License
  217.19 +// along with this program; if not, write to the Free Software Foundation,
  217.20 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  217.21 +
  217.22 +// adapted from gmon.c
  217.23 +/*-
  217.24 + * Copyright (c) 1991, 1998 The Regents of the University of California.
  217.25 + * All rights reserved.
  217.26 + *
  217.27 + * Redistribution and use in source and binary forms, with or without
  217.28 + * modification, are permitted provided that the following conditions
  217.29 + * are met:
  217.30 + * 1. Redistributions of source code must retain the above copyright
  217.31 + *    notice, this list of conditions and the following disclaimer.
  217.32 + * 2. Redistributions in binary form must reproduce the above copyright
  217.33 + *    notice, this list of conditions and the following disclaimer in the
  217.34 + *    documentation and/or other materials provided with the distribution.
  217.35 + * 3. [rescinded 22 July 1999]
  217.36 + * 4. Neither the name of the University nor the names of its contributors
  217.37 + *    may be used to endorse or promote products derived from this software
  217.38 + *    without specific prior written permission.
  217.39 + *
  217.40 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  217.41 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  217.42 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  217.43 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  217.44 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  217.45 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  217.46 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  217.47 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  217.48 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  217.49 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  217.50 + * SUCH DAMAGE.
  217.51 + */
  217.52 +
  217.53 +#include <stdlib.h>
  217.54 +#include <stdio.h>
  217.55 +#include <memory.h>
  217.56 +
  217.57 +#include "gmon.h"
  217.58 +#include "gmon_out.h"
  217.59 +
  217.60 +#include "../common/System.h"
  217.61 +#include "../gba/GBA.h"
  217.62 +#include "../gba/GBAGlobals.h"
  217.63 +#include "../NLS.h"
  217.64 +
  217.65 +/*
  217.66 + * froms is actually a bunch of unsigned shorts indexing tos
  217.67 + */
  217.68 +static int  profiling = 3;
  217.69 +static unsigned short *froms;
  217.70 +static struct tostruct *tos = 0;
  217.71 +static long  tolimit = 0;
  217.72 +static u32  s_lowpc = 0;
  217.73 +static u32  s_highpc = 0;
  217.74 +static unsigned long s_textsize = 0;
  217.75 +
  217.76 +static int ssiz;
  217.77 +static char *sbuf;
  217.78 +static int s_scale;
  217.79 +
  217.80 +static int hz = 0;
  217.81 +static int hist_num_bins = 0;
  217.82 +static char hist_dimension[16] = "seconds";
  217.83 +static char hist_dimension_abbrev = 's';
  217.84 +
  217.85 +/* see profil(2) where this is describe (incorrectly) */
  217.86 +#define  SCALE_1_TO_1 0x10000L
  217.87 +
  217.88 +void profPut32(char *b, u32 v)
  217.89 +{
  217.90 +  b[0] = v & 255;
  217.91 +  b[1] = (v >> 8) & 255;
  217.92 +  b[2] = (v >> 16) & 255;
  217.93 +  b[3] = (v >> 24) & 255;
  217.94 +}
  217.95 +
  217.96 +void profPut16(char *b, u16 v)
  217.97 +{
  217.98 +  b[0] = v & 255;
  217.99 +  b[1] = (v >> 8) & 255;
 217.100 +}
 217.101 +
 217.102 +int profWrite8(FILE *f, u8 b)
 217.103 +{
 217.104 +  if(fwrite(&b, 1, 1, f) != 1)
 217.105 +    return 1;
 217.106 +  return 0;
 217.107 +}
 217.108 +
 217.109 +int profWrite32(FILE *f, u32 v)
 217.110 +{
 217.111 +  char buf[4];
 217.112 +
 217.113 +  profPut32(buf, v);
 217.114 +  if(fwrite(buf, 1, 4, f) != 4)
 217.115 +    return 1;
 217.116 +  return 0;
 217.117 +}
 217.118 +
 217.119 +int profWrite(FILE *f, char *buf, unsigned int n)
 217.120 +{
 217.121 +  if(fwrite(buf, 1, n, f) != n)
 217.122 +    return 1;
 217.123 +  return 0;
 217.124 +}
 217.125 +
 217.126 +/* Control profiling;
 217.127 +   profiling is what mcount checks to see if
 217.128 +   all the data structures are ready.  */
 217.129 +
 217.130 +void profControl(int mode)
 217.131 +{
 217.132 +  if (mode) {
 217.133 +    /* start */
 217.134 +#ifdef PROFILING
 217.135 +    cpuProfil(sbuf, ssiz, (u32)s_lowpc, s_scale);
 217.136 +#endif
 217.137 +    profiling = 0;
 217.138 +  } else {
 217.139 +    /* stop */
 217.140 +#ifdef PROFILING
 217.141 +    cpuProfil(NULL, 0, 0, 0);
 217.142 +#endif
 217.143 +    profiling = 3;
 217.144 +  }
 217.145 +}
 217.146 +
 217.147 +
 217.148 +#define MSG N_("No space for profiling buffer(s)\n")
 217.149 +
 217.150 +void profStartup(u32 lowpc, u32 highpc)
 217.151 +{
 217.152 +  int monsize;
 217.153 +  char *buffer;
 217.154 +  int o;
 217.155 +  
 217.156 +  /*
 217.157 +   * round lowpc and highpc to multiples of the density we're using
 217.158 +   * so the rest of the scaling (here and in gprof) stays in ints.
 217.159 +   */
 217.160 +  lowpc = ROUNDDOWN(lowpc, HISTFRACTION*sizeof(HISTCOUNTER));
 217.161 +  s_lowpc = lowpc;
 217.162 +  highpc = ROUNDUP(highpc, HISTFRACTION*sizeof(HISTCOUNTER));
 217.163 +  s_highpc = highpc;
 217.164 +  s_textsize = highpc - lowpc;
 217.165 +  monsize = (s_textsize / HISTFRACTION);
 217.166 +  buffer = (char *)calloc(1, 2*monsize );
 217.167 +  if ( buffer == NULL ) {
 217.168 +    systemMessage(0, MSG);
 217.169 +    return;
 217.170 +  }
 217.171 +  froms = (unsigned short *) calloc(1, 4*s_textsize / HASHFRACTION );
 217.172 +  if ( froms == NULL ) {
 217.173 +    systemMessage(0, MSG);
 217.174 +    free(buffer);
 217.175 +    buffer = NULL;
 217.176 +    return;
 217.177 +  }
 217.178 +  tolimit = s_textsize * ARCDENSITY / 100;
 217.179 +  if ( tolimit < MINARCS ) {
 217.180 +    tolimit = MINARCS;
 217.181 +  } else if ( tolimit > 65534 ) {
 217.182 +    tolimit = 65534;
 217.183 +  }
 217.184 +  tos = (struct tostruct *) calloc(1, tolimit * sizeof( struct tostruct ) );
 217.185 +  if ( tos == NULL ) {
 217.186 +    systemMessage(0, MSG);
 217.187 +    
 217.188 +    free(buffer);
 217.189 +    buffer = NULL;
 217.190 +    
 217.191 +    free(froms);
 217.192 +    froms = NULL;
 217.193 +    
 217.194 +    return;
 217.195 +  }
 217.196 +  tos[0].link = 0;
 217.197 +  sbuf = buffer;
 217.198 +  ssiz = monsize;
 217.199 +  if ( monsize <= 0 )
 217.200 +    return;
 217.201 +  o = highpc - lowpc;
 217.202 +  if( monsize < o )
 217.203 +    s_scale = (int)(( (float) monsize / o ) * SCALE_1_TO_1);
 217.204 +  else
 217.205 +    s_scale = SCALE_1_TO_1;
 217.206 +  profControl(1);
 217.207 +}
 217.208 +
 217.209 +void profCleanup()
 217.210 +{
 217.211 +  FILE *fd;
 217.212 +  int fromindex;
 217.213 +  int endfrom;
 217.214 +  u32 frompc;
 217.215 +  int toindex;
 217.216 +  struct gmon_hdr ghdr;
 217.217 +  
 217.218 +  profControl(0);
 217.219 +  fd = fopen( "gmon.out" , "wb" );
 217.220 +  if ( fd == NULL ) {
 217.221 +    systemMessage( 0, "mcount: gmon.out" );
 217.222 +    return;
 217.223 +  }
 217.224 +
 217.225 +  memcpy(&ghdr.cookie[0], GMON_MAGIC, 4);
 217.226 +  profPut32((char *)ghdr.version, GMON_VERSION);
 217.227 +
 217.228 +  if(fwrite(&ghdr, sizeof(ghdr), 1, fd) != 1) {
 217.229 +    systemMessage(0, "mcount: gmon.out header");
 217.230 +    fclose(fd);
 217.231 +    return;
 217.232 +  }
 217.233 +
 217.234 +  if(hz == 0)
 217.235 +    hz = 100;
 217.236 +
 217.237 +  hist_num_bins = ssiz;
 217.238 +  
 217.239 +  if(profWrite8(fd, GMON_TAG_TIME_HIST) ||
 217.240 +     profWrite32(fd, (u32)s_lowpc) ||
 217.241 +     profWrite32(fd, (u32)s_highpc) ||
 217.242 +     profWrite32(fd, hist_num_bins) ||
 217.243 +     profWrite32(fd, hz) ||
 217.244 +     profWrite(fd, hist_dimension, 15) ||
 217.245 +     profWrite(fd, &hist_dimension_abbrev, 1)) {
 217.246 +    systemMessage(0, "mcount: gmon.out hist");
 217.247 +    fclose(fd);
 217.248 +    return;
 217.249 +  }
 217.250 +  u16 *hist_sample = (u16 *)sbuf;
 217.251 +
 217.252 +  u16 count;
 217.253 +  int i;
 217.254 +  
 217.255 +  for(i = 0; i < hist_num_bins; ++i) {
 217.256 +    profPut16((char *)&count, hist_sample[i]);
 217.257 +
 217.258 +    if(fwrite(&count, sizeof(count), 1, fd) != 1) {
 217.259 +      systemMessage(0, "mcount: gmon.out sample");
 217.260 +      fclose(fd);
 217.261 +      return;
 217.262 +    }
 217.263 +  }
 217.264 +  
 217.265 +  endfrom = s_textsize / (HASHFRACTION * sizeof(*froms));
 217.266 +  for ( fromindex = 0 ; fromindex < endfrom ; fromindex++ ) {
 217.267 +    if ( froms[fromindex] == 0 ) {
 217.268 +      continue;
 217.269 +    }
 217.270 +    frompc = s_lowpc + (fromindex * HASHFRACTION * sizeof(*froms));
 217.271 +    for (toindex=froms[fromindex]; toindex!=0; toindex=tos[toindex].link) {
 217.272 +      if(profWrite8(fd, GMON_TAG_CG_ARC) ||
 217.273 +         profWrite32(fd, (u32)frompc) ||
 217.274 +         profWrite32(fd, (u32)tos[toindex].selfpc) ||
 217.275 +         profWrite32(fd, tos[toindex].count)) {
 217.276 +        systemMessage(0, "mcount: arc");
 217.277 +        fclose(fd);
 217.278 +        return;
 217.279 +      }
 217.280 +    }
 217.281 +  }
 217.282 +  fclose(fd);
 217.283 +}
 217.284 +
 217.285 +void profCount()
 217.286 +{
 217.287 +  register u32 selfpc;
 217.288 +  register unsigned short *frompcindex;
 217.289 +  register struct tostruct *top;
 217.290 +  register struct tostruct *prevtop;
 217.291 +  register long toindex;
 217.292 +
 217.293 +  /*
 217.294 +   * find the return address for mcount,
 217.295 +   * and the return address for mcount's caller.
 217.296 +   */
 217.297 +  
 217.298 +  /* selfpc = pc pushed by mcount call.
 217.299 +     This identifies the function that was just entered.  */
 217.300 +  selfpc = (u32) reg[14].I;
 217.301 +  /* frompcindex = pc in preceding frame.
 217.302 +     This identifies the caller of the function just entered.  */
 217.303 +  frompcindex = (unsigned short *) reg[12].I;
 217.304 +  /*
 217.305 +   * check that we are profiling
 217.306 +   * and that we aren't recursively invoked.
 217.307 +   */
 217.308 +  if (profiling) {
 217.309 +    goto out;
 217.310 +  }
 217.311 +  profiling++;
 217.312 +  /*
 217.313 +   * check that frompcindex is a reasonable pc value.
 217.314 +   * for example: signal catchers get called from the stack,
 217.315 +   *   not from text space.  too bad.
 217.316 +   */
 217.317 +  frompcindex = (unsigned short *) ((long) frompcindex - (long) s_lowpc);
 217.318 +  if ((unsigned long) frompcindex > s_textsize) {
 217.319 +    goto done;
 217.320 +  }
 217.321 +  frompcindex =
 217.322 +    &froms[((long) frompcindex) / (HASHFRACTION * sizeof(*froms))];
 217.323 +  toindex = *frompcindex;
 217.324 +  if (toindex == 0) {
 217.325 +    /*
 217.326 +     * first time traversing this arc
 217.327 +     */
 217.328 +    toindex = ++tos[0].link;
 217.329 +    if (toindex >= tolimit) {
 217.330 +      goto overflow;
 217.331 +    }
 217.332 +    *frompcindex = (unsigned short)toindex;
 217.333 +    top = &tos[toindex];
 217.334 +    top->selfpc = selfpc;
 217.335 +    top->count = 1;
 217.336 +    top->link = 0;
 217.337 +    goto done;
 217.338 +  }
 217.339 +  top = &tos[toindex];
 217.340 +  if (top->selfpc == selfpc) {
 217.341 +    /*
 217.342 +     * arc at front of chain; usual case.
 217.343 +     */
 217.344 +    top->count++;
 217.345 +    goto done;
 217.346 +  }
 217.347 +  /*
 217.348 +   * have to go looking down chain for it.
 217.349 +   * top points to what we are looking at,
 217.350 +   * prevtop points to previous top.
 217.351 +   * we know it is not at the head of the chain.
 217.352 +   */
 217.353 +  for (; /* goto done */; ) {
 217.354 +    if (top->link == 0) {
 217.355 +      /*
 217.356 +       * top is end of the chain and none of the chain
 217.357 +       * had top->selfpc == selfpc.
 217.358 +       * so we allocate a new tostruct
 217.359 +       * and link it to the head of the chain.
 217.360 +       */
 217.361 +      toindex = ++tos[0].link;
 217.362 +      if (toindex >= tolimit) {
 217.363 +        goto overflow;
 217.364 +      }
 217.365 +      top = &tos[toindex];
 217.366 +      top->selfpc = selfpc;
 217.367 +      top->count = 1;
 217.368 +      top->link = *frompcindex;
 217.369 +      *frompcindex = (unsigned short)toindex;
 217.370 +      goto done;
 217.371 +    }
 217.372 +    /*
 217.373 +     * otherwise, check the next arc on the chain.
 217.374 +     */
 217.375 +    prevtop = top;
 217.376 +    top = &tos[top->link];
 217.377 +    if (top->selfpc == selfpc) {
 217.378 +      /*
 217.379 +       * there it is.
 217.380 +       * increment its count
 217.381 +       * move it to the head of the chain.
 217.382 +       */
 217.383 +      top->count++;
 217.384 +      toindex = prevtop->link;
 217.385 +      prevtop->link = top->link;
 217.386 +      top->link = *frompcindex;
 217.387 +      *frompcindex = (unsigned short)toindex;
 217.388 +      goto done;
 217.389 +    }
 217.390 +    
 217.391 +  }
 217.392 + done:
 217.393 +  profiling--;
 217.394 +  /* and fall through */
 217.395 + out:
 217.396 +  return;  /* normal return restores saved registers */
 217.397 +  
 217.398 + overflow:
 217.399 +  profiling++; /* halt further profiling */
 217.400 +#define TOLIMIT "mcount: tos overflow\n"
 217.401 +  systemMessage(0, TOLIMIT);
 217.402 +  goto out;
 217.403 +}
 217.404 +
 217.405 +void profSetHertz(int h)
 217.406 +{
 217.407 +  hz = h;
 217.408 +}
   218.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   218.2 +++ b/src/prof/prof.h	Sat Mar 03 10:31:27 2012 -0600
   218.3 @@ -0,0 +1,34 @@
   218.4 +// -*- C++ -*-
   218.5 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   218.6 +// Copyright (C) 1999-2003 Forgotten
   218.7 +// Copyright (C) 2004 Forgotten and the VBA development team
   218.8 +
   218.9 +// This program is free software; you can redistribute it and/or modify
  218.10 +// it under the terms of the GNU General Public License as published by
  218.11 +// the Free Software Foundation; either version 2, or(at your option)
  218.12 +// any later version.
  218.13 +//
  218.14 +// This program is distributed in the hope that it will be useful,
  218.15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  218.16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  218.17 +// GNU General Public License for more details.
  218.18 +//
  218.19 +// You should have received a copy of the GNU General Public License
  218.20 +// along with this program; if not, write to the Free Software Foundation,
  218.21 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  218.22 +
  218.23 +#ifndef VBA_PROF_PROF_H
  218.24 +#define VBA_PROF_PROF_H
  218.25 +
  218.26 +/* Control profiling;
  218.27 +   profiling is what mcount checks to see if
  218.28 +   all the data structures are ready.  */
  218.29 +
  218.30 +extern void profControl(int mode);
  218.31 +extern void profStartup(u32 lowpc, u32 highpc);
  218.32 +extern void profCleanup();
  218.33 +extern void profCount();
  218.34 +
  218.35 +extern void profSetHertz(int hertz);
  218.36 +#endif
  218.37 +
   219.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   219.2 +++ b/src/sdl/Array.h	Sat Mar 03 10:31:27 2012 -0600
   219.3 @@ -0,0 +1,40 @@
   219.4 +/***************************************************************************
   219.5 + *   Copyright (C) 2008 by Sindre Aam�s                                    *
   219.6 + *   aamas@stud.ntnu.no                                                    *
   219.7 + *                                                                         *
   219.8 + *   This program is free software; you can redistribute it and/or modify  *
   219.9 + *   it under the terms of the GNU General Public License version 2 as     *
  219.10 + *   published by the Free Software Foundation.                            *
  219.11 + *                                                                         *
  219.12 + *   This program is distributed in the hope that it will be useful,       *
  219.13 + *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  219.14 + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  219.15 + *   GNU General Public License version 2 for more details.                *
  219.16 + *                                                                         *
  219.17 + *   You should have received a copy of the GNU General Public License     *
  219.18 + *   version 2 along with this program; if not, write to the               *
  219.19 + *   Free Software Foundation, Inc.,                                       *
  219.20 + *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  219.21 + ***************************************************************************/
  219.22 +#ifndef ARRAY_H
  219.23 +#define ARRAY_H
  219.24 +
  219.25 +#include <cstddef>
  219.26 +
  219.27 +template<typename T>
  219.28 +class Array {
  219.29 +	T *a;
  219.30 +	std::size_t sz;
  219.31 +	
  219.32 +	Array(const Array &ar);
  219.33 +	
  219.34 +public:
  219.35 +	Array(const std::size_t size = 0) : a(size ? new T[size] : 0), sz(size) {}
  219.36 +	~Array() { delete []a; }
  219.37 +	void reset(const std::size_t size) { delete []a; a = size ? new T[size] : 0; sz = size; }
  219.38 +	std::size_t size() const { return sz; }
  219.39 +	operator T*() { return a; }
  219.40 +	operator const T*() const { return a; }
  219.41 +};
  219.42 +
  219.43 +#endif
   220.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   220.2 +++ b/src/sdl/Makefile.am	Sat Mar 03 10:31:27 2012 -0600
   220.3 @@ -0,0 +1,47 @@
   220.4 +bin_PROGRAMS = VisualBoyAdvance
   220.5 +
   220.6 +noinst_PROGRAMS = TestEmu
   220.7 +
   220.8 +VisualBoyAdvance_SOURCES = \
   220.9 +	SDL.cpp			\
  220.10 +	debugger.cpp		\
  220.11 +	debugger.h		\
  220.12 +	expr-lex.cpp		\
  220.13 +	expr.cpp		\
  220.14 +	expr.cpp.h		\
  220.15 +	exprNode.cpp		\
  220.16 +	exprNode.h		\
  220.17 +	getopt.c		\
  220.18 +	getopt.h		\
  220.19 +	getopt1.c		\
  220.20 +	../AutoBuild.h		\
  220.21 +	../NLS.h		\
  220.22 +	../Port.h
  220.23 +
  220.24 +VisualBoyAdvance_LDADD = @VBA_LIBS@ @SDL_LIBS@
  220.25 +
  220.26 +VisualBoyAdvance_DEPENDENCIES = @VBA_LIBS@
  220.27 +
  220.28 +TestEmu_SOURCES = \
  220.29 +	TestEmu.cpp		\
  220.30 +	debugger.cpp		\
  220.31 +	debugger.h		\
  220.32 +	expr-lex.cpp		\
  220.33 +	expr.cpp		\
  220.34 +	expr.cpp.h		\
  220.35 +	exprNode.cpp		\
  220.36 +	exprNode.h		\
  220.37 +	../AutoBuild.h		\
  220.38 +	../NLS.h		\
  220.39 +	../Port.h
  220.40 +
  220.41 +TestEmu_LDADD = @VBA_LIBS@ @SDL_LIBS@
  220.42 +
  220.43 +TestEmu_DEPENDENCIES = @VBA_LIBS@
  220.44 +
  220.45 +AM_CPPFLAGS = \
  220.46 +	-I$(top_srcdir)/src		\
  220.47 +	-DSDL				\
  220.48 +	-DSYSCONFDIR=\"$(sysconfdir)\"
  220.49 +
  220.50 +AM_CXXFLAGS = -fno-exceptions @SDL_CFLAGS@
   221.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   221.2 +++ b/src/sdl/RingBuffer.h	Sat Mar 03 10:31:27 2012 -0600
   221.3 @@ -0,0 +1,112 @@
   221.4 +/***************************************************************************
   221.5 + *   Copyright (C) 2008 by Sindre Aamås                                    *
   221.6 + *   aamas@stud.ntnu.no                                                    *
   221.7 + *                                                                         *
   221.8 + *   This program is free software; you can redistribute it and/or modify  *
   221.9 + *   it under the terms of the GNU General Public License version 2 as     *
  221.10 + *   published by the Free Software Foundation.                            *
  221.11 + *                                                                         *
  221.12 + *   This program is distributed in the hope that it will be useful,       *
  221.13 + *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  221.14 + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  221.15 + *   GNU General Public License version 2 for more details.                *
  221.16 + *                                                                         *
  221.17 + *   You should have received a copy of the GNU General Public License     *
  221.18 + *   version 2 along with this program; if not, write to the               *
  221.19 + *   Free Software Foundation, Inc.,                                       *
  221.20 + *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  221.21 + ***************************************************************************/
  221.22 +#ifndef RINGBUFFER_H
  221.23 +#define RINGBUFFER_H
  221.24 +
  221.25 +#include "Array.h"
  221.26 +#include <cstddef>
  221.27 +#include <algorithm>
  221.28 +#include <cstring>
  221.29 +
  221.30 +template<typename T>
  221.31 +class RingBuffer {
  221.32 +	Array<T> buf;
  221.33 +	std::size_t sz;
  221.34 +	std::size_t rpos;
  221.35 +	std::size_t wpos;
  221.36 +
  221.37 +public:
  221.38 +	RingBuffer(const std::size_t sz_in = 0) : sz(0), rpos(0), wpos(0) { reset(sz_in); }
  221.39 +
  221.40 +	std::size_t avail() const {
  221.41 +		return (wpos < rpos ? 0 : sz) + rpos - wpos - 1;
  221.42 +	}
  221.43 +
  221.44 +	void clear() {
  221.45 +		wpos = rpos = 0;
  221.46 +	}
  221.47 +
  221.48 +	void fill(T value);
  221.49 +
  221.50 +	void read(T *out, std::size_t num);
  221.51 +
  221.52 +	void reset(std::size_t sz_in);
  221.53 +
  221.54 +	std::size_t size() const {
  221.55 +		return sz - 1;
  221.56 +	}
  221.57 +
  221.58 +	std::size_t used() const {
  221.59 +		return (wpos < rpos ? sz : 0) + wpos - rpos;
  221.60 +	}
  221.61 +
  221.62 +	void write(const T *in, std::size_t num);
  221.63 +};
  221.64 +
  221.65 +template<typename T>
  221.66 +void RingBuffer<T>::fill(const T value) {
  221.67 +	std::fill(buf + 0, buf + sz, value);
  221.68 +	rpos = 0;
  221.69 +	wpos = sz - 1;
  221.70 +}
  221.71 +
  221.72 +template<typename T>
  221.73 +void RingBuffer<T>::read(T *out, std::size_t num) {
  221.74 +	if (rpos + num > sz) {
  221.75 +		const std::size_t n = sz - rpos;
  221.76 +
  221.77 +		std::memcpy(out, buf + rpos, n * sizeof(T));
  221.78 +
  221.79 +		rpos = 0;
  221.80 +		num -= n;
  221.81 +		out += n;
  221.82 +	}
  221.83 +
  221.84 +	std::memcpy(out, buf + rpos, num * sizeof(T));
  221.85 +
  221.86 +	if ((rpos += num) == sz)
  221.87 +		rpos = 0;
  221.88 +}
  221.89 +
  221.90 +template<typename T>
  221.91 +void RingBuffer<T>::reset(const std::size_t sz_in) {
  221.92 +	sz = sz_in + 1;
  221.93 +	rpos = wpos = 0;
  221.94 +	buf.reset(sz_in ? sz : 0);
  221.95 +}
  221.96 +
  221.97 +template<typename T>
  221.98 +void RingBuffer<T>::write(const T *in, std::size_t num) {
  221.99 +	if (wpos + num > sz) {
 221.100 +		const std::size_t n = sz - wpos;
 221.101 +
 221.102 +		std::memcpy(buf + wpos, in, n * sizeof(T));
 221.103 +
 221.104 +		wpos = 0;
 221.105 +		num -= n;
 221.106 +		in += n;
 221.107 +	}
 221.108 +
 221.109 +	std::memcpy(buf + wpos, in, num * sizeof(T));
 221.110 +
 221.111 +	if ((wpos += num) == sz)
 221.112 +		wpos = 0;
 221.113 +}
 221.114 +
 221.115 +#endif
   222.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   222.2 +++ b/src/sdl/SDL.cpp	Sat Mar 03 10:31:27 2012 -0600
   222.3 @@ -0,0 +1,3623 @@
   222.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   222.5 +// Copyright (C) 1999-2003 Forgotten
   222.6 +// Copyright (C) 2004 Forgotten and the VBA development team
   222.7 +
   222.8 +// This program is free software; you can redistribute it and/or modify
   222.9 +// it under the terms of the GNU General Public License as published by
  222.10 +// the Free Software Foundation; either version 2, or(at your option)
  222.11 +// any later version.
  222.12 +//
  222.13 +// This program is distributed in the hope that it will be useful,
  222.14 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  222.15 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  222.16 +// GNU General Public License for more details.
  222.17 +//
  222.18 +// You should have received a copy of the GNU General Public License
  222.19 +// along with this program; if not, write to the Free Software Foundation,
  222.20 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  222.21 +
  222.22 +#include <stdarg.h>
  222.23 +#include <stdlib.h>
  222.24 +#include <stdio.h>
  222.25 +#include <string.h>
  222.26 +#include <sys/types.h>
  222.27 +#include <sys/stat.h>
  222.28 +
  222.29 +#include "AutoBuild.h"
  222.30 +
  222.31 +#include "Port.h"
  222.32 +#include "SDL.h"
  222.33 +#include "debugger.h"
  222.34 +#include "gba/GBA.h"
  222.35 +#include "gba/GBAGlobals.h"
  222.36 +#include "gba/agbprint.h"
  222.37 +#include "gba/Flash.h"
  222.38 +#include "gba/RTC.h"
  222.39 +#include "gba/GBASound.h"
  222.40 +#include "gb/GB.h"
  222.41 +#include "gb/gbGlobals.h"
  222.42 +#include "common/Text.h"
  222.43 +#include "common/unzip.h"
  222.44 +#include "common/Util.h"
  222.45 +#include "common/movie.h"
  222.46 +#include "common/System.h"
  222.47 +#include "common/inputGlobal.h"
  222.48 +#include "../common/vbalua.h"
  222.49 +#include "SoundSDL.h"
  222.50 +
  222.51 +
  222.52 +#define GBC_CAPABLE ((gbRom[0x143] & 0x80) != 0)
  222.53 +#define SGB_CAPABLE (gbRom[0x146] == 0x03)
  222.54 +
  222.55 +#ifndef WIN32
  222.56 +# include <unistd.h>
  222.57 +# define GETCWD getcwd
  222.58 +#else // WIN32
  222.59 +# include <direct.h>
  222.60 +# define GETCWD _getcwd
  222.61 +#endif // WIN32
  222.62 +
  222.63 +#ifndef __GNUC__
  222.64 +# define HAVE_DECL_GETOPT 0
  222.65 +# define __STDC__ 1
  222.66 +# include "getopt.h"
  222.67 +#else // ! __GNUC__
  222.68 +# define HAVE_DECL_GETOPT 1
  222.69 +# include "getopt.h"
  222.70 +#endif // ! __GNUC__
  222.71 +
  222.72 +#ifdef MMX
  222.73 +extern "C" bool cpu_mmx;
  222.74 +#endif
  222.75 +extern bool8 soundEcho;
  222.76 +extern bool8 soundLowPass;
  222.77 +extern bool8 soundReverse;
  222.78 +extern int Init_2xSaI(u32);
  222.79 +extern void _2xSaI(u8*,u32,u8*,u8*,u32,int,int);
  222.80 +extern void _2xSaI32(u8*,u32,u8*,u8*,u32,int,int);  
  222.81 +extern void Super2xSaI(u8*,u32,u8*,u8*,u32,int,int);
  222.82 +extern void Super2xSaI32(u8*,u32,u8*,u8*,u32,int,int);
  222.83 +extern void SuperEagle(u8*,u32,u8*,u8*,u32,int,int);
  222.84 +extern void SuperEagle32(u8*,u32,u8*,u8*,u32,int,int);  
  222.85 +extern void Pixelate2x16(u8*,u32,u8*,u8*,u32,int,int);
  222.86 +extern void Pixelate2x32(u8*,u32,u8*,u8*,u32,int,int);
  222.87 +extern void MotionBlur(u8*,u32,u8*,u8*,u32,int,int);
  222.88 +extern void MotionBlur32(u8*,u32,u8*,u8*,u32,int,int);
  222.89 +extern void AdMame2x(u8*,u32,u8*,u8*,u32,int,int);
  222.90 +extern void AdMame2x32(u8*,u32,u8*,u8*,u32,int,int);
  222.91 +extern void Simple2x16(u8*,u32,u8*,u8*,u32,int,int);
  222.92 +extern void Simple2x32(u8*,u32,u8*,u8*,u32,int,int);
  222.93 +extern void Bilinear(u8*,u32,u8*,u8*,u32,int,int);
  222.94 +extern void Bilinear32(u8*,u32,u8*,u8*,u32,int,int);
  222.95 +extern void BilinearPlus(u8*,u32,u8*,u8*,u32,int,int);
  222.96 +extern void BilinearPlus32(u8*,u32,u8*,u8*,u32,int,int);
  222.97 +extern void Scanlines(u8*,u32,u8*,u8*,u32,int,int);
  222.98 +extern void Scanlines32(u8*,u32,u8*,u8*,u32,int,int);
  222.99 +extern void ScanlinesTV(u8*,u32,u8*,u8*,u32,int,int);
 222.100 +extern void ScanlinesTV32(u8*,u32,u8*,u8*,u32,int,int);
 222.101 +extern void hq2x(u8*,u32,u8*,u8*,u32,int,int);
 222.102 +extern void hq2x32(u8*,u32,u8*,u8*,u32,int,int);
 222.103 +extern void lq2x(u8*,u32,u8*,u8*,u32,int,int);
 222.104 +extern void lq2x32(u8*,u32,u8*,u8*,u32,int,int);
 222.105 +
 222.106 +extern void SmartIB(u8*,u32,int,int);
 222.107 +extern void SmartIB32(u8*,u32,int,int);
 222.108 +extern void MotionBlurIB(u8*,u32,int,int);
 222.109 +extern void MotionBlurIB32(u8*,u32,int,int);
 222.110 +
 222.111 +void Init_Overlay(SDL_Surface *surface, int overlaytype);
 222.112 +void Quit_Overlay(void);
 222.113 +void Draw_Overlay(SDL_Surface *surface, int size);
 222.114 +
 222.115 +extern void remoteInit();
 222.116 +extern void remoteCleanUp();
 222.117 +extern void remoteStubMain();
 222.118 +extern void remoteStubSignal(int,int);
 222.119 +extern void remoteOutput(char *, u32);
 222.120 +extern void remoteSetProtocol(int);
 222.121 +extern void remoteSetPort(int);
 222.122 +extern void debuggerOutput(char *, u32);
 222.123 +
 222.124 +extern void CPUUpdateRenderBuffers(bool);
 222.125 +
 222.126 +struct EmulatedSystem theEmulator = {
 222.127 +  NULL,
 222.128 +  NULL,
 222.129 +  NULL,
 222.130 +  NULL,
 222.131 +  NULL,
 222.132 +  NULL,
 222.133 +  NULL,
 222.134 +  NULL,
 222.135 +  NULL,
 222.136 +  NULL,
 222.137 +  NULL,
 222.138 +  NULL,
 222.139 +  false,
 222.140 +  0
 222.141 +};
 222.142 +
 222.143 +SDL_Surface *surface = NULL;
 222.144 +SDL_Overlay *overlay = NULL;
 222.145 +SDL_Rect overlay_rect;
 222.146 +
 222.147 +int systemSpeed = 0;
 222.148 +int systemRedShift = 0;
 222.149 +int systemBlueShift = 0;
 222.150 +int systemGreenShift = 0;
 222.151 +int systemColorDepth = 0;
 222.152 +int systemDebug = 0;
 222.153 +int systemVerbose = 0;
 222.154 +int systemFrameSkip = 0;
 222.155 +int systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
 222.156 +
 222.157 +int srcPitch = 0;
 222.158 +int srcWidth = 0;
 222.159 +int srcHeight = 0;
 222.160 +int destWidth = 0;
 222.161 +int destHeight = 0;
 222.162 +
 222.163 +int sensorX = 2047;
 222.164 +int sensorY = 2047;
 222.165 +bool sensorOn = false;
 222.166 +
 222.167 +int filter = 0;
 222.168 +u8 *delta = NULL;
 222.169 +
 222.170 +int sdlPrintUsage = 0;
 222.171 +int disableMMX = 0;
 222.172 +
 222.173 +int systemCartridgeType = 3;
 222.174 +int sizeOption = 0;
 222.175 +int captureFormat = 0;
 222.176 +int useMovie = 0;
 222.177 +
 222.178 +int pauseWhenInactive = 0;
 222.179 +int active = 1;
 222.180 +int emulating = 0;
 222.181 +int RGB_LOW_BITS_MASK=0x821;
 222.182 +u32 systemColorMap32[0x10000];
 222.183 +u16 systemColorMap16[0x10000];
 222.184 +u16 systemGbPalette[24];
 222.185 +void (*filterFunction)(u8*,u32,u8*,u8*,u32,int,int) = NULL;
 222.186 +void (*ifbFunction)(u8*,u32,int,int) = NULL;
 222.187 +int ifbType = 0;
 222.188 +char filename[2048];
 222.189 +char ipsname[2048];
 222.190 +char biosFileName[2048];
 222.191 +char movieFileName[2048];
 222.192 +char captureDir[2048];
 222.193 +char saveDir[2048];
 222.194 +char batteryDir[2048];
 222.195 +
 222.196 +static char *rewindMemory = NULL;
 222.197 +static int rewindPos = 0;
 222.198 +static int rewindTopPos = 0;
 222.199 +static int rewindCounter = 0;
 222.200 +static int rewindCount = 0;
 222.201 +static bool rewindSaveNeeded = false;
 222.202 +static int rewindTimer = 0;
 222.203 +
 222.204 +#define REWIND_SIZE 400000
 222.205 +
 222.206 +#define _stricmp strcasecmp
 222.207 +
 222.208 +/*bool sdlButtons[4][12] = {
 222.209 +  { false, false, false, false, false, false, 
 222.210 +    false, false, false, false, false, false },
 222.211 +  { false, false, false, false, false, false,
 222.212 +    false, false, false, false, false, false },
 222.213 +  { false, false, false, false, false, false,
 222.214 +    false, false, false, false, false, false },
 222.215 +  { false, false, false, false, false, false,
 222.216 +    false, false, false, false, false, false }
 222.217 +};*/
 222.218 +/*
 222.219 +	I'm changing the way the SDL GUI handles the button
 222.220 +	input to match the one in win32, this is needed in
 222.221 +	order to be compatible with the format required by
 222.222 +	common/movie.cpp
 222.223 +	--Felipe
 222.224 +*/
 222.225 +
 222.226 +u16 currentButtons[4] = {0, 0, 0, 0};
 222.227 +
 222.228 +bool sdlMotionButtons[4] = { false, false, false, false };
 222.229 +const int32 INITIAL_SENSOR_VALUE = 2047;
 222.230 +
 222.231 +int sdlNumDevices = 0;
 222.232 +SDL_Joystick **sdlDevices = NULL;
 222.233 +
 222.234 +bool wasPaused = false;
 222.235 +int autoFrameSkip = 0;
 222.236 +int frameskipadjust = 0;
 222.237 +int showRenderedFrames = 0;
 222.238 +int renderedFrames = 0;
 222.239 +
 222.240 +int throttle = 0;
 222.241 +u32 throttleLastTime = 0;
 222.242 +u32 autoFrameSkipLastTime = 0;
 222.243 +
 222.244 +int showSpeed = 1;
 222.245 +int showSpeedTransparent = 1;
 222.246 +bool disableStatusMessages = false;
 222.247 +bool paused = false;
 222.248 +bool pauseNextFrame = false;
 222.249 +bool debugger = false;
 222.250 +bool debuggerStub = false;
 222.251 +int fullscreen = 0;
 222.252 +bool systemSoundOn = false;
 222.253 +bool yuv = false;
 222.254 +int yuvType = 0;
 222.255 +bool removeIntros = false;
 222.256 +int sdlFlashSize = 0;
 222.257 +int sdlAutoIPS = 1;
 222.258 +int sdlRtcEnable = 0;
 222.259 +int sdlAgbPrint = 0;
 222.260 +
 222.261 +int sdlDefaultJoypad = 0;
 222.262 +
 222.263 +extern void debuggerSignal(int,int);
 222.264 +
 222.265 +void (*dbgMain)() = debuggerMain;
 222.266 +void (*dbgSignal)(int,int) = debuggerSignal;
 222.267 +void (*dbgOutput)(char *, u32) = debuggerOutput;
 222.268 +
 222.269 +int  mouseCounter = 0;
 222.270 +int autoFire = 0;
 222.271 +bool autoFireToggle = false;
 222.272 +
 222.273 +bool screenMessage[8] = {false,false,false,false,false,false,false,false};
 222.274 +char screenMessageBuffer[8][21];
 222.275 +u32  screenMessageTime[8] = {0,0,0,0,0,0,0,0};
 222.276 +u32  screenMessageDuration[8] = {0,0,0,0,0,0,0,0};
 222.277 +
 222.278 +SDL_cond *cond = NULL;
 222.279 +SDL_mutex *mutex = NULL;
 222.280 +u8* sdlBuffer;
 222.281 +int sdlSoundLen = 0;
 222.282 +SoundSDL* soundDriver = NULL;
 222.283 +
 222.284 +char *arg0;
 222.285 +
 222.286 +#ifndef C_CORE
 222.287 +u8 sdlStretcher[16384];
 222.288 +int sdlStretcherPos;
 222.289 +#else
 222.290 +void (*sdlStretcher)(u8 *, u8*) = NULL;
 222.291 +#endif
 222.292 +
 222.293 +u16 joypad[4][12] = {
 222.294 +  { SDLK_LEFT,  SDLK_RIGHT,
 222.295 +    SDLK_UP,    SDLK_DOWN,
 222.296 +    SDLK_z,     SDLK_x,
 222.297 +    SDLK_RETURN,SDLK_BACKSPACE,
 222.298 +    SDLK_a,     SDLK_s,
 222.299 +    SDLK_SPACE, SDLK_F12
 222.300 +  },
 222.301 +  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
 222.302 +  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
 222.303 +  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
 222.304 +};
 222.305 +
 222.306 +u16 defaultJoypad[12] = {
 222.307 +  SDLK_LEFT,  SDLK_RIGHT,
 222.308 +  SDLK_UP,    SDLK_DOWN,
 222.309 +  SDLK_z,     SDLK_x,
 222.310 +  SDLK_RETURN,SDLK_BACKSPACE,
 222.311 +  SDLK_a,     SDLK_s,
 222.312 +  SDLK_SPACE, SDLK_F12
 222.313 +};
 222.314 +
 222.315 +u16 motion[4] = {
 222.316 +  SDLK_KP4, SDLK_KP6, SDLK_KP8, SDLK_KP2
 222.317 +};
 222.318 +
 222.319 +u16 defaultMotion[4] = {
 222.320 +  SDLK_KP4, SDLK_KP6, SDLK_KP8, SDLK_KP2
 222.321 +};
 222.322 +
 222.323 +struct option sdlOptions[] = {
 222.324 +  { "agb-print", no_argument, &sdlAgbPrint, 1 },
 222.325 +  { "auto-frameskip", no_argument, &autoFrameSkip, 1 },  
 222.326 +  { "bios", required_argument, 0, 'b' },
 222.327 +  { "config", required_argument, 0, 'c' },
 222.328 +  { "debug", no_argument, 0, 'd' },
 222.329 +  { "filter", required_argument, 0, 'f' },
 222.330 +  { "filter-normal", no_argument, &filter, 0 },
 222.331 +  { "filter-tv-mode", no_argument, &filter, 1 },
 222.332 +  { "filter-2xsai", no_argument, &filter, 2 },
 222.333 +  { "filter-super-2xsai", no_argument, &filter, 3 },
 222.334 +  { "filter-super-eagle", no_argument, &filter, 4 },
 222.335 +  { "filter-pixelate", no_argument, &filter, 5 },
 222.336 +  { "filter-motion-blur", no_argument, &filter, 6 },
 222.337 +  { "filter-advmame", no_argument, &filter, 7 },
 222.338 +  { "filter-simple2x", no_argument, &filter, 8 },
 222.339 +  { "filter-bilinear", no_argument, &filter, 9 },
 222.340 +  { "filter-bilinear+", no_argument, &filter, 10 },
 222.341 +  { "filter-scanlines", no_argument, &filter, 11 },
 222.342 +  { "filter-hq2x", no_argument, &filter, 12 },
 222.343 +  { "filter-lq2x", no_argument, &filter, 13 },
 222.344 +  { "flash-size", required_argument, 0, 'S' },
 222.345 +  { "flash-64k", no_argument, &sdlFlashSize, 0 },
 222.346 +  { "flash-128k", no_argument, &sdlFlashSize, 1 },
 222.347 +  { "frameskip", required_argument, 0, 's' },
 222.348 +  { "fullscreen", no_argument, &fullscreen, 1 },
 222.349 +  { "gdb", required_argument, 0, 'G' },
 222.350 +  { "help", no_argument, &sdlPrintUsage, 1 },
 222.351 +  { "ifb-none", no_argument, &ifbType, 0 },
 222.352 +  { "ifb-motion-blur", no_argument, &ifbType, 1 },
 222.353 +  { "ifb-smart", no_argument, &ifbType, 2 },
 222.354 +  { "ips", required_argument, 0, 'i' },
 222.355 +  { "no-agb-print", no_argument, &sdlAgbPrint, 0 },
 222.356 +  { "no-auto-frameskip", no_argument, &autoFrameSkip, 0 },
 222.357 +  { "no-debug", no_argument, 0, 'N' },
 222.358 +  { "no-ips", no_argument, &sdlAutoIPS, 0 },
 222.359 +  { "no-mmx", no_argument, &disableMMX, 1 },
 222.360 +  { "no-pause-when-inactive", no_argument, &pauseWhenInactive, 0 },
 222.361 +  { "no-rtc", no_argument, &sdlRtcEnable, 0 },
 222.362 +  { "no-show-speed", no_argument, &showSpeed, 0 },
 222.363 +  { "no-throttle", no_argument, &throttle, 0 },
 222.364 +  { "pause-when-inactive", no_argument, &pauseWhenInactive, 1 },
 222.365 +  { "profile", optional_argument, 0, 'P' },
 222.366 +  { "rtc", no_argument, &sdlRtcEnable, 1 },
 222.367 +  { "save-type", required_argument, 0, 't' },
 222.368 +  { "save-auto", no_argument, &cpuSaveType, 0 },
 222.369 +  { "save-eeprom", no_argument, &cpuSaveType, 1 },
 222.370 +  { "save-sram", no_argument, &cpuSaveType, 2 },
 222.371 +  { "save-flash", no_argument, &cpuSaveType, 3 },
 222.372 +  { "save-sensor", no_argument, &cpuSaveType, 4 },
 222.373 +  { "save-none", no_argument, &cpuSaveType, 5 },
 222.374 +  { "show-speed-normal", no_argument, &showSpeed, 1 },
 222.375 +  { "show-speed-detailed", no_argument, &showSpeed, 2 },
 222.376 +  { "throttle", required_argument, 0, 'T' },
 222.377 +  { "verbose", required_argument, 0, 'v' },  
 222.378 +  { "video-1x", no_argument, &sizeOption, 0 },
 222.379 +  { "video-2x", no_argument, &sizeOption, 1 },
 222.380 +  { "video-3x", no_argument, &sizeOption, 2 },
 222.381 +  { "video-4x", no_argument, &sizeOption, 3 },
 222.382 +  { "yuv", required_argument, 0, 'Y' },
 222.383 +  { "recordmovie", required_argument, 0, 'r' },
 222.384 +  { "playmovie", required_argument, 0, 'p' },
 222.385 +  { "watchmovie", required_argument, 0, 'w' },
 222.386 +  { NULL, no_argument, NULL, 0 }
 222.387 +};
 222.388 +
 222.389 +#ifndef C_CORE
 222.390 +#define SDL_LONG(val) \
 222.391 +  *((u32 *)&sdlStretcher[sdlStretcherPos]) = val;\
 222.392 +  sdlStretcherPos+=4;
 222.393 +
 222.394 +#define SDL_AND_EAX(val) \
 222.395 +  sdlStretcher[sdlStretcherPos++] = 0x25;\
 222.396 +  SDL_LONG(val);
 222.397 +
 222.398 +#define SDL_AND_EBX(val) \
 222.399 +  sdlStretcher[sdlStretcherPos++] = 0x81;\
 222.400 +  sdlStretcher[sdlStretcherPos++] = 0xe3;\
 222.401 +  SDL_LONG(val);
 222.402 +
 222.403 +#define SDL_OR_EAX_EBX \
 222.404 +  sdlStretcher[sdlStretcherPos++] = 0x09;\
 222.405 +  sdlStretcher[sdlStretcherPos++] = 0xd8;
 222.406 +
 222.407 +#define SDL_LOADL_EBX \
 222.408 +  sdlStretcher[sdlStretcherPos++] = 0x8b;\
 222.409 +  sdlStretcher[sdlStretcherPos++] = 0x1f;
 222.410 +
 222.411 +#define SDL_LOADW \
 222.412 +  sdlStretcher[sdlStretcherPos++] = 0x66;\
 222.413 +  sdlStretcher[sdlStretcherPos++] = 0x8b;\
 222.414 +  sdlStretcher[sdlStretcherPos++] = 0x06;\
 222.415 +  sdlStretcher[sdlStretcherPos++] = 0x83;\
 222.416 +  sdlStretcher[sdlStretcherPos++] = 0xc6;\
 222.417 +  sdlStretcher[sdlStretcherPos++] = 0x02;  
 222.418 +
 222.419 +#define SDL_LOADL \
 222.420 +  sdlStretcher[sdlStretcherPos++] = 0x8b;\
 222.421 +  sdlStretcher[sdlStretcherPos++] = 0x06;\
 222.422 +  sdlStretcher[sdlStretcherPos++] = 0x83;\
 222.423 +  sdlStretcher[sdlStretcherPos++] = 0xc6;\
 222.424 +  sdlStretcher[sdlStretcherPos++] = 0x04;  
 222.425 +
 222.426 +#define SDL_LOADL2 \
 222.427 +  sdlStretcher[sdlStretcherPos++] = 0x8b;\
 222.428 +  sdlStretcher[sdlStretcherPos++] = 0x06;\
 222.429 +  sdlStretcher[sdlStretcherPos++] = 0x83;\
 222.430 +  sdlStretcher[sdlStretcherPos++] = 0xc6;\
 222.431 +  sdlStretcher[sdlStretcherPos++] = 0x03;  
 222.432 +
 222.433 +#define SDL_STOREW \
 222.434 +  sdlStretcher[sdlStretcherPos++] = 0x66;\
 222.435 +  sdlStretcher[sdlStretcherPos++] = 0x89;\
 222.436 +  sdlStretcher[sdlStretcherPos++] = 0x07;\
 222.437 +  sdlStretcher[sdlStretcherPos++] = 0x83;\
 222.438 +  sdlStretcher[sdlStretcherPos++] = 0xc7;\
 222.439 +  sdlStretcher[sdlStretcherPos++] = 0x02;  
 222.440 +
 222.441 +#define SDL_STOREL \
 222.442 +  sdlStretcher[sdlStretcherPos++] = 0x89;\
 222.443 +  sdlStretcher[sdlStretcherPos++] = 0x07;\
 222.444 +  sdlStretcher[sdlStretcherPos++] = 0x83;\
 222.445 +  sdlStretcher[sdlStretcherPos++] = 0xc7;\
 222.446 +  sdlStretcher[sdlStretcherPos++] = 0x04;  
 222.447 +
 222.448 +#define SDL_STOREL2 \
 222.449 +  sdlStretcher[sdlStretcherPos++] = 0x89;\
 222.450 +  sdlStretcher[sdlStretcherPos++] = 0x07;\
 222.451 +  sdlStretcher[sdlStretcherPos++] = 0x83;\
 222.452 +  sdlStretcher[sdlStretcherPos++] = 0xc7;\
 222.453 +  sdlStretcher[sdlStretcherPos++] = 0x03;  
 222.454 +
 222.455 +#define SDL_RET \
 222.456 +  sdlStretcher[sdlStretcherPos++] = 0xc3;
 222.457 +
 222.458 +#define SDL_PUSH_EAX \
 222.459 +  sdlStretcher[sdlStretcherPos++] = 0x50;
 222.460 +
 222.461 +#define SDL_PUSH_ECX \
 222.462 +  sdlStretcher[sdlStretcherPos++] = 0x51;
 222.463 +
 222.464 +#define SDL_PUSH_EBX \
 222.465 +  sdlStretcher[sdlStretcherPos++] = 0x53;
 222.466 +
 222.467 +#define SDL_PUSH_ESI \
 222.468 +  sdlStretcher[sdlStretcherPos++] = 0x56;
 222.469 +
 222.470 +#define SDL_PUSH_EDI \
 222.471 +  sdlStretcher[sdlStretcherPos++] = 0x57;
 222.472 +
 222.473 +#define SDL_POP_EAX \
 222.474 +  sdlStretcher[sdlStretcherPos++] = 0x58;
 222.475 +
 222.476 +#define SDL_POP_ECX \
 222.477 +  sdlStretcher[sdlStretcherPos++] = 0x59;
 222.478 +
 222.479 +#define SDL_POP_EBX \
 222.480 +  sdlStretcher[sdlStretcherPos++] = 0x5b;
 222.481 +
 222.482 +#define SDL_POP_ESI \
 222.483 +  sdlStretcher[sdlStretcherPos++] = 0x5e;
 222.484 +
 222.485 +#define SDL_POP_EDI \
 222.486 +  sdlStretcher[sdlStretcherPos++] = 0x5f;
 222.487 +
 222.488 +#define SDL_MOV_ECX(val) \
 222.489 +  sdlStretcher[sdlStretcherPos++] = 0xb9;\
 222.490 +  SDL_LONG(val);
 222.491 +
 222.492 +#define SDL_REP_MOVSB \
 222.493 +  sdlStretcher[sdlStretcherPos++] = 0xf3;\
 222.494 +  sdlStretcher[sdlStretcherPos++] = 0xa4;
 222.495 +
 222.496 +#define SDL_REP_MOVSW \
 222.497 +  sdlStretcher[sdlStretcherPos++] = 0xf3;\
 222.498 +  sdlStretcher[sdlStretcherPos++] = 0x66;\
 222.499 +  sdlStretcher[sdlStretcherPos++] = 0xa5;
 222.500 +
 222.501 +#define SDL_REP_MOVSL \
 222.502 +  sdlStretcher[sdlStretcherPos++] = 0xf3;\
 222.503 +  sdlStretcher[sdlStretcherPos++] = 0xa5;
 222.504 +
 222.505 +void sdlMakeStretcher(int width)
 222.506 +{
 222.507 +  sdlStretcherPos = 0;
 222.508 +  switch(systemColorDepth) {
 222.509 +  case 16:
 222.510 +    if(sizeOption) {
 222.511 +      SDL_PUSH_EAX;
 222.512 +      SDL_PUSH_ESI;
 222.513 +      SDL_PUSH_EDI;
 222.514 +      for(int i = 0; i < width; i++) {
 222.515 +        SDL_LOADW;
 222.516 +        SDL_STOREW;
 222.517 +        SDL_STOREW;
 222.518 +        if(sizeOption > 1) {
 222.519 +          SDL_STOREW;
 222.520 +        }
 222.521 +        if(sizeOption > 2) {
 222.522 +          SDL_STOREW;
 222.523 +        }
 222.524 +      }
 222.525 +      SDL_POP_EDI;
 222.526 +      SDL_POP_ESI;
 222.527 +      SDL_POP_EAX;
 222.528 +      SDL_RET;
 222.529 +    } else {
 222.530 +      SDL_PUSH_ESI;
 222.531 +      SDL_PUSH_EDI;
 222.532 +      SDL_PUSH_ECX;
 222.533 +      SDL_MOV_ECX(width);
 222.534 +      SDL_REP_MOVSW;
 222.535 +      SDL_POP_ECX;
 222.536 +      SDL_POP_EDI;
 222.537 +      SDL_POP_ESI;
 222.538 +      SDL_RET;
 222.539 +    }
 222.540 +    break;
 222.541 +  case 24:
 222.542 +    if(sizeOption) {
 222.543 +      SDL_PUSH_EAX;
 222.544 +      SDL_PUSH_ESI;
 222.545 +      SDL_PUSH_EDI;
 222.546 +      int w = width - 1;
 222.547 +      for(int i = 0; i < w; i++) {
 222.548 +        SDL_LOADL2;
 222.549 +        SDL_STOREL2;
 222.550 +        SDL_STOREL2;
 222.551 +        if(sizeOption > 1) {
 222.552 +          SDL_STOREL2;
 222.553 +        }
 222.554 +        if(sizeOption > 2) {
 222.555 +          SDL_STOREL2;
 222.556 +        }
 222.557 +      }
 222.558 +      // need to write the last one
 222.559 +      SDL_LOADL2;
 222.560 +      SDL_STOREL2;
 222.561 +      if(sizeOption > 1) {
 222.562 +        SDL_STOREL2;
 222.563 +      }
 222.564 +      if(sizeOption > 2) {
 222.565 +        SDL_STOREL2;
 222.566 +      }
 222.567 +      SDL_AND_EAX(0x00ffffff);
 222.568 +      SDL_PUSH_EBX;
 222.569 +      SDL_LOADL_EBX;
 222.570 +      SDL_AND_EBX(0xff000000);
 222.571 +      SDL_OR_EAX_EBX;
 222.572 +      SDL_POP_EBX;
 222.573 +      SDL_STOREL2;
 222.574 +      SDL_POP_EDI;
 222.575 +      SDL_POP_ESI;
 222.576 +      SDL_POP_EAX;
 222.577 +      SDL_RET;
 222.578 +    } else {
 222.579 +      SDL_PUSH_ESI;
 222.580 +      SDL_PUSH_EDI;
 222.581 +      SDL_PUSH_ECX;
 222.582 +      SDL_MOV_ECX(3*width);
 222.583 +      SDL_REP_MOVSB;
 222.584 +      SDL_POP_ECX;
 222.585 +      SDL_POP_EDI;
 222.586 +      SDL_POP_ESI;
 222.587 +      SDL_RET;
 222.588 +    }
 222.589 +    break;
 222.590 +  case 32:
 222.591 +    if(sizeOption) {
 222.592 +      SDL_PUSH_EAX;
 222.593 +      SDL_PUSH_ESI;
 222.594 +      SDL_PUSH_EDI;
 222.595 +      for(int i = 0; i < width; i++) {
 222.596 +        SDL_LOADL;
 222.597 +        SDL_STOREL;
 222.598 +        SDL_STOREL;
 222.599 +        if(sizeOption > 1) {
 222.600 +          SDL_STOREL;
 222.601 +        }
 222.602 +        if(sizeOption > 2) {
 222.603 +          SDL_STOREL;
 222.604 +        }
 222.605 +      }
 222.606 +      SDL_POP_EDI;
 222.607 +      SDL_POP_ESI;
 222.608 +      SDL_POP_EAX;
 222.609 +      SDL_RET;
 222.610 +    } else {
 222.611 +      SDL_PUSH_ESI;
 222.612 +      SDL_PUSH_EDI;
 222.613 +      SDL_PUSH_ECX;
 222.614 +      SDL_MOV_ECX(width);
 222.615 +      SDL_REP_MOVSL;
 222.616 +      SDL_POP_ECX;
 222.617 +      SDL_POP_EDI;
 222.618 +      SDL_POP_ESI;
 222.619 +      SDL_RET;
 222.620 +    }
 222.621 +    break;
 222.622 +  }
 222.623 +}
 222.624 +
 222.625 +#ifdef _MSC_VER
 222.626 +#define SDL_CALL_STRETCHER \
 222.627 +  {\
 222.628 +    __asm mov eax, stretcher\
 222.629 +    __asm mov edi, dest\
 222.630 +    __asm mov esi, src\
 222.631 +    __asm call eax\
 222.632 +  }
 222.633 +#else
 222.634 +#define SDL_CALL_STRETCHER \
 222.635 +        asm volatile("call *%%eax"::"a" (stretcher),"S" (src),"D" (dest))
 222.636 +#endif
 222.637 +#else
 222.638 +#define SDL_CALL_STRETCHER \
 222.639 +       sdlStretcher(src, dest)
 222.640 +
 222.641 +void sdlStretch16x1(u8 *src, u8 *dest)
 222.642 +{
 222.643 +  u16 *s = (u16 *)src;
 222.644 +  u16 *d = (u16 *)dest;
 222.645 +  for(int i = 0; i < srcWidth; i++)
 222.646 +    *d++ = *s++;
 222.647 +}
 222.648 +
 222.649 +void sdlStretch16x2(u8 *src, u8 *dest)
 222.650 +{
 222.651 +  u16 *s = (u16 *)src;
 222.652 +  u16 *d = (u16 *)dest;
 222.653 +  for(int i = 0; i < srcWidth; i++) {
 222.654 +    *d++ = *s;
 222.655 +    *d++ = *s++;
 222.656 +  }
 222.657 +}
 222.658 +
 222.659 +void sdlStretch16x3(u8 *src, u8 *dest)
 222.660 +{
 222.661 +  u16 *s = (u16 *)src;
 222.662 +  u16 *d = (u16 *)dest;
 222.663 +  for(int i = 0; i < srcWidth; i++) {
 222.664 +    *d++ = *s;
 222.665 +    *d++ = *s;
 222.666 +    *d++ = *s++;
 222.667 +  }
 222.668 +}
 222.669 +
 222.670 +void sdlStretch16x4(u8 *src, u8 *dest)
 222.671 +{
 222.672 +  u16 *s = (u16 *)src;
 222.673 +  u16 *d = (u16 *)dest;
 222.674 +  for(int i = 0; i < srcWidth; i++) {
 222.675 +    *d++ = *s;
 222.676 +    *d++ = *s;
 222.677 +    *d++ = *s;
 222.678 +    *d++ = *s++;
 222.679 +  }
 222.680 +}
 222.681 +
 222.682 +void (*sdlStretcher16[4])(u8 *, u8 *) = {
 222.683 +  sdlStretch16x1,
 222.684 +  sdlStretch16x2,
 222.685 +  sdlStretch16x3,
 222.686 +  sdlStretch16x4
 222.687 +};
 222.688 +
 222.689 +void sdlStretch32x1(u8 *src, u8 *dest)
 222.690 +{
 222.691 +  u32 *s = (u32 *)src;
 222.692 +  u32 *d = (u32 *)dest;
 222.693 +  for(int i = 0; i < srcWidth; i++)
 222.694 +    *d++ = *s++;
 222.695 +}
 222.696 +
 222.697 +void sdlStretch32x2(u8 *src, u8 *dest)
 222.698 +{
 222.699 +  u32 *s = (u32 *)src;
 222.700 +  u32 *d = (u32 *)dest;
 222.701 +  for(int i = 0; i < srcWidth; i++) {
 222.702 +    *d++ = *s;
 222.703 +    *d++ = *s++;
 222.704 +  }
 222.705 +}
 222.706 +
 222.707 +void sdlStretch32x3(u8 *src, u8 *dest)
 222.708 +{
 222.709 +  u32 *s = (u32 *)src;
 222.710 +  u32 *d = (u32 *)dest;
 222.711 +  for(int i = 0; i < srcWidth; i++) {
 222.712 +    *d++ = *s;
 222.713 +    *d++ = *s;
 222.714 +    *d++ = *s++;
 222.715 +  }
 222.716 +}
 222.717 +
 222.718 +void sdlStretch32x4(u8 *src, u8 *dest)
 222.719 +{
 222.720 +  u32 *s = (u32 *)src;
 222.721 +  u32 *d = (u32 *)dest;
 222.722 +  for(int i = 0; i < srcWidth; i++) {
 222.723 +    *d++ = *s;
 222.724 +    *d++ = *s;
 222.725 +    *d++ = *s;
 222.726 +    *d++ = *s++;
 222.727 +  }
 222.728 +}
 222.729 +
 222.730 +void (*sdlStretcher32[4])(u8 *, u8 *) = {
 222.731 +  sdlStretch32x1,
 222.732 +  sdlStretch32x2,
 222.733 +  sdlStretch32x3,
 222.734 +  sdlStretch32x4
 222.735 +};
 222.736 +
 222.737 +void sdlStretch24x1(u8 *src, u8 *dest)
 222.738 +{
 222.739 +  u8 *s = src;
 222.740 +  u8 *d = dest;
 222.741 +  for(int i = 0; i < srcWidth; i++) {
 222.742 +    *d++ = *s++;
 222.743 +    *d++ = *s++;
 222.744 +    *d++ = *s++;
 222.745 +  }
 222.746 +}
 222.747 +
 222.748 +void sdlStretch24x2(u8 *src, u8 *dest)
 222.749 +{
 222.750 +  u8 *s = (u8 *)src;
 222.751 +  u8 *d = (u8 *)dest;
 222.752 +  for(int i = 0; i < srcWidth; i++) {
 222.753 +    *d++ = *s;
 222.754 +    *d++ = *(s+1);
 222.755 +    *d++ = *(s+2);
 222.756 +    s += 3;
 222.757 +    *d++ = *s;
 222.758 +    *d++ = *(s+1);
 222.759 +    *d++ = *(s+2);
 222.760 +    s += 3;
 222.761 +  }
 222.762 +}
 222.763 +
 222.764 +void sdlStretch24x3(u8 *src, u8 *dest)
 222.765 +{
 222.766 +  u8 *s = (u8 *)src;
 222.767 +  u8 *d = (u8 *)dest;
 222.768 +  for(int i = 0; i < srcWidth; i++) {
 222.769 +    *d++ = *s;
 222.770 +    *d++ = *(s+1);
 222.771 +    *d++ = *(s+2);
 222.772 +    s += 3;
 222.773 +    *d++ = *s;
 222.774 +    *d++ = *(s+1);
 222.775 +    *d++ = *(s+2);
 222.776 +    s += 3;
 222.777 +    *d++ = *s;
 222.778 +    *d++ = *(s+1);
 222.779 +    *d++ = *(s+2);
 222.780 +    s += 3;
 222.781 +  }
 222.782 +}
 222.783 +
 222.784 +void sdlStretch24x4(u8 *src, u8 *dest)
 222.785 +{
 222.786 +  u8 *s = (u8 *)src;
 222.787 +  u8 *d = (u8 *)dest;
 222.788 +  for(int i = 0; i < srcWidth; i++) {
 222.789 +    *d++ = *s;
 222.790 +    *d++ = *(s+1);
 222.791 +    *d++ = *(s+2);
 222.792 +    s += 3;
 222.793 +    *d++ = *s;
 222.794 +    *d++ = *(s+1);
 222.795 +    *d++ = *(s+2);
 222.796 +    s += 3;
 222.797 +    *d++ = *s;
 222.798 +    *d++ = *(s+1);
 222.799 +    *d++ = *(s+2);
 222.800 +    s += 3;
 222.801 +    *d++ = *s;
 222.802 +    *d++ = *(s+1);
 222.803 +    *d++ = *(s+2);
 222.804 +    s += 3;
 222.805 +  }
 222.806 +}
 222.807 +
 222.808 +void (*sdlStretcher24[4])(u8 *, u8 *) = {
 222.809 +  sdlStretch24x1,
 222.810 +  sdlStretch24x2,
 222.811 +  sdlStretch24x3,
 222.812 +  sdlStretch24x4
 222.813 +};
 222.814 +
 222.815 +#endif
 222.816 +
 222.817 +u32 sdlFromHex(char *s)
 222.818 +{
 222.819 +  u32 value;
 222.820 +  sscanf(s, "%x", &value);
 222.821 +  return value;
 222.822 +}
 222.823 +
 222.824 +#ifdef __MSC__
 222.825 +#define stat _stat
 222.826 +#define S_IFDIR _S_IFDIR
 222.827 +#endif
 222.828 +
 222.829 +void sdlCheckDirectory(char *dir)
 222.830 +{
 222.831 +  struct stat buf;
 222.832 +
 222.833 +  int len = strlen(dir);
 222.834 +
 222.835 +  char *p = dir + len - 1;
 222.836 +
 222.837 +  if(*p == '/' ||
 222.838 +     *p == '\\')
 222.839 +    *p = 0;
 222.840 +  
 222.841 +  if(stat(dir, &buf) == 0) {
 222.842 +    if(!(buf.st_mode & S_IFDIR)) {
 222.843 +      fprintf(stderr, "Error: %s is not a directory\n", dir);
 222.844 +      dir[0] = 0;
 222.845 +    }
 222.846 +  } else {
 222.847 +    fprintf(stderr, "Error: %s does not exist\n", dir);
 222.848 +    dir[0] = 0;
 222.849 +  }
 222.850 +}
 222.851 +
 222.852 +char *sdlGetFilename(char *name)
 222.853 +{
 222.854 +  static char filebuffer[2048];
 222.855 +
 222.856 +  int len = strlen(name);
 222.857 +  
 222.858 +  char *p = name + len - 1;
 222.859 +  
 222.860 +  while(true) {
 222.861 +    if(*p == '/' ||
 222.862 +       *p == '\\') {
 222.863 +      p++;
 222.864 +      break;
 222.865 +    }
 222.866 +    len--;
 222.867 +    p--;
 222.868 +    if(len == 0)
 222.869 +      break;
 222.870 +  }
 222.871 +  
 222.872 +  if(len == 0)
 222.873 +    strcpy(filebuffer, name);
 222.874 +  else
 222.875 +    strcpy(filebuffer, p);
 222.876 +  return filebuffer;
 222.877 +}
 222.878 +
 222.879 +FILE *sdlFindFile(const char *name)
 222.880 +{
 222.881 +  char buffer[4096];
 222.882 +  char path[2048];
 222.883 +
 222.884 +#ifdef WIN32
 222.885 +#define PATH_SEP ";"
 222.886 +#define FILE_SEP '\\'
 222.887 +#define EXE_NAME "VisualBoyAdvance-SDL.exe"
 222.888 +#else // ! WIN32
 222.889 +#define PATH_SEP ":"
 222.890 +#define FILE_SEP '/'
 222.891 +#define EXE_NAME "VisualBoyAdvance"
 222.892 +#endif // ! WIN32
 222.893 +
 222.894 +  fprintf(stderr, "Searching for file %s\n", name);
 222.895 +  
 222.896 +  if(GETCWD(buffer, 2048)) {
 222.897 +    fprintf(stderr, "Searching current directory: %s\n", buffer);
 222.898 +  }
 222.899 +  
 222.900 +  FILE *f = fopen(name, "r");
 222.901 +  if(f != NULL) {
 222.902 +    return f;
 222.903 +  }
 222.904 +
 222.905 +  char *home = getenv("HOME");
 222.906 +
 222.907 +  if(home != NULL) {
 222.908 +    fprintf(stderr, "Searching home directory: %s\n", home);
 222.909 +    sprintf(path, "%s%c%s", home, FILE_SEP, name);
 222.910 +    f = fopen(path, "r");
 222.911 +    if(f != NULL)
 222.912 +      return f;
 222.913 +  }
 222.914 +
 222.915 +#ifdef WIN32
 222.916 +  home = getenv("USERPROFILE");
 222.917 +  if(home != NULL) {
 222.918 +    fprintf(stderr, "Searching user profile directory: %s\n", home);
 222.919 +    sprintf(path, "%s%c%s", home, FILE_SEP, name);
 222.920 +    f = fopen(path, "r");
 222.921 +    if(f != NULL)
 222.922 +      return f;
 222.923 +  }
 222.924 +#else // ! WIN32
 222.925 +    fprintf(stderr, "Searching system config directory: %s\n", SYSCONFDIR);
 222.926 +    sprintf(path, "%s%c%s", SYSCONFDIR, FILE_SEP, name);
 222.927 +    f = fopen(path, "r");
 222.928 +    if(f != NULL)
 222.929 +      return f;
 222.930 +#endif // ! WIN32
 222.931 +
 222.932 +  if(!strchr(arg0, '/') &&
 222.933 +     !strchr(arg0, '\\')) {
 222.934 +    char *path = getenv("PATH");
 222.935 +
 222.936 +    if(path != NULL) {
 222.937 +      fprintf(stderr, "Searching PATH\n");
 222.938 +      strncpy(buffer, path, 4096);
 222.939 +      buffer[4095] = 0;
 222.940 +      char *tok = strtok(buffer, PATH_SEP);
 222.941 +      
 222.942 +      while(tok) {
 222.943 +        sprintf(path, "%s%c%s", tok, FILE_SEP, EXE_NAME);
 222.944 +        f = fopen(path, "r");
 222.945 +        if(f != NULL) {
 222.946 +          char path2[2048];
 222.947 +          fclose(f);
 222.948 +          sprintf(path2, "%s%c%s", tok, FILE_SEP, name);
 222.949 +          f = fopen(path2, "r");
 222.950 +          if(f != NULL) {
 222.951 +            fprintf(stderr, "Found at %s\n", path2);
 222.952 +            return f;
 222.953 +          }
 222.954 +        }
 222.955 +        tok = strtok(NULL, PATH_SEP);
 222.956 +      }
 222.957 +    }
 222.958 +  } else {
 222.959 +    // executable is relative to some directory
 222.960 +    fprintf(stderr, "Searching executable directory\n");
 222.961 +    strcpy(buffer, arg0);
 222.962 +    char *p = strrchr(buffer, FILE_SEP);
 222.963 +    if(p) {
 222.964 +      *p = 0;
 222.965 +      sprintf(path, "%s%c%s", buffer, FILE_SEP, name);
 222.966 +      f = fopen(path, "r");
 222.967 +      if(f != NULL)
 222.968 +        return f;
 222.969 +    }
 222.970 +  }
 222.971 +  return NULL;
 222.972 +}
 222.973 +
 222.974 +void sdlReadPreferences(FILE *f)
 222.975 +{
 222.976 +  char buffer[2048];
 222.977 +  
 222.978 +  while(1) {
 222.979 +    char *s = fgets(buffer, 2048, f);
 222.980 +
 222.981 +    if(s == NULL)
 222.982 +      break;
 222.983 +
 222.984 +    char *p  = strchr(s, '#');
 222.985 +    
 222.986 +    if(p)
 222.987 +      *p = 0;
 222.988 +    
 222.989 +    char *token = strtok(s, " \t\n\r=");
 222.990 +
 222.991 +    if(!token)
 222.992 +      continue;
 222.993 +
 222.994 +    if(strlen(token) == 0)
 222.995 +      continue;
 222.996 +
 222.997 +    char *key = token;
 222.998 +    char *value = strtok(NULL, "\t\n\r");
 222.999 +
222.1000 +    if(value == NULL) {
222.1001 +      fprintf(stderr, "Empty value for key %s\n", key);
222.1002 +      continue;
222.1003 +    }
222.1004 +
222.1005 +    if(!strcmp(key,"Joy0_Left")) {
222.1006 +      joypad[0][KEY_LEFT] = sdlFromHex(value);
222.1007 +    } else if(!strcmp(key, "Joy0_Right")) {
222.1008 +      joypad[0][KEY_RIGHT] = sdlFromHex(value);
222.1009 +    } else if(!strcmp(key, "Joy0_Up")) {
222.1010 +      joypad[0][KEY_UP] = sdlFromHex(value);
222.1011 +    } else if(!strcmp(key, "Joy0_Down")) {
222.1012 +      joypad[0][KEY_DOWN] = sdlFromHex(value);
222.1013 +    } else if(!strcmp(key, "Joy0_A")) {
222.1014 +      joypad[0][KEY_BUTTON_A] = sdlFromHex(value);
222.1015 +    } else if(!strcmp(key, "Joy0_B")) {
222.1016 +      joypad[0][KEY_BUTTON_B] = sdlFromHex(value);
222.1017 +    } else if(!strcmp(key, "Joy0_L")) {
222.1018 +      joypad[0][KEY_BUTTON_L] = sdlFromHex(value);
222.1019 +    } else if(!strcmp(key, "Joy0_R")) {
222.1020 +      joypad[0][KEY_BUTTON_R] = sdlFromHex(value);
222.1021 +    } else if(!strcmp(key, "Joy0_Start")) {
222.1022 +      joypad[0][KEY_BUTTON_START] = sdlFromHex(value);
222.1023 +    } else if(!strcmp(key, "Joy0_Select")) {
222.1024 +      joypad[0][KEY_BUTTON_SELECT] = sdlFromHex(value);
222.1025 +    } else if(!strcmp(key, "Joy0_Speed")) {
222.1026 +      joypad[0][KEY_BUTTON_SPEED] = sdlFromHex(value);
222.1027 +    } else if(!strcmp(key, "Joy0_Capture")) {
222.1028 +      joypad[0][KEY_BUTTON_CAPTURE] = sdlFromHex(value);
222.1029 +    } else if(!strcmp(key,"Joy1_Left")) {
222.1030 +      joypad[1][KEY_LEFT] = sdlFromHex(value);
222.1031 +    } else if(!strcmp(key, "Joy1_Right")) {
222.1032 +      joypad[1][KEY_RIGHT] = sdlFromHex(value);
222.1033 +    } else if(!strcmp(key, "Joy1_Up")) {
222.1034 +      joypad[1][KEY_UP] = sdlFromHex(value);
222.1035 +    } else if(!strcmp(key, "Joy1_Down")) {
222.1036 +      joypad[1][KEY_DOWN] = sdlFromHex(value);
222.1037 +    } else if(!strcmp(key, "Joy1_A")) {
222.1038 +      joypad[1][KEY_BUTTON_A] = sdlFromHex(value);
222.1039 +    } else if(!strcmp(key, "Joy1_B")) {
222.1040 +      joypad[1][KEY_BUTTON_B] = sdlFromHex(value);
222.1041 +    } else if(!strcmp(key, "Joy1_L")) {
222.1042 +      joypad[1][KEY_BUTTON_L] = sdlFromHex(value);
222.1043 +    } else if(!strcmp(key, "Joy1_R")) {
222.1044 +      joypad[1][KEY_BUTTON_R] = sdlFromHex(value);
222.1045 +    } else if(!strcmp(key, "Joy1_Start")) {
222.1046 +      joypad[1][KEY_BUTTON_START] = sdlFromHex(value);
222.1047 +    } else if(!strcmp(key, "Joy1_Select")) {
222.1048 +      joypad[1][KEY_BUTTON_SELECT] = sdlFromHex(value);
222.1049 +    } else if(!strcmp(key, "Joy1_Speed")) {
222.1050 +      joypad[1][KEY_BUTTON_SPEED] = sdlFromHex(value);
222.1051 +    } else if(!strcmp(key, "Joy1_Capture")) {
222.1052 +      joypad[1][KEY_BUTTON_CAPTURE] = sdlFromHex(value);
222.1053 +    } else if(!strcmp(key,"Joy2_Left")) {
222.1054 +      joypad[2][KEY_LEFT] = sdlFromHex(value);
222.1055 +    } else if(!strcmp(key, "Joy2_Right")) {
222.1056 +      joypad[2][KEY_RIGHT] = sdlFromHex(value);
222.1057 +    } else if(!strcmp(key, "Joy2_Up")) {
222.1058 +      joypad[2][KEY_UP] = sdlFromHex(value);
222.1059 +    } else if(!strcmp(key, "Joy2_Down")) {
222.1060 +      joypad[2][KEY_DOWN] = sdlFromHex(value);
222.1061 +    } else if(!strcmp(key, "Joy2_A")) {
222.1062 +      joypad[2][KEY_BUTTON_A] = sdlFromHex(value);
222.1063 +    } else if(!strcmp(key, "Joy2_B")) {
222.1064 +      joypad[2][KEY_BUTTON_B] = sdlFromHex(value);
222.1065 +    } else if(!strcmp(key, "Joy2_L")) {
222.1066 +      joypad[2][KEY_BUTTON_L] = sdlFromHex(value);
222.1067 +    } else if(!strcmp(key, "Joy2_R")) {
222.1068 +      joypad[2][KEY_BUTTON_R] = sdlFromHex(value);
222.1069 +    } else if(!strcmp(key, "Joy2_Start")) {
222.1070 +      joypad[2][KEY_BUTTON_START] = sdlFromHex(value);
222.1071 +    } else if(!strcmp(key, "Joy2_Select")) {
222.1072 +      joypad[2][KEY_BUTTON_SELECT] = sdlFromHex(value);
222.1073 +    } else if(!strcmp(key, "Joy2_Speed")) {
222.1074 +      joypad[2][KEY_BUTTON_SPEED] = sdlFromHex(value);
222.1075 +    } else if(!strcmp(key, "Joy2_Capture")) {
222.1076 +      joypad[2][KEY_BUTTON_CAPTURE] = sdlFromHex(value);
222.1077 +    } else if(!strcmp(key,"Joy4_Left")) {
222.1078 +      joypad[4][KEY_LEFT] = sdlFromHex(value);
222.1079 +    } else if(!strcmp(key, "Joy4_Right")) {
222.1080 +      joypad[4][KEY_RIGHT] = sdlFromHex(value);
222.1081 +    } else if(!strcmp(key, "Joy4_Up")) {
222.1082 +      joypad[4][KEY_UP] = sdlFromHex(value);
222.1083 +    } else if(!strcmp(key, "Joy4_Down")) {
222.1084 +      joypad[4][KEY_DOWN] = sdlFromHex(value);
222.1085 +    } else if(!strcmp(key, "Joy4_A")) {
222.1086 +      joypad[4][KEY_BUTTON_A] = sdlFromHex(value);
222.1087 +    } else if(!strcmp(key, "Joy4_B")) {
222.1088 +      joypad[4][KEY_BUTTON_B] = sdlFromHex(value);
222.1089 +    } else if(!strcmp(key, "Joy4_L")) {
222.1090 +      joypad[4][KEY_BUTTON_L] = sdlFromHex(value);
222.1091 +    } else if(!strcmp(key, "Joy4_R")) {
222.1092 +      joypad[4][KEY_BUTTON_R] = sdlFromHex(value);
222.1093 +    } else if(!strcmp(key, "Joy4_Start")) {
222.1094 +      joypad[4][KEY_BUTTON_START] = sdlFromHex(value);
222.1095 +    } else if(!strcmp(key, "Joy4_Select")) {
222.1096 +      joypad[4][KEY_BUTTON_SELECT] = sdlFromHex(value);
222.1097 +    } else if(!strcmp(key, "Joy4_Speed")) {
222.1098 +      joypad[4][KEY_BUTTON_SPEED] = sdlFromHex(value);
222.1099 +    } else if(!strcmp(key, "Joy4_Capture")) {
222.1100 +      joypad[4][KEY_BUTTON_CAPTURE] = sdlFromHex(value);
222.1101 +    } else if(!strcmp(key, "Motion_Left")) {
222.1102 +      motion[KEY_LEFT] = sdlFromHex(value);
222.1103 +    } else if(!strcmp(key, "Motion_Right")) {
222.1104 +      motion[KEY_RIGHT] = sdlFromHex(value);
222.1105 +    } else if(!strcmp(key, "Motion_Up")) {
222.1106 +      motion[KEY_UP] = sdlFromHex(value);
222.1107 +    } else if(!strcmp(key, "Motion_Down")) {
222.1108 +      motion[KEY_DOWN] = sdlFromHex(value);
222.1109 +    } else if(!strcmp(key, "frameSkip")) {
222.1110 +      frameSkip = sdlFromHex(value);
222.1111 +      if(frameSkip < 0 || frameSkip > 9)
222.1112 +        frameSkip = 2;
222.1113 +    } else if(!strcmp(key, "gbFrameSkip")) {
222.1114 +      gbFrameSkip = sdlFromHex(value);
222.1115 +      if(gbFrameSkip < 0 || gbFrameSkip > 9)
222.1116 +        gbFrameSkip = 0;      
222.1117 +    } else if(!strcmp(key, "video")) {
222.1118 +      sizeOption = sdlFromHex(value);
222.1119 +      if(sizeOption < 0 || sizeOption > 3)
222.1120 +        sizeOption = 1;
222.1121 +    } else if(!strcmp(key, "fullScreen")) {
222.1122 +      fullscreen = sdlFromHex(value) ? 1 : 0;
222.1123 +    } else if(!strcmp(key, "useBios")) {
222.1124 +      useBios = sdlFromHex(value) ? true : false;
222.1125 +    } else if(!strcmp(key, "skipBios")) {
222.1126 +      skipBios = sdlFromHex(value) ? true : false;
222.1127 +    } else if(!strcmp(key, "biosFile")) {
222.1128 +      strcpy(biosFileName, value);
222.1129 +    } else if(!strcmp(key, "filter")) {
222.1130 +      filter = sdlFromHex(value);
222.1131 +      if(filter < 0 || filter > 13)
222.1132 +        filter = 0;
222.1133 +    } else if(!strcmp(key, "disableStatus")) {
222.1134 +      disableStatusMessages = sdlFromHex(value) ? true : false;
222.1135 +    } else if(!strcmp(key, "borderOn")) {
222.1136 +      gbBorderOn = sdlFromHex(value) ? true : false;
222.1137 +    } else if(!strcmp(key, "borderAutomatic")) {
222.1138 +      gbBorderAutomatic = sdlFromHex(value) ? true : false;
222.1139 +    } else if(!strcmp(key, "emulatorType")) {
222.1140 +      gbEmulatorType = sdlFromHex(value);
222.1141 +      if(gbEmulatorType < 0 || gbEmulatorType > 5)
222.1142 +        gbEmulatorType = 1;
222.1143 +    } else if(!strcmp(key, "colorOption")) {
222.1144 +      gbColorOption = sdlFromHex(value) ? true : false;
222.1145 +    } else if(!strcmp(key, "captureDir")) {
222.1146 +      sdlCheckDirectory(value);
222.1147 +      strcpy(captureDir, value);
222.1148 +    } else if(!strcmp(key, "saveDir")) {
222.1149 +      sdlCheckDirectory(value);
222.1150 +      strcpy(saveDir, value);
222.1151 +    } else if(!strcmp(key, "batteryDir")) {
222.1152 +      sdlCheckDirectory(value);
222.1153 +      strcpy(batteryDir, value);
222.1154 +    } else if(!strcmp(key, "captureFormat")) {
222.1155 +      captureFormat = sdlFromHex(value);
222.1156 +    } else if(!strcmp(key, "soundQuality")) {
222.1157 +      soundQuality = sdlFromHex(value);
222.1158 +      switch(soundQuality) {
222.1159 +      case 1: break;
222.1160 +      default:
222.1161 +        fprintf(stderr, "The rerecording version will run only sound at highest quality. Defaulting to 44.1 KHz\n");
222.1162 +        soundQuality = 1;
222.1163 +        break;
222.1164 +      }
222.1165 +    } else if(!strcmp(key, "soundOff")) {
222.1166 +      soundOffFlag = sdlFromHex(value) ? true : false;
222.1167 +    } else if(!strcmp(key, "soundEnable")) {
222.1168 +      int res = sdlFromHex(value) & 0x30f;
222.1169 +      soundEnableChannels(res);
222.1170 +      soundDisableChannels(~res);
222.1171 +    } else if(!strcmp(key, "soundEcho")) {
222.1172 +      soundEcho = sdlFromHex(value) ? true : false;
222.1173 +    } else if(!strcmp(key, "soundLowPass")) {
222.1174 +      soundLowPass = sdlFromHex(value) ? true : false;
222.1175 +    } else if(!strcmp(key, "soundReverse")) {
222.1176 +      soundReverse = sdlFromHex(value) ? true : false;
222.1177 +    } else if(!strcmp(key, "soundVolume")) {
222.1178 +      soundVolume = sdlFromHex(value);
222.1179 +      if(soundVolume < 0 || soundVolume > 3)
222.1180 +        soundVolume = 0;
222.1181 +    } else if(!strcmp(key, "removeIntros")) {
222.1182 +      removeIntros = sdlFromHex(value) ? true : false;
222.1183 +    } else if(!strcmp(key, "saveType")) {
222.1184 +      cpuSaveType = sdlFromHex(value);
222.1185 +      if(cpuSaveType < 0 || cpuSaveType > 5)
222.1186 +        cpuSaveType = 0;
222.1187 +    } else if(!strcmp(key, "flashSize")) {
222.1188 +      sdlFlashSize = sdlFromHex(value);
222.1189 +      if(sdlFlashSize != 0 && sdlFlashSize != 1)
222.1190 +        sdlFlashSize = 0;
222.1191 +    } else if(!strcmp(key, "ifbType")) {
222.1192 +      ifbType = sdlFromHex(value);
222.1193 +      if(ifbType < 0 || ifbType > 2)
222.1194 +        ifbType = 0;
222.1195 +    } else if(!strcmp(key, "showSpeed")) {
222.1196 +      showSpeed = sdlFromHex(value);
222.1197 +      if(showSpeed < 0 || showSpeed > 2)
222.1198 +        showSpeed = 1;
222.1199 +    } else if(!strcmp(key, "showSpeedTransparent")) {
222.1200 +      showSpeedTransparent = sdlFromHex(value);
222.1201 +    } else if(!strcmp(key, "autoFrameSkip")) {
222.1202 +      autoFrameSkip = sdlFromHex(value);
222.1203 +    } else if(!strcmp(key, "throttle")) {
222.1204 +      throttle = sdlFromHex(value);
222.1205 +      if(throttle != 0 && (throttle < 5 || throttle > 1000))
222.1206 +        throttle = 0;
222.1207 +    } else if(!strcmp(key, "disableMMX")) {
222.1208 +#ifdef MMX
222.1209 +      cpu_mmx = sdlFromHex(value) ? false : true;
222.1210 +#endif
222.1211 +    } else if(!strcmp(key, "pauseWhenInactive")) {
222.1212 +      pauseWhenInactive = sdlFromHex(value) ? true : false;
222.1213 +    } else if(!strcmp(key, "agbPrint")) {
222.1214 +      sdlAgbPrint = sdlFromHex(value);
222.1215 +    } else if(!strcmp(key, "rtcEnabled")) {
222.1216 +      sdlRtcEnable = sdlFromHex(value);
222.1217 +    } else if(!strcmp(key, "rewindTimer")) {
222.1218 +      rewindTimer = sdlFromHex(value);
222.1219 +      if(rewindTimer < 0 || rewindTimer > 600)
222.1220 +        rewindTimer = 0;
222.1221 +      rewindTimer *= 6;  // convert value to 10 frames multiple
222.1222 +    } else if(!strcmp(key, "enhancedDetection")) {
222.1223 +      cpuEnhancedDetection = sdlFromHex(value) ? true : false;
222.1224 +    } else {
222.1225 +      fprintf(stderr, "Unknown configuration key %s\n", key);
222.1226 +    }
222.1227 +  }
222.1228 +}
222.1229 +
222.1230 +void sdlReadPreferences()
222.1231 +{
222.1232 +  FILE *f = sdlFindFile("VisualBoyAdvance.cfg");
222.1233 +
222.1234 +  if(f == NULL) {
222.1235 +    fprintf(stderr, "Configuration file NOT FOUND (using defaults)\n");
222.1236 +    return;
222.1237 +  } else
222.1238 +    fprintf(stderr, "Reading configuration file.\n");
222.1239 +
222.1240 +  sdlReadPreferences(f);
222.1241 +
222.1242 +  fclose(f);
222.1243 +}
222.1244 +
222.1245 +static void sdlApplyPerImagePreferences()
222.1246 +{
222.1247 +  FILE *f = sdlFindFile("vba-over.ini");
222.1248 +  if(!f) {
222.1249 +    fprintf(stderr, "vba-over.ini NOT FOUND (using emulator settings)\n");
222.1250 +    return;
222.1251 +  } else
222.1252 +    fprintf(stderr, "Reading vba-over.ini\n");
222.1253 +
222.1254 +  char buffer[7];
222.1255 +  buffer[0] = '[';
222.1256 +  buffer[1] = rom[0xac];
222.1257 +  buffer[2] = rom[0xad];
222.1258 +  buffer[3] = rom[0xae];
222.1259 +  buffer[4] = rom[0xaf];
222.1260 +  buffer[5] = ']';
222.1261 +  buffer[6] = 0;
222.1262 +
222.1263 +  char readBuffer[2048];
222.1264 +
222.1265 +  bool found = false;
222.1266 +  
222.1267 +  while(1) {
222.1268 +    char *s = fgets(readBuffer, 2048, f);
222.1269 +
222.1270 +    if(s == NULL)
222.1271 +      break;
222.1272 +
222.1273 +    char *p  = strchr(s, ';');
222.1274 +    
222.1275 +    if(p)
222.1276 +      *p = 0;
222.1277 +    
222.1278 +    char *token = strtok(s, " \t\n\r=");
222.1279 +
222.1280 +    if(!token)
222.1281 +      continue;
222.1282 +    if(strlen(token) == 0)
222.1283 +      continue;
222.1284 +
222.1285 +    if(!strcmp(token, buffer)) {
222.1286 +      found = true;
222.1287 +      break;
222.1288 +    }
222.1289 +  }
222.1290 +
222.1291 +  if(found) {
222.1292 +    while(1) {
222.1293 +      char *s = fgets(readBuffer, 2048, f);
222.1294 +
222.1295 +      if(s == NULL)
222.1296 +        break;
222.1297 +
222.1298 +      char *p = strchr(s, ';');
222.1299 +      if(p)
222.1300 +        *p = 0;
222.1301 +
222.1302 +      char *token = strtok(s, " \t\n\r=");
222.1303 +      if(!token)
222.1304 +        continue;
222.1305 +      if(strlen(token) == 0)
222.1306 +        continue;
222.1307 +
222.1308 +      if(token[0] == '[') // starting another image settings
222.1309 +        break;
222.1310 +      char *value = strtok(NULL, "\t\n\r=");
222.1311 +      if(value == NULL)
222.1312 +        continue;
222.1313 +      
222.1314 +      if(!strcmp(token, "rtcEnabled"))
222.1315 +        rtcEnable(atoi(value) == 0 ? false : true);
222.1316 +      else if(!strcmp(token, "flashSize")) {
222.1317 +        int size = atoi(value);
222.1318 +        if(size == 0x10000 || size == 0x20000)
222.1319 +          flashSetSize(size);
222.1320 +      } else if(!strcmp(token, "saveType")) {
222.1321 +        int save = atoi(value);
222.1322 +        if(save >= 0 && save <= 5)
222.1323 +          cpuSaveType = save;
222.1324 +      }
222.1325 +    }
222.1326 +  }
222.1327 +  fclose(f);
222.1328 +}
222.1329 +
222.1330 +static int sdlCalculateShift(u32 mask)
222.1331 +{
222.1332 +  int m = 0;
222.1333 +  
222.1334 +  while(mask) {
222.1335 +    m++;
222.1336 +    mask >>= 1;
222.1337 +  }
222.1338 +
222.1339 +  return m-5;
222.1340 +}
222.1341 +
222.1342 +static int sdlCalculateMaskWidth(u32 mask)
222.1343 +{
222.1344 +  int m = 0;
222.1345 +  int mask2 = mask;
222.1346 +
222.1347 +  while(mask2) {
222.1348 +    m++;
222.1349 +    mask2 >>= 1;
222.1350 +  }
222.1351 +
222.1352 +  int m2 = 0;
222.1353 +  mask2 = mask;
222.1354 +  while(!(mask2 & 1)) {
222.1355 +    m2++;
222.1356 +    mask2 >>= 1;
222.1357 +  }
222.1358 +
222.1359 +  return m - m2;
222.1360 +}
222.1361 +
222.1362 +void sdlWriteState(int num)
222.1363 +{
222.1364 +  char stateName[2048];
222.1365 +
222.1366 +  if(saveDir[0])
222.1367 +    sprintf(stateName, "%s/%s%d.sgm", saveDir, sdlGetFilename(filename),
222.1368 +            num+1);
222.1369 +  else
222.1370 +    sprintf(stateName,"%s%d.sgm", filename, num+1);
222.1371 +  if(theEmulator.emuWriteState)
222.1372 +    theEmulator.emuWriteState(stateName);
222.1373 +  sprintf(stateName, "Wrote state %d", num+1);
222.1374 +  systemScreenMessage(stateName);
222.1375 +}
222.1376 +
222.1377 +void sdlReadState(int num)
222.1378 +{
222.1379 +  char stateName[2048];
222.1380 +
222.1381 +  if(saveDir[0])
222.1382 +    sprintf(stateName, "%s/%s%d.sgm", saveDir, sdlGetFilename(filename),
222.1383 +            num+1);
222.1384 +  else
222.1385 +    sprintf(stateName,"%s%d.sgm", filename, num+1);
222.1386 +
222.1387 +  if(theEmulator.emuReadState)
222.1388 +    theEmulator.emuReadState(stateName);
222.1389 +
222.1390 +  sprintf(stateName, "Loaded state %d", num+1);
222.1391 +  systemScreenMessage(stateName);
222.1392 +}
222.1393 +
222.1394 +void sdlWriteBattery()
222.1395 +{
222.1396 +  char buffer[1048];
222.1397 +
222.1398 +  if(batteryDir[0])
222.1399 +    sprintf(buffer, "%s/%s.sav", batteryDir, sdlGetFilename(filename));
222.1400 +  else  
222.1401 +    sprintf(buffer, "%s.sav", filename);
222.1402 +
222.1403 +  theEmulator.emuWriteBattery(buffer);	
222.1404 +
222.1405 +  systemScreenMessage("Wrote battery");
222.1406 +}
222.1407 +
222.1408 +void sdlReadBattery()
222.1409 +{
222.1410 +  char buffer[1048];
222.1411 +  
222.1412 +  if(batteryDir[0])
222.1413 +    sprintf(buffer, "%s/%s.sav", batteryDir, sdlGetFilename(filename));
222.1414 +  else 
222.1415 +    sprintf(buffer, "%s.sav", filename);
222.1416 +  
222.1417 +  bool res = false;
222.1418 +
222.1419 +  res = theEmulator.emuReadBattery(buffer);
222.1420 +
222.1421 +  if(res)
222.1422 +    systemScreenMessage("Loaded battery");
222.1423 +}
222.1424 +
222.1425 +#define MOD_KEYS    (KMOD_CTRL|KMOD_SHIFT|KMOD_ALT|KMOD_META)
222.1426 +#define MOD_NOCTRL  (KMOD_SHIFT|KMOD_ALT|KMOD_META)
222.1427 +#define MOD_NOALT   (KMOD_CTRL|KMOD_SHIFT|KMOD_META)
222.1428 +#define MOD_NOSHIFT (KMOD_CTRL|KMOD_ALT|KMOD_META)
222.1429 +
222.1430 +void sdlUpdateKey(int key, bool down)
222.1431 +{
222.1432 +  int i;
222.1433 +  for(int j = 0; j < 4; j++) {
222.1434 +    for(i = 0 ; i < 12; i++) {
222.1435 +      if((joypad[j][i] & 0xf000) == 0) {
222.1436 +        if(key == joypad[j][i])
222.1437 +          if (down) currentButtons[j] |= 1<<i;
222.1438 +          else currentButtons[j] ^= 1<<i;
222.1439 +      }
222.1440 +    }
222.1441 +  }
222.1442 +  for(i = 0 ; i < 4; i++) {
222.1443 +    if((motion[i] & 0xf000) == 0) {
222.1444 +      if(key == motion[i])
222.1445 +        sdlMotionButtons[i] = down;
222.1446 +    }
222.1447 +  }
222.1448 +}
222.1449 +
222.1450 +void sdlUpdateJoyButton(int which,
222.1451 +                        int button,
222.1452 +                        bool pressed)
222.1453 +{
222.1454 +  int i;
222.1455 +  for(int j = 0; j < 4; j++) {
222.1456 +    for(i = 0; i < 12; i++) {
222.1457 +      int dev = (joypad[j][i] >> 12);
222.1458 +      int b = joypad[j][i] & 0xfff;
222.1459 +      if(dev) {
222.1460 +        dev--;
222.1461 +        
222.1462 +        if((dev == which) && (b >= 128) && (b == (button+128))) {
222.1463 +          if (pressed) currentButtons[j] |= 1<<i;
222.1464 +          else currentButtons[j] ^= 1<<i;
222.1465 +        }
222.1466 +      }
222.1467 +    }
222.1468 +  }
222.1469 +  for(i = 0; i < 4; i++) {
222.1470 +    int dev = (motion[i] >> 12);
222.1471 +    int b = motion[i] & 0xfff;
222.1472 +    if(dev) {
222.1473 +      dev--;
222.1474 +
222.1475 +      if((dev == which) && (b >= 128) && (b == (button+128))) {
222.1476 +        sdlMotionButtons[i] = pressed;
222.1477 +      }
222.1478 +    }
222.1479 +  }  
222.1480 +}
222.1481 +
222.1482 +void sdlUpdateJoyHat(int which,
222.1483 +                     int hat,
222.1484 +                     int value)
222.1485 +{
222.1486 +  int i;
222.1487 +  for(int j = 0; j < 4; j++) {
222.1488 +    for(i = 0; i < 12; i++) {
222.1489 +      int dev = (joypad[j][i] >> 12);
222.1490 +      int a = joypad[j][i] & 0xfff;
222.1491 +      if(dev) {
222.1492 +        dev--;
222.1493 +        
222.1494 +        if((dev == which) && (a>=32) && (a < 48) && (((a&15)>>2) == hat)) {
222.1495 +          int dir = a & 3;
222.1496 +          int v = 0;
222.1497 +          switch(dir) {
222.1498 +          case 0:
222.1499 +            v = value & SDL_HAT_UP;
222.1500 +            break;
222.1501 +          case 1:
222.1502 +            v = value & SDL_HAT_DOWN;
222.1503 +            break;
222.1504 +          case 2:
222.1505 +            v = value & SDL_HAT_RIGHT;
222.1506 +            break;
222.1507 +          case 3:
222.1508 +            v = value & SDL_HAT_LEFT;
222.1509 +            break;
222.1510 +          }
222.1511 +          if (v) currentButtons[j] |= 1<<i;
222.1512 +          else currentButtons[j] ^= 1<<i;
222.1513 +        }
222.1514 +      }
222.1515 +    }
222.1516 +  }
222.1517 +  for(i = 0; i < 4; i++) {
222.1518 +    int dev = (motion[i] >> 12);
222.1519 +    int a = motion[i] & 0xfff;
222.1520 +    if(dev) {
222.1521 +      dev--;
222.1522 +
222.1523 +      if((dev == which) && (a>=32) && (a < 48) && (((a&15)>>2) == hat)) {
222.1524 +        int dir = a & 3;
222.1525 +        int v = 0;
222.1526 +        switch(dir) {
222.1527 +        case 0:
222.1528 +          v = value & SDL_HAT_UP;
222.1529 +          break;
222.1530 +        case 1:
222.1531 +          v = value & SDL_HAT_DOWN;
222.1532 +          break;
222.1533 +        case 2:
222.1534 +          v = value & SDL_HAT_RIGHT;
222.1535 +          break;
222.1536 +        case 3:
222.1537 +          v = value & SDL_HAT_LEFT;
222.1538 +          break;
222.1539 +        }
222.1540 +        sdlMotionButtons[i] = (v ? true : false);
222.1541 +      }
222.1542 +    }
222.1543 +  }      
222.1544 +}
222.1545 +
222.1546 +void sdlUpdateJoyAxis(int which,
222.1547 +                      int axis,
222.1548 +                      int value)
222.1549 +{
222.1550 +  int i;
222.1551 +  for(int j = 0; j < 4; j++) {
222.1552 +    for(i = 0; i < 12; i++) {
222.1553 +      int dev = (joypad[j][i] >> 12);
222.1554 +      int a = joypad[j][i] & 0xfff;
222.1555 +      if(dev) {
222.1556 +        dev--;
222.1557 +        
222.1558 +        if((dev == which) && (a < 32) && ((a>>1) == axis)) {
222.1559 +	  //I have no idea what this does, is this reimplementation correct? --Felipe
222.1560 +	  if (value>16384) {
222.1561 +	  	if (a&1) currentButtons[j] |= 1<<i;
222.1562 +	  	else currentButtons[j] ^= 1<<i;
222.1563 +	  }
222.1564 +          else if (value<16384){
222.1565 +          	if (a&1) currentButtons[j] ^= 1<<i;
222.1566 +          	else currentButtons[j] |= 1<<i;
222.1567 +          }
222.1568 +        }
222.1569 +      }
222.1570 +    }
222.1571 +  }
222.1572 +  for(i = 0; i < 4; i++) {
222.1573 +    int dev = (motion[i] >> 12);
222.1574 +    int a = motion[i] & 0xfff;
222.1575 +    if(dev) {
222.1576 +      dev--;
222.1577 +
222.1578 +      if((dev == which) && (a < 32) && ((a>>1) == axis)) {
222.1579 +        sdlMotionButtons[i] = (a & 1) ? (value > 16384) : (value < -16384);
222.1580 +      }
222.1581 +    }
222.1582 +  }  
222.1583 +}
222.1584 +
222.1585 +bool sdlCheckJoyKey(int key)
222.1586 +{
222.1587 +  int dev = (key >> 12) - 1;
222.1588 +  int what = key & 0xfff;
222.1589 +
222.1590 +  if(what >= 128) {
222.1591 +    // joystick button
222.1592 +    int button = what - 128;
222.1593 +
222.1594 +    if(button >= SDL_JoystickNumButtons(sdlDevices[dev]))
222.1595 +      return false;
222.1596 +  } else if (what < 0x20) {
222.1597 +    // joystick axis    
222.1598 +    what >>= 1;
222.1599 +    if(what >= SDL_JoystickNumAxes(sdlDevices[dev]))
222.1600 +      return false;
222.1601 +  } else if (what < 0x30) {
222.1602 +    // joystick hat
222.1603 +    what = (what & 15);
222.1604 +    what >>= 2;
222.1605 +    if(what >= SDL_JoystickNumHats(sdlDevices[dev]))
222.1606 +      return false;
222.1607 +  }
222.1608 +
222.1609 +  // no problem found
222.1610 +  return true;
222.1611 +}
222.1612 +
222.1613 +void sdlCheckKeys()
222.1614 +{
222.1615 +  sdlNumDevices = SDL_NumJoysticks();
222.1616 +
222.1617 +  if(sdlNumDevices)
222.1618 +    sdlDevices = (SDL_Joystick **)calloc(1,sdlNumDevices *
222.1619 +                                         sizeof(SDL_Joystick **));
222.1620 +  int i;
222.1621 +
222.1622 +  bool usesJoy = false;
222.1623 +
222.1624 +  for(int j = 0; j < 4; j++) {
222.1625 +    for(i = 0; i < 12; i++) {
222.1626 +      int dev = joypad[j][i] >> 12;
222.1627 +      if(dev) {
222.1628 +        dev--;
222.1629 +        bool ok = false;
222.1630 +        
222.1631 +        if(sdlDevices) {
222.1632 +          if(dev < sdlNumDevices) {
222.1633 +            if(sdlDevices[dev] == NULL) {
222.1634 +              sdlDevices[dev] = SDL_JoystickOpen(dev);
222.1635 +            }
222.1636 +            
222.1637 +            ok = sdlCheckJoyKey(joypad[j][i]);
222.1638 +          } else
222.1639 +            ok = false;
222.1640 +        }
222.1641 +        
222.1642 +        if(!ok)
222.1643 +          joypad[j][i] = defaultJoypad[i];
222.1644 +        else
222.1645 +          usesJoy = true;
222.1646 +      }
222.1647 +    }
222.1648 +  }
222.1649 +
222.1650 +  for(i = 0; i < 4; i++) {
222.1651 +    int dev = motion[i] >> 12;
222.1652 +    if(dev) {
222.1653 +      dev--;
222.1654 +      bool ok = false;
222.1655 +      
222.1656 +      if(sdlDevices) {
222.1657 +        if(dev < sdlNumDevices) {
222.1658 +          if(sdlDevices[dev] == NULL) {
222.1659 +            sdlDevices[dev] = SDL_JoystickOpen(dev);
222.1660 +          }
222.1661 +          
222.1662 +          ok = sdlCheckJoyKey(motion[i]);
222.1663 +        } else
222.1664 +          ok = false;
222.1665 +      }
222.1666 +      
222.1667 +      if(!ok)
222.1668 +        motion[i] = defaultMotion[i];
222.1669 +      else
222.1670 +        usesJoy = true;
222.1671 +    }
222.1672 +  }
222.1673 +
222.1674 +  if(usesJoy)
222.1675 +    SDL_JoystickEventState(SDL_ENABLE);
222.1676 +}
222.1677 +
222.1678 +void sdlPollEvents()
222.1679 +{
222.1680 +  SDL_Event event;
222.1681 +  while(SDL_PollEvent(&event)) {
222.1682 +    switch(event.type) {
222.1683 +    case SDL_QUIT:
222.1684 +      emulating = 0;
222.1685 +      break;
222.1686 +    case SDL_ACTIVEEVENT:
222.1687 +      if(pauseWhenInactive && (event.active.state & SDL_APPINPUTFOCUS)) {
222.1688 +        active = event.active.gain;
222.1689 +        if(active) {
222.1690 +          if(!paused) {
222.1691 +            if(emulating)
222.1692 +              soundResume();
222.1693 +          }
222.1694 +        } else {
222.1695 +          wasPaused = true;
222.1696 +          if(pauseWhenInactive) {
222.1697 +            if(emulating)
222.1698 +              soundPause();
222.1699 +          }
222.1700 +          
222.1701 +          memset(delta,255,sizeof(delta));
222.1702 +        }
222.1703 +      }
222.1704 +      break;
222.1705 +    case SDL_MOUSEMOTION:
222.1706 +    case SDL_MOUSEBUTTONUP:
222.1707 +    case SDL_MOUSEBUTTONDOWN:
222.1708 +      if(fullscreen) {
222.1709 +        SDL_ShowCursor(SDL_ENABLE);
222.1710 +        mouseCounter = 120;
222.1711 +      }
222.1712 +      break;
222.1713 +    case SDL_JOYHATMOTION:
222.1714 +      sdlUpdateJoyHat(event.jhat.which,
222.1715 +                      event.jhat.hat,
222.1716 +                      event.jhat.value);
222.1717 +      break;
222.1718 +    case SDL_JOYBUTTONDOWN:
222.1719 +    case SDL_JOYBUTTONUP:
222.1720 +      sdlUpdateJoyButton(event.jbutton.which,
222.1721 +                         event.jbutton.button,
222.1722 +                         event.jbutton.state == SDL_PRESSED);
222.1723 +      break;
222.1724 +    case SDL_JOYAXISMOTION:
222.1725 +      sdlUpdateJoyAxis(event.jaxis.which,
222.1726 +                       event.jaxis.axis,
222.1727 +                       event.jaxis.value);
222.1728 +      break;
222.1729 +    case SDL_KEYDOWN:
222.1730 +      sdlUpdateKey(event.key.keysym.sym, true);
222.1731 +      break;
222.1732 +    case SDL_KEYUP:
222.1733 +      switch(event.key.keysym.sym) {
222.1734 +      case SDLK_r:
222.1735 +        if(!(event.key.keysym.mod & MOD_NOCTRL) &&
222.1736 +           (event.key.keysym.mod & KMOD_CTRL)) {
222.1737 +          if(emulating) {
222.1738 +            theEmulator.emuReset(true);
222.1739 +
222.1740 +            systemScreenMessage("Reset");
222.1741 +          }
222.1742 +        }
222.1743 +        break;
222.1744 +      case SDLK_b:
222.1745 +        if(!(event.key.keysym.mod & MOD_NOCTRL) &&
222.1746 +           (event.key.keysym.mod & KMOD_CTRL)) {
222.1747 +          if(emulating && theEmulator.emuReadMemState && rewindMemory 
222.1748 +             && rewindCount) {
222.1749 +            rewindPos = --rewindPos & 7;
222.1750 +            theEmulator.emuReadMemState(&rewindMemory[REWIND_SIZE*rewindPos], 
222.1751 +                                     REWIND_SIZE);
222.1752 +            rewindCount--;
222.1753 +            rewindCounter = 0;
222.1754 +            systemScreenMessage("Rewind");
222.1755 +          }
222.1756 +        }
222.1757 +        break;
222.1758 +      case SDLK_p:
222.1759 +        if(!(event.key.keysym.mod & MOD_NOCTRL) &&
222.1760 +           (event.key.keysym.mod & KMOD_CTRL)) {
222.1761 +          paused = !paused;
222.1762 +          SDL_PauseAudio(paused);
222.1763 +          if(paused)
222.1764 +            wasPaused = true;
222.1765 +        }
222.1766 +        break;
222.1767 +      case SDLK_ESCAPE:
222.1768 +        emulating = 0;
222.1769 +        break;
222.1770 +      case SDLK_f:
222.1771 +        if(!(event.key.keysym.mod & MOD_NOCTRL) &&
222.1772 +           (event.key.keysym.mod & KMOD_CTRL)) {
222.1773 +          int flags = 0;
222.1774 +          fullscreen = !fullscreen;
222.1775 +          if(fullscreen)
222.1776 +            flags |= SDL_FULLSCREEN;
222.1777 +          SDL_SetVideoMode(destWidth, destHeight, systemColorDepth, flags);
222.1778 +          //          if(SDL_WM_ToggleFullScreen(surface))
222.1779 +          //            fullscreen = !fullscreen;
222.1780 +        }
222.1781 +        break;
222.1782 +      case SDLK_F11:
222.1783 +        if(dbgMain != debuggerMain) {
222.1784 +          if(armState) {
222.1785 +            armNextPC -= 4;
222.1786 +            reg[15].I -= 4;
222.1787 +          } else {
222.1788 +            armNextPC -= 2;
222.1789 +            reg[15].I -= 2;
222.1790 +          }
222.1791 +        }
222.1792 +        debugger = true;
222.1793 +        break;
222.1794 +      case SDLK_F1:
222.1795 +      case SDLK_F2:
222.1796 +      case SDLK_F3:
222.1797 +      case SDLK_F4:
222.1798 +      case SDLK_F5:
222.1799 +      case SDLK_F6:
222.1800 +      case SDLK_F7:
222.1801 +      case SDLK_F8:
222.1802 +      case SDLK_F9:
222.1803 +      case SDLK_F10:
222.1804 +        if(!(event.key.keysym.mod & MOD_NOSHIFT) &&
222.1805 +           (event.key.keysym.mod & KMOD_SHIFT)) {
222.1806 +          sdlWriteState(event.key.keysym.sym-SDLK_F1);
222.1807 +        } else if(!(event.key.keysym.mod & MOD_KEYS)) {
222.1808 +          sdlReadState(event.key.keysym.sym-SDLK_F1);
222.1809 +        }
222.1810 +        break;
222.1811 +      case SDLK_1:
222.1812 +      case SDLK_2:
222.1813 +      case SDLK_3:
222.1814 +      case SDLK_4:
222.1815 +        if(!(event.key.keysym.mod & MOD_NOALT) &&
222.1816 +           (event.key.keysym.mod & KMOD_ALT)) {
222.1817 +          char *disableMessages[4] = 
222.1818 +            { "autofire A disabled",
222.1819 +              "autofire B disabled",
222.1820 +              "autofire R disabled",
222.1821 +              "autofire L disabled"};
222.1822 +          char *enableMessages[4] = 
222.1823 +            { "autofire A",
222.1824 +              "autofire B",
222.1825 +              "autofire R",
222.1826 +              "autofire L"};
222.1827 +          int mask = 1 << (event.key.keysym.sym - SDLK_1);
222.1828 +    if(event.key.keysym.sym > SDLK_2)
222.1829 +      mask <<= 6;
222.1830 +          if(autoFire & mask) {
222.1831 +            autoFire &= ~mask;
222.1832 +            systemScreenMessage(disableMessages[event.key.keysym.sym - SDLK_1]);
222.1833 +          } else {
222.1834 +            autoFire |= mask;
222.1835 +            systemScreenMessage(enableMessages[event.key.keysym.sym - SDLK_1]);
222.1836 +          }
222.1837 +        } if(!(event.key.keysym.mod & MOD_NOCTRL) &&
222.1838 +             (event.key.keysym.mod & KMOD_CTRL)) {
222.1839 +          int mask = 0x0100 << (event.key.keysym.sym - SDLK_1);
222.1840 +          layerSettings ^= mask;
222.1841 +          layerEnable = DISPCNT & layerSettings;
222.1842 +          CPUUpdateRenderBuffers(false);
222.1843 +        }
222.1844 +        break;
222.1845 +      case SDLK_5:
222.1846 +      case SDLK_6:
222.1847 +      case SDLK_7:
222.1848 +      case SDLK_8:
222.1849 +        if(!(event.key.keysym.mod & MOD_NOCTRL) &&
222.1850 +           (event.key.keysym.mod & KMOD_CTRL)) {
222.1851 +          int mask = 0x0100 << (event.key.keysym.sym - SDLK_1);
222.1852 +          layerSettings ^= mask;
222.1853 +          layerEnable = DISPCNT & layerSettings;
222.1854 +        }
222.1855 +        break;
222.1856 +      case SDLK_n:
222.1857 +        if(!(event.key.keysym.mod & MOD_NOCTRL) &&
222.1858 +           (event.key.keysym.mod & KMOD_CTRL)) {
222.1859 +          if(paused)
222.1860 +            paused = false;
222.1861 +          pauseNextFrame = true;
222.1862 +        }
222.1863 +        break;
222.1864 +      default:
222.1865 +        break;
222.1866 +      }
222.1867 +      sdlUpdateKey(event.key.keysym.sym, false);
222.1868 +      break;
222.1869 +    }
222.1870 +  }
222.1871 +}
222.1872 +
222.1873 +void usage(char *cmd)
222.1874 +{
222.1875 +  printf("%s [option ...] file\n", cmd);
222.1876 +  printf("\
222.1877 +\n\
222.1878 +Options:\n\
222.1879 +  -1, --video-1x               1x\n\
222.1880 +  -2, --video-2x               2x\n\
222.1881 +  -3, --video-3x               3x\n\
222.1882 +  -4, --video-4x               4x\n\
222.1883 +  -F, --fullscreen             Full screen\n\
222.1884 +  -G, --gdb=PROTOCOL           GNU Remote Stub mode:\n\
222.1885 +                                tcp      - use TCP at port 55555\n\
222.1886 +                                tcp:PORT - use TCP at port PORT\n\
222.1887 +                                pipe     - use pipe transport\n\
222.1888 +  -N, --no-debug               Don't parse debug information\n\
222.1889 +  -S, --flash-size=SIZE        Set the Flash size\n\
222.1890 +      --flash-64k               0 -  64K Flash\n\
222.1891 +      --flash-128k              1 - 128K Flash\n\
222.1892 +  -T, --throttle=THROTTLE      Set the desired throttle (5...1000)\n\
222.1893 +  -Y, --yuv=TYPE               Use YUV overlay for drawing:\n\
222.1894 +                                0 - YV12\n\
222.1895 +                                1 - UYVY\n\
222.1896 +                                2 - YVYU\n\
222.1897 +                                3 - YUY2\n\
222.1898 +                                4 - IYUV\n\
222.1899 +  -b, --bios=BIOS              Use given bios file\n\
222.1900 +  -c, --config=FILE            Read the given configuration file\n\
222.1901 +  -d, --debug                  Enter debugger\n\
222.1902 +  -f, --filter=FILTER          Select filter:\n\
222.1903 +      --filter-normal            0 - normal mode\n\
222.1904 +      --filter-tv-mode           1 - TV Mode\n\
222.1905 +      --filter-2xsai             2 - 2xSaI\n\
222.1906 +      --filter-super-2xsai       3 - Super 2xSaI\n\
222.1907 +      --filter-super-eagle       4 - Super Eagle\n\
222.1908 +      --filter-pixelate          5 - Pixelate\n\
222.1909 +      --filter-motion-blur       6 - Motion Blur\n\
222.1910 +      --filter-advmame           7 - AdvanceMAME Scale2x\n\
222.1911 +      --filter-simple2x          8 - Simple2x\n\
222.1912 +      --filter-bilinear          9 - Bilinear\n\
222.1913 +      --filter-bilinear+        10 - Bilinear Plus\n\
222.1914 +      --filter-scanlines        11 - Scanlines\n\
222.1915 +      --filter-hq2x             12 - hq2x\n\
222.1916 +      --filter-lq2x             13 - lq2x\n\
222.1917 +  -h, --help                   Print this help\n\
222.1918 +  -i, --ips=PATCH              Apply given IPS patch\n\
222.1919 +  -P, --profile=[HERTZ]        Enable profiling\n\
222.1920 +  -s, --frameskip=FRAMESKIP    Set frame skip (0...9)\n\
222.1921 +");
222.1922 +  printf("\
222.1923 +  -t, --save-type=TYPE         Set the available save type\n\
222.1924 +      --save-auto               0 - Automatic (EEPROM, SRAM, FLASH)\n\
222.1925 +      --save-eeprom             1 - EEPROM\n\
222.1926 +      --save-sram               2 - SRAM\n\
222.1927 +      --save-flash              3 - FLASH\n\
222.1928 +      --save-sensor             4 - EEPROM+Sensor\n\
222.1929 +      --save-none               5 - NONE\n\
222.1930 +  -v, --verbose=VERBOSE        Set verbose logging (trace.log)\n\
222.1931 +                                  1 - SWI\n\
222.1932 +                                  2 - Unaligned memory access\n\
222.1933 +                                  4 - Illegal memory write\n\
222.1934 +                                  8 - Illegal memory read\n\
222.1935 +                                 16 - DMA 0\n\
222.1936 +                                 32 - DMA 1\n\
222.1937 +                                 64 - DMA 2\n\
222.1938 +                                128 - DMA 3\n\
222.1939 +                                256 - Undefined instruction\n\
222.1940 +                                512 - AGBPrint messages\n\
222.1941 +\n\
222.1942 +Long options only:\n\
222.1943 +      --agb-print              Enable AGBPrint support\n\
222.1944 +      --auto-frameskip         Enable auto frameskipping\n\
222.1945 +      --ifb-none               No interframe blending\n\
222.1946 +      --ifb-motion-blur        Interframe motion blur\n\
222.1947 +      --ifb-smart              Smart interframe blending\n\
222.1948 +      --no-agb-print           Disable AGBPrint support\n\
222.1949 +      --no-auto-frameskip      Disable auto frameskipping\n\
222.1950 +      --no-ips                 Do not apply IPS patch\n\
222.1951 +      --no-mmx                 Disable MMX support\n\
222.1952 +      --no-pause-when-inactive Don't pause when inactive\n\
222.1953 +      --no-rtc                 Disable RTC support\n\
222.1954 +      --no-show-speed          Don't show emulation speed\n\
222.1955 +      --no-throttle            Disable thrrotle\n\
222.1956 +      --pause-when-inactive    Pause when inactive\n\
222.1957 +      --rtc                    Enable RTC support\n\
222.1958 +      --show-speed-normal      Show emulation speed\n\
222.1959 +      --show-speed-detailed    Show detailed speed data\n\
222.1960 +");
222.1961 +  printf("\
222.1962 +  -r, --recordmovie=filename   Start recording input movie\n\
222.1963 +  -p, --playmovie=filename   Play input movie non-read-only\n\
222.1964 +  -w, --watchmovie=filename   Play input movie in read-only mode\n\
222.1965 +");
222.1966 +}
222.1967 +
222.1968 +static char *szFile;
222.1969 +
222.1970 +void file_run()
222.1971 +{
222.1972 +    utilGetBaseName(szFile, filename);
222.1973 +    char *p = strrchr(filename, '.');
222.1974 +
222.1975 +    if(p)
222.1976 +      *p = 0;
222.1977 +
222.1978 +    if(ipsname[0] == 0)
222.1979 +      sprintf(ipsname, "%s.ips", filename);
222.1980 +    
222.1981 +    bool failed = false;
222.1982 +
222.1983 +    IMAGE_TYPE type = utilFindType(szFile);
222.1984 +
222.1985 +    if(type == IMAGE_UNKNOWN) {
222.1986 +      systemMessage(0, "Unknown file type %s", szFile);
222.1987 +      exit(-1);
222.1988 +    }
222.1989 +    systemCartridgeType = (int)type;
222.1990 +
222.1991 +    if(type == IMAGE_GB) {
222.1992 +      failed = !gbLoadRom(szFile);
222.1993 +      if(!failed) {
222.1994 +        systemCartridgeType = 1;
222.1995 +        theEmulator = GBSystem;
222.1996 +        if(sdlAutoIPS) {
222.1997 +          int size = gbRomSize;
222.1998 +          utilApplyIPS(ipsname, &gbRom, &size);
222.1999 +          if(size != gbRomSize) {
222.2000 +            extern bool gbUpdateSizes();
222.2001 +            gbUpdateSizes();
222.2002 +            gbReset();
222.2003 +          }
222.2004 +        }
222.2005 +      }
222.2006 +    } else if(type == IMAGE_GBA) {
222.2007 +      int size = CPULoadRom(szFile);
222.2008 +      failed = (size == 0);
222.2009 +      if(!failed) {
222.2010 +        //        if(cpuEnhancedDetection && cpuSaveType == 0) {
222.2011 +        //          utilGBAFindSave(rom, size);
222.2012 +        //        }
222.2013 +
222.2014 +        sdlApplyPerImagePreferences();
222.2015 +        
222.2016 +        systemCartridgeType = 0;
222.2017 +        theEmulator = GBASystem;
222.2018 +
222.2019 +        /* disabled due to problems
222.2020 +        if(removeIntros && rom != NULL) {
222.2021 +          WRITE32LE(&rom[0], 0xea00002e);
222.2022 +        }
222.2023 +        */
222.2024 +        
222.2025 +        //CPUInit(biosFileName, useBios);
222.2026 +	CPUInit();
222.2027 +        CPUReset();
222.2028 +        if(sdlAutoIPS) {
222.2029 +          int size = 0x2000000;
222.2030 +          utilApplyIPS(ipsname, &rom, &size);
222.2031 +          if(size != 0x2000000) {
222.2032 +            CPUReset();
222.2033 +          }
222.2034 +        }
222.2035 +      }
222.2036 +    }
222.2037 +    
222.2038 +    if(failed) {
222.2039 +      systemMessage(0, "Failed to load file %s", szFile);
222.2040 +      exit(-1);
222.2041 +    }
222.2042 +  
222.2043 +  emulating = 1;
222.2044 +  renderedFrames = 0;
222.2045 +  }
222.2046 +
222.2047 +int main(int argc, char **argv)
222.2048 +{
222.2049 +  fprintf(stderr, "VisualBoyAdvance version %s [SDL]\n", VERSION);
222.2050 +
222.2051 +  arg0 = argv[0];
222.2052 +  
222.2053 +  captureDir[0] = 0;
222.2054 +  saveDir[0] = 0;
222.2055 +  batteryDir[0] = 0;
222.2056 +  ipsname[0] = 0;
222.2057 +  
222.2058 +  int op = -1;
222.2059 +
222.2060 +  frameSkip = 2;
222.2061 +  gbBorderOn = 0;
222.2062 +
222.2063 +  parseDebug = true;
222.2064 +
222.2065 +  sdlReadPreferences();
222.2066 +
222.2067 +  sdlPrintUsage = 0;
222.2068 +  
222.2069 +  while((op = getopt_long(argc,
222.2070 +                          argv,
222.2071 +                          "FNT:Y:G:D:b:c:df:hi:p::s:t:v:1234",
222.2072 +                          sdlOptions,
222.2073 +                          NULL)) != -1) {
222.2074 +    switch(op) {
222.2075 +    case 0:
222.2076 +      // long option already processed by getopt_long
222.2077 +      break;
222.2078 +    case 'b':
222.2079 +      useBios = true;
222.2080 +      if(optarg == NULL) {
222.2081 +        fprintf(stderr, "Missing BIOS file name\n");
222.2082 +        exit(-1);
222.2083 +      }
222.2084 +      strcpy(biosFileName, optarg);
222.2085 +      break;
222.2086 +    case 'c':
222.2087 +      {
222.2088 +        if(optarg == NULL) {
222.2089 +          fprintf(stderr, "Missing config file name\n");
222.2090 +          exit(-1);
222.2091 +        }
222.2092 +        FILE *f = fopen(optarg, "r");
222.2093 +        if(f == NULL) {
222.2094 +          fprintf(stderr, "File not found %s\n", optarg);
222.2095 +          exit(-1);
222.2096 +        }
222.2097 +        sdlReadPreferences(f);
222.2098 +        fclose(f);
222.2099 +      }
222.2100 +      break;
222.2101 +    case 'd':
222.2102 +      debugger = true;
222.2103 +      break;
222.2104 +    case 'h':
222.2105 +      sdlPrintUsage = 1;
222.2106 +      break;
222.2107 +    case 'i':
222.2108 +      if(optarg == NULL) {
222.2109 +        fprintf(stderr, "Missing IPS name\n");
222.2110 +        exit(-1);
222.2111 +        strcpy(ipsname, optarg);
222.2112 +      }
222.2113 +      break;
222.2114 +    case 'Y':
222.2115 +      yuv = true;
222.2116 +      if(optarg) {
222.2117 +        yuvType = atoi(optarg);
222.2118 +        switch(yuvType) {
222.2119 +        case 0:
222.2120 +          yuvType = SDL_YV12_OVERLAY;
222.2121 +          break;
222.2122 +        case 1:
222.2123 +          yuvType = SDL_UYVY_OVERLAY;
222.2124 +          break;
222.2125 +        case 2:
222.2126 +          yuvType = SDL_YVYU_OVERLAY;
222.2127 +          break;
222.2128 +        case 3:
222.2129 +          yuvType = SDL_YUY2_OVERLAY;
222.2130 +          break;
222.2131 +        case 4:
222.2132 +          yuvType = SDL_IYUV_OVERLAY;
222.2133 +          break;
222.2134 +        default:
222.2135 +          yuvType = SDL_YV12_OVERLAY;
222.2136 +        }
222.2137 +      } else
222.2138 +        yuvType = SDL_YV12_OVERLAY;
222.2139 +      break;
222.2140 +    case 'G':
222.2141 +      dbgMain = remoteStubMain;
222.2142 +      dbgSignal = remoteStubSignal;
222.2143 +      dbgOutput = remoteOutput;
222.2144 +      debugger = true;
222.2145 +      debuggerStub = true;
222.2146 +      if(optarg) {
222.2147 +        char *s = optarg;
222.2148 +        if(strncmp(s,"tcp:", 4) == 0) {
222.2149 +          s+=4;
222.2150 +          int port = atoi(s);
222.2151 +          remoteSetProtocol(0);
222.2152 +          remoteSetPort(port);
222.2153 +        } else if(strcmp(s,"tcp") == 0) {
222.2154 +          remoteSetProtocol(0);
222.2155 +        } else if(strcmp(s, "pipe") == 0) {
222.2156 +          remoteSetProtocol(1);
222.2157 +        } else {
222.2158 +          fprintf(stderr, "Unknown protocol %s\n", s);
222.2159 +          exit(-1);
222.2160 +        }
222.2161 +      } else {
222.2162 +        remoteSetProtocol(0);
222.2163 +      }
222.2164 +      break;
222.2165 +    case 'N':
222.2166 +      parseDebug = false;
222.2167 +      break;
222.2168 +    case 'D':
222.2169 +      if(optarg) {
222.2170 +        systemDebug = atoi(optarg);
222.2171 +      } else {
222.2172 +        systemDebug = 1;
222.2173 +      }
222.2174 +      break;
222.2175 +    case 'F':
222.2176 +      fullscreen = 1;
222.2177 +      mouseCounter = 120;
222.2178 +      break;
222.2179 +    case 'f':
222.2180 +      if(optarg) {
222.2181 +        filter = atoi(optarg);
222.2182 +      } else {
222.2183 +        filter = 0;
222.2184 +      }
222.2185 +      break;
222.2186 +      
222.2187 +    case 'r':
222.2188 +      if(optarg == NULL) {
222.2189 +        fprintf(stderr, "ERROR: --recordMovie ('r') needs movie filename as option\n");
222.2190 +        exit(-1);
222.2191 +      }
222.2192 +        strcpy(movieFileName, optarg);
222.2193 +        useMovie = 1;
222.2194 +      break;
222.2195 +    case 'p': // play without read-only (editable)
222.2196 +      fprintf (stderr, "-p got called!\n");
222.2197 +      if(optarg == NULL) {
222.2198 +        fprintf(stderr, "ERROR: --playMovie ('p') needs movie filename as option\n");
222.2199 +        exit(-1);
222.2200 +      }
222.2201 +        strcpy(movieFileName, optarg);
222.2202 +        useMovie = 2;
222.2203 +      break;
222.2204 +    case 'w': // play with read-only
222.2205 +     fprintf (stderr, "-w got called!\n"); 
222.2206 +      if(optarg == NULL) {
222.2207 +        fprintf(stderr, "ERROR: --watchMovie ('w') needs movie filename as option\n");
222.2208 +        exit(-1);
222.2209 +      }
222.2210 +        strcpy(movieFileName, optarg);
222.2211 +        useMovie = 3;
222.2212 +      break;
222.2213 +                  
222.2214 +    case 'P':
222.2215 +#ifdef PROFILING
222.2216 +      if(optarg) {
222.2217 +        cpuEnableProfiling(atoi(optarg));
222.2218 +      } else
222.2219 +        cpuEnableProfiling(100);
222.2220 +#endif
222.2221 +      break;
222.2222 +    case 'S':
222.2223 +      sdlFlashSize = atoi(optarg);
222.2224 +      if(sdlFlashSize < 0 || sdlFlashSize > 1)
222.2225 +        sdlFlashSize = 0;
222.2226 +      break;
222.2227 +    case 's':
222.2228 +      if(optarg) {
222.2229 +        int a = atoi(optarg);
222.2230 +        if(a >= 0 && a <= 9) {
222.2231 +          gbFrameSkip = a;
222.2232 +          frameSkip = a;
222.2233 +        }
222.2234 +      } else {
222.2235 +        frameSkip = 2;
222.2236 +        gbFrameSkip = 0;
222.2237 +      }
222.2238 +      break;
222.2239 +    case 't':
222.2240 +      if(optarg) {
222.2241 +        int a = atoi(optarg);
222.2242 +        if(a < 0 || a > 5)
222.2243 +          a = 0;
222.2244 +        cpuSaveType = a;
222.2245 +      }
222.2246 +      break;
222.2247 +    case 'T':
222.2248 +      if(optarg) {
222.2249 +        int t = atoi(optarg);
222.2250 +        throttle = t;
222.2251 +      }
222.2252 +      break;
222.2253 +    case 'v':
222.2254 +      if(optarg) {
222.2255 +        systemVerbose = atoi(optarg);
222.2256 +      } else 
222.2257 +        systemVerbose = 0;
222.2258 +      break;
222.2259 +    case '1':
222.2260 +      sizeOption = 0;
222.2261 +      break;
222.2262 +    case '2':
222.2263 +      sizeOption = 1;
222.2264 +      break;
222.2265 +    case '3':
222.2266 +      sizeOption = 2;
222.2267 +      break;
222.2268 +    case '4':
222.2269 +      sizeOption = 3;
222.2270 +      break;
222.2271 +    case '?':
222.2272 +      sdlPrintUsage = 1;
222.2273 +      break;
222.2274 +    }
222.2275 +  }
222.2276 +
222.2277 +  if(sdlPrintUsage) {
222.2278 +    usage(argv[0]);
222.2279 +    exit(-1);
222.2280 +  }
222.2281 +
222.2282 +#ifdef MMX
222.2283 +  if(disableMMX)
222.2284 +    cpu_mmx = 0;
222.2285 +#endif
222.2286 +
222.2287 +  if(rewindTimer)
222.2288 +    rewindMemory = (char *)malloc(8*REWIND_SIZE);
222.2289 +
222.2290 +  if(sdlFlashSize == 0)
222.2291 +    flashSetSize(0x10000);
222.2292 +  else
222.2293 +    flashSetSize(0x20000);
222.2294 +
222.2295 +  rtcEnable(sdlRtcEnable ? true : false);
222.2296 +  agbPrintEnable(sdlAgbPrint ? true : false);
222.2297 +  
222.2298 +  if(!debuggerStub) {
222.2299 +    if(optind >= argc) {
222.2300 +      systemMessage(0,"Missing image name");
222.2301 +      usage(argv[0]);
222.2302 +      exit(-1);
222.2303 +    }
222.2304 +  }
222.2305 +
222.2306 +  if(filter) {
222.2307 +    sizeOption = 1;
222.2308 +  }
222.2309 +
222.2310 +  for(int i = 0; i < 24;) {
222.2311 +    systemGbPalette[i++] = (0x1f) | (0x1f << 5) | (0x1f << 10);
222.2312 +    systemGbPalette[i++] = (0x15) | (0x15 << 5) | (0x15 << 10);
222.2313 +    systemGbPalette[i++] = (0x0c) | (0x0c << 5) | (0x0c << 10);
222.2314 +    systemGbPalette[i++] = 0;
222.2315 +  }
222.2316 +
222.2317 +  systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
222.2318 +
222.2319 +  if(optind < argc) 
222.2320 +  {
222.2321 +      szFile = argv[optind];
222.2322 +      file_run();
222.2323 +  }
222.2324 +   else 
222.2325 +  {
222.2326 +    systemCartridgeType = 0;
222.2327 +    strcpy(filename, "gnu_stub");
222.2328 +    rom = (u8 *)malloc(0x2000000);
222.2329 +    workRAM = (u8 *)calloc(1, 0x40000);
222.2330 +    bios = (u8 *)calloc(1,0x4000);
222.2331 +    internalRAM = (u8 *)calloc(1,0x8000);
222.2332 +    paletteRAM = (u8 *)calloc(1,0x400);
222.2333 +    vram = (u8 *)calloc(1, 0x20000);
222.2334 +    oam = (u8 *)calloc(1, 0x400);
222.2335 +    pix = (u8 *)calloc(1, 4 * 240 * 160);
222.2336 +    ioMem = (u8 *)calloc(1, 0x400);
222.2337 +
222.2338 +    theEmulator = GBASystem;
222.2339 +    
222.2340 +    //CPUInit(biosFileName, useBios);
222.2341 +    CPUInit();
222.2342 +    CPUReset();    
222.2343 +  }
222.2344 +  
222.2345 +  if(debuggerStub) 
222.2346 +    remoteInit();
222.2347 +  
222.2348 +  int flags = SDL_INIT_VIDEO|SDL_INIT_AUDIO|
222.2349 +    SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE;
222.2350 +
222.2351 +  if(soundOffFlag)
222.2352 +    flags ^= SDL_INIT_AUDIO;
222.2353 +  
222.2354 +  if(SDL_Init(flags)) {
222.2355 +    systemMessage(0, "Failed to init SDL: %s", SDL_GetError());
222.2356 +    exit(-1);
222.2357 +  }
222.2358 +
222.2359 +  if(SDL_InitSubSystem(SDL_INIT_JOYSTICK)) {
222.2360 +    systemMessage(0, "Failed to init joystick support: %s", SDL_GetError());
222.2361 +  }
222.2362 +  
222.2363 +  sdlCheckKeys();
222.2364 +  
222.2365 +  if(systemCartridgeType == 0) {
222.2366 +    srcWidth = 240;
222.2367 +    srcHeight = 160;
222.2368 +    systemFrameSkip = frameSkip;
222.2369 +  } else if (systemCartridgeType == 1) {
222.2370 +    if(gbBorderOn) {
222.2371 +      srcWidth = 256;
222.2372 +      srcHeight = 224;
222.2373 +      gbBorderLineSkip = 256;
222.2374 +      gbBorderColumnSkip = 48;
222.2375 +      gbBorderRowSkip = 40;
222.2376 +    } else {      
222.2377 +      srcWidth = 160;
222.2378 +      srcHeight = 144;
222.2379 +      gbBorderLineSkip = 160;
222.2380 +      gbBorderColumnSkip = 0;
222.2381 +      gbBorderRowSkip = 0;
222.2382 +    }
222.2383 +    systemFrameSkip = gbFrameSkip;
222.2384 +  } else {
222.2385 +    srcWidth = 320;
222.2386 +    srcHeight = 240;
222.2387 +  }
222.2388 +  
222.2389 +  destWidth = (sizeOption+1)*srcWidth;
222.2390 +  destHeight = (sizeOption+1)*srcHeight;
222.2391 +  
222.2392 +  surface = SDL_SetVideoMode(destWidth, destHeight, 16,
222.2393 +                             SDL_ANYFORMAT|SDL_HWSURFACE|SDL_DOUBLEBUF|
222.2394 +                             (fullscreen ? SDL_FULLSCREEN : 0));
222.2395 +  
222.2396 +  if(surface == NULL) {
222.2397 +    systemMessage(0, "Failed to set video mode");
222.2398 +    SDL_Quit();
222.2399 +    exit(-1);
222.2400 +  }
222.2401 +  
222.2402 +  systemRedShift = sdlCalculateShift(surface->format->Rmask);
222.2403 +  systemGreenShift = sdlCalculateShift(surface->format->Gmask);
222.2404 +  systemBlueShift = sdlCalculateShift(surface->format->Bmask);
222.2405 +  
222.2406 +  systemColorDepth = surface->format->BitsPerPixel;
222.2407 +  if(systemColorDepth == 15)
222.2408 +    systemColorDepth = 16;
222.2409 +
222.2410 +  if(yuv) {
222.2411 +    Init_Overlay(surface, yuvType);
222.2412 +    systemColorDepth = 32;
222.2413 +    systemRedShift = 3;
222.2414 +    systemGreenShift = 11;
222.2415 +    systemBlueShift =  19;
222.2416 +  }
222.2417 +  
222.2418 +  if(systemColorDepth != 16 && systemColorDepth != 24 &&
222.2419 +     systemColorDepth != 32) {
222.2420 +    fprintf(stderr,"Unsupported color depth '%d'.\nOnly 16, 24 and 32 bit color depths are supported\n", systemColorDepth);
222.2421 +    exit(-1);
222.2422 +  }
222.2423 +
222.2424 +#ifndef C_CORE
222.2425 +  sdlMakeStretcher(srcWidth);
222.2426 +#else
222.2427 +  switch(systemColorDepth) {
222.2428 +  case 16:
222.2429 +    sdlStretcher = sdlStretcher16[sizeOption];
222.2430 +    break;
222.2431 +  case 24:
222.2432 +    sdlStretcher = sdlStretcher24[sizeOption];
222.2433 +    break;
222.2434 +  case 32:
222.2435 +    sdlStretcher = sdlStretcher32[sizeOption];
222.2436 +    break;
222.2437 +  default:
222.2438 +    fprintf(stderr, "Unsupported resolution: %d\n", systemColorDepth);
222.2439 +    exit(-1);
222.2440 +  }
222.2441 +#endif
222.2442 +
222.2443 +  fprintf(stderr,"Color depth: %d\n", systemColorDepth);
222.2444 +  
222.2445 +  if(systemColorDepth == 16) {
222.2446 +    if(sdlCalculateMaskWidth(surface->format->Gmask) == 6) {
222.2447 +      Init_2xSaI(565);
222.2448 +      RGB_LOW_BITS_MASK = 0x821;
222.2449 +    } else {
222.2450 +      Init_2xSaI(555);
222.2451 +      RGB_LOW_BITS_MASK = 0x421;      
222.2452 +    }
222.2453 +    if(systemCartridgeType == 2) {
222.2454 +      for(int i = 0; i < 0x10000; i++) {
222.2455 +        systemColorMap16[i] = (((i >> 1) & 0x1f) << systemBlueShift) |
222.2456 +          (((i & 0x7c0) >> 6) << systemGreenShift) |
222.2457 +          (((i & 0xf800) >> 11) << systemRedShift);  
222.2458 +      }      
222.2459 +    } else {
222.2460 +      for(int i = 0; i < 0x10000; i++) {
222.2461 +        systemColorMap16[i] = ((i & 0x1f) << systemRedShift) |
222.2462 +          (((i & 0x3e0) >> 5) << systemGreenShift) |
222.2463 +          (((i & 0x7c00) >> 10) << systemBlueShift);  
222.2464 +      }
222.2465 +    }
222.2466 +    srcPitch = srcWidth * 2+4;
222.2467 +  } else {
222.2468 +    if(systemColorDepth != 32)
222.2469 +      filterFunction = NULL;
222.2470 +    RGB_LOW_BITS_MASK = 0x010101;
222.2471 +    if(systemColorDepth == 32) {
222.2472 +      Init_2xSaI(32);
222.2473 +    }
222.2474 +    for(int i = 0; i < 0x10000; i++) {
222.2475 +      systemColorMap32[i] = ((i & 0x1f) << systemRedShift) |
222.2476 +        (((i & 0x3e0) >> 5) << systemGreenShift) |
222.2477 +        (((i & 0x7c00) >> 10) << systemBlueShift);  
222.2478 +    }
222.2479 +    if(systemColorDepth == 32)
222.2480 +      srcPitch = srcWidth*4 + 4;
222.2481 +    else
222.2482 +      srcPitch = srcWidth*3;
222.2483 +  }
222.2484 +
222.2485 +  if(systemColorDepth != 32) {
222.2486 +    switch(filter) {
222.2487 +    case 0:
222.2488 +      filterFunction = NULL;
222.2489 +      break;
222.2490 +    case 1:
222.2491 +      filterFunction = ScanlinesTV;
222.2492 +      break;
222.2493 +    case 2:
222.2494 +      filterFunction = _2xSaI;
222.2495 +      break;
222.2496 +    case 3:
222.2497 +      filterFunction = Super2xSaI;
222.2498 +      break;
222.2499 +    case 4:
222.2500 +      filterFunction = SuperEagle;
222.2501 +      break;
222.2502 +    case 5:
222.2503 +      filterFunction = Pixelate2x16;
222.2504 +      break;
222.2505 +    case 6:
222.2506 +      filterFunction = MotionBlur;
222.2507 +      break;
222.2508 +    case 7:
222.2509 +      filterFunction = AdMame2x;
222.2510 +      break;
222.2511 +    case 8:
222.2512 +      filterFunction = Simple2x16;
222.2513 +      break;
222.2514 +    case 9:
222.2515 +      filterFunction = Bilinear;
222.2516 +      break;
222.2517 +    case 10:
222.2518 +      filterFunction = BilinearPlus;
222.2519 +      break;
222.2520 +    case 11:
222.2521 +      filterFunction = Scanlines;
222.2522 +      break;
222.2523 +    case 12:
222.2524 +      filterFunction = hq2x;
222.2525 +      break;
222.2526 +    case 13:
222.2527 +      filterFunction = lq2x;
222.2528 +      break;
222.2529 +    default:
222.2530 +      filterFunction = NULL;
222.2531 +      break;
222.2532 +    }
222.2533 +  } else {
222.2534 +    switch(filter) {
222.2535 +    case 0:
222.2536 +      filterFunction = NULL;
222.2537 +      break;
222.2538 +    case 1:
222.2539 +      filterFunction = ScanlinesTV32;
222.2540 +      break;
222.2541 +    case 2:
222.2542 +      filterFunction = _2xSaI32;
222.2543 +      break;
222.2544 +    case 3:
222.2545 +      filterFunction = Super2xSaI32;
222.2546 +      break;
222.2547 +    case 4:
222.2548 +      filterFunction = SuperEagle32;
222.2549 +      break;
222.2550 +    case 5:
222.2551 +      filterFunction = Pixelate2x32;
222.2552 +      break;
222.2553 +    case 6:
222.2554 +      filterFunction = MotionBlur32;
222.2555 +      break;
222.2556 +    case 7:
222.2557 +      filterFunction = AdMame2x32;
222.2558 +      break;
222.2559 +    case 8:
222.2560 +      filterFunction = Simple2x32;
222.2561 +      break;
222.2562 +    case 9:
222.2563 +      filterFunction = Bilinear32;
222.2564 +      break;
222.2565 +    case 10:
222.2566 +      filterFunction = BilinearPlus32;
222.2567 +      break;
222.2568 +    case 11:
222.2569 +      filterFunction = Scanlines32;
222.2570 +      break;
222.2571 +    case 12:
222.2572 +      filterFunction = hq2x32;
222.2573 +      break;
222.2574 +    case 13:
222.2575 +      filterFunction = lq2x32;
222.2576 +      break;
222.2577 +    default:
222.2578 +      filterFunction = NULL;
222.2579 +      break;
222.2580 +    }
222.2581 +  }
222.2582 +  
222.2583 +  if(systemColorDepth == 16) {
222.2584 +    switch(ifbType) {
222.2585 +    case 0:
222.2586 +    default:
222.2587 +      ifbFunction = NULL;
222.2588 +      break;
222.2589 +    case 1:
222.2590 +      ifbFunction = MotionBlurIB;
222.2591 +      break;
222.2592 +    case 2:
222.2593 +      ifbFunction = SmartIB;
222.2594 +      break;
222.2595 +    }
222.2596 +  } else if(systemColorDepth == 32) {
222.2597 +    switch(ifbType) {
222.2598 +    case 0:
222.2599 +    default:
222.2600 +      ifbFunction = NULL;
222.2601 +      break;
222.2602 +    case 1:
222.2603 +      ifbFunction = MotionBlurIB32;
222.2604 +      break;
222.2605 +    case 2:
222.2606 +      ifbFunction = SmartIB32;
222.2607 +      break;
222.2608 +    }
222.2609 +  } else
222.2610 +    ifbFunction = NULL;
222.2611 +
222.2612 +  if(delta == NULL) {
222.2613 +    delta = (u8*)malloc(322*242*4);
222.2614 +    memset(delta, 255, 322*242*4);
222.2615 +  }
222.2616 +
222.2617 +  if(!soundOffFlag)
222.2618 +    soundInit();
222.2619 +
222.2620 +  autoFrameSkipLastTime = throttleLastTime = systemGetClock();
222.2621 +
222.2622 +  switch(useMovie)
222.2623 +  {
222.2624 +    case 1: // --recordMovie
222.2625 +      VBAMovieCreate(movieFileName,
222.2626 +        /*authorInfo*/"",
222.2627 +        /*startFlags*/0,
222.2628 +        /*controllerFlags*/MOVIE_CONTROLLER(0),
222.2629 +        /*typeFlags*/(systemCartridgeType==IMAGE_GBA)?(MOVIE_TYPE_GBA):(GBC_CAPABLE?MOVIE_TYPE_GBC:MOVIE_TYPE_SGB));
222.2630 +	  break;
222.2631 +    case 2: // --playMovie
222.2632 +      VBAMovieOpen(movieFileName, false);
222.2633 +  	  break;
222.2634 +    case 3: // --watchMovie
222.2635 +      VBAMovieOpen(movieFileName, true);
222.2636 +  	  break;
222.2637 +    default:
222.2638 +    	sdlReadBattery();
222.2639 +  	  break;
222.2640 +  }
222.2641 +  SDL_WM_SetCaption("VisualBoyAdvance", NULL);
222.2642 +  
222.2643 +  char *moviefile = getenv("AUTODEMO");
222.2644 +//  fprintf (stderr, "Checking for AUTODEMO...\n");
222.2645 +  if (moviefile)
222.2646 +  {
222.2647 +//    fprintf (stderr, "I got a filename OMG!\nCalling VBAMovieOpen...\n");
222.2648 +    VBAMovieOpen(moviefile, true);
222.2649 +  }
222.2650 +
222.2651 +  while(emulating) {
222.2652 +    if(!paused && active) {
222.2653 +      if(debugger && theEmulator.emuHasDebugger)
222.2654 +        dbgMain();
222.2655 +      else {
222.2656 +        theEmulator.emuMain(theEmulator.emuCount);
222.2657 +        if(rewindSaveNeeded && rewindMemory && theEmulator.emuWriteMemState) {
222.2658 +          rewindCount++;
222.2659 +          if(rewindCount > 8)
222.2660 +            rewindCount = 8;
222.2661 +          if(theEmulator.emuWriteMemState &&
222.2662 +             theEmulator.emuWriteMemState(&rewindMemory[rewindPos*REWIND_SIZE], 
222.2663 +                                       REWIND_SIZE)) {
222.2664 +            rewindPos = ++rewindPos & 7;
222.2665 +            if(rewindCount == 8)
222.2666 +              rewindTopPos = ++rewindTopPos & 7;
222.2667 +          }
222.2668 +        }
222.2669 +
222.2670 +        rewindSaveNeeded = false;
222.2671 +      }
222.2672 +    } else {
222.2673 +      SDL_Delay(500);
222.2674 +    }
222.2675 +    sdlPollEvents();
222.2676 +    if(mouseCounter) {
222.2677 +      mouseCounter--;
222.2678 +      if(mouseCounter == 0)
222.2679 +        SDL_ShowCursor(SDL_DISABLE);
222.2680 +    }
222.2681 +  }
222.2682 +  
222.2683 +  emulating = 0;
222.2684 +  fprintf(stderr,"Shutting down\n");
222.2685 +  remoteCleanUp();
222.2686 +  soundShutdown();
222.2687 +
222.2688 +  if(gbRom != NULL || rom != NULL) {
222.2689 +    sdlWriteBattery();
222.2690 +    theEmulator.emuCleanUp();
222.2691 +  }
222.2692 +
222.2693 +  if(delta) {
222.2694 +    free(delta);
222.2695 +    delta = NULL;
222.2696 +  }
222.2697 +  
222.2698 +  SDL_Quit();
222.2699 +  return 0;
222.2700 +}
222.2701 +
222.2702 +void systemMessage(int num, const char *msg, ...)
222.2703 +{
222.2704 +  char buffer[2048];
222.2705 +  va_list valist;
222.2706 +  
222.2707 +  va_start(valist, msg);
222.2708 +  vsprintf(buffer, msg, valist);
222.2709 +  
222.2710 +  fprintf(stderr, "%s\n", buffer);
222.2711 +  va_end(valist);
222.2712 +}
222.2713 +
222.2714 +//On WIN32, this function messages requesting
222.2715 +//the window to be redrawn. Can this be ignored here?
222.2716 +void systemRefreshScreen(){}
222.2717 +
222.2718 +void systemRenderFrame()
222.2719 +{
222.2720 +  renderedFrames++;
222.2721 +  VBAUpdateFrameCountDisplay();
222.2722 +  VBAUpdateButtonPressDisplay();
222.2723 +  
222.2724 +  if(yuv) {
222.2725 +    Draw_Overlay(surface, sizeOption+1);
222.2726 +    return;
222.2727 +  }
222.2728 +  
222.2729 +  SDL_LockSurface(surface);
222.2730 +
222.2731 +  for(int slot = 0 ; slot < 8 ; slot++)
222.2732 +  {
222.2733 +	if(screenMessage[slot]) {
222.2734 +		if(systemCartridgeType == 1 && gbBorderOn) {
222.2735 +			gbSgbRenderBorder();
222.2736 +		}
222.2737 +		if(((systemGetClock() - screenMessageTime[slot]) < screenMessageDuration[slot]) &&
222.2738 +			!disableStatusMessages) {
222.2739 +			drawText(pix, srcPitch, 10, srcHeight - 20*(slot+1),
222.2740 +					screenMessageBuffer[slot]); 
222.2741 +		} else {
222.2742 +			screenMessage[slot] = false;
222.2743 +		}
222.2744 +	}
222.2745 +  }
222.2746 +
222.2747 +  if(ifbFunction) {
222.2748 +    if(systemColorDepth == 16)
222.2749 +      ifbFunction(pix+destWidth+4, destWidth+4, srcWidth, srcHeight);
222.2750 +    else
222.2751 +      ifbFunction(pix+destWidth*2+4, destWidth*2+4, srcWidth, srcHeight);
222.2752 +  }
222.2753 +  
222.2754 +  if(filterFunction) {
222.2755 +    if(systemColorDepth == 16)
222.2756 +      filterFunction(pix+destWidth+4,destWidth+4, delta,
222.2757 +                     (u8*)surface->pixels,surface->pitch,
222.2758 +                     srcWidth,
222.2759 +                     srcHeight);
222.2760 +    else
222.2761 +      filterFunction(pix+destWidth*2+4,
222.2762 +                     destWidth*2+4,
222.2763 +                     delta,
222.2764 +                     (u8*)surface->pixels,
222.2765 +                     surface->pitch,
222.2766 +                     srcWidth,
222.2767 +                     srcHeight);
222.2768 +  } else {
222.2769 +    int destPitch = surface->pitch;
222.2770 +    u8 *src = pix;
222.2771 +    u8 *dest = (u8*)surface->pixels;
222.2772 +    int i;
222.2773 +    u32 *stretcher = (u32 *)sdlStretcher;
222.2774 +    if(systemColorDepth == 16)
222.2775 +      src += srcPitch;
222.2776 +    int option = sizeOption;
222.2777 +    if(yuv)
222.2778 +      option = 0;
222.2779 +    switch(sizeOption) {
222.2780 +    case 0:
222.2781 +      for(i = 0; i < srcHeight; i++) {
222.2782 +        SDL_CALL_STRETCHER;
222.2783 +        src += srcPitch;
222.2784 +        dest += destPitch;
222.2785 +      }
222.2786 +      break;
222.2787 +    case 1:
222.2788 +      for(i = 0; i < srcHeight; i++) {
222.2789 +        SDL_CALL_STRETCHER;     
222.2790 +        dest += destPitch;
222.2791 +        SDL_CALL_STRETCHER;
222.2792 +        src += srcPitch;
222.2793 +        dest += destPitch;
222.2794 +      }
222.2795 +      break;
222.2796 +    case 2:
222.2797 +      for(i = 0; i < srcHeight; i++) {
222.2798 +        SDL_CALL_STRETCHER;
222.2799 +        dest += destPitch;
222.2800 +        SDL_CALL_STRETCHER;
222.2801 +        dest += destPitch;
222.2802 +        SDL_CALL_STRETCHER;
222.2803 +        src += srcPitch;
222.2804 +        dest += destPitch;
222.2805 +      }
222.2806 +      break;
222.2807 +    case 3:
222.2808 +      for(i = 0; i < srcHeight; i++) {
222.2809 +        SDL_CALL_STRETCHER;
222.2810 +        dest += destPitch;
222.2811 +        SDL_CALL_STRETCHER;
222.2812 +        dest += destPitch;
222.2813 +        SDL_CALL_STRETCHER;
222.2814 +        dest += destPitch;
222.2815 +        SDL_CALL_STRETCHER;
222.2816 +        src += srcPitch;
222.2817 +        dest += destPitch;
222.2818 +      }
222.2819 +      break;
222.2820 +    }
222.2821 +  }
222.2822 +
222.2823 +  if(showSpeed && fullscreen) {
222.2824 +    char buffer[50];
222.2825 +    if(showSpeed == 1)
222.2826 +      sprintf(buffer, "%d%%", systemSpeed);
222.2827 +    else
222.2828 +      sprintf(buffer, "%3d%%(%d, %d fps)", systemSpeed,
222.2829 +              systemFrameSkip,
222.2830 +              showRenderedFrames);
222.2831 +    if(showSpeedTransparent)
222.2832 +      drawTextTransp((u8*)surface->pixels,
222.2833 +                     surface->pitch,
222.2834 +                     10,
222.2835 +                     surface->h-20,
222.2836 +                     buffer);
222.2837 +    else
222.2838 +      drawText((u8*)surface->pixels,
222.2839 +               surface->pitch,
222.2840 +               10,
222.2841 +               surface->h-20,
222.2842 +               buffer);        
222.2843 +  }  
222.2844 +
222.2845 +  SDL_UnlockSurface(surface);
222.2846 +  //  SDL_UpdateRect(surface, 0, 0, destWidth, destHeight);
222.2847 +  SDL_Flip(surface);
222.2848 +}
222.2849 +
222.2850 +bool systemReadJoypads()
222.2851 +{
222.2852 +  return true;
222.2853 +}
222.2854 +
222.2855 +// Kludge to make Lua call the right function.
222.2856 +u32 systemGetOriginalJoypad(int which, bool sensor){
222.2857 +	return systemGetJoypad(which,sensor);
222.2858 +}
222.2859 +
222.2860 +u32 systemGetJoypad(int which, bool sensor)
222.2861 +{
222.2862 +    sensorOn = sensor;
222.2863 +  if(which < 0 || which > 3)
222.2864 +    which = sdlDefaultJoypad;
222.2865 +  
222.2866 +  //VBAMovieUpdate(which);
222.2867 +  //VBAMovieUpdateState();
222.2868 +  u32 res = 0;
222.2869 +  
222.2870 +  //----------------------------//
222.2871 +  if (VBAMoviePlaying()){
222.2872 +	// VBAMovieRead() overwrites currentButtons[i]
222.2873 +	VBAMovieRead(which, sensor);
222.2874 +	res = currentButtons[which];
222.2875 +	return res;
222.2876 +  }  
222.2877 +  //---------------------------//
222.2878 +  //Temporary implementation, not sure if it's correct --Felipe
222.2879 +  
222.2880 +  /*
222.2881 +  if(sdlButtons[which][KEY_BUTTON_A])
222.2882 +    res |= BUTTON_MASK_A;
222.2883 +  if(sdlButtons[which][KEY_BUTTON_B])
222.2884 +    res |= BUTTON_MASK_B;
222.2885 +  if(sdlButtons[which][KEY_BUTTON_SELECT])
222.2886 +    res |= BUTTON_MASK_SELECT;
222.2887 +  if(sdlButtons[which][KEY_BUTTON_START])
222.2888 +    res |= BUTTON_MASK_START;
222.2889 +  if(sdlButtons[which][KEY_RIGHT])
222.2890 +    res |= BUTTON_MASK_RIGHT;
222.2891 +  if(sdlButtons[which][KEY_LEFT])
222.2892 +    res |= BUTTON_MASK_LEFT;
222.2893 +  if(sdlButtons[which][KEY_UP])
222.2894 +    res |= BUTTON_MASK_UP;
222.2895 +  if(sdlButtons[which][KEY_DOWN])
222.2896 +    res |= BUTTON_MASK_DOWN;
222.2897 +  if(sdlButtons[which][KEY_BUTTON_R])
222.2898 +    res |= BUTTON_MASK_R;
222.2899 +  if(sdlButtons[which][KEY_BUTTON_L])
222.2900 +    res |= BUTTON_MASK_L;
222.2901 +  */
222.2902 +/*
222.2903 +  // disallow L+R or U+D of being pressed at the same time
222.2904 +  if((res & 48) == 48)
222.2905 +    res &= ~16;
222.2906 +  if((res & 192) == 192)
222.2907 +    res &= ~128;
222.2908 +*/
222.2909 +/*  
222.2910 +  if(sdlbuttons[which][KEY_BUTTON_SPEED])
222.2911 +    res |= 1024;
222.2912 +  if(sdlButtons[which][KEY_BUTTON_CAPTURE])
222.2913 +    res |= 2048;
222.2914 +*/
222.2915 +	res = currentButtons[which];
222.2916 +
222.2917 +  if(autoFire) {
222.2918 +    res &= (~autoFire);
222.2919 +    if(autoFireToggle)
222.2920 +      res |= autoFire;
222.2921 +    autoFireToggle = !autoFireToggle;
222.2922 +  }
222.2923 +  
222.2924 +  //if (res) fprintf(stdout,"%x\n",res);
222.2925 +  
222.2926 +  return res;
222.2927 +}
222.2928 +
222.2929 +void systemSetJoypad(int which, u32 buttons)
222.2930 +{
222.2931 +  if(which < 0 || which > 3)
222.2932 +    which = sdlDefaultJoypad;
222.2933 +/*  
222.2934 +  sdlButtons[which][KEY_BUTTON_A] = (buttons & 1) != 0;
222.2935 +  sdlButtons[which][KEY_BUTTON_B] = (buttons & 2) != 0;
222.2936 +  sdlButtons[which][KEY_BUTTON_SELECT] = (buttons & 4) != 0;
222.2937 +  sdlButtons[which][KEY_BUTTON_START] = (buttons & 8) != 0;
222.2938 +  sdlButtons[which][KEY_RIGHT] = (buttons & 16) != 0;
222.2939 +  sdlButtons[which][KEY_LEFT] = (buttons & 32) != 0;
222.2940 +  sdlButtons[which][KEY_UP] = (buttons & 64) != 0;
222.2941 +  sdlButtons[which][KEY_DOWN] = (buttons & 128) != 0;
222.2942 +  sdlButtons[which][KEY_BUTTON_R] = (buttons & 256) != 0;
222.2943 +  sdlButtons[which][KEY_BUTTON_L] = (buttons & 512) != 0;
222.2944 +*/
222.2945 +	currentButtons[which]= buttons & 0x3ff;
222.2946 +}
222.2947 +
222.2948 +void systemClearJoypads()
222.2949 +{
222.2950 +	for (int i = 0; i < 4; ++i)
222.2951 +		currentButtons[i] = 0;
222.2952 +
222.2953 +	//lastKeys = 0;
222.2954 +}
222.2955 +
222.2956 +void systemSetTitle(const char *title)
222.2957 +{
222.2958 +  SDL_WM_SetCaption(title, NULL);
222.2959 +}
222.2960 +
222.2961 +void systemShowSpeed(int speed)
222.2962 +{
222.2963 +  systemSpeed = speed;
222.2964 +
222.2965 +  showRenderedFrames = renderedFrames;
222.2966 +  renderedFrames = 0;  
222.2967 +
222.2968 +  if(!fullscreen && showSpeed) {
222.2969 +    char buffer[80];
222.2970 +    if(showSpeed == 1)
222.2971 +      sprintf(buffer, "VisualBoyAdvance-%3d%%", systemSpeed);
222.2972 +    else
222.2973 +      sprintf(buffer, "VisualBoyAdvance-%3d%%(%d, %d fps)", systemSpeed,
222.2974 +              systemFrameSkip,
222.2975 +              showRenderedFrames);
222.2976 +
222.2977 +    systemSetTitle(buffer);
222.2978 +  }
222.2979 +}
222.2980 +
222.2981 +// FIXME: the timing
222.2982 +void systemFrame(/*int rate*/) //Looking at System.cpp, it looks like rate should be 600
222.2983 +{
222.2984 +  u32 time = systemGetClock();  
222.2985 +  if(!wasPaused && autoFrameSkip && !throttle) {
222.2986 +    u32 diff = time - autoFrameSkipLastTime;
222.2987 +    int speed = 100;
222.2988 +
222.2989 +    if(diff)
222.2990 +      speed = (1000000/600)/diff;
222.2991 +    
222.2992 +    if(speed >= 98) {
222.2993 +      frameskipadjust++;
222.2994 +
222.2995 +      if(frameskipadjust >= 3) {
222.2996 +        frameskipadjust=0;
222.2997 +        if(systemFrameSkip > 0)
222.2998 +          systemFrameSkip--;
222.2999 +      }
222.3000 +    } else {
222.3001 +      if(speed  < 80)
222.3002 +        frameskipadjust -= (90 - speed)/5;
222.3003 +      else if(systemFrameSkip < 9)
222.3004 +        frameskipadjust--;
222.3005 +
222.3006 +      if(frameskipadjust <= -2) {
222.3007 +        frameskipadjust += 2;
222.3008 +        if(systemFrameSkip < 9)
222.3009 +          systemFrameSkip++;
222.3010 +      }
222.3011 +    }    
222.3012 +  }
222.3013 +  if(!wasPaused && throttle) {
222.3014 +    /*if(!speedup) {
222.3015 +      u32 diff = time - throttleLastTime;
222.3016 +      
222.3017 +      int target = (1000000.0/(600*throttle));
222.3018 +      int d = (target - diff);
222.3019 +      
222.3020 +      if(d > 0) {
222.3021 +        SDL_Delay(d);
222.3022 +      }
222.3023 +    }
222.3024 +    throttleLastTime = systemGetClock();
222.3025 +    */
222.3026 +  }
222.3027 +  if(rewindMemory) {
222.3028 +    if(++rewindCounter >= rewindTimer) {
222.3029 +      rewindSaveNeeded = true;
222.3030 +      rewindCounter = 0;
222.3031 +    }
222.3032 +  }
222.3033 +
222.3034 +  if(systemSaveUpdateCounter) {
222.3035 +    if(--systemSaveUpdateCounter <= SYSTEM_SAVE_NOT_UPDATED) {
222.3036 +      sdlWriteBattery();
222.3037 +      systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
222.3038 +    }
222.3039 +  }
222.3040 +
222.3041 +  wasPaused = false;
222.3042 +  autoFrameSkipLastTime = time;
222.3043 +}
222.3044 +
222.3045 +int systemFramesToSkip(){
222.3046 +	return systemFrameSkip;
222.3047 +}
222.3048 +
222.3049 +int systemScreenCapture(int a)
222.3050 +{
222.3051 +  char buffer[2048];
222.3052 +
222.3053 +  if(captureFormat) {
222.3054 +    if(captureDir[0])
222.3055 +      sprintf(buffer, "%s/%s%02d.bmp", captureDir, sdlGetFilename(filename), a);
222.3056 +    else
222.3057 +      sprintf(buffer, "%s%02d.bmp", filename, a);
222.3058 +
222.3059 +    theEmulator.emuWriteBMP(buffer);
222.3060 +  } else {
222.3061 +    if(captureDir[0])
222.3062 +      sprintf(buffer, "%s/%s%02d.png", captureDir, sdlGetFilename(filename), a);
222.3063 +    else
222.3064 +      sprintf(buffer, "%s%02d.png", filename, a);
222.3065 +    theEmulator.emuWritePNG(buffer);
222.3066 +  }
222.3067 +
222.3068 +  systemScreenMessage("Screen capture");
222.3069 +  return a;
222.3070 +}
222.3071 +
222.3072 +void soundCallback(void *,u8 *stream,int len){}
222.3073 +
222.3074 +void systemSoundWriteToBuffer(){
222.3075 +	soundDriver->write(soundFinalWave, soundBufferLen);  
222.3076 +}
222.3077 +
222.3078 +void systemSoundClearBuffer()
222.3079 +{
222.3080 +	SDL_mutexP(mutex);
222.3081 +	memset(sdlBuffer,0,soundBufferTotalLen);
222.3082 +	sdlSoundLen=0;
222.3083 +	printf("Hi\n");
222.3084 +	SDL_mutexV(mutex);
222.3085 +}
222.3086 +
222.3087 +bool systemSoundInit(){
222.3088 +	systemSoundShutdown();
222.3089 +	soundDriver = new SoundSDL();
222.3090 +	if ( !soundDriver )
222.3091 +		return false;
222.3092 +
222.3093 +	if (!soundDriver->init()) //<-- sound sample rate
222.3094 +		return false;
222.3095 +	
222.3096 +	if (!(soundDriver->setThrottle(throttle))){
222.3097 +        	fprintf(stderr,"Failed to set desired throttle, defaulting to 100 %%.\n");
222.3098 +        	if (!soundDriver->setThrottle(100)) return false;
222.3099 +        }
222.3100 +	soundPaused = true;
222.3101 +	systemSoundOn = true;
222.3102 +	return true;
222.3103 +}
222.3104 +
222.3105 +void systemSoundShutdown(){
222.3106 +	if (soundDriver)
222.3107 +	{
222.3108 +		delete soundDriver;
222.3109 +		soundDriver = 0;
222.3110 +	}
222.3111 +}
222.3112 +
222.3113 +void systemSoundPause()
222.3114 +{
222.3115 +  SDL_PauseAudio(1);
222.3116 +}
222.3117 +
222.3118 +void systemSoundResume()
222.3119 +{
222.3120 +  SDL_PauseAudio(0);
222.3121 +}
222.3122 +
222.3123 +void systemSoundReset()
222.3124 +{
222.3125 +}
222.3126 +
222.3127 +u32 systemGetClock()
222.3128 +{
222.3129 +  return SDL_GetTicks();
222.3130 +}
222.3131 +
222.3132 +void systemUpdateMotionSensor()
222.3133 +{
222.3134 +  if(sdlMotionButtons[KEY_LEFT]) {
222.3135 +    sensorX += 3;
222.3136 +    if(sensorX > 2197)
222.3137 +      sensorX = 2197;
222.3138 +    if(sensorX < 2047)
222.3139 +      sensorX = 2057;
222.3140 +  } else if(sdlMotionButtons[KEY_RIGHT]) {
222.3141 +    sensorX -= 3;
222.3142 +    if(sensorX < 1897)
222.3143 +      sensorX = 1897;
222.3144 +    if(sensorX > 2047)
222.3145 +      sensorX = 2037;
222.3146 +  } else if(sensorX > 2047) {
222.3147 +    sensorX -= 2;
222.3148 +    if(sensorX < 2047)
222.3149 +      sensorX = 2047;
222.3150 +  } else {
222.3151 +    sensorX += 2;
222.3152 +    if(sensorX > 2047)
222.3153 +      sensorX = 2047;
222.3154 +  }
222.3155 +
222.3156 +  if(sdlMotionButtons[KEY_UP]) {
222.3157 +    sensorY += 3;
222.3158 +    if(sensorY > 2197)
222.3159 +      sensorY = 2197;
222.3160 +    if(sensorY < 2047)
222.3161 +      sensorY = 2057;
222.3162 +  } else if(sdlMotionButtons[KEY_DOWN]) {
222.3163 +    sensorY -= 3;
222.3164 +    if(sensorY < 1897)
222.3165 +      sensorY = 1897;
222.3166 +    if(sensorY > 2047)
222.3167 +      sensorY = 2037;
222.3168 +  } else if(sensorY > 2047) {
222.3169 +    sensorY -= 2;
222.3170 +    if(sensorY < 2047)
222.3171 +      sensorY = 2047;
222.3172 +  } else {
222.3173 +    sensorY += 2;
222.3174 +    if(sensorY > 2047)
222.3175 +      sensorY = 2047;
222.3176 +  }    
222.3177 +}
222.3178 +
222.3179 +void systemResetSensor()
222.3180 +{
222.3181 +	sensorX = sensorY = INITIAL_SENSOR_VALUE;
222.3182 +}
222.3183 +
222.3184 +int systemGetSensorX()
222.3185 +{
222.3186 +  return sensorX;
222.3187 +}
222.3188 +
222.3189 +int systemGetSensorY()
222.3190 +{
222.3191 +  return sensorY;
222.3192 +}
222.3193 +
222.3194 +void systemGbPrint(u8 *data,int pages,int feed,int palette, int contrast)
222.3195 +{
222.3196 +}
222.3197 +
222.3198 +void systemScreenMessage(const char *msg, int slot, int duration, const char *colorList)
222.3199 +{
222.3200 +  screenMessage[slot] = true;
222.3201 +  screenMessageTime[slot] = systemGetClock();
222.3202 +  screenMessageDuration[slot] = duration;
222.3203 +  if(strlen(msg) > 20) {
222.3204 +    strncpy(screenMessageBuffer[slot], msg, 20);
222.3205 +    screenMessageBuffer[slot][20] = 0;
222.3206 +  } else
222.3207 +    strcpy(screenMessageBuffer[slot], msg);  
222.3208 +}
222.3209 +
222.3210 +bool systemSoundCanChangeQuality()
222.3211 +{
222.3212 +  return false;
222.3213 +}
222.3214 +
222.3215 +bool systemSoundSetQuality(int quality)
222.3216 +{
222.3217 +	if (systemCartridgeType == 0)
222.3218 +		soundSetQuality(quality);
222.3219 +	else
222.3220 +		gbSoundSetQuality(quality);
222.3221 +
222.3222 +	return true;
222.3223 +}
222.3224 +
222.3225 +bool systemPauseOnFrame()
222.3226 +{
222.3227 +  if(pauseNextFrame) {
222.3228 +    paused = true;
222.3229 +    pauseNextFrame = false;
222.3230 +    return true;
222.3231 +  }
222.3232 +  return false;
222.3233 +}
222.3234 +
222.3235 +// Code donated by Niels Wagenaar (BoycottAdvance)
222.3236 +
222.3237 +// GBA screensize.
222.3238 +#define GBA_WIDTH   240
222.3239 +#define GBA_HEIGHT  160
222.3240 +
222.3241 +void Init_Overlay(SDL_Surface *gbascreen, int overlaytype)
222.3242 +{
222.3243 +  
222.3244 +  overlay = SDL_CreateYUVOverlay( GBA_WIDTH,
222.3245 +                                  GBA_HEIGHT,
222.3246 +                                  overlaytype, gbascreen);
222.3247 +  fprintf(stderr, "Created %dx%dx%d %s %s overlay\n",
222.3248 +          overlay->w,overlay->h,overlay->planes,
222.3249 +          overlay->hw_overlay?"hardware":"software",
222.3250 +          overlay->format==SDL_YV12_OVERLAY?"YV12":
222.3251 +          overlay->format==SDL_IYUV_OVERLAY?"IYUV":
222.3252 +          overlay->format==SDL_YUY2_OVERLAY?"YUY2":
222.3253 +          overlay->format==SDL_UYVY_OVERLAY?"UYVY":
222.3254 +          overlay->format==SDL_YVYU_OVERLAY?"YVYU":
222.3255 +          "Unknown");
222.3256 +}
222.3257 +
222.3258 +void Quit_Overlay(void)
222.3259 +{
222.3260 +  
222.3261 +  SDL_FreeYUVOverlay(overlay);
222.3262 +}
222.3263 +
222.3264 +/* NOTE: These RGB conversion functions are not intended for speed,
222.3265 +   only as examples.
222.3266 +*/
222.3267 +inline void RGBtoYUV(Uint8 *rgb, int *yuv)
222.3268 +{
222.3269 +  yuv[0] = (int)((0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16);
222.3270 +  yuv[1] = (int)(128 - (0.148 * rgb[0]) - (0.291 * rgb[1]) + (0.439 * rgb[2]));
222.3271 +  yuv[2] = (int)(128 + (0.439 * rgb[0]) - (0.368 * rgb[1]) - (0.071 * rgb[2]));
222.3272 +}
222.3273 +
222.3274 +inline void ConvertRGBtoYV12(SDL_Overlay *o)
222.3275 +{
222.3276 +  int x,y;
222.3277 +  int yuv[3];
222.3278 +  Uint8 *p,*op[3];
222.3279 +  
222.3280 +  SDL_LockYUVOverlay(o);
222.3281 +  
222.3282 +  /* Black initialization */
222.3283 +  /*
222.3284 +    memset(o->pixels[0],0,o->pitches[0]*o->h);
222.3285 +    memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2));
222.3286 +    memset(o->pixels[2],128,o->pitches[2]*((o->h+1)/2));
222.3287 +  */
222.3288 +  
222.3289 +  /* Convert */
222.3290 +  for(y=0; y<160 && y<o->h; y++) {
222.3291 +    p=(Uint8 *)pix+srcPitch*y;
222.3292 +    op[0]=o->pixels[0]+o->pitches[0]*y;
222.3293 +    op[1]=o->pixels[1]+o->pitches[1]*(y/2);
222.3294 +    op[2]=o->pixels[2]+o->pitches[2]*(y/2);
222.3295 +    for(x=0; x<240 && x<o->w; x++) {
222.3296 +      RGBtoYUV(p,yuv);
222.3297 +      *(op[0]++)=yuv[0];
222.3298 +      if(x%2==0 && y%2==0) {
222.3299 +        *(op[1]++)=yuv[2];
222.3300 +        *(op[2]++)=yuv[1];
222.3301 +      }
222.3302 +      p+=4;//s->format->BytesPerPixel;
222.3303 +    }
222.3304 +  }
222.3305 +  
222.3306 +  SDL_UnlockYUVOverlay(o);
222.3307 +}
222.3308 +
222.3309 +inline void ConvertRGBtoIYUV(SDL_Overlay *o)
222.3310 +{
222.3311 +  int x,y;
222.3312 +  int yuv[3];
222.3313 +  Uint8 *p,*op[3];
222.3314 +  
222.3315 +  SDL_LockYUVOverlay(o);
222.3316 +  
222.3317 +  /* Black initialization */
222.3318 +  /*
222.3319 +    memset(o->pixels[0],0,o->pitches[0]*o->h);
222.3320 +    memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2));
222.3321 +    memset(o->pixels[2],128,o->pitches[2]*((o->h+1)/2));
222.3322 +  */
222.3323 +  
222.3324 +  /* Convert */
222.3325 +  for(y=0; y<160 && y<o->h; y++) {
222.3326 +    p=(Uint8 *)pix+srcPitch*y;
222.3327 +    op[0]=o->pixels[0]+o->pitches[0]*y;
222.3328 +    op[1]=o->pixels[1]+o->pitches[1]*(y/2);
222.3329 +    op[2]=o->pixels[2]+o->pitches[2]*(y/2);
222.3330 +    for(x=0; x<240 && x<o->w; x++) {
222.3331 +      RGBtoYUV(p,yuv);
222.3332 +      *(op[0]++)=yuv[0];
222.3333 +      if(x%2==0 && y%2==0) {
222.3334 +        *(op[1]++)=yuv[1];
222.3335 +        *(op[2]++)=yuv[2];
222.3336 +      }
222.3337 +      p+=4; //s->format->BytesPerPixel;
222.3338 +    }
222.3339 +  }
222.3340 +  
222.3341 +  SDL_UnlockYUVOverlay(o);
222.3342 +}
222.3343 +
222.3344 +inline void ConvertRGBtoUYVY(SDL_Overlay *o)
222.3345 +{
222.3346 +  int x,y;
222.3347 +  int yuv[3];
222.3348 +  Uint8 *p,*op;
222.3349 +  
222.3350 +  SDL_LockYUVOverlay(o);
222.3351 +  
222.3352 +  for(y=0; y<160 && y<o->h; y++) {
222.3353 +    p=(Uint8 *)pix+srcPitch*y;
222.3354 +    op=o->pixels[0]+o->pitches[0]*y;
222.3355 +    for(x=0; x<240 && x<o->w; x++) {
222.3356 +      RGBtoYUV(p,yuv);
222.3357 +      if(x%2==0) {
222.3358 +        *(op++)=yuv[1];
222.3359 +        *(op++)=yuv[0];
222.3360 +        *(op++)=yuv[2];
222.3361 +      } else
222.3362 +        *(op++)=yuv[0];
222.3363 +      
222.3364 +      p+=4; //s->format->BytesPerPixel;
222.3365 +    }
222.3366 +  }
222.3367 +  
222.3368 +  SDL_UnlockYUVOverlay(o);
222.3369 +}
222.3370 +
222.3371 +inline void ConvertRGBtoYVYU(SDL_Overlay *o)
222.3372 +{
222.3373 +  int x,y;
222.3374 +  int yuv[3];
222.3375 +  Uint8 *p,*op;
222.3376 +  
222.3377 +  SDL_LockYUVOverlay(o);
222.3378 +  
222.3379 +  for(y=0; y<160 && y<o->h; y++) {
222.3380 +    p=(Uint8 *)pix+srcPitch*y;
222.3381 +    op=o->pixels[0]+o->pitches[0]*y;
222.3382 +    for(x=0; x<240 && x<o->w; x++) {
222.3383 +      RGBtoYUV(p,yuv);
222.3384 +      if(x%2==0) {
222.3385 +        *(op++)=yuv[0];
222.3386 +        *(op++)=yuv[2];
222.3387 +        op[1]=yuv[1];
222.3388 +      } else {
222.3389 +        *op=yuv[0];
222.3390 +        op+=2;
222.3391 +      }
222.3392 +      
222.3393 +      p+=4; //s->format->BytesPerPixel;
222.3394 +    }
222.3395 +  }
222.3396 +  
222.3397 +  SDL_UnlockYUVOverlay(o);
222.3398 +}
222.3399 +
222.3400 +inline void ConvertRGBtoYUY2(SDL_Overlay *o)
222.3401 +{
222.3402 +  int x,y;
222.3403 +  int yuv[3];
222.3404 +  Uint8 *p,*op;
222.3405 +  
222.3406 +  SDL_LockYUVOverlay(o);
222.3407 +  
222.3408 +  for(y=0; y<160 && y<o->h; y++) {
222.3409 +    p=(Uint8 *)pix+srcPitch*y;
222.3410 +    op=o->pixels[0]+o->pitches[0]*y;
222.3411 +    for(x=0; x<240 && x<o->w; x++) {
222.3412 +      RGBtoYUV(p,yuv);
222.3413 +      if(x%2==0) {
222.3414 +        *(op++)=yuv[0];
222.3415 +        *(op++)=yuv[1];
222.3416 +        op[1]=yuv[2];
222.3417 +      } else {
222.3418 +        *op=yuv[0];
222.3419 +        op+=2;
222.3420 +      }
222.3421 +      
222.3422 +      p+=4; //s->format->BytesPerPixel;
222.3423 +    }
222.3424 +  }
222.3425 +  
222.3426 +  SDL_UnlockYUVOverlay(o);
222.3427 +}
222.3428 +
222.3429 +inline void Convert32bit(SDL_Surface *display)
222.3430 +{
222.3431 +  switch(overlay->format) {
222.3432 +  case SDL_YV12_OVERLAY:
222.3433 +    ConvertRGBtoYV12(overlay);
222.3434 +    break;
222.3435 +  case SDL_UYVY_OVERLAY:
222.3436 +    ConvertRGBtoUYVY(overlay);
222.3437 +    break;
222.3438 +  case SDL_YVYU_OVERLAY:
222.3439 +    ConvertRGBtoYVYU(overlay);
222.3440 +    break;
222.3441 +  case SDL_YUY2_OVERLAY:
222.3442 +    ConvertRGBtoYUY2(overlay);
222.3443 +    break;
222.3444 +  case SDL_IYUV_OVERLAY:
222.3445 +    ConvertRGBtoIYUV(overlay);
222.3446 +    break;
222.3447 +  default:
222.3448 +    fprintf(stderr, "cannot convert RGB picture to obtained YUV format!\n");
222.3449 +    exit(1);
222.3450 +    break;
222.3451 +  }
222.3452 +  
222.3453 +}
222.3454 +
222.3455 +
222.3456 +inline void Draw_Overlay(SDL_Surface *display, int size)
222.3457 +{
222.3458 +  SDL_LockYUVOverlay(overlay);
222.3459 +  
222.3460 +  Convert32bit(display);
222.3461 +  
222.3462 +  overlay_rect.x = 0;
222.3463 +  overlay_rect.y = 0;
222.3464 +  overlay_rect.w = GBA_WIDTH  * size;
222.3465 +  overlay_rect.h = GBA_HEIGHT * size;
222.3466 +
222.3467 +  SDL_DisplayYUVOverlay(overlay, &overlay_rect);
222.3468 +  SDL_UnlockYUVOverlay(overlay);
222.3469 +}
222.3470 +
222.3471 +bool systemIsEmulating()
222.3472 +{
222.3473 +	return emulating != 0;
222.3474 +}
222.3475 +
222.3476 +void systemGbBorderOn()
222.3477 +{
222.3478 +  srcWidth = 256;
222.3479 +  srcHeight = 224;
222.3480 +  gbBorderLineSkip = 256;
222.3481 +  gbBorderColumnSkip = 48;
222.3482 +  gbBorderRowSkip = 40;
222.3483 +
222.3484 +  destWidth = (sizeOption+1)*srcWidth;
222.3485 +  destHeight = (sizeOption+1)*srcHeight;
222.3486 +  
222.3487 +  surface = SDL_SetVideoMode(destWidth, destHeight, 16,
222.3488 +                             SDL_ANYFORMAT|SDL_HWSURFACE|SDL_DOUBLEBUF|
222.3489 +                             (fullscreen ? SDL_FULLSCREEN : 0));  
222.3490 +#ifndef C_CORE
222.3491 +  sdlMakeStretcher(srcWidth);
222.3492 +#else
222.3493 +  switch(systemColorDepth) {
222.3494 +  case 16:
222.3495 +    sdlStretcher = sdlStretcher16[sizeOption];
222.3496 +    break;
222.3497 +  case 24:
222.3498 +    sdlStretcher = sdlStretcher24[sizeOption];
222.3499 +    break;
222.3500 +  case 32:
222.3501 +    sdlStretcher = sdlStretcher32[sizeOption];
222.3502 +    break;
222.3503 +  default:
222.3504 +    fprintf(stderr, "Unsupported resolution: %d\n", systemColorDepth);
222.3505 +    exit(-1);
222.3506 +  }
222.3507 +#endif
222.3508 +
222.3509 +  if(systemColorDepth == 16) {
222.3510 +    if(sdlCalculateMaskWidth(surface->format->Gmask) == 6) {
222.3511 +      Init_2xSaI(565);
222.3512 +      RGB_LOW_BITS_MASK = 0x821;
222.3513 +    } else {
222.3514 +      Init_2xSaI(555);
222.3515 +      RGB_LOW_BITS_MASK = 0x421;      
222.3516 +    }
222.3517 +    if(systemCartridgeType == 2) {
222.3518 +      for(int i = 0; i < 0x10000; i++) {
222.3519 +        systemColorMap16[i] = (((i >> 1) & 0x1f) << systemBlueShift) |
222.3520 +          (((i & 0x7c0) >> 6) << systemGreenShift) |
222.3521 +          (((i & 0xf800) >> 11) << systemRedShift);  
222.3522 +      }      
222.3523 +    } else {
222.3524 +      for(int i = 0; i < 0x10000; i++) {
222.3525 +        systemColorMap16[i] = ((i & 0x1f) << systemRedShift) |
222.3526 +          (((i & 0x3e0) >> 5) << systemGreenShift) |
222.3527 +          (((i & 0x7c00) >> 10) << systemBlueShift);  
222.3528 +      }
222.3529 +    }
222.3530 +    srcPitch = srcWidth * 2+4;
222.3531 +  } else {
222.3532 +    if(systemColorDepth != 32)
222.3533 +      filterFunction = NULL;
222.3534 +    RGB_LOW_BITS_MASK = 0x010101;
222.3535 +    if(systemColorDepth == 32) {
222.3536 +      Init_2xSaI(32);
222.3537 +    }
222.3538 +    for(int i = 0; i < 0x10000; i++) {
222.3539 +      systemColorMap32[i] = ((i & 0x1f) << systemRedShift) |
222.3540 +        (((i & 0x3e0) >> 5) << systemGreenShift) |
222.3541 +        (((i & 0x7c00) >> 10) << systemBlueShift);  
222.3542 +    }
222.3543 +    if(systemColorDepth == 32)
222.3544 +      srcPitch = srcWidth*4 + 4;
222.3545 +    else
222.3546 +      srcPitch = srcWidth*3;
222.3547 +  }
222.3548 +}
222.3549 +
222.3550 +bool systemIsRunningGBA()
222.3551 +{
222.3552 +	return (rom != NULL);
222.3553 +}
222.3554 +
222.3555 +int systemGetDefaultJoypad()
222.3556 +{
222.3557 +	return sdlDefaultJoypad;
222.3558 +}
222.3559 +
222.3560 +bool systemIsPaused()
222.3561 +{
222.3562 +	return paused;
222.3563 +}
222.3564 +
222.3565 +void systemSetPause(bool pause)
222.3566 +{
222.3567 +	paused = pause;
222.3568 +	if (pause)
222.3569 +		systemSoundPause();
222.3570 +	else
222.3571 +		systemSoundResume();
222.3572 +}
222.3573 +
222.3574 +u16 checksumBIOS()
222.3575 +{
222.3576 +	bool hasBIOS = false;
222.3577 +	u8 * tempBIOS;
222.3578 +	if(useBios)
222.3579 +	{
222.3580 +		tempBIOS = (u8 *)malloc(0x4000);
222.3581 +		int size = 0x4000;
222.3582 +		if(utilLoad(biosFileName,
222.3583 +					utilIsGBABios,
222.3584 +					tempBIOS,
222.3585 +					size)) {
222.3586 +		if(size == 0x4000)
222.3587 +			hasBIOS = true;
222.3588 +		}
222.3589 +	}
222.3590 +
222.3591 +	u16 biosCheck = 0;
222.3592 +	if(hasBIOS) {
222.3593 +		for(int i = 0; i < 0x4000; i += 4)
222.3594 +			biosCheck += *((u32 *)&tempBIOS[i]);
222.3595 +		free(tempBIOS);
222.3596 +	}
222.3597 +
222.3598 +	return biosCheck;
222.3599 +}
222.3600 +
222.3601 +EmulatedSystemCounters systemCounters = {
222.3602 +	0,	//framecount
222.3603 +	0,	//lagcount
222.3604 +	0,	//extracount
222.3605 +	true,	//lagged
222.3606 +	true	//laggedLast
222.3607 +};
222.3608 +
222.3609 +void VBAOnEnteringFrameBoundary()
222.3610 +{
222.3611 +	CallRegisteredLuaFunctions(LUACALL_AFTEREMULATION);
222.3612 +
222.3613 +	if (VBALuaRunning())
222.3614 +	{
222.3615 +		VBALuaFrameBoundary();
222.3616 +	}
222.3617 +
222.3618 +	VBAMovieUpdateState();
222.3619 +}
222.3620 +
222.3621 +void VBAOnExitingFrameBoundary()
222.3622 +{
222.3623 +	;
222.3624 +}
222.3625 +
222.3626 +
   223.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   223.2 +++ b/src/sdl/SoundDriver.h	Sat Mar 03 10:31:27 2012 -0600
   223.3 @@ -0,0 +1,65 @@
   223.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   223.5 +// Copyright (C) 2008 VBA-M development team
   223.6 +
   223.7 +// This program is free software; you can redistribute it and/or modify
   223.8 +// it under the terms of the GNU General Public License as published by
   223.9 +// the Free Software Foundation; either version 2, or(at your option)
  223.10 +// any later version.
  223.11 +//
  223.12 +// This program is distributed in the hope that it will be useful,
  223.13 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  223.14 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  223.15 +// GNU General Public License for more details.
  223.16 +//
  223.17 +// You should have received a copy of the GNU General Public License
  223.18 +// along with this program; if not, write to the Free Software Foundation,
  223.19 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  223.20 +
  223.21 +#ifndef __VBA_SOUND_DRIVER_H__
  223.22 +#define __VBA_SOUND_DRIVER_H__
  223.23 +
  223.24 +#include "Types.h"
  223.25 +
  223.26 +/**
  223.27 + * Sound driver abstract interface for the core to use to output sound.
  223.28 + * Subclass this to implement a new sound driver.
  223.29 + */
  223.30 +class SoundDriver
  223.31 +{
  223.32 +public:
  223.33 +
  223.34 +	/**
  223.35 +	 * Destructor. Free the resources allocated by the sound driver.
  223.36 +	 */
  223.37 +	virtual ~SoundDriver() { };
  223.38 +
  223.39 +	/**
  223.40 +	 * Initialize the sound driver.
  223.41 +	 * @param sampleRate In Hertz
  223.42 +	 */
  223.43 +	virtual bool init() = 0;
  223.44 +
  223.45 +	/**
  223.46 +	 * Tell the driver that the sound stream has paused
  223.47 +	 */
  223.48 +	virtual void pause() = 0;
  223.49 +
  223.50 +	/**
  223.51 +	 * Reset the sound driver
  223.52 +	 */
  223.53 +	virtual void reset() = 0;
  223.54 +
  223.55 +	/**
  223.56 +	 * Tell the driver that the sound stream has resumed
  223.57 +	 */
  223.58 +	virtual void resume() = 0;
  223.59 +
  223.60 +	/**
  223.61 +	 * Write length bytes of data from the finalWave buffer to the driver output buffer.
  223.62 +	 */
  223.63 +	virtual void write(u16 * finalWave, int length) = 0;
  223.64 +
  223.65 +	virtual bool setThrottle(unsigned short throttle) = 0;
  223.66 +};
  223.67 +
  223.68 +#endif // __VBA_SOUND_DRIVER_H__
   224.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   224.2 +++ b/src/sdl/SoundSDL.cpp	Sat Mar 03 10:31:27 2012 -0600
   224.3 @@ -0,0 +1,178 @@
   224.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   224.5 +// Copyright (C) 2008 VBA-M development team
   224.6 +
   224.7 +// This program is free software; you can redistribute it and/or modify
   224.8 +// it under the terms of the GNU General Public License as published by
   224.9 +// the Free Software Foundation; either version 2, or(at your option)
  224.10 +// any later version.
  224.11 +//
  224.12 +// This program is distributed in the hope that it will be useful,
  224.13 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  224.14 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  224.15 +// GNU General Public License for more details.
  224.16 +//
  224.17 +// You should have received a copy of the GNU General Public License
  224.18 +// along with this program; if not, write to the Free Software Foundation,
  224.19 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  224.20 +
  224.21 +#include "SoundSDL.h"
  224.22 +
  224.23 +extern int emulating;
  224.24 +extern bool speedup;
  224.25 +
  224.26 +// Hold up to 100 ms of data in the ring buffer
  224.27 +const float SoundSDL::_delay = 0.1f;
  224.28 +
  224.29 +SoundSDL::SoundSDL():
  224.30 +	_rbuf(0),
  224.31 +	_initialized(false)
  224.32 +{
  224.33 +
  224.34 +}
  224.35 +
  224.36 +void SoundSDL::soundCallback(void *data, u8 *stream, int len)
  224.37 +{
  224.38 +	reinterpret_cast<SoundSDL*>(data)->read(reinterpret_cast<u16 *>(stream), len);
  224.39 +}
  224.40 +
  224.41 +void SoundSDL::read(u16 * stream, int length)
  224.42 +{
  224.43 +	if (!_initialized || length <= 0 || !emulating)
  224.44 +		return;
  224.45 +
  224.46 +	SDL_mutexP(_mutex);
  224.47 +	_rbuf.read(stream, std::min(static_cast<std::size_t>(length) / 2, _rbuf.used()));
  224.48 +
  224.49 +	SDL_CondSignal(_cond);
  224.50 +	SDL_mutexV(_mutex);
  224.51 +}
  224.52 +
  224.53 +void SoundSDL::write(u16 * finalWave, int length)
  224.54 +{
  224.55 +	if (!_initialized)
  224.56 +		return;
  224.57 +
  224.58 +	if (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING)
  224.59 +		SDL_PauseAudio(0);
  224.60 +
  224.61 +	SDL_mutexP(_mutex);
  224.62 +
  224.63 +	unsigned int samples = length / 4;
  224.64 +
  224.65 +	std::size_t avail;
  224.66 +	while ((avail = _rbuf.avail() / 2) < samples)
  224.67 +	{
  224.68 +		_rbuf.write(finalWave, avail * 2);
  224.69 +
  224.70 +		finalWave += avail * 2;
  224.71 +		samples -= avail;
  224.72 +
  224.73 +		// If emulating and not in speed up mode, synchronize to audio
  224.74 +		// by waiting till there is enough room in the buffer
  224.75 +		if (emulating && !speedup)
  224.76 +		{
  224.77 +			SDL_CondWait(_cond,_mutex);
  224.78 +		}
  224.79 +		else
  224.80 +		{
  224.81 +			// Drop the remaining of the audio data
  224.82 +			SDL_mutexV(_mutex);
  224.83 +			return;
  224.84 +		}
  224.85 +	}
  224.86 +
  224.87 +	_rbuf.write(finalWave, samples * 2);
  224.88 +
  224.89 +	SDL_mutexV(_mutex);
  224.90 +}
  224.91 +
  224.92 +
  224.93 +bool SoundSDL::init()
  224.94 +{
  224.95 +	SDL_AudioSpec audio;
  224.96 +	audio.freq = SDL_SAMPLE_RATE;
  224.97 +	audio.format = AUDIO_S16SYS;
  224.98 +	audio.channels = 2;
  224.99 +	audio.samples = 1024;
 224.100 +	audio.callback = soundCallback;
 224.101 +	audio.userdata = this;
 224.102 +
 224.103 +	if(SDL_OpenAudio(&audio, NULL))
 224.104 +	{
 224.105 +		fprintf(stderr,"Failed to open audio: %s\n", SDL_GetError());
 224.106 +		return false;
 224.107 +	}
 224.108 +
 224.109 +	_rbuf.reset(_delay * SDL_SAMPLE_RATE * 2);
 224.110 +
 224.111 +	_cond  = SDL_CreateCond();
 224.112 +	_mutex = SDL_CreateMutex();
 224.113 +	_initialized = true;
 224.114 +
 224.115 +	return true;
 224.116 +}
 224.117 +
 224.118 +SoundSDL::~SoundSDL()
 224.119 +{
 224.120 +	if (!_initialized)
 224.121 +		return;
 224.122 +
 224.123 +	SDL_mutexP(_mutex);
 224.124 +	int iSave = emulating;
 224.125 +	emulating = 0;
 224.126 +	SDL_CondSignal(_cond);
 224.127 +	SDL_mutexV(_mutex);
 224.128 +
 224.129 +	SDL_DestroyCond(_cond);
 224.130 +	_cond = NULL;
 224.131 +
 224.132 +	SDL_DestroyMutex(_mutex);
 224.133 +	_mutex = NULL;
 224.134 +
 224.135 +	SDL_CloseAudio();
 224.136 +
 224.137 +	emulating = iSave;
 224.138 +}
 224.139 +
 224.140 +void SoundSDL::pause()
 224.141 +{
 224.142 +	if (!_initialized)
 224.143 +		return;
 224.144 +
 224.145 +	SDL_PauseAudio(1);
 224.146 +}
 224.147 +
 224.148 +void SoundSDL::resume()
 224.149 +{
 224.150 +	if (!_initialized)
 224.151 +		return;
 224.152 +
 224.153 +	SDL_PauseAudio(0);
 224.154 +}
 224.155 +
 224.156 +void SoundSDL::reset()
 224.157 +{
 224.158 +}
 224.159 +
 224.160 +bool SoundSDL::setThrottle(unsigned short throttle){
 224.161 +	switch(throttle){
 224.162 +		case 25:
 224.163 +		case 50:
 224.164 +		case 100:
 224.165 +		case 200:
 224.166 +		case 400:
 224.167 +			break;
 224.168 +		default:
 224.169 +			return false;
 224.170 +	}
 224.171 +	SDL_CloseAudio();
 224.172 +	SDL_AudioSpec audio;
 224.173 +	audio.freq = SDL_SAMPLE_RATE*throttle/100;
 224.174 +	audio.format = AUDIO_S16SYS;
 224.175 +	audio.channels = 2;
 224.176 +	audio.samples = 1024;
 224.177 +	audio.callback = soundCallback;
 224.178 +	audio.userdata = this;
 224.179 +	_rbuf.reset((_delay * SDL_SAMPLE_RATE * throttle * 2)/100);
 224.180 +	return !SDL_OpenAudio(&audio,NULL);
 224.181 +}
   225.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   225.2 +++ b/src/sdl/SoundSDL.h	Sat Mar 03 10:31:27 2012 -0600
   225.3 @@ -0,0 +1,56 @@
   225.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   225.5 +// Copyright (C) 2008 VBA-M development team
   225.6 +
   225.7 +// This program is free software; you can redistribute it and/or modify
   225.8 +// it under the terms of the GNU General Public License as published by
   225.9 +// the Free Software Foundation; either version 2, or(at your option)
  225.10 +// any later version.
  225.11 +//
  225.12 +// This program is distributed in the hope that it will be useful,
  225.13 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  225.14 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  225.15 +// GNU General Public License for more details.
  225.16 +//
  225.17 +// You should have received a copy of the GNU General Public License
  225.18 +// along with this program; if not, write to the Free Software Foundation,
  225.19 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  225.20 +
  225.21 +#ifndef __VBA_SOUND_SDL_H__
  225.22 +#define __VBA_SOUND_SDL_H__
  225.23 +
  225.24 +#include "SoundDriver.h"
  225.25 +#include "RingBuffer.h"
  225.26 +
  225.27 +#include <SDL.h>
  225.28 +
  225.29 +const int SDL_SAMPLE_RATE = 44100;
  225.30 +
  225.31 +class SoundSDL: public SoundDriver
  225.32 +{
  225.33 +public:
  225.34 +	SoundSDL();
  225.35 +	virtual ~SoundSDL();
  225.36 +
  225.37 +	virtual bool init();
  225.38 +	virtual void pause();
  225.39 +	virtual void reset();
  225.40 +	virtual void resume();
  225.41 +	virtual void write(u16 * finalWave, int length);
  225.42 +	virtual bool setThrottle(unsigned short throttle);
  225.43 +
  225.44 +//private:
  225.45 +	RingBuffer<u16> _rbuf;
  225.46 +
  225.47 +	SDL_cond  * _cond;
  225.48 +	SDL_mutex * _mutex;
  225.49 +
  225.50 +	bool _initialized;
  225.51 +
  225.52 +	// Defines what delay in seconds we keep in the sound buffer
  225.53 +	static const float _delay;
  225.54 +
  225.55 +	static void soundCallback(void *data, u8 *stream, int length);
  225.56 +	virtual void read(u16 * stream, int length);
  225.57 +};
  225.58 +
  225.59 +#endif // __VBA_SOUND_SDL_H__
   226.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   226.2 +++ b/src/sdl/TestEmu.cpp	Sat Mar 03 10:31:27 2012 -0600
   226.3 @@ -0,0 +1,501 @@
   226.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   226.5 +// Copyright (C) 1999-2003 Forgotten
   226.6 +// Copyright (C) 2004 Forgotten and the VBA development team
   226.7 +
   226.8 +// This program is free software; you can redistribute it and/or modify
   226.9 +// it under the terms of the GNU General Public License as published by
  226.10 +// the Free Software Foundation; either version 2, or(at your option)
  226.11 +// any later version.
  226.12 +//
  226.13 +// This program is distributed in the hope that it will be useful,
  226.14 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  226.15 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  226.16 +// GNU General Public License for more details.
  226.17 +//
  226.18 +// You should have received a copy of the GNU General Public License
  226.19 +// along with this program; if not, write to the Free Software Foundation,
  226.20 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  226.21 +
  226.22 +#include <stdarg.h>
  226.23 +#include <stdlib.h>
  226.24 +#include <stdio.h>
  226.25 +#include <string.h>
  226.26 +#include <sys/types.h>
  226.27 +#include <sys/stat.h>
  226.28 +
  226.29 +#include "AutoBuild.h"
  226.30 +
  226.31 +#include "SDL.h"
  226.32 +#include "debugger.h"
  226.33 +#include "common/System.h"
  226.34 +#include "common/unzip.h"
  226.35 +#include "common/Util.h"
  226.36 +#include "gba/GBA.h"
  226.37 +#include "gba/GBAGlobals.h"
  226.38 +#include "gba/GBASound.h"
  226.39 +#include "gb/GB.h"
  226.40 +#include "gb/gbGlobals.h"
  226.41 +
  226.42 +#ifndef WIN32
  226.43 +# include <unistd.h>
  226.44 +# define GETCWD getcwd
  226.45 +#else // WIN32
  226.46 +# include <direct.h>
  226.47 +# define GETCWD _getcwd
  226.48 +#endif // WIN32
  226.49 +
  226.50 +#ifdef MMX
  226.51 +extern "C" bool cpu_mmx;
  226.52 +#endif
  226.53 +extern bool8 soundEcho;
  226.54 +extern bool8 soundLowPass;
  226.55 +extern bool8 soundReverse;
  226.56 +
  226.57 +extern void remoteInit();
  226.58 +extern void remoteCleanUp();
  226.59 +extern void remoteStubMain();
  226.60 +extern void remoteStubSignal(int,int);
  226.61 +extern void remoteOutput(char *, u32);
  226.62 +extern void remoteSetProtocol(int);
  226.63 +extern void remoteSetPort(int);
  226.64 +extern void debuggerOutput(char *, u32);
  226.65 +
  226.66 +struct EmulatedSystem emulator;
  226.67 +
  226.68 +int systemRedShift = 0;
  226.69 +int systemBlueShift = 16;
  226.70 +int systemGreenShift = 8;
  226.71 +int systemColorDepth = 32;
  226.72 +int systemDebug = 0;
  226.73 +int systemVerbose = 0;
  226.74 +int systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
  226.75 +
  226.76 +int sensorX = 2047;
  226.77 +int sensorY = 2047;
  226.78 +bool sensorOn = false;
  226.79 +
  226.80 +int cartridgeType = 3;
  226.81 +int captureFormat = 0;
  226.82 +
  226.83 +int emulating = 0;
  226.84 +int RGB_LOW_BITS_MASK=0x821;
  226.85 +int systemFrameSkip = 0;
  226.86 +u32 systemColorMap32[0x10000];
  226.87 +u16 systemColorMap16[0x10000];
  226.88 +u16 systemGbPalette[24];
  226.89 +char filename[2048];
  226.90 +char biosFileName[2048];
  226.91 +char captureDir[2048];
  226.92 +char saveDir[2048];
  226.93 +char batteryDir[2048];
  226.94 +
  226.95 +int throttle = 0;
  226.96 +
  226.97 +bool paused = false;
  226.98 +bool debugger = true;
  226.99 +bool debuggerStub = false;
 226.100 +bool systemSoundOn = false;
 226.101 +bool removeIntros = false;
 226.102 +int sdlFlashSize = 0;
 226.103 +int sdlAutoIPS = 1;
 226.104 +int sdlRtcEnable = 0;
 226.105 +int sdlAgbPrint = 0;
 226.106 +
 226.107 +int sdlDefaultJoypad = 0;
 226.108 +
 226.109 +u16 motion[4] = {
 226.110 +  SDLK_KP4, SDLK_KP6, SDLK_KP8, SDLK_KP2
 226.111 +};
 226.112 +
 226.113 +extern void debuggerSignal(int,int);
 226.114 +
 226.115 +void (*dbgMain)() = debuggerMain;
 226.116 +void (*dbgSignal)(int,int) = debuggerSignal;
 226.117 +void (*dbgOutput)(char *, u32) = debuggerOutput;
 226.118 +
 226.119 +char *sdlGetFilename(char *name)
 226.120 +{
 226.121 +  static char filebuffer[2048];
 226.122 +
 226.123 +  int len = strlen(name);
 226.124 +  
 226.125 +  char *p = name + len - 1;
 226.126 +  
 226.127 +  while(true) {
 226.128 +    if(*p == '/' ||
 226.129 +       *p == '\\') {
 226.130 +      p++;
 226.131 +      break;
 226.132 +    }
 226.133 +    len--;
 226.134 +    p--;
 226.135 +    if(len == 0)
 226.136 +      break;
 226.137 +  }
 226.138 +  
 226.139 +  if(len == 0)
 226.140 +    strcpy(filebuffer, name);
 226.141 +  else
 226.142 +    strcpy(filebuffer, p);
 226.143 +  return filebuffer;
 226.144 +}
 226.145 +
 226.146 +void usage(char *cmd)
 226.147 +{
 226.148 +  printf("%s file-name\n",cmd);
 226.149 +}
 226.150 +
 226.151 +int main(int argc, char **argv)
 226.152 +{
 226.153 +  fprintf(stderr,"VisualBoyAdvance-Test version %s\n", VERSION);
 226.154 +
 226.155 +  captureDir[0] = 0;
 226.156 +  saveDir[0] = 0;
 226.157 +  batteryDir[0] = 0;
 226.158 +  
 226.159 +  char buffer[1024];
 226.160 +
 226.161 +  systemFrameSkip = frameSkip = 2;
 226.162 +  gbBorderOn = 0;
 226.163 +
 226.164 +  parseDebug = true;
 226.165 +
 226.166 +  if(!debuggerStub) {
 226.167 +    if(argc <= 1) {
 226.168 +      systemMessage(0,"Missing image name");
 226.169 +      usage(argv[0]);
 226.170 +      exit(-1);
 226.171 +    }
 226.172 +  }
 226.173 +
 226.174 +  for(int i = 0; i < 24;) {
 226.175 +    systemGbPalette[i++] = (0x1f) | (0x1f << 5) | (0x1f << 10);
 226.176 +    systemGbPalette[i++] = (0x15) | (0x15 << 5) | (0x15 << 10);
 226.177 +    systemGbPalette[i++] = (0x0c) | (0x0c << 5) | (0x0c << 10);
 226.178 +    systemGbPalette[i++] = 0;
 226.179 +  }
 226.180 +
 226.181 +  if(argc == 2) {
 226.182 +    char *szFile = argv[optind];
 226.183 +    bool failed = false;
 226.184 +    if(utilIsZipFile(szFile)) {
 226.185 +      unzFile unz = unzOpen(szFile);
 226.186 +      
 226.187 +      if(unz == NULL) {
 226.188 +        systemMessage(0, "Cannot open file %s", szFile);
 226.189 +        exit(-1);
 226.190 +      }
 226.191 +      int r = unzGoToFirstFile(unz);
 226.192 +      
 226.193 +      if(r != UNZ_OK) {
 226.194 +        unzClose(unz);
 226.195 +        systemMessage(0, "Bad ZIP file %s", szFile);
 226.196 +        exit(-1);
 226.197 +      }
 226.198 +      
 226.199 +      bool found = false;
 226.200 +      
 226.201 +      unz_file_info info;
 226.202 +      
 226.203 +      while(true) {
 226.204 +        r = unzGetCurrentFileInfo(unz,
 226.205 +                                  &info,
 226.206 +                                  buffer,
 226.207 +                                  sizeof(buffer),
 226.208 +                                  NULL,
 226.209 +                                  0,
 226.210 +                                  NULL,
 226.211 +                                  0);
 226.212 +        
 226.213 +        if(r != UNZ_OK) {
 226.214 +          unzClose(unz);
 226.215 +          systemMessage(0,"Bad ZIP file %s", szFile);
 226.216 +          exit(-1);
 226.217 +        }
 226.218 +        
 226.219 +        if(utilIsGBImage(buffer)) {
 226.220 +          found = true;
 226.221 +          cartridgeType = 1;
 226.222 +          break;
 226.223 +        }
 226.224 +        if(utilIsGBAImage(buffer)) {
 226.225 +          found = true;
 226.226 +          cartridgeType = 0;
 226.227 +          break;
 226.228 +        }
 226.229 +        
 226.230 +        r = unzGoToNextFile(unz);
 226.231 +        
 226.232 +        if(r != UNZ_OK)
 226.233 +          break;
 226.234 +      }
 226.235 +      
 226.236 +      if(!found) {
 226.237 +        unzClose(unz);
 226.238 +        systemMessage(0, "No image found on ZIP file %s", szFile);
 226.239 +        exit(-1);
 226.240 +      }
 226.241 +      
 226.242 +      unzClose(unz);
 226.243 +    }
 226.244 +    
 226.245 +    if(utilIsGBImage(szFile) || cartridgeType == 1) {
 226.246 +      failed = !gbLoadRom(szFile);
 226.247 +      cartridgeType = 1;
 226.248 +      emulator = GBSystem;
 226.249 +    } else if(utilIsGBAImage(szFile) || cartridgeType == 0) {
 226.250 +      failed = !CPULoadRom(szFile);
 226.251 +      cartridgeType = 0;
 226.252 +      emulator = GBASystem;
 226.253 +
 226.254 +      //CPUInit(biosFileName, useBios);
 226.255 +      CPUInit();
 226.256 +      CPUReset();
 226.257 +    } else {
 226.258 +      systemMessage(0, "Unknown file type %s", szFile);
 226.259 +      exit(-1);
 226.260 +    }
 226.261 +    
 226.262 +    if(failed) {
 226.263 +      systemMessage(0, "Failed to load file %s", szFile);
 226.264 +      exit(-1);
 226.265 +    }
 226.266 +    strcpy(filename, szFile);
 226.267 +    char *p = strrchr(filename, '.');
 226.268 +    
 226.269 +    if(p)
 226.270 +      *p = 0;
 226.271 +  } else {
 226.272 +    cartridgeType = 0;
 226.273 +    strcpy(filename, "gnu_stub");
 226.274 +    rom = (u8 *)malloc(0x2000000);
 226.275 +    workRAM = (u8 *)calloc(1, 0x40000);
 226.276 +    bios = (u8 *)calloc(1,0x4000);
 226.277 +    internalRAM = (u8 *)calloc(1,0x8000);
 226.278 +    paletteRAM = (u8 *)calloc(1,0x400);
 226.279 +    vram = (u8 *)calloc(1, 0x20000);
 226.280 +    oam = (u8 *)calloc(1, 0x400);
 226.281 +    pix = (u8 *)calloc(1, 4 * 240 * 160);
 226.282 +    ioMem = (u8 *)calloc(1, 0x400);
 226.283 +
 226.284 +    emulator = GBASystem;
 226.285 +    
 226.286 +    //CPUInit(biosFileName, useBios);
 226.287 +    CPUInit();
 226.288 +    CPUReset();    
 226.289 +  }
 226.290 +  
 226.291 +  if(debuggerStub) 
 226.292 +    remoteInit();
 226.293 +  
 226.294 +  if(cartridgeType == 0) {
 226.295 +  } else if (cartridgeType == 1) {
 226.296 +    if(gbBorderOn) {
 226.297 +      gbBorderLineSkip = 256;
 226.298 +      gbBorderColumnSkip = 48;
 226.299 +      gbBorderRowSkip = 40;
 226.300 +    } else {      
 226.301 +      gbBorderLineSkip = 160;
 226.302 +      gbBorderColumnSkip = 0;
 226.303 +      gbBorderRowSkip = 0;
 226.304 +    }      
 226.305 +  } else {
 226.306 +  }
 226.307 +
 226.308 +  for(int i = 0; i < 0x10000; i++) {
 226.309 +    systemColorMap32[i] = ((i & 0x1f) << systemRedShift) |
 226.310 +      (((i & 0x3e0) >> 5) << systemGreenShift) |
 226.311 +      (((i & 0x7c00) >> 10) << systemBlueShift);  
 226.312 +  }
 226.313 +
 226.314 +  emulating = 1;
 226.315 +  soundInit();
 226.316 +  
 226.317 +  while(emulating) {
 226.318 +    if(!paused) {
 226.319 +      if(debugger && emulator.emuHasDebugger)
 226.320 +        dbgMain();
 226.321 +      else
 226.322 +        emulator.emuMain(emulator.emuCount);
 226.323 +    }
 226.324 +  }
 226.325 +  emulating = 0;
 226.326 +  fprintf(stderr,"Shutting down\n");
 226.327 +  remoteCleanUp();
 226.328 +  soundShutdown();
 226.329 +
 226.330 +  if(gbRom != NULL || rom != NULL) {
 226.331 +    emulator.emuCleanUp();
 226.332 +  }
 226.333 +
 226.334 +  return 0;
 226.335 +}
 226.336 +
 226.337 +void systemMessage(int num, const char *msg, ...)
 226.338 +{
 226.339 +  char buffer[2048];
 226.340 +  va_list valist;
 226.341 +  
 226.342 +  va_start(valist, msg);
 226.343 +  vsprintf(buffer, msg, valist);
 226.344 +  
 226.345 +  fprintf(stderr, "%s\n", buffer);
 226.346 +  va_end(valist);
 226.347 +}
 226.348 +
 226.349 +void systemDrawScreen()
 226.350 +{
 226.351 +}
 226.352 +
 226.353 +bool systemReadJoypads()
 226.354 +{
 226.355 +  return true;
 226.356 +}
 226.357 +
 226.358 +u32 systemReadJoypad(int,bool)
 226.359 +{
 226.360 +  return 0;
 226.361 +}
 226.362 +
 226.363 +void systemShowSpeed(int speed)
 226.364 +{
 226.365 +}
 226.366 +
 226.367 +void system10Frames(int rate)
 226.368 +{
 226.369 +}
 226.370 +
 226.371 +void systemFrame(int)
 226.372 +{
 226.373 +}
 226.374 +
 226.375 +void systemSetTitle(const char *title)
 226.376 +{
 226.377 +}
 226.378 +
 226.379 +int systemScreenCapture(int a)
 226.380 +{
 226.381 +  char buffer[2048];
 226.382 +
 226.383 +  if(captureFormat) {
 226.384 +    if(captureDir[0])
 226.385 +      sprintf(buffer, "%s/%s%02d.bmp", captureDir, sdlGetFilename(filename), a);
 226.386 +    else
 226.387 +      sprintf(buffer, "%s%02d.bmp", filename, a);
 226.388 +
 226.389 +    emulator.emuWriteBMP(buffer);
 226.390 +  } else {
 226.391 +    if(captureDir[0])
 226.392 +      sprintf(buffer, "%s/%s%02d.png", captureDir, sdlGetFilename(filename), a);
 226.393 +    else
 226.394 +      sprintf(buffer, "%s%02d.png", filename, a);
 226.395 +    emulator.emuWritePNG(buffer);
 226.396 +  }
 226.397 +
 226.398 +  systemScreenMessage("Screen capture");
 226.399 +}
 226.400 +
 226.401 +u32 systemReadJoypadExtended()
 226.402 +{
 226.403 +  return 0;
 226.404 +}
 226.405 +
 226.406 +void systemWriteDataToSoundBuffer()
 226.407 +{
 226.408 +}
 226.409 +
 226.410 +bool systemSoundInit()
 226.411 +{
 226.412 +  return true;
 226.413 +}
 226.414 +
 226.415 +void systemSoundShutdown()
 226.416 +{
 226.417 +}
 226.418 +
 226.419 +void systemSoundPause()
 226.420 +{
 226.421 +}
 226.422 +
 226.423 +void systemSoundResume()
 226.424 +{
 226.425 +}
 226.426 +
 226.427 +void systemSoundReset()
 226.428 +{
 226.429 +}
 226.430 +
 226.431 +static int ticks = 0;
 226.432 +
 226.433 +u32 systemGetClock()
 226.434 +{
 226.435 +  return ticks++;
 226.436 +}
 226.437 +
 226.438 +void systemUpdateMotionSensor()
 226.439 +{
 226.440 +}
 226.441 +
 226.442 +int systemGetSensorX()
 226.443 +{
 226.444 +  return 0;
 226.445 +}
 226.446 +
 226.447 +int systemGetSensorY()
 226.448 +{
 226.449 +  return 0;
 226.450 +}
 226.451 +
 226.452 +void systemGbPrint(u8 *data,int pages,int feed,int palette, int contrast)
 226.453 +{
 226.454 +}
 226.455 +
 226.456 +void systemScreenMessage(const char *msg, int slot, int duration, const char *colorList)
 226.457 +{
 226.458 +}
 226.459 +
 226.460 +bool systemCanChangeSoundQuality()
 226.461 +{
 226.462 +  return false;
 226.463 +}
 226.464 +
 226.465 +bool systemPauseOnFrame()
 226.466 +{
 226.467 +  return false;
 226.468 +}
 226.469 +
 226.470 +void systemGbBorderOn()
 226.471 +{
 226.472 +}
 226.473 +
 226.474 +bool sdlCheckJoyKey(int)
 226.475 +{
 226.476 +  return true;
 226.477 +}
 226.478 +
 226.479 +u16 checksumBIOS()
 226.480 +{
 226.481 +	bool hasBIOS = false;
 226.482 +	u8 * tempBIOS;
 226.483 +	if(useBios)
 226.484 +	{
 226.485 +		tempBIOS = (u8 *)malloc(0x4000);
 226.486 +		int size = 0x4000;
 226.487 +		if(utilLoad(biosFileName,
 226.488 +					utilIsGBABios,
 226.489 +					tempBIOS,
 226.490 +					size)) {
 226.491 +		if(size == 0x4000)
 226.492 +			hasBIOS = true;
 226.493 +		}
 226.494 +	}
 226.495 +
 226.496 +	u16 biosCheck = 0;
 226.497 +	if(hasBIOS) {
 226.498 +		for(int i = 0; i < 0x4000; i += 4)
 226.499 +			biosCheck += *((u32 *)&tempBIOS[i]);
 226.500 +		free(tempBIOS);
 226.501 +	}
 226.502 +
 226.503 +	return biosCheck;
 226.504 +}
   227.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   227.2 +++ b/src/sdl/Types.h	Sat Mar 03 10:31:27 2012 -0600
   227.3 @@ -0,0 +1,33 @@
   227.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   227.5 +// Copyright (C) 2008 VBA-M development team
   227.6 +
   227.7 +// This program is free software; you can redistribute it and/or modify
   227.8 +// it under the terms of the GNU General Public License as published by
   227.9 +// the Free Software Foundation; either version 2, or(at your option)
  227.10 +// any later version.
  227.11 +//
  227.12 +// This program is distributed in the hope that it will be useful,
  227.13 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  227.14 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  227.15 +// GNU General Public License for more details.
  227.16 +//
  227.17 +// You should have received a copy of the GNU General Public License
  227.18 +// along with this program; if not, write to the Free Software Foundation,
  227.19 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  227.20 +
  227.21 +#ifndef __VBA_TYPES_H__
  227.22 +#define __VBA_TYPES_H__
  227.23 +
  227.24 +#include <stdint.h>
  227.25 +
  227.26 +typedef uint8_t u8;
  227.27 +typedef uint16_t u16;
  227.28 +typedef uint32_t u32;
  227.29 +typedef uint64_t u64;
  227.30 +
  227.31 +typedef int8_t s8;
  227.32 +typedef int16_t s16;
  227.33 +typedef int32_t s32;
  227.34 +typedef int64_t s64;
  227.35 +
  227.36 +#endif // __VBA_TYPES_H__
   228.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   228.2 +++ b/src/sdl/debugger.cpp	Sat Mar 03 10:31:27 2012 -0600
   228.3 @@ -0,0 +1,1460 @@
   228.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   228.5 +// Copyright (C) 1999-2003 Forgotten
   228.6 +// Copyright (C) 2004 Forgotten and the VBA development team
   228.7 +
   228.8 +// This program is free software; you can redistribute it and/or modify
   228.9 +// it under the terms of the GNU General Public License as published by
  228.10 +// the Free Software Foundation; either version 2, or(at your option)
  228.11 +// any later version.
  228.12 +//
  228.13 +// This program is distributed in the hope that it will be useful,
  228.14 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  228.15 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  228.16 +// GNU General Public License for more details.
  228.17 +//
  228.18 +// You should have received a copy of the GNU General Public License
  228.19 +// along with this program; if not, write to the Free Software Foundation,
  228.20 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  228.21 +
  228.22 +extern "C" {
  228.23 +#include <stdio.h>
  228.24 +#include <stdlib.h>
  228.25 +} // FIXME: should use c++ headers instead
  228.26 +
  228.27 +#include <string.h>
  228.28 +
  228.29 +#include "Port.h"
  228.30 +#include "gba/GBA.h"
  228.31 +#include "gba/GBAGlobals.h"
  228.32 +#include "gba/GBACheats.h"
  228.33 +#include "gba/armdis.h"
  228.34 +#include "gba/elf.h"
  228.35 +#include "common/System.h"
  228.36 +#include "exprNode.h"
  228.37 +
  228.38 +extern bool debugger;
  228.39 +extern int emulating;
  228.40 +
  228.41 +extern struct EmulatedSystem theEmulator;
  228.42 +
  228.43 +#define debuggerReadMemory(addr) \
  228.44 +  READ32LE((&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
  228.45 +
  228.46 +#define debuggerReadHalfWord(addr) \
  228.47 +  READ16LE((&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
  228.48 +
  228.49 +#define debuggerReadByte(addr) \
  228.50 +  map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]
  228.51 +
  228.52 +#define debuggerWriteMemory(addr, value) \
  228.53 +  WRITE32LE(&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask], value)
  228.54 +
  228.55 +#define debuggerWriteHalfWord(addr, value) \
  228.56 +  WRITE16LE(&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask], value)
  228.57 +
  228.58 +#define debuggerWriteByte(addr, value) \
  228.59 +  map[(addr)>>24].address[(addr) & map[(addr)>>24].mask] = (value)
  228.60 +
  228.61 +struct breakpointInfo {
  228.62 +  u32 address;
  228.63 +  u32 value;
  228.64 +  int size;
  228.65 +};
  228.66 +
  228.67 +struct DebuggerCommand {
  228.68 +  const char *name;
  228.69 +  void (*function)(int,char **);
  228.70 +  const char *help;
  228.71 +  const char *syntax;
  228.72 +};
  228.73 +
  228.74 +void debuggerContinueAfterBreakpoint();
  228.75 +
  228.76 +void debuggerHelp(int,char **);
  228.77 +void debuggerNext(int,char **);
  228.78 +void debuggerContinue(int, char **);
  228.79 +void debuggerRegisters(int, char **);
  228.80 +void debuggerBreak(int, char **);
  228.81 +void debuggerBreakDelete(int, char **);
  228.82 +void debuggerBreakList(int, char **);
  228.83 +void debuggerBreakArm(int, char **);
  228.84 +void debuggerBreakWriteClear(int, char **);
  228.85 +void debuggerBreakThumb(int, char **);
  228.86 +void debuggerBreakWrite(int, char **);
  228.87 +void debuggerDebug(int, char **);
  228.88 +void debuggerDisassemble(int, char **);
  228.89 +void debuggerDisassembleArm(int, char **);
  228.90 +void debuggerDisassembleThumb(int, char **);
  228.91 +void debuggerEditByte(int, char **);
  228.92 +void debuggerEditHalfWord(int, char **);
  228.93 +void debuggerEdit(int, char **);
  228.94 +void debuggerIo(int, char **);
  228.95 +void debuggerLocals(int, char **);
  228.96 +void debuggerMemoryByte(int, char **);
  228.97 +void debuggerMemoryHalfWord(int, char **);
  228.98 +void debuggerMemory(int, char **);
  228.99 +void debuggerPrint(int, char **);
 228.100 +void debuggerQuit(int, char **);
 228.101 +void debuggerSetRadix(int, char **);
 228.102 +void debuggerSymbols(int, char **);
 228.103 +void debuggerVerbose(int, char **);
 228.104 +void debuggerWhere(int, char **);
 228.105 +
 228.106 +DebuggerCommand debuggerCommands[] = {
 228.107 +  { "?", debuggerHelp,        "Shows this help information. Type ? <command> for command help", "[<command>]" },
 228.108 +  { "ba", debuggerBreakArm,   "Adds an ARM breakpoint", "<address>" },
 228.109 +  { "bd", debuggerBreakDelete,"Deletes a breakpoint", "<number>" },
 228.110 +  { "bl", debuggerBreakList,  "Lists breakpoints" },
 228.111 +  { "bpw", debuggerBreakWrite, "Break on write", "<address> <size>" },
 228.112 +  { "bpwc", debuggerBreakWriteClear, "Clear break on write", NULL },
 228.113 +  { "break", debuggerBreak,    "Adds a breakpoint on the given function", "<function>|<line>|<file:line>" },
 228.114 +  { "bt", debuggerBreakThumb, "Adds a THUMB breakpoint", "<address>" },
 228.115 +  { "c", debuggerContinue,    "Continues execution" , NULL },
 228.116 +  { "d", debuggerDisassemble, "Disassembles instructions", "[<address> [<number>]]" },
 228.117 +  { "da", debuggerDisassembleArm, "Disassembles ARM instructions", "[<address> [<number>]]" },
 228.118 +  { "dt", debuggerDisassembleThumb, "Disassembles THUMB instructions", "[<address> [<number>]]" },
 228.119 +  { "eb", debuggerEditByte,   "Modify memory location (byte)", "<address> <hex value>" },
 228.120 +  { "eh", debuggerEditHalfWord,"Modify memory location (half-word)","<address> <hex value>" },
 228.121 +  { "ew", debuggerEdit,       "Modify memory location (word)", "<address> <hex value" },
 228.122 +  { "h", debuggerHelp,        "Shows this help information. Type h <command> for command help", "[<command>]" },
 228.123 +  { "io", debuggerIo,         "Show I/O registers status", "[video|video2|dma|timer|misc]" },
 228.124 +  { "locals", debuggerLocals, "Shows local variables", NULL },
 228.125 +  { "mb", debuggerMemoryByte, "Shows memory contents (bytes)", "<address>" },
 228.126 +  { "mh", debuggerMemoryHalfWord, "Shows memory contents (half-words)", "<address>"},
 228.127 +  { "mw", debuggerMemory,     "Shows memory contents (words)", "<address>" },
 228.128 +  { "n", debuggerNext,        "Executes the next instruction", "[<count>]" },
 228.129 +  { "print", debuggerPrint,   "Print the value of a expression (if known)", "[/x|/o|/d] <expression>" },
 228.130 +  { "q", debuggerQuit,        "Quits the emulator", NULL },
 228.131 +  { "r", debuggerRegisters,   "Shows ARM registers", NULL },
 228.132 +  { "radix", debuggerSetRadix,   "Sets the print radix", "<radix>" },
 228.133 +  { "symbols", debuggerSymbols, "List symbols", "[<symbol>]" },
 228.134 +#ifndef FINAL_VERSION
 228.135 +  { "trace", debuggerDebug,       "Sets the trace level", "<value>" },
 228.136 +#endif
 228.137 +#ifdef DEV_VERSION
 228.138 +  { "verbose", debuggerVerbose,     "Change verbose setting", "<value>" },
 228.139 +#endif
 228.140 +  { "where", debuggerWhere,   "Shows call chain", NULL },
 228.141 +  { NULL, NULL, NULL, NULL} // end marker
 228.142 +};
 228.143 +
 228.144 +breakpointInfo debuggerBreakpointList[100];
 228.145 +
 228.146 +int debuggerNumOfBreakpoints = 0;
 228.147 +bool debuggerAtBreakpoint = false;
 228.148 +int debuggerBreakpointNumber = 0;
 228.149 +int debuggerRadix = 0;
 228.150 +
 228.151 +void debuggerApplyBreakpoint(u32 address, int num, int size)
 228.152 +{
 228.153 +  if(size)
 228.154 +    debuggerWriteMemory(address, (u32)(0xe1200070 | 
 228.155 +                                       (num & 0xf) | 
 228.156 +                                       ((num<<4)&0xf0)));
 228.157 +  else
 228.158 +    debuggerWriteHalfWord(address, 
 228.159 +                          (u16)(0xbe00 | num));
 228.160 +}
 228.161 +
 228.162 +void debuggerDisableBreakpoints()
 228.163 +{
 228.164 +  for(int i = 0; i < debuggerNumOfBreakpoints; i++) {
 228.165 +    if(debuggerBreakpointList[i].size)
 228.166 +      debuggerWriteMemory(debuggerBreakpointList[i].address,
 228.167 +                          debuggerBreakpointList[i].value);
 228.168 +    else
 228.169 +      debuggerWriteHalfWord(debuggerBreakpointList[i].address,
 228.170 +                            debuggerBreakpointList[i].value);      
 228.171 +  }
 228.172 +}
 228.173 +
 228.174 +void debuggerEnableBreakpoints(bool skipPC)
 228.175 +{
 228.176 +  for(int i = 0; i < debuggerNumOfBreakpoints; i++) {
 228.177 +    if(debuggerBreakpointList[i].address == armNextPC && skipPC)
 228.178 +      continue;
 228.179 +
 228.180 +    debuggerApplyBreakpoint(debuggerBreakpointList[i].address,
 228.181 +                            i,
 228.182 +                            debuggerBreakpointList[i].size);
 228.183 +  }  
 228.184 +}
 228.185 +
 228.186 +void debuggerUsage(const char *cmd)
 228.187 +{
 228.188 +  for(int i = 0; ; i++) {
 228.189 +    if(debuggerCommands[i].name) {
 228.190 +      if(!strcmp(debuggerCommands[i].name, cmd)) {
 228.191 +        printf("%s %s\t%s\n", 
 228.192 +               debuggerCommands[i].name, 
 228.193 +               debuggerCommands[i].syntax ? debuggerCommands[i].syntax : "",
 228.194 +               debuggerCommands[i].help);
 228.195 +        break;
 228.196 +      }
 228.197 +    } else {
 228.198 +      printf("Unrecognized command '%s'.", cmd);
 228.199 +      break;
 228.200 +    }
 228.201 +  }  
 228.202 +}
 228.203 +
 228.204 +void debuggerPrintBaseType(Type *t, u32 value, u32 location,
 228.205 +                           LocationType type,
 228.206 +                           int bitSize, int bitOffset)
 228.207 +{
 228.208 +  if(bitSize) {
 228.209 +    if(bitOffset)
 228.210 +      value >>= ((t->size*8)-bitOffset-bitSize);
 228.211 +    value &= (1 << bitSize)-1;
 228.212 +  } else {
 228.213 +    if(t->size == 2)
 228.214 +      value &= 0xFFFF;
 228.215 +    else if(t->size == 1)
 228.216 +      value &= 0xFF;
 228.217 +  }
 228.218 +
 228.219 +  if(t->size == 8) {
 228.220 +    u64 value = 0;
 228.221 +    if(type == LOCATION_memory) {
 228.222 +      value = debuggerReadMemory(location) |
 228.223 +        ((u64)debuggerReadMemory(location+4)<<32);
 228.224 +    } else if(type == LOCATION_register) {
 228.225 +      value = reg[location].I | ((u64)reg[location+1].I << 32);
 228.226 +    }
 228.227 +    switch(t->encoding) {
 228.228 +    case DW_ATE_signed:
 228.229 +      switch(debuggerRadix) {
 228.230 +      case 0:
 228.231 +        printf("%lld", value);
 228.232 +        break;
 228.233 +      case 1:
 228.234 +        printf("0x%llx", value);
 228.235 +        break;
 228.236 +      case 2:
 228.237 +        printf("0%llo", value);
 228.238 +        break;
 228.239 +      }
 228.240 +      break;
 228.241 +    case DW_ATE_unsigned:
 228.242 +      switch(debuggerRadix) {
 228.243 +      case 0:
 228.244 +        printf("%llu", value);
 228.245 +        break;
 228.246 +      case 1:
 228.247 +        printf("0x%llx", value);
 228.248 +        break;
 228.249 +      case 2:
 228.250 +        printf("0%llo", value);
 228.251 +        break;
 228.252 +      }
 228.253 +      break;
 228.254 +    default:
 228.255 +      printf("Unknowing 64-bit encoding\n");
 228.256 +    }
 228.257 +    return;
 228.258 +  }
 228.259 +  
 228.260 +  switch(t->encoding) {
 228.261 +  case DW_ATE_boolean:
 228.262 +    if(value)
 228.263 +      printf("true");
 228.264 +    else
 228.265 +      printf("false");
 228.266 +    break;
 228.267 +  case DW_ATE_signed:
 228.268 +    switch(debuggerRadix) {
 228.269 +    case 0:
 228.270 +      printf("%d", value);
 228.271 +      break;
 228.272 +    case 1:
 228.273 +      printf("0x%x", value);
 228.274 +      break;
 228.275 +    case 2:
 228.276 +      printf("0%o", value);
 228.277 +      break;
 228.278 +    }
 228.279 +    break;
 228.280 +  case DW_ATE_unsigned:
 228.281 +  case DW_ATE_unsigned_char:
 228.282 +    switch(debuggerRadix) {
 228.283 +    case 0:
 228.284 +      printf("%u", value);
 228.285 +      break;
 228.286 +    case 1:
 228.287 +      printf("0x%x", value);
 228.288 +      break;
 228.289 +    case 2:
 228.290 +      printf("0%o", value);
 228.291 +      break;
 228.292 +    }
 228.293 +    break;
 228.294 +  default:
 228.295 +    printf("UNKNOWN BASE %d %08x", t->encoding, value);
 228.296 +  }
 228.297 +}
 228.298 +
 228.299 +char *debuggerPrintType(Type *t)
 228.300 +{
 228.301 +  char buffer[1024];  
 228.302 +  static char buffer2[1024];
 228.303 +  
 228.304 +  if(t->type == TYPE_pointer) {
 228.305 +    if(t->pointer)
 228.306 +      strcpy(buffer, debuggerPrintType(t->pointer));
 228.307 +    else
 228.308 +      strcpy(buffer, "void");
 228.309 +    sprintf(buffer2, "%s *", buffer);
 228.310 +    return buffer2;
 228.311 +  } else if(t->type == TYPE_reference) {
 228.312 +    strcpy(buffer, debuggerPrintType(t->pointer));
 228.313 +    sprintf(buffer2, "%s &", buffer);
 228.314 +    return buffer2;    
 228.315 +  }
 228.316 +  return t->name;
 228.317 +}
 228.318 +
 228.319 +void debuggerPrintValueInternal(Function *, Type *, ELFBlock *, int, int, u32);
 228.320 +void debuggerPrintValueInternal(Function *f, Type *t,
 228.321 +                                int bitSize, int bitOffset,
 228.322 +                                u32 objLocation, LocationType type);
 228.323 +
 228.324 +u32 debuggerGetValue(u32 location, LocationType type)
 228.325 +{
 228.326 +  switch(type) {
 228.327 +  case LOCATION_memory:
 228.328 +    return debuggerReadMemory(location);
 228.329 +  case LOCATION_register:
 228.330 +    return reg[location].I;
 228.331 +  case LOCATION_value:
 228.332 +    return location;
 228.333 +  }
 228.334 +  return 0;
 228.335 +}
 228.336 +
 228.337 +void debuggerPrintPointer(Type *t, u32 value)
 228.338 +{
 228.339 +  printf("(%s)0x%08x", debuggerPrintType(t), value);
 228.340 +}
 228.341 +
 228.342 +void debuggerPrintReference(Type *t, u32 value)
 228.343 +{
 228.344 +  printf("(%s)0x%08x", debuggerPrintType(t), value);
 228.345 +}
 228.346 +
 228.347 +void debuggerPrintFunction(Type *t, u32 value)
 228.348 +{
 228.349 +  printf("(%s)0x%08x", debuggerPrintType(t), value);
 228.350 +}
 228.351 +
 228.352 +void debuggerPrintArray(Type *t, u32 value)
 228.353 +{
 228.354 +  // todo
 228.355 +  printf("(%s[])0x%08x", debuggerPrintType(t->array->type), value);
 228.356 +}
 228.357 +
 228.358 +void debuggerPrintMember(Function *f,
 228.359 +                         Member *m,
 228.360 +                         u32 objLocation,
 228.361 +                         u32 location)
 228.362 +{
 228.363 +  int bitSize = m->bitSize;
 228.364 +  if(bitSize) {
 228.365 +    u32 value = 0;
 228.366 +    int off = m->bitOffset;
 228.367 +    int size = m->byteSize;
 228.368 +    u32 v = 0;
 228.369 +    if(size == 1)
 228.370 +      v = debuggerReadByte(location);
 228.371 +      else if(size == 2)
 228.372 +        v = debuggerReadHalfWord(location);
 228.373 +      else if(size == 4)
 228.374 +        v = debuggerReadMemory(location);
 228.375 +      
 228.376 +      while(bitSize) {
 228.377 +        int top = size*8 - off;
 228.378 +        int bot = top - bitSize;
 228.379 +        top--;
 228.380 +        if(bot >= 0) {
 228.381 +          value = (v >> (size*8 - bitSize - off)) & ((1 << bitSize)-1);
 228.382 +          bitSize = 0;
 228.383 +        } else {
 228.384 +          value |= (v & ((1 << top)-1)) << (bitSize - top);
 228.385 +          bitSize -= (top+1);
 228.386 +          location -= size;
 228.387 +          off = 0;
 228.388 +          if(size == 1)
 228.389 +            v = debuggerReadByte(location);
 228.390 +          else if(size == 2)
 228.391 +            v = debuggerReadHalfWord(location);
 228.392 +          else
 228.393 +            v = debuggerReadMemory(location);
 228.394 +        }
 228.395 +      }
 228.396 +      debuggerPrintBaseType(m->type, value, location, LOCATION_memory,
 228.397 +                            bitSize, 0);
 228.398 +    } else {
 228.399 +      debuggerPrintValueInternal(f, m->type, m->location, m->bitSize,
 228.400 +                                 m->bitOffset, objLocation);
 228.401 +    }  
 228.402 +}
 228.403 +
 228.404 +void debuggerPrintStructure(Function *f, Type *t, u32 objLocation)
 228.405 +{
 228.406 +  printf("{");
 228.407 +  int count = t->structure->memberCount;
 228.408 +  int i = 0;
 228.409 +  while(i < count) {
 228.410 +    Member *m = &t->structure->members[i];
 228.411 +    printf("%s=", m->name);
 228.412 +    LocationType type;
 228.413 +    u32 location = elfDecodeLocation(f, m->location, &type, objLocation);
 228.414 +    debuggerPrintMember(f, m, objLocation, location);
 228.415 +    i++;
 228.416 +    if(i < count)
 228.417 +      printf(",");
 228.418 +  }
 228.419 +  printf("}");
 228.420 +}
 228.421 +
 228.422 +void debuggerPrintUnion(Function *f, Type *t, u32 objLocation)
 228.423 +{
 228.424 +  // todo
 228.425 +  printf("{");
 228.426 +  int count = t->structure->memberCount;
 228.427 +  int i = 0;
 228.428 +  while(i < count) {
 228.429 +    Member *m = &t->structure->members[i];
 228.430 +    printf("%s=", m->name);
 228.431 +    debuggerPrintMember(f, m, objLocation, 0);
 228.432 +    i++;
 228.433 +    if(i < count)
 228.434 +      printf(",");
 228.435 +  }
 228.436 +  printf("}");
 228.437 +}
 228.438 +
 228.439 +void debuggerPrintEnum(Type *t, u32 value)
 228.440 +{
 228.441 +  int i;
 228.442 +  for(i = 0; i < t->enumeration->count; i++) {
 228.443 +    EnumMember *m = (EnumMember *)&t->enumeration->members[i];
 228.444 +    if(value == m->value) {
 228.445 +      puts(m->name);
 228.446 +      return;
 228.447 +    }
 228.448 +  }
 228.449 +  printf("(UNKNOWN VALUE) %d", value);
 228.450 +}
 228.451 +
 228.452 +void debuggerPrintValueInternal(Function *f, Type *t,
 228.453 +                                int bitSize, int bitOffset,
 228.454 +                                u32 objLocation, LocationType type)
 228.455 +{
 228.456 +  u32 value = debuggerGetValue(objLocation, type);
 228.457 +  if(!t) {
 228.458 +    printf("void");
 228.459 +    return;
 228.460 +  }
 228.461 +  switch(t->type) {
 228.462 +  case TYPE_base:
 228.463 +    debuggerPrintBaseType(t, value, objLocation, type, bitSize, bitOffset);
 228.464 +    break;
 228.465 +  case TYPE_pointer:
 228.466 +    debuggerPrintPointer(t, value);
 228.467 +    break;
 228.468 +  case TYPE_reference:
 228.469 +    debuggerPrintReference(t, value);
 228.470 +    break;
 228.471 +  case TYPE_function:
 228.472 +    debuggerPrintFunction(t, value);
 228.473 +    break;
 228.474 +  case TYPE_array:
 228.475 +    debuggerPrintArray(t, objLocation);
 228.476 +    break;
 228.477 +  case TYPE_struct:
 228.478 +    debuggerPrintStructure(f, t, objLocation);
 228.479 +    break;
 228.480 +  case TYPE_union:
 228.481 +    debuggerPrintUnion(f, t, objLocation);
 228.482 +    break;
 228.483 +  case TYPE_enum:
 228.484 +    debuggerPrintEnum(t, value);
 228.485 +    break;
 228.486 +  default:
 228.487 +    printf("%08x", value);
 228.488 +    break;
 228.489 +  }  
 228.490 +}
 228.491 +
 228.492 +void debuggerPrintValueInternal(Function *f, Type *t, ELFBlock *loc,
 228.493 +                                int bitSize, int bitOffset, u32 objLocation)
 228.494 +{
 228.495 +  LocationType type;  
 228.496 +  u32 location;
 228.497 +  if(loc) {
 228.498 +    if(objLocation)
 228.499 +      location = elfDecodeLocation(f, loc, &type, objLocation);
 228.500 +    else
 228.501 +      location = elfDecodeLocation(f, loc,&type);
 228.502 +  } else {
 228.503 +    location = objLocation;
 228.504 +    type = LOCATION_memory;
 228.505 +  }
 228.506 +
 228.507 +  debuggerPrintValueInternal(f, t, bitSize, bitOffset, location, type);
 228.508 +}
 228.509 +
 228.510 +void debuggerPrintValue(Function *f, Object *o)
 228.511 +{
 228.512 +  debuggerPrintValueInternal(f, o->type, o->location, 0, 0, 0);
 228.513 +  
 228.514 +  printf("\n");
 228.515 +}
 228.516 +
 228.517 +void debuggerSymbols(int argc, char **argv)
 228.518 +{
 228.519 +  int i = 0;
 228.520 +  u32 value;
 228.521 +  u32 size;
 228.522 +  int type;
 228.523 +  bool match = false;
 228.524 +  int matchSize = 0;
 228.525 +  char *matchStr = NULL;
 228.526 +  
 228.527 +  if(argc == 2) {
 228.528 +    match = true;
 228.529 +    matchSize = strlen(argv[1]);
 228.530 +    matchStr = argv[1];
 228.531 +  }
 228.532 +  printf("Symbol               Value    Size     Type   \n");
 228.533 +  printf("-------------------- -------  -------- -------\n");
 228.534 +  char *s = NULL;
 228.535 +  while((s = elfGetSymbol(i, &value, &size, &type))) {
 228.536 +    if(*s) {
 228.537 +      if(match) {
 228.538 +        if(strncmp(s, matchStr, matchSize) != 0) {
 228.539 +          i++;
 228.540 +          continue;
 228.541 +        }
 228.542 +      }
 228.543 +      const char *ts = "?";
 228.544 +      switch(type) {
 228.545 +      case 2:
 228.546 +        ts = "ARM";
 228.547 +        break;
 228.548 +      case 0x0d:
 228.549 +        ts = "THUMB";
 228.550 +        break;
 228.551 +      case 1:
 228.552 +        ts = "DATA";
 228.553 +        break;
 228.554 +      }
 228.555 +      printf("%-20s %08x %08x %-7s\n",
 228.556 +             s, value, size, ts);
 228.557 +    }
 228.558 +    i++;
 228.559 +  }
 228.560 +}
 228.561 +
 228.562 +void debuggerSetRadix(int argc, char **argv)
 228.563 +{
 228.564 +  if(argc != 2)
 228.565 +    debuggerUsage(argv[0]);
 228.566 +  else {
 228.567 +    int r = atoi(argv[1]);
 228.568 +
 228.569 +    bool error = false;
 228.570 +    switch(r) {
 228.571 +    case 10:
 228.572 +      debuggerRadix = 0;
 228.573 +      break;
 228.574 +    case 8:
 228.575 +      debuggerRadix = 2;
 228.576 +      break;
 228.577 +    case 16:
 228.578 +      debuggerRadix = 1;
 228.579 +      break;
 228.580 +    default:
 228.581 +      error = true;
 228.582 +      printf("Unknown radix %d. Valid values are 8, 10 and 16.\n", r);
 228.583 +      break;
 228.584 +    }
 228.585 +    if(!error)
 228.586 +      printf("Radix set to %d\n", r);
 228.587 +  }
 228.588 +}
 228.589 +
 228.590 +void debuggerPrint(int argc, char **argv)
 228.591 +{
 228.592 +  if(argc != 2 && argc != 3) {
 228.593 +    debuggerUsage(argv[0]);
 228.594 +  } else {
 228.595 +    u32 pc = armNextPC;
 228.596 +    Function *f = NULL;
 228.597 +    CompileUnit *u = NULL;
 228.598 +    
 228.599 +    elfGetCurrentFunction(pc,
 228.600 +                          &f, &u);
 228.601 +
 228.602 +    int oldRadix = debuggerRadix;
 228.603 +    if(argc == 3) {
 228.604 +      if(argv[1][0] == '/') {
 228.605 +        if(argv[1][1] == 'x')
 228.606 +          debuggerRadix = 1;
 228.607 +        else if(argv[1][1] == 'o')
 228.608 +          debuggerRadix = 2;
 228.609 +        else if(argv[1][1] == 'd')
 228.610 +          debuggerRadix = 0;
 228.611 +        else {
 228.612 +          printf("Unknown format %c\n", argv[1][1]);
 228.613 +          return;
 228.614 +        }
 228.615 +      } else {
 228.616 +        printf("Unknown option %s\n", argv[1]);
 228.617 +        return;
 228.618 +      }
 228.619 +    } 
 228.620 +    
 228.621 +    char *s = argc == 2 ? argv[1] : argv[2];
 228.622 +
 228.623 +    extern char *exprString;
 228.624 +    extern int exprCol;
 228.625 +    extern int yyparse();
 228.626 +    exprString = s;
 228.627 +    exprCol = 0;
 228.628 +    if(!yyparse()) {
 228.629 +      extern Node *result;
 228.630 +      if(result->resolve(result, f, u)) {
 228.631 +        if(result->member)
 228.632 +          debuggerPrintMember(f,
 228.633 +                              result->member,
 228.634 +                              result->objLocation,
 228.635 +                              result->location);
 228.636 +        else
 228.637 +          debuggerPrintValueInternal(f, result->type, 0, 0,
 228.638 +                                     result->location,
 228.639 +                                     result->locType);
 228.640 +        printf("\n");
 228.641 +      } else {
 228.642 +        printf("Error resolving expression\n");
 228.643 +      }
 228.644 +    } else {
 228.645 +      printf("Error parsing expression:\n");
 228.646 +      printf("%s\n", s);
 228.647 +      exprCol--;
 228.648 +      for(int i = 0; i < exprCol; i++)
 228.649 +        printf(" ");
 228.650 +      printf("^\n");
 228.651 +    }
 228.652 +    extern void exprCleanBuffer();
 228.653 +    exprCleanBuffer();
 228.654 +    exprNodeCleanUp();
 228.655 +    debuggerRadix = oldRadix;
 228.656 +  }
 228.657 +}
 228.658 +
 228.659 +void debuggerHelp(int n, char **args)
 228.660 +{
 228.661 +  if(n == 2) {
 228.662 +    debuggerUsage(args[1]);
 228.663 +  } else {
 228.664 +    for(int i = 0; ; i++) {
 228.665 +      if(debuggerCommands[i].name) {
 228.666 +        printf("%s\t%s\n", debuggerCommands[i].name, debuggerCommands[i].help);
 228.667 +      } else
 228.668 +        break;
 228.669 +    }
 228.670 +  }
 228.671 +}
 228.672 +
 228.673 +void debuggerDebug(int n, char **args)
 228.674 +{
 228.675 +  if(n == 2) {
 228.676 +    int v = 0;
 228.677 +    sscanf(args[1], "%d", &v);
 228.678 +    systemDebug = v;
 228.679 +    printf("Debug level set to %d\n", systemDebug);
 228.680 +  } else
 228.681 +    debuggerUsage("trace");      
 228.682 +}
 228.683 +
 228.684 +void debuggerVerbose(int n, char **args)
 228.685 +{
 228.686 +  if(n == 2) {
 228.687 +    int v = 0;
 228.688 +    sscanf(args[1], "%d", &v);
 228.689 +    systemVerbose = v;
 228.690 +    printf("Verbose level set to %d\n", systemVerbose);
 228.691 +  } else
 228.692 +    debuggerUsage("verbose");    
 228.693 +}
 228.694 +
 228.695 +void debuggerWhere(int n, char **args)
 228.696 +{
 228.697 +  void elfPrintCallChain(u32);
 228.698 +  elfPrintCallChain(armNextPC);
 228.699 +}
 228.700 +
 228.701 +void debuggerLocals(int n, char **args)
 228.702 +{
 228.703 +  Function *f = NULL;
 228.704 +  CompileUnit *u = NULL;
 228.705 +  u32 pc = armNextPC;
 228.706 +  if(elfGetCurrentFunction(pc,
 228.707 +                           &f, &u)) {
 228.708 +    Object *o = f->parameters;
 228.709 +    while(o) {
 228.710 +      printf("%s=", o->name);
 228.711 +      debuggerPrintValue(f, o);
 228.712 +      o = o->next;
 228.713 +    }
 228.714 +
 228.715 +    o = f->variables;
 228.716 +    while(o) {
 228.717 +      bool visible = o->startScope ? pc>=o->startScope : true;
 228.718 +      if(visible)
 228.719 +        visible = o->endScope ? pc < o->endScope : true;
 228.720 +      if(visible) {
 228.721 +        printf("%s=", o->name);
 228.722 +        debuggerPrintValue(f, o);
 228.723 +      }
 228.724 +      o = o->next;      
 228.725 +    }
 228.726 +  } else {
 228.727 +    printf("No information for current address\n");
 228.728 +  }  
 228.729 +}
 228.730 +
 228.731 +void debuggerNext(int n, char **args)
 228.732 +{
 228.733 +  int count = 1;
 228.734 +  if(n == 2) {
 228.735 +    sscanf(args[1], "%d", &count);
 228.736 +  }
 228.737 +  for(int i = 0; i < count; i++) {
 228.738 +    if(debuggerAtBreakpoint) {
 228.739 +      debuggerContinueAfterBreakpoint();
 228.740 +      debuggerEnableBreakpoints(false);
 228.741 +    } else 
 228.742 +      theEmulator.emuMain(1);
 228.743 +  }
 228.744 +  debuggerDisableBreakpoints();
 228.745 +  Function *f = NULL;
 228.746 +  CompileUnit *u = NULL;
 228.747 +  u32 a = armNextPC;
 228.748 +  if(elfGetCurrentFunction(a, &f, &u)) {
 228.749 +    char *file;
 228.750 +    int line = elfFindLine(u, f, a, &file);
 228.751 +    
 228.752 +    printf("File %s, function %s, line %d\n", file, f->name,
 228.753 +           line);
 228.754 +  }
 228.755 +  debuggerRegisters(0, NULL);
 228.756 +}
 228.757 +
 228.758 +void debuggerContinue(int n, char **args)
 228.759 +{
 228.760 +  if(debuggerAtBreakpoint)
 228.761 +    debuggerContinueAfterBreakpoint();
 228.762 +  debuggerEnableBreakpoints(false);
 228.763 +  debugger = false;
 228.764 +}
 228.765 +
 228.766 +void debuggerSignal(int sig,int number)
 228.767 +{
 228.768 +  switch(sig) {
 228.769 +  case 4:
 228.770 +    {
 228.771 +      printf("Illegal instruction at %08x\n", armNextPC);
 228.772 +      debugger = true;
 228.773 +    }
 228.774 +    break;
 228.775 +  case 5:
 228.776 +    {
 228.777 +      printf("Breakpoint %d reached\n", number);
 228.778 +      debugger = true;
 228.779 +      debuggerAtBreakpoint = true;
 228.780 +      debuggerBreakpointNumber = number;
 228.781 +      debuggerDisableBreakpoints();
 228.782 +      
 228.783 +      Function *f = NULL;
 228.784 +      CompileUnit *u = NULL;
 228.785 +      
 228.786 +      if(elfGetCurrentFunction(armNextPC, &f, &u)) {
 228.787 +        char *file;
 228.788 +        int line = elfFindLine(u,f,armNextPC,&file);
 228.789 +        printf("File %s, function %s, line %d\n", file, f->name,
 228.790 +               line);
 228.791 +      }
 228.792 +    }
 228.793 +    break;
 228.794 +  default:
 228.795 +    printf("Unknown signal %d\n", sig);
 228.796 +    break;
 228.797 +  }
 228.798 +}
 228.799 +
 228.800 +void debuggerBreakList(int, char **)
 228.801 +{
 228.802 +  printf("Num Address  Type  Symbol\n");
 228.803 +  printf("--- -------- ----- ------\n");
 228.804 +  for(int i = 0; i < debuggerNumOfBreakpoints; i++) {
 228.805 +    printf("%3d %08x %s %s\n",i, debuggerBreakpointList[i].address,
 228.806 +           debuggerBreakpointList[i].size ? "ARM" : "THUMB",
 228.807 +           elfGetAddressSymbol(debuggerBreakpointList[i].address));
 228.808 +  }
 228.809 +}
 228.810 +
 228.811 +void debuggerBreakDelete(int n, char **args)
 228.812 +{
 228.813 +  if(n == 2) {
 228.814 +    int n = 0;
 228.815 +    sscanf(args[1], "%d", &n);
 228.816 +    printf("Deleting breakpoint %d (%d)\n", n, debuggerNumOfBreakpoints);
 228.817 +    if(n >= 0 && n < debuggerNumOfBreakpoints) {
 228.818 +      n++;
 228.819 +      if(n < debuggerNumOfBreakpoints) {
 228.820 +        for(int i = n; i < debuggerNumOfBreakpoints; i++) {
 228.821 +          debuggerBreakpointList[i-1].address = 
 228.822 +            debuggerBreakpointList[i].address;
 228.823 +          debuggerBreakpointList[i-1].value = 
 228.824 +            debuggerBreakpointList[i].value;
 228.825 +          debuggerBreakpointList[i-1].size = 
 228.826 +            debuggerBreakpointList[i].size;
 228.827 +        }
 228.828 +      }
 228.829 +      debuggerNumOfBreakpoints--;
 228.830 +    }
 228.831 +  } else
 228.832 +    debuggerUsage("bd");    
 228.833 +}
 228.834 +
 228.835 +void debuggerBreak(int n, char **args)
 228.836 +{
 228.837 +  if(n == 2) {
 228.838 +    u32 address = 0;
 228.839 +    u32 value = 0;
 228.840 +    int type = 0;
 228.841 +    char *s = args[1];
 228.842 +    char c = *s;
 228.843 +    if(strchr(s, ':')) {
 228.844 +      char *name = s;
 228.845 +      char *l = strchr(s, ':');
 228.846 +      *l++ = 0;
 228.847 +      int line = atoi(l);
 228.848 +
 228.849 +      u32 addr;
 228.850 +      Function *f;
 228.851 +      CompileUnit *u;
 228.852 +      
 228.853 +      if(elfFindLineInModule(&addr, name, line)) {
 228.854 +        if(elfGetCurrentFunction(addr, &f, &u)) {
 228.855 +          u32 addr2;
 228.856 +          if(elfGetSymbolAddress(f->name, &addr2, &value, &type)) {
 228.857 +            address = addr;
 228.858 +          } else {
 228.859 +            printf("Unable to get function symbol data\n");
 228.860 +            return;
 228.861 +          }
 228.862 +        } else {
 228.863 +          printf("Unable to find function for address\n");
 228.864 +          return;
 228.865 +        }
 228.866 +      } else {
 228.867 +        printf("Unable to find module or line\n");
 228.868 +        return;
 228.869 +      }
 228.870 +    } else if(c >= '0' && c <= '9') {
 228.871 +      int line = atoi(s);
 228.872 +      Function *f;
 228.873 +      CompileUnit *u;
 228.874 +      u32 addr;
 228.875 +      
 228.876 +      if(elfGetCurrentFunction(armNextPC, &f, &u)) {
 228.877 +        if(elfFindLineInUnit(&addr, u, line)) {
 228.878 +          if(elfGetCurrentFunction(addr, &f, &u)) {
 228.879 +            u32 addr2;
 228.880 +            if(elfGetSymbolAddress(f->name, &addr2, &value, &type)) {
 228.881 +              address = addr;
 228.882 +            } else {
 228.883 +              printf("Unable to get function symbol data\n");
 228.884 +              return;
 228.885 +            }
 228.886 +          } else {
 228.887 +            printf("Unable to find function for address\n");
 228.888 +            return;
 228.889 +          }
 228.890 +        } else {
 228.891 +          printf("Unable to find line\n");
 228.892 +          return;
 228.893 +        }
 228.894 +      } else {
 228.895 +        printf("Cannot find current function\n");
 228.896 +        return;
 228.897 +      }
 228.898 +    } else {
 228.899 +      if(!elfGetSymbolAddress(s, &address, &value, &type)) {
 228.900 +        printf("Function %s not found\n", args[1]);
 228.901 +        return;
 228.902 +      }
 228.903 +    }
 228.904 +    if(type == 0x02 || type == 0x0d) {
 228.905 +      int i = debuggerNumOfBreakpoints;
 228.906 +      int size = 0;
 228.907 +      if(type == 2)
 228.908 +        size = 1;
 228.909 +      debuggerBreakpointList[i].address = address;
 228.910 +      debuggerBreakpointList[i].value = type == 0x02 ?
 228.911 +        debuggerReadMemory(address) : debuggerReadHalfWord(address);
 228.912 +      debuggerBreakpointList[i].size = size;
 228.913 +      //      debuggerApplyBreakpoint(address, i, size);
 228.914 +      debuggerNumOfBreakpoints++;
 228.915 +      if(size)
 228.916 +        printf("Added ARM breakpoint at %08x\n", address);        
 228.917 +      else
 228.918 +        printf("Added THUMB breakpoint at %08x\n", address);
 228.919 +    } else {
 228.920 +      printf("%s is not a function symbol\n", args[1]); 
 228.921 +    }
 228.922 +  } else
 228.923 +    debuggerUsage("break");  
 228.924 +}
 228.925 +
 228.926 +void debuggerBreakThumb(int n, char **args)
 228.927 +{
 228.928 +  if(n == 2) {
 228.929 +    u32 address = 0;
 228.930 +    sscanf(args[1],"%x", &address);
 228.931 +    int i = debuggerNumOfBreakpoints;
 228.932 +    debuggerBreakpointList[i].address = address;
 228.933 +    debuggerBreakpointList[i].value = debuggerReadHalfWord(address);
 228.934 +    debuggerBreakpointList[i].size = 0;
 228.935 +    //    debuggerApplyBreakpoint(address, i, 0);
 228.936 +    debuggerNumOfBreakpoints++;
 228.937 +    printf("Added THUMB breakpoint at %08x\n", address);
 228.938 +  } else
 228.939 +    debuggerUsage("bt");    
 228.940 +}
 228.941 +
 228.942 +void debuggerBreakArm(int n, char **args)
 228.943 +{
 228.944 +  if(n == 2) {
 228.945 +    u32 address = 0;
 228.946 +    sscanf(args[1],"%x", &address);
 228.947 +    int i = debuggerNumOfBreakpoints;
 228.948 +    debuggerBreakpointList[i].address = address;
 228.949 +    debuggerBreakpointList[i].value = debuggerReadMemory(address);
 228.950 +    debuggerBreakpointList[i].size = 1;
 228.951 +    //    debuggerApplyBreakpoint(address, i, 1);
 228.952 +    debuggerNumOfBreakpoints++;
 228.953 +    printf("Added ARM breakpoint at %08x\n", address);
 228.954 +  } else
 228.955 +    debuggerUsage("ba");
 228.956 +}
 228.957 +
 228.958 +void debuggerBreakOnWrite(u32 *mem, u32 oldvalue, u32 value, int size)
 228.959 +{
 228.960 +  u32 address = 0;
 228.961 +  if(mem >= (u32*)&workRAM[0] && mem <= (u32*)&workRAM[0x3ffff])
 228.962 +    address = 0x2000000 + ((u64)mem - (u64)&workRAM[0]);
 228.963 +  else
 228.964 +    address = 0x3000000 + ((u64)mem - (u64)&internalRAM[0]);
 228.965 +
 228.966 +  if(size == 2)
 228.967 +    printf("Breakpoint (on write) address %08x old:%08x new:%08x\n", 
 228.968 +           address, oldvalue, value);
 228.969 +  else if(size == 1)
 228.970 +    printf("Breakpoint (on write) address %08x old:%04x new:%04x\n", 
 228.971 +           address, (u16)oldvalue,(u16)value);
 228.972 +  else
 228.973 +    printf("Breakpoint (on write) address %08x old:%02x new:%02x\n", 
 228.974 +           address, (u8)oldvalue, (u8)value);
 228.975 +  debugger = true;
 228.976 +}
 228.977 +
 228.978 +void debuggerBreakWriteClear(int n, char **args)
 228.979 +{
 228.980 +  memset(freezeWorkRAM, false, 0x40000);
 228.981 +  memset(freezeInternalRAM, false, 0x8000);
 228.982 +  printf("Cleared all break on write\n");
 228.983 +}
 228.984 +
 228.985 +void debuggerBreakWrite(int n, char **args)
 228.986 +{
 228.987 +  if(n == 3) {
 228.988 +    if(cheatsNumber != 0) {
 228.989 +      printf("Cheats are enabled. Cannot continue.\n");
 228.990 +      return;
 228.991 +    }
 228.992 +    u32 address = 0;
 228.993 +    sscanf(args[1], "%x", &address);
 228.994 +    int n = 0;
 228.995 +    sscanf(args[2], "%d", &n);
 228.996 +    
 228.997 +    if(address < 0x2000000 || address > 0x3007fff) {
 228.998 +      printf("Invalid address: %08x\n", address);
 228.999 +      return;
228.1000 +    }
228.1001 +    
228.1002 +    if(address > 0x203ffff && address < 0x3000000) {
228.1003 +      printf("Invalid address: %08x\n", address);
228.1004 +      return;
228.1005 +    }
228.1006 +
228.1007 +    u32 final = address + n;
228.1008 +
228.1009 +    if(address < 0x2040000 && final > 0x2040000) {
228.1010 +      printf("Invalid byte count: %d\n", n);
228.1011 +      return;
228.1012 +    } else if(address < 0x3008000 && final > 0x3008000) {
228.1013 +      printf("Invalid byte count: %d\n", n);
228.1014 +      return;
228.1015 +    }
228.1016 +    printf("Added break on write at %08x for %d bytes\n", address, n);
228.1017 +    for(int i = 0; i < n; i++) {
228.1018 +      if((address >> 24) == 2)
228.1019 +        freezeWorkRAM[address & 0x3ffff] = true;
228.1020 +      else
228.1021 +        freezeInternalRAM[address & 0x7fff] = true;
228.1022 +      address++;
228.1023 +    }
228.1024 +  } else
228.1025 +    debuggerUsage("bpw");    
228.1026 +}
228.1027 +
228.1028 +void debuggerDisassembleArm(int n, char **args)
228.1029 +{
228.1030 +  char buffer[80];
228.1031 +  u32 pc = reg[15].I;
228.1032 +  pc -= 4;
228.1033 +  int count = 20;
228.1034 +  if(n >= 2) {
228.1035 +    sscanf(args[1], "%x", &pc);
228.1036 +  }
228.1037 +  if(pc & 3) {
228.1038 +    printf("Misaligned address %08x\n", pc);
228.1039 +    pc &= 0xfffffffc;
228.1040 +  }
228.1041 +  if(n >= 3) {
228.1042 +    sscanf(args[2], "%d", &count);
228.1043 +  }
228.1044 +  int i = 0;
228.1045 +  int len = 0;
228.1046 +  char format[30];
228.1047 +  for(i = 0; i < count; i++) {
228.1048 +    int l = strlen(elfGetAddressSymbol(pc+4*i));
228.1049 +    if(l > len)
228.1050 +      len = l;
228.1051 +  }
228.1052 +  sprintf(format, "%%08x %%-%ds %%s\n", len);
228.1053 +  for(i = 0; i < count; i++) {
228.1054 +    u32 addr = pc;
228.1055 +    pc += disArm(pc, buffer, 2);
228.1056 +    printf(format, addr, elfGetAddressSymbol(addr), buffer);
228.1057 +  }
228.1058 +}
228.1059 +
228.1060 +void debuggerDisassembleThumb(int n, char **args)
228.1061 +{
228.1062 +  char buffer[80];
228.1063 +  u32 pc = reg[15].I;
228.1064 +  pc -= 2;
228.1065 +  int count = 20;
228.1066 +  if(n >= 2) {
228.1067 +    sscanf(args[1], "%x", &pc);
228.1068 +  }
228.1069 +  if(pc & 1) {
228.1070 +    printf("Misaligned address %08x\n", pc);
228.1071 +    pc &= 0xfffffffe;
228.1072 +  }
228.1073 +  if(n >= 3) {
228.1074 +    sscanf(args[2], "%d", &count);
228.1075 +  }
228.1076 +
228.1077 +  int i = 0;
228.1078 +  int len = 0;
228.1079 +  char format[30];
228.1080 +  for(i = 0; i < count; i++) {
228.1081 +    int l = strlen(elfGetAddressSymbol(pc+2*i));
228.1082 +    if(l > len)
228.1083 +      len = l;
228.1084 +  }
228.1085 +  sprintf(format, "%%08x %%-%ds %%s\n", len);  
228.1086 +  
228.1087 +  for(i = 0; i < count; i++) {
228.1088 +    u32 addr = pc;
228.1089 +    pc += disThumb(pc, buffer, 2);
228.1090 +    printf(format, addr, elfGetAddressSymbol(addr), buffer);
228.1091 +  }
228.1092 +}
228.1093 +
228.1094 +void debuggerDisassemble(int n, char **args)
228.1095 +{
228.1096 +  if(armState)
228.1097 +    debuggerDisassembleArm(n, args);
228.1098 +  else
228.1099 +    debuggerDisassembleThumb(n, args);
228.1100 +}
228.1101 +
228.1102 +void debuggerContinueAfterBreakpoint()
228.1103 +{
228.1104 +  printf("Continuing after breakpoint\n");
228.1105 +  debuggerEnableBreakpoints(true);
228.1106 +  theEmulator.emuMain(1);
228.1107 +  debuggerAtBreakpoint = false;
228.1108 +}
228.1109 +
228.1110 +void debuggerRegisters(int, char **)
228.1111 +{
228.1112 +  char *command[3];
228.1113 +  char buffer[10];
228.1114 +
228.1115 +  printf("R00=%08x R04=%08x R08=%08x R12=%08x\n",
228.1116 +         reg[0].I, reg[4].I, reg[8].I, reg[12].I);
228.1117 +  printf("R01=%08x R05=%08x R09=%08x R13=%08x\n",
228.1118 +         reg[1].I, reg[5].I, reg[9].I, reg[13].I);
228.1119 +  printf("R02=%08x R06=%08x R10=%08x R14=%08x\n",
228.1120 +         reg[2].I, reg[6].I, reg[10].I, reg[14].I);
228.1121 +  printf("R03=%08x R07=%08x R11=%08x R15=%08x\n",
228.1122 +         reg[3].I, reg[7].I, reg[11].I, reg[15].I);
228.1123 +  printf("CPSR=%08x (%c%c%c%c%c%c%c Mode: %02x)\n",
228.1124 +         reg[16].I,
228.1125 +         (N_FLAG ? 'N' : '.'),
228.1126 +         (Z_FLAG ? 'Z' : '.'),
228.1127 +         (C_FLAG ? 'C' : '.'),
228.1128 +         (V_FLAG ? 'V' : '.'),
228.1129 +         (armIrqEnable ? '.' : 'I'),
228.1130 +         ((!(reg[16].I & 0x40)) ? '.' : 'F'),
228.1131 +         (armState ? '.' : 'T'),
228.1132 +         armMode);
228.1133 +  sprintf(buffer,"%08x", armState ? reg[15].I - 4 : reg[15].I - 2);
228.1134 +  command[0]=const_cast<char *>("m");
228.1135 +  command[1]=buffer;
228.1136 +  command[2]=const_cast<char *>("1");
228.1137 +  debuggerDisassemble(3, command);
228.1138 +}
228.1139 +
228.1140 +void debuggerIoVideo()
228.1141 +{
228.1142 +  printf("DISPCNT  = %04x\n", DISPCNT);
228.1143 +  printf("DISPSTAT = %04x\n", DISPSTAT);
228.1144 +  printf("VCOUNT   = %04x\n", VCOUNT);
228.1145 +  printf("BG0CNT   = %04x\n", BG0CNT);
228.1146 +  printf("BG1CNT   = %04x\n", BG1CNT);
228.1147 +  printf("BG2CNT   = %04x\n", BG2CNT);
228.1148 +  printf("BG3CNT   = %04x\n", BG3CNT);
228.1149 +  printf("WIN0H    = %04x\n", WIN0H);
228.1150 +  printf("WIN0V    = %04x\n", WIN0V);
228.1151 +  printf("WIN1H    = %04x\n", WIN1H);
228.1152 +  printf("WIN1V    = %04x\n", WIN1V);
228.1153 +  printf("WININ    = %04x\n", WININ);
228.1154 +  printf("WINOUT   = %04x\n", WINOUT);
228.1155 +  printf("MOSAIC   = %04x\n", MOSAIC);
228.1156 +  printf("BLDMOD   = %04x\n", BLDMOD);
228.1157 +  printf("COLEV    = %04x\n", COLEV);
228.1158 +  printf("COLY     = %04x\n", COLY);
228.1159 +}
228.1160 +
228.1161 +void debuggerIoVideo2()
228.1162 +{
228.1163 +  printf("BG0HOFS  = %04x\n", BG0HOFS);
228.1164 +  printf("BG0VOFS  = %04x\n", BG0VOFS);
228.1165 +  printf("BG1HOFS  = %04x\n", BG1HOFS);
228.1166 +  printf("BG1VOFS  = %04x\n", BG1VOFS);
228.1167 +  printf("BG2HOFS  = %04x\n", BG2HOFS);
228.1168 +  printf("BG2VOFS  = %04x\n", BG2VOFS);
228.1169 +  printf("BG3HOFS  = %04x\n", BG3HOFS);
228.1170 +  printf("BG3VOFS  = %04x\n", BG3VOFS);
228.1171 +  printf("BG2PA    = %04x\n", BG2PA);
228.1172 +  printf("BG2PB    = %04x\n", BG2PB);
228.1173 +  printf("BG2PC    = %04x\n", BG2PC);
228.1174 +  printf("BG2PD    = %04x\n", BG2PD);
228.1175 +  printf("BG2X     = %08x\n", (BG2X_H<<16)|BG2X_L);
228.1176 +  printf("BG2Y     = %08x\n", (BG2Y_H<<16)|BG2Y_L);
228.1177 +  printf("BG3PA    = %04x\n", BG3PA);
228.1178 +  printf("BG3PB    = %04x\n", BG3PB);
228.1179 +  printf("BG3PC    = %04x\n", BG3PC);
228.1180 +  printf("BG3PD    = %04x\n", BG3PD);
228.1181 +  printf("BG3X     = %08x\n", (BG3X_H<<16)|BG3X_L);
228.1182 +  printf("BG3Y     = %08x\n", (BG3Y_H<<16)|BG3Y_L);
228.1183 +}
228.1184 +
228.1185 +void debuggerIoDMA()
228.1186 +{
228.1187 +  printf("DM0SAD   = %08x\n", (DM0SAD_H<<16)|DM0SAD_L);
228.1188 +  printf("DM0DAD   = %08x\n", (DM0DAD_H<<16)|DM0DAD_L);
228.1189 +  printf("DM0CNT   = %08x\n", (DM0CNT_H<<16)|DM0CNT_L);  
228.1190 +  printf("DM1SAD   = %08x\n", (DM1SAD_H<<16)|DM1SAD_L);
228.1191 +  printf("DM1DAD   = %08x\n", (DM1DAD_H<<16)|DM1DAD_L);
228.1192 +  printf("DM1CNT   = %08x\n", (DM1CNT_H<<16)|DM1CNT_L);  
228.1193 +  printf("DM2SAD   = %08x\n", (DM2SAD_H<<16)|DM2SAD_L);
228.1194 +  printf("DM2DAD   = %08x\n", (DM2DAD_H<<16)|DM2DAD_L);
228.1195 +  printf("DM2CNT   = %08x\n", (DM2CNT_H<<16)|DM2CNT_L);  
228.1196 +  printf("DM3SAD   = %08x\n", (DM3SAD_H<<16)|DM3SAD_L);
228.1197 +  printf("DM3DAD   = %08x\n", (DM3DAD_H<<16)|DM3DAD_L);
228.1198 +  printf("DM3CNT   = %08x\n", (DM3CNT_H<<16)|DM3CNT_L);    
228.1199 +}
228.1200 +
228.1201 +void debuggerIoTimer()
228.1202 +{
228.1203 +  printf("TM0D     = %04x\n", TM0D);
228.1204 +  printf("TM0CNT   = %04x\n", TM0CNT);
228.1205 +  printf("TM1D     = %04x\n", TM1D);
228.1206 +  printf("TM1CNT   = %04x\n", TM1CNT);
228.1207 +  printf("TM2D     = %04x\n", TM2D);
228.1208 +  printf("TM2CNT   = %04x\n", TM2CNT);
228.1209 +  printf("TM3D     = %04x\n", TM3D);
228.1210 +  printf("TM3CNT   = %04x\n", TM3CNT);
228.1211 +}
228.1212 +
228.1213 +void debuggerIoMisc()
228.1214 +{
228.1215 +  printf("P1       = %04x\n", P1);  
228.1216 +  printf("IE       = %04x\n", IE);
228.1217 +  printf("IF       = %04x\n", IF);
228.1218 +  printf("IME      = %04x\n", IME);
228.1219 +}
228.1220 +
228.1221 +void debuggerIo(int n, char **args)
228.1222 +{
228.1223 +  if(n == 1) {
228.1224 +    debuggerIoVideo();
228.1225 +    return;
228.1226 +  }
228.1227 +  if(!strcmp(args[1], "video"))
228.1228 +    debuggerIoVideo();
228.1229 +  else if(!strcmp(args[1], "video2"))
228.1230 +    debuggerIoVideo2();
228.1231 +  else if(!strcmp(args[1], "dma"))
228.1232 +    debuggerIoDMA();
228.1233 +  else if(!strcmp(args[1], "timer"))
228.1234 +    debuggerIoTimer();
228.1235 +  else if(!strcmp(args[1], "misc"))
228.1236 +    debuggerIoMisc();
228.1237 +  else printf("Unrecognized option %s\n", args[1]);
228.1238 +}
228.1239 +
228.1240 +void debuggerEditByte(int n, char **args)
228.1241 +{
228.1242 +  if(n == 3) {
228.1243 +    u32 address;
228.1244 +    u32 byte;
228.1245 +    sscanf(args[1], "%x", &address);
228.1246 +    sscanf(args[2], "%x", &byte);
228.1247 +    debuggerWriteByte(address, (u8)byte);
228.1248 +  } else
228.1249 +    debuggerUsage("eb");    
228.1250 +}
228.1251 +
228.1252 +void debuggerEditHalfWord(int n, char **args)
228.1253 +{
228.1254 +  if(n == 3) {
228.1255 +    u32 address;
228.1256 +    u32 byte;
228.1257 +    sscanf(args[1], "%x", &address);
228.1258 +    if(address & 1) {
228.1259 +      printf("Error: address must be half-word aligned\n");
228.1260 +      return;
228.1261 +    }
228.1262 +    sscanf(args[2], "%x", &byte);
228.1263 +    debuggerWriteHalfWord(address, (u16)byte);
228.1264 +  } else
228.1265 +    debuggerUsage("eh");        
228.1266 +}
228.1267 +
228.1268 +void debuggerEdit(int n, char **args)
228.1269 +{
228.1270 +  if(n == 3) {
228.1271 +    u32 address;
228.1272 +    u32 byte;
228.1273 +    sscanf(args[1], "%x", &address);
228.1274 +    if(address & 3) {
228.1275 +      printf("Error: address must be word aligned\n");
228.1276 +      return;
228.1277 +    }
228.1278 +    sscanf(args[2], "%x", &byte);
228.1279 +    debuggerWriteMemory(address, (u32)byte);
228.1280 +  } else
228.1281 +    debuggerUsage("ew");    
228.1282 +}
228.1283 +
228.1284 +
228.1285 +#define ASCII(c) (c) < 32 ? '.' : (c) > 127 ? '.' : (c)
228.1286 +
228.1287 +void debuggerMemoryByte(int n, char **args)
228.1288 +{
228.1289 +  if(n == 2) {
228.1290 +    u32 addr = 0;
228.1291 +    sscanf(args[1], "%x", &addr);
228.1292 +    for(int ii = 0; ii < 16; ii++) {
228.1293 +      int a = debuggerReadByte(addr);
228.1294 +      int b = debuggerReadByte(addr+1);
228.1295 +      int c = debuggerReadByte(addr+2);
228.1296 +      int d = debuggerReadByte(addr+3);
228.1297 +      int e = debuggerReadByte(addr+4);
228.1298 +      int f = debuggerReadByte(addr+5);
228.1299 +      int g = debuggerReadByte(addr+6);
228.1300 +      int h = debuggerReadByte(addr+7);
228.1301 +      int i = debuggerReadByte(addr+8);
228.1302 +      int j = debuggerReadByte(addr+9);
228.1303 +      int k = debuggerReadByte(addr+10);
228.1304 +      int l = debuggerReadByte(addr+11);
228.1305 +      int m = debuggerReadByte(addr+12);
228.1306 +      int n = debuggerReadByte(addr+13);
228.1307 +      int o = debuggerReadByte(addr+14);
228.1308 +      int p = debuggerReadByte(addr+15);
228.1309 +      
228.1310 +      printf("%08x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
228.1311 +             addr,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,
228.1312 +             ASCII(a),ASCII(b),ASCII(c),ASCII(d),
228.1313 +             ASCII(e),ASCII(f),ASCII(g),ASCII(h),
228.1314 +             ASCII(i),ASCII(j),ASCII(k),ASCII(l),
228.1315 +             ASCII(m),ASCII(n),ASCII(o),ASCII(p));
228.1316 +      addr += 16;
228.1317 +    }
228.1318 +  } else
228.1319 +    debuggerUsage("mb");    
228.1320 +}
228.1321 +
228.1322 +void debuggerMemoryHalfWord(int n, char **args)
228.1323 +{
228.1324 +  if(n == 2) {
228.1325 +    u32 addr = 0;
228.1326 +    sscanf(args[1], "%x", &addr);
228.1327 +    addr = addr & 0xfffffffe;
228.1328 +    for(int ii = 0; ii < 16; ii++) {
228.1329 +      int a = debuggerReadByte(addr);
228.1330 +      int b = debuggerReadByte(addr+1);
228.1331 +      int c = debuggerReadByte(addr+2);
228.1332 +      int d = debuggerReadByte(addr+3);
228.1333 +      int e = debuggerReadByte(addr+4);
228.1334 +      int f = debuggerReadByte(addr+5);
228.1335 +      int g = debuggerReadByte(addr+6);
228.1336 +      int h = debuggerReadByte(addr+7);
228.1337 +      int i = debuggerReadByte(addr+8);
228.1338 +      int j = debuggerReadByte(addr+9);
228.1339 +      int k = debuggerReadByte(addr+10);
228.1340 +      int l = debuggerReadByte(addr+11);
228.1341 +      int m = debuggerReadByte(addr+12);
228.1342 +      int n = debuggerReadByte(addr+13);
228.1343 +      int o = debuggerReadByte(addr+14);
228.1344 +      int p = debuggerReadByte(addr+15);
228.1345 +      
228.1346 +      printf("%08x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
228.1347 +             addr,b,a,d,c,f,e,h,g,j,i,l,k,n,m,p,o,
228.1348 +             ASCII(a),ASCII(b),ASCII(c),ASCII(d),
228.1349 +             ASCII(e),ASCII(f),ASCII(g),ASCII(h),
228.1350 +             ASCII(i),ASCII(j),ASCII(k),ASCII(l),
228.1351 +             ASCII(m),ASCII(n),ASCII(o),ASCII(p));
228.1352 +      addr += 16;
228.1353 +    }
228.1354 +  } else
228.1355 +    debuggerUsage("mh");    
228.1356 +}
228.1357 +
228.1358 +void debuggerMemory(int n, char **args)
228.1359 +{
228.1360 +  if(n == 2) {
228.1361 +    u32 addr = 0;
228.1362 +    sscanf(args[1], "%x", &addr);
228.1363 +    addr = addr & 0xfffffffc;
228.1364 +    for(int ii = 0; ii < 16; ii++) {
228.1365 +      int a = debuggerReadByte(addr);
228.1366 +      int b = debuggerReadByte(addr+1);
228.1367 +      int c = debuggerReadByte(addr+2);
228.1368 +      int d = debuggerReadByte(addr+3);
228.1369 +
228.1370 +      int e = debuggerReadByte(addr+4);
228.1371 +      int f = debuggerReadByte(addr+5);
228.1372 +      int g = debuggerReadByte(addr+6);
228.1373 +      int h = debuggerReadByte(addr+7);
228.1374 +
228.1375 +      int i = debuggerReadByte(addr+8);
228.1376 +      int j = debuggerReadByte(addr+9);
228.1377 +      int k = debuggerReadByte(addr+10);
228.1378 +      int l = debuggerReadByte(addr+11);
228.1379 +
228.1380 +      int m = debuggerReadByte(addr+12);
228.1381 +      int n = debuggerReadByte(addr+13);
228.1382 +      int o = debuggerReadByte(addr+14);
228.1383 +      int p = debuggerReadByte(addr+15);
228.1384 +      
228.1385 +      printf("%08x %02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
228.1386 +             addr,d,c,b,a,h,g,f,e,l,k,j,i,p,o,n,m,
228.1387 +             ASCII(a),ASCII(b),ASCII(c),ASCII(d),
228.1388 +             ASCII(e),ASCII(f),ASCII(g),ASCII(h),
228.1389 +             ASCII(i),ASCII(j),ASCII(k),ASCII(l),
228.1390 +             ASCII(m),ASCII(n),ASCII(o),ASCII(p));
228.1391 +      addr += 16;
228.1392 +    }
228.1393 +  } else
228.1394 +    debuggerUsage("mw");    
228.1395 +}
228.1396 +
228.1397 +void debuggerQuit(int, char **)
228.1398 +{
228.1399 +  char buffer[10];
228.1400 +  printf("Are you sure you want to quit (y/n)? ");
228.1401 +  fgets(buffer, 1024, stdin);
228.1402 +  
228.1403 +  if(buffer[0] == 'y' || buffer[0] == 'Y') {
228.1404 +    debugger = false;
228.1405 +    emulating = false;
228.1406 +  }
228.1407 +}
228.1408 +
228.1409 +void debuggerOutput(char *s, u32 addr)
228.1410 +{
228.1411 +  if(s)
228.1412 +    puts(s);
228.1413 +  else {
228.1414 +    char c;
228.1415 +
228.1416 +    c = debuggerReadByte(addr);
228.1417 +    addr++;
228.1418 +    while(c) {
228.1419 +      putchar(c);
228.1420 +      c = debuggerReadByte(addr);
228.1421 +      addr++;
228.1422 +    }
228.1423 +  }
228.1424 +}
228.1425 +
228.1426 +void debuggerMain()
228.1427 +{
228.1428 +  char buffer[1024];
228.1429 +  char *commands[10];
228.1430 +  int commandCount = 0;
228.1431 +  
228.1432 +  if(theEmulator.emuUpdateCPSR)
228.1433 +    theEmulator.emuUpdateCPSR();
228.1434 +  debuggerRegisters(0, NULL);
228.1435 +  
228.1436 +  while(debugger) {
228.1437 +    systemSoundPause();
228.1438 +    printf("debugger> ");
228.1439 +    commandCount = 0;
228.1440 +    char *s = fgets(buffer, 1024, stdin);
228.1441 +
228.1442 +    commands[0] = strtok(s, " \t\n");
228.1443 +    if(commands[0] == NULL)
228.1444 +      continue;
228.1445 +    commandCount++;
228.1446 +    while((s = strtok(NULL, " \t\n"))) {
228.1447 +      commands[commandCount++] = s;
228.1448 +      if(commandCount == 10)
228.1449 +        break;
228.1450 +    }
228.1451 +
228.1452 +    for(int j = 0; ; j++) {
228.1453 +      if(debuggerCommands[j].name == NULL) {
228.1454 +        printf("Unrecognized command %s. Type h for help.\n", commands[0]);
228.1455 +        break;
228.1456 +      }
228.1457 +      if(!strcmp(commands[0], debuggerCommands[j].name)) {
228.1458 +        debuggerCommands[j].function(commandCount, commands);
228.1459 +        break;
228.1460 +      }
228.1461 +    } 
228.1462 +  }
228.1463 +}
   229.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   229.2 +++ b/src/sdl/debugger.h	Sat Mar 03 10:31:27 2012 -0600
   229.3 @@ -0,0 +1,20 @@
   229.4 +// -*- C++ -*-
   229.5 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   229.6 +// Copyright (C) 1999-2003 Forgotten
   229.7 +// Copyright (C) 2004 Forgotten and the VBA development team
   229.8 +
   229.9 +// This program is free software; you can redistribute it and/or modify
  229.10 +// it under the terms of the GNU General Public License as published by
  229.11 +// the Free Software Foundation; either version 2, or(at your option)
  229.12 +// any later version.
  229.13 +//
  229.14 +// This program is distributed in the hope that it will be useful,
  229.15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  229.16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  229.17 +// GNU General Public License for more details.
  229.18 +//
  229.19 +// You should have received a copy of the GNU General Public License
  229.20 +// along with this program; if not, write to the Free Software Foundation,
  229.21 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  229.22 +
  229.23 +extern void debuggerMain();
   230.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   230.2 +++ b/src/sdl/expr-lex.cpp	Sat Mar 03 10:31:27 2012 -0600
   230.3 @@ -0,0 +1,1590 @@
   230.4 +#line 2 "expr-lex.cpp"
   230.5 +/* A lexical scanner generated by flex */
   230.6 +
   230.7 +/* Scanner skeleton version:
   230.8 + * $Header: /cvsroot/vba/VisualBoyAdvance/src/expr-lex.cpp,v 1.2 2003/06/06 14:17:21 forgotten Exp $
   230.9 + */
  230.10 +
  230.11 +#define FLEX_SCANNER
  230.12 +#define YY_FLEX_MAJOR_VERSION 2
  230.13 +#define YY_FLEX_MINOR_VERSION 5
  230.14 +
  230.15 +#include <stdio.h>
  230.16 +#ifdef __GNUC__
  230.17 +#include <unistd.h>
  230.18 +#endif
  230.19 +
  230.20 +
  230.21 +/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
  230.22 +#ifdef c_plusplus
  230.23 +#ifndef __cplusplus
  230.24 +#define __cplusplus
  230.25 +#endif
  230.26 +#endif
  230.27 +
  230.28 +
  230.29 +#ifdef __cplusplus
  230.30 +
  230.31 +#include <stdlib.h>
  230.32 +
  230.33 +/* Use prototypes in function declarations. */
  230.34 +#define YY_USE_PROTOS
  230.35 +
  230.36 +/* The "const" storage-class-modifier is valid. */
  230.37 +#define YY_USE_CONST
  230.38 +
  230.39 +#else   /* ! __cplusplus */
  230.40 +
  230.41 +#if __STDC__
  230.42 +
  230.43 +#define YY_USE_PROTOS
  230.44 +#define YY_USE_CONST
  230.45 +
  230.46 +#endif  /* __STDC__ */
  230.47 +#endif  /* ! __cplusplus */
  230.48 +
  230.49 +#ifdef __TURBOC__
  230.50 + #pragma warn -rch
  230.51 + #pragma warn -use
  230.52 +#include <io.h>
  230.53 +#include <stdlib.h>
  230.54 +#define YY_USE_CONST
  230.55 +#define YY_USE_PROTOS
  230.56 +#endif
  230.57 +
  230.58 +#ifdef YY_USE_CONST
  230.59 +#define yyconst const
  230.60 +#else
  230.61 +#define yyconst
  230.62 +#endif
  230.63 +
  230.64 +
  230.65 +#ifdef YY_USE_PROTOS
  230.66 +#define YY_PROTO(proto) proto
  230.67 +#else
  230.68 +#define YY_PROTO(proto) ()
  230.69 +#endif
  230.70 +
  230.71 +/* Returned upon end-of-file. */
  230.72 +#define YY_NULL 0
  230.73 +
  230.74 +/* Promotes a possibly negative, possibly signed char to an unsigned
  230.75 + * integer for use as an array index.  If the signed char is negative,
  230.76 + * we want to instead treat it as an 8-bit unsigned char, hence the
  230.77 + * double cast.
  230.78 + */
  230.79 +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
  230.80 +
  230.81 +/* Enter a start condition.  This macro really ought to take a parameter,
  230.82 + * but we do it the disgusting crufty way forced on us by the ()-less
  230.83 + * definition of BEGIN.
  230.84 + */
  230.85 +#define BEGIN yy_start = 1 + 2 *
  230.86 +
  230.87 +/* Translate the current start state into a value that can be later handed
  230.88 + * to BEGIN to return to the state.  The YYSTATE alias is for lex
  230.89 + * compatibility.
  230.90 + */
  230.91 +#define YY_START ((yy_start - 1) / 2)
  230.92 +#define YYSTATE YY_START
  230.93 +
  230.94 +/* Action number for EOF rule of a given start state. */
  230.95 +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
  230.96 +
  230.97 +/* Special action meaning "start processing a new file". */
  230.98 +#define YY_NEW_FILE yyrestart( yyin )
  230.99 +
 230.100 +#define YY_END_OF_BUFFER_CHAR 0
 230.101 +
 230.102 +/* Size of default input buffer. */
 230.103 +#define YY_BUF_SIZE 16384
 230.104 +
 230.105 +typedef struct yy_buffer_state *YY_BUFFER_STATE;
 230.106 +
 230.107 +extern int yyleng;
 230.108 +extern FILE *yyin, *yyout;
 230.109 +
 230.110 +#define EOB_ACT_CONTINUE_SCAN 0
 230.111 +#define EOB_ACT_END_OF_FILE 1
 230.112 +#define EOB_ACT_LAST_MATCH 2
 230.113 +
 230.114 +/* The funky do-while in the following #define is used to turn the definition
 230.115 + * int a single C statement (which needs a semi-colon terminator).  This
 230.116 + * avoids problems with code like:
 230.117 + *
 230.118 + *      if ( condition_holds )
 230.119 + *              yyless( 5 );
 230.120 + *      else
 230.121 + *              do_something_else();
 230.122 + *
 230.123 + * Prior to using the do-while the compiler would get upset at the
 230.124 + * "else" because it interpreted the "if" statement as being all
 230.125 + * done when it reached the ';' after the yyless() call.
 230.126 + */
 230.127 +
 230.128 +/* Return all but the first 'n' matched characters back to the input stream. */
 230.129 +
 230.130 +#define yyless(n) \
 230.131 +        do \
 230.132 +                { \
 230.133 +                /* Undo effects of setting up yytext. */ \
 230.134 +                *yy_cp = yy_hold_char; \
 230.135 +                YY_RESTORE_YY_MORE_OFFSET \
 230.136 +                yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \
 230.137 +                YY_DO_BEFORE_ACTION; /* set up yytext again */ \
 230.138 +                } \
 230.139 +        while ( 0 )
 230.140 +
 230.141 +#define unput(c) yyunput( c, yytext_ptr )
 230.142 +
 230.143 +/* The following is because we cannot portably get our hands on size_t
 230.144 + * (without autoconf's help, which isn't available because we want
 230.145 + * flex-generated scanners to compile on their own).
 230.146 + */
 230.147 +typedef unsigned int yy_size_t;
 230.148 +
 230.149 +
 230.150 +struct yy_buffer_state
 230.151 +        {
 230.152 +        FILE *yy_input_file;
 230.153 +
 230.154 +        char *yy_ch_buf;                /* input buffer */
 230.155 +        char *yy_buf_pos;               /* current position in input buffer */
 230.156 +
 230.157 +        /* Size of input buffer in bytes, not including room for EOB
 230.158 +         * characters.
 230.159 +         */
 230.160 +        yy_size_t yy_buf_size;
 230.161 +
 230.162 +        /* Number of characters read into yy_ch_buf, not including EOB
 230.163 +         * characters.
 230.164 +         */
 230.165 +        int yy_n_chars;
 230.166 +
 230.167 +        /* Whether we "own" the buffer - i.e., we know we created it,
 230.168 +         * and can realloc() it to grow it, and should free() it to
 230.169 +         * delete it.
 230.170 +         */
 230.171 +        int yy_is_our_buffer;
 230.172 +
 230.173 +        /* Whether this is an "interactive" input source; if so, and
 230.174 +         * if we're using stdio for input, then we want to use getc()
 230.175 +         * instead of fread(), to make sure we stop fetching input after
 230.176 +         * each newline.
 230.177 +         */
 230.178 +        int yy_is_interactive;
 230.179 +
 230.180 +        /* Whether we're considered to be at the beginning of a line.
 230.181 +         * If so, '^' rules will be active on the next match, otherwise
 230.182 +         * not.
 230.183 +         */
 230.184 +        int yy_at_bol;
 230.185 +
 230.186 +        /* Whether to try to fill the input buffer when we reach the
 230.187 +         * end of it.
 230.188 +         */
 230.189 +        int yy_fill_buffer;
 230.190 +
 230.191 +        int yy_buffer_status;
 230.192 +#define YY_BUFFER_NEW 0
 230.193 +#define YY_BUFFER_NORMAL 1
 230.194 +        /* When an EOF's been seen but there's still some text to process
 230.195 +         * then we mark the buffer as YY_EOF_PENDING, to indicate that we
 230.196 +         * shouldn't try reading from the input source any more.  We might
 230.197 +         * still have a bunch of tokens to match, though, because of
 230.198 +         * possible backing-up.
 230.199 +         *
 230.200 +         * When we actually see the EOF, we change the status to "new"
 230.201 +         * (via yyrestart()), so that the user can continue scanning by
 230.202 +         * just pointing yyin at a new input file.
 230.203 +         */
 230.204 +#define YY_BUFFER_EOF_PENDING 2
 230.205 +        };
 230.206 +
 230.207 +static YY_BUFFER_STATE yy_current_buffer = 0;
 230.208 +
 230.209 +/* We provide macros for accessing buffer states in case in the
 230.210 + * future we want to put the buffer states in a more general
 230.211 + * "scanner state".
 230.212 + */
 230.213 +#define YY_CURRENT_BUFFER yy_current_buffer
 230.214 +
 230.215 +
 230.216 +/* yy_hold_char holds the character lost when yytext is formed. */
 230.217 +static char yy_hold_char;
 230.218 +
 230.219 +static int yy_n_chars;          /* number of characters read into yy_ch_buf */
 230.220 +
 230.221 +
 230.222 +int yyleng;
 230.223 +
 230.224 +/* Points to current character in buffer. */
 230.225 +static char *yy_c_buf_p = (char *) 0;
 230.226 +static int yy_init = 1;         /* whether we need to initialize */
 230.227 +static int yy_start = 0;        /* start state number */
 230.228 +
 230.229 +/* Flag which is used to allow yywrap()'s to do buffer switches
 230.230 + * instead of setting up a fresh yyin.  A bit of a hack ...
 230.231 + */
 230.232 +static int yy_did_buffer_switch_on_eof;
 230.233 +
 230.234 +void yyrestart YY_PROTO(( FILE *input_file ));
 230.235 +
 230.236 +void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
 230.237 +void yy_load_buffer_state YY_PROTO(( void ));
 230.238 +YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
 230.239 +void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
 230.240 +void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
 230.241 +void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));
 230.242 +#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )
 230.243 +
 230.244 +YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size ));
 230.245 +YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str ));
 230.246 +YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));
 230.247 +
 230.248 +static void *yy_flex_alloc YY_PROTO(( yy_size_t ));
 230.249 +static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));
 230.250 +static void yy_flex_free YY_PROTO(( void * ));
 230.251 +
 230.252 +#define yy_new_buffer yy_create_buffer
 230.253 +
 230.254 +#define yy_set_interactive(is_interactive) \
 230.255 +        { \
 230.256 +        if ( ! yy_current_buffer ) \
 230.257 +                yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
 230.258 +        yy_current_buffer->yy_is_interactive = is_interactive; \
 230.259 +        }
 230.260 +
 230.261 +#define yy_set_bol(at_bol) \
 230.262 +        { \
 230.263 +        if ( ! yy_current_buffer ) \
 230.264 +                yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
 230.265 +        yy_current_buffer->yy_at_bol = at_bol; \
 230.266 +        }
 230.267 +
 230.268 +#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)
 230.269 +
 230.270 +
 230.271 +#define yywrap() 1
 230.272 +#define YY_SKIP_YYWRAP
 230.273 +typedef unsigned char YY_CHAR;
 230.274 +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
 230.275 +typedef int yy_state_type;
 230.276 +extern char *yytext;
 230.277 +#define yytext_ptr yytext
 230.278 +
 230.279 +static yy_state_type yy_get_previous_state YY_PROTO(( void ));
 230.280 +static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
 230.281 +static int yy_get_next_buffer YY_PROTO(( void ));
 230.282 +static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
 230.283 +
 230.284 +/* Done after the current pattern has been matched and before the
 230.285 + * corresponding action - sets up yytext.
 230.286 + */
 230.287 +#define YY_DO_BEFORE_ACTION \
 230.288 +        yytext_ptr = yy_bp; \
 230.289 +        yyleng = (int) (yy_cp - yy_bp); \
 230.290 +        yy_hold_char = *yy_cp; \
 230.291 +        *yy_cp = '\0'; \
 230.292 +        yy_c_buf_p = yy_cp;
 230.293 +
 230.294 +#define YY_NUM_RULES 10
 230.295 +#define YY_END_OF_BUFFER 11
 230.296 +static yyconst short int yy_accept[24] =
 230.297 +    {   0,
 230.298 +        0,    0,   11,    9,    8,    8,    6,    7,    9,    4,
 230.299 +        3,    2,    2,    8,    5,    3,    2,    2,    2,    2,
 230.300 +        2,    1,    0
 230.301 +    } ;
 230.302 +
 230.303 +static yyconst int yy_ec[256] =
 230.304 +    {   0,
 230.305 +        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
 230.306 +        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 230.307 +        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 230.308 +        1,    2,    1,    1,    1,    1,    1,    4,    1,    1,
 230.309 +        1,    5,    1,    1,    6,    7,    1,    8,    8,    8,
 230.310 +        8,    8,    8,    8,    8,    8,    8,    1,    1,    1,
 230.311 +        1,    9,    1,    1,   10,   10,   10,   10,   10,   10,
 230.312 +       10,   10,   10,   10,   10,   10,   10,   10,   10,   10,
 230.313 +       10,   10,   10,   10,   10,   10,   10,   10,   10,   10,
 230.314 +        1,    1,    1,    1,   10,    1,   10,   10,   10,   10,
 230.315 +
 230.316 +       11,   12,   10,   10,   13,   10,   10,   10,   10,   10,
 230.317 +       14,   10,   10,   10,   15,   10,   10,   10,   10,   10,
 230.318 +       10,   16,    1,    1,    1,    1,    1,    1,    1,    1,
 230.319 +        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 230.320 +        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 230.321 +        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 230.322 +        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 230.323 +        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 230.324 +        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 230.325 +        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 230.326 +
 230.327 +        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 230.328 +        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 230.329 +        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 230.330 +        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 230.331 +        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 230.332 +        1,    1,    1,    1,    1
 230.333 +    } ;
 230.334 +
 230.335 +static yyconst int yy_meta[17] =
 230.336 +    {   0,
 230.337 +        1,    1,    1,    1,    1,    1,    1,    2,    1,    2,
 230.338 +        2,    2,    2,    2,    2,    2
 230.339 +    } ;
 230.340 +
 230.341 +static yyconst short int yy_base[25] =
 230.342 +    {   0,
 230.343 +        0,    0,   32,   33,   15,   17,   33,   33,   22,   33,
 230.344 +       22,    0,   16,   19,   33,   20,    0,   11,   15,   11,
 230.345 +       12,    0,   33,   21
 230.346 +    } ;
 230.347 +
 230.348 +static yyconst short int yy_def[25] =
 230.349 +    {   0,
 230.350 +       23,    1,   23,   23,   23,   23,   23,   23,   23,   23,
 230.351 +       23,   24,   24,   23,   23,   23,   24,   24,   24,   24,
 230.352 +       24,   24,    0,   23
 230.353 +    } ;
 230.354 +
 230.355 +static yyconst short int yy_nxt[50] =
 230.356 +    {   0,
 230.357 +        4,    5,    6,    7,    8,    9,   10,   11,    4,   12,
 230.358 +       12,   12,   12,   12,   13,   12,   14,   14,   14,   14,
 230.359 +       14,   14,   17,   22,   21,   20,   19,   16,   18,   16,
 230.360 +       15,   23,    3,   23,   23,   23,   23,   23,   23,   23,
 230.361 +       23,   23,   23,   23,   23,   23,   23,   23,   23
 230.362 +    } ;
 230.363 +
 230.364 +static yyconst short int yy_chk[50] =
 230.365 +    {   0,
 230.366 +        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 230.367 +        1,    1,    1,    1,    1,    1,    5,    5,    6,    6,
 230.368 +       14,   14,   24,   21,   20,   19,   18,   16,   13,   11,
 230.369 +        9,    3,   23,   23,   23,   23,   23,   23,   23,   23,
 230.370 +       23,   23,   23,   23,   23,   23,   23,   23,   23
 230.371 +    } ;
 230.372 +
 230.373 +static yy_state_type yy_last_accepting_state;
 230.374 +static char *yy_last_accepting_cpos;
 230.375 +
 230.376 +/* The intent behind this definition is that it'll catch
 230.377 + * any uses of REJECT which flex missed.
 230.378 + */
 230.379 +#define REJECT reject_used_but_not_detected
 230.380 +#define yymore() yymore_used_but_not_detected
 230.381 +#define YY_MORE_ADJ 0
 230.382 +#define YY_RESTORE_YY_MORE_OFFSET
 230.383 +char *yytext;
 230.384 +#line 1 "expr.l"
 230.385 +#define INITIAL 0
 230.386 +#line 2 "expr.l"
 230.387 +#include "expr.cpp.h"
 230.388 +
 230.389 +#ifndef __GNUC__
 230.390 +#include <io.h>
 230.391 +#define isatty _isatty
 230.392 +#endif
 230.393 +
 230.394 +char *exprString;
 230.395 +int exprCol;
 230.396 +
 230.397 +#define YY_INPUT(buf,result,max_size) \
 230.398 +    { \
 230.399 +    int c = *exprString++; \
 230.400 +    exprCol++;\
 230.401 +    result = (c == 0) ? YY_NULL : (buf[0] = c, 1); \
 230.402 +    }
 230.403 +#define YY_MAIN 0
 230.404 +#line 400 "expr-lex.cpp"
 230.405 +
 230.406 +/* Macros after this point can all be overridden by user definitions in
 230.407 + * section 1.
 230.408 + */
 230.409 +
 230.410 +#ifndef YY_SKIP_YYWRAP
 230.411 +#ifdef __cplusplus
 230.412 +extern "C" int yywrap YY_PROTO(( void ));
 230.413 +#else
 230.414 +extern int yywrap YY_PROTO(( void ));
 230.415 +#endif
 230.416 +#endif
 230.417 +
 230.418 +#ifndef YY_NO_UNPUT
 230.419 +static void yyunput YY_PROTO(( int c, char *buf_ptr ));
 230.420 +#endif
 230.421 +
 230.422 +#ifndef yytext_ptr
 230.423 +static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));
 230.424 +#endif
 230.425 +
 230.426 +#ifdef YY_NEED_STRLEN
 230.427 +static int yy_flex_strlen YY_PROTO(( yyconst char * ));
 230.428 +#endif
 230.429 +
 230.430 +#ifndef YY_NO_INPUT
 230.431 +#ifdef __cplusplus
 230.432 +static int yyinput YY_PROTO(( void ));
 230.433 +#else
 230.434 +static int input YY_PROTO(( void ));
 230.435 +#endif
 230.436 +#endif
 230.437 +
 230.438 +#if YY_STACK_USED
 230.439 +static int yy_start_stack_ptr = 0;
 230.440 +static int yy_start_stack_depth = 0;
 230.441 +static int *yy_start_stack = 0;
 230.442 +#ifndef YY_NO_PUSH_STATE
 230.443 +static void yy_push_state YY_PROTO(( int new_state ));
 230.444 +#endif
 230.445 +#ifndef YY_NO_POP_STATE
 230.446 +static void yy_pop_state YY_PROTO(( void ));
 230.447 +#endif
 230.448 +#ifndef YY_NO_TOP_STATE
 230.449 +static int yy_top_state YY_PROTO(( void ));
 230.450 +#endif
 230.451 +
 230.452 +#else
 230.453 +#define YY_NO_PUSH_STATE 1
 230.454 +#define YY_NO_POP_STATE 1
 230.455 +#define YY_NO_TOP_STATE 1
 230.456 +#endif
 230.457 +
 230.458 +#ifdef YY_MALLOC_DECL
 230.459 +YY_MALLOC_DECL
 230.460 +#else
 230.461 +#if __STDC__
 230.462 +#ifndef __cplusplus
 230.463 +#include <stdlib.h>
 230.464 +#endif
 230.465 +#else
 230.466 +/* Just try to get by without declaring the routines.  This will fail
 230.467 + * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
 230.468 + * or sizeof(void*) != sizeof(int).
 230.469 + */
 230.470 +#endif
 230.471 +#endif
 230.472 +
 230.473 +/* Amount of stuff to slurp up with each read. */
 230.474 +#ifndef YY_READ_BUF_SIZE
 230.475 +#define YY_READ_BUF_SIZE 8192
 230.476 +#endif
 230.477 +
 230.478 +/* Copy whatever the last rule matched to the standard output. */
 230.479 +
 230.480 +#ifndef ECHO
 230.481 +/* This used to be an fputs(), but since the string might contain NUL's,
 230.482 + * we now use fwrite().
 230.483 + */
 230.484 +#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
 230.485 +#endif
 230.486 +
 230.487 +/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
 230.488 + * is returned in "result".
 230.489 + */
 230.490 +#ifndef YY_INPUT
 230.491 +#define YY_INPUT(buf,result,max_size) \
 230.492 +        if ( yy_current_buffer->yy_is_interactive ) \
 230.493 +                { \
 230.494 +                int c = '*', n; \
 230.495 +                for ( n = 0; n < max_size && \
 230.496 +                             (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
 230.497 +                        buf[n] = (char) c; \
 230.498 +                if ( c == '\n' ) \
 230.499 +                        buf[n++] = (char) c; \
 230.500 +                if ( c == EOF && ferror( yyin ) ) \
 230.501 +                        YY_FATAL_ERROR( "input in flex scanner failed" ); \
 230.502 +                result = n; \
 230.503 +                } \
 230.504 +        else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
 230.505 +                  && ferror( yyin ) ) \
 230.506 +                YY_FATAL_ERROR( "input in flex scanner failed" );
 230.507 +#endif
 230.508 +
 230.509 +/* No semi-colon after return; correct usage is to write "yyterminate();" -
 230.510 + * we don't want an extra ';' after the "return" because that will cause
 230.511 + * some compilers to complain about unreachable statements.
 230.512 + */
 230.513 +#ifndef yyterminate
 230.514 +#define yyterminate() return YY_NULL
 230.515 +#endif
 230.516 +
 230.517 +/* Number of entries by which start-condition stack grows. */
 230.518 +#ifndef YY_START_STACK_INCR
 230.519 +#define YY_START_STACK_INCR 25
 230.520 +#endif
 230.521 +
 230.522 +/* Report a fatal error. */
 230.523 +#ifndef YY_FATAL_ERROR
 230.524 +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
 230.525 +#endif
 230.526 +
 230.527 +/* Default declaration of generated scanner - a define so the user can
 230.528 + * easily add parameters.
 230.529 + */
 230.530 +#ifndef YY_DECL
 230.531 +#define YY_DECL int yylex YY_PROTO(( void ))
 230.532 +#endif
 230.533 +
 230.534 +/* Code executed at the beginning of each rule, after yytext and yyleng
 230.535 + * have been set up.
 230.536 + */
 230.537 +#ifndef YY_USER_ACTION
 230.538 +#define YY_USER_ACTION
 230.539 +#endif
 230.540 +
 230.541 +/* Code executed at the end of each rule. */
 230.542 +#ifndef YY_BREAK
 230.543 +#define YY_BREAK break;
 230.544 +#endif
 230.545 +
 230.546 +#define YY_RULE_SETUP \
 230.547 +        YY_USER_ACTION
 230.548 +
 230.549 +YY_DECL
 230.550 +        {
 230.551 +        register yy_state_type yy_current_state;
 230.552 +        register char *yy_cp = NULL, *yy_bp = NULL;
 230.553 +        register int yy_act;
 230.554 +
 230.555 +#line 31 "expr.l"
 230.556 +
 230.557 +
 230.558 +#line 554 "expr-lex.cpp"
 230.559 +
 230.560 +        if ( yy_init )
 230.561 +                {
 230.562 +                yy_init = 0;
 230.563 +
 230.564 +#ifdef YY_USER_INIT
 230.565 +                YY_USER_INIT;
 230.566 +#endif
 230.567 +
 230.568 +                if ( ! yy_start )
 230.569 +                        yy_start = 1;   /* first start state */
 230.570 +
 230.571 +                if ( ! yyin )
 230.572 +                        yyin = stdin;
 230.573 +
 230.574 +                if ( ! yyout )
 230.575 +                        yyout = stdout;
 230.576 +
 230.577 +                if ( ! yy_current_buffer )
 230.578 +                        yy_current_buffer =
 230.579 +                                yy_create_buffer( yyin, YY_BUF_SIZE );
 230.580 +
 230.581 +                yy_load_buffer_state();
 230.582 +                }
 230.583 +
 230.584 +        while ( 1 )             /* loops until end-of-file is reached */
 230.585 +                {
 230.586 +                yy_cp = yy_c_buf_p;
 230.587 +
 230.588 +                /* Support of yytext. */
 230.589 +                *yy_cp = yy_hold_char;
 230.590 +
 230.591 +                /* yy_bp points to the position in yy_ch_buf of the start of
 230.592 +                 * the current run.
 230.593 +                 */
 230.594 +                yy_bp = yy_cp;
 230.595 +
 230.596 +                yy_current_state = yy_start;
 230.597 +yy_match:
 230.598 +                do
 230.599 +                        {
 230.600 +                        register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
 230.601 +                        if ( yy_accept[yy_current_state] )
 230.602 +                                {
 230.603 +                                yy_last_accepting_state = yy_current_state;
 230.604 +                                yy_last_accepting_cpos = yy_cp;
 230.605 +                                }
 230.606 +                        while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 230.607 +                                {
 230.608 +                                yy_current_state = (int) yy_def[yy_current_state];
 230.609 +                                if ( yy_current_state >= 24 )
 230.610 +                                        yy_c = yy_meta[(unsigned int) yy_c];
 230.611 +                                }
 230.612 +                        yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
 230.613 +                        ++yy_cp;
 230.614 +                        }
 230.615 +                while ( yy_base[yy_current_state] != 33 );
 230.616 +
 230.617 +yy_find_action:
 230.618 +                yy_act = yy_accept[yy_current_state];
 230.619 +                if ( yy_act == 0 )
 230.620 +                        { /* have to back up */
 230.621 +                        yy_cp = yy_last_accepting_cpos;
 230.622 +                        yy_current_state = yy_last_accepting_state;
 230.623 +                        yy_act = yy_accept[yy_current_state];
 230.624 +                        }
 230.625 +
 230.626 +                YY_DO_BEFORE_ACTION;
 230.627 +
 230.628 +
 230.629 +do_action:      /* This label is used only to access EOF actions. */
 230.630 +
 230.631 +
 230.632 +                switch ( yy_act )
 230.633 +        { /* beginning of action switch */
 230.634 +                        case 0: /* must back up */
 230.635 +                        /* undo the effects of YY_DO_BEFORE_ACTION */
 230.636 +                        *yy_cp = yy_hold_char;
 230.637 +                        yy_cp = yy_last_accepting_cpos;
 230.638 +                        yy_current_state = yy_last_accepting_state;
 230.639 +                        goto yy_find_action;
 230.640 +
 230.641 +case 1:
 230.642 +YY_RULE_SETUP
 230.643 +#line 33 "expr.l"
 230.644 +{
 230.645 +        return TOKEN_SIZEOF;
 230.646 +}
 230.647 +        YY_BREAK
 230.648 +case 2:
 230.649 +YY_RULE_SETUP
 230.650 +#line 37 "expr.l"
 230.651 +{
 230.652 +        return TOKEN_IDENTIFIER;
 230.653 +}
 230.654 +        YY_BREAK
 230.655 +case 3:
 230.656 +YY_RULE_SETUP
 230.657 +#line 41 "expr.l"
 230.658 +{
 230.659 +        return TOKEN_NUMBER;
 230.660 +}
 230.661 +        YY_BREAK
 230.662 +case 4:
 230.663 +YY_RULE_SETUP
 230.664 +#line 45 "expr.l"
 230.665 +{
 230.666 +        return TOKEN_DOT;
 230.667 +}       
 230.668 +        YY_BREAK
 230.669 +case 5:
 230.670 +YY_RULE_SETUP
 230.671 +#line 49 "expr.l"
 230.672 +{
 230.673 +        return TOKEN_ARROW;
 230.674 +}
 230.675 +        YY_BREAK
 230.676 +case 6:
 230.677 +YY_RULE_SETUP
 230.678 +#line 53 "expr.l"
 230.679 +{
 230.680 +        return TOKEN_ADDR;
 230.681 +}
 230.682 +        YY_BREAK
 230.683 +case 7:
 230.684 +YY_RULE_SETUP
 230.685 +#line 57 "expr.l"
 230.686 +{
 230.687 +        return TOKEN_STAR;
 230.688 +}
 230.689 +        YY_BREAK
 230.690 +case 8:
 230.691 +YY_RULE_SETUP
 230.692 +#line 61 "expr.l"
 230.693 +
 230.694 +        YY_BREAK
 230.695 +case 9:
 230.696 +YY_RULE_SETUP
 230.697 +#line 63 "expr.l"
 230.698 +return *yytext;
 230.699 +        YY_BREAK
 230.700 +case 10:
 230.701 +YY_RULE_SETUP
 230.702 +#line 65 "expr.l"
 230.703 +ECHO;
 230.704 +        YY_BREAK
 230.705 +#line 701 "expr-lex.cpp"
 230.706 +case YY_STATE_EOF(INITIAL):
 230.707 +        yyterminate();
 230.708 +
 230.709 +        case YY_END_OF_BUFFER:
 230.710 +                {
 230.711 +                /* Amount of text matched not including the EOB char. */
 230.712 +                int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1;
 230.713 +
 230.714 +                /* Undo the effects of YY_DO_BEFORE_ACTION. */
 230.715 +                *yy_cp = yy_hold_char;
 230.716 +                YY_RESTORE_YY_MORE_OFFSET
 230.717 +
 230.718 +                if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW )
 230.719 +                        {
 230.720 +                        /* We're scanning a new file or input source.  It's
 230.721 +                         * possible that this happened because the user
 230.722 +                         * just pointed yyin at a new source and called
 230.723 +                         * yylex().  If so, then we have to assure
 230.724 +                         * consistency between yy_current_buffer and our
 230.725 +                         * globals.  Here is the right place to do so, because
 230.726 +                         * this is the first action (other than possibly a
 230.727 +                         * back-up) that will match for the new input source.
 230.728 +                         */
 230.729 +                        yy_n_chars = yy_current_buffer->yy_n_chars;
 230.730 +                        yy_current_buffer->yy_input_file = yyin;
 230.731 +                        yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
 230.732 +                        }
 230.733 +
 230.734 +                /* Note that here we test for yy_c_buf_p "<=" to the position
 230.735 +                 * of the first EOB in the buffer, since yy_c_buf_p will
 230.736 +                 * already have been incremented past the NUL character
 230.737 +                 * (since all states make transitions on EOB to the
 230.738 +                 * end-of-buffer state).  Contrast this with the test
 230.739 +                 * in input().
 230.740 +                 */
 230.741 +                if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
 230.742 +                        { /* This was really a NUL. */
 230.743 +                        yy_state_type yy_next_state;
 230.744 +
 230.745 +                        yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
 230.746 +
 230.747 +                        yy_current_state = yy_get_previous_state();
 230.748 +
 230.749 +                        /* Okay, we're now positioned to make the NUL
 230.750 +                         * transition.  We couldn't have
 230.751 +                         * yy_get_previous_state() go ahead and do it
 230.752 +                         * for us because it doesn't know how to deal
 230.753 +                         * with the possibility of jamming (and we don't
 230.754 +                         * want to build jamming into it because then it
 230.755 +                         * will run more slowly).
 230.756 +                         */
 230.757 +
 230.758 +                        yy_next_state = yy_try_NUL_trans( yy_current_state );
 230.759 +
 230.760 +                        yy_bp = yytext_ptr + YY_MORE_ADJ;
 230.761 +
 230.762 +                        if ( yy_next_state )
 230.763 +                                {
 230.764 +                                /* Consume the NUL. */
 230.765 +                                yy_cp = ++yy_c_buf_p;
 230.766 +                                yy_current_state = yy_next_state;
 230.767 +                                goto yy_match;
 230.768 +                                }
 230.769 +
 230.770 +                        else
 230.771 +                                {
 230.772 +                                yy_cp = yy_c_buf_p;
 230.773 +                                goto yy_find_action;
 230.774 +                                }
 230.775 +                        }
 230.776 +
 230.777 +                else switch ( yy_get_next_buffer() )
 230.778 +                        {
 230.779 +                        case EOB_ACT_END_OF_FILE:
 230.780 +                                {
 230.781 +                                yy_did_buffer_switch_on_eof = 0;
 230.782 +
 230.783 +                                if ( yywrap() )
 230.784 +                                        {
 230.785 +                                        /* Note: because we've taken care in
 230.786 +                                         * yy_get_next_buffer() to have set up
 230.787 +                                         * yytext, we can now set up
 230.788 +                                         * yy_c_buf_p so that if some total
 230.789 +                                         * hoser (like flex itself) wants to
 230.790 +                                         * call the scanner after we return the
 230.791 +                                         * YY_NULL, it'll still work - another
 230.792 +                                         * YY_NULL will get returned.
 230.793 +                                         */
 230.794 +                                        yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;
 230.795 +
 230.796 +                                        yy_act = YY_STATE_EOF(YY_START);
 230.797 +                                        goto do_action;
 230.798 +                                        }
 230.799 +
 230.800 +                                else
 230.801 +                                        {
 230.802 +                                        if ( ! yy_did_buffer_switch_on_eof )
 230.803 +                                                YY_NEW_FILE;
 230.804 +                                        }
 230.805 +                                break;
 230.806 +                                }
 230.807 +
 230.808 +                        case EOB_ACT_CONTINUE_SCAN:
 230.809 +                                yy_c_buf_p =
 230.810 +                                        yytext_ptr + yy_amount_of_matched_text;
 230.811 +
 230.812 +                                yy_current_state = yy_get_previous_state();
 230.813 +
 230.814 +                                yy_cp = yy_c_buf_p;
 230.815 +                                yy_bp = yytext_ptr + YY_MORE_ADJ;
 230.816 +                                goto yy_match;
 230.817 +
 230.818 +                        case EOB_ACT_LAST_MATCH:
 230.819 +                                yy_c_buf_p =
 230.820 +                                &yy_current_buffer->yy_ch_buf[yy_n_chars];
 230.821 +
 230.822 +                                yy_current_state = yy_get_previous_state();
 230.823 +
 230.824 +                                yy_cp = yy_c_buf_p;
 230.825 +                                yy_bp = yytext_ptr + YY_MORE_ADJ;
 230.826 +                                goto yy_find_action;
 230.827 +                        }
 230.828 +                break;
 230.829 +                }
 230.830 +
 230.831 +        default:
 230.832 +                YY_FATAL_ERROR(
 230.833 +                        "fatal flex scanner internal error--no action found" );
 230.834 +        } /* end of action switch */
 230.835 +                } /* end of scanning one token */
 230.836 +        } /* end of yylex */
 230.837 +
 230.838 +
 230.839 +/* yy_get_next_buffer - try to read in a new buffer
 230.840 + *
 230.841 + * Returns a code representing an action:
 230.842 + *      EOB_ACT_LAST_MATCH -
 230.843 + *      EOB_ACT_CONTINUE_SCAN - continue scanning from current position
 230.844 + *      EOB_ACT_END_OF_FILE - end of file
 230.845 + */
 230.846 +
 230.847 +static int yy_get_next_buffer()
 230.848 +        {
 230.849 +        register char *dest = yy_current_buffer->yy_ch_buf;
 230.850 +        register char *source = yytext_ptr;
 230.851 +        register int number_to_move, i;
 230.852 +        int ret_val;
 230.853 +
 230.854 +        if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
 230.855 +                YY_FATAL_ERROR(
 230.856 +                "fatal flex scanner internal error--end of buffer missed" );
 230.857 +
 230.858 +        if ( yy_current_buffer->yy_fill_buffer == 0 )
 230.859 +                { /* Don't try to fill the buffer, so this is an EOF. */
 230.860 +                if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
 230.861 +                        {
 230.862 +                        /* We matched a single character, the EOB, so
 230.863 +                         * treat this as a final EOF.
 230.864 +                         */
 230.865 +                        return EOB_ACT_END_OF_FILE;
 230.866 +                        }
 230.867 +
 230.868 +                else
 230.869 +                        {
 230.870 +                        /* We matched some text prior to the EOB, first
 230.871 +                         * process it.
 230.872 +                         */
 230.873 +                        return EOB_ACT_LAST_MATCH;
 230.874 +                        }
 230.875 +                }
 230.876 +
 230.877 +        /* Try to read more data. */
 230.878 +
 230.879 +        /* First move last chars to start of buffer. */
 230.880 +        number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;
 230.881 +
 230.882 +        for ( i = 0; i < number_to_move; ++i )
 230.883 +                *(dest++) = *(source++);
 230.884 +
 230.885 +        if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING )
 230.886 +                /* don't do the read, it's not guaranteed to return an EOF,
 230.887 +                 * just force an EOF
 230.888 +                 */
 230.889 +                yy_current_buffer->yy_n_chars = yy_n_chars = 0;
 230.890 +
 230.891 +        else
 230.892 +                {
 230.893 +                int num_to_read =
 230.894 +                        yy_current_buffer->yy_buf_size - number_to_move - 1;
 230.895 +
 230.896 +                while ( num_to_read <= 0 )
 230.897 +                        { /* Not enough room in the buffer - grow it. */
 230.898 +#ifdef YY_USES_REJECT
 230.899 +                        YY_FATAL_ERROR(
 230.900 +"input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
 230.901 +#else
 230.902 +
 230.903 +                        /* just a shorter name for the current buffer */
 230.904 +                        YY_BUFFER_STATE b = yy_current_buffer;
 230.905 +
 230.906 +                        int yy_c_buf_p_offset =
 230.907 +                                (int) (yy_c_buf_p - b->yy_ch_buf);
 230.908 +
 230.909 +                        if ( b->yy_is_our_buffer )
 230.910 +                                {
 230.911 +                                int new_size = b->yy_buf_size * 2;
 230.912 +
 230.913 +                                if ( new_size <= 0 )
 230.914 +                                        b->yy_buf_size += b->yy_buf_size / 8;
 230.915 +                                else
 230.916 +                                        b->yy_buf_size *= 2;
 230.917 +
 230.918 +                                b->yy_ch_buf = (char *)
 230.919 +                                        /* Include room in for 2 EOB chars. */
 230.920 +                                        yy_flex_realloc( (void *) b->yy_ch_buf,
 230.921 +                                                         b->yy_buf_size + 2 );
 230.922 +                                }
 230.923 +                        else
 230.924 +                                /* Can't grow it, we don't own it. */
 230.925 +                                b->yy_ch_buf = 0;
 230.926 +
 230.927 +                        if ( ! b->yy_ch_buf )
 230.928 +                                YY_FATAL_ERROR(
 230.929 +                                "fatal error - scanner input buffer overflow" );
 230.930 +
 230.931 +                        yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
 230.932 +
 230.933 +                        num_to_read = yy_current_buffer->yy_buf_size -
 230.934 +                                                number_to_move - 1;
 230.935 +#endif
 230.936 +                        }
 230.937 +
 230.938 +                if ( num_to_read > YY_READ_BUF_SIZE )
 230.939 +                        num_to_read = YY_READ_BUF_SIZE;
 230.940 +
 230.941 +                /* Read in more data. */
 230.942 +                YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
 230.943 +                        yy_n_chars, num_to_read );
 230.944 +
 230.945 +                yy_current_buffer->yy_n_chars = yy_n_chars;
 230.946 +                }
 230.947 +
 230.948 +        if ( yy_n_chars == 0 )
 230.949 +                {
 230.950 +                if ( number_to_move == YY_MORE_ADJ )
 230.951 +                        {
 230.952 +                        ret_val = EOB_ACT_END_OF_FILE;
 230.953 +                        yyrestart( yyin );
 230.954 +                        }
 230.955 +
 230.956 +                else
 230.957 +                        {
 230.958 +                        ret_val = EOB_ACT_LAST_MATCH;
 230.959 +                        yy_current_buffer->yy_buffer_status =
 230.960 +                                YY_BUFFER_EOF_PENDING;
 230.961 +                        }
 230.962 +                }
 230.963 +
 230.964 +        else
 230.965 +                ret_val = EOB_ACT_CONTINUE_SCAN;
 230.966 +
 230.967 +        yy_n_chars += number_to_move;
 230.968 +        yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
 230.969 +        yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
 230.970 +
 230.971 +        yytext_ptr = &yy_current_buffer->yy_ch_buf[0];
 230.972 +
 230.973 +        return ret_val;
 230.974 +        }
 230.975 +
 230.976 +
 230.977 +/* yy_get_previous_state - get the state just before the EOB char was reached */
 230.978 +
 230.979 +static yy_state_type yy_get_previous_state()
 230.980 +        {
 230.981 +        register yy_state_type yy_current_state;
 230.982 +        register char *yy_cp;
 230.983 +
 230.984 +        yy_current_state = yy_start;
 230.985 +
 230.986 +        for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
 230.987 +                {
 230.988 +                register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
 230.989 +                if ( yy_accept[yy_current_state] )
 230.990 +                        {
 230.991 +                        yy_last_accepting_state = yy_current_state;
 230.992 +                        yy_last_accepting_cpos = yy_cp;
 230.993 +                        }
 230.994 +                while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 230.995 +                        {
 230.996 +                        yy_current_state = (int) yy_def[yy_current_state];
 230.997 +                        if ( yy_current_state >= 24 )
 230.998 +                                yy_c = yy_meta[(unsigned int) yy_c];
 230.999 +                        }
230.1000 +                yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
230.1001 +                }
230.1002 +
230.1003 +        return yy_current_state;
230.1004 +        }
230.1005 +
230.1006 +
230.1007 +/* yy_try_NUL_trans - try to make a transition on the NUL character
230.1008 + *
230.1009 + * synopsis
230.1010 + *      next_state = yy_try_NUL_trans( current_state );
230.1011 + */
230.1012 +
230.1013 +#ifdef YY_USE_PROTOS
230.1014 +static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )
230.1015 +#else
230.1016 +static yy_state_type yy_try_NUL_trans( yy_current_state )
230.1017 +yy_state_type yy_current_state;
230.1018 +#endif
230.1019 +        {
230.1020 +        register int yy_is_jam;
230.1021 +        register char *yy_cp = yy_c_buf_p;
230.1022 +
230.1023 +        register YY_CHAR yy_c = 1;
230.1024 +        if ( yy_accept[yy_current_state] )
230.1025 +                {
230.1026 +                yy_last_accepting_state = yy_current_state;
230.1027 +                yy_last_accepting_cpos = yy_cp;
230.1028 +                }
230.1029 +        while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
230.1030 +                {
230.1031 +                yy_current_state = (int) yy_def[yy_current_state];
230.1032 +                if ( yy_current_state >= 24 )
230.1033 +                        yy_c = yy_meta[(unsigned int) yy_c];
230.1034 +                }
230.1035 +        yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
230.1036 +        yy_is_jam = (yy_current_state == 23);
230.1037 +
230.1038 +        return yy_is_jam ? 0 : yy_current_state;
230.1039 +        }
230.1040 +
230.1041 +
230.1042 +#ifndef YY_NO_UNPUT
230.1043 +#ifdef YY_USE_PROTOS
230.1044 +static void yyunput( int c, register char *yy_bp )
230.1045 +#else
230.1046 +static void yyunput( c, yy_bp )
230.1047 +int c;
230.1048 +register char *yy_bp;
230.1049 +#endif
230.1050 +        {
230.1051 +        register char *yy_cp = yy_c_buf_p;
230.1052 +
230.1053 +        /* undo effects of setting up yytext */
230.1054 +        *yy_cp = yy_hold_char;
230.1055 +
230.1056 +        if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
230.1057 +                { /* need to shift things up to make room */
230.1058 +                /* +2 for EOB chars. */
230.1059 +                register int number_to_move = yy_n_chars + 2;
230.1060 +                register char *dest = &yy_current_buffer->yy_ch_buf[
230.1061 +                                        yy_current_buffer->yy_buf_size + 2];
230.1062 +                register char *source =
230.1063 +                                &yy_current_buffer->yy_ch_buf[number_to_move];
230.1064 +
230.1065 +                while ( source > yy_current_buffer->yy_ch_buf )
230.1066 +                        *--dest = *--source;
230.1067 +
230.1068 +                yy_cp += (int) (dest - source);
230.1069 +                yy_bp += (int) (dest - source);
230.1070 +                yy_current_buffer->yy_n_chars =
230.1071 +                        yy_n_chars = yy_current_buffer->yy_buf_size;
230.1072 +
230.1073 +                if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
230.1074 +                        YY_FATAL_ERROR( "flex scanner push-back overflow" );
230.1075 +                }
230.1076 +
230.1077 +        *--yy_cp = (char) c;
230.1078 +
230.1079 +
230.1080 +        yytext_ptr = yy_bp;
230.1081 +        yy_hold_char = *yy_cp;
230.1082 +        yy_c_buf_p = yy_cp;
230.1083 +        }
230.1084 +#endif  /* ifndef YY_NO_UNPUT */
230.1085 +
230.1086 +
230.1087 +#ifdef __cplusplus
230.1088 +static int yyinput()
230.1089 +#else
230.1090 +static int input()
230.1091 +#endif
230.1092 +        {
230.1093 +        int c;
230.1094 +
230.1095 +        *yy_c_buf_p = yy_hold_char;
230.1096 +
230.1097 +        if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
230.1098 +                {
230.1099 +                /* yy_c_buf_p now points to the character we want to return.
230.1100 +                 * If this occurs *before* the EOB characters, then it's a
230.1101 +                 * valid NUL; if not, then we've hit the end of the buffer.
230.1102 +                 */
230.1103 +                if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
230.1104 +                        /* This was really a NUL. */
230.1105 +                        *yy_c_buf_p = '\0';
230.1106 +
230.1107 +                else
230.1108 +                        { /* need more input */
230.1109 +                        int offset = yy_c_buf_p - yytext_ptr;
230.1110 +                        ++yy_c_buf_p;
230.1111 +
230.1112 +                        switch ( yy_get_next_buffer() )
230.1113 +                                {
230.1114 +                                case EOB_ACT_LAST_MATCH:
230.1115 +                                        /* This happens because yy_g_n_b()
230.1116 +                                         * sees that we've accumulated a
230.1117 +                                         * token and flags that we need to
230.1118 +                                         * try matching the token before
230.1119 +                                         * proceeding.  But for input(),
230.1120 +                                         * there's no matching to consider.
230.1121 +                                         * So convert the EOB_ACT_LAST_MATCH
230.1122 +                                         * to EOB_ACT_END_OF_FILE.
230.1123 +                                         */
230.1124 +
230.1125 +                                        /* Reset buffer status. */
230.1126 +                                        yyrestart( yyin );
230.1127 +
230.1128 +                                        /* fall through */
230.1129 +
230.1130 +                                case EOB_ACT_END_OF_FILE:
230.1131 +                                        {
230.1132 +                                        if ( yywrap() )
230.1133 +                                                return EOF;
230.1134 +
230.1135 +                                        if ( ! yy_did_buffer_switch_on_eof )
230.1136 +                                                YY_NEW_FILE;
230.1137 +#ifdef __cplusplus
230.1138 +                                        return yyinput();
230.1139 +#else
230.1140 +                                        return input();
230.1141 +#endif
230.1142 +                                        }
230.1143 +
230.1144 +                                case EOB_ACT_CONTINUE_SCAN:
230.1145 +                                        yy_c_buf_p = yytext_ptr + offset;
230.1146 +                                        break;
230.1147 +                                }
230.1148 +                        }
230.1149 +                }
230.1150 +
230.1151 +        c = *(unsigned char *) yy_c_buf_p;      /* cast for 8-bit char's */
230.1152 +        *yy_c_buf_p = '\0';     /* preserve yytext */
230.1153 +        yy_hold_char = *++yy_c_buf_p;
230.1154 +
230.1155 +
230.1156 +        return c;
230.1157 +        }
230.1158 +
230.1159 +
230.1160 +#ifdef YY_USE_PROTOS
230.1161 +void yyrestart( FILE *input_file )
230.1162 +#else
230.1163 +void yyrestart( input_file )
230.1164 +FILE *input_file;
230.1165 +#endif
230.1166 +        {
230.1167 +        if ( ! yy_current_buffer )
230.1168 +                yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
230.1169 +
230.1170 +        yy_init_buffer( yy_current_buffer, input_file );
230.1171 +        yy_load_buffer_state();
230.1172 +        }
230.1173 +
230.1174 +
230.1175 +#ifdef YY_USE_PROTOS
230.1176 +void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
230.1177 +#else
230.1178 +void yy_switch_to_buffer( new_buffer )
230.1179 +YY_BUFFER_STATE new_buffer;
230.1180 +#endif
230.1181 +        {
230.1182 +        if ( yy_current_buffer == new_buffer )
230.1183 +                return;
230.1184 +
230.1185 +        if ( yy_current_buffer )
230.1186 +                {
230.1187 +                /* Flush out information for old buffer. */
230.1188 +                *yy_c_buf_p = yy_hold_char;
230.1189 +                yy_current_buffer->yy_buf_pos = yy_c_buf_p;
230.1190 +                yy_current_buffer->yy_n_chars = yy_n_chars;
230.1191 +                }
230.1192 +
230.1193 +        yy_current_buffer = new_buffer;
230.1194 +        yy_load_buffer_state();
230.1195 +
230.1196 +        /* We don't actually know whether we did this switch during
230.1197 +         * EOF (yywrap()) processing, but the only time this flag
230.1198 +         * is looked at is after yywrap() is called, so it's safe
230.1199 +         * to go ahead and always set it.
230.1200 +         */
230.1201 +        yy_did_buffer_switch_on_eof = 1;
230.1202 +        }
230.1203 +
230.1204 +
230.1205 +#ifdef YY_USE_PROTOS
230.1206 +void yy_load_buffer_state( void )
230.1207 +#else
230.1208 +void yy_load_buffer_state()
230.1209 +#endif
230.1210 +        {
230.1211 +        yy_n_chars = yy_current_buffer->yy_n_chars;
230.1212 +        yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
230.1213 +        yyin = yy_current_buffer->yy_input_file;
230.1214 +        yy_hold_char = *yy_c_buf_p;
230.1215 +        }
230.1216 +
230.1217 +
230.1218 +#ifdef YY_USE_PROTOS
230.1219 +YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
230.1220 +#else
230.1221 +YY_BUFFER_STATE yy_create_buffer( file, size )
230.1222 +FILE *file;
230.1223 +int size;
230.1224 +#endif
230.1225 +        {
230.1226 +        YY_BUFFER_STATE b;
230.1227 +
230.1228 +        b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
230.1229 +        if ( ! b )
230.1230 +                YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
230.1231 +
230.1232 +        b->yy_buf_size = size;
230.1233 +
230.1234 +        /* yy_ch_buf has to be 2 characters longer than the size given because
230.1235 +         * we need to put in 2 end-of-buffer characters.
230.1236 +         */
230.1237 +        b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 );
230.1238 +        if ( ! b->yy_ch_buf )
230.1239 +                YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
230.1240 +
230.1241 +        b->yy_is_our_buffer = 1;
230.1242 +
230.1243 +        yy_init_buffer( b, file );
230.1244 +
230.1245 +        return b;
230.1246 +        }
230.1247 +
230.1248 +
230.1249 +#ifdef YY_USE_PROTOS
230.1250 +void yy_delete_buffer( YY_BUFFER_STATE b )
230.1251 +#else
230.1252 +void yy_delete_buffer( b )
230.1253 +YY_BUFFER_STATE b;
230.1254 +#endif
230.1255 +        {
230.1256 +        if ( ! b )
230.1257 +                return;
230.1258 +
230.1259 +        if ( b == yy_current_buffer )
230.1260 +                yy_current_buffer = (YY_BUFFER_STATE) 0;
230.1261 +
230.1262 +        if ( b->yy_is_our_buffer )
230.1263 +                yy_flex_free( (void *) b->yy_ch_buf );
230.1264 +
230.1265 +        yy_flex_free( (void *) b );
230.1266 +        }
230.1267 +
230.1268 +
230.1269 +
230.1270 +#ifdef YY_USE_PROTOS
230.1271 +void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
230.1272 +#else
230.1273 +void yy_init_buffer( b, file )
230.1274 +YY_BUFFER_STATE b;
230.1275 +FILE *file;
230.1276 +#endif
230.1277 +
230.1278 +
230.1279 +        {
230.1280 +        yy_flush_buffer( b );
230.1281 +
230.1282 +        b->yy_input_file = file;
230.1283 +        b->yy_fill_buffer = 1;
230.1284 +
230.1285 +#if YY_ALWAYS_INTERACTIVE
230.1286 +        b->yy_is_interactive = 1;
230.1287 +#else
230.1288 +#if YY_NEVER_INTERACTIVE
230.1289 +        b->yy_is_interactive = 0;
230.1290 +#else
230.1291 +        b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
230.1292 +#endif
230.1293 +#endif
230.1294 +        }
230.1295 +
230.1296 +
230.1297 +#ifdef YY_USE_PROTOS
230.1298 +void yy_flush_buffer( YY_BUFFER_STATE b )
230.1299 +#else
230.1300 +void yy_flush_buffer( b )
230.1301 +YY_BUFFER_STATE b;
230.1302 +#endif
230.1303 +
230.1304 +        {
230.1305 +        if ( ! b )
230.1306 +                return;
230.1307 +
230.1308 +        b->yy_n_chars = 0;
230.1309 +
230.1310 +        /* We always need two end-of-buffer characters.  The first causes
230.1311 +         * a transition to the end-of-buffer state.  The second causes
230.1312 +         * a jam in that state.
230.1313 +         */
230.1314 +        b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
230.1315 +        b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
230.1316 +
230.1317 +        b->yy_buf_pos = &b->yy_ch_buf[0];
230.1318 +
230.1319 +        b->yy_at_bol = 1;
230.1320 +        b->yy_buffer_status = YY_BUFFER_NEW;
230.1321 +
230.1322 +        if ( b == yy_current_buffer )
230.1323 +                yy_load_buffer_state();
230.1324 +        }
230.1325 +
230.1326 +
230.1327 +#ifndef YY_NO_SCAN_BUFFER
230.1328 +#ifdef YY_USE_PROTOS
230.1329 +YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )
230.1330 +#else
230.1331 +YY_BUFFER_STATE yy_scan_buffer( base, size )
230.1332 +char *base;
230.1333 +yy_size_t size;
230.1334 +#endif
230.1335 +        {
230.1336 +        YY_BUFFER_STATE b;
230.1337 +
230.1338 +        if ( size < 2 ||
230.1339 +             base[size-2] != YY_END_OF_BUFFER_CHAR ||
230.1340 +             base[size-1] != YY_END_OF_BUFFER_CHAR )
230.1341 +                /* They forgot to leave room for the EOB's. */
230.1342 +                return 0;
230.1343 +
230.1344 +        b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
230.1345 +        if ( ! b )
230.1346 +                YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
230.1347 +
230.1348 +        b->yy_buf_size = size - 2;      /* "- 2" to take care of EOB's */
230.1349 +        b->yy_buf_pos = b->yy_ch_buf = base;
230.1350 +        b->yy_is_our_buffer = 0;
230.1351 +        b->yy_input_file = 0;
230.1352 +        b->yy_n_chars = b->yy_buf_size;
230.1353 +        b->yy_is_interactive = 0;
230.1354 +        b->yy_at_bol = 1;
230.1355 +        b->yy_fill_buffer = 0;
230.1356 +        b->yy_buffer_status = YY_BUFFER_NEW;
230.1357 +
230.1358 +        yy_switch_to_buffer( b );
230.1359 +
230.1360 +        return b;
230.1361 +        }
230.1362 +#endif
230.1363 +
230.1364 +
230.1365 +#ifndef YY_NO_SCAN_STRING
230.1366 +#ifdef YY_USE_PROTOS
230.1367 +YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str )
230.1368 +#else
230.1369 +YY_BUFFER_STATE yy_scan_string( yy_str )
230.1370 +yyconst char *yy_str;
230.1371 +#endif
230.1372 +        {
230.1373 +        int len;
230.1374 +        for ( len = 0; yy_str[len]; ++len )
230.1375 +                ;
230.1376 +
230.1377 +        return yy_scan_bytes( yy_str, len );
230.1378 +        }
230.1379 +#endif
230.1380 +
230.1381 +
230.1382 +#ifndef YY_NO_SCAN_BYTES
230.1383 +#ifdef YY_USE_PROTOS
230.1384 +YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )
230.1385 +#else
230.1386 +YY_BUFFER_STATE yy_scan_bytes( bytes, len )
230.1387 +yyconst char *bytes;
230.1388 +int len;
230.1389 +#endif
230.1390 +        {
230.1391 +        YY_BUFFER_STATE b;
230.1392 +        char *buf;
230.1393 +        yy_size_t n;
230.1394 +        int i;
230.1395 +
230.1396 +        /* Get memory for full buffer, including space for trailing EOB's. */
230.1397 +        n = len + 2;
230.1398 +        buf = (char *) yy_flex_alloc( n );
230.1399 +        if ( ! buf )
230.1400 +                YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
230.1401 +
230.1402 +        for ( i = 0; i < len; ++i )
230.1403 +                buf[i] = bytes[i];
230.1404 +
230.1405 +        buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;
230.1406 +
230.1407 +        b = yy_scan_buffer( buf, n );
230.1408 +        if ( ! b )
230.1409 +                YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
230.1410 +
230.1411 +        /* It's okay to grow etc. this buffer, and we should throw it
230.1412 +         * away when we're done.
230.1413 +         */
230.1414 +        b->yy_is_our_buffer = 1;
230.1415 +
230.1416 +        return b;
230.1417 +        }
230.1418 +#endif
230.1419 +
230.1420 +
230.1421 +#ifndef YY_NO_PUSH_STATE
230.1422 +#ifdef YY_USE_PROTOS
230.1423 +static void yy_push_state( int new_state )
230.1424 +#else
230.1425 +static void yy_push_state( new_state )
230.1426 +int new_state;
230.1427 +#endif
230.1428 +        {
230.1429 +        if ( yy_start_stack_ptr >= yy_start_stack_depth )
230.1430 +                {
230.1431 +                yy_size_t new_size;
230.1432 +
230.1433 +                yy_start_stack_depth += YY_START_STACK_INCR;
230.1434 +                new_size = yy_start_stack_depth * sizeof( int );
230.1435 +
230.1436 +                if ( ! yy_start_stack )
230.1437 +                        yy_start_stack = (int *) yy_flex_alloc( new_size );
230.1438 +
230.1439 +                else
230.1440 +                        yy_start_stack = (int *) yy_flex_realloc(
230.1441 +                                        (void *) yy_start_stack, new_size );
230.1442 +
230.1443 +                if ( ! yy_start_stack )
230.1444 +                        YY_FATAL_ERROR(
230.1445 +                        "out of memory expanding start-condition stack" );
230.1446 +                }
230.1447 +
230.1448 +        yy_start_stack[yy_start_stack_ptr++] = YY_START;
230.1449 +
230.1450 +        BEGIN(new_state);
230.1451 +        }
230.1452 +#endif
230.1453 +
230.1454 +
230.1455 +#ifndef YY_NO_POP_STATE
230.1456 +static void yy_pop_state()
230.1457 +        {
230.1458 +        if ( --yy_start_stack_ptr < 0 )
230.1459 +                YY_FATAL_ERROR( "start-condition stack underflow" );
230.1460 +
230.1461 +        BEGIN(yy_start_stack[yy_start_stack_ptr]);
230.1462 +        }
230.1463 +#endif
230.1464 +
230.1465 +
230.1466 +#ifndef YY_NO_TOP_STATE
230.1467 +static int yy_top_state()
230.1468 +        {
230.1469 +        return yy_start_stack[yy_start_stack_ptr - 1];
230.1470 +        }
230.1471 +#endif
230.1472 +
230.1473 +#ifndef YY_EXIT_FAILURE
230.1474 +#define YY_EXIT_FAILURE 2
230.1475 +#endif
230.1476 +
230.1477 +#ifdef YY_USE_PROTOS
230.1478 +static void yy_fatal_error( yyconst char msg[] )
230.1479 +#else
230.1480 +static void yy_fatal_error( msg )
230.1481 +char msg[];
230.1482 +#endif
230.1483 +        {
230.1484 +        (void) fprintf( stderr, "%s\n", msg );
230.1485 +        exit( YY_EXIT_FAILURE );
230.1486 +        }
230.1487 +
230.1488 +
230.1489 +
230.1490 +/* Redefine yyless() so it works in section 3 code. */
230.1491 +
230.1492 +#undef yyless
230.1493 +#define yyless(n) \
230.1494 +        do \
230.1495 +                { \
230.1496 +                /* Undo effects of setting up yytext. */ \
230.1497 +                yytext[yyleng] = yy_hold_char; \
230.1498 +                yy_c_buf_p = yytext + n; \
230.1499 +                yy_hold_char = *yy_c_buf_p; \
230.1500 +                *yy_c_buf_p = '\0'; \
230.1501 +                yyleng = n; \
230.1502 +                } \
230.1503 +        while ( 0 )
230.1504 +
230.1505 +
230.1506 +/* Internal utility routines. */
230.1507 +
230.1508 +#ifndef yytext_ptr
230.1509 +#ifdef YY_USE_PROTOS
230.1510 +static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )
230.1511 +#else
230.1512 +static void yy_flex_strncpy( s1, s2, n )
230.1513 +char *s1;
230.1514 +yyconst char *s2;
230.1515 +int n;
230.1516 +#endif
230.1517 +        {
230.1518 +        register int i;
230.1519 +        for ( i = 0; i < n; ++i )
230.1520 +                s1[i] = s2[i];
230.1521 +        }
230.1522 +#endif
230.1523 +
230.1524 +#ifdef YY_NEED_STRLEN
230.1525 +#ifdef YY_USE_PROTOS
230.1526 +static int yy_flex_strlen( yyconst char *s )
230.1527 +#else
230.1528 +static int yy_flex_strlen( s )
230.1529 +yyconst char *s;
230.1530 +#endif
230.1531 +        {
230.1532 +        register int n;
230.1533 +        for ( n = 0; s[n]; ++n )
230.1534 +                ;
230.1535 +
230.1536 +        return n;
230.1537 +        }
230.1538 +#endif
230.1539 +
230.1540 +
230.1541 +#ifdef YY_USE_PROTOS
230.1542 +static void *yy_flex_alloc( yy_size_t size )
230.1543 +#else
230.1544 +static void *yy_flex_alloc( size )
230.1545 +yy_size_t size;
230.1546 +#endif
230.1547 +        {
230.1548 +        return (void *) malloc( size );
230.1549 +        }
230.1550 +
230.1551 +#ifdef YY_USE_PROTOS
230.1552 +static void *yy_flex_realloc( void *ptr, yy_size_t size )
230.1553 +#else
230.1554 +static void *yy_flex_realloc( ptr, size )
230.1555 +void *ptr;
230.1556 +yy_size_t size;
230.1557 +#endif
230.1558 +        {
230.1559 +        /* The cast to (char *) in the following accommodates both
230.1560 +         * implementations that use char* generic pointers, and those
230.1561 +         * that use void* generic pointers.  It works with the latter
230.1562 +         * because both ANSI C and C++ allow castless assignment from
230.1563 +         * any pointer type to void*, and deal with argument conversions
230.1564 +         * as though doing an assignment.
230.1565 +         */
230.1566 +        return (void *) realloc( (char *) ptr, size );
230.1567 +        }
230.1568 +
230.1569 +#ifdef YY_USE_PROTOS
230.1570 +static void yy_flex_free( void *ptr )
230.1571 +#else
230.1572 +static void yy_flex_free( ptr )
230.1573 +void *ptr;
230.1574 +#endif
230.1575 +        {
230.1576 +        free( ptr );
230.1577 +        }
230.1578 +
230.1579 +#if YY_MAIN
230.1580 +int main()
230.1581 +        {
230.1582 +        yylex();
230.1583 +        return 0;
230.1584 +        }
230.1585 +#endif
230.1586 +#line 65 "expr.l"
230.1587 +
230.1588 +
230.1589 +void exprCleanBuffer()
230.1590 +{
230.1591 +  yy_delete_buffer(yy_current_buffer);
230.1592 +  yy_init = 1;
230.1593 +}
   231.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   231.2 +++ b/src/sdl/expr.cpp	Sat Mar 03 10:31:27 2012 -0600
   231.3 @@ -0,0 +1,998 @@
   231.4 +
   231.5 +/*  A Bison parser, made from expr.y
   231.6 +    by GNU Bison version 1.28  */
   231.7 +
   231.8 +#define YYBISON 1  /* Identify Bison output.  */
   231.9 +
  231.10 +#define TOKEN_IDENTIFIER        257
  231.11 +#define TOKEN_DOT       258
  231.12 +#define TOKEN_STAR      259
  231.13 +#define TOKEN_ARROW     260
  231.14 +#define TOKEN_ADDR      261
  231.15 +#define TOKEN_SIZEOF    262
  231.16 +#define TOKEN_NUMBER    263
  231.17 +
  231.18 +#line 1 "expr.y"
  231.19 +
  231.20 +namespace std {  
  231.21 +#include <stdio.h>
  231.22 +#include <memory.h>
  231.23 +#include <stdlib.h>
  231.24 +#include <string.h>
  231.25 +}
  231.26 +
  231.27 +using namespace std;
  231.28 + 
  231.29 +#include "../common/System.h"
  231.30 +#include "../gba/elf.h"
  231.31 +#include "exprNode.h" 
  231.32 +
  231.33 +extern int yyerror(char *);
  231.34 +extern int yylex(); 
  231.35 +extern char *yytext;
  231.36 +
  231.37 +  
  231.38 +//#define YYERROR_VERBOSE 1
  231.39 +//#define YYDEBUG 1
  231.40 +
  231.41 + Node *result = NULL;
  231.42 +#ifndef YYSTYPE
  231.43 +#define YYSTYPE int
  231.44 +#endif
  231.45 +#include <stdio.h>
  231.46 +
  231.47 +#ifndef __cplusplus
  231.48 +#ifndef __STDC__
  231.49 +#define const
  231.50 +#endif
  231.51 +#endif
  231.52 +
  231.53 +
  231.54 +
  231.55 +#define YYFINAL         26
  231.56 +#define YYFLAG          -32768
  231.57 +#define YYNTBASE        14
  231.58 +
  231.59 +#define YYTRANSLATE(x) ((unsigned)(x) <= 263 ? yytranslate[x] : 19)
  231.60 +
  231.61 +static const char yytranslate[] = {     0,
  231.62 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.63 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.64 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.65 +     2,     2,     2,     2,     2,     2,     2,     2,     2,    11,
  231.66 +    12,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.67 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.68 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.69 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.70 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.71 +    10,     2,    13,     2,     2,     2,     2,     2,     2,     2,
  231.72 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.73 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.74 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.75 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.76 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.77 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.78 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.79 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.80 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.81 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.82 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.83 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.84 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.85 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.86 +     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.87 +     2,     2,     2,     2,     2,     1,     3,     4,     5,     6,
  231.88 +     7,     8,     9
  231.89 +};
  231.90 +
  231.91 +#if YYDEBUG != 0
  231.92 +static const short yyprhs[] = {     0,
  231.93 +     0,     2,     4,     8,    12,    16,    21,    23,    26,    29,
  231.94 +    34,    36
  231.95 +};
  231.96 +
  231.97 +static const short yyrhs[] = {    15,
  231.98 +     0,    16,     0,    11,    15,    12,     0,    15,     4,    18,
  231.99 +     0,    15,     6,    18,     0,    15,    10,    17,    13,     0,
 231.100 +    18,     0,     5,    15,     0,     7,    15,     0,     8,    11,
 231.101 +    15,    12,     0,     9,     0,     3,     0
 231.102 +};
 231.103 +
 231.104 +#endif
 231.105 +
 231.106 +#if YYDEBUG != 0
 231.107 +static const short yyrline[] = { 0,
 231.108 +    32,    35,    36,    37,    38,    39,    42,    43,    44,    45,
 231.109 +    49,    53
 231.110 +};
 231.111 +#endif
 231.112 +
 231.113 +
 231.114 +#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
 231.115 +
 231.116 +static const char * const yytname[] = {   "$","error","$undefined.","TOKEN_IDENTIFIER",
 231.117 +"TOKEN_DOT","TOKEN_STAR","TOKEN_ARROW","TOKEN_ADDR","TOKEN_SIZEOF","TOKEN_NUMBER",
 231.118 +"'['","'('","')'","']'","final","expression","simple_expression","number","ident", NULL
 231.119 +};
 231.120 +#endif
 231.121 +
 231.122 +static const short yyr1[] = {     0,
 231.123 +    14,    15,    15,    15,    15,    15,    16,    16,    16,    16,
 231.124 +    17,    18
 231.125 +};
 231.126 +
 231.127 +static const short yyr2[] = {     0,
 231.128 +     1,     1,     3,     3,     3,     4,     1,     2,     2,     4,
 231.129 +     1,     1
 231.130 +};
 231.131 +
 231.132 +static const short yydefact[] = {     0,
 231.133 +    12,     0,     0,     0,     0,     1,     2,     7,     8,     9,
 231.134 +     0,     0,     0,     0,     0,     0,     3,     4,     5,    11,
 231.135 +     0,    10,     6,     0,     0,     0
 231.136 +};
 231.137 +
 231.138 +static const short yydefgoto[] = {    24,
 231.139 +     6,     7,    21,     8
 231.140 +};
 231.141 +
 231.142 +static const short yypact[] = {    -1,
 231.143 +-32768,    -1,    -1,    -6,    -1,    17,-32768,-32768,    17,    17,
 231.144 +    -1,     7,     5,     5,    13,     8,-32768,-32768,-32768,-32768,
 231.145 +    11,-32768,-32768,    25,    26,-32768
 231.146 +};
 231.147 +
 231.148 +static const short yypgoto[] = {-32768,
 231.149 +    -2,-32768,-32768,     2
 231.150 +};
 231.151 +
 231.152 +
 231.153 +#define YYLAST          27
 231.154 +
 231.155 +
 231.156 +static const short yytable[] = {     9,
 231.157 +    10,     1,    12,     2,    11,     3,     4,     1,    16,     5,
 231.158 +    13,    13,    14,    14,    18,    19,    15,    15,    17,    22,
 231.159 +    13,    20,    14,    23,    25,    26,    15
 231.160 +};
 231.161 +
 231.162 +static const short yycheck[] = {     2,
 231.163 +     3,     3,     5,     5,    11,     7,     8,     3,    11,    11,
 231.164 +     4,     4,     6,     6,    13,    14,    10,    10,    12,    12,
 231.165 +     4,     9,     6,    13,     0,     0,    10
 231.166 +};
 231.167 +/* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
 231.168 +#line 3 "/usr/lib/bison.simple"
 231.169 +/* This file comes from bison-1.28.  */
 231.170 +
 231.171 +/* Skeleton output parser for bison,
 231.172 +   Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
 231.173 +
 231.174 +   This program is free software; you can redistribute it and/or modify
 231.175 +   it under the terms of the GNU General Public License as published by
 231.176 +   the Free Software Foundation; either version 2, or (at your option)
 231.177 +   any later version.
 231.178 +
 231.179 +   This program is distributed in the hope that it will be useful,
 231.180 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
 231.181 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 231.182 +   GNU General Public License for more details.
 231.183 +
 231.184 +   You should have received a copy of the GNU General Public License
 231.185 +   along with this program; if not, write to the Free Software
 231.186 +   Foundation, Inc., 59 Temple Place - Suite 330,
 231.187 +   Boston, MA 02111-1307, USA.  */
 231.188 +
 231.189 +/* As a special exception, when this file is copied by Bison into a
 231.190 +   Bison output file, you may use that output file without restriction.
 231.191 +   This special exception was added by the Free Software Foundation
 231.192 +   in version 1.24 of Bison.  */
 231.193 +
 231.194 +/* This is the parser code that is written into each bison parser
 231.195 +  when the %semantic_parser declaration is not specified in the grammar.
 231.196 +  It was written by Richard Stallman by simplifying the hairy parser
 231.197 +  used when %semantic_parser is specified.  */
 231.198 +
 231.199 +#ifndef YYSTACK_USE_ALLOCA
 231.200 +#ifdef alloca
 231.201 +#define YYSTACK_USE_ALLOCA
 231.202 +#else /* alloca not defined */
 231.203 +#ifdef __GNUC__
 231.204 +#define YYSTACK_USE_ALLOCA
 231.205 +#define alloca __builtin_alloca
 231.206 +#else /* not GNU C.  */
 231.207 +#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
 231.208 +#define YYSTACK_USE_ALLOCA
 231.209 +#include <alloca.h>
 231.210 +#else /* not sparc */
 231.211 +/* We think this test detects Watcom and Microsoft C.  */
 231.212 +/* This used to test MSDOS, but that is a bad idea
 231.213 +   since that symbol is in the user namespace.  */
 231.214 +#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
 231.215 +#if 0 /* No need for malloc.h, which pollutes the namespace;
 231.216 +         instead, just don't use alloca.  */
 231.217 +#include <malloc.h>
 231.218 +#endif
 231.219 +#else /* not MSDOS, or __TURBOC__ */
 231.220 +#if defined(_AIX)
 231.221 +/* I don't know what this was needed for, but it pollutes the namespace.
 231.222 +   So I turned it off.   rms, 2 May 1997.  */
 231.223 +/* #include <malloc.h>  */
 231.224 + #pragma alloca
 231.225 +#define YYSTACK_USE_ALLOCA
 231.226 +#else /* not MSDOS, or __TURBOC__, or _AIX */
 231.227 +#if 0
 231.228 +#ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
 231.229 +                 and on HPUX 10.  Eventually we can turn this on.  */
 231.230 +#define YYSTACK_USE_ALLOCA
 231.231 +#define alloca __builtin_alloca
 231.232 +#endif /* __hpux */
 231.233 +#endif
 231.234 +#endif /* not _AIX */
 231.235 +#endif /* not MSDOS, or __TURBOC__ */
 231.236 +#endif /* not sparc */
 231.237 +#endif /* not GNU C */
 231.238 +#endif /* alloca not defined */
 231.239 +#endif /* YYSTACK_USE_ALLOCA not defined */
 231.240 +
 231.241 +#ifdef YYSTACK_USE_ALLOCA
 231.242 +#define YYSTACK_ALLOC alloca
 231.243 +#else
 231.244 +#define YYSTACK_ALLOC malloc
 231.245 +#endif
 231.246 +
 231.247 +/* Note: there must be only one dollar sign in this file.
 231.248 +   It is replaced by the list of actions, each action
 231.249 +   as one case of the switch.  */
 231.250 +
 231.251 +#define yyerrok         (yyerrstatus = 0)
 231.252 +#define yyclearin       (yychar = YYEMPTY)
 231.253 +#define YYEMPTY         -2
 231.254 +#define YYEOF           0
 231.255 +#define YYACCEPT        goto yyacceptlab
 231.256 +#define YYABORT         goto yyabortlab
 231.257 +#define YYERROR         goto yyerrlab1
 231.258 +/* Like YYERROR except do call yyerror.
 231.259 +   This remains here temporarily to ease the
 231.260 +   transition to the new meaning of YYERROR, for GCC.
 231.261 +   Once GCC version 2 has supplanted version 1, this can go.  */
 231.262 +#define YYFAIL          goto yyerrlab
 231.263 +#define YYRECOVERING()  (!!yyerrstatus)
 231.264 +#define YYBACKUP(token, value) \
 231.265 +do                                                              \
 231.266 +  if (yychar == YYEMPTY && yylen == 1)                          \
 231.267 +    { yychar = (token), yylval = (value);                       \
 231.268 +      yychar1 = YYTRANSLATE (yychar);                           \
 231.269 +      YYPOPSTACK;                                               \
 231.270 +      goto yybackup;                                            \
 231.271 +    }                                                           \
 231.272 +  else                                                          \
 231.273 +    { yyerror ("syntax error: cannot back up"); YYERROR; }      \
 231.274 +while (0)
 231.275 +
 231.276 +#define YYTERROR        1
 231.277 +#define YYERRCODE       256
 231.278 +
 231.279 +#ifndef YYPURE
 231.280 +#define YYLEX           yylex()
 231.281 +#endif
 231.282 +
 231.283 +#ifdef YYPURE
 231.284 +#ifdef YYLSP_NEEDED
 231.285 +#ifdef YYLEX_PARAM
 231.286 +#define YYLEX           yylex(&yylval, &yylloc, YYLEX_PARAM)
 231.287 +#else
 231.288 +#define YYLEX           yylex(&yylval, &yylloc)
 231.289 +#endif
 231.290 +#else /* not YYLSP_NEEDED */
 231.291 +#ifdef YYLEX_PARAM
 231.292 +#define YYLEX           yylex(&yylval, YYLEX_PARAM)
 231.293 +#else
 231.294 +#define YYLEX           yylex(&yylval)
 231.295 +#endif
 231.296 +#endif /* not YYLSP_NEEDED */
 231.297 +#endif
 231.298 +
 231.299 +/* If nonreentrant, generate the variables here */
 231.300 +
 231.301 +#ifndef YYPURE
 231.302 +
 231.303 +int     yychar;                 /*  the lookahead symbol                */
 231.304 +YYSTYPE yylval;                 /*  the semantic value of the           */
 231.305 +                                /*  lookahead symbol                    */
 231.306 +
 231.307 +#ifdef YYLSP_NEEDED
 231.308 +YYLTYPE yylloc;                 /*  location data for the lookahead     */
 231.309 +                                /*  symbol                              */
 231.310 +#endif
 231.311 +
 231.312 +int yynerrs;                    /*  number of parse errors so far       */
 231.313 +#endif  /* not YYPURE */
 231.314 +
 231.315 +#if YYDEBUG != 0
 231.316 +int yydebug;                    /*  nonzero means print parse trace     */
 231.317 +/* Since this is uninitialized, it does not stop multiple parsers
 231.318 +   from coexisting.  */
 231.319 +#endif
 231.320 +
 231.321 +/*  YYINITDEPTH indicates the initial size of the parser's stacks       */
 231.322 +
 231.323 +#ifndef YYINITDEPTH
 231.324 +#define YYINITDEPTH 200
 231.325 +#endif
 231.326 +
 231.327 +/*  YYMAXDEPTH is the maximum size the stacks can grow to
 231.328 +    (effective only if the built-in stack extension method is used).  */
 231.329 +
 231.330 +#if YYMAXDEPTH == 0
 231.331 +#undef YYMAXDEPTH
 231.332 +#endif
 231.333 +
 231.334 +#ifndef YYMAXDEPTH
 231.335 +#define YYMAXDEPTH 10000
 231.336 +#endif
 231.337 +
 231.338 +/* Define __yy_memcpy.  Note that the size argument
 231.339 +   should be passed with type unsigned int, because that is what the non-GCC
 231.340 +   definitions require.  With GCC, __builtin_memcpy takes an arg
 231.341 +   of type size_t, but it can handle unsigned int.  */
 231.342 +
 231.343 +#if __GNUC__ > 1                /* GNU C and GNU C++ define this.  */
 231.344 +#define __yy_memcpy(TO,FROM,COUNT)      __builtin_memcpy(TO,FROM,COUNT)
 231.345 +#else                           /* not GNU C or C++ */
 231.346 +#ifndef __cplusplus
 231.347 +
 231.348 +/* This is the most reliable way to avoid incompatibilities
 231.349 +   in available built-in functions on various systems.  */
 231.350 +static void
 231.351 +__yy_memcpy (to, from, count)
 231.352 +     char *to;
 231.353 +     char *from;
 231.354 +     unsigned int count;
 231.355 +{
 231.356 +  register char *f = from;
 231.357 +  register char *t = to;
 231.358 +  register int i = count;
 231.359 +
 231.360 +  while (i-- > 0)
 231.361 +    *t++ = *f++;
 231.362 +}
 231.363 +
 231.364 +#else /* __cplusplus */
 231.365 +
 231.366 +/* This is the most reliable way to avoid incompatibilities
 231.367 +   in available built-in functions on various systems.  */
 231.368 +static void
 231.369 +__yy_memcpy (char *to, char *from, unsigned int count)
 231.370 +{
 231.371 +  register char *t = to;
 231.372 +  register char *f = from;
 231.373 +  register int i = count;
 231.374 +
 231.375 +  while (i-- > 0)
 231.376 +    *t++ = *f++;
 231.377 +}
 231.378 +
 231.379 +#endif
 231.380 +#endif
 231.381 +
 231.382 +#line 217 "/usr/lib/bison.simple"
 231.383 +
 231.384 +/* The user can define YYPARSE_PARAM as the name of an argument to be passed
 231.385 +   into yyparse.  The argument should have type void *.
 231.386 +   It should actually point to an object.
 231.387 +   Grammar actions can access the variable by casting it
 231.388 +   to the proper pointer type.  */
 231.389 +
 231.390 +#ifdef YYPARSE_PARAM
 231.391 +#ifdef __cplusplus
 231.392 +#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
 231.393 +#define YYPARSE_PARAM_DECL
 231.394 +#else /* not __cplusplus */
 231.395 +#define YYPARSE_PARAM_ARG YYPARSE_PARAM
 231.396 +#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
 231.397 +#endif /* not __cplusplus */
 231.398 +#else /* not YYPARSE_PARAM */
 231.399 +#define YYPARSE_PARAM_ARG
 231.400 +#define YYPARSE_PARAM_DECL
 231.401 +#endif /* not YYPARSE_PARAM */
 231.402 +
 231.403 +/* Prevent warning if -Wstrict-prototypes.  */
 231.404 +#ifdef __GNUC__
 231.405 +#ifdef YYPARSE_PARAM
 231.406 +int yyparse (void *);
 231.407 +#else
 231.408 +int yyparse (void);
 231.409 +#endif
 231.410 +#endif
 231.411 +
 231.412 +int
 231.413 +yyparse(YYPARSE_PARAM_ARG)
 231.414 +     YYPARSE_PARAM_DECL
 231.415 +{
 231.416 +  register int yystate;
 231.417 +  register int yyn;
 231.418 +  register short *yyssp;
 231.419 +  register YYSTYPE *yyvsp;
 231.420 +  int yyerrstatus;      /*  number of tokens to shift before error messages enabled */
 231.421 +  int yychar1 = 0;              /*  lookahead token as an internal (translated) token number */
 231.422 +
 231.423 +  short yyssa[YYINITDEPTH];     /*  the state stack                     */
 231.424 +  YYSTYPE yyvsa[YYINITDEPTH];   /*  the semantic value stack            */
 231.425 +
 231.426 +  short *yyss = yyssa;          /*  refer to the stacks thru separate pointers */
 231.427 +  YYSTYPE *yyvs = yyvsa;        /*  to allow yyoverflow to reallocate them elsewhere */
 231.428 +
 231.429 +#ifdef YYLSP_NEEDED
 231.430 +  YYLTYPE yylsa[YYINITDEPTH];   /*  the location stack                  */
 231.431 +  YYLTYPE *yyls = yylsa;
 231.432 +  YYLTYPE *yylsp;
 231.433 +
 231.434 +#define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
 231.435 +#else
 231.436 +#define YYPOPSTACK   (yyvsp--, yyssp--)
 231.437 +#endif
 231.438 +
 231.439 +  int yystacksize = YYINITDEPTH;
 231.440 +  int yyfree_stacks = 0;
 231.441 +
 231.442 +#ifdef YYPURE
 231.443 +  int yychar;
 231.444 +  YYSTYPE yylval;
 231.445 +  int yynerrs;
 231.446 +#ifdef YYLSP_NEEDED
 231.447 +  YYLTYPE yylloc;
 231.448 +#endif
 231.449 +#endif
 231.450 +
 231.451 +  YYSTYPE yyval;                /*  the variable used to return         */
 231.452 +                                /*  semantic values from the action     */
 231.453 +                                /*  routines                            */
 231.454 +
 231.455 +  int yylen;
 231.456 +
 231.457 +#if YYDEBUG != 0
 231.458 +  if (yydebug)
 231.459 +    fprintf(stderr, "Starting parse\n");
 231.460 +#endif
 231.461 +
 231.462 +  yystate = 0;
 231.463 +  yyerrstatus = 0;
 231.464 +  yynerrs = 0;
 231.465 +  yychar = YYEMPTY;             /* Cause a token to be read.  */
 231.466 +
 231.467 +  /* Initialize stack pointers.
 231.468 +     Waste one element of value and location stack
 231.469 +     so that they stay on the same level as the state stack.
 231.470 +     The wasted elements are never initialized.  */
 231.471 +
 231.472 +  yyssp = yyss - 1;
 231.473 +  yyvsp = yyvs;
 231.474 +#ifdef YYLSP_NEEDED
 231.475 +  yylsp = yyls;
 231.476 +#endif
 231.477 +
 231.478 +/* Push a new state, which is found in  yystate  .  */
 231.479 +/* In all cases, when you get here, the value and location stacks
 231.480 +   have just been pushed. so pushing a state here evens the stacks.  */
 231.481 +yynewstate:
 231.482 +
 231.483 +  *++yyssp = yystate;
 231.484 +
 231.485 +  if (yyssp >= yyss + yystacksize - 1)
 231.486 +    {
 231.487 +      /* Give user a chance to reallocate the stack */
 231.488 +      /* Use copies of these so that the &'s don't force the real ones into memory. */
 231.489 +      YYSTYPE *yyvs1 = yyvs;
 231.490 +      short *yyss1 = yyss;
 231.491 +#ifdef YYLSP_NEEDED
 231.492 +      YYLTYPE *yyls1 = yyls;
 231.493 +#endif
 231.494 +
 231.495 +      /* Get the current used size of the three stacks, in elements.  */
 231.496 +      int size = yyssp - yyss + 1;
 231.497 +
 231.498 +#ifdef yyoverflow
 231.499 +      /* Each stack pointer address is followed by the size of
 231.500 +         the data in use in that stack, in bytes.  */
 231.501 +#ifdef YYLSP_NEEDED
 231.502 +      /* This used to be a conditional around just the two extra args,
 231.503 +         but that might be undefined if yyoverflow is a macro.  */
 231.504 +      yyoverflow("parser stack overflow",
 231.505 +                 &yyss1, size * sizeof (*yyssp),
 231.506 +                 &yyvs1, size * sizeof (*yyvsp),
 231.507 +                 &yyls1, size * sizeof (*yylsp),
 231.508 +                 &yystacksize);
 231.509 +#else
 231.510 +      yyoverflow("parser stack overflow",
 231.511 +                 &yyss1, size * sizeof (*yyssp),
 231.512 +                 &yyvs1, size * sizeof (*yyvsp),
 231.513 +                 &yystacksize);
 231.514 +#endif
 231.515 +
 231.516 +      yyss = yyss1; yyvs = yyvs1;
 231.517 +#ifdef YYLSP_NEEDED
 231.518 +      yyls = yyls1;
 231.519 +#endif
 231.520 +#else /* no yyoverflow */
 231.521 +      /* Extend the stack our own way.  */
 231.522 +      if (yystacksize >= YYMAXDEPTH)
 231.523 +        {
 231.524 +          yyerror("parser stack overflow");
 231.525 +          if (yyfree_stacks)
 231.526 +            {
 231.527 +              free (yyss);
 231.528 +              free (yyvs);
 231.529 +#ifdef YYLSP_NEEDED
 231.530 +              free (yyls);
 231.531 +#endif
 231.532 +            }
 231.533 +          return 2;
 231.534 +        }
 231.535 +      yystacksize *= 2;
 231.536 +      if (yystacksize > YYMAXDEPTH)
 231.537 +        yystacksize = YYMAXDEPTH;
 231.538 +#ifndef YYSTACK_USE_ALLOCA
 231.539 +      yyfree_stacks = 1;
 231.540 +#endif
 231.541 +      yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
 231.542 +      __yy_memcpy ((char *)yyss, (char *)yyss1,
 231.543 +                   size * (unsigned int) sizeof (*yyssp));
 231.544 +      yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
 231.545 +      __yy_memcpy ((char *)yyvs, (char *)yyvs1,
 231.546 +                   size * (unsigned int) sizeof (*yyvsp));
 231.547 +#ifdef YYLSP_NEEDED
 231.548 +      yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
 231.549 +      __yy_memcpy ((char *)yyls, (char *)yyls1,
 231.550 +                   size * (unsigned int) sizeof (*yylsp));
 231.551 +#endif
 231.552 +#endif /* no yyoverflow */
 231.553 +
 231.554 +      yyssp = yyss + size - 1;
 231.555 +      yyvsp = yyvs + size - 1;
 231.556 +#ifdef YYLSP_NEEDED
 231.557 +      yylsp = yyls + size - 1;
 231.558 +#endif
 231.559 +
 231.560 +#if YYDEBUG != 0
 231.561 +      if (yydebug)
 231.562 +        fprintf(stderr, "Stack size increased to %d\n", yystacksize);
 231.563 +#endif
 231.564 +
 231.565 +      if (yyssp >= yyss + yystacksize - 1)
 231.566 +        YYABORT;
 231.567 +    }
 231.568 +
 231.569 +#if YYDEBUG != 0
 231.570 +  if (yydebug)
 231.571 +    fprintf(stderr, "Entering state %d\n", yystate);
 231.572 +#endif
 231.573 +
 231.574 +  goto yybackup;
 231.575 + yybackup:
 231.576 +
 231.577 +/* Do appropriate processing given the current state.  */
 231.578 +/* Read a lookahead token if we need one and don't already have one.  */
 231.579 +/* yyresume: */
 231.580 +
 231.581 +  /* First try to decide what to do without reference to lookahead token.  */
 231.582 +
 231.583 +  yyn = yypact[yystate];
 231.584 +  if (yyn == YYFLAG)
 231.585 +    goto yydefault;
 231.586 +
 231.587 +  /* Not known => get a lookahead token if don't already have one.  */
 231.588 +
 231.589 +  /* yychar is either YYEMPTY or YYEOF
 231.590 +     or a valid token in external form.  */
 231.591 +
 231.592 +  if (yychar == YYEMPTY)
 231.593 +    {
 231.594 +#if YYDEBUG != 0
 231.595 +      if (yydebug)
 231.596 +        fprintf(stderr, "Reading a token: ");
 231.597 +#endif
 231.598 +      yychar = YYLEX;
 231.599 +    }
 231.600 +
 231.601 +  /* Convert token to internal form (in yychar1) for indexing tables with */
 231.602 +
 231.603 +  if (yychar <= 0)              /* This means end of input. */
 231.604 +    {
 231.605 +      yychar1 = 0;
 231.606 +      yychar = YYEOF;           /* Don't call YYLEX any more */
 231.607 +
 231.608 +#if YYDEBUG != 0
 231.609 +      if (yydebug)
 231.610 +        fprintf(stderr, "Now at end of input.\n");
 231.611 +#endif
 231.612 +    }
 231.613 +  else
 231.614 +    {
 231.615 +      yychar1 = YYTRANSLATE(yychar);
 231.616 +
 231.617 +#if YYDEBUG != 0
 231.618 +      if (yydebug)
 231.619 +        {
 231.620 +          fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
 231.621 +          /* Give the individual parser a way to print the precise meaning
 231.622 +             of a token, for further debugging info.  */
 231.623 +#ifdef YYPRINT
 231.624 +          YYPRINT (stderr, yychar, yylval);
 231.625 +#endif
 231.626 +          fprintf (stderr, ")\n");
 231.627 +        }
 231.628 +#endif
 231.629 +    }
 231.630 +
 231.631 +  yyn += yychar1;
 231.632 +  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
 231.633 +    goto yydefault;
 231.634 +
 231.635 +  yyn = yytable[yyn];
 231.636 +
 231.637 +  /* yyn is what to do for this token type in this state.
 231.638 +     Negative => reduce, -yyn is rule number.
 231.639 +     Positive => shift, yyn is new state.
 231.640 +       New state is final state => don't bother to shift,
 231.641 +       just return success.
 231.642 +     0, or most negative number => error.  */
 231.643 +
 231.644 +  if (yyn < 0)
 231.645 +    {
 231.646 +      if (yyn == YYFLAG)
 231.647 +        goto yyerrlab;
 231.648 +      yyn = -yyn;
 231.649 +      goto yyreduce;
 231.650 +    }
 231.651 +  else if (yyn == 0)
 231.652 +    goto yyerrlab;
 231.653 +
 231.654 +  if (yyn == YYFINAL)
 231.655 +    YYACCEPT;
 231.656 +
 231.657 +  /* Shift the lookahead token.  */
 231.658 +
 231.659 +#if YYDEBUG != 0
 231.660 +  if (yydebug)
 231.661 +    fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
 231.662 +#endif
 231.663 +
 231.664 +  /* Discard the token being shifted unless it is eof.  */
 231.665 +  if (yychar != YYEOF)
 231.666 +    yychar = YYEMPTY;
 231.667 +
 231.668 +  *++yyvsp = yylval;
 231.669 +#ifdef YYLSP_NEEDED
 231.670 +  *++yylsp = yylloc;
 231.671 +#endif
 231.672 +
 231.673 +  /* count tokens shifted since error; after three, turn off error status.  */
 231.674 +  if (yyerrstatus) yyerrstatus--;
 231.675 +
 231.676 +  yystate = yyn;
 231.677 +  goto yynewstate;
 231.678 +
 231.679 +/* Do the default action for the current state.  */
 231.680 +yydefault:
 231.681 +
 231.682 +  yyn = yydefact[yystate];
 231.683 +  if (yyn == 0)
 231.684 +    goto yyerrlab;
 231.685 +
 231.686 +/* Do a reduction.  yyn is the number of a rule to reduce with.  */
 231.687 +yyreduce:
 231.688 +  yylen = yyr2[yyn];
 231.689 +  if (yylen > 0)
 231.690 +    yyval = yyvsp[1-yylen]; /* implement default value of the action */
 231.691 +
 231.692 +#if YYDEBUG != 0
 231.693 +  if (yydebug)
 231.694 +    {
 231.695 +      int i;
 231.696 +
 231.697 +      fprintf (stderr, "Reducing via rule %d (line %d), ",
 231.698 +               yyn, yyrline[yyn]);
 231.699 +
 231.700 +      /* Print the symbols being reduced, and their result.  */
 231.701 +      for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
 231.702 +        fprintf (stderr, "%s ", yytname[yyrhs[i]]);
 231.703 +      fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
 231.704 +    }
 231.705 +#endif
 231.706 +
 231.707 +
 231.708 +  switch (yyn) {
 231.709 +
 231.710 +case 1:
 231.711 +#line 32 "expr.y"
 231.712 +{ result = yyvsp[0]; ;
 231.713 +    break;}
 231.714 +case 2:
 231.715 +#line 36 "expr.y"
 231.716 +{ yyval = yyvsp[0]; ;
 231.717 +    break;}
 231.718 +case 3:
 231.719 +#line 37 "expr.y"
 231.720 +{ yyval = yyvsp[-1]; ;
 231.721 +    break;}
 231.722 +case 4:
 231.723 +#line 38 "expr.y"
 231.724 +{ yyval = exprNodeDot(yyvsp[-2], yyvsp[0]); ;
 231.725 +    break;}
 231.726 +case 5:
 231.727 +#line 39 "expr.y"
 231.728 +{ yyval = exprNodeArrow(yyvsp[-2], yyvsp[0]); ;
 231.729 +    break;}
 231.730 +case 6:
 231.731 +#line 40 "expr.y"
 231.732 +{ yyval = exprNodeArray(yyvsp[-3], yyvsp[-1]); ;
 231.733 +    break;}
 231.734 +case 7:
 231.735 +#line 43 "expr.y"
 231.736 +{ yyval = yyvsp[0]; ;
 231.737 +    break;}
 231.738 +case 8:
 231.739 +#line 44 "expr.y"
 231.740 +{ yyval = exprNodeStar(yyvsp[0]); ;
 231.741 +    break;}
 231.742 +case 9:
 231.743 +#line 45 "expr.y"
 231.744 +{ yyval = exprNodeAddr(yyvsp[0]); ;
 231.745 +    break;}
 231.746 +case 10:
 231.747 +#line 46 "expr.y"
 231.748 +{ yyval = exprNodeSizeof(yyvsp[-1]); ;
 231.749 +    break;}
 231.750 +case 11:
 231.751 +#line 50 "expr.y"
 231.752 +{ yyval = exprNodeNumber(); ;
 231.753 +    break;}
 231.754 +case 12:
 231.755 +#line 54 "expr.y"
 231.756 +{yyval = exprNodeIdentifier(); ;
 231.757 +    break;}
 231.758 +}
 231.759 +   /* the action file gets copied in in place of this dollarsign */
 231.760 +#line 543 "/usr/lib/bison.simple"
 231.761 +
 231.762 +  yyvsp -= yylen;
 231.763 +  yyssp -= yylen;
 231.764 +#ifdef YYLSP_NEEDED
 231.765 +  yylsp -= yylen;
 231.766 +#endif
 231.767 +
 231.768 +#if YYDEBUG != 0
 231.769 +  if (yydebug)
 231.770 +    {
 231.771 +      short *ssp1 = yyss - 1;
 231.772 +      fprintf (stderr, "state stack now");
 231.773 +      while (ssp1 != yyssp)
 231.774 +        fprintf (stderr, " %d", *++ssp1);
 231.775 +      fprintf (stderr, "\n");
 231.776 +    }
 231.777 +#endif
 231.778 +
 231.779 +  *++yyvsp = yyval;
 231.780 +
 231.781 +#ifdef YYLSP_NEEDED
 231.782 +  yylsp++;
 231.783 +  if (yylen == 0)
 231.784 +    {
 231.785 +      yylsp->first_line = yylloc.first_line;
 231.786 +      yylsp->first_column = yylloc.first_column;
 231.787 +      yylsp->last_line = (yylsp-1)->last_line;
 231.788 +      yylsp->last_column = (yylsp-1)->last_column;
 231.789 +      yylsp->text = 0;
 231.790 +    }
 231.791 +  else
 231.792 +    {
 231.793 +      yylsp->last_line = (yylsp+yylen-1)->last_line;
 231.794 +      yylsp->last_column = (yylsp+yylen-1)->last_column;
 231.795 +    }
 231.796 +#endif
 231.797 +
 231.798 +  /* Now "shift" the result of the reduction.
 231.799 +     Determine what state that goes to,
 231.800 +     based on the state we popped back to
 231.801 +     and the rule number reduced by.  */
 231.802 +
 231.803 +  yyn = yyr1[yyn];
 231.804 +
 231.805 +  yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
 231.806 +  if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
 231.807 +    yystate = yytable[yystate];
 231.808 +  else
 231.809 +    yystate = yydefgoto[yyn - YYNTBASE];
 231.810 +
 231.811 +  goto yynewstate;
 231.812 +
 231.813 +yyerrlab:   /* here on detecting error */
 231.814 +
 231.815 +  if (! yyerrstatus)
 231.816 +    /* If not already recovering from an error, report this error.  */
 231.817 +    {
 231.818 +      ++yynerrs;
 231.819 +
 231.820 +#ifdef YYERROR_VERBOSE
 231.821 +      yyn = yypact[yystate];
 231.822 +
 231.823 +      if (yyn > YYFLAG && yyn < YYLAST)
 231.824 +        {
 231.825 +          int size = 0;
 231.826 +          char *msg;
 231.827 +          int x, count;
 231.828 +
 231.829 +          count = 0;
 231.830 +          /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
 231.831 +          for (x = (yyn < 0 ? -yyn : 0);
 231.832 +               x < (sizeof(yytname) / sizeof(char *)); x++)
 231.833 +            if (yycheck[x + yyn] == x)
 231.834 +              size += strlen(yytname[x]) + 15, count++;
 231.835 +          msg = (char *) malloc(size + 15);
 231.836 +          if (msg != 0)
 231.837 +            {
 231.838 +              strcpy(msg, "parse error");
 231.839 +
 231.840 +              if (count < 5)
 231.841 +                {
 231.842 +                  count = 0;
 231.843 +                  for (x = (yyn < 0 ? -yyn : 0);
 231.844 +                       x < (sizeof(yytname) / sizeof(char *)); x++)
 231.845 +                    if (yycheck[x + yyn] == x)
 231.846 +                      {
 231.847 +                        strcat(msg, count == 0 ? ", expecting `" : " or `");
 231.848 +                        strcat(msg, yytname[x]);
 231.849 +                        strcat(msg, "'");
 231.850 +                        count++;
 231.851 +                      }
 231.852 +                }
 231.853 +              yyerror(msg);
 231.854 +              free(msg);
 231.855 +            }
 231.856 +          else
 231.857 +            yyerror ("parse error; also virtual memory exceeded");
 231.858 +        }
 231.859 +      else
 231.860 +#endif /* YYERROR_VERBOSE */
 231.861 +        yyerror("parse error");
 231.862 +    }
 231.863 +
 231.864 +  goto yyerrlab1;
 231.865 +yyerrlab1:   /* here on error raised explicitly by an action */
 231.866 +
 231.867 +  if (yyerrstatus == 3)
 231.868 +    {
 231.869 +      /* if just tried and failed to reuse lookahead token after an error, discard it.  */
 231.870 +
 231.871 +      /* return failure if at end of input */
 231.872 +      if (yychar == YYEOF)
 231.873 +        YYABORT;
 231.874 +
 231.875 +#if YYDEBUG != 0
 231.876 +      if (yydebug)
 231.877 +        fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
 231.878 +#endif
 231.879 +
 231.880 +      yychar = YYEMPTY;
 231.881 +    }
 231.882 +
 231.883 +  /* Else will try to reuse lookahead token
 231.884 +     after shifting the error token.  */
 231.885 +
 231.886 +  yyerrstatus = 3;              /* Each real token shifted decrements this */
 231.887 +
 231.888 +  goto yyerrhandle;
 231.889 +
 231.890 +yyerrdefault:  /* current state does not do anything special for the error token. */
 231.891 +
 231.892 +#if 0
 231.893 +  /* This is wrong; only states that explicitly want error tokens
 231.894 +     should shift them.  */
 231.895 +  yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
 231.896 +  if (yyn) goto yydefault;
 231.897 +#endif
 231.898 +
 231.899 +yyerrpop:   /* pop the current state because it cannot handle the error token */
 231.900 +
 231.901 +  if (yyssp == yyss) YYABORT;
 231.902 +  yyvsp--;
 231.903 +  yystate = *--yyssp;
 231.904 +#ifdef YYLSP_NEEDED
 231.905 +  yylsp--;
 231.906 +#endif
 231.907 +
 231.908 +#if YYDEBUG != 0
 231.909 +  if (yydebug)
 231.910 +    {
 231.911 +      short *ssp1 = yyss - 1;
 231.912 +      fprintf (stderr, "Error: state stack now");
 231.913 +      while (ssp1 != yyssp)
 231.914 +        fprintf (stderr, " %d", *++ssp1);
 231.915 +      fprintf (stderr, "\n");
 231.916 +    }
 231.917 +#endif
 231.918 +
 231.919 +yyerrhandle:
 231.920 +
 231.921 +  yyn = yypact[yystate];
 231.922 +  if (yyn == YYFLAG)
 231.923 +    goto yyerrdefault;
 231.924 +
 231.925 +  yyn += YYTERROR;
 231.926 +  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
 231.927 +    goto yyerrdefault;
 231.928 +
 231.929 +  yyn = yytable[yyn];
 231.930 +  if (yyn < 0)
 231.931 +    {
 231.932 +      if (yyn == YYFLAG)
 231.933 +        goto yyerrpop;
 231.934 +      yyn = -yyn;
 231.935 +      goto yyreduce;
 231.936 +    }
 231.937 +  else if (yyn == 0)
 231.938 +    goto yyerrpop;
 231.939 +
 231.940 +  if (yyn == YYFINAL)
 231.941 +    YYACCEPT;
 231.942 +
 231.943 +#if YYDEBUG != 0
 231.944 +  if (yydebug)
 231.945 +    fprintf(stderr, "Shifting error token, ");
 231.946 +#endif
 231.947 +
 231.948 +  *++yyvsp = yylval;
 231.949 +#ifdef YYLSP_NEEDED
 231.950 +  *++yylsp = yylloc;
 231.951 +#endif
 231.952 +
 231.953 +  yystate = yyn;
 231.954 +  goto yynewstate;
 231.955 +
 231.956 + yyacceptlab:
 231.957 +  /* YYACCEPT comes here.  */
 231.958 +  if (yyfree_stacks)
 231.959 +    {
 231.960 +      free (yyss);
 231.961 +      free (yyvs);
 231.962 +#ifdef YYLSP_NEEDED
 231.963 +      free (yyls);
 231.964 +#endif
 231.965 +    }
 231.966 +  return 0;
 231.967 +
 231.968 + yyabortlab:
 231.969 +  /* YYABORT comes here.  */
 231.970 +  if (yyfree_stacks)
 231.971 +    {
 231.972 +      free (yyss);
 231.973 +      free (yyvs);
 231.974 +#ifdef YYLSP_NEEDED
 231.975 +      free (yyls);
 231.976 +#endif
 231.977 +    }
 231.978 +  return 1;
 231.979 +}
 231.980 +#line 57 "expr.y"
 231.981 +
 231.982 +
 231.983 +int yyerror(char *s)
 231.984 +{
 231.985 +  return 0;
 231.986 +}
 231.987 +
 231.988 +#ifndef SDL
 231.989 +extern FILE *yyin;
 231.990 +int main(int argc, char **argv)
 231.991 +{
 231.992 +  //  yydebug = 1;
 231.993 +  ++argv, --argc;
 231.994 +  if(argc > 0)
 231.995 +    yyin = fopen(argv[0], "r");
 231.996 +  else
 231.997 +    yyin = stdin;
 231.998 +  if(!yyparse())
 231.999 +    result->print();
231.1000 +}
231.1001 +#endif
   232.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   232.2 +++ b/src/sdl/expr.cpp.h	Sat Mar 03 10:31:27 2012 -0600
   232.3 @@ -0,0 +1,13 @@
   232.4 +#ifndef YYSTYPE
   232.5 +#define YYSTYPE int
   232.6 +#endif
   232.7 +#define TOKEN_IDENTIFIER        257
   232.8 +#define TOKEN_DOT       258
   232.9 +#define TOKEN_STAR      259
  232.10 +#define TOKEN_ARROW     260
  232.11 +#define TOKEN_ADDR      261
  232.12 +#define TOKEN_SIZEOF    262
  232.13 +#define TOKEN_NUMBER    263
  232.14 +
  232.15 +
  232.16 +extern YYSTYPE yylval;
   233.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   233.2 +++ b/src/sdl/expr.l	Sat Mar 03 10:31:27 2012 -0600
   233.3 @@ -0,0 +1,71 @@
   233.4 +%{
   233.5 +#include "expr.cpp.h"
   233.6 +
   233.7 +#ifndef __GNUC__
   233.8 +#include <io.h>
   233.9 +#define isatty _isatty
  233.10 +#endif
  233.11 +
  233.12 +char *exprString;
  233.13 +int exprCol;
  233.14 +
  233.15 +#define YY_INPUT(buf,result,max_size) \
  233.16 +    { \
  233.17 +    int c = *exprString++; \
  233.18 +    exprCol++;\
  233.19 +    result = (c == 0) ? YY_NULL : (buf[0] = c, 1); \
  233.20 +    }
  233.21 +%}
  233.22 +
  233.23 +%option nomain
  233.24 +%option noyywrap
  233.25 +
  233.26 +SIZEOF "sizeof"
  233.27 +ID [a-zA-Z_][a-zA-Z0-9_]*
  233.28 +NUM [0-9]+
  233.29 +DOT "."
  233.30 +ARROW "->"
  233.31 +STAR "*"
  233.32 +ADDR "&"
  233.33 +
  233.34 +%%
  233.35 +
  233.36 +{SIZEOF} {
  233.37 +        return TOKEN_SIZEOF;
  233.38 +}
  233.39 +
  233.40 +{ID} {
  233.41 +        return TOKEN_IDENTIFIER;
  233.42 +}
  233.43 +
  233.44 +{NUM} {
  233.45 +        return TOKEN_NUMBER;
  233.46 +}
  233.47 +
  233.48 +{DOT} {
  233.49 +        return TOKEN_DOT;
  233.50 +}       
  233.51 +
  233.52 +{ARROW} {
  233.53 +        return TOKEN_ARROW;
  233.54 +}
  233.55 +
  233.56 +{ADDR} {
  233.57 +        return TOKEN_ADDR;
  233.58 +}
  233.59 +
  233.60 +{STAR} {
  233.61 +        return TOKEN_STAR;
  233.62 +}
  233.63 +
  233.64 +[ \t\n]+
  233.65 +
  233.66 +. return *yytext;
  233.67 +
  233.68 +%%
  233.69 +
  233.70 +void exprCleanBuffer()
  233.71 +{
  233.72 +  yy_delete_buffer(yy_current_buffer);
  233.73 +  yy_init = 1;
  233.74 +}
   234.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   234.2 +++ b/src/sdl/expr.y	Sat Mar 03 10:31:27 2012 -0600
   234.3 @@ -0,0 +1,77 @@
   234.4 +%{
   234.5 +namespace std {  
   234.6 +#include <stdio.h>
   234.7 +#include <memory.h>
   234.8 +#include <stdlib.h>
   234.9 +#include <string.h>
  234.10 +}
  234.11 +
  234.12 +using namespace std;
  234.13 + 
  234.14 +#include "System.h"
  234.15 +#include "elf.h"
  234.16 +#include "exprNode.h" 
  234.17 +
  234.18 +extern int yyerror(char *);
  234.19 +extern int yylex(); 
  234.20 +extern char *yytext;
  234.21 +
  234.22 +  
  234.23 +//#define YYERROR_VERBOSE 1
  234.24 +//#define YYDEBUG 1
  234.25 +
  234.26 + Node *result = NULL;
  234.27 +%}
  234.28 +
  234.29 +%token TOKEN_IDENTIFIER TOKEN_DOT TOKEN_STAR TOKEN_ARROW TOKEN_ADDR
  234.30 +%token TOKEN_SIZEOF TOKEN_NUMBER
  234.31 +%left TOKEN_DOT TOKEN_ARROW '['
  234.32 +%expect 6
  234.33 +%%
  234.34 +
  234.35 +final: expression { result = $1; }
  234.36 +;
  234.37 +
  234.38 +expression:
  234.39 +  simple_expression { $$ = $1; } |
  234.40 +  '(' expression ')' { $$ = $2; } |
  234.41 +  expression TOKEN_DOT ident { $$ = exprNodeDot($1, $3); } |
  234.42 +  expression TOKEN_ARROW ident { $$ = exprNodeArrow($1, $3); } |
  234.43 +  expression '[' number ']' { $$ = exprNodeArray($1, $3); }
  234.44 +;
  234.45 +simple_expression:
  234.46 +  ident  { $$ = $1; } |
  234.47 +  TOKEN_STAR expression { $$ = exprNodeStar($2); } |
  234.48 +  TOKEN_ADDR expression { $$ = exprNodeAddr($2); } |
  234.49 +  TOKEN_SIZEOF '(' expression ')' { $$ = exprNodeSizeof($3); }
  234.50 +;
  234.51 +
  234.52 +number:
  234.53 +  TOKEN_NUMBER { $$ = exprNodeNumber(); }
  234.54 +;
  234.55 +
  234.56 +ident:
  234.57 +  TOKEN_IDENTIFIER {$$ = exprNodeIdentifier(); }
  234.58 +;
  234.59 +
  234.60 +%%
  234.61 +
  234.62 +int yyerror(char *s)
  234.63 +{
  234.64 +  return 0;
  234.65 +}
  234.66 +
  234.67 +#ifndef SDL
  234.68 +extern FILE *yyin;
  234.69 +int main(int argc, char **argv)
  234.70 +{
  234.71 +  //  yydebug = 1;
  234.72 +  ++argv, --argc;
  234.73 +  if(argc > 0)
  234.74 +    yyin = fopen(argv[0], "r");
  234.75 +  else
  234.76 +    yyin = stdin;
  234.77 +  if(!yyparse())
  234.78 +    result->print();
  234.79 +}
  234.80 +#endif
   235.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   235.2 +++ b/src/sdl/exprNode.cpp	Sat Mar 03 10:31:27 2012 -0600
   235.3 @@ -0,0 +1,411 @@
   235.4 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   235.5 +// Copyright (C) 1999-2003 Forgotten
   235.6 +// Copyright (C) 2004 Forgotten and the VBA development team
   235.7 +
   235.8 +// This program is free software; you can redistribute it and/or modify
   235.9 +// it under the terms of the GNU General Public License as published by
  235.10 +// the Free Software Foundation; either version 2, or(at your option)
  235.11 +// any later version.
  235.12 +//
  235.13 +// This program is distributed in the hope that it will be useful,
  235.14 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  235.15 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  235.16 +// GNU General Public License for more details.
  235.17 +//
  235.18 +// You should have received a copy of the GNU General Public License
  235.19 +// along with this program; if not, write to the Free Software Foundation,
  235.20 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  235.21 +
  235.22 +#include <string.h>
  235.23 +#include <stdio.h>
  235.24 +#include <stdlib.h>
  235.25 +
  235.26 +#include "Port.h"
  235.27 +#include "gba/GBAGlobals.h"
  235.28 +#include "gba/elf.h"
  235.29 +#include "exprNode.h"
  235.30 +
  235.31 +extern char *yytext;
  235.32 +
  235.33 +#define debuggerReadMemory(addr) \
  235.34 +  READ32LE((&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
  235.35 +
  235.36 +void *exprNodeCleanUpList[100];
  235.37 +int exprNodeCleanUpCount = 0;
  235.38 +Type exprNodeType = { 0, TYPE_base, "int", DW_ATE_signed, 4, 0, {0}, 0 };
  235.39 +
  235.40 +void exprNodeClean(void *m)
  235.41 +{
  235.42 +  exprNodeCleanUpList[exprNodeCleanUpCount++] = m;
  235.43 +}
  235.44 +
  235.45 +void exprNodeCleanUp()
  235.46 +{
  235.47 +  for(int i = 0; i < exprNodeCleanUpCount; i++) {
  235.48 +    free(exprNodeCleanUpList[i]);
  235.49 +  }
  235.50 +  exprNodeCleanUpCount = 0;
  235.51 +}
  235.52 +
  235.53 +Node *exprNodeIdentifier()
  235.54 +{
  235.55 +  Node *n = (Node *)calloc(1, sizeof(Node));
  235.56 +  n->name = strdup(yytext);
  235.57 +
  235.58 +  exprNodeClean(n->name);  
  235.59 +  exprNodeClean(n);
  235.60 +  
  235.61 +  n->print = exprNodeIdentifierPrint;
  235.62 +  n->resolve = exprNodeIdentifierResolve;
  235.63 +  return n;
  235.64 +}
  235.65 +
  235.66 +bool exprNodeIdentifierResolve(Node *n, Function *f, CompileUnit *u)
  235.67 +{
  235.68 +  Object *o;
  235.69 +  if(elfGetObject(n->name, f, u, &o)) {
  235.70 +    n->type = o->type;
  235.71 +    n->location = elfDecodeLocation(f, o->location, &n->locType);
  235.72 +    return true;
  235.73 +  } else {
  235.74 +    printf("Object %s not found\n", n->name);
  235.75 +  }
  235.76 +  return false;
  235.77 +}
  235.78 +
  235.79 +void exprNodeIdentifierPrint(Node *n)
  235.80 +{
  235.81 +  printf("%s", n->name);
  235.82 +}
  235.83 +
  235.84 +Node *exprNodeNumber()
  235.85 +{
  235.86 +  Node *n = (Node *)calloc(1, sizeof(Node));
  235.87 +
  235.88 +  exprNodeClean(n);
  235.89 +  n->location = atoi(yytext);
  235.90 +  n->type = &exprNodeType;
  235.91 +  n->locType = LOCATION_value;  
  235.92 +  n->print = exprNodeNumberPrint;
  235.93 +  n->resolve = exprNodeNumberResolve;
  235.94 +  return n;
  235.95 +}
  235.96 +
  235.97 +bool exprNodeNumberResolve(Node *n, Function *f, CompileUnit *u)
  235.98 +{
  235.99 +  return true;
 235.100 +}
 235.101 +
 235.102 +void exprNodeNumberPrint(Node *n)
 235.103 +{
 235.104 +  printf("%d", n->location);
 235.105 +}
 235.106 +
 235.107 +Node *exprNodeStar(Node *exp)
 235.108 +{
 235.109 +  Node *n = (Node *)calloc(1, sizeof(Node));
 235.110 +  exprNodeClean(n);
 235.111 +  
 235.112 +  n->expression = exp;
 235.113 +  
 235.114 +  n->print = exprNodeStarPrint;
 235.115 +  n->resolve = exprNodeStarResolve;
 235.116 +  return n;
 235.117 +}
 235.118 +
 235.119 +bool exprNodeStarResolve(Node *n, Function *f, CompileUnit *u)
 235.120 +{
 235.121 +  if(n->expression->resolve(n->expression, f, u)) {
 235.122 +    if(n->expression->type->type == TYPE_pointer) {
 235.123 +      n->location = n->expression->location;
 235.124 +      if(n->expression->locType == LOCATION_memory) {
 235.125 +        n->location = debuggerReadMemory(n->location);
 235.126 +      } else if(n->expression->locType == LOCATION_register) {
 235.127 +        n->location = reg[n->expression->location].I;
 235.128 +      } else {
 235.129 +        n->location = n->expression->location;
 235.130 +      }
 235.131 +      n->type = n->expression->type->pointer;
 235.132 +      n->locType = LOCATION_memory;
 235.133 +      return true;
 235.134 +    } else {
 235.135 +      printf("Object is not of pointer type\n");
 235.136 +    }
 235.137 +  }
 235.138 +  return false;
 235.139 +}
 235.140 +
 235.141 +void exprNodeStarPrint(Node *n)
 235.142 +{
 235.143 +  printf("*");
 235.144 +  n->expression->print(n->expression);
 235.145 +}
 235.146 +
 235.147 +Node *exprNodeDot(Node *exp, Node *ident)
 235.148 +{
 235.149 +  Node *n = (Node *)calloc(1, sizeof(Node));
 235.150 +  exprNodeClean(n);
 235.151 +  
 235.152 +  n->expression = exp;
 235.153 +  n->name = ident->name;
 235.154 +  
 235.155 +  n->print = exprNodeDotPrint;
 235.156 +  n->resolve = exprNodeDotResolve;
 235.157 +  return n;
 235.158 +}
 235.159 +
 235.160 +bool exprNodeDotResolve(Node *n, Function *f, CompileUnit *u)
 235.161 +{
 235.162 +  if(n->expression->resolve(n->expression, f, u)) {
 235.163 +    TypeEnum tt = n->expression->type->type;
 235.164 +    
 235.165 +    if(tt == TYPE_struct ||
 235.166 +       tt == TYPE_union) {
 235.167 +      u32 loc = n->expression->location;
 235.168 +      Type *t = n->expression->type;
 235.169 +      int count = t->structure->memberCount;
 235.170 +      int i = 0;
 235.171 +      while(i < count) {
 235.172 +        Member *m = &t->structure->members[i];
 235.173 +        if(strcmp(m->name, n->name) == 0) {
 235.174 +          // found member
 235.175 +          n->type = m->type;
 235.176 +          if(tt == TYPE_struct) {
 235.177 +            n->location = elfDecodeLocation(f, m->location, &n->locType,
 235.178 +                                            loc);
 235.179 +            n->objLocation = loc;
 235.180 +          } else {
 235.181 +            n->location = loc;
 235.182 +            n->locType = n->expression->locType;
 235.183 +            n->objLocation = loc;
 235.184 +          }
 235.185 +          n->member = m;
 235.186 +          return true;
 235.187 +        }
 235.188 +        i++;
 235.189 +      }
 235.190 +      printf("Member %s not found\n", n->name);
 235.191 +    } else {
 235.192 +      printf("Object is not of structure type\n");
 235.193 +    }
 235.194 +  }
 235.195 +  return false;
 235.196 +}
 235.197 +
 235.198 +void exprNodeDotPrint(Node *n)
 235.199 +{
 235.200 +  n->expression->print(n->expression);
 235.201 +  printf(".%s", n->name);
 235.202 +}
 235.203 +
 235.204 +Node *exprNodeArrow(Node *exp, Node *ident)
 235.205 +{
 235.206 +  Node *n = (Node *)calloc(1, sizeof(Node));
 235.207 +  exprNodeClean(n);
 235.208 +  
 235.209 +  n->expression = exp;
 235.210 +  n->name = ident->name;
 235.211 +  
 235.212 +  n->print = exprNodeArrowPrint;
 235.213 +  n->resolve = exprNodeArrowResolve;
 235.214 +  return n;
 235.215 +}
 235.216 +
 235.217 +bool exprNodeArrowResolve(Node *n, Function *f, CompileUnit *u)
 235.218 +{
 235.219 +  if(n->expression->resolve(n->expression, f, u)) {
 235.220 +    TypeEnum tt = n->expression->type->type;
 235.221 +    if(tt != TYPE_pointer) {
 235.222 +      printf("Object not of pointer type\n");
 235.223 +      return false;
 235.224 +    }
 235.225 +    tt = n->expression->type->pointer->type;
 235.226 +    
 235.227 +    if(tt == TYPE_struct ||
 235.228 +       tt == TYPE_union) {
 235.229 +      u32 loc = debuggerReadMemory(n->expression->location);
 235.230 +      Type *t = n->expression->type->pointer;
 235.231 +      int count = t->structure->memberCount;
 235.232 +      int i = 0;
 235.233 +      while(i < count) {
 235.234 +        Member *m = &t->structure->members[i];
 235.235 +        if(strcmp(m->name, n->name) == 0) {
 235.236 +          // found member
 235.237 +          n->type = m->type;
 235.238 +          if(tt == TYPE_struct) {
 235.239 +            n->location = elfDecodeLocation(f, m->location, &n->locType,
 235.240 +                                            loc);
 235.241 +            n->objLocation = loc;
 235.242 +          } else {
 235.243 +            n->location = loc;
 235.244 +            n->objLocation = loc;
 235.245 +          }
 235.246 +          n->locType = LOCATION_memory;
 235.247 +          n->member = m;
 235.248 +          return true;
 235.249 +        }
 235.250 +        i++;
 235.251 +      }
 235.252 +      printf("Member %s not found\n", n->name);
 235.253 +    } else {
 235.254 +      printf("Object is not of structure type\n");
 235.255 +    }
 235.256 +  }
 235.257 +  return false;
 235.258 +}
 235.259 +
 235.260 +void exprNodeArrowPrint(Node *n)
 235.261 +{
 235.262 +  n->expression->print(n->expression);
 235.263 +  printf("->%s", n->name);
 235.264 +}
 235.265 +
 235.266 +Node *exprNodeAddr(Node *exp)
 235.267 +{
 235.268 +  Node *n = (Node *)calloc(1, sizeof(Node));
 235.269 +  exprNodeClean(n);
 235.270 +  
 235.271 +  n->expression = exp;
 235.272 +  
 235.273 +  n->print = exprNodeAddrPrint;
 235.274 +  n->resolve = exprNodeAddrResolve;
 235.275 +  return n;
 235.276 +}
 235.277 +
 235.278 +bool exprNodeAddrResolve(Node *n, Function *f, CompileUnit *u)
 235.279 +{
 235.280 +  if(n->expression->resolve(n->expression, f, u)) {
 235.281 +    if(n->expression->locType == LOCATION_memory) {
 235.282 +      n->location = n->expression->location;
 235.283 +      n->locType = LOCATION_value;
 235.284 +      n->type = &exprNodeType;
 235.285 +    } else if(n->expression->locType == LOCATION_register) {
 235.286 +      printf("Value is in register %d\n", n->expression->location);
 235.287 +    } else {
 235.288 +      printf("Direct value is %d\n", n->location);
 235.289 +    }
 235.290 +    return true;
 235.291 +  }
 235.292 +  return false;
 235.293 +}
 235.294 +
 235.295 +void exprNodeAddrPrint(Node *n)
 235.296 +{
 235.297 +  printf("*");
 235.298 +  n->expression->print(n->expression);
 235.299 +}
 235.300 +
 235.301 +Node *exprNodeSizeof(Node *exp)
 235.302 +{
 235.303 +  Node *n = (Node *)calloc(1, sizeof(Node));
 235.304 +  exprNodeClean(n);
 235.305 +  
 235.306 +  n->expression = exp;
 235.307 +  
 235.308 +  n->print = exprNodeSizeofPrint;
 235.309 +  n->resolve = exprNodeSizeofResolve;
 235.310 +  return n;
 235.311 +}
 235.312 +
 235.313 +bool exprNodeSizeofResolve(Node *n, Function *f, CompileUnit *u)
 235.314 +{
 235.315 +  if(n->expression->resolve(n->expression, f, u)) {
 235.316 +    n->location = n->expression->type->size;
 235.317 +    n->locType = LOCATION_value;
 235.318 +    n->type = &exprNodeType;
 235.319 +    return true;
 235.320 +  }
 235.321 +  return false;
 235.322 +}
 235.323 +
 235.324 +void exprNodeSizeofPrint(Node *n)
 235.325 +{
 235.326 +  printf("sizeof(");
 235.327 +  n->expression->print(n->expression);
 235.328 +  printf(")");
 235.329 +}
 235.330 +
 235.331 +Node *exprNodeArray(Node *exp, Node *number)
 235.332 +{
 235.333 +  Node *n = (Node *)calloc(1, sizeof(Node));
 235.334 +  exprNodeClean(n);
 235.335 +  
 235.336 +  n->expression = exp;
 235.337 +  n->value = number->location;
 235.338 +  
 235.339 +  n->print = exprNodeArrayPrint;
 235.340 +  n->resolve = exprNodeArrayResolve;
 235.341 +  return n;
 235.342 +}
 235.343 +
 235.344 +int exprNodeGetSize(Array *a, int index)
 235.345 +{
 235.346 +  index++;
 235.347 +  if(index == a->maxBounds) {
 235.348 +    return a->type->size;
 235.349 +  } else {
 235.350 +    int size = a->bounds[a->maxBounds-1] * a->type->size;
 235.351 +    
 235.352 +    for(int i = index; i < a->maxBounds-1; i++) {
 235.353 +      size *= a->bounds[i];
 235.354 +    }
 235.355 +    return size;
 235.356 +  }
 235.357 +}
 235.358 +
 235.359 +bool exprNodeArrayResolve(Node *n, Function *f, CompileUnit *u)
 235.360 +{
 235.361 +  if(n->expression->resolve(n->expression, f, u)) {
 235.362 +    TypeEnum tt = n->expression->type->type;
 235.363 +    if(tt != TYPE_array &&
 235.364 +       tt != TYPE_pointer) {
 235.365 +      printf("Object not of array or pointer type\n");
 235.366 +      return false;
 235.367 +    }
 235.368 +
 235.369 +    if(tt == TYPE_array) {
 235.370 +      Array *a = n->expression->type->array;
 235.371 +      
 235.372 +      u32 loc = n->expression->location;
 235.373 +      Type *t = a->type;
 235.374 +      if(a->maxBounds > 1) {
 235.375 +        int index = n->expression->index;
 235.376 +
 235.377 +        if(index == a->maxBounds) {
 235.378 +          printf("Too many indices for array\n");
 235.379 +          return false;
 235.380 +        }
 235.381 +
 235.382 +        if((index+1) < a->maxBounds) {
 235.383 +          n->type = n->expression->type;
 235.384 +          n->index = index+1;
 235.385 +          n->locType = LOCATION_memory;
 235.386 +          n->location = n->expression->location +
 235.387 +            n->value * exprNodeGetSize(a, index);
 235.388 +          return true;
 235.389 +        }
 235.390 +      }
 235.391 +      n->type = t;
 235.392 +      n->location = loc + n->value * t->size;
 235.393 +      n->locType = LOCATION_memory;
 235.394 +    } else {
 235.395 +      Type *t = n->expression->type->pointer;
 235.396 +      u32 loc = n->expression->location;
 235.397 +      if(n->expression->locType == LOCATION_register)
 235.398 +        loc = reg[loc].I;
 235.399 +      else
 235.400 +        loc = debuggerReadMemory(loc);
 235.401 +      n->type = t;
 235.402 +      n->location = loc + n->value * t->size;
 235.403 +      n->locType = LOCATION_memory;
 235.404 +    }
 235.405 +    return true;
 235.406 +  }
 235.407 +  return false;
 235.408 +}
 235.409 +
 235.410 +void exprNodeArrayPrint(Node *n)
 235.411 +{
 235.412 +  n->expression->print(n->expression);
 235.413 +  printf("[%d]", n->value);
 235.414 +}
   236.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   236.2 +++ b/src/sdl/exprNode.h	Sat Mar 03 10:31:27 2012 -0600
   236.3 @@ -0,0 +1,68 @@
   236.4 +// -*- C++ -*-
   236.5 +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
   236.6 +// Copyright (C) 1999-2003 Forgotten
   236.7 +// Copyright (C) 2004 Forgotten and the VBA development team
   236.8 +
   236.9 +// This program is free software; you can redistribute it and/or modify
  236.10 +// it under the terms of the GNU General Public License as published by
  236.11 +// the Free Software Foundation; either version 2, or(at your option)
  236.12 +// any later version.
  236.13 +//
  236.14 +// This program is distributed in the hope that it will be useful,
  236.15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  236.16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  236.17 +// GNU General Public License for more details.
  236.18 +//
  236.19 +// You should have received a copy of the GNU General Public License
  236.20 +// along with this program; if not, write to the Free Software Foundation,
  236.21 +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  236.22 +
  236.23 +struct Node {
  236.24 +  Type *type;
  236.25 +  u32 location;
  236.26 +  u32 objLocation;
  236.27 +  LocationType locType;
  236.28 +  int value;
  236.29 +  int index;
  236.30 +  char *name;
  236.31 +  Node *expression;
  236.32 +  Member *member;
  236.33 +  void (*print)(Node *);
  236.34 +  bool (*resolve)(Node *, Function *f, CompileUnit *u);
  236.35 +};
  236.36 +
  236.37 +extern void exprNodeCleanUp();
  236.38 +
  236.39 +extern Node *exprNodeIdentifier();
  236.40 +extern void exprNodeIdentifierPrint(Node *);
  236.41 +extern bool exprNodeIdentifierResolve(Node *, Function *, CompileUnit *);
  236.42 +
  236.43 +extern Node *exprNodeNumber();
  236.44 +extern void exprNodeNumberPrint(Node *);
  236.45 +extern bool exprNodeNumberResolve(Node *, Function *, CompileUnit *);
  236.46 +
  236.47 +extern Node *exprNodeStar(Node *);
  236.48 +extern void exprNodeStarPrint(Node *);
  236.49 +extern bool exprNodeStarResolve(Node *, Function *, CompileUnit *);
  236.50 +
  236.51 +extern Node *exprNodeDot(Node *, Node *);
  236.52 +extern void exprNodeDotPrint(Node *);
  236.53 +extern bool exprNodeDotResolve(Node *, Function *, CompileUnit *);
  236.54 +
  236.55 +extern Node *exprNodeArrow(Node *, Node *);
  236.56 +extern void exprNodeArrowPrint(Node *);
  236.57 +extern bool exprNodeArrowResolve(Node *, Function *, CompileUnit *);
  236.58 +
  236.59 +extern Node *exprNodeAddr(Node *);
  236.60 +extern void exprNodeAddrPrint(Node *);
  236.61 +extern bool exprNodeAddrResolve(Node *, Function *, CompileUnit *);
  236.62 +
  236.63 +extern Node *exprNodeSizeof(Node *);
  236.64 +extern void exprNodeSizeofPrint(Node *);
  236.65 +extern bool exprNodeSizeofResolve(Node *, Function *, CompileUnit *);
  236.66 +
  236.67 +extern Node *exprNodeArray(Node *, Node *);
  236.68 +extern void exprNodeArrayPrint(Node *);
  236.69 +extern bool exprNodeArrayResolve(Node *, Function *, CompileUnit *);
  236.70 +
  236.71 +#define YYSTYPE struct Node *
   237.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   237.2 +++ b/src/sdl/getopt.c	Sat Mar 03 10:31:27 2012 -0600
   237.3 @@ -0,0 +1,1060 @@
   237.4 +/* Getopt for GNU.
   237.5 +   NOTE: getopt is now part of the C library, so if you don't know what
   237.6 +   "Keep this file name-space clean" means, talk to drepper@gnu.org
   237.7 +   before changing it!
   237.8 +
   237.9 +   Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98
  237.10 +   	Free Software Foundation, Inc.
  237.11 +
  237.12 +   NOTE: This source is derived from an old version taken from the GNU C
  237.13 +   Library (glibc).
  237.14 +
  237.15 +   This program is free software; you can redistribute it and/or modify it
  237.16 +   under the terms of the GNU General Public License as published by the
  237.17 +   Free Software Foundation; either version 2, or (at your option) any
  237.18 +   later version.
  237.19 +
  237.20 +   This program is distributed in the hope that it will be useful,
  237.21 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
  237.22 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  237.23 +   GNU General Public License for more details.
  237.24 +
  237.25 +   You should have received a copy of the GNU General Public License
  237.26 +   along with this program; if not, write to the Free Software
  237.27 +   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  237.28 +   USA.  */
  237.29 +
  237.30 +/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
  237.31 +   Ditto for AIX 3.2 and <stdlib.h>.  */
  237.32 +#ifndef _NO_PROTO
  237.33 +# define _NO_PROTO
  237.34 +#endif
  237.35 +
  237.36 +#ifdef HAVE_CONFIG_H
  237.37 +# include <config.h>
  237.38 +#endif
  237.39 +
  237.40 +#if !defined __STDC__ || !__STDC__
  237.41 +/* This is a separate conditional since some stdc systems
  237.42 +   reject `defined (const)'.  */
  237.43 +# ifndef const
  237.44 +#  define const
  237.45 +# endif
  237.46 +#endif
  237.47 +
  237.48 +#include <stdio.h>
  237.49 +
  237.50 +/* Comment out all this code if we are using the GNU C Library, and are not
  237.51 +   actually compiling the library itself.  This code is part of the GNU C
  237.52 +   Library, but also included in many other GNU distributions.  Compiling
  237.53 +   and linking in this code is a waste when using the GNU C library
  237.54 +   (especially if it is a shared library).  Rather than having every GNU
  237.55 +   program understand `configure --with-gnu-libc' and omit the object files,
  237.56 +   it is simpler to just do this in the source for each such file.  */
  237.57 +
  237.58 +#define GETOPT_INTERFACE_VERSION 2
  237.59 +#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
  237.60 +# include <gnu-versions.h>
  237.61 +# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
  237.62 +#  define ELIDE_CODE
  237.63 +# endif
  237.64 +#endif
  237.65 +
  237.66 +#ifndef ELIDE_CODE
  237.67 +
  237.68 +
  237.69 +/* This needs to come after some library #include
  237.70 +   to get __GNU_LIBRARY__ defined.  */
  237.71 +#ifdef	__GNU_LIBRARY__
  237.72 +/* Don't include stdlib.h for non-GNU C libraries because some of them
  237.73 +   contain conflicting prototypes for getopt.  */
  237.74 +# include <stdlib.h>
  237.75 +# include <unistd.h>
  237.76 +#endif	/* GNU C library.  */
  237.77 +
  237.78 +#ifdef VMS
  237.79 +# include <unixlib.h>
  237.80 +# if HAVE_STRING_H - 0
  237.81 +#  include <string.h>
  237.82 +# endif
  237.83 +#endif
  237.84 +
  237.85 +#ifndef _
  237.86 +/* This is for other GNU distributions with internationalized messages.
  237.87 +   When compiling libc, the _ macro is predefined.  */
  237.88 +# ifdef HAVE_LIBINTL_H
  237.89 +#  include <libintl.h>
  237.90 +#  define _(msgid)	gettext (msgid)
  237.91 +# else
  237.92 +#  define _(msgid)	(msgid)
  237.93 +# endif
  237.94 +#endif
  237.95 +
  237.96 +#ifdef _MSC_VER
  237.97 +#include <string.h>
  237.98 +#endif
  237.99 +
 237.100 +/* This version of `getopt' appears to the caller like standard Unix `getopt'
 237.101 +   but it behaves differently for the user, since it allows the user
 237.102 +   to intersperse the options with the other arguments.
 237.103 +
 237.104 +   As `getopt' works, it permutes the elements of ARGV so that,
 237.105 +   when it is done, all the options precede everything else.  Thus
 237.106 +   all application programs are extended to handle flexible argument order.
 237.107 +
 237.108 +   Setting the environment variable POSIXLY_CORRECT disables permutation.
 237.109 +   Then the behavior is completely standard.
 237.110 +
 237.111 +   GNU application programs can use a third alternative mode in which
 237.112 +   they can distinguish the relative order of options and other arguments.  */
 237.113 +
 237.114 +#include "getopt.h"
 237.115 +
 237.116 +/* For communication from `getopt' to the caller.
 237.117 +   When `getopt' finds an option that takes an argument,
 237.118 +   the argument value is returned here.
 237.119 +   Also, when `ordering' is RETURN_IN_ORDER,
 237.120 +   each non-option ARGV-element is returned here.  */
 237.121 +
 237.122 +char *optarg = NULL;
 237.123 +
 237.124 +/* Index in ARGV of the next element to be scanned.
 237.125 +   This is used for communication to and from the caller
 237.126 +   and for communication between successive calls to `getopt'.
 237.127 +
 237.128 +   On entry to `getopt', zero means this is the first call; initialize.
 237.129 +
 237.130 +   When `getopt' returns -1, this is the index of the first of the
 237.131 +   non-option elements that the caller should itself scan.
 237.132 +
 237.133 +   Otherwise, `optind' communicates from one call to the next
 237.134 +   how much of ARGV has been scanned so far.  */
 237.135 +
 237.136 +/* 1003.2 says this must be 1 before any call.  */
 237.137 +int optind = 1;
 237.138 +
 237.139 +/* Formerly, initialization of getopt depended on optind==0, which
 237.140 +   causes problems with re-calling getopt as programs generally don't
 237.141 +   know that. */
 237.142 +
 237.143 +int __getopt_initialized = 0;
 237.144 +
 237.145 +/* The next char to be scanned in the option-element
 237.146 +   in which the last option character we returned was found.
 237.147 +   This allows us to pick up the scan where we left off.
 237.148 +
 237.149 +   If this is zero, or a null string, it means resume the scan
 237.150 +   by advancing to the next ARGV-element.  */
 237.151 +
 237.152 +static char *nextchar;
 237.153 +
 237.154 +/* Callers store zero here to inhibit the error message
 237.155 +   for unrecognized options.  */
 237.156 +
 237.157 +int opterr = 1;
 237.158 +
 237.159 +/* Set to an option character which was unrecognized.
 237.160 +   This must be initialized on some systems to avoid linking in the
 237.161 +   system's own getopt implementation.  */
 237.162 +
 237.163 +int optopt = '?';
 237.164 +
 237.165 +/* Describe how to deal with options that follow non-option ARGV-elements.
 237.166 +
 237.167 +   If the caller did not specify anything,
 237.168 +   the default is REQUIRE_ORDER if the environment variable
 237.169 +   POSIXLY_CORRECT is defined, PERMUTE otherwise.
 237.170 +
 237.171 +   REQUIRE_ORDER means don't recognize them as options;
 237.172 +   stop option processing when the first non-option is seen.
 237.173 +   This is what Unix does.
 237.174 +   This mode of operation is selected by either setting the environment
 237.175 +   variable POSIXLY_CORRECT, or using `+' as the first character
 237.176 +   of the list of option characters.
 237.177 +
 237.178 +   PERMUTE is the default.  We permute the contents of ARGV as we scan,
 237.179 +   so that eventually all the non-options are at the end.  This allows options
 237.180 +   to be given in any order, even with programs that were not written to
 237.181 +   expect this.
 237.182 +
 237.183 +   RETURN_IN_ORDER is an option available to programs that were written
 237.184 +   to expect options and other ARGV-elements in any order and that care about
 237.185 +   the ordering of the two.  We describe each non-option ARGV-element
 237.186 +   as if it were the argument of an option with character code 1.
 237.187 +   Using `-' as the first character of the list of option characters
 237.188 +   selects this mode of operation.
 237.189 +
 237.190 +   The special argument `--' forces an end of option-scanning regardless
 237.191 +   of the value of `ordering'.  In the case of RETURN_IN_ORDER, only
 237.192 +   `--' can cause `getopt' to return -1 with `optind' != ARGC.  */
 237.193 +
 237.194 +static enum
 237.195 +{
 237.196 +  REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
 237.197 +} ordering;
 237.198 +
 237.199 +/* Value of POSIXLY_CORRECT environment variable.  */
 237.200 +static char *posixly_correct;
 237.201 +
 237.202 +#ifdef	__GNU_LIBRARY__
 237.203 +/* We want to avoid inclusion of string.h with non-GNU libraries
 237.204 +   because there are many ways it can cause trouble.
 237.205 +   On some systems, it contains special magic macros that don't work
 237.206 +   in GCC.  */
 237.207 +# include <string.h>
 237.208 +# define my_index	strchr
 237.209 +#else
 237.210 +
 237.211 +# if HAVE_STRING_H
 237.212 +#  include <string.h>
 237.213 +# else
 237.214 +#  if HAVE_STRINGS_H
 237.215 +#   include <strings.h>
 237.216 +#  endif
 237.217 +# endif
 237.218 +
 237.219 +/* Avoid depending on library functions or files
 237.220 +   whose names are inconsistent.  */
 237.221 +
 237.222 +#ifndef getenv
 237.223 +extern char *getenv ();
 237.224 +#endif
 237.225 +
 237.226 +static char *
 237.227 +my_index (str, chr)
 237.228 +     const char *str;
 237.229 +     int chr;
 237.230 +{
 237.231 +  while (*str)
 237.232 +    {
 237.233 +      if (*str == chr)
 237.234 +	return (char *) str;
 237.235 +      str++;
 237.236 +    }
 237.237 +  return 0;
 237.238 +}
 237.239 +
 237.240 +/* If using GCC, we can safely declare strlen this way.
 237.241 +   If not using GCC, it is ok not to declare it.  */
 237.242 +#ifdef __GNUC__
 237.243 +/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
 237.244 +   That was relevant to code that was here before.  */
 237.245 +# if (!defined __STDC__ || !__STDC__) && !defined strlen
 237.246 +/* gcc with -traditional declares the built-in strlen to return int,
 237.247 +   and has done so at least since version 2.4.5. -- rms.  */
 237.248 +extern int strlen (const char *);
 237.249 +# endif /* not __STDC__ */
 237.250 +#endif /* __GNUC__ */
 237.251 +
 237.252 +#endif /* not __GNU_LIBRARY__ */
 237.253 +
 237.254 +/* Handle permutation of arguments.  */
 237.255 +
 237.256 +/* Describe the part of ARGV that contains non-options that have
 237.257 +   been skipped.  `first_nonopt' is the index in ARGV of the first of them;
 237.258 +   `last_nonopt' is the index after the last of them.  */
 237.259 +
 237.260 +static int first_nonopt;
 237.261 +static int last_nonopt;
 237.262 +
 237.263 +#ifdef _LIBC
 237.264 +/* Bash 2.0 gives us an environment variable containing flags
 237.265 +   indicating ARGV elements that should not be considered arguments.  */
 237.266 +
 237.267 +/* Defined in getopt_init.c  */
 237.268 +extern char *__getopt_nonoption_flags;
 237.269 +
 237.270 +static int nonoption_flags_max_len;
 237.271 +static int nonoption_flags_len;
 237.272 +
 237.273 +static int original_argc;
 237.274 +static char *const *original_argv;
 237.275 +
 237.276 +/* Make sure the environment variable bash 2.0 puts in the environment
 237.277 +   is valid for the getopt call we must make sure that the ARGV passed
 237.278 +   to getopt is that one passed to the process.  */
 237.279 +static void
 237.280 +__attribute__ ((unused))
 237.281 +store_args_and_env (int argc, char *const *argv)
 237.282 +{
 237.283 +  /* XXX This is no good solution.  We should rather copy the args so
 237.284 +     that we can compare them later.  But we must not use malloc(3).  */
 237.285 +  original_argc = argc;
 237.286 +  original_argv = argv;
 237.287 +}
 237.288 +# ifdef text_set_element
 237.289 +text_set_element (__libc_subinit, store_args_and_env);
 237.290 +# endif /* text_set_element */
 237.291 +
 237.292 +# define SWAP_FLAGS(ch1, ch2) \
 237.293 +  if (nonoption_flags_len > 0)						      \
 237.294 +    {									      \
 237.295 +      char __tmp = __getopt_nonoption_flags[ch1];			      \
 237.296 +      __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2];	      \
 237.297 +      __getopt_nonoption_flags[ch2] = __tmp;				      \
 237.298 +    }
 237.299 +#else	/* !_LIBC */
 237.300 +# define SWAP_FLAGS(ch1, ch2)
 237.301 +#endif	/* _LIBC */
 237.302 +
 237.303 +/* Exchange two adjacent subsequences of ARGV.
 237.304 +   One subsequence is elements [first_nonopt,last_nonopt)
 237.305 +   which contains all the non-options that have been skipped so far.
 237.306 +   The other is elements [last_nonopt,optind), which contains all
 237.307 +   the options processed since those non-options were skipped.
 237.308 +
 237.309 +   `first_nonopt' and `last_nonopt' are relocated so that they describe
 237.310 +   the new indices of the non-options in ARGV after they are moved.  */
 237.311 +
 237.312 +#if defined __STDC__ && __STDC__
 237.313 +static void exchange (char **);
 237.314 +#endif
 237.315 +
 237.316 +static void
 237.317 +exchange (argv)
 237.318 +     char **argv;
 237.319 +{
 237.320 +  int bottom = first_nonopt;
 237.321 +  int middle = last_nonopt;
 237.322 +  int top = optind;
 237.323 +  char *tem;
 237.324 +
 237.325 +  /* Exchange the shorter segment with the far end of the longer segment.
 237.326 +     That puts the shorter segment into the right place.
 237.327 +     It leaves the longer segment in the right place overall,
 237.328 +     but it consists of two parts that need to be swapped next.  */
 237.329 +
 237.330 +#ifdef _LIBC
 237.331 +  /* First make sure the handling of the `__getopt_nonoption_flags'
 237.332 +     string can work normally.  Our top argument must be in the range
 237.333 +     of the string.  */
 237.334 +  if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len)
 237.335 +    {
 237.336 +      /* We must extend the array.  The user plays games with us and
 237.337 +	 presents new arguments.  */
 237.338 +      char *new_str = malloc (top + 1);
 237.339 +      if (new_str == NULL)
 237.340 +	nonoption_flags_len = nonoption_flags_max_len = 0;
 237.341 +      else
 237.342 +	{
 237.343 +	  memset (__mempcpy (new_str, __getopt_nonoption_flags,
 237.344 +			     nonoption_flags_max_len),
 237.345 +		  '\0', top + 1 - nonoption_flags_max_len);
 237.346 +	  nonoption_flags_max_len = top + 1;
 237.347 +	  __getopt_nonoption_flags = new_str;
 237.348 +	}
 237.349 +    }
 237.350 +#endif
 237.351 +
 237.352 +  while (top > middle && middle > bottom)
 237.353 +    {
 237.354 +      if (top - middle > middle - bottom)
 237.355 +	{
 237.356 +	  /* Bottom segment is the short one.  */
 237.357 +	  int len = middle - bottom;
 237.358 +	  register int i;
 237.359 +
 237.360 +	  /* Swap it with the top part of the top segment.  */
 237.361 +	  for (i = 0; i < len; i++)
 237.362 +	    {
 237.363 +	      tem = argv[bottom + i];
 237.364 +	      argv[bottom + i] = argv[top - (middle - bottom) + i];
 237.365 +	      argv[top - (middle - bottom) + i] = tem;
 237.366 +	      SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
 237.367 +	    }
 237.368 +	  /* Exclude the moved bottom segment from further swapping.  */
 237.369 +	  top -= len;
 237.370 +	}
 237.371 +      else
 237.372 +	{
 237.373 +	  /* Top segment is the short one.  */
 237.374 +	  int len = top - middle;
 237.375 +	  register int i;
 237.376 +
 237.377 +	  /* Swap it with the bottom part of the bottom segment.  */
 237.378 +	  for (i = 0; i < len; i++)
 237.379 +	    {
 237.380 +	      tem = argv[bottom + i];
 237.381 +	      argv[bottom + i] = argv[middle + i];
 237.382 +	      argv[middle + i] = tem;
 237.383 +	      SWAP_FLAGS (bottom + i, middle + i);
 237.384 +	    }
 237.385 +	  /* Exclude the moved top segment from further swapping.  */
 237.386 +	  bottom += len;
 237.387 +	}
 237.388 +    }
 237.389 +
 237.390 +  /* Update records for the slots the non-options now occupy.  */
 237.391 +
 237.392 +  first_nonopt += (optind - last_nonopt);
 237.393 +  last_nonopt = optind;
 237.394 +}
 237.395 +
 237.396 +/* Initialize the internal data when the first call is made.  */
 237.397 +
 237.398 +#if defined __STDC__ && __STDC__
 237.399 +static const char *_getopt_initialize (int, char *const *, const char *);
 237.400 +#endif
 237.401 +static const char *
 237.402 +_getopt_initialize (argc, argv, optstring)
 237.403 +     int argc;
 237.404 +     char *const *argv;
 237.405 +     const char *optstring;
 237.406 +{
 237.407 +  /* Start processing options with ARGV-element 1 (since ARGV-element 0
 237.408 +     is the program name); the sequence of previously skipped
 237.409 +     non-option ARGV-elements is empty.  */
 237.410 +
 237.411 +  first_nonopt = last_nonopt = optind;
 237.412 +
 237.413 +  nextchar = NULL;
 237.414 +
 237.415 +  posixly_correct = getenv ("POSIXLY_CORRECT");
 237.416 +
 237.417 +  /* Determine how to handle the ordering of options and nonoptions.  */
 237.418 +
 237.419 +  if (optstring[0] == '-')
 237.420 +    {
 237.421 +      ordering = RETURN_IN_ORDER;
 237.422 +      ++optstring;
 237.423 +    }
 237.424 +  else if (optstring[0] == '+')
 237.425 +    {
 237.426 +      ordering = REQUIRE_ORDER;
 237.427 +      ++optstring;
 237.428 +    }
 237.429 +  else if (posixly_correct != NULL)
 237.430 +    ordering = REQUIRE_ORDER;
 237.431 +  else
 237.432 +    ordering = PERMUTE;
 237.433 +
 237.434 +#ifdef _LIBC
 237.435 +  if (posixly_correct == NULL
 237.436 +      && argc == original_argc && argv == original_argv)
 237.437 +    {
 237.438 +      if (nonoption_flags_max_len == 0)
 237.439 +	{
 237.440 +	  if (__getopt_nonoption_flags == NULL
 237.441 +	      || __getopt_nonoption_flags[0] == '\0')
 237.442 +	    nonoption_flags_max_len = -1;
 237.443 +	  else
 237.444 +	    {
 237.445 +	      const char *orig_str = __getopt_nonoption_flags;
 237.446 +	      int len = nonoption_flags_max_len = strlen (orig_str);
 237.447 +	      if (nonoption_flags_max_len < argc)
 237.448 +		nonoption_flags_max_len = argc;
 237.449 +	      __getopt_nonoption_flags =
 237.450 +		(char *) malloc (nonoption_flags_max_len);
 237.451 +	      if (__getopt_nonoption_flags == NULL)
 237.452 +		nonoption_flags_max_len = -1;
 237.453 +	      else
 237.454 +		memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
 237.455 +			'\0', nonoption_flags_max_len - len);
 237.456 +	    }
 237.457 +	}
 237.458 +      nonoption_flags_len = nonoption_flags_max_len;
 237.459 +    }
 237.460 +  else
 237.461 +    nonoption_flags_len = 0;
 237.462 +#endif
 237.463 +
 237.464 +  return optstring;
 237.465 +}
 237.466 +
 237.467 +/* Scan elements of ARGV (whose length is ARGC) for option characters
 237.468 +   given in OPTSTRING.
 237.469 +
 237.470 +   If an element of ARGV starts with '-', and is not exactly "-" or "--",
 237.471 +   then it is an option element.  The characters of this element
 237.472 +   (aside from the initial '-') are option characters.  If `getopt'
 237.473 +   is called repeatedly, it returns successively each of the option characters
 237.474 +   from each of the option elements.
 237.475 +
 237.476 +   If `getopt' finds another option character, it returns that character,
 237.477 +   updating `optind' and `nextchar' so that the next call to `getopt' can
 237.478 +   resume the scan with the following option character or ARGV-element.
 237.479 +
 237.480 +   If there are no more option characters, `getopt' returns -1.
 237.481 +   Then `optind' is the index in ARGV of the first ARGV-element
 237.482 +   that is not an option.  (The ARGV-elements have been permuted
 237.483 +   so that those that are not options now come last.)
 237.484 +
 237.485 +   OPTSTRING is a string containing the legitimate option characters.
 237.486 +   If an option character is seen that is not listed in OPTSTRING,
 237.487 +   return '?' after printing an error message.  If you set `opterr' to
 237.488 +   zero, the error message is suppressed but we still return '?'.
 237.489 +
 237.490 +   If a char in OPTSTRING is followed by a colon, that means it wants an arg,
 237.491 +   so the following text in the same ARGV-element, or the text of the following
 237.492 +   ARGV-element, is returned in `optarg'.  Two colons mean an option that
 237.493 +   wants an optional arg; if there is text in the current ARGV-element,
 237.494 +   it is returned in `optarg', otherwise `optarg' is set to zero.
 237.495 +
 237.496 +   If OPTSTRING starts with `-' or `+', it requests different methods of
 237.497 +   handling the non-option ARGV-elements.
 237.498 +   See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
 237.499 +
 237.500 +   Long-named options begin with `--' instead of `-'.
 237.501 +   Their names may be abbreviated as long as the abbreviation is unique
 237.502 +   or is an exact match for some defined option.  If they have an
 237.503 +   argument, it follows the option name in the same ARGV-element, separated
 237.504 +   from the option name by a `=', or else the in next ARGV-element.
 237.505 +   When `getopt' finds a long-named option, it returns 0 if that option's
 237.506 +   `flag' field is nonzero, the value of the option's `val' field
 237.507 +   if the `flag' field is zero.
 237.508 +
 237.509 +   The elements of ARGV aren't really const, because we permute them.
 237.510 +   But we pretend they're const in the prototype to be compatible
 237.511 +   with other systems.
 237.512 +
 237.513 +   LONGOPTS is a vector of `struct option' terminated by an
 237.514 +   element containing a name which is zero.
 237.515 +
 237.516 +   LONGIND returns the index in LONGOPT of the long-named option found.
 237.517 +   It is only valid when a long-named option has been found by the most
 237.518 +   recent call.
 237.519 +
 237.520 +   If LONG_ONLY is nonzero, '-' as well as '--' can introduce
 237.521 +   long-named options.  */
 237.522 +
 237.523 +int
 237.524 +_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
 237.525 +     int argc;
 237.526 +     char *const *argv;
 237.527 +     const char *optstring;
 237.528 +     const struct option *longopts;
 237.529 +     int *longind;
 237.530 +     int long_only;
 237.531 +{
 237.532 +  optarg = NULL;
 237.533 +
 237.534 +  if (optind == 0 || !__getopt_initialized)
 237.535 +    {
 237.536 +      if (optind == 0)
 237.537 +	optind = 1;	/* Don't scan ARGV[0], the program name.  */
 237.538 +      optstring = _getopt_initialize (argc, argv, optstring);
 237.539 +      __getopt_initialized = 1;
 237.540 +    }
 237.541 +
 237.542 +  /* Test whether ARGV[optind] points to a non-option argument.
 237.543 +     Either it does not have option syntax, or there is an environment flag
 237.544 +     from the shell indicating it is not an option.  The later information
 237.545 +     is only used when the used in the GNU libc.  */
 237.546 +#ifdef _LIBC
 237.547 +# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0'	      \
 237.548 +		      || (optind < nonoption_flags_len			      \
 237.549 +			  && __getopt_nonoption_flags[optind] == '1'))
 237.550 +#else
 237.551 +# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
 237.552 +#endif
 237.553 +
 237.554 +  if (nextchar == NULL || *nextchar == '\0')
 237.555 +    {
 237.556 +      /* Advance to the next ARGV-element.  */
 237.557 +
 237.558 +      /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
 237.559 +	 moved back by the user (who may also have changed the arguments).  */
 237.560 +      if (last_nonopt > optind)
 237.561 +	last_nonopt = optind;
 237.562 +      if (first_nonopt > optind)
 237.563 +	first_nonopt = optind;
 237.564 +
 237.565 +      if (ordering == PERMUTE)
 237.566 +	{
 237.567 +	  /* If we have just processed some options following some non-options,
 237.568 +	     exchange them so that the options come first.  */
 237.569 +
 237.570 +	  if (first_nonopt != last_nonopt && last_nonopt != optind)
 237.571 +	    exchange ((char **) argv);
 237.572 +	  else if (last_nonopt != optind)
 237.573 +	    first_nonopt = optind;
 237.574 +
 237.575 +	  /* Skip any additional non-options
 237.576 +	     and extend the range of non-options previously skipped.  */
 237.577 +
 237.578 +	  while (optind < argc && NONOPTION_P)
 237.579 +	    optind++;
 237.580 +	  last_nonopt = optind;
 237.581 +	}
 237.582 +
 237.583 +      /* The special ARGV-element `--' means premature end of options.
 237.584 +	 Skip it like a null option,
 237.585 +	 then exchange with previous non-options as if it were an option,
 237.586 +	 then skip everything else like a non-option.  */
 237.587 +
 237.588 +      if (optind != argc && !strcmp (argv[optind], "--"))
 237.589 +	{
 237.590 +	  optind++;
 237.591 +
 237.592 +	  if (first_nonopt != last_nonopt && last_nonopt != optind)
 237.593 +	    exchange ((char **) argv);
 237.594 +	  else if (first_nonopt == last_nonopt)
 237.595 +	    first_nonopt = optind;
 237.596 +	  last_nonopt = argc;
 237.597 +
 237.598 +	  optind = argc;
 237.599 +	}
 237.600 +
 237.601 +      /* If we have done all the ARGV-elements, stop the scan
 237.602 +	 and back over any non-options that we skipped and permuted.  */
 237.603 +
 237.604 +      if (optind == argc)
 237.605 +	{
 237.606 +	  /* Set the next-arg-index to point at the non-options
 237.607 +	     that we previously skipped, so the caller will digest them.  */
 237.608 +	  if (first_nonopt != last_nonopt)
 237.609 +	    optind = first_nonopt;
 237.610 +	  return -1;
 237.611 +	}
 237.612 +
 237.613 +      /* If we have come to a non-option and did not permute it,
 237.614 +	 either stop the scan or describe it to the caller and pass it by.  */
 237.615 +
 237.616 +      if (NONOPTION_P)
 237.617 +	{
 237.618 +	  if (ordering == REQUIRE_ORDER)
 237.619 +	    return -1;
 237.620 +	  optarg = argv[optind++];
 237.621 +	  return 1;
 237.622 +	}
 237.623 +
 237.624 +      /* We have found another option-ARGV-element.
 237.625 +	 Skip the initial punctuation.  */
 237.626 +
 237.627 +      nextchar = (argv[optind] + 1
 237.628 +		  + (longopts != NULL && argv[optind][1] == '-'));
 237.629 +    }
 237.630 +
 237.631 +  /* Decode the current option-ARGV-element.  */
 237.632 +
 237.633 +  /* Check whether the ARGV-element is a long option.
 237.634 +
 237.635 +     If long_only and the ARGV-element has the form "-f", where f is
 237.636 +     a valid short option, don't consider it an abbreviated form of
 237.637 +     a long option that starts with f.  Otherwise there would be no
 237.638 +     way to give the -f short option.
 237.639 +
 237.640 +     On the other hand, if there's a long option "fubar" and
 237.641 +     the ARGV-element is "-fu", do consider that an abbreviation of
 237.642 +     the long option, just like "--fu", and not "-f" with arg "u".
 237.643 +
 237.644 +     This distinction seems to be the most useful approach.  */
 237.645 +
 237.646 +  if (longopts != NULL
 237.647 +      && (argv[optind][1] == '-'
 237.648 +	  || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
 237.649 +    {
 237.650 +      char *nameend;
 237.651 +      const struct option *p;
 237.652 +      const struct option *pfound = NULL;
 237.653 +      int exact = 0;
 237.654 +      int ambig = 0;
 237.655 +      int indfound = -1;
 237.656 +      int option_index;
 237.657 +
 237.658 +      for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
 237.659 +	/* Do nothing.  */ ;
 237.660 +
 237.661 +      /* Test all long options for either exact match
 237.662 +	 or abbreviated matches.  */
 237.663 +      for (p = longopts, option_index = 0; p->name; p++, option_index++)
 237.664 +	if (!strncmp (p->name, nextchar, nameend - nextchar))
 237.665 +	  {
 237.666 +	    if ((unsigned int) (nameend - nextchar)
 237.667 +		== (unsigned int) strlen (p->name))
 237.668 +	      {
 237.669 +		/* Exact match found.  */
 237.670 +		pfound = p;
 237.671 +		indfound = option_index;
 237.672 +		exact = 1;
 237.673 +		break;
 237.674 +	      }
 237.675 +	    else if (pfound == NULL)
 237.676 +	      {
 237.677 +		/* First nonexact match found.  */
 237.678 +		pfound = p;
 237.679 +		indfound = option_index;
 237.680 +	      }
 237.681 +	    else
 237.682 +	      /* Second or later nonexact match found.  */
 237.683 +	      ambig = 1;
 237.684 +	  }
 237.685 +
 237.686 +      if (ambig && !exact)
 237.687 +	{
 237.688 +	  if (opterr)
 237.689 +	    fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
 237.690 +		     argv[0], argv[optind]);
 237.691 +	  nextchar += strlen (nextchar);
 237.692 +	  optind++;
 237.693 +	  optopt = 0;
 237.694 +	  return '?';
 237.695 +	}
 237.696 +
 237.697 +      if (pfound != NULL)
 237.698 +	{
 237.699 +	  option_index = indfound;
 237.700 +	  optind++;
 237.701 +	  if (*nameend)
 237.702 +	    {
 237.703 +	      /* Don't test has_arg with >, because some C compilers don't
 237.704 +		 allow it to be used on enums.  */
 237.705 +	      if (pfound->has_arg)
 237.706 +		optarg = nameend + 1;
 237.707 +	      else
 237.708 +		{
 237.709 +		  if (opterr)
 237.710 +		    {
 237.711 +		      if (argv[optind - 1][1] == '-')
 237.712 +			/* --option */
 237.713 +			fprintf (stderr,
 237.714 +				 _("%s: option `--%s' doesn't allow an argument\n"),
 237.715 +				 argv[0], pfound->name);
 237.716 +		      else
 237.717 +			/* +option or -option */
 237.718 +			fprintf (stderr,
 237.719 +				 _("%s: option `%c%s' doesn't allow an argument\n"),
 237.720 +				 argv[0], argv[optind - 1][0], pfound->name);
 237.721 +
 237.722 +		      nextchar += strlen (nextchar);
 237.723 +
 237.724 +		      optopt = pfound->val;
 237.725 +		      return '?';
 237.726 +		    }
 237.727 +		}
 237.728 +	    }
 237.729 +	  else if (pfound->has_arg == 1)
 237.730 +	    {
 237.731 +	      if (optind < argc)
 237.732 +		optarg = argv[optind++];
 237.733 +	      else
 237.734 +		{
 237.735 +		  if (opterr)
 237.736 +		    fprintf (stderr,
 237.737 +			   _("%s: option `%s' requires an argument\n"),
 237.738 +			   argv[0], argv[optind - 1]);
 237.739 +		  nextchar += strlen (nextchar);
 237.740 +		  optopt = pfound->val;
 237.741 +		  return optstring[0] == ':' ? ':' : '?';
 237.742 +		}
 237.743 +	    }
 237.744 +	  nextchar += strlen (nextchar);
 237.745 +	  if (longind != NULL)
 237.746 +	    *longind = option_index;
 237.747 +	  if (pfound->flag)
 237.748 +	    {
 237.749 +	      *(pfound->flag) = pfound->val;
 237.750 +	      return 0;
 237.751 +	    }
 237.752 +	  return pfound->val;
 237.753 +	}
 237.754 +
 237.755 +      /* Can't find it as a long option.  If this is not getopt_long_only,
 237.756 +	 or the option starts with '--' or is not a valid short
 237.757 +	 option, then it's an error.
 237.758 +	 Otherwise interpret it as a short option.  */
 237.759 +      if (!long_only || argv[optind][1] == '-'
 237.760 +	  || my_index (optstring, *nextchar) == NULL)
 237.761 +	{
 237.762 +	  if (opterr)
 237.763 +	    {
 237.764 +	      if (argv[optind][1] == '-')
 237.765 +		/* --option */
 237.766 +		fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
 237.767 +			 argv[0], nextchar);
 237.768 +	      else
 237.769 +		/* +option or -option */
 237.770 +		fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
 237.771 +			 argv[0], argv[optind][0], nextchar);
 237.772 +	    }
 237.773 +	  nextchar = (char *) "";
 237.774 +	  optind++;
 237.775 +	  optopt = 0;
 237.776 +	  return '?';
 237.777 +	}
 237.778 +    }
 237.779 +
 237.780 +  /* Look at and handle the next short option-character.  */
 237.781 +
 237.782 +  {
 237.783 +    char c = *nextchar++;
 237.784 +    char *temp = my_index (optstring, c);
 237.785 +
 237.786 +    /* Increment `optind' when we start to process its last character.  */
 237.787 +    if (*nextchar == '\0')
 237.788 +      ++optind;
 237.789 +
 237.790 +    if (temp == NULL || c == ':')
 237.791 +      {
 237.792 +	if (opterr)
 237.793 +	  {
 237.794 +	    if (posixly_correct)
 237.795 +	      /* 1003.2 specifies the format of this message.  */
 237.796 +	      fprintf (stderr, _("%s: illegal option -- %c\n"),
 237.797 +		       argv[0], c);
 237.798 +	    else
 237.799 +	      fprintf (stderr, _("%s: invalid option -- %c\n"),
 237.800 +		       argv[0], c);
 237.801 +	  }
 237.802 +	optopt = c;
 237.803 +	return '?';
 237.804 +      }
 237.805 +    /* Convenience. Treat POSIX -W foo same as long option --foo */
 237.806 +    if (temp[0] == 'W' && temp[1] == ';')
 237.807 +      {
 237.808 +	char *nameend;
 237.809 +	const struct option *p;
 237.810 +	const struct option *pfound = NULL;
 237.811 +	int exact = 0;
 237.812 +	int ambig = 0;
 237.813 +	int indfound = 0;
 237.814 +	int option_index;
 237.815 +
 237.816 +	/* This is an option that requires an argument.  */
 237.817 +	if (*nextchar != '\0')
 237.818 +	  {
 237.819 +	    optarg = nextchar;
 237.820 +	    /* If we end this ARGV-element by taking the rest as an arg,
 237.821 +	       we must advance to the next element now.  */
 237.822 +	    optind++;
 237.823 +	  }
 237.824 +	else if (optind == argc)
 237.825 +	  {
 237.826 +	    if (opterr)
 237.827 +	      {
 237.828 +		/* 1003.2 specifies the format of this message.  */
 237.829 +		fprintf (stderr, _("%s: option requires an argument -- %c\n"),
 237.830 +			 argv[0], c);
 237.831 +	      }
 237.832 +	    optopt = c;
 237.833 +	    if (optstring[0] == ':')
 237.834 +	      c = ':';
 237.835 +	    else
 237.836 +	      c = '?';
 237.837 +	    return c;
 237.838 +	  }
 237.839 +	else
 237.840 +	  /* We already incremented `optind' once;
 237.841 +	     increment it again when taking next ARGV-elt as argument.  */
 237.842 +	  optarg = argv[optind++];
 237.843 +
 237.844 +	/* optarg is now the argument, see if it's in the
 237.845 +	   table of longopts.  */
 237.846 +
 237.847 +	for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
 237.848 +	  /* Do nothing.  */ ;
 237.849 +
 237.850 +	/* Test all long options for either exact match
 237.851 +	   or abbreviated matches.  */
 237.852 +	for (p = longopts, option_index = 0; p->name; p++, option_index++)
 237.853 +	  if (!strncmp (p->name, nextchar, nameend - nextchar))
 237.854 +	    {
 237.855 +	      if ((unsigned int) (nameend - nextchar) == strlen (p->name))
 237.856 +		{
 237.857 +		  /* Exact match found.  */
 237.858 +		  pfound = p;
 237.859 +		  indfound = option_index;
 237.860 +		  exact = 1;
 237.861 +		  break;
 237.862 +		}
 237.863 +	      else if (pfound == NULL)
 237.864 +		{
 237.865 +		  /* First nonexact match found.  */
 237.866 +		  pfound = p;
 237.867 +		  indfound = option_index;
 237.868 +		}
 237.869 +	      else
 237.870 +		/* Second or later nonexact match found.  */
 237.871 +		ambig = 1;
 237.872 +	    }
 237.873 +	if (ambig && !exact)
 237.874 +	  {
 237.875 +	    if (opterr)
 237.876 +	      fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
 237.877 +		       argv[0], argv[optind]);
 237.878 +	    nextchar += strlen (nextchar);
 237.879 +	    optind++;
 237.880 +	    return '?';
 237.881 +	  }
 237.882 +	if (pfound != NULL)
 237.883 +	  {
 237.884 +	    option_index = indfound;
 237.885 +	    if (*nameend)
 237.886 +	      {
 237.887 +		/* Don't test has_arg with >, because some C compilers don't
 237.888 +		   allow it to be used on enums.  */
 237.889 +		if (pfound->has_arg)
 237.890 +		  optarg = nameend + 1;
 237.891 +		else
 237.892 +		  {
 237.893 +		    if (opterr)
 237.894 +		      fprintf (stderr, _("\
 237.895 +%s: option `-W %s' doesn't allow an argument\n"),
 237.896 +			       argv[0], pfound->name);
 237.897 +
 237.898 +		    nextchar += strlen (nextchar);
 237.899 +		    return '?';
 237.900 +		  }
 237.901 +	      }
 237.902 +	    else if (pfound->has_arg == 1)
 237.903 +	      {
 237.904 +		if (optind < argc)
 237.905 +		  optarg = argv[optind++];
 237.906 +		else
 237.907 +		  {
 237.908 +		    if (opterr)
 237.909 +		      fprintf (stderr,
 237.910 +			       _("%s: option `%s' requires an argument\n"),
 237.911 +			       argv[0], argv[optind - 1]);
 237.912 +		    nextchar += strlen (nextchar);
 237.913 +		    return optstring[0] == ':' ? ':' : '?';
 237.914 +		  }
 237.915 +	      }
 237.916 +	    nextchar += strlen (nextchar);
 237.917 +	    if (longind != NULL)
 237.918 +	      *longind = option_index;
 237.919 +	    if (pfound->flag)
 237.920 +	      {
 237.921 +		*(pfound->flag) = pfound->val;
 237.922 +		return 0;
 237.923 +	      }
 237.924 +	    return pfound->val;
 237.925 +	  }
 237.926 +	  nextchar = NULL;
 237.927 +	  return 'W';	/* Let the application handle it.   */
 237.928 +      }
 237.929 +    if (temp[1] == ':')
 237.930 +      {
 237.931 +	if (temp[2] == ':')
 237.932 +	  {
 237.933 +	    /* This is an option that accepts an argument optionally.  */
 237.934 +	    if (*nextchar != '\0')
 237.935 +	      {
 237.936 +		optarg = nextchar;
 237.937 +		optind++;
 237.938 +	      }
 237.939 +	    else
 237.940 +	      optarg = NULL;
 237.941 +	    nextchar = NULL;
 237.942 +	  }
 237.943 +	else
 237.944 +	  {
 237.945 +	    /* This is an option that requires an argument.  */
 237.946 +	    if (*nextchar != '\0')
 237.947 +	      {
 237.948 +		optarg = nextchar;
 237.949 +		/* If we end this ARGV-element by taking the rest as an arg,
 237.950 +		   we must advance to the next element now.  */
 237.951 +		optind++;
 237.952 +	      }
 237.953 +	    else if (optind == argc)
 237.954 +	      {
 237.955 +		if (opterr)
 237.956 +		  {
 237.957 +		    /* 1003.2 specifies the format of this message.  */
 237.958 +		    fprintf (stderr,
 237.959 +			   _("%s: option requires an argument -- %c\n"),
 237.960 +			   argv[0], c);
 237.961 +		  }
 237.962 +		optopt = c;
 237.963 +		if (optstring[0] == ':')
 237.964 +		  c = ':';
 237.965 +		else
 237.966 +		  c = '?';
 237.967 +	      }
 237.968 +	    else
 237.969 +	      /* We already incremented `optind' once;
 237.970 +		 increment it again when taking next ARGV-elt as argument.  */
 237.971 +	      optarg = argv[optind++];
 237.972 +	    nextchar = NULL;
 237.973 +	  }
 237.974 +      }
 237.975 +    return c;
 237.976 +  }
 237.977 +}
 237.978 +
 237.979 +int
 237.980 +getopt (argc, argv, optstring)
 237.981 +     int argc;
 237.982 +     char *const *argv;
 237.983 +     const char *optstring;
 237.984 +{
 237.985 +  return _getopt_internal (argc, argv, optstring,
 237.986 +			   (const struct option *) 0,
 237.987 +			   (int *) 0,
 237.988 +			   0);
 237.989 +}
 237.990 +
 237.991 +#endif	/* Not ELIDE_CODE.  */
 237.992 +
 237.993 +#ifdef TEST
 237.994 +
 237.995 +/* Compile with -DTEST to make an executable for use in testing
 237.996 +   the above definition of `getopt'.  */
 237.997 +
 237.998 +int
 237.999 +main (argc, argv)
237.1000 +     int argc;
237.1001 +     char **argv;
237.1002 +{
237.1003 +  int c;
237.1004 +  int digit_optind = 0;
237.1005 +
237.1006 +  while (1)
237.1007 +    {
237.1008 +      int this_option_optind = optind ? optind : 1;
237.1009 +
237.1010 +      c = getopt (argc, argv, "abc:d:0123456789");
237.1011 +      if (c == -1)
237.1012 +	break;
237.1013 +
237.1014 +      switch (c)
237.1015 +	{
237.1016 +	case '0':
237.1017 +	case '1':
237.1018 +	case '2':
237.1019 +	case '3':
237.1020 +	case '4':
237.1021 +	case '5':
237.1022 +	case '6':
237.1023 +	case '7':
237.1024 +	case '8':
237.1025 +	case '9':
237.1026 +	  if (digit_optind != 0 && digit_optind != this_option_optind)
237.1027 +	    printf ("digits occur in two different argv-elements.\n");
237.1028 +	  digit_optind = this_option_optind;
237.1029 +	  printf ("option %c\n", c);
237.1030 +	  break;
237.1031 +
237.1032 +	case 'a':
237.1033 +	  printf ("option a\n");
237.1034 +	  break;
237.1035 +
237.1036 +	case 'b':
237.1037 +	  printf ("option b\n");
237.1038 +	  break;
237.1039 +
237.1040 +	case 'c':
237.1041 +	  printf ("option c with value `%s'\n", optarg);
237.1042 +	  break;
237.1043 +
237.1044 +	case '?':
237.1045 +	  break;
237.1046 +
237.1047 +	default:
237.1048 +	  printf ("?? getopt returned character code 0%o ??\n", c);
237.1049 +	}
237.1050 +    }
237.1051 +
237.1052 +  if (optind < argc)
237.1053 +    {
237.1054 +      printf ("non-option ARGV-elements: ");
237.1055 +      while (optind < argc)
237.1056 +	printf ("%s ", argv[optind++]);
237.1057 +      printf ("\n");
237.1058 +    }
237.1059 +
237.1060 +  exit (0);
237.1061 +}
237.1062 +
237.1063 +#endif /* TEST */
   238.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   238.2 +++ b/src/sdl/getopt.h	Sat Mar 03 10:31:27 2012 -0600
   238.3 @@ -0,0 +1,141 @@
   238.4 +/* Declarations for getopt.
   238.5 +   Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, 2000
   238.6 +   Free Software Foundation, Inc.
   238.7 +
   238.8 +   NOTE: The canonical source of this file is maintained with the GNU C Library.
   238.9 +   Bugs can be reported to bug-glibc@gnu.org.
  238.10 +
  238.11 +   This program is free software; you can redistribute it and/or modify it
  238.12 +   under the terms of the GNU General Public License as published by the
  238.13 +   Free Software Foundation; either version 2, or (at your option) any
  238.14 +   later version.
  238.15 +
  238.16 +   This program is distributed in the hope that it will be useful,
  238.17 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
  238.18 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  238.19 +   GNU General Public License for more details.
  238.20 +
  238.21 +   You should have received a copy of the GNU General Public License
  238.22 +   along with this program; if not, write to the Free Software
  238.23 +   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  238.24 +   USA.  */
  238.25 +
  238.26 +#ifndef _GETOPT_H
  238.27 +#define _GETOPT_H 1
  238.28 +
  238.29 +#ifdef	__cplusplus
  238.30 +extern "C" {
  238.31 +#endif
  238.32 +
  238.33 +/* For communication from `getopt' to the caller.
  238.34 +   When `getopt' finds an option that takes an argument,
  238.35 +   the argument value is returned here.
  238.36 +   Also, when `ordering' is RETURN_IN_ORDER,
  238.37 +   each non-option ARGV-element is returned here.  */
  238.38 +
  238.39 +extern char *optarg;
  238.40 +
  238.41 +/* Index in ARGV of the next element to be scanned.
  238.42 +   This is used for communication to and from the caller
  238.43 +   and for communication between successive calls to `getopt'.
  238.44 +
  238.45 +   On entry to `getopt', zero means this is the first call; initialize.
  238.46 +
  238.47 +   When `getopt' returns -1, this is the index of the first of the
  238.48 +   non-option elements that the caller should itself scan.
  238.49 +
  238.50 +   Otherwise, `optind' communicates from one call to the next
  238.51 +   how much of ARGV has been scanned so far.  */
  238.52 +
  238.53 +extern int optind;
  238.54 +
  238.55 +/* Callers store zero here to inhibit the error message `getopt' prints
  238.56 +   for unrecognized options.  */
  238.57 +
  238.58 +extern int opterr;
  238.59 +
  238.60 +/* Set to an option character which was unrecognized.  */
  238.61 +
  238.62 +extern int optopt;
  238.63 +
  238.64 +/* Describe the long-named options requested by the application.
  238.65 +   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
  238.66 +   of `struct option' terminated by an element containing a name which is
  238.67 +   zero.
  238.68 +
  238.69 +   The field `has_arg' is:
  238.70 +   no_argument		(or 0) if the option does not take an argument,
  238.71 +   required_argument	(or 1) if the option requires an argument,
  238.72 +   optional_argument 	(or 2) if the option takes an optional argument.
  238.73 +
  238.74 +   If the field `flag' is not NULL, it points to a variable that is set
  238.75 +   to the value given in the field `val' when the option is found, but
  238.76 +   left unchanged if the option is not found.
  238.77 +
  238.78 +   To have a long-named option do something other than set an `int' to
  238.79 +   a compiled-in constant, such as set a value from `optarg', set the
  238.80 +   option's `flag' field to zero and its `val' field to a nonzero
  238.81 +   value (the equivalent single-letter option character, if there is
  238.82 +   one).  For long options that have a zero `flag' field, `getopt'
  238.83 +   returns the contents of the `val' field.  */
  238.84 +
  238.85 +struct option
  238.86 +{
  238.87 +#if defined (__STDC__) && __STDC__
  238.88 +  const char *name;
  238.89 +#else
  238.90 +  char *name;
  238.91 +#endif
  238.92 +  /* has_arg can't be an enum because some compilers complain about
  238.93 +     type mismatches in all the code that assumes it is an int.  */
  238.94 +  int has_arg;
  238.95 +  int *flag;
  238.96 +  int val;
  238.97 +};
  238.98 +
  238.99 +/* Names for the values of the `has_arg' field of `struct option'.  */
 238.100 +
 238.101 +#define	no_argument		0
 238.102 +#define required_argument	1
 238.103 +#define optional_argument	2
 238.104 +
 238.105 +#if defined (__STDC__) && __STDC__
 238.106 +/* HAVE_DECL_* is a three-state macro: undefined, 0 or 1.  If it is
 238.107 +   undefined, we haven't run the autoconf check so provide the
 238.108 +   declaration without arguments.  If it is 0, we checked and failed
 238.109 +   to find the declaration so provide a fully prototyped one.  If it
 238.110 +   is 1, we found it so don't provide any declaration at all.  */
 238.111 +#if defined (__GNU_LIBRARY__) || (defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT)
 238.112 +/* Many other libraries have conflicting prototypes for getopt, with
 238.113 +   differences in the consts, in stdlib.h.  To avoid compilation
 238.114 +   errors, only prototype getopt for the GNU C library.  */
 238.115 +extern int getopt (int argc, char *const *argv, const char *shortopts);
 238.116 +#else /* not __GNU_LIBRARY__ */
 238.117 +# if !defined (HAVE_DECL_GETOPT)
 238.118 +extern int getopt ();
 238.119 +# endif
 238.120 +#endif /* __GNU_LIBRARY__ */
 238.121 +extern int getopt_long (int argc, char *const *argv, const char *shortopts,
 238.122 +		        const struct option *longopts, int *longind);
 238.123 +extern int getopt_long_only (int argc, char *const *argv,
 238.124 +			     const char *shortopts,
 238.125 +		             const struct option *longopts, int *longind);
 238.126 +
 238.127 +/* Internal only.  Users should not call this directly.  */
 238.128 +extern int _getopt_internal (int argc, char *const *argv,
 238.129 +			     const char *shortopts,
 238.130 +		             const struct option *longopts, int *longind,
 238.131 +			     int long_only);
 238.132 +#else /* not __STDC__ */
 238.133 +extern int getopt ();
 238.134 +extern int getopt_long ();
 238.135 +extern int getopt_long_only ();
 238.136 +
 238.137 +extern int _getopt_internal ();
 238.138 +#endif /* __STDC__ */
 238.139 +
 238.140 +#ifdef	__cplusplus
 238.141 +}
 238.142 +#endif
 238.143 +
 238.144 +#endif /* getopt.h */
   239.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   239.2 +++ b/src/sdl/getopt1.c	Sat Mar 03 10:31:27 2012 -0600
   239.3 @@ -0,0 +1,190 @@
   239.4 +/* getopt_long and getopt_long_only entry points for GNU getopt.
   239.5 +   Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98
   239.6 +     Free Software Foundation, Inc.
   239.7 +
   239.8 +   NOTE: This source is derived from an old version taken from the GNU C
   239.9 +   Library (glibc).
  239.10 +
  239.11 +   This program is free software; you can redistribute it and/or modify it
  239.12 +   under the terms of the GNU General Public License as published by the
  239.13 +   Free Software Foundation; either version 2, or (at your option) any
  239.14 +   later version.
  239.15 +
  239.16 +   This program is distributed in the hope that it will be useful,
  239.17 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
  239.18 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  239.19 +   GNU General Public License for more details.
  239.20 +
  239.21 +   You should have received a copy of the GNU General Public License
  239.22 +   along with this program; if not, write to the Free Software
  239.23 +   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  239.24 +   USA.  */
  239.25 +
  239.26 +#ifdef HAVE_CONFIG_H
  239.27 +#include <config.h>
  239.28 +#endif
  239.29 +
  239.30 +#include "getopt.h"
  239.31 +
  239.32 +#if !defined __STDC__ || !__STDC__
  239.33 +/* This is a separate conditional since some stdc systems
  239.34 +   reject `defined (const)'.  */
  239.35 +#ifndef const
  239.36 +#define const
  239.37 +#endif
  239.38 +#endif
  239.39 +
  239.40 +#include <stdio.h>
  239.41 +
  239.42 +/* Comment out all this code if we are using the GNU C Library, and are not
  239.43 +   actually compiling the library itself.  This code is part of the GNU C
  239.44 +   Library, but also included in many other GNU distributions.  Compiling
  239.45 +   and linking in this code is a waste when using the GNU C library
  239.46 +   (especially if it is a shared library).  Rather than having every GNU
  239.47 +   program understand `configure --with-gnu-libc' and omit the object files,
  239.48 +   it is simpler to just do this in the source for each such file.  */
  239.49 +
  239.50 +#define GETOPT_INTERFACE_VERSION 2
  239.51 +#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
  239.52 +#include <gnu-versions.h>
  239.53 +#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
  239.54 +#define ELIDE_CODE
  239.55 +#endif
  239.56 +#endif
  239.57 +
  239.58 +#ifndef ELIDE_CODE
  239.59 +
  239.60 +
  239.61 +/* This needs to come after some library #include
  239.62 +   to get __GNU_LIBRARY__ defined.  */
  239.63 +#ifdef __GNU_LIBRARY__
  239.64 +#include <stdlib.h>
  239.65 +#endif
  239.66 +
  239.67 +#ifndef	NULL
  239.68 +#define NULL 0
  239.69 +#endif
  239.70 +
  239.71 +int
  239.72 +getopt_long (argc, argv, options, long_options, opt_index)
  239.73 +     int argc;
  239.74 +     char *const *argv;
  239.75 +     const char *options;
  239.76 +     const struct option *long_options;
  239.77 +     int *opt_index;
  239.78 +{
  239.79 +  return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
  239.80 +}
  239.81 +
  239.82 +/* Like getopt_long, but '-' as well as '--' can indicate a long option.
  239.83 +   If an option that starts with '-' (not '--') doesn't match a long option,
  239.84 +   but does match a short option, it is parsed as a short option
  239.85 +   instead.  */
  239.86 +
  239.87 +int
  239.88 +getopt_long_only (argc, argv, options, long_options, opt_index)
  239.89 +     int argc;
  239.90 +     char *const *argv;
  239.91 +     const char *options;
  239.92 +     const struct option *long_options;
  239.93 +     int *opt_index;
  239.94 +{
  239.95 +  return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
  239.96 +}
  239.97 +
  239.98 +
  239.99 +#endif	/* Not ELIDE_CODE.  */
 239.100 +
 239.101 +#ifdef TEST
 239.102 +
 239.103 +#include <stdio.h>
 239.104 +
 239.105 +int
 239.106 +main (argc, argv)
 239.107 +     int argc;
 239.108 +     char **argv;
 239.109 +{
 239.110 +  int c;
 239.111 +  int digit_optind = 0;
 239.112 +
 239.113 +  while (1)
 239.114 +    {
 239.115 +      int this_option_optind = optind ? optind : 1;
 239.116 +      int option_index = 0;
 239.117 +      static struct option long_options[] =
 239.118 +      {
 239.119 +	{"add", 1, 0, 0},
 239.120 +	{"append", 0, 0, 0},
 239.121 +	{"delete", 1, 0, 0},
 239.122 +	{"verbose", 0, 0, 0},
 239.123 +	{"create", 0, 0, 0},
 239.124 +	{"file", 1, 0, 0},
 239.125 +	{0, 0, 0, 0}
 239.126 +      };
 239.127 +
 239.128 +      c = getopt_long (argc, argv, "abc:d:0123456789",
 239.129 +		       long_options, &option_index);
 239.130 +      if (c == -1)
 239.131 +	break;
 239.132 +
 239.133 +      switch (c)
 239.134 +	{
 239.135 +	case 0:
 239.136 +	  printf ("option %s", long_options[option_index].name);
 239.137 +	  if (optarg)
 239.138 +	    printf (" with arg %s", optarg);
 239.139 +	  printf ("\n");
 239.140 +	  break;
 239.141 +
 239.142 +	case '0':
 239.143 +	case '1':
 239.144 +	case '2':
 239.145 +	case '3':
 239.146 +	case '4':
 239.147 +	case '5':
 239.148 +	case '6':
 239.149 +	case '7':
 239.150 +	case '8':
 239.151 +	case '9':
 239.152 +	  if (digit_optind != 0 && digit_optind != this_option_optind)
 239.153 +	    printf ("digits occur in two different argv-elements.\n");
 239.154 +	  digit_optind = this_option_optind;
 239.155 +	  printf ("option %c\n", c);
 239.156 +	  break;
 239.157 +
 239.158 +	case 'a':
 239.159 +	  printf ("option a\n");
 239.160 +	  break;
 239.161 +
 239.162 +	case 'b':
 239.163 +	  printf ("option b\n");
 239.164 +	  break;
 239.165 +
 239.166 +	case 'c':
 239.167 +	  printf ("option c with value `%s'\n", optarg);
 239.168 +	  break;
 239.169 +
 239.170 +	case 'd':
 239.171 +	  printf ("option d with value `%s'\n", optarg);
 239.172 +	  break;
 239.173 +
 239.174 +	case '?':
 239.175 +	  break;
 239.176 +
 239.177 +	default:
 239.178 +	  printf ("?? getopt returned character code 0%o ??\n", c);
 239.179 +	}
 239.180 +    }
 239.181 +
 239.182 +  if (optind < argc)
 239.183 +    {
 239.184 +      printf ("non-option ARGV-elements: ");
 239.185 +      while (optind < argc)
 239.186 +	printf ("%s ", argv[optind++]);
 239.187 +      printf ("\n");
 239.188 +    }
 239.189 +
 239.190 +  exit (0);
 239.191 +}
 239.192 +
 239.193 +#endif /* TEST */
   240.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   240.2 +++ b/src/version.h	Sat Mar 03 10:31:27 2012 -0600
   240.3 @@ -0,0 +1,66 @@
   240.4 +#ifndef VBA_VERSION_H
   240.5 +#define VBA_VERSION_H
   240.6 +
   240.7 +#if _MSC_VER > 1000
   240.8 +#pragma once
   240.9 +#endif // _MSC_VER > 1000
  240.10 +
  240.11 +#define STRINGIZE_VALUE(X) _Py_STRINGIZE2(X)
  240.12 +#define _Py_STRINGIZE(X) _Py_STRINGIZE1((X))
  240.13 +#define _Py_STRINGIZE1(X) _Py_STRINGIZE2 ## X
  240.14 +#define _Py_STRINGIZE2(X) #X
  240.15 +//re: http://72.14.203.104/search?q=cache:HG-okth5NGkJ:mail.python.org/pipermail/python-checkins/2002-November/030704.html+_msc_ver+compiler+version+string&hl=en&gl=us&ct=clnk&cd=5
  240.16 +
  240.17 +#if defined(_MSC_VER)
  240.18 +#	define VBA_COMPILER ""
  240.19 +#	define VBA_COMPILER_DETAIL " msvc " _Py_STRINGIZE(_MSC_VER)
  240.20 +#else
  240.21 +// TODO: make for others compilers
  240.22 +#	define VBA_COMPILER ""
  240.23 +#	define VBA_COMPILER_DETAIL ""
  240.24 +#endif
  240.25 +
  240.26 +#define VBA_NAME "VBA-RR"
  240.27 +#define VBA_RR_MAJOR_VERSION_NO 23
  240.28 +#define VBA_RR_MINOR_VERSION_NO 5
  240.29 +
  240.30 +#if !defined(_DEBUG) && (defined(WIN32) || defined(RC_INVOKED))
  240.31 +#	include "../win32/userconfig/svnrev.h"
  240.32 +#endif
  240.33 +#
  240.34 +#ifndef SVN_REV
  240.35 +#	define SVN_REV 0
  240.36 +#endif
  240.37 +
  240.38 +#ifndef SVN_REV_STR
  240.39 +#	if SVN_REV > 0
  240.40 +#		define SVN_REV_STR STRINGIZE_VALUE(SVN_REV)
  240.41 +#	else
  240.42 +#		define define SVN_REV_STR ""
  240.43 +#	endif
  240.44 +#endif
  240.45 +
  240.46 +#ifdef _DEBUG
  240.47 +#	define VBA_SUBVERSION_STRING " DEBUG"
  240.48 +#	define VBA_BUILDTYPE_STRING  "Debug"
  240.49 +#elif defined(PUBLIC_RELEASE)
  240.50 +#	define VBA_SUBVERSION_STRING ""
  240.51 +#	define VBA_BUILDTYPE_STRING  "Release"
  240.52 +#else // interim
  240.53 +#	define VBA_SUBVERSION_STRING " svn" SVN_REV_STR
  240.54 +#	define VBA_BUILDTYPE_STRING  "Interim"
  240.55 +#endif
  240.56 +
  240.57 +#define VBA_FEATURE_STRING ""
  240.58 +
  240.59 +#if VBA_RR_MINOR_VERSION_NO > 0
  240.60 +#	define VBA_RR_VERSION_NO VBA_RR_MAJOR_VERSION_NO ## . ## VBA_RR_MINOR_VERSION_NO
  240.61 +#else
  240.62 +#	define VBA_RR_VERSION_NO VBA_RR_MAJOR_VERSION_NO
  240.63 +#endif
  240.64 +
  240.65 +#define VBA_VERSION_STRING "v" STRINGIZE_VALUE(VBA_RR_VERSION_NO) VBA_SUBVERSION_STRING VBA_FEATURE_STRING VBA_COMPILER
  240.66 +#define VBA_NAME_AND_VERSION VBA_NAME " " VBA_VERSION_STRING
  240.67 +#define VBA_RR_SITE "http://code.google.com/p/vba-rerecording/"
  240.68 +
  240.69 +#endif // !VBA_VERSION_H
   241.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   241.2 +++ b/src/win32/.cvsignore	Sat Mar 03 10:31:27 2012 -0600
   241.3 @@ -0,0 +1,1 @@
   241.4 +vba.aps
   242.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   242.2 +++ b/src/win32/7zip/7z/7zip_2005.vcproj	Sat Mar 03 10:31:27 2012 -0600
   242.3 @@ -0,0 +1,4058 @@
   242.4 +<?xml version="1.0" encoding="Windows-1252"?>
   242.5 +<VisualStudioProject
   242.6 +	ProjectType="Visual C++"
   242.7 +	Version="8.00"
   242.8 +	Name="wlib7zip"
   242.9 +	ProjectGUID="{5646C572-A578-49F8-9DA9-3E00A8CBFE3F}"
  242.10 +	RootNamespace="gens"
  242.11 +	>
  242.12 +	<Platforms>
  242.13 +		<Platform
  242.14 +			Name="Win32"
  242.15 +		/>
  242.16 +	</Platforms>
  242.17 +	<ToolFiles>
  242.18 +		<DefaultToolFile
  242.19 +			FileName="masm.rules"
  242.20 +		/>
  242.21 +	</ToolFiles>
  242.22 +	<Configurations>
  242.23 +		<Configuration
  242.24 +			Name="Release|Win32"
  242.25 +			OutputDirectory="$(SolutionDir)\.VS2005\$(ConfigurationName)\$(PlatformName)\$(ProjectName)"
  242.26 +			IntermediateDirectory="$(SolutionDir)\.VS2005\$(ConfigurationName)\$(PlatformName)\$(ProjectName)"
  242.27 +			ConfigurationType="4"
  242.28 +			UseOfMFC="0"
  242.29 +			ATLMinimizesCRunTimeLibraryUsage="false"
  242.30 +			WholeProgramOptimization="1"
  242.31 +			>
  242.32 +			<Tool
  242.33 +				Name="VCPreBuildEventTool"
  242.34 +			/>
  242.35 +			<Tool
  242.36 +				Name="VCCustomBuildTool"
  242.37 +			/>
  242.38 +			<Tool
  242.39 +				Name="MASM"
  242.40 +			/>
  242.41 +			<Tool
  242.42 +				Name="VCXMLDataGeneratorTool"
  242.43 +			/>
  242.44 +			<Tool
  242.45 +				Name="VCWebServiceProxyGeneratorTool"
  242.46 +			/>
  242.47 +			<Tool
  242.48 +				Name="VCMIDLTool"
  242.49 +				PreprocessorDefinitions="NDEBUG"
  242.50 +				MkTypLibCompatible="true"
  242.51 +				SuppressStartupBanner="true"
  242.52 +				TargetEnvironment="1"
  242.53 +				TypeLibraryName=".\Release/gens.tlb"
  242.54 +				HeaderFileName=""
  242.55 +			/>
  242.56 +			<Tool
  242.57 +				Name="VCCLCompilerTool"
  242.58 +				Optimization="3"
  242.59 +				InlineFunctionExpansion="2"
  242.60 +				EnableIntrinsicFunctions="true"
  242.61 +				FavorSizeOrSpeed="1"
  242.62 +				OmitFramePointers="true"
  242.63 +				EnableFiberSafeOptimizations="true"
  242.64 +				WholeProgramOptimization="true"
  242.65 +				AdditionalIncludeDirectories="CPP"
  242.66 +				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;EXTRACT_ONLY;_NO_CRYPTO"
  242.67 +				StringPooling="true"
  242.68 +				ExceptionHandling="1"
  242.69 +				RuntimeLibrary="0"
  242.70 +				UsePrecompiledHeader="2"
  242.71 +				PrecompiledHeaderFile="$(IntDir)\7z.pch"
  242.72 +				AssemblerListingLocation="$(IntDir)\"
  242.73 +				ObjectFile="$(IntDir)\"
  242.74 +				ProgramDataBaseFileName="$(IntDir)\vc80.pdb"
  242.75 +				WarningLevel="3"
  242.76 +				SuppressStartupBanner="true"
  242.77 +				DebugInformationFormat="3"
  242.78 +				OmitDefaultLibName="true"
  242.79 +			/>
  242.80 +			<Tool
  242.81 +				Name="VCManagedResourceCompilerTool"
  242.82 +			/>
  242.83 +			<Tool
  242.84 +				Name="VCResourceCompilerTool"
  242.85 +				PreprocessorDefinitions="NDEBUG"
  242.86 +			/>
  242.87 +			<Tool
  242.88 +				Name="VCPreLinkEventTool"
  242.89 +			/>
  242.90 +			<Tool
  242.91 +				Name="VCLibrarianTool"
  242.92 +				AdditionalOptions=" /LTCG"
  242.93 +			/>
  242.94 +			<Tool
  242.95 +				Name="VCALinkTool"
  242.96 +			/>
  242.97 +			<Tool
  242.98 +				Name="VCXDCMakeTool"
  242.99 +			/>
 242.100 +			<Tool
 242.101 +				Name="VCBscMakeTool"
 242.102 +			/>
 242.103 +			<Tool
 242.104 +				Name="VCFxCopTool"
 242.105 +			/>
 242.106 +			<Tool
 242.107 +				Name="VCPostBuildEventTool"
 242.108 +			/>
 242.109 +		</Configuration>
 242.110 +		<Configuration
 242.111 +			Name="Debug|Win32"
 242.112 +			OutputDirectory="$(SolutionDir)\.VS2005\$(ConfigurationName)\$(PlatformName)\$(ProjectName)"
 242.113 +			IntermediateDirectory="$(SolutionDir)\.VS2005\$(ConfigurationName)\$(PlatformName)\$(ProjectName)"
 242.114 +			ConfigurationType="4"
 242.115 +			UseOfMFC="0"
 242.116 +			ATLMinimizesCRunTimeLibraryUsage="false"
 242.117 +			>
 242.118 +			<Tool
 242.119 +				Name="VCPreBuildEventTool"
 242.120 +				CommandLine=""
 242.121 +			/>
 242.122 +			<Tool
 242.123 +				Name="VCCustomBuildTool"
 242.124 +				CommandLine=""
 242.125 +			/>
 242.126 +			<Tool
 242.127 +				Name="MASM"
 242.128 +			/>
 242.129 +			<Tool
 242.130 +				Name="VCXMLDataGeneratorTool"
 242.131 +			/>
 242.132 +			<Tool
 242.133 +				Name="VCWebServiceProxyGeneratorTool"
 242.134 +			/>
 242.135 +			<Tool
 242.136 +				Name="VCMIDLTool"
 242.137 +				PreprocessorDefinitions="NDEBUG"
 242.138 +				MkTypLibCompatible="true"
 242.139 +				SuppressStartupBanner="true"
 242.140 +				TargetEnvironment="1"
 242.141 +				TypeLibraryName=".\Release/gens.tlb"
 242.142 +				HeaderFileName=""
 242.143 +			/>
 242.144 +			<Tool
 242.145 +				Name="VCCLCompilerTool"
 242.146 +				Optimization="0"
 242.147 +				InlineFunctionExpansion="0"
 242.148 +				EnableIntrinsicFunctions="false"
 242.149 +				AdditionalIncludeDirectories="CPP"
 242.150 +				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;EXTRACT_ONLY;_NO_CRYPTO"
 242.151 +				StringPooling="false"
 242.152 +				ExceptionHandling="1"
 242.153 +				BasicRuntimeChecks="3"
 242.154 +				SmallerTypeCheck="true"
 242.155 +				RuntimeLibrary="0"
 242.156 +				EnableFunctionLevelLinking="false"
 242.157 +				UsePrecompiledHeader="2"
 242.158 +				PrecompiledHeaderFile="$(IntDir)\7z.pch"
 242.159 +				AssemblerListingLocation="$(IntDir)\"
 242.160 +				ObjectFile="$(IntDir)\"
 242.161 +				ProgramDataBaseFileName="$(IntDir)\vc80.pdb"
 242.162 +				WarningLevel="3"
 242.163 +				SuppressStartupBanner="true"
 242.164 +				DebugInformationFormat="3"
 242.165 +				OmitDefaultLibName="true"
 242.166 +			/>
 242.167 +			<Tool
 242.168 +				Name="VCManagedResourceCompilerTool"
 242.169 +			/>
 242.170 +			<Tool
 242.171 +				Name="VCResourceCompilerTool"
 242.172 +				PreprocessorDefinitions="NDEBUG"
 242.173 +			/>
 242.174 +			<Tool
 242.175 +				Name="VCPreLinkEventTool"
 242.176 +			/>
 242.177 +			<Tool
 242.178 +				Name="VCLibrarianTool"
 242.179 +			/>
 242.180 +			<Tool
 242.181 +				Name="VCALinkTool"
 242.182 +			/>
 242.183 +			<Tool
 242.184 +				Name="VCXDCMakeTool"
 242.185 +			/>
 242.186 +			<Tool
 242.187 +				Name="VCBscMakeTool"
 242.188 +			/>
 242.189 +			<Tool
 242.190 +				Name="VCFxCopTool"
 242.191 +			/>
 242.192 +			<Tool
 242.193 +				Name="VCPostBuildEventTool"
 242.194 +			/>
 242.195 +		</Configuration>
 242.196 +	</Configurations>
 242.197 +	<References>
 242.198 +	</References>
 242.199 +	<Files>
 242.200 +		<Filter
 242.201 +			Name="7zip"
 242.202 +			>
 242.203 +			<File
 242.204 +				RelativePath=".\CPP\7zip\Common\FilterCoder.cpp"
 242.205 +				>
 242.206 +				<FileConfiguration
 242.207 +					Name="Release|Win32"
 242.208 +					>
 242.209 +					<Tool
 242.210 +						Name="VCCLCompilerTool"
 242.211 +						UsePrecompiledHeader="2"
 242.212 +					/>
 242.213 +				</FileConfiguration>
 242.214 +				<FileConfiguration
 242.215 +					Name="Debug|Win32"
 242.216 +					>
 242.217 +					<Tool
 242.218 +						Name="VCCLCompilerTool"
 242.219 +						UsePrecompiledHeader="2"
 242.220 +					/>
 242.221 +				</FileConfiguration>
 242.222 +			</File>
 242.223 +			<File
 242.224 +				RelativePath=".\CPP\7zip\Common\InBuffer.cpp"
 242.225 +				>
 242.226 +				<FileConfiguration
 242.227 +					Name="Release|Win32"
 242.228 +					>
 242.229 +					<Tool
 242.230 +						Name="VCCLCompilerTool"
 242.231 +						UsePrecompiledHeader="2"
 242.232 +					/>
 242.233 +				</FileConfiguration>
 242.234 +				<FileConfiguration
 242.235 +					Name="Debug|Win32"
 242.236 +					>
 242.237 +					<Tool
 242.238 +						Name="VCCLCompilerTool"
 242.239 +						UsePrecompiledHeader="2"
 242.240 +					/>
 242.241 +				</FileConfiguration>
 242.242 +			</File>
 242.243 +			<File
 242.244 +				RelativePath=".\CPP\7zip\Common\InOutTempBuffer.cpp"
 242.245 +				>
 242.246 +				<FileConfiguration
 242.247 +					Name="Release|Win32"
 242.248 +					>
 242.249 +					<Tool
 242.250 +						Name="VCCLCompilerTool"
 242.251 +						UsePrecompiledHeader="2"
 242.252 +					/>
 242.253 +				</FileConfiguration>
 242.254 +				<FileConfiguration
 242.255 +					Name="Debug|Win32"
 242.256 +					>
 242.257 +					<Tool
 242.258 +						Name="VCCLCompilerTool"
 242.259 +						UsePrecompiledHeader="2"
 242.260 +					/>
 242.261 +				</FileConfiguration>
 242.262 +			</File>
 242.263 +			<File
 242.264 +				RelativePath=".\CPP\7zip\Common\LimitedStreams.cpp"
 242.265 +				>
 242.266 +				<FileConfiguration
 242.267 +					Name="Release|Win32"
 242.268 +					>
 242.269 +					<Tool
 242.270 +						Name="VCCLCompilerTool"
 242.271 +						UsePrecompiledHeader="2"
 242.272 +					/>
 242.273 +				</FileConfiguration>
 242.274 +				<FileConfiguration
 242.275 +					Name="Debug|Win32"
 242.276 +					>
 242.277 +					<Tool
 242.278 +						Name="VCCLCompilerTool"
 242.279 +						UsePrecompiledHeader="2"
 242.280 +					/>
 242.281 +				</FileConfiguration>
 242.282 +			</File>
 242.283 +			<File
 242.284 +				RelativePath=".\CPP\7zip\Common\LockedStream.cpp"
 242.285 +				>
 242.286 +				<FileConfiguration
 242.287 +					Name="Release|Win32"
 242.288 +					>
 242.289 +					<Tool
 242.290 +						Name="VCCLCompilerTool"
 242.291 +						UsePrecompiledHeader="2"
 242.292 +					/>
 242.293 +				</FileConfiguration>
 242.294 +				<FileConfiguration
 242.295 +					Name="Debug|Win32"
 242.296 +					>
 242.297 +					<Tool
 242.298 +						Name="VCCLCompilerTool"
 242.299 +						UsePrecompiledHeader="2"
 242.300 +					/>
 242.301 +				</FileConfiguration>
 242.302 +			</File>
 242.303 +			<File
 242.304 +				RelativePath=".\CPP\7zip\Common\MemBlocks.cpp"
 242.305 +				>
 242.306 +				<FileConfiguration
 242.307 +					Name="Release|Win32"
 242.308 +					>
 242.309 +					<Tool
 242.310 +						Name="VCCLCompilerTool"
 242.311 +						UsePrecompiledHeader="2"
 242.312 +					/>
 242.313 +				</FileConfiguration>
 242.314 +				<FileConfiguration
 242.315 +					Name="Debug|Win32"
 242.316 +					>
 242.317 +					<Tool
 242.318 +						Name="VCCLCompilerTool"
 242.319 +						UsePrecompiledHeader="2"
 242.320 +					/>
 242.321 +				</FileConfiguration>
 242.322 +			</File>
 242.323 +			<File
 242.324 +				RelativePath=".\CPP\7zip\Common\MethodId.cpp"
 242.325 +				>
 242.326 +				<FileConfiguration
 242.327 +					Name="Release|Win32"
 242.328 +					>
 242.329 +					<Tool
 242.330 +						Name="VCCLCompilerTool"
 242.331 +						UsePrecompiledHeader="2"
 242.332 +					/>
 242.333 +				</FileConfiguration>
 242.334 +				<FileConfiguration
 242.335 +					Name="Debug|Win32"
 242.336 +					>
 242.337 +					<Tool
 242.338 +						Name="VCCLCompilerTool"
 242.339 +						UsePrecompiledHeader="2"
 242.340 +					/>
 242.341 +				</FileConfiguration>
 242.342 +			</File>
 242.343 +			<File
 242.344 +				RelativePath=".\CPP\7zip\Common\MethodProps.cpp"
 242.345 +				>
 242.346 +				<FileConfiguration
 242.347 +					Name="Release|Win32"
 242.348 +					>
 242.349 +					<Tool
 242.350 +						Name="VCCLCompilerTool"
 242.351 +						UsePrecompiledHeader="2"
 242.352 +					/>
 242.353 +				</FileConfiguration>
 242.354 +				<FileConfiguration
 242.355 +					Name="Debug|Win32"
 242.356 +					>
 242.357 +					<Tool
 242.358 +						Name="VCCLCompilerTool"
 242.359 +						UsePrecompiledHeader="2"
 242.360 +					/>
 242.361 +				</FileConfiguration>
 242.362 +			</File>
 242.363 +			<File
 242.364 +				RelativePath=".\CPP\7zip\Common\OffsetStream.cpp"
 242.365 +				>
 242.366 +				<FileConfiguration
 242.367 +					Name="Release|Win32"
 242.368 +					>
 242.369 +					<Tool
 242.370 +						Name="VCCLCompilerTool"
 242.371 +						UsePrecompiledHeader="2"
 242.372 +					/>
 242.373 +				</FileConfiguration>
 242.374 +				<FileConfiguration
 242.375 +					Name="Debug|Win32"
 242.376 +					>
 242.377 +					<Tool
 242.378 +						Name="VCCLCompilerTool"
 242.379 +						UsePrecompiledHeader="2"
 242.380 +					/>
 242.381 +				</FileConfiguration>
 242.382 +			</File>
 242.383 +			<File
 242.384 +				RelativePath=".\CPP\7zip\Common\OutBuffer.cpp"
 242.385 +				>
 242.386 +				<FileConfiguration
 242.387 +					Name="Release|Win32"
 242.388 +					>
 242.389 +					<Tool
 242.390 +						Name="VCCLCompilerTool"
 242.391 +						UsePrecompiledHeader="2"
 242.392 +					/>
 242.393 +				</FileConfiguration>
 242.394 +				<FileConfiguration
 242.395 +					Name="Debug|Win32"
 242.396 +					>
 242.397 +					<Tool
 242.398 +						Name="VCCLCompilerTool"
 242.399 +						UsePrecompiledHeader="2"
 242.400 +					/>
 242.401 +				</FileConfiguration>
 242.402 +			</File>
 242.403 +			<File
 242.404 +				RelativePath=".\CPP\7zip\Common\OutMemStream.cpp"
 242.405 +				>
 242.406 +				<FileConfiguration
 242.407 +					Name="Release|Win32"
 242.408 +					>
 242.409 +					<Tool
 242.410 +						Name="VCCLCompilerTool"
 242.411 +						UsePrecompiledHeader="2"
 242.412 +					/>
 242.413 +				</FileConfiguration>
 242.414 +				<FileConfiguration
 242.415 +					Name="Debug|Win32"
 242.416 +					>
 242.417 +					<Tool
 242.418 +						Name="VCCLCompilerTool"
 242.419 +						UsePrecompiledHeader="2"
 242.420 +					/>
 242.421 +				</FileConfiguration>
 242.422 +			</File>
 242.423 +			<File
 242.424 +				RelativePath=".\CPP\7zip\Common\ProgressMt.cpp"
 242.425 +				>
 242.426 +				<FileConfiguration
 242.427 +					Name="Release|Win32"
 242.428 +					>
 242.429 +					<Tool
 242.430 +						Name="VCCLCompilerTool"
 242.431 +						UsePrecompiledHeader="2"
 242.432 +					/>
 242.433 +				</FileConfiguration>
 242.434 +				<FileConfiguration
 242.435 +					Name="Debug|Win32"
 242.436 +					>
 242.437 +					<Tool
 242.438 +						Name="VCCLCompilerTool"
 242.439 +						UsePrecompiledHeader="2"
 242.440 +					/>
 242.441 +				</FileConfiguration>
 242.442 +			</File>
 242.443 +			<File
 242.444 +				RelativePath=".\CPP\7zip\Common\ProgressUtils.cpp"
 242.445 +				>
 242.446 +				<FileConfiguration
 242.447 +					Name="Release|Win32"
 242.448 +					>
 242.449 +					<Tool
 242.450 +						Name="VCCLCompilerTool"
 242.451 +						UsePrecompiledHeader="2"
 242.452 +					/>
 242.453 +				</FileConfiguration>
 242.454 +				<FileConfiguration
 242.455 +					Name="Debug|Win32"
 242.456 +					>
 242.457 +					<Tool
 242.458 +						Name="VCCLCompilerTool"
 242.459 +						UsePrecompiledHeader="2"
 242.460 +					/>
 242.461 +				</FileConfiguration>
 242.462 +			</File>
 242.463 +			<File
 242.464 +				RelativePath=".\CPP\7zip\Common\StreamBinder.cpp"
 242.465 +				>
 242.466 +				<FileConfiguration
 242.467 +					Name="Release|Win32"
 242.468 +					>
 242.469 +					<Tool
 242.470 +						Name="VCCLCompilerTool"
 242.471 +						UsePrecompiledHeader="2"
 242.472 +					/>
 242.473 +				</FileConfiguration>
 242.474 +				<FileConfiguration
 242.475 +					Name="Debug|Win32"
 242.476 +					>
 242.477 +					<Tool
 242.478 +						Name="VCCLCompilerTool"
 242.479 +						UsePrecompiledHeader="2"
 242.480 +					/>
 242.481 +				</FileConfiguration>
 242.482 +			</File>
 242.483 +			<File
 242.484 +				RelativePath=".\CPP\7zip\Common\StreamObjects.cpp"
 242.485 +				>
 242.486 +				<FileConfiguration
 242.487 +					Name="Release|Win32"
 242.488 +					>
 242.489 +					<Tool
 242.490 +						Name="VCCLCompilerTool"
 242.491 +						UsePrecompiledHeader="2"
 242.492 +					/>
 242.493 +				</FileConfiguration>
 242.494 +				<FileConfiguration
 242.495 +					Name="Debug|Win32"
 242.496 +					>
 242.497 +					<Tool
 242.498 +						Name="VCCLCompilerTool"
 242.499 +						UsePrecompiledHeader="2"
 242.500 +					/>
 242.501 +				</FileConfiguration>
 242.502 +			</File>
 242.503 +			<File
 242.504 +				RelativePath=".\CPP\7zip\Common\StreamUtils.cpp"
 242.505 +				>
 242.506 +				<FileConfiguration
 242.507 +					Name="Release|Win32"
 242.508 +					>
 242.509 +					<Tool
 242.510 +						Name="VCCLCompilerTool"
 242.511 +						UsePrecompiledHeader="2"
 242.512 +					/>
 242.513 +				</FileConfiguration>
 242.514 +				<FileConfiguration
 242.515 +					Name="Debug|Win32"
 242.516 +					>
 242.517 +					<Tool
 242.518 +						Name="VCCLCompilerTool"
 242.519 +						UsePrecompiledHeader="2"
 242.520 +					/>
 242.521 +				</FileConfiguration>
 242.522 +			</File>
 242.523 +			<File
 242.524 +				RelativePath=".\CPP\7zip\Common\VirtThread.cpp"
 242.525 +				>
 242.526 +				<FileConfiguration
 242.527 +					Name="Release|Win32"
 242.528 +					>
 242.529 +					<Tool
 242.530 +						Name="VCCLCompilerTool"
 242.531 +						UsePrecompiledHeader="2"
 242.532 +					/>
 242.533 +				</FileConfiguration>
 242.534 +				<FileConfiguration
 242.535 +					Name="Debug|Win32"
 242.536 +					>
 242.537 +					<Tool
 242.538 +						Name="VCCLCompilerTool"
 242.539 +						UsePrecompiledHeader="2"
 242.540 +					/>
 242.541 +				</FileConfiguration>
 242.542 +			</File>
 242.543 +		</Filter>
 242.544 +		<Filter
 242.545 +			Name="Windows"
 242.546 +			>
 242.547 +			<File
 242.548 +				RelativePath=".\CPP\Windows\FileDir.cpp"
 242.549 +				>
 242.550 +				<FileConfiguration
 242.551 +					Name="Release|Win32"
 242.552 +					>
 242.553 +					<Tool
 242.554 +						Name="VCCLCompilerTool"
 242.555 +						UsePrecompiledHeader="2"
 242.556 +					/>
 242.557 +				</FileConfiguration>
 242.558 +				<FileConfiguration
 242.559 +					Name="Debug|Win32"
 242.560 +					>
 242.561 +					<Tool
 242.562 +						Name="VCCLCompilerTool"
 242.563 +						UsePrecompiledHeader="2"
 242.564 +					/>
 242.565 +				</FileConfiguration>
 242.566 +			</File>
 242.567 +			<File
 242.568 +				RelativePath=".\CPP\Windows\FileFind.cpp"
 242.569 +				>
 242.570 +				<FileConfiguration
 242.571 +					Name="Release|Win32"
 242.572 +					>
 242.573 +					<Tool
 242.574 +						Name="VCCLCompilerTool"
 242.575 +						UsePrecompiledHeader="2"
 242.576 +					/>
 242.577 +				</FileConfiguration>
 242.578 +				<FileConfiguration
 242.579 +					Name="Debug|Win32"
 242.580 +					>
 242.581 +					<Tool
 242.582 +						Name="VCCLCompilerTool"
 242.583 +						UsePrecompiledHeader="2"
 242.584 +					/>
 242.585 +				</FileConfiguration>
 242.586 +			</File>
 242.587 +			<File
 242.588 +				RelativePath=".\CPP\Windows\FileIO.cpp"
 242.589 +				>
 242.590 +				<FileConfiguration
 242.591 +					Name="Release|Win32"
 242.592 +					>
 242.593 +					<Tool
 242.594 +						Name="VCCLCompilerTool"
 242.595 +						UsePrecompiledHeader="2"
 242.596 +					/>
 242.597 +				</FileConfiguration>
 242.598 +				<FileConfiguration
 242.599 +					Name="Debug|Win32"
 242.600 +					>
 242.601 +					<Tool
 242.602 +						Name="VCCLCompilerTool"
 242.603 +						UsePrecompiledHeader="2"
 242.604 +					/>
 242.605 +				</FileConfiguration>
 242.606 +			</File>
 242.607 +			<File
 242.608 +				RelativePath=".\CPP\Windows\PropVariant.cpp"
 242.609 +				>
 242.610 +				<FileConfiguration
 242.611 +					Name="Release|Win32"
 242.612 +					>
 242.613 +					<Tool
 242.614 +						Name="VCCLCompilerTool"
 242.615 +						UsePrecompiledHeader="2"
 242.616 +					/>
 242.617 +				</FileConfiguration>
 242.618 +				<FileConfiguration
 242.619 +					Name="Debug|Win32"
 242.620 +					>
 242.621 +					<Tool
 242.622 +						Name="VCCLCompilerTool"
 242.623 +						UsePrecompiledHeader="2"
 242.624 +					/>
 242.625 +				</FileConfiguration>
 242.626 +			</File>
 242.627 +			<File
 242.628 +				RelativePath=".\CPP\Windows\Time.cpp"
 242.629 +				>
 242.630 +				<FileConfiguration
 242.631 +					Name="Release|Win32"
 242.632 +					>
 242.633 +					<Tool
 242.634 +						Name="VCCLCompilerTool"
 242.635 +						UsePrecompiledHeader="2"
 242.636 +					/>
 242.637 +				</FileConfiguration>
 242.638 +				<FileConfiguration
 242.639 +					Name="Debug|Win32"
 242.640 +					>
 242.641 +					<Tool
 242.642 +						Name="VCCLCompilerTool"
 242.643 +						UsePrecompiledHeader="2"
 242.644 +					/>
 242.645 +				</FileConfiguration>
 242.646 +			</File>
 242.647 +		</Filter>
 242.648 +		<Filter
 242.649 +			Name="Archive"
 242.650 +			>
 242.651 +			<Filter
 242.652 +				Name="7z"
 242.653 +				>
 242.654 +				<File
 242.655 +					RelativePath=".\CPP\7zip\Archive\7z\7zCompressionMode.cpp"
 242.656 +					>
 242.657 +					<FileConfiguration
 242.658 +						Name="Release|Win32"
 242.659 +						>
 242.660 +						<Tool
 242.661 +							Name="VCCLCompilerTool"
 242.662 +							UsePrecompiledHeader="2"
 242.663 +						/>
 242.664 +					</FileConfiguration>
 242.665 +					<FileConfiguration
 242.666 +						Name="Debug|Win32"
 242.667 +						>
 242.668 +						<Tool
 242.669 +							Name="VCCLCompilerTool"
 242.670 +							UsePrecompiledHeader="2"
 242.671 +						/>
 242.672 +					</FileConfiguration>
 242.673 +				</File>
 242.674 +				<File
 242.675 +					RelativePath=".\CPP\7zip\Archive\7z\7zDecode.cpp"
 242.676 +					>
 242.677 +					<FileConfiguration
 242.678 +						Name="Release|Win32"
 242.679 +						>
 242.680 +						<Tool
 242.681 +							Name="VCCLCompilerTool"
 242.682 +							UsePrecompiledHeader="2"
 242.683 +						/>
 242.684 +					</FileConfiguration>
 242.685 +					<FileConfiguration
 242.686 +						Name="Debug|Win32"
 242.687 +						>
 242.688 +						<Tool
 242.689 +							Name="VCCLCompilerTool"
 242.690 +							UsePrecompiledHeader="2"
 242.691 +						/>
 242.692 +					</FileConfiguration>
 242.693 +				</File>
 242.694 +				<File
 242.695 +					RelativePath=".\CPP\7zip\Archive\7z\7zExtract.cpp"
 242.696 +					>
 242.697 +					<FileConfiguration
 242.698 +						Name="Release|Win32"
 242.699 +						>
 242.700 +						<Tool
 242.701 +							Name="VCCLCompilerTool"
 242.702 +							UsePrecompiledHeader="2"
 242.703 +						/>
 242.704 +					</FileConfiguration>
 242.705 +					<FileConfiguration
 242.706 +						Name="Debug|Win32"
 242.707 +						>
 242.708 +						<Tool
 242.709 +							Name="VCCLCompilerTool"
 242.710 +							UsePrecompiledHeader="2"
 242.711 +						/>
 242.712 +					</FileConfiguration>
 242.713 +				</File>
 242.714 +				<File
 242.715 +					RelativePath=".\CPP\7zip\Archive\7z\7zFolderInStream.cpp"
 242.716 +					>
 242.717 +					<FileConfiguration
 242.718 +						Name="Release|Win32"
 242.719 +						>
 242.720 +						<Tool
 242.721 +							Name="VCCLCompilerTool"
 242.722 +							UsePrecompiledHeader="2"
 242.723 +						/>
 242.724 +					</FileConfiguration>
 242.725 +					<FileConfiguration
 242.726 +						Name="Debug|Win32"
 242.727 +						>
 242.728 +						<Tool
 242.729 +							Name="VCCLCompilerTool"
 242.730 +							UsePrecompiledHeader="2"
 242.731 +						/>
 242.732 +					</FileConfiguration>
 242.733 +				</File>
 242.734 +				<File
 242.735 +					RelativePath=".\CPP\7zip\Archive\7z\7zFolderOutStream.cpp"
 242.736 +					>
 242.737 +					<FileConfiguration
 242.738 +						Name="Release|Win32"
 242.739 +						>
 242.740 +						<Tool
 242.741 +							Name="VCCLCompilerTool"
 242.742 +							UsePrecompiledHeader="2"
 242.743 +						/>
 242.744 +					</FileConfiguration>
 242.745 +					<FileConfiguration
 242.746 +						Name="Debug|Win32"
 242.747 +						>
 242.748 +						<Tool
 242.749 +							Name="VCCLCompilerTool"
 242.750 +							UsePrecompiledHeader="2"
 242.751 +						/>
 242.752 +					</FileConfiguration>
 242.753 +				</File>
 242.754 +				<File
 242.755 +					RelativePath=".\CPP\7zip\Archive\7z\7zHandler.cpp"
 242.756 +					>
 242.757 +					<FileConfiguration
 242.758 +						Name="Release|Win32"
 242.759 +						>
 242.760 +						<Tool
 242.761 +							Name="VCCLCompilerTool"
 242.762 +							UsePrecompiledHeader="2"
 242.763 +						/>
 242.764 +					</FileConfiguration>
 242.765 +					<FileConfiguration
 242.766 +						Name="Debug|Win32"
 242.767 +						>
 242.768 +						<Tool
 242.769 +							Name="VCCLCompilerTool"
 242.770 +							UsePrecompiledHeader="2"
 242.771 +						/>
 242.772 +					</FileConfiguration>
 242.773 +				</File>
 242.774 +				<File
 242.775 +					RelativePath=".\CPP\7zip\Archive\7z\7zHeader.cpp"
 242.776 +					>
 242.777 +					<FileConfiguration
 242.778 +						Name="Release|Win32"
 242.779 +						>
 242.780 +						<Tool
 242.781 +							Name="VCCLCompilerTool"
 242.782 +							UsePrecompiledHeader="2"
 242.783 +						/>
 242.784 +					</FileConfiguration>
 242.785 +					<FileConfiguration
 242.786 +						Name="Debug|Win32"
 242.787 +						>
 242.788 +						<Tool
 242.789 +							Name="VCCLCompilerTool"
 242.790 +							UsePrecompiledHeader="2"
 242.791 +						/>
 242.792 +					</FileConfiguration>
 242.793 +				</File>
 242.794 +				<File
 242.795 +					RelativePath=".\CPP\7zip\Archive\7z\7zIn.cpp"
 242.796 +					>
 242.797 +					<FileConfiguration
 242.798 +						Name="Release|Win32"
 242.799 +						>
 242.800 +						<Tool
 242.801 +							Name="VCCLCompilerTool"
 242.802 +							UsePrecompiledHeader="2"
 242.803 +						/>
 242.804 +					</FileConfiguration>
 242.805 +					<FileConfiguration
 242.806 +						Name="Debug|Win32"
 242.807 +						>
 242.808 +						<Tool
 242.809 +							Name="VCCLCompilerTool"
 242.810 +							UsePrecompiledHeader="2"
 242.811 +						/>
 242.812 +					</FileConfiguration>
 242.813 +				</File>
 242.814 +				<File
 242.815 +					RelativePath=".\CPP\7zip\Archive\7z\7zProperties.cpp"
 242.816 +					>
 242.817 +					<FileConfiguration
 242.818 +						Name="Release|Win32"
 242.819 +						>
 242.820 +						<Tool
 242.821 +							Name="VCCLCompilerTool"
 242.822 +							UsePrecompiledHeader="2"
 242.823 +						/>
 242.824 +					</FileConfiguration>
 242.825 +					<FileConfiguration
 242.826 +						Name="Debug|Win32"
 242.827 +						>
 242.828 +						<Tool
 242.829 +							Name="VCCLCompilerTool"
 242.830 +							UsePrecompiledHeader="2"
 242.831 +						/>
 242.832 +					</FileConfiguration>
 242.833 +				</File>
 242.834 +				<File
 242.835 +					RelativePath=".\CPP\7zip\Archive\7z\7zSpecStream.cpp"
 242.836 +					>
 242.837 +					<FileConfiguration
 242.838 +						Name="Release|Win32"
 242.839 +						>
 242.840 +						<Tool
 242.841 +							Name="VCCLCompilerTool"
 242.842 +							UsePrecompiledHeader="2"
 242.843 +						/>
 242.844 +					</FileConfiguration>
 242.845 +					<FileConfiguration
 242.846 +						Name="Debug|Win32"
 242.847 +						>
 242.848 +						<Tool
 242.849 +							Name="VCCLCompilerTool"
 242.850 +							UsePrecompiledHeader="2"
 242.851 +						/>
 242.852 +					</FileConfiguration>
 242.853 +				</File>
 242.854 +			</Filter>
 242.855 +			<Filter
 242.856 +				Name="Rar"
 242.857 +				>
 242.858 +				<File
 242.859 +					RelativePath=".\CPP\7zip\Archive\Rar\RarHandler.cpp"
 242.860 +					>
 242.861 +					<FileConfiguration
 242.862 +						Name="Release|Win32"
 242.863 +						>
 242.864 +						<Tool
 242.865 +							Name="VCCLCompilerTool"
 242.866 +							UsePrecompiledHeader="2"
 242.867 +						/>
 242.868 +					</FileConfiguration>
 242.869 +					<FileConfiguration
 242.870 +						Name="Debug|Win32"
 242.871 +						>
 242.872 +						<Tool
 242.873 +							Name="VCCLCompilerTool"
 242.874 +							UsePrecompiledHeader="2"
 242.875 +						/>
 242.876 +					</FileConfiguration>
 242.877 +				</File>
 242.878 +				<File
 242.879 +					RelativePath=".\CPP\7zip\Archive\Rar\RarHeader.cpp"
 242.880 +					>
 242.881 +					<FileConfiguration
 242.882 +						Name="Release|Win32"
 242.883 +						>
 242.884 +						<Tool
 242.885 +							Name="VCCLCompilerTool"
 242.886 +							UsePrecompiledHeader="2"
 242.887 +						/>
 242.888 +					</FileConfiguration>
 242.889 +					<FileConfiguration
 242.890 +						Name="Debug|Win32"
 242.891 +						>
 242.892 +						<Tool
 242.893 +							Name="VCCLCompilerTool"
 242.894 +							UsePrecompiledHeader="2"
 242.895 +						/>
 242.896 +					</FileConfiguration>
 242.897 +				</File>
 242.898 +				<File
 242.899 +					RelativePath=".\CPP\7zip\Archive\Rar\RarIn.cpp"
 242.900 +					>
 242.901 +					<FileConfiguration
 242.902 +						Name="Release|Win32"
 242.903 +						>
 242.904 +						<Tool
 242.905 +							Name="VCCLCompilerTool"
 242.906 +							UsePrecompiledHeader="2"
 242.907 +						/>
 242.908 +					</FileConfiguration>
 242.909 +					<FileConfiguration
 242.910 +						Name="Debug|Win32"
 242.911 +						>
 242.912 +						<Tool
 242.913 +							Name="VCCLCompilerTool"
 242.914 +							UsePrecompiledHeader="2"
 242.915 +						/>
 242.916 +					</FileConfiguration>
 242.917 +				</File>
 242.918 +				<File
 242.919 +					RelativePath=".\CPP\7zip\Archive\Rar\RarItem.cpp"
 242.920 +					>
 242.921 +					<FileConfiguration
 242.922 +						Name="Release|Win32"
 242.923 +						>
 242.924 +						<Tool
 242.925 +							Name="VCCLCompilerTool"
 242.926 +							UsePrecompiledHeader="2"
 242.927 +						/>
 242.928 +					</FileConfiguration>
 242.929 +					<FileConfiguration
 242.930 +						Name="Debug|Win32"
 242.931 +						>
 242.932 +						<Tool
 242.933 +							Name="VCCLCompilerTool"
 242.934 +							UsePrecompiledHeader="2"
 242.935 +						/>
 242.936 +					</FileConfiguration>
 242.937 +				</File>
 242.938 +				<File
 242.939 +					RelativePath=".\CPP\7zip\Archive\Rar\RarVolumeInStream.cpp"
 242.940 +					>
 242.941 +					<FileConfiguration
 242.942 +						Name="Release|Win32"
 242.943 +						>
 242.944 +						<Tool
 242.945 +							Name="VCCLCompilerTool"
 242.946 +							UsePrecompiledHeader="2"
 242.947 +						/>
 242.948 +					</FileConfiguration>
 242.949 +					<FileConfiguration
 242.950 +						Name="Debug|Win32"
 242.951 +						>
 242.952 +						<Tool
 242.953 +							Name="VCCLCompilerTool"
 242.954 +							UsePrecompiledHeader="2"
 242.955 +						/>
 242.956 +					</FileConfiguration>
 242.957 +				</File>
 242.958 +			</Filter>
 242.959 +			<Filter
 242.960 +				Name="bz2"
 242.961 +				>
 242.962 +				<File
 242.963 +					RelativePath=".\CPP\7zip\Archive\BZip2\BZip2Handler.cpp"
 242.964 +					>
 242.965 +					<FileConfiguration
 242.966 +						Name="Release|Win32"
 242.967 +						>
 242.968 +						<Tool
 242.969 +							Name="VCCLCompilerTool"
 242.970 +							UsePrecompiledHeader="2"
 242.971 +						/>
 242.972 +					</FileConfiguration>
 242.973 +					<FileConfiguration
 242.974 +						Name="Debug|Win32"
 242.975 +						>
 242.976 +						<Tool
 242.977 +							Name="VCCLCompilerTool"
 242.978 +							UsePrecompiledHeader="2"
 242.979 +						/>
 242.980 +					</FileConfiguration>
 242.981 +				</File>
 242.982 +			</Filter>
 242.983 +			<Filter
 242.984 +				Name="Archive common"
 242.985 +				>
 242.986 +				<File
 242.987 +					RelativePath=".\CPP\7zip\Archive\Common\CoderMixer2.cpp"
 242.988 +					>
 242.989 +					<FileConfiguration
 242.990 +						Name="Release|Win32"
 242.991 +						>
 242.992 +						<Tool
 242.993 +							Name="VCCLCompilerTool"
 242.994 +							UsePrecompiledHeader="2"
 242.995 +						/>
 242.996 +					</FileConfiguration>
 242.997 +					<FileConfiguration
 242.998 +						Name="Debug|Win32"
 242.999 +						>
242.1000 +						<Tool
242.1001 +							Name="VCCLCompilerTool"
242.1002 +							UsePrecompiledHeader="2"
242.1003 +						/>
242.1004 +					</FileConfiguration>
242.1005 +				</File>
242.1006 +				<File
242.1007 +					RelativePath=".\CPP\7zip\Archive\Common\CoderMixer2MT.cpp"
242.1008 +					>
242.1009 +					<FileConfiguration
242.1010 +						Name="Release|Win32"
242.1011 +						>
242.1012 +						<Tool
242.1013 +							Name="VCCLCompilerTool"
242.1014 +							UsePrecompiledHeader="2"
242.1015 +						/>
242.1016 +					</FileConfiguration>
242.1017 +					<FileConfiguration
242.1018 +						Name="Debug|Win32"
242.1019 +						>
242.1020 +						<Tool
242.1021 +							Name="VCCLCompilerTool"
242.1022 +							UsePrecompiledHeader="2"
242.1023 +						/>
242.1024 +					</FileConfiguration>
242.1025 +				</File>
242.1026 +				<File
242.1027 +					RelativePath=".\CPP\7zip\Archive\Common\DummyOutStream.cpp"
242.1028 +					>
242.1029 +					<FileConfiguration
242.1030 +						Name="Release|Win32"
242.1031 +						>
242.1032 +						<Tool
242.1033 +							Name="VCCLCompilerTool"
242.1034 +							UsePrecompiledHeader="2"
242.1035 +						/>
242.1036 +					</FileConfiguration>
242.1037 +					<FileConfiguration
242.1038 +						Name="Debug|Win32"
242.1039 +						>
242.1040 +						<Tool
242.1041 +							Name="VCCLCompilerTool"
242.1042 +							UsePrecompiledHeader="2"
242.1043 +						/>
242.1044 +					</FileConfiguration>
242.1045 +				</File>
242.1046 +				<File
242.1047 +					RelativePath=".\CPP\7zip\Archive\Common\FindSignature.cpp"
242.1048 +					>
242.1049 +					<FileConfiguration
242.1050 +						Name="Release|Win32"
242.1051 +						>
242.1052 +						<Tool
242.1053 +							Name="VCCLCompilerTool"
242.1054 +							UsePrecompiledHeader="2"
242.1055 +						/>
242.1056 +					</FileConfiguration>
242.1057 +					<FileConfiguration
242.1058 +						Name="Debug|Win32"
242.1059 +						>
242.1060 +						<Tool
242.1061 +							Name="VCCLCompilerTool"
242.1062 +							UsePrecompiledHeader="2"
242.1063 +						/>
242.1064 +					</FileConfiguration>
242.1065 +				</File>
242.1066 +				<File
242.1067 +					RelativePath=".\CPP\7zip\Archive\Common\InStreamWithCRC.cpp"
242.1068 +					>
242.1069 +					<FileConfiguration
242.1070 +						Name="Release|Win32"
242.1071 +						>
242.1072 +						<Tool
242.1073 +							Name="VCCLCompilerTool"
242.1074 +							UsePrecompiledHeader="2"
242.1075 +						/>
242.1076 +					</FileConfiguration>
242.1077 +					<FileConfiguration
242.1078 +						Name="Debug|Win32"
242.1079 +						>
242.1080 +						<Tool
242.1081 +							Name="VCCLCompilerTool"
242.1082 +							UsePrecompiledHeader="2"
242.1083 +						/>
242.1084 +					</FileConfiguration>
242.1085 +				</File>
242.1086 +				<File
242.1087 +					RelativePath=".\CPP\7zip\Archive\Common\ItemNameUtils.cpp"
242.1088 +					>
242.1089 +					<FileConfiguration
242.1090 +						Name="Release|Win32"
242.1091 +						>
242.1092 +						<Tool
242.1093 +							Name="VCCLCompilerTool"
242.1094 +							UsePrecompiledHeader="2"
242.1095 +						/>
242.1096 +					</FileConfiguration>
242.1097 +					<FileConfiguration
242.1098 +						Name="Debug|Win32"
242.1099 +						>
242.1100 +						<Tool
242.1101 +							Name="VCCLCompilerTool"
242.1102 +							UsePrecompiledHeader="2"
242.1103 +						/>
242.1104 +					</FileConfiguration>
242.1105 +				</File>
242.1106 +				<File
242.1107 +					RelativePath=".\CPP\7zip\Archive\Common\MultiStream.cpp"
242.1108 +					>
242.1109 +					<FileConfiguration
242.1110 +						Name="Release|Win32"
242.1111 +						>
242.1112 +						<Tool
242.1113 +							Name="VCCLCompilerTool"
242.1114 +							UsePrecompiledHeader="2"
242.1115 +						/>
242.1116 +					</FileConfiguration>
242.1117 +					<FileConfiguration
242.1118 +						Name="Debug|Win32"
242.1119 +						>
242.1120 +						<Tool
242.1121 +							Name="VCCLCompilerTool"
242.1122 +							UsePrecompiledHeader="2"
242.1123 +						/>
242.1124 +					</FileConfiguration>
242.1125 +				</File>
242.1126 +				<File
242.1127 +					RelativePath=".\CPP\7zip\Archive\Common\OutStreamWithCRC.cpp"
242.1128 +					>
242.1129 +					<FileConfiguration
242.1130 +						Name="Release|Win32"
242.1131 +						>
242.1132 +						<Tool
242.1133 +							Name="VCCLCompilerTool"
242.1134 +							UsePrecompiledHeader="2"
242.1135 +						/>
242.1136 +					</FileConfiguration>
242.1137 +					<FileConfiguration
242.1138 +						Name="Debug|Win32"
242.1139 +						>
242.1140 +						<Tool
242.1141 +							Name="VCCLCompilerTool"
242.1142 +							UsePrecompiledHeader="2"
242.1143 +						/>
242.1144 +					</FileConfiguration>
242.1145 +				</File>
242.1146 +				<File
242.1147 +					RelativePath=".\CPP\7zip\Archive\Common\ParseProperties.cpp"
242.1148 +					>
242.1149 +					<FileConfiguration
242.1150 +						Name="Release|Win32"
242.1151 +						>
242.1152 +						<Tool
242.1153 +							Name="VCCLCompilerTool"
242.1154 +							UsePrecompiledHeader="2"
242.1155 +						/>
242.1156 +					</FileConfiguration>
242.1157 +					<FileConfiguration
242.1158 +						Name="Debug|Win32"
242.1159 +						>
242.1160 +						<Tool
242.1161 +							Name="VCCLCompilerTool"
242.1162 +							UsePrecompiledHeader="2"
242.1163 +						/>
242.1164 +					</FileConfiguration>
242.1165 +				</File>
242.1166 +			</Filter>
242.1167 +			<Filter
242.1168 +				Name="GZip"
242.1169 +				>
242.1170 +				<File
242.1171 +					RelativePath=".\CPP\7zip\Archive\GZip\GZipHandler.cpp"
242.1172 +					>
242.1173 +					<FileConfiguration
242.1174 +						Name="Release|Win32"
242.1175 +						>
242.1176 +						<Tool
242.1177 +							Name="VCCLCompilerTool"
242.1178 +							UsePrecompiledHeader="2"
242.1179 +						/>
242.1180 +					</FileConfiguration>
242.1181 +					<FileConfiguration
242.1182 +						Name="Debug|Win32"
242.1183 +						>
242.1184 +						<Tool
242.1185 +							Name="VCCLCompilerTool"
242.1186 +							UsePrecompiledHeader="2"
242.1187 +						/>
242.1188 +					</FileConfiguration>
242.1189 +				</File>
242.1190 +				<File
242.1191 +					RelativePath=".\CPP\7zip\Archive\GZip\GZipHeader.cpp"
242.1192 +					>
242.1193 +					<FileConfiguration
242.1194 +						Name="Release|Win32"
242.1195 +						>
242.1196 +						<Tool
242.1197 +							Name="VCCLCompilerTool"
242.1198 +							UsePrecompiledHeader="2"
242.1199 +						/>
242.1200 +					</FileConfiguration>
242.1201 +					<FileConfiguration
242.1202 +						Name="Debug|Win32"
242.1203 +						>
242.1204 +						<Tool
242.1205 +							Name="VCCLCompilerTool"
242.1206 +							UsePrecompiledHeader="2"
242.1207 +						/>
242.1208 +					</FileConfiguration>
242.1209 +				</File>
242.1210 +				<File
242.1211 +					RelativePath=".\CPP\7zip\Archive\GZip\GZipIn.cpp"
242.1212 +					>
242.1213 +					<FileConfiguration
242.1214 +						Name="Release|Win32"
242.1215 +						>
242.1216 +						<Tool
242.1217 +							Name="VCCLCompilerTool"
242.1218 +							UsePrecompiledHeader="2"
242.1219 +						/>
242.1220 +					</FileConfiguration>
242.1221 +					<FileConfiguration
242.1222 +						Name="Debug|Win32"
242.1223 +						>
242.1224 +						<Tool
242.1225 +							Name="VCCLCompilerTool"
242.1226 +							UsePrecompiledHeader="2"
242.1227 +						/>
242.1228 +					</FileConfiguration>
242.1229 +				</File>
242.1230 +			</Filter>
242.1231 +			<Filter
242.1232 +				Name="Lzh"
242.1233 +				>
242.1234 +				<File
242.1235 +					RelativePath=".\CPP\7zip\Archive\Lzh\LzhCRC.cpp"
242.1236 +					>
242.1237 +					<FileConfiguration
242.1238 +						Name="Release|Win32"
242.1239 +						>
242.1240 +						<Tool
242.1241 +							Name="VCCLCompilerTool"
242.1242 +							UsePrecompiledHeader="2"
242.1243 +						/>
242.1244 +					</FileConfiguration>
242.1245 +					<FileConfiguration
242.1246 +						Name="Debug|Win32"
242.1247 +						>
242.1248 +						<Tool
242.1249 +							Name="VCCLCompilerTool"
242.1250 +							UsePrecompiledHeader="2"
242.1251 +						/>
242.1252 +					</FileConfiguration>
242.1253 +				</File>
242.1254 +				<File
242.1255 +					RelativePath=".\CPP\7zip\Archive\Lzh\LzhHandler.cpp"
242.1256 +					>
242.1257 +					<FileConfiguration
242.1258 +						Name="Release|Win32"
242.1259 +						>
242.1260 +						<Tool
242.1261 +							Name="VCCLCompilerTool"
242.1262 +							UsePrecompiledHeader="2"
242.1263 +						/>
242.1264 +					</FileConfiguration>
242.1265 +					<FileConfiguration
242.1266 +						Name="Debug|Win32"
242.1267 +						>
242.1268 +						<Tool
242.1269 +							Name="VCCLCompilerTool"
242.1270 +							UsePrecompiledHeader="2"
242.1271 +						/>
242.1272 +					</FileConfiguration>
242.1273 +				</File>
242.1274 +				<File
242.1275 +					RelativePath=".\CPP\7zip\Archive\Lzh\LzhIn.cpp"
242.1276 +					>
242.1277 +					<FileConfiguration
242.1278 +						Name="Release|Win32"
242.1279 +						>
242.1280 +						<Tool
242.1281 +							Name="VCCLCompilerTool"
242.1282 +							UsePrecompiledHeader="2"
242.1283 +						/>
242.1284 +					</FileConfiguration>
242.1285 +					<FileConfiguration
242.1286 +						Name="Debug|Win32"
242.1287 +						>
242.1288 +						<Tool
242.1289 +							Name="VCCLCompilerTool"
242.1290 +							UsePrecompiledHeader="2"
242.1291 +						/>
242.1292 +					</FileConfiguration>
242.1293 +				</File>
242.1294 +				<File
242.1295 +					RelativePath=".\CPP\7zip\Archive\Lzh\LzhOutStreamWithCRC.cpp"
242.1296 +					>
242.1297 +					<FileConfiguration
242.1298 +						Name="Release|Win32"
242.1299 +						>
242.1300 +						<Tool
242.1301 +							Name="VCCLCompilerTool"
242.1302 +							UsePrecompiledHeader="2"
242.1303 +						/>
242.1304 +					</FileConfiguration>
242.1305 +					<FileConfiguration
242.1306 +						Name="Debug|Win32"
242.1307 +						>
242.1308 +						<Tool
242.1309 +							Name="VCCLCompilerTool"
242.1310 +							UsePrecompiledHeader="2"
242.1311 +						/>
242.1312 +					</FileConfiguration>
242.1313 +				</File>
242.1314 +			</Filter>
242.1315 +			<Filter
242.1316 +				Name="Split"
242.1317 +				>
242.1318 +				<File
242.1319 +					RelativePath=".\CPP\7zip\Archive\Split\SplitHandler.cpp"
242.1320 +					>
242.1321 +					<FileConfiguration
242.1322 +						Name="Release|Win32"
242.1323 +						>
242.1324 +						<Tool
242.1325 +							Name="VCCLCompilerTool"
242.1326 +							UsePrecompiledHeader="2"
242.1327 +						/>
242.1328 +					</FileConfiguration>
242.1329 +					<FileConfiguration
242.1330 +						Name="Debug|Win32"
242.1331 +						>
242.1332 +						<Tool
242.1333 +							Name="VCCLCompilerTool"
242.1334 +							UsePrecompiledHeader="2"
242.1335 +						/>
242.1336 +					</FileConfiguration>
242.1337 +				</File>
242.1338 +			</Filter>
242.1339 +			<Filter
242.1340 +				Name="Tar"
242.1341 +				>
242.1342 +				<File
242.1343 +					RelativePath=".\CPP\7zip\Archive\Tar\TarHandler.cpp"
242.1344 +					>
242.1345 +					<FileConfiguration
242.1346 +						Name="Release|Win32"
242.1347 +						>
242.1348 +						<Tool
242.1349 +							Name="VCCLCompilerTool"
242.1350 +							UsePrecompiledHeader="2"
242.1351 +						/>
242.1352 +					</FileConfiguration>
242.1353 +					<FileConfiguration
242.1354 +						Name="Debug|Win32"
242.1355 +						>
242.1356 +						<Tool
242.1357 +							Name="VCCLCompilerTool"
242.1358 +							UsePrecompiledHeader="2"
242.1359 +						/>
242.1360 +					</FileConfiguration>
242.1361 +				</File>
242.1362 +				<File
242.1363 +					RelativePath=".\CPP\7zip\Archive\Tar\TarHeader.cpp"
242.1364 +					>
242.1365 +					<FileConfiguration
242.1366 +						Name="Release|Win32"
242.1367 +						>
242.1368 +						<Tool
242.1369 +							Name="VCCLCompilerTool"
242.1370 +							UsePrecompiledHeader="2"
242.1371 +						/>
242.1372 +					</FileConfiguration>
242.1373 +					<FileConfiguration
242.1374 +						Name="Debug|Win32"
242.1375 +						>
242.1376 +						<Tool
242.1377 +							Name="VCCLCompilerTool"
242.1378 +							UsePrecompiledHeader="2"
242.1379 +						/>
242.1380 +					</FileConfiguration>
242.1381 +				</File>
242.1382 +				<File
242.1383 +					RelativePath=".\CPP\7zip\Archive\Tar\TarIn.cpp"
242.1384 +					>
242.1385 +					<FileConfiguration
242.1386 +						Name="Release|Win32"
242.1387 +						>
242.1388 +						<Tool
242.1389 +							Name="VCCLCompilerTool"
242.1390 +							UsePrecompiledHeader="2"
242.1391 +						/>
242.1392 +					</FileConfiguration>
242.1393 +					<FileConfiguration
242.1394 +						Name="Debug|Win32"
242.1395 +						>
242.1396 +						<Tool
242.1397 +							Name="VCCLCompilerTool"
242.1398 +							UsePrecompiledHeader="2"
242.1399 +						/>
242.1400 +					</FileConfiguration>
242.1401 +				</File>
242.1402 +			</Filter>
242.1403 +			<Filter
242.1404 +				Name="Zip"
242.1405 +				>
242.1406 +				<File
242.1407 +					RelativePath=".\CPP\7zip\Archive\Zip\ZipHandler.cpp"
242.1408 +					>
242.1409 +					<FileConfiguration
242.1410 +						Name="Release|Win32"
242.1411 +						>
242.1412 +						<Tool
242.1413 +							Name="VCCLCompilerTool"
242.1414 +							UsePrecompiledHeader="2"
242.1415 +						/>
242.1416 +					</FileConfiguration>
242.1417 +					<FileConfiguration
242.1418 +						Name="Debug|Win32"
242.1419 +						>
242.1420 +						<Tool
242.1421 +							Name="VCCLCompilerTool"
242.1422 +							UsePrecompiledHeader="2"
242.1423 +						/>
242.1424 +					</FileConfiguration>
242.1425 +				</File>
242.1426 +				<File
242.1427 +					RelativePath=".\CPP\7zip\Archive\Zip\ZipHeader.cpp"
242.1428 +					>
242.1429 +					<FileConfiguration
242.1430 +						Name="Release|Win32"
242.1431 +						>
242.1432 +						<Tool
242.1433 +							Name="VCCLCompilerTool"
242.1434 +							UsePrecompiledHeader="2"
242.1435 +						/>
242.1436 +					</FileConfiguration>
242.1437 +					<FileConfiguration
242.1438 +						Name="Debug|Win32"
242.1439 +						>
242.1440 +						<Tool
242.1441 +							Name="VCCLCompilerTool"
242.1442 +							UsePrecompiledHeader="2"
242.1443 +						/>
242.1444 +					</FileConfiguration>
242.1445 +				</File>
242.1446 +				<File
242.1447 +					RelativePath=".\CPP\7zip\Archive\Zip\ZipIn.cpp"
242.1448 +					>
242.1449 +					<FileConfiguration
242.1450 +						Name="Release|Win32"
242.1451 +						>
242.1452 +						<Tool
242.1453 +							Name="VCCLCompilerTool"
242.1454 +							UsePrecompiledHeader="2"
242.1455 +						/>
242.1456 +					</FileConfiguration>
242.1457 +					<FileConfiguration
242.1458 +						Name="Debug|Win32"
242.1459 +						>
242.1460 +						<Tool
242.1461 +							Name="VCCLCompilerTool"
242.1462 +							UsePrecompiledHeader="2"
242.1463 +						/>
242.1464 +					</FileConfiguration>
242.1465 +				</File>
242.1466 +				<File
242.1467 +					RelativePath=".\CPP\7zip\Archive\Zip\ZipItem.cpp"
242.1468 +					>
242.1469 +					<FileConfiguration
242.1470 +						Name="Release|Win32"
242.1471 +						>
242.1472 +						<Tool
242.1473 +							Name="VCCLCompilerTool"
242.1474 +							UsePrecompiledHeader="2"
242.1475 +						/>
242.1476 +					</FileConfiguration>
242.1477 +					<FileConfiguration
242.1478 +						Name="Debug|Win32"
242.1479 +						>
242.1480 +						<Tool
242.1481 +							Name="VCCLCompilerTool"
242.1482 +							UsePrecompiledHeader="2"
242.1483 +						/>
242.1484 +					</FileConfiguration>
242.1485 +				</File>
242.1486 +			</Filter>
242.1487 +			<Filter
242.1488 +				Name="Lzma Ar"
242.1489 +				>
242.1490 +				<File
242.1491 +					RelativePath=".\CPP\7zip\Archive\Lzma\LzmaFiltersDecode.cpp"
242.1492 +					>
242.1493 +					<FileConfiguration
242.1494 +						Name="Release|Win32"
242.1495 +						>
242.1496 +						<Tool
242.1497 +							Name="VCCLCompilerTool"
242.1498 +							UsePrecompiledHeader="2"
242.1499 +						/>
242.1500 +					</FileConfiguration>
242.1501 +					<FileConfiguration
242.1502 +						Name="Debug|Win32"
242.1503 +						>
242.1504 +						<Tool
242.1505 +							Name="VCCLCompilerTool"
242.1506 +							UsePrecompiledHeader="2"
242.1507 +						/>
242.1508 +					</FileConfiguration>
242.1509 +				</File>
242.1510 +				<File
242.1511 +					RelativePath=".\CPP\7zip\Archive\Lzma\LzmaHandler.cpp"
242.1512 +					>
242.1513 +					<FileConfiguration
242.1514 +						Name="Release|Win32"
242.1515 +						>
242.1516 +						<Tool
242.1517 +							Name="VCCLCompilerTool"
242.1518 +							UsePrecompiledHeader="2"
242.1519 +						/>
242.1520 +					</FileConfiguration>
242.1521 +					<FileConfiguration
242.1522 +						Name="Debug|Win32"
242.1523 +						>
242.1524 +						<Tool
242.1525 +							Name="VCCLCompilerTool"
242.1526 +							UsePrecompiledHeader="2"
242.1527 +						/>
242.1528 +					</FileConfiguration>
242.1529 +				</File>
242.1530 +				<File
242.1531 +					RelativePath=".\CPP\7zip\Archive\Lzma\LzmaIn.cpp"
242.1532 +					>
242.1533 +					<FileConfiguration
242.1534 +						Name="Release|Win32"
242.1535 +						>
242.1536 +						<Tool
242.1537 +							Name="VCCLCompilerTool"
242.1538 +							UsePrecompiledHeader="2"
242.1539 +						/>
242.1540 +					</FileConfiguration>
242.1541 +					<FileConfiguration
242.1542 +						Name="Debug|Win32"
242.1543 +						>
242.1544 +						<Tool
242.1545 +							Name="VCCLCompilerTool"
242.1546 +							UsePrecompiledHeader="2"
242.1547 +						/>
242.1548 +					</FileConfiguration>
242.1549 +				</File>
242.1550 +			</Filter>
242.1551 +		</Filter>
242.1552 +		<Filter
242.1553 +			Name="C"
242.1554 +			>
242.1555 +			<File
242.1556 +				RelativePath=".\C\7zCrc.c"
242.1557 +				>
242.1558 +				<FileConfiguration
242.1559 +					Name="Release|Win32"
242.1560 +					>
242.1561 +					<Tool
242.1562 +						Name="VCCLCompilerTool"
242.1563 +						UsePrecompiledHeader="0"
242.1564 +					/>
242.1565 +				</FileConfiguration>
242.1566 +				<FileConfiguration
242.1567 +					Name="Debug|Win32"
242.1568 +					>
242.1569 +					<Tool
242.1570 +						Name="VCCLCompilerTool"
242.1571 +						UsePrecompiledHeader="0"
242.1572 +					/>
242.1573 +				</FileConfiguration>
242.1574 +			</File>
242.1575 +			<File
242.1576 +				RelativePath=".\C\Aes.c"
242.1577 +				>
242.1578 +				<FileConfiguration
242.1579 +					Name="Release|Win32"
242.1580 +					>
242.1581 +					<Tool
242.1582 +						Name="VCCLCompilerTool"
242.1583 +						UsePrecompiledHeader="0"
242.1584 +					/>
242.1585 +				</FileConfiguration>
242.1586 +				<FileConfiguration
242.1587 +					Name="Debug|Win32"
242.1588 +					>
242.1589 +					<Tool
242.1590 +						Name="VCCLCompilerTool"
242.1591 +						UsePrecompiledHeader="0"
242.1592 +					/>
242.1593 +				</FileConfiguration>
242.1594 +			</File>
242.1595 +			<File
242.1596 +				RelativePath=".\C\Alloc.c"
242.1597 +				>
242.1598 +				<FileConfiguration
242.1599 +					Name="Release|Win32"
242.1600 +					>
242.1601 +					<Tool
242.1602 +						Name="VCCLCompilerTool"
242.1603 +						UsePrecompiledHeader="0"
242.1604 +					/>
242.1605 +				</FileConfiguration>
242.1606 +				<FileConfiguration
242.1607 +					Name="Debug|Win32"
242.1608 +					>
242.1609 +					<Tool
242.1610 +						Name="VCCLCompilerTool"
242.1611 +						UsePrecompiledHeader="0"
242.1612 +					/>
242.1613 +				</FileConfiguration>
242.1614 +			</File>
242.1615 +			<File
242.1616 +				RelativePath=".\C\Bra.c"
242.1617 +				>
242.1618 +				<FileConfiguration
242.1619 +					Name="Release|Win32"
242.1620 +					>
242.1621 +					<Tool
242.1622 +						Name="VCCLCompilerTool"
242.1623 +						UsePrecompiledHeader="0"
242.1624 +					/>
242.1625 +				</FileConfiguration>
242.1626 +				<FileConfiguration
242.1627 +					Name="Debug|Win32"
242.1628 +					>
242.1629 +					<Tool
242.1630 +						Name="VCCLCompilerTool"
242.1631 +						UsePrecompiledHeader="0"
242.1632 +					/>
242.1633 +				</FileConfiguration>
242.1634 +			</File>
242.1635 +			<File
242.1636 +				RelativePath=".\C\Bra86.c"
242.1637 +				>
242.1638 +				<FileConfiguration
242.1639 +					Name="Release|Win32"
242.1640 +					>
242.1641 +					<Tool
242.1642 +						Name="VCCLCompilerTool"
242.1643 +						UsePrecompiledHeader="0"
242.1644 +					/>
242.1645 +				</FileConfiguration>
242.1646 +				<FileConfiguration
242.1647 +					Name="Debug|Win32"
242.1648 +					>
242.1649 +					<Tool
242.1650 +						Name="VCCLCompilerTool"
242.1651 +						UsePrecompiledHeader="0"
242.1652 +					/>
242.1653 +				</FileConfiguration>
242.1654 +			</File>
242.1655 +			<File
242.1656 +				RelativePath=".\C\BraIA64.c"
242.1657 +				>
242.1658 +				<FileConfiguration
242.1659 +					Name="Release|Win32"
242.1660 +					>
242.1661 +					<Tool
242.1662 +						Name="VCCLCompilerTool"
242.1663 +						UsePrecompiledHeader="0"
242.1664 +					/>
242.1665 +				</FileConfiguration>
242.1666 +				<FileConfiguration
242.1667 +					Name="Debug|Win32"
242.1668 +					>
242.1669 +					<Tool
242.1670 +						Name="VCCLCompilerTool"
242.1671 +						UsePrecompiledHeader="0"
242.1672 +					/>
242.1673 +				</FileConfiguration>
242.1674 +			</File>
242.1675 +			<File
242.1676 +				RelativePath=".\C\BwtSort.c"
242.1677 +				>
242.1678 +				<FileConfiguration
242.1679 +					Name="Release|Win32"
242.1680 +					>
242.1681 +					<Tool
242.1682 +						Name="VCCLCompilerTool"
242.1683 +						UsePrecompiledHeader="0"
242.1684 +					/>
242.1685 +				</FileConfiguration>
242.1686 +				<FileConfiguration
242.1687 +					Name="Debug|Win32"
242.1688 +					>
242.1689 +					<Tool
242.1690 +						Name="VCCLCompilerTool"
242.1691 +						UsePrecompiledHeader="0"
242.1692 +					/>
242.1693 +				</FileConfiguration>
242.1694 +			</File>
242.1695 +			<File
242.1696 +				RelativePath=".\C\HuffEnc.c"
242.1697 +				>
242.1698 +				<FileConfiguration
242.1699 +					Name="Release|Win32"
242.1700 +					>
242.1701 +					<Tool
242.1702 +						Name="VCCLCompilerTool"
242.1703 +						UsePrecompiledHeader="0"
242.1704 +					/>
242.1705 +				</FileConfiguration>
242.1706 +				<FileConfiguration
242.1707 +					Name="Debug|Win32"
242.1708 +					>
242.1709 +					<Tool
242.1710 +						Name="VCCLCompilerTool"
242.1711 +						UsePrecompiledHeader="0"
242.1712 +					/>
242.1713 +				</FileConfiguration>
242.1714 +			</File>
242.1715 +			<File
242.1716 +				RelativePath=".\C\LzFind.c"
242.1717 +				>
242.1718 +				<FileConfiguration
242.1719 +					Name="Release|Win32"
242.1720 +					>
242.1721 +					<Tool
242.1722 +						Name="VCCLCompilerTool"
242.1723 +						UsePrecompiledHeader="0"
242.1724 +					/>
242.1725 +				</FileConfiguration>
242.1726 +				<FileConfiguration
242.1727 +					Name="Debug|Win32"
242.1728 +					>
242.1729 +					<Tool
242.1730 +						Name="VCCLCompilerTool"
242.1731 +						UsePrecompiledHeader="0"
242.1732 +					/>
242.1733 +				</FileConfiguration>
242.1734 +			</File>
242.1735 +			<File
242.1736 +				RelativePath=".\C\LzFindMt.c"
242.1737 +				>
242.1738 +				<FileConfiguration
242.1739 +					Name="Release|Win32"
242.1740 +					>
242.1741 +					<Tool
242.1742 +						Name="VCCLCompilerTool"
242.1743 +						UsePrecompiledHeader="0"
242.1744 +					/>
242.1745 +				</FileConfiguration>
242.1746 +				<FileConfiguration
242.1747 +					Name="Debug|Win32"
242.1748 +					>
242.1749 +					<Tool
242.1750 +						Name="VCCLCompilerTool"
242.1751 +						UsePrecompiledHeader="0"
242.1752 +					/>
242.1753 +				</FileConfiguration>
242.1754 +			</File>
242.1755 +			<File
242.1756 +				RelativePath=".\C\LzmaDec.c"
242.1757 +				>
242.1758 +				<FileConfiguration
242.1759 +					Name="Release|Win32"
242.1760 +					>
242.1761 +					<Tool
242.1762 +						Name="VCCLCompilerTool"
242.1763 +						UsePrecompiledHeader="0"
242.1764 +					/>
242.1765 +				</FileConfiguration>
242.1766 +				<FileConfiguration
242.1767 +					Name="Debug|Win32"
242.1768 +					>
242.1769 +					<Tool
242.1770 +						Name="VCCLCompilerTool"
242.1771 +						UsePrecompiledHeader="0"
242.1772 +					/>
242.1773 +				</FileConfiguration>
242.1774 +			</File>
242.1775 +			<File
242.1776 +				RelativePath=".\C\LzmaEnc.c"
242.1777 +				>
242.1778 +				<FileConfiguration
242.1779 +					Name="Release|Win32"
242.1780 +					>
242.1781 +					<Tool
242.1782 +						Name="VCCLCompilerTool"
242.1783 +						UsePrecompiledHeader="0"
242.1784 +					/>
242.1785 +				</FileConfiguration>
242.1786 +				<FileConfiguration
242.1787 +					Name="Debug|Win32"
242.1788 +					>
242.1789 +					<Tool
242.1790 +						Name="VCCLCompilerTool"
242.1791 +						UsePrecompiledHeader="0"
242.1792 +					/>
242.1793 +				</FileConfiguration>
242.1794 +			</File>
242.1795 +			<File
242.1796 +				RelativePath=".\C\Sha256.c"
242.1797 +				>
242.1798 +				<FileConfiguration
242.1799 +					Name="Release|Win32"
242.1800 +					>
242.1801 +					<Tool
242.1802 +						Name="VCCLCompilerTool"
242.1803 +						UsePrecompiledHeader="0"
242.1804 +					/>
242.1805 +				</FileConfiguration>
242.1806 +				<FileConfiguration
242.1807 +					Name="Debug|Win32"
242.1808 +					>
242.1809 +					<Tool
242.1810 +						Name="VCCLCompilerTool"
242.1811 +						UsePrecompiledHeader="0"
242.1812 +					/>
242.1813 +				</FileConfiguration>
242.1814 +			</File>
242.1815 +			<File
242.1816 +				RelativePath=".\C\Sort.c"
242.1817 +				>
242.1818 +				<FileConfiguration
242.1819 +					Name="Release|Win32"
242.1820 +					>
242.1821 +					<Tool
242.1822 +						Name="VCCLCompilerTool"
242.1823 +						UsePrecompiledHeader="0"
242.1824 +					/>
242.1825 +				</FileConfiguration>
242.1826 +				<FileConfiguration
242.1827 +					Name="Debug|Win32"
242.1828 +					>
242.1829 +					<Tool
242.1830 +						Name="VCCLCompilerTool"
242.1831 +						UsePrecompiledHeader="0"
242.1832 +					/>
242.1833 +				</FileConfiguration>
242.1834 +			</File>
242.1835 +			<File
242.1836 +				RelativePath=".\C\Threads.c"
242.1837 +				>
242.1838 +				<FileConfiguration
242.1839 +					Name="Release|Win32"
242.1840 +					>
242.1841 +					<Tool
242.1842 +						Name="VCCLCompilerTool"
242.1843 +						UsePrecompiledHeader="0"
242.1844 +					/>
242.1845 +				</FileConfiguration>
242.1846 +				<FileConfiguration
242.1847 +					Name="Debug|Win32"
242.1848 +					>
242.1849 +					<Tool
242.1850 +						Name="VCCLCompilerTool"
242.1851 +						UsePrecompiledHeader="0"
242.1852 +					/>
242.1853 +				</FileConfiguration>
242.1854 +			</File>
242.1855 +		</Filter>
242.1856 +		<Filter
242.1857 +			Name="Common"
242.1858 +			>
242.1859 +			<File
242.1860 +				RelativePath=".\CPP\Common\CRC.cpp"
242.1861 +				>
242.1862 +				<FileConfiguration
242.1863 +					Name="Release|Win32"
242.1864 +					>
242.1865 +					<Tool
242.1866 +						Name="VCCLCompilerTool"
242.1867 +						UsePrecompiledHeader="2"
242.1868 +					/>
242.1869 +				</FileConfiguration>
242.1870 +				<FileConfiguration
242.1871 +					Name="Debug|Win32"
242.1872 +					>
242.1873 +					<Tool
242.1874 +						Name="VCCLCompilerTool"
242.1875 +						UsePrecompiledHeader="2"
242.1876 +					/>
242.1877 +				</FileConfiguration>
242.1878 +			</File>
242.1879 +			<File
242.1880 +				RelativePath=".\CPP\Common\IntToString.cpp"
242.1881 +				>
242.1882 +				<FileConfiguration
242.1883 +					Name="Release|Win32"
242.1884 +					>
242.1885 +					<Tool
242.1886 +						Name="VCCLCompilerTool"
242.1887 +						UsePrecompiledHeader="2"
242.1888 +					/>
242.1889 +				</FileConfiguration>
242.1890 +				<FileConfiguration
242.1891 +					Name="Debug|Win32"
242.1892 +					>
242.1893 +					<Tool
242.1894 +						Name="VCCLCompilerTool"
242.1895 +						UsePrecompiledHeader="2"
242.1896 +					/>
242.1897 +				</FileConfiguration>
242.1898 +			</File>
242.1899 +			<File
242.1900 +				RelativePath=".\CPP\Common\MyMap.cpp"
242.1901 +				>
242.1902 +				<FileConfiguration
242.1903 +					Name="Release|Win32"
242.1904 +					>
242.1905 +					<Tool
242.1906 +						Name="VCCLCompilerTool"
242.1907 +						UsePrecompiledHeader="2"
242.1908 +					/>
242.1909 +				</FileConfiguration>
242.1910 +				<FileConfiguration
242.1911 +					Name="Debug|Win32"
242.1912 +					>
242.1913 +					<Tool
242.1914 +						Name="VCCLCompilerTool"
242.1915 +						UsePrecompiledHeader="2"
242.1916 +					/>
242.1917 +				</FileConfiguration>
242.1918 +			</File>
242.1919 +			<File
242.1920 +				RelativePath=".\CPP\Common\MyString.cpp"
242.1921 +				>
242.1922 +				<FileConfiguration
242.1923 +					Name="Release|Win32"
242.1924 +					>
242.1925 +					<Tool
242.1926 +						Name="VCCLCompilerTool"
242.1927 +						UsePrecompiledHeader="2"
242.1928 +					/>
242.1929 +				</FileConfiguration>
242.1930 +				<FileConfiguration
242.1931 +					Name="Debug|Win32"
242.1932 +					>
242.1933 +					<Tool
242.1934 +						Name="VCCLCompilerTool"
242.1935 +						UsePrecompiledHeader="2"
242.1936 +					/>
242.1937 +				</FileConfiguration>
242.1938 +			</File>
242.1939 +			<File
242.1940 +				RelativePath=".\CPP\Common\MyVector.cpp"
242.1941 +				>
242.1942 +				<FileConfiguration
242.1943 +					Name="Release|Win32"
242.1944 +					>
242.1945 +					<Tool
242.1946 +						Name="VCCLCompilerTool"
242.1947 +						UsePrecompiledHeader="2"
242.1948 +					/>
242.1949 +				</FileConfiguration>
242.1950 +				<FileConfiguration
242.1951 +					Name="Debug|Win32"
242.1952 +					>
242.1953 +					<Tool
242.1954 +						Name="VCCLCompilerTool"
242.1955 +						UsePrecompiledHeader="2"
242.1956 +					/>
242.1957 +				</FileConfiguration>
242.1958 +			</File>
242.1959 +			<File
242.1960 +				RelativePath=".\CPP\Common\MyXml.cpp"
242.1961 +				>
242.1962 +				<FileConfiguration
242.1963 +					Name="Release|Win32"
242.1964 +					>
242.1965 +					<Tool
242.1966 +						Name="VCCLCompilerTool"
242.1967 +						UsePrecompiledHeader="2"
242.1968 +					/>
242.1969 +				</FileConfiguration>
242.1970 +				<FileConfiguration
242.1971 +					Name="Debug|Win32"
242.1972 +					>
242.1973 +					<Tool
242.1974 +						Name="VCCLCompilerTool"
242.1975 +						UsePrecompiledHeader="2"
242.1976 +					/>
242.1977 +				</FileConfiguration>
242.1978 +			</File>
242.1979 +			<File
242.1980 +				RelativePath=".\CPP\Common\NewHandler.cpp"
242.1981 +				>
242.1982 +				<FileConfiguration
242.1983 +					Name="Release|Win32"
242.1984 +					ExcludedFromBuild="true"
242.1985 +					>
242.1986 +					<Tool
242.1987 +						Name="VCCLCompilerTool"
242.1988 +						UsePrecompiledHeader="2"
242.1989 +					/>
242.1990 +				</FileConfiguration>
242.1991 +				<FileConfiguration
242.1992 +					Name="Debug|Win32"
242.1993 +					ExcludedFromBuild="true"
242.1994 +					>
242.1995 +					<Tool
242.1996 +						Name="VCCLCompilerTool"
242.1997 +						UsePrecompiledHeader="2"
242.1998 +					/>
242.1999 +				</FileConfiguration>
242.2000 +			</File>
242.2001 +			<File
242.2002 +				RelativePath=".\CPP\Common\StringConvert.cpp"
242.2003 +				>
242.2004 +				<FileConfiguration
242.2005 +					Name="Release|Win32"
242.2006 +					>
242.2007 +					<Tool
242.2008 +						Name="VCCLCompilerTool"
242.2009 +						UsePrecompiledHeader="2"
242.2010 +					/>
242.2011 +				</FileConfiguration>
242.2012 +				<FileConfiguration
242.2013 +					Name="Debug|Win32"
242.2014 +					>
242.2015 +					<Tool
242.2016 +						Name="VCCLCompilerTool"
242.2017 +						UsePrecompiledHeader="2"
242.2018 +					/>
242.2019 +				</FileConfiguration>
242.2020 +			</File>
242.2021 +			<File
242.2022 +				RelativePath=".\CPP\Common\StringToInt.cpp"
242.2023 +				>
242.2024 +				<FileConfiguration
242.2025 +					Name="Release|Win32"
242.2026 +					>
242.2027 +					<Tool
242.2028 +						Name="VCCLCompilerTool"
242.2029 +						UsePrecompiledHeader="2"
242.2030 +					/>
242.2031 +				</FileConfiguration>
242.2032 +				<FileConfiguration
242.2033 +					Name="Debug|Win32"
242.2034 +					>
242.2035 +					<Tool
242.2036 +						Name="VCCLCompilerTool"
242.2037 +						UsePrecompiledHeader="2"
242.2038 +					/>
242.2039 +				</FileConfiguration>
242.2040 +			</File>
242.2041 +			<File
242.2042 +				RelativePath=".\CPP\Common\UTFConvert.cpp"
242.2043 +				>
242.2044 +				<FileConfiguration
242.2045 +					Name="Release|Win32"
242.2046 +					>
242.2047 +					<Tool
242.2048 +						Name="VCCLCompilerTool"
242.2049 +						UsePrecompiledHeader="2"
242.2050 +					/>
242.2051 +				</FileConfiguration>
242.2052 +				<FileConfiguration
242.2053 +					Name="Debug|Win32"
242.2054 +					>
242.2055 +					<Tool
242.2056 +						Name="VCCLCompilerTool"
242.2057 +						UsePrecompiledHeader="2"
242.2058 +					/>
242.2059 +				</FileConfiguration>
242.2060 +			</File>
242.2061 +			<File
242.2062 +				RelativePath=".\CPP\Common\Wildcard.cpp"
242.2063 +				>
242.2064 +				<FileConfiguration
242.2065 +					Name="Release|Win32"
242.2066 +					>
242.2067 +					<Tool
242.2068 +						Name="VCCLCompilerTool"
242.2069 +						UsePrecompiledHeader="2"
242.2070 +					/>
242.2071 +				</FileConfiguration>
242.2072 +				<FileConfiguration
242.2073 +					Name="Debug|Win32"
242.2074 +					>
242.2075 +					<Tool
242.2076 +						Name="VCCLCompilerTool"
242.2077 +						UsePrecompiledHeader="2"
242.2078 +					/>
242.2079 +				</FileConfiguration>
242.2080 +			</File>
242.2081 +		</Filter>
242.2082 +		<Filter
242.2083 +			Name="Compress"
242.2084 +			>
242.2085 +			<File
242.2086 +				RelativePath=".\CPP\7zip\Compress\LzhDecoder.cpp"
242.2087 +				>
242.2088 +				<FileConfiguration
242.2089 +					Name="Release|Win32"
242.2090 +					>
242.2091 +					<Tool
242.2092 +						Name="VCCLCompilerTool"
242.2093 +						UsePrecompiledHeader="2"
242.2094 +					/>
242.2095 +				</FileConfiguration>
242.2096 +				<FileConfiguration
242.2097 +					Name="Debug|Win32"
242.2098 +					>
242.2099 +					<Tool
242.2100 +						Name="VCCLCompilerTool"
242.2101 +						UsePrecompiledHeader="2"
242.2102 +					/>
242.2103 +				</FileConfiguration>
242.2104 +			</File>
242.2105 +			<File
242.2106 +				RelativePath=".\CPP\7zip\Compress\LzOutWindow.cpp"
242.2107 +				>
242.2108 +				<FileConfiguration
242.2109 +					Name="Release|Win32"
242.2110 +					>
242.2111 +					<Tool
242.2112 +						Name="VCCLCompilerTool"
242.2113 +						UsePrecompiledHeader="2"
242.2114 +					/>
242.2115 +				</FileConfiguration>
242.2116 +				<FileConfiguration
242.2117 +					Name="Debug|Win32"
242.2118 +					>
242.2119 +					<Tool
242.2120 +						Name="VCCLCompilerTool"
242.2121 +						UsePrecompiledHeader="2"
242.2122 +					/>
242.2123 +				</FileConfiguration>
242.2124 +			</File>
242.2125 +			<Filter
242.2126 +				Name="PPMD"
242.2127 +				>
242.2128 +				<File
242.2129 +					RelativePath=".\CPP\7zip\Compress\PpmdDecoder.cpp"
242.2130 +					>
242.2131 +					<FileConfiguration
242.2132 +						Name="Release|Win32"
242.2133 +						>
242.2134 +						<Tool
242.2135 +							Name="VCCLCompilerTool"
242.2136 +							UsePrecompiledHeader="2"
242.2137 +						/>
242.2138 +					</FileConfiguration>
242.2139 +					<FileConfiguration
242.2140 +						Name="Debug|Win32"
242.2141 +						>
242.2142 +						<Tool
242.2143 +							Name="VCCLCompilerTool"
242.2144 +							UsePrecompiledHeader="2"
242.2145 +						/>
242.2146 +					</FileConfiguration>
242.2147 +				</File>
242.2148 +			</Filter>
242.2149 +			<Filter
242.2150 +				Name="Bit Coder"
242.2151 +				>
242.2152 +				<File
242.2153 +					RelativePath=".\CPP\7zip\Compress\BitlDecoder.cpp"
242.2154 +					>
242.2155 +					<FileConfiguration
242.2156 +						Name="Release|Win32"
242.2157 +						>
242.2158 +						<Tool
242.2159 +							Name="VCCLCompilerTool"
242.2160 +							UsePrecompiledHeader="2"
242.2161 +						/>
242.2162 +					</FileConfiguration>
242.2163 +					<FileConfiguration
242.2164 +						Name="Debug|Win32"
242.2165 +						>
242.2166 +						<Tool
242.2167 +							Name="VCCLCompilerTool"
242.2168 +							UsePrecompiledHeader="2"
242.2169 +						/>
242.2170 +					</FileConfiguration>
242.2171 +				</File>
242.2172 +			</Filter>
242.2173 +			<Filter
242.2174 +				Name="Rar Compress"
242.2175 +				>
242.2176 +				<File
242.2177 +					RelativePath=".\CPP\7zip\Compress\Rar1Decoder.cpp"
242.2178 +					>
242.2179 +					<FileConfiguration
242.2180 +						Name="Release|Win32"
242.2181 +						>
242.2182 +						<Tool
242.2183 +							Name="VCCLCompilerTool"
242.2184 +							UsePrecompiledHeader="2"
242.2185 +						/>
242.2186 +					</FileConfiguration>
242.2187 +					<FileConfiguration
242.2188 +						Name="Debug|Win32"
242.2189 +						>
242.2190 +						<Tool
242.2191 +							Name="VCCLCompilerTool"
242.2192 +							UsePrecompiledHeader="2"
242.2193 +						/>
242.2194 +					</FileConfiguration>
242.2195 +				</File>
242.2196 +				<File
242.2197 +					RelativePath=".\CPP\7zip\Compress\Rar2Decoder.cpp"
242.2198 +					>
242.2199 +					<FileConfiguration
242.2200 +						Name="Release|Win32"
242.2201 +						>
242.2202 +						<Tool
242.2203 +							Name="VCCLCompilerTool"
242.2204 +							UsePrecompiledHeader="2"
242.2205 +						/>
242.2206 +					</FileConfiguration>
242.2207 +					<FileConfiguration
242.2208 +						Name="Debug|Win32"
242.2209 +						>
242.2210 +						<Tool
242.2211 +							Name="VCCLCompilerTool"
242.2212 +							UsePrecompiledHeader="2"
242.2213 +						/>
242.2214 +					</FileConfiguration>
242.2215 +				</File>
242.2216 +				<File
242.2217 +					RelativePath=".\CPP\7zip\Compress\Rar3Decoder.cpp"
242.2218 +					>
242.2219 +					<FileConfiguration
242.2220 +						Name="Release|Win32"
242.2221 +						>
242.2222 +						<Tool
242.2223 +							Name="VCCLCompilerTool"
242.2224 +							UsePrecompiledHeader="2"
242.2225 +						/>
242.2226 +					</FileConfiguration>
242.2227 +					<FileConfiguration
242.2228 +						Name="Debug|Win32"
242.2229 +						>
242.2230 +						<Tool
242.2231 +							Name="VCCLCompilerTool"
242.2232 +							UsePrecompiledHeader="2"
242.2233 +						/>
242.2234 +					</FileConfiguration>
242.2235 +				</File>
242.2236 +				<File
242.2237 +					RelativePath=".\CPP\7zip\Compress\Rar3Vm.cpp"
242.2238 +					>
242.2239 +					<FileConfiguration
242.2240 +						Name="Release|Win32"
242.2241 +						>
242.2242 +						<Tool
242.2243 +							Name="VCCLCompilerTool"
242.2244 +							UsePrecompiledHeader="2"
242.2245 +						/>
242.2246 +					</FileConfiguration>
242.2247 +					<FileConfiguration
242.2248 +						Name="Debug|Win32"
242.2249 +						>
242.2250 +						<Tool
242.2251 +							Name="VCCLCompilerTool"
242.2252 +							UsePrecompiledHeader="2"
242.2253 +						/>
242.2254 +					</FileConfiguration>
242.2255 +				</File>
242.2256 +			</Filter>
242.2257 +			<Filter
242.2258 +				Name="BZip2 Compress"
242.2259 +				>
242.2260 +				<File
242.2261 +					RelativePath=".\CPP\7zip\Compress\BZip2Crc.cpp"
242.2262 +					>
242.2263 +					<FileConfiguration
242.2264 +						Name="Release|Win32"
242.2265 +						>
242.2266 +						<Tool
242.2267 +							Name="VCCLCompilerTool"
242.2268 +							UsePrecompiledHeader="2"
242.2269 +						/>
242.2270 +					</FileConfiguration>
242.2271 +					<FileConfiguration
242.2272 +						Name="Debug|Win32"
242.2273 +						>
242.2274 +						<Tool
242.2275 +							Name="VCCLCompilerTool"
242.2276 +							UsePrecompiledHeader="2"
242.2277 +						/>
242.2278 +					</FileConfiguration>
242.2279 +				</File>
242.2280 +				<File
242.2281 +					RelativePath=".\CPP\7zip\Compress\BZip2Decoder.cpp"
242.2282 +					>
242.2283 +					<FileConfiguration
242.2284 +						Name="Release|Win32"
242.2285 +						>
242.2286 +						<Tool
242.2287 +							Name="VCCLCompilerTool"
242.2288 +							UsePrecompiledHeader="2"
242.2289 +						/>
242.2290 +					</FileConfiguration>
242.2291 +					<FileConfiguration
242.2292 +						Name="Debug|Win32"
242.2293 +						>
242.2294 +						<Tool
242.2295 +							Name="VCCLCompilerTool"
242.2296 +							UsePrecompiledHeader="2"
242.2297 +						/>
242.2298 +					</FileConfiguration>
242.2299 +				</File>
242.2300 +			</Filter>
242.2301 +			<Filter
242.2302 +				Name="Zip Compress"
242.2303 +				>
242.2304 +				<File
242.2305 +					RelativePath=".\CPP\7zip\Compress\DeflateDecoder.cpp"
242.2306 +					>
242.2307 +					<FileConfiguration
242.2308 +						Name="Release|Win32"
242.2309 +						>
242.2310 +						<Tool
242.2311 +							Name="VCCLCompilerTool"
242.2312 +							UsePrecompiledHeader="2"
242.2313 +						/>
242.2314 +					</FileConfiguration>
242.2315 +					<FileConfiguration
242.2316 +						Name="Debug|Win32"
242.2317 +						>
242.2318 +						<Tool
242.2319 +							Name="VCCLCompilerTool"
242.2320 +							UsePrecompiledHeader="2"
242.2321 +						/>
242.2322 +					</FileConfiguration>
242.2323 +				</File>
242.2324 +				<File
242.2325 +					RelativePath=".\CPP\7zip\Compress\ImplodeDecoder.cpp"
242.2326 +					>
242.2327 +					<FileConfiguration
242.2328 +						Name="Release|Win32"
242.2329 +						>
242.2330 +						<Tool
242.2331 +							Name="VCCLCompilerTool"
242.2332 +							UsePrecompiledHeader="2"
242.2333 +						/>
242.2334 +					</FileConfiguration>
242.2335 +					<FileConfiguration
242.2336 +						Name="Debug|Win32"
242.2337 +						>
242.2338 +						<Tool
242.2339 +							Name="VCCLCompilerTool"
242.2340 +							UsePrecompiledHeader="2"
242.2341 +						/>
242.2342 +					</FileConfiguration>
242.2343 +				</File>
242.2344 +				<File
242.2345 +					RelativePath=".\CPP\7zip\Compress\ImplodeHuffmanDecoder.cpp"
242.2346 +					>
242.2347 +					<FileConfiguration
242.2348 +						Name="Release|Win32"
242.2349 +						>
242.2350 +						<Tool
242.2351 +							Name="VCCLCompilerTool"
242.2352 +							UsePrecompiledHeader="2"
242.2353 +						/>
242.2354 +					</FileConfiguration>
242.2355 +					<FileConfiguration
242.2356 +						Name="Debug|Win32"
242.2357 +						>
242.2358 +						<Tool
242.2359 +							Name="VCCLCompilerTool"
242.2360 +							UsePrecompiledHeader="2"
242.2361 +						/>
242.2362 +					</FileConfiguration>
242.2363 +				</File>
242.2364 +				<File
242.2365 +					RelativePath=".\CPP\7zip\Compress\ShrinkDecoder.cpp"
242.2366 +					>
242.2367 +					<FileConfiguration
242.2368 +						Name="Release|Win32"
242.2369 +						>
242.2370 +						<Tool
242.2371 +							Name="VCCLCompilerTool"
242.2372 +							UsePrecompiledHeader="2"
242.2373 +						/>
242.2374 +					</FileConfiguration>
242.2375 +					<FileConfiguration
242.2376 +						Name="Debug|Win32"
242.2377 +						>
242.2378 +						<Tool
242.2379 +							Name="VCCLCompilerTool"
242.2380 +							UsePrecompiledHeader="2"
242.2381 +						/>
242.2382 +					</FileConfiguration>
242.2383 +				</File>
242.2384 +				<File
242.2385 +					RelativePath=".\CPP\7zip\Compress\ZlibDecoder.cpp"
242.2386 +					>
242.2387 +					<FileConfiguration
242.2388 +						Name="Release|Win32"
242.2389 +						>
242.2390 +						<Tool
242.2391 +							Name="VCCLCompilerTool"
242.2392 +							UsePrecompiledHeader="2"
242.2393 +						/>
242.2394 +					</FileConfiguration>
242.2395 +					<FileConfiguration
242.2396 +						Name="Debug|Win32"
242.2397 +						>
242.2398 +						<Tool
242.2399 +							Name="VCCLCompilerTool"
242.2400 +							UsePrecompiledHeader="2"
242.2401 +						/>
242.2402 +					</FileConfiguration>
242.2403 +				</File>
242.2404 +			</Filter>
242.2405 +			<Filter
242.2406 +				Name="7z Compress"
242.2407 +				>
242.2408 +				<File
242.2409 +					RelativePath=".\CPP\7zip\Compress\Bcj2Coder.cpp"
242.2410 +					>
242.2411 +					<FileConfiguration
242.2412 +						Name="Release|Win32"
242.2413 +						>
242.2414 +						<Tool
242.2415 +							Name="VCCLCompilerTool"
242.2416 +							UsePrecompiledHeader="2"
242.2417 +						/>
242.2418 +					</FileConfiguration>
242.2419 +					<FileConfiguration
242.2420 +						Name="Debug|Win32"
242.2421 +						>
242.2422 +						<Tool
242.2423 +							Name="VCCLCompilerTool"
242.2424 +							UsePrecompiledHeader="2"
242.2425 +						/>
242.2426 +					</FileConfiguration>
242.2427 +				</File>
242.2428 +				<File
242.2429 +					RelativePath=".\CPP\7zip\Compress\BcjCoder.cpp"
242.2430 +					>
242.2431 +					<FileConfiguration
242.2432 +						Name="Release|Win32"
242.2433 +						>
242.2434 +						<Tool
242.2435 +							Name="VCCLCompilerTool"
242.2436 +							UsePrecompiledHeader="2"
242.2437 +						/>
242.2438 +					</FileConfiguration>
242.2439 +					<FileConfiguration
242.2440 +						Name="Debug|Win32"
242.2441 +						>
242.2442 +						<Tool
242.2443 +							Name="VCCLCompilerTool"
242.2444 +							UsePrecompiledHeader="2"
242.2445 +						/>
242.2446 +					</FileConfiguration>
242.2447 +				</File>
242.2448 +				<File
242.2449 +					RelativePath=".\CPP\7zip\Compress\BranchCoder.cpp"
242.2450 +					>
242.2451 +					<FileConfiguration
242.2452 +						Name="Release|Win32"
242.2453 +						>
242.2454 +						<Tool
242.2455 +							Name="VCCLCompilerTool"
242.2456 +							UsePrecompiledHeader="2"
242.2457 +						/>
242.2458 +					</FileConfiguration>
242.2459 +					<FileConfiguration
242.2460 +						Name="Debug|Win32"
242.2461 +						>
242.2462 +						<Tool
242.2463 +							Name="VCCLCompilerTool"
242.2464 +							UsePrecompiledHeader="2"
242.2465 +						/>
242.2466 +					</FileConfiguration>
242.2467 +				</File>
242.2468 +				<File
242.2469 +					RelativePath=".\CPP\7zip\Compress\BranchMisc.cpp"
242.2470 +					>
242.2471 +					<FileConfiguration
242.2472 +						Name="Release|Win32"
242.2473 +						>
242.2474 +						<Tool
242.2475 +							Name="VCCLCompilerTool"
242.2476 +							UsePrecompiledHeader="2"
242.2477 +						/>
242.2478 +					</FileConfiguration>
242.2479 +					<FileConfiguration
242.2480 +						Name="Debug|Win32"
242.2481 +						>
242.2482 +						<Tool
242.2483 +							Name="VCCLCompilerTool"
242.2484 +							UsePrecompiledHeader="2"
242.2485 +						/>
242.2486 +					</FileConfiguration>
242.2487 +				</File>
242.2488 +				<File
242.2489 +					RelativePath=".\CPP\7zip\Compress\ByteSwap.cpp"
242.2490 +					>
242.2491 +					<FileConfiguration
242.2492 +						Name="Release|Win32"
242.2493 +						>
242.2494 +						<Tool
242.2495 +							Name="VCCLCompilerTool"
242.2496 +							UsePrecompiledHeader="2"
242.2497 +						/>
242.2498 +					</FileConfiguration>
242.2499 +					<FileConfiguration
242.2500 +						Name="Debug|Win32"
242.2501 +						>
242.2502 +						<Tool
242.2503 +							Name="VCCLCompilerTool"
242.2504 +							UsePrecompiledHeader="2"
242.2505 +						/>
242.2506 +					</FileConfiguration>
242.2507 +				</File>
242.2508 +				<File
242.2509 +					RelativePath=".\CPP\7zip\Compress\CopyCoder.cpp"
242.2510 +					>
242.2511 +					<FileConfiguration
242.2512 +						Name="Release|Win32"
242.2513 +						>
242.2514 +						<Tool
242.2515 +							Name="VCCLCompilerTool"
242.2516 +							UsePrecompiledHeader="2"
242.2517 +						/>
242.2518 +					</FileConfiguration>
242.2519 +					<FileConfiguration
242.2520 +						Name="Debug|Win32"
242.2521 +						>
242.2522 +						<Tool
242.2523 +							Name="VCCLCompilerTool"
242.2524 +							UsePrecompiledHeader="2"
242.2525 +						/>
242.2526 +					</FileConfiguration>
242.2527 +				</File>
242.2528 +				<File
242.2529 +					RelativePath=".\CPP\7zip\Compress\LzmaDecoder.cpp"
242.2530 +					>
242.2531 +					<FileConfiguration
242.2532 +						Name="Release|Win32"
242.2533 +						>
242.2534 +						<Tool
242.2535 +							Name="VCCLCompilerTool"
242.2536 +							UsePrecompiledHeader="2"
242.2537 +						/>
242.2538 +					</FileConfiguration>
242.2539 +					<FileConfiguration
242.2540 +						Name="Debug|Win32"
242.2541 +						>
242.2542 +						<Tool
242.2543 +							Name="VCCLCompilerTool"
242.2544 +							UsePrecompiledHeader="2"
242.2545 +						/>
242.2546 +					</FileConfiguration>
242.2547 +				</File>
242.2548 +			</Filter>
242.2549 +		</Filter>
242.2550 +		<Filter
242.2551 +			Name="Crypto"
242.2552 +			>
242.2553 +			<File
242.2554 +				RelativePath=".\CPP\7zip\Crypto\7zAes.cpp"
242.2555 +				>
242.2556 +				<FileConfiguration
242.2557 +					Name="Release|Win32"
242.2558 +					>
242.2559 +					<Tool
242.2560 +						Name="VCCLCompilerTool"
242.2561 +						UsePrecompiledHeader="2"
242.2562 +					/>
242.2563 +				</FileConfiguration>
242.2564 +				<FileConfiguration
242.2565 +					Name="Debug|Win32"
242.2566 +					>
242.2567 +					<Tool
242.2568 +						Name="VCCLCompilerTool"
242.2569 +						UsePrecompiledHeader="2"
242.2570 +					/>
242.2571 +				</FileConfiguration>
242.2572 +			</File>
242.2573 +			<File
242.2574 +				RelativePath=".\CPP\7zip\Crypto\HmacSha1.cpp"
242.2575 +				>
242.2576 +				<FileConfiguration
242.2577 +					Name="Release|Win32"
242.2578 +					>
242.2579 +					<Tool
242.2580 +						Name="VCCLCompilerTool"
242.2581 +						UsePrecompiledHeader="2"
242.2582 +					/>
242.2583 +				</FileConfiguration>
242.2584 +				<FileConfiguration
242.2585 +					Name="Debug|Win32"
242.2586 +					>
242.2587 +					<Tool
242.2588 +						Name="VCCLCompilerTool"
242.2589 +						UsePrecompiledHeader="2"
242.2590 +					/>
242.2591 +				</FileConfiguration>
242.2592 +			</File>
242.2593 +			<File
242.2594 +				RelativePath=".\CPP\7zip\Crypto\MyAes.cpp"
242.2595 +				>
242.2596 +				<FileConfiguration
242.2597 +					Name="Release|Win32"
242.2598 +					>
242.2599 +					<Tool
242.2600 +						Name="VCCLCompilerTool"
242.2601 +						UsePrecompiledHeader="2"
242.2602 +					/>
242.2603 +				</FileConfiguration>
242.2604 +				<FileConfiguration
242.2605 +					Name="Debug|Win32"
242.2606 +					>
242.2607 +					<Tool
242.2608 +						Name="VCCLCompilerTool"
242.2609 +						UsePrecompiledHeader="2"
242.2610 +					/>
242.2611 +				</FileConfiguration>
242.2612 +			</File>
242.2613 +			<File
242.2614 +				RelativePath=".\CPP\7zip\Crypto\Pbkdf2HmacSha1.cpp"
242.2615 +				>
242.2616 +				<FileConfiguration
242.2617 +					Name="Release|Win32"
242.2618 +					>
242.2619 +					<Tool
242.2620 +						Name="VCCLCompilerTool"
242.2621 +						UsePrecompiledHeader="2"
242.2622 +					/>
242.2623 +				</FileConfiguration>
242.2624 +				<FileConfiguration
242.2625 +					Name="Debug|Win32"
242.2626 +					>
242.2627 +					<Tool
242.2628 +						Name="VCCLCompilerTool"
242.2629 +						UsePrecompiledHeader="2"
242.2630 +					/>
242.2631 +				</FileConfiguration>
242.2632 +			</File>
242.2633 +			<File
242.2634 +				RelativePath=".\CPP\7zip\Crypto\RandGen.cpp"
242.2635 +				>
242.2636 +				<FileConfiguration
242.2637 +					Name="Release|Win32"
242.2638 +					>
242.2639 +					<Tool
242.2640 +						Name="VCCLCompilerTool"
242.2641 +						UsePrecompiledHeader="2"
242.2642 +					/>
242.2643 +				</FileConfiguration>
242.2644 +				<FileConfiguration
242.2645 +					Name="Debug|Win32"
242.2646 +					>
242.2647 +					<Tool
242.2648 +						Name="VCCLCompilerTool"
242.2649 +						UsePrecompiledHeader="2"
242.2650 +					/>
242.2651 +				</FileConfiguration>
242.2652 +			</File>
242.2653 +			<File
242.2654 +				RelativePath=".\CPP\7zip\Crypto\Rar20Crypto.cpp"
242.2655 +				>
242.2656 +				<FileConfiguration
242.2657 +					Name="Release|Win32"
242.2658 +					>
242.2659 +					<Tool
242.2660 +						Name="VCCLCompilerTool"
242.2661 +						UsePrecompiledHeader="2"
242.2662 +					/>
242.2663 +				</FileConfiguration>
242.2664 +				<FileConfiguration
242.2665 +					Name="Debug|Win32"
242.2666 +					>
242.2667 +					<Tool
242.2668 +						Name="VCCLCompilerTool"
242.2669 +						UsePrecompiledHeader="2"
242.2670 +					/>
242.2671 +				</FileConfiguration>
242.2672 +			</File>
242.2673 +			<File
242.2674 +				RelativePath=".\CPP\7zip\Crypto\RarAes.cpp"
242.2675 +				>
242.2676 +				<FileConfiguration
242.2677 +					Name="Release|Win32"
242.2678 +					>
242.2679 +					<Tool
242.2680 +						Name="VCCLCompilerTool"
242.2681 +						UsePrecompiledHeader="2"
242.2682 +					/>
242.2683 +				</FileConfiguration>
242.2684 +				<FileConfiguration
242.2685 +					Name="Debug|Win32"
242.2686 +					>
242.2687 +					<Tool
242.2688 +						Name="VCCLCompilerTool"
242.2689 +						UsePrecompiledHeader="2"
242.2690 +					/>
242.2691 +				</FileConfiguration>
242.2692 +			</File>
242.2693 +			<File
242.2694 +				RelativePath=".\CPP\7zip\Crypto\Sha1.cpp"
242.2695 +				>
242.2696 +				<FileConfiguration
242.2697 +					Name="Release|Win32"
242.2698 +					>
242.2699 +					<Tool
242.2700 +						Name="VCCLCompilerTool"
242.2701 +						UsePrecompiledHeader="2"
242.2702 +					/>
242.2703 +				</FileConfiguration>
242.2704 +				<FileConfiguration
242.2705 +					Name="Debug|Win32"
242.2706 +					>
242.2707 +					<Tool
242.2708 +						Name="VCCLCompilerTool"
242.2709 +						UsePrecompiledHeader="2"
242.2710 +					/>
242.2711 +				</FileConfiguration>
242.2712 +			</File>
242.2713 +			<File
242.2714 +				RelativePath=".\CPP\7zip\Crypto\WzAes.cpp"
242.2715 +				>
242.2716 +				<FileConfiguration
242.2717 +					Name="Release|Win32"
242.2718 +					>
242.2719 +					<Tool
242.2720 +						Name="VCCLCompilerTool"
242.2721 +						UsePrecompiledHeader="2"
242.2722 +					/>
242.2723 +				</FileConfiguration>
242.2724 +				<FileConfiguration
242.2725 +					Name="Debug|Win32"
242.2726 +					>
242.2727 +					<Tool
242.2728 +						Name="VCCLCompilerTool"
242.2729 +						UsePrecompiledHeader="2"
242.2730 +					/>
242.2731 +				</FileConfiguration>
242.2732 +			</File>
242.2733 +			<File
242.2734 +				RelativePath=".\CPP\7zip\Crypto\ZipCrypto.cpp"
242.2735 +				>
242.2736 +				<FileConfiguration
242.2737 +					Name="Release|Win32"
242.2738 +					>
242.2739 +					<Tool
242.2740 +						Name="VCCLCompilerTool"
242.2741 +						UsePrecompiledHeader="2"
242.2742 +					/>
242.2743 +				</FileConfiguration>
242.2744 +				<FileConfiguration
242.2745 +					Name="Debug|Win32"
242.2746 +					>
242.2747 +					<Tool
242.2748 +						Name="VCCLCompilerTool"
242.2749 +						UsePrecompiledHeader="2"
242.2750 +					/>
242.2751 +				</FileConfiguration>
242.2752 +			</File>
242.2753 +			<File
242.2754 +				RelativePath=".\CPP\7zip\Crypto\ZipStrong.cpp"
242.2755 +				>
242.2756 +				<FileConfiguration
242.2757 +					Name="Release|Win32"
242.2758 +					>
242.2759 +					<Tool
242.2760 +						Name="VCCLCompilerTool"
242.2761 +						UsePrecompiledHeader="2"
242.2762 +					/>
242.2763 +				</FileConfiguration>
242.2764 +				<FileConfiguration
242.2765 +					Name="Debug|Win32"
242.2766 +					>
242.2767 +					<Tool
242.2768 +						Name="VCCLCompilerTool"
242.2769 +						UsePrecompiledHeader="2"
242.2770 +					/>
242.2771 +				</FileConfiguration>
242.2772 +			</File>
242.2773 +		</Filter>
242.2774 +		<Filter
242.2775 +			Name="Headers"
242.2776 +			>
242.2777 +			<File
242.2778 +				RelativePath=".\CPP\7zip\Crypto\7zAes.h"
242.2779 +				>
242.2780 +			</File>
242.2781 +			<File
242.2782 +				RelativePath=".\CPP\7zip\Archive\7z\7zCompressionMode.h"
242.2783 +				>
242.2784 +			</File>
242.2785 +			<File
242.2786 +				RelativePath=".\C\7zCrc.h"
242.2787 +				>
242.2788 +			</File>
242.2789 +			<File
242.2790 +				RelativePath=".\CPP\7zip\Archive\7z\7zDecode.h"
242.2791 +				>
242.2792 +			</File>
242.2793 +			<File
242.2794 +				RelativePath=".\CPP\7zip\Archive\7z\7zFolderInStream.h"
242.2795 +				>
242.2796 +			</File>
242.2797 +			<File
242.2798 +				RelativePath=".\CPP\7zip\Archive\7z\7zFolderOutStream.h"
242.2799 +				>
242.2800 +			</File>
242.2801 +			<File
242.2802 +				RelativePath=".\CPP\7zip\Archive\7z\7zHandler.h"
242.2803 +				>
242.2804 +			</File>
242.2805 +			<File
242.2806 +				RelativePath=".\CPP\7zip\Archive\7z\7zHeader.h"
242.2807 +				>
242.2808 +			</File>
242.2809 +			<File
242.2810 +				RelativePath=".\CPP\7zip\Archive\7z\7zIn.h"
242.2811 +				>
242.2812 +			</File>
242.2813 +			<File
242.2814 +				RelativePath=".\CPP\7zip\Archive\7z\7zItem.h"
242.2815 +				>
242.2816 +			</File>
242.2817 +			<File
242.2818 +				RelativePath=".\CPP\7zip\Archive\7z\7zProperties.h"
242.2819 +				>
242.2820 +			</File>
242.2821 +			<File
242.2822 +				RelativePath=".\CPP\7zip\Archive\7z\7zSpecStream.h"
242.2823 +				>
242.2824 +			</File>
242.2825 +			<File
242.2826 +				RelativePath=".\C\Aes.h"
242.2827 +				>
242.2828 +			</File>
242.2829 +			<File
242.2830 +				RelativePath=".\C\Alloc.h"
242.2831 +				>
242.2832 +			</File>
242.2833 +			<File
242.2834 +				RelativePath=".\CPP\7zip\Compress\Bcj2Coder.h"
242.2835 +				>
242.2836 +			</File>
242.2837 +			<File
242.2838 +				RelativePath=".\CPP\7zip\Compress\BcjCoder.h"
242.2839 +				>
242.2840 +			</File>
242.2841 +			<File
242.2842 +				RelativePath=".\CPP\7zip\Compress\BitlDecoder.h"
242.2843 +				>
242.2844 +			</File>
242.2845 +			<File
242.2846 +				RelativePath=".\CPP\7zip\Compress\BitmDecoder.h"
242.2847 +				>
242.2848 +			</File>
242.2849 +			<File
242.2850 +				RelativePath=".\C\Bra.h"
242.2851 +				>
242.2852 +			</File>
242.2853 +			<File
242.2854 +				RelativePath=".\CPP\7zip\Compress\BranchCoder.h"
242.2855 +				>
242.2856 +			</File>
242.2857 +			<File
242.2858 +				RelativePath=".\CPP\7zip\Compress\BranchMisc.h"
242.2859 +				>
242.2860 +			</File>
242.2861 +			<File
242.2862 +				RelativePath=".\CPP\Common\Buffer.h"
242.2863 +				>
242.2864 +			</File>
242.2865 +			<File
242.2866 +				RelativePath=".\C\BwtSort.h"
242.2867 +				>
242.2868 +			</File>
242.2869 +			<File
242.2870 +				RelativePath=".\CPP\7zip\Compress\ByteSwap.h"
242.2871 +				>
242.2872 +			</File>
242.2873 +			<File
242.2874 +				RelativePath=".\CPP\7zip\Compress\BZip2Const.h"
242.2875 +				>
242.2876 +			</File>
242.2877 +			<File
242.2878 +				RelativePath=".\CPP\7zip\Compress\BZip2Crc.h"
242.2879 +				>
242.2880 +			</File>
242.2881 +			<File
242.2882 +				RelativePath=".\CPP\7zip\Compress\BZip2Decoder.h"
242.2883 +				>
242.2884 +			</File>
242.2885 +			<File
242.2886 +				RelativePath=".\CPP\7zip\Archive\BZip2\BZip2Handler.h"
242.2887 +				>
242.2888 +			</File>
242.2889 +			<File
242.2890 +				RelativePath=".\CPP\7zip\Archive\BZip2\BZip2Item.h"
242.2891 +				>
242.2892 +			</File>
242.2893 +			<File
242.2894 +				RelativePath=".\CPP\7zip\Archive\Common\CoderMixer2.h"
242.2895 +				>
242.2896 +			</File>
242.2897 +			<File
242.2898 +				RelativePath=".\CPP\7zip\Archive\Common\CoderMixer2MT.h"
242.2899 +				>
242.2900 +			</File>
242.2901 +			<File
242.2902 +				RelativePath=".\CPP\Common\ComTry.h"
242.2903 +				>
242.2904 +			</File>
242.2905 +			<File
242.2906 +				RelativePath=".\CPP\7zip\Compress\CopyCoder.h"
242.2907 +				>
242.2908 +			</File>
242.2909 +			<File
242.2910 +				RelativePath=".\C\CpuArch.h"
242.2911 +				>
242.2912 +			</File>
242.2913 +			<File
242.2914 +				RelativePath=".\CPP\7zip\Common\CreateCoder.h"
242.2915 +				>
242.2916 +			</File>
242.2917 +			<File
242.2918 +				RelativePath=".\CPP\7zip\Common\DeclareArcs.h"
242.2919 +				>
242.2920 +			</File>
242.2921 +			<File
242.2922 +				RelativePath=".\CPP\7zip\Common\DeclareCodecs.h"
242.2923 +				>
242.2924 +			</File>
242.2925 +			<File
242.2926 +				RelativePath=".\CPP\7zip\Compress\DeflateConst.h"
242.2927 +				>
242.2928 +			</File>
242.2929 +			<File
242.2930 +				RelativePath=".\CPP\7zip\Compress\DeflateDecoder.h"
242.2931 +				>
242.2932 +			</File>
242.2933 +			<File
242.2934 +				RelativePath=".\CPP\Windows\Defs.h"
242.2935 +				>
242.2936 +			</File>
242.2937 +			<File
242.2938 +				RelativePath=".\CPP\Common\Defs.h"
242.2939 +				>
242.2940 +			</File>
242.2941 +			<File
242.2942 +				RelativePath=".\CPP\7zip\Archive\Common\DummyOutStream.h"
242.2943 +				>
242.2944 +			</File>
242.2945 +			<File
242.2946 +				RelativePath=".\CPP\Common\DynamicBuffer.h"
242.2947 +				>
242.2948 +			</File>
242.2949 +			<File
242.2950 +				RelativePath=".\CPP\Windows\FileDir.h"
242.2951 +				>
242.2952 +			</File>
242.2953 +			<File
242.2954 +				RelativePath=".\CPP\Windows\FileFind.h"
242.2955 +				>
242.2956 +			</File>
242.2957 +			<File
242.2958 +				RelativePath=".\CPP\Windows\FileIO.h"
242.2959 +				>
242.2960 +			</File>
242.2961 +			<File
242.2962 +				RelativePath=".\CPP\Windows\FileName.h"
242.2963 +				>
242.2964 +			</File>
242.2965 +			<File
242.2966 +				RelativePath=".\CPP\7zip\Common\FilterCoder.h"
242.2967 +				>
242.2968 +			</File>
242.2969 +			<File
242.2970 +				RelativePath=".\CPP\7zip\Archive\Common\FindSignature.h"
242.2971 +				>
242.2972 +			</File>
242.2973 +			<File
242.2974 +				RelativePath=".\CPP\7zip\Archive\GZip\GZipHandler.h"
242.2975 +				>
242.2976 +			</File>
242.2977 +			<File
242.2978 +				RelativePath=".\CPP\7zip\Archive\GZip\GZipHeader.h"
242.2979 +				>
242.2980 +			</File>
242.2981 +			<File
242.2982 +				RelativePath=".\CPP\7zip\Archive\GZip\GZipIn.h"
242.2983 +				>
242.2984 +			</File>
242.2985 +			<File
242.2986 +				RelativePath=".\CPP\7zip\Archive\GZip\GZipItem.h"
242.2987 +				>
242.2988 +			</File>
242.2989 +			<File
242.2990 +				RelativePath=".\CPP\7zip\Archive\GZip\GZipUpdate.h"
242.2991 +				>
242.2992 +			</File>
242.2993 +			<File
242.2994 +				RelativePath=".\CPP\Windows\Handle.h"
242.2995 +				>
242.2996 +			</File>
242.2997 +			<File
242.2998 +				RelativePath=".\CPP\7zip\Crypto\HmacSha1.h"
242.2999 +				>
242.3000 +			</File>
242.3001 +			<File
242.3002 +				RelativePath=".\C\HuffEnc.h"
242.3003 +				>
242.3004 +			</File>
242.3005 +			<File
242.3006 +				RelativePath=".\CPP\7zip\Compress\HuffmanDecoder.h"
242.3007 +				>
242.3008 +			</File>
242.3009 +			<File
242.3010 +				RelativePath=".\CPP\7zip\Archive\IArchive.h"
242.3011 +				>
242.3012 +			</File>
242.3013 +			<File
242.3014 +				RelativePath=".\CPP\7zip\ICoder.h"
242.3015 +				>
242.3016 +			</File>
242.3017 +			<File
242.3018 +				RelativePath=".\CPP\7zip\IDecl.h"
242.3019 +				>
242.3020 +			</File>
242.3021 +			<File
242.3022 +				RelativePath=".\CPP\7zip\Compress\ImplodeDecoder.h"
242.3023 +				>
242.3024 +			</File>
242.3025 +			<File
242.3026 +				RelativePath=".\CPP\7zip\Compress\ImplodeHuffmanDecoder.h"
242.3027 +				>
242.3028 +			</File>
242.3029 +			<File
242.3030 +				RelativePath=".\CPP\7zip\Common\InBuffer.h"
242.3031 +				>
242.3032 +			</File>
242.3033 +			<File
242.3034 +				RelativePath=".\CPP\Common\InitializeStaticLib.h"
242.3035 +				>
242.3036 +			</File>
242.3037 +			<File
242.3038 +				RelativePath=".\CPP\7zip\Common\InOutTempBuffer.h"
242.3039 +				>
242.3040 +			</File>
242.3041 +			<File
242.3042 +				RelativePath=".\CPP\7zip\Archive\Common\InStreamWithCRC.h"
242.3043 +				>
242.3044 +			</File>
242.3045 +			<File
242.3046 +				RelativePath=".\CPP\Common\IntToString.h"
242.3047 +				>
242.3048 +			</File>
242.3049 +			<File
242.3050 +				RelativePath=".\CPP\7zip\IPassword.h"
242.3051 +				>
242.3052 +			</File>
242.3053 +			<File
242.3054 +				RelativePath=".\CPP\7zip\IProgress.h"
242.3055 +				>
242.3056 +			</File>
242.3057 +			<File
242.3058 +				RelativePath=".\CPP\7zip\IStream.h"
242.3059 +				>
242.3060 +			</File>
242.3061 +			<File
242.3062 +				RelativePath=".\CPP\7zip\Archive\Common\ItemNameUtils.h"
242.3063 +				>
242.3064 +			</File>
242.3065 +			<File
242.3066 +				RelativePath=".\CPP\7zip\Common\LimitedStreams.h"
242.3067 +				>
242.3068 +			</File>
242.3069 +			<File
242.3070 +				RelativePath=".\CPP\7zip\Common\LockedStream.h"
242.3071 +				>
242.3072 +			</File>
242.3073 +			<File
242.3074 +				RelativePath=".\C\LzFind.h"
242.3075 +				>
242.3076 +			</File>
242.3077 +			<File
242.3078 +				RelativePath=".\C\LzFindMt.h"
242.3079 +				>
242.3080 +			</File>
242.3081 +			<File
242.3082 +				RelativePath=".\C\LzHash.h"
242.3083 +				>
242.3084 +			</File>
242.3085 +			<File
242.3086 +				RelativePath=".\CPP\7zip\Archive\Lzh\LzhCRC.h"
242.3087 +				>
242.3088 +			</File>
242.3089 +			<File
242.3090 +				RelativePath=".\CPP\7zip\Compress\LzhDecoder.h"
242.3091 +				>
242.3092 +			</File>
242.3093 +			<File
242.3094 +				RelativePath=".\CPP\7zip\Archive\Lzh\LzhHandler.h"
242.3095 +				>
242.3096 +			</File>
242.3097 +			<File
242.3098 +				RelativePath=".\CPP\7zip\Archive\Lzh\LzhHeader.h"
242.3099 +				>
242.3100 +			</File>
242.3101 +			<File
242.3102 +				RelativePath=".\CPP\7zip\Archive\Lzh\LzhIn.h"
242.3103 +				>
242.3104 +			</File>
242.3105 +			<File
242.3106 +				RelativePath=".\CPP\7zip\Archive\Lzh\LzhItem.h"
242.3107 +				>
242.3108 +			</File>
242.3109 +			<File
242.3110 +				RelativePath=".\CPP\7zip\Archive\Lzh\LzhOutStreamWithCRC.h"
242.3111 +				>
242.3112 +			</File>
242.3113 +			<File
242.3114 +				RelativePath=".\C\LzmaDec.h"
242.3115 +				>
242.3116 +			</File>
242.3117 +			<File
242.3118 +				RelativePath=".\CPP\7zip\Compress\LzmaDecoder.h"
242.3119 +				>
242.3120 +			</File>
242.3121 +			<File
242.3122 +				RelativePath=".\C\LzmaEnc.h"
242.3123 +				>
242.3124 +			</File>
242.3125 +			<File
242.3126 +				RelativePath=".\CPP\7zip\Archive\Lzma\LzmaFiltersDecode.h"
242.3127 +				>
242.3128 +			</File>
242.3129 +			<File
242.3130 +				RelativePath=".\CPP\7zip\Archive\Lzma\LzmaHandler.h"
242.3131 +				>
242.3132 +			</File>
242.3133 +			<File
242.3134 +				RelativePath=".\CPP\7zip\Archive\Lzma\LzmaIn.h"
242.3135 +				>
242.3136 +			</File>
242.3137 +			<File
242.3138 +				RelativePath=".\CPP\7zip\Archive\Lzma\LzmaItem.h"
242.3139 +				>
242.3140 +			</File>
242.3141 +			<File
242.3142 +				RelativePath=".\CPP\7zip\Compress\LzOutWindow.h"
242.3143 +				>
242.3144 +			</File>
242.3145 +			<File
242.3146 +				RelativePath=".\CPP\7zip\Common\MemBlocks.h"
242.3147 +				>
242.3148 +			</File>
242.3149 +			<File
242.3150 +				RelativePath=".\CPP\7zip\Common\MethodId.h"
242.3151 +				>
242.3152 +			</File>
242.3153 +			<File
242.3154 +				RelativePath=".\CPP\7zip\Common\MethodProps.h"
242.3155 +				>
242.3156 +			</File>
242.3157 +			<File
242.3158 +				RelativePath=".\CPP\7zip\Compress\Mtf8.h"
242.3159 +				>
242.3160 +			</File>
242.3161 +			<File
242.3162 +				RelativePath=".\CPP\7zip\Archive\Common\MultiStream.h"
242.3163 +				>
242.3164 +			</File>
242.3165 +			<File
242.3166 +				RelativePath=".\CPP\7zip\Crypto\MyAes.h"
242.3167 +				>
242.3168 +			</File>
242.3169 +			<File
242.3170 +				RelativePath=".\CPP\Common\MyCom.h"
242.3171 +				>
242.3172 +			</File>
242.3173 +			<File
242.3174 +				RelativePath=".\CPP\Common\MyException.h"
242.3175 +				>
242.3176 +			</File>
242.3177 +			<File
242.3178 +				RelativePath=".\CPP\Common\MyInitGuid.h"
242.3179 +				>
242.3180 +			</File>
242.3181 +			<File
242.3182 +				RelativePath=".\CPP\Common\MyMap.h"
242.3183 +				>
242.3184 +			</File>
242.3185 +			<File
242.3186 +				RelativePath=".\CPP\Common\MyString.h"
242.3187 +				>
242.3188 +			</File>
242.3189 +			<File
242.3190 +				RelativePath=".\CPP\Common\MyUnknown.h"
242.3191 +				>
242.3192 +			</File>
242.3193 +			<File
242.3194 +				RelativePath=".\CPP\Common\MyVector.h"
242.3195 +				>
242.3196 +			</File>
242.3197 +			<File
242.3198 +				RelativePath=".\CPP\Common\MyWindows.h"
242.3199 +				>
242.3200 +			</File>
242.3201 +			<File
242.3202 +				RelativePath=".\CPP\Common\MyXml.h"
242.3203 +				>
242.3204 +			</File>
242.3205 +			<File
242.3206 +				RelativePath=".\CPP\Common\NewHandler.h"
242.3207 +				>
242.3208 +			</File>
242.3209 +			<File
242.3210 +				RelativePath=".\CPP\7zip\Common\OffsetStream.h"
242.3211 +				>
242.3212 +			</File>
242.3213 +			<File
242.3214 +				RelativePath=".\CPP\7zip\Common\OutBuffer.h"
242.3215 +				>
242.3216 +			</File>
242.3217 +			<File
242.3218 +				RelativePath=".\CPP\7zip\Common\OutMemStream.h"
242.3219 +				>
242.3220 +			</File>
242.3221 +			<File
242.3222 +				RelativePath=".\CPP\7zip\Archive\Common\OutStreamWithCRC.h"
242.3223 +				>
242.3224 +			</File>
242.3225 +			<File
242.3226 +				RelativePath=".\CPP\7zip\Archive\Common\ParseProperties.h"
242.3227 +				>
242.3228 +			</File>
242.3229 +			<File
242.3230 +				RelativePath=".\CPP\7zip\Crypto\Pbkdf2HmacSha1.h"
242.3231 +				>
242.3232 +			</File>
242.3233 +			<File
242.3234 +				RelativePath=".\CPP\7zip\Compress\PpmdContext.h"
242.3235 +				>
242.3236 +			</File>
242.3237 +			<File
242.3238 +				RelativePath=".\CPP\7zip\Compress\PpmdDecode.h"
242.3239 +				>
242.3240 +			</File>
242.3241 +			<File
242.3242 +				RelativePath=".\CPP\7zip\Compress\PpmdDecoder.h"
242.3243 +				>
242.3244 +			</File>
242.3245 +			<File
242.3246 +				RelativePath=".\CPP\7zip\Compress\PpmdSubAlloc.h"
242.3247 +				>
242.3248 +			</File>
242.3249 +			<File
242.3250 +				RelativePath=".\CPP\7zip\Compress\PpmdType.h"
242.3251 +				>
242.3252 +			</File>
242.3253 +			<File
242.3254 +				RelativePath=".\CPP\7zip\Common\ProgressMt.h"
242.3255 +				>
242.3256 +			</File>
242.3257 +			<File
242.3258 +				RelativePath=".\CPP\7zip\Common\ProgressUtils.h"
242.3259 +				>
242.3260 +			</File>
242.3261 +			<File
242.3262 +				RelativePath=".\CPP\7zip\PropID.h"
242.3263 +				>
242.3264 +			</File>
242.3265 +			<File
242.3266 +				RelativePath=".\CPP\Windows\PropVariant.h"
242.3267 +				>
242.3268 +			</File>
242.3269 +			<File
242.3270 +				RelativePath=".\CPP\7zip\Crypto\RandGen.h"
242.3271 +				>
242.3272 +			</File>
242.3273 +			<File
242.3274 +				RelativePath=".\CPP\7zip\Compress\RangeCoder.h"
242.3275 +				>
242.3276 +			</File>
242.3277 +			<File
242.3278 +				RelativePath=".\CPP\7zip\Compress\RangeCoderBit.h"
242.3279 +				>
242.3280 +			</File>
242.3281 +			<File
242.3282 +				RelativePath=".\CPP\7zip\Compress\Rar1Decoder.h"
242.3283 +				>
242.3284 +			</File>
242.3285 +			<File
242.3286 +				RelativePath=".\CPP\7zip\Crypto\Rar20Crypto.h"
242.3287 +				>
242.3288 +			</File>
242.3289 +			<File
242.3290 +				RelativePath=".\CPP\7zip\Compress\Rar2Decoder.h"
242.3291 +				>
242.3292 +			</File>
242.3293 +			<File
242.3294 +				RelativePath=".\CPP\7zip\Compress\Rar3Decoder.h"
242.3295 +				>
242.3296 +			</File>
242.3297 +			<File
242.3298 +				RelativePath=".\CPP\7zip\Compress\Rar3Vm.h"
242.3299 +				>
242.3300 +			</File>
242.3301 +			<File
242.3302 +				RelativePath=".\CPP\7zip\Crypto\RarAes.h"
242.3303 +				>
242.3304 +			</File>
242.3305 +			<File
242.3306 +				RelativePath=".\CPP\7zip\Archive\Rar\RarHandler.h"
242.3307 +				>
242.3308 +			</File>
242.3309 +			<File
242.3310 +				RelativePath=".\CPP\7zip\Archive\Rar\RarHeader.h"
242.3311 +				>
242.3312 +			</File>
242.3313 +			<File
242.3314 +				RelativePath=".\CPP\7zip\Archive\Rar\RarIn.h"
242.3315 +				>
242.3316 +			</File>
242.3317 +			<File
242.3318 +				RelativePath=".\CPP\7zip\Archive\Rar\RarItem.h"
242.3319 +				>
242.3320 +			</File>
242.3321 +			<File
242.3322 +				RelativePath=".\CPP\7zip\Archive\Rar\RarVolumeInStream.h"
242.3323 +				>
242.3324 +			</File>
242.3325 +			<File
242.3326 +				RelativePath=".\CPP\7zip\Common\RegisterArc.h"
242.3327 +				>
242.3328 +			</File>
242.3329 +			<File
242.3330 +				RelativePath=".\CPP\7zip\Common\RegisterCodec.h"
242.3331 +				>
242.3332 +			</File>
242.3333 +			<File
242.3334 +				RelativePath=".\C\RotateDefs.h"
242.3335 +				>
242.3336 +			</File>
242.3337 +			<File
242.3338 +				RelativePath=".\CPP\7zip\Crypto\Sha1.h"
242.3339 +				>
242.3340 +			</File>
242.3341 +			<File
242.3342 +				RelativePath=".\C\Sha256.h"
242.3343 +				>
242.3344 +			</File>
242.3345 +			<File
242.3346 +				RelativePath=".\CPP\7zip\Compress\ShrinkDecoder.h"
242.3347 +				>
242.3348 +			</File>
242.3349 +			<File
242.3350 +				RelativePath=".\C\Sort.h"
242.3351 +				>
242.3352 +			</File>
242.3353 +			<File
242.3354 +				RelativePath=".\CPP\7zip\Archive\Split\SplitHandler.h"
242.3355 +				>
242.3356 +			</File>
242.3357 +			<File
242.3358 +				RelativePath=".\CPP\7zip\Archive\Common\StdAfx.h"
242.3359 +				>
242.3360 +			</File>
242.3361 +			<File
242.3362 +				RelativePath=".\CPP\7zip\Archive\Rar\StdAfx.h"
242.3363 +				>
242.3364 +			</File>
242.3365 +			<File
242.3366 +				RelativePath=".\CPP\7zip\Archive\BZip2\StdAfx.h"
242.3367 +				>
242.3368 +			</File>
242.3369 +			<File
242.3370 +				RelativePath=".\CPP\Windows\StdAfx.h"
242.3371 +				>
242.3372 +			</File>
242.3373 +			<File
242.3374 +				RelativePath=".\CPP\7zip\Archive\7z\StdAfx.h"
242.3375 +				>
242.3376 +			</File>
242.3377 +			<File
242.3378 +				RelativePath=".\CPP\7zip\Archive\StdAfx.h"
242.3379 +				>
242.3380 +			</File>
242.3381 +			<File
242.3382 +				RelativePath=".\CPP\7zip\Compress\StdAfx.h"
242.3383 +				>
242.3384 +			</File>
242.3385 +			<File
242.3386 +				RelativePath=".\CPP\7zip\Bundles\Format7zF\StdAfx.h"
242.3387 +				>
242.3388 +			</File>
242.3389 +			<File
242.3390 +				RelativePath=".\CPP\7zip\Archive\GZip\StdAfx.h"
242.3391 +				>
242.3392 +			</File>
242.3393 +			<File
242.3394 +				RelativePath=".\CPP\7zip\Crypto\StdAfx.h"
242.3395 +				>
242.3396 +			</File>
242.3397 +			<File
242.3398 +				RelativePath=".\CPP\7zip\Archive\Tar\StdAfx.h"
242.3399 +				>
242.3400 +			</File>
242.3401 +			<File
242.3402 +				RelativePath=".\CPP\7zip\Archive\Zip\StdAfx.h"
242.3403 +				>
242.3404 +			</File>
242.3405 +			<File
242.3406 +				RelativePath=".\CPP\7zip\Archive\Lzh\StdAfx.h"
242.3407 +				>
242.3408 +			</File>
242.3409 +			<File
242.3410 +				RelativePath=".\CPP\7zip\Common\StdAfx.h"
242.3411 +				>
242.3412 +			</File>
242.3413 +			<File
242.3414 +				RelativePath=".\CPP\7zip\Archive\Split\StdAfx.h"
242.3415 +				>
242.3416 +			</File>
242.3417 +			<File
242.3418 +				RelativePath=".\CPP\7zip\Archive\Lzma\StdAfx.h"
242.3419 +				>
242.3420 +			</File>
242.3421 +			<File
242.3422 +				RelativePath=".\CPP\7zip\Common\StreamBinder.h"
242.3423 +				>
242.3424 +			</File>
242.3425 +			<File
242.3426 +				RelativePath=".\CPP\7zip\Common\StreamObjects.h"
242.3427 +				>
242.3428 +			</File>
242.3429 +			<File
242.3430 +				RelativePath=".\CPP\7zip\Common\StreamUtils.h"
242.3431 +				>
242.3432 +			</File>
242.3433 +			<File
242.3434 +				RelativePath=".\CPP\Common\StringConvert.h"
242.3435 +				>
242.3436 +			</File>
242.3437 +			<File
242.3438 +				RelativePath=".\CPP\Common\StringToInt.h"
242.3439 +				>
242.3440 +			</File>
242.3441 +			<File
242.3442 +				RelativePath=".\CPP\Windows\Synchronization.h"
242.3443 +				>
242.3444 +			</File>
242.3445 +			<File
242.3446 +				RelativePath=".\CPP\7zip\Archive\Tar\TarHandler.h"
242.3447 +				>
242.3448 +			</File>
242.3449 +			<File
242.3450 +				RelativePath=".\CPP\7zip\Archive\Tar\TarHeader.h"
242.3451 +				>
242.3452 +			</File>
242.3453 +			<File
242.3454 +				RelativePath=".\CPP\7zip\Archive\Tar\TarIn.h"
242.3455 +				>
242.3456 +			</File>
242.3457 +			<File
242.3458 +				RelativePath=".\CPP\7zip\Archive\Tar\TarItem.h"
242.3459 +				>
242.3460 +			</File>
242.3461 +			<File
242.3462 +				RelativePath=".\CPP\Windows\Thread.h"
242.3463 +				>
242.3464 +			</File>
242.3465 +			<File
242.3466 +				RelativePath=".\C\Threads.h"
242.3467 +				>
242.3468 +			</File>
242.3469 +			<File
242.3470 +				RelativePath=".\CPP\Windows\Time.h"
242.3471 +				>
242.3472 +			</File>
242.3473 +			<File
242.3474 +				RelativePath=".\CPP\Common\Types.h"
242.3475 +				>
242.3476 +			</File>
242.3477 +			<File
242.3478 +				RelativePath=".\C\Types.h"
242.3479 +				>
242.3480 +			</File>
242.3481 +			<File
242.3482 +				RelativePath=".\CPP\Common\UTFConvert.h"
242.3483 +				>
242.3484 +			</File>
242.3485 +			<File
242.3486 +				RelativePath=".\CPP\7zip\Common\VirtThread.h"
242.3487 +				>
242.3488 +			</File>
242.3489 +			<File
242.3490 +				RelativePath=".\CPP\Common\Wildcard.h"
242.3491 +				>
242.3492 +			</File>
242.3493 +			<File
242.3494 +				RelativePath=".\CPP\7zip\Crypto\WzAes.h"
242.3495 +				>
242.3496 +			</File>
242.3497 +			<File
242.3498 +				RelativePath=".\CPP\7zip\Archive\Zip\ZipCompressionMode.h"
242.3499 +				>
242.3500 +			</File>
242.3501 +			<File
242.3502 +				RelativePath=".\CPP\7zip\Crypto\ZipCrypto.h"
242.3503 +				>
242.3504 +			</File>
242.3505 +			<File
242.3506 +				RelativePath=".\CPP\7zip\Archive\Zip\ZipHandler.h"
242.3507 +				>
242.3508 +			</File>
242.3509 +			<File
242.3510 +				RelativePath=".\CPP\7zip\Archive\Zip\ZipHeader.h"
242.3511 +				>
242.3512 +			</File>
242.3513 +			<File
242.3514 +				RelativePath=".\CPP\7zip\Archive\Zip\ZipIn.h"
242.3515 +				>
242.3516 +			</File>
242.3517 +			<File
242.3518 +				RelativePath=".\CPP\7zip\Archive\Zip\ZipItem.h"
242.3519 +				>
242.3520 +			</File>
242.3521 +			<File
242.3522 +				RelativePath=".\CPP\7zip\Archive\Zip\ZipItemEx.h"
242.3523 +				>
242.3524 +			</File>
242.3525 +			<File
242.3526 +				RelativePath=".\CPP\7zip\Crypto\ZipStrong.h"
242.3527 +				>
242.3528 +			</File>
242.3529 +			<File
242.3530 +				RelativePath=".\CPP\7zip\Compress\ZlibDecoder.h"
242.3531 +				>
242.3532 +			</File>
242.3533 +		</Filter>
242.3534 +		<Filter
242.3535 +			Name="Register"
242.3536 +			>
242.3537 +			<File
242.3538 +				RelativePath=".\CPP\7zip\Crypto\7zAesRegister.cpp"
242.3539 +				>
242.3540 +				<FileConfiguration
242.3541 +					Name="Release|Win32"
242.3542 +					>
242.3543 +					<Tool
242.3544 +						Name="VCCLCompilerTool"
242.3545 +						UsePrecompiledHeader="2"
242.3546 +					/>
242.3547 +				</FileConfiguration>
242.3548 +				<FileConfiguration
242.3549 +					Name="Debug|Win32"
242.3550 +					>
242.3551 +					<Tool
242.3552 +						Name="VCCLCompilerTool"
242.3553 +						UsePrecompiledHeader="2"
242.3554 +					/>
242.3555 +				</FileConfiguration>
242.3556 +			</File>
242.3557 +			<File
242.3558 +				RelativePath=".\CPP\7zip\Archive\7z\7zRegister.cpp"
242.3559 +				>
242.3560 +				<FileConfiguration
242.3561 +					Name="Release|Win32"
242.3562 +					>
242.3563 +					<Tool
242.3564 +						Name="VCCLCompilerTool"
242.3565 +						UsePrecompiledHeader="2"
242.3566 +					/>
242.3567 +				</FileConfiguration>
242.3568 +				<FileConfiguration
242.3569 +					Name="Debug|Win32"
242.3570 +					>
242.3571 +					<Tool
242.3572 +						Name="VCCLCompilerTool"
242.3573 +						UsePrecompiledHeader="2"
242.3574 +					/>
242.3575 +				</FileConfiguration>
242.3576 +			</File>
242.3577 +			<File
242.3578 +				RelativePath=".\CPP\7zip\Archive\ArchiveExports.cpp"
242.3579 +				>
242.3580 +				<FileConfiguration
242.3581 +					Name="Release|Win32"
242.3582 +					>
242.3583 +					<Tool
242.3584 +						Name="VCCLCompilerTool"
242.3585 +						UsePrecompiledHeader="1"
242.3586 +					/>
242.3587 +				</FileConfiguration>
242.3588 +				<FileConfiguration
242.3589 +					Name="Debug|Win32"
242.3590 +					>
242.3591 +					<Tool
242.3592 +						Name="VCCLCompilerTool"
242.3593 +						UsePrecompiledHeader="1"
242.3594 +					/>
242.3595 +				</FileConfiguration>
242.3596 +			</File>
242.3597 +			<File
242.3598 +				RelativePath=".\CPP\7zip\Compress\Bcj2Register.cpp"
242.3599 +				>
242.3600 +				<FileConfiguration
242.3601 +					Name="Release|Win32"
242.3602 +					>
242.3603 +					<Tool
242.3604 +						Name="VCCLCompilerTool"
242.3605 +						UsePrecompiledHeader="2"
242.3606 +					/>
242.3607 +				</FileConfiguration>
242.3608 +				<FileConfiguration
242.3609 +					Name="Debug|Win32"
242.3610 +					>
242.3611 +					<Tool
242.3612 +						Name="VCCLCompilerTool"
242.3613 +						UsePrecompiledHeader="2"
242.3614 +					/>
242.3615 +				</FileConfiguration>
242.3616 +			</File>
242.3617 +			<File
242.3618 +				RelativePath=".\CPP\7zip\Compress\BcjRegister.cpp"
242.3619 +				>
242.3620 +				<FileConfiguration
242.3621 +					Name="Release|Win32"
242.3622 +					>
242.3623 +					<Tool
242.3624 +						Name="VCCLCompilerTool"
242.3625 +						UsePrecompiledHeader="2"
242.3626 +					/>
242.3627 +				</FileConfiguration>
242.3628 +				<FileConfiguration
242.3629 +					Name="Debug|Win32"
242.3630 +					>
242.3631 +					<Tool
242.3632 +						Name="VCCLCompilerTool"
242.3633 +						UsePrecompiledHeader="2"
242.3634 +					/>
242.3635 +				</FileConfiguration>
242.3636 +			</File>
242.3637 +			<File
242.3638 +				RelativePath=".\CPP\7zip\Compress\BranchRegister.cpp"
242.3639 +				>
242.3640 +				<FileConfiguration
242.3641 +					Name="Release|Win32"
242.3642 +					>
242.3643 +					<Tool
242.3644 +						Name="VCCLCompilerTool"
242.3645 +						UsePrecompiledHeader="2"
242.3646 +					/>
242.3647 +				</FileConfiguration>
242.3648 +				<FileConfiguration
242.3649 +					Name="Debug|Win32"
242.3650 +					>
242.3651 +					<Tool
242.3652 +						Name="VCCLCompilerTool"
242.3653 +						UsePrecompiledHeader="2"
242.3654 +					/>
242.3655 +				</FileConfiguration>
242.3656 +			</File>
242.3657 +			<File
242.3658 +				RelativePath=".\CPP\7zip\Compress\ByteSwapRegister.cpp"
242.3659 +				>
242.3660 +				<FileConfiguration
242.3661 +					Name="Release|Win32"
242.3662 +					>
242.3663 +					<Tool
242.3664 +						Name="VCCLCompilerTool"
242.3665 +						UsePrecompiledHeader="2"
242.3666 +					/>
242.3667 +				</FileConfiguration>
242.3668 +				<FileConfiguration
242.3669 +					Name="Debug|Win32"
242.3670 +					>
242.3671 +					<Tool
242.3672 +						Name="VCCLCompilerTool"
242.3673 +						UsePrecompiledHeader="2"
242.3674 +					/>
242.3675 +				</FileConfiguration>
242.3676 +			</File>
242.3677 +			<File
242.3678 +				RelativePath=".\CPP\7zip\Archive\BZip2\bz2Register.cpp"
242.3679 +				>
242.3680 +				<FileConfiguration
242.3681 +					Name="Release|Win32"
242.3682 +					>
242.3683 +					<Tool
242.3684 +						Name="VCCLCompilerTool"
242.3685 +						UsePrecompiledHeader="2"
242.3686 +					/>
242.3687 +				</FileConfiguration>
242.3688 +				<FileConfiguration
242.3689 +					Name="Debug|Win32"
242.3690 +					>
242.3691 +					<Tool
242.3692 +						Name="VCCLCompilerTool"
242.3693 +						UsePrecompiledHeader="2"
242.3694 +					/>
242.3695 +				</FileConfiguration>
242.3696 +			</File>
242.3697 +			<File
242.3698 +				RelativePath=".\CPP\7zip\Compress\BZip2Register.cpp"
242.3699 +				>
242.3700 +				<FileConfiguration
242.3701 +					Name="Release|Win32"
242.3702 +					>
242.3703 +					<Tool
242.3704 +						Name="VCCLCompilerTool"
242.3705 +						UsePrecompiledHeader="2"
242.3706 +					/>
242.3707 +				</FileConfiguration>
242.3708 +				<FileConfiguration
242.3709 +					Name="Debug|Win32"
242.3710 +					>
242.3711 +					<Tool
242.3712 +						Name="VCCLCompilerTool"
242.3713 +						UsePrecompiledHeader="2"
242.3714 +					/>
242.3715 +				</FileConfiguration>
242.3716 +			</File>
242.3717 +			<File
242.3718 +				RelativePath=".\CPP\7zip\Compress\CodecExports.cpp"
242.3719 +				>
242.3720 +				<FileConfiguration
242.3721 +					Name="Release|Win32"
242.3722 +					>
242.3723 +					<Tool
242.3724 +						Name="VCCLCompilerTool"
242.3725 +						UsePrecompiledHeader="2"
242.3726 +					/>
242.3727 +				</FileConfiguration>
242.3728 +				<FileConfiguration
242.3729 +					Name="Debug|Win32"
242.3730 +					>
242.3731 +					<Tool
242.3732 +						Name="VCCLCompilerTool"
242.3733 +						UsePrecompiledHeader="2"
242.3734 +					/>
242.3735 +				</FileConfiguration>
242.3736 +			</File>
242.3737 +			<File
242.3738 +				RelativePath=".\CPP\7zip\Compress\CopyRegister.cpp"
242.3739 +				>
242.3740 +				<FileConfiguration
242.3741 +					Name="Release|Win32"
242.3742 +					>
242.3743 +					<Tool
242.3744 +						Name="VCCLCompilerTool"
242.3745 +						UsePrecompiledHeader="2"
242.3746 +					/>
242.3747 +				</FileConfiguration>
242.3748 +				<FileConfiguration
242.3749 +					Name="Debug|Win32"
242.3750 +					>
242.3751 +					<Tool
242.3752 +						Name="VCCLCompilerTool"
242.3753 +						UsePrecompiledHeader="2"
242.3754 +					/>
242.3755 +				</FileConfiguration>
242.3756 +			</File>
242.3757 +			<File
242.3758 +				RelativePath=".\CPP\7zip\Common\CreateCoder.cpp"
242.3759 +				>
242.3760 +				<FileConfiguration
242.3761 +					Name="Release|Win32"
242.3762 +					>
242.3763 +					<Tool
242.3764 +						Name="VCCLCompilerTool"
242.3765 +						UsePrecompiledHeader="2"
242.3766 +					/>
242.3767 +				</FileConfiguration>
242.3768 +				<FileConfiguration
242.3769 +					Name="Debug|Win32"
242.3770 +					>
242.3771 +					<Tool
242.3772 +						Name="VCCLCompilerTool"
242.3773 +						UsePrecompiledHeader="2"
242.3774 +					/>
242.3775 +				</FileConfiguration>
242.3776 +			</File>
242.3777 +			<File
242.3778 +				RelativePath=".\CPP\7zip\Compress\Deflate64Register.cpp"
242.3779 +				>
242.3780 +				<FileConfiguration
242.3781 +					Name="Release|Win32"
242.3782 +					>
242.3783 +					<Tool
242.3784 +						Name="VCCLCompilerTool"
242.3785 +						UsePrecompiledHeader="2"
242.3786 +					/>
242.3787 +				</FileConfiguration>
242.3788 +				<FileConfiguration
242.3789 +					Name="Debug|Win32"
242.3790 +					>
242.3791 +					<Tool
242.3792 +						Name="VCCLCompilerTool"
242.3793 +						UsePrecompiledHeader="2"
242.3794 +					/>
242.3795 +				</FileConfiguration>
242.3796 +			</File>
242.3797 +			<File
242.3798 +				RelativePath=".\CPP\7zip\Compress\DeflateNsisRegister.cpp"
242.3799 +				>
242.3800 +				<FileConfiguration
242.3801 +					Name="Release|Win32"
242.3802 +					>
242.3803 +					<Tool
242.3804 +						Name="VCCLCompilerTool"
242.3805 +						UsePrecompiledHeader="2"
242.3806 +					/>
242.3807 +				</FileConfiguration>
242.3808 +				<FileConfiguration
242.3809 +					Name="Debug|Win32"
242.3810 +					>
242.3811 +					<Tool
242.3812 +						Name="VCCLCompilerTool"
242.3813 +						UsePrecompiledHeader="2"
242.3814 +					/>
242.3815 +				</FileConfiguration>
242.3816 +			</File>
242.3817 +			<File
242.3818 +				RelativePath=".\CPP\7zip\Compress\DeflateRegister.cpp"
242.3819 +				>
242.3820 +				<FileConfiguration
242.3821 +					Name="Release|Win32"
242.3822 +					>
242.3823 +					<Tool
242.3824 +						Name="VCCLCompilerTool"
242.3825 +						UsePrecompiledHeader="2"
242.3826 +					/>
242.3827 +				</FileConfiguration>
242.3828 +				<FileConfiguration
242.3829 +					Name="Debug|Win32"
242.3830 +					>
242.3831 +					<Tool
242.3832 +						Name="VCCLCompilerTool"
242.3833 +						UsePrecompiledHeader="2"
242.3834 +					/>
242.3835 +				</FileConfiguration>
242.3836 +			</File>
242.3837 +			<File
242.3838 +				RelativePath=".\CPP\7zip\Archive\DllExports2.cpp"
242.3839 +				>
242.3840 +				<FileConfiguration
242.3841 +					Name="Release|Win32"
242.3842 +					>
242.3843 +					<Tool
242.3844 +						Name="VCCLCompilerTool"
242.3845 +						UsePrecompiledHeader="2"
242.3846 +					/>
242.3847 +				</FileConfiguration>
242.3848 +				<FileConfiguration
242.3849 +					Name="Debug|Win32"
242.3850 +					>
242.3851 +					<Tool
242.3852 +						Name="VCCLCompilerTool"
242.3853 +						UsePrecompiledHeader="2"
242.3854 +					/>
242.3855 +				</FileConfiguration>
242.3856 +			</File>
242.3857 +			<File
242.3858 +				RelativePath=".\CPP\7zip\Archive\GZip\GZipRegister.cpp"
242.3859 +				>
242.3860 +				<FileConfiguration
242.3861 +					Name="Release|Win32"
242.3862 +					>
242.3863 +					<Tool
242.3864 +						Name="VCCLCompilerTool"
242.3865 +						UsePrecompiledHeader="2"
242.3866 +					/>
242.3867 +				</FileConfiguration>
242.3868 +				<FileConfiguration
242.3869 +					Name="Debug|Win32"
242.3870 +					>
242.3871 +					<Tool
242.3872 +						Name="VCCLCompilerTool"
242.3873 +						UsePrecompiledHeader="2"
242.3874 +					/>
242.3875 +				</FileConfiguration>
242.3876 +			</File>
242.3877 +			<File
242.3878 +				RelativePath=".\CPP\7zip\Archive\Lzh\LzhRegister.cpp"
242.3879 +				>
242.3880 +				<FileConfiguration
242.3881 +					Name="Release|Win32"
242.3882 +					>
242.3883 +					<Tool
242.3884 +						Name="VCCLCompilerTool"
242.3885 +						UsePrecompiledHeader="2"
242.3886 +					/>
242.3887 +				</FileConfiguration>
242.3888 +				<FileConfiguration
242.3889 +					Name="Debug|Win32"
242.3890 +					>
242.3891 +					<Tool
242.3892 +						Name="VCCLCompilerTool"
242.3893 +						UsePrecompiledHeader="2"
242.3894 +					/>
242.3895 +				</FileConfiguration>
242.3896 +			</File>
242.3897 +			<File
242.3898 +				RelativePath=".\CPP\7zip\Archive\Lzma\LzmaArcRegister.cpp"
242.3899 +				>
242.3900 +				<FileConfiguration
242.3901 +					Name="Release|Win32"
242.3902 +					>
242.3903 +					<Tool
242.3904 +						Name="VCCLCompilerTool"
242.3905 +						UsePrecompiledHeader="2"
242.3906 +					/>
242.3907 +				</FileConfiguration>
242.3908 +				<FileConfiguration
242.3909 +					Name="Debug|Win32"
242.3910 +					>
242.3911 +					<Tool
242.3912 +						Name="VCCLCompilerTool"
242.3913 +						UsePrecompiledHeader="2"
242.3914 +					/>
242.3915 +				</FileConfiguration>
242.3916 +			</File>
242.3917 +			<File
242.3918 +				RelativePath=".\CPP\7zip\Compress\LzmaRegister.cpp"
242.3919 +				>
242.3920 +				<FileConfiguration
242.3921 +					Name="Release|Win32"
242.3922 +					>
242.3923 +					<Tool
242.3924 +						Name="VCCLCompilerTool"
242.3925 +						UsePrecompiledHeader="2"
242.3926 +					/>
242.3927 +				</FileConfiguration>
242.3928 +				<FileConfiguration
242.3929 +					Name="Debug|Win32"
242.3930 +					>
242.3931 +					<Tool
242.3932 +						Name="VCCLCompilerTool"
242.3933 +						UsePrecompiledHeader="2"
242.3934 +					/>
242.3935 +				</FileConfiguration>
242.3936 +			</File>
242.3937 +			<File
242.3938 +				RelativePath=".\CPP\7zip\Compress\PpmdRegister.cpp"
242.3939 +				>
242.3940 +				<FileConfiguration
242.3941 +					Name="Release|Win32"
242.3942 +					>
242.3943 +					<Tool
242.3944 +						Name="VCCLCompilerTool"
242.3945 +						UsePrecompiledHeader="2"
242.3946 +					/>
242.3947 +				</FileConfiguration>
242.3948 +				<FileConfiguration
242.3949 +					Name="Debug|Win32"
242.3950 +					>
242.3951 +					<Tool
242.3952 +						Name="VCCLCompilerTool"
242.3953 +						UsePrecompiledHeader="2"
242.3954 +					/>
242.3955 +				</FileConfiguration>
242.3956 +			</File>
242.3957 +			<File
242.3958 +				RelativePath=".\CPP\7zip\Compress\RarCodecsRegister.cpp"
242.3959 +				>
242.3960 +				<FileConfiguration
242.3961 +					Name="Release|Win32"
242.3962 +					>
242.3963 +					<Tool
242.3964 +						Name="VCCLCompilerTool"
242.3965 +						UsePrecompiledHeader="2"
242.3966 +					/>
242.3967 +				</FileConfiguration>
242.3968 +				<FileConfiguration
242.3969 +					Name="Debug|Win32"
242.3970 +					>
242.3971 +					<Tool
242.3972 +						Name="VCCLCompilerTool"
242.3973 +						UsePrecompiledHeader="2"
242.3974 +					/>
242.3975 +				</FileConfiguration>
242.3976 +			</File>
242.3977 +			<File
242.3978 +				RelativePath=".\CPP\7zip\Archive\Rar\RarRegister.cpp"
242.3979 +				>
242.3980 +				<FileConfiguration
242.3981 +					Name="Release|Win32"
242.3982 +					>
242.3983 +					<Tool
242.3984 +						Name="VCCLCompilerTool"
242.3985 +						UsePrecompiledHeader="2"
242.3986 +					/>
242.3987 +				</FileConfiguration>
242.3988 +				<FileConfiguration
242.3989 +					Name="Debug|Win32"
242.3990 +					>
242.3991 +					<Tool
242.3992 +						Name="VCCLCompilerTool"
242.3993 +						UsePrecompiledHeader="2"
242.3994 +					/>
242.3995 +				</FileConfiguration>
242.3996 +			</File>
242.3997 +			<File
242.3998 +				RelativePath=".\CPP\7zip\Archive\Split\SplitRegister.cpp"
242.3999 +				>
242.4000 +				<FileConfiguration
242.4001 +					Name="Release|Win32"
242.4002 +					>
242.4003 +					<Tool
242.4004 +						Name="VCCLCompilerTool"
242.4005 +						UsePrecompiledHeader="2"
242.4006 +					/>
242.4007 +				</FileConfiguration>
242.4008 +				<FileConfiguration
242.4009 +					Name="Debug|Win32"
242.4010 +					>
242.4011 +					<Tool
242.4012 +						Name="VCCLCompilerTool"
242.4013 +						UsePrecompiledHeader="2"
242.4014 +					/>
242.4015 +				</FileConfiguration>
242.4016 +			</File>
242.4017 +			<File
242.4018 +				RelativePath=".\CPP\7zip\Archive\Tar\TarRegister.cpp"
242.4019 +				>
242.4020 +				<FileConfiguration
242.4021 +					Name="Release|Win32"
242.4022 +					>
242.4023 +					<Tool
242.4024 +						Name="VCCLCompilerTool"
242.4025 +						UsePrecompiledHeader="2"
242.4026 +					/>
242.4027 +				</FileConfiguration>
242.4028 +				<FileConfiguration
242.4029 +					Name="Debug|Win32"
242.4030 +					>
242.4031 +					<Tool
242.4032 +						Name="VCCLCompilerTool"
242.4033 +						UsePrecompiledHeader="2"
242.4034 +					/>
242.4035 +				</FileConfiguration>
242.4036 +			</File>
242.4037 +			<File
242.4038 +				RelativePath=".\CPP\7zip\Archive\Zip\ZipRegister.cpp"
242.4039 +				>
242.4040 +				<FileConfiguration
242.4041 +					Name="Release|Win32"
242.4042 +					>
242.4043 +					<Tool
242.4044 +						Name="VCCLCompilerTool"
242.4045 +						UsePrecompiledHeader="2"
242.4046 +					/>
242.4047 +				</FileConfiguration>
242.4048 +				<FileConfiguration
242.4049 +					Name="Debug|Win32"
242.4050 +					>
242.4051 +					<Tool
242.4052 +						Name="VCCLCompilerTool"
242.4053 +						UsePrecompiledHeader="2"
242.4054 +					/>
242.4055 +				</FileConfiguration>
242.4056 +			</File>
242.4057 +		</Filter>
242.4058 +	</Files>
242.4059 +	<Globals>
242.4060 +	</Globals>
242.4061 +</VisualStudioProject>
   243.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   243.2 +++ b/src/win32/7zip/7z/7zip_2008.vcproj	Sat Mar 03 10:31:27 2012 -0600
   243.3 @@ -0,0 +1,5347 @@
   243.4 +<?xml version="1.0" encoding="Windows-1252"?>
   243.5 +<VisualStudioProject
   243.6 +	ProjectType="Visual C++"
   243.7 +	Version="9.00"
   243.8 +	Name="wlib7zip"
   243.9 +	ProjectGUID="{5646C572-A578-49F8-9DA9-3E00A8CBFE3F}"
  243.10 +	RootNamespace="gens"
  243.11 +	TargetFrameworkVersion="131072"
  243.12 +	>
  243.13 +	<Platforms>
  243.14 +		<Platform
  243.15 +			Name="Win32"
  243.16 +		/>
  243.17 +	</Platforms>
  243.18 +	<ToolFiles>
  243.19 +		<DefaultToolFile
  243.20 +			FileName="masm.rules"
  243.21 +		/>
  243.22 +	</ToolFiles>
  243.23 +	<Configurations>
  243.24 +		<Configuration
  243.25 +			Name="Release|Win32"
  243.26 +			OutputDirectory="$(SolutionDir)\.VS2008\$(ConfigurationName)\$(PlatformName)\$(ProjectName)"
  243.27 +			IntermediateDirectory="$(SolutionDir)\.VS2008\$(ConfigurationName)\$(PlatformName)\$(ProjectName)"
  243.28 +			ConfigurationType="4"
  243.29 +			UseOfMFC="0"
  243.30 +			ATLMinimizesCRunTimeLibraryUsage="false"
  243.31 +			WholeProgramOptimization="1"
  243.32 +			>
  243.33 +			<Tool
  243.34 +				Name="VCPreBuildEventTool"
  243.35 +			/>
  243.36 +			<Tool
  243.37 +				Name="VCCustomBuildTool"
  243.38 +			/>
  243.39 +			<Tool
  243.40 +				Name="MASM"
  243.41 +			/>
  243.42 +			<Tool
  243.43 +				Name="VCXMLDataGeneratorTool"
  243.44 +			/>
  243.45 +			<Tool
  243.46 +				Name="VCWebServiceProxyGeneratorTool"
  243.47 +			/>
  243.48 +			<Tool
  243.49 +				Name="VCMIDLTool"
  243.50 +				PreprocessorDefinitions="NDEBUG"
  243.51 +				MkTypLibCompatible="true"
  243.52 +				SuppressStartupBanner="true"
  243.53 +				TargetEnvironment="1"
  243.54 +				TypeLibraryName=".\Release/gens.tlb"
  243.55 +				HeaderFileName=""
  243.56 +			/>
  243.57 +			<Tool
  243.58 +				Name="VCCLCompilerTool"
  243.59 +				Optimization="3"
  243.60 +				InlineFunctionExpansion="2"
  243.61 +				EnableIntrinsicFunctions="true"
  243.62 +				FavorSizeOrSpeed="1"
  243.63 +				OmitFramePointers="true"
  243.64 +				EnableFiberSafeOptimizations="true"
  243.65 +				WholeProgramOptimization="true"
  243.66 +				AdditionalIncludeDirectories="CPP"
  243.67 +				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;EXTRACT_ONLY;_NO_CRYPTO"
  243.68 +				StringPooling="true"
  243.69 +				ExceptionHandling="1"
  243.70 +				RuntimeLibrary="0"
  243.71 +				UsePrecompiledHeader="2"
  243.72 +				PrecompiledHeaderFile="$(IntDir)\7z.pch"
  243.73 +				AssemblerListingLocation="$(IntDir)\"
  243.74 +				ObjectFile="$(IntDir)\"
  243.75 +				ProgramDataBaseFileName="$(IntDir)\vc80.pdb"
  243.76 +				WarningLevel="3"
  243.77 +				SuppressStartupBanner="true"
  243.78 +				DebugInformationFormat="3"
  243.79 +				OmitDefaultLibName="true"
  243.80 +			/>
  243.81 +			<Tool
  243.82 +				Name="VCManagedResourceCompilerTool"
  243.83 +			/>
  243.84 +			<Tool
  243.85 +				Name="VCResourceCompilerTool"
  243.86 +				PreprocessorDefinitions="NDEBUG"
  243.87 +			/>
  243.88 +			<Tool
  243.89 +				Name="VCPreLinkEventTool"
  243.90 +			/>
  243.91 +			<Tool
  243.92 +				Name="VCLibrarianTool"
  243.93 +				AdditionalOptions=" /LTCG"
  243.94 +			/>
  243.95 +			<Tool
  243.96 +				Name="VCALinkTool"
  243.97 +			/>
  243.98 +			<Tool
  243.99 +				Name="VCXDCMakeTool"
 243.100 +			/>
 243.101 +			<Tool
 243.102 +				Name="VCBscMakeTool"
 243.103 +			/>
 243.104 +			<Tool
 243.105 +				Name="VCFxCopTool"
 243.106 +			/>
 243.107 +			<Tool
 243.108 +				Name="VCPostBuildEventTool"
 243.109 +			/>
 243.110 +		</Configuration>
 243.111 +		<Configuration
 243.112 +			Name="Debug|Win32"
 243.113 +			OutputDirectory="$(SolutionDir)\.VS2008\$(ConfigurationName)\$(PlatformName)\$(ProjectName)"
 243.114 +			IntermediateDirectory="$(SolutionDir)\.VS2008\$(ConfigurationName)\$(PlatformName)\$(ProjectName)"
 243.115 +			ConfigurationType="4"
 243.116 +			UseOfMFC="0"
 243.117 +			ATLMinimizesCRunTimeLibraryUsage="false"
 243.118 +			>
 243.119 +			<Tool
 243.120 +				Name="VCPreBuildEventTool"
 243.121 +				CommandLine=""
 243.122 +			/>
 243.123 +			<Tool
 243.124 +				Name="VCCustomBuildTool"
 243.125 +				CommandLine=""
 243.126 +			/>
 243.127 +			<Tool
 243.128 +				Name="MASM"
 243.129 +			/>
 243.130 +			<Tool
 243.131 +				Name="VCXMLDataGeneratorTool"
 243.132 +			/>
 243.133 +			<Tool
 243.134 +				Name="VCWebServiceProxyGeneratorTool"
 243.135 +			/>
 243.136 +			<Tool
 243.137 +				Name="VCMIDLTool"
 243.138 +				PreprocessorDefinitions="NDEBUG"
 243.139 +				MkTypLibCompatible="true"
 243.140 +				SuppressStartupBanner="true"
 243.141 +				TargetEnvironment="1"
 243.142 +				TypeLibraryName=".\Release/gens.tlb"
 243.143 +				HeaderFileName=""
 243.144 +			/>
 243.145 +			<Tool
 243.146 +				Name="VCCLCompilerTool"
 243.147 +				Optimization="0"
 243.148 +				InlineFunctionExpansion="0"
 243.149 +				EnableIntrinsicFunctions="false"
 243.150 +				AdditionalIncludeDirectories="CPP"
 243.151 +				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;EXTRACT_ONLY;_NO_CRYPTO"
 243.152 +				StringPooling="false"
 243.153 +				ExceptionHandling="1"
 243.154 +				BasicRuntimeChecks="3"
 243.155 +				SmallerTypeCheck="true"
 243.156 +				RuntimeLibrary="0"
 243.157 +				EnableFunctionLevelLinking="false"
 243.158 +				UsePrecompiledHeader="2"
 243.159 +				PrecompiledHeaderFile="$(IntDir)\7z.pch"
 243.160 +				AssemblerListingLocation="$(IntDir)\"
 243.161 +				ObjectFile="$(IntDir)\"
 243.162 +				ProgramDataBaseFileName="$(IntDir)\vc80.pdb"
 243.163 +				WarningLevel="3"
 243.164 +				SuppressStartupBanner="true"
 243.165 +				DebugInformationFormat="3"
 243.166 +				OmitDefaultLibName="true"
 243.167 +			/>
 243.168 +			<Tool
 243.169 +				Name="VCManagedResourceCompilerTool"
 243.170 +			/>
 243.171 +			<Tool
 243.172 +				Name="VCResourceCompilerTool"
 243.173 +				PreprocessorDefinitions="NDEBUG"
 243.174 +			/>
 243.175 +			<Tool
 243.176 +				Name="VCPreLinkEventTool"
 243.177 +			/>
 243.178 +			<Tool
 243.179 +				Name="VCLibrarianTool"
 243.180 +			/>
 243.181 +			<Tool
 243.182 +				Name="VCALinkTool"
 243.183 +			/>
 243.184 +			<Tool
 243.185 +				Name="VCXDCMakeTool"
 243.186 +			/>
 243.187 +			<Tool
 243.188 +				Name="VCBscMakeTool"
 243.189 +			/>
 243.190 +			<Tool
 243.191 +				Name="VCFxCopTool"
 243.192 +			/>
 243.193 +			<Tool
 243.194 +				Name="VCPostBuildEventTool"
 243.195 +			/>
 243.196 +		</Configuration>
 243.197 +		<Configuration
 243.198 +			Name="Release FastBuild|Win32"
 243.199 +			OutputDirectory="$(SolutionDir)\.VS2008\$(ConfigurationName)\$(PlatformName)\$(ProjectName)"
 243.200 +			IntermediateDirectory="$(SolutionDir)\.VS2008\$(ConfigurationName)\$(PlatformName)\$(ProjectName)"
 243.201 +			ConfigurationType="4"
 243.202 +			UseOfMFC="0"
 243.203 +			ATLMinimizesCRunTimeLibraryUsage="false"
 243.204 +			WholeProgramOptimization="0"
 243.205 +			>
 243.206 +			<Tool
 243.207 +				Name="VCPreBuildEventTool"
 243.208 +			/>
 243.209 +			<Tool
 243.210 +				Name="VCCustomBuildTool"
 243.211 +			/>
 243.212 +			<Tool
 243.213 +				Name="MASM"
 243.214 +			/>
 243.215 +			<Tool
 243.216 +				Name="VCXMLDataGeneratorTool"
 243.217 +			/>
 243.218 +			<Tool
 243.219 +				Name="VCWebServiceProxyGeneratorTool"
 243.220 +			/>
 243.221 +			<Tool
 243.222 +				Name="VCMIDLTool"
 243.223 +				PreprocessorDefinitions="NDEBUG"
 243.224 +				MkTypLibCompatible="true"
 243.225 +				SuppressStartupBanner="true"
 243.226 +				TargetEnvironment="1"
 243.227 +				TypeLibraryName=".\Release/gens.tlb"
 243.228 +				HeaderFileName=""
 243.229 +			/>
 243.230 +			<Tool
 243.231 +				Name="VCCLCompilerTool"
 243.232 +				Optimization="3"
 243.233 +				InlineFunctionExpansion="2"
 243.234 +				EnableIntrinsicFunctions="true"
 243.235 +				FavorSizeOrSpeed="1"
 243.236 +				OmitFramePointers="true"
 243.237 +				EnableFiberSafeOptimizations="true"
 243.238 +				WholeProgramOptimization="false"
 243.239 +				AdditionalIncludeDirectories="CPP"
 243.240 +				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;EXTRACT_ONLY;_NO_CRYPTO"
 243.241 +				StringPooling="true"
 243.242 +				ExceptionHandling="1"
 243.243 +				RuntimeLibrary="0"
 243.244 +				UsePrecompiledHeader="2"
 243.245 +				PrecompiledHeaderFile="$(IntDir)\7z.pch"
 243.246 +				AssemblerListingLocation="$(IntDir)\"
 243.247 +				ObjectFile="$(IntDir)\"
 243.248 +				ProgramDataBaseFileName="$(IntDir)\vc80.pdb"
 243.249 +				WarningLevel="3"
 243.250 +				SuppressStartupBanner="true"
 243.251 +				DebugInformationFormat="3"
 243.252 +				OmitDefaultLibName="true"
 243.253 +			/>
 243.254 +			<Tool
 243.255 +				Name="VCManagedResourceCompilerTool"
 243.256 +			/>
 243.257 +			<Tool
 243.258 +				Name="VCResourceCompilerTool"
 243.259 +				PreprocessorDefinitions="NDEBUG"
 243.260 +			/>
 243.261 +			<Tool
 243.262 +				Name="VCPreLinkEventTool"
 243.263 +			/>
 243.264 +			<Tool
 243.265 +				Name="VCLibrarianTool"
 243.266 +				AdditionalOptions=" /LTCG"
 243.267 +			/>
 243.268 +			<Tool
 243.269 +				Name="VCALinkTool"
 243.270 +			/>
 243.271 +			<Tool
 243.272 +				Name="VCXDCMakeTool"
 243.273 +			/>
 243.274 +			<Tool
 243.275 +				Name="VCBscMakeTool"
 243.276 +			/>
 243.277 +			<Tool
 243.278 +				Name="VCFxCopTool"
 243.279 +			/>
 243.280 +			<Tool
 243.281 +				Name="VCPostBuildEventTool"
 243.282 +			/>
 243.283 +		</Configuration>
 243.284 +	</Configurations>
 243.285 +	<References>
 243.286 +	</References>
 243.287 +	<Files>
 243.288 +		<Filter
 243.289 +			Name="7zip"
 243.290 +			>
 243.291 +			<File
 243.292 +				RelativePath=".\CPP\7zip\Common\FilterCoder.cpp"
 243.293 +				>
 243.294 +				<FileConfiguration
 243.295 +					Name="Release|Win32"
 243.296 +					>
 243.297 +					<Tool
 243.298 +						Name="VCCLCompilerTool"
 243.299 +						UsePrecompiledHeader="2"
 243.300 +					/>
 243.301 +				</FileConfiguration>
 243.302 +				<FileConfiguration
 243.303 +					Name="Debug|Win32"
 243.304 +					>
 243.305 +					<Tool
 243.306 +						Name="VCCLCompilerTool"
 243.307 +						UsePrecompiledHeader="2"
 243.308 +					/>
 243.309 +				</FileConfiguration>
 243.310 +				<FileConfiguration
 243.311 +					Name="Release FastBuild|Win32"
 243.312 +					>
 243.313 +					<Tool
 243.314 +						Name="VCCLCompilerTool"
 243.315 +						UsePrecompiledHeader="2"
 243.316 +					/>
 243.317 +				</FileConfiguration>
 243.318 +			</File>
 243.319 +			<File
 243.320 +				RelativePath=".\CPP\7zip\Common\InBuffer.cpp"
 243.321 +				>
 243.322 +				<FileConfiguration
 243.323 +					Name="Release|Win32"
 243.324 +					>
 243.325 +					<Tool
 243.326 +						Name="VCCLCompilerTool"
 243.327 +						UsePrecompiledHeader="2"
 243.328 +					/>
 243.329 +				</FileConfiguration>
 243.330 +				<FileConfiguration
 243.331 +					Name="Debug|Win32"
 243.332 +					>
 243.333 +					<Tool
 243.334 +						Name="VCCLCompilerTool"
 243.335 +						UsePrecompiledHeader="2"
 243.336 +					/>
 243.337 +				</FileConfiguration>
 243.338 +				<FileConfiguration
 243.339 +					Name="Release FastBuild|Win32"
 243.340 +					>
 243.341 +					<Tool
 243.342 +						Name="VCCLCompilerTool"
 243.343 +						UsePrecompiledHeader="2"
 243.344 +					/>
 243.345 +				</FileConfiguration>
 243.346 +			</File>
 243.347 +			<File
 243.348 +				RelativePath=".\CPP\7zip\Common\InOutTempBuffer.cpp"
 243.349 +				>
 243.350 +				<FileConfiguration
 243.351 +					Name="Release|Win32"
 243.352 +					>
 243.353 +					<Tool
 243.354 +						Name="VCCLCompilerTool"
 243.355 +						UsePrecompiledHeader="2"
 243.356 +					/>
 243.357 +				</FileConfiguration>
 243.358 +				<FileConfiguration
 243.359 +					Name="Debug|Win32"
 243.360 +					>
 243.361 +					<Tool
 243.362 +						Name="VCCLCompilerTool"
 243.363 +						UsePrecompiledHeader="2"
 243.364 +					/>
 243.365 +				</FileConfiguration>
 243.366 +				<FileConfiguration
 243.367 +					Name="Release FastBuild|Win32"
 243.368 +					>
 243.369 +					<Tool
 243.370 +						Name="VCCLCompilerTool"
 243.371 +						UsePrecompiledHeader="2"
 243.372 +					/>
 243.373 +				</FileConfiguration>
 243.374 +			</File>
 243.375 +			<File
 243.376 +				RelativePath=".\CPP\7zip\Common\LimitedStreams.cpp"
 243.377 +				>
 243.378 +				<FileConfiguration
 243.379 +					Name="Release|Win32"
 243.380 +					>
 243.381 +					<Tool
 243.382 +						Name="VCCLCompilerTool"
 243.383 +						UsePrecompiledHeader="2"
 243.384 +					/>
 243.385 +				</FileConfiguration>
 243.386 +				<FileConfiguration
 243.387 +					Name="Debug|Win32"
 243.388 +					>
 243.389 +					<Tool
 243.390 +						Name="VCCLCompilerTool"
 243.391 +						UsePrecompiledHeader="2"
 243.392 +					/>
 243.393 +				</FileConfiguration>
 243.394 +				<FileConfiguration
 243.395 +					Name="Release FastBuild|Win32"
 243.396 +					>
 243.397 +					<Tool
 243.398 +						Name="VCCLCompilerTool"
 243.399 +						UsePrecompiledHeader="2"
 243.400 +					/>
 243.401 +				</FileConfiguration>
 243.402 +			</File>
 243.403 +			<File
 243.404 +				RelativePath=".\CPP\7zip\Common\LockedStream.cpp"
 243.405 +				>
 243.406 +				<FileConfiguration
 243.407 +					Name="Release|Win32"
 243.408 +					>
 243.409 +					<Tool
 243.410 +						Name="VCCLCompilerTool"
 243.411 +						UsePrecompiledHeader="2"
 243.412 +					/>
 243.413 +				</FileConfiguration>
 243.414 +				<FileConfiguration
 243.415 +					Name="Debug|Win32"
 243.416 +					>
 243.417 +					<Tool
 243.418 +						Name="VCCLCompilerTool"
 243.419 +						UsePrecompiledHeader="2"
 243.420 +					/>
 243.421 +				</FileConfiguration>
 243.422 +				<FileConfiguration
 243.423 +					Name="Release FastBuild|Win32"
 243.424 +					>
 243.425 +					<Tool
 243.426 +						Name="VCCLCompilerTool"
 243.427 +						UsePrecompiledHeader="2"
 243.428 +					/>
 243.429 +				</FileConfiguration>
 243.430 +			</File>
 243.431 +			<File
 243.432 +				RelativePath=".\CPP\7zip\Common\MemBlocks.cpp"
 243.433 +				>
 243.434 +				<FileConfiguration
 243.435 +					Name="Release|Win32"
 243.436 +					>
 243.437 +					<Tool
 243.438 +						Name="VCCLCompilerTool"
 243.439 +						UsePrecompiledHeader="2"
 243.440 +					/>
 243.441 +				</FileConfiguration>
 243.442 +				<FileConfiguration
 243.443 +					Name="Debug|Win32"
 243.444 +					>
 243.445 +					<Tool
 243.446 +						Name="VCCLCompilerTool"
 243.447 +						UsePrecompiledHeader="2"
 243.448 +					/>
 243.449 +				</FileConfiguration>
 243.450 +				<FileConfiguration
 243.451 +					Name="Release FastBuild|Win32"
 243.452 +					>
 243.453 +					<Tool
 243.454 +						Name="VCCLCompilerTool"
 243.455 +						UsePrecompiledHeader="2"
 243.456 +					/>
 243.457 +				</FileConfiguration>
 243.458 +			</File>
 243.459 +			<File
 243.460 +				RelativePath=".\CPP\7zip\Common\MethodId.cpp"
 243.461 +				>
 243.462 +				<FileConfiguration
 243.463 +					Name="Release|Win32"
 243.464 +					>
 243.465 +					<Tool
 243.466 +						Name="VCCLCompilerTool"
 243.467 +						UsePrecompiledHeader="2"
 243.468 +					/>
 243.469 +				</FileConfiguration>
 243.470 +				<FileConfiguration
 243.471 +					Name="Debug|Win32"
 243.472 +					>
 243.473 +					<Tool
 243.474 +						Name="VCCLCompilerTool"
 243.475 +						UsePrecompiledHeader="2"
 243.476 +					/>
 243.477 +				</FileConfiguration>
 243.478 +				<FileConfiguration
 243.479 +					Name="Release FastBuild|Win32"
 243.480 +					>
 243.481 +					<Tool
 243.482 +						Name="VCCLCompilerTool"
 243.483 +						UsePrecompiledHeader="2"
 243.484 +					/>
 243.485 +				</FileConfiguration>
 243.486 +			</File>
 243.487 +			<File
 243.488 +				RelativePath=".\CPP\7zip\Common\MethodProps.cpp"
 243.489 +				>
 243.490 +				<FileConfiguration
 243.491 +					Name="Release|Win32"
 243.492 +					>
 243.493 +					<Tool
 243.494 +						Name="VCCLCompilerTool"
 243.495 +						UsePrecompiledHeader="2"
 243.496 +					/>
 243.497 +				</FileConfiguration>
 243.498 +				<FileConfiguration
 243.499 +					Name="Debug|Win32"
 243.500 +					>
 243.501 +					<Tool
 243.502 +						Name="VCCLCompilerTool"
 243.503 +						UsePrecompiledHeader="2"
 243.504 +					/>
 243.505 +				</FileConfiguration>
 243.506 +				<FileConfiguration
 243.507 +					Name="Release FastBuild|Win32"
 243.508 +					>
 243.509 +					<Tool
 243.510 +						Name="VCCLCompilerTool"
 243.511 +						UsePrecompiledHeader="2"
 243.512 +					/>
 243.513 +				</FileConfiguration>
 243.514 +			</File>
 243.515 +			<File
 243.516 +				RelativePath=".\CPP\7zip\Common\OffsetStream.cpp"
 243.517 +				>
 243.518 +				<FileConfiguration
 243.519 +					Name="Release|Win32"
 243.520 +					>
 243.521 +					<Tool
 243.522 +						Name="VCCLCompilerTool"
 243.523 +						UsePrecompiledHeader="2"
 243.524 +					/>
 243.525 +				</FileConfiguration>
 243.526 +				<FileConfiguration
 243.527 +					Name="Debug|Win32"
 243.528 +					>
 243.529 +					<Tool
 243.530 +						Name="VCCLCompilerTool"
 243.531 +						UsePrecompiledHeader="2"
 243.532 +					/>
 243.533 +				</FileConfiguration>
 243.534 +				<FileConfiguration
 243.535 +					Name="Release FastBuild|Win32"
 243.536 +					>
 243.537 +					<Tool
 243.538 +						Name="VCCLCompilerTool"
 243.539 +						UsePrecompiledHeader="2"
 243.540 +					/>
 243.541 +				</FileConfiguration>
 243.542 +			</File>
 243.543 +			<File
 243.544 +				RelativePath=".\CPP\7zip\Common\OutBuffer.cpp"
 243.545 +				>
 243.546 +				<FileConfiguration
 243.547 +					Name="Release|Win32"
 243.548 +					>
 243.549 +					<Tool
 243.550 +						Name="VCCLCompilerTool"
 243.551 +						UsePrecompiledHeader="2"
 243.552 +					/>
 243.553 +				</FileConfiguration>
 243.554 +				<FileConfiguration
 243.555 +					Name="Debug|Win32"
 243.556 +					>
 243.557 +					<Tool
 243.558 +						Name="VCCLCompilerTool"
 243.559 +						UsePrecompiledHeader="2"
 243.560 +					/>
 243.561 +				</FileConfiguration>
 243.562 +				<FileConfiguration
 243.563 +					Name="Release FastBuild|Win32"
 243.564 +					>
 243.565 +					<Tool
 243.566 +						Name="VCCLCompilerTool"
 243.567 +						UsePrecompiledHeader="2"
 243.568 +					/>
 243.569 +				</FileConfiguration>
 243.570 +			</File>
 243.571 +			<File
 243.572 +				RelativePath=".\CPP\7zip\Common\OutMemStream.cpp"
 243.573 +				>
 243.574 +				<FileConfiguration
 243.575 +					Name="Release|Win32"
 243.576 +					>
 243.577 +					<Tool
 243.578 +						Name="VCCLCompilerTool"
 243.579 +						UsePrecompiledHeader="2"
 243.580 +					/>
 243.581 +				</FileConfiguration>
 243.582 +				<FileConfiguration
 243.583 +					Name="Debug|Win32"
 243.584 +					>
 243.585 +					<Tool
 243.586 +						Name="VCCLCompilerTool"
 243.587 +						UsePrecompiledHeader="2"
 243.588 +					/>
 243.589 +				</FileConfiguration>
 243.590 +				<FileConfiguration
 243.591 +					Name="Release FastBuild|Win32"
 243.592 +					>
 243.593 +					<Tool
 243.594 +						Name="VCCLCompilerTool"
 243.595 +						UsePrecompiledHeader="2"
 243.596 +					/>
 243.597 +				</FileConfiguration>
 243.598 +			</File>
 243.599 +			<File
 243.600 +				RelativePath=".\CPP\7zip\Common\ProgressMt.cpp"
 243.601 +				>
 243.602 +				<FileConfiguration
 243.603 +					Name="Release|Win32"
 243.604 +					>
 243.605 +					<Tool
 243.606 +						Name="VCCLCompilerTool"
 243.607 +						UsePrecompiledHeader="2"
 243.608 +					/>
 243.609 +				</FileConfiguration>
 243.610 +				<FileConfiguration
 243.611 +					Name="Debug|Win32"
 243.612 +					>
 243.613 +					<Tool
 243.614 +						Name="VCCLCompilerTool"
 243.615 +						UsePrecompiledHeader="2"
 243.616 +					/>
 243.617 +				</FileConfiguration>
 243.618 +				<FileConfiguration
 243.619 +					Name="Release FastBuild|Win32"
 243.620 +					>
 243.621 +					<Tool
 243.622 +						Name="VCCLCompilerTool"
 243.623 +						UsePrecompiledHeader="2"
 243.624 +					/>
 243.625 +				</FileConfiguration>
 243.626 +			</File>
 243.627 +			<File
 243.628 +				RelativePath=".\CPP\7zip\Common\ProgressUtils.cpp"
 243.629 +				>
 243.630 +				<FileConfiguration
 243.631 +					Name="Release|Win32"
 243.632 +					>
 243.633 +					<Tool
 243.634 +						Name="VCCLCompilerTool"
 243.635 +						UsePrecompiledHeader="2"
 243.636 +					/>
 243.637 +				</FileConfiguration>
 243.638 +				<FileConfiguration
 243.639 +					Name="Debug|Win32"
 243.640 +					>
 243.641 +					<Tool
 243.642 +						Name="VCCLCompilerTool"
 243.643 +						UsePrecompiledHeader="2"
 243.644 +					/>
 243.645 +				</FileConfiguration>
 243.646 +				<FileConfiguration
 243.647 +					Name="Release FastBuild|Win32"
 243.648 +					>
 243.649 +					<Tool
 243.650 +						Name="VCCLCompilerTool"
 243.651 +						UsePrecompiledHeader="2"
 243.652 +					/>
 243.653 +				</FileConfiguration>
 243.654 +			</File>
 243.655 +			<File
 243.656 +				RelativePath=".\CPP\7zip\Common\StreamBinder.cpp"
 243.657 +				>
 243.658 +				<FileConfiguration
 243.659 +					Name="Release|Win32"
 243.660 +					>
 243.661 +					<Tool
 243.662 +						Name="VCCLCompilerTool"
 243.663 +						UsePrecompiledHeader="2"
 243.664 +					/>
 243.665 +				</FileConfiguration>
 243.666 +				<FileConfiguration
 243.667 +					Name="Debug|Win32"
 243.668 +					>
 243.669 +					<Tool
 243.670 +						Name="VCCLCompilerTool"
 243.671 +						UsePrecompiledHeader="2"
 243.672 +					/>
 243.673 +				</FileConfiguration>
 243.674 +				<FileConfiguration
 243.675 +					Name="Release FastBuild|Win32"
 243.676 +					>
 243.677 +					<Tool
 243.678 +						Name="VCCLCompilerTool"
 243.679 +						UsePrecompiledHeader="2"
 243.680 +					/>
 243.681 +				</FileConfiguration>
 243.682 +			</File>
 243.683 +			<File
 243.684 +				RelativePath=".\CPP\7zip\Common\StreamObjects.cpp"
 243.685 +				>
 243.686 +				<FileConfiguration
 243.687 +					Name="Release|Win32"
 243.688 +					>
 243.689 +					<Tool
 243.690 +						Name="VCCLCompilerTool"
 243.691 +						UsePrecompiledHeader="2"
 243.692 +					/>
 243.693 +				</FileConfiguration>
 243.694 +				<FileConfiguration
 243.695 +					Name="Debug|Win32"
 243.696 +					>
 243.697 +					<Tool
 243.698 +						Name="VCCLCompilerTool"
 243.699 +						UsePrecompiledHeader="2"
 243.700 +					/>
 243.701 +				</FileConfiguration>
 243.702 +				<FileConfiguration
 243.703 +					Name="Release FastBuild|Win32"
 243.704 +					>
 243.705 +					<Tool
 243.706 +						Name="VCCLCompilerTool"
 243.707 +						UsePrecompiledHeader="2"
 243.708 +					/>
 243.709 +				</FileConfiguration>
 243.710 +			</File>
 243.711 +			<File
 243.712 +				RelativePath=".\CPP\7zip\Common\StreamUtils.cpp"
 243.713 +				>
 243.714 +				<FileConfiguration
 243.715 +					Name="Release|Win32"
 243.716 +					>
 243.717 +					<Tool
 243.718 +						Name="VCCLCompilerTool"
 243.719 +						UsePrecompiledHeader="2"
 243.720 +					/>
 243.721 +				</FileConfiguration>
 243.722 +				<FileConfiguration
 243.723 +					Name="Debug|Win32"
 243.724 +					>
 243.725 +					<Tool
 243.726 +						Name="VCCLCompilerTool"
 243.727 +						UsePrecompiledHeader="2"
 243.728 +					/>
 243.729 +				</FileConfiguration>
 243.730 +				<FileConfiguration
 243.731 +					Name="Release FastBuild|Win32"
 243.732 +					>
 243.733 +					<Tool
 243.734 +						Name="VCCLCompilerTool"
 243.735 +						UsePrecompiledHeader="2"
 243.736 +					/>
 243.737 +				</FileConfiguration>
 243.738 +			</File>
 243.739 +			<File
 243.740 +				RelativePath=".\CPP\7zip\Common\VirtThread.cpp"
 243.741 +				>
 243.742 +				<FileConfiguration
 243.743 +					Name="Release|Win32"
 243.744 +					>
 243.745 +					<Tool
 243.746 +						Name="VCCLCompilerTool"
 243.747 +						UsePrecompiledHeader="2"
 243.748 +					/>
 243.749 +				</FileConfiguration>
 243.750 +				<FileConfiguration
 243.751 +					Name="Debug|Win32"
 243.752 +					>
 243.753 +					<Tool
 243.754 +						Name="VCCLCompilerTool"
 243.755 +						UsePrecompiledHeader="2"
 243.756 +					/>
 243.757 +				</FileConfiguration>
 243.758 +				<FileConfiguration
 243.759 +					Name="Release FastBuild|Win32"
 243.760 +					>
 243.761 +					<Tool
 243.762 +						Name="VCCLCompilerTool"
 243.763 +						UsePrecompiledHeader="2"
 243.764 +					/>
 243.765 +				</FileConfiguration>
 243.766 +			</File>
 243.767 +		</Filter>
 243.768 +		<Filter
 243.769 +			Name="Windows"
 243.770 +			>
 243.771 +			<File
 243.772 +				RelativePath=".\CPP\Windows\FileDir.cpp"
 243.773 +				>
 243.774 +				<FileConfiguration
 243.775 +					Name="Release|Win32"
 243.776 +					>
 243.777 +					<Tool
 243.778 +						Name="VCCLCompilerTool"
 243.779 +						UsePrecompiledHeader="2"
 243.780 +					/>
 243.781 +				</FileConfiguration>
 243.782 +				<FileConfiguration
 243.783 +					Name="Debug|Win32"
 243.784 +					>
 243.785 +					<Tool
 243.786 +						Name="VCCLCompilerTool"
 243.787 +						UsePrecompiledHeader="2"
 243.788 +					/>
 243.789 +				</FileConfiguration>
 243.790 +				<FileConfiguration
 243.791 +					Name="Release FastBuild|Win32"
 243.792 +					>
 243.793 +					<Tool
 243.794 +						Name="VCCLCompilerTool"
 243.795 +						UsePrecompiledHeader="2"
 243.796 +					/>
 243.797 +				</FileConfiguration>
 243.798 +			</File>
 243.799 +			<File
 243.800 +				RelativePath=".\CPP\Windows\FileFind.cpp"
 243.801 +				>
 243.802 +				<FileConfiguration
 243.803 +					Name="Release|Win32"
 243.804 +					>
 243.805 +					<Tool
 243.806 +						Name="VCCLCompilerTool"
 243.807 +						UsePrecompiledHeader="2"
 243.808 +					/>
 243.809 +				</FileConfiguration>
 243.810 +				<FileConfiguration
 243.811 +					Name="Debug|Win32"
 243.812 +					>
 243.813 +					<Tool
 243.814 +						Name="VCCLCompilerTool"
 243.815 +						UsePrecompiledHeader="2"
 243.816 +					/>
 243.817 +				</FileConfiguration>
 243.818 +				<FileConfiguration
 243.819 +					Name="Release FastBuild|Win32"
 243.820 +					>
 243.821 +					<Tool
 243.822 +						Name="VCCLCompilerTool"
 243.823 +						UsePrecompiledHeader="2"
 243.824 +					/>
 243.825 +				</FileConfiguration>
 243.826 +			</File>
 243.827 +			<File
 243.828 +				RelativePath=".\CPP\Windows\FileIO.cpp"
 243.829 +				>
 243.830 +				<FileConfiguration
 243.831 +					Name="Release|Win32"
 243.832 +					>
 243.833 +					<Tool
 243.834 +						Name="VCCLCompilerTool"
 243.835 +						UsePrecompiledHeader="2"
 243.836 +					/>
 243.837 +				</FileConfiguration>
 243.838 +				<FileConfiguration
 243.839 +					Name="Debug|Win32"
 243.840 +					>
 243.841 +					<Tool
 243.842 +						Name="VCCLCompilerTool"
 243.843 +						UsePrecompiledHeader="2"
 243.844 +					/>
 243.845 +				</FileConfiguration>
 243.846 +				<FileConfiguration
 243.847 +					Name="Release FastBuild|Win32"
 243.848 +					>
 243.849 +					<Tool
 243.850 +						Name="VCCLCompilerTool"
 243.851 +						UsePrecompiledHeader="2"
 243.852 +					/>
 243.853 +				</FileConfiguration>
 243.854 +			</File>
 243.855 +			<File
 243.856 +				RelativePath=".\CPP\Windows\PropVariant.cpp"
 243.857 +				>
 243.858 +				<FileConfiguration
 243.859 +					Name="Release|Win32"
 243.860 +					>
 243.861 +					<Tool
 243.862 +						Name="VCCLCompilerTool"
 243.863 +						UsePrecompiledHeader="2"
 243.864 +					/>
 243.865 +				</FileConfiguration>
 243.866 +				<FileConfiguration
 243.867 +					Name="Debug|Win32"
 243.868 +					>
 243.869 +					<Tool
 243.870 +						Name="VCCLCompilerTool"
 243.871 +						UsePrecompiledHeader="2"
 243.872 +					/>
 243.873 +				</FileConfiguration>
 243.874 +				<FileConfiguration
 243.875 +					Name="Release FastBuild|Win32"
 243.876 +					>
 243.877 +					<Tool
 243.878 +						Name="VCCLCompilerTool"
 243.879 +						UsePrecompiledHeader="2"
 243.880 +					/>
 243.881 +				</FileConfiguration>
 243.882 +			</File>
 243.883 +			<File
 243.884 +				RelativePath=".\CPP\Windows\Time.cpp"
 243.885 +				>
 243.886 +				<FileConfiguration
 243.887 +					Name="Release|Win32"
 243.888 +					>
 243.889 +					<Tool
 243.890 +						Name="VCCLCompilerTool"
 243.891 +						UsePrecompiledHeader="2"
 243.892 +					/>
 243.893 +				</FileConfiguration>
 243.894 +				<FileConfiguration
 243.895 +					Name="Debug|Win32"
 243.896 +					>
 243.897 +					<Tool
 243.898 +						Name="VCCLCompilerTool"
 243.899 +						UsePrecompiledHeader="2"
 243.900 +					/>
 243.901 +				</FileConfiguration>
 243.902 +				<FileConfiguration
 243.903 +					Name="Release FastBuild|Win32"
 243.904 +					>
 243.905 +					<Tool
 243.906 +						Name="VCCLCompilerTool"
 243.907 +						UsePrecompiledHeader="2"
 243.908 +					/>
 243.909 +				</FileConfiguration>
 243.910 +			</File>
 243.911 +		</Filter>
 243.912 +		<Filter
 243.913 +			Name="Archive"
 243.914 +			>
 243.915 +			<Filter
 243.916 +				Name="7z"
 243.917 +				>
 243.918 +				<File
 243.919 +					RelativePath=".\CPP\7zip\Archive\7z\7zCompressionMode.cpp"
 243.920 +					>
 243.921 +					<FileConfiguration
 243.922 +						Name="Release|Win32"
 243.923 +						>
 243.924 +						<Tool
 243.925 +							Name="VCCLCompilerTool"
 243.926 +							UsePrecompiledHeader="2"
 243.927 +						/>
 243.928 +					</FileConfiguration>
 243.929 +					<FileConfiguration
 243.930 +						Name="Debug|Win32"
 243.931 +						>
 243.932 +						<Tool
 243.933 +							Name="VCCLCompilerTool"
 243.934 +							UsePrecompiledHeader="2"
 243.935 +						/>
 243.936 +					</FileConfiguration>
 243.937 +					<FileConfiguration
 243.938 +						Name="Release FastBuild|Win32"
 243.939 +						>
 243.940 +						<Tool
 243.941 +							Name="VCCLCompilerTool"
 243.942 +							UsePrecompiledHeader="2"
 243.943 +						/>
 243.944 +					</FileConfiguration>
 243.945 +				</File>
 243.946 +				<File
 243.947 +					RelativePath=".\CPP\7zip\Archive\7z\7zDecode.cpp"
 243.948 +					>
 243.949 +					<FileConfiguration
 243.950 +						Name="Release|Win32"
 243.951 +						>
 243.952 +						<Tool
 243.953 +							Name="VCCLCompilerTool"
 243.954 +							UsePrecompiledHeader="2"
 243.955 +						/>
 243.956 +					</FileConfiguration>
 243.957 +					<FileConfiguration
 243.958 +						Name="Debug|Win32"
 243.959 +						>
 243.960 +						<Tool
 243.961 +							Name="VCCLCompilerTool"
 243.962 +							UsePrecompiledHeader="2"
 243.963 +						/>
 243.964 +					</FileConfiguration>
 243.965 +					<FileConfiguration
 243.966 +						Name="Release FastBuild|Win32"
 243.967 +						>
 243.968 +						<Tool
 243.969 +							Name="VCCLCompilerTool"
 243.970 +							UsePrecompiledHeader="2"
 243.971 +						/>
 243.972 +					</FileConfiguration>
 243.973 +				</File>
 243.974 +				<File
 243.975 +					RelativePath=".\CPP\7zip\Archive\7z\7zExtract.cpp"
 243.976 +					>
 243.977 +					<FileConfiguration
 243.978 +						Name="Release|Win32"
 243.979 +						>
 243.980 +						<Tool
 243.981 +							Name="VCCLCompilerTool"
 243.982 +							UsePrecompiledHeader="2"
 243.983 +						/>
 243.984 +					</FileConfiguration>
 243.985 +					<FileConfiguration
 243.986 +						Name="Debug|Win32"
 243.987 +						>
 243.988 +						<Tool
 243.989 +							Name="VCCLCompilerTool"
 243.990 +							UsePrecompiledHeader="2"
 243.991 +						/>
 243.992 +					</FileConfiguration>
 243.993 +					<FileConfiguration
 243.994 +						Name="Release FastBuild|Win32"
 243.995 +						>
 243.996 +						<Tool
 243.997 +							Name="VCCLCompilerTool"
 243.998 +							UsePrecompiledHeader="2"
 243.999 +						/>
243.1000 +					</FileConfiguration>
243.1001 +				</File>
243.1002 +				<File
243.1003 +					RelativePath=".\CPP\7zip\Archive\7z\7zFolderInStream.cpp"
243.1004 +					>
243.1005 +					<FileConfiguration
243.1006 +						Name="Release|Win32"
243.1007 +						>
243.1008 +						<Tool
243.1009 +							Name="VCCLCompilerTool"
243.1010 +							UsePrecompiledHeader="2"
243.1011 +						/>
243.1012 +					</FileConfiguration>
243.1013 +					<FileConfiguration
243.1014 +						Name="Debug|Win32"
243.1015 +						>
243.1016 +						<Tool
243.1017 +							Name="VCCLCompilerTool"
243.1018 +							UsePrecompiledHeader="2"
243.1019 +						/>
243.1020 +					</FileConfiguration>
243.1021 +					<FileConfiguration
243.1022 +						Name="Release FastBuild|Win32"
243.1023 +						>
243.1024 +						<Tool
243.1025 +							Name="VCCLCompilerTool"
243.1026 +							UsePrecompiledHeader="2"
243.1027 +						/>
243.1028 +					</FileConfiguration>
243.1029 +				</File>
243.1030 +				<File
243.1031 +					RelativePath=".\CPP\7zip\Archive\7z\7zFolderOutStream.cpp"
243.1032 +					>
243.1033 +					<FileConfiguration
243.1034 +						Name="Release|Win32"
243.1035 +						>
243.1036 +						<Tool
243.1037 +							Name="VCCLCompilerTool"
243.1038 +							UsePrecompiledHeader="2"
243.1039 +						/>
243.1040 +					</FileConfiguration>
243.1041 +					<FileConfiguration
243.1042 +						Name="Debug|Win32"
243.1043 +						>
243.1044 +						<Tool
243.1045 +							Name="VCCLCompilerTool"
243.1046 +							UsePrecompiledHeader="2"
243.1047 +						/>
243.1048 +					</FileConfiguration>
243.1049 +					<FileConfiguration
243.1050 +						Name="Release FastBuild|Win32"
243.1051 +						>
243.1052 +						<Tool
243.1053 +							Name="VCCLCompilerTool"
243.1054 +							UsePrecompiledHeader="2"
243.1055 +						/>
243.1056 +					</FileConfiguration>
243.1057 +				</File>
243.1058 +				<File
243.1059 +					RelativePath=".\CPP\7zip\Archive\7z\7zHandler.cpp"
243.1060 +					>
243.1061 +					<FileConfiguration
243.1062 +						Name="Release|Win32"
243.1063 +						>
243.1064 +						<Tool
243.1065 +							Name="VCCLCompilerTool"
243.1066 +							UsePrecompiledHeader="2"
243.1067 +						/>
243.1068 +					</FileConfiguration>
243.1069 +					<FileConfiguration
243.1070 +						Name="Debug|Win32"
243.1071 +						>
243.1072 +						<Tool
243.1073 +							Name="VCCLCompilerTool"
243.1074 +							UsePrecompiledHeader="2"
243.1075 +						/>
243.1076 +					</FileConfiguration>
243.1077 +					<FileConfiguration
243.1078 +						Name="Release FastBuild|Win32"
243.1079 +						>
243.1080 +						<Tool
243.1081 +							Name="VCCLCompilerTool"
243.1082 +							UsePrecompiledHeader="2"
243.1083 +						/>
243.1084 +					</FileConfiguration>
243.1085 +				</File>
243.1086 +				<File
243.1087 +					RelativePath=".\CPP\7zip\Archive\7z\7zHeader.cpp"
243.1088 +					>
243.1089 +					<FileConfiguration
243.1090 +						Name="Release|Win32"
243.1091 +						>
243.1092 +						<Tool
243.1093 +							Name="VCCLCompilerTool"
243.1094 +							UsePrecompiledHeader="2"
243.1095 +						/>
243.1096 +					</FileConfiguration>
243.1097 +					<FileConfiguration
243.1098 +						Name="Debug|Win32"
243.1099 +						>
243.1100 +						<Tool
243.1101 +							Name="VCCLCompilerTool"
243.1102 +							UsePrecompiledHeader="2"
243.1103 +						/>
243.1104 +					</FileConfiguration>
243.1105 +					<FileConfiguration
243.1106 +						Name="Release FastBuild|Win32"
243.1107 +						>
243.1108 +						<Tool
243.1109 +							Name="VCCLCompilerTool"
243.1110 +							UsePrecompiledHeader="2"
243.1111 +						/>
243.1112 +					</FileConfiguration>
243.1113 +				</File>
243.1114 +				<File
243.1115 +					RelativePath=".\CPP\7zip\Archive\7z\7zIn.cpp"
243.1116 +					>
243.1117 +					<FileConfiguration
243.1118 +						Name="Release|Win32"
243.1119 +						>
243.1120 +						<Tool
243.1121 +							Name="VCCLCompilerTool"
243.1122 +							UsePrecompiledHeader="2"
243.1123 +						/>
243.1124 +					</FileConfiguration>
243.1125 +					<FileConfiguration
243.1126 +						Name="Debug|Win32"
243.1127 +						>
243.1128 +						<Tool
243.1129 +							Name="VCCLCompilerTool"
243.1130 +							UsePrecompiledHeader="2"
243.1131 +						/>
243.1132 +					</FileConfiguration>
243.1133 +					<FileConfiguration
243.1134 +						Name="Release FastBuild|Win32"
243.1135 +						>
243.1136 +						<Tool
243.1137 +							Name="VCCLCompilerTool"
243.1138 +							UsePrecompiledHeader="2"
243.1139 +						/>
243.1140 +					</FileConfiguration>
243.1141 +				</File>
243.1142 +				<File
243.1143 +					RelativePath=".\CPP\7zip\Archive\7z\7zProperties.cpp"
243.1144 +					>
243.1145 +					<FileConfiguration
243.1146 +						Name="Release|Win32"
243.1147 +						>
243.1148 +						<Tool
243.1149 +							Name="VCCLCompilerTool"
243.1150 +							UsePrecompiledHeader="2"
243.1151 +						/>
243.1152 +					</FileConfiguration>
243.1153 +					<FileConfiguration
243.1154 +						Name="Debug|Win32"
243.1155 +						>
243.1156 +						<Tool
243.1157 +							Name="VCCLCompilerTool"
243.1158 +							UsePrecompiledHeader="2"
243.1159 +						/>
243.1160 +					</FileConfiguration>
243.1161 +					<FileConfiguration
243.1162 +						Name="Release FastBuild|Win32"
243.1163 +						>
243.1164 +						<Tool
243.1165 +							Name="VCCLCompilerTool"
243.1166 +							UsePrecompiledHeader="2"
243.1167 +						/>
243.1168 +					</FileConfiguration>
243.1169 +				</File>
243.1170 +				<File
243.1171 +					RelativePath=".\CPP\7zip\Archive\7z\7zSpecStream.cpp"
243.1172 +					>
243.1173 +					<FileConfiguration
243.1174 +						Name="Release|Win32"
243.1175 +						>
243.1176 +						<Tool
243.1177 +							Name="VCCLCompilerTool"
243.1178 +							UsePrecompiledHeader="2"
243.1179 +						/>
243.1180 +					</FileConfiguration>
243.1181 +					<FileConfiguration
243.1182 +						Name="Debug|Win32"
243.1183 +						>
243.1184 +						<Tool
243.1185 +							Name="VCCLCompilerTool"
243.1186 +							UsePrecompiledHeader="2"
243.1187 +						/>
243.1188 +					</FileConfiguration>
243.1189 +					<FileConfiguration
243.1190 +						Name="Release FastBuild|Win32"
243.1191 +						>
243.1192 +						<Tool
243.1193 +							Name="VCCLCompilerTool"
243.1194 +							UsePrecompiledHeader="2"
243.1195 +						/>
243.1196 +					</FileConfiguration>
243.1197 +				</File>
243.1198 +			</Filter>
243.1199 +			<Filter
243.1200 +				Name="Rar"
243.1201 +				>
243.1202 +				<File
243.1203 +					RelativePath=".\CPP\7zip\Archive\Rar\RarHandler.cpp"
243.1204 +					>
243.1205 +					<FileConfiguration
243.1206 +						Name="Release|Win32"
243.1207 +						>
243.1208 +						<Tool
243.1209 +							Name="VCCLCompilerTool"
243.1210 +							UsePrecompiledHeader="2"
243.1211 +						/>
243.1212 +					</FileConfiguration>
243.1213 +					<FileConfiguration
243.1214 +						Name="Debug|Win32"
243.1215 +						>
243.1216 +						<Tool
243.1217 +							Name="VCCLCompilerTool"
243.1218 +							UsePrecompiledHeader="2"
243.1219 +						/>
243.1220 +					</FileConfiguration>
243.1221 +					<FileConfiguration
243.1222 +						Name="Release FastBuild|Win32"
243.1223 +						>
243.1224 +						<Tool
243.1225 +							Name="VCCLCompilerTool"
243.1226 +							UsePrecompiledHeader="2"
243.1227 +						/>
243.1228 +					</FileConfiguration>
243.1229 +				</File>
243.1230 +				<File
243.1231 +					RelativePath=".\CPP\7zip\Archive\Rar\RarHeader.cpp"
243.1232 +					>
243.1233 +					<FileConfiguration
243.1234 +						Name="Release|Win32"
243.1235 +						>
243.1236 +						<Tool
243.1237 +							Name="VCCLCompilerTool"
243.1238 +							UsePrecompiledHeader="2"
243.1239 +						/>
243.1240 +					</FileConfiguration>
243.1241 +					<FileConfiguration
243.1242 +						Name="Debug|Win32"
243.1243 +						>
243.1244 +						<Tool
243.1245 +							Name="VCCLCompilerTool"
243.1246 +							UsePrecompiledHeader="2"
243.1247 +						/>
243.1248 +					</FileConfiguration>
243.1249 +					<FileConfiguration
243.1250 +						Name="Release FastBuild|Win32"
243.1251 +						>
243.1252 +						<Tool
243.1253 +							Name="VCCLCompilerTool"
243.1254 +							UsePrecompiledHeader="2"
243.1255 +						/>
243.1256 +					</FileConfiguration>
243.1257 +				</File>
243.1258 +				<File
243.1259 +					RelativePath=".\CPP\7zip\Archive\Rar\RarIn.cpp"
243.1260 +					>
243.1261 +					<FileConfiguration
243.1262 +						Name="Release|Win32"
243.1263 +						>
243.1264 +						<Tool
243.1265 +							Name="VCCLCompilerTool"
243.1266 +							UsePrecompiledHeader="2"
243.1267 +						/>
243.1268 +					</FileConfiguration>
243.1269 +					<FileConfiguration
243.1270 +						Name="Debug|Win32"
243.1271 +						>
243.1272 +						<Tool
243.1273 +							Name="VCCLCompilerTool"
243.1274 +							UsePrecompiledHeader="2"
243.1275 +						/>
243.1276 +					</FileConfiguration>
243.1277 +					<FileConfiguration
243.1278 +						Name="Release FastBuild|Win32"
243.1279 +						>
243.1280 +						<Tool
243.1281 +							Name="VCCLCompilerTool"
243.1282 +							UsePrecompiledHeader="2"
243.1283 +						/>
243.1284 +					</FileConfiguration>
243.1285 +				</File>
243.1286 +				<File
243.1287 +					RelativePath=".\CPP\7zip\Archive\Rar\RarItem.cpp"
243.1288 +					>
243.1289 +					<FileConfiguration
243.1290 +						Name="Release|Win32"
243.1291 +						>
243.1292 +						<Tool
243.1293 +							Name="VCCLCompilerTool"
243.1294 +							UsePrecompiledHeader="2"
243.1295 +						/>
243.1296 +					</FileConfiguration>
243.1297 +					<FileConfiguration
243.1298 +						Name="Debug|Win32"
243.1299 +						>
243.1300 +						<Tool
243.1301 +							Name="VCCLCompilerTool"
243.1302 +							UsePrecompiledHeader="2"
243.1303 +						/>
243.1304 +					</FileConfiguration>
243.1305 +					<FileConfiguration
243.1306 +						Name="Release FastBuild|Win32"
243.1307 +						>
243.1308 +						<Tool
243.1309 +							Name="VCCLCompilerTool"
243.1310 +							UsePrecompiledHeader="2"
243.1311 +						/>
243.1312 +					</FileConfiguration>
243.1313 +				</File>
243.1314 +				<File
243.1315 +					RelativePath=".\CPP\7zip\Archive\Rar\RarVolumeInStream.cpp"
243.1316 +					>
243.1317 +					<FileConfiguration
243.1318 +						Name="Release|Win32"
243.1319 +						>
243.1320 +						<Tool
243.1321 +							Name="VCCLCompilerTool"
243.1322 +							UsePrecompiledHeader="2"
243.1323 +						/>
243.1324 +					</FileConfiguration>
243.1325 +					<FileConfiguration
243.1326 +						Name="Debug|Win32"
243.1327 +						>
243.1328 +						<Tool
243.1329 +							Name="VCCLCompilerTool"
243.1330 +							UsePrecompiledHeader="2"
243.1331 +						/>
243.1332 +					</FileConfiguration>
243.1333 +					<FileConfiguration
243.1334 +						Name="Release FastBuild|Win32"
243.1335 +						>
243.1336 +						<Tool
243.1337 +							Name="VCCLCompilerTool"
243.1338 +							UsePrecompiledHeader="2"
243.1339 +						/>
243.1340 +					</FileConfiguration>
243.1341 +				</File>
243.1342 +			</Filter>
243.1343 +			<Filter
243.1344 +				Name="bz2"
243.1345 +				>
243.1346 +				<File
243.1347 +					RelativePath=".\CPP\7zip\Archive\BZip2\BZip2Handler.cpp"
243.1348 +					>
243.1349 +					<FileConfiguration
243.1350 +						Name="Release|Win32"
243.1351 +						>
243.1352 +						<Tool
243.1353 +							Name="VCCLCompilerTool"
243.1354 +							UsePrecompiledHeader="2"
243.1355 +						/>
243.1356 +					</FileConfiguration>
243.1357 +					<FileConfiguration
243.1358 +						Name="Debug|Win32"
243.1359 +						>
243.1360 +						<Tool
243.1361 +							Name="VCCLCompilerTool"
243.1362 +							UsePrecompiledHeader="2"
243.1363 +						/>
243.1364 +					</FileConfiguration>
243.1365 +					<FileConfiguration
243.1366 +						Name="Release FastBuild|Win32"
243.1367 +						>
243.1368 +						<Tool
243.1369 +							Name="VCCLCompilerTool"
243.1370 +							UsePrecompiledHeader="2"
243.1371 +						/>
243.1372 +					</FileConfiguration>
243.1373 +				</File>
243.1374 +			</Filter>
243.1375 +			<Filter
243.1376 +				Name="Archive common"
243.1377 +				>
243.1378 +				<File
243.1379 +					RelativePath=".\CPP\7zip\Archive\Common\CoderMixer2.cpp"
243.1380 +					>
243.1381 +					<FileConfiguration
243.1382 +						Name="Release|Win32"
243.1383 +						>
243.1384 +						<Tool
243.1385 +							Name="VCCLCompilerTool"
243.1386 +							UsePrecompiledHeader="2"
243.1387 +						/>
243.1388 +					</FileConfiguration>
243.1389 +					<FileConfiguration
243.1390 +						Name="Debug|Win32"
243.1391 +						>
243.1392 +						<Tool
243.1393 +							Name="VCCLCompilerTool"
243.1394 +							UsePrecompiledHeader="2"
243.1395 +						/>
243.1396 +					</FileConfiguration>
243.1397 +					<FileConfiguration
243.1398 +						Name="Release FastBuild|Win32"
243.1399 +						>
243.1400 +						<Tool
243.1401 +							Name="VCCLCompilerTool"
243.1402 +							UsePrecompiledHeader="2"
243.1403 +						/>
243.1404 +					</FileConfiguration>
243.1405 +				</File>
243.1406 +				<File
243.1407 +					RelativePath=".\CPP\7zip\Archive\Common\CoderMixer2MT.cpp"
243.1408 +					>
243.1409 +					<FileConfiguration
243.1410 +						Name="Release|Win32"
243.1411 +						>
243.1412 +						<Tool
243.1413 +							Name="VCCLCompilerTool"
243.1414 +							UsePrecompiledHeader="2"
243.1415 +						/>
243.1416 +					</FileConfiguration>
243.1417 +					<FileConfiguration
243.1418 +						Name="Debug|Win32"
243.1419 +						>
243.1420 +						<Tool
243.1421 +							Name="VCCLCompilerTool"
243.1422 +							UsePrecompiledHeader="2"
243.1423 +						/>
243.1424 +					</FileConfiguration>
243.1425 +					<FileConfiguration
243.1426 +						Name="Release FastBuild|Win32"
243.1427 +						>
243.1428 +						<Tool
243.1429 +							Name="VCCLCompilerTool"
243.1430 +							UsePrecompiledHeader="2"
243.1431 +						/>
243.1432 +					</FileConfiguration>
243.1433 +				</File>
243.1434 +				<File
243.1435 +					RelativePath=".\CPP\7zip\Archive\Common\DummyOutStream.cpp"
243.1436 +					>
243.1437 +					<FileConfiguration
243.1438 +						Name="Release|Win32"
243.1439 +						>
243.1440 +						<Tool
243.1441 +							Name="VCCLCompilerTool"
243.1442 +							UsePrecompiledHeader="2"
243.1443 +						/>
243.1444 +					</FileConfiguration>
243.1445 +					<FileConfiguration
243.1446 +						Name="Debug|Win32"
243.1447 +						>
243.1448 +						<Tool
243.1449 +							Name="VCCLCompilerTool"
243.1450 +							UsePrecompiledHeader="2"
243.1451 +						/>
243.1452 +					</FileConfiguration>
243.1453 +					<FileConfiguration
243.1454 +						Name="Release FastBuild|Win32"
243.1455 +						>
243.1456 +						<Tool
243.1457 +							Name="VCCLCompilerTool"
243.1458 +							UsePrecompiledHeader="2"
243.1459 +						/>
243.1460 +					</FileConfiguration>
243.1461 +				</File>
243.1462 +				<File
243.1463 +					RelativePath=".\CPP\7zip\Archive\Common\FindSignature.cpp"
243.1464 +					>
243.1465 +					<FileConfiguration
243.1466 +						Name="Release|Win32"
243.1467 +						>
243.1468 +						<Tool
243.1469 +							Name="VCCLCompilerTool"
243.1470 +							UsePrecompiledHeader="2"
243.1471 +						/>
243.1472 +					</FileConfiguration>
243.1473 +					<FileConfiguration
243.1474 +						Name="Debug|Win32"
243.1475 +						>
243.1476 +						<Tool
243.1477 +							Name="VCCLCompilerTool"
243.1478 +							UsePrecompiledHeader="2"
243.1479 +						/>
243.1480 +					</FileConfiguration>
243.1481 +					<FileConfiguration
243.1482 +						Name="Release FastBuild|Win32"
243.1483 +						>
243.1484 +						<Tool
243.1485 +							Name="VCCLCompilerTool"
243.1486 +							UsePrecompiledHeader="2"
243.1487 +						/>
243.1488 +					</FileConfiguration>
243.1489 +				</File>
243.1490 +				<File
243.1491 +					RelativePath=".\CPP\7zip\Archive\Common\InStreamWithCRC.cpp"
243.1492 +					>
243.1493 +					<FileConfiguration
243.1494 +						Name="Release|Win32"
243.1495 +						>
243.1496 +						<Tool
243.1497 +							Name="VCCLCompilerTool"
243.1498 +							UsePrecompiledHeader="2"
243.1499 +						/>
243.1500 +					</FileConfiguration>
243.1501 +					<FileConfiguration
243.1502 +						Name="Debug|Win32"
243.1503 +						>
243.1504 +						<Tool
243.1505 +							Name="VCCLCompilerTool"
243.1506 +							UsePrecompiledHeader="2"
243.1507 +						/>
243.1508 +					</FileConfiguration>
243.1509 +					<FileConfiguration
243.1510 +						Name="Release FastBuild|Win32"
243.1511 +						>
243.1512 +						<Tool
243.1513 +							Name="VCCLCompilerTool"
243.1514 +							UsePrecompiledHeader="2"
243.1515 +						/>
243.1516 +					</FileConfiguration>
243.1517 +				</File>
243.1518 +				<File
243.1519 +					RelativePath=".\CPP\7zip\Archive\Common\ItemNameUtils.cpp"
243.1520 +					>
243.1521 +					<FileConfiguration
243.1522 +						Name="Release|Win32"
243.1523 +						>
243.1524 +						<Tool
243.1525 +							Name="VCCLCompilerTool"
243.1526 +							UsePrecompiledHeader="2"
243.1527 +						/>
243.1528 +					</FileConfiguration>
243.1529 +					<FileConfiguration
243.1530 +						Name="Debug|Win32"
243.1531 +						>
243.1532 +						<Tool
243.1533 +							Name="VCCLCompilerTool"
243.1534 +							UsePrecompiledHeader="2"
243.1535 +						/>
243.1536 +					</FileConfiguration>
243.1537 +					<FileConfiguration
243.1538 +						Name="Release FastBuild|Win32"
243.1539 +						>
243.1540 +						<Tool
243.1541 +							Name="VCCLCompilerTool"
243.1542 +							UsePrecompiledHeader="2"
243.1543 +						/>
243.1544 +					</FileConfiguration>
243.1545 +				</File>
243.1546 +				<File
243.1547 +					RelativePath=".\CPP\7zip\Archive\Common\MultiStream.cpp"
243.1548 +					>
243.1549 +					<FileConfiguration
243.1550 +						Name="Release|Win32"
243.1551 +						>
243.1552 +						<Tool
243.1553 +							Name="VCCLCompilerTool"
243.1554 +							UsePrecompiledHeader="2"
243.1555 +						/>
243.1556 +					</FileConfiguration>
243.1557 +					<FileConfiguration
243.1558 +						Name="Debug|Win32"
243.1559 +						>
243.1560 +						<Tool
243.1561 +							Name="VCCLCompilerTool"
243.1562 +							UsePrecompiledHeader="2"
243.1563 +						/>
243.1564 +					</FileConfiguration>
243.1565 +					<FileConfiguration
243.1566 +						Name="Release FastBuild|Win32"
243.1567 +						>
243.1568 +						<Tool
243.1569 +							Name="VCCLCompilerTool"
243.1570 +							UsePrecompiledHeader="2"
243.1571 +						/>
243.1572 +					</FileConfiguration>
243.1573 +				</File>
243.1574 +				<File
243.1575 +					RelativePath=".\CPP\7zip\Archive\Common\OutStreamWithCRC.cpp"
243.1576 +					>
243.1577 +					<FileConfiguration
243.1578 +						Name="Release|Win32"
243.1579 +						>
243.1580 +						<Tool
243.1581 +							Name="VCCLCompilerTool"
243.1582 +							UsePrecompiledHeader="2"
243.1583 +						/>
243.1584 +					</FileConfiguration>
243.1585 +					<FileConfiguration
243.1586 +						Name="Debug|Win32"
243.1587 +						>
243.1588 +						<Tool
243.1589 +							Name="VCCLCompilerTool"
243.1590 +							UsePrecompiledHeader="2"
243.1591 +						/>
243.1592 +					</FileConfiguration>
243.1593 +					<FileConfiguration
243.1594 +						Name="Release FastBuild|Win32"
243.1595 +						>
243.1596 +						<Tool
243.1597 +							Name="VCCLCompilerTool"
243.1598 +							UsePrecompiledHeader="2"
243.1599 +						/>
243.1600 +					</FileConfiguration>
243.1601 +				</File>
243.1602 +				<File
243.1603 +					RelativePath=".\CPP\7zip\Archive\Common\ParseProperties.cpp"
243.1604 +					>
243.1605 +					<FileConfiguration
243.1606 +						Name="Release|Win32"
243.1607 +						>
243.1608 +						<Tool
243.1609 +							Name="VCCLCompilerTool"
243.1610 +							UsePrecompiledHeader="2"
243.1611 +						/>
243.1612 +					</FileConfiguration>
243.1613 +					<FileConfiguration
243.1614 +						Name="Debug|Win32"
243.1615 +						>
243.1616 +						<Tool
243.1617 +							Name="VCCLCompilerTool"
243.1618 +							UsePrecompiledHeader="2"
243.1619 +						/>
243.1620 +					</FileConfiguration>
243.1621 +					<FileConfiguration
243.1622 +						Name="Release FastBuild|Win32"
243.1623 +						>
243.1624 +						<Tool
243.1625 +							Name="VCCLCompilerTool"
243.1626 +							UsePrecompiledHeader="2"
243.1627 +						/>
243.1628 +					</FileConfiguration>
243.1629 +				</File>
243.1630 +			</Filter>
243.1631 +			<Filter
243.1632 +				Name="GZip"
243.1633 +				>
243.1634 +				<File
243.1635 +					RelativePath=".\CPP\7zip\Archive\GZip\GZipHandler.cpp"
243.1636 +					>
243.1637 +					<FileConfiguration
243.1638 +						Name="Release|Win32"
243.1639 +						>
243.1640 +						<Tool
243.1641 +							Name="VCCLCompilerTool"
243.1642 +							UsePrecompiledHeader="2"
243.1643 +						/>
243.1644 +					</FileConfiguration>
243.1645 +					<FileConfiguration
243.1646 +						Name="Debug|Win32"
243.1647 +						>
243.1648 +						<Tool
243.1649 +							Name="VCCLCompilerTool"
243.1650 +							UsePrecompiledHeader="2"
243.1651 +						/>
243.1652 +					</FileConfiguration>
243.1653 +					<FileConfiguration
243.1654 +						Name="Release FastBuild|Win32"
243.1655 +						>
243.1656 +						<Tool
243.1657 +							Name="VCCLCompilerTool"
243.1658 +							UsePrecompiledHeader="2"
243.1659 +						/>
243.1660 +					</FileConfiguration>
243.1661 +				</File>
243.1662 +				<File
243.1663 +					RelativePath=".\CPP\7zip\Archive\GZip\GZipHeader.cpp"
243.1664 +					>
243.1665 +					<FileConfiguration
243.1666 +						Name="Release|Win32"
243.1667 +						>
243.1668 +						<Tool
243.1669 +							Name="VCCLCompilerTool"
243.1670 +							UsePrecompiledHeader="2"
243.1671 +						/>
243.1672 +					</FileConfiguration>
243.1673 +					<FileConfiguration
243.1674 +						Name="Debug|Win32"
243.1675 +						>
243.1676 +						<Tool
243.1677 +							Name="VCCLCompilerTool"
243.1678 +							UsePrecompiledHeader="2"
243.1679 +						/>
243.1680 +					</FileConfiguration>
243.1681 +					<FileConfiguration
243.1682 +						Name="Release FastBuild|Win32"
243.1683 +						>
243.1684 +						<Tool
243.1685 +							Name="VCCLCompilerTool"
243.1686 +							UsePrecompiledHeader="2"
243.1687 +						/>
243.1688 +					</FileConfiguration>
243.1689 +				</File>
243.1690 +				<File
243.1691 +					RelativePath=".\CPP\7zip\Archive\GZip\GZipIn.cpp"
243.1692 +					>
243.1693 +					<FileConfiguration
243.1694 +						Name="Release|Win32"
243.1695 +						>
243.1696 +						<Tool
243.1697 +							Name="VCCLCompilerTool"
243.1698 +							UsePrecompiledHeader="2"
243.1699 +						/>
243.1700 +					</FileConfiguration>
243.1701 +					<FileConfiguration
243.1702 +						Name="Debug|Win32"
243.1703 +						>
243.1704 +						<Tool
243.1705 +							Name="VCCLCompilerTool"
243.1706 +							UsePrecompiledHeader="2"
243.1707 +						/>
243.1708 +					</FileConfiguration>
243.1709 +					<FileConfiguration
243.1710 +						Name="Release FastBuild|Win32"
243.1711 +						>
243.1712 +						<Tool
243.1713 +							Name="VCCLCompilerTool"
243.1714 +							UsePrecompiledHeader="2"
243.1715 +						/>
243.1716 +					</FileConfiguration>
243.1717 +				</File>
243.1718 +			</Filter>
243.1719 +			<Filter
243.1720 +				Name="Lzh"
243.1721 +				>
243.1722 +				<File
243.1723 +					RelativePath=".\CPP\7zip\Archive\Lzh\LzhCRC.cpp"
243.1724 +					>
243.1725 +					<FileConfiguration
243.1726 +						Name="Release|Win32"
243.1727 +						>
243.1728 +						<Tool
243.1729 +							Name="VCCLCompilerTool"
243.1730 +							UsePrecompiledHeader="2"
243.1731 +						/>
243.1732 +					</FileConfiguration>
243.1733 +					<FileConfiguration
243.1734 +						Name="Debug|Win32"
243.1735 +						>
243.1736 +						<Tool
243.1737 +							Name="VCCLCompilerTool"
243.1738 +							UsePrecompiledHeader="2"
243.1739 +						/>
243.1740 +					</FileConfiguration>
243.1741 +					<FileConfiguration
243.1742 +						Name="Release FastBuild|Win32"
243.1743 +						>
243.1744 +						<Tool
243.1745 +							Name="VCCLCompilerTool"
243.1746 +							UsePrecompiledHeader="2"
243.1747 +						/>
243.1748 +					</FileConfiguration>
243.1749 +				</File>
243.1750 +				<File
243.1751 +					RelativePath=".\CPP\7zip\Archive\Lzh\LzhHandler.cpp"
243.1752 +					>
243.1753 +					<FileConfiguration
243.1754 +						Name="Release|Win32"
243.1755 +						>
243.1756 +						<Tool
243.1757 +							Name="VCCLCompilerTool"
243.1758 +							UsePrecompiledHeader="2"
243.1759 +						/>
243.1760 +					</FileConfiguration>
243.1761 +					<FileConfiguration
243.1762 +						Name="Debug|Win32"
243.1763 +						>
243.1764 +						<Tool
243.1765 +							Name="VCCLCompilerTool"
243.1766 +							UsePrecompiledHeader="2"
243.1767 +						/>
243.1768 +					</FileConfiguration>
243.1769 +					<FileConfiguration
243.1770 +						Name="Release FastBuild|Win32"
243.1771 +						>
243.1772 +						<Tool
243.1773 +							Name="VCCLCompilerTool"
243.1774 +							UsePrecompiledHeader="2"
243.1775 +						/>
243.1776 +					</FileConfiguration>
243.1777 +				</File>
243.1778 +				<File
243.1779 +					RelativePath=".\CPP\7zip\Archive\Lzh\LzhIn.cpp"
243.1780 +					>
243.1781 +					<FileConfiguration
243.1782 +						Name="Release|Win32"
243.1783 +						>
243.1784 +						<Tool
243.1785 +							Name="VCCLCompilerTool"
243.1786 +							UsePrecompiledHeader="2"
243.1787 +						/>
243.1788 +					</FileConfiguration>
243.1789 +					<FileConfiguration
243.1790 +						Name="Debug|Win32"
243.1791 +						>
243.1792 +						<Tool
243.1793 +							Name="VCCLCompilerTool"
243.1794 +							UsePrecompiledHeader="2"
243.1795 +						/>
243.1796 +					</FileConfiguration>
243.1797 +					<FileConfiguration
243.1798 +						Name="Release FastBuild|Win32"
243.1799 +						>
243.1800 +						<Tool
243.1801 +							Name="VCCLCompilerTool"
243.1802 +							UsePrecompiledHeader="2"
243.1803 +						/>
243.1804 +					</FileConfiguration>
243.1805 +				</File>
243.1806 +				<File
243.1807 +					RelativePath=".\CPP\7zip\Archive\Lzh\LzhOutStreamWithCRC.cpp"
243.1808 +					>
243.1809 +					<FileConfiguration
243.1810 +						Name="Release|Win32"
243.1811 +						>
243.1812 +						<Tool
243.1813 +							Name="VCCLCompilerTool"
243.1814 +							UsePrecompiledHeader="2"
243.1815 +						/>
243.1816 +					</FileConfiguration>
243.1817 +					<FileConfiguration
243.1818 +						Name="Debug|Win32"
243.1819 +						>
243.1820 +						<Tool
243.1821 +							Name="VCCLCompilerTool"
243.1822 +							UsePrecompiledHeader="2"
243.1823 +						/>
243.1824 +					</FileConfiguration>
243.1825 +					<FileConfiguration
243.1826 +						Name="Release FastBuild|Win32"
243.1827 +						>
243.1828 +						<Tool
243.1829 +							Name="VCCLCompilerTool"
243.1830 +							UsePrecompiledHeader="2"
243.1831 +						/>
243.1832 +					</FileConfiguration>
243.1833 +				</File>
243.1834 +			</Filter>
243.1835 +			<Filter
243.1836 +				Name="Split"
243.1837 +				>
243.1838 +				<File
243.1839 +					RelativePath=".\CPP\7zip\Archive\Split\SplitHandler.cpp"
243.1840 +					>
243.1841 +					<FileConfiguration
243.1842 +						Name="Release|Win32"
243.1843 +						>
243.1844 +						<Tool
243.1845 +							Name="VCCLCompilerTool"
243.1846 +							UsePrecompiledHeader="2"
243.1847 +						/>
243.1848 +					</FileConfiguration>
243.1849 +					<FileConfiguration
243.1850 +						Name="Debug|Win32"
243.1851 +						>
243.1852 +						<Tool
243.1853 +							Name="VCCLCompilerTool"
243.1854 +							UsePrecompiledHeader="2"
243.1855 +						/>
243.1856 +					</FileConfiguration>
243.1857 +					<FileConfiguration
243.1858 +						Name="Release FastBuild|Win32"
243.1859 +						>
243.1860 +						<Tool
243.1861 +							Name="VCCLCompilerTool"
243.1862 +							UsePrecompiledHeader="2"
243.1863 +						/>
243.1864 +					</FileConfiguration>
243.1865 +				</File>
243.1866 +			</Filter>
243.1867 +			<Filter
243.1868 +				Name="Tar"
243.1869 +				>
243.1870 +				<File
243.1871 +					RelativePath=".\CPP\7zip\Archive\Tar\TarHandler.cpp"
243.1872 +					>
243.1873 +					<FileConfiguration
243.1874 +						Name="Release|Win32"
243.1875 +						>
243.1876 +						<Tool
243.1877 +							Name="VCCLCompilerTool"
243.1878 +							UsePrecompiledHeader="2"
243.1879 +						/>
243.1880 +					</FileConfiguration>
243.1881 +					<FileConfiguration
243.1882 +						Name="Debug|Win32"
243.1883 +						>
243.1884 +						<Tool
243.1885 +							Name="VCCLCompilerTool"
243.1886 +							UsePrecompiledHeader="2"
243.1887 +						/>
243.1888 +					</FileConfiguration>
243.1889 +					<FileConfiguration
243.1890 +						Name="Release FastBuild|Win32"
243.1891 +						>
243.1892 +						<Tool
243.1893 +							Name="VCCLCompilerTool"
243.1894 +							UsePrecompiledHeader="2"
243.1895 +						/>
243.1896 +					</FileConfiguration>
243.1897 +				</File>
243.1898 +				<File
243.1899 +					RelativePath=".\CPP\7zip\Archive\Tar\TarHeader.cpp"
243.1900 +					>
243.1901 +					<FileConfiguration
243.1902 +						Name="Release|Win32"
243.1903 +						>
243.1904 +						<Tool
243.1905 +							Name="VCCLCompilerTool"
243.1906 +							UsePrecompiledHeader="2"
243.1907 +						/>
243.1908 +					</FileConfiguration>
243.1909 +					<FileConfiguration
243.1910 +						Name="Debug|Win32"
243.1911 +						>
243.1912 +						<Tool
243.1913 +							Name="VCCLCompilerTool"
243.1914 +							UsePrecompiledHeader="2"
243.1915 +						/>
243.1916 +					</FileConfiguration>
243.1917 +					<FileConfiguration
243.1918 +						Name="Release FastBuild|Win32"
243.1919 +						>
243.1920 +						<Tool
243.1921 +							Name="VCCLCompilerTool"
243.1922 +							UsePrecompiledHeader="2"
243.1923 +						/>
243.1924 +					</FileConfiguration>
243.1925 +				</File>
243.1926 +				<File
243.1927 +					RelativePath=".\CPP\7zip\Archive\Tar\TarIn.cpp"
243.1928 +					>
243.1929 +					<FileConfiguration
243.1930 +						Name="Release|Win32"
243.1931 +						>
243.1932 +						<Tool
243.1933 +							Name="VCCLCompilerTool"
243.1934 +							UsePrecompiledHeader="2"
243.1935 +						/>
243.1936 +					</FileConfiguration>
243.1937 +					<FileConfiguration
243.1938 +						Name="Debug|Win32"
243.1939 +						>
243.1940 +						<Tool
243.1941 +							Name="VCCLCompilerTool"
243.1942 +							UsePrecompiledHeader="2"
243.1943 +						/>
243.1944 +					</FileConfiguration>
243.1945 +					<FileConfiguration
243.1946 +						Name="Release FastBuild|Win32"
243.1947 +						>
243.1948 +						<Tool
243.1949 +							Name="VCCLCompilerTool"
243.1950 +							UsePrecompiledHeader="2"
243.1951 +						/>
243.1952 +					</FileConfiguration>
243.1953 +				</File>
243.1954 +			</Filter>
243.1955 +			<Filter
243.1956 +				Name="Zip"
243.1957 +				>
243.1958 +				<File
243.1959 +					RelativePath=".\CPP\7zip\Archive\Zip\ZipHandler.cpp"
243.1960 +					>
243.1961 +					<FileConfiguration
243.1962 +						Name="Release|Win32"
243.1963 +						>
243.1964 +						<Tool
243.1965 +							Name="VCCLCompilerTool"
243.1966 +							UsePrecompiledHeader="2"
243.1967 +						/>
243.1968 +					</FileConfiguration>
243.1969 +					<FileConfiguration
243.1970 +						Name="Debug|Win32"
243.1971 +						>
243.1972 +						<Tool
243.1973 +							Name="VCCLCompilerTool"
243.1974 +							UsePrecompiledHeader="2"
243.1975 +						/>
243.1976 +					</FileConfiguration>
243.1977 +					<FileConfiguration
243.1978 +						Name="Release FastBuild|Win32"
243.1979 +						>
243.1980 +						<Tool
243.1981 +							Name="VCCLCompilerTool"
243.1982 +							UsePrecompiledHeader="2"
243.1983 +						/>
243.1984 +					</FileConfiguration>
243.1985 +				</File>
243.1986 +				<File
243.1987 +					RelativePath=".\CPP\7zip\Archive\Zip\ZipHeader.cpp"
243.1988 +					>
243.1989 +					<FileConfiguration
243.1990 +						Name="Release|Win32"
243.1991 +						>
243.1992 +						<Tool
243.1993 +							Name="VCCLCompilerTool"
243.1994 +							UsePrecompiledHeader="2"
243.1995 +						/>
243.1996 +					</FileConfiguration>
243.1997 +					<FileConfiguration
243.1998 +						Name="Debug|Win32"
243.1999 +						>
243.2000 +						<Tool
243.2001 +							Name="VCCLCompilerTool"
243.2002 +							UsePrecompiledHeader="2"
243.2003 +						/>
243.2004 +					</FileConfiguration>
243.2005 +					<FileConfiguration
243.2006 +						Name="Release FastBuild|Win32"
243.2007 +						>
243.2008 +						<Tool
243.2009 +							Name="VCCLCompilerTool"
243.2010 +							UsePrecompiledHeader="2"
243.2011 +						/>
243.2012 +					</FileConfiguration>
243.2013 +				</File>
243.2014 +				<File
243.2015 +					RelativePath=".\CPP\7zip\Archive\Zip\ZipIn.cpp"
243.2016 +					>
243.2017 +					<FileConfiguration
243.2018 +						Name="Release|Win32"
243.2019 +						>
243.2020 +						<Tool
243.2021 +							Name="VCCLCompilerTool"
243.2022 +							UsePrecompiledHeader="2"
243.2023 +						/>
243.2024 +					</FileConfiguration>
243.2025 +					<FileConfiguration
243.2026 +						Name="Debug|Win32"
243.2027 +						>
243.2028 +						<Tool
243.2029 +							Name="VCCLCompilerTool"
243.2030 +							UsePrecompiledHeader="2"
243.2031 +						/>
243.2032 +					</FileConfiguration>
243.2033 +					<FileConfiguration
243.2034 +						Name="Release FastBuild|Win32"
243.2035 +						>
243.2036 +						<Tool
243.2037 +							Name="VCCLCompilerTool"
243.2038 +							UsePrecompiledHeader="2"
243.2039 +						/>
243.2040 +					</FileConfiguration>
243.2041 +				</File>
243.2042 +				<File
243.2043 +					RelativePath=".\CPP\7zip\Archive\Zip\ZipItem.cpp"
243.2044 +					>
243.2045 +					<FileConfiguration
243.2046 +						Name="Release|Win32"
243.2047 +						>
243.2048 +						<Tool
243.2049 +							Name="VCCLCompilerTool"
243.2050 +							UsePrecompiledHeader="2"
243.2051 +						/>
243.2052 +					</FileConfiguration>
243.2053 +					<FileConfiguration
243.2054 +						Name="Debug|Win32"
243.2055 +						>
243.2056 +						<Tool
243.2057 +							Name="VCCLCompilerTool"
243.2058 +							UsePrecompiledHeader="2"
243.2059 +						/>
243.2060 +					</FileConfiguration>
243.2061 +					<FileConfiguration
243.2062 +						Name="Release FastBuild|Win32"
243.2063 +						>
243.2064 +						<Tool
243.2065 +							Name="VCCLCompilerTool"
243.2066 +							UsePrecompiledHeader="2"
243.2067 +						/>
243.2068 +					</FileConfiguration>
243.2069 +				</File>
243.2070 +			</Filter>
243.2071 +			<Filter
243.2072 +				Name="Lzma Ar"
243.2073 +				>
243.2074 +				<File
243.2075 +					RelativePath=".\CPP\7zip\Archive\Lzma\LzmaFiltersDecode.cpp"
243.2076 +					>
243.2077 +					<FileConfiguration
243.2078 +						Name="Release|Win32"
243.2079 +						>
243.2080 +						<Tool
243.2081 +							Name="VCCLCompilerTool"
243.2082 +							UsePrecompiledHeader="2"
243.2083 +						/>
243.2084 +					</FileConfiguration>
243.2085 +					<FileConfiguration
243.2086 +						Name="Debug|Win32"
243.2087 +						>
243.2088 +						<Tool
243.2089 +							Name="VCCLCompilerTool"
243.2090 +							UsePrecompiledHeader="2"
243.2091 +						/>
243.2092 +					</FileConfiguration>
243.2093 +					<FileConfiguration
243.2094 +						Name="Release FastBuild|Win32"
243.2095 +						>
243.2096 +						<Tool
243.2097 +							Name="VCCLCompilerTool"
243.2098 +							UsePrecompiledHeader="2"
243.2099 +						/>
243.2100 +					</FileConfiguration>
243.2101 +				</File>
243.2102 +				<File
243.2103 +					RelativePath=".\CPP\7zip\Archive\Lzma\LzmaHandler.cpp"
243.2104 +					>
243.2105 +					<FileConfiguration
243.2106 +						Name="Release|Win32"
243.2107 +						>
243.2108 +						<Tool
243.2109 +							Name="VCCLCompilerTool"
243.2110 +							UsePrecompiledHeader="2"
243.2111 +						/>
243.2112 +					</FileConfiguration>
243.2113 +					<FileConfiguration
243.2114 +						Name="Debug|Win32"
243.2115 +						>
243.2116 +						<Tool
243.2117 +							Name="VCCLCompilerTool"
243.2118 +							UsePrecompiledHeader="2"
243.2119 +						/>
243.2120 +					</FileConfiguration>
243.2121 +					<FileConfiguration
243.2122 +						Name="Release FastBuild|Win32"
243.2123 +						>
243.2124 +						<Tool
243.2125 +							Name="VCCLCompilerTool"
243.2126 +							UsePrecompiledHeader="2"
243.2127 +						/>
243.2128 +					</FileConfiguration>
243.2129 +				</File>
243.2130 +				<File
243.2131 +					RelativePath=".\CPP\7zip\Archive\Lzma\LzmaIn.cpp"
243.2132 +					>
243.2133 +					<FileConfiguration
243.2134 +						Name="Release|Win32"
243.2135 +						>
243.2136 +						<Tool
243.2137 +							Name="VCCLCompilerTool"
243.2138 +							UsePrecompiledHeader="2"
243.2139 +						/>
243.2140 +					</FileConfiguration>
243.2141 +					<FileConfiguration
243.2142 +						Name="Debug|Win32"
243.2143 +						>
243.2144 +						<Tool
243.2145 +							Name="VCCLCompilerTool"
243.2146 +							UsePrecompiledHeader="2"
243.2147 +						/>
243.2148 +					</FileConfiguration>
243.2149 +					<FileConfiguration
243.2150 +						Name="Release FastBuild|Win32"
243.2151 +						>
243.2152 +						<Tool
243.2153 +							Name="VCCLCompilerTool"
243.2154 +							UsePrecompiledHeader="2"
243.2155 +						/>
243.2156 +					</FileConfiguration>
243.2157 +				</File>
243.2158 +			</Filter>
243.2159 +		</Filter>
243.2160 +		<Filter
243.2161 +			Name="C"
243.2162 +			>
243.2163 +			<File
243.2164 +				RelativePath=".\C\7zCrc.c"
243.2165 +				>
243.2166 +				<FileConfiguration
243.2167 +					Name="Release|Win32"
243.2168 +					>
243.2169 +					<Tool
243.2170 +						Name="VCCLCompilerTool"
243.2171 +						UsePrecompiledHeader="0"
243.2172 +					/>
243.2173 +				</FileConfiguration>
243.2174 +				<FileConfiguration
243.2175 +					Name="Debug|Win32"
243.2176 +					>
243.2177 +					<Tool
243.2178 +						Name="VCCLCompilerTool"
243.2179 +						UsePrecompiledHeader="0"
243.2180 +					/>
243.2181 +				</FileConfiguration>
243.2182 +				<FileConfiguration
243.2183 +					Name="Release FastBuild|Win32"
243.2184 +					>
243.2185 +					<Tool
243.2186 +						Name="VCCLCompilerTool"
243.2187 +						UsePrecompiledHeader="0"
243.2188 +					/>
243.2189 +				</FileConfiguration>
243.2190 +			</File>
243.2191 +			<File
243.2192 +				RelativePath=".\C\Aes.c"
243.2193 +				>
243.2194 +				<FileConfiguration
243.2195 +					Name="Release|Win32"
243.2196 +					>
243.2197 +					<Tool
243.2198 +						Name="VCCLCompilerTool"
243.2199 +						UsePrecompiledHeader="0"
243.2200 +					/>
243.2201 +				</FileConfiguration>
243.2202 +				<FileConfiguration
243.2203 +					Name="Debug|Win32"
243.2204 +					>
243.2205 +					<Tool
243.2206 +						Name="VCCLCompilerTool"
243.2207 +						UsePrecompiledHeader="0"
243.2208 +					/>
243.2209 +				</FileConfiguration>
243.2210 +				<FileConfiguration
243.2211 +					Name="Release FastBuild|Win32"
243.2212 +					>
243.2213 +					<Tool
243.2214 +						Name="VCCLCompilerTool"
243.2215 +						UsePrecompiledHeader="0"
243.2216 +					/>
243.2217 +				</FileConfiguration>
243.2218 +			</File>
243.2219 +			<File
243.2220 +				RelativePath=".\C\Alloc.c"
243.2221 +				>
243.2222 +				<FileConfiguration
243.2223 +					Name="Release|Win32"
243.2224 +					>
243.2225 +					<Tool
243.2226 +						Name="VCCLCompilerTool"
243.2227 +						UsePrecompiledHeader="0"
243.2228 +					/>
243.2229 +				</FileConfiguration>
243.2230 +				<FileConfiguration
243.2231 +					Name="Debug|Win32"
243.2232 +					>
243.2233 +					<Tool
243.2234 +						Name="VCCLCompilerTool"
243.2235 +						UsePrecompiledHeader="0"
243.2236 +					/>
243.2237 +				</FileConfiguration>
243.2238 +				<FileConfiguration
243.2239 +					Name="Release FastBuild|Win32"
243.2240 +					>
243.2241 +					<Tool
243.2242 +						Name="VCCLCompilerTool"
243.2243 +						UsePrecompiledHeader="0"
243.2244 +					/>
243.2245 +				</FileConfiguration>
243.2246 +			</File>
243.2247 +			<File
243.2248 +				RelativePath=".\C\Bra.c"
243.2249 +				>
243.2250 +				<FileConfiguration
243.2251 +					Name="Release|Win32"
243.2252 +					>
243.2253 +					<Tool
243.2254 +						Name="VCCLCompilerTool"
243.2255 +						UsePrecompiledHeader="0"
243.2256 +					/>
243.2257 +				</FileConfiguration>
243.2258 +				<FileConfiguration
243.2259 +					Name="Debug|Win32"
243.2260 +					>
243.2261 +					<Tool
243.2262 +						Name="VCCLCompilerTool"
243.2263 +						UsePrecompiledHeader="0"
243.2264 +					/>
243.2265 +				</FileConfiguration>
243.2266 +				<FileConfiguration
243.2267 +					Name="Release FastBuild|Win32"
243.2268 +					>
243.2269 +					<Tool
243.2270 +						Name="VCCLCompilerTool"
243.2271 +						UsePrecompiledHeader="0"
243.2272 +					/>
243.2273 +				</FileConfiguration>
243.2274 +			</File>
243.2275 +			<File
243.2276 +				RelativePath=".\C\Bra86.c"
243.2277 +				>
243.2278 +				<FileConfiguration
243.2279 +					Name="Release|Win32"
243.2280 +					>
243.2281 +					<Tool
243.2282 +						Name="VCCLCompilerTool"
243.2283 +						UsePrecompiledHeader="0"
243.2284 +					/>
243.2285 +				</FileConfiguration>
243.2286 +				<FileConfiguration
243.2287 +					Name="Debug|Win32"
243.2288 +					>
243.2289 +					<Tool
243.2290 +						Name="VCCLCompilerTool"
243.2291 +						UsePrecompiledHeader="0"
243.2292 +					/>
243.2293 +				</FileConfiguration>
243.2294 +				<FileConfiguration
243.2295 +					Name="Release FastBuild|Win32"
243.2296 +					>
243.2297 +					<Tool
243.2298 +						Name="VCCLCompilerTool"
243.2299 +						UsePrecompiledHeader="0"
243.2300 +					/>
243.2301 +				</FileConfiguration>
243.2302 +			</File>
243.2303 +			<File
243.2304 +				RelativePath=".\C\BraIA64.c"
243.2305 +				>
243.2306 +				<FileConfiguration
243.2307 +					Name="Release|Win32"
243.2308 +					>
243.2309 +					<Tool
243.2310 +						Name="VCCLCompilerTool"
243.2311 +						UsePrecompiledHeader="0"
243.2312 +					/>
243.2313 +				</FileConfiguration>
243.2314 +				<FileConfiguration
243.2315 +					Name="Debug|Win32"
243.2316 +					>
243.2317 +					<Tool
243.2318 +						Name="VCCLCompilerTool"
243.2319 +						UsePrecompiledHeader="0"
243.2320 +					/>
243.2321 +				</FileConfiguration>
243.2322 +				<FileConfiguration
243.2323 +					Name="Release FastBuild|Win32"
243.2324 +					>
243.2325 +					<Tool
243.2326 +						Name="VCCLCompilerTool"
243.2327 +						UsePrecompiledHeader="0"
243.2328 +					/>
243.2329 +				</FileConfiguration>
243.2330 +			</File>
243.2331 +			<File
243.2332 +				RelativePath=".\C\BwtSort.c"
243.2333 +				>
243.2334 +				<FileConfiguration
243.2335 +					Name="Release|Win32"
243.2336 +					>
243.2337 +					<Tool
243.2338 +						Name="VCCLCompilerTool"
243.2339 +						UsePrecompiledHeader="0"
243.2340 +					/>
243.2341 +				</FileConfiguration>
243.2342 +				<FileConfiguration
243.2343 +					Name="Debug|Win32"
243.2344 +					>
243.2345 +					<Tool
243.2346 +						Name="VCCLCompilerTool"
243.2347 +						UsePrecompiledHeader="0"
243.2348 +					/>
243.2349 +				</FileConfiguration>
243.2350 +				<FileConfiguration
243.2351 +					Name="Release FastBuild|Win32"
243.2352 +					>
243.2353 +					<Tool
243.2354 +						Name="VCCLCompilerTool"
243.2355 +						UsePrecompiledHeader="0"
243.2356 +					/>
243.2357 +				</FileConfiguration>
243.2358 +			</File>
243.2359 +			<File
243.2360 +				RelativePath=".\C\HuffEnc.c"
243.2361 +				>
243.2362 +				<FileConfiguration
243.2363 +					Name="Release|Win32"
243.2364 +					>
243.2365 +					<Tool
243.2366 +						Name="VCCLCompilerTool"
243.2367 +						UsePrecompiledHeader="0"
243.2368 +					/>
243.2369 +				</FileConfiguration>
243.2370 +				<FileConfiguration
243.2371 +					Name="Debug|Win32"
243.2372 +					>
243.2373 +					<Tool
243.2374 +						Name="VCCLCompilerTool"
243.2375 +						UsePrecompiledHeader="0"
243.2376 +					/>
243.2377 +				</FileConfiguration>
243.2378 +				<FileConfiguration
243.2379 +					Name="Release FastBuild|Win32"
243.2380 +					>
243.2381 +					<Tool
243.2382 +						Name="VCCLCompilerTool"
243.2383 +						UsePrecompiledHeader="0"
243.2384 +					/>
243.2385 +				</FileConfiguration>
243.2386 +			</File>
243.2387 +			<File
243.2388 +				RelativePath=".\C\LzFind.c"
243.2389 +				>
243.2390 +				<FileConfiguration
243.2391 +					Name="Release|Win32"
243.2392 +					>
243.2393 +					<Tool
243.2394 +						Name="VCCLCompilerTool"
243.2395 +						UsePrecompiledHeader="0"
243.2396 +					/>
243.2397 +				</FileConfiguration>
243.2398 +				<FileConfiguration
243.2399 +					Name="Debug|Win32"
243.2400 +					>
243.2401 +					<Tool
243.2402 +						Name="VCCLCompilerTool"
243.2403 +						UsePrecompiledHeader="0"
243.2404 +					/>
243.2405 +				</FileConfiguration>
243.2406 +				<FileConfiguration
243.2407 +					Name="Release FastBuild|Win32"
243.2408 +					>
243.2409 +					<Tool
243.2410 +						Name="VCCLCompilerTool"
243.2411 +						UsePrecompiledHeader="0"
243.2412 +					/>
243.2413 +				</FileConfiguration>
243.2414 +			</File>
243.2415 +			<File
243.2416 +				RelativePath=".\C\LzFindMt.c"
243.2417 +				>
243.2418 +				<FileConfiguration
243.2419 +					Name="Release|Win32"
243.2420 +					>
243.2421 +					<Tool
243.2422 +						Name="VCCLCompilerTool"
243.2423 +						UsePrecompiledHeader="0"
243.2424 +					/>
243.2425 +				</FileConfiguration>
243.2426 +				<FileConfiguration
243.2427 +					Name="Debug|Win32"
243.2428 +					>
243.2429 +					<Tool
243.2430 +						Name="VCCLCompilerTool"
243.2431 +						UsePrecompiledHeader="0"
243.2432 +					/>
243.2433 +				</FileConfiguration>
243.2434 +				<FileConfiguration
243.2435 +					Name="Release FastBuild|Win32"
243.2436 +					>
243.2437 +					<Tool
243.2438 +						Name="VCCLCompilerTool"
243.2439 +						UsePrecompiledHeader="0"
243.2440 +					/>
243.2441 +				</FileConfiguration>
243.2442 +			</File>
243.2443 +			<File
243.2444 +				RelativePath=".\C\LzmaDec.c"
243.2445 +				>
243.2446 +				<FileConfiguration
243.2447 +					Name="Release|Win32"
243.2448 +					>
243.2449 +					<Tool
243.2450 +						Name="VCCLCompilerTool"
243.2451 +						UsePrecompiledHeader="0"
243.2452 +					/>
243.2453 +				</FileConfiguration>
243.2454 +				<FileConfiguration
243.2455 +					Name="Debug|Win32"
243.2456 +					>
243.2457 +					<Tool
243.2458 +						Name="VCCLCompilerTool"
243.2459 +						UsePrecompiledHeader="0"
243.2460 +					/>
243.2461 +				</FileConfiguration>
243.2462 +				<FileConfiguration
243.2463 +					Name="Release FastBuild|Win32"
243.2464 +					>
243.2465 +					<Tool
243.2466 +						Name="VCCLCompilerTool"
243.2467 +						UsePrecompiledHeader="0"
243.2468 +					/>
243.2469 +				</FileConfiguration>
243.2470 +			</File>
243.2471 +			<File
243.2472 +				RelativePath=".\C\LzmaEnc.c"
243.2473 +				>
243.2474 +				<FileConfiguration
243.2475 +					Name="Release|Win32"
243.2476 +					>
243.2477 +					<Tool
243.2478 +						Name="VCCLCompilerTool"
243.2479 +						UsePrecompiledHeader="0"
243.2480 +					/>
243.2481 +				</FileConfiguration>
243.2482 +				<FileConfiguration
243.2483 +					Name="Debug|Win32"
243.2484 +					>
243.2485 +					<Tool
243.2486 +						Name="VCCLCompilerTool"
243.2487 +						UsePrecompiledHeader="0"
243.2488 +					/>
243.2489 +				</FileConfiguration>
243.2490 +				<FileConfiguration
243.2491 +					Name="Release FastBuild|Win32"
243.2492 +					>
243.2493 +					<Tool
243.2494 +						Name="VCCLCompilerTool"
243.2495 +						UsePrecompiledHeader="0"
243.2496 +					/>
243.2497 +				</FileConfiguration>
243.2498 +			</File>
243.2499 +			<File
243.2500 +				RelativePath=".\C\Sha256.c"
243.2501 +				>
243.2502 +				<FileConfiguration
243.2503 +					Name="Release|Win32"
243.2504 +					>
243.2505 +					<Tool
243.2506 +						Name="VCCLCompilerTool"
243.2507 +						UsePrecompiledHeader="0"
243.2508 +					/>
243.2509 +				</FileConfiguration>
243.2510 +				<FileConfiguration
243.2511 +					Name="Debug|Win32"
243.2512 +					>
243.2513 +					<Tool
243.2514 +						Name="VCCLCompilerTool"
243.2515 +						UsePrecompiledHeader="0"
243.2516 +					/>
243.2517 +				</FileConfiguration>
243.2518 +				<FileConfiguration
243.2519 +					Name="Release FastBuild|Win32"
243.2520 +					>
243.2521 +					<Tool
243.2522 +						Name="VCCLCompilerTool"
243.2523 +						UsePrecompiledHeader="0"
243.2524 +					/>
243.2525 +				</FileConfiguration>
243.2526 +			</File>
243.2527 +			<File
243.2528 +				RelativePath=".\C\Sort.c"
243.2529 +				>
243.2530 +				<FileConfiguration
243.2531 +					Name="Release|Win32"
243.2532 +					>
243.2533 +					<Tool
243.2534 +						Name="VCCLCompilerTool"
243.2535 +						UsePrecompiledHeader="0"
243.2536 +					/>
243.2537 +				</FileConfiguration>
243.2538 +				<FileConfiguration
243.2539 +					Name="Debug|Win32"
243.2540 +					>
243.2541 +					<Tool
243.2542 +						Name="VCCLCompilerTool"
243.2543 +						UsePrecompiledHeader="0"
243.2544 +					/>
243.2545 +				</FileConfiguration>
243.2546 +				<FileConfiguration
243.2547 +					Name="Release FastBuild|Win32"
243.2548 +					>
243.2549 +					<Tool
243.2550 +						Name="VCCLCompilerTool"
243.2551 +						UsePrecompiledHeader="0"
243.2552 +					/>
243.2553 +				</FileConfiguration>
243.2554 +			</File>
243.2555 +			<File
243.2556 +				RelativePath=".\C\Threads.c"
243.2557 +				>
243.2558 +				<FileConfiguration
243.2559 +					Name="Release|Win32"
243.2560 +					>
243.2561 +					<Tool
243.2562 +						Name="VCCLCompilerTool"
243.2563 +						UsePrecompiledHeader="0"
243.2564 +					/>
243.2565 +				</FileConfiguration>
243.2566 +				<FileConfiguration
243.2567 +					Name="Debug|Win32"
243.2568 +					>
243.2569 +					<Tool
243.2570 +						Name="VCCLCompilerTool"
243.2571 +						UsePrecompiledHeader="0"
243.2572 +					/>
243.2573 +				</FileConfiguration>
243.2574 +				<FileConfiguration
243.2575 +					Name="Release FastBuild|Win32"
243.2576 +					>
243.2577 +					<Tool
243.2578 +						Name="VCCLCompilerTool"
243.2579 +						UsePrecompiledHeader="0"
243.2580 +					/>
243.2581 +				</FileConfiguration>
243.2582 +			</File>
243.2583 +		</Filter>
243.2584 +		<Filter
243.2585 +			Name="Common"
243.2586 +			>
243.2587 +			<File
243.2588 +				RelativePath=".\CPP\Common\CRC.cpp"
243.2589 +				>
243.2590 +				<FileConfiguration
243.2591 +					Name="Release|Win32"
243.2592 +					>
243.2593 +					<Tool
243.2594 +						Name="VCCLCompilerTool"
243.2595 +						UsePrecompiledHeader="2"
243.2596 +					/>
243.2597 +				</FileConfiguration>
243.2598 +				<FileConfiguration
243.2599 +					Name="Debug|Win32"
243.2600 +					>
243.2601 +					<Tool
243.2602 +						Name="VCCLCompilerTool"
243.2603 +						UsePrecompiledHeader="2"
243.2604 +					/>
243.2605 +				</FileConfiguration>
243.2606 +				<FileConfiguration
243.2607 +					Name="Release FastBuild|Win32"
243.2608 +					>
243.2609 +					<Tool
243.2610 +						Name="VCCLCompilerTool"
243.2611 +						UsePrecompiledHeader="2"
243.2612 +					/>
243.2613 +				</FileConfiguration>
243.2614 +			</File>
243.2615 +			<File
243.2616 +				RelativePath=".\CPP\Common\IntToString.cpp"
243.2617 +				>
243.2618 +				<FileConfiguration
243.2619 +					Name="Release|Win32"
243.2620 +					>
243.2621 +					<Tool
243.2622 +						Name="VCCLCompilerTool"
243.2623 +						UsePrecompiledHeader="2"
243.2624 +					/>
243.2625 +				</FileConfiguration>
243.2626 +				<FileConfiguration
243.2627 +					Name="Debug|Win32"
243.2628 +					>
243.2629 +					<Tool
243.2630 +						Name="VCCLCompilerTool"
243.2631 +						UsePrecompiledHeader="2"
243.2632 +					/>
243.2633 +				</FileConfiguration>
243.2634 +				<FileConfiguration
243.2635 +					Name="Release FastBuild|Win32"
243.2636 +					>
243.2637 +					<Tool
243.2638 +						Name="VCCLCompilerTool"
243.2639 +						UsePrecompiledHeader="2"
243.2640 +					/>
243.2641 +				</FileConfiguration>
243.2642 +			</File>
243.2643 +			<File
243.2644 +				RelativePath=".\CPP\Common\MyMap.cpp"
243.2645 +				>
243.2646 +				<FileConfiguration
243.2647 +					Name="Release|Win32"
243.2648 +					>
243.2649 +					<Tool
243.2650 +						Name="VCCLCompilerTool"
243.2651 +						UsePrecompiledHeader="2"
243.2652 +					/>
243.2653 +				</FileConfiguration>
243.2654 +				<FileConfiguration
243.2655 +					Name="Debug|Win32"
243.2656 +					>
243.2657 +					<Tool
243.2658 +						Name="VCCLCompilerTool"
243.2659 +						UsePrecompiledHeader="2"
243.2660 +					/>
243.2661 +				</FileConfiguration>
243.2662 +				<FileConfiguration
243.2663 +					Name="Release FastBuild|Win32"
243.2664 +					>
243.2665 +					<Tool
243.2666 +						Name="VCCLCompilerTool"
243.2667 +						UsePrecompiledHeader="2"
243.2668 +					/>
243.2669 +				</FileConfiguration>
243.2670 +			</File>
243.2671 +			<File
243.2672 +				RelativePath=".\CPP\Common\MyString.cpp"
243.2673 +				>
243.2674 +				<FileConfiguration
243.2675 +					Name="Release|Win32"
243.2676 +					>
243.2677 +					<Tool
243.2678 +						Name="VCCLCompilerTool"
243.2679 +						UsePrecompiledHeader="2"
243.2680 +					/>
243.2681 +				</FileConfiguration>
243.2682 +				<FileConfiguration
243.2683 +					Name="Debug|Win32"
243.2684 +					>
243.2685 +					<Tool
243.2686 +						Name="VCCLCompilerTool"
243.2687 +						UsePrecompiledHeader="2"
243.2688 +					/>
243.2689 +				</FileConfiguration>
243.2690 +				<FileConfiguration
243.2691 +					Name="Release FastBuild|Win32"
243.2692 +					>
243.2693 +					<Tool
243.2694 +						Name="VCCLCompilerTool"
243.2695 +						UsePrecompiledHeader="2"
243.2696 +					/>
243.2697 +				</FileConfiguration>
243.2698 +			</File>
243.2699 +			<File
243.2700 +				RelativePath=".\CPP\Common\MyVector.cpp"
243.2701 +				>
243.2702 +				<FileConfiguration
243.2703 +					Name="Release|Win32"
243.2704 +					>
243.2705 +					<Tool
243.2706 +						Name="VCCLCompilerTool"
243.2707 +						UsePrecompiledHeader="2"
243.2708 +					/>
243.2709 +				</FileConfiguration>
243.2710 +				<FileConfiguration
243.2711 +					Name="Debug|Win32"
243.2712 +					>
243.2713 +					<Tool
243.2714 +						Name="VCCLCompilerTool"
243.2715 +						UsePrecompiledHeader="2"
243.2716 +					/>
243.2717 +				</FileConfiguration>
243.2718 +				<FileConfiguration
243.2719 +					Name="Release FastBuild|Win32"
243.2720 +					>
243.2721 +					<Tool
243.2722 +						Name="VCCLCompilerTool"
243.2723 +						UsePrecompiledHeader="2"
243.2724 +					/>
243.2725 +				</FileConfiguration>
243.2726 +			</File>
243.2727 +			<File
243.2728 +				RelativePath=".\CPP\Common\MyXml.cpp"
243.2729 +				>
243.2730 +				<FileConfiguration
243.2731 +					Name="Release|Win32"
243.2732 +					>
243.2733 +					<Tool
243.2734 +						Name="VCCLCompilerTool"
243.2735 +						UsePrecompiledHeader="2"
243.2736 +					/>
243.2737 +				</FileConfiguration>
243.2738 +				<FileConfiguration
243.2739 +					Name="Debug|Win32"
243.2740 +					>
243.2741 +					<Tool
243.2742 +						Name="VCCLCompilerTool"
243.2743 +						UsePrecompiledHeader="2"
243.2744 +					/>
243.2745 +				</FileConfiguration>
243.2746 +				<FileConfiguration
243.2747 +					Name="Release FastBuild|Win32"
243.2748 +					>
243.2749 +					<Tool
243.2750 +						Name="VCCLCompilerTool"
243.2751 +						UsePrecompiledHeader="2"
243.2752 +					/>
243.2753 +				</FileConfiguration>
243.2754 +			</File>
243.2755 +			<File
243.2756 +				RelativePath=".\CPP\Common\NewHandler.cpp"
243.2757 +				>
243.2758 +				<FileConfiguration
243.2759 +					Name="Release|Win32"
243.2760 +					ExcludedFromBuild="true"
243.2761 +					>
243.2762 +					<Tool
243.2763 +						Name="VCCLCompilerTool"
243.2764 +						UsePrecompiledHeader="2"
243.2765 +					/>
243.2766 +				</FileConfiguration>
243.2767 +				<FileConfiguration
243.2768 +					Name="Debug|Win32"
243.2769 +					ExcludedFromBuild="true"
243.2770 +					>
243.2771 +					<Tool
243.2772 +						Name="VCCLCompilerTool"
243.2773 +						UsePrecompiledHeader="2"
243.2774 +					/>
243.2775 +				</FileConfiguration>
243.2776 +				<FileConfiguration
243.2777 +					Name="Release FastBuild|Win32"
243.2778 +					ExcludedFromBuild="true"
243.2779 +					>
243.2780 +					<Tool
243.2781 +						Name="VCCLCompilerTool"
243.2782 +						UsePrecompiledHeader="2"
243.2783 +					/>
243.2784 +				</FileConfiguration>
243.2785 +			</File>
243.2786 +			<File
243.2787 +				RelativePath=".\CPP\Common\StringConvert.cpp"
243.2788 +				>
243.2789 +				<FileConfiguration
243.2790 +					Name="Release|Win32"
243.2791 +					>
243.2792 +					<Tool
243.2793 +						Name="VCCLCompilerTool"
243.2794 +						UsePrecompiledHeader="2"
243.2795 +					/>
243.2796 +				</FileConfiguration>
243.2797 +				<FileConfiguration
243.2798 +					Name="Debug|Win32"
243.2799 +					>
243.2800 +					<Tool
243.2801 +						Name="VCCLCompilerTool"
243.2802 +						UsePrecompiledHeader="2"
243.2803 +					/>
243.2804 +				</FileConfiguration>
243.2805 +				<FileConfiguration
243.2806 +					Name="Release FastBuild|Win32"
243.2807 +					>
243.2808 +					<Tool
243.2809 +						Name="VCCLCompilerTool"
243.2810 +						UsePrecompiledHeader="2"
243.2811 +					/>
243.2812 +				</FileConfiguration>
243.2813 +			</File>
243.2814 +			<File
243.2815 +				RelativePath=".\CPP\Common\StringToInt.cpp"
243.2816 +				>
243.2817 +				<FileConfiguration
243.2818 +					Name="Release|Win32"
243.2819 +					>
243.2820 +					<Tool
243.2821 +						Name="VCCLCompilerTool"
243.2822 +						UsePrecompiledHeader="2"
243.2823 +					/>
243.2824 +				</FileConfiguration>
243.2825 +				<FileConfiguration
243.2826 +					Name="Debug|Win32"
243.2827 +					>
243.2828 +					<Tool
243.2829 +						Name="VCCLCompilerTool"
243.2830 +						UsePrecompiledHeader="2"
243.2831 +					/>
243.2832 +				</FileConfiguration>
243.2833 +				<FileConfiguration
243.2834 +					Name="Release FastBuild|Win32"
243.2835 +					>
243.2836 +					<Tool
243.2837 +						Name="VCCLCompilerTool"
243.2838 +						UsePrecompiledHeader="2"
243.2839 +					/>
243.2840 +				</FileConfiguration>
243.2841 +			</File>
243.2842 +			<File
243.2843 +				RelativePath=".\CPP\Common\UTFConvert.cpp"
243.2844 +				>
243.2845 +				<FileConfiguration
243.2846 +					Name="Release|Win32"
243.2847 +					>
243.2848 +					<Tool
243.2849 +						Name="VCCLCompilerTool"
243.2850 +						UsePrecompiledHeader="2"
243.2851 +					/>
243.2852 +				</FileConfiguration>
243.2853 +				<FileConfiguration
243.2854 +					Name="Debug|Win32"
243.2855 +					>
243.2856 +					<Tool
243.2857 +						Name="VCCLCompilerTool"
243.2858 +						UsePrecompiledHeader="2"
243.2859 +					/>
243.2860 +				</FileConfiguration>
243.2861 +				<FileConfiguration
243.2862 +					Name="Release FastBuild|Win32"
243.2863 +					>
243.2864 +					<Tool
243.2865 +						Name="VCCLCompilerTool"
243.2866 +						UsePrecompiledHeader="2"
243.2867 +					/>
243.2868 +				</FileConfiguration>
243.2869 +			</File>
243.2870 +			<File
243.2871 +				RelativePath=".\CPP\Common\Wildcard.cpp"
243.2872 +				>
243.2873 +				<FileConfiguration
243.2874 +					Name="Release|Win32"
243.2875 +					>
243.2876 +					<Tool
243.2877 +						Name="VCCLCompilerTool"
243.2878 +						UsePrecompiledHeader="2"
243.2879 +					/>
243.2880 +				</FileConfiguration>
243.2881 +				<FileConfiguration
243.2882 +					Name="Debug|Win32"
243.2883 +					>
243.2884 +					<Tool
243.2885 +						Name="VCCLCompilerTool"
243.2886 +						UsePrecompiledHeader="2"
243.2887 +					/>
243.2888 +				</FileConfiguration>
243.2889 +				<FileConfiguration
243.2890 +					Name="Release FastBuild|Win32"
243.2891 +					>
243.2892 +					<Tool
243.2893 +						Name="VCCLCompilerTool"
243.2894 +						UsePrecompiledHeader="2"
243.2895 +					/>
243.2896 +				</FileConfiguration>
243.2897 +			</File>
243.2898 +		</Filter>
243.2899 +		<Filter
243.2900 +			Name="Compress"
243.2901 +			>
243.2902 +			<File
243.2903 +				RelativePath=".\CPP\7zip\Compress\LzhDecoder.cpp"
243.2904 +				>
243.2905 +				<FileConfiguration
243.2906 +					Name="Release|Win32"
243.2907 +					>
243.2908 +					<Tool
243.2909 +						Name="VCCLCompilerTool"
243.2910 +						UsePrecompiledHeader="2"
243.2911 +					/>
243.2912 +				</FileConfiguration>
243.2913 +				<FileConfiguration
243.2914 +					Name="Debug|Win32"
243.2915 +					>
243.2916 +					<Tool
243.2917 +						Name="VCCLCompilerTool"
243.2918 +						UsePrecompiledHeader="2"
243.2919 +					/>
243.2920 +				</FileConfiguration>
243.2921 +				<FileConfiguration
243.2922 +					Name="Release FastBuild|Win32"
243.2923 +					>
243.2924 +					<Tool
243.2925 +						Name="VCCLCompilerTool"
243.2926 +						UsePrecompiledHeader="2"
243.2927 +					/>
243.2928 +				</FileConfiguration>
243.2929 +			</File>
243.2930 +			<File
243.2931 +				RelativePath=".\CPP\7zip\Compress\LzOutWindow.cpp"
243.2932 +				>
243.2933 +				<FileConfiguration
243.2934 +					Name="Release|Win32"
243.2935 +					>
243.2936 +					<Tool
243.2937 +						Name="VCCLCompilerTool"
243.2938 +						UsePrecompiledHeader="2"
243.2939 +					/>
243.2940 +				</FileConfiguration>
243.2941 +				<FileConfiguration
243.2942 +					Name="Debug|Win32"
243.2943 +					>
243.2944 +					<Tool
243.2945 +						Name="VCCLCompilerTool"
243.2946 +						UsePrecompiledHeader="2"
243.2947 +					/>
243.2948 +				</FileConfiguration>
243.2949 +				<FileConfiguration
243.2950 +					Name="Release FastBuild|Win32"
243.2951 +					>
243.2952 +					<Tool
243.2953 +						Name="VCCLCompilerTool"
243.2954 +						UsePrecompiledHeader="2"
243.2955 +					/>
243.2956 +				</FileConfiguration>
243.2957 +			</File>
243.2958 +			<Filter
243.2959 +				Name="PPMD"
243.2960 +				>
243.2961 +				<File
243.2962 +					RelativePath=".\CPP\7zip\Compress\PpmdDecoder.cpp"
243.2963 +					>
243.2964 +					<FileConfiguration
243.2965 +						Name="Release|Win32"
243.2966 +						>
243.2967 +						<Tool
243.2968 +							Name="VCCLCompilerTool"
243.2969 +							UsePrecompiledHeader="2"
243.2970 +						/>
243.2971 +					</FileConfiguration>
243.2972 +					<FileConfiguration
243.2973 +						Name="Debug|Win32"
243.2974 +						>
243.2975 +						<Tool
243.2976 +							Name="VCCLCompilerTool"
243.2977 +							UsePrecompiledHeader="2"
243.2978 +						/>
243.2979 +					</FileConfiguration>
243.2980 +					<FileConfiguration
243.2981 +						Name="Release FastBuild|Win32"
243.2982 +						>
243.2983 +						<Tool
243.2984 +							Name="VCCLCompilerTool"
243.2985 +							UsePrecompiledHeader="2"
243.2986 +						/>
243.2987 +					</FileConfiguration>
243.2988 +				</File>
243.2989 +			</Filter>
243.2990 +			<Filter
243.2991 +				Name="Bit Coder"
243.2992 +				>
243.2993 +				<File
243.2994 +					RelativePath=".\CPP\7zip\Compress\BitlDecoder.cpp"
243.2995 +					>
243.2996 +					<FileConfiguration
243.2997 +						Name="Release|Win32"
243.2998 +						>
243.2999 +						<Tool
243.3000 +							Name="VCCLCompilerTool"
243.3001 +							UsePrecompiledHeader="2"
243.3002 +						/>
243.3003 +					</FileConfiguration>
243.3004 +					<FileConfiguration
243.3005 +						Name="Debug|Win32"
243.3006 +						>
243.3007 +						<Tool
243.3008 +							Name="VCCLCompilerTool"
243.3009 +							UsePrecompiledHeader="2"
243.3010 +						/>
243.3011 +					</FileConfiguration>
243.3012 +					<FileConfiguration
243.3013 +						Name="Release FastBuild|Win32"
243.3014 +						>
243.3015 +						<Tool
243.3016 +							Name="VCCLCompilerTool"
243.3017 +							UsePrecompiledHeader="2"
243.3018 +						/>
243.3019 +					</FileConfiguration>
243.3020 +				</File>
243.3021 +			</Filter>
243.3022 +			<Filter
243.3023 +				Name="Rar Compress"
243.3024 +				>
243.3025 +				<File
243.3026 +					RelativePath=".\CPP\7zip\Compress\Rar1Decoder.cpp"
243.3027 +					>
243.3028 +					<FileConfiguration
243.3029 +						Name="Release|Win32"
243.3030 +						>
243.3031 +						<Tool
243.3032 +							Name="VCCLCompilerTool"
243.3033 +							UsePrecompiledHeader="2"
243.3034 +						/>
243.3035 +					</FileConfiguration>
243.3036 +					<FileConfiguration
243.3037 +						Name="Debug|Win32"
243.3038 +						>
243.3039 +						<Tool
243.3040 +							Name="VCCLCompilerTool"
243.3041 +							UsePrecompiledHeader="2"
243.3042 +						/>
243.3043 +					</FileConfiguration>
243.3044 +					<FileConfiguration
243.3045 +						Name="Release FastBuild|Win32"
243.3046 +						>
243.3047 +						<Tool
243.3048 +							Name="VCCLCompilerTool"
243.3049 +							UsePrecompiledHeader="2"
243.3050 +						/>
243.3051 +					</FileConfiguration>
243.3052 +				</File>
243.3053 +				<File
243.3054 +					RelativePath=".\CPP\7zip\Compress\Rar2Decoder.cpp"
243.3055 +					>
243.3056 +					<FileConfiguration
243.3057 +						Name="Release|Win32"
243.3058 +						>
243.3059 +						<Tool
243.3060 +							Name="VCCLCompilerTool"
243.3061 +							UsePrecompiledHeader="2"
243.3062 +						/>
243.3063 +					</FileConfiguration>
243.3064 +					<FileConfiguration
243.3065 +						Name="Debug|Win32"
243.3066 +						>
243.3067 +						<Tool
243.3068 +							Name="VCCLCompilerTool"
243.3069 +							UsePrecompiledHeader="2"
243.3070 +						/>
243.3071 +					</FileConfiguration>
243.3072 +					<FileConfiguration
243.3073 +						Name="Release FastBuild|Win32"
243.3074 +						>
243.3075 +						<Tool
243.3076 +							Name="VCCLCompilerTool"
243.3077 +							UsePrecompiledHeader="2"
243.3078 +						/>
243.3079 +					</FileConfiguration>
243.3080 +				</File>
243.3081 +				<File
243.3082 +					RelativePath=".\CPP\7zip\Compress\Rar3Decoder.cpp"
243.3083 +					>
243.3084 +					<FileConfiguration
243.3085 +						Name="Release|Win32"
243.3086 +						>
243.3087 +						<Tool
243.3088 +							Name="VCCLCompilerTool"
243.3089 +							UsePrecompiledHeader="2"
243.3090 +						/>
243.3091 +					</FileConfiguration>
243.3092 +					<FileConfiguration
243.3093 +						Name="Debug|Win32"
243.3094 +						>
243.3095 +						<Tool
243.3096 +							Name="VCCLCompilerTool"
243.3097 +							UsePrecompiledHeader="2"
243.3098 +						/>
243.3099 +					</FileConfiguration>
243.3100 +					<FileConfiguration
243.3101 +						Name="Release FastBuild|Win32"
243.3102 +						>
243.3103 +						<Tool
243.3104 +							Name="VCCLCompilerTool"
243.3105 +							UsePrecompiledHeader="2"
243.3106 +						/>
243.3107 +					</FileConfiguration>
243.3108 +				</File>
243.3109 +				<File
243.3110 +					RelativePath=".\CPP\7zip\Compress\Rar3Vm.cpp"
243.3111 +					>
243.3112 +					<FileConfiguration
243.3113 +						Name="Release|Win32"
243.3114 +						>
243.3115 +						<Tool
243.3116 +							Name="VCCLCompilerTool"
243.3117 +							UsePrecompiledHeader="2"
243.3118 +						/>
243.3119 +					</FileConfiguration>
243.3120 +					<FileConfiguration
243.3121 +						Name="Debug|Win32"
243.3122 +						>
243.3123 +						<Tool
243.3124 +							Name="VCCLCompilerTool"
243.3125 +							UsePrecompiledHeader="2"
243.3126 +						/>
243.3127 +					</FileConfiguration>
243.3128 +					<FileConfiguration
243.3129 +						Name="Release FastBuild|Win32"
243.3130 +						>
243.3131 +						<Tool
243.3132 +							Name="VCCLCompilerTool"
243.3133 +							UsePrecompiledHeader="2"
243.3134 +						/>
243.3135 +					</FileConfiguration>
243.3136 +				</File>
243.3137 +			</Filter>
243.3138 +			<Filter
243.3139 +				Name="BZip2 Compress"
243.3140 +				>
243.3141 +				<File
243.3142 +					RelativePath=".\CPP\7zip\Compress\BZip2Crc.cpp"
243.3143 +					>
243.3144 +					<FileConfiguration
243.3145 +						Name="Release|Win32"
243.3146 +						>
243.3147 +						<Tool
243.3148 +							Name="VCCLCompilerTool"
243.3149 +							UsePrecompiledHeader="2"
243.3150 +						/>
243.3151 +					</FileConfiguration>
243.3152 +					<FileConfiguration
243.3153 +						Name="Debug|Win32"
243.3154 +						>
243.3155 +						<Tool
243.3156 +							Name="VCCLCompilerTool"
243.3157 +							UsePrecompiledHeader="2"
243.3158 +						/>
243.3159 +					</FileConfiguration>
243.3160 +					<FileConfiguration
243.3161 +						Name="Release FastBuild|Win32"
243.3162 +						>
243.3163 +						<Tool
243.3164 +							Name="VCCLCompilerTool"
243.3165 +							UsePrecompiledHeader="2"
243.3166 +						/>
243.3167 +					</FileConfiguration>
243.3168 +				</File>
243.3169 +				<File
243.3170 +					RelativePath=".\CPP\7zip\Compress\BZip2Decoder.cpp"
243.3171 +					>
243.3172 +					<FileConfiguration
243.3173 +						Name="Release|Win32"
243.3174 +						>
243.3175 +						<Tool
243.3176 +							Name="VCCLCompilerTool"
243.3177 +							UsePrecompiledHeader="2"
243.3178 +						/>
243.3179 +					</FileConfiguration>
243.3180 +					<FileConfiguration
243.3181 +						Name="Debug|Win32"
243.3182 +						>
243.3183 +						<Tool
243.3184 +							Name="VCCLCompilerTool"
243.3185 +							UsePrecompiledHeader="2"
243.3186 +						/>
243.3187 +					</FileConfiguration>
243.3188 +					<FileConfiguration
243.3189 +						Name="Release FastBuild|Win32"
243.3190 +						>
243.3191 +						<Tool
243.3192 +							Name="VCCLCompilerTool"
243.3193 +							UsePrecompiledHeader="2"
243.3194 +						/>
243.3195 +					</FileConfiguration>
243.3196 +				</File>
243.3197 +			</Filter>
243.3198 +			<Filter
243.3199 +				Name="Zip Compress"
243.3200 +				>
243.3201 +				<File
243.3202 +					RelativePath=".\CPP\7zip\Compress\DeflateDecoder.cpp"
243.3203 +					>
243.3204 +					<FileConfiguration
243.3205 +						Name="Release|Win32"
243.3206 +						>
243.3207 +						<Tool
243.3208 +							Name="VCCLCompilerTool"
243.3209 +							UsePrecompiledHeader="2"
243.3210 +						/>
243.3211 +					</FileConfiguration>
243.3212 +					<FileConfiguration
243.3213 +						Name="Debug|Win32"
243.3214 +						>
243.3215 +						<Tool
243.3216 +							Name="VCCLCompilerTool"
243.3217 +							UsePrecompiledHeader="2"
243.3218 +						/>
243.3219 +					</FileConfiguration>
243.3220 +					<FileConfiguration
243.3221 +						Name="Release FastBuild|Win32"
243.3222 +						>
243.3223 +						<Tool
243.3224 +							Name="VCCLCompilerTool"
243.3225 +							UsePrecompiledHeader="2"
243.3226 +						/>
243.3227 +					</FileConfiguration>
243.3228 +				</File>
243.3229 +				<File
243.3230 +					RelativePath=".\CPP\7zip\Compress\ImplodeDecoder.cpp"
243.3231 +					>
243.3232 +					<FileConfiguration
243.3233 +						Name="Release|Win32"
243.3234 +						>
243.3235 +						<Tool
243.3236 +							Name="VCCLCompilerTool"
243.3237 +							UsePrecompiledHeader="2"
243.3238 +						/>
243.3239 +					</FileConfiguration>
243.3240 +					<FileConfiguration
243.3241 +						Name="Debug|Win32"
243.3242 +						>
243.3243 +						<Tool
243.3244 +							Name="VCCLCompilerTool"
243.3245 +							UsePrecompiledHeader="2"
243.3246 +						/>
243.3247 +					</FileConfiguration>
243.3248 +					<FileConfiguration
243.3249 +						Name="Release FastBuild|Win32"
243.3250 +						>
243.3251 +						<Tool
243.3252 +							Name="VCCLCompilerTool"
243.3253 +							UsePrecompiledHeader="2"
243.3254 +						/>
243.3255 +					</FileConfiguration>
243.3256 +				</File>
243.3257 +				<File
243.3258 +					RelativePath=".\CPP\7zip\Compress\ImplodeHuffmanDecoder.cpp"
243.3259 +					>
243.3260 +					<FileConfiguration
243.3261 +						Name="Release|Win32"
243.3262 +						>
243.3263 +						<Tool
243.3264 +							Name="VCCLCompilerTool"
243.3265 +							UsePrecompiledHeader="2"
243.3266 +						/>
243.3267 +					</FileConfiguration>
243.3268 +					<FileConfiguration
243.3269 +						Name="Debug|Win32"
243.3270 +						>
243.3271 +						<Tool
243.3272 +							Name="VCCLCompilerTool"
243.3273 +							UsePrecompiledHeader="2"
243.3274 +						/>
243.3275 +					</FileConfiguration>
243.3276 +					<FileConfiguration
243.3277 +						Name="Release FastBuild|Win32"
243.3278 +						>
243.3279 +						<Tool
243.3280 +							Name="VCCLCompilerTool"
243.3281 +							UsePrecompiledHeader="2"
243.3282 +						/>
243.3283 +					</FileConfiguration>
243.3284 +				</File>
243.3285 +				<File
243.3286 +					RelativePath=".\CPP\7zip\Compress\ShrinkDecoder.cpp"
243.3287 +					>
243.3288 +					<FileConfiguration
243.3289 +						Name="Release|Win32"
243.3290 +						>
243.3291 +						<Tool
243.3292 +							Name="VCCLCompilerTool"
243.3293 +							UsePrecompiledHeader="2"
243.3294 +						/>
243.3295 +					</FileConfiguration>
243.3296 +					<FileConfiguration
243.3297 +						Name="Debug|Win32"
243.3298 +						>
243.3299 +						<Tool
243.3300 +							Name="VCCLCompilerTool"
243.3301 +							UsePrecompiledHeader="2"
243.3302 +						/>
243.3303 +					</FileConfiguration>
243.3304 +					<FileConfiguration
243.3305 +						Name="Release FastBuild|Win32"
243.3306 +						>
243.3307 +						<Tool
243.3308 +							Name="VCCLCompilerTool"
243.3309 +							UsePrecompiledHeader="2"
243.3310 +						/>
243.3311 +					</FileConfiguration>
243.3312 +				</File>
243.3313 +				<File
243.3314 +					RelativePath=".\CPP\7zip\Compress\ZlibDecoder.cpp"
243.3315 +					>
243.3316 +					<FileConfiguration
243.3317 +						Name="Release|Win32"
243.3318 +						>
243.3319 +						<Tool
243.3320 +							Name="VCCLCompilerTool"
243.3321 +							UsePrecompiledHeader="2"
243.3322 +						/>
243.3323 +					</FileConfiguration>
243.3324 +					<FileConfiguration
243.3325 +						Name="Debug|Win32"
243.3326 +						>
243.3327 +						<Tool
243.3328 +							Name="VCCLCompilerTool"
243.3329 +							UsePrecompiledHeader="2"
243.3330 +						/>
243.3331 +					</FileConfiguration>
243.3332 +					<FileConfiguration
243.3333 +						Name="Release FastBuild|Win32"
243.3334 +						>
243.3335 +						<Tool
243.3336 +							Name="VCCLCompilerTool"
243.3337 +							UsePrecompiledHeader="2"
243.3338 +						/>
243.3339 +					</FileConfiguration>
243.3340 +				</File>
243.3341 +			</Filter>
243.3342 +			<Filter
243.3343 +				Name="7z Compress"
243.3344 +				>
243.3345 +				<File
243.3346 +					RelativePath=".\CPP\7zip\Compress\Bcj2Coder.cpp"
243.3347 +					>
243.3348 +					<FileConfiguration
243.3349 +						Name="Release|Win32"
243.3350 +						>
243.3351 +						<Tool
243.3352 +							Name="VCCLCompilerTool"
243.3353 +							UsePrecompiledHeader="2"
243.3354 +						/>
243.3355 +					</FileConfiguration>
243.3356 +					<FileConfiguration
243.3357 +						Name="Debug|Win32"
243.3358 +						>
243.3359 +						<Tool
243.3360 +							Name="VCCLCompilerTool"
243.3361 +							UsePrecompiledHeader="2"
243.3362 +						/>
243.3363 +					</FileConfiguration>
243.3364 +					<FileConfiguration
243.3365 +						Name="Release FastBuild|Win32"
243.3366 +						>
243.3367 +						<Tool
243.3368 +							Name="VCCLCompilerTool"
243.3369 +							UsePrecompiledHeader="2"
243.3370 +						/>
243.3371 +					</FileConfiguration>
243.3372 +				</File>
243.3373 +				<File
243.3374 +					RelativePath=".\CPP\7zip\Compress\BcjCoder.cpp"
243.3375 +					>
243.3376 +					<FileConfiguration
243.3377 +						Name="Release|Win32"
243.3378 +						>
243.3379 +						<Tool
243.3380 +							Name="VCCLCompilerTool"
243.3381 +							UsePrecompiledHeader="2"
243.3382 +						/>
243.3383 +					</FileConfiguration>
243.3384 +					<FileConfiguration
243.3385 +						Name="Debug|Win32"
243.3386 +						>
243.3387 +						<Tool
243.3388 +							Name="VCCLCompilerTool"
243.3389 +							UsePrecompiledHeader="2"
243.3390 +						/>
243.3391 +					</FileConfiguration>
243.3392 +					<FileConfiguration
243.3393 +						Name="Release FastBuild|Win32"
243.3394 +						>
243.3395 +						<Tool
243.3396 +							Name="VCCLCompilerTool"
243.3397 +							UsePrecompiledHeader="2"
243.3398 +						/>
243.3399 +					</FileConfiguration>
243.3400 +				</File>
243.3401 +				<File
243.3402 +					RelativePath=".\CPP\7zip\Compress\BranchCoder.cpp"
243.3403 +					>
243.3404 +					<FileConfiguration
243.3405 +						Name="Release|Win32"
243.3406 +						>
243.3407 +						<Tool
243.3408 +							Name="VCCLCompilerTool"
243.3409 +							UsePrecompiledHeader="2"
243.3410 +						/>
243.3411 +					</FileConfiguration>
243.3412 +					<FileConfiguration
243.3413 +						Name="Debug|Win32"
243.3414 +						>
243.3415 +						<Tool
243.3416 +							Name="VCCLCompilerTool"
243.3417 +							UsePrecompiledHeader="2"
243.3418 +						/>
243.3419 +					</FileConfiguration>
243.3420 +					<FileConfiguration
243.3421 +						Name="Release FastBuild|Win32"
243.3422 +						>
243.3423 +						<Tool
243.3424 +							Name="VCCLCompilerTool"
243.3425 +							UsePrecompiledHeader="2"
243.3426 +						/>
243.3427 +					</FileConfiguration>
243.3428 +				</File>
243.3429 +				<File
243.3430 +					RelativePath=".\CPP\7zip\Compress\BranchMisc.cpp"
243.3431 +					>
243.3432 +					<FileConfiguration
243.3433 +						Name="Release|Win32"
243.3434 +						>
243.3435 +						<Tool
243.3436 +							Name="VCCLCompilerTool"
243.3437 +							UsePrecompiledHeader="2"
243.3438 +						/>
243.3439 +					</FileConfiguration>
243.3440 +					<FileConfiguration
243.3441 +						Name="Debug|Win32"
243.3442 +						>
243.3443 +						<Tool
243.3444 +							Name="VCCLCompilerTool"
243.3445 +							UsePrecompiledHeader="2"
243.3446 +						/>
243.3447 +					</FileConfiguration>
243.3448 +					<FileConfiguration
243.3449 +						Name="Release FastBuild|Win32"
243.3450 +						>
243.3451 +						<Tool
243.3452 +							Name="VCCLCompilerTool"
243.3453 +							UsePrecompiledHeader="2"
243.3454 +						/>
243.3455 +					</FileConfiguration>
243.3456 +				</File>
243.3457 +				<File
243.3458 +					RelativePath=".\CPP\7zip\Compress\ByteSwap.cpp"
243.3459 +					>
243.3460 +					<FileConfiguration
243.3461 +						Name="Release|Win32"
243.3462 +						>
243.3463 +						<Tool
243.3464 +							Name="VCCLCompilerTool"
243.3465 +							UsePrecompiledHeader="2"
243.3466 +						/>
243.3467 +					</FileConfiguration>
243.3468 +					<FileConfiguration
243.3469 +						Name="Debug|Win32"
243.3470 +						>
243.3471 +						<Tool
243.3472 +							Name="VCCLCompilerTool"
243.3473 +							UsePrecompiledHeader="2"
243.3474 +						/>
243.3475 +					</FileConfiguration>
243.3476 +					<FileConfiguration
243.3477 +						Name="Release FastBuild|Win32"
243.3478 +						>
243.3479 +						<Tool
243.3480 +							Name="VCCLCompilerTool"
243.3481 +							UsePrecompiledHeader="2"
243.3482 +						/>
243.3483 +					</FileConfiguration>
243.3484 +				</File>
243.3485 +				<File
243.3486 +					RelativePath=".\CPP\7zip\Compress\CopyCoder.cpp"
243.3487 +					>
243.3488 +					<FileConfiguration
243.3489 +						Name="Release|Win32"
243.3490 +						>
243.3491 +						<Tool
243.3492 +							Name="VCCLCompilerTool"
243.3493 +							UsePrecompiledHeader="2"
243.3494 +						/>
243.3495 +					</FileConfiguration>
243.3496 +					<FileConfiguration
243.3497 +						Name="Debug|Win32"
243.3498 +						>
243.3499 +						<Tool
243.3500 +							Name="VCCLCompilerTool"
243.3501 +							UsePrecompiledHeader="2"
243.3502 +						/>
243.3503 +					</FileConfiguration>
243.3504 +					<FileConfiguration
243.3505 +						Name="Release FastBuild|Win32"
243.3506 +						>
243.3507 +						<Tool
243.3508 +							Name="VCCLCompilerTool"
243.3509 +							UsePrecompiledHeader="2"
243.3510 +						/>
243.3511 +					</FileConfiguration>
243.3512 +				</File>
243.3513 +				<File
243.3514 +					RelativePath=".\CPP\7zip\Compress\LzmaDecoder.cpp"
243.3515 +					>
243.3516 +					<FileConfiguration
243.3517 +						Name="Release|Win32"
243.3518 +						>
243.3519 +						<Tool
243.3520 +							Name="VCCLCompilerTool"
243.3521 +							UsePrecompiledHeader="2"
243.3522 +						/>
243.3523 +					</FileConfiguration>
243.3524 +					<FileConfiguration
243.3525 +						Name="Debug|Win32"
243.3526 +						>
243.3527 +						<Tool
243.3528 +							Name="VCCLCompilerTool"
243.3529 +							UsePrecompiledHeader="2"
243.3530 +						/>
243.3531 +					</FileConfiguration>
243.3532 +					<FileConfiguration
243.3533 +						Name="Release FastBuild|Win32"
243.3534 +						>
243.3535 +						<Tool
243.3536 +							Name="VCCLCompilerTool"
243.3537 +							UsePrecompiledHeader="2"
243.3538 +						/>
243.3539 +					</FileConfiguration>
243.3540 +				</File>
243.3541 +			</Filter>
243.3542 +		</Filter>
243.3543 +		<Filter
243.3544 +			Name="Crypto"
243.3545 +			>
243.3546 +			<File
243.3547 +				RelativePath=".\CPP\7zip\Crypto\7zAes.cpp"
243.3548 +				>
243.3549 +				<FileConfiguration
243.3550 +					Name="Release|Win32"
243.3551 +					>
243.3552 +					<Tool
243.3553 +						Name="VCCLCompilerTool"
243.3554 +						UsePrecompiledHeader="2"
243.3555 +					/>
243.3556 +				</FileConfiguration>
243.3557 +				<FileConfiguration
243.3558 +					Name="Debug|Win32"
243.3559 +					>
243.3560 +					<Tool
243.3561 +						Name="VCCLCompilerTool"
243.3562 +						UsePrecompiledHeader="2"
243.3563 +					/>
243.3564 +				</FileConfiguration>
243.3565 +				<FileConfiguration
243.3566 +					Name="Release FastBuild|Win32"
243.3567 +					>
243.3568 +					<Tool
243.3569 +						Name="VCCLCompilerTool"
243.3570 +						UsePrecompiledHeader="2"
243.3571 +					/>
243.3572 +				</FileConfiguration>
243.3573 +			</File>
243.3574 +			<File
243.3575 +				RelativePath=".\CPP\7zip\Crypto\HmacSha1.cpp"
243.3576 +				>
243.3577 +				<FileConfiguration
243.3578 +					Name="Release|Win32"
243.3579 +					>
243.3580 +					<Tool
243.3581 +						Name="VCCLCompilerTool"
243.3582 +						UsePrecompiledHeader="2"
243.3583 +					/>
243.3584 +				</FileConfiguration>
243.3585 +				<FileConfiguration
243.3586 +					Name="Debug|Win32"
243.3587 +					>
243.3588 +					<Tool
243.3589 +						Name="VCCLCompilerTool"
243.3590 +						UsePrecompiledHeader="2"
243.3591 +					/>
243.3592 +				</FileConfiguration>
243.3593 +				<FileConfiguration
243.3594 +					Name="Release FastBuild|Win32"
243.3595 +					>
243.3596 +					<Tool
243.3597 +						Name="VCCLCompilerTool"
243.3598 +						UsePrecompiledHeader="2"
243.3599 +					/>
243.3600 +				</FileConfiguration>
243.3601 +			</File>
243.3602 +			<File
243.3603 +				RelativePath=".\CPP\7zip\Crypto\MyAes.cpp"
243.3604 +				>
243.3605 +				<FileConfiguration
243.3606 +					Name="Release|Win32"
243.3607 +					>
243.3608 +					<Tool
243.3609 +						Name="VCCLCompilerTool"
243.3610 +						UsePrecompiledHeader="2"
243.3611 +					/>
243.3612 +				</FileConfiguration>
243.3613 +				<FileConfiguration
243.3614 +					Name="Debug|Win32"
243.3615 +					>
243.3616 +					<Tool
243.3617 +						Name="VCCLCompilerTool"
243.3618 +						UsePrecompiledHeader="2"
243.3619 +					/>
243.3620 +				</FileConfiguration>
243.3621 +				<FileConfiguration
243.3622 +					Name="Release FastBuild|Win32"
243.3623 +					>
243.3624 +					<Tool
243.3625 +						Name="VCCLCompilerTool"
243.3626 +						UsePrecompiledHeader="2"
243.3627 +					/>
243.3628 +				</FileConfiguration>
243.3629 +			</File>
243.3630 +			<File
243.3631 +				RelativePath=".\CPP\7zip\Crypto\Pbkdf2HmacSha1.cpp"
243.3632 +				>
243.3633 +				<FileConfiguration
243.3634 +					Name="Release|Win32"
243.3635 +					>
243.3636 +					<Tool
243.3637 +						Name="VCCLCompilerTool"
243.3638 +						UsePrecompiledHeader="2"
243.3639 +					/>
243.3640 +				</FileConfiguration>
243.3641 +				<FileConfiguration
243.3642 +					Name="Debug|Win32"
243.3643 +					>
243.3644 +					<Tool
243.3645 +						Name="VCCLCompilerTool"
243.3646 +						UsePrecompiledHeader="2"
243.3647 +					/>
243.3648 +				</FileConfiguration>
243.3649 +				<FileConfiguration
243.3650 +					Name="Release FastBuild|Win32"
243.3651 +					>
243.3652 +					<Tool
243.3653 +						Name="VCCLCompilerTool"
243.3654 +						UsePrecompiledHeader="2"
243.3655 +					/>
243.3656 +				</FileConfiguration>
243.3657 +			</File>
243.3658 +			<File
243.3659 +				RelativePath=".\CPP\7zip\Crypto\RandGen.cpp"
243.3660 +				>
243.3661 +				<FileConfiguration
243.3662 +					Name="Release|Win32"
243.3663 +					>
243.3664 +					<Tool
243.3665 +						Name="VCCLCompilerTool"
243.3666 +						UsePrecompiledHeader="2"
243.3667 +					/>
243.3668 +				</FileConfiguration>
243.3669 +				<FileConfiguration
243.3670 +					Name="Debug|Win32"
243.3671 +					>
243.3672 +					<Tool
243.3673 +						Name="VCCLCompilerTool"
243.3674 +						UsePrecompiledHeader="2"
243.3675 +					/>
243.3676 +				</FileConfiguration>
243.3677 +				<FileConfiguration
243.3678 +					Name="Release FastBuild|Win32"
243.3679 +					>
243.3680 +					<Tool
243.3681 +						Name="VCCLCompilerTool"
243.3682 +						UsePrecompiledHeader="2"
243.3683 +					/>
243.3684 +				</FileConfiguration>
243.3685 +			</File>
243.3686 +			<File
243.3687 +				RelativePath=".\CPP\7zip\Crypto\Rar20Crypto.cpp"
243.3688 +				>
243.3689 +				<FileConfiguration
243.3690 +					Name="Release|Win32"
243.3691 +					>
243.3692 +					<Tool
243.3693 +						Name="VCCLCompilerTool"
243.3694 +						UsePrecompiledHeader="2"
243.3695 +					/>
243.3696 +				</FileConfiguration>
243.3697 +				<FileConfiguration
243.3698 +					Name="Debug|Win32"
243.3699 +					>
243.3700 +					<Tool
243.3701 +						Name="VCCLCompilerTool"
243.3702 +						UsePrecompiledHeader="2"
243.3703 +					/>
243.3704 +				</FileConfiguration>
243.3705 +				<FileConfiguration
243.3706 +					Name="Release FastBuild|Win32"
243.3707 +					>
243.3708 +					<Tool
243.3709 +						Name="VCCLCompilerTool"
243.3710 +						UsePrecompiledHeader="2"
243.3711 +					/>
243.3712 +				</FileConfiguration>
243.3713 +			</File>
243.3714 +			<File
243.3715 +				RelativePath=".\CPP\7zip\Crypto\RarAes.cpp"
243.3716 +				>
243.3717 +				<FileConfiguration
243.3718 +					Name="Release|Win32"
243.3719 +					>
243.3720 +					<Tool
243.3721 +						Name="VCCLCompilerTool"
243.3722 +						UsePrecompiledHeader="2"
243.3723 +					/>
243.3724 +				</FileConfiguration>
243.3725 +				<FileConfiguration
243.3726 +					Name="Debug|Win32"
243.3727 +					>
243.3728 +					<Tool
243.3729 +						Name="VCCLCompilerTool"
243.3730 +						UsePrecompiledHeader="2"
243.3731 +					/>
243.3732 +				</FileConfiguration>
243.3733 +				<FileConfiguration
243.3734 +					Name="Release FastBuild|Win32"
243.3735 +					>
243.3736 +					<Tool
243.3737 +						Name="VCCLCompilerTool"
243.3738 +						UsePrecompiledHeader="2"
243.3739 +					/>
243.3740 +				</FileConfiguration>
243.3741 +			</File>
243.3742 +			<File
243.3743 +				RelativePath=".\CPP\7zip\Crypto\Sha1.cpp"
243.3744 +				>
243.3745 +				<FileConfiguration
243.3746 +					Name="Release|Win32"
243.3747 +					>
243.3748 +					<Tool
243.3749 +						Name="VCCLCompilerTool"
243.3750 +						UsePrecompiledHeader="2"
243.3751 +					/>
243.3752 +				</FileConfiguration>
243.3753 +				<FileConfiguration
243.3754 +					Name="Debug|Win32"
243.3755 +					>
243.3756 +					<Tool
243.3757 +						Name="VCCLCompilerTool"
243.3758 +						UsePrecompiledHeader="2"
243.3759 +					/>
243.3760 +				</FileConfiguration>
243.3761 +				<FileConfiguration
243.3762 +					Name="Release FastBuild|Win32"
243.3763 +					>
243.3764 +					<Tool
243.3765 +						Name="VCCLCompilerTool"
243.3766 +						UsePrecompiledHeader="2"
243.3767 +					/>
243.3768 +				</FileConfiguration>
243.3769 +			</File>
243.3770 +			<File
243.3771 +				RelativePath=".\CPP\7zip\Crypto\WzAes.cpp"
243.3772 +				>
243.3773 +				<FileConfiguration
243.3774 +					Name="Release|Win32"
243.3775 +					>
243.3776 +					<Tool
243.3777 +						Name="VCCLCompilerTool"
243.3778 +						UsePrecompiledHeader="2"
243.3779 +					/>
243.3780 +				</FileConfiguration>
243.3781 +				<FileConfiguration
243.3782 +					Name="Debug|Win32"
243.3783 +					>
243.3784 +					<Tool
243.3785 +						Name="VCCLCompilerTool"
243.3786 +						UsePrecompiledHeader="2"
243.3787 +					/>
243.3788 +				</FileConfiguration>
243.3789 +				<FileConfiguration
243.3790 +					Name="Release FastBuild|Win32"
243.3791 +					>
243.3792 +					<Tool
243.3793 +						Name="VCCLCompilerTool"
243.3794 +						UsePrecompiledHeader="2"
243.3795 +					/>
243.3796 +				</FileConfiguration>
243.3797 +			</File>
243.3798 +			<File
243.3799 +				RelativePath=".\CPP\7zip\Crypto\ZipCrypto.cpp"
243.3800 +				>
243.3801 +				<FileConfiguration
243.3802 +					Name="Release|Win32"
243.3803 +					>
243.3804 +					<Tool
243.3805 +						Name="VCCLCompilerTool"
243.3806 +						UsePrecompiledHeader="2"
243.3807 +					/>
243.3808 +				</FileConfiguration>
243.3809 +				<FileConfiguration
243.3810 +					Name="Debug|Win32"
243.3811 +					>
243.3812 +					<Tool
243.3813 +						Name="VCCLCompilerTool"
243.3814 +						UsePrecompiledHeader="2"
243.3815 +					/>
243.3816 +				</FileConfiguration>
243.3817 +				<FileConfiguration
243.3818 +					Name="Release FastBuild|Win32"
243.3819 +					>
243.3820 +					<Tool
243.3821 +						Name="VCCLCompilerTool"
243.3822 +						UsePrecompiledHeader="2"
243.3823 +					/>
243.3824 +				</FileConfiguration>
243.3825 +			</File>
243.3826 +			<File
243.3827 +				RelativePath=".\CPP\7zip\Crypto\ZipStrong.cpp"
243.3828 +				>
243.3829 +				<FileConfiguration
243.3830 +					Name="Release|Win32"
243.3831 +					>
243.3832 +					<Tool
243.3833 +						Name="VCCLCompilerTool"
243.3834 +						UsePrecompiledHeader="2"
243.3835 +					/>
243.3836 +				</FileConfiguration>
243.3837 +				<FileConfiguration
243.3838 +					Name="Debug|Win32"
243.3839 +					>
243.3840 +					<Tool
243.3841 +						Name="VCCLCompilerTool"
243.3842 +						UsePrecompiledHeader="2"
243.3843 +					/>
243.3844 +				</FileConfiguration>
243.3845 +				<FileConfiguration
243.3846 +					Name="Release FastBuild|Win32"
243.3847 +					>
243.3848 +					<Tool
243.3849 +						Name="VCCLCompilerTool"
243.3850 +						UsePrecompiledHeader="2"
243.3851 +					/>
243.3852 +				</FileConfiguration>
243.3853 +			</File>
243.3854 +		</Filter>
243.3855 +		<Filter
243.3856 +			Name="Headers"
243.3857 +			>
243.3858 +			<File
243.3859 +				RelativePath=".\CPP\7zip\Crypto\7zAes.h"
243.3860 +				>
243.3861 +			</File>
243.3862 +			<File
243.3863 +				RelativePath=".\CPP\7zip\Archive\7z\7zCompressionMode.h"
243.3864 +				>
243.3865 +			</File>
243.3866 +			<File
243.3867 +				RelativePath=".\C\7zCrc.h"
243.3868 +				>
243.3869 +			</File>
243.3870 +			<File
243.3871 +				RelativePath=".\CPP\7zip\Archive\7z\7zDecode.h"
243.3872 +				>
243.3873 +			</File>
243.3874 +			<File
243.3875 +				RelativePath=".\CPP\7zip\Archive\7z\7zFolderInStream.h"
243.3876 +				>
243.3877 +			</File>
243.3878 +			<File
243.3879 +				RelativePath=".\CPP\7zip\Archive\7z\7zFolderOutStream.h"
243.3880 +				>
243.3881 +			</File>
243.3882 +			<File
243.3883 +				RelativePath=".\CPP\7zip\Archive\7z\7zHandler.h"
243.3884 +				>
243.3885 +			</File>
243.3886 +			<File
243.3887 +				RelativePath=".\CPP\7zip\Archive\7z\7zHeader.h"
243.3888 +				>
243.3889 +			</File>
243.3890 +			<File
243.3891 +				RelativePath=".\CPP\7zip\Archive\7z\7zIn.h"
243.3892 +				>
243.3893 +			</File>
243.3894 +			<File
243.3895 +				RelativePath=".\CPP\7zip\Archive\7z\7zItem.h"
243.3896 +				>
243.3897 +			</File>
243.3898 +			<File
243.3899 +				RelativePath=".\CPP\7zip\Archive\7z\7zProperties.h"
243.3900 +				>
243.3901 +			</File>
243.3902 +			<File
243.3903 +				RelativePath=".\CPP\7zip\Archive\7z\7zSpecStream.h"
243.3904 +				>
243.3905 +			</File>
243.3906 +			<File
243.3907 +				RelativePath=".\C\Aes.h"
243.3908 +				>
243.3909 +			</File>
243.3910 +			<File
243.3911 +				RelativePath=".\C\Alloc.h"
243.3912 +				>
243.3913 +			</File>
243.3914 +			<File
243.3915 +				RelativePath=".\CPP\7zip\Compress\Bcj2Coder.h"
243.3916 +				>
243.3917 +			</File>
243.3918 +			<File
243.3919 +				RelativePath=".\CPP\7zip\Compress\BcjCoder.h"
243.3920 +				>
243.3921 +			</File>
243.3922 +			<File
243.3923 +				RelativePath=".\CPP\7zip\Compress\BitlDecoder.h"
243.3924 +				>
243.3925 +			</File>
243.3926 +			<File
243.3927 +				RelativePath=".\CPP\7zip\Compress\BitmDecoder.h"
243.3928 +				>
243.3929 +			</File>
243.3930 +			<File
243.3931 +				RelativePath=".\C\Bra.h"
243.3932 +				>
243.3933 +			</File>
243.3934 +			<File
243.3935 +				RelativePath=".\CPP\7zip\Compress\BranchCoder.h"
243.3936 +				>
243.3937 +			</File>
243.3938 +			<File
243.3939 +				RelativePath=".\CPP\7zip\Compress\BranchMisc.h"
243.3940 +				>
243.3941 +			</File>
243.3942 +			<File
243.3943 +				RelativePath=".\CPP\Common\Buffer.h"
243.3944 +				>
243.3945 +			</File>
243.3946 +			<File
243.3947 +				RelativePath=".\C\BwtSort.h"
243.3948 +				>
243.3949 +			</File>
243.3950 +			<File
243.3951 +				RelativePath=".\CPP\7zip\Compress\ByteSwap.h"
243.3952 +				>
243.3953 +			</File>
243.3954 +			<File
243.3955 +				RelativePath=".\CPP\7zip\Compress\BZip2Const.h"
243.3956 +				>
243.3957 +			</File>
243.3958 +			<File
243.3959 +				RelativePath=".\CPP\7zip\Compress\BZip2Crc.h"
243.3960 +				>
243.3961 +			</File>
243.3962 +			<File
243.3963 +				RelativePath=".\CPP\7zip\Compress\BZip2Decoder.h"
243.3964 +				>
243.3965 +			</File>
243.3966 +			<File
243.3967 +				RelativePath=".\CPP\7zip\Archive\BZip2\BZip2Handler.h"
243.3968 +				>
243.3969 +			</File>
243.3970 +			<File
243.3971 +				RelativePath=".\CPP\7zip\Archive\BZip2\BZip2Item.h"
243.3972 +				>
243.3973 +			</File>
243.3974 +			<File
243.3975 +				RelativePath=".\CPP\7zip\Archive\Common\CoderMixer2.h"
243.3976 +				>
243.3977 +			</File>
243.3978 +			<File
243.3979 +				RelativePath=".\CPP\7zip\Archive\Common\CoderMixer2MT.h"
243.3980 +				>
243.3981 +			</File>
243.3982 +			<File
243.3983 +				RelativePath=".\CPP\Common\ComTry.h"
243.3984 +				>
243.3985 +			</File>
243.3986 +			<File
243.3987 +				RelativePath=".\CPP\7zip\Compress\CopyCoder.h"
243.3988 +				>
243.3989 +			</File>
243.3990 +			<File
243.3991 +				RelativePath=".\C\CpuArch.h"
243.3992 +				>
243.3993 +			</File>
243.3994 +			<File
243.3995 +				RelativePath=".\CPP\7zip\Common\CreateCoder.h"
243.3996 +				>
243.3997 +			</File>
243.3998 +			<File
243.3999 +				RelativePath=".\CPP\7zip\Common\DeclareArcs.h"
243.4000 +				>
243.4001 +			</File>
243.4002 +			<File
243.4003 +				RelativePath=".\CPP\7zip\Common\DeclareCodecs.h"
243.4004 +				>
243.4005 +			</File>
243.4006 +			<File
243.4007 +				RelativePath=".\CPP\7zip\Compress\DeflateConst.h"
243.4008 +				>
243.4009 +			</File>
243.4010 +			<File
243.4011 +				RelativePath=".\CPP\7zip\Compress\DeflateDecoder.h"
243.4012 +				>
243.4013 +			</File>
243.4014 +			<File
243.4015 +				RelativePath=".\CPP\Windows\Defs.h"
243.4016 +				>
243.4017 +			</File>
243.4018 +			<File
243.4019 +				RelativePath=".\CPP\Common\Defs.h"
243.4020 +				>
243.4021 +			</File>
243.4022 +			<File
243.4023 +				RelativePath=".\CPP\7zip\Archive\Common\DummyOutStream.h"
243.4024 +				>
243.4025 +			</File>
243.4026 +			<File
243.4027 +				RelativePath=".\CPP\Common\DynamicBuffer.h"
243.4028 +				>
243.4029 +			</File>
243.4030 +			<File
243.4031 +				RelativePath=".\CPP\Windows\FileDir.h"
243.4032 +				>
243.4033 +			</File>
243.4034 +			<File
243.4035 +				RelativePath=".\CPP\Windows\FileFind.h"
243.4036 +				>
243.4037 +			</File>
243.4038 +			<File
243.4039 +				RelativePath=".\CPP\Windows\FileIO.h"
243.4040 +				>
243.4041 +			</File>
243.4042 +			<File
243.4043 +				RelativePath=".\CPP\Windows\FileName.h"
243.4044 +				>
243.4045 +			</File>
243.4046 +			<File
243.4047 +				RelativePath=".\CPP\7zip\Common\FilterCoder.h"
243.4048 +				>
243.4049 +			</File>
243.4050 +			<File
243.4051 +				RelativePath=".\CPP\7zip\Archive\Common\FindSignature.h"
243.4052 +				>
243.4053 +			</File>
243.4054 +			<File
243.4055 +				RelativePath=".\CPP\7zip\Archive\GZip\GZipHandler.h"
243.4056 +				>
243.4057 +			</File>
243.4058 +			<File
243.4059 +				RelativePath=".\CPP\7zip\Archive\GZip\GZipHeader.h"
243.4060 +				>
243.4061 +			</File>
243.4062 +			<File
243.4063 +				RelativePath=".\CPP\7zip\Archive\GZip\GZipIn.h"
243.4064 +				>
243.4065 +			</File>
243.4066 +			<File
243.4067 +				RelativePath=".\CPP\7zip\Archive\GZip\GZipItem.h"
243.4068 +				>
243.4069 +			</File>
243.4070 +			<File
243.4071 +				RelativePath=".\CPP\7zip\Archive\GZip\GZipUpdate.h"
243.4072 +				>
243.4073 +			</File>
243.4074 +			<File
243.4075 +				RelativePath=".\CPP\Windows\Handle.h"
243.4076 +				>
243.4077 +			</File>
243.4078 +			<File
243.4079 +				RelativePath=".\CPP\7zip\Crypto\HmacSha1.h"
243.4080 +				>
243.4081 +			</File>
243.4082 +			<File
243.4083 +				RelativePath=".\C\HuffEnc.h"
243.4084 +				>
243.4085 +			</File>
243.4086 +			<File
243.4087 +				RelativePath=".\CPP\7zip\Compress\HuffmanDecoder.h"
243.4088 +				>
243.4089 +			</File>
243.4090 +			<File
243.4091 +				RelativePath=".\CPP\7zip\Archive\IArchive.h"
243.4092 +				>
243.4093 +			</File>
243.4094 +			<File
243.4095 +				RelativePath=".\CPP\7zip\ICoder.h"
243.4096 +				>
243.4097 +			</File>
243.4098 +			<File
243.4099 +				RelativePath=".\CPP\7zip\IDecl.h"
243.4100 +				>
243.4101 +			</File>
243.4102 +			<File
243.4103 +				RelativePath=".\CPP\7zip\Compress\ImplodeDecoder.h"
243.4104 +				>
243.4105 +			</File>
243.4106 +			<File
243.4107 +				RelativePath=".\CPP\7zip\Compress\ImplodeHuffmanDecoder.h"
243.4108 +				>
243.4109 +			</File>
243.4110 +			<File
243.4111 +				RelativePath=".\CPP\7zip\Common\InBuffer.h"
243.4112 +				>
243.4113 +			</File>
243.4114 +			<File
243.4115 +				RelativePath=".\CPP\Common\InitializeStaticLib.h"
243.4116 +				>
243.4117 +			</File>
243.4118 +			<File
243.4119 +				RelativePath=".\CPP\7zip\Common\InOutTempBuffer.h"
243.4120 +				>
243.4121 +			</File>
243.4122 +			<File
243.4123 +				RelativePath=".\CPP\7zip\Archive\Common\InStreamWithCRC.h"
243.4124 +				>
243.4125 +			</File>
243.4126 +			<File
243.4127 +				RelativePath=".\CPP\Common\IntToString.h"
243.4128 +				>
243.4129 +			</File>
243.4130 +			<File
243.4131 +				RelativePath=".\CPP\7zip\IPassword.h"
243.4132 +				>
243.4133 +			</File>
243.4134 +			<File
243.4135 +				RelativePath=".\CPP\7zip\IProgress.h"
243.4136 +				>
243.4137 +			</File>
243.4138 +			<File
243.4139 +				RelativePath=".\CPP\7zip\IStream.h"
243.4140 +				>
243.4141 +			</File>
243.4142 +			<File
243.4143 +				RelativePath=".\CPP\7zip\Archive\Common\ItemNameUtils.h"
243.4144 +				>
243.4145 +			</File>
243.4146 +			<File
243.4147 +				RelativePath=".\CPP\7zip\Common\LimitedStreams.h"
243.4148 +				>
243.4149 +			</File>
243.4150 +			<File
243.4151 +				RelativePath=".\CPP\7zip\Common\LockedStream.h"
243.4152 +				>
243.4153 +			</File>
243.4154 +			<File
243.4155 +				RelativePath=".\C\LzFind.h"
243.4156 +				>
243.4157 +			</File>
243.4158 +			<File
243.4159 +				RelativePath=".\C\LzFindMt.h"
243.4160 +				>
243.4161 +			</File>
243.4162 +			<File
243.4163 +				RelativePath=".\C\LzHash.h"
243.4164 +				>
243.4165 +			</File>
243.4166 +			<File
243.4167 +				RelativePath=".\CPP\7zip\Archive\Lzh\LzhCRC.h"
243.4168 +				>
243.4169 +			</File>
243.4170 +			<File
243.4171 +				RelativePath=".\CPP\7zip\Compress\LzhDecoder.h"
243.4172 +				>
243.4173 +			</File>
243.4174 +			<File
243.4175 +				RelativePath=".\CPP\7zip\Archive\Lzh\LzhHandler.h"
243.4176 +				>
243.4177 +			</File>
243.4178 +			<File
243.4179 +				RelativePath=".\CPP\7zip\Archive\Lzh\LzhHeader.h"
243.4180 +				>
243.4181 +			</File>
243.4182 +			<File
243.4183 +				RelativePath=".\CPP\7zip\Archive\Lzh\LzhIn.h"
243.4184 +				>
243.4185 +			</File>
243.4186 +			<File
243.4187 +				RelativePath=".\CPP\7zip\Archive\Lzh\LzhItem.h"
243.4188 +				>
243.4189 +			</File>
243.4190 +			<File
243.4191 +				RelativePath=".\CPP\7zip\Archive\Lzh\LzhOutStreamWithCRC.h"
243.4192 +				>
243.4193 +			</File>
243.4194 +			<File
243.4195 +				RelativePath=".\C\LzmaDec.h"
243.4196 +				>
243.4197 +			</File>
243.4198 +			<File
243.4199 +				RelativePath=".\CPP\7zip\Compress\LzmaDecoder.h"
243.4200 +				>
243.4201 +			</File>
243.4202 +			<File
243.4203 +				RelativePath=".\C\LzmaEnc.h"
243.4204 +				>
243.4205 +			</File>
243.4206 +			<File
243.4207 +				RelativePath=".\CPP\7zip\Archive\Lzma\LzmaFiltersDecode.h"
243.4208 +				>
243.4209 +			</File>
243.4210 +			<File
243.4211 +				RelativePath=".\CPP\7zip\Archive\Lzma\LzmaHandler.h"
243.4212 +				>
243.4213 +			</File>
243.4214 +			<File
243.4215 +				RelativePath=".\CPP\7zip\Archive\Lzma\LzmaIn.h"
243.4216 +				>
243.4217 +			</File>
243.4218 +			<File
243.4219 +				RelativePath=".\CPP\7zip\Archive\Lzma\LzmaItem.h"
243.4220 +				>
243.4221 +			</File>
243.4222 +			<File
243.4223 +				RelativePath=".\CPP\7zip\Compress\LzOutWindow.h"
243.4224 +				>
243.4225 +			</File>
243.4226 +			<File
243.4227 +				RelativePath=".\CPP\7zip\Common\MemBlocks.h"
243.4228 +				>
243.4229 +			</File>
243.4230 +			<File
243.4231 +				RelativePath=".\CPP\7zip\Common\MethodId.h"
243.4232 +				>
243.4233 +			</File>
243.4234 +			<File
243.4235 +				RelativePath=".\CPP\7zip\Common\MethodProps.h"
243.4236 +				>
243.4237 +			</File>
243.4238 +			<File
243.4239 +				RelativePath=".\CPP\7zip\Compress\Mtf8.h"
243.4240 +				>
243.4241 +			</File>
243.4242 +			<File
243.4243 +				RelativePath=".\CPP\7zip\Archive\Common\MultiStream.h"
243.4244 +				>
243.4245 +			</File>
243.4246 +			<File
243.4247 +				RelativePath=".\CPP\7zip\Crypto\MyAes.h"
243.4248 +				>
243.4249 +			</File>
243.4250 +			<File
243.4251 +				RelativePath=".\CPP\Common\MyCom.h"
243.4252 +				>
243.4253 +			</File>
243.4254 +			<File
243.4255 +				RelativePath=".\CPP\Common\MyException.h"
243.4256 +				>
243.4257 +			</File>
243.4258 +			<File
243.4259 +				RelativePath=".\CPP\Common\MyInitGuid.h"
243.4260 +				>
243.4261 +			</File>
243.4262 +			<File
243.4263 +				RelativePath=".\CPP\Common\MyMap.h"
243.4264 +				>
243.4265 +			</File>
243.4266 +			<File
243.4267 +				RelativePath=".\CPP\Common\MyString.h"
243.4268 +				>
243.4269 +			</File>
243.4270 +			<File
243.4271 +				RelativePath=".\CPP\Common\MyUnknown.h"
243.4272 +				>
243.4273 +			</File>
243.4274 +			<File
243.4275 +				RelativePath=".\CPP\Common\MyVector.h"
243.4276 +				>
243.4277 +			</File>
243.4278 +			<File
243.4279 +				RelativePath=".\CPP\Common\MyWindows.h"
243.4280 +				>
243.4281 +			</File>
243.4282 +			<File
243.4283 +				RelativePath=".\CPP\Common\MyXml.h"
243.4284 +				>
243.4285 +			</File>
243.4286 +			<File
243.4287 +				RelativePath=".\CPP\Common\NewHandler.h"
243.4288 +				>
243.4289 +			</File>
243.4290 +			<File
243.4291 +				RelativePath=".\CPP\7zip\Common\OffsetStream.h"
243.4292 +				>
243.4293 +			</File>
243.4294 +			<File
243.4295 +				RelativePath=".\CPP\7zip\Common\OutBuffer.h"
243.4296 +				>
243.4297 +			</File>
243.4298 +			<File
243.4299 +				RelativePath=".\CPP\7zip\Common\OutMemStream.h"
243.4300 +				>
243.4301 +			</File>
243.4302 +			<File
243.4303 +				RelativePath=".\CPP\7zip\Archive\Common\OutStreamWithCRC.h"
243.4304 +				>
243.4305 +			</File>
243.4306 +			<File
243.4307 +				RelativePath=".\CPP\7zip\Archive\Common\ParseProperties.h"
243.4308 +				>
243.4309 +			</File>
243.4310 +			<File
243.4311 +				RelativePath=".\CPP\7zip\Crypto\Pbkdf2HmacSha1.h"
243.4312 +				>
243.4313 +			</File>
243.4314 +			<File
243.4315 +				RelativePath=".\CPP\7zip\Compress\PpmdContext.h"
243.4316 +				>
243.4317 +			</File>
243.4318 +			<File
243.4319 +				RelativePath=".\CPP\7zip\Compress\PpmdDecode.h"
243.4320 +				>
243.4321 +			</File>
243.4322 +			<File
243.4323 +				RelativePath=".\CPP\7zip\Compress\PpmdDecoder.h"
243.4324 +				>
243.4325 +			</File>
243.4326 +			<File
243.4327 +				RelativePath=".\CPP\7zip\Compress\PpmdSubAlloc.h"
243.4328 +				>
243.4329 +			</File>
243.4330 +			<File
243.4331 +				RelativePath=".\CPP\7zip\Compress\PpmdType.h"
243.4332 +				>
243.4333 +			</File>
243.4334 +			<File
243.4335 +				RelativePath=".\CPP\7zip\Common\ProgressMt.h"
243.4336 +				>
243.4337 +			</File>
243.4338 +			<File
243.4339 +				RelativePath=".\CPP\7zip\Common\ProgressUtils.h"
243.4340 +				>
243.4341 +			</File>
243.4342 +			<File
243.4343 +				RelativePath=".\CPP\7zip\PropID.h"
243.4344 +				>
243.4345 +			</File>
243.4346 +			<File
243.4347 +				RelativePath=".\CPP\Windows\PropVariant.h"
243.4348 +				>
243.4349 +			</File>
243.4350 +			<File
243.4351 +				RelativePath=".\CPP\7zip\Crypto\RandGen.h"
243.4352 +				>
243.4353 +			</File>
243.4354 +			<File
243.4355 +				RelativePath=".\CPP\7zip\Compress\RangeCoder.h"
243.4356 +				>
243.4357 +			</File>
243.4358 +			<File
243.4359 +				RelativePath=".\CPP\7zip\Compress\RangeCoderBit.h"
243.4360 +				>
243.4361 +			</File>
243.4362 +			<File
243.4363 +				RelativePath=".\CPP\7zip\Compress\Rar1Decoder.h"
243.4364 +				>
243.4365 +			</File>
243.4366 +			<File
243.4367 +				RelativePath=".\CPP\7zip\Crypto\Rar20Crypto.h"
243.4368 +				>
243.4369 +			</File>
243.4370 +			<File
243.4371 +				RelativePath=".\CPP\7zip\Compress\Rar2Decoder.h"
243.4372 +				>
243.4373 +			</File>
243.4374 +			<File
243.4375 +				RelativePath=".\CPP\7zip\Compress\Rar3Decoder.h"
243.4376 +				>
243.4377 +			</File>
243.4378 +			<File
243.4379 +				RelativePath=".\CPP\7zip\Compress\Rar3Vm.h"
243.4380 +				>
243.4381 +			</File>
243.4382 +			<File
243.4383 +				RelativePath=".\CPP\7zip\Crypto\RarAes.h"
243.4384 +				>
243.4385 +			</File>
243.4386 +			<File
243.4387 +				RelativePath=".\CPP\7zip\Archive\Rar\RarHandler.h"
243.4388 +				>
243.4389 +			</File>
243.4390 +			<File
243.4391 +				RelativePath=".\CPP\7zip\Archive\Rar\RarHeader.h"
243.4392 +				>
243.4393 +			</File>
243.4394 +			<File
243.4395 +				RelativePath=".\CPP\7zip\Archive\Rar\RarIn.h"
243.4396 +				>
243.4397 +			</File>
243.4398 +			<File
243.4399 +				RelativePath=".\CPP\7zip\Archive\Rar\RarItem.h"
243.4400 +				>
243.4401 +			</File>
243.4402 +			<File
243.4403 +				RelativePath=".\CPP\7zip\Archive\Rar\RarVolumeInStream.h"
243.4404 +				>
243.4405 +			</File>
243.4406 +			<File
243.4407 +				RelativePath=".\CPP\7zip\Common\RegisterArc.h"
243.4408 +				>
243.4409 +			</File>
243.4410 +			<File
243.4411 +				RelativePath=".\CPP\7zip\Common\RegisterCodec.h"
243.4412 +				>
243.4413 +			</File>
243.4414 +			<File
243.4415 +				RelativePath=".\C\RotateDefs.h"
243.4416 +				>
243.4417 +			</File>
243.4418 +			<File
243.4419 +				RelativePath=".\CPP\7zip\Crypto\Sha1.h"
243.4420 +				>
243.4421 +			</File>
243.4422 +			<File
243.4423 +				RelativePath=".\C\Sha256.h"
243.4424 +				>
243.4425 +			</File>
243.4426 +			<File
243.4427 +				RelativePath=".\CPP\7zip\Compress\ShrinkDecoder.h"
243.4428 +				>
243.4429 +			</File>
243.4430 +			<File
243.4431 +				RelativePath=".\C\Sort.h"
243.4432 +				>
243.4433 +			</File>
243.4434 +			<File
243.4435 +				RelativePath=".\CPP\7zip\Archive\Split\SplitHandler.h"
243.4436 +				>
243.4437 +			</File>
243.4438 +			<File
243.4439 +				RelativePath=".\CPP\7zip\Archive\Common\StdAfx.h"
243.4440 +				>
243.4441 +			</File>
243.4442 +			<File
243.4443 +				RelativePath=".\CPP\7zip\Archive\Rar\StdAfx.h"
243.4444 +				>
243.4445 +			</File>
243.4446 +			<File
243.4447 +				RelativePath=".\CPP\7zip\Archive\BZip2\StdAfx.h"
243.4448 +				>
243.4449 +			</File>
243.4450 +			<File
243.4451 +				RelativePath=".\CPP\Windows\StdAfx.h"
243.4452 +				>
243.4453 +			</File>
243.4454 +			<File
243.4455 +				RelativePath=".\CPP\7zip\Archive\7z\StdAfx.h"
243.4456 +				>
243.4457 +			</File>
243.4458 +			<File
243.4459 +				RelativePath=".\CPP\7zip\Archive\StdAfx.h"
243.4460 +				>
243.4461 +			</File>
243.4462 +			<File
243.4463 +				RelativePath=".\CPP\7zip\Compress\StdAfx.h"
243.4464 +				>
243.4465 +			</File>
243.4466 +			<File
243.4467 +				RelativePath=".\CPP\7zip\Bundles\Format7zF\StdAfx.h"
243.4468 +				>
243.4469 +			</File>
243.4470 +			<File
243.4471 +				RelativePath=".\CPP\7zip\Archive\GZip\StdAfx.h"
243.4472 +				>
243.4473 +			</File>
243.4474 +			<File
243.4475 +				RelativePath=".\CPP\7zip\Crypto\StdAfx.h"
243.4476 +				>
243.4477 +			</File>
243.4478 +			<File
243.4479 +				RelativePath=".\CPP\7zip\Archive\Tar\StdAfx.h"
243.4480 +				>
243.4481 +			</File>
243.4482 +			<File
243.4483 +				RelativePath=".\CPP\7zip\Archive\Zip\StdAfx.h"
243.4484 +				>
243.4485 +			</File>
243.4486 +			<File
243.4487 +				RelativePath=".\CPP\7zip\Archive\Lzh\StdAfx.h"
243.4488 +				>
243.4489 +			</File>
243.4490 +			<File
243.4491 +				RelativePath=".\CPP\7zip\Common\StdAfx.h"
243.4492 +				>
243.4493 +			</File>
243.4494 +			<File
243.4495 +				RelativePath=".\CPP\7zip\Archive\Split\StdAfx.h"
243.4496 +				>
243.4497 +			</File>
243.4498 +			<File
243.4499 +				RelativePath=".\CPP\7zip\Archive\Lzma\StdAfx.h"
243.4500 +				>
243.4501 +			</File>
243.4502 +			<File
243.4503 +				RelativePath=".\CPP\7zip\Common\StreamBinder.h"
243.4504 +				>
243.4505 +			</File>
243.4506 +			<File
243.4507 +				RelativePath=".\CPP\7zip\Common\StreamObjects.h"
243.4508 +				>
243.4509 +			</File>
243.4510 +			<File
243.4511 +				RelativePath=".\CPP\7zip\Common\StreamUtils.h"
243.4512 +				>
243.4513 +			</File>
243.4514 +			<File
243.4515 +				RelativePath=".\CPP\Common\StringConvert.h"
243.4516 +				>
243.4517 +			</File>
243.4518 +			<File
243.4519 +				RelativePath=".\CPP\Common\StringToInt.h"
243.4520 +				>
243.4521 +			</File>
243.4522 +			<File
243.4523 +				RelativePath=".\CPP\Windows\Synchronization.h"
243.4524 +				>
243.4525 +			</File>
243.4526 +			<File
243.4527 +				RelativePath=".\CPP\7zip\Archive\Tar\TarHandler.h"
243.4528 +				>
243.4529 +			</File>
243.4530 +			<File
243.4531 +				RelativePath=".\CPP\7zip\Archive\Tar\TarHeader.h"
243.4532 +				>
243.4533 +			</File>
243.4534 +			<File
243.4535 +				RelativePath=".\CPP\7zip\Archive\Tar\TarIn.h"
243.4536 +				>
243.4537 +			</File>
243.4538 +			<File
243.4539 +				RelativePath=".\CPP\7zip\Archive\Tar\TarItem.h"
243.4540 +				>
243.4541 +			</File>
243.4542 +			<File
243.4543 +				RelativePath=".\CPP\Windows\Thread.h"
243.4544 +				>
243.4545 +			</File>
243.4546 +			<File
243.4547 +				RelativePath=".\C\Threads.h"
243.4548 +				>
243.4549 +			</File>
243.4550 +			<File
243.4551 +				RelativePath=".\CPP\Windows\Time.h"
243.4552 +				>
243.4553 +			</File>
243.4554 +			<File
243.4555 +				RelativePath=".\CPP\Common\Types.h"
243.4556 +				>
243.4557 +			</File>
243.4558 +			<File
243.4559 +				RelativePath=".\C\Types.h"
243.4560 +				>
243.4561 +			</File>
243.4562 +			<File
243.4563 +				RelativePath=".\CPP\Common\UTFConvert.h"
243.4564 +				>
243.4565 +			</File>
243.4566 +			<File
243.4567 +				RelativePath=".\CPP\7zip\Common\VirtThread.h"
243.4568 +				>
243.4569 +			</File>
243.4570 +			<File
243.4571 +				RelativePath=".\CPP\Common\Wildcard.h"
243.4572 +				>
243.4573 +			</File>
243.4574 +			<File
243.4575 +				RelativePath=".\CPP\7zip\Crypto\WzAes.h"
243.4576 +				>
243.4577 +			</File>
243.4578 +			<File
243.4579 +				RelativePath=".\CPP\7zip\Archive\Zip\ZipCompressionMode.h"
243.4580 +				>
243.4581 +			</File>
243.4582 +			<File
243.4583 +				RelativePath=".\CPP\7zip\Crypto\ZipCrypto.h"
243.4584 +				>
243.4585 +			</File>
243.4586 +			<File
243.4587 +				RelativePath=".\CPP\7zip\Archive\Zip\ZipHandler.h"
243.4588 +				>
243.4589 +			</File>
243.4590 +			<File
243.4591 +				RelativePath=".\CPP\7zip\Archive\Zip\ZipHeader.h"
243.4592 +				>
243.4593 +			</File>
243.4594 +			<File
243.4595 +				RelativePath=".\CPP\7zip\Archive\Zip\ZipIn.h"
243.4596 +				>
243.4597 +			</File>
243.4598 +			<File
243.4599 +				RelativePath=".\CPP\7zip\Archive\Zip\ZipItem.h"
243.4600 +				>
243.4601 +			</File>
243.4602 +			<File
243.4603 +				RelativePath=".\CPP\7zip\Archive\Zip\ZipItemEx.h"
243.4604 +				>
243.4605 +			</File>
243.4606 +			<File
243.4607 +				RelativePath=".\CPP\7zip\Crypto\ZipStrong.h"
243.4608 +				>
243.4609 +			</File>
243.4610 +			<File
243.4611 +				RelativePath=".\CPP\7zip\Compress\ZlibDecoder.h"
243.4612 +				>
243.4613 +			</File>
243.4614 +		</Filter>
243.4615 +		<Filter
243.4616 +			Name="Register"
243.4617 +			>
243.4618 +			<File
243.4619 +				RelativePath=".\CPP\7zip\Crypto\7zAesRegister.cpp"
243.4620 +				>
243.4621 +				<FileConfiguration
243.4622 +					Name="Release|Win32"
243.4623 +					>
243.4624 +					<Tool
243.4625 +						Name="VCCLCompilerTool"
243.4626 +						UsePrecompiledHeader="2"
243.4627 +					/>
243.4628 +				</FileConfiguration>
243.4629 +				<FileConfiguration
243.4630 +					Name="Debug|Win32"
243.4631 +					>
243.4632 +					<Tool
243.4633 +						Name="VCCLCompilerTool"
243.4634 +						UsePrecompiledHeader="2"
243.4635 +					/>
243.4636 +				</FileConfiguration>
243.4637 +				<FileConfiguration
243.4638 +					Name="Release FastBuild|Win32"
243.4639 +					>
243.4640 +					<Tool
243.4641 +						Name="VCCLCompilerTool"
243.4642 +						UsePrecompiledHeader="2"
243.4643 +					/>
243.4644 +				</FileConfiguration>
243.4645 +			</File>
243.4646 +			<File
243.4647 +				RelativePath=".\CPP\7zip\Archive\7z\7zRegister.cpp"
243.4648 +				>
243.4649 +				<FileConfiguration
243.4650 +					Name="Release|Win32"
243.4651 +					>
243.4652 +					<Tool
243.4653 +						Name="VCCLCompilerTool"
243.4654 +						UsePrecompiledHeader="2"
243.4655 +					/>
243.4656 +				</FileConfiguration>
243.4657 +				<FileConfiguration
243.4658 +					Name="Debug|Win32"
243.4659 +					>
243.4660 +					<Tool
243.4661 +						Name="VCCLCompilerTool"
243.4662 +						UsePrecompiledHeader="2"
243.4663 +					/>
243.4664 +				</FileConfiguration>
243.4665 +				<FileConfiguration
243.4666 +					Name="Release FastBuild|Win32"
243.4667 +					>
243.4668 +					<Tool
243.4669 +						Name="VCCLCompilerTool"
243.4670 +						UsePrecompiledHeader="2"
243.4671 +					/>
243.4672 +				</FileConfiguration>
243.4673 +			</File>
243.4674 +			<File
243.4675 +				RelativePath=".\CPP\7zip\Archive\ArchiveExports.cpp"
243.4676 +				>
243.4677 +				<FileConfiguration
243.4678 +					Name="Release|Win32"
243.4679 +					>
243.4680 +					<Tool
243.4681 +						Name="VCCLCompilerTool"
243.4682 +						UsePrecompiledHeader="1"
243.4683 +					/>
243.4684 +				</FileConfiguration>
243.4685 +				<FileConfiguration
243.4686 +					Name="Debug|Win32"
243.4687 +					>
243.4688 +					<Tool
243.4689 +						Name="VCCLCompilerTool"
243.4690 +						UsePrecompiledHeader="1"
243.4691 +					/>
243.4692 +				</FileConfiguration>
243.4693 +				<FileConfiguration
243.4694 +					Name="Release FastBuild|Win32"
243.4695 +					>
243.4696 +					<Tool
243.4697 +						Name="VCCLCompilerTool"
243.4698 +						UsePrecompiledHeader="1"
243.4699 +					/>
243.4700 +				</FileConfiguration>
243.4701 +			</File>
243.4702 +			<File
243.4703 +				RelativePath=".\CPP\7zip\Compress\Bcj2Register.cpp"
243.4704 +				>
243.4705 +				<FileConfiguration
243.4706 +					Name="Release|Win32"
243.4707 +					>
243.4708 +					<Tool
243.4709 +						Name="VCCLCompilerTool"
243.4710 +						UsePrecompiledHeader="2"
243.4711 +					/>
243.4712 +				</FileConfiguration>
243.4713 +				<FileConfiguration
243.4714 +					Name="Debug|Win32"
243.4715 +					>
243.4716 +					<Tool
243.4717 +						Name="VCCLCompilerTool"
243.4718 +						UsePrecompiledHeader="2"
243.4719 +					/>
243.4720 +				</FileConfiguration>
243.4721 +				<FileConfiguration
243.4722 +					Name="Release FastBuild|Win32"
243.4723 +					>
243.4724 +					<Tool
243.4725 +						Name="VCCLCompilerTool"
243.4726 +						UsePrecompiledHeader="2"
243.4727 +					/>
243.4728 +				</FileConfiguration>
243.4729 +			</File>
243.4730 +			<File
243.4731 +				RelativePath=".\CPP\7zip\Compress\BcjRegister.cpp"
243.4732 +				>
243.4733 +				<FileConfiguration
243.4734 +					Name="Release|Win32"
243.4735 +					>
243.4736 +					<Tool
243.4737 +						Name="VCCLCompilerTool"
243.4738 +						UsePrecompiledHeader="2"
243.4739 +					/>
243.4740 +				</FileConfiguration>
243.4741 +				<FileConfiguration
243.4742 +					Name="Debug|Win32"
243.4743 +					>
243.4744 +					<Tool
243.4745 +						Name="VCCLCompilerTool"
243.4746 +						UsePrecompiledHeader="2"
243.4747 +					/>
243.4748 +				</FileConfiguration>
243.4749 +				<FileConfiguration
243.4750 +					Name="Release FastBuild|Win32"
243.4751 +					>
243.4752 +					<Tool
243.4753 +						Name="VCCLCompilerTool"
243.4754 +						UsePrecompiledHeader="2"
243.4755 +					/>
243.4756 +				</FileConfiguration>
243.4757 +			</File>
243.4758 +			<File
243.4759 +				RelativePath=".\CPP\7zip\Compress\BranchRegister.cpp"
243.4760 +				>
243.4761 +				<FileConfiguration
243.4762 +					Name="Release|Win32"
243.4763 +					>
243.4764 +					<Tool
243.4765 +						Name="VCCLCompilerTool"
243.4766 +						UsePrecompiledHeader="2"
243.4767 +					/>
243.4768 +				</FileConfiguration>
243.4769 +				<FileConfiguration
243.4770 +					Name="Debug|Win32"
243.4771 +					>
243.4772 +					<Tool
243.4773 +						Name="VCCLCompilerTool"
243.4774 +						UsePrecompiledHeader="2"
243.4775 +					/>
243.4776 +				</FileConfiguration>
243.4777 +				<FileConfiguration
243.4778 +					Name="Release FastBuild|Win32"
243.4779 +					>
243.4780 +					<Tool
243.4781 +						Name="VCCLCompilerTool"
243.4782 +						UsePrecompiledHeader="2"
243.4783 +					/>
243.4784 +				</FileConfiguration>
243.4785 +			</File>
243.4786 +			<File
243.4787 +				RelativePath=".\CPP\7zip\Compress\ByteSwapRegister.cpp"
243.4788 +				>
243.4789 +				<FileConfiguration
243.4790 +					Name="Release|Win32"
243.4791 +					>
243.4792 +					<Tool
243.4793 +						Name="VCCLCompilerTool"
243.4794 +						UsePrecompiledHeader="2"
243.4795 +					/>
243.4796 +				</FileConfiguration>
243.4797 +				<FileConfiguration
243.4798 +					Name="Debug|Win32"
243.4799 +					>
243.4800 +					<Tool
243.4801 +						Name="VCCLCompilerTool"
243.4802 +						UsePrecompiledHeader="2"
243.4803 +					/>
243.4804 +				</FileConfiguration>
243.4805 +				<FileConfiguration
243.4806 +					Name="Release FastBuild|Win32"
243.4807 +					>
243.4808 +					<Tool
243.4809 +						Name="VCCLCompilerTool"
243.4810 +						UsePrecompiledHeader="2"
243.4811 +					/>
243.4812 +				</FileConfiguration>
243.4813 +			</File>
243.4814 +			<File
243.4815 +				RelativePath=".\CPP\7zip\Archive\BZip2\bz2Register.cpp"
243.4816 +				>
243.4817 +				<FileConfiguration
243.4818 +					Name="Release|Win32"
243.4819 +					>
243.4820 +					<Tool
243.4821 +						Name="VCCLCompilerTool"
243.4822 +						UsePrecompiledHeader="2"
243.4823 +					/>
243.4824 +				</FileConfiguration>
243.4825 +				<FileConfiguration
243.4826 +					Name="Debug|Win32"
243.4827 +					>
243.4828 +					<Tool
243.4829 +						Name="VCCLCompilerTool"
243.4830 +						UsePrecompiledHeader="2"
243.4831 +					/>
243.4832 +				</FileConfiguration>
243.4833 +				<FileConfiguration
243.4834 +					Name="Release FastBuild|Win32"
243.4835 +					>
243.4836 +					<Tool
243.4837 +						Name="VCCLCompilerTool"
243.4838 +						UsePrecompiledHeader="2"
243.4839 +					/>
243.4840 +				</FileConfiguration>
243.4841 +			</File>
243.4842 +			<File
243.4843 +				RelativePath=".\CPP\7zip\Compress\BZip2Register.cpp"
243.4844 +				>
243.4845 +				<FileConfiguration
243.4846 +					Name="Release|Win32"
243.4847 +					>
243.4848 +					<Tool
243.4849 +						Name="VCCLCompilerTool"
243.4850 +						UsePrecompiledHeader="2"
243.4851 +					/>
243.4852 +				</FileConfiguration>
243.4853 +				<FileConfiguration
243.4854 +					Name="Debug|Win32"
243.4855 +					>
243.4856 +					<Tool
243.4857 +						Name="VCCLCompilerTool"
243.4858 +						UsePrecompiledHeader="2"
243.4859 +					/>
243.4860 +				</FileConfiguration>
243.4861 +				<FileConfiguration
243.4862 +					Name="Release FastBuild|Win32"
243.4863 +					>
243.4864 +					<Tool
243.4865 +						Name="VCCLCompilerTool"
243.4866 +						UsePrecompiledHeader="2"
243.4867 +					/>
243.4868 +				</FileConfiguration>
243.4869 +			</File>
243.4870 +			<File
243.4871 +				RelativePath=".\CPP\7zip\Compress\CodecExports.cpp"
243.4872 +				>
243.4873 +				<FileConfiguration
243.4874 +					Name="Release|Win32"
243.4875 +					>
243.4876 +					<Tool
243.4877 +						Name="VCCLCompilerTool"
243.4878 +						UsePrecompiledHeader="2"
243.4879 +					/>
243.4880 +				</FileConfiguration>
243.4881 +				<FileConfiguration
243.4882 +					Name="Debug|Win32"
243.4883 +					>
243.4884 +					<Tool
243.4885 +						Name="VCCLCompilerTool"
243.4886 +						UsePrecompiledHeader="2"
243.4887 +					/>
243.4888 +				</FileConfiguration>
243.4889 +				<FileConfiguration
243.4890 +					Name="Release FastBuild|Win32"
243.4891 +					>
243.4892 +					<Tool
243.4893 +						Name="VCCLCompilerTool"
243.4894 +						UsePrecompiledHeader="2"
243.4895 +					/>
243.4896 +				</FileConfiguration>
243.4897 +			</File>
243.4898 +			<File
243.4899 +				RelativePath=".\CPP\7zip\Compress\CopyRegister.cpp"
243.4900 +				>
243.4901 +				<FileConfiguration
243.4902 +					Name="Release|Win32"
243.4903 +					>
243.4904 +					<Tool
243.4905 +						Name="VCCLCompilerTool"
243.4906 +						UsePrecompiledHeader="2"
243.4907 +					/>
243.4908 +				</FileConfiguration>
243.4909 +				<FileConfiguration
243.4910 +					Name="Debug|Win32"
243.4911 +					>
243.4912 +					<Tool
243.4913 +						Name="VCCLCompilerTool"
243.4914 +						UsePrecompiledHeader="2"
243.4915 +					/>
243.4916 +				</FileConfiguration>
243.4917 +				<FileConfiguration
243.4918 +					Name="Release FastBuild|Win32"
243.4919 +					>
243.4920 +					<Tool
243.4921 +						Name="VCCLCompilerTool"
243.4922 +						UsePrecompiledHeader="2"
243.4923 +					/>
243.4924 +				</FileConfiguration>
243.4925 +			</File>
243.4926 +			<File
243.4927 +				RelativePath=".\CPP\7zip\Common\CreateCoder.cpp"
243.4928 +				>
243.4929 +				<FileConfiguration
243.4930 +					Name="Release|Win32"
243.4931 +					>
243.4932 +					<Tool
243.4933 +						Name="VCCLCompilerTool"
243.4934 +						UsePrecompiledHeader="2"
243.4935 +					/>
243.4936 +				</FileConfiguration>
243.4937 +				<FileConfiguration
243.4938 +					Name="Debug|Win32"
243.4939 +					>
243.4940 +					<Tool
243.4941 +						Name="VCCLCompilerTool"
243.4942 +						UsePrecompiledHeader="2"
243.4943 +					/>
243.4944 +				</FileConfiguration>
243.4945 +				<FileConfiguration
243.4946 +					Name="Release FastBuild|Win32"
243.4947 +					>
243.4948 +					<Tool
243.4949 +						Name="VCCLCompilerTool"
243.4950 +						UsePrecompiledHeader="2"
243.4951 +					/>
243.4952 +				</FileConfiguration>
243.4953 +			</File>
243.4954 +			<File
243.4955 +				RelativePath=".\CPP\7zip\Compress\Deflate64Register.cpp"
243.4956 +				>
243.4957 +				<FileConfiguration
243.4958 +					Name="Release|Win32"
243.4959 +					>
243.4960 +					<Tool
243.4961 +						Name="VCCLCompilerTool"
243.4962 +						UsePrecompiledHeader="2"
243.4963 +					/>
243.4964 +				</FileConfiguration>
243.4965 +				<FileConfiguration
243.4966 +					Name="Debug|Win32"
243.4967 +					>
243.4968 +					<Tool
243.4969 +						Name="VCCLCompilerTool"
243.4970 +						UsePrecompiledHeader="2"
243.4971 +					/>
243.4972 +				</FileConfiguration>
243.4973 +				<FileConfiguration
243.4974 +					Name="Release FastBuild|Win32"
243.4975 +					>
243.4976 +					<Tool
243.4977 +						Name="VCCLCompilerTool"
243.4978 +						UsePrecompiledHeader="2"
243.4979 +					/>
243.4980 +				</FileConfiguration>
243.4981 +			</File>
243.4982 +			<File
243.4983 +				RelativePath=".\CPP\7zip\Compress\DeflateNsisRegister.cpp"
243.4984 +				>
243.4985 +				<FileConfiguration
243.4986 +					Name="Release|Win32"
243.4987 +					>
243.4988 +					<Tool
243.4989 +						Name="VCCLCompilerTool"
243.4990 +						UsePrecompiledHeader="2"
243.4991 +					/>
243.4992 +				</FileConfiguration>
243.4993 +				<FileConfiguration
243.4994 +					Name="Debug|Win32"
243.4995 +					>
243.4996 +					<Tool
243.4997 +						Name="VCCLCompilerTool"
243.4998 +						UsePrecompiledHeader="2"
243.4999 +					/>
243.5000 +				</FileConfiguration>
243.5001 +				<FileConfiguration
243.5002 +					Name="Release FastBuild|Win32"
243.5003 +					>
243.5004 +					<Tool
243.5005 +						Name="VCCLCompilerTool"
243.5006 +						UsePrecompiledHeader="2"
243.5007 +					/>
243.5008 +				</FileConfiguration>
243.5009 +			</File>
243.5010 +			<File
243.5011 +				RelativePath=".\CPP\7zip\Compress\DeflateRegister.cpp"
243.5012 +				>
243.5013 +				<FileConfiguration
243.5014 +					Name="Release|Win32"
243.5015 +					>
243.5016 +					<Tool
243.5017 +						Name="VCCLCompilerTool"
243.5018 +						UsePrecompiledHeader="2"
243.5019 +					/>
243.5020 +				</FileConfiguration>
243.5021 +				<FileConfiguration
243.5022 +					Name="Debug|Win32"
243.5023 +					>
243.5024 +					<Tool
243.5025 +						Name="VCCLCompilerTool"
243.5026 +						UsePrecompiledHeader="2"
243.5027 +					/>
243.5028 +				</FileConfiguration>
243.5029 +				<FileConfiguration
243.5030 +					Name="Release FastBuild|Win32"
243.5031 +					>
243.5032 +					<Tool
243.5033 +						Name="VCCLCompilerTool"
243.5034 +						UsePrecompiledHeader="2"
243.5035 +					/>
243.5036 +				</FileConfiguration>
243.5037 +			</File>
243.5038 +			<File
243.5039 +				RelativePath=".\CPP\7zip\Archive\DllExports2.cpp"
243.5040 +				>
243.5041 +				<FileConfiguration
243.5042 +					Name="Release|Win32"
243.5043 +					>
243.5044 +					<Tool
243.5045 +						Name="VCCLCompilerTool"
243.5046 +						UsePrecompiledHeader="2"
243.5047 +					/>
243.5048 +				</FileConfiguration>
243.5049 +				<FileConfiguration
243.5050 +					Name="Debug|Win32"
243.5051 +					>
243.5052 +					<Tool
243.5053 +						Name="VCCLCompilerTool"
243.5054 +						UsePrecompiledHeader="2"
243.5055 +					/>
243.5056 +				</FileConfiguration>
243.5057 +				<FileConfiguration
243.5058 +					Name="Release FastBuild|Win32"
243.5059 +					>
243.5060 +					<Tool
243.5061 +						Name="VCCLCompilerTool"
243.5062 +						UsePrecompiledHeader="2"
243.5063 +					/>
243.5064 +				</FileConfiguration>
243.5065 +			</File>
243.5066 +			<File
243.5067 +				RelativePath=".\CPP\7zip\Archive\GZip\GZipRegister.cpp"
243.5068 +				>
243.5069 +				<FileConfiguration
243.5070 +					Name="Release|Win32"
243.5071 +					>
243.5072 +					<Tool
243.5073 +						Name="VCCLCompilerTool"
243.5074 +						UsePrecompiledHeader="2"
243.5075 +					/>
243.5076 +				</FileConfiguration>
243.5077 +				<FileConfiguration
243.5078 +					Name="Debug|Win32"
243.5079 +					>
243.5080 +					<Tool
243.5081 +						Name="VCCLCompilerTool"
243.5082 +						UsePrecompiledHeader="2"
243.5083 +					/>
243.5084 +				</FileConfiguration>
243.5085 +				<FileConfiguration
243.5086 +					Name="Release FastBuild|Win32"
243.5087 +					>
243.5088 +					<Tool
243.5089 +						Name="VCCLCompilerTool"
243.5090 +						UsePrecompiledHeader="2"
243.5091 +					/>
243.5092 +				</FileConfiguration>
243.5093 +			</File>
243.5094 +			<File
243.5095 +				RelativePath=".\CPP\7zip\Archive\Lzh\LzhRegister.cpp"
243.5096 +				>
243.5097 +				<FileConfiguration
243.5098 +					Name="Release|Win32"
243.5099 +					>
243.5100 +					<Tool
243.5101 +						Name="VCCLCompilerTool"
243.5102 +						UsePrecompiledHeader="2"
243.5103 +					/>
243.5104 +				</FileConfiguration>
243.5105 +				<FileConfiguration
243.5106 +					Name="Debug|Win32"
243.5107 +					>
243.5108 +					<Tool
243.5109 +						Name="VCCLCompilerTool"
243.5110 +						UsePrecompiledHeader="2"
243.5111 +					/>
243.5112 +				</FileConfiguration>
243.5113 +				<FileConfiguration
243.5114 +					Name="Release FastBuild|Win32"
243.5115 +					>
243.5116 +					<Tool
243.5117 +						Name="VCCLCompilerTool"
243.5118 +						UsePrecompiledHeader="2"
243.5119 +					/>
243.5120 +				</FileConfiguration>
243.5121 +			</File>
243.5122 +			<File
243.5123 +				RelativePath=".\CPP\7zip\Archive\Lzma\LzmaArcRegister.cpp"
243.5124 +				>
243.5125 +				<FileConfiguration
243.5126 +					Name="Release|Win32"
243.5127 +					>
243.5128 +					<Tool
243.5129 +						Name="VCCLCompilerTool"
243.5130 +						UsePrecompiledHeader="2"
243.5131 +					/>
243.5132 +				</FileConfiguration>
243.5133 +				<FileConfiguration
243.5134 +					Name="Debug|Win32"
243.5135 +					>
243.5136 +					<Tool
243.5137 +						Name="VCCLCompilerTool"
243.5138 +						UsePrecompiledHeader="2"
243.5139 +					/>
243.5140 +				</FileConfiguration>
243.5141 +				<FileConfiguration
243.5142 +					Name="Release FastBuild|Win32"
243.5143 +					>
243.5144 +					<Tool
243.5145 +						Name="VCCLCompilerTool"
243.5146 +						UsePrecompiledHeader="2"
243.5147 +					/>
243.5148 +				</FileConfiguration>
243.5149 +			</File>
243.5150 +			<File
243.5151 +				RelativePath=".\CPP\7zip\Compress\LzmaRegister.cpp"
243.5152 +				>
243.5153 +				<FileConfiguration
243.5154 +					Name="Release|Win32"
243.5155 +					>
243.5156 +					<Tool
243.5157 +						Name="VCCLCompilerTool"
243.5158 +						UsePrecompiledHeader="2"
243.5159 +					/>
243.5160 +				</FileConfiguration>
243.5161 +				<FileConfiguration
243.5162 +					Name="Debug|Win32"
243.5163 +					>
243.5164 +					<Tool
243.5165 +						Name="VCCLCompilerTool"
243.5166 +						UsePrecompiledHeader="2"
243.5167 +					/>
243.5168 +				</FileConfiguration>
243.5169 +				<FileConfiguration
243.5170 +					Name="Release FastBuild|Win32"
243.5171 +					>
243.5172 +					<Tool
243.5173 +						Name="VCCLCompilerTool"
243.5174 +						UsePrecompiledHeader="2"
243.5175 +					/>
243.5176 +				</FileConfiguration>
243.5177 +			</File>
243.5178 +			<File
243.5179 +				RelativePath=".\CPP\7zip\Compress\PpmdRegister.cpp"
243.5180 +				>
243.5181 +				<FileConfiguration
243.5182 +					Name="Release|Win32"
243.5183 +					>
243.5184 +					<Tool
243.5185 +						Name="VCCLCompilerTool"
243.5186 +						UsePrecompiledHeader="2"
243.5187 +					/>
243.5188 +				</FileConfiguration>
243.5189 +				<FileConfiguration
243.5190 +					Name="Debug|Win32"
243.5191 +					>
243.5192 +					<Tool
243.5193 +						Name="VCCLCompilerTool"
243.5194 +						UsePrecompiledHeader="2"
243.5195 +					/>
243.5196 +				</FileConfiguration>
243.5197 +				<FileConfiguration
243.5198 +					Name="Release FastBuild|Win32"
243.5199 +					>
243.5200 +					<Tool
243.5201 +						Name="VCCLCompilerTool"
243.5202 +						UsePrecompiledHeader="2"
243.5203 +					/>
243.5204 +				</FileConfiguration>
243.5205 +			</File>
243.5206 +			<File
243.5207 +				RelativePath=".\CPP\7zip\Compress\RarCodecsRegister.cpp"
243.5208 +				>
243.5209 +				<FileConfiguration
243.5210 +					Name="Release|Win32"
243.5211 +					>
243.5212 +					<Tool
243.5213 +						Name="VCCLCompilerTool"
243.5214 +						UsePrecompiledHeader="2"
243.5215 +					/>
243.5216 +				</FileConfiguration>
243.5217 +				<FileConfiguration
243.5218 +					Name="Debug|Win32"
243.5219 +					>
243.5220 +					<Tool
243.5221 +						Name="VCCLCompilerTool"
243.5222 +						UsePrecompiledHeader="2"
243.5223 +					/>
243.5224 +				</FileConfiguration>
243.5225 +				<FileConfiguration
243.5226 +					Name="Release FastBuild|Win32"
243.5227 +					>
243.5228 +					<Tool
243.5229 +						Name="VCCLCompilerTool"
243.5230 +						UsePrecompiledHeader="2"
243.5231 +					/>
243.5232 +				</FileConfiguration>
243.5233 +			</File>
243.5234 +			<File
243.5235 +				RelativePath=".\CPP\7zip\Archive\Rar\RarRegister.cpp"
243.5236 +				>
243.5237 +				<FileConfiguration
243.5238 +					Name="Release|Win32"
243.5239 +					>
243.5240 +					<Tool
243.5241 +						Name="VCCLCompilerTool"
243.5242 +						UsePrecompiledHeader="2"
243.5243 +					/>
243.5244 +				</FileConfiguration>
243.5245 +				<FileConfiguration
243.5246 +					Name="Debug|Win32"
243.5247 +					>
243.5248 +					<Tool
243.5249 +						Name="VCCLCompilerTool"
243.5250 +						UsePrecompiledHeader="2"
243.5251 +					/>
243.5252 +				</FileConfiguration>
243.5253 +				<FileConfiguration
243.5254 +					Name="Release FastBuild|Win32"
243.5255 +					>
243.5256 +					<Tool
243.5257 +						Name="VCCLCompilerTool"
243.5258 +						UsePrecompiledHeader="2"
243.5259 +					/>
243.5260 +				</FileConfiguration>
243.5261 +			</File>
243.5262 +			<File
243.5263 +				RelativePath=".\CPP\7zip\Archive\Split\SplitRegister.cpp"
243.5264 +				>
243.5265 +				<FileConfiguration
243.5266 +					Name="Release|Win32"
243.5267 +					>
243.5268 +					<Tool
243.5269 +						Name="VCCLCompilerTool"
243.5270 +						UsePrecompiledHeader="2"
243.5271 +					/>
243.5272 +				</FileConfiguration>
243.5273 +				<FileConfiguration
243.5274 +					Name="Debug|Win32"
243.5275 +					>
243.5276 +					<Tool
243.5277 +						Name="VCCLCompilerTool"
243.5278 +						UsePrecompiledHeader="2"
243.5279 +					/>
243.5280 +				</FileConfiguration>
243.5281 +				<FileConfiguration
243.5282 +					Name="Release FastBuild|Win32"
243.5283 +					>
243.5284 +					<Tool
243.5285 +						Name="VCCLCompilerTool"
243.5286 +						UsePrecompiledHeader="2"
243.5287 +					/>
243.5288 +				</FileConfiguration>
243.5289 +			</File>
243.5290 +			<File
243.5291 +				RelativePath=".\CPP\7zip\Archive\Tar\TarRegister.cpp"
243.5292 +				>
243.5293 +				<FileConfiguration
243.5294 +					Name="Release|Win32"
243.5295 +					>
243.5296 +					<Tool
243.5297 +						Name="VCCLCompilerTool"
243.5298 +						UsePrecompiledHeader="2"
243.5299 +					/>
243.5300 +				</FileConfiguration>
243.5301 +				<FileConfiguration
243.5302 +					Name="Debug|Win32"
243.5303 +					>
243.5304 +					<Tool
243.5305 +						Name="VCCLCompilerTool"
243.5306 +						UsePrecompiledHeader="2"
243.5307 +					/>
243.5308 +				</FileConfiguration>
243.5309 +				<FileConfiguration
243.5310 +					Name="Release FastBuild|Win32"
243.5311 +					>
243.5312 +					<Tool
243.5313 +						Name="VCCLCompilerTool"
243.5314 +						UsePrecompiledHeader="2"
243.5315 +					/>
243.5316 +				</FileConfiguration>
243.5317 +			</File>
243.5318 +			<File
243.5319 +				RelativePath=".\CPP\7zip\Archive\Zip\ZipRegister.cpp"
243.5320 +				>
243.5321 +				<FileConfiguration
243.5322 +					Name="Release|Win32"
243.5323 +					>
243.5324 +					<Tool
243.5325 +						Name="VCCLCompilerTool"
243.5326 +						UsePrecompiledHeader="2"
243.5327 +					/>
243.5328 +				</FileConfiguration>
243.5329 +				<FileConfiguration
243.5330 +					Name="Debug|Win32"
243.5331 +					>
243.5332 +					<Tool
243.5333 +						Name="VCCLCompilerTool"
243.5334 +						UsePrecompiledHeader="2"
243.5335 +					/>
243.5336 +				</FileConfiguration>
243.5337 +				<FileConfiguration
243.5338 +					Name="Release FastBuild|Win32"
243.5339 +					>
243.5340 +					<Tool
243.5341 +						Name="VCCLCompilerTool"
243.5342 +						UsePrecompiledHeader="2"
243.5343 +					/>
243.5344 +				</FileConfiguration>
243.5345 +			</File>
243.5346 +		</Filter>
243.5347 +	</Files>
243.5348 +	<Globals>
243.5349 +	</Globals>
243.5350 +</VisualStudioProject>
   244.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   244.2 +++ b/src/win32/7zip/7z/7zip_2010.vcxproj	Sat Mar 03 10:31:27 2012 -0600
   244.3 @@ -0,0 +1,1193 @@
   244.4 +<?xml version="1.0" encoding="utf-8"?>
   244.5 +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   244.6 +  <ItemGroup Label="ProjectConfigurations">
   244.7 +    <ProjectConfiguration Include="Debug|Win32">
   244.8 +      <Configuration>Debug</Configuration>
   244.9 +      <Platform>Win32</Platform>
  244.10 +    </ProjectConfiguration>
  244.11 +    <ProjectConfiguration Include="Release FastBuild|Win32">
  244.12 +      <Configuration>Release FastBuild</Configuration>
  244.13 +      <Platform>Win32</Platform>
  244.14 +    </ProjectConfiguration>
  244.15 +    <ProjectConfiguration Include="Release|Win32">
  244.16 +      <Configuration>Release</Configuration>
  244.17 +      <Platform>Win32</Platform>
  244.18 +    </ProjectConfiguration>
  244.19 +  </ItemGroup>
  244.20 +  <PropertyGroup Label="Globals">
  244.21 +    <ProjectName>wlib7zip</ProjectName>
  244.22 +    <ProjectGuid>{5646C572-A578-49F8-9DA9-3E00A8CBFE3F}</ProjectGuid>
  244.23 +    <RootNamespace>gens</RootNamespace>
  244.24 +  </PropertyGroup>
  244.25 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  244.26 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'" Label="Configuration">
  244.27 +    <ConfigurationType>StaticLibrary</ConfigurationType>
  244.28 +    <UseOfMfc>false</UseOfMfc>
  244.29 +    <WholeProgramOptimization>false</WholeProgramOptimization>
  244.30 +    <CharacterSet>MultiByte</CharacterSet>
  244.31 +  </PropertyGroup>
  244.32 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
  244.33 +    <ConfigurationType>StaticLibrary</ConfigurationType>
  244.34 +    <UseOfMfc>false</UseOfMfc>
  244.35 +    <CharacterSet>MultiByte</CharacterSet>
  244.36 +  </PropertyGroup>
  244.37 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
  244.38 +    <ConfigurationType>StaticLibrary</ConfigurationType>
  244.39 +    <UseOfMfc>false</UseOfMfc>
  244.40 +    <WholeProgramOptimization>true</WholeProgramOptimization>
  244.41 +    <CharacterSet>MultiByte</CharacterSet>
  244.42 +  </PropertyGroup>
  244.43 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  244.44 +  <ImportGroup Label="ExtensionSettings">
  244.45 +    <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
  244.46 +  </ImportGroup>
  244.47 +  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'" Label="PropertySheets">
  244.48 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
  244.49 +  </ImportGroup>
  244.50 +  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
  244.51 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
  244.52 +  </ImportGroup>
  244.53 +  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
  244.54 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
  244.55 +  </ImportGroup>
  244.56 +  <PropertyGroup Label="UserMacros" />
  244.57 +  <PropertyGroup>
  244.58 +    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>
  244.59 +    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir).VS2010\$(Configuration)\$(Platform)\$(ProjectName)\</OutDir>
  244.60 +    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir).VS2010\$(Configuration)\$(Platform)\$(ProjectName)\</IntDir>
  244.61 +    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir).VS2010\$(Configuration)\$(Platform)\$(ProjectName)\</OutDir>
  244.62 +    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir).VS2010\$(Configuration)\$(Platform)\$(ProjectName)\</IntDir>
  244.63 +    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">$(SolutionDir).VS2010\$(Configuration)\$(Platform)\$(ProjectName)\</OutDir>
  244.64 +    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">$(SolutionDir).VS2010\$(Configuration)\$(Platform)\$(ProjectName)\</IntDir>
  244.65 +    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
  244.66 +    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
  244.67 +    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
  244.68 +    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
  244.69 +    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'" />
  244.70 +    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'" />
  244.71 +    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
  244.72 +    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
  244.73 +    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
  244.74 +  </PropertyGroup>
  244.75 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
  244.76 +    <Midl>
  244.77 +      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  244.78 +      <MkTypLibCompatible>true</MkTypLibCompatible>
  244.79 +      <SuppressStartupBanner>true</SuppressStartupBanner>
  244.80 +      <TargetEnvironment>Win32</TargetEnvironment>
  244.81 +      <TypeLibraryName>.\Release/gens.tlb</TypeLibraryName>
  244.82 +      <HeaderFileName>
  244.83 +      </HeaderFileName>
  244.84 +    </Midl>
  244.85 +    <ClCompile>
  244.86 +      <Optimization>Full</Optimization>
  244.87 +      <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
  244.88 +      <IntrinsicFunctions>false</IntrinsicFunctions>
  244.89 +      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
  244.90 +      <OmitFramePointers>true</OmitFramePointers>
  244.91 +      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
  244.92 +      <WholeProgramOptimization>true</WholeProgramOptimization>
  244.93 +      <AdditionalIncludeDirectories>CPP;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
  244.94 +      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;EXTRACT_ONLY;_NO_CRYPTO;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  244.95 +      <StringPooling>true</StringPooling>
  244.96 +      <ExceptionHandling>Sync</ExceptionHandling>
  244.97 +      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
  244.98 +      <PrecompiledHeader>Use</PrecompiledHeader>
  244.99 +      <PrecompiledHeaderOutputFile>$(IntDir)7z.pch</PrecompiledHeaderOutputFile>
 244.100 +      <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation>
 244.101 +      <ObjectFileName>$(IntDir)</ObjectFileName>
 244.102 +      <ProgramDataBaseFileName>$(IntDir)vc80.pdb</ProgramDataBaseFileName>
 244.103 +      <WarningLevel>Level3</WarningLevel>
 244.104 +      <SuppressStartupBanner>true</SuppressStartupBanner>
 244.105 +      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
 244.106 +      <OmitDefaultLibName>true</OmitDefaultLibName>
 244.107 +      <BufferSecurityCheck>false</BufferSecurityCheck>
 244.108 +      <EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
 244.109 +    </ClCompile>
 244.110 +    <ResourceCompile>
 244.111 +      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 244.112 +    </ResourceCompile>
 244.113 +    <Lib>
 244.114 +      <AdditionalOptions> /LTCG %(AdditionalOptions)</AdditionalOptions>
 244.115 +    </Lib>
 244.116 +  </ItemDefinitionGroup>
 244.117 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.118 +    <PreBuildEvent>
 244.119 +      <Command>
 244.120 +      </Command>
 244.121 +    </PreBuildEvent>
 244.122 +    <CustomBuildStep>
 244.123 +      <Command>
 244.124 +      </Command>
 244.125 +    </CustomBuildStep>
 244.126 +    <Midl>
 244.127 +      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 244.128 +      <MkTypLibCompatible>true</MkTypLibCompatible>
 244.129 +      <SuppressStartupBanner>true</SuppressStartupBanner>
 244.130 +      <TargetEnvironment>Win32</TargetEnvironment>
 244.131 +      <TypeLibraryName>.\Release/gens.tlb</TypeLibraryName>
 244.132 +      <HeaderFileName>
 244.133 +      </HeaderFileName>
 244.134 +    </Midl>
 244.135 +    <ClCompile>
 244.136 +      <Optimization>Disabled</Optimization>
 244.137 +      <InlineFunctionExpansion>Default</InlineFunctionExpansion>
 244.138 +      <IntrinsicFunctions>false</IntrinsicFunctions>
 244.139 +      <AdditionalIncludeDirectories>CPP;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
 244.140 +      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;EXTRACT_ONLY;_NO_CRYPTO;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 244.141 +      <StringPooling>false</StringPooling>
 244.142 +      <ExceptionHandling>Sync</ExceptionHandling>
 244.143 +      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
 244.144 +      <SmallerTypeCheck>true</SmallerTypeCheck>
 244.145 +      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
 244.146 +      <FunctionLevelLinking>false</FunctionLevelLinking>
 244.147 +      <PrecompiledHeader>Use</PrecompiledHeader>
 244.148 +      <PrecompiledHeaderOutputFile>$(IntDir)7z.pch</PrecompiledHeaderOutputFile>
 244.149 +      <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation>
 244.150 +      <ObjectFileName>$(IntDir)</ObjectFileName>
 244.151 +      <ProgramDataBaseFileName>$(IntDir)vc80.pdb</ProgramDataBaseFileName>
 244.152 +      <WarningLevel>Level3</WarningLevel>
 244.153 +      <SuppressStartupBanner>true</SuppressStartupBanner>
 244.154 +      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
 244.155 +      <OmitDefaultLibName>true</OmitDefaultLibName>
 244.156 +    </ClCompile>
 244.157 +    <ResourceCompile>
 244.158 +      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 244.159 +    </ResourceCompile>
 244.160 +  </ItemDefinitionGroup>
 244.161 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.162 +    <Midl>
 244.163 +      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 244.164 +      <MkTypLibCompatible>true</MkTypLibCompatible>
 244.165 +      <SuppressStartupBanner>true</SuppressStartupBanner>
 244.166 +      <TargetEnvironment>Win32</TargetEnvironment>
 244.167 +      <TypeLibraryName>.\Release/gens.tlb</TypeLibraryName>
 244.168 +      <HeaderFileName>
 244.169 +      </HeaderFileName>
 244.170 +    </Midl>
 244.171 +    <ClCompile>
 244.172 +      <Optimization>Full</Optimization>
 244.173 +      <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
 244.174 +      <IntrinsicFunctions>true</IntrinsicFunctions>
 244.175 +      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
 244.176 +      <OmitFramePointers>true</OmitFramePointers>
 244.177 +      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
 244.178 +      <WholeProgramOptimization>false</WholeProgramOptimization>
 244.179 +      <AdditionalIncludeDirectories>CPP;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
 244.180 +      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;EXTRACT_ONLY;_NO_CRYPTO;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 244.181 +      <StringPooling>true</StringPooling>
 244.182 +      <ExceptionHandling>Sync</ExceptionHandling>
 244.183 +      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
 244.184 +      <PrecompiledHeader>Use</PrecompiledHeader>
 244.185 +      <PrecompiledHeaderOutputFile>$(IntDir)7z.pch</PrecompiledHeaderOutputFile>
 244.186 +      <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation>
 244.187 +      <ObjectFileName>$(IntDir)</ObjectFileName>
 244.188 +      <ProgramDataBaseFileName>$(IntDir)vc80.pdb</ProgramDataBaseFileName>
 244.189 +      <WarningLevel>Level3</WarningLevel>
 244.190 +      <SuppressStartupBanner>true</SuppressStartupBanner>
 244.191 +      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
 244.192 +      <OmitDefaultLibName>true</OmitDefaultLibName>
 244.193 +    </ClCompile>
 244.194 +    <ResourceCompile>
 244.195 +      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 244.196 +    </ResourceCompile>
 244.197 +    <Lib>
 244.198 +      <AdditionalOptions> /LTCG %(AdditionalOptions)</AdditionalOptions>
 244.199 +    </Lib>
 244.200 +  </ItemDefinitionGroup>
 244.201 +  <ItemGroup>
 244.202 +    <ClCompile Include="CPP\7zip\Common\FilterCoder.cpp">
 244.203 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.204 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.205 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.206 +    </ClCompile>
 244.207 +    <ClCompile Include="CPP\7zip\Common\InBuffer.cpp">
 244.208 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.209 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.210 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.211 +    </ClCompile>
 244.212 +    <ClCompile Include="CPP\7zip\Common\InOutTempBuffer.cpp">
 244.213 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.214 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.215 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.216 +    </ClCompile>
 244.217 +    <ClCompile Include="CPP\7zip\Common\LimitedStreams.cpp">
 244.218 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.219 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.220 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.221 +    </ClCompile>
 244.222 +    <ClCompile Include="CPP\7zip\Common\LockedStream.cpp">
 244.223 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.224 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.225 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.226 +    </ClCompile>
 244.227 +    <ClCompile Include="CPP\7zip\Common\MemBlocks.cpp">
 244.228 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.229 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.230 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.231 +    </ClCompile>
 244.232 +    <ClCompile Include="CPP\7zip\Common\MethodId.cpp">
 244.233 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.234 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.235 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.236 +    </ClCompile>
 244.237 +    <ClCompile Include="CPP\7zip\Common\MethodProps.cpp">
 244.238 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.239 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.240 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.241 +    </ClCompile>
 244.242 +    <ClCompile Include="CPP\7zip\Common\OffsetStream.cpp">
 244.243 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.244 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.245 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.246 +    </ClCompile>
 244.247 +    <ClCompile Include="CPP\7zip\Common\OutBuffer.cpp">
 244.248 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.249 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.250 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.251 +    </ClCompile>
 244.252 +    <ClCompile Include="CPP\7zip\Common\OutMemStream.cpp">
 244.253 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.254 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.255 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.256 +    </ClCompile>
 244.257 +    <ClCompile Include="CPP\7zip\Common\ProgressMt.cpp">
 244.258 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.259 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.260 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.261 +    </ClCompile>
 244.262 +    <ClCompile Include="CPP\7zip\Common\ProgressUtils.cpp">
 244.263 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.264 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.265 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.266 +    </ClCompile>
 244.267 +    <ClCompile Include="CPP\7zip\Common\StreamBinder.cpp">
 244.268 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.269 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.270 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.271 +    </ClCompile>
 244.272 +    <ClCompile Include="CPP\7zip\Common\StreamObjects.cpp">
 244.273 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.274 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.275 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.276 +    </ClCompile>
 244.277 +    <ClCompile Include="CPP\7zip\Common\StreamUtils.cpp">
 244.278 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.279 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.280 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.281 +    </ClCompile>
 244.282 +    <ClCompile Include="CPP\7zip\Common\VirtThread.cpp">
 244.283 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.284 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.285 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.286 +    </ClCompile>
 244.287 +    <ClCompile Include="CPP\Windows\FileDir.cpp">
 244.288 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.289 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.290 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.291 +    </ClCompile>
 244.292 +    <ClCompile Include="CPP\Windows\FileFind.cpp">
 244.293 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.294 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.295 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.296 +    </ClCompile>
 244.297 +    <ClCompile Include="CPP\Windows\FileIO.cpp">
 244.298 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.299 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.300 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.301 +    </ClCompile>
 244.302 +    <ClCompile Include="CPP\Windows\PropVariant.cpp">
 244.303 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.304 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.305 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.306 +    </ClCompile>
 244.307 +    <ClCompile Include="CPP\Windows\Time.cpp">
 244.308 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.309 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.310 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.311 +    </ClCompile>
 244.312 +    <ClCompile Include="CPP\7zip\Archive\7z\7zCompressionMode.cpp">
 244.313 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.314 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.315 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.316 +    </ClCompile>
 244.317 +    <ClCompile Include="CPP\7zip\Archive\7z\7zDecode.cpp">
 244.318 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.319 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.320 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.321 +    </ClCompile>
 244.322 +    <ClCompile Include="CPP\7zip\Archive\7z\7zExtract.cpp">
 244.323 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.324 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.325 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.326 +    </ClCompile>
 244.327 +    <ClCompile Include="CPP\7zip\Archive\7z\7zFolderInStream.cpp">
 244.328 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.329 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.330 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.331 +    </ClCompile>
 244.332 +    <ClCompile Include="CPP\7zip\Archive\7z\7zFolderOutStream.cpp">
 244.333 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.334 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.335 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.336 +    </ClCompile>
 244.337 +    <ClCompile Include="CPP\7zip\Archive\7z\7zHandler.cpp">
 244.338 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.339 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.340 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.341 +    </ClCompile>
 244.342 +    <ClCompile Include="CPP\7zip\Archive\7z\7zHeader.cpp">
 244.343 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.344 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.345 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.346 +    </ClCompile>
 244.347 +    <ClCompile Include="CPP\7zip\Archive\7z\7zIn.cpp">
 244.348 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.349 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.350 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.351 +    </ClCompile>
 244.352 +    <ClCompile Include="CPP\7zip\Archive\7z\7zProperties.cpp">
 244.353 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.354 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.355 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.356 +    </ClCompile>
 244.357 +    <ClCompile Include="CPP\7zip\Archive\7z\7zSpecStream.cpp">
 244.358 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.359 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.360 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.361 +    </ClCompile>
 244.362 +    <ClCompile Include="CPP\7zip\Archive\Rar\RarHandler.cpp">
 244.363 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.364 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.365 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.366 +    </ClCompile>
 244.367 +    <ClCompile Include="CPP\7zip\Archive\Rar\RarHeader.cpp">
 244.368 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.369 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.370 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.371 +    </ClCompile>
 244.372 +    <ClCompile Include="CPP\7zip\Archive\Rar\RarIn.cpp">
 244.373 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.374 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.375 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.376 +    </ClCompile>
 244.377 +    <ClCompile Include="CPP\7zip\Archive\Rar\RarItem.cpp">
 244.378 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.379 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.380 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.381 +    </ClCompile>
 244.382 +    <ClCompile Include="CPP\7zip\Archive\Rar\RarVolumeInStream.cpp">
 244.383 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.384 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.385 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.386 +    </ClCompile>
 244.387 +    <ClCompile Include="CPP\7zip\Archive\BZip2\BZip2Handler.cpp">
 244.388 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.389 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.390 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.391 +    </ClCompile>
 244.392 +    <ClCompile Include="CPP\7zip\Archive\Common\CoderMixer2.cpp">
 244.393 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.394 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.395 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.396 +    </ClCompile>
 244.397 +    <ClCompile Include="CPP\7zip\Archive\Common\CoderMixer2MT.cpp">
 244.398 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.399 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.400 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.401 +    </ClCompile>
 244.402 +    <ClCompile Include="CPP\7zip\Archive\Common\DummyOutStream.cpp">
 244.403 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.404 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.405 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.406 +    </ClCompile>
 244.407 +    <ClCompile Include="CPP\7zip\Archive\Common\FindSignature.cpp">
 244.408 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.409 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.410 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.411 +    </ClCompile>
 244.412 +    <ClCompile Include="CPP\7zip\Archive\Common\InStreamWithCRC.cpp">
 244.413 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.414 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.415 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.416 +    </ClCompile>
 244.417 +    <ClCompile Include="CPP\7zip\Archive\Common\ItemNameUtils.cpp">
 244.418 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.419 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.420 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.421 +    </ClCompile>
 244.422 +    <ClCompile Include="CPP\7zip\Archive\Common\MultiStream.cpp">
 244.423 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.424 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.425 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.426 +    </ClCompile>
 244.427 +    <ClCompile Include="CPP\7zip\Archive\Common\OutStreamWithCRC.cpp">
 244.428 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.429 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.430 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.431 +    </ClCompile>
 244.432 +    <ClCompile Include="CPP\7zip\Archive\Common\ParseProperties.cpp">
 244.433 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.434 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.435 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.436 +    </ClCompile>
 244.437 +    <ClCompile Include="CPP\7zip\Archive\GZip\GZipHandler.cpp">
 244.438 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.439 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.440 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.441 +    </ClCompile>
 244.442 +    <ClCompile Include="CPP\7zip\Archive\GZip\GZipHeader.cpp">
 244.443 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.444 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.445 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.446 +    </ClCompile>
 244.447 +    <ClCompile Include="CPP\7zip\Archive\GZip\GZipIn.cpp">
 244.448 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.449 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.450 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.451 +    </ClCompile>
 244.452 +    <ClCompile Include="CPP\7zip\Archive\Lzh\LzhCRC.cpp">
 244.453 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.454 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.455 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.456 +    </ClCompile>
 244.457 +    <ClCompile Include="CPP\7zip\Archive\Lzh\LzhHandler.cpp">
 244.458 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.459 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.460 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.461 +    </ClCompile>
 244.462 +    <ClCompile Include="CPP\7zip\Archive\Lzh\LzhIn.cpp">
 244.463 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.464 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.465 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.466 +    </ClCompile>
 244.467 +    <ClCompile Include="CPP\7zip\Archive\Lzh\LzhOutStreamWithCRC.cpp">
 244.468 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.469 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.470 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.471 +    </ClCompile>
 244.472 +    <ClCompile Include="CPP\7zip\Archive\Split\SplitHandler.cpp">
 244.473 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.474 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.475 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.476 +    </ClCompile>
 244.477 +    <ClCompile Include="CPP\7zip\Archive\Tar\TarHandler.cpp">
 244.478 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.479 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.480 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.481 +    </ClCompile>
 244.482 +    <ClCompile Include="CPP\7zip\Archive\Tar\TarHeader.cpp">
 244.483 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.484 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.485 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.486 +    </ClCompile>
 244.487 +    <ClCompile Include="CPP\7zip\Archive\Tar\TarIn.cpp">
 244.488 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.489 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.490 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.491 +    </ClCompile>
 244.492 +    <ClCompile Include="CPP\7zip\Archive\Zip\ZipHandler.cpp">
 244.493 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.494 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.495 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.496 +    </ClCompile>
 244.497 +    <ClCompile Include="CPP\7zip\Archive\Zip\ZipHeader.cpp">
 244.498 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.499 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.500 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.501 +    </ClCompile>
 244.502 +    <ClCompile Include="CPP\7zip\Archive\Zip\ZipIn.cpp">
 244.503 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.504 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.505 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.506 +    </ClCompile>
 244.507 +    <ClCompile Include="CPP\7zip\Archive\Zip\ZipItem.cpp">
 244.508 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.509 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.510 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.511 +    </ClCompile>
 244.512 +    <ClCompile Include="CPP\7zip\Archive\Lzma\LzmaFiltersDecode.cpp">
 244.513 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.514 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.515 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.516 +    </ClCompile>
 244.517 +    <ClCompile Include="CPP\7zip\Archive\Lzma\LzmaHandler.cpp">
 244.518 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.519 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.520 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.521 +    </ClCompile>
 244.522 +    <ClCompile Include="CPP\7zip\Archive\Lzma\LzmaIn.cpp">
 244.523 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.524 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.525 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.526 +    </ClCompile>
 244.527 +    <ClCompile Include="C\7zCrc.c">
 244.528 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.529 +      </PrecompiledHeader>
 244.530 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.531 +      </PrecompiledHeader>
 244.532 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 244.533 +      </PrecompiledHeader>
 244.534 +    </ClCompile>
 244.535 +    <ClCompile Include="C\Aes.c">
 244.536 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.537 +      </PrecompiledHeader>
 244.538 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.539 +      </PrecompiledHeader>
 244.540 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 244.541 +      </PrecompiledHeader>
 244.542 +    </ClCompile>
 244.543 +    <ClCompile Include="C\Alloc.c">
 244.544 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.545 +      </PrecompiledHeader>
 244.546 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.547 +      </PrecompiledHeader>
 244.548 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 244.549 +      </PrecompiledHeader>
 244.550 +    </ClCompile>
 244.551 +    <ClCompile Include="C\Bra.c">
 244.552 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.553 +      </PrecompiledHeader>
 244.554 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.555 +      </PrecompiledHeader>
 244.556 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 244.557 +      </PrecompiledHeader>
 244.558 +    </ClCompile>
 244.559 +    <ClCompile Include="C\Bra86.c">
 244.560 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.561 +      </PrecompiledHeader>
 244.562 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.563 +      </PrecompiledHeader>
 244.564 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 244.565 +      </PrecompiledHeader>
 244.566 +    </ClCompile>
 244.567 +    <ClCompile Include="C\BraIA64.c">
 244.568 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.569 +      </PrecompiledHeader>
 244.570 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.571 +      </PrecompiledHeader>
 244.572 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 244.573 +      </PrecompiledHeader>
 244.574 +    </ClCompile>
 244.575 +    <ClCompile Include="C\BwtSort.c">
 244.576 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.577 +      </PrecompiledHeader>
 244.578 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.579 +      </PrecompiledHeader>
 244.580 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 244.581 +      </PrecompiledHeader>
 244.582 +    </ClCompile>
 244.583 +    <ClCompile Include="C\HuffEnc.c">
 244.584 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.585 +      </PrecompiledHeader>
 244.586 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.587 +      </PrecompiledHeader>
 244.588 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 244.589 +      </PrecompiledHeader>
 244.590 +    </ClCompile>
 244.591 +    <ClCompile Include="C\LzFind.c">
 244.592 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.593 +      </PrecompiledHeader>
 244.594 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.595 +      </PrecompiledHeader>
 244.596 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 244.597 +      </PrecompiledHeader>
 244.598 +    </ClCompile>
 244.599 +    <ClCompile Include="C\LzFindMt.c">
 244.600 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.601 +      </PrecompiledHeader>
 244.602 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.603 +      </PrecompiledHeader>
 244.604 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 244.605 +      </PrecompiledHeader>
 244.606 +    </ClCompile>
 244.607 +    <ClCompile Include="C\LzmaDec.c">
 244.608 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.609 +      </PrecompiledHeader>
 244.610 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.611 +      </PrecompiledHeader>
 244.612 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 244.613 +      </PrecompiledHeader>
 244.614 +    </ClCompile>
 244.615 +    <ClCompile Include="C\LzmaEnc.c">
 244.616 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.617 +      </PrecompiledHeader>
 244.618 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.619 +      </PrecompiledHeader>
 244.620 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 244.621 +      </PrecompiledHeader>
 244.622 +    </ClCompile>
 244.623 +    <ClCompile Include="C\Sha256.c">
 244.624 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.625 +      </PrecompiledHeader>
 244.626 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.627 +      </PrecompiledHeader>
 244.628 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 244.629 +      </PrecompiledHeader>
 244.630 +    </ClCompile>
 244.631 +    <ClCompile Include="C\Sort.c">
 244.632 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.633 +      </PrecompiledHeader>
 244.634 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.635 +      </PrecompiledHeader>
 244.636 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 244.637 +      </PrecompiledHeader>
 244.638 +    </ClCompile>
 244.639 +    <ClCompile Include="C\Threads.c">
 244.640 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 244.641 +      </PrecompiledHeader>
 244.642 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">
 244.643 +      </PrecompiledHeader>
 244.644 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 244.645 +      </PrecompiledHeader>
 244.646 +    </ClCompile>
 244.647 +    <ClCompile Include="CPP\Common\CRC.cpp">
 244.648 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.649 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.650 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.651 +    </ClCompile>
 244.652 +    <ClCompile Include="CPP\Common\IntToString.cpp">
 244.653 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.654 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.655 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.656 +    </ClCompile>
 244.657 +    <ClCompile Include="CPP\Common\MyMap.cpp">
 244.658 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.659 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.660 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.661 +    </ClCompile>
 244.662 +    <ClCompile Include="CPP\Common\MyString.cpp">
 244.663 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.664 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.665 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.666 +    </ClCompile>
 244.667 +    <ClCompile Include="CPP\Common\MyVector.cpp">
 244.668 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.669 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.670 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.671 +    </ClCompile>
 244.672 +    <ClCompile Include="CPP\Common\MyXml.cpp">
 244.673 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.674 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.675 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.676 +    </ClCompile>
 244.677 +    <ClCompile Include="CPP\Common\NewHandler.cpp">
 244.678 +      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
 244.679 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.680 +      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">true</ExcludedFromBuild>
 244.681 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.682 +      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
 244.683 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.684 +    </ClCompile>
 244.685 +    <ClCompile Include="CPP\Common\StringConvert.cpp">
 244.686 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.687 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.688 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.689 +    </ClCompile>
 244.690 +    <ClCompile Include="CPP\Common\StringToInt.cpp">
 244.691 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.692 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.693 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.694 +    </ClCompile>
 244.695 +    <ClCompile Include="CPP\Common\UTFConvert.cpp">
 244.696 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.697 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.698 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.699 +    </ClCompile>
 244.700 +    <ClCompile Include="CPP\Common\Wildcard.cpp">
 244.701 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.702 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.703 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.704 +    </ClCompile>
 244.705 +    <ClCompile Include="CPP\7zip\Compress\LzhDecoder.cpp">
 244.706 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.707 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.708 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.709 +    </ClCompile>
 244.710 +    <ClCompile Include="CPP\7zip\Compress\LzOutWindow.cpp">
 244.711 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.712 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.713 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.714 +    </ClCompile>
 244.715 +    <ClCompile Include="CPP\7zip\Compress\PpmdDecoder.cpp">
 244.716 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.717 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.718 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.719 +    </ClCompile>
 244.720 +    <ClCompile Include="CPP\7zip\Compress\BitlDecoder.cpp">
 244.721 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.722 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.723 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.724 +    </ClCompile>
 244.725 +    <ClCompile Include="CPP\7zip\Compress\Rar1Decoder.cpp">
 244.726 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.727 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.728 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.729 +    </ClCompile>
 244.730 +    <ClCompile Include="CPP\7zip\Compress\Rar2Decoder.cpp">
 244.731 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.732 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.733 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.734 +    </ClCompile>
 244.735 +    <ClCompile Include="CPP\7zip\Compress\Rar3Decoder.cpp">
 244.736 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.737 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.738 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.739 +    </ClCompile>
 244.740 +    <ClCompile Include="CPP\7zip\Compress\Rar3Vm.cpp">
 244.741 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.742 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.743 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.744 +    </ClCompile>
 244.745 +    <ClCompile Include="CPP\7zip\Compress\BZip2Crc.cpp">
 244.746 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.747 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.748 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.749 +    </ClCompile>
 244.750 +    <ClCompile Include="CPP\7zip\Compress\BZip2Decoder.cpp">
 244.751 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.752 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.753 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.754 +    </ClCompile>
 244.755 +    <ClCompile Include="CPP\7zip\Compress\DeflateDecoder.cpp">
 244.756 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.757 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.758 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.759 +    </ClCompile>
 244.760 +    <ClCompile Include="CPP\7zip\Compress\ImplodeDecoder.cpp">
 244.761 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.762 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.763 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.764 +    </ClCompile>
 244.765 +    <ClCompile Include="CPP\7zip\Compress\ImplodeHuffmanDecoder.cpp">
 244.766 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.767 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.768 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.769 +    </ClCompile>
 244.770 +    <ClCompile Include="CPP\7zip\Compress\ShrinkDecoder.cpp">
 244.771 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.772 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.773 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.774 +    </ClCompile>
 244.775 +    <ClCompile Include="CPP\7zip\Compress\ZlibDecoder.cpp">
 244.776 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.777 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.778 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.779 +    </ClCompile>
 244.780 +    <ClCompile Include="CPP\7zip\Compress\Bcj2Coder.cpp">
 244.781 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.782 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.783 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.784 +    </ClCompile>
 244.785 +    <ClCompile Include="CPP\7zip\Compress\BcjCoder.cpp">
 244.786 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.787 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.788 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.789 +    </ClCompile>
 244.790 +    <ClCompile Include="CPP\7zip\Compress\BranchCoder.cpp">
 244.791 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.792 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.793 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.794 +    </ClCompile>
 244.795 +    <ClCompile Include="CPP\7zip\Compress\BranchMisc.cpp">
 244.796 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.797 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.798 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.799 +    </ClCompile>
 244.800 +    <ClCompile Include="CPP\7zip\Compress\ByteSwap.cpp">
 244.801 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.802 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.803 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.804 +    </ClCompile>
 244.805 +    <ClCompile Include="CPP\7zip\Compress\CopyCoder.cpp">
 244.806 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.807 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.808 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.809 +    </ClCompile>
 244.810 +    <ClCompile Include="CPP\7zip\Compress\LzmaDecoder.cpp">
 244.811 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.812 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.813 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.814 +    </ClCompile>
 244.815 +    <ClCompile Include="CPP\7zip\Crypto\7zAes.cpp">
 244.816 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.817 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.818 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.819 +    </ClCompile>
 244.820 +    <ClCompile Include="CPP\7zip\Crypto\HmacSha1.cpp">
 244.821 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.822 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.823 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.824 +    </ClCompile>
 244.825 +    <ClCompile Include="CPP\7zip\Crypto\MyAes.cpp">
 244.826 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.827 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.828 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.829 +    </ClCompile>
 244.830 +    <ClCompile Include="CPP\7zip\Crypto\Pbkdf2HmacSha1.cpp">
 244.831 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.832 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.833 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.834 +    </ClCompile>
 244.835 +    <ClCompile Include="CPP\7zip\Crypto\RandGen.cpp">
 244.836 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.837 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.838 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.839 +    </ClCompile>
 244.840 +    <ClCompile Include="CPP\7zip\Crypto\Rar20Crypto.cpp">
 244.841 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.842 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.843 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.844 +    </ClCompile>
 244.845 +    <ClCompile Include="CPP\7zip\Crypto\RarAes.cpp">
 244.846 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.847 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.848 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.849 +    </ClCompile>
 244.850 +    <ClCompile Include="CPP\7zip\Crypto\Sha1.cpp">
 244.851 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.852 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.853 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.854 +    </ClCompile>
 244.855 +    <ClCompile Include="CPP\7zip\Crypto\WzAes.cpp">
 244.856 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.857 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.858 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.859 +    </ClCompile>
 244.860 +    <ClCompile Include="CPP\7zip\Crypto\ZipCrypto.cpp">
 244.861 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.862 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.863 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.864 +    </ClCompile>
 244.865 +    <ClCompile Include="CPP\7zip\Crypto\ZipStrong.cpp">
 244.866 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.867 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.868 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.869 +    </ClCompile>
 244.870 +    <ClCompile Include="CPP\7zip\Crypto\7zAesRegister.cpp">
 244.871 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.872 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.873 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.874 +    </ClCompile>
 244.875 +    <ClCompile Include="CPP\7zip\Archive\7z\7zRegister.cpp">
 244.876 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.877 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.878 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.879 +    </ClCompile>
 244.880 +    <ClCompile Include="CPP\7zip\Archive\ArchiveExports.cpp">
 244.881 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
 244.882 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Create</PrecompiledHeader>
 244.883 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
 244.884 +    </ClCompile>
 244.885 +    <ClCompile Include="CPP\7zip\Compress\Bcj2Register.cpp">
 244.886 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.887 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.888 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.889 +    </ClCompile>
 244.890 +    <ClCompile Include="CPP\7zip\Compress\BcjRegister.cpp">
 244.891 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.892 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.893 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.894 +    </ClCompile>
 244.895 +    <ClCompile Include="CPP\7zip\Compress\BranchRegister.cpp">
 244.896 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.897 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.898 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.899 +    </ClCompile>
 244.900 +    <ClCompile Include="CPP\7zip\Compress\ByteSwapRegister.cpp">
 244.901 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.902 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.903 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.904 +    </ClCompile>
 244.905 +    <ClCompile Include="CPP\7zip\Archive\BZip2\bz2Register.cpp">
 244.906 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.907 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.908 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.909 +    </ClCompile>
 244.910 +    <ClCompile Include="CPP\7zip\Compress\BZip2Register.cpp">
 244.911 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.912 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.913 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.914 +    </ClCompile>
 244.915 +    <ClCompile Include="CPP\7zip\Compress\CodecExports.cpp">
 244.916 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.917 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.918 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.919 +    </ClCompile>
 244.920 +    <ClCompile Include="CPP\7zip\Compress\CopyRegister.cpp">
 244.921 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.922 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.923 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.924 +    </ClCompile>
 244.925 +    <ClCompile Include="CPP\7zip\Common\CreateCoder.cpp">
 244.926 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.927 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.928 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.929 +    </ClCompile>
 244.930 +    <ClCompile Include="CPP\7zip\Compress\Deflate64Register.cpp">
 244.931 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.932 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.933 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.934 +    </ClCompile>
 244.935 +    <ClCompile Include="CPP\7zip\Compress\DeflateNsisRegister.cpp">
 244.936 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.937 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.938 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.939 +    </ClCompile>
 244.940 +    <ClCompile Include="CPP\7zip\Compress\DeflateRegister.cpp">
 244.941 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.942 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.943 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.944 +    </ClCompile>
 244.945 +    <ClCompile Include="CPP\7zip\Archive\DllExports2.cpp">
 244.946 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.947 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.948 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.949 +    </ClCompile>
 244.950 +    <ClCompile Include="CPP\7zip\Archive\GZip\GZipRegister.cpp">
 244.951 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.952 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.953 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.954 +    </ClCompile>
 244.955 +    <ClCompile Include="CPP\7zip\Archive\Lzh\LzhRegister.cpp">
 244.956 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.957 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.958 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.959 +    </ClCompile>
 244.960 +    <ClCompile Include="CPP\7zip\Archive\Lzma\LzmaArcRegister.cpp">
 244.961 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.962 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.963 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.964 +    </ClCompile>
 244.965 +    <ClCompile Include="CPP\7zip\Compress\LzmaRegister.cpp">
 244.966 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.967 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.968 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.969 +    </ClCompile>
 244.970 +    <ClCompile Include="CPP\7zip\Compress\PpmdRegister.cpp">
 244.971 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.972 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.973 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.974 +    </ClCompile>
 244.975 +    <ClCompile Include="CPP\7zip\Compress\RarCodecsRegister.cpp">
 244.976 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.977 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.978 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.979 +    </ClCompile>
 244.980 +    <ClCompile Include="CPP\7zip\Archive\Rar\RarRegister.cpp">
 244.981 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.982 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.983 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.984 +    </ClCompile>
 244.985 +    <ClCompile Include="CPP\7zip\Archive\Split\SplitRegister.cpp">
 244.986 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.987 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.988 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.989 +    </ClCompile>
 244.990 +    <ClCompile Include="CPP\7zip\Archive\Tar\TarRegister.cpp">
 244.991 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.992 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.993 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.994 +    </ClCompile>
 244.995 +    <ClCompile Include="CPP\7zip\Archive\Zip\ZipRegister.cpp">
 244.996 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
 244.997 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release FastBuild|Win32'">Use</PrecompiledHeader>
 244.998 +      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
 244.999 +    </ClCompile>
244.1000 +  </ItemGroup>
244.1001 +  <ItemGroup>
244.1002 +    <ClInclude Include="CPP\7zip\Crypto\7zAes.h" />
244.1003 +    <ClInclude Include="CPP\7zip\Archive\7z\7zCompressionMode.h" />
244.1004 +    <ClInclude Include="C\7zCrc.h" />
244.1005 +    <ClInclude Include="CPP\7zip\Archive\7z\7zDecode.h" />
244.1006 +    <ClInclude Include="CPP\7zip\Archive\7z\7zFolderInStream.h" />
244.1007 +    <ClInclude Include="CPP\7zip\Archive\7z\7zFolderOutStream.h" />
244.1008 +    <ClInclude Include="CPP\7zip\Archive\7z\7zHandler.h" />
244.1009 +    <ClInclude Include="CPP\7zip\Archive\7z\7zHeader.h" />
244.1010 +    <ClInclude Include="CPP\7zip\Archive\7z\7zIn.h" />
244.1011 +    <ClInclude Include="CPP\7zip\Archive\7z\7zItem.h" />
244.1012 +    <ClInclude Include="CPP\7zip\Archive\7z\7zProperties.h" />
244.1013 +    <ClInclude Include="CPP\7zip\Archive\7z\7zSpecStream.h" />
244.1014 +    <ClInclude Include="C\Aes.h" />
244.1015 +    <ClInclude Include="C\Alloc.h" />
244.1016 +    <ClInclude Include="CPP\7zip\Compress\Bcj2Coder.h" />
244.1017 +    <ClInclude Include="CPP\7zip\Compress\BcjCoder.h" />
244.1018 +    <ClInclude Include="CPP\7zip\Compress\BitlDecoder.h" />
244.1019 +    <ClInclude Include="CPP\7zip\Compress\BitmDecoder.h" />
244.1020 +    <ClInclude Include="C\Bra.h" />
244.1021 +    <ClInclude Include="CPP\7zip\Compress\BranchCoder.h" />
244.1022 +    <ClInclude Include="CPP\7zip\Compress\BranchMisc.h" />
244.1023 +    <ClInclude Include="CPP\Common\Buffer.h" />
244.1024 +    <ClInclude Include="C\BwtSort.h" />
244.1025 +    <ClInclude Include="CPP\7zip\Compress\ByteSwap.h" />
244.1026 +    <ClInclude Include="CPP\7zip\Compress\BZip2Const.h" />
244.1027 +    <ClInclude Include="CPP\7zip\Compress\BZip2Crc.h" />
244.1028 +    <ClInclude Include="CPP\7zip\Compress\BZip2Decoder.h" />
244.1029 +    <ClInclude Include="CPP\7zip\Archive\BZip2\BZip2Handler.h" />
244.1030 +    <ClInclude Include="CPP\7zip\Archive\BZip2\BZip2Item.h" />
244.1031 +    <ClInclude Include="CPP\7zip\Archive\Common\CoderMixer2.h" />
244.1032 +    <ClInclude Include="CPP\7zip\Archive\Common\CoderMixer2MT.h" />
244.1033 +    <ClInclude Include="CPP\Common\ComTry.h" />
244.1034 +    <ClInclude Include="CPP\7zip\Compress\CopyCoder.h" />
244.1035 +    <ClInclude Include="C\CpuArch.h" />
244.1036 +    <ClInclude Include="CPP\7zip\Common\CreateCoder.h" />
244.1037 +    <ClInclude Include="CPP\7zip\Common\DeclareArcs.h" />
244.1038 +    <ClInclude Include="CPP\7zip\Common\DeclareCodecs.h" />
244.1039 +    <ClInclude Include="CPP\7zip\Compress\DeflateConst.h" />
244.1040 +    <ClInclude Include="CPP\7zip\Compress\DeflateDecoder.h" />
244.1041 +    <ClInclude Include="CPP\Windows\Defs.h" />
244.1042 +    <ClInclude Include="CPP\Common\Defs.h" />
244.1043 +    <ClInclude Include="CPP\7zip\Archive\Common\DummyOutStream.h" />
244.1044 +    <ClInclude Include="CPP\Common\DynamicBuffer.h" />
244.1045 +    <ClInclude Include="CPP\Windows\FileDir.h" />
244.1046 +    <ClInclude Include="CPP\Windows\FileFind.h" />
244.1047 +    <ClInclude Include="CPP\Windows\FileIO.h" />
244.1048 +    <ClInclude Include="CPP\Windows\FileName.h" />
244.1049 +    <ClInclude Include="CPP\7zip\Common\FilterCoder.h" />
244.1050 +    <ClInclude Include="CPP\7zip\Archive\Common\FindSignature.h" />
244.1051 +    <ClInclude Include="CPP\7zip\Archive\GZip\GZipHandler.h" />
244.1052 +    <ClInclude Include="CPP\7zip\Archive\GZip\GZipHeader.h" />
244.1053 +    <ClInclude Include="CPP\7zip\Archive\GZip\GZipIn.h" />
244.1054 +    <ClInclude Include="CPP\7zip\Archive\GZip\GZipItem.h" />
244.1055 +    <ClInclude Include="CPP\7zip\Archive\GZip\GZipUpdate.h" />
244.1056 +    <ClInclude Include="CPP\Windows\Handle.h" />
244.1057 +    <ClInclude Include="CPP\7zip\Crypto\HmacSha1.h" />
244.1058 +    <ClInclude Include="C\HuffEnc.h" />
244.1059 +    <ClInclude Include="CPP\7zip\Compress\HuffmanDecoder.h" />
244.1060 +    <ClInclude Include="CPP\7zip\Archive\IArchive.h" />
244.1061 +    <ClInclude Include="CPP\7zip\ICoder.h" />
244.1062 +    <ClInclude Include="CPP\7zip\IDecl.h" />
244.1063 +    <ClInclude Include="CPP\7zip\Compress\ImplodeDecoder.h" />
244.1064 +    <ClInclude Include="CPP\7zip\Compress\ImplodeHuffmanDecoder.h" />
244.1065 +    <ClInclude Include="CPP\7zip\Common\InBuffer.h" />
244.1066 +    <ClInclude Include="CPP\Common\InitializeStaticLib.h" />
244.1067 +    <ClInclude Include="CPP\7zip\Common\InOutTempBuffer.h" />
244.1068 +    <ClInclude Include="CPP\7zip\Archive\Common\InStreamWithCRC.h" />
244.1069 +    <ClInclude Include="CPP\Common\IntToString.h" />
244.1070 +    <ClInclude Include="CPP\7zip\IPassword.h" />
244.1071 +    <ClInclude Include="CPP\7zip\IProgress.h" />
244.1072 +    <ClInclude Include="CPP\7zip\IStream.h" />
244.1073 +    <ClInclude Include="CPP\7zip\Archive\Common\ItemNameUtils.h" />
244.1074 +    <ClInclude Include="CPP\7zip\Common\LimitedStreams.h" />
244.1075 +    <ClInclude Include="CPP\7zip\Common\LockedStream.h" />
244.1076 +    <ClInclude Include="C\LzFind.h" />
244.1077 +    <ClInclude Include="C\LzFindMt.h" />
244.1078 +    <ClInclude Include="C\LzHash.h" />
244.1079 +    <ClInclude Include="CPP\7zip\Archive\Lzh\LzhCRC.h" />
244.1080 +    <ClInclude Include="CPP\7zip\Compress\LzhDecoder.h" />
244.1081 +    <ClInclude Include="CPP\7zip\Archive\Lzh\LzhHandler.h" />
244.1082 +    <ClInclude Include="CPP\7zip\Archive\Lzh\LzhHeader.h" />
244.1083 +    <ClInclude Include="CPP\7zip\Archive\Lzh\LzhIn.h" />
244.1084 +    <ClInclude Include="CPP\7zip\Archive\Lzh\LzhItem.h" />
244.1085 +    <ClInclude Include="CPP\7zip\Archive\Lzh\LzhOutStreamWithCRC.h" />
244.1086 +    <ClInclude Include="C\LzmaDec.h" />
244.1087 +    <ClInclude Include="CPP\7zip\Compress\LzmaDecoder.h" />
244.1088 +    <ClInclude Include="C\LzmaEnc.h" />
244.1089 +    <ClInclude Include="CPP\7zip\Archive\Lzma\LzmaFiltersDecode.h" />
244.1090 +    <ClInclude Include="CPP\7zip\Archive\Lzma\LzmaHandler.h" />
244.1091 +    <ClInclude Include="CPP\7zip\Archive\Lzma\LzmaIn.h" />
244.1092 +    <ClInclude Include="CPP\7zip\Archive\Lzma\LzmaItem.h" />
244.1093 +    <ClInclude Include="CPP\7zip\Compress\LzOutWindow.h" />
244.1094 +    <ClInclude Include="CPP\7zip\Common\MemBlocks.h" />
244.1095 +    <ClInclude Include="CPP\7zip\Common\MethodId.h" />
244.1096 +    <ClInclude Include="CPP\7zip\Common\MethodProps.h" />
244.1097 +    <ClInclude Include="CPP\7zip\Compress\Mtf8.h" />
244.1098 +    <ClInclude Include="CPP\7zip\Archive\Common\MultiStream.h" />
244.1099 +    <ClInclude Include="CPP\7zip\Crypto\MyAes.h" />
244.1100 +    <ClInclude Include="CPP\Common\MyCom.h" />
244.1101 +    <ClInclude Include="CPP\Common\MyException.h" />
244.1102 +    <ClInclude Include="CPP\Common\MyInitGuid.h" />
244.1103 +    <ClInclude Include="CPP\Common\MyMap.h" />
244.1104 +    <ClInclude Include="CPP\Common\MyString.h" />
244.1105 +    <ClInclude Include="CPP\Common\MyUnknown.h" />
244.1106 +    <ClInclude Include="CPP\Common\MyVector.h" />
244.1107 +    <ClInclude Include="CPP\Common\MyWindows.h" />
244.1108 +    <ClInclude Include="CPP\Common\MyXml.h" />
244.1109 +    <ClInclude Include="CPP\Common\NewHandler.h" />
244.1110 +    <ClInclude Include="CPP\7zip\Common\OffsetStream.h" />
244.1111 +    <ClInclude Include="CPP\7zip\Common\OutBuffer.h" />
244.1112 +    <ClInclude Include="CPP\7zip\Common\OutMemStream.h" />
244.1113 +    <ClInclude Include="CPP\7zip\Archive\Common\OutStreamWithCRC.h" />
244.1114 +    <ClInclude Include="CPP\7zip\Archive\Common\ParseProperties.h" />
244.1115 +    <ClInclude Include="CPP\7zip\Crypto\Pbkdf2HmacSha1.h" />
244.1116 +    <ClInclude Include="CPP\7zip\Compress\PpmdContext.h" />
244.1117 +    <ClInclude Include="CPP\7zip\Compress\PpmdDecode.h" />
244.1118 +    <ClInclude Include="CPP\7zip\Compress\PpmdDecoder.h" />
244.1119 +    <ClInclude Include="CPP\7zip\Compress\PpmdSubAlloc.h" />
244.1120 +    <ClInclude Include="CPP\7zip\Compress\PpmdType.h" />
244.1121 +    <ClInclude Include="CPP\7zip\Common\ProgressMt.h" />
244.1122 +    <ClInclude Include="CPP\7zip\Common\ProgressUtils.h" />
244.1123 +    <ClInclude Include="CPP\7zip\PropID.h" />
244.1124 +    <ClInclude Include="CPP\Windows\PropVariant.h" />
244.1125 +    <ClInclude Include="CPP\7zip\Crypto\RandGen.h" />
244.1126 +    <ClInclude Include="CPP\7zip\Compress\RangeCoder.h" />
244.1127 +    <ClInclude Include="CPP\7zip\Compress\RangeCoderBit.h" />
244.1128 +    <ClInclude Include="CPP\7zip\Compress\Rar1Decoder.h" />
244.1129 +    <ClInclude Include="CPP\7zip\Crypto\Rar20Crypto.h" />
244.1130 +    <ClInclude Include="CPP\7zip\Compress\Rar2Decoder.h" />
244.1131 +    <ClInclude Include="CPP\7zip\Compress\Rar3Decoder.h" />
244.1132 +    <ClInclude Include="CPP\7zip\Compress\Rar3Vm.h" />
244.1133 +    <ClInclude Include="CPP\7zip\Crypto\RarAes.h" />
244.1134 +    <ClInclude Include="CPP\7zip\Archive\Rar\RarHandler.h" />
244.1135 +    <ClInclude Include="CPP\7zip\Archive\Rar\RarHeader.h" />
244.1136 +    <ClInclude Include="CPP\7zip\Archive\Rar\RarIn.h" />
244.1137 +    <ClInclude Include="CPP\7zip\Archive\Rar\RarItem.h" />
244.1138 +    <ClInclude Include="CPP\7zip\Archive\Rar\RarVolumeInStream.h" />
244.1139 +    <ClInclude Include="CPP\7zip\Common\RegisterArc.h" />
244.1140 +    <ClInclude Include="CPP\7zip\Common\RegisterCodec.h" />
244.1141 +    <ClInclude Include="C\RotateDefs.h" />
244.1142 +    <ClInclude Include="CPP\7zip\Crypto\Sha1.h" />
244.1143 +    <ClInclude Include="C\Sha256.h" />
244.1144 +    <ClInclude Include="CPP\7zip\Compress\ShrinkDecoder.h" />
244.1145 +    <ClInclude Include="C\Sort.h" />
244.1146 +    <ClInclude Include="CPP\7zip\Archive\Split\SplitHandler.h" />
244.1147 +    <ClInclude Include="CPP\7zip\Archive\Common\StdAfx.h" />
244.1148 +    <ClInclude Include="CPP\7zip\Archive\Rar\StdAfx.h" />
244.1149 +    <ClInclude Include="CPP\7zip\Archive\BZip2\StdAfx.h" />
244.1150 +    <ClInclude Include="CPP\Windows\StdAfx.h" />
244.1151 +    <ClInclude Include="CPP\7zip\Archive\7z\StdAfx.h" />
244.1152 +    <ClInclude Include="CPP\7zip\Archive\StdAfx.h" />
244.1153 +    <ClInclude Include="CPP\7zip\Compress\StdAfx.h" />
244.1154 +    <ClInclude Include="CPP\7zip\Bundles\Format7zF\StdAfx.h" />
244.1155 +    <ClInclude Include="CPP\7zip\Archive\GZip\StdAfx.h" />
244.1156 +    <ClInclude Include="CPP\7zip\Crypto\StdAfx.h" />
244.1157 +    <ClInclude Include="CPP\7zip\Archive\Tar\StdAfx.h" />
244.1158 +    <ClInclude Include="CPP\7zip\Archive\Zip\StdAfx.h" />
244.1159 +    <ClInclude Include="CPP\7zip\Archive\Lzh\StdAfx.h" />
244.1160 +    <ClInclude Include="CPP\7zip\Common\StdAfx.h" />
244.1161 +    <ClInclude Include="CPP\7zip\Archive\Split\StdAfx.h" />
244.1162 +    <ClInclude Include="CPP\7zip\Archive\Lzma\StdAfx.h" />
244.1163 +    <ClInclude Include="CPP\7zip\Common\StreamBinder.h" />
244.1164 +    <ClInclude Include="CPP\7zip\Common\StreamObjects.h" />
244.1165 +    <ClInclude Include="CPP\7zip\Common\StreamUtils.h" />
244.1166 +    <ClInclude Include="CPP\Common\StringConvert.h" />
244.1167 +    <ClInclude Include="CPP\Common\StringToInt.h" />
244.1168 +    <ClInclude Include="CPP\Windows\Synchronization.h" />
244.1169 +    <ClInclude Include="CPP\7zip\Archive\Tar\TarHandler.h" />
244.1170 +    <ClInclude Include="CPP\7zip\Archive\Tar\TarHeader.h" />
244.1171 +    <ClInclude Include="CPP\7zip\Archive\Tar\TarIn.h" />
244.1172 +    <ClInclude Include="CPP\7zip\Archive\Tar\TarItem.h" />
244.1173 +    <ClInclude Include="CPP\Windows\Thread.h" />
244.1174 +    <ClInclude Include="C\Threads.h" />
244.1175 +    <ClInclude Include="CPP\Windows\Time.h" />
244.1176 +    <ClInclude Include="CPP\Common\Types.h" />
244.1177 +    <ClInclude Include="C\Types.h" />
244.1178 +    <ClInclude Include="CPP\Common\UTFConvert.h" />
244.1179 +    <ClInclude Include="CPP\7zip\Common\VirtThread.h" />
244.1180 +    <ClInclude Include="CPP\Common\Wildcard.h" />
244.1181 +    <ClInclude Include="CPP\7zip\Crypto\WzAes.h" />
244.1182 +    <ClInclude Include="CPP\7zip\Archive\Zip\ZipCompressionMode.h" />
244.1183 +    <ClInclude Include="CPP\7zip\Crypto\ZipCrypto.h" />
244.1184 +    <ClInclude Include="CPP\7zip\Archive\Zip\ZipHandler.h" />
244.1185 +    <ClInclude Include="CPP\7zip\Archive\Zip\ZipHeader.h" />
244.1186 +    <ClInclude Include="CPP\7zip\Archive\Zip\ZipIn.h" />
244.1187 +    <ClInclude Include="CPP\7zip\Archive\Zip\ZipItem.h" />
244.1188 +    <ClInclude Include="CPP\7zip\Archive\Zip\ZipItemEx.h" />
244.1189 +    <ClInclude Include="CPP\7zip\Crypto\ZipStrong.h" />
244.1190 +    <ClInclude Include="CPP\7zip\Compress\ZlibDecoder.h" />
244.1191 +  </ItemGroup>
244.1192 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
244.1193 +  <ImportGroup Label="ExtensionTargets">
244.1194 +    <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
244.1195 +  </ImportGroup>
244.1196 +</Project>
244.1197 \ No newline at end of file
   245.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   245.2 +++ b/src/win32/7zip/7z/7zip_2010.vcxproj.filters	Sat Mar 03 10:31:27 2012 -0600
   245.3 @@ -0,0 +1,1101 @@
   245.4 +<?xml version="1.0" encoding="utf-8"?>
   245.5 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   245.6 +  <ItemGroup>
   245.7 +    <Filter Include="7zip">
   245.8 +      <UniqueIdentifier>{640011be-3f4f-4873-8d35-29603260353a}</UniqueIdentifier>
   245.9 +    </Filter>
  245.10 +    <Filter Include="Archive">
  245.11 +      <UniqueIdentifier>{ca6f9c4b-9f5f-48ad-a31c-af98fcd62e40}</UniqueIdentifier>
  245.12 +    </Filter>
  245.13 +    <Filter Include="Archive\7z">
  245.14 +      <UniqueIdentifier>{92298691-8079-41ab-97b4-ea8c5d57705d}</UniqueIdentifier>
  245.15 +    </Filter>
  245.16 +    <Filter Include="Archive\Archive common">
  245.17 +      <UniqueIdentifier>{07c1f99d-328c-4292-bcae-756aa615b6b8}</UniqueIdentifier>
  245.18 +    </Filter>
  245.19 +    <Filter Include="Archive\bz2">
  245.20 +      <UniqueIdentifier>{d4404f87-37f6-47c0-84ad-28f886e050f1}</UniqueIdentifier>
  245.21 +    </Filter>
  245.22 +    <Filter Include="Archive\GZip">
  245.23 +      <UniqueIdentifier>{2da83f5f-49e0-4bf4-94df-5f71548d513e}</UniqueIdentifier>
  245.24 +    </Filter>
  245.25 +    <Filter Include="Archive\Lzh">
  245.26 +      <UniqueIdentifier>{c294dbd6-e157-4b12-a25f-f86c6f33c0ac}</UniqueIdentifier>
  245.27 +    </Filter>
  245.28 +    <Filter Include="Archive\Lzma Ar">
  245.29 +      <UniqueIdentifier>{cf17b1b3-505a-4072-82c3-a558076da4c9}</UniqueIdentifier>
  245.30 +    </Filter>
  245.31 +    <Filter Include="Archive\Rar">
  245.32 +      <UniqueIdentifier>{2c848328-adab-4c70-8850-0cd99749a22a}</UniqueIdentifier>
  245.33 +    </Filter>
  245.34 +    <Filter Include="Archive\Split">
  245.35 +      <UniqueIdentifier>{681491fd-a85a-4c9d-979c-16310a4bc7d2}</UniqueIdentifier>
  245.36 +    </Filter>
  245.37 +    <Filter Include="Archive\Tar">
  245.38 +      <UniqueIdentifier>{f3894462-e945-41f6-8e24-095eb40a5366}</UniqueIdentifier>
  245.39 +    </Filter>
  245.40 +    <Filter Include="Archive\Zip">
  245.41 +      <UniqueIdentifier>{67371b0c-95dc-4dc8-8783-b64dff05d198}</UniqueIdentifier>
  245.42 +    </Filter>
  245.43 +    <Filter Include="C">
  245.44 +      <UniqueIdentifier>{5ea4ccf3-187c-4ab5-a59c-a7ad7eec0faa}</UniqueIdentifier>
  245.45 +    </Filter>
  245.46 +    <Filter Include="Common">
  245.47 +      <UniqueIdentifier>{f50e973f-7173-4cde-a755-fb5e8d91ab0e}</UniqueIdentifier>
  245.48 +    </Filter>
  245.49 +    <Filter Include="Compress">
  245.50 +      <UniqueIdentifier>{6af22ddd-1f4e-4843-a216-ec5e10c4fa28}</UniqueIdentifier>
  245.51 +    </Filter>
  245.52 +    <Filter Include="Compress\7z Compress">
  245.53 +      <UniqueIdentifier>{79334f59-b7f7-4c4f-86af-408256cd4abe}</UniqueIdentifier>
  245.54 +    </Filter>
  245.55 +    <Filter Include="Compress\Bit Coder">
  245.56 +      <UniqueIdentifier>{489a1d17-d337-4891-9071-61795accd837}</UniqueIdentifier>
  245.57 +    </Filter>
  245.58 +    <Filter Include="Compress\BZip2 Compress">
  245.59 +      <UniqueIdentifier>{97f1da29-65d5-42e9-9d87-6e25185e01c6}</UniqueIdentifier>
  245.60 +    </Filter>
  245.61 +    <Filter Include="Compress\PPMD">
  245.62 +      <UniqueIdentifier>{6ae17cf5-91d4-437c-84ea-e70b79c5f915}</UniqueIdentifier>
  245.63 +    </Filter>
  245.64 +    <Filter Include="Compress\Rar Compress">
  245.65 +      <UniqueIdentifier>{17dd5db8-6972-4bde-a450-a16aded15a07}</UniqueIdentifier>
  245.66 +    </Filter>
  245.67 +    <Filter Include="Compress\Zip Compress">
  245.68 +      <UniqueIdentifier>{3a7d5a57-f03c-4adb-8101-4dd3c84d9514}</UniqueIdentifier>
  245.69 +    </Filter>
  245.70 +    <Filter Include="Crypto">
  245.71 +      <UniqueIdentifier>{7164d745-e58e-44a4-bfe9-037f44bee447}</UniqueIdentifier>
  245.72 +    </Filter>
  245.73 +    <Filter Include="Headers">
  245.74 +      <UniqueIdentifier>{33eeb3f2-448c-4542-b150-472136c39410}</UniqueIdentifier>
  245.75 +    </Filter>
  245.76 +    <Filter Include="Register">
  245.77 +      <UniqueIdentifier>{6f4b2871-2e91-4697-a7f5-6596fae9ac6e}</UniqueIdentifier>
  245.78 +    </Filter>
  245.79 +    <Filter Include="Windows">
  245.80 +      <UniqueIdentifier>{c1dbfe74-7113-46fd-80cf-bb76de09bf98}</UniqueIdentifier>
  245.81 +    </Filter>
  245.82 +  </ItemGroup>
  245.83 +  <ItemGroup>
  245.84 +    <ClCompile Include="CPP\7zip\Archive\7z\7zCompressionMode.cpp">
  245.85 +      <Filter>Archive\7z</Filter>
  245.86 +    </ClCompile>
  245.87 +    <ClCompile Include="CPP\7zip\Archive\7z\7zDecode.cpp">
  245.88 +      <Filter>Archive\7z</Filter>
  245.89 +    </ClCompile>
  245.90 +    <ClCompile Include="CPP\7zip\Archive\7z\7zExtract.cpp">
  245.91 +      <Filter>Archive\7z</Filter>
  245.92 +    </ClCompile>
  245.93 +    <ClCompile Include="CPP\7zip\Archive\7z\7zFolderInStream.cpp">
  245.94 +      <Filter>Archive\7z</Filter>
  245.95 +    </ClCompile>
  245.96 +    <ClCompile Include="CPP\7zip\Archive\7z\7zFolderOutStream.cpp">
  245.97 +      <Filter>Archive\7z</Filter>
  245.98 +    </ClCompile>
  245.99 +    <ClCompile Include="CPP\7zip\Archive\7z\7zHandler.cpp">
 245.100 +      <Filter>Archive\7z</Filter>
 245.101 +    </ClCompile>
 245.102 +    <ClCompile Include="CPP\7zip\Archive\7z\7zHeader.cpp">
 245.103 +      <Filter>Archive\7z</Filter>
 245.104 +    </ClCompile>
 245.105 +    <ClCompile Include="CPP\7zip\Archive\7z\7zIn.cpp">
 245.106 +      <Filter>Archive\7z</Filter>
 245.107 +    </ClCompile>
 245.108 +    <ClCompile Include="CPP\7zip\Archive\7z\7zProperties.cpp">
 245.109 +      <Filter>Archive\7z</Filter>
 245.110 +    </ClCompile>
 245.111 +    <ClCompile Include="CPP\7zip\Archive\7z\7zRegister.cpp">
 245.112 +      <Filter>Register</Filter>
 245.113 +    </ClCompile>
 245.114 +    <ClCompile Include="CPP\7zip\Archive\7z\7zSpecStream.cpp">
 245.115 +      <Filter>Archive\7z</Filter>
 245.116 +    </ClCompile>
 245.117 +    <ClCompile Include="CPP\7zip\Archive\ArchiveExports.cpp">
 245.118 +      <Filter>Register</Filter>
 245.119 +    </ClCompile>
 245.120 +    <ClCompile Include="CPP\7zip\Archive\BZip2\bz2Register.cpp">
 245.121 +      <Filter>Register</Filter>
 245.122 +    </ClCompile>
 245.123 +    <ClCompile Include="CPP\7zip\Archive\BZip2\BZip2Handler.cpp">
 245.124 +      <Filter>Archive\bz2</Filter>
 245.125 +    </ClCompile>
 245.126 +    <ClCompile Include="CPP\7zip\Archive\Common\CoderMixer2.cpp">
 245.127 +      <Filter>Archive\Archive common</Filter>
 245.128 +    </ClCompile>
 245.129 +    <ClCompile Include="CPP\7zip\Archive\Common\CoderMixer2MT.cpp">
 245.130 +      <Filter>Archive\Archive common</Filter>
 245.131 +    </ClCompile>
 245.132 +    <ClCompile Include="CPP\7zip\Archive\Common\DummyOutStream.cpp">
 245.133 +      <Filter>Archive\Archive common</Filter>
 245.134 +    </ClCompile>
 245.135 +    <ClCompile Include="CPP\7zip\Archive\Common\FindSignature.cpp">
 245.136 +      <Filter>Archive\Archive common</Filter>
 245.137 +    </ClCompile>
 245.138 +    <ClCompile Include="CPP\7zip\Archive\Common\InStreamWithCRC.cpp">
 245.139 +      <Filter>Archive\Archive common</Filter>
 245.140 +    </ClCompile>
 245.141 +    <ClCompile Include="CPP\7zip\Archive\Common\ItemNameUtils.cpp">
 245.142 +      <Filter>Archive\Archive common</Filter>
 245.143 +    </ClCompile>
 245.144 +    <ClCompile Include="CPP\7zip\Archive\Common\MultiStream.cpp">
 245.145 +      <Filter>Archive\Archive common</Filter>
 245.146 +    </ClCompile>
 245.147 +    <ClCompile Include="CPP\7zip\Archive\Common\OutStreamWithCRC.cpp">
 245.148 +      <Filter>Archive\Archive common</Filter>
 245.149 +    </ClCompile>
 245.150 +    <ClCompile Include="CPP\7zip\Archive\Common\ParseProperties.cpp">
 245.151 +      <Filter>Archive\Archive common</Filter>
 245.152 +    </ClCompile>
 245.153 +    <ClCompile Include="CPP\7zip\Archive\DllExports2.cpp">
 245.154 +      <Filter>Register</Filter>
 245.155 +    </ClCompile>
 245.156 +    <ClCompile Include="CPP\7zip\Archive\GZip\GZipHandler.cpp">
 245.157 +      <Filter>Archive\GZip</Filter>
 245.158 +    </ClCompile>
 245.159 +    <ClCompile Include="CPP\7zip\Archive\GZip\GZipHeader.cpp">
 245.160 +      <Filter>Archive\GZip</Filter>
 245.161 +    </ClCompile>
 245.162 +    <ClCompile Include="CPP\7zip\Archive\GZip\GZipIn.cpp">
 245.163 +      <Filter>Archive\GZip</Filter>
 245.164 +    </ClCompile>
 245.165 +    <ClCompile Include="CPP\7zip\Archive\GZip\GZipRegister.cpp">
 245.166 +      <Filter>Register</Filter>
 245.167 +    </ClCompile>
 245.168 +    <ClCompile Include="CPP\7zip\Archive\Lzh\LzhCRC.cpp">
 245.169 +      <Filter>Archive\Lzh</Filter>
 245.170 +    </ClCompile>
 245.171 +    <ClCompile Include="CPP\7zip\Archive\Lzh\LzhHandler.cpp">
 245.172 +      <Filter>Archive\Lzh</Filter>
 245.173 +    </ClCompile>
 245.174 +    <ClCompile Include="CPP\7zip\Archive\Lzh\LzhIn.cpp">
 245.175 +      <Filter>Archive\Lzh</Filter>
 245.176 +    </ClCompile>
 245.177 +    <ClCompile Include="CPP\7zip\Archive\Lzh\LzhOutStreamWithCRC.cpp">
 245.178 +      <Filter>Archive\Lzh</Filter>
 245.179 +    </ClCompile>
 245.180 +    <ClCompile Include="CPP\7zip\Archive\Lzh\LzhRegister.cpp">
 245.181 +      <Filter>Register</Filter>
 245.182 +    </ClCompile>
 245.183 +    <ClCompile Include="CPP\7zip\Archive\Lzma\LzmaArcRegister.cpp">
 245.184 +      <Filter>Register</Filter>
 245.185 +    </ClCompile>
 245.186 +    <ClCompile Include="CPP\7zip\Archive\Lzma\LzmaFiltersDecode.cpp">
 245.187 +      <Filter>Archive\Lzma Ar</Filter>
 245.188 +    </ClCompile>
 245.189 +    <ClCompile Include="CPP\7zip\Archive\Lzma\LzmaHandler.cpp">
 245.190 +      <Filter>Archive\Lzma Ar</Filter>
 245.191 +    </ClCompile>
 245.192 +    <ClCompile Include="CPP\7zip\Archive\Lzma\LzmaIn.cpp">
 245.193 +      <Filter>Archive\Lzma Ar</Filter>
 245.194 +    </ClCompile>
 245.195 +    <ClCompile Include="CPP\7zip\Archive\Rar\RarHandler.cpp">
 245.196 +      <Filter>Archive\Rar</Filter>
 245.197 +    </ClCompile>
 245.198 +    <ClCompile Include="CPP\7zip\Archive\Rar\RarHeader.cpp">
 245.199 +      <Filter>Archive\Rar</Filter>
 245.200 +    </ClCompile>
 245.201 +    <ClCompile Include="CPP\7zip\Archive\Rar\RarIn.cpp">
 245.202 +      <Filter>Archive\Rar</Filter>
 245.203 +    </ClCompile>
 245.204 +    <ClCompile Include="CPP\7zip\Archive\Rar\RarItem.cpp">
 245.205 +      <Filter>Archive\Rar</Filter>
 245.206 +    </ClCompile>
 245.207 +    <ClCompile Include="CPP\7zip\Archive\Rar\RarRegister.cpp">
 245.208 +      <Filter>Register</Filter>
 245.209 +    </ClCompile>
 245.210 +    <ClCompile Include="CPP\7zip\Archive\Rar\RarVolumeInStream.cpp">
 245.211 +      <Filter>Archive\Rar</Filter>
 245.212 +    </ClCompile>
 245.213 +    <ClCompile Include="CPP\7zip\Archive\Split\SplitHandler.cpp">
 245.214 +      <Filter>Archive\Split</Filter>
 245.215 +    </ClCompile>
 245.216 +    <ClCompile Include="CPP\7zip\Archive\Split\SplitRegister.cpp">
 245.217 +      <Filter>Register</Filter>
 245.218 +    </ClCompile>
 245.219 +    <ClCompile Include="CPP\7zip\Archive\Tar\TarHandler.cpp">
 245.220 +      <Filter>Archive\Tar</Filter>
 245.221 +    </ClCompile>
 245.222 +    <ClCompile Include="CPP\7zip\Archive\Tar\TarHeader.cpp">
 245.223 +      <Filter>Archive\Tar</Filter>
 245.224 +    </ClCompile>
 245.225 +    <ClCompile Include="CPP\7zip\Archive\Tar\TarIn.cpp">
 245.226 +      <Filter>Archive\Tar</Filter>
 245.227 +    </ClCompile>
 245.228 +    <ClCompile Include="CPP\7zip\Archive\Tar\TarRegister.cpp">
 245.229 +      <Filter>Register</Filter>
 245.230 +    </ClCompile>
 245.231 +    <ClCompile Include="CPP\7zip\Archive\Zip\ZipHandler.cpp">
 245.232 +      <Filter>Archive\Zip</Filter>
 245.233 +    </ClCompile>
 245.234 +    <ClCompile Include="CPP\7zip\Archive\Zip\ZipHeader.cpp">
 245.235 +      <Filter>Archive\Zip</Filter>
 245.236 +    </ClCompile>
 245.237 +    <ClCompile Include="CPP\7zip\Archive\Zip\ZipIn.cpp">
 245.238 +      <Filter>Archive\Zip</Filter>
 245.239 +    </ClCompile>
 245.240 +    <ClCompile Include="CPP\7zip\Archive\Zip\ZipItem.cpp">
 245.241 +      <Filter>Archive\Zip</Filter>
 245.242 +    </ClCompile>
 245.243 +    <ClCompile Include="CPP\7zip\Archive\Zip\ZipRegister.cpp">
 245.244 +      <Filter>Register</Filter>
 245.245 +    </ClCompile>
 245.246 +    <ClCompile Include="CPP\7zip\Common\CreateCoder.cpp">
 245.247 +      <Filter>Register</Filter>
 245.248 +    </ClCompile>
 245.249 +    <ClCompile Include="CPP\7zip\Common\FilterCoder.cpp">
 245.250 +      <Filter>7zip</Filter>
 245.251 +    </ClCompile>
 245.252 +    <ClCompile Include="CPP\7zip\Common\InBuffer.cpp">
 245.253 +      <Filter>7zip</Filter>
 245.254 +    </ClCompile>
 245.255 +    <ClCompile Include="CPP\7zip\Common\InOutTempBuffer.cpp">
 245.256 +      <Filter>7zip</Filter>
 245.257 +    </ClCompile>
 245.258 +    <ClCompile Include="CPP\7zip\Common\LimitedStreams.cpp">
 245.259 +      <Filter>7zip</Filter>
 245.260 +    </ClCompile>
 245.261 +    <ClCompile Include="CPP\7zip\Common\LockedStream.cpp">
 245.262 +      <Filter>7zip</Filter>
 245.263 +    </ClCompile>
 245.264 +    <ClCompile Include="CPP\7zip\Common\MemBlocks.cpp">
 245.265 +      <Filter>7zip</Filter>
 245.266 +    </ClCompile>
 245.267 +    <ClCompile Include="CPP\7zip\Common\MethodId.cpp">
 245.268 +      <Filter>7zip</Filter>
 245.269 +    </ClCompile>
 245.270 +    <ClCompile Include="CPP\7zip\Common\MethodProps.cpp">
 245.271 +      <Filter>7zip</Filter>
 245.272 +    </ClCompile>
 245.273 +    <ClCompile Include="CPP\7zip\Common\OffsetStream.cpp">
 245.274 +      <Filter>7zip</Filter>
 245.275 +    </ClCompile>
 245.276 +    <ClCompile Include="CPP\7zip\Common\OutBuffer.cpp">
 245.277 +      <Filter>7zip</Filter>
 245.278 +    </ClCompile>
 245.279 +    <ClCompile Include="CPP\7zip\Common\OutMemStream.cpp">
 245.280 +      <Filter>7zip</Filter>
 245.281 +    </ClCompile>
 245.282 +    <ClCompile Include="CPP\7zip\Common\ProgressMt.cpp">
 245.283 +      <Filter>7zip</Filter>
 245.284 +    </ClCompile>
 245.285 +    <ClCompile Include="CPP\7zip\Common\ProgressUtils.cpp">
 245.286 +      <Filter>7zip</Filter>
 245.287 +    </ClCompile>
 245.288 +    <ClCompile Include="CPP\7zip\Common\StreamBinder.cpp">
 245.289 +      <Filter>7zip</Filter>
 245.290 +    </ClCompile>
 245.291 +    <ClCompile Include="CPP\7zip\Common\StreamObjects.cpp">
 245.292 +      <Filter>7zip</Filter>
 245.293 +    </ClCompile>
 245.294 +    <ClCompile Include="CPP\7zip\Common\StreamUtils.cpp">
 245.295 +      <Filter>7zip</Filter>
 245.296 +    </ClCompile>
 245.297 +    <ClCompile Include="CPP\7zip\Common\VirtThread.cpp">
 245.298 +      <Filter>7zip</Filter>
 245.299 +    </ClCompile>
 245.300 +    <ClCompile Include="CPP\7zip\Compress\Bcj2Coder.cpp">
 245.301 +      <Filter>Compress\7z Compress</Filter>
 245.302 +    </ClCompile>
 245.303 +    <ClCompile Include="CPP\7zip\Compress\Bcj2Register.cpp">
 245.304 +      <Filter>Register</Filter>
 245.305 +    </ClCompile>
 245.306 +    <ClCompile Include="CPP\7zip\Compress\BcjCoder.cpp">
 245.307 +      <Filter>Compress\7z Compress</Filter>
 245.308 +    </ClCompile>
 245.309 +    <ClCompile Include="CPP\7zip\Compress\BcjRegister.cpp">
 245.310 +      <Filter>Register</Filter>
 245.311 +    </ClCompile>
 245.312 +    <ClCompile Include="CPP\7zip\Compress\BitlDecoder.cpp">
 245.313 +      <Filter>Compress\Bit Coder</Filter>
 245.314 +    </ClCompile>
 245.315 +    <ClCompile Include="CPP\7zip\Compress\BranchCoder.cpp">
 245.316 +      <Filter>Compress\7z Compress</Filter>
 245.317 +    </ClCompile>
 245.318 +    <ClCompile Include="CPP\7zip\Compress\BranchMisc.cpp">
 245.319 +      <Filter>Compress\7z Compress</Filter>
 245.320 +    </ClCompile>
 245.321 +    <ClCompile Include="CPP\7zip\Compress\BranchRegister.cpp">
 245.322 +      <Filter>Register</Filter>
 245.323 +    </ClCompile>
 245.324 +    <ClCompile Include="CPP\7zip\Compress\ByteSwap.cpp">
 245.325 +      <Filter>Compress\7z Compress</Filter>
 245.326 +    </ClCompile>
 245.327 +    <ClCompile Include="CPP\7zip\Compress\ByteSwapRegister.cpp">
 245.328 +      <Filter>Register</Filter>
 245.329 +    </ClCompile>
 245.330 +    <ClCompile Include="CPP\7zip\Compress\BZip2Crc.cpp">
 245.331 +      <Filter>Compress\BZip2 Compress</Filter>
 245.332 +    </ClCompile>
 245.333 +    <ClCompile Include="CPP\7zip\Compress\BZip2Decoder.cpp">
 245.334 +      <Filter>Compress\BZip2 Compress</Filter>
 245.335 +    </ClCompile>
 245.336 +    <ClCompile Include="CPP\7zip\Compress\BZip2Register.cpp">
 245.337 +      <Filter>Register</Filter>
 245.338 +    </ClCompile>
 245.339 +    <ClCompile Include="CPP\7zip\Compress\CodecExports.cpp">
 245.340 +      <Filter>Register</Filter>
 245.341 +    </ClCompile>
 245.342 +    <ClCompile Include="CPP\7zip\Compress\CopyCoder.cpp">
 245.343 +      <Filter>Compress\7z Compress</Filter>
 245.344 +    </ClCompile>
 245.345 +    <ClCompile Include="CPP\7zip\Compress\CopyRegister.cpp">
 245.346 +      <Filter>Register</Filter>
 245.347 +    </ClCompile>
 245.348 +    <ClCompile Include="CPP\7zip\Compress\Deflate64Register.cpp">
 245.349 +      <Filter>Register</Filter>
 245.350 +    </ClCompile>
 245.351 +    <ClCompile Include="CPP\7zip\Compress\DeflateDecoder.cpp">
 245.352 +      <Filter>Compress\Zip Compress</Filter>
 245.353 +    </ClCompile>
 245.354 +    <ClCompile Include="CPP\7zip\Compress\DeflateNsisRegister.cpp">
 245.355 +      <Filter>Register</Filter>
 245.356 +    </ClCompile>
 245.357 +    <ClCompile Include="CPP\7zip\Compress\DeflateRegister.cpp">
 245.358 +      <Filter>Register</Filter>
 245.359 +    </ClCompile>
 245.360 +    <ClCompile Include="CPP\7zip\Compress\ImplodeDecoder.cpp">
 245.361 +      <Filter>Compress\Zip Compress</Filter>
 245.362 +    </ClCompile>
 245.363 +    <ClCompile Include="CPP\7zip\Compress\ImplodeHuffmanDecoder.cpp">
 245.364 +      <Filter>Compress\Zip Compress</Filter>
 245.365 +    </ClCompile>
 245.366 +    <ClCompile Include="CPP\7zip\Compress\LzhDecoder.cpp">
 245.367 +      <Filter>Compress</Filter>
 245.368 +    </ClCompile>
 245.369 +    <ClCompile Include="CPP\7zip\Compress\LzmaDecoder.cpp">
 245.370 +      <Filter>Compress\7z Compress</Filter>
 245.371 +    </ClCompile>
 245.372 +    <ClCompile Include="CPP\7zip\Compress\LzmaRegister.cpp">
 245.373 +      <Filter>Register</Filter>
 245.374 +    </ClCompile>
 245.375 +    <ClCompile Include="CPP\7zip\Compress\LzOutWindow.cpp">
 245.376 +      <Filter>Compress</Filter>
 245.377 +    </ClCompile>
 245.378 +    <ClCompile Include="CPP\7zip\Compress\PpmdDecoder.cpp">
 245.379 +      <Filter>Compress\PPMD</Filter>
 245.380 +    </ClCompile>
 245.381 +    <ClCompile Include="CPP\7zip\Compress\PpmdRegister.cpp">
 245.382 +      <Filter>Register</Filter>
 245.383 +    </ClCompile>
 245.384 +    <ClCompile Include="CPP\7zip\Compress\Rar1Decoder.cpp">
 245.385 +      <Filter>Compress\Rar Compress</Filter>
 245.386 +    </ClCompile>
 245.387 +    <ClCompile Include="CPP\7zip\Compress\Rar2Decoder.cpp">
 245.388 +      <Filter>Compress\Rar Compress</Filter>
 245.389 +    </ClCompile>
 245.390 +    <ClCompile Include="CPP\7zip\Compress\Rar3Decoder.cpp">
 245.391 +      <Filter>Compress\Rar Compress</Filter>
 245.392 +    </ClCompile>
 245.393 +    <ClCompile Include="CPP\7zip\Compress\Rar3Vm.cpp">
 245.394 +      <Filter>Compress\Rar Compress</Filter>
 245.395 +    </ClCompile>
 245.396 +    <ClCompile Include="CPP\7zip\Compress\RarCodecsRegister.cpp">
 245.397 +      <Filter>Register</Filter>
 245.398 +    </ClCompile>
 245.399 +    <ClCompile Include="CPP\7zip\Compress\ShrinkDecoder.cpp">
 245.400 +      <Filter>Compress\Zip Compress</Filter>
 245.401 +    </ClCompile>
 245.402 +    <ClCompile Include="CPP\7zip\Compress\ZlibDecoder.cpp">
 245.403 +      <Filter>Compress\Zip Compress</Filter>
 245.404 +    </ClCompile>
 245.405 +    <ClCompile Include="CPP\7zip\Crypto\7zAes.cpp">
 245.406 +      <Filter>Crypto</Filter>
 245.407 +    </ClCompile>
 245.408 +    <ClCompile Include="CPP\7zip\Crypto\7zAesRegister.cpp">
 245.409 +      <Filter>Register</Filter>
 245.410 +    </ClCompile>
 245.411 +    <ClCompile Include="CPP\7zip\Crypto\HmacSha1.cpp">
 245.412 +      <Filter>Crypto</Filter>
 245.413 +    </ClCompile>
 245.414 +    <ClCompile Include="CPP\7zip\Crypto\MyAes.cpp">
 245.415 +      <Filter>Crypto</Filter>
 245.416 +    </ClCompile>
 245.417 +    <ClCompile Include="CPP\7zip\Crypto\Pbkdf2HmacSha1.cpp">
 245.418 +      <Filter>Crypto</Filter>
 245.419 +    </ClCompile>
 245.420 +    <ClCompile Include="CPP\7zip\Crypto\RandGen.cpp">
 245.421 +      <Filter>Crypto</Filter>
 245.422 +    </ClCompile>
 245.423 +    <ClCompile Include="CPP\7zip\Crypto\Rar20Crypto.cpp">
 245.424 +      <Filter>Crypto</Filter>
 245.425 +    </ClCompile>
 245.426 +    <ClCompile Include="CPP\7zip\Crypto\RarAes.cpp">
 245.427 +      <Filter>Crypto</Filter>
 245.428 +    </ClCompile>
 245.429 +    <ClCompile Include="CPP\7zip\Crypto\Sha1.cpp">
 245.430 +      <Filter>Crypto</Filter>
 245.431 +    </ClCompile>
 245.432 +    <ClCompile Include="CPP\7zip\Crypto\WzAes.cpp">
 245.433 +      <Filter>Crypto</Filter>
 245.434 +    </ClCompile>
 245.435 +    <ClCompile Include="CPP\7zip\Crypto\ZipCrypto.cpp">
 245.436 +      <Filter>Crypto</Filter>
 245.437 +    </ClCompile>
 245.438 +    <ClCompile Include="CPP\7zip\Crypto\ZipStrong.cpp">
 245.439 +      <Filter>Crypto</Filter>
 245.440 +    </ClCompile>
 245.441 +    <ClCompile Include="CPP\Common\CRC.cpp">
 245.442 +      <Filter>Common</Filter>
 245.443 +    </ClCompile>
 245.444 +    <ClCompile Include="CPP\Common\IntToString.cpp">
 245.445 +      <Filter>Common</Filter>
 245.446 +    </ClCompile>
 245.447 +    <ClCompile Include="CPP\Common\MyMap.cpp">
 245.448 +      <Filter>Common</Filter>
 245.449 +    </ClCompile>
 245.450 +    <ClCompile Include="CPP\Common\MyString.cpp">
 245.451 +      <Filter>Common</Filter>
 245.452 +    </ClCompile>
 245.453 +    <ClCompile Include="CPP\Common\MyVector.cpp">
 245.454 +      <Filter>Common</Filter>
 245.455 +    </ClCompile>
 245.456 +    <ClCompile Include="CPP\Common\MyXml.cpp">
 245.457 +      <Filter>Common</Filter>
 245.458 +    </ClCompile>
 245.459 +    <ClCompile Include="CPP\Common\NewHandler.cpp">
 245.460 +      <Filter>Common</Filter>
 245.461 +    </ClCompile>
 245.462 +    <ClCompile Include="CPP\Common\StringConvert.cpp">
 245.463 +      <Filter>Common</Filter>
 245.464 +    </ClCompile>
 245.465 +    <ClCompile Include="CPP\Common\StringToInt.cpp">
 245.466 +      <Filter>Common</Filter>
 245.467 +    </ClCompile>
 245.468 +    <ClCompile Include="CPP\Common\UTFConvert.cpp">
 245.469 +      <Filter>Common</Filter>
 245.470 +    </ClCompile>
 245.471 +    <ClCompile Include="CPP\Common\Wildcard.cpp">
 245.472 +      <Filter>Common</Filter>
 245.473 +    </ClCompile>
 245.474 +    <ClCompile Include="CPP\Windows\FileDir.cpp">
 245.475 +      <Filter>Windows</Filter>
 245.476 +    </ClCompile>
 245.477 +    <ClCompile Include="CPP\Windows\FileFind.cpp">
 245.478 +      <Filter>Windows</Filter>
 245.479 +    </ClCompile>
 245.480 +    <ClCompile Include="CPP\Windows\FileIO.cpp">
 245.481 +      <Filter>Windows</Filter>
 245.482 +    </ClCompile>
 245.483 +    <ClCompile Include="CPP\Windows\PropVariant.cpp">
 245.484 +      <Filter>Windows</Filter>
 245.485 +    </ClCompile>
 245.486 +    <ClCompile Include="CPP\Windows\Time.cpp">
 245.487 +      <Filter>Windows</Filter>
 245.488 +    </ClCompile>
 245.489 +    <ClCompile Include="C\7zCrc.c">
 245.490 +      <Filter>C</Filter>
 245.491 +    </ClCompile>
 245.492 +    <ClCompile Include="C\Aes.c">
 245.493 +      <Filter>C</Filter>
 245.494 +    </ClCompile>
 245.495 +    <ClCompile Include="C\Alloc.c">
 245.496 +      <Filter>C</Filter>
 245.497 +    </ClCompile>
 245.498 +    <ClCompile Include="C\Bra.c">
 245.499 +      <Filter>C</Filter>
 245.500 +    </ClCompile>
 245.501 +    <ClCompile Include="C\Bra86.c">
 245.502 +      <Filter>C</Filter>
 245.503 +    </ClCompile>
 245.504 +    <ClCompile Include="C\BraIA64.c">
 245.505 +      <Filter>C</Filter>
 245.506 +    </ClCompile>
 245.507 +    <ClCompile Include="C\BwtSort.c">
 245.508 +      <Filter>C</Filter>
 245.509 +    </ClCompile>
 245.510 +    <ClCompile Include="C\HuffEnc.c">
 245.511 +      <Filter>C</Filter>
 245.512 +    </ClCompile>
 245.513 +    <ClCompile Include="C\LzFind.c">
 245.514 +      <Filter>C</Filter>
 245.515 +    </ClCompile>
 245.516 +    <ClCompile Include="C\LzFindMt.c">
 245.517 +      <Filter>C</Filter>
 245.518 +    </ClCompile>
 245.519 +    <ClCompile Include="C\LzmaDec.c">
 245.520 +      <Filter>C</Filter>
 245.521 +    </ClCompile>
 245.522 +    <ClCompile Include="C\LzmaEnc.c">
 245.523 +      <Filter>C</Filter>
 245.524 +    </ClCompile>
 245.525 +    <ClCompile Include="C\Sha256.c">
 245.526 +      <Filter>C</Filter>
 245.527 +    </ClCompile>
 245.528 +    <ClCompile Include="C\Sort.c">
 245.529 +      <Filter>C</Filter>
 245.530 +    </ClCompile>
 245.531 +    <ClCompile Include="C\Threads.c">
 245.532 +      <Filter>C</Filter>
 245.533 +    </ClCompile>
 245.534 +  </ItemGroup>
 245.535 +  <ItemGroup>
 245.536 +    <ClInclude Include="CPP\7zip\Archive\7z\7zCompressionMode.h">
 245.537 +      <Filter>Headers</Filter>
 245.538 +    </ClInclude>
 245.539 +    <ClInclude Include="CPP\7zip\Archive\7z\7zDecode.h">
 245.540 +      <Filter>Headers</Filter>
 245.541 +    </ClInclude>
 245.542 +    <ClInclude Include="CPP\7zip\Archive\7z\7zFolderInStream.h">
 245.543 +      <Filter>Headers</Filter>
 245.544 +    </ClInclude>
 245.545 +    <ClInclude Include="CPP\7zip\Archive\7z\7zFolderOutStream.h">
 245.546 +      <Filter>Headers</Filter>
 245.547 +    </ClInclude>
 245.548 +    <ClInclude Include="CPP\7zip\Archive\7z\7zHandler.h">
 245.549 +      <Filter>Headers</Filter>
 245.550 +    </ClInclude>
 245.551 +    <ClInclude Include="CPP\7zip\Archive\7z\7zHeader.h">
 245.552 +      <Filter>Headers</Filter>
 245.553 +    </ClInclude>
 245.554 +    <ClInclude Include="CPP\7zip\Archive\7z\7zIn.h">
 245.555 +      <Filter>Headers</Filter>
 245.556 +    </ClInclude>
 245.557 +    <ClInclude Include="CPP\7zip\Archive\7z\7zItem.h">
 245.558 +      <Filter>Headers</Filter>
 245.559 +    </ClInclude>
 245.560 +    <ClInclude Include="CPP\7zip\Archive\7z\7zProperties.h">
 245.561 +      <Filter>Headers</Filter>
 245.562 +    </ClInclude>
 245.563 +    <ClInclude Include="CPP\7zip\Archive\7z\7zSpecStream.h">
 245.564 +      <Filter>Headers</Filter>
 245.565 +    </ClInclude>
 245.566 +    <ClInclude Include="CPP\7zip\Archive\7z\StdAfx.h">
 245.567 +      <Filter>Headers</Filter>
 245.568 +    </ClInclude>
 245.569 +    <ClInclude Include="CPP\7zip\Archive\BZip2\BZip2Handler.h">
 245.570 +      <Filter>Headers</Filter>
 245.571 +    </ClInclude>
 245.572 +    <ClInclude Include="CPP\7zip\Archive\BZip2\BZip2Item.h">
 245.573 +      <Filter>Headers</Filter>
 245.574 +    </ClInclude>
 245.575 +    <ClInclude Include="CPP\7zip\Archive\BZip2\StdAfx.h">
 245.576 +      <Filter>Headers</Filter>
 245.577 +    </ClInclude>
 245.578 +    <ClInclude Include="CPP\7zip\Archive\Common\CoderMixer2.h">
 245.579 +      <Filter>Headers</Filter>
 245.580 +    </ClInclude>
 245.581 +    <ClInclude Include="CPP\7zip\Archive\Common\CoderMixer2MT.h">
 245.582 +      <Filter>Headers</Filter>
 245.583 +    </ClInclude>
 245.584 +    <ClInclude Include="CPP\7zip\Archive\Common\DummyOutStream.h">
 245.585 +      <Filter>Headers</Filter>
 245.586 +    </ClInclude>
 245.587 +    <ClInclude Include="CPP\7zip\Archive\Common\FindSignature.h">
 245.588 +      <Filter>Headers</Filter>
 245.589 +    </ClInclude>
 245.590 +    <ClInclude Include="CPP\7zip\Archive\Common\InStreamWithCRC.h">
 245.591 +      <Filter>Headers</Filter>
 245.592 +    </ClInclude>
 245.593 +    <ClInclude Include="CPP\7zip\Archive\Common\ItemNameUtils.h">
 245.594 +      <Filter>Headers</Filter>
 245.595 +    </ClInclude>
 245.596 +    <ClInclude Include="CPP\7zip\Archive\Common\MultiStream.h">
 245.597 +      <Filter>Headers</Filter>
 245.598 +    </ClInclude>
 245.599 +    <ClInclude Include="CPP\7zip\Archive\Common\OutStreamWithCRC.h">
 245.600 +      <Filter>Headers</Filter>
 245.601 +    </ClInclude>
 245.602 +    <ClInclude Include="CPP\7zip\Archive\Common\ParseProperties.h">
 245.603 +      <Filter>Headers</Filter>
 245.604 +    </ClInclude>
 245.605 +    <ClInclude Include="CPP\7zip\Archive\Common\StdAfx.h">
 245.606 +      <Filter>Headers</Filter>
 245.607 +    </ClInclude>
 245.608 +    <ClInclude Include="CPP\7zip\Archive\GZip\GZipHandler.h">
 245.609 +      <Filter>Headers</Filter>
 245.610 +    </ClInclude>
 245.611 +    <ClInclude Include="CPP\7zip\Archive\GZip\GZipHeader.h">
 245.612 +      <Filter>Headers</Filter>
 245.613 +    </ClInclude>
 245.614 +    <ClInclude Include="CPP\7zip\Archive\GZip\GZipIn.h">
 245.615 +      <Filter>Headers</Filter>
 245.616 +    </ClInclude>
 245.617 +    <ClInclude Include="CPP\7zip\Archive\GZip\GZipItem.h">
 245.618 +      <Filter>Headers</Filter>
 245.619 +    </ClInclude>
 245.620 +    <ClInclude Include="CPP\7zip\Archive\GZip\GZipUpdate.h">
 245.621 +      <Filter>Headers</Filter>
 245.622 +    </ClInclude>
 245.623 +    <ClInclude Include="CPP\7zip\Archive\GZip\StdAfx.h">
 245.624 +      <Filter>Headers</Filter>
 245.625 +    </ClInclude>
 245.626 +    <ClInclude Include="CPP\7zip\Archive\IArchive.h">
 245.627 +      <Filter>Headers</Filter>
 245.628 +    </ClInclude>
 245.629 +    <ClInclude Include="CPP\7zip\Archive\Lzh\LzhCRC.h">
 245.630 +      <Filter>Headers</Filter>
 245.631 +    </ClInclude>
 245.632 +    <ClInclude Include="CPP\7zip\Archive\Lzh\LzhHandler.h">
 245.633 +      <Filter>Headers</Filter>
 245.634 +    </ClInclude>
 245.635 +    <ClInclude Include="CPP\7zip\Archive\Lzh\LzhHeader.h">
 245.636 +      <Filter>Headers</Filter>
 245.637 +    </ClInclude>
 245.638 +    <ClInclude Include="CPP\7zip\Archive\Lzh\LzhIn.h">
 245.639 +      <Filter>Headers</Filter>
 245.640 +    </ClInclude>
 245.641 +    <ClInclude Include="CPP\7zip\Archive\Lzh\LzhItem.h">
 245.642 +      <Filter>Headers</Filter>
 245.643 +    </ClInclude>
 245.644 +    <ClInclude Include="CPP\7zip\Archive\Lzh\LzhOutStreamWithCRC.h">
 245.645 +      <Filter>Headers</Filter>
 245.646 +    </ClInclude>
 245.647 +    <ClInclude Include="CPP\7zip\Archive\Lzh\StdAfx.h">
 245.648 +      <Filter>Headers</Filter>
 245.649 +    </ClInclude>
 245.650 +    <ClInclude Include="CPP\7zip\Archive\Lzma\LzmaFiltersDecode.h">
 245.651 +      <Filter>Headers</Filter>
 245.652 +    </ClInclude>
 245.653 +    <ClInclude Include="CPP\7zip\Archive\Lzma\LzmaHandler.h">
 245.654 +      <Filter>Headers</Filter>
 245.655 +    </ClInclude>
 245.656 +    <ClInclude Include="CPP\7zip\Archive\Lzma\LzmaIn.h">
 245.657 +      <Filter>Headers</Filter>
 245.658 +    </ClInclude>
 245.659 +    <ClInclude Include="CPP\7zip\Archive\Lzma\LzmaItem.h">
 245.660 +      <Filter>Headers</Filter>
 245.661 +    </ClInclude>
 245.662 +    <ClInclude Include="CPP\7zip\Archive\Lzma\StdAfx.h">
 245.663 +      <Filter>Headers</Filter>
 245.664 +    </ClInclude>
 245.665 +    <ClInclude Include="CPP\7zip\Archive\Rar\RarHandler.h">
 245.666 +      <Filter>Headers</Filter>
 245.667 +    </ClInclude>
 245.668 +    <ClInclude Include="CPP\7zip\Archive\Rar\RarHeader.h">
 245.669 +      <Filter>Headers</Filter>
 245.670 +    </ClInclude>
 245.671 +    <ClInclude Include="CPP\7zip\Archive\Rar\RarIn.h">
 245.672 +      <Filter>Headers</Filter>
 245.673 +    </ClInclude>
 245.674 +    <ClInclude Include="CPP\7zip\Archive\Rar\RarItem.h">
 245.675 +      <Filter>Headers</Filter>
 245.676 +    </ClInclude>
 245.677 +    <ClInclude Include="CPP\7zip\Archive\Rar\RarVolumeInStream.h">
 245.678 +      <Filter>Headers</Filter>
 245.679 +    </ClInclude>
 245.680 +    <ClInclude Include="CPP\7zip\Archive\Rar\StdAfx.h">
 245.681 +      <Filter>Headers</Filter>
 245.682 +    </ClInclude>
 245.683 +    <ClInclude Include="CPP\7zip\Archive\Split\SplitHandler.h">
 245.684 +      <Filter>Headers</Filter>
 245.685 +    </ClInclude>
 245.686 +    <ClInclude Include="CPP\7zip\Archive\Split\StdAfx.h">
 245.687 +      <Filter>Headers</Filter>
 245.688 +    </ClInclude>
 245.689 +    <ClInclude Include="CPP\7zip\Archive\StdAfx.h">
 245.690 +      <Filter>Headers</Filter>
 245.691 +    </ClInclude>
 245.692 +    <ClInclude Include="CPP\7zip\Archive\Tar\StdAfx.h">
 245.693 +      <Filter>Headers</Filter>
 245.694 +    </ClInclude>
 245.695 +    <ClInclude Include="CPP\7zip\Archive\Tar\TarHandler.h">
 245.696 +      <Filter>Headers</Filter>
 245.697 +    </ClInclude>
 245.698 +    <ClInclude Include="CPP\7zip\Archive\Tar\TarHeader.h">
 245.699 +      <Filter>Headers</Filter>
 245.700 +    </ClInclude>
 245.701 +    <ClInclude Include="CPP\7zip\Archive\Tar\TarIn.h">
 245.702 +      <Filter>Headers</Filter>
 245.703 +    </ClInclude>
 245.704 +    <ClInclude Include="CPP\7zip\Archive\Tar\TarItem.h">
 245.705 +      <Filter>Headers</Filter>
 245.706 +    </ClInclude>
 245.707 +    <ClInclude Include="CPP\7zip\Archive\Zip\StdAfx.h">
 245.708 +      <Filter>Headers</Filter>
 245.709 +    </ClInclude>
 245.710 +    <ClInclude Include="CPP\7zip\Archive\Zip\ZipCompressionMode.h">
 245.711 +      <Filter>Headers</Filter>
 245.712 +    </ClInclude>
 245.713 +    <ClInclude Include="CPP\7zip\Archive\Zip\ZipHandler.h">
 245.714 +      <Filter>Headers</Filter>
 245.715 +    </ClInclude>
 245.716 +    <ClInclude Include="CPP\7zip\Archive\Zip\ZipHeader.h">
 245.717 +      <Filter>Headers</Filter>
 245.718 +    </ClInclude>
 245.719 +    <ClInclude Include="CPP\7zip\Archive\Zip\ZipIn.h">
 245.720 +      <Filter>Headers</Filter>
 245.721 +    </ClInclude>
 245.722 +    <ClInclude Include="CPP\7zip\Archive\Zip\ZipItem.h">
 245.723 +      <Filter>Headers</Filter>
 245.724 +    </ClInclude>
 245.725 +    <ClInclude Include="CPP\7zip\Archive\Zip\ZipItemEx.h">
 245.726 +      <Filter>Headers</Filter>
 245.727 +    </ClInclude>
 245.728 +    <ClInclude Include="CPP\7zip\Bundles\Format7zF\StdAfx.h">
 245.729 +      <Filter>Headers</Filter>
 245.730 +    </ClInclude>
 245.731 +    <ClInclude Include="CPP\7zip\Common\CreateCoder.h">
 245.732 +      <Filter>Headers</Filter>
 245.733 +    </ClInclude>
 245.734 +    <ClInclude Include="CPP\7zip\Common\DeclareArcs.h">
 245.735 +      <Filter>Headers</Filter>
 245.736 +    </ClInclude>
 245.737 +    <ClInclude Include="CPP\7zip\Common\DeclareCodecs.h">
 245.738 +      <Filter>Headers</Filter>
 245.739 +    </ClInclude>
 245.740 +    <ClInclude Include="CPP\7zip\Common\FilterCoder.h">
 245.741 +      <Filter>Headers</Filter>
 245.742 +    </ClInclude>
 245.743 +    <ClInclude Include="CPP\7zip\Common\InBuffer.h">
 245.744 +      <Filter>Headers</Filter>
 245.745 +    </ClInclude>
 245.746 +    <ClInclude Include="CPP\7zip\Common\InOutTempBuffer.h">
 245.747 +      <Filter>Headers</Filter>
 245.748 +    </ClInclude>
 245.749 +    <ClInclude Include="CPP\7zip\Common\LimitedStreams.h">
 245.750 +      <Filter>Headers</Filter>
 245.751 +    </ClInclude>
 245.752 +    <ClInclude Include="CPP\7zip\Common\LockedStream.h">
 245.753 +      <Filter>Headers</Filter>
 245.754 +    </ClInclude>
 245.755 +    <ClInclude Include="CPP\7zip\Common\MemBlocks.h">
 245.756 +      <Filter>Headers</Filter>
 245.757 +    </ClInclude>
 245.758 +    <ClInclude Include="CPP\7zip\Common\MethodId.h">
 245.759 +      <Filter>Headers</Filter>
 245.760 +    </ClInclude>
 245.761 +    <ClInclude Include="CPP\7zip\Common\MethodProps.h">
 245.762 +      <Filter>Headers</Filter>
 245.763 +    </ClInclude>
 245.764 +    <ClInclude Include="CPP\7zip\Common\OffsetStream.h">
 245.765 +      <Filter>Headers</Filter>
 245.766 +    </ClInclude>
 245.767 +    <ClInclude Include="CPP\7zip\Common\OutBuffer.h">
 245.768 +      <Filter>Headers</Filter>
 245.769 +    </ClInclude>
 245.770 +    <ClInclude Include="CPP\7zip\Common\OutMemStream.h">
 245.771 +      <Filter>Headers</Filter>
 245.772 +    </ClInclude>
 245.773 +    <ClInclude Include="CPP\7zip\Common\ProgressMt.h">
 245.774 +      <Filter>Headers</Filter>
 245.775 +    </ClInclude>
 245.776 +    <ClInclude Include="CPP\7zip\Common\ProgressUtils.h">
 245.777 +      <Filter>Headers</Filter>
 245.778 +    </ClInclude>
 245.779 +    <ClInclude Include="CPP\7zip\Common\RegisterArc.h">
 245.780 +      <Filter>Headers</Filter>
 245.781 +    </ClInclude>
 245.782 +    <ClInclude Include="CPP\7zip\Common\RegisterCodec.h">
 245.783 +      <Filter>Headers</Filter>
 245.784 +    </ClInclude>
 245.785 +    <ClInclude Include="CPP\7zip\Common\StdAfx.h">
 245.786 +      <Filter>Headers</Filter>
 245.787 +    </ClInclude>
 245.788 +    <ClInclude Include="CPP\7zip\Common\StreamBinder.h">
 245.789 +      <Filter>Headers</Filter>
 245.790 +    </ClInclude>
 245.791 +    <ClInclude Include="CPP\7zip\Common\StreamObjects.h">
 245.792 +      <Filter>Headers</Filter>
 245.793 +    </ClInclude>
 245.794 +    <ClInclude Include="CPP\7zip\Common\StreamUtils.h">
 245.795 +      <Filter>Headers</Filter>
 245.796 +    </ClInclude>
 245.797 +    <ClInclude Include="CPP\7zip\Common\VirtThread.h">
 245.798 +      <Filter>Headers</Filter>
 245.799 +    </ClInclude>
 245.800 +    <ClInclude Include="CPP\7zip\Compress\Bcj2Coder.h">
 245.801 +      <Filter>Headers</Filter>
 245.802 +    </ClInclude>
 245.803 +    <ClInclude Include="CPP\7zip\Compress\BcjCoder.h">
 245.804 +      <Filter>Headers</Filter>
 245.805 +    </ClInclude>
 245.806 +    <ClInclude Include="CPP\7zip\Compress\BitlDecoder.h">
 245.807 +      <Filter>Headers</Filter>
 245.808 +    </ClInclude>
 245.809 +    <ClInclude Include="CPP\7zip\Compress\BitmDecoder.h">
 245.810 +      <Filter>Headers</Filter>
 245.811 +    </ClInclude>
 245.812 +    <ClInclude Include="CPP\7zip\Compress\BranchCoder.h">
 245.813 +      <Filter>Headers</Filter>
 245.814 +    </ClInclude>
 245.815 +    <ClInclude Include="CPP\7zip\Compress\BranchMisc.h">
 245.816 +      <Filter>Headers</Filter>
 245.817 +    </ClInclude>
 245.818 +    <ClInclude Include="CPP\7zip\Compress\ByteSwap.h">
 245.819 +      <Filter>Headers</Filter>
 245.820 +    </ClInclude>
 245.821 +    <ClInclude Include="CPP\7zip\Compress\BZip2Const.h">
 245.822 +      <Filter>Headers</Filter>
 245.823 +    </ClInclude>
 245.824 +    <ClInclude Include="CPP\7zip\Compress\BZip2Crc.h">
 245.825 +      <Filter>Headers</Filter>
 245.826 +    </ClInclude>
 245.827 +    <ClInclude Include="CPP\7zip\Compress\BZip2Decoder.h">
 245.828 +      <Filter>Headers</Filter>
 245.829 +    </ClInclude>
 245.830 +    <ClInclude Include="CPP\7zip\Compress\CopyCoder.h">
 245.831 +      <Filter>Headers</Filter>
 245.832 +    </ClInclude>
 245.833 +    <ClInclude Include="CPP\7zip\Compress\DeflateConst.h">
 245.834 +      <Filter>Headers</Filter>
 245.835 +    </ClInclude>
 245.836 +    <ClInclude Include="CPP\7zip\Compress\DeflateDecoder.h">
 245.837 +      <Filter>Headers</Filter>
 245.838 +    </ClInclude>
 245.839 +    <ClInclude Include="CPP\7zip\Compress\HuffmanDecoder.h">
 245.840 +      <Filter>Headers</Filter>
 245.841 +    </ClInclude>
 245.842 +    <ClInclude Include="CPP\7zip\Compress\ImplodeDecoder.h">
 245.843 +      <Filter>Headers</Filter>
 245.844 +    </ClInclude>
 245.845 +    <ClInclude Include="CPP\7zip\Compress\ImplodeHuffmanDecoder.h">
 245.846 +      <Filter>Headers</Filter>
 245.847 +    </ClInclude>
 245.848 +    <ClInclude Include="CPP\7zip\Compress\LzhDecoder.h">
 245.849 +      <Filter>Headers</Filter>
 245.850 +    </ClInclude>
 245.851 +    <ClInclude Include="CPP\7zip\Compress\LzmaDecoder.h">
 245.852 +      <Filter>Headers</Filter>
 245.853 +    </ClInclude>
 245.854 +    <ClInclude Include="CPP\7zip\Compress\LzOutWindow.h">
 245.855 +      <Filter>Headers</Filter>
 245.856 +    </ClInclude>
 245.857 +    <ClInclude Include="CPP\7zip\Compress\Mtf8.h">
 245.858 +      <Filter>Headers</Filter>
 245.859 +    </ClInclude>
 245.860 +    <ClInclude Include="CPP\7zip\Compress\PpmdContext.h">
 245.861 +      <Filter>Headers</Filter>
 245.862 +    </ClInclude>
 245.863 +    <ClInclude Include="CPP\7zip\Compress\PpmdDecode.h">
 245.864 +      <Filter>Headers</Filter>
 245.865 +    </ClInclude>
 245.866 +    <ClInclude Include="CPP\7zip\Compress\PpmdDecoder.h">
 245.867 +      <Filter>Headers</Filter>
 245.868 +    </ClInclude>
 245.869 +    <ClInclude Include="CPP\7zip\Compress\PpmdSubAlloc.h">
 245.870 +      <Filter>Headers</Filter>
 245.871 +    </ClInclude>
 245.872 +    <ClInclude Include="CPP\7zip\Compress\PpmdType.h">
 245.873 +      <Filter>Headers</Filter>
 245.874 +    </ClInclude>
 245.875 +    <ClInclude Include="CPP\7zip\Compress\RangeCoder.h">
 245.876 +      <Filter>Headers</Filter>
 245.877 +    </ClInclude>
 245.878 +    <ClInclude Include="CPP\7zip\Compress\RangeCoderBit.h">
 245.879 +      <Filter>Headers</Filter>
 245.880 +    </ClInclude>
 245.881 +    <ClInclude Include="CPP\7zip\Compress\Rar1Decoder.h">
 245.882 +      <Filter>Headers</Filter>
 245.883 +    </ClInclude>
 245.884 +    <ClInclude Include="CPP\7zip\Compress\Rar2Decoder.h">
 245.885 +      <Filter>Headers</Filter>
 245.886 +    </ClInclude>
 245.887 +    <ClInclude Include="CPP\7zip\Compress\Rar3Decoder.h">
 245.888 +      <Filter>Headers</Filter>
 245.889 +    </ClInclude>
 245.890 +    <ClInclude Include="CPP\7zip\Compress\Rar3Vm.h">
 245.891 +      <Filter>Headers</Filter>
 245.892 +    </ClInclude>
 245.893 +    <ClInclude Include="CPP\7zip\Compress\ShrinkDecoder.h">
 245.894 +      <Filter>Headers</Filter>
 245.895 +    </ClInclude>
 245.896 +    <ClInclude Include="CPP\7zip\Compress\StdAfx.h">
 245.897 +      <Filter>Headers</Filter>
 245.898 +    </ClInclude>
 245.899 +    <ClInclude Include="CPP\7zip\Compress\ZlibDecoder.h">
 245.900 +      <Filter>Headers</Filter>
 245.901 +    </ClInclude>
 245.902 +    <ClInclude Include="CPP\7zip\Crypto\7zAes.h">
 245.903 +      <Filter>Headers</Filter>
 245.904 +    </ClInclude>
 245.905 +    <ClInclude Include="CPP\7zip\Crypto\HmacSha1.h">
 245.906 +      <Filter>Headers</Filter>
 245.907 +    </ClInclude>
 245.908 +    <ClInclude Include="CPP\7zip\Crypto\MyAes.h">
 245.909 +      <Filter>Headers</Filter>
 245.910 +    </ClInclude>
 245.911 +    <ClInclude Include="CPP\7zip\Crypto\Pbkdf2HmacSha1.h">
 245.912 +      <Filter>Headers</Filter>
 245.913 +    </ClInclude>
 245.914 +    <ClInclude Include="CPP\7zip\Crypto\RandGen.h">
 245.915 +      <Filter>Headers</Filter>
 245.916 +    </ClInclude>
 245.917 +    <ClInclude Include="CPP\7zip\Crypto\Rar20Crypto.h">
 245.918 +      <Filter>Headers</Filter>
 245.919 +    </ClInclude>
 245.920 +    <ClInclude Include="CPP\7zip\Crypto\RarAes.h">
 245.921 +      <Filter>Headers</Filter>
 245.922 +    </ClInclude>
 245.923 +    <ClInclude Include="CPP\7zip\Crypto\Sha1.h">
 245.924 +      <Filter>Headers</Filter>
 245.925 +    </ClInclude>
 245.926 +    <ClInclude Include="CPP\7zip\Crypto\StdAfx.h">
 245.927 +      <Filter>Headers</Filter>
 245.928 +    </ClInclude>
 245.929 +    <ClInclude Include="CPP\7zip\Crypto\WzAes.h">
 245.930 +      <Filter>Headers</Filter>
 245.931 +    </ClInclude>
 245.932 +    <ClInclude Include="CPP\7zip\Crypto\ZipCrypto.h">
 245.933 +      <Filter>Headers</Filter>
 245.934 +    </ClInclude>
 245.935 +    <ClInclude Include="CPP\7zip\Crypto\ZipStrong.h">
 245.936 +      <Filter>Headers</Filter>
 245.937 +    </ClInclude>
 245.938 +    <ClInclude Include="CPP\7zip\ICoder.h">
 245.939 +      <Filter>Headers</Filter>
 245.940 +    </ClInclude>
 245.941 +    <ClInclude Include="CPP\7zip\IDecl.h">
 245.942 +      <Filter>Headers</Filter>
 245.943 +    </ClInclude>
 245.944 +    <ClInclude Include="CPP\7zip\IPassword.h">
 245.945 +      <Filter>Headers</Filter>
 245.946 +    </ClInclude>
 245.947 +    <ClInclude Include="CPP\7zip\IProgress.h">
 245.948 +      <Filter>Headers</Filter>
 245.949 +    </ClInclude>
 245.950 +    <ClInclude Include="CPP\7zip\IStream.h">
 245.951 +      <Filter>Headers</Filter>
 245.952 +    </ClInclude>
 245.953 +    <ClInclude Include="CPP\7zip\PropID.h">
 245.954 +      <Filter>Headers</Filter>
 245.955 +    </ClInclude>
 245.956 +    <ClInclude Include="CPP\Common\Buffer.h">
 245.957 +      <Filter>Headers</Filter>
 245.958 +    </ClInclude>
 245.959 +    <ClInclude Include="CPP\Common\ComTry.h">
 245.960 +      <Filter>Headers</Filter>
 245.961 +    </ClInclude>
 245.962 +    <ClInclude Include="CPP\Common\Defs.h">
 245.963 +      <Filter>Headers</Filter>
 245.964 +    </ClInclude>
 245.965 +    <ClInclude Include="CPP\Common\DynamicBuffer.h">
 245.966 +      <Filter>Headers</Filter>
 245.967 +    </ClInclude>
 245.968 +    <ClInclude Include="CPP\Common\InitializeStaticLib.h">
 245.969 +      <Filter>Headers</Filter>
 245.970 +    </ClInclude>
 245.971 +    <ClInclude Include="CPP\Common\IntToString.h">
 245.972 +      <Filter>Headers</Filter>
 245.973 +    </ClInclude>
 245.974 +    <ClInclude Include="CPP\Common\MyCom.h">
 245.975 +      <Filter>Headers</Filter>
 245.976 +    </ClInclude>
 245.977 +    <ClInclude Include="CPP\Common\MyException.h">
 245.978 +      <Filter>Headers</Filter>
 245.979 +    </ClInclude>
 245.980 +    <ClInclude Include="CPP\Common\MyInitGuid.h">
 245.981 +      <Filter>Headers</Filter>
 245.982 +    </ClInclude>
 245.983 +    <ClInclude Include="CPP\Common\MyMap.h">
 245.984 +      <Filter>Headers</Filter>
 245.985 +    </ClInclude>
 245.986 +    <ClInclude Include="CPP\Common\MyString.h">
 245.987 +      <Filter>Headers</Filter>
 245.988 +    </ClInclude>
 245.989 +    <ClInclude Include="CPP\Common\MyUnknown.h">
 245.990 +      <Filter>Headers</Filter>
 245.991 +    </ClInclude>
 245.992 +    <ClInclude Include="CPP\Common\MyVector.h">
 245.993 +      <Filter>Headers</Filter>
 245.994 +    </ClInclude>
 245.995 +    <ClInclude Include="CPP\Common\MyWindows.h">
 245.996 +      <Filter>Headers</Filter>
 245.997 +    </ClInclude>
 245.998 +    <ClInclude Include="CPP\Common\MyXml.h">
 245.999 +      <Filter>Headers</Filter>
245.1000 +    </ClInclude>
245.1001 +    <ClInclude Include="CPP\Common\NewHandler.h">
245.1002 +      <Filter>Headers</Filter>
245.1003 +    </ClInclude>
245.1004 +    <ClInclude Include="CPP\Common\StringConvert.h">
245.1005 +      <Filter>Headers</Filter>
245.1006 +    </ClInclude>
245.1007 +    <ClInclude Include="CPP\Common\StringToInt.h">
245.1008 +      <Filter>Headers</Filter>
245.1009 +    </ClInclude>
245.1010 +    <ClInclude Include="CPP\Common\Types.h">
245.1011 +      <Filter>Headers</Filter>
245.1012 +    </ClInclude>
245.1013 +    <ClInclude Include="CPP\Common\UTFConvert.h">
245.1014 +      <Filter>Headers</Filter>
245.1015 +    </ClInclude>
245.1016 +    <ClInclude Include="CPP\Common\Wildcard.h">
245.1017 +      <Filter>Headers</Filter>
245.1018 +    </ClInclude>
245.1019 +    <ClInclude Include="CPP\Windows\Defs.h">
245.1020 +      <Filter>Headers</Filter>
245.1021 +    </ClInclude>
245.1022 +    <ClInclude Include="CPP\Windows\FileDir.h">
245.1023 +      <Filter>Headers</Filter>
245.1024 +    </ClInclude>
245.1025 +    <ClInclude Include="CPP\Windows\FileFind.h">
245.1026 +      <Filter>Headers</Filter>
245.1027 +    </ClInclude>
245.1028 +    <ClInclude Include="CPP\Windows\FileIO.h">
245.1029 +      <Filter>Headers</Filter>
245.1030 +    </ClInclude>
245.1031 +    <ClInclude Include="CPP\Windows\FileName.h">
245.1032 +      <Filter>Headers</Filter>
245.1033 +    </ClInclude>
245.1034 +    <ClInclude Include="CPP\Windows\Handle.h">
245.1035 +      <Filter>Headers</Filter>
245.1036 +    </ClInclude>
245.1037 +    <ClInclude Include="CPP\Windows\PropVariant.h">
245.1038 +      <Filter>Headers</Filter>
245.1039 +    </ClInclude>
245.1040 +    <ClInclude Include="CPP\Windows\StdAfx.h">
245.1041 +      <Filter>Headers</Filter>
245.1042 +    </ClInclude>
245.1043 +    <ClInclude Include="CPP\Windows\Synchronization.h">
245.1044 +      <Filter>Headers</Filter>
245.1045 +    </ClInclude>
245.1046 +    <ClInclude Include="CPP\Windows\Thread.h">
245.1047 +      <Filter>Headers</Filter>
245.1048 +    </ClInclude>
245.1049 +    <ClInclude Include="CPP\Windows\Time.h">
245.1050 +      <Filter>Headers</Filter>
245.1051 +    </ClInclude>
245.1052 +    <ClInclude Include="C\7zCrc.h">
245.1053 +      <Filter>Headers</Filter>
245.1054 +    </ClInclude>
245.1055 +    <ClInclude Include="C\Aes.h">
245.1056 +      <Filter>Headers</Filter>
245.1057 +    </ClInclude>
245.1058 +    <ClInclude Include="C\Alloc.h">
245.1059 +      <Filter>Headers</Filter>
245.1060 +    </ClInclude>
245.1061 +    <ClInclude Include="C\Bra.h">
245.1062 +      <Filter>Headers</Filter>
245.1063 +    </ClInclude>
245.1064 +    <ClInclude Include="C\BwtSort.h">
245.1065 +      <Filter>Headers</Filter>
245.1066 +    </ClInclude>
245.1067 +    <ClInclude Include="C\CpuArch.h">
245.1068 +      <Filter>Headers</Filter>
245.1069 +    </ClInclude>
245.1070 +    <ClInclude Include="C\HuffEnc.h">
245.1071 +      <Filter>Headers</Filter>
245.1072 +    </ClInclude>
245.1073 +    <ClInclude Include="C\LzFind.h">
245.1074 +      <Filter>Headers</Filter>
245.1075 +    </ClInclude>
245.1076 +    <ClInclude Include="C\LzFindMt.h">
245.1077 +      <Filter>Headers</Filter>
245.1078 +    </ClInclude>
245.1079 +    <ClInclude Include="C\LzHash.h">
245.1080 +      <Filter>Headers</Filter>
245.1081 +    </ClInclude>
245.1082 +    <ClInclude Include="C\LzmaDec.h">
245.1083 +      <Filter>Headers</Filter>
245.1084 +    </ClInclude>
245.1085 +    <ClInclude Include="C\LzmaEnc.h">
245.1086 +      <Filter>Headers</Filter>
245.1087 +    </ClInclude>
245.1088 +    <ClInclude Include="C\RotateDefs.h">
245.1089 +      <Filter>Headers</Filter>
245.1090 +    </ClInclude>
245.1091 +    <ClInclude Include="C\Sha256.h">
245.1092 +      <Filter>Headers</Filter>
245.1093 +    </ClInclude>
245.1094 +    <ClInclude Include="C\Sort.h">
245.1095 +      <Filter>Headers</Filter>
245.1096 +    </ClInclude>
245.1097 +    <ClInclude Include="C\Threads.h">
245.1098 +      <Filter>Headers</Filter>
245.1099 +    </ClInclude>
245.1100 +    <ClInclude Include="C\Types.h">
245.1101 +      <Filter>Headers</Filter>
245.1102 +    </ClInclude>
245.1103 +  </ItemGroup>
245.1104 +</Project>
245.1105 \ No newline at end of file
   246.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   246.2 +++ b/src/win32/7zip/7z/C/7zCrc.c	Sat Mar 03 10:31:27 2012 -0600
   246.3 @@ -0,0 +1,35 @@
   246.4 +/* 7zCrc.c -- CRC32 calculation
   246.5 +2008-08-05
   246.6 +Igor Pavlov
   246.7 +Public domain */
   246.8 +
   246.9 +#include "7zCrc.h"
  246.10 +
  246.11 +#define kCrcPoly 0xEDB88320
  246.12 +UInt32 g_CrcTable[256];
  246.13 +
  246.14 +void MY_FAST_CALL CrcGenerateTable(void)
  246.15 +{
  246.16 +  UInt32 i;
  246.17 +  for (i = 0; i < 256; i++)
  246.18 +  {
  246.19 +    UInt32 r = i;
  246.20 +    int j;
  246.21 +    for (j = 0; j < 8; j++)
  246.22 +      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
  246.23 +    g_CrcTable[i] = r;
  246.24 +  }
  246.25 +}
  246.26 +
  246.27 +UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
  246.28 +{
  246.29 +  const Byte *p = (const Byte *)data;
  246.30 +  for (; size > 0 ; size--, p++)
  246.31 +    v = CRC_UPDATE_BYTE(v, *p);
  246.32 +  return v;
  246.33 +}
  246.34 +
  246.35 +UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)
  246.36 +{
  246.37 +  return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF;
  246.38 +}
   247.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   247.2 +++ b/src/win32/7zip/7z/C/7zCrc.h	Sat Mar 03 10:31:27 2012 -0600
   247.3 @@ -0,0 +1,24 @@
   247.4 +/* 7zCrc.h -- CRC32 calculation
   247.5 +2008-03-13
   247.6 +Igor Pavlov
   247.7 +Public domain */
   247.8 +
   247.9 +#ifndef __7Z_CRC_H
  247.10 +#define __7Z_CRC_H
  247.11 +
  247.12 +#include <stddef.h>
  247.13 +
  247.14 +#include "Types.h"
  247.15 +
  247.16 +extern UInt32 g_CrcTable[];
  247.17 +
  247.18 +void MY_FAST_CALL CrcGenerateTable(void);
  247.19 +
  247.20 +#define CRC_INIT_VAL 0xFFFFFFFF
  247.21 +#define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF)
  247.22 +#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
  247.23 +
  247.24 +UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);
  247.25 +UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);
  247.26 +
  247.27 +#endif
   248.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   248.2 +++ b/src/win32/7zip/7z/C/Aes.c	Sat Mar 03 10:31:27 2012 -0600
   248.3 @@ -0,0 +1,262 @@
   248.4 +/* Aes.c -- AES encryption / decryption
   248.5 +2008-08-05
   248.6 +Igor Pavlov
   248.7 +Public domain */
   248.8 +
   248.9 +#include "Aes.h"
  248.10 +#include "CpuArch.h"
  248.11 +
  248.12 +static UInt32 T[256 * 4];
  248.13 +static Byte Sbox[256] = {
  248.14 +  0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
  248.15 +  0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
  248.16 +  0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  248.17 +  0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
  248.18 +  0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
  248.19 +  0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  248.20 +  0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
  248.21 +  0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
  248.22 +  0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  248.23 +  0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
  248.24 +  0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
  248.25 +  0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  248.26 +  0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
  248.27 +  0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
  248.28 +  0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  248.29 +  0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16};
  248.30 +
  248.31 +static UInt32 D[256 * 4];
  248.32 +static Byte InvS[256];
  248.33 +
  248.34 +static Byte Rcon[11] = { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 };
  248.35 +
  248.36 +#define xtime(x) ((((x) << 1) ^ (((x) & 0x80) != 0 ? 0x1B : 0)) & 0xFF)
  248.37 +
  248.38 +#define Ui32(a0, a1, a2, a3) ((UInt32)(a0) | ((UInt32)(a1) << 8) | ((UInt32)(a2) << 16) | ((UInt32)(a3) << 24))
  248.39 +
  248.40 +#define gb0(x) ( (x)          & 0xFF)
  248.41 +#define gb1(x) (((x) >> ( 8)) & 0xFF)
  248.42 +#define gb2(x) (((x) >> (16)) & 0xFF)
  248.43 +#define gb3(x) (((x) >> (24)) & 0xFF)
  248.44 +
  248.45 +void AesGenTables(void)
  248.46 +{
  248.47 +  unsigned i;
  248.48 +  for (i = 0; i < 256; i++)
  248.49 +    InvS[Sbox[i]] = (Byte)i;
  248.50 +  for (i = 0; i < 256; i++)
  248.51 +  {
  248.52 +    {
  248.53 +      UInt32 a1 = Sbox[i];
  248.54 +      UInt32 a2 = xtime(a1);
  248.55 +      UInt32 a3 = xtime(a1) ^ a1;
  248.56 +      T[        i] = Ui32(a2, a1, a1, a3);
  248.57 +      T[0x100 + i] = Ui32(a3, a2, a1, a1);
  248.58 +      T[0x200 + i] = Ui32(a1, a3, a2, a1);
  248.59 +      T[0x300 + i] = Ui32(a1, a1, a3, a2);
  248.60 +    }
  248.61 +    {
  248.62 +      UInt32 a1 = InvS[i];
  248.63 +      UInt32 a2 = xtime(a1);
  248.64 +      UInt32 a4 = xtime(a2);
  248.65 +      UInt32 a8 = xtime(a4);
  248.66 +      UInt32 a9 = a8 ^ a1;
  248.67 +      UInt32 aB = a8 ^ a2 ^ a1;
  248.68 +      UInt32 aD = a8 ^ a4 ^ a1;
  248.69 +      UInt32 aE = a8 ^ a4 ^ a2;
  248.70 +      D[        i] = Ui32(aE, a9, aD, aB);
  248.71 +      D[0x100 + i] = Ui32(aB, aE, a9, aD);
  248.72 +      D[0x200 + i] = Ui32(aD, aB, aE, a9);
  248.73 +      D[0x300 + i] = Ui32(a9, aD, aB, aE);
  248.74 +    }
  248.75 +  }
  248.76 +}
  248.77 +
  248.78 +#define HT(i, x, s) (T + (x << 8))[gb ## x(s[(i + x) & 3])]
  248.79 +#define HT4(m, i, s, p) m[i] = \
  248.80 +    HT(i, 0, s) ^ \
  248.81 +    HT(i, 1, s) ^ \
  248.82 +    HT(i, 2, s) ^ \
  248.83 +    HT(i, 3, s) ^ w[p + i]
  248.84 +/* such order (2031) in HT16 is for VC6/K8 speed optimization) */
  248.85 +#define HT16(m, s, p) \
  248.86 +    HT4(m, 2, s, p); \
  248.87 +    HT4(m, 0, s, p); \
  248.88 +    HT4(m, 3, s, p); \
  248.89 +    HT4(m, 1, s, p); \
  248.90 +
  248.91 +#define FT(i, x) Sbox[gb ## x(m[(i + x) & 3])]
  248.92 +#define FT4(i) dest[i] = Ui32(FT(i, 0), FT(i, 1), FT(i, 2), FT(i, 3)) ^ w[i];
  248.93 +
  248.94 +#define HD(i, x, s) (D + (x << 8))[gb ## x(s[(i - x) & 3])]
  248.95 +#define HD4(m, i, s, p) m[i] = \
  248.96 +    HD(i, 0, s) ^ \
  248.97 +    HD(i, 1, s) ^ \
  248.98 +    HD(i, 2, s) ^ \
  248.99 +    HD(i, 3, s) ^ w[p + i];
 248.100 +/* such order (0231) in HD16 is for VC6/K8 speed optimization) */
 248.101 +#define HD16(m, s, p) \
 248.102 +    HD4(m, 0, s, p); \
 248.103 +    HD4(m, 2, s, p); \
 248.104 +    HD4(m, 3, s, p); \
 248.105 +    HD4(m, 1, s, p); \
 248.106 +
 248.107 +#define FD(i, x) InvS[gb ## x(m[(i - x) & 3])]
 248.108 +#define FD4(i) dest[i] = Ui32(FD(i, 0), FD(i, 1), FD(i, 2), FD(i, 3)) ^ w[i];
 248.109 +
 248.110 +void Aes_SetKeyEncode(CAes *p, const Byte *key, unsigned keySize)
 248.111 +{
 248.112 +  unsigned i, wSize;
 248.113 +  UInt32 *w;
 248.114 +  keySize /= 4;
 248.115 +  p->numRounds2 = keySize / 2 + 3;
 248.116 +
 248.117 +  wSize = (p->numRounds2 * 2 + 1) * 4;
 248.118 +  w = p->rkey;
 248.119 +
 248.120 +  for (i = 0; i < keySize; i++, key += 4)
 248.121 +    w[i] = Ui32(key[0], key[1], key[2], key[3]);
 248.122 +
 248.123 +  for (; i < wSize; i++)
 248.124 +  {
 248.125 +    UInt32 t = w[i - 1];
 248.126 +    unsigned rem = i % keySize;
 248.127 +    if (rem == 0)
 248.128 +      t = Ui32(Sbox[gb1(t)] ^ Rcon[i / keySize], Sbox[gb2(t)], Sbox[gb3(t)], Sbox[gb0(t)]);
 248.129 +    else if (keySize > 6 && rem == 4)
 248.130 +      t = Ui32(Sbox[gb0(t)], Sbox[gb1(t)], Sbox[gb2(t)], Sbox[gb3(t)]);
 248.131 +    w[i] = w[i - keySize] ^ t;
 248.132 +  }
 248.133 +}
 248.134 +
 248.135 +void Aes_SetKeyDecode(CAes *p, const Byte *key, unsigned keySize)
 248.136 +{
 248.137 +  unsigned i, num;
 248.138 +  UInt32 *w;
 248.139 +  Aes_SetKeyEncode(p, key, keySize);
 248.140 +  num = p->numRounds2 * 8 - 4;
 248.141 +  w = p->rkey + 4;
 248.142 +  for (i = 0; i < num; i++)
 248.143 +  {
 248.144 +    UInt32 r = w[i];
 248.145 +    w[i] =
 248.146 +      D[        Sbox[gb0(r)]] ^
 248.147 +      D[0x100 + Sbox[gb1(r)]] ^
 248.148 +      D[0x200 + Sbox[gb2(r)]] ^
 248.149 +      D[0x300 + Sbox[gb3(r)]];
 248.150 +  }
 248.151 +}
 248.152 +
 248.153 +static void AesEncode32(UInt32 *dest, const UInt32 *src, const UInt32 *w, unsigned numRounds2)
 248.154 +{
 248.155 +  UInt32 s[4];
 248.156 +  UInt32 m[4];
 248.157 +  s[0] = src[0] ^ w[0];
 248.158 +  s[1] = src[1] ^ w[1];
 248.159 +  s[2] = src[2] ^ w[2];
 248.160 +  s[3] = src[3] ^ w[3];
 248.161 +  w += 4;
 248.162 +  for (;;)
 248.163 +  {
 248.164 +    HT16(m, s, 0);
 248.165 +    if (--numRounds2 == 0)
 248.166 +      break;
 248.167 +    HT16(s, m, 4);
 248.168 +    w += 8;
 248.169 +  }
 248.170 +  w += 4;
 248.171 +  FT4(0); FT4(1); FT4(2); FT4(3);
 248.172 +}
 248.173 +
 248.174 +static void AesDecode32(UInt32 *dest, const UInt32 *src, const UInt32 *w, unsigned numRounds2)
 248.175 +{
 248.176 +  UInt32 s[4];
 248.177 +  UInt32 m[4];
 248.178 +  w += numRounds2 * 8;
 248.179 +  s[0] = src[0] ^ w[0];
 248.180 +  s[1] = src[1] ^ w[1];
 248.181 +  s[2] = src[2] ^ w[2];
 248.182 +  s[3] = src[3] ^ w[3];
 248.183 +  for (;;)
 248.184 +  {
 248.185 +    w -= 8;
 248.186 +    HD16(m, s, 4);
 248.187 +    if (--numRounds2 == 0)
 248.188 +      break;
 248.189 +    HD16(s, m, 0);
 248.190 +  }
 248.191 +  FD4(0); FD4(1); FD4(2); FD4(3);
 248.192 +}
 248.193 +
 248.194 +void Aes_Encode32(const CAes *p, UInt32 *dest, const UInt32 *src)
 248.195 +{
 248.196 +  AesEncode32(dest, src, p->rkey, p->numRounds2);
 248.197 +}
 248.198 +
 248.199 +void Aes_Decode32(const CAes *p, UInt32 *dest, const UInt32 *src)
 248.200 +{
 248.201 +  AesDecode32(dest, src, p->rkey, p->numRounds2);
 248.202 +}
 248.203 +
 248.204 +void AesCbc_Init(CAesCbc *p, const Byte *iv)
 248.205 +{
 248.206 +  unsigned i;
 248.207 +  for (i = 0; i < 4; i++)
 248.208 +    p->prev[i] = GetUi32(iv + i * 4);
 248.209 +}
 248.210 +
 248.211 +SizeT AesCbc_Encode(CAesCbc *p, Byte *data, SizeT size)
 248.212 +{
 248.213 +  SizeT i;
 248.214 +  if (size == 0)
 248.215 +    return 0;
 248.216 +  if (size < AES_BLOCK_SIZE)
 248.217 +    return AES_BLOCK_SIZE;
 248.218 +  size -= AES_BLOCK_SIZE;
 248.219 +  for (i = 0; i <= size; i += AES_BLOCK_SIZE, data += AES_BLOCK_SIZE)
 248.220 +  {
 248.221 +    p->prev[0] ^= GetUi32(data);
 248.222 +    p->prev[1] ^= GetUi32(data + 4);
 248.223 +    p->prev[2] ^= GetUi32(data + 8);
 248.224 +    p->prev[3] ^= GetUi32(data + 12);
 248.225 +    
 248.226 +    AesEncode32(p->prev, p->prev, p->aes.rkey, p->aes.numRounds2);
 248.227 +    
 248.228 +    SetUi32(data,      p->prev[0]);
 248.229 +    SetUi32(data + 4,  p->prev[1]);
 248.230 +    SetUi32(data + 8,  p->prev[2]);
 248.231 +    SetUi32(data + 12, p->prev[3]);
 248.232 +  }
 248.233 +  return i;
 248.234 +}
 248.235 +
 248.236 +SizeT AesCbc_Decode(CAesCbc *p, Byte *data, SizeT size)
 248.237 +{
 248.238 +  SizeT i;
 248.239 +  UInt32 in[4], out[4];
 248.240 +  if (size == 0)
 248.241 +    return 0;
 248.242 +  if (size < AES_BLOCK_SIZE)
 248.243 +    return AES_BLOCK_SIZE;
 248.244 +  size -= AES_BLOCK_SIZE;
 248.245 +  for (i = 0; i <= size; i += AES_BLOCK_SIZE, data += AES_BLOCK_SIZE)
 248.246 +  {
 248.247 +    in[0] = GetUi32(data);
 248.248 +    in[1] = GetUi32(data + 4);
 248.249 +    in[2] = GetUi32(data + 8);
 248.250 +    in[3] = GetUi32(data + 12);
 248.251 +    
 248.252 +    AesDecode32(out, in, p->aes.rkey, p->aes.numRounds2);
 248.253 +    
 248.254 +    SetUi32(data,      p->prev[0] ^ out[0]);
 248.255 +    SetUi32(data + 4,  p->prev[1] ^ out[1]);
 248.256 +    SetUi32(data + 8,  p->prev[2] ^ out[2]);
 248.257 +    SetUi32(data + 12, p->prev[3] ^ out[3]);
 248.258 +    
 248.259 +    p->prev[0] = in[0];
 248.260 +    p->prev[1] = in[1];
 248.261 +    p->prev[2] = in[2];
 248.262 +    p->prev[3] = in[3];
 248.263 +  }
 248.264 +  return i;
 248.265 +}
   249.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   249.2 +++ b/src/win32/7zip/7z/C/Aes.h	Sat Mar 03 10:31:27 2012 -0600
   249.3 @@ -0,0 +1,48 @@
   249.4 +/* Aes.h -- AES encryption / decryption
   249.5 +2008-08-05
   249.6 +Igor Pavlov
   249.7 +Public domain */
   249.8 +
   249.9 +#ifndef __AES_H
  249.10 +#define __AES_H
  249.11 +
  249.12 +#include "Types.h"
  249.13 +
  249.14 +#define AES_BLOCK_SIZE 16
  249.15 +
  249.16 +typedef struct
  249.17 +{
  249.18 +  unsigned numRounds2; /* = numRounds / 2 */
  249.19 +  UInt32 rkey[(14 + 1) * 4];
  249.20 +} CAes;
  249.21 +
  249.22 +/* Call AesGenTables one time before other AES functions */
  249.23 +void AesGenTables(void);
  249.24 +
  249.25 +/* keySize = 16 or 24 or 32 (bytes) */
  249.26 +void Aes_SetKeyEncode(CAes *p, const Byte *key, unsigned keySize);
  249.27 +void Aes_SetKeyDecode(CAes *p, const Byte *key, unsigned keySize);
  249.28 +
  249.29 +/* Aes_Encode32 and Aes_Decode32 functions work with little-endian words.
  249.30 +  src and dest are pointers to 4 UInt32 words.
  249.31 +  arc and dest can point to same block */
  249.32 +void Aes_Encode32(const CAes *p, UInt32 *dest, const UInt32 *src);
  249.33 +void Aes_Decode32(const CAes *p, UInt32 *dest, const UInt32 *src);
  249.34 +
  249.35 +typedef struct
  249.36 +{
  249.37 +  UInt32 prev[4];
  249.38 +  CAes aes;
  249.39 +} CAesCbc;
  249.40 +
  249.41 +void AesCbc_Init(CAesCbc *p, const Byte *iv); /* iv size is AES_BLOCK_SIZE */
  249.42 +
  249.43 +/* AesCbc_Encode and AesCbc_Decode:
  249.44 +  if (res <= size): Filter have converted res bytes
  249.45 +  if (res > size):  Filter have not converted anything. And it needs at
  249.46 +                    least res = AES_BLOCK_SIZE bytes to convert one block */
  249.47 +
  249.48 +SizeT AesCbc_Encode(CAesCbc *p, Byte *data, SizeT size);
  249.49 +SizeT AesCbc_Decode(CAesCbc *p, Byte *data, SizeT size);
  249.50 +
  249.51 +#endif
   250.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   250.2 +++ b/src/win32/7zip/7z/C/Alloc.c	Sat Mar 03 10:31:27 2012 -0600
   250.3 @@ -0,0 +1,127 @@
   250.4 +/* Alloc.c -- Memory allocation functions
   250.5 +2008-09-24
   250.6 +Igor Pavlov
   250.7 +Public domain */
   250.8 +
   250.9 +#ifdef _WIN32
  250.10 +#include <windows.h>
  250.11 +#endif
  250.12 +#include <stdlib.h>
  250.13 +
  250.14 +#include "Alloc.h"
  250.15 +
  250.16 +/* #define _SZ_ALLOC_DEBUG */
  250.17 +
  250.18 +/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
  250.19 +#ifdef _SZ_ALLOC_DEBUG
  250.20 +#include <stdio.h>
  250.21 +int g_allocCount = 0;
  250.22 +int g_allocCountMid = 0;
  250.23 +int g_allocCountBig = 0;
  250.24 +#endif
  250.25 +
  250.26 +void *MyAlloc(size_t size)
  250.27 +{
  250.28 +  if (size == 0)
  250.29 +    return 0;
  250.30 +  #ifdef _SZ_ALLOC_DEBUG
  250.31 +  {
  250.32 +    void *p = malloc(size);
  250.33 +    fprintf(stderr, "\nAlloc %10d bytes, count = %10d,  addr = %8X", size, g_allocCount++, (unsigned)p);
  250.34 +    return p;
  250.35 +  }
  250.36 +  #else
  250.37 +  return malloc(size);
  250.38 +  #endif
  250.39 +}
  250.40 +
  250.41 +void MyFree(void *address)
  250.42 +{
  250.43 +  #ifdef _SZ_ALLOC_DEBUG
  250.44 +  if (address != 0)
  250.45 +    fprintf(stderr, "\nFree; count = %10d,  addr = %8X", --g_allocCount, (unsigned)address);
  250.46 +  #endif
  250.47 +  free(address);
  250.48 +}
  250.49 +
  250.50 +#ifdef _WIN32
  250.51 +
  250.52 +void *MidAlloc(size_t size)
  250.53 +{
  250.54 +  if (size == 0)
  250.55 +    return 0;
  250.56 +  #ifdef _SZ_ALLOC_DEBUG
  250.57 +  fprintf(stderr, "\nAlloc_Mid %10d bytes;  count = %10d", size, g_allocCountMid++);
  250.58 +  #endif
  250.59 +  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
  250.60 +}
  250.61 +
  250.62 +void MidFree(void *address)
  250.63 +{
  250.64 +  #ifdef _SZ_ALLOC_DEBUG
  250.65 +  if (address != 0)
  250.66 +    fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid);
  250.67 +  #endif
  250.68 +  if (address == 0)
  250.69 +    return;
  250.70 +  VirtualFree(address, 0, MEM_RELEASE);
  250.71 +}
  250.72 +
  250.73 +#ifndef MEM_LARGE_PAGES
  250.74 +#undef _7ZIP_LARGE_PAGES
  250.75 +#endif
  250.76 +
  250.77 +#ifdef _7ZIP_LARGE_PAGES
  250.78 +SIZE_T g_LargePageSize = 0;
  250.79 +typedef SIZE_T (WINAPI *GetLargePageMinimumP)();
  250.80 +#endif
  250.81 +
  250.82 +void SetLargePageSize()
  250.83 +{
  250.84 +  #ifdef _7ZIP_LARGE_PAGES
  250.85 +  SIZE_T size = 0;
  250.86 +  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)
  250.87 +        GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum");
  250.88 +  if (largePageMinimum == 0)
  250.89 +    return;
  250.90 +  size = largePageMinimum();
  250.91 +  if (size == 0 || (size & (size - 1)) != 0)
  250.92 +    return;
  250.93 +  g_LargePageSize = size;
  250.94 +  #endif
  250.95 +}
  250.96 +
  250.97 +
  250.98 +void *BigAlloc(size_t size)
  250.99 +{
 250.100 +  if (size == 0)
 250.101 +    return 0;
 250.102 +  #ifdef _SZ_ALLOC_DEBUG
 250.103 +  fprintf(stderr, "\nAlloc_Big %10d bytes;  count = %10d", size, g_allocCountBig++);
 250.104 +  #endif
 250.105 +  
 250.106 +  #ifdef _7ZIP_LARGE_PAGES
 250.107 +  if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))
 250.108 +  {
 250.109 +    void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),
 250.110 +        MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
 250.111 +    if (res != 0)
 250.112 +      return res;
 250.113 +  }
 250.114 +  #endif
 250.115 +  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
 250.116 +}
 250.117 +
 250.118 +void BigFree(void *address)
 250.119 +{
 250.120 +  #ifdef _SZ_ALLOC_DEBUG
 250.121 +  if (address != 0)
 250.122 +    fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
 250.123 +  #endif
 250.124 +  
 250.125 +  if (address == 0)
 250.126 +    return;
 250.127 +  VirtualFree(address, 0, MEM_RELEASE);
 250.128 +}
 250.129 +
 250.130 +#endif
   251.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   251.2 +++ b/src/win32/7zip/7z/C/Alloc.h	Sat Mar 03 10:31:27 2012 -0600
   251.3 @@ -0,0 +1,32 @@
   251.4 +/* Alloc.h -- Memory allocation functions
   251.5 +2008-03-13
   251.6 +Igor Pavlov
   251.7 +Public domain */
   251.8 +
   251.9 +#ifndef __COMMON_ALLOC_H
  251.10 +#define __COMMON_ALLOC_H
  251.11 +
  251.12 +#include <stddef.h>
  251.13 +
  251.14 +void *MyAlloc(size_t size);
  251.15 +void MyFree(void *address);
  251.16 +
  251.17 +#ifdef _WIN32
  251.18 +
  251.19 +void SetLargePageSize();
  251.20 +
  251.21 +void *MidAlloc(size_t size);
  251.22 +void MidFree(void *address);
  251.23 +void *BigAlloc(size_t size);
  251.24 +void BigFree(void *address);
  251.25 +
  251.26 +#else
  251.27 +
  251.28 +#define MidAlloc(size) MyAlloc(size)
  251.29 +#define MidFree(address) MyFree(address)
  251.30 +#define BigAlloc(size) MyAlloc(size)
  251.31 +#define BigFree(address) MyFree(address)
  251.32 +
  251.33 +#endif
  251.34 +
  251.35 +#endif
   252.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   252.2 +++ b/src/win32/7zip/7z/C/Bra.c	Sat Mar 03 10:31:27 2012 -0600
   252.3 @@ -0,0 +1,133 @@
   252.4 +/* Bra.c -- Converters for RISC code
   252.5 +2008-10-04 : Igor Pavlov : Public domain */
   252.6 +
   252.7 +#include "Bra.h"
   252.8 +
   252.9 +SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
  252.10 +{
  252.11 +  SizeT i;
  252.12 +  if (size < 4)
  252.13 +    return 0;
  252.14 +  size -= 4;
  252.15 +  ip += 8;
  252.16 +  for (i = 0; i <= size; i += 4)
  252.17 +  {
  252.18 +    if (data[i + 3] == 0xEB)
  252.19 +    {
  252.20 +      UInt32 dest;
  252.21 +      UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]);
  252.22 +      src <<= 2;
  252.23 +      if (encoding)
  252.24 +        dest = ip + (UInt32)i + src;
  252.25 +      else
  252.26 +        dest = src - (ip + (UInt32)i);
  252.27 +      dest >>= 2;
  252.28 +      data[i + 2] = (Byte)(dest >> 16);
  252.29 +      data[i + 1] = (Byte)(dest >> 8);
  252.30 +      data[i + 0] = (Byte)dest;
  252.31 +    }
  252.32 +  }
  252.33 +  return i;
  252.34 +}
  252.35 +
  252.36 +SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
  252.37 +{
  252.38 +  SizeT i;
  252.39 +  if (size < 4)
  252.40 +    return 0;
  252.41 +  size -= 4;
  252.42 +  ip += 4;
  252.43 +  for (i = 0; i <= size; i += 2)
  252.44 +  {
  252.45 +    if ((data[i + 1] & 0xF8) == 0xF0 &&
  252.46 +        (data[i + 3] & 0xF8) == 0xF8)
  252.47 +    {
  252.48 +      UInt32 dest;
  252.49 +      UInt32 src =
  252.50 +        (((UInt32)data[i + 1] & 0x7) << 19) |
  252.51 +        ((UInt32)data[i + 0] << 11) |
  252.52 +        (((UInt32)data[i + 3] & 0x7) << 8) |
  252.53 +        (data[i + 2]);
  252.54 +      
  252.55 +      src <<= 1;
  252.56 +      if (encoding)
  252.57 +        dest = ip + (UInt32)i + src;
  252.58 +      else
  252.59 +        dest = src - (ip + (UInt32)i);
  252.60 +      dest >>= 1;
  252.61 +      
  252.62 +      data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));
  252.63 +      data[i + 0] = (Byte)(dest >> 11);
  252.64 +      data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));
  252.65 +      data[i + 2] = (Byte)dest;
  252.66 +      i += 2;
  252.67 +    }
  252.68 +  }
  252.69 +  return i;
  252.70 +}
  252.71 +
  252.72 +SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
  252.73 +{
  252.74 +  SizeT i;
  252.75 +  if (size < 4)
  252.76 +    return 0;
  252.77 +  size -= 4;
  252.78 +  for (i = 0; i <= size; i += 4)
  252.79 +  {
  252.80 +    if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1)
  252.81 +    {
  252.82 +      UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) |
  252.83 +        ((UInt32)data[i + 1] << 16) |
  252.84 +        ((UInt32)data[i + 2] << 8) |
  252.85 +        ((UInt32)data[i + 3] & (~3));
  252.86 +      
  252.87 +      UInt32 dest;
  252.88 +      if (encoding)
  252.89 +        dest = ip + (UInt32)i + src;
  252.90 +      else
  252.91 +        dest = src - (ip + (UInt32)i);
  252.92 +      data[i + 0] = (Byte)(0x48 | ((dest >> 24) &  0x3));
  252.93 +      data[i + 1] = (Byte)(dest >> 16);
  252.94 +      data[i + 2] = (Byte)(dest >> 8);
  252.95 +      data[i + 3] &= 0x3;
  252.96 +      data[i + 3] |= dest;
  252.97 +    }
  252.98 +  }
  252.99 +  return i;
 252.100 +}
 252.101 +
 252.102 +SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
 252.103 +{
 252.104 +  UInt32 i;
 252.105 +  if (size < 4)
 252.106 +    return 0;
 252.107 +  size -= 4;
 252.108 +  for (i = 0; i <= size; i += 4)
 252.109 +  {
 252.110 +    if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 ||
 252.111 +        data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)
 252.112 +    {
 252.113 +      UInt32 src =
 252.114 +        ((UInt32)data[i + 0] << 24) |
 252.115 +        ((UInt32)data[i + 1] << 16) |
 252.116 +        ((UInt32)data[i + 2] << 8) |
 252.117 +        ((UInt32)data[i + 3]);
 252.118 +      UInt32 dest;
 252.119 +      
 252.120 +      src <<= 2;
 252.121 +      if (encoding)
 252.122 +        dest = ip + i + src;
 252.123 +      else
 252.124 +        dest = src - (ip + i);
 252.125 +      dest >>= 2;
 252.126 +      
 252.127 +      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;
 252.128 +
 252.129 +      data[i + 0] = (Byte)(dest >> 24);
 252.130 +      data[i + 1] = (Byte)(dest >> 16);
 252.131 +      data[i + 2] = (Byte)(dest >> 8);
 252.132 +      data[i + 3] = (Byte)dest;
 252.133 +    }
 252.134 +  }
 252.135 +  return i;
 252.136 +}
   253.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   253.2 +++ b/src/win32/7zip/7z/C/Bra.h	Sat Mar 03 10:31:27 2012 -0600
   253.3 @@ -0,0 +1,60 @@
   253.4 +/* Bra.h -- Branch converters for executables
   253.5 +2008-10-04 : Igor Pavlov : Public domain */
   253.6 +
   253.7 +#ifndef __BRA_H
   253.8 +#define __BRA_H
   253.9 +
  253.10 +#include "Types.h"
  253.11 +
  253.12 +/*
  253.13 +These functions convert relative addresses to absolute addresses
  253.14 +in CALL instructions to increase the compression ratio.
  253.15 +  
  253.16 +  In:
  253.17 +    data     - data buffer
  253.18 +    size     - size of data
  253.19 +    ip       - current virtual Instruction Pinter (IP) value
  253.20 +    state    - state variable for x86 converter
  253.21 +    encoding - 0 (for decoding), 1 (for encoding)
  253.22 +  
  253.23 +  Out:
  253.24 +    state    - state variable for x86 converter
  253.25 +
  253.26 +  Returns:
  253.27 +    The number of processed bytes. If you call these functions with multiple calls,
  253.28 +    you must start next call with first byte after block of processed bytes.
  253.29 +  
  253.30 +  Type   Endian  Alignment  LookAhead
  253.31 +  
  253.32 +  x86    little      1          4
  253.33 +  ARMT   little      2          2
  253.34 +  ARM    little      4          0
  253.35 +  PPC     big        4          0
  253.36 +  SPARC   big        4          0
  253.37 +  IA64   little     16          0
  253.38 +
  253.39 +  size must be >= Alignment + LookAhead, if it's not last block.
  253.40 +  If (size < Alignment + LookAhead), converter returns 0.
  253.41 +
  253.42 +  Example:
  253.43 +
  253.44 +    UInt32 ip = 0;
  253.45 +    for ()
  253.46 +    {
  253.47 +      ; size must be >= Alignment + LookAhead, if it's not last block
  253.48 +      SizeT processed = Convert(data, size, ip, 1);
  253.49 +      data += processed;
  253.50 +      size -= processed;
  253.51 +      ip += processed;
  253.52 +    }
  253.53 +*/
  253.54 +
  253.55 +#define x86_Convert_Init(state) { state = 0; }
  253.56 +SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
  253.57 +SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
  253.58 +SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
  253.59 +SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
  253.60 +SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
  253.61 +SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
  253.62 +
  253.63 +#endif
   254.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   254.2 +++ b/src/win32/7zip/7z/C/Bra86.c	Sat Mar 03 10:31:27 2012 -0600
   254.3 @@ -0,0 +1,85 @@
   254.4 +/* Bra86.c -- Converter for x86 code (BCJ)
   254.5 +2008-10-04 : Igor Pavlov : Public domain */
   254.6 +
   254.7 +#include "Bra.h"
   254.8 +
   254.9 +#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)
  254.10 +
  254.11 +const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};
  254.12 +const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};
  254.13 +
  254.14 +SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)
  254.15 +{
  254.16 +  SizeT bufferPos = 0, prevPosT;
  254.17 +  UInt32 prevMask = *state & 0x7;
  254.18 +  if (size < 5)
  254.19 +    return 0;
  254.20 +  ip += 5;
  254.21 +  prevPosT = (SizeT)0 - 1;
  254.22 +
  254.23 +  for (;;)
  254.24 +  {
  254.25 +    Byte *p = data + bufferPos;
  254.26 +    Byte *limit = data + size - 4;
  254.27 +    for (; p < limit; p++)
  254.28 +      if ((*p & 0xFE) == 0xE8)
  254.29 +        break;
  254.30 +    bufferPos = (SizeT)(p - data);
  254.31 +    if (p >= limit)
  254.32 +      break;
  254.33 +    prevPosT = bufferPos - prevPosT;
  254.34 +    if (prevPosT > 3)
  254.35 +      prevMask = 0;
  254.36 +    else
  254.37 +    {
  254.38 +      prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;
  254.39 +      if (prevMask != 0)
  254.40 +      {
  254.41 +        Byte b = p[4 - kMaskToBitNumber[prevMask]];
  254.42 +        if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))
  254.43 +        {
  254.44 +          prevPosT = bufferPos;
  254.45 +          prevMask = ((prevMask << 1) & 0x7) | 1;
  254.46 +          bufferPos++;
  254.47 +          continue;
  254.48 +        }
  254.49 +      }
  254.50 +    }
  254.51 +    prevPosT = bufferPos;
  254.52 +
  254.53 +    if (Test86MSByte(p[4]))
  254.54 +    {
  254.55 +      UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);
  254.56 +      UInt32 dest;
  254.57 +      for (;;)
  254.58 +      {
  254.59 +        Byte b;
  254.60 +        int index;
  254.61 +        if (encoding)
  254.62 +          dest = (ip + (UInt32)bufferPos) + src;
  254.63 +        else
  254.64 +          dest = src - (ip + (UInt32)bufferPos);
  254.65 +        if (prevMask == 0)
  254.66 +          break;
  254.67 +        index = kMaskToBitNumber[prevMask] * 8;
  254.68 +        b = (Byte)((dest >> (24 - index)) & 0xFF);
  254.69 +        if (!Test86MSByte(b))
  254.70 +          break;
  254.71 +        src = dest ^ ((1 << (32 - index)) - 1);
  254.72 +      }
  254.73 +      p[4] = (Byte)((~(((dest >> 24) & 1) - 1)) & 0xFF);
  254.74 +      p[3] = (Byte)((dest >> 16) & 0xFF);
  254.75 +      p[2] = (Byte)((dest >> 8) & 0xFF);
  254.76 +      p[1] = (Byte)(dest & 0xFF);
  254.77 +      bufferPos += 5;
  254.78 +    }
  254.79 +    else
  254.80 +    {
  254.81 +      prevMask = ((prevMask << 1) & 0x7) | 1;
  254.82 +      bufferPos++;
  254.83 +    }
  254.84 +  }
  254.85 +  prevPosT = bufferPos - prevPosT;
  254.86 +  *state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));
  254.87 +  return bufferPos;
  254.88 +}
   255.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   255.2 +++ b/src/win32/7zip/7z/C/BraIA64.c	Sat Mar 03 10:31:27 2012 -0600
   255.3 @@ -0,0 +1,67 @@
   255.4 +/* BraIA64.c -- Converter for IA-64 code
   255.5 +2008-10-04 : Igor Pavlov : Public domain */
   255.6 +
   255.7 +#include "Bra.h"
   255.8 +
   255.9 +static const Byte kBranchTable[32] =
  255.10 +{
  255.11 +  0, 0, 0, 0, 0, 0, 0, 0,
  255.12 +  0, 0, 0, 0, 0, 0, 0, 0,
  255.13 +  4, 4, 6, 6, 0, 0, 7, 7,
  255.14 +  4, 4, 0, 0, 4, 4, 0, 0
  255.15 +};
  255.16 +
  255.17 +SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
  255.18 +{
  255.19 +  SizeT i;
  255.20 +  if (size < 16)
  255.21 +    return 0;
  255.22 +  size -= 16;
  255.23 +  for (i = 0; i <= size; i += 16)
  255.24 +  {
  255.25 +    UInt32 instrTemplate = data[i] & 0x1F;
  255.26 +    UInt32 mask = kBranchTable[instrTemplate];
  255.27 +    UInt32 bitPos = 5;
  255.28 +    int slot;
  255.29 +    for (slot = 0; slot < 3; slot++, bitPos += 41)
  255.30 +    {
  255.31 +      UInt32 bytePos, bitRes;
  255.32 +      UInt64 instruction, instNorm;
  255.33 +      int j;
  255.34 +      if (((mask >> slot) & 1) == 0)
  255.35 +        continue;
  255.36 +      bytePos = (bitPos >> 3);
  255.37 +      bitRes = bitPos & 0x7;
  255.38 +      instruction = 0;
  255.39 +      for (j = 0; j < 6; j++)
  255.40 +        instruction += (UInt64)data[i + j + bytePos] << (8 * j);
  255.41 +
  255.42 +      instNorm = instruction >> bitRes;
  255.43 +      if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0)
  255.44 +      {
  255.45 +        UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);
  255.46 +        UInt32 dest;
  255.47 +        src |= ((UInt32)(instNorm >> 36) & 1) << 20;
  255.48 +        
  255.49 +        src <<= 4;
  255.50 +        
  255.51 +        if (encoding)
  255.52 +          dest = ip + (UInt32)i + src;
  255.53 +        else
  255.54 +          dest = src - (ip + (UInt32)i);
  255.55 +        
  255.56 +        dest >>= 4;
  255.57 +        
  255.58 +        instNorm &= ~((UInt64)(0x8FFFFF) << 13);
  255.59 +        instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);
  255.60 +        instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));
  255.61 +        
  255.62 +        instruction &= (1 << bitRes) - 1;
  255.63 +        instruction |= (instNorm << bitRes);
  255.64 +        for (j = 0; j < 6; j++)
  255.65 +          data[i + j + bytePos] = (Byte)(instruction >> (8 * j));
  255.66 +      }
  255.67 +    }
  255.68 +  }
  255.69 +  return i;
  255.70 +}
   256.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   256.2 +++ b/src/win32/7zip/7z/C/BwtSort.c	Sat Mar 03 10:31:27 2012 -0600
   256.3 @@ -0,0 +1,516 @@
   256.4 +/* BwtSort.c -- BWT block sorting
   256.5 +2008-08-17
   256.6 +Igor Pavlov
   256.7 +Public domain */
   256.8 +
   256.9 +#include "BwtSort.h"
  256.10 +#include "Sort.h"
  256.11 +
  256.12 +/* #define BLOCK_SORT_USE_HEAP_SORT */
  256.13 +
  256.14 +#define NO_INLINE MY_FAST_CALL
  256.15 +
  256.16 +/* Don't change it !!! */
  256.17 +#define kNumHashBytes 2
  256.18 +#define kNumHashValues (1 << (kNumHashBytes * 8))
  256.19 +
  256.20 +/* kNumRefBitsMax must be < (kNumHashBytes * 8) = 16 */
  256.21 +#define kNumRefBitsMax 12
  256.22 +
  256.23 +#define BS_TEMP_SIZE kNumHashValues
  256.24 +
  256.25 +#ifdef BLOCK_SORT_EXTERNAL_FLAGS
  256.26 +
  256.27 +/* 32 Flags in UInt32 word */
  256.28 +#define kNumFlagsBits 5
  256.29 +#define kNumFlagsInWord (1 << kNumFlagsBits)
  256.30 +#define kFlagsMask (kNumFlagsInWord - 1)
  256.31 +#define kAllFlags 0xFFFFFFFF
  256.32 +
  256.33 +#else
  256.34 +
  256.35 +#define kNumBitsMax 20
  256.36 +#define kIndexMask ((1 << kNumBitsMax) - 1)
  256.37 +#define kNumExtraBits (32 - kNumBitsMax)
  256.38 +#define kNumExtra0Bits (kNumExtraBits - 2)
  256.39 +#define kNumExtra0Mask ((1 << kNumExtra0Bits) - 1)
  256.40 +
  256.41 +#define SetFinishedGroupSize(p, size) \
  256.42 +  {  *(p) |= ((((size) - 1) & kNumExtra0Mask) << kNumBitsMax); \
  256.43 +    if ((size) > (1 << kNumExtra0Bits)) { \
  256.44 +    *(p) |= 0x40000000;  *((p) + 1) |= ((((size) - 1)>> kNumExtra0Bits) << kNumBitsMax); } } \
  256.45 +
  256.46 +static void SetGroupSize(UInt32 *p, UInt32 size)
  256.47 +{
  256.48 +  if (--size == 0)
  256.49 +    return;
  256.50 +  *p |= 0x80000000 | ((size & kNumExtra0Mask) << kNumBitsMax);
  256.51 +  if (size >= (1 << kNumExtra0Bits))
  256.52 +  {
  256.53 +    *p |= 0x40000000;
  256.54 +    p[1] |= ((size >> kNumExtra0Bits) << kNumBitsMax);
  256.55 +  }
  256.56 +}
  256.57 +
  256.58 +#endif
  256.59 +
  256.60 +/*
  256.61 +SortGroup - is recursive Range-Sort function with HeapSort optimization for small blocks
  256.62 +  "range" is not real range. It's only for optimization.
  256.63 +returns: 1 - if there are groups, 0 - no more groups
  256.64 +*/
  256.65 +
  256.66 +UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 groupOffset, UInt32 groupSize, int NumRefBits, UInt32 *Indices
  256.67 +  #ifndef BLOCK_SORT_USE_HEAP_SORT
  256.68 +  , UInt32 left, UInt32 range
  256.69 +  #endif
  256.70 +  )
  256.71 +{
  256.72 +  UInt32 *ind2 = Indices + groupOffset;
  256.73 +  UInt32 *Groups;
  256.74 +  if (groupSize <= 1)
  256.75 +  {
  256.76 +    /*
  256.77 +    #ifndef BLOCK_SORT_EXTERNAL_FLAGS
  256.78 +    SetFinishedGroupSize(ind2, 1);
  256.79 +    #endif
  256.80 +    */
  256.81 +    return 0;
  256.82 +  }
  256.83 +  Groups = Indices + BlockSize + BS_TEMP_SIZE;
  256.84 +  if (groupSize <= ((UInt32)1 << NumRefBits)
  256.85 +      #ifndef BLOCK_SORT_USE_HEAP_SORT
  256.86 +      && groupSize <= range
  256.87 +      #endif
  256.88 +      )
  256.89 +  {
  256.90 +    UInt32 *temp = Indices + BlockSize;
  256.91 +    UInt32 j;
  256.92 +    UInt32 mask, thereAreGroups, group, cg;
  256.93 +    {
  256.94 +      UInt32 gPrev;
  256.95 +      UInt32 gRes = 0;
  256.96 +      {
  256.97 +        UInt32 sp = ind2[0] + NumSortedBytes;
  256.98 +        if (sp >= BlockSize) sp -= BlockSize;
  256.99 +        gPrev = Groups[sp];
 256.100 +        temp[0] = (gPrev << NumRefBits);
 256.101 +      }
 256.102 +      
 256.103 +      for (j = 1; j < groupSize; j++)
 256.104 +      {
 256.105 +        UInt32 sp = ind2[j] + NumSortedBytes;
 256.106 +        UInt32 g;
 256.107 +        if (sp >= BlockSize) sp -= BlockSize;
 256.108 +        g = Groups[sp];
 256.109 +        temp[j] = (g << NumRefBits) | j;
 256.110 +        gRes |= (gPrev ^ g);
 256.111 +      }
 256.112 +      if (gRes == 0)
 256.113 +      {
 256.114 +        #ifndef BLOCK_SORT_EXTERNAL_FLAGS
 256.115 +        SetGroupSize(ind2, groupSize);
 256.116 +        #endif
 256.117 +        return 1;
 256.118 +      }
 256.119 +    }
 256.120 +    
 256.121 +    HeapSort(temp, groupSize);
 256.122 +    mask = ((1 << NumRefBits) - 1);
 256.123 +    thereAreGroups = 0;
 256.124 +    
 256.125 +    group = groupOffset;
 256.126 +    cg = (temp[0] >> NumRefBits);
 256.127 +    temp[0] = ind2[temp[0] & mask];
 256.128 +
 256.129 +    {
 256.130 +    #ifdef BLOCK_SORT_EXTERNAL_FLAGS
 256.131 +    UInt32 *Flags = Groups + BlockSize;
 256.132 +    #else
 256.133 +    UInt32 prevGroupStart = 0;
 256.134 +    #endif
 256.135 +    
 256.136 +    for (j = 1; j < groupSize; j++)
 256.137 +    {
 256.138 +      UInt32 val = temp[j];
 256.139 +      UInt32 cgCur = (val >> NumRefBits);
 256.140 +      
 256.141 +      if (cgCur != cg)
 256.142 +      {
 256.143 +        cg = cgCur;
 256.144 +        group = groupOffset + j;
 256.145 +
 256.146 +        #ifdef BLOCK_SORT_EXTERNAL_FLAGS
 256.147 +        {
 256.148 +        UInt32 t = group - 1;
 256.149 +        Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
 256.150 +        }
 256.151 +        #else
 256.152 +        SetGroupSize(temp + prevGroupStart, j - prevGroupStart);
 256.153 +        prevGroupStart = j;
 256.154 +        #endif
 256.155 +      }
 256.156 +      else
 256.157 +        thereAreGroups = 1;
 256.158 +      {
 256.159 +      UInt32 ind = ind2[val & mask];
 256.160 +      temp[j] = ind;
 256.161 +      Groups[ind] = group;
 256.162 +      }
 256.163 +    }
 256.164 +
 256.165 +    #ifndef BLOCK_SORT_EXTERNAL_FLAGS
 256.166 +    SetGroupSize(temp + prevGroupStart, j - prevGroupStart);
 256.167 +    #endif
 256.168 +    }
 256.169 +
 256.170 +    for (j = 0; j < groupSize; j++)
 256.171 +      ind2[j] = temp[j];
 256.172 +    return thereAreGroups;
 256.173 +  }
 256.174 +
 256.175 +  /* Check that all strings are in one group (cannot sort) */
 256.176 +  {
 256.177 +    UInt32 group, j;
 256.178 +    UInt32 sp = ind2[0] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
 256.179 +    group = Groups[sp];
 256.180 +    for (j = 1; j < groupSize; j++)
 256.181 +    {
 256.182 +      sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
 256.183 +      if (Groups[sp] != group)
 256.184 +        break;
 256.185 +    }
 256.186 +    if (j == groupSize)
 256.187 +    {
 256.188 +      #ifndef BLOCK_SORT_EXTERNAL_FLAGS
 256.189 +      SetGroupSize(ind2, groupSize);
 256.190 +      #endif
 256.191 +      return 1;
 256.192 +    }
 256.193 +  }
 256.194 +
 256.195 +  #ifndef BLOCK_SORT_USE_HEAP_SORT
 256.196 +  {
 256.197 +  /* ---------- Range Sort ---------- */
 256.198 +  UInt32 i;
 256.199 +  UInt32 mid;
 256.200 +  for (;;)
 256.201 +  {
 256.202 +    UInt32 j;
 256.203 +    if (range <= 1)
 256.204 +    {
 256.205 +      #ifndef BLOCK_SORT_EXTERNAL_FLAGS
 256.206 +      SetGroupSize(ind2, groupSize);
 256.207 +      #endif
 256.208 +      return 1;
 256.209 +    }
 256.210 +    mid = left + ((range + 1) >> 1);
 256.211 +    j = groupSize;
 256.212 +    i = 0;
 256.213 +    do
 256.214 +    {
 256.215 +      UInt32 sp = ind2[i] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
 256.216 +      if (Groups[sp] >= mid)
 256.217 +      {
 256.218 +        for (j--; j > i; j--)
 256.219 +        {
 256.220 +          sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
 256.221 +          if (Groups[sp] < mid)
 256.222 +          {
 256.223 +            UInt32 temp = ind2[i]; ind2[i] = ind2[j]; ind2[j] = temp;
 256.224 +            break;
 256.225 +          }
 256.226 +        }
 256.227 +        if (i >= j)
 256.228 +          break;
 256.229 +      }
 256.230 +    }
 256.231 +    while (++i < j);
 256.232 +    if (i == 0)
 256.233 +    {
 256.234 +      range = range - (mid - left);
 256.235 +      left = mid;
 256.236 +    }
 256.237 +    else if (i == groupSize)
 256.238 +      range = (mid - left);
 256.239 +    else
 256.240 +      break;
 256.241 +  }
 256.242 +
 256.243 +  #ifdef BLOCK_SORT_EXTERNAL_FLAGS
 256.244 +  {
 256.245 +    UInt32 t = (groupOffset + i - 1);
 256.246 +    UInt32 *Flags = Groups + BlockSize;
 256.247 +    Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
 256.248 +  }
 256.249 +  #endif
 256.250 +
 256.251 +  {
 256.252 +    UInt32 j;
 256.253 +    for (j = i; j < groupSize; j++)
 256.254 +      Groups[ind2[j]] = groupOffset + i;
 256.255 +  }
 256.256 +
 256.257 +  {
 256.258 +  UInt32 res = SortGroup(BlockSize, NumSortedBytes, groupOffset, i, NumRefBits, Indices, left, mid - left);
 256.259 +  return res | SortGroup(BlockSize, NumSortedBytes, groupOffset + i, groupSize - i, NumRefBits, Indices, mid, range - (mid - left));
 256.260 +  }
 256.261 +
 256.262 +  }
 256.263 +
 256.264 +  #else
 256.265 +
 256.266 +  /* ---------- Heap Sort ---------- */
 256.267 +
 256.268 +  {
 256.269 +    UInt32 j;
 256.270 +    for (j = 0; j < groupSize; j++)
 256.271 +    {
 256.272 +      UInt32 sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
 256.273 +      ind2[j] = sp;
 256.274 +    }
 256.275 +
 256.276 +    HeapSortRef(ind2, Groups, groupSize);
 256.277 +
 256.278 +    /* Write Flags */
 256.279 +    {
 256.280 +    UInt32 sp = ind2[0];
 256.281 +    UInt32 group = Groups[sp];
 256.282 +
 256.283 +    #ifdef BLOCK_SORT_EXTERNAL_FLAGS
 256.284 +    UInt32 *Flags = Groups + BlockSize;
 256.285 +    #else
 256.286 +    UInt32 prevGroupStart = 0;
 256.287 +    #endif
 256.288 +
 256.289 +    for (j = 1; j < groupSize; j++)
 256.290 +    {
 256.291 +      sp = ind2[j];
 256.292 +      if (Groups[sp] != group)
 256.293 +      {
 256.294 +        group = Groups[sp];
 256.295 +        #ifdef BLOCK_SORT_EXTERNAL_FLAGS
 256.296 +        {
 256.297 +        UInt32 t = groupOffset + j - 1;
 256.298 +        Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
 256.299 +        }
 256.300 +        #else
 256.301 +        SetGroupSize(ind2 + prevGroupStart, j - prevGroupStart);
 256.302 +        prevGroupStart = j;
 256.303 +        #endif
 256.304 +      }
 256.305 +    }
 256.306 +
 256.307 +    #ifndef BLOCK_SORT_EXTERNAL_FLAGS
 256.308 +    SetGroupSize(ind2 + prevGroupStart, j - prevGroupStart);
 256.309 +    #endif
 256.310 +    }
 256.311 +    {
 256.312 +    /* Write new Groups values and Check that there are groups */
 256.313 +    UInt32 thereAreGroups = 0;
 256.314 +    for (j = 0; j < groupSize; j++)
 256.315 +    {
 256.316 +      UInt32 group = groupOffset + j;
 256.317 +      #ifndef BLOCK_SORT_EXTERNAL_FLAGS
 256.318 +      UInt32 subGroupSize = ((ind2[j] & ~0xC0000000) >> kNumBitsMax);
 256.319 +      if ((ind2[j] & 0x40000000) != 0)
 256.320 +        subGroupSize += ((ind2[j + 1] >> kNumBitsMax) << kNumExtra0Bits);
 256.321 +      subGroupSize++;
 256.322 +      for (;;)
 256.323 +      {
 256.324 +        UInt32 original = ind2[j];
 256.325 +        UInt32 sp = original & kIndexMask;
 256.326 +        if (sp < NumSortedBytes) sp += BlockSize; sp -= NumSortedBytes;
 256.327 +        ind2[j] = sp | (original & ~kIndexMask);
 256.328 +        Groups[sp] = group;
 256.329 +        if (--subGroupSize == 0)
 256.330 +          break;
 256.331 +        j++;
 256.332 +        thereAreGroups = 1;
 256.333 +      }
 256.334 +      #else
 256.335 +      UInt32 *Flags = Groups + BlockSize;
 256.336 +      for (;;)
 256.337 +      {
 256.338 +        UInt32 sp = ind2[j]; if (sp < NumSortedBytes) sp += BlockSize; sp -= NumSortedBytes;
 256.339 +        ind2[j] = sp;
 256.340 +        Groups[sp] = group;
 256.341 +        if ((Flags[(groupOffset + j) >> kNumFlagsBits] & (1 << ((groupOffset + j) & kFlagsMask))) == 0)
 256.342 +          break;
 256.343 +        j++;
 256.344 +        thereAreGroups = 1;
 256.345 +      }
 256.346 +      #endif
 256.347 +    }
 256.348 +    return thereAreGroups;
 256.349 +    }
 256.350 +  }
 256.351 +  #endif
 256.352 +}
 256.353 +
 256.354 +/* conditions: blockSize > 0 */
 256.355 +UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
 256.356 +{
 256.357 +  UInt32 *counters = Indices + blockSize;
 256.358 +  UInt32 i;
 256.359 +  UInt32 *Groups;
 256.360 +  #ifdef BLOCK_SORT_EXTERNAL_FLAGS
 256.361 +  UInt32 *Flags;
 256.362 +  #endif
 256.363 +
 256.364 +  /* Radix-Sort for 2 bytes */
 256.365 +  for (i = 0; i < kNumHashValues; i++)
 256.366 +    counters[i] = 0;
 256.367 +  for (i = 0; i < blockSize - 1; i++)
 256.368 +    counters[((UInt32)data[i] << 8) | data[i + 1]]++;
 256.369 +  counters[((UInt32)data[i] << 8) | data[0]]++;
 256.370 +
 256.371 +  Groups = counters + BS_TEMP_SIZE;
 256.372 +  #ifdef BLOCK_SORT_EXTERNAL_FLAGS
 256.373 +  Flags = Groups + blockSize;
 256.374 +    {
 256.375 +      UInt32 numWords = (blockSize + kFlagsMask) >> kNumFlagsBits;
 256.376 +      for (i = 0; i < numWords; i++)
 256.377 +        Flags[i] = kAllFlags;
 256.378 +    }
 256.379 +  #endif
 256.380 +
 256.381 +  {
 256.382 +    UInt32 sum = 0;
 256.383 +    for (i = 0; i < kNumHashValues; i++)
 256.384 +    {
 256.385 +      UInt32 groupSize = counters[i];
 256.386 +      if (groupSize > 0)
 256.387 +      {
 256.388 +        #ifdef BLOCK_SORT_EXTERNAL_FLAGS
 256.389 +        UInt32 t = sum + groupSize - 1;
 256.390 +        Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
 256.391 +        #endif
 256.392 +        sum += groupSize;
 256.393 +      }
 256.394 +      counters[i] = sum - groupSize;
 256.395 +    }
 256.396 +
 256.397 +    for (i = 0; i < blockSize - 1; i++)
 256.398 +      Groups[i] = counters[((UInt32)data[i] << 8) | data[i + 1]];
 256.399 +    Groups[i] = counters[((UInt32)data[i] << 8) | data[0]];
 256.400 +
 256.401 +    for (i = 0; i < blockSize - 1; i++)
 256.402 +      Indices[counters[((UInt32)data[i] << 8) | data[i + 1]]++] = i;
 256.403 +    Indices[counters[((UInt32)data[i] << 8) | data[0]]++] = i;
 256.404 +    
 256.405 +    #ifndef BLOCK_SORT_EXTERNAL_FLAGS
 256.406 +    {
 256.407 +    UInt32 prev = 0;
 256.408 +    for (i = 0; i < kNumHashValues; i++)
 256.409 +    {
 256.410 +      UInt32 prevGroupSize = counters[i] - prev;
 256.411 +      if (prevGroupSize == 0)
 256.412 +        continue;
 256.413 +      SetGroupSize(Indices + prev, prevGroupSize);
 256.414 +      prev = counters[i];
 256.415 +    }
 256.416 +    }
 256.417 +    #endif
 256.418 +  }
 256.419 +
 256.420 +  {
 256.421 +  int NumRefBits;
 256.422 +  UInt32 NumSortedBytes;
 256.423 +  for (NumRefBits = 0; ((blockSize - 1) >> NumRefBits) != 0; NumRefBits++);
 256.424 +  NumRefBits = 32 - NumRefBits;
 256.425 +  if (NumRefBits > kNumRefBitsMax)
 256.426 +    NumRefBits = kNumRefBitsMax;
 256.427 +
 256.428 +  for (NumSortedBytes = kNumHashBytes; ; NumSortedBytes <<= 1)
 256.429 +  {
 256.430 +    #ifndef BLOCK_SORT_EXTERNAL_FLAGS
 256.431 +    UInt32 finishedGroupSize = 0;
 256.432 +    #endif
 256.433 +    UInt32 newLimit = 0;
 256.434 +    for (i = 0; i < blockSize;)
 256.435 +    {
 256.436 +      UInt32 groupSize;
 256.437 +      #ifdef BLOCK_SORT_EXTERNAL_FLAGS
 256.438 +
 256.439 +      if ((Flags[i >> kNumFlagsBits] & (1 << (i & kFlagsMask))) == 0)
 256.440 +      {
 256.441 +        i++;
 256.442 +        continue;
 256.443 +      }
 256.444 +      for (groupSize = 1;
 256.445 +        (Flags[(i + groupSize) >> kNumFlagsBits] & (1 << ((i + groupSize) & kFlagsMask))) != 0;
 256.446 +        groupSize++);
 256.447 +      
 256.448 +      groupSize++;
 256.449 +
 256.450 +      #else
 256.451 +
 256.452 +      groupSize = ((Indices[i] & ~0xC0000000) >> kNumBitsMax);
 256.453 +      {
 256.454 +      Bool finishedGroup = ((Indices[i] & 0x80000000) == 0);
 256.455 +      if ((Indices[i] & 0x40000000) != 0)
 256.456 +      {
 256.457 +        groupSize += ((Indices[i + 1] >> kNumBitsMax) << kNumExtra0Bits);
 256.458 +        Indices[i + 1] &= kIndexMask;
 256.459 +      }
 256.460 +      Indices[i] &= kIndexMask;
 256.461 +      groupSize++;
 256.462 +      if (finishedGroup || groupSize == 1)
 256.463 +      {
 256.464 +        Indices[i - finishedGroupSize] &= kIndexMask;
 256.465 +        if (finishedGroupSize > 1)
 256.466 +          Indices[i - finishedGroupSize + 1] &= kIndexMask;
 256.467 +        {
 256.468 +        UInt32 newGroupSize = groupSize + finishedGroupSize;
 256.469 +        SetFinishedGroupSize(Indices + i - finishedGroupSize, newGroupSize);
 256.470 +        finishedGroupSize = newGroupSize;
 256.471 +        }
 256.472 +        i += groupSize;
 256.473 +        continue;
 256.474 +      }
 256.475 +      finishedGroupSize = 0;
 256.476 +      }
 256.477 +
 256.478 +      #endif
 256.479 +      
 256.480 +      if (NumSortedBytes >= blockSize)
 256.481 +      {
 256.482 +        UInt32 j;
 256.483 +        for (j = 0; j < groupSize; j++)
 256.484 +        {
 256.485 +          UInt32 t = (i + j);
 256.486 +          /* Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask)); */
 256.487 +          Groups[Indices[t]] = t;
 256.488 +        }
 256.489 +      }
 256.490 +      else
 256.491 +        if (SortGroup(blockSize, NumSortedBytes, i, groupSize, NumRefBits, Indices
 256.492 +          #ifndef BLOCK_SORT_USE_HEAP_SORT
 256.493 +          , 0, blockSize
 256.494 +          #endif
 256.495 +          ) != 0)
 256.496 +          newLimit = i + groupSize;
 256.497 +      i += groupSize;
 256.498 +    }
 256.499 +    if (newLimit == 0)
 256.500 +      break;
 256.501 +  }
 256.502 +  }
 256.503 +  #ifndef BLOCK_SORT_EXTERNAL_FLAGS
 256.504 +  for (i = 0; i < blockSize;)
 256.505 +  {
 256.506 +    UInt32 groupSize = ((Indices[i] & ~0xC0000000) >> kNumBitsMax);
 256.507 +    if ((Indices[i] & 0x40000000) != 0)
 256.508 +    {
 256.509 +      groupSize += ((Indices[i + 1] >> kNumBitsMax) << kNumExtra0Bits);
 256.510 +      Indices[i + 1] &= kIndexMask;
 256.511 +    }
 256.512 +    Indices[i] &= kIndexMask;
 256.513 +    groupSize++;
 256.514 +    i += groupSize;
 256.515 +  }
 256.516 +  #endif
 256.517 +  return Groups[0];
 256.518 +}
 256.519 +
   257.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   257.2 +++ b/src/win32/7zip/7z/C/BwtSort.h	Sat Mar 03 10:31:27 2012 -0600
   257.3 @@ -0,0 +1,24 @@
   257.4 +/* BwtSort.h -- BWT block sorting
   257.5 +2008-03-26
   257.6 +Igor Pavlov
   257.7 +Public domain */
   257.8 +
   257.9 +#ifndef __BWTSORT_H
  257.10 +#define __BWTSORT_H
  257.11 +
  257.12 +#include "Types.h"
  257.13 +
  257.14 +/* use BLOCK_SORT_EXTERNAL_FLAGS if blockSize can be > 1M */
  257.15 +/* #define BLOCK_SORT_EXTERNAL_FLAGS */
  257.16 +
  257.17 +#ifdef BLOCK_SORT_EXTERNAL_FLAGS
  257.18 +#define BLOCK_SORT_EXTERNAL_SIZE(blockSize) ((((blockSize) + 31) >> 5))
  257.19 +#else
  257.20 +#define BLOCK_SORT_EXTERNAL_SIZE(blockSize) 0
  257.21 +#endif
  257.22 +
  257.23 +#define BLOCK_SORT_BUF_SIZE(blockSize) ((blockSize) * 2 + BLOCK_SORT_EXTERNAL_SIZE(blockSize) + (1 << 16))
  257.24 +
  257.25 +UInt32 BlockSort(UInt32 *indices, const Byte *data, UInt32 blockSize);
  257.26 +
  257.27 +#endif
   258.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   258.2 +++ b/src/win32/7zip/7z/C/CpuArch.h	Sat Mar 03 10:31:27 2012 -0600
   258.3 @@ -0,0 +1,69 @@
   258.4 +/* CpuArch.h
   258.5 +2008-08-05
   258.6 +Igor Pavlov
   258.7 +Public domain */
   258.8 +
   258.9 +#ifndef __CPUARCH_H
  258.10 +#define __CPUARCH_H
  258.11 +
  258.12 +/*
  258.13 +LITTLE_ENDIAN_UNALIGN means:
  258.14 +  1) CPU is LITTLE_ENDIAN
  258.15 +  2) it's allowed to make unaligned memory accesses
  258.16 +if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know
  258.17 +about these properties of platform.
  258.18 +*/
  258.19 +
  258.20 +#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)
  258.21 +#define LITTLE_ENDIAN_UNALIGN
  258.22 +#endif
  258.23 +
  258.24 +#ifdef LITTLE_ENDIAN_UNALIGN
  258.25 +
  258.26 +#define GetUi16(p) (*(const UInt16 *)(p))
  258.27 +#define GetUi32(p) (*(const UInt32 *)(p))
  258.28 +#define GetUi64(p) (*(const UInt64 *)(p))
  258.29 +#define SetUi32(p, d) *(UInt32 *)(p) = (d);
  258.30 +
  258.31 +#else
  258.32 +
  258.33 +#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))
  258.34 +
  258.35 +#define GetUi32(p) ( \
  258.36 +             ((const Byte *)(p))[0]        | \
  258.37 +    ((UInt32)((const Byte *)(p))[1] <<  8) | \
  258.38 +    ((UInt32)((const Byte *)(p))[2] << 16) | \
  258.39 +    ((UInt32)((const Byte *)(p))[3] << 24))
  258.40 +
  258.41 +#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
  258.42 +
  258.43 +#define SetUi32(p, d) { UInt32 _x_ = (d); \
  258.44 +    ((Byte *)(p))[0] = (Byte)_x_; \
  258.45 +    ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \
  258.46 +    ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \
  258.47 +    ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }
  258.48 +
  258.49 +#endif
  258.50 +
  258.51 +#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)
  258.52 +
  258.53 +#pragma intrinsic(_byteswap_ulong)
  258.54 +#pragma intrinsic(_byteswap_uint64)
  258.55 +#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
  258.56 +#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
  258.57 +
  258.58 +#else
  258.59 +
  258.60 +#define GetBe32(p) ( \
  258.61 +    ((UInt32)((const Byte *)(p))[0] << 24) | \
  258.62 +    ((UInt32)((const Byte *)(p))[1] << 16) | \
  258.63 +    ((UInt32)((const Byte *)(p))[2] <<  8) | \
  258.64 +             ((const Byte *)(p))[3] )
  258.65 +
  258.66 +#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
  258.67 +
  258.68 +#endif
  258.69 +
  258.70 +#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])
  258.71 +
  258.72 +#endif
   259.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   259.2 +++ b/src/win32/7zip/7z/C/HuffEnc.c	Sat Mar 03 10:31:27 2012 -0600
   259.3 @@ -0,0 +1,148 @@
   259.4 +/* HuffEnc.c -- functions for Huffman encoding
   259.5 +2008-08-05
   259.6 +Igor Pavlov
   259.7 +Public domain */
   259.8 +
   259.9 +#include "HuffEnc.h"
  259.10 +#include "Sort.h"
  259.11 +
  259.12 +#define kMaxLen 16
  259.13 +#define NUM_BITS 10
  259.14 +#define MASK ((1 << NUM_BITS) - 1)
  259.15 +
  259.16 +#define NUM_COUNTERS 64
  259.17 +
  259.18 +#define HUFFMAN_SPEED_OPT
  259.19 +
  259.20 +void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymbols, UInt32 maxLen)
  259.21 +{
  259.22 +  UInt32 num = 0;
  259.23 +  /* if (maxLen > 10) maxLen = 10; */
  259.24 +  {
  259.25 +    UInt32 i;
  259.26 +    
  259.27 +    #ifdef HUFFMAN_SPEED_OPT
  259.28 +    
  259.29 +    UInt32 counters[NUM_COUNTERS];
  259.30 +    for (i = 0; i < NUM_COUNTERS; i++)
  259.31 +      counters[i] = 0;
  259.32 +    for (i = 0; i < numSymbols; i++)
  259.33 +    {
  259.34 +      UInt32 freq = freqs[i];
  259.35 +      counters[(freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1]++;
  259.36 +    }
  259.37 + 
  259.38 +    for (i = 1; i < NUM_COUNTERS; i++)
  259.39 +    {
  259.40 +      UInt32 temp = counters[i];
  259.41 +      counters[i] = num;
  259.42 +      num += temp;
  259.43 +    }
  259.44 +
  259.45 +    for (i = 0; i < numSymbols; i++)
  259.46 +    {
  259.47 +      UInt32 freq = freqs[i];
  259.48 +      if (freq == 0)
  259.49 +        lens[i] = 0;
  259.50 +      else
  259.51 +        p[counters[((freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1)]++] = i | (freq << NUM_BITS);
  259.52 +    }
  259.53 +    counters[0] = 0;
  259.54 +    HeapSort(p + counters[NUM_COUNTERS - 2], counters[NUM_COUNTERS - 1] - counters[NUM_COUNTERS - 2]);
  259.55 +    
  259.56 +    #else
  259.57 +
  259.58 +    for (i = 0; i < numSymbols; i++)
  259.59 +    {
  259.60 +      UInt32 freq = freqs[i];
  259.61 +      if (freq == 0)
  259.62 +        lens[i] = 0;
  259.63 +      else
  259.64 +        p[num++] = i | (freq << NUM_BITS);
  259.65 +    }
  259.66 +    HeapSort(p, num);
  259.67 +
  259.68 +    #endif
  259.69 +  }
  259.70 +
  259.71 +  if (num < 2)
  259.72 +  {
  259.73 +    int minCode = 0;
  259.74 +    int maxCode = 1;
  259.75 +    if (num == 1)
  259.76 +    {
  259.77 +      maxCode = (int)(p[0] & MASK);
  259.78 +      if (maxCode == 0)
  259.79 +        maxCode++;
  259.80 +    }
  259.81 +    p[minCode] = 0;
  259.82 +    p[maxCode] = 1;
  259.83 +    lens[minCode] = lens[maxCode] = 1;
  259.84 +    return;
  259.85 +  }
  259.86 +  
  259.87 +  {
  259.88 +    UInt32 b, e, i;
  259.89 +  
  259.90 +    i = b = e = 0;
  259.91 +    do
  259.92 +    {
  259.93 +      UInt32 n, m, freq;
  259.94 +      n = (i != num && (b == e || (p[i] >> NUM_BITS) <= (p[b] >> NUM_BITS))) ? i++ : b++;
  259.95 +      freq = (p[n] & ~MASK);
  259.96 +      p[n] = (p[n] & MASK) | (e << NUM_BITS);
  259.97 +      m = (i != num && (b == e || (p[i] >> NUM_BITS) <= (p[b] >> NUM_BITS))) ? i++ : b++;
  259.98 +      freq += (p[m] & ~MASK);
  259.99 +      p[m] = (p[m] & MASK) | (e << NUM_BITS);
 259.100 +      p[e] = (p[e] & MASK) | freq;
 259.101 +      e++;
 259.102 +    }
 259.103 +    while (num - e > 1);
 259.104 +    
 259.105 +    {
 259.106 +      UInt32 lenCounters[kMaxLen + 1];
 259.107 +      for (i = 0; i <= kMaxLen; i++)
 259.108 +        lenCounters[i] = 0;
 259.109 +      
 259.110 +      p[--e] &= MASK;
 259.111 +      lenCounters[1] = 2;
 259.112 +      while (e > 0)
 259.113 +      {
 259.114 +        UInt32 len = (p[p[--e] >> NUM_BITS] >> NUM_BITS) + 1;
 259.115 +        p[e] = (p[e] & MASK) | (len << NUM_BITS);
 259.116 +        if (len >= maxLen)
 259.117 +          for (len = maxLen - 1; lenCounters[len] == 0; len--);
 259.118 +        lenCounters[len]--;
 259.119 +        lenCounters[len + 1] += 2;
 259.120 +      }
 259.121 +      
 259.122 +      {
 259.123 +        UInt32 len;
 259.124 +        i = 0;
 259.125 +        for (len = maxLen; len != 0; len--)
 259.126 +        {
 259.127 +          UInt32 num;
 259.128 +          for (num = lenCounters[len]; num != 0; num--)
 259.129 +            lens[p[i++] & MASK] = (Byte)len;
 259.130 +        }
 259.131 +      }
 259.132 +      
 259.133 +      {
 259.134 +        UInt32 nextCodes[kMaxLen + 1];
 259.135 +        {
 259.136 +          UInt32 code = 0;
 259.137 +          UInt32 len;
 259.138 +          for (len = 1; len <= kMaxLen; len++)
 259.139 +            nextCodes[len] = code = (code + lenCounters[len - 1]) << 1;
 259.140 +        }
 259.141 +        /* if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1; */
 259.142 +
 259.143 +        {
 259.144 +          UInt32 i;
 259.145 +          for (i = 0; i < numSymbols; i++)
 259.146 +            p[i] = nextCodes[lens[i]]++;
 259.147 +        }
 259.148 +      }
 259.149 +    }
 259.150 +  }
 259.151 +}
   260.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   260.2 +++ b/src/win32/7zip/7z/C/HuffEnc.h	Sat Mar 03 10:31:27 2012 -0600
   260.3 @@ -0,0 +1,21 @@
   260.4 +/* HuffEnc.h -- functions for Huffman encoding
   260.5 +2008-03-26
   260.6 +Igor Pavlov
   260.7 +Public domain */
   260.8 +
   260.9 +#ifndef __HUFFENC_H
  260.10 +#define __HUFFENC_H
  260.11 +
  260.12 +#include "Types.h"
  260.13 +
  260.14 +/*
  260.15 +Conditions:
  260.16 +  num <= 1024 = 2 ^ NUM_BITS
  260.17 +  Sum(freqs) < 4M = 2 ^ (32 - NUM_BITS)
  260.18 +  maxLen <= 16 = kMaxLen
  260.19 +  Num_Items(p) >= HUFFMAN_TEMP_SIZE(num)
  260.20 +*/
  260.21 + 
  260.22 +void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 num, UInt32 maxLen);
  260.23 +
  260.24 +#endif
   261.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   261.2 +++ b/src/win32/7zip/7z/C/LzFind.c	Sat Mar 03 10:31:27 2012 -0600
   261.3 @@ -0,0 +1,751 @@
   261.4 +/* LzFind.c -- Match finder for LZ algorithms
   261.5 +2008-10-04 : Igor Pavlov : Public domain */
   261.6 +
   261.7 +#include <string.h>
   261.8 +
   261.9 +#include "LzFind.h"
  261.10 +#include "LzHash.h"
  261.11 +
  261.12 +#define kEmptyHashValue 0
  261.13 +#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)
  261.14 +#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */
  261.15 +#define kNormalizeMask (~(kNormalizeStepMin - 1))
  261.16 +#define kMaxHistorySize ((UInt32)3 << 30)
  261.17 +
  261.18 +#define kStartMaxLen 3
  261.19 +
  261.20 +static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
  261.21 +{
  261.22 +  if (!p->directInput)
  261.23 +  {
  261.24 +    alloc->Free(alloc, p->bufferBase);
  261.25 +    p->bufferBase = 0;
  261.26 +  }
  261.27 +}
  261.28 +
  261.29 +/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */
  261.30 +
  261.31 +static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
  261.32 +{
  261.33 +  UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
  261.34 +  if (p->directInput)
  261.35 +  {
  261.36 +    p->blockSize = blockSize;
  261.37 +    return 1;
  261.38 +  }
  261.39 +  if (p->bufferBase == 0 || p->blockSize != blockSize)
  261.40 +  {
  261.41 +    LzInWindow_Free(p, alloc);
  261.42 +    p->blockSize = blockSize;
  261.43 +    p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);
  261.44 +  }
  261.45 +  return (p->bufferBase != 0);
  261.46 +}
  261.47 +
  261.48 +Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
  261.49 +Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
  261.50 +
  261.51 +UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
  261.52 +
  261.53 +void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
  261.54 +{
  261.55 +  p->posLimit -= subValue;
  261.56 +  p->pos -= subValue;
  261.57 +  p->streamPos -= subValue;
  261.58 +}
  261.59 +
  261.60 +static void MatchFinder_ReadBlock(CMatchFinder *p)
  261.61 +{
  261.62 +  if (p->streamEndWasReached || p->result != SZ_OK)
  261.63 +    return;
  261.64 +  for (;;)
  261.65 +  {
  261.66 +    Byte *dest = p->buffer + (p->streamPos - p->pos);
  261.67 +    size_t size = (p->bufferBase + p->blockSize - dest);
  261.68 +    if (size == 0)
  261.69 +      return;
  261.70 +    p->result = p->stream->Read(p->stream, dest, &size);
  261.71 +    if (p->result != SZ_OK)
  261.72 +      return;
  261.73 +    if (size == 0)
  261.74 +    {
  261.75 +      p->streamEndWasReached = 1;
  261.76 +      return;
  261.77 +    }
  261.78 +    p->streamPos += (UInt32)size;
  261.79 +    if (p->streamPos - p->pos > p->keepSizeAfter)
  261.80 +      return;
  261.81 +  }
  261.82 +}
  261.83 +
  261.84 +void MatchFinder_MoveBlock(CMatchFinder *p)
  261.85 +{
  261.86 +  memmove(p->bufferBase,
  261.87 +    p->buffer - p->keepSizeBefore,
  261.88 +    (size_t)(p->streamPos - p->pos + p->keepSizeBefore));
  261.89 +  p->buffer = p->bufferBase + p->keepSizeBefore;
  261.90 +}
  261.91 +
  261.92 +int MatchFinder_NeedMove(CMatchFinder *p)
  261.93 +{
  261.94 +  /* if (p->streamEndWasReached) return 0; */
  261.95 +  return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
  261.96 +}
  261.97 +
  261.98 +void MatchFinder_ReadIfRequired(CMatchFinder *p)
  261.99 +{
 261.100 +  if (p->streamEndWasReached)
 261.101 +    return;
 261.102 +  if (p->keepSizeAfter >= p->streamPos - p->pos)
 261.103 +    MatchFinder_ReadBlock(p);
 261.104 +}
 261.105 +
 261.106 +static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
 261.107 +{
 261.108 +  if (MatchFinder_NeedMove(p))
 261.109 +    MatchFinder_MoveBlock(p);
 261.110 +  MatchFinder_ReadBlock(p);
 261.111 +}
 261.112 +
 261.113 +static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
 261.114 +{
 261.115 +  p->cutValue = 32;
 261.116 +  p->btMode = 1;
 261.117 +  p->numHashBytes = 4;
 261.118 +  /* p->skipModeBits = 0; */
 261.119 +  p->directInput = 0;
 261.120 +  p->bigHash = 0;
 261.121 +}
 261.122 +
 261.123 +#define kCrcPoly 0xEDB88320
 261.124 +
 261.125 +void MatchFinder_Construct(CMatchFinder *p)
 261.126 +{
 261.127 +  UInt32 i;
 261.128 +  p->bufferBase = 0;
 261.129 +  p->directInput = 0;
 261.130 +  p->hash = 0;
 261.131 +  MatchFinder_SetDefaultSettings(p);
 261.132 +
 261.133 +  for (i = 0; i < 256; i++)
 261.134 +  {
 261.135 +    UInt32 r = i;
 261.136 +    int j;
 261.137 +    for (j = 0; j < 8; j++)
 261.138 +      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
 261.139 +    p->crc[i] = r;
 261.140 +  }
 261.141 +}
 261.142 +
 261.143 +static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)
 261.144 +{
 261.145 +  alloc->Free(alloc, p->hash);
 261.146 +  p->hash = 0;
 261.147 +}
 261.148 +
 261.149 +void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)
 261.150 +{
 261.151 +  MatchFinder_FreeThisClassMemory(p, alloc);
 261.152 +  LzInWindow_Free(p, alloc);
 261.153 +}
 261.154 +
 261.155 +static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)
 261.156 +{
 261.157 +  size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
 261.158 +  if (sizeInBytes / sizeof(CLzRef) != num)
 261.159 +    return 0;
 261.160 +  return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);
 261.161 +}
 261.162 +
 261.163 +int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
 261.164 +    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
 261.165 +    ISzAlloc *alloc)
 261.166 +{
 261.167 +  UInt32 sizeReserv;
 261.168 +  if (historySize > kMaxHistorySize)
 261.169 +  {
 261.170 +    MatchFinder_Free(p, alloc);
 261.171 +    return 0;
 261.172 +  }
 261.173 +  sizeReserv = historySize >> 1;
 261.174 +  if (historySize > ((UInt32)2 << 30))
 261.175 +    sizeReserv = historySize >> 2;
 261.176 +  sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);
 261.177 +
 261.178 +  p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
 261.179 +  p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;
 261.180 +  /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */
 261.181 +  if (LzInWindow_Create(p, sizeReserv, alloc))
 261.182 +  {
 261.183 +    UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;
 261.184 +    UInt32 hs;
 261.185 +    p->matchMaxLen = matchMaxLen;
 261.186 +    {
 261.187 +      p->fixedHashSize = 0;
 261.188 +      if (p->numHashBytes == 2)
 261.189 +        hs = (1 << 16) - 1;
 261.190 +      else
 261.191 +      {
 261.192 +        hs = historySize - 1;
 261.193 +        hs |= (hs >> 1);
 261.194 +        hs |= (hs >> 2);
 261.195 +        hs |= (hs >> 4);
 261.196 +        hs |= (hs >> 8);
 261.197 +        hs >>= 1;
 261.198 +        /* hs >>= p->skipModeBits; */
 261.199 +        hs |= 0xFFFF; /* don't change it! It's required for Deflate */
 261.200 +        if (hs > (1 << 24))
 261.201 +        {
 261.202 +          if (p->numHashBytes == 3)
 261.203 +            hs = (1 << 24) - 1;
 261.204 +          else
 261.205 +            hs >>= 1;
 261.206 +        }
 261.207 +      }
 261.208 +      p->hashMask = hs;
 261.209 +      hs++;
 261.210 +      if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;
 261.211 +      if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;
 261.212 +      if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;
 261.213 +      hs += p->fixedHashSize;
 261.214 +    }
 261.215 +
 261.216 +    {
 261.217 +      UInt32 prevSize = p->hashSizeSum + p->numSons;
 261.218 +      UInt32 newSize;
 261.219 +      p->historySize = historySize;
 261.220 +      p->hashSizeSum = hs;
 261.221 +      p->cyclicBufferSize = newCyclicBufferSize;
 261.222 +      p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);
 261.223 +      newSize = p->hashSizeSum + p->numSons;
 261.224 +      if (p->hash != 0 && prevSize == newSize)
 261.225 +        return 1;
 261.226 +      MatchFinder_FreeThisClassMemory(p, alloc);
 261.227 +      p->hash = AllocRefs(newSize, alloc);
 261.228 +      if (p->hash != 0)
 261.229 +      {
 261.230 +        p->son = p->hash + p->hashSizeSum;
 261.231 +        return 1;
 261.232 +      }
 261.233 +    }
 261.234 +  }
 261.235 +  MatchFinder_Free(p, alloc);
 261.236 +  return 0;
 261.237 +}
 261.238 +
 261.239 +static void MatchFinder_SetLimits(CMatchFinder *p)
 261.240 +{
 261.241 +  UInt32 limit = kMaxValForNormalize - p->pos;
 261.242 +  UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
 261.243 +  if (limit2 < limit)
 261.244 +    limit = limit2;
 261.245 +  limit2 = p->streamPos - p->pos;
 261.246 +  if (limit2 <= p->keepSizeAfter)
 261.247 +  {
 261.248 +    if (limit2 > 0)
 261.249 +      limit2 = 1;
 261.250 +  }
 261.251 +  else
 261.252 +    limit2 -= p->keepSizeAfter;
 261.253 +  if (limit2 < limit)
 261.254 +    limit = limit2;
 261.255 +  {
 261.256 +    UInt32 lenLimit = p->streamPos - p->pos;
 261.257 +    if (lenLimit > p->matchMaxLen)
 261.258 +      lenLimit = p->matchMaxLen;
 261.259 +    p->lenLimit = lenLimit;
 261.260 +  }
 261.261 +  p->posLimit = p->pos + limit;
 261.262 +}
 261.263 +
 261.264 +void MatchFinder_Init(CMatchFinder *p)
 261.265 +{
 261.266 +  UInt32 i;
 261.267 +  for (i = 0; i < p->hashSizeSum; i++)
 261.268 +    p->hash[i] = kEmptyHashValue;
 261.269 +  p->cyclicBufferPos = 0;
 261.270 +  p->buffer = p->bufferBase;
 261.271 +  p->pos = p->streamPos = p->cyclicBufferSize;
 261.272 +  p->result = SZ_OK;
 261.273 +  p->streamEndWasReached = 0;
 261.274 +  MatchFinder_ReadBlock(p);
 261.275 +  MatchFinder_SetLimits(p);
 261.276 +}
 261.277 +
 261.278 +static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
 261.279 +{
 261.280 +  return (p->pos - p->historySize - 1) & kNormalizeMask;
 261.281 +}
 261.282 +
 261.283 +void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
 261.284 +{
 261.285 +  UInt32 i;
 261.286 +  for (i = 0; i < numItems; i++)
 261.287 +  {
 261.288 +    UInt32 value = items[i];
 261.289 +    if (value <= subValue)
 261.290 +      value = kEmptyHashValue;
 261.291 +    else
 261.292 +      value -= subValue;
 261.293 +    items[i] = value;
 261.294 +  }
 261.295 +}
 261.296 +
 261.297 +static void MatchFinder_Normalize(CMatchFinder *p)
 261.298 +{
 261.299 +  UInt32 subValue = MatchFinder_GetSubValue(p);
 261.300 +  MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);
 261.301 +  MatchFinder_ReduceOffsets(p, subValue);
 261.302 +}
 261.303 +
 261.304 +static void MatchFinder_CheckLimits(CMatchFinder *p)
 261.305 +{
 261.306 +  if (p->pos == kMaxValForNormalize)
 261.307 +    MatchFinder_Normalize(p);
 261.308 +  if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)
 261.309 +    MatchFinder_CheckAndMoveAndRead(p);
 261.310 +  if (p->cyclicBufferPos == p->cyclicBufferSize)
 261.311 +    p->cyclicBufferPos = 0;
 261.312 +  MatchFinder_SetLimits(p);
 261.313 +}
 261.314 +
 261.315 +static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
 261.316 +    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
 261.317 +    UInt32 *distances, UInt32 maxLen)
 261.318 +{
 261.319 +  son[_cyclicBufferPos] = curMatch;
 261.320 +  for (;;)
 261.321 +  {
 261.322 +    UInt32 delta = pos - curMatch;
 261.323 +    if (cutValue-- == 0 || delta >= _cyclicBufferSize)
 261.324 +      return distances;
 261.325 +    {
 261.326 +      const Byte *pb = cur - delta;
 261.327 +      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
 261.328 +      if (pb[maxLen] == cur[maxLen] && *pb == *cur)
 261.329 +      {
 261.330 +        UInt32 len = 0;
 261.331 +        while (++len != lenLimit)
 261.332 +          if (pb[len] != cur[len])
 261.333 +            break;
 261.334 +        if (maxLen < len)
 261.335 +        {
 261.336 +          *distances++ = maxLen = len;
 261.337 +          *distances++ = delta - 1;
 261.338 +          if (len == lenLimit)
 261.339 +            return distances;
 261.340 +        }
 261.341 +      }
 261.342 +    }
 261.343 +  }
 261.344 +}
 261.345 +
 261.346 +UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
 261.347 +    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
 261.348 +    UInt32 *distances, UInt32 maxLen)
 261.349 +{
 261.350 +  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
 261.351 +  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
 261.352 +  UInt32 len0 = 0, len1 = 0;
 261.353 +  for (;;)
 261.354 +  {
 261.355 +    UInt32 delta = pos - curMatch;
 261.356 +    if (cutValue-- == 0 || delta >= _cyclicBufferSize)
 261.357 +    {
 261.358 +      *ptr0 = *ptr1 = kEmptyHashValue;
 261.359 +      return distances;
 261.360 +    }
 261.361 +    {
 261.362 +      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
 261.363 +      const Byte *pb = cur - delta;
 261.364 +      UInt32 len = (len0 < len1 ? len0 : len1);
 261.365 +      if (pb[len] == cur[len])
 261.366 +      {
 261.367 +        if (++len != lenLimit && pb[len] == cur[len])
 261.368 +          while (++len != lenLimit)
 261.369 +            if (pb[len] != cur[len])
 261.370 +              break;
 261.371 +        if (maxLen < len)
 261.372 +        {
 261.373 +          *distances++ = maxLen = len;
 261.374 +          *distances++ = delta - 1;
 261.375 +          if (len == lenLimit)
 261.376 +          {
 261.377 +            *ptr1 = pair[0];
 261.378 +            *ptr0 = pair[1];
 261.379 +            return distances;
 261.380 +          }
 261.381 +        }
 261.382 +      }
 261.383 +      if (pb[len] < cur[len])
 261.384 +      {
 261.385 +        *ptr1 = curMatch;
 261.386 +        ptr1 = pair + 1;
 261.387 +        curMatch = *ptr1;
 261.388 +        len1 = len;
 261.389 +      }
 261.390 +      else
 261.391 +      {
 261.392 +        *ptr0 = curMatch;
 261.393 +        ptr0 = pair;
 261.394 +        curMatch = *ptr0;
 261.395 +        len0 = len;
 261.396 +      }
 261.397 +    }
 261.398 +  }
 261.399 +}
 261.400 +
 261.401 +static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
 261.402 +    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)
 261.403 +{
 261.404 +  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
 261.405 +  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
 261.406 +  UInt32 len0 = 0, len1 = 0;
 261.407 +  for (;;)
 261.408 +  {
 261.409 +    UInt32 delta = pos - curMatch;
 261.410 +    if (cutValue-- == 0 || delta >= _cyclicBufferSize)
 261.411 +    {
 261.412 +      *ptr0 = *ptr1 = kEmptyHashValue;
 261.413 +      return;
 261.414 +    }
 261.415 +    {
 261.416 +      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
 261.417 +      const Byte *pb = cur - delta;
 261.418 +      UInt32 len = (len0 < len1 ? len0 : len1);
 261.419 +      if (pb[len] == cur[len])
 261.420 +      {
 261.421 +        while (++len != lenLimit)
 261.422 +          if (pb[len] != cur[len])
 261.423 +            break;
 261.424 +        {
 261.425 +          if (len == lenLimit)
 261.426 +          {
 261.427 +            *ptr1 = pair[0];
 261.428 +            *ptr0 = pair[1];
 261.429 +            return;
 261.430 +          }
 261.431 +        }
 261.432 +      }
 261.433 +      if (pb[len] < cur[len])
 261.434 +      {
 261.435 +        *ptr1 = curMatch;
 261.436 +        ptr1 = pair + 1;
 261.437 +        curMatch = *ptr1;
 261.438 +        len1 = len;
 261.439 +      }
 261.440 +      else
 261.441 +      {
 261.442 +        *ptr0 = curMatch;
 261.443 +        ptr0 = pair;
 261.444 +        curMatch = *ptr0;
 261.445 +        len0 = len;
 261.446 +      }
 261.447 +    }
 261.448 +  }
 261.449 +}
 261.450 +
 261.451 +#define MOVE_POS \
 261.452 +  ++p->cyclicBufferPos; \
 261.453 +  p->buffer++; \
 261.454 +  if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
 261.455 +
 261.456 +#define MOVE_POS_RET MOVE_POS return offset;
 261.457 +
 261.458 +static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
 261.459 +
 261.460 +#define GET_MATCHES_HEADER2(minLen, ret_op) \
 261.461 +  UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \
 261.462 +  lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
 261.463 +  cur = p->buffer;
 261.464 +
 261.465 +#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)
 261.466 +#define SKIP_HEADER(minLen)        GET_MATCHES_HEADER2(minLen, continue)
 261.467 +
 261.468 +#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
 261.469 +
 261.470 +#define GET_MATCHES_FOOTER(offset, maxLen) \
 261.471 +  offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \
 261.472 +  distances + offset, maxLen) - distances); MOVE_POS_RET;
 261.473 +
 261.474 +#define SKIP_FOOTER \
 261.475 +  SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
 261.476 +
 261.477 +static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
 261.478 +{
 261.479 +  UInt32 offset;
 261.480 +  GET_MATCHES_HEADER(2)
 261.481 +  HASH2_CALC;
 261.482 +  curMatch = p->hash[hashValue];
 261.483 +  p->hash[hashValue] = p->pos;
 261.484 +  offset = 0;
 261.485 +  GET_MATCHES_FOOTER(offset, 1)
 261.486 +}
 261.487 +
 261.488 +UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
 261.489 +{
 261.490 +  UInt32 offset;
 261.491 +  GET_MATCHES_HEADER(3)
 261.492 +  HASH_ZIP_CALC;
 261.493 +  curMatch = p->hash[hashValue];
 261.494 +  p->hash[hashValue] = p->pos;
 261.495 +  offset = 0;
 261.496 +  GET_MATCHES_FOOTER(offset, 2)
 261.497 +}
 261.498 +
 261.499 +static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
 261.500 +{
 261.501 +  UInt32 hash2Value, delta2, maxLen, offset;
 261.502 +  GET_MATCHES_HEADER(3)
 261.503 +
 261.504 +  HASH3_CALC;
 261.505 +
 261.506 +  delta2 = p->pos - p->hash[hash2Value];
 261.507 +  curMatch = p->hash[kFix3HashSize + hashValue];
 261.508 +  
 261.509 +  p->hash[hash2Value] =
 261.510 +  p->hash[kFix3HashSize + hashValue] = p->pos;
 261.511 +
 261.512 +
 261.513 +  maxLen = 2;
 261.514 +  offset = 0;
 261.515 +  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
 261.516 +  {
 261.517 +    for (; maxLen != lenLimit; maxLen++)
 261.518 +      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
 261.519 +        break;
 261.520 +    distances[0] = maxLen;
 261.521 +    distances[1] = delta2 - 1;
 261.522 +    offset = 2;
 261.523 +    if (maxLen == lenLimit)
 261.524 +    {
 261.525 +      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
 261.526 +      MOVE_POS_RET;
 261.527 +    }
 261.528 +  }
 261.529 +  GET_MATCHES_FOOTER(offset, maxLen)
 261.530 +}
 261.531 +
 261.532 +static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
 261.533 +{
 261.534 +  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
 261.535 +  GET_MATCHES_HEADER(4)
 261.536 +
 261.537 +  HASH4_CALC;
 261.538 +
 261.539 +  delta2 = p->pos - p->hash[                hash2Value];
 261.540 +  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
 261.541 +  curMatch = p->hash[kFix4HashSize + hashValue];
 261.542 +  
 261.543 +  p->hash[                hash2Value] =
 261.544 +  p->hash[kFix3HashSize + hash3Value] =
 261.545 +  p->hash[kFix4HashSize + hashValue] = p->pos;
 261.546 +
 261.547 +  maxLen = 1;
 261.548 +  offset = 0;
 261.549 +  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
 261.550 +  {
 261.551 +    distances[0] = maxLen = 2;
 261.552 +    distances[1] = delta2 - 1;
 261.553 +    offset = 2;
 261.554 +  }
 261.555 +  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
 261.556 +  {
 261.557 +    maxLen = 3;
 261.558 +    distances[offset + 1] = delta3 - 1;
 261.559 +    offset += 2;
 261.560 +    delta2 = delta3;
 261.561 +  }
 261.562 +  if (offset != 0)
 261.563 +  {
 261.564 +    for (; maxLen != lenLimit; maxLen++)
 261.565 +      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
 261.566 +        break;
 261.567 +    distances[offset - 2] = maxLen;
 261.568 +    if (maxLen == lenLimit)
 261.569 +    {
 261.570 +      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
 261.571 +      MOVE_POS_RET;
 261.572 +    }
 261.573 +  }
 261.574 +  if (maxLen < 3)
 261.575 +    maxLen = 3;
 261.576 +  GET_MATCHES_FOOTER(offset, maxLen)
 261.577 +}
 261.578 +
 261.579 +static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
 261.580 +{
 261.581 +  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
 261.582 +  GET_MATCHES_HEADER(4)
 261.583 +
 261.584 +  HASH4_CALC;
 261.585 +
 261.586 +  delta2 = p->pos - p->hash[                hash2Value];
 261.587 +  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
 261.588 +  curMatch = p->hash[kFix4HashSize + hashValue];
 261.589 +
 261.590 +  p->hash[                hash2Value] =
 261.591 +  p->hash[kFix3HashSize + hash3Value] =
 261.592 +  p->hash[kFix4HashSize + hashValue] = p->pos;
 261.593 +
 261.594 +  maxLen = 1;
 261.595 +  offset = 0;
 261.596 +  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
 261.597 +  {
 261.598 +    distances[0] = maxLen = 2;
 261.599 +    distances[1] = delta2 - 1;
 261.600 +    offset = 2;
 261.601 +  }
 261.602 +  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
 261.603 +  {
 261.604 +    maxLen = 3;
 261.605 +    distances[offset + 1] = delta3 - 1;
 261.606 +    offset += 2;
 261.607 +    delta2 = delta3;
 261.608 +  }
 261.609 +  if (offset != 0)
 261.610 +  {
 261.611 +    for (; maxLen != lenLimit; maxLen++)
 261.612 +      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
 261.613 +        break;
 261.614 +    distances[offset - 2] = maxLen;
 261.615 +    if (maxLen == lenLimit)
 261.616 +    {
 261.617 +      p->son[p->cyclicBufferPos] = curMatch;
 261.618 +      MOVE_POS_RET;
 261.619 +    }
 261.620 +  }
 261.621 +  if (maxLen < 3)
 261.622 +    maxLen = 3;
 261.623 +  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
 261.624 +    distances + offset, maxLen) - (distances));
 261.625 +  MOVE_POS_RET
 261.626 +}
 261.627 +
 261.628 +UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
 261.629 +{
 261.630 +  UInt32 offset;
 261.631 +  GET_MATCHES_HEADER(3)
 261.632 +  HASH_ZIP_CALC;
 261.633 +  curMatch = p->hash[hashValue];
 261.634 +  p->hash[hashValue] = p->pos;
 261.635 +  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
 261.636 +    distances, 2) - (distances));
 261.637 +  MOVE_POS_RET
 261.638 +}
 261.639 +
 261.640 +static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
 261.641 +{
 261.642 +  do
 261.643 +  {
 261.644 +    SKIP_HEADER(2)
 261.645 +    HASH2_CALC;
 261.646 +    curMatch = p->hash[hashValue];
 261.647 +    p->hash[hashValue] = p->pos;
 261.648 +    SKIP_FOOTER
 261.649 +  }
 261.650 +  while (--num != 0);
 261.651 +}
 261.652 +
 261.653 +void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
 261.654 +{
 261.655 +  do
 261.656 +  {
 261.657 +    SKIP_HEADER(3)
 261.658 +    HASH_ZIP_CALC;
 261.659 +    curMatch = p->hash[hashValue];
 261.660 +    p->hash[hashValue] = p->pos;
 261.661 +    SKIP_FOOTER
 261.662 +  }
 261.663 +  while (--num != 0);
 261.664 +}
 261.665 +
 261.666 +static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
 261.667 +{
 261.668 +  do
 261.669 +  {
 261.670 +    UInt32 hash2Value;
 261.671 +    SKIP_HEADER(3)
 261.672 +    HASH3_CALC;
 261.673 +    curMatch = p->hash[kFix3HashSize + hashValue];
 261.674 +    p->hash[hash2Value] =
 261.675 +    p->hash[kFix3HashSize + hashValue] = p->pos;
 261.676 +    SKIP_FOOTER
 261.677 +  }
 261.678 +  while (--num != 0);
 261.679 +}
 261.680 +
 261.681 +static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
 261.682 +{
 261.683 +  do
 261.684 +  {
 261.685 +    UInt32 hash2Value, hash3Value;
 261.686 +    SKIP_HEADER(4)
 261.687 +    HASH4_CALC;
 261.688 +    curMatch = p->hash[kFix4HashSize + hashValue];
 261.689 +    p->hash[                hash2Value] =
 261.690 +    p->hash[kFix3HashSize + hash3Value] = p->pos;
 261.691 +    p->hash[kFix4HashSize + hashValue] = p->pos;
 261.692 +    SKIP_FOOTER
 261.693 +  }
 261.694 +  while (--num != 0);
 261.695 +}
 261.696 +
 261.697 +static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
 261.698 +{
 261.699 +  do
 261.700 +  {
 261.701 +    UInt32 hash2Value, hash3Value;
 261.702 +    SKIP_HEADER(4)
 261.703 +    HASH4_CALC;
 261.704 +    curMatch = p->hash[kFix4HashSize + hashValue];
 261.705 +    p->hash[                hash2Value] =
 261.706 +    p->hash[kFix3HashSize + hash3Value] =
 261.707 +    p->hash[kFix4HashSize + hashValue] = p->pos;
 261.708 +    p->son[p->cyclicBufferPos] = curMatch;
 261.709 +    MOVE_POS
 261.710 +  }
 261.711 +  while (--num != 0);
 261.712 +}
 261.713 +
 261.714 +void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
 261.715 +{
 261.716 +  do
 261.717 +  {
 261.718 +    SKIP_HEADER(3)
 261.719 +    HASH_ZIP_CALC;
 261.720 +    curMatch = p->hash[hashValue];
 261.721 +    p->hash[hashValue] = p->pos;
 261.722 +    p->son[p->cyclicBufferPos] = curMatch;
 261.723 +    MOVE_POS
 261.724 +  }
 261.725 +  while (--num != 0);
 261.726 +}
 261.727 +
 261.728 +void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
 261.729 +{
 261.730 +  vTable->Init = (Mf_Init_Func)MatchFinder_Init;
 261.731 +  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;
 261.732 +  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;
 261.733 +  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;
 261.734 +  if (!p->btMode)
 261.735 +  {
 261.736 +    vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
 261.737 +    vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
 261.738 +  }
 261.739 +  else if (p->numHashBytes == 2)
 261.740 +  {
 261.741 +    vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;
 261.742 +    vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
 261.743 +  }
 261.744 +  else if (p->numHashBytes == 3)
 261.745 +  {
 261.746 +    vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
 261.747 +    vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
 261.748 +  }
 261.749 +  else
 261.750 +  {
 261.751 +    vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
 261.752 +    vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
 261.753 +  }
 261.754 +}
   262.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   262.2 +++ b/src/win32/7zip/7z/C/LzFind.h	Sat Mar 03 10:31:27 2012 -0600
   262.3 @@ -0,0 +1,107 @@
   262.4 +/* LzFind.h -- Match finder for LZ algorithms
   262.5 +2008-10-04 : Igor Pavlov : Public domain */
   262.6 +
   262.7 +#ifndef __LZFIND_H
   262.8 +#define __LZFIND_H
   262.9 +
  262.10 +#include "Types.h"
  262.11 +
  262.12 +typedef UInt32 CLzRef;
  262.13 +
  262.14 +typedef struct _CMatchFinder
  262.15 +{
  262.16 +  Byte *buffer;
  262.17 +  UInt32 pos;
  262.18 +  UInt32 posLimit;
  262.19 +  UInt32 streamPos;
  262.20 +  UInt32 lenLimit;
  262.21 +
  262.22 +  UInt32 cyclicBufferPos;
  262.23 +  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
  262.24 +
  262.25 +  UInt32 matchMaxLen;
  262.26 +  CLzRef *hash;
  262.27 +  CLzRef *son;
  262.28 +  UInt32 hashMask;
  262.29 +  UInt32 cutValue;
  262.30 +
  262.31 +  Byte *bufferBase;
  262.32 +  ISeqInStream *stream;
  262.33 +  int streamEndWasReached;
  262.34 +
  262.35 +  UInt32 blockSize;
  262.36 +  UInt32 keepSizeBefore;
  262.37 +  UInt32 keepSizeAfter;
  262.38 +
  262.39 +  UInt32 numHashBytes;
  262.40 +  int directInput;
  262.41 +  int btMode;
  262.42 +  /* int skipModeBits; */
  262.43 +  int bigHash;
  262.44 +  UInt32 historySize;
  262.45 +  UInt32 fixedHashSize;
  262.46 +  UInt32 hashSizeSum;
  262.47 +  UInt32 numSons;
  262.48 +  SRes result;
  262.49 +  UInt32 crc[256];
  262.50 +} CMatchFinder;
  262.51 +
  262.52 +#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
  262.53 +#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])
  262.54 +
  262.55 +#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
  262.56 +
  262.57 +int MatchFinder_NeedMove(CMatchFinder *p);
  262.58 +Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
  262.59 +void MatchFinder_MoveBlock(CMatchFinder *p);
  262.60 +void MatchFinder_ReadIfRequired(CMatchFinder *p);
  262.61 +
  262.62 +void MatchFinder_Construct(CMatchFinder *p);
  262.63 +
  262.64 +/* Conditions:
  262.65 +     historySize <= 3 GB
  262.66 +     keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
  262.67 +*/
  262.68 +int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
  262.69 +    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
  262.70 +    ISzAlloc *alloc);
  262.71 +void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
  262.72 +void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
  262.73 +void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
  262.74 +
  262.75 +UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
  262.76 +    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
  262.77 +    UInt32 *distances, UInt32 maxLen);
  262.78 +
  262.79 +/*
  262.80 +Conditions:
  262.81 +  Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
  262.82 +  Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
  262.83 +*/
  262.84 +
  262.85 +typedef void (*Mf_Init_Func)(void *object);
  262.86 +typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);
  262.87 +typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
  262.88 +typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
  262.89 +typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
  262.90 +typedef void (*Mf_Skip_Func)(void *object, UInt32);
  262.91 +
  262.92 +typedef struct _IMatchFinder
  262.93 +{
  262.94 +  Mf_Init_Func Init;
  262.95 +  Mf_GetIndexByte_Func GetIndexByte;
  262.96 +  Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
  262.97 +  Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
  262.98 +  Mf_GetMatches_Func GetMatches;
  262.99 +  Mf_Skip_Func Skip;
 262.100 +} IMatchFinder;
 262.101 +
 262.102 +void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
 262.103 +
 262.104 +void MatchFinder_Init(CMatchFinder *p);
 262.105 +UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
 262.106 +UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
 262.107 +void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
 262.108 +void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
 262.109 +
 262.110 +#endif
   263.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   263.2 +++ b/src/win32/7zip/7z/C/LzFindMt.c	Sat Mar 03 10:31:27 2012 -0600
   263.3 @@ -0,0 +1,793 @@
   263.4 +/* LzFindMt.c -- multithreaded Match finder for LZ algorithms
   263.5 +2008-10-04 : Igor Pavlov : Public domain */
   263.6 +
   263.7 +#include "LzHash.h"
   263.8 +
   263.9 +#include "LzFindMt.h"
  263.10 +
  263.11 +void MtSync_Construct(CMtSync *p)
  263.12 +{
  263.13 +  p->wasCreated = False;
  263.14 +  p->csWasInitialized = False;
  263.15 +  p->csWasEntered = False;
  263.16 +  Thread_Construct(&p->thread);
  263.17 +  Event_Construct(&p->canStart);
  263.18 +  Event_Construct(&p->wasStarted);
  263.19 +  Event_Construct(&p->wasStopped);
  263.20 +  Semaphore_Construct(&p->freeSemaphore);
  263.21 +  Semaphore_Construct(&p->filledSemaphore);
  263.22 +}
  263.23 +
  263.24 +void MtSync_GetNextBlock(CMtSync *p)
  263.25 +{
  263.26 +  if (p->needStart)
  263.27 +  {
  263.28 +    p->numProcessedBlocks = 1;
  263.29 +    p->needStart = False;
  263.30 +    p->stopWriting = False;
  263.31 +    p->exit = False;
  263.32 +    Event_Reset(&p->wasStarted);
  263.33 +    Event_Reset(&p->wasStopped);
  263.34 +
  263.35 +    Event_Set(&p->canStart);
  263.36 +    Event_Wait(&p->wasStarted);
  263.37 +  }
  263.38 +  else
  263.39 +  {
  263.40 +    CriticalSection_Leave(&p->cs);
  263.41 +    p->csWasEntered = False;
  263.42 +    p->numProcessedBlocks++;
  263.43 +    Semaphore_Release1(&p->freeSemaphore);
  263.44 +  }
  263.45 +  Semaphore_Wait(&p->filledSemaphore);
  263.46 +  CriticalSection_Enter(&p->cs);
  263.47 +  p->csWasEntered = True;
  263.48 +}
  263.49 +
  263.50 +/* MtSync_StopWriting must be called if Writing was started */
  263.51 +
  263.52 +void MtSync_StopWriting(CMtSync *p)
  263.53 +{
  263.54 +  UInt32 myNumBlocks = p->numProcessedBlocks;
  263.55 +  if (!Thread_WasCreated(&p->thread) || p->needStart)
  263.56 +    return;
  263.57 +  p->stopWriting = True;
  263.58 +  if (p->csWasEntered)
  263.59 +  {
  263.60 +    CriticalSection_Leave(&p->cs);
  263.61 +    p->csWasEntered = False;
  263.62 +  }
  263.63 +  Semaphore_Release1(&p->freeSemaphore);
  263.64 + 
  263.65 +  Event_Wait(&p->wasStopped);
  263.66 +
  263.67 +  while (myNumBlocks++ != p->numProcessedBlocks)
  263.68 +  {
  263.69 +    Semaphore_Wait(&p->filledSemaphore);
  263.70 +    Semaphore_Release1(&p->freeSemaphore);
  263.71 +  }
  263.72 +  p->needStart = True;
  263.73 +}
  263.74 +
  263.75 +void MtSync_Destruct(CMtSync *p)
  263.76 +{
  263.77 +  if (Thread_WasCreated(&p->thread))
  263.78 +  {
  263.79 +    MtSync_StopWriting(p);
  263.80 +    p->exit = True;
  263.81 +    if (p->needStart)
  263.82 +      Event_Set(&p->canStart);
  263.83 +    Thread_Wait(&p->thread);
  263.84 +    Thread_Close(&p->thread);
  263.85 +  }
  263.86 +  if (p->csWasInitialized)
  263.87 +  {
  263.88 +    CriticalSection_Delete(&p->cs);
  263.89 +    p->csWasInitialized = False;
  263.90 +  }
  263.91 +
  263.92 +  Event_Close(&p->canStart);
  263.93 +  Event_Close(&p->wasStarted);
  263.94 +  Event_Close(&p->wasStopped);
  263.95 +  Semaphore_Close(&p->freeSemaphore);
  263.96 +  Semaphore_Close(&p->filledSemaphore);
  263.97 +
  263.98 +  p->wasCreated = False;
  263.99 +}
 263.100 +
 263.101 +#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }
 263.102 +
 263.103 +static SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)
 263.104 +{
 263.105 +  if (p->wasCreated)
 263.106 +    return SZ_OK;
 263.107 +
 263.108 +  RINOK_THREAD(CriticalSection_Init(&p->cs));
 263.109 +  p->csWasInitialized = True;
 263.110 +
 263.111 +  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart));
 263.112 +  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted));
 263.113 +  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped));
 263.114 +  
 263.115 +  RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));
 263.116 +  RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));
 263.117 +
 263.118 +  p->needStart = True;
 263.119 +  
 263.120 +  RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj));
 263.121 +  p->wasCreated = True;
 263.122 +  return SZ_OK;
 263.123 +}
 263.124 +
 263.125 +static SRes MtSync_Create(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)
 263.126 +{
 263.127 +  SRes res = MtSync_Create2(p, startAddress, obj, numBlocks);
 263.128 +  if (res != SZ_OK)
 263.129 +    MtSync_Destruct(p);
 263.130 +  return res;
 263.131 +}
 263.132 +
 263.133 +void MtSync_Init(CMtSync *p) { p->needStart = True; }
 263.134 +
 263.135 +#define kMtMaxValForNormalize 0xFFFFFFFF
 263.136 +
 263.137 +#define DEF_GetHeads2(name, v, action) \
 263.138 +static void GetHeads ## name(const Byte *p, UInt32 pos, \
 263.139 +UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \
 263.140 +{ action; for (; numHeads != 0; numHeads--) { \
 263.141 +const UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++;  } }
 263.142 +
 263.143 +#define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;)
 263.144 +
 263.145 +DEF_GetHeads2(2,  (p[0] | ((UInt32)p[1] << 8)), hashMask = hashMask; crc = crc; )
 263.146 +DEF_GetHeads(3,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)
 263.147 +DEF_GetHeads(4,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask)
 263.148 +DEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)
 263.149 +DEF_GetHeads(5,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask)
 263.150 +
 263.151 +void HashThreadFunc(CMatchFinderMt *mt)
 263.152 +{
 263.153 +  CMtSync *p = &mt->hashSync;
 263.154 +  for (;;)
 263.155 +  {
 263.156 +    UInt32 numProcessedBlocks = 0;
 263.157 +    Event_Wait(&p->canStart);
 263.158 +    Event_Set(&p->wasStarted);
 263.159 +    for (;;)
 263.160 +    {
 263.161 +      if (p->exit)
 263.162 +        return;
 263.163 +      if (p->stopWriting)
 263.164 +      {
 263.165 +        p->numProcessedBlocks = numProcessedBlocks;
 263.166 +        Event_Set(&p->wasStopped);
 263.167 +        break;
 263.168 +      }
 263.169 +
 263.170 +      {
 263.171 +        CMatchFinder *mf = mt->MatchFinder;
 263.172 +        if (MatchFinder_NeedMove(mf))
 263.173 +        {
 263.174 +          CriticalSection_Enter(&mt->btSync.cs);
 263.175 +          CriticalSection_Enter(&mt->hashSync.cs);
 263.176 +          {
 263.177 +            const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf);
 263.178 +            const Byte *afterPtr;
 263.179 +            MatchFinder_MoveBlock(mf);
 263.180 +            afterPtr = MatchFinder_GetPointerToCurrentPos(mf);
 263.181 +            mt->pointerToCurPos -= beforePtr - afterPtr;
 263.182 +            mt->buffer -= beforePtr - afterPtr;
 263.183 +          }
 263.184 +          CriticalSection_Leave(&mt->btSync.cs);
 263.185 +          CriticalSection_Leave(&mt->hashSync.cs);
 263.186 +          continue;
 263.187 +        }
 263.188 +
 263.189 +        Semaphore_Wait(&p->freeSemaphore);
 263.190 +
 263.191 +        MatchFinder_ReadIfRequired(mf);
 263.192 +        if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize))
 263.193 +        {
 263.194 +          UInt32 subValue = (mf->pos - mf->historySize - 1);
 263.195 +          MatchFinder_ReduceOffsets(mf, subValue);
 263.196 +          MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1);
 263.197 +        }
 263.198 +        {
 263.199 +          UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize;
 263.200 +          UInt32 num = mf->streamPos - mf->pos;
 263.201 +          heads[0] = 2;
 263.202 +          heads[1] = num;
 263.203 +          if (num >= mf->numHashBytes)
 263.204 +          {
 263.205 +            num = num - mf->numHashBytes + 1;
 263.206 +            if (num > kMtHashBlockSize - 2)
 263.207 +              num = kMtHashBlockSize - 2;
 263.208 +            mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc);
 263.209 +            heads[0] += num;
 263.210 +          }
 263.211 +          mf->pos += num;
 263.212 +          mf->buffer += num;
 263.213 +        }
 263.214 +      }
 263.215 +
 263.216 +      Semaphore_Release1(&p->filledSemaphore);
 263.217 +    }
 263.218 +  }
 263.219 +}
 263.220 +
 263.221 +void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)
 263.222 +{
 263.223 +  MtSync_GetNextBlock(&p->hashSync);
 263.224 +  p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize;
 263.225 +  p->hashBufPosLimit += p->hashBuf[p->hashBufPos++];
 263.226 +  p->hashNumAvail = p->hashBuf[p->hashBufPos++];
 263.227 +}
 263.228 +
 263.229 +#define kEmptyHashValue 0
 263.230 +
 263.231 +/* #define MFMT_GM_INLINE */
 263.232 +
 263.233 +#ifdef MFMT_GM_INLINE
 263.234 +
 263.235 +#define NO_INLINE MY_FAST_CALL
 263.236 +
 263.237 +Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,
 263.238 +    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
 263.239 +    UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)
 263.240 +{
 263.241 +  do
 263.242 +  {
 263.243 +  UInt32 *distances = _distances + 1;
 263.244 +  UInt32 curMatch = pos - *hash++;
 263.245 +
 263.246 +  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
 263.247 +  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
 263.248 +  UInt32 len0 = 0, len1 = 0;
 263.249 +  UInt32 cutValue = _cutValue;
 263.250 +  UInt32 maxLen = _maxLen;
 263.251 +  for (;;)
 263.252 +  {
 263.253 +    UInt32 delta = pos - curMatch;
 263.254 +    if (cutValue-- == 0 || delta >= _cyclicBufferSize)
 263.255 +    {
 263.256 +      *ptr0 = *ptr1 = kEmptyHashValue;
 263.257 +      break;
 263.258 +    }
 263.259 +    {
 263.260 +      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
 263.261 +      const Byte *pb = cur - delta;
 263.262 +      UInt32 len = (len0 < len1 ? len0 : len1);
 263.263 +      if (pb[len] == cur[len])
 263.264 +      {
 263.265 +        if (++len != lenLimit && pb[len] == cur[len])
 263.266 +          while (++len != lenLimit)
 263.267 +            if (pb[len] != cur[len])
 263.268 +              break;
 263.269 +        if (maxLen < len)
 263.270 +        {
 263.271 +          *distances++ = maxLen = len;
 263.272 +          *distances++ = delta - 1;
 263.273 +          if (len == lenLimit)
 263.274 +          {
 263.275 +            *ptr1 = pair[0];
 263.276 +            *ptr0 = pair[1];
 263.277 +            break;
 263.278 +          }
 263.279 +        }
 263.280 +      }
 263.281 +      if (pb[len] < cur[len])
 263.282 +      {
 263.283 +        *ptr1 = curMatch;
 263.284 +        ptr1 = pair + 1;
 263.285 +        curMatch = *ptr1;
 263.286 +        len1 = len;
 263.287 +      }
 263.288 +      else
 263.289 +      {
 263.290 +        *ptr0 = curMatch;
 263.291 +        ptr0 = pair;
 263.292 +        curMatch = *ptr0;
 263.293 +        len0 = len;
 263.294 +      }
 263.295 +    }
 263.296 +  }
 263.297 +  pos++;
 263.298 +  _cyclicBufferPos++;
 263.299 +  cur++;
 263.300 +  {
 263.301 +    UInt32 num = (UInt32)(distances - _distances);
 263.302 +    *_distances = num - 1;
 263.303 +    _distances += num;
 263.304 +    limit -= num;
 263.305 +  }
 263.306 +  }
 263.307 +  while (limit > 0 && --size != 0);
 263.308 +  *posRes = pos;
 263.309 +  return limit;
 263.310 +}
 263.311 +
 263.312 +#endif
 263.313 +
 263.314 +void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)
 263.315 +{
 263.316 +  UInt32 numProcessed = 0;
 263.317 +  UInt32 curPos = 2;
 263.318 +  UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);
 263.319 +  distances[1] = p->hashNumAvail;
 263.320 +  while (curPos < limit)
 263.321 +  {
 263.322 +    if (p->hashBufPos == p->hashBufPosLimit)
 263.323 +    {
 263.324 +      MatchFinderMt_GetNextBlock_Hash(p);
 263.325 +      distances[1] = numProcessed + p->hashNumAvail;
 263.326 +      if (p->hashNumAvail >= p->numHashBytes)
 263.327 +        continue;
 263.328 +      for (; p->hashNumAvail != 0; p->hashNumAvail--)
 263.329 +        distances[curPos++] = 0;
 263.330 +      break;
 263.331 +    }
 263.332 +    {
 263.333 +      UInt32 size = p->hashBufPosLimit - p->hashBufPos;
 263.334 +      UInt32 lenLimit = p->matchMaxLen;
 263.335 +      UInt32 pos = p->pos;
 263.336 +      UInt32 cyclicBufferPos = p->cyclicBufferPos;
 263.337 +      if (lenLimit >= p->hashNumAvail)
 263.338 +        lenLimit = p->hashNumAvail;
 263.339 +      {
 263.340 +        UInt32 size2 = p->hashNumAvail - lenLimit + 1;
 263.341 +        if (size2 < size)
 263.342 +          size = size2;
 263.343 +        size2 = p->cyclicBufferSize - cyclicBufferPos;
 263.344 +        if (size2 < size)
 263.345 +          size = size2;
 263.346 +      }
 263.347 +      #ifndef MFMT_GM_INLINE
 263.348 +      while (curPos < limit && size-- != 0)
 263.349 +      {
 263.350 +        UInt32 *startDistances = distances + curPos;
 263.351 +        UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++],
 263.352 +          pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
 263.353 +          startDistances + 1, p->numHashBytes - 1) - startDistances);
 263.354 +        *startDistances = num - 1;
 263.355 +        curPos += num;
 263.356 +        cyclicBufferPos++;
 263.357 +        pos++;
 263.358 +        p->buffer++;
 263.359 +      }
 263.360 +      #else
 263.361 +      {
 263.362 +        UInt32 posRes;
 263.363 +        curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
 263.364 +          distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes);
 263.365 +        p->hashBufPos += posRes - pos;
 263.366 +        cyclicBufferPos += posRes - pos;
 263.367 +        p->buffer += posRes - pos;
 263.368 +        pos = posRes;
 263.369 +      }
 263.370 +      #endif
 263.371 +
 263.372 +      numProcessed += pos - p->pos;
 263.373 +      p->hashNumAvail -= pos - p->pos;
 263.374 +      p->pos = pos;
 263.375 +      if (cyclicBufferPos == p->cyclicBufferSize)
 263.376 +        cyclicBufferPos = 0;
 263.377 +      p->cyclicBufferPos = cyclicBufferPos;
 263.378 +    }
 263.379 +  }
 263.380 +  distances[0] = curPos;
 263.381 +}
 263.382 +
 263.383 +void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)
 263.384 +{
 263.385 +  CMtSync *sync = &p->hashSync;
 263.386 +  if (!sync->needStart)
 263.387 +  {
 263.388 +    CriticalSection_Enter(&sync->cs);
 263.389 +    sync->csWasEntered = True;
 263.390 +  }
 263.391 +  
 263.392 +  BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize);
 263.393 +
 263.394 +  if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)
 263.395 +  {
 263.396 +    UInt32 subValue = p->pos - p->cyclicBufferSize;
 263.397 +    MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2);
 263.398 +    p->pos -= subValue;
 263.399 +  }
 263.400 +
 263.401 +  if (!sync->needStart)
 263.402 +  {
 263.403 +    CriticalSection_Leave(&sync->cs);
 263.404 +    sync->csWasEntered = False;
 263.405 +  }
 263.406 +}
 263.407 +
 263.408 +void BtThreadFunc(CMatchFinderMt *mt)
 263.409 +{
 263.410 +  CMtSync *p = &mt->btSync;
 263.411 +  for (;;)
 263.412 +  {
 263.413 +    UInt32 blockIndex = 0;
 263.414 +    Event_Wait(&p->canStart);
 263.415 +    Event_Set(&p->wasStarted);
 263.416 +    for (;;)
 263.417 +    {
 263.418 +      if (p->exit)
 263.419 +        return;
 263.420 +      if (p->stopWriting)
 263.421 +      {
 263.422 +        p->numProcessedBlocks = blockIndex;
 263.423 +        MtSync_StopWriting(&mt->hashSync);
 263.424 +        Event_Set(&p->wasStopped);
 263.425 +        break;
 263.426 +      }
 263.427 +      Semaphore_Wait(&p->freeSemaphore);
 263.428 +      BtFillBlock(mt, blockIndex++);
 263.429 +      Semaphore_Release1(&p->filledSemaphore);
 263.430 +    }
 263.431 +  }
 263.432 +}
 263.433 +
 263.434 +void MatchFinderMt_Construct(CMatchFinderMt *p)
 263.435 +{
 263.436 +  p->hashBuf = 0;
 263.437 +  MtSync_Construct(&p->hashSync);
 263.438 +  MtSync_Construct(&p->btSync);
 263.439 +}
 263.440 +
 263.441 +void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)
 263.442 +{
 263.443 +  alloc->Free(alloc, p->hashBuf);
 263.444 +  p->hashBuf = 0;
 263.445 +}
 263.446 +
 263.447 +void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)
 263.448 +{
 263.449 +  MtSync_Destruct(&p->hashSync);
 263.450 +  MtSync_Destruct(&p->btSync);
 263.451 +  MatchFinderMt_FreeMem(p, alloc);
 263.452 +}
 263.453 +
 263.454 +#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)
 263.455 +#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)
 263.456 +
 263.457 +static unsigned MY_STD_CALL HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p);  return 0; }
 263.458 +static unsigned MY_STD_CALL BtThreadFunc2(void *p)
 263.459 +{
 263.460 +  Byte allocaDummy[0x180];
 263.461 +  int i = 0;
 263.462 +  for (i = 0; i < 16; i++)
 263.463 +    allocaDummy[i] = (Byte)i;
 263.464 +  BtThreadFunc((CMatchFinderMt *)p);
 263.465 +  return 0;
 263.466 +}
 263.467 +
 263.468 +SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
 263.469 +    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)
 263.470 +{
 263.471 +  CMatchFinder *mf = p->MatchFinder;
 263.472 +  p->historySize = historySize;
 263.473 +  if (kMtBtBlockSize <= matchMaxLen * 4)
 263.474 +    return SZ_ERROR_PARAM;
 263.475 +  if (p->hashBuf == 0)
 263.476 +  {
 263.477 +    p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));
 263.478 +    if (p->hashBuf == 0)
 263.479 +      return SZ_ERROR_MEM;
 263.480 +    p->btBuf = p->hashBuf + kHashBufferSize;
 263.481 +  }
 263.482 +  keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);
 263.483 +  keepAddBufferAfter += kMtHashBlockSize;
 263.484 +  if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))
 263.485 +    return SZ_ERROR_MEM;
 263.486 +
 263.487 +  RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks));
 263.488 +  RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks));
 263.489 +  return SZ_OK;
 263.490 +}
 263.491 +
 263.492 +/* Call it after ReleaseStream / SetStream */
 263.493 +void MatchFinderMt_Init(CMatchFinderMt *p)
 263.494 +{
 263.495 +  CMatchFinder *mf = p->MatchFinder;
 263.496 +  p->btBufPos = p->btBufPosLimit = 0;
 263.497 +  p->hashBufPos = p->hashBufPosLimit = 0;
 263.498 +  MatchFinder_Init(mf);
 263.499 +  p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf);
 263.500 +  p->btNumAvailBytes = 0;
 263.501 +  p->lzPos = p->historySize + 1;
 263.502 +
 263.503 +  p->hash = mf->hash;
 263.504 +  p->fixedHashSize = mf->fixedHashSize;
 263.505 +  p->crc = mf->crc;
 263.506 +
 263.507 +  p->son = mf->son;
 263.508 +  p->matchMaxLen = mf->matchMaxLen;
 263.509 +  p->numHashBytes = mf->numHashBytes;
 263.510 +  p->pos = mf->pos;
 263.511 +  p->buffer = mf->buffer;
 263.512 +  p->cyclicBufferPos = mf->cyclicBufferPos;
 263.513 +  p->cyclicBufferSize = mf->cyclicBufferSize;
 263.514 +  p->cutValue = mf->cutValue;
 263.515 +}
 263.516 +
 263.517 +/* ReleaseStream is required to finish multithreading */
 263.518 +void MatchFinderMt_ReleaseStream(CMatchFinderMt *p)
 263.519 +{
 263.520 +  MtSync_StopWriting(&p->btSync);
 263.521 +  /* p->MatchFinder->ReleaseStream(); */
 263.522 +}
 263.523 +
 263.524 +void MatchFinderMt_Normalize(CMatchFinderMt *p)
 263.525 +{
 263.526 +  MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize);
 263.527 +  p->lzPos = p->historySize + 1;
 263.528 +}
 263.529 +
 263.530 +void MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)
 263.531 +{
 263.532 +  UInt32 blockIndex;
 263.533 +  MtSync_GetNextBlock(&p->btSync);
 263.534 +  blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask);
 263.535 +  p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize;
 263.536 +  p->btBufPosLimit += p->btBuf[p->btBufPos++];
 263.537 +  p->btNumAvailBytes = p->btBuf[p->btBufPos++];
 263.538 +  if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize)
 263.539 +    MatchFinderMt_Normalize(p);
 263.540 +}
 263.541 +
 263.542 +const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)
 263.543 +{
 263.544 +  return p->pointerToCurPos;
 263.545 +}
 263.546 +
 263.547 +#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);
 263.548 +
 263.549 +UInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)
 263.550 +{
 263.551 +  GET_NEXT_BLOCK_IF_REQUIRED;
 263.552 +  return p->btNumAvailBytes;
 263.553 +}
 263.554 +
 263.555 +Byte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index)
 263.556 +{
 263.557 +  return p->pointerToCurPos[index];
 263.558 +}
 263.559 +
 263.560 +UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
 263.561 +{
 263.562 +  UInt32 hash2Value, curMatch2;
 263.563 +  UInt32 *hash = p->hash;
 263.564 +  const Byte *cur = p->pointerToCurPos;
 263.565 +  UInt32 lzPos = p->lzPos;
 263.566 +  MT_HASH2_CALC
 263.567 +      
 263.568 +  curMatch2 = hash[hash2Value];
 263.569 +  hash[hash2Value] = lzPos;
 263.570 +
 263.571 +  if (curMatch2 >= matchMinPos)
 263.572 +    if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
 263.573 +    {
 263.574 +      *distances++ = 2;
 263.575 +      *distances++ = lzPos - curMatch2 - 1;
 263.576 +    }
 263.577 +  return distances;
 263.578 +}
 263.579 +
 263.580 +UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
 263.581 +{
 263.582 +  UInt32 hash2Value, hash3Value, curMatch2, curMatch3;
 263.583 +  UInt32 *hash = p->hash;
 263.584 +  const Byte *cur = p->pointerToCurPos;
 263.585 +  UInt32 lzPos = p->lzPos;
 263.586 +  MT_HASH3_CALC
 263.587 +
 263.588 +  curMatch2 = hash[                hash2Value];
 263.589 +  curMatch3 = hash[kFix3HashSize + hash3Value];
 263.590 +  
 263.591 +  hash[                hash2Value] =
 263.592 +  hash[kFix3HashSize + hash3Value] =
 263.593 +    lzPos;
 263.594 +
 263.595 +  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
 263.596 +  {
 263.597 +    distances[1] = lzPos - curMatch2 - 1;
 263.598 +    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])
 263.599 +    {
 263.600 +      distances[0] = 3;
 263.601 +      return distances + 2;
 263.602 +    }
 263.603 +    distances[0] = 2;
 263.604 +    distances += 2;
 263.605 +  }
 263.606 +  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])
 263.607 +  {
 263.608 +    *distances++ = 3;
 263.609 +    *distances++ = lzPos - curMatch3 - 1;
 263.610 +  }
 263.611 +  return distances;
 263.612 +}
 263.613 +
 263.614 +/*
 263.615 +UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
 263.616 +{
 263.617 +  UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4;
 263.618 +  UInt32 *hash = p->hash;
 263.619 +  const Byte *cur = p->pointerToCurPos;
 263.620 +  UInt32 lzPos = p->lzPos;
 263.621 +  MT_HASH4_CALC
 263.622 +      
 263.623 +  curMatch2 = hash[                hash2Value];
 263.624 +  curMatch3 = hash[kFix3HashSize + hash3Value];
 263.625 +  curMatch4 = hash[kFix4HashSize + hash4Value];
 263.626 +  
 263.627 +  hash[                hash2Value] =
 263.628 +  hash[kFix3HashSize + hash3Value] =
 263.629 +  hash[kFix4HashSize + hash4Value] =
 263.630 +    lzPos;
 263.631 +
 263.632 +  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
 263.633 +  {
 263.634 +    distances[1] = lzPos - curMatch2 - 1;
 263.635 +    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])
 263.636 +    {
 263.637 +      distances[0] =  (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;
 263.638 +      return distances + 2;
 263.639 +    }
 263.640 +    distances[0] = 2;
 263.641 +    distances += 2;
 263.642 +  }
 263.643 +  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])
 263.644 +  {
 263.645 +    distances[1] = lzPos - curMatch3 - 1;
 263.646 +    if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3])
 263.647 +    {
 263.648 +      distances[0] = 4;
 263.649 +      return distances + 2;
 263.650 +    }
 263.651 +    distances[0] = 3;
 263.652 +    distances += 2;
 263.653 +  }
 263.654 +
 263.655 +  if (curMatch4 >= matchMinPos)
 263.656 +    if (
 263.657 +      cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] &&
 263.658 +      cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3]
 263.659 +      )
 263.660 +    {
 263.661 +      *distances++ = 4;
 263.662 +      *distances++ = lzPos - curMatch4 - 1;
 263.663 +    }
 263.664 +  return distances;
 263.665 +}
 263.666 +*/
 263.667 +
 263.668 +#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;
 263.669 +
 263.670 +UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)
 263.671 +{
 263.672 +  const UInt32 *btBuf = p->btBuf + p->btBufPos;
 263.673 +  UInt32 len = *btBuf++;
 263.674 +  p->btBufPos += 1 + len;
 263.675 +  p->btNumAvailBytes--;
 263.676 +  {
 263.677 +    UInt32 i;
 263.678 +    for (i = 0; i < len; i += 2)
 263.679 +    {
 263.680 +      *distances++ = *btBuf++;
 263.681 +      *distances++ = *btBuf++;
 263.682 +    }
 263.683 +  }
 263.684 +  INCREASE_LZ_POS
 263.685 +  return len;
 263.686 +}
 263.687 +
 263.688 +UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)
 263.689 +{
 263.690 +  const UInt32 *btBuf = p->btBuf + p->btBufPos;
 263.691 +  UInt32 len = *btBuf++;
 263.692 +  p->btBufPos += 1 + len;
 263.693 +
 263.694 +  if (len == 0)
 263.695 +  {
 263.696 +    if (p->btNumAvailBytes-- >= 4)
 263.697 +      len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));
 263.698 +  }
 263.699 +  else
 263.700 +  {
 263.701 +    /* Condition: there are matches in btBuf with length < p->numHashBytes */
 263.702 +    UInt32 *distances2;
 263.703 +    p->btNumAvailBytes--;
 263.704 +    distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);
 263.705 +    do
 263.706 +    {
 263.707 +      *distances2++ = *btBuf++;
 263.708 +      *distances2++ = *btBuf++;
 263.709 +    }
 263.710 +    while ((len -= 2) != 0);
 263.711 +    len  = (UInt32)(distances2 - (distances));
 263.712 +  }
 263.713 +  INCREASE_LZ_POS
 263.714 +  return len;
 263.715 +}
 263.716 +
 263.717 +#define SKIP_HEADER2  do { GET_NEXT_BLOCK_IF_REQUIRED
 263.718 +#define SKIP_HEADER(n) SKIP_HEADER2 if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;
 263.719 +#define SKIP_FOOTER } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num != 0);
 263.720 +
 263.721 +void MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)
 263.722 +{
 263.723 +  SKIP_HEADER2 { p->btNumAvailBytes--;
 263.724 +  SKIP_FOOTER
 263.725 +}
 263.726 +
 263.727 +void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)
 263.728 +{
 263.729 +  SKIP_HEADER(2)
 263.730 +      UInt32 hash2Value;
 263.731 +      MT_HASH2_CALC
 263.732 +      hash[hash2Value] = p->lzPos;
 263.733 +  SKIP_FOOTER
 263.734 +}
 263.735 +
 263.736 +void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)
 263.737 +{
 263.738 +  SKIP_HEADER(3)
 263.739 +      UInt32 hash2Value, hash3Value;
 263.740 +      MT_HASH3_CALC
 263.741 +      hash[kFix3HashSize + hash3Value] =
 263.742 +      hash[                hash2Value] =
 263.743 +        p->lzPos;
 263.744 +  SKIP_FOOTER
 263.745 +}
 263.746 +
 263.747 +/*
 263.748 +void MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)
 263.749 +{
 263.750 +  SKIP_HEADER(4)
 263.751 +      UInt32 hash2Value, hash3Value, hash4Value;
 263.752 +      MT_HASH4_CALC
 263.753 +      hash[kFix4HashSize + hash4Value] =
 263.754 +      hash[kFix3HashSize + hash3Value] =
 263.755 +      hash[                hash2Value] =
 263.756 +        p->lzPos;
 263.757 +  SKIP_FOOTER
 263.758 +}
 263.759 +*/
 263.760 +
 263.761 +void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)
 263.762 +{
 263.763 +  vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;
 263.764 +  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte;
 263.765 +  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;
 263.766 +  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;
 263.767 +  vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;
 263.768 +  switch(p->MatchFinder->numHashBytes)
 263.769 +  {
 263.770 +    case 2:
 263.771 +      p->GetHeadsFunc = GetHeads2;
 263.772 +      p->MixMatchesFunc = (Mf_Mix_Matches)0;
 263.773 +      vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;
 263.774 +      vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;
 263.775 +      break;
 263.776 +    case 3:
 263.777 +      p->GetHeadsFunc = GetHeads3;
 263.778 +      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;
 263.779 +      vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip;
 263.780 +      break;
 263.781 +    default:
 263.782 +    /* case 4: */
 263.783 +      p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;
 263.784 +      /* p->GetHeadsFunc = GetHeads4; */
 263.785 +      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;
 263.786 +      vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;
 263.787 +      break;
 263.788 +    /*
 263.789 +    default:
 263.790 +      p->GetHeadsFunc = GetHeads5;
 263.791 +      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4;
 263.792 +      vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip;
 263.793 +      break;
 263.794 +    */
 263.795 +  }
 263.796 +}
   264.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   264.2 +++ b/src/win32/7zip/7z/C/LzFindMt.h	Sat Mar 03 10:31:27 2012 -0600
   264.3 @@ -0,0 +1,97 @@
   264.4 +/* LzFindMt.h -- multithreaded Match finder for LZ algorithms
   264.5 +2008-10-04 : Igor Pavlov : Public domain */
   264.6 +
   264.7 +#ifndef __LZFINDMT_H
   264.8 +#define __LZFINDMT_H
   264.9 +
  264.10 +#include "Threads.h"
  264.11 +#include "LzFind.h"
  264.12 +
  264.13 +#define kMtHashBlockSize (1 << 13)
  264.14 +#define kMtHashNumBlocks (1 << 3)
  264.15 +#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)
  264.16 +
  264.17 +#define kMtBtBlockSize (1 << 14)
  264.18 +#define kMtBtNumBlocks (1 << 6)
  264.19 +#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)
  264.20 +
  264.21 +typedef struct _CMtSync
  264.22 +{
  264.23 +  Bool wasCreated;
  264.24 +  Bool needStart;
  264.25 +  Bool exit;
  264.26 +  Bool stopWriting;
  264.27 +
  264.28 +  CThread thread;
  264.29 +  CAutoResetEvent canStart;
  264.30 +  CAutoResetEvent wasStarted;
  264.31 +  CAutoResetEvent wasStopped;
  264.32 +  CSemaphore freeSemaphore;
  264.33 +  CSemaphore filledSemaphore;
  264.34 +  Bool csWasInitialized;
  264.35 +  Bool csWasEntered;
  264.36 +  CCriticalSection cs;
  264.37 +  UInt32 numProcessedBlocks;
  264.38 +} CMtSync;
  264.39 +
  264.40 +typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);
  264.41 +
  264.42 +/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */
  264.43 +#define kMtCacheLineDummy 128
  264.44 +
  264.45 +typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,
  264.46 +  UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);
  264.47 +
  264.48 +typedef struct _CMatchFinderMt
  264.49 +{
  264.50 +  /* LZ */
  264.51 +  const Byte *pointerToCurPos;
  264.52 +  UInt32 *btBuf;
  264.53 +  UInt32 btBufPos;
  264.54 +  UInt32 btBufPosLimit;
  264.55 +  UInt32 lzPos;
  264.56 +  UInt32 btNumAvailBytes;
  264.57 +
  264.58 +  UInt32 *hash;
  264.59 +  UInt32 fixedHashSize;
  264.60 +  UInt32 historySize;
  264.61 +  const UInt32 *crc;
  264.62 +
  264.63 +  Mf_Mix_Matches MixMatchesFunc;
  264.64 +  
  264.65 +  /* LZ + BT */
  264.66 +  CMtSync btSync;
  264.67 +  Byte btDummy[kMtCacheLineDummy];
  264.68 +
  264.69 +  /* BT */
  264.70 +  UInt32 *hashBuf;
  264.71 +  UInt32 hashBufPos;
  264.72 +  UInt32 hashBufPosLimit;
  264.73 +  UInt32 hashNumAvail;
  264.74 +
  264.75 +  CLzRef *son;
  264.76 +  UInt32 matchMaxLen;
  264.77 +  UInt32 numHashBytes;
  264.78 +  UInt32 pos;
  264.79 +  Byte *buffer;
  264.80 +  UInt32 cyclicBufferPos;
  264.81 +  UInt32 cyclicBufferSize; /* it must be historySize + 1 */
  264.82 +  UInt32 cutValue;
  264.83 +
  264.84 +  /* BT + Hash */
  264.85 +  CMtSync hashSync;
  264.86 +  /* Byte hashDummy[kMtCacheLineDummy]; */
  264.87 +  
  264.88 +  /* Hash */
  264.89 +  Mf_GetHeads GetHeadsFunc;
  264.90 +  CMatchFinder *MatchFinder;
  264.91 +} CMatchFinderMt;
  264.92 +
  264.93 +void MatchFinderMt_Construct(CMatchFinderMt *p);
  264.94 +void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);
  264.95 +SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
  264.96 +    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);
  264.97 +void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);
  264.98 +void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);
  264.99 +
 264.100 +#endif
   265.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   265.2 +++ b/src/win32/7zip/7z/C/LzHash.h	Sat Mar 03 10:31:27 2012 -0600
   265.3 @@ -0,0 +1,54 @@
   265.4 +/* LzHash.h -- HASH functions for LZ algorithms
   265.5 +2008-10-04 : Igor Pavlov : Public domain */
   265.6 +
   265.7 +#ifndef __LZHASH_H
   265.8 +#define __LZHASH_H
   265.9 +
  265.10 +#define kHash2Size (1 << 10)
  265.11 +#define kHash3Size (1 << 16)
  265.12 +#define kHash4Size (1 << 20)
  265.13 +
  265.14 +#define kFix3HashSize (kHash2Size)
  265.15 +#define kFix4HashSize (kHash2Size + kHash3Size)
  265.16 +#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
  265.17 +
  265.18 +#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);
  265.19 +
  265.20 +#define HASH3_CALC { \
  265.21 +  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  265.22 +  hash2Value = temp & (kHash2Size - 1); \
  265.23 +  hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
  265.24 +
  265.25 +#define HASH4_CALC { \
  265.26 +  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  265.27 +  hash2Value = temp & (kHash2Size - 1); \
  265.28 +  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
  265.29 +  hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
  265.30 +
  265.31 +#define HASH5_CALC { \
  265.32 +  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  265.33 +  hash2Value = temp & (kHash2Size - 1); \
  265.34 +  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
  265.35 +  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \
  265.36 +  hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \
  265.37 +  hash4Value &= (kHash4Size - 1); }
  265.38 +
  265.39 +/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
  265.40 +#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
  265.41 +
  265.42 +
  265.43 +#define MT_HASH2_CALC \
  265.44 +  hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
  265.45 +
  265.46 +#define MT_HASH3_CALC { \
  265.47 +  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  265.48 +  hash2Value = temp & (kHash2Size - 1); \
  265.49 +  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
  265.50 +
  265.51 +#define MT_HASH4_CALC { \
  265.52 +  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  265.53 +  hash2Value = temp & (kHash2Size - 1); \
  265.54 +  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
  265.55 +  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
  265.56 +
  265.57 +#endif
   266.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   266.2 +++ b/src/win32/7zip/7z/C/LzmaDec.c	Sat Mar 03 10:31:27 2012 -0600
   266.3 @@ -0,0 +1,1007 @@
   266.4 +/* LzmaDec.c -- LZMA Decoder
   266.5 +2008-11-06 : Igor Pavlov : Public domain */
   266.6 +
   266.7 +#include "LzmaDec.h"
   266.8 +
   266.9 +#include <string.h>
  266.10 +
  266.11 +#define kNumTopBits 24
  266.12 +#define kTopValue ((UInt32)1 << kNumTopBits)
  266.13 +
  266.14 +#define kNumBitModelTotalBits 11
  266.15 +#define kBitModelTotal (1 << kNumBitModelTotalBits)
  266.16 +#define kNumMoveBits 5
  266.17 +
  266.18 +#define RC_INIT_SIZE 5
  266.19 +
  266.20 +#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }
  266.21 +
  266.22 +#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
  266.23 +#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
  266.24 +#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));
  266.25 +#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \
  266.26 +  { UPDATE_0(p); i = (i + i); A0; } else \
  266.27 +  { UPDATE_1(p); i = (i + i) + 1; A1; }
  266.28 +#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)
  266.29 +
  266.30 +#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }
  266.31 +#define TREE_DECODE(probs, limit, i) \
  266.32 +  { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }
  266.33 +
  266.34 +/* #define _LZMA_SIZE_OPT */
  266.35 +
  266.36 +#ifdef _LZMA_SIZE_OPT
  266.37 +#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)
  266.38 +#else
  266.39 +#define TREE_6_DECODE(probs, i) \
  266.40 +  { i = 1; \
  266.41 +  TREE_GET_BIT(probs, i); \
  266.42 +  TREE_GET_BIT(probs, i); \
  266.43 +  TREE_GET_BIT(probs, i); \
  266.44 +  TREE_GET_BIT(probs, i); \
  266.45 +  TREE_GET_BIT(probs, i); \
  266.46 +  TREE_GET_BIT(probs, i); \
  266.47 +  i -= 0x40; }
  266.48 +#endif
  266.49 +
  266.50 +#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }
  266.51 +
  266.52 +#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
  266.53 +#define UPDATE_0_CHECK range = bound;
  266.54 +#define UPDATE_1_CHECK range -= bound; code -= bound;
  266.55 +#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \
  266.56 +  { UPDATE_0_CHECK; i = (i + i); A0; } else \
  266.57 +  { UPDATE_1_CHECK; i = (i + i) + 1; A1; }
  266.58 +#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)
  266.59 +#define TREE_DECODE_CHECK(probs, limit, i) \
  266.60 +  { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }
  266.61 +
  266.62 +
  266.63 +#define kNumPosBitsMax 4
  266.64 +#define kNumPosStatesMax (1 << kNumPosBitsMax)
  266.65 +
  266.66 +#define kLenNumLowBits 3
  266.67 +#define kLenNumLowSymbols (1 << kLenNumLowBits)
  266.68 +#define kLenNumMidBits 3
  266.69 +#define kLenNumMidSymbols (1 << kLenNumMidBits)
  266.70 +#define kLenNumHighBits 8
  266.71 +#define kLenNumHighSymbols (1 << kLenNumHighBits)
  266.72 +
  266.73 +#define LenChoice 0
  266.74 +#define LenChoice2 (LenChoice + 1)
  266.75 +#define LenLow (LenChoice2 + 1)
  266.76 +#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
  266.77 +#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
  266.78 +#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
  266.79 +
  266.80 +
  266.81 +#define kNumStates 12
  266.82 +#define kNumLitStates 7
  266.83 +
  266.84 +#define kStartPosModelIndex 4
  266.85 +#define kEndPosModelIndex 14
  266.86 +#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
  266.87 +
  266.88 +#define kNumPosSlotBits 6
  266.89 +#define kNumLenToPosStates 4
  266.90 +
  266.91 +#define kNumAlignBits 4
  266.92 +#define kAlignTableSize (1 << kNumAlignBits)
  266.93 +
  266.94 +#define kMatchMinLen 2
  266.95 +#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)
  266.96 +
  266.97 +#define IsMatch 0
  266.98 +#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
  266.99 +#define IsRepG0 (IsRep + kNumStates)
 266.100 +#define IsRepG1 (IsRepG0 + kNumStates)
 266.101 +#define IsRepG2 (IsRepG1 + kNumStates)
 266.102 +#define IsRep0Long (IsRepG2 + kNumStates)
 266.103 +#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
 266.104 +#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
 266.105 +#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
 266.106 +#define LenCoder (Align + kAlignTableSize)
 266.107 +#define RepLenCoder (LenCoder + kNumLenProbs)
 266.108 +#define Literal (RepLenCoder + kNumLenProbs)
 266.109 +
 266.110 +#define LZMA_BASE_SIZE 1846
 266.111 +#define LZMA_LIT_SIZE 768
 266.112 +
 266.113 +#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))
 266.114 +
 266.115 +#if Literal != LZMA_BASE_SIZE
 266.116 +StopCompilingDueBUG
 266.117 +#endif
 266.118 +
 266.119 +static const Byte kLiteralNextStates[kNumStates * 2] =
 266.120 +{
 266.121 +  0, 0, 0, 0, 1, 2, 3,  4,  5,  6,  4,  5,
 266.122 +  7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10
 266.123 +};
 266.124 +
 266.125 +#define LZMA_DIC_MIN (1 << 12)
 266.126 +
 266.127 +/* First LZMA-symbol is always decoded.
 266.128 +And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization
 266.129 +Out:
 266.130 +  Result:
 266.131 +    SZ_OK - OK
 266.132 +    SZ_ERROR_DATA - Error
 266.133 +  p->remainLen:
 266.134 +    < kMatchSpecLenStart : normal remain
 266.135 +    = kMatchSpecLenStart : finished
 266.136 +    = kMatchSpecLenStart + 1 : Flush marker
 266.137 +    = kMatchSpecLenStart + 2 : State Init Marker
 266.138 +*/
 266.139 +
 266.140 +static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
 266.141 +{
 266.142 +  CLzmaProb *probs = p->probs;
 266.143 +
 266.144 +  unsigned state = p->state;
 266.145 +  UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];
 266.146 +  unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;
 266.147 +  unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;
 266.148 +  unsigned lc = p->prop.lc;
 266.149 +
 266.150 +  Byte *dic = p->dic;
 266.151 +  SizeT dicBufSize = p->dicBufSize;
 266.152 +  SizeT dicPos = p->dicPos;
 266.153 +  
 266.154 +  UInt32 processedPos = p->processedPos;
 266.155 +  UInt32 checkDicSize = p->checkDicSize;
 266.156 +  unsigned len = 0;
 266.157 +
 266.158 +  const Byte *buf = p->buf;
 266.159 +  UInt32 range = p->range;
 266.160 +  UInt32 code = p->code;
 266.161 +
 266.162 +  do
 266.163 +  {
 266.164 +    CLzmaProb *prob;
 266.165 +    UInt32 bound;
 266.166 +    unsigned ttt;
 266.167 +    unsigned posState = processedPos & pbMask;
 266.168 +
 266.169 +    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
 266.170 +    IF_BIT_0(prob)
 266.171 +    {
 266.172 +      unsigned symbol;
 266.173 +      UPDATE_0(prob);
 266.174 +      prob = probs + Literal;
 266.175 +      if (checkDicSize != 0 || processedPos != 0)
 266.176 +        prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +
 266.177 +        (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));
 266.178 +
 266.179 +      if (state < kNumLitStates)
 266.180 +      {
 266.181 +        symbol = 1;
 266.182 +        do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);
 266.183 +      }
 266.184 +      else
 266.185 +      {
 266.186 +        unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
 266.187 +        unsigned offs = 0x100;
 266.188 +        symbol = 1;
 266.189 +        do
 266.190 +        {
 266.191 +          unsigned bit;
 266.192 +          CLzmaProb *probLit;
 266.193 +          matchByte <<= 1;
 266.194 +          bit = (matchByte & offs);
 266.195 +          probLit = prob + offs + bit + symbol;
 266.196 +          GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)
 266.197 +        }
 266.198 +        while (symbol < 0x100);
 266.199 +      }
 266.200 +      dic[dicPos++] = (Byte)(symbol & 0xFF);
 266.201 +      processedPos++;
 266.202 +
 266.203 +      state = kLiteralNextStates[state];
 266.204 +      /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */
 266.205 +      continue;
 266.206 +    }
 266.207 +    else
 266.208 +    {
 266.209 +      UPDATE_1(prob);
 266.210 +      prob = probs + IsRep + state;
 266.211 +      IF_BIT_0(prob)
 266.212 +      {
 266.213 +        UPDATE_0(prob);
 266.214 +        state += kNumStates;
 266.215 +        prob = probs + LenCoder;
 266.216 +      }
 266.217 +      else
 266.218 +      {
 266.219 +        UPDATE_1(prob);
 266.220 +        if (checkDicSize == 0 && processedPos == 0)
 266.221 +          return SZ_ERROR_DATA;
 266.222 +        prob = probs + IsRepG0 + state;
 266.223 +        IF_BIT_0(prob)
 266.224 +        {
 266.225 +          UPDATE_0(prob);
 266.226 +          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
 266.227 +          IF_BIT_0(prob)
 266.228 +          {
 266.229 +            UPDATE_0(prob);
 266.230 +            dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
 266.231 +            dicPos++;
 266.232 +            processedPos++;
 266.233 +            state = state < kNumLitStates ? 9 : 11;
 266.234 +            continue;
 266.235 +          }
 266.236 +          UPDATE_1(prob);
 266.237 +        }
 266.238 +        else
 266.239 +        {
 266.240 +          UInt32 distance;
 266.241 +          UPDATE_1(prob);
 266.242 +          prob = probs + IsRepG1 + state;
 266.243 +          IF_BIT_0(prob)
 266.244 +          {
 266.245 +            UPDATE_0(prob);
 266.246 +            distance = rep1;
 266.247 +          }
 266.248 +          else
 266.249 +          {
 266.250 +            UPDATE_1(prob);
 266.251 +            prob = probs + IsRepG2 + state;
 266.252 +            IF_BIT_0(prob)
 266.253 +            {
 266.254 +              UPDATE_0(prob);
 266.255 +              distance = rep2;
 266.256 +            }
 266.257 +            else
 266.258 +            {
 266.259 +              UPDATE_1(prob);
 266.260 +              distance = rep3;
 266.261 +              rep3 = rep2;
 266.262 +            }
 266.263 +            rep2 = rep1;
 266.264 +          }
 266.265 +          rep1 = rep0;
 266.266 +          rep0 = distance;
 266.267 +        }
 266.268 +        state = state < kNumLitStates ? 8 : 11;
 266.269 +        prob = probs + RepLenCoder;
 266.270 +      }
 266.271 +      {
 266.272 +        unsigned limit, offset;
 266.273 +        CLzmaProb *probLen = prob + LenChoice;
 266.274 +        IF_BIT_0(probLen)
 266.275 +        {
 266.276 +          UPDATE_0(probLen);
 266.277 +          probLen = prob + LenLow + (posState << kLenNumLowBits);
 266.278 +          offset = 0;
 266.279 +          limit = (1 << kLenNumLowBits);
 266.280 +        }
 266.281 +        else
 266.282 +        {
 266.283 +          UPDATE_1(probLen);
 266.284 +          probLen = prob + LenChoice2;
 266.285 +          IF_BIT_0(probLen)
 266.286 +          {
 266.287 +            UPDATE_0(probLen);
 266.288 +            probLen = prob + LenMid + (posState << kLenNumMidBits);
 266.289 +            offset = kLenNumLowSymbols;
 266.290 +            limit = (1 << kLenNumMidBits);
 266.291 +          }
 266.292 +          else
 266.293 +          {
 266.294 +            UPDATE_1(probLen);
 266.295 +            probLen = prob + LenHigh;
 266.296 +            offset = kLenNumLowSymbols + kLenNumMidSymbols;
 266.297 +            limit = (1 << kLenNumHighBits);
 266.298 +          }
 266.299 +        }
 266.300 +        TREE_DECODE(probLen, limit, len);
 266.301 +        len += offset;
 266.302 +      }
 266.303 +
 266.304 +      if (state >= kNumStates)
 266.305 +      {
 266.306 +        UInt32 distance;
 266.307 +        prob = probs + PosSlot +
 266.308 +            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
 266.309 +        TREE_6_DECODE(prob, distance);
 266.310 +        if (distance >= kStartPosModelIndex)
 266.311 +        {
 266.312 +          unsigned posSlot = (unsigned)distance;
 266.313 +          int numDirectBits = (int)(((distance >> 1) - 1));
 266.314 +          distance = (2 | (distance & 1));
 266.315 +          if (posSlot < kEndPosModelIndex)
 266.316 +          {
 266.317 +            distance <<= numDirectBits;
 266.318 +            prob = probs + SpecPos + distance - posSlot - 1;
 266.319 +            {
 266.320 +              UInt32 mask = 1;
 266.321 +              unsigned i = 1;
 266.322 +              do
 266.323 +              {
 266.324 +                GET_BIT2(prob + i, i, ; , distance |= mask);
 266.325 +                mask <<= 1;
 266.326 +              }
 266.327 +              while (--numDirectBits != 0);
 266.328 +            }
 266.329 +          }
 266.330 +          else
 266.331 +          {
 266.332 +            numDirectBits -= kNumAlignBits;
 266.333 +            do
 266.334 +            {
 266.335 +              NORMALIZE
 266.336 +              range >>= 1;
 266.337 +              
 266.338 +              {
 266.339 +                UInt32 t;
 266.340 +                code -= range;
 266.341 +                t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */
 266.342 +                distance = (distance << 1) + (t + 1);
 266.343 +                code += range & t;
 266.344 +              }
 266.345 +              /*
 266.346 +              distance <<= 1;
 266.347 +              if (code >= range)
 266.348 +              {
 266.349 +                code -= range;
 266.350 +                distance |= 1;
 266.351 +              }
 266.352 +              */
 266.353 +            }
 266.354 +            while (--numDirectBits != 0);
 266.355 +            prob = probs + Align;
 266.356 +            distance <<= kNumAlignBits;
 266.357 +            {
 266.358 +              unsigned i = 1;
 266.359 +              GET_BIT2(prob + i, i, ; , distance |= 1);
 266.360 +              GET_BIT2(prob + i, i, ; , distance |= 2);
 266.361 +              GET_BIT2(prob + i, i, ; , distance |= 4);
 266.362 +              GET_BIT2(prob + i, i, ; , distance |= 8);
 266.363 +            }
 266.364 +            if (distance == (UInt32)0xFFFFFFFF)
 266.365 +            {
 266.366 +              len += kMatchSpecLenStart;
 266.367 +              state -= kNumStates;
 266.368 +              break;
 266.369 +            }
 266.370 +          }
 266.371 +        }
 266.372 +        rep3 = rep2;
 266.373 +        rep2 = rep1;
 266.374 +        rep1 = rep0;
 266.375 +        rep0 = distance + 1;
 266.376 +        if (checkDicSize == 0)
 266.377 +        {
 266.378 +          if (distance >= processedPos)
 266.379 +            return SZ_ERROR_DATA;
 266.380 +        }
 266.381 +        else if (distance >= checkDicSize)
 266.382 +          return SZ_ERROR_DATA;
 266.383 +        state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
 266.384 +        /* state = kLiteralNextStates[state]; */
 266.385 +      }
 266.386 +
 266.387 +      len += kMatchMinLen;
 266.388 +
 266.389 +      if (limit == dicPos)
 266.390 +        return SZ_ERROR_DATA;
 266.391 +      {
 266.392 +        SizeT rem = limit - dicPos;
 266.393 +        unsigned curLen = ((rem < len) ? (unsigned)rem : len);
 266.394 +        SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);
 266.395 +
 266.396 +        processedPos += curLen;
 266.397 +
 266.398 +        len -= curLen;
 266.399 +        if (pos + curLen <= dicBufSize)
 266.400 +        {
 266.401 +          Byte *dest = dic + dicPos;
 266.402 +          ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
 266.403 +          const Byte *lim = dest + curLen;
 266.404 +          dicPos += curLen;
 266.405 +          do
 266.406 +            *(dest) = (Byte)*(dest + src);
 266.407 +          while (++dest != lim);
 266.408 +        }
 266.409 +        else
 266.410 +        {
 266.411 +          do
 266.412 +          {
 266.413 +            dic[dicPos++] = dic[pos];
 266.414 +            if (++pos == dicBufSize)
 266.415 +              pos = 0;
 266.416 +          }
 266.417 +          while (--curLen != 0);
 266.418 +        }
 266.419 +      }
 266.420 +    }
 266.421 +  }
 266.422 +  while (dicPos < limit && buf < bufLimit);
 266.423 +  NORMALIZE;
 266.424 +  p->buf = buf;
 266.425 +  p->range = range;
 266.426 +  p->code = code;
 266.427 +  p->remainLen = len;
 266.428 +  p->dicPos = dicPos;
 266.429 +  p->processedPos = processedPos;
 266.430 +  p->reps[0] = rep0;
 266.431 +  p->reps[1] = rep1;
 266.432 +  p->reps[2] = rep2;
 266.433 +  p->reps[3] = rep3;
 266.434 +  p->state = state;
 266.435 +
 266.436 +  return SZ_OK;
 266.437 +}
 266.438 +
 266.439 +static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
 266.440 +{
 266.441 +  if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)
 266.442 +  {
 266.443 +    Byte *dic = p->dic;
 266.444 +    SizeT dicPos = p->dicPos;
 266.445 +    SizeT dicBufSize = p->dicBufSize;
 266.446 +    unsigned len = p->remainLen;
 266.447 +    UInt32 rep0 = p->reps[0];
 266.448 +    if (limit - dicPos < len)
 266.449 +      len = (unsigned)(limit - dicPos);
 266.450 +
 266.451 +    if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)
 266.452 +      p->checkDicSize = p->prop.dicSize;
 266.453 +
 266.454 +    p->processedPos += len;
 266.455 +    p->remainLen -= len;
 266.456 +    while (len-- != 0)
 266.457 +    {
 266.458 +      dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
 266.459 +      dicPos++;
 266.460 +    }
 266.461 +    p->dicPos = dicPos;
 266.462 +  }
 266.463 +}
 266.464 +
 266.465 +static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
 266.466 +{
 266.467 +  do
 266.468 +  {
 266.469 +    SizeT limit2 = limit;
 266.470 +    if (p->checkDicSize == 0)
 266.471 +    {
 266.472 +      UInt32 rem = p->prop.dicSize - p->processedPos;
 266.473 +      if (limit - p->dicPos > rem)
 266.474 +        limit2 = p->dicPos + rem;
 266.475 +    }
 266.476 +    RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));
 266.477 +    if (p->processedPos >= p->prop.dicSize)
 266.478 +      p->checkDicSize = p->prop.dicSize;
 266.479 +    LzmaDec_WriteRem(p, limit);
 266.480 +  }
 266.481 +  while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);
 266.482 +
 266.483 +  if (p->remainLen > kMatchSpecLenStart)
 266.484 +  {
 266.485 +    p->remainLen = kMatchSpecLenStart;
 266.486 +  }
 266.487 +  return 0;
 266.488 +}
 266.489 +
 266.490 +typedef enum
 266.491 +{
 266.492 +  DUMMY_ERROR, /* unexpected end of input stream */
 266.493 +  DUMMY_LIT,
 266.494 +  DUMMY_MATCH,
 266.495 +  DUMMY_REP
 266.496 +} ELzmaDummy;
 266.497 +
 266.498 +static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)
 266.499 +{
 266.500 +  UInt32 range = p->range;
 266.501 +  UInt32 code = p->code;
 266.502 +  const Byte *bufLimit = buf + inSize;
 266.503 +  CLzmaProb *probs = p->probs;
 266.504 +  unsigned state = p->state;
 266.505 +  ELzmaDummy res;
 266.506 +
 266.507 +  {
 266.508 +    CLzmaProb *prob;
 266.509 +    UInt32 bound;
 266.510 +    unsigned ttt;
 266.511 +    unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);
 266.512 +
 266.513 +    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
 266.514 +    IF_BIT_0_CHECK(prob)
 266.515 +    {
 266.516 +      UPDATE_0_CHECK
 266.517 +
 266.518 +      /* if (bufLimit - buf >= 7) return DUMMY_LIT; */
 266.519 +
 266.520 +      prob = probs + Literal;
 266.521 +      if (p->checkDicSize != 0 || p->processedPos != 0)
 266.522 +        prob += (LZMA_LIT_SIZE *
 266.523 +          ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
 266.524 +          (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
 266.525 +
 266.526 +      if (state < kNumLitStates)
 266.527 +      {
 266.528 +        unsigned symbol = 1;
 266.529 +        do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);
 266.530 +      }
 266.531 +      else
 266.532 +      {
 266.533 +        unsigned matchByte = p->dic[p->dicPos - p->reps[0] +
 266.534 +            ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];
 266.535 +        unsigned offs = 0x100;
 266.536 +        unsigned symbol = 1;
 266.537 +        do
 266.538 +        {
 266.539 +          unsigned bit;
 266.540 +          CLzmaProb *probLit;
 266.541 +          matchByte <<= 1;
 266.542 +          bit = (matchByte & offs);
 266.543 +          probLit = prob + offs + bit + symbol;
 266.544 +          GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)
 266.545 +        }
 266.546 +        while (symbol < 0x100);
 266.547 +      }
 266.548 +      res = DUMMY_LIT;
 266.549 +    }
 266.550 +    else
 266.551 +    {
 266.552 +      unsigned len;
 266.553 +      UPDATE_1_CHECK;
 266.554 +
 266.555 +      prob = probs + IsRep + state;
 266.556 +      IF_BIT_0_CHECK(prob)
 266.557 +      {
 266.558 +        UPDATE_0_CHECK;
 266.559 +        state = 0;
 266.560 +        prob = probs + LenCoder;
 266.561 +        res = DUMMY_MATCH;
 266.562 +      }
 266.563 +      else
 266.564 +      {
 266.565 +        UPDATE_1_CHECK;
 266.566 +        res = DUMMY_REP;
 266.567 +        prob = probs + IsRepG0 + state;
 266.568 +        IF_BIT_0_CHECK(prob)
 266.569 +        {
 266.570 +          UPDATE_0_CHECK;
 266.571 +          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
 266.572 +          IF_BIT_0_CHECK(prob)
 266.573 +          {
 266.574 +            UPDATE_0_CHECK;
 266.575 +            NORMALIZE_CHECK;
 266.576 +            return DUMMY_REP;
 266.577 +          }
 266.578 +          else
 266.579 +          {
 266.580 +            UPDATE_1_CHECK;
 266.581 +          }
 266.582 +        }
 266.583 +        else
 266.584 +        {
 266.585 +          UPDATE_1_CHECK;
 266.586 +          prob = probs + IsRepG1 + state;
 266.587 +          IF_BIT_0_CHECK(prob)
 266.588 +          {
 266.589 +            UPDATE_0_CHECK;
 266.590 +          }
 266.591 +          else
 266.592 +          {
 266.593 +            UPDATE_1_CHECK;
 266.594 +            prob = probs + IsRepG2 + state;
 266.595 +            IF_BIT_0_CHECK(prob)
 266.596 +            {
 266.597 +              UPDATE_0_CHECK;
 266.598 +            }
 266.599 +            else
 266.600 +            {
 266.601 +              UPDATE_1_CHECK;
 266.602 +            }
 266.603 +          }
 266.604 +        }
 266.605 +        state = kNumStates;
 266.606 +        prob = probs + RepLenCoder;
 266.607 +      }
 266.608 +      {
 266.609 +        unsigned limit, offset;
 266.610 +        CLzmaProb *probLen = prob + LenChoice;
 266.611 +        IF_BIT_0_CHECK(probLen)
 266.612 +        {
 266.613 +          UPDATE_0_CHECK;
 266.614 +          probLen = prob + LenLow + (posState << kLenNumLowBits);
 266.615 +          offset = 0;
 266.616 +          limit = 1 << kLenNumLowBits;
 266.617 +        }
 266.618 +        else
 266.619 +        {
 266.620 +          UPDATE_1_CHECK;
 266.621 +          probLen = prob + LenChoice2;
 266.622 +          IF_BIT_0_CHECK(probLen)
 266.623 +          {
 266.624 +            UPDATE_0_CHECK;
 266.625 +            probLen = prob + LenMid + (posState << kLenNumMidBits);
 266.626 +            offset = kLenNumLowSymbols;
 266.627 +            limit = 1 << kLenNumMidBits;
 266.628 +          }
 266.629 +          else
 266.630 +          {
 266.631 +            UPDATE_1_CHECK;
 266.632 +            probLen = prob + LenHigh;
 266.633 +            offset = kLenNumLowSymbols + kLenNumMidSymbols;
 266.634 +            limit = 1 << kLenNumHighBits;
 266.635 +          }
 266.636 +        }
 266.637 +        TREE_DECODE_CHECK(probLen, limit, len);
 266.638 +        len += offset;
 266.639 +      }
 266.640 +
 266.641 +      if (state < 4)
 266.642 +      {
 266.643 +        unsigned posSlot;
 266.644 +        prob = probs + PosSlot +
 266.645 +            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
 266.646 +            kNumPosSlotBits);
 266.647 +        TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);
 266.648 +        if (posSlot >= kStartPosModelIndex)
 266.649 +        {
 266.650 +          int numDirectBits = ((posSlot >> 1) - 1);
 266.651 +
 266.652 +          /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */
 266.653 +
 266.654 +          if (posSlot < kEndPosModelIndex)
 266.655 +          {
 266.656 +            prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;
 266.657 +          }
 266.658 +          else
 266.659 +          {
 266.660 +            numDirectBits -= kNumAlignBits;
 266.661 +            do
 266.662 +            {
 266.663 +              NORMALIZE_CHECK
 266.664 +              range >>= 1;
 266.665 +              code -= range & (((code - range) >> 31) - 1);
 266.666 +              /* if (code >= range) code -= range; */
 266.667 +            }
 266.668 +            while (--numDirectBits != 0);
 266.669 +            prob = probs + Align;
 266.670 +            numDirectBits = kNumAlignBits;
 266.671 +          }
 266.672 +          {
 266.673 +            unsigned i = 1;
 266.674 +            do
 266.675 +            {
 266.676 +              GET_BIT_CHECK(prob + i, i);
 266.677 +            }
 266.678 +            while (--numDirectBits != 0);
 266.679 +          }
 266.680 +        }
 266.681 +      }
 266.682 +    }
 266.683 +  }
 266.684 +  NORMALIZE_CHECK;
 266.685 +  return res;
 266.686 +}
 266.687 +
 266.688 +
 266.689 +static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
 266.690 +{
 266.691 +  p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);
 266.692 +  p->range = 0xFFFFFFFF;
 266.693 +  p->needFlush = 0;
 266.694 +}
 266.695 +
 266.696 +void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
 266.697 +{
 266.698 +  p->needFlush = 1;
 266.699 +  p->remainLen = 0;
 266.700 +  p->tempBufSize = 0;
 266.701 +
 266.702 +  if (initDic)
 266.703 +  {
 266.704 +    p->processedPos = 0;
 266.705 +    p->checkDicSize = 0;
 266.706 +    p->needInitState = 1;
 266.707 +  }
 266.708 +  if (initState)
 266.709 +    p->needInitState = 1;
 266.710 +}
 266.711 +
 266.712 +void LzmaDec_Init(CLzmaDec *p)
 266.713 +{
 266.714 +  p->dicPos = 0;
 266.715 +  LzmaDec_InitDicAndState(p, True, True);
 266.716 +}
 266.717 +
 266.718 +static void LzmaDec_InitStateReal(CLzmaDec *p)
 266.719 +{
 266.720 +  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));
 266.721 +  UInt32 i;
 266.722 +  CLzmaProb *probs = p->probs;
 266.723 +  for (i = 0; i < numProbs; i++)
 266.724 +    probs[i] = kBitModelTotal >> 1;
 266.725 +  p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
 266.726 +  p->state = 0;
 266.727 +  p->needInitState = 0;
 266.728 +}
 266.729 +
 266.730 +SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
 266.731 +    ELzmaFinishMode finishMode, ELzmaStatus *status)
 266.732 +{
 266.733 +  SizeT inSize = *srcLen;
 266.734 +  (*srcLen) = 0;
 266.735 +  LzmaDec_WriteRem(p, dicLimit);
 266.736 +  
 266.737 +  *status = LZMA_STATUS_NOT_SPECIFIED;
 266.738 +
 266.739 +  while (p->remainLen != kMatchSpecLenStart)
 266.740 +  {
 266.741 +      int checkEndMarkNow;
 266.742 +
 266.743 +      if (p->needFlush != 0)
 266.744 +      {
 266.745 +        for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
 266.746 +          p->tempBuf[p->tempBufSize++] = *src++;
 266.747 +        if (p->tempBufSize < RC_INIT_SIZE)
 266.748 +        {
 266.749 +          *status = LZMA_STATUS_NEEDS_MORE_INPUT;
 266.750 +          return SZ_OK;
 266.751 +        }
 266.752 +        if (p->tempBuf[0] != 0)
 266.753 +          return SZ_ERROR_DATA;
 266.754 +
 266.755 +        LzmaDec_InitRc(p, p->tempBuf);
 266.756 +        p->tempBufSize = 0;
 266.757 +      }
 266.758 +
 266.759 +      checkEndMarkNow = 0;
 266.760 +      if (p->dicPos >= dicLimit)
 266.761 +      {
 266.762 +        if (p->remainLen == 0 && p->code == 0)
 266.763 +        {
 266.764 +          *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;
 266.765 +          return SZ_OK;
 266.766 +        }
 266.767 +        if (finishMode == LZMA_FINISH_ANY)
 266.768 +        {
 266.769 +          *status = LZMA_STATUS_NOT_FINISHED;
 266.770 +          return SZ_OK;
 266.771 +        }
 266.772 +        if (p->remainLen != 0)
 266.773 +        {
 266.774 +          *status = LZMA_STATUS_NOT_FINISHED;
 266.775 +          return SZ_ERROR_DATA;
 266.776 +        }
 266.777 +        checkEndMarkNow = 1;
 266.778 +      }
 266.779 +
 266.780 +      if (p->needInitState)
 266.781 +        LzmaDec_InitStateReal(p);
 266.782 +  
 266.783 +      if (p->tempBufSize == 0)
 266.784 +      {
 266.785 +        SizeT processed;
 266.786 +        const Byte *bufLimit;
 266.787 +        if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
 266.788 +        {
 266.789 +          int dummyRes = LzmaDec_TryDummy(p, src, inSize);
 266.790 +          if (dummyRes == DUMMY_ERROR)
 266.791 +          {
 266.792 +            memcpy(p->tempBuf, src, inSize);
 266.793 +            p->tempBufSize = (unsigned)inSize;
 266.794 +            (*srcLen) += inSize;
 266.795 +            *status = LZMA_STATUS_NEEDS_MORE_INPUT;
 266.796 +            return SZ_OK;
 266.797 +          }
 266.798 +          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
 266.799 +          {
 266.800 +            *status = LZMA_STATUS_NOT_FINISHED;
 266.801 +            return SZ_ERROR_DATA;
 266.802 +          }
 266.803 +          bufLimit = src;
 266.804 +        }
 266.805 +        else
 266.806 +          bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
 266.807 +        p->buf = src;
 266.808 +        if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
 266.809 +          return SZ_ERROR_DATA;
 266.810 +        processed = (SizeT)(p->buf - src);
 266.811 +        (*srcLen) += processed;
 266.812 +        src += processed;
 266.813 +        inSize -= processed;
 266.814 +      }
 266.815 +      else
 266.816 +      {
 266.817 +        unsigned rem = p->tempBufSize, lookAhead = 0;
 266.818 +        while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
 266.819 +          p->tempBuf[rem++] = src[lookAhead++];
 266.820 +        p->tempBufSize = rem;
 266.821 +        if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
 266.822 +        {
 266.823 +          int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);
 266.824 +          if (dummyRes == DUMMY_ERROR)
 266.825 +          {
 266.826 +            (*srcLen) += lookAhead;
 266.827 +            *status = LZMA_STATUS_NEEDS_MORE_INPUT;
 266.828 +            return SZ_OK;
 266.829 +          }
 266.830 +          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
 266.831 +          {
 266.832 +            *status = LZMA_STATUS_NOT_FINISHED;
 266.833 +            return SZ_ERROR_DATA;
 266.834 +          }
 266.835 +        }
 266.836 +        p->buf = p->tempBuf;
 266.837 +        if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
 266.838 +          return SZ_ERROR_DATA;
 266.839 +        lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));
 266.840 +        (*srcLen) += lookAhead;
 266.841 +        src += lookAhead;
 266.842 +        inSize -= lookAhead;
 266.843 +        p->tempBufSize = 0;
 266.844 +      }
 266.845 +  }
 266.846 +  if (p->code == 0)
 266.847 +    *status = LZMA_STATUS_FINISHED_WITH_MARK;
 266.848 +  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
 266.849 +}
 266.850 +
 266.851 +SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
 266.852 +{
 266.853 +  SizeT outSize = *destLen;
 266.854 +  SizeT inSize = *srcLen;
 266.855 +  *srcLen = *destLen = 0;
 266.856 +  for (;;)
 266.857 +  {
 266.858 +    SizeT inSizeCur = inSize, outSizeCur, dicPos;
 266.859 +    ELzmaFinishMode curFinishMode;
 266.860 +    SRes res;
 266.861 +    if (p->dicPos == p->dicBufSize)
 266.862 +      p->dicPos = 0;
 266.863 +    dicPos = p->dicPos;
 266.864 +    if (outSize > p->dicBufSize - dicPos)
 266.865 +    {
 266.866 +      outSizeCur = p->dicBufSize;
 266.867 +      curFinishMode = LZMA_FINISH_ANY;
 266.868 +    }
 266.869 +    else
 266.870 +    {
 266.871 +      outSizeCur = dicPos + outSize;
 266.872 +      curFinishMode = finishMode;
 266.873 +    }
 266.874 +
 266.875 +    res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
 266.876 +    src += inSizeCur;
 266.877 +    inSize -= inSizeCur;
 266.878 +    *srcLen += inSizeCur;
 266.879 +    outSizeCur = p->dicPos - dicPos;
 266.880 +    memcpy(dest, p->dic + dicPos, outSizeCur);
 266.881 +    dest += outSizeCur;
 266.882 +    outSize -= outSizeCur;
 266.883 +    *destLen += outSizeCur;
 266.884 +    if (res != 0)
 266.885 +      return res;
 266.886 +    if (outSizeCur == 0 || outSize == 0)
 266.887 +      return SZ_OK;
 266.888 +  }
 266.889 +}
 266.890 +
 266.891 +void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
 266.892 +{
 266.893 +  alloc->Free(alloc, p->probs);
 266.894 +  p->probs = 0;
 266.895 +}
 266.896 +
 266.897 +static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
 266.898 +{
 266.899 +  alloc->Free(alloc, p->dic);
 266.900 +  p->dic = 0;
 266.901 +}
 266.902 +
 266.903 +void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
 266.904 +{
 266.905 +  LzmaDec_FreeProbs(p, alloc);
 266.906 +  LzmaDec_FreeDict(p, alloc);
 266.907 +}
 266.908 +
 266.909 +SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
 266.910 +{
 266.911 +  UInt32 dicSize;
 266.912 +  Byte d;
 266.913 +  
 266.914 +  if (size < LZMA_PROPS_SIZE)
 266.915 +    return SZ_ERROR_UNSUPPORTED;
 266.916 +  else
 266.917 +    dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
 266.918 + 
 266.919 +  if (dicSize < LZMA_DIC_MIN)
 266.920 +    dicSize = LZMA_DIC_MIN;
 266.921 +  p->dicSize = dicSize;
 266.922 +
 266.923 +  d = data[0];
 266.924 +  if (d >= (9 * 5 * 5))
 266.925 +    return SZ_ERROR_UNSUPPORTED;
 266.926 +
 266.927 +  p->lc = d % 9;
 266.928 +  d /= 9;
 266.929 +  p->pb = d / 5;
 266.930 +  p->lp = d % 5;
 266.931 +
 266.932 +  return SZ_OK;
 266.933 +}
 266.934 +
 266.935 +static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
 266.936 +{
 266.937 +  UInt32 numProbs = LzmaProps_GetNumProbs(propNew);
 266.938 +  if (p->probs == 0 || numProbs != p->numProbs)
 266.939 +  {
 266.940 +    LzmaDec_FreeProbs(p, alloc);
 266.941 +    p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));
 266.942 +    p->numProbs = numProbs;
 266.943 +    if (p->probs == 0)
 266.944 +      return SZ_ERROR_MEM;
 266.945 +  }
 266.946 +  return SZ_OK;
 266.947 +}
 266.948 +
 266.949 +SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
 266.950 +{
 266.951 +  CLzmaProps propNew;
 266.952 +  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
 266.953 +  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
 266.954 +  p->prop = propNew;
 266.955 +  return SZ_OK;
 266.956 +}
 266.957 +
 266.958 +SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
 266.959 +{
 266.960 +  CLzmaProps propNew;
 266.961 +  SizeT dicBufSize;
 266.962 +  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
 266.963 +  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
 266.964 +  dicBufSize = propNew.dicSize;
 266.965 +  if (p->dic == 0 || dicBufSize != p->dicBufSize)
 266.966 +  {
 266.967 +    LzmaDec_FreeDict(p, alloc);
 266.968 +    p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);
 266.969 +    if (p->dic == 0)
 266.970 +    {
 266.971 +      LzmaDec_FreeProbs(p, alloc);
 266.972 +      return SZ_ERROR_MEM;
 266.973 +    }
 266.974 +  }
 266.975 +  p->dicBufSize = dicBufSize;
 266.976 +  p->prop = propNew;
 266.977 +  return SZ_OK;
 266.978 +}
 266.979 +
 266.980 +SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
 266.981 +    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
 266.982 +    ELzmaStatus *status, ISzAlloc *alloc)
 266.983 +{
 266.984 +  CLzmaDec p;
 266.985 +  SRes res;
 266.986 +  SizeT inSize = *srcLen;
 266.987 +  SizeT outSize = *destLen;
 266.988 +  *srcLen = *destLen = 0;
 266.989 +  if (inSize < RC_INIT_SIZE)
 266.990 +    return SZ_ERROR_INPUT_EOF;
 266.991 +
 266.992 +  LzmaDec_Construct(&p);
 266.993 +  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);
 266.994 +  if (res != 0)
 266.995 +    return res;
 266.996 +  p.dic = dest;
 266.997 +  p.dicBufSize = outSize;
 266.998 +
 266.999 +  LzmaDec_Init(&p);
266.1000 +  
266.1001 +  *srcLen = inSize;
266.1002 +  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
266.1003 +
266.1004 +  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
266.1005 +    res = SZ_ERROR_INPUT_EOF;
266.1006 +
266.1007 +  (*destLen) = p.dicPos;
266.1008 +  LzmaDec_FreeProbs(&p, alloc);
266.1009 +  return res;
266.1010 +}
   267.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   267.2 +++ b/src/win32/7zip/7z/C/LzmaDec.h	Sat Mar 03 10:31:27 2012 -0600
   267.3 @@ -0,0 +1,223 @@
   267.4 +/* LzmaDec.h -- LZMA Decoder
   267.5 +2008-10-04 : Igor Pavlov : Public domain */
   267.6 +
   267.7 +#ifndef __LZMADEC_H
   267.8 +#define __LZMADEC_H
   267.9 +
  267.10 +#include "Types.h"
  267.11 +
  267.12 +/* #define _LZMA_PROB32 */
  267.13 +/* _LZMA_PROB32 can increase the speed on some CPUs,
  267.14 +   but memory usage for CLzmaDec::probs will be doubled in that case */
  267.15 +
  267.16 +#ifdef _LZMA_PROB32
  267.17 +#define CLzmaProb UInt32
  267.18 +#else
  267.19 +#define CLzmaProb UInt16
  267.20 +#endif
  267.21 +
  267.22 +
  267.23 +/* ---------- LZMA Properties ---------- */
  267.24 +
  267.25 +#define LZMA_PROPS_SIZE 5
  267.26 +
  267.27 +typedef struct _CLzmaProps
  267.28 +{
  267.29 +  unsigned lc, lp, pb;
  267.30 +  UInt32 dicSize;
  267.31 +} CLzmaProps;
  267.32 +
  267.33 +/* LzmaProps_Decode - decodes properties
  267.34 +Returns:
  267.35 +  SZ_OK
  267.36 +  SZ_ERROR_UNSUPPORTED - Unsupported properties
  267.37 +*/
  267.38 +
  267.39 +SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
  267.40 +
  267.41 +
  267.42 +/* ---------- LZMA Decoder state ---------- */
  267.43 +
  267.44 +/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
  267.45 +   Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
  267.46 +
  267.47 +#define LZMA_REQUIRED_INPUT_MAX 20
  267.48 +
  267.49 +typedef struct
  267.50 +{
  267.51 +  CLzmaProps prop;
  267.52 +  CLzmaProb *probs;
  267.53 +  Byte *dic;
  267.54 +  const Byte *buf;
  267.55 +  UInt32 range, code;
  267.56 +  SizeT dicPos;
  267.57 +  SizeT dicBufSize;
  267.58 +  UInt32 processedPos;
  267.59 +  UInt32 checkDicSize;
  267.60 +  unsigned state;
  267.61 +  UInt32 reps[4];
  267.62 +  unsigned remainLen;
  267.63 +  int needFlush;
  267.64 +  int needInitState;
  267.65 +  UInt32 numProbs;
  267.66 +  unsigned tempBufSize;
  267.67 +  Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
  267.68 +} CLzmaDec;
  267.69 +
  267.70 +#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
  267.71 +
  267.72 +void LzmaDec_Init(CLzmaDec *p);
  267.73 +
  267.74 +/* There are two types of LZMA streams:
  267.75 +     0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
  267.76 +     1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
  267.77 +
  267.78 +typedef enum
  267.79 +{
  267.80 +  LZMA_FINISH_ANY,   /* finish at any point */
  267.81 +  LZMA_FINISH_END    /* block must be finished at the end */
  267.82 +} ELzmaFinishMode;
  267.83 +
  267.84 +/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
  267.85 +
  267.86 +   You must use LZMA_FINISH_END, when you know that current output buffer
  267.87 +   covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
  267.88 +
  267.89 +   If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
  267.90 +   and output value of destLen will be less than output buffer size limit.
  267.91 +   You can check status result also.
  267.92 +
  267.93 +   You can use multiple checks to test data integrity after full decompression:
  267.94 +     1) Check Result and "status" variable.
  267.95 +     2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
  267.96 +     3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
  267.97 +        You must use correct finish mode in that case. */
  267.98 +
  267.99 +typedef enum
 267.100 +{
 267.101 +  LZMA_STATUS_NOT_SPECIFIED,               /* use main error code instead */
 267.102 +  LZMA_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */
 267.103 +  LZMA_STATUS_NOT_FINISHED,                /* stream was not finished */
 267.104 +  LZMA_STATUS_NEEDS_MORE_INPUT,            /* you must provide more input bytes */
 267.105 +  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK  /* there is probability that stream was finished without end mark */
 267.106 +} ELzmaStatus;
 267.107 +
 267.108 +/* ELzmaStatus is used only as output value for function call */
 267.109 +
 267.110 +
 267.111 +/* ---------- Interfaces ---------- */
 267.112 +
 267.113 +/* There are 3 levels of interfaces:
 267.114 +     1) Dictionary Interface
 267.115 +     2) Buffer Interface
 267.116 +     3) One Call Interface
 267.117 +   You can select any of these interfaces, but don't mix functions from different
 267.118 +   groups for same object. */
 267.119 +
 267.120 +
 267.121 +/* There are two variants to allocate state for Dictionary Interface:
 267.122 +     1) LzmaDec_Allocate / LzmaDec_Free
 267.123 +     2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
 267.124 +   You can use variant 2, if you set dictionary buffer manually.
 267.125 +   For Buffer Interface you must always use variant 1.
 267.126 +
 267.127 +LzmaDec_Allocate* can return:
 267.128 +  SZ_OK
 267.129 +  SZ_ERROR_MEM         - Memory allocation error
 267.130 +  SZ_ERROR_UNSUPPORTED - Unsupported properties
 267.131 +*/
 267.132 +   
 267.133 +SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
 267.134 +void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
 267.135 +
 267.136 +SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
 267.137 +void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
 267.138 +
 267.139 +/* ---------- Dictionary Interface ---------- */
 267.140 +
 267.141 +/* You can use it, if you want to eliminate the overhead for data copying from
 267.142 +   dictionary to some other external buffer.
 267.143 +   You must work with CLzmaDec variables directly in this interface.
 267.144 +
 267.145 +   STEPS:
 267.146 +     LzmaDec_Constr()
 267.147 +     LzmaDec_Allocate()
 267.148 +     for (each new stream)
 267.149 +     {
 267.150 +       LzmaDec_Init()
 267.151 +       while (it needs more decompression)
 267.152 +       {
 267.153 +         LzmaDec_DecodeToDic()
 267.154 +         use data from CLzmaDec::dic and update CLzmaDec::dicPos
 267.155 +       }
 267.156 +     }
 267.157 +     LzmaDec_Free()
 267.158 +*/
 267.159 +
 267.160 +/* LzmaDec_DecodeToDic
 267.161 +   
 267.162 +   The decoding to internal dictionary buffer (CLzmaDec::dic).
 267.163 +   You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
 267.164 +
 267.165 +finishMode:
 267.166 +  It has meaning only if the decoding reaches output limit (dicLimit).
 267.167 +  LZMA_FINISH_ANY - Decode just dicLimit bytes.
 267.168 +  LZMA_FINISH_END - Stream must be finished after dicLimit.
 267.169 +
 267.170 +Returns:
 267.171 +  SZ_OK
 267.172 +    status:
 267.173 +      LZMA_STATUS_FINISHED_WITH_MARK
 267.174 +      LZMA_STATUS_NOT_FINISHED
 267.175 +      LZMA_STATUS_NEEDS_MORE_INPUT
 267.176 +      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
 267.177 +  SZ_ERROR_DATA - Data error
 267.178 +*/
 267.179 +
 267.180 +SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
 267.181 +    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
 267.182 +
 267.183 +
 267.184 +/* ---------- Buffer Interface ---------- */
 267.185 +
 267.186 +/* It's zlib-like interface.
 267.187 +   See LzmaDec_DecodeToDic description for information about STEPS and return results,
 267.188 +   but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
 267.189 +   to work with CLzmaDec variables manually.
 267.190 +
 267.191 +finishMode:
 267.192 +  It has meaning only if the decoding reaches output limit (*destLen).
 267.193 +  LZMA_FINISH_ANY - Decode just destLen bytes.
 267.194 +  LZMA_FINISH_END - Stream must be finished after (*destLen).
 267.195 +*/
 267.196 +
 267.197 +SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
 267.198 +    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
 267.199 +
 267.200 +
 267.201 +/* ---------- One Call Interface ---------- */
 267.202 +
 267.203 +/* LzmaDecode
 267.204 +
 267.205 +finishMode:
 267.206 +  It has meaning only if the decoding reaches output limit (*destLen).
 267.207 +  LZMA_FINISH_ANY - Decode just destLen bytes.
 267.208 +  LZMA_FINISH_END - Stream must be finished after (*destLen).
 267.209 +
 267.210 +Returns:
 267.211 +  SZ_OK
 267.212 +    status:
 267.213 +      LZMA_STATUS_FINISHED_WITH_MARK
 267.214 +      LZMA_STATUS_NOT_FINISHED
 267.215 +      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
 267.216 +  SZ_ERROR_DATA - Data error
 267.217 +  SZ_ERROR_MEM  - Memory allocation error
 267.218 +  SZ_ERROR_UNSUPPORTED - Unsupported properties
 267.219 +  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
 267.220 +*/
 267.221 +
 267.222 +SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
 267.223 +    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
 267.224 +    ELzmaStatus *status, ISzAlloc *alloc);
 267.225 +
 267.226 +#endif
   268.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   268.2 +++ b/src/win32/7zip/7z/C/LzmaEnc.c	Sat Mar 03 10:31:27 2012 -0600
   268.3 @@ -0,0 +1,2275 @@
   268.4 +/* LzmaEnc.c -- LZMA Encoder
   268.5 +2008-10-04 : Igor Pavlov : Public domain */
   268.6 +
   268.7 +#include <string.h>
   268.8 +
   268.9 +/* #define SHOW_STAT */
  268.10 +/* #define SHOW_STAT2 */
  268.11 +
  268.12 +#if defined(SHOW_STAT) || defined(SHOW_STAT2)
  268.13 +#include <stdio.h>
  268.14 +#endif
  268.15 +
  268.16 +#include "LzmaEnc.h"
  268.17 +
  268.18 +#include "LzFind.h"
  268.19 +#ifdef COMPRESS_MF_MT
  268.20 +#include "LzFindMt.h"
  268.21 +#endif
  268.22 +
  268.23 +#ifdef SHOW_STAT
  268.24 +static int ttt = 0;
  268.25 +#endif
  268.26 +
  268.27 +#define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1)
  268.28 +
  268.29 +#define kBlockSize (9 << 10)
  268.30 +#define kUnpackBlockSize (1 << 18)
  268.31 +#define kMatchArraySize (1 << 21)
  268.32 +#define kMatchRecordMaxSize ((LZMA_MATCH_LEN_MAX * 2 + 3) * LZMA_MATCH_LEN_MAX)
  268.33 +
  268.34 +#define kNumMaxDirectBits (31)
  268.35 +
  268.36 +#define kNumTopBits 24
  268.37 +#define kTopValue ((UInt32)1 << kNumTopBits)
  268.38 +
  268.39 +#define kNumBitModelTotalBits 11
  268.40 +#define kBitModelTotal (1 << kNumBitModelTotalBits)
  268.41 +#define kNumMoveBits 5
  268.42 +#define kProbInitValue (kBitModelTotal >> 1)
  268.43 +
  268.44 +#define kNumMoveReducingBits 4
  268.45 +#define kNumBitPriceShiftBits 4
  268.46 +#define kBitPrice (1 << kNumBitPriceShiftBits)
  268.47 +
  268.48 +void LzmaEncProps_Init(CLzmaEncProps *p)
  268.49 +{
  268.50 +  p->level = 5;
  268.51 +  p->dictSize = p->mc = 0;
  268.52 +  p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;
  268.53 +  p->writeEndMark = 0;
  268.54 +}
  268.55 +
  268.56 +void LzmaEncProps_Normalize(CLzmaEncProps *p)
  268.57 +{
  268.58 +  int level = p->level;
  268.59 +  if (level < 0) level = 5;
  268.60 +  p->level = level;
  268.61 +  if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));
  268.62 +  if (p->lc < 0) p->lc = 3;
  268.63 +  if (p->lp < 0) p->lp = 0;
  268.64 +  if (p->pb < 0) p->pb = 2;
  268.65 +  if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);
  268.66 +  if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);
  268.67 +  if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);
  268.68 +  if (p->numHashBytes < 0) p->numHashBytes = 4;
  268.69 +  if (p->mc == 0)  p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);
  268.70 +  if (p->numThreads < 0) p->numThreads = ((p->btMode && p->algo) ? 2 : 1);
  268.71 +}
  268.72 +
  268.73 +UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
  268.74 +{
  268.75 +  CLzmaEncProps props = *props2;
  268.76 +  LzmaEncProps_Normalize(&props);
  268.77 +  return props.dictSize;
  268.78 +}
  268.79 +
  268.80 +/* #define LZMA_LOG_BSR */
  268.81 +/* Define it for Intel's CPU */
  268.82 +
  268.83 +
  268.84 +#ifdef LZMA_LOG_BSR
  268.85 +
  268.86 +#define kDicLogSizeMaxCompress 30
  268.87 +
  268.88 +#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }
  268.89 +
  268.90 +UInt32 GetPosSlot1(UInt32 pos)
  268.91 +{
  268.92 +  UInt32 res;
  268.93 +  BSR2_RET(pos, res);
  268.94 +  return res;
  268.95 +}
  268.96 +#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
  268.97 +#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }
  268.98 +
  268.99 +#else
 268.100 +
 268.101 +#define kNumLogBits (9 + (int)sizeof(size_t) / 2)
 268.102 +#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
 268.103 +
 268.104 +void LzmaEnc_FastPosInit(Byte *g_FastPos)
 268.105 +{
 268.106 +  int c = 2, slotFast;
 268.107 +  g_FastPos[0] = 0;
 268.108 +  g_FastPos[1] = 1;
 268.109 +  
 268.110 +  for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++)
 268.111 +  {
 268.112 +    UInt32 k = (1 << ((slotFast >> 1) - 1));
 268.113 +    UInt32 j;
 268.114 +    for (j = 0; j < k; j++, c++)
 268.115 +      g_FastPos[c] = (Byte)slotFast;
 268.116 +  }
 268.117 +}
 268.118 +
 268.119 +#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \
 268.120 +  (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \
 268.121 +  res = p->g_FastPos[pos >> i] + (i * 2); }
 268.122 +/*
 268.123 +#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \
 268.124 +  p->g_FastPos[pos >> 6] + 12 : \
 268.125 +  p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }
 268.126 +*/
 268.127 +
 268.128 +#define GetPosSlot1(pos) p->g_FastPos[pos]
 268.129 +#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
 268.130 +#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(pos, res); }
 268.131 +
 268.132 +#endif
 268.133 +
 268.134 +
 268.135 +#define LZMA_NUM_REPS 4
 268.136 +
 268.137 +typedef unsigned CState;
 268.138 +
 268.139 +typedef struct _COptimal
 268.140 +{
 268.141 +  UInt32 price;
 268.142 +
 268.143 +  CState state;
 268.144 +  int prev1IsChar;
 268.145 +  int prev2;
 268.146 +
 268.147 +  UInt32 posPrev2;
 268.148 +  UInt32 backPrev2;
 268.149 +
 268.150 +  UInt32 posPrev;
 268.151 +  UInt32 backPrev;
 268.152 +  UInt32 backs[LZMA_NUM_REPS];
 268.153 +} COptimal;
 268.154 +
 268.155 +#define kNumOpts (1 << 12)
 268.156 +
 268.157 +#define kNumLenToPosStates 4
 268.158 +#define kNumPosSlotBits 6
 268.159 +#define kDicLogSizeMin 0
 268.160 +#define kDicLogSizeMax 32
 268.161 +#define kDistTableSizeMax (kDicLogSizeMax * 2)
 268.162 +
 268.163 +
 268.164 +#define kNumAlignBits 4
 268.165 +#define kAlignTableSize (1 << kNumAlignBits)
 268.166 +#define kAlignMask (kAlignTableSize - 1)
 268.167 +
 268.168 +#define kStartPosModelIndex 4
 268.169 +#define kEndPosModelIndex 14
 268.170 +#define kNumPosModels (kEndPosModelIndex - kStartPosModelIndex)
 268.171 +
 268.172 +#define kNumFullDistances (1 << (kEndPosModelIndex / 2))
 268.173 +
 268.174 +#ifdef _LZMA_PROB32
 268.175 +#define CLzmaProb UInt32
 268.176 +#else
 268.177 +#define CLzmaProb UInt16
 268.178 +#endif
 268.179 +
 268.180 +#define LZMA_PB_MAX 4
 268.181 +#define LZMA_LC_MAX 8
 268.182 +#define LZMA_LP_MAX 4
 268.183 +
 268.184 +#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)
 268.185 +
 268.186 +
 268.187 +#define kLenNumLowBits 3
 268.188 +#define kLenNumLowSymbols (1 << kLenNumLowBits)
 268.189 +#define kLenNumMidBits 3
 268.190 +#define kLenNumMidSymbols (1 << kLenNumMidBits)
 268.191 +#define kLenNumHighBits 8
 268.192 +#define kLenNumHighSymbols (1 << kLenNumHighBits)
 268.193 +
 268.194 +#define kLenNumSymbolsTotal (kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)
 268.195 +
 268.196 +#define LZMA_MATCH_LEN_MIN 2
 268.197 +#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)
 268.198 +
 268.199 +#define kNumStates 12
 268.200 +
 268.201 +typedef struct
 268.202 +{
 268.203 +  CLzmaProb choice;
 268.204 +  CLzmaProb choice2;
 268.205 +  CLzmaProb low[LZMA_NUM_PB_STATES_MAX << kLenNumLowBits];
 268.206 +  CLzmaProb mid[LZMA_NUM_PB_STATES_MAX << kLenNumMidBits];
 268.207 +  CLzmaProb high[kLenNumHighSymbols];
 268.208 +} CLenEnc;
 268.209 +
 268.210 +typedef struct
 268.211 +{
 268.212 +  CLenEnc p;
 268.213 +  UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];
 268.214 +  UInt32 tableSize;
 268.215 +  UInt32 counters[LZMA_NUM_PB_STATES_MAX];
 268.216 +} CLenPriceEnc;
 268.217 +
 268.218 +typedef struct _CRangeEnc
 268.219 +{
 268.220 +  UInt32 range;
 268.221 +  Byte cache;
 268.222 +  UInt64 low;
 268.223 +  UInt64 cacheSize;
 268.224 +  Byte *buf;
 268.225 +  Byte *bufLim;
 268.226 +  Byte *bufBase;
 268.227 +  ISeqOutStream *outStream;
 268.228 +  UInt64 processed;
 268.229 +  SRes res;
 268.230 +} CRangeEnc;
 268.231 +
 268.232 +typedef struct _CSeqInStreamBuf
 268.233 +{
 268.234 +  ISeqInStream funcTable;
 268.235 +  const Byte *data;
 268.236 +  SizeT rem;
 268.237 +} CSeqInStreamBuf;
 268.238 +
 268.239 +static SRes MyRead(void *pp, void *data, size_t *size)
 268.240 +{
 268.241 +  size_t curSize = *size;
 268.242 +  CSeqInStreamBuf *p = (CSeqInStreamBuf *)pp;
 268.243 +  if (p->rem < curSize)
 268.244 +    curSize = p->rem;
 268.245 +  memcpy(data, p->data, curSize);
 268.246 +  p->rem -= curSize;
 268.247 +  p->data += curSize;
 268.248 +  *size = curSize;
 268.249 +  return SZ_OK;
 268.250 +}
 268.251 +
 268.252 +typedef struct
 268.253 +{
 268.254 +  CLzmaProb *litProbs;
 268.255 +
 268.256 +  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
 268.257 +  CLzmaProb isRep[kNumStates];
 268.258 +  CLzmaProb isRepG0[kNumStates];
 268.259 +  CLzmaProb isRepG1[kNumStates];
 268.260 +  CLzmaProb isRepG2[kNumStates];
 268.261 +  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
 268.262 +
 268.263 +  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
 268.264 +  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];
 268.265 +  CLzmaProb posAlignEncoder[1 << kNumAlignBits];
 268.266 +  
 268.267 +  CLenPriceEnc lenEnc;
 268.268 +  CLenPriceEnc repLenEnc;
 268.269 +
 268.270 +  UInt32 reps[LZMA_NUM_REPS];
 268.271 +  UInt32 state;
 268.272 +} CSaveState;
 268.273 +
 268.274 +typedef struct _CLzmaEnc
 268.275 +{
 268.276 +  IMatchFinder matchFinder;
 268.277 +  void *matchFinderObj;
 268.278 +
 268.279 +  #ifdef COMPRESS_MF_MT
 268.280 +  Bool mtMode;
 268.281 +  CMatchFinderMt matchFinderMt;
 268.282 +  #endif
 268.283 +
 268.284 +  CMatchFinder matchFinderBase;
 268.285 +
 268.286 +  #ifdef COMPRESS_MF_MT
 268.287 +  Byte pad[128];
 268.288 +  #endif
 268.289 +  
 268.290 +  UInt32 optimumEndIndex;
 268.291 +  UInt32 optimumCurrentIndex;
 268.292 +
 268.293 +  UInt32 longestMatchLength;
 268.294 +  UInt32 numPairs;
 268.295 +  UInt32 numAvail;
 268.296 +  COptimal opt[kNumOpts];
 268.297 +  
 268.298 +  #ifndef LZMA_LOG_BSR
 268.299 +  Byte g_FastPos[1 << kNumLogBits];
 268.300 +  #endif
 268.301 +
 268.302 +  UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
 268.303 +  UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];
 268.304 +  UInt32 numFastBytes;
 268.305 +  UInt32 additionalOffset;
 268.306 +  UInt32 reps[LZMA_NUM_REPS];
 268.307 +  UInt32 state;
 268.308 +
 268.309 +  UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
 268.310 +  UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];
 268.311 +  UInt32 alignPrices[kAlignTableSize];
 268.312 +  UInt32 alignPriceCount;
 268.313 +
 268.314 +  UInt32 distTableSize;
 268.315 +
 268.316 +  unsigned lc, lp, pb;
 268.317 +  unsigned lpMask, pbMask;
 268.318 +
 268.319 +  CLzmaProb *litProbs;
 268.320 +
 268.321 +  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
 268.322 +  CLzmaProb isRep[kNumStates];
 268.323 +  CLzmaProb isRepG0[kNumStates];
 268.324 +  CLzmaProb isRepG1[kNumStates];
 268.325 +  CLzmaProb isRepG2[kNumStates];
 268.326 +  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
 268.327 +
 268.328 +  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
 268.329 +  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];
 268.330 +  CLzmaProb posAlignEncoder[1 << kNumAlignBits];
 268.331 +  
 268.332 +  CLenPriceEnc lenEnc;
 268.333 +  CLenPriceEnc repLenEnc;
 268.334 +
 268.335 +  unsigned lclp;
 268.336 +
 268.337 +  Bool fastMode;
 268.338 +  
 268.339 +  CRangeEnc rc;
 268.340 +
 268.341 +  Bool writeEndMark;
 268.342 +  UInt64 nowPos64;
 268.343 +  UInt32 matchPriceCount;
 268.344 +  Bool finished;
 268.345 +  Bool multiThread;
 268.346 +
 268.347 +  SRes result;
 268.348 +  UInt32 dictSize;
 268.349 +  UInt32 matchFinderCycles;
 268.350 +
 268.351 +  ISeqInStream *inStream;
 268.352 +  CSeqInStreamBuf seqBufInStream;
 268.353 +
 268.354 +  CSaveState saveState;
 268.355 +} CLzmaEnc;
 268.356 +
 268.357 +void LzmaEnc_SaveState(CLzmaEncHandle pp)
 268.358 +{
 268.359 +  CLzmaEnc *p = (CLzmaEnc *)pp;
 268.360 +  CSaveState *dest = &p->saveState;
 268.361 +  int i;
 268.362 +  dest->lenEnc = p->lenEnc;
 268.363 +  dest->repLenEnc = p->repLenEnc;
 268.364 +  dest->state = p->state;
 268.365 +
 268.366 +  for (i = 0; i < kNumStates; i++)
 268.367 +  {
 268.368 +    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
 268.369 +    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
 268.370 +  }
 268.371 +  for (i = 0; i < kNumLenToPosStates; i++)
 268.372 +    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
 268.373 +  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
 268.374 +  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
 268.375 +  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
 268.376 +  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
 268.377 +  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
 268.378 +  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
 268.379 +  memcpy(dest->reps, p->reps, sizeof(p->reps));
 268.380 +  memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));
 268.381 +}
 268.382 +
 268.383 +void LzmaEnc_RestoreState(CLzmaEncHandle pp)
 268.384 +{
 268.385 +  CLzmaEnc *dest = (CLzmaEnc *)pp;
 268.386 +  const CSaveState *p = &dest->saveState;
 268.387 +  int i;
 268.388 +  dest->lenEnc = p->lenEnc;
 268.389 +  dest->repLenEnc = p->repLenEnc;
 268.390 +  dest->state = p->state;
 268.391 +
 268.392 +  for (i = 0; i < kNumStates; i++)
 268.393 +  {
 268.394 +    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
 268.395 +    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
 268.396 +  }
 268.397 +  for (i = 0; i < kNumLenToPosStates; i++)
 268.398 +    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
 268.399 +  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
 268.400 +  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
 268.401 +  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
 268.402 +  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
 268.403 +  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
 268.404 +  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
 268.405 +  memcpy(dest->reps, p->reps, sizeof(p->reps));
 268.406 +  memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));
 268.407 +}
 268.408 +
 268.409 +SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
 268.410 +{
 268.411 +  CLzmaEnc *p = (CLzmaEnc *)pp;
 268.412 +  CLzmaEncProps props = *props2;
 268.413 +  LzmaEncProps_Normalize(&props);
 268.414 +
 268.415 +  if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX ||
 268.416 +      props.dictSize > (1 << kDicLogSizeMaxCompress) || props.dictSize > (1 << 30))
 268.417 +    return SZ_ERROR_PARAM;
 268.418 +  p->dictSize = props.dictSize;
 268.419 +  p->matchFinderCycles = props.mc;
 268.420 +  {
 268.421 +    unsigned fb = props.fb;
 268.422 +    if (fb < 5)
 268.423 +      fb = 5;
 268.424 +    if (fb > LZMA_MATCH_LEN_MAX)
 268.425 +      fb = LZMA_MATCH_LEN_MAX;
 268.426 +    p->numFastBytes = fb;
 268.427 +  }
 268.428 +  p->lc = props.lc;
 268.429 +  p->lp = props.lp;
 268.430 +  p->pb = props.pb;
 268.431 +  p->fastMode = (props.algo == 0);
 268.432 +  p->matchFinderBase.btMode = props.btMode;
 268.433 +  {
 268.434 +    UInt32 numHashBytes = 4;
 268.435 +    if (props.btMode)
 268.436 +    {
 268.437 +      if (props.numHashBytes < 2)
 268.438 +        numHashBytes = 2;
 268.439 +      else if (props.numHashBytes < 4)
 268.440 +        numHashBytes = props.numHashBytes;
 268.441 +    }
 268.442 +    p->matchFinderBase.numHashBytes = numHashBytes;
 268.443 +  }
 268.444 +
 268.445 +  p->matchFinderBase.cutValue = props.mc;
 268.446 +
 268.447 +  p->writeEndMark = props.writeEndMark;
 268.448 +
 268.449 +  #ifdef COMPRESS_MF_MT
 268.450 +  /*
 268.451 +  if (newMultiThread != _multiThread)
 268.452 +  {
 268.453 +    ReleaseMatchFinder();
 268.454 +    _multiThread = newMultiThread;
 268.455 +  }
 268.456 +  */
 268.457 +  p->multiThread = (props.numThreads > 1);
 268.458 +  #endif
 268.459 +
 268.460 +  return SZ_OK;
 268.461 +}
 268.462 +
 268.463 +static const int kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};
 268.464 +static const int kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
 268.465 +static const int kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
 268.466 +static const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
 268.467 +
 268.468 +#define IsCharState(s) ((s) < 7)
 268.469 +
 268.470 +#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)
 268.471 +
 268.472 +#define kInfinityPrice (1 << 30)
 268.473 +
 268.474 +static void RangeEnc_Construct(CRangeEnc *p)
 268.475 +{
 268.476 +  p->outStream = 0;
 268.477 +  p->bufBase = 0;
 268.478 +}
 268.479 +
 268.480 +#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)
 268.481 +
 268.482 +#define RC_BUF_SIZE (1 << 16)
 268.483 +static int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)
 268.484 +{
 268.485 +  if (p->bufBase == 0)
 268.486 +  {
 268.487 +    p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE);
 268.488 +    if (p->bufBase == 0)
 268.489 +      return 0;
 268.490 +    p->bufLim = p->bufBase + RC_BUF_SIZE;
 268.491 +  }
 268.492 +  return 1;
 268.493 +}
 268.494 +
 268.495 +static void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc)
 268.496 +{
 268.497 +  alloc->Free(alloc, p->bufBase);
 268.498 +  p->bufBase = 0;
 268.499 +}
 268.500 +
 268.501 +static void RangeEnc_Init(CRangeEnc *p)
 268.502 +{
 268.503 +  /* Stream.Init(); */
 268.504 +  p->low = 0;
 268.505 +  p->range = 0xFFFFFFFF;
 268.506 +  p->cacheSize = 1;
 268.507 +  p->cache = 0;
 268.508 +
 268.509 +  p->buf = p->bufBase;
 268.510 +
 268.511 +  p->processed = 0;
 268.512 +  p->res = SZ_OK;
 268.513 +}
 268.514 +
 268.515 +static void RangeEnc_FlushStream(CRangeEnc *p)
 268.516 +{
 268.517 +  size_t num;
 268.518 +  if (p->res != SZ_OK)
 268.519 +    return;
 268.520 +  num = p->buf - p->bufBase;
 268.521 +  if (num != p->outStream->Write(p->outStream, p->bufBase, num))
 268.522 +    p->res = SZ_ERROR_WRITE;
 268.523 +  p->processed += num;
 268.524 +  p->buf = p->bufBase;
 268.525 +}
 268.526 +
 268.527 +static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)
 268.528 +{
 268.529 +  if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0)
 268.530 +  {
 268.531 +    Byte temp = p->cache;
 268.532 +    do
 268.533 +    {
 268.534 +      Byte *buf = p->buf;
 268.535 +      *buf++ = (Byte)(temp + (Byte)(p->low >> 32));
 268.536 +      p->buf = buf;
 268.537 +      if (buf == p->bufLim)
 268.538 +        RangeEnc_FlushStream(p);
 268.539 +      temp = 0xFF;
 268.540 +    }
 268.541 +    while (--p->cacheSize != 0);
 268.542 +    p->cache = (Byte)((UInt32)p->low >> 24);
 268.543 +  }
 268.544 +  p->cacheSize++;
 268.545 +  p->low = (UInt32)p->low << 8;
 268.546 +}
 268.547 +
 268.548 +static void RangeEnc_FlushData(CRangeEnc *p)
 268.549 +{
 268.550 +  int i;
 268.551 +  for (i = 0; i < 5; i++)
 268.552 +    RangeEnc_ShiftLow(p);
 268.553 +}
 268.554 +
 268.555 +static void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, int numBits)
 268.556 +{
 268.557 +  do
 268.558 +  {
 268.559 +    p->range >>= 1;
 268.560 +    p->low += p->range & (0 - ((value >> --numBits) & 1));
 268.561 +    if (p->range < kTopValue)
 268.562 +    {
 268.563 +      p->range <<= 8;
 268.564 +      RangeEnc_ShiftLow(p);
 268.565 +    }
 268.566 +  }
 268.567 +  while (numBits != 0);
 268.568 +}
 268.569 +
 268.570 +static void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol)
 268.571 +{
 268.572 +  UInt32 ttt = *prob;
 268.573 +  UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt;
 268.574 +  if (symbol == 0)
 268.575 +  {
 268.576 +    p->range = newBound;
 268.577 +    ttt += (kBitModelTotal - ttt) >> kNumMoveBits;
 268.578 +  }
 268.579 +  else
 268.580 +  {
 268.581 +    p->low += newBound;
 268.582 +    p->range -= newBound;
 268.583 +    ttt -= ttt >> kNumMoveBits;
 268.584 +  }
 268.585 +  *prob = (CLzmaProb)ttt;
 268.586 +  if (p->range < kTopValue)
 268.587 +  {
 268.588 +    p->range <<= 8;
 268.589 +    RangeEnc_ShiftLow(p);
 268.590 +  }
 268.591 +}
 268.592 +
 268.593 +static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)
 268.594 +{
 268.595 +  symbol |= 0x100;
 268.596 +  do
 268.597 +  {
 268.598 +    RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);
 268.599 +    symbol <<= 1;
 268.600 +  }
 268.601 +  while (symbol < 0x10000);
 268.602 +}
 268.603 +
 268.604 +static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte)
 268.605 +{
 268.606 +  UInt32 offs = 0x100;
 268.607 +  symbol |= 0x100;
 268.608 +  do
 268.609 +  {
 268.610 +    matchByte <<= 1;
 268.611 +    RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);
 268.612 +    symbol <<= 1;
 268.613 +    offs &= ~(matchByte ^ symbol);
 268.614 +  }
 268.615 +  while (symbol < 0x10000);
 268.616 +}
 268.617 +
 268.618 +void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
 268.619 +{
 268.620 +  UInt32 i;
 268.621 +  for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))
 268.622 +  {
 268.623 +    const int kCyclesBits = kNumBitPriceShiftBits;
 268.624 +    UInt32 w = i;
 268.625 +    UInt32 bitCount = 0;
 268.626 +    int j;
 268.627 +    for (j = 0; j < kCyclesBits; j++)
 268.628 +    {
 268.629 +      w = w * w;
 268.630 +      bitCount <<= 1;
 268.631 +      while (w >= ((UInt32)1 << 16))
 268.632 +      {
 268.633 +        w >>= 1;
 268.634 +        bitCount++;
 268.635 +      }
 268.636 +    }
 268.637 +    ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);
 268.638 +  }
 268.639 +}
 268.640 +
 268.641 +
 268.642 +#define GET_PRICE(prob, symbol) \
 268.643 +  p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
 268.644 +
 268.645 +#define GET_PRICEa(prob, symbol) \
 268.646 +  ProbPrices[((prob) ^ ((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
 268.647 +
 268.648 +#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]
 268.649 +#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
 268.650 +
 268.651 +#define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits]
 268.652 +#define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
 268.653 +
 268.654 +static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *ProbPrices)
 268.655 +{
 268.656 +  UInt32 price = 0;
 268.657 +  symbol |= 0x100;
 268.658 +  do
 268.659 +  {
 268.660 +    price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);
 268.661 +    symbol <<= 1;
 268.662 +  }
 268.663 +  while (symbol < 0x10000);
 268.664 +  return price;
 268.665 +}
 268.666 +
 268.667 +static UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, UInt32 *ProbPrices)
 268.668 +{
 268.669 +  UInt32 price = 0;
 268.670 +  UInt32 offs = 0x100;
 268.671 +  symbol |= 0x100;
 268.672 +  do
 268.673 +  {
 268.674 +    matchByte <<= 1;
 268.675 +    price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);
 268.676 +    symbol <<= 1;
 268.677 +    offs &= ~(matchByte ^ symbol);
 268.678 +  }
 268.679 +  while (symbol < 0x10000);
 268.680 +  return price;
 268.681 +}
 268.682 +
 268.683 +
 268.684 +static void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)
 268.685 +{
 268.686 +  UInt32 m = 1;
 268.687 +  int i;
 268.688 +  for (i = numBitLevels; i != 0;)
 268.689 +  {
 268.690 +    UInt32 bit;
 268.691 +    i--;
 268.692 +    bit = (symbol >> i) & 1;
 268.693 +    RangeEnc_EncodeBit(rc, probs + m, bit);
 268.694 +    m = (m << 1) | bit;
 268.695 +  }
 268.696 +}
 268.697 +
 268.698 +static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)
 268.699 +{
 268.700 +  UInt32 m = 1;
 268.701 +  int i;
 268.702 +  for (i = 0; i < numBitLevels; i++)
 268.703 +  {
 268.704 +    UInt32 bit = symbol & 1;
 268.705 +    RangeEnc_EncodeBit(rc, probs + m, bit);
 268.706 +    m = (m << 1) | bit;
 268.707 +    symbol >>= 1;
 268.708 +  }
 268.709 +}
 268.710 +
 268.711 +static UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)
 268.712 +{
 268.713 +  UInt32 price = 0;
 268.714 +  symbol |= (1 << numBitLevels);
 268.715 +  while (symbol != 1)
 268.716 +  {
 268.717 +    price += GET_PRICEa(probs[symbol >> 1], symbol & 1);
 268.718 +    symbol >>= 1;
 268.719 +  }
 268.720 +  return price;
 268.721 +}
 268.722 +
 268.723 +static UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)
 268.724 +{
 268.725 +  UInt32 price = 0;
 268.726 +  UInt32 m = 1;
 268.727 +  int i;
 268.728 +  for (i = numBitLevels; i != 0; i--)
 268.729 +  {
 268.730 +    UInt32 bit = symbol & 1;
 268.731 +    symbol >>= 1;
 268.732 +    price += GET_PRICEa(probs[m], bit);
 268.733 +    m = (m << 1) | bit;
 268.734 +  }
 268.735 +  return price;
 268.736 +}
 268.737 +
 268.738 +
 268.739 +static void LenEnc_Init(CLenEnc *p)
 268.740 +{
 268.741 +  unsigned i;
 268.742 +  p->choice = p->choice2 = kProbInitValue;
 268.743 +  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++)
 268.744 +    p->low[i] = kProbInitValue;
 268.745 +  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++)
 268.746 +    p->mid[i] = kProbInitValue;
 268.747 +  for (i = 0; i < kLenNumHighSymbols; i++)
 268.748 +    p->high[i] = kProbInitValue;
 268.749 +}
 268.750 +
 268.751 +static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState)
 268.752 +{
 268.753 +  if (symbol < kLenNumLowSymbols)
 268.754 +  {
 268.755 +    RangeEnc_EncodeBit(rc, &p->choice, 0);
 268.756 +    RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol);
 268.757 +  }
 268.758 +  else
 268.759 +  {
 268.760 +    RangeEnc_EncodeBit(rc, &p->choice, 1);
 268.761 +    if (symbol < kLenNumLowSymbols + kLenNumMidSymbols)
 268.762 +    {
 268.763 +      RangeEnc_EncodeBit(rc, &p->choice2, 0);
 268.764 +      RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbols);
 268.765 +    }
 268.766 +    else
 268.767 +    {
 268.768 +      RangeEnc_EncodeBit(rc, &p->choice2, 1);
 268.769 +      RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols);
 268.770 +    }
 268.771 +  }
 268.772 +}
 268.773 +
 268.774 +static void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32 *ProbPrices)
 268.775 +{
 268.776 +  UInt32 a0 = GET_PRICE_0a(p->choice);
 268.777 +  UInt32 a1 = GET_PRICE_1a(p->choice);
 268.778 +  UInt32 b0 = a1 + GET_PRICE_0a(p->choice2);
 268.779 +  UInt32 b1 = a1 + GET_PRICE_1a(p->choice2);
 268.780 +  UInt32 i = 0;
 268.781 +  for (i = 0; i < kLenNumLowSymbols; i++)
 268.782 +  {
 268.783 +    if (i >= numSymbols)
 268.784 +      return;
 268.785 +    prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPrices);
 268.786 +  }
 268.787 +  for (; i < kLenNumLowSymbols + kLenNumMidSymbols; i++)
 268.788 +  {
 268.789 +    if (i >= numSymbols)
 268.790 +      return;
 268.791 +    prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNumLowSymbols, ProbPrices);
 268.792 +  }
 268.793 +  for (; i < numSymbols; i++)
 268.794 +    prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices);
 268.795 +}
 268.796 +
 268.797 +static void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPrices)
 268.798 +{
 268.799 +  LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices);
 268.800 +  p->counters[posState] = p->tableSize;
 268.801 +}
 268.802 +
 268.803 +static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices)
 268.804 +{
 268.805 +  UInt32 posState;
 268.806 +  for (posState = 0; posState < numPosStates; posState++)
 268.807 +    LenPriceEnc_UpdateTable(p, posState, ProbPrices);
 268.808 +}
 268.809 +
 268.810 +static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, UInt32 *ProbPrices)
 268.811 +{
 268.812 +  LenEnc_Encode(&p->p, rc, symbol, posState);
 268.813 +  if (updatePrice)
 268.814 +    if (--p->counters[posState] == 0)
 268.815 +      LenPriceEnc_UpdateTable(p, posState, ProbPrices);
 268.816 +}
 268.817 +
 268.818 +
 268.819 +
 268.820 +
 268.821 +static void MovePos(CLzmaEnc *p, UInt32 num)
 268.822 +{
 268.823 +  #ifdef SHOW_STAT
 268.824 +  ttt += num;
 268.825 +  printf("\n MovePos %d", num);
 268.826 +  #endif
 268.827 +  if (num != 0)
 268.828 +  {
 268.829 +    p->additionalOffset += num;
 268.830 +    p->matchFinder.Skip(p->matchFinderObj, num);
 268.831 +  }
 268.832 +}
 268.833 +
 268.834 +static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)
 268.835 +{
 268.836 +  UInt32 lenRes = 0, numPairs;
 268.837 +  p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
 268.838 +  numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);
 268.839 +  #ifdef SHOW_STAT
 268.840 +  printf("\n i = %d numPairs = %d    ", ttt, numPairs / 2);
 268.841 +  ttt++;
 268.842 +  {
 268.843 +    UInt32 i;
 268.844 +    for (i = 0; i < numPairs; i += 2)
 268.845 +      printf("%2d %6d   | ", p->matches[i], p->matches[i + 1]);
 268.846 +  }
 268.847 +  #endif
 268.848 +  if (numPairs > 0)
 268.849 +  {
 268.850 +    lenRes = p->matches[numPairs - 2];
 268.851 +    if (lenRes == p->numFastBytes)
 268.852 +    {
 268.853 +      const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
 268.854 +      UInt32 distance = p->matches[numPairs - 1] + 1;
 268.855 +      UInt32 numAvail = p->numAvail;
 268.856 +      if (numAvail > LZMA_MATCH_LEN_MAX)
 268.857 +        numAvail = LZMA_MATCH_LEN_MAX;
 268.858 +      {
 268.859 +        const Byte *pby2 = pby - distance;
 268.860 +        for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);
 268.861 +      }
 268.862 +    }
 268.863 +  }
 268.864 +  p->additionalOffset++;
 268.865 +  *numDistancePairsRes = numPairs;
 268.866 +  return lenRes;
 268.867 +}
 268.868 +
 268.869 +
 268.870 +#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False;
 268.871 +#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False;
 268.872 +#define IsShortRep(p) ((p)->backPrev == 0)
 268.873 +
 268.874 +static UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState)
 268.875 +{
 268.876 +  return
 268.877 +    GET_PRICE_0(p->isRepG0[state]) +
 268.878 +    GET_PRICE_0(p->isRep0Long[state][posState]);
 268.879 +}
 268.880 +
 268.881 +static UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState)
 268.882 +{
 268.883 +  UInt32 price;
 268.884 +  if (repIndex == 0)
 268.885 +  {
 268.886 +    price = GET_PRICE_0(p->isRepG0[state]);
 268.887 +    price += GET_PRICE_1(p->isRep0Long[state][posState]);
 268.888 +  }
 268.889 +  else
 268.890 +  {
 268.891 +    price = GET_PRICE_1(p->isRepG0[state]);
 268.892 +    if (repIndex == 1)
 268.893 +      price += GET_PRICE_0(p->isRepG1[state]);
 268.894 +    else
 268.895 +    {
 268.896 +      price += GET_PRICE_1(p->isRepG1[state]);
 268.897 +      price += GET_PRICE(p->isRepG2[state], repIndex - 2);
 268.898 +    }
 268.899 +  }
 268.900 +  return price;
 268.901 +}
 268.902 +
 268.903 +static UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState)
 268.904 +{
 268.905 +  return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] +
 268.906 +    GetPureRepPrice(p, repIndex, state, posState);
 268.907 +}
 268.908 +
 268.909 +static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)
 268.910 +{
 268.911 +  UInt32 posMem = p->opt[cur].posPrev;
 268.912 +  UInt32 backMem = p->opt[cur].backPrev;
 268.913 +  p->optimumEndIndex = cur;
 268.914 +  do
 268.915 +  {
 268.916 +    if (p->opt[cur].prev1IsChar)
 268.917 +    {
 268.918 +      MakeAsChar(&p->opt[posMem])
 268.919 +      p->opt[posMem].posPrev = posMem - 1;
 268.920 +      if (p->opt[cur].prev2)
 268.921 +      {
 268.922 +        p->opt[posMem - 1].prev1IsChar = False;
 268.923 +        p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2;
 268.924 +        p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2;
 268.925 +      }
 268.926 +    }
 268.927 +    {
 268.928 +      UInt32 posPrev = posMem;
 268.929 +      UInt32 backCur = backMem;
 268.930 +      
 268.931 +      backMem = p->opt[posPrev].backPrev;
 268.932 +      posMem = p->opt[posPrev].posPrev;
 268.933 +      
 268.934 +      p->opt[posPrev].backPrev = backCur;
 268.935 +      p->opt[posPrev].posPrev = cur;
 268.936 +      cur = posPrev;
 268.937 +    }
 268.938 +  }
 268.939 +  while (cur != 0);
 268.940 +  *backRes = p->opt[0].backPrev;
 268.941 +  p->optimumCurrentIndex  = p->opt[0].posPrev;
 268.942 +  return p->optimumCurrentIndex;
 268.943 +}
 268.944 +
 268.945 +#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300)
 268.946 +
 268.947 +static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
 268.948 +{
 268.949 +  UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur;
 268.950 +  UInt32 matchPrice, repMatchPrice, normalMatchPrice;
 268.951 +  UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS];
 268.952 +  UInt32 *matches;
 268.953 +  const Byte *data;
 268.954 +  Byte curByte, matchByte;
 268.955 +  if (p->optimumEndIndex != p->optimumCurrentIndex)
 268.956 +  {
 268.957 +    const COptimal *opt = &p->opt[p->optimumCurrentIndex];
 268.958 +    UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex;
 268.959 +    *backRes = opt->backPrev;
 268.960 +    p->optimumCurrentIndex = opt->posPrev;
 268.961 +    return lenRes;
 268.962 +  }
 268.963 +  p->optimumCurrentIndex = p->optimumEndIndex = 0;
 268.964 +  
 268.965 +  if (p->additionalOffset == 0)
 268.966 +    mainLen = ReadMatchDistances(p, &numPairs);
 268.967 +  else
 268.968 +  {
 268.969 +    mainLen = p->longestMatchLength;
 268.970 +    numPairs = p->numPairs;
 268.971 +  }
 268.972 +
 268.973 +  numAvail = p->numAvail;
 268.974 +  if (numAvail < 2)
 268.975 +  {
 268.976 +    *backRes = (UInt32)(-1);
 268.977 +    return 1;
 268.978 +  }
 268.979 +  if (numAvail > LZMA_MATCH_LEN_MAX)
 268.980 +    numAvail = LZMA_MATCH_LEN_MAX;
 268.981 +
 268.982 +  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
 268.983 +  repMaxIndex = 0;
 268.984 +  for (i = 0; i < LZMA_NUM_REPS; i++)
 268.985 +  {
 268.986 +    UInt32 lenTest;
 268.987 +    const Byte *data2;
 268.988 +    reps[i] = p->reps[i];
 268.989 +    data2 = data - (reps[i] + 1);
 268.990 +    if (data[0] != data2[0] || data[1] != data2[1])
 268.991 +    {
 268.992 +      repLens[i] = 0;
 268.993 +      continue;
 268.994 +    }
 268.995 +    for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);
 268.996 +    repLens[i] = lenTest;
 268.997 +    if (lenTest > repLens[repMaxIndex])
 268.998 +      repMaxIndex = i;
 268.999 +  }
268.1000 +  if (repLens[repMaxIndex] >= p->numFastBytes)
268.1001 +  {
268.1002 +    UInt32 lenRes;
268.1003 +    *backRes = repMaxIndex;
268.1004 +    lenRes = repLens[repMaxIndex];
268.1005 +    MovePos(p, lenRes - 1);
268.1006 +    return lenRes;
268.1007 +  }
268.1008 +
268.1009 +  matches = p->matches;
268.1010 +  if (mainLen >= p->numFastBytes)
268.1011 +  {
268.1012 +    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;
268.1013 +    MovePos(p, mainLen - 1);
268.1014 +    return mainLen;
268.1015 +  }
268.1016 +  curByte = *data;
268.1017 +  matchByte = *(data - (reps[0] + 1));
268.1018 +
268.1019 +  if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2)
268.1020 +  {
268.1021 +    *backRes = (UInt32)-1;
268.1022 +    return 1;
268.1023 +  }
268.1024 +
268.1025 +  p->opt[0].state = (CState)p->state;
268.1026 +
268.1027 +  posState = (position & p->pbMask);
268.1028 +
268.1029 +  {
268.1030 +    const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
268.1031 +    p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +
268.1032 +        (!IsCharState(p->state) ?
268.1033 +          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :
268.1034 +          LitEnc_GetPrice(probs, curByte, p->ProbPrices));
268.1035 +  }
268.1036 +
268.1037 +  MakeAsChar(&p->opt[1]);
268.1038 +
268.1039 +  matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);
268.1040 +  repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);
268.1041 +
268.1042 +  if (matchByte == curByte)
268.1043 +  {
268.1044 +    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState);
268.1045 +    if (shortRepPrice < p->opt[1].price)
268.1046 +    {
268.1047 +      p->opt[1].price = shortRepPrice;
268.1048 +      MakeAsShortRep(&p->opt[1]);
268.1049 +    }
268.1050 +  }
268.1051 +  lenEnd = ((mainLen >= repLens[repMaxIndex]) ? mainLen : repLens[repMaxIndex]);
268.1052 +
268.1053 +  if (lenEnd < 2)
268.1054 +  {
268.1055 +    *backRes = p->opt[1].backPrev;
268.1056 +    return 1;
268.1057 +  }
268.1058 +
268.1059 +  p->opt[1].posPrev = 0;
268.1060 +  for (i = 0; i < LZMA_NUM_REPS; i++)
268.1061 +    p->opt[0].backs[i] = reps[i];
268.1062 +
268.1063 +  len = lenEnd;
268.1064 +  do
268.1065 +    p->opt[len--].price = kInfinityPrice;
268.1066 +  while (len >= 2);
268.1067 +
268.1068 +  for (i = 0; i < LZMA_NUM_REPS; i++)
268.1069 +  {
268.1070 +    UInt32 repLen = repLens[i];
268.1071 +    UInt32 price;
268.1072 +    if (repLen < 2)
268.1073 +      continue;
268.1074 +    price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState);
268.1075 +    do
268.1076 +    {
268.1077 +      UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2];
268.1078 +      COptimal *opt = &p->opt[repLen];
268.1079 +      if (curAndLenPrice < opt->price)
268.1080 +      {
268.1081 +        opt->price = curAndLenPrice;
268.1082 +        opt->posPrev = 0;
268.1083 +        opt->backPrev = i;
268.1084 +        opt->prev1IsChar = False;
268.1085 +      }
268.1086 +    }
268.1087 +    while (--repLen >= 2);
268.1088 +  }
268.1089 +
268.1090 +  normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);
268.1091 +
268.1092 +  len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);
268.1093 +  if (len <= mainLen)
268.1094 +  {
268.1095 +    UInt32 offs = 0;
268.1096 +    while (len > matches[offs])
268.1097 +      offs += 2;
268.1098 +    for (; ; len++)
268.1099 +    {
268.1100 +      COptimal *opt;
268.1101 +      UInt32 distance = matches[offs + 1];
268.1102 +
268.1103 +      UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN];
268.1104 +      UInt32 lenToPosState = GetLenToPosState(len);
268.1105 +      if (distance < kNumFullDistances)
268.1106 +        curAndLenPrice += p->distancesPrices[lenToPosState][distance];
268.1107 +      else
268.1108 +      {
268.1109 +        UInt32 slot;
268.1110 +        GetPosSlot2(distance, slot);
268.1111 +        curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot];
268.1112 +      }
268.1113 +      opt = &p->opt[len];
268.1114 +      if (curAndLenPrice < opt->price)
268.1115 +      {
268.1116 +        opt->price = curAndLenPrice;
268.1117 +        opt->posPrev = 0;
268.1118 +        opt->backPrev = distance + LZMA_NUM_REPS;
268.1119 +        opt->prev1IsChar = False;
268.1120 +      }
268.1121 +      if (len == matches[offs])
268.1122 +      {
268.1123 +        offs += 2;
268.1124 +        if (offs == numPairs)
268.1125 +          break;
268.1126 +      }
268.1127 +    }
268.1128 +  }
268.1129 +
268.1130 +  cur = 0;
268.1131 +
268.1132 +    #ifdef SHOW_STAT2
268.1133 +    if (position >= 0)
268.1134 +    {
268.1135 +      unsigned i;
268.1136 +      printf("\n pos = %4X", position);
268.1137 +      for (i = cur; i <= lenEnd; i++)
268.1138 +      printf("\nprice[%4X] = %d", position - cur + i, p->opt[i].price);
268.1139 +    }
268.1140 +    #endif
268.1141 +
268.1142 +  for (;;)
268.1143 +  {
268.1144 +    UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;
268.1145 +    UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;
268.1146 +    Bool nextIsChar;
268.1147 +    Byte curByte, matchByte;
268.1148 +    const Byte *data;
268.1149 +    COptimal *curOpt;
268.1150 +    COptimal *nextOpt;
268.1151 +
268.1152 +    cur++;
268.1153 +    if (cur == lenEnd)
268.1154 +      return Backward(p, backRes, cur);
268.1155 +
268.1156 +    newLen = ReadMatchDistances(p, &numPairs);
268.1157 +    if (newLen >= p->numFastBytes)
268.1158 +    {
268.1159 +      p->numPairs = numPairs;
268.1160 +      p->longestMatchLength = newLen;
268.1161 +      return Backward(p, backRes, cur);
268.1162 +    }
268.1163 +    position++;
268.1164 +    curOpt = &p->opt[cur];
268.1165 +    posPrev = curOpt->posPrev;
268.1166 +    if (curOpt->prev1IsChar)
268.1167 +    {
268.1168 +      posPrev--;
268.1169 +      if (curOpt->prev2)
268.1170 +      {
268.1171 +        state = p->opt[curOpt->posPrev2].state;
268.1172 +        if (curOpt->backPrev2 < LZMA_NUM_REPS)
268.1173 +          state = kRepNextStates[state];
268.1174 +        else
268.1175 +          state = kMatchNextStates[state];
268.1176 +      }
268.1177 +      else
268.1178 +        state = p->opt[posPrev].state;
268.1179 +      state = kLiteralNextStates[state];
268.1180 +    }
268.1181 +    else
268.1182 +      state = p->opt[posPrev].state;
268.1183 +    if (posPrev == cur - 1)
268.1184 +    {
268.1185 +      if (IsShortRep(curOpt))
268.1186 +        state = kShortRepNextStates[state];
268.1187 +      else
268.1188 +        state = kLiteralNextStates[state];
268.1189 +    }
268.1190 +    else
268.1191 +    {
268.1192 +      UInt32 pos;
268.1193 +      const COptimal *prevOpt;
268.1194 +      if (curOpt->prev1IsChar && curOpt->prev2)
268.1195 +      {
268.1196 +        posPrev = curOpt->posPrev2;
268.1197 +        pos = curOpt->backPrev2;
268.1198 +        state = kRepNextStates[state];
268.1199 +      }
268.1200 +      else
268.1201 +      {
268.1202 +        pos = curOpt->backPrev;
268.1203 +        if (pos < LZMA_NUM_REPS)
268.1204 +          state = kRepNextStates[state];
268.1205 +        else
268.1206 +          state = kMatchNextStates[state];
268.1207 +      }
268.1208 +      prevOpt = &p->opt[posPrev];
268.1209 +      if (pos < LZMA_NUM_REPS)
268.1210 +      {
268.1211 +        UInt32 i;
268.1212 +        reps[0] = prevOpt->backs[pos];
268.1213 +        for (i = 1; i <= pos; i++)
268.1214 +          reps[i] = prevOpt->backs[i - 1];
268.1215 +        for (; i < LZMA_NUM_REPS; i++)
268.1216 +          reps[i] = prevOpt->backs[i];
268.1217 +      }
268.1218 +      else
268.1219 +      {
268.1220 +        UInt32 i;
268.1221 +        reps[0] = (pos - LZMA_NUM_REPS);
268.1222 +        for (i = 1; i < LZMA_NUM_REPS; i++)
268.1223 +          reps[i] = prevOpt->backs[i - 1];
268.1224 +      }
268.1225 +    }
268.1226 +    curOpt->state = (CState)state;
268.1227 +
268.1228 +    curOpt->backs[0] = reps[0];
268.1229 +    curOpt->backs[1] = reps[1];
268.1230 +    curOpt->backs[2] = reps[2];
268.1231 +    curOpt->backs[3] = reps[3];
268.1232 +
268.1233 +    curPrice = curOpt->price;
268.1234 +    nextIsChar = False;
268.1235 +    data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
268.1236 +    curByte = *data;
268.1237 +    matchByte = *(data - (reps[0] + 1));
268.1238 +
268.1239 +    posState = (position & p->pbMask);
268.1240 +
268.1241 +    curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]);
268.1242 +    {
268.1243 +      const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
268.1244 +      curAnd1Price +=
268.1245 +        (!IsCharState(state) ?
268.1246 +          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :
268.1247 +          LitEnc_GetPrice(probs, curByte, p->ProbPrices));
268.1248 +    }
268.1249 +
268.1250 +    nextOpt = &p->opt[cur + 1];
268.1251 +
268.1252 +    if (curAnd1Price < nextOpt->price)
268.1253 +    {
268.1254 +      nextOpt->price = curAnd1Price;
268.1255 +      nextOpt->posPrev = cur;
268.1256 +      MakeAsChar(nextOpt);
268.1257 +      nextIsChar = True;
268.1258 +    }
268.1259 +
268.1260 +    matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);
268.1261 +    repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);
268.1262 +    
268.1263 +    if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))
268.1264 +    {
268.1265 +      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState);
268.1266 +      if (shortRepPrice <= nextOpt->price)
268.1267 +      {
268.1268 +        nextOpt->price = shortRepPrice;
268.1269 +        nextOpt->posPrev = cur;
268.1270 +        MakeAsShortRep(nextOpt);
268.1271 +        nextIsChar = True;
268.1272 +      }
268.1273 +    }
268.1274 +    numAvailFull = p->numAvail;
268.1275 +    {
268.1276 +      UInt32 temp = kNumOpts - 1 - cur;
268.1277 +      if (temp < numAvailFull)
268.1278 +        numAvailFull = temp;
268.1279 +    }
268.1280 +
268.1281 +    if (numAvailFull < 2)
268.1282 +      continue;
268.1283 +    numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);
268.1284 +
268.1285 +    if (!nextIsChar && matchByte != curByte) /* speed optimization */
268.1286 +    {
268.1287 +      /* try Literal + rep0 */
268.1288 +      UInt32 temp;
268.1289 +      UInt32 lenTest2;
268.1290 +      const Byte *data2 = data - (reps[0] + 1);
268.1291 +      UInt32 limit = p->numFastBytes + 1;
268.1292 +      if (limit > numAvailFull)
268.1293 +        limit = numAvailFull;
268.1294 +
268.1295 +      for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);
268.1296 +      lenTest2 = temp - 1;
268.1297 +      if (lenTest2 >= 2)
268.1298 +      {
268.1299 +        UInt32 state2 = kLiteralNextStates[state];
268.1300 +        UInt32 posStateNext = (position + 1) & p->pbMask;
268.1301 +        UInt32 nextRepMatchPrice = curAnd1Price +
268.1302 +            GET_PRICE_1(p->isMatch[state2][posStateNext]) +
268.1303 +            GET_PRICE_1(p->isRep[state2]);
268.1304 +        /* for (; lenTest2 >= 2; lenTest2--) */
268.1305 +        {
268.1306 +          UInt32 curAndLenPrice;
268.1307 +          COptimal *opt;
268.1308 +          UInt32 offset = cur + 1 + lenTest2;
268.1309 +          while (lenEnd < offset)
268.1310 +            p->opt[++lenEnd].price = kInfinityPrice;
268.1311 +          curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
268.1312 +          opt = &p->opt[offset];
268.1313 +          if (curAndLenPrice < opt->price)
268.1314 +          {
268.1315 +            opt->price = curAndLenPrice;
268.1316 +            opt->posPrev = cur + 1;
268.1317 +            opt->backPrev = 0;
268.1318 +            opt->prev1IsChar = True;
268.1319 +            opt->prev2 = False;
268.1320 +          }
268.1321 +        }
268.1322 +      }
268.1323 +    }
268.1324 +    
268.1325 +    startLen = 2; /* speed optimization */
268.1326 +    {
268.1327 +    UInt32 repIndex;
268.1328 +    for (repIndex = 0; repIndex < LZMA_NUM_REPS; repIndex++)
268.1329 +    {
268.1330 +      UInt32 lenTest;
268.1331 +      UInt32 lenTestTemp;
268.1332 +      UInt32 price;
268.1333 +      const Byte *data2 = data - (reps[repIndex] + 1);
268.1334 +      if (data[0] != data2[0] || data[1] != data2[1])
268.1335 +        continue;
268.1336 +      for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);
268.1337 +      while (lenEnd < cur + lenTest)
268.1338 +        p->opt[++lenEnd].price = kInfinityPrice;
268.1339 +      lenTestTemp = lenTest;
268.1340 +      price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState);
268.1341 +      do
268.1342 +      {
268.1343 +        UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2];
268.1344 +        COptimal *opt = &p->opt[cur + lenTest];
268.1345 +        if (curAndLenPrice < opt->price)
268.1346 +        {
268.1347 +          opt->price = curAndLenPrice;
268.1348 +          opt->posPrev = cur;
268.1349 +          opt->backPrev = repIndex;
268.1350 +          opt->prev1IsChar = False;
268.1351 +        }
268.1352 +      }
268.1353 +      while (--lenTest >= 2);
268.1354 +      lenTest = lenTestTemp;
268.1355 +      
268.1356 +      if (repIndex == 0)
268.1357 +        startLen = lenTest + 1;
268.1358 +        
268.1359 +      /* if (_maxMode) */
268.1360 +        {
268.1361 +          UInt32 lenTest2 = lenTest + 1;
268.1362 +          UInt32 limit = lenTest2 + p->numFastBytes;
268.1363 +          UInt32 nextRepMatchPrice;
268.1364 +          if (limit > numAvailFull)
268.1365 +            limit = numAvailFull;
268.1366 +          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
268.1367 +          lenTest2 -= lenTest + 1;
268.1368 +          if (lenTest2 >= 2)
268.1369 +          {
268.1370 +            UInt32 state2 = kRepNextStates[state];
268.1371 +            UInt32 posStateNext = (position + lenTest) & p->pbMask;
268.1372 +            UInt32 curAndLenCharPrice =
268.1373 +                price + p->repLenEnc.prices[posState][lenTest - 2] +
268.1374 +                GET_PRICE_0(p->isMatch[state2][posStateNext]) +
268.1375 +                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),
268.1376 +                    data[lenTest], data2[lenTest], p->ProbPrices);
268.1377 +            state2 = kLiteralNextStates[state2];
268.1378 +            posStateNext = (position + lenTest + 1) & p->pbMask;
268.1379 +            nextRepMatchPrice = curAndLenCharPrice +
268.1380 +                GET_PRICE_1(p->isMatch[state2][posStateNext]) +
268.1381 +                GET_PRICE_1(p->isRep[state2]);
268.1382 +            
268.1383 +            /* for (; lenTest2 >= 2; lenTest2--) */
268.1384 +            {
268.1385 +              UInt32 curAndLenPrice;
268.1386 +              COptimal *opt;
268.1387 +              UInt32 offset = cur + lenTest + 1 + lenTest2;
268.1388 +              while (lenEnd < offset)
268.1389 +                p->opt[++lenEnd].price = kInfinityPrice;
268.1390 +              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
268.1391 +              opt = &p->opt[offset];
268.1392 +              if (curAndLenPrice < opt->price)
268.1393 +              {
268.1394 +                opt->price = curAndLenPrice;
268.1395 +                opt->posPrev = cur + lenTest + 1;
268.1396 +                opt->backPrev = 0;
268.1397 +                opt->prev1IsChar = True;
268.1398 +                opt->prev2 = True;
268.1399 +                opt->posPrev2 = cur;
268.1400 +                opt->backPrev2 = repIndex;
268.1401 +              }
268.1402 +            }
268.1403 +          }
268.1404 +        }
268.1405 +    }
268.1406 +    }
268.1407 +    /* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */
268.1408 +    if (newLen > numAvail)
268.1409 +    {
268.1410 +      newLen = numAvail;
268.1411 +      for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2);
268.1412 +      matches[numPairs] = newLen;
268.1413 +      numPairs += 2;
268.1414 +    }
268.1415 +    if (newLen >= startLen)
268.1416 +    {
268.1417 +      UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);
268.1418 +      UInt32 offs, curBack, posSlot;
268.1419 +      UInt32 lenTest;
268.1420 +      while (lenEnd < cur + newLen)
268.1421 +        p->opt[++lenEnd].price = kInfinityPrice;
268.1422 +
268.1423 +      offs = 0;
268.1424 +      while (startLen > matches[offs])
268.1425 +        offs += 2;
268.1426 +      curBack = matches[offs + 1];
268.1427 +      GetPosSlot2(curBack, posSlot);
268.1428 +      for (lenTest = /*2*/ startLen; ; lenTest++)
268.1429 +      {
268.1430 +        UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];
268.1431 +        UInt32 lenToPosState = GetLenToPosState(lenTest);
268.1432 +        COptimal *opt;
268.1433 +        if (curBack < kNumFullDistances)
268.1434 +          curAndLenPrice += p->distancesPrices[lenToPosState][curBack];
268.1435 +        else
268.1436 +          curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask];
268.1437 +        
268.1438 +        opt = &p->opt[cur + lenTest];
268.1439 +        if (curAndLenPrice < opt->price)
268.1440 +        {
268.1441 +          opt->price = curAndLenPrice;
268.1442 +          opt->posPrev = cur;
268.1443 +          opt->backPrev = curBack + LZMA_NUM_REPS;
268.1444 +          opt->prev1IsChar = False;
268.1445 +        }
268.1446 +
268.1447 +        if (/*_maxMode && */lenTest == matches[offs])
268.1448 +        {
268.1449 +          /* Try Match + Literal + Rep0 */
268.1450 +          const Byte *data2 = data - (curBack + 1);
268.1451 +          UInt32 lenTest2 = lenTest + 1;
268.1452 +          UInt32 limit = lenTest2 + p->numFastBytes;
268.1453 +          UInt32 nextRepMatchPrice;
268.1454 +          if (limit > numAvailFull)
268.1455 +            limit = numAvailFull;
268.1456 +          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
268.1457 +          lenTest2 -= lenTest + 1;
268.1458 +          if (lenTest2 >= 2)
268.1459 +          {
268.1460 +            UInt32 state2 = kMatchNextStates[state];
268.1461 +            UInt32 posStateNext = (position + lenTest) & p->pbMask;
268.1462 +            UInt32 curAndLenCharPrice = curAndLenPrice +
268.1463 +                GET_PRICE_0(p->isMatch[state2][posStateNext]) +
268.1464 +                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),
268.1465 +                    data[lenTest], data2[lenTest], p->ProbPrices);
268.1466 +            state2 = kLiteralNextStates[state2];
268.1467 +            posStateNext = (posStateNext + 1) & p->pbMask;
268.1468 +            nextRepMatchPrice = curAndLenCharPrice +
268.1469 +                GET_PRICE_1(p->isMatch[state2][posStateNext]) +
268.1470 +                GET_PRICE_1(p->isRep[state2]);
268.1471 +            
268.1472 +            /* for (; lenTest2 >= 2; lenTest2--) */
268.1473 +            {
268.1474 +              UInt32 offset = cur + lenTest + 1 + lenTest2;
268.1475 +              UInt32 curAndLenPrice;
268.1476 +              COptimal *opt;
268.1477 +              while (lenEnd < offset)
268.1478 +                p->opt[++lenEnd].price = kInfinityPrice;
268.1479 +              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
268.1480 +              opt = &p->opt[offset];
268.1481 +              if (curAndLenPrice < opt->price)
268.1482 +              {
268.1483 +                opt->price = curAndLenPrice;
268.1484 +                opt->posPrev = cur + lenTest + 1;
268.1485 +                opt->backPrev = 0;
268.1486 +                opt->prev1IsChar = True;
268.1487 +                opt->prev2 = True;
268.1488 +                opt->posPrev2 = cur;
268.1489 +                opt->backPrev2 = curBack + LZMA_NUM_REPS;
268.1490 +              }
268.1491 +            }
268.1492 +          }
268.1493 +          offs += 2;
268.1494 +          if (offs == numPairs)
268.1495 +            break;
268.1496 +          curBack = matches[offs + 1];
268.1497 +          if (curBack >= kNumFullDistances)
268.1498 +            GetPosSlot2(curBack, posSlot);
268.1499 +        }
268.1500 +      }
268.1501 +    }
268.1502 +  }
268.1503 +}
268.1504 +
268.1505 +#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist))
268.1506 +
268.1507 +static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)
268.1508 +{
268.1509 +  UInt32 numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i;
268.1510 +  const Byte *data;
268.1511 +  const UInt32 *matches;
268.1512 +
268.1513 +  if (p->additionalOffset == 0)
268.1514 +    mainLen = ReadMatchDistances(p, &numPairs);
268.1515 +  else
268.1516 +  {
268.1517 +    mainLen = p->longestMatchLength;
268.1518 +    numPairs = p->numPairs;
268.1519 +  }
268.1520 +
268.1521 +  numAvail = p->numAvail;
268.1522 +  *backRes = (UInt32)-1;
268.1523 +  if (numAvail < 2)
268.1524 +    return 1;
268.1525 +  if (numAvail > LZMA_MATCH_LEN_MAX)
268.1526 +    numAvail = LZMA_MATCH_LEN_MAX;
268.1527 +  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
268.1528 +
268.1529 +  repLen = repIndex = 0;
268.1530 +  for (i = 0; i < LZMA_NUM_REPS; i++)
268.1531 +  {
268.1532 +    UInt32 len;
268.1533 +    const Byte *data2 = data - (p->reps[i] + 1);
268.1534 +    if (data[0] != data2[0] || data[1] != data2[1])
268.1535 +      continue;
268.1536 +    for (len = 2; len < numAvail && data[len] == data2[len]; len++);
268.1537 +    if (len >= p->numFastBytes)
268.1538 +    {
268.1539 +      *backRes = i;
268.1540 +      MovePos(p, len - 1);
268.1541 +      return len;
268.1542 +    }
268.1543 +    if (len > repLen)
268.1544 +    {
268.1545 +      repIndex = i;
268.1546 +      repLen = len;
268.1547 +    }
268.1548 +  }
268.1549 +
268.1550 +  matches = p->matches;
268.1551 +  if (mainLen >= p->numFastBytes)
268.1552 +  {
268.1553 +    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;
268.1554 +    MovePos(p, mainLen - 1);
268.1555 +    return mainLen;
268.1556 +  }
268.1557 +
268.1558 +  mainDist = 0; /* for GCC */
268.1559 +  if (mainLen >= 2)
268.1560 +  {
268.1561 +    mainDist = matches[numPairs - 1];
268.1562 +    while (numPairs > 2 && mainLen == matches[numPairs - 4] + 1)
268.1563 +    {
268.1564 +      if (!ChangePair(matches[numPairs - 3], mainDist))
268.1565 +        break;
268.1566 +      numPairs -= 2;
268.1567 +      mainLen = matches[numPairs - 2];
268.1568 +      mainDist = matches[numPairs - 1];
268.1569 +    }
268.1570 +    if (mainLen == 2 && mainDist >= 0x80)
268.1571 +      mainLen = 1;
268.1572 +  }
268.1573 +
268.1574 +  if (repLen >= 2 && (
268.1575 +        (repLen + 1 >= mainLen) ||
268.1576 +        (repLen + 2 >= mainLen && mainDist >= (1 << 9)) ||
268.1577 +        (repLen + 3 >= mainLen && mainDist >= (1 << 15))))
268.1578 +  {
268.1579 +    *backRes = repIndex;
268.1580 +    MovePos(p, repLen - 1);
268.1581 +    return repLen;
268.1582 +  }
268.1583 +  
268.1584 +  if (mainLen < 2 || numAvail <= 2)
268.1585 +    return 1;
268.1586 +
268.1587 +  p->longestMatchLength = ReadMatchDistances(p, &p->numPairs);
268.1588 +  if (p->longestMatchLength >= 2)
268.1589 +  {
268.1590 +    UInt32 newDistance = matches[p->numPairs - 1];
268.1591 +    if ((p->longestMatchLength >= mainLen && newDistance < mainDist) ||
268.1592 +        (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) ||
268.1593 +        (p->longestMatchLength > mainLen + 1) ||
268.1594 +        (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist)))
268.1595 +      return 1;
268.1596 +  }
268.1597 +  
268.1598 +  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
268.1599 +  for (i = 0; i < LZMA_NUM_REPS; i++)
268.1600 +  {
268.1601 +    UInt32 len, limit;
268.1602 +    const Byte *data2 = data - (p->reps[i] + 1);
268.1603 +    if (data[0] != data2[0] || data[1] != data2[1])
268.1604 +      continue;
268.1605 +    limit = mainLen - 1;
268.1606 +    for (len = 2; len < limit && data[len] == data2[len]; len++);
268.1607 +    if (len >= limit)
268.1608 +      return 1;
268.1609 +  }
268.1610 +  *backRes = mainDist + LZMA_NUM_REPS;
268.1611 +  MovePos(p, mainLen - 2);
268.1612 +  return mainLen;
268.1613 +}
268.1614 +
268.1615 +static void WriteEndMarker(CLzmaEnc *p, UInt32 posState)
268.1616 +{
268.1617 +  UInt32 len;
268.1618 +  RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);
268.1619 +  RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);
268.1620 +  p->state = kMatchNextStates[p->state];
268.1621 +  len = LZMA_MATCH_LEN_MIN;
268.1622 +  LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
268.1623 +  RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlotBits) - 1);
268.1624 +  RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits);
268.1625 +  RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask);
268.1626 +}
268.1627 +
268.1628 +static SRes CheckErrors(CLzmaEnc *p)
268.1629 +{
268.1630 +  if (p->result != SZ_OK)
268.1631 +    return p->result;
268.1632 +  if (p->rc.res != SZ_OK)
268.1633 +    p->result = SZ_ERROR_WRITE;
268.1634 +  if (p->matchFinderBase.result != SZ_OK)
268.1635 +    p->result = SZ_ERROR_READ;
268.1636 +  if (p->result != SZ_OK)
268.1637 +    p->finished = True;
268.1638 +  return p->result;
268.1639 +}
268.1640 +
268.1641 +static SRes Flush(CLzmaEnc *p, UInt32 nowPos)
268.1642 +{
268.1643 +  /* ReleaseMFStream(); */
268.1644 +  p->finished = True;
268.1645 +  if (p->writeEndMark)
268.1646 +    WriteEndMarker(p, nowPos & p->pbMask);
268.1647 +  RangeEnc_FlushData(&p->rc);
268.1648 +  RangeEnc_FlushStream(&p->rc);
268.1649 +  return CheckErrors(p);
268.1650 +}
268.1651 +
268.1652 +static void FillAlignPrices(CLzmaEnc *p)
268.1653 +{
268.1654 +  UInt32 i;
268.1655 +  for (i = 0; i < kAlignTableSize; i++)
268.1656 +    p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);
268.1657 +  p->alignPriceCount = 0;
268.1658 +}
268.1659 +
268.1660 +static void FillDistancesPrices(CLzmaEnc *p)
268.1661 +{
268.1662 +  UInt32 tempPrices[kNumFullDistances];
268.1663 +  UInt32 i, lenToPosState;
268.1664 +  for (i = kStartPosModelIndex; i < kNumFullDistances; i++)
268.1665 +  {
268.1666 +    UInt32 posSlot = GetPosSlot1(i);
268.1667 +    UInt32 footerBits = ((posSlot >> 1) - 1);
268.1668 +    UInt32 base = ((2 | (posSlot & 1)) << footerBits);
268.1669 +    tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, p->ProbPrices);
268.1670 +  }
268.1671 +
268.1672 +  for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)
268.1673 +  {
268.1674 +    UInt32 posSlot;
268.1675 +    const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState];
268.1676 +    UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState];
268.1677 +    for (posSlot = 0; posSlot < p->distTableSize; posSlot++)
268.1678 +      posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices);
268.1679 +    for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++)
268.1680 +      posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits);
268.1681 +
268.1682 +    {
268.1683 +      UInt32 *distancesPrices = p->distancesPrices[lenToPosState];
268.1684 +      UInt32 i;
268.1685 +      for (i = 0; i < kStartPosModelIndex; i++)
268.1686 +        distancesPrices[i] = posSlotPrices[i];
268.1687 +      for (; i < kNumFullDistances; i++)
268.1688 +        distancesPrices[i] = posSlotPrices[GetPosSlot1(i)] + tempPrices[i];
268.1689 +    }
268.1690 +  }
268.1691 +  p->matchPriceCount = 0;
268.1692 +}
268.1693 +
268.1694 +void LzmaEnc_Construct(CLzmaEnc *p)
268.1695 +{
268.1696 +  RangeEnc_Construct(&p->rc);
268.1697 +  MatchFinder_Construct(&p->matchFinderBase);
268.1698 +  #ifdef COMPRESS_MF_MT
268.1699 +  MatchFinderMt_Construct(&p->matchFinderMt);
268.1700 +  p->matchFinderMt.MatchFinder = &p->matchFinderBase;
268.1701 +  #endif
268.1702 +
268.1703 +  {
268.1704 +    CLzmaEncProps props;
268.1705 +    LzmaEncProps_Init(&props);
268.1706 +    LzmaEnc_SetProps(p, &props);
268.1707 +  }
268.1708 +
268.1709 +  #ifndef LZMA_LOG_BSR
268.1710 +  LzmaEnc_FastPosInit(p->g_FastPos);
268.1711 +  #endif
268.1712 +
268.1713 +  LzmaEnc_InitPriceTables(p->ProbPrices);
268.1714 +  p->litProbs = 0;
268.1715 +  p->saveState.litProbs = 0;
268.1716 +}
268.1717 +
268.1718 +CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)
268.1719 +{
268.1720 +  void *p;
268.1721 +  p = alloc->Alloc(alloc, sizeof(CLzmaEnc));
268.1722 +  if (p != 0)
268.1723 +    LzmaEnc_Construct((CLzmaEnc *)p);
268.1724 +  return p;
268.1725 +}
268.1726 +
268.1727 +void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
268.1728 +{
268.1729 +  alloc->Free(alloc, p->litProbs);
268.1730 +  alloc->Free(alloc, p->saveState.litProbs);
268.1731 +  p->litProbs = 0;
268.1732 +  p->saveState.litProbs = 0;
268.1733 +}
268.1734 +
268.1735 +void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
268.1736 +{
268.1737 +  #ifdef COMPRESS_MF_MT
268.1738 +  MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
268.1739 +  #endif
268.1740 +  MatchFinder_Free(&p->matchFinderBase, allocBig);
268.1741 +  LzmaEnc_FreeLits(p, alloc);
268.1742 +  RangeEnc_Free(&p->rc, alloc);
268.1743 +}
268.1744 +
268.1745 +void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig)
268.1746 +{
268.1747 +  LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);
268.1748 +  alloc->Free(alloc, p);
268.1749 +}
268.1750 +
268.1751 +static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize)
268.1752 +{
268.1753 +  UInt32 nowPos32, startPos32;
268.1754 +  if (p->inStream != 0)
268.1755 +  {
268.1756 +    p->matchFinderBase.stream = p->inStream;
268.1757 +    p->matchFinder.Init(p->matchFinderObj);
268.1758 +    p->inStream = 0;
268.1759 +  }
268.1760 +
268.1761 +  if (p->finished)
268.1762 +    return p->result;
268.1763 +  RINOK(CheckErrors(p));
268.1764 +
268.1765 +  nowPos32 = (UInt32)p->nowPos64;
268.1766 +  startPos32 = nowPos32;
268.1767 +
268.1768 +  if (p->nowPos64 == 0)
268.1769 +  {
268.1770 +    UInt32 numPairs;
268.1771 +    Byte curByte;
268.1772 +    if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
268.1773 +      return Flush(p, nowPos32);
268.1774 +    ReadMatchDistances(p, &numPairs);
268.1775 +    RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);
268.1776 +    p->state = kLiteralNextStates[p->state];
268.1777 +    curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset);
268.1778 +    LitEnc_Encode(&p->rc, p->litProbs, curByte);
268.1779 +    p->additionalOffset--;
268.1780 +    nowPos32++;
268.1781 +  }
268.1782 +
268.1783 +  if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)
268.1784 +  for (;;)
268.1785 +  {
268.1786 +    UInt32 pos, len, posState;
268.1787 +
268.1788 +    if (p->fastMode)
268.1789 +      len = GetOptimumFast(p, &pos);
268.1790 +    else
268.1791 +      len = GetOptimum(p, nowPos32, &pos);
268.1792 +
268.1793 +    #ifdef SHOW_STAT2
268.1794 +    printf("\n pos = %4X,   len = %d   pos = %d", nowPos32, len, pos);
268.1795 +    #endif
268.1796 +
268.1797 +    posState = nowPos32 & p->pbMask;
268.1798 +    if (len == 1 && pos == (UInt32)-1)
268.1799 +    {
268.1800 +      Byte curByte;
268.1801 +      CLzmaProb *probs;
268.1802 +      const Byte *data;
268.1803 +
268.1804 +      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0);
268.1805 +      data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
268.1806 +      curByte = *data;
268.1807 +      probs = LIT_PROBS(nowPos32, *(data - 1));
268.1808 +      if (IsCharState(p->state))
268.1809 +        LitEnc_Encode(&p->rc, probs, curByte);
268.1810 +      else
268.1811 +        LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1));
268.1812 +      p->state = kLiteralNextStates[p->state];
268.1813 +    }
268.1814 +    else
268.1815 +    {
268.1816 +      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);
268.1817 +      if (pos < LZMA_NUM_REPS)
268.1818 +      {
268.1819 +        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1);
268.1820 +        if (pos == 0)
268.1821 +        {
268.1822 +          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0);
268.1823 +          RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1));
268.1824 +        }
268.1825 +        else
268.1826 +        {
268.1827 +          UInt32 distance = p->reps[pos];
268.1828 +          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1);
268.1829 +          if (pos == 1)
268.1830 +            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0);
268.1831 +          else
268.1832 +          {
268.1833 +            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1);
268.1834 +            RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2);
268.1835 +            if (pos == 3)
268.1836 +              p->reps[3] = p->reps[2];
268.1837 +            p->reps[2] = p->reps[1];
268.1838 +          }
268.1839 +          p->reps[1] = p->reps[0];
268.1840 +          p->reps[0] = distance;
268.1841 +        }
268.1842 +        if (len == 1)
268.1843 +          p->state = kShortRepNextStates[p->state];
268.1844 +        else
268.1845 +        {
268.1846 +          LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
268.1847 +          p->state = kRepNextStates[p->state];
268.1848 +        }
268.1849 +      }
268.1850 +      else
268.1851 +      {
268.1852 +        UInt32 posSlot;
268.1853 +        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);
268.1854 +        p->state = kMatchNextStates[p->state];
268.1855 +        LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
268.1856 +        pos -= LZMA_NUM_REPS;
268.1857 +        GetPosSlot(pos, posSlot);
268.1858 +        RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);
268.1859 +        
268.1860 +        if (posSlot >= kStartPosModelIndex)
268.1861 +        {
268.1862 +          UInt32 footerBits = ((posSlot >> 1) - 1);
268.1863 +          UInt32 base = ((2 | (posSlot & 1)) << footerBits);
268.1864 +          UInt32 posReduced = pos - base;
268.1865 +
268.1866 +          if (posSlot < kEndPosModelIndex)
268.1867 +            RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced);
268.1868 +          else
268.1869 +          {
268.1870 +            RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);
268.1871 +            RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);
268.1872 +            p->alignPriceCount++;
268.1873 +          }
268.1874 +        }
268.1875 +        p->reps[3] = p->reps[2];
268.1876 +        p->reps[2] = p->reps[1];
268.1877 +        p->reps[1] = p->reps[0];
268.1878 +        p->reps[0] = pos;
268.1879 +        p->matchPriceCount++;
268.1880 +      }
268.1881 +    }
268.1882 +    p->additionalOffset -= len;
268.1883 +    nowPos32 += len;
268.1884 +    if (p->additionalOffset == 0)
268.1885 +    {
268.1886 +      UInt32 processed;
268.1887 +      if (!p->fastMode)
268.1888 +      {
268.1889 +        if (p->matchPriceCount >= (1 << 7))
268.1890 +          FillDistancesPrices(p);
268.1891 +        if (p->alignPriceCount >= kAlignTableSize)
268.1892 +          FillAlignPrices(p);
268.1893 +      }
268.1894 +      if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
268.1895 +        break;
268.1896 +      processed = nowPos32 - startPos32;
268.1897 +      if (useLimits)
268.1898 +      {
268.1899 +        if (processed + kNumOpts + 300 >= maxUnpackSize ||
268.1900 +            RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)
268.1901 +          break;
268.1902 +      }
268.1903 +      else if (processed >= (1 << 15))
268.1904 +      {
268.1905 +        p->nowPos64 += nowPos32 - startPos32;
268.1906 +        return CheckErrors(p);
268.1907 +      }
268.1908 +    }
268.1909 +  }
268.1910 +  p->nowPos64 += nowPos32 - startPos32;
268.1911 +  return Flush(p, nowPos32);
268.1912 +}
268.1913 +
268.1914 +#define kBigHashDicLimit ((UInt32)1 << 24)
268.1915 +
268.1916 +static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
268.1917 +{
268.1918 +  UInt32 beforeSize = kNumOpts;
268.1919 +  Bool btMode;
268.1920 +  if (!RangeEnc_Alloc(&p->rc, alloc))
268.1921 +    return SZ_ERROR_MEM;
268.1922 +  btMode = (p->matchFinderBase.btMode != 0);
268.1923 +  #ifdef COMPRESS_MF_MT
268.1924 +  p->mtMode = (p->multiThread && !p->fastMode && btMode);
268.1925 +  #endif
268.1926 +
268.1927 +  {
268.1928 +    unsigned lclp = p->lc + p->lp;
268.1929 +    if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp)
268.1930 +    {
268.1931 +      LzmaEnc_FreeLits(p, alloc);
268.1932 +      p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));
268.1933 +      p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));
268.1934 +      if (p->litProbs == 0 || p->saveState.litProbs == 0)
268.1935 +      {
268.1936 +        LzmaEnc_FreeLits(p, alloc);
268.1937 +        return SZ_ERROR_MEM;
268.1938 +      }
268.1939 +      p->lclp = lclp;
268.1940 +    }
268.1941 +  }
268.1942 +
268.1943 +  p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit);
268.1944 +
268.1945 +  if (beforeSize + p->dictSize < keepWindowSize)
268.1946 +    beforeSize = keepWindowSize - p->dictSize;
268.1947 +
268.1948 +  #ifdef COMPRESS_MF_MT
268.1949 +  if (p->mtMode)
268.1950 +  {
268.1951 +    RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));
268.1952 +    p->matchFinderObj = &p->matchFinderMt;
268.1953 +    MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);
268.1954 +  }
268.1955 +  else
268.1956 +  #endif
268.1957 +  {
268.1958 +    if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))
268.1959 +      return SZ_ERROR_MEM;
268.1960 +    p->matchFinderObj = &p->matchFinderBase;
268.1961 +    MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);
268.1962 +  }
268.1963 +  return SZ_OK;
268.1964 +}
268.1965 +
268.1966 +void LzmaEnc_Init(CLzmaEnc *p)
268.1967 +{
268.1968 +  UInt32 i;
268.1969 +  p->state = 0;
268.1970 +  for (i = 0 ; i < LZMA_NUM_REPS; i++)
268.1971 +    p->reps[i] = 0;
268.1972 +
268.1973 +  RangeEnc_Init(&p->rc);
268.1974 +
268.1975 +
268.1976 +  for (i = 0; i < kNumStates; i++)
268.1977 +  {
268.1978 +    UInt32 j;
268.1979 +    for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)
268.1980 +    {
268.1981 +      p->isMatch[i][j] = kProbInitValue;
268.1982 +      p->isRep0Long[i][j] = kProbInitValue;
268.1983 +    }
268.1984 +    p->isRep[i] = kProbInitValue;
268.1985 +    p->isRepG0[i] = kProbInitValue;
268.1986 +    p->isRepG1[i] = kProbInitValue;
268.1987 +    p->isRepG2[i] = kProbInitValue;
268.1988 +  }
268.1989 +
268.1990 +  {
268.1991 +    UInt32 num = 0x300 << (p->lp + p->lc);
268.1992 +    for (i = 0; i < num; i++)
268.1993 +      p->litProbs[i] = kProbInitValue;
268.1994 +  }
268.1995 +
268.1996 +  {
268.1997 +    for (i = 0; i < kNumLenToPosStates; i++)
268.1998 +    {
268.1999 +      CLzmaProb *probs = p->posSlotEncoder[i];
268.2000 +      UInt32 j;
268.2001 +      for (j = 0; j < (1 << kNumPosSlotBits); j++)
268.2002 +        probs[j] = kProbInitValue;
268.2003 +    }
268.2004 +  }
268.2005 +  {
268.2006 +    for (i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)
268.2007 +      p->posEncoders[i] = kProbInitValue;
268.2008 +  }
268.2009 +
268.2010 +  LenEnc_Init(&p->lenEnc.p);
268.2011 +  LenEnc_Init(&p->repLenEnc.p);
268.2012 +
268.2013 +  for (i = 0; i < (1 << kNumAlignBits); i++)
268.2014 +    p->posAlignEncoder[i] = kProbInitValue;
268.2015 +
268.2016 +  p->optimumEndIndex = 0;
268.2017 +  p->optimumCurrentIndex = 0;
268.2018 +  p->additionalOffset = 0;
268.2019 +
268.2020 +  p->pbMask = (1 << p->pb) - 1;
268.2021 +  p->lpMask = (1 << p->lp) - 1;
268.2022 +}
268.2023 +
268.2024 +void LzmaEnc_InitPrices(CLzmaEnc *p)
268.2025 +{
268.2026 +  if (!p->fastMode)
268.2027 +  {
268.2028 +    FillDistancesPrices(p);
268.2029 +    FillAlignPrices(p);
268.2030 +  }
268.2031 +
268.2032 +  p->lenEnc.tableSize =
268.2033 +  p->repLenEnc.tableSize =
268.2034 +      p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;
268.2035 +  LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices);
268.2036 +  LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);
268.2037 +}
268.2038 +
268.2039 +static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
268.2040 +{
268.2041 +  UInt32 i;
268.2042 +  for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++)
268.2043 +    if (p->dictSize <= ((UInt32)1 << i))
268.2044 +      break;
268.2045 +  p->distTableSize = i * 2;
268.2046 +
268.2047 +  p->finished = False;
268.2048 +  p->result = SZ_OK;
268.2049 +  RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig));
268.2050 +  LzmaEnc_Init(p);
268.2051 +  LzmaEnc_InitPrices(p);
268.2052 +  p->nowPos64 = 0;
268.2053 +  return SZ_OK;
268.2054 +}
268.2055 +
268.2056 +static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqInStream *inStream, ISeqOutStream *outStream,
268.2057 +    ISzAlloc *alloc, ISzAlloc *allocBig)
268.2058 +{
268.2059 +  CLzmaEnc *p = (CLzmaEnc *)pp;
268.2060 +  p->inStream = inStream;
268.2061 +  p->rc.outStream = outStream;
268.2062 +  return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
268.2063 +}
268.2064 +
268.2065 +SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
268.2066 +    ISeqInStream *inStream, UInt32 keepWindowSize,
268.2067 +    ISzAlloc *alloc, ISzAlloc *allocBig)
268.2068 +{
268.2069 +  CLzmaEnc *p = (CLzmaEnc *)pp;
268.2070 +  p->inStream = inStream;
268.2071 +  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
268.2072 +}
268.2073 +
268.2074 +static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
268.2075 +{
268.2076 +  p->seqBufInStream.funcTable.Read = MyRead;
268.2077 +  p->seqBufInStream.data = src;
268.2078 +  p->seqBufInStream.rem = srcLen;
268.2079 +}
268.2080 +
268.2081 +SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
268.2082 +    UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
268.2083 +{
268.2084 +  CLzmaEnc *p = (CLzmaEnc *)pp;
268.2085 +  LzmaEnc_SetInputBuf(p, src, srcLen);
268.2086 +  p->inStream = &p->seqBufInStream.funcTable;
268.2087 +  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
268.2088 +}
268.2089 +
268.2090 +void LzmaEnc_Finish(CLzmaEncHandle pp)
268.2091 +{
268.2092 +  #ifdef COMPRESS_MF_MT
268.2093 +  CLzmaEnc *p = (CLzmaEnc *)pp;
268.2094 +  if (p->mtMode)
268.2095 +    MatchFinderMt_ReleaseStream(&p->matchFinderMt);
268.2096 +  #else
268.2097 +  pp = pp;
268.2098 +  #endif
268.2099 +}
268.2100 +
268.2101 +typedef struct _CSeqOutStreamBuf
268.2102 +{
268.2103 +  ISeqOutStream funcTable;
268.2104 +  Byte *data;
268.2105 +  SizeT rem;
268.2106 +  Bool overflow;
268.2107 +} CSeqOutStreamBuf;
268.2108 +
268.2109 +static size_t MyWrite(void *pp, const void *data, size_t size)
268.2110 +{
268.2111 +  CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp;
268.2112 +  if (p->rem < size)
268.2113 +  {
268.2114 +    size = p->rem;
268.2115 +    p->overflow = True;
268.2116 +  }
268.2117 +  memcpy(p->data, data, size);
268.2118 +  p->rem -= size;
268.2119 +  p->data += size;
268.2120 +  return size;
268.2121 +}
268.2122 +
268.2123 +
268.2124 +UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
268.2125 +{
268.2126 +  const CLzmaEnc *p = (CLzmaEnc *)pp;
268.2127 +  return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
268.2128 +}
268.2129 +
268.2130 +const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
268.2131 +{
268.2132 +  const CLzmaEnc *p = (CLzmaEnc *)pp;
268.2133 +  return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
268.2134 +}
268.2135 +
268.2136 +SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
268.2137 +    Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
268.2138 +{
268.2139 +  CLzmaEnc *p = (CLzmaEnc *)pp;
268.2140 +  UInt64 nowPos64;
268.2141 +  SRes res;
268.2142 +  CSeqOutStreamBuf outStream;
268.2143 +
268.2144 +  outStream.funcTable.Write = MyWrite;
268.2145 +  outStream.data = dest;
268.2146 +  outStream.rem = *destLen;
268.2147 +  outStream.overflow = False;
268.2148 +
268.2149 +  p->writeEndMark = False;
268.2150 +  p->finished = False;
268.2151 +  p->result = SZ_OK;
268.2152 +
268.2153 +  if (reInit)
268.2154 +    LzmaEnc_Init(p);
268.2155 +  LzmaEnc_InitPrices(p);
268.2156 +  nowPos64 = p->nowPos64;
268.2157 +  RangeEnc_Init(&p->rc);
268.2158 +  p->rc.outStream = &outStream.funcTable;
268.2159 +
268.2160 +  res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);
268.2161 +  
268.2162 +  *unpackSize = (UInt32)(p->nowPos64 - nowPos64);
268.2163 +  *destLen -= outStream.rem;
268.2164 +  if (outStream.overflow)
268.2165 +    return SZ_ERROR_OUTPUT_EOF;
268.2166 +
268.2167 +  return res;
268.2168 +}
268.2169 +
268.2170 +SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
268.2171 +    ISzAlloc *alloc, ISzAlloc *allocBig)
268.2172 +{
268.2173 +  CLzmaEnc *p = (CLzmaEnc *)pp;
268.2174 +  SRes res = SZ_OK;
268.2175 +
268.2176 +  #ifdef COMPRESS_MF_MT
268.2177 +  Byte allocaDummy[0x300];
268.2178 +  int i = 0;
268.2179 +  for (i = 0; i < 16; i++)
268.2180 +    allocaDummy[i] = (Byte)i;
268.2181 +  #endif
268.2182 +
268.2183 +  RINOK(LzmaEnc_Prepare(pp, inStream, outStream, alloc, allocBig));
268.2184 +
268.2185 +  for (;;)
268.2186 +  {
268.2187 +    res = LzmaEnc_CodeOneBlock(p, False, 0, 0);
268.2188 +    if (res != SZ_OK || p->finished != 0)
268.2189 +      break;
268.2190 +    if (progress != 0)
268.2191 +    {
268.2192 +      res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));
268.2193 +      if (res != SZ_OK)
268.2194 +      {
268.2195 +        res = SZ_ERROR_PROGRESS;
268.2196 +        break;
268.2197 +      }
268.2198 +    }
268.2199 +  }
268.2200 +  LzmaEnc_Finish(pp);
268.2201 +  return res;
268.2202 +}
268.2203 +
268.2204 +SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
268.2205 +{
268.2206 +  CLzmaEnc *p = (CLzmaEnc *)pp;
268.2207 +  int i;
268.2208 +  UInt32 dictSize = p->dictSize;
268.2209 +  if (*size < LZMA_PROPS_SIZE)
268.2210 +    return SZ_ERROR_PARAM;
268.2211 +  *size = LZMA_PROPS_SIZE;
268.2212 +  props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);
268.2213 +
268.2214 +  for (i = 11; i <= 30; i++)
268.2215 +  {
268.2216 +    if (dictSize <= ((UInt32)2 << i))
268.2217 +    {
268.2218 +      dictSize = (2 << i);
268.2219 +      break;
268.2220 +    }
268.2221 +    if (dictSize <= ((UInt32)3 << i))
268.2222 +    {
268.2223 +      dictSize = (3 << i);
268.2224 +      break;
268.2225 +    }
268.2226 +  }
268.2227 +
268.2228 +  for (i = 0; i < 4; i++)
268.2229 +    props[1 + i] = (Byte)(dictSize >> (8 * i));
268.2230 +  return SZ_OK;
268.2231 +}
268.2232 +
268.2233 +SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
268.2234 +    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
268.2235 +{
268.2236 +  SRes res;
268.2237 +  CLzmaEnc *p = (CLzmaEnc *)pp;
268.2238 +
268.2239 +  CSeqOutStreamBuf outStream;
268.2240 +
268.2241 +  LzmaEnc_SetInputBuf(p, src, srcLen);
268.2242 +
268.2243 +  outStream.funcTable.Write = MyWrite;
268.2244 +  outStream.data = dest;
268.2245 +  outStream.rem = *destLen;
268.2246 +  outStream.overflow = False;
268.2247 +
268.2248 +  p->writeEndMark = writeEndMark;
268.2249 +  res = LzmaEnc_Encode(pp, &outStream.funcTable, &p->seqBufInStream.funcTable,
268.2250 +      progress, alloc, allocBig);
268.2251 +
268.2252 +  *destLen -= outStream.rem;
268.2253 +  if (outStream.overflow)
268.2254 +    return SZ_ERROR_OUTPUT_EOF;
268.2255 +  return res;
268.2256 +}
268.2257 +
268.2258 +SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
268.2259 +    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
268.2260 +    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
268.2261 +{
268.2262 +  CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
268.2263 +  SRes res;
268.2264 +  if (p == 0)
268.2265 +    return SZ_ERROR_MEM;
268.2266 +
268.2267 +  res = LzmaEnc_SetProps(p, props);
268.2268 +  if (res == SZ_OK)
268.2269 +  {
268.2270 +    res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);
268.2271 +    if (res == SZ_OK)
268.2272 +      res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,
268.2273 +          writeEndMark, progress, alloc, allocBig);
268.2274 +  }
268.2275 +
268.2276 +  LzmaEnc_Destroy(p, alloc, allocBig);
268.2277 +  return res;
268.2278 +}
   269.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   269.2 +++ b/src/win32/7zip/7z/C/LzmaEnc.h	Sat Mar 03 10:31:27 2012 -0600
   269.3 @@ -0,0 +1,72 @@
   269.4 +/*  LzmaEnc.h -- LZMA Encoder
   269.5 +2008-10-04 : Igor Pavlov : Public domain */
   269.6 +
   269.7 +#ifndef __LZMAENC_H
   269.8 +#define __LZMAENC_H
   269.9 +
  269.10 +#include "Types.h"
  269.11 +
  269.12 +#define LZMA_PROPS_SIZE 5
  269.13 +
  269.14 +typedef struct _CLzmaEncProps
  269.15 +{
  269.16 +  int level;       /*  0 <= level <= 9 */
  269.17 +  UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
  269.18 +                      (1 << 12) <= dictSize <= (1 << 30) for 64-bit version
  269.19 +                       default = (1 << 24) */
  269.20 +  int lc;          /* 0 <= lc <= 8, default = 3 */
  269.21 +  int lp;          /* 0 <= lp <= 4, default = 0 */
  269.22 +  int pb;          /* 0 <= pb <= 4, default = 2 */
  269.23 +  int algo;        /* 0 - fast, 1 - normal, default = 1 */
  269.24 +  int fb;          /* 5 <= fb <= 273, default = 32 */
  269.25 +  int btMode;      /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */
  269.26 +  int numHashBytes; /* 2, 3 or 4, default = 4 */
  269.27 +  UInt32 mc;        /* 1 <= mc <= (1 << 30), default = 32 */
  269.28 +  unsigned writeEndMark;  /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */
  269.29 +  int numThreads;  /* 1 or 2, default = 2 */
  269.30 +} CLzmaEncProps;
  269.31 +
  269.32 +void LzmaEncProps_Init(CLzmaEncProps *p);
  269.33 +void LzmaEncProps_Normalize(CLzmaEncProps *p);
  269.34 +UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
  269.35 +
  269.36 +
  269.37 +/* ---------- CLzmaEncHandle Interface ---------- */
  269.38 +
  269.39 +/* LzmaEnc_* functions can return the following exit codes:
  269.40 +Returns:
  269.41 +  SZ_OK           - OK
  269.42 +  SZ_ERROR_MEM    - Memory allocation error
  269.43 +  SZ_ERROR_PARAM  - Incorrect paramater in props
  269.44 +  SZ_ERROR_WRITE  - Write callback error.
  269.45 +  SZ_ERROR_PROGRESS - some break from progress callback
  269.46 +  SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
  269.47 +*/
  269.48 +
  269.49 +typedef void * CLzmaEncHandle;
  269.50 +
  269.51 +CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);
  269.52 +void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);
  269.53 +SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
  269.54 +SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
  269.55 +SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
  269.56 +    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
  269.57 +SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
  269.58 +    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
  269.59 +
  269.60 +/* ---------- One Call Interface ---------- */
  269.61 +
  269.62 +/* LzmaEncode
  269.63 +Return code:
  269.64 +  SZ_OK               - OK
  269.65 +  SZ_ERROR_MEM        - Memory allocation error
  269.66 +  SZ_ERROR_PARAM      - Incorrect paramater
  269.67 +  SZ_ERROR_OUTPUT_EOF - output buffer overflow
  269.68 +  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)
  269.69 +*/
  269.70 +
  269.71 +SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
  269.72 +    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
  269.73 +    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
  269.74 +
  269.75 +#endif
   270.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   270.2 +++ b/src/win32/7zip/7z/C/RotateDefs.h	Sat Mar 03 10:31:27 2012 -0600
   270.3 @@ -0,0 +1,22 @@
   270.4 +/* RotateDefs.h -- Rotate functions
   270.5 +2008-08-05
   270.6 +Igor Pavlov
   270.7 +Public domain */
   270.8 +
   270.9 +#ifndef __ROTATEDEFS_H
  270.10 +#define __ROTATEDEFS_H
  270.11 +
  270.12 +#ifdef _MSC_VER
  270.13 +
  270.14 +#include <stdlib.h>
  270.15 +#define rotlFixed(x, n) _rotl((x), (n))
  270.16 +#define rotrFixed(x, n) _rotr((x), (n))
  270.17 +
  270.18 +#else
  270.19 +
  270.20 +#define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
  270.21 +#define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
  270.22 +
  270.23 +#endif
  270.24 +
  270.25 +#endif
   271.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   271.2 +++ b/src/win32/7zip/7z/C/Sha256.c	Sat Mar 03 10:31:27 2012 -0600
   271.3 @@ -0,0 +1,204 @@
   271.4 +/* Crypto/Sha256.c -- SHA-256 Hash function
   271.5 +2008-11-06 : Igor Pavlov : Public domain
   271.6 +This code is based on public domain code from Wei Dai's Crypto++ library. */
   271.7 +
   271.8 +#include "Sha256.h"
   271.9 +#include "RotateDefs.h"
  271.10 +
  271.11 +/* define it for speed optimization */
  271.12 +/* #define _SHA256_UNROLL */
  271.13 +/* #define _SHA256_UNROLL2 */
  271.14 +
  271.15 +void Sha256_Init(CSha256 *p)
  271.16 +{
  271.17 +  p->state[0] = 0x6a09e667;
  271.18 +  p->state[1] = 0xbb67ae85;
  271.19 +  p->state[2] = 0x3c6ef372;
  271.20 +  p->state[3] = 0xa54ff53a;
  271.21 +  p->state[4] = 0x510e527f;
  271.22 +  p->state[5] = 0x9b05688c;
  271.23 +  p->state[6] = 0x1f83d9ab;
  271.24 +  p->state[7] = 0x5be0cd19;
  271.25 +  p->count = 0;
  271.26 +}
  271.27 +
  271.28 +#define S0(x) (rotrFixed(x, 2) ^ rotrFixed(x,13) ^ rotrFixed(x, 22))
  271.29 +#define S1(x) (rotrFixed(x, 6) ^ rotrFixed(x,11) ^ rotrFixed(x, 25))
  271.30 +#define s0(x) (rotrFixed(x, 7) ^ rotrFixed(x,18) ^ (x >> 3))
  271.31 +#define s1(x) (rotrFixed(x,17) ^ rotrFixed(x,19) ^ (x >> 10))
  271.32 +
  271.33 +#define blk0(i) (W[i] = data[i])
  271.34 +#define blk2(i) (W[i&15] += s1(W[(i-2)&15]) + W[(i-7)&15] + s0(W[(i-15)&15]))
  271.35 +
  271.36 +#define Ch(x,y,z) (z^(x&(y^z)))
  271.37 +#define Maj(x,y,z) ((x&y)|(z&(x|y)))
  271.38 +
  271.39 +#define a(i) T[(0-(i))&7]
  271.40 +#define b(i) T[(1-(i))&7]
  271.41 +#define c(i) T[(2-(i))&7]
  271.42 +#define d(i) T[(3-(i))&7]
  271.43 +#define e(i) T[(4-(i))&7]
  271.44 +#define f(i) T[(5-(i))&7]
  271.45 +#define g(i) T[(6-(i))&7]
  271.46 +#define h(i) T[(7-(i))&7]
  271.47 +
  271.48 +
  271.49 +#ifdef _SHA256_UNROLL2
  271.50 +
  271.51 +#define R(a,b,c,d,e,f,g,h, i) h += S1(e) + Ch(e,f,g) + K[i+j] + (j?blk2(i):blk0(i));\
  271.52 +  d += h; h += S0(a) + Maj(a, b, c)
  271.53 +
  271.54 +#define RX_8(i) \
  271.55 +  R(a,b,c,d,e,f,g,h, i); \
  271.56 +  R(h,a,b,c,d,e,f,g, i+1); \
  271.57 +  R(g,h,a,b,c,d,e,f, i+2); \
  271.58 +  R(f,g,h,a,b,c,d,e, i+3); \
  271.59 +  R(e,f,g,h,a,b,c,d, i+4); \
  271.60 +  R(d,e,f,g,h,a,b,c, i+5); \
  271.61 +  R(c,d,e,f,g,h,a,b, i+6); \
  271.62 +  R(b,c,d,e,f,g,h,a, i+7)
  271.63 +
  271.64 +#else
  271.65 +
  271.66 +#define R(i) h(i) += S1(e(i)) + Ch(e(i),f(i),g(i)) + K[i+j] + (j?blk2(i):blk0(i));\
  271.67 +  d(i) += h(i); h(i) += S0(a(i)) + Maj(a(i), b(i), c(i))
  271.68 +
  271.69 +#ifdef _SHA256_UNROLL
  271.70 +
  271.71 +#define RX_8(i) R(i+0); R(i+1); R(i+2); R(i+3); R(i+4); R(i+5); R(i+6); R(i+7);
  271.72 +
  271.73 +#endif
  271.74 +
  271.75 +#endif
  271.76 +
  271.77 +const UInt32 K[64] = {
  271.78 +  0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  271.79 +  0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  271.80 +  0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  271.81 +  0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  271.82 +  0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  271.83 +  0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  271.84 +  0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  271.85 +  0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  271.86 +  0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  271.87 +  0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  271.88 +  0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  271.89 +  0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  271.90 +  0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  271.91 +  0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  271.92 +  0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  271.93 +  0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
  271.94 +};
  271.95 +
  271.96 +static void Sha256_Transform(UInt32 *state, const UInt32 *data)
  271.97 +{
  271.98 +  UInt32 W[16];
  271.99 +  unsigned j;
 271.100 +  #ifdef _SHA256_UNROLL2
 271.101 +  UInt32 a,b,c,d,e,f,g,h;
 271.102 +  a = state[0];
 271.103 +  b = state[1];
 271.104 +  c = state[2];
 271.105 +  d = state[3];
 271.106 +  e = state[4];
 271.107 +  f = state[5];
 271.108 +  g = state[6];
 271.109 +  h = state[7];
 271.110 +  #else
 271.111 +  UInt32 T[8];
 271.112 +  for (j = 0; j < 8; j++)
 271.113 +    T[j] = state[j];
 271.114 +  #endif
 271.115 +
 271.116 +  for (j = 0; j < 64; j += 16)
 271.117 +  {
 271.118 +    #if defined(_SHA256_UNROLL) || defined(_SHA256_UNROLL2)
 271.119 +    RX_8(0); RX_8(8);
 271.120 +    #else
 271.121 +    unsigned i;
 271.122 +    for (i = 0; i < 16; i++) { R(i); }
 271.123 +    #endif
 271.124 +  }
 271.125 +
 271.126 +  #ifdef _SHA256_UNROLL2
 271.127 +  state[0] += a;
 271.128 +  state[1] += b;
 271.129 +  state[2] += c;
 271.130 +  state[3] += d;
 271.131 +  state[4] += e;
 271.132 +  state[5] += f;
 271.133 +  state[6] += g;
 271.134 +  state[7] += h;
 271.135 +  #else
 271.136 +  for (j = 0; j < 8; j++)
 271.137 +    state[j] += T[j];
 271.138 +  #endif
 271.139 +  
 271.140 +  /* Wipe variables */
 271.141 +  /* memset(W, 0, sizeof(W)); */
 271.142 +  /* memset(T, 0, sizeof(T)); */
 271.143 +}
 271.144 +
 271.145 +#undef S0
 271.146 +#undef S1
 271.147 +#undef s0
 271.148 +#undef s1
 271.149 +
 271.150 +static void Sha256_WriteByteBlock(CSha256 *p)
 271.151 +{
 271.152 +  UInt32 data32[16];
 271.153 +  unsigned i;
 271.154 +  for (i = 0; i < 16; i++)
 271.155 +    data32[i] =
 271.156 +      ((UInt32)(p->buffer[i * 4    ]) << 24) +
 271.157 +      ((UInt32)(p->buffer[i * 4 + 1]) << 16) +
 271.158 +      ((UInt32)(p->buffer[i * 4 + 2]) <<  8) +
 271.159 +      ((UInt32)(p->buffer[i * 4 + 3]));
 271.160 +  Sha256_Transform(p->state, data32);
 271.161 +}
 271.162 +
 271.163 +void Sha256_Update(CSha256 *p, const Byte *data, size_t size)
 271.164 +{
 271.165 +  UInt32 curBufferPos = (UInt32)p->count & 0x3F;
 271.166 +  while (size > 0)
 271.167 +  {
 271.168 +    p->buffer[curBufferPos++] = *data++;
 271.169 +    p->count++;
 271.170 +    size--;
 271.171 +    if (curBufferPos == 64)
 271.172 +    {
 271.173 +      curBufferPos = 0;
 271.174 +      Sha256_WriteByteBlock(p);
 271.175 +    }
 271.176 +  }
 271.177 +}
 271.178 +
 271.179 +void Sha256_Final(CSha256 *p, Byte *digest)
 271.180 +{
 271.181 +  UInt64 lenInBits = (p->count << 3);
 271.182 +  UInt32 curBufferPos = (UInt32)p->count & 0x3F;
 271.183 +  unsigned i;
 271.184 +  p->buffer[curBufferPos++] = 0x80;
 271.185 +  while (curBufferPos != (64 - 8))
 271.186 +  {
 271.187 +    curBufferPos &= 0x3F;
 271.188 +    if (curBufferPos == 0)
 271.189 +      Sha256_WriteByteBlock(p);
 271.190 +    p->buffer[curBufferPos++] = 0;
 271.191 +  }
 271.192 +  for (i = 0; i < 8; i++)
 271.193 +  {
 271.194 +    p->buffer[curBufferPos++] = (Byte)(lenInBits >> 56);
 271.195 +    lenInBits <<= 8;
 271.196 +  }
 271.197 +  Sha256_WriteByteBlock(p);
 271.198 +
 271.199 +  for (i = 0; i < 8; i++)
 271.200 +  {
 271.201 +    *digest++ = (Byte)((p->state[i] >> 24) & 0xFF);
 271.202 +    *digest++ = (Byte)((p->state[i] >> 16) & 0xFF);
 271.203 +    *digest++ = (Byte)((p->state[i] >> 8) & 0xFF);
 271.204 +    *digest++ = (Byte)((p->state[i]) & 0xFF);
 271.205 +  }
 271.206 +  Sha256_Init(p);
 271.207 +}
   272.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   272.2 +++ b/src/win32/7zip/7z/C/Sha256.h	Sat Mar 03 10:31:27 2012 -0600
   272.3 @@ -0,0 +1,22 @@
   272.4 +/* Crypto/Sha256.h -- SHA-256 Hash function
   272.5 +2008-10-04 : Igor Pavlov : Public domain */
   272.6 +
   272.7 +#ifndef __CRYPTO_SHA256_H
   272.8 +#define __CRYPTO_SHA256_H
   272.9 +
  272.10 +#include "Types.h"
  272.11 +
  272.12 +#define SHA256_DIGEST_SIZE 32
  272.13 +
  272.14 +typedef struct
  272.15 +{
  272.16 +  UInt32 state[8];
  272.17 +  UInt64 count;
  272.18 +  Byte buffer[64];
  272.19 +} CSha256;
  272.20 +
  272.21 +void Sha256_Init(CSha256 *p);
  272.22 +void Sha256_Update(CSha256 *p, const Byte *data, size_t size);
  272.23 +void Sha256_Final(CSha256 *p, Byte *digest);
  272.24 +
  272.25 +#endif
   273.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   273.2 +++ b/src/win32/7zip/7z/C/Sort.c	Sat Mar 03 10:31:27 2012 -0600
   273.3 @@ -0,0 +1,95 @@
   273.4 +/* Sort.c -- Sort functions
   273.5 +2008-08-17
   273.6 +Igor Pavlov
   273.7 +Public domain */
   273.8 +
   273.9 +#include "Sort.h"
  273.10 +
  273.11 +#define HeapSortDown(p, k, size, temp) \
  273.12 +  { for (;;) { \
  273.13 +    UInt32 s = (k << 1); \
  273.14 +    if (s > size) break; \
  273.15 +    if (s < size && p[s + 1] > p[s]) s++; \
  273.16 +    if (temp >= p[s]) break; \
  273.17 +    p[k] = p[s]; k = s; \
  273.18 +  } p[k] = temp; }
  273.19 +
  273.20 +void HeapSort(UInt32 *p, UInt32 size)
  273.21 +{
  273.22 +  if (size <= 1)
  273.23 +    return;
  273.24 +  p--;
  273.25 +  {
  273.26 +    UInt32 i = size / 2;
  273.27 +    do
  273.28 +    {
  273.29 +      UInt32 temp = p[i];
  273.30 +      UInt32 k = i;
  273.31 +      HeapSortDown(p, k, size, temp)
  273.32 +    }
  273.33 +    while (--i != 0);
  273.34 +  }
  273.35 +  /*
  273.36 +  do
  273.37 +  {
  273.38 +    UInt32 k = 1;
  273.39 +    UInt32 temp = p[size];
  273.40 +    p[size--] = p[1];
  273.41 +    HeapSortDown(p, k, size, temp)
  273.42 +  }
  273.43 +  while (size > 1);
  273.44 +  */
  273.45 +  while (size > 3)
  273.46 +  {
  273.47 +    UInt32 temp = p[size];
  273.48 +    UInt32 k = (p[3] > p[2]) ? 3 : 2;
  273.49 +    p[size--] = p[1];
  273.50 +    p[1] = p[k];
  273.51 +    HeapSortDown(p, k, size, temp)
  273.52 +  }
  273.53 +  {
  273.54 +    UInt32 temp = p[size];
  273.55 +    p[size] = p[1];
  273.56 +    if (size > 2 && p[2] < temp)
  273.57 +    {
  273.58 +      p[1] = p[2];
  273.59 +      p[2] = temp;
  273.60 +    }
  273.61 +    else
  273.62 +      p[1] = temp;
  273.63 +  }
  273.64 +}
  273.65 +
  273.66 +/*
  273.67 +#define HeapSortRefDown(p, vals, n, size, temp) \
  273.68 +  { UInt32 k = n; UInt32 val = vals[temp]; for (;;) { \
  273.69 +    UInt32 s = (k << 1); \
  273.70 +    if (s > size) break; \
  273.71 +    if (s < size && vals[p[s + 1]] > vals[p[s]]) s++; \
  273.72 +    if (val >= vals[p[s]]) break; \
  273.73 +    p[k] = p[s]; k = s; \
  273.74 +  } p[k] = temp; }
  273.75 +
  273.76 +void HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size)
  273.77 +{
  273.78 +  if (size <= 1)
  273.79 +    return;
  273.80 +  p--;
  273.81 +  {
  273.82 +    UInt32 i = size / 2;
  273.83 +    do
  273.84 +    {
  273.85 +      UInt32 temp = p[i];
  273.86 +      HeapSortRefDown(p, vals, i, size, temp);
  273.87 +    }
  273.88 +    while (--i != 0);
  273.89 +  }
  273.90 +  do
  273.91 +  {
  273.92 +    UInt32 temp = p[size];
  273.93 +    p[size--] = p[1];
  273.94 +    HeapSortRefDown(p, vals, 1, size, temp);
  273.95 +  }
  273.96 +  while (size > 1);
  273.97 +}
  273.98 +*/
  273.99 \ No newline at end of file
   274.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   274.2 +++ b/src/win32/7zip/7z/C/Sort.h	Sat Mar 03 10:31:27 2012 -0600
   274.3 @@ -0,0 +1,14 @@
   274.4 +/* Sort.h -- Sort functions
   274.5 +2008-03-19
   274.6 +Igor Pavlov
   274.7 +Public domain */
   274.8 +
   274.9 +#ifndef __7Z_SORT_H
  274.10 +#define __7Z_SORT_H
  274.11 +
  274.12 +#include "Types.h"
  274.13 +
  274.14 +void HeapSort(UInt32 *p, UInt32 size);
  274.15 +/* void HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size); */
  274.16 +
  274.17 +#endif
   275.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   275.2 +++ b/src/win32/7zip/7z/C/Threads.c	Sat Mar 03 10:31:27 2012 -0600
   275.3 @@ -0,0 +1,109 @@
   275.4 +/* Threads.c -- multithreading library
   275.5 +2008-08-05
   275.6 +Igor Pavlov
   275.7 +Public domain */
   275.8 +
   275.9 +#include "Threads.h"
  275.10 +#include <process.h>
  275.11 +
  275.12 +static WRes GetError()
  275.13 +{
  275.14 +  DWORD res = GetLastError();
  275.15 +  return (res) ? (WRes)(res) : 1;
  275.16 +}
  275.17 +
  275.18 +WRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); }
  275.19 +WRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); }
  275.20 +
  275.21 +static WRes MyCloseHandle(HANDLE *h)
  275.22 +{
  275.23 +  if (*h != NULL)
  275.24 +    if (!CloseHandle(*h))
  275.25 +      return GetError();
  275.26 +  *h = NULL;
  275.27 +  return 0;
  275.28 +}
  275.29 +
  275.30 +WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
  275.31 +{
  275.32 +  unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */
  275.33 +  thread->handle =
  275.34 +    /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */
  275.35 +    (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId);
  275.36 +    /* maybe we must use errno here, but probably GetLastError() is also OK. */
  275.37 +  return HandleToWRes(thread->handle);
  275.38 +}
  275.39 +
  275.40 +WRes WaitObject(HANDLE h)
  275.41 +{
  275.42 +  return (WRes)WaitForSingleObject(h, INFINITE);
  275.43 +}
  275.44 +
  275.45 +WRes Thread_Wait(CThread *thread)
  275.46 +{
  275.47 +  if (thread->handle == NULL)
  275.48 +    return 1;
  275.49 +  return WaitObject(thread->handle);
  275.50 +}
  275.51 +
  275.52 +WRes Thread_Close(CThread *thread)
  275.53 +{
  275.54 +  return MyCloseHandle(&thread->handle);
  275.55 +}
  275.56 +
  275.57 +WRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)
  275.58 +{
  275.59 +  p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL);
  275.60 +  return HandleToWRes(p->handle);
  275.61 +}
  275.62 +
  275.63 +WRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)
  275.64 +  { return Event_Create(p, TRUE, initialSignaled); }
  275.65 +WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p)
  275.66 +  { return ManualResetEvent_Create(p, 0); }
  275.67 +
  275.68 +WRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)
  275.69 +  { return Event_Create(p, FALSE, initialSignaled); }
  275.70 +WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p)
  275.71 +  { return AutoResetEvent_Create(p, 0); }
  275.72 +
  275.73 +WRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(p->handle)); }
  275.74 +WRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(p->handle)); }
  275.75 +WRes Event_Wait(CEvent *p) { return WaitObject(p->handle); }
  275.76 +WRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); }
  275.77 +
  275.78 +
  275.79 +WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)
  275.80 +{
  275.81 +  p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL);
  275.82 +  return HandleToWRes(p->handle);
  275.83 +}
  275.84 +
  275.85 +WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)
  275.86 +{
  275.87 +  return BOOLToWRes(ReleaseSemaphore(p->handle, releaseCount, previousCount));
  275.88 +}
  275.89 +WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)
  275.90 +{
  275.91 +  return Semaphore_Release(p, (LONG)releaseCount, NULL);
  275.92 +}
  275.93 +WRes Semaphore_Release1(CSemaphore *p)
  275.94 +{
  275.95 +  return Semaphore_ReleaseN(p, 1);
  275.96 +}
  275.97 +
  275.98 +WRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); }
  275.99 +WRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); }
 275.100 +
 275.101 +WRes CriticalSection_Init(CCriticalSection *p)
 275.102 +{
 275.103 +  /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */
 275.104 +  __try
 275.105 +  {
 275.106 +    InitializeCriticalSection(p);
 275.107 +    /* InitializeCriticalSectionAndSpinCount(p, 0); */
 275.108 +  }
 275.109 +  __except (EXCEPTION_EXECUTE_HANDLER) { return 1; }
 275.110 +  return 0;
 275.111 +}
 275.112 +
   276.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   276.2 +++ b/src/win32/7zip/7z/C/Threads.h	Sat Mar 03 10:31:27 2012 -0600
   276.3 @@ -0,0 +1,68 @@
   276.4 +/* Threads.h -- multithreading library
   276.5 +2008-11-22 : Igor Pavlov : Public domain */
   276.6 +
   276.7 +#ifndef __7Z_THRESDS_H
   276.8 +#define __7Z_THRESDS_H
   276.9 +
  276.10 +#include "Types.h"
  276.11 +
  276.12 +typedef struct _CThread
  276.13 +{
  276.14 +  HANDLE handle;
  276.15 +} CThread;
  276.16 +
  276.17 +#define Thread_Construct(thread) (thread)->handle = NULL
  276.18 +#define Thread_WasCreated(thread) ((thread)->handle != NULL)
  276.19 + 
  276.20 +typedef unsigned THREAD_FUNC_RET_TYPE;
  276.21 +#define THREAD_FUNC_CALL_TYPE MY_STD_CALL
  276.22 +#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
  276.23 +
  276.24 +WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);
  276.25 +WRes Thread_Wait(CThread *thread);
  276.26 +WRes Thread_Close(CThread *thread);
  276.27 +
  276.28 +typedef struct _CEvent
  276.29 +{
  276.30 +  HANDLE handle;
  276.31 +} CEvent;
  276.32 +
  276.33 +typedef CEvent CAutoResetEvent;
  276.34 +typedef CEvent CManualResetEvent;
  276.35 +
  276.36 +#define Event_Construct(event) (event)->handle = NULL
  276.37 +#define Event_IsCreated(event) ((event)->handle != NULL)
  276.38 +
  276.39 +WRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);
  276.40 +WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);
  276.41 +WRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);
  276.42 +WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);
  276.43 +WRes Event_Set(CEvent *event);
  276.44 +WRes Event_Reset(CEvent *event);
  276.45 +WRes Event_Wait(CEvent *event);
  276.46 +WRes Event_Close(CEvent *event);
  276.47 +
  276.48 +
  276.49 +typedef struct _CSemaphore
  276.50 +{
  276.51 +  HANDLE handle;
  276.52 +} CSemaphore;
  276.53 +
  276.54 +#define Semaphore_Construct(p) (p)->handle = NULL
  276.55 +
  276.56 +WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);
  276.57 +WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
  276.58 +WRes Semaphore_Release1(CSemaphore *p);
  276.59 +WRes Semaphore_Wait(CSemaphore *p);
  276.60 +WRes Semaphore_Close(CSemaphore *p);
  276.61 +
  276.62 +
  276.63 +typedef CRITICAL_SECTION CCriticalSection;
  276.64 +
  276.65 +WRes CriticalSection_Init(CCriticalSection *p);
  276.66 +#define CriticalSection_Delete(p) DeleteCriticalSection(p)
  276.67 +#define CriticalSection_Enter(p) EnterCriticalSection(p)
  276.68 +#define CriticalSection_Leave(p) LeaveCriticalSection(p)
  276.69 +
  276.70 +#endif
  276.71 +
   277.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   277.2 +++ b/src/win32/7zip/7z/C/Types.h	Sat Mar 03 10:31:27 2012 -0600
   277.3 @@ -0,0 +1,208 @@
   277.4 +/* Types.h -- Basic types
   277.5 +2008-11-23 : Igor Pavlov : Public domain */
   277.6 +
   277.7 +#ifndef __7Z_TYPES_H
   277.8 +#define __7Z_TYPES_H
   277.9 +
  277.10 +#include <stddef.h>
  277.11 +
  277.12 +#ifdef _WIN32
  277.13 +#include <windows.h>
  277.14 +#endif
  277.15 +
  277.16 +#define SZ_OK 0
  277.17 +
  277.18 +#define SZ_ERROR_DATA 1
  277.19 +#define SZ_ERROR_MEM 2
  277.20 +#define SZ_ERROR_CRC 3
  277.21 +#define SZ_ERROR_UNSUPPORTED 4
  277.22 +#define SZ_ERROR_PARAM 5
  277.23 +#define SZ_ERROR_INPUT_EOF 6
  277.24 +#define SZ_ERROR_OUTPUT_EOF 7
  277.25 +#define SZ_ERROR_READ 8
  277.26 +#define SZ_ERROR_WRITE 9
  277.27 +#define SZ_ERROR_PROGRESS 10
  277.28 +#define SZ_ERROR_FAIL 11
  277.29 +#define SZ_ERROR_THREAD 12
  277.30 +
  277.31 +#define SZ_ERROR_ARCHIVE 16
  277.32 +#define SZ_ERROR_NO_ARCHIVE 17
  277.33 +
  277.34 +typedef int SRes;
  277.35 +
  277.36 +#ifdef _WIN32
  277.37 +typedef DWORD WRes;
  277.38 +#else
  277.39 +typedef int WRes;
  277.40 +#endif
  277.41 +
  277.42 +#ifndef RINOK
  277.43 +#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
  277.44 +#endif
  277.45 +
  277.46 +typedef unsigned char Byte;
  277.47 +typedef short Int16;
  277.48 +typedef unsigned short UInt16;
  277.49 +
  277.50 +#ifdef _LZMA_UINT32_IS_ULONG
  277.51 +typedef long Int32;
  277.52 +typedef unsigned long UInt32;
  277.53 +#else
  277.54 +typedef int Int32;
  277.55 +typedef unsigned int UInt32;
  277.56 +#endif
  277.57 +
  277.58 +#ifdef _SZ_NO_INT_64
  277.59 +
  277.60 +/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
  277.61 +   NOTES: Some code will work incorrectly in that case! */
  277.62 +
  277.63 +typedef long Int64;
  277.64 +typedef unsigned long UInt64;
  277.65 +
  277.66 +#else
  277.67 +
  277.68 +#if defined(_MSC_VER) || defined(__BORLANDC__)
  277.69 +typedef __int64 Int64;
  277.70 +typedef unsigned __int64 UInt64;
  277.71 +#else
  277.72 +typedef long long int Int64;
  277.73 +typedef unsigned long long int UInt64;
  277.74 +#endif
  277.75 +
  277.76 +#endif
  277.77 +
  277.78 +#ifdef _LZMA_NO_SYSTEM_SIZE_T
  277.79 +typedef UInt32 SizeT;
  277.80 +#else
  277.81 +typedef size_t SizeT;
  277.82 +#endif
  277.83 +
  277.84 +typedef int Bool;
  277.85 +#define True 1
  277.86 +#define False 0
  277.87 +
  277.88 +
  277.89 +#ifdef _MSC_VER
  277.90 +
  277.91 +#if _MSC_VER >= 1300
  277.92 +#define MY_NO_INLINE __declspec(noinline)
  277.93 +#else
  277.94 +#define MY_NO_INLINE
  277.95 +#endif
  277.96 +
  277.97 +#define MY_CDECL __cdecl
  277.98 +#define MY_STD_CALL __stdcall
  277.99 +#define MY_FAST_CALL MY_NO_INLINE __fastcall
 277.100 +
 277.101 +#else
 277.102 +
 277.103 +#define MY_CDECL
 277.104 +#define MY_STD_CALL
 277.105 +#define MY_FAST_CALL
 277.106 +
 277.107 +#endif
 277.108 +
 277.109 +
 277.110 +/* The following interfaces use first parameter as pointer to structure */
 277.111 +
 277.112 +typedef struct
 277.113 +{
 277.114 +  SRes (*Read)(void *p, void *buf, size_t *size);
 277.115 +    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
 277.116 +       (output(*size) < input(*size)) is allowed */
 277.117 +} ISeqInStream;
 277.118 +
 277.119 +/* it can return SZ_ERROR_INPUT_EOF */
 277.120 +SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
 277.121 +SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
 277.122 +SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
 277.123 +
 277.124 +typedef struct
 277.125 +{
 277.126 +  size_t (*Write)(void *p, const void *buf, size_t size);
 277.127 +    /* Returns: result - the number of actually written bytes.
 277.128 +       (result < size) means error */
 277.129 +} ISeqOutStream;
 277.130 +
 277.131 +typedef enum
 277.132 +{
 277.133 +  SZ_SEEK_SET = 0,
 277.134 +  SZ_SEEK_CUR = 1,
 277.135 +  SZ_SEEK_END = 2
 277.136 +} ESzSeek;
 277.137 +
 277.138 +typedef struct
 277.139 +{
 277.140 +  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */
 277.141 +  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
 277.142 +} ISeekInStream;
 277.143 +
 277.144 +typedef struct
 277.145 +{
 277.146 +  SRes (*Look)(void *p, void **buf, size_t *size);
 277.147 +    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
 277.148 +       (output(*size) > input(*size)) is not allowed
 277.149 +       (output(*size) < input(*size)) is allowed */
 277.150 +  SRes (*Skip)(void *p, size_t offset);
 277.151 +    /* offset must be <= output(*size) of Look */
 277.152 +
 277.153 +  SRes (*Read)(void *p, void *buf, size_t *size);
 277.154 +    /* reads directly (without buffer). It's same as ISeqInStream::Read */
 277.155 +  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
 277.156 +} ILookInStream;
 277.157 +
 277.158 +SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
 277.159 +SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
 277.160 +
 277.161 +/* reads via ILookInStream::Read */
 277.162 +SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
 277.163 +SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
 277.164 +
 277.165 +#define LookToRead_BUF_SIZE (1 << 14)
 277.166 +
 277.167 +typedef struct
 277.168 +{
 277.169 +  ILookInStream s;
 277.170 +  ISeekInStream *realStream;
 277.171 +  size_t pos;
 277.172 +  size_t size;
 277.173 +  Byte buf[LookToRead_BUF_SIZE];
 277.174 +} CLookToRead;
 277.175 +
 277.176 +void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
 277.177 +void LookToRead_Init(CLookToRead *p);
 277.178 +
 277.179 +typedef struct
 277.180 +{
 277.181 +  ISeqInStream s;
 277.182 +  ILookInStream *realStream;
 277.183 +} CSecToLook;
 277.184 +
 277.185 +void SecToLook_CreateVTable(CSecToLook *p);
 277.186 +
 277.187 +typedef struct
 277.188 +{
 277.189 +  ISeqInStream s;
 277.190 +  ILookInStream *realStream;
 277.191 +} CSecToRead;
 277.192 +
 277.193 +void SecToRead_CreateVTable(CSecToRead *p);
 277.194 +
 277.195 +typedef struct
 277.196 +{
 277.197 +  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
 277.198 +    /* Returns: result. (result != SZ_OK) means break.
 277.199 +       Value (UInt64)(Int64)-1 for size means unknown value. */
 277.200 +} ICompressProgress;
 277.201 +
 277.202 +typedef struct
 277.203 +{
 277.204 +  void *(*Alloc)(void *p, size_t size);
 277.205 +  void (*Free)(void *p, void *address); /* address can be 0 */
 277.206 +} ISzAlloc;
 277.207 +
 277.208 +#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
 277.209 +#define IAlloc_Free(p, a) (p)->Free((p), a)
 277.210 +
 277.211 +#endif
   278.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   278.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zCompressionMode.cpp	Sat Mar 03 10:31:27 2012 -0600
   278.3 @@ -0,0 +1,3 @@
   278.4 +// CompressionMethod.cpp
   278.5 +
   278.6 +#include "StdAfx.h"
   279.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   279.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zCompressionMode.h	Sat Mar 03 10:31:27 2012 -0600
   279.3 @@ -0,0 +1,50 @@
   279.4 +// 7zCompressionMode.h
   279.5 +
   279.6 +#ifndef __7Z_COMPRESSION_MODE_H
   279.7 +#define __7Z_COMPRESSION_MODE_H
   279.8 +
   279.9 +#include "../../../Common/MyString.h"
  279.10 +
  279.11 +#include "../../../Windows/PropVariant.h"
  279.12 +
  279.13 +#include "../../Common/MethodProps.h"
  279.14 +
  279.15 +namespace NArchive {
  279.16 +namespace N7z {
  279.17 +
  279.18 +struct CMethodFull: public CMethod
  279.19 +{
  279.20 +  UInt32 NumInStreams;
  279.21 +  UInt32 NumOutStreams;
  279.22 +  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }
  279.23 +};
  279.24 +
  279.25 +struct CBind
  279.26 +{
  279.27 +  UInt32 InCoder;
  279.28 +  UInt32 InStream;
  279.29 +  UInt32 OutCoder;
  279.30 +  UInt32 OutStream;
  279.31 +};
  279.32 +
  279.33 +struct CCompressionMethodMode
  279.34 +{
  279.35 +  CObjectVector<CMethodFull> Methods;
  279.36 +  CRecordVector<CBind> Binds;
  279.37 +  #ifdef COMPRESS_MT
  279.38 +  UInt32 NumThreads;
  279.39 +  #endif
  279.40 +  bool PasswordIsDefined;
  279.41 +  UString Password;
  279.42 +
  279.43 +  bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); }
  279.44 +  CCompressionMethodMode(): PasswordIsDefined(false)
  279.45 +      #ifdef COMPRESS_MT
  279.46 +      , NumThreads(1)
  279.47 +      #endif
  279.48 +  {}
  279.49 +};
  279.50 +
  279.51 +}}
  279.52 +
  279.53 +#endif
   280.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   280.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zDecode.cpp	Sat Mar 03 10:31:27 2012 -0600
   280.3 @@ -0,0 +1,332 @@
   280.4 +// 7zDecode.cpp
   280.5 +
   280.6 +#include "StdAfx.h"
   280.7 +
   280.8 +#include "../../Common/LimitedStreams.h"
   280.9 +#include "../../Common/LockedStream.h"
  280.10 +#include "../../Common/ProgressUtils.h"
  280.11 +#include "../../Common/StreamObjects.h"
  280.12 +
  280.13 +#include "7zDecode.h"
  280.14 +
  280.15 +namespace NArchive {
  280.16 +namespace N7z {
  280.17 +
  280.18 +static void ConvertFolderItemInfoToBindInfo(const CFolder &folder,
  280.19 +    CBindInfoEx &bindInfo)
  280.20 +{
  280.21 +  bindInfo.Clear();
  280.22 +  int i;
  280.23 +  for (i = 0; i < folder.BindPairs.Size(); i++)
  280.24 +  {
  280.25 +    NCoderMixer::CBindPair bindPair;
  280.26 +    bindPair.InIndex = (UInt32)folder.BindPairs[i].InIndex;
  280.27 +    bindPair.OutIndex = (UInt32)folder.BindPairs[i].OutIndex;
  280.28 +    bindInfo.BindPairs.Add(bindPair);
  280.29 +  }
  280.30 +  UInt32 outStreamIndex = 0;
  280.31 +  for (i = 0; i < folder.Coders.Size(); i++)
  280.32 +  {
  280.33 +    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;
  280.34 +    const CCoderInfo &coderInfo = folder.Coders[i];
  280.35 +    coderStreamsInfo.NumInStreams = (UInt32)coderInfo.NumInStreams;
  280.36 +    coderStreamsInfo.NumOutStreams = (UInt32)coderInfo.NumOutStreams;
  280.37 +    bindInfo.Coders.Add(coderStreamsInfo);
  280.38 +    bindInfo.CoderMethodIDs.Add(coderInfo.MethodID);
  280.39 +    for (UInt32 j = 0; j < coderStreamsInfo.NumOutStreams; j++, outStreamIndex++)
  280.40 +      if (folder.FindBindPairForOutStream(outStreamIndex) < 0)
  280.41 +        bindInfo.OutStreams.Add(outStreamIndex);
  280.42 +  }
  280.43 +  for (i = 0; i < folder.PackStreams.Size(); i++)
  280.44 +    bindInfo.InStreams.Add((UInt32)folder.PackStreams[i]);
  280.45 +}
  280.46 +
  280.47 +static bool AreCodersEqual(const NCoderMixer::CCoderStreamsInfo &a1,
  280.48 +    const NCoderMixer::CCoderStreamsInfo &a2)
  280.49 +{
  280.50 +  return (a1.NumInStreams == a2.NumInStreams) &&
  280.51 +    (a1.NumOutStreams == a2.NumOutStreams);
  280.52 +}
  280.53 +
  280.54 +static bool AreBindPairsEqual(const NCoderMixer::CBindPair &a1, const NCoderMixer::CBindPair &a2)
  280.55 +{
  280.56 +  return (a1.InIndex == a2.InIndex) &&
  280.57 +    (a1.OutIndex == a2.OutIndex);
  280.58 +}
  280.59 +
  280.60 +static bool AreBindInfoExEqual(const CBindInfoEx &a1, const CBindInfoEx &a2)
  280.61 +{
  280.62 +  if (a1.Coders.Size() != a2.Coders.Size())
  280.63 +    return false;
  280.64 +  int i;
  280.65 +  for (i = 0; i < a1.Coders.Size(); i++)
  280.66 +    if (!AreCodersEqual(a1.Coders[i], a2.Coders[i]))
  280.67 +      return false;
  280.68 +  if (a1.BindPairs.Size() != a2.BindPairs.Size())
  280.69 +    return false;
  280.70 +  for (i = 0; i < a1.BindPairs.Size(); i++)
  280.71 +    if (!AreBindPairsEqual(a1.BindPairs[i], a2.BindPairs[i]))
  280.72 +      return false;
  280.73 +  for (i = 0; i < a1.CoderMethodIDs.Size(); i++)
  280.74 +    if (a1.CoderMethodIDs[i] != a2.CoderMethodIDs[i])
  280.75 +      return false;
  280.76 +  if (a1.InStreams.Size() != a2.InStreams.Size())
  280.77 +    return false;
  280.78 +  if (a1.OutStreams.Size() != a2.OutStreams.Size())
  280.79 +    return false;
  280.80 +  return true;
  280.81 +}
  280.82 +
  280.83 +CDecoder::CDecoder(bool multiThread)
  280.84 +{
  280.85 +  #ifndef _ST_MODE
  280.86 +  multiThread = true;
  280.87 +  #endif
  280.88 +  _multiThread = multiThread;
  280.89 +  _bindInfoExPrevIsDefined = false;
  280.90 +}
  280.91 +
  280.92 +HRESULT CDecoder::Decode(
  280.93 +    DECL_EXTERNAL_CODECS_LOC_VARS
  280.94 +    IInStream *inStream,
  280.95 +    UInt64 startPos,
  280.96 +    const UInt64 *packSizes,
  280.97 +    const CFolder &folderInfo,
  280.98 +    ISequentialOutStream *outStream,
  280.99 +    ICompressProgressInfo *compressProgress
 280.100 +    #ifndef _NO_CRYPTO
 280.101 +    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
 280.102 +    #endif
 280.103 +    #ifdef COMPRESS_MT
 280.104 +    , bool mtMode, UInt32 numThreads
 280.105 +    #endif
 280.106 +    )
 280.107 +{
 280.108 +  if (!folderInfo.CheckStructure())
 280.109 +    return E_NOTIMPL;
 280.110 +  #ifndef _NO_CRYPTO
 280.111 +  passwordIsDefined = false;
 280.112 +  #endif
 280.113 +  CObjectVector< CMyComPtr<ISequentialInStream> > inStreams;
 280.114 +  
 280.115 +  CLockedInStream lockedInStream;
 280.116 +  lockedInStream.Init(inStream);
 280.117 +  
 280.118 +  for (int j = 0; j < folderInfo.PackStreams.Size(); j++)
 280.119 +  {
 280.120 +    CLockedSequentialInStreamImp *lockedStreamImpSpec = new
 280.121 +        CLockedSequentialInStreamImp;
 280.122 +    CMyComPtr<ISequentialInStream> lockedStreamImp = lockedStreamImpSpec;
 280.123 +    lockedStreamImpSpec->Init(&lockedInStream, startPos);
 280.124 +    startPos += packSizes[j];
 280.125 +    
 280.126 +    CLimitedSequentialInStream *streamSpec = new
 280.127 +        CLimitedSequentialInStream;
 280.128 +    CMyComPtr<ISequentialInStream> inStream = streamSpec;
 280.129 +    streamSpec->SetStream(lockedStreamImp);
 280.130 +    streamSpec->Init(packSizes[j]);
 280.131 +    inStreams.Add(inStream);
 280.132 +  }
 280.133 +  
 280.134 +  int numCoders = folderInfo.Coders.Size();
 280.135 +  
 280.136 +  CBindInfoEx bindInfo;
 280.137 +  ConvertFolderItemInfoToBindInfo(folderInfo, bindInfo);
 280.138 +  bool createNewCoders;
 280.139 +  if (!_bindInfoExPrevIsDefined)
 280.140 +    createNewCoders = true;
 280.141 +  else
 280.142 +    createNewCoders = !AreBindInfoExEqual(bindInfo, _bindInfoExPrev);
 280.143 +  if (createNewCoders)
 280.144 +  {
 280.145 +    int i;
 280.146 +    _decoders.Clear();
 280.147 +    // _decoders2.Clear();
 280.148 +    
 280.149 +    _mixerCoder.Release();
 280.150 +
 280.151 +    if (_multiThread)
 280.152 +    {
 280.153 +      _mixerCoderMTSpec = new NCoderMixer::CCoderMixer2MT;
 280.154 +      _mixerCoder = _mixerCoderMTSpec;
 280.155 +      _mixerCoderCommon = _mixerCoderMTSpec;
 280.156 +    }
 280.157 +    else
 280.158 +    {
 280.159 +      #ifdef _ST_MODE
 280.160 +      _mixerCoderSTSpec = new NCoderMixer::CCoderMixer2ST;
 280.161 +      _mixerCoder = _mixerCoderSTSpec;
 280.162 +      _mixerCoderCommon = _mixerCoderSTSpec;
 280.163 +      #endif
 280.164 +    }
 280.165 +    RINOK(_mixerCoderCommon->SetBindInfo(bindInfo));
 280.166 +    
 280.167 +    for (i = 0; i < numCoders; i++)
 280.168 +    {
 280.169 +      const CCoderInfo &coderInfo = folderInfo.Coders[i];
 280.170 +
 280.171 +  
 280.172 +      CMyComPtr<ICompressCoder> decoder;
 280.173 +      CMyComPtr<ICompressCoder2> decoder2;
 280.174 +      RINOK(CreateCoder(
 280.175 +          EXTERNAL_CODECS_LOC_VARS
 280.176 +          coderInfo.MethodID, decoder, decoder2, false));
 280.177 +      CMyComPtr<IUnknown> decoderUnknown;
 280.178 +      if (coderInfo.IsSimpleCoder())
 280.179 +      {
 280.180 +        if (decoder == 0)
 280.181 +          return E_NOTIMPL;
 280.182 +
 280.183 +        decoderUnknown = (IUnknown *)decoder;
 280.184 +        
 280.185 +        if (_multiThread)
 280.186 +          _mixerCoderMTSpec->AddCoder(decoder);
 280.187 +        #ifdef _ST_MODE
 280.188 +        else
 280.189 +          _mixerCoderSTSpec->AddCoder(decoder, false);
 280.190 +        #endif
 280.191 +      }
 280.192 +      else
 280.193 +      {
 280.194 +        if (decoder2 == 0)
 280.195 +          return E_NOTIMPL;
 280.196 +        decoderUnknown = (IUnknown *)decoder2;
 280.197 +        if (_multiThread)
 280.198 +          _mixerCoderMTSpec->AddCoder2(decoder2);
 280.199 +        #ifdef _ST_MODE
 280.200 +        else
 280.201 +          _mixerCoderSTSpec->AddCoder2(decoder2, false);
 280.202 +        #endif
 280.203 +      }
 280.204 +      _decoders.Add(decoderUnknown);
 280.205 +      #ifdef EXTERNAL_CODECS
 280.206 +      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;
 280.207 +      decoderUnknown.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);
 280.208 +      if (setCompressCodecsInfo)
 280.209 +      {
 280.210 +        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));
 280.211 +      }
 280.212 +      #endif
 280.213 +    }
 280.214 +    _bindInfoExPrev = bindInfo;
 280.215 +    _bindInfoExPrevIsDefined = true;
 280.216 +  }
 280.217 +  int i;
 280.218 +  _mixerCoderCommon->ReInit();
 280.219 +  
 280.220 +  UInt32 packStreamIndex = 0, unpackStreamIndex = 0;
 280.221 +  UInt32 coderIndex = 0;
 280.222 +  // UInt32 coder2Index = 0;
 280.223 +  
 280.224 +  for (i = 0; i < numCoders; i++)
 280.225 +  {
 280.226 +    const CCoderInfo &coderInfo = folderInfo.Coders[i];
 280.227 +    CMyComPtr<IUnknown> &decoder = _decoders[coderIndex];
 280.228 +    
 280.229 +    {
 280.230 +      CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;
 280.231 +      decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);
 280.232 +      if (setDecoderProperties)
 280.233 +      {
 280.234 +        const CByteBuffer &props = coderInfo.Props;
 280.235 +        size_t size = props.GetCapacity();
 280.236 +        if (size > 0xFFFFFFFF)
 280.237 +          return E_NOTIMPL;
 280.238 +        if (size > 0)
 280.239 +        {
 280.240 +          RINOK(setDecoderProperties->SetDecoderProperties2((const Byte *)props, (UInt32)size));
 280.241 +        }
 280.242 +      }
 280.243 +    }
 280.244 +
 280.245 +    #ifdef COMPRESS_MT
 280.246 +    if (mtMode)
 280.247 +    {
 280.248 +      CMyComPtr<ICompressSetCoderMt> setCoderMt;
 280.249 +      decoder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);
 280.250 +      if (setCoderMt)
 280.251 +      {
 280.252 +        RINOK(setCoderMt->SetNumberOfThreads(numThreads));
 280.253 +      }
 280.254 +    }
 280.255 +    #endif
 280.256 +
 280.257 +    #ifndef _NO_CRYPTO
 280.258 +    {
 280.259 +      CMyComPtr<ICryptoSetPassword> cryptoSetPassword;
 280.260 +      decoder.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);
 280.261 +      if (cryptoSetPassword)
 280.262 +      {
 280.263 +        if (getTextPassword == 0)
 280.264 +          return E_FAIL;
 280.265 +        CMyComBSTR passwordBSTR;
 280.266 +        RINOK(getTextPassword->CryptoGetTextPassword(&passwordBSTR));
 280.267 +        CByteBuffer buffer;
 280.268 +        passwordIsDefined = true;
 280.269 +        const UString password(passwordBSTR);
 280.270 +        const UInt32 sizeInBytes = password.Length() * 2;
 280.271 +        buffer.SetCapacity(sizeInBytes);
 280.272 +        for (int i = 0; i < password.Length(); i++)
 280.273 +        {
 280.274 +          wchar_t c = password[i];
 280.275 +          ((Byte *)buffer)[i * 2] = (Byte)c;
 280.276 +          ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
 280.277 +        }
 280.278 +        RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));
 280.279 +      }
 280.280 +    }
 280.281 +    #endif
 280.282 +
 280.283 +    coderIndex++;
 280.284 +    
 280.285 +    UInt32 numInStreams = (UInt32)coderInfo.NumInStreams;
 280.286 +    UInt32 numOutStreams = (UInt32)coderInfo.NumOutStreams;
 280.287 +    CRecordVector<const UInt64 *> packSizesPointers;
 280.288 +    CRecordVector<const UInt64 *> unpackSizesPointers;
 280.289 +    packSizesPointers.Reserve(numInStreams);
 280.290 +    unpackSizesPointers.Reserve(numOutStreams);
 280.291 +    UInt32 j;
 280.292 +    for (j = 0; j < numOutStreams; j++, unpackStreamIndex++)
 280.293 +      unpackSizesPointers.Add(&folderInfo.UnpackSizes[unpackStreamIndex]);
 280.294 +    
 280.295 +    for (j = 0; j < numInStreams; j++, packStreamIndex++)
 280.296 +    {
 280.297 +      int bindPairIndex = folderInfo.FindBindPairForInStream(packStreamIndex);
 280.298 +      if (bindPairIndex >= 0)
 280.299 +        packSizesPointers.Add(
 280.300 +        &folderInfo.UnpackSizes[(UInt32)folderInfo.BindPairs[bindPairIndex].OutIndex]);
 280.301 +      else
 280.302 +      {
 280.303 +        int index = folderInfo.FindPackStreamArrayIndex(packStreamIndex);
 280.304 +        if (index < 0)
 280.305 +          return E_FAIL;
 280.306 +        packSizesPointers.Add(&packSizes[index]);
 280.307 +      }
 280.308 +    }
 280.309 +    
 280.310 +    _mixerCoderCommon->SetCoderInfo(i,
 280.311 +        &packSizesPointers.Front(),
 280.312 +        &unpackSizesPointers.Front());
 280.313 +  }
 280.314 +  UInt32 mainCoder, temp;
 280.315 +  bindInfo.FindOutStream(bindInfo.OutStreams[0], mainCoder, temp);
 280.316 +
 280.317 +  if (_multiThread)
 280.318 +    _mixerCoderMTSpec->SetProgressCoderIndex(mainCoder);
 280.319 +  /*
 280.320 +  else
 280.321 +    _mixerCoderSTSpec->SetProgressCoderIndex(mainCoder);;
 280.322 +  */
 280.323 +  
 280.324 +  if (numCoders == 0)
 280.325 +    return 0;
 280.326 +  CRecordVector<ISequentialInStream *> inStreamPointers;
 280.327 +  inStreamPointers.Reserve(inStreams.Size());
 280.328 +  for (i = 0; i < inStreams.Size(); i++)
 280.329 +    inStreamPointers.Add(inStreams[i]);
 280.330 +  ISequentialOutStream *outStreamPointer = outStream;
 280.331 +  return _mixerCoder->Code(&inStreamPointers.Front(), NULL,
 280.332 +    inStreams.Size(), &outStreamPointer, NULL, 1, compressProgress);
 280.333 +}
 280.334 +
 280.335 +}}
   281.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   281.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zDecode.h	Sat Mar 03 10:31:27 2012 -0600
   281.3 @@ -0,0 +1,68 @@
   281.4 +// 7zDecode.h
   281.5 +
   281.6 +#ifndef __7Z_DECODE_H
   281.7 +#define __7Z_DECODE_H
   281.8 +
   281.9 +#include "../../IStream.h"
  281.10 +#include "../../IPassword.h"
  281.11 +
  281.12 +#include "../Common/CoderMixer2.h"
  281.13 +#include "../Common/CoderMixer2MT.h"
  281.14 +#ifdef _ST_MODE
  281.15 +#include "../Common/CoderMixer2ST.h"
  281.16 +#endif
  281.17 +
  281.18 +#include "../../Common/CreateCoder.h"
  281.19 +
  281.20 +#include "7zItem.h"
  281.21 +
  281.22 +namespace NArchive {
  281.23 +namespace N7z {
  281.24 +
  281.25 +struct CBindInfoEx: public NCoderMixer::CBindInfo
  281.26 +{
  281.27 +  CRecordVector<CMethodId> CoderMethodIDs;
  281.28 +  void Clear()
  281.29 +  {
  281.30 +    CBindInfo::Clear();
  281.31 +    CoderMethodIDs.Clear();
  281.32 +  }
  281.33 +};
  281.34 +
  281.35 +class CDecoder
  281.36 +{
  281.37 +  bool _bindInfoExPrevIsDefined;
  281.38 +  CBindInfoEx _bindInfoExPrev;
  281.39 +  
  281.40 +  bool _multiThread;
  281.41 +  #ifdef _ST_MODE
  281.42 +  NCoderMixer::CCoderMixer2ST *_mixerCoderSTSpec;
  281.43 +  #endif
  281.44 +  NCoderMixer::CCoderMixer2MT *_mixerCoderMTSpec;
  281.45 +  NCoderMixer::CCoderMixer2 *_mixerCoderCommon;
  281.46 +  
  281.47 +  CMyComPtr<ICompressCoder2> _mixerCoder;
  281.48 +  CObjectVector<CMyComPtr<IUnknown> > _decoders;
  281.49 +  // CObjectVector<CMyComPtr<ICompressCoder2> > _decoders2;
  281.50 +public:
  281.51 +  CDecoder(bool multiThread);
  281.52 +  HRESULT Decode(
  281.53 +      DECL_EXTERNAL_CODECS_LOC_VARS
  281.54 +      IInStream *inStream,
  281.55 +      UInt64 startPos,
  281.56 +      const UInt64 *packSizes,
  281.57 +      const CFolder &folder,
  281.58 +      ISequentialOutStream *outStream,
  281.59 +      ICompressProgressInfo *compressProgress
  281.60 +      #ifndef _NO_CRYPTO
  281.61 +      , ICryptoGetTextPassword *getTextPasswordSpec, bool &passwordIsDefined
  281.62 +      #endif
  281.63 +      #ifdef COMPRESS_MT
  281.64 +      , bool mtMode, UInt32 numThreads
  281.65 +      #endif
  281.66 +      );
  281.67 +};
  281.68 +
  281.69 +}}
  281.70 +
  281.71 +#endif
   282.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   282.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zExtract.cpp	Sat Mar 03 10:31:27 2012 -0600
   282.3 @@ -0,0 +1,273 @@
   282.4 +// 7zExtract.cpp
   282.5 +
   282.6 +#include "StdAfx.h"
   282.7 +
   282.8 +#include "7zHandler.h"
   282.9 +#include "7zFolderOutStream.h"
  282.10 +#include "7zDecode.h"
  282.11 +// #include "7z1Decode.h"
  282.12 +
  282.13 +#include "../../../Common/ComTry.h"
  282.14 +#include "../../Common/StreamObjects.h"
  282.15 +#include "../../Common/ProgressUtils.h"
  282.16 +#include "../../Common/LimitedStreams.h"
  282.17 +
  282.18 +namespace NArchive {
  282.19 +namespace N7z {
  282.20 +
  282.21 +struct CExtractFolderInfo
  282.22 +{
  282.23 +  #ifdef _7Z_VOL
  282.24 +  int VolumeIndex;
  282.25 +  #endif
  282.26 +  CNum FileIndex;
  282.27 +  CNum FolderIndex;
  282.28 +  CBoolVector ExtractStatuses;
  282.29 +  UInt64 UnpackSize;
  282.30 +  CExtractFolderInfo(
  282.31 +    #ifdef _7Z_VOL
  282.32 +    int volumeIndex,
  282.33 +    #endif
  282.34 +    CNum fileIndex, CNum folderIndex):
  282.35 +    #ifdef _7Z_VOL
  282.36 +    VolumeIndex(volumeIndex),
  282.37 +    #endif
  282.38 +    FileIndex(fileIndex),
  282.39 +    FolderIndex(folderIndex),
  282.40 +    UnpackSize(0)
  282.41 +  {
  282.42 +    if (fileIndex != kNumNoIndex)
  282.43 +    {
  282.44 +      ExtractStatuses.Reserve(1);
  282.45 +      ExtractStatuses.Add(true);
  282.46 +    }
  282.47 +  };
  282.48 +};
  282.49 +
  282.50 +STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
  282.51 +    Int32 testModeSpec, IArchiveExtractCallback *extractCallbackSpec)
  282.52 +{
  282.53 +  COM_TRY_BEGIN
  282.54 +  bool testMode = (testModeSpec != 0);
  282.55 +  CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;
  282.56 +  UInt64 importantTotalUnpacked = 0;
  282.57 +
  282.58 +  bool allFilesMode = (numItems == UInt32(-1));
  282.59 +  if (allFilesMode)
  282.60 +    numItems =
  282.61 +    #ifdef _7Z_VOL
  282.62 +    _refs.Size();
  282.63 +    #else
  282.64 +    _db.Files.Size();
  282.65 +    #endif
  282.66 +
  282.67 +  if(numItems == 0)
  282.68 +    return S_OK;
  282.69 +
  282.70 +  /*
  282.71 +  if(_volumes.Size() != 1)
  282.72 +    return E_FAIL;
  282.73 +  const CVolume &volume = _volumes.Front();
  282.74 +  const CArchiveDatabaseEx &_db = volume.Database;
  282.75 +  IInStream *_inStream = volume.Stream;
  282.76 +  */
  282.77 +  
  282.78 +  CObjectVector<CExtractFolderInfo> extractFolderInfoVector;
  282.79 +  for(UInt32 ii = 0; ii < numItems; ii++)
  282.80 +  {
  282.81 +    // UInt32 fileIndex = allFilesMode ? indexIndex : indices[indexIndex];
  282.82 +    UInt32 ref2Index = allFilesMode ? ii : indices[ii];
  282.83 +    // const CRef2 &ref2 = _refs[ref2Index];
  282.84 +
  282.85 +    // for(UInt32 ri = 0; ri < ref2.Refs.Size(); ri++)
  282.86 +    {
  282.87 +      #ifdef _7Z_VOL
  282.88 +      // const CRef &ref = ref2.Refs[ri];
  282.89 +      const CRef &ref = _refs[ref2Index];
  282.90 +
  282.91 +      int volumeIndex = ref.VolumeIndex;
  282.92 +      const CVolume &volume = _volumes[volumeIndex];
  282.93 +      const CArchiveDatabaseEx &db = volume.Database;
  282.94 +      UInt32 fileIndex = ref.ItemIndex;
  282.95 +      #else
  282.96 +      const CArchiveDatabaseEx &db = _db;
  282.97 +      UInt32 fileIndex = ref2Index;
  282.98 +      #endif
  282.99 +
 282.100 +      CNum folderIndex = db.FileIndexToFolderIndexMap[fileIndex];
 282.101 +      if (folderIndex == kNumNoIndex)
 282.102 +      {
 282.103 +        extractFolderInfoVector.Add(CExtractFolderInfo(
 282.104 +            #ifdef _7Z_VOL
 282.105 +            volumeIndex,
 282.106 +            #endif
 282.107 +            fileIndex, kNumNoIndex));
 282.108 +        continue;
 282.109 +      }
 282.110 +      if (extractFolderInfoVector.IsEmpty() ||
 282.111 +        folderIndex != extractFolderInfoVector.Back().FolderIndex
 282.112 +        #ifdef _7Z_VOL
 282.113 +        || volumeIndex != extractFolderInfoVector.Back().VolumeIndex
 282.114 +        #endif
 282.115 +        )
 282.116 +      {
 282.117 +        extractFolderInfoVector.Add(CExtractFolderInfo(
 282.118 +            #ifdef _7Z_VOL
 282.119 +            volumeIndex,
 282.120 +            #endif
 282.121 +            kNumNoIndex, folderIndex));
 282.122 +        const CFolder &folderInfo = db.Folders[folderIndex];
 282.123 +        UInt64 unpackSize = folderInfo.GetUnpackSize();
 282.124 +        importantTotalUnpacked += unpackSize;
 282.125 +        extractFolderInfoVector.Back().UnpackSize = unpackSize;
 282.126 +      }
 282.127 +      
 282.128 +      CExtractFolderInfo &efi = extractFolderInfoVector.Back();
 282.129 +      
 282.130 +      // const CFolderInfo &folderInfo = m_dam_Folders[folderIndex];
 282.131 +      CNum startIndex = db.FolderStartFileIndex[folderIndex];
 282.132 +      for (CNum index = efi.ExtractStatuses.Size();
 282.133 +          index <= fileIndex - startIndex; index++)
 282.134 +      {
 282.135 +        // UInt64 unpackSize = _db.Files[startIndex + index].UnpackSize;
 282.136 +        // Count partial_folder_size
 282.137 +        // efi.UnpackSize += unpackSize;
 282.138 +        // importantTotalUnpacked += unpackSize;
 282.139 +        efi.ExtractStatuses.Add(index == fileIndex - startIndex);
 282.140 +      }
 282.141 +    }
 282.142 +  }
 282.143 +
 282.144 +  extractCallback->SetTotal(importantTotalUnpacked);
 282.145 +
 282.146 +  CDecoder decoder(
 282.147 +    #ifdef _ST_MODE
 282.148 +    false
 282.149 +    #else
 282.150 +    true
 282.151 +    #endif
 282.152 +    );
 282.153 +  // CDecoder1 decoder;
 282.154 +
 282.155 +  UInt64 currentTotalPacked = 0;
 282.156 +  UInt64 currentTotalUnpacked = 0;
 282.157 +  UInt64 totalFolderUnpacked;
 282.158 +  UInt64 totalFolderPacked;
 282.159 +
 282.160 +  CLocalProgress *lps = new CLocalProgress;
 282.161 +  CMyComPtr<ICompressProgressInfo> progress = lps;
 282.162 +  lps->Init(extractCallback, false);
 282.163 +
 282.164 +  for(int i = 0; i < extractFolderInfoVector.Size(); i++,
 282.165 +      currentTotalUnpacked += totalFolderUnpacked,
 282.166 +      currentTotalPacked += totalFolderPacked)
 282.167 +  {
 282.168 +    lps->OutSize = currentTotalUnpacked;
 282.169 +    lps->InSize = currentTotalPacked;
 282.170 +    RINOK(lps->SetCur());
 282.171 +    
 282.172 +    const CExtractFolderInfo &efi = extractFolderInfoVector[i];
 282.173 +    totalFolderUnpacked = efi.UnpackSize;
 282.174 +
 282.175 +    totalFolderPacked = 0;
 282.176 +
 282.177 +    CFolderOutStream *folderOutStream = new CFolderOutStream;
 282.178 +    CMyComPtr<ISequentialOutStream> outStream(folderOutStream);
 282.179 +
 282.180 +    #ifdef _7Z_VOL
 282.181 +    const CVolume &volume = _volumes[efi.VolumeIndex];
 282.182 +    const CArchiveDatabaseEx &db = volume.Database;
 282.183 +    #else
 282.184 +    const CArchiveDatabaseEx &db = _db;
 282.185 +    #endif
 282.186 +
 282.187 +    CNum startIndex;
 282.188 +    if (efi.FileIndex != kNumNoIndex)
 282.189 +      startIndex = efi.FileIndex;
 282.190 +    else
 282.191 +      startIndex = db.FolderStartFileIndex[efi.FolderIndex];
 282.192 +
 282.193 +
 282.194 +    HRESULT result = folderOutStream->Init(&db,
 282.195 +        #ifdef _7Z_VOL
 282.196 +        volume.StartRef2Index,
 282.197 +        #else
 282.198 +        0,
 282.199 +        #endif
 282.200 +        startIndex,
 282.201 +        &efi.ExtractStatuses, extractCallback, testMode, _crcSize != 0);
 282.202 +
 282.203 +    RINOK(result);
 282.204 +
 282.205 +    if (efi.FileIndex != kNumNoIndex)
 282.206 +      continue;
 282.207 +
 282.208 +    CNum folderIndex = efi.FolderIndex;
 282.209 +    const CFolder &folderInfo = db.Folders[folderIndex];
 282.210 +
 282.211 +    totalFolderPacked = _db.GetFolderFullPackSize(folderIndex);
 282.212 +
 282.213 +    CNum packStreamIndex = db.FolderStartPackStreamIndex[folderIndex];
 282.214 +    UInt64 folderStartPackPos = db.GetFolderStreamPos(folderIndex, 0);
 282.215 +
 282.216 +    #ifndef _NO_CRYPTO
 282.217 +    CMyComPtr<ICryptoGetTextPassword> getTextPassword;
 282.218 +    if (extractCallback)
 282.219 +      extractCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);
 282.220 +    #endif
 282.221 +
 282.222 +    try
 282.223 +    {
 282.224 +      #ifndef _NO_CRYPTO
 282.225 +      bool passwordIsDefined;
 282.226 +      #endif
 282.227 +
 282.228 +      HRESULT result = decoder.Decode(
 282.229 +          EXTERNAL_CODECS_VARS
 282.230 +          #ifdef _7Z_VOL
 282.231 +          volume.Stream,
 282.232 +          #else
 282.233 +          _inStream,
 282.234 +          #endif
 282.235 +          folderStartPackPos,
 282.236 +          &db.PackSizes[packStreamIndex],
 282.237 +          folderInfo,
 282.238 +          outStream,
 282.239 +          progress
 282.240 +          #ifndef _NO_CRYPTO
 282.241 +          , getTextPassword, passwordIsDefined
 282.242 +          #endif
 282.243 +          #ifdef COMPRESS_MT
 282.244 +          , true, _numThreads
 282.245 +          #endif
 282.246 +          );
 282.247 +
 282.248 +      if (result == S_FALSE)
 282.249 +      {
 282.250 +        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));
 282.251 +        continue;
 282.252 +      }
 282.253 +      if (result == E_NOTIMPL)
 282.254 +      {
 282.255 +        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kUnSupportedMethod));
 282.256 +        continue;
 282.257 +      }
 282.258 +      if (result != S_OK)
 282.259 +        return result;
 282.260 +      if (folderOutStream->WasWritingFinished() != S_OK)
 282.261 +      {
 282.262 +        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));
 282.263 +        continue;
 282.264 +      }
 282.265 +    }
 282.266 +    catch(...)
 282.267 +    {
 282.268 +      RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));
 282.269 +      continue;
 282.270 +    }
 282.271 +  }
 282.272 +  return S_OK;
 282.273 +  COM_TRY_END
 282.274 +}
 282.275 +
 282.276 +}}
   283.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   283.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zFolderInStream.cpp	Sat Mar 03 10:31:27 2012 -0600
   283.3 @@ -0,0 +1,130 @@
   283.4 +// 7zFolderInStream.cpp
   283.5 +
   283.6 +#include "StdAfx.h"
   283.7 +
   283.8 +#include "7zFolderInStream.h"
   283.9 +
  283.10 +namespace NArchive {
  283.11 +namespace N7z {
  283.12 +
  283.13 +CFolderInStream::CFolderInStream()
  283.14 +{
  283.15 +  _inStreamWithHashSpec = new CSequentialInStreamWithCRC;
  283.16 +  _inStreamWithHash = _inStreamWithHashSpec;
  283.17 +}
  283.18 +
  283.19 +void CFolderInStream::Init(IArchiveUpdateCallback *updateCallback,
  283.20 +    const UInt32 *fileIndices, UInt32 numFiles)
  283.21 +{
  283.22 +  _updateCallback = updateCallback;
  283.23 +  _numFiles = numFiles;
  283.24 +  _fileIndex = 0;
  283.25 +  _fileIndices = fileIndices;
  283.26 +  Processed.Clear();
  283.27 +  CRCs.Clear();
  283.28 +  Sizes.Clear();
  283.29 +  _fileIsOpen = false;
  283.30 +  _currentSizeIsDefined = false;
  283.31 +}
  283.32 +
  283.33 +HRESULT CFolderInStream::OpenStream()
  283.34 +{
  283.35 +  _filePos = 0;
  283.36 +  while (_fileIndex < _numFiles)
  283.37 +  {
  283.38 +    _currentSizeIsDefined = false;
  283.39 +    CMyComPtr<ISequentialInStream> stream;
  283.40 +    HRESULT result = _updateCallback->GetStream(_fileIndices[_fileIndex], &stream);
  283.41 +    if (result != S_OK && result != S_FALSE)
  283.42 +      return result;
  283.43 +    _fileIndex++;
  283.44 +    _inStreamWithHashSpec->SetStream(stream);
  283.45 +    _inStreamWithHashSpec->Init();
  283.46 +    if (!stream)
  283.47 +    {
  283.48 +      RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));
  283.49 +      Sizes.Add(0);
  283.50 +      Processed.Add(result == S_OK);
  283.51 +      AddDigest();
  283.52 +      continue;
  283.53 +    }
  283.54 +    CMyComPtr<IStreamGetSize> streamGetSize;
  283.55 +    if (stream.QueryInterface(IID_IStreamGetSize, &streamGetSize) == S_OK)
  283.56 +    {
  283.57 +      if(streamGetSize)
  283.58 +      {
  283.59 +        _currentSizeIsDefined = true;
  283.60 +        RINOK(streamGetSize->GetSize(&_currentSize));
  283.61 +      }
  283.62 +    }
  283.63 +
  283.64 +    _fileIsOpen = true;
  283.65 +    return S_OK;
  283.66 +  }
  283.67 +  return S_OK;
  283.68 +}
  283.69 +
  283.70 +void CFolderInStream::AddDigest()
  283.71 +{
  283.72 +  CRCs.Add(_inStreamWithHashSpec->GetCRC());
  283.73 +}
  283.74 +
  283.75 +HRESULT CFolderInStream::CloseStream()
  283.76 +{
  283.77 +  RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));
  283.78 +  _inStreamWithHashSpec->ReleaseStream();
  283.79 +  _fileIsOpen = false;
  283.80 +  Processed.Add(true);
  283.81 +  Sizes.Add(_filePos);
  283.82 +  AddDigest();
  283.83 +  return S_OK;
  283.84 +}
  283.85 +
  283.86 +STDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
  283.87 +{
  283.88 +  UInt32 realProcessedSize = 0;
  283.89 +  while ((_fileIndex < _numFiles || _fileIsOpen) && size > 0)
  283.90 +  {
  283.91 +    if (_fileIsOpen)
  283.92 +    {
  283.93 +      UInt32 localProcessedSize;
  283.94 +      RINOK(_inStreamWithHash->Read(
  283.95 +          ((Byte *)data) + realProcessedSize, size, &localProcessedSize));
  283.96 +      if (localProcessedSize == 0)
  283.97 +      {
  283.98 +        RINOK(CloseStream());
  283.99 +        continue;
 283.100 +      }
 283.101 +      realProcessedSize += localProcessedSize;
 283.102 +      _filePos += localProcessedSize;
 283.103 +      size -= localProcessedSize;
 283.104 +      break;
 283.105 +    }
 283.106 +    else
 283.107 +    {
 283.108 +      RINOK(OpenStream());
 283.109 +    }
 283.110 +  }
 283.111 +  if (processedSize != 0)
 283.112 +    *processedSize = realProcessedSize;
 283.113 +  return S_OK;
 283.114 +}
 283.115 +
 283.116 +STDMETHODIMP CFolderInStream::GetSubStreamSize(UInt64 subStream, UInt64 *value)
 283.117 +{
 283.118 +  *value = 0;
 283.119 +  int subStreamIndex = (int)subStream;
 283.120 +  if (subStreamIndex < 0 || subStream > Sizes.Size())
 283.121 +    return E_FAIL;
 283.122 +  if (subStreamIndex < Sizes.Size())
 283.123 +  {
 283.124 +    *value= Sizes[subStreamIndex];
 283.125 +    return S_OK;
 283.126 +  }
 283.127 +  if (!_currentSizeIsDefined)
 283.128 +    return S_FALSE;
 283.129 +  *value = _currentSize;
 283.130 +  return S_OK;
 283.131 +}
 283.132 +
 283.133 +}}
   284.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   284.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zFolderInStream.h	Sat Mar 03 10:31:27 2012 -0600
   284.3 @@ -0,0 +1,66 @@
   284.4 +// 7z/FolderInStream.h
   284.5 +
   284.6 +#ifndef __7Z_FOLDERINSTREAM_H
   284.7 +#define __7Z_FOLDERINSTREAM_H
   284.8 +
   284.9 +#include "7zItem.h"
  284.10 +#include "7zHeader.h"
  284.11 +
  284.12 +#include "../IArchive.h"
  284.13 +#include "../Common/InStreamWithCRC.h"
  284.14 +#include "../../IStream.h"
  284.15 +#include "../../ICoder.h"
  284.16 +
  284.17 +namespace NArchive {
  284.18 +namespace N7z {
  284.19 +
  284.20 +class CFolderInStream:
  284.21 +  public ISequentialInStream,
  284.22 +  public ICompressGetSubStreamSize,
  284.23 +  public CMyUnknownImp
  284.24 +{
  284.25 +public:
  284.26 +
  284.27 +  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)
  284.28 +
  284.29 +  CFolderInStream();
  284.30 +
  284.31 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
  284.32 +
  284.33 +  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);
  284.34 +private:
  284.35 +  CSequentialInStreamWithCRC *_inStreamWithHashSpec;
  284.36 +  CMyComPtr<ISequentialInStream> _inStreamWithHash;
  284.37 +  CMyComPtr<IArchiveUpdateCallback> _updateCallback;
  284.38 +
  284.39 +  bool _currentSizeIsDefined;
  284.40 +  UInt64 _currentSize;
  284.41 +
  284.42 +  bool _fileIsOpen;
  284.43 +  UInt64 _filePos;
  284.44 +
  284.45 +  const UInt32 *_fileIndices;
  284.46 +  UInt32 _numFiles;
  284.47 +  UInt32 _fileIndex;
  284.48 +
  284.49 +  HRESULT OpenStream();
  284.50 +  HRESULT CloseStream();
  284.51 +  void AddDigest();
  284.52 +public:
  284.53 +  void Init(IArchiveUpdateCallback *updateCallback,
  284.54 +      const UInt32 *fileIndices, UInt32 numFiles);
  284.55 +  CRecordVector<bool> Processed;
  284.56 +  CRecordVector<UInt32> CRCs;
  284.57 +  CRecordVector<UInt64> Sizes;
  284.58 +  UInt64 GetFullSize() const
  284.59 +  {
  284.60 +    UInt64 size = 0;
  284.61 +    for (int i = 0; i < Sizes.Size(); i++)
  284.62 +      size += Sizes[i];
  284.63 +    return size;
  284.64 +  }
  284.65 +};
  284.66 +
  284.67 +}}
  284.68 +
  284.69 +#endif
   285.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   285.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zFolderOutStream.cpp	Sat Mar 03 10:31:27 2012 -0600
   285.3 @@ -0,0 +1,164 @@
   285.4 +// 7zFolderOutStream.cpp
   285.5 +
   285.6 +#include "StdAfx.h"
   285.7 +
   285.8 +#include "7zFolderOutStream.h"
   285.9 +
  285.10 +namespace NArchive {
  285.11 +namespace N7z {
  285.12 +
  285.13 +CFolderOutStream::CFolderOutStream()
  285.14 +{
  285.15 +  _outStreamWithHashSpec = new COutStreamWithCRC;
  285.16 +  _outStreamWithHash = _outStreamWithHashSpec;
  285.17 +}
  285.18 +
  285.19 +HRESULT CFolderOutStream::Init(
  285.20 +    const CArchiveDatabaseEx *archiveDatabase,
  285.21 +    UInt32 ref2Offset,
  285.22 +    UInt32 startIndex,
  285.23 +    const CBoolVector *extractStatuses,
  285.24 +    IArchiveExtractCallback *extractCallback,
  285.25 +    bool testMode,
  285.26 +    bool checkCrc)
  285.27 +{
  285.28 +  _archiveDatabase = archiveDatabase;
  285.29 +  _ref2Offset = ref2Offset;
  285.30 +  _startIndex = startIndex;
  285.31 +
  285.32 +  _extractStatuses = extractStatuses;
  285.33 +  _extractCallback = extractCallback;
  285.34 +  _testMode = testMode;
  285.35 +
  285.36 +  _checkCrc = checkCrc;
  285.37 +
  285.38 +  _currentIndex = 0;
  285.39 +  _fileIsOpen = false;
  285.40 +  return WriteEmptyFiles();
  285.41 +}
  285.42 +
  285.43 +HRESULT CFolderOutStream::OpenFile()
  285.44 +{
  285.45 +  Int32 askMode;
  285.46 +  if((*_extractStatuses)[_currentIndex])
  285.47 +    askMode = _testMode ?
  285.48 +        NArchive::NExtract::NAskMode::kTest :
  285.49 +        NArchive::NExtract::NAskMode::kExtract;
  285.50 +  else
  285.51 +    askMode = NArchive::NExtract::NAskMode::kSkip;
  285.52 +  CMyComPtr<ISequentialOutStream> realOutStream;
  285.53 +
  285.54 +  UInt32 index = _startIndex + _currentIndex;
  285.55 +  RINOK(_extractCallback->GetStream(_ref2Offset + index, &realOutStream, askMode));
  285.56 +
  285.57 +  _outStreamWithHashSpec->SetStream(realOutStream);
  285.58 +  _outStreamWithHashSpec->Init(_checkCrc);
  285.59 +  if (askMode == NArchive::NExtract::NAskMode::kExtract &&
  285.60 +      (!realOutStream))
  285.61 +  {
  285.62 +    const CFileItem &fi = _archiveDatabase->Files[index];
  285.63 +    if (!_archiveDatabase->IsItemAnti(index) && !fi.IsDir)
  285.64 +      askMode = NArchive::NExtract::NAskMode::kSkip;
  285.65 +  }
  285.66 +  return _extractCallback->PrepareOperation(askMode);
  285.67 +}
  285.68 +
  285.69 +HRESULT CFolderOutStream::WriteEmptyFiles()
  285.70 +{
  285.71 +  for(;_currentIndex < _extractStatuses->Size(); _currentIndex++)
  285.72 +  {
  285.73 +    UInt32 index = _startIndex + _currentIndex;
  285.74 +    const CFileItem &fi = _archiveDatabase->Files[index];
  285.75 +    if (!_archiveDatabase->IsItemAnti(index) && !fi.IsDir && fi.Size != 0)
  285.76 +      return S_OK;
  285.77 +    RINOK(OpenFile());
  285.78 +    RINOK(_extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));
  285.79 +    _outStreamWithHashSpec->ReleaseStream();
  285.80 +  }
  285.81 +  return S_OK;
  285.82 +}
  285.83 +
  285.84 +STDMETHODIMP CFolderOutStream::Write(const void *data,
  285.85 +    UInt32 size, UInt32 *processedSize)
  285.86 +{
  285.87 +  UInt32 realProcessedSize = 0;
  285.88 +  while(_currentIndex < _extractStatuses->Size())
  285.89 +  {
  285.90 +    if (_fileIsOpen)
  285.91 +    {
  285.92 +      UInt32 index = _startIndex + _currentIndex;
  285.93 +      const CFileItem &fi = _archiveDatabase->Files[index];
  285.94 +      UInt64 fileSize = fi.Size;
  285.95 +      
  285.96 +      UInt32 numBytesToWrite = (UInt32)MyMin(fileSize - _filePos,
  285.97 +          UInt64(size - realProcessedSize));
  285.98 +      
  285.99 +      UInt32 processedSizeLocal;
 285.100 +      RINOK(_outStreamWithHash->Write((const Byte *)data + realProcessedSize,
 285.101 +            numBytesToWrite, &processedSizeLocal));
 285.102 +
 285.103 +      _filePos += processedSizeLocal;
 285.104 +      realProcessedSize += processedSizeLocal;
 285.105 +      if (_filePos == fileSize)
 285.106 +      {
 285.107 +        bool digestsAreEqual;
 285.108 +        if (fi.CrcDefined && _checkCrc)
 285.109 +          digestsAreEqual = fi.Crc == _outStreamWithHashSpec->GetCRC();
 285.110 +        else
 285.111 +          digestsAreEqual = true;
 285.112 +
 285.113 +        RINOK(_extractCallback->SetOperationResult(
 285.114 +            digestsAreEqual ?
 285.115 +            NArchive::NExtract::NOperationResult::kOK :
 285.116 +            NArchive::NExtract::NOperationResult::kCRCError));
 285.117 +        _outStreamWithHashSpec->ReleaseStream();
 285.118 +        _fileIsOpen = false;
 285.119 +        _currentIndex++;
 285.120 +      }
 285.121 +      if (realProcessedSize == size)
 285.122 +      {
 285.123 +        if (processedSize != NULL)
 285.124 +          *processedSize = realProcessedSize;
 285.125 +        return WriteEmptyFiles();
 285.126 +      }
 285.127 +    }
 285.128 +    else
 285.129 +    {
 285.130 +      RINOK(OpenFile());
 285.131 +      _fileIsOpen = true;
 285.132 +      _filePos = 0;
 285.133 +    }
 285.134 +  }
 285.135 +  if (processedSize != NULL)
 285.136 +    *processedSize = size;
 285.137 +  return S_OK;
 285.138 +}
 285.139 +
 285.140 +HRESULT CFolderOutStream::FlushCorrupted(Int32 resultEOperationResult)
 285.141 +{
 285.142 +  while(_currentIndex < _extractStatuses->Size())
 285.143 +  {
 285.144 +    if (_fileIsOpen)
 285.145 +    {
 285.146 +      RINOK(_extractCallback->SetOperationResult(resultEOperationResult));
 285.147 +      _outStreamWithHashSpec->ReleaseStream();
 285.148 +      _fileIsOpen = false;
 285.149 +      _currentIndex++;
 285.150 +    }
 285.151 +    else
 285.152 +    {
 285.153 +      RINOK(OpenFile());
 285.154 +      _fileIsOpen = true;
 285.155 +    }
 285.156 +  }
 285.157 +  return S_OK;
 285.158 +}
 285.159 +
 285.160 +HRESULT CFolderOutStream::WasWritingFinished()
 285.161 +{
 285.162 +  if (_currentIndex == _extractStatuses->Size())
 285.163 +    return S_OK;
 285.164 +  return E_FAIL;
 285.165 +}
 285.166 +
 285.167 +}}
   286.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   286.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zFolderOutStream.h	Sat Mar 03 10:31:27 2012 -0600
   286.3 @@ -0,0 +1,60 @@
   286.4 +// 7zFolderOutStream.h
   286.5 +
   286.6 +#ifndef __7Z_FOLDEROUTSTREAM_H
   286.7 +#define __7Z_FOLDEROUTSTREAM_H
   286.8 +
   286.9 +#include "7zIn.h"
  286.10 +
  286.11 +#include "../../IStream.h"
  286.12 +#include "../IArchive.h"
  286.13 +#include "../Common/OutStreamWithCRC.h"
  286.14 +
  286.15 +namespace NArchive {
  286.16 +namespace N7z {
  286.17 +
  286.18 +class CFolderOutStream:
  286.19 +  public ISequentialOutStream,
  286.20 +  public CMyUnknownImp
  286.21 +{
  286.22 +public:
  286.23 +  MY_UNKNOWN_IMP
  286.24 +  
  286.25 +  CFolderOutStream();
  286.26 +
  286.27 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  286.28 +private:
  286.29 +
  286.30 +  COutStreamWithCRC *_outStreamWithHashSpec;
  286.31 +  CMyComPtr<ISequentialOutStream> _outStreamWithHash;
  286.32 +  const CArchiveDatabaseEx *_archiveDatabase;
  286.33 +  const CBoolVector *_extractStatuses;
  286.34 +  UInt32 _startIndex;
  286.35 +  UInt32 _ref2Offset;
  286.36 +  int _currentIndex;
  286.37 +  // UInt64 _currentDataPos;
  286.38 +  CMyComPtr<IArchiveExtractCallback> _extractCallback;
  286.39 +  bool _testMode;
  286.40 +
  286.41 +  bool _fileIsOpen;
  286.42 +
  286.43 +  bool _checkCrc;
  286.44 +  UInt64 _filePos;
  286.45 +
  286.46 +  HRESULT OpenFile();
  286.47 +  HRESULT WriteEmptyFiles();
  286.48 +public:
  286.49 +  HRESULT Init(
  286.50 +      const CArchiveDatabaseEx *archiveDatabase,
  286.51 +      UInt32 ref2Offset,
  286.52 +      UInt32 startIndex,
  286.53 +      const CBoolVector *extractStatuses,
  286.54 +      IArchiveExtractCallback *extractCallback,
  286.55 +      bool testMode,
  286.56 +      bool checkCrc);
  286.57 +  HRESULT FlushCorrupted(Int32 resultEOperationResult);
  286.58 +  HRESULT WasWritingFinished();
  286.59 +};
  286.60 +
  286.61 +}}
  286.62 +
  286.63 +#endif
   287.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   287.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zHandler.cpp	Sat Mar 03 10:31:27 2012 -0600
   287.3 @@ -0,0 +1,503 @@
   287.4 +// 7zHandler.cpp
   287.5 +
   287.6 +#include "StdAfx.h"
   287.7 +
   287.8 +extern "C"
   287.9 +{
  287.10 +  #include "../../../../C/CpuArch.h"
  287.11 +}
  287.12 +
  287.13 +#include "../../../Common/ComTry.h"
  287.14 +#include "../../../Common/IntToString.h"
  287.15 +
  287.16 +#ifdef COMPRESS_MT
  287.17 +#include "../../../Windows/System.h"
  287.18 +#endif
  287.19 +
  287.20 +#include "../Common/ItemNameUtils.h"
  287.21 +
  287.22 +#include "7zHandler.h"
  287.23 +#include "7zProperties.h"
  287.24 +
  287.25 +#ifdef __7Z_SET_PROPERTIES
  287.26 +#ifdef EXTRACT_ONLY
  287.27 +#include "../Common/ParseProperties.h"
  287.28 +#endif
  287.29 +#endif
  287.30 +
  287.31 +using namespace NWindows;
  287.32 +
  287.33 +extern UString ConvertMethodIdToString(UInt64 id);
  287.34 +
  287.35 +namespace NArchive {
  287.36 +namespace N7z {
  287.37 +
  287.38 +CHandler::CHandler()
  287.39 +{
  287.40 +  _crcSize = 4;
  287.41 +
  287.42 +  #ifndef _NO_CRYPTO
  287.43 +  _passwordIsDefined = false;
  287.44 +  #endif
  287.45 +
  287.46 +  #ifdef EXTRACT_ONLY
  287.47 +  #ifdef COMPRESS_MT
  287.48 +  _numThreads = NSystem::GetNumberOfProcessors();
  287.49 +  #endif
  287.50 +  #else
  287.51 +  Init();
  287.52 +  #endif
  287.53 +}
  287.54 +
  287.55 +STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
  287.56 +{
  287.57 +  *numItems = _db.Files.Size();
  287.58 +  return S_OK;
  287.59 +}
  287.60 +
  287.61 +#ifdef _SFX
  287.62 +
  287.63 +IMP_IInArchive_ArcProps_NO
  287.64 +
  287.65 +STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 * /* numProperties */)
  287.66 +{
  287.67 +  return E_NOTIMPL;
  287.68 +}
  287.69 +
  287.70 +STDMETHODIMP CHandler::GetPropertyInfo(UInt32 /* index */,
  287.71 +      BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */)
  287.72 +{
  287.73 +  return E_NOTIMPL;
  287.74 +}
  287.75 +
  287.76 +
  287.77 +#else
  287.78 +
  287.79 +STATPROPSTG kArcProps[] =
  287.80 +{
  287.81 +  { NULL, kpidMethod, VT_BSTR},
  287.82 +  { NULL, kpidSolid, VT_BOOL},
  287.83 +  { NULL, kpidNumBlocks, VT_UI4},
  287.84 +  { NULL, kpidPhySize, VT_UI8},
  287.85 +  { NULL, kpidHeadersSize, VT_UI8},
  287.86 +  { NULL, kpidOffset, VT_UI8}
  287.87 +};
  287.88 +
  287.89 +STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
  287.90 +{
  287.91 +  COM_TRY_BEGIN
  287.92 +  NCOM::CPropVariant prop;
  287.93 +  switch(propID)
  287.94 +  {
  287.95 +    case kpidMethod:
  287.96 +    {
  287.97 +      UString resString;
  287.98 +      CRecordVector<UInt64> ids;
  287.99 +      int i;
 287.100 +      for (i = 0; i < _db.Folders.Size(); i++)
 287.101 +      {
 287.102 +        const CFolder &f = _db.Folders[i];
 287.103 +        for (int j = f.Coders.Size() - 1; j >= 0; j--)
 287.104 +          ids.AddToUniqueSorted(f.Coders[j].MethodID);
 287.105 +      }
 287.106 +
 287.107 +      for (i = 0; i < ids.Size(); i++)
 287.108 +      {
 287.109 +        UInt64 id = ids[i];
 287.110 +        UString methodName;
 287.111 +        /* bool methodIsKnown = */ FindMethod(EXTERNAL_CODECS_VARS id, methodName);
 287.112 +        if (methodName.IsEmpty())
 287.113 +          methodName = ConvertMethodIdToString(id);
 287.114 +        if (!resString.IsEmpty())
 287.115 +          resString += L' ';
 287.116 +        resString += methodName;
 287.117 +      }
 287.118 +      prop = resString;
 287.119 +      break;
 287.120 +    }
 287.121 +    case kpidSolid: prop = _db.IsSolid(); break;
 287.122 +    case kpidNumBlocks: prop = (UInt32)_db.Folders.Size(); break;
 287.123 +    case kpidHeadersSize:  prop = _db.HeadersSize; break;
 287.124 +    case kpidPhySize:  prop = _db.PhySize; break;
 287.125 +    case kpidOffset: if (_db.ArchiveInfo.StartPosition != 0) prop = _db.ArchiveInfo.StartPosition; break;
 287.126 +  }
 287.127 +  prop.Detach(value);
 287.128 +  return S_OK;
 287.129 +  COM_TRY_END
 287.130 +}
 287.131 +
 287.132 +IMP_IInArchive_ArcProps
 287.133 +
 287.134 +#endif
 287.135 +
 287.136 +static void SetPropFromUInt64Def(CUInt64DefVector &v, int index, NCOM::CPropVariant &prop)
 287.137 +{
 287.138 +  UInt64 value;
 287.139 +  if (v.GetItem(index, value))
 287.140 +  {
 287.141 +    FILETIME ft;
 287.142 +    ft.dwLowDateTime = (DWORD)value;
 287.143 +    ft.dwHighDateTime = (DWORD)(value >> 32);
 287.144 +    prop = ft;
 287.145 +  }
 287.146 +}
 287.147 +
 287.148 +#ifndef _SFX
 287.149 +
 287.150 +static UString ConvertUInt32ToString(UInt32 value)
 287.151 +{
 287.152 +  wchar_t buffer[32];
 287.153 +  ConvertUInt64ToString(value, buffer);
 287.154 +  return buffer;
 287.155 +}
 287.156 +
 287.157 +static UString GetStringForSizeValue(UInt32 value)
 287.158 +{
 287.159 +  for (int i = 31; i >= 0; i--)
 287.160 +    if ((UInt32(1) << i) == value)
 287.161 +      return ConvertUInt32ToString(i);
 287.162 +  UString result;
 287.163 +  if (value % (1 << 20) == 0)
 287.164 +  {
 287.165 +    result += ConvertUInt32ToString(value >> 20);
 287.166 +    result += L"m";
 287.167 +  }
 287.168 +  else if (value % (1 << 10) == 0)
 287.169 +  {
 287.170 +    result += ConvertUInt32ToString(value >> 10);
 287.171 +    result += L"k";
 287.172 +  }
 287.173 +  else
 287.174 +  {
 287.175 +    result += ConvertUInt32ToString(value);
 287.176 +    result += L"b";
 287.177 +  }
 287.178 +  return result;
 287.179 +}
 287.180 +
 287.181 +static const UInt64 k_Copy = 0x0;
 287.182 +static const UInt64 k_LZMA  = 0x030101;
 287.183 +static const UInt64 k_PPMD  = 0x030401;
 287.184 +
 287.185 +static wchar_t GetHex(Byte value)
 287.186 +{
 287.187 +  return (wchar_t)((value < 10) ? (L'0' + value) : (L'A' + (value - 10)));
 287.188 +}
 287.189 +static inline UString GetHex2(Byte value)
 287.190 +{
 287.191 +  UString result;
 287.192 +  result += GetHex((Byte)(value >> 4));
 287.193 +  result += GetHex((Byte)(value & 0xF));
 287.194 +  return result;
 287.195 +}
 287.196 +
 287.197 +#endif
 287.198 +
 287.199 +static const UInt64 k_AES  = 0x06F10701;
 287.200 +
 287.201 +bool CHandler::IsEncrypted(UInt32 index2) const
 287.202 +{
 287.203 +  CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
 287.204 +  if (folderIndex != kNumNoIndex)
 287.205 +  {
 287.206 +    const CFolder &folderInfo = _db.Folders[folderIndex];
 287.207 +    for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)
 287.208 +      if (folderInfo.Coders[i].MethodID == k_AES)
 287.209 +        return true;
 287.210 +  }
 287.211 +  return false;
 287.212 +}
 287.213 +
 287.214 +STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)
 287.215 +{
 287.216 +  COM_TRY_BEGIN
 287.217 +  NCOM::CPropVariant prop;
 287.218 +  
 287.219 +  /*
 287.220 +  const CRef2 &ref2 = _refs[index];
 287.221 +  if (ref2.Refs.IsEmpty())
 287.222 +    return E_FAIL;
 287.223 +  const CRef &ref = ref2.Refs.Front();
 287.224 +  */
 287.225 +  
 287.226 +  const CFileItem &item = _db.Files[index];
 287.227 +  UInt32 index2 = index;
 287.228 +
 287.229 +  switch(propID)
 287.230 +  {
 287.231 +    case kpidPath:
 287.232 +      if (!item.Name.IsEmpty())
 287.233 +        prop = NItemName::GetOSName(item.Name);
 287.234 +      break;
 287.235 +    case kpidIsDir:  prop = item.IsDir; break;
 287.236 +    case kpidSize:
 287.237 +    {
 287.238 +      prop = item.Size;
 287.239 +      // prop = ref2.Size;
 287.240 +      break;
 287.241 +    }
 287.242 +    case kpidPackSize:
 287.243 +    {
 287.244 +      // prop = ref2.PackSize;
 287.245 +      {
 287.246 +        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
 287.247 +        if (folderIndex != kNumNoIndex)
 287.248 +        {
 287.249 +          if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2)
 287.250 +            prop = _db.GetFolderFullPackSize(folderIndex);
 287.251 +          /*
 287.252 +          else
 287.253 +            prop = (UInt64)0;
 287.254 +          */
 287.255 +        }
 287.256 +        else
 287.257 +          prop = (UInt64)0;
 287.258 +      }
 287.259 +      break;
 287.260 +    }
 287.261 +    case kpidPosition:  { UInt64 v; if (_db.StartPos.GetItem(index2, v)) prop = v; break; }
 287.262 +    case kpidCTime:  SetPropFromUInt64Def(_db.CTime, index2, prop); break;
 287.263 +    case kpidATime:  SetPropFromUInt64Def(_db.ATime, index2, prop); break;
 287.264 +    case kpidMTime:  SetPropFromUInt64Def(_db.MTime, index2, prop); break;
 287.265 +    case kpidAttrib:  if (item.AttribDefined) prop = item.Attrib; break;
 287.266 +    case kpidCRC:  if (item.CrcDefined) prop = item.Crc; break;
 287.267 +    case kpidEncrypted:  prop = IsEncrypted(index2); break;
 287.268 +    case kpidIsAnti:  prop = _db.IsItemAnti(index2); break;
 287.269 +    #ifndef _SFX
 287.270 +    case kpidMethod:
 287.271 +      {
 287.272 +        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
 287.273 +        if (folderIndex != kNumNoIndex)
 287.274 +        {
 287.275 +          const CFolder &folderInfo = _db.Folders[folderIndex];
 287.276 +          UString methodsString;
 287.277 +          for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)
 287.278 +          {
 287.279 +            const CCoderInfo &coderInfo = folderInfo.Coders[i];
 287.280 +            if (!methodsString.IsEmpty())
 287.281 +              methodsString += L' ';
 287.282 +
 287.283 +            {
 287.284 +              UString methodName;
 287.285 +              bool methodIsKnown = FindMethod(
 287.286 +                  EXTERNAL_CODECS_VARS
 287.287 +                  coderInfo.MethodID, methodName);
 287.288 +
 287.289 +              if (methodIsKnown)
 287.290 +              {
 287.291 +                methodsString += methodName;
 287.292 +                if (coderInfo.MethodID == k_LZMA)
 287.293 +                {
 287.294 +                  if (coderInfo.Props.GetCapacity() >= 5)
 287.295 +                  {
 287.296 +                    methodsString += L":";
 287.297 +                    UInt32 dicSize = GetUi32((const Byte *)coderInfo.Props + 1);
 287.298 +                    methodsString += GetStringForSizeValue(dicSize);
 287.299 +                  }
 287.300 +                }
 287.301 +                else if (coderInfo.MethodID == k_PPMD)
 287.302 +                {
 287.303 +                  if (coderInfo.Props.GetCapacity() >= 5)
 287.304 +                  {
 287.305 +                    Byte order = *(const Byte *)coderInfo.Props;
 287.306 +                    methodsString += L":o";
 287.307 +                    methodsString += ConvertUInt32ToString(order);
 287.308 +                    methodsString += L":mem";
 287.309 +                    UInt32 dicSize = GetUi32((const Byte *)coderInfo.Props + 1);
 287.310 +                    methodsString += GetStringForSizeValue(dicSize);
 287.311 +                  }
 287.312 +                }
 287.313 +                else if (coderInfo.MethodID == k_AES)
 287.314 +                {
 287.315 +                  if (coderInfo.Props.GetCapacity() >= 1)
 287.316 +                  {
 287.317 +                    methodsString += L":";
 287.318 +                    const Byte *data = (const Byte *)coderInfo.Props;
 287.319 +                    Byte firstByte = *data++;
 287.320 +                    UInt32 numCyclesPower = firstByte & 0x3F;
 287.321 +                    methodsString += ConvertUInt32ToString(numCyclesPower);
 287.322 +                    /*
 287.323 +                    if ((firstByte & 0xC0) != 0)
 287.324 +                    {
 287.325 +                      methodsString += L":";
 287.326 +                      return S_OK;
 287.327 +                      UInt32 saltSize = (firstByte >> 7) & 1;
 287.328 +                      UInt32 ivSize = (firstByte >> 6) & 1;
 287.329 +                      if (coderInfo.Props.GetCapacity() >= 2)
 287.330 +                      {
 287.331 +                        Byte secondByte = *data++;
 287.332 +                        saltSize += (secondByte >> 4);
 287.333 +                        ivSize += (secondByte & 0x0F);
 287.334 +                      }
 287.335 +                    }
 287.336 +                    */
 287.337 +                  }
 287.338 +                }
 287.339 +                else
 287.340 +                {
 287.341 +                  if (coderInfo.Props.GetCapacity() > 0)
 287.342 +                  {
 287.343 +                    methodsString += L":[";
 287.344 +                    for (size_t bi = 0; bi < coderInfo.Props.GetCapacity(); bi++)
 287.345 +                    {
 287.346 +                      if (bi > 5 && bi + 1 < coderInfo.Props.GetCapacity())
 287.347 +                      {
 287.348 +                        methodsString += L"..";
 287.349 +                        break;
 287.350 +                      }
 287.351 +                      else
 287.352 +                        methodsString += GetHex2(coderInfo.Props[bi]);
 287.353 +                    }
 287.354 +                    methodsString += L"]";
 287.355 +                  }
 287.356 +                }
 287.357 +              }
 287.358 +              else
 287.359 +              {
 287.360 +                methodsString += ConvertMethodIdToString(coderInfo.MethodID);
 287.361 +              }
 287.362 +            }
 287.363 +          }
 287.364 +          prop = methodsString;
 287.365 +        }
 287.366 +      }
 287.367 +      break;
 287.368 +    case kpidBlock:
 287.369 +      {
 287.370 +        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
 287.371 +        if (folderIndex != kNumNoIndex)
 287.372 +          prop = (UInt32)folderIndex;
 287.373 +      }
 287.374 +      break;
 287.375 +    case kpidPackedSize0:
 287.376 +    case kpidPackedSize1:
 287.377 +    case kpidPackedSize2:
 287.378 +    case kpidPackedSize3:
 287.379 +    case kpidPackedSize4:
 287.380 +      {
 287.381 +        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
 287.382 +        if (folderIndex != kNumNoIndex)
 287.383 +        {
 287.384 +          const CFolder &folderInfo = _db.Folders[folderIndex];
 287.385 +          if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2 &&
 287.386 +              folderInfo.PackStreams.Size() > (int)(propID - kpidPackedSize0))
 287.387 +          {
 287.388 +            prop = _db.GetFolderPackStreamSize(folderIndex, propID - kpidPackedSize0);
 287.389 +          }
 287.390 +          else
 287.391 +            prop = (UInt64)0;
 287.392 +        }
 287.393 +        else
 287.394 +          prop = (UInt64)0;
 287.395 +      }
 287.396 +      break;
 287.397 +    #endif
 287.398 +  }
 287.399 +  prop.Detach(value);
 287.400 +  return S_OK;
 287.401 +  COM_TRY_END
 287.402 +}
 287.403 +
 287.404 +STDMETHODIMP CHandler::Open(IInStream *stream,
 287.405 +    const UInt64 *maxCheckStartPosition,
 287.406 +    IArchiveOpenCallback *openArchiveCallback)
 287.407 +{
 287.408 +  COM_TRY_BEGIN
 287.409 +  Close();
 287.410 +  #ifndef _SFX
 287.411 +  _fileInfoPopIDs.Clear();
 287.412 +  #endif
 287.413 +  try
 287.414 +  {
 287.415 +    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackTemp = openArchiveCallback;
 287.416 +
 287.417 +    #ifndef _NO_CRYPTO
 287.418 +    CMyComPtr<ICryptoGetTextPassword> getTextPassword;
 287.419 +    if (openArchiveCallback)
 287.420 +    {
 287.421 +      openArchiveCallbackTemp.QueryInterface(
 287.422 +          IID_ICryptoGetTextPassword, &getTextPassword);
 287.423 +    }
 287.424 +    #endif
 287.425 +    CInArchive archive;
 287.426 +    RINOK(archive.Open(stream, maxCheckStartPosition));
 287.427 +    #ifndef _NO_CRYPTO
 287.428 +    _passwordIsDefined = false;
 287.429 +    UString password;
 287.430 +    #endif
 287.431 +    HRESULT result = archive.ReadDatabase(
 287.432 +      EXTERNAL_CODECS_VARS
 287.433 +      _db
 287.434 +      #ifndef _NO_CRYPTO
 287.435 +      , getTextPassword, _passwordIsDefined
 287.436 +      #endif
 287.437 +      );
 287.438 +    RINOK(result);
 287.439 +    _db.Fill();
 287.440 +    _inStream = stream;
 287.441 +  }
 287.442 +  catch(...)
 287.443 +  {
 287.444 +    Close();
 287.445 +    return S_FALSE;
 287.446 +  }
 287.447 +  // _inStream = stream;
 287.448 +  #ifndef _SFX
 287.449 +  FillPopIDs();
 287.450 +  #endif
 287.451 +  return S_OK;
 287.452 +  COM_TRY_END
 287.453 +}
 287.454 +
 287.455 +STDMETHODIMP CHandler::Close()
 287.456 +{
 287.457 +  COM_TRY_BEGIN
 287.458 +  _inStream.Release();
 287.459 +  _db.Clear();
 287.460 +  return S_OK;
 287.461 +  COM_TRY_END
 287.462 +}
 287.463 +
 287.464 +#ifdef __7Z_SET_PROPERTIES
 287.465 +#ifdef EXTRACT_ONLY
 287.466 +
 287.467 +STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)
 287.468 +{
 287.469 +  COM_TRY_BEGIN
 287.470 +  #ifdef COMPRESS_MT
 287.471 +  const UInt32 numProcessors = NSystem::GetNumberOfProcessors();
 287.472 +  _numThreads = numProcessors;
 287.473 +  #endif
 287.474 +
 287.475 +  for (int i = 0; i < numProperties; i++)
 287.476 +  {
 287.477 +    UString name = names[i];
 287.478 +    name.MakeUpper();
 287.479 +    if (name.IsEmpty())
 287.480 +      return E_INVALIDARG;
 287.481 +    const PROPVARIANT &value = values[i];
 287.482 +    UInt32 number;
 287.483 +    int index = ParseStringToUInt32(name, number);
 287.484 +    if (index == 0)
 287.485 +    {
 287.486 +      if(name.Left(2).CompareNoCase(L"MT") == 0)
 287.487 +      {
 287.488 +        #ifdef COMPRESS_MT
 287.489 +        RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));
 287.490 +        #endif
 287.491 +        continue;
 287.492 +      }
 287.493 +      else
 287.494 +        return E_INVALIDARG;
 287.495 +    }
 287.496 +  }
 287.497 +  return S_OK;
 287.498 +  COM_TRY_END
 287.499 +}
 287.500 +
 287.501 +#endif
 287.502 +#endif
 287.503 +
 287.504 +IMPL_ISetCompressCodecsInfo
 287.505 +
 287.506 +}}
   288.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   288.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zHandler.h	Sat Mar 03 10:31:27 2012 -0600
   288.3 @@ -0,0 +1,121 @@
   288.4 +// 7z/Handler.h
   288.5 +
   288.6 +#ifndef __7Z_HANDLER_H
   288.7 +#define __7Z_HANDLER_H
   288.8 +
   288.9 +#include "../../ICoder.h"
  288.10 +#include "../IArchive.h"
  288.11 +#include "7zIn.h"
  288.12 +
  288.13 +#include "7zCompressionMode.h"
  288.14 +
  288.15 +#include "../../Common/CreateCoder.h"
  288.16 +
  288.17 +#ifndef EXTRACT_ONLY
  288.18 +#include "../Common/HandlerOut.h"
  288.19 +#endif
  288.20 +
  288.21 +namespace NArchive {
  288.22 +namespace N7z {
  288.23 +
  288.24 +#ifndef __7Z_SET_PROPERTIES
  288.25 +
  288.26 +#ifdef EXTRACT_ONLY
  288.27 +#ifdef COMPRESS_MT
  288.28 +#define __7Z_SET_PROPERTIES
  288.29 +#endif
  288.30 +#else
  288.31 +#define __7Z_SET_PROPERTIES
  288.32 +#endif
  288.33 +
  288.34 +#endif
  288.35 +
  288.36 +
  288.37 +class CHandler:
  288.38 +  #ifndef EXTRACT_ONLY
  288.39 +  public NArchive::COutHandler,
  288.40 +  #endif
  288.41 +  public IInArchive,
  288.42 +  #ifdef __7Z_SET_PROPERTIES
  288.43 +  public ISetProperties,
  288.44 +  #endif
  288.45 +  #ifndef EXTRACT_ONLY
  288.46 +  public IOutArchive,
  288.47 +  #endif
  288.48 +  PUBLIC_ISetCompressCodecsInfo
  288.49 +  public CMyUnknownImp
  288.50 +{
  288.51 +public:
  288.52 +  MY_QUERYINTERFACE_BEGIN2(IInArchive)
  288.53 +  #ifdef __7Z_SET_PROPERTIES
  288.54 +  MY_QUERYINTERFACE_ENTRY(ISetProperties)
  288.55 +  #endif
  288.56 +  #ifndef EXTRACT_ONLY
  288.57 +  MY_QUERYINTERFACE_ENTRY(IOutArchive)
  288.58 +  #endif
  288.59 +  QUERY_ENTRY_ISetCompressCodecsInfo
  288.60 +  MY_QUERYINTERFACE_END
  288.61 +  MY_ADDREF_RELEASE
  288.62 +
  288.63 +  INTERFACE_IInArchive(;)
  288.64 +
  288.65 +  #ifdef __7Z_SET_PROPERTIES
  288.66 +  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);
  288.67 +  #endif
  288.68 +
  288.69 +  #ifndef EXTRACT_ONLY
  288.70 +  INTERFACE_IOutArchive(;)
  288.71 +  #endif
  288.72 +
  288.73 +  DECL_ISetCompressCodecsInfo
  288.74 +
  288.75 +  CHandler();
  288.76 +
  288.77 +private:
  288.78 +  CMyComPtr<IInStream> _inStream;
  288.79 +  NArchive::N7z::CArchiveDatabaseEx _db;
  288.80 +  #ifndef _NO_CRYPTO
  288.81 +  bool _passwordIsDefined;
  288.82 +  #endif
  288.83 +
  288.84 +  #ifdef EXTRACT_ONLY
  288.85 +  
  288.86 +  #ifdef COMPRESS_MT
  288.87 +  UInt32 _numThreads;
  288.88 +  #endif
  288.89 +
  288.90 +  UInt32 _crcSize;
  288.91 +
  288.92 +  #else
  288.93 +  
  288.94 +  CRecordVector<CBind> _binds;
  288.95 +
  288.96 +  HRESULT SetPassword(CCompressionMethodMode &methodMode, IArchiveUpdateCallback *updateCallback);
  288.97 +
  288.98 +  HRESULT SetCompressionMethod(CCompressionMethodMode &method,
  288.99 +      CObjectVector<COneMethodInfo> &methodsInfo
 288.100 +      #ifdef COMPRESS_MT
 288.101 +      , UInt32 numThreads
 288.102 +      #endif
 288.103 +      );
 288.104 +
 288.105 +  HRESULT SetCompressionMethod(
 288.106 +      CCompressionMethodMode &method,
 288.107 +      CCompressionMethodMode &headerMethod);
 288.108 +
 288.109 +  #endif
 288.110 +
 288.111 +  bool IsEncrypted(UInt32 index2) const;
 288.112 +  #ifndef _SFX
 288.113 +
 288.114 +  CRecordVector<UInt64> _fileInfoPopIDs;
 288.115 +  void FillPopIDs();
 288.116 +
 288.117 +  #endif
 288.118 +
 288.119 +  DECL_EXTERNAL_CODECS_VARS
 288.120 +};
 288.121 +
 288.122 +}}
 288.123 +
 288.124 +#endif
   289.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   289.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zHeader.cpp	Sat Mar 03 10:31:27 2012 -0600
   289.3 @@ -0,0 +1,27 @@
   289.4 +// 7z/Header.cpp
   289.5 +
   289.6 +#include "StdAfx.h"
   289.7 +#include "7zHeader.h"
   289.8 +
   289.9 +namespace NArchive {
  289.10 +namespace N7z {
  289.11 +
  289.12 +Byte kSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C};
  289.13 +#ifdef _7Z_VOL
  289.14 +Byte kFinishSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C + 1};
  289.15 +#endif
  289.16 +
  289.17 +class SignatureInitializer
  289.18 +{
  289.19 +public:
  289.20 +  SignatureInitializer()
  289.21 +  {
  289.22 +    kSignature[0]--;
  289.23 +    #ifdef _7Z_VOL
  289.24 +    kFinishSignature[0]--;
  289.25 +    #endif
  289.26 +  };
  289.27 +} g_SignatureInitializer;
  289.28 +
  289.29 +}}
  289.30 +
   290.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   290.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zHeader.h	Sat Mar 03 10:31:27 2012 -0600
   290.3 @@ -0,0 +1,97 @@
   290.4 +// 7z/7zHeader.h
   290.5 +
   290.6 +#ifndef __7Z_HEADER_H
   290.7 +#define __7Z_HEADER_H
   290.8 +
   290.9 +#include "../../../Common/Types.h"
  290.10 +
  290.11 +namespace NArchive {
  290.12 +namespace N7z {
  290.13 +
  290.14 +const int kSignatureSize = 6;
  290.15 +extern Byte kSignature[kSignatureSize];
  290.16 +
  290.17 +// #define _7Z_VOL
  290.18 +// 7z-MultiVolume is not finished yet.
  290.19 +// It can work already, but I still do not like some
  290.20 +// things of that new multivolume format.
  290.21 +// So please keep it commented.
  290.22 +
  290.23 +#ifdef _7Z_VOL
  290.24 +extern Byte kFinishSignature[kSignatureSize];
  290.25 +#endif
  290.26 +
  290.27 +struct CArchiveVersion
  290.28 +{
  290.29 +  Byte Major;
  290.30 +  Byte Minor;
  290.31 +};
  290.32 +
  290.33 +const Byte kMajorVersion = 0;
  290.34 +
  290.35 +struct CStartHeader
  290.36 +{
  290.37 +  UInt64 NextHeaderOffset;
  290.38 +  UInt64 NextHeaderSize;
  290.39 +  UInt32 NextHeaderCRC;
  290.40 +};
  290.41 +
  290.42 +const UInt32 kStartHeaderSize = 20;
  290.43 +
  290.44 +#ifdef _7Z_VOL
  290.45 +struct CFinishHeader: public CStartHeader
  290.46 +{
  290.47 +  UInt64 ArchiveStartOffset;  // data offset from end if that struct
  290.48 +  UInt64 AdditionalStartBlockSize; // start  signature & start header size
  290.49 +};
  290.50 +
  290.51 +const UInt32 kFinishHeaderSize = kStartHeaderSize + 16;
  290.52 +#endif
  290.53 +
  290.54 +namespace NID
  290.55 +{
  290.56 +  enum EEnum
  290.57 +  {
  290.58 +    kEnd,
  290.59 +
  290.60 +    kHeader,
  290.61 +
  290.62 +    kArchiveProperties,
  290.63 +    
  290.64 +    kAdditionalStreamsInfo,
  290.65 +    kMainStreamsInfo,
  290.66 +    kFilesInfo,
  290.67 +    
  290.68 +    kPackInfo,
  290.69 +    kUnpackInfo,
  290.70 +    kSubStreamsInfo,
  290.71 +
  290.72 +    kSize,
  290.73 +    kCRC,
  290.74 +
  290.75 +    kFolder,
  290.76 +
  290.77 +    kCodersUnpackSize,
  290.78 +    kNumUnpackStream,
  290.79 +
  290.80 +    kEmptyStream,
  290.81 +    kEmptyFile,
  290.82 +    kAnti,
  290.83 +
  290.84 +    kName,
  290.85 +    kCTime,
  290.86 +    kATime,
  290.87 +    kMTime,
  290.88 +    kWinAttributes,
  290.89 +    kComment,
  290.90 +
  290.91 +    kEncodedHeader,
  290.92 +
  290.93 +    kStartPos,
  290.94 +    kDummy
  290.95 +  };
  290.96 +}
  290.97 +
  290.98 +}}
  290.99 +
 290.100 +#endif
   291.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   291.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zIn.cpp	Sat Mar 03 10:31:27 2012 -0600
   291.3 @@ -0,0 +1,1260 @@
   291.4 +// 7zIn.cpp
   291.5 +
   291.6 +#include "StdAfx.h"
   291.7 +
   291.8 +extern "C"
   291.9 +{
  291.10 +  #include "../../../../C/7zCrc.h"
  291.11 +  #include "../../../../C/CpuArch.h"
  291.12 +}
  291.13 +
  291.14 +#include "../../Common/StreamObjects.h"
  291.15 +#include "../../Common/StreamUtils.h"
  291.16 +
  291.17 +#include "7zDecode.h"
  291.18 +#include "7zIn.h"
  291.19 +
  291.20 +#define Get16(p) GetUi16(p)
  291.21 +#define Get32(p) GetUi32(p)
  291.22 +#define Get64(p) GetUi64(p)
  291.23 +
  291.24 +// define FORMAT_7Z_RECOVERY if you want to recover multivolume archives with empty StartHeader
  291.25 +#ifndef _SFX
  291.26 +#define FORMAT_7Z_RECOVERY
  291.27 +#endif
  291.28 +
  291.29 +namespace NArchive {
  291.30 +namespace N7z {
  291.31 +
  291.32 +static void BoolVector_Fill_False(CBoolVector &v, int size)
  291.33 +{
  291.34 +  v.Clear();
  291.35 +  v.Reserve(size);
  291.36 +  for (int i = 0; i < size; i++)
  291.37 +    v.Add(false);
  291.38 +}
  291.39 +
  291.40 +static bool BoolVector_GetAndSet(CBoolVector &v, UInt32 index)
  291.41 +{
  291.42 +  if (index >= (UInt32)v.Size())
  291.43 +    return true;
  291.44 +  bool res = v[index];
  291.45 +  v[index] = true;
  291.46 +  return res;
  291.47 +}
  291.48 +
  291.49 +bool CFolder::CheckStructure() const
  291.50 +{
  291.51 +  const int kNumCodersMax = sizeof(UInt32) * 8; // don't change it
  291.52 +  const int kMaskSize = sizeof(UInt32) * 8; // it must be >= kNumCodersMax
  291.53 +  const int kNumBindsMax = 32;
  291.54 +
  291.55 +  if (Coders.Size() > kNumCodersMax || BindPairs.Size() > kNumBindsMax)
  291.56 +    return false;
  291.57 +
  291.58 +  {
  291.59 +    CBoolVector v;
  291.60 +    BoolVector_Fill_False(v, BindPairs.Size() + PackStreams.Size());
  291.61 +    
  291.62 +    int i;
  291.63 +    for (i = 0; i < BindPairs.Size(); i++)
  291.64 +      if (BoolVector_GetAndSet(v, BindPairs[i].InIndex))
  291.65 +        return false;
  291.66 +    for (i = 0; i < PackStreams.Size(); i++)
  291.67 +      if (BoolVector_GetAndSet(v, PackStreams[i]))
  291.68 +        return false;
  291.69 +    
  291.70 +    BoolVector_Fill_False(v, UnpackSizes.Size());
  291.71 +    for (i = 0; i < BindPairs.Size(); i++)
  291.72 +      if (BoolVector_GetAndSet(v, BindPairs[i].OutIndex))
  291.73 +        return false;
  291.74 +  }
  291.75 +  
  291.76 +  UInt32 mask[kMaskSize];
  291.77 +  int i;
  291.78 +  for (i = 0; i < kMaskSize; i++)
  291.79 +    mask[i] = 0;
  291.80 +
  291.81 +  {
  291.82 +    CIntVector inStreamToCoder, outStreamToCoder;
  291.83 +    for (i = 0; i < Coders.Size(); i++)
  291.84 +    {
  291.85 +      CNum j;
  291.86 +      const CCoderInfo &coder = Coders[i];
  291.87 +      for (j = 0; j < coder.NumInStreams; j++)
  291.88 +        inStreamToCoder.Add(i);
  291.89 +      for (j = 0; j < coder.NumOutStreams; j++)
  291.90 +        outStreamToCoder.Add(i);
  291.91 +    }
  291.92 +    
  291.93 +    for (i = 0; i < BindPairs.Size(); i++)
  291.94 +    {
  291.95 +      const CBindPair &bp = BindPairs[i];
  291.96 +      mask[inStreamToCoder[bp.InIndex]] |= (1 << outStreamToCoder[bp.OutIndex]);
  291.97 +    }
  291.98 +  }
  291.99 +  
 291.100 +  for (i = 0; i < kMaskSize; i++)
 291.101 +    for (int j = 0; j < kMaskSize; j++)
 291.102 +      if (((1 << j) & mask[i]) != 0)
 291.103 +        mask[i] |= mask[j];
 291.104 +
 291.105 +  for (i = 0; i < kMaskSize; i++)
 291.106 +    if (((1 << i) & mask[i]) != 0)
 291.107 +      return false;
 291.108 +
 291.109 +  return true;
 291.110 +}
 291.111 +
 291.112 +class CInArchiveException {};
 291.113 +
 291.114 +static void ThrowException() { throw CInArchiveException(); }
 291.115 +static inline void ThrowEndOfData()   { ThrowException(); }
 291.116 +static inline void ThrowUnsupported() { ThrowException(); }
 291.117 +static inline void ThrowIncorrect()   { ThrowException(); }
 291.118 +static inline void ThrowUnsupportedVersion() { ThrowException(); }
 291.119 +
 291.120 +/*
 291.121 +class CInArchiveException
 291.122 +{
 291.123 +public:
 291.124 +  enum CCauseType
 291.125 +  {
 291.126 +    kUnsupportedVersion = 0,
 291.127 +    kUnsupported,
 291.128 +    kIncorrect,
 291.129 +    kEndOfData,
 291.130 +  } Cause;
 291.131 +  CInArchiveException(CCauseType cause): Cause(cause) {};
 291.132 +};
 291.133 +
 291.134 +static void ThrowException(CInArchiveException::CCauseType c) { throw CInArchiveException(c); }
 291.135 +static void ThrowEndOfData()   { ThrowException(CInArchiveException::kEndOfData); }
 291.136 +static void ThrowUnsupported() { ThrowException(CInArchiveException::kUnsupported); }
 291.137 +static void ThrowIncorrect()   { ThrowException(CInArchiveException::kIncorrect); }
 291.138 +static void ThrowUnsupportedVersion() { ThrowException(CInArchiveException::kUnsupportedVersion); }
 291.139 +*/
 291.140 +
 291.141 +class CStreamSwitch
 291.142 +{
 291.143 +  CInArchive *_archive;
 291.144 +  bool _needRemove;
 291.145 +public:
 291.146 +  CStreamSwitch(): _needRemove(false) {}
 291.147 +  ~CStreamSwitch() { Remove(); }
 291.148 +  void Remove();
 291.149 +  void Set(CInArchive *archive, const Byte *data, size_t size);
 291.150 +  void Set(CInArchive *archive, const CByteBuffer &byteBuffer);
 291.151 +  void Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector);
 291.152 +};
 291.153 +
 291.154 +void CStreamSwitch::Remove()
 291.155 +{
 291.156 +  if (_needRemove)
 291.157 +  {
 291.158 +    _archive->DeleteByteStream();
 291.159 +    _needRemove = false;
 291.160 +  }
 291.161 +}
 291.162 +
 291.163 +void CStreamSwitch::Set(CInArchive *archive, const Byte *data, size_t size)
 291.164 +{
 291.165 +  Remove();
 291.166 +  _archive = archive;
 291.167 +  _archive->AddByteStream(data, size);
 291.168 +  _needRemove = true;
 291.169 +}
 291.170 +
 291.171 +void CStreamSwitch::Set(CInArchive *archive, const CByteBuffer &byteBuffer)
 291.172 +{
 291.173 +  Set(archive, byteBuffer, byteBuffer.GetCapacity());
 291.174 +}
 291.175 +
 291.176 +void CStreamSwitch::Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector)
 291.177 +{
 291.178 +  Remove();
 291.179 +  Byte external = archive->ReadByte();
 291.180 +  if (external != 0)
 291.181 +  {
 291.182 +    int dataIndex = (int)archive->ReadNum();
 291.183 +    if (dataIndex < 0 || dataIndex >= dataVector->Size())
 291.184 +      ThrowIncorrect();
 291.185 +    Set(archive, (*dataVector)[dataIndex]);
 291.186 +  }
 291.187 +}
 291.188 +
 291.189 +Byte CInByte2::ReadByte()
 291.190 +{
 291.191 +  if (_pos >= _size)
 291.192 +    ThrowEndOfData();
 291.193 +  return _buffer[_pos++];
 291.194 +}
 291.195 +
 291.196 +void CInByte2::ReadBytes(Byte *data, size_t size)
 291.197 +{
 291.198 +  if (size > _size - _pos)
 291.199 +    ThrowEndOfData();
 291.200 +  for (size_t i = 0; i < size; i++)
 291.201 +    data[i] = _buffer[_pos++];
 291.202 +}
 291.203 +
 291.204 +void CInByte2::SkeepData(UInt64 size)
 291.205 +{
 291.206 +  if (size > _size - _pos)
 291.207 +    ThrowEndOfData();
 291.208 +  _pos += (size_t)size;
 291.209 +}
 291.210 +
 291.211 +void CInByte2::SkeepData()
 291.212 +{
 291.213 +  SkeepData(ReadNumber());
 291.214 +}
 291.215 +
 291.216 +UInt64 CInByte2::ReadNumber()
 291.217 +{
 291.218 +  if (_pos >= _size)
 291.219 +    ThrowEndOfData();
 291.220 +  Byte firstByte = _buffer[_pos++];
 291.221 +  Byte mask = 0x80;
 291.222 +  UInt64 value = 0;
 291.223 +  for (int i = 0; i < 8; i++)
 291.224 +  {
 291.225 +    if ((firstByte & mask) == 0)
 291.226 +    {
 291.227 +      UInt64 highPart = firstByte & (mask - 1);
 291.228 +      value += (highPart << (i * 8));
 291.229 +      return value;
 291.230 +    }
 291.231 +    if (_pos >= _size)
 291.232 +      ThrowEndOfData();
 291.233 +    value |= ((UInt64)_buffer[_pos++] << (8 * i));
 291.234 +    mask >>= 1;
 291.235 +  }
 291.236 +  return value;
 291.237 +}
 291.238 +
 291.239 +CNum CInByte2::ReadNum()
 291.240 +{
 291.241 +  UInt64 value = ReadNumber();
 291.242 +  if (value > kNumMax)
 291.243 +    ThrowUnsupported();
 291.244 +  return (CNum)value;
 291.245 +}
 291.246 +
 291.247 +UInt32 CInByte2::ReadUInt32()
 291.248 +{
 291.249 +  if (_pos + 4 > _size)
 291.250 +    ThrowEndOfData();
 291.251 +  UInt32 res = Get32(_buffer + _pos);
 291.252 +  _pos += 4;
 291.253 +  return res;
 291.254 +}
 291.255 +
 291.256 +UInt64 CInByte2::ReadUInt64()
 291.257 +{
 291.258 +  if (_pos + 8 > _size)
 291.259 +    ThrowEndOfData();
 291.260 +  UInt64 res = Get64(_buffer + _pos);
 291.261 +  _pos += 8;
 291.262 +  return res;
 291.263 +}
 291.264 +
 291.265 +void CInByte2::ReadString(UString &s)
 291.266 +{
 291.267 +  const Byte *buf = _buffer + _pos;
 291.268 +  size_t rem = (_size - _pos) / 2 * 2;
 291.269 +  {
 291.270 +    size_t i;
 291.271 +    for (i = 0; i < rem; i += 2)
 291.272 +      if (buf[i] == 0 && buf[i + 1] == 0)
 291.273 +        break;
 291.274 +    if (i == rem)
 291.275 +      ThrowEndOfData();
 291.276 +    rem = i;
 291.277 +  }
 291.278 +  int len = (int)(rem / 2);
 291.279 +  if (len < 0 || (size_t)len * 2 != rem)
 291.280 +    ThrowUnsupported();
 291.281 +  wchar_t *p = s.GetBuffer(len);
 291.282 +  int i;
 291.283 +  for (i = 0; i < len; i++, buf += 2)
 291.284 +    p[i] = (wchar_t)Get16(buf);
 291.285 +  s.ReleaseBuffer(len);
 291.286 +  _pos += rem + 2;
 291.287 +}
 291.288 +
 291.289 +static inline bool TestSignatureCandidate(const Byte *p)
 291.290 +{
 291.291 +  for (int i = 0; i < kSignatureSize; i++)
 291.292 +    if (p[i] != kSignature[i])
 291.293 +      return false;
 291.294 +  return (p[0x1A] == 0 && p[0x1B] == 0);
 291.295 +}
 291.296 +
 291.297 +HRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
 291.298 +{
 291.299 +  RINOK(ReadStream_FALSE(stream, _header, kHeaderSize));
 291.300 +
 291.301 +  if (TestSignatureCandidate(_header))
 291.302 +    return S_OK;
 291.303 +
 291.304 +  CByteBuffer byteBuffer;
 291.305 +  const UInt32 kBufferSize = (1 << 16);
 291.306 +  byteBuffer.SetCapacity(kBufferSize);
 291.307 +  Byte *buffer = byteBuffer;
 291.308 +  UInt32 numPrevBytes = kHeaderSize - 1;
 291.309 +  memcpy(buffer, _header + 1, numPrevBytes);
 291.310 +  UInt64 curTestPos = _arhiveBeginStreamPosition + 1;
 291.311 +  for (;;)
 291.312 +  {
 291.313 +    if (searchHeaderSizeLimit != NULL)
 291.314 +      if (curTestPos - _arhiveBeginStreamPosition > *searchHeaderSizeLimit)
 291.315 +        break;
 291.316 +    do
 291.317 +    {
 291.318 +      UInt32 numReadBytes = kBufferSize - numPrevBytes;
 291.319 +      UInt32 processedSize;
 291.320 +      RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));
 291.321 +      numPrevBytes += processedSize;
 291.322 +      if (processedSize == 0)
 291.323 +        return S_FALSE;
 291.324 +    }
 291.325 +    while (numPrevBytes < kHeaderSize);
 291.326 +    UInt32 numTests = numPrevBytes - kHeaderSize + 1;
 291.327 +    for (UInt32 pos = 0; pos < numTests; pos++)
 291.328 +    {
 291.329 +      for (; buffer[pos] != '7' && pos < numTests; pos++);
 291.330 +      if (pos == numTests)
 291.331 +        break;
 291.332 +      if (TestSignatureCandidate(buffer + pos))
 291.333 +      {
 291.334 +        memcpy(_header, buffer + pos, kHeaderSize);
 291.335 +        curTestPos += pos;
 291.336 +        _arhiveBeginStreamPosition = curTestPos;
 291.337 +        return stream->Seek(curTestPos + kHeaderSize, STREAM_SEEK_SET, NULL);
 291.338 +      }
 291.339 +    }
 291.340 +    curTestPos += numTests;
 291.341 +    numPrevBytes -= numTests;
 291.342 +    memmove(buffer, buffer + numTests, numPrevBytes);
 291.343 +  }
 291.344 +  return S_FALSE;
 291.345 +}
 291.346 +
 291.347 +// S_FALSE means that file is not archive
 291.348 +HRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
 291.349 +{
 291.350 +  HeadersSize = 0;
 291.351 +  Close();
 291.352 +  RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_arhiveBeginStreamPosition))
 291.353 +  RINOK(FindAndReadSignature(stream, searchHeaderSizeLimit));
 291.354 +  _stream = stream;
 291.355 +  return S_OK;
 291.356 +}
 291.357 +  
 291.358 +void CInArchive::Close()
 291.359 +{
 291.360 +  _stream.Release();
 291.361 +}
 291.362 +
 291.363 +void CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */)
 291.364 +{
 291.365 +  for (;;)
 291.366 +  {
 291.367 +    if (ReadID() == NID::kEnd)
 291.368 +      break;
 291.369 +    SkeepData();
 291.370 +  }
 291.371 +}
 291.372 +
 291.373 +void CInArchive::GetNextFolderItem(CFolder &folder)
 291.374 +{
 291.375 +  CNum numCoders = ReadNum();
 291.376 +
 291.377 +  folder.Coders.Clear();
 291.378 +  folder.Coders.Reserve((int)numCoders);
 291.379 +  CNum numInStreams = 0;
 291.380 +  CNum numOutStreams = 0;
 291.381 +  CNum i;
 291.382 +  for (i = 0; i < numCoders; i++)
 291.383 +  {
 291.384 +    folder.Coders.Add(CCoderInfo());
 291.385 +    CCoderInfo &coder = folder.Coders.Back();
 291.386 +
 291.387 +    {
 291.388 +      Byte mainByte = ReadByte();
 291.389 +      int idSize = (mainByte & 0xF);
 291.390 +      Byte longID[15];
 291.391 +      ReadBytes(longID, idSize);
 291.392 +      if (idSize > 8)
 291.393 +        ThrowUnsupported();
 291.394 +      UInt64 id = 0;
 291.395 +      for (int j = 0; j < idSize; j++)
 291.396 +        id |= (UInt64)longID[idSize - 1 - j] << (8 * j);
 291.397 +      coder.MethodID = id;
 291.398 +
 291.399 +      if ((mainByte & 0x10) != 0)
 291.400 +      {
 291.401 +        coder.NumInStreams = ReadNum();
 291.402 +        coder.NumOutStreams = ReadNum();
 291.403 +      }
 291.404 +      else
 291.405 +      {
 291.406 +        coder.NumInStreams = 1;
 291.407 +        coder.NumOutStreams = 1;
 291.408 +      }
 291.409 +      if ((mainByte & 0x20) != 0)
 291.410 +      {
 291.411 +        CNum propsSize = ReadNum();
 291.412 +        coder.Props.SetCapacity((size_t)propsSize);
 291.413 +        ReadBytes((Byte *)coder.Props, (size_t)propsSize);
 291.414 +      }
 291.415 +      if ((mainByte & 0x80) != 0)
 291.416 +        ThrowUnsupported();
 291.417 +    }
 291.418 +    numInStreams += coder.NumInStreams;
 291.419 +    numOutStreams += coder.NumOutStreams;
 291.420 +  }
 291.421 +
 291.422 +  CNum numBindPairs = numOutStreams - 1;
 291.423 +  folder.BindPairs.Clear();
 291.424 +  folder.BindPairs.Reserve(numBindPairs);
 291.425 +  for (i = 0; i < numBindPairs; i++)
 291.426 +  {
 291.427 +    CBindPair bp;
 291.428 +    bp.InIndex = ReadNum();
 291.429 +    bp.OutIndex = ReadNum();
 291.430 +    folder.BindPairs.Add(bp);
 291.431 +  }
 291.432 +
 291.433 +  if (numInStreams < numBindPairs)
 291.434 +    ThrowUnsupported();
 291.435 +  CNum numPackStreams = numInStreams - numBindPairs;
 291.436 +  folder.PackStreams.Reserve(numPackStreams);
 291.437 +  if (numPackStreams == 1)
 291.438 +  {
 291.439 +    for (i = 0; i < numInStreams; i++)
 291.440 +      if (folder.FindBindPairForInStream(i) < 0)
 291.441 +      {
 291.442 +        folder.PackStreams.Add(i);
 291.443 +        break;
 291.444 +      }
 291.445 +    if (folder.PackStreams.Size() != 1)
 291.446 +      ThrowUnsupported();
 291.447 +  }
 291.448 +  else
 291.449 +    for (i = 0; i < numPackStreams; i++)
 291.450 +      folder.PackStreams.Add(ReadNum());
 291.451 +}
 291.452 +
 291.453 +void CInArchive::WaitAttribute(UInt64 attribute)
 291.454 +{
 291.455 +  for (;;)
 291.456 +  {
 291.457 +    UInt64 type = ReadID();
 291.458 +    if (type == attribute)
 291.459 +      return;
 291.460 +    if (type == NID::kEnd)
 291.461 +      ThrowIncorrect();
 291.462 +    SkeepData();
 291.463 +  }
 291.464 +}
 291.465 +
 291.466 +void CInArchive::ReadHashDigests(int numItems,
 291.467 +    CBoolVector &digestsDefined,
 291.468 +    CRecordVector<UInt32> &digests)
 291.469 +{
 291.470 +  ReadBoolVector2(numItems, digestsDefined);
 291.471 +  digests.Clear();
 291.472 +  digests.Reserve(numItems);
 291.473 +  for (int i = 0; i < numItems; i++)
 291.474 +  {
 291.475 +    UInt32 crc = 0;
 291.476 +    if (digestsDefined[i])
 291.477 +      crc = ReadUInt32();
 291.478 +    digests.Add(crc);
 291.479 +  }
 291.480 +}
 291.481 +
 291.482 +void CInArchive::ReadPackInfo(
 291.483 +    UInt64 &dataOffset,
 291.484 +    CRecordVector<UInt64> &packSizes,
 291.485 +    CBoolVector &packCRCsDefined,
 291.486 +    CRecordVector<UInt32> &packCRCs)
 291.487 +{
 291.488 +  dataOffset = ReadNumber();
 291.489 +  CNum numPackStreams = ReadNum();
 291.490 +
 291.491 +  WaitAttribute(NID::kSize);
 291.492 +  packSizes.Clear();
 291.493 +  packSizes.Reserve(numPackStreams);
 291.494 +  for (CNum i = 0; i < numPackStreams; i++)
 291.495 +    packSizes.Add(ReadNumber());
 291.496 +
 291.497 +  UInt64 type;
 291.498 +  for (;;)
 291.499 +  {
 291.500 +    type = ReadID();
 291.501 +    if (type == NID::kEnd)
 291.502 +      break;
 291.503 +    if (type == NID::kCRC)
 291.504 +    {
 291.505 +      ReadHashDigests(numPackStreams, packCRCsDefined, packCRCs);
 291.506 +      continue;
 291.507 +    }
 291.508 +    SkeepData();
 291.509 +  }
 291.510 +  if (packCRCsDefined.IsEmpty())
 291.511 +  {
 291.512 +    BoolVector_Fill_False(packCRCsDefined, numPackStreams);
 291.513 +    packCRCs.Reserve(numPackStreams);
 291.514 +    packCRCs.Clear();
 291.515 +    for (CNum i = 0; i < numPackStreams; i++)
 291.516 +      packCRCs.Add(0);
 291.517 +  }
 291.518 +}
 291.519 +
 291.520 +void CInArchive::ReadUnpackInfo(
 291.521 +    const CObjectVector<CByteBuffer> *dataVector,
 291.522 +    CObjectVector<CFolder> &folders)
 291.523 +{
 291.524 +  WaitAttribute(NID::kFolder);
 291.525 +  CNum numFolders = ReadNum();
 291.526 +
 291.527 +  {
 291.528 +    CStreamSwitch streamSwitch;
 291.529 +    streamSwitch.Set(this, dataVector);
 291.530 +    folders.Clear();
 291.531 +    folders.Reserve(numFolders);
 291.532 +    for (CNum i = 0; i < numFolders; i++)
 291.533 +    {
 291.534 +      folders.Add(CFolder());
 291.535 +      GetNextFolderItem(folders.Back());
 291.536 +    }
 291.537 +  }
 291.538 +
 291.539 +  WaitAttribute(NID::kCodersUnpackSize);
 291.540 +
 291.541 +  CNum i;
 291.542 +  for (i = 0; i < numFolders; i++)
 291.543 +  {
 291.544 +    CFolder &folder = folders[i];
 291.545 +    CNum numOutStreams = folder.GetNumOutStreams();
 291.546 +    folder.UnpackSizes.Reserve(numOutStreams);
 291.547 +    for (CNum j = 0; j < numOutStreams; j++)
 291.548 +      folder.UnpackSizes.Add(ReadNumber());
 291.549 +  }
 291.550 +
 291.551 +  for (;;)
 291.552 +  {
 291.553 +    UInt64 type = ReadID();
 291.554 +    if (type == NID::kEnd)
 291.555 +      return;
 291.556 +    if (type == NID::kCRC)
 291.557 +    {
 291.558 +      CBoolVector crcsDefined;
 291.559 +      CRecordVector<UInt32> crcs;
 291.560 +      ReadHashDigests(numFolders, crcsDefined, crcs);
 291.561 +      for (i = 0; i < numFolders; i++)
 291.562 +      {
 291.563 +        CFolder &folder = folders[i];
 291.564 +        folder.UnpackCRCDefined = crcsDefined[i];
 291.565 +        folder.UnpackCRC = crcs[i];
 291.566 +      }
 291.567 +      continue;
 291.568 +    }
 291.569 +    SkeepData();
 291.570 +  }
 291.571 +}
 291.572 +
 291.573 +void CInArchive::ReadSubStreamsInfo(
 291.574 +    const CObjectVector<CFolder> &folders,
 291.575 +    CRecordVector<CNum> &numUnpackStreamsInFolders,
 291.576 +    CRecordVector<UInt64> &unpackSizes,
 291.577 +    CBoolVector &digestsDefined,
 291.578 +    CRecordVector<UInt32> &digests)
 291.579 +{
 291.580 +  numUnpackStreamsInFolders.Clear();
 291.581 +  numUnpackStreamsInFolders.Reserve(folders.Size());
 291.582 +  UInt64 type;
 291.583 +  for (;;)
 291.584 +  {
 291.585 +    type = ReadID();
 291.586 +    if (type == NID::kNumUnpackStream)
 291.587 +    {
 291.588 +      for (int i = 0; i < folders.Size(); i++)
 291.589 +        numUnpackStreamsInFolders.Add(ReadNum());
 291.590 +      continue;
 291.591 +    }
 291.592 +    if (type == NID::kCRC || type == NID::kSize)
 291.593 +      break;
 291.594 +    if (type == NID::kEnd)
 291.595 +      break;
 291.596 +    SkeepData();
 291.597 +  }
 291.598 +
 291.599 +  if (numUnpackStreamsInFolders.IsEmpty())
 291.600 +    for (int i = 0; i < folders.Size(); i++)
 291.601 +      numUnpackStreamsInFolders.Add(1);
 291.602 +
 291.603 +  int i;
 291.604 +  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)
 291.605 +  {
 291.606 +    // v3.13 incorrectly worked with empty folders
 291.607 +    // v4.07: we check that folder is empty
 291.608 +    CNum numSubstreams = numUnpackStreamsInFolders[i];
 291.609 +    if (numSubstreams == 0)
 291.610 +      continue;
 291.611 +    UInt64 sum = 0;
 291.612 +    for (CNum j = 1; j < numSubstreams; j++)
 291.613 +      if (type == NID::kSize)
 291.614 +      {
 291.615 +        UInt64 size = ReadNumber();
 291.616 +        unpackSizes.Add(size);
 291.617 +        sum += size;
 291.618 +      }
 291.619 +    unpackSizes.Add(folders[i].GetUnpackSize() - sum);
 291.620 +  }
 291.621 +  if (type == NID::kSize)
 291.622 +    type = ReadID();
 291.623 +
 291.624 +  int numDigests = 0;
 291.625 +  int numDigestsTotal = 0;
 291.626 +  for (i = 0; i < folders.Size(); i++)
 291.627 +  {
 291.628 +    CNum numSubstreams = numUnpackStreamsInFolders[i];
 291.629 +    if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)
 291.630 +      numDigests += numSubstreams;
 291.631 +    numDigestsTotal += numSubstreams;
 291.632 +  }
 291.633 +
 291.634 +  for (;;)
 291.635 +  {
 291.636 +    if (type == NID::kCRC)
 291.637 +    {
 291.638 +      CBoolVector digestsDefined2;
 291.639 +      CRecordVector<UInt32> digests2;
 291.640 +      ReadHashDigests(numDigests, digestsDefined2, digests2);
 291.641 +      int digestIndex = 0;
 291.642 +      for (i = 0; i < folders.Size(); i++)
 291.643 +      {
 291.644 +        CNum numSubstreams = numUnpackStreamsInFolders[i];
 291.645 +        const CFolder &folder = folders[i];
 291.646 +        if (numSubstreams == 1 && folder.UnpackCRCDefined)
 291.647 +        {
 291.648 +          digestsDefined.Add(true);
 291.649 +          digests.Add(folder.UnpackCRC);
 291.650 +        }
 291.651 +        else
 291.652 +          for (CNum j = 0; j < numSubstreams; j++, digestIndex++)
 291.653 +          {
 291.654 +            digestsDefined.Add(digestsDefined2[digestIndex]);
 291.655 +            digests.Add(digests2[digestIndex]);
 291.656 +          }
 291.657 +      }
 291.658 +    }
 291.659 +    else if (type == NID::kEnd)
 291.660 +    {
 291.661 +      if (digestsDefined.IsEmpty())
 291.662 +      {
 291.663 +        BoolVector_Fill_False(digestsDefined, numDigestsTotal);
 291.664 +        digests.Clear();
 291.665 +        for (int i = 0; i < numDigestsTotal; i++)
 291.666 +          digests.Add(0);
 291.667 +      }
 291.668 +      return;
 291.669 +    }
 291.670 +    else
 291.671 +      SkeepData();
 291.672 +    type = ReadID();
 291.673 +  }
 291.674 +}
 291.675 +
 291.676 +void CInArchive::ReadStreamsInfo(
 291.677 +    const CObjectVector<CByteBuffer> *dataVector,
 291.678 +    UInt64 &dataOffset,
 291.679 +    CRecordVector<UInt64> &packSizes,
 291.680 +    CBoolVector &packCRCsDefined,
 291.681 +    CRecordVector<UInt32> &packCRCs,
 291.682 +    CObjectVector<CFolder> &folders,
 291.683 +    CRecordVector<CNum> &numUnpackStreamsInFolders,
 291.684 +    CRecordVector<UInt64> &unpackSizes,
 291.685 +    CBoolVector &digestsDefined,
 291.686 +    CRecordVector<UInt32> &digests)
 291.687 +{
 291.688 +  for (;;)
 291.689 +  {
 291.690 +    UInt64 type = ReadID();
 291.691 +    if (type > ((UInt32)1 << 30))
 291.692 +      ThrowIncorrect();
 291.693 +    switch((UInt32)type)
 291.694 +    {
 291.695 +      case NID::kEnd:
 291.696 +        return;
 291.697 +      case NID::kPackInfo:
 291.698 +      {
 291.699 +        ReadPackInfo(dataOffset, packSizes, packCRCsDefined, packCRCs);
 291.700 +        break;
 291.701 +      }
 291.702 +      case NID::kUnpackInfo:
 291.703 +      {
 291.704 +        ReadUnpackInfo(dataVector, folders);
 291.705 +        break;
 291.706 +      }
 291.707 +      case NID::kSubStreamsInfo:
 291.708 +      {
 291.709 +        ReadSubStreamsInfo(folders, numUnpackStreamsInFolders,
 291.710 +            unpackSizes, digestsDefined, digests);
 291.711 +        break;
 291.712 +      }
 291.713 +      default:
 291.714 +        ThrowIncorrect();
 291.715 +    }
 291.716 +  }
 291.717 +}
 291.718 +
 291.719 +void CInArchive::ReadBoolVector(int numItems, CBoolVector &v)
 291.720 +{
 291.721 +  v.Clear();
 291.722 +  v.Reserve(numItems);
 291.723 +  Byte b = 0;
 291.724 +  Byte mask = 0;
 291.725 +  for (int i = 0; i < numItems; i++)
 291.726 +  {
 291.727 +    if (mask == 0)
 291.728 +    {
 291.729 +      b = ReadByte();
 291.730 +      mask = 0x80;
 291.731 +    }
 291.732 +    v.Add((b & mask) != 0);
 291.733 +    mask >>= 1;
 291.734 +  }
 291.735 +}
 291.736 +
 291.737 +void CInArchive::ReadBoolVector2(int numItems, CBoolVector &v)
 291.738 +{
 291.739 +  Byte allAreDefined = ReadByte();
 291.740 +  if (allAreDefined == 0)
 291.741 +  {
 291.742 +    ReadBoolVector(numItems, v);
 291.743 +    return;
 291.744 +  }
 291.745 +  v.Clear();
 291.746 +  v.Reserve(numItems);
 291.747 +  for (int i = 0; i < numItems; i++)
 291.748 +    v.Add(true);
 291.749 +}
 291.750 +
 291.751 +void CInArchive::ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,
 291.752 +    CUInt64DefVector &v, int numFiles)
 291.753 +{
 291.754 +  ReadBoolVector2(numFiles, v.Defined);
 291.755 +
 291.756 +  CStreamSwitch streamSwitch;
 291.757 +  streamSwitch.Set(this, &dataVector);
 291.758 +  v.Values.Reserve(numFiles);
 291.759 +
 291.760 +  for (int i = 0; i < numFiles; i++)
 291.761 +  {
 291.762 +    UInt64 t = 0;
 291.763 +    if (v.Defined[i])
 291.764 +      t = ReadUInt64();
 291.765 +    v.Values.Add(t);
 291.766 +  }
 291.767 +}
 291.768 +
 291.769 +HRESULT CInArchive::ReadAndDecodePackedStreams(
 291.770 +    DECL_EXTERNAL_CODECS_LOC_VARS
 291.771 +    UInt64 baseOffset,
 291.772 +    UInt64 &dataOffset, CObjectVector<CByteBuffer> &dataVector
 291.773 +    #ifndef _NO_CRYPTO
 291.774 +    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
 291.775 +    #endif
 291.776 +    )
 291.777 +{
 291.778 +  CRecordVector<UInt64> packSizes;
 291.779 +  CBoolVector packCRCsDefined;
 291.780 +  CRecordVector<UInt32> packCRCs;
 291.781 +  CObjectVector<CFolder> folders;
 291.782 +  
 291.783 +  CRecordVector<CNum> numUnpackStreamsInFolders;
 291.784 +  CRecordVector<UInt64> unpackSizes;
 291.785 +  CBoolVector digestsDefined;
 291.786 +  CRecordVector<UInt32> digests;
 291.787 +  
 291.788 +  ReadStreamsInfo(NULL,
 291.789 +    dataOffset,
 291.790 +    packSizes,
 291.791 +    packCRCsDefined,
 291.792 +    packCRCs,
 291.793 +    folders,
 291.794 +    numUnpackStreamsInFolders,
 291.795 +    unpackSizes,
 291.796 +    digestsDefined,
 291.797 +    digests);
 291.798 +  
 291.799 +  // db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;
 291.800 +  
 291.801 +  CNum packIndex = 0;
 291.802 +  CDecoder decoder(
 291.803 +    #ifdef _ST_MODE
 291.804 +    false
 291.805 +    #else
 291.806 +    true
 291.807 +    #endif
 291.808 +    );
 291.809 +  UInt64 dataStartPos = baseOffset + dataOffset;
 291.810 +  for (int i = 0; i < folders.Size(); i++)
 291.811 +  {
 291.812 +    const CFolder &folder = folders[i];
 291.813 +    dataVector.Add(CByteBuffer());
 291.814 +    CByteBuffer &data = dataVector.Back();
 291.815 +    UInt64 unpackSize64 = folder.GetUnpackSize();
 291.816 +    size_t unpackSize = (size_t)unpackSize64;
 291.817 +    if (unpackSize != unpackSize64)
 291.818 +      ThrowUnsupported();
 291.819 +    data.SetCapacity(unpackSize);
 291.820 +    
 291.821 +    CSequentialOutStreamImp2 *outStreamSpec = new CSequentialOutStreamImp2;
 291.822 +    CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
 291.823 +    outStreamSpec->Init(data, unpackSize);
 291.824 +    
 291.825 +    HRESULT result = decoder.Decode(
 291.826 +      EXTERNAL_CODECS_LOC_VARS
 291.827 +      _stream, dataStartPos,
 291.828 +      &packSizes[packIndex], folder, outStream, NULL
 291.829 +      #ifndef _NO_CRYPTO
 291.830 +      , getTextPassword, passwordIsDefined
 291.831 +      #endif
 291.832 +      #ifdef COMPRESS_MT
 291.833 +      , false, 1
 291.834 +      #endif
 291.835 +      );
 291.836 +    RINOK(result);
 291.837 +    
 291.838 +    if (folder.UnpackCRCDefined)
 291.839 +      if (CrcCalc(data, unpackSize) != folder.UnpackCRC)
 291.840 +        ThrowIncorrect();
 291.841 +    for (int j = 0; j < folder.PackStreams.Size(); j++)
 291.842 +    {
 291.843 +      UInt64 packSize = packSizes[packIndex++];
 291.844 +      dataStartPos += packSize;
 291.845 +      HeadersSize += packSize;
 291.846 +    }
 291.847 +  }
 291.848 +  return S_OK;
 291.849 +}
 291.850 +
 291.851 +HRESULT CInArchive::ReadHeader(
 291.852 +    DECL_EXTERNAL_CODECS_LOC_VARS
 291.853 +    CArchiveDatabaseEx &db
 291.854 +    #ifndef _NO_CRYPTO
 291.855 +    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
 291.856 +    #endif
 291.857 +    )
 291.858 +{
 291.859 +  UInt64 type = ReadID();
 291.860 +
 291.861 +  if (type == NID::kArchiveProperties)
 291.862 +  {
 291.863 +    ReadArchiveProperties(db.ArchiveInfo);
 291.864 +    type = ReadID();
 291.865 +  }
 291.866 + 
 291.867 +  CObjectVector<CByteBuffer> dataVector;
 291.868 +  
 291.869 +  if (type == NID::kAdditionalStreamsInfo)
 291.870 +  {
 291.871 +    HRESULT result = ReadAndDecodePackedStreams(
 291.872 +        EXTERNAL_CODECS_LOC_VARS
 291.873 +        db.ArchiveInfo.StartPositionAfterHeader,
 291.874 +        db.ArchiveInfo.DataStartPosition2,
 291.875 +        dataVector
 291.876 +        #ifndef _NO_CRYPTO
 291.877 +        , getTextPassword, passwordIsDefined
 291.878 +        #endif
 291.879 +        );
 291.880 +    RINOK(result);
 291.881 +    db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;
 291.882 +    type = ReadID();
 291.883 +  }
 291.884 +
 291.885 +  CRecordVector<UInt64> unpackSizes;
 291.886 +  CBoolVector digestsDefined;
 291.887 +  CRecordVector<UInt32> digests;
 291.888 +  
 291.889 +  if (type == NID::kMainStreamsInfo)
 291.890 +  {
 291.891 +    ReadStreamsInfo(&dataVector,
 291.892 +        db.ArchiveInfo.DataStartPosition,
 291.893 +        db.PackSizes,
 291.894 +        db.PackCRCsDefined,
 291.895 +        db.PackCRCs,
 291.896 +        db.Folders,
 291.897 +        db.NumUnpackStreamsVector,
 291.898 +        unpackSizes,
 291.899 +        digestsDefined,
 291.900 +        digests);
 291.901 +    db.ArchiveInfo.DataStartPosition += db.ArchiveInfo.StartPositionAfterHeader;
 291.902 +    type = ReadID();
 291.903 +  }
 291.904 +  else
 291.905 +  {
 291.906 +    for (int i = 0; i < db.Folders.Size(); i++)
 291.907 +    {
 291.908 +      db.NumUnpackStreamsVector.Add(1);
 291.909 +      CFolder &folder = db.Folders[i];
 291.910 +      unpackSizes.Add(folder.GetUnpackSize());
 291.911 +      digestsDefined.Add(folder.UnpackCRCDefined);
 291.912 +      digests.Add(folder.UnpackCRC);
 291.913 +    }
 291.914 +  }
 291.915 +
 291.916 +  db.Files.Clear();
 291.917 +
 291.918 +  if (type == NID::kEnd)
 291.919 +    return S_OK;
 291.920 +  if (type != NID::kFilesInfo)
 291.921 +    ThrowIncorrect();
 291.922 +  
 291.923 +  CNum numFiles = ReadNum();
 291.924 +  db.Files.Reserve(numFiles);
 291.925 +  CNum i;
 291.926 +  for (i = 0; i < numFiles; i++)
 291.927 +    db.Files.Add(CFileItem());
 291.928 +
 291.929 +  db.ArchiveInfo.FileInfoPopIDs.Add(NID::kSize);
 291.930 +  if (!db.PackSizes.IsEmpty())
 291.931 +    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kPackInfo);
 291.932 +  if (numFiles > 0  && !digests.IsEmpty())
 291.933 +    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kCRC);
 291.934 +
 291.935 +  CBoolVector emptyStreamVector;
 291.936 +  BoolVector_Fill_False(emptyStreamVector, (int)numFiles);
 291.937 +  CBoolVector emptyFileVector;
 291.938 +  CBoolVector antiFileVector;
 291.939 +  CNum numEmptyStreams = 0;
 291.940 +
 291.941 +  for (;;)
 291.942 +  {
 291.943 +    UInt64 type = ReadID();
 291.944 +    if (type == NID::kEnd)
 291.945 +      break;
 291.946 +    UInt64 size = ReadNumber();
 291.947 +    size_t ppp = _inByteBack->_pos;
 291.948 +    bool addPropIdToList = true;
 291.949 +    bool isKnownType = true;
 291.950 +    if (type > ((UInt32)1 << 30))
 291.951 +      isKnownType = false;
 291.952 +    else switch((UInt32)type)
 291.953 +    {
 291.954 +      case NID::kName:
 291.955 +      {
 291.956 +        CStreamSwitch streamSwitch;
 291.957 +        streamSwitch.Set(this, &dataVector);
 291.958 +        for (int i = 0; i < db.Files.Size(); i++)
 291.959 +          _inByteBack->ReadString(db.Files[i].Name);
 291.960 +        break;
 291.961 +      }
 291.962 +      case NID::kWinAttributes:
 291.963 +      {
 291.964 +        CBoolVector boolVector;
 291.965 +        ReadBoolVector2(db.Files.Size(), boolVector);
 291.966 +        CStreamSwitch streamSwitch;
 291.967 +        streamSwitch.Set(this, &dataVector);
 291.968 +        for (i = 0; i < numFiles; i++)
 291.969 +        {
 291.970 +          CFileItem &file = db.Files[i];
 291.971 +          file.AttribDefined = boolVector[i];
 291.972 +          if (file.AttribDefined)
 291.973 +            file.Attrib = ReadUInt32();
 291.974 +        }
 291.975 +        break;
 291.976 +      }
 291.977 +      case NID::kEmptyStream:
 291.978 +      {
 291.979 +        ReadBoolVector(numFiles, emptyStreamVector);
 291.980 +        for (i = 0; i < (CNum)emptyStreamVector.Size(); i++)
 291.981 +          if (emptyStreamVector[i])
 291.982 +            numEmptyStreams++;
 291.983 +
 291.984 +        BoolVector_Fill_False(emptyFileVector, numEmptyStreams);
 291.985 +        BoolVector_Fill_False(antiFileVector, numEmptyStreams);
 291.986 +
 291.987 +        break;
 291.988 +      }
 291.989 +      case NID::kEmptyFile:  ReadBoolVector(numEmptyStreams, emptyFileVector); break;
 291.990 +      case NID::kAnti:  ReadBoolVector(numEmptyStreams, antiFileVector); break;
 291.991 +      case NID::kStartPos:  ReadUInt64DefVector(dataVector, db.StartPos, (int)numFiles); break;
 291.992 +      case NID::kCTime:  ReadUInt64DefVector(dataVector, db.CTime, (int)numFiles); break;
 291.993 +      case NID::kATime:  ReadUInt64DefVector(dataVector, db.ATime, (int)numFiles); break;
 291.994 +      case NID::kMTime:  ReadUInt64DefVector(dataVector, db.MTime, (int)numFiles); break;
 291.995 +      case NID::kDummy:
 291.996 +      {
 291.997 +        for (UInt64 j = 0; j < size; j++)
 291.998 +          if (ReadByte() != 0)
 291.999 +            ThrowIncorrect();
291.1000 +        addPropIdToList = false;
291.1001 +        break;
291.1002 +      }
291.1003 +      default:
291.1004 +        addPropIdToList = isKnownType = false;
291.1005 +    }
291.1006 +    if (isKnownType)
291.1007 +    {
291.1008 +      if(addPropIdToList)
291.1009 +        db.ArchiveInfo.FileInfoPopIDs.Add(type);
291.1010 +    }
291.1011 +    else
291.1012 +      SkeepData(size);
291.1013 +    bool checkRecordsSize = (db.ArchiveInfo.Version.Major > 0 ||
291.1014 +        db.ArchiveInfo.Version.Minor > 2);
291.1015 +    if (checkRecordsSize && _inByteBack->_pos - ppp != size)
291.1016 +      ThrowIncorrect();
291.1017 +  }
291.1018 +
291.1019 +  CNum emptyFileIndex = 0;
291.1020 +  CNum sizeIndex = 0;
291.1021 +
291.1022 +  CNum numAntiItems = 0;
291.1023 +  for (i = 0; i < numEmptyStreams; i++)
291.1024 +    if (antiFileVector[i])
291.1025 +      numAntiItems++;
291.1026 +    
291.1027 +  for (i = 0; i < numFiles; i++)
291.1028 +  {
291.1029 +    CFileItem &file = db.Files[i];
291.1030 +    bool isAnti;
291.1031 +    file.HasStream = !emptyStreamVector[i];
291.1032 +    if (file.HasStream)
291.1033 +    {
291.1034 +      file.IsDir = false;
291.1035 +      isAnti = false;
291.1036 +      file.Size = unpackSizes[sizeIndex];
291.1037 +      file.Crc = digests[sizeIndex];
291.1038 +      file.CrcDefined = digestsDefined[sizeIndex];
291.1039 +      sizeIndex++;
291.1040 +    }
291.1041 +    else
291.1042 +    {
291.1043 +      file.IsDir = !emptyFileVector[emptyFileIndex];
291.1044 +      isAnti = antiFileVector[emptyFileIndex];
291.1045 +      emptyFileIndex++;
291.1046 +      file.Size = 0;
291.1047 +      file.CrcDefined = false;
291.1048 +    }
291.1049 +    if (numAntiItems != 0)
291.1050 +      db.IsAnti.Add(isAnti);
291.1051 +  }
291.1052 +  return S_OK;
291.1053 +}
291.1054 +
291.1055 +
291.1056 +void CArchiveDatabaseEx::FillFolderStartPackStream()
291.1057 +{
291.1058 +  FolderStartPackStreamIndex.Clear();
291.1059 +  FolderStartPackStreamIndex.Reserve(Folders.Size());
291.1060 +  CNum startPos = 0;
291.1061 +  for (int i = 0; i < Folders.Size(); i++)
291.1062 +  {
291.1063 +    FolderStartPackStreamIndex.Add(startPos);
291.1064 +    startPos += (CNum)Folders[i].PackStreams.Size();
291.1065 +  }
291.1066 +}
291.1067 +
291.1068 +void CArchiveDatabaseEx::FillStartPos()
291.1069 +{
291.1070 +  PackStreamStartPositions.Clear();
291.1071 +  PackStreamStartPositions.Reserve(PackSizes.Size());
291.1072 +  UInt64 startPos = 0;
291.1073 +  for (int i = 0; i < PackSizes.Size(); i++)
291.1074 +  {
291.1075 +    PackStreamStartPositions.Add(startPos);
291.1076 +    startPos += PackSizes[i];
291.1077 +  }
291.1078 +}
291.1079 +
291.1080 +void CArchiveDatabaseEx::FillFolderStartFileIndex()
291.1081 +{
291.1082 +  FolderStartFileIndex.Clear();
291.1083 +  FolderStartFileIndex.Reserve(Folders.Size());
291.1084 +  FileIndexToFolderIndexMap.Clear();
291.1085 +  FileIndexToFolderIndexMap.Reserve(Files.Size());
291.1086 +  
291.1087 +  int folderIndex = 0;
291.1088 +  CNum indexInFolder = 0;
291.1089 +  for (int i = 0; i < Files.Size(); i++)
291.1090 +  {
291.1091 +    const CFileItem &file = Files[i];
291.1092 +    bool emptyStream = !file.HasStream;
291.1093 +    if (emptyStream && indexInFolder == 0)
291.1094 +    {
291.1095 +      FileIndexToFolderIndexMap.Add(kNumNoIndex);
291.1096 +      continue;
291.1097 +    }
291.1098 +    if (indexInFolder == 0)
291.1099 +    {
291.1100 +      // v3.13 incorrectly worked with empty folders
291.1101 +      // v4.07: Loop for skipping empty folders
291.1102 +      for (;;)
291.1103 +      {
291.1104 +        if (folderIndex >= Folders.Size())
291.1105 +          ThrowIncorrect();
291.1106 +        FolderStartFileIndex.Add(i); // check it
291.1107 +        if (NumUnpackStreamsVector[folderIndex] != 0)
291.1108 +          break;
291.1109 +        folderIndex++;
291.1110 +      }
291.1111 +    }
291.1112 +    FileIndexToFolderIndexMap.Add(folderIndex);
291.1113 +    if (emptyStream)
291.1114 +      continue;
291.1115 +    indexInFolder++;
291.1116 +    if (indexInFolder >= NumUnpackStreamsVector[folderIndex])
291.1117 +    {
291.1118 +      folderIndex++;
291.1119 +      indexInFolder = 0;
291.1120 +    }
291.1121 +  }
291.1122 +}
291.1123 +
291.1124 +HRESULT CInArchive::ReadDatabase2(
291.1125 +    DECL_EXTERNAL_CODECS_LOC_VARS
291.1126 +    CArchiveDatabaseEx &db
291.1127 +    #ifndef _NO_CRYPTO
291.1128 +    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
291.1129 +    #endif
291.1130 +    )
291.1131 +{
291.1132 +  db.Clear();
291.1133 +  db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;
291.1134 +
291.1135 +  db.ArchiveInfo.Version.Major = _header[6];
291.1136 +  db.ArchiveInfo.Version.Minor = _header[7];
291.1137 +
291.1138 +  if (db.ArchiveInfo.Version.Major != kMajorVersion)
291.1139 +    ThrowUnsupportedVersion();
291.1140 +
291.1141 +  UInt32 crcFromArchive = Get32(_header + 8);
291.1142 +  UInt64 nextHeaderOffset = Get64(_header + 0xC);
291.1143 +  UInt64 nextHeaderSize = Get64(_header + 0x14);
291.1144 +  UInt32 nextHeaderCRC = Get32(_header + 0x1C);
291.1145 +  UInt32 crc = CrcCalc(_header + 0xC, 20);
291.1146 +
291.1147 +  #ifdef FORMAT_7Z_RECOVERY
291.1148 +  if (crcFromArchive == 0 && nextHeaderOffset == 0 && nextHeaderSize == 0 && nextHeaderCRC == 0)
291.1149 +  {
291.1150 +    UInt64 cur, cur2;
291.1151 +    RINOK(_stream->Seek(0, STREAM_SEEK_CUR, &cur));
291.1152 +    const int kCheckSize = 500;
291.1153 +    Byte buf[kCheckSize];
291.1154 +    RINOK(_stream->Seek(0, STREAM_SEEK_END, &cur2));
291.1155 +    int checkSize = kCheckSize;
291.1156 +    if (cur2 - cur < kCheckSize)
291.1157 +      checkSize = (int)(cur2 - cur);
291.1158 +    RINOK(_stream->Seek(-checkSize, STREAM_SEEK_END, &cur2));
291.1159 +    
291.1160 +    RINOK(ReadStream_FALSE(_stream, buf, (size_t)checkSize));
291.1161 +
291.1162 +    int i;
291.1163 +    for (i = (int)checkSize - 2; i >= 0; i--)
291.1164 +      if (buf[i] == 0x17 && buf[i + 1] == 0x6 || buf[i] == 0x01 && buf[i + 1] == 0x04)
291.1165 +        break;
291.1166 +    if (i < 0)
291.1167 +      return S_FALSE;
291.1168 +    nextHeaderSize = checkSize - i;
291.1169 +    nextHeaderOffset = cur2 - cur + i;
291.1170 +    nextHeaderCRC = CrcCalc(buf + i, (size_t)nextHeaderSize);
291.1171 +    RINOK(_stream->Seek(cur, STREAM_SEEK_SET, NULL));
291.1172 +  }
291.1173 +  #endif
291.1174 +
291.1175 +  #ifdef FORMAT_7Z_RECOVERY
291.1176 +  crcFromArchive = crc;
291.1177 +  #endif
291.1178 +
291.1179 +  db.ArchiveInfo.StartPositionAfterHeader = _arhiveBeginStreamPosition + kHeaderSize;
291.1180 +
291.1181 +  if (crc != crcFromArchive)
291.1182 +    ThrowIncorrect();
291.1183 +
291.1184 +  if (nextHeaderSize == 0)
291.1185 +    return S_OK;
291.1186 +
291.1187 +  if (nextHeaderSize > (UInt64)0xFFFFFFFF)
291.1188 +    return S_FALSE;
291.1189 +
291.1190 +  RINOK(_stream->Seek(nextHeaderOffset, STREAM_SEEK_CUR, NULL));
291.1191 +
291.1192 +  CByteBuffer buffer2;
291.1193 +  buffer2.SetCapacity((size_t)nextHeaderSize);
291.1194 +
291.1195 +  RINOK(ReadStream_FALSE(_stream, buffer2, (size_t)nextHeaderSize));
291.1196 +  HeadersSize += kHeaderSize + nextHeaderSize;
291.1197 +  db.PhySize = kHeaderSize + nextHeaderOffset + nextHeaderSize;
291.1198 +
291.1199 +  if (CrcCalc(buffer2, (UInt32)nextHeaderSize) != nextHeaderCRC)
291.1200 +    ThrowIncorrect();
291.1201 +  
291.1202 +  CStreamSwitch streamSwitch;
291.1203 +  streamSwitch.Set(this, buffer2);
291.1204 +  
291.1205 +  CObjectVector<CByteBuffer> dataVector;
291.1206 +  
291.1207 +  UInt64 type = ReadID();
291.1208 +  if (type != NID::kHeader)
291.1209 +  {
291.1210 +    if (type != NID::kEncodedHeader)
291.1211 +      ThrowIncorrect();
291.1212 +    HRESULT result = ReadAndDecodePackedStreams(
291.1213 +        EXTERNAL_CODECS_LOC_VARS
291.1214 +        db.ArchiveInfo.StartPositionAfterHeader,
291.1215 +        db.ArchiveInfo.DataStartPosition2,
291.1216 +        dataVector
291.1217 +        #ifndef _NO_CRYPTO
291.1218 +        , getTextPassword, passwordIsDefined
291.1219 +        #endif
291.1220 +        );
291.1221 +    RINOK(result);
291.1222 +    if (dataVector.Size() == 0)
291.1223 +      return S_OK;
291.1224 +    if (dataVector.Size() > 1)
291.1225 +      ThrowIncorrect();
291.1226 +    streamSwitch.Remove();
291.1227 +    streamSwitch.Set(this, dataVector.Front());
291.1228 +    if (ReadID() != NID::kHeader)
291.1229 +      ThrowIncorrect();
291.1230 +  }
291.1231 +
291.1232 +  db.HeadersSize = HeadersSize;
291.1233 +
291.1234 +  return ReadHeader(
291.1235 +    EXTERNAL_CODECS_LOC_VARS
291.1236 +    db
291.1237 +    #ifndef _NO_CRYPTO
291.1238 +    , getTextPassword, passwordIsDefined
291.1239 +    #endif
291.1240 +    );
291.1241 +}
291.1242 +
291.1243 +HRESULT CInArchive::ReadDatabase(
291.1244 +    DECL_EXTERNAL_CODECS_LOC_VARS
291.1245 +    CArchiveDatabaseEx &db
291.1246 +    #ifndef _NO_CRYPTO
291.1247 +    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
291.1248 +    #endif
291.1249 +    )
291.1250 +{
291.1251 +  try
291.1252 +  {
291.1253 +    return ReadDatabase2(
291.1254 +      EXTERNAL_CODECS_LOC_VARS db
291.1255 +      #ifndef _NO_CRYPTO
291.1256 +      , getTextPassword, passwordIsDefined
291.1257 +      #endif
291.1258 +      );
291.1259 +  }
291.1260 +  catch(CInArchiveException &) { return S_FALSE; }
291.1261 +}
291.1262 +
291.1263 +}}
   292.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   292.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zIn.h	Sat Mar 03 10:31:27 2012 -0600
   292.3 @@ -0,0 +1,245 @@
   292.4 +// 7zIn.h
   292.5 +
   292.6 +#ifndef __7Z_IN_H
   292.7 +#define __7Z_IN_H
   292.8 +
   292.9 +#include "../../../Common/MyCom.h"
  292.10 +
  292.11 +#include "../../IPassword.h"
  292.12 +#include "../../IStream.h"
  292.13 +
  292.14 +#include "../../Common/CreateCoder.h"
  292.15 +#include "../../Common/InBuffer.h"
  292.16 +
  292.17 +#include "7zItem.h"
  292.18 + 
  292.19 +namespace NArchive {
  292.20 +namespace N7z {
  292.21 +  
  292.22 +struct CInArchiveInfo
  292.23 +{
  292.24 +  CArchiveVersion Version;
  292.25 +  UInt64 StartPosition;
  292.26 +  UInt64 StartPositionAfterHeader;
  292.27 +  UInt64 DataStartPosition;
  292.28 +  UInt64 DataStartPosition2;
  292.29 +  CRecordVector<UInt64> FileInfoPopIDs;
  292.30 +  void Clear()
  292.31 +  {
  292.32 +    FileInfoPopIDs.Clear();
  292.33 +  }
  292.34 +};
  292.35 +
  292.36 +struct CArchiveDatabaseEx: public CArchiveDatabase
  292.37 +{
  292.38 +  CInArchiveInfo ArchiveInfo;
  292.39 +  CRecordVector<UInt64> PackStreamStartPositions;
  292.40 +  CRecordVector<CNum> FolderStartPackStreamIndex;
  292.41 +  CRecordVector<CNum> FolderStartFileIndex;
  292.42 +  CRecordVector<CNum> FileIndexToFolderIndexMap;
  292.43 +
  292.44 +  UInt64 HeadersSize;
  292.45 +  UInt64 PhySize;
  292.46 +
  292.47 +  void Clear()
  292.48 +  {
  292.49 +    CArchiveDatabase::Clear();
  292.50 +    ArchiveInfo.Clear();
  292.51 +    PackStreamStartPositions.Clear();
  292.52 +    FolderStartPackStreamIndex.Clear();
  292.53 +    FolderStartFileIndex.Clear();
  292.54 +    FileIndexToFolderIndexMap.Clear();
  292.55 +
  292.56 +    HeadersSize = 0;
  292.57 +    PhySize = 0;
  292.58 +  }
  292.59 +
  292.60 +  void FillFolderStartPackStream();
  292.61 +  void FillStartPos();
  292.62 +  void FillFolderStartFileIndex();
  292.63 +
  292.64 +  void Fill()
  292.65 +  {
  292.66 +    FillFolderStartPackStream();
  292.67 +    FillStartPos();
  292.68 +    FillFolderStartFileIndex();
  292.69 +  }
  292.70 +  
  292.71 +  UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const
  292.72 +  {
  292.73 +    return ArchiveInfo.DataStartPosition +
  292.74 +        PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] + indexInFolder];
  292.75 +  }
  292.76 +  
  292.77 +  UInt64 GetFolderFullPackSize(int folderIndex) const
  292.78 +  {
  292.79 +    CNum packStreamIndex = FolderStartPackStreamIndex[folderIndex];
  292.80 +    const CFolder &folder = Folders[folderIndex];
  292.81 +    UInt64 size = 0;
  292.82 +    for (int i = 0; i < folder.PackStreams.Size(); i++)
  292.83 +      size += PackSizes[packStreamIndex + i];
  292.84 +    return size;
  292.85 +  }
  292.86 +  
  292.87 +  UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const
  292.88 +  {
  292.89 +    return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];
  292.90 +  }
  292.91 +
  292.92 +  UInt64 GetFilePackSize(CNum fileIndex) const
  292.93 +  {
  292.94 +    CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];
  292.95 +    if (folderIndex != kNumNoIndex)
  292.96 +      if (FolderStartFileIndex[folderIndex] == fileIndex)
  292.97 +        return GetFolderFullPackSize(folderIndex);
  292.98 +    return 0;
  292.99 +  }
 292.100 +};
 292.101 +
 292.102 +class CInByte2
 292.103 +{
 292.104 +  const Byte *_buffer;
 292.105 +  size_t _size;
 292.106 +public:
 292.107 +  size_t _pos;
 292.108 +  void Init(const Byte *buffer, size_t size)
 292.109 +  {
 292.110 +    _buffer = buffer;
 292.111 +    _size = size;
 292.112 +    _pos = 0;
 292.113 +  }
 292.114 +  Byte ReadByte();
 292.115 +  void ReadBytes(Byte *data, size_t size);
 292.116 +  void SkeepData(UInt64 size);
 292.117 +  void SkeepData();
 292.118 +  UInt64 ReadNumber();
 292.119 +  CNum ReadNum();
 292.120 +  UInt32 ReadUInt32();
 292.121 +  UInt64 ReadUInt64();
 292.122 +  void ReadString(UString &s);
 292.123 +};
 292.124 +
 292.125 +class CStreamSwitch;
 292.126 +
 292.127 +const UInt32 kHeaderSize = 32;
 292.128 +
 292.129 +class CInArchive
 292.130 +{
 292.131 +  friend class CStreamSwitch;
 292.132 +
 292.133 +  CMyComPtr<IInStream> _stream;
 292.134 +
 292.135 +  CObjectVector<CInByte2> _inByteVector;
 292.136 +  CInByte2 *_inByteBack;
 292.137 + 
 292.138 +  UInt64 _arhiveBeginStreamPosition;
 292.139 +
 292.140 +  Byte _header[kHeaderSize];
 292.141 +
 292.142 +  UInt64 HeadersSize;
 292.143 +
 292.144 +  void AddByteStream(const Byte *buffer, size_t size)
 292.145 +  {
 292.146 +    _inByteVector.Add(CInByte2());
 292.147 +    _inByteBack = &_inByteVector.Back();
 292.148 +    _inByteBack->Init(buffer, size);
 292.149 +  }
 292.150 +  
 292.151 +  void DeleteByteStream()
 292.152 +  {
 292.153 +    _inByteVector.DeleteBack();
 292.154 +    if (!_inByteVector.IsEmpty())
 292.155 +      _inByteBack = &_inByteVector.Back();
 292.156 +  }
 292.157 +
 292.158 +private:
 292.159 +  HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
 292.160 +  
 292.161 +  void ReadBytes(Byte *data, size_t size) { _inByteBack->ReadBytes(data, size); }
 292.162 +  Byte ReadByte() { return _inByteBack->ReadByte(); }
 292.163 +  UInt64 ReadNumber() { return _inByteBack->ReadNumber(); }
 292.164 +  CNum ReadNum() { return _inByteBack->ReadNum(); }
 292.165 +  UInt64 ReadID() { return _inByteBack->ReadNumber(); }
 292.166 +  UInt32 ReadUInt32() { return _inByteBack->ReadUInt32(); }
 292.167 +  UInt64 ReadUInt64() { return _inByteBack->ReadUInt64(); }
 292.168 +  void SkeepData(UInt64 size) { _inByteBack->SkeepData(size); }
 292.169 +  void SkeepData() { _inByteBack->SkeepData(); }
 292.170 +  void WaitAttribute(UInt64 attribute);
 292.171 +
 292.172 +  void ReadArchiveProperties(CInArchiveInfo &archiveInfo);
 292.173 +  void GetNextFolderItem(CFolder &itemInfo);
 292.174 +  void ReadHashDigests(int numItems,
 292.175 +      CBoolVector &digestsDefined, CRecordVector<UInt32> &digests);
 292.176 +  
 292.177 +  void ReadPackInfo(
 292.178 +      UInt64 &dataOffset,
 292.179 +      CRecordVector<UInt64> &packSizes,
 292.180 +      CBoolVector &packCRCsDefined,
 292.181 +      CRecordVector<UInt32> &packCRCs);
 292.182 +  
 292.183 +  void ReadUnpackInfo(
 292.184 +      const CObjectVector<CByteBuffer> *dataVector,
 292.185 +      CObjectVector<CFolder> &folders);
 292.186 +  
 292.187 +  void ReadSubStreamsInfo(
 292.188 +      const CObjectVector<CFolder> &folders,
 292.189 +      CRecordVector<CNum> &numUnpackStreamsInFolders,
 292.190 +      CRecordVector<UInt64> &unpackSizes,
 292.191 +      CBoolVector &digestsDefined,
 292.192 +      CRecordVector<UInt32> &digests);
 292.193 +
 292.194 +  void ReadStreamsInfo(
 292.195 +      const CObjectVector<CByteBuffer> *dataVector,
 292.196 +      UInt64 &dataOffset,
 292.197 +      CRecordVector<UInt64> &packSizes,
 292.198 +      CBoolVector &packCRCsDefined,
 292.199 +      CRecordVector<UInt32> &packCRCs,
 292.200 +      CObjectVector<CFolder> &folders,
 292.201 +      CRecordVector<CNum> &numUnpackStreamsInFolders,
 292.202 +      CRecordVector<UInt64> &unpackSizes,
 292.203 +      CBoolVector &digestsDefined,
 292.204 +      CRecordVector<UInt32> &digests);
 292.205 +
 292.206 +
 292.207 +  void ReadBoolVector(int numItems, CBoolVector &v);
 292.208 +  void ReadBoolVector2(int numItems, CBoolVector &v);
 292.209 +  void ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,
 292.210 +      CUInt64DefVector &v, int numFiles);
 292.211 +  HRESULT ReadAndDecodePackedStreams(
 292.212 +      DECL_EXTERNAL_CODECS_LOC_VARS
 292.213 +      UInt64 baseOffset, UInt64 &dataOffset,
 292.214 +      CObjectVector<CByteBuffer> &dataVector
 292.215 +      #ifndef _NO_CRYPTO
 292.216 +      , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
 292.217 +      #endif
 292.218 +      );
 292.219 +  HRESULT ReadHeader(
 292.220 +      DECL_EXTERNAL_CODECS_LOC_VARS
 292.221 +      CArchiveDatabaseEx &db
 292.222 +      #ifndef _NO_CRYPTO
 292.223 +      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
 292.224 +      #endif
 292.225 +      );
 292.226 +  HRESULT ReadDatabase2(
 292.227 +      DECL_EXTERNAL_CODECS_LOC_VARS
 292.228 +      CArchiveDatabaseEx &db
 292.229 +      #ifndef _NO_CRYPTO
 292.230 +      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
 292.231 +      #endif
 292.232 +      );
 292.233 +public:
 292.234 +  HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive
 292.235 +  void Close();
 292.236 +
 292.237 +  HRESULT ReadDatabase(
 292.238 +      DECL_EXTERNAL_CODECS_LOC_VARS
 292.239 +      CArchiveDatabaseEx &db
 292.240 +      #ifndef _NO_CRYPTO
 292.241 +      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
 292.242 +      #endif
 292.243 +      );
 292.244 +};
 292.245 +  
 292.246 +}}
 292.247 +  
 292.248 +#endif
   293.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   293.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zItem.h	Sat Mar 03 10:31:27 2012 -0600
   293.3 @@ -0,0 +1,258 @@
   293.4 +// 7zItem.h
   293.5 +
   293.6 +#ifndef __7Z_ITEM_H
   293.7 +#define __7Z_ITEM_H
   293.8 +
   293.9 +#include "../../../Common/Buffer.h"
  293.10 +#include "../../../Common/MyString.h"
  293.11 +
  293.12 +#include "../../Common/MethodId.h"
  293.13 +
  293.14 +#include "7zHeader.h"
  293.15 +
  293.16 +namespace NArchive {
  293.17 +namespace N7z {
  293.18 +
  293.19 +typedef UInt32 CNum;
  293.20 +const CNum kNumMax     = 0x7FFFFFFF;
  293.21 +const CNum kNumNoIndex = 0xFFFFFFFF;
  293.22 +
  293.23 +struct CCoderInfo
  293.24 +{
  293.25 +  CMethodId MethodID;
  293.26 +  CByteBuffer Props;
  293.27 +  CNum NumInStreams;
  293.28 +  CNum NumOutStreams;
  293.29 +  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }
  293.30 +};
  293.31 +
  293.32 +struct CBindPair
  293.33 +{
  293.34 +  CNum InIndex;
  293.35 +  CNum OutIndex;
  293.36 +};
  293.37 +
  293.38 +struct CFolder
  293.39 +{
  293.40 +  CObjectVector<CCoderInfo> Coders;
  293.41 +  CRecordVector<CBindPair> BindPairs;
  293.42 +  CRecordVector<CNum> PackStreams;
  293.43 +  CRecordVector<UInt64> UnpackSizes;
  293.44 +  UInt32 UnpackCRC;
  293.45 +  bool UnpackCRCDefined;
  293.46 +
  293.47 +  CFolder(): UnpackCRCDefined(false) {}
  293.48 +
  293.49 +  UInt64 GetUnpackSize() const // test it
  293.50 +  {
  293.51 +    if (UnpackSizes.IsEmpty())
  293.52 +      return 0;
  293.53 +    for (int i = UnpackSizes.Size() - 1; i >= 0; i--)
  293.54 +      if (FindBindPairForOutStream(i) < 0)
  293.55 +        return UnpackSizes[i];
  293.56 +    throw 1;
  293.57 +  }
  293.58 +
  293.59 +  CNum GetNumOutStreams() const
  293.60 +  {
  293.61 +    CNum result = 0;
  293.62 +    for (int i = 0; i < Coders.Size(); i++)
  293.63 +      result += Coders[i].NumOutStreams;
  293.64 +    return result;
  293.65 +  }
  293.66 +
  293.67 +  int FindBindPairForInStream(CNum inStreamIndex) const
  293.68 +  {
  293.69 +    for(int i = 0; i < BindPairs.Size(); i++)
  293.70 +      if (BindPairs[i].InIndex == inStreamIndex)
  293.71 +        return i;
  293.72 +    return -1;
  293.73 +  }
  293.74 +  int FindBindPairForOutStream(CNum outStreamIndex) const
  293.75 +  {
  293.76 +    for(int i = 0; i < BindPairs.Size(); i++)
  293.77 +      if (BindPairs[i].OutIndex == outStreamIndex)
  293.78 +        return i;
  293.79 +    return -1;
  293.80 +  }
  293.81 +  int FindPackStreamArrayIndex(CNum inStreamIndex) const
  293.82 +  {
  293.83 +    for(int i = 0; i < PackStreams.Size(); i++)
  293.84 +      if (PackStreams[i] == inStreamIndex)
  293.85 +        return i;
  293.86 +    return -1;
  293.87 +  }
  293.88 +
  293.89 +  bool CheckStructure() const;
  293.90 +};
  293.91 +
  293.92 +struct CUInt64DefVector
  293.93 +{
  293.94 +  CRecordVector<UInt64> Values;
  293.95 +  CRecordVector<bool> Defined;
  293.96 +  
  293.97 +  void Clear()
  293.98 +  {
  293.99 +    Values.Clear();
 293.100 +    Defined.Clear();
 293.101 +  }
 293.102 +  
 293.103 +  void ReserveDown()
 293.104 +  {
 293.105 +    Values.ReserveDown();
 293.106 +    Values.ReserveDown();
 293.107 +  }
 293.108 +
 293.109 +  bool GetItem(int index, UInt64 &value) const
 293.110 +  {
 293.111 +    if (index < Defined.Size() && Defined[index])
 293.112 +    {
 293.113 +      value = Values[index];
 293.114 +      return true;
 293.115 +    }
 293.116 +    value = 0;
 293.117 +    return false;
 293.118 +  }
 293.119 +  
 293.120 +  void SetItem(int index, bool defined, UInt64 value)
 293.121 +  {
 293.122 +    while (index >= Defined.Size())
 293.123 +      Defined.Add(false);
 293.124 +    Defined[index] = defined;
 293.125 +    if (!defined)
 293.126 +      return;
 293.127 +    while (index >= Values.Size())
 293.128 +      Values.Add(0);
 293.129 +    Values[index] = value;
 293.130 +  }
 293.131 +
 293.132 +  bool CheckSize(int size) const { return Defined.Size() == size || Defined.Size() == 0; }
 293.133 +};
 293.134 +
 293.135 +struct CFileItem
 293.136 +{
 293.137 +  UInt64 Size;
 293.138 +  UInt32 Attrib;
 293.139 +  UInt32 Crc;
 293.140 +  UString Name;
 293.141 +
 293.142 +  bool HasStream; // Test it !!! it means that there is
 293.143 +                  // stream in some folder. It can be empty stream
 293.144 +  bool IsDir;
 293.145 +  bool CrcDefined;
 293.146 +  bool AttribDefined;
 293.147 +
 293.148 +  CFileItem():
 293.149 +    HasStream(true),
 293.150 +    IsDir(false),
 293.151 +    CrcDefined(false),
 293.152 +    AttribDefined(false)
 293.153 +      {}
 293.154 +  void SetAttrib(UInt32 attrib)
 293.155 +  {
 293.156 +    AttribDefined = true;
 293.157 +    Attrib = attrib;
 293.158 +  }
 293.159 +};
 293.160 +
 293.161 +struct CFileItem2
 293.162 +{
 293.163 +  UInt64 CTime;
 293.164 +  UInt64 ATime;
 293.165 +  UInt64 MTime;
 293.166 +  UInt64 StartPos;
 293.167 +  bool CTimeDefined;
 293.168 +  bool ATimeDefined;
 293.169 +  bool MTimeDefined;
 293.170 +  bool StartPosDefined;
 293.171 +  bool IsAnti;
 293.172 +};
 293.173 +
 293.174 +struct CArchiveDatabase
 293.175 +{
 293.176 +  CRecordVector<UInt64> PackSizes;
 293.177 +  CRecordVector<bool> PackCRCsDefined;
 293.178 +  CRecordVector<UInt32> PackCRCs;
 293.179 +  CObjectVector<CFolder> Folders;
 293.180 +  CRecordVector<CNum> NumUnpackStreamsVector;
 293.181 +  CObjectVector<CFileItem> Files;
 293.182 +
 293.183 +  CUInt64DefVector CTime;
 293.184 +  CUInt64DefVector ATime;
 293.185 +  CUInt64DefVector MTime;
 293.186 +  CUInt64DefVector StartPos;
 293.187 +  CRecordVector<bool> IsAnti;
 293.188 +
 293.189 +  void Clear()
 293.190 +  {
 293.191 +    PackSizes.Clear();
 293.192 +    PackCRCsDefined.Clear();
 293.193 +    PackCRCs.Clear();
 293.194 +    Folders.Clear();
 293.195 +    NumUnpackStreamsVector.Clear();
 293.196 +    Files.Clear();
 293.197 +    CTime.Clear();
 293.198 +    ATime.Clear();
 293.199 +    MTime.Clear();
 293.200 +    StartPos.Clear();
 293.201 +    IsAnti.Clear();
 293.202 +  }
 293.203 +
 293.204 +  void ReserveDown()
 293.205 +  {
 293.206 +    PackSizes.ReserveDown();
 293.207 +    PackCRCsDefined.ReserveDown();
 293.208 +    PackCRCs.ReserveDown();
 293.209 +    Folders.ReserveDown();
 293.210 +    NumUnpackStreamsVector.ReserveDown();
 293.211 +    Files.ReserveDown();
 293.212 +    CTime.ReserveDown();
 293.213 +    ATime.ReserveDown();
 293.214 +    MTime.ReserveDown();
 293.215 +    StartPos.ReserveDown();
 293.216 +    IsAnti.ReserveDown();
 293.217 +  }
 293.218 +
 293.219 +  bool IsEmpty() const
 293.220 +  {
 293.221 +    return (PackSizes.IsEmpty() &&
 293.222 +      PackCRCsDefined.IsEmpty() &&
 293.223 +      PackCRCs.IsEmpty() &&
 293.224 +      Folders.IsEmpty() &&
 293.225 +      NumUnpackStreamsVector.IsEmpty() &&
 293.226 +      Files.IsEmpty());
 293.227 +  }
 293.228 +
 293.229 +  bool CheckNumFiles() const
 293.230 +  {
 293.231 +    int size = Files.Size();
 293.232 +    return (
 293.233 +      CTime.CheckSize(size) &&
 293.234 +      ATime.CheckSize(size) &&
 293.235 +      MTime.CheckSize(size) &&
 293.236 +      StartPos.CheckSize(size) &&
 293.237 +      (size == IsAnti.Size() || IsAnti.Size() == 0));
 293.238 +  }
 293.239 +
 293.240 +  bool IsSolid() const
 293.241 +  {
 293.242 +    for (int i = 0; i < NumUnpackStreamsVector.Size(); i++)
 293.243 +      if (NumUnpackStreamsVector[i] > 1)
 293.244 +        return true;
 293.245 +    return false;
 293.246 +  }
 293.247 +  bool IsItemAnti(int index) const { return (index < IsAnti.Size() && IsAnti[index]); }
 293.248 +  void SetItemAnti(int index, bool isAnti)
 293.249 +  {
 293.250 +    while (index >= IsAnti.Size())
 293.251 +      IsAnti.Add(false);
 293.252 +    IsAnti[index] = isAnti;
 293.253 +  }
 293.254 +
 293.255 +  void GetFile(int index, CFileItem &file, CFileItem2 &file2) const;
 293.256 +  void AddFile(const CFileItem &file, const CFileItem2 &file2);
 293.257 +};
 293.258 +
 293.259 +}}
 293.260 +
 293.261 +#endif
   294.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   294.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zProperties.cpp	Sat Mar 03 10:31:27 2012 -0600
   294.3 @@ -0,0 +1,163 @@
   294.4 +// 7zProperties.cpp
   294.5 +
   294.6 +#include "StdAfx.h"
   294.7 +
   294.8 +#include "7zProperties.h"
   294.9 +#include "7zHeader.h"
  294.10 +#include "7zHandler.h"
  294.11 +
  294.12 +// #define _MULTI_PACK
  294.13 +
  294.14 +namespace NArchive {
  294.15 +namespace N7z {
  294.16 +
  294.17 +struct CPropMap
  294.18 +{
  294.19 +  UInt64 FilePropID;
  294.20 +  STATPROPSTG StatPROPSTG;
  294.21 +};
  294.22 +
  294.23 +CPropMap kPropMap[] =
  294.24 +{
  294.25 +  { NID::kName, NULL, kpidPath, VT_BSTR},
  294.26 +  { NID::kSize, NULL, kpidSize, VT_UI8},
  294.27 +  { NID::kPackInfo, NULL, kpidPackSize, VT_UI8},
  294.28 +  
  294.29 +  #ifdef _MULTI_PACK
  294.30 +  { 100, L"Pack0", kpidPackedSize0, VT_UI8},
  294.31 +  { 101, L"Pack1", kpidPackedSize1, VT_UI8},
  294.32 +  { 102, L"Pack2", kpidPackedSize2, VT_UI8},
  294.33 +  { 103, L"Pack3", kpidPackedSize3, VT_UI8},
  294.34 +  { 104, L"Pack4", kpidPackedSize4, VT_UI8},
  294.35 +  #endif
  294.36 +
  294.37 +  { NID::kCTime, NULL, kpidCTime, VT_FILETIME},
  294.38 +  { NID::kMTime, NULL, kpidMTime, VT_FILETIME},
  294.39 +  { NID::kATime, NULL, kpidATime, VT_FILETIME},
  294.40 +  { NID::kWinAttributes, NULL, kpidAttrib, VT_UI4},
  294.41 +  { NID::kStartPos, NULL, kpidPosition, VT_UI4},
  294.42 +
  294.43 +  { NID::kCRC, NULL, kpidCRC, VT_UI4},
  294.44 +  
  294.45 +  { NID::kAnti, NULL, kpidIsAnti, VT_BOOL},
  294.46 +
  294.47 +  #ifndef _SFX
  294.48 +  { 97, NULL, kpidEncrypted, VT_BOOL},
  294.49 +  { 98, NULL, kpidMethod, VT_BSTR},
  294.50 +  { 99, NULL, kpidBlock, VT_UI4}
  294.51 +  #endif
  294.52 +};
  294.53 +
  294.54 +static const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);
  294.55 +
  294.56 +static int FindPropInMap(UInt64 filePropID)
  294.57 +{
  294.58 +  for (int i = 0; i < kPropMapSize; i++)
  294.59 +    if (kPropMap[i].FilePropID == filePropID)
  294.60 +      return i;
  294.61 +  return -1;
  294.62 +}
  294.63 +
  294.64 +static void CopyOneItem(CRecordVector<UInt64> &src,
  294.65 +    CRecordVector<UInt64> &dest, UInt32 item)
  294.66 +{
  294.67 +  for (int i = 0; i < src.Size(); i++)
  294.68 +    if (src[i] == item)
  294.69 +    {
  294.70 +      dest.Add(item);
  294.71 +      src.Delete(i);
  294.72 +      return;
  294.73 +    }
  294.74 +}
  294.75 +
  294.76 +static void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)
  294.77 +{
  294.78 +  for (int i = 0; i < src.Size(); i++)
  294.79 +    if (src[i] == item)
  294.80 +    {
  294.81 +      src.Delete(i);
  294.82 +      return;
  294.83 +    }
  294.84 +}
  294.85 +
  294.86 +static void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)
  294.87 +{
  294.88 +  for (int i = 0; i < dest.Size(); i++)
  294.89 +    if (dest[i] == item)
  294.90 +    {
  294.91 +      dest.Delete(i);
  294.92 +      break;
  294.93 +    }
  294.94 +  dest.Insert(0, item);
  294.95 +}
  294.96 +
  294.97 +void CHandler::FillPopIDs()
  294.98 +{
  294.99 +  _fileInfoPopIDs.Clear();
 294.100 +
 294.101 +  #ifdef _7Z_VOL
 294.102 +  if(_volumes.Size() < 1)
 294.103 +    return;
 294.104 +  const CVolume &volume = _volumes.Front();
 294.105 +  const CArchiveDatabaseEx &_db = volume.Database;
 294.106 +  #endif
 294.107 +
 294.108 +  CRecordVector<UInt64> fileInfoPopIDs = _db.ArchiveInfo.FileInfoPopIDs;
 294.109 +
 294.110 +  RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);
 294.111 +  RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);
 294.112 +
 294.113 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);
 294.114 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);
 294.115 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);
 294.116 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);
 294.117 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCTime);
 294.118 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kMTime);
 294.119 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kATime);
 294.120 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);
 294.121 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);
 294.122 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);
 294.123 +  _fileInfoPopIDs += fileInfoPopIDs;
 294.124 + 
 294.125 +  #ifndef _SFX
 294.126 +  _fileInfoPopIDs.Add(97);
 294.127 +  _fileInfoPopIDs.Add(98);
 294.128 +  _fileInfoPopIDs.Add(99);
 294.129 +  #endif
 294.130 +  #ifdef _MULTI_PACK
 294.131 +  _fileInfoPopIDs.Add(100);
 294.132 +  _fileInfoPopIDs.Add(101);
 294.133 +  _fileInfoPopIDs.Add(102);
 294.134 +  _fileInfoPopIDs.Add(103);
 294.135 +  _fileInfoPopIDs.Add(104);
 294.136 +  #endif
 294.137 +
 294.138 +  #ifndef _SFX
 294.139 +  InsertToHead(_fileInfoPopIDs, NID::kMTime);
 294.140 +  InsertToHead(_fileInfoPopIDs, NID::kPackInfo);
 294.141 +  InsertToHead(_fileInfoPopIDs, NID::kSize);
 294.142 +  InsertToHead(_fileInfoPopIDs, NID::kName);
 294.143 +  #endif
 294.144 +}
 294.145 +
 294.146 +STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)
 294.147 +{
 294.148 +  *numProperties = _fileInfoPopIDs.Size();
 294.149 +  return S_OK;
 294.150 +}
 294.151 +
 294.152 +STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType)
 294.153 +{
 294.154 +  if ((int)index >= _fileInfoPopIDs.Size())
 294.155 +    return E_INVALIDARG;
 294.156 +  int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);
 294.157 +  if (indexInMap == -1)
 294.158 +    return E_INVALIDARG;
 294.159 +  const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;
 294.160 +  *propID = srcItem.propid;
 294.161 +  *varType = srcItem.vt;
 294.162 +  *name = 0;
 294.163 +  return S_OK;
 294.164 +}
 294.165 +
 294.166 +}}
   295.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   295.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zProperties.h	Sat Mar 03 10:31:27 2012 -0600
   295.3 @@ -0,0 +1,22 @@
   295.4 +// 7zProperties.h
   295.5 +
   295.6 +#ifndef __7Z_PROPERTIES_H
   295.7 +#define __7Z_PROPERTIES_H
   295.8 +
   295.9 +#include "../../PropID.h"
  295.10 +
  295.11 +namespace NArchive {
  295.12 +namespace N7z {
  295.13 +
  295.14 +enum
  295.15 +{
  295.16 +  kpidPackedSize0 = kpidUserDefined,
  295.17 +  kpidPackedSize1,
  295.18 +  kpidPackedSize2,
  295.19 +  kpidPackedSize3,
  295.20 +  kpidPackedSize4
  295.21 +};
  295.22 +
  295.23 +}}
  295.24 +
  295.25 +#endif
   296.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   296.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   296.3 @@ -0,0 +1,18 @@
   296.4 +// 7zRegister.cpp
   296.5 +
   296.6 +#include "StdAfx.h"
   296.7 +
   296.8 +#include "../../Common/RegisterArc.h"
   296.9 +
  296.10 +#include "7zHandler.h"
  296.11 +static IInArchive *CreateArc() { return new NArchive::N7z::CHandler;  }
  296.12 +#ifndef EXTRACT_ONLY
  296.13 +static IOutArchive *CreateArcOut() { return new NArchive::N7z::CHandler;  }
  296.14 +#else
  296.15 +#define CreateArcOut 0
  296.16 +#endif
  296.17 +
  296.18 +static CArcInfo g_ArcInfo =
  296.19 +  { L"7z", L"7z", 0, 7, {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}, 6, false, CreateArc, CreateArcOut };
  296.20 +
  296.21 +REGISTER_ARC(7z)
   297.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   297.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zSpecStream.cpp	Sat Mar 03 10:31:27 2012 -0600
   297.3 @@ -0,0 +1,24 @@
   297.4 +// 7zSpecStream.cpp
   297.5 +
   297.6 +#include "StdAfx.h"
   297.7 +
   297.8 +#include "7zSpecStream.h"
   297.9 +
  297.10 +STDMETHODIMP CSequentialInStreamSizeCount2::Read(void *data, UInt32 size, UInt32 *processedSize)
  297.11 +{
  297.12 +  UInt32 realProcessedSize;
  297.13 +  HRESULT result = _stream->Read(data, size, &realProcessedSize);
  297.14 +  _size += realProcessedSize;
  297.15 +  if (processedSize != 0)
  297.16 +    *processedSize = realProcessedSize;
  297.17 +  return result;
  297.18 +}
  297.19 +
  297.20 +STDMETHODIMP CSequentialInStreamSizeCount2::GetSubStreamSize(
  297.21 +    UInt64 subStream, UInt64 *value)
  297.22 +{
  297.23 +  if (_getSubStreamSize == NULL)
  297.24 +    return E_NOTIMPL;
  297.25 +  return  _getSubStreamSize->GetSubStreamSize(subStream, value);
  297.26 +}
  297.27 +
   298.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   298.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zSpecStream.h	Sat Mar 03 10:31:27 2012 -0600
   298.3 @@ -0,0 +1,35 @@
   298.4 +// 7zSpecStream.h
   298.5 +
   298.6 +#ifndef __7Z_SPEC_STREAM_H
   298.7 +#define __7Z_SPEC_STREAM_H
   298.8 +
   298.9 +#include "../../IStream.h"
  298.10 +#include "../../ICoder.h"
  298.11 +#include "../../../Common/MyCom.h"
  298.12 +
  298.13 +class CSequentialInStreamSizeCount2:
  298.14 +  public ISequentialInStream,
  298.15 +  public ICompressGetSubStreamSize,
  298.16 +  public CMyUnknownImp
  298.17 +{
  298.18 +  CMyComPtr<ISequentialInStream> _stream;
  298.19 +  CMyComPtr<ICompressGetSubStreamSize> _getSubStreamSize;
  298.20 +  UInt64 _size;
  298.21 +public:
  298.22 +  void Init(ISequentialInStream *stream)
  298.23 +  {
  298.24 +    _stream = stream;
  298.25 +    _getSubStreamSize = 0;
  298.26 +    _stream.QueryInterface(IID_ICompressGetSubStreamSize, &_getSubStreamSize);
  298.27 +    _size = 0;
  298.28 +  }
  298.29 +  UInt64 GetSize() const { return _size; }
  298.30 +
  298.31 +  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)
  298.32 +
  298.33 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
  298.34 +
  298.35 +  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);
  298.36 +};
  298.37 +
  298.38 +#endif
   299.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   299.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   299.3 @@ -0,0 +1,9 @@
   299.4 +// StdAfx.h
   299.5 +
   299.6 +#ifndef __STDAFX_H
   299.7 +#define __STDAFX_H
   299.8 +
   299.9 +#include "../../../Common/MyWindows.h"
  299.10 +#include "../../../Common/NewHandler.h"
  299.11 +
  299.12 +#endif
   300.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   300.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/ArchiveExports.cpp	Sat Mar 03 10:31:27 2012 -0600
   300.3 @@ -0,0 +1,130 @@
   300.4 +// ArchiveExports.cpp
   300.5 +
   300.6 +#include "StdAfx.h"
   300.7 +
   300.8 +#include "../../Common/ComTry.h"
   300.9 +#include "../../Common/Types.h"
  300.10 +#include "../../Windows/PropVariant.h"
  300.11 +#include "../Common/RegisterArc.h"
  300.12 +
  300.13 +#include "IArchive.h"
  300.14 +#include "../ICoder.h"
  300.15 +#include "../IPassword.h"
  300.16 +
  300.17 +static const unsigned int kNumArcsMax = 32;
  300.18 +static unsigned int g_NumArcs = 0;
  300.19 +static const CArcInfo *g_Arcs[kNumArcsMax];
  300.20 +void RegisterArc(const CArcInfo *arcInfo)
  300.21 +{
  300.22 +  if (g_NumArcs < kNumArcsMax)
  300.23 +    g_Arcs[g_NumArcs++] = arcInfo;
  300.24 +}
  300.25 +
  300.26 +DEFINE_GUID(CLSID_CArchiveHandler,
  300.27 +0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);
  300.28 +
  300.29 +#define CLS_ARC_ID_ITEM(cls) ((cls).Data4[5])
  300.30 +
  300.31 +static inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)
  300.32 +{
  300.33 +  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)
  300.34 +    value->vt = VT_BSTR;
  300.35 +  return S_OK;
  300.36 +}
  300.37 +
  300.38 +static inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)
  300.39 +{
  300.40 +  return SetPropString((const char *)&guid, sizeof(GUID), value);
  300.41 +}
  300.42 +
  300.43 +int FindFormatCalssId(const GUID *clsID)
  300.44 +{
  300.45 +  GUID cls = *clsID;
  300.46 +  CLS_ARC_ID_ITEM(cls) = 0;
  300.47 +  if (cls != CLSID_CArchiveHandler)
  300.48 +    return -1;
  300.49 +  Byte id = CLS_ARC_ID_ITEM(*clsID);
  300.50 +  for (unsigned i = 0; i < g_NumArcs; i++)
  300.51 +    if (g_Arcs[i]->ClassId == id)
  300.52 +      return (int)i;
  300.53 +  return -1;
  300.54 +}
  300.55 +
  300.56 +STDAPI CreateArchiver(const GUID *clsid, const GUID *iid, void **outObject)
  300.57 +{
  300.58 +  COM_TRY_BEGIN
  300.59 +  {
  300.60 +    int needIn = (*iid == IID_IInArchive);
  300.61 +    int needOut = (*iid == IID_IOutArchive);
  300.62 +    if (!needIn && !needOut)
  300.63 +      return E_NOINTERFACE;
  300.64 +    int formatIndex = FindFormatCalssId(clsid);
  300.65 +    if (formatIndex < 0)
  300.66 +      return CLASS_E_CLASSNOTAVAILABLE;
  300.67 +    
  300.68 +    const CArcInfo &arc = *g_Arcs[formatIndex];
  300.69 +    if (needIn)
  300.70 +    {
  300.71 +      *outObject = arc.CreateInArchive();
  300.72 +      ((IInArchive *)*outObject)->AddRef();
  300.73 +    }
  300.74 +    else
  300.75 +    {
  300.76 +      if (!arc.CreateOutArchive)
  300.77 +        return CLASS_E_CLASSNOTAVAILABLE;
  300.78 +      *outObject = arc.CreateOutArchive();
  300.79 +      ((IOutArchive *)*outObject)->AddRef();
  300.80 +    }
  300.81 +  }
  300.82 +  COM_TRY_END
  300.83 +  return S_OK;
  300.84 +}
  300.85 +
  300.86 +STDAPI GetHandlerProperty2(UInt32 formatIndex, PROPID propID, PROPVARIANT *value)
  300.87 +{
  300.88 +  if (formatIndex >= g_NumArcs)
  300.89 +    return E_INVALIDARG;
  300.90 +  const CArcInfo &arc = *g_Arcs[formatIndex];
  300.91 +  NWindows::NCOM::CPropVariant prop;
  300.92 +  switch(propID)
  300.93 +  {
  300.94 +    case NArchive::kName:
  300.95 +      prop = arc.Name;
  300.96 +      break;
  300.97 +    case NArchive::kClassID:
  300.98 +    {
  300.99 +      GUID clsId = CLSID_CArchiveHandler;
 300.100 +      CLS_ARC_ID_ITEM(clsId) = arc.ClassId;
 300.101 +      return SetPropGUID(clsId, value);
 300.102 +    }
 300.103 +    case NArchive::kExtension:
 300.104 +      if (arc.Ext != 0)
 300.105 +        prop = arc.Ext;
 300.106 +      break;
 300.107 +    case NArchive::kAddExtension:
 300.108 +      if (arc.AddExt != 0)
 300.109 +        prop = arc.AddExt;
 300.110 +      break;
 300.111 +    case NArchive::kUpdate:
 300.112 +      prop = (bool)(arc.CreateOutArchive != 0);
 300.113 +      break;
 300.114 +    case NArchive::kKeepName:
 300.115 +      prop = arc.KeepName;
 300.116 +      break;
 300.117 +    case NArchive::kStartSignature:
 300.118 +      return SetPropString((const char *)arc.Signature, arc.SignatureSize, value);
 300.119 +  }
 300.120 +  prop.Detach(value);
 300.121 +  return S_OK;
 300.122 +}
 300.123 +
 300.124 +STDAPI GetHandlerProperty(PROPID propID, PROPVARIANT *value)
 300.125 +{
 300.126 +  return GetHandlerProperty2(0, propID, value);
 300.127 +}
 300.128 +
 300.129 +STDAPI GetNumberOfFormats(UINT32 *numFormats)
 300.130 +{
 300.131 +  *numFormats = g_NumArcs;
 300.132 +  return S_OK;
 300.133 +}
   301.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   301.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/BZip2/BZip2Handler.cpp	Sat Mar 03 10:31:27 2012 -0600
   301.3 @@ -0,0 +1,216 @@
   301.4 +// BZip2Handler.cpp
   301.5 +
   301.6 +#include "StdAfx.h"
   301.7 +
   301.8 +#include "Common/ComTry.h"
   301.9 +
  301.10 +#include "Windows/PropVariant.h"
  301.11 +
  301.12 +#include "../../Common/CreateCoder.h"
  301.13 +#include "../../Common/ProgressUtils.h"
  301.14 +#include "../../Common/StreamUtils.h"
  301.15 +
  301.16 +#include "../Common/DummyOutStream.h"
  301.17 +
  301.18 +#include "BZip2Handler.h"
  301.19 +
  301.20 +using namespace NWindows;
  301.21 +
  301.22 +namespace NArchive {
  301.23 +namespace NBZip2 {
  301.24 +
  301.25 +static const CMethodId kMethodId_BZip2 = 0x040202;
  301.26 +
  301.27 +STATPROPSTG kProps[] =
  301.28 +{
  301.29 +  { NULL, kpidPackSize, VT_UI8}
  301.30 +};
  301.31 +
  301.32 +IMP_IInArchive_Props
  301.33 +IMP_IInArchive_ArcProps_NO
  301.34 +
  301.35 +STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
  301.36 +{
  301.37 +  *numItems = 1;
  301.38 +  return S_OK;
  301.39 +}
  301.40 +
  301.41 +STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID,  PROPVARIANT *value)
  301.42 +{
  301.43 +  NWindows::NCOM::CPropVariant prop;
  301.44 +  switch(propID)
  301.45 +  {
  301.46 +    case kpidPackSize: prop = _item.PackSize; break;
  301.47 +  }
  301.48 +  prop.Detach(value);
  301.49 +  return S_OK;
  301.50 +}
  301.51 +
  301.52 +STDMETHODIMP CHandler::Open(IInStream *stream,
  301.53 +    const UInt64 * /* maxCheckStartPosition */,
  301.54 +    IArchiveOpenCallback * /* openArchiveCallback */)
  301.55 +{
  301.56 +  COM_TRY_BEGIN
  301.57 +  try
  301.58 +  {
  301.59 +    RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_streamStartPosition));
  301.60 +    const int kSignatureSize = 3;
  301.61 +    Byte buffer[kSignatureSize];
  301.62 +    RINOK(ReadStream_FALSE(stream, buffer, kSignatureSize));
  301.63 +    if (buffer[0] != 'B' || buffer[1] != 'Z' || buffer[2] != 'h')
  301.64 +      return S_FALSE;
  301.65 +
  301.66 +    UInt64 endPosition;
  301.67 +    RINOK(stream->Seek(0, STREAM_SEEK_END, &endPosition));
  301.68 +    _item.PackSize = endPosition - _streamStartPosition;
  301.69 +    
  301.70 +    _stream = stream;
  301.71 +  }
  301.72 +  catch(...)
  301.73 +  {
  301.74 +    return S_FALSE;
  301.75 +  }
  301.76 +  return S_OK;
  301.77 +  COM_TRY_END
  301.78 +}
  301.79 +
  301.80 +STDMETHODIMP CHandler::Close()
  301.81 +{
  301.82 +  _stream.Release();
  301.83 +  return S_OK;
  301.84 +}
  301.85 +
  301.86 +
  301.87 +STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
  301.88 +    Int32 testModeSpec, IArchiveExtractCallback *extractCallback)
  301.89 +{
  301.90 +  COM_TRY_BEGIN
  301.91 +  bool allFilesMode = (numItems == UInt32(-1));
  301.92 +  if (!allFilesMode)
  301.93 +  {
  301.94 +    if (numItems == 0)
  301.95 +      return S_OK;
  301.96 +    if (numItems != 1)
  301.97 +      return E_INVALIDARG;
  301.98 +    if (indices[0] != 0)
  301.99 +      return E_INVALIDARG;
 301.100 +  }
 301.101 +
 301.102 +  bool testMode = (testModeSpec != 0);
 301.103 +
 301.104 +  extractCallback->SetTotal(_item.PackSize);
 301.105 +
 301.106 +  UInt64 currentTotalPacked = 0;
 301.107 +  
 301.108 +  RINOK(extractCallback->SetCompleted(&currentTotalPacked));
 301.109 +  
 301.110 +  CMyComPtr<ISequentialOutStream> realOutStream;
 301.111 +  Int32 askMode;
 301.112 +  askMode = testMode ? NExtract::NAskMode::kTest :
 301.113 +  NExtract::NAskMode::kExtract;
 301.114 +  
 301.115 +  RINOK(extractCallback->GetStream(0, &realOutStream, askMode));
 301.116 +    
 301.117 +  if(!testMode && !realOutStream)
 301.118 +    return S_OK;
 301.119 +
 301.120 +
 301.121 +  extractCallback->PrepareOperation(askMode);
 301.122 +
 301.123 +  CMyComPtr<ICompressCoder> decoder;
 301.124 +  HRESULT loadResult = CreateCoder(
 301.125 +      EXTERNAL_CODECS_VARS
 301.126 +      kMethodId_BZip2, decoder, false);
 301.127 +  if (loadResult != S_OK || !decoder)
 301.128 +  {
 301.129 +    RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kUnSupportedMethod));
 301.130 +    return S_OK;
 301.131 +  }
 301.132 +
 301.133 +  #ifdef COMPRESS_MT
 301.134 +  {
 301.135 +    CMyComPtr<ICompressSetCoderMt> setCoderMt;
 301.136 +    decoder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);
 301.137 +    if (setCoderMt)
 301.138 +    {
 301.139 +      RINOK(setCoderMt->SetNumberOfThreads(_numThreads));
 301.140 +    }
 301.141 +  }
 301.142 +  #endif
 301.143 +
 301.144 +  CDummyOutStream *outStreamSpec = new CDummyOutStream;
 301.145 +  CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
 301.146 +  outStreamSpec->SetStream(realOutStream);
 301.147 +  outStreamSpec->Init();
 301.148 +  
 301.149 +  realOutStream.Release();
 301.150 +
 301.151 +  CLocalProgress *lps = new CLocalProgress;
 301.152 +  CMyComPtr<ICompressProgressInfo> progress = lps;
 301.153 +  lps->Init(extractCallback, true);
 301.154 +  
 301.155 +  RINOK(_stream->Seek(_streamStartPosition, STREAM_SEEK_SET, NULL));
 301.156 +
 301.157 +  HRESULT result = S_OK;
 301.158 +
 301.159 +  bool firstItem = true;
 301.160 +  for (;;)
 301.161 +  {
 301.162 +    lps->InSize = currentTotalPacked;
 301.163 +    lps->OutSize = outStreamSpec->GetSize();
 301.164 +
 301.165 +    RINOK(lps->SetCur());
 301.166 +
 301.167 +    const int kSignatureSize = 3;
 301.168 +    Byte buffer[kSignatureSize];
 301.169 +    size_t processedSize = kSignatureSize;
 301.170 +    RINOK(ReadStream(_stream, buffer, &processedSize));
 301.171 +    if (processedSize != kSignatureSize)
 301.172 +    {
 301.173 +      if (firstItem)
 301.174 +        return E_FAIL;
 301.175 +      break;
 301.176 +    }
 301.177 +    if (buffer[0] != 'B' || buffer[1] != 'Z' || buffer[2] != 'h')
 301.178 +    {
 301.179 +      if (firstItem)
 301.180 +        return E_FAIL;
 301.181 +      break;
 301.182 +    }
 301.183 +    firstItem = false;
 301.184 +
 301.185 +    UInt64 dataStartPos;
 301.186 +    RINOK(_stream->Seek((UInt64)(Int64)(-3), STREAM_SEEK_CUR, &dataStartPos));
 301.187 +
 301.188 +    result = decoder->Code(_stream, outStream, NULL, NULL, progress);
 301.189 +
 301.190 +    if (result != S_OK)
 301.191 +      break;
 301.192 +
 301.193 +    CMyComPtr<ICompressGetInStreamProcessedSize> getInStreamProcessedSize;
 301.194 +    decoder.QueryInterface(IID_ICompressGetInStreamProcessedSize, &getInStreamProcessedSize);
 301.195 +    if (!getInStreamProcessedSize)
 301.196 +      break;
 301.197 +    UInt64 packSize;
 301.198 +    RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(&packSize));
 301.199 +    UInt64 pos;
 301.200 +    RINOK(_stream->Seek(dataStartPos + packSize, STREAM_SEEK_SET, &pos));
 301.201 +    currentTotalPacked = pos - _streamStartPosition;
 301.202 +  }
 301.203 +  outStream.Release();
 301.204 +
 301.205 +  Int32 retResult;
 301.206 +  if (result == S_OK)
 301.207 +    retResult = NExtract::NOperationResult::kOK;
 301.208 +  else if (result == S_FALSE)
 301.209 +    retResult = NExtract::NOperationResult::kDataError;
 301.210 +  else
 301.211 +    return result;
 301.212 +  return extractCallback->SetOperationResult(retResult);
 301.213 +
 301.214 +  COM_TRY_END
 301.215 +}
 301.216 +
 301.217 +IMPL_ISetCompressCodecsInfo
 301.218 +
 301.219 +}}
   302.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   302.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/BZip2/BZip2Handler.h	Sat Mar 03 10:31:27 2012 -0600
   302.3 @@ -0,0 +1,70 @@
   302.4 +// BZip2/Handler.h
   302.5 +
   302.6 +#ifndef __BZIP2_HANDLER_H
   302.7 +#define __BZIP2_HANDLER_H
   302.8 +
   302.9 +#include "Common/MyCom.h"
  302.10 +#include "../IArchive.h"
  302.11 +#include "../../Common/CreateCoder.h"
  302.12 +#include "BZip2Item.h"
  302.13 +
  302.14 +#ifdef COMPRESS_MT
  302.15 +#include "../../../Windows/System.h"
  302.16 +#endif
  302.17 +
  302.18 +namespace NArchive {
  302.19 +namespace NBZip2 {
  302.20 +
  302.21 +class CHandler:
  302.22 +  public IInArchive,
  302.23 +  public IOutArchive,
  302.24 +  public ISetProperties,
  302.25 +  PUBLIC_ISetCompressCodecsInfo
  302.26 +  public CMyUnknownImp
  302.27 +{
  302.28 +  CMyComPtr<IInStream> _stream;
  302.29 +  NArchive::NBZip2::CItem _item;
  302.30 +  UInt64 _streamStartPosition;
  302.31 +
  302.32 +  UInt32 _level;
  302.33 +  UInt32 _dicSize;
  302.34 +  UInt32 _numPasses;
  302.35 +  #ifdef COMPRESS_MT
  302.36 +  UInt32 _numThreads;
  302.37 +  #endif
  302.38 +
  302.39 +  DECL_EXTERNAL_CODECS_VARS
  302.40 +
  302.41 +  void InitMethodProperties()
  302.42 +  {
  302.43 +    _level = 5;
  302.44 +    _dicSize =
  302.45 +    _numPasses = 0xFFFFFFFF;
  302.46 +    #ifdef COMPRESS_MT
  302.47 +    _numThreads = NWindows::NSystem::GetNumberOfProcessors();;
  302.48 +    #endif
  302.49 +  }
  302.50 +
  302.51 +public:
  302.52 +  MY_QUERYINTERFACE_BEGIN2(IInArchive)
  302.53 +  MY_QUERYINTERFACE_ENTRY(IOutArchive)
  302.54 +  MY_QUERYINTERFACE_ENTRY(ISetProperties)
  302.55 +  QUERY_ENTRY_ISetCompressCodecsInfo
  302.56 +  MY_QUERYINTERFACE_END
  302.57 +  MY_ADDREF_RELEASE
  302.58 +
  302.59 +  INTERFACE_IInArchive(;)
  302.60 +#ifndef EXTRACT_ONLY
  302.61 +  INTERFACE_IOutArchive(;)
  302.62 +
  302.63 +  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);
  302.64 +#endif
  302.65 +
  302.66 +  DECL_ISetCompressCodecsInfo
  302.67 +
  302.68 +  CHandler() { InitMethodProperties(); }
  302.69 +};
  302.70 +
  302.71 +}}
  302.72 +
  302.73 +#endif
   303.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   303.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/BZip2/BZip2Item.h	Sat Mar 03 10:31:27 2012 -0600
   303.3 @@ -0,0 +1,20 @@
   303.4 +// Archive/BZip2Item.h
   303.5 +
   303.6 +#ifndef __ARCHIVE_BZIP2_ITEM_H
   303.7 +#define __ARCHIVE_BZIP2_ITEM_H
   303.8 +
   303.9 +namespace NArchive {
  303.10 +namespace NBZip2 {
  303.11 +  
  303.12 +struct CItem
  303.13 +{
  303.14 +  UInt64 PackSize;
  303.15 +  UInt64 UnPackSize;
  303.16 +};
  303.17 +
  303.18 +}}
  303.19 +
  303.20 +#endif
  303.21 +
  303.22 +
  303.23 +
   304.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   304.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/BZip2/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   304.3 @@ -0,0 +1,8 @@
   304.4 +// StdAfx.h
   304.5 +
   304.6 +#ifndef __STDAFX_H
   304.7 +#define __STDAFX_H
   304.8 +
   304.9 +#include "../../../Common/MyWindows.h"
  304.10 +
  304.11 +#endif
   305.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   305.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/BZip2/bz2Register.cpp	Sat Mar 03 10:31:27 2012 -0600
   305.3 @@ -0,0 +1,18 @@
   305.4 +// BZip2Register.cpp
   305.5 +
   305.6 +#include "StdAfx.h"
   305.7 +
   305.8 +#include "../../Common/RegisterArc.h"
   305.9 +
  305.10 +#include "BZip2Handler.h"
  305.11 +static IInArchive *CreateArc() { return new NArchive::NBZip2::CHandler;  }
  305.12 +#ifndef EXTRACT_ONLY
  305.13 +static IOutArchive *CreateArcOut() { return new NArchive::NBZip2::CHandler;  }
  305.14 +#else
  305.15 +#define CreateArcOut 0
  305.16 +#endif
  305.17 +
  305.18 +static CArcInfo g_ArcInfo =
  305.19 +  { L"BZip2", L"bz2 bzip2 tbz2 tbz", L"* * .tar .tar", 2, { 'B', 'Z', 'h' }, 3, true, CreateArc, CreateArcOut };
  305.20 +
  305.21 +REGISTER_ARC(BZip2)
   306.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   306.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/CoderMixer2.cpp	Sat Mar 03 10:31:27 2012 -0600
   306.3 @@ -0,0 +1,121 @@
   306.4 +// CoderMixer2.cpp
   306.5 +
   306.6 +#include "StdAfx.h"
   306.7 +
   306.8 +#include "CoderMixer2.h"
   306.9 +
  306.10 +namespace NCoderMixer {
  306.11 +
  306.12 +CBindReverseConverter::CBindReverseConverter(const CBindInfo &srcBindInfo):
  306.13 +  _srcBindInfo(srcBindInfo)
  306.14 +{
  306.15 +  srcBindInfo.GetNumStreams(NumSrcInStreams, _numSrcOutStreams);
  306.16 +
  306.17 +  UInt32  j;
  306.18 +  for (j = 0; j < NumSrcInStreams; j++)
  306.19 +  {
  306.20 +    _srcInToDestOutMap.Add(0);
  306.21 +    DestOutToSrcInMap.Add(0);
  306.22 +  }
  306.23 +  for (j = 0; j < _numSrcOutStreams; j++)
  306.24 +  {
  306.25 +    _srcOutToDestInMap.Add(0);
  306.26 +    _destInToSrcOutMap.Add(0);
  306.27 +  }
  306.28 +
  306.29 +  UInt32 destInOffset = 0;
  306.30 +  UInt32 destOutOffset = 0;
  306.31 +  UInt32 srcInOffset = NumSrcInStreams;
  306.32 +  UInt32 srcOutOffset = _numSrcOutStreams;
  306.33 +
  306.34 +  for (int i = srcBindInfo.Coders.Size() - 1; i >= 0; i--)
  306.35 +  {
  306.36 +    const CCoderStreamsInfo &srcCoderInfo = srcBindInfo.Coders[i];
  306.37 +
  306.38 +    srcInOffset -= srcCoderInfo.NumInStreams;
  306.39 +    srcOutOffset -= srcCoderInfo.NumOutStreams;
  306.40 +    
  306.41 +    UInt32 j;
  306.42 +    for (j = 0; j < srcCoderInfo.NumInStreams; j++, destOutOffset++)
  306.43 +    {
  306.44 +      UInt32 index = srcInOffset + j;
  306.45 +      _srcInToDestOutMap[index] = destOutOffset;
  306.46 +      DestOutToSrcInMap[destOutOffset] = index;
  306.47 +    }
  306.48 +    for (j = 0; j < srcCoderInfo.NumOutStreams; j++, destInOffset++)
  306.49 +    {
  306.50 +      UInt32 index = srcOutOffset + j;
  306.51 +      _srcOutToDestInMap[index] = destInOffset;
  306.52 +      _destInToSrcOutMap[destInOffset] = index;
  306.53 +    }
  306.54 +  }
  306.55 +}
  306.56 +
  306.57 +void CBindReverseConverter::CreateReverseBindInfo(CBindInfo &destBindInfo)
  306.58 +{
  306.59 +  destBindInfo.Coders.Clear();
  306.60 +  destBindInfo.BindPairs.Clear();
  306.61 +  destBindInfo.InStreams.Clear();
  306.62 +  destBindInfo.OutStreams.Clear();
  306.63 +
  306.64 +  int i;
  306.65 +  for (i = _srcBindInfo.Coders.Size() - 1; i >= 0; i--)
  306.66 +  {
  306.67 +    const CCoderStreamsInfo &srcCoderInfo = _srcBindInfo.Coders[i];
  306.68 +    CCoderStreamsInfo destCoderInfo;
  306.69 +    destCoderInfo.NumInStreams = srcCoderInfo.NumOutStreams;
  306.70 +    destCoderInfo.NumOutStreams = srcCoderInfo.NumInStreams;
  306.71 +    destBindInfo.Coders.Add(destCoderInfo);
  306.72 +  }
  306.73 +  for (i = _srcBindInfo.BindPairs.Size() - 1; i >= 0; i--)
  306.74 +  {
  306.75 +    const CBindPair &srcBindPair = _srcBindInfo.BindPairs[i];
  306.76 +    CBindPair destBindPair;
  306.77 +    destBindPair.InIndex = _srcOutToDestInMap[srcBindPair.OutIndex];
  306.78 +    destBindPair.OutIndex = _srcInToDestOutMap[srcBindPair.InIndex];
  306.79 +    destBindInfo.BindPairs.Add(destBindPair);
  306.80 +  }
  306.81 +  for (i = 0; i < _srcBindInfo.InStreams.Size(); i++)
  306.82 +    destBindInfo.OutStreams.Add(_srcInToDestOutMap[_srcBindInfo.InStreams[i]]);
  306.83 +  for (i = 0; i < _srcBindInfo.OutStreams.Size(); i++)
  306.84 +    destBindInfo.InStreams.Add(_srcOutToDestInMap[_srcBindInfo.OutStreams[i]]);
  306.85 +}
  306.86 +
  306.87 +CCoderInfo2::CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams):
  306.88 +    NumInStreams(numInStreams),
  306.89 +    NumOutStreams(numOutStreams)
  306.90 +{
  306.91 +  InSizes.Reserve(NumInStreams);
  306.92 +  InSizePointers.Reserve(NumInStreams);
  306.93 +  OutSizePointers.Reserve(NumOutStreams);
  306.94 +  OutSizePointers.Reserve(NumOutStreams);
  306.95 +}
  306.96 +
  306.97 +static void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes,
  306.98 +    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)
  306.99 +{
 306.100 +  sizes.Clear();
 306.101 +  sizePointers.Clear();
 306.102 +  for(UInt32 i = 0; i < numItems; i++)
 306.103 +  {
 306.104 +    if (srcSizes == 0 || srcSizes[i] == NULL)
 306.105 +    {
 306.106 +      sizes.Add(0);
 306.107 +      sizePointers.Add(NULL);
 306.108 +    }
 306.109 +    else
 306.110 +    {
 306.111 +      sizes.Add(*srcSizes[i]);
 306.112 +      sizePointers.Add(&sizes.Back());
 306.113 +    }
 306.114 +  }
 306.115 +}
 306.116 +
 306.117 +void CCoderInfo2::SetCoderInfo(const UInt64 **inSizes,
 306.118 +      const UInt64 **outSizes)
 306.119 +{
 306.120 +  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);
 306.121 +  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);
 306.122 +}
 306.123 +
 306.124 +}
   307.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   307.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/CoderMixer2.h	Sat Mar 03 10:31:27 2012 -0600
   307.3 @@ -0,0 +1,174 @@
   307.4 +// CoderMixer2.h
   307.5 +
   307.6 +#ifndef __CODER_MIXER2_H
   307.7 +#define __CODER_MIXER2_H
   307.8 +
   307.9 +#include "../../../Common/MyVector.h"
  307.10 +#include "../../../Common/Types.h"
  307.11 +#include "../../../Common/MyCom.h"
  307.12 +#include "../../ICoder.h"
  307.13 +
  307.14 +namespace NCoderMixer {
  307.15 +
  307.16 +struct CBindPair
  307.17 +{
  307.18 +  UInt32 InIndex;
  307.19 +  UInt32 OutIndex;
  307.20 +};
  307.21 +
  307.22 +struct CCoderStreamsInfo
  307.23 +{
  307.24 +  UInt32 NumInStreams;
  307.25 +  UInt32 NumOutStreams;
  307.26 +};
  307.27 +
  307.28 +struct CBindInfo
  307.29 +{
  307.30 +  CRecordVector<CCoderStreamsInfo> Coders;
  307.31 +  CRecordVector<CBindPair> BindPairs;
  307.32 +  CRecordVector<UInt32> InStreams;
  307.33 +  CRecordVector<UInt32> OutStreams;
  307.34 +
  307.35 +  void Clear()
  307.36 +  {
  307.37 +    Coders.Clear();
  307.38 +    BindPairs.Clear();
  307.39 +    InStreams.Clear();
  307.40 +    OutStreams.Clear();
  307.41 +  }
  307.42 +
  307.43 +  /*
  307.44 +  UInt32 GetCoderStartOutStream(UInt32 coderIndex) const
  307.45 +  {
  307.46 +    UInt32 numOutStreams = 0;
  307.47 +    for (UInt32 i = 0; i < coderIndex; i++)
  307.48 +      numOutStreams += Coders[i].NumOutStreams;
  307.49 +    return numOutStreams;
  307.50 +  }
  307.51 +  */
  307.52 +
  307.53 +
  307.54 +  void GetNumStreams(UInt32 &numInStreams, UInt32 &numOutStreams) const
  307.55 +  {
  307.56 +    numInStreams = 0;
  307.57 +    numOutStreams = 0;
  307.58 +    for (int i = 0; i < Coders.Size(); i++)
  307.59 +    {
  307.60 +      const CCoderStreamsInfo &coderStreamsInfo = Coders[i];
  307.61 +      numInStreams += coderStreamsInfo.NumInStreams;
  307.62 +      numOutStreams += coderStreamsInfo.NumOutStreams;
  307.63 +    }
  307.64 +  }
  307.65 +
  307.66 +  int FindBinderForInStream(UInt32 inStream) const
  307.67 +  {
  307.68 +    for (int i = 0; i < BindPairs.Size(); i++)
  307.69 +      if (BindPairs[i].InIndex == inStream)
  307.70 +        return i;
  307.71 +    return -1;
  307.72 +  }
  307.73 +  int FindBinderForOutStream(UInt32 outStream) const
  307.74 +  {
  307.75 +    for (int i = 0; i < BindPairs.Size(); i++)
  307.76 +      if (BindPairs[i].OutIndex == outStream)
  307.77 +        return i;
  307.78 +    return -1;
  307.79 +  }
  307.80 +
  307.81 +  UInt32 GetCoderInStreamIndex(UInt32 coderIndex) const
  307.82 +  {
  307.83 +    UInt32 streamIndex = 0;
  307.84 +    for (UInt32 i = 0; i < coderIndex; i++)
  307.85 +      streamIndex += Coders[i].NumInStreams;
  307.86 +    return streamIndex;
  307.87 +  }
  307.88 +
  307.89 +  UInt32 GetCoderOutStreamIndex(UInt32 coderIndex) const
  307.90 +  {
  307.91 +    UInt32 streamIndex = 0;
  307.92 +    for (UInt32 i = 0; i < coderIndex; i++)
  307.93 +      streamIndex += Coders[i].NumOutStreams;
  307.94 +    return streamIndex;
  307.95 +  }
  307.96 +
  307.97 +
  307.98 +  void FindInStream(UInt32 streamIndex, UInt32 &coderIndex,
  307.99 +      UInt32 &coderStreamIndex) const
 307.100 +  {
 307.101 +    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)
 307.102 +    {
 307.103 +      UInt32 curSize = Coders[coderIndex].NumInStreams;
 307.104 +      if (streamIndex < curSize)
 307.105 +      {
 307.106 +        coderStreamIndex = streamIndex;
 307.107 +        return;
 307.108 +      }
 307.109 +      streamIndex -= curSize;
 307.110 +    }
 307.111 +    throw 1;
 307.112 +  }
 307.113 +  void FindOutStream(UInt32 streamIndex, UInt32 &coderIndex,
 307.114 +      UInt32 &coderStreamIndex) const
 307.115 +  {
 307.116 +    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)
 307.117 +    {
 307.118 +      UInt32 curSize = Coders[coderIndex].NumOutStreams;
 307.119 +      if (streamIndex < curSize)
 307.120 +      {
 307.121 +        coderStreamIndex = streamIndex;
 307.122 +        return;
 307.123 +      }
 307.124 +      streamIndex -= curSize;
 307.125 +    }
 307.126 +    throw 1;
 307.127 +  }
 307.128 +};
 307.129 +
 307.130 +class CBindReverseConverter
 307.131 +{
 307.132 +  UInt32 _numSrcOutStreams;
 307.133 +  NCoderMixer::CBindInfo _srcBindInfo;
 307.134 +  CRecordVector<UInt32> _srcInToDestOutMap;
 307.135 +  CRecordVector<UInt32> _srcOutToDestInMap;
 307.136 +  CRecordVector<UInt32> _destInToSrcOutMap;
 307.137 +public:
 307.138 +  UInt32 NumSrcInStreams;
 307.139 +  CRecordVector<UInt32> DestOutToSrcInMap;
 307.140 +
 307.141 +  CBindReverseConverter(const NCoderMixer::CBindInfo &srcBindInfo);
 307.142 +  void CreateReverseBindInfo(NCoderMixer::CBindInfo &destBindInfo);
 307.143 +};
 307.144 +
 307.145 +struct CCoderInfo2
 307.146 +{
 307.147 +  CMyComPtr<ICompressCoder> Coder;
 307.148 +  CMyComPtr<ICompressCoder2> Coder2;
 307.149 +  UInt32 NumInStreams;
 307.150 +  UInt32 NumOutStreams;
 307.151 +
 307.152 +  CRecordVector<UInt64> InSizes;
 307.153 +  CRecordVector<UInt64> OutSizes;
 307.154 +  CRecordVector<const UInt64 *> InSizePointers;
 307.155 +  CRecordVector<const UInt64 *> OutSizePointers;
 307.156 +
 307.157 +  CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams);
 307.158 +  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);
 307.159 +
 307.160 +  HRESULT QueryInterface(REFGUID iid, void** pp) const
 307.161 +  {
 307.162 +    IUnknown *p = Coder ? (IUnknown *)Coder : (IUnknown *)Coder2;
 307.163 +    return p->QueryInterface(iid, pp);
 307.164 +  }
 307.165 +};
 307.166 +
 307.167 +class CCoderMixer2
 307.168 +{
 307.169 +public:
 307.170 +  virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0;
 307.171 +  virtual void ReInit() = 0;
 307.172 +  virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0;
 307.173 +};
 307.174 +
 307.175 +}
 307.176 +#endif
 307.177 +
   308.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   308.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/CoderMixer2MT.cpp	Sat Mar 03 10:31:27 2012 -0600
   308.3 @@ -0,0 +1,230 @@
   308.4 +// CoderMixer2MT.cpp
   308.5 +
   308.6 +#include "StdAfx.h"
   308.7 +
   308.8 +#include "CoderMixer2MT.h"
   308.9 +
  308.10 +namespace NCoderMixer {
  308.11 +
  308.12 +CCoder2::CCoder2(UInt32 numInStreams, UInt32 numOutStreams):
  308.13 +    CCoderInfo2(numInStreams, numOutStreams)
  308.14 +{
  308.15 +  InStreams.Reserve(NumInStreams);
  308.16 +  InStreamPointers.Reserve(NumInStreams);
  308.17 +  OutStreams.Reserve(NumOutStreams);
  308.18 +  OutStreamPointers.Reserve(NumOutStreams);
  308.19 +}
  308.20 +
  308.21 +void CCoder2::Execute() { Code(NULL); }
  308.22 +
  308.23 +void CCoder2::Code(ICompressProgressInfo *progress)
  308.24 +{
  308.25 +  InStreamPointers.Clear();
  308.26 +  OutStreamPointers.Clear();
  308.27 +  UInt32 i;
  308.28 +  for (i = 0; i < NumInStreams; i++)
  308.29 +  {
  308.30 +    if (InSizePointers[i] != NULL)
  308.31 +      InSizePointers[i] = &InSizes[i];
  308.32 +    InStreamPointers.Add((ISequentialInStream *)InStreams[i]);
  308.33 +  }
  308.34 +  for (i = 0; i < NumOutStreams; i++)
  308.35 +  {
  308.36 +    if (OutSizePointers[i] != NULL)
  308.37 +      OutSizePointers[i] = &OutSizes[i];
  308.38 +    OutStreamPointers.Add((ISequentialOutStream *)OutStreams[i]);
  308.39 +  }
  308.40 +  if (Coder)
  308.41 +    Result = Coder->Code(InStreamPointers[0], OutStreamPointers[0],
  308.42 +        InSizePointers[0], OutSizePointers[0], progress);
  308.43 +  else
  308.44 +    Result = Coder2->Code(&InStreamPointers.Front(), &InSizePointers.Front(), NumInStreams,
  308.45 +      &OutStreamPointers.Front(), &OutSizePointers.Front(), NumOutStreams, progress);
  308.46 +  {
  308.47 +    int i;
  308.48 +    for (i = 0; i < InStreams.Size(); i++)
  308.49 +      InStreams[i].Release();
  308.50 +    for (i = 0; i < OutStreams.Size(); i++)
  308.51 +      OutStreams[i].Release();
  308.52 +  }
  308.53 +}
  308.54 +
  308.55 +static void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes,
  308.56 +    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)
  308.57 +{
  308.58 +  sizes.Clear();
  308.59 +  sizePointers.Clear();
  308.60 +  for(UInt32 i = 0; i < numItems; i++)
  308.61 +  {
  308.62 +    if (srcSizes == 0 || srcSizes[i] == NULL)
  308.63 +    {
  308.64 +      sizes.Add(0);
  308.65 +      sizePointers.Add(NULL);
  308.66 +    }
  308.67 +    else
  308.68 +    {
  308.69 +      sizes.Add(*srcSizes[i]);
  308.70 +      sizePointers.Add(&sizes.Back());
  308.71 +    }
  308.72 +  }
  308.73 +}
  308.74 +
  308.75 +
  308.76 +void CCoder2::SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes)
  308.77 +{
  308.78 +  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);
  308.79 +  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);
  308.80 +}
  308.81 +
  308.82 +//////////////////////////////////////
  308.83 +// CCoderMixer2MT
  308.84 +
  308.85 +HRESULT CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo)
  308.86 +{
  308.87 +  _bindInfo = bindInfo;
  308.88 +  _streamBinders.Clear();
  308.89 +  for(int i = 0; i < _bindInfo.BindPairs.Size(); i++)
  308.90 +  {
  308.91 +    _streamBinders.Add(CStreamBinder());
  308.92 +    RINOK(_streamBinders.Back().CreateEvents());
  308.93 +  }
  308.94 +  return S_OK;
  308.95 +}
  308.96 +
  308.97 +void CCoderMixer2MT::AddCoderCommon()
  308.98 +{
  308.99 +  const CCoderStreamsInfo &c = _bindInfo.Coders[_coders.Size()];
 308.100 +  CCoder2 threadCoderInfo(c.NumInStreams, c.NumOutStreams);
 308.101 +  _coders.Add(threadCoderInfo);
 308.102 +}
 308.103 +
 308.104 +void CCoderMixer2MT::AddCoder(ICompressCoder *coder)
 308.105 +{
 308.106 +  AddCoderCommon();
 308.107 +  _coders.Back().Coder = coder;
 308.108 +}
 308.109 +
 308.110 +void CCoderMixer2MT::AddCoder2(ICompressCoder2 *coder)
 308.111 +{
 308.112 +  AddCoderCommon();
 308.113 +  _coders.Back().Coder2 = coder;
 308.114 +}
 308.115 +
 308.116 +
 308.117 +void CCoderMixer2MT::ReInit()
 308.118 +{
 308.119 +  for(int i = 0; i < _streamBinders.Size(); i++)
 308.120 +    _streamBinders[i].ReInit();
 308.121 +}
 308.122 +
 308.123 +
 308.124 +HRESULT CCoderMixer2MT::Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams)
 308.125 +{
 308.126 +  /*
 308.127 +  if (_coders.Size() != _bindInfo.Coders.Size())
 308.128 +    throw 0;
 308.129 +  */
 308.130 +  int i;
 308.131 +  for(i = 0; i < _coders.Size(); i++)
 308.132 +  {
 308.133 +    CCoder2 &coderInfo = _coders[i];
 308.134 +    const CCoderStreamsInfo &coderStreamsInfo = _bindInfo.Coders[i];
 308.135 +    coderInfo.InStreams.Clear();
 308.136 +    UInt32 j;
 308.137 +    for(j = 0; j < coderStreamsInfo.NumInStreams; j++)
 308.138 +      coderInfo.InStreams.Add(NULL);
 308.139 +    coderInfo.OutStreams.Clear();
 308.140 +    for(j = 0; j < coderStreamsInfo.NumOutStreams; j++)
 308.141 +      coderInfo.OutStreams.Add(NULL);
 308.142 +  }
 308.143 +
 308.144 +  for(i = 0; i < _bindInfo.BindPairs.Size(); i++)
 308.145 +  {
 308.146 +    const CBindPair &bindPair = _bindInfo.BindPairs[i];
 308.147 +    UInt32 inCoderIndex, inCoderStreamIndex;
 308.148 +    UInt32 outCoderIndex, outCoderStreamIndex;
 308.149 +    _bindInfo.FindInStream(bindPair.InIndex, inCoderIndex, inCoderStreamIndex);
 308.150 +    _bindInfo.FindOutStream(bindPair.OutIndex, outCoderIndex, outCoderStreamIndex);
 308.151 +
 308.152 +    _streamBinders[i].CreateStreams(
 308.153 +        &_coders[inCoderIndex].InStreams[inCoderStreamIndex],
 308.154 +        &_coders[outCoderIndex].OutStreams[outCoderStreamIndex]);
 308.155 +  }
 308.156 +
 308.157 +  for(i = 0; i < _bindInfo.InStreams.Size(); i++)
 308.158 +  {
 308.159 +    UInt32 inCoderIndex, inCoderStreamIndex;
 308.160 +    _bindInfo.FindInStream(_bindInfo.InStreams[i], inCoderIndex, inCoderStreamIndex);
 308.161 +    _coders[inCoderIndex].InStreams[inCoderStreamIndex] = inStreams[i];
 308.162 +  }
 308.163 +  
 308.164 +  for(i = 0; i < _bindInfo.OutStreams.Size(); i++)
 308.165 +  {
 308.166 +    UInt32 outCoderIndex, outCoderStreamIndex;
 308.167 +    _bindInfo.FindOutStream(_bindInfo.OutStreams[i], outCoderIndex, outCoderStreamIndex);
 308.168 +    _coders[outCoderIndex].OutStreams[outCoderStreamIndex] = outStreams[i];
 308.169 +  }
 308.170 +  return S_OK;
 308.171 +}
 308.172 +
 308.173 +HRESULT CCoderMixer2MT::ReturnIfError(HRESULT code)
 308.174 +{
 308.175 +  for (int i = 0; i < _coders.Size(); i++)
 308.176 +    if (_coders[i].Result == code)
 308.177 +      return code;
 308.178 +  return S_OK;
 308.179 +}
 308.180 +
 308.181 +STDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams,
 308.182 +      const UInt64 ** /* inSizes */,
 308.183 +      UInt32 numInStreams,
 308.184 +      ISequentialOutStream **outStreams,
 308.185 +      const UInt64 ** /* outSizes */,
 308.186 +      UInt32 numOutStreams,
 308.187 +      ICompressProgressInfo *progress)
 308.188 +{
 308.189 +  if (numInStreams != (UInt32)_bindInfo.InStreams.Size() ||
 308.190 +      numOutStreams != (UInt32)_bindInfo.OutStreams.Size())
 308.191 +    return E_INVALIDARG;
 308.192 +
 308.193 +  Init(inStreams, outStreams);
 308.194 +
 308.195 +  int i;
 308.196 +  for (i = 0; i < _coders.Size(); i++)
 308.197 +    if (i != _progressCoderIndex)
 308.198 +    {
 308.199 +      RINOK(_coders[i].Create());
 308.200 +    }
 308.201 +
 308.202 +  for (i = 0; i < _coders.Size(); i++)
 308.203 +    if (i != _progressCoderIndex)
 308.204 +      _coders[i].Start();
 308.205 +
 308.206 +  _coders[_progressCoderIndex].Code(progress);
 308.207 +
 308.208 +  for (i = 0; i < _coders.Size(); i++)
 308.209 +    if (i != _progressCoderIndex)
 308.210 +      _coders[i].WaitFinish();
 308.211 +
 308.212 +  RINOK(ReturnIfError(E_ABORT));
 308.213 +  RINOK(ReturnIfError(E_OUTOFMEMORY));
 308.214 +
 308.215 +  for (i = 0; i < _coders.Size(); i++)
 308.216 +  {
 308.217 +    HRESULT result = _coders[i].Result;
 308.218 +    if (result != S_OK && result != E_FAIL && result != S_FALSE)
 308.219 +      return result;
 308.220 +  }
 308.221 +
 308.222 +  RINOK(ReturnIfError(S_FALSE));
 308.223 +
 308.224 +  for (i = 0; i < _coders.Size(); i++)
 308.225 +  {
 308.226 +    HRESULT result = _coders[i].Result;
 308.227 +    if (result != S_OK)
 308.228 +      return result;
 308.229 +  }
 308.230 +  return S_OK;
 308.231 +}
 308.232 +
 308.233 +}
   309.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   309.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/CoderMixer2MT.h	Sat Mar 03 10:31:27 2012 -0600
   309.3 @@ -0,0 +1,80 @@
   309.4 +// CoderMixer2MT.h
   309.5 +
   309.6 +#ifndef __CODER_MIXER2_MT_H
   309.7 +#define __CODER_MIXER2_MT_H
   309.8 +
   309.9 +#include "CoderMixer2.h"
  309.10 +#include "../../../Common/MyCom.h"
  309.11 +#include "../../Common/StreamBinder.h"
  309.12 +#include "../../Common/VirtThread.h"
  309.13 +
  309.14 +namespace NCoderMixer {
  309.15 +
  309.16 +struct CCoder2: public CCoderInfo2, public CVirtThread
  309.17 +{
  309.18 +  HRESULT Result;
  309.19 +  CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;
  309.20 +  CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;
  309.21 +  CRecordVector<ISequentialInStream*> InStreamPointers;
  309.22 +  CRecordVector<ISequentialOutStream*> OutStreamPointers;
  309.23 +
  309.24 +  CCoder2(UInt32 numInStreams, UInt32 numOutStreams);
  309.25 +  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);
  309.26 +  virtual void Execute();
  309.27 +  void Code(ICompressProgressInfo *progress);
  309.28 +};
  309.29 +
  309.30 +
  309.31 +/*
  309.32 +  SetBindInfo()
  309.33 +  for each coder
  309.34 +    AddCoder[2]()
  309.35 +  SetProgressIndex(UInt32 coderIndex);
  309.36 + 
  309.37 +  for each file
  309.38 +  {
  309.39 +    ReInit()
  309.40 +    for each coder
  309.41 +      SetCoderInfo
  309.42 +    Code
  309.43 +  }
  309.44 +*/
  309.45 +
  309.46 +class CCoderMixer2MT:
  309.47 +  public ICompressCoder2,
  309.48 +  public CCoderMixer2,
  309.49 +  public CMyUnknownImp
  309.50 +{
  309.51 +  CBindInfo _bindInfo;
  309.52 +  CObjectVector<CStreamBinder> _streamBinders;
  309.53 +  int _progressCoderIndex;
  309.54 +
  309.55 +  void AddCoderCommon();
  309.56 +  HRESULT Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams);
  309.57 +  HRESULT ReturnIfError(HRESULT code);
  309.58 +public:
  309.59 +  CObjectVector<CCoder2> _coders;
  309.60 +  MY_UNKNOWN_IMP
  309.61 +
  309.62 +  STDMETHOD(Code)(ISequentialInStream **inStreams,
  309.63 +      const UInt64 **inSizes,
  309.64 +      UInt32 numInStreams,
  309.65 +      ISequentialOutStream **outStreams,
  309.66 +      const UInt64 **outSizes,
  309.67 +      UInt32 numOutStreams,
  309.68 +      ICompressProgressInfo *progress);
  309.69 +
  309.70 +  HRESULT SetBindInfo(const CBindInfo &bindInfo);
  309.71 +  void AddCoder(ICompressCoder *coder);
  309.72 +  void AddCoder2(ICompressCoder2 *coder);
  309.73 +  void SetProgressCoderIndex(int coderIndex) {  _progressCoderIndex = coderIndex; }
  309.74 +
  309.75 +  void ReInit();
  309.76 +  void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)
  309.77 +    {  _coders[coderIndex].SetCoderInfo(inSizes, outSizes); }
  309.78 +  UInt64 GetWriteProcessedSize(UInt32 binderIndex) const
  309.79 +    {  return _streamBinders[binderIndex].ProcessedSize; }
  309.80 +};
  309.81 +
  309.82 +}
  309.83 +#endif
   310.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   310.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/DummyOutStream.cpp	Sat Mar 03 10:31:27 2012 -0600
   310.3 @@ -0,0 +1,22 @@
   310.4 +// DummyOutStream.cpp
   310.5 +
   310.6 +#include "StdAfx.h"
   310.7 +
   310.8 +#include "DummyOutStream.h"
   310.9 +
  310.10 +STDMETHODIMP CDummyOutStream::Write(const void *data,  UInt32 size, UInt32 *processedSize)
  310.11 +{
  310.12 +  UInt32 realProcessedSize;
  310.13 +  HRESULT result;
  310.14 +  if(!_stream)
  310.15 +  {
  310.16 +    realProcessedSize = size;
  310.17 +    result = S_OK;
  310.18 +  }
  310.19 +  else
  310.20 +    result = _stream->Write(data, size, &realProcessedSize);
  310.21 +  _size += realProcessedSize;
  310.22 +  if(processedSize != NULL)
  310.23 +    *processedSize = realProcessedSize;
  310.24 +  return result;
  310.25 +}
   311.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   311.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/DummyOutStream.h	Sat Mar 03 10:31:27 2012 -0600
   311.3 @@ -0,0 +1,24 @@
   311.4 +// DummyOutStream.h
   311.5 +
   311.6 +#ifndef __DUMMYOUTSTREAM_H
   311.7 +#define __DUMMYOUTSTREAM_H
   311.8 +
   311.9 +#include "../../IStream.h"
  311.10 +#include "Common/MyCom.h"
  311.11 +
  311.12 +class CDummyOutStream:
  311.13 +  public ISequentialOutStream,
  311.14 +  public CMyUnknownImp
  311.15 +{
  311.16 +  CMyComPtr<ISequentialOutStream> _stream;
  311.17 +  UInt64 _size;
  311.18 +public:
  311.19 +  void SetStream(ISequentialOutStream *outStream) { _stream = outStream; }
  311.20 +  void ReleaseStream() { _stream.Release(); }
  311.21 +  void Init() { _size = 0; }
  311.22 +  MY_UNKNOWN_IMP
  311.23 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  311.24 +  UInt64 GetSize() const { return _size; }
  311.25 +};
  311.26 +
  311.27 +#endif
   312.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   312.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/FindSignature.cpp	Sat Mar 03 10:31:27 2012 -0600
   312.3 @@ -0,0 +1,62 @@
   312.4 +// FindSignature.cpp
   312.5 +
   312.6 +#include "StdAfx.h"
   312.7 +
   312.8 +#include "Common/Buffer.h"
   312.9 +
  312.10 +#include "FindSignature.h"
  312.11 +
  312.12 +#include "../../Common/StreamUtils.h"
  312.13 +
  312.14 +HRESULT FindSignatureInStream(ISequentialInStream *stream,
  312.15 +    const Byte *signature, unsigned signatureSize,
  312.16 +    const UInt64 *limit, UInt64 &resPos)
  312.17 +{
  312.18 +  resPos = 0;
  312.19 +  CByteBuffer byteBuffer2;
  312.20 +  byteBuffer2.SetCapacity(signatureSize);
  312.21 +  RINOK(ReadStream_FALSE(stream, byteBuffer2, signatureSize));
  312.22 +
  312.23 +  if (memcmp(byteBuffer2, signature, signatureSize) == 0)
  312.24 +    return S_OK;
  312.25 +
  312.26 +  const UInt32 kBufferSize = (1 << 16);
  312.27 +  CByteBuffer byteBuffer;
  312.28 +  byteBuffer.SetCapacity(kBufferSize);
  312.29 +  Byte *buffer = byteBuffer;
  312.30 +  UInt32 numPrevBytes = signatureSize - 1;
  312.31 +  memcpy(buffer, (const Byte *)byteBuffer2 + 1, numPrevBytes);
  312.32 +  resPos = 1;
  312.33 +  for (;;)
  312.34 +  {
  312.35 +    if (limit != NULL)
  312.36 +      if (resPos > *limit)
  312.37 +        return S_FALSE;
  312.38 +    do
  312.39 +    {
  312.40 +      UInt32 numReadBytes = kBufferSize - numPrevBytes;
  312.41 +      UInt32 processedSize;
  312.42 +      RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));
  312.43 +      numPrevBytes += processedSize;
  312.44 +      if (processedSize == 0)
  312.45 +        return S_FALSE;
  312.46 +    }
  312.47 +    while (numPrevBytes < signatureSize);
  312.48 +    UInt32 numTests = numPrevBytes - signatureSize + 1;
  312.49 +    for (UInt32 pos = 0; pos < numTests; pos++)
  312.50 +    {
  312.51 +      Byte b = signature[0];
  312.52 +      for (; buffer[pos] != b && pos < numTests; pos++);
  312.53 +      if (pos == numTests)
  312.54 +        break;
  312.55 +      if (memcmp(buffer + pos, signature, signatureSize) == 0)
  312.56 +      {
  312.57 +        resPos += pos;
  312.58 +        return S_OK;
  312.59 +      }
  312.60 +    }
  312.61 +    resPos += numTests;
  312.62 +    numPrevBytes -= numTests;
  312.63 +    memmove(buffer, buffer + numTests, numPrevBytes);
  312.64 +  }
  312.65 +}
   313.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   313.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/FindSignature.h	Sat Mar 03 10:31:27 2012 -0600
   313.3 @@ -0,0 +1,12 @@
   313.4 +// FindSignature.h
   313.5 +
   313.6 +#ifndef __FINDSIGNATURE_H
   313.7 +#define __FINDSIGNATURE_H
   313.8 +
   313.9 +#include "../../IStream.h"
  313.10 +
  313.11 +HRESULT FindSignatureInStream(ISequentialInStream *stream,
  313.12 +    const Byte *signature, unsigned signatureSize,
  313.13 +    const UInt64 *limit, UInt64 &resPos);
  313.14 +
  313.15 +#endif
   314.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   314.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/InStreamWithCRC.cpp	Sat Mar 03 10:31:27 2012 -0600
   314.3 @@ -0,0 +1,40 @@
   314.4 +// InStreamWithCRC.cpp
   314.5 +
   314.6 +#include "StdAfx.h"
   314.7 +
   314.8 +#include "InStreamWithCRC.h"
   314.9 +
  314.10 +STDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)
  314.11 +{
  314.12 +  UInt32 realProcessedSize;
  314.13 +  HRESULT result = _stream->Read(data, size, &realProcessedSize);
  314.14 +  _size += realProcessedSize;
  314.15 +  if (size > 0 && realProcessedSize == 0)
  314.16 +    _wasFinished = true;
  314.17 +  _crc = CrcUpdate(_crc, data, realProcessedSize);
  314.18 +  if(processedSize != NULL)
  314.19 +    *processedSize = realProcessedSize;
  314.20 +  return result;
  314.21 +}
  314.22 +
  314.23 +STDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)
  314.24 +{
  314.25 +  UInt32 realProcessedSize;
  314.26 +  HRESULT result = _stream->Read(data, size, &realProcessedSize);
  314.27 +  if (size > 0 && realProcessedSize == 0)
  314.28 +    _wasFinished = true;
  314.29 +  _size += realProcessedSize;
  314.30 +  _crc = CrcUpdate(_crc, data, realProcessedSize);
  314.31 +  if(processedSize != NULL)
  314.32 +    *processedSize = realProcessedSize;
  314.33 +  return result;
  314.34 +}
  314.35 +
  314.36 +STDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
  314.37 +{
  314.38 +  if (seekOrigin != STREAM_SEEK_SET || offset != 0)
  314.39 +    return E_FAIL;
  314.40 +  _size = 0;
  314.41 +  _crc = CRC_INIT_VAL;
  314.42 +  return _stream->Seek(offset, seekOrigin, newPosition);
  314.43 +}
   315.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   315.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/InStreamWithCRC.h	Sat Mar 03 10:31:27 2012 -0600
   315.3 @@ -0,0 +1,69 @@
   315.4 +// InStreamWithCRC.h
   315.5 +
   315.6 +#ifndef __INSTREAMWITHCRC_H
   315.7 +#define __INSTREAMWITHCRC_H
   315.8 +
   315.9 +#include "../../../Common/MyCom.h"
  315.10 +#include "../../IStream.h"
  315.11 +
  315.12 +extern "C"
  315.13 +{
  315.14 +#include "../../../../C/7zCrc.h"
  315.15 +}
  315.16 +
  315.17 +class CSequentialInStreamWithCRC:
  315.18 +  public ISequentialInStream,
  315.19 +  public CMyUnknownImp
  315.20 +{
  315.21 +public:
  315.22 +  MY_UNKNOWN_IMP
  315.23 +
  315.24 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
  315.25 +private:
  315.26 +  CMyComPtr<ISequentialInStream> _stream;
  315.27 +  UInt64 _size;
  315.28 +  UInt32 _crc;
  315.29 +  bool _wasFinished;
  315.30 +public:
  315.31 +  void SetStream(ISequentialInStream *stream) { _stream = stream;  }
  315.32 +  void Init()
  315.33 +  {
  315.34 +    _size = 0;
  315.35 +    _wasFinished = false;
  315.36 +    _crc = CRC_INIT_VAL;
  315.37 +  }
  315.38 +  void ReleaseStream() { _stream.Release(); }
  315.39 +  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
  315.40 +  UInt64 GetSize() const { return _size; }
  315.41 +  bool WasFinished() const { return _wasFinished; }
  315.42 +};
  315.43 +
  315.44 +class CInStreamWithCRC:
  315.45 +  public IInStream,
  315.46 +  public CMyUnknownImp
  315.47 +{
  315.48 +public:
  315.49 +  MY_UNKNOWN_IMP1(IInStream)
  315.50 +
  315.51 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
  315.52 +  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
  315.53 +private:
  315.54 +  CMyComPtr<IInStream> _stream;
  315.55 +  UInt64 _size;
  315.56 +  UInt32 _crc;
  315.57 +  bool _wasFinished;
  315.58 +public:
  315.59 +  void SetStream(IInStream *stream) { _stream = stream;  }
  315.60 +  void Init()
  315.61 +  {
  315.62 +    _size = 0;
  315.63 +    _wasFinished = false;
  315.64 +    _crc = CRC_INIT_VAL;
  315.65 +  }
  315.66 +  void ReleaseStream() { _stream.Release(); }
  315.67 +  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
  315.68 +  UInt64 GetSize() const { return _size; }
  315.69 +  bool WasFinished() const { return _wasFinished; }
  315.70 +};
  315.71 +
  315.72 +#endif
   316.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   316.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/ItemNameUtils.cpp	Sat Mar 03 10:31:27 2012 -0600
   316.3 @@ -0,0 +1,59 @@
   316.4 +// Archive/Common/ItemNameUtils.cpp
   316.5 +
   316.6 +#include "StdAfx.h"
   316.7 +
   316.8 +#include "ItemNameUtils.h"
   316.9 +
  316.10 +namespace NArchive {
  316.11 +namespace NItemName {
  316.12 +
  316.13 +static const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR;
  316.14 +static const wchar_t kDirDelimiter = L'/';
  316.15 +
  316.16 +UString MakeLegalName(const UString &name)
  316.17 +{
  316.18 +  UString zipName = name;
  316.19 +  zipName.Replace(kOSDirDelimiter, kDirDelimiter);
  316.20 +  return zipName;
  316.21 +}
  316.22 +
  316.23 +UString GetOSName(const UString &name)
  316.24 +{
  316.25 +  UString newName = name;
  316.26 +  newName.Replace(kDirDelimiter, kOSDirDelimiter);
  316.27 +  return newName;
  316.28 +}
  316.29 +
  316.30 +UString GetOSName2(const UString &name)
  316.31 +{
  316.32 +  if (name.IsEmpty())
  316.33 +    return UString();
  316.34 +  UString newName = GetOSName(name);
  316.35 +  if (newName[newName.Length() - 1] == kOSDirDelimiter)
  316.36 +    newName.Delete(newName.Length() - 1);
  316.37 +  return newName;
  316.38 +}
  316.39 +
  316.40 +bool HasTailSlash(const AString &name, UINT codePage)
  316.41 +{
  316.42 +  if (name.IsEmpty())
  316.43 +    return false;
  316.44 +  LPCSTR prev =
  316.45 +  #ifdef _WIN32
  316.46 +    CharPrevExA((WORD)codePage, name, &name[name.Length()], 0);
  316.47 +  #else
  316.48 +    (LPCSTR)(name) + (name.Length() - 1);
  316.49 +  #endif
  316.50 +  return (*prev == '/');
  316.51 +}
  316.52 +
  316.53 +#ifndef _WIN32
  316.54 +UString WinNameToOSName(const UString &name)
  316.55 +{
  316.56 +  UString newName = name;
  316.57 +  newName.Replace(L'\\', kOSDirDelimiter);
  316.58 +  return newName;
  316.59 +}
  316.60 +#endif
  316.61 +
  316.62 +}}
   317.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   317.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/ItemNameUtils.h	Sat Mar 03 10:31:27 2012 -0600
   317.3 @@ -0,0 +1,24 @@
   317.4 +// Archive/Common/ItemNameUtils.h
   317.5 +
   317.6 +#ifndef __ARCHIVE_ITEMNAMEUTILS_H
   317.7 +#define __ARCHIVE_ITEMNAMEUTILS_H
   317.8 +
   317.9 +#include "../../../Common/MyString.h"
  317.10 +
  317.11 +namespace NArchive {
  317.12 +namespace NItemName {
  317.13 +
  317.14 +  UString MakeLegalName(const UString &name);
  317.15 +  UString GetOSName(const UString &name);
  317.16 +  UString GetOSName2(const UString &name);
  317.17 +  bool HasTailSlash(const AString &name, UINT codePage);
  317.18 +
  317.19 +  #ifdef _WIN32
  317.20 +  inline UString WinNameToOSName(const UString &name)  { return name; }
  317.21 +  #else
  317.22 +  UString WinNameToOSName(const UString &name);
  317.23 +  #endif
  317.24 +
  317.25 +}}
  317.26 +
  317.27 +#endif
   318.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   318.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/MultiStream.cpp	Sat Mar 03 10:31:27 2012 -0600
   318.3 @@ -0,0 +1,201 @@
   318.4 +// MultiStream.cpp
   318.5 +
   318.6 +#include "StdAfx.h"
   318.7 +
   318.8 +#include "MultiStream.h"
   318.9 +
  318.10 +STDMETHODIMP CMultiStream::Read(void *data, UInt32 size, UInt32 *processedSize)
  318.11 +{
  318.12 +  if(processedSize != NULL)
  318.13 +    *processedSize = 0;
  318.14 +  while(_streamIndex < Streams.Size() && size > 0)
  318.15 +  {
  318.16 +    CSubStreamInfo &s = Streams[_streamIndex];
  318.17 +    if (_pos == s.Size)
  318.18 +    {
  318.19 +      _streamIndex++;
  318.20 +      _pos = 0;
  318.21 +      continue;
  318.22 +    }
  318.23 +    RINOK(s.Stream->Seek(s.Pos + _pos, STREAM_SEEK_SET, 0));
  318.24 +    UInt32 sizeToRead = UInt32(MyMin((UInt64)size, s.Size - _pos));
  318.25 +    UInt32 realProcessed;
  318.26 +    HRESULT result = s.Stream->Read(data, sizeToRead, &realProcessed);
  318.27 +    data = (void *)((Byte *)data + realProcessed);
  318.28 +    size -= realProcessed;
  318.29 +    if(processedSize != NULL)
  318.30 +      *processedSize += realProcessed;
  318.31 +    _pos += realProcessed;
  318.32 +    _seekPos += realProcessed;
  318.33 +    RINOK(result);
  318.34 +    break;
  318.35 +  }
  318.36 +  return S_OK;
  318.37 +}
  318.38 +  
  318.39 +STDMETHODIMP CMultiStream::Seek(Int64 offset, UInt32 seekOrigin,
  318.40 +    UInt64 *newPosition)
  318.41 +{
  318.42 +  UInt64 newPos;
  318.43 +  switch(seekOrigin)
  318.44 +  {
  318.45 +    case STREAM_SEEK_SET:
  318.46 +      newPos = offset;
  318.47 +      break;
  318.48 +    case STREAM_SEEK_CUR:
  318.49 +      newPos = _seekPos + offset;
  318.50 +      break;
  318.51 +    case STREAM_SEEK_END:
  318.52 +      newPos = _totalLength + offset;
  318.53 +      break;
  318.54 +    default:
  318.55 +      return STG_E_INVALIDFUNCTION;
  318.56 +  }
  318.57 +  _seekPos = 0;
  318.58 +  for (_streamIndex = 0; _streamIndex < Streams.Size(); _streamIndex++)
  318.59 +  {
  318.60 +    UInt64 size = Streams[_streamIndex].Size;
  318.61 +    if (newPos < _seekPos + size)
  318.62 +    {
  318.63 +      _pos = newPos - _seekPos;
  318.64 +      _seekPos += _pos;
  318.65 +      if (newPosition != 0)
  318.66 +        *newPosition = newPos;
  318.67 +      return S_OK;
  318.68 +    }
  318.69 +    _seekPos += size;
  318.70 +  }
  318.71 +  if (newPos == _seekPos)
  318.72 +  {
  318.73 +    if (newPosition != 0)
  318.74 +      *newPosition = newPos;
  318.75 +    return S_OK;
  318.76 +  }
  318.77 +  return E_FAIL;
  318.78 +}
  318.79 +
  318.80 +
  318.81 +/*
  318.82 +class COutVolumeStream:
  318.83 +  public ISequentialOutStream,
  318.84 +  public CMyUnknownImp
  318.85 +{
  318.86 +  int _volIndex;
  318.87 +  UInt64 _volSize;
  318.88 +  UInt64 _curPos;
  318.89 +  CMyComPtr<ISequentialOutStream> _volumeStream;
  318.90 +  COutArchive _archive;
  318.91 +  CCRC _crc;
  318.92 +
  318.93 +public:
  318.94 +  MY_UNKNOWN_IMP
  318.95 +
  318.96 +  CFileItem _file;
  318.97 +  CUpdateOptions _options;
  318.98 +  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;
  318.99 +  void Init(IArchiveUpdateCallback2 *volumeCallback,
 318.100 +      const UString &name)
 318.101 +  {
 318.102 +    _file.Name = name;
 318.103 +    _file.IsStartPosDefined = true;
 318.104 +    _file.StartPos = 0;
 318.105 +    
 318.106 +    VolumeCallback = volumeCallback;
 318.107 +    _volIndex = 0;
 318.108 +    _volSize = 0;
 318.109 +  }
 318.110 +  
 318.111 +  HRESULT Flush();
 318.112 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
 318.113 +};
 318.114 +
 318.115 +HRESULT COutVolumeStream::Flush()
 318.116 +{
 318.117 +  if (_volumeStream)
 318.118 +  {
 318.119 +    _file.UnPackSize = _curPos;
 318.120 +    _file.FileCRC = _crc.GetDigest();
 318.121 +    RINOK(WriteVolumeHeader(_archive, _file, _options));
 318.122 +    _archive.Close();
 318.123 +    _volumeStream.Release();
 318.124 +    _file.StartPos += _file.UnPackSize;
 318.125 +  }
 318.126 +  return S_OK;
 318.127 +}
 318.128 +*/
 318.129 +
 318.130 +/*
 318.131 +STDMETHODIMP COutMultiStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
 318.132 +{
 318.133 +  if(processedSize != NULL)
 318.134 +    *processedSize = 0;
 318.135 +  while(size > 0)
 318.136 +  {
 318.137 +    if (_streamIndex >= Streams.Size())
 318.138 +    {
 318.139 +      CSubStreamInfo subStream;
 318.140 +      RINOK(VolumeCallback->GetVolumeSize(Streams.Size(), &subStream.Size));
 318.141 +      RINOK(VolumeCallback->GetVolumeStream(Streams.Size(), &subStream.Stream));
 318.142 +      subStream.Pos = 0;
 318.143 +      Streams.Add(subStream);
 318.144 +      continue;
 318.145 +    }
 318.146 +    CSubStreamInfo &subStream = Streams[_streamIndex];
 318.147 +    if (_offsetPos >= subStream.Size)
 318.148 +    {
 318.149 +      _offsetPos -= subStream.Size;
 318.150 +      _streamIndex++;
 318.151 +      continue;
 318.152 +    }
 318.153 +    if (_offsetPos != subStream.Pos)
 318.154 +    {
 318.155 +      CMyComPtr<IOutStream> outStream;
 318.156 +      RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));
 318.157 +      RINOK(outStream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));
 318.158 +      subStream.Pos = _offsetPos;
 318.159 +    }
 318.160 +
 318.161 +    UInt32 curSize = (UInt32)MyMin((UInt64)size, subStream.Size - subStream.Pos);
 318.162 +    UInt32 realProcessed;
 318.163 +    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));
 318.164 +    data = (void *)((Byte *)data + realProcessed);
 318.165 +    size -= realProcessed;
 318.166 +    subStream.Pos += realProcessed;
 318.167 +    _offsetPos += realProcessed;
 318.168 +    _absPos += realProcessed;
 318.169 +    if (_absPos > _length)
 318.170 +      _length = _absPos;
 318.171 +    if(processedSize != NULL)
 318.172 +      *processedSize += realProcessed;
 318.173 +    if (subStream.Pos == subStream.Size)
 318.174 +    {
 318.175 +      _streamIndex++;
 318.176 +      _offsetPos = 0;
 318.177 +    }
 318.178 +    if (realProcessed != curSize && realProcessed == 0)
 318.179 +      return E_FAIL;
 318.180 +  }
 318.181 +  return S_OK;
 318.182 +}
 318.183 +
 318.184 +STDMETHODIMP COutMultiStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
 318.185 +{
 318.186 +  if(seekOrigin >= 3)
 318.187 +    return STG_E_INVALIDFUNCTION;
 318.188 +  switch(seekOrigin)
 318.189 +  {
 318.190 +    case STREAM_SEEK_SET:
 318.191 +      _absPos = offset;
 318.192 +      break;
 318.193 +    case STREAM_SEEK_CUR:
 318.194 +      _absPos += offset;
 318.195 +      break;
 318.196 +    case STREAM_SEEK_END:
 318.197 +      _absPos = _length + offset;
 318.198 +      break;
 318.199 +  }
 318.200 +  _offsetPos = _absPos;
 318.201 +  _streamIndex = 0;
 318.202 +  return S_OK;
 318.203 +}
 318.204 +*/
   319.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   319.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/MultiStream.h	Sat Mar 03 10:31:27 2012 -0600
   319.3 @@ -0,0 +1,76 @@
   319.4 +// MultiStream.h
   319.5 +
   319.6 +#ifndef __MULTISTREAM_H
   319.7 +#define __MULTISTREAM_H
   319.8 +
   319.9 +#include "../../../Common/MyCom.h"
  319.10 +#include "../../../Common/MyVector.h"
  319.11 +#include "../../Archive/IArchive.h"
  319.12 +
  319.13 +class CMultiStream:
  319.14 +  public IInStream,
  319.15 +  public CMyUnknownImp
  319.16 +{
  319.17 +  int _streamIndex;
  319.18 +  UInt64 _pos;
  319.19 +  UInt64 _seekPos;
  319.20 +  UInt64 _totalLength;
  319.21 +public:
  319.22 +  struct CSubStreamInfo
  319.23 +  {
  319.24 +    CMyComPtr<IInStream> Stream;
  319.25 +    UInt64 Pos;
  319.26 +    UInt64 Size;
  319.27 +  };
  319.28 +  CObjectVector<CSubStreamInfo> Streams;
  319.29 +  void Init()
  319.30 +  {
  319.31 +    _streamIndex = 0;
  319.32 +    _pos = 0;
  319.33 +    _seekPos = 0;
  319.34 +    _totalLength = 0;
  319.35 +    for (int i = 0; i < Streams.Size(); i++)
  319.36 +      _totalLength += Streams[i].Size;
  319.37 +  }
  319.38 +
  319.39 +  MY_UNKNOWN_IMP1(IInStream)
  319.40 +
  319.41 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
  319.42 +  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
  319.43 +};
  319.44 +
  319.45 +/*
  319.46 +class COutMultiStream:
  319.47 +  public IOutStream,
  319.48 +  public CMyUnknownImp
  319.49 +{
  319.50 +  int _streamIndex; // required stream
  319.51 +  UInt64 _offsetPos; // offset from start of _streamIndex index
  319.52 +  UInt64 _absPos;
  319.53 +  UInt64 _length;
  319.54 +
  319.55 +  struct CSubStreamInfo
  319.56 +  {
  319.57 +    CMyComPtr<ISequentialOutStream> Stream;
  319.58 +    UInt64 Size;
  319.59 +    UInt64 Pos;
  319.60 + };
  319.61 +  CObjectVector<CSubStreamInfo> Streams;
  319.62 +public:
  319.63 +  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;
  319.64 +  void Init()
  319.65 +  {
  319.66 +    _streamIndex = 0;
  319.67 +    _offsetPos = 0;
  319.68 +    _absPos = 0;
  319.69 +    _length = 0;
  319.70 +  }
  319.71 +
  319.72 +  MY_UNKNOWN_IMP1(IOutStream)
  319.73 +
  319.74 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  319.75 +  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
  319.76 +};
  319.77 +*/
  319.78 +
  319.79 +#endif
   320.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   320.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp	Sat Mar 03 10:31:27 2012 -0600
   320.3 @@ -0,0 +1,24 @@
   320.4 +// OutStreamWithCRC.cpp
   320.5 +
   320.6 +#include "StdAfx.h"
   320.7 +
   320.8 +#include "OutStreamWithCRC.h"
   320.9 +
  320.10 +STDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize)
  320.11 +{
  320.12 +  UInt32 realProcessedSize;
  320.13 +  HRESULT result;
  320.14 +  if(!_stream)
  320.15 +  {
  320.16 +    realProcessedSize = size;
  320.17 +    result = S_OK;
  320.18 +  }
  320.19 +  else
  320.20 +    result = _stream->Write(data, size, &realProcessedSize);
  320.21 +  if (_calculate)
  320.22 +    _crc = CrcUpdate(_crc, data, realProcessedSize);
  320.23 +  _size += realProcessedSize;
  320.24 +  if(processedSize != NULL)
  320.25 +    *processedSize = realProcessedSize;
  320.26 +  return result;
  320.27 +}
   321.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   321.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/OutStreamWithCRC.h	Sat Mar 03 10:31:27 2012 -0600
   321.3 @@ -0,0 +1,38 @@
   321.4 +// OutStreamWithCRC.h
   321.5 +
   321.6 +#ifndef __OUT_STREAM_WITH_CRC_H
   321.7 +#define __OUT_STREAM_WITH_CRC_H
   321.8 +
   321.9 +#include "../../../Common/MyCom.h"
  321.10 +#include "../../IStream.h"
  321.11 +
  321.12 +extern "C"
  321.13 +{
  321.14 +#include "../../../../C/7zCrc.h"
  321.15 +}
  321.16 +
  321.17 +class COutStreamWithCRC:
  321.18 +  public ISequentialOutStream,
  321.19 +  public CMyUnknownImp
  321.20 +{
  321.21 +  CMyComPtr<ISequentialOutStream> _stream;
  321.22 +  UInt64 _size;
  321.23 +  UInt32 _crc;
  321.24 +  bool _calculate;
  321.25 +public:
  321.26 +  MY_UNKNOWN_IMP
  321.27 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  321.28 +  void SetStream(ISequentialOutStream *stream) { _stream = stream; }
  321.29 +  void ReleaseStream() { _stream.Release(); }
  321.30 +  void Init(bool calculate = true)
  321.31 +  {
  321.32 +    _size = 0;
  321.33 +    _calculate = calculate;
  321.34 +    _crc = CRC_INIT_VAL;
  321.35 +  }
  321.36 +  void InitCRC() { _crc = CRC_INIT_VAL; }
  321.37 +  UInt64 GetSize() const { return _size; }
  321.38 +  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
  321.39 +};
  321.40 +
  321.41 +#endif
   322.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   322.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/ParseProperties.cpp	Sat Mar 03 10:31:27 2012 -0600
   322.3 @@ -0,0 +1,177 @@
   322.4 +// ParseProperties.cpp
   322.5 +
   322.6 +#include "StdAfx.h"
   322.7 +
   322.8 +#include "ParseProperties.h"
   322.9 +
  322.10 +#include "Common/StringToInt.h"
  322.11 +#include "Common/MyCom.h"
  322.12 +
  322.13 +HRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)
  322.14 +{
  322.15 +  if (prop.vt == VT_UI4)
  322.16 +  {
  322.17 +    if (!name.IsEmpty())
  322.18 +      return E_INVALIDARG;
  322.19 +    resValue = prop.ulVal;
  322.20 +  }
  322.21 +  else if (prop.vt == VT_EMPTY)
  322.22 +  {
  322.23 +    if(!name.IsEmpty())
  322.24 +    {
  322.25 +      const wchar_t *start = name;
  322.26 +      const wchar_t *end;
  322.27 +      UInt64 v = ConvertStringToUInt64(start, &end);
  322.28 +      if (end - start != name.Length())
  322.29 +        return E_INVALIDARG;
  322.30 +      resValue = (UInt32)v;
  322.31 +    }
  322.32 +  }
  322.33 +  else
  322.34 +    return E_INVALIDARG;
  322.35 +  return S_OK;
  322.36 +}
  322.37 +
  322.38 +static const int kLogarithmicSizeLimit = 32;
  322.39 +static const wchar_t kByteSymbol = L'B';
  322.40 +static const wchar_t kKiloByteSymbol = L'K';
  322.41 +static const wchar_t kMegaByteSymbol = L'M';
  322.42 +
  322.43 +HRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize)
  322.44 +{
  322.45 +  UString srcString = srcStringSpec;
  322.46 +  srcString.MakeUpper();
  322.47 +
  322.48 +  const wchar_t *start = srcString;
  322.49 +  const wchar_t *end;
  322.50 +  UInt64 number = ConvertStringToUInt64(start, &end);
  322.51 +  int numDigits = (int)(end - start);
  322.52 +  if (numDigits == 0 || srcString.Length() > numDigits + 1)
  322.53 +    return E_INVALIDARG;
  322.54 +  if (srcString.Length() == numDigits)
  322.55 +  {
  322.56 +    if (number >= kLogarithmicSizeLimit)
  322.57 +      return E_INVALIDARG;
  322.58 +    dicSize = (UInt32)1 << (int)number;
  322.59 +    return S_OK;
  322.60 +  }
  322.61 +  switch (srcString[numDigits])
  322.62 +  {
  322.63 +    case kByteSymbol:
  322.64 +      if (number >= ((UInt64)1 << kLogarithmicSizeLimit))
  322.65 +        return E_INVALIDARG;
  322.66 +      dicSize = (UInt32)number;
  322.67 +      break;
  322.68 +    case kKiloByteSymbol:
  322.69 +      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 10)))
  322.70 +        return E_INVALIDARG;
  322.71 +      dicSize = (UInt32)(number << 10);
  322.72 +      break;
  322.73 +    case kMegaByteSymbol:
  322.74 +      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 20)))
  322.75 +        return E_INVALIDARG;
  322.76 +      dicSize = (UInt32)(number << 20);
  322.77 +      break;
  322.78 +    default:
  322.79 +      return E_INVALIDARG;
  322.80 +  }
  322.81 +  return S_OK;
  322.82 +}
  322.83 +
  322.84 +HRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)
  322.85 +{
  322.86 +  if (name.IsEmpty())
  322.87 +  {
  322.88 +    if (prop.vt == VT_UI4)
  322.89 +    {
  322.90 +      UInt32 logDicSize = prop.ulVal;
  322.91 +      if (logDicSize >= 32)
  322.92 +        return E_INVALIDARG;
  322.93 +      resValue = (UInt32)1 << logDicSize;
  322.94 +      return S_OK;
  322.95 +    }
  322.96 +    if (prop.vt == VT_BSTR)
  322.97 +      return ParsePropDictionaryValue(prop.bstrVal, resValue);
  322.98 +    return E_INVALIDARG;
  322.99 +  }
 322.100 +  return ParsePropDictionaryValue(name, resValue);
 322.101 +}
 322.102 +
 322.103 +bool StringToBool(const UString &s, bool &res)
 322.104 +{
 322.105 +  if (s.IsEmpty() || s.CompareNoCase(L"ON") == 0 || s.Compare(L"+") == 0)
 322.106 +  {
 322.107 +    res = true;
 322.108 +    return true;
 322.109 +  }
 322.110 +  if (s.CompareNoCase(L"OFF") == 0 || s.Compare(L"-") == 0)
 322.111 +  {
 322.112 +    res = false;
 322.113 +    return true;
 322.114 +  }
 322.115 +  return false;
 322.116 +}
 322.117 +
 322.118 +HRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value)
 322.119 +{
 322.120 +  switch(value.vt)
 322.121 +  {
 322.122 +    case VT_EMPTY:
 322.123 +      dest = true;
 322.124 +      return S_OK;
 322.125 +    case VT_BOOL:
 322.126 +      dest = (value.boolVal != VARIANT_FALSE);
 322.127 +      return S_OK;
 322.128 +    /*
 322.129 +    case VT_UI4:
 322.130 +      dest = (value.ulVal != 0);
 322.131 +      break;
 322.132 +    */
 322.133 +    case VT_BSTR:
 322.134 +      return StringToBool(value.bstrVal, dest) ?  S_OK : E_INVALIDARG;
 322.135 +  }
 322.136 +  return E_INVALIDARG;
 322.137 +}
 322.138 +
 322.139 +int ParseStringToUInt32(const UString &srcString, UInt32 &number)
 322.140 +{
 322.141 +  const wchar_t *start = srcString;
 322.142 +  const wchar_t *end;
 322.143 +  UInt64 number64 = ConvertStringToUInt64(start, &end);
 322.144 +  if (number64 > 0xFFFFFFFF)
 322.145 +  {
 322.146 +    number = 0;
 322.147 +    return 0;
 322.148 +  }
 322.149 +  number = (UInt32)number64;
 322.150 +  return (int)(end - start);
 322.151 +}
 322.152 +
 322.153 +HRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads)
 322.154 +{
 322.155 +  if (name.IsEmpty())
 322.156 +  {
 322.157 +    switch(prop.vt)
 322.158 +    {
 322.159 +      case VT_UI4:
 322.160 +        numThreads = prop.ulVal;
 322.161 +        break;
 322.162 +      default:
 322.163 +      {
 322.164 +        bool val;
 322.165 +        RINOK(SetBoolProperty(val, prop));
 322.166 +        numThreads = (val ? defaultNumThreads : 1);
 322.167 +        break;
 322.168 +      }
 322.169 +    }
 322.170 +  }
 322.171 +  else
 322.172 +  {
 322.173 +    UInt32 number;
 322.174 +    int index = ParseStringToUInt32(name, number);
 322.175 +    if (index != name.Length())
 322.176 +      return E_INVALIDARG;
 322.177 +    numThreads = number;
 322.178 +  }
 322.179 +  return S_OK;
 322.180 +}
   323.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   323.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/ParseProperties.h	Sat Mar 03 10:31:27 2012 -0600
   323.3 @@ -0,0 +1,18 @@
   323.4 +// ParseProperties.h
   323.5 +
   323.6 +#ifndef __PARSEPROPERTIES_H
   323.7 +#define __PARSEPROPERTIES_H
   323.8 +
   323.9 +#include "Common/MyString.h"
  323.10 +#include "Common/Types.h"
  323.11 +
  323.12 +HRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);
  323.13 +HRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize);
  323.14 +HRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);
  323.15 +
  323.16 +bool StringToBool(const UString &s, bool &res);
  323.17 +HRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value);
  323.18 +int ParseStringToUInt32(const UString &srcString, UInt32 &number);
  323.19 +HRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads);
  323.20 +
  323.21 +#endif
   324.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   324.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   324.3 @@ -0,0 +1,9 @@
   324.4 +// StdAfx.h
   324.5 +
   324.6 +#ifndef __STDAFX_H
   324.7 +#define __STDAFX_H
   324.8 +
   324.9 +#include "../../../Common/MyWindows.h"
  324.10 +#include "../../../Common/NewHandler.h"
  324.11 +
  324.12 +#endif
   325.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   325.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/DllExports2.cpp	Sat Mar 03 10:31:27 2012 -0600
   325.3 @@ -0,0 +1,82 @@
   325.4 +// DLLExports.cpp
   325.5 +
   325.6 +#include "StdAfx.h"
   325.7 +
   325.8 +#include "../../Common/MyInitGuid.h"
   325.9 +#include "../../Common/ComTry.h"
  325.10 +#include "../../Common/Types.h"
  325.11 +#include "../../Windows/PropVariant.h"
  325.12 +#if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)
  325.13 +extern "C"
  325.14 +{
  325.15 +#include "../../../C/Alloc.h"
  325.16 +}
  325.17 +#endif
  325.18 +
  325.19 +#include "IArchive.h"
  325.20 +#include "../ICoder.h"
  325.21 +#include "../IPassword.h"
  325.22 +
  325.23 +HINSTANCE g_hInstance;
  325.24 +#ifndef _UNICODE
  325.25 +#ifdef _WIN32
  325.26 +bool g_IsNT = false;
  325.27 +static bool IsItWindowsNT()
  325.28 +{
  325.29 +  OSVERSIONINFO versionInfo;
  325.30 +  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
  325.31 +  if (!::GetVersionEx(&versionInfo))
  325.32 +    return false;
  325.33 +  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
  325.34 +}
  325.35 +#endif
  325.36 +#endif
  325.37 +
  325.38 +extern "C"
  325.39 +BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  325.40 +{
  325.41 +  if (dwReason == DLL_PROCESS_ATTACH)
  325.42 +  {
  325.43 +    g_hInstance = hInstance;
  325.44 +    #ifndef _UNICODE
  325.45 +    #ifdef _WIN32
  325.46 +    g_IsNT = IsItWindowsNT();
  325.47 +    #endif
  325.48 +    #endif
  325.49 +  }
  325.50 +  return TRUE;
  325.51 +}
  325.52 +
  325.53 +DEFINE_GUID(CLSID_CArchiveHandler,
  325.54 +0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);
  325.55 +
  325.56 +static const UInt16 kDecodeId = 0x2790;
  325.57 +
  325.58 +DEFINE_GUID(CLSID_CCodec,
  325.59 +0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
  325.60 +
  325.61 +STDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject);
  325.62 +STDAPI CreateArchiver(const GUID *classID, const GUID *iid, void **outObject);
  325.63 +
  325.64 +STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)
  325.65 +{
  325.66 +  // COM_TRY_BEGIN
  325.67 +  *outObject = 0;
  325.68 +  if (*iid == IID_ICompressCoder || *iid == IID_ICompressCoder2 || *iid == IID_ICompressFilter)
  325.69 +  {
  325.70 +    return CreateCoder(clsid, iid, outObject);
  325.71 +  }
  325.72 +  else
  325.73 +  {
  325.74 +    return CreateArchiver(clsid, iid, outObject);
  325.75 +  }
  325.76 +  // COM_TRY_END
  325.77 +}
  325.78 +
  325.79 +STDAPI SetLargePageMode()
  325.80 +{
  325.81 +  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)
  325.82 +  SetLargePageSize();
  325.83 +  #endif
  325.84 +  return S_OK;
  325.85 +}
   326.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   326.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipHandler.cpp	Sat Mar 03 10:31:27 2012 -0600
   326.3 @@ -0,0 +1,284 @@
   326.4 +// GZipHandler.cpp
   326.5 +
   326.6 +#include "StdAfx.h"
   326.7 +
   326.8 +#include "GZipHandler.h"
   326.9 +
  326.10 +#include "Common/Defs.h"
  326.11 +#include "Common/StringConvert.h"
  326.12 +#include "Common/ComTry.h"
  326.13 +#include "Windows/PropVariant.h"
  326.14 +#include "Windows/Time.h"
  326.15 +
  326.16 +#include "../../ICoder.h"
  326.17 +#include "../../Common/ProgressUtils.h"
  326.18 +#include "../../Common/CreateCoder.h"
  326.19 +#include "../Common/OutStreamWithCRC.h"
  326.20 +
  326.21 +using namespace NWindows;
  326.22 +
  326.23 +namespace NArchive {
  326.24 +namespace NGZip {
  326.25 +
  326.26 +static const CMethodId kMethodId_Deflate = 0x040108;
  326.27 +
  326.28 +const wchar_t *kHostOS[] =
  326.29 +{
  326.30 +  L"FAT",
  326.31 +  L"AMIGA",
  326.32 +  L"VMS",
  326.33 +  L"Unix",
  326.34 +  L"VM_CMS",
  326.35 +  L"Atari",  // what if it's a minix filesystem? [cjh]
  326.36 +  L"HPFS",  // filesystem used by OS/2 (and NT 3.x)
  326.37 +  L"Mac",
  326.38 +  L"Z_System",
  326.39 +  L"CPM",
  326.40 +  L"TOPS20", // pkzip 2.50 NTFS
  326.41 +  L"NTFS", // filesystem used by Windows NT
  326.42 +  L"QDOS ", // SMS/QDOS
  326.43 +  L"Acorn", // Archimedes Acorn RISC OS
  326.44 +  L"VFAT", // filesystem used by Windows 95, NT
  326.45 +  L"MVS",
  326.46 +  L"BeOS", // hybrid POSIX/database filesystem
  326.47 +                        // BeBOX or PowerMac
  326.48 +  L"Tandem",
  326.49 +  L"THEOS"
  326.50 +};
  326.51 +
  326.52 +static const int kNumHostOSes = sizeof(kHostOS) / sizeof(kHostOS[0]);
  326.53 +
  326.54 +static const wchar_t *kUnknownOS = L"Unknown";
  326.55 +
  326.56 +/*
  326.57 +enum // PropID
  326.58 +{
  326.59 +  kpidExtraIsPresent = kpidUserDefined,
  326.60 +  kpidExtraFlags,
  326.61 +  kpidIsText
  326.62 +};
  326.63 +*/
  326.64 +
  326.65 +STATPROPSTG kProps[] =
  326.66 +{
  326.67 +  { NULL, kpidPath, VT_BSTR},
  326.68 +  { NULL, kpidSize, VT_UI8},
  326.69 +  { NULL, kpidPackSize, VT_UI8},
  326.70 +  { NULL, kpidMTime, VT_FILETIME},
  326.71 +  // { NULL, kpidMethod, VT_UI1},
  326.72 +  { NULL, kpidHostOS, VT_BSTR},
  326.73 +  { NULL, kpidCRC, VT_UI4}
  326.74 +  // { L"Extra", kpidExtraIsPresent, VT_BOOL}
  326.75 +  // { L"Extra flags", kpidExtraFlags, VT_UI1},
  326.76 +  // { L"Is Text", kpidIsText, VT_BOOL},
  326.77 +};
  326.78 +
  326.79 +IMP_IInArchive_Props
  326.80 +IMP_IInArchive_ArcProps_NO
  326.81 +
  326.82 +STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
  326.83 +{
  326.84 +  *numItems = 1;
  326.85 +  return S_OK;
  326.86 +}
  326.87 +
  326.88 +STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID,  PROPVARIANT *value)
  326.89 +{
  326.90 +  COM_TRY_BEGIN
  326.91 +  NWindows::NCOM::CPropVariant prop;
  326.92 +  switch(propID)
  326.93 +  {
  326.94 +    case kpidPath:
  326.95 +      if (m_Item.NameIsPresent())
  326.96 +        prop = MultiByteToUnicodeString(m_Item.Name, CP_ACP);
  326.97 +      break;
  326.98 +    case kpidMTime:
  326.99 +    {
 326.100 +      FILETIME utcTime;
 326.101 +      if (m_Item.Time != 0)
 326.102 +      {
 326.103 +        NTime::UnixTimeToFileTime((UInt32)m_Item.Time, utcTime);
 326.104 +        prop = utcTime;
 326.105 +      }
 326.106 +      else
 326.107 +      {
 326.108 +        // utcTime.dwLowDateTime = utcTime.dwHighDateTime = 0;
 326.109 +        // prop = utcTime;
 326.110 +      }
 326.111 +      break;
 326.112 +    }
 326.113 +    case kpidSize:  prop = UInt64(m_Item.UnPackSize32); break;
 326.114 +    case kpidPackSize:  prop = m_PackSize; break;
 326.115 +    case kpidCommented:  prop = m_Item.CommentIsPresent(); break;
 326.116 +    case kpidHostOS:
 326.117 +      prop = (m_Item.HostOS < kNumHostOSes) ?
 326.118 +          kHostOS[m_Item.HostOS] : kUnknownOS;
 326.119 +      break;
 326.120 +    case kpidMethod:  prop = m_Item.CompressionMethod; break;
 326.121 +    case kpidCRC:  prop = m_Item.FileCRC; break;
 326.122 +    /*
 326.123 +    case kpidExtraFlags:  prop = m_Item.ExtraFlags; break;
 326.124 +    case kpidIsText:  prop = m_Item.IsText(); break;
 326.125 +    case kpidExtraIsPresent:  prop = m_Item.ExtraFieldIsPresent(); break;
 326.126 +    */
 326.127 +  }
 326.128 +  prop.Detach(value);
 326.129 +  return S_OK;
 326.130 +  COM_TRY_END
 326.131 +}
 326.132 +
 326.133 +STDMETHODIMP CHandler::Open(IInStream *inStream,
 326.134 +    const UInt64 * /* maxCheckStartPosition */,
 326.135 +    IArchiveOpenCallback * /* openArchiveCallback */)
 326.136 +{
 326.137 +  COM_TRY_BEGIN
 326.138 +  try
 326.139 +  {
 326.140 +    CInArchive archive;
 326.141 +    RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_StreamStartPosition));
 326.142 +    RINOK(archive.ReadHeader(inStream, m_Item));
 326.143 +    m_DataOffset = archive.GetOffset();
 326.144 +    UInt64 newPosition;
 326.145 +    RINOK(inStream->Seek(-8, STREAM_SEEK_END, &newPosition));
 326.146 +    m_PackSize = newPosition - (m_StreamStartPosition + m_DataOffset);
 326.147 +    if (archive.ReadPostHeader(inStream, m_Item) != S_OK)
 326.148 +      return S_FALSE;
 326.149 +    m_Stream = inStream;
 326.150 +  }
 326.151 +  catch(...)
 326.152 +  {
 326.153 +    return S_FALSE;
 326.154 +  }
 326.155 +  return S_OK;
 326.156 +  COM_TRY_END
 326.157 +}
 326.158 +
 326.159 +STDMETHODIMP CHandler::Close()
 326.160 +{
 326.161 +  m_Stream.Release();
 326.162 +  return S_OK;
 326.163 +}
 326.164 +
 326.165 +STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
 326.166 +    Int32 _aTestMode, IArchiveExtractCallback *extractCallback)
 326.167 +{
 326.168 +  COM_TRY_BEGIN
 326.169 +  bool allFilesMode = (numItems == UInt32(-1));
 326.170 +  if (!allFilesMode)
 326.171 +  {
 326.172 +    if (numItems == 0)
 326.173 +      return S_OK;
 326.174 +    if (numItems != 1)
 326.175 +      return E_INVALIDARG;
 326.176 +    if (indices[0] != 0)
 326.177 +      return E_INVALIDARG;
 326.178 +  }
 326.179 +
 326.180 +  bool testMode = (_aTestMode != 0);
 326.181 +
 326.182 +  extractCallback->SetTotal(m_PackSize);
 326.183 +
 326.184 +  UInt64 currentTotalPacked = 0;
 326.185 +  
 326.186 +  RINOK(extractCallback->SetCompleted(&currentTotalPacked));
 326.187 +  CMyComPtr<ISequentialOutStream> realOutStream;
 326.188 +  Int32 askMode;
 326.189 +  askMode = testMode ? NArchive::NExtract::NAskMode::kTest :
 326.190 +      NArchive::NExtract::NAskMode::kExtract;
 326.191 +  
 326.192 +  RINOK(extractCallback->GetStream(0, &realOutStream, askMode));
 326.193 +  
 326.194 +  if(!testMode && !realOutStream)
 326.195 +    return S_OK;
 326.196 +
 326.197 +  extractCallback->PrepareOperation(askMode);
 326.198 +
 326.199 +  COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC;
 326.200 +  CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
 326.201 +  outStreamSpec->SetStream(realOutStream);
 326.202 +  outStreamSpec->Init();
 326.203 +  realOutStream.Release();
 326.204 +
 326.205 +  CLocalProgress *lps = new CLocalProgress;
 326.206 +  CMyComPtr<ICompressProgressInfo> progress = lps;
 326.207 +  lps->Init(extractCallback, true);
 326.208 +
 326.209 +  CMyComPtr<ICompressCoder> deflateDecoder;
 326.210 +  bool firstItem = true;
 326.211 +  RINOK(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL));
 326.212 +  Int32 opRes;
 326.213 +  for (;;)
 326.214 +  {
 326.215 +    lps->InSize = currentTotalPacked;
 326.216 +    lps->OutSize = outStreamSpec->GetSize();
 326.217 +
 326.218 +    CInArchive archive;
 326.219 +    CItem item;
 326.220 +    HRESULT result = archive.ReadHeader(m_Stream, item);
 326.221 +    if (result != S_OK)
 326.222 +    {
 326.223 +      if (firstItem)
 326.224 +        return E_FAIL;
 326.225 +      opRes = NArchive::NExtract::NOperationResult::kOK;
 326.226 +      break;
 326.227 +    }
 326.228 +    firstItem = false;
 326.229 +
 326.230 +    UInt64 dataStartPos;
 326.231 +    RINOK(m_Stream->Seek(0, STREAM_SEEK_CUR, &dataStartPos));
 326.232 +
 326.233 +    outStreamSpec->InitCRC();
 326.234 +
 326.235 +    if (item.CompressionMethod != NFileHeader::NCompressionMethod::kDeflate)
 326.236 +    {
 326.237 +      opRes = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
 326.238 +      break;
 326.239 +    }
 326.240 +
 326.241 +    if (!deflateDecoder)
 326.242 +    {
 326.243 +      RINOK(CreateCoder(
 326.244 +          EXTERNAL_CODECS_VARS
 326.245 +          kMethodId_Deflate, deflateDecoder, false));
 326.246 +      if (!deflateDecoder)
 326.247 +      {
 326.248 +        opRes = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
 326.249 +        break;
 326.250 +      }
 326.251 +    }
 326.252 +    result = deflateDecoder->Code(m_Stream, outStream, NULL, NULL, progress);
 326.253 +    if (result != S_OK)
 326.254 +    {
 326.255 +      if (result != S_FALSE)
 326.256 +        return result;
 326.257 +      opRes = NArchive::NExtract::NOperationResult::kDataError;
 326.258 +      break;
 326.259 +    }
 326.260 +
 326.261 +    CMyComPtr<ICompressGetInStreamProcessedSize> getInStreamProcessedSize;
 326.262 +    RINOK(deflateDecoder.QueryInterface(IID_ICompressGetInStreamProcessedSize,
 326.263 +        &getInStreamProcessedSize));
 326.264 +    UInt64 packSize;
 326.265 +    RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(&packSize));
 326.266 +    UInt64 pos;
 326.267 +    RINOK(m_Stream->Seek(dataStartPos + packSize, STREAM_SEEK_SET, &pos));
 326.268 +
 326.269 +    currentTotalPacked = pos - m_StreamStartPosition;
 326.270 +    
 326.271 +    CItem postItem;
 326.272 +    if (archive.ReadPostHeader(m_Stream, postItem) != S_OK)
 326.273 +      return E_FAIL;
 326.274 +    if((outStreamSpec->GetCRC() != postItem.FileCRC))
 326.275 +    {
 326.276 +      opRes = NArchive::NExtract::NOperationResult::kCRCError;
 326.277 +      break;
 326.278 +    }
 326.279 +  }
 326.280 +  outStream.Release();
 326.281 +  return extractCallback->SetOperationResult(opRes);
 326.282 +  COM_TRY_END
 326.283 +}
 326.284 +
 326.285 +IMPL_ISetCompressCodecsInfo
 326.286 +
 326.287 +}}
   327.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   327.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipHandler.h	Sat Mar 03 10:31:27 2012 -0600
   327.3 @@ -0,0 +1,65 @@
   327.4 +// GZip/Handler.h
   327.5 +
   327.6 +#ifndef __GZIP_HANDLER_H
   327.7 +#define __GZIP_HANDLER_H
   327.8 +
   327.9 +#include "Common/MyCom.h"
  327.10 +
  327.11 +#include "../IArchive.h"
  327.12 +
  327.13 +#include "../../Common/CreateCoder.h"
  327.14 +
  327.15 +#include "GZipIn.h"
  327.16 +#include "GZipUpdate.h"
  327.17 +
  327.18 +namespace NArchive {
  327.19 +namespace NGZip {
  327.20 +
  327.21 +class CHandler:
  327.22 +  public IInArchive,
  327.23 +  public IOutArchive,
  327.24 +  public ISetProperties,
  327.25 +  PUBLIC_ISetCompressCodecsInfo
  327.26 +  public CMyUnknownImp
  327.27 +{
  327.28 +public:
  327.29 +  MY_QUERYINTERFACE_BEGIN2(IInArchive)
  327.30 +  MY_QUERYINTERFACE_ENTRY(IOutArchive)
  327.31 +  MY_QUERYINTERFACE_ENTRY(ISetProperties)
  327.32 +  QUERY_ENTRY_ISetCompressCodecsInfo
  327.33 +  MY_QUERYINTERFACE_END
  327.34 +  MY_ADDREF_RELEASE
  327.35 +
  327.36 +  INTERFACE_IInArchive(;)
  327.37 +#ifndef EXTRACT_ONLY
  327.38 +  INTERFACE_IOutArchive(;)
  327.39 +
  327.40 +  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);
  327.41 +#endif
  327.42 +
  327.43 +  DECL_ISetCompressCodecsInfo
  327.44 +
  327.45 +  CHandler() { InitMethodProperties(); }
  327.46 +
  327.47 +private:
  327.48 +  NArchive::NGZip::CItem m_Item;
  327.49 +  UInt64 m_StreamStartPosition;
  327.50 +  UInt64 m_DataOffset;
  327.51 +  UInt64 m_PackSize;
  327.52 +  CMyComPtr<IInStream> m_Stream;
  327.53 +  CCompressionMethodMode m_Method;
  327.54 +  UInt32 m_Level;
  327.55 +
  327.56 +  DECL_EXTERNAL_CODECS_VARS
  327.57 +
  327.58 +  void InitMethodProperties()
  327.59 +  {
  327.60 +    m_Method.NumMatchFinderCyclesDefined = false;
  327.61 +    m_Level = m_Method.NumPasses = m_Method.NumFastBytes =
  327.62 +        m_Method.NumMatchFinderCycles = m_Method.Algo = 0xFFFFFFFF;
  327.63 +  }
  327.64 +};
  327.65 +
  327.66 +}}
  327.67 +
  327.68 +#endif
   328.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   328.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipHeader.cpp	Sat Mar 03 10:31:27 2012 -0600
   328.3 @@ -0,0 +1,20 @@
   328.4 +// Archive/GZip/Header.h
   328.5 +
   328.6 +#include "StdAfx.h"
   328.7 +
   328.8 +#include "GZipHeader.h"
   328.9 +
  328.10 +namespace NArchive {
  328.11 +namespace NGZip {
  328.12 +
  328.13 +extern UInt16 kSignature = 0x8B1F + 1;
  328.14 +
  328.15 +class CMarkersInitializer
  328.16 +{
  328.17 +public:
  328.18 +  CMarkersInitializer()
  328.19 +    { kSignature--; }
  328.20 +} g_MarkerInitializer;
  328.21 +
  328.22 +}}
  328.23 +
   329.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   329.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipHeader.h	Sat Mar 03 10:31:27 2012 -0600
   329.3 @@ -0,0 +1,85 @@
   329.4 +// Archive/GZip/Header.h
   329.5 +
   329.6 +#ifndef __ARCHIVE_GZIP_HEADER_H
   329.7 +#define __ARCHIVE_GZIP_HEADER_H
   329.8 +
   329.9 +#include "Common/Types.h"
  329.10 +
  329.11 +namespace NArchive {
  329.12 +namespace NGZip {
  329.13 +
  329.14 +extern UInt16 kSignature;
  329.15 +static const UInt32 kSignatureSize = 2;
  329.16 +
  329.17 +namespace NFileHeader
  329.18 +{
  329.19 +  /*
  329.20 +  struct CBlock
  329.21 +  {
  329.22 +    UInt16 Id;
  329.23 +    Byte CompressionMethod;
  329.24 +    Byte Flags;
  329.25 +    UInt32 Time;
  329.26 +    Byte ExtraFlags;
  329.27 +    Byte HostOS;
  329.28 +  };
  329.29 +  */
  329.30 +  
  329.31 +  namespace NFlags
  329.32 +  {
  329.33 +    const int kDataIsText = 1 << 0;
  329.34 +    const int kHeaderCRCIsPresent = 1 << 1;
  329.35 +    const int kExtraIsPresent = 1 << 2;
  329.36 +    const int kNameIsPresent = 1 << 3;
  329.37 +    const int kComentIsPresent = 1 << 4;
  329.38 +  }
  329.39 +  
  329.40 +  namespace NExtraFlags
  329.41 +  {
  329.42 +    enum EEnum
  329.43 +    {
  329.44 +      kMaximum = 2,
  329.45 +      kFastest = 4
  329.46 +    };
  329.47 +  }
  329.48 +  
  329.49 +  namespace NCompressionMethod
  329.50 +  {
  329.51 +    const Byte kDeflate = 8;
  329.52 +  }
  329.53 +
  329.54 +  namespace NHostOS
  329.55 +  {
  329.56 +    enum EEnum
  329.57 +    {
  329.58 +      kFAT      = 0,  // filesystem used by MS-DOS, OS/2, Win32
  329.59 +        // pkzip 2.50 (FAT / VFAT / FAT32 file systems)
  329.60 +        kAMIGA    = 1,
  329.61 +        kVMS      = 2,  // VAX/VMS
  329.62 +        kUnix     = 3,
  329.63 +        kVM_CMS   = 4,
  329.64 +        kAtari    = 5,  // what if it's a minix filesystem? [cjh]
  329.65 +        kHPFS     = 6,  // filesystem used by OS/2 (and NT 3.x)
  329.66 +        kMac      = 7,
  329.67 +        kZ_System = 8,
  329.68 +        kCPM      = 9,
  329.69 +        kTOPS20   = 10, // pkzip 2.50 NTFS
  329.70 +        kNTFS     = 11, // filesystem used by Windows NT
  329.71 +        kQDOS     = 12, // SMS/QDOS
  329.72 +        kAcorn    = 13, // Archimedes Acorn RISC OS
  329.73 +        kVFAT     = 14, // filesystem used by Windows 95, NT
  329.74 +        kMVS      = 15,
  329.75 +        kBeOS     = 16, // hybrid POSIX/database filesystem
  329.76 +                        // BeBOX or PowerMac
  329.77 +        kTandem   = 17,
  329.78 +        kTHEOS    = 18,
  329.79 +
  329.80 +        kUnknown = 255
  329.81 +    };
  329.82 +    const int kNumHostSystems = 19;
  329.83 +  }
  329.84 +}
  329.85 +
  329.86 +}}
  329.87 +
  329.88 +#endif
   330.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   330.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipIn.cpp	Sat Mar 03 10:31:27 2012 -0600
   330.3 @@ -0,0 +1,119 @@
   330.4 +// Archive/GZipIn.cpp
   330.5 +
   330.6 +#include "StdAfx.h"
   330.7 +
   330.8 +#include "GZipIn.h"
   330.9 +
  330.10 +#include "Common/Defs.h"
  330.11 +#include "Common/MyCom.h"
  330.12 +#include "Windows/Defs.h"
  330.13 +
  330.14 +#include "../../Common/StreamUtils.h"
  330.15 +
  330.16 +extern "C"
  330.17 +{
  330.18 +  #include "../../../../C/7zCrc.h"
  330.19 +}
  330.20 +
  330.21 +namespace NArchive {
  330.22 +namespace NGZip {
  330.23 + 
  330.24 +HRESULT CInArchive::ReadBytes(ISequentialInStream *inStream, void *data, UInt32 size)
  330.25 +{
  330.26 +  RINOK(ReadStream_FALSE(inStream, data, size));
  330.27 +  m_Position += size;
  330.28 +  return S_OK;
  330.29 +}
  330.30 +
  330.31 +HRESULT CInArchive::ReadByte(ISequentialInStream *inStream, Byte &value, UInt32 &crc)
  330.32 +{
  330.33 +  RINOK(ReadBytes(inStream, &value, 1));
  330.34 +  crc = CRC_UPDATE_BYTE(crc, value);
  330.35 +  return S_OK;
  330.36 +}
  330.37 +
  330.38 +HRESULT CInArchive::ReadUInt16(ISequentialInStream *inStream, UInt16 &value, UInt32 &crc)
  330.39 +{
  330.40 +  value = 0;
  330.41 +  for (int i = 0; i < 2; i++)
  330.42 +  {
  330.43 +    Byte b;
  330.44 +    RINOK(ReadByte(inStream, b, crc));
  330.45 +    value |= (UInt16(b) << (8 * i));
  330.46 +  }
  330.47 +  return S_OK;
  330.48 +}
  330.49 +
  330.50 +HRESULT CInArchive::ReadUInt32(ISequentialInStream *inStream, UInt32 &value, UInt32 &crc)
  330.51 +{
  330.52 +  value = 0;
  330.53 +  for (int i = 0; i < 4; i++)
  330.54 +  {
  330.55 +    Byte b;
  330.56 +    RINOK(ReadByte(inStream, b, crc));
  330.57 +    value |= (UInt32(b) << (8 * i));
  330.58 +  }
  330.59 +  return S_OK;
  330.60 +}
  330.61 +
  330.62 +HRESULT CInArchive::ReadZeroTerminatedString(ISequentialInStream *inStream, AString &resString, UInt32 &crc)
  330.63 +{
  330.64 +  resString.Empty();
  330.65 +  for (;;)
  330.66 +  {
  330.67 +    Byte c;
  330.68 +    RINOK(ReadByte(inStream, c, crc));
  330.69 +    if (c == 0)
  330.70 +      return S_OK;
  330.71 +    resString += char(c);
  330.72 +  }
  330.73 +}
  330.74 +
  330.75 +HRESULT CInArchive::ReadHeader(ISequentialInStream *inStream, CItem &item)
  330.76 +{
  330.77 +  item.Clear();
  330.78 +  m_Position = 0;
  330.79 +
  330.80 +  UInt16 signature;
  330.81 +  UInt32 crc = CRC_INIT_VAL;;
  330.82 +  RINOK(ReadUInt16(inStream, signature, crc));
  330.83 +  if (signature != kSignature)
  330.84 +    return S_FALSE;
  330.85 +  
  330.86 +  RINOK(ReadByte(inStream, item.CompressionMethod, crc));
  330.87 +  RINOK(ReadByte(inStream, item.Flags, crc));
  330.88 +  RINOK(ReadUInt32(inStream, item.Time, crc));
  330.89 +  RINOK(ReadByte(inStream, item.ExtraFlags, crc));
  330.90 +  RINOK(ReadByte(inStream, item.HostOS, crc));
  330.91 +  
  330.92 +  if (item.ExtraFieldIsPresent())
  330.93 +  {
  330.94 +    UInt16 extraSize;
  330.95 +    RINOK(ReadUInt16(inStream, extraSize, crc));
  330.96 +    item.Extra.SetCapacity(extraSize);
  330.97 +    RINOK(ReadBytes(inStream, item.Extra, extraSize));
  330.98 +    crc = CrcUpdate(crc, item.Extra, extraSize);
  330.99 +  }
 330.100 +  if (item.NameIsPresent())
 330.101 +    RINOK(ReadZeroTerminatedString(inStream, item.Name, crc));
 330.102 +  if (item.CommentIsPresent())
 330.103 +    RINOK(ReadZeroTerminatedString(inStream, item.Comment, crc));
 330.104 +  if (item.HeaderCRCIsPresent())
 330.105 +  {
 330.106 +    UInt16 headerCRC;
 330.107 +    UInt32 dummy = 0;
 330.108 +    RINOK(ReadUInt16(inStream, headerCRC, dummy));
 330.109 +    if ((UInt16)CRC_GET_DIGEST(crc) != headerCRC)
 330.110 +      return S_FALSE;
 330.111 +  }
 330.112 +  return S_OK;
 330.113 +}
 330.114 +
 330.115 +HRESULT CInArchive::ReadPostHeader(ISequentialInStream *inStream, CItem &item)
 330.116 +{
 330.117 +  UInt32 dummy = 0;
 330.118 +  RINOK(ReadUInt32(inStream, item.FileCRC, dummy));
 330.119 +  return ReadUInt32(inStream, item.UnPackSize32, dummy);
 330.120 +}
 330.121 +
 330.122 +}}
   331.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   331.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipIn.h	Sat Mar 03 10:31:27 2012 -0600
   331.3 @@ -0,0 +1,30 @@
   331.4 +// Archive/GZipIn.h
   331.5 +
   331.6 +#ifndef __ARCHIVE_GZIP_IN_H
   331.7 +#define __ARCHIVE_GZIP_IN_H
   331.8 +
   331.9 +#include "GZipHeader.h"
  331.10 +#include "GZipItem.h"
  331.11 +#include "../../IStream.h"
  331.12 +
  331.13 +namespace NArchive {
  331.14 +namespace NGZip {
  331.15 +  
  331.16 +class CInArchive
  331.17 +{
  331.18 +  UInt64 m_Position;
  331.19 +  
  331.20 +  HRESULT ReadBytes(ISequentialInStream *inStream, void *data, UInt32 size);
  331.21 +  HRESULT ReadZeroTerminatedString(ISequentialInStream *inStream, AString &resString, UInt32 &crc);
  331.22 +  HRESULT ReadByte(ISequentialInStream *inStream, Byte &value, UInt32 &crc);
  331.23 +  HRESULT ReadUInt16(ISequentialInStream *inStream, UInt16 &value, UInt32 &crc);
  331.24 +  HRESULT ReadUInt32(ISequentialInStream *inStream, UInt32 &value, UInt32 &crc);
  331.25 +public:
  331.26 +  HRESULT ReadHeader(ISequentialInStream *inStream, CItem &item);
  331.27 +  HRESULT ReadPostHeader(ISequentialInStream *inStream, CItem &item);
  331.28 +  UInt64 GetOffset() const { return m_Position; }
  331.29 +};
  331.30 +  
  331.31 +}}
  331.32 +  
  331.33 +#endif
   332.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   332.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipItem.h	Sat Mar 03 10:31:27 2012 -0600
   332.3 @@ -0,0 +1,59 @@
   332.4 +// Archive/GZipItem.h
   332.5 +
   332.6 +#ifndef __ARCHIVE_GZIP_ITEM_H
   332.7 +#define __ARCHIVE_GZIP_ITEM_H
   332.8 +
   332.9 +#include "Common/Types.h"
  332.10 +#include "Common/MyString.h"
  332.11 +#include "Common/Buffer.h"
  332.12 +
  332.13 +namespace NArchive {
  332.14 +namespace NGZip {
  332.15 +
  332.16 +class CItem
  332.17 +{
  332.18 +private:
  332.19 +  bool TestFlag(Byte flag) const { return ((Flags & flag) != 0); }
  332.20 +public:
  332.21 +  Byte CompressionMethod;
  332.22 +  Byte Flags;
  332.23 +  UInt32 Time;
  332.24 +  Byte ExtraFlags;
  332.25 +  Byte HostOS;
  332.26 +  UInt32 FileCRC;
  332.27 +  UInt32 UnPackSize32;
  332.28 +
  332.29 +  AString Name;
  332.30 +  AString Comment;
  332.31 +  CByteBuffer Extra;
  332.32 +
  332.33 +  bool IsText() const
  332.34 +    {  return TestFlag(NFileHeader::NFlags::kDataIsText); }
  332.35 +  bool HeaderCRCIsPresent() const
  332.36 +    {  return TestFlag(NFileHeader::NFlags::kHeaderCRCIsPresent); }
  332.37 +  bool ExtraFieldIsPresent() const
  332.38 +    {  return TestFlag(NFileHeader::NFlags::kExtraIsPresent); }
  332.39 +  bool NameIsPresent() const
  332.40 +    {  return TestFlag(NFileHeader::NFlags::kNameIsPresent); }
  332.41 +  bool CommentIsPresent() const
  332.42 +    {  return TestFlag(NFileHeader::NFlags::kComentIsPresent); }
  332.43 +
  332.44 +  void SetNameIsPresentFlag(bool nameIsPresent)
  332.45 +  {
  332.46 +    if (nameIsPresent)
  332.47 +      Flags |= NFileHeader::NFlags::kNameIsPresent;
  332.48 +    else
  332.49 +      Flags &= (~NFileHeader::NFlags::kNameIsPresent);
  332.50 +  }
  332.51 +
  332.52 +  void Clear()
  332.53 +  {
  332.54 +    Name.Empty();
  332.55 +    Comment.Empty();;
  332.56 +    Extra.SetCapacity(0);
  332.57 +  }
  332.58 +};
  332.59 +
  332.60 +}}
  332.61 +
  332.62 +#endif
   333.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   333.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   333.3 @@ -0,0 +1,18 @@
   333.4 +// GZipRegister.cpp
   333.5 +
   333.6 +#include "StdAfx.h"
   333.7 +
   333.8 +#include "../../Common/RegisterArc.h"
   333.9 +
  333.10 +#include "GZipHandler.h"
  333.11 +static IInArchive *CreateArc() { return new NArchive::NGZip::CHandler;  }
  333.12 +#ifndef EXTRACT_ONLY
  333.13 +static IOutArchive *CreateArcOut() { return new NArchive::NGZip::CHandler;  }
  333.14 +#else
  333.15 +#define CreateArcOut 0
  333.16 +#endif
  333.17 +
  333.18 +static CArcInfo g_ArcInfo =
  333.19 +  { L"GZip", L"gz gzip tgz tpz", L"* * .tar .tar", 0xEF, { 0x1F, 0x8B, 8 }, 3, true, CreateArc, CreateArcOut };
  333.20 +
  333.21 +REGISTER_ARC(GZip)
   334.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   334.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipUpdate.h	Sat Mar 03 10:31:27 2012 -0600
   334.3 @@ -0,0 +1,39 @@
   334.4 +// GZip/Update.h
   334.5 +
   334.6 +#ifndef __GZIP_UPDATE_H
   334.7 +#define __GZIP_UPDATE_H
   334.8 +
   334.9 +#include "../IArchive.h"
  334.10 +
  334.11 +#include "../../Common/CreateCoder.h"
  334.12 +
  334.13 +#ifndef EXTRACT_ONLY
  334.14 +#include "GZipOut.h"
  334.15 +#endif
  334.16 +#include "GZipItem.h"
  334.17 +
  334.18 +namespace NArchive {
  334.19 +namespace NGZip {
  334.20 +
  334.21 +struct CCompressionMethodMode
  334.22 +{
  334.23 +  UInt32 NumPasses;
  334.24 +  UInt32 NumFastBytes;
  334.25 +  UInt32 Algo;
  334.26 +  bool NumMatchFinderCyclesDefined;
  334.27 +  UInt32 NumMatchFinderCycles;
  334.28 +};
  334.29 +
  334.30 +HRESULT UpdateArchive(
  334.31 +    DECL_EXTERNAL_CODECS_LOC_VARS
  334.32 +    IInStream *inStream,
  334.33 +    UInt64 unpackSize,
  334.34 +    ISequentialOutStream *outStream,
  334.35 +    const CItem &newItem,
  334.36 +    const CCompressionMethodMode &compressionMethod,
  334.37 +    int indexInClient,
  334.38 +    IArchiveUpdateCallback *updateCallback);
  334.39 +
  334.40 +}}
  334.41 +
  334.42 +#endif
   335.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   335.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/GZip/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   335.3 @@ -0,0 +1,8 @@
   335.4 +// StdAfx.h
   335.5 +
   335.6 +#ifndef __STDAFX_H
   335.7 +#define __STDAFX_H
   335.8 +
   335.9 +#include "../../../Common/MyWindows.h"
  335.10 +
  335.11 +#endif
   336.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   336.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/IArchive.h	Sat Mar 03 10:31:27 2012 -0600
   336.3 @@ -0,0 +1,237 @@
   336.4 +// IArchive.h
   336.5 +
   336.6 +#ifndef __IARCHIVE_H
   336.7 +#define __IARCHIVE_H
   336.8 +
   336.9 +#include "../IStream.h"
  336.10 +#include "../IProgress.h"
  336.11 +#include "../PropID.h"
  336.12 +
  336.13 +#define ARCHIVE_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 6, x)
  336.14 +#define ARCHIVE_INTERFACE(i, x) ARCHIVE_INTERFACE_SUB(i, IUnknown, x)
  336.15 +
  336.16 +namespace NFileTimeType
  336.17 +{
  336.18 +  enum EEnum
  336.19 +  {
  336.20 +    kWindows,
  336.21 +    kUnix,
  336.22 +    kDOS
  336.23 +  };
  336.24 +}
  336.25 +
  336.26 +namespace NArchive
  336.27 +{
  336.28 +  enum
  336.29 +  {
  336.30 +    kName = 0,
  336.31 +    kClassID,
  336.32 +    kExtension,
  336.33 +    kAddExtension,
  336.34 +    kUpdate,
  336.35 +    kKeepName,
  336.36 +    kStartSignature,
  336.37 +    kFinishSignature,
  336.38 +    kAssociate
  336.39 +  };
  336.40 +
  336.41 +  namespace NExtract
  336.42 +  {
  336.43 +    namespace NAskMode
  336.44 +    {
  336.45 +      enum
  336.46 +      {
  336.47 +        kExtract = 0,
  336.48 +        kTest,
  336.49 +        kSkip
  336.50 +      };
  336.51 +    }
  336.52 +    namespace NOperationResult
  336.53 +    {
  336.54 +      enum
  336.55 +      {
  336.56 +        kOK = 0,
  336.57 +        kUnSupportedMethod,
  336.58 +        kDataError,
  336.59 +        kCRCError
  336.60 +      };
  336.61 +    }
  336.62 +  }
  336.63 +  namespace NUpdate
  336.64 +  {
  336.65 +    namespace NOperationResult
  336.66 +    {
  336.67 +      enum
  336.68 +      {
  336.69 +        kOK = 0,
  336.70 +        kError
  336.71 +      };
  336.72 +    }
  336.73 +  }
  336.74 +}
  336.75 +
  336.76 +#define INTERFACE_IArchiveOpenCallback(x) \
  336.77 +  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes) x; \
  336.78 +  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes) x; \
  336.79 +
  336.80 +ARCHIVE_INTERFACE(IArchiveOpenCallback, 0x10)
  336.81 +{
  336.82 +  INTERFACE_IArchiveOpenCallback(PURE);
  336.83 +};
  336.84 +
  336.85 +
  336.86 +#define INTERFACE_IArchiveExtractCallback(x) \
  336.87 +  INTERFACE_IProgress(x) \
  336.88 +  /* GetStream OUT: S_OK - OK, S_FALSE - skeep this file */ \
  336.89 +  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream,  Int32 askExtractMode) x; \
  336.90 +  STDMETHOD(PrepareOperation)(Int32 askExtractMode) x; \
  336.91 +  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult) x; \
  336.92 +
  336.93 +ARCHIVE_INTERFACE_SUB(IArchiveExtractCallback, IProgress, 0x20)
  336.94 +{
  336.95 +  INTERFACE_IArchiveExtractCallback(PURE)
  336.96 +};
  336.97 +
  336.98 +
  336.99 +#define INTERFACE_IArchiveOpenVolumeCallback(x) \
 336.100 +  STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value) x; \
 336.101 +  STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream) x; \
 336.102 +
 336.103 +ARCHIVE_INTERFACE(IArchiveOpenVolumeCallback, 0x30)
 336.104 +{
 336.105 +  INTERFACE_IArchiveOpenVolumeCallback(PURE);
 336.106 +};
 336.107 +
 336.108 +
 336.109 +ARCHIVE_INTERFACE(IInArchiveGetStream, 0x40)
 336.110 +{
 336.111 +  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream) PURE;
 336.112 +};
 336.113 +
 336.114 +
 336.115 +ARCHIVE_INTERFACE(IArchiveOpenSetSubArchiveName, 0x50)
 336.116 +{
 336.117 +  STDMETHOD(SetSubArchiveName)(const wchar_t *name) PURE;
 336.118 +};
 336.119 +
 336.120 +
 336.121 +/*
 336.122 +IInArchive::Extract:
 336.123 +  indices must be sorted
 336.124 +  numItems = 0xFFFFFFFF means "all files"
 336.125 +  testMode != 0 means "test files without writing to outStream"
 336.126 +*/
 336.127 +
 336.128 +#define INTERFACE_IInArchive(x) \
 336.129 +  STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openArchiveCallback) x; \
 336.130 +  STDMETHOD(Close)() x; \
 336.131 +  STDMETHOD(GetNumberOfItems)(UInt32 *numItems) x; \
 336.132 +  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \
 336.133 +  STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback) x; \
 336.134 +  STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) x; \
 336.135 +  STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties) x; \
 336.136 +  STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x; \
 336.137 +  STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties) x; \
 336.138 +  STDMETHOD(GetArchivePropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x;
 336.139 +
 336.140 +ARCHIVE_INTERFACE(IInArchive, 0x60)
 336.141 +{
 336.142 +  INTERFACE_IInArchive(PURE)
 336.143 +  virtual ~IInArchive() {}
 336.144 +};
 336.145 +
 336.146 +
 336.147 +#define INTERFACE_IArchiveUpdateCallback(x) \
 336.148 +  INTERFACE_IProgress(x); \
 336.149 +  STDMETHOD(GetUpdateItemInfo)(UInt32 index,  \
 336.150 +      Int32 *newData, /*1 - new data, 0 - old data */ \
 336.151 +      Int32 *newProperties, /* 1 - new properties, 0 - old properties */ \
 336.152 +      UInt32 *indexInArchive /* -1 if there is no in archive, or if doesn't matter */ \
 336.153 +      )  x; \
 336.154 +  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \
 336.155 +  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream) x; \
 336.156 +  STDMETHOD(SetOperationResult)(Int32 operationResult) x; \
 336.157 +
 336.158 +ARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback, IProgress, 0x80)
 336.159 +{
 336.160 +  INTERFACE_IArchiveUpdateCallback(PURE);
 336.161 +};
 336.162 +
 336.163 +#define INTERFACE_IArchiveUpdateCallback2(x) \
 336.164 +  INTERFACE_IArchiveUpdateCallback(x) \
 336.165 +  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size) x; \
 336.166 +  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream) x; \
 336.167 +
 336.168 +ARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback2, IArchiveUpdateCallback, 0x82)
 336.169 +{
 336.170 +  INTERFACE_IArchiveUpdateCallback2(PURE);
 336.171 +};
 336.172 +
 336.173 +
 336.174 +#ifndef EXTRACT_ONLY
 336.175 +#define INTERFACE_IOutArchive(x) \
 336.176 +  STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, IArchiveUpdateCallback *updateCallback) x; \
 336.177 +  STDMETHOD(GetFileTimeType)(UInt32 *type) x;
 336.178 +#else
 336.179 +#define INTERFACE_IOutArchive(x)
 336.180 +#endif
 336.181 +
 336.182 +ARCHIVE_INTERFACE(IOutArchive, 0xA0)
 336.183 +{
 336.184 +#ifndef EXTRACT_ONLY
 336.185 +  INTERFACE_IOutArchive(PURE)
 336.186 +#endif
 336.187 +};
 336.188 +
 336.189 +
 336.190 +ARCHIVE_INTERFACE(ISetProperties, 0x03)
 336.191 +{
 336.192 +#ifndef EXTRACT_ONLY
 336.193 +  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) PURE;
 336.194 +#endif
 336.195 +};
 336.196 +
 336.197 +
 336.198 +#define IMP_IInArchive_GetProp(k) \
 336.199 +  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \
 336.200 +    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \
 336.201 +    const STATPROPSTG &srcItem = k[index]; \
 336.202 +    *propID = srcItem.propid; *varType = srcItem.vt; *name = 0; return S_OK; } \
 336.203 +
 336.204 +#define IMP_IInArchive_GetProp_WITH_NAME(k) \
 336.205 +  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \
 336.206 +    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \
 336.207 +    const STATPROPSTG &srcItem = k[index]; \
 336.208 +    *propID = srcItem.propid; *varType = srcItem.vt; \
 336.209 +    if (srcItem.lpwstrName == 0) *name = 0; else *name = ::SysAllocString(srcItem.lpwstrName); return S_OK; } \
 336.210 +
 336.211 +#define IMP_IInArchive_Props \
 336.212 +  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \
 336.213 +    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \
 336.214 +  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp(kProps)
 336.215 +
 336.216 +#define IMP_IInArchive_Props_WITH_NAME \
 336.217 +  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \
 336.218 +    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \
 336.219 +  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kProps)
 336.220 +
 336.221 +
 336.222 +#define IMP_IInArchive_ArcProps \
 336.223 +  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \
 336.224 +    { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \
 336.225 +  STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp(kArcProps)
 336.226 +
 336.227 +#define IMP_IInArchive_ArcProps_WITH_NAME \
 336.228 +  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \
 336.229 +    { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \
 336.230 +  STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kArcProps)
 336.231 +
 336.232 +#define IMP_IInArchive_ArcProps_NO \
 336.233 +  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \
 336.234 +    { *numProperties = 0; return S_OK; } \
 336.235 +  STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32, BSTR *, PROPID *, VARTYPE *) \
 336.236 +    { return E_NOTIMPL; } \
 336.237 +  STDMETHODIMP CHandler::GetArchiveProperty(PROPID, PROPVARIANT *value) \
 336.238 +    { value->vt = VT_EMPTY; return S_OK; }
 336.239 +
 336.240 +#endif
   337.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   337.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhCRC.cpp	Sat Mar 03 10:31:27 2012 -0600
   337.3 @@ -0,0 +1,43 @@
   337.4 +// LzhCRC.cpp
   337.5 +
   337.6 +#include "StdAfx.h"
   337.7 +
   337.8 +#include "LzhCRC.h"
   337.9 +
  337.10 +namespace NArchive {
  337.11 +namespace NLzh {
  337.12 +
  337.13 +static const UInt16 kCRCPoly = 0xA001;
  337.14 +
  337.15 +UInt16 CCRC::Table[256];
  337.16 +
  337.17 +void CCRC::InitTable()
  337.18 +{
  337.19 +  for (UInt32 i = 0; i < 256; i++)
  337.20 +  {
  337.21 +    UInt32 r = i;
  337.22 +    for (int j = 0; j < 8; j++)
  337.23 +      if (r & 1)
  337.24 +        r = (r >> 1) ^ kCRCPoly;
  337.25 +      else
  337.26 +        r >>= 1;
  337.27 +    CCRC::Table[i] = (UInt16)r;
  337.28 +  }
  337.29 +}
  337.30 +
  337.31 +class CCRCTableInit
  337.32 +{
  337.33 +public:
  337.34 +  CCRCTableInit() { CCRC::InitTable(); }
  337.35 +} g_CRCTableInit;
  337.36 +
  337.37 +void CCRC::Update(const void *data, size_t size)
  337.38 +{
  337.39 +  UInt16 v = _value;
  337.40 +  const Byte *p = (const Byte *)data;
  337.41 +  for (; size > 0; size--, p++)
  337.42 +    v = (UInt16)(Table[((Byte)(v)) ^ *p] ^ (v >> 8));
  337.43 +  _value = v;
  337.44 +}
  337.45 +
  337.46 +}}
   338.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   338.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhCRC.h	Sat Mar 03 10:31:27 2012 -0600
   338.3 @@ -0,0 +1,27 @@
   338.4 +// LzhCRC.h
   338.5 +
   338.6 +#ifndef __LZH_CRC_H
   338.7 +#define __LZH_CRC_H
   338.8 +
   338.9 +#include <stddef.h>
  338.10 +#include "Common/Types.h"
  338.11 +
  338.12 +namespace NArchive {
  338.13 +namespace NLzh {
  338.14 +
  338.15 +class CCRC
  338.16 +{
  338.17 +  UInt16 _value;
  338.18 +public:
  338.19 +  static UInt16 Table[256];
  338.20 +  static void InitTable();
  338.21 +  
  338.22 +  CCRC():  _value(0){};
  338.23 +  void Init() { _value = 0; }
  338.24 +  void Update(const void *data, size_t size);
  338.25 +  UInt16 GetDigest() const { return _value; }
  338.26 +};
  338.27 +
  338.28 +}}
  338.29 +
  338.30 +#endif
   339.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   339.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhHandler.cpp	Sat Mar 03 10:31:27 2012 -0600
   339.3 @@ -0,0 +1,387 @@
   339.4 +// LzhHandler.cpp
   339.5 +
   339.6 +#include "StdAfx.h"
   339.7 +
   339.8 +#include "Common/ComTry.h"
   339.9 +#include "Common/Defs.h"
  339.10 +#include "Common/StringConvert.h"
  339.11 +
  339.12 +#include "Windows/PropVariant.h"
  339.13 +#include "Windows/Time.h"
  339.14 +
  339.15 +#include "LzhHandler.h"
  339.16 +#include "LzhOutStreamWithCRC.h"
  339.17 +
  339.18 +#include "../../ICoder.h"
  339.19 +
  339.20 +#include "../../Common/LimitedStreams.h"
  339.21 +#include "../../Common/ProgressUtils.h"
  339.22 +
  339.23 +#include "../../Compress/CopyCoder.h"
  339.24 +#include "../../Compress/LzhDecoder.h"
  339.25 +
  339.26 +#include "../Common/ItemNameUtils.h"
  339.27 +
  339.28 +using namespace NWindows;
  339.29 +using namespace NTime;
  339.30 +
  339.31 +namespace NArchive {
  339.32 +namespace NLzh{
  339.33 +
  339.34 +struct COsPair
  339.35 +{
  339.36 +  Byte Id;
  339.37 +  const wchar_t *Name;
  339.38 +};
  339.39 +
  339.40 +COsPair g_OsPairs[] =
  339.41 +{
  339.42 +  { 'M', L"MS-DOS" },
  339.43 +  { '2', L"OS/2" },
  339.44 +  { '9', L"OS9" },
  339.45 +  { 'K', L"OS/68K" },
  339.46 +  { '3', L"OS/386" },
  339.47 +  { 'H', L"HUMAN" },
  339.48 +  { 'U', L"UNIX" },
  339.49 +  { 'C', L"CP/M" },
  339.50 +  { 'F', L"FLEX" },
  339.51 +  { 'm', L"Mac" },
  339.52 +  { 'R', L"Runser" },
  339.53 +  { 'T', L"TownsOS" },
  339.54 +  { 'X', L"XOSK" },
  339.55 +  { 'w', L"Windows95" },
  339.56 +  { 'W', L"WindowsNT" },
  339.57 +  {  0,  L"MS-DOS" },
  339.58 +  { 'J', L"Java VM" }
  339.59 +};
  339.60 +
  339.61 +const wchar_t *kUnknownOS = L"Unknown";
  339.62 +
  339.63 +const int kNumHostOSes = sizeof(g_OsPairs) / sizeof(g_OsPairs[0]);
  339.64 +
  339.65 +static const wchar_t *GetOS(Byte osId)
  339.66 +{
  339.67 +  for (int i = 0; i < kNumHostOSes; i++)
  339.68 +    if (g_OsPairs[i].Id == osId)
  339.69 +      return g_OsPairs[i].Name;
  339.70 +  return kUnknownOS;
  339.71 +};
  339.72 +
  339.73 +STATPROPSTG kProps[] =
  339.74 +{
  339.75 +  { NULL, kpidPath, VT_BSTR},
  339.76 +  { NULL, kpidIsDir, VT_BOOL},
  339.77 +  { NULL, kpidSize, VT_UI8},
  339.78 +  { NULL, kpidPackSize, VT_UI8},
  339.79 +  { NULL, kpidMTime, VT_FILETIME},
  339.80 +  { NULL, kpidAttrib, VT_UI4},
  339.81 +
  339.82 +  // { NULL, kpidCommented, VT_BOOL},
  339.83 +    
  339.84 +  { NULL, kpidCRC, VT_UI4},
  339.85 +
  339.86 +  { NULL, kpidMethod, VT_UI1},
  339.87 +  { NULL, kpidHostOS, VT_BSTR}
  339.88 +
  339.89 +};
  339.90 +
  339.91 +IMP_IInArchive_Props
  339.92 +IMP_IInArchive_ArcProps_NO
  339.93 +
  339.94 +CHandler::CHandler() {}
  339.95 +
  339.96 +STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
  339.97 +{
  339.98 +  *numItems = _items.Size();
  339.99 +  return S_OK;
 339.100 +}
 339.101 +
 339.102 +STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)
 339.103 +{
 339.104 +  COM_TRY_BEGIN
 339.105 +  NWindows::NCOM::CPropVariant prop;
 339.106 +  const CItemEx &item = _items[index];
 339.107 +  switch(propID)
 339.108 +  {
 339.109 +    case kpidPath:
 339.110 +    {
 339.111 +      UString s = NItemName::WinNameToOSName(MultiByteToUnicodeString(item.GetName(), CP_OEMCP));
 339.112 +      if (!s.IsEmpty())
 339.113 +      {
 339.114 +        if (s[s.Length() - 1] == WCHAR_PATH_SEPARATOR)
 339.115 +           s.Delete(s.Length() - 1);
 339.116 +        prop = s;
 339.117 +      }
 339.118 +      break;
 339.119 +    }
 339.120 +    case kpidIsDir:  prop = item.IsDir(); break;
 339.121 +    case kpidSize:   prop = item.Size; break;
 339.122 +    case kpidPackSize:  prop = item.PackSize; break;
 339.123 +    case kpidCRC:  prop = (UInt32)item.CRC; break;
 339.124 +    case kpidHostOS:  prop = GetOS(item.OsId); break;
 339.125 +    case kpidMTime:
 339.126 +    {
 339.127 +      FILETIME utcFileTime;
 339.128 +      UInt32 unixTime;
 339.129 +      if (item.GetUnixTime(unixTime))
 339.130 +        NTime::UnixTimeToFileTime(unixTime, utcFileTime);
 339.131 +      else
 339.132 +      {
 339.133 +        FILETIME localFileTime;
 339.134 +        if (DosTimeToFileTime(item.ModifiedTime, localFileTime))
 339.135 +        {
 339.136 +          if (!LocalFileTimeToFileTime(&localFileTime, &utcFileTime))
 339.137 +            utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
 339.138 +        }
 339.139 +        else
 339.140 +          utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
 339.141 +      }
 339.142 +      prop = utcFileTime;
 339.143 +      break;
 339.144 +    }
 339.145 +    /*
 339.146 +    case kpidAttrib:  prop = (UInt32)item.Attributes; break;
 339.147 +    case kpidCommented:  prop = item.IsCommented(); break;
 339.148 +    */
 339.149 +    case kpidMethod:
 339.150 +    {
 339.151 +      wchar_t method2[kMethodIdSize + 1];
 339.152 +      method2[kMethodIdSize] = 0;
 339.153 +      for (int i = 0; i < kMethodIdSize; i++)
 339.154 +        method2[i] = item.Method[i];
 339.155 +      prop = method2;
 339.156 +      break;
 339.157 +    }
 339.158 +  }
 339.159 +  prop.Detach(value);
 339.160 +  return S_OK;
 339.161 +  COM_TRY_END
 339.162 +}
 339.163 +
 339.164 +/*
 339.165 +class CProgressImp: public CProgressVirt
 339.166 +{
 339.167 +public:
 339.168 +  CMyComPtr<IArchiveOpenCallback> Callback;
 339.169 +  STDMETHOD(SetCompleted)(const UInt64 *numFiles);
 339.170 +};
 339.171 +
 339.172 +STDMETHODIMP CProgressImp::SetCompleted(const UInt64 *numFiles)
 339.173 +{
 339.174 +  if (Callback)
 339.175 +    return Callback->SetCompleted(numFiles, NULL);
 339.176 +  return S_OK;
 339.177 +}
 339.178 +*/
 339.179 +
 339.180 +STDMETHODIMP CHandler::Open(IInStream *stream,
 339.181 +    const UInt64 * /* maxCheckStartPosition */, IArchiveOpenCallback *callback)
 339.182 +{
 339.183 +  COM_TRY_BEGIN
 339.184 +  try
 339.185 +  {
 339.186 +    _items.Clear();
 339.187 +    CInArchive archive;
 339.188 +
 339.189 +    UInt64 endPos = 0;
 339.190 +    bool needSetTotal = true;
 339.191 +
 339.192 +    if (callback != NULL)
 339.193 +    {
 339.194 +      RINOK(stream->Seek(0, STREAM_SEEK_END, &endPos));
 339.195 +      RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
 339.196 +    }
 339.197 +
 339.198 +    RINOK(archive.Open(stream));
 339.199 +    for (;;)
 339.200 +    {
 339.201 +      CItemEx item;
 339.202 +      bool filled;
 339.203 +      HRESULT result = archive.GetNextItem(filled, item);
 339.204 +      if (result == S_FALSE)
 339.205 +        return S_FALSE;
 339.206 +      if (result != S_OK)
 339.207 +        return S_FALSE;
 339.208 +      if (!filled)
 339.209 +        break;
 339.210 +      _items.Add(item);
 339.211 +      archive.Skeep(item.PackSize);
 339.212 +      if (callback != NULL)
 339.213 +      {
 339.214 +        if (needSetTotal)
 339.215 +        {
 339.216 +          RINOK(callback->SetTotal(NULL, &endPos));
 339.217 +          needSetTotal = false;
 339.218 +        }
 339.219 +        if (_items.Size() % 100 == 0)
 339.220 +        {
 339.221 +          UInt64 numFiles = _items.Size();
 339.222 +          UInt64 numBytes = item.DataPosition;
 339.223 +          RINOK(callback->SetCompleted(&numFiles, &numBytes));
 339.224 +        }
 339.225 +      }
 339.226 +    }
 339.227 +    if (_items.IsEmpty())
 339.228 +      return S_FALSE;
 339.229 +
 339.230 +    _stream = stream;
 339.231 +  }
 339.232 +  catch(...)
 339.233 +  {
 339.234 +    return S_FALSE;
 339.235 +  }
 339.236 +  COM_TRY_END
 339.237 +  return S_OK;
 339.238 +}
 339.239 +
 339.240 +STDMETHODIMP CHandler::Close()
 339.241 +{
 339.242 +  _items.Clear();
 339.243 +  _stream.Release();
 339.244 +  return S_OK;
 339.245 +}
 339.246 +
 339.247 +
 339.248 +
 339.249 +//////////////////////////////////////
 339.250 +// CHandler::DecompressItems
 339.251 +
 339.252 +STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
 339.253 +    Int32 testModeSpec, IArchiveExtractCallback *extractCallback)
 339.254 +{
 339.255 +  COM_TRY_BEGIN
 339.256 +  bool testMode = (testModeSpec != 0);
 339.257 +  UInt64 totalUnPacked = 0, totalPacked = 0;
 339.258 +  bool allFilesMode = (numItems == UInt32(-1));
 339.259 +  if (allFilesMode)
 339.260 +    numItems = _items.Size();
 339.261 +  if(numItems == 0)
 339.262 +    return S_OK;
 339.263 +  UInt32 i;
 339.264 +  for(i = 0; i < numItems; i++)
 339.265 +  {
 339.266 +    const CItemEx &item = _items[allFilesMode ? i : indices[i]];
 339.267 +    totalUnPacked += item.Size;
 339.268 +    totalPacked += item.PackSize;
 339.269 +  }
 339.270 +  extractCallback->SetTotal(totalUnPacked);
 339.271 +
 339.272 +  UInt64 currentTotalUnPacked = 0, currentTotalPacked = 0;
 339.273 +  UInt64 currentItemUnPacked, currentItemPacked;
 339.274 +  
 339.275 +  NCompress::NLzh::NDecoder::CCoder *lzhDecoderSpec = 0;
 339.276 +  CMyComPtr<ICompressCoder> lzhDecoder;
 339.277 +  CMyComPtr<ICompressCoder> lzh1Decoder;
 339.278 +  CMyComPtr<ICompressCoder> arj2Decoder;
 339.279 +
 339.280 +  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
 339.281 +  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
 339.282 +
 339.283 +  CLocalProgress *lps = new CLocalProgress;
 339.284 +  CMyComPtr<ICompressProgressInfo> progress = lps;
 339.285 +  lps->Init(extractCallback, false);
 339.286 +
 339.287 +  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
 339.288 +  CMyComPtr<ISequentialInStream> inStream(streamSpec);
 339.289 +  streamSpec->SetStream(_stream);
 339.290 +
 339.291 +  for(i = 0; i < numItems; i++, currentTotalUnPacked += currentItemUnPacked,
 339.292 +      currentTotalPacked += currentItemPacked)
 339.293 +  {
 339.294 +    currentItemUnPacked = 0;
 339.295 +    currentItemPacked = 0;
 339.296 +
 339.297 +    lps->InSize = currentTotalPacked;
 339.298 +    lps->OutSize = currentTotalUnPacked;
 339.299 +    RINOK(lps->SetCur());
 339.300 +
 339.301 +    CMyComPtr<ISequentialOutStream> realOutStream;
 339.302 +    Int32 askMode;
 339.303 +    askMode = testMode ? NExtract::NAskMode::kTest :
 339.304 +        NExtract::NAskMode::kExtract;
 339.305 +    Int32 index = allFilesMode ? i : indices[i];
 339.306 +    const CItemEx &item = _items[index];
 339.307 +    RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
 339.308 +
 339.309 +    if (item.IsDir())
 339.310 +    {
 339.311 +      // if (!testMode)
 339.312 +      {
 339.313 +        RINOK(extractCallback->PrepareOperation(askMode));
 339.314 +        RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
 339.315 +      }
 339.316 +      continue;
 339.317 +    }
 339.318 +
 339.319 +    if (!testMode && (!realOutStream))
 339.320 +      continue;
 339.321 +
 339.322 +    RINOK(extractCallback->PrepareOperation(askMode));
 339.323 +    currentItemUnPacked = item.Size;
 339.324 +    currentItemPacked = item.PackSize;
 339.325 +
 339.326 +    {
 339.327 +      COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC;
 339.328 +      CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
 339.329 +      outStreamSpec->Init(realOutStream);
 339.330 +      realOutStream.Release();
 339.331 +      
 339.332 +      UInt64 pos;
 339.333 +      _stream->Seek(item.DataPosition, STREAM_SEEK_SET, &pos);
 339.334 +
 339.335 +      streamSpec->Init(item.PackSize);
 339.336 +
 339.337 +      HRESULT result = S_OK;
 339.338 +      Int32 opRes = NExtract::NOperationResult::kOK;
 339.339 +
 339.340 +      if (item.IsCopyMethod())
 339.341 +      {
 339.342 +        result = copyCoder->Code(inStream, outStream, NULL, NULL, progress);
 339.343 +        if (result == S_OK && copyCoderSpec->TotalSize != item.PackSize)
 339.344 +          result = S_FALSE;
 339.345 +      }
 339.346 +      else if (item.IsLh4GroupMethod())
 339.347 +      {
 339.348 +        if (!lzhDecoder)
 339.349 +        {
 339.350 +          lzhDecoderSpec = new NCompress::NLzh::NDecoder::CCoder;
 339.351 +          lzhDecoder = lzhDecoderSpec;
 339.352 +        }
 339.353 +        lzhDecoderSpec->SetDictionary(item.GetNumDictBits());
 339.354 +        result = lzhDecoder->Code(inStream, outStream, NULL, &currentItemUnPacked, progress);
 339.355 +      }
 339.356 +      /*
 339.357 +      else if (item.IsLh1GroupMethod())
 339.358 +      {
 339.359 +        if (!lzh1Decoder)
 339.360 +        {
 339.361 +          lzh1DecoderSpec = new NCompress::NLzh1::NDecoder::CCoder;
 339.362 +          lzh1Decoder = lzh1DecoderSpec;
 339.363 +        }
 339.364 +        lzh1DecoderSpec->SetDictionary(item.GetNumDictBits());
 339.365 +        result = lzh1Decoder->Code(inStream, outStream, NULL, &currentItemUnPacked, progress);
 339.366 +      }
 339.367 +      */
 339.368 +      else
 339.369 +        opRes = NExtract::NOperationResult::kUnSupportedMethod;
 339.370 +
 339.371 +      if (opRes == NExtract::NOperationResult::kOK)
 339.372 +      {
 339.373 +        if (result == S_FALSE)
 339.374 +          opRes = NExtract::NOperationResult::kDataError;
 339.375 +        else
 339.376 +        {
 339.377 +          RINOK(result);
 339.378 +          if (outStreamSpec->GetCRC() != item.CRC)
 339.379 +            opRes = NExtract::NOperationResult::kCRCError;
 339.380 +        }
 339.381 +      }
 339.382 +      outStream.Release();
 339.383 +      RINOK(extractCallback->SetOperationResult(opRes));
 339.384 +    }
 339.385 +  }
 339.386 +  return S_OK;
 339.387 +  COM_TRY_END
 339.388 +}
 339.389 +
 339.390 +}}
   340.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   340.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhHandler.h	Sat Mar 03 10:31:27 2012 -0600
   340.3 @@ -0,0 +1,30 @@
   340.4 +// LzhHandler.h
   340.5 +
   340.6 +#ifndef __LZH_HANDLER_H
   340.7 +#define __LZH_HANDLER_H
   340.8 +
   340.9 +#include "Common/MyCom.h"
  340.10 +#include "../IArchive.h"
  340.11 +#include "LzhIn.h"
  340.12 +
  340.13 +namespace NArchive {
  340.14 +namespace NLzh {
  340.15 +
  340.16 +class CHandler:
  340.17 +  public IInArchive,
  340.18 +  public CMyUnknownImp
  340.19 +{
  340.20 +public:
  340.21 +  MY_UNKNOWN_IMP1(IInArchive)
  340.22 +
  340.23 +  INTERFACE_IInArchive(;)
  340.24 +
  340.25 +  CHandler();
  340.26 +private:
  340.27 +  CObjectVector<CItemEx> _items;
  340.28 +  CMyComPtr<IInStream> _stream;
  340.29 +};
  340.30 +
  340.31 +}}
  340.32 +
  340.33 +#endif
   341.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   341.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhHeader.h	Sat Mar 03 10:31:27 2012 -0600
   341.3 @@ -0,0 +1,19 @@
   341.4 +// Archive/Lzh/Header.h
   341.5 +
   341.6 +#ifndef __ARCHIVE_LZH_HEADER_H
   341.7 +#define __ARCHIVE_LZH_HEADER_H
   341.8 +
   341.9 +#include "Common/Types.h"
  341.10 +
  341.11 +namespace NArchive {
  341.12 +namespace NLzh {
  341.13 +
  341.14 +const int kMethodIdSize = 5;
  341.15 +
  341.16 +const Byte kExtIdFileName = 0x01;
  341.17 +const Byte kExtIdDirName  = 0x02;
  341.18 +const Byte kExtIdUnixTime = 0x54;
  341.19 +
  341.20 +}}
  341.21 +
  341.22 +#endif
   342.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   342.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhIn.cpp	Sat Mar 03 10:31:27 2012 -0600
   342.3 @@ -0,0 +1,172 @@
   342.4 +// Archive/LzhIn.cpp
   342.5 +
   342.6 +#include "StdAfx.h"
   342.7 +
   342.8 +#include "Common/StringConvert.h"
   342.9 +#include "Common/Buffer.h"
  342.10 +
  342.11 +#include "../../Common/StreamUtils.h"
  342.12 +
  342.13 +#include "LzhIn.h"
  342.14 +
  342.15 +namespace NArchive {
  342.16 +namespace NLzh {
  342.17 + 
  342.18 +HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
  342.19 +{
  342.20 +  size_t realProcessedSize = size;
  342.21 +  RINOK(ReadStream(m_Stream, data, &realProcessedSize));
  342.22 +  processedSize = (UInt32)realProcessedSize;
  342.23 +  m_Position += processedSize;
  342.24 +  return S_OK;
  342.25 +}
  342.26 +
  342.27 +HRESULT CInArchive::CheckReadBytes(void *data, UInt32 size)
  342.28 +{
  342.29 +  UInt32 processedSize;
  342.30 +  RINOK(ReadBytes(data, size, processedSize));
  342.31 +  return (processedSize == size) ? S_OK: S_FALSE;
  342.32 +}
  342.33 +
  342.34 +HRESULT CInArchive::Open(IInStream *inStream)
  342.35 +{
  342.36 +  RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_Position));
  342.37 +  m_Stream = inStream;
  342.38 +  return S_OK;
  342.39 +}
  342.40 +
  342.41 +static const Byte *ReadUInt32(const Byte *p, UInt32 &v)
  342.42 +{
  342.43 +  v = 0;
  342.44 +  for (int i = 0; i < 4; i++)
  342.45 +    v |= ((UInt32)(*p++) << (i * 8));
  342.46 +  return p;
  342.47 +}
  342.48 +
  342.49 +static const Byte *ReadUInt16(const Byte *p, UInt16 &v)
  342.50 +{
  342.51 +  v = 0;
  342.52 +  for (int i = 0; i < 2; i++)
  342.53 +    v |= ((UInt16)(*p++) << (i * 8));
  342.54 +  return p;
  342.55 +}
  342.56 +
  342.57 +static const Byte *ReadString(const Byte *p, size_t size, AString &s)
  342.58 +{
  342.59 +  s.Empty();
  342.60 +  for (size_t i = 0; i < size; i++)
  342.61 +  {
  342.62 +    char c = p[i];
  342.63 +    if (c == 0)
  342.64 +      break;
  342.65 +    s += c;
  342.66 +  }
  342.67 +  return p + size;
  342.68 +}
  342.69 +
  342.70 +static Byte CalcSum(const Byte *data, size_t size)
  342.71 +{
  342.72 +  Byte sum = 0;
  342.73 +  for (size_t i = 0; i < size; i++)
  342.74 +    sum = (Byte)(sum + data[i]);
  342.75 +  return sum;
  342.76 +}
  342.77 +
  342.78 +HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item)
  342.79 +{
  342.80 +  filled = false;
  342.81 +
  342.82 +  UInt32 processedSize;
  342.83 +  Byte startHeader[2];
  342.84 +  RINOK(ReadBytes(startHeader, 2, processedSize))
  342.85 +  if (processedSize == 0)
  342.86 +    return S_OK;
  342.87 +  if (processedSize == 1)
  342.88 +    return (startHeader[0] == 0) ? S_OK: S_FALSE;
  342.89 +  if (startHeader[0] == 0 && startHeader[1] == 0)
  342.90 +    return S_OK;
  342.91 +
  342.92 +  Byte header[256];
  342.93 +  const UInt32 kBasicPartSize = 22;
  342.94 +  RINOK(ReadBytes(header, kBasicPartSize, processedSize));
  342.95 +  if (processedSize != kBasicPartSize)
  342.96 +    return (startHeader[0] == 0) ? S_OK: S_FALSE;
  342.97 +
  342.98 +  const Byte *p = header;
  342.99 +  memmove(item.Method, p, kMethodIdSize);
 342.100 +  if (!item.IsValidMethod())
 342.101 +    return S_OK;
 342.102 +  p += kMethodIdSize;
 342.103 +  p = ReadUInt32(p, item.PackSize);
 342.104 +  p = ReadUInt32(p, item.Size);
 342.105 +  p = ReadUInt32(p, item.ModifiedTime);
 342.106 +  item.Attributes = *p++;
 342.107 +  item.Level = *p++;
 342.108 +  if (item.Level > 2)
 342.109 +    return S_FALSE;
 342.110 +  UInt32 headerSize;
 342.111 +  if (item.Level < 2)
 342.112 +  {
 342.113 +    headerSize = startHeader[0];
 342.114 +    if (headerSize < kBasicPartSize)
 342.115 +      return S_FALSE;
 342.116 +    UInt32 remain = headerSize - kBasicPartSize;
 342.117 +    RINOK(CheckReadBytes(header + kBasicPartSize, remain));
 342.118 +    if (startHeader[1] != CalcSum(header, headerSize))
 342.119 +      return S_FALSE;
 342.120 +    size_t nameLength = *p++;
 342.121 +    if ((p - header) + nameLength + 2 > headerSize)
 342.122 +      return S_FALSE;
 342.123 +    p = ReadString(p, nameLength, item.Name);
 342.124 +  }
 342.125 +  else
 342.126 +   headerSize = startHeader[0] | ((UInt32)startHeader[1] << 8);
 342.127 +  p = ReadUInt16(p, item.CRC);
 342.128 +  if (item.Level != 0)
 342.129 +  {
 342.130 +    if (item.Level == 2)
 342.131 +    {
 342.132 +      RINOK(CheckReadBytes(header + kBasicPartSize, 2));
 342.133 +    }
 342.134 +    if ((size_t)(p - header) + 3 > headerSize)
 342.135 +      return S_FALSE;
 342.136 +    item.OsId = *p++;
 342.137 +    UInt16 nextSize;
 342.138 +    p = ReadUInt16(p, nextSize);
 342.139 +    while (nextSize != 0)
 342.140 +    {
 342.141 +      if (nextSize < 3)
 342.142 +        return S_FALSE;
 342.143 +      if (item.Level == 1)
 342.144 +      {
 342.145 +        if (item.PackSize < nextSize)
 342.146 +          return S_FALSE;
 342.147 +        item.PackSize -= nextSize;
 342.148 +      }
 342.149 +      CExtension ext;
 342.150 +      RINOK(CheckReadBytes(&ext.Type, 1))
 342.151 +      nextSize -= 3;
 342.152 +      ext.Data.SetCapacity(nextSize);
 342.153 +      RINOK(CheckReadBytes((Byte *)ext.Data, nextSize))
 342.154 +      item.Extensions.Add(ext);
 342.155 +      Byte hdr2[2];
 342.156 +      RINOK(CheckReadBytes(hdr2, 2));
 342.157 +      ReadUInt16(hdr2, nextSize);
 342.158 +    }
 342.159 +  }
 342.160 +  item.DataPosition = m_Position;
 342.161 +  filled = true;
 342.162 +  return S_OK;
 342.163 +}
 342.164 +
 342.165 +HRESULT CInArchive::Skeep(UInt64 numBytes)
 342.166 +{
 342.167 +  UInt64 newPostion;
 342.168 +  RINOK(m_Stream->Seek(numBytes, STREAM_SEEK_CUR, &newPostion));
 342.169 +  m_Position += numBytes;
 342.170 +  if (m_Position != newPostion)
 342.171 +    return E_FAIL;
 342.172 +  return S_OK;
 342.173 +}
 342.174 +
 342.175 +}}
   343.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   343.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhIn.h	Sat Mar 03 10:31:27 2012 -0600
   343.3 @@ -0,0 +1,29 @@
   343.4 +// Archive/LzhIn.h
   343.5 +
   343.6 +#ifndef __ARCHIVE_LZHIN_H
   343.7 +#define __ARCHIVE_LZHIN_H
   343.8 +
   343.9 +#include "Common/MyCom.h"
  343.10 +#include "../../IStream.h"
  343.11 +
  343.12 +#include "LzhItem.h"
  343.13 +
  343.14 +namespace NArchive {
  343.15 +namespace NLzh {
  343.16 +  
  343.17 +class CInArchive
  343.18 +{
  343.19 +  CMyComPtr<IInStream> m_Stream;
  343.20 +  UInt64 m_Position;
  343.21 +  
  343.22 +  HRESULT ReadBytes(void *data, UInt32 size, UInt32 &processedSize);
  343.23 +  HRESULT CheckReadBytes(void *data, UInt32 size);
  343.24 +public:
  343.25 +  HRESULT Open(IInStream *inStream);
  343.26 +  HRESULT GetNextItem(bool &filled, CItemEx &itemInfo);
  343.27 +  HRESULT Skeep(UInt64 numBytes);
  343.28 +};
  343.29 +  
  343.30 +}}
  343.31 +  
  343.32 +#endif
   344.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   344.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhItem.h	Sat Mar 03 10:31:27 2012 -0600
   344.3 @@ -0,0 +1,172 @@
   344.4 +// Archive/LzhItem.h
   344.5 +
   344.6 +#ifndef __ARCHIVE_LZH_ITEM_H
   344.7 +#define __ARCHIVE_LZH_ITEM_H
   344.8 +
   344.9 +#include "Common/Types.h"
  344.10 +#include "Common/MyString.h"
  344.11 +#include "Common/Buffer.h"
  344.12 +#include "LzhHeader.h"
  344.13 +
  344.14 +namespace NArchive {
  344.15 +namespace NLzh {
  344.16 +
  344.17 +struct CExtension
  344.18 +{
  344.19 +  Byte Type;
  344.20 +  CByteBuffer Data;
  344.21 +  AString GetString() const
  344.22 +  {
  344.23 +    AString s;
  344.24 +    for (size_t i = 0; i < Data.GetCapacity(); i++)
  344.25 +    {
  344.26 +      char c = (char)Data[i];
  344.27 +      if (c == 0)
  344.28 +        break;
  344.29 +      s += c;
  344.30 +    }
  344.31 +    return s;
  344.32 +  }
  344.33 +};
  344.34 +
  344.35 +struct CItem
  344.36 +{
  344.37 +public:
  344.38 +  AString Name;
  344.39 +  Byte Method[kMethodIdSize];
  344.40 +  UInt32 PackSize;
  344.41 +  UInt32 Size;
  344.42 +  UInt32 ModifiedTime;
  344.43 +  Byte Attributes;
  344.44 +  Byte Level;
  344.45 +  UInt16 CRC;
  344.46 +  Byte OsId;
  344.47 +  CObjectVector<CExtension> Extensions;
  344.48 +
  344.49 +  bool IsValidMethod() const  { return (Method[0] == '-' && Method[1] == 'l' && Method[4] == '-'); }
  344.50 +  bool IsLhMethod() const  {return (IsValidMethod() && Method[2] == 'h'); }
  344.51 +  bool IsDir() const {return (IsLhMethod() && Method[3] == 'd'); }
  344.52 +
  344.53 +  bool IsCopyMethod() const
  344.54 +  {
  344.55 +    return (IsLhMethod() && Method[3] == '0') ||
  344.56 +      (IsValidMethod() && Method[2] == 'z' && Method[3] == '4');
  344.57 +  }
  344.58 +  
  344.59 +  bool IsLh1GroupMethod() const
  344.60 +  {
  344.61 +    if (!IsLhMethod())
  344.62 +      return false;
  344.63 +    switch(Method[3])
  344.64 +    {
  344.65 +      case '1':
  344.66 +        return true;
  344.67 +    }
  344.68 +    return false;
  344.69 +  }
  344.70 +  
  344.71 +  bool IsLh4GroupMethod() const
  344.72 +  {
  344.73 +    if (!IsLhMethod())
  344.74 +      return false;
  344.75 +    switch(Method[3])
  344.76 +    {
  344.77 +      case '4':
  344.78 +      case '5':
  344.79 +      case '6':
  344.80 +      case '7':
  344.81 +        return true;
  344.82 +    }
  344.83 +    return false;
  344.84 +  }
  344.85 +  
  344.86 +  int GetNumDictBits() const
  344.87 +  {
  344.88 +    if (!IsLhMethod())
  344.89 +      return 0;
  344.90 +    switch(Method[3])
  344.91 +    {
  344.92 +      case '1':
  344.93 +        return 12;
  344.94 +      case '2':
  344.95 +        return 13;
  344.96 +      case '3':
  344.97 +        return 13;
  344.98 +      case '4':
  344.99 +        return 12;
 344.100 +      case '5':
 344.101 +        return 13;
 344.102 +      case '6':
 344.103 +        return 15;
 344.104 +      case '7':
 344.105 +        return 16;
 344.106 +    }
 344.107 +    return 0;
 344.108 +  }
 344.109 +
 344.110 +  int FindExt(Byte type) const
 344.111 +  {
 344.112 +    for (int i = 0; i < Extensions.Size(); i++)
 344.113 +      if (Extensions[i].Type == type)
 344.114 +        return i;
 344.115 +    return -1;
 344.116 +  }
 344.117 +  bool GetUnixTime(UInt32 &value) const
 344.118 +  {
 344.119 +    int index = FindExt(kExtIdUnixTime);
 344.120 +    if (index < 0)
 344.121 +    {
 344.122 +      if (Level == 2)
 344.123 +      {
 344.124 +        value = ModifiedTime;
 344.125 +        return true;
 344.126 +      }
 344.127 +      return false;
 344.128 +    }
 344.129 +    const Byte *data = (const Byte *)(Extensions[index].Data);
 344.130 +    value = data[0] |
 344.131 +        ((UInt32)data[1] << 8) |
 344.132 +        ((UInt32)data[2] << 16) |
 344.133 +        ((UInt32)data[3] << 24);
 344.134 +    return true;
 344.135 +  }
 344.136 +
 344.137 +  AString GetDirName() const
 344.138 +  {
 344.139 +    int index = FindExt(kExtIdDirName);
 344.140 +    if (index < 0)
 344.141 +      return AString();
 344.142 +    return Extensions[index].GetString();
 344.143 +  }
 344.144 +
 344.145 +  AString GetFileName() const
 344.146 +  {
 344.147 +    int index = FindExt(kExtIdFileName);
 344.148 +    if (index < 0)
 344.149 +      return Name;
 344.150 +    return Extensions[index].GetString();
 344.151 +  }
 344.152 +
 344.153 +  AString GetName() const
 344.154 +  {
 344.155 +    AString dirName = GetDirName();
 344.156 +    dirName.Replace((char)(unsigned char)0xFF, '\\');
 344.157 +    if (!dirName.IsEmpty())
 344.158 +    {
 344.159 +      char c = dirName[dirName.Length() - 1];
 344.160 +      if (c != '\\')
 344.161 +        dirName += '\\';
 344.162 +    }
 344.163 +    return dirName + GetFileName();
 344.164 +  }
 344.165 +};
 344.166 +
 344.167 +class CItemEx: public CItem
 344.168 +{
 344.169 +public:
 344.170 +  UInt64 DataPosition;
 344.171 +};
 344.172 +
 344.173 +}}
 344.174 +
 344.175 +#endif
   345.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   345.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhOutStreamWithCRC.cpp	Sat Mar 03 10:31:27 2012 -0600
   345.3 @@ -0,0 +1,27 @@
   345.4 +// LzhOutStreamWithCRC.cpp
   345.5 +
   345.6 +#include "StdAfx.h"
   345.7 +
   345.8 +#include "LzhOutStreamWithCRC.h"
   345.9 +
  345.10 +namespace NArchive {
  345.11 +namespace NLzh {
  345.12 +
  345.13 +STDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize)
  345.14 +{
  345.15 +  UInt32 realProcessedSize;
  345.16 +  HRESULT result;
  345.17 +  if(!_stream)
  345.18 +  {
  345.19 +    realProcessedSize = size;
  345.20 +    result = S_OK;
  345.21 +  }
  345.22 +  else
  345.23 +    result = _stream->Write(data, size, &realProcessedSize);
  345.24 +  _crc.Update(data, realProcessedSize);
  345.25 +  if(processedSize != NULL)
  345.26 +    *processedSize = realProcessedSize;
  345.27 +  return result;
  345.28 +}
  345.29 +
  345.30 +}}
   346.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   346.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhOutStreamWithCRC.h	Sat Mar 03 10:31:27 2012 -0600
   346.3 @@ -0,0 +1,38 @@
   346.4 +// LzhOutStreamWithCRC.h
   346.5 +
   346.6 +#ifndef __LZHOUTSTREAMWITHCRC_H
   346.7 +#define __LZHOUTSTREAMWITHCRC_H
   346.8 +
   346.9 +#include "LzhCRC.h"
  346.10 +#include "../../../Common/MyCom.h"
  346.11 +#include "../../IStream.h"
  346.12 +
  346.13 +namespace NArchive {
  346.14 +namespace NLzh {
  346.15 +
  346.16 +class COutStreamWithCRC:
  346.17 +  public ISequentialOutStream,
  346.18 +  public CMyUnknownImp
  346.19 +{
  346.20 +public:
  346.21 +  MY_UNKNOWN_IMP
  346.22 +
  346.23 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  346.24 +private:
  346.25 +  CCRC _crc;
  346.26 +  CMyComPtr<ISequentialOutStream> _stream;
  346.27 +public:
  346.28 +  void Init(ISequentialOutStream *stream)
  346.29 +  {
  346.30 +    _stream = stream;
  346.31 +    _crc.Init();
  346.32 +  }
  346.33 +  void ReleaseStream() { _stream.Release(); }
  346.34 +  UInt32 GetCRC() const { return _crc.GetDigest(); }
  346.35 +  void InitCRC() { _crc.Init(); }
  346.36 +
  346.37 +};
  346.38 +
  346.39 +}}
  346.40 +
  346.41 +#endif
   347.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   347.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   347.3 @@ -0,0 +1,13 @@
   347.4 +// LzhRegister.cpp
   347.5 +
   347.6 +#include "StdAfx.h"
   347.7 +
   347.8 +#include "../../Common/RegisterArc.h"
   347.9 +
  347.10 +#include "LzhHandler.h"
  347.11 +static IInArchive *CreateArc() { return new NArchive::NLzh::CHandler;  }
  347.12 +
  347.13 +static CArcInfo g_ArcInfo =
  347.14 +  { L"Lzh", L"lzh lha", 0, 6, { '-', 'l' }, 2, false, CreateArc, 0 };
  347.15 +
  347.16 +REGISTER_ARC(Lzh)
   348.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   348.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzh/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   348.3 @@ -0,0 +1,8 @@
   348.4 +// StdAfx.h
   348.5 +
   348.6 +#ifndef __STDAFX_H
   348.7 +#define __STDAFX_H
   348.8 +
   348.9 +#include "../../../Common/MyWindows.h"
  348.10 +
  348.11 +#endif
   349.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   349.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaArcRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   349.3 @@ -0,0 +1,14 @@
   349.4 +// LzmaArcRegister.cpp
   349.5 +
   349.6 +#include "StdAfx.h"
   349.7 +
   349.8 +#include "../../Common/RegisterArc.h"
   349.9 +
  349.10 +#include "LzmaHandler.h"
  349.11 +
  349.12 +static IInArchive *CreateArc() { return new NArchive::NLzma::CHandler;  }
  349.13 +
  349.14 +static CArcInfo g_ArcInfo =
  349.15 +  { L"Lzma", L"lzma lzma86", 0, 0xA, {0 }, 0, true, CreateArc, NULL };
  349.16 +
  349.17 +REGISTER_ARC(Lzma)
   350.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   350.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.cpp	Sat Mar 03 10:31:27 2012 -0600
   350.3 @@ -0,0 +1,86 @@
   350.4 +// LzmaFiltersDecode.cpp
   350.5 +
   350.6 +#include "StdAfx.h"
   350.7 +
   350.8 +#include "LzmaFiltersDecode.h"
   350.9 +
  350.10 +namespace NArchive {
  350.11 +namespace NLzma {
  350.12 +
  350.13 +static const UInt64 k_LZMA = 0x030101;
  350.14 +static const UInt64 k_BCJ = 0x03030103;
  350.15 +  
  350.16 +HRESULT CDecoder::Code(
  350.17 +    DECL_EXTERNAL_CODECS_LOC_VARS
  350.18 +    const CHeader &block,
  350.19 +    ISequentialInStream *inStream, ISequentialOutStream *outStream,
  350.20 +    UInt64 *inProcessedSize, ICompressProgressInfo *progress)
  350.21 +{
  350.22 +  *inProcessedSize = (UInt64)(Int64)-1;
  350.23 +
  350.24 +  if (block.FilterMethod > 1)
  350.25 +    return E_NOTIMPL;
  350.26 +
  350.27 +  if (!_lzmaDecoder)
  350.28 +  {
  350.29 +    RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_LZMA, _lzmaDecoder, false));
  350.30 +    if (_lzmaDecoder == 0)
  350.31 +      return E_NOTIMPL;
  350.32 +  }
  350.33 +
  350.34 +  {
  350.35 +    CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;
  350.36 +    _lzmaDecoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);
  350.37 +    if (!setDecoderProperties)
  350.38 +      return E_NOTIMPL;
  350.39 +    RINOK(setDecoderProperties->SetDecoderProperties2(block.LzmaProps, 5));
  350.40 +  }
  350.41 +
  350.42 +  bool filteredMode = (block.FilterMethod == 1);
  350.43 +
  350.44 +  CMyComPtr<ICompressSetOutStream> setOutStream;
  350.45 +
  350.46 +  if (filteredMode)
  350.47 +  {
  350.48 +    if (!_bcjStream)
  350.49 +    {
  350.50 +      CMyComPtr<ICompressCoder> coder;
  350.51 +      RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_BCJ, coder, false));
  350.52 +      if (!coder)
  350.53 +        return E_NOTIMPL;
  350.54 +      coder.QueryInterface(IID_ISequentialOutStream, &_bcjStream);
  350.55 +      if (!_bcjStream)
  350.56 +        return E_NOTIMPL;
  350.57 +    }
  350.58 +
  350.59 +    _bcjStream.QueryInterface(IID_ICompressSetOutStream, &setOutStream);
  350.60 +    if (!setOutStream)
  350.61 +      return E_NOTIMPL;
  350.62 +    RINOK(setOutStream->SetOutStream(outStream));
  350.63 +    outStream = _bcjStream;
  350.64 +  }
  350.65 +
  350.66 +  const UInt64 *unpackSize = block.HasUnpackSize() ? &block.UnpackSize : NULL;
  350.67 +  RINOK(_lzmaDecoder->Code(inStream, outStream, NULL, unpackSize, progress));
  350.68 +
  350.69 +  if (filteredMode)
  350.70 +  {
  350.71 +    CMyComPtr<IOutStreamFlush> flush;
  350.72 +    _bcjStream.QueryInterface(IID_IOutStreamFlush, &flush);
  350.73 +    if (flush)
  350.74 +    {
  350.75 +      RINOK(flush->Flush());
  350.76 +    }
  350.77 +    RINOK(setOutStream->ReleaseOutStream());
  350.78 +  }
  350.79 +
  350.80 +  CMyComPtr<ICompressGetInStreamProcessedSize> getInStreamProcessedSize;
  350.81 +  _lzmaDecoder.QueryInterface(IID_ICompressGetInStreamProcessedSize, &getInStreamProcessedSize);
  350.82 +  if (getInStreamProcessedSize)
  350.83 +  {
  350.84 +    RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(inProcessedSize));
  350.85 +  }
  350.86 +  return S_OK;
  350.87 +}
  350.88 +
  350.89 +}}
   351.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   351.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.h	Sat Mar 03 10:31:27 2012 -0600
   351.3 @@ -0,0 +1,26 @@
   351.4 +// LzmaFiltersDecode.h
   351.5 +
   351.6 +#ifndef __LZMA_FILTERS_DECODE_H
   351.7 +#define __LZMA_FILTERS_DECODE_H
   351.8 +
   351.9 +#include "../../Common/CreateCoder.h"
  351.10 +
  351.11 +#include "LzmaItem.h"
  351.12 +
  351.13 +namespace NArchive {
  351.14 +namespace NLzma {
  351.15 +
  351.16 +class CDecoder
  351.17 +{
  351.18 +  CMyComPtr<ICompressCoder> _lzmaDecoder;
  351.19 +  CMyComPtr<ISequentialOutStream> _bcjStream;
  351.20 +public:
  351.21 +  HRESULT Code(DECL_EXTERNAL_CODECS_LOC_VARS
  351.22 +      const CHeader &block,
  351.23 +      ISequentialInStream *inStream, ISequentialOutStream *outStream,
  351.24 +      UInt64 *inProcessedSize, ICompressProgressInfo *progress);
  351.25 +};
  351.26 +
  351.27 +}}
  351.28 +
  351.29 +#endif
   352.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   352.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaHandler.cpp	Sat Mar 03 10:31:27 2012 -0600
   352.3 @@ -0,0 +1,243 @@
   352.4 +// LzmaHandler.cpp
   352.5 +
   352.6 +#include "StdAfx.h"
   352.7 +
   352.8 +#include "LzmaHandler.h"
   352.9 +
  352.10 +#include "Common/Defs.h"
  352.11 +#include "Common/StringConvert.h"
  352.12 +#include "Common/ComTry.h"
  352.13 +#include "Common/IntToString.h"
  352.14 +
  352.15 +#include "Windows/PropVariant.h"
  352.16 +
  352.17 +#include "../../Common/ProgressUtils.h"
  352.18 +#include "../../Common/StreamUtils.h"
  352.19 +#include "../Common/DummyOutStream.h"
  352.20 +
  352.21 +#include "LzmaFiltersDecode.h"
  352.22 +
  352.23 +namespace NArchive {
  352.24 +namespace NLzma {
  352.25 +
  352.26 +STATPROPSTG kProps[] =
  352.27 +{
  352.28 +  { NULL, kpidSize, VT_UI8},
  352.29 +  { NULL, kpidPackSize, VT_UI8},
  352.30 +  { NULL, kpidMethod, VT_UI1}
  352.31 +};
  352.32 +
  352.33 +IMP_IInArchive_Props
  352.34 +IMP_IInArchive_ArcProps_NO
  352.35 +
  352.36 +STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
  352.37 +{
  352.38 +  *numItems = 1;
  352.39 +  return S_OK;
  352.40 +}
  352.41 +
  352.42 +static void ConvertUInt32ToString(UInt32 value, wchar_t *s)
  352.43 +{
  352.44 +  ConvertUInt64ToString(value, s + MyStringLen(s));
  352.45 +}
  352.46 +
  352.47 +static void DictSizeToString(UInt32 value, wchar_t *s)
  352.48 +{
  352.49 +  for (int i = 0; i <= 31; i++)
  352.50 +    if ((UInt32(1) << i) == value)
  352.51 +    {
  352.52 +      ConvertUInt32ToString(i, s);
  352.53 +      return;
  352.54 +    }
  352.55 +  wchar_t c = L'b';
  352.56 +  if ((value & ((1 << 20) - 1)) == 0)
  352.57 +  {
  352.58 +    value >>= 20;
  352.59 +    c = L'm';
  352.60 +  }
  352.61 +  else if ((value & ((1 << 10) - 1)) == 0)
  352.62 +  {
  352.63 +    value >>= 10;
  352.64 +    c = L'k';
  352.65 +  }
  352.66 +  ConvertUInt32ToString(value, s);
  352.67 +  int p = MyStringLen(s);
  352.68 +  s[p++] = c;
  352.69 +  s[p++] = L'\0';
  352.70 +}
  352.71 +
  352.72 +static void MyStrCat(wchar_t *d, const wchar_t *s)
  352.73 +{
  352.74 +  MyStringCopy(d + MyStringLen(d), s);
  352.75 +}
  352.76 +
  352.77 +STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)
  352.78 +{
  352.79 +  if (index != 0)
  352.80 +    return E_INVALIDARG;
  352.81 +  NWindows::NCOM::CPropVariant propVariant;
  352.82 +  switch(propID)
  352.83 +  {
  352.84 +    case kpidSize:
  352.85 +      if (m_StreamInfo.HasUnpackSize())
  352.86 +        propVariant = (UInt64)m_StreamInfo.UnpackSize;
  352.87 +      break;
  352.88 +    case kpidPackSize:
  352.89 +      propVariant = (UInt64)m_PackSize;
  352.90 +      break;
  352.91 +    case kpidMethod:
  352.92 +    {
  352.93 +      wchar_t s[64];
  352.94 +      s[0] = '\0';
  352.95 +      if (m_StreamInfo.IsThereFilter)
  352.96 +      {
  352.97 +        const wchar_t *f;
  352.98 +        if (m_StreamInfo.FilterMethod == 0)
  352.99 +          f = L"Copy";
 352.100 +        else if (m_StreamInfo.FilterMethod == 1)
 352.101 +          f = L"BCJ";
 352.102 +        else
 352.103 +          f = L"Unknown";
 352.104 +        MyStrCat(s, f);
 352.105 +        MyStrCat(s, L" ");
 352.106 +      }
 352.107 +      MyStrCat(s, L"LZMA:");
 352.108 +      DictSizeToString(m_StreamInfo.GetDicSize(), s);
 352.109 +      propVariant = s;
 352.110 +      break;
 352.111 +    }
 352.112 +  }
 352.113 +  propVariant.Detach(value);
 352.114 +  return S_OK;
 352.115 +}
 352.116 +
 352.117 +STDMETHODIMP CHandler::Open(IInStream *inStream,
 352.118 +    const UInt64 * /* maxCheckStartPosition */,
 352.119 +    IArchiveOpenCallback * /* openArchiveCallback */)
 352.120 +{
 352.121 +  {
 352.122 +    RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_StreamStartPosition));
 352.123 +
 352.124 +    HRESULT res = ReadStreamHeader(inStream, m_StreamInfo);
 352.125 +    if (res != S_OK)
 352.126 +      return S_FALSE;
 352.127 +    
 352.128 +    Byte b;
 352.129 +    RINOK(ReadStream_FALSE(inStream, &b, 1));
 352.130 +    if (b != 0)
 352.131 +      return S_FALSE;
 352.132 +
 352.133 +    UInt64 endPos;
 352.134 +    RINOK(inStream->Seek(0, STREAM_SEEK_END, &endPos));
 352.135 +    m_PackSize = endPos - m_StreamStartPosition - m_StreamInfo.GetHeaderSize();
 352.136 +
 352.137 +    m_Stream = inStream;
 352.138 +  }
 352.139 +  return S_OK;
 352.140 +}
 352.141 +
 352.142 +STDMETHODIMP CHandler::Close()
 352.143 +{
 352.144 +  m_Stream.Release();
 352.145 +  return S_OK;
 352.146 +}
 352.147 +
 352.148 +
 352.149 +STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
 352.150 +    Int32 _aTestMode, IArchiveExtractCallback *extractCallback)
 352.151 +{
 352.152 +  COM_TRY_BEGIN
 352.153 +  bool allFilesMode = (numItems == UInt32(-1));
 352.154 +  if (!allFilesMode)
 352.155 +  {
 352.156 +    if (numItems == 0)
 352.157 +      return S_OK;
 352.158 +    if (numItems != 1)
 352.159 +      return E_INVALIDARG;
 352.160 +    if (indices[0] != 0)
 352.161 +      return E_INVALIDARG;
 352.162 +  }
 352.163 +
 352.164 +  bool testMode = (_aTestMode != 0);
 352.165 +
 352.166 +  RINOK(extractCallback->SetTotal(m_PackSize));
 352.167 +    
 352.168 +  UInt64 currentTotalPacked = 0;
 352.169 +
 352.170 +  CDummyOutStream *outStreamSpec = new CDummyOutStream;
 352.171 +  CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
 352.172 +
 352.173 +  {
 352.174 +    CMyComPtr<ISequentialOutStream> realOutStream;
 352.175 +    Int32 askMode = testMode ?
 352.176 +        NArchive::NExtract::NAskMode::kTest :
 352.177 +        NArchive::NExtract::NAskMode::kExtract;
 352.178 +    
 352.179 +    RINOK(extractCallback->GetStream(0, &realOutStream, askMode));
 352.180 +
 352.181 +    outStreamSpec->SetStream(realOutStream);
 352.182 +    outStreamSpec->Init();
 352.183 +    if(!testMode && !realOutStream)
 352.184 +      return S_OK;
 352.185 +    extractCallback->PrepareOperation(askMode);
 352.186 +  }
 352.187 +  
 352.188 +  CLocalProgress *lps = new CLocalProgress;
 352.189 +  CMyComPtr<ICompressProgressInfo> progress = lps;
 352.190 +  lps->Init(extractCallback, true);
 352.191 +
 352.192 +  CDecoder decoder;
 352.193 +  RINOK(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL));
 352.194 +  UInt64 streamPos = m_StreamStartPosition;
 352.195 +  Int32 opRes = NArchive::NExtract::NOperationResult::kOK;
 352.196 +  bool firstItem = true;
 352.197 +  for (;;)
 352.198 +  {
 352.199 +    CHeader st;
 352.200 +    HRESULT result = ReadStreamHeader(m_Stream, st);
 352.201 +    if (result != S_OK)
 352.202 +    {
 352.203 +      if (firstItem)
 352.204 +        return E_FAIL;
 352.205 +      break;
 352.206 +    }
 352.207 +    firstItem = false;
 352.208 +
 352.209 +    lps->OutSize = outStreamSpec->GetSize();
 352.210 +    lps->InSize = currentTotalPacked;
 352.211 +    RINOK(lps->SetCur());
 352.212 +    
 352.213 +    streamPos += st.GetHeaderSize();
 352.214 +    UInt64 packProcessed;
 352.215 +
 352.216 +    {
 352.217 +      result = decoder.Code(
 352.218 +          EXTERNAL_CODECS_VARS
 352.219 +          st, m_Stream, outStream, &packProcessed, progress);
 352.220 +      if (result == E_NOTIMPL)
 352.221 +      {
 352.222 +        opRes = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
 352.223 +        break;
 352.224 +      }
 352.225 +      if (result == S_FALSE)
 352.226 +      {
 352.227 +        opRes = NArchive::NExtract::NOperationResult::kDataError;
 352.228 +        break;
 352.229 +      }
 352.230 +      RINOK(result);
 352.231 +    }
 352.232 +
 352.233 +    if (packProcessed == (UInt64)(Int64)-1)
 352.234 +      break;
 352.235 +    RINOK(m_Stream->Seek(streamPos + packProcessed, STREAM_SEEK_SET, NULL));
 352.236 +    currentTotalPacked += packProcessed;
 352.237 +    streamPos += packProcessed;
 352.238 +  }
 352.239 +  outStream.Release();
 352.240 +  return extractCallback->SetOperationResult(opRes);
 352.241 +  COM_TRY_END
 352.242 +}
 352.243 +
 352.244 +IMPL_ISetCompressCodecsInfo
 352.245 +
 352.246 +}}
   353.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   353.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaHandler.h	Sat Mar 03 10:31:27 2012 -0600
   353.3 @@ -0,0 +1,69 @@
   353.4 +// Lzma/Handler.h
   353.5 +
   353.6 +#ifndef __GZIP_HANDLER_H
   353.7 +#define __GZIP_HANDLER_H
   353.8 +
   353.9 +#include "Common/MyCom.h"
  353.10 +
  353.11 +#include "../IArchive.h"
  353.12 +#include "../../Common/CreateCoder.h"
  353.13 +
  353.14 +#include "LzmaIn.h"
  353.15 +
  353.16 +namespace NArchive {
  353.17 +namespace NLzma {
  353.18 +
  353.19 +// const UInt64 k_LZMA = 0x030101;
  353.20 +
  353.21 +class CHandler:
  353.22 +  public IInArchive,
  353.23 +  PUBLIC_ISetCompressCodecsInfo
  353.24 +  public CMyUnknownImp
  353.25 +{
  353.26 +public:
  353.27 +  MY_QUERYINTERFACE_BEGIN
  353.28 +  MY_QUERYINTERFACE_ENTRY(IInArchive)
  353.29 +  QUERY_ENTRY_ISetCompressCodecsInfo
  353.30 +  MY_QUERYINTERFACE_END
  353.31 +  MY_ADDREF_RELEASE
  353.32 +
  353.33 +  STDMETHOD(Open)(IInStream *inStream,
  353.34 +      const UInt64 *maxCheckStartPosition,
  353.35 +      IArchiveOpenCallback *openArchiveCallback);
  353.36 +  STDMETHOD(Close)();
  353.37 +  
  353.38 +  STDMETHOD(GetNumberOfItems)(UInt32 *numItems);
  353.39 +  STDMETHOD(GetProperty)(UInt32 index, PROPID propID,  PROPVARIANT *value);
  353.40 +  STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems,
  353.41 +      Int32 testMode, IArchiveExtractCallback *extractCallback);
  353.42 +
  353.43 +  STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value);
  353.44 +
  353.45 +  STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties);
  353.46 +  STDMETHOD(GetPropertyInfo)(UInt32 index,
  353.47 +      BSTR *name, PROPID *propID, VARTYPE *varType);
  353.48 +
  353.49 +  STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties);
  353.50 +  STDMETHOD(GetArchivePropertyInfo)(UInt32 index,
  353.51 +      BSTR *name, PROPID *propID, VARTYPE *varType);
  353.52 +
  353.53 +  UString GetMethodString();
  353.54 +public:
  353.55 +  CHandler() {  }
  353.56 +
  353.57 +private:
  353.58 +  CHeader m_StreamInfo;
  353.59 +  UInt64 m_StreamStartPosition;
  353.60 +  UInt64 m_PackSize;
  353.61 +
  353.62 +  CMyComPtr<IInStream> m_Stream;
  353.63 +
  353.64 +  DECL_EXTERNAL_CODECS_VARS
  353.65 +
  353.66 +  DECL_ISetCompressCodecsInfo
  353.67 +
  353.68 +};
  353.69 +
  353.70 +}}
  353.71 +
  353.72 +#endif
   354.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   354.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaIn.cpp	Sat Mar 03 10:31:27 2012 -0600
   354.3 @@ -0,0 +1,56 @@
   354.4 +// Archive/LzmaIn.cpp
   354.5 +
   354.6 +#include "StdAfx.h"
   354.7 +
   354.8 +#include "LzmaIn.h"
   354.9 +
  354.10 +#include "../../Common/StreamUtils.h"
  354.11 +
  354.12 +namespace NArchive {
  354.13 +namespace NLzma {
  354.14 + 
  354.15 +static bool CheckDictSize(const Byte *p)
  354.16 +{
  354.17 +  UInt32 dicSize = GetUi32(p);
  354.18 +  int i;
  354.19 +  for (i = 1; i <= 30; i++)
  354.20 +    if (dicSize == ((UInt32)2 << i) || dicSize == ((UInt32)3 << i))
  354.21 +      return true;
  354.22 +  return false;
  354.23 +}
  354.24 +
  354.25 +HRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &block)
  354.26 +{
  354.27 +  Byte sig[5 + 9];
  354.28 +  RINOK(ReadStream_FALSE(inStream, sig, 5 + 8));
  354.29 +
  354.30 +  const Byte kMaxProp0Val = 5 * 5 * 9 - 1;
  354.31 +  if (sig[0] > kMaxProp0Val)
  354.32 +    return S_FALSE;
  354.33 +
  354.34 +  for (int i = 0; i < 5; i++)
  354.35 +    block.LzmaProps[i] = sig[i];
  354.36 +  
  354.37 +  block.IsThereFilter = false;
  354.38 +  block.FilterMethod = 0;
  354.39 +
  354.40 +  if (!CheckDictSize(sig + 1))
  354.41 +  {
  354.42 +    if (sig[0] > 1 || sig[1] > kMaxProp0Val)
  354.43 +      return S_FALSE;
  354.44 +    block.IsThereFilter = true;
  354.45 +    block.FilterMethod = sig[0];
  354.46 +    for (int i = 0; i < 5; i++)
  354.47 +      block.LzmaProps[i] = sig[i + 1];
  354.48 +    if (!CheckDictSize(block.LzmaProps + 1))
  354.49 +      return S_FALSE;
  354.50 +    RINOK(ReadStream_FALSE(inStream, sig + 5 + 8, 1));
  354.51 +  }
  354.52 +  UInt32 unpOffset = 5 + (block.IsThereFilter ? 1 : 0);
  354.53 +  block.UnpackSize = GetUi64(sig + unpOffset);
  354.54 +  if (block.HasUnpackSize() && block.UnpackSize >= ((UInt64)1 << 56))
  354.55 +    return S_FALSE;
  354.56 +  return S_OK;
  354.57 +}
  354.58 +
  354.59 +}}
   355.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   355.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaIn.h	Sat Mar 03 10:31:27 2012 -0600
   355.3 @@ -0,0 +1,16 @@
   355.4 +// Archive/LzmaIn.h
   355.5 +
   355.6 +#ifndef __ARCHIVE_LZMA_IN_H
   355.7 +#define __ARCHIVE_LZMA_IN_H
   355.8 +
   355.9 +#include "LzmaItem.h"
  355.10 +#include "../../IStream.h"
  355.11 +
  355.12 +namespace NArchive {
  355.13 +namespace NLzma {
  355.14 +
  355.15 +HRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &st);
  355.16 +
  355.17 +}}
  355.18 +  
  355.19 +#endif
   356.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   356.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaItem.h	Sat Mar 03 10:31:27 2012 -0600
   356.3 @@ -0,0 +1,27 @@
   356.4 +// Archive/LzmaItem.h
   356.5 +
   356.6 +#ifndef __ARCHIVE_LZMA_ITEM_H
   356.7 +#define __ARCHIVE_LZMA_ITEM_H
   356.8 +
   356.9 +#include "Common/Types.h"
  356.10 +
  356.11 +#include "../../../../C/CpuArch.h"
  356.12 +
  356.13 +namespace NArchive {
  356.14 +namespace NLzma {
  356.15 +
  356.16 +struct CHeader
  356.17 +{
  356.18 +  UInt64 UnpackSize;
  356.19 +  bool IsThereFilter;
  356.20 +  Byte FilterMethod;
  356.21 +  Byte LzmaProps[5];
  356.22 +
  356.23 +  UInt32 GetDicSize() const { return GetUi32(LzmaProps + 1); }
  356.24 +  bool HasUnpackSize() const { return (UnpackSize != (UInt64)(Int64)-1);  }
  356.25 +  unsigned GetHeaderSize() const { return 5 + 8 + (IsThereFilter ? 1 : 0); }
  356.26 +};
  356.27 +
  356.28 +}}
  356.29 +
  356.30 +#endif
   357.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   357.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzma/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   357.3 @@ -0,0 +1,8 @@
   357.4 +// StdAfx.h
   357.5 +
   357.6 +#ifndef __STDAFX_H
   357.7 +#define __STDAFX_H
   357.8 +
   357.9 +#include "../../../Common/MyWindows.h"
  357.10 +
  357.11 +#endif
   358.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   358.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarHandler.cpp	Sat Mar 03 10:31:27 2012 -0600
   358.3 @@ -0,0 +1,835 @@
   358.4 +// RarHandler.cpp
   358.5 +
   358.6 +#include "StdAfx.h"
   358.7 +
   358.8 +#include "Common/ComTry.h"
   358.9 +#include "Common/IntToString.h"
  358.10 +#include "Common/StringConvert.h"
  358.11 +
  358.12 +#include "Windows/PropVariant.h"
  358.13 +#include "Windows/Time.h"
  358.14 +
  358.15 +#include "../../IPassword.h"
  358.16 +
  358.17 +#include "../../Common/CreateCoder.h"
  358.18 +#include "../../Common/FilterCoder.h"
  358.19 +#include "../../Common/MethodId.h"
  358.20 +#include "../../Common/ProgressUtils.h"
  358.21 +
  358.22 +#include "../../Compress/CopyCoder.h"
  358.23 +
  358.24 +#include "../../Crypto/Rar20Crypto.h"
  358.25 +#include "../../Crypto/RarAes.h"
  358.26 +
  358.27 +#include "../Common/ItemNameUtils.h"
  358.28 +#include "../Common/OutStreamWithCRC.h"
  358.29 +
  358.30 +#include "RarHandler.h"
  358.31 +
  358.32 +using namespace NWindows;
  358.33 +using namespace NTime;
  358.34 +
  358.35 +namespace NArchive {
  358.36 +namespace NRar {
  358.37 +
  358.38 +static const wchar_t *kHostOS[] =
  358.39 +{
  358.40 +  L"MS DOS",
  358.41 +  L"OS/2",
  358.42 +  L"Win32",
  358.43 +  L"Unix",
  358.44 +  L"Mac OS",
  358.45 +  L"BeOS"
  358.46 +};
  358.47 +
  358.48 +static const int kNumHostOSes = sizeof(kHostOS) / sizeof(kHostOS[0]);
  358.49 +
  358.50 +static const wchar_t *kUnknownOS = L"Unknown";
  358.51 +
  358.52 +STATPROPSTG kProps[] =
  358.53 +{
  358.54 +  { NULL, kpidPath, VT_BSTR},
  358.55 +  { NULL, kpidIsDir, VT_BOOL},
  358.56 +  { NULL, kpidSize, VT_UI8},
  358.57 +  { NULL, kpidPackSize, VT_UI8},
  358.58 +  { NULL, kpidMTime, VT_FILETIME},
  358.59 +  { NULL, kpidCTime, VT_FILETIME},
  358.60 +  { NULL, kpidATime, VT_FILETIME},
  358.61 +  { NULL, kpidAttrib, VT_UI4},
  358.62 +
  358.63 +  { NULL, kpidEncrypted, VT_BOOL},
  358.64 +  { NULL, kpidSolid, VT_BOOL},
  358.65 +  { NULL, kpidCommented, VT_BOOL},
  358.66 +  { NULL, kpidSplitBefore, VT_BOOL},
  358.67 +  { NULL, kpidSplitAfter, VT_BOOL},
  358.68 +  { NULL, kpidCRC, VT_UI4},
  358.69 +  { NULL, kpidHostOS, VT_BSTR},
  358.70 +  { NULL, kpidMethod, VT_BSTR},
  358.71 +  { NULL, kpidUnpackVer, VT_UI1}
  358.72 +};
  358.73 +
  358.74 +STATPROPSTG kArcProps[] =
  358.75 +{
  358.76 +  { NULL, kpidSolid, VT_BOOL},
  358.77 +  { NULL, kpidNumBlocks, VT_UI4},
  358.78 +  // { NULL, kpidEncrypted, VT_BOOL},
  358.79 +  { NULL, kpidIsVolume, VT_BOOL},
  358.80 +  { NULL, kpidNumVolumes, VT_UI4},
  358.81 +  { NULL, kpidPhySize, VT_UI8}
  358.82 +  // { NULL, kpidCommented, VT_BOOL}
  358.83 +};
  358.84 +
  358.85 +IMP_IInArchive_Props
  358.86 +IMP_IInArchive_ArcProps
  358.87 +
  358.88 +UInt64 CHandler::GetPackSize(int refIndex) const
  358.89 +{
  358.90 +  const CRefItem &refItem = _refItems[refIndex];
  358.91 +  UInt64 totalPackSize = 0;
  358.92 +  for (int i = 0; i < refItem.NumItems; i++)
  358.93 +    totalPackSize += _items[refItem.ItemIndex + i].PackSize;
  358.94 +  return totalPackSize;
  358.95 +}
  358.96 +
  358.97 +STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
  358.98 +{
  358.99 +  // COM_TRY_BEGIN
 358.100 +  NWindows::NCOM::CPropVariant prop;
 358.101 +  switch(propID)
 358.102 +  {
 358.103 +    case kpidSolid: prop = _archiveInfo.IsSolid(); break;
 358.104 +    // case kpidEncrypted: prop = _archiveInfo.IsEncrypted(); break; // it's for encrypted names.
 358.105 +    case kpidIsVolume: prop = _archiveInfo.IsVolume(); break;
 358.106 +    case kpidNumVolumes: prop = (UInt32)_archives.Size(); break;
 358.107 +    case kpidOffset: if (_archiveInfo.StartPosition != 0) prop = _archiveInfo.StartPosition; break;
 358.108 +    // case kpidCommented: prop = _archiveInfo.IsCommented(); break;
 358.109 +    case kpidNumBlocks:
 358.110 +    {
 358.111 +      UInt32 numBlocks = 0;
 358.112 +      for (int i = 0; i < _refItems.Size(); i++)
 358.113 +        if (!IsSolid(i))
 358.114 +          numBlocks++;
 358.115 +      prop = (UInt32)numBlocks;
 358.116 +      break;
 358.117 +    }
 358.118 +  }
 358.119 +  prop.Detach(value);
 358.120 +  return S_OK;
 358.121 +  // COM_TRY_END
 358.122 +}
 358.123 +
 358.124 +STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
 358.125 +{
 358.126 +  *numItems = _refItems.Size();
 358.127 +  return S_OK;
 358.128 +}
 358.129 +
 358.130 +static bool RarTimeToFileTime(const CRarTime &rarTime, FILETIME &result)
 358.131 +{
 358.132 +  if (!DosTimeToFileTime(rarTime.DosTime, result))
 358.133 +    return false;
 358.134 +  UInt64 value =  (((UInt64)result.dwHighDateTime) << 32) + result.dwLowDateTime;
 358.135 +  value += (UInt64)rarTime.LowSecond * 10000000;
 358.136 +  value += ((UInt64)rarTime.SubTime[2] << 16) +
 358.137 +    ((UInt64)rarTime.SubTime[1] << 8) +
 358.138 +    ((UInt64)rarTime.SubTime[0]);
 358.139 +  result.dwLowDateTime = (DWORD)value;
 358.140 +  result.dwHighDateTime = DWORD(value >> 32);
 358.141 +  return true;
 358.142 +}
 358.143 +
 358.144 +static void RarTimeToProp(const CRarTime &rarTime, NWindows::NCOM::CPropVariant &prop)
 358.145 +{
 358.146 +  FILETIME localFileTime, utcFileTime;
 358.147 +  if (RarTimeToFileTime(rarTime, localFileTime))
 358.148 +  {
 358.149 +    if (!LocalFileTimeToFileTime(&localFileTime, &utcFileTime))
 358.150 +      utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
 358.151 +  }
 358.152 +  else
 358.153 +    utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
 358.154 +  prop = utcFileTime;
 358.155 +}
 358.156 +
 358.157 +STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)
 358.158 +{
 358.159 +  COM_TRY_BEGIN
 358.160 +  NWindows::NCOM::CPropVariant prop;
 358.161 +  const CRefItem &refItem = _refItems[index];
 358.162 +  const CItemEx &item = _items[refItem.ItemIndex];
 358.163 +  switch(propID)
 358.164 +  {
 358.165 +    case kpidPath:
 358.166 +    {
 358.167 +      UString u;
 358.168 +      if (item.HasUnicodeName() && !item.UnicodeName.IsEmpty())
 358.169 +        u = item.UnicodeName;
 358.170 +      else
 358.171 +        u = MultiByteToUnicodeString(item.Name, CP_OEMCP);
 358.172 +      prop = (const wchar_t *)NItemName::WinNameToOSName(u);
 358.173 +      break;
 358.174 +    }
 358.175 +    case kpidIsDir: prop = item.IsDir(); break;
 358.176 +    case kpidSize: prop = item.Size; break;
 358.177 +    case kpidPackSize: prop = GetPackSize(index); break;
 358.178 +    case kpidMTime: RarTimeToProp(item.MTime, prop); break;
 358.179 +    case kpidCTime: if (item.CTimeDefined) RarTimeToProp(item.CTime, prop); break;
 358.180 +    case kpidATime: if (item.ATimeDefined) RarTimeToProp(item.ATime, prop); break;
 358.181 +    case kpidAttrib: prop = item.GetWinAttributes(); break;
 358.182 +    case kpidEncrypted: prop = item.IsEncrypted(); break;
 358.183 +    case kpidSolid: prop = IsSolid(index); break;
 358.184 +    case kpidCommented: prop = item.IsCommented(); break;
 358.185 +    case kpidSplitBefore: prop = item.IsSplitBefore(); break;
 358.186 +    case kpidSplitAfter: prop = _items[refItem.ItemIndex + refItem.NumItems - 1].IsSplitAfter(); break;
 358.187 +    case kpidCRC:
 358.188 +    {
 358.189 +      const CItemEx &lastItem = _items[refItem.ItemIndex + refItem.NumItems - 1];
 358.190 +      prop = ((lastItem.IsSplitAfter()) ? item.FileCRC : lastItem.FileCRC);
 358.191 +      break;
 358.192 +    }
 358.193 +    case kpidUnpackVer: prop = item.UnPackVersion; break;
 358.194 +    case kpidMethod:
 358.195 +    {
 358.196 +      UString method;
 358.197 +      if (item.Method >= Byte('0') && item.Method <= Byte('5'))
 358.198 +      {
 358.199 +        method = L"m";
 358.200 +        wchar_t temp[32];
 358.201 +        ConvertUInt64ToString(item.Method - Byte('0'), temp);
 358.202 +        method += temp;
 358.203 +        if (!item.IsDir())
 358.204 +        {
 358.205 +          method += L":";
 358.206 +          ConvertUInt64ToString(16 + item.GetDictSize(), temp);
 358.207 +          method += temp;
 358.208 +        }
 358.209 +      }
 358.210 +      else
 358.211 +      {
 358.212 +        wchar_t temp[32];
 358.213 +        ConvertUInt64ToString(item.Method, temp);
 358.214 +        method += temp;
 358.215 +      }
 358.216 +      prop = method;
 358.217 +      break;
 358.218 +    }
 358.219 +    case kpidHostOS: prop = (item.HostOS < kNumHostOSes) ? (kHostOS[item.HostOS]) : kUnknownOS; break;
 358.220 +  }
 358.221 +  prop.Detach(value);
 358.222 +  return S_OK;
 358.223 +  COM_TRY_END
 358.224 +}
 358.225 +
 358.226 +class CVolumeName
 358.227 +{
 358.228 +  bool _first;
 358.229 +  bool _newStyle;
 358.230 +  UString _unchangedPart;
 358.231 +  UString _changedPart;
 358.232 +  UString _afterPart;
 358.233 +public:
 358.234 +  CVolumeName(): _newStyle(true) {};
 358.235 +
 358.236 +  bool InitName(const UString &name, bool newStyle)
 358.237 +  {
 358.238 +    _first = true;
 358.239 +    _newStyle = newStyle;
 358.240 +    int dotPos = name.ReverseFind('.');
 358.241 +    UString basePart = name;
 358.242 +    if (dotPos >= 0)
 358.243 +    {
 358.244 +      UString ext = name.Mid(dotPos + 1);
 358.245 +      if (ext.CompareNoCase(L"rar") == 0)
 358.246 +      {
 358.247 +        _afterPart = name.Mid(dotPos);
 358.248 +        basePart = name.Left(dotPos);
 358.249 +      }
 358.250 +      else if (ext.CompareNoCase(L"exe") == 0)
 358.251 +      {
 358.252 +        _afterPart = L".rar";
 358.253 +        basePart = name.Left(dotPos);
 358.254 +      }
 358.255 +      else if (!_newStyle)
 358.256 +      {
 358.257 +        if (ext.CompareNoCase(L"000") == 0 || ext.CompareNoCase(L"001") == 0)
 358.258 +        {
 358.259 +          _afterPart.Empty();
 358.260 +          _first = false;
 358.261 +          _changedPart = ext;
 358.262 +          _unchangedPart = name.Left(dotPos + 1);
 358.263 +          return true;
 358.264 +        }
 358.265 +      }
 358.266 +    }
 358.267 +
 358.268 +    if (!_newStyle)
 358.269 +    {
 358.270 +      _afterPart.Empty();
 358.271 +      _unchangedPart = basePart + UString(L".");
 358.272 +      _changedPart = L"r00";
 358.273 +      return true;
 358.274 +    }
 358.275 +
 358.276 +    int numLetters = 1;
 358.277 +    if (basePart.Right(numLetters) == L"1" || basePart.Right(numLetters) == L"0")
 358.278 +    {
 358.279 +      while (numLetters < basePart.Length())
 358.280 +      {
 358.281 +        if (basePart[basePart.Length() - numLetters - 1] != '0')
 358.282 +          break;
 358.283 +        numLetters++;
 358.284 +      }
 358.285 +    }
 358.286 +    else
 358.287 +      return false;
 358.288 +    _unchangedPart = basePart.Left(basePart.Length() - numLetters);
 358.289 +    _changedPart = basePart.Right(numLetters);
 358.290 +    return true;
 358.291 +  }
 358.292 +
 358.293 +  UString GetNextName()
 358.294 +  {
 358.295 +    UString newName;
 358.296 +    if (_newStyle || !_first)
 358.297 +    {
 358.298 +      int i;
 358.299 +      int numLetters = _changedPart.Length();
 358.300 +      for (i = numLetters - 1; i >= 0; i--)
 358.301 +      {
 358.302 +        wchar_t c = _changedPart[i];
 358.303 +        if (c == L'9')
 358.304 +        {
 358.305 +          c = L'0';
 358.306 +          newName = c + newName;
 358.307 +          if (i == 0)
 358.308 +            newName = UString(L'1') + newName;
 358.309 +          continue;
 358.310 +        }
 358.311 +        c++;
 358.312 +        newName = UString(c) + newName;
 358.313 +        i--;
 358.314 +        for (; i >= 0; i--)
 358.315 +          newName = _changedPart[i] + newName;
 358.316 +        break;
 358.317 +      }
 358.318 +      _changedPart = newName;
 358.319 +    }
 358.320 +    _first = false;
 358.321 +    return _unchangedPart + _changedPart + _afterPart;
 358.322 +  }
 358.323 +};
 358.324 +
 358.325 +HRESULT CHandler::Open2(IInStream *stream,
 358.326 +    const UInt64 *maxCheckStartPosition,
 358.327 +    IArchiveOpenCallback *openArchiveCallback)
 358.328 +{
 358.329 +  {
 358.330 +    CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
 358.331 +    CMyComPtr<ICryptoGetTextPassword> getTextPassword;
 358.332 +    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackWrap = openArchiveCallback;
 358.333 +    
 358.334 +    CVolumeName seqName;
 358.335 +
 358.336 +    UInt64 totalBytes = 0;
 358.337 +    UInt64 curBytes = 0;
 358.338 +
 358.339 +    if (openArchiveCallback != NULL)
 358.340 +    {
 358.341 +      openArchiveCallbackWrap.QueryInterface(IID_IArchiveOpenVolumeCallback, &openVolumeCallback);
 358.342 +      openArchiveCallbackWrap.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);
 358.343 +    }
 358.344 +
 358.345 +    for (;;)
 358.346 +    {
 358.347 +      CMyComPtr<IInStream> inStream;
 358.348 +      if (!_archives.IsEmpty())
 358.349 +      {
 358.350 +        if (!openVolumeCallback)
 358.351 +          break;
 358.352 +        
 358.353 +        if(_archives.Size() == 1)
 358.354 +        {
 358.355 +          if (!_archiveInfo.IsVolume())
 358.356 +            break;
 358.357 +          UString baseName;
 358.358 +          {
 358.359 +            NCOM::CPropVariant prop;
 358.360 +            RINOK(openVolumeCallback->GetProperty(kpidName, &prop));
 358.361 +            if (prop.vt != VT_BSTR)
 358.362 +              break;
 358.363 +            baseName = prop.bstrVal;
 358.364 +          }
 358.365 +          seqName.InitName(baseName, _archiveInfo.HaveNewVolumeName());
 358.366 +        }
 358.367 +
 358.368 +        UString fullName = seqName.GetNextName();
 358.369 +        HRESULT result = openVolumeCallback->GetStream(fullName, &inStream);
 358.370 +        if (result == S_FALSE)
 358.371 +          break;
 358.372 +        if (result != S_OK)
 358.373 +          return result;
 358.374 +        if (!stream)
 358.375 +          break;
 358.376 +      }
 358.377 +      else
 358.378 +        inStream = stream;
 358.379 +
 358.380 +      UInt64 endPos = 0;
 358.381 +      if (openArchiveCallback != NULL)
 358.382 +      {
 358.383 +        RINOK(stream->Seek(0, STREAM_SEEK_END, &endPos));
 358.384 +        RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
 358.385 +        totalBytes += endPos;
 358.386 +        RINOK(openArchiveCallback->SetTotal(NULL, &totalBytes));
 358.387 +      }
 358.388 +      
 358.389 +      NArchive::NRar::CInArchive archive;
 358.390 +      RINOK(archive.Open(inStream, maxCheckStartPosition));
 358.391 +
 358.392 +      if (_archives.IsEmpty())
 358.393 +        archive.GetArchiveInfo(_archiveInfo);
 358.394 +     
 358.395 +      CItemEx item;
 358.396 +      for (;;)
 358.397 +      {
 358.398 +        HRESULT result = archive.GetNextItem(item, getTextPassword);
 358.399 +        if (result == S_FALSE)
 358.400 +          break;
 358.401 +        RINOK(result);
 358.402 +        if (item.IgnoreItem())
 358.403 +          continue;
 358.404 +
 358.405 +        bool needAdd = true;
 358.406 +        if (item.IsSplitBefore())
 358.407 +        {
 358.408 +          if (!_refItems.IsEmpty())
 358.409 +          {
 358.410 +            CRefItem &refItem = _refItems.Back();
 358.411 +            refItem.NumItems++;
 358.412 +            needAdd = false;
 358.413 +          }
 358.414 +        }
 358.415 +        if (needAdd)
 358.416 +        {
 358.417 +          CRefItem refItem;
 358.418 +          refItem.ItemIndex = _items.Size();
 358.419 +          refItem.NumItems = 1;
 358.420 +          refItem.VolumeIndex = _archives.Size();
 358.421 +          _refItems.Add(refItem);
 358.422 +        }
 358.423 +        _items.Add(item);
 358.424 +        if (openArchiveCallback != NULL && _items.Size() % 100 == 0)
 358.425 +        {
 358.426 +          UInt64 numFiles = _items.Size();
 358.427 +          UInt64 numBytes = curBytes + item.Position;
 358.428 +          RINOK(openArchiveCallback->SetCompleted(&numFiles, &numBytes));
 358.429 +        }
 358.430 +      }
 358.431 +      curBytes += endPos;
 358.432 +      _archives.Add(archive);
 358.433 +    }
 358.434 +  }
 358.435 +  return S_OK;
 358.436 +}
 358.437 +
 358.438 +STDMETHODIMP CHandler::Open(IInStream *stream,
 358.439 +    const UInt64 *maxCheckStartPosition,
 358.440 +    IArchiveOpenCallback *openArchiveCallback)
 358.441 +{
 358.442 +  COM_TRY_BEGIN
 358.443 +  Close();
 358.444 +  try
 358.445 +  {
 358.446 +    HRESULT res = Open2(stream, maxCheckStartPosition, openArchiveCallback);
 358.447 +    if (res != S_OK)
 358.448 +      Close();
 358.449 +    return res;
 358.450 +  }
 358.451 +  catch(const CInArchiveException &) { Close(); return S_FALSE; }
 358.452 +  catch(...) { Close(); throw; }
 358.453 +  COM_TRY_END
 358.454 +}
 358.455 +
 358.456 +STDMETHODIMP CHandler::Close()
 358.457 +{
 358.458 +  COM_TRY_BEGIN
 358.459 +  _refItems.Clear();
 358.460 +  _items.Clear();
 358.461 +  _archives.Clear();
 358.462 +  return S_OK;
 358.463 +  COM_TRY_END
 358.464 +}
 358.465 +
 358.466 +struct CMethodItem
 358.467 +{
 358.468 +  Byte RarUnPackVersion;
 358.469 +  CMyComPtr<ICompressCoder> Coder;
 358.470 +};
 358.471 +
 358.472 +
 358.473 +STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
 358.474 +    Int32 _aTestMode, IArchiveExtractCallback *_anExtractCallback)
 358.475 +{
 358.476 +  COM_TRY_BEGIN
 358.477 +  CMyComPtr<ICryptoGetTextPassword> getTextPassword;
 358.478 +  bool testMode = (_aTestMode != 0);
 358.479 +  CMyComPtr<IArchiveExtractCallback> extractCallback = _anExtractCallback;
 358.480 +  UInt64 censoredTotalUnPacked = 0,
 358.481 +        // censoredTotalPacked = 0,
 358.482 +        importantTotalUnPacked = 0;
 358.483 +        // importantTotalPacked = 0;
 358.484 +  bool allFilesMode = (numItems == UInt32(-1));
 358.485 +  if (allFilesMode)
 358.486 +    numItems = _refItems.Size();
 358.487 +  if(numItems == 0)
 358.488 +    return S_OK;
 358.489 +  int lastIndex = 0;
 358.490 +  CRecordVector<int> importantIndexes;
 358.491 +  CRecordVector<bool> extractStatuses;
 358.492 +
 358.493 +  for(UInt32 t = 0; t < numItems; t++)
 358.494 +  {
 358.495 +    int index = allFilesMode ? t : indices[t];
 358.496 +    const CRefItem &refItem = _refItems[index];
 358.497 +    const CItemEx &item = _items[refItem.ItemIndex];
 358.498 +    censoredTotalUnPacked += item.Size;
 358.499 +    // censoredTotalPacked += item.PackSize;
 358.500 +    int j;
 358.501 +    for(j = lastIndex; j <= index; j++)
 358.502 +      // if(!_items[_refItems[j].ItemIndex].IsSolid())
 358.503 +      if(!IsSolid(j))
 358.504 +        lastIndex = j;
 358.505 +    for(j = lastIndex; j <= index; j++)
 358.506 +    {
 358.507 +      const CRefItem &refItem = _refItems[j];
 358.508 +      const CItemEx &item = _items[refItem.ItemIndex];
 358.509 +
 358.510 +      // const CItemEx &item = _items[j];
 358.511 +
 358.512 +      importantTotalUnPacked += item.Size;
 358.513 +      // importantTotalPacked += item.PackSize;
 358.514 +      importantIndexes.Add(j);
 358.515 +      extractStatuses.Add(j == index);
 358.516 +    }
 358.517 +    lastIndex = index + 1;
 358.518 +  }
 358.519 +
 358.520 +  extractCallback->SetTotal(importantTotalUnPacked);
 358.521 +  UInt64 currentImportantTotalUnPacked = 0;
 358.522 +  UInt64 currentImportantTotalPacked = 0;
 358.523 +  UInt64 currentUnPackSize, currentPackSize;
 358.524 +
 358.525 +  CObjectVector<CMethodItem> methodItems;
 358.526 +
 358.527 +  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;
 358.528 +  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
 358.529 +
 358.530 +  CFilterCoder *filterStreamSpec = new CFilterCoder;
 358.531 +  CMyComPtr<ISequentialInStream> filterStream = filterStreamSpec;
 358.532 +
 358.533 +  NCrypto::NRar20::CDecoder *rar20CryptoDecoderSpec = NULL;
 358.534 +  CMyComPtr<ICompressFilter> rar20CryptoDecoder;
 358.535 +  NCrypto::NRar29::CDecoder *rar29CryptoDecoderSpec = NULL;
 358.536 +  CMyComPtr<ICompressFilter> rar29CryptoDecoder;
 358.537 +
 358.538 +  CFolderInStream *folderInStreamSpec = NULL;
 358.539 +  CMyComPtr<ISequentialInStream> folderInStream;
 358.540 +
 358.541 +  CLocalProgress *lps = new CLocalProgress;
 358.542 +  CMyComPtr<ICompressProgressInfo> progress = lps;
 358.543 +  lps->Init(extractCallback, false);
 358.544 +
 358.545 +  bool solidStart = true;
 358.546 +  for(int i = 0; i < importantIndexes.Size(); i++,
 358.547 +      currentImportantTotalUnPacked += currentUnPackSize,
 358.548 +      currentImportantTotalPacked += currentPackSize)
 358.549 +  {
 358.550 +    lps->InSize = currentImportantTotalPacked;
 358.551 +    lps->OutSize = currentImportantTotalUnPacked;
 358.552 +    RINOK(lps->SetCur());
 358.553 +    CMyComPtr<ISequentialOutStream> realOutStream;
 358.554 +
 358.555 +    Int32 askMode;
 358.556 +    if(extractStatuses[i])
 358.557 +      askMode = testMode ?
 358.558 +          NArchive::NExtract::NAskMode::kTest :
 358.559 +          NArchive::NExtract::NAskMode::kExtract;
 358.560 +    else
 358.561 +      askMode = NArchive::NExtract::NAskMode::kSkip;
 358.562 +
 358.563 +    UInt32 index = importantIndexes[i];
 358.564 +
 358.565 +    const CRefItem &refItem = _refItems[index];
 358.566 +    const CItemEx &item = _items[refItem.ItemIndex];
 358.567 +
 358.568 +    currentUnPackSize = item.Size;
 358.569 +
 358.570 +    currentPackSize = GetPackSize(index);
 358.571 +
 358.572 +    if(item.IgnoreItem())
 358.573 +      continue;
 358.574 +
 358.575 +    RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
 358.576 +
 358.577 +    if (!IsSolid(index))
 358.578 +      solidStart = true;
 358.579 +    if(item.IsDir())
 358.580 +    {
 358.581 +      RINOK(extractCallback->PrepareOperation(askMode));
 358.582 +      RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));
 358.583 +      continue;
 358.584 +    }
 358.585 +
 358.586 +    bool mustBeProcessedAnywhere = false;
 358.587 +    if(i < importantIndexes.Size() - 1)
 358.588 +    {
 358.589 +      // const CRefItem &nextRefItem = _refItems[importantIndexes[i + 1]];
 358.590 +      // const CItemEx &nextItemInfo = _items[nextRefItem.ItemIndex];
 358.591 +      // mustBeProcessedAnywhere = nextItemInfo.IsSolid();
 358.592 +      mustBeProcessedAnywhere = IsSolid(importantIndexes[i + 1]);
 358.593 +    }
 358.594 +    
 358.595 +    if (!mustBeProcessedAnywhere && !testMode && !realOutStream)
 358.596 +      continue;
 358.597 +    
 358.598 +    if (!realOutStream && !testMode)
 358.599 +      askMode = NArchive::NExtract::NAskMode::kSkip;
 358.600 +
 358.601 +    RINOK(extractCallback->PrepareOperation(askMode));
 358.602 +
 358.603 +    COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC;
 358.604 +    CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
 358.605 +    outStreamSpec->SetStream(realOutStream);
 358.606 +    outStreamSpec->Init();
 358.607 +    realOutStream.Release();
 358.608 +    
 358.609 +    /*
 358.610 +    for (int partIndex = 0; partIndex < 1; partIndex++)
 358.611 +    {
 358.612 +    CMyComPtr<ISequentialInStream> inStream;
 358.613 +
 358.614 +    // item redefinition
 358.615 +    const CItemEx &item = _items[refItem.ItemIndex + partIndex];
 358.616 +
 358.617 +    NArchive::NRar::CInArchive &archive = _archives[refItem.VolumeIndex + partIndex];
 358.618 +
 358.619 +    inStream.Attach(archive.CreateLimitedStream(item.GetDataPosition(),
 358.620 +      item.PackSize));
 358.621 +    */
 358.622 +    if (!folderInStream)
 358.623 +    {
 358.624 +      folderInStreamSpec = new CFolderInStream;
 358.625 +      folderInStream = folderInStreamSpec;
 358.626 +    }
 358.627 +
 358.628 +    folderInStreamSpec->Init(&_archives, &_items, refItem);
 358.629 +
 358.630 +    UInt64 packSize = currentPackSize;
 358.631 +
 358.632 +    // packedPos += item.PackSize;
 358.633 +    // unpackedPos += 0;
 358.634 +    
 358.635 +    CMyComPtr<ISequentialInStream> inStream;
 358.636 +    if (item.IsEncrypted())
 358.637 +    {
 358.638 +      CMyComPtr<ICryptoSetPassword> cryptoSetPassword;
 358.639 +      if (item.UnPackVersion >= 29)
 358.640 +      {
 358.641 +        if (!rar29CryptoDecoder)
 358.642 +        {
 358.643 +          rar29CryptoDecoderSpec = new NCrypto::NRar29::CDecoder;
 358.644 +          rar29CryptoDecoder = rar29CryptoDecoderSpec;
 358.645 +          // RINOK(rar29CryptoDecoder.CoCreateInstance(CLSID_CCryptoRar29Decoder));
 358.646 +        }
 358.647 +        rar29CryptoDecoderSpec->SetRar350Mode(item.UnPackVersion < 36);
 358.648 +        CMyComPtr<ICompressSetDecoderProperties2> cryptoProperties;
 358.649 +        RINOK(rar29CryptoDecoder.QueryInterface(IID_ICompressSetDecoderProperties2,
 358.650 +            &cryptoProperties));
 358.651 +        RINOK(cryptoProperties->SetDecoderProperties2(item.Salt, item.HasSalt() ? sizeof(item.Salt) : 0));
 358.652 +        filterStreamSpec->Filter = rar29CryptoDecoder;
 358.653 +      }
 358.654 +      else if (item.UnPackVersion >= 20)
 358.655 +      {
 358.656 +        if (!rar20CryptoDecoder)
 358.657 +        {
 358.658 +          rar20CryptoDecoderSpec = new NCrypto::NRar20::CDecoder;
 358.659 +          rar20CryptoDecoder = rar20CryptoDecoderSpec;
 358.660 +          // RINOK(rar20CryptoDecoder.CoCreateInstance(CLSID_CCryptoRar20Decoder));
 358.661 +        }
 358.662 +        filterStreamSpec->Filter = rar20CryptoDecoder;
 358.663 +      }
 358.664 +      else
 358.665 +      {
 358.666 +        outStream.Release();
 358.667 +        RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kUnSupportedMethod));
 358.668 +        continue;
 358.669 +      }
 358.670 +      RINOK(filterStreamSpec->Filter.QueryInterface(IID_ICryptoSetPassword,
 358.671 +          &cryptoSetPassword));
 358.672 +
 358.673 +      if (!getTextPassword)
 358.674 +        extractCallback.QueryInterface(IID_ICryptoGetTextPassword,
 358.675 +          &getTextPassword);
 358.676 +      if (getTextPassword)
 358.677 +      {
 358.678 +        CMyComBSTR password;
 358.679 +        RINOK(getTextPassword->CryptoGetTextPassword(&password));
 358.680 +        if (item.UnPackVersion >= 29)
 358.681 +        {
 358.682 +          CByteBuffer buffer;
 358.683 +          UString unicodePassword(password);
 358.684 +          const UInt32 sizeInBytes = unicodePassword.Length() * 2;
 358.685 +          buffer.SetCapacity(sizeInBytes);
 358.686 +          for (int i = 0; i < unicodePassword.Length(); i++)
 358.687 +          {
 358.688 +            wchar_t c = unicodePassword[i];
 358.689 +            ((Byte *)buffer)[i * 2] = (Byte)c;
 358.690 +            ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
 358.691 +          }
 358.692 +          RINOK(cryptoSetPassword->CryptoSetPassword(
 358.693 +            (const Byte *)buffer, sizeInBytes));
 358.694 +        }
 358.695 +        else
 358.696 +        {
 358.697 +          AString oemPassword = UnicodeStringToMultiByte(
 358.698 +            (const wchar_t *)password, CP_OEMCP);
 358.699 +          RINOK(cryptoSetPassword->CryptoSetPassword(
 358.700 +            (const Byte *)(const char *)oemPassword, oemPassword.Length()));
 358.701 +        }
 358.702 +      }
 358.703 +      else
 358.704 +      {
 358.705 +        RINOK(cryptoSetPassword->CryptoSetPassword(0, 0));
 358.706 +      }
 358.707 +      filterStreamSpec->SetInStream(folderInStream);
 358.708 +      inStream = filterStream;
 358.709 +    }
 358.710 +    else
 358.711 +    {
 358.712 +      inStream = folderInStream;
 358.713 +    }
 358.714 +    CMyComPtr<ICompressCoder> commonCoder;
 358.715 +    switch(item.Method)
 358.716 +    {
 358.717 +      case '0':
 358.718 +      {
 358.719 +        commonCoder = copyCoder;
 358.720 +        break;
 358.721 +      }
 358.722 +      case '1':
 358.723 +      case '2':
 358.724 +      case '3':
 358.725 +      case '4':
 358.726 +      case '5':
 358.727 +      {
 358.728 +        /*
 358.729 +        if (item.UnPackVersion >= 29)
 358.730 +        {
 358.731 +          outStream.Release();
 358.732 +          RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kUnSupportedMethod));
 358.733 +          continue;
 358.734 +        }
 358.735 +        */
 358.736 +        int m;
 358.737 +        for (m = 0; m < methodItems.Size(); m++)
 358.738 +          if (methodItems[m].RarUnPackVersion == item.UnPackVersion)
 358.739 +            break;
 358.740 +        if (m == methodItems.Size())
 358.741 +        {
 358.742 +          CMethodItem mi;
 358.743 +          mi.RarUnPackVersion = item.UnPackVersion;
 358.744 +
 358.745 +          mi.Coder.Release();
 358.746 +          if (item.UnPackVersion <= 30)
 358.747 +          {
 358.748 +            UInt32 methodID = 0x040300;
 358.749 +            if (item.UnPackVersion < 20)
 358.750 +              methodID += 1;
 358.751 +            else if (item.UnPackVersion < 29)
 358.752 +              methodID += 2;
 358.753 +            else
 358.754 +              methodID += 3;
 358.755 +            RINOK(CreateCoder(EXTERNAL_CODECS_VARS methodID, mi.Coder, false));
 358.756 +          }
 358.757 +         
 358.758 +          if (mi.Coder == 0)
 358.759 +          {
 358.760 +            outStream.Release();
 358.761 +            RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kUnSupportedMethod));
 358.762 +            continue;
 358.763 +          }
 358.764 +
 358.765 +          m = methodItems.Add(mi);
 358.766 +        }
 358.767 +        CMyComPtr<ICompressCoder> decoder = methodItems[m].Coder;
 358.768 +
 358.769 +        CMyComPtr<ICompressSetDecoderProperties2> compressSetDecoderProperties;
 358.770 +        RINOK(decoder.QueryInterface(IID_ICompressSetDecoderProperties2,
 358.771 +            &compressSetDecoderProperties));
 358.772 +        
 358.773 +        Byte isSolid = (Byte)((IsSolid(index) || item.IsSplitBefore()) ? 1: 0);
 358.774 +        if (solidStart)
 358.775 +        {
 358.776 +          isSolid = false;
 358.777 +          solidStart = false;
 358.778 +        }
 358.779 +
 358.780 +
 358.781 +        RINOK(compressSetDecoderProperties->SetDecoderProperties2(&isSolid, 1));
 358.782 +          
 358.783 +        commonCoder = decoder;
 358.784 +        break;
 358.785 +      }
 358.786 +      default:
 358.787 +        outStream.Release();
 358.788 +        RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kUnSupportedMethod));
 358.789 +        continue;
 358.790 +    }
 358.791 +    HRESULT result = commonCoder->Code(inStream, outStream, &packSize, &item.Size, progress);
 358.792 +    if (item.IsEncrypted())
 358.793 +      filterStreamSpec->ReleaseInStream();
 358.794 +    if (result == S_FALSE)
 358.795 +    {
 358.796 +      outStream.Release();
 358.797 +      RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kDataError));
 358.798 +      continue;
 358.799 +    }
 358.800 +    if (result != S_OK)
 358.801 +      return result;
 358.802 +
 358.803 +    /*
 358.804 +    if (refItem.NumItems == 1 &&
 358.805 +        !item.IsSplitBefore() && !item.IsSplitAfter())
 358.806 +    */
 358.807 +    {
 358.808 +      const CItemEx &lastItem = _items[refItem.ItemIndex + refItem.NumItems - 1];
 358.809 +      bool crcOK = outStreamSpec->GetCRC() == lastItem.FileCRC;
 358.810 +      outStream.Release();
 358.811 +      RINOK(extractCallback->SetOperationResult(crcOK ? NArchive::NExtract::NOperationResult::kOK:
 358.812 +          NArchive::NExtract::NOperationResult::kCRCError));
 358.813 +    }
 358.814 +    /*
 358.815 +    else
 358.816 +    {
 358.817 +      bool crcOK = true;
 358.818 +      for (int partIndex = 0; partIndex < refItem.NumItems; partIndex++)
 358.819 +      {
 358.820 +        const CItemEx &item = _items[refItem.ItemIndex + partIndex];
 358.821 +        if (item.FileCRC != folderInStreamSpec->CRCs[partIndex])
 358.822 +        {
 358.823 +          crcOK = false;
 358.824 +          break;
 358.825 +        }
 358.826 +      }
 358.827 +      RINOK(extractCallback->SetOperationResult(crcOK ? NArchive::NExtract::NOperationResult::kOK:
 358.828 +          NArchive::NExtract::NOperationResult::kCRCError));
 358.829 +    }
 358.830 +    */
 358.831 +  }
 358.832 +  return S_OK;
 358.833 +  COM_TRY_END
 358.834 +}
 358.835 +
 358.836 +IMPL_ISetCompressCodecsInfo
 358.837 +
 358.838 +}}
   359.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   359.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarHandler.h	Sat Mar 03 10:31:27 2012 -0600
   359.3 @@ -0,0 +1,60 @@
   359.4 +// Rar/Handler.h
   359.5 +
   359.6 +#ifndef __RAR_HANDLER_H
   359.7 +#define __RAR_HANDLER_H
   359.8 +
   359.9 +#include "../IArchive.h"
  359.10 +#include "RarIn.h"
  359.11 +#include "RarVolumeInStream.h"
  359.12 +
  359.13 +#include "../../Common/CreateCoder.h"
  359.14 +
  359.15 +namespace NArchive {
  359.16 +namespace NRar {
  359.17 +
  359.18 +class CHandler:
  359.19 +  public IInArchive,
  359.20 +  PUBLIC_ISetCompressCodecsInfo
  359.21 +  public CMyUnknownImp
  359.22 +{
  359.23 +public:
  359.24 +  MY_QUERYINTERFACE_BEGIN2(IInArchive)
  359.25 +  QUERY_ENTRY_ISetCompressCodecsInfo
  359.26 +  MY_QUERYINTERFACE_END
  359.27 +  MY_ADDREF_RELEASE
  359.28 +  
  359.29 +  INTERFACE_IInArchive(;)
  359.30 +
  359.31 +  DECL_ISetCompressCodecsInfo
  359.32 +
  359.33 +private:
  359.34 +  CRecordVector<CRefItem> _refItems;
  359.35 +  CObjectVector<CItemEx> _items;
  359.36 +  CObjectVector<CInArchive> _archives;
  359.37 +  NArchive::NRar::CInArchiveInfo _archiveInfo;
  359.38 +
  359.39 +  DECL_EXTERNAL_CODECS_VARS
  359.40 +
  359.41 +  UInt64 GetPackSize(int refIndex) const;
  359.42 +  // NArchive::NRar::CInArchive _archive;
  359.43 +
  359.44 +  bool IsSolid(int refIndex)
  359.45 +  {
  359.46 +    const CItemEx &item = _items[_refItems[refIndex].ItemIndex];
  359.47 +    if (item.UnPackVersion < 20)
  359.48 +    {
  359.49 +      if (_archiveInfo.IsSolid())
  359.50 +        return (refIndex > 0);
  359.51 +      return false;
  359.52 +    }
  359.53 +    return item.IsSolid();
  359.54 +  }
  359.55 +
  359.56 +  HRESULT Open2(IInStream *stream,
  359.57 +      const UInt64 *maxCheckStartPosition,
  359.58 +      IArchiveOpenCallback *openArchiveCallback);
  359.59 +};
  359.60 +
  359.61 +}}
  359.62 +
  359.63 +#endif
   360.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   360.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarHeader.cpp	Sat Mar 03 10:31:27 2012 -0600
   360.3 @@ -0,0 +1,19 @@
   360.4 +// Archive/Rar/Headers.cpp
   360.5 +
   360.6 +#include "StdAfx.h"
   360.7 +
   360.8 +#include "RarHeader.h"
   360.9 +
  360.10 +namespace NArchive{
  360.11 +namespace NRar{
  360.12 +namespace NHeader{
  360.13 +
  360.14 +Byte kMarker[kMarkerSize] = {0x52 + 1, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00};
  360.15 +  
  360.16 +class CMarkerInitializer
  360.17 +{
  360.18 +public:
  360.19 +  CMarkerInitializer() { kMarker[0]--; };
  360.20 +} g_MarkerInitializer;
  360.21 +
  360.22 +}}}
   361.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   361.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarHeader.h	Sat Mar 03 10:31:27 2012 -0600
   361.3 @@ -0,0 +1,224 @@
   361.4 +// Archive/RarHeader.h
   361.5 +
   361.6 +#ifndef __ARCHIVE_RAR_HEADER_H
   361.7 +#define __ARCHIVE_RAR_HEADER_H
   361.8 +
   361.9 +#include "Common/Types.h"
  361.10 +
  361.11 +namespace NArchive{
  361.12 +namespace NRar{
  361.13 +namespace NHeader{
  361.14 +
  361.15 +const int kMarkerSize = 7;
  361.16 +extern Byte kMarker[kMarkerSize];
  361.17 +  
  361.18 +const int kArchiveSolid = 0x1;
  361.19 +
  361.20 +namespace NBlockType
  361.21 +{
  361.22 +  enum EBlockType
  361.23 +  {
  361.24 +    kMarker        = 0x72,
  361.25 +    kArchiveHeader = 0x73,
  361.26 +    kFileHeader    = 0x74,
  361.27 +    kCommentHeader = 0x75,
  361.28 +    kOldAuthenticity = 0x76,
  361.29 +    kSubBlock       = 0x77,
  361.30 +    kRecoveryRecord = 0x78,
  361.31 +    kAuthenticity   = 0x79,
  361.32 +
  361.33 +    kEndOfArchive   = 0x7B // Is not safe
  361.34 +  };
  361.35 +}
  361.36 +
  361.37 +namespace NArchive
  361.38 +{
  361.39 +  const UInt16 kVolume  = 1;
  361.40 +  const UInt16 kComment = 2;
  361.41 +  const UInt16 kLock    = 4;
  361.42 +  const UInt16 kSolid   = 8;
  361.43 +  const UInt16 kNewVolName = 0x10; // ('volname.partN.rar')
  361.44 +  const UInt16 kAuthenticity  = 0x20;
  361.45 +  const UInt16 kRecovery = 0x40;
  361.46 +  const UInt16 kBlockEncryption  = 0x80;
  361.47 +  const UInt16 kFirstVolume = 0x100; // (set only by RAR 3.0 and later)
  361.48 +  const UInt16 kEncryptVer = 0x200; // RAR 3.6 there is EncryptVer Byte in End of MainHeader
  361.49 +  
  361.50 +  const int kHeaderSizeMin = 7;
  361.51 +
  361.52 +  struct CBlock
  361.53 +  {
  361.54 +    UInt16 CRC;
  361.55 +    Byte Type;
  361.56 +    UInt16 Flags;
  361.57 +    UInt16 Size;
  361.58 +    UInt16 Reserved1;
  361.59 +    UInt32 Reserved2;
  361.60 +    // UInt16 GetRealCRC() const;
  361.61 +  };
  361.62 +  
  361.63 +  const int kArchiveHeaderSize = 13;
  361.64 +
  361.65 +  const int kBlockHeadersAreEncrypted = 0x80;
  361.66 +
  361.67 +  struct CHeader360: public CBlock
  361.68 +  {
  361.69 +    Byte EncryptVersion;
  361.70 +    bool IsEncrypted() const { return (Flags & NHeader::NArchive::kBlockEncryption) != 0; }
  361.71 +    bool IsThereEncryptVer() const { return (Flags & NHeader::NArchive::kEncryptVer) != 0; }
  361.72 +    bool IsEncryptOld() const { return (!IsThereEncryptVer() || EncryptVersion < 36); }
  361.73 +    UInt32 GetBaseSize() const { return kArchiveHeaderSize + (IsEncryptOld() ? 0 : 1); }
  361.74 +  };
  361.75 +}
  361.76 +
  361.77 +namespace NFile
  361.78 +{
  361.79 +  const int kSplitBefore = 1 << 0;
  361.80 +  const int kSplitAfter  = 1 << 1;
  361.81 +  const int kEncrypted   = 1 << 2;
  361.82 +  const int kComment     = 1 << 3;
  361.83 +  const int kSolid       = 1 << 4;
  361.84 +  
  361.85 +  const int kDictBitStart     = 5;
  361.86 +  const int kNumDictBits  = 3;
  361.87 +  const int kDictMask         = (1 << kNumDictBits) - 1;
  361.88 +  const int kDictDirectoryValue  = 0x7;
  361.89 +  
  361.90 +  const int kSize64Bits    = 1 << 8;
  361.91 +  const int kUnicodeName   = 1 << 9;
  361.92 +  const int kSalt          = 1 << 10;
  361.93 +  const int kOldVersion    = 1 << 11;
  361.94 +  const int kExtTime       = 1 << 12;
  361.95 +  // const int kExtFlags      = 1 << 13;
  361.96 +  // const int kSkipIfUnknown = 1 << 14;
  361.97 +
  361.98 +  const int kLongBlock    = 1 << 15;
  361.99 +  
 361.100 +  /*
 361.101 +  struct CBlock
 361.102 +  {
 361.103 +    // UInt16 HeadCRC;
 361.104 +    // Byte Type;
 361.105 +    // UInt16 Flags;
 361.106 +    // UInt16 HeadSize;
 361.107 +    UInt32 PackSize;
 361.108 +    UInt32 UnPackSize;
 361.109 +    Byte HostOS;
 361.110 +    UInt32 FileCRC;
 361.111 +    UInt32 Time;
 361.112 +    Byte UnPackVersion;
 361.113 +    Byte Method;
 361.114 +    UInt16 NameSize;
 361.115 +    UInt32 Attributes;
 361.116 +  };
 361.117 +  */
 361.118 +
 361.119 +  /*
 361.120 +  struct CBlock32
 361.121 +  {
 361.122 +    UInt16 HeadCRC;
 361.123 +    Byte Type;
 361.124 +    UInt16 Flags;
 361.125 +    UInt16 HeadSize;
 361.126 +    UInt32 PackSize;
 361.127 +    UInt32 UnPackSize;
 361.128 +    Byte HostOS;
 361.129 +    UInt32 FileCRC;
 361.130 +    UInt32 Time;
 361.131 +    Byte UnPackVersion;
 361.132 +    Byte Method;
 361.133 +    UInt16 NameSize;
 361.134 +    UInt32 Attributes;
 361.135 +    UInt16 GetRealCRC(const void *aName, UInt32 aNameSize,
 361.136 +        bool anExtraDataDefined = false, Byte *anExtraData = 0) const;
 361.137 +  };
 361.138 +  struct CBlock64
 361.139 +  {
 361.140 +    UInt16 HeadCRC;
 361.141 +    Byte Type;
 361.142 +    UInt16 Flags;
 361.143 +    UInt16 HeadSize;
 361.144 +    UInt32 PackSizeLow;
 361.145 +    UInt32 UnPackSizeLow;
 361.146 +    Byte HostOS;
 361.147 +    UInt32 FileCRC;
 361.148 +    UInt32 Time;
 361.149 +    Byte UnPackVersion;
 361.150 +    Byte Method;
 361.151 +    UInt16 NameSize;
 361.152 +    UInt32 Attributes;
 361.153 +    UInt32 PackSizeHigh;
 361.154 +    UInt32 UnPackSizeHigh;
 361.155 +    UInt16 GetRealCRC(const void *aName, UInt32 aNameSize) const;
 361.156 +  };
 361.157 +  */
 361.158 +  
 361.159 +  const int kLabelFileAttribute            = 0x08;
 361.160 +  const int kWinFileDirectoryAttributeMask = 0x10;
 361.161 +  
 361.162 +  enum CHostOS
 361.163 +  {
 361.164 +    kHostMSDOS = 0,
 361.165 +      kHostOS2   = 1,
 361.166 +      kHostWin32 = 2,
 361.167 +      kHostUnix  = 3,
 361.168 +      kHostMacOS = 4,
 361.169 +      kHostBeOS = 5
 361.170 +  };
 361.171 +}
 361.172 +
 361.173 +namespace NBlock
 361.174 +{
 361.175 +  const UInt16 kLongBlock = 1 << 15;
 361.176 +  struct CBlock
 361.177 +  {
 361.178 +    UInt16 CRC;
 361.179 +    Byte Type;
 361.180 +    UInt16 Flags;
 361.181 +    UInt16 HeadSize;
 361.182 +    //  UInt32 DataSize;
 361.183 +  };
 361.184 +}
 361.185 +
 361.186 +/*
 361.187 +struct CSubBlock
 361.188 +{
 361.189 +  UInt16 HeadCRC;
 361.190 +  Byte HeadType;
 361.191 +  UInt16 Flags;
 361.192 +  UInt16 HeadSize;
 361.193 +  UInt32 DataSize;
 361.194 +  UInt16 SubType;
 361.195 +  Byte Level; // Reserved : Must be 0
 361.196 +};
 361.197 +
 361.198 +struct CCommentBlock
 361.199 +{
 361.200 +  UInt16 HeadCRC;
 361.201 +  Byte HeadType;
 361.202 +  UInt16 Flags;
 361.203 +  UInt16 HeadSize;
 361.204 +  UInt16 UnpSize;
 361.205 +  Byte UnpVer;
 361.206 +  Byte Method;
 361.207 +  UInt16 CommCRC;
 361.208 +};
 361.209 +
 361.210 +
 361.211 +struct CProtectHeader
 361.212 +{
 361.213 +  UInt16 HeadCRC;
 361.214 +  Byte HeadType;
 361.215 +  UInt16 Flags;
 361.216 +  UInt16 HeadSize;
 361.217 +  UInt32 DataSize;
 361.218 +  Byte Version;
 361.219 +  UInt16 RecSectors;
 361.220 +  UInt32 TotalBlocks;
 361.221 +  Byte Mark[8];
 361.222 +};
 361.223 +*/
 361.224 +
 361.225 +}}}
 361.226 +
 361.227 +#endif
   362.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   362.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarIn.cpp	Sat Mar 03 10:31:27 2012 -0600
   362.3 @@ -0,0 +1,513 @@
   362.4 +// Archive/RarIn.cpp
   362.5 +
   362.6 +#include "StdAfx.h"
   362.7 +
   362.8 +#include "Common/StringConvert.h"
   362.9 +#include "Common/UTFConvert.h"
  362.10 +
  362.11 +#include "RarIn.h"
  362.12 +#include "../../Common/LimitedStreams.h"
  362.13 +#include "../../Common/StreamUtils.h"
  362.14 +
  362.15 +#include "../Common/FindSignature.h"
  362.16 +
  362.17 +extern "C"
  362.18 +{
  362.19 +  #include "../../../../C/7zCrc.h"
  362.20 +}
  362.21 +
  362.22 +namespace NArchive {
  362.23 +namespace NRar {
  362.24 + 
  362.25 +void CInArchive::ThrowExceptionWithCode(
  362.26 +    CInArchiveException::CCauseType cause)
  362.27 +{
  362.28 +  throw CInArchiveException(cause);
  362.29 +}
  362.30 +
  362.31 +HRESULT CInArchive::Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit)
  362.32 +{
  362.33 +  try
  362.34 +  {
  362.35 +    Close();
  362.36 +    HRESULT res = Open2(inStream, searchHeaderSizeLimit);
  362.37 +    if (res == S_OK)
  362.38 +      return res;
  362.39 +    Close();
  362.40 +    return res;
  362.41 +  }
  362.42 +  catch(...) { Close(); throw; }
  362.43 +}
  362.44 +
  362.45 +void CInArchive::Close()
  362.46 +{
  362.47 +  m_Stream.Release();
  362.48 +}
  362.49 +
  362.50 +
  362.51 +static inline bool TestMarkerCandidate(const void *aTestBytes)
  362.52 +{
  362.53 +  for (UInt32 i = 0; i < NHeader::kMarkerSize; i++)
  362.54 +    if (((const Byte *)aTestBytes)[i] != NHeader::kMarker[i])
  362.55 +      return false;
  362.56 +  return true;
  362.57 +}
  362.58 +
  362.59 +HRESULT CInArchive::FindAndReadMarker(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
  362.60 +{
  362.61 +  RINOK(FindSignatureInStream(stream,
  362.62 +      NHeader::kMarker, NHeader::kMarkerSize,
  362.63 +      searchHeaderSizeLimit, m_ArchiveStartPosition));
  362.64 +  m_Stream = stream;
  362.65 +  m_Position = m_ArchiveStartPosition + NHeader::kMarkerSize;
  362.66 +  return m_Stream->Seek(m_Position, STREAM_SEEK_SET, NULL);
  362.67 +}
  362.68 +
  362.69 +void CInArchive::ThrowUnexpectedEndOfArchiveException()
  362.70 +{
  362.71 +  ThrowExceptionWithCode(CInArchiveException::kUnexpectedEndOfArchive);
  362.72 +}
  362.73 +
  362.74 +bool CInArchive::ReadBytesAndTestSize(void *data, UInt32 size)
  362.75 +{
  362.76 +  if (m_CryptoMode)
  362.77 +  {
  362.78 +    const Byte *bufData = (const Byte *)m_DecryptedData;
  362.79 +    UInt32 bufSize = m_DecryptedDataSize;
  362.80 +    UInt32 i;
  362.81 +    for (i = 0; i < size && m_CryptoPos < bufSize; i++)
  362.82 +      ((Byte *)data)[i] = bufData[m_CryptoPos++];
  362.83 +    return (i == size);
  362.84 +  }
  362.85 +  return (ReadStream_FALSE(m_Stream, data, size) == S_OK);
  362.86 +}
  362.87 +
  362.88 +void CInArchive::ReadBytesAndTestResult(void *data, UInt32 size)
  362.89 +{
  362.90 +  if(!ReadBytesAndTestSize(data,size))
  362.91 +    ThrowUnexpectedEndOfArchiveException();
  362.92 +}
  362.93 +
  362.94 +HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 *processedSize)
  362.95 +{
  362.96 +  size_t realProcessedSize = size;
  362.97 +  HRESULT result = ReadStream(m_Stream, data, &realProcessedSize);
  362.98 +  if (processedSize != NULL)
  362.99 +    *processedSize = (UInt32)realProcessedSize;
 362.100 +  AddToSeekValue(realProcessedSize);
 362.101 +  return result;
 362.102 +}
 362.103 +
 362.104 +static UInt32 CrcUpdateUInt16(UInt32 crc, UInt16 v)
 362.105 +{
 362.106 +  crc = CRC_UPDATE_BYTE(crc, (Byte)(v & 0xFF));
 362.107 +  crc = CRC_UPDATE_BYTE(crc, (Byte)((v >> 8) & 0xFF));
 362.108 +  return crc;
 362.109 +}
 362.110 +
 362.111 +static UInt32 CrcUpdateUInt32(UInt32 crc, UInt32 v)
 362.112 +{
 362.113 +  crc = CRC_UPDATE_BYTE(crc, (Byte)(v & 0xFF));
 362.114 +  crc = CRC_UPDATE_BYTE(crc, (Byte)((v >> 8) & 0xFF));
 362.115 +  crc = CRC_UPDATE_BYTE(crc, (Byte)((v >> 16) & 0xFF));
 362.116 +  crc = CRC_UPDATE_BYTE(crc, (Byte)((v >> 24) & 0xFF));
 362.117 +  return crc;
 362.118 +}
 362.119 +
 362.120 +
 362.121 +HRESULT CInArchive::Open2(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
 362.122 +{
 362.123 +  m_CryptoMode = false;
 362.124 +  RINOK(stream->Seek(0, STREAM_SEEK_SET, &m_StreamStartPosition));
 362.125 +  m_Position = m_StreamStartPosition;
 362.126 +
 362.127 +  RINOK(FindAndReadMarker(stream, searchHeaderSizeLimit));
 362.128 +
 362.129 +  Byte buf[NHeader::NArchive::kArchiveHeaderSize];
 362.130 +  UInt32 processedSize;
 362.131 +  ReadBytes(buf, sizeof(buf), &processedSize);
 362.132 +  if (processedSize != sizeof(buf))
 362.133 +    return S_FALSE;
 362.134 +  m_CurData = buf;
 362.135 +  m_CurPos = 0;
 362.136 +  m_PosLimit = sizeof(buf);
 362.137 +
 362.138 +  m_ArchiveHeader.CRC = ReadUInt16();
 362.139 +  m_ArchiveHeader.Type = ReadByte();
 362.140 +  m_ArchiveHeader.Flags = ReadUInt16();
 362.141 +  m_ArchiveHeader.Size = ReadUInt16();
 362.142 +  m_ArchiveHeader.Reserved1 = ReadUInt16();
 362.143 +  m_ArchiveHeader.Reserved2 = ReadUInt32();
 362.144 +  m_ArchiveHeader.EncryptVersion = 0;
 362.145 +
 362.146 +  UInt32 crc = CRC_INIT_VAL;
 362.147 +  crc = CRC_UPDATE_BYTE(crc, m_ArchiveHeader.Type);
 362.148 +  crc = CrcUpdateUInt16(crc, m_ArchiveHeader.Flags);
 362.149 +  crc = CrcUpdateUInt16(crc, m_ArchiveHeader.Size);
 362.150 +  crc = CrcUpdateUInt16(crc, m_ArchiveHeader.Reserved1);
 362.151 +  crc = CrcUpdateUInt32(crc, m_ArchiveHeader.Reserved2);
 362.152 +
 362.153 +  if (m_ArchiveHeader.IsThereEncryptVer() && m_ArchiveHeader.Size > NHeader::NArchive::kArchiveHeaderSize)
 362.154 +  {
 362.155 +    ReadBytes(&m_ArchiveHeader.EncryptVersion, 1, &processedSize);
 362.156 +    if (processedSize != 1)
 362.157 +      return S_FALSE;
 362.158 +    crc = CRC_UPDATE_BYTE(crc, m_ArchiveHeader.EncryptVersion);
 362.159 +  }
 362.160 +
 362.161 +  if(m_ArchiveHeader.CRC != (CRC_GET_DIGEST(crc) & 0xFFFF))
 362.162 +    ThrowExceptionWithCode(CInArchiveException::kArchiveHeaderCRCError);
 362.163 +  if (m_ArchiveHeader.Type != NHeader::NBlockType::kArchiveHeader)
 362.164 +    return S_FALSE;
 362.165 +  m_ArchiveCommentPosition = m_Position;
 362.166 +  m_SeekOnArchiveComment = true;
 362.167 +  return S_OK;
 362.168 +}
 362.169 +
 362.170 +void CInArchive::SkipArchiveComment()
 362.171 +{
 362.172 +  if (!m_SeekOnArchiveComment)
 362.173 +    return;
 362.174 +  AddToSeekValue(m_ArchiveHeader.Size - m_ArchiveHeader.GetBaseSize());
 362.175 +  m_SeekOnArchiveComment = false;
 362.176 +}
 362.177 +
 362.178 +void CInArchive::GetArchiveInfo(CInArchiveInfo &archiveInfo) const
 362.179 +{
 362.180 +  archiveInfo.StartPosition = m_ArchiveStartPosition;
 362.181 +  archiveInfo.Flags = m_ArchiveHeader.Flags;
 362.182 +  archiveInfo.CommentPosition = m_ArchiveCommentPosition;
 362.183 +  archiveInfo.CommentSize = (UInt16)(m_ArchiveHeader.Size - NHeader::NArchive::kArchiveHeaderSize);
 362.184 +}
 362.185 +
 362.186 +static void DecodeUnicodeFileName(const char *name, const Byte *encName,
 362.187 +    int encSize, wchar_t *unicodeName, int maxDecSize)
 362.188 +{
 362.189 +  int encPos = 0;
 362.190 +  int decPos = 0;
 362.191 +  int flagBits = 0;
 362.192 +  Byte flags = 0;
 362.193 +  Byte highByte = encName[encPos++];
 362.194 +  while (encPos < encSize && decPos < maxDecSize)
 362.195 +  {
 362.196 +    if (flagBits == 0)
 362.197 +    {
 362.198 +      flags = encName[encPos++];
 362.199 +      flagBits = 8;
 362.200 +    }
 362.201 +    switch(flags >> 6)
 362.202 +    {
 362.203 +      case 0:
 362.204 +        unicodeName[decPos++] = encName[encPos++];
 362.205 +        break;
 362.206 +      case 1:
 362.207 +        unicodeName[decPos++] = (wchar_t)(encName[encPos++] + (highByte << 8));
 362.208 +        break;
 362.209 +      case 2:
 362.210 +        unicodeName[decPos++] = (wchar_t)(encName[encPos] + (encName[encPos + 1] << 8));
 362.211 +        encPos += 2;
 362.212 +        break;
 362.213 +      case 3:
 362.214 +        {
 362.215 +          int length = encName[encPos++];
 362.216 +          if (length & 0x80)
 362.217 +          {
 362.218 +            Byte correction = encName[encPos++];
 362.219 +            for (length = (length & 0x7f) + 2;
 362.220 +                length > 0 && decPos < maxDecSize; length--, decPos++)
 362.221 +              unicodeName[decPos] = (wchar_t)(((name[decPos] + correction) & 0xff) + (highByte << 8));
 362.222 +          }
 362.223 +          else
 362.224 +            for (length += 2; length > 0 && decPos < maxDecSize; length--, decPos++)
 362.225 +              unicodeName[decPos] = name[decPos];
 362.226 +        }
 362.227 +        break;
 362.228 +    }
 362.229 +    flags <<= 2;
 362.230 +    flagBits -= 2;
 362.231 +  }
 362.232 +  unicodeName[decPos < maxDecSize ? decPos : maxDecSize - 1] = 0;
 362.233 +}
 362.234 +
 362.235 +void CInArchive::ReadName(CItemEx &item, int nameSize)
 362.236 +{
 362.237 +  item.UnicodeName.Empty();
 362.238 +  if (nameSize > 0)
 362.239 +  {
 362.240 +    m_NameBuffer.EnsureCapacity(nameSize + 1);
 362.241 +    char *buffer = (char *)m_NameBuffer;
 362.242 +
 362.243 +    for (int i = 0; i < nameSize; i++)
 362.244 +      buffer[i] = ReadByte();
 362.245 +
 362.246 +    int mainLen;
 362.247 +    for (mainLen = 0; mainLen < nameSize; mainLen++)
 362.248 +      if (buffer[mainLen] == '\0')
 362.249 +        break;
 362.250 +    buffer[mainLen] = '\0';
 362.251 +    item.Name = buffer;
 362.252 +
 362.253 +    if(item.HasUnicodeName())
 362.254 +    {
 362.255 +      if(mainLen < nameSize)
 362.256 +      {
 362.257 +        int unicodeNameSizeMax = MyMin(nameSize, (0x400));
 362.258 +        _unicodeNameBuffer.EnsureCapacity(unicodeNameSizeMax + 1);
 362.259 +        DecodeUnicodeFileName(buffer, (const Byte *)buffer + mainLen + 1,
 362.260 +            nameSize - (mainLen + 1), _unicodeNameBuffer, unicodeNameSizeMax);
 362.261 +        item.UnicodeName = _unicodeNameBuffer;
 362.262 +      }
 362.263 +      else if (!ConvertUTF8ToUnicode(item.Name, item.UnicodeName))
 362.264 +        item.UnicodeName.Empty();
 362.265 +    }
 362.266 +  }
 362.267 +  else
 362.268 +    item.Name.Empty();
 362.269 +}
 362.270 +
 362.271 +Byte CInArchive::ReadByte()
 362.272 +{
 362.273 +  if (m_CurPos >= m_PosLimit)
 362.274 +    throw CInArchiveException(CInArchiveException::kIncorrectArchive);
 362.275 +  return m_CurData[m_CurPos++];
 362.276 +}
 362.277 +
 362.278 +UInt16 CInArchive::ReadUInt16()
 362.279 +{
 362.280 +  UInt16 value = 0;
 362.281 +  for (int i = 0; i < 2; i++)
 362.282 +  {
 362.283 +    Byte b = ReadByte();
 362.284 +    value |= (UInt16(b) << (8 * i));
 362.285 +  }
 362.286 +  return value;
 362.287 +}
 362.288 +
 362.289 +UInt32 CInArchive::ReadUInt32()
 362.290 +{
 362.291 +  UInt32 value = 0;
 362.292 +  for (int i = 0; i < 4; i++)
 362.293 +  {
 362.294 +    Byte b = ReadByte();
 362.295 +    value |= (UInt32(b) << (8 * i));
 362.296 +  }
 362.297 +  return value;
 362.298 +}
 362.299 +
 362.300 +void CInArchive::ReadTime(Byte mask, CRarTime &rarTime)
 362.301 +{
 362.302 +  rarTime.LowSecond = (Byte)(((mask & 4) != 0) ? 1 : 0);
 362.303 +  int numDigits = (mask & 3);
 362.304 +  rarTime.SubTime[0] = rarTime.SubTime[1] = rarTime.SubTime[2] = 0;
 362.305 +  for (int i = 0; i < numDigits; i++)
 362.306 +    rarTime.SubTime[3 - numDigits + i] = ReadByte();
 362.307 +}
 362.308 +
 362.309 +void CInArchive::ReadHeaderReal(CItemEx &item)
 362.310 +{
 362.311 +  item.Flags = m_BlockHeader.Flags;
 362.312 +  item.PackSize = ReadUInt32();
 362.313 +  item.Size = ReadUInt32();
 362.314 +  item.HostOS = ReadByte();
 362.315 +  item.FileCRC = ReadUInt32();
 362.316 +  item.MTime.DosTime = ReadUInt32();
 362.317 +  item.UnPackVersion = ReadByte();
 362.318 +  item.Method = ReadByte();
 362.319 +  int nameSize = ReadUInt16();
 362.320 +  item.Attrib = ReadUInt32();
 362.321 +
 362.322 +  item.MTime.LowSecond = 0;
 362.323 +  item.MTime.SubTime[0] =
 362.324 +      item.MTime.SubTime[1] =
 362.325 +      item.MTime.SubTime[2] = 0;
 362.326 +
 362.327 +  if((item.Flags & NHeader::NFile::kSize64Bits) != 0)
 362.328 +  {
 362.329 +    item.PackSize |= ((UInt64)ReadUInt32() << 32);
 362.330 +    item.Size |= ((UInt64)ReadUInt32() << 32);
 362.331 +  }
 362.332 +
 362.333 +  ReadName(item, nameSize);
 362.334 +
 362.335 +  if (item.HasSalt())
 362.336 +    for (int i = 0; i < sizeof(item.Salt); i++)
 362.337 +      item.Salt[i] = ReadByte();
 362.338 +
 362.339 +  // some rar archives have HasExtTime flag without field.
 362.340 +  if (m_CurPos < m_PosLimit && item.HasExtTime())
 362.341 +  {
 362.342 +    Byte accessMask = (Byte)(ReadByte() >> 4);
 362.343 +    Byte b = ReadByte();
 362.344 +    Byte modifMask = (Byte)(b >> 4);
 362.345 +    Byte createMask = (Byte)(b & 0xF);
 362.346 +    if ((modifMask & 8) != 0)
 362.347 +      ReadTime(modifMask, item.MTime);
 362.348 +    item.CTimeDefined = ((createMask & 8) != 0);
 362.349 +    if (item.CTimeDefined)
 362.350 +    {
 362.351 +      item.CTime.DosTime = ReadUInt32();
 362.352 +      ReadTime(createMask, item.CTime);
 362.353 +    }
 362.354 +    item.ATimeDefined = ((accessMask & 8) != 0);
 362.355 +    if (item.ATimeDefined)
 362.356 +    {
 362.357 +      item.ATime.DosTime = ReadUInt32();
 362.358 +      ReadTime(accessMask, item.ATime);
 362.359 +    }
 362.360 +  }
 362.361 +
 362.362 +  UInt16 fileHeaderWithNameSize = (UInt16)m_CurPos;
 362.363 +  
 362.364 +  item.Position = m_Position;
 362.365 +  item.MainPartSize = fileHeaderWithNameSize;
 362.366 +  item.CommentSize = (UInt16)(m_BlockHeader.HeadSize - fileHeaderWithNameSize);
 362.367 +
 362.368 +  if (m_CryptoMode)
 362.369 +    item.AlignSize = (UInt16)((16 - ((m_BlockHeader.HeadSize) & 0xF)) & 0xF);
 362.370 +  else
 362.371 +    item.AlignSize = 0;
 362.372 +  AddToSeekValue(m_BlockHeader.HeadSize);
 362.373 +}
 362.374 +
 362.375 +void CInArchive::AddToSeekValue(UInt64 addValue)
 362.376 +{
 362.377 +  m_Position += addValue;
 362.378 +}
 362.379 +
 362.380 +HRESULT CInArchive::GetNextItem(CItemEx &item, ICryptoGetTextPassword *getTextPassword)
 362.381 +{
 362.382 +  if (m_SeekOnArchiveComment)
 362.383 +    SkipArchiveComment();
 362.384 +  for (;;)
 362.385 +  {
 362.386 +    if(!SeekInArchive(m_Position))
 362.387 +      return S_FALSE;
 362.388 +    if (!m_CryptoMode && (m_ArchiveHeader.Flags &
 362.389 +        NHeader::NArchive::kBlockHeadersAreEncrypted) != 0)
 362.390 +    {
 362.391 +      m_CryptoMode = false;
 362.392 +      if (getTextPassword == 0)
 362.393 +        return S_FALSE;
 362.394 +      if(!SeekInArchive(m_Position))
 362.395 +        return S_FALSE;
 362.396 +      if (!m_RarAES)
 362.397 +      {
 362.398 +        m_RarAESSpec = new NCrypto::NRar29::CDecoder;
 362.399 +        m_RarAES = m_RarAESSpec;
 362.400 +      }
 362.401 +      m_RarAESSpec->SetRar350Mode(m_ArchiveHeader.IsEncryptOld());
 362.402 +
 362.403 +      // Salt
 362.404 +      const UInt32 kSaltSize = 8;
 362.405 +      Byte salt[kSaltSize];
 362.406 +      if(!ReadBytesAndTestSize(salt, kSaltSize))
 362.407 +        return S_FALSE;
 362.408 +      m_Position += kSaltSize;
 362.409 +      RINOK(m_RarAESSpec->SetDecoderProperties2(salt, kSaltSize))
 362.410 +      // Password
 362.411 +      CMyComBSTR password;
 362.412 +      RINOK(getTextPassword->CryptoGetTextPassword(&password))
 362.413 +      UString unicodePassword(password);
 362.414 +
 362.415 +      CByteBuffer buffer;
 362.416 +      const UInt32 sizeInBytes = unicodePassword.Length() * 2;
 362.417 +      buffer.SetCapacity(sizeInBytes);
 362.418 +      for (int i = 0; i < unicodePassword.Length(); i++)
 362.419 +      {
 362.420 +        wchar_t c = unicodePassword[i];
 362.421 +        ((Byte *)buffer)[i * 2] = (Byte)c;
 362.422 +        ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
 362.423 +      }
 362.424 +
 362.425 +      RINOK(m_RarAESSpec->CryptoSetPassword((const Byte *)buffer, sizeInBytes));
 362.426 +
 362.427 +      const UInt32 kDecryptedBufferSize = (1 << 12);
 362.428 +      if (m_DecryptedData.GetCapacity() == 0)
 362.429 +      {
 362.430 +        m_DecryptedData.SetCapacity(kDecryptedBufferSize);
 362.431 +      }
 362.432 +      RINOK(m_RarAES->Init());
 362.433 +      size_t decryptedDataSizeT = kDecryptedBufferSize;
 362.434 +      RINOK(ReadStream(m_Stream, (Byte *)m_DecryptedData, &decryptedDataSizeT));
 362.435 +      m_DecryptedDataSize = (UInt32)decryptedDataSizeT;
 362.436 +      m_DecryptedDataSize = m_RarAES->Filter((Byte *)m_DecryptedData, m_DecryptedDataSize);
 362.437 +
 362.438 +      m_CryptoMode = true;
 362.439 +      m_CryptoPos = 0;
 362.440 +    }
 362.441 +
 362.442 +    m_FileHeaderData.EnsureCapacity(7);
 362.443 +    if(!ReadBytesAndTestSize((Byte *)m_FileHeaderData, 7))
 362.444 +      return S_FALSE;
 362.445 +
 362.446 +    m_CurData = (Byte *)m_FileHeaderData;
 362.447 +    m_CurPos = 0;
 362.448 +    m_PosLimit = 7;
 362.449 +    m_BlockHeader.CRC = ReadUInt16();
 362.450 +    m_BlockHeader.Type = ReadByte();
 362.451 +    m_BlockHeader.Flags = ReadUInt16();
 362.452 +    m_BlockHeader.HeadSize = ReadUInt16();
 362.453 +
 362.454 +    if (m_BlockHeader.HeadSize < 7)
 362.455 +      ThrowExceptionWithCode(CInArchiveException::kIncorrectArchive);
 362.456 +
 362.457 +    if (m_BlockHeader.Type == NHeader::NBlockType::kEndOfArchive)
 362.458 +      return S_FALSE;
 362.459 +
 362.460 +    if (m_BlockHeader.Type == NHeader::NBlockType::kFileHeader)
 362.461 +    {
 362.462 +      m_FileHeaderData.EnsureCapacity(m_BlockHeader.HeadSize);
 362.463 +      m_CurData = (Byte *)m_FileHeaderData;
 362.464 +      m_PosLimit = m_BlockHeader.HeadSize;
 362.465 +      ReadBytesAndTestResult(m_CurData + m_CurPos, m_BlockHeader.HeadSize - 7);
 362.466 +      ReadHeaderReal(item);
 362.467 +      if ((CrcCalc(m_CurData + 2,
 362.468 +          m_BlockHeader.HeadSize - item.CommentSize - 2) & 0xFFFF) != m_BlockHeader.CRC)
 362.469 +        ThrowExceptionWithCode(CInArchiveException::kFileHeaderCRCError);
 362.470 +
 362.471 +      FinishCryptoBlock();
 362.472 +      m_CryptoMode = false;
 362.473 +      SeekInArchive(m_Position); // Move Position to compressed Data;
 362.474 +      AddToSeekValue(item.PackSize);  // m_Position points to next header;
 362.475 +      return S_OK;
 362.476 +    }
 362.477 +    if (m_CryptoMode && m_BlockHeader.HeadSize > (1 << 12))
 362.478 +      return E_FAIL; // it's for bad passwords
 362.479 +    if ((m_BlockHeader.Flags & NHeader::NBlock::kLongBlock) != 0)
 362.480 +    {
 362.481 +      m_FileHeaderData.EnsureCapacity(7 + 4);
 362.482 +      m_CurData = (Byte *)m_FileHeaderData;
 362.483 +      ReadBytesAndTestResult(m_CurData + m_CurPos, 4); // test it
 362.484 +      m_PosLimit = 7 + 4;
 362.485 +      UInt32 dataSize = ReadUInt32();
 362.486 +      AddToSeekValue(dataSize);
 362.487 +      if (m_CryptoMode && dataSize > (1 << 27))
 362.488 +        return E_FAIL; // it's for bad passwords
 362.489 +      m_CryptoPos = m_BlockHeader.HeadSize;
 362.490 +    }
 362.491 +    else
 362.492 +      m_CryptoPos = 0;
 362.493 +    AddToSeekValue(m_BlockHeader.HeadSize);
 362.494 +    FinishCryptoBlock();
 362.495 +    m_CryptoMode = false;
 362.496 +  }
 362.497 +}
 362.498 +
 362.499 +bool CInArchive::SeekInArchive(UInt64 position)
 362.500 +{
 362.501 +  UInt64 newPosition;
 362.502 +  m_Stream->Seek(position, STREAM_SEEK_SET, &newPosition);
 362.503 +  return newPosition == position;
 362.504 +}
 362.505 +
 362.506 +ISequentialInStream* CInArchive::CreateLimitedStream(UInt64 position, UInt64 size)
 362.507 +{
 362.508 +  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
 362.509 +  CMyComPtr<ISequentialInStream> inStream(streamSpec);
 362.510 +  SeekInArchive(position);
 362.511 +  streamSpec->SetStream(m_Stream);
 362.512 +  streamSpec->Init(size);
 362.513 +  return inStream.Detach();
 362.514 +}
 362.515 +
 362.516 +}}
   363.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   363.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarIn.h	Sat Mar 03 10:31:27 2012 -0600
   363.3 @@ -0,0 +1,126 @@
   363.4 +// RarIn.h
   363.5 +
   363.6 +#ifndef __ARCHIVE_RAR_IN_H
   363.7 +#define __ARCHIVE_RAR_IN_H
   363.8 +
   363.9 +#include "Common/DynamicBuffer.h"
  363.10 +#include "Common/MyCom.h"
  363.11 +
  363.12 +#include "../../ICoder.h"
  363.13 +#include "../../IStream.h"
  363.14 +
  363.15 +#include "../../Common/StreamObjects.h"
  363.16 +
  363.17 +#include "../../Crypto/RarAes.h"
  363.18 +
  363.19 +#include "RarHeader.h"
  363.20 +#include "RarItem.h"
  363.21 +
  363.22 +namespace NArchive {
  363.23 +namespace NRar {
  363.24 +
  363.25 +class CInArchiveException
  363.26 +{
  363.27 +public:
  363.28 +  enum CCauseType
  363.29 +  {
  363.30 +    kUnexpectedEndOfArchive = 0,
  363.31 +    kArchiveHeaderCRCError,
  363.32 +    kFileHeaderCRCError,
  363.33 +    kIncorrectArchive
  363.34 +  }
  363.35 +  Cause;
  363.36 +  CInArchiveException(CCauseType cause) :   Cause(cause) {}
  363.37 +};
  363.38 +
  363.39 +class CInArchiveInfo
  363.40 +{
  363.41 +public:
  363.42 +  UInt64 StartPosition;
  363.43 +  UInt16 Flags;
  363.44 +  UInt64 CommentPosition;
  363.45 +  UInt16 CommentSize;
  363.46 +  bool IsSolid() const { return (Flags & NHeader::NArchive::kSolid) != 0; }
  363.47 +  bool IsCommented() const {  return (Flags & NHeader::NArchive::kComment) != 0; }
  363.48 +  bool IsVolume() const {  return (Flags & NHeader::NArchive::kVolume) != 0; }
  363.49 +  bool HaveNewVolumeName() const {  return (Flags & NHeader::NArchive::kNewVolName) != 0; }
  363.50 +  bool IsEncrypted() const { return (Flags & NHeader::NArchive::kBlockEncryption) != 0; }
  363.51 +};
  363.52 +
  363.53 +class CInArchive
  363.54 +{
  363.55 +  CMyComPtr<IInStream> m_Stream;
  363.56 +  
  363.57 +  UInt64 m_StreamStartPosition;
  363.58 +  UInt64 m_Position;
  363.59 +  UInt64 m_ArchiveStartPosition;
  363.60 +  
  363.61 +  NHeader::NArchive::CHeader360 m_ArchiveHeader;
  363.62 +  CDynamicBuffer<char> m_NameBuffer;
  363.63 +  CDynamicBuffer<wchar_t> _unicodeNameBuffer;
  363.64 +  bool m_SeekOnArchiveComment;
  363.65 +  UInt64 m_ArchiveCommentPosition;
  363.66 +  
  363.67 +  void ReadName(CItemEx &item, int nameSize);
  363.68 +  void ReadHeaderReal(CItemEx &item);
  363.69 +  
  363.70 +  HRESULT ReadBytes(void *data, UInt32 size, UInt32 *aProcessedSize);
  363.71 +  bool ReadBytesAndTestSize(void *data, UInt32 size);
  363.72 +  void ReadBytesAndTestResult(void *data, UInt32 size);
  363.73 +  
  363.74 +  HRESULT FindAndReadMarker(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
  363.75 +  HRESULT Open2(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
  363.76 +
  363.77 +  void ThrowExceptionWithCode(CInArchiveException::CCauseType cause);
  363.78 +  void ThrowUnexpectedEndOfArchiveException();
  363.79 +  
  363.80 +  void AddToSeekValue(UInt64 addValue);
  363.81 +  
  363.82 +protected:
  363.83 +
  363.84 +  CDynamicBuffer<Byte> m_FileHeaderData;
  363.85 +  
  363.86 +  NHeader::NBlock::CBlock m_BlockHeader;
  363.87 +
  363.88 +  NCrypto::NRar29::CDecoder *m_RarAESSpec;
  363.89 +  CMyComPtr<ICompressFilter> m_RarAES;
  363.90 +  
  363.91 +  Byte *m_CurData; // it must point to start of Rar::Block
  363.92 +  UInt32 m_CurPos;
  363.93 +  UInt32 m_PosLimit;
  363.94 +  Byte ReadByte();
  363.95 +  UInt16 ReadUInt16();
  363.96 +  UInt32 ReadUInt32();
  363.97 +  void ReadTime(Byte mask, CRarTime &rarTime);
  363.98 +
  363.99 +  CBuffer<Byte> m_DecryptedData;
 363.100 +  UInt32 m_DecryptedDataSize;
 363.101 +
 363.102 +  bool m_CryptoMode;
 363.103 +  UInt32 m_CryptoPos;
 363.104 +  void FinishCryptoBlock()
 363.105 +  {
 363.106 +    if (m_CryptoMode)
 363.107 +      while ((m_CryptoPos & 0xF) != 0)
 363.108 +      {
 363.109 +        m_CryptoPos++;
 363.110 +        m_Position++;
 363.111 +      }
 363.112 +  }
 363.113 +
 363.114 +public:
 363.115 +  HRESULT Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit);
 363.116 +  void Close();
 363.117 +  HRESULT GetNextItem(CItemEx &item, ICryptoGetTextPassword *getTextPassword);
 363.118 +  
 363.119 +  void SkipArchiveComment();
 363.120 +  
 363.121 +  void GetArchiveInfo(CInArchiveInfo &archiveInfo) const;
 363.122 +  
 363.123 +  bool SeekInArchive(UInt64 position);
 363.124 +  ISequentialInStream *CreateLimitedStream(UInt64 position, UInt64 size);
 363.125 +};
 363.126 +  
 363.127 +}}
 363.128 +  
 363.129 +#endif
   364.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   364.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarItem.cpp	Sat Mar 03 10:31:27 2012 -0600
   364.3 @@ -0,0 +1,55 @@
   364.4 +// RarItem.cpp
   364.5 +
   364.6 +#include "StdAfx.h"
   364.7 +
   364.8 +#include "RarItem.h"
   364.9 +
  364.10 +namespace NArchive{
  364.11 +namespace NRar{
  364.12 +
  364.13 +bool CItem::IgnoreItem() const
  364.14 +{
  364.15 +  switch(HostOS)
  364.16 +  {
  364.17 +    case NHeader::NFile::kHostMSDOS:
  364.18 +    case NHeader::NFile::kHostOS2:
  364.19 +    case NHeader::NFile::kHostWin32:
  364.20 +      return ((Attrib & NHeader::NFile::kLabelFileAttribute) != 0);
  364.21 +  }
  364.22 +  return false;
  364.23 +}
  364.24 +
  364.25 +bool CItem::IsDir() const
  364.26 +{
  364.27 +  if (GetDictSize() == NHeader::NFile::kDictDirectoryValue)
  364.28 +    return true;
  364.29 +  switch(HostOS)
  364.30 +  {
  364.31 +    case NHeader::NFile::kHostMSDOS:
  364.32 +    case NHeader::NFile::kHostOS2:
  364.33 +    case NHeader::NFile::kHostWin32:
  364.34 +      if ((Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0)
  364.35 +        return true;
  364.36 +  }
  364.37 +  return false;
  364.38 +}
  364.39 +
  364.40 +UInt32 CItem::GetWinAttributes() const
  364.41 +{
  364.42 +  UInt32 winAttributes;
  364.43 +  switch(HostOS)
  364.44 +  {
  364.45 +    case NHeader::NFile::kHostMSDOS:
  364.46 +    case NHeader::NFile::kHostOS2:
  364.47 +    case NHeader::NFile::kHostWin32:
  364.48 +      winAttributes = Attrib;
  364.49 +      break;
  364.50 +    default:
  364.51 +      winAttributes = 0; // must be converted from unix value;
  364.52 +  }
  364.53 +  if (IsDir())
  364.54 +    winAttributes |= NHeader::NFile::kWinFileDirectoryAttributeMask;
  364.55 +  return winAttributes;
  364.56 +}
  364.57 +
  364.58 +}}
   365.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   365.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarItem.h	Sat Mar 03 10:31:27 2012 -0600
   365.3 @@ -0,0 +1,79 @@
   365.4 +// RarItem.h
   365.5 +
   365.6 +#ifndef __ARCHIVE_RAR_ITEM_H
   365.7 +#define __ARCHIVE_RAR_ITEM_H
   365.8 +
   365.9 +#include "Common/Types.h"
  365.10 +#include "Common/MyString.h"
  365.11 +
  365.12 +#include "RarHeader.h"
  365.13 +
  365.14 +namespace NArchive{
  365.15 +namespace NRar{
  365.16 +
  365.17 +struct CRarTime
  365.18 +{
  365.19 +  UInt32 DosTime;
  365.20 +  Byte LowSecond;
  365.21 +  Byte SubTime[3];
  365.22 +};
  365.23 +
  365.24 +struct CItem
  365.25 +{
  365.26 +  UInt64 Size;
  365.27 +  UInt64 PackSize;
  365.28 +  
  365.29 +  CRarTime CTime;
  365.30 +  CRarTime ATime;
  365.31 +  CRarTime MTime;
  365.32 +
  365.33 +  UInt32 FileCRC;
  365.34 +  UInt32 Attrib;
  365.35 +
  365.36 +  UInt16 Flags;
  365.37 +  Byte HostOS;
  365.38 +  Byte UnPackVersion;
  365.39 +  Byte Method;
  365.40 +
  365.41 +  bool CTimeDefined;
  365.42 +  bool ATimeDefined;
  365.43 +
  365.44 +  AString Name;
  365.45 +  UString UnicodeName;
  365.46 +
  365.47 +  Byte Salt[8];
  365.48 +  
  365.49 +  bool IsEncrypted()   const { return (Flags & NHeader::NFile::kEncrypted) != 0; }
  365.50 +  bool IsSolid()       const { return (Flags & NHeader::NFile::kSolid) != 0; }
  365.51 +  bool IsCommented()   const { return (Flags & NHeader::NFile::kComment) != 0; }
  365.52 +  bool IsSplitBefore() const { return (Flags & NHeader::NFile::kSplitBefore) != 0; }
  365.53 +  bool IsSplitAfter()  const { return (Flags & NHeader::NFile::kSplitAfter) != 0; }
  365.54 +  bool HasSalt()       const { return (Flags & NHeader::NFile::kSalt) != 0; }
  365.55 +  bool HasExtTime()    const { return (Flags & NHeader::NFile::kExtTime) != 0; }
  365.56 +  bool HasUnicodeName()const { return (Flags & NHeader::NFile::kUnicodeName) != 0; }
  365.57 +  bool IsOldVersion()  const { return (Flags & NHeader::NFile::kOldVersion) != 0; }
  365.58 +  
  365.59 +  UInt32 GetDictSize() const { return (Flags >> NHeader::NFile::kDictBitStart) & NHeader::NFile::kDictMask; }
  365.60 +  bool IsDir() const;
  365.61 +  bool IgnoreItem() const;
  365.62 +  UInt32 GetWinAttributes() const;
  365.63 +  
  365.64 +  CItem(): CTimeDefined(false), ATimeDefined(false) {}
  365.65 +};
  365.66 +
  365.67 +class CItemEx: public CItem
  365.68 +{
  365.69 +public:
  365.70 +  UInt64 Position;
  365.71 +  UInt16 MainPartSize;
  365.72 +  UInt16 CommentSize;
  365.73 +  UInt16 AlignSize;
  365.74 +  UInt64 GetFullSize()  const { return MainPartSize + CommentSize + AlignSize + PackSize; };
  365.75 +  //  DWORD GetHeaderWithCommentSize()  const { return MainPartSize + CommentSize; };
  365.76 +  UInt64 GetCommentPosition() const { return Position + MainPartSize; };
  365.77 +  UInt64 GetDataPosition()    const { return GetCommentPosition() + CommentSize + AlignSize; };
  365.78 +};
  365.79 +
  365.80 +}}
  365.81 +
  365.82 +#endif
   366.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   366.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   366.3 @@ -0,0 +1,13 @@
   366.4 +// RarRegister.cpp
   366.5 +
   366.6 +#include "StdAfx.h"
   366.7 +
   366.8 +#include "../../Common/RegisterArc.h"
   366.9 +
  366.10 +#include "RarHandler.h"
  366.11 +static IInArchive *CreateArc() { return new NArchive::NRar::CHandler;  }
  366.12 +
  366.13 +static CArcInfo g_ArcInfo =
  366.14 +  { L"Rar", L"rar r00", 0, 3, {0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00}, 7, false, CreateArc, 0,  };
  366.15 +
  366.16 +REGISTER_ARC(Rar)
   367.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   367.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp	Sat Mar 03 10:31:27 2012 -0600
   367.3 @@ -0,0 +1,84 @@
   367.4 +// RarVolumeInStream.cpp
   367.5 +
   367.6 +#include "StdAfx.h"
   367.7 +
   367.8 +#include "RarVolumeInStream.h"
   367.9 +
  367.10 +#include "Windows/Defs.h"
  367.11 +#include "Common/Defs.h"
  367.12 +
  367.13 +extern "C"
  367.14 +{
  367.15 +  #include "../../../../C/7zCrc.h"
  367.16 +}
  367.17 +
  367.18 +namespace NArchive {
  367.19 +namespace NRar {
  367.20 +
  367.21 +void CFolderInStream::Init(
  367.22 +    CObjectVector<CInArchive> *archives,
  367.23 +    const CObjectVector<CItemEx> *items,
  367.24 +    const CRefItem &refItem)
  367.25 +{
  367.26 +  _archives = archives;
  367.27 +  _items = items;
  367.28 +  _refItem = refItem;
  367.29 +  _curIndex = 0;
  367.30 +  CRCs.Clear();
  367.31 +  _fileIsOpen = false;
  367.32 +}
  367.33 +
  367.34 +HRESULT CFolderInStream::OpenStream()
  367.35 +{
  367.36 +  while (_curIndex < _refItem.NumItems)
  367.37 +  {
  367.38 +    const CItemEx &item = (*_items)[_refItem.ItemIndex + _curIndex];
  367.39 +    _stream.Attach((*_archives)[_refItem.VolumeIndex + _curIndex].
  367.40 +        CreateLimitedStream(item.GetDataPosition(), item.PackSize));
  367.41 +    _curIndex++;
  367.42 +    _fileIsOpen = true;
  367.43 +    _crc = CRC_INIT_VAL;
  367.44 +    return S_OK;
  367.45 +  }
  367.46 +  return S_OK;
  367.47 +}
  367.48 +
  367.49 +HRESULT CFolderInStream::CloseStream()
  367.50 +{
  367.51 +  CRCs.Add(CRC_GET_DIGEST(_crc));
  367.52 +  _stream.Release();
  367.53 +  _fileIsOpen = false;
  367.54 +  return S_OK;
  367.55 +}
  367.56 +
  367.57 +STDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
  367.58 +{
  367.59 +  UInt32 realProcessedSize = 0;
  367.60 +  while ((_curIndex < _refItem.NumItems || _fileIsOpen) && size > 0)
  367.61 +  {
  367.62 +    if (_fileIsOpen)
  367.63 +    {
  367.64 +      UInt32 localProcessedSize;
  367.65 +      RINOK(_stream->Read(
  367.66 +          ((Byte *)data) + realProcessedSize, size, &localProcessedSize));
  367.67 +      _crc = CrcUpdate(_crc, ((Byte *)data) + realProcessedSize, localProcessedSize);
  367.68 +      if (localProcessedSize == 0)
  367.69 +      {
  367.70 +        RINOK(CloseStream());
  367.71 +        continue;
  367.72 +      }
  367.73 +      realProcessedSize += localProcessedSize;
  367.74 +      size -= localProcessedSize;
  367.75 +      break;
  367.76 +    }
  367.77 +    else
  367.78 +    {
  367.79 +      RINOK(OpenStream());
  367.80 +    }
  367.81 +  }
  367.82 +  if (processedSize != 0)
  367.83 +    *processedSize = realProcessedSize;
  367.84 +  return S_OK;
  367.85 +}
  367.86 +
  367.87 +}}
   368.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   368.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarVolumeInStream.h	Sat Mar 03 10:31:27 2012 -0600
   368.3 @@ -0,0 +1,49 @@
   368.4 +// RarVolumeInStream.h
   368.5 +
   368.6 +#ifndef __RAR_VOLUME_IN_STREAM_H
   368.7 +#define __RAR_VOLUME_IN_STREAM_H
   368.8 +
   368.9 +#include "../../IStream.h"
  368.10 +#include "RarIn.h"
  368.11 +
  368.12 +namespace NArchive {
  368.13 +namespace NRar {
  368.14 +
  368.15 +struct CRefItem
  368.16 +{
  368.17 +  int VolumeIndex;
  368.18 +  int ItemIndex;
  368.19 +  int NumItems;
  368.20 +};
  368.21 +
  368.22 +class CFolderInStream:
  368.23 +  public ISequentialInStream,
  368.24 +  public CMyUnknownImp
  368.25 +{
  368.26 +public:
  368.27 +  MY_UNKNOWN_IMP
  368.28 +
  368.29 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
  368.30 +
  368.31 +private:
  368.32 +  CObjectVector<CInArchive> *_archives;
  368.33 +  const CObjectVector<CItemEx> *_items;
  368.34 +  CRefItem _refItem;
  368.35 +  int _curIndex;
  368.36 +  UInt32 _crc;
  368.37 +  bool _fileIsOpen;
  368.38 +  CMyComPtr<ISequentialInStream> _stream;
  368.39 +
  368.40 +  HRESULT OpenStream();
  368.41 +  HRESULT CloseStream();
  368.42 +public:
  368.43 +  void Init(CObjectVector<CInArchive> *archives,
  368.44 +      const CObjectVector<CItemEx> *items,
  368.45 +      const CRefItem &refItem);
  368.46 +
  368.47 +  CRecordVector<UInt32> CRCs;
  368.48 +};
  368.49 +  
  368.50 +}}
  368.51 +
  368.52 +#endif
   369.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   369.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Rar/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   369.3 @@ -0,0 +1,8 @@
   369.4 +// StdAfx.h
   369.5 +
   369.6 +#ifndef __STDAFX_H
   369.7 +#define __STDAFX_H
   369.8 +
   369.9 +#include "../../../Common/MyWindows.h"
  369.10 +
  369.11 +#endif
   370.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   370.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Split/SplitHandler.cpp	Sat Mar 03 10:31:27 2012 -0600
   370.3 @@ -0,0 +1,357 @@
   370.4 +// SplitHandler.cpp
   370.5 +
   370.6 +#include "StdAfx.h"
   370.7 +
   370.8 +#include "Common/ComTry.h"
   370.9 +#include "Common/Defs.h"
  370.10 +#include "Common/NewHandler.h"
  370.11 +#include "Common/StringConvert.h"
  370.12 +
  370.13 +#include "Windows/PropVariant.h"
  370.14 +#include "Windows/Time.h"
  370.15 +
  370.16 +#include "../../Common/ProgressUtils.h"
  370.17 +
  370.18 +#include "../../Compress/CopyCoder.h"
  370.19 +
  370.20 +#include "../Common/ItemNameUtils.h"
  370.21 +#include "../Common/MultiStream.h"
  370.22 +
  370.23 +#include "SplitHandler.h"
  370.24 +
  370.25 +using namespace NWindows;
  370.26 +using namespace NTime;
  370.27 +
  370.28 +namespace NArchive {
  370.29 +namespace NSplit {
  370.30 +
  370.31 +STATPROPSTG kProps[] =
  370.32 +{
  370.33 +  { NULL, kpidPath, VT_BSTR},
  370.34 +  { NULL, kpidSize, VT_UI8},
  370.35 +  { NULL, kpidPackSize, VT_UI8},
  370.36 +};
  370.37 +
  370.38 +IMP_IInArchive_Props
  370.39 +IMP_IInArchive_ArcProps_NO
  370.40 +
  370.41 +class CSeqName
  370.42 +{
  370.43 +public:
  370.44 +  UString _unchangedPart;
  370.45 +  UString _changedPart;
  370.46 +  bool _splitStyle;
  370.47 +  UString GetNextName()
  370.48 +  {
  370.49 +    UString newName;
  370.50 +    if (_splitStyle)
  370.51 +    {
  370.52 +      int i;
  370.53 +      int numLetters = _changedPart.Length();
  370.54 +      for (i = numLetters - 1; i >= 0; i--)
  370.55 +      {
  370.56 +        wchar_t c = _changedPart[i];
  370.57 +        if (c == 'z')
  370.58 +        {
  370.59 +          c = 'a';
  370.60 +          newName = c + newName;
  370.61 +          continue;
  370.62 +        }
  370.63 +        else if (c == 'Z')
  370.64 +        {
  370.65 +          c = 'A';
  370.66 +          newName = c + newName;
  370.67 +          continue;
  370.68 +        }
  370.69 +        c++;
  370.70 +        if ((c == 'z' || c == 'Z') && i == 0)
  370.71 +        {
  370.72 +          _unchangedPart += c;
  370.73 +          wchar_t newChar = (c == 'z') ? L'a' : L'A';
  370.74 +          newName.Empty();
  370.75 +          numLetters++;
  370.76 +          for (int k = 0; k < numLetters; k++)
  370.77 +            newName += newChar;
  370.78 +          break;
  370.79 +        }
  370.80 +        newName = c + newName;
  370.81 +        i--;
  370.82 +        for (; i >= 0; i--)
  370.83 +          newName = _changedPart[i] + newName;
  370.84 +        break;
  370.85 +      }
  370.86 +    }
  370.87 +    else
  370.88 +    {
  370.89 +      int i;
  370.90 +      int numLetters = _changedPart.Length();
  370.91 +      for (i = numLetters - 1; i >= 0; i--)
  370.92 +      {
  370.93 +        wchar_t c = _changedPart[i];
  370.94 +        if (c == L'9')
  370.95 +        {
  370.96 +          c = L'0';
  370.97 +          newName = c + newName;
  370.98 +          if (i == 0)
  370.99 +            newName = UString(L'1') + newName;
 370.100 +          continue;
 370.101 +        }
 370.102 +        c++;
 370.103 +        newName = c + newName;
 370.104 +        i--;
 370.105 +        for (; i >= 0; i--)
 370.106 +          newName = _changedPart[i] + newName;
 370.107 +        break;
 370.108 +      }
 370.109 +    }
 370.110 +    _changedPart = newName;
 370.111 +    return _unchangedPart + _changedPart;
 370.112 +  }
 370.113 +};
 370.114 +
 370.115 +STDMETHODIMP CHandler::Open(IInStream *stream,
 370.116 +    const UInt64 * /* maxCheckStartPosition */,
 370.117 +    IArchiveOpenCallback *openArchiveCallback)
 370.118 +{
 370.119 +  COM_TRY_BEGIN
 370.120 +  Close();
 370.121 +  if (openArchiveCallback == 0)
 370.122 +    return S_FALSE;
 370.123 +  // try
 370.124 +  {
 370.125 +    CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
 370.126 +    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackWrap = openArchiveCallback;
 370.127 +    if (openArchiveCallbackWrap.QueryInterface(IID_IArchiveOpenVolumeCallback,
 370.128 +        &openVolumeCallback) != S_OK)
 370.129 +      return S_FALSE;
 370.130 +    
 370.131 +    {
 370.132 +      NCOM::CPropVariant prop;
 370.133 +      RINOK(openVolumeCallback->GetProperty(kpidName, &prop));
 370.134 +      if (prop.vt != VT_BSTR)
 370.135 +        return S_FALSE;
 370.136 +      _name = prop.bstrVal;
 370.137 +    }
 370.138 +    
 370.139 +    int dotPos = _name.ReverseFind('.');
 370.140 +    UString prefix, ext;
 370.141 +    if (dotPos >= 0)
 370.142 +    {
 370.143 +      prefix = _name.Left(dotPos + 1);
 370.144 +      ext = _name.Mid(dotPos + 1);
 370.145 +    }
 370.146 +    else
 370.147 +      ext = _name;
 370.148 +    UString extBig = ext;
 370.149 +    extBig.MakeUpper();
 370.150 +
 370.151 +    CSeqName seqName;
 370.152 +
 370.153 +    int numLetters = 2;
 370.154 +    bool splitStyle = false;
 370.155 +    if (extBig.Right(2) == L"AA")
 370.156 +    {
 370.157 +      splitStyle = true;
 370.158 +      while (numLetters < extBig.Length())
 370.159 +      {
 370.160 +        if (extBig[extBig.Length() - numLetters - 1] != 'A')
 370.161 +          break;
 370.162 +        numLetters++;
 370.163 +      }
 370.164 +    }
 370.165 +    else if (ext.Right(2) == L"01")
 370.166 +    {
 370.167 +      while (numLetters < extBig.Length())
 370.168 +      {
 370.169 +        if (extBig[extBig.Length() - numLetters - 1] != '0')
 370.170 +          break;
 370.171 +        numLetters++;
 370.172 +      }
 370.173 +      if (numLetters != ext.Length())
 370.174 +        return S_FALSE;
 370.175 +    }
 370.176 +    else
 370.177 +      return S_FALSE;
 370.178 +
 370.179 +    _streams.Add(stream);
 370.180 +
 370.181 +    seqName._unchangedPart = prefix + ext.Left(extBig.Length() - numLetters);
 370.182 +    seqName._changedPart = ext.Right(numLetters);
 370.183 +    seqName._splitStyle = splitStyle;
 370.184 +
 370.185 +    if (prefix.Length() < 1)
 370.186 +      _subName = L"file";
 370.187 +    else
 370.188 +      _subName = prefix.Left(prefix.Length() - 1);
 370.189 +
 370.190 +    _totalSize = 0;
 370.191 +    UInt64 size;
 370.192 +    {
 370.193 +      NCOM::CPropVariant prop;
 370.194 +      RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));
 370.195 +      if (prop.vt != VT_UI8)
 370.196 +        return E_INVALIDARG;
 370.197 +      size = prop.uhVal.QuadPart;
 370.198 +    }
 370.199 +    _totalSize += size;
 370.200 +    _sizes.Add(size);
 370.201 +    
 370.202 +    if (openArchiveCallback != NULL)
 370.203 +    {
 370.204 +      UInt64 numFiles = _streams.Size();
 370.205 +      RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));
 370.206 +    }
 370.207 +
 370.208 +    for (;;)
 370.209 +    {
 370.210 +      UString fullName = seqName.GetNextName();
 370.211 +      CMyComPtr<IInStream> nextStream;
 370.212 +      HRESULT result = openVolumeCallback->GetStream(fullName, &nextStream);
 370.213 +      if (result == S_FALSE)
 370.214 +        break;
 370.215 +      if (result != S_OK)
 370.216 +        return result;
 370.217 +      if (!stream)
 370.218 +        break;
 370.219 +      {
 370.220 +        NCOM::CPropVariant prop;
 370.221 +        RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));
 370.222 +        if (prop.vt != VT_UI8)
 370.223 +          return E_INVALIDARG;
 370.224 +        size = prop.uhVal.QuadPart;
 370.225 +      }
 370.226 +      _totalSize += size;
 370.227 +      _sizes.Add(size);
 370.228 +      _streams.Add(nextStream);
 370.229 +      if (openArchiveCallback != NULL)
 370.230 +      {
 370.231 +        UInt64 numFiles = _streams.Size();
 370.232 +        RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));
 370.233 +      }
 370.234 +    }
 370.235 +  }
 370.236 +  /*
 370.237 +  catch(...)
 370.238 +  {
 370.239 +    return S_FALSE;
 370.240 +  }
 370.241 +  */
 370.242 +  return S_OK;
 370.243 +  COM_TRY_END
 370.244 +}
 370.245 +
 370.246 +STDMETHODIMP CHandler::Close()
 370.247 +{
 370.248 +  _sizes.Clear();
 370.249 +  _streams.Clear();
 370.250 +  return S_OK;
 370.251 +}
 370.252 +
 370.253 +STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
 370.254 +{
 370.255 +  *numItems = _streams.IsEmpty() ? 0 : 1;
 370.256 +  return S_OK;
 370.257 +}
 370.258 +
 370.259 +STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value)
 370.260 +{
 370.261 +  NWindows::NCOM::CPropVariant prop;
 370.262 +  switch(propID)
 370.263 +  {
 370.264 +    case kpidPath:
 370.265 +      prop = _subName;
 370.266 +      break;
 370.267 +    case kpidSize:
 370.268 +    case kpidPackSize:
 370.269 +      prop = _totalSize;
 370.270 +      break;
 370.271 +  }
 370.272 +  prop.Detach(value);
 370.273 +  return S_OK;
 370.274 +}
 370.275 +
 370.276 +STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
 370.277 +    Int32 _aTestMode, IArchiveExtractCallback *_anExtractCallback)
 370.278 +{
 370.279 +  COM_TRY_BEGIN
 370.280 +
 370.281 +  if (numItems != UInt32(-1))
 370.282 +  {
 370.283 +    if (numItems != 1)
 370.284 +      return E_INVALIDARG;
 370.285 +    if (indices[0] != 0)
 370.286 +      return E_INVALIDARG;
 370.287 +  }
 370.288 +  bool testMode = (_aTestMode != 0);
 370.289 +  CMyComPtr<IArchiveExtractCallback> extractCallback = _anExtractCallback;
 370.290 +  extractCallback->SetTotal(_totalSize);
 370.291 +  
 370.292 +  /*
 370.293 +  CMyComPtr<IArchiveVolumeExtractCallback> volumeExtractCallback;
 370.294 +  if (extractCallback.QueryInterface(&volumeExtractCallback) != S_OK)
 370.295 +    return E_FAIL;
 370.296 +  */
 370.297 +
 370.298 +  UInt64 currentTotalSize = 0;
 370.299 +  UInt64 currentItemSize;
 370.300 +
 370.301 +  RINOK(extractCallback->SetCompleted(&currentTotalSize));
 370.302 +  CMyComPtr<ISequentialOutStream> realOutStream;
 370.303 +  Int32 askMode;
 370.304 +  askMode = testMode ? NArchive::NExtract::NAskMode::kTest :
 370.305 +  NArchive::NExtract::NAskMode::kExtract;
 370.306 +  Int32 index = 0;
 370.307 +  RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
 370.308 +  
 370.309 +  RINOK(extractCallback->PrepareOperation(askMode));
 370.310 +  if (testMode)
 370.311 +  {
 370.312 +    RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));
 370.313 +    return S_OK;
 370.314 +  }
 370.315 +  
 370.316 +  if (!testMode && (!realOutStream))
 370.317 +    return S_OK;
 370.318 +
 370.319 +  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;
 370.320 +  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
 370.321 +
 370.322 +  CLocalProgress *lps = new CLocalProgress;
 370.323 +  CMyComPtr<ICompressProgressInfo> progress = lps;
 370.324 +  lps->Init(extractCallback, false);
 370.325 +
 370.326 +  for (int i = 0; i < _streams.Size(); i++, currentTotalSize += currentItemSize)
 370.327 +  {
 370.328 +    lps->InSize = lps->OutSize = currentTotalSize;
 370.329 +    RINOK(lps->SetCur());
 370.330 +    IInStream *inStream = _streams[i];
 370.331 +    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));
 370.332 +    RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
 370.333 +    currentItemSize = copyCoderSpec->TotalSize;
 370.334 +  }
 370.335 +  realOutStream.Release();
 370.336 +  return extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK);
 370.337 +  COM_TRY_END
 370.338 +}
 370.339 +
 370.340 +STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
 370.341 +{
 370.342 +  if (index != 0)
 370.343 +    return E_INVALIDARG;
 370.344 +  *stream = 0;
 370.345 +  CMultiStream *streamSpec = new CMultiStream;
 370.346 +  CMyComPtr<ISequentialInStream> streamTemp = streamSpec;
 370.347 +  for (int i = 0; i < _streams.Size(); i++)
 370.348 +  {
 370.349 +    CMultiStream::CSubStreamInfo subStreamInfo;
 370.350 +    subStreamInfo.Stream = _streams[i];
 370.351 +    subStreamInfo.Pos = 0;
 370.352 +    subStreamInfo.Size = _sizes[i];
 370.353 +    streamSpec->Streams.Add(subStreamInfo);
 370.354 +  }
 370.355 +  streamSpec->Init();
 370.356 +  *stream = streamTemp.Detach();
 370.357 +  return S_OK;
 370.358 +}
 370.359 +
 370.360 +}}
   371.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   371.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Split/SplitHandler.h	Sat Mar 03 10:31:27 2012 -0600
   371.3 @@ -0,0 +1,37 @@
   371.4 +// Split/Handler.h
   371.5 +
   371.6 +#ifndef __SPLIT_HANDLER_H
   371.7 +#define __SPLIT_HANDLER_H
   371.8 +
   371.9 +#include "Common/MyCom.h"
  371.10 +#include "Common/MyString.h"
  371.11 +#include "../IArchive.h"
  371.12 +
  371.13 +namespace NArchive {
  371.14 +namespace NSplit {
  371.15 +
  371.16 +class CHandler:
  371.17 +  public IInArchive,
  371.18 +  public IInArchiveGetStream,
  371.19 +  // public IOutArchive,
  371.20 +  public CMyUnknownImp
  371.21 +{
  371.22 +public:
  371.23 +  MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
  371.24 +
  371.25 +  INTERFACE_IInArchive(;)
  371.26 +
  371.27 +  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
  371.28 +
  371.29 +private:
  371.30 +  UString _subName;
  371.31 +  UString _name;
  371.32 +  CObjectVector<CMyComPtr<IInStream> > _streams;
  371.33 +  CRecordVector<UInt64> _sizes;
  371.34 +
  371.35 +  UInt64 _totalSize;
  371.36 +};
  371.37 +
  371.38 +}}
  371.39 +
  371.40 +#endif
   372.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   372.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Split/SplitRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   372.3 @@ -0,0 +1,20 @@
   372.4 +// SplitRegister.cpp
   372.5 +
   372.6 +#include "StdAfx.h"
   372.7 +
   372.8 +#include "../../Common/RegisterArc.h"
   372.9 +
  372.10 +#include "SplitHandler.h"
  372.11 +static IInArchive *CreateArc() { return new NArchive::NSplit::CHandler;  }
  372.12 +/*
  372.13 +#ifndef EXTRACT_ONLY
  372.14 +static IOutArchive *CreateArcOut() { return new NArchive::NSplit::CHandler;  }
  372.15 +#else
  372.16 +#define CreateArcOut 0
  372.17 +#endif
  372.18 +*/
  372.19 +
  372.20 +static CArcInfo g_ArcInfo =
  372.21 +{ L"Split", L"001", 0, 0xEA, { 0 }, 0, false, CreateArc, 0 };
  372.22 +
  372.23 +REGISTER_ARC(Split)
   373.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   373.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Split/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   373.3 @@ -0,0 +1,8 @@
   373.4 +// StdAfx.h
   373.5 +
   373.6 +#ifndef __STDAFX_H
   373.7 +#define __STDAFX_H
   373.8 +
   373.9 +#include "../../../Common/MyWindows.h"
  373.10 +
  373.11 +#endif
   374.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   374.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   374.3 @@ -0,0 +1,9 @@
   374.4 +// StdAfx.h
   374.5 +
   374.6 +#ifndef __STDAFX_H
   374.7 +#define __STDAFX_H
   374.8 +
   374.9 +#include "../../Common/MyWindows.h"
  374.10 +#include "../../Common/NewHandler.h"
  374.11 +
  374.12 +#endif
   375.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   375.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Tar/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   375.3 @@ -0,0 +1,9 @@
   375.4 +// StdAfx.h
   375.5 +
   375.6 +#ifndef __STDAFX_H
   375.7 +#define __STDAFX_H
   375.8 +
   375.9 +#include "../../../Common/MyWindows.h"
  375.10 +#include "../../../Common/NewHandler.h"
  375.11 +
  375.12 +#endif
   376.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   376.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarHandler.cpp	Sat Mar 03 10:31:27 2012 -0600
   376.3 @@ -0,0 +1,229 @@
   376.4 +// TarHandler.cpp
   376.5 +
   376.6 +#include "StdAfx.h"
   376.7 +
   376.8 +#include "Common/ComTry.h"
   376.9 +#include "Common/Defs.h"
  376.10 +#include "Common/NewHandler.h"
  376.11 +#include "Common/StringConvert.h"
  376.12 +
  376.13 +#include "Windows/PropVariant.h"
  376.14 +#include "Windows/Time.h"
  376.15 +
  376.16 +#include "../../Common/LimitedStreams.h"
  376.17 +#include "../../Common/ProgressUtils.h"
  376.18 +
  376.19 +#include "../../Compress/CopyCoder.h"
  376.20 +
  376.21 +#include "../Common/DummyOutStream.h"
  376.22 +#include "../Common/ItemNameUtils.h"
  376.23 +
  376.24 +#include "TarHandler.h"
  376.25 +#include "TarIn.h"
  376.26 +
  376.27 +using namespace NWindows;
  376.28 +
  376.29 +namespace NArchive {
  376.30 +namespace NTar {
  376.31 +
  376.32 +STATPROPSTG kProps[] =
  376.33 +{
  376.34 +  { NULL, kpidPath, VT_BSTR},
  376.35 +  { NULL, kpidIsDir, VT_BOOL},
  376.36 +  { NULL, kpidSize, VT_UI8},
  376.37 +  { NULL, kpidPackSize, VT_UI8},
  376.38 +  { NULL, kpidMTime, VT_FILETIME},
  376.39 +  { NULL, kpidUser, VT_BSTR},
  376.40 +  { NULL, kpidGroup, VT_BSTR}
  376.41 +};
  376.42 +
  376.43 +IMP_IInArchive_Props
  376.44 +IMP_IInArchive_ArcProps_NO
  376.45 +
  376.46 +HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
  376.47 +{
  376.48 +  UInt64 endPos = 0;
  376.49 +  if (callback != NULL)
  376.50 +  {
  376.51 +    RINOK(stream->Seek(0, STREAM_SEEK_END, &endPos));
  376.52 +    RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
  376.53 +  }
  376.54 +  
  376.55 +  UInt64 pos = 0;
  376.56 +  for (;;)
  376.57 +  {
  376.58 +    CItemEx item;
  376.59 +    bool filled;
  376.60 +    item.HeaderPosition = pos;
  376.61 +    RINOK(ReadItem(stream, filled, item));
  376.62 +    if (!filled)
  376.63 +      break;
  376.64 +    _items.Add(item);
  376.65 +    
  376.66 +    RINOK(stream->Seek(item.GetPackSize(), STREAM_SEEK_CUR, &pos));
  376.67 +    if (pos >= endPos)
  376.68 +      return S_FALSE;
  376.69 +    if (callback != NULL)
  376.70 +    {
  376.71 +      if (_items.Size() == 1)
  376.72 +      {
  376.73 +        RINOK(callback->SetTotal(NULL, &endPos));
  376.74 +      }
  376.75 +      if (_items.Size() % 100 == 0)
  376.76 +      {
  376.77 +        UInt64 numFiles = _items.Size();
  376.78 +        RINOK(callback->SetCompleted(&numFiles, &pos));
  376.79 +      }
  376.80 +    }
  376.81 +  }
  376.82 +
  376.83 +  if (_items.Size() == 0)
  376.84 +  {
  376.85 +    CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
  376.86 +    if (!callback)
  376.87 +      return S_FALSE;
  376.88 +    callback->QueryInterface(IID_IArchiveOpenVolumeCallback, (void **)&openVolumeCallback);
  376.89 +    if (!openVolumeCallback)
  376.90 +      return S_FALSE;
  376.91 +    NCOM::CPropVariant prop;
  376.92 +    if (openVolumeCallback->GetProperty(kpidName, &prop) != S_OK)
  376.93 +      return S_FALSE;
  376.94 +    if (prop.vt != VT_BSTR)
  376.95 +      return S_FALSE;
  376.96 +    UString baseName = prop.bstrVal;
  376.97 +    baseName = baseName.Right(4);
  376.98 +    if (baseName.CompareNoCase(L".tar") != 0)
  376.99 +      return S_FALSE;
 376.100 +  }
 376.101 +  return S_OK;
 376.102 +}
 376.103 +
 376.104 +STDMETHODIMP CHandler::Open(IInStream *stream,
 376.105 +    const UInt64 * /* maxCheckStartPosition */,
 376.106 +    IArchiveOpenCallback *openArchiveCallback)
 376.107 +{
 376.108 +  COM_TRY_BEGIN
 376.109 +  {
 376.110 +    Close();
 376.111 +    RINOK(Open2(stream, openArchiveCallback));
 376.112 +    _inStream = stream;
 376.113 +  }
 376.114 +  return S_OK;
 376.115 +  COM_TRY_END
 376.116 +}
 376.117 +
 376.118 +STDMETHODIMP CHandler::Close()
 376.119 +{
 376.120 +  _items.Clear();
 376.121 +  _inStream.Release();
 376.122 +  return S_OK;
 376.123 +}
 376.124 +
 376.125 +STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
 376.126 +{
 376.127 +  *numItems = _items.Size();
 376.128 +  return S_OK;
 376.129 +}
 376.130 +
 376.131 +STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
 376.132 +{
 376.133 +  COM_TRY_BEGIN
 376.134 +  NWindows::NCOM::CPropVariant prop;
 376.135 +  const CItemEx &item = _items[index];
 376.136 +
 376.137 +  switch(propID)
 376.138 +  {
 376.139 +    case kpidPath:  prop = NItemName::GetOSName2(MultiByteToUnicodeString(item.Name, CP_OEMCP)); break;
 376.140 +    case kpidIsDir:  prop = item.IsDir(); break;
 376.141 +    case kpidSize:  prop = item.Size; break;
 376.142 +    case kpidPackSize:  prop = item.GetPackSize(); break;
 376.143 +    case kpidMTime:
 376.144 +      if (item.MTime != 0)
 376.145 +      {
 376.146 +        FILETIME ft;
 376.147 +        NTime::UnixTimeToFileTime(item.MTime, ft);
 376.148 +        prop = ft;
 376.149 +      }
 376.150 +      break;
 376.151 +    case kpidUser:  prop = MultiByteToUnicodeString(item.UserName, CP_OEMCP); break;
 376.152 +    case kpidGroup:  prop = MultiByteToUnicodeString(item.GroupName, CP_OEMCP); break;
 376.153 +  }
 376.154 +  prop.Detach(value);
 376.155 +  return S_OK;
 376.156 +  COM_TRY_END
 376.157 +}
 376.158 +
 376.159 +STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
 376.160 +    Int32 _aTestMode, IArchiveExtractCallback *extractCallback)
 376.161 +{
 376.162 +  COM_TRY_BEGIN
 376.163 +  bool testMode = (_aTestMode != 0);
 376.164 +  bool allFilesMode = (numItems == UInt32(-1));
 376.165 +  if (allFilesMode)
 376.166 +    numItems = _items.Size();
 376.167 +  if (numItems == 0)
 376.168 +    return S_OK;
 376.169 +  UInt64 totalSize = 0;
 376.170 +  UInt32 i;
 376.171 +  for (i = 0; i < numItems; i++)
 376.172 +    totalSize += _items[allFilesMode ? i : indices[i]].Size;
 376.173 +  extractCallback->SetTotal(totalSize);
 376.174 +
 376.175 +  UInt64 totalPackSize, curPackSize, curSize;
 376.176 +  totalSize = totalPackSize = 0;
 376.177 +  
 376.178 +  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
 376.179 +  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
 376.180 +
 376.181 +  CLocalProgress *lps = new CLocalProgress;
 376.182 +  CMyComPtr<ICompressProgressInfo> progress = lps;
 376.183 +  lps->Init(extractCallback, false);
 376.184 +
 376.185 +  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
 376.186 +  CMyComPtr<ISequentialInStream> inStream(streamSpec);
 376.187 +  streamSpec->SetStream(_inStream);
 376.188 +
 376.189 +  CDummyOutStream *outStreamSpec = new CDummyOutStream;
 376.190 +  CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
 376.191 +
 376.192 +  for (i = 0; i < numItems; i++, totalSize += curSize, totalPackSize += curPackSize)
 376.193 +  {
 376.194 +    lps->InSize = totalPackSize;
 376.195 +    lps->OutSize = totalSize;
 376.196 +    RINOK(lps->SetCur());
 376.197 +    CMyComPtr<ISequentialOutStream> realOutStream;
 376.198 +    Int32 askMode = testMode ?
 376.199 +        NArchive::NExtract::NAskMode::kTest :
 376.200 +        NArchive::NExtract::NAskMode::kExtract;
 376.201 +    Int32 index = allFilesMode ? i : indices[i];
 376.202 +    const CItemEx &item = _items[index];
 376.203 +    RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
 376.204 +    curSize = item.Size;
 376.205 +    curPackSize = item.GetPackSize();
 376.206 +    if (item.IsDir())
 376.207 +    {
 376.208 +      RINOK(extractCallback->PrepareOperation(askMode));
 376.209 +      RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));
 376.210 +      continue;
 376.211 +    }
 376.212 +    if (!testMode && (!realOutStream))
 376.213 +      continue;
 376.214 +    RINOK(extractCallback->PrepareOperation(askMode));
 376.215 +
 376.216 +    outStreamSpec->SetStream(realOutStream);
 376.217 +    realOutStream.Release();
 376.218 +    outStreamSpec->Init();
 376.219 +
 376.220 +    RINOK(_inStream->Seek(item.GetDataPosition(), STREAM_SEEK_SET, NULL));
 376.221 +    streamSpec->Init(item.Size);
 376.222 +    RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
 376.223 +    outStreamSpec->ReleaseStream();
 376.224 +    RINOK(extractCallback->SetOperationResult(copyCoderSpec->TotalSize == item.Size ?
 376.225 +        NArchive::NExtract::NOperationResult::kOK:
 376.226 +        NArchive::NExtract::NOperationResult::kDataError));
 376.227 +  }
 376.228 +  return S_OK;
 376.229 +  COM_TRY_END
 376.230 +}
 376.231 +
 376.232 +}}
   377.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   377.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarHandler.h	Sat Mar 03 10:31:27 2012 -0600
   377.3 @@ -0,0 +1,37 @@
   377.4 +// Tar/Handler.h
   377.5 +
   377.6 +#ifndef __TAR_HANDLER_H
   377.7 +#define __TAR_HANDLER_H
   377.8 +
   377.9 +#include "Common/MyCom.h"
  377.10 +#include "../IArchive.h"
  377.11 +
  377.12 +#include "TarItem.h"
  377.13 +
  377.14 +namespace NArchive {
  377.15 +namespace NTar {
  377.16 +
  377.17 +class CHandler:
  377.18 +  public IInArchive,
  377.19 +  public IOutArchive,
  377.20 +  public CMyUnknownImp
  377.21 +{
  377.22 +public:
  377.23 +  MY_UNKNOWN_IMP2(
  377.24 +    IInArchive,
  377.25 +    IOutArchive
  377.26 +  )
  377.27 +
  377.28 +  INTERFACE_IInArchive(;)
  377.29 +  INTERFACE_IOutArchive(;)
  377.30 +
  377.31 +  HRESULT Open2(IInStream *stream, IArchiveOpenCallback *callback);
  377.32 +
  377.33 +private:
  377.34 +  CObjectVector<CItemEx> _items;
  377.35 +  CMyComPtr<IInStream> _inStream;
  377.36 +};
  377.37 +
  377.38 +}}
  377.39 +
  377.40 +#endif
   378.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   378.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarHeader.cpp	Sat Mar 03 10:31:27 2012 -0600
   378.3 @@ -0,0 +1,25 @@
   378.4 +// Archive/Tar/Header.h
   378.5 +
   378.6 +#include "StdAfx.h"
   378.7 +
   378.8 +#include "TarHeader.h"
   378.9 +
  378.10 +namespace NArchive {
  378.11 +namespace NTar {
  378.12 +namespace NFileHeader {
  378.13 +
  378.14 +  // The checksum field is filled with this while the checksum is computed.
  378.15 +  const char *kCheckSumBlanks = "        ";   // 8 blanks, no null
  378.16 +
  378.17 +  const char *kLongLink = "././@LongLink";
  378.18 +  const char *kLongLink2 = "@LongLink";
  378.19 +
  378.20 +  // The magic field is filled with this if uname and gname are valid.
  378.21 +  namespace NMagic
  378.22 +  {
  378.23 +    const char *kUsTar  = "ustar"; // 5 chars
  378.24 +    const char *kGNUTar = "GNUtar "; // 7 chars and a null
  378.25 +    const char *kEmpty = "\0\0\0\0\0\0\0\0"; // 7 chars and a null
  378.26 +  }
  378.27 +
  378.28 +}}}
   379.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   379.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarHeader.h	Sat Mar 03 10:31:27 2012 -0600
   379.3 @@ -0,0 +1,108 @@
   379.4 +// Archive/Tar/Header.h
   379.5 +
   379.6 +#ifndef __ARCHIVE_TAR_HEADER_H
   379.7 +#define __ARCHIVE_TAR_HEADER_H
   379.8 +
   379.9 +#include "Common/Types.h"
  379.10 +
  379.11 +namespace NArchive {
  379.12 +namespace NTar {
  379.13 +
  379.14 +namespace NFileHeader
  379.15 +{
  379.16 +  const int kRecordSize = 512;
  379.17 +  const int kNameSize = 100;
  379.18 +  const int kUserNameSize = 32;
  379.19 +  const int kGroupNameSize = 32;
  379.20 +  const int kPrefixSize = 155;
  379.21 +
  379.22 +  /*
  379.23 +  struct CHeader
  379.24 +  {
  379.25 +    char Name[kNameSize];
  379.26 +    char Mode[8];
  379.27 +    char UID[8];
  379.28 +    char GID[8];
  379.29 +    char Size[12];
  379.30 +    char ModificationTime[12];
  379.31 +    char CheckSum[8];
  379.32 +    char LinkFlag;
  379.33 +    char LinkName[kNameSize];
  379.34 +    char Magic[8];
  379.35 +    char UserName[kUserNameSize];
  379.36 +    char GroupName[kGroupNameSize];
  379.37 +    char DeviceMajor[8];
  379.38 +    char DeviceMinor[8];
  379.39 +    char Prefix[155];
  379.40 +  };
  379.41 +  union CRecord
  379.42 +  {
  379.43 +    CHeader Header;
  379.44 +    Byte Padding[kRecordSize];
  379.45 +  };
  379.46 +  */
  379.47 +
  379.48 +  namespace NMode
  379.49 +  {
  379.50 +    const int kSetUID   = 04000;  // Set UID on execution
  379.51 +    const int kSetGID   = 02000;  // Set GID on execution
  379.52 +    const int kSaveText = 01000;  // Save text (sticky bit)
  379.53 +  }
  379.54 +
  379.55 +  namespace NFilePermissions
  379.56 +  {
  379.57 +    const int kUserRead     = 00400;  // read by owner
  379.58 +    const int kUserWrite    = 00200;  // write by owner
  379.59 +    const int kUserExecute  = 00100;  // execute/search by owner
  379.60 +    const int kGroupRead    = 00040;  // read by group
  379.61 +    const int kGroupWrite   = 00020;  // write by group
  379.62 +    const int kGroupExecute = 00010;  // execute/search by group
  379.63 +    const int kOtherRead    = 00004;  // read by other
  379.64 +    const int kOtherWrite   = 00002;  // write by other
  379.65 +    const int kOtherExecute = 00001;  // execute/search by other
  379.66 +  }
  379.67 +
  379.68 +
  379.69 +  // The linkflag defines the type of file
  379.70 +  namespace NLinkFlag
  379.71 +  {
  379.72 +    const char kOldNormal    = '\0'; // Normal disk file, Unix compatible
  379.73 +    const char kNormal       = '0'; // Normal disk file
  379.74 +    const char kLink         = '1'; // Link to previously dumped file
  379.75 +    const char kSymbolicLink = '2'; // Symbolic link
  379.76 +    const char kCharacter    = '3'; // Character special file
  379.77 +    const char kBlock        = '4'; // Block special file
  379.78 +    const char kDirectory    = '5'; // Directory
  379.79 +    const char kFIFO         = '6'; // FIFO special file
  379.80 +    const char kContiguous   = '7'; // Contiguous file
  379.81 +
  379.82 +    const char kDumpDir       = 'D'; /* GNUTYPE_DUMPDIR.
  379.83 +      data: list of files created by the --incremental (-G) option
  379.84 +      Each file name is preceded by either
  379.85 +        - 'Y' (file should be in this archive)
  379.86 +        - 'N' (file is a directory, or is not stored in the archive.)
  379.87 +        Each file name is terminated by a null + an additional null after
  379.88 +        the last file name. */
  379.89 +
  379.90 +  }
  379.91 +  // Further link types may be defined later.
  379.92 +
  379.93 +  // The checksum field is filled with this while the checksum is computed.
  379.94 +  extern const char *kCheckSumBlanks;//   = "        ";   // 8 blanks, no null
  379.95 +
  379.96 +  extern const char *kLongLink;  //   = "././@LongLink";
  379.97 +  extern const char *kLongLink2; //   = "@LongLink";
  379.98 +
  379.99 +  // The magic field is filled with this if uname and gname are valid.
 379.100 +  namespace NMagic
 379.101 +  {
 379.102 +    extern const char *kUsTar; //   = "ustar"; // 5 chars
 379.103 +    extern const char *kGNUTar; //  = "GNUtar "; // 7 chars and a null
 379.104 +    extern const char *kEmpty; //  = "GNUtar "; // 7 chars and a null
 379.105 +  }
 379.106 +
 379.107 +}
 379.108 +
 379.109 +}}
 379.110 +
 379.111 +#endif
   380.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   380.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarIn.cpp	Sat Mar 03 10:31:27 2012 -0600
   380.3 @@ -0,0 +1,176 @@
   380.4 +// Archive/TarIn.cpp
   380.5 +
   380.6 +#include "StdAfx.h"
   380.7 +
   380.8 +#include "TarIn.h"
   380.9 +#include "TarHeader.h"
  380.10 +
  380.11 +#include "Common/StringToInt.h"
  380.12 +#include "Windows/Defs.h"
  380.13 +
  380.14 +#include "../../Common/StreamUtils.h"
  380.15 +
  380.16 +namespace NArchive {
  380.17 +namespace NTar {
  380.18 + 
  380.19 +static void MyStrNCpy(char *dest, const char *src, int size)
  380.20 +{
  380.21 +  for (int i = 0; i < size; i++)
  380.22 +  {
  380.23 +    char c = src[i];
  380.24 +    dest[i] = c;
  380.25 +    if (c == 0)
  380.26 +      break;
  380.27 +  }
  380.28 +}
  380.29 +
  380.30 +static bool OctalToNumber(const char *srcString, int size, UInt64 &res)
  380.31 +{
  380.32 +  char sz[32];
  380.33 +  MyStrNCpy(sz, srcString, size);
  380.34 +  sz[size] = 0;
  380.35 +  const char *end;
  380.36 +  int i;
  380.37 +  for (i = 0; sz[i] == ' '; i++);
  380.38 +  res = ConvertOctStringToUInt64(sz + i, &end);
  380.39 +  return (*end == ' ' || *end == 0);
  380.40 +}
  380.41 +
  380.42 +static bool OctalToNumber32(const char *srcString, int size, UInt32 &res)
  380.43 +{
  380.44 +  UInt64 res64;
  380.45 +  if (!OctalToNumber(srcString, size, res64))
  380.46 +    return false;
  380.47 +  res = (UInt32)res64;
  380.48 +  return (res64 <= 0xFFFFFFFF);
  380.49 +}
  380.50 +
  380.51 +#define RIF(x) { if (!(x)) return S_FALSE; }
  380.52 +
  380.53 +static bool IsRecordLast(const char *buf)
  380.54 +{
  380.55 +  for (int i = 0; i < NFileHeader::kRecordSize; i++)
  380.56 +    if (buf[i] != 0)
  380.57 +      return false;
  380.58 +  return true;
  380.59 +}
  380.60 +
  380.61 +static void ReadString(const char *s, int size, AString &result)
  380.62 +{
  380.63 +  char temp[NFileHeader::kRecordSize + 1];
  380.64 +  MyStrNCpy(temp, s, size);
  380.65 +  temp[size] = '\0';
  380.66 +  result = temp;
  380.67 +}
  380.68 +
  380.69 +static HRESULT GetNextItemReal(ISequentialInStream *stream, bool &filled, CItemEx &item, size_t &processedSize)
  380.70 +{
  380.71 +  item.LongLinkSize = 0;
  380.72 +  char buf[NFileHeader::kRecordSize];
  380.73 +  char *p = buf;
  380.74 +
  380.75 +  filled = false;
  380.76 +
  380.77 +  processedSize = NFileHeader::kRecordSize;
  380.78 +  RINOK(ReadStream(stream, buf, &processedSize));
  380.79 +  if (processedSize == 0 || (processedSize == NFileHeader::kRecordSize && IsRecordLast(buf)))
  380.80 +    return S_OK;
  380.81 +  if (processedSize < NFileHeader::kRecordSize)
  380.82 +    return S_FALSE;
  380.83 +  
  380.84 +  ReadString(p, NFileHeader::kNameSize, item.Name); p += NFileHeader::kNameSize;
  380.85 +
  380.86 +  RIF(OctalToNumber32(p, 8, item.Mode)); p += 8;
  380.87 +
  380.88 +  if (!OctalToNumber32(p, 8, item.UID)) item.UID = 0; p += 8;
  380.89 +  if (!OctalToNumber32(p, 8, item.GID)) item.GID = 0; p += 8;
  380.90 +
  380.91 +  RIF(OctalToNumber(p, 12, item.Size)); p += 12;
  380.92 +  RIF(OctalToNumber32(p, 12, item.MTime)); p += 12;
  380.93 +  
  380.94 +  UInt32 checkSum;
  380.95 +  RIF(OctalToNumber32(p, 8, checkSum));
  380.96 +  memcpy(p, NFileHeader::kCheckSumBlanks, 8); p += 8;
  380.97 +
  380.98 +  item.LinkFlag = *p++;
  380.99 +
 380.100 +  ReadString(p, NFileHeader::kNameSize, item.LinkName); p += NFileHeader::kNameSize;
 380.101 +
 380.102 +  memcpy(item.Magic, p, 8); p += 8;
 380.103 +
 380.104 +  ReadString(p, NFileHeader::kUserNameSize, item.UserName);  p += NFileHeader::kUserNameSize;
 380.105 +  ReadString(p, NFileHeader::kUserNameSize, item.GroupName); p += NFileHeader::kUserNameSize;
 380.106 +
 380.107 +  item.DeviceMajorDefined = (p[0] != 0); RIF(OctalToNumber32(p, 8, item.DeviceMajor)); p += 8;
 380.108 +  item.DeviceMinorDefined = (p[0] != 0); RIF(OctalToNumber32(p, 8, item.DeviceMinor)); p += 8;
 380.109 +
 380.110 +  AString prefix;
 380.111 +  ReadString(p, NFileHeader::kPrefixSize, prefix);
 380.112 +  p += NFileHeader::kPrefixSize;
 380.113 +  if (!prefix.IsEmpty() && item.IsMagic() &&
 380.114 +      (item.LinkFlag != 'L' /* || prefix != "00000000000" */ ))
 380.115 +    item.Name = prefix + AString('/') + item.Name;
 380.116 +
 380.117 +  if (item.LinkFlag == NFileHeader::NLinkFlag::kLink)
 380.118 +    item.Size = 0;
 380.119 + 
 380.120 +  UInt32 checkSumReal = 0;
 380.121 +  for (int i = 0; i < NFileHeader::kRecordSize; i++)
 380.122 +    checkSumReal += (Byte)buf[i];
 380.123 +  
 380.124 +  if (checkSumReal != checkSum)
 380.125 +    return S_FALSE;
 380.126 +
 380.127 +  filled = true;
 380.128 +  return S_OK;
 380.129 +}
 380.130 +
 380.131 +HRESULT ReadItem(ISequentialInStream *stream, bool &filled, CItemEx &item)
 380.132 +{
 380.133 +  size_t processedSize;
 380.134 +  RINOK(GetNextItemReal(stream, filled, item, processedSize));
 380.135 +  if (!filled)
 380.136 +    return S_OK;
 380.137 +  // GNUtar extension
 380.138 +  if (item.LinkFlag == 'L')
 380.139 +  {
 380.140 +    if (item.Name.Compare(NFileHeader::kLongLink) != 0)
 380.141 +      if (item.Name.Compare(NFileHeader::kLongLink2) != 0)
 380.142 +        return S_FALSE;
 380.143 +
 380.144 +    AString fullName;
 380.145 +    if (item.Size > (1 << 15))
 380.146 +      return S_FALSE;
 380.147 +    int packSize = (int)item.GetPackSize();
 380.148 +    char *buffer = fullName.GetBuffer(packSize + 1);
 380.149 +
 380.150 +    RINOK(ReadStream_FALSE(stream, buffer, packSize));
 380.151 +    processedSize += packSize;
 380.152 +    buffer[item.Size] = '\0';
 380.153 +    fullName.ReleaseBuffer();
 380.154 +
 380.155 +    UInt64 headerPosition = item.HeaderPosition;
 380.156 +    {
 380.157 +      size_t processedSize2;
 380.158 +      RINOK(GetNextItemReal(stream, filled, item, processedSize2));
 380.159 +    }
 380.160 +    item.LongLinkSize = (unsigned)processedSize;
 380.161 +    item.Name = fullName;
 380.162 +    item.HeaderPosition = headerPosition;
 380.163 +  }
 380.164 +  else if (item.LinkFlag == 'g' || item.LinkFlag == 'x' || item.LinkFlag == 'X')
 380.165 +  {
 380.166 +    // pax Extended Header
 380.167 +    return S_OK;
 380.168 +  }
 380.169 +  else if (item.LinkFlag == NFileHeader::NLinkFlag::kDumpDir)
 380.170 +  {
 380.171 +    // GNU Extensions to the Archive Format
 380.172 +    return S_OK;
 380.173 +  }
 380.174 +  else if (item.LinkFlag > '7' || (item.LinkFlag < '0' && item.LinkFlag != 0))
 380.175 +    return S_FALSE;
 380.176 +  return S_OK;
 380.177 +}
 380.178 +
 380.179 +}}
   381.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   381.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarIn.h	Sat Mar 03 10:31:27 2012 -0600
   381.3 @@ -0,0 +1,18 @@
   381.4 +// Archive/TarIn.h
   381.5 +
   381.6 +#ifndef __ARCHIVE_TAR_IN_H
   381.7 +#define __ARCHIVE_TAR_IN_H
   381.8 +
   381.9 +#include "Common/MyCom.h"
  381.10 +#include "../../IStream.h"
  381.11 +
  381.12 +#include "TarItem.h"
  381.13 +
  381.14 +namespace NArchive {
  381.15 +namespace NTar {
  381.16 +  
  381.17 +HRESULT ReadItem(ISequentialInStream *stream, bool &filled, CItemEx &itemInfo);
  381.18 +
  381.19 +}}
  381.20 +  
  381.21 +#endif
   382.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   382.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarItem.h	Sat Mar 03 10:31:27 2012 -0600
   382.3 @@ -0,0 +1,71 @@
   382.4 +// Archive/Tar/Item.h
   382.5 +
   382.6 +#ifndef __ARCHIVE_TAR_ITEM_H
   382.7 +#define __ARCHIVE_TAR_ITEM_H
   382.8 +
   382.9 +#include "Common/Types.h"
  382.10 +#include "Common/MyString.h"
  382.11 +
  382.12 +#include "../Common/ItemNameUtils.h"
  382.13 +#include "TarHeader.h"
  382.14 +
  382.15 +namespace NArchive {
  382.16 +namespace NTar {
  382.17 +
  382.18 +struct CItem
  382.19 +{
  382.20 +  AString Name;
  382.21 +  UInt64 Size;
  382.22 +
  382.23 +  UInt32 Mode;
  382.24 +  UInt32 UID;
  382.25 +  UInt32 GID;
  382.26 +  UInt32 MTime;
  382.27 +  UInt32 DeviceMajor;
  382.28 +  UInt32 DeviceMinor;
  382.29 +
  382.30 +  AString LinkName;
  382.31 +  AString UserName;
  382.32 +  AString GroupName;
  382.33 +
  382.34 +  char Magic[8];
  382.35 +  char LinkFlag;
  382.36 +  bool DeviceMajorDefined;
  382.37 +  bool DeviceMinorDefined;
  382.38 +
  382.39 +  bool IsDir() const
  382.40 +  {
  382.41 +    switch(LinkFlag)
  382.42 +    {
  382.43 +      case NFileHeader::NLinkFlag::kDirectory:
  382.44 +      case NFileHeader::NLinkFlag::kDumpDir:
  382.45 +        return true;
  382.46 +      case NFileHeader::NLinkFlag::kOldNormal:
  382.47 +      case NFileHeader::NLinkFlag::kNormal:
  382.48 +        return NItemName::HasTailSlash(Name, CP_OEMCP);
  382.49 +    }
  382.50 +    return false;
  382.51 +  }
  382.52 +
  382.53 +  bool IsMagic() const
  382.54 +  {
  382.55 +    for (int i = 0; i < 5; i++)
  382.56 +      if (Magic[i] != NFileHeader::NMagic::kUsTar[i])
  382.57 +        return false;
  382.58 +    return true;
  382.59 +  }
  382.60 +
  382.61 +  UInt64 GetPackSize() const { return (Size + 0x1FF) & (~((UInt64)0x1FF)); }
  382.62 +};
  382.63 +
  382.64 +struct CItemEx: public CItem
  382.65 +{
  382.66 +  UInt64 HeaderPosition;
  382.67 +  unsigned LongLinkSize;
  382.68 +  UInt64 GetDataPosition() const { return HeaderPosition + LongLinkSize + NFileHeader::kRecordSize; }
  382.69 +  UInt64 GetFullSize() const { return LongLinkSize + NFileHeader::kRecordSize + Size; }
  382.70 +};
  382.71 +
  382.72 +}}
  382.73 +
  382.74 +#endif
   383.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   383.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Tar/TarRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   383.3 @@ -0,0 +1,18 @@
   383.4 +// TarRegister.cpp
   383.5 +
   383.6 +#include "StdAfx.h"
   383.7 +
   383.8 +#include "../../Common/RegisterArc.h"
   383.9 +
  383.10 +#include "TarHandler.h"
  383.11 +static IInArchive *CreateArc() { return new NArchive::NTar::CHandler;  }
  383.12 +#ifndef EXTRACT_ONLY
  383.13 +static IOutArchive *CreateArcOut() { return new NArchive::NTar::CHandler;  }
  383.14 +#else
  383.15 +#define CreateArcOut 0
  383.16 +#endif
  383.17 +
  383.18 +static CArcInfo g_ArcInfo =
  383.19 +{ L"Tar", L"tar", 0, 0xEE, { 'u', 's', 't', 'a', 'r' }, 5, false, CreateArc, CreateArcOut };
  383.20 +
  383.21 +REGISTER_ARC(Tar)
   384.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   384.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Zip/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   384.3 @@ -0,0 +1,8 @@
   384.4 +// StdAfx.h
   384.5 +
   384.6 +#ifndef __STDAFX_H
   384.7 +#define __STDAFX_H
   384.8 +
   384.9 +#include "../../../Common/MyWindows.h"
  384.10 +
  384.11 +#endif
   385.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   385.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipCompressionMode.h	Sat Mar 03 10:31:27 2012 -0600
   385.3 @@ -0,0 +1,39 @@
   385.4 +// CompressionMode.h
   385.5 +
   385.6 +#ifndef __ZIP_COMPRESSIONMETHOD_H
   385.7 +#define __ZIP_COMPRESSIONMETHOD_H
   385.8 +
   385.9 +#include "../../../Common/MyString.h"
  385.10 +
  385.11 +namespace NArchive {
  385.12 +namespace NZip {
  385.13 +
  385.14 +struct CCompressionMethodMode
  385.15 +{
  385.16 +  CRecordVector<Byte> MethodSequence;
  385.17 +  UString MatchFinder;
  385.18 +  UInt32 Algo;
  385.19 +  UInt32 NumPasses;
  385.20 +  UInt32 NumFastBytes;
  385.21 +  bool NumMatchFinderCyclesDefined;
  385.22 +  UInt32 NumMatchFinderCycles;
  385.23 +  UInt32 DicSize;
  385.24 +  #ifdef COMPRESS_MT
  385.25 +  UInt32 NumThreads;
  385.26 +  #endif
  385.27 +  bool PasswordIsDefined;
  385.28 +  AString Password;
  385.29 +  bool IsAesMode;
  385.30 +  Byte AesKeyMode;
  385.31 +  
  385.32 +  CCompressionMethodMode():
  385.33 +      NumMatchFinderCyclesDefined(false),
  385.34 +      PasswordIsDefined(false),
  385.35 +      IsAesMode(false),
  385.36 +      AesKeyMode(3)
  385.37 +      {}
  385.38 +};
  385.39 +
  385.40 +}}
  385.41 +
  385.42 +#endif
   386.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   386.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipHandler.cpp	Sat Mar 03 10:31:27 2012 -0600
   386.3 @@ -0,0 +1,831 @@
   386.4 +// ZipHandler.cpp
   386.5 +
   386.6 +#include "StdAfx.h"
   386.7 +
   386.8 +#include "Common/ComTry.h"
   386.9 +#include "Common/Defs.h"
  386.10 +#include "Common/IntToString.h"
  386.11 +#include "Common/StringConvert.h"
  386.12 +
  386.13 +#include "Windows/PropVariant.h"
  386.14 +#include "Windows/Time.h"
  386.15 +
  386.16 +#include "../../IPassword.h"
  386.17 +
  386.18 +#include "../../Common/CreateCoder.h"
  386.19 +#include "../../Common/FilterCoder.h"
  386.20 +#include "../../Common/ProgressUtils.h"
  386.21 +#include "../../Common/StreamObjects.h"
  386.22 +#include "../../Common/StreamUtils.h"
  386.23 +
  386.24 +#include "../../Compress/CopyCoder.h"
  386.25 +#include "../../Compress/LzmaDecoder.h"
  386.26 +#include "../../Compress/ImplodeDecoder.h"
  386.27 +#include "../../Compress/ShrinkDecoder.h"
  386.28 +
  386.29 +#include "../../Crypto/WzAes.h"
  386.30 +#include "../../Crypto/ZipCrypto.h"
  386.31 +#include "../../Crypto/ZipStrong.h"
  386.32 +
  386.33 +#include "../Common/ItemNameUtils.h"
  386.34 +#include "../Common/OutStreamWithCRC.h"
  386.35 +
  386.36 +#include "ZipHandler.h"
  386.37 +
  386.38 +using namespace NWindows;
  386.39 +
  386.40 +namespace NArchive {
  386.41 +namespace NZip {
  386.42 +
  386.43 +// static const CMethodId kMethodId_Store = 0;
  386.44 +static const CMethodId kMethodId_ZipBase = 0x040100;
  386.45 +static const CMethodId kMethodId_BZip2 = 0x040202;
  386.46 +
  386.47 +const wchar_t *kHostOS[] =
  386.48 +{
  386.49 +  L"FAT",
  386.50 +  L"AMIGA",
  386.51 +  L"VMS",
  386.52 +  L"Unix",
  386.53 +  L"VM/CMS",
  386.54 +  L"Atari",
  386.55 +  L"HPFS",
  386.56 +  L"Macintosh",
  386.57 +  L"Z-System",
  386.58 +  L"CP/M",
  386.59 +  L"TOPS-20",
  386.60 +  L"NTFS",
  386.61 +  L"SMS/QDOS",
  386.62 +  L"Acorn",
  386.63 +  L"VFAT",
  386.64 +  L"MVS",
  386.65 +  L"BeOS",
  386.66 +  L"Tandem",
  386.67 +  L"OS/400",
  386.68 +  L"OS/X"
  386.69 +};
  386.70 +
  386.71 +
  386.72 +static const int kNumHostOSes = sizeof(kHostOS) / sizeof(kHostOS[0]);
  386.73 +
  386.74 +static const wchar_t *kUnknownOS = L"Unknown";
  386.75 +
  386.76 +STATPROPSTG kProps[] =
  386.77 +{
  386.78 +  { NULL, kpidPath, VT_BSTR},
  386.79 +  { NULL, kpidIsDir, VT_BOOL},
  386.80 +  { NULL, kpidSize, VT_UI8},
  386.81 +  { NULL, kpidPackSize, VT_UI8},
  386.82 +  { NULL, kpidMTime, VT_FILETIME},
  386.83 +  { NULL, kpidCTime, VT_FILETIME},
  386.84 +  { NULL, kpidATime, VT_FILETIME},
  386.85 +  
  386.86 +  { NULL, kpidAttrib, VT_UI4},
  386.87 +
  386.88 +  { NULL, kpidEncrypted, VT_BOOL},
  386.89 +  { NULL, kpidComment, VT_BSTR},
  386.90 +    
  386.91 +  { NULL, kpidCRC, VT_UI4},
  386.92 +
  386.93 +  { NULL, kpidMethod, VT_BSTR},
  386.94 +  { NULL, kpidHostOS, VT_BSTR}
  386.95 +
  386.96 +  // { NULL, kpidUnpackVer, VT_UI1},
  386.97 +};
  386.98 +
  386.99 +const wchar_t *kMethods[] =
 386.100 +{
 386.101 +  L"Store",
 386.102 +  L"Shrink",
 386.103 +  L"Reduced1",
 386.104 +  L"Reduced2",
 386.105 +  L"Reduced2",
 386.106 +  L"Reduced3",
 386.107 +  L"Implode",
 386.108 +  L"Tokenizing",
 386.109 +  L"Deflate",
 386.110 +  L"Deflate64",
 386.111 +  L"PKImploding"
 386.112 +};
 386.113 +
 386.114 +const int kNumMethods = sizeof(kMethods) / sizeof(kMethods[0]);
 386.115 +const wchar_t *kBZip2Method = L"BZip2";
 386.116 +const wchar_t *kLZMAMethod = L"LZMA";
 386.117 +const wchar_t *kJpegMethod = L"Jpeg";
 386.118 +const wchar_t *kWavPackMethod = L"WavPack";
 386.119 +const wchar_t *kPPMdMethod = L"PPMd";
 386.120 +const wchar_t *kAESMethod = L"AES";
 386.121 +const wchar_t *kZipCryptoMethod = L"ZipCrypto";
 386.122 +const wchar_t *kStrongCryptoMethod = L"StrongCrypto";
 386.123 +
 386.124 +struct CStrongCryptoPair
 386.125 +{
 386.126 +  UInt16 Id;
 386.127 +  const wchar_t *Name;
 386.128 +};
 386.129 +
 386.130 +CStrongCryptoPair g_StrongCryptoPairs[] =
 386.131 +{
 386.132 +  { NStrongCryptoFlags::kDES, L"DES" },
 386.133 +  { NStrongCryptoFlags::kRC2old, L"RC2a" },
 386.134 +  { NStrongCryptoFlags::k3DES168, L"3DES-168" },
 386.135 +  { NStrongCryptoFlags::k3DES112, L"3DES-112" },
 386.136 +  { NStrongCryptoFlags::kAES128, L"pkAES-128" },
 386.137 +  { NStrongCryptoFlags::kAES192, L"pkAES-192" },
 386.138 +  { NStrongCryptoFlags::kAES256, L"pkAES-256" },
 386.139 +  { NStrongCryptoFlags::kRC2, L"RC2" },
 386.140 +  { NStrongCryptoFlags::kBlowfish, L"Blowfish" },
 386.141 +  { NStrongCryptoFlags::kTwofish, L"Twofish" },
 386.142 +  { NStrongCryptoFlags::kRC4, L"RC4" }
 386.143 +};
 386.144 +
 386.145 +STATPROPSTG kArcProps[] =
 386.146 +{
 386.147 +  { NULL, kpidBit64, VT_BOOL},
 386.148 +  { NULL, kpidComment, VT_BSTR}
 386.149 +};
 386.150 +
 386.151 +CHandler::CHandler()
 386.152 +{
 386.153 +  InitMethodProperties();
 386.154 +}
 386.155 +
 386.156 +static AString BytesToString(const CByteBuffer &data)
 386.157 +{
 386.158 +  AString s;
 386.159 +  int size = (int)data.GetCapacity();
 386.160 +  if (size > 0)
 386.161 +  {
 386.162 +    char *p = s.GetBuffer(size + 1);
 386.163 +    memcpy(p, (const Byte *)data, size);
 386.164 +    p[size] = '\0';
 386.165 +    s.ReleaseBuffer();
 386.166 +  }
 386.167 +  return s;
 386.168 +}
 386.169 +
 386.170 +IMP_IInArchive_Props
 386.171 +IMP_IInArchive_ArcProps
 386.172 +
 386.173 +STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
 386.174 +{
 386.175 +  COM_TRY_BEGIN
 386.176 +  NWindows::NCOM::CPropVariant prop;
 386.177 +  switch(propID)
 386.178 +  {
 386.179 +    case kpidBit64:  if (m_Archive.IsZip64) prop = m_Archive.IsZip64; break;
 386.180 +    case kpidComment:
 386.181 +      prop = MultiByteToUnicodeString(BytesToString(m_Archive.m_ArchiveInfo.Comment), CP_ACP);
 386.182 +      break;
 386.183 +  }
 386.184 +  prop.Detach(value);
 386.185 +  COM_TRY_END
 386.186 +  return S_OK;
 386.187 +}
 386.188 +
 386.189 +STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
 386.190 +{
 386.191 +  *numItems = m_Items.Size();
 386.192 +  return S_OK;
 386.193 +}
 386.194 +
 386.195 +STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
 386.196 +{
 386.197 +  COM_TRY_BEGIN
 386.198 +  NWindows::NCOM::CPropVariant prop;
 386.199 +  const CItemEx &item = m_Items[index];
 386.200 +  switch(propID)
 386.201 +  {
 386.202 +    case kpidPath:  prop = NItemName::GetOSName2(item.GetUnicodeString(item.Name)); break;
 386.203 +    case kpidIsDir:  prop = item.IsDir(); break;
 386.204 +    case kpidSize:  prop = item.UnPackSize; break;
 386.205 +    case kpidPackSize:  prop = item.PackSize; break;
 386.206 +    case kpidTimeType:
 386.207 +    {
 386.208 +      FILETIME utcFileTime;
 386.209 +      if (item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kTagTime, utcFileTime))
 386.210 +        prop = (UInt32)NFileTimeType::kWindows;
 386.211 +      break;
 386.212 +    }
 386.213 +    case kpidCTime:
 386.214 +    {
 386.215 +      FILETIME ft;
 386.216 +      if (item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kCTime, ft))
 386.217 +        prop = ft;
 386.218 +      break;
 386.219 +    }
 386.220 +    case kpidATime:
 386.221 +    {
 386.222 +      FILETIME ft;
 386.223 +      if (item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kATime, ft))
 386.224 +        prop = ft;
 386.225 +      break;
 386.226 +    }
 386.227 +    case kpidMTime:
 386.228 +    {
 386.229 +      FILETIME utcFileTime;
 386.230 +      if (!item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kMTime, utcFileTime))
 386.231 +      {
 386.232 +        FILETIME localFileTime;
 386.233 +        if (NTime::DosTimeToFileTime(item.Time, localFileTime))
 386.234 +        {
 386.235 +          if (!LocalFileTimeToFileTime(&localFileTime, &utcFileTime))
 386.236 +            utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
 386.237 +        }
 386.238 +        else
 386.239 +          utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
 386.240 +      }
 386.241 +      prop = utcFileTime;
 386.242 +      break;
 386.243 +    }
 386.244 +    case kpidAttrib:  prop = item.GetWinAttributes(); break;
 386.245 +    case kpidEncrypted:  prop = item.IsEncrypted(); break;
 386.246 +    case kpidComment:  prop = item.GetUnicodeString(BytesToString(item.Comment)); break;
 386.247 +    case kpidCRC:  if (item.IsThereCrc()) prop = item.FileCRC; break;
 386.248 +    case kpidMethod:
 386.249 +    {
 386.250 +      UInt16 methodId = item.CompressionMethod;
 386.251 +      UString method;
 386.252 +      if (item.IsEncrypted())
 386.253 +      {
 386.254 +        if (methodId == NFileHeader::NCompressionMethod::kWzAES)
 386.255 +        {
 386.256 +          method = kAESMethod;
 386.257 +          CWzAesExtraField aesField;
 386.258 +          if (item.CentralExtra.GetWzAesField(aesField))
 386.259 +          {
 386.260 +            method += L"-";
 386.261 +            wchar_t s[32];
 386.262 +            ConvertUInt64ToString((aesField.Strength + 1) * 64 , s);
 386.263 +            method += s;
 386.264 +            method += L" ";
 386.265 +            methodId = aesField.Method;
 386.266 +          }
 386.267 +        }
 386.268 +        else
 386.269 +        {
 386.270 +          if (item.IsStrongEncrypted())
 386.271 +          {
 386.272 +            CStrongCryptoField f;
 386.273 +            bool finded = false;
 386.274 +            if (item.CentralExtra.GetStrongCryptoField(f))
 386.275 +            {
 386.276 +              for (int i = 0; i < sizeof(g_StrongCryptoPairs) / sizeof(g_StrongCryptoPairs[0]); i++)
 386.277 +              {
 386.278 +                const CStrongCryptoPair &pair = g_StrongCryptoPairs[i];
 386.279 +                if (f.AlgId == pair.Id)
 386.280 +                {
 386.281 +                  method += pair.Name;
 386.282 +                  finded = true;
 386.283 +                  break;
 386.284 +                }
 386.285 +              }
 386.286 +            }
 386.287 +            if (!finded)
 386.288 +              method += kStrongCryptoMethod;
 386.289 +          }
 386.290 +          else
 386.291 +            method += kZipCryptoMethod;
 386.292 +          method += L" ";
 386.293 +        }
 386.294 +      }
 386.295 +      if (methodId < kNumMethods)
 386.296 +        method += kMethods[methodId];
 386.297 +      else switch (methodId)
 386.298 +      {
 386.299 +        case NFileHeader::NCompressionMethod::kLZMA:
 386.300 +          method += kLZMAMethod;
 386.301 +          if (item.IsLzmaEOS())
 386.302 +            method += L":EOS";
 386.303 +          break;
 386.304 +        case NFileHeader::NCompressionMethod::kBZip2: method += kBZip2Method; break;
 386.305 +        case NFileHeader::NCompressionMethod::kJpeg: method += kJpegMethod; break;
 386.306 +        case NFileHeader::NCompressionMethod::kWavPack: method += kWavPackMethod; break;
 386.307 +        case NFileHeader::NCompressionMethod::kPPMd: method += kPPMdMethod; break;
 386.308 +        default:
 386.309 +        {
 386.310 +          wchar_t s[32];
 386.311 +          ConvertUInt64ToString(methodId, s);
 386.312 +          method += s;
 386.313 +        }
 386.314 +      }
 386.315 +      prop = method;
 386.316 +      break;
 386.317 +    }
 386.318 +    case kpidHostOS:
 386.319 +      prop = (item.MadeByVersion.HostOS < kNumHostOSes) ?
 386.320 +        (kHostOS[item.MadeByVersion.HostOS]) : kUnknownOS;
 386.321 +      break;
 386.322 +  }
 386.323 +  prop.Detach(value);
 386.324 +  return S_OK;
 386.325 +  COM_TRY_END
 386.326 +}
 386.327 +
 386.328 +class CProgressImp: public CProgressVirt
 386.329 +{
 386.330 +  CMyComPtr<IArchiveOpenCallback> _callback;
 386.331 +public:
 386.332 +  STDMETHOD(SetTotal)(UInt64 numFiles);
 386.333 +  STDMETHOD(SetCompleted)(UInt64 numFiles);
 386.334 +  CProgressImp(IArchiveOpenCallback *callback): _callback(callback) {}
 386.335 +};
 386.336 +
 386.337 +STDMETHODIMP CProgressImp::SetTotal(UInt64 numFiles)
 386.338 +{
 386.339 +  if (_callback)
 386.340 +    return _callback->SetTotal(&numFiles, NULL);
 386.341 +  return S_OK;
 386.342 +}
 386.343 +
 386.344 +STDMETHODIMP CProgressImp::SetCompleted(UInt64 numFiles)
 386.345 +{
 386.346 +  if (_callback)
 386.347 +    return _callback->SetCompleted(&numFiles, NULL);
 386.348 +  return S_OK;
 386.349 +}
 386.350 +
 386.351 +STDMETHODIMP CHandler::Open(IInStream *inStream,
 386.352 +    const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *callback)
 386.353 +{
 386.354 +  COM_TRY_BEGIN
 386.355 +  try
 386.356 +  {
 386.357 +    Close();
 386.358 +    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));
 386.359 +    RINOK(m_Archive.Open(inStream, maxCheckStartPosition));
 386.360 +    CProgressImp progressImp(callback);
 386.361 +    return m_Archive.ReadHeaders(m_Items, &progressImp);
 386.362 +  }
 386.363 +  catch(const CInArchiveException &) { Close(); return S_FALSE; }
 386.364 +  catch(...) { Close(); throw; }
 386.365 +  COM_TRY_END
 386.366 +}
 386.367 +
 386.368 +STDMETHODIMP CHandler::Close()
 386.369 +{
 386.370 +  m_Items.Clear();
 386.371 +  m_Archive.Close();
 386.372 +  return S_OK;
 386.373 +}
 386.374 +
 386.375 +//////////////////////////////////////
 386.376 +// CHandler::DecompressItems
 386.377 +
 386.378 +class CLzmaDecoder:
 386.379 +  public ICompressCoder,
 386.380 +  public CMyUnknownImp
 386.381 +{
 386.382 +  NCompress::NLzma::CDecoder *DecoderSpec;
 386.383 +  CMyComPtr<ICompressCoder> Decoder;
 386.384 +public:
 386.385 +  CLzmaDecoder();
 386.386 +  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 386.387 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
 386.388 +
 386.389 +  MY_UNKNOWN_IMP
 386.390 +};
 386.391 +
 386.392 +CLzmaDecoder::CLzmaDecoder()
 386.393 +{
 386.394 +  DecoderSpec = new NCompress::NLzma::CDecoder;
 386.395 +  Decoder = DecoderSpec;
 386.396 +}
 386.397 +
 386.398 +HRESULT CLzmaDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 386.399 +    const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)
 386.400 +{
 386.401 +  Byte buf[9];
 386.402 +  RINOK(ReadStream_FALSE(inStream, buf, 9));
 386.403 +  if (buf[2] != 5 || buf[3] != 0)
 386.404 +    return E_NOTIMPL;
 386.405 +  RINOK(DecoderSpec->SetDecoderProperties2(buf + 4, 5));
 386.406 +  return Decoder->Code(inStream, outStream, NULL, outSize, progress);
 386.407 +}
 386.408 +
 386.409 +struct CMethodItem
 386.410 +{
 386.411 +  UInt16 ZipMethod;
 386.412 +  CMyComPtr<ICompressCoder> Coder;
 386.413 +};
 386.414 +
 386.415 +class CZipDecoder
 386.416 +{
 386.417 +  NCrypto::NZip::CDecoder *_zipCryptoDecoderSpec;
 386.418 +  NCrypto::NZipStrong::CDecoder *_pkAesDecoderSpec;
 386.419 +  NCrypto::NWzAes::CDecoder *_wzAesDecoderSpec;
 386.420 +
 386.421 +  CMyComPtr<ICompressFilter> _zipCryptoDecoder;
 386.422 +  CMyComPtr<ICompressFilter> _pkAesDecoder;
 386.423 +  CMyComPtr<ICompressFilter> _wzAesDecoder;
 386.424 +
 386.425 +  CFilterCoder *filterStreamSpec;
 386.426 +  CMyComPtr<ISequentialInStream> filterStream;
 386.427 +  CMyComPtr<ICryptoGetTextPassword> getTextPassword;
 386.428 +  CObjectVector<CMethodItem> methodItems;
 386.429 +
 386.430 +public:
 386.431 +  CZipDecoder():
 386.432 +      _zipCryptoDecoderSpec(0),
 386.433 +      _pkAesDecoderSpec(0),
 386.434 +      _wzAesDecoderSpec(0),
 386.435 +      filterStreamSpec(0) {}
 386.436 +
 386.437 +  HRESULT Decode(
 386.438 +    DECL_EXTERNAL_CODECS_LOC_VARS
 386.439 +    CInArchive &archive, const CItemEx &item,
 386.440 +    ISequentialOutStream *realOutStream,
 386.441 +    IArchiveExtractCallback *extractCallback,
 386.442 +    ICompressProgressInfo *compressProgress,
 386.443 +    UInt32 numThreads, Int32 &res);
 386.444 +};
 386.445 +
 386.446 +HRESULT CZipDecoder::Decode(
 386.447 +    DECL_EXTERNAL_CODECS_LOC_VARS
 386.448 +    CInArchive &archive, const CItemEx &item,
 386.449 +    ISequentialOutStream *realOutStream,
 386.450 +    IArchiveExtractCallback *extractCallback,
 386.451 +    ICompressProgressInfo *compressProgress,
 386.452 +    UInt32 numThreads, Int32 &res)
 386.453 +{
 386.454 +  res = NArchive::NExtract::NOperationResult::kDataError;
 386.455 +  CInStreamReleaser inStreamReleaser;
 386.456 +
 386.457 +  bool needCRC = true;
 386.458 +  bool wzAesMode = false;
 386.459 +  bool pkAesMode = false;
 386.460 +  UInt16 methodId = item.CompressionMethod;
 386.461 +  if (item.IsEncrypted())
 386.462 +  {
 386.463 +    if (item.IsStrongEncrypted())
 386.464 +    {
 386.465 +      CStrongCryptoField f;
 386.466 +      if (item.CentralExtra.GetStrongCryptoField(f))
 386.467 +      {
 386.468 +        pkAesMode = true;
 386.469 +      }
 386.470 +      if (!pkAesMode)
 386.471 +      {
 386.472 +        res = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
 386.473 +        return S_OK;
 386.474 +      }
 386.475 +    }
 386.476 +    if (methodId == NFileHeader::NCompressionMethod::kWzAES)
 386.477 +    {
 386.478 +      CWzAesExtraField aesField;
 386.479 +      if (item.CentralExtra.GetWzAesField(aesField))
 386.480 +      {
 386.481 +        wzAesMode = true;
 386.482 +        needCRC = aesField.NeedCrc();
 386.483 +      }
 386.484 +    }
 386.485 +  }
 386.486 +    
 386.487 +  COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC;
 386.488 +  CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
 386.489 +  outStreamSpec->SetStream(realOutStream);
 386.490 +  outStreamSpec->Init(needCRC);
 386.491 +  
 386.492 +  UInt64 authenticationPos;
 386.493 +  
 386.494 +  CMyComPtr<ISequentialInStream> inStream;
 386.495 +  {
 386.496 +    UInt64 packSize = item.PackSize;
 386.497 +    if (wzAesMode)
 386.498 +    {
 386.499 +      if (packSize < NCrypto::NWzAes::kMacSize)
 386.500 +        return S_OK;
 386.501 +      packSize -= NCrypto::NWzAes::kMacSize;
 386.502 +    }
 386.503 +    UInt64 dataPos = item.GetDataPosition();
 386.504 +    inStream.Attach(archive.CreateLimitedStream(dataPos, packSize));
 386.505 +    authenticationPos = dataPos + packSize;
 386.506 +  }
 386.507 +  
 386.508 +  CMyComPtr<ICompressFilter> cryptoFilter;
 386.509 +  if (item.IsEncrypted())
 386.510 +  {
 386.511 +    if (wzAesMode)
 386.512 +    {
 386.513 +      CWzAesExtraField aesField;
 386.514 +      if (!item.CentralExtra.GetWzAesField(aesField))
 386.515 +        return S_OK;
 386.516 +      methodId = aesField.Method;
 386.517 +      if (!_wzAesDecoder)
 386.518 +      {
 386.519 +        _wzAesDecoderSpec = new NCrypto::NWzAes::CDecoder;
 386.520 +        _wzAesDecoder = _wzAesDecoderSpec;
 386.521 +      }
 386.522 +      cryptoFilter = _wzAesDecoder;
 386.523 +      Byte properties = aesField.Strength;
 386.524 +      RINOK(_wzAesDecoderSpec->SetDecoderProperties2(&properties, 1));
 386.525 +    }
 386.526 +    else if (pkAesMode)
 386.527 +    {
 386.528 +      if (!_pkAesDecoder)
 386.529 +      {
 386.530 +        _pkAesDecoderSpec = new NCrypto::NZipStrong::CDecoder;
 386.531 +        _pkAesDecoder = _pkAesDecoderSpec;
 386.532 +      }
 386.533 +      cryptoFilter = _pkAesDecoder;
 386.534 +    }
 386.535 +    else
 386.536 +    {
 386.537 +      if (!_zipCryptoDecoder)
 386.538 +      {
 386.539 +        _zipCryptoDecoderSpec = new NCrypto::NZip::CDecoder;
 386.540 +        _zipCryptoDecoder = _zipCryptoDecoderSpec;
 386.541 +      }
 386.542 +      cryptoFilter = _zipCryptoDecoder;
 386.543 +    }
 386.544 +    CMyComPtr<ICryptoSetPassword> cryptoSetPassword;
 386.545 +    RINOK(cryptoFilter.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword));
 386.546 +    
 386.547 +    if (!getTextPassword)
 386.548 +      extractCallback->QueryInterface(IID_ICryptoGetTextPassword, (void **)&getTextPassword);
 386.549 +    
 386.550 +    if (getTextPassword)
 386.551 +    {
 386.552 +      CMyComBSTR password;
 386.553 +      RINOK(getTextPassword->CryptoGetTextPassword(&password));
 386.554 +      AString charPassword;
 386.555 +      if (wzAesMode || pkAesMode)
 386.556 +      {
 386.557 +        charPassword = UnicodeStringToMultiByte((const wchar_t *)password, CP_ACP);
 386.558 +        /*
 386.559 +        for (int i = 0;; i++)
 386.560 +        {
 386.561 +          wchar_t c = password[i];
 386.562 +          if (c == 0)
 386.563 +            break;
 386.564 +          if (c >= 0x80)
 386.565 +          {
 386.566 +            res = NArchive::NExtract::NOperationResult::kDataError;
 386.567 +            return S_OK;
 386.568 +          }
 386.569 +          charPassword += (char)c;
 386.570 +        }
 386.571 +        */
 386.572 +      }
 386.573 +      else
 386.574 +      {
 386.575 +        // we use OEM. WinZip/Windows probably use ANSI for some files
 386.576 +        charPassword = UnicodeStringToMultiByte((const wchar_t *)password, CP_OEMCP);
 386.577 +      }
 386.578 +      HRESULT result = cryptoSetPassword->CryptoSetPassword(
 386.579 +        (const Byte *)(const char *)charPassword, charPassword.Length());
 386.580 +      if (result != S_OK)
 386.581 +        return S_OK;
 386.582 +    }
 386.583 +    else
 386.584 +    {
 386.585 +      RINOK(cryptoSetPassword->CryptoSetPassword(0, 0));
 386.586 +    }
 386.587 +  }
 386.588 +  
 386.589 +  int m;
 386.590 +  for (m = 0; m < methodItems.Size(); m++)
 386.591 +    if (methodItems[m].ZipMethod == methodId)
 386.592 +      break;
 386.593 +
 386.594 +  if (m == methodItems.Size())
 386.595 +  {
 386.596 +    CMethodItem mi;
 386.597 +    mi.ZipMethod = methodId;
 386.598 +    if (methodId == NFileHeader::NCompressionMethod::kStored)
 386.599 +      mi.Coder = new NCompress::CCopyCoder;
 386.600 +    else if (methodId == NFileHeader::NCompressionMethod::kShrunk)
 386.601 +      mi.Coder = new NCompress::NShrink::CDecoder;
 386.602 +    else if (methodId == NFileHeader::NCompressionMethod::kImploded)
 386.603 +      mi.Coder = new NCompress::NImplode::NDecoder::CCoder;
 386.604 +    else if (methodId == NFileHeader::NCompressionMethod::kLZMA)
 386.605 +      mi.Coder = new CLzmaDecoder;
 386.606 +    else
 386.607 +    {
 386.608 +      CMethodId szMethodID;
 386.609 +      if (methodId == NFileHeader::NCompressionMethod::kBZip2)
 386.610 +        szMethodID = kMethodId_BZip2;
 386.611 +      else
 386.612 +      {
 386.613 +        if (methodId > 0xFF)
 386.614 +        {
 386.615 +          res = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
 386.616 +          return S_OK;
 386.617 +        }
 386.618 +        szMethodID = kMethodId_ZipBase + (Byte)methodId;
 386.619 +      }
 386.620 +
 386.621 +      RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS szMethodID, mi.Coder, false));
 386.622 +
 386.623 +      if (mi.Coder == 0)
 386.624 +      {
 386.625 +        res = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
 386.626 +        return S_OK;
 386.627 +      }
 386.628 +    }
 386.629 +    m = methodItems.Add(mi);
 386.630 +  }
 386.631 +  ICompressCoder *coder = methodItems[m].Coder;
 386.632 +  
 386.633 +  {
 386.634 +    CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;
 386.635 +    coder->QueryInterface(IID_ICompressSetDecoderProperties2, (void **)&setDecoderProperties);
 386.636 +    if (setDecoderProperties)
 386.637 +    {
 386.638 +      Byte properties = (Byte)item.Flags;
 386.639 +      RINOK(setDecoderProperties->SetDecoderProperties2(&properties, 1));
 386.640 +    }
 386.641 +  }
 386.642 +  
 386.643 +  #ifdef COMPRESS_MT
 386.644 +  {
 386.645 +    CMyComPtr<ICompressSetCoderMt> setCoderMt;
 386.646 +    coder->QueryInterface(IID_ICompressSetCoderMt, (void **)&setCoderMt);
 386.647 +    if (setCoderMt)
 386.648 +    {
 386.649 +      RINOK(setCoderMt->SetNumberOfThreads(numThreads));
 386.650 +    }
 386.651 +  }
 386.652 +  #endif
 386.653 +  
 386.654 +  {
 386.655 +    HRESULT result = S_OK;
 386.656 +    CMyComPtr<ISequentialInStream> inStreamNew;
 386.657 +    if (item.IsEncrypted())
 386.658 +    {
 386.659 +      if (!filterStream)
 386.660 +      {
 386.661 +        filterStreamSpec = new CFilterCoder;
 386.662 +        filterStream = filterStreamSpec;
 386.663 +      }
 386.664 +      filterStreamSpec->Filter = cryptoFilter;
 386.665 +      if (wzAesMode)
 386.666 +      {
 386.667 +        result = _wzAesDecoderSpec->ReadHeader(inStream);
 386.668 +      }
 386.669 +      else if (pkAesMode)
 386.670 +      {
 386.671 +        result =_pkAesDecoderSpec->ReadHeader(inStream, item.FileCRC, item.UnPackSize);
 386.672 +        if (result == S_OK)
 386.673 +        {
 386.674 +          bool passwOK;
 386.675 +          result = _pkAesDecoderSpec->CheckPassword(passwOK);
 386.676 +          if (result == S_OK && !passwOK)
 386.677 +            result = S_FALSE;
 386.678 +        }
 386.679 +      }
 386.680 +      else
 386.681 +      {
 386.682 +        result = _zipCryptoDecoderSpec->ReadHeader(inStream);
 386.683 +      }
 386.684 +
 386.685 +      if (result == S_OK)
 386.686 +      {
 386.687 +        RINOK(filterStreamSpec->SetInStream(inStream));
 386.688 +        inStreamReleaser.FilterCoder = filterStreamSpec;
 386.689 +        inStreamNew = filterStream;
 386.690 +        if (wzAesMode)
 386.691 +        {
 386.692 +          if (!_wzAesDecoderSpec->CheckPasswordVerifyCode())
 386.693 +            result = S_FALSE;
 386.694 +        }
 386.695 +      }
 386.696 +    }
 386.697 +    else
 386.698 +      inStreamNew = inStream;
 386.699 +    if (result == S_OK)
 386.700 +      result = coder->Code(inStreamNew, outStream, NULL, &item.UnPackSize, compressProgress);
 386.701 +    if (result == S_FALSE)
 386.702 +      return S_OK;
 386.703 +    if (result == E_NOTIMPL)
 386.704 +    {
 386.705 +      res = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
 386.706 +      return S_OK;
 386.707 +    }
 386.708 +
 386.709 +    RINOK(result);
 386.710 +  }
 386.711 +  bool crcOK = true;
 386.712 +  bool authOk = true;
 386.713 +  if (needCRC)
 386.714 +    crcOK = (outStreamSpec->GetCRC() == item.FileCRC);
 386.715 +  if (wzAesMode)
 386.716 +  {
 386.717 +    inStream.Attach(archive.CreateLimitedStream(authenticationPos, NCrypto::NWzAes::kMacSize));
 386.718 +    if (_wzAesDecoderSpec->CheckMac(inStream, authOk) != S_OK)
 386.719 +      authOk = false;
 386.720 +  }
 386.721 +  
 386.722 +  res = ((crcOK && authOk) ?
 386.723 +    NArchive::NExtract::NOperationResult::kOK :
 386.724 +    NArchive::NExtract::NOperationResult::kCRCError);
 386.725 +  return S_OK;
 386.726 +}
 386.727 +
 386.728 +
 386.729 +STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
 386.730 +    Int32 _aTestMode, IArchiveExtractCallback *extractCallback)
 386.731 +{
 386.732 +  COM_TRY_BEGIN
 386.733 +  CZipDecoder myDecoder;
 386.734 +  bool testMode = (_aTestMode != 0);
 386.735 +  UInt64 totalUnPacked = 0, totalPacked = 0;
 386.736 +  bool allFilesMode = (numItems == UInt32(-1));
 386.737 +  if (allFilesMode)
 386.738 +    numItems = m_Items.Size();
 386.739 +  if(numItems == 0)
 386.740 +    return S_OK;
 386.741 +  UInt32 i;
 386.742 +  for(i = 0; i < numItems; i++)
 386.743 +  {
 386.744 +    const CItemEx &item = m_Items[allFilesMode ? i : indices[i]];
 386.745 +    totalUnPacked += item.UnPackSize;
 386.746 +    totalPacked += item.PackSize;
 386.747 +  }
 386.748 +  RINOK(extractCallback->SetTotal(totalUnPacked));
 386.749 +
 386.750 +  UInt64 currentTotalUnPacked = 0, currentTotalPacked = 0;
 386.751 +  UInt64 currentItemUnPacked, currentItemPacked;
 386.752 +  
 386.753 +  CLocalProgress *lps = new CLocalProgress;
 386.754 +  CMyComPtr<ICompressProgressInfo> progress = lps;
 386.755 +  lps->Init(extractCallback, false);
 386.756 +
 386.757 +  for (i = 0; i < numItems; i++, currentTotalUnPacked += currentItemUnPacked,
 386.758 +      currentTotalPacked += currentItemPacked)
 386.759 +  {
 386.760 +    currentItemUnPacked = 0;
 386.761 +    currentItemPacked = 0;
 386.762 +
 386.763 +    lps->InSize = currentTotalPacked;
 386.764 +    lps->OutSize = currentTotalUnPacked;
 386.765 +    RINOK(lps->SetCur());
 386.766 +
 386.767 +    CMyComPtr<ISequentialOutStream> realOutStream;
 386.768 +    Int32 askMode = testMode ?
 386.769 +        NArchive::NExtract::NAskMode::kTest :
 386.770 +        NArchive::NExtract::NAskMode::kExtract;
 386.771 +    Int32 index = allFilesMode ? i : indices[i];
 386.772 +
 386.773 +    RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
 386.774 +
 386.775 +    CItemEx item = m_Items[index];
 386.776 +    if (!item.FromLocal)
 386.777 +    {
 386.778 +      HRESULT res = m_Archive.ReadLocalItemAfterCdItem(item);
 386.779 +      if (res == S_FALSE)
 386.780 +      {
 386.781 +        if (item.IsDir() || realOutStream || testMode)
 386.782 +        {
 386.783 +          RINOK(extractCallback->PrepareOperation(askMode));
 386.784 +          realOutStream.Release();
 386.785 +          RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kUnSupportedMethod));
 386.786 +        }
 386.787 +        continue;
 386.788 +      }
 386.789 +      RINOK(res);
 386.790 +    }
 386.791 +
 386.792 +    if (item.IsDir() || item.IgnoreItem())
 386.793 +    {
 386.794 +      // if (!testMode)
 386.795 +      {
 386.796 +        RINOK(extractCallback->PrepareOperation(askMode));
 386.797 +        realOutStream.Release();
 386.798 +        RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));
 386.799 +      }
 386.800 +      continue;
 386.801 +    }
 386.802 +
 386.803 +    currentItemUnPacked = item.UnPackSize;
 386.804 +    currentItemPacked = item.PackSize;
 386.805 +
 386.806 +    if (!testMode && (!realOutStream))
 386.807 +      continue;
 386.808 +
 386.809 +    RINOK(extractCallback->PrepareOperation(askMode));
 386.810 +
 386.811 +#ifndef COMPRESS_MT
 386.812 +#define _numThreads 1
 386.813 +#endif
 386.814 +
 386.815 +    Int32 res;
 386.816 +    RINOK(myDecoder.Decode(
 386.817 +        EXTERNAL_CODECS_VARS
 386.818 +        m_Archive, item, realOutStream, extractCallback,
 386.819 +        progress, 
 386.820 +		_numThreads, 
 386.821 +		res));
 386.822 +    realOutStream.Release();
 386.823 +    
 386.824 +    RINOK(extractCallback->SetOperationResult(res))
 386.825 +  }
 386.826 +  return S_OK;
 386.827 +  COM_TRY_END
 386.828 +}
 386.829 +
 386.830 +#ifndef EXTRACT_ONLY
 386.831 +IMPL_ISetCompressCodecsInfo
 386.832 +#endif
 386.833 +
 386.834 +}}
   387.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   387.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipHandler.h	Sat Mar 03 10:31:27 2012 -0600
   387.3 @@ -0,0 +1,100 @@
   387.4 +// Zip/Handler.h
   387.5 +
   387.6 +#ifndef __ZIP_HANDLER_H
   387.7 +#define __ZIP_HANDLER_H
   387.8 +
   387.9 +#include "../../../Common/DynamicBuffer.h"
  387.10 +#include "../../ICoder.h"
  387.11 +#include "../IArchive.h"
  387.12 +
  387.13 +#include "../../Common/CreateCoder.h"
  387.14 +
  387.15 +#include "ZipIn.h"
  387.16 +#include "ZipCompressionMode.h"
  387.17 +
  387.18 +#ifdef COMPRESS_MT
  387.19 +#include "../../../Windows/System.h"
  387.20 +#endif
  387.21 +
  387.22 +namespace NArchive {
  387.23 +namespace NZip {
  387.24 +
  387.25 +class CHandler:
  387.26 +  public IInArchive,
  387.27 +#ifndef EXTRACT_ONLY
  387.28 +  public IOutArchive,
  387.29 +  public ISetProperties,
  387.30 +  PUBLIC_ISetCompressCodecsInfo
  387.31 +#endif
  387.32 +  public CMyUnknownImp
  387.33 +{
  387.34 +public:
  387.35 +  MY_QUERYINTERFACE_BEGIN2(IInArchive)
  387.36 +#ifndef EXTRACT_ONLY
  387.37 +  MY_QUERYINTERFACE_ENTRY(IOutArchive)
  387.38 +  MY_QUERYINTERFACE_ENTRY(ISetProperties)
  387.39 +  QUERY_ENTRY_ISetCompressCodecsInfo
  387.40 +#endif
  387.41 +  MY_QUERYINTERFACE_END
  387.42 +  MY_ADDREF_RELEASE
  387.43 +
  387.44 +  INTERFACE_IInArchive(;)
  387.45 +#ifndef EXTRACT_ONLY
  387.46 +  INTERFACE_IOutArchive(;)
  387.47 +
  387.48 +  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);
  387.49 +
  387.50 +  DECL_ISetCompressCodecsInfo
  387.51 +#endif
  387.52 +
  387.53 +  CHandler();
  387.54 +private:
  387.55 +  CObjectVector<CItemEx> m_Items;
  387.56 +  CInArchive m_Archive;
  387.57 +
  387.58 +  int m_Level;
  387.59 +  int m_MainMethod;
  387.60 +  UInt32 m_DicSize;
  387.61 +  UInt32 m_Algo;
  387.62 +  UInt32 m_NumPasses;
  387.63 +  UInt32 m_NumFastBytes;
  387.64 +  UInt32 m_NumMatchFinderCycles;
  387.65 +  bool m_NumMatchFinderCyclesDefined;
  387.66 +
  387.67 +  bool m_IsAesMode;
  387.68 +  Byte m_AesKeyMode;
  387.69 +
  387.70 +  bool m_WriteNtfsTimeExtra;
  387.71 +  bool m_ForseLocal;
  387.72 +  bool m_ForseUtf8;
  387.73 +
  387.74 +  #ifdef COMPRESS_MT
  387.75 +  UInt32 _numThreads;
  387.76 +  #endif
  387.77 +
  387.78 +  DECL_EXTERNAL_CODECS_VARS
  387.79 +
  387.80 +  void InitMethodProperties()
  387.81 +  {
  387.82 +    m_Level = -1;
  387.83 +    m_MainMethod = -1;
  387.84 +    m_Algo =
  387.85 +    m_DicSize =
  387.86 +    m_NumPasses =
  387.87 +    m_NumFastBytes =
  387.88 +    m_NumMatchFinderCycles = 0xFFFFFFFF;
  387.89 +    m_NumMatchFinderCyclesDefined = false;
  387.90 +    m_IsAesMode = false;
  387.91 +    m_AesKeyMode = 3; // aes-256
  387.92 +    m_WriteNtfsTimeExtra = false;
  387.93 +    m_ForseLocal = false;
  387.94 +    m_ForseUtf8 = false;
  387.95 +    #ifdef COMPRESS_MT
  387.96 +    _numThreads = NWindows::NSystem::GetNumberOfProcessors();;
  387.97 +    #endif
  387.98 +  }
  387.99 +};
 387.100 +
 387.101 +}}
 387.102 +
 387.103 +#endif
   388.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   388.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipHeader.cpp	Sat Mar 03 10:31:27 2012 -0600
   388.3 @@ -0,0 +1,35 @@
   388.4 +// Archive/Zip/Header.h
   388.5 +
   388.6 +#include "StdAfx.h"
   388.7 +
   388.8 +#include "ZipHeader.h"
   388.9 +
  388.10 +namespace NArchive {
  388.11 +namespace NZip {
  388.12 +
  388.13 +namespace NSignature
  388.14 +{
  388.15 +  UInt32 kLocalFileHeader   = 0x04034B50 + 1;
  388.16 +  UInt32 kDataDescriptor    = 0x08074B50 + 1;
  388.17 +  UInt32 kCentralFileHeader = 0x02014B50 + 1;
  388.18 +  UInt32 kEndOfCentralDir   = 0x06054B50 + 1;
  388.19 +  UInt32 kZip64EndOfCentralDir   = 0x06064B50 + 1;
  388.20 +  UInt32 kZip64EndOfCentralDirLocator   = 0x07064B50 + 1;
  388.21 +  
  388.22 +  class CMarkersInitializer
  388.23 +  {
  388.24 +  public:
  388.25 +    CMarkersInitializer()
  388.26 +    {
  388.27 +      kLocalFileHeader--;
  388.28 +      kDataDescriptor--;
  388.29 +      kCentralFileHeader--;
  388.30 +      kEndOfCentralDir--;
  388.31 +      kZip64EndOfCentralDir--;
  388.32 +      kZip64EndOfCentralDirLocator--;
  388.33 +    }
  388.34 +  } g_MarkerInitializer;
  388.35 +}
  388.36 +
  388.37 +}}
  388.38 +
   389.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   389.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipHeader.h	Sat Mar 03 10:31:27 2012 -0600
   389.3 @@ -0,0 +1,265 @@
   389.4 +// Archive/Zip/Header.h
   389.5 +
   389.6 +#ifndef __ARCHIVE_ZIP_HEADER_H
   389.7 +#define __ARCHIVE_ZIP_HEADER_H
   389.8 +
   389.9 +#include "../../../Common/Types.h"
  389.10 +
  389.11 +namespace NArchive {
  389.12 +namespace NZip {
  389.13 +
  389.14 +namespace NSignature
  389.15 +{
  389.16 +  extern UInt32 kLocalFileHeader;
  389.17 +  extern UInt32 kDataDescriptor;
  389.18 +  extern UInt32 kCentralFileHeader;
  389.19 +  extern UInt32 kEndOfCentralDir;
  389.20 +  extern UInt32 kZip64EndOfCentralDir;
  389.21 +  extern UInt32 kZip64EndOfCentralDirLocator;
  389.22 +  
  389.23 +  static const UInt32 kMarkerSize = 4;
  389.24 +}
  389.25 +
  389.26 +const UInt32 kEcdSize = 22;
  389.27 +const UInt32 kZip64EcdSize = 44;
  389.28 +const UInt32 kZip64EcdLocatorSize = 20;
  389.29 +/*
  389.30 +struct CEndOfCentralDirectoryRecord
  389.31 +{
  389.32 +  UInt16 ThisDiskNumber;
  389.33 +  UInt16 StartCentralDirectoryDiskNumber;
  389.34 +  UInt16 NumEntriesInCentaralDirectoryOnThisDisk;
  389.35 +  UInt16 NumEntriesInCentaralDirectory;
  389.36 +  UInt32 CentralDirectorySize;
  389.37 +  UInt32 CentralDirectoryStartOffset;
  389.38 +  UInt16 CommentSize;
  389.39 +};
  389.40 +
  389.41 +struct CEndOfCentralDirectoryRecordFull
  389.42 +{
  389.43 +  UInt32 Signature;
  389.44 +  CEndOfCentralDirectoryRecord Header;
  389.45 +};
  389.46 +*/
  389.47 +
  389.48 +namespace NFileHeader
  389.49 +{
  389.50 +  /*
  389.51 +  struct CVersion
  389.52 +  {
  389.53 +    Byte Version;
  389.54 +    Byte HostOS;
  389.55 +  };
  389.56 +  */
  389.57 +  
  389.58 +  namespace NCompressionMethod
  389.59 +  {
  389.60 +    enum EType
  389.61 +    {
  389.62 +      kStored = 0,
  389.63 +      kShrunk = 1,
  389.64 +      kReduced1 = 2,
  389.65 +      kReduced2 = 3,
  389.66 +      kReduced3 = 4,
  389.67 +      kReduced4 = 5,
  389.68 +      kImploded = 6,
  389.69 +      kReservedTokenizing = 7, // reserved for tokenizing
  389.70 +      kDeflated = 8,
  389.71 +      kDeflated64 = 9,
  389.72 +      kPKImploding = 10,
  389.73 +      
  389.74 +      kBZip2 = 12,
  389.75 +      kLZMA = 14,
  389.76 +      kTerse = 18,
  389.77 +      kLz77 = 19,
  389.78 +      kJpeg = 0x60,
  389.79 +      kWavPack = 0x61,
  389.80 +      kPPMd = 0x62,
  389.81 +      kWzAES = 0x63
  389.82 +    };
  389.83 +    const int kNumCompressionMethods = 11;
  389.84 +    const Byte kMadeByProgramVersion = 20;
  389.85 +    
  389.86 +    const Byte kDeflateExtractVersion = 20;
  389.87 +    const Byte kStoreExtractVersion = 10;
  389.88 +    
  389.89 +    const Byte kSupportedVersion   = 20;
  389.90 +  }
  389.91 +
  389.92 +  namespace NExtraID
  389.93 +  {
  389.94 +    enum
  389.95 +    {
  389.96 +      kZip64 = 0x01,
  389.97 +      kNTFS = 0x0A,
  389.98 +      kStrongEncrypt = 0x17,
  389.99 +      kWzAES = 0x9901
 389.100 +    };
 389.101 +  }
 389.102 +
 389.103 +  namespace NNtfsExtra
 389.104 +  {
 389.105 +    const UInt16 kTagTime = 1;
 389.106 +    enum
 389.107 +    {
 389.108 +      kMTime = 0,
 389.109 +      kATime = 1,
 389.110 +      kCTime = 2
 389.111 +    };
 389.112 +  }
 389.113 +
 389.114 +  const UInt32 kLocalBlockSize = 26;
 389.115 +  /*
 389.116 +  struct CLocalBlock
 389.117 +  {
 389.118 +    CVersion ExtractVersion;
 389.119 +    
 389.120 +    UInt16 Flags;
 389.121 +    UInt16 CompressionMethod;
 389.122 +    UInt32 Time;
 389.123 +    UInt32 FileCRC;
 389.124 +    UInt32 PackSize;
 389.125 +    UInt32 UnPackSize;
 389.126 +    UInt16 NameSize;
 389.127 +    UInt16 ExtraSize;
 389.128 +  };
 389.129 +  */
 389.130 +
 389.131 +  const UInt32 kDataDescriptorSize = 16;
 389.132 +  // const UInt32 kDataDescriptor64Size = 16 + 8;
 389.133 +  /*
 389.134 +  struct CDataDescriptor
 389.135 +  {
 389.136 +    UInt32 Signature;
 389.137 +    UInt32 FileCRC;
 389.138 +    UInt32 PackSize;
 389.139 +    UInt32 UnPackSize;
 389.140 +  };
 389.141 +
 389.142 +  struct CLocalBlockFull
 389.143 +  {
 389.144 +    UInt32 Signature;
 389.145 +    CLocalBlock Header;
 389.146 +  };
 389.147 +  */
 389.148 +  
 389.149 +  const UInt32 kCentralBlockSize = 42;
 389.150 +  /*
 389.151 +  struct CBlock
 389.152 +  {
 389.153 +    CVersion MadeByVersion;
 389.154 +    CVersion ExtractVersion;
 389.155 +    UInt16 Flags;
 389.156 +    UInt16 CompressionMethod;
 389.157 +    UInt32 Time;
 389.158 +    UInt32 FileCRC;
 389.159 +    UInt32 PackSize;
 389.160 +    UInt32 UnPackSize;
 389.161 +    UInt16 NameSize;
 389.162 +    UInt16 ExtraSize;
 389.163 +    UInt16 CommentSize;
 389.164 +    UInt16 DiskNumberStart;
 389.165 +    UInt16 InternalAttributes;
 389.166 +    UInt32 ExternalAttributes;
 389.167 +    UInt32 LocalHeaderOffset;
 389.168 +  };
 389.169 +  
 389.170 +  struct CBlockFull
 389.171 +  {
 389.172 +    UInt32 Signature;
 389.173 +    CBlock Header;
 389.174 +  };
 389.175 +  */
 389.176 +
 389.177 +  namespace NFlags
 389.178 +  {
 389.179 +    const int kEncrypted = 1 << 0;
 389.180 +    const int kLzmaEOS = 1 << 1;
 389.181 +    const int kDescriptorUsedMask = 1 << 3;
 389.182 +    const int kStrongEncrypted = 1 << 6;
 389.183 +    const int kUtf8 = 1 << 11;
 389.184 +
 389.185 +    const int kImplodeDictionarySizeMask = 1 << 1;
 389.186 +    const int kImplodeLiteralsOnMask     = 1 << 2;
 389.187 +    
 389.188 +    const int kDeflateTypeBitStart = 1;
 389.189 +    const int kNumDeflateTypeBits = 2;
 389.190 +    const int kNumDeflateTypes = (1 << kNumDeflateTypeBits);
 389.191 +    const int kDeflateTypeMask = (1 << kNumDeflateTypeBits) - 1;
 389.192 +  }
 389.193 +  
 389.194 +  namespace NHostOS
 389.195 +  {
 389.196 +    enum EEnum
 389.197 +    {
 389.198 +        kFAT      = 0,
 389.199 +        kAMIGA    = 1,
 389.200 +        kVMS      = 2,  // VAX/VMS
 389.201 +        kUnix     = 3,
 389.202 +        kVM_CMS   = 4,
 389.203 +        kAtari    = 5,  // what if it's a minix filesystem? [cjh]
 389.204 +        kHPFS     = 6,  // filesystem used by OS/2 (and NT 3.x)
 389.205 +        kMac      = 7,
 389.206 +        kZ_System = 8,
 389.207 +        kCPM      = 9,
 389.208 +        kTOPS20   = 10, // pkzip 2.50 NTFS
 389.209 +        kNTFS     = 11, // filesystem used by Windows NT
 389.210 +        kQDOS     = 12, // SMS/QDOS
 389.211 +        kAcorn    = 13, // Archimedes Acorn RISC OS
 389.212 +        kVFAT     = 14, // filesystem used by Windows 95, NT
 389.213 +        kMVS      = 15,
 389.214 +        kBeOS     = 16, // hybrid POSIX/database filesystem
 389.215 +        kTandem   = 17,
 389.216 +        kOS400    = 18,
 389.217 +        kOSX      = 19
 389.218 +    };
 389.219 +  }
 389.220 +  namespace NUnixAttribute
 389.221 +  {
 389.222 +    const UInt32 kIFMT   =   0170000;     /* Unix file type mask */
 389.223 +    
 389.224 +    const UInt32 kIFDIR  =   0040000;     /* Unix directory */
 389.225 +    const UInt32 kIFREG  =   0100000;     /* Unix regular file */
 389.226 +    const UInt32 kIFSOCK =   0140000;     /* Unix socket (BSD, not SysV or Amiga) */
 389.227 +    const UInt32 kIFLNK  =   0120000;     /* Unix symbolic link (not SysV, Amiga) */
 389.228 +    const UInt32 kIFBLK  =   0060000;     /* Unix block special       (not Amiga) */
 389.229 +    const UInt32 kIFCHR  =   0020000;     /* Unix character special   (not Amiga) */
 389.230 +    const UInt32 kIFIFO  =   0010000;     /* Unix fifo    (BCC, not MSC or Amiga) */
 389.231 +    
 389.232 +    const UInt32 kISUID  =   04000;       /* Unix set user id on execution */
 389.233 +    const UInt32 kISGID  =   02000;       /* Unix set group id on execution */
 389.234 +    const UInt32 kISVTX  =   01000;       /* Unix directory permissions control */
 389.235 +    const UInt32 kENFMT  =   kISGID;   /* Unix record locking enforcement flag */
 389.236 +    const UInt32 kIRWXU  =   00700;       /* Unix read, write, execute: owner */
 389.237 +    const UInt32 kIRUSR  =   00400;       /* Unix read permission: owner */
 389.238 +    const UInt32 kIWUSR  =   00200;       /* Unix write permission: owner */
 389.239 +    const UInt32 kIXUSR  =   00100;       /* Unix execute permission: owner */
 389.240 +    const UInt32 kIRWXG  =   00070;       /* Unix read, write, execute: group */
 389.241 +    const UInt32 kIRGRP  =   00040;       /* Unix read permission: group */
 389.242 +    const UInt32 kIWGRP  =   00020;       /* Unix write permission: group */
 389.243 +    const UInt32 kIXGRP  =   00010;       /* Unix execute permission: group */
 389.244 +    const UInt32 kIRWXO  =   00007;       /* Unix read, write, execute: other */
 389.245 +    const UInt32 kIROTH  =   00004;       /* Unix read permission: other */
 389.246 +    const UInt32 kIWOTH  =   00002;       /* Unix write permission: other */
 389.247 +    const UInt32 kIXOTH  =   00001;       /* Unix execute permission: other */
 389.248 +  }
 389.249 +  
 389.250 +  namespace NAmigaAttribute
 389.251 +  {
 389.252 +    const UInt32 kIFMT     = 06000;       /* Amiga file type mask */
 389.253 +    const UInt32 kIFDIR    = 04000;       /* Amiga directory */
 389.254 +    const UInt32 kIFREG    = 02000;       /* Amiga regular file */
 389.255 +    const UInt32 kIHIDDEN  = 00200;       /* to be supported in AmigaDOS 3.x */
 389.256 +    const UInt32 kISCRIPT  = 00100;       /* executable script (text command file) */
 389.257 +    const UInt32 kIPURE    = 00040;       /* allow loading into resident memory */
 389.258 +    const UInt32 kIARCHIVE = 00020;       /* not modified since bit was last set */
 389.259 +    const UInt32 kIREAD    = 00010;       /* can be opened for reading */
 389.260 +    const UInt32 kIWRITE   = 00004;       /* can be opened for writing */
 389.261 +    const UInt32 kIEXECUTE = 00002;       /* executable image, a loadable runfile */
 389.262 +    const UInt32 kIDELETE  = 00001;      /* can be deleted */
 389.263 +  }
 389.264 +}
 389.265 +
 389.266 +}}
 389.267 +
 389.268 +#endif
   390.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   390.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipIn.cpp	Sat Mar 03 10:31:27 2012 -0600
   390.3 @@ -0,0 +1,868 @@
   390.4 +// Archive/ZipIn.cpp
   390.5 +
   390.6 +#include "StdAfx.h"
   390.7 +
   390.8 +#include "ZipIn.h"
   390.9 +#include "Windows/Defs.h"
  390.10 +#include "Common/StringConvert.h"
  390.11 +#include "Common/DynamicBuffer.h"
  390.12 +#include "../../Common/LimitedStreams.h"
  390.13 +#include "../../Common/StreamUtils.h"
  390.14 +
  390.15 +extern "C"
  390.16 +{
  390.17 +  #include "../../../../C/CpuArch.h"
  390.18 +}
  390.19 +
  390.20 +#define Get16(p) GetUi16(p)
  390.21 +#define Get32(p) GetUi32(p)
  390.22 +#define Get64(p) GetUi64(p)
  390.23 +
  390.24 +namespace NArchive {
  390.25 +namespace NZip {
  390.26 + 
  390.27 +// static const char kEndOfString = '\0';
  390.28 +
  390.29 +HRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
  390.30 +{
  390.31 +  Close();
  390.32 +  RINOK(stream->Seek(0, STREAM_SEEK_CUR, &m_StreamStartPosition));
  390.33 +  m_Position = m_StreamStartPosition;
  390.34 +  RINOK(FindAndReadMarker(stream, searchHeaderSizeLimit));
  390.35 +  RINOK(stream->Seek(m_Position, STREAM_SEEK_SET, NULL));
  390.36 +  m_Stream = stream;
  390.37 +  return S_OK;
  390.38 +}
  390.39 +
  390.40 +void CInArchive::Close()
  390.41 +{
  390.42 +  m_Stream.Release();
  390.43 +}
  390.44 +
  390.45 +HRESULT CInArchive::Seek(UInt64 offset)
  390.46 +{
  390.47 +  return m_Stream->Seek(offset, STREAM_SEEK_SET, NULL);
  390.48 +}
  390.49 +
  390.50 +//////////////////////////////////////
  390.51 +// Markers
  390.52 +
  390.53 +static inline bool TestMarkerCandidate(const Byte *p, UInt32 &value)
  390.54 +{
  390.55 +  value = Get32(p);
  390.56 +  return
  390.57 +    (value == NSignature::kLocalFileHeader) ||
  390.58 +    (value == NSignature::kEndOfCentralDir);
  390.59 +}
  390.60 +
  390.61 +static const UInt32 kNumMarkerAddtionalBytes = 2;
  390.62 +static inline bool TestMarkerCandidate2(const Byte *p, UInt32 &value)
  390.63 +{
  390.64 +  value = Get32(p);
  390.65 +  if (value == NSignature::kEndOfCentralDir)
  390.66 +    return (Get16(p + 4) == 0);
  390.67 +  return (value == NSignature::kLocalFileHeader && p[4] < 128);
  390.68 +}
  390.69 +
  390.70 +HRESULT CInArchive::FindAndReadMarker(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
  390.71 +{
  390.72 +  m_ArchiveInfo.Clear();
  390.73 +  m_Position = m_StreamStartPosition;
  390.74 +
  390.75 +  Byte marker[NSignature::kMarkerSize];
  390.76 +  RINOK(ReadStream_FALSE(stream, marker, NSignature::kMarkerSize));
  390.77 +  m_Position += NSignature::kMarkerSize;
  390.78 +  if (TestMarkerCandidate(marker, m_Signature))
  390.79 +    return S_OK;
  390.80 +
  390.81 +  CByteDynamicBuffer dynamicBuffer;
  390.82 +  const UInt32 kSearchMarkerBufferSize = 0x10000;
  390.83 +  dynamicBuffer.EnsureCapacity(kSearchMarkerBufferSize);
  390.84 +  Byte *buffer = dynamicBuffer;
  390.85 +  UInt32 numBytesPrev = NSignature::kMarkerSize - 1;
  390.86 +  memcpy(buffer, marker + 1, numBytesPrev);
  390.87 +  UInt64 curTestPos = m_StreamStartPosition + 1;
  390.88 +  for (;;)
  390.89 +  {
  390.90 +    if (searchHeaderSizeLimit != NULL)
  390.91 +      if (curTestPos - m_StreamStartPosition > *searchHeaderSizeLimit)
  390.92 +        break;
  390.93 +    size_t numReadBytes = kSearchMarkerBufferSize - numBytesPrev;
  390.94 +    RINOK(ReadStream(stream, buffer + numBytesPrev, &numReadBytes));
  390.95 +    m_Position += numReadBytes;
  390.96 +    UInt32 numBytesInBuffer = numBytesPrev + (UInt32)numReadBytes;
  390.97 +    const UInt32 kMarker2Size = NSignature::kMarkerSize + kNumMarkerAddtionalBytes;
  390.98 +    if (numBytesInBuffer < kMarker2Size)
  390.99 +      break;
 390.100 +    UInt32 numTests = numBytesInBuffer - kMarker2Size + 1;
 390.101 +    for (UInt32 pos = 0; pos < numTests; pos++)
 390.102 +    {
 390.103 +      if (buffer[pos] != 0x50)
 390.104 +        continue;
 390.105 +      if (TestMarkerCandidate2(buffer + pos, m_Signature))
 390.106 +      {
 390.107 +        curTestPos += pos;
 390.108 +        m_ArchiveInfo.StartPosition = curTestPos;
 390.109 +        m_Position = curTestPos + NSignature::kMarkerSize;
 390.110 +        return S_OK;
 390.111 +      }
 390.112 +    }
 390.113 +    curTestPos += numTests;
 390.114 +    numBytesPrev = numBytesInBuffer - numTests;
 390.115 +    memmove(buffer, buffer + numTests, numBytesPrev);
 390.116 +  }
 390.117 +  return S_FALSE;
 390.118 +}
 390.119 +
 390.120 +HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 *processedSize)
 390.121 +{
 390.122 +  size_t realProcessedSize = size;
 390.123 +  HRESULT result = ReadStream(m_Stream, data, &realProcessedSize);
 390.124 +  if (processedSize != NULL)
 390.125 +    *processedSize = (UInt32)realProcessedSize;
 390.126 +  m_Position += realProcessedSize;
 390.127 +  return result;
 390.128 +}
 390.129 +
 390.130 +void CInArchive::IncreaseRealPosition(UInt64 addValue)
 390.131 +{
 390.132 +  if (m_Stream->Seek(addValue, STREAM_SEEK_CUR, &m_Position) != S_OK)
 390.133 +    throw CInArchiveException(CInArchiveException::kSeekStreamError);
 390.134 +}
 390.135 +
 390.136 +bool CInArchive::ReadBytesAndTestSize(void *data, UInt32 size)
 390.137 +{
 390.138 +  UInt32 realProcessedSize;
 390.139 +  if (ReadBytes(data, size, &realProcessedSize) != S_OK)
 390.140 +    throw CInArchiveException(CInArchiveException::kReadStreamError);
 390.141 +  return (realProcessedSize == size);
 390.142 +}
 390.143 +
 390.144 +void CInArchive::SafeReadBytes(void *data, UInt32 size)
 390.145 +{
 390.146 +  if (!ReadBytesAndTestSize(data, size))
 390.147 +    throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive);
 390.148 +}
 390.149 +
 390.150 +void CInArchive::ReadBuffer(CByteBuffer &buffer, UInt32 size)
 390.151 +{
 390.152 +  buffer.SetCapacity(size);
 390.153 +  if (size > 0)
 390.154 +    SafeReadBytes(buffer, size);
 390.155 +}
 390.156 +
 390.157 +Byte CInArchive::ReadByte()
 390.158 +{
 390.159 +  Byte b;
 390.160 +  SafeReadBytes(&b, 1);
 390.161 +  return b;
 390.162 +}
 390.163 +
 390.164 +UInt16 CInArchive::ReadUInt16()
 390.165 +{
 390.166 +  UInt16 value = 0;
 390.167 +  for (int i = 0; i < 2; i++)
 390.168 +    value |= (((UInt16)ReadByte()) << (8 * i));
 390.169 +  return value;
 390.170 +}
 390.171 +
 390.172 +UInt32 CInArchive::ReadUInt32()
 390.173 +{
 390.174 +  UInt32 value = 0;
 390.175 +  for (int i = 0; i < 4; i++)
 390.176 +    value |= (((UInt32)ReadByte()) << (8 * i));
 390.177 +  return value;
 390.178 +}
 390.179 +
 390.180 +UInt64 CInArchive::ReadUInt64()
 390.181 +{
 390.182 +  UInt64 value = 0;
 390.183 +  for (int i = 0; i < 8; i++)
 390.184 +    value |= (((UInt64)ReadByte()) << (8 * i));
 390.185 +  return value;
 390.186 +}
 390.187 +
 390.188 +bool CInArchive::ReadUInt32(UInt32 &value)
 390.189 +{
 390.190 +  value = 0;
 390.191 +  for (int i = 0; i < 4; i++)
 390.192 +  {
 390.193 +    Byte b;
 390.194 +    if (!ReadBytesAndTestSize(&b, 1))
 390.195 +      return false;
 390.196 +    value |= (UInt32(b) << (8 * i));
 390.197 +  }
 390.198 +  return true;
 390.199 +}
 390.200 +
 390.201 +
 390.202 +AString CInArchive::ReadFileName(UInt32 nameSize)
 390.203 +{
 390.204 +  if (nameSize == 0)
 390.205 +    return AString();
 390.206 +  char *p = m_NameBuffer.GetBuffer(nameSize);
 390.207 +  SafeReadBytes(p, nameSize);
 390.208 +  p[nameSize] = 0;
 390.209 +  m_NameBuffer.ReleaseBuffer();
 390.210 +  return m_NameBuffer;
 390.211 +}
 390.212 +
 390.213 +void CInArchive::GetArchiveInfo(CInArchiveInfo &archiveInfo) const
 390.214 +{
 390.215 +  archiveInfo = m_ArchiveInfo;
 390.216 +}
 390.217 +
 390.218 +/*
 390.219 +void CInArchive::ThrowIncorrectArchiveException()
 390.220 +{
 390.221 +  throw CInArchiveException(CInArchiveException::kIncorrectArchive);
 390.222 +}
 390.223 +*/
 390.224 +
 390.225 +static UInt32 GetUInt32(const Byte *data)
 390.226 +{
 390.227 +  return
 390.228 +      ((UInt32)(Byte)data[0]) |
 390.229 +      (((UInt32)(Byte)data[1]) << 8) |
 390.230 +      (((UInt32)(Byte)data[2]) << 16) |
 390.231 +      (((UInt32)(Byte)data[3]) << 24);
 390.232 +}
 390.233 +
 390.234 +/*
 390.235 +static UInt16 GetUInt16(const Byte *data)
 390.236 +{
 390.237 +  return
 390.238 +      ((UInt16)(Byte)data[0]) |
 390.239 +      (((UInt16)(Byte)data[1]) << 8);
 390.240 +}
 390.241 +*/
 390.242 +
 390.243 +static UInt64 GetUInt64(const Byte *data)
 390.244 +{
 390.245 +  return GetUInt32(data) | ((UInt64)GetUInt32(data + 4) << 32);
 390.246 +}
 390.247 +
 390.248 +
 390.249 +
 390.250 +void CInArchive::ReadExtra(UInt32 extraSize, CExtraBlock &extraBlock,
 390.251 +    UInt64 &unpackSize, UInt64 &packSize, UInt64 &localHeaderOffset, UInt32 &diskStartNumber)
 390.252 +{
 390.253 +  extraBlock.Clear();
 390.254 +  UInt32 remain = extraSize;
 390.255 +  while(remain >= 4)
 390.256 +  {
 390.257 +    CExtraSubBlock subBlock;
 390.258 +    subBlock.ID = ReadUInt16();
 390.259 +    UInt32 dataSize = ReadUInt16();
 390.260 +    remain -= 4;
 390.261 +    if (dataSize > remain) // it's bug
 390.262 +      dataSize = remain;
 390.263 +    if (subBlock.ID == NFileHeader::NExtraID::kZip64)
 390.264 +    {
 390.265 +      if (unpackSize == 0xFFFFFFFF)
 390.266 +      {
 390.267 +        if (dataSize < 8)
 390.268 +          break;
 390.269 +        unpackSize = ReadUInt64();
 390.270 +        remain -= 8;
 390.271 +        dataSize -= 8;
 390.272 +      }
 390.273 +      if (packSize == 0xFFFFFFFF)
 390.274 +      {
 390.275 +        if (dataSize < 8)
 390.276 +          break;
 390.277 +        packSize = ReadUInt64();
 390.278 +        remain -= 8;
 390.279 +        dataSize -= 8;
 390.280 +      }
 390.281 +      if (localHeaderOffset == 0xFFFFFFFF)
 390.282 +      {
 390.283 +        if (dataSize < 8)
 390.284 +          break;
 390.285 +        localHeaderOffset = ReadUInt64();
 390.286 +        remain -= 8;
 390.287 +        dataSize -= 8;
 390.288 +      }
 390.289 +      if (diskStartNumber == 0xFFFF)
 390.290 +      {
 390.291 +        if (dataSize < 4)
 390.292 +          break;
 390.293 +        diskStartNumber = ReadUInt32();
 390.294 +        remain -= 4;
 390.295 +        dataSize -= 4;
 390.296 +      }
 390.297 +      for (UInt32 i = 0; i < dataSize; i++)
 390.298 +        ReadByte();
 390.299 +    }
 390.300 +    else
 390.301 +    {
 390.302 +      ReadBuffer(subBlock.Data, dataSize);
 390.303 +      extraBlock.SubBlocks.Add(subBlock);
 390.304 +    }
 390.305 +    remain -= dataSize;
 390.306 +  }
 390.307 +  IncreaseRealPosition(remain);
 390.308 +}
 390.309 +
 390.310 +HRESULT CInArchive::ReadLocalItem(CItemEx &item)
 390.311 +{
 390.312 +  item.ExtractVersion.Version = ReadByte();
 390.313 +  item.ExtractVersion.HostOS = ReadByte();
 390.314 +  item.Flags = ReadUInt16();
 390.315 +  item.CompressionMethod = ReadUInt16();
 390.316 +  item.Time =  ReadUInt32();
 390.317 +  item.FileCRC = ReadUInt32();
 390.318 +  item.PackSize = ReadUInt32();
 390.319 +  item.UnPackSize = ReadUInt32();
 390.320 +  UInt32 fileNameSize = ReadUInt16();
 390.321 +  item.LocalExtraSize = ReadUInt16();
 390.322 +  item.Name = ReadFileName(fileNameSize);
 390.323 +  item.FileHeaderWithNameSize = 4 + NFileHeader::kLocalBlockSize + fileNameSize;
 390.324 +  if (item.LocalExtraSize > 0)
 390.325 +  {
 390.326 +    UInt64 localHeaderOffset = 0;
 390.327 +    UInt32 diskStartNumber = 0;
 390.328 +    ReadExtra(item.LocalExtraSize, item.LocalExtra, item.UnPackSize, item.PackSize,
 390.329 +      localHeaderOffset, diskStartNumber);
 390.330 +  }
 390.331 +  /*
 390.332 +  if (item.IsDir())
 390.333 +    item.UnPackSize = 0;       // check It
 390.334 +  */
 390.335 +  return S_OK;
 390.336 +}
 390.337 +
 390.338 +HRESULT CInArchive::ReadLocalItemAfterCdItem(CItemEx &item)
 390.339 +{
 390.340 +  if (item.FromLocal)
 390.341 +    return S_OK;
 390.342 +  try
 390.343 +  {
 390.344 +    RINOK(Seek(m_ArchiveInfo.Base + item.LocalHeaderPosition));
 390.345 +    CItemEx localItem;
 390.346 +    if (ReadUInt32() != NSignature::kLocalFileHeader)
 390.347 +      return S_FALSE;
 390.348 +    RINOK(ReadLocalItem(localItem));
 390.349 +    if (item.Flags != localItem.Flags)
 390.350 +    {
 390.351 +      if (
 390.352 +          (item.CompressionMethod != NFileHeader::NCompressionMethod::kDeflated ||
 390.353 +            (item.Flags & 0x7FF9) != (localItem.Flags & 0x7FF9)) &&
 390.354 +          (item.CompressionMethod != NFileHeader::NCompressionMethod::kStored ||
 390.355 +            (item.Flags & 0x7FFF) != (localItem.Flags & 0x7FFF)) &&
 390.356 +          (item.CompressionMethod != NFileHeader::NCompressionMethod::kImploded ||
 390.357 +            (item.Flags & 0x7FFF) != (localItem.Flags & 0x7FFF))
 390.358 +        )
 390.359 +        return S_FALSE;
 390.360 +    }
 390.361 +
 390.362 +    if (item.CompressionMethod != localItem.CompressionMethod ||
 390.363 +        // item.Time != localItem.Time ||
 390.364 +        (!localItem.HasDescriptor() &&
 390.365 +          (
 390.366 +            item.FileCRC != localItem.FileCRC ||
 390.367 +            item.PackSize != localItem.PackSize ||
 390.368 +            item.UnPackSize != localItem.UnPackSize
 390.369 +          )
 390.370 +        ) ||
 390.371 +        item.Name.Length() != localItem.Name.Length()
 390.372 +        )
 390.373 +      return S_FALSE;
 390.374 +    item.FileHeaderWithNameSize = localItem.FileHeaderWithNameSize;
 390.375 +    item.LocalExtraSize = localItem.LocalExtraSize;
 390.376 +    item.LocalExtra = localItem.LocalExtra;
 390.377 +    item.FromLocal = true;
 390.378 +  }
 390.379 +  catch(...) { return S_FALSE; }
 390.380 +  return S_OK;
 390.381 +}
 390.382 +
 390.383 +HRESULT CInArchive::ReadLocalItemDescriptor(CItemEx &item)
 390.384 +{
 390.385 +  if (item.HasDescriptor())
 390.386 +  {
 390.387 +    const int kBufferSize = (1 << 12);
 390.388 +    Byte buffer[kBufferSize];
 390.389 +    
 390.390 +    UInt32 numBytesInBuffer = 0;
 390.391 +    UInt32 packedSize = 0;
 390.392 +    
 390.393 +    bool descriptorWasFound = false;
 390.394 +    for (;;)
 390.395 +    {
 390.396 +      UInt32 processedSize;
 390.397 +      RINOK(ReadBytes(buffer + numBytesInBuffer, kBufferSize - numBytesInBuffer, &processedSize));
 390.398 +      numBytesInBuffer += processedSize;
 390.399 +      if (numBytesInBuffer < NFileHeader::kDataDescriptorSize)
 390.400 +        return S_FALSE;
 390.401 +      UInt32 i;
 390.402 +      for (i = 0; i <= numBytesInBuffer - NFileHeader::kDataDescriptorSize; i++)
 390.403 +      {
 390.404 +        // descriptorSignature field is Info-ZIP's extension
 390.405 +        // to Zip specification.
 390.406 +        UInt32 descriptorSignature = GetUInt32(buffer + i);
 390.407 +        
 390.408 +        // !!!! It must be fixed for Zip64 archives
 390.409 +        UInt32 descriptorPackSize = GetUInt32(buffer + i + 8);
 390.410 +        if (descriptorSignature== NSignature::kDataDescriptor && descriptorPackSize == packedSize + i)
 390.411 +        {
 390.412 +          descriptorWasFound = true;
 390.413 +          item.FileCRC = GetUInt32(buffer + i + 4);
 390.414 +          item.PackSize = descriptorPackSize;
 390.415 +          item.UnPackSize = GetUInt32(buffer + i + 12);
 390.416 +          IncreaseRealPosition(Int64(Int32(0 - (numBytesInBuffer - i - NFileHeader::kDataDescriptorSize))));
 390.417 +          break;
 390.418 +        }
 390.419 +      }
 390.420 +      if (descriptorWasFound)
 390.421 +        break;
 390.422 +      packedSize += i;
 390.423 +      int j;
 390.424 +      for (j = 0; i < numBytesInBuffer; i++, j++)
 390.425 +        buffer[j] = buffer[i];
 390.426 +      numBytesInBuffer = j;
 390.427 +    }
 390.428 +  }
 390.429 +  else
 390.430 +    IncreaseRealPosition(item.PackSize);
 390.431 +  return S_OK;
 390.432 +}
 390.433 +
 390.434 +HRESULT CInArchive::ReadLocalItemAfterCdItemFull(CItemEx &item)
 390.435 +{
 390.436 +  if (item.FromLocal)
 390.437 +    return S_OK;
 390.438 +  try
 390.439 +  {
 390.440 +    RINOK(ReadLocalItemAfterCdItem(item));
 390.441 +    if (item.HasDescriptor())
 390.442 +    {
 390.443 +      RINOK(Seek(m_ArchiveInfo.Base + item.GetDataPosition() + item.PackSize));
 390.444 +      if (ReadUInt32() != NSignature::kDataDescriptor)
 390.445 +        return S_FALSE;
 390.446 +      UInt32 crc = ReadUInt32();
 390.447 +      UInt64 packSize, unpackSize;
 390.448 +
 390.449 +      /*
 390.450 +      if (IsZip64)
 390.451 +      {
 390.452 +        packSize = ReadUInt64();
 390.453 +        unpackSize = ReadUInt64();
 390.454 +      }
 390.455 +      else
 390.456 +      */
 390.457 +      {
 390.458 +        packSize = ReadUInt32();
 390.459 +        unpackSize = ReadUInt32();
 390.460 +      }
 390.461 +
 390.462 +      if (crc != item.FileCRC || item.PackSize != packSize || item.UnPackSize != unpackSize)
 390.463 +        return S_FALSE;
 390.464 +    }
 390.465 +  }
 390.466 +  catch(...) { return S_FALSE; }
 390.467 +  return S_OK;
 390.468 +}
 390.469 +  
 390.470 +HRESULT CInArchive::ReadCdItem(CItemEx &item)
 390.471 +{
 390.472 +  item.FromCentral = true;
 390.473 +  const int kBufSize = 42;
 390.474 +  Byte p[kBufSize];
 390.475 +  SafeReadBytes(p, kBufSize);
 390.476 +  item.MadeByVersion.Version = p[0];
 390.477 +  item.MadeByVersion.HostOS = p[1];
 390.478 +  item.ExtractVersion.Version = p[2];
 390.479 +  item.ExtractVersion.HostOS = p[3];
 390.480 +  item.Flags = Get16(p + 4);
 390.481 +  item.CompressionMethod = Get16(p + 6);
 390.482 +  item.Time = Get32(p + 8);
 390.483 +  item.FileCRC = Get32(p + 12);
 390.484 +  item.PackSize = Get32(p + 16);
 390.485 +  item.UnPackSize = Get32(p + 20);
 390.486 +  UInt16 headerNameSize = Get16(p + 24);
 390.487 +  UInt16 headerExtraSize = Get16(p + 26);
 390.488 +  UInt16 headerCommentSize = Get16(p + 28);
 390.489 +  UInt32 headerDiskNumberStart = Get16(p + 30);
 390.490 +  item.InternalAttributes = Get16(p + 32);
 390.491 +  item.ExternalAttributes = Get32(p + 34);
 390.492 +  item.LocalHeaderPosition = Get32(p + 38);
 390.493 +  item.Name = ReadFileName(headerNameSize);
 390.494 +  
 390.495 +  if (headerExtraSize > 0)
 390.496 +  {
 390.497 +    ReadExtra(headerExtraSize, item.CentralExtra, item.UnPackSize, item.PackSize,
 390.498 +        item.LocalHeaderPosition, headerDiskNumberStart);
 390.499 +  }
 390.500 +
 390.501 +  if (headerDiskNumberStart != 0)
 390.502 +    throw CInArchiveException(CInArchiveException::kMultiVolumeArchiveAreNotSupported);
 390.503 +  
 390.504 +  // May be these strings must be deleted
 390.505 +  /*
 390.506 +  if (item.IsDir())
 390.507 +    item.UnPackSize = 0;
 390.508 +  */
 390.509 +  
 390.510 +  ReadBuffer(item.Comment, headerCommentSize);
 390.511 +  return S_OK;
 390.512 +}
 390.513 +
 390.514 +HRESULT CInArchive::TryEcd64(UInt64 offset, CCdInfo &cdInfo)
 390.515 +{
 390.516 +  RINOK(Seek(offset));
 390.517 +  const UInt32 kEcd64Size = 56;
 390.518 +  Byte buf[kEcd64Size];
 390.519 +  if (!ReadBytesAndTestSize(buf, kEcd64Size))
 390.520 +    return S_FALSE;
 390.521 +  if (GetUInt32(buf) != NSignature::kZip64EndOfCentralDir)
 390.522 +    return S_FALSE;
 390.523 +  // cdInfo.NumEntries = GetUInt64(buf + 24);
 390.524 +  cdInfo.Size = GetUInt64(buf + 40);
 390.525 +  cdInfo.Offset = GetUInt64(buf + 48);
 390.526 +  return S_OK;
 390.527 +}
 390.528 +
 390.529 +HRESULT CInArchive::FindCd(CCdInfo &cdInfo)
 390.530 +{
 390.531 +  UInt64 endPosition;
 390.532 +  RINOK(m_Stream->Seek(0, STREAM_SEEK_END, &endPosition));
 390.533 +  const UInt32 kBufSizeMax = (1 << 16) + kEcdSize + kZip64EcdLocatorSize;
 390.534 +  Byte buf[kBufSizeMax];
 390.535 +  UInt32 bufSize = (endPosition < kBufSizeMax) ? (UInt32)endPosition : kBufSizeMax;
 390.536 +  if (bufSize < kEcdSize)
 390.537 +    return S_FALSE;
 390.538 +  UInt64 startPosition = endPosition - bufSize;
 390.539 +  RINOK(m_Stream->Seek(startPosition, STREAM_SEEK_SET, &m_Position));
 390.540 +  if (m_Position != startPosition)
 390.541 +    return S_FALSE;
 390.542 +  if (!ReadBytesAndTestSize(buf, bufSize))
 390.543 +    return S_FALSE;
 390.544 +  for (int i = (int)(bufSize - kEcdSize); i >= 0; i--)
 390.545 +  {
 390.546 +    if (GetUInt32(buf + i) == NSignature::kEndOfCentralDir)
 390.547 +    {
 390.548 +      if (i >= kZip64EcdLocatorSize)
 390.549 +      {
 390.550 +        const Byte *locator = buf + i - kZip64EcdLocatorSize;
 390.551 +        if (GetUInt32(locator) == NSignature::kZip64EndOfCentralDirLocator)
 390.552 +        {
 390.553 +          UInt64 ecd64Offset = GetUInt64(locator + 8);
 390.554 +          if (TryEcd64(ecd64Offset, cdInfo) == S_OK)
 390.555 +            return S_OK;
 390.556 +          if (TryEcd64(m_ArchiveInfo.StartPosition + ecd64Offset, cdInfo) == S_OK)
 390.557 +          {
 390.558 +            m_ArchiveInfo.Base = m_ArchiveInfo.StartPosition;
 390.559 +            return S_OK;
 390.560 +          }
 390.561 +        }
 390.562 +      }
 390.563 +      if (GetUInt32(buf + i + 4) == 0)
 390.564 +      {
 390.565 +        // cdInfo.NumEntries = GetUInt16(buf + i + 10);
 390.566 +        cdInfo.Size = GetUInt32(buf + i + 12);
 390.567 +        cdInfo.Offset = GetUInt32(buf + i + 16);
 390.568 +        UInt64 curPos = endPosition - bufSize + i;
 390.569 +        UInt64 cdEnd = cdInfo.Size + cdInfo.Offset;
 390.570 +        if (curPos > cdEnd)
 390.571 +          m_ArchiveInfo.Base = curPos - cdEnd;
 390.572 +        return S_OK;
 390.573 +      }
 390.574 +    }
 390.575 +  }
 390.576 +  return S_FALSE;
 390.577 +}
 390.578 +
 390.579 +HRESULT CInArchive::TryReadCd(CObjectVector<CItemEx> &items, UInt64 cdOffset, UInt64 cdSize, CProgressVirt *progress)
 390.580 +{
 390.581 +  items.Clear();
 390.582 +  RINOK(m_Stream->Seek(cdOffset, STREAM_SEEK_SET, &m_Position));
 390.583 +  if (m_Position != cdOffset)
 390.584 +    return S_FALSE;
 390.585 +  while(m_Position - cdOffset < cdSize)
 390.586 +  {
 390.587 +    if (ReadUInt32() != NSignature::kCentralFileHeader)
 390.588 +      return S_FALSE;
 390.589 +    CItemEx cdItem;
 390.590 +    RINOK(ReadCdItem(cdItem));
 390.591 +    items.Add(cdItem);
 390.592 +    if (progress && items.Size() % 1000 == 0)
 390.593 +      RINOK(progress->SetCompleted(items.Size()));
 390.594 +  }
 390.595 +  return (m_Position - cdOffset == cdSize) ? S_OK : S_FALSE;
 390.596 +}
 390.597 +
 390.598 +HRESULT CInArchive::ReadCd(CObjectVector<CItemEx> &items, UInt64 &cdOffset, UInt64 &cdSize, CProgressVirt *progress)
 390.599 +{
 390.600 +  m_ArchiveInfo.Base = 0;
 390.601 +  CCdInfo cdInfo;
 390.602 +  RINOK(FindCd(cdInfo));
 390.603 +  HRESULT res = S_FALSE;
 390.604 +  cdSize = cdInfo.Size;
 390.605 +  cdOffset = cdInfo.Offset;
 390.606 +  res = TryReadCd(items, m_ArchiveInfo.Base + cdOffset, cdSize, progress);
 390.607 +  if (res == S_FALSE && m_ArchiveInfo.Base == 0)
 390.608 +  {
 390.609 +    res = TryReadCd(items, cdInfo.Offset + m_ArchiveInfo.StartPosition, cdSize, progress);
 390.610 +    if (res == S_OK)
 390.611 +      m_ArchiveInfo.Base = m_ArchiveInfo.StartPosition;
 390.612 +  }
 390.613 +  if (!ReadUInt32(m_Signature))
 390.614 +    return S_FALSE;
 390.615 +  return res;
 390.616 +}
 390.617 +
 390.618 +HRESULT CInArchive::ReadLocalsAndCd(CObjectVector<CItemEx> &items, CProgressVirt *progress, UInt64 &cdOffset)
 390.619 +{
 390.620 +  items.Clear();
 390.621 +  while (m_Signature == NSignature::kLocalFileHeader)
 390.622 +  {
 390.623 +    // FSeek points to next byte after signature
 390.624 +    // NFileHeader::CLocalBlock localHeader;
 390.625 +    CItemEx item;
 390.626 +    item.LocalHeaderPosition = m_Position - m_StreamStartPosition - 4; // points to signature;
 390.627 +    RINOK(ReadLocalItem(item));
 390.628 +    item.FromLocal = true;
 390.629 +    ReadLocalItemDescriptor(item);
 390.630 +    items.Add(item);
 390.631 +    if (progress && items.Size() % 100 == 0)
 390.632 +      RINOK(progress->SetCompleted(items.Size()));
 390.633 +    if (!ReadUInt32(m_Signature))
 390.634 +      break;
 390.635 +  }
 390.636 +  cdOffset = m_Position - 4;
 390.637 +  for (int i = 0; i < items.Size(); i++)
 390.638 +  {
 390.639 +    if (progress && i % 1000 == 0)
 390.640 +      RINOK(progress->SetCompleted(items.Size()));
 390.641 +    if (m_Signature != NSignature::kCentralFileHeader)
 390.642 +      return S_FALSE;
 390.643 +
 390.644 +    CItemEx cdItem;
 390.645 +    RINOK(ReadCdItem(cdItem));
 390.646 +
 390.647 +    if (i == 0)
 390.648 +    {
 390.649 +      if (cdItem.LocalHeaderPosition == 0)
 390.650 +        m_ArchiveInfo.Base = m_ArchiveInfo.StartPosition;
 390.651 +    }
 390.652 +
 390.653 +    int index;
 390.654 +    int left = 0, right = items.Size();
 390.655 +    for (;;)
 390.656 +    {
 390.657 +      if (left >= right)
 390.658 +        return S_FALSE;
 390.659 +      index = (left + right) / 2;
 390.660 +      UInt64 position = items[index].LocalHeaderPosition - m_ArchiveInfo.Base;
 390.661 +      if (cdItem.LocalHeaderPosition == position)
 390.662 +        break;
 390.663 +      if (cdItem.LocalHeaderPosition < position)
 390.664 +        right = index;
 390.665 +      else
 390.666 +        left = index + 1;
 390.667 +    }
 390.668 +    CItemEx &item = items[index];
 390.669 +    item.LocalHeaderPosition = cdItem.LocalHeaderPosition;
 390.670 +    item.MadeByVersion = cdItem.MadeByVersion;
 390.671 +    item.CentralExtra = cdItem.CentralExtra;
 390.672 +
 390.673 +    if (
 390.674 +        // item.ExtractVersion != cdItem.ExtractVersion ||
 390.675 +        item.Flags != cdItem.Flags ||
 390.676 +        item.CompressionMethod != cdItem.CompressionMethod ||
 390.677 +        // item.Time != cdItem.Time ||
 390.678 +        item.FileCRC != cdItem.FileCRC)
 390.679 +      return S_FALSE;
 390.680 +
 390.681 +    if (item.Name.Length() != cdItem.Name.Length() ||
 390.682 +        item.PackSize != cdItem.PackSize ||
 390.683 +        item.UnPackSize != cdItem.UnPackSize
 390.684 +      )
 390.685 +      return S_FALSE;
 390.686 +    item.Name = cdItem.Name;
 390.687 +    item.InternalAttributes = cdItem.InternalAttributes;
 390.688 +    item.ExternalAttributes = cdItem.ExternalAttributes;
 390.689 +    item.Comment = cdItem.Comment;
 390.690 +    item.FromCentral = cdItem.FromCentral;
 390.691 +    if (!ReadUInt32(m_Signature))
 390.692 +      return S_FALSE;
 390.693 +  }
 390.694 +  return S_OK;
 390.695 +}
 390.696 +
 390.697 +struct CEcd
 390.698 +{
 390.699 +  UInt16 thisDiskNumber;
 390.700 +  UInt16 startCDDiskNumber;
 390.701 +  UInt16 numEntriesInCDOnThisDisk;
 390.702 +  UInt16 numEntriesInCD;
 390.703 +  UInt32 cdSize;
 390.704 +  UInt32 cdStartOffset;
 390.705 +  UInt16 commentSize;
 390.706 +  void Parse(const Byte *p);
 390.707 +};
 390.708 +
 390.709 +void CEcd::Parse(const Byte *p)
 390.710 +{
 390.711 +  thisDiskNumber = Get16(p);
 390.712 +  startCDDiskNumber = Get16(p + 2);
 390.713 +  numEntriesInCDOnThisDisk = Get16(p + 4);
 390.714 +  numEntriesInCD = Get16(p + 6);
 390.715 +  cdSize = Get32(p + 8);
 390.716 +  cdStartOffset = Get32(p + 12);
 390.717 +  commentSize = Get16(p + 16);
 390.718 +}
 390.719 +
 390.720 +struct CEcd64
 390.721 +{
 390.722 +  UInt16 versionMade;
 390.723 +  UInt16 versionNeedExtract;
 390.724 +  UInt32 thisDiskNumber;
 390.725 +  UInt32 startCDDiskNumber;
 390.726 +  UInt64 numEntriesInCDOnThisDisk;
 390.727 +  UInt64 numEntriesInCD;
 390.728 +  UInt64 cdSize;
 390.729 +  UInt64 cdStartOffset;
 390.730 +  void Parse(const Byte *p);
 390.731 +  CEcd64() { memset(this, 0, sizeof(*this)); }
 390.732 +};
 390.733 +
 390.734 +void CEcd64::Parse(const Byte *p)
 390.735 +{
 390.736 +  versionMade = Get16(p);
 390.737 +  versionNeedExtract = Get16(p + 2);
 390.738 +  thisDiskNumber = Get32(p + 4);
 390.739 +  startCDDiskNumber = Get32(p + 8);
 390.740 +  numEntriesInCDOnThisDisk = Get64(p + 12);
 390.741 +  numEntriesInCD = Get64(p + 20);
 390.742 +  cdSize = Get64(p + 28);
 390.743 +  cdStartOffset = Get64(p + 36);
 390.744 +}
 390.745 +
 390.746 +#define COPY_ECD_ITEM_16(n) if (!isZip64 || ecd. n != 0xFFFF)     ecd64. n = ecd. n;
 390.747 +#define COPY_ECD_ITEM_32(n) if (!isZip64 || ecd. n != 0xFFFFFFFF) ecd64. n = ecd. n;
 390.748 +
 390.749 +HRESULT CInArchive::ReadHeaders(CObjectVector<CItemEx> &items, CProgressVirt *progress)
 390.750 +{
 390.751 +  // m_Signature must be kLocalFileHeaderSignature or
 390.752 +  // kEndOfCentralDirSignature
 390.753 +  // m_Position points to next byte after signature
 390.754 +
 390.755 +  IsZip64 = false;
 390.756 +  items.Clear();
 390.757 +
 390.758 +  UInt64 cdSize, cdStartOffset;
 390.759 +  HRESULT res = ReadCd(items, cdStartOffset, cdSize, progress);
 390.760 +  if (res != S_FALSE && res != S_OK)
 390.761 +    return res;
 390.762 +
 390.763 +  /*
 390.764 +  if (res != S_OK)
 390.765 +    return res;
 390.766 +  res = S_FALSE;
 390.767 +  */
 390.768 +
 390.769 +  if (res == S_FALSE)
 390.770 +  {
 390.771 +    m_ArchiveInfo.Base = 0;
 390.772 +    RINOK(m_Stream->Seek(m_ArchiveInfo.StartPosition, STREAM_SEEK_SET, &m_Position));
 390.773 +    if (m_Position != m_ArchiveInfo.StartPosition)
 390.774 +      return S_FALSE;
 390.775 +    if (!ReadUInt32(m_Signature))
 390.776 +      return S_FALSE;
 390.777 +    RINOK(ReadLocalsAndCd(items, progress, cdStartOffset));
 390.778 +    cdSize = (m_Position - 4) - cdStartOffset;
 390.779 +    cdStartOffset -= m_ArchiveInfo.Base;
 390.780 +  }
 390.781 +
 390.782 +  CEcd64 ecd64;
 390.783 +  bool isZip64 = false;
 390.784 +  UInt64 zip64EcdStartOffset = m_Position - 4 - m_ArchiveInfo.Base;
 390.785 +  if (m_Signature == NSignature::kZip64EndOfCentralDir)
 390.786 +  {
 390.787 +    IsZip64 = isZip64 = true;
 390.788 +    UInt64 recordSize = ReadUInt64();
 390.789 +
 390.790 +    const int kBufSize = kZip64EcdSize;
 390.791 +    Byte buf[kBufSize];
 390.792 +    SafeReadBytes(buf, kBufSize);
 390.793 +    ecd64.Parse(buf);
 390.794 +
 390.795 +    IncreaseRealPosition(recordSize - kZip64EcdSize);
 390.796 +    if (!ReadUInt32(m_Signature))
 390.797 +      return S_FALSE;
 390.798 +    if (ecd64.thisDiskNumber != 0 || ecd64.startCDDiskNumber != 0)
 390.799 +      throw CInArchiveException(CInArchiveException::kMultiVolumeArchiveAreNotSupported);
 390.800 +    if (ecd64.numEntriesInCDOnThisDisk != items.Size() ||
 390.801 +        ecd64.numEntriesInCD != items.Size() ||
 390.802 +        ecd64.cdSize != cdSize ||
 390.803 +        (ecd64.cdStartOffset != cdStartOffset &&
 390.804 +        (!items.IsEmpty())))
 390.805 +      return S_FALSE;
 390.806 +  }
 390.807 +  if (m_Signature == NSignature::kZip64EndOfCentralDirLocator)
 390.808 +  {
 390.809 +    /* UInt32 startEndCDDiskNumber = */ ReadUInt32();
 390.810 +    UInt64 endCDStartOffset = ReadUInt64();
 390.811 +    /* UInt32 numberOfDisks = */ ReadUInt32();
 390.812 +    if (zip64EcdStartOffset != endCDStartOffset)
 390.813 +      return S_FALSE;
 390.814 +    if (!ReadUInt32(m_Signature))
 390.815 +      return S_FALSE;
 390.816 +  }
 390.817 +  if (m_Signature != NSignature::kEndOfCentralDir)
 390.818 +      return S_FALSE;
 390.819 +
 390.820 +  const int kBufSize = kEcdSize - 4;
 390.821 +  Byte buf[kBufSize];
 390.822 +  SafeReadBytes(buf, kBufSize);
 390.823 +  CEcd ecd;
 390.824 +  ecd.Parse(buf);
 390.825 +
 390.826 +  COPY_ECD_ITEM_16(thisDiskNumber);
 390.827 +  COPY_ECD_ITEM_16(startCDDiskNumber);
 390.828 +  COPY_ECD_ITEM_16(numEntriesInCDOnThisDisk);
 390.829 +  COPY_ECD_ITEM_16(numEntriesInCD);
 390.830 +  COPY_ECD_ITEM_32(cdSize);
 390.831 +  COPY_ECD_ITEM_32(cdStartOffset);
 390.832 +
 390.833 +  ReadBuffer(m_ArchiveInfo.Comment, ecd.commentSize);
 390.834 +
 390.835 +  if (ecd64.thisDiskNumber != 0 || ecd64.startCDDiskNumber != 0)
 390.836 +    throw CInArchiveException(CInArchiveException::kMultiVolumeArchiveAreNotSupported);
 390.837 +  if ((UInt16)ecd64.numEntriesInCDOnThisDisk != ((UInt16)items.Size()) ||
 390.838 +      (UInt16)ecd64.numEntriesInCD != ((UInt16)items.Size()) ||
 390.839 +      (UInt32)ecd64.cdSize != (UInt32)cdSize ||
 390.840 +      ((UInt32)(ecd64.cdStartOffset) != (UInt32)cdStartOffset &&
 390.841 +        (!items.IsEmpty())))
 390.842 +      return S_FALSE;
 390.843 +  
 390.844 +  return S_OK;
 390.845 +}
 390.846 +
 390.847 +ISequentialInStream* CInArchive::CreateLimitedStream(UInt64 position, UInt64 size)
 390.848 +{
 390.849 +  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
 390.850 +  CMyComPtr<ISequentialInStream> stream(streamSpec);
 390.851 +  SeekInArchive(m_ArchiveInfo.Base + position);
 390.852 +  streamSpec->SetStream(m_Stream);
 390.853 +  streamSpec->Init(size);
 390.854 +  return stream.Detach();
 390.855 +}
 390.856 +
 390.857 +IInStream* CInArchive::CreateStream()
 390.858 +{
 390.859 +  CMyComPtr<IInStream> stream = m_Stream;
 390.860 +  return stream.Detach();
 390.861 +}
 390.862 +
 390.863 +bool CInArchive::SeekInArchive(UInt64 position)
 390.864 +{
 390.865 +  UInt64 newPosition;
 390.866 +  if (m_Stream->Seek(position, STREAM_SEEK_SET, &newPosition) != S_OK)
 390.867 +    return false;
 390.868 +  return (newPosition == position);
 390.869 +}
 390.870 +
 390.871 +}}
   391.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   391.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipIn.h	Sat Mar 03 10:31:27 2012 -0600
   391.3 @@ -0,0 +1,116 @@
   391.4 +// Archive/ZipIn.h
   391.5 +
   391.6 +#ifndef __ZIP_IN_H
   391.7 +#define __ZIP_IN_H
   391.8 +
   391.9 +#include "../../../Common/MyCom.h"
  391.10 +#include "../../IStream.h"
  391.11 +
  391.12 +#include "ZipHeader.h"
  391.13 +#include "ZipItemEx.h"
  391.14 +
  391.15 +namespace NArchive {
  391.16 +namespace NZip {
  391.17 +  
  391.18 +class CInArchiveException
  391.19 +{
  391.20 +public:
  391.21 +  enum ECauseType
  391.22 +  {
  391.23 +    kUnexpectedEndOfArchive = 0,
  391.24 +    kArchiceHeaderCRCError,
  391.25 +    kFileHeaderCRCError,
  391.26 +    kIncorrectArchive,
  391.27 +    kDataDescroptorsAreNotSupported,
  391.28 +    kMultiVolumeArchiveAreNotSupported,
  391.29 +    kReadStreamError,
  391.30 +    kSeekStreamError
  391.31 +  }
  391.32 +  Cause;
  391.33 +  CInArchiveException(ECauseType cause): Cause(cause) {}
  391.34 +};
  391.35 +
  391.36 +class CInArchiveInfo
  391.37 +{
  391.38 +public:
  391.39 +  UInt64 Base;
  391.40 +  UInt64 StartPosition;
  391.41 +  CByteBuffer Comment;
  391.42 +  CInArchiveInfo(): Base(0), StartPosition(0) {}
  391.43 +  void Clear()
  391.44 +  {
  391.45 +    Base = 0;
  391.46 +    StartPosition = 0;
  391.47 +    Comment.SetCapacity(0);
  391.48 +  }
  391.49 +};
  391.50 +
  391.51 +class CProgressVirt
  391.52 +{
  391.53 +public:
  391.54 +  STDMETHOD(SetTotal)(UInt64 numFiles) PURE;
  391.55 +  STDMETHOD(SetCompleted)(UInt64 numFiles) PURE;
  391.56 +};
  391.57 +
  391.58 +struct CCdInfo
  391.59 +{
  391.60 +  // UInt64 NumEntries;
  391.61 +  UInt64 Size;
  391.62 +  UInt64 Offset;
  391.63 +};
  391.64 +
  391.65 +class CInArchive
  391.66 +{
  391.67 +  CMyComPtr<IInStream> m_Stream;
  391.68 +  UInt32 m_Signature;
  391.69 +  UInt64 m_StreamStartPosition;
  391.70 +  UInt64 m_Position;
  391.71 +  AString m_NameBuffer;
  391.72 +  
  391.73 +  HRESULT Seek(UInt64 offset);
  391.74 +
  391.75 +  HRESULT FindAndReadMarker(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
  391.76 +  bool ReadUInt32(UInt32 &signature);
  391.77 +  AString ReadFileName(UInt32 nameSize);
  391.78 +  
  391.79 +  HRESULT ReadBytes(void *data, UInt32 size, UInt32 *processedSize);
  391.80 +  bool ReadBytesAndTestSize(void *data, UInt32 size);
  391.81 +  void SafeReadBytes(void *data, UInt32 size);
  391.82 +  void ReadBuffer(CByteBuffer &buffer, UInt32 size);
  391.83 +  Byte ReadByte();
  391.84 +  UInt16 ReadUInt16();
  391.85 +  UInt32 ReadUInt32();
  391.86 +  UInt64 ReadUInt64();
  391.87 +  
  391.88 +  void IncreaseRealPosition(UInt64 addValue);
  391.89 + 
  391.90 +  void ReadExtra(UInt32 extraSize, CExtraBlock &extraBlock,
  391.91 +      UInt64 &unpackSize, UInt64 &packSize, UInt64 &localHeaderOffset, UInt32 &diskStartNumber);
  391.92 +  HRESULT ReadLocalItem(CItemEx &item);
  391.93 +  HRESULT ReadLocalItemDescriptor(CItemEx &item);
  391.94 +  HRESULT ReadCdItem(CItemEx &item);
  391.95 +  HRESULT TryEcd64(UInt64 offset, CCdInfo &cdInfo);
  391.96 +  HRESULT FindCd(CCdInfo &cdInfo);
  391.97 +  HRESULT TryReadCd(CObjectVector<CItemEx> &items, UInt64 cdOffset, UInt64 cdSize, CProgressVirt *progress);
  391.98 +  HRESULT ReadCd(CObjectVector<CItemEx> &items, UInt64 &cdOffset, UInt64 &cdSize, CProgressVirt *progress);
  391.99 +  HRESULT ReadLocalsAndCd(CObjectVector<CItemEx> &items, CProgressVirt *progress, UInt64 &cdOffset);
 391.100 +public:
 391.101 +  CInArchiveInfo m_ArchiveInfo;
 391.102 +  bool IsZip64;
 391.103 +
 391.104 +  HRESULT ReadHeaders(CObjectVector<CItemEx> &items, CProgressVirt *progress);
 391.105 +  HRESULT ReadLocalItemAfterCdItem(CItemEx &item);
 391.106 +  HRESULT ReadLocalItemAfterCdItemFull(CItemEx &item);
 391.107 +  HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
 391.108 +  void Close();
 391.109 +  void GetArchiveInfo(CInArchiveInfo &archiveInfo) const;
 391.110 +  bool SeekInArchive(UInt64 position);
 391.111 +  ISequentialInStream *CreateLimitedStream(UInt64 position, UInt64 size);
 391.112 +  IInStream* CreateStream();
 391.113 +
 391.114 +  bool IsOpen() const { return m_Stream != NULL; }
 391.115 +};
 391.116 +  
 391.117 +}}
 391.118 +  
 391.119 +#endif
   392.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   392.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipItem.cpp	Sat Mar 03 10:31:27 2012 -0600
   392.3 @@ -0,0 +1,147 @@
   392.4 +// Archive/ZipItem.cpp
   392.5 +
   392.6 +#include "StdAfx.h"
   392.7 +
   392.8 +#include "ZipHeader.h"
   392.9 +#include "ZipItem.h"
  392.10 +#include "../Common/ItemNameUtils.h"
  392.11 +#include "../../../../C/CpuArch.h"
  392.12 +
  392.13 +namespace NArchive {
  392.14 +namespace NZip {
  392.15 +
  392.16 +bool operator==(const CVersion &v1, const CVersion &v2)
  392.17 +{
  392.18 +  return (v1.Version == v2.Version) && (v1.HostOS == v2.HostOS);
  392.19 +}
  392.20 +
  392.21 +bool operator!=(const CVersion &v1, const CVersion &v2)
  392.22 +{
  392.23 +  return !(v1 == v2);
  392.24 +}
  392.25 +
  392.26 +bool CExtraSubBlock::ExtractNtfsTime(int index, FILETIME &ft) const
  392.27 +{
  392.28 +  ft.dwHighDateTime = ft.dwLowDateTime = 0;
  392.29 +  UInt32 size = (UInt32)Data.GetCapacity();
  392.30 +  if (ID != NFileHeader::NExtraID::kNTFS || size < 32)
  392.31 +    return false;
  392.32 +  const Byte *p = (const Byte *)Data;
  392.33 +  p += 4; // for reserved
  392.34 +  size -= 4;
  392.35 +  while (size > 4)
  392.36 +  {
  392.37 +    UInt16 tag = GetUi16(p);
  392.38 +    UInt32 attrSize = GetUi16(p + 2);
  392.39 +    p += 4;
  392.40 +    size -= 4;
  392.41 +    if (attrSize > size)
  392.42 +      attrSize = size;
  392.43 +    
  392.44 +    if (tag == NFileHeader::NNtfsExtra::kTagTime && attrSize >= 24)
  392.45 +    {
  392.46 +      p += 8 * index;
  392.47 +      ft.dwLowDateTime = GetUi32(p);
  392.48 +      ft.dwHighDateTime = GetUi32(p + 4);
  392.49 +      return true;
  392.50 +    }
  392.51 +    p += attrSize;
  392.52 +    size -= attrSize;
  392.53 +  }
  392.54 +  return false;
  392.55 +}
  392.56 +
  392.57 +bool CLocalItem::IsDir() const
  392.58 +{
  392.59 +  return NItemName::HasTailSlash(Name, GetCodePage());
  392.60 +}
  392.61 +
  392.62 +bool CItem::IsDir() const
  392.63 +{
  392.64 +  if (NItemName::HasTailSlash(Name, GetCodePage()))
  392.65 +    return true;
  392.66 +  if (!FromCentral)
  392.67 +    return false;
  392.68 +  WORD highAttributes = WORD((ExternalAttributes >> 16 ) & 0xFFFF);
  392.69 +  switch(MadeByVersion.HostOS)
  392.70 +  {
  392.71 +    case NFileHeader::NHostOS::kAMIGA:
  392.72 +      switch (highAttributes & NFileHeader::NAmigaAttribute::kIFMT)
  392.73 +      {
  392.74 +        case NFileHeader::NAmigaAttribute::kIFDIR: return true;
  392.75 +        case NFileHeader::NAmigaAttribute::kIFREG: return false;
  392.76 +        default: return false; // change it throw kUnknownAttributes;
  392.77 +      }
  392.78 +    case NFileHeader::NHostOS::kFAT:
  392.79 +    case NFileHeader::NHostOS::kNTFS:
  392.80 +    case NFileHeader::NHostOS::kHPFS:
  392.81 +    case NFileHeader::NHostOS::kVFAT:
  392.82 +      return ((ExternalAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  392.83 +    case NFileHeader::NHostOS::kAtari:
  392.84 +    case NFileHeader::NHostOS::kMac:
  392.85 +    case NFileHeader::NHostOS::kVMS:
  392.86 +    case NFileHeader::NHostOS::kVM_CMS:
  392.87 +    case NFileHeader::NHostOS::kAcorn:
  392.88 +    case NFileHeader::NHostOS::kMVS:
  392.89 +      return false; // change it throw kUnknownAttributes;
  392.90 +    default:
  392.91 +      /*
  392.92 +      switch (highAttributes & NFileHeader::NUnixAttribute::kIFMT)
  392.93 +      {
  392.94 +        case NFileHeader::NUnixAttribute::kIFDIR:
  392.95 +          return true;
  392.96 +        default:
  392.97 +          return false;
  392.98 +      }
  392.99 +      */
 392.100 +      return false;
 392.101 +  }
 392.102 +}
 392.103 +
 392.104 +UInt32 CLocalItem::GetWinAttributes() const
 392.105 +{
 392.106 +  DWORD winAttributes = 0;
 392.107 +  if (IsDir())
 392.108 +    winAttributes |= FILE_ATTRIBUTE_DIRECTORY;
 392.109 +  return winAttributes;
 392.110 +}
 392.111 +
 392.112 +UInt32 CItem::GetWinAttributes() const
 392.113 +{
 392.114 +  DWORD winAttributes = 0;
 392.115 +  switch(MadeByVersion.HostOS)
 392.116 +  {
 392.117 +    case NFileHeader::NHostOS::kFAT:
 392.118 +    case NFileHeader::NHostOS::kNTFS:
 392.119 +      if (FromCentral)
 392.120 +        winAttributes = ExternalAttributes;
 392.121 +      break;
 392.122 +    default:
 392.123 +      winAttributes = 0; // must be converted from unix value;
 392.124 +  }
 392.125 +  if (IsDir())       // test it;
 392.126 +    winAttributes |= FILE_ATTRIBUTE_DIRECTORY;
 392.127 +  return winAttributes;
 392.128 +}
 392.129 +
 392.130 +void CLocalItem::SetFlagBits(int startBitNumber, int numBits, int value)
 392.131 +{
 392.132 +  UInt16 mask = (UInt16)(((1 << numBits) - 1) << startBitNumber);
 392.133 +  Flags &= ~mask;
 392.134 +  Flags |= value << startBitNumber;
 392.135 +}
 392.136 +
 392.137 +void CLocalItem::SetBitMask(int bitMask, bool enable)
 392.138 +{
 392.139 +  if(enable)
 392.140 +    Flags |= bitMask;
 392.141 +  else
 392.142 +    Flags &= ~bitMask;
 392.143 +}
 392.144 +
 392.145 +void CLocalItem::SetEncrypted(bool encrypted)
 392.146 +  { SetBitMask(NFileHeader::NFlags::kEncrypted, encrypted); }
 392.147 +void CLocalItem::SetUtf8(bool isUtf8)
 392.148 +  { SetBitMask(NFileHeader::NFlags::kUtf8, isUtf8); }
 392.149 +
 392.150 +}}
   393.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   393.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipItem.h	Sat Mar 03 10:31:27 2012 -0600
   393.3 @@ -0,0 +1,268 @@
   393.4 +// Archive/ZipItem.h
   393.5 +
   393.6 +#ifndef __ARCHIVE_ZIP_ITEM_H
   393.7 +#define __ARCHIVE_ZIP_ITEM_H
   393.8 +
   393.9 +#include "../../../Common/Types.h"
  393.10 +#include "../../../Common/MyString.h"
  393.11 +#include "../../../Common/Buffer.h"
  393.12 +#include "../../../Common/UTFConvert.h"
  393.13 +#include "../../../Common/StringConvert.h"
  393.14 +
  393.15 +#include "ZipHeader.h"
  393.16 +
  393.17 +namespace NArchive {
  393.18 +namespace NZip {
  393.19 +
  393.20 +struct CVersion
  393.21 +{
  393.22 +  Byte Version;
  393.23 +  Byte HostOS;
  393.24 +};
  393.25 +
  393.26 +bool operator==(const CVersion &v1, const CVersion &v2);
  393.27 +bool operator!=(const CVersion &v1, const CVersion &v2);
  393.28 +
  393.29 +struct CExtraSubBlock
  393.30 +{
  393.31 +  UInt16 ID;
  393.32 +  CByteBuffer Data;
  393.33 +  bool ExtractNtfsTime(int index, FILETIME &ft) const;
  393.34 +};
  393.35 +
  393.36 +struct CWzAesExtraField
  393.37 +{
  393.38 +  UInt16 VendorVersion; // 0x0001 - AE-1, 0x0002 - AE-2,
  393.39 +  // UInt16 VendorId; // "AE"
  393.40 +  Byte Strength; // 1 - 128-bit , 2 - 192-bit , 3 - 256-bit
  393.41 +  UInt16 Method;
  393.42 +
  393.43 +  CWzAesExtraField(): VendorVersion(2), Strength(3), Method(0) {}
  393.44 +
  393.45 +  bool NeedCrc() const { return (VendorVersion == 1); }
  393.46 +
  393.47 +  bool ParseFromSubBlock(const CExtraSubBlock &sb)
  393.48 +  {
  393.49 +    if (sb.ID != NFileHeader::NExtraID::kWzAES)
  393.50 +      return false;
  393.51 +    if (sb.Data.GetCapacity() < 7)
  393.52 +      return false;
  393.53 +    const Byte *p = (const Byte *)sb.Data;
  393.54 +    VendorVersion = (((UInt16)p[1]) << 8) | p[0];
  393.55 +    if (p[2] != 'A' || p[3] != 'E')
  393.56 +      return false;
  393.57 +    Strength = p[4];
  393.58 +    Method = (((UInt16)p[6]) << 16) | p[5];
  393.59 +    return true;
  393.60 +  }
  393.61 +  void SetSubBlock(CExtraSubBlock &sb) const
  393.62 +  {
  393.63 +    sb.Data.SetCapacity(7);
  393.64 +    sb.ID = NFileHeader::NExtraID::kWzAES;
  393.65 +    Byte *p = (Byte *)sb.Data;
  393.66 +    p[0] = (Byte)VendorVersion;
  393.67 +    p[1] = (Byte)(VendorVersion >> 8);
  393.68 +    p[2] = 'A';
  393.69 +    p[3] = 'E';
  393.70 +    p[4] = Strength;
  393.71 +    p[5] = (Byte)Method;
  393.72 +    p[6] = (Byte)(Method >> 8);
  393.73 +  }
  393.74 +};
  393.75 +
  393.76 +namespace NStrongCryptoFlags
  393.77 +{
  393.78 +  const UInt16 kDES = 0x6601;
  393.79 +  const UInt16 kRC2old = 0x6602;
  393.80 +  const UInt16 k3DES168 = 0x6603;
  393.81 +  const UInt16 k3DES112 = 0x6609;
  393.82 +  const UInt16 kAES128 = 0x660E;
  393.83 +  const UInt16 kAES192 = 0x660F;
  393.84 +  const UInt16 kAES256 = 0x6610;
  393.85 +  const UInt16 kRC2 = 0x6702;
  393.86 +  const UInt16 kBlowfish = 0x6720;
  393.87 +  const UInt16 kTwofish = 0x6721;
  393.88 +  const UInt16 kRC4 = 0x6801;
  393.89 +}
  393.90 +
  393.91 +struct CStrongCryptoField
  393.92 +{
  393.93 +  UInt16 Format;
  393.94 +  UInt16 AlgId;
  393.95 +  UInt16 BitLen;
  393.96 +  UInt16 Flags;
  393.97 +
  393.98 +  bool ParseFromSubBlock(const CExtraSubBlock &sb)
  393.99 +  {
 393.100 +    if (sb.ID != NFileHeader::NExtraID::kStrongEncrypt)
 393.101 +      return false;
 393.102 +    const Byte *p = (const Byte *)sb.Data;
 393.103 +    if (sb.Data.GetCapacity() < 8)
 393.104 +      return false;
 393.105 +    Format = (((UInt16)p[1]) << 8) | p[0];
 393.106 +    AlgId  = (((UInt16)p[3]) << 8) | p[2];
 393.107 +    BitLen = (((UInt16)p[5]) << 8) | p[4];
 393.108 +    Flags  = (((UInt16)p[7]) << 8) | p[6];
 393.109 +    return (Format == 2);
 393.110 +  }
 393.111 +};
 393.112 +
 393.113 +struct CExtraBlock
 393.114 +{
 393.115 +  CObjectVector<CExtraSubBlock> SubBlocks;
 393.116 +  void Clear() { SubBlocks.Clear(); }
 393.117 +  size_t GetSize() const
 393.118 +  {
 393.119 +    size_t res = 0;
 393.120 +    for (int i = 0; i < SubBlocks.Size(); i++)
 393.121 +      res += SubBlocks[i].Data.GetCapacity() + 2 + 2;
 393.122 +    return res;
 393.123 +  }
 393.124 +  bool GetWzAesField(CWzAesExtraField &aesField) const
 393.125 +  {
 393.126 +    for (int i = 0; i < SubBlocks.Size(); i++)
 393.127 +      if (aesField.ParseFromSubBlock(SubBlocks[i]))
 393.128 +        return true;
 393.129 +    return false;
 393.130 +  }
 393.131 +
 393.132 +  bool GetStrongCryptoField(CStrongCryptoField &f) const
 393.133 +  {
 393.134 +    for (int i = 0; i < SubBlocks.Size(); i++)
 393.135 +      if (f.ParseFromSubBlock(SubBlocks[i]))
 393.136 +        return true;
 393.137 +    return false;
 393.138 +  }
 393.139 +
 393.140 +  bool HasWzAesField() const
 393.141 +  {
 393.142 +    CWzAesExtraField aesField;
 393.143 +    return GetWzAesField(aesField);
 393.144 +  }
 393.145 +
 393.146 +  bool GetNtfsTime(int index, FILETIME &ft) const
 393.147 +  {
 393.148 +    for (int i = 0; i < SubBlocks.Size(); i++)
 393.149 +    {
 393.150 +      const CExtraSubBlock &sb = SubBlocks[i];
 393.151 +      if (sb.ID == NFileHeader::NExtraID::kNTFS)
 393.152 +        return sb.ExtractNtfsTime(index, ft);
 393.153 +    }
 393.154 +    return false;
 393.155 +  }
 393.156 +
 393.157 +  /*
 393.158 +  bool HasStrongCryptoField() const
 393.159 +  {
 393.160 +    CStrongCryptoField f;
 393.161 +    return GetStrongCryptoField(f);
 393.162 +  }
 393.163 +  */
 393.164 +
 393.165 +  void RemoveUnknownSubBlocks()
 393.166 +  {
 393.167 +    for (int i = SubBlocks.Size() - 1; i >= 0; i--)
 393.168 +      if (SubBlocks[i].ID != NFileHeader::NExtraID::kWzAES)
 393.169 +        SubBlocks.Delete(i);
 393.170 +  }
 393.171 +};
 393.172 +
 393.173 +
 393.174 +class CLocalItem
 393.175 +{
 393.176 +public:
 393.177 +  CVersion ExtractVersion;
 393.178 +  UInt16 Flags;
 393.179 +  UInt16 CompressionMethod;
 393.180 +  UInt32 Time;
 393.181 +  UInt32 FileCRC;
 393.182 +  UInt64 PackSize;
 393.183 +  UInt64 UnPackSize;
 393.184 +  
 393.185 +  AString Name;
 393.186 +
 393.187 +  CExtraBlock LocalExtra;
 393.188 +
 393.189 +  bool IsUtf8() const { return (Flags & NFileHeader::NFlags::kUtf8) != 0; }
 393.190 +  
 393.191 +  bool IsEncrypted() const { return (Flags & NFileHeader::NFlags::kEncrypted) != 0; }
 393.192 +  bool IsStrongEncrypted() const { return IsEncrypted() && (Flags & NFileHeader::NFlags::kStrongEncrypted) != 0; };
 393.193 +  
 393.194 +  bool IsLzmaEOS() const { return (Flags & NFileHeader::NFlags::kLzmaEOS) != 0; }
 393.195 +  
 393.196 +  bool IsDir() const;
 393.197 +  bool IgnoreItem() const { return false; }
 393.198 +  UInt32 GetWinAttributes() const;
 393.199 +  
 393.200 +  bool HasDescriptor() const  { return (Flags & NFileHeader::NFlags::kDescriptorUsedMask) != 0; }
 393.201 +
 393.202 +  UString GetUnicodeString(const AString &s) const
 393.203 +  {
 393.204 +    UString res;
 393.205 +    if (IsUtf8())
 393.206 +      if (!ConvertUTF8ToUnicode(s, res))
 393.207 +        res.Empty();
 393.208 +    if (res.IsEmpty())
 393.209 +      res = MultiByteToUnicodeString(s, GetCodePage());
 393.210 +    return res;
 393.211 +  }
 393.212 +  
 393.213 +private:
 393.214 +  void SetFlagBits(int startBitNumber, int numBits, int value);
 393.215 +  void SetBitMask(int bitMask, bool enable);
 393.216 +public:
 393.217 +  void ClearFlags() { Flags = 0; }
 393.218 +  void SetEncrypted(bool encrypted);
 393.219 +  void SetUtf8(bool isUtf8);
 393.220 +
 393.221 +  WORD GetCodePage() const { return  CP_OEMCP; }
 393.222 +};
 393.223 +
 393.224 +class CItem: public CLocalItem
 393.225 +{
 393.226 +public:
 393.227 +  CVersion MadeByVersion;
 393.228 +  UInt16 InternalAttributes;
 393.229 +  UInt32 ExternalAttributes;
 393.230 +  
 393.231 +  UInt64 LocalHeaderPosition;
 393.232 +  
 393.233 +  FILETIME NtfsMTime;
 393.234 +  FILETIME NtfsATime;
 393.235 +  FILETIME NtfsCTime;
 393.236 +
 393.237 +  CExtraBlock CentralExtra;
 393.238 +  CByteBuffer Comment;
 393.239 +
 393.240 +  bool FromLocal;
 393.241 +  bool FromCentral;
 393.242 +  bool NtfsTimeIsDefined;
 393.243 +  
 393.244 +  bool IsDir() const;
 393.245 +  UInt32 GetWinAttributes() const;
 393.246 +
 393.247 +  bool IsThereCrc() const
 393.248 +  {
 393.249 +    if (CompressionMethod == NFileHeader::NCompressionMethod::kWzAES)
 393.250 +    {
 393.251 +      CWzAesExtraField aesField;
 393.252 +      if (CentralExtra.GetWzAesField(aesField))
 393.253 +        return aesField.NeedCrc();
 393.254 +    }
 393.255 +    return (FileCRC != 0 || !IsDir());
 393.256 +  }
 393.257 +  
 393.258 +  WORD GetCodePage() const
 393.259 +  {
 393.260 +    return (WORD)((MadeByVersion.HostOS == NFileHeader::NHostOS::kFAT
 393.261 +        || MadeByVersion.HostOS == NFileHeader::NHostOS::kNTFS
 393.262 +        ) ? CP_OEMCP : CP_ACP);
 393.263 +  }
 393.264 +  CItem() : FromLocal(false), FromCentral(false), NtfsTimeIsDefined(false) {}
 393.265 +};
 393.266 +
 393.267 +}}
 393.268 +
 393.269 +#endif
 393.270 +
 393.271 +
   394.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   394.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipItemEx.h	Sat Mar 03 10:31:27 2012 -0600
   394.3 @@ -0,0 +1,34 @@
   394.4 +// Archive/ZipItemEx.h
   394.5 +
   394.6 +#ifndef __ARCHIVE_ZIP_ITEMEX_H
   394.7 +#define __ARCHIVE_ZIP_ITEMEX_H
   394.8 +
   394.9 +#include "ZipHeader.h"
  394.10 +#include "ZipItem.h"
  394.11 +
  394.12 +namespace NArchive {
  394.13 +namespace NZip {
  394.14 +  
  394.15 +class CItemEx: public CItem
  394.16 +{
  394.17 +public:
  394.18 +  UInt32 FileHeaderWithNameSize;
  394.19 +  UInt16 LocalExtraSize;
  394.20 +  
  394.21 +  UInt64 GetLocalFullSize() const
  394.22 +    { return FileHeaderWithNameSize + LocalExtraSize + PackSize +
  394.23 +      (HasDescriptor() ? NFileHeader::kDataDescriptorSize : 0); };
  394.24 +  /*
  394.25 +  UInt64 GetLocalFullSize(bool isZip64) const
  394.26 +    { return FileHeaderWithNameSize + LocalExtraSize + PackSize +
  394.27 +    (HasDescriptor() ? (isZip64 ? NFileHeader::kDataDescriptor64Size : NFileHeader::kDataDescriptorSize) : 0); };
  394.28 +  */
  394.29 +  UInt64 GetLocalExtraPosition() const
  394.30 +    { return LocalHeaderPosition + FileHeaderWithNameSize; };
  394.31 +  UInt64 GetDataPosition() const
  394.32 +    { return GetLocalExtraPosition() + LocalExtraSize; };
  394.33 +};
  394.34 +
  394.35 +}}
  394.36 +
  394.37 +#endif
   395.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   395.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   395.3 @@ -0,0 +1,21 @@
   395.4 +// ZipRegister.cpp
   395.5 +
   395.6 +#include "StdAfx.h"
   395.7 +
   395.8 +#include "../../Common/RegisterArc.h"
   395.9 +
  395.10 +#include "ZipHandler.h"
  395.11 +static IInArchive *CreateArc() { return new NArchive::NZip::CHandler;  }
  395.12 +#ifndef EXTRACT_ONLY
  395.13 +static IOutArchive *CreateArcOut() { return new NArchive::NZip::CHandler;  }
  395.14 +#else
  395.15 +#define CreateArcOut 0
  395.16 +#endif
  395.17 +
  395.18 +static CArcInfo g_ArcInfo  = { L"Zip", L"zip jar xpi zsg", 0, 1, { 0x50, 0x4B, 0x03, 0x04 }, 4, false, CreateArc, CreateArcOut };
  395.19 +static CArcInfo g_ArcInfo2 = { L"Zip", L"zip jar xpi zsg", 0, 1, { 0x50, 0x4B, 0x01, 0x02 }, 4, false, CreateArc, CreateArcOut };
  395.20 +static CArcInfo g_ArcInfo3 = { L"Zip", L"zip jar xpi zsg", 0, 1, { 0x50, 0x4B, 0x05, 0x06 }, 4, false, CreateArc, CreateArcOut };
  395.21 +
  395.22 +REGISTER_ARC(Zip)
  395.23 +REGISTER_ARCN(Zip,2)
  395.24 +REGISTER_ARCN(Zip,3)
   396.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   396.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/CreateCoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   396.3 @@ -0,0 +1,292 @@
   396.4 +// CreateCoder.cpp
   396.5 +
   396.6 +#include "StdAfx.h"
   396.7 +
   396.8 +#include "CreateCoder.h"
   396.9 +
  396.10 +#include "../../Windows/PropVariant.h"
  396.11 +#include "../../Windows/Defs.h"
  396.12 +#include "FilterCoder.h"
  396.13 +#include "RegisterCodec.h"
  396.14 +
  396.15 +static const unsigned int kNumCodecsMax = 64;
  396.16 +unsigned int g_NumCodecs = 0;
  396.17 +const CCodecInfo *g_Codecs[kNumCodecsMax];
  396.18 +void RegisterCodec(const CCodecInfo *codecInfo)
  396.19 +{
  396.20 +  if (g_NumCodecs < kNumCodecsMax)
  396.21 +    g_Codecs[g_NumCodecs++] = codecInfo;
  396.22 +}
  396.23 +
  396.24 +#ifdef EXTERNAL_CODECS
  396.25 +static HRESULT ReadNumberOfStreams(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, UInt32 &res)
  396.26 +{
  396.27 +  NWindows::NCOM::CPropVariant prop;
  396.28 +  RINOK(codecsInfo->GetProperty(index, propID, &prop));
  396.29 +  if (prop.vt == VT_EMPTY)
  396.30 +    res = 1;
  396.31 +  else if (prop.vt == VT_UI4)
  396.32 +    res = prop.ulVal;
  396.33 +  else
  396.34 +    return E_INVALIDARG;
  396.35 +  return S_OK;
  396.36 +}
  396.37 +
  396.38 +static HRESULT ReadIsAssignedProp(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, bool &res)
  396.39 +{
  396.40 +  NWindows::NCOM::CPropVariant prop;
  396.41 +  RINOK(codecsInfo->GetProperty(index, propID, &prop));
  396.42 +  if (prop.vt == VT_EMPTY)
  396.43 +    res = true;
  396.44 +  else if (prop.vt == VT_BOOL)
  396.45 +    res = VARIANT_BOOLToBool(prop.boolVal);
  396.46 +  else
  396.47 +    return E_INVALIDARG;
  396.48 +  return S_OK;
  396.49 +}
  396.50 +
  396.51 +HRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs)
  396.52 +{
  396.53 +  UInt32 num;
  396.54 +  RINOK(codecsInfo->GetNumberOfMethods(&num));
  396.55 +  for (UInt32 i = 0; i < num; i++)
  396.56 +  {
  396.57 +    CCodecInfoEx info;
  396.58 +    NWindows::NCOM::CPropVariant prop;
  396.59 +    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kID, &prop));
  396.60 +    // if (prop.vt != VT_BSTR)
  396.61 +    // info.Id.IDSize = (Byte)SysStringByteLen(prop.bstrVal);
  396.62 +    // memmove(info.Id.ID, prop.bstrVal, info.Id.IDSize);
  396.63 +    if (prop.vt != VT_UI8)
  396.64 +    {
  396.65 +      continue; // old Interface
  396.66 +      // return E_INVALIDARG;
  396.67 +    }
  396.68 +    info.Id = prop.uhVal.QuadPart;
  396.69 +    prop.Clear();
  396.70 +    
  396.71 +    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kName, &prop));
  396.72 +    if (prop.vt == VT_BSTR)
  396.73 +      info.Name = prop.bstrVal;
  396.74 +    else if (prop.vt != VT_EMPTY)
  396.75 +      return E_INVALIDARG;;
  396.76 +    
  396.77 +    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kInStreams, info.NumInStreams));
  396.78 +    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kOutStreams, info.NumOutStreams));
  396.79 +    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kEncoderIsAssigned, info.EncoderIsAssigned));
  396.80 +    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kDecoderIsAssigned, info.DecoderIsAssigned));
  396.81 +    
  396.82 +    externalCodecs.Add(info);
  396.83 +  }
  396.84 +  return S_OK;
  396.85 +}
  396.86 +
  396.87 +#endif
  396.88 +
  396.89 +bool FindMethod(
  396.90 +  #ifdef EXTERNAL_CODECS
  396.91 +  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,
  396.92 +  #endif
  396.93 +  const UString &name,
  396.94 +  CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams)
  396.95 +{
  396.96 +  UInt32 i;
  396.97 +  for (i = 0; i < g_NumCodecs; i++)
  396.98 +  {
  396.99 +    const CCodecInfo &codec = *g_Codecs[i];
 396.100 +    if (name.CompareNoCase(codec.Name) == 0)
 396.101 +    {
 396.102 +      methodId = codec.Id;
 396.103 +      numInStreams = codec.NumInStreams;
 396.104 +      numOutStreams = 1;
 396.105 +      return true;
 396.106 +    }
 396.107 +  }
 396.108 +  #ifdef EXTERNAL_CODECS
 396.109 +  if (externalCodecs)
 396.110 +    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)
 396.111 +    {
 396.112 +      const CCodecInfoEx &codec = (*externalCodecs)[i];
 396.113 +      if (codec.Name.CompareNoCase(name) == 0)
 396.114 +      {
 396.115 +        methodId = codec.Id;
 396.116 +        numInStreams = codec.NumInStreams;
 396.117 +        numOutStreams = codec.NumOutStreams;
 396.118 +        return true;
 396.119 +      }
 396.120 +    }
 396.121 +  #endif
 396.122 +  return false;
 396.123 +}
 396.124 +
 396.125 +bool FindMethod(
 396.126 +  #ifdef EXTERNAL_CODECS
 396.127 +  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,
 396.128 +  #endif
 396.129 +  CMethodId methodId, UString &name)
 396.130 +{
 396.131 +  UInt32 i;
 396.132 +  for (i = 0; i < g_NumCodecs; i++)
 396.133 +  {
 396.134 +    const CCodecInfo &codec = *g_Codecs[i];
 396.135 +    if (methodId == codec.Id)
 396.136 +    {
 396.137 +      name = codec.Name;
 396.138 +      return true;
 396.139 +    }
 396.140 +  }
 396.141 +  #ifdef EXTERNAL_CODECS
 396.142 +  if (externalCodecs)
 396.143 +    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)
 396.144 +    {
 396.145 +      const CCodecInfoEx &codec = (*externalCodecs)[i];
 396.146 +      if (methodId == codec.Id)
 396.147 +      {
 396.148 +        name = codec.Name;
 396.149 +        return true;
 396.150 +      }
 396.151 +    }
 396.152 +  #endif
 396.153 +  return false;
 396.154 +}
 396.155 +
 396.156 +HRESULT CreateCoder(
 396.157 +  DECL_EXTERNAL_CODECS_LOC_VARS
 396.158 +  CMethodId methodId,
 396.159 +  CMyComPtr<ICompressFilter> &filter,
 396.160 +  CMyComPtr<ICompressCoder> &coder,
 396.161 +  CMyComPtr<ICompressCoder2> &coder2,
 396.162 +  bool encode, bool onlyCoder)
 396.163 +{
 396.164 +  bool created = false;
 396.165 +  UInt32 i;
 396.166 +  for (i = 0; i < g_NumCodecs; i++)
 396.167 +  {
 396.168 +    const CCodecInfo &codec = *g_Codecs[i];
 396.169 +    if (codec.Id == methodId)
 396.170 +    {
 396.171 +      if (encode)
 396.172 +      {
 396.173 +        if (codec.CreateEncoder)
 396.174 +        {
 396.175 +          void *p = codec.CreateEncoder();
 396.176 +          if (codec.IsFilter) filter = (ICompressFilter *)p;
 396.177 +          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;
 396.178 +          else coder2 = (ICompressCoder2 *)p;
 396.179 +          created = (p != 0);
 396.180 +          break;
 396.181 +        }
 396.182 +      }
 396.183 +      else
 396.184 +        if (codec.CreateDecoder)
 396.185 +        {
 396.186 +          void *p = codec.CreateDecoder();
 396.187 +          if (codec.IsFilter) filter = (ICompressFilter *)p;
 396.188 +          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;
 396.189 +          else coder2 = (ICompressCoder2 *)p;
 396.190 +          created = (p != 0);
 396.191 +          break;
 396.192 +        }
 396.193 +    }
 396.194 +  }
 396.195 +
 396.196 +  #ifdef EXTERNAL_CODECS
 396.197 +  if (!created && externalCodecs)
 396.198 +    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)
 396.199 +    {
 396.200 +      const CCodecInfoEx &codec = (*externalCodecs)[i];
 396.201 +      if (codec.Id == methodId)
 396.202 +      {
 396.203 +        if (encode)
 396.204 +        {
 396.205 +          if (codec.EncoderIsAssigned)
 396.206 +          {
 396.207 +            if (codec.IsSimpleCodec())
 396.208 +            {
 396.209 +              HRESULT result = codecsInfo->CreateEncoder(i, &IID_ICompressCoder, (void **)&coder);
 396.210 +              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)
 396.211 +                return result;
 396.212 +              if (!coder)
 396.213 +              {
 396.214 +                RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressFilter, (void **)&filter));
 396.215 +              }
 396.216 +            }
 396.217 +            else
 396.218 +            {
 396.219 +              RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressCoder2, (void **)&coder2));
 396.220 +            }
 396.221 +            break;
 396.222 +          }
 396.223 +        }
 396.224 +        else
 396.225 +          if (codec.DecoderIsAssigned)
 396.226 +          {
 396.227 +            if (codec.IsSimpleCodec())
 396.228 +            {
 396.229 +              HRESULT result = codecsInfo->CreateDecoder(i, &IID_ICompressCoder, (void **)&coder);
 396.230 +              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)
 396.231 +                return result;
 396.232 +              if (!coder)
 396.233 +              {
 396.234 +                RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressFilter, (void **)&filter));
 396.235 +              }
 396.236 +            }
 396.237 +            else
 396.238 +            {
 396.239 +              RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressCoder2, (void **)&coder2));
 396.240 +            }
 396.241 +            break;
 396.242 +          }
 396.243 +      }
 396.244 +    }
 396.245 +  #endif
 396.246 +
 396.247 +  if (onlyCoder && filter)
 396.248 +  {
 396.249 +    CFilterCoder *coderSpec = new CFilterCoder;
 396.250 +    coder = coderSpec;
 396.251 +    coderSpec->Filter = filter;
 396.252 +  }
 396.253 +  return S_OK;
 396.254 +}
 396.255 +
 396.256 +HRESULT CreateCoder(
 396.257 +  DECL_EXTERNAL_CODECS_LOC_VARS
 396.258 +  CMethodId methodId,
 396.259 +  CMyComPtr<ICompressCoder> &coder,
 396.260 +  CMyComPtr<ICompressCoder2> &coder2,
 396.261 +  bool encode)
 396.262 +{
 396.263 +  CMyComPtr<ICompressFilter> filter;
 396.264 +  return CreateCoder(
 396.265 +    EXTERNAL_CODECS_LOC_VARS
 396.266 +    methodId,
 396.267 +    filter, coder, coder2, encode, true);
 396.268 +}
 396.269 +
 396.270 +HRESULT CreateCoder(
 396.271 +  DECL_EXTERNAL_CODECS_LOC_VARS
 396.272 +  CMethodId methodId,
 396.273 +  CMyComPtr<ICompressCoder> &coder, bool encode)
 396.274 +{
 396.275 +  CMyComPtr<ICompressFilter> filter;
 396.276 +  CMyComPtr<ICompressCoder2> coder2;
 396.277 +  return CreateCoder(
 396.278 +    EXTERNAL_CODECS_LOC_VARS
 396.279 +    methodId,
 396.280 +    coder, coder2, encode);
 396.281 +}
 396.282 +
 396.283 +HRESULT CreateFilter(
 396.284 +  DECL_EXTERNAL_CODECS_LOC_VARS
 396.285 +  CMethodId methodId,
 396.286 +  CMyComPtr<ICompressFilter> &filter,
 396.287 +  bool encode)
 396.288 +{
 396.289 +  CMyComPtr<ICompressCoder> coder;
 396.290 +  CMyComPtr<ICompressCoder2> coder2;
 396.291 +  return CreateCoder(
 396.292 +    EXTERNAL_CODECS_LOC_VARS
 396.293 +    methodId,
 396.294 +    filter, coder, coder2, encode, false);
 396.295 +}
   397.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   397.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/CreateCoder.h	Sat Mar 03 10:31:27 2012 -0600
   397.3 @@ -0,0 +1,98 @@
   397.4 +// CreateCoder.h
   397.5 +
   397.6 +#ifndef __CREATECODER_H
   397.7 +#define __CREATECODER_H
   397.8 +
   397.9 +#include "../../Common/MyCom.h"
  397.10 +#include "../../Common/MyString.h"
  397.11 +#include "../ICoder.h"
  397.12 +
  397.13 +#include "MethodId.h"
  397.14 +
  397.15 +#ifdef EXTERNAL_CODECS
  397.16 +
  397.17 +struct CCodecInfoEx
  397.18 +{
  397.19 +  UString Name;
  397.20 +  CMethodId Id;
  397.21 +  UInt32 NumInStreams;
  397.22 +  UInt32 NumOutStreams;
  397.23 +  bool EncoderIsAssigned;
  397.24 +  bool DecoderIsAssigned;
  397.25 +  bool IsSimpleCodec() const { return NumOutStreams == 1 && NumInStreams == 1; }
  397.26 +  CCodecInfoEx(): EncoderIsAssigned(false), DecoderIsAssigned(false) {}
  397.27 +};
  397.28 +
  397.29 +HRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs);
  397.30 +
  397.31 +#define PUBLIC_ISetCompressCodecsInfo public ISetCompressCodecsInfo,
  397.32 +#define QUERY_ENTRY_ISetCompressCodecsInfo MY_QUERYINTERFACE_ENTRY(ISetCompressCodecsInfo)
  397.33 +#define DECL_ISetCompressCodecsInfo STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo);
  397.34 +#define IMPL_ISetCompressCodecsInfo2(x) \
  397.35 +STDMETHODIMP x::SetCompressCodecsInfo(ICompressCodecsInfo *compressCodecsInfo) { \
  397.36 +  COM_TRY_BEGIN _codecsInfo = compressCodecsInfo;  return LoadExternalCodecs(_codecsInfo, _externalCodecs); COM_TRY_END }
  397.37 +#define IMPL_ISetCompressCodecsInfo IMPL_ISetCompressCodecsInfo2(CHandler)
  397.38 +
  397.39 +#define EXTERNAL_CODECS_VARS2 _codecsInfo, &_externalCodecs
  397.40 +
  397.41 +#define DECL_EXTERNAL_CODECS_VARS CMyComPtr<ICompressCodecsInfo> _codecsInfo; CObjectVector<CCodecInfoEx> _externalCodecs;
  397.42 +#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2,
  397.43 +
  397.44 +#define DECL_EXTERNAL_CODECS_LOC_VARS2 ICompressCodecsInfo *codecsInfo, const CObjectVector<CCodecInfoEx> *externalCodecs
  397.45 +#define EXTERNAL_CODECS_LOC_VARS2 codecsInfo, externalCodecs
  397.46 +
  397.47 +#define DECL_EXTERNAL_CODECS_LOC_VARS DECL_EXTERNAL_CODECS_LOC_VARS2,
  397.48 +#define EXTERNAL_CODECS_LOC_VARS EXTERNAL_CODECS_LOC_VARS2,
  397.49 +
  397.50 +#else
  397.51 +
  397.52 +#define PUBLIC_ISetCompressCodecsInfo
  397.53 +#define QUERY_ENTRY_ISetCompressCodecsInfo
  397.54 +#define DECL_ISetCompressCodecsInfo
  397.55 +#define IMPL_ISetCompressCodecsInfo
  397.56 +#define EXTERNAL_CODECS_VARS2
  397.57 +#define DECL_EXTERNAL_CODECS_VARS
  397.58 +#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2
  397.59 +#define DECL_EXTERNAL_CODECS_LOC_VARS2
  397.60 +#define EXTERNAL_CODECS_LOC_VARS2
  397.61 +#define DECL_EXTERNAL_CODECS_LOC_VARS
  397.62 +#define EXTERNAL_CODECS_LOC_VARS
  397.63 +
  397.64 +#endif
  397.65 +
  397.66 +bool FindMethod(
  397.67 +  DECL_EXTERNAL_CODECS_LOC_VARS
  397.68 +  const UString &name, CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams);
  397.69 +
  397.70 +bool FindMethod(
  397.71 +  DECL_EXTERNAL_CODECS_LOC_VARS
  397.72 +  CMethodId methodId, UString &name);
  397.73 +
  397.74 +
  397.75 +HRESULT CreateCoder(
  397.76 +  DECL_EXTERNAL_CODECS_LOC_VARS
  397.77 +  CMethodId methodId,
  397.78 +  CMyComPtr<ICompressFilter> &filter,
  397.79 +  CMyComPtr<ICompressCoder> &coder,
  397.80 +  CMyComPtr<ICompressCoder2> &coder2,
  397.81 +  bool encode, bool onlyCoder);
  397.82 +
  397.83 +HRESULT CreateCoder(
  397.84 +  DECL_EXTERNAL_CODECS_LOC_VARS
  397.85 +  CMethodId methodId,
  397.86 +  CMyComPtr<ICompressCoder> &coder,
  397.87 +  CMyComPtr<ICompressCoder2> &coder2,
  397.88 +  bool encode);
  397.89 +
  397.90 +HRESULT CreateCoder(
  397.91 +  DECL_EXTERNAL_CODECS_LOC_VARS
  397.92 +  CMethodId methodId,
  397.93 +  CMyComPtr<ICompressCoder> &coder, bool encode);
  397.94 +
  397.95 +HRESULT CreateFilter(
  397.96 +  DECL_EXTERNAL_CODECS_LOC_VARS
  397.97 +  CMethodId methodId,
  397.98 +  CMyComPtr<ICompressFilter> &filter,
  397.99 +  bool encode);
 397.100 +
 397.101 +#endif
   398.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   398.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/DeclareArcs.h	Sat Mar 03 10:31:27 2012 -0600
   398.3 @@ -0,0 +1,28 @@
   398.4 +// DeclareArcs.h
   398.5 +
   398.6 +#ifndef __DECLAREARCS_H
   398.7 +#define __DECLAREARCS_H
   398.8 +
   398.9 +#define DECLARE_ARC(x) struct CRegister##x { CRegister##x(); }; \
  398.10 +	FORCE_REF(CRegister##x, g_RegisterArc##x)
  398.11 +
  398.12 +#define DECLARE_ARCN(x,n) struct CRegister##x##n { CRegister##x##n(); }; \
  398.13 +	FORCE_REF(CRegister##x##n, g_RegisterArc##n##x)
  398.14 +
  398.15 +#ifndef FORCE_REF
  398.16 +	#define FORCE_REF(x,y)
  398.17 +#endif
  398.18 +
  398.19 +DECLARE_ARC(7z)
  398.20 +DECLARE_ARC(BZip2)
  398.21 +DECLARE_ARC(GZip)
  398.22 +DECLARE_ARC(Lzh)
  398.23 +DECLARE_ARC(Lzma)
  398.24 +DECLARE_ARC(Rar)
  398.25 +DECLARE_ARC(Split)
  398.26 +DECLARE_ARC(Tar)
  398.27 +DECLARE_ARC(Zip)
  398.28 +DECLARE_ARCN(Zip,2)
  398.29 +DECLARE_ARCN(Zip,3)
  398.30 +
  398.31 +#endif
   399.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   399.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/DeclareCodecs.h	Sat Mar 03 10:31:27 2012 -0600
   399.3 @@ -0,0 +1,31 @@
   399.4 +// DeclareCodecs.h
   399.5 +
   399.6 +#ifndef __DECLARECODECS_H
   399.7 +#define __DECLARECODECS_H
   399.8 +
   399.9 +#define DECLARE_CODEC(x) struct CRegisterCodec##x { CRegisterCodec##x(); }; \
  399.10 +	FORCE_REF(CRegisterCodec##x, g_RegisterCodec##x)
  399.11 +
  399.12 +#define DECLARE_CODECS(x) struct CRegisterCodecs##x { CRegisterCodecs##x(); }; \
  399.13 +	FORCE_REF(CRegisterCodecs##x, g_RegisterCodecs##x)
  399.14 +
  399.15 +#ifndef FORCE_REF
  399.16 +	#define FORCE_REF(x,y)
  399.17 +#endif
  399.18 +
  399.19 +DECLARE_CODEC(7zAES)
  399.20 +DECLARE_CODEC(BCJ2)
  399.21 +DECLARE_CODEC(BCJ)
  399.22 +DECLARE_CODEC(BZip2)
  399.23 +DECLARE_CODEC(Copy)
  399.24 +DECLARE_CODEC(Deflate64)
  399.25 +DECLARE_CODEC(DeflateNsis)
  399.26 +DECLARE_CODEC(Deflate)
  399.27 +DECLARE_CODEC(LZMA)
  399.28 +DECLARE_CODEC(PPMD)
  399.29 +
  399.30 +DECLARE_CODECS(Branch)
  399.31 +DECLARE_CODECS(ByteSwap)
  399.32 +DECLARE_CODECS(Rar)
  399.33 +
  399.34 +#endif
   400.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   400.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/FilterCoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   400.3 @@ -0,0 +1,262 @@
   400.4 +// FilterCoder.cpp
   400.5 +
   400.6 +#include "StdAfx.h"
   400.7 +
   400.8 +#include "FilterCoder.h"
   400.9 +extern "C"
  400.10 +{
  400.11 +#include "../../../C/Alloc.h"
  400.12 +}
  400.13 +#include "../../Common/Defs.h"
  400.14 +#include "StreamUtils.h"
  400.15 +
  400.16 +static const UInt32 kBufferSize = 1 << 17;
  400.17 +
  400.18 +CFilterCoder::CFilterCoder()
  400.19 +{
  400.20 +  _buffer = (Byte *)::MidAlloc(kBufferSize);
  400.21 +}
  400.22 +
  400.23 +CFilterCoder::~CFilterCoder()
  400.24 +{
  400.25 +  ::MidFree(_buffer);
  400.26 +}
  400.27 +
  400.28 +HRESULT CFilterCoder::WriteWithLimit(ISequentialOutStream *outStream, UInt32 size)
  400.29 +{
  400.30 +  if (_outSizeIsDefined)
  400.31 +  {
  400.32 +    UInt64 remSize = _outSize - _nowPos64;
  400.33 +    if (size > remSize)
  400.34 +      size = (UInt32)remSize;
  400.35 +  }
  400.36 +  RINOK(WriteStream(outStream, _buffer, size));
  400.37 +  _nowPos64 += size;
  400.38 +  return S_OK;
  400.39 +}
  400.40 +
  400.41 +
  400.42 +STDMETHODIMP CFilterCoder::Code(ISequentialInStream *inStream,
  400.43 +      ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,
  400.44 +      ICompressProgressInfo *progress)
  400.45 +{
  400.46 +  RINOK(Init());
  400.47 +  UInt32 bufferPos = 0;
  400.48 +  _outSizeIsDefined = (outSize != 0);
  400.49 +  if (_outSizeIsDefined)
  400.50 +    _outSize = *outSize;
  400.51 +
  400.52 +  while(NeedMore())
  400.53 +  {
  400.54 +    size_t processedSize = kBufferSize - bufferPos;
  400.55 +    
  400.56 +    // Change it: It can be optimized using ReadPart
  400.57 +    RINOK(ReadStream(inStream, _buffer + bufferPos, &processedSize));
  400.58 +    
  400.59 +    UInt32 endPos = bufferPos + (UInt32)processedSize;
  400.60 +
  400.61 +    bufferPos = Filter->Filter(_buffer, endPos);
  400.62 +    if (bufferPos > endPos)
  400.63 +    {
  400.64 +      for (; endPos< bufferPos; endPos++)
  400.65 +        _buffer[endPos] = 0;
  400.66 +      bufferPos = Filter->Filter(_buffer, endPos);
  400.67 +    }
  400.68 +
  400.69 +    if (bufferPos == 0)
  400.70 +    {
  400.71 +      if (endPos > 0)
  400.72 +        return WriteWithLimit(outStream, endPos);
  400.73 +      return S_OK;
  400.74 +    }
  400.75 +    RINOK(WriteWithLimit(outStream, bufferPos));
  400.76 +    if (progress != NULL)
  400.77 +    {
  400.78 +      RINOK(progress->SetRatioInfo(&_nowPos64, &_nowPos64));
  400.79 +    }
  400.80 +    UInt32 i = 0;
  400.81 +    while(bufferPos < endPos)
  400.82 +      _buffer[i++] = _buffer[bufferPos++];
  400.83 +    bufferPos = i;
  400.84 +  }
  400.85 +  return S_OK;
  400.86 +}
  400.87 +
  400.88 +// #ifdef _ST_MODE
  400.89 +STDMETHODIMP CFilterCoder::SetOutStream(ISequentialOutStream *outStream)
  400.90 +{
  400.91 +  _bufferPos = 0;
  400.92 +  _outStream = outStream;
  400.93 +  return Init();
  400.94 +}
  400.95 +
  400.96 +STDMETHODIMP CFilterCoder::ReleaseOutStream()
  400.97 +{
  400.98 +  _outStream.Release();
  400.99 +  return S_OK;
 400.100 +};
 400.101 +
 400.102 +
 400.103 +STDMETHODIMP CFilterCoder::Write(const void *data, UInt32 size, UInt32 *processedSize)
 400.104 +{
 400.105 +  UInt32 processedSizeTotal = 0;
 400.106 +  while(size > 0)
 400.107 +  {
 400.108 +    UInt32 sizeMax = kBufferSize - _bufferPos;
 400.109 +    UInt32 sizeTemp = size;
 400.110 +    if (sizeTemp > sizeMax)
 400.111 +      sizeTemp = sizeMax;
 400.112 +    memmove(_buffer + _bufferPos, data, sizeTemp);
 400.113 +    size -= sizeTemp;
 400.114 +    processedSizeTotal += sizeTemp;
 400.115 +    data = (const Byte *)data + sizeTemp;
 400.116 +    UInt32 endPos = _bufferPos + sizeTemp;
 400.117 +    _bufferPos = Filter->Filter(_buffer, endPos);
 400.118 +    if (_bufferPos == 0)
 400.119 +    {
 400.120 +      _bufferPos = endPos;
 400.121 +      break;
 400.122 +    }
 400.123 +    if (_bufferPos > endPos)
 400.124 +    {
 400.125 +      if (size != 0)
 400.126 +        return E_FAIL;
 400.127 +      break;
 400.128 +    }
 400.129 +    RINOK(WriteWithLimit(_outStream, _bufferPos));
 400.130 +    UInt32 i = 0;
 400.131 +    while(_bufferPos < endPos)
 400.132 +      _buffer[i++] = _buffer[_bufferPos++];
 400.133 +    _bufferPos = i;
 400.134 +  }
 400.135 +  if (processedSize != NULL)
 400.136 +    *processedSize = processedSizeTotal;
 400.137 +  return S_OK;
 400.138 +}
 400.139 +
 400.140 +STDMETHODIMP CFilterCoder::Flush()
 400.141 +{
 400.142 +  if (_bufferPos != 0)
 400.143 +  {
 400.144 +    UInt32 endPos = Filter->Filter(_buffer, _bufferPos);
 400.145 +    if (endPos > _bufferPos)
 400.146 +    {
 400.147 +      for (; _bufferPos < endPos; _bufferPos++)
 400.148 +        _buffer[_bufferPos] = 0;
 400.149 +      if (Filter->Filter(_buffer, endPos) != endPos)
 400.150 +        return E_FAIL;
 400.151 +    }
 400.152 +    RINOK(WriteStream(_outStream, _buffer, _bufferPos));
 400.153 +    _bufferPos = 0;
 400.154 +  }
 400.155 +  CMyComPtr<IOutStreamFlush> flush;
 400.156 +  _outStream.QueryInterface(IID_IOutStreamFlush, &flush);
 400.157 +  if (flush)
 400.158 +    return  flush->Flush();
 400.159 +  return S_OK;
 400.160 +}
 400.161 +
 400.162 +
 400.163 +STDMETHODIMP CFilterCoder::SetInStream(ISequentialInStream *inStream)
 400.164 +{
 400.165 +  _convertedPosBegin = _convertedPosEnd = _bufferPos = 0;
 400.166 +  _inStream = inStream;
 400.167 +  return Init();
 400.168 +}
 400.169 +
 400.170 +STDMETHODIMP CFilterCoder::ReleaseInStream()
 400.171 +{
 400.172 +  _inStream.Release();
 400.173 +  return S_OK;
 400.174 +};
 400.175 +
 400.176 +STDMETHODIMP CFilterCoder::Read(void *data, UInt32 size, UInt32 *processedSize)
 400.177 +{
 400.178 +  UInt32 processedSizeTotal = 0;
 400.179 +  while(size > 0)
 400.180 +  {
 400.181 +    if (_convertedPosBegin != _convertedPosEnd)
 400.182 +    {
 400.183 +      UInt32 sizeTemp = MyMin(size, _convertedPosEnd - _convertedPosBegin);
 400.184 +      memmove(data, _buffer + _convertedPosBegin, sizeTemp);
 400.185 +      _convertedPosBegin += sizeTemp;
 400.186 +      data = (void *)((Byte *)data + sizeTemp);
 400.187 +      size -= sizeTemp;
 400.188 +      processedSizeTotal += sizeTemp;
 400.189 +      break;
 400.190 +    }
 400.191 +    int i;
 400.192 +    for (i = 0; _convertedPosEnd + i < _bufferPos; i++)
 400.193 +      _buffer[i] = _buffer[i + _convertedPosEnd];
 400.194 +    _bufferPos = i;
 400.195 +    _convertedPosBegin = _convertedPosEnd = 0;
 400.196 +    size_t processedSizeTemp = kBufferSize - _bufferPos;
 400.197 +    RINOK(ReadStream(_inStream, _buffer + _bufferPos, &processedSizeTemp));
 400.198 +    _bufferPos = _bufferPos + (UInt32)processedSizeTemp;
 400.199 +    _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);
 400.200 +    if (_convertedPosEnd == 0)
 400.201 +    {
 400.202 +      if (_bufferPos == 0)
 400.203 +        break;
 400.204 +      else
 400.205 +      {
 400.206 +        _convertedPosEnd = _bufferPos; // check it
 400.207 +        continue;
 400.208 +      }
 400.209 +    }
 400.210 +    if (_convertedPosEnd > _bufferPos)
 400.211 +    {
 400.212 +      for (; _bufferPos < _convertedPosEnd; _bufferPos++)
 400.213 +        _buffer[_bufferPos] = 0;
 400.214 +      _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);
 400.215 +    }
 400.216 +  }
 400.217 +  if (processedSize != NULL)
 400.218 +    *processedSize = processedSizeTotal;
 400.219 +  return S_OK;
 400.220 +}
 400.221 +
 400.222 +// #endif // _ST_MODE
 400.223 +
 400.224 +#ifndef _NO_CRYPTO
 400.225 +STDMETHODIMP CFilterCoder::CryptoSetPassword(const Byte *data, UInt32 size)
 400.226 +{
 400.227 +  return _setPassword->CryptoSetPassword(data, size);
 400.228 +}
 400.229 +#endif
 400.230 +
 400.231 +#ifndef EXTRACT_ONLY
 400.232 +STDMETHODIMP CFilterCoder::SetCoderProperties(const PROPID *propIDs,
 400.233 +      const PROPVARIANT *properties, UInt32 numProperties)
 400.234 +{
 400.235 +  return _SetCoderProperties->SetCoderProperties(propIDs, properties, numProperties);
 400.236 +}
 400.237 +
 400.238 +STDMETHODIMP CFilterCoder::WriteCoderProperties(ISequentialOutStream *outStream)
 400.239 +{
 400.240 +  return _writeCoderProperties->WriteCoderProperties(outStream);
 400.241 +}
 400.242 +
 400.243 +/*
 400.244 +STDMETHODIMP CFilterCoder::ResetSalt()
 400.245 +{
 400.246 +  return _CryptoResetSalt->ResetSalt();
 400.247 +}
 400.248 +*/
 400.249 +
 400.250 +STDMETHODIMP CFilterCoder::ResetInitVector()
 400.251 +{
 400.252 +  return _CryptoResetInitVector->ResetInitVector();
 400.253 +}
 400.254 +#endif
 400.255 +
 400.256 +STDMETHODIMP CFilterCoder::SetDecoderProperties2(const Byte *data, UInt32 size)
 400.257 +{
 400.258 +  return _setDecoderProperties->SetDecoderProperties2(data, size);
 400.259 +}
 400.260 +
 400.261 +
 400.262 +
 400.263 +void foo()
 400.264 +{
 400.265 +}
   401.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   401.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/FilterCoder.h	Sat Mar 03 10:31:27 2012 -0600
   401.3 @@ -0,0 +1,143 @@
   401.4 +// FilterCoder.h
   401.5 +
   401.6 +#ifndef __FILTERCODER_H
   401.7 +#define __FILTERCODER_H
   401.8 +
   401.9 +#include "../../Common/MyCom.h"
  401.10 +#include "../ICoder.h"
  401.11 +#include "../IPassword.h"
  401.12 +
  401.13 +#define MY_QUERYINTERFACE_ENTRY_AG(i, sub0, sub) if (iid == IID_ ## i) \
  401.14 +{ if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \
  401.15 +*outObject = (void *)(i *)this; AddRef(); return S_OK; }
  401.16 +
  401.17 +class CFilterCoder:
  401.18 +  public ICompressCoder,
  401.19 +  // #ifdef _ST_MODE
  401.20 +  public ICompressSetInStream,
  401.21 +  public ISequentialInStream,
  401.22 +  public ICompressSetOutStream,
  401.23 +  public ISequentialOutStream,
  401.24 +  public IOutStreamFlush,
  401.25 +  // #endif
  401.26 +
  401.27 +  #ifndef _NO_CRYPTO
  401.28 +  public ICryptoSetPassword,
  401.29 +  #endif
  401.30 +  #ifndef EXTRACT_ONLY
  401.31 +  public ICompressSetCoderProperties,
  401.32 +  public ICompressWriteCoderProperties,
  401.33 +  // public ICryptoResetSalt,
  401.34 +  public ICryptoResetInitVector,
  401.35 +  #endif
  401.36 +  public ICompressSetDecoderProperties2,
  401.37 +  public CMyUnknownImp
  401.38 +{
  401.39 +protected:
  401.40 +  Byte *_buffer;
  401.41 +  // #ifdef _ST_MODE
  401.42 +  CMyComPtr<ISequentialInStream> _inStream;
  401.43 +  CMyComPtr<ISequentialOutStream> _outStream;
  401.44 +  UInt32 _bufferPos;
  401.45 +  UInt32 _convertedPosBegin;
  401.46 +  UInt32 _convertedPosEnd;
  401.47 +  // #endif
  401.48 +  bool _outSizeIsDefined;
  401.49 +  UInt64 _outSize;
  401.50 +  UInt64 _nowPos64;
  401.51 +
  401.52 +  HRESULT Init()
  401.53 +  {
  401.54 +    _nowPos64 = 0;
  401.55 +    _outSizeIsDefined = false;
  401.56 +    return Filter->Init();
  401.57 +  }
  401.58 +
  401.59 +  CMyComPtr<ICryptoSetPassword> _setPassword;
  401.60 +  #ifndef EXTRACT_ONLY
  401.61 +  CMyComPtr<ICompressSetCoderProperties> _SetCoderProperties;
  401.62 +  CMyComPtr<ICompressWriteCoderProperties> _writeCoderProperties;
  401.63 +  // CMyComPtr<ICryptoResetSalt> _CryptoResetSalt;
  401.64 +  CMyComPtr<ICryptoResetInitVector> _CryptoResetInitVector;
  401.65 +  #endif
  401.66 +  CMyComPtr<ICompressSetDecoderProperties2> _setDecoderProperties;
  401.67 +public:
  401.68 +  CMyComPtr<ICompressFilter> Filter;
  401.69 +
  401.70 +  CFilterCoder();
  401.71 +  ~CFilterCoder();
  401.72 +  HRESULT WriteWithLimit(ISequentialOutStream *outStream, UInt32 size);
  401.73 +  bool NeedMore() const
  401.74 +    { return (!_outSizeIsDefined || (_nowPos64 < _outSize)); }
  401.75 +
  401.76 +public:
  401.77 +  MY_QUERYINTERFACE_BEGIN
  401.78 +    MY_QUERYINTERFACE_ENTRY(ICompressCoder)
  401.79 +    // #ifdef _ST_MODE
  401.80 +    MY_QUERYINTERFACE_ENTRY(ICompressSetInStream)
  401.81 +    MY_QUERYINTERFACE_ENTRY(ISequentialInStream)
  401.82 +
  401.83 +    MY_QUERYINTERFACE_ENTRY(ICompressSetOutStream)
  401.84 +    MY_QUERYINTERFACE_ENTRY(ISequentialOutStream)
  401.85 +    MY_QUERYINTERFACE_ENTRY(IOutStreamFlush)
  401.86 +    // #endif
  401.87 +
  401.88 +    #ifndef _NO_CRYPTO
  401.89 +    MY_QUERYINTERFACE_ENTRY_AG(ICryptoSetPassword, Filter, _setPassword)
  401.90 +    #endif
  401.91 +
  401.92 +    #ifndef EXTRACT_ONLY
  401.93 +    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetCoderProperties, Filter, _SetCoderProperties)
  401.94 +    MY_QUERYINTERFACE_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties)
  401.95 +    // MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetSalt, Filter, _CryptoResetSalt)
  401.96 +    MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetInitVector, Filter, _CryptoResetInitVector)
  401.97 +    #endif
  401.98 +
  401.99 +    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties)
 401.100 +  MY_QUERYINTERFACE_END
 401.101 +  MY_ADDREF_RELEASE
 401.102 +  STDMETHOD(Code)(ISequentialInStream *inStream,
 401.103 +      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
 401.104 +      ICompressProgressInfo *progress);
 401.105 +  // #ifdef _ST_MODE
 401.106 +  STDMETHOD(ReleaseInStream)();
 401.107 +  STDMETHOD(SetInStream)(ISequentialInStream *inStream);
 401.108 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); \
 401.109 +  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);
 401.110 +  STDMETHOD(ReleaseOutStream)();
 401.111 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
 401.112 +  STDMETHOD(Flush)();
 401.113 +  // #endif
 401.114 +
 401.115 +  #ifndef _NO_CRYPTO
 401.116 +  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
 401.117 +  #endif
 401.118 +  #ifndef EXTRACT_ONLY
 401.119 +  STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
 401.120 +      const PROPVARIANT *properties, UInt32 numProperties);
 401.121 +  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
 401.122 +  // STDMETHOD(ResetSalt)();
 401.123 +  STDMETHOD(ResetInitVector)();
 401.124 +  #endif
 401.125 +  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
 401.126 +};
 401.127 +
 401.128 +// #ifdef _ST_MODE
 401.129 +class CInStreamReleaser
 401.130 +{
 401.131 +public:
 401.132 +  CFilterCoder *FilterCoder;
 401.133 +  CInStreamReleaser(): FilterCoder(0) {}
 401.134 +  ~CInStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseInStream(); }
 401.135 +};
 401.136 +
 401.137 +class COutStreamReleaser
 401.138 +{
 401.139 +public:
 401.140 +  CFilterCoder *FilterCoder;
 401.141 +  COutStreamReleaser(): FilterCoder(0) {}
 401.142 +  ~COutStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseOutStream(); }
 401.143 +};
 401.144 +// #endif
 401.145 +
 401.146 +#endif
   402.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   402.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/InBuffer.cpp	Sat Mar 03 10:31:27 2012 -0600
   402.3 @@ -0,0 +1,83 @@
   402.4 +// InBuffer.cpp
   402.5 +
   402.6 +#include "StdAfx.h"
   402.7 +
   402.8 +#include "InBuffer.h"
   402.9 +
  402.10 +extern "C"
  402.11 +{
  402.12 +  #include "../../../C/Alloc.h"
  402.13 +}
  402.14 +
  402.15 +CInBuffer::CInBuffer():
  402.16 +  _buffer(0),
  402.17 +  _bufferLimit(0),
  402.18 +  _bufferBase(0),
  402.19 +  _stream(0),
  402.20 +  _bufferSize(0)
  402.21 +{}
  402.22 +
  402.23 +bool CInBuffer::Create(UInt32 bufferSize)
  402.24 +{
  402.25 +  const UInt32 kMinBlockSize = 1;
  402.26 +  if (bufferSize < kMinBlockSize)
  402.27 +    bufferSize = kMinBlockSize;
  402.28 +  if (_bufferBase != 0 && _bufferSize == bufferSize)
  402.29 +    return true;
  402.30 +  Free();
  402.31 +  _bufferSize = bufferSize;
  402.32 +  _bufferBase = (Byte *)::MidAlloc(bufferSize);
  402.33 +  return (_bufferBase != 0);
  402.34 +}
  402.35 +
  402.36 +void CInBuffer::Free()
  402.37 +{
  402.38 +  ::MidFree(_bufferBase);
  402.39 +  _bufferBase = 0;
  402.40 +}
  402.41 +
  402.42 +void CInBuffer::SetStream(ISequentialInStream *stream)
  402.43 +{
  402.44 +  _stream = stream;
  402.45 +}
  402.46 +
  402.47 +void CInBuffer::Init()
  402.48 +{
  402.49 +  _processedSize = 0;
  402.50 +  _buffer = _bufferBase;
  402.51 +  _bufferLimit = _buffer;
  402.52 +  _wasFinished = false;
  402.53 +  #ifdef _NO_EXCEPTIONS
  402.54 +  ErrorCode = S_OK;
  402.55 +  #endif
  402.56 +}
  402.57 +
  402.58 +bool CInBuffer::ReadBlock()
  402.59 +{
  402.60 +  #ifdef _NO_EXCEPTIONS
  402.61 +  if (ErrorCode != S_OK)
  402.62 +    return false;
  402.63 +  #endif
  402.64 +  if (_wasFinished)
  402.65 +    return false;
  402.66 +  _processedSize += (_buffer - _bufferBase);
  402.67 +  UInt32 numProcessedBytes;
  402.68 +  HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes);
  402.69 +  #ifdef _NO_EXCEPTIONS
  402.70 +  ErrorCode = result;
  402.71 +  #else
  402.72 +  if (result != S_OK)
  402.73 +    throw CInBufferException(result);
  402.74 +  #endif
  402.75 +  _buffer = _bufferBase;
  402.76 +  _bufferLimit = _buffer + numProcessedBytes;
  402.77 +  _wasFinished = (numProcessedBytes == 0);
  402.78 +  return (!_wasFinished);
  402.79 +}
  402.80 +
  402.81 +Byte CInBuffer::ReadBlock2()
  402.82 +{
  402.83 +  if(!ReadBlock())
  402.84 +    return 0xFF;
  402.85 +  return *_buffer++;
  402.86 +}
   403.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   403.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/InBuffer.h	Sat Mar 03 10:31:27 2012 -0600
   403.3 @@ -0,0 +1,81 @@
   403.4 +// InBuffer.h
   403.5 +
   403.6 +#ifndef __INBUFFER_H
   403.7 +#define __INBUFFER_H
   403.8 +
   403.9 +#include "../IStream.h"
  403.10 +#include "../../Common/MyCom.h"
  403.11 +#include "../../Common/MyException.h"
  403.12 +
  403.13 +#ifndef _NO_EXCEPTIONS
  403.14 +struct CInBufferException: public CSystemException
  403.15 +{
  403.16 +  CInBufferException(HRESULT errorCode): CSystemException(errorCode) {}
  403.17 +};
  403.18 +#endif
  403.19 +
  403.20 +class CInBuffer
  403.21 +{
  403.22 +  Byte *_buffer;
  403.23 +  Byte *_bufferLimit;
  403.24 +  Byte *_bufferBase;
  403.25 +  CMyComPtr<ISequentialInStream> _stream;
  403.26 +  UInt64 _processedSize;
  403.27 +  UInt32 _bufferSize;
  403.28 +  bool _wasFinished;
  403.29 +
  403.30 +  bool ReadBlock();
  403.31 +  Byte ReadBlock2();
  403.32 +
  403.33 +public:
  403.34 +  #ifdef _NO_EXCEPTIONS
  403.35 +  HRESULT ErrorCode;
  403.36 +  #endif
  403.37 +
  403.38 +  CInBuffer();
  403.39 +  ~CInBuffer() { Free(); }
  403.40 +
  403.41 +  bool Create(UInt32 bufferSize);
  403.42 +  void Free();
  403.43 +  
  403.44 +  void SetStream(ISequentialInStream *stream);
  403.45 +  void Init();
  403.46 +  void ReleaseStream() { _stream.Release(); }
  403.47 +
  403.48 +  bool ReadByte(Byte &b)
  403.49 +  {
  403.50 +    if (_buffer >= _bufferLimit)
  403.51 +      if (!ReadBlock())
  403.52 +        return false;
  403.53 +    b = *_buffer++;
  403.54 +    return true;
  403.55 +  }
  403.56 +  Byte ReadByte()
  403.57 +  {
  403.58 +    if (_buffer >= _bufferLimit)
  403.59 +      return ReadBlock2();
  403.60 +    return *_buffer++;
  403.61 +  }
  403.62 +  UInt32 ReadBytes(Byte *buf, UInt32 size)
  403.63 +  {
  403.64 +    if ((UInt32)(_bufferLimit - _buffer) >= size)
  403.65 +    {
  403.66 +      for (UInt32 i = 0; i < size; i++)
  403.67 +        buf[i] = _buffer[i];
  403.68 +      _buffer += size;
  403.69 +      return size;
  403.70 +    }
  403.71 +    for (UInt32 i = 0; i < size; i++)
  403.72 +    {
  403.73 +      if (_buffer >= _bufferLimit)
  403.74 +        if (!ReadBlock())
  403.75 +          return i;
  403.76 +      buf[i] = *_buffer++;
  403.77 +    }
  403.78 +    return size;
  403.79 +  }
  403.80 +  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }
  403.81 +  bool WasFinished() const { return _wasFinished; }
  403.82 +};
  403.83 +
  403.84 +#endif
   404.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   404.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/InOutTempBuffer.cpp	Sat Mar 03 10:31:27 2012 -0600
   404.3 @@ -0,0 +1,122 @@
   404.4 +// InOutTempBuffer.cpp
   404.5 +
   404.6 +#include "StdAfx.h"
   404.7 +
   404.8 +#include "InOutTempBuffer.h"
   404.9 +#include "../../Common/Defs.h"
  404.10 +// #include "Windows/Defs.h"
  404.11 +
  404.12 +#include "StreamUtils.h"
  404.13 +
  404.14 +using namespace NWindows;
  404.15 +using namespace NFile;
  404.16 +using namespace NDirectory;
  404.17 +
  404.18 +static UInt32 kTmpBufferMemorySize = (1 << 20);
  404.19 +
  404.20 +static LPCTSTR kTempFilePrefixString = TEXT("iot");
  404.21 +
  404.22 +CInOutTempBuffer::CInOutTempBuffer():
  404.23 +  _buffer(NULL)
  404.24 +{
  404.25 +}
  404.26 +
  404.27 +void CInOutTempBuffer::Create()
  404.28 +{
  404.29 +  _buffer = new Byte[kTmpBufferMemorySize];
  404.30 +}
  404.31 +
  404.32 +CInOutTempBuffer::~CInOutTempBuffer()
  404.33 +{
  404.34 +  delete []_buffer;
  404.35 +}
  404.36 +void CInOutTempBuffer::InitWriting()
  404.37 +{
  404.38 +  _bufferPosition = 0;
  404.39 +  _tmpFileCreated = false;
  404.40 +  _fileSize = 0;
  404.41 +}
  404.42 +
  404.43 +bool CInOutTempBuffer::WriteToFile(const void *data, UInt32 size)
  404.44 +{
  404.45 +  if (size == 0)
  404.46 +    return true;
  404.47 +  if(!_tmpFileCreated)
  404.48 +  {
  404.49 +    CSysString tempDirPath;
  404.50 +    if(!MyGetTempPath(tempDirPath))
  404.51 +      return false;
  404.52 +    if (_tempFile.Create(tempDirPath, kTempFilePrefixString, _tmpFileName) == 0)
  404.53 +      return false;
  404.54 +    // _outFile.SetOpenCreationDispositionCreateAlways();
  404.55 +    if(!_outFile.Create(_tmpFileName, true))
  404.56 +      return false;
  404.57 +    _tmpFileCreated = true;
  404.58 +  }
  404.59 +  UInt32 processedSize;
  404.60 +  if(!_outFile.Write(data, size, processedSize))
  404.61 +    return false;
  404.62 +  _fileSize += processedSize;
  404.63 +  return (processedSize == size);
  404.64 +}
  404.65 +
  404.66 +bool CInOutTempBuffer::FlushWrite()
  404.67 +{
  404.68 +  return _outFile.Close();
  404.69 +}
  404.70 +
  404.71 +bool CInOutTempBuffer::Write(const void *data, UInt32 size)
  404.72 +{
  404.73 +  if(_bufferPosition < kTmpBufferMemorySize)
  404.74 +  {
  404.75 +    UInt32 curSize = MyMin(kTmpBufferMemorySize - _bufferPosition, size);
  404.76 +    memmove(_buffer + _bufferPosition, (const Byte *)data, curSize);
  404.77 +    _bufferPosition += curSize;
  404.78 +    size -= curSize;
  404.79 +    data = ((const Byte *)data) + curSize;
  404.80 +    _fileSize += curSize;
  404.81 +  }
  404.82 +  return WriteToFile(data, size);
  404.83 +}
  404.84 +
  404.85 +bool CInOutTempBuffer::InitReading()
  404.86 +{
  404.87 +  _currentPositionInBuffer = 0;
  404.88 +  if(_tmpFileCreated)
  404.89 +    return _inFile.Open(_tmpFileName);
  404.90 +  return true;
  404.91 +}
  404.92 +
  404.93 +HRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)
  404.94 +{
  404.95 +  if (_currentPositionInBuffer < _bufferPosition)
  404.96 +  {
  404.97 +    UInt32 sizeToWrite = _bufferPosition - _currentPositionInBuffer;
  404.98 +    RINOK(WriteStream(stream, _buffer + _currentPositionInBuffer, sizeToWrite));
  404.99 +    _currentPositionInBuffer += sizeToWrite;
 404.100 +  }
 404.101 +  if (!_tmpFileCreated)
 404.102 +    return true;
 404.103 +  for (;;)
 404.104 +  {
 404.105 +    UInt32 localProcessedSize;
 404.106 +    if (!_inFile.ReadPart(_buffer, kTmpBufferMemorySize, localProcessedSize))
 404.107 +      return E_FAIL;
 404.108 +    if (localProcessedSize == 0)
 404.109 +      return S_OK;
 404.110 +    RINOK(WriteStream(stream, _buffer, localProcessedSize));
 404.111 +  }
 404.112 +}
 404.113 +
 404.114 +STDMETHODIMP CSequentialOutTempBufferImp::Write(const void *data, UInt32 size, UInt32 *processedSize)
 404.115 +{
 404.116 +  if (!_buffer->Write(data, size))
 404.117 +  {
 404.118 +    if (processedSize != NULL)
 404.119 +      *processedSize = 0;
 404.120 +    return E_FAIL;
 404.121 +  }
 404.122 +  if (processedSize != NULL)
 404.123 +    *processedSize = size;
 404.124 +  return S_OK;
 404.125 +}
   405.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   405.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/InOutTempBuffer.h	Sat Mar 03 10:31:27 2012 -0600
   405.3 @@ -0,0 +1,55 @@
   405.4 +// Util/InOutTempBuffer.h
   405.5 +
   405.6 +#ifndef __IN_OUT_TEMP_BUFFER_H
   405.7 +#define __IN_OUT_TEMP_BUFFER_H
   405.8 +
   405.9 +#include "../../Windows/FileIO.h"
  405.10 +#include "../../Windows/FileDir.h"
  405.11 +#include "../../Common/MyCom.h"
  405.12 +
  405.13 +#include "../IStream.h"
  405.14 +
  405.15 +class CInOutTempBuffer
  405.16 +{
  405.17 +  NWindows::NFile::NDirectory::CTempFile _tempFile;
  405.18 +  NWindows::NFile::NIO::COutFile _outFile;
  405.19 +  NWindows::NFile::NIO::CInFile _inFile;
  405.20 +  Byte *_buffer;
  405.21 +  UInt32 _bufferPosition;
  405.22 +  UInt32 _currentPositionInBuffer;
  405.23 +  CSysString _tmpFileName;
  405.24 +  bool _tmpFileCreated;
  405.25 +
  405.26 +  UInt64 _fileSize;
  405.27 +
  405.28 +  bool WriteToFile(const void *data, UInt32 size);
  405.29 +public:
  405.30 +  CInOutTempBuffer();
  405.31 +  ~CInOutTempBuffer();
  405.32 +  void Create();
  405.33 +
  405.34 +  void InitWriting();
  405.35 +  bool Write(const void *data, UInt32 size);
  405.36 +  UInt64 GetDataSize() const { return _fileSize; }
  405.37 +  bool FlushWrite();
  405.38 +  bool InitReading();
  405.39 +  HRESULT WriteToStream(ISequentialOutStream *stream);
  405.40 +};
  405.41 +
  405.42 +class CSequentialOutTempBufferImp:
  405.43 +  public ISequentialOutStream,
  405.44 +  public CMyUnknownImp
  405.45 +{
  405.46 +  CInOutTempBuffer *_buffer;
  405.47 +public:
  405.48 +  // CSequentialOutStreamImp(): _size(0) {}
  405.49 +  // UInt32 _size;
  405.50 +  void Init(CInOutTempBuffer *buffer)  { _buffer = buffer; }
  405.51 +  // UInt32 GetSize() const { return _size; }
  405.52 +
  405.53 +  MY_UNKNOWN_IMP
  405.54 +
  405.55 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  405.56 +};
  405.57 +
  405.58 +#endif
   406.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   406.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/LimitedStreams.cpp	Sat Mar 03 10:31:27 2012 -0600
   406.3 @@ -0,0 +1,45 @@
   406.4 +// LimitedStreams.cpp
   406.5 +
   406.6 +#include "StdAfx.h"
   406.7 +
   406.8 +#include "LimitedStreams.h"
   406.9 +#include "../../Common/Defs.h"
  406.10 +
  406.11 +STDMETHODIMP CLimitedSequentialInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
  406.12 +{
  406.13 +  UInt32 realProcessedSize = 0;
  406.14 +  UInt32 sizeToRead = (UInt32)MyMin((_size - _pos), (UInt64)size);
  406.15 +  HRESULT result = S_OK;
  406.16 +  if (sizeToRead > 0)
  406.17 +  {
  406.18 +    result = _stream->Read(data, sizeToRead, &realProcessedSize);
  406.19 +    _pos += realProcessedSize;
  406.20 +    if (realProcessedSize == 0)
  406.21 +      _wasFinished = true;
  406.22 +  }
  406.23 +  if(processedSize != NULL)
  406.24 +    *processedSize = realProcessedSize;
  406.25 +  return result;
  406.26 +}
  406.27 +
  406.28 +STDMETHODIMP CLimitedSequentialOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
  406.29 +{
  406.30 +  HRESULT result = S_OK;
  406.31 +  if (processedSize != NULL)
  406.32 +    *processedSize = 0;
  406.33 +  if (size > _size)
  406.34 +  {
  406.35 +    size = (UInt32)_size;
  406.36 +    if (size == 0)
  406.37 +    {
  406.38 +      _overflow = true;
  406.39 +      return E_FAIL;
  406.40 +    }
  406.41 +  }
  406.42 +  if (_stream)
  406.43 +    result = _stream->Write(data, size, &size);
  406.44 +  _size -= size;
  406.45 +  if (processedSize != NULL)
  406.46 +    *processedSize = size;
  406.47 +  return result;
  406.48 +}
   407.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   407.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/LimitedStreams.h	Sat Mar 03 10:31:27 2012 -0600
   407.3 @@ -0,0 +1,54 @@
   407.4 +// LimitedStreams.h
   407.5 +
   407.6 +#ifndef __LIMITEDSTREAMS_H
   407.7 +#define __LIMITEDSTREAMS_H
   407.8 +
   407.9 +#include "../../Common/MyCom.h"
  407.10 +#include "../IStream.h"
  407.11 +
  407.12 +class CLimitedSequentialInStream:
  407.13 +  public ISequentialInStream,
  407.14 +  public CMyUnknownImp
  407.15 +{
  407.16 +  CMyComPtr<ISequentialInStream> _stream;
  407.17 +  UInt64 _size;
  407.18 +  UInt64 _pos;
  407.19 +  bool _wasFinished;
  407.20 +public:
  407.21 +  void SetStream(ISequentialInStream *stream) { _stream = stream; }
  407.22 +  void Init(UInt64 streamSize)
  407.23 +  {
  407.24 +    _size = streamSize;
  407.25 +    _pos = 0;
  407.26 +    _wasFinished = false;
  407.27 +  }
  407.28 + 
  407.29 +  MY_UNKNOWN_IMP
  407.30 +
  407.31 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
  407.32 +  UInt64 GetSize() const { return _pos; }
  407.33 +  bool WasFinished() const { return _wasFinished; }
  407.34 +};
  407.35 +
  407.36 +class CLimitedSequentialOutStream:
  407.37 +  public ISequentialOutStream,
  407.38 +  public CMyUnknownImp
  407.39 +{
  407.40 +  CMyComPtr<ISequentialOutStream> _stream;
  407.41 +  UInt64 _size;
  407.42 +  bool _overflow;
  407.43 +public:
  407.44 +  MY_UNKNOWN_IMP
  407.45 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  407.46 +  void SetStream(ISequentialOutStream *stream) { _stream = stream; }
  407.47 +  void ReleaseStream() { _stream.Release(); }
  407.48 +  void Init(UInt64 size)
  407.49 +  {
  407.50 +    _size = size;
  407.51 +    _overflow = false;
  407.52 +  }
  407.53 +  bool IsFinishedOK() const { return (_size == 0 && !_overflow); }
  407.54 +  UInt64 GetRem() const { return _size; }
  407.55 +};
  407.56 +
  407.57 +#endif
   408.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   408.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/LockedStream.cpp	Sat Mar 03 10:31:27 2012 -0600
   408.3 @@ -0,0 +1,23 @@
   408.4 +// LockedStream.cpp
   408.5 +
   408.6 +#include "StdAfx.h"
   408.7 +
   408.8 +#include "LockedStream.h"
   408.9 +
  408.10 +HRESULT CLockedInStream::Read(UInt64 startPos, void *data, UInt32 size,
  408.11 +  UInt32 *processedSize)
  408.12 +{
  408.13 +  NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
  408.14 +  RINOK(_stream->Seek(startPos, STREAM_SEEK_SET, NULL));
  408.15 +  return _stream->Read(data, size, processedSize);
  408.16 +}
  408.17 +
  408.18 +STDMETHODIMP CLockedSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)
  408.19 +{
  408.20 +  UInt32 realProcessedSize = 0;
  408.21 +  HRESULT result = _lockedInStream->Read(_pos, data, size, &realProcessedSize);
  408.22 +  _pos += realProcessedSize;
  408.23 +  if (processedSize != NULL)
  408.24 +    *processedSize = realProcessedSize;
  408.25 +  return result;
  408.26 +}
   409.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   409.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/LockedStream.h	Sat Mar 03 10:31:27 2012 -0600
   409.3 @@ -0,0 +1,38 @@
   409.4 +// LockedStream.h
   409.5 +
   409.6 +#ifndef __LOCKEDSTREAM_H
   409.7 +#define __LOCKEDSTREAM_H
   409.8 +
   409.9 +#include "../../Windows/Synchronization.h"
  409.10 +#include "../../Common/MyCom.h"
  409.11 +#include "../IStream.h"
  409.12 +
  409.13 +class CLockedInStream
  409.14 +{
  409.15 +  CMyComPtr<IInStream> _stream;
  409.16 +  NWindows::NSynchronization::CCriticalSection _criticalSection;
  409.17 +public:
  409.18 +  void Init(IInStream *stream)
  409.19 +    { _stream = stream; }
  409.20 +  HRESULT Read(UInt64 startPos, void *data, UInt32 size, UInt32 *processedSize);
  409.21 +};
  409.22 +
  409.23 +class CLockedSequentialInStreamImp:
  409.24 +  public ISequentialInStream,
  409.25 +  public CMyUnknownImp
  409.26 +{
  409.27 +  CLockedInStream *_lockedInStream;
  409.28 +  UInt64 _pos;
  409.29 +public:
  409.30 +  void Init(CLockedInStream *lockedInStream, UInt64 startPos)
  409.31 +  {
  409.32 +    _lockedInStream = lockedInStream;
  409.33 +    _pos = startPos;
  409.34 +  }
  409.35 +
  409.36 +  MY_UNKNOWN_IMP
  409.37 +
  409.38 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
  409.39 +};
  409.40 +
  409.41 +#endif
   410.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   410.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/MemBlocks.cpp	Sat Mar 03 10:31:27 2012 -0600
   410.3 @@ -0,0 +1,183 @@
   410.4 +// MemBlocks.cpp
   410.5 +
   410.6 +#include "StdAfx.h"
   410.7 +
   410.8 +#include "Common/MyCom.h"
   410.9 +
  410.10 +#include "StreamUtils.h"
  410.11 +#include "MemBlocks.h"
  410.12 +
  410.13 +bool CMemBlockManager::AllocateSpace(size_t numBlocks)
  410.14 +{
  410.15 +  FreeSpace();
  410.16 +  if (_blockSize < sizeof(void *) || numBlocks < 1)
  410.17 +    return false;
  410.18 +  size_t totalSize = numBlocks * _blockSize;
  410.19 +  if (totalSize / _blockSize != numBlocks)
  410.20 +    return false;
  410.21 +  _data = ::MidAlloc(totalSize);
  410.22 +  if (_data == 0)
  410.23 +    return false;
  410.24 +  Byte *p = (Byte *)_data;
  410.25 +  for (size_t i = 0; i + 1 < numBlocks; i++, p += _blockSize)
  410.26 +    *(Byte **)p = (p + _blockSize);
  410.27 +  *(Byte **)p = 0;
  410.28 +  _headFree = _data;
  410.29 +  return true;
  410.30 +}
  410.31 +
  410.32 +void CMemBlockManager::FreeSpace()
  410.33 +{
  410.34 +  ::MidFree(_data);
  410.35 +  _data = 0;
  410.36 +  _headFree= 0;
  410.37 +}
  410.38 +
  410.39 +void *CMemBlockManager::AllocateBlock()
  410.40 +{
  410.41 +  if (_headFree == 0)
  410.42 +    return 0;
  410.43 +  void *p = _headFree;
  410.44 +  _headFree = *(void **)_headFree;
  410.45 +  return p;
  410.46 +}
  410.47 +
  410.48 +void CMemBlockManager::FreeBlock(void *p)
  410.49 +{
  410.50 +  if (p == 0)
  410.51 +    return;
  410.52 +  *(void **)p = _headFree;
  410.53 +  _headFree = p;
  410.54 +}
  410.55 +
  410.56 +
  410.57 +HRes CMemBlockManagerMt::AllocateSpace(size_t numBlocks, size_t numNoLockBlocks)
  410.58 +{
  410.59 +  if (numNoLockBlocks > numBlocks)
  410.60 +    return E_INVALIDARG;
  410.61 +  if (!CMemBlockManager::AllocateSpace(numBlocks))
  410.62 +    return E_OUTOFMEMORY;
  410.63 +  size_t numLockBlocks = numBlocks - numNoLockBlocks;
  410.64 +  Semaphore.Close();
  410.65 +  return Semaphore.Create((LONG)numLockBlocks, (LONG)numLockBlocks);
  410.66 +}
  410.67 +
  410.68 +HRes CMemBlockManagerMt::AllocateSpaceAlways(size_t desiredNumberOfBlocks, size_t numNoLockBlocks)
  410.69 +{
  410.70 +  if (numNoLockBlocks > desiredNumberOfBlocks)
  410.71 +    return E_INVALIDARG;
  410.72 +  for (;;)
  410.73 +  {
  410.74 +    if (AllocateSpace(desiredNumberOfBlocks, numNoLockBlocks) == 0)
  410.75 +      return 0;
  410.76 +    if (desiredNumberOfBlocks == numNoLockBlocks)
  410.77 +      return E_OUTOFMEMORY;
  410.78 +    desiredNumberOfBlocks = numNoLockBlocks + ((desiredNumberOfBlocks - numNoLockBlocks) >> 1);
  410.79 +  }
  410.80 +}
  410.81 +
  410.82 +void CMemBlockManagerMt::FreeSpace()
  410.83 +{
  410.84 +  Semaphore.Close();
  410.85 +  CMemBlockManager::FreeSpace();
  410.86 +}
  410.87 +
  410.88 +void *CMemBlockManagerMt::AllocateBlock()
  410.89 +{
  410.90 +  // Semaphore.Lock();
  410.91 +  NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
  410.92 +  return CMemBlockManager::AllocateBlock();
  410.93 +}
  410.94 +
  410.95 +void CMemBlockManagerMt::FreeBlock(void *p, bool lockMode)
  410.96 +{
  410.97 +  if (p == 0)
  410.98 +    return;
  410.99 +  {
 410.100 +    NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
 410.101 +    CMemBlockManager::FreeBlock(p);
 410.102 +  }
 410.103 +  if (lockMode)
 410.104 +    Semaphore.Release();
 410.105 +}
 410.106 +
 410.107 +void CMemBlocks::Free(CMemBlockManagerMt *manager)
 410.108 +{
 410.109 +  while(Blocks.Size() > 0)
 410.110 +  {
 410.111 +    manager->FreeBlock(Blocks.Back());
 410.112 +    Blocks.DeleteBack();
 410.113 +  }
 410.114 +  TotalSize = 0;
 410.115 +}
 410.116 +
 410.117 +void CMemBlocks::FreeOpt(CMemBlockManagerMt *manager)
 410.118 +{
 410.119 +  Free(manager);
 410.120 +  Blocks.ClearAndFree();
 410.121 +}
 410.122 +
 410.123 +HRESULT CMemBlocks::WriteToStream(size_t blockSize, ISequentialOutStream *outStream) const
 410.124 +{
 410.125 +  UInt64 totalSize = TotalSize;
 410.126 +  for (int blockIndex = 0; totalSize > 0; blockIndex++)
 410.127 +  {
 410.128 +    UInt32 curSize = (UInt32)blockSize;
 410.129 +    if (totalSize < curSize)
 410.130 +      curSize = (UInt32)totalSize;
 410.131 +    if (blockIndex >= Blocks.Size())
 410.132 +      return E_FAIL;
 410.133 +    RINOK(WriteStream(outStream, Blocks[blockIndex], curSize));
 410.134 +    totalSize -= curSize;
 410.135 +  }
 410.136 +  return S_OK;
 410.137 +}
 410.138 +
 410.139 +
 410.140 +void CMemLockBlocks::FreeBlock(int index, CMemBlockManagerMt *memManager)
 410.141 +{
 410.142 +  memManager->FreeBlock(Blocks[index], LockMode);
 410.143 +  Blocks[index] = 0;
 410.144 +}
 410.145 +
 410.146 +void CMemLockBlocks::Free(CMemBlockManagerMt *memManager)
 410.147 +{
 410.148 +  while (Blocks.Size() > 0)
 410.149 +  {
 410.150 +    FreeBlock(Blocks.Size() - 1, memManager);
 410.151 +    Blocks.DeleteBack();
 410.152 +  }
 410.153 +  TotalSize = 0;
 410.154 +}
 410.155 +
 410.156 +HRes CMemLockBlocks::SwitchToNoLockMode(CMemBlockManagerMt *memManager)
 410.157 +{
 410.158 +  if (LockMode)
 410.159 +  {
 410.160 +    if (Blocks.Size() > 0)
 410.161 +    {
 410.162 +      RINOK(memManager->ReleaseLockedBlocks(Blocks.Size()));
 410.163 +    }
 410.164 +    LockMode = false;
 410.165 +  }
 410.166 +  return 0;
 410.167 +}
 410.168 +
 410.169 +void CMemLockBlocks::Detach(CMemLockBlocks &blocks, CMemBlockManagerMt *memManager)
 410.170 +{
 410.171 +  blocks.Free(memManager);
 410.172 +  blocks.LockMode = LockMode;
 410.173 +  UInt64 totalSize = 0;
 410.174 +  size_t blockSize = memManager->GetBlockSize();
 410.175 +  for (int i = 0; i < Blocks.Size(); i++)
 410.176 +  {
 410.177 +    if (totalSize < TotalSize)
 410.178 +      blocks.Blocks.Add(Blocks[i]);
 410.179 +    else
 410.180 +      FreeBlock(i, memManager);
 410.181 +    Blocks[i] = 0;
 410.182 +    totalSize += blockSize;
 410.183 +  }
 410.184 +  blocks.TotalSize = TotalSize;
 410.185 +  Free(memManager);
 410.186 +}
   411.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   411.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/MemBlocks.h	Sat Mar 03 10:31:27 2012 -0600
   411.3 @@ -0,0 +1,77 @@
   411.4 +// MemBlocks.h
   411.5 +
   411.6 +#ifndef __MEMBLOCKS_H
   411.7 +#define __MEMBLOCKS_H
   411.8 +
   411.9 +extern "C"
  411.10 +{
  411.11 +#include "../../../C/Alloc.h"
  411.12 +}
  411.13 +
  411.14 +#include "Common/Types.h"
  411.15 +#include "Common/MyVector.h"
  411.16 +
  411.17 +#include "Windows/Synchronization.h"
  411.18 +
  411.19 +#include "../IStream.h"
  411.20 +
  411.21 +class CMemBlockManager
  411.22 +{
  411.23 +  void *_data;
  411.24 +  size_t _blockSize;
  411.25 +  void *_headFree;
  411.26 +public:
  411.27 +  CMemBlockManager(size_t blockSize = (1 << 20)): _data(0), _blockSize(blockSize), _headFree(0) {}
  411.28 +  ~CMemBlockManager() { FreeSpace(); }
  411.29 +
  411.30 +  bool AllocateSpace(size_t numBlocks);
  411.31 +  void FreeSpace();
  411.32 +  size_t GetBlockSize() const { return _blockSize; }
  411.33 +  void *AllocateBlock();
  411.34 +  void FreeBlock(void *p);
  411.35 +};
  411.36 +
  411.37 +
  411.38 +class CMemBlockManagerMt: public CMemBlockManager
  411.39 +{
  411.40 +  NWindows::NSynchronization::CCriticalSection _criticalSection;
  411.41 +public:
  411.42 +  NWindows::NSynchronization::CSemaphore Semaphore;
  411.43 +
  411.44 +  CMemBlockManagerMt(size_t blockSize = (1 << 20)): CMemBlockManager(blockSize) {}
  411.45 +  ~CMemBlockManagerMt() { FreeSpace(); }
  411.46 +
  411.47 +  HRes AllocateSpace(size_t numBlocks, size_t numNoLockBlocks = 0);
  411.48 +  HRes AllocateSpaceAlways(size_t desiredNumberOfBlocks, size_t numNoLockBlocks = 0);
  411.49 +  void FreeSpace();
  411.50 +  void *AllocateBlock();
  411.51 +  void FreeBlock(void *p, bool lockMode = true);
  411.52 +  HRes ReleaseLockedBlocks(int number) { return Semaphore.Release(number); }
  411.53 +};
  411.54 +
  411.55 +
  411.56 +class CMemBlocks
  411.57 +{
  411.58 +  void Free(CMemBlockManagerMt *manager);
  411.59 +public:
  411.60 +  CRecordVector<void *> Blocks;
  411.61 +  UInt64 TotalSize;
  411.62 +  
  411.63 +  CMemBlocks(): TotalSize(0) {}
  411.64 +
  411.65 +  void FreeOpt(CMemBlockManagerMt *manager);
  411.66 +  HRESULT WriteToStream(size_t blockSize, ISequentialOutStream *outStream) const;
  411.67 +};
  411.68 +
  411.69 +struct CMemLockBlocks: public CMemBlocks
  411.70 +{
  411.71 +  bool LockMode;
  411.72 +
  411.73 +  CMemLockBlocks(): LockMode(true) {};
  411.74 +  void Free(CMemBlockManagerMt *memManager);
  411.75 +  void FreeBlock(int index, CMemBlockManagerMt *memManager);
  411.76 +  HRes SwitchToNoLockMode(CMemBlockManagerMt *memManager);
  411.77 +  void Detach(CMemLockBlocks &blocks, CMemBlockManagerMt *memManager);
  411.78 +};
  411.79 +
  411.80 +#endif
   412.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   412.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/MethodId.cpp	Sat Mar 03 10:31:27 2012 -0600
   412.3 @@ -0,0 +1,27 @@
   412.4 +// MethodId.cpp
   412.5 +
   412.6 +#include "StdAfx.h"
   412.7 +
   412.8 +#include "MethodId.h"
   412.9 +#include "../../Common/MyString.h"
  412.10 +
  412.11 +static inline wchar_t GetHex(Byte value)
  412.12 +{
  412.13 +  return (wchar_t)((value < 10) ? ('0' + value) : ('A' + (value - 10)));
  412.14 +}
  412.15 +
  412.16 +UString ConvertMethodIdToString(UInt64 id)
  412.17 +{
  412.18 +  wchar_t s[32];
  412.19 +  int len = 32;
  412.20 +  s[--len] = 0;
  412.21 +  do
  412.22 +  {
  412.23 +    s[--len] = GetHex((Byte)id & 0xF);
  412.24 +    id >>= 4;
  412.25 +    s[--len] = GetHex((Byte)id & 0xF);
  412.26 +    id >>= 4;
  412.27 +  }
  412.28 +  while (id != 0);
  412.29 +  return s + len;
  412.30 +}
   413.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   413.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/MethodId.h	Sat Mar 03 10:31:27 2012 -0600
   413.3 @@ -0,0 +1,10 @@
   413.4 +// MethodId.h
   413.5 +
   413.6 +#ifndef __7Z_METHOD_ID_H
   413.7 +#define __7Z_METHOD_ID_H
   413.8 +
   413.9 +#include "../../Common/Types.h"
  413.10 +
  413.11 +typedef UInt64 CMethodId;
  413.12 +
  413.13 +#endif
   414.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   414.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/MethodProps.cpp	Sat Mar 03 10:31:27 2012 -0600
   414.3 @@ -0,0 +1,99 @@
   414.4 +// MethodProps.cpp
   414.5 +
   414.6 +#include "StdAfx.h"
   414.7 +
   414.8 +#include "../../Common/MyCom.h"
   414.9 +
  414.10 +#include "../ICoder.h"
  414.11 +
  414.12 +#include "MethodProps.h"
  414.13 +
  414.14 +static UInt64 k_LZMA = 0x030101;
  414.15 +// static UInt64 k_LZMA2 = 0x030102;
  414.16 +
  414.17 +HRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder)
  414.18 +{
  414.19 +  bool tryReduce = false;
  414.20 +  UInt32 reducedDictionarySize = 1 << 10;
  414.21 +  if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */))
  414.22 +  {
  414.23 +    for (;;)
  414.24 +    {
  414.25 +      const UInt32 step = (reducedDictionarySize >> 1);
  414.26 +      if (reducedDictionarySize >= *inSizeForReduce)
  414.27 +      {
  414.28 +        tryReduce = true;
  414.29 +        break;
  414.30 +      }
  414.31 +      reducedDictionarySize += step;
  414.32 +      if (reducedDictionarySize >= *inSizeForReduce)
  414.33 +      {
  414.34 +        tryReduce = true;
  414.35 +        break;
  414.36 +      }
  414.37 +      if (reducedDictionarySize >= ((UInt32)3 << 30))
  414.38 +        break;
  414.39 +      reducedDictionarySize += step;
  414.40 +    }
  414.41 +  }
  414.42 +
  414.43 +  {
  414.44 +    int numProps = method.Props.Size();
  414.45 +    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
  414.46 +    coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);
  414.47 +    if (setCoderProperties == NULL)
  414.48 +    {
  414.49 +      if (numProps != 0)
  414.50 +        return E_INVALIDARG;
  414.51 +    }
  414.52 +    else
  414.53 +    {
  414.54 +      CRecordVector<PROPID> propIDs;
  414.55 +      NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProps];
  414.56 +      HRESULT res = S_OK;
  414.57 +      try
  414.58 +      {
  414.59 +        for (int i = 0; i < numProps; i++)
  414.60 +        {
  414.61 +          const CProp &prop = method.Props[i];
  414.62 +          propIDs.Add(prop.Id);
  414.63 +          NWindows::NCOM::CPropVariant &value = values[i];
  414.64 +          value = prop.Value;
  414.65 +          // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal)
  414.66 +          if (tryReduce)
  414.67 +            if (prop.Id == NCoderPropID::kDictionarySize)
  414.68 +              if (value.vt == VT_UI4)
  414.69 +                if (reducedDictionarySize < value.ulVal)
  414.70 +            value.ulVal = reducedDictionarySize;
  414.71 +        }
  414.72 +        CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
  414.73 +        coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);
  414.74 +        res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProps);
  414.75 +      }
  414.76 +      catch(...)
  414.77 +      {
  414.78 +        delete []values;
  414.79 +        throw;
  414.80 +      }
  414.81 +      delete []values;
  414.82 +      RINOK(res);
  414.83 +    }
  414.84 +  }
  414.85 + 
  414.86 +  /*
  414.87 +  CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;
  414.88 +  coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);
  414.89 +  if (writeCoderProperties != NULL)
  414.90 +  {
  414.91 +    CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;
  414.92 +    CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
  414.93 +    outStreamSpec->Init();
  414.94 +    RINOK(writeCoderProperties->WriteCoderProperties(outStream));
  414.95 +    size_t size = outStreamSpec->GetSize();
  414.96 +    filterProps.SetCapacity(size);
  414.97 +    memmove(filterProps, outStreamSpec->GetBuffer(), size);
  414.98 +  }
  414.99 +  */
 414.100 +  return S_OK;
 414.101 +}
 414.102 +
   415.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   415.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/MethodProps.h	Sat Mar 03 10:31:27 2012 -0600
   415.3 @@ -0,0 +1,41 @@
   415.4 +// MethodProps.h
   415.5 +
   415.6 +#ifndef __7Z_METHOD_PROPS_H
   415.7 +#define __7Z_METHOD_PROPS_H
   415.8 +
   415.9 +#include "../../Common/MyVector.h"
  415.10 +
  415.11 +#include "../../Windows/PropVariant.h"
  415.12 +
  415.13 +#include "MethodId.h"
  415.14 +
  415.15 +struct CProp
  415.16 +{
  415.17 +  PROPID Id;
  415.18 +  NWindows::NCOM::CPropVariant Value;
  415.19 +};
  415.20 +
  415.21 +struct CMethod
  415.22 +{
  415.23 +  CMethodId Id;
  415.24 +  CObjectVector<CProp> Props;
  415.25 +};
  415.26 +
  415.27 +struct CMethodsMode
  415.28 +{
  415.29 +  CObjectVector<CMethod> Methods;
  415.30 +  #ifdef COMPRESS_MT
  415.31 +  UInt32 NumThreads;
  415.32 +  #endif
  415.33 +
  415.34 +  CMethodsMode()
  415.35 +      #ifdef COMPRESS_MT
  415.36 +      : NumThreads(1)
  415.37 +      #endif
  415.38 +  {}
  415.39 +  bool IsEmpty() const { return Methods.IsEmpty() ; }
  415.40 +};
  415.41 +
  415.42 +HRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder);
  415.43 +
  415.44 +#endif
   416.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   416.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/OffsetStream.cpp	Sat Mar 03 10:31:27 2012 -0600
   416.3 @@ -0,0 +1,35 @@
   416.4 +// OffsetStream.cpp
   416.5 +
   416.6 +#include "StdAfx.h"
   416.7 +
   416.8 +#include "Common/Defs.h"
   416.9 +#include "OffsetStream.h"
  416.10 +
  416.11 +HRESULT COffsetOutStream::Init(IOutStream *stream, UInt64 offset)
  416.12 +{
  416.13 +  _offset = offset;
  416.14 +  _stream = stream;
  416.15 +  return _stream->Seek(offset, STREAM_SEEK_SET, NULL);
  416.16 +}
  416.17 +
  416.18 +STDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
  416.19 +{
  416.20 +  return _stream->Write(data, size, processedSize);
  416.21 +}
  416.22 +
  416.23 +STDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin,
  416.24 +    UInt64 *newPosition)
  416.25 +{
  416.26 +  UInt64 absoluteNewPosition;
  416.27 +  if (seekOrigin == STREAM_SEEK_SET)
  416.28 +    offset += _offset;
  416.29 +  HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);
  416.30 +  if (newPosition != NULL)
  416.31 +    *newPosition = absoluteNewPosition - _offset;
  416.32 +  return result;
  416.33 +}
  416.34 +
  416.35 +STDMETHODIMP COffsetOutStream::SetSize(Int64 newSize)
  416.36 +{
  416.37 +  return _stream->SetSize(_offset + newSize);
  416.38 +}
   417.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   417.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/OffsetStream.h	Sat Mar 03 10:31:27 2012 -0600
   417.3 @@ -0,0 +1,25 @@
   417.4 +// OffsetStream.h
   417.5 +
   417.6 +#ifndef __OFFSETSTREAM_H
   417.7 +#define __OFFSETSTREAM_H
   417.8 +
   417.9 +#include "Common/MyCom.h"
  417.10 +#include "../IStream.h"
  417.11 +
  417.12 +class COffsetOutStream:
  417.13 +  public IOutStream,
  417.14 +  public CMyUnknownImp
  417.15 +{
  417.16 +  UInt64 _offset;
  417.17 +  CMyComPtr<IOutStream> _stream;
  417.18 +public:
  417.19 +  HRESULT Init(IOutStream *stream, UInt64 offset);
  417.20 +  
  417.21 +  MY_UNKNOWN_IMP
  417.22 +
  417.23 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  417.24 +  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
  417.25 +  STDMETHOD(SetSize)(Int64 newSize);
  417.26 +};
  417.27 +
  417.28 +#endif
   418.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   418.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/OutBuffer.cpp	Sat Mar 03 10:31:27 2012 -0600
   418.3 @@ -0,0 +1,119 @@
   418.4 +// OutByte.cpp
   418.5 +
   418.6 +#include "StdAfx.h"
   418.7 +
   418.8 +#include "OutBuffer.h"
   418.9 +
  418.10 +extern "C"
  418.11 +{
  418.12 +  #include "../../../C/Alloc.h"
  418.13 +}
  418.14 +
  418.15 +bool COutBuffer::Create(UInt32 bufferSize)
  418.16 +{
  418.17 +  const UInt32 kMinBlockSize = 1;
  418.18 +  if (bufferSize < kMinBlockSize)
  418.19 +    bufferSize = kMinBlockSize;
  418.20 +  if (_buffer != 0 && _bufferSize == bufferSize)
  418.21 +    return true;
  418.22 +  Free();
  418.23 +  _bufferSize = bufferSize;
  418.24 +  _buffer = (Byte *)::MidAlloc(bufferSize);
  418.25 +  return (_buffer != 0);
  418.26 +}
  418.27 +
  418.28 +void COutBuffer::Free()
  418.29 +{
  418.30 +  ::MidFree(_buffer);
  418.31 +  _buffer = 0;
  418.32 +}
  418.33 +
  418.34 +void COutBuffer::SetStream(ISequentialOutStream *stream)
  418.35 +{
  418.36 +  _stream = stream;
  418.37 +}
  418.38 +
  418.39 +void COutBuffer::Init()
  418.40 +{
  418.41 +  _streamPos = 0;
  418.42 +  _limitPos = _bufferSize;
  418.43 +  _pos = 0;
  418.44 +  _processedSize = 0;
  418.45 +  _overDict = false;
  418.46 +  #ifdef _NO_EXCEPTIONS
  418.47 +  ErrorCode = S_OK;
  418.48 +  #endif
  418.49 +}
  418.50 +
  418.51 +UInt64 COutBuffer::GetProcessedSize() const
  418.52 +{
  418.53 +  UInt64 res = _processedSize + _pos - _streamPos;
  418.54 +  if (_streamPos > _pos)
  418.55 +    res += _bufferSize;
  418.56 +  return res;
  418.57 +}
  418.58 +
  418.59 +
  418.60 +HRESULT COutBuffer::FlushPart()
  418.61 +{
  418.62 +  // _streamPos < _bufferSize
  418.63 +  UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos);
  418.64 +  HRESULT result = S_OK;
  418.65 +  #ifdef _NO_EXCEPTIONS
  418.66 +  result = ErrorCode;
  418.67 +  #endif
  418.68 +  if (_buffer2 != 0)
  418.69 +  {
  418.70 +    memmove(_buffer2, _buffer + _streamPos, size);
  418.71 +    _buffer2 += size;
  418.72 +  }
  418.73 +
  418.74 +  if (_stream != 0
  418.75 +      #ifdef _NO_EXCEPTIONS
  418.76 +      && (ErrorCode == S_OK)
  418.77 +      #endif
  418.78 +     )
  418.79 +  {
  418.80 +    UInt32 processedSize = 0;
  418.81 +    result = _stream->Write(_buffer + _streamPos, size, &processedSize);
  418.82 +    size = processedSize;
  418.83 +  }
  418.84 +  _streamPos += size;
  418.85 +  if (_streamPos == _bufferSize)
  418.86 +    _streamPos = 0;
  418.87 +  if (_pos == _bufferSize)
  418.88 +  {
  418.89 +    _overDict = true;
  418.90 +    _pos = 0;
  418.91 +  }
  418.92 +  _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize;
  418.93 +  _processedSize += size;
  418.94 +  return result;
  418.95 +}
  418.96 +
  418.97 +HRESULT COutBuffer::Flush()
  418.98 +{
  418.99 +  #ifdef _NO_EXCEPTIONS
 418.100 +  if (ErrorCode != S_OK)
 418.101 +    return ErrorCode;
 418.102 +  #endif
 418.103 +
 418.104 +  while(_streamPos != _pos)
 418.105 +  {
 418.106 +    HRESULT result = FlushPart();
 418.107 +    if (result != S_OK)
 418.108 +      return result;
 418.109 +  }
 418.110 +  return S_OK;
 418.111 +}
 418.112 +
 418.113 +void COutBuffer::FlushWithCheck()
 418.114 +{
 418.115 +  HRESULT result = Flush();
 418.116 +  #ifdef _NO_EXCEPTIONS
 418.117 +  ErrorCode = result;
 418.118 +  #else
 418.119 +  if (result != S_OK)
 418.120 +    throw COutBufferException(result);
 418.121 +  #endif
 418.122 +}
   419.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   419.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/OutBuffer.h	Sat Mar 03 10:31:27 2012 -0600
   419.3 @@ -0,0 +1,64 @@
   419.4 +// OutBuffer.h
   419.5 +
   419.6 +#ifndef __OUTBUFFER_H
   419.7 +#define __OUTBUFFER_H
   419.8 +
   419.9 +#include "../IStream.h"
  419.10 +#include "../../Common/MyCom.h"
  419.11 +#include "../../Common/MyException.h"
  419.12 +
  419.13 +#ifndef _NO_EXCEPTIONS
  419.14 +struct COutBufferException: public CSystemException
  419.15 +{
  419.16 +  COutBufferException(HRESULT errorCode): CSystemException(errorCode) {}
  419.17 +};
  419.18 +#endif
  419.19 +
  419.20 +class COutBuffer
  419.21 +{
  419.22 +protected:
  419.23 +  Byte *_buffer;
  419.24 +  UInt32 _pos;
  419.25 +  UInt32 _limitPos;
  419.26 +  UInt32 _streamPos;
  419.27 +  UInt32 _bufferSize;
  419.28 +  CMyComPtr<ISequentialOutStream> _stream;
  419.29 +  UInt64 _processedSize;
  419.30 +  Byte  *_buffer2;
  419.31 +  bool _overDict;
  419.32 +
  419.33 +  HRESULT FlushPart();
  419.34 +public:
  419.35 +  #ifdef _NO_EXCEPTIONS
  419.36 +  HRESULT ErrorCode;
  419.37 +  #endif
  419.38 +
  419.39 +  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}
  419.40 +  ~COutBuffer() { Free(); }
  419.41 +  
  419.42 +  bool Create(UInt32 bufferSize);
  419.43 +  void Free();
  419.44 +
  419.45 +  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }
  419.46 +  void SetStream(ISequentialOutStream *stream);
  419.47 +  void Init();
  419.48 +  HRESULT Flush();
  419.49 +  void FlushWithCheck();
  419.50 +  void ReleaseStream() {  _stream.Release(); }
  419.51 +
  419.52 +  void WriteByte(Byte b)
  419.53 +  {
  419.54 +    _buffer[_pos++] = b;
  419.55 +    if(_pos == _limitPos)
  419.56 +      FlushWithCheck();
  419.57 +  }
  419.58 +  void WriteBytes(const void *data, size_t size)
  419.59 +  {
  419.60 +    for (size_t i = 0; i < size; i++)
  419.61 +      WriteByte(((const Byte *)data)[i]);
  419.62 +  }
  419.63 +
  419.64 +  UInt64 GetProcessedSize() const;
  419.65 +};
  419.66 +
  419.67 +#endif
   420.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   420.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/OutMemStream.cpp	Sat Mar 03 10:31:27 2012 -0600
   420.3 @@ -0,0 +1,142 @@
   420.4 +// OutMemStream.cpp
   420.5 +
   420.6 +#include "StdAfx.h"
   420.7 +
   420.8 +#include "OutMemStream.h"
   420.9 +
  420.10 +void COutMemStream::Free()
  420.11 +{
  420.12 +  Blocks.Free(_memManager);
  420.13 +  Blocks.LockMode = true;
  420.14 +}
  420.15 +
  420.16 +void COutMemStream::Init()
  420.17 +{
  420.18 +  WriteToRealStreamEvent.Reset();
  420.19 +  _unlockEventWasSent = false;
  420.20 +  _realStreamMode = false;
  420.21 +  Free();
  420.22 +  _curBlockPos = 0;
  420.23 +  _curBlockIndex = 0;
  420.24 +}
  420.25 +
  420.26 +void COutMemStream::DetachData(CMemLockBlocks &blocks)
  420.27 +{
  420.28 +  Blocks.Detach(blocks, _memManager);
  420.29 +  Free();
  420.30 +}
  420.31 +
  420.32 +
  420.33 +HRESULT COutMemStream::WriteToRealStream()
  420.34 +{
  420.35 +  RINOK(Blocks.WriteToStream(_memManager->GetBlockSize(), OutSeqStream));
  420.36 +  Blocks.Free(_memManager);
  420.37 +  return S_OK;
  420.38 +}
  420.39 +
  420.40 +STDMETHODIMP COutMemStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
  420.41 +{
  420.42 +  if (_realStreamMode)
  420.43 +    return OutSeqStream->Write(data, size, processedSize);
  420.44 +  if (processedSize != 0)
  420.45 +    *processedSize = 0;
  420.46 +  while(size != 0)
  420.47 +  {
  420.48 +    if ((int)_curBlockIndex < Blocks.Blocks.Size())
  420.49 +    {
  420.50 +      Byte *p = (Byte *)Blocks.Blocks[(int)_curBlockIndex] + _curBlockPos;
  420.51 +      size_t curSize = _memManager->GetBlockSize() - _curBlockPos;
  420.52 +      if (size < curSize)
  420.53 +        curSize = size;
  420.54 +      memmove(p, data, curSize);
  420.55 +      if (processedSize != 0)
  420.56 +        *processedSize += (UInt32)curSize;
  420.57 +      data = (const void *)((const Byte *)data + curSize);
  420.58 +      size -= (UInt32)curSize;
  420.59 +      _curBlockPos += curSize;
  420.60 +
  420.61 +      UInt64 pos64 = GetPos();
  420.62 +      if (pos64 > Blocks.TotalSize)
  420.63 +        Blocks.TotalSize = pos64;
  420.64 +      if (_curBlockPos == _memManager->GetBlockSize())
  420.65 +      {
  420.66 +        _curBlockIndex++;
  420.67 +        _curBlockPos = 0;
  420.68 +      }
  420.69 +      continue;
  420.70 +    }
  420.71 +    HANDLE events[3] = { StopWritingEvent, WriteToRealStreamEvent, /* NoLockEvent, */ _memManager->Semaphore };
  420.72 +    DWORD waitResult = ::WaitForMultipleObjects((Blocks.LockMode ? 3 : 2), events, FALSE, INFINITE);
  420.73 +    switch (waitResult)
  420.74 +    {
  420.75 +      case (WAIT_OBJECT_0 + 0):
  420.76 +        return StopWriteResult;
  420.77 +      case (WAIT_OBJECT_0 + 1):
  420.78 +      {
  420.79 +        _realStreamMode = true;
  420.80 +        RINOK(WriteToRealStream());
  420.81 +        UInt32 processedSize2;
  420.82 +        HRESULT res = OutSeqStream->Write(data, size, &processedSize2);
  420.83 +        if (processedSize != 0)
  420.84 +          *processedSize += processedSize2;
  420.85 +        return res;
  420.86 +      }
  420.87 +      /*
  420.88 +      case (WAIT_OBJECT_0 + 2):
  420.89 +      {
  420.90 +        // it has bug: no write.
  420.91 +        if (!Blocks.SwitchToNoLockMode(_memManager))
  420.92 +          return E_FAIL;
  420.93 +        break;
  420.94 +      }
  420.95 +      */
  420.96 +      case (WAIT_OBJECT_0 + 2):
  420.97 +        break;
  420.98 +      default:
  420.99 +        return E_FAIL;
 420.100 +    }
 420.101 +    Blocks.Blocks.Add(_memManager->AllocateBlock());
 420.102 +    if (Blocks.Blocks.Back() == 0)
 420.103 +      return E_FAIL;
 420.104 +  }
 420.105 +  return S_OK;
 420.106 +}
 420.107 +
 420.108 +STDMETHODIMP COutMemStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
 420.109 +{
 420.110 +  if (_realStreamMode)
 420.111 +  {
 420.112 +    if (!OutStream)
 420.113 +      return E_FAIL;
 420.114 +    return OutStream->Seek(offset, seekOrigin, newPosition);
 420.115 +  }
 420.116 +  if (seekOrigin == STREAM_SEEK_CUR)
 420.117 +  {
 420.118 +    if (offset != 0)
 420.119 +      return E_NOTIMPL;
 420.120 +  }
 420.121 +  else if (seekOrigin == STREAM_SEEK_SET)
 420.122 +  {
 420.123 +    if (offset != 0)
 420.124 +      return E_NOTIMPL;
 420.125 +    _curBlockIndex = 0;
 420.126 +    _curBlockPos = 0;
 420.127 +  }
 420.128 +  else
 420.129 +    return E_NOTIMPL;
 420.130 +  if (newPosition != 0)
 420.131 +    *newPosition = GetPos();
 420.132 +  return S_OK;
 420.133 +}
 420.134 +
 420.135 +STDMETHODIMP COutMemStream::SetSize(Int64 newSize)
 420.136 +{
 420.137 +  if (_realStreamMode)
 420.138 +  {
 420.139 +    if (!OutStream)
 420.140 +      return E_FAIL;
 420.141 +    return OutStream->SetSize(newSize);
 420.142 +  }
 420.143 +  Blocks.TotalSize = newSize;
 420.144 +  return S_OK;
 420.145 +}
   421.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   421.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/OutMemStream.h	Sat Mar 03 10:31:27 2012 -0600
   421.3 @@ -0,0 +1,96 @@
   421.4 +// OutMemStream.h
   421.5 +
   421.6 +#ifndef __OUTMEMSTREAM_H
   421.7 +#define __OUTMEMSTREAM_H
   421.8 +
   421.9 +#include "Common/MyCom.h"
  421.10 +#include "MemBlocks.h"
  421.11 +
  421.12 +class COutMemStream:
  421.13 +  public IOutStream,
  421.14 +  public CMyUnknownImp
  421.15 +{
  421.16 +  CMemBlockManagerMt *_memManager;
  421.17 +  size_t _curBlockIndex;
  421.18 +  size_t _curBlockPos;
  421.19 +  bool _realStreamMode;
  421.20 +
  421.21 +  bool _unlockEventWasSent;
  421.22 +  NWindows::NSynchronization::CAutoResetEvent StopWritingEvent;
  421.23 +  NWindows::NSynchronization::CAutoResetEvent WriteToRealStreamEvent;
  421.24 +  // NWindows::NSynchronization::CAutoResetEvent NoLockEvent;
  421.25 +
  421.26 +  HRESULT StopWriteResult;
  421.27 +  CMemLockBlocks Blocks;
  421.28 +
  421.29 +  UInt64 GetPos() const { return (UInt64)_curBlockIndex * _memManager->GetBlockSize() + _curBlockPos; }
  421.30 +
  421.31 +  CMyComPtr<ISequentialOutStream> OutSeqStream;
  421.32 +  CMyComPtr<IOutStream> OutStream;
  421.33 +
  421.34 +public:
  421.35 +
  421.36 +  HRes CreateEvents()
  421.37 +  {
  421.38 +    RINOK(StopWritingEvent.CreateIfNotCreated());
  421.39 +    return WriteToRealStreamEvent.CreateIfNotCreated();
  421.40 +  }
  421.41 +
  421.42 +  void SetOutStream(IOutStream *outStream)
  421.43 +  {
  421.44 +    OutStream = outStream;
  421.45 +    OutSeqStream = outStream;
  421.46 +  }
  421.47 +
  421.48 +  void SetSeqOutStream(ISequentialOutStream *outStream)
  421.49 +  {
  421.50 +    OutStream = NULL;
  421.51 +    OutSeqStream = outStream;
  421.52 +  }
  421.53 +
  421.54 +  void ReleaseOutStream()
  421.55 +  {
  421.56 +    OutStream.Release();
  421.57 +    OutSeqStream.Release();
  421.58 +  }
  421.59 +
  421.60 +  COutMemStream(CMemBlockManagerMt *memManager): _memManager(memManager)  { }
  421.61 +
  421.62 +  ~COutMemStream() { Free(); }
  421.63 +  void Free();
  421.64 +
  421.65 +  void Init();
  421.66 +  HRESULT WriteToRealStream();
  421.67 +
  421.68 +  void DetachData(CMemLockBlocks &blocks);
  421.69 +
  421.70 +  bool WasUnlockEventSent() const { return _unlockEventWasSent; }
  421.71 +
  421.72 +  void SetRealStreamMode()
  421.73 +  {
  421.74 +    _unlockEventWasSent = true;
  421.75 +    WriteToRealStreamEvent.Set();
  421.76 +  }
  421.77 +
  421.78 +  /*
  421.79 +  void SetNoLockMode()
  421.80 +  {
  421.81 +    _unlockEventWasSent = true;
  421.82 +    NoLockEvent.Set();
  421.83 +  }
  421.84 +  */
  421.85 +
  421.86 +  void StopWriting(HRESULT res)
  421.87 +  {
  421.88 +    StopWriteResult = res;
  421.89 +    StopWritingEvent.Set();
  421.90 +  }
  421.91 +
  421.92 +  MY_UNKNOWN_IMP
  421.93 +
  421.94 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  421.95 +  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
  421.96 +  STDMETHOD(SetSize)(Int64 newSize);
  421.97 +};
  421.98 +
  421.99 +#endif
   422.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   422.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/ProgressMt.cpp	Sat Mar 03 10:31:27 2012 -0600
   422.3 @@ -0,0 +1,53 @@
   422.4 +// ProgressMt.h
   422.5 +
   422.6 +#include "StdAfx.h"
   422.7 +
   422.8 +#include "ProgressMt.h"
   422.9 +
  422.10 +void CMtCompressProgressMixer::Init(int numItems, ICompressProgressInfo *progress)
  422.11 +{
  422.12 +  NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection);
  422.13 +  InSizes.Clear();
  422.14 +  OutSizes.Clear();
  422.15 +  for (int i = 0; i < numItems; i++)
  422.16 +  {
  422.17 +    InSizes.Add(0);
  422.18 +    OutSizes.Add(0);
  422.19 +  }
  422.20 +  TotalInSize = 0;
  422.21 +  TotalOutSize = 0;
  422.22 +  _progress = progress;
  422.23 +}
  422.24 +
  422.25 +void CMtCompressProgressMixer::Reinit(int index)
  422.26 +{
  422.27 +  NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection);
  422.28 +  InSizes[index] = 0;
  422.29 +  OutSizes[index] = 0;
  422.30 +}
  422.31 +
  422.32 +HRESULT CMtCompressProgressMixer::SetRatioInfo(int index, const UInt64 *inSize, const UInt64 *outSize)
  422.33 +{
  422.34 +  NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection);
  422.35 +  if (inSize != 0)
  422.36 +  {
  422.37 +    UInt64 diff = *inSize - InSizes[index];
  422.38 +    InSizes[index] = *inSize;
  422.39 +    TotalInSize += diff;
  422.40 +  }
  422.41 +  if (outSize != 0)
  422.42 +  {
  422.43 +    UInt64 diff = *outSize - OutSizes[index];
  422.44 +    OutSizes[index] = *outSize;
  422.45 +    TotalOutSize += diff;
  422.46 +  }
  422.47 +  if (_progress)
  422.48 +    return _progress->SetRatioInfo(&TotalInSize, &TotalOutSize);
  422.49 +  return S_OK;
  422.50 +}
  422.51 +
  422.52 +
  422.53 +STDMETHODIMP CMtCompressProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
  422.54 +{
  422.55 +  return _progress->SetRatioInfo(_index, inSize, outSize);
  422.56 +}
   423.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   423.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/ProgressMt.h	Sat Mar 03 10:31:27 2012 -0600
   423.3 @@ -0,0 +1,46 @@
   423.4 +// ProgressMt.h
   423.5 +
   423.6 +#ifndef __PROGRESSMT_H
   423.7 +#define __PROGRESSMT_H
   423.8 +
   423.9 +#include "../../Common/MyCom.h"
  423.10 +#include "../../Common/MyVector.h"
  423.11 +#include "../../Windows/Synchronization.h"
  423.12 +
  423.13 +#include "../ICoder.h"
  423.14 +#include "../IProgress.h"
  423.15 +
  423.16 +class CMtCompressProgressMixer
  423.17 +{
  423.18 +  CMyComPtr<ICompressProgressInfo> _progress;
  423.19 +  CRecordVector<UInt64> InSizes;
  423.20 +  CRecordVector<UInt64> OutSizes;
  423.21 +  UInt64 TotalInSize;
  423.22 +  UInt64 TotalOutSize;
  423.23 +public:
  423.24 +  NWindows::NSynchronization::CCriticalSection CriticalSection;
  423.25 +  void Init(int numItems, ICompressProgressInfo *progress);
  423.26 +  void Reinit(int index);
  423.27 +  HRESULT SetRatioInfo(int index, const UInt64 *inSize, const UInt64 *outSize);
  423.28 +};
  423.29 +
  423.30 +class CMtCompressProgress:
  423.31 +  public ICompressProgressInfo,
  423.32 +  public CMyUnknownImp
  423.33 +{
  423.34 +  CMtCompressProgressMixer *_progress;
  423.35 +  int _index;
  423.36 +public:
  423.37 +  void Init(CMtCompressProgressMixer *progress, int index)
  423.38 +  {
  423.39 +    _progress = progress;
  423.40 +    _index = index;
  423.41 +  }
  423.42 +  void Reinit() { _progress->Reinit(_index); }
  423.43 +
  423.44 +  MY_UNKNOWN_IMP
  423.45 +
  423.46 +  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
  423.47 +};
  423.48 +
  423.49 +#endif
   424.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   424.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/ProgressUtils.cpp	Sat Mar 03 10:31:27 2012 -0600
   424.3 @@ -0,0 +1,42 @@
   424.4 +// ProgressUtils.h
   424.5 +
   424.6 +#include "StdAfx.h"
   424.7 +
   424.8 +#include "ProgressUtils.h"
   424.9 +
  424.10 +CLocalProgress::CLocalProgress()
  424.11 +{
  424.12 +  ProgressOffset = InSize = OutSize = 0;
  424.13 +  SendRatio = SendProgress = true;
  424.14 +}
  424.15 +
  424.16 +void CLocalProgress::Init(IProgress *progress, bool inSizeIsMain)
  424.17 +{
  424.18 +  _ratioProgress.Release();
  424.19 +  _progress = progress;
  424.20 +  _progress.QueryInterface(IID_ICompressProgressInfo, &_ratioProgress);
  424.21 +  _inSizeIsMain = inSizeIsMain;
  424.22 +}
  424.23 +
  424.24 +STDMETHODIMP CLocalProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
  424.25 +{
  424.26 +  UInt64 inSizeNew = InSize, outSizeNew = OutSize;
  424.27 +  if (inSize)
  424.28 +    inSizeNew += (*inSize);
  424.29 +  if (outSize)
  424.30 +    outSizeNew += (*outSize);
  424.31 +  if (SendRatio && _ratioProgress)
  424.32 +  {
  424.33 +    RINOK(_ratioProgress->SetRatioInfo(&inSizeNew, &outSizeNew));
  424.34 +  }
  424.35 +  inSizeNew += ProgressOffset;
  424.36 +  outSizeNew += ProgressOffset;
  424.37 +  if (SendProgress)
  424.38 +    return _progress->SetCompleted(_inSizeIsMain ? &inSizeNew : &outSizeNew);
  424.39 +  return S_OK;
  424.40 +}
  424.41 +
  424.42 +HRESULT CLocalProgress::SetCur()
  424.43 +{
  424.44 +  return SetRatioInfo(NULL, NULL);
  424.45 +}
   425.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   425.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/ProgressUtils.h	Sat Mar 03 10:31:27 2012 -0600
   425.3 @@ -0,0 +1,34 @@
   425.4 +// ProgressUtils.h
   425.5 +
   425.6 +#ifndef __PROGRESSUTILS_H
   425.7 +#define __PROGRESSUTILS_H
   425.8 +
   425.9 +#include "../../Common/MyCom.h"
  425.10 +
  425.11 +#include "../ICoder.h"
  425.12 +#include "../IProgress.h"
  425.13 +
  425.14 +class CLocalProgress:
  425.15 +  public ICompressProgressInfo,
  425.16 +  public CMyUnknownImp
  425.17 +{
  425.18 +  CMyComPtr<IProgress> _progress;
  425.19 +  CMyComPtr<ICompressProgressInfo> _ratioProgress;
  425.20 +  bool _inSizeIsMain;
  425.21 +public:
  425.22 +  UInt64 ProgressOffset;
  425.23 +  UInt64 InSize;
  425.24 +  UInt64 OutSize;
  425.25 +  bool SendRatio;
  425.26 +  bool SendProgress;
  425.27 +
  425.28 +  CLocalProgress();
  425.29 +  void Init(IProgress *progress, bool inSizeIsMain);
  425.30 +  HRESULT SetCur();
  425.31 +
  425.32 +  MY_UNKNOWN_IMP
  425.33 +
  425.34 +  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
  425.35 +};
  425.36 +
  425.37 +#endif
   426.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   426.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/RegisterArc.h	Sat Mar 03 10:31:27 2012 -0600
   426.3 @@ -0,0 +1,33 @@
   426.4 +// RegisterArc.h
   426.5 +
   426.6 +#ifndef __REGISTERARC_H
   426.7 +#define __REGISTERARC_H
   426.8 +
   426.9 +#include "../Archive/IArchive.h"
  426.10 +#include "DeclareArcs.h"
  426.11 +
  426.12 +typedef IInArchive * (*CreateInArchiveP)();
  426.13 +typedef IOutArchive * (*CreateOutArchiveP)();
  426.14 +
  426.15 +struct CArcInfo
  426.16 +{
  426.17 +  const wchar_t *Name;
  426.18 +  const wchar_t *Ext;
  426.19 +  const wchar_t *AddExt;
  426.20 +  Byte ClassId;
  426.21 +  Byte Signature[16];
  426.22 +  int SignatureSize;
  426.23 +  bool KeepName;
  426.24 +  CreateInArchiveP CreateInArchive;
  426.25 +  CreateOutArchiveP CreateOutArchive;
  426.26 +};
  426.27 +
  426.28 +void RegisterArc(const CArcInfo *arcInfo);
  426.29 +
  426.30 +#define REGISTER_ARC(x) CRegister##x::CRegister##x() { RegisterArc(&g_ArcInfo); } \
  426.31 +    CRegister##x g_RegisterArc##x;
  426.32 +
  426.33 +#define REGISTER_ARCN(x,n) CRegister##x##n::CRegister##x##n() { RegisterArc(&g_ArcInfo##n); } \
  426.34 +	CRegister##x##n g_RegisterArc##n##x;
  426.35 +
  426.36 +#endif
   427.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   427.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/RegisterCodec.h	Sat Mar 03 10:31:27 2012 -0600
   427.3 @@ -0,0 +1,30 @@
   427.4 +// RegisterCodec.h
   427.5 +
   427.6 +#ifndef __REGISTERCODEC_H
   427.7 +#define __REGISTERCODEC_H
   427.8 +
   427.9 +#include "../Common/MethodId.h"
  427.10 +#include "DeclareCodecs.h"
  427.11 +
  427.12 +typedef void * (*CreateCodecP)();
  427.13 +struct CCodecInfo
  427.14 +{
  427.15 +  CreateCodecP CreateDecoder;
  427.16 +  CreateCodecP CreateEncoder;
  427.17 +  CMethodId Id;
  427.18 +  const wchar_t *Name;
  427.19 +  UInt32 NumInStreams;
  427.20 +  bool IsFilter;
  427.21 +};
  427.22 +
  427.23 +void RegisterCodec(const CCodecInfo *codecInfo);
  427.24 +
  427.25 +#define REGISTER_CODEC(x) CRegisterCodec##x::CRegisterCodec##x() { RegisterCodec(&g_CodecInfo); } \
  427.26 +    CRegisterCodec##x g_RegisterCodec##x;
  427.27 +
  427.28 +#define REGISTER_CODECS(x) CRegisterCodecs##x::CRegisterCodecs##x() { \
  427.29 +	for(int i=0;i<sizeof(g_CodecsInfo)/sizeof(*g_CodecsInfo);i++) \
  427.30 +		RegisterCodec(&g_CodecsInfo[i]); } \
  427.31 +	CRegisterCodecs##x g_RegisterCodecs##x;
  427.32 +
  427.33 +#endif
   428.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   428.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   428.3 @@ -0,0 +1,9 @@
   428.4 +// StdAfx.h
   428.5 +
   428.6 +#ifndef __STDAFX_H
   428.7 +#define __STDAFX_H
   428.8 +
   428.9 +#include "../../Common/MyWindows.h"
  428.10 +#include "../../Common/NewHandler.h"
  428.11 +
  428.12 +#endif
   429.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   429.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/StreamBinder.cpp	Sat Mar 03 10:31:27 2012 -0600
   429.3 @@ -0,0 +1,150 @@
   429.4 +// StreamBinder.cpp
   429.5 +
   429.6 +#include "StdAfx.h"
   429.7 +
   429.8 +#include "StreamBinder.h"
   429.9 +#include "../../Common/Defs.h"
  429.10 +#include "../../Common/MyCom.h"
  429.11 +
  429.12 +using namespace NWindows;
  429.13 +using namespace NSynchronization;
  429.14 +
  429.15 +class CSequentialInStreamForBinder:
  429.16 +  public ISequentialInStream,
  429.17 +  public CMyUnknownImp
  429.18 +{
  429.19 +public:
  429.20 +  MY_UNKNOWN_IMP
  429.21 +
  429.22 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
  429.23 +private:
  429.24 +  CStreamBinder *m_StreamBinder;
  429.25 +public:
  429.26 +  ~CSequentialInStreamForBinder() { m_StreamBinder->CloseRead(); }
  429.27 +  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }
  429.28 +};
  429.29 +
  429.30 +STDMETHODIMP CSequentialInStreamForBinder::Read(void *data, UInt32 size, UInt32 *processedSize)
  429.31 +  { return m_StreamBinder->Read(data, size, processedSize); }
  429.32 +
  429.33 +class CSequentialOutStreamForBinder:
  429.34 +  public ISequentialOutStream,
  429.35 +  public CMyUnknownImp
  429.36 +{
  429.37 +public:
  429.38 +  MY_UNKNOWN_IMP
  429.39 +
  429.40 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  429.41 +
  429.42 +private:
  429.43 +  CStreamBinder *m_StreamBinder;
  429.44 +public:
  429.45 +  ~CSequentialOutStreamForBinder() {  m_StreamBinder->CloseWrite(); }
  429.46 +  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }
  429.47 +};
  429.48 +
  429.49 +STDMETHODIMP CSequentialOutStreamForBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)
  429.50 +  { return m_StreamBinder->Write(data, size, processedSize); }
  429.51 +
  429.52 +
  429.53 +//////////////////////////
  429.54 +// CStreamBinder
  429.55 +// (_thereAreBytesToReadEvent && _bufferSize == 0) means that stream is finished.
  429.56 +
  429.57 +HRes CStreamBinder::CreateEvents()
  429.58 +{
  429.59 +  RINOK(_allBytesAreWritenEvent.Create(true));
  429.60 +  RINOK(_thereAreBytesToReadEvent.Create());
  429.61 +  return _readStreamIsClosedEvent.Create();
  429.62 +}
  429.63 +
  429.64 +void CStreamBinder::ReInit()
  429.65 +{
  429.66 +  _thereAreBytesToReadEvent.Reset();
  429.67 +  _readStreamIsClosedEvent.Reset();
  429.68 +  ProcessedSize = 0;
  429.69 +}
  429.70 +
  429.71 +
  429.72 +  
  429.73 +void CStreamBinder::CreateStreams(ISequentialInStream **inStream,
  429.74 +      ISequentialOutStream **outStream)
  429.75 +{
  429.76 +  CSequentialInStreamForBinder *inStreamSpec = new
  429.77 +      CSequentialInStreamForBinder;
  429.78 +  CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);
  429.79 +  inStreamSpec->SetBinder(this);
  429.80 +  *inStream = inStreamLoc.Detach();
  429.81 +
  429.82 +  CSequentialOutStreamForBinder *outStreamSpec = new
  429.83 +      CSequentialOutStreamForBinder;
  429.84 +  CMyComPtr<ISequentialOutStream> outStreamLoc(outStreamSpec);
  429.85 +  outStreamSpec->SetBinder(this);
  429.86 +  *outStream = outStreamLoc.Detach();
  429.87 +
  429.88 +  _buffer = NULL;
  429.89 +  _bufferSize= 0;
  429.90 +  ProcessedSize = 0;
  429.91 +}
  429.92 +
  429.93 +HRESULT CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize)
  429.94 +{
  429.95 +  UInt32 sizeToRead = size;
  429.96 +  if (size > 0)
  429.97 +  {
  429.98 +    RINOK(_thereAreBytesToReadEvent.Lock());
  429.99 +    sizeToRead = MyMin(_bufferSize, size);
 429.100 +    if (_bufferSize > 0)
 429.101 +    {
 429.102 +      memcpy(data, _buffer, sizeToRead);
 429.103 +      _buffer = ((const Byte *)_buffer) + sizeToRead;
 429.104 +      _bufferSize -= sizeToRead;
 429.105 +      if (_bufferSize == 0)
 429.106 +      {
 429.107 +        _thereAreBytesToReadEvent.Reset();
 429.108 +        _allBytesAreWritenEvent.Set();
 429.109 +      }
 429.110 +    }
 429.111 +  }
 429.112 +  if (processedSize != NULL)
 429.113 +    *processedSize = sizeToRead;
 429.114 +  ProcessedSize += sizeToRead;
 429.115 +  return S_OK;
 429.116 +}
 429.117 +
 429.118 +void CStreamBinder::CloseRead()
 429.119 +{
 429.120 +  _readStreamIsClosedEvent.Set();
 429.121 +}
 429.122 +
 429.123 +HRESULT CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)
 429.124 +{
 429.125 +  if (size > 0)
 429.126 +  {
 429.127 +    _buffer = data;
 429.128 +    _bufferSize = size;
 429.129 +    _allBytesAreWritenEvent.Reset();
 429.130 +    _thereAreBytesToReadEvent.Set();
 429.131 +
 429.132 +    HANDLE events[2];
 429.133 +    events[0] = _allBytesAreWritenEvent;
 429.134 +    events[1] = _readStreamIsClosedEvent;
 429.135 +    DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE);
 429.136 +    if (waitResult != WAIT_OBJECT_0 + 0)
 429.137 +    {
 429.138 +      // ReadingWasClosed = true;
 429.139 +      return S_FALSE;
 429.140 +    }
 429.141 +    // if(!_allBytesAreWritenEvent.Lock())
 429.142 +    //   return E_FAIL;
 429.143 +  }
 429.144 +  if (processedSize != NULL)
 429.145 +    *processedSize = size;
 429.146 +  return S_OK;
 429.147 +}
 429.148 +
 429.149 +void CStreamBinder::CloseWrite()
 429.150 +{
 429.151 +  // _bufferSize must be = 0
 429.152 +  _thereAreBytesToReadEvent.Set();
 429.153 +}
   430.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   430.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/StreamBinder.h	Sat Mar 03 10:31:27 2012 -0600
   430.3 @@ -0,0 +1,32 @@
   430.4 +// StreamBinder.h
   430.5 +
   430.6 +#ifndef __STREAMBINDER_H
   430.7 +#define __STREAMBINDER_H
   430.8 +
   430.9 +#include "../IStream.h"
  430.10 +#include "../../Windows/Synchronization.h"
  430.11 +
  430.12 +class CStreamBinder
  430.13 +{
  430.14 +  NWindows::NSynchronization::CManualResetEvent _allBytesAreWritenEvent;
  430.15 +  NWindows::NSynchronization::CManualResetEvent _thereAreBytesToReadEvent;
  430.16 +  NWindows::NSynchronization::CManualResetEvent _readStreamIsClosedEvent;
  430.17 +  UInt32 _bufferSize;
  430.18 +  const void *_buffer;
  430.19 +public:
  430.20 +  // bool ReadingWasClosed;
  430.21 +  UInt64 ProcessedSize;
  430.22 +  CStreamBinder() {}
  430.23 +  HRes CreateEvents();
  430.24 +
  430.25 +  void CreateStreams(ISequentialInStream **inStream,
  430.26 +      ISequentialOutStream **outStream);
  430.27 +  HRESULT Read(void *data, UInt32 size, UInt32 *processedSize);
  430.28 +  void CloseRead();
  430.29 +
  430.30 +  HRESULT Write(const void *data, UInt32 size, UInt32 *processedSize);
  430.31 +  void CloseWrite();
  430.32 +  void ReInit();
  430.33 +};
  430.34 +
  430.35 +#endif
   431.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   431.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/StreamObjects.cpp	Sat Mar 03 10:31:27 2012 -0600
   431.3 @@ -0,0 +1,68 @@
   431.4 +// StreamObjects.cpp
   431.5 +
   431.6 +#include "StdAfx.h"
   431.7 +
   431.8 +#include "StreamObjects.h"
   431.9 +#include "../../Common/Defs.h"
  431.10 +
  431.11 +
  431.12 +STDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)
  431.13 +{
  431.14 +  size_t rem = _size - _pos;
  431.15 +  if (size < rem)
  431.16 +    rem = (size_t)size;
  431.17 +  memcpy(data, _dataPointer + _pos, rem);
  431.18 +  _pos += rem;
  431.19 +  if (processedSize != NULL)
  431.20 +    *processedSize = (UInt32)rem;
  431.21 +  return S_OK;
  431.22 +}
  431.23 +
  431.24 +
  431.25 +void CWriteBuffer::Write(const void *data, size_t size)
  431.26 +{
  431.27 +  size_t newCapacity = _size + size;
  431.28 +  _buffer.EnsureCapacity(newCapacity);
  431.29 +  memcpy(_buffer + _size, data, size);
  431.30 +  _size += size;
  431.31 +}
  431.32 +
  431.33 +STDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize)
  431.34 +{
  431.35 +  _writeBuffer.Write(data, (size_t)size);
  431.36 +  if(processedSize != NULL)
  431.37 +    *processedSize = size;
  431.38 +  return S_OK;
  431.39 +}
  431.40 +
  431.41 +STDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)
  431.42 +{
  431.43 +  size_t rem = _size - _pos;
  431.44 +  if (size < rem)
  431.45 +    rem = (size_t)size;
  431.46 +  memcpy(_buffer + _pos, data, rem);
  431.47 +  _pos += rem;
  431.48 +  if (processedSize != NULL)
  431.49 +    *processedSize = (UInt32)rem;
  431.50 +  return (rem == size ? S_OK : E_FAIL);
  431.51 +}
  431.52 +
  431.53 +STDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize)
  431.54 +{
  431.55 +  UInt32 realProcessedSize;
  431.56 +  HRESULT result = _stream->Read(data, size, &realProcessedSize);
  431.57 +  _size += realProcessedSize;
  431.58 +  if (processedSize != 0)
  431.59 +    *processedSize = realProcessedSize;
  431.60 +  return result;
  431.61 +}
  431.62 +
  431.63 +STDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize)
  431.64 +{
  431.65 +  UInt32 realProcessedSize;
  431.66 +  HRESULT result = _stream->Write(data, size, &realProcessedSize);
  431.67 +  _size += realProcessedSize;
  431.68 +  if (processedSize != 0)
  431.69 +    *processedSize = realProcessedSize;
  431.70 +  return result;
  431.71 +}
   432.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   432.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/StreamObjects.h	Sat Mar 03 10:31:27 2012 -0600
   432.3 @@ -0,0 +1,117 @@
   432.4 +// StreamObjects.h
   432.5 +
   432.6 +#ifndef __STREAMOBJECTS_H
   432.7 +#define __STREAMOBJECTS_H
   432.8 +
   432.9 +#include "../../Common/DynamicBuffer.h"
  432.10 +#include "../../Common/MyCom.h"
  432.11 +#include "../IStream.h"
  432.12 +
  432.13 +class CSequentialInStreamImp:
  432.14 +  public ISequentialInStream,
  432.15 +  public CMyUnknownImp
  432.16 +{
  432.17 +  const Byte *_dataPointer;
  432.18 +  size_t _size;
  432.19 +  size_t _pos;
  432.20 +
  432.21 +public:
  432.22 +  void Init(const Byte *dataPointer, size_t size)
  432.23 +  {
  432.24 +    _dataPointer = dataPointer;
  432.25 +    _size = size;
  432.26 +    _pos = 0;
  432.27 +  }
  432.28 +
  432.29 +  MY_UNKNOWN_IMP
  432.30 +
  432.31 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
  432.32 +};
  432.33 +
  432.34 +
  432.35 +class CWriteBuffer
  432.36 +{
  432.37 +  CByteDynamicBuffer _buffer;
  432.38 +  size_t _size;
  432.39 +public:
  432.40 +  CWriteBuffer(): _size(0) {}
  432.41 +  void Init() { _size = 0;  }
  432.42 +  void Write(const void *data, size_t size);
  432.43 +  size_t GetSize() const { return _size; }
  432.44 +  const CByteDynamicBuffer& GetBuffer() const { return _buffer; }
  432.45 +};
  432.46 +
  432.47 +class CSequentialOutStreamImp:
  432.48 +  public ISequentialOutStream,
  432.49 +  public CMyUnknownImp
  432.50 +{
  432.51 +  CWriteBuffer _writeBuffer;
  432.52 +public:
  432.53 +  void Init() { _writeBuffer.Init(); }
  432.54 +  size_t GetSize() const { return _writeBuffer.GetSize(); }
  432.55 +  const CByteDynamicBuffer& GetBuffer() const { return _writeBuffer.GetBuffer(); }
  432.56 +
  432.57 +  MY_UNKNOWN_IMP
  432.58 +
  432.59 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  432.60 +};
  432.61 +
  432.62 +class CSequentialOutStreamImp2:
  432.63 +  public ISequentialOutStream,
  432.64 +  public CMyUnknownImp
  432.65 +{
  432.66 +  Byte *_buffer;
  432.67 +  size_t _size;
  432.68 +  size_t _pos;
  432.69 +public:
  432.70 +
  432.71 +  void Init(Byte *buffer, size_t size)
  432.72 +  {
  432.73 +    _buffer = buffer;
  432.74 +    _pos = 0;
  432.75 +    _size = size;
  432.76 +  }
  432.77 +
  432.78 +  size_t GetPos() const { return _pos; }
  432.79 +
  432.80 +  MY_UNKNOWN_IMP
  432.81 +
  432.82 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  432.83 +};
  432.84 +
  432.85 +class CSequentialInStreamSizeCount:
  432.86 +  public ISequentialInStream,
  432.87 +  public CMyUnknownImp
  432.88 +{
  432.89 +  CMyComPtr<ISequentialInStream> _stream;
  432.90 +  UInt64 _size;
  432.91 +public:
  432.92 +  void Init(ISequentialInStream *stream)
  432.93 +  {
  432.94 +    _stream = stream;
  432.95 +    _size = 0;
  432.96 +  }
  432.97 +  UInt64 GetSize() const { return _size; }
  432.98 +
  432.99 +  MY_UNKNOWN_IMP
 432.100 +
 432.101 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
 432.102 +};
 432.103 +
 432.104 +class CSequentialOutStreamSizeCount:
 432.105 +  public ISequentialOutStream,
 432.106 +  public CMyUnknownImp
 432.107 +{
 432.108 +  CMyComPtr<ISequentialOutStream> _stream;
 432.109 +  UInt64 _size;
 432.110 +public:
 432.111 +  void SetStream(ISequentialOutStream *stream) { _stream = stream; }
 432.112 +  void Init() { _size = 0; }
 432.113 +  UInt64 GetSize() const { return _size; }
 432.114 +
 432.115 +  MY_UNKNOWN_IMP
 432.116 +
 432.117 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
 432.118 +};
 432.119 +
 432.120 +#endif
   433.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   433.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/StreamUtils.cpp	Sat Mar 03 10:31:27 2012 -0600
   433.3 @@ -0,0 +1,56 @@
   433.4 +// StreamUtils.cpp
   433.5 +
   433.6 +#include "StdAfx.h"
   433.7 +
   433.8 +#include "StreamUtils.h"
   433.9 +
  433.10 +static const UInt32 kBlockSize = ((UInt32)1 << 31);
  433.11 +
  433.12 +HRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *processedSize)
  433.13 +{
  433.14 +  size_t size = *processedSize;
  433.15 +  *processedSize = 0;
  433.16 +  while (size != 0)
  433.17 +  {
  433.18 +    UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;
  433.19 +    UInt32 processedSizeLoc;
  433.20 +    HRESULT res = stream->Read(data, curSize, &processedSizeLoc);
  433.21 +    *processedSize += processedSizeLoc;
  433.22 +    data = (void *)((Byte *)data + processedSizeLoc);
  433.23 +    size -= processedSizeLoc;
  433.24 +    RINOK(res);
  433.25 +    if (processedSizeLoc == 0)
  433.26 +      return S_OK;
  433.27 +  }
  433.28 +  return S_OK;
  433.29 +}
  433.30 +
  433.31 +HRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size)
  433.32 +{
  433.33 +  size_t processedSize = size;
  433.34 +  RINOK(ReadStream(stream, data, &processedSize));
  433.35 +  return (size == processedSize) ? S_OK : S_FALSE;
  433.36 +}
  433.37 +
  433.38 +HRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size)
  433.39 +{
  433.40 +  size_t processedSize = size;
  433.41 +  RINOK(ReadStream(stream, data, &processedSize));
  433.42 +  return (size == processedSize) ? S_OK : E_FAIL;
  433.43 +}
  433.44 +
  433.45 +HRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size)
  433.46 +{
  433.47 +  while (size != 0)
  433.48 +  {
  433.49 +    UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;
  433.50 +    UInt32 processedSizeLoc;
  433.51 +    HRESULT res = stream->Write(data, curSize, &processedSizeLoc);
  433.52 +    data = (const void *)((const Byte *)data + processedSizeLoc);
  433.53 +    size -= processedSizeLoc;
  433.54 +    RINOK(res);
  433.55 +    if (processedSizeLoc == 0)
  433.56 +      return E_FAIL;
  433.57 +  }
  433.58 +  return S_OK;
  433.59 +}
   434.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   434.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/StreamUtils.h	Sat Mar 03 10:31:27 2012 -0600
   434.3 @@ -0,0 +1,13 @@
   434.4 +// StreamUtils.h
   434.5 +
   434.6 +#ifndef __STREAMUTILS_H
   434.7 +#define __STREAMUTILS_H
   434.8 +
   434.9 +#include "../IStream.h"
  434.10 +
  434.11 +HRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *size);
  434.12 +HRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size);
  434.13 +HRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size);
  434.14 +HRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size);
  434.15 +
  434.16 +#endif
   435.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   435.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/VirtThread.cpp	Sat Mar 03 10:31:27 2012 -0600
   435.3 @@ -0,0 +1,45 @@
   435.4 +// VirtThread.cpp
   435.5 +
   435.6 +#include "StdAfx.h"
   435.7 +
   435.8 +#include "VirtThread.h"
   435.9 +
  435.10 +static THREAD_FUNC_DECL CoderThread(void *p)
  435.11 +{
  435.12 +  for (;;)
  435.13 +  {
  435.14 +    CVirtThread *t = (CVirtThread *)p;
  435.15 +    t->StartEvent.Lock();
  435.16 +    if (t->ExitEvent)
  435.17 +      return 0;
  435.18 +    t->Execute();
  435.19 +    t->FinishedEvent.Set();
  435.20 +  }
  435.21 +}
  435.22 +
  435.23 +WRes CVirtThread::Create()
  435.24 +{
  435.25 +  RINOK(StartEvent.CreateIfNotCreated());
  435.26 +  RINOK(FinishedEvent.CreateIfNotCreated());
  435.27 +  StartEvent.Reset();
  435.28 +  FinishedEvent.Reset();
  435.29 +  ExitEvent = false;
  435.30 +  if (Thread.IsCreated())
  435.31 +    return S_OK;
  435.32 +  return Thread.Create(CoderThread, this);
  435.33 +}
  435.34 +
  435.35 +void CVirtThread::Start()
  435.36 +{
  435.37 +  ExitEvent = false;
  435.38 +  StartEvent.Set();
  435.39 +}
  435.40 +
  435.41 +CVirtThread::~CVirtThread()
  435.42 +{
  435.43 +  ExitEvent = true;
  435.44 +  if (StartEvent.IsCreated())
  435.45 +    StartEvent.Set();
  435.46 +  Thread.Wait();
  435.47 +}
  435.48 +
   436.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   436.2 +++ b/src/win32/7zip/7z/CPP/7zip/Common/VirtThread.h	Sat Mar 03 10:31:27 2012 -0600
   436.3 @@ -0,0 +1,23 @@
   436.4 +// VirtThread.h
   436.5 +
   436.6 +#ifndef __VIRTTHREAD_H
   436.7 +#define __VIRTTHREAD_H
   436.8 +
   436.9 +#include "../../Windows/Synchronization.h"
  436.10 +#include "../../Windows/Thread.h"
  436.11 +
  436.12 +struct CVirtThread
  436.13 +{
  436.14 +  NWindows::NSynchronization::CAutoResetEvent StartEvent;
  436.15 +  NWindows::NSynchronization::CAutoResetEvent FinishedEvent;
  436.16 +  NWindows::CThread Thread;
  436.17 +  bool ExitEvent;
  436.18 +
  436.19 +  ~CVirtThread();
  436.20 +  WRes Create();
  436.21 +  void Start();
  436.22 +  void WaitFinish() { FinishedEvent.Lock(); }
  436.23 +  virtual void Execute() = 0;
  436.24 +};
  436.25 +
  436.26 +#endif
   437.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   437.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BZip2Const.h	Sat Mar 03 10:31:27 2012 -0600
   437.3 @@ -0,0 +1,54 @@
   437.4 +// Compress/BZip2Const.h
   437.5 +
   437.6 +#ifndef __COMPRESS_BZIP2_CONST_H
   437.7 +#define __COMPRESS_BZIP2_CONST_H
   437.8 +
   437.9 +namespace NCompress {
  437.10 +namespace NBZip2 {
  437.11 +
  437.12 +const Byte kArSig0 = 'B';
  437.13 +const Byte kArSig1 = 'Z';
  437.14 +const Byte kArSig2 = 'h';
  437.15 +const Byte kArSig3 = '0';
  437.16 +
  437.17 +const Byte kFinSig0 = 0x17;
  437.18 +const Byte kFinSig1 = 0x72;
  437.19 +const Byte kFinSig2 = 0x45;
  437.20 +const Byte kFinSig3 = 0x38;
  437.21 +const Byte kFinSig4 = 0x50;
  437.22 +const Byte kFinSig5 = 0x90;
  437.23 +
  437.24 +const Byte kBlockSig0 = 0x31;
  437.25 +const Byte kBlockSig1 = 0x41;
  437.26 +const Byte kBlockSig2 = 0x59;
  437.27 +const Byte kBlockSig3 = 0x26;
  437.28 +const Byte kBlockSig4 = 0x53;
  437.29 +const Byte kBlockSig5 = 0x59;
  437.30 +
  437.31 +const int kNumOrigBits = 24;
  437.32 +
  437.33 +const int kNumTablesBits = 3;
  437.34 +const int kNumTablesMin = 2;
  437.35 +const int kNumTablesMax = 6;
  437.36 +
  437.37 +const int kNumLevelsBits = 5;
  437.38 +
  437.39 +const int kMaxHuffmanLen = 20; // Check it
  437.40 +
  437.41 +const int kMaxAlphaSize = 258;
  437.42 +
  437.43 +const int kGroupSize = 50;
  437.44 +
  437.45 +const int kBlockSizeMultMin = 1;
  437.46 +const int kBlockSizeMultMax = 9;
  437.47 +const UInt32 kBlockSizeStep = 100000;
  437.48 +const UInt32 kBlockSizeMax = kBlockSizeMultMax * kBlockSizeStep;
  437.49 +
  437.50 +const int kNumSelectorsBits = 15;
  437.51 +const UInt32 kNumSelectorsMax = (2 + (kBlockSizeMax / kGroupSize));
  437.52 +
  437.53 +const int kRleModeRepSize = 4;
  437.54 +
  437.55 +}}
  437.56 +
  437.57 +#endif
   438.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   438.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BZip2Crc.cpp	Sat Mar 03 10:31:27 2012 -0600
   438.3 @@ -0,0 +1,26 @@
   438.4 +// BZip2Crc.cpp
   438.5 +
   438.6 +#include "StdAfx.h"
   438.7 +
   438.8 +#include "BZip2Crc.h"
   438.9 +
  438.10 +UInt32 CBZip2Crc::Table[256];
  438.11 +
  438.12 +static const UInt32 kBZip2CrcPoly = 0x04c11db7;  /* AUTODIN II, Ethernet, & FDDI */
  438.13 +
  438.14 +void CBZip2Crc::InitTable()
  438.15 +{
  438.16 +  for (UInt32 i = 0; i < 256; i++)
  438.17 +  {
  438.18 +    UInt32 r = (i << 24);
  438.19 +    for (int j = 8; j > 0; j--)
  438.20 +      r = (r & 0x80000000) ? ((r << 1) ^ kBZip2CrcPoly) : (r << 1);
  438.21 +    Table[i] = r;
  438.22 +  }
  438.23 +}
  438.24 +
  438.25 +class CBZip2CrcTableInit
  438.26 +{
  438.27 +public:
  438.28 +  CBZip2CrcTableInit() { CBZip2Crc::InitTable(); }
  438.29 +} g_BZip2CrcTableInit;
   439.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   439.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BZip2Crc.h	Sat Mar 03 10:31:27 2012 -0600
   439.3 @@ -0,0 +1,31 @@
   439.4 +// BZip2Crc.h
   439.5 +
   439.6 +#ifndef __BZIP2_CRC_H
   439.7 +#define __BZIP2_CRC_H
   439.8 +
   439.9 +#include "Common/Types.h"
  439.10 +
  439.11 +class CBZip2Crc
  439.12 +{
  439.13 +  UInt32 _value;
  439.14 +  static UInt32 Table[256];
  439.15 +public:
  439.16 +  static void InitTable();
  439.17 +  CBZip2Crc(): _value(0xFFFFFFFF) {};
  439.18 +  void Init() { _value = 0xFFFFFFFF; }
  439.19 +  void UpdateByte(Byte b) { _value = Table[(_value >> 24) ^ b] ^ (_value << 8); }
  439.20 +  void UpdateByte(unsigned int b) { _value = Table[(_value >> 24) ^ b] ^ (_value << 8); }
  439.21 +  UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; }
  439.22 +};
  439.23 +
  439.24 +class CBZip2CombinedCrc
  439.25 +{
  439.26 +  UInt32 _value;
  439.27 +public:
  439.28 +  CBZip2CombinedCrc():  _value(0){};
  439.29 +  void Init() { _value = 0; }
  439.30 +  void Update(UInt32 v) { _value = ((_value << 1) | (_value >> 31)) ^ v; }
  439.31 +  UInt32 GetDigest() const { return _value ; }
  439.32 +};
  439.33 +
  439.34 +#endif
   440.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   440.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BZip2Decoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   440.3 @@ -0,0 +1,791 @@
   440.4 +// BZip2Decoder.cpp
   440.5 +
   440.6 +#include "StdAfx.h"
   440.7 +
   440.8 +extern "C"
   440.9 +{
  440.10 +#include "../../../C/Alloc.h"
  440.11 +}
  440.12 +
  440.13 +#include "../../Common/Defs.h"
  440.14 +
  440.15 +#include "BZip2Crc.h"
  440.16 +#include "BZip2Decoder.h"
  440.17 +#include "Mtf8.h"
  440.18 +
  440.19 +namespace NCompress {
  440.20 +namespace NBZip2 {
  440.21 +
  440.22 +#define NO_INLINE MY_FAST_CALL
  440.23 +
  440.24 +const UInt32 kNumThreadsMax = 4;
  440.25 +
  440.26 +static const UInt32 kBufferSize = (1 << 17);
  440.27 +
  440.28 +static Int16 kRandNums[512] = {
  440.29 +   619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
  440.30 +   985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
  440.31 +   733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
  440.32 +   419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
  440.33 +   878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
  440.34 +   862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
  440.35 +   150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
  440.36 +   170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
  440.37 +   73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
  440.38 +   909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
  440.39 +   641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
  440.40 +   161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
  440.41 +   382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
  440.42 +   98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
  440.43 +   227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
  440.44 +   469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
  440.45 +   184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
  440.46 +   715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
  440.47 +   951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
  440.48 +   652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
  440.49 +   645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
  440.50 +   609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
  440.51 +   653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
  440.52 +   411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
  440.53 +   170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
  440.54 +   857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
  440.55 +   669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
  440.56 +   944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
  440.57 +   344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
  440.58 +   897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
  440.59 +   433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
  440.60 +   686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
  440.61 +   946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
  440.62 +   978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
  440.63 +   680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
  440.64 +   707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
  440.65 +   297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
  440.66 +   134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
  440.67 +   343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
  440.68 +   140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
  440.69 +   170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
  440.70 +   369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
  440.71 +   804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
  440.72 +   896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
  440.73 +   661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
  440.74 +   768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
  440.75 +   61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
  440.76 +   372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
  440.77 +   780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
  440.78 +   920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
  440.79 +   645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
  440.80 +   936, 638
  440.81 +};
  440.82 +
  440.83 +bool CState::Alloc()
  440.84 +{
  440.85 +  if (Counters == 0)
  440.86 +    Counters = (UInt32 *)BigAlloc((256 + kBlockSizeMax) * sizeof(UInt32));
  440.87 +  return (Counters != 0);
  440.88 +}
  440.89 +
  440.90 +void CState::Free()
  440.91 +{
  440.92 +  ::BigFree(Counters);
  440.93 +  Counters = 0;
  440.94 +}
  440.95 +
  440.96 +UInt32 CDecoder::ReadBits(int numBits) {  return m_InStream.ReadBits(numBits); }
  440.97 +Byte CDecoder::ReadByte() {return (Byte)ReadBits(8); }
  440.98 +bool CDecoder::ReadBit() { return ReadBits(1) != 0; }
  440.99 +
 440.100 +UInt32 CDecoder::ReadCrc()
 440.101 +{
 440.102 +  UInt32 crc = 0;
 440.103 +  for (int i = 0; i < 4; i++)
 440.104 +  {
 440.105 +    crc <<= 8;
 440.106 +    crc |= ReadByte();
 440.107 +  }
 440.108 +  return crc;
 440.109 +}
 440.110 +
 440.111 +UInt32 NO_INLINE ReadBits(NBitm::CDecoder<CInBuffer> *m_InStream, int num)
 440.112 +{
 440.113 +  return m_InStream->ReadBits(num);
 440.114 +}
 440.115 +
 440.116 +UInt32 NO_INLINE ReadBit(NBitm::CDecoder<CInBuffer> *m_InStream)
 440.117 +{
 440.118 +  return m_InStream->ReadBits(1);
 440.119 +}
 440.120 +
 440.121 +static HRESULT NO_INLINE ReadBlock(NBitm::CDecoder<CInBuffer> *m_InStream,
 440.122 +  UInt32 *CharCounters, UInt32 blockSizeMax, Byte *m_Selectors, CHuffmanDecoder *m_HuffmanDecoders,
 440.123 +  UInt32 *blockSizeRes, UInt32 *origPtrRes, bool *randRes)
 440.124 +{
 440.125 +  *randRes = ReadBit(m_InStream) ? true : false;
 440.126 +  *origPtrRes = ReadBits(m_InStream, kNumOrigBits);
 440.127 +  
 440.128 +  // in original code it compares OrigPtr to (UInt32)(10 + blockSizeMax)) : why ?
 440.129 +  if (*origPtrRes >= blockSizeMax)
 440.130 +    return S_FALSE;
 440.131 +
 440.132 +  CMtf8Decoder mtf;
 440.133 +  mtf.StartInit();
 440.134 +  
 440.135 +  int numInUse = 0;
 440.136 +  {
 440.137 +    Byte inUse16[16];
 440.138 +    int i;
 440.139 +    for (i = 0; i < 16; i++)
 440.140 +      inUse16[i] = (Byte)ReadBit(m_InStream);
 440.141 +    for (i = 0; i < 256; i++)
 440.142 +      if (inUse16[i >> 4])
 440.143 +      {
 440.144 +        if (ReadBit(m_InStream))
 440.145 +          mtf.Add(numInUse++, (Byte)i);
 440.146 +      }
 440.147 +    if (numInUse == 0)
 440.148 +      return S_FALSE;
 440.149 +    // mtf.Init(numInUse);
 440.150 +  }
 440.151 +  int alphaSize = numInUse + 2;
 440.152 +
 440.153 +  int numTables = ReadBits(m_InStream, kNumTablesBits);
 440.154 +  if (numTables < kNumTablesMin || numTables > kNumTablesMax)
 440.155 +    return S_FALSE;
 440.156 +  
 440.157 +  UInt32 numSelectors = ReadBits(m_InStream, kNumSelectorsBits);
 440.158 +  if (numSelectors < 1 || numSelectors > kNumSelectorsMax)
 440.159 +    return S_FALSE;
 440.160 +
 440.161 +  {
 440.162 +    Byte mtfPos[kNumTablesMax];
 440.163 +    int t = 0;
 440.164 +    do
 440.165 +      mtfPos[t] = (Byte)t;
 440.166 +    while(++t < numTables);
 440.167 +    UInt32 i = 0;
 440.168 +    do
 440.169 +    {
 440.170 +      int j = 0;
 440.171 +      while (ReadBit(m_InStream))
 440.172 +        if (++j >= numTables)
 440.173 +          return S_FALSE;
 440.174 +      Byte tmp = mtfPos[j];
 440.175 +      for (;j > 0; j--)
 440.176 +        mtfPos[j] = mtfPos[j - 1];
 440.177 +      m_Selectors[i] = mtfPos[0] = tmp;
 440.178 +    }
 440.179 +    while(++i < numSelectors);
 440.180 +  }
 440.181 +
 440.182 +  int t = 0;
 440.183 +  do
 440.184 +  {
 440.185 +    Byte lens[kMaxAlphaSize];
 440.186 +    int len = (int)ReadBits(m_InStream, kNumLevelsBits);
 440.187 +    int i;
 440.188 +    for (i = 0; i < alphaSize; i++)
 440.189 +    {
 440.190 +      for (;;)
 440.191 +      {
 440.192 +        if (len < 1 || len > kMaxHuffmanLen)
 440.193 +          return S_FALSE;
 440.194 +        if (!ReadBit(m_InStream))
 440.195 +          break;
 440.196 +        len += 1 - (int)(ReadBit(m_InStream) << 1);
 440.197 +      }
 440.198 +      lens[i] = (Byte)len;
 440.199 +    }
 440.200 +    for (; i < kMaxAlphaSize; i++)
 440.201 +      lens[i] = 0;
 440.202 +    if(!m_HuffmanDecoders[t].SetCodeLengths(lens))
 440.203 +      return S_FALSE;
 440.204 +  }
 440.205 +  while(++t < numTables);
 440.206 +
 440.207 +  {
 440.208 +    for (int i = 0; i < 256; i++)
 440.209 +      CharCounters[i] = 0;
 440.210 +  }
 440.211 +  
 440.212 +  UInt32 blockSize = 0;
 440.213 +  {
 440.214 +    UInt32 groupIndex = 0;
 440.215 +    UInt32 groupSize = 0;
 440.216 +    CHuffmanDecoder *huffmanDecoder = 0;
 440.217 +    int runPower = 0;
 440.218 +    UInt32 runCounter = 0;
 440.219 +    
 440.220 +    for (;;)
 440.221 +    {
 440.222 +      if (groupSize == 0)
 440.223 +      {
 440.224 +        if (groupIndex >= numSelectors)
 440.225 +          return S_FALSE;
 440.226 +        groupSize = kGroupSize;
 440.227 +        huffmanDecoder = &m_HuffmanDecoders[m_Selectors[groupIndex++]];
 440.228 +      }
 440.229 +      groupSize--;
 440.230 +        
 440.231 +      UInt32 nextSym = huffmanDecoder->DecodeSymbol(m_InStream);
 440.232 +      
 440.233 +      if (nextSym < 2)
 440.234 +      {
 440.235 +        runCounter += ((UInt32)(nextSym + 1) << runPower++);
 440.236 +        if (blockSizeMax - blockSize < runCounter)
 440.237 +          return S_FALSE;
 440.238 +        continue;
 440.239 +      }
 440.240 +      if (runCounter != 0)
 440.241 +      {
 440.242 +        UInt32 b = (UInt32)mtf.GetHead();
 440.243 +        CharCounters[b] += runCounter;
 440.244 +        do
 440.245 +          CharCounters[256 + blockSize++] = b;
 440.246 +        while(--runCounter != 0);
 440.247 +        runPower = 0;
 440.248 +      }
 440.249 +      if (nextSym <= (UInt32)numInUse)
 440.250 +      {
 440.251 +        UInt32 b = (UInt32)mtf.GetAndMove((int)nextSym - 1);
 440.252 +        if (blockSize >= blockSizeMax)
 440.253 +          return S_FALSE;
 440.254 +        CharCounters[b]++;
 440.255 +        CharCounters[256 + blockSize++] = b;
 440.256 +      }
 440.257 +      else if (nextSym == (UInt32)numInUse + 1)
 440.258 +        break;
 440.259 +      else
 440.260 +        return S_FALSE;
 440.261 +    }
 440.262 +  }
 440.263 +  *blockSizeRes = blockSize;
 440.264 +  return (*origPtrRes < blockSize) ? S_OK : S_FALSE;
 440.265 +}
 440.266 +
 440.267 +void NO_INLINE DecodeBlock1(UInt32 *charCounters, UInt32 blockSize)
 440.268 +{
 440.269 +  {
 440.270 +    UInt32 sum = 0;
 440.271 +    for (UInt32 i = 0; i < 256; i++)
 440.272 +    {
 440.273 +      sum += charCounters[i];
 440.274 +      charCounters[i] = sum - charCounters[i];
 440.275 +    }
 440.276 +  }
 440.277 +  
 440.278 +  UInt32 *tt = charCounters + 256;
 440.279 +  // Compute the T^(-1) vector
 440.280 +  UInt32 i = 0;
 440.281 +  do
 440.282 +    tt[charCounters[tt[i] & 0xFF]++] |= (i << 8);
 440.283 +  while(++i < blockSize);
 440.284 +}
 440.285 +
 440.286 +static UInt32 NO_INLINE DecodeBlock2(const UInt32 *tt, UInt32 blockSize, UInt32 OrigPtr, COutBuffer &m_OutStream)
 440.287 +{
 440.288 +  CBZip2Crc crc;
 440.289 +
 440.290 +  // it's for speed optimization: prefetch & prevByte_init;
 440.291 +  UInt32 tPos = tt[tt[OrigPtr] >> 8];
 440.292 +  unsigned int prevByte = (unsigned int)(tPos & 0xFF);
 440.293 +  
 440.294 +  int numReps = 0;
 440.295 +
 440.296 +  do
 440.297 +  {
 440.298 +    unsigned int b = (unsigned int)(tPos & 0xFF);
 440.299 +    tPos = tt[tPos >> 8];
 440.300 +    
 440.301 +    if (numReps == kRleModeRepSize)
 440.302 +    {
 440.303 +      for (; b > 0; b--)
 440.304 +      {
 440.305 +        crc.UpdateByte(prevByte);
 440.306 +        m_OutStream.WriteByte((Byte)prevByte);
 440.307 +      }
 440.308 +      numReps = 0;
 440.309 +      continue;
 440.310 +    }
 440.311 +    if (b != prevByte)
 440.312 +      numReps = 0;
 440.313 +    numReps++;
 440.314 +    prevByte = b;
 440.315 +    crc.UpdateByte(b);
 440.316 +    m_OutStream.WriteByte((Byte)b);
 440.317 +
 440.318 +    /*
 440.319 +    prevByte = b;
 440.320 +    crc.UpdateByte(b);
 440.321 +    m_OutStream.WriteByte((Byte)b);
 440.322 +    for (; --blockSize != 0;)
 440.323 +    {
 440.324 +      b = (unsigned int)(tPos & 0xFF);
 440.325 +      tPos = tt[tPos >> 8];
 440.326 +      crc.UpdateByte(b);
 440.327 +      m_OutStream.WriteByte((Byte)b);
 440.328 +      if (b != prevByte)
 440.329 +      {
 440.330 +        prevByte = b;
 440.331 +        continue;
 440.332 +      }
 440.333 +      if (--blockSize == 0)
 440.334 +        break;
 440.335 +      
 440.336 +      b = (unsigned int)(tPos & 0xFF);
 440.337 +      tPos = tt[tPos >> 8];
 440.338 +      crc.UpdateByte(b);
 440.339 +      m_OutStream.WriteByte((Byte)b);
 440.340 +      if (b != prevByte)
 440.341 +      {
 440.342 +        prevByte = b;
 440.343 +        continue;
 440.344 +      }
 440.345 +      if (--blockSize == 0)
 440.346 +        break;
 440.347 +      
 440.348 +      b = (unsigned int)(tPos & 0xFF);
 440.349 +      tPos = tt[tPos >> 8];
 440.350 +      crc.UpdateByte(b);
 440.351 +      m_OutStream.WriteByte((Byte)b);
 440.352 +      if (b != prevByte)
 440.353 +      {
 440.354 +        prevByte = b;
 440.355 +        continue;
 440.356 +      }
 440.357 +      --blockSize;
 440.358 +      break;
 440.359 +    }
 440.360 +    if (blockSize == 0)
 440.361 +      break;
 440.362 +
 440.363 +    b = (unsigned int)(tPos & 0xFF);
 440.364 +    tPos = tt[tPos >> 8];
 440.365 +    
 440.366 +    for (; b > 0; b--)
 440.367 +    {
 440.368 +      crc.UpdateByte(prevByte);
 440.369 +      m_OutStream.WriteByte((Byte)prevByte);
 440.370 +    }
 440.371 +    */
 440.372 +  }
 440.373 +  while(--blockSize != 0);
 440.374 +  return crc.GetDigest();
 440.375 +}
 440.376 +
 440.377 +static UInt32 NO_INLINE DecodeBlock2Rand(const UInt32 *tt, UInt32 blockSize, UInt32 OrigPtr, COutBuffer &m_OutStream)
 440.378 +{
 440.379 +  CBZip2Crc crc;
 440.380 +  
 440.381 +  UInt32 randIndex = 1;
 440.382 +  UInt32 randToGo = kRandNums[0] - 2;
 440.383 +  
 440.384 +  int numReps = 0;
 440.385 +
 440.386 +  // it's for speed optimization: prefetch & prevByte_init;
 440.387 +  UInt32 tPos = tt[tt[OrigPtr] >> 8];
 440.388 +  unsigned int prevByte = (unsigned int)(tPos & 0xFF);
 440.389 +  
 440.390 +  do
 440.391 +  {
 440.392 +    unsigned int b = (unsigned int)(tPos & 0xFF);
 440.393 +    tPos = tt[tPos >> 8];
 440.394 +    
 440.395 +    {
 440.396 +      if (randToGo == 0)
 440.397 +      {
 440.398 +        b ^= 1;
 440.399 +        randToGo = kRandNums[randIndex++];
 440.400 +        randIndex &= 0x1FF;
 440.401 +      }
 440.402 +      randToGo--;
 440.403 +    }
 440.404 +    
 440.405 +    if (numReps == kRleModeRepSize)
 440.406 +    {
 440.407 +      for (; b > 0; b--)
 440.408 +      {
 440.409 +        crc.UpdateByte(prevByte);
 440.410 +        m_OutStream.WriteByte((Byte)prevByte);
 440.411 +      }
 440.412 +      numReps = 0;
 440.413 +      continue;
 440.414 +    }
 440.415 +    if (b != prevByte)
 440.416 +      numReps = 0;
 440.417 +    numReps++;
 440.418 +    prevByte = b;
 440.419 +    crc.UpdateByte(b);
 440.420 +    m_OutStream.WriteByte((Byte)b);
 440.421 +  }
 440.422 +  while(--blockSize != 0);
 440.423 +  return crc.GetDigest();
 440.424 +}
 440.425 +
 440.426 +#ifdef COMPRESS_BZIP2_MT
 440.427 +
 440.428 +CDecoder::CDecoder():
 440.429 +  m_States(0)
 440.430 +{
 440.431 +  m_NumThreadsPrev = 0;
 440.432 +  NumThreads = 1;
 440.433 +}
 440.434 +
 440.435 +CDecoder::~CDecoder()
 440.436 +{
 440.437 +  Free();
 440.438 +}
 440.439 +
 440.440 +#define RINOK_THREAD(x) { WRes __result_ = (x); if(__result_ != 0) return __result_; }
 440.441 +
 440.442 +HRESULT CDecoder::Create()
 440.443 +{
 440.444 +  RINOK_THREAD(CanProcessEvent.CreateIfNotCreated());
 440.445 +  RINOK_THREAD(CanStartWaitingEvent.CreateIfNotCreated());
 440.446 +  if (m_States != 0 && m_NumThreadsPrev == NumThreads)
 440.447 +    return S_OK;
 440.448 +  Free();
 440.449 +  MtMode = (NumThreads > 1);
 440.450 +  m_NumThreadsPrev = NumThreads;
 440.451 +  try
 440.452 +  {
 440.453 +    m_States = new CState[NumThreads];
 440.454 +    if (m_States == 0)
 440.455 +      return E_OUTOFMEMORY;
 440.456 +  }
 440.457 +  catch(...) { return E_OUTOFMEMORY; }
 440.458 +  for (UInt32 t = 0; t < NumThreads; t++)
 440.459 +  {
 440.460 +    CState &ti = m_States[t];
 440.461 +    ti.Decoder = this;
 440.462 +    if (MtMode)
 440.463 +    {
 440.464 +      HRESULT res = ti.Create();
 440.465 +      if (res != S_OK)
 440.466 +      {
 440.467 +        NumThreads = t;
 440.468 +        Free();
 440.469 +        return res;
 440.470 +      }
 440.471 +    }
 440.472 +  }
 440.473 +  return S_OK;
 440.474 +}
 440.475 +
 440.476 +void CDecoder::Free()
 440.477 +{
 440.478 +  if (!m_States)
 440.479 +    return;
 440.480 +  CloseThreads = true;
 440.481 +  CanProcessEvent.Set();
 440.482 +  for (UInt32 t = 0; t < NumThreads; t++)
 440.483 +  {
 440.484 +    CState &s = m_States[t];
 440.485 +    if (MtMode)
 440.486 +      s.Thread.Wait();
 440.487 +    s.Free();
 440.488 +  }
 440.489 +  delete []m_States;
 440.490 +  m_States = 0;
 440.491 +}
 440.492 +#endif
 440.493 +
 440.494 +HRESULT CDecoder::ReadSignatures(bool &wasFinished, UInt32 &crc)
 440.495 +{
 440.496 +  wasFinished = false;
 440.497 +  Byte s[6];
 440.498 +  for (int i = 0; i < 6; i++)
 440.499 +    s[i] = ReadByte();
 440.500 +  crc = ReadCrc();
 440.501 +  if (s[0] == kFinSig0)
 440.502 +  {
 440.503 +    if (s[1] != kFinSig1 ||
 440.504 +        s[2] != kFinSig2 ||
 440.505 +        s[3] != kFinSig3 ||
 440.506 +        s[4] != kFinSig4 ||
 440.507 +        s[5] != kFinSig5)
 440.508 +      return S_FALSE;
 440.509 +    
 440.510 +    wasFinished = true;
 440.511 +    return (crc == CombinedCrc.GetDigest()) ? S_OK : S_FALSE;
 440.512 +  }
 440.513 +  if (s[0] != kBlockSig0 ||
 440.514 +      s[1] != kBlockSig1 ||
 440.515 +      s[2] != kBlockSig2 ||
 440.516 +      s[3] != kBlockSig3 ||
 440.517 +      s[4] != kBlockSig4 ||
 440.518 +      s[5] != kBlockSig5)
 440.519 +    return S_FALSE;
 440.520 +  CombinedCrc.Update(crc);
 440.521 +  return S_OK;
 440.522 +}
 440.523 +
 440.524 +HRESULT CDecoder::DecodeFile(bool &isBZ, ICompressProgressInfo *progress)
 440.525 +{
 440.526 +  #ifdef COMPRESS_BZIP2_MT
 440.527 +  Progress = progress;
 440.528 +  RINOK(Create());
 440.529 +  for (UInt32 t = 0; t < NumThreads; t++)
 440.530 +  {
 440.531 +    CState &s = m_States[t];
 440.532 +    if (!s.Alloc())
 440.533 +      return E_OUTOFMEMORY;
 440.534 +    if (MtMode)
 440.535 +    {
 440.536 +      RINOK(s.StreamWasFinishedEvent.Reset());
 440.537 +      RINOK(s.WaitingWasStartedEvent.Reset());
 440.538 +      RINOK(s.CanWriteEvent.Reset());
 440.539 +    }
 440.540 +  }
 440.541 +  #else
 440.542 +  if (!m_States[0].Alloc())
 440.543 +    return E_OUTOFMEMORY;
 440.544 +  #endif
 440.545 +
 440.546 +  isBZ = false;
 440.547 +  Byte s[6];
 440.548 +  int i;
 440.549 +  for (i = 0; i < 4; i++)
 440.550 +    s[i] = ReadByte();
 440.551 +  if (s[0] != kArSig0 ||
 440.552 +      s[1] != kArSig1 ||
 440.553 +      s[2] != kArSig2 ||
 440.554 +      s[3] <= kArSig3 ||
 440.555 +      s[3] > kArSig3 + kBlockSizeMultMax)
 440.556 +    return S_OK;
 440.557 +  isBZ = true;
 440.558 +  UInt32 dicSize = (UInt32)(s[3] - kArSig3) * kBlockSizeStep;
 440.559 +
 440.560 +  CombinedCrc.Init();
 440.561 +  #ifdef COMPRESS_BZIP2_MT
 440.562 +  if (MtMode)
 440.563 +  {
 440.564 +    NextBlockIndex = 0;
 440.565 +    StreamWasFinished1 = StreamWasFinished2 = false;
 440.566 +    CloseThreads = false;
 440.567 +    CanStartWaitingEvent.Reset();
 440.568 +    m_States[0].CanWriteEvent.Set();
 440.569 +    BlockSizeMax = dicSize;
 440.570 +    Result1 = Result2 = S_OK;
 440.571 +    CanProcessEvent.Set();
 440.572 +    UInt32 t;
 440.573 +    for (t = 0; t < NumThreads; t++)
 440.574 +      m_States[t].StreamWasFinishedEvent.Lock();
 440.575 +    CanProcessEvent.Reset();
 440.576 +    CanStartWaitingEvent.Set();
 440.577 +    for (t = 0; t < NumThreads; t++)
 440.578 +      m_States[t].WaitingWasStartedEvent.Lock();
 440.579 +    CanStartWaitingEvent.Reset();
 440.580 +    RINOK(Result2);
 440.581 +    RINOK(Result1);
 440.582 +  }
 440.583 +  else
 440.584 +  #endif
 440.585 +  {
 440.586 +    CState &state = m_States[0];
 440.587 +    for (;;)
 440.588 +    {
 440.589 +      if (progress)
 440.590 +      {
 440.591 +        UInt64 packSize = m_InStream.GetProcessedSize();
 440.592 +        UInt64 unpackSize = m_OutStream.GetProcessedSize();
 440.593 +        RINOK(progress->SetRatioInfo(&packSize, &unpackSize));
 440.594 +      }
 440.595 +      bool wasFinished;
 440.596 +      UInt32 crc;
 440.597 +      RINOK(ReadSignatures(wasFinished, crc));
 440.598 +      if (wasFinished)
 440.599 +        return S_OK;
 440.600 +
 440.601 +      UInt32 blockSize, origPtr;
 440.602 +      bool randMode;
 440.603 +      RINOK(ReadBlock(&m_InStream, state.Counters, dicSize,
 440.604 +        m_Selectors, m_HuffmanDecoders,
 440.605 +        &blockSize, &origPtr, &randMode));
 440.606 +      DecodeBlock1(state.Counters, blockSize);
 440.607 +      if ((randMode ?
 440.608 +          DecodeBlock2Rand(state.Counters + 256, blockSize, origPtr, m_OutStream) :
 440.609 +          DecodeBlock2(state.Counters + 256, blockSize, origPtr, m_OutStream)) != crc)
 440.610 +        return S_FALSE;
 440.611 +    }
 440.612 +  }
 440.613 +  return S_OK;
 440.614 +}
 440.615 +
 440.616 +HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 440.617 +    const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)
 440.618 +{
 440.619 +  if (!m_InStream.Create(kBufferSize))
 440.620 +    return E_OUTOFMEMORY;
 440.621 +  if (!m_OutStream.Create(kBufferSize))
 440.622 +    return E_OUTOFMEMORY;
 440.623 +
 440.624 +  m_InStream.SetStream(inStream);
 440.625 +  m_InStream.Init();
 440.626 +
 440.627 +  m_OutStream.SetStream(outStream);
 440.628 +  m_OutStream.Init();
 440.629 +
 440.630 +  CDecoderFlusher flusher(this);
 440.631 +
 440.632 +  bool isBZ;
 440.633 +  RINOK(DecodeFile(isBZ, progress));
 440.634 +  return isBZ ? S_OK: S_FALSE;
 440.635 +}
 440.636 +
 440.637 +STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 440.638 +    const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
 440.639 +{
 440.640 +  try { return CodeReal(inStream, outStream, inSize, outSize, progress); }
 440.641 +  catch(const CInBufferException &e)  { return e.ErrorCode; }
 440.642 +  catch(const COutBufferException &e) { return e.ErrorCode; }
 440.643 +  catch(...) { return E_FAIL; }
 440.644 +}
 440.645 +
 440.646 +STDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value)
 440.647 +{
 440.648 +  if (value == NULL)
 440.649 +    return E_INVALIDARG;
 440.650 +  *value = m_InStream.GetProcessedSize();
 440.651 +  return S_OK;
 440.652 +}
 440.653 +
 440.654 +#ifdef COMPRESS_BZIP2_MT
 440.655 +
 440.656 +static THREAD_FUNC_DECL MFThread(void *p) { ((CState *)p)->ThreadFunc(); return 0; }
 440.657 +
 440.658 +HRESULT CState::Create()
 440.659 +{
 440.660 +  RINOK_THREAD(StreamWasFinishedEvent.CreateIfNotCreated());
 440.661 +  RINOK_THREAD(WaitingWasStartedEvent.CreateIfNotCreated());
 440.662 +  RINOK_THREAD(CanWriteEvent.CreateIfNotCreated());
 440.663 +  RINOK_THREAD(Thread.Create(MFThread, this));
 440.664 +  return S_OK;
 440.665 +}
 440.666 +
 440.667 +void CState::FinishStream()
 440.668 +{
 440.669 +  Decoder->StreamWasFinished1 = true;
 440.670 +  StreamWasFinishedEvent.Set();
 440.671 +  Decoder->CS.Leave();
 440.672 +  Decoder->CanStartWaitingEvent.Lock();
 440.673 +  WaitingWasStartedEvent.Set();
 440.674 +}
 440.675 +
 440.676 +void CState::ThreadFunc()
 440.677 +{
 440.678 +  for (;;)
 440.679 +  {
 440.680 +    Decoder->CanProcessEvent.Lock();
 440.681 +    Decoder->CS.Enter();
 440.682 +    if (Decoder->CloseThreads)
 440.683 +    {
 440.684 +      Decoder->CS.Leave();
 440.685 +      return;
 440.686 +    }
 440.687 +    if (Decoder->StreamWasFinished1)
 440.688 +    {
 440.689 +      FinishStream();
 440.690 +      continue;
 440.691 +    }
 440.692 +    HRESULT res = S_OK;
 440.693 +
 440.694 +    UInt32 blockIndex = Decoder->NextBlockIndex;
 440.695 +    UInt32 nextBlockIndex = blockIndex + 1;
 440.696 +    if (nextBlockIndex == Decoder->NumThreads)
 440.697 +      nextBlockIndex = 0;
 440.698 +    Decoder->NextBlockIndex = nextBlockIndex;
 440.699 +    UInt32 crc;
 440.700 +    UInt64 packSize;
 440.701 +    UInt32 blockSize = 0, origPtr = 0;
 440.702 +    bool randMode = false;
 440.703 +
 440.704 +    try
 440.705 +    {
 440.706 +      bool wasFinished;
 440.707 +      res = Decoder->ReadSignatures(wasFinished, crc);
 440.708 +      if (res != S_OK)
 440.709 +      {
 440.710 +        Decoder->Result1 = res;
 440.711 +        FinishStream();
 440.712 +        continue;
 440.713 +      }
 440.714 +      if (wasFinished)
 440.715 +      {
 440.716 +        Decoder->Result1 = res;
 440.717 +        FinishStream();
 440.718 +        continue;
 440.719 +      }
 440.720 +
 440.721 +      res = ReadBlock(&Decoder->m_InStream, Counters, Decoder->BlockSizeMax,
 440.722 +          Decoder->m_Selectors, Decoder->m_HuffmanDecoders,
 440.723 +          &blockSize, &origPtr, &randMode);
 440.724 +      if (res != S_OK)
 440.725 +      {
 440.726 +        Decoder->Result1 = res;
 440.727 +        FinishStream();
 440.728 +        continue;
 440.729 +      }
 440.730 +      packSize = Decoder->m_InStream.GetProcessedSize();
 440.731 +    }
 440.732 +    catch(const CInBufferException &e) { res = e.ErrorCode;  if (res != S_OK) res = E_FAIL; }
 440.733 +    catch(...) { res = E_FAIL; }
 440.734 +    if (res != S_OK)
 440.735 +    {
 440.736 +      Decoder->Result1 = res;
 440.737 +      FinishStream();
 440.738 +      continue;
 440.739 +    }
 440.740 +
 440.741 +    Decoder->CS.Leave();
 440.742 +
 440.743 +    DecodeBlock1(Counters, blockSize);
 440.744 +
 440.745 +    bool needFinish = true;
 440.746 +    try
 440.747 +    {
 440.748 +      Decoder->m_States[blockIndex].CanWriteEvent.Lock();
 440.749 +      needFinish = Decoder->StreamWasFinished2;
 440.750 +      if (!needFinish)
 440.751 +      {
 440.752 +        if ((randMode ?
 440.753 +          DecodeBlock2Rand(Counters + 256, blockSize, origPtr, Decoder->m_OutStream) :
 440.754 +          DecodeBlock2(Counters + 256, blockSize, origPtr, Decoder->m_OutStream)) == crc)
 440.755 +        {
 440.756 +          if (Decoder->Progress)
 440.757 +          {
 440.758 +            UInt64 unpackSize = Decoder->m_OutStream.GetProcessedSize();
 440.759 +            res = Decoder->Progress->SetRatioInfo(&packSize, &unpackSize);
 440.760 +          }
 440.761 +        }
 440.762 +        else
 440.763 +          res = S_FALSE;
 440.764 +      }
 440.765 +    }
 440.766 +    catch(const COutBufferException &e) { res = e.ErrorCode; if (res != S_OK) res = E_FAIL; }
 440.767 +    catch(...) { res = E_FAIL; }
 440.768 +    if (res != S_OK)
 440.769 +    {
 440.770 +      Decoder->Result2 = res;
 440.771 +      Decoder->StreamWasFinished2 = true;
 440.772 +    }
 440.773 +    Decoder->m_States[nextBlockIndex].CanWriteEvent.Set();
 440.774 +    if (res != S_OK || needFinish)
 440.775 +    {
 440.776 +      StreamWasFinishedEvent.Set();
 440.777 +      Decoder->CanStartWaitingEvent.Lock();
 440.778 +      WaitingWasStartedEvent.Set();
 440.779 +    }
 440.780 +  }
 440.781 +}
 440.782 +
 440.783 +STDMETHODIMP CDecoder::SetNumberOfThreads(UInt32 numThreads)
 440.784 +{
 440.785 +  NumThreads = numThreads;
 440.786 +  if (NumThreads < 1)
 440.787 +    NumThreads = 1;
 440.788 +  if (NumThreads > kNumThreadsMax)
 440.789 +    NumThreads = kNumThreadsMax;
 440.790 +  return S_OK;
 440.791 +}
 440.792 +#endif
 440.793 +
 440.794 +}}
   441.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   441.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BZip2Decoder.h	Sat Mar 03 10:31:27 2012 -0600
   441.3 @@ -0,0 +1,159 @@
   441.4 +// Compress/BZip2Decoder.h
   441.5 +
   441.6 +#ifndef __COMPRESS_BZIP2_DECODER_H
   441.7 +#define __COMPRESS_BZIP2_DECODER_H
   441.8 +
   441.9 +#include "../../Common/MyCom.h"
  441.10 +
  441.11 +#ifdef COMPRESS_BZIP2_MT
  441.12 +#include "../../Windows/Synchronization.h"
  441.13 +#include "../../Windows/Thread.h"
  441.14 +#endif
  441.15 +
  441.16 +#include "../ICoder.h"
  441.17 +
  441.18 +#include "../Common/InBuffer.h"
  441.19 +#include "../Common/OutBuffer.h"
  441.20 +
  441.21 +#include "BitmDecoder.h"
  441.22 +#include "BZip2Const.h"
  441.23 +#include "BZip2Crc.h"
  441.24 +#include "HuffmanDecoder.h"
  441.25 +
  441.26 +namespace NCompress {
  441.27 +namespace NBZip2 {
  441.28 +
  441.29 +typedef NCompress::NHuffman::CDecoder<kMaxHuffmanLen, kMaxAlphaSize> CHuffmanDecoder;
  441.30 +
  441.31 +class CDecoder;
  441.32 +
  441.33 +struct CState
  441.34 +{
  441.35 +  UInt32 *Counters;
  441.36 +
  441.37 +  #ifdef COMPRESS_BZIP2_MT
  441.38 +
  441.39 +  CDecoder *Decoder;
  441.40 +  NWindows::CThread Thread;
  441.41 +  bool m_OptimizeNumTables;
  441.42 +
  441.43 +  NWindows::NSynchronization::CAutoResetEvent StreamWasFinishedEvent;
  441.44 +  NWindows::NSynchronization::CAutoResetEvent WaitingWasStartedEvent;
  441.45 +
  441.46 +  // it's not member of this thread. We just need one event per thread
  441.47 +  NWindows::NSynchronization::CAutoResetEvent CanWriteEvent;
  441.48 +
  441.49 +  Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size.
  441.50 +
  441.51 +  HRESULT Create();
  441.52 +  void FinishStream();
  441.53 +  void ThreadFunc();
  441.54 +
  441.55 +  #endif
  441.56 +
  441.57 +  CState(): Counters(0) {}
  441.58 +  ~CState() { Free(); }
  441.59 +  bool Alloc();
  441.60 +  void Free();
  441.61 +};
  441.62 +
  441.63 +class CDecoder :
  441.64 +  public ICompressCoder,
  441.65 +  #ifdef COMPRESS_BZIP2_MT
  441.66 +  public ICompressSetCoderMt,
  441.67 +  #endif
  441.68 +  public ICompressGetInStreamProcessedSize,
  441.69 +  public CMyUnknownImp
  441.70 +{
  441.71 +public:
  441.72 +  COutBuffer m_OutStream;
  441.73 +  Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size.
  441.74 +  NBitm::CDecoder<CInBuffer> m_InStream;
  441.75 +  Byte m_Selectors[kNumSelectorsMax];
  441.76 +  CHuffmanDecoder m_HuffmanDecoders[kNumTablesMax];
  441.77 +private:
  441.78 +
  441.79 +  UInt32 m_NumThreadsPrev;
  441.80 +
  441.81 +  UInt32 ReadBits(int numBits);
  441.82 +  Byte ReadByte();
  441.83 +  bool ReadBit();
  441.84 +  UInt32 ReadCrc();
  441.85 +  HRESULT PrepareBlock(CState &state);
  441.86 +  HRESULT DecodeFile(bool &isBZ, ICompressProgressInfo *progress);
  441.87 +  HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  441.88 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
  441.89 +  class CDecoderFlusher
  441.90 +  {
  441.91 +    CDecoder *_decoder;
  441.92 +  public:
  441.93 +    bool NeedFlush;
  441.94 +    CDecoderFlusher(CDecoder *decoder): _decoder(decoder), NeedFlush(true) {}
  441.95 +    ~CDecoderFlusher()
  441.96 +    {
  441.97 +      if (NeedFlush)
  441.98 +        _decoder->Flush();
  441.99 +      _decoder->ReleaseStreams();
 441.100 +    }
 441.101 +  };
 441.102 +
 441.103 +public:
 441.104 +  CBZip2CombinedCrc CombinedCrc;
 441.105 +
 441.106 +  #ifdef COMPRESS_BZIP2_MT
 441.107 +  ICompressProgressInfo *Progress;
 441.108 +  CState *m_States;
 441.109 +
 441.110 +  NWindows::NSynchronization::CManualResetEvent CanProcessEvent;
 441.111 +  NWindows::NSynchronization::CCriticalSection CS;
 441.112 +  UInt32 NumThreads;
 441.113 +  bool MtMode;
 441.114 +  UInt32 NextBlockIndex;
 441.115 +  bool CloseThreads;
 441.116 +  bool StreamWasFinished1;
 441.117 +  bool StreamWasFinished2;
 441.118 +  NWindows::NSynchronization::CManualResetEvent CanStartWaitingEvent;
 441.119 +
 441.120 +  HRESULT Result1;
 441.121 +  HRESULT Result2;
 441.122 +
 441.123 +  UInt32 BlockSizeMax;
 441.124 +  CDecoder();
 441.125 +  ~CDecoder();
 441.126 +  HRESULT Create();
 441.127 +  void Free();
 441.128 +
 441.129 +  #else
 441.130 +  CState m_States[1];
 441.131 +  #endif
 441.132 +
 441.133 +  HRESULT ReadSignatures(bool &wasFinished, UInt32 &crc);
 441.134 +
 441.135 +
 441.136 +  HRESULT Flush() { return m_OutStream.Flush(); }
 441.137 +  void ReleaseStreams()
 441.138 +  {
 441.139 +    m_InStream.ReleaseStream();
 441.140 +    m_OutStream.ReleaseStream();
 441.141 +  }
 441.142 +
 441.143 +  #ifdef COMPRESS_BZIP2_MT
 441.144 +  MY_UNKNOWN_IMP2(ICompressSetCoderMt, ICompressGetInStreamProcessedSize)
 441.145 +  #else
 441.146 +  MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)
 441.147 +  #endif
 441.148 +
 441.149 +  
 441.150 +  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 441.151 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
 441.152 +
 441.153 +  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
 441.154 +
 441.155 +  #ifdef COMPRESS_BZIP2_MT
 441.156 +  STDMETHOD(SetNumberOfThreads)(UInt32 numThreads);
 441.157 +  #endif
 441.158 +};
 441.159 +
 441.160 +}}
 441.161 +
 441.162 +#endif
   442.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   442.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BZip2Register.cpp	Sat Mar 03 10:31:27 2012 -0600
   442.3 @@ -0,0 +1,20 @@
   442.4 +// BZip2Register.cpp
   442.5 +
   442.6 +#include "StdAfx.h"
   442.7 +
   442.8 +#include "../Common/RegisterCodec.h"
   442.9 +
  442.10 +#include "BZip2Decoder.h"
  442.11 +
  442.12 +static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NBZip2::CDecoder); }
  442.13 +#if !defined(EXTRACT_ONLY) && !defined(BZIP2_EXTRACT_ONLY)
  442.14 +#include "BZip2Encoder.h"
  442.15 +static void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NBZip2::CEncoder);  }
  442.16 +#else
  442.17 +#define CreateCodecOut 0
  442.18 +#endif
  442.19 +
  442.20 +static CCodecInfo g_CodecInfo =
  442.21 +  { CreateCodec, CreateCodecOut, 0x040202, L"BZip2", 1, false };
  442.22 +
  442.23 +REGISTER_CODEC(BZip2)
   443.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   443.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/Bcj2Coder.cpp	Sat Mar 03 10:31:27 2012 -0600
   443.3 @@ -0,0 +1,393 @@
   443.4 +// Bcj2Coder.cpp
   443.5 +
   443.6 +#include "StdAfx.h"
   443.7 +
   443.8 +extern "C"
   443.9 +{
  443.10 +#include "../../../C/Alloc.h"
  443.11 +}
  443.12 +
  443.13 +#include "Bcj2Coder.h"
  443.14 +
  443.15 +namespace NCompress {
  443.16 +namespace NBcj2 {
  443.17 +
  443.18 +inline bool IsJcc(Byte b0, Byte b1) { return (b0 == 0x0F && (b1 & 0xF0) == 0x80); }
  443.19 +inline bool IsJ(Byte b0, Byte b1) { return ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)); }
  443.20 +inline unsigned GetIndex(Byte b0, Byte b1) { return ((b1 == 0xE8) ? b0 : ((b1 == 0xE9) ? 256 : 257)); }
  443.21 +
  443.22 +#ifndef EXTRACT_ONLY
  443.23 +
  443.24 +static const int kBufferSize = 1 << 17;
  443.25 +
  443.26 +static bool inline Test86MSByte(Byte b)
  443.27 +{
  443.28 +  return (b == 0 || b == 0xFF);
  443.29 +}
  443.30 +
  443.31 +bool CEncoder::Create()
  443.32 +{
  443.33 +  if (!_mainStream.Create(1 << 16))
  443.34 +    return false;
  443.35 +  if (!_callStream.Create(1 << 20))
  443.36 +    return false;
  443.37 +  if (!_jumpStream.Create(1 << 20))
  443.38 +    return false;
  443.39 +  if (!_rangeEncoder.Create(1 << 20))
  443.40 +    return false;
  443.41 +  if (_buffer == 0)
  443.42 +  {
  443.43 +    _buffer = (Byte *)MidAlloc(kBufferSize);
  443.44 +    if (_buffer == 0)
  443.45 +      return false;
  443.46 +  }
  443.47 +  return true;
  443.48 +}
  443.49 +
  443.50 +CEncoder::~CEncoder()
  443.51 +{
  443.52 +  ::MidFree(_buffer);
  443.53 +}
  443.54 +
  443.55 +HRESULT CEncoder::Flush()
  443.56 +{
  443.57 +  RINOK(_mainStream.Flush());
  443.58 +  RINOK(_callStream.Flush());
  443.59 +  RINOK(_jumpStream.Flush());
  443.60 +  _rangeEncoder.FlushData();
  443.61 +  return _rangeEncoder.FlushStream();
  443.62 +}
  443.63 +
  443.64 +const UInt32 kDefaultLimit = (1 << 24);
  443.65 +
  443.66 +HRESULT CEncoder::CodeReal(ISequentialInStream **inStreams,
  443.67 +      const UInt64 **inSizes,
  443.68 +      UInt32 numInStreams,
  443.69 +      ISequentialOutStream **outStreams,
  443.70 +      const UInt64 ** /* outSizes */,
  443.71 +      UInt32 numOutStreams,
  443.72 +      ICompressProgressInfo *progress)
  443.73 +{
  443.74 +  if (numInStreams != 1 || numOutStreams != 4)
  443.75 +    return E_INVALIDARG;
  443.76 +
  443.77 +  if (!Create())
  443.78 +    return E_OUTOFMEMORY;
  443.79 +
  443.80 +  bool sizeIsDefined = false;
  443.81 +  UInt64 inSize = 0;
  443.82 +  if (inSizes != NULL)
  443.83 +    if (inSizes[0] != NULL)
  443.84 +    {
  443.85 +      inSize = *inSizes[0];
  443.86 +      if (inSize <= kDefaultLimit)
  443.87 +        sizeIsDefined = true;
  443.88 +    }
  443.89 +
  443.90 +  ISequentialInStream *inStream = inStreams[0];
  443.91 +
  443.92 +  _mainStream.SetStream(outStreams[0]);
  443.93 +  _mainStream.Init();
  443.94 +  _callStream.SetStream(outStreams[1]);
  443.95 +  _callStream.Init();
  443.96 +  _jumpStream.SetStream(outStreams[2]);
  443.97 +  _jumpStream.Init();
  443.98 +  _rangeEncoder.SetStream(outStreams[3]);
  443.99 +  _rangeEncoder.Init();
 443.100 +  for (int i = 0; i < 256 + 2; i++)
 443.101 +    _statusEncoder[i].Init();
 443.102 +  CCoderReleaser releaser(this);
 443.103 +
 443.104 +  CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;
 443.105 +  {
 443.106 +    inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);
 443.107 +  }
 443.108 +
 443.109 +  UInt32 nowPos = 0;
 443.110 +  UInt64 nowPos64 = 0;
 443.111 +  UInt32 bufferPos = 0;
 443.112 +
 443.113 +  Byte prevByte = 0;
 443.114 +
 443.115 +  UInt64 subStreamIndex = 0;
 443.116 +  UInt64 subStreamStartPos  = 0;
 443.117 +  UInt64 subStreamEndPos = 0;
 443.118 +
 443.119 +  for (;;)
 443.120 +  {
 443.121 +    UInt32 processedSize = 0;
 443.122 +    for (;;)
 443.123 +    {
 443.124 +      UInt32 size = kBufferSize - (bufferPos + processedSize);
 443.125 +      UInt32 processedSizeLoc;
 443.126 +      if (size == 0)
 443.127 +        break;
 443.128 +      RINOK(inStream->Read(_buffer + bufferPos + processedSize, size, &processedSizeLoc));
 443.129 +      if (processedSizeLoc == 0)
 443.130 +        break;
 443.131 +      processedSize += processedSizeLoc;
 443.132 +    }
 443.133 +    UInt32 endPos = bufferPos + processedSize;
 443.134 +    
 443.135 +    if (endPos < 5)
 443.136 +    {
 443.137 +      // change it
 443.138 +      for (bufferPos = 0; bufferPos < endPos; bufferPos++)
 443.139 +      {
 443.140 +        Byte b = _buffer[bufferPos];
 443.141 +        _mainStream.WriteByte(b);
 443.142 +        UInt32 index;
 443.143 +        if (b == 0xE8)
 443.144 +          index = prevByte;
 443.145 +        else if (b == 0xE9)
 443.146 +          index = 256;
 443.147 +        else if (IsJcc(prevByte, b))
 443.148 +          index = 257;
 443.149 +        else
 443.150 +        {
 443.151 +          prevByte = b;
 443.152 +          continue;
 443.153 +        }
 443.154 +        _statusEncoder[index].Encode(&_rangeEncoder, 0);
 443.155 +        prevByte = b;
 443.156 +      }
 443.157 +      return Flush();
 443.158 +    }
 443.159 +
 443.160 +    bufferPos = 0;
 443.161 +
 443.162 +    UInt32 limit = endPos - 5;
 443.163 +    while(bufferPos <= limit)
 443.164 +    {
 443.165 +      Byte b = _buffer[bufferPos];
 443.166 +      _mainStream.WriteByte(b);
 443.167 +      if (!IsJ(prevByte, b))
 443.168 +      {
 443.169 +        bufferPos++;
 443.170 +        prevByte = b;
 443.171 +        continue;
 443.172 +      }
 443.173 +      Byte nextByte = _buffer[bufferPos + 4];
 443.174 +      UInt32 src =
 443.175 +        (UInt32(nextByte) << 24) |
 443.176 +        (UInt32(_buffer[bufferPos + 3]) << 16) |
 443.177 +        (UInt32(_buffer[bufferPos + 2]) << 8) |
 443.178 +        (_buffer[bufferPos + 1]);
 443.179 +      UInt32 dest = (nowPos + bufferPos + 5) + src;
 443.180 +      // if (Test86MSByte(nextByte))
 443.181 +      bool convert;
 443.182 +      if (getSubStreamSize != NULL)
 443.183 +      {
 443.184 +        UInt64 currentPos = (nowPos64 + bufferPos);
 443.185 +        while (subStreamEndPos < currentPos)
 443.186 +        {
 443.187 +          UInt64 subStreamSize;
 443.188 +          HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);
 443.189 +          if (result == S_OK)
 443.190 +          {
 443.191 +            subStreamStartPos = subStreamEndPos;
 443.192 +            subStreamEndPos += subStreamSize;
 443.193 +            subStreamIndex++;
 443.194 +          }
 443.195 +          else if (result == S_FALSE || result == E_NOTIMPL)
 443.196 +          {
 443.197 +            getSubStreamSize.Release();
 443.198 +            subStreamStartPos = 0;
 443.199 +            subStreamEndPos = subStreamStartPos - 1;
 443.200 +          }
 443.201 +          else
 443.202 +            return result;
 443.203 +        }
 443.204 +        if (getSubStreamSize == NULL)
 443.205 +        {
 443.206 +          if (sizeIsDefined)
 443.207 +            convert = (dest < inSize);
 443.208 +          else
 443.209 +            convert = Test86MSByte(nextByte);
 443.210 +        }
 443.211 +        else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)
 443.212 +          convert = Test86MSByte(nextByte);
 443.213 +        else
 443.214 +        {
 443.215 +          UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));
 443.216 +          convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);
 443.217 +        }
 443.218 +      }
 443.219 +      else if (sizeIsDefined)
 443.220 +        convert = (dest < inSize);
 443.221 +      else
 443.222 +        convert = Test86MSByte(nextByte);
 443.223 +      unsigned index = GetIndex(prevByte, b);
 443.224 +      if (convert)
 443.225 +      {
 443.226 +        _statusEncoder[index].Encode(&_rangeEncoder, 1);
 443.227 +        bufferPos += 5;
 443.228 +        COutBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;
 443.229 +        for (int i = 24; i >= 0; i -= 8)
 443.230 +          s.WriteByte((Byte)(dest >> i));
 443.231 +        prevByte = nextByte;
 443.232 +      }
 443.233 +      else
 443.234 +      {
 443.235 +        _statusEncoder[index].Encode(&_rangeEncoder, 0);
 443.236 +        bufferPos++;
 443.237 +        prevByte = b;
 443.238 +      }
 443.239 +    }
 443.240 +    nowPos += bufferPos;
 443.241 +    nowPos64 += bufferPos;
 443.242 +
 443.243 +    if (progress != NULL)
 443.244 +    {
 443.245 +      /*
 443.246 +      const UInt64 compressedSize =
 443.247 +        _mainStream.GetProcessedSize() +
 443.248 +        _callStream.GetProcessedSize() +
 443.249 +        _jumpStream.GetProcessedSize() +
 443.250 +        _rangeEncoder.GetProcessedSize();
 443.251 +      */
 443.252 +      RINOK(progress->SetRatioInfo(&nowPos64, NULL));
 443.253 +    }
 443.254 + 
 443.255 +    UInt32 i = 0;
 443.256 +    while(bufferPos < endPos)
 443.257 +      _buffer[i++] = _buffer[bufferPos++];
 443.258 +    bufferPos = i;
 443.259 +  }
 443.260 +}
 443.261 +
 443.262 +STDMETHODIMP CEncoder::Code(ISequentialInStream **inStreams,
 443.263 +      const UInt64 **inSizes,
 443.264 +      UInt32 numInStreams,
 443.265 +      ISequentialOutStream **outStreams,
 443.266 +      const UInt64 **outSizes,
 443.267 +      UInt32 numOutStreams,
 443.268 +      ICompressProgressInfo *progress)
 443.269 +{
 443.270 +  try
 443.271 +  {
 443.272 +    return CodeReal(inStreams, inSizes, numInStreams,
 443.273 +      outStreams, outSizes,numOutStreams, progress);
 443.274 +  }
 443.275 +  catch(const COutBufferException &e) { return e.ErrorCode; }
 443.276 +  catch(...) { return S_FALSE; }
 443.277 +}
 443.278 +
 443.279 +#endif
 443.280 +
 443.281 +HRESULT CDecoder::CodeReal(ISequentialInStream **inStreams,
 443.282 +      const UInt64 ** /* inSizes */,
 443.283 +      UInt32 numInStreams,
 443.284 +      ISequentialOutStream **outStreams,
 443.285 +      const UInt64 ** /* outSizes */,
 443.286 +      UInt32 numOutStreams,
 443.287 +      ICompressProgressInfo *progress)
 443.288 +{
 443.289 +  if (numInStreams != 4 || numOutStreams != 1)
 443.290 +    return E_INVALIDARG;
 443.291 +
 443.292 +  if (!_mainInStream.Create(1 << 16))
 443.293 +    return E_OUTOFMEMORY;
 443.294 +  if (!_callStream.Create(1 << 20))
 443.295 +    return E_OUTOFMEMORY;
 443.296 +  if (!_jumpStream.Create(1 << 16))
 443.297 +    return E_OUTOFMEMORY;
 443.298 +  if (!_rangeDecoder.Create(1 << 20))
 443.299 +    return E_OUTOFMEMORY;
 443.300 +  if (!_outStream.Create(1 << 16))
 443.301 +    return E_OUTOFMEMORY;
 443.302 +
 443.303 +  _mainInStream.SetStream(inStreams[0]);
 443.304 +  _callStream.SetStream(inStreams[1]);
 443.305 +  _jumpStream.SetStream(inStreams[2]);
 443.306 +  _rangeDecoder.SetStream(inStreams[3]);
 443.307 +  _outStream.SetStream(outStreams[0]);
 443.308 +
 443.309 +  _mainInStream.Init();
 443.310 +  _callStream.Init();
 443.311 +  _jumpStream.Init();
 443.312 +  _rangeDecoder.Init();
 443.313 +  _outStream.Init();
 443.314 +
 443.315 +  for (int i = 0; i < 256 + 2; i++)
 443.316 +    _statusDecoder[i].Init();
 443.317 +
 443.318 +  CCoderReleaser releaser(this);
 443.319 +
 443.320 +  Byte prevByte = 0;
 443.321 +  UInt32 processedBytes = 0;
 443.322 +  for (;;)
 443.323 +  {
 443.324 +    if (processedBytes >= (1 << 20) && progress != NULL)
 443.325 +    {
 443.326 +      /*
 443.327 +      const UInt64 compressedSize =
 443.328 +        _mainInStream.GetProcessedSize() +
 443.329 +        _callStream.GetProcessedSize() +
 443.330 +        _jumpStream.GetProcessedSize() +
 443.331 +        _rangeDecoder.GetProcessedSize();
 443.332 +      */
 443.333 +      const UInt64 nowPos64 = _outStream.GetProcessedSize();
 443.334 +      RINOK(progress->SetRatioInfo(NULL, &nowPos64));
 443.335 +      processedBytes = 0;
 443.336 +    }
 443.337 +    UInt32 i;
 443.338 +    Byte b = 0;
 443.339 +    const UInt32 kBurstSize = (1 << 18);
 443.340 +    for (i = 0; i < kBurstSize; i++)
 443.341 +    {
 443.342 +      if (!_mainInStream.ReadByte(b))
 443.343 +        return Flush();
 443.344 +      _outStream.WriteByte(b);
 443.345 +      if (IsJ(prevByte, b))
 443.346 +        break;
 443.347 +      prevByte = b;
 443.348 +    }
 443.349 +    processedBytes += i;
 443.350 +    if (i == kBurstSize)
 443.351 +      continue;
 443.352 +    unsigned index = GetIndex(prevByte, b);
 443.353 +    if (_statusDecoder[index].Decode(&_rangeDecoder) == 1)
 443.354 +    {
 443.355 +      UInt32 src = 0;
 443.356 +      CInBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;
 443.357 +      for (int i = 0; i < 4; i++)
 443.358 +      {
 443.359 +        Byte b0;
 443.360 +        if(!s.ReadByte(b0))
 443.361 +          return S_FALSE;
 443.362 +        src <<= 8;
 443.363 +        src |= ((UInt32)b0);
 443.364 +      }
 443.365 +      UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;
 443.366 +      _outStream.WriteByte((Byte)(dest));
 443.367 +      _outStream.WriteByte((Byte)(dest >> 8));
 443.368 +      _outStream.WriteByte((Byte)(dest >> 16));
 443.369 +      _outStream.WriteByte((Byte)(dest >> 24));
 443.370 +      prevByte = (Byte)(dest >> 24);
 443.371 +      processedBytes += 4;
 443.372 +    }
 443.373 +    else
 443.374 +      prevByte = b;
 443.375 +  }
 443.376 +}
 443.377 +
 443.378 +STDMETHODIMP CDecoder::Code(ISequentialInStream **inStreams,
 443.379 +      const UInt64 **inSizes,
 443.380 +      UInt32 numInStreams,
 443.381 +      ISequentialOutStream **outStreams,
 443.382 +      const UInt64 **outSizes,
 443.383 +      UInt32 numOutStreams,
 443.384 +      ICompressProgressInfo *progress)
 443.385 +{
 443.386 +  try
 443.387 +  {
 443.388 +    return CodeReal(inStreams, inSizes, numInStreams,
 443.389 +        outStreams, outSizes,numOutStreams, progress);
 443.390 +  }
 443.391 +  catch(const CInBufferException &e) { return e.ErrorCode; }
 443.392 +  catch(const COutBufferException &e) { return e.ErrorCode; }
 443.393 +  catch(...) { return S_FALSE; }
 443.394 +}
 443.395 +
 443.396 +}}
   444.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   444.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/Bcj2Coder.h	Sat Mar 03 10:31:27 2012 -0600
   444.3 @@ -0,0 +1,125 @@
   444.4 +// Bcj2Coder.h
   444.5 +
   444.6 +#ifndef __COMPRESS_BCJ2_CODER_H
   444.7 +#define __COMPRESS_BCJ2_CODER_H
   444.8 +
   444.9 +#include "../../Common/MyCom.h"
  444.10 +
  444.11 +#include "../ICoder.h"
  444.12 +
  444.13 +#include "RangeCoderBit.h"
  444.14 +
  444.15 +namespace NCompress {
  444.16 +namespace NBcj2 {
  444.17 +
  444.18 +const int kNumMoveBits = 5;
  444.19 +
  444.20 +#ifndef EXTRACT_ONLY
  444.21 +
  444.22 +class CEncoder:
  444.23 +  public ICompressCoder2,
  444.24 +  public CMyUnknownImp
  444.25 +{
  444.26 +  Byte *_buffer;
  444.27 +public:
  444.28 +  CEncoder(): _buffer(0) {};
  444.29 +  ~CEncoder();
  444.30 +  bool Create();
  444.31 +
  444.32 +  COutBuffer _mainStream;
  444.33 +  COutBuffer _callStream;
  444.34 +  COutBuffer _jumpStream;
  444.35 +  NCompress::NRangeCoder::CEncoder _rangeEncoder;
  444.36 +  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusEncoder[256 + 2];
  444.37 +
  444.38 +  HRESULT Flush();
  444.39 +  void ReleaseStreams()
  444.40 +  {
  444.41 +    _mainStream.ReleaseStream();
  444.42 +    _callStream.ReleaseStream();
  444.43 +    _jumpStream.ReleaseStream();
  444.44 +    _rangeEncoder.ReleaseStream();
  444.45 +  }
  444.46 +
  444.47 +  class CCoderReleaser
  444.48 +  {
  444.49 +    CEncoder *_coder;
  444.50 +  public:
  444.51 +    CCoderReleaser(CEncoder *coder): _coder(coder) {}
  444.52 +    ~CCoderReleaser() {  _coder->ReleaseStreams(); }
  444.53 +  };
  444.54 +
  444.55 +public:
  444.56 +
  444.57 +  MY_UNKNOWN_IMP
  444.58 +
  444.59 +  HRESULT CodeReal(ISequentialInStream **inStreams,
  444.60 +      const UInt64 **inSizes,
  444.61 +      UInt32 numInStreams,
  444.62 +      ISequentialOutStream **outStreams,
  444.63 +      const UInt64 **outSizes,
  444.64 +      UInt32 numOutStreams,
  444.65 +      ICompressProgressInfo *progress);
  444.66 +  STDMETHOD(Code)(ISequentialInStream **inStreams,
  444.67 +      const UInt64 **inSizes,
  444.68 +      UInt32 numInStreams,
  444.69 +      ISequentialOutStream **outStreams,
  444.70 +      const UInt64 **outSizes,
  444.71 +      UInt32 numOutStreams,
  444.72 +      ICompressProgressInfo *progress);
  444.73 +};
  444.74 +
  444.75 +#endif
  444.76 +
  444.77 +class CDecoder:
  444.78 +  public ICompressCoder2,
  444.79 +  public CMyUnknownImp
  444.80 +{
  444.81 +public:
  444.82 +  CInBuffer _mainInStream;
  444.83 +  CInBuffer _callStream;
  444.84 +  CInBuffer _jumpStream;
  444.85 +  NCompress::NRangeCoder::CDecoder _rangeDecoder;
  444.86 +  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusDecoder[256 + 2];
  444.87 +
  444.88 +  COutBuffer _outStream;
  444.89 +
  444.90 +  void ReleaseStreams()
  444.91 +  {
  444.92 +    _mainInStream.ReleaseStream();
  444.93 +    _callStream.ReleaseStream();
  444.94 +    _jumpStream.ReleaseStream();
  444.95 +    _rangeDecoder.ReleaseStream();
  444.96 +    _outStream.ReleaseStream();
  444.97 +  }
  444.98 +
  444.99 +  HRESULT Flush() { return _outStream.Flush(); }
 444.100 +  class CCoderReleaser
 444.101 +  {
 444.102 +    CDecoder *_coder;
 444.103 +  public:
 444.104 +    CCoderReleaser(CDecoder *coder): _coder(coder) {}
 444.105 +    ~CCoderReleaser()  { _coder->ReleaseStreams(); }
 444.106 +  };
 444.107 +
 444.108 +public:
 444.109 +  MY_UNKNOWN_IMP
 444.110 +  HRESULT CodeReal(ISequentialInStream **inStreams,
 444.111 +      const UInt64 **inSizes,
 444.112 +      UInt32 numInStreams,
 444.113 +      ISequentialOutStream **outStreams,
 444.114 +      const UInt64 **outSizes,
 444.115 +      UInt32 numOutStreams,
 444.116 +      ICompressProgressInfo *progress);
 444.117 +  STDMETHOD(Code)(ISequentialInStream **inStreams,
 444.118 +      const UInt64 **inSizes,
 444.119 +      UInt32 numInStreams,
 444.120 +      ISequentialOutStream **outStreams,
 444.121 +      const UInt64 **outSizes,
 444.122 +      UInt32 numOutStreams,
 444.123 +      ICompressProgressInfo *progress);
 444.124 +};
 444.125 +
 444.126 +}}
 444.127 +
 444.128 +#endif
   445.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   445.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/Bcj2Register.cpp	Sat Mar 03 10:31:27 2012 -0600
   445.3 @@ -0,0 +1,19 @@
   445.4 +// Bcj2Register.cpp
   445.5 +
   445.6 +#include "StdAfx.h"
   445.7 +
   445.8 +#include "../Common/RegisterCodec.h"
   445.9 +
  445.10 +#include "Bcj2Coder.h"
  445.11 +
  445.12 +static void *CreateCodec() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CDecoder()); }
  445.13 +#ifndef EXTRACT_ONLY
  445.14 +static void *CreateCodecOut() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CEncoder());  }
  445.15 +#else
  445.16 +#define CreateCodecOut 0
  445.17 +#endif
  445.18 +
  445.19 +static CCodecInfo g_CodecInfo =
  445.20 +  { CreateCodec, CreateCodecOut, 0x0303011B, L"BCJ2", 4, false };
  445.21 +
  445.22 +REGISTER_CODEC(BCJ2)
   446.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   446.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BcjCoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   446.3 @@ -0,0 +1,15 @@
   446.4 +// BcjCoder.cpp
   446.5 +
   446.6 +#include "StdAfx.h"
   446.7 +
   446.8 +#include "BcjCoder.h"
   446.9 +
  446.10 +UInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)
  446.11 +{
  446.12 +  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 1);
  446.13 +}
  446.14 +
  446.15 +UInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)
  446.16 +{
  446.17 +  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 0);
  446.18 +}
   447.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   447.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BcjCoder.h	Sat Mar 03 10:31:27 2012 -0600
   447.3 @@ -0,0 +1,22 @@
   447.4 +// BcjCoder.h
   447.5 +
   447.6 +#ifndef __COMPRESS_BCJ_CODER_H
   447.7 +#define __COMPRESS_BCJ_CODER_H
   447.8 +
   447.9 +extern "C"
  447.10 +{
  447.11 +#include "../../../C/Bra.h"
  447.12 +}
  447.13 +
  447.14 +#include "BranchCoder.h"
  447.15 +
  447.16 +struct CBranch86
  447.17 +{
  447.18 +  UInt32 _prevMask;
  447.19 +  void x86Init() { x86_Convert_Init(_prevMask); }
  447.20 +};
  447.21 +
  447.22 +MyClassB(BCJ_x86, 0x01, 3, CBranch86 ,
  447.23 +    virtual void SubInit() { x86Init(); })
  447.24 +
  447.25 +#endif
   448.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   448.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BcjRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   448.3 @@ -0,0 +1,19 @@
   448.4 +// BcjRegister.cpp
   448.5 +
   448.6 +#include "StdAfx.h"
   448.7 +
   448.8 +#include "../Common/RegisterCodec.h"
   448.9 +
  448.10 +#include "BcjCoder.h"
  448.11 +
  448.12 +static void *CreateCodec() { return (void *)(ICompressFilter *)(new CBCJ_x86_Decoder()); }
  448.13 +#ifndef EXTRACT_ONLY
  448.14 +static void *CreateCodecOut() { return (void *)(ICompressFilter *)(new CBCJ_x86_Encoder());  }
  448.15 +#else
  448.16 +#define CreateCodecOut 0
  448.17 +#endif
  448.18 +
  448.19 +static CCodecInfo g_CodecInfo =
  448.20 +  { CreateCodec, CreateCodecOut, 0x03030103, L"BCJ", 1, true };
  448.21 +
  448.22 +REGISTER_CODEC(BCJ)
   449.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   449.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BitlDecoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   449.3 @@ -0,0 +1,24 @@
   449.4 +// BitlDecoder.cpp
   449.5 +
   449.6 +#include "StdAfx.h"
   449.7 +
   449.8 +#include "BitlDecoder.h"
   449.9 +
  449.10 +namespace NBitl {
  449.11 +
  449.12 +Byte kInvertTable[256];
  449.13 +
  449.14 +struct CInverterTableInitializer
  449.15 +{
  449.16 +  CInverterTableInitializer()
  449.17 +  {
  449.18 +    for (int i = 0; i < 256; i++)
  449.19 +    {
  449.20 +      int x = ((i & 0x55) << 1) | ((i & 0xAA) >> 1);
  449.21 +      x = ((x & 0x33) << 2) | ((x & 0xCC) >> 2);
  449.22 +      kInvertTable[i] = (Byte)(((x & 0x0F) << 4) | ((x & 0xF0) >> 4));
  449.23 +    }
  449.24 +  }
  449.25 +} g_InverterTableInitializer;
  449.26 +
  449.27 +}
   450.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   450.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BitlDecoder.h	Sat Mar 03 10:31:27 2012 -0600
   450.3 @@ -0,0 +1,125 @@
   450.4 +// BitlDecoder.h -- the Least Significant Bit of byte is First
   450.5 +
   450.6 +#ifndef __BITL_DECODER_H
   450.7 +#define __BITL_DECODER_H
   450.8 +
   450.9 +#include "../IStream.h"
  450.10 +
  450.11 +namespace NBitl {
  450.12 +
  450.13 +const int kNumBigValueBits = 8 * 4;
  450.14 +
  450.15 +const int kNumValueBytes = 3;
  450.16 +const int kNumValueBits = 8  * kNumValueBytes;
  450.17 +
  450.18 +const UInt32 kMask = (1 << kNumValueBits) - 1;
  450.19 +
  450.20 +extern Byte kInvertTable[256];
  450.21 +
  450.22 +template<class TInByte>
  450.23 +class CBaseDecoder
  450.24 +{
  450.25 +protected:
  450.26 +  int m_BitPos;
  450.27 +  UInt32 m_Value;
  450.28 +  TInByte m_Stream;
  450.29 +public:
  450.30 +  UInt32 NumExtraBytes;
  450.31 +  bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
  450.32 +  void SetStream(ISequentialInStream *inStream) { m_Stream.SetStream(inStream); }
  450.33 +  void ReleaseStream() { m_Stream.ReleaseStream(); }
  450.34 +  void Init()
  450.35 +  {
  450.36 +    m_Stream.Init();
  450.37 +    m_BitPos = kNumBigValueBits;
  450.38 +    m_Value = 0;
  450.39 +    NumExtraBytes = 0;
  450.40 +  }
  450.41 +  UInt64 GetProcessedSize() const
  450.42 +    { return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; }
  450.43 +  UInt64 GetProcessedBitsSize() const
  450.44 +    { return (m_Stream.GetProcessedSize() << 3) - (kNumBigValueBits - m_BitPos); }
  450.45 +  int GetBitPosition() const { return (m_BitPos & 7); }
  450.46 +
  450.47 +  void Normalize()
  450.48 +  {
  450.49 +    for (;m_BitPos >= 8; m_BitPos -= 8)
  450.50 +    {
  450.51 +      Byte b = 0;
  450.52 +      if (!m_Stream.ReadByte(b))
  450.53 +      {
  450.54 +        b = 0xFF; // check it
  450.55 +        NumExtraBytes++;
  450.56 +      }
  450.57 +      m_Value = (b << (kNumBigValueBits - m_BitPos)) | m_Value;
  450.58 +    }
  450.59 +  }
  450.60 +  
  450.61 +  UInt32 ReadBits(int numBits)
  450.62 +  {
  450.63 +    Normalize();
  450.64 +    UInt32 res = m_Value & ((1 << numBits) - 1);
  450.65 +    m_BitPos += numBits;
  450.66 +    m_Value >>= numBits;
  450.67 +    return res;
  450.68 +  }
  450.69 +
  450.70 +  bool ExtraBitsWereRead() const
  450.71 +  {
  450.72 +    if (NumExtraBytes == 0)
  450.73 +      return false;
  450.74 +    return ((UInt32)(kNumBigValueBits - m_BitPos) < (NumExtraBytes << 3));
  450.75 +  }
  450.76 +};
  450.77 +
  450.78 +template<class TInByte>
  450.79 +class CDecoder: public CBaseDecoder<TInByte>
  450.80 +{
  450.81 +  UInt32 m_NormalValue;
  450.82 +
  450.83 +public:
  450.84 +  void Init()
  450.85 +  {
  450.86 +    CBaseDecoder<TInByte>::Init();
  450.87 +    m_NormalValue = 0;
  450.88 +  }
  450.89 +
  450.90 +  void Normalize()
  450.91 +  {
  450.92 +    for (; this->m_BitPos >= 8; this->m_BitPos -= 8)
  450.93 +    {
  450.94 +      Byte b = 0;
  450.95 +      if (!this->m_Stream.ReadByte(b))
  450.96 +      {
  450.97 +        b = 0xFF; // check it
  450.98 +        this->NumExtraBytes++;
  450.99 +      }
 450.100 +      m_NormalValue = (b << (kNumBigValueBits - this->m_BitPos)) | m_NormalValue;
 450.101 +      this->m_Value = (this->m_Value << 8) | kInvertTable[b];
 450.102 +    }
 450.103 +  }
 450.104 +  
 450.105 +  UInt32 GetValue(int numBits)
 450.106 +  {
 450.107 +    Normalize();
 450.108 +    return ((this->m_Value >> (8 - this->m_BitPos)) & kMask) >> (kNumValueBits - numBits);
 450.109 +  }
 450.110 +
 450.111 +  void MovePos(int numBits)
 450.112 +  {
 450.113 +    this->m_BitPos += numBits;
 450.114 +    m_NormalValue >>= numBits;
 450.115 +  }
 450.116 +  
 450.117 +  UInt32 ReadBits(int numBits)
 450.118 +  {
 450.119 +    Normalize();
 450.120 +    UInt32 res = m_NormalValue & ( (1 << numBits) - 1);
 450.121 +    MovePos(numBits);
 450.122 +    return res;
 450.123 +  }
 450.124 +};
 450.125 +
 450.126 +}
 450.127 +
 450.128 +#endif
   451.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   451.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BitmDecoder.h	Sat Mar 03 10:31:27 2012 -0600
   451.3 @@ -0,0 +1,66 @@
   451.4 +// BitmDecoder.h -- the Most Significant Bit of byte is First
   451.5 +
   451.6 +#ifndef __BITM_DECODER_H
   451.7 +#define __BITM_DECODER_H
   451.8 +
   451.9 +#include "../IStream.h"
  451.10 +
  451.11 +namespace NBitm {
  451.12 +
  451.13 +const int kNumBigValueBits = 8 * 4;
  451.14 +const int kNumValueBytes = 3;
  451.15 +const int kNumValueBits = 8  * kNumValueBytes;
  451.16 +
  451.17 +const UInt32 kMask = (1 << kNumValueBits) - 1;
  451.18 +
  451.19 +template<class TInByte>
  451.20 +class CDecoder
  451.21 +{
  451.22 +  UInt32 m_BitPos;
  451.23 +  UInt32 m_Value;
  451.24 +public:
  451.25 +  TInByte m_Stream;
  451.26 +  bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
  451.27 +  void SetStream(ISequentialInStream *inStream) { m_Stream.SetStream(inStream);}
  451.28 +  void ReleaseStream() { m_Stream.ReleaseStream();}
  451.29 +
  451.30 +  void Init()
  451.31 +  {
  451.32 +    m_Stream.Init();
  451.33 +    m_BitPos = kNumBigValueBits;
  451.34 +    Normalize();
  451.35 +  }
  451.36 +  
  451.37 +  UInt64 GetProcessedSize() const
  451.38 +    { return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; }
  451.39 +  UInt32 GetBitPosition() const { return (m_BitPos & 7); }
  451.40 +  
  451.41 +  void Normalize()
  451.42 +  {
  451.43 +    for (;m_BitPos >= 8; m_BitPos -= 8)
  451.44 +      m_Value = (m_Value << 8) | m_Stream.ReadByte();
  451.45 +  }
  451.46 +
  451.47 +  UInt32 GetValue(UInt32 numBits) const
  451.48 +  {
  451.49 +    // return (m_Value << m_BitPos) >> (kNumBigValueBits - numBits);
  451.50 +    return ((m_Value >> (8 - m_BitPos)) & kMask) >> (kNumValueBits - numBits);
  451.51 +  }
  451.52 +  
  451.53 +  void MovePos(UInt32 numBits)
  451.54 +  {
  451.55 +    m_BitPos += numBits;
  451.56 +    Normalize();
  451.57 +  }
  451.58 +  
  451.59 +  UInt32 ReadBits(UInt32 numBits)
  451.60 +  {
  451.61 +    UInt32 res = GetValue(numBits);
  451.62 +    MovePos(numBits);
  451.63 +    return res;
  451.64 +  }
  451.65 +};
  451.66 +
  451.67 +}
  451.68 +
  451.69 +#endif
   452.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   452.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BranchCoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   452.3 @@ -0,0 +1,19 @@
   452.4 +// BranchCoder.cpp
   452.5 +
   452.6 +#include "StdAfx.h"
   452.7 +
   452.8 +#include "BranchCoder.h"
   452.9 +
  452.10 +STDMETHODIMP CBranchConverter::Init()
  452.11 +{
  452.12 +  _bufferPos = 0;
  452.13 +  SubInit();
  452.14 +  return S_OK;
  452.15 +}
  452.16 +
  452.17 +STDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)
  452.18 +{
  452.19 +  UInt32 processedSize = SubFilter(data, size);
  452.20 +  _bufferPos += processedSize;
  452.21 +  return processedSize;
  452.22 +}
   453.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   453.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BranchCoder.h	Sat Mar 03 10:31:27 2012 -0600
   453.3 @@ -0,0 +1,44 @@
   453.4 +// BranchCoder.h
   453.5 +
   453.6 +#ifndef __COMPRESS_BRANCH_CODER_H
   453.7 +#define __COMPRESS_BRANCH_CODER_H
   453.8 +
   453.9 +#include "../../Common/MyCom.h"
  453.10 +
  453.11 +#include "../ICoder.h"
  453.12 +
  453.13 +class CBranchConverter:
  453.14 +  public ICompressFilter,
  453.15 +  public CMyUnknownImp
  453.16 +{
  453.17 +protected:
  453.18 +  UInt32 _bufferPos;
  453.19 +  virtual void SubInit() {}
  453.20 +  virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;
  453.21 +public:
  453.22 +  MY_UNKNOWN_IMP;
  453.23 +  STDMETHOD(Init)();
  453.24 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
  453.25 +};
  453.26 +
  453.27 +#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \
  453.28 +  { public: UInt32 SubFilter(Byte *data, UInt32 size); };
  453.29 +
  453.30 +#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \
  453.31 +  { public: UInt32 SubFilter(Byte *data, UInt32 size); };
  453.32 +
  453.33 +#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \
  453.34 +  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};
  453.35 +
  453.36 +#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \
  453.37 +  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};
  453.38 +
  453.39 +#define MyClassA(Name, id, subId)  \
  453.40 +MyClassEncoderA(Name ## _Encoder) \
  453.41 +MyClassDecoderA(Name ## _Decoder)
  453.42 +
  453.43 +#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT)  \
  453.44 +MyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \
  453.45 +MyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)
  453.46 +
  453.47 +#endif
   454.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   454.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BranchMisc.cpp	Sat Mar 03 10:31:27 2012 -0600
   454.3 @@ -0,0 +1,40 @@
   454.4 +// BranchMisc.cpp
   454.5 +
   454.6 +#include "StdAfx.h"
   454.7 +
   454.8 +extern "C"
   454.9 +{
  454.10 +#include "../../../C/Bra.h"
  454.11 +}
  454.12 +
  454.13 +#include "BranchMisc.h"
  454.14 +
  454.15 +UInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)
  454.16 +  { return (UInt32)::ARM_Convert(data, size, _bufferPos, 1); }
  454.17 +
  454.18 +UInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)
  454.19 +  { return (UInt32)::ARM_Convert(data, size, _bufferPos, 0); }
  454.20 +
  454.21 +UInt32 CBC_ARMT_Encoder::SubFilter(Byte *data, UInt32 size)
  454.22 +  { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 1); }
  454.23 +
  454.24 +UInt32 CBC_ARMT_Decoder::SubFilter(Byte *data, UInt32 size)
  454.25 +  { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 0); }
  454.26 +
  454.27 +UInt32 CBC_PPC_Encoder::SubFilter(Byte *data, UInt32 size)
  454.28 +  { return (UInt32)::PPC_Convert(data, size, _bufferPos, 1); }
  454.29 +
  454.30 +UInt32 CBC_PPC_Decoder::SubFilter(Byte *data, UInt32 size)
  454.31 +  { return (UInt32)::PPC_Convert(data, size, _bufferPos, 0); }
  454.32 +
  454.33 +UInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)
  454.34 +  { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 1); }
  454.35 +
  454.36 +UInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)
  454.37 +  { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 0); }
  454.38 +
  454.39 +UInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)
  454.40 +  { return (UInt32)::IA64_Convert(data, size, _bufferPos, 1); }
  454.41 +
  454.42 +UInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)
  454.43 +  {  return (UInt32)::IA64_Convert(data, size, _bufferPos, 0); }
   455.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   455.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BranchMisc.h	Sat Mar 03 10:31:27 2012 -0600
   455.3 @@ -0,0 +1,14 @@
   455.4 +// BranchMisc.h
   455.5 +
   455.6 +#ifndef __COMPRESS_BRANCH_MISC_H
   455.7 +#define __COMPRESS_BRANCH_MISC_H
   455.8 +
   455.9 +#include "BranchCoder.h"
  455.10 +
  455.11 +MyClassA(BC_ARM,   0x05, 1)
  455.12 +MyClassA(BC_ARMT,  0x07, 1)
  455.13 +MyClassA(BC_PPC,   0x02, 5)
  455.14 +MyClassA(BC_SPARC, 0x08, 5)
  455.15 +MyClassA(BC_IA64,  0x04, 1)
  455.16 +
  455.17 +#endif
   456.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   456.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BranchRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   456.3 @@ -0,0 +1,30 @@
   456.4 +// BranchRegister.cpp
   456.5 +
   456.6 +#include "StdAfx.h"
   456.7 +
   456.8 +#include "../Common/RegisterCodec.h"
   456.9 +
  456.10 +#include "BranchMisc.h"
  456.11 +
  456.12 +#define CREATE_CODEC(x) \
  456.13 +  static void *CreateCodec ## x() { return (void *)(ICompressFilter *)(new C ## x ## _Decoder); } \
  456.14 +  static void *CreateCodec ## x ## Out() { return (void *)(ICompressFilter *)(new C ## x ## _Encoder); }
  456.15 +
  456.16 +CREATE_CODEC(BC_PPC)
  456.17 +CREATE_CODEC(BC_IA64)
  456.18 +CREATE_CODEC(BC_ARM)
  456.19 +CREATE_CODEC(BC_ARMT)
  456.20 +CREATE_CODEC(BC_SPARC)
  456.21 +
  456.22 +#define METHOD_ITEM(x, id1, id2, name) { CreateCodec ## x, CreateCodec ## x ## Out, 0x03030000 + (id1 * 256) + id2, name, 1, true  }
  456.23 +
  456.24 +static CCodecInfo g_CodecsInfo[] =
  456.25 +{
  456.26 +  METHOD_ITEM(BC_PPC,   0x02, 0x05, L"PPC"),
  456.27 +  METHOD_ITEM(BC_IA64,  0x04, 1, L"IA64"),
  456.28 +  METHOD_ITEM(BC_ARM,   0x05, 1, L"ARM"),
  456.29 +  METHOD_ITEM(BC_ARMT,  0x07, 1, L"ARMT"),
  456.30 +  METHOD_ITEM(BC_SPARC, 0x08, 0x05, L"SPARC")
  456.31 +};
  456.32 +
  456.33 +REGISTER_CODECS(Branch)
   457.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   457.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/ByteSwap.cpp	Sat Mar 03 10:31:27 2012 -0600
   457.3 @@ -0,0 +1,38 @@
   457.4 +// ByteSwap.cpp
   457.5 +
   457.6 +#include "StdAfx.h"
   457.7 +
   457.8 +#include "ByteSwap.h"
   457.9 +
  457.10 +STDMETHODIMP CByteSwap2::Init() { return S_OK; }
  457.11 +
  457.12 +STDMETHODIMP_(UInt32) CByteSwap2::Filter(Byte *data, UInt32 size)
  457.13 +{
  457.14 +  const UInt32 kStep = 2;
  457.15 +  UInt32 i;
  457.16 +  for (i = 0; i + kStep <= size; i += kStep)
  457.17 +  {
  457.18 +    Byte b = data[i];
  457.19 +    data[i] = data[i + 1];
  457.20 +    data[i + 1] = b;
  457.21 +  }
  457.22 +  return i;
  457.23 +}
  457.24 +
  457.25 +STDMETHODIMP CByteSwap4::Init() { return S_OK; }
  457.26 +
  457.27 +STDMETHODIMP_(UInt32) CByteSwap4::Filter(Byte *data, UInt32 size)
  457.28 +{
  457.29 +  const UInt32 kStep = 4;
  457.30 +  UInt32 i;
  457.31 +  for (i = 0; i + kStep <= size; i += kStep)
  457.32 +  {
  457.33 +    Byte b0 = data[i];
  457.34 +    Byte b1 = data[i + 1];
  457.35 +    data[i] = data[i + 3];
  457.36 +    data[i + 1] = data[i + 2];
  457.37 +    data[i + 2] = b1;
  457.38 +    data[i + 3] = b0;
  457.39 +  }
  457.40 +  return i;
  457.41 +}
   458.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   458.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/ByteSwap.h	Sat Mar 03 10:31:27 2012 -0600
   458.3 @@ -0,0 +1,30 @@
   458.4 +// ByteSwap.h
   458.5 +
   458.6 +#ifndef __COMPRESS_BYTE_SWAP_H
   458.7 +#define __COMPRESS_BYTE_SWAP_H
   458.8 +
   458.9 +#include "../../Common/MyCom.h"
  458.10 +
  458.11 +#include "../ICoder.h"
  458.12 +
  458.13 +class CByteSwap2:
  458.14 +  public ICompressFilter,
  458.15 +  public CMyUnknownImp
  458.16 +{
  458.17 +public:
  458.18 +  MY_UNKNOWN_IMP
  458.19 +  STDMETHOD(Init)();
  458.20 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
  458.21 +};
  458.22 +
  458.23 +class CByteSwap4:
  458.24 +  public ICompressFilter,
  458.25 +  public CMyUnknownImp
  458.26 +{
  458.27 +public:
  458.28 +  MY_UNKNOWN_IMP
  458.29 +  STDMETHOD(Init)();
  458.30 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
  458.31 +};
  458.32 +
  458.33 +#endif
   459.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   459.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/ByteSwapRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   459.3 @@ -0,0 +1,18 @@
   459.4 +// ByteSwapRegister.cpp
   459.5 +
   459.6 +#include "StdAfx.h"
   459.7 +
   459.8 +#include "../Common/RegisterCodec.h"
   459.9 +
  459.10 +#include "ByteSwap.h"
  459.11 +
  459.12 +static void *CreateCodec2() { return (void *)(ICompressFilter *)(new CByteSwap2); }
  459.13 +static void *CreateCodec4() { return (void *)(ICompressFilter *)(new CByteSwap4); }
  459.14 +
  459.15 +static CCodecInfo g_CodecsInfo[] =
  459.16 +{
  459.17 +  { CreateCodec2, CreateCodec4, 0x020302, L"Swap2", 1, true },
  459.18 +  { CreateCodec4, CreateCodec4, 0x020304, L"Swap4", 1, true }
  459.19 +};
  459.20 +
  459.21 +REGISTER_CODECS(ByteSwap)
   460.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   460.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/Codec.def	Sat Mar 03 10:31:27 2012 -0600
   460.3 @@ -0,0 +1,4 @@
   460.4 +EXPORTS
   460.5 +  CreateObject PRIVATE
   460.6 +  GetNumberOfMethods PRIVATE
   460.7 +  GetMethodProperty PRIVATE
   461.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   461.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/CodecExports.cpp	Sat Mar 03 10:31:27 2012 -0600
   461.3 @@ -0,0 +1,157 @@
   461.4 +// CodecExports.cpp
   461.5 +
   461.6 +#include "StdAfx.h"
   461.7 +
   461.8 +#include "../../Common/ComTry.h"
   461.9 +#include "../../Windows/PropVariant.h"
  461.10 +#include "../Common/RegisterCodec.h"
  461.11 +#include "../ICoder.h"
  461.12 +
  461.13 +extern unsigned int g_NumCodecs;
  461.14 +extern const CCodecInfo *g_Codecs[];
  461.15 +
  461.16 +static const UInt16 kDecodeId = 0x2790;
  461.17 +
  461.18 +DEFINE_GUID(CLSID_CCodec,
  461.19 +0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
  461.20 +
  461.21 +static inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)
  461.22 +{
  461.23 +  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)
  461.24 +    value->vt = VT_BSTR;
  461.25 +  return S_OK;
  461.26 +}
  461.27 +
  461.28 +static inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)
  461.29 +{
  461.30 +  return SetPropString((const char *)&guid, sizeof(GUID), value);
  461.31 +}
  461.32 +
  461.33 +static HRESULT SetClassID(CMethodId id, bool encode, PROPVARIANT *value)
  461.34 +{
  461.35 +  GUID clsId = CLSID_CCodec;
  461.36 +  for (int i = 0; i < sizeof(id); i++, id >>= 8)
  461.37 +    clsId.Data4[i] = (Byte)(id & 0xFF);
  461.38 +  if (encode)
  461.39 +    clsId.Data3++;
  461.40 +  return SetPropGUID(clsId, value);
  461.41 +}
  461.42 +
  461.43 +static HRESULT FindCodecClassId(const GUID *clsID, UInt32 isCoder2, bool isFilter, bool &encode, int &index)
  461.44 +{
  461.45 +  index = -1;
  461.46 +  if (clsID->Data1 != CLSID_CCodec.Data1 ||
  461.47 +      clsID->Data2 != CLSID_CCodec.Data2 ||
  461.48 +      (clsID->Data3 & ~1) != kDecodeId)
  461.49 +    return S_OK;
  461.50 +  encode = (clsID->Data3 != kDecodeId);
  461.51 +  UInt64 id = 0;
  461.52 +  for (int j = 0; j < 8; j++)
  461.53 +    id |= ((UInt64)clsID->Data4[j]) << (8 * j);
  461.54 +  for (unsigned i = 0; i < g_NumCodecs; i++)
  461.55 +  {
  461.56 +    const CCodecInfo &codec = *g_Codecs[i];
  461.57 +    if (id != codec.Id || encode && !codec.CreateEncoder || !encode && !codec.CreateDecoder)
  461.58 +      continue;
  461.59 +    if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||
  461.60 +        codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)
  461.61 +      return E_NOINTERFACE;
  461.62 +    index = i;
  461.63 +    return S_OK;
  461.64 +  }
  461.65 +  return S_OK;
  461.66 +}
  461.67 +
  461.68 +STDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject)
  461.69 +{
  461.70 +  COM_TRY_BEGIN
  461.71 +  *outObject = 0;
  461.72 +  bool isCoder = (*iid == IID_ICompressCoder) != 0;
  461.73 +  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;
  461.74 +  bool isFilter = (*iid == IID_ICompressFilter) != 0;
  461.75 +  const CCodecInfo &codec = *g_Codecs[index];
  461.76 +  if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||
  461.77 +      codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)
  461.78 +    return E_NOINTERFACE;
  461.79 +  if (encode)
  461.80 +  {
  461.81 +    if (!codec.CreateEncoder)
  461.82 +      return CLASS_E_CLASSNOTAVAILABLE;
  461.83 +    *outObject = codec.CreateEncoder();
  461.84 +  }
  461.85 +  else
  461.86 +  {
  461.87 +    if (!codec.CreateDecoder)
  461.88 +      return CLASS_E_CLASSNOTAVAILABLE;
  461.89 +    *outObject = codec.CreateDecoder();
  461.90 +  }
  461.91 +  if (isCoder)
  461.92 +    ((ICompressCoder *)*outObject)->AddRef();
  461.93 +  else if (isCoder2)
  461.94 +    ((ICompressCoder2 *)*outObject)->AddRef();
  461.95 +  else
  461.96 +    ((ICompressFilter *)*outObject)->AddRef();
  461.97 +  return S_OK;
  461.98 +  COM_TRY_END
  461.99 +}
 461.100 +
 461.101 +STDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject)
 461.102 +{
 461.103 +  *outObject = 0;
 461.104 +  bool isCoder = (*iid == IID_ICompressCoder) != 0;
 461.105 +  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;
 461.106 +  bool isFilter = (*iid == IID_ICompressFilter) != 0;
 461.107 +  if (!isCoder && !isCoder2 && !isFilter)
 461.108 +    return E_NOINTERFACE;
 461.109 +  bool encode;
 461.110 +  int codecIndex;
 461.111 +  HRESULT res = FindCodecClassId(clsid, isCoder2, isFilter, encode, codecIndex);
 461.112 +  if (res != S_OK)
 461.113 +    return res;
 461.114 +  if (codecIndex < 0)
 461.115 +    return CLASS_E_CLASSNOTAVAILABLE;
 461.116 +  return CreateCoder2(encode, codecIndex, iid, outObject);
 461.117 +}
 461.118 +
 461.119 +STDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value)
 461.120 +{
 461.121 +  ::VariantClear((VARIANTARG *)value);
 461.122 +  const CCodecInfo &codec = *g_Codecs[codecIndex];
 461.123 +  switch(propID)
 461.124 +  {
 461.125 +    case NMethodPropID::kID:
 461.126 +    {
 461.127 +      value->uhVal.QuadPart = (UInt64)codec.Id;
 461.128 +      value->vt = VT_UI8;
 461.129 +      break;
 461.130 +    }
 461.131 +    case NMethodPropID::kName:
 461.132 +      if ((value->bstrVal = ::SysAllocString(codec.Name)) != 0)
 461.133 +        value->vt = VT_BSTR;
 461.134 +      break;
 461.135 +    case NMethodPropID::kDecoder:
 461.136 +      if (codec.CreateDecoder)
 461.137 +        return SetClassID(codec.Id, false, value);
 461.138 +      break;
 461.139 +    case NMethodPropID::kEncoder:
 461.140 +      if (codec.CreateEncoder)
 461.141 +        return SetClassID(codec.Id, true, value);
 461.142 +      break;
 461.143 +    case NMethodPropID::kInStreams:
 461.144 +    {
 461.145 +      if (codec.NumInStreams != 1)
 461.146 +      {
 461.147 +        value->vt = VT_UI4;
 461.148 +        value->ulVal = (ULONG)codec.NumInStreams;
 461.149 +      }
 461.150 +      break;
 461.151 +    }
 461.152 +  }
 461.153 +  return S_OK;
 461.154 +}
 461.155 +
 461.156 +STDAPI GetNumberOfMethods(UINT32 *numCodecs)
 461.157 +{
 461.158 +  *numCodecs = g_NumCodecs;
 461.159 +  return S_OK;
 461.160 +}
   462.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   462.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/CopyCoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   462.3 @@ -0,0 +1,62 @@
   462.4 +// Compress/CopyCoder.cpp
   462.5 +
   462.6 +#include "StdAfx.h"
   462.7 +
   462.8 +extern "C"
   462.9 +{
  462.10 +#include "../../../C/Alloc.h"
  462.11 +}
  462.12 +
  462.13 +#include "../Common/StreamUtils.h"
  462.14 +
  462.15 +#include "CopyCoder.h"
  462.16 +
  462.17 +namespace NCompress {
  462.18 +
  462.19 +static const UInt32 kBufferSize = 1 << 17;
  462.20 +
  462.21 +CCopyCoder::~CCopyCoder()
  462.22 +{
  462.23 +  ::MidFree(_buffer);
  462.24 +}
  462.25 +
  462.26 +STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,
  462.27 +    ISequentialOutStream *outStream,
  462.28 +    const UInt64 * /* inSize */, const UInt64 *outSize,
  462.29 +    ICompressProgressInfo *progress)
  462.30 +{
  462.31 +  if (_buffer == 0)
  462.32 +  {
  462.33 +    _buffer = (Byte *)::MidAlloc(kBufferSize);
  462.34 +    if (_buffer == 0)
  462.35 +      return E_OUTOFMEMORY;
  462.36 +  }
  462.37 +
  462.38 +  TotalSize = 0;
  462.39 +  for (;;)
  462.40 +  {
  462.41 +    UInt32 realProcessedSize;
  462.42 +    UInt32 size = kBufferSize;
  462.43 +    if (outSize != 0)
  462.44 +      if (size > *outSize - TotalSize)
  462.45 +        size = (UInt32)(*outSize - TotalSize);
  462.46 +    RINOK(inStream->Read(_buffer, size, &realProcessedSize));
  462.47 +    if (realProcessedSize == 0)
  462.48 +      break;
  462.49 +    RINOK(WriteStream(outStream, _buffer, realProcessedSize));
  462.50 +    TotalSize += realProcessedSize;
  462.51 +    if (progress != NULL)
  462.52 +    {
  462.53 +      RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));
  462.54 +    }
  462.55 +  }
  462.56 +  return S_OK;
  462.57 +}
  462.58 +
  462.59 +STDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value)
  462.60 +{
  462.61 +  *value = TotalSize;
  462.62 +  return S_OK;
  462.63 +}
  462.64 +
  462.65 +}
   463.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   463.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/CopyCoder.h	Sat Mar 03 10:31:27 2012 -0600
   463.3 @@ -0,0 +1,32 @@
   463.4 +// Compress/CopyCoder.h
   463.5 +
   463.6 +#ifndef __COMPRESS_COPY_CODER_H
   463.7 +#define __COMPRESS_COPY_CODER_H
   463.8 +
   463.9 +#include "../../Common/MyCom.h"
  463.10 +
  463.11 +#include "../ICoder.h"
  463.12 +
  463.13 +namespace NCompress {
  463.14 +
  463.15 +class CCopyCoder:
  463.16 +  public ICompressCoder,
  463.17 +  public ICompressGetInStreamProcessedSize,
  463.18 +  public CMyUnknownImp
  463.19 +{
  463.20 +  Byte *_buffer;
  463.21 +public:
  463.22 +  UInt64 TotalSize;
  463.23 +  CCopyCoder(): TotalSize(0) , _buffer(0) {};
  463.24 +  ~CCopyCoder();
  463.25 +
  463.26 +  MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)
  463.27 +
  463.28 +  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  463.29 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
  463.30 +  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
  463.31 +};
  463.32 +
  463.33 +}
  463.34 +
  463.35 +#endif
   464.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   464.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/CopyRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   464.3 @@ -0,0 +1,14 @@
   464.4 +// CopyRegister.cpp
   464.5 +
   464.6 +#include "StdAfx.h"
   464.7 +
   464.8 +#include "../Common/RegisterCodec.h"
   464.9 +
  464.10 +#include "CopyCoder.h"
  464.11 +
  464.12 +static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::CCopyCoder); }
  464.13 +
  464.14 +static CCodecInfo g_CodecInfo =
  464.15 +{ CreateCodec, CreateCodec, 0x00, L"Copy", 1, false };
  464.16 +
  464.17 +REGISTER_CODEC(Copy)
   465.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   465.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/Deflate64Register.cpp	Sat Mar 03 10:31:27 2012 -0600
   465.3 @@ -0,0 +1,20 @@
   465.4 +// Deflate64Register.cpp
   465.5 +
   465.6 +#include "StdAfx.h"
   465.7 +
   465.8 +#include "../Common/RegisterCodec.h"
   465.9 +
  465.10 +#include "DeflateDecoder.h"
  465.11 +
  465.12 +static void *CreateCodecDeflate64() { return (void *)(ICompressCoder *)(new NCompress::NDeflate::NDecoder::CCOMCoder64); }
  465.13 +#if !defined(EXTRACT_ONLY) && !defined(DEFLATE_EXTRACT_ONLY)
  465.14 +#include "DeflateEncoder.h"
  465.15 +static void *CreateCodecOutDeflate64() { return (void *)(ICompressCoder *)(new NCompress::NDeflate::NEncoder::CCOMCoder64);  }
  465.16 +#else
  465.17 +#define CreateCodecOutDeflate64 0
  465.18 +#endif
  465.19 +
  465.20 +static CCodecInfo g_CodecInfo =
  465.21 +  { CreateCodecDeflate64, CreateCodecOutDeflate64, 0x040109, L"Deflate64", 1, false };
  465.22 +
  465.23 +REGISTER_CODEC(Deflate64)
   466.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   466.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/DeflateConst.h	Sat Mar 03 10:31:27 2012 -0600
   466.3 @@ -0,0 +1,134 @@
   466.4 +// DeflateConst.h
   466.5 +
   466.6 +#ifndef __DEFLATE_CONST_H
   466.7 +#define __DEFLATE_CONST_H
   466.8 +
   466.9 +namespace NCompress {
  466.10 +namespace NDeflate {
  466.11 +
  466.12 +const int kNumHuffmanBits = 15;
  466.13 +
  466.14 +const UInt32 kHistorySize32 = (1 << 15);
  466.15 +const UInt32 kHistorySize64 = (1 << 16);
  466.16 +
  466.17 +const UInt32 kDistTableSize32 = 30;
  466.18 +const UInt32 kDistTableSize64 = 32;
  466.19 +  
  466.20 +const UInt32 kNumLenSymbols32 = 256;
  466.21 +const UInt32 kNumLenSymbols64 = 255; // don't change it. It must be <= 255.
  466.22 +const UInt32 kNumLenSymbolsMax = kNumLenSymbols32;
  466.23 +  
  466.24 +const UInt32 kNumLenSlots = 29;
  466.25 +
  466.26 +const UInt32 kFixedDistTableSize = 32;
  466.27 +const UInt32 kFixedLenTableSize = 31;
  466.28 +
  466.29 +const UInt32 kSymbolEndOfBlock = 0x100;
  466.30 +const UInt32 kSymbolMatch = kSymbolEndOfBlock + 1;
  466.31 +
  466.32 +const UInt32 kMainTableSize = kSymbolMatch + kNumLenSlots;
  466.33 +const UInt32 kFixedMainTableSize = kSymbolMatch + kFixedLenTableSize;
  466.34 +
  466.35 +const UInt32 kLevelTableSize = 19;
  466.36 +
  466.37 +const UInt32 kTableDirectLevels = 16;
  466.38 +const UInt32 kTableLevelRepNumber = kTableDirectLevels;
  466.39 +const UInt32 kTableLevel0Number = kTableLevelRepNumber + 1;
  466.40 +const UInt32 kTableLevel0Number2 = kTableLevel0Number + 1;
  466.41 +
  466.42 +const UInt32 kLevelMask = 0xF;
  466.43 +
  466.44 +const Byte kLenStart32[kFixedLenTableSize] =
  466.45 +  {0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224, 255, 0, 0};
  466.46 +const Byte kLenStart64[kFixedLenTableSize] =
  466.47 +  {0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224, 0, 0, 0};
  466.48 +
  466.49 +const Byte kLenDirectBits32[kFixedLenTableSize] =
  466.50 +  {0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,  4,  5,  5,  5,  5, 0, 0, 0};
  466.51 +const Byte kLenDirectBits64[kFixedLenTableSize] =
  466.52 +  {0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,  4,  5,  5,  5,  5, 16, 0, 0};
  466.53 +
  466.54 +const UInt32 kDistStart[kDistTableSize64]  =
  466.55 +  {0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,
  466.56 +  1024,1536,2048,3072,4096,6144,8192,12288,16384,24576,32768,49152};
  466.57 +const Byte kDistDirectBits[kDistTableSize64] =
  466.58 +  {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14};
  466.59 +
  466.60 +const Byte kLevelDirectBits[3] = {2, 3, 7};
  466.61 +
  466.62 +const Byte kCodeLengthAlphabetOrder[kLevelTableSize] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  466.63 +
  466.64 +const UInt32 kMatchMinLen = 3;
  466.65 +const UInt32 kMatchMaxLen32 = kNumLenSymbols32 + kMatchMinLen - 1; //256 + 2
  466.66 +const UInt32 kMatchMaxLen64 = kNumLenSymbols64 + kMatchMinLen - 1; //255 + 2
  466.67 +const UInt32 kMatchMaxLen = kMatchMaxLen32;
  466.68 +
  466.69 +const int kFinalBlockFieldSize = 1;
  466.70 +
  466.71 +namespace NFinalBlockField
  466.72 +{
  466.73 +  enum
  466.74 +  {
  466.75 +    kNotFinalBlock = 0,
  466.76 +    kFinalBlock = 1
  466.77 +  };
  466.78 +}
  466.79 +
  466.80 +const int kBlockTypeFieldSize = 2;
  466.81 +
  466.82 +namespace NBlockType
  466.83 +{
  466.84 +  enum
  466.85 +  {
  466.86 +    kStored = 0,
  466.87 +    kFixedHuffman = 1,
  466.88 +    kDynamicHuffman = 2
  466.89 +  };
  466.90 +}
  466.91 +
  466.92 +const int kNumLenCodesFieldSize = 5;
  466.93 +const int kNumDistCodesFieldSize = 5;
  466.94 +const int kNumLevelCodesFieldSize = 4;
  466.95 +
  466.96 +const UInt32 kNumLitLenCodesMin = 257;
  466.97 +const UInt32 kNumDistCodesMin = 1;
  466.98 +const UInt32 kNumLevelCodesMin = 4;
  466.99 +
 466.100 +const int kLevelFieldSize = 3;
 466.101 +
 466.102 +const int kStoredBlockLengthFieldSize = 16;
 466.103 +
 466.104 +struct CLevels
 466.105 +{
 466.106 +  Byte litLenLevels[kFixedMainTableSize];
 466.107 +  Byte distLevels[kFixedDistTableSize];
 466.108 +
 466.109 +  void SubClear()
 466.110 +  {
 466.111 +    UInt32 i;
 466.112 +    for(i = kNumLitLenCodesMin; i < kFixedMainTableSize; i++)
 466.113 +      litLenLevels[i] = 0;
 466.114 +    for(i = 0; i < kFixedDistTableSize; i++)
 466.115 +      distLevels[i] = 0;
 466.116 +  }
 466.117 +
 466.118 +  void SetFixedLevels()
 466.119 +  {
 466.120 +    int i;
 466.121 +    
 466.122 +    for (i = 0; i < 144; i++)
 466.123 +      litLenLevels[i] = 8;
 466.124 +    for (; i < 256; i++)
 466.125 +      litLenLevels[i] = 9;
 466.126 +    for (; i < 280; i++)
 466.127 +      litLenLevels[i] = 7;
 466.128 +    for (; i < 288; i++)
 466.129 +      litLenLevels[i] = 8;
 466.130 +    for (i = 0; i < kFixedDistTableSize; i++)  // test it: InfoZip only uses kDistTableSize
 466.131 +      distLevels[i] = 5;
 466.132 +  }
 466.133 +};
 466.134 +
 466.135 +}}
 466.136 +
 466.137 +#endif
   467.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   467.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/DeflateDecoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   467.3 @@ -0,0 +1,345 @@
   467.4 +// DeflateDecoder.cpp
   467.5 +
   467.6 +#include "StdAfx.h"
   467.7 +
   467.8 +#include "DeflateDecoder.h"
   467.9 +
  467.10 +namespace NCompress {
  467.11 +namespace NDeflate {
  467.12 +namespace NDecoder {
  467.13 +
  467.14 +static const int kLenIdFinished = -1;
  467.15 +static const int kLenIdNeedInit = -2;
  467.16 +
  467.17 +CCoder::CCoder(bool deflate64Mode, bool deflateNSIS):
  467.18 +    _deflate64Mode(deflate64Mode),
  467.19 +    _deflateNSIS(deflateNSIS),
  467.20 +    _keepHistory(false),
  467.21 +    ZlibMode(false) {}
  467.22 +
  467.23 +UInt32 CCoder::ReadBits(int numBits)
  467.24 +{
  467.25 +  return m_InBitStream.ReadBits(numBits);
  467.26 +}
  467.27 +
  467.28 +bool CCoder::DeCodeLevelTable(Byte *values, int numSymbols)
  467.29 +{
  467.30 +  int i = 0;
  467.31 +  do
  467.32 +  {
  467.33 +    UInt32 number = m_LevelDecoder.DecodeSymbol(&m_InBitStream);
  467.34 +    if (number < kTableDirectLevels)
  467.35 +      values[i++] = (Byte)number;
  467.36 +    else if (number < kLevelTableSize)
  467.37 +    {
  467.38 +      if (number == kTableLevelRepNumber)
  467.39 +      {
  467.40 +        if (i == 0)
  467.41 +          return false;
  467.42 +        int num = ReadBits(2) + 3;
  467.43 +        for (; num > 0 && i < numSymbols; num--, i++)
  467.44 +          values[i] = values[i - 1];
  467.45 +      }
  467.46 +      else
  467.47 +      {
  467.48 +        int num;
  467.49 +        if (number == kTableLevel0Number)
  467.50 +          num = ReadBits(3) + 3;
  467.51 +        else
  467.52 +          num = ReadBits(7) + 11;
  467.53 +        for (;num > 0 && i < numSymbols; num--)
  467.54 +          values[i++] = 0;
  467.55 +      }
  467.56 +    }
  467.57 +    else
  467.58 +      return false;
  467.59 +  }
  467.60 +  while(i < numSymbols);
  467.61 +  return true;
  467.62 +}
  467.63 +
  467.64 +#define RIF(x) { if (!(x)) return false; }
  467.65 +
  467.66 +bool CCoder::ReadTables(void)
  467.67 +{
  467.68 +  m_FinalBlock = (ReadBits(kFinalBlockFieldSize) == NFinalBlockField::kFinalBlock);
  467.69 +  UInt32 blockType = ReadBits(kBlockTypeFieldSize);
  467.70 +  if (blockType > NBlockType::kDynamicHuffman)
  467.71 +    return false;
  467.72 +
  467.73 +  if (blockType == NBlockType::kStored)
  467.74 +  {
  467.75 +    m_StoredMode = true;
  467.76 +    UInt32 currentBitPosition = m_InBitStream.GetBitPosition();
  467.77 +    int numBitsForAlign = (int)(currentBitPosition > 0 ? (8 - currentBitPosition): 0);
  467.78 +    ReadBits(numBitsForAlign);
  467.79 +    m_StoredBlockSize = ReadBits(kStoredBlockLengthFieldSize);
  467.80 +    if (_deflateNSIS)
  467.81 +      return true;
  467.82 +    return (m_StoredBlockSize == (UInt16)~ReadBits(kStoredBlockLengthFieldSize));
  467.83 +  }
  467.84 +
  467.85 +  m_StoredMode = false;
  467.86 +
  467.87 +  CLevels levels;
  467.88 +  if (blockType == NBlockType::kFixedHuffman)
  467.89 +  {
  467.90 +    levels.SetFixedLevels();
  467.91 +    _numDistLevels = _deflate64Mode ? kDistTableSize64 : kDistTableSize32;
  467.92 +  }
  467.93 +  else
  467.94 +  {
  467.95 +    int numLitLenLevels = ReadBits(kNumLenCodesFieldSize) + kNumLitLenCodesMin;
  467.96 +    _numDistLevels = ReadBits(kNumDistCodesFieldSize) + kNumDistCodesMin;
  467.97 +    int numLevelCodes = ReadBits(kNumLevelCodesFieldSize) + kNumLevelCodesMin;
  467.98 +
  467.99 +    if (!_deflate64Mode)
 467.100 +      if (_numDistLevels > kDistTableSize32)
 467.101 +        return false;
 467.102 +    
 467.103 +    Byte levelLevels[kLevelTableSize];
 467.104 +    for (int i = 0; i < kLevelTableSize; i++)
 467.105 +    {
 467.106 +      int position = kCodeLengthAlphabetOrder[i];
 467.107 +      if(i < numLevelCodes)
 467.108 +        levelLevels[position] = (Byte)ReadBits(kLevelFieldSize);
 467.109 +      else
 467.110 +        levelLevels[position] = 0;
 467.111 +    }
 467.112 +    
 467.113 +    RIF(m_LevelDecoder.SetCodeLengths(levelLevels));
 467.114 +    
 467.115 +    Byte tmpLevels[kFixedMainTableSize + kFixedDistTableSize];
 467.116 +    if (!DeCodeLevelTable(tmpLevels, numLitLenLevels + _numDistLevels))
 467.117 +      return false;
 467.118 +
 467.119 +    levels.SubClear();
 467.120 +    memcpy(levels.litLenLevels, tmpLevels, numLitLenLevels);
 467.121 +    memcpy(levels.distLevels, tmpLevels + numLitLenLevels, _numDistLevels);
 467.122 +  }
 467.123 +  RIF(m_MainDecoder.SetCodeLengths(levels.litLenLevels));
 467.124 +  return m_DistDecoder.SetCodeLengths(levels.distLevels);
 467.125 +}
 467.126 +
 467.127 +HRESULT CCoder::CodeSpec(UInt32 curSize)
 467.128 +{
 467.129 +  if (_remainLen == kLenIdFinished)
 467.130 +    return S_OK;
 467.131 +  if (_remainLen == kLenIdNeedInit)
 467.132 +  {
 467.133 +    if (!_keepHistory)
 467.134 +      if (!m_OutWindowStream.Create(_deflate64Mode ? kHistorySize64: kHistorySize32))
 467.135 +        return E_OUTOFMEMORY;
 467.136 +    if (!m_InBitStream.Create(1 << 17))
 467.137 +      return E_OUTOFMEMORY;
 467.138 +    m_OutWindowStream.Init(_keepHistory);
 467.139 +    m_InBitStream.Init();
 467.140 +    m_FinalBlock = false;
 467.141 +    _remainLen = 0;
 467.142 +    _needReadTable = true;
 467.143 +  }
 467.144 +
 467.145 +  if (curSize == 0)
 467.146 +    return S_OK;
 467.147 +
 467.148 +  while(_remainLen > 0 && curSize > 0)
 467.149 +  {
 467.150 +    _remainLen--;
 467.151 +    Byte b = m_OutWindowStream.GetByte(_rep0);
 467.152 +    m_OutWindowStream.PutByte(b);
 467.153 +    curSize--;
 467.154 +  }
 467.155 +
 467.156 +  while(curSize > 0)
 467.157 +  {
 467.158 +    if (_needReadTable)
 467.159 +    {
 467.160 +      if (m_FinalBlock)
 467.161 +      {
 467.162 +        _remainLen = kLenIdFinished;
 467.163 +        break;
 467.164 +      }
 467.165 +      if (!ReadTables())
 467.166 +        return S_FALSE;
 467.167 +      _needReadTable = false;
 467.168 +    }
 467.169 +
 467.170 +    if(m_StoredMode)
 467.171 +    {
 467.172 +      for (; m_StoredBlockSize > 0 && curSize > 0; m_StoredBlockSize--, curSize--)
 467.173 +        m_OutWindowStream.PutByte((Byte)m_InBitStream.ReadBits(8));
 467.174 +      _needReadTable = (m_StoredBlockSize == 0);
 467.175 +      continue;
 467.176 +    }
 467.177 +    while(curSize > 0)
 467.178 +    {
 467.179 +      if (m_InBitStream.NumExtraBytes > 4)
 467.180 +        return S_FALSE;
 467.181 +
 467.182 +      UInt32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream);
 467.183 +      if (number < 0x100)
 467.184 +      {
 467.185 +        m_OutWindowStream.PutByte((Byte)number);
 467.186 +        curSize--;
 467.187 +        continue;
 467.188 +      }
 467.189 +      else if (number == kSymbolEndOfBlock)
 467.190 +      {
 467.191 +        _needReadTable = true;
 467.192 +        break;
 467.193 +      }
 467.194 +      else if (number < kMainTableSize)
 467.195 +      {
 467.196 +        number -= kSymbolMatch;
 467.197 +        UInt32 len;
 467.198 +        {
 467.199 +          int numBits;
 467.200 +          if (_deflate64Mode)
 467.201 +          {
 467.202 +            len = kLenStart64[number];
 467.203 +            numBits = kLenDirectBits64[number];
 467.204 +          }
 467.205 +          else
 467.206 +          {
 467.207 +            len = kLenStart32[number];
 467.208 +            numBits = kLenDirectBits32[number];
 467.209 +          }
 467.210 +          len += kMatchMinLen + m_InBitStream.ReadBits(numBits);
 467.211 +        }
 467.212 +        UInt32 locLen = len;
 467.213 +        if (locLen > curSize)
 467.214 +          locLen = (UInt32)curSize;
 467.215 +        number = m_DistDecoder.DecodeSymbol(&m_InBitStream);
 467.216 +        if (number >= _numDistLevels)
 467.217 +          return S_FALSE;
 467.218 +        UInt32 distance = kDistStart[number] + m_InBitStream.ReadBits(kDistDirectBits[number]);
 467.219 +        if (!m_OutWindowStream.CopyBlock(distance, locLen))
 467.220 +          return S_FALSE;
 467.221 +        curSize -= locLen;
 467.222 +        len -= locLen;
 467.223 +        if (len != 0)
 467.224 +        {
 467.225 +          _remainLen = (Int32)len;
 467.226 +          _rep0 = distance;
 467.227 +          break;
 467.228 +        }
 467.229 +      }
 467.230 +      else
 467.231 +        return S_FALSE;
 467.232 +    }
 467.233 +  }
 467.234 +  return S_OK;
 467.235 +}
 467.236 +
 467.237 +HRESULT CCoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 467.238 +    const UInt64 *, const UInt64 *outSize, ICompressProgressInfo *progress)
 467.239 +{
 467.240 +  SetInStream(inStream);
 467.241 +  m_OutWindowStream.SetStream(outStream);
 467.242 +  SetOutStreamSize(outSize);
 467.243 +  CCoderReleaser flusher(this);
 467.244 +
 467.245 +  const UInt64 start = m_OutWindowStream.GetProcessedSize();
 467.246 +  for (;;)
 467.247 +  {
 467.248 +    UInt32 curSize = 1 << 18;
 467.249 +    if (outSize != 0)
 467.250 +    {
 467.251 +      const UInt64 rem = *outSize - (m_OutWindowStream.GetProcessedSize() - start);
 467.252 +      if (curSize > rem)
 467.253 +        curSize = (UInt32)rem;
 467.254 +    }
 467.255 +    if (curSize == 0)
 467.256 +      break;
 467.257 +    RINOK(CodeSpec(curSize));
 467.258 +    if (_remainLen == kLenIdFinished)
 467.259 +      break;
 467.260 +    if (progress != NULL)
 467.261 +    {
 467.262 +      const UInt64 inSize = m_InBitStream.GetProcessedSize();
 467.263 +      const UInt64 nowPos64 = m_OutWindowStream.GetProcessedSize() - start;
 467.264 +      RINOK(progress->SetRatioInfo(&inSize, &nowPos64));
 467.265 +    }
 467.266 +  }
 467.267 +  if (_remainLen == kLenIdFinished && ZlibMode)
 467.268 +  {
 467.269 +    UInt32 currentBitPosition = m_InBitStream.GetBitPosition();
 467.270 +    int numBitsForAlign = (int)(currentBitPosition > 0 ? (8 - currentBitPosition): 0);
 467.271 +    ReadBits(numBitsForAlign);
 467.272 +    for (int i = 0; i < 4; i++)
 467.273 +      ZlibFooter[i] = (Byte)m_InBitStream.ReadBits(8);
 467.274 +  }
 467.275 +  flusher.NeedFlush = false;
 467.276 +  return Flush();
 467.277 +}
 467.278 +
 467.279 +
 467.280 +#ifdef _NO_EXCEPTIONS
 467.281 +
 467.282 +#define DEFLATE_TRY_BEGIN
 467.283 +#define DEFLATE_TRY_END
 467.284 +
 467.285 +#else
 467.286 +
 467.287 +#define DEFLATE_TRY_BEGIN try {
 467.288 +#define DEFLATE_TRY_END } \
 467.289 +  catch(const CInBufferException &e)  { return e.ErrorCode; } \
 467.290 +  catch(const CLzOutWindowException &e)  { return e.ErrorCode; } \
 467.291 +  catch(...) { return S_FALSE; }
 467.292 +
 467.293 +#endif
 467.294 +
 467.295 +HRESULT CCoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 467.296 +    const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
 467.297 +{
 467.298 +  DEFLATE_TRY_BEGIN
 467.299 +  return CodeReal(inStream, outStream, inSize, outSize, progress);
 467.300 +  DEFLATE_TRY_END
 467.301 +}
 467.302 +
 467.303 +STDMETHODIMP CCoder::GetInStreamProcessedSize(UInt64 *value)
 467.304 +{
 467.305 +  if (value == NULL)
 467.306 +    return E_INVALIDARG;
 467.307 +  *value = m_InBitStream.GetProcessedSize();
 467.308 +  return S_OK;
 467.309 +}
 467.310 +
 467.311 +STDMETHODIMP CCoder::SetInStream(ISequentialInStream *inStream)
 467.312 +{
 467.313 +  m_InBitStream.SetStream(inStream);
 467.314 +  return S_OK;
 467.315 +}
 467.316 +
 467.317 +STDMETHODIMP CCoder::ReleaseInStream()
 467.318 +{
 467.319 +  m_InBitStream.ReleaseStream();
 467.320 +  return S_OK;
 467.321 +}
 467.322 +
 467.323 +STDMETHODIMP CCoder::SetOutStreamSize(const UInt64 * /* outSize */)
 467.324 +{
 467.325 +  _remainLen = kLenIdNeedInit;
 467.326 +  m_OutWindowStream.Init(_keepHistory);
 467.327 +  return S_OK;
 467.328 +}
 467.329 +
 467.330 +#ifndef NO_READ_FROM_CODER
 467.331 +
 467.332 +STDMETHODIMP CCoder::Read(void *data, UInt32 size, UInt32 *processedSize)
 467.333 +{
 467.334 +  DEFLATE_TRY_BEGIN
 467.335 +  if (processedSize)
 467.336 +    *processedSize = 0;
 467.337 +  const UInt64 startPos = m_OutWindowStream.GetProcessedSize();
 467.338 +  m_OutWindowStream.SetMemStream((Byte *)data);
 467.339 +  RINOK(CodeSpec(size));
 467.340 +  if (processedSize)
 467.341 +    *processedSize = (UInt32)(m_OutWindowStream.GetProcessedSize() - startPos);
 467.342 +  return Flush();
 467.343 +  DEFLATE_TRY_END
 467.344 +}
 467.345 +
 467.346 +#endif
 467.347 +
 467.348 +}}}
   468.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   468.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/DeflateDecoder.h	Sat Mar 03 10:31:27 2012 -0600
   468.3 @@ -0,0 +1,136 @@
   468.4 +// DeflateDecoder.h
   468.5 +
   468.6 +#ifndef __DEFLATE_DECODER_H
   468.7 +#define __DEFLATE_DECODER_H
   468.8 +
   468.9 +#include "../../Common/MyCom.h"
  468.10 +
  468.11 +#include "../ICoder.h"
  468.12 +
  468.13 +#include "../Common/InBuffer.h"
  468.14 +
  468.15 +#include "BitlDecoder.h"
  468.16 +#include "DeflateConst.h"
  468.17 +#include "HuffmanDecoder.h"
  468.18 +#include "LzOutWindow.h"
  468.19 +
  468.20 +namespace NCompress {
  468.21 +namespace NDeflate {
  468.22 +namespace NDecoder {
  468.23 +
  468.24 +class CCoder:
  468.25 +  public ICompressCoder,
  468.26 +  public ICompressGetInStreamProcessedSize,
  468.27 +  #ifndef NO_READ_FROM_CODER
  468.28 +  public ICompressSetInStream,
  468.29 +  public ICompressSetOutStreamSize,
  468.30 +  public ISequentialInStream,
  468.31 +  #endif
  468.32 +  public CMyUnknownImp
  468.33 +{
  468.34 +  CLzOutWindow m_OutWindowStream;
  468.35 +  NBitl::CDecoder<CInBuffer> m_InBitStream;
  468.36 +  NCompress::NHuffman::CDecoder<kNumHuffmanBits, kFixedMainTableSize> m_MainDecoder;
  468.37 +  NCompress::NHuffman::CDecoder<kNumHuffmanBits, kFixedDistTableSize> m_DistDecoder;
  468.38 +  NCompress::NHuffman::CDecoder<kNumHuffmanBits, kLevelTableSize> m_LevelDecoder;
  468.39 +
  468.40 +  UInt32 m_StoredBlockSize;
  468.41 +
  468.42 +  bool m_FinalBlock;
  468.43 +  bool m_StoredMode;
  468.44 +  UInt32 _numDistLevels;
  468.45 +
  468.46 +
  468.47 +  bool _deflateNSIS;
  468.48 +  bool _deflate64Mode;
  468.49 +  bool _keepHistory;
  468.50 +  Int32 _remainLen;
  468.51 +  UInt32 _rep0;
  468.52 +  bool _needReadTable;
  468.53 +
  468.54 +  UInt32 ReadBits(int numBits);
  468.55 +
  468.56 +  bool DeCodeLevelTable(Byte *values, int numSymbols);
  468.57 +  bool ReadTables();
  468.58 +  
  468.59 +  void ReleaseStreams()
  468.60 +  {
  468.61 +    m_OutWindowStream.ReleaseStream();
  468.62 +    ReleaseInStream();
  468.63 +  }
  468.64 +
  468.65 +  HRESULT Flush() { return m_OutWindowStream.Flush(); }
  468.66 +  class CCoderReleaser
  468.67 +  {
  468.68 +    CCoder *m_Coder;
  468.69 +  public:
  468.70 +    bool NeedFlush;
  468.71 +    CCoderReleaser(CCoder *coder): m_Coder(coder), NeedFlush(true) {}
  468.72 +    ~CCoderReleaser()
  468.73 +    {
  468.74 +      if (NeedFlush)
  468.75 +        m_Coder->Flush();
  468.76 +      m_Coder->ReleaseStreams();
  468.77 +    }
  468.78 +  };
  468.79 +  friend class CCoderReleaser;
  468.80 +
  468.81 +  HRESULT CodeSpec(UInt32 curSize);
  468.82 +public:
  468.83 +  bool ZlibMode;
  468.84 +  Byte ZlibFooter[4];
  468.85 +
  468.86 +  CCoder(bool deflate64Mode, bool deflateNSIS = false);
  468.87 +  void SetKeepHistory(bool keepHistory) { _keepHistory = keepHistory; }
  468.88 +
  468.89 +  HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  468.90 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
  468.91 +
  468.92 +  #ifndef NO_READ_FROM_CODER
  468.93 +  MY_UNKNOWN_IMP4(
  468.94 +      ICompressGetInStreamProcessedSize,
  468.95 +      ICompressSetInStream,
  468.96 +      ICompressSetOutStreamSize,
  468.97 +      ISequentialInStream
  468.98 +      )
  468.99 +  #else
 468.100 +  MY_UNKNOWN_IMP1(
 468.101 +      ICompressGetInStreamProcessedSize)
 468.102 +  #endif
 468.103 +
 468.104 +  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 468.105 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
 468.106 +
 468.107 +  STDMETHOD(SetInStream)(ISequentialInStream *inStream);
 468.108 +  STDMETHOD(ReleaseInStream)();
 468.109 +  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);
 468.110 +  
 468.111 +  #ifndef NO_READ_FROM_CODER
 468.112 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
 468.113 +  #endif
 468.114 +
 468.115 +  // IGetInStreamProcessedSize
 468.116 +  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
 468.117 +};
 468.118 +
 468.119 +class CCOMCoder : public CCoder
 468.120 +{
 468.121 +public:
 468.122 +  CCOMCoder(): CCoder(false) {}
 468.123 +};
 468.124 +
 468.125 +class CNsisCOMCoder : public CCoder
 468.126 +{
 468.127 +public:
 468.128 +  CNsisCOMCoder(): CCoder(false, true) {}
 468.129 +};
 468.130 +
 468.131 +class CCOMCoder64 : public CCoder
 468.132 +{
 468.133 +public:
 468.134 +  CCOMCoder64(): CCoder(true) {}
 468.135 +};
 468.136 +
 468.137 +}}}
 468.138 +
 468.139 +#endif
   469.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   469.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/DeflateNsisRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   469.3 @@ -0,0 +1,14 @@
   469.4 +// DeflateNsisRegister.cpp
   469.5 +
   469.6 +#include "StdAfx.h"
   469.7 +
   469.8 +#include "../Common/RegisterCodec.h"
   469.9 +
  469.10 +#include "DeflateDecoder.h"
  469.11 +
  469.12 +static void *CreateCodecDeflateNsis() { return (void *)(ICompressCoder *)(new NCompress::NDeflate::NDecoder::CNsisCOMCoder); }
  469.13 +
  469.14 +static CCodecInfo g_CodecInfo =
  469.15 +  { CreateCodecDeflateNsis, 0,   0x040901, L"DeflateNSIS", 1, false };
  469.16 +
  469.17 +REGISTER_CODEC(DeflateNsis)
   470.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   470.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/DeflateRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   470.3 @@ -0,0 +1,21 @@
   470.4 +// DeflateRegister.cpp
   470.5 +
   470.6 +#include "StdAfx.h"
   470.7 +
   470.8 +#include "../Common/RegisterCodec.h"
   470.9 +
  470.10 +#include "DeflateDecoder.h"
  470.11 +
  470.12 +static void *CreateCodecDeflate() { return (void *)(ICompressCoder *)(new NCompress::NDeflate::NDecoder::CCOMCoder); }
  470.13 +
  470.14 +#if !defined(EXTRACT_ONLY) && !defined(DEFLATE_EXTRACT_ONLY)
  470.15 +#include "DeflateEncoder.h"
  470.16 +static void *CreateCodecOutDeflate() { return (void *)(ICompressCoder *)(new NCompress::NDeflate::NEncoder::CCOMCoder);  }
  470.17 +#else
  470.18 +#define CreateCodecOutDeflate 0
  470.19 +#endif
  470.20 +
  470.21 +static CCodecInfo g_CodecInfo =
  470.22 +  { CreateCodecDeflate,   CreateCodecOutDeflate,   0x040108, L"Deflate", 1, false };
  470.23 +
  470.24 +REGISTER_CODEC(Deflate)
   471.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   471.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/HuffmanDecoder.h	Sat Mar 03 10:31:27 2012 -0600
   471.3 @@ -0,0 +1,89 @@
   471.4 +// Compress/HuffmanDecoder.h
   471.5 +
   471.6 +#ifndef __COMPRESS_HUFFMAN_DECODER_H
   471.7 +#define __COMPRESS_HUFFMAN_DECODER_H
   471.8 +
   471.9 +#include "../../Common/Types.h"
  471.10 +
  471.11 +namespace NCompress {
  471.12 +namespace NHuffman {
  471.13 +
  471.14 +const int kNumTableBits = 9;
  471.15 +
  471.16 +template <int kNumBitsMax, UInt32 m_NumSymbols>
  471.17 +class CDecoder
  471.18 +{
  471.19 +  UInt32 m_Limits[kNumBitsMax + 1];     // m_Limits[i] = value limit for symbols with length = i
  471.20 +  UInt32 m_Positions[kNumBitsMax + 1];  // m_Positions[i] = index in m_Symbols[] of first symbol with length = i
  471.21 +  UInt32 m_Symbols[m_NumSymbols];
  471.22 +  Byte m_Lengths[1 << kNumTableBits];   // Table oh length for short codes.
  471.23 +
  471.24 +public:
  471.25 +  
  471.26 +  bool SetCodeLengths(const Byte *codeLengths)
  471.27 +  {
  471.28 +    int lenCounts[kNumBitsMax + 1];
  471.29 +    UInt32 tmpPositions[kNumBitsMax + 1];
  471.30 +    int i;
  471.31 +    for(i = 1; i <= kNumBitsMax; i++)
  471.32 +      lenCounts[i] = 0;
  471.33 +    UInt32 symbol;
  471.34 +    for (symbol = 0; symbol < m_NumSymbols; symbol++)
  471.35 +    {
  471.36 +      int len = codeLengths[symbol];
  471.37 +      if (len > kNumBitsMax)
  471.38 +        return false;
  471.39 +      lenCounts[len]++;
  471.40 +      m_Symbols[symbol] = 0xFFFFFFFF;
  471.41 +    }
  471.42 +    lenCounts[0] = 0;
  471.43 +    m_Positions[0] = m_Limits[0] = 0;
  471.44 +    UInt32 startPos = 0;
  471.45 +    UInt32 index = 0;
  471.46 +    const UInt32 kMaxValue = (1 << kNumBitsMax);
  471.47 +    for (i = 1; i <= kNumBitsMax; i++)
  471.48 +    {
  471.49 +      startPos += lenCounts[i] << (kNumBitsMax - i);
  471.50 +      if (startPos > kMaxValue)
  471.51 +        return false;
  471.52 +      m_Limits[i] = (i == kNumBitsMax) ? kMaxValue : startPos;
  471.53 +      m_Positions[i] = m_Positions[i - 1] + lenCounts[i - 1];
  471.54 +      tmpPositions[i] = m_Positions[i];
  471.55 +      if(i <= kNumTableBits)
  471.56 +      {
  471.57 +        UInt32 limit = (m_Limits[i] >> (kNumBitsMax - kNumTableBits));
  471.58 +        for (; index < limit; index++)
  471.59 +          m_Lengths[index] = (Byte)i;
  471.60 +      }
  471.61 +    }
  471.62 +    for (symbol = 0; symbol < m_NumSymbols; symbol++)
  471.63 +    {
  471.64 +      int len = codeLengths[symbol];
  471.65 +      if (len != 0)
  471.66 +        m_Symbols[tmpPositions[len]++] = symbol;
  471.67 +    }
  471.68 +    return true;
  471.69 +  }
  471.70 +
  471.71 +  template <class TBitDecoder>
  471.72 +  UInt32 DecodeSymbol(TBitDecoder *bitStream)
  471.73 +  {
  471.74 +    int numBits;
  471.75 +    UInt32 value = bitStream->GetValue(kNumBitsMax);
  471.76 +    if (value < m_Limits[kNumTableBits])
  471.77 +      numBits = m_Lengths[value >> (kNumBitsMax - kNumTableBits)];
  471.78 +    else
  471.79 +      for (numBits = kNumTableBits + 1; value >= m_Limits[numBits]; numBits++);
  471.80 +    bitStream->MovePos(numBits);
  471.81 +    UInt32 index = m_Positions[numBits] +
  471.82 +      ((value - m_Limits[numBits - 1]) >> (kNumBitsMax - numBits));
  471.83 +    if (index >= m_NumSymbols)
  471.84 +      // throw CDecoderException(); // test it
  471.85 +      return 0xFFFFFFFF;
  471.86 +    return m_Symbols[index];
  471.87 +  }
  471.88 +};
  471.89 +
  471.90 +}}
  471.91 +
  471.92 +#endif
   472.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   472.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/ImplodeDecoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   472.3 @@ -0,0 +1,219 @@
   472.4 +// Implode/Decoder.cpp
   472.5 +
   472.6 +#include "StdAfx.h"
   472.7 +
   472.8 +#include "ImplodeDecoder.h"
   472.9 +#include "Common/Defs.h"
  472.10 +
  472.11 +namespace NCompress {
  472.12 +namespace NImplode {
  472.13 +namespace NDecoder {
  472.14 +
  472.15 +class CException
  472.16 +{
  472.17 +public:
  472.18 +  enum ECauseType
  472.19 +  {
  472.20 +    kData
  472.21 +  } m_Cause;
  472.22 +  CException(ECauseType cause): m_Cause(cause) {}
  472.23 +};
  472.24 +
  472.25 +static const int kNumDistanceLowDirectBitsForBigDict = 7;
  472.26 +static const int kNumDistanceLowDirectBitsForSmallDict = 6;
  472.27 +
  472.28 +static const int kNumBitsInByte = 8;
  472.29 +
  472.30 +// static const int kLevelStructuresNumberFieldSize = kNumBitsInByte;
  472.31 +static const int kLevelStructuresNumberAdditionalValue = 1;
  472.32 +
  472.33 +static const int kNumLevelStructureLevelBits = 4;
  472.34 +static const int kLevelStructureLevelAdditionalValue = 1;
  472.35 +
  472.36 +static const int kNumLevelStructureRepNumberBits = 4;
  472.37 +static const int kLevelStructureRepNumberAdditionalValue = 1;
  472.38 +
  472.39 +
  472.40 +static const int kLiteralTableSize = (1 << kNumBitsInByte);
  472.41 +static const int kDistanceTableSize = 64;
  472.42 +static const int kLengthTableSize = 64;
  472.43 +
  472.44 +static const UInt32 kHistorySize =
  472.45 +    (1 << MyMax(kNumDistanceLowDirectBitsForBigDict,
  472.46 +                kNumDistanceLowDirectBitsForSmallDict)) *
  472.47 +    kDistanceTableSize; // = 8 KB;
  472.48 +
  472.49 +static const int kNumAdditionalLengthBits = 8;
  472.50 +
  472.51 +static const UInt32 kMatchMinLenWhenLiteralsOn = 3;
  472.52 +static const UInt32 kMatchMinLenWhenLiteralsOff = 2;
  472.53 +
  472.54 +static const UInt32 kMatchMinLenMax = MyMax(kMatchMinLenWhenLiteralsOn,
  472.55 +    kMatchMinLenWhenLiteralsOff);  // 3
  472.56 +
  472.57 +// static const UInt32 kMatchMaxLenMax = kMatchMinLenMax + (kLengthTableSize - 1) + (1 << kNumAdditionalLengthBits) - 1;  // or 2
  472.58 +
  472.59 +enum
  472.60 +{
  472.61 +  kMatchId = 0,
  472.62 +  kLiteralId = 1
  472.63 +};
  472.64 +
  472.65 +
  472.66 +CCoder::CCoder():
  472.67 +  m_LiteralDecoder(kLiteralTableSize),
  472.68 +  m_LengthDecoder(kLengthTableSize),
  472.69 +  m_DistanceDecoder(kDistanceTableSize)
  472.70 +{
  472.71 +}
  472.72 +
  472.73 +void CCoder::ReleaseStreams()
  472.74 +{
  472.75 +  m_OutWindowStream.ReleaseStream();
  472.76 +  m_InBitStream.ReleaseStream();
  472.77 +}
  472.78 +
  472.79 +bool CCoder::ReadLevelItems(NImplode::NHuffman::CDecoder &decoder,
  472.80 +    Byte *levels, int numLevelItems)
  472.81 +{
  472.82 +  int numCodedStructures = m_InBitStream.ReadBits(kNumBitsInByte) +
  472.83 +      kLevelStructuresNumberAdditionalValue;
  472.84 +  int currentIndex = 0;
  472.85 +  for(int i = 0; i < numCodedStructures; i++)
  472.86 +  {
  472.87 +    int level = m_InBitStream.ReadBits(kNumLevelStructureLevelBits) +
  472.88 +      kLevelStructureLevelAdditionalValue;
  472.89 +    int rep = m_InBitStream.ReadBits(kNumLevelStructureRepNumberBits) +
  472.90 +      kLevelStructureRepNumberAdditionalValue;
  472.91 +    if (currentIndex + rep > numLevelItems)
  472.92 +      throw CException(CException::kData);
  472.93 +    for(int j = 0; j < rep; j++)
  472.94 +      levels[currentIndex++] = (Byte)level;
  472.95 +  }
  472.96 +  if (currentIndex != numLevelItems)
  472.97 +    return false;
  472.98 +  return decoder.SetCodeLengths(levels);
  472.99 +}
 472.100 +
 472.101 +
 472.102 +bool CCoder::ReadTables(void)
 472.103 +{
 472.104 +  if (m_LiteralsOn)
 472.105 +  {
 472.106 +    Byte literalLevels[kLiteralTableSize];
 472.107 +    if (!ReadLevelItems(m_LiteralDecoder, literalLevels, kLiteralTableSize))
 472.108 +      return false;
 472.109 +  }
 472.110 +
 472.111 +  Byte lengthLevels[kLengthTableSize];
 472.112 +  if (!ReadLevelItems(m_LengthDecoder, lengthLevels, kLengthTableSize))
 472.113 +    return false;
 472.114 +
 472.115 +  Byte distanceLevels[kDistanceTableSize];
 472.116 +  return ReadLevelItems(m_DistanceDecoder, distanceLevels, kDistanceTableSize);
 472.117 +}
 472.118 +
 472.119 +class CCoderReleaser
 472.120 +{
 472.121 +  CCoder *m_Coder;
 472.122 +public:
 472.123 +  CCoderReleaser(CCoder *coder): m_Coder(coder) {}
 472.124 +  ~CCoderReleaser() { m_Coder->ReleaseStreams(); }
 472.125 +};
 472.126 +
 472.127 +HRESULT CCoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 472.128 +    const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)
 472.129 +{
 472.130 +  if (!m_InBitStream.Create(1 << 20))
 472.131 +    return E_OUTOFMEMORY;
 472.132 +  if (!m_OutWindowStream.Create(kHistorySize))
 472.133 +    return E_OUTOFMEMORY;
 472.134 +  if (outSize == NULL)
 472.135 +    return E_INVALIDARG;
 472.136 +  UInt64 pos = 0, unPackSize = *outSize;
 472.137 +
 472.138 +  m_OutWindowStream.SetStream(outStream);
 472.139 +  m_OutWindowStream.Init(false);
 472.140 +  m_InBitStream.SetStream(inStream);
 472.141 +  m_InBitStream.Init();
 472.142 +  CCoderReleaser coderReleaser(this);
 472.143 +
 472.144 +  if (!ReadTables())
 472.145 +    return S_FALSE;
 472.146 +  
 472.147 +  while(pos < unPackSize)
 472.148 +  {
 472.149 +    if (progress != NULL && pos % (1 << 16) == 0)
 472.150 +    {
 472.151 +      UInt64 packSize = m_InBitStream.GetProcessedSize();
 472.152 +      RINOK(progress->SetRatioInfo(&packSize, &pos));
 472.153 +    }
 472.154 +    if(m_InBitStream.ReadBits(1) == kMatchId) // match
 472.155 +    {
 472.156 +      UInt32 lowDistBits = m_InBitStream.ReadBits(m_NumDistanceLowDirectBits);
 472.157 +      UInt32 distance = m_DistanceDecoder.DecodeSymbol(&m_InBitStream);
 472.158 +      if (distance >= kDistanceTableSize)
 472.159 +        return S_FALSE;
 472.160 +      distance = (distance << m_NumDistanceLowDirectBits) + lowDistBits;
 472.161 +      UInt32 lengthSymbol = m_LengthDecoder.DecodeSymbol(&m_InBitStream);
 472.162 +      if (lengthSymbol >= kLengthTableSize)
 472.163 +        return S_FALSE;
 472.164 +      UInt32 length = lengthSymbol + m_MinMatchLength;
 472.165 +      if (lengthSymbol == kLengthTableSize - 1) // special symbol  = 63
 472.166 +        length += m_InBitStream.ReadBits(kNumAdditionalLengthBits);
 472.167 +      while(distance >= pos && length > 0)
 472.168 +      {
 472.169 +        m_OutWindowStream.PutByte(0);
 472.170 +        pos++;
 472.171 +        length--;
 472.172 +      }
 472.173 +      if (length > 0)
 472.174 +        m_OutWindowStream.CopyBlock(distance, length);
 472.175 +      pos += length;
 472.176 +    }
 472.177 +    else
 472.178 +    {
 472.179 +      Byte b;
 472.180 +      if (m_LiteralsOn)
 472.181 +      {
 472.182 +        UInt32 temp = m_LiteralDecoder.DecodeSymbol(&m_InBitStream);
 472.183 +        if (temp >= kLiteralTableSize)
 472.184 +          return S_FALSE;
 472.185 +        b = (Byte)temp;
 472.186 +      }
 472.187 +      else
 472.188 +        b = (Byte)m_InBitStream.ReadBits(kNumBitsInByte);
 472.189 +      m_OutWindowStream.PutByte(b);
 472.190 +      pos++;
 472.191 +    }
 472.192 +  }
 472.193 +  if (pos > unPackSize)
 472.194 +    return S_FALSE;
 472.195 +  return m_OutWindowStream.Flush();
 472.196 +}
 472.197 +
 472.198 +STDMETHODIMP CCoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 472.199 +    const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
 472.200 +{
 472.201 +  try { return CodeReal(inStream, outStream, inSize, outSize, progress);  }
 472.202 +  catch(const CLzOutWindowException &e) { return e.ErrorCode; }
 472.203 +  catch(...) { return S_FALSE; }
 472.204 +}
 472.205 +
 472.206 +STDMETHODIMP CCoder::SetDecoderProperties2(const Byte *data, UInt32 size)
 472.207 +{
 472.208 +  if (size < 1)
 472.209 +    return E_INVALIDARG;
 472.210 +  Byte flag = data[0];
 472.211 +  m_BigDictionaryOn = ((flag & 2) != 0);
 472.212 +  m_NumDistanceLowDirectBits = m_BigDictionaryOn ?
 472.213 +      kNumDistanceLowDirectBitsForBigDict:
 472.214 +      kNumDistanceLowDirectBitsForSmallDict;
 472.215 +  m_LiteralsOn = ((flag & 4) != 0);
 472.216 +  m_MinMatchLength = m_LiteralsOn ?
 472.217 +      kMatchMinLenWhenLiteralsOn :
 472.218 +      kMatchMinLenWhenLiteralsOff;
 472.219 +  return S_OK;
 472.220 +}
 472.221 +
 472.222 +}}}
   473.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   473.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/ImplodeDecoder.h	Sat Mar 03 10:31:27 2012 -0600
   473.3 @@ -0,0 +1,57 @@
   473.4 +// ImplodeDecoder.h
   473.5 +
   473.6 +#ifndef __COMPRESS_IMPLODE_DECODER_H
   473.7 +#define __COMPRESS_IMPLODE_DECODER_H
   473.8 +
   473.9 +#include "../../Common/MyCom.h"
  473.10 +
  473.11 +#include "../ICoder.h"
  473.12 +
  473.13 +#include "ImplodeHuffmanDecoder.h"
  473.14 +#include "LzOutWindow.h"
  473.15 +
  473.16 +namespace NCompress {
  473.17 +namespace NImplode {
  473.18 +namespace NDecoder {
  473.19 +
  473.20 +class CCoder:
  473.21 +  public ICompressCoder,
  473.22 +  public ICompressSetDecoderProperties2,
  473.23 +  public CMyUnknownImp
  473.24 +{
  473.25 +  CLzOutWindow m_OutWindowStream;
  473.26 +  NBitl::CDecoder<CInBuffer> m_InBitStream;
  473.27 +  
  473.28 +  NImplode::NHuffman::CDecoder m_LiteralDecoder;
  473.29 +  NImplode::NHuffman::CDecoder m_LengthDecoder;
  473.30 +  NImplode::NHuffman::CDecoder m_DistanceDecoder;
  473.31 +
  473.32 +  bool m_BigDictionaryOn;
  473.33 +  bool m_LiteralsOn;
  473.34 +
  473.35 +  int m_NumDistanceLowDirectBits;
  473.36 +  UInt32 m_MinMatchLength;
  473.37 +
  473.38 +  bool ReadLevelItems(NImplode::NHuffman::CDecoder &table, Byte *levels, int numLevelItems);
  473.39 +  bool ReadTables();
  473.40 +  void DeCodeLevelTable(Byte *newLevels, int numLevels);
  473.41 +public:
  473.42 +  CCoder();
  473.43 +
  473.44 +  MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2)
  473.45 +
  473.46 +  void ReleaseStreams();
  473.47 +  HRESULT Flush() { return m_OutWindowStream.Flush(); }
  473.48 +
  473.49 +  HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  473.50 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
  473.51 +
  473.52 +  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  473.53 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
  473.54 +
  473.55 +  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
  473.56 +};
  473.57 +
  473.58 +}}}
  473.59 +
  473.60 +#endif
   474.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   474.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/ImplodeHuffmanDecoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   474.3 @@ -0,0 +1,89 @@
   474.4 +// ImplodeHuffmanDecoder.cpp
   474.5 +
   474.6 +#include "StdAfx.h"
   474.7 +
   474.8 +#include "ImplodeHuffmanDecoder.h"
   474.9 +
  474.10 +namespace NCompress {
  474.11 +namespace NImplode {
  474.12 +namespace NHuffman {
  474.13 +
  474.14 +CDecoder::CDecoder(UInt32 numSymbols):
  474.15 +  m_NumSymbols(numSymbols)
  474.16 +{
  474.17 +  m_Symbols = new UInt32[m_NumSymbols];
  474.18 +}
  474.19 +
  474.20 +CDecoder::~CDecoder()
  474.21 +{
  474.22 +  delete []m_Symbols;
  474.23 +}
  474.24 +
  474.25 +bool CDecoder::SetCodeLengths(const Byte *codeLengths)
  474.26 +{
  474.27 +  // int lenCounts[kNumBitsInLongestCode + 1], tmpPositions[kNumBitsInLongestCode + 1];
  474.28 +  int lenCounts[kNumBitsInLongestCode + 2], tmpPositions[kNumBitsInLongestCode + 1];
  474.29 +  int i;
  474.30 +  for(i = 0; i <= kNumBitsInLongestCode; i++)
  474.31 +    lenCounts[i] = 0;
  474.32 +  UInt32 symbolIndex;
  474.33 +  for (symbolIndex = 0; symbolIndex < m_NumSymbols; symbolIndex++)
  474.34 +    lenCounts[codeLengths[symbolIndex]]++;
  474.35 +  // lenCounts[0] = 0;
  474.36 +  
  474.37 +  // tmpPositions[0] = m_Positions[0] = m_Limitits[0] = 0;
  474.38 +  m_Limitits[kNumBitsInLongestCode + 1] = 0;
  474.39 +  m_Positions[kNumBitsInLongestCode + 1] = 0;
  474.40 +  lenCounts[kNumBitsInLongestCode + 1] = 0;
  474.41 +
  474.42 +
  474.43 +  UInt32 startPos = 0;
  474.44 +  static const UInt32 kMaxValue = (1 << kNumBitsInLongestCode);
  474.45 +
  474.46 +  for (i = kNumBitsInLongestCode; i > 0; i--)
  474.47 +  {
  474.48 +    startPos += lenCounts[i] << (kNumBitsInLongestCode - i);
  474.49 +    if (startPos > kMaxValue)
  474.50 +      return false;
  474.51 +    m_Limitits[i] = startPos;
  474.52 +    m_Positions[i] = m_Positions[i + 1] + lenCounts[i + 1];
  474.53 +    tmpPositions[i] = m_Positions[i] + lenCounts[i];
  474.54 +
  474.55 +  }
  474.56 +
  474.57 +  // if _ZIP_MODE do not throw exception for trees containing only one node
  474.58 +  // #ifndef _ZIP_MODE
  474.59 +  if (startPos != kMaxValue)
  474.60 +    return false;
  474.61 +  // #endif
  474.62 +
  474.63 +  for (symbolIndex = 0; symbolIndex < m_NumSymbols; symbolIndex++)
  474.64 +    if (codeLengths[symbolIndex] != 0)
  474.65 +      m_Symbols[--tmpPositions[codeLengths[symbolIndex]]] = symbolIndex;
  474.66 +  return true;
  474.67 +}
  474.68 +
  474.69 +UInt32 CDecoder::DecodeSymbol(CInBit *inStream)
  474.70 +{
  474.71 +  UInt32 numBits = 0;
  474.72 +  UInt32 value = inStream->GetValue(kNumBitsInLongestCode);
  474.73 +  int i;
  474.74 +  for(i = kNumBitsInLongestCode; i > 0; i--)
  474.75 +  {
  474.76 +    if (value < m_Limitits[i])
  474.77 +    {
  474.78 +      numBits = i;
  474.79 +      break;
  474.80 +    }
  474.81 +  }
  474.82 +  if (i == 0)
  474.83 +    return 0xFFFFFFFF;
  474.84 +  inStream->MovePos(numBits);
  474.85 +  UInt32 index = m_Positions[numBits] +
  474.86 +      ((value - m_Limitits[numBits + 1]) >> (kNumBitsInLongestCode - numBits));
  474.87 +  if (index >= m_NumSymbols)
  474.88 +    return 0xFFFFFFFF;
  474.89 +  return m_Symbols[index];
  474.90 +}
  474.91 +
  474.92 +}}}
   475.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   475.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/ImplodeHuffmanDecoder.h	Sat Mar 03 10:31:27 2012 -0600
   475.3 @@ -0,0 +1,34 @@
   475.4 +// ImplodeHuffmanDecoder.h
   475.5 +
   475.6 +#ifndef __IMPLODE_HUFFMAN_DECODER_H
   475.7 +#define __IMPLODE_HUFFMAN_DECODER_H
   475.8 +
   475.9 +#include "../Common/InBuffer.h"
  475.10 +
  475.11 +#include "BitlDecoder.h"
  475.12 +
  475.13 +namespace NCompress {
  475.14 +namespace NImplode {
  475.15 +namespace NHuffman {
  475.16 +
  475.17 +const int kNumBitsInLongestCode = 16;
  475.18 +
  475.19 +typedef NBitl::CDecoder<CInBuffer> CInBit;
  475.20 +
  475.21 +class CDecoder
  475.22 +{
  475.23 +  UInt32 m_Limitits[kNumBitsInLongestCode + 2]; // m_Limitits[i] = value limit for symbols with length = i
  475.24 +  UInt32 m_Positions[kNumBitsInLongestCode + 2];   // m_Positions[i] = index in m_Symbols[] of first symbol with length = i
  475.25 +  UInt32 m_NumSymbols; // number of symbols in m_Symbols
  475.26 +  UInt32 *m_Symbols; // symbols: at first with len=1 then 2, ... 15.
  475.27 +public:
  475.28 +  CDecoder(UInt32 numSymbols);
  475.29 +  ~CDecoder();
  475.30 +  
  475.31 +  bool SetCodeLengths(const Byte *codeLengths);
  475.32 +  UInt32 DecodeSymbol(CInBit *inStream);
  475.33 +};
  475.34 +
  475.35 +}}}
  475.36 +
  475.37 +#endif
   476.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   476.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/LzOutWindow.cpp	Sat Mar 03 10:31:27 2012 -0600
   476.3 @@ -0,0 +1,14 @@
   476.4 +// LzOutWindow.cpp
   476.5 +
   476.6 +#include "StdAfx.h"
   476.7 +
   476.8 +#include "LzOutWindow.h"
   476.9 +
  476.10 +void CLzOutWindow::Init(bool solid)
  476.11 +{
  476.12 +  if (!solid)
  476.13 +    COutBuffer::Init();
  476.14 +  #ifdef _NO_EXCEPTIONS
  476.15 +  ErrorCode = S_OK;
  476.16 +  #endif
  476.17 +}
   477.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   477.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/LzOutWindow.h	Sat Mar 03 10:31:27 2012 -0600
   477.3 @@ -0,0 +1,66 @@
   477.4 +// LzOutWindow.h
   477.5 +
   477.6 +#ifndef __LZ_OUT_WINDOW_H
   477.7 +#define __LZ_OUT_WINDOW_H
   477.8 +
   477.9 +#include "../IStream.h"
  477.10 +
  477.11 +#include "../Common/OutBuffer.h"
  477.12 +
  477.13 +#ifndef _NO_EXCEPTIONS
  477.14 +typedef COutBufferException CLzOutWindowException;
  477.15 +#endif
  477.16 +
  477.17 +class CLzOutWindow: public COutBuffer
  477.18 +{
  477.19 +public:
  477.20 +  void Init(bool solid = false);
  477.21 +  
  477.22 +  // distance >= 0, len > 0,
  477.23 +  bool CopyBlock(UInt32 distance, UInt32 len)
  477.24 +  {
  477.25 +    UInt32 pos = _pos - distance - 1;
  477.26 +    if (distance >= _pos)
  477.27 +    {
  477.28 +      if (!_overDict || distance >= _bufferSize)
  477.29 +        return false;
  477.30 +      pos += _bufferSize;
  477.31 +    }
  477.32 +    if (_limitPos - _pos > len && _bufferSize - pos > len)
  477.33 +    {
  477.34 +      const Byte *src = _buffer + pos;
  477.35 +      Byte *dest = _buffer + _pos;
  477.36 +      _pos += len;
  477.37 +      do
  477.38 +        *dest++ = *src++;
  477.39 +      while(--len != 0);
  477.40 +    }
  477.41 +    else do
  477.42 +    {
  477.43 +      if (pos == _bufferSize)
  477.44 +        pos = 0;
  477.45 +      _buffer[_pos++] = _buffer[pos++];
  477.46 +      if (_pos == _limitPos)
  477.47 +        FlushWithCheck();
  477.48 +    }
  477.49 +    while(--len != 0);
  477.50 +    return true;
  477.51 +  }
  477.52 +  
  477.53 +  void PutByte(Byte b)
  477.54 +  {
  477.55 +    _buffer[_pos++] = b;
  477.56 +    if (_pos == _limitPos)
  477.57 +      FlushWithCheck();
  477.58 +  }
  477.59 +  
  477.60 +  Byte GetByte(UInt32 distance) const
  477.61 +  {
  477.62 +    UInt32 pos = _pos - distance - 1;
  477.63 +    if (pos >= _bufferSize)
  477.64 +      pos += _bufferSize;
  477.65 +    return _buffer[pos];
  477.66 +  }
  477.67 +};
  477.68 +
  477.69 +#endif
   478.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   478.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/LzhDecoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   478.3 @@ -0,0 +1,220 @@
   478.4 +// LzhDecoder.cpp
   478.5 +
   478.6 +#include "StdAfx.h"
   478.7 +
   478.8 +#include "LzhDecoder.h"
   478.9 +
  478.10 +#include "Windows/Defs.h"
  478.11 +
  478.12 +namespace NCompress{
  478.13 +namespace NLzh {
  478.14 +namespace NDecoder {
  478.15 +
  478.16 +static const UInt32 kHistorySize = (1 << 16);
  478.17 +
  478.18 +static const int kBlockSizeBits = 16;
  478.19 +static const int kNumCBits = 9;
  478.20 +static const int kNumLevelBits = 5; // smallest integer such that (1 << kNumLevelBits) > kNumLevelSymbols/
  478.21 +
  478.22 +UInt32 CCoder::ReadBits(int numBits) {  return m_InBitStream.ReadBits(numBits); }
  478.23 +
  478.24 +HRESULT CCoder::ReadLevelTable()
  478.25 +{
  478.26 +  int n = ReadBits(kNumLevelBits);
  478.27 +  if (n == 0)
  478.28 +  {
  478.29 +    m_LevelHuffman.Symbol = ReadBits(kNumLevelBits);
  478.30 +    if (m_LevelHuffman.Symbol >= kNumLevelSymbols)
  478.31 +      return S_FALSE;
  478.32 +  }
  478.33 +  else
  478.34 +  {
  478.35 +    if (n > kNumLevelSymbols)
  478.36 +      return S_FALSE;
  478.37 +    m_LevelHuffman.Symbol = -1;
  478.38 +    Byte lens[kNumLevelSymbols];
  478.39 +    int i = 0;
  478.40 +    while (i < n)
  478.41 +    {
  478.42 +      int c = m_InBitStream.ReadBits(3);
  478.43 +      if (c == 7)
  478.44 +        while (ReadBits(1))
  478.45 +          if (c++ > kMaxHuffmanLen)
  478.46 +            return S_FALSE;
  478.47 +      lens[i++] = (Byte)c;
  478.48 +      if (i == kNumSpecLevelSymbols)
  478.49 +      {
  478.50 +        c = ReadBits(2);
  478.51 +        while (--c >= 0)
  478.52 +          lens[i++] = 0;
  478.53 +      }
  478.54 +    }
  478.55 +    while (i < kNumLevelSymbols)
  478.56 +      lens[i++] = 0;
  478.57 +    m_LevelHuffman.SetCodeLengths(lens);
  478.58 +  }
  478.59 +  return S_OK;
  478.60 +}
  478.61 +
  478.62 +HRESULT CCoder::ReadPTable(int numBits)
  478.63 +{
  478.64 +  int n = ReadBits(numBits);
  478.65 +  if (n == 0)
  478.66 +  {
  478.67 +    m_PHuffmanDecoder.Symbol = ReadBits(numBits);
  478.68 +    if (m_PHuffmanDecoder.Symbol >= kNumDistanceSymbols)
  478.69 +      return S_FALSE;
  478.70 +  }
  478.71 +  else
  478.72 +  {
  478.73 +    if (n > kNumDistanceSymbols)
  478.74 +      return S_FALSE;
  478.75 +    m_PHuffmanDecoder.Symbol = -1;
  478.76 +    Byte lens[kNumDistanceSymbols];
  478.77 +    int i = 0;
  478.78 +    while (i < n)
  478.79 +    {
  478.80 +      int c = m_InBitStream.ReadBits(3);
  478.81 +      if (c == 7)
  478.82 +        while (ReadBits(1))
  478.83 +        {
  478.84 +          if (c > kMaxHuffmanLen)
  478.85 +            return S_FALSE;
  478.86 +          c++;
  478.87 +        }
  478.88 +      lens[i++] = (Byte)c;
  478.89 +    }
  478.90 +    while (i < kNumDistanceSymbols)
  478.91 +      lens[i++] = 0;
  478.92 +    m_PHuffmanDecoder.SetCodeLengths(lens);
  478.93 +  }
  478.94 +  return S_OK;
  478.95 +}
  478.96 +
  478.97 +HRESULT CCoder::ReadCTable()
  478.98 +{
  478.99 +  int n = ReadBits(kNumCBits);
 478.100 +  if (n == 0)
 478.101 +  {
 478.102 +    m_CHuffmanDecoder.Symbol = ReadBits(kNumCBits);
 478.103 +    if (m_CHuffmanDecoder.Symbol >= kNumCSymbols)
 478.104 +      return S_FALSE;
 478.105 +  }
 478.106 +  else
 478.107 +  {
 478.108 +    if (n > kNumCSymbols)
 478.109 +      return S_FALSE;
 478.110 +    m_CHuffmanDecoder.Symbol = -1;
 478.111 +    Byte lens[kNumCSymbols];
 478.112 +    int i = 0;
 478.113 +    while (i < n)
 478.114 +    {
 478.115 +      int c = m_LevelHuffman.Decode(&m_InBitStream);
 478.116 +      if (c < kNumSpecLevelSymbols)
 478.117 +      {
 478.118 +        if (c == 0)
 478.119 +          c = 1;
 478.120 +        else if (c == 1)
 478.121 +          c = ReadBits(4) + 3;
 478.122 +        else
 478.123 +          c = ReadBits(kNumCBits) + 20;
 478.124 +        while (--c >= 0)
 478.125 +        {
 478.126 +          if (i > kNumCSymbols)
 478.127 +            return S_FALSE;
 478.128 +          lens[i++] = 0;
 478.129 +        }
 478.130 +      }
 478.131 +      else
 478.132 +        lens[i++] = (Byte)(c - 2);
 478.133 +    }
 478.134 +    while (i < kNumCSymbols)
 478.135 +      lens[i++] = 0;
 478.136 +    m_CHuffmanDecoder.SetCodeLengths(lens);
 478.137 +  }
 478.138 +  return S_OK;
 478.139 +}
 478.140 +
 478.141 +STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
 478.142 +    ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,
 478.143 +    ICompressProgressInfo *progress)
 478.144 +{
 478.145 +  if (outSize == NULL)
 478.146 +    return E_INVALIDARG;
 478.147 +
 478.148 +  if (!m_OutWindowStream.Create(kHistorySize))
 478.149 +    return E_OUTOFMEMORY;
 478.150 +  if (!m_InBitStream.Create(1 << 20))
 478.151 +    return E_OUTOFMEMORY;
 478.152 +
 478.153 +  UInt64 pos = 0;
 478.154 +  m_OutWindowStream.SetStream(outStream);
 478.155 +  m_OutWindowStream.Init(false);
 478.156 +  m_InBitStream.SetStream(inStream);
 478.157 +  m_InBitStream.Init();
 478.158 +  
 478.159 +  CCoderReleaser coderReleaser(this);
 478.160 +
 478.161 +  int pbit;
 478.162 +  if (m_NumDictBits <= 13)
 478.163 +    pbit = 4;
 478.164 +  else
 478.165 +    pbit = 5;
 478.166 +
 478.167 +  UInt32 blockSize = 0;
 478.168 +
 478.169 +  while(pos < *outSize)
 478.170 +  {
 478.171 +    // for (i = 0; i < dictSize; i++) dtext[i] = 0x20;
 478.172 +    
 478.173 +    if (blockSize == 0)
 478.174 +    {
 478.175 +      if (progress != NULL)
 478.176 +      {
 478.177 +        UInt64 packSize = m_InBitStream.GetProcessedSize();
 478.178 +        RINOK(progress->SetRatioInfo(&packSize, &pos));
 478.179 +      }
 478.180 +      blockSize = ReadBits(kBlockSizeBits);
 478.181 +      ReadLevelTable();
 478.182 +      ReadCTable();
 478.183 +      RINOK(ReadPTable(pbit));
 478.184 +    }
 478.185 +    blockSize--;
 478.186 +    UInt32 c = m_CHuffmanDecoder.Decode(&m_InBitStream);
 478.187 +    if (c < 256)
 478.188 +    {
 478.189 +      m_OutWindowStream.PutByte((Byte)c);
 478.190 +      pos++;
 478.191 +    }
 478.192 +    else if (c >= kNumCSymbols)
 478.193 +      return S_FALSE;
 478.194 +    else
 478.195 +    {
 478.196 +      // offset = (interface->method == LARC_METHOD_NUM) ? 0x100 - 2 : 0x100 - 3;
 478.197 +      UInt32 len  = c - 256 + kMinMatch;
 478.198 +      UInt32 distance = m_PHuffmanDecoder.Decode(&m_InBitStream);
 478.199 +      if (distance != 0)
 478.200 +        distance = (1 << (distance - 1)) + ReadBits(distance - 1);
 478.201 +      if (distance >= pos)
 478.202 +        return S_FALSE;
 478.203 +      if (pos + len > *outSize)
 478.204 +        len = (UInt32)(*outSize - pos);
 478.205 +      pos += len;
 478.206 +      m_OutWindowStream.CopyBlock(distance, len);
 478.207 +    }
 478.208 +  }
 478.209 +  coderReleaser.NeedFlush = false;
 478.210 +  return m_OutWindowStream.Flush();
 478.211 +}
 478.212 +
 478.213 +STDMETHODIMP CCoder::Code(ISequentialInStream *inStream,
 478.214 +    ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
 478.215 +    ICompressProgressInfo *progress)
 478.216 +{
 478.217 +  try { return CodeReal(inStream, outStream, inSize, outSize, progress);}
 478.218 +  catch(const CInBufferException &e) { return e.ErrorCode; }
 478.219 +  catch(const CLzOutWindowException &e) { return e.ErrorCode; }
 478.220 +  catch(...) { return S_FALSE; }
 478.221 +}
 478.222 +
 478.223 +}}}
   479.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   479.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/LzhDecoder.h	Sat Mar 03 10:31:27 2012 -0600
   479.3 @@ -0,0 +1,106 @@
   479.4 +// LzhDecoder.h
   479.5 +
   479.6 +#ifndef __COMPRESS_LZH_DECODER_H
   479.7 +#define __COMPRESS_LZH_DECODER_H
   479.8 +
   479.9 +#include "../../Common/MyCom.h"
  479.10 +
  479.11 +#include "../ICoder.h"
  479.12 +
  479.13 +#include "../Common/InBuffer.h"
  479.14 +
  479.15 +#include "BitmDecoder.h"
  479.16 +#include "HuffmanDecoder.h"
  479.17 +#include "LzOutWindow.h"
  479.18 +
  479.19 +namespace NCompress {
  479.20 +namespace NLzh {
  479.21 +namespace NDecoder {
  479.22 +
  479.23 +const int kMaxHuffmanLen = 16; // Check it
  479.24 +
  479.25 +const int kNumSpecLevelSymbols = 3;
  479.26 +const int kNumLevelSymbols = kNumSpecLevelSymbols + kMaxHuffmanLen;
  479.27 +
  479.28 +const int kDictBitsMax = 16;
  479.29 +const int kNumDistanceSymbols = kDictBitsMax + 1;
  479.30 +
  479.31 +const int kMaxMatch = 256;
  479.32 +const int kMinMatch = 3;
  479.33 +const int kNumCSymbols = 256 + kMaxMatch + 2 - kMinMatch;
  479.34 +
  479.35 +template <UInt32 m_NumSymbols>
  479.36 +class CHuffmanDecoder:public NCompress::NHuffman::CDecoder<kMaxHuffmanLen, m_NumSymbols>
  479.37 +{
  479.38 +public:
  479.39 +  int Symbol;
  479.40 +  template <class TBitDecoder>
  479.41 +  UInt32 Decode(TBitDecoder *bitStream)
  479.42 +  {
  479.43 +    if (Symbol >= 0)
  479.44 +      return (UInt32)Symbol;
  479.45 +    return DecodeSymbol(bitStream);
  479.46 +  }
  479.47 +};
  479.48 +
  479.49 +class CCoder :
  479.50 +  public ICompressCoder,
  479.51 +  public CMyUnknownImp
  479.52 +{
  479.53 +  CLzOutWindow m_OutWindowStream;
  479.54 +  NBitm::CDecoder<CInBuffer> m_InBitStream;
  479.55 +
  479.56 +  int m_NumDictBits;
  479.57 +
  479.58 +  CHuffmanDecoder<kNumLevelSymbols> m_LevelHuffman;
  479.59 +  CHuffmanDecoder<kNumDistanceSymbols> m_PHuffmanDecoder;
  479.60 +  CHuffmanDecoder<kNumCSymbols> m_CHuffmanDecoder;
  479.61 +
  479.62 +  void ReleaseStreams()
  479.63 +  {
  479.64 +    m_OutWindowStream.ReleaseStream();
  479.65 +    m_InBitStream.ReleaseStream();
  479.66 +  }
  479.67 +
  479.68 +  class CCoderReleaser
  479.69 +  {
  479.70 +    CCoder *m_Coder;
  479.71 +  public:
  479.72 +    bool NeedFlush;
  479.73 +    CCoderReleaser(CCoder *coder): m_Coder(coder), NeedFlush(true) {}
  479.74 +    ~CCoderReleaser()
  479.75 +    {
  479.76 +      if (NeedFlush)
  479.77 +        m_Coder->m_OutWindowStream.Flush();
  479.78 +      m_Coder->ReleaseStreams();
  479.79 +    }
  479.80 +  };
  479.81 +  friend class CCoderReleaser;
  479.82 +
  479.83 +  void MakeTable(int nchar, Byte *bitlen, int tablebits,
  479.84 +      UInt32 *table, int tablesize);
  479.85 +  
  479.86 +  UInt32 ReadBits(int numBits);
  479.87 +  HRESULT ReadLevelTable();
  479.88 +  HRESULT ReadPTable(int numBits);
  479.89 +  HRESULT ReadCTable();
  479.90 +
  479.91 +public:
  479.92 +  
  479.93 +  MY_UNKNOWN_IMP
  479.94 +
  479.95 +  STDMETHOD(CodeReal)(ISequentialInStream *inStream,
  479.96 +      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
  479.97 +      ICompressProgressInfo *progress);
  479.98 +
  479.99 +  STDMETHOD(Code)(ISequentialInStream *inStream,
 479.100 +      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
 479.101 +      ICompressProgressInfo *progress);
 479.102 +
 479.103 +  void SetDictionary(int numDictBits) { m_NumDictBits = numDictBits; }
 479.104 +  CCoder(): m_NumDictBits(0) {}
 479.105 +};
 479.106 +
 479.107 +}}}
 479.108 +
 479.109 +#endif
   480.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   480.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/LzmaDecoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   480.3 @@ -0,0 +1,190 @@
   480.4 +// LzmaDecoder.cpp
   480.5 +
   480.6 +#include "StdAfx.h"
   480.7 +
   480.8 +extern "C"
   480.9 +{
  480.10 +#include "../../../C/Alloc.h"
  480.11 +}
  480.12 +
  480.13 +#include "../Common/StreamUtils.h"
  480.14 +
  480.15 +#include "LzmaDecoder.h"
  480.16 +
  480.17 +static HRESULT SResToHRESULT(SRes res)
  480.18 +{
  480.19 +  switch(res)
  480.20 +  {
  480.21 +    case SZ_OK: return S_OK;
  480.22 +    case SZ_ERROR_MEM: return E_OUTOFMEMORY;
  480.23 +    case SZ_ERROR_PARAM: return E_INVALIDARG;
  480.24 +    case SZ_ERROR_UNSUPPORTED: return E_NOTIMPL;
  480.25 +    // case SZ_ERROR_PROGRESS: return E_ABORT;
  480.26 +    case SZ_ERROR_DATA: return S_FALSE;
  480.27 +  }
  480.28 +  return E_FAIL;
  480.29 +}
  480.30 +
  480.31 +namespace NCompress {
  480.32 +namespace NLzma {
  480.33 +
  480.34 +static const UInt32 kInBufSize = 1 << 20;
  480.35 +
  480.36 +CDecoder::CDecoder(): _inBuf(0), _outSizeDefined(false), FinishStream(false)
  480.37 +{
  480.38 +  LzmaDec_Construct(&_state);
  480.39 +}
  480.40 +
  480.41 +static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
  480.42 +static void SzFree(void *p, void *address) { p = p; MyFree(address); }
  480.43 +static ISzAlloc g_Alloc = { SzAlloc, SzFree };
  480.44 +
  480.45 +CDecoder::~CDecoder()
  480.46 +{
  480.47 +  LzmaDec_Free(&_state, &g_Alloc);
  480.48 +  MyFree(_inBuf);
  480.49 +}
  480.50 +
  480.51 +STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *prop, UInt32 size)
  480.52 +{
  480.53 +  RINOK(SResToHRESULT(LzmaDec_Allocate(&_state, prop, size, &g_Alloc)));
  480.54 +
  480.55 +  if (_inBuf == 0)
  480.56 +  {
  480.57 +    _inBuf = (Byte *)MyAlloc(kInBufSize);
  480.58 +    if (_inBuf == 0)
  480.59 +      return E_OUTOFMEMORY;
  480.60 +  }
  480.61 +
  480.62 +  return S_OK;
  480.63 +}
  480.64 +
  480.65 +STDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value) { *value = _inSizeProcessed; return S_OK; }
  480.66 +STDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream) { _inStream = inStream; return S_OK; }
  480.67 +STDMETHODIMP CDecoder::ReleaseInStream() { _inStream.Release(); return S_OK; }
  480.68 +
  480.69 +STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)
  480.70 +{
  480.71 +  _outSizeDefined = (outSize != NULL);
  480.72 +  if (_outSizeDefined)
  480.73 +    _outSize = *outSize;
  480.74 +
  480.75 +  LzmaDec_Init(&_state);
  480.76 +  
  480.77 +  _inPos = _inSize = 0;
  480.78 +  _inSizeProcessed = _outSizeProcessed = 0;
  480.79 +  return S_OK;
  480.80 +}
  480.81 +
  480.82 +STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  480.83 +    const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)
  480.84 +{
  480.85 +  if (_inBuf == 0)
  480.86 +    return S_FALSE;
  480.87 +  SetOutStreamSize(outSize);
  480.88 +
  480.89 +  for (;;)
  480.90 +  {
  480.91 +    if (_inPos == _inSize)
  480.92 +    {
  480.93 +      _inPos = _inSize = 0;
  480.94 +      RINOK(inStream->Read(_inBuf, kInBufSize, &_inSize));
  480.95 +    }
  480.96 +
  480.97 +    SizeT dicPos = _state.dicPos;
  480.98 +    SizeT curSize = _state.dicBufSize - dicPos;
  480.99 +    const UInt32 kStepSize = ((UInt32)1 << 22);
 480.100 +    if (curSize > kStepSize)
 480.101 +      curSize = (SizeT)kStepSize;
 480.102 +    
 480.103 +    ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
 480.104 +    if (_outSizeDefined)
 480.105 +    {
 480.106 +      const UInt64 rem = _outSize - _outSizeProcessed;
 480.107 +      if (rem < curSize)
 480.108 +      {
 480.109 +        curSize = (SizeT)rem;
 480.110 +        if (FinishStream)
 480.111 +          finishMode = LZMA_FINISH_END;
 480.112 +      }
 480.113 +    }
 480.114 +
 480.115 +    SizeT inSizeProcessed = _inSize - _inPos;
 480.116 +    ELzmaStatus status;
 480.117 +    SRes res = LzmaDec_DecodeToDic(&_state, dicPos + curSize, _inBuf + _inPos, &inSizeProcessed, finishMode, &status);
 480.118 +
 480.119 +    _inPos += (UInt32)inSizeProcessed;
 480.120 +    _inSizeProcessed += inSizeProcessed;
 480.121 +    SizeT outSizeProcessed = _state.dicPos - dicPos;
 480.122 +    _outSizeProcessed += outSizeProcessed;
 480.123 +
 480.124 +    bool finished = (inSizeProcessed == 0 && outSizeProcessed == 0);
 480.125 +    bool stopDecoding = (_outSizeDefined && _outSizeProcessed >= _outSize);
 480.126 +
 480.127 +    if (res != 0 || _state.dicPos == _state.dicBufSize || finished || stopDecoding)
 480.128 +    {
 480.129 +      HRESULT res2 = WriteStream(outStream, _state.dic, _state.dicPos);
 480.130 +      if (res != 0)
 480.131 +        return S_FALSE;
 480.132 +      RINOK(res2);
 480.133 +      if (stopDecoding)
 480.134 +        return S_OK;
 480.135 +      if (finished)
 480.136 +        return (status == LZMA_STATUS_FINISHED_WITH_MARK ? S_OK : S_FALSE);
 480.137 +    }
 480.138 +    if (_state.dicPos == _state.dicBufSize)
 480.139 +      _state.dicPos = 0;
 480.140 +
 480.141 +    if (progress != NULL)
 480.142 +    {
 480.143 +      RINOK(progress->SetRatioInfo(&_inSizeProcessed, &_outSizeProcessed));
 480.144 +    }
 480.145 +  }
 480.146 +}
 480.147 +
 480.148 +#ifndef NO_READ_FROM_CODER
 480.149 +
 480.150 +STDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)
 480.151 +{
 480.152 +  if (processedSize)
 480.153 +    *processedSize = 0;
 480.154 +  do
 480.155 +  {
 480.156 +    if (_inPos == _inSize)
 480.157 +    {
 480.158 +      _inPos = _inSize = 0;
 480.159 +      RINOK(_inStream->Read(_inBuf, kInBufSize, &_inSize));
 480.160 +    }
 480.161 +    {
 480.162 +      SizeT inProcessed = _inSize - _inPos;
 480.163 +
 480.164 +      if (_outSizeDefined)
 480.165 +      {
 480.166 +        const UInt64 rem = _outSize - _outSizeProcessed;
 480.167 +        if (rem < size)
 480.168 +          size = (UInt32)rem;
 480.169 +      }
 480.170 +
 480.171 +      SizeT outProcessed = size;
 480.172 +      ELzmaStatus status;
 480.173 +      SRes res = LzmaDec_DecodeToBuf(&_state, (Byte *)data, &outProcessed,
 480.174 +          _inBuf + _inPos, &inProcessed, LZMA_FINISH_ANY, &status);
 480.175 +      _inPos += (UInt32)inProcessed;
 480.176 +      _inSizeProcessed += inProcessed;
 480.177 +      _outSizeProcessed += outProcessed;
 480.178 +      size -= (UInt32)outProcessed;
 480.179 +      data = (Byte *)data + outProcessed;
 480.180 +      if (processedSize)
 480.181 +        *processedSize += (UInt32)outProcessed;
 480.182 +      RINOK(SResToHRESULT(res));
 480.183 +      if (inProcessed == 0 && outProcessed == 0)
 480.184 +        return S_OK;
 480.185 +    }
 480.186 +  }
 480.187 +  while (size != 0);
 480.188 +  return S_OK;
 480.189 +}
 480.190 +
 480.191 +#endif
 480.192 +
 480.193 +}}
   481.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   481.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/LzmaDecoder.h	Sat Mar 03 10:31:27 2012 -0600
   481.3 @@ -0,0 +1,73 @@
   481.4 +// LzmaDecoder.h
   481.5 +
   481.6 +#ifndef __LZMA_DECODER_H
   481.7 +#define __LZMA_DECODER_H
   481.8 +
   481.9 +extern "C"
  481.10 +{
  481.11 +#include "../../../C/LzmaDec.h"
  481.12 +}
  481.13 +
  481.14 +#include "../../Common/MyCom.h"
  481.15 +#include "../ICoder.h"
  481.16 +
  481.17 +namespace NCompress {
  481.18 +namespace NLzma {
  481.19 +
  481.20 +class CDecoder:
  481.21 +  public ICompressCoder,
  481.22 +  public ICompressSetDecoderProperties2,
  481.23 +  public ICompressGetInStreamProcessedSize,
  481.24 +  #ifndef NO_READ_FROM_CODER
  481.25 +  public ICompressSetInStream,
  481.26 +  public ICompressSetOutStreamSize,
  481.27 +  public ISequentialInStream,
  481.28 +  #endif
  481.29 +  public CMyUnknownImp
  481.30 +{
  481.31 +  CMyComPtr<ISequentialInStream> _inStream;
  481.32 +  Byte *_inBuf;
  481.33 +  UInt32 _inPos;
  481.34 +  UInt32 _inSize;
  481.35 +  CLzmaDec _state;
  481.36 +  bool _outSizeDefined;
  481.37 +  UInt64 _outSize;
  481.38 +  UInt64 _inSizeProcessed;
  481.39 +  UInt64 _outSizeProcessed;
  481.40 +public:
  481.41 +
  481.42 +  #ifndef NO_READ_FROM_CODER
  481.43 +  MY_UNKNOWN_IMP5(
  481.44 +      ICompressSetDecoderProperties2,
  481.45 +      ICompressGetInStreamProcessedSize,
  481.46 +      ICompressSetInStream,
  481.47 +      ICompressSetOutStreamSize,
  481.48 +      ISequentialInStream)
  481.49 +  #else
  481.50 +  MY_UNKNOWN_IMP2(
  481.51 +      ICompressSetDecoderProperties2,
  481.52 +      ICompressGetInStreamProcessedSize)
  481.53 +  #endif
  481.54 +
  481.55 +  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  481.56 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
  481.57 +  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
  481.58 +  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
  481.59 +  STDMETHOD(SetInStream)(ISequentialInStream *inStream);
  481.60 +  STDMETHOD(ReleaseInStream)();
  481.61 +  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);
  481.62 +
  481.63 +  #ifndef NO_READ_FROM_CODER
  481.64 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
  481.65 +  #endif
  481.66 +
  481.67 +  bool FinishStream;
  481.68 +
  481.69 +  CDecoder();
  481.70 +  virtual ~CDecoder();
  481.71 +
  481.72 +};
  481.73 +
  481.74 +}}
  481.75 +
  481.76 +#endif
   482.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   482.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/LzmaRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   482.3 @@ -0,0 +1,20 @@
   482.4 +// LzmaRegister.cpp
   482.5 +
   482.6 +#include "StdAfx.h"
   482.7 +
   482.8 +#include "../Common/RegisterCodec.h"
   482.9 +
  482.10 +#include "LzmaDecoder.h"
  482.11 +
  482.12 +static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CDecoder); }
  482.13 +#ifndef EXTRACT_ONLY
  482.14 +#include "LzmaEncoder.h"
  482.15 +static void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CEncoder);  }
  482.16 +#else
  482.17 +#define CreateCodecOut 0
  482.18 +#endif
  482.19 +
  482.20 +static CCodecInfo g_CodecInfo =
  482.21 +  { CreateCodec, CreateCodecOut, 0x030101, L"LZMA", 1, false };
  482.22 +
  482.23 +REGISTER_CODEC(LZMA)
   483.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   483.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/Mtf8.h	Sat Mar 03 10:31:27 2012 -0600
   483.3 @@ -0,0 +1,196 @@
   483.4 +// Mtf8.h
   483.5 +
   483.6 +#ifndef __COMPRESS_MTF8_H
   483.7 +#define __COMPRESS_MTF8_H
   483.8 +
   483.9 +#include "../../Common/Types.h"
  483.10 +
  483.11 +namespace NCompress {
  483.12 +
  483.13 +struct CMtf8Encoder
  483.14 +{
  483.15 +  Byte Buf[256];
  483.16 +
  483.17 +  int FindAndMove(Byte v)
  483.18 +  {
  483.19 +    int pos;
  483.20 +    for (pos = 0; Buf[pos] != v; pos++);
  483.21 +    int resPos = pos;
  483.22 +    for (; pos >= 8; pos -= 8)
  483.23 +    {
  483.24 +      Buf[pos] = Buf[pos - 1];
  483.25 +      Buf[pos - 1] = Buf[pos - 2];
  483.26 +      Buf[pos - 2] = Buf[pos - 3];
  483.27 +      Buf[pos - 3] = Buf[pos - 4];
  483.28 +      Buf[pos - 4] = Buf[pos - 5];
  483.29 +      Buf[pos - 5] = Buf[pos - 6];
  483.30 +      Buf[pos - 6] = Buf[pos - 7];
  483.31 +      Buf[pos - 7] = Buf[pos - 8];
  483.32 +    }
  483.33 +    for (; pos > 0; pos--)
  483.34 +      Buf[pos] = Buf[pos - 1];
  483.35 +    Buf[0] = v;
  483.36 +    return resPos;
  483.37 +  }
  483.38 +};
  483.39 +
  483.40 +/*
  483.41 +struct CMtf8Decoder
  483.42 +{
  483.43 +  Byte Buf[256];
  483.44 +
  483.45 +  void Init(int) {};
  483.46 +  Byte GetHead() const { return Buf[0]; }
  483.47 +  Byte GetAndMove(int pos)
  483.48 +  {
  483.49 +    Byte res = Buf[pos];
  483.50 +    for (; pos >= 8; pos -= 8)
  483.51 +    {
  483.52 +      Buf[pos] = Buf[pos - 1];
  483.53 +      Buf[pos - 1] = Buf[pos - 2];
  483.54 +      Buf[pos - 2] = Buf[pos - 3];
  483.55 +      Buf[pos - 3] = Buf[pos - 4];
  483.56 +      Buf[pos - 4] = Buf[pos - 5];
  483.57 +      Buf[pos - 5] = Buf[pos - 6];
  483.58 +      Buf[pos - 6] = Buf[pos - 7];
  483.59 +      Buf[pos - 7] = Buf[pos - 8];
  483.60 +    }
  483.61 +    for (; pos > 0; pos--)
  483.62 +      Buf[pos] = Buf[pos - 1];
  483.63 +    Buf[0] = res;
  483.64 +    return res;
  483.65 +  }
  483.66 +};
  483.67 +*/
  483.68 +
  483.69 +#ifdef _WIN64
  483.70 +#define MODE_64BIT
  483.71 +#endif
  483.72 +
  483.73 +#ifdef MODE_64BIT
  483.74 +typedef UInt64 CMtfVar;
  483.75 +#define MTF_MOVS 3
  483.76 +#else
  483.77 +typedef UInt32 CMtfVar;
  483.78 +#define MTF_MOVS 2
  483.79 +#endif
  483.80 +
  483.81 +#define MTF_MASK ((1 << MTF_MOVS) - 1)
  483.82 +
  483.83 +
  483.84 +struct CMtf8Decoder
  483.85 +{
  483.86 +  CMtfVar Buf[256 >> MTF_MOVS];
  483.87 +
  483.88 +  void StartInit() { memset(Buf, 0, sizeof(Buf)); }
  483.89 +  void Add(unsigned int pos, Byte val) { Buf[pos >> MTF_MOVS] |= ((CMtfVar)val << ((pos & MTF_MASK) << 3));  }
  483.90 +  Byte GetHead() const { return (Byte)Buf[0]; }
  483.91 +  Byte GetAndMove(unsigned int pos)
  483.92 +  {
  483.93 +    UInt32 lim = ((UInt32)pos >> MTF_MOVS);
  483.94 +    pos = (pos & MTF_MASK) << 3;
  483.95 +    CMtfVar prev = (Buf[lim] >> pos) & 0xFF;
  483.96 +
  483.97 +    UInt32 i = 0;
  483.98 +    if ((lim & 1) != 0)
  483.99 +    {
 483.100 +      CMtfVar next = Buf[0];
 483.101 +      Buf[0] = (next << 8) | prev;
 483.102 +      prev = (next >> (MTF_MASK << 3));
 483.103 +      i = 1;
 483.104 +      lim -= 1;
 483.105 +    }
 483.106 +    for (; i < lim; i += 2)
 483.107 +    {
 483.108 +      CMtfVar next = Buf[i];
 483.109 +      Buf[i] = (next << 8) | prev;
 483.110 +      prev = (next >> (MTF_MASK << 3));
 483.111 +      next = Buf[i + 1];
 483.112 +      Buf[i + 1] = (next << 8) | prev;
 483.113 +      prev = (next >> (MTF_MASK << 3));
 483.114 +    }
 483.115 +    CMtfVar next = Buf[i];
 483.116 +    CMtfVar mask = (((CMtfVar)0x100 << pos) - 1);
 483.117 +    Buf[i] = (next & ~mask) | (((next << 8) | prev) & mask);
 483.118 +    return (Byte)Buf[0];
 483.119 +  }
 483.120 +};
 483.121 +
 483.122 +/*
 483.123 +const int kSmallSize = 64;
 483.124 +class CMtf8Decoder
 483.125 +{
 483.126 +  Byte SmallBuffer[kSmallSize];
 483.127 +  int SmallSize;
 483.128 +  Byte Counts[16];
 483.129 +  int Size;
 483.130 +public:
 483.131 +  Byte Buf[256];
 483.132 +
 483.133 +  Byte GetHead() const
 483.134 +  {
 483.135 +    if (SmallSize > 0)
 483.136 +      return SmallBuffer[kSmallSize - SmallSize];
 483.137 +    return Buf[0];
 483.138 +  }
 483.139 +
 483.140 +  void Init(int size)
 483.141 +  {
 483.142 +    Size = size;
 483.143 +    SmallSize = 0;
 483.144 +    for (int i = 0; i < 16; i++)
 483.145 +    {
 483.146 +      Counts[i] = ((size >= 16) ? 16 : size);
 483.147 +      size -= Counts[i];
 483.148 +    }
 483.149 +  }
 483.150 +
 483.151 +  Byte GetAndMove(int pos)
 483.152 +  {
 483.153 +    if (pos < SmallSize)
 483.154 +    {
 483.155 +      Byte *p = SmallBuffer + kSmallSize - SmallSize;
 483.156 +      Byte res = p[pos];
 483.157 +      for (; pos > 0; pos--)
 483.158 +        p[pos] = p[pos - 1];
 483.159 +      SmallBuffer[kSmallSize - SmallSize] = res;
 483.160 +      return res;
 483.161 +    }
 483.162 +    if (SmallSize == kSmallSize)
 483.163 +    {
 483.164 +      int i = Size - 1;
 483.165 +      int g = 16;
 483.166 +      do
 483.167 +      {
 483.168 +        g--;
 483.169 +        int offset = (g << 4);
 483.170 +        for (int t = Counts[g] - 1; t >= 0; t--, i--)
 483.171 +          Buf[i] = Buf[offset + t];
 483.172 +      }
 483.173 +      while(g != 0);
 483.174 +      
 483.175 +      for (i = kSmallSize - 1; i >= 0; i--)
 483.176 +        Buf[i] = SmallBuffer[i];
 483.177 +      Init(Size);
 483.178 +    }
 483.179 +    pos -= SmallSize;
 483.180 +    int g;
 483.181 +    for (g = 0; pos >= Counts[g]; g++)
 483.182 +      pos -= Counts[g];
 483.183 +    int offset = (g << 4);
 483.184 +    Byte res = Buf[offset + pos];
 483.185 +    for (pos; pos < 16 - 1; pos++)
 483.186 +      Buf[offset + pos] = Buf[offset + pos + 1];
 483.187 +    
 483.188 +    SmallSize++;
 483.189 +    SmallBuffer[kSmallSize - SmallSize] = res;
 483.190 +
 483.191 +    Counts[g]--;
 483.192 +    return res;
 483.193 +  }
 483.194 +};
 483.195 +*/
 483.196 +
 483.197 +}
 483.198 +
 483.199 +#endif
   484.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   484.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/PpmdContext.h	Sat Mar 03 10:31:27 2012 -0600
   484.3 @@ -0,0 +1,489 @@
   484.4 +// PpmdContext.h
   484.5 +// This code is based on Dmitry Shkarin's PPMdH code
   484.6 +
   484.7 +#ifndef __COMPRESS_PPMD_CONTEXT_H
   484.8 +#define __COMPRESS_PPMD_CONTEXT_H
   484.9 +
  484.10 +#include "../../Common/Types.h"
  484.11 +
  484.12 +#include "PpmdSubAlloc.h"
  484.13 +#include "RangeCoder.h"
  484.14 +
  484.15 +namespace NCompress {
  484.16 +namespace NPpmd {
  484.17 +
  484.18 +const int INT_BITS=7, PERIOD_BITS=7, TOT_BITS=INT_BITS+PERIOD_BITS,
  484.19 +        INTERVAL=1 << INT_BITS, BIN_SCALE=1 << TOT_BITS, MAX_FREQ=124;
  484.20 +
  484.21 +struct SEE2_CONTEXT
  484.22 +{
  484.23 +  // SEE-contexts for PPM-contexts with masked symbols
  484.24 +  UInt16 Summ;
  484.25 +  Byte Shift, Count;
  484.26 +  void init(int InitVal) { Summ = (UInt16)(InitVal << (Shift=PERIOD_BITS-4)); Count=4; }
  484.27 +  unsigned int getMean()
  484.28 +  {
  484.29 +    unsigned int RetVal=(Summ >> Shift);
  484.30 +    Summ = (UInt16)(Summ - RetVal);
  484.31 +    return RetVal+(RetVal == 0);
  484.32 +  }
  484.33 +  void update()
  484.34 +  {
  484.35 +    if (Shift < PERIOD_BITS && --Count == 0)
  484.36 +    {
  484.37 +      Summ <<= 1;
  484.38 +      Count = (Byte)(3 << Shift++);
  484.39 +    }
  484.40 +  }
  484.41 +};
  484.42 +
  484.43 +struct PPM_CONTEXT
  484.44 +{
  484.45 +  UInt16 NumStats; // sizeof(UInt16) > sizeof(Byte)
  484.46 +  UInt16 SummFreq;
  484.47 +  
  484.48 +  struct STATE
  484.49 +  {
  484.50 +    Byte Symbol, Freq;
  484.51 +    UInt16 SuccessorLow;
  484.52 +    UInt16 SuccessorHigh;
  484.53 +
  484.54 +    UInt32 GetSuccessor() const { return SuccessorLow | ((UInt32)SuccessorHigh << 16); }
  484.55 +    void SetSuccessor(UInt32 v)
  484.56 +    {
  484.57 +      SuccessorLow = (UInt16)(v & 0xFFFF);
  484.58 +      SuccessorHigh = (UInt16)((v >> 16) & 0xFFFF);
  484.59 +    }
  484.60 +  };
  484.61 +  
  484.62 +  UInt32 Stats;
  484.63 +  UInt32 Suffix;
  484.64 +  
  484.65 +  PPM_CONTEXT* createChild(CSubAllocator &subAllocator, STATE* pStats, STATE& FirstState)
  484.66 +  {
  484.67 +    PPM_CONTEXT* pc = (PPM_CONTEXT*) subAllocator.AllocContext();
  484.68 +    if (pc)
  484.69 +    {
  484.70 +      pc->NumStats = 1;
  484.71 +      pc->oneState() = FirstState;
  484.72 +      pc->Suffix = subAllocator.GetOffset(this);
  484.73 +      pStats->SetSuccessor(subAllocator.GetOffsetNoCheck(pc));
  484.74 +    }
  484.75 +    return pc;
  484.76 +  }
  484.77 +
  484.78 +  STATE& oneState() const { return (STATE&) SummFreq; }
  484.79 +};
  484.80 +
  484.81 +/////////////////////////////////
  484.82 +
  484.83 +const UInt16 InitBinEsc[] =
  484.84 +  {0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051};
  484.85 +
  484.86 +struct CInfo
  484.87 +{
  484.88 +  CSubAllocator SubAllocator;
  484.89 +  SEE2_CONTEXT SEE2Cont[25][16], DummySEE2Cont;
  484.90 +  PPM_CONTEXT * MinContext, * MaxContext;
  484.91 +
  484.92 +  PPM_CONTEXT::STATE* FoundState;      // found next state transition
  484.93 +  int NumMasked, InitEsc, OrderFall, RunLength, InitRL, MaxOrder;
  484.94 +  Byte CharMask[256], NS2Indx[256], NS2BSIndx[256], HB2Flag[256];
  484.95 +  Byte EscCount, PrintCount, PrevSuccess, HiBitsFlag;
  484.96 +  UInt16 BinSumm[128][64];               // binary SEE-contexts
  484.97 +
  484.98 +  UInt16 &GetBinSumm(const PPM_CONTEXT::STATE &rs, int numStates)
  484.99 +  {
 484.100 +    HiBitsFlag = HB2Flag[FoundState->Symbol];
 484.101 +    return BinSumm[rs.Freq - 1][
 484.102 +         PrevSuccess + NS2BSIndx[numStates - 1] +
 484.103 +         HiBitsFlag + 2 * HB2Flag[rs.Symbol] +
 484.104 +         ((RunLength >> 26) & 0x20)];
 484.105 +  }
 484.106 +
 484.107 +  PPM_CONTEXT *GetContext(UInt32 offset) const { return (PPM_CONTEXT *)SubAllocator.GetPtr(offset); }
 484.108 +  PPM_CONTEXT *GetContextNoCheck(UInt32 offset) const { return (PPM_CONTEXT *)SubAllocator.GetPtrNoCheck(offset); }
 484.109 +  PPM_CONTEXT::STATE *GetState(UInt32 offset) const { return (PPM_CONTEXT::STATE *)SubAllocator.GetPtr(offset); }
 484.110 +  PPM_CONTEXT::STATE *GetStateNoCheck(UInt32 offset) const { return (PPM_CONTEXT::STATE *)SubAllocator.GetPtr(offset); }
 484.111 +
 484.112 +  void RestartModelRare()
 484.113 +  {
 484.114 +    int i, k, m;
 484.115 +    memset(CharMask,0,sizeof(CharMask));
 484.116 +    SubAllocator.InitSubAllocator();
 484.117 +    InitRL = -((MaxOrder < 12) ? MaxOrder : 12) - 1;
 484.118 +    MinContext = MaxContext = (PPM_CONTEXT*) SubAllocator.AllocContext();
 484.119 +    MinContext->Suffix = 0;
 484.120 +    OrderFall = MaxOrder;
 484.121 +    MinContext->SummFreq = (UInt16)((MinContext->NumStats = 256) + 1);
 484.122 +    FoundState = (PPM_CONTEXT::STATE*)SubAllocator.AllocUnits(256 / 2);
 484.123 +    MinContext->Stats = SubAllocator.GetOffsetNoCheck(FoundState);
 484.124 +    PrevSuccess = 0;
 484.125 +    for (RunLength = InitRL, i = 0; i < 256; i++)
 484.126 +    {
 484.127 +      PPM_CONTEXT::STATE &state = FoundState[i];
 484.128 +      state.Symbol = (Byte)i;
 484.129 +      state.Freq = 1;
 484.130 +      state.SetSuccessor(0);
 484.131 +    }
 484.132 +    for (i = 0; i < 128; i++)
 484.133 +        for (k = 0; k < 8; k++)
 484.134 +            for ( m=0; m < 64; m += 8)
 484.135 +                BinSumm[i][k + m] = (UInt16)(BIN_SCALE - InitBinEsc[k] / (i + 2));
 484.136 +    for (i = 0; i < 25; i++)
 484.137 +        for (k = 0; k < 16; k++)
 484.138 +            SEE2Cont[i][k].init(5*i+10);
 484.139 +  }
 484.140 +
 484.141 +  void StartModelRare(int maxOrder)
 484.142 +  {
 484.143 +    int i, k, m ,Step;
 484.144 +    EscCount=PrintCount=1;
 484.145 +    if (maxOrder < 2)
 484.146 +    {
 484.147 +        memset(CharMask,0,sizeof(CharMask));
 484.148 +        OrderFall = MaxOrder;
 484.149 +        MinContext = MaxContext;
 484.150 +        while (MinContext->Suffix != 0)
 484.151 +        {
 484.152 +          MinContext = GetContextNoCheck(MinContext->Suffix);
 484.153 +          OrderFall--;
 484.154 +        }
 484.155 +        FoundState = GetState(MinContext->Stats);
 484.156 +        MinContext = MaxContext;
 484.157 +    }
 484.158 +    else
 484.159 +    {
 484.160 +        MaxOrder = maxOrder;
 484.161 +        RestartModelRare();
 484.162 +        NS2BSIndx[0] = 2 * 0;
 484.163 +        NS2BSIndx[1] = 2 * 1;
 484.164 +        memset(NS2BSIndx + 2, 2 * 2, 9);
 484.165 +        memset(NS2BSIndx + 11, 2 * 3, 256 - 11);
 484.166 +        for (i = 0; i < 3; i++)
 484.167 +          NS2Indx[i] = (Byte)i;
 484.168 +        for (m = i, k = Step = 1; i < 256; i++)
 484.169 +        {
 484.170 +            NS2Indx[i] = (Byte)m;
 484.171 +            if ( !--k )
 484.172 +            {
 484.173 +              k = ++Step;
 484.174 +              m++;
 484.175 +            }
 484.176 +        }
 484.177 +        memset(HB2Flag, 0, 0x40);
 484.178 +        memset(HB2Flag + 0x40, 0x08, 0x100 - 0x40);
 484.179 +        DummySEE2Cont.Shift = PERIOD_BITS;
 484.180 +    }
 484.181 +  }
 484.182 +
 484.183 +  PPM_CONTEXT* CreateSuccessors(bool skip, PPM_CONTEXT::STATE* p1)
 484.184 +  {
 484.185 +    // static UpState declaration bypasses IntelC bug
 484.186 +    // static PPM_CONTEXT::STATE UpState;
 484.187 +    PPM_CONTEXT::STATE UpState;
 484.188 +
 484.189 +    PPM_CONTEXT *pc = MinContext;
 484.190 +    PPM_CONTEXT *UpBranch = GetContext(FoundState->GetSuccessor());
 484.191 +    PPM_CONTEXT::STATE * p, * ps[MAX_O], ** pps = ps;
 484.192 +    if ( !skip )
 484.193 +    {
 484.194 +        *pps++ = FoundState;
 484.195 +        if ( !pc->Suffix )
 484.196 +          goto NO_LOOP;
 484.197 +    }
 484.198 +    if ( p1 )
 484.199 +    {
 484.200 +        p = p1;
 484.201 +        pc = GetContext(pc->Suffix);
 484.202 +        goto LOOP_ENTRY;
 484.203 +    }
 484.204 +    do
 484.205 +    {
 484.206 +        pc = GetContext(pc->Suffix);
 484.207 +        if (pc->NumStats != 1)
 484.208 +        {
 484.209 +            if ((p = GetStateNoCheck(pc->Stats))->Symbol != FoundState->Symbol)
 484.210 +                do { p++; } while (p->Symbol != FoundState->Symbol);
 484.211 +        }
 484.212 +        else
 484.213 +          p = &(pc->oneState());
 484.214 +LOOP_ENTRY:
 484.215 +        if (GetContext(p->GetSuccessor()) != UpBranch)
 484.216 +        {
 484.217 +            pc = GetContext(p->GetSuccessor());
 484.218 +            break;
 484.219 +        }
 484.220 +        *pps++ = p;
 484.221 +    }
 484.222 +    while ( pc->Suffix );
 484.223 +NO_LOOP:
 484.224 +    if (pps == ps)
 484.225 +      return pc;
 484.226 +    UpState.Symbol = *(Byte*) UpBranch;
 484.227 +    UpState.SetSuccessor(SubAllocator.GetOffset(UpBranch) + 1);
 484.228 +    if (pc->NumStats != 1)
 484.229 +    {
 484.230 +        if ((p = GetStateNoCheck(pc->Stats))->Symbol != UpState.Symbol)
 484.231 +                do { p++; } while (p->Symbol != UpState.Symbol);
 484.232 +        unsigned int cf = p->Freq-1;
 484.233 +        unsigned int s0 = pc->SummFreq - pc->NumStats - cf;
 484.234 +        UpState.Freq = (Byte)(1 + ((2 * cf <= s0) ? (5 * cf > s0) :
 484.235 +            ((2 * cf + 3 * s0 - 1) / (2 * s0))));
 484.236 +    }
 484.237 +    else
 484.238 +      UpState.Freq = pc->oneState().Freq;
 484.239 +    do
 484.240 +    {
 484.241 +        pc = pc->createChild(SubAllocator, *--pps, UpState);
 484.242 +        if ( !pc )
 484.243 +          return NULL;
 484.244 +    }
 484.245 +    while (pps != ps);
 484.246 +    return pc;
 484.247 +  }
 484.248 +
 484.249 +  void UpdateModel()
 484.250 +  {
 484.251 +    PPM_CONTEXT::STATE fs = *FoundState, * p = NULL;
 484.252 +    PPM_CONTEXT* pc, * Successor;
 484.253 +    unsigned int ns1, ns, cf, sf, s0;
 484.254 +    if (fs.Freq < MAX_FREQ / 4 && MinContext->Suffix != 0)
 484.255 +    {
 484.256 +        pc = GetContextNoCheck(MinContext->Suffix);
 484.257 +      
 484.258 +        if (pc->NumStats != 1)
 484.259 +        {
 484.260 +            if ((p = GetStateNoCheck(pc->Stats))->Symbol != fs.Symbol)
 484.261 +            {
 484.262 +                do { p++; } while (p->Symbol != fs.Symbol);
 484.263 +                if (p[0].Freq >= p[-1].Freq)
 484.264 +                {
 484.265 +                    _PPMD_SWAP(p[0],p[-1]);
 484.266 +                    p--;
 484.267 +                }
 484.268 +            }
 484.269 +            if (p->Freq < MAX_FREQ-9)
 484.270 +            {
 484.271 +                p->Freq += 2;
 484.272 +                pc->SummFreq += 2;
 484.273 +            }
 484.274 +        }
 484.275 +        else
 484.276 +        {
 484.277 +            p = &(pc->oneState());
 484.278 +            p->Freq = (Byte)(p->Freq + ((p->Freq < 32) ? 1 : 0));
 484.279 +        }
 484.280 +    }
 484.281 +    if ( !OrderFall )
 484.282 +    {
 484.283 +        MinContext = MaxContext = CreateSuccessors(true, p);
 484.284 +        FoundState->SetSuccessor(SubAllocator.GetOffset(MinContext));
 484.285 +        if (MinContext == 0)
 484.286 +          goto RESTART_MODEL;
 484.287 +        return;
 484.288 +    }
 484.289 +    *SubAllocator.pText++ = fs.Symbol;
 484.290 +    Successor = (PPM_CONTEXT*) SubAllocator.pText;
 484.291 +    if (SubAllocator.pText >= SubAllocator.UnitsStart)
 484.292 +      goto RESTART_MODEL;
 484.293 +    if (fs.GetSuccessor() != 0)
 484.294 +    {
 484.295 +        if ((Byte *)GetContext(fs.GetSuccessor()) <= SubAllocator.pText)
 484.296 +        {
 484.297 +          PPM_CONTEXT* cs = CreateSuccessors(false, p);
 484.298 +          fs.SetSuccessor(SubAllocator.GetOffset(cs));
 484.299 +          if (cs == NULL)
 484.300 +            goto RESTART_MODEL;
 484.301 +        }
 484.302 +        if ( !--OrderFall )
 484.303 +        {
 484.304 +            Successor = GetContext(fs.GetSuccessor());
 484.305 +            SubAllocator.pText -= (MaxContext != MinContext);
 484.306 +        }
 484.307 +    }
 484.308 +    else
 484.309 +    {
 484.310 +        FoundState->SetSuccessor(SubAllocator.GetOffsetNoCheck(Successor));
 484.311 +        fs.SetSuccessor(SubAllocator.GetOffsetNoCheck(MinContext));
 484.312 +    }
 484.313 +    s0 = MinContext->SummFreq - (ns = MinContext->NumStats) - (fs.Freq - 1);
 484.314 +    for (pc = MaxContext; pc != MinContext; pc = GetContext(pc->Suffix))
 484.315 +    {
 484.316 +        if ((ns1 = pc->NumStats) != 1)
 484.317 +        {
 484.318 +            if ((ns1 & 1) == 0)
 484.319 +            {
 484.320 +                void *ppp = SubAllocator.ExpandUnits(GetState(pc->Stats), ns1 >> 1);
 484.321 +                pc->Stats = SubAllocator.GetOffset(ppp);
 484.322 +                if (!ppp)
 484.323 +                  goto RESTART_MODEL;
 484.324 +            }
 484.325 +            pc->SummFreq = (UInt16)(pc->SummFreq + (2 * ns1 < ns) + 2 * ((4 * ns1 <= ns) &
 484.326 +                    (pc->SummFreq <= 8 * ns1)));
 484.327 +        }
 484.328 +        else
 484.329 +        {
 484.330 +            p = (PPM_CONTEXT::STATE*) SubAllocator.AllocUnits(1);
 484.331 +            if ( !p )
 484.332 +              goto RESTART_MODEL;
 484.333 +            *p = pc->oneState();
 484.334 +            pc->Stats = SubAllocator.GetOffsetNoCheck(p);
 484.335 +            if (p->Freq < MAX_FREQ / 4 - 1)
 484.336 +              p->Freq <<= 1;
 484.337 +            else
 484.338 +              p->Freq  = MAX_FREQ - 4;
 484.339 +            pc->SummFreq = (UInt16)(p->Freq + InitEsc + (ns > 3));
 484.340 +        }
 484.341 +        cf = 2 * fs.Freq * (pc->SummFreq+6);
 484.342 +        sf = s0 + pc->SummFreq;
 484.343 +        if (cf < 6 * sf)
 484.344 +        {
 484.345 +            cf = 1 + (cf > sf)+(cf >= 4 * sf);
 484.346 +            pc->SummFreq += 3;
 484.347 +        }
 484.348 +        else
 484.349 +        {
 484.350 +            cf = 4 + (cf >= 9 * sf) + (cf >= 12 * sf) + (cf >= 15 * sf);
 484.351 +            pc->SummFreq = (UInt16)(pc->SummFreq + cf);
 484.352 +        }
 484.353 +        p = GetState(pc->Stats) + ns1;
 484.354 +        p->SetSuccessor(SubAllocator.GetOffset(Successor));
 484.355 +        p->Symbol = fs.Symbol;
 484.356 +        p->Freq = (Byte)cf;
 484.357 +        pc->NumStats = (UInt16)++ns1;
 484.358 +    }
 484.359 +    MaxContext = MinContext = GetContext(fs.GetSuccessor());
 484.360 +    return;
 484.361 +RESTART_MODEL:
 484.362 +    RestartModelRare();
 484.363 +    EscCount = 0;
 484.364 +    PrintCount = 0xFF;
 484.365 +  }
 484.366 +
 484.367 +  void ClearMask()
 484.368 +  {
 484.369 +    EscCount = 1;
 484.370 +    memset(CharMask, 0, sizeof(CharMask));
 484.371 +    // if (++PrintCount == 0)
 484.372 +    //   PrintInfo(DecodedFile,EncodedFile);
 484.373 +  }
 484.374 +
 484.375 +  void update1(PPM_CONTEXT::STATE* p)
 484.376 +  {
 484.377 +    (FoundState = p)->Freq += 4;
 484.378 +    MinContext->SummFreq += 4;
 484.379 +    if (p[0].Freq > p[-1].Freq)
 484.380 +    {
 484.381 +        _PPMD_SWAP(p[0],p[-1]);
 484.382 +        FoundState = --p;
 484.383 +        if (p->Freq > MAX_FREQ)
 484.384 +          rescale();
 484.385 +    }
 484.386 +  }
 484.387 +
 484.388 +
 484.389 +  void update2(PPM_CONTEXT::STATE* p)
 484.390 +  {
 484.391 +    (FoundState = p)->Freq += 4;
 484.392 +    MinContext->SummFreq += 4;
 484.393 +    if (p->Freq > MAX_FREQ)
 484.394 +      rescale();
 484.395 +    EscCount++;
 484.396 +    RunLength = InitRL;
 484.397 +  }
 484.398 +  
 484.399 +  SEE2_CONTEXT* makeEscFreq2(int Diff, UInt32 &scale)
 484.400 +  {
 484.401 +    SEE2_CONTEXT* psee2c;
 484.402 +    if (MinContext->NumStats != 256)
 484.403 +    {
 484.404 +      psee2c = SEE2Cont[NS2Indx[Diff-1]] +
 484.405 +        (Diff < (GetContext(MinContext->Suffix))->NumStats - MinContext->NumStats) +
 484.406 +        2 * (MinContext->SummFreq < 11 * MinContext->NumStats) +
 484.407 +        4 * (NumMasked > Diff) +
 484.408 +        HiBitsFlag;
 484.409 +      scale = psee2c->getMean();
 484.410 +    }
 484.411 +    else
 484.412 +    {
 484.413 +      psee2c = &DummySEE2Cont;
 484.414 +      scale = 1;
 484.415 +    }
 484.416 +    return psee2c;
 484.417 +  }
 484.418 +
 484.419 +
 484.420 +
 484.421 +  void rescale()
 484.422 +  {
 484.423 +    int OldNS = MinContext->NumStats, i = MinContext->NumStats - 1, Adder, EscFreq;
 484.424 +    PPM_CONTEXT::STATE* p1, * p;
 484.425 +    PPM_CONTEXT::STATE *stats = GetStateNoCheck(MinContext->Stats);
 484.426 +    for (p = FoundState; p != stats; p--)
 484.427 +      _PPMD_SWAP(p[0], p[-1]);
 484.428 +    stats->Freq += 4;
 484.429 +    MinContext->SummFreq += 4;
 484.430 +    EscFreq = MinContext->SummFreq - p->Freq;
 484.431 +    Adder = (OrderFall != 0);
 484.432 +    p->Freq = (Byte)((p->Freq + Adder) >> 1);
 484.433 +    MinContext->SummFreq = p->Freq;
 484.434 +    do
 484.435 +    {
 484.436 +        EscFreq -= (++p)->Freq;
 484.437 +        p->Freq = (Byte)((p->Freq + Adder) >> 1);
 484.438 +        MinContext->SummFreq = (UInt16)(MinContext->SummFreq + p->Freq);
 484.439 +        if (p[0].Freq > p[-1].Freq)
 484.440 +        {
 484.441 +            PPM_CONTEXT::STATE tmp = *(p1 = p);
 484.442 +            do
 484.443 +            {
 484.444 +              p1[0] = p1[-1];
 484.445 +            }
 484.446 +            while (--p1 != stats && tmp.Freq > p1[-1].Freq);
 484.447 +            *p1 = tmp;
 484.448 +        }
 484.449 +    }
 484.450 +    while ( --i );
 484.451 +    if (p->Freq == 0)
 484.452 +    {
 484.453 +        do { i++; } while ((--p)->Freq == 0);
 484.454 +        EscFreq += i;
 484.455 +        MinContext->NumStats = (UInt16)(MinContext->NumStats - i);
 484.456 +        if (MinContext->NumStats == 1)
 484.457 +        {
 484.458 +            PPM_CONTEXT::STATE tmp = *stats;
 484.459 +            do { tmp.Freq = (Byte)(tmp.Freq - (tmp.Freq >> 1)); EscFreq >>= 1; } while (EscFreq > 1);
 484.460 +            SubAllocator.FreeUnits(stats, (OldNS+1) >> 1);
 484.461 +            *(FoundState = &MinContext->oneState()) = tmp;  return;
 484.462 +        }
 484.463 +    }
 484.464 +    EscFreq -= (EscFreq >> 1);
 484.465 +    MinContext->SummFreq = (UInt16)(MinContext->SummFreq + EscFreq);
 484.466 +    int n0 = (OldNS+1) >> 1, n1 = (MinContext->NumStats + 1) >> 1;
 484.467 +    if (n0 != n1)
 484.468 +      MinContext->Stats = SubAllocator.GetOffset(SubAllocator.ShrinkUnits(stats, n0, n1));
 484.469 +    FoundState = GetState(MinContext->Stats);
 484.470 +  }
 484.471 +
 484.472 +  void NextContext()
 484.473 +  {
 484.474 +    PPM_CONTEXT *c = GetContext(FoundState->GetSuccessor());
 484.475 +    if (!OrderFall && (Byte *)c > SubAllocator.pText)
 484.476 +      MinContext = MaxContext = c;
 484.477 +    else
 484.478 +    {
 484.479 +      UpdateModel();
 484.480 +      if (EscCount == 0)
 484.481 +        ClearMask();
 484.482 +    }
 484.483 +  }
 484.484 +};
 484.485 +
 484.486 +// Tabulated escapes for exponential symbol distribution
 484.487 +const Byte ExpEscape[16]={ 25,14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 };
 484.488 +#define GET_MEAN(SUMM,SHIFT,ROUND) ((SUMM+(1 << (SHIFT-ROUND))) >> (SHIFT))
 484.489 +
 484.490 +}}
 484.491 +
 484.492 +#endif
   485.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   485.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/PpmdDecode.h	Sat Mar 03 10:31:27 2012 -0600
   485.3 @@ -0,0 +1,154 @@
   485.4 +// PpmdDecode.h
   485.5 +// This code is based on Dmitry Shkarin's PPMdH code
   485.6 +
   485.7 +#ifndef __COMPRESS_PPMD_DECODE_H
   485.8 +#define __COMPRESS_PPMD_DECODE_H
   485.9 +
  485.10 +#include "PpmdContext.h"
  485.11 +
  485.12 +namespace NCompress {
  485.13 +namespace NPpmd {
  485.14 +
  485.15 +class CRangeDecoderVirt
  485.16 +{
  485.17 +public:
  485.18 +  virtual UInt32 GetThreshold(UInt32 total) = 0;
  485.19 +  virtual void Decode(UInt32 start, UInt32 size) = 0;
  485.20 +  virtual UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits) = 0;
  485.21 +};
  485.22 +
  485.23 +typedef NRangeCoder::CDecoder CRangeDecoderMy;
  485.24 +
  485.25 +class CRangeDecoder:public CRangeDecoderVirt, public CRangeDecoderMy
  485.26 +{
  485.27 +  UInt32 GetThreshold(UInt32 total) { return CRangeDecoderMy::GetThreshold(total); }
  485.28 +  void Decode(UInt32 start, UInt32 size) { CRangeDecoderMy::Decode(start, size); }
  485.29 +  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits) { return CRangeDecoderMy::DecodeBit(size0, numTotalBits); }
  485.30 +};
  485.31 +
  485.32 +struct CDecodeInfo: public CInfo
  485.33 +{
  485.34 +  void DecodeBinSymbol(CRangeDecoderVirt *rangeDecoder)
  485.35 +  {
  485.36 +    PPM_CONTEXT::STATE& rs = MinContext->oneState();
  485.37 +    UInt16& bs = GetBinSumm(rs, GetContextNoCheck(MinContext->Suffix)->NumStats);
  485.38 +    if (rangeDecoder->DecodeBit(bs, TOT_BITS) == 0)
  485.39 +    {
  485.40 +      FoundState = &rs;
  485.41 +      rs.Freq = (Byte)(rs.Freq + (rs.Freq < 128 ? 1: 0));
  485.42 +      bs = (UInt16)(bs + INTERVAL - GET_MEAN(bs, PERIOD_BITS, 2));
  485.43 +      PrevSuccess = 1;
  485.44 +      RunLength++;
  485.45 +    }
  485.46 +    else
  485.47 +    {
  485.48 +      bs = (UInt16)(bs - GET_MEAN(bs, PERIOD_BITS, 2));
  485.49 +      InitEsc = ExpEscape[bs >> 10];
  485.50 +      NumMasked = 1;
  485.51 +      CharMask[rs.Symbol] = EscCount;
  485.52 +      PrevSuccess = 0;
  485.53 +      FoundState = NULL;
  485.54 +    }
  485.55 +  }
  485.56 +
  485.57 +  void DecodeSymbol1(CRangeDecoderVirt *rangeDecoder)
  485.58 +  {
  485.59 +    PPM_CONTEXT::STATE* p = GetStateNoCheck(MinContext->Stats);
  485.60 +    int i, count, hiCnt;
  485.61 +    if ((count = rangeDecoder->GetThreshold(MinContext->SummFreq)) < (hiCnt = p->Freq))
  485.62 +    {
  485.63 +      PrevSuccess = (2 * hiCnt > MinContext->SummFreq);
  485.64 +      RunLength += PrevSuccess;
  485.65 +      rangeDecoder->Decode(0, p->Freq); // MinContext->SummFreq);
  485.66 +      (FoundState = p)->Freq = (Byte)(hiCnt += 4);
  485.67 +      MinContext->SummFreq += 4;
  485.68 +      if (hiCnt > MAX_FREQ)
  485.69 +        rescale();
  485.70 +      return;
  485.71 +    }
  485.72 +    PrevSuccess = 0;
  485.73 +    i = MinContext->NumStats - 1;
  485.74 +    while ((hiCnt += (++p)->Freq) <= count)
  485.75 +      if (--i == 0)
  485.76 +      {
  485.77 +        HiBitsFlag = HB2Flag[FoundState->Symbol];
  485.78 +        rangeDecoder->Decode(hiCnt, MinContext->SummFreq - hiCnt); // , MinContext->SummFreq);
  485.79 +        CharMask[p->Symbol] = EscCount;
  485.80 +        i = (NumMasked = MinContext->NumStats)-1;
  485.81 +        FoundState = NULL;
  485.82 +        do { CharMask[(--p)->Symbol] = EscCount; } while ( --i );
  485.83 +        return;
  485.84 +      }
  485.85 +    rangeDecoder->Decode(hiCnt - p->Freq, p->Freq); // , MinContext->SummFreq);
  485.86 +    update1(p);
  485.87 +  }
  485.88 +
  485.89 +
  485.90 +  void DecodeSymbol2(CRangeDecoderVirt *rangeDecoder)
  485.91 +  {
  485.92 +    int count, hiCnt, i = MinContext->NumStats - NumMasked;
  485.93 +    UInt32 freqSum;
  485.94 +    SEE2_CONTEXT* psee2c = makeEscFreq2(i, freqSum);
  485.95 +    PPM_CONTEXT::STATE* ps[256], ** pps = ps, * p = GetStateNoCheck(MinContext->Stats)-1;
  485.96 +    hiCnt = 0;
  485.97 +    do
  485.98 +    {
  485.99 +      do { p++; } while (CharMask[p->Symbol] == EscCount);
 485.100 +      hiCnt += p->Freq;
 485.101 +      *pps++ = p;
 485.102 +    }
 485.103 +    while ( --i );
 485.104 +    
 485.105 +    freqSum += hiCnt;
 485.106 +    count = rangeDecoder->GetThreshold(freqSum);
 485.107 +    
 485.108 +    p = *(pps = ps);
 485.109 +    if (count < hiCnt)
 485.110 +    {
 485.111 +      hiCnt = 0;
 485.112 +      while ((hiCnt += p->Freq) <= count)
 485.113 +        p=*++pps;
 485.114 +      rangeDecoder->Decode(hiCnt - p->Freq, p->Freq); // , freqSum);
 485.115 +      
 485.116 +      psee2c->update();
 485.117 +      update2(p);
 485.118 +    }
 485.119 +    else
 485.120 +    {
 485.121 +      rangeDecoder->Decode(hiCnt, freqSum - hiCnt); // , freqSum);
 485.122 +      
 485.123 +      i = MinContext->NumStats - NumMasked;
 485.124 +      pps--;
 485.125 +      do { CharMask[(*++pps)->Symbol] = EscCount; } while ( --i );
 485.126 +      psee2c->Summ = (UInt16)(psee2c->Summ + freqSum);
 485.127 +      NumMasked = MinContext->NumStats;
 485.128 +    }
 485.129 +  }
 485.130 +
 485.131 +  int DecodeSymbol(CRangeDecoderVirt *rangeDecoder)
 485.132 +  {
 485.133 +    if (MinContext->NumStats != 1)
 485.134 +      DecodeSymbol1(rangeDecoder);
 485.135 +    else
 485.136 +      DecodeBinSymbol(rangeDecoder);
 485.137 +    while ( !FoundState )
 485.138 +    {
 485.139 +      do
 485.140 +      {
 485.141 +        OrderFall++;
 485.142 +        MinContext = GetContext(MinContext->Suffix);
 485.143 +        if (MinContext == 0)
 485.144 +          return -1;
 485.145 +      }
 485.146 +      while (MinContext->NumStats == NumMasked);
 485.147 +      DecodeSymbol2(rangeDecoder);
 485.148 +    }
 485.149 +    Byte symbol = FoundState->Symbol;
 485.150 +    NextContext();
 485.151 +    return symbol;
 485.152 +  }
 485.153 +};
 485.154 +
 485.155 +}}
 485.156 +
 485.157 +#endif
   486.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   486.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/PpmdDecoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   486.3 @@ -0,0 +1,182 @@
   486.4 +// PpmdDecoder.cpp
   486.5 +
   486.6 +#include "StdAfx.h"
   486.7 +
   486.8 +#include "Common/Defs.h"
   486.9 +#include "Windows/Defs.h"
  486.10 +
  486.11 +#include "PpmdDecoder.h"
  486.12 +
  486.13 +namespace NCompress {
  486.14 +namespace NPpmd {
  486.15 +
  486.16 +const int kLenIdFinished = -1;
  486.17 +const int kLenIdNeedInit = -2;
  486.18 +
  486.19 +STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *properties, UInt32 size)
  486.20 +{
  486.21 +  if (size < 5)
  486.22 +    return E_INVALIDARG;
  486.23 +  _order = properties[0];
  486.24 +  _usedMemorySize = 0;
  486.25 +  for (int i = 0; i < 4; i++)
  486.26 +    _usedMemorySize += ((UInt32)(properties[1 + i])) << (i * 8);
  486.27 +
  486.28 +  if (_usedMemorySize > kMaxMemBlockSize)
  486.29 +    return E_NOTIMPL;
  486.30 +
  486.31 +  if (!_rangeDecoder.Create(1 << 20))
  486.32 +    return E_OUTOFMEMORY;
  486.33 +  if (!_info.SubAllocator.StartSubAllocator(_usedMemorySize))
  486.34 +    return E_OUTOFMEMORY;
  486.35 +
  486.36 +  return S_OK;
  486.37 +}
  486.38 +
  486.39 +class CDecoderFlusher
  486.40 +{
  486.41 +  CDecoder *_coder;
  486.42 +public:
  486.43 +  bool NeedFlush;
  486.44 +  CDecoderFlusher(CDecoder *coder): _coder(coder), NeedFlush(true) {}
  486.45 +  ~CDecoderFlusher()
  486.46 +  {
  486.47 +    if (NeedFlush)
  486.48 +      _coder->Flush();
  486.49 +    _coder->ReleaseStreams();
  486.50 +  }
  486.51 +};
  486.52 +
  486.53 +HRESULT CDecoder::CodeSpec(UInt32 size, Byte *memStream)
  486.54 +{
  486.55 +  if (_outSizeDefined)
  486.56 +  {
  486.57 +    const UInt64 rem = _outSize - _processedSize;
  486.58 +    if (size > rem)
  486.59 +      size = (UInt32)rem;
  486.60 +  }
  486.61 +  const UInt32 startSize = size;
  486.62 +
  486.63 +  if (_remainLen == kLenIdFinished)
  486.64 +    return S_OK;
  486.65 +  if (_remainLen == kLenIdNeedInit)
  486.66 +  {
  486.67 +    _rangeDecoder.Init();
  486.68 +    _remainLen = 0;
  486.69 +    _info.MaxOrder = 0;
  486.70 +    _info.StartModelRare(_order);
  486.71 +  }
  486.72 +  while (size != 0)
  486.73 +  {
  486.74 +    int symbol = _info.DecodeSymbol(&_rangeDecoder);
  486.75 +    if (symbol < 0)
  486.76 +    {
  486.77 +      _remainLen = kLenIdFinished;
  486.78 +      break;
  486.79 +    }
  486.80 +    if (memStream != 0)
  486.81 +      *memStream++ = (Byte)symbol;
  486.82 +    else
  486.83 +      _outStream.WriteByte((Byte)symbol);
  486.84 +    size--;
  486.85 +  }
  486.86 +  _processedSize += startSize - size;
  486.87 +  return S_OK;
  486.88 +}
  486.89 +
  486.90 +STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  486.91 +    const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)
  486.92 +{
  486.93 +  if (!_outStream.Create(1 << 20))
  486.94 +    return E_OUTOFMEMORY;
  486.95 +  
  486.96 +  SetInStream(inStream);
  486.97 +  _outStream.SetStream(outStream);
  486.98 +  SetOutStreamSize(outSize);
  486.99 +  CDecoderFlusher flusher(this);
 486.100 +
 486.101 +  for (;;)
 486.102 +  {
 486.103 +    _processedSize = _outStream.GetProcessedSize();
 486.104 +    UInt32 curSize = (1 << 18);
 486.105 +    RINOK(CodeSpec(curSize, NULL));
 486.106 +    if (_remainLen == kLenIdFinished)
 486.107 +      break;
 486.108 +    if (progress != NULL)
 486.109 +    {
 486.110 +      UInt64 inSize = _rangeDecoder.GetProcessedSize();
 486.111 +      RINOK(progress->SetRatioInfo(&inSize, &_processedSize));
 486.112 +    }
 486.113 +    if (_outSizeDefined)
 486.114 +      if (_outStream.GetProcessedSize() >= _outSize)
 486.115 +        break;
 486.116 +  }
 486.117 +  flusher.NeedFlush = false;
 486.118 +  return Flush();
 486.119 +}
 486.120 +
 486.121 +#ifdef _NO_EXCEPTIONS
 486.122 +
 486.123 +#define PPMD_TRY_BEGIN
 486.124 +#define PPMD_TRY_END
 486.125 +
 486.126 +#else
 486.127 +
 486.128 +#define PPMD_TRY_BEGIN try {
 486.129 +#define PPMD_TRY_END } \
 486.130 +  catch(const CInBufferException &e)  { return e.ErrorCode; } \
 486.131 +  catch(const COutBufferException &e)  { return e.ErrorCode; } \
 486.132 +  catch(...) { return S_FALSE; }
 486.133 +
 486.134 +#endif
 486.135 +
 486.136 +
 486.137 +STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 486.138 +    const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
 486.139 +{
 486.140 +  PPMD_TRY_BEGIN
 486.141 +  return CodeReal(inStream, outStream, inSize, outSize, progress);
 486.142 +  PPMD_TRY_END
 486.143 +}
 486.144 +
 486.145 +STDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream)
 486.146 +{
 486.147 +  _rangeDecoder.SetStream(inStream);
 486.148 +  return S_OK;
 486.149 +}
 486.150 +
 486.151 +STDMETHODIMP CDecoder::ReleaseInStream()
 486.152 +{
 486.153 +  _rangeDecoder.ReleaseStream();
 486.154 +  return S_OK;
 486.155 +}
 486.156 +
 486.157 +STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)
 486.158 +{
 486.159 +  _outSizeDefined = (outSize != NULL);
 486.160 +  if (_outSizeDefined)
 486.161 +    _outSize = *outSize;
 486.162 +  _processedSize = 0;
 486.163 +  _remainLen = kLenIdNeedInit;
 486.164 +  _outStream.Init();
 486.165 +  return S_OK;
 486.166 +}
 486.167 +
 486.168 +#ifndef NO_READ_FROM_CODER
 486.169 +
 486.170 +STDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)
 486.171 +{
 486.172 +  PPMD_TRY_BEGIN
 486.173 +  if (processedSize)
 486.174 +    *processedSize = 0;
 486.175 +  const UInt64 startPos = _processedSize;
 486.176 +  RINOK(CodeSpec(size, (Byte *)data));
 486.177 +  if (processedSize)
 486.178 +    *processedSize = (UInt32)(_processedSize - startPos);
 486.179 +  return Flush();
 486.180 +  PPMD_TRY_END
 486.181 +}
 486.182 +
 486.183 +#endif
 486.184 +
 486.185 +}}
   487.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   487.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/PpmdDecoder.h	Sat Mar 03 10:31:27 2012 -0600
   487.3 @@ -0,0 +1,86 @@
   487.4 +// PpmdDecoder.h
   487.5 +
   487.6 +#ifndef __COMPRESS_PPMD_DECODER_H
   487.7 +#define __COMPRESS_PPMD_DECODER_H
   487.8 +
   487.9 +#include "../../Common/MyCom.h"
  487.10 +
  487.11 +#include "../ICoder.h"
  487.12 +
  487.13 +#include "../Common/OutBuffer.h"
  487.14 +
  487.15 +#include "PpmdDecode.h"
  487.16 +#include "RangeCoder.h"
  487.17 +
  487.18 +namespace NCompress {
  487.19 +namespace NPpmd {
  487.20 +
  487.21 +class CDecoder :
  487.22 +  public ICompressCoder,
  487.23 +  public ICompressSetDecoderProperties2,
  487.24 +  #ifndef NO_READ_FROM_CODER
  487.25 +  public ICompressSetInStream,
  487.26 +  public ICompressSetOutStreamSize,
  487.27 +  public ISequentialInStream,
  487.28 +  #endif
  487.29 +  public CMyUnknownImp
  487.30 +{
  487.31 +  CRangeDecoder _rangeDecoder;
  487.32 +
  487.33 +  COutBuffer _outStream;
  487.34 +
  487.35 +  CDecodeInfo _info;
  487.36 +
  487.37 +  Byte _order;
  487.38 +  UInt32 _usedMemorySize;
  487.39 +
  487.40 +  int _remainLen;
  487.41 +  UInt64 _outSize;
  487.42 +  bool _outSizeDefined;
  487.43 +  UInt64 _processedSize;
  487.44 +
  487.45 +  HRESULT CodeSpec(UInt32 num, Byte *memStream);
  487.46 +
  487.47 +public:
  487.48 +
  487.49 +  #ifndef NO_READ_FROM_CODER
  487.50 +  MY_UNKNOWN_IMP4(
  487.51 +      ICompressSetDecoderProperties2,
  487.52 +      ICompressSetInStream,
  487.53 +      ICompressSetOutStreamSize,
  487.54 +      ISequentialInStream)
  487.55 +  #else
  487.56 +  MY_UNKNOWN_IMP1(
  487.57 +      ICompressSetDecoderProperties2)
  487.58 +  #endif
  487.59 +
  487.60 +  void ReleaseStreams()
  487.61 +  {
  487.62 +    ReleaseInStream();
  487.63 +    _outStream.ReleaseStream();
  487.64 +  }
  487.65 +
  487.66 +  HRESULT Flush() { return _outStream.Flush(); }
  487.67 +
  487.68 +  STDMETHOD(CodeReal)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  487.69 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
  487.70 +
  487.71 +  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  487.72 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
  487.73 +
  487.74 +  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
  487.75 +
  487.76 +  STDMETHOD(SetInStream)(ISequentialInStream *inStream);
  487.77 +  STDMETHOD(ReleaseInStream)();
  487.78 +  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);
  487.79 +
  487.80 +  #ifndef NO_READ_FROM_CODER
  487.81 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
  487.82 +  #endif
  487.83 +
  487.84 +  CDecoder(): _outSizeDefined(false) {}
  487.85 +};
  487.86 +
  487.87 +}}
  487.88 +
  487.89 +#endif
   488.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   488.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/PpmdRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   488.3 @@ -0,0 +1,20 @@
   488.4 +// PpmdRegister.cpp
   488.5 +
   488.6 +#include "StdAfx.h"
   488.7 +
   488.8 +#include "../Common/RegisterCodec.h"
   488.9 +
  488.10 +#include "PpmdDecoder.h"
  488.11 +
  488.12 +static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NPpmd::CDecoder); }
  488.13 +#ifndef EXTRACT_ONLY
  488.14 +#include "PpmdEncoder.h"
  488.15 +static void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NPpmd::CEncoder);  }
  488.16 +#else
  488.17 +#define CreateCodecOut 0
  488.18 +#endif
  488.19 +
  488.20 +static CCodecInfo g_CodecInfo =
  488.21 +  { CreateCodec, CreateCodecOut, 0x030401, L"PPMD", 1, false };
  488.22 +
  488.23 +REGISTER_CODEC(PPMD)
   489.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   489.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/PpmdSubAlloc.h	Sat Mar 03 10:31:27 2012 -0600
   489.3 @@ -0,0 +1,295 @@
   489.4 +// PpmdSubAlloc.h
   489.5 +// This code is based on Dmitry Shkarin's PPMdH code
   489.6 +
   489.7 +#ifndef __COMPRESS_PPMD_SUB_ALLOC_H
   489.8 +#define __COMPRESS_PPMD_SUB_ALLOC_H
   489.9 +
  489.10 +extern "C"
  489.11 +{
  489.12 +#include "../../../C/Alloc.h"
  489.13 +}
  489.14 +
  489.15 +#include "PpmdType.h"
  489.16 +
  489.17 +const UINT N1=4, N2=4, N3=4, N4=(128+3-1*N1-2*N2-3*N3)/4;
  489.18 +const UINT UNIT_SIZE=12, N_INDEXES=N1+N2+N3+N4;
  489.19 +
  489.20 +// Extra 1 * UNIT_SIZE for NULL support
  489.21 +// Extra 2 * UNIT_SIZE for s0 in GlueFreeBlocks()
  489.22 +const UInt32 kExtraSize = (UNIT_SIZE * 3);
  489.23 +const UInt32 kMaxMemBlockSize = 0xFFFFFFFF - kExtraSize;
  489.24 +
  489.25 +struct MEM_BLK
  489.26 +{
  489.27 +  UInt16 Stamp, NU;
  489.28 +  UInt32 Next, Prev;
  489.29 +  void InsertAt(Byte *Base, UInt32 p)
  489.30 +  {
  489.31 +    Prev = p;
  489.32 +    MEM_BLK *pp = (MEM_BLK *)(Base + p);
  489.33 +    Next = pp->Next;
  489.34 +    pp->Next = ((MEM_BLK *)(Base + Next))->Prev = (UInt32)((Byte *)this - Base);
  489.35 +  }
  489.36 +  void Remove(Byte *Base)
  489.37 +  {
  489.38 +    ((MEM_BLK *)(Base + Prev))->Next = Next;
  489.39 +    ((MEM_BLK *)(Base + Next))->Prev = Prev;
  489.40 +  }
  489.41 +};
  489.42 +
  489.43 +
  489.44 +class CSubAllocator
  489.45 +{
  489.46 +  UInt32 SubAllocatorSize;
  489.47 +  Byte Indx2Units[N_INDEXES], Units2Indx[128], GlueCount;
  489.48 +  UInt32 FreeList[N_INDEXES];
  489.49 +
  489.50 +  Byte *Base;
  489.51 +  Byte *HeapStart, *LoUnit, *HiUnit;
  489.52 +public:
  489.53 +  Byte *pText, *UnitsStart;
  489.54 +  CSubAllocator():
  489.55 +    SubAllocatorSize(0),
  489.56 +    GlueCount(0),
  489.57 +    LoUnit(0),
  489.58 +    HiUnit(0),
  489.59 +    pText(0),
  489.60 +    UnitsStart(0)
  489.61 +  {
  489.62 +    memset(Indx2Units, 0, sizeof(Indx2Units));
  489.63 +    memset(FreeList, 0, sizeof(FreeList));
  489.64 +  }
  489.65 +  ~CSubAllocator()
  489.66 +  {
  489.67 +    StopSubAllocator();
  489.68 +  };
  489.69 +
  489.70 +  void *GetPtr(UInt32 offset) const { return (offset == 0) ? 0 : (void *)(Base + offset); }
  489.71 +  void *GetPtrNoCheck(UInt32 offset) const { return (void *)(Base + offset); }
  489.72 +  UInt32 GetOffset(void *ptr) const { return (ptr == 0) ? 0 : (UInt32)((Byte *)ptr - Base); }
  489.73 +  UInt32 GetOffsetNoCheck(void *ptr) const { return (UInt32)((Byte *)ptr - Base); }
  489.74 +  MEM_BLK *GetBlk(UInt32 offset) const { return (MEM_BLK *)(Base + offset); }
  489.75 +  UInt32 *GetNode(UInt32 offset) const { return (UInt32 *)(Base + offset); }
  489.76 +
  489.77 +  void InsertNode(void* p, int indx)
  489.78 +  {
  489.79 +    *(UInt32 *)p = FreeList[indx];
  489.80 +    FreeList[indx] = GetOffsetNoCheck(p);
  489.81 +  }
  489.82 +
  489.83 +  void* RemoveNode(int indx)
  489.84 +  {
  489.85 +    UInt32 offset = FreeList[indx];
  489.86 +    UInt32 *p = GetNode(offset);
  489.87 +    FreeList[indx] = *p;
  489.88 +    return (void *)p;
  489.89 +  }
  489.90 +  
  489.91 +  UINT U2B(int NU) const { return (UINT)(NU) * UNIT_SIZE; }
  489.92 +  
  489.93 +  void SplitBlock(void* pv, int oldIndx, int newIndx)
  489.94 +  {
  489.95 +    int i, UDiff = Indx2Units[oldIndx] - Indx2Units[newIndx];
  489.96 +    Byte* p = ((Byte*)pv) + U2B(Indx2Units[newIndx]);
  489.97 +    if (Indx2Units[i = Units2Indx[UDiff-1]] != UDiff)
  489.98 +    {
  489.99 +      InsertNode(p, --i);
 489.100 +      p += U2B(i = Indx2Units[i]);
 489.101 +      UDiff -= i;
 489.102 +    }
 489.103 +    InsertNode(p, Units2Indx[UDiff - 1]);
 489.104 +  }
 489.105 +  
 489.106 +  UInt32 GetUsedMemory() const
 489.107 +  {
 489.108 +    UInt32 RetVal = SubAllocatorSize - (UInt32)(HiUnit - LoUnit) - (UInt32)(UnitsStart - pText);
 489.109 +    for (UInt32 i = 0; i < N_INDEXES; i++)
 489.110 +      for (UInt32 pn = FreeList[i]; pn != 0; RetVal -= (UInt32)Indx2Units[i] * UNIT_SIZE)
 489.111 +        pn = *GetNode(pn);
 489.112 +    return (RetVal >> 2);
 489.113 +  }
 489.114 +  
 489.115 +  UInt32 GetSubAllocatorSize() const { return SubAllocatorSize; }
 489.116 +
 489.117 +  void StopSubAllocator()
 489.118 +  {
 489.119 +    if (SubAllocatorSize != 0)
 489.120 +    {
 489.121 +      BigFree(Base);
 489.122 +      SubAllocatorSize = 0;
 489.123 +      Base = 0;
 489.124 +    }
 489.125 +  }
 489.126 +
 489.127 +  bool StartSubAllocator(UInt32 size)
 489.128 +  {
 489.129 +    if (SubAllocatorSize == size)
 489.130 +      return true;
 489.131 +    StopSubAllocator();
 489.132 +    if (size == 0)
 489.133 +      Base = 0;
 489.134 +    else
 489.135 +    {
 489.136 +      if ((Base = (Byte *)::BigAlloc(size + kExtraSize)) == 0)
 489.137 +        return false;
 489.138 +      HeapStart = Base + UNIT_SIZE; // we need such code to support NULL;
 489.139 +    }
 489.140 +    SubAllocatorSize = size;
 489.141 +    return true;
 489.142 +  }
 489.143 +
 489.144 +  void InitSubAllocator()
 489.145 +  {
 489.146 +    int i, k;
 489.147 +    memset(FreeList, 0, sizeof(FreeList));
 489.148 +    HiUnit = (pText = HeapStart) + SubAllocatorSize;
 489.149 +    UINT Diff = UNIT_SIZE * (SubAllocatorSize / 8 / UNIT_SIZE * 7);
 489.150 +    LoUnit = UnitsStart = HiUnit - Diff;
 489.151 +    for (i = 0, k=1; i < N1 ; i++, k += 1)        Indx2Units[i] = (Byte)k;
 489.152 +    for (k++; i < N1 + N2      ;i++, k += 2)      Indx2Units[i] = (Byte)k;
 489.153 +    for (k++; i < N1 + N2 + N3   ;i++,k += 3)     Indx2Units[i] = (Byte)k;
 489.154 +    for (k++; i < N1 + N2 + N3 + N4; i++, k += 4) Indx2Units[i] = (Byte)k;
 489.155 +    GlueCount = 0;
 489.156 +    for (k = i = 0; k < 128; k++)
 489.157 +    {
 489.158 +      i += (Indx2Units[i] < k+1);
 489.159 +        Units2Indx[k] = (Byte)i;
 489.160 +    }
 489.161 +  }
 489.162 +  
 489.163 +  void GlueFreeBlocks()
 489.164 +  {
 489.165 +    UInt32 s0 = (UInt32)(HeapStart + SubAllocatorSize - Base);
 489.166 +
 489.167 +    // We need add exta MEM_BLK with Stamp=0
 489.168 +    GetBlk(s0)->Stamp = 0;
 489.169 +    s0 += UNIT_SIZE;
 489.170 +    MEM_BLK *ps0 = GetBlk(s0);
 489.171 +
 489.172 +    UInt32 p;
 489.173 +    int i;
 489.174 +    if (LoUnit != HiUnit)
 489.175 +      *LoUnit=0;
 489.176 +    ps0->Next = ps0->Prev = s0;
 489.177 +
 489.178 +    for (i = 0; i < N_INDEXES; i++)
 489.179 +      while (FreeList[i] != 0)
 489.180 +      {
 489.181 +        MEM_BLK *pp = (MEM_BLK *)RemoveNode(i);
 489.182 +        pp->InsertAt(Base, s0);
 489.183 +        pp->Stamp = 0xFFFF;
 489.184 +        pp->NU = Indx2Units[i];
 489.185 +      }
 489.186 +    for (p = ps0->Next; p != s0; p = GetBlk(p)->Next)
 489.187 +    {
 489.188 +      for (;;)
 489.189 +      {
 489.190 +        MEM_BLK *pp = GetBlk(p);
 489.191 +        MEM_BLK *pp1 = GetBlk(p + pp->NU * UNIT_SIZE);
 489.192 +        if (pp1->Stamp != 0xFFFF || int(pp->NU) + pp1->NU >= 0x10000)
 489.193 +          break;
 489.194 +        pp1->Remove(Base);
 489.195 +        pp->NU = (UInt16)(pp->NU + pp1->NU);
 489.196 +      }
 489.197 +    }
 489.198 +    while ((p = ps0->Next) != s0)
 489.199 +    {
 489.200 +      MEM_BLK *pp = GetBlk(p);
 489.201 +      pp->Remove(Base);
 489.202 +      int sz;
 489.203 +      for (sz = pp->NU; sz > 128; sz -= 128, p += 128 * UNIT_SIZE)
 489.204 +        InsertNode(Base + p, N_INDEXES - 1);
 489.205 +      if (Indx2Units[i = Units2Indx[sz-1]] != sz)
 489.206 +      {
 489.207 +        int k = sz - Indx2Units[--i];
 489.208 +        InsertNode(Base + p + (sz - k) * UNIT_SIZE, k - 1);
 489.209 +      }
 489.210 +      InsertNode(Base + p, i);
 489.211 +    }
 489.212 +  }
 489.213 +  void* AllocUnitsRare(int indx)
 489.214 +  {
 489.215 +    if ( !GlueCount )
 489.216 +    {
 489.217 +      GlueCount = 255;
 489.218 +      GlueFreeBlocks();
 489.219 +      if (FreeList[indx] != 0)
 489.220 +        return RemoveNode(indx);
 489.221 +    }
 489.222 +    int i = indx;
 489.223 +    do
 489.224 +    {
 489.225 +      if (++i == N_INDEXES)
 489.226 +      {
 489.227 +        GlueCount--;
 489.228 +        i = U2B(Indx2Units[indx]);
 489.229 +        return (UnitsStart - pText > i) ? (UnitsStart -= i) : (NULL);
 489.230 +      }
 489.231 +    } while (FreeList[i] == 0);
 489.232 +    void* RetVal = RemoveNode(i);
 489.233 +    SplitBlock(RetVal, i, indx);
 489.234 +    return RetVal;
 489.235 +  }
 489.236 +  
 489.237 +  void* AllocUnits(int NU)
 489.238 +  {
 489.239 +    int indx = Units2Indx[NU - 1];
 489.240 +    if (FreeList[indx] != 0)
 489.241 +      return RemoveNode(indx);
 489.242 +    void* RetVal = LoUnit;
 489.243 +    LoUnit += U2B(Indx2Units[indx]);
 489.244 +    if (LoUnit <= HiUnit)
 489.245 +      return RetVal;
 489.246 +    LoUnit -= U2B(Indx2Units[indx]);
 489.247 +    return AllocUnitsRare(indx);
 489.248 +  }
 489.249 +  
 489.250 +  void* AllocContext()
 489.251 +  {
 489.252 +    if (HiUnit != LoUnit)
 489.253 +      return (HiUnit -= UNIT_SIZE);
 489.254 +    if (FreeList[0] != 0)
 489.255 +      return RemoveNode(0);
 489.256 +    return AllocUnitsRare(0);
 489.257 +  }
 489.258 +  
 489.259 +  void* ExpandUnits(void* oldPtr, int oldNU)
 489.260 +  {
 489.261 +    int i0=Units2Indx[oldNU - 1], i1=Units2Indx[oldNU - 1 + 1];
 489.262 +    if (i0 == i1)
 489.263 +      return oldPtr;
 489.264 +    void* ptr = AllocUnits(oldNU + 1);
 489.265 +    if (ptr)
 489.266 +    {
 489.267 +      memcpy(ptr, oldPtr, U2B(oldNU));
 489.268 +      InsertNode(oldPtr, i0);
 489.269 +    }
 489.270 +    return ptr;
 489.271 +  }
 489.272 +  
 489.273 +  void* ShrinkUnits(void* oldPtr, int oldNU, int newNU)
 489.274 +  {
 489.275 +    int i0 = Units2Indx[oldNU - 1], i1 = Units2Indx[newNU - 1];
 489.276 +    if (i0 == i1)
 489.277 +      return oldPtr;
 489.278 +    if (FreeList[i1] != 0)
 489.279 +    {
 489.280 +      void* ptr = RemoveNode(i1);
 489.281 +      memcpy(ptr, oldPtr, U2B(newNU));
 489.282 +      InsertNode(oldPtr,i0);
 489.283 +      return ptr;
 489.284 +    }
 489.285 +    else
 489.286 +    {
 489.287 +      SplitBlock(oldPtr, i0, i1);
 489.288 +      return oldPtr;
 489.289 +    }
 489.290 +  }
 489.291 +  
 489.292 +  void FreeUnits(void* ptr, int oldNU)
 489.293 +  {
 489.294 +    InsertNode(ptr, Units2Indx[oldNU - 1]);
 489.295 +  }
 489.296 +};
 489.297 +
 489.298 +#endif
   490.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   490.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/PpmdType.h	Sat Mar 03 10:31:27 2012 -0600
   490.3 @@ -0,0 +1,20 @@
   490.4 +/****************************************************************************
   490.5 + *  This file is part of PPMd project                                       *
   490.6 + *  Written and distributed to public domain by Dmitry Shkarin 1997,        *
   490.7 + *  1999-2001                                                               *
   490.8 + *  Contents: compilation parameters and miscelaneous definitions           *
   490.9 + *  Comments: system & compiler dependent file
  490.10 + 
  490.11 + *  modified by Igor Pavlov (2004-08-29).
  490.12 + ****************************************************************************/
  490.13 +
  490.14 +#ifndef __COMPRESS_PPMD_TYPE_H
  490.15 +#define __COMPRESS_PPMD_TYPE_H
  490.16 +
  490.17 +const int kMaxOrderCompress = 32;
  490.18 +const int MAX_O = 255; /* maximum allowed model order */
  490.19 +
  490.20 +template <class T>
  490.21 +inline void _PPMD_SWAP(T& t1,T& t2) { T tmp = t1; t1 = t2; t2 = tmp; }
  490.22 +
  490.23 +#endif
   491.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   491.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/RangeCoder.h	Sat Mar 03 10:31:27 2012 -0600
   491.3 @@ -0,0 +1,204 @@
   491.4 +// Compress/RangeCoder.h
   491.5 +
   491.6 +#ifndef __COMPRESS_RANGE_CODER_H
   491.7 +#define __COMPRESS_RANGE_CODER_H
   491.8 +
   491.9 +#include "../Common/InBuffer.h"
  491.10 +#include "../Common/OutBuffer.h"
  491.11 +
  491.12 +namespace NCompress {
  491.13 +namespace NRangeCoder {
  491.14 +
  491.15 +const int kNumTopBits = 24;
  491.16 +const UInt32 kTopValue = (1 << kNumTopBits);
  491.17 +
  491.18 +class CEncoder
  491.19 +{
  491.20 +  UInt32 _cacheSize;
  491.21 +  Byte _cache;
  491.22 +public:
  491.23 +  UInt64 Low;
  491.24 +  UInt32 Range;
  491.25 +  COutBuffer Stream;
  491.26 +  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }
  491.27 +
  491.28 +  void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }
  491.29 +  void Init()
  491.30 +  {
  491.31 +    Stream.Init();
  491.32 +    Low = 0;
  491.33 +    Range = 0xFFFFFFFF;
  491.34 +    _cacheSize = 1;
  491.35 +    _cache = 0;
  491.36 +  }
  491.37 +
  491.38 +  void FlushData()
  491.39 +  {
  491.40 +    // Low += 1;
  491.41 +    for(int i = 0; i < 5; i++)
  491.42 +      ShiftLow();
  491.43 +  }
  491.44 +
  491.45 +  HRESULT FlushStream() { return Stream.Flush();  }
  491.46 +
  491.47 +  void ReleaseStream() { Stream.ReleaseStream(); }
  491.48 +
  491.49 +  void Encode(UInt32 start, UInt32 size, UInt32 total)
  491.50 +  {
  491.51 +    Low += start * (Range /= total);
  491.52 +    Range *= size;
  491.53 +    while (Range < kTopValue)
  491.54 +    {
  491.55 +      Range <<= 8;
  491.56 +      ShiftLow();
  491.57 +    }
  491.58 +  }
  491.59 +
  491.60 +  void ShiftLow()
  491.61 +  {
  491.62 +    if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0)
  491.63 +    {
  491.64 +      Byte temp = _cache;
  491.65 +      do
  491.66 +      {
  491.67 +        Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));
  491.68 +        temp = 0xFF;
  491.69 +      }
  491.70 +      while(--_cacheSize != 0);
  491.71 +      _cache = (Byte)((UInt32)Low >> 24);
  491.72 +    }
  491.73 +    _cacheSize++;
  491.74 +    Low = (UInt32)Low << 8;
  491.75 +  }
  491.76 +  
  491.77 +  void EncodeDirectBits(UInt32 value, int numBits)
  491.78 +  {
  491.79 +    for (numBits--; numBits >= 0; numBits--)
  491.80 +    {
  491.81 +      Range >>= 1;
  491.82 +      Low += Range & (0 - ((value >> numBits) & 1));
  491.83 +      if (Range < kTopValue)
  491.84 +      {
  491.85 +        Range <<= 8;
  491.86 +        ShiftLow();
  491.87 +      }
  491.88 +    }
  491.89 +  }
  491.90 +
  491.91 +  void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)
  491.92 +  {
  491.93 +    UInt32 newBound = (Range >> numTotalBits) * size0;
  491.94 +    if (symbol == 0)
  491.95 +      Range = newBound;
  491.96 +    else
  491.97 +    {
  491.98 +      Low += newBound;
  491.99 +      Range -= newBound;
 491.100 +    }
 491.101 +    while (Range < kTopValue)
 491.102 +    {
 491.103 +      Range <<= 8;
 491.104 +      ShiftLow();
 491.105 +    }
 491.106 +  }
 491.107 +
 491.108 +  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _cacheSize + 4; }
 491.109 +};
 491.110 +
 491.111 +class CDecoder
 491.112 +{
 491.113 +public:
 491.114 +  CInBuffer Stream;
 491.115 +  UInt32 Range;
 491.116 +  UInt32 Code;
 491.117 +  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }
 491.118 +
 491.119 +  void Normalize()
 491.120 +  {
 491.121 +    while (Range < kTopValue)
 491.122 +    {
 491.123 +      Code = (Code << 8) | Stream.ReadByte();
 491.124 +      Range <<= 8;
 491.125 +    }
 491.126 +  }
 491.127 +  
 491.128 +  void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }
 491.129 +  void Init()
 491.130 +  {
 491.131 +    Stream.Init();
 491.132 +    Code = 0;
 491.133 +    Range = 0xFFFFFFFF;
 491.134 +    for(int i = 0; i < 5; i++)
 491.135 +      Code = (Code << 8) | Stream.ReadByte();
 491.136 +  }
 491.137 +
 491.138 +  void ReleaseStream() { Stream.ReleaseStream(); }
 491.139 +
 491.140 +  UInt32 GetThreshold(UInt32 total)
 491.141 +  {
 491.142 +    return (Code) / ( Range /= total);
 491.143 +  }
 491.144 +
 491.145 +  void Decode(UInt32 start, UInt32 size)
 491.146 +  {
 491.147 +    Code -= start * Range;
 491.148 +    Range *= size;
 491.149 +    Normalize();
 491.150 +  }
 491.151 +
 491.152 +  UInt32 DecodeDirectBits(int numTotalBits)
 491.153 +  {
 491.154 +    UInt32 range = Range;
 491.155 +    UInt32 code = Code;
 491.156 +    UInt32 result = 0;
 491.157 +    for (int i = numTotalBits; i != 0; i--)
 491.158 +    {
 491.159 +      range >>= 1;
 491.160 +      /*
 491.161 +      result <<= 1;
 491.162 +      if (code >= range)
 491.163 +      {
 491.164 +        code -= range;
 491.165 +        result |= 1;
 491.166 +      }
 491.167 +      */
 491.168 +      UInt32 t = (code - range) >> 31;
 491.169 +      code -= range & (t - 1);
 491.170 +      result = (result << 1) | (1 - t);
 491.171 +
 491.172 +      if (range < kTopValue)
 491.173 +      {
 491.174 +        code = (code << 8) | Stream.ReadByte();
 491.175 +        range <<= 8;
 491.176 +      }
 491.177 +    }
 491.178 +    Range = range;
 491.179 +    Code = code;
 491.180 +    return result;
 491.181 +  }
 491.182 +
 491.183 +  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)
 491.184 +  {
 491.185 +    UInt32 newBound = (Range >> numTotalBits) * size0;
 491.186 +    UInt32 symbol;
 491.187 +    if (Code < newBound)
 491.188 +    {
 491.189 +      symbol = 0;
 491.190 +      Range = newBound;
 491.191 +    }
 491.192 +    else
 491.193 +    {
 491.194 +      symbol = 1;
 491.195 +      Code -= newBound;
 491.196 +      Range -= newBound;
 491.197 +    }
 491.198 +    Normalize();
 491.199 +    return symbol;
 491.200 +  }
 491.201 +
 491.202 +  UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }
 491.203 +};
 491.204 +
 491.205 +}}
 491.206 +
 491.207 +#endif
   492.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   492.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/RangeCoderBit.h	Sat Mar 03 10:31:27 2012 -0600
   492.3 @@ -0,0 +1,113 @@
   492.4 +// Compress/RangeCoderBit.h
   492.5 +
   492.6 +#ifndef __COMPRESS_RANGE_CODER_BIT_H
   492.7 +#define __COMPRESS_RANGE_CODER_BIT_H
   492.8 +
   492.9 +#include "RangeCoder.h"
  492.10 +
  492.11 +namespace NCompress {
  492.12 +namespace NRangeCoder {
  492.13 +
  492.14 +const int kNumBitModelTotalBits  = 11;
  492.15 +const UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);
  492.16 +
  492.17 +const int kNumMoveReducingBits = 4;
  492.18 +
  492.19 +const int kNumBitPriceShiftBits = 4;
  492.20 +const UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;
  492.21 +
  492.22 +extern UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
  492.23 +
  492.24 +template <int numMoveBits>
  492.25 +class CBitModel
  492.26 +{
  492.27 +public:
  492.28 +  UInt32 Prob;
  492.29 +  void UpdateModel(UInt32 symbol)
  492.30 +  {
  492.31 +    /*
  492.32 +    Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;
  492.33 +    Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);
  492.34 +    */
  492.35 +    if (symbol == 0)
  492.36 +      Prob += (kBitModelTotal - Prob) >> numMoveBits;
  492.37 +    else
  492.38 +      Prob -= (Prob) >> numMoveBits;
  492.39 +  }
  492.40 +public:
  492.41 +  void Init() { Prob = kBitModelTotal / 2; }
  492.42 +};
  492.43 +
  492.44 +template <int numMoveBits>
  492.45 +class CBitEncoder: public CBitModel<numMoveBits>
  492.46 +{
  492.47 +public:
  492.48 +  void Encode(CEncoder *encoder, UInt32 symbol)
  492.49 +  {
  492.50 +    /*
  492.51 +    encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);
  492.52 +    this->UpdateModel(symbol);
  492.53 +    */
  492.54 +    UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;
  492.55 +    if (symbol == 0)
  492.56 +    {
  492.57 +      encoder->Range = newBound;
  492.58 +      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;
  492.59 +    }
  492.60 +    else
  492.61 +    {
  492.62 +      encoder->Low += newBound;
  492.63 +      encoder->Range -= newBound;
  492.64 +      this->Prob -= (this->Prob) >> numMoveBits;
  492.65 +    }
  492.66 +    if (encoder->Range < kTopValue)
  492.67 +    {
  492.68 +      encoder->Range <<= 8;
  492.69 +      encoder->ShiftLow();
  492.70 +    }
  492.71 +  }
  492.72 +  UInt32 GetPrice(UInt32 symbol) const
  492.73 +  {
  492.74 +    return ProbPrices[(this->Prob ^ ((-(int)symbol)) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];
  492.75 +  }
  492.76 +  UInt32 GetPrice0() const { return ProbPrices[this->Prob >> kNumMoveReducingBits]; }
  492.77 +  UInt32 GetPrice1() const { return ProbPrices[(this->Prob ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]; }
  492.78 +};
  492.79 +
  492.80 +
  492.81 +template <int numMoveBits>
  492.82 +class CBitDecoder: public CBitModel<numMoveBits>
  492.83 +{
  492.84 +public:
  492.85 +  UInt32 Decode(CDecoder *decoder)
  492.86 +  {
  492.87 +    UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;
  492.88 +    if (decoder->Code < newBound)
  492.89 +    {
  492.90 +      decoder->Range = newBound;
  492.91 +      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;
  492.92 +      if (decoder->Range < kTopValue)
  492.93 +      {
  492.94 +        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();
  492.95 +        decoder->Range <<= 8;
  492.96 +      }
  492.97 +      return 0;
  492.98 +    }
  492.99 +    else
 492.100 +    {
 492.101 +      decoder->Range -= newBound;
 492.102 +      decoder->Code -= newBound;
 492.103 +      this->Prob -= (this->Prob) >> numMoveBits;
 492.104 +      if (decoder->Range < kTopValue)
 492.105 +      {
 492.106 +        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();
 492.107 +        decoder->Range <<= 8;
 492.108 +      }
 492.109 +      return 1;
 492.110 +    }
 492.111 +  }
 492.112 +};
 492.113 +
 492.114 +}}
 492.115 +
 492.116 +#endif
   493.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   493.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/Rar1Decoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   493.3 @@ -0,0 +1,478 @@
   493.4 +// Rar1Decoder.cpp
   493.5 +// According to unRAR license, this code may not be used to develop
   493.6 +// a program that creates RAR archives
   493.7 + 
   493.8 +#include "StdAfx.h"
   493.9 +
  493.10 +#include "Rar1Decoder.h"
  493.11 +
  493.12 +namespace NCompress {
  493.13 +namespace NRar1 {
  493.14 +
  493.15 +static UInt32 PosL1[]={0,0,0,2,3,5,7,11,16,20,24,32,32, 256};
  493.16 +static UInt32 PosL2[]={0,0,0,0,5,7,9,13,18,22,26,34,36, 256};
  493.17 +static UInt32 PosHf0[]={0,0,0,0,0,8,16,24,33,33,33,33,33, 257};
  493.18 +static UInt32 PosHf1[]={0,0,0,0,0,0,4,44,60,76,80,80,127, 257};
  493.19 +static UInt32 PosHf2[]={0,0,0,0,0,0,2,7,53,117,233, 257,0};
  493.20 +static UInt32 PosHf3[]={0,0,0,0,0,0,0,2,16,218,251, 257,0};
  493.21 +static UInt32 PosHf4[]={0,0,0,0,0,0,0,0,0,255, 257,0,0};
  493.22 +
  493.23 +static const UInt32 kHistorySize = (1 << 16);
  493.24 +
  493.25 +class CCoderReleaser
  493.26 +{
  493.27 +  CDecoder *m_Coder;
  493.28 +public:
  493.29 +  CCoderReleaser(CDecoder *coder): m_Coder(coder) {}
  493.30 +  ~CCoderReleaser() { m_Coder->ReleaseStreams(); }
  493.31 +};
  493.32 +
  493.33 +CDecoder::CDecoder(): m_IsSolid(false) { }
  493.34 +
  493.35 +void CDecoder::InitStructures()
  493.36 +{
  493.37 +  for(int i = 0; i < kNumRepDists; i++)
  493.38 +    m_RepDists[i] = 0;
  493.39 +  m_RepDistPtr = 0;
  493.40 +  LastLength = 0;
  493.41 +  LastDist = 0;
  493.42 +}
  493.43 +
  493.44 +UInt32 CDecoder::ReadBits(int numBits) { return m_InBitStream.ReadBits(numBits); }
  493.45 +
  493.46 +HRESULT CDecoder::CopyBlock(UInt32 distance, UInt32 len)
  493.47 +{
  493.48 +  m_UnpackSize -= len;
  493.49 +  return m_OutWindowStream.CopyBlock(distance, len) ? S_OK : S_FALSE;
  493.50 +}
  493.51 +
  493.52 +
  493.53 +UInt32 CDecoder::DecodeNum(const UInt32 *posTab)
  493.54 +{
  493.55 +  UInt32 startPos = 2;
  493.56 +  UInt32 num = m_InBitStream.GetValue(12);
  493.57 +  for (;;)
  493.58 +  {
  493.59 +    UInt32 cur = (posTab[startPos + 1] - posTab[startPos]) << (12 - startPos);
  493.60 +    if (num < cur)
  493.61 +      break;
  493.62 +    startPos++;
  493.63 +    num -= cur;
  493.64 +  }
  493.65 +  m_InBitStream.MovePos(startPos);
  493.66 +  return((num >> (12 - startPos)) + posTab[startPos]);
  493.67 +}
  493.68 +
  493.69 +static Byte kShortLen1[]  = {1,3,4,4,5,6,7,8,8,4,4,5,6,6 };
  493.70 +static Byte kShortLen1a[] = {1,4,4,4,5,6,7,8,8,4,4,5,6,6,4 };
  493.71 +static Byte kShortLen2[]  = {2,3,3,3,4,4,5,6,6,4,4,5,6,6 };
  493.72 +static Byte kShortLen2a[] = {2,3,3,4,4,4,5,6,6,4,4,5,6,6,4 };
  493.73 +static UInt32 kShortXor1[] = {0,0xa0,0xd0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0xc0,0x80,0x90,0x98,0x9c,0xb0};
  493.74 +static UInt32 kShortXor2[] = {0,0x40,0x60,0xa0,0xd0,0xe0,0xf0,0xf8,0xfc,0xc0,0x80,0x90,0x98,0x9c,0xb0};
  493.75 +
  493.76 +HRESULT CDecoder::ShortLZ()
  493.77 +{
  493.78 +  UInt32 len, saveLen, dist;
  493.79 +  int distancePlace;
  493.80 +  Byte *kShortLen;
  493.81 +  const UInt32 *kShortXor;
  493.82 +  NumHuf = 0;
  493.83 +
  493.84 +  if (LCount == 2)
  493.85 +  {
  493.86 +    if (ReadBits(1))
  493.87 +      return CopyBlock(LastDist, LastLength);
  493.88 +    LCount = 0;
  493.89 +  }
  493.90 +
  493.91 +  UInt32 bitField = m_InBitStream.GetValue(8);
  493.92 +
  493.93 +  if (AvrLn1 < 37)
  493.94 +  {
  493.95 +    kShortLen = Buf60 ? kShortLen1a : kShortLen1;
  493.96 +    kShortXor = kShortXor1;
  493.97 +  }
  493.98 +  else
  493.99 +  {
 493.100 +    kShortLen = Buf60 ? kShortLen2a : kShortLen2;
 493.101 +    kShortXor = kShortXor2;
 493.102 +  }
 493.103 +
 493.104 +  for (len = 0; ((bitField ^ kShortXor[len]) & (~(0xff >> kShortLen[len]))) != 0; len++);
 493.105 +  m_InBitStream.MovePos(kShortLen[len]);
 493.106 +
 493.107 +  if (len >= 9)
 493.108 +  {
 493.109 +    if (len == 9)
 493.110 +    {
 493.111 +      LCount++;
 493.112 +      return CopyBlock(LastDist, LastLength);
 493.113 +    }
 493.114 +    if (len == 14)
 493.115 +    {
 493.116 +      LCount = 0;
 493.117 +      len = DecodeNum(PosL2) + 5;
 493.118 +      dist = 0x8000 + ReadBits(15) - 1;
 493.119 +      LastLength = len;
 493.120 +      LastDist = dist;
 493.121 +      return CopyBlock(dist, len);
 493.122 +    }
 493.123 +
 493.124 +    LCount = 0;
 493.125 +    saveLen = len;
 493.126 +    dist = m_RepDists[(m_RepDistPtr - (len - 9)) & 3];
 493.127 +    len = DecodeNum(PosL1) + 2;
 493.128 +    if (len == 0x101 && saveLen == 10)
 493.129 +    {
 493.130 +      Buf60 ^= 1;
 493.131 +      return S_OK;
 493.132 +    }
 493.133 +    if (dist >= 256)
 493.134 +      len++;
 493.135 +    if (dist >= MaxDist3 - 1)
 493.136 +      len++;
 493.137 +  }
 493.138 +  else
 493.139 +  {
 493.140 +    LCount = 0;
 493.141 +    AvrLn1 += len;
 493.142 +    AvrLn1 -= AvrLn1 >> 4;
 493.143 +    
 493.144 +    distancePlace = DecodeNum(PosHf2) & 0xff;
 493.145 +    dist = ChSetA[distancePlace];
 493.146 +    if (--distancePlace != -1)
 493.147 +    {
 493.148 +      PlaceA[dist]--;
 493.149 +      UInt32 lastDistance = ChSetA[distancePlace];
 493.150 +      PlaceA[lastDistance]++;
 493.151 +      ChSetA[distancePlace + 1] = lastDistance;
 493.152 +      ChSetA[distancePlace] = dist;
 493.153 +    }
 493.154 +    len += 2;
 493.155 +  }
 493.156 +  m_RepDists[m_RepDistPtr++] = dist;
 493.157 +  m_RepDistPtr &= 3;
 493.158 +  LastLength = len;
 493.159 +  LastDist = dist;
 493.160 +  return CopyBlock(dist, len);
 493.161 +}
 493.162 +
 493.163 +
 493.164 +HRESULT CDecoder::LongLZ()
 493.165 +{
 493.166 +  UInt32 len;
 493.167 +  UInt32 dist;
 493.168 +  UInt32 distancePlace, newDistancePlace;
 493.169 +  UInt32 oldAvr2, oldAvr3;
 493.170 +
 493.171 +  NumHuf = 0;
 493.172 +  Nlzb += 16;
 493.173 +  if (Nlzb > 0xff)
 493.174 +  {
 493.175 +    Nlzb = 0x90;
 493.176 +    Nhfb >>= 1;
 493.177 +  }
 493.178 +  oldAvr2=AvrLn2;
 493.179 +
 493.180 +  if (AvrLn2 >= 122)
 493.181 +    len = DecodeNum(PosL2);
 493.182 +  else if (AvrLn2 >= 64)
 493.183 +    len = DecodeNum(PosL1);
 493.184 +  else
 493.185 +  {
 493.186 +    UInt32 bitField = m_InBitStream.GetValue(16);
 493.187 +    if (bitField < 0x100)
 493.188 +    {
 493.189 +      len = bitField;
 493.190 +      m_InBitStream.MovePos(16);
 493.191 +    }
 493.192 +    else
 493.193 +    {
 493.194 +      for (len = 0; ((bitField << len) & 0x8000) == 0; len++)
 493.195 +        ;
 493.196 +      m_InBitStream.MovePos(len + 1);
 493.197 +    }
 493.198 +  }
 493.199 +
 493.200 +  AvrLn2 += len;
 493.201 +  AvrLn2 -= AvrLn2 >> 5;
 493.202 +
 493.203 +  if (AvrPlcB > 0x28ff)
 493.204 +    distancePlace = DecodeNum(PosHf2);
 493.205 +  else if (AvrPlcB > 0x6ff)
 493.206 +    distancePlace = DecodeNum(PosHf1);
 493.207 +  else
 493.208 +    distancePlace = DecodeNum(PosHf0);
 493.209 +
 493.210 +  AvrPlcB += distancePlace;
 493.211 +  AvrPlcB -= AvrPlcB >> 8;
 493.212 +  for (;;)
 493.213 +  {
 493.214 +    dist = ChSetB[distancePlace & 0xff];
 493.215 +    newDistancePlace = NToPlB[dist++ & 0xff]++;
 493.216 +    if (!(dist & 0xff))
 493.217 +      CorrHuff(ChSetB,NToPlB);
 493.218 +    else
 493.219 +      break;
 493.220 +  }
 493.221 +
 493.222 +  ChSetB[distancePlace] = ChSetB[newDistancePlace];
 493.223 +  ChSetB[newDistancePlace] = dist;
 493.224 +
 493.225 +  dist = ((dist & 0xff00) >> 1) | ReadBits(7);
 493.226 +
 493.227 +  oldAvr3 = AvrLn3;
 493.228 +  if (len != 1 && len != 4)
 493.229 +    if (len == 0 && dist <= MaxDist3)
 493.230 +    {
 493.231 +      AvrLn3++;
 493.232 +      AvrLn3 -= AvrLn3 >> 8;
 493.233 +    }
 493.234 +    else
 493.235 +      if (AvrLn3 > 0)
 493.236 +        AvrLn3--;
 493.237 +  len += 3;
 493.238 +  if (dist >= MaxDist3)
 493.239 +    len++;
 493.240 +  if (dist <= 256)
 493.241 +    len += 8;
 493.242 +  if (oldAvr3 > 0xb0 || AvrPlc >= 0x2a00 && oldAvr2 < 0x40)
 493.243 +    MaxDist3 = 0x7f00;
 493.244 +  else
 493.245 +    MaxDist3 = 0x2001;
 493.246 +  m_RepDists[m_RepDistPtr++] = --dist;
 493.247 +  m_RepDistPtr &= 3;
 493.248 +  LastLength = len;
 493.249 +  LastDist = dist;
 493.250 +  return CopyBlock(dist, len);
 493.251 +}
 493.252 +
 493.253 +
 493.254 +HRESULT CDecoder::HuffDecode()
 493.255 +{
 493.256 +  UInt32 curByte, newBytePlace;
 493.257 +  UInt32 len;
 493.258 +  UInt32 dist;
 493.259 +  int bytePlace;
 493.260 +
 493.261 +  if      (AvrPlc > 0x75ff)  bytePlace = DecodeNum(PosHf4);
 493.262 +  else if (AvrPlc > 0x5dff)  bytePlace = DecodeNum(PosHf3);
 493.263 +  else if (AvrPlc > 0x35ff)  bytePlace = DecodeNum(PosHf2);
 493.264 +  else if (AvrPlc > 0x0dff)  bytePlace = DecodeNum(PosHf1);
 493.265 +  else                       bytePlace = DecodeNum(PosHf0);
 493.266 +  if (StMode)
 493.267 +  {
 493.268 +    if (--bytePlace == -1)
 493.269 +    {
 493.270 +      if (ReadBits(1))
 493.271 +      {
 493.272 +        NumHuf = StMode = 0;
 493.273 +        return S_OK;
 493.274 +      }
 493.275 +      else
 493.276 +      {
 493.277 +        len = (ReadBits(1)) ? 4 : 3;
 493.278 +        dist = DecodeNum(PosHf2);
 493.279 +        dist = (dist << 5) | ReadBits(5);
 493.280 +        return CopyBlock(dist - 1, len);
 493.281 +      }
 493.282 +    }
 493.283 +  }
 493.284 +  else if (NumHuf++ >= 16 && FlagsCnt == 0)
 493.285 +    StMode = 1;
 493.286 +  bytePlace &= 0xff;
 493.287 +  AvrPlc += bytePlace;
 493.288 +  AvrPlc -= AvrPlc >> 8;
 493.289 +  Nhfb+=16;
 493.290 +  if (Nhfb > 0xff)
 493.291 +  {
 493.292 +    Nhfb=0x90;
 493.293 +    Nlzb >>= 1;
 493.294 +  }
 493.295 +
 493.296 +  m_UnpackSize --;
 493.297 +  m_OutWindowStream.PutByte((Byte)(ChSet[bytePlace] >> 8));
 493.298 +
 493.299 +  for (;;)
 493.300 +  {
 493.301 +    curByte = ChSet[bytePlace];
 493.302 +    newBytePlace = NToPl[curByte++ & 0xff]++;
 493.303 +    if ((curByte & 0xff) > 0xa1)
 493.304 +      CorrHuff(ChSet, NToPl);
 493.305 +    else
 493.306 +      break;
 493.307 +  }
 493.308 +
 493.309 +  ChSet[bytePlace] = ChSet[newBytePlace];
 493.310 +  ChSet[newBytePlace] = curByte;
 493.311 +  return S_OK;
 493.312 +}
 493.313 +
 493.314 +
 493.315 +void CDecoder::GetFlagsBuf()
 493.316 +{
 493.317 +  UInt32 flags, newFlagsPlace;
 493.318 +  UInt32 flagsPlace = DecodeNum(PosHf2);
 493.319 +
 493.320 +  for (;;)
 493.321 +  {
 493.322 +    flags = ChSetC[flagsPlace];
 493.323 +    FlagBuf = flags >> 8;
 493.324 +    newFlagsPlace = NToPlC[flags++ & 0xff]++;
 493.325 +    if ((flags & 0xff) != 0)
 493.326 +      break;
 493.327 +    CorrHuff(ChSetC, NToPlC);
 493.328 +  }
 493.329 +
 493.330 +  ChSetC[flagsPlace] = ChSetC[newFlagsPlace];
 493.331 +  ChSetC[newFlagsPlace] = flags;
 493.332 +}
 493.333 +
 493.334 +void CDecoder::InitData()
 493.335 +{
 493.336 +  if (!m_IsSolid)
 493.337 +  {
 493.338 +    AvrPlcB = AvrLn1 = AvrLn2 = AvrLn3 = NumHuf = Buf60 = 0;
 493.339 +    AvrPlc = 0x3500;
 493.340 +    MaxDist3 = 0x2001;
 493.341 +    Nhfb = Nlzb = 0x80;
 493.342 +  }
 493.343 +  FlagsCnt = 0;
 493.344 +  FlagBuf = 0;
 493.345 +  StMode = 0;
 493.346 +  LCount = 0;
 493.347 +}
 493.348 +
 493.349 +void CDecoder::CorrHuff(UInt32 *CharSet,UInt32 *NumToPlace)
 493.350 +{
 493.351 +  int i;
 493.352 +  for (i = 7; i >= 0; i--)
 493.353 +    for (int j = 0; j < 32; j++, CharSet++)
 493.354 +      *CharSet = (*CharSet & ~0xff) | i;
 493.355 +  memset(NumToPlace, 0, sizeof(NToPl));
 493.356 +  for (i = 6; i >= 0; i--)
 493.357 +    NumToPlace[i] = (7 - i) * 32;
 493.358 +}
 493.359 +
 493.360 +void CDecoder::InitHuff()
 493.361 +{
 493.362 +  for (UInt32 i = 0; i < 256; i++)
 493.363 +  {
 493.364 +    Place[i] = PlaceA[i] = PlaceB[i] = i;
 493.365 +    PlaceC[i] = (~i + 1) & 0xff;
 493.366 +    ChSet[i] = ChSetB[i] = i << 8;
 493.367 +    ChSetA[i] = i;
 493.368 +    ChSetC[i] = ((~i + 1) & 0xff) << 8;
 493.369 +  }
 493.370 +  memset(NToPl, 0, sizeof(NToPl));
 493.371 +  memset(NToPlB, 0, sizeof(NToPlB));
 493.372 +  memset(NToPlC, 0, sizeof(NToPlC));
 493.373 +  CorrHuff(ChSetB, NToPlB);
 493.374 +}
 493.375 +
 493.376 +HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 493.377 +    const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo * /* progress */)
 493.378 +{
 493.379 +  if (inSize == NULL || outSize == NULL)
 493.380 +    return E_INVALIDARG;
 493.381 +
 493.382 +  if (!m_OutWindowStream.Create(kHistorySize))
 493.383 +    return E_OUTOFMEMORY;
 493.384 +  if (!m_InBitStream.Create(1 << 20))
 493.385 +    return E_OUTOFMEMORY;
 493.386 +
 493.387 +  m_UnpackSize = (Int64)*outSize;
 493.388 +  m_OutWindowStream.SetStream(outStream);
 493.389 +  m_OutWindowStream.Init(m_IsSolid);
 493.390 +  m_InBitStream.SetStream(inStream);
 493.391 +  m_InBitStream.Init();
 493.392 +
 493.393 +  CCoderReleaser coderReleaser(this);
 493.394 +  InitData();
 493.395 +  if (!m_IsSolid)
 493.396 +  {
 493.397 +    InitStructures();
 493.398 +    InitHuff();
 493.399 +  }
 493.400 +  if (m_UnpackSize > 0)
 493.401 +  {
 493.402 +    GetFlagsBuf();
 493.403 +    FlagsCnt = 8;
 493.404 +  }
 493.405 +
 493.406 +  while (m_UnpackSize > 0)
 493.407 +  {
 493.408 +    if (StMode)
 493.409 +    {
 493.410 +      RINOK(HuffDecode());
 493.411 +      continue;
 493.412 +    }
 493.413 +
 493.414 +    if (--FlagsCnt < 0)
 493.415 +    {
 493.416 +      GetFlagsBuf();
 493.417 +      FlagsCnt=7;
 493.418 +    }
 493.419 +
 493.420 +    if (FlagBuf & 0x80)
 493.421 +    {
 493.422 +      FlagBuf <<= 1;
 493.423 +      if (Nlzb > Nhfb)
 493.424 +      {
 493.425 +        RINOK(LongLZ());
 493.426 +      }
 493.427 +      else
 493.428 +      {
 493.429 +        RINOK(HuffDecode());
 493.430 +      }
 493.431 +    }
 493.432 +    else
 493.433 +    {
 493.434 +      FlagBuf <<= 1;
 493.435 +      if (--FlagsCnt < 0)
 493.436 +      {
 493.437 +        GetFlagsBuf();
 493.438 +        FlagsCnt = 7;
 493.439 +      }
 493.440 +      if (FlagBuf & 0x80)
 493.441 +      {
 493.442 +        FlagBuf <<= 1;
 493.443 +        if (Nlzb > Nhfb)
 493.444 +        {
 493.445 +          RINOK(HuffDecode());
 493.446 +        }
 493.447 +        else
 493.448 +        {
 493.449 +          RINOK(LongLZ());
 493.450 +        }
 493.451 +      }
 493.452 +      else
 493.453 +      {
 493.454 +        FlagBuf <<= 1;
 493.455 +        RINOK(ShortLZ());
 493.456 +      }
 493.457 +    }
 493.458 +  }
 493.459 +  if (m_UnpackSize < 0)
 493.460 +    return S_FALSE;
 493.461 +  return m_OutWindowStream.Flush();
 493.462 +}
 493.463 +
 493.464 +STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 493.465 +    const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
 493.466 +{
 493.467 +  try { return CodeReal(inStream, outStream, inSize, outSize, progress); }
 493.468 +  catch(const CInBufferException &e) { return e.ErrorCode; }
 493.469 +  catch(const CLzOutWindowException &e) { return e.ErrorCode; }
 493.470 +  catch(...) { return S_FALSE; }
 493.471 +}
 493.472 +
 493.473 +STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
 493.474 +{
 493.475 +  if (size < 1)
 493.476 +    return E_INVALIDARG;
 493.477 +  m_IsSolid = (data[0] != 0);
 493.478 +  return S_OK;
 493.479 +}
 493.480 +
 493.481 +}}
   494.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   494.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/Rar1Decoder.h	Sat Mar 03 10:31:27 2012 -0600
   494.3 @@ -0,0 +1,88 @@
   494.4 +// Rar1Decoder.h
   494.5 +// According to unRAR license, this code may not be used to develop
   494.6 +// a program that creates RAR archives
   494.7 +
   494.8 +#ifndef __COMPRESS_RAR1_DECODER_H
   494.9 +#define __COMPRESS_RAR1_DECODER_H
  494.10 +
  494.11 +#include "../../Common/MyCom.h"
  494.12 +
  494.13 +#include "../ICoder.h"
  494.14 +
  494.15 +#include "../Common/InBuffer.h"
  494.16 +
  494.17 +#include "BitmDecoder.h"
  494.18 +#include "HuffmanDecoder.h"
  494.19 +#include "LzOutWindow.h"
  494.20 +
  494.21 +namespace NCompress {
  494.22 +namespace NRar1 {
  494.23 +
  494.24 +const UInt32 kNumRepDists = 4;
  494.25 +
  494.26 +typedef NBitm::CDecoder<CInBuffer> CBitDecoder;
  494.27 +
  494.28 +class CDecoder :
  494.29 +  public ICompressCoder,
  494.30 +  public ICompressSetDecoderProperties2,
  494.31 +  public CMyUnknownImp
  494.32 +{
  494.33 +public:
  494.34 +  CLzOutWindow m_OutWindowStream;
  494.35 +  CBitDecoder m_InBitStream;
  494.36 +
  494.37 +  UInt32 m_RepDists[kNumRepDists];
  494.38 +  UInt32 m_RepDistPtr;
  494.39 +
  494.40 +  UInt32 LastDist;
  494.41 +  UInt32 LastLength;
  494.42 +
  494.43 +  Int64 m_UnpackSize;
  494.44 +  bool m_IsSolid;
  494.45 +
  494.46 +  UInt32 ReadBits(int numBits);
  494.47 +  HRESULT CopyBlock(UInt32 distance, UInt32 len);
  494.48 +
  494.49 +  UInt32 DecodeNum(const UInt32 *posTab);
  494.50 +  HRESULT ShortLZ();
  494.51 +  HRESULT LongLZ();
  494.52 +  HRESULT HuffDecode();
  494.53 +  void GetFlagsBuf();
  494.54 +  void InitData();
  494.55 +  void InitHuff();
  494.56 +  void CorrHuff(UInt32 *CharSet, UInt32 *NumToPlace);
  494.57 +  void OldUnpWriteBuf();
  494.58 +  
  494.59 +  UInt32 ChSet[256],ChSetA[256],ChSetB[256],ChSetC[256];
  494.60 +  UInt32 Place[256],PlaceA[256],PlaceB[256],PlaceC[256];
  494.61 +  UInt32 NToPl[256],NToPlB[256],NToPlC[256];
  494.62 +  UInt32 FlagBuf,AvrPlc,AvrPlcB,AvrLn1,AvrLn2,AvrLn3;
  494.63 +  int Buf60,NumHuf,StMode,LCount,FlagsCnt;
  494.64 +  UInt32 Nhfb,Nlzb,MaxDist3;
  494.65 +
  494.66 +  void InitStructures();
  494.67 +
  494.68 +  HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  494.69 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
  494.70 +
  494.71 +public:
  494.72 +  CDecoder();
  494.73 +
  494.74 +  MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2)
  494.75 +
  494.76 +  void ReleaseStreams()
  494.77 +  {
  494.78 +    m_OutWindowStream.ReleaseStream();
  494.79 +    m_InBitStream.ReleaseStream();
  494.80 +  }
  494.81 +
  494.82 +  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  494.83 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
  494.84 +
  494.85 +  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
  494.86 +
  494.87 +};
  494.88 +
  494.89 +}}
  494.90 +
  494.91 +#endif
   495.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   495.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/Rar2Decoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   495.3 @@ -0,0 +1,389 @@
   495.4 +// Rar2Decoder.cpp
   495.5 +// According to unRAR license, this code may not be used to develop
   495.6 +// a program that creates RAR archives
   495.7 + 
   495.8 +#include "StdAfx.h"
   495.9 +
  495.10 +#include "Rar2Decoder.h"
  495.11 +
  495.12 +namespace NCompress {
  495.13 +namespace NRar2 {
  495.14 +
  495.15 +namespace NMultimedia {
  495.16 +
  495.17 +Byte CFilter::Decode(int &channelDelta, Byte deltaByte)
  495.18 +{
  495.19 +  D4 = D3;
  495.20 +  D3 = D2;
  495.21 +  D2 = LastDelta - D1;
  495.22 +  D1 = LastDelta;
  495.23 +  int predictedValue = ((8 * LastChar + K1 * D1 + K2 * D2 + K3 * D3 + K4 * D4 + K5 * channelDelta) >> 3);
  495.24 +
  495.25 +  Byte realValue = (Byte)(predictedValue - deltaByte);
  495.26 +  int i = ((int)(signed char)deltaByte) << 3;
  495.27 +
  495.28 +  Dif[0] += abs(i);
  495.29 +  Dif[1] += abs(i - D1);
  495.30 +  Dif[2] += abs(i + D1);
  495.31 +  Dif[3] += abs(i - D2);
  495.32 +  Dif[4] += abs(i + D2);
  495.33 +  Dif[5] += abs(i - D3);
  495.34 +  Dif[6] += abs(i + D3);
  495.35 +  Dif[7] += abs(i - D4);
  495.36 +  Dif[8] += abs(i + D4);
  495.37 +  Dif[9] += abs(i - channelDelta);
  495.38 +  Dif[10] += abs(i + channelDelta);
  495.39 +
  495.40 +  channelDelta = LastDelta = (signed char)(realValue - LastChar);
  495.41 +  LastChar = realValue;
  495.42 +
  495.43 +  if (((++ByteCount) & 0x1F) == 0)
  495.44 +  {
  495.45 +    UInt32 minDif = Dif[0];
  495.46 +    UInt32 numMinDif = 0;
  495.47 +    Dif[0] = 0;
  495.48 +    for (i = 1; i < sizeof(Dif) / sizeof(Dif[0]); i++)
  495.49 +    {
  495.50 +      if (Dif[i] < minDif)
  495.51 +      {
  495.52 +        minDif = Dif[i];
  495.53 +        numMinDif = i;
  495.54 +      }
  495.55 +      Dif[i] = 0;
  495.56 +    }
  495.57 +    switch(numMinDif)
  495.58 +    {
  495.59 +      case 1: if (K1 >= -16) K1--; break;
  495.60 +      case 2: if (K1 <   16) K1++; break;
  495.61 +      case 3: if (K2 >= -16) K2--; break;
  495.62 +      case 4: if (K2 <   16) K2++; break;
  495.63 +      case 5: if (K3 >= -16) K3--; break;
  495.64 +      case 6: if (K3 <   16) K3++; break;
  495.65 +      case 7: if (K4 >= -16) K4--; break;
  495.66 +      case 8: if (K4 <   16) K4++; break;
  495.67 +      case 9: if (K5 >= -16) K5--; break;
  495.68 +      case 10:if (K5 <   16) K5++; break;
  495.69 +    }
  495.70 +  }
  495.71 +  return realValue;
  495.72 +}
  495.73 +}
  495.74 +
  495.75 +static const char *kNumberErrorMessage = "Number error";
  495.76 +
  495.77 +static const UInt32 kHistorySize = 1 << 20;
  495.78 +
  495.79 +static const int kNumStats = 11;
  495.80 +
  495.81 +static const UInt32 kWindowReservSize = (1 << 22) + 256;
  495.82 +
  495.83 +CDecoder::CDecoder():
  495.84 +  m_IsSolid(false)
  495.85 +{
  495.86 +}
  495.87 +
  495.88 +void CDecoder::InitStructures()
  495.89 +{
  495.90 +  m_MmFilter.Init();
  495.91 +  for(int i = 0; i < kNumRepDists; i++)
  495.92 +    m_RepDists[i] = 0;
  495.93 +  m_RepDistPtr = 0;
  495.94 +  m_LastLength = 0;
  495.95 +  memset(m_LastLevels, 0, kMaxTableSize);
  495.96 +}
  495.97 +
  495.98 +UInt32 CDecoder::ReadBits(int numBits) { return m_InBitStream.ReadBits(numBits); }
  495.99 +
 495.100 +#define RIF(x) { if (!(x)) return false; }
 495.101 +
 495.102 +bool CDecoder::ReadTables(void)
 495.103 +{
 495.104 +  Byte levelLevels[kLevelTableSize];
 495.105 +  Byte newLevels[kMaxTableSize];
 495.106 +  m_AudioMode = (ReadBits(1) == 1);
 495.107 +
 495.108 +  if (ReadBits(1) == 0)
 495.109 +    memset(m_LastLevels, 0, kMaxTableSize);
 495.110 +  int numLevels;
 495.111 +  if (m_AudioMode)
 495.112 +  {
 495.113 +    m_NumChannels = ReadBits(2) + 1;
 495.114 +    if (m_MmFilter.CurrentChannel >= m_NumChannels)
 495.115 +      m_MmFilter.CurrentChannel = 0;
 495.116 +    numLevels = m_NumChannels * kMMTableSize;
 495.117 +  }
 495.118 +  else
 495.119 +    numLevels = kHeapTablesSizesSum;
 495.120 + 
 495.121 +  int i;
 495.122 +  for (i = 0; i < kLevelTableSize; i++)
 495.123 +    levelLevels[i] = (Byte)ReadBits(4);
 495.124 +  RIF(m_LevelDecoder.SetCodeLengths(levelLevels));
 495.125 +  i = 0;
 495.126 +  while (i < numLevels)
 495.127 +  {
 495.128 +    UInt32 number = m_LevelDecoder.DecodeSymbol(&m_InBitStream);
 495.129 +    if (number < kTableDirectLevels)
 495.130 +    {
 495.131 +      newLevels[i] = (Byte)((number + m_LastLevels[i]) & kLevelMask);
 495.132 +      i++;
 495.133 +    }
 495.134 +    else
 495.135 +    {
 495.136 +      if (number == kTableLevelRepNumber)
 495.137 +      {
 495.138 +        int t = ReadBits(2) + 3;
 495.139 +        for (int reps = t; reps > 0 && i < numLevels ; reps--, i++)
 495.140 +          newLevels[i] = newLevels[i - 1];
 495.141 +      }
 495.142 +      else
 495.143 +      {
 495.144 +        int num;
 495.145 +        if (number == kTableLevel0Number)
 495.146 +          num = ReadBits(3) + 3;
 495.147 +        else if (number == kTableLevel0Number2)
 495.148 +          num = ReadBits(7) + 11;
 495.149 +        else
 495.150 +          return false;
 495.151 +        for (;num > 0 && i < numLevels; num--)
 495.152 +          newLevels[i++] = 0;
 495.153 +      }
 495.154 +    }
 495.155 +  }
 495.156 +  if (m_AudioMode)
 495.157 +    for (i = 0; i < m_NumChannels; i++)
 495.158 +    {
 495.159 +      RIF(m_MMDecoders[i].SetCodeLengths(&newLevels[i * kMMTableSize]));
 495.160 +    }
 495.161 +  else
 495.162 +  {
 495.163 +    RIF(m_MainDecoder.SetCodeLengths(&newLevels[0]));
 495.164 +    RIF(m_DistDecoder.SetCodeLengths(&newLevels[kMainTableSize]));
 495.165 +    RIF(m_LenDecoder.SetCodeLengths(&newLevels[kMainTableSize + kDistTableSize]));
 495.166 +  }
 495.167 +  memcpy(m_LastLevels, newLevels, kMaxTableSize);
 495.168 +  return true;
 495.169 +}
 495.170 +
 495.171 +bool CDecoder::ReadLastTables()
 495.172 +{
 495.173 +  // it differs a little from pure RAR sources;
 495.174 +  // UInt64 ttt = m_InBitStream.GetProcessedSize() + 2;
 495.175 +  // + 2 works for: return 0xFF; in CInBuffer::ReadByte.
 495.176 +  if (m_InBitStream.GetProcessedSize() + 7 <= m_PackSize) // test it: probably incorrect;
 495.177 +  // if (m_InBitStream.GetProcessedSize() + 2 <= m_PackSize) // test it: probably incorrect;
 495.178 +    if (m_AudioMode)
 495.179 +    {
 495.180 +      UInt32 symbol = m_MMDecoders[m_MmFilter.CurrentChannel].DecodeSymbol(&m_InBitStream);
 495.181 +      if (symbol == 256)
 495.182 +        return ReadTables();
 495.183 +      if (symbol >= kMMTableSize)
 495.184 +        return false;
 495.185 +    }
 495.186 +    else
 495.187 +    {
 495.188 +      UInt32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream);
 495.189 +      if (number == kReadTableNumber)
 495.190 +        return ReadTables();
 495.191 +      if (number >= kMainTableSize)
 495.192 +        return false;
 495.193 +    }
 495.194 +  return true;
 495.195 +}
 495.196 +
 495.197 +class CCoderReleaser
 495.198 +{
 495.199 +  CDecoder *m_Coder;
 495.200 +public:
 495.201 +  CCoderReleaser(CDecoder *coder): m_Coder(coder) {}
 495.202 +  ~CCoderReleaser()
 495.203 +  {
 495.204 +    m_Coder->ReleaseStreams();
 495.205 +  }
 495.206 +};
 495.207 +
 495.208 +bool CDecoder::DecodeMm(UInt32 pos)
 495.209 +{
 495.210 +  while (pos-- > 0)
 495.211 +  {
 495.212 +    UInt32 symbol = m_MMDecoders[m_MmFilter.CurrentChannel].DecodeSymbol(&m_InBitStream);
 495.213 +    if (symbol == 256)
 495.214 +      return true;
 495.215 +    if (symbol >= kMMTableSize)
 495.216 +      return false;
 495.217 +    /*
 495.218 +    Byte byPredict = m_Predictor.Predict();
 495.219 +    Byte byReal = (Byte)(byPredict - (Byte)symbol);
 495.220 +    m_Predictor.Update(byReal, byPredict);
 495.221 +    */
 495.222 +    Byte byReal = m_MmFilter.Decode((Byte)symbol);
 495.223 +    m_OutWindowStream.PutByte(byReal);
 495.224 +    if (++m_MmFilter.CurrentChannel == m_NumChannels)
 495.225 +      m_MmFilter.CurrentChannel = 0;
 495.226 +  }
 495.227 +  return true;
 495.228 +}
 495.229 +
 495.230 +bool CDecoder::DecodeLz(Int32 pos)
 495.231 +{
 495.232 +  while (pos > 0)
 495.233 +  {
 495.234 +    UInt32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream);
 495.235 +    UInt32 length, distance;
 495.236 +    if (number < 256)
 495.237 +    {
 495.238 +      m_OutWindowStream.PutByte(Byte(number));
 495.239 +      pos--;
 495.240 +      continue;
 495.241 +    }
 495.242 +    else if (number >= kMatchNumber)
 495.243 +    {
 495.244 +      number -= kMatchNumber;
 495.245 +      length = kNormalMatchMinLen + UInt32(kLenStart[number]) +
 495.246 +        m_InBitStream.ReadBits(kLenDirectBits[number]);
 495.247 +      number = m_DistDecoder.DecodeSymbol(&m_InBitStream);
 495.248 +      if (number >= kDistTableSize)
 495.249 +        return false;
 495.250 +      distance = kDistStart[number] + m_InBitStream.ReadBits(kDistDirectBits[number]);
 495.251 +      if (distance >= kDistLimit3)
 495.252 +      {
 495.253 +        length += 2 - ((distance - kDistLimit4) >> 31);
 495.254 +        // length++;
 495.255 +        // if (distance >= kDistLimit4)
 495.256 +        //  length++;
 495.257 +      }
 495.258 +    }
 495.259 +    else if (number == kRepBothNumber)
 495.260 +    {
 495.261 +      length = m_LastLength;
 495.262 +      distance = m_RepDists[(m_RepDistPtr + 4 - 1) & 3];
 495.263 +    }
 495.264 +    else if (number < kLen2Number)
 495.265 +    {
 495.266 +      distance = m_RepDists[(m_RepDistPtr - (number - kRepNumber + 1)) & 3];
 495.267 +      number = m_LenDecoder.DecodeSymbol(&m_InBitStream);
 495.268 +      if (number >= kLenTableSize)
 495.269 +        return false;
 495.270 +      length = 2 + kLenStart[number] + m_InBitStream.ReadBits(kLenDirectBits[number]);
 495.271 +      if (distance >= kDistLimit2)
 495.272 +      {
 495.273 +        length++;
 495.274 +        if (distance >= kDistLimit3)
 495.275 +        {
 495.276 +          length += 2 - ((distance - kDistLimit4) >> 31);
 495.277 +          // length++;
 495.278 +          // if (distance >= kDistLimit4)
 495.279 +          //   length++;
 495.280 +        }
 495.281 +      }
 495.282 +    }
 495.283 +    else if (number < kReadTableNumber)
 495.284 +    {
 495.285 +      number -= kLen2Number;
 495.286 +      distance = kLen2DistStarts[number] +
 495.287 +        m_InBitStream.ReadBits(kLen2DistDirectBits[number]);
 495.288 +      length = 2;
 495.289 +    }
 495.290 +    else if (number == kReadTableNumber)
 495.291 +      return true;
 495.292 +    else
 495.293 +      return false;
 495.294 +    m_RepDists[m_RepDistPtr++ & 3] = distance;
 495.295 +    m_LastLength = length;
 495.296 +    if (!m_OutWindowStream.CopyBlock(distance, length))
 495.297 +      return false;
 495.298 +    pos -= length;
 495.299 +  }
 495.300 +  return true;
 495.301 +}
 495.302 +
 495.303 +HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 495.304 +    const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
 495.305 +{
 495.306 +  if (inSize == NULL || outSize == NULL)
 495.307 +    return E_INVALIDARG;
 495.308 +
 495.309 +  if (!m_OutWindowStream.Create(kHistorySize))
 495.310 +    return E_OUTOFMEMORY;
 495.311 +  if (!m_InBitStream.Create(1 << 20))
 495.312 +    return E_OUTOFMEMORY;
 495.313 +
 495.314 +  m_PackSize = *inSize;
 495.315 +
 495.316 +  UInt64 pos = 0, unPackSize = *outSize;
 495.317 +  
 495.318 +  m_OutWindowStream.SetStream(outStream);
 495.319 +  m_OutWindowStream.Init(m_IsSolid);
 495.320 +  m_InBitStream.SetStream(inStream);
 495.321 +  m_InBitStream.Init();
 495.322 +
 495.323 +  CCoderReleaser coderReleaser(this);
 495.324 +  if (!m_IsSolid)
 495.325 +  {
 495.326 +    InitStructures();
 495.327 +    if (unPackSize == 0)
 495.328 +    {
 495.329 +      if (m_InBitStream.GetProcessedSize() + 2 <= m_PackSize) // test it: probably incorrect;
 495.330 +        if (!ReadTables())
 495.331 +          return S_FALSE;
 495.332 +      return S_OK;
 495.333 +    }
 495.334 +    if (!ReadTables())
 495.335 +      return S_FALSE;
 495.336 +  }
 495.337 +
 495.338 +  UInt64 startPos = m_OutWindowStream.GetProcessedSize();
 495.339 +  while(pos < unPackSize)
 495.340 +  {
 495.341 +    UInt32 blockSize = 1 << 20;
 495.342 +    if (blockSize > unPackSize - pos)
 495.343 +      blockSize = (UInt32)(unPackSize - pos);
 495.344 +    UInt64 blockStartPos = m_OutWindowStream.GetProcessedSize();
 495.345 +    if (m_AudioMode)
 495.346 +    {
 495.347 +      if (!DecodeMm(blockSize))
 495.348 +        return S_FALSE;
 495.349 +    }
 495.350 +    else
 495.351 +    {
 495.352 +      if (!DecodeLz((Int32)blockSize))
 495.353 +        return S_FALSE;
 495.354 +    }
 495.355 +    UInt64 globalPos = m_OutWindowStream.GetProcessedSize();
 495.356 +    pos = globalPos - blockStartPos;
 495.357 +    if (pos < blockSize)
 495.358 +      if (!ReadTables())
 495.359 +        return S_FALSE;
 495.360 +    pos = globalPos - startPos;
 495.361 +    if (progress != 0)
 495.362 +    {
 495.363 +      UInt64 packSize = m_InBitStream.GetProcessedSize();
 495.364 +      RINOK(progress->SetRatioInfo(&packSize, &pos));
 495.365 +    }
 495.366 +  }
 495.367 +  if (pos > unPackSize)
 495.368 +    return S_FALSE;
 495.369 +
 495.370 +  if (!ReadLastTables())
 495.371 +    return S_FALSE;
 495.372 +  return m_OutWindowStream.Flush();
 495.373 +}
 495.374 +
 495.375 +STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 495.376 +    const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
 495.377 +{
 495.378 +  try { return CodeReal(inStream, outStream, inSize, outSize, progress); }
 495.379 +  catch(const CInBufferException &e) { return e.ErrorCode; }
 495.380 +  catch(const CLzOutWindowException &e) { return e.ErrorCode; }
 495.381 +  catch(...) { return S_FALSE; }
 495.382 +}
 495.383 +
 495.384 +STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
 495.385 +{
 495.386 +  if (size < 1)
 495.387 +    return E_INVALIDARG;
 495.388 +  m_IsSolid = (data[0] != 0);
 495.389 +  return S_OK;
 495.390 +}
 495.391 +
 495.392 +}}
   496.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   496.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/Rar2Decoder.h	Sat Mar 03 10:31:27 2012 -0600
   496.3 @@ -0,0 +1,174 @@
   496.4 +// Rar2Decoder.h
   496.5 +// According to unRAR license, this code may not be used to develop
   496.6 +// a program that creates RAR archives
   496.7 +
   496.8 +#ifndef __COMPRESS_RAR2_DECODER_H
   496.9 +#define __COMPRESS_RAR2_DECODER_H
  496.10 +
  496.11 +#include "../../Common/MyCom.h"
  496.12 +
  496.13 +#include "../ICoder.h"
  496.14 +
  496.15 +#include "../Common/InBuffer.h"
  496.16 +
  496.17 +#include "BitmDecoder.h"
  496.18 +#include "HuffmanDecoder.h"
  496.19 +#include "LzOutWindow.h"
  496.20 +
  496.21 +namespace NCompress {
  496.22 +namespace NRar2 {
  496.23 +
  496.24 +const UInt32 kNumRepDists = 4;
  496.25 +const UInt32 kDistTableSize = 48;
  496.26 +
  496.27 +const int kMMTableSize = 256 + 1;
  496.28 +
  496.29 +const UInt32 kMainTableSize = 298;
  496.30 +const UInt32 kLenTableSize = 28;
  496.31 +
  496.32 +const UInt32 kDistTableStart = kMainTableSize;
  496.33 +const UInt32 kLenTableStart = kDistTableStart + kDistTableSize;
  496.34 +
  496.35 +const UInt32 kHeapTablesSizesSum = kMainTableSize + kDistTableSize + kLenTableSize;
  496.36 +
  496.37 +const UInt32 kLevelTableSize = 19;
  496.38 +
  496.39 +const UInt32 kMMTablesSizesSum = kMMTableSize * 4;
  496.40 +
  496.41 +const UInt32 kMaxTableSize = kMMTablesSizesSum;
  496.42 +
  496.43 +const UInt32 kTableDirectLevels = 16;
  496.44 +const UInt32 kTableLevelRepNumber = kTableDirectLevels;
  496.45 +const UInt32 kTableLevel0Number = kTableLevelRepNumber + 1;
  496.46 +const UInt32 kTableLevel0Number2 = kTableLevel0Number + 1;
  496.47 +
  496.48 +const UInt32 kLevelMask = 0xF;
  496.49 +
  496.50 +
  496.51 +const UInt32 kRepBothNumber = 256;
  496.52 +const UInt32 kRepNumber = kRepBothNumber + 1;
  496.53 +const UInt32 kLen2Number = kRepNumber + 4;
  496.54 +
  496.55 +const UInt32 kLen2NumNumbers = 8;
  496.56 +const UInt32 kReadTableNumber = kLen2Number + kLen2NumNumbers;
  496.57 +const UInt32 kMatchNumber = kReadTableNumber + 1;
  496.58 +
  496.59 +const Byte kLenStart[kLenTableSize]      = {0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224};
  496.60 +const Byte kLenDirectBits[kLenTableSize] = {0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,  4,  5,  5,  5,  5};
  496.61 +
  496.62 +const UInt32 kDistStart[kDistTableSize]     = {0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,1024,1536,2048,3072,4096,6144,8192,12288,16384,24576,32768U,49152U,65536,98304,131072,196608,262144,327680,393216,458752,524288,589824,655360,720896,786432,851968,917504,983040};
  496.63 +const Byte kDistDirectBits[kDistTableSize] = {0,0,0,0,1,1,2, 2, 3, 3, 4, 4, 5, 5,  6,  6,  7,  7,  8,  8,   9,   9,  10,  10,  11,  11,  12,   12,   13,   13,    14,    14,   15,   15,    16,    16,    16,    16,    16,    16,    16,    16,    16,    16,    16,    16,    16,    16};
  496.64 +
  496.65 +const Byte kLevelDirectBits[kLevelTableSize] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7};
  496.66 +
  496.67 +const Byte kLen2DistStarts[kLen2NumNumbers]={0,4,8,16,32,64,128,192};
  496.68 +const Byte kLen2DistDirectBits[kLen2NumNumbers]={2,2,3, 4, 5, 6,  6,  6};
  496.69 +
  496.70 +const UInt32 kDistLimit2 = 0x101 - 1;
  496.71 +const UInt32 kDistLimit3 = 0x2000 - 1;
  496.72 +const UInt32 kDistLimit4 = 0x40000 - 1;
  496.73 +
  496.74 +const UInt32 kMatchMaxLen = 255 + 2;
  496.75 +const UInt32 kMatchMaxLenMax = 255 + 5;
  496.76 +const UInt32 kNormalMatchMinLen = 3;
  496.77 +
  496.78 +namespace NMultimedia {
  496.79 +
  496.80 +struct CFilter
  496.81 +{
  496.82 +  int K1,K2,K3,K4,K5;
  496.83 +  int D1,D2,D3,D4;
  496.84 +  int LastDelta;
  496.85 +  UInt32 Dif[11];
  496.86 +  UInt32 ByteCount;
  496.87 +  int LastChar;
  496.88 +
  496.89 +  Byte Decode(int &channelDelta, Byte delta);
  496.90 +
  496.91 +  void Init() { memset(this, 0, sizeof(*this)); }
  496.92 +
  496.93 +};
  496.94 +
  496.95 +const int kNumChanelsMax = 4;
  496.96 +
  496.97 +class CFilter2
  496.98 +{
  496.99 +public:
 496.100 +  CFilter  m_Filters[kNumChanelsMax];
 496.101 +  int m_ChannelDelta;
 496.102 +  int CurrentChannel;
 496.103 +
 496.104 +  void Init() { memset(this, 0, sizeof(*this)); }
 496.105 +  Byte Decode(Byte delta)
 496.106 +  {
 496.107 +    return m_Filters[CurrentChannel].Decode(m_ChannelDelta, delta);
 496.108 +  }
 496.109 +
 496.110 +};
 496.111 +
 496.112 +}
 496.113 +
 496.114 +typedef NBitm::CDecoder<CInBuffer> CBitDecoder;
 496.115 +
 496.116 +const int kNumHuffmanBits = 15;
 496.117 +
 496.118 +class CDecoder :
 496.119 +  public ICompressCoder,
 496.120 +  public ICompressSetDecoderProperties2,
 496.121 +  public CMyUnknownImp
 496.122 +{
 496.123 +  CLzOutWindow m_OutWindowStream;
 496.124 +  CBitDecoder m_InBitStream;
 496.125 +  NHuffman::CDecoder<kNumHuffmanBits, kMainTableSize> m_MainDecoder;
 496.126 +  NHuffman::CDecoder<kNumHuffmanBits, kDistTableSize> m_DistDecoder;
 496.127 +  NHuffman::CDecoder<kNumHuffmanBits, kLenTableSize> m_LenDecoder;
 496.128 +  NHuffman::CDecoder<kNumHuffmanBits, kMMTableSize> m_MMDecoders[NMultimedia::kNumChanelsMax];
 496.129 +  NHuffman::CDecoder<kNumHuffmanBits, kLevelTableSize> m_LevelDecoder;
 496.130 +
 496.131 +  bool m_AudioMode;
 496.132 +
 496.133 +  NMultimedia::CFilter2 m_MmFilter;
 496.134 +  int m_NumChannels;
 496.135 +
 496.136 +  UInt32 m_RepDists[kNumRepDists];
 496.137 +  UInt32 m_RepDistPtr;
 496.138 +
 496.139 +  UInt32 m_LastLength;
 496.140 +  
 496.141 +  Byte m_LastLevels[kMaxTableSize];
 496.142 +
 496.143 +  UInt64 m_PackSize;
 496.144 +  bool m_IsSolid;
 496.145 +
 496.146 +  void InitStructures();
 496.147 +  UInt32 ReadBits(int numBits);
 496.148 +  bool ReadTables();
 496.149 +  bool ReadLastTables();
 496.150 +
 496.151 +  bool DecodeMm(UInt32 pos);
 496.152 +  bool DecodeLz(Int32 pos);
 496.153 +
 496.154 +  HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 496.155 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
 496.156 +
 496.157 +public:
 496.158 +  CDecoder();
 496.159 +
 496.160 +  MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2)
 496.161 +
 496.162 +  void ReleaseStreams()
 496.163 +  {
 496.164 +    m_OutWindowStream.ReleaseStream();
 496.165 +    m_InBitStream.ReleaseStream();
 496.166 +  }
 496.167 +
 496.168 +  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 496.169 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
 496.170 +
 496.171 +  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
 496.172 +
 496.173 +};
 496.174 +
 496.175 +}}
 496.176 +
 496.177 +#endif
   497.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   497.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/Rar3Decoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   497.3 @@ -0,0 +1,834 @@
   497.4 +// Rar3Decoder.cpp
   497.5 +// According to unRAR license, this code may not be used to develop
   497.6 +// a program that creates RAR archives
   497.7 + 
   497.8 +#include "StdAfx.h"
   497.9 +
  497.10 +#include "../Common/StreamUtils.h"
  497.11 +
  497.12 +#include "Rar3Decoder.h"
  497.13 +
  497.14 +namespace NCompress {
  497.15 +namespace NRar3 {
  497.16 +
  497.17 +static const UInt32 kNumAlignReps = 15;
  497.18 +
  497.19 +static const UInt32 kSymbolReadTable = 256;
  497.20 +static const UInt32 kSymbolRep = 259;
  497.21 +static const UInt32 kSymbolLen2 = kSymbolRep + kNumReps;
  497.22 +
  497.23 +static const Byte kLenStart[kLenTableSize]      = {0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224};
  497.24 +static const Byte kLenDirectBits[kLenTableSize] = {0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,  4,  5,  5,  5,  5};
  497.25 +
  497.26 +static const Byte kDistDirectBits[kDistTableSize] =
  497.27 +  {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,
  497.28 +  16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  497.29 +  18,18,18,18,18,18,18,18,18,18,18,18};
  497.30 +
  497.31 +static const Byte kLevelDirectBits[kLevelTableSize] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  497.32 +
  497.33 +static const Byte kLen2DistStarts[kNumLen2Symbols]={0,4,8,16,32,64,128,192};
  497.34 +static const Byte kLen2DistDirectBits[kNumLen2Symbols]={2,2,3, 4, 5, 6,  6,  6};
  497.35 +
  497.36 +static const UInt32 kDistLimit3 = 0x2000 - 2;
  497.37 +static const UInt32 kDistLimit4 = 0x40000 - 2;
  497.38 +
  497.39 +static const UInt32 kNormalMatchMinLen = 3;
  497.40 +
  497.41 +static const UInt32 kVmDataSizeMax = 1 << 16;
  497.42 +static const UInt32 kVmCodeSizeMax = 1 << 16;
  497.43 +
  497.44 +CDecoder::CDecoder():
  497.45 +  _window(0),
  497.46 +  _winPos(0),
  497.47 +  _wrPtr(0),
  497.48 +  _lzSize(0),
  497.49 +  _writtenFileSize(0),
  497.50 +  _vmData(0),
  497.51 +  _vmCode(0),
  497.52 +  m_IsSolid(false)
  497.53 +{
  497.54 +}
  497.55 +
  497.56 +CDecoder::~CDecoder()
  497.57 +{
  497.58 +  InitFilters();
  497.59 +  ::MidFree(_vmData);
  497.60 +  ::MidFree(_window);
  497.61 +}
  497.62 +
  497.63 +HRESULT CDecoder::WriteDataToStream(const Byte *data, UInt32 size)
  497.64 +{
  497.65 +  return WriteStream(_outStream, data, size);
  497.66 +}
  497.67 +
  497.68 +HRESULT CDecoder::WriteData(const Byte *data, UInt32 size)
  497.69 +{
  497.70 +  HRESULT res = S_OK;
  497.71 +  if (_writtenFileSize < _unpackSize)
  497.72 +  {
  497.73 +    UInt32 curSize = size;
  497.74 +    UInt64 remain = _unpackSize - _writtenFileSize;
  497.75 +    if (remain < curSize)
  497.76 +      curSize = (UInt32)remain;
  497.77 +    res = WriteDataToStream(data, curSize);
  497.78 +  }
  497.79 +  _writtenFileSize += size;
  497.80 +  return res;
  497.81 +}
  497.82 +
  497.83 +HRESULT CDecoder::WriteArea(UInt32 startPtr, UInt32 endPtr)
  497.84 +{
  497.85 +  if (startPtr <= endPtr)
  497.86 +    return WriteData(_window + startPtr, endPtr - startPtr);
  497.87 +  RINOK(WriteData(_window + startPtr, kWindowSize - startPtr));
  497.88 +  return WriteData(_window, endPtr);
  497.89 +}
  497.90 +
  497.91 +void CDecoder::ExecuteFilter(int tempFilterIndex, NVm::CBlockRef &outBlockRef)
  497.92 +{
  497.93 +  CTempFilter *tempFilter = _tempFilters[tempFilterIndex];
  497.94 +  tempFilter->InitR[6] = (UInt32)_writtenFileSize;
  497.95 +  NVm::SetValue32(&tempFilter->GlobalData[0x24], (UInt32)_writtenFileSize);
  497.96 +  NVm::SetValue32(&tempFilter->GlobalData[0x28], (UInt32)(_writtenFileSize >> 32));
  497.97 +  CFilter *filter = _filters[tempFilter->FilterIndex];
  497.98 +  _vm.Execute(filter, tempFilter, outBlockRef, filter->GlobalData);
  497.99 +  delete tempFilter;
 497.100 +  _tempFilters[tempFilterIndex] = 0;
 497.101 +}
 497.102 +
 497.103 +HRESULT CDecoder::WriteBuf()
 497.104 +{
 497.105 +  UInt32 writtenBorder = _wrPtr;
 497.106 +  UInt32 writeSize = (_winPos - writtenBorder) & kWindowMask;
 497.107 +  for (int i = 0; i < _tempFilters.Size(); i++)
 497.108 +  {
 497.109 +    CTempFilter *filter = _tempFilters[i];
 497.110 +    if (filter == NULL)
 497.111 +      continue;
 497.112 +    if (filter->NextWindow)
 497.113 +    {
 497.114 +      filter->NextWindow = false;
 497.115 +      continue;
 497.116 +    }
 497.117 +    UInt32 blockStart = filter->BlockStart;
 497.118 +    UInt32 blockSize = filter->BlockSize;
 497.119 +    if (((blockStart - writtenBorder) & kWindowMask) < writeSize)
 497.120 +    {
 497.121 +      if (writtenBorder != blockStart)
 497.122 +      {
 497.123 +        RINOK(WriteArea(writtenBorder, blockStart));
 497.124 +        writtenBorder = blockStart;
 497.125 +        writeSize = (_winPos - writtenBorder) & kWindowMask;
 497.126 +      }
 497.127 +      if (blockSize <= writeSize)
 497.128 +      {
 497.129 +        UInt32 blockEnd = (blockStart + blockSize) & kWindowMask;
 497.130 +        if (blockStart < blockEnd || blockEnd == 0)
 497.131 +          _vm.SetMemory(0, _window + blockStart, blockSize);
 497.132 +        else
 497.133 +        {
 497.134 +          UInt32 tailSize = kWindowSize - blockStart;
 497.135 +          _vm.SetMemory(0, _window + blockStart, tailSize);
 497.136 +          _vm.SetMemory(tailSize, _window, blockEnd);
 497.137 +        }
 497.138 +        NVm::CBlockRef outBlockRef;
 497.139 +        ExecuteFilter(i, outBlockRef);
 497.140 +        while (i + 1 < _tempFilters.Size())
 497.141 +        {
 497.142 +          CTempFilter *nextFilter = _tempFilters[i + 1];
 497.143 +          if (nextFilter == NULL || nextFilter->BlockStart != blockStart ||
 497.144 +              nextFilter->BlockSize != outBlockRef.Size || nextFilter->NextWindow)
 497.145 +            break;
 497.146 +          _vm.SetMemory(0, _vm.GetDataPointer(outBlockRef.Offset), outBlockRef.Size);
 497.147 +          ExecuteFilter(++i, outBlockRef);
 497.148 +        }
 497.149 +        WriteDataToStream(_vm.GetDataPointer(outBlockRef.Offset), outBlockRef.Size);
 497.150 +        _writtenFileSize += outBlockRef.Size;
 497.151 +        writtenBorder = blockEnd;
 497.152 +        writeSize = (_winPos - writtenBorder) & kWindowMask;
 497.153 +      }
 497.154 +      else
 497.155 +      {
 497.156 +        for (int j = i; j < _tempFilters.Size(); j++)
 497.157 +        {
 497.158 +          CTempFilter *filter = _tempFilters[j];
 497.159 +          if (filter != NULL && filter->NextWindow)
 497.160 +            filter->NextWindow = false;
 497.161 +        }
 497.162 +        _wrPtr = writtenBorder;
 497.163 +        return S_OK; // check it
 497.164 +      }
 497.165 +    }
 497.166 +  }
 497.167 +      
 497.168 +  _wrPtr = _winPos;
 497.169 +  return WriteArea(writtenBorder, _winPos);
 497.170 +}
 497.171 +
 497.172 +void CDecoder::InitFilters()
 497.173 +{
 497.174 +  _lastFilter = 0;
 497.175 +  int i;
 497.176 +  for (i = 0; i < _tempFilters.Size(); i++)
 497.177 +    delete _tempFilters[i];
 497.178 +  _tempFilters.Clear();
 497.179 +  for (i = 0; i < _filters.Size(); i++)
 497.180 +    delete _filters[i];
 497.181 +  _filters.Clear();
 497.182 +}
 497.183 +
 497.184 +bool CDecoder::AddVmCode(UInt32 firstByte, UInt32 codeSize)
 497.185 +{
 497.186 +  CMemBitDecoder inp;
 497.187 +  inp.Init(_vmData, codeSize);
 497.188 +
 497.189 +  UInt32 filterIndex;
 497.190 +  if (firstByte & 0x80)
 497.191 +  {
 497.192 +    filterIndex = NVm::ReadEncodedUInt32(inp);
 497.193 +    if (filterIndex == 0)
 497.194 +      InitFilters();
 497.195 +    else
 497.196 +      filterIndex--;
 497.197 +  }
 497.198 +  else
 497.199 +    filterIndex = _lastFilter;
 497.200 +  if (filterIndex > (UInt32)_filters.Size())
 497.201 +    return false;
 497.202 +  _lastFilter = filterIndex;
 497.203 +  bool newFilter = (filterIndex == (UInt32)_filters.Size());
 497.204 +
 497.205 +  CFilter *filter;
 497.206 +  if (newFilter)
 497.207 +  {
 497.208 +    // check if too many filters
 497.209 +    if (filterIndex > 1024)
 497.210 +      return false;
 497.211 +    filter = new CFilter;
 497.212 +    _filters.Add(filter);
 497.213 +  }
 497.214 +  else
 497.215 +  {
 497.216 +    filter = _filters[filterIndex];
 497.217 +    filter->ExecCount++;
 497.218 +  }
 497.219 +
 497.220 +  int numEmptyItems = 0;
 497.221 +  int i;
 497.222 +  for (i = 0; i < _tempFilters.Size(); i++)
 497.223 +  {
 497.224 +    _tempFilters[i - numEmptyItems] = _tempFilters[i];
 497.225 +    if (_tempFilters[i] == NULL)
 497.226 +      numEmptyItems++;
 497.227 +    if (numEmptyItems > 0)
 497.228 +      _tempFilters[i] = NULL;
 497.229 +  }
 497.230 +  if (numEmptyItems == 0)
 497.231 +  {
 497.232 +    _tempFilters.Add(NULL);
 497.233 +    numEmptyItems = 1;
 497.234 +  }
 497.235 +  CTempFilter *tempFilter = new CTempFilter;
 497.236 +  _tempFilters[_tempFilters.Size() - numEmptyItems] = tempFilter;
 497.237 +  tempFilter->FilterIndex = filterIndex;
 497.238 +  tempFilter->ExecCount = filter->ExecCount;
 497.239 + 
 497.240 +  UInt32 blockStart = NVm::ReadEncodedUInt32(inp);
 497.241 +  if (firstByte & 0x40)
 497.242 +    blockStart += 258;
 497.243 +  tempFilter->BlockStart = (blockStart + _winPos) & kWindowMask;
 497.244 +  if (firstByte & 0x20)
 497.245 +    filter->BlockSize = NVm::ReadEncodedUInt32(inp);
 497.246 +  tempFilter->BlockSize = filter->BlockSize;
 497.247 +  tempFilter->NextWindow = _wrPtr != _winPos && ((_wrPtr - _winPos) & kWindowMask) <= blockStart;
 497.248 +
 497.249 +  memset(tempFilter->InitR, 0, sizeof(tempFilter->InitR));
 497.250 +  tempFilter->InitR[3] = NVm::kGlobalOffset;
 497.251 +  tempFilter->InitR[4] = tempFilter->BlockSize;
 497.252 +  tempFilter->InitR[5] = tempFilter->ExecCount;
 497.253 +  if (firstByte & 0x10)
 497.254 +  {
 497.255 +    UInt32 initMask = inp.ReadBits(NVm::kNumGpRegs);
 497.256 +    for (int i = 0; i < NVm::kNumGpRegs; i++)
 497.257 +      if (initMask & (1 << i))
 497.258 +        tempFilter->InitR[i] = NVm::ReadEncodedUInt32(inp);
 497.259 +  }
 497.260 +  if (newFilter)
 497.261 +  {
 497.262 +    UInt32 vmCodeSize = NVm::ReadEncodedUInt32(inp);
 497.263 +    if (vmCodeSize >= kVmCodeSizeMax || vmCodeSize == 0)
 497.264 +      return false;
 497.265 +    for (UInt32 i = 0; i < vmCodeSize; i++)
 497.266 +      _vmCode[i] = (Byte)inp.ReadBits(8);
 497.267 +    _vm.PrepareProgram(_vmCode, vmCodeSize, filter);
 497.268 +  }
 497.269 +
 497.270 +  tempFilter->AllocateEmptyFixedGlobal();
 497.271 +
 497.272 +  Byte *globalData = &tempFilter->GlobalData[0];
 497.273 +  for (i = 0; i < NVm::kNumGpRegs; i++)
 497.274 +    NVm::SetValue32(&globalData[i * 4], tempFilter->InitR[i]);
 497.275 +  NVm::SetValue32(&globalData[NVm::NGlobalOffset::kBlockSize], tempFilter->BlockSize);
 497.276 +  NVm::SetValue32(&globalData[NVm::NGlobalOffset::kBlockPos], 0); // It was commented. why?
 497.277 +  NVm::SetValue32(&globalData[NVm::NGlobalOffset::kExecCount], tempFilter->ExecCount);
 497.278 +
 497.279 +  if (firstByte & 8)
 497.280 +  {
 497.281 +    UInt32 dataSize = NVm::ReadEncodedUInt32(inp);
 497.282 +    if (dataSize > NVm::kGlobalSize - NVm::kFixedGlobalSize)
 497.283 +      return false;
 497.284 +    CRecordVector<Byte> &globalData = tempFilter->GlobalData;
 497.285 +    int requredSize = (int)(dataSize + NVm::kFixedGlobalSize);
 497.286 +    if (globalData.Size() < requredSize)
 497.287 +    {
 497.288 +      globalData.Reserve(requredSize);
 497.289 +      for (; globalData.Size() < requredSize; i++)
 497.290 +        globalData.Add(0);
 497.291 +    }
 497.292 +    for (UInt32 i = 0; i < dataSize; i++)
 497.293 +      globalData[NVm::kFixedGlobalSize + i] = (Byte)inp.ReadBits(8);
 497.294 +  }
 497.295 +  return true;
 497.296 +}
 497.297 +
 497.298 +bool CDecoder::ReadVmCodeLZ()
 497.299 +{
 497.300 +  UInt32 firstByte = m_InBitStream.ReadBits(8);
 497.301 +  UInt32 length = (firstByte & 7) + 1;
 497.302 +  if (length == 7)
 497.303 +    length = m_InBitStream.ReadBits(8) + 7;
 497.304 +  else if (length == 8)
 497.305 +    length = m_InBitStream.ReadBits(16);
 497.306 +  if (length > kVmDataSizeMax)
 497.307 +    return false;
 497.308 +  for (UInt32 i = 0; i < length; i++)
 497.309 +    _vmData[i] = (Byte)m_InBitStream.ReadBits(8);
 497.310 +  return AddVmCode(firstByte, length);
 497.311 +}
 497.312 +
 497.313 +bool CDecoder::ReadVmCodePPM()
 497.314 +{
 497.315 +  int firstByte = DecodePpmSymbol();
 497.316 +  if (firstByte == -1)
 497.317 +    return false;
 497.318 +  UInt32 length = (firstByte & 7) + 1;
 497.319 +  if (length == 7)
 497.320 +  {
 497.321 +    int b1 = DecodePpmSymbol();
 497.322 +    if (b1 == -1)
 497.323 +      return false;
 497.324 +    length = b1 + 7;
 497.325 +  }
 497.326 +  else if (length == 8)
 497.327 +  {
 497.328 +    int b1 = DecodePpmSymbol();
 497.329 +    if (b1 == -1)
 497.330 +      return false;
 497.331 +    int b2 = DecodePpmSymbol();
 497.332 +    if (b2 == -1)
 497.333 +      return false;
 497.334 +    length = b1 * 256 + b2;
 497.335 +  }
 497.336 +  if (length > kVmDataSizeMax)
 497.337 +    return false;
 497.338 +  for (UInt32 i = 0; i < length; i++)
 497.339 +  {
 497.340 +    int b = DecodePpmSymbol();
 497.341 +    if (b == -1)
 497.342 +      return false;
 497.343 +    _vmData[i] = (Byte)b;
 497.344 +  }
 497.345 +  return AddVmCode(firstByte, length);
 497.346 +}
 497.347 +
 497.348 +#define RIF(x) { if (!(x)) return S_FALSE; }
 497.349 +
 497.350 +UInt32 CDecoder::ReadBits(int numBits) { return m_InBitStream.ReadBits(numBits); }
 497.351 +
 497.352 +/////////////////////////////////////////////////
 497.353 +// PPM
 497.354 +
 497.355 +HRESULT CDecoder::InitPPM()
 497.356 +{
 497.357 +  Byte maxOrder = (Byte)ReadBits(7);
 497.358 +
 497.359 +  bool reset = ((maxOrder & 0x20) != 0);
 497.360 +  int maxMB = 0;
 497.361 +  if (reset)
 497.362 +    maxMB = (Byte)ReadBits(8);
 497.363 +  else
 497.364 +  {
 497.365 +    if (_ppm.SubAllocator.GetSubAllocatorSize()== 0)
 497.366 +      return S_FALSE;
 497.367 +  }
 497.368 +  if (maxOrder & 0x40)
 497.369 +    PpmEscChar = (Byte)ReadBits(8);
 497.370 +  m_InBitStream.InitRangeCoder();
 497.371 +  /*
 497.372 +  if (m_InBitStream.m_BitPos != 0)
 497.373 +    return S_FALSE;
 497.374 +  */
 497.375 +  if (reset)
 497.376 +  {
 497.377 +    maxOrder = (maxOrder & 0x1F) + 1;
 497.378 +    if (maxOrder > 16)
 497.379 +      maxOrder = 16 + (maxOrder - 16) * 3;
 497.380 +    if (maxOrder == 1)
 497.381 +    {
 497.382 +      // SubAlloc.StopSubAllocator();
 497.383 +      _ppm.SubAllocator.StopSubAllocator();
 497.384 +      return S_FALSE;
 497.385 +    }
 497.386 +    // SubAlloc.StartSubAllocator(MaxMB+1);
 497.387 +    // StartModelRare(maxOrder);
 497.388 +
 497.389 +    if (!_ppm.SubAllocator.StartSubAllocator((maxMB + 1) << 20))
 497.390 +      return E_OUTOFMEMORY;
 497.391 +    _ppm.MaxOrder = 0;
 497.392 +    _ppm.StartModelRare(maxOrder);
 497.393 +
 497.394 +  }
 497.395 +  // return (minContext != NULL);
 497.396 +
 497.397 +  return S_OK;
 497.398 +}
 497.399 +
 497.400 +int CDecoder::DecodePpmSymbol() { return _ppm.DecodeSymbol(&m_InBitStream); }
 497.401 +
 497.402 +HRESULT CDecoder::DecodePPM(Int32 num, bool &keepDecompressing)
 497.403 +{
 497.404 +  keepDecompressing = false;
 497.405 +  do
 497.406 +  {
 497.407 +    if (((_wrPtr - _winPos) & kWindowMask) < 260 && _wrPtr != _winPos)
 497.408 +    {
 497.409 +      RINOK(WriteBuf());
 497.410 +      if (_writtenFileSize > _unpackSize)
 497.411 +      {
 497.412 +        keepDecompressing = false;
 497.413 +        return S_OK;
 497.414 +      }
 497.415 +    }
 497.416 +    int c = DecodePpmSymbol();
 497.417 +    if (c == -1)
 497.418 +    {
 497.419 +      // Original code sets PPMError=true here and then it returns S_OK. Why ???
 497.420 +      // return S_OK;
 497.421 +      return S_FALSE;
 497.422 +    }
 497.423 +    if (c == PpmEscChar)
 497.424 +    {
 497.425 +      int nextCh = DecodePpmSymbol();
 497.426 +      if (nextCh == 0)
 497.427 +        return ReadTables(keepDecompressing);
 497.428 +      if (nextCh == 2 || nextCh == -1)
 497.429 +        return S_OK;
 497.430 +      if (nextCh == 3)
 497.431 +      {
 497.432 +        if (!ReadVmCodePPM())
 497.433 +          return S_FALSE;
 497.434 +        continue;
 497.435 +      }
 497.436 +      if (nextCh == 4 || nextCh == 5)
 497.437 +      {
 497.438 +        UInt32 distance = 0;
 497.439 +        UInt32 length = 4;
 497.440 +        if (nextCh == 4)
 497.441 +        {
 497.442 +          for (int i = 0; i < 3; i++)
 497.443 +          {
 497.444 +            int c = DecodePpmSymbol();
 497.445 +            if (c == -1)
 497.446 +              return S_OK;
 497.447 +            distance = (distance << 8) + (Byte)c;
 497.448 +          }
 497.449 +          distance++;
 497.450 +          length += 28;
 497.451 +        }
 497.452 +        int c = DecodePpmSymbol();
 497.453 +        if (c == -1)
 497.454 +          return S_OK;
 497.455 +        length += c;
 497.456 +        if (distance >= _lzSize)
 497.457 +          return S_FALSE;
 497.458 +        CopyBlock(distance, length);
 497.459 +        num -= (Int32)length;
 497.460 +        continue;
 497.461 +      }
 497.462 +    }
 497.463 +    PutByte((Byte)c);
 497.464 +    num--;
 497.465 +  }
 497.466 +  while (num >= 0);
 497.467 +  keepDecompressing = true;
 497.468 +  return S_OK;
 497.469 +}
 497.470 +
 497.471 +/////////////////////////////////////////////////
 497.472 +// LZ
 497.473 +
 497.474 +HRESULT CDecoder::ReadTables(bool &keepDecompressing)
 497.475 +{
 497.476 +  keepDecompressing = true;
 497.477 +  ReadBits((8 - m_InBitStream.GetBitPosition()) & 7);
 497.478 +  if (ReadBits(1) != 0)
 497.479 +  {
 497.480 +    _lzMode = false;
 497.481 +    return InitPPM();
 497.482 +  }
 497.483 +
 497.484 +  _lzMode = true;
 497.485 +  PrevAlignBits = 0;
 497.486 +  PrevAlignCount = 0;
 497.487 +
 497.488 +  Byte levelLevels[kLevelTableSize];
 497.489 +  Byte newLevels[kTablesSizesSum];
 497.490 +
 497.491 +  if (ReadBits(1) == 0)
 497.492 +    memset(m_LastLevels, 0, kTablesSizesSum);
 497.493 +
 497.494 +  int i;
 497.495 +  for (i = 0; i < kLevelTableSize; i++)
 497.496 +  {
 497.497 +    UInt32 length = ReadBits(4);
 497.498 +    if (length == 15)
 497.499 +    {
 497.500 +      UInt32 zeroCount = ReadBits(4);
 497.501 +      if (zeroCount != 0)
 497.502 +      {
 497.503 +        zeroCount += 2;
 497.504 +        while (zeroCount-- > 0 && i < kLevelTableSize)
 497.505 +          levelLevels[i++]=0;
 497.506 +        i--;
 497.507 +        continue;
 497.508 +      }
 497.509 +    }
 497.510 +    levelLevels[i] = (Byte)length;
 497.511 +  }
 497.512 +  RIF(m_LevelDecoder.SetCodeLengths(levelLevels));
 497.513 +  i = 0;
 497.514 +  while (i < kTablesSizesSum)
 497.515 +  {
 497.516 +    UInt32 number = m_LevelDecoder.DecodeSymbol(&m_InBitStream);
 497.517 +    if (number < 16)
 497.518 +    {
 497.519 +      newLevels[i] = Byte((number + m_LastLevels[i]) & 15);
 497.520 +      i++;
 497.521 +    }
 497.522 +    else if (number > kLevelTableSize)
 497.523 +      return S_FALSE;
 497.524 +    else
 497.525 +    {
 497.526 +      int num;
 497.527 +      if (((number - 16) & 1) == 0)
 497.528 +        num = ReadBits(3) + 3;
 497.529 +      else
 497.530 +        num = ReadBits(7) + 11;
 497.531 +      if (number < 18)
 497.532 +      {
 497.533 +        if (i == 0)
 497.534 +          return S_FALSE;
 497.535 +        for (; num > 0 && i < kTablesSizesSum; num--, i++)
 497.536 +          newLevels[i] = newLevels[i - 1];
 497.537 +      }
 497.538 +      else
 497.539 +      {
 497.540 +        for (; num > 0 && i < kTablesSizesSum; num--)
 497.541 +          newLevels[i++] = 0;
 497.542 +      }
 497.543 +    }
 497.544 +  }
 497.545 +  TablesRead = true;
 497.546 +
 497.547 +  // original code has check here:
 497.548 +  /*
 497.549 +  if (InAddr > ReadTop)
 497.550 +  {
 497.551 +    keepDecompressing = false;
 497.552 +    return true;
 497.553 +  }
 497.554 +  */
 497.555 +
 497.556 +  RIF(m_MainDecoder.SetCodeLengths(&newLevels[0]));
 497.557 +  RIF(m_DistDecoder.SetCodeLengths(&newLevels[kMainTableSize]));
 497.558 +  RIF(m_AlignDecoder.SetCodeLengths(&newLevels[kMainTableSize + kDistTableSize]));
 497.559 +  RIF(m_LenDecoder.SetCodeLengths(&newLevels[kMainTableSize + kDistTableSize + kAlignTableSize]));
 497.560 +
 497.561 +  memcpy(m_LastLevels, newLevels, kTablesSizesSum);
 497.562 +  return S_OK;
 497.563 +}
 497.564 +
 497.565 +class CCoderReleaser
 497.566 +{
 497.567 +  CDecoder *m_Coder;
 497.568 +public:
 497.569 +  CCoderReleaser(CDecoder *coder): m_Coder(coder) {}
 497.570 +  ~CCoderReleaser()
 497.571 +  {
 497.572 +    // m_Coder->m_OutWindowStream.Flush();
 497.573 +    m_Coder->ReleaseStreams();
 497.574 +  }
 497.575 +};
 497.576 +
 497.577 +HRESULT CDecoder::ReadEndOfBlock(bool &keepDecompressing)
 497.578 +{
 497.579 +  if (ReadBits(1) != 0)
 497.580 +  {
 497.581 +    // old file
 497.582 +    TablesRead = false;
 497.583 +    return ReadTables(keepDecompressing);
 497.584 +  }
 497.585 +  // new file
 497.586 +  keepDecompressing = false;
 497.587 +  TablesRead = (ReadBits(1) == 0);
 497.588 +  return S_OK;
 497.589 +}
 497.590 +
 497.591 +UInt32 kDistStart[kDistTableSize];
 497.592 +
 497.593 +class CDistInit
 497.594 +{
 497.595 +public:
 497.596 +  CDistInit() { Init(); }
 497.597 +  void Init()
 497.598 +  {
 497.599 +    UInt32 start = 0;
 497.600 +    for (UInt32 i = 0; i < kDistTableSize; i++)
 497.601 +    {
 497.602 +      kDistStart[i] = start;
 497.603 +      start += (1 << kDistDirectBits[i]);
 497.604 +    }
 497.605 +  }
 497.606 +} g_DistInit;
 497.607 +
 497.608 +HRESULT CDecoder::DecodeLZ(bool &keepDecompressing)
 497.609 +{
 497.610 +  UInt32 rep0 = _reps[0];
 497.611 +  UInt32 rep1 = _reps[1];
 497.612 +  UInt32 rep2 = _reps[2];
 497.613 +  UInt32 rep3 = _reps[3];
 497.614 +  UInt32 length = _lastLength;
 497.615 +  for (;;)
 497.616 +  {
 497.617 +    if (((_wrPtr - _winPos) & kWindowMask) < 260 && _wrPtr != _winPos)
 497.618 +    {
 497.619 +      RINOK(WriteBuf());
 497.620 +      if (_writtenFileSize > _unpackSize)
 497.621 +      {
 497.622 +        keepDecompressing = false;
 497.623 +        return S_OK;
 497.624 +      }
 497.625 +    }
 497.626 +    UInt32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream);
 497.627 +    if (number < 256)
 497.628 +    {
 497.629 +      PutByte(Byte(number));
 497.630 +
 497.631 +      continue;
 497.632 +    }
 497.633 +    else if (number == kSymbolReadTable)
 497.634 +    {
 497.635 +      RINOK(ReadEndOfBlock(keepDecompressing));
 497.636 +      break;
 497.637 +    }
 497.638 +    else if (number == 257)
 497.639 +    {
 497.640 +      if (!ReadVmCodeLZ())
 497.641 +        return S_FALSE;
 497.642 +      continue;
 497.643 +    }
 497.644 +    else if (number == 258)
 497.645 +    {
 497.646 +    }
 497.647 +    else if (number < kSymbolRep + 4)
 497.648 +    {
 497.649 +      if (number != kSymbolRep)
 497.650 +      {
 497.651 +        UInt32 distance;
 497.652 +        if (number == kSymbolRep + 1)
 497.653 +          distance = rep1;
 497.654 +        else
 497.655 +        {
 497.656 +          if (number == kSymbolRep + 2)
 497.657 +            distance = rep2;
 497.658 +          else
 497.659 +          {
 497.660 +            distance = rep3;
 497.661 +            rep3 = rep2;
 497.662 +          }
 497.663 +          rep2 = rep1;
 497.664 +        }
 497.665 +        rep1 = rep0;
 497.666 +        rep0 = distance;
 497.667 +      }
 497.668 +
 497.669 +      UInt32 number = m_LenDecoder.DecodeSymbol(&m_InBitStream);
 497.670 +      if (number >= kLenTableSize)
 497.671 +        return S_FALSE;
 497.672 +      length = 2 + kLenStart[number] + m_InBitStream.ReadBits(kLenDirectBits[number]);
 497.673 +    }
 497.674 +    else
 497.675 +    {
 497.676 +      rep3 = rep2;
 497.677 +      rep2 = rep1;
 497.678 +      rep1 = rep0;
 497.679 +      if (number < 271)
 497.680 +      {
 497.681 +        number -= 263;
 497.682 +        rep0 = kLen2DistStarts[number] + m_InBitStream.ReadBits(kLen2DistDirectBits[number]);
 497.683 +        length = 2;
 497.684 +      }
 497.685 +      else if (number < 299)
 497.686 +      {
 497.687 +        number -= 271;
 497.688 +        length = kNormalMatchMinLen + (UInt32)kLenStart[number] + m_InBitStream.ReadBits(kLenDirectBits[number]);
 497.689 +        UInt32 number = m_DistDecoder.DecodeSymbol(&m_InBitStream);
 497.690 +        if (number >= kDistTableSize)
 497.691 +          return S_FALSE;
 497.692 +        rep0 = kDistStart[number];
 497.693 +        int numBits = kDistDirectBits[number];
 497.694 +        if (number >= (kNumAlignBits * 2) + 2)
 497.695 +        {
 497.696 +          if (numBits > kNumAlignBits)
 497.697 +            rep0 += (m_InBitStream.ReadBits(numBits - kNumAlignBits) << kNumAlignBits);
 497.698 +          if (PrevAlignCount > 0)
 497.699 +          {
 497.700 +            PrevAlignCount--;
 497.701 +            rep0 += PrevAlignBits;
 497.702 +          }
 497.703 +          else
 497.704 +          {
 497.705 +            UInt32 number = m_AlignDecoder.DecodeSymbol(&m_InBitStream);
 497.706 +            if (number < (1 << kNumAlignBits))
 497.707 +            {
 497.708 +              rep0 += number;
 497.709 +              PrevAlignBits = number;
 497.710 +            }
 497.711 +            else if (number  == (1 << kNumAlignBits))
 497.712 +            {
 497.713 +              PrevAlignCount = kNumAlignReps;
 497.714 +              rep0 += PrevAlignBits;
 497.715 +            }
 497.716 +            else
 497.717 +              return S_FALSE;
 497.718 +          }
 497.719 +        }
 497.720 +        else
 497.721 +          rep0 += m_InBitStream.ReadBits(numBits);
 497.722 +        length += ((kDistLimit4 - rep0) >> 31) + ((kDistLimit3 - rep0) >> 31);
 497.723 +      }
 497.724 +      else
 497.725 +        return S_FALSE;
 497.726 +    }
 497.727 +    if (rep0 >= _lzSize)
 497.728 +      return S_FALSE;
 497.729 +    CopyBlock(rep0, length);
 497.730 +  }
 497.731 +  _reps[0] = rep0;
 497.732 +  _reps[1] = rep1;
 497.733 +  _reps[2] = rep2;
 497.734 +  _reps[3] = rep3;
 497.735 +  _lastLength = length;
 497.736 +
 497.737 +  return S_OK;
 497.738 +}
 497.739 +
 497.740 +HRESULT CDecoder::CodeReal(ICompressProgressInfo *progress)
 497.741 +{
 497.742 +  _writtenFileSize = 0;
 497.743 +  if (!m_IsSolid)
 497.744 +  {
 497.745 +    _lzSize = 0;
 497.746 +    _winPos = 0;
 497.747 +    _wrPtr = 0;
 497.748 +    for (int i = 0; i < kNumReps; i++)
 497.749 +      _reps[i] = 0;
 497.750 +    _lastLength = 0;
 497.751 +    memset(m_LastLevels, 0, kTablesSizesSum);
 497.752 +    TablesRead = false;
 497.753 +    PpmEscChar = 2;
 497.754 +    InitFilters();
 497.755 +  }
 497.756 +  if (!m_IsSolid || !TablesRead)
 497.757 +  {
 497.758 +    bool keepDecompressing;
 497.759 +    RINOK(ReadTables(keepDecompressing));
 497.760 +    if (!keepDecompressing)
 497.761 +      return S_OK;
 497.762 +  }
 497.763 +
 497.764 +  for(;;)
 497.765 +  {
 497.766 +    bool keepDecompressing;
 497.767 +    if (_lzMode)
 497.768 +    {
 497.769 +      RINOK(DecodeLZ(keepDecompressing))
 497.770 +    }
 497.771 +    else
 497.772 +    {
 497.773 +      RINOK(DecodePPM(1 << 18, keepDecompressing))
 497.774 +    }
 497.775 +    UInt64 packSize = m_InBitStream.GetProcessedSize();
 497.776 +    RINOK(progress->SetRatioInfo(&packSize, &_writtenFileSize));
 497.777 +    if (!keepDecompressing)
 497.778 +      break;
 497.779 +  }
 497.780 +  RINOK(WriteBuf());
 497.781 +  if (_writtenFileSize < _unpackSize)
 497.782 +    return S_FALSE;
 497.783 +  // return m_OutWindowStream.Flush();
 497.784 +  return S_OK;
 497.785 +}
 497.786 +
 497.787 +STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 497.788 +    const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
 497.789 +{
 497.790 +  try
 497.791 +  {
 497.792 +    if (inSize == NULL || outSize == NULL)
 497.793 +      return E_INVALIDARG;
 497.794 +
 497.795 +    if (_vmData == 0)
 497.796 +    {
 497.797 +      _vmData = (Byte *)::MidAlloc(kVmDataSizeMax + kVmCodeSizeMax);
 497.798 +      if (_vmData == 0)
 497.799 +        return E_OUTOFMEMORY;
 497.800 +      _vmCode = _vmData + kVmDataSizeMax;
 497.801 +    }
 497.802 +    
 497.803 +    if (_window == 0)
 497.804 +    {
 497.805 +      _window = (Byte *)::MidAlloc(kWindowSize);
 497.806 +      if (_window == 0)
 497.807 +        return E_OUTOFMEMORY;
 497.808 +    }
 497.809 +    if (!m_InBitStream.Create(1 << 20))
 497.810 +      return E_OUTOFMEMORY;
 497.811 +    if (!_vm.Create())
 497.812 +      return E_OUTOFMEMORY;
 497.813 +
 497.814 +    
 497.815 +    m_InBitStream.SetStream(inStream);
 497.816 +    m_InBitStream.Init();
 497.817 +    _outStream = outStream;
 497.818 +   
 497.819 +    CCoderReleaser coderReleaser(this);
 497.820 +    _unpackSize = *outSize;
 497.821 +    return CodeReal(progress);
 497.822 +  }
 497.823 +  catch(const CInBufferException &e)  { return e.ErrorCode; }
 497.824 +  catch(...) { return S_FALSE; }
 497.825 +  // CNewException is possible here. But probably CNewException is caused
 497.826 +  // by error in data stream.
 497.827 +}
 497.828 +
 497.829 +STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
 497.830 +{
 497.831 +  if (size < 1)
 497.832 +    return E_INVALIDARG;
 497.833 +  m_IsSolid = (data[0] != 0);
 497.834 +  return S_OK;
 497.835 +}
 497.836 +
 497.837 +}}
   498.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   498.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/Rar3Decoder.h	Sat Mar 03 10:31:27 2012 -0600
   498.3 @@ -0,0 +1,301 @@
   498.4 +// Rar3Decoder.h
   498.5 +// According to unRAR license, this code may not be used to develop
   498.6 +// a program that creates RAR archives
   498.7 +
   498.8 +#ifndef __COMPRESS_RAR3_DECODER_H
   498.9 +#define __COMPRESS_RAR3_DECODER_H
  498.10 +
  498.11 +#include "../../Common/MyCom.h"
  498.12 +
  498.13 +#include "../ICoder.h"
  498.14 +
  498.15 +#include "../Common/InBuffer.h"
  498.16 +
  498.17 +#include "BitmDecoder.h"
  498.18 +#include "HuffmanDecoder.h"
  498.19 +#include "PpmdDecode.h"
  498.20 +#include "Rar3Vm.h"
  498.21 +
  498.22 +namespace NCompress {
  498.23 +namespace NRar3 {
  498.24 +
  498.25 +const UInt32 kWindowSize = 1 << 22;
  498.26 +const UInt32 kWindowMask = (kWindowSize - 1);
  498.27 +
  498.28 +const UInt32 kNumReps = 4;
  498.29 +const UInt32 kNumLen2Symbols = 8;
  498.30 +const UInt32 kLenTableSize = 28;
  498.31 +const UInt32 kMainTableSize = 256 + 1 + 1 + 1 + kNumReps + kNumLen2Symbols + kLenTableSize;
  498.32 +const UInt32 kDistTableSize = 60;
  498.33 +
  498.34 +const int kNumAlignBits = 4;
  498.35 +const UInt32 kAlignTableSize = (1 << kNumAlignBits) + 1;
  498.36 +
  498.37 +const UInt32 kLevelTableSize = 20;
  498.38 +
  498.39 +const UInt32 kTablesSizesSum = kMainTableSize + kDistTableSize + kAlignTableSize + kLenTableSize;
  498.40 +
  498.41 +class CBitDecoder
  498.42 +{
  498.43 +  UInt32 m_Value;
  498.44 +public:
  498.45 +  UInt32 m_BitPos;
  498.46 +  CInBuffer m_Stream;
  498.47 +  bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
  498.48 +  void SetStream(ISequentialInStream *inStream) { m_Stream.SetStream(inStream);}
  498.49 +  void ReleaseStream() { m_Stream.ReleaseStream();}
  498.50 +
  498.51 +  void Init()
  498.52 +  {
  498.53 +    m_Stream.Init();
  498.54 +    m_BitPos = 0;
  498.55 +    m_Value = 0;
  498.56 +    // m_BitPos = kNumBigValueBits;
  498.57 +    // Normalize();
  498.58 +  }
  498.59 +  
  498.60 +  UInt64 GetProcessedSize() const
  498.61 +    { return m_Stream.GetProcessedSize() - (m_BitPos) / 8; }
  498.62 +  UInt32 GetBitPosition() const { return ((8 - m_BitPos) & 7); }
  498.63 +  
  498.64 +  /*
  498.65 +  void Normalize()
  498.66 +  {
  498.67 +    for (;m_BitPos >= 8; m_BitPos -= 8)
  498.68 +      m_Value = (m_Value << 8) | m_Stream.ReadByte();
  498.69 +  }
  498.70 +  */
  498.71 +
  498.72 +  UInt32 GetValue(UInt32 numBits)
  498.73 +  {
  498.74 +    // return (m_Value << m_BitPos) >> (kNumBigValueBits - numBits);
  498.75 +    // return ((m_Value >> (8 - m_BitPos)) & kMask) >> (kNumValueBits - numBits);
  498.76 +    if (m_BitPos < numBits)
  498.77 +    {
  498.78 +      m_BitPos += 8;
  498.79 +      m_Value = (m_Value << 8) | m_Stream.ReadByte();
  498.80 +      if (m_BitPos < numBits)
  498.81 +      {
  498.82 +        m_BitPos += 8;
  498.83 +        m_Value = (m_Value << 8) | m_Stream.ReadByte();
  498.84 +      }
  498.85 +    }
  498.86 +    return m_Value >> (m_BitPos - numBits);
  498.87 +  }
  498.88 +  
  498.89 +  void MovePos(UInt32 numBits)
  498.90 +  {
  498.91 +    m_BitPos -= numBits;
  498.92 +    m_Value = m_Value & ((1 << m_BitPos) - 1);
  498.93 +  }
  498.94 +  
  498.95 +  UInt32 ReadBits(UInt32 numBits)
  498.96 +  {
  498.97 +    UInt32 res = GetValue(numBits);
  498.98 +    MovePos(numBits);
  498.99 +    return res;
 498.100 +  }
 498.101 +};
 498.102 +
 498.103 +const int kNumTopBits = 24;
 498.104 +const UInt32 kTopValue = (1 << kNumTopBits);
 498.105 +const UInt32 kBot = (1 << 15);
 498.106 +
 498.107 +class CRangeDecoder:public NPpmd::CRangeDecoderVirt, public CBitDecoder
 498.108 +{
 498.109 +public:
 498.110 +  UInt32 Range;
 498.111 +  UInt32 Low;
 498.112 +  UInt32 Code;
 498.113 +
 498.114 +  void Normalize()
 498.115 +  {
 498.116 +    while ((Low ^ (Low + Range)) < kTopValue ||
 498.117 +       Range < kBot && ((Range = (0 - Low) & (kBot - 1)), 1))
 498.118 +    {
 498.119 +      Code = (Code << 8) | m_Stream.ReadByte();
 498.120 +      Range <<= 8;
 498.121 +      Low <<= 8;
 498.122 +    }
 498.123 +  }
 498.124 +  
 498.125 +  void InitRangeCoder()
 498.126 +  {
 498.127 +    Code = 0;
 498.128 +    Low = 0;
 498.129 +    Range = 0xFFFFFFFF;
 498.130 +    for(int i = 0; i < 4; i++)
 498.131 +      Code = (Code << 8) | ReadBits(8);
 498.132 +  }
 498.133 +
 498.134 +  virtual UInt32 GetThreshold(UInt32 total)
 498.135 +  {
 498.136 +    return (Code - Low) / ( Range /= total);
 498.137 +  }
 498.138 +
 498.139 +  virtual void Decode(UInt32 start, UInt32 size)
 498.140 +  {
 498.141 +    Low += start * Range;
 498.142 +    Range *= size;
 498.143 +    Normalize();
 498.144 +  }
 498.145 +
 498.146 +  virtual UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)
 498.147 +  {
 498.148 +    if (((Code - Low) / (Range >>= numTotalBits)) < size0)
 498.149 +    {
 498.150 +      Decode(0, size0);
 498.151 +      return 0;
 498.152 +    }
 498.153 +    else
 498.154 +    {
 498.155 +      Decode(size0, (1 << numTotalBits) - size0);
 498.156 +      return 1;
 498.157 +    }
 498.158 +  }
 498.159 +
 498.160 +  // UInt64 GetProcessedSizeRangeCoder() {return Stream.GetProcessedSize(); }
 498.161 +};
 498.162 +
 498.163 +
 498.164 +struct CFilter: public NVm::CProgram
 498.165 +{
 498.166 +  CRecordVector<Byte> GlobalData;
 498.167 +  UInt32 BlockStart;
 498.168 +  UInt32 BlockSize;
 498.169 +  UInt32 ExecCount;
 498.170 +  CFilter(): BlockStart(0), BlockSize(0), ExecCount(0) {}
 498.171 +};
 498.172 +
 498.173 +struct CTempFilter: public NVm::CProgramInitState
 498.174 +{
 498.175 +  UInt32 BlockStart;
 498.176 +  UInt32 BlockSize;
 498.177 +  UInt32 ExecCount;
 498.178 +  bool NextWindow;
 498.179 +  
 498.180 +  UInt32 FilterIndex;
 498.181 +};
 498.182 +
 498.183 +const int kNumHuffmanBits = 15;
 498.184 +
 498.185 +class CDecoder:
 498.186 +  public ICompressCoder,
 498.187 +  public ICompressSetDecoderProperties2,
 498.188 +  public CMyUnknownImp
 498.189 +{
 498.190 +  CRangeDecoder m_InBitStream;
 498.191 +  Byte *_window;
 498.192 +  UInt32 _winPos;
 498.193 +  UInt32 _wrPtr;
 498.194 +  UInt64 _lzSize;
 498.195 +  UInt64 _unpackSize;
 498.196 +  UInt64 _writtenFileSize; // if it's > _unpackSize, then _unpackSize only written
 498.197 +  CMyComPtr<ISequentialOutStream> _outStream;
 498.198 +  NHuffman::CDecoder<kNumHuffmanBits, kMainTableSize> m_MainDecoder;
 498.199 +  NHuffman::CDecoder<kNumHuffmanBits, kDistTableSize> m_DistDecoder;
 498.200 +  NHuffman::CDecoder<kNumHuffmanBits, kAlignTableSize> m_AlignDecoder;
 498.201 +  NHuffman::CDecoder<kNumHuffmanBits, kLenTableSize> m_LenDecoder;
 498.202 +  NHuffman::CDecoder<kNumHuffmanBits, kLevelTableSize> m_LevelDecoder;
 498.203 +
 498.204 +  UInt32 _reps[kNumReps];
 498.205 +  UInt32 _lastLength;
 498.206 +  
 498.207 +  Byte m_LastLevels[kTablesSizesSum];
 498.208 +
 498.209 +  Byte *_vmData;
 498.210 +  Byte *_vmCode;
 498.211 +  NVm::CVm _vm;
 498.212 +  CRecordVector<CFilter *> _filters;
 498.213 +  CRecordVector<CTempFilter *>  _tempFilters;
 498.214 +  UInt32 _lastFilter;
 498.215 +
 498.216 +  bool m_IsSolid;
 498.217 +
 498.218 +  bool _lzMode;
 498.219 +
 498.220 +  UInt32 PrevAlignBits;
 498.221 +  UInt32 PrevAlignCount;
 498.222 +
 498.223 +  bool TablesRead;
 498.224 +
 498.225 +  NPpmd::CDecodeInfo _ppm;
 498.226 +  int PpmEscChar;
 498.227 +  
 498.228 +  HRESULT WriteDataToStream(const Byte *data, UInt32 size);
 498.229 +  HRESULT WriteData(const Byte *data, UInt32 size);
 498.230 +  HRESULT WriteArea(UInt32 startPtr, UInt32 endPtr);
 498.231 +  void ExecuteFilter(int tempFilterIndex, NVm::CBlockRef &outBlockRef);
 498.232 +  HRESULT WriteBuf();
 498.233 +
 498.234 +  void InitFilters();
 498.235 +  bool AddVmCode(UInt32 firstByte, UInt32 codeSize);
 498.236 +  bool ReadVmCodeLZ();
 498.237 +  bool ReadVmCodePPM();
 498.238 +  
 498.239 +  UInt32 ReadBits(int numBits);
 498.240 +
 498.241 +  HRESULT InitPPM();
 498.242 +  int DecodePpmSymbol();
 498.243 +  HRESULT DecodePPM(Int32 num, bool &keepDecompressing);
 498.244 +
 498.245 +  HRESULT ReadTables(bool &keepDecompressing);
 498.246 +  HRESULT ReadEndOfBlock(bool &keepDecompressing);
 498.247 +  HRESULT DecodeLZ(bool &keepDecompressing);
 498.248 +  HRESULT CodeReal(ICompressProgressInfo *progress);
 498.249 +public:
 498.250 +  CDecoder();
 498.251 +  ~CDecoder();
 498.252 +
 498.253 +  MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2)
 498.254 +
 498.255 +  void ReleaseStreams()
 498.256 +  {
 498.257 +    _outStream.Release();
 498.258 +    m_InBitStream.ReleaseStream();
 498.259 +  }
 498.260 +
 498.261 +  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 498.262 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
 498.263 +
 498.264 +  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
 498.265 +
 498.266 +  void CopyBlock(UInt32 distance, UInt32 len)
 498.267 +  {
 498.268 +    _lzSize += len;
 498.269 +    UInt32 pos = (_winPos - distance - 1) & kWindowMask;
 498.270 +    Byte *window = _window;
 498.271 +    UInt32 winPos = _winPos;
 498.272 +    if (kWindowSize - winPos > len && kWindowSize - pos > len)
 498.273 +    {
 498.274 +      const Byte *src = window + pos;
 498.275 +      Byte *dest = window + winPos;
 498.276 +      _winPos += len;
 498.277 +      do
 498.278 +        *dest++ = *src++;
 498.279 +      while(--len != 0);
 498.280 +      return;
 498.281 +    }
 498.282 +    do
 498.283 +    {
 498.284 +      window[winPos] = window[pos];
 498.285 +      winPos = (winPos + 1) & kWindowMask;
 498.286 +      pos = (pos + 1) & kWindowMask;
 498.287 +    }
 498.288 +    while(--len != 0);
 498.289 +    _winPos = winPos;
 498.290 +  }
 498.291 +  
 498.292 +  void PutByte(Byte b)
 498.293 +  {
 498.294 +    _window[_winPos] = b;
 498.295 +    _winPos = (_winPos + 1) & kWindowMask;
 498.296 +    _lzSize++;
 498.297 +  }
 498.298 +
 498.299 +
 498.300 +};
 498.301 +
 498.302 +}}
 498.303 +
 498.304 +#endif
   499.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   499.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/Rar3Vm.cpp	Sat Mar 03 10:31:27 2012 -0600
   499.3 @@ -0,0 +1,1094 @@
   499.4 +// Rar3Vm.cpp
   499.5 +// According to unRAR license, this code may not be used to develop
   499.6 +// a program that creates RAR archives
   499.7 +
   499.8 +/*
   499.9 +Note:
  499.10 +  Due to performance considerations Rar VM may set Flags C incorrectly
  499.11 +  for some operands (SHL x, 0, ... ).
  499.12 +  Check implementation of concrete VM command
  499.13 +  to see if it sets flags right.
  499.14 +*/
  499.15 +
  499.16 +#include "StdAfx.h"
  499.17 +
  499.18 +extern "C"
  499.19 +{
  499.20 +#include "../../../C/7zCrc.h"
  499.21 +#include "../../../C/Alloc.h"
  499.22 +}
  499.23 +
  499.24 +#include "Rar3Vm.h"
  499.25 +
  499.26 +namespace NCompress {
  499.27 +namespace NRar3 {
  499.28 +
  499.29 +UInt32 CMemBitDecoder::ReadBits(int numBits)
  499.30 +{
  499.31 +  UInt32 res = 0;
  499.32 +  for (;;)
  499.33 +  {
  499.34 +    Byte b = _bitPos < _bitSize ? _data[_bitPos >> 3] : 0;
  499.35 +    int avail = (int)(8 - (_bitPos & 7));
  499.36 +    if (numBits <= avail)
  499.37 +    {
  499.38 +      _bitPos += numBits;
  499.39 +      return res | (b >> (avail - numBits)) & ((1 << numBits) - 1);
  499.40 +    }
  499.41 +    numBits -= avail;
  499.42 +    res |= (UInt32)(b & ((1 << avail) - 1)) << numBits;
  499.43 +    _bitPos += avail;
  499.44 +  }
  499.45 +}
  499.46 +
  499.47 +UInt32 CMemBitDecoder::ReadBit() { return ReadBits(1); }
  499.48 +
  499.49 +namespace NVm {
  499.50 +
  499.51 +static const UInt32 kStackRegIndex = kNumRegs - 1;
  499.52 +
  499.53 +static const UInt32 FLAG_C = 1;
  499.54 +static const UInt32 FLAG_Z = 2;
  499.55 +static const UInt32 FLAG_S = 0x80000000;
  499.56 +
  499.57 +static const Byte CF_OP0 = 0;
  499.58 +static const Byte CF_OP1 = 1;
  499.59 +static const Byte CF_OP2 = 2;
  499.60 +static const Byte CF_OPMASK = 3;
  499.61 +static const Byte CF_BYTEMODE = 4;
  499.62 +static const Byte CF_JUMP = 8;
  499.63 +static const Byte CF_PROC = 16;
  499.64 +static const Byte CF_USEFLAGS = 32;
  499.65 +static const Byte CF_CHFLAGS = 64;
  499.66 +
  499.67 +static Byte kCmdFlags[]=
  499.68 +{
  499.69 +  /* CMD_MOV   */ CF_OP2 | CF_BYTEMODE,
  499.70 +  /* CMD_CMP   */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
  499.71 +  /* CMD_ADD   */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
  499.72 +  /* CMD_SUB   */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
  499.73 +  /* CMD_JZ    */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
  499.74 +  /* CMD_JNZ   */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
  499.75 +  /* CMD_INC   */ CF_OP1 | CF_BYTEMODE | CF_CHFLAGS,
  499.76 +  /* CMD_DEC   */ CF_OP1 | CF_BYTEMODE | CF_CHFLAGS,
  499.77 +  /* CMD_JMP   */ CF_OP1 | CF_JUMP,
  499.78 +  /* CMD_XOR   */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
  499.79 +  /* CMD_AND   */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
  499.80 +  /* CMD_OR    */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
  499.81 +  /* CMD_TEST  */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
  499.82 +  /* CMD_JS    */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
  499.83 +  /* CMD_JNS   */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
  499.84 +  /* CMD_JB    */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
  499.85 +  /* CMD_JBE   */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
  499.86 +  /* CMD_JA    */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
  499.87 +  /* CMD_JAE   */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
  499.88 +  /* CMD_PUSH  */ CF_OP1,
  499.89 +  /* CMD_POP   */ CF_OP1,
  499.90 +  /* CMD_CALL  */ CF_OP1 | CF_PROC,
  499.91 +  /* CMD_RET   */ CF_OP0 | CF_PROC,
  499.92 +  /* CMD_NOT   */ CF_OP1 | CF_BYTEMODE,
  499.93 +  /* CMD_SHL   */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
  499.94 +  /* CMD_SHR   */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
  499.95 +  /* CMD_SAR   */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
  499.96 +  /* CMD_NEG   */ CF_OP1 | CF_BYTEMODE | CF_CHFLAGS,
  499.97 +  /* CMD_PUSHA */ CF_OP0,
  499.98 +  /* CMD_POPA  */ CF_OP0,
  499.99 +  /* CMD_PUSHF */ CF_OP0 | CF_USEFLAGS,
 499.100 +  /* CMD_POPF  */ CF_OP0 | CF_CHFLAGS,
 499.101 +  /* CMD_MOVZX */ CF_OP2,
 499.102 +  /* CMD_MOVSX */ CF_OP2,
 499.103 +  /* CMD_XCHG  */ CF_OP2 | CF_BYTEMODE,
 499.104 +  /* CMD_MUL   */ CF_OP2 | CF_BYTEMODE,
 499.105 +  /* CMD_DIV   */ CF_OP2 | CF_BYTEMODE,
 499.106 +  /* CMD_ADC   */ CF_OP2 | CF_BYTEMODE | CF_USEFLAGS | CF_CHFLAGS ,
 499.107 +  /* CMD_SBB   */ CF_OP2 | CF_BYTEMODE | CF_USEFLAGS | CF_CHFLAGS ,
 499.108 +  /* CMD_PRINT */ CF_OP0
 499.109 +};
 499.110 +
 499.111 +CVm::CVm(): Mem(NULL) {}
 499.112 +
 499.113 +bool CVm::Create()
 499.114 +{
 499.115 +  if (Mem == NULL)
 499.116 +    Mem = (Byte *)::MyAlloc(kSpaceSize + 4);
 499.117 +  return (Mem != NULL);
 499.118 +}
 499.119 +
 499.120 +CVm::~CVm()
 499.121 +{
 499.122 +  ::MyFree(Mem);
 499.123 +}
 499.124 +
 499.125 +// CVm::Execute can change CProgram object: it clears progarm if VM returns error.
 499.126 +
 499.127 +bool CVm::Execute(CProgram *prg, const CProgramInitState *initState,
 499.128 +    CBlockRef &outBlockRef, CRecordVector<Byte> &outGlobalData)
 499.129 +{
 499.130 +  memcpy(R, initState->InitR, sizeof(initState->InitR));
 499.131 +  R[kStackRegIndex] = kSpaceSize;
 499.132 +  R[kNumRegs] = 0;
 499.133 +  Flags = 0;
 499.134 +
 499.135 +  UInt32 globalSize = MyMin((UInt32)initState->GlobalData.Size(), kGlobalSize);
 499.136 +  if (globalSize != 0)
 499.137 +    memcpy(Mem + kGlobalOffset, &initState->GlobalData[0], globalSize);
 499.138 +  UInt32 staticSize = MyMin((UInt32)prg->StaticData.Size(), kGlobalSize - globalSize);
 499.139 +  if (staticSize != 0)
 499.140 +    memcpy(Mem + kGlobalOffset + globalSize, &prg->StaticData[0], staticSize);
 499.141 +
 499.142 +  bool res = true;
 499.143 +  #ifdef RARVM_STANDARD_FILTERS
 499.144 +  if (prg->StandardFilterIndex >= 0)
 499.145 +    ExecuteStandardFilter(prg->StandardFilterIndex);
 499.146 +  else
 499.147 +  #endif
 499.148 +  {
 499.149 +    res = ExecuteCode(prg);
 499.150 +    if (!res)
 499.151 +      prg->Commands[0].OpCode = CMD_RET;
 499.152 +  }
 499.153 +  UInt32 newBlockPos = GetFixedGlobalValue32(NGlobalOffset::kBlockPos) & kSpaceMask;
 499.154 +  UInt32 newBlockSize = GetFixedGlobalValue32(NGlobalOffset::kBlockSize) & kSpaceMask;
 499.155 +  if (newBlockPos + newBlockSize >= kSpaceSize)
 499.156 +    newBlockPos = newBlockSize = 0;
 499.157 +  outBlockRef.Offset = newBlockPos;
 499.158 +  outBlockRef.Size = newBlockSize;
 499.159 +
 499.160 +  outGlobalData.Clear();
 499.161 +  UInt32 dataSize = GetFixedGlobalValue32(NGlobalOffset::kGlobalMemOutSize);
 499.162 +  dataSize = MyMin(dataSize, kGlobalSize - kFixedGlobalSize);
 499.163 +  if (dataSize != 0)
 499.164 +  {
 499.165 +    dataSize += kFixedGlobalSize;
 499.166 +    outGlobalData.Reserve(dataSize);
 499.167 +    for (UInt32 i = 0; i < dataSize; i++)
 499.168 +      outGlobalData.Add(Mem[kGlobalOffset + i]);
 499.169 +  }
 499.170 +  return res;
 499.171 +}
 499.172 +
 499.173 +
 499.174 +#define SET_IP(IP) \
 499.175 +  if ((IP) >= numCommands) return true; \
 499.176 +  if (--maxOpCount <= 0) return false; \
 499.177 +  cmd = commands + (IP);
 499.178 +
 499.179 +#define GET_FLAG_S_B(res) (((res) & 0x80) ? FLAG_S : 0)
 499.180 +#define SET_IP_OP1 { UInt32 val = GetOperand32(&cmd->Op1); SET_IP(val); }
 499.181 +#define FLAGS_UPDATE_SZ Flags = res == 0 ? FLAG_Z : res & FLAG_S
 499.182 +#define FLAGS_UPDATE_SZ_B Flags = (res & 0xFF) == 0 ? FLAG_Z : GET_FLAG_S_B(res)
 499.183 +
 499.184 +UInt32 CVm::GetOperand32(const COperand *op) const
 499.185 +{
 499.186 +  switch(op->Type)
 499.187 +  {
 499.188 +    case OP_TYPE_REG: return R[op->Data];
 499.189 +    case OP_TYPE_REGMEM: return GetValue32(&Mem[(op->Base + R[op->Data]) & kSpaceMask]);
 499.190 +    default: return op->Data;
 499.191 +  }
 499.192 +}
 499.193 +
 499.194 +void CVm::SetOperand32(const COperand *op, UInt32 val)
 499.195 +{
 499.196 +  switch(op->Type)
 499.197 +  {
 499.198 +    case OP_TYPE_REG: R[op->Data] = val; return;
 499.199 +    case OP_TYPE_REGMEM: SetValue32(&Mem[(op->Base + R[op->Data]) & kSpaceMask], val); return;
 499.200 +  }
 499.201 +}
 499.202 +
 499.203 +Byte CVm::GetOperand8(const COperand *op) const
 499.204 +{
 499.205 +  switch(op->Type)
 499.206 +  {
 499.207 +    case OP_TYPE_REG: return (Byte)R[op->Data];
 499.208 +    case OP_TYPE_REGMEM: return Mem[(op->Base + R[op->Data]) & kSpaceMask];;
 499.209 +    default: return (Byte)op->Data;
 499.210 +  }
 499.211 +}
 499.212 +
 499.213 +void CVm::SetOperand8(const COperand *op, Byte val)
 499.214 +{
 499.215 +  switch(op->Type)
 499.216 +  {
 499.217 +    case OP_TYPE_REG: R[op->Data] = (R[op->Data] & 0xFFFFFF00) | val; return;
 499.218 +    case OP_TYPE_REGMEM: Mem[(op->Base + R[op->Data]) & kSpaceMask] = val; return;
 499.219 +  }
 499.220 +}
 499.221 +
 499.222 +UInt32 CVm::GetOperand(bool byteMode, const COperand *op) const
 499.223 +{
 499.224 +  if (byteMode)
 499.225 +    return GetOperand8(op);
 499.226 +  return GetOperand32(op);
 499.227 +}
 499.228 +
 499.229 +void CVm::SetOperand(bool byteMode, const COperand *op, UInt32 val)
 499.230 +{
 499.231 +  if (byteMode)
 499.232 +    SetOperand8(op, (Byte)(val & 0xFF));
 499.233 +  else
 499.234 +    SetOperand32(op, val);
 499.235 +}
 499.236 +
 499.237 +bool CVm::ExecuteCode(const CProgram *prg)
 499.238 +{
 499.239 +  Int32 maxOpCount = 25000000;
 499.240 +  const CCommand *commands = &prg->Commands[0];
 499.241 +  const CCommand *cmd = commands;
 499.242 +  UInt32 numCommands = prg->Commands.Size();
 499.243 +  for (;;)
 499.244 +  {
 499.245 +    switch(cmd->OpCode)
 499.246 +    {
 499.247 +      #ifndef RARVM_NO_VM
 499.248 +      
 499.249 +      case CMD_MOV:
 499.250 +        SetOperand32(&cmd->Op1, GetOperand32(&cmd->Op2));
 499.251 +        break;
 499.252 +      case CMD_MOVB:
 499.253 +        SetOperand8(&cmd->Op1, GetOperand8(&cmd->Op2));
 499.254 +        break;
 499.255 +      case CMD_CMP:
 499.256 +        {
 499.257 +          UInt32 v1 = GetOperand32(&cmd->Op1);
 499.258 +          UInt32 res = v1 - GetOperand32(&cmd->Op2);
 499.259 +          Flags = res == 0 ? FLAG_Z : (res > v1) | (res & FLAG_S);
 499.260 +        }
 499.261 +        break;
 499.262 +      case CMD_CMPB:
 499.263 +        {
 499.264 +          Byte v1 = GetOperand8(&cmd->Op1);
 499.265 +          Byte res = v1 - GetOperand8(&cmd->Op2);
 499.266 +          res &= 0xFF;
 499.267 +          Flags = res == 0 ? FLAG_Z : (res > v1) | GET_FLAG_S_B(res);
 499.268 +        }
 499.269 +        break;
 499.270 +      case CMD_ADD:
 499.271 +        {
 499.272 +          UInt32 v1 = GetOperand32(&cmd->Op1);
 499.273 +          UInt32 res = v1 + GetOperand32(&cmd->Op2);
 499.274 +          SetOperand32(&cmd->Op1, res);
 499.275 +          Flags = (res < v1) | (res == 0 ? FLAG_Z : (res & FLAG_S));
 499.276 +        }
 499.277 +        break;
 499.278 +      case CMD_ADDB:
 499.279 +        {
 499.280 +          Byte v1 = GetOperand8(&cmd->Op1);
 499.281 +          Byte res = v1 + GetOperand8(&cmd->Op2);
 499.282 +          res &= 0xFF;
 499.283 +          SetOperand8(&cmd->Op1, (Byte)res);
 499.284 +          Flags = (res < v1) | (res == 0 ? FLAG_Z : GET_FLAG_S_B(res));
 499.285 +        }
 499.286 +        break;
 499.287 +      case CMD_ADC:
 499.288 +        {
 499.289 +          UInt32 v1 = GetOperand(cmd->ByteMode, &cmd->Op1);
 499.290 +          UInt32 FC = (Flags & FLAG_C);
 499.291 +          UInt32 res = v1 + GetOperand(cmd->ByteMode, &cmd->Op2) + FC;
 499.292 +          if (cmd->ByteMode)
 499.293 +            res &= 0xFF;
 499.294 +          SetOperand(cmd->ByteMode, &cmd->Op1, res);
 499.295 +          Flags = (res < v1 || res == v1 && FC) | (res == 0 ? FLAG_Z : (res & FLAG_S));
 499.296 +        }
 499.297 +        break;
 499.298 +      case CMD_SUB:
 499.299 +        {
 499.300 +          UInt32 v1 = GetOperand32(&cmd->Op1);
 499.301 +          UInt32 res = v1 - GetOperand32(&cmd->Op2);
 499.302 +          SetOperand32(&cmd->Op1, res);
 499.303 +          Flags = res == 0 ? FLAG_Z : (res > v1) | (res & FLAG_S);
 499.304 +        }
 499.305 +        break;
 499.306 +      case CMD_SUBB:
 499.307 +        {
 499.308 +          UInt32 v1 = GetOperand8(&cmd->Op1);
 499.309 +          UInt32 res = v1 - GetOperand8(&cmd->Op2);
 499.310 +          SetOperand8(&cmd->Op1, (Byte)res);
 499.311 +          Flags = res == 0 ? FLAG_Z : (res > v1) | (res & FLAG_S);
 499.312 +        }
 499.313 +        break;
 499.314 +      case CMD_SBB:
 499.315 +        {
 499.316 +          UInt32 v1 = GetOperand(cmd->ByteMode, &cmd->Op1);
 499.317 +          UInt32 FC = (Flags & FLAG_C);
 499.318 +          UInt32 res = v1 - GetOperand(cmd->ByteMode, &cmd->Op2) - FC;
 499.319 +          // Flags = res == 0 ? FLAG_Z : (res > v1 || res == v1 && FC) | (res & FLAG_S);
 499.320 +          if (cmd->ByteMode)
 499.321 +            res &= 0xFF;
 499.322 +          SetOperand(cmd->ByteMode, &cmd->Op1, res);
 499.323 +          Flags = (res > v1 || res == v1 && FC) | (res == 0 ? FLAG_Z : (res & FLAG_S));
 499.324 +        }
 499.325 +        break;
 499.326 +      case CMD_INC:
 499.327 +        {
 499.328 +          UInt32 res = GetOperand32(&cmd->Op1) + 1;
 499.329 +          SetOperand32(&cmd->Op1, res);
 499.330 +          FLAGS_UPDATE_SZ;
 499.331 +        }
 499.332 +        break;
 499.333 +      case CMD_INCB:
 499.334 +        {
 499.335 +          Byte res = GetOperand8(&cmd->Op1) + 1;
 499.336 +          SetOperand8(&cmd->Op1, res);;
 499.337 +          FLAGS_UPDATE_SZ_B;
 499.338 +        }
 499.339 +        break;
 499.340 +      case CMD_DEC:
 499.341 +        {
 499.342 +          UInt32 res = GetOperand32(&cmd->Op1) - 1;
 499.343 +          SetOperand32(&cmd->Op1, res);
 499.344 +          FLAGS_UPDATE_SZ;
 499.345 +        }
 499.346 +        break;
 499.347 +      case CMD_DECB:
 499.348 +        {
 499.349 +          Byte res = GetOperand8(&cmd->Op1) - 1;
 499.350 +          SetOperand8(&cmd->Op1, res);;
 499.351 +          FLAGS_UPDATE_SZ_B;
 499.352 +        }
 499.353 +        break;
 499.354 +      case CMD_XOR:
 499.355 +        {
 499.356 +          UInt32 res = GetOperand32(&cmd->Op1) ^ GetOperand32(&cmd->Op2);
 499.357 +          SetOperand32(&cmd->Op1, res);
 499.358 +          FLAGS_UPDATE_SZ;
 499.359 +        }
 499.360 +        break;
 499.361 +      case CMD_XORB:
 499.362 +        {
 499.363 +          Byte res = GetOperand8(&cmd->Op1) ^ GetOperand8(&cmd->Op2);
 499.364 +          SetOperand8(&cmd->Op1, res);
 499.365 +          FLAGS_UPDATE_SZ_B;
 499.366 +        }
 499.367 +        break;
 499.368 +      case CMD_AND:
 499.369 +        {
 499.370 +          UInt32 res = GetOperand32(&cmd->Op1) & GetOperand32(&cmd->Op2);
 499.371 +          SetOperand32(&cmd->Op1, res);
 499.372 +          FLAGS_UPDATE_SZ;
 499.373 +        }
 499.374 +        break;
 499.375 +      case CMD_ANDB:
 499.376 +        {
 499.377 +          Byte res = GetOperand8(&cmd->Op1) & GetOperand8(&cmd->Op2);
 499.378 +          SetOperand8(&cmd->Op1, res);
 499.379 +          FLAGS_UPDATE_SZ_B;
 499.380 +        }
 499.381 +        break;
 499.382 +      case CMD_OR:
 499.383 +        {
 499.384 +          UInt32 res = GetOperand32(&cmd->Op1) | GetOperand32(&cmd->Op2);
 499.385 +          SetOperand32(&cmd->Op1, res);
 499.386 +          FLAGS_UPDATE_SZ;
 499.387 +        }
 499.388 +        break;
 499.389 +      case CMD_ORB:
 499.390 +        {
 499.391 +          Byte res = GetOperand8(&cmd->Op1) | GetOperand8(&cmd->Op2);
 499.392 +          SetOperand8(&cmd->Op1, res);
 499.393 +          FLAGS_UPDATE_SZ_B;
 499.394 +        }
 499.395 +        break;
 499.396 +      case CMD_TEST:
 499.397 +        {
 499.398 +          UInt32 res = GetOperand32(&cmd->Op1) & GetOperand32(&cmd->Op2);
 499.399 +          FLAGS_UPDATE_SZ;
 499.400 +        }
 499.401 +        break;
 499.402 +      case CMD_TESTB:
 499.403 +        {
 499.404 +          Byte res = GetOperand8(&cmd->Op1) & GetOperand8(&cmd->Op2);
 499.405 +          FLAGS_UPDATE_SZ_B;
 499.406 +        }
 499.407 +        break;
 499.408 +      case CMD_NOT:
 499.409 +        SetOperand(cmd->ByteMode, &cmd->Op1, ~GetOperand(cmd->ByteMode, &cmd->Op1));
 499.410 +        break;
 499.411 +      case CMD_NEG:
 499.412 +        {
 499.413 +          UInt32 res = 0 - GetOperand32(&cmd->Op1);
 499.414 +          SetOperand32(&cmd->Op1, res);
 499.415 +          Flags = res == 0 ? FLAG_Z : FLAG_C | (res & FLAG_S);
 499.416 +        }
 499.417 +        break;
 499.418 +      case CMD_NEGB:
 499.419 +        {
 499.420 +          Byte res = (Byte)(0 - GetOperand8(&cmd->Op1));
 499.421 +          SetOperand8(&cmd->Op1, res);
 499.422 +          Flags = res == 0 ? FLAG_Z : FLAG_C | GET_FLAG_S_B(res);
 499.423 +        }
 499.424 +        break;
 499.425 +
 499.426 +      case CMD_SHL:
 499.427 +        {
 499.428 +          UInt32 v1 = GetOperand32(&cmd->Op1);
 499.429 +          int v2 = (int)GetOperand32(&cmd->Op2);
 499.430 +          UInt32 res = v1 << v2;
 499.431 +          SetOperand32(&cmd->Op1, res);
 499.432 +          Flags = (res == 0 ? FLAG_Z : (res & FLAG_S)) | ((v1 << (v2 - 1)) & 0x80000000 ? FLAG_C : 0);
 499.433 +        }
 499.434 +        break;
 499.435 +      case CMD_SHLB:
 499.436 +        {
 499.437 +          Byte v1 = GetOperand8(&cmd->Op1);
 499.438 +          int v2 = (int)GetOperand8(&cmd->Op2);
 499.439 +          Byte res = (Byte)(v1 << v2);
 499.440 +          SetOperand8(&cmd->Op1, res);
 499.441 +          Flags = (res == 0 ? FLAG_Z : GET_FLAG_S_B(res)) | ((v1 << (v2 - 1)) & 0x80 ? FLAG_C : 0);
 499.442 +        }
 499.443 +        break;
 499.444 +      case CMD_SHR:
 499.445 +        {
 499.446 +          UInt32 v1 = GetOperand32(&cmd->Op1);
 499.447 +          int v2 = (int)GetOperand32(&cmd->Op2);
 499.448 +          UInt32 res = v1 >> v2;
 499.449 +          SetOperand32(&cmd->Op1, res);
 499.450 +          Flags = (res == 0 ? FLAG_Z : (res & FLAG_S)) | ((v1 >> (v2 - 1)) & FLAG_C);
 499.451 +        }
 499.452 +        break;
 499.453 +      case CMD_SHRB:
 499.454 +        {
 499.455 +          Byte v1 = GetOperand8(&cmd->Op1);
 499.456 +          int v2 = (int)GetOperand8(&cmd->Op2);
 499.457 +          Byte res = (Byte)(v1 >> v2);
 499.458 +          SetOperand8(&cmd->Op1, res);
 499.459 +          Flags = (res == 0 ? FLAG_Z : GET_FLAG_S_B(res)) | ((v1 >> (v2 - 1)) & FLAG_C);
 499.460 +        }
 499.461 +        break;
 499.462 +      case CMD_SAR:
 499.463 +        {
 499.464 +          UInt32 v1 = GetOperand32(&cmd->Op1);
 499.465 +          int v2 = (int)GetOperand32(&cmd->Op2);
 499.466 +          UInt32 res = UInt32(((Int32)v1) >> v2);
 499.467 +          SetOperand32(&cmd->Op1, res);
 499.468 +          Flags= (res == 0 ? FLAG_Z : (res & FLAG_S)) | ((v1 >> (v2 - 1)) & FLAG_C);
 499.469 +        }
 499.470 +        break;
 499.471 +      case CMD_SARB:
 499.472 +        {
 499.473 +          Byte v1 = GetOperand8(&cmd->Op1);
 499.474 +          int v2 = (int)GetOperand8(&cmd->Op2);
 499.475 +          Byte res = (Byte)(((signed char)v1) >> v2);
 499.476 +          SetOperand8(&cmd->Op1, res);
 499.477 +          Flags= (res == 0 ? FLAG_Z : GET_FLAG_S_B(res)) | ((v1 >> (v2 - 1)) & FLAG_C);
 499.478 +        }
 499.479 +        break;
 499.480 +
 499.481 +      case CMD_JMP:
 499.482 +        SET_IP_OP1;
 499.483 +        continue;
 499.484 +      case CMD_JZ:
 499.485 +        if ((Flags & FLAG_Z) != 0)
 499.486 +        {
 499.487 +          SET_IP_OP1;
 499.488 +          continue;
 499.489 +        }
 499.490 +        break;
 499.491 +      case CMD_JNZ:
 499.492 +        if ((Flags & FLAG_Z) == 0)
 499.493 +        {
 499.494 +          SET_IP_OP1;
 499.495 +          continue;
 499.496 +        }
 499.497 +        break;
 499.498 +      case CMD_JS:
 499.499 +        if ((Flags & FLAG_S) != 0)
 499.500 +        {
 499.501 +          SET_IP_OP1;
 499.502 +          continue;
 499.503 +        }
 499.504 +        break;
 499.505 +      case CMD_JNS:
 499.506 +        if ((Flags & FLAG_S) == 0)
 499.507 +        {
 499.508 +          SET_IP_OP1;
 499.509 +          continue;
 499.510 +        }
 499.511 +        break;
 499.512 +      case CMD_JB:
 499.513 +        if ((Flags & FLAG_C) != 0)
 499.514 +        {
 499.515 +          SET_IP_OP1;
 499.516 +          continue;
 499.517 +        }
 499.518 +        break;
 499.519 +      case CMD_JBE:
 499.520 +        if ((Flags & (FLAG_C | FLAG_Z)) != 0)
 499.521 +        {
 499.522 +          SET_IP_OP1;
 499.523 +          continue;
 499.524 +        }
 499.525 +        break;
 499.526 +      case CMD_JA:
 499.527 +        if ((Flags & (FLAG_C | FLAG_Z)) == 0)
 499.528 +        {
 499.529 +          SET_IP_OP1;
 499.530 +          continue;
 499.531 +        }
 499.532 +        break;
 499.533 +      case CMD_JAE:
 499.534 +        if ((Flags & FLAG_C) == 0)
 499.535 +        {
 499.536 +          SET_IP_OP1;
 499.537 +          continue;
 499.538 +        }
 499.539 +        break;
 499.540 +      
 499.541 +      case CMD_PUSH:
 499.542 +        R[kStackRegIndex] -= 4;
 499.543 +        SetValue32(&Mem[R[kStackRegIndex] & kSpaceMask], GetOperand32(&cmd->Op1));
 499.544 +        break;
 499.545 +      case CMD_POP:
 499.546 +        SetOperand32(&cmd->Op1, GetValue32(&Mem[R[kStackRegIndex] & kSpaceMask]));
 499.547 +        R[kStackRegIndex] += 4;
 499.548 +        break;
 499.549 +      case CMD_CALL:
 499.550 +        R[kStackRegIndex] -= 4;
 499.551 +        SetValue32(&Mem[R[kStackRegIndex] & kSpaceMask], (UInt32)(cmd - commands + 1));
 499.552 +        SET_IP_OP1;
 499.553 +        continue;
 499.554 +
 499.555 +      case CMD_PUSHA:
 499.556 +        {
 499.557 +          for (UInt32 i = 0, SP = R[kStackRegIndex] - 4; i < kNumRegs; i++, SP -= 4)
 499.558 +            SetValue32(&Mem[SP & kSpaceMask], R[i]);
 499.559 +          R[kStackRegIndex] -= kNumRegs * 4;
 499.560 +        }
 499.561 +        break;
 499.562 +      case CMD_POPA:
 499.563 +        {
 499.564 +          for (UInt32 i = 0, SP = R[kStackRegIndex]; i < kNumRegs; i++, SP += 4)
 499.565 +            R[kStackRegIndex - i] = GetValue32(&Mem[SP & kSpaceMask]);
 499.566 +        }
 499.567 +        break;
 499.568 +      case CMD_PUSHF:
 499.569 +        R[kStackRegIndex] -= 4;
 499.570 +        SetValue32(&Mem[R[kStackRegIndex]&kSpaceMask], Flags);
 499.571 +        break;
 499.572 +      case CMD_POPF:
 499.573 +        Flags = GetValue32(&Mem[R[kStackRegIndex] & kSpaceMask]);
 499.574 +        R[kStackRegIndex] += 4;
 499.575 +        break;
 499.576 +      
 499.577 +      case CMD_MOVZX:
 499.578 +        SetOperand32(&cmd->Op1, GetOperand8(&cmd->Op2));
 499.579 +        break;
 499.580 +      case CMD_MOVSX:
 499.581 +        SetOperand32(&cmd->Op1, (UInt32)(Int32)(signed char)GetOperand8(&cmd->Op2));
 499.582 +        break;
 499.583 +      case CMD_XCHG:
 499.584 +        {
 499.585 +          UInt32 v1 = GetOperand(cmd->ByteMode, &cmd->Op1);
 499.586 +          SetOperand(cmd->ByteMode, &cmd->Op1, GetOperand(cmd->ByteMode, &cmd->Op2));
 499.587 +          SetOperand(cmd->ByteMode, &cmd->Op2, v1);
 499.588 +        }
 499.589 +        break;
 499.590 +      case CMD_MUL:
 499.591 +        {
 499.592 +          UInt32 res = GetOperand32(&cmd->Op1) * GetOperand32(&cmd->Op2);
 499.593 +          SetOperand32(&cmd->Op1, res);
 499.594 +        }
 499.595 +        break;
 499.596 +      case CMD_MULB:
 499.597 +        {
 499.598 +          Byte res = GetOperand8(&cmd->Op1) * GetOperand8(&cmd->Op2);
 499.599 +          SetOperand8(&cmd->Op1, res);
 499.600 +        }
 499.601 +        break;
 499.602 +      case CMD_DIV:
 499.603 +        {
 499.604 +          UInt32 divider = GetOperand(cmd->ByteMode, &cmd->Op2);
 499.605 +          if (divider != 0)
 499.606 +          {
 499.607 +            UInt32 res = GetOperand(cmd->ByteMode, &cmd->Op1) / divider;
 499.608 +            SetOperand(cmd->ByteMode, &cmd->Op1, res);
 499.609 +          }
 499.610 +        }
 499.611 +        break;
 499.612 +      
 499.613 +      #endif
 499.614 +      
 499.615 +      case CMD_RET:
 499.616 +        {
 499.617 +          if (R[kStackRegIndex] >= kSpaceSize)
 499.618 +            return true;
 499.619 +          UInt32 ip = GetValue32(&Mem[R[kStackRegIndex] & kSpaceMask]);
 499.620 +          SET_IP(ip);
 499.621 +          R[kStackRegIndex] += 4;
 499.622 +          continue;
 499.623 +        }
 499.624 +      case CMD_PRINT:
 499.625 +        break;
 499.626 +    }
 499.627 +    cmd++;
 499.628 +    --maxOpCount;
 499.629 +  }
 499.630 +}
 499.631 +
 499.632 +
 499.633 +//////////////////////////////////////////////////////
 499.634 +// Read program
 499.635 +
 499.636 +UInt32 ReadEncodedUInt32(CMemBitDecoder &inp)
 499.637 +{
 499.638 +  switch(inp.ReadBits(2))
 499.639 +  {
 499.640 +    case 0:
 499.641 +      return inp.ReadBits(4);
 499.642 +    case 1:
 499.643 +    {
 499.644 +      UInt32 v = inp.ReadBits(4);
 499.645 +      if (v == 0)
 499.646 +        return 0xFFFFFF00 | inp.ReadBits(8);
 499.647 +      else
 499.648 +        return (v << 4) | inp.ReadBits(4);
 499.649 +    }
 499.650 +    case 2:
 499.651 +      return inp.ReadBits(16);
 499.652 +    default:
 499.653 +      return inp.ReadBits(32);
 499.654 +  }
 499.655 +}
 499.656 +
 499.657 +void CVm::DecodeArg(CMemBitDecoder &inp, COperand &op, bool byteMode)
 499.658 +{
 499.659 +  if (inp.ReadBit())
 499.660 +  {
 499.661 +    op.Type = OP_TYPE_REG;
 499.662 +    op.Data = inp.ReadBits(kNumRegBits);
 499.663 +  }
 499.664 +  else if (inp.ReadBit() == 0)
 499.665 +  {
 499.666 +    op.Type = OP_TYPE_INT;
 499.667 +    if (byteMode)
 499.668 +      op.Data = inp.ReadBits(8);
 499.669 +    else
 499.670 +      op.Data = ReadEncodedUInt32(inp);
 499.671 +  }
 499.672 +  else
 499.673 +  {
 499.674 +    op.Type = OP_TYPE_REGMEM;
 499.675 +    if (inp.ReadBit() == 0)
 499.676 +    {
 499.677 +      op.Data = inp.ReadBits(kNumRegBits);
 499.678 +      op.Base = 0;
 499.679 +    }
 499.680 +    else
 499.681 +    {
 499.682 +      if (inp.ReadBit() == 0)
 499.683 +        op.Data = inp.ReadBits(kNumRegBits);
 499.684 +      else
 499.685 +        op.Data = kNumRegs;
 499.686 +      op.Base = ReadEncodedUInt32(inp);
 499.687 +    }
 499.688 +  }
 499.689 +}
 499.690 +
 499.691 +void CVm::ReadVmProgram(const Byte *code, UInt32 codeSize, CProgram *prg)
 499.692 +{
 499.693 +  CMemBitDecoder inp;
 499.694 +  inp.Init(code, codeSize);
 499.695 +
 499.696 +  prg->StaticData.Clear();
 499.697 +  if (inp.ReadBit())
 499.698 +  {
 499.699 +    UInt32 dataSize = ReadEncodedUInt32(inp) + 1;
 499.700 +    for (UInt32 i = 0; inp.Avail() && i < dataSize; i++)
 499.701 +      prg->StaticData.Add((Byte)inp.ReadBits(8));
 499.702 +  }
 499.703 +  while (inp.Avail())
 499.704 +  {
 499.705 +    prg->Commands.Add(CCommand());
 499.706 +    CCommand *cmd = &prg->Commands.Back();
 499.707 +    if (inp.ReadBit() == 0)
 499.708 +      cmd->OpCode = (ECommand)inp.ReadBits(3);
 499.709 +    else
 499.710 +      cmd->OpCode = (ECommand)(8 + inp.ReadBits(5));
 499.711 +    if (kCmdFlags[cmd->OpCode] & CF_BYTEMODE)
 499.712 +      cmd->ByteMode = (inp.ReadBit()) ? true : false;
 499.713 +    else
 499.714 +      cmd->ByteMode = 0;
 499.715 +    int opNum = (kCmdFlags[cmd->OpCode] & CF_OPMASK);
 499.716 +    if (opNum > 0)
 499.717 +    {
 499.718 +      DecodeArg(inp, cmd->Op1, cmd->ByteMode);
 499.719 +      if (opNum == 2)
 499.720 +        DecodeArg(inp, cmd->Op2, cmd->ByteMode);
 499.721 +      else
 499.722 +      {
 499.723 +        if (cmd->Op1.Type == OP_TYPE_INT && (kCmdFlags[cmd->OpCode] & (CF_JUMP | CF_PROC)))
 499.724 +        {
 499.725 +          int Distance = cmd->Op1.Data;
 499.726 +          if (Distance >= 256)
 499.727 +            Distance -= 256;
 499.728 +          else
 499.729 +          {
 499.730 +            if (Distance >= 136)
 499.731 +              Distance -= 264;
 499.732 +            else if (Distance >= 16)
 499.733 +              Distance -= 8;
 499.734 +            else if (Distance >= 8)
 499.735 +              Distance -= 16;
 499.736 +            Distance += prg->Commands.Size() - 1;
 499.737 +          }
 499.738 +          cmd->Op1.Data = Distance;
 499.739 +        }
 499.740 +      }
 499.741 +    }
 499.742 +    if (cmd->ByteMode)
 499.743 +    {
 499.744 +      switch (cmd->OpCode)
 499.745 +      {
 499.746 +        case CMD_MOV: cmd->OpCode = CMD_MOVB; break;
 499.747 +        case CMD_CMP: cmd->OpCode = CMD_CMPB; break;
 499.748 +        case CMD_ADD: cmd->OpCode = CMD_ADDB; break;
 499.749 +        case CMD_SUB: cmd->OpCode = CMD_SUBB; break;
 499.750 +        case CMD_INC: cmd->OpCode = CMD_INCB; break;
 499.751 +        case CMD_DEC: cmd->OpCode = CMD_DECB; break;
 499.752 +        case CMD_XOR: cmd->OpCode = CMD_XORB; break;
 499.753 +        case CMD_AND: cmd->OpCode = CMD_ANDB; break;
 499.754 +        case CMD_OR: cmd->OpCode = CMD_ORB; break;
 499.755 +        case CMD_TEST: cmd->OpCode = CMD_TESTB; break;
 499.756 +        case CMD_NEG: cmd->OpCode = CMD_NEGB; break;
 499.757 +        case CMD_SHL: cmd->OpCode = CMD_SHLB; break;
 499.758 +        case CMD_SHR: cmd->OpCode = CMD_SHRB; break;
 499.759 +        case CMD_SAR: cmd->OpCode = CMD_SARB; break;
 499.760 +        case CMD_MUL: cmd->OpCode = CMD_MULB; break;
 499.761 +      }
 499.762 +    }
 499.763 +  }
 499.764 +}
 499.765 +
 499.766 +#ifdef RARVM_STANDARD_FILTERS
 499.767 +
 499.768 +enum EStandardFilter
 499.769 +{
 499.770 +  SF_E8,
 499.771 +  SF_E8E9,
 499.772 +  SF_ITANIUM,
 499.773 +  SF_RGB,
 499.774 +  SF_AUDIO,
 499.775 +  SF_DELTA,
 499.776 +  SF_UPCASE
 499.777 +};
 499.778 +
 499.779 +struct StandardFilterSignature
 499.780 +{
 499.781 +  UInt32 Length;
 499.782 +  UInt32 CRC;
 499.783 +  EStandardFilter Type;
 499.784 +}
 499.785 +kStdFilters[]=
 499.786 +{
 499.787 +   53, 0xad576887, SF_E8,
 499.788 +   57, 0x3cd7e57e, SF_E8E9,
 499.789 +  120, 0x3769893f, SF_ITANIUM,
 499.790 +   29, 0x0e06077d, SF_DELTA,
 499.791 +  149, 0x1c2c5dc8, SF_RGB,
 499.792 +  216, 0xbc85e701, SF_AUDIO,
 499.793 +   40, 0x46b9c560, SF_UPCASE
 499.794 +};
 499.795 +
 499.796 +static int FindStandardFilter(const Byte *code, UInt32 codeSize)
 499.797 +{
 499.798 +  UInt32 crc = CrcCalc(code, codeSize);
 499.799 +  for (int i = 0; i < sizeof(kStdFilters) / sizeof(kStdFilters[0]); i++)
 499.800 +  {
 499.801 +    StandardFilterSignature &sfs = kStdFilters[i];
 499.802 +    if (sfs.CRC == crc && sfs.Length == codeSize)
 499.803 +      return i;
 499.804 +  }
 499.805 +  return -1;
 499.806 +}
 499.807 +
 499.808 +#endif
 499.809 +
 499.810 +void CVm::PrepareProgram(const Byte *code, UInt32 codeSize, CProgram *prg)
 499.811 +{
 499.812 +  Byte xorSum = 0;
 499.813 +  for (UInt32 i = 1; i < codeSize; i++)
 499.814 +    xorSum ^= code[i];
 499.815 +
 499.816 +  prg->Commands.Clear();
 499.817 +  #ifdef RARVM_STANDARD_FILTERS
 499.818 +  prg->StandardFilterIndex = -1;
 499.819 +  #endif
 499.820 +
 499.821 +  if (xorSum == code[0] && codeSize > 0)
 499.822 +  {
 499.823 +    #ifdef RARVM_STANDARD_FILTERS
 499.824 +    prg->StandardFilterIndex = FindStandardFilter(code, codeSize);
 499.825 +    if (prg->StandardFilterIndex >= 0)
 499.826 +      return;
 499.827 +    #endif
 499.828 +    // 1 byte for checksum
 499.829 +    ReadVmProgram(code + 1, codeSize - 1, prg);
 499.830 +  }
 499.831 +  prg->Commands.Add(CCommand());
 499.832 +  CCommand *cmd = &prg->Commands.Back();
 499.833 +  cmd->OpCode = CMD_RET;
 499.834 +}
 499.835 +
 499.836 +void CVm::SetMemory(UInt32 pos, const Byte *data, UInt32 dataSize)
 499.837 +{
 499.838 +  if (pos < kSpaceSize && data != Mem + pos)
 499.839 +    memmove(Mem + pos, data, MyMin(dataSize, kSpaceSize - pos));
 499.840 +}
 499.841 +
 499.842 +#ifdef RARVM_STANDARD_FILTERS
 499.843 +
 499.844 +static void E8E9Decode(Byte *data, UInt32 dataSize, UInt32 fileOffset, bool e9)
 499.845 +{
 499.846 +  if (dataSize <= 4)
 499.847 +    return;
 499.848 +  dataSize -= 4;
 499.849 +  const UInt32 kFileSize = 0x1000000;
 499.850 +  Byte cmpByte2 = (e9 ? 0xE9 : 0xE8);
 499.851 +  for (UInt32 curPos = 0; curPos < dataSize;)
 499.852 +  {
 499.853 +    Byte curByte = *(data++);
 499.854 +    curPos++;
 499.855 +    if (curByte == 0xE8 || curByte == cmpByte2)
 499.856 +    {
 499.857 +      UInt32 offset = curPos + fileOffset;
 499.858 +      UInt32 addr = (Int32)GetValue32(data);
 499.859 +      if (addr < kFileSize)
 499.860 +        SetValue32(data, addr - offset);
 499.861 +      else if ((Int32)addr < 0 && (Int32)(addr + offset) >= 0)
 499.862 +        SetValue32(data, addr + kFileSize);
 499.863 +      data += 4;
 499.864 +      curPos += 4;
 499.865 +    }
 499.866 +  }
 499.867 +}
 499.868 +
 499.869 +static inline UInt32 ItaniumGetOpType(const Byte *data, int bitPos)
 499.870 +{
 499.871 +  return (data[(unsigned int)bitPos >> 3] >> (bitPos & 7)) & 0xF;
 499.872 +}
 499.873 +
 499.874 +
 499.875 +static void ItaniumDecode(Byte *data, UInt32 dataSize, UInt32 fileOffset)
 499.876 +{
 499.877 +  UInt32 curPos = 0;
 499.878 +  fileOffset >>= 4;
 499.879 +  while (curPos < dataSize - 21)
 499.880 +  {
 499.881 +    int b = (data[0] & 0x1F) - 0x10;
 499.882 +    if (b >= 0)
 499.883 +    {
 499.884 +      static Byte kCmdMasks[16] = {4,4,6,6,0,0,7,7,4,4,0,0,4,4,0,0};
 499.885 +      Byte cmdMask = kCmdMasks[b];
 499.886 +      if (cmdMask != 0)
 499.887 +        for (int i = 0; i < 3; i++)
 499.888 +          if (cmdMask & (1 << i))
 499.889 +          {
 499.890 +            int startPos = i * 41 + 18;
 499.891 +            if (ItaniumGetOpType(data, startPos + 24) == 5)
 499.892 +            {
 499.893 +              const UInt32 kMask = 0xFFFFF;
 499.894 +              Byte *p = data + ((unsigned int)startPos >> 3);
 499.895 +              UInt32 bitField =  ((UInt32)p[0]) | ((UInt32)p[1] <<  8) | ((UInt32)p[2] << 16);
 499.896 +              int inBit = (startPos & 7);
 499.897 +              UInt32 offset = (bitField >> inBit) & kMask;
 499.898 +              UInt32 andMask = ~(kMask << inBit);
 499.899 +              bitField = ((offset - fileOffset) & kMask) << inBit;
 499.900 +              for (int j = 0; j < 3; j++)
 499.901 +              {
 499.902 +                p[j] &= andMask;
 499.903 +                p[j] |= bitField;
 499.904 +                andMask >>= 8;
 499.905 +                bitField >>= 8;
 499.906 +              }
 499.907 +            }
 499.908 +          }
 499.909 +    }
 499.910 +    data += 16;
 499.911 +    curPos += 16;
 499.912 +    fileOffset++;
 499.913 +  }
 499.914 +}
 499.915 +
 499.916 +static void DeltaDecode(Byte *data, UInt32 dataSize, UInt32 numChannels)
 499.917 +{
 499.918 +  UInt32 srcPos = 0;
 499.919 +  UInt32 border = dataSize * 2;
 499.920 +  for (UInt32 curChannel = 0; curChannel < numChannels; curChannel++)
 499.921 +  {
 499.922 +    Byte prevByte = 0;
 499.923 +    for (UInt32 destPos = dataSize + curChannel; destPos < border; destPos += numChannels)
 499.924 +      data[destPos] = (prevByte = prevByte - data[srcPos++]);
 499.925 +  }
 499.926 +}
 499.927 +
 499.928 +static void RgbDecode(Byte *srcData, UInt32 dataSize, UInt32 width, UInt32 posR)
 499.929 +{
 499.930 +  Byte *destData = srcData + dataSize;
 499.931 +  const UInt32 numChannels = 3;
 499.932 +  for (UInt32 curChannel = 0; curChannel < numChannels; curChannel++)
 499.933 +  {
 499.934 +    Byte prevByte = 0;
 499.935 +    
 499.936 +    for (UInt32 i = curChannel; i < dataSize; i+= numChannels)
 499.937 +    {
 499.938 +      unsigned int predicted;
 499.939 +      if (i < width)
 499.940 +        predicted = prevByte;
 499.941 +      else
 499.942 +      {
 499.943 +        unsigned int upperLeftByte = destData[i - width];
 499.944 +        unsigned int upperByte = destData[i - width + 3];
 499.945 +        predicted = prevByte + upperByte - upperLeftByte;
 499.946 +        int pa = abs((int)(predicted - prevByte));
 499.947 +        int pb = abs((int)(predicted - upperByte));
 499.948 +        int pc = abs((int)(predicted - upperLeftByte));
 499.949 +        if (pa <= pb && pa <= pc)
 499.950 +          predicted = prevByte;
 499.951 +        else
 499.952 +          if (pb <= pc)
 499.953 +            predicted = upperByte;
 499.954 +          else
 499.955 +            predicted = upperLeftByte;
 499.956 +      }
 499.957 +      destData[i] = prevByte = (Byte)(predicted - *(srcData++));
 499.958 +    }
 499.959 +  }
 499.960 +  if (dataSize < 3)
 499.961 +    return;
 499.962 +  for (UInt32 i = posR, border = dataSize - 2; i < border; i += 3)
 499.963 +  {
 499.964 +    Byte g = destData[i + 1];
 499.965 +    destData[i] = destData[i] + g;
 499.966 +    destData[i + 2] = destData[i + 2] + g;
 499.967 +  }
 499.968 +}
 499.969 +
 499.970 +static void AudioDecode(Byte *srcData, UInt32 dataSize, UInt32 numChannels)
 499.971 +{
 499.972 +  Byte *destData = srcData + dataSize;
 499.973 +  for (UInt32 curChannel = 0; curChannel < numChannels; curChannel++)
 499.974 +  {
 499.975 +    UInt32 prevByte = 0, prevDelta = 0, dif[7];
 499.976 +    Int32 D1 = 0, D2 = 0, D3;
 499.977 +    Int32 K1 = 0, K2 = 0, K3 = 0;
 499.978 +    memset(dif, 0, sizeof(dif));
 499.979 +    
 499.980 +    for (UInt32 i = curChannel, byteCount = 0; i < dataSize; i += numChannels, byteCount++)
 499.981 +    {
 499.982 +      D3 = D2;
 499.983 +      D2 = prevDelta - D1;
 499.984 +      D1 = prevDelta;
 499.985 +      
 499.986 +      UInt32 predicted = 8 * prevByte + K1 * D1 + K2 * D2 + K3 * D3;
 499.987 +      predicted = (predicted >> 3) & 0xFF;
 499.988 +      
 499.989 +      UInt32 curByte = *(srcData++);
 499.990 +      
 499.991 +      predicted -= curByte;
 499.992 +      destData[i] = (Byte)predicted;
 499.993 +      prevDelta = (UInt32)(Int32)(signed char)(predicted - prevByte);
 499.994 +      prevByte = predicted;
 499.995 +      
 499.996 +      Int32 D = ((Int32)(signed char)curByte) << 3;
 499.997 +      
 499.998 +      dif[0] += abs(D);
 499.999 +      dif[1] += abs(D - D1);
499.1000 +      dif[2] += abs(D + D1);
499.1001 +      dif[3] += abs(D - D2);
499.1002 +      dif[4] += abs(D + D2);
499.1003 +      dif[5] += abs(D - D3);
499.1004 +      dif[6] += abs(D + D3);
499.1005 +      
499.1006 +      if ((byteCount & 0x1F) == 0)
499.1007 +      {
499.1008 +        UInt32 minDif = dif[0], numMinDif = 0;
499.1009 +        dif[0] = 0;
499.1010 +        for (int j = 1; j < sizeof(dif) / sizeof(dif[0]); j++)
499.1011 +        {
499.1012 +          if (dif[j] < minDif)
499.1013 +          {
499.1014 +            minDif = dif[j];
499.1015 +            numMinDif = j;
499.1016 +          }
499.1017 +          dif[j] = 0;
499.1018 +        }
499.1019 +        switch (numMinDif)
499.1020 +        {
499.1021 +          case 1: if (K1 >= -16) K1--; break;
499.1022 +          case 2: if (K1 <   16) K1++; break;
499.1023 +          case 3: if (K2 >= -16) K2--; break;
499.1024 +          case 4: if (K2 <   16) K2++; break;
499.1025 +          case 5: if (K3 >= -16) K3--; break;
499.1026 +          case 6: if (K3 <   16) K3++; break;
499.1027 +        }
499.1028 +      }
499.1029 +    }
499.1030 +  }
499.1031 +}
499.1032 +
499.1033 +static UInt32 UpCaseDecode(Byte *data, UInt32 dataSize)
499.1034 +{
499.1035 +  UInt32 srcPos = 0, destPos = dataSize;
499.1036 +  while (srcPos < dataSize)
499.1037 +  {
499.1038 +    Byte curByte = data[srcPos++];
499.1039 +    if (curByte == 2 && (curByte = data[srcPos++]) != 2)
499.1040 +      curByte -= 32;
499.1041 +    data[destPos++] = curByte;
499.1042 +  }
499.1043 +  return destPos - dataSize;
499.1044 +}
499.1045 +
499.1046 +void CVm::ExecuteStandardFilter(int filterIndex)
499.1047 +{
499.1048 +  UInt32 dataSize = R[4];
499.1049 +  if (dataSize >= kGlobalOffset)
499.1050 +    return;
499.1051 +  EStandardFilter filterType = kStdFilters[filterIndex].Type;
499.1052 +
499.1053 +  switch (filterType)
499.1054 +  {
499.1055 +    case SF_E8:
499.1056 +    case SF_E8E9:
499.1057 +      E8E9Decode(Mem, dataSize, R[6], (filterType == SF_E8E9));
499.1058 +      break;
499.1059 +    case SF_ITANIUM:
499.1060 +      ItaniumDecode(Mem, dataSize, R[6]);
499.1061 +      break;
499.1062 +    case SF_DELTA:
499.1063 +      if (dataSize >= kGlobalOffset / 2)
499.1064 +        break;
499.1065 +      SetBlockPos(dataSize);
499.1066 +      DeltaDecode(Mem, dataSize, R[0]);
499.1067 +      break;
499.1068 +    case SF_RGB:
499.1069 +      if (dataSize >= kGlobalOffset / 2)
499.1070 +        break;
499.1071 +      {
499.1072 +        UInt32 width = R[0];
499.1073 +        if (width <= 3)
499.1074 +          break;
499.1075 +        SetBlockPos(dataSize);
499.1076 +        RgbDecode(Mem, dataSize, width, R[1]);
499.1077 +      }
499.1078 +      break;
499.1079 +    case SF_AUDIO:
499.1080 +      if (dataSize >= kGlobalOffset / 2)
499.1081 +        break;
499.1082 +      SetBlockPos(dataSize);
499.1083 +      AudioDecode(Mem, dataSize, R[0]);
499.1084 +      break;
499.1085 +    case SF_UPCASE:
499.1086 +      if (dataSize >= kGlobalOffset / 2)
499.1087 +        break;
499.1088 +      UInt32 destSize = UpCaseDecode(Mem, dataSize);
499.1089 +      SetBlockSize(destSize);
499.1090 +      SetBlockPos(dataSize);
499.1091 +      break;
499.1092 +  }
499.1093 +}
499.1094 +
499.1095 +#endif
499.1096 +
499.1097 +}}}
   500.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   500.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/Rar3Vm.h	Sat Mar 03 10:31:27 2012 -0600
   500.3 @@ -0,0 +1,179 @@
   500.4 +// Rar3Vm.h
   500.5 +// According to unRAR license, this code may not be used to develop
   500.6 +// a program that creates RAR archives
   500.7 +
   500.8 +#ifndef __COMPRESS_RAR3_VM_H
   500.9 +#define __COMPRESS_RAR3_VM_H
  500.10 +
  500.11 +#include "../../../C/CpuArch.h"
  500.12 +
  500.13 +#include "Common/MyVector.h"
  500.14 +#include "Common/Types.h"
  500.15 +
  500.16 +#define RARVM_STANDARD_FILTERS
  500.17 +
  500.18 +namespace NCompress {
  500.19 +namespace NRar3 {
  500.20 +
  500.21 +class CMemBitDecoder
  500.22 +{
  500.23 +  const Byte *_data;
  500.24 +  UInt32 _bitSize;
  500.25 +  UInt32 _bitPos;
  500.26 +public:
  500.27 +  void Init(const Byte *data, UInt32 byteSize)
  500.28 +  {
  500.29 +    _data = data;
  500.30 +    _bitSize = (byteSize << 3);
  500.31 +    _bitPos = 0;
  500.32 +  }
  500.33 +  UInt32 ReadBits(int numBits);
  500.34 +  UInt32 ReadBit();
  500.35 +  bool Avail() const { return (_bitPos < _bitSize); }
  500.36 +};
  500.37 +
  500.38 +namespace NVm {
  500.39 +
  500.40 +inline UInt32 GetValue32(const void *addr) { return GetUi32(addr); }
  500.41 +inline void SetValue32(void *addr, UInt32 value) { SetUi32(addr, value); }
  500.42 +
  500.43 +UInt32 ReadEncodedUInt32(CMemBitDecoder &inp);
  500.44 +
  500.45 +const int kNumRegBits = 3;
  500.46 +const UInt32 kNumRegs = 1 << kNumRegBits;
  500.47 +const UInt32 kNumGpRegs = kNumRegs - 1;
  500.48 +
  500.49 +const UInt32 kSpaceSize = 0x40000;
  500.50 +const UInt32 kSpaceMask = kSpaceSize -1;
  500.51 +const UInt32 kGlobalOffset = 0x3C000;
  500.52 +const UInt32 kGlobalSize = 0x2000;
  500.53 +const UInt32 kFixedGlobalSize = 64;
  500.54 +
  500.55 +namespace NGlobalOffset
  500.56 +{
  500.57 +  const UInt32 kBlockSize = 0x1C;
  500.58 +  const UInt32 kBlockPos  = 0x20;
  500.59 +  const UInt32 kExecCount = 0x2C;
  500.60 +  const UInt32 kGlobalMemOutSize = 0x30;
  500.61 +}
  500.62 +
  500.63 +enum ECommand
  500.64 +{
  500.65 +  CMD_MOV,  CMD_CMP,  CMD_ADD,  CMD_SUB,  CMD_JZ,   CMD_JNZ,  CMD_INC,  CMD_DEC,
  500.66 +  CMD_JMP,  CMD_XOR,  CMD_AND,  CMD_OR,   CMD_TEST, CMD_JS,   CMD_JNS,  CMD_JB,
  500.67 +  CMD_JBE,  CMD_JA,   CMD_JAE,  CMD_PUSH, CMD_POP,  CMD_CALL, CMD_RET,  CMD_NOT,
  500.68 +  CMD_SHL,  CMD_SHR,  CMD_SAR,  CMD_NEG,  CMD_PUSHA,CMD_POPA, CMD_PUSHF,CMD_POPF,
  500.69 +  CMD_MOVZX,CMD_MOVSX,CMD_XCHG, CMD_MUL,  CMD_DIV,  CMD_ADC,  CMD_SBB,  CMD_PRINT,
  500.70 +
  500.71 +  CMD_MOVB, CMD_CMPB, CMD_ADDB, CMD_SUBB, CMD_INCB, CMD_DECB,
  500.72 +  CMD_XORB, CMD_ANDB, CMD_ORB,  CMD_TESTB,CMD_NEGB,
  500.73 +  CMD_SHLB, CMD_SHRB, CMD_SARB, CMD_MULB
  500.74 +};
  500.75 +
  500.76 +enum EOpType {OP_TYPE_REG, OP_TYPE_INT, OP_TYPE_REGMEM, OP_TYPE_NONE};
  500.77 +
  500.78 +// Addr in COperand object can link (point) to CVm object!!!
  500.79 +
  500.80 +struct COperand
  500.81 +{
  500.82 +  EOpType Type;
  500.83 +  UInt32 Data;
  500.84 +  UInt32 Base;
  500.85 +  COperand(): Type(OP_TYPE_NONE), Data(0), Base(0) {}
  500.86 +};
  500.87 +
  500.88 +struct CCommand
  500.89 +{
  500.90 +  ECommand OpCode;
  500.91 +  bool ByteMode;
  500.92 +  COperand Op1, Op2;
  500.93 +};
  500.94 +
  500.95 +struct CBlockRef
  500.96 +{
  500.97 +  UInt32 Offset;
  500.98 +  UInt32 Size;
  500.99 +};
 500.100 +
 500.101 +struct CProgram
 500.102 +{
 500.103 +  CRecordVector<CCommand> Commands;
 500.104 +  #ifdef RARVM_STANDARD_FILTERS
 500.105 +  int StandardFilterIndex;
 500.106 +  #endif
 500.107 +  CRecordVector<Byte> StaticData;
 500.108 +};
 500.109 +
 500.110 +struct CProgramInitState
 500.111 +{
 500.112 +  UInt32 InitR[kNumGpRegs];
 500.113 +  CRecordVector<Byte> GlobalData;
 500.114 +
 500.115 +  void AllocateEmptyFixedGlobal()
 500.116 +  {
 500.117 +    GlobalData.Clear();
 500.118 +    GlobalData.Reserve(NVm::kFixedGlobalSize);
 500.119 +    for (UInt32 i = 0; i < NVm::kFixedGlobalSize; i++)
 500.120 +      GlobalData.Add(0);
 500.121 +  }
 500.122 +};
 500.123 +
 500.124 +class CVm
 500.125 +{
 500.126 +  static UInt32 GetValue(bool byteMode, const void *addr)
 500.127 +  {
 500.128 +    if (byteMode)
 500.129 +      return(*(const Byte *)addr);
 500.130 +    else
 500.131 +      return GetUi32(addr);
 500.132 +  }
 500.133 +
 500.134 +  static void SetValue(bool byteMode, void *addr, UInt32 value)
 500.135 +  {
 500.136 +    if (byteMode)
 500.137 +      *(Byte *)addr = (Byte)value;
 500.138 +    else
 500.139 +      SetUi32(addr, value);
 500.140 +  }
 500.141 +
 500.142 +  UInt32 GetFixedGlobalValue32(UInt32 globalOffset) { return GetValue(false, &Mem[kGlobalOffset + globalOffset]); }
 500.143 +
 500.144 +  void SetBlockSize(UInt32 v) { SetValue(&Mem[kGlobalOffset + NGlobalOffset::kBlockSize], v); }
 500.145 +  void SetBlockPos(UInt32 v) { SetValue(&Mem[kGlobalOffset + NGlobalOffset::kBlockPos], v); }
 500.146 +public:
 500.147 +  static void SetValue(void *addr, UInt32 value) { SetValue(false, addr, value); }
 500.148 +private:
 500.149 +  UInt32 GetOperand32(const COperand *op) const;
 500.150 +  void SetOperand32(const COperand *op, UInt32 val);
 500.151 +  Byte GetOperand8(const COperand *op) const;
 500.152 +  void SetOperand8(const COperand *op, Byte val);
 500.153 +  UInt32 GetOperand(bool byteMode, const COperand *op) const;
 500.154 +  void SetOperand(bool byteMode, const COperand *op, UInt32 val);
 500.155 +
 500.156 +  void DecodeArg(CMemBitDecoder &inp, COperand &op, bool byteMode);
 500.157 +  
 500.158 +  bool ExecuteCode(const CProgram *prg);
 500.159 +  
 500.160 +  #ifdef RARVM_STANDARD_FILTERS
 500.161 +  void ExecuteStandardFilter(int filterIndex);
 500.162 +  #endif
 500.163 +  
 500.164 +  Byte *Mem;
 500.165 +  UInt32 R[kNumRegs + 1]; // R[kNumRegs] = 0 always (speed optimization)
 500.166 +  UInt32 Flags;
 500.167 +  void ReadVmProgram(const Byte *code, UInt32 codeSize, CProgram *prg);
 500.168 +public:
 500.169 +  CVm();
 500.170 +  ~CVm();
 500.171 +  bool Create();
 500.172 +  void PrepareProgram(const Byte *code, UInt32 codeSize, CProgram *prg);
 500.173 +  void SetMemory(UInt32 pos, const Byte *data, UInt32 dataSize);
 500.174 +  bool Execute(CProgram *prg, const CProgramInitState *initState,
 500.175 +      CBlockRef &outBlockRef, CRecordVector<Byte> &outGlobalData);
 500.176 +  const Byte *GetDataPointer(UInt32 offset) const { return Mem + offset; }
 500.177 +
 500.178 +};
 500.179 +
 500.180 +#endif
 500.181 +
 500.182 +}}}
   501.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   501.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/RarCodecsRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   501.3 @@ -0,0 +1,26 @@
   501.4 +// RarCodecsRegister.cpp
   501.5 +
   501.6 +#include "StdAfx.h"
   501.7 +
   501.8 +#include "../Common/RegisterCodec.h"
   501.9 +
  501.10 +#include "Rar1Decoder.h"
  501.11 +#include "Rar2Decoder.h"
  501.12 +#include "Rar3Decoder.h"
  501.13 +
  501.14 +#define CREATE_CODEC(x) static void *CreateCodec ## x() { return (void *)(ICompressCoder *)(new NCompress::NRar ## x::CDecoder); }
  501.15 +
  501.16 +CREATE_CODEC(1)
  501.17 +CREATE_CODEC(2)
  501.18 +CREATE_CODEC(3)
  501.19 +
  501.20 +#define RAR_CODEC(x, name) { CreateCodec ## x, 0, 0x040300 + x, L"Rar" name, 1, false }
  501.21 +
  501.22 +static CCodecInfo g_CodecsInfo[] =
  501.23 +{
  501.24 +  RAR_CODEC(1, L"1"),
  501.25 +  RAR_CODEC(2, L"2"),
  501.26 +  RAR_CODEC(3, L"3"),
  501.27 +};
  501.28 +
  501.29 +REGISTER_CODECS(Rar)
   502.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   502.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/ShrinkDecoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   502.3 @@ -0,0 +1,148 @@
   502.4 +// ShrinkDecoder.cpp
   502.5 +
   502.6 +#include "StdAfx.h"
   502.7 +
   502.8 +extern "C"
   502.9 +{
  502.10 +#include "../../../C/Alloc.h"
  502.11 +}
  502.12 +
  502.13 +#include "../Common/InBuffer.h"
  502.14 +#include "../Common/OutBuffer.h"
  502.15 +
  502.16 +#include "BitlDecoder.h"
  502.17 +#include "ShrinkDecoder.h"
  502.18 +
  502.19 +namespace NCompress {
  502.20 +namespace NShrink {
  502.21 +
  502.22 +static const UInt32 kBufferSize = (1 << 20);
  502.23 +static const int kNumMinBits = 9;
  502.24 +
  502.25 +HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  502.26 +    const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)
  502.27 +{
  502.28 +  NBitl::CBaseDecoder<CInBuffer> inBuffer;
  502.29 +  COutBuffer outBuffer;
  502.30 +
  502.31 +  if (!inBuffer.Create(kBufferSize))
  502.32 +    return E_OUTOFMEMORY;
  502.33 +  inBuffer.SetStream(inStream);
  502.34 +  inBuffer.Init();
  502.35 +
  502.36 +  if (!outBuffer.Create(kBufferSize))
  502.37 +    return E_OUTOFMEMORY;
  502.38 +  outBuffer.SetStream(outStream);
  502.39 +  outBuffer.Init();
  502.40 +
  502.41 +  UInt64 prevPos = 0;
  502.42 +  int numBits = kNumMinBits;
  502.43 +  UInt32 head = 257;
  502.44 +  bool needPrev = false;
  502.45 +  UInt32 lastSymbol = 0;
  502.46 +
  502.47 +  int i;
  502.48 +  for (i = 0; i < kNumItems; i++)
  502.49 +    _parents[i] = 0;
  502.50 +  for (i = 0; i < kNumItems; i++)
  502.51 +    _suffixes[i] = 0;
  502.52 +  for (i = 0; i < 257; i++)
  502.53 +    _isFree[i] = false;
  502.54 +  for (; i < kNumItems; i++)
  502.55 +    _isFree[i] = true;
  502.56 +
  502.57 +  for (;;)
  502.58 +  {
  502.59 +    UInt32 symbol = inBuffer.ReadBits(numBits);
  502.60 +    if (inBuffer.ExtraBitsWereRead())
  502.61 +      break;
  502.62 +    if (_isFree[symbol])
  502.63 +      return S_FALSE;
  502.64 +    if (symbol == 256)
  502.65 +    {
  502.66 +      UInt32 symbol = inBuffer.ReadBits(numBits);
  502.67 +      if (symbol == 1)
  502.68 +      {
  502.69 +        if (numBits < kNumMaxBits)
  502.70 +          numBits++;
  502.71 +      }
  502.72 +      else if (symbol == 2)
  502.73 +      {
  502.74 +        if (needPrev)
  502.75 +          _isFree[head - 1] = true;
  502.76 +        for (i = 257; i < kNumItems; i++)
  502.77 +          _isParent[i] = false;
  502.78 +        for (i = 257; i < kNumItems; i++)
  502.79 +          if (!_isFree[i])
  502.80 +            _isParent[_parents[i]] = true;
  502.81 +        for (i = 257; i < kNumItems; i++)
  502.82 +          if (!_isParent[i])
  502.83 +            _isFree[i] = true;
  502.84 +        head = 257;
  502.85 +        while (head < kNumItems && !_isFree[head])
  502.86 +          head++;
  502.87 +        if (head < kNumItems)
  502.88 +        {
  502.89 +          needPrev = true;
  502.90 +          _isFree[head] = false;
  502.91 +          _parents[head] = (UInt16)lastSymbol;
  502.92 +          head++;
  502.93 +        }
  502.94 +      }
  502.95 +      else
  502.96 +        return S_FALSE;
  502.97 +      continue;
  502.98 +    }
  502.99 +    UInt32 cur = symbol;
 502.100 +    i = 0;
 502.101 +    int corectionIndex = -1;
 502.102 +    while (cur >= 256)
 502.103 +    {
 502.104 +      if (cur == head - 1)
 502.105 +        corectionIndex = i;
 502.106 +      _stack[i++] = _suffixes[cur];
 502.107 +      cur = _parents[cur];
 502.108 +    }
 502.109 +    _stack[i++] = (Byte)cur;
 502.110 +    if (needPrev)
 502.111 +    {
 502.112 +      _suffixes[head - 1] = (Byte)cur;
 502.113 +      if (corectionIndex >= 0)
 502.114 +        _stack[corectionIndex] = (Byte)cur;
 502.115 +    }
 502.116 +    while (i > 0)
 502.117 +      outBuffer.WriteByte((_stack[--i]));
 502.118 +    while (head < kNumItems && !_isFree[head])
 502.119 +      head++;
 502.120 +    if (head < kNumItems)
 502.121 +    {
 502.122 +      needPrev = true;
 502.123 +      _isFree[head] = false;
 502.124 +      _parents[head] = (UInt16)symbol;
 502.125 +      head++;
 502.126 +    }
 502.127 +    else
 502.128 +      needPrev = false;
 502.129 +    lastSymbol = symbol;
 502.130 +
 502.131 +    UInt64 nowPos = outBuffer.GetProcessedSize();
 502.132 +    if (progress != NULL && nowPos - prevPos > (1 << 18))
 502.133 +    {
 502.134 +      prevPos = nowPos;
 502.135 +      UInt64 packSize = inBuffer.GetProcessedSize();
 502.136 +      RINOK(progress->SetRatioInfo(&packSize, &nowPos));
 502.137 +    }
 502.138 +  }
 502.139 +  return outBuffer.Flush();
 502.140 +}
 502.141 +
 502.142 +STDMETHODIMP CDecoder ::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
 502.143 +    const UInt64 *inSize, const UInt64 *outSize,    ICompressProgressInfo *progress)
 502.144 +{
 502.145 +  try { return CodeReal(inStream, outStream, inSize, outSize, progress); }
 502.146 +  catch(const CInBufferException &e) { return e.ErrorCode; }
 502.147 +  catch(const COutBufferException &e) { return e.ErrorCode; }
 502.148 +  catch(...) { return S_FALSE; }
 502.149 +}
 502.150 +
 502.151 +}}
   503.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   503.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/ShrinkDecoder.h	Sat Mar 03 10:31:27 2012 -0600
   503.3 @@ -0,0 +1,38 @@
   503.4 +// ShrinkDecoder.h
   503.5 +
   503.6 +#ifndef __COMPRESS_SHRINK_DECODER_H
   503.7 +#define __COMPRESS_SHRINK_DECODER_H
   503.8 +
   503.9 +#include "../../Common/MyCom.h"
  503.10 +
  503.11 +#include "../ICoder.h"
  503.12 +
  503.13 +namespace NCompress {
  503.14 +namespace NShrink {
  503.15 +
  503.16 +const int kNumMaxBits = 13;
  503.17 +const UInt32 kNumItems = 1 << kNumMaxBits;
  503.18 +
  503.19 +class CDecoder :
  503.20 +  public ICompressCoder,
  503.21 +  public CMyUnknownImp
  503.22 +{
  503.23 +  UInt16 _parents[kNumItems];
  503.24 +  Byte _suffixes[kNumItems];
  503.25 +  Byte _stack[kNumItems];
  503.26 +  bool _isFree[kNumItems];
  503.27 +  bool _isParent[kNumItems];
  503.28 +
  503.29 +public:
  503.30 +  MY_UNKNOWN_IMP
  503.31 +
  503.32 +  HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  503.33 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
  503.34 +  
  503.35 +  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  503.36 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
  503.37 +};
  503.38 +
  503.39 +}}
  503.40 +
  503.41 +#endif
   504.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   504.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   504.3 @@ -0,0 +1,8 @@
   504.4 +// StdAfx.h
   504.5 +
   504.6 +#ifndef __STDAFX_H
   504.7 +#define __STDAFX_H
   504.8 +
   504.9 +#include "../../Common/MyWindows.h"
  504.10 +
  504.11 +#endif
   505.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   505.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/ZlibDecoder.cpp	Sat Mar 03 10:31:27 2012 -0600
   505.3 @@ -0,0 +1,94 @@
   505.4 +// ZlibDecoder.cpp
   505.5 +
   505.6 +#include "StdAfx.h"
   505.7 +
   505.8 +#include "../Common/StreamUtils.h"
   505.9 +
  505.10 +#include "DeflateDecoder.h"
  505.11 +#include "ZlibDecoder.h"
  505.12 +
  505.13 +namespace NCompress {
  505.14 +namespace NZlib {
  505.15 +
  505.16 +#define DEFLATE_TRY_BEGIN try {
  505.17 +#define DEFLATE_TRY_END } \
  505.18 +  catch(...) { return S_FALSE; }
  505.19 +
  505.20 +#define ADLER_MOD 65521
  505.21 +#define ADLER_LOOP_MAX 5550
  505.22 +
  505.23 +static UInt32 Adler32_Update(UInt32 adler, const Byte *buf, size_t size)
  505.24 +{
  505.25 +  UInt32 a = adler & 0xFFFF;
  505.26 +  UInt32 b = (adler >> 16) & 0xFFFF;
  505.27 +  while (size > 0)
  505.28 +  {
  505.29 +    unsigned curSize = (size > ADLER_LOOP_MAX) ? ADLER_LOOP_MAX : (unsigned )size;
  505.30 +    unsigned i;
  505.31 +    for (i = 0; i < curSize; i++)
  505.32 +    {
  505.33 +      a += buf[i];
  505.34 +      b += a;
  505.35 +    }
  505.36 +    buf += curSize;
  505.37 +    size -= curSize;
  505.38 +    a %= ADLER_MOD;
  505.39 +    b %= ADLER_MOD;
  505.40 +  }
  505.41 +  return (b << 16) + a;
  505.42 +}
  505.43 +
  505.44 +STDMETHODIMP COutStreamWithAdler::Write(const void *data, UInt32 size, UInt32 *processedSize)
  505.45 +{
  505.46 +  HRESULT result = _stream->Write(data, size, &size);
  505.47 +  _adler = Adler32_Update(_adler, (const Byte *)data, size);
  505.48 +  if (processedSize != NULL)
  505.49 +    *processedSize = size;
  505.50 +  return result;
  505.51 +}
  505.52 +
  505.53 +STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  505.54 +    const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
  505.55 +{
  505.56 +  DEFLATE_TRY_BEGIN
  505.57 +  if (!AdlerStream)
  505.58 +  {
  505.59 +    AdlerSpec = new COutStreamWithAdler;
  505.60 +    AdlerStream = AdlerSpec;
  505.61 +  }
  505.62 +  if (!DeflateDecoder)
  505.63 +  {
  505.64 +    DeflateDecoderSpec = new NCompress::NDeflate::NDecoder::CCOMCoder;
  505.65 +    DeflateDecoderSpec->ZlibMode = true;
  505.66 +    DeflateDecoder = DeflateDecoderSpec;
  505.67 +  }
  505.68 +
  505.69 +  Byte buf[2];
  505.70 +  RINOK(ReadStream_FALSE(inStream, buf, 2));
  505.71 +  int method = buf[0] & 0xF;
  505.72 +  if (method != 8)
  505.73 +    return S_FALSE;
  505.74 +  // int dicSize = buf[0] >> 4;
  505.75 +  if ((((UInt32)buf[0] << 8) + buf[1]) % 31 != 0)
  505.76 +    return S_FALSE;
  505.77 +  if ((buf[1] & 0x20) != 0) // dictPresent
  505.78 +    return S_FALSE;
  505.79 +  // int level = (buf[1] >> 6);
  505.80 +
  505.81 +  AdlerSpec->SetStream(outStream);
  505.82 +  AdlerSpec->Init();
  505.83 +  HRESULT res = DeflateDecoder->Code(inStream, AdlerStream, inSize, outSize, progress);
  505.84 +  AdlerSpec->ReleaseStream();
  505.85 +
  505.86 +  if (res == S_OK)
  505.87 +  {
  505.88 +    const Byte *p = DeflateDecoderSpec->ZlibFooter;
  505.89 +    UInt32 adler = ((UInt32)p[0] << 24) | ((UInt32)p[1] << 16) | ((UInt32)p[2] << 8) | p[3];
  505.90 +    if (adler != AdlerSpec->GetAdler())
  505.91 +      return S_FALSE;
  505.92 +  }
  505.93 +  return res;
  505.94 +  DEFLATE_TRY_END
  505.95 +}
  505.96 +
  505.97 +}}
   506.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   506.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/ZlibDecoder.h	Sat Mar 03 10:31:27 2012 -0600
   506.3 @@ -0,0 +1,46 @@
   506.4 +// ZlibDecoder.h
   506.5 +
   506.6 +#ifndef __ZLIB_DECODER_H
   506.7 +#define __ZLIB_DECODER_H
   506.8 +
   506.9 +#include "DeflateDecoder.h"
  506.10 +
  506.11 +namespace NCompress {
  506.12 +namespace NZlib {
  506.13 +
  506.14 +const UInt32 ADLER_INIT_VAL = 1;
  506.15 +
  506.16 +class COutStreamWithAdler:
  506.17 +  public ISequentialOutStream,
  506.18 +  public CMyUnknownImp
  506.19 +{
  506.20 +  CMyComPtr<ISequentialOutStream> _stream;
  506.21 +  UInt32 _adler;
  506.22 +public:
  506.23 +  MY_UNKNOWN_IMP
  506.24 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  506.25 +  void SetStream(ISequentialOutStream *stream) { _stream = stream; }
  506.26 +  void ReleaseStream() { _stream.Release(); }
  506.27 +  void Init() { _adler = ADLER_INIT_VAL; }
  506.28 +  UInt32 GetAdler() const { return _adler; }
  506.29 +};
  506.30 +
  506.31 +class CDecoder:
  506.32 +  public ICompressCoder,
  506.33 +  public CMyUnknownImp
  506.34 +{
  506.35 +  COutStreamWithAdler *AdlerSpec;
  506.36 +  CMyComPtr<ISequentialOutStream> AdlerStream;
  506.37 +  
  506.38 +  NCompress::NDeflate::NDecoder::CCOMCoder *DeflateDecoderSpec;
  506.39 +  CMyComPtr<ICompressCoder> DeflateDecoder;
  506.40 +public:
  506.41 +  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
  506.42 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
  506.43 +
  506.44 +  MY_UNKNOWN_IMP
  506.45 +};
  506.46 +
  506.47 +}}
  506.48 +
  506.49 +#endif
   507.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   507.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/makefile	Sat Mar 03 10:31:27 2012 -0600
   507.3 @@ -0,0 +1,14 @@
   507.4 +DIRS = \
   507.5 +  Branch\~ \
   507.6 +  ByteSwap\~ \
   507.7 +  BZip2\~ \
   507.8 +  Copy\~ \
   507.9 +  Deflate\~ \
  507.10 +  LZMA\~ \
  507.11 +  PPMD\~ \
  507.12 +  Rar\~ \
  507.13 +  
  507.14 +all: $(DIRS)
  507.15 +
  507.16 +$(DIRS):
  507.17 +!include "../SubBuild.mak"
   508.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   508.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/7zAes.cpp	Sat Mar 03 10:31:27 2012 -0600
   508.3 @@ -0,0 +1,245 @@
   508.4 +// 7zAes.cpp
   508.5 +
   508.6 +#include "StdAfx.h"
   508.7 +
   508.8 +extern "C"
   508.9 +{
  508.10 +#include "../../../C/Sha256.h"
  508.11 +}
  508.12 +
  508.13 +#include "Windows/Synchronization.h"
  508.14 +#include "../Common/StreamObjects.h"
  508.15 +#include "../Common/StreamUtils.h"
  508.16 +#include "7zAes.h"
  508.17 +#include "MyAes.h"
  508.18 +
  508.19 +#ifndef EXTRACT_ONLY
  508.20 +#include "RandGen.h"
  508.21 +#endif
  508.22 +
  508.23 +using namespace NWindows;
  508.24 +
  508.25 +namespace NCrypto {
  508.26 +namespace NSevenZ {
  508.27 +
  508.28 +bool CKeyInfo::IsEqualTo(const CKeyInfo &a) const
  508.29 +{
  508.30 +  if (SaltSize != a.SaltSize || NumCyclesPower != a.NumCyclesPower)
  508.31 +    return false;
  508.32 +  for (UInt32 i = 0; i < SaltSize; i++)
  508.33 +    if (Salt[i] != a.Salt[i])
  508.34 +      return false;
  508.35 +  return (Password == a.Password);
  508.36 +}
  508.37 +
  508.38 +void CKeyInfo::CalculateDigest()
  508.39 +{
  508.40 +  if (NumCyclesPower == 0x3F)
  508.41 +  {
  508.42 +    UInt32 pos;
  508.43 +    for (pos = 0; pos < SaltSize; pos++)
  508.44 +      Key[pos] = Salt[pos];
  508.45 +    for (UInt32 i = 0; i < Password.GetCapacity() && pos < kKeySize; i++)
  508.46 +      Key[pos++] = Password[i];
  508.47 +    for (; pos < kKeySize; pos++)
  508.48 +      Key[pos] = 0;
  508.49 +  }
  508.50 +  else
  508.51 +  {
  508.52 +    CSha256 sha;
  508.53 +    Sha256_Init(&sha);
  508.54 +    const UInt64 numRounds = UInt64(1) << (NumCyclesPower);
  508.55 +    Byte temp[8] = { 0,0,0,0,0,0,0,0 };
  508.56 +    for (UInt64 round = 0; round < numRounds; round++)
  508.57 +    {
  508.58 +      Sha256_Update(&sha, Salt, (size_t)SaltSize);
  508.59 +      Sha256_Update(&sha, Password, Password.GetCapacity());
  508.60 +      Sha256_Update(&sha, temp, 8);
  508.61 +      for (int i = 0; i < 8; i++)
  508.62 +        if (++(temp[i]) != 0)
  508.63 +          break;
  508.64 +    }
  508.65 +    Sha256_Final(&sha, Key);
  508.66 +  }
  508.67 +}
  508.68 +
  508.69 +bool CKeyInfoCache::Find(CKeyInfo &key)
  508.70 +{
  508.71 +  for (int i = 0; i < Keys.Size(); i++)
  508.72 +  {
  508.73 +    const CKeyInfo &cached = Keys[i];
  508.74 +    if (key.IsEqualTo(cached))
  508.75 +    {
  508.76 +      for (int j = 0; j < kKeySize; j++)
  508.77 +        key.Key[j] = cached.Key[j];
  508.78 +      if (i != 0)
  508.79 +      {
  508.80 +        Keys.Insert(0, cached);
  508.81 +        Keys.Delete(i+1);
  508.82 +      }
  508.83 +      return true;
  508.84 +    }
  508.85 +  }
  508.86 +  return false;
  508.87 +}
  508.88 +
  508.89 +void CKeyInfoCache::Add(CKeyInfo &key)
  508.90 +{
  508.91 +  if (Find(key))
  508.92 +    return;
  508.93 +  if (Keys.Size() >= Size)
  508.94 +    Keys.DeleteBack();
  508.95 +  Keys.Insert(0, key);
  508.96 +}
  508.97 +
  508.98 +static CKeyInfoCache g_GlobalKeyCache(32);
  508.99 +static NSynchronization::CCriticalSection g_GlobalKeyCacheCriticalSection;
 508.100 +
 508.101 +CBase::CBase():
 508.102 +  _cachedKeys(16),
 508.103 +  _ivSize(0)
 508.104 +{
 508.105 +  for (int i = 0; i < sizeof(_iv); i++)
 508.106 +    _iv[i] = 0;
 508.107 +}
 508.108 +
 508.109 +void CBase::CalculateDigest()
 508.110 +{
 508.111 +  NSynchronization::CCriticalSectionLock lock(g_GlobalKeyCacheCriticalSection);
 508.112 +  if (_cachedKeys.Find(_key))
 508.113 +    g_GlobalKeyCache.Add(_key);
 508.114 +  else
 508.115 +  {
 508.116 +    if (!g_GlobalKeyCache.Find(_key))
 508.117 +    {
 508.118 +      _key.CalculateDigest();
 508.119 +      g_GlobalKeyCache.Add(_key);
 508.120 +    }
 508.121 +    _cachedKeys.Add(_key);
 508.122 +  }
 508.123 +}
 508.124 +
 508.125 +#ifndef EXTRACT_ONLY
 508.126 +
 508.127 +/*
 508.128 +STDMETHODIMP CEncoder::ResetSalt()
 508.129 +{
 508.130 +  _key.SaltSize = 4;
 508.131 +  g_RandomGenerator.Generate(_key.Salt, _key.SaltSize);
 508.132 +  return S_OK;
 508.133 +}
 508.134 +*/
 508.135 +
 508.136 +STDMETHODIMP CEncoder::ResetInitVector()
 508.137 +{
 508.138 +  _ivSize = 8;
 508.139 +  g_RandomGenerator.Generate(_iv, (unsigned)_ivSize);
 508.140 +  return S_OK;
 508.141 +}
 508.142 +
 508.143 +STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
 508.144 +{
 508.145 +   // _key.Init();
 508.146 +   for (UInt32 i = _ivSize; i < sizeof(_iv); i++)
 508.147 +    _iv[i] = 0;
 508.148 +
 508.149 +  UInt32 ivSize = _ivSize;
 508.150 +  
 508.151 +  // _key.NumCyclesPower = 0x3F;
 508.152 +  _key.NumCyclesPower = 19;
 508.153 +
 508.154 +  Byte firstByte = (Byte)(_key.NumCyclesPower |
 508.155 +    (((_key.SaltSize == 0) ? 0 : 1) << 7) |
 508.156 +    (((ivSize == 0) ? 0 : 1) << 6));
 508.157 +  RINOK(outStream->Write(&firstByte, 1, NULL));
 508.158 +  if (_key.SaltSize == 0 && ivSize == 0)
 508.159 +    return S_OK;
 508.160 +  Byte saltSizeSpec = (Byte)((_key.SaltSize == 0) ? 0 : (_key.SaltSize - 1));
 508.161 +  Byte ivSizeSpec = (Byte)((ivSize == 0) ? 0 : (ivSize - 1));
 508.162 +  Byte secondByte = (Byte)(((saltSizeSpec) << 4) | ivSizeSpec);
 508.163 +  RINOK(outStream->Write(&secondByte, 1, NULL));
 508.164 +  if (_key.SaltSize > 0)
 508.165 +  {
 508.166 +    RINOK(WriteStream(outStream, _key.Salt, _key.SaltSize));
 508.167 +  }
 508.168 +  if (ivSize > 0)
 508.169 +  {
 508.170 +    RINOK(WriteStream(outStream, _iv, ivSize));
 508.171 +  }
 508.172 +  return S_OK;
 508.173 +}
 508.174 +
 508.175 +HRESULT CEncoder::CreateFilter()
 508.176 +{
 508.177 +  _aesFilter = new CAesCbcEncoder;
 508.178 +  return S_OK;
 508.179 +}
 508.180 +
 508.181 +#endif
 508.182 +
 508.183 +STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
 508.184 +{
 508.185 +  _key.Init();
 508.186 +  UInt32 i;
 508.187 +  for (i = 0; i < sizeof(_iv); i++)
 508.188 +    _iv[i] = 0;
 508.189 +  if (size == 0)
 508.190 +    return S_OK;
 508.191 +  UInt32 pos = 0;
 508.192 +  Byte firstByte = data[pos++];
 508.193 +
 508.194 +  _key.NumCyclesPower = firstByte & 0x3F;
 508.195 +  if ((firstByte & 0xC0) == 0)
 508.196 +    return S_OK;
 508.197 +  _key.SaltSize = (firstByte >> 7) & 1;
 508.198 +  UInt32 ivSize = (firstByte >> 6) & 1;
 508.199 +
 508.200 +  if (pos >= size)
 508.201 +    return E_INVALIDARG;
 508.202 +  Byte secondByte = data[pos++];
 508.203 +  
 508.204 +  _key.SaltSize += (secondByte >> 4);
 508.205 +  ivSize += (secondByte & 0x0F);
 508.206 +  
 508.207 +  if (pos + _key.SaltSize + ivSize > size)
 508.208 +    return E_INVALIDARG;
 508.209 +  for (i = 0; i < _key.SaltSize; i++)
 508.210 +    _key.Salt[i] = data[pos++];
 508.211 +  for (i = 0; i < ivSize; i++)
 508.212 +    _iv[i] = data[pos++];
 508.213 +  return S_OK;
 508.214 +}
 508.215 +
 508.216 +STDMETHODIMP CBaseCoder::CryptoSetPassword(const Byte *data, UInt32 size)
 508.217 +{
 508.218 +  _key.Password.SetCapacity((size_t)size);
 508.219 +  memcpy(_key.Password, data, (size_t)size);
 508.220 +  return S_OK;
 508.221 +}
 508.222 +
 508.223 +STDMETHODIMP CBaseCoder::Init()
 508.224 +{
 508.225 +  CalculateDigest();
 508.226 +  if (_aesFilter == 0)
 508.227 +  {
 508.228 +    RINOK(CreateFilter());
 508.229 +  }
 508.230 +  CMyComPtr<ICryptoProperties> cp;
 508.231 +  RINOK(_aesFilter.QueryInterface(IID_ICryptoProperties, &cp));
 508.232 +  RINOK(cp->SetKey(_key.Key, sizeof(_key.Key)));
 508.233 +  RINOK(cp->SetInitVector(_iv, sizeof(_iv)));
 508.234 +  return S_OK;
 508.235 +}
 508.236 +
 508.237 +STDMETHODIMP_(UInt32) CBaseCoder::Filter(Byte *data, UInt32 size)
 508.238 +{
 508.239 +  return _aesFilter->Filter(data, size);
 508.240 +}
 508.241 +
 508.242 +HRESULT CDecoder::CreateFilter()
 508.243 +{
 508.244 +  _aesFilter = new CAesCbcDecoder;
 508.245 +  return S_OK;
 508.246 +}
 508.247 +
 508.248 +}}
   509.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   509.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/7zAes.h	Sat Mar 03 10:31:27 2012 -0600
   509.3 @@ -0,0 +1,117 @@
   509.4 +// 7zAes.h
   509.5 +
   509.6 +#ifndef __CRYPTO_7Z_AES_H
   509.7 +#define __CRYPTO_7Z_AES_H
   509.8 +
   509.9 +#include "Common/Buffer.h"
  509.10 +#include "Common/MyCom.h"
  509.11 +#include "Common/MyVector.h"
  509.12 +
  509.13 +#include "../ICoder.h"
  509.14 +#include "../IPassword.h"
  509.15 +
  509.16 +namespace NCrypto {
  509.17 +namespace NSevenZ {
  509.18 +
  509.19 +const int kKeySize = 32;
  509.20 +
  509.21 +class CKeyInfo
  509.22 +{
  509.23 +public:
  509.24 +  int NumCyclesPower;
  509.25 +  UInt32 SaltSize;
  509.26 +  Byte Salt[16];
  509.27 +  CByteBuffer Password;
  509.28 +  Byte Key[kKeySize];
  509.29 +
  509.30 +  bool IsEqualTo(const CKeyInfo &a) const;
  509.31 +  void CalculateDigest();
  509.32 +
  509.33 +  CKeyInfo() { Init(); }
  509.34 +  void Init()
  509.35 +  {
  509.36 +    NumCyclesPower = 0;
  509.37 +    SaltSize = 0;
  509.38 +    for (int i = 0; i < sizeof(Salt); i++)
  509.39 +      Salt[i] = 0;
  509.40 +  }
  509.41 +};
  509.42 +
  509.43 +class CKeyInfoCache
  509.44 +{
  509.45 +  int Size;
  509.46 +  CObjectVector<CKeyInfo> Keys;
  509.47 +public:
  509.48 +  CKeyInfoCache(int size): Size(size) {}
  509.49 +  bool Find(CKeyInfo &key);
  509.50 +  // HRESULT Calculate(CKeyInfo &key);
  509.51 +  void Add(CKeyInfo &key);
  509.52 +};
  509.53 +
  509.54 +class CBase
  509.55 +{
  509.56 +  CKeyInfoCache _cachedKeys;
  509.57 +protected:
  509.58 +  CKeyInfo _key;
  509.59 +  Byte _iv[16];
  509.60 +  UInt32 _ivSize;
  509.61 +  void CalculateDigest();
  509.62 +  CBase();
  509.63 +};
  509.64 +
  509.65 +class CBaseCoder:
  509.66 +  public ICompressFilter,
  509.67 +  public ICryptoSetPassword,
  509.68 +  public CMyUnknownImp,
  509.69 +  public CBase
  509.70 +{
  509.71 +protected:
  509.72 +  CMyComPtr<ICompressFilter> _aesFilter;
  509.73 +
  509.74 +  virtual HRESULT CreateFilter() = 0;
  509.75 +  #ifndef CRYPTO_AES
  509.76 +  HRESULT CreateFilterFromDLL(REFCLSID clsID);
  509.77 +  #endif
  509.78 +public:
  509.79 +  STDMETHOD(Init)();
  509.80 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
  509.81 +  
  509.82 +  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
  509.83 +};
  509.84 +
  509.85 +#ifndef EXTRACT_ONLY
  509.86 +
  509.87 +class CEncoder:
  509.88 +  public CBaseCoder,
  509.89 +  public ICompressWriteCoderProperties,
  509.90 +  // public ICryptoResetSalt,
  509.91 +  public ICryptoResetInitVector
  509.92 +{
  509.93 +  virtual HRESULT CreateFilter();
  509.94 +public:
  509.95 +  MY_UNKNOWN_IMP3(
  509.96 +      ICryptoSetPassword,
  509.97 +      ICompressWriteCoderProperties,
  509.98 +      // ICryptoResetSalt,
  509.99 +      ICryptoResetInitVector)
 509.100 +  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
 509.101 +  // STDMETHOD(ResetSalt)();
 509.102 +  STDMETHOD(ResetInitVector)();
 509.103 +};
 509.104 +#endif
 509.105 +
 509.106 +class CDecoder:
 509.107 +  public CBaseCoder,
 509.108 +  public ICompressSetDecoderProperties2
 509.109 +{
 509.110 +  virtual HRESULT CreateFilter();
 509.111 +public:
 509.112 +  MY_UNKNOWN_IMP2(
 509.113 +      ICryptoSetPassword,
 509.114 +      ICompressSetDecoderProperties2)
 509.115 +  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
 509.116 +};
 509.117 +
 509.118 +}}
 509.119 +
 509.120 +#endif
   510.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   510.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/7zAesRegister.cpp	Sat Mar 03 10:31:27 2012 -0600
   510.3 @@ -0,0 +1,18 @@
   510.4 +// 7zAesRegister.cpp
   510.5 +
   510.6 +#include "StdAfx.h"
   510.7 +
   510.8 +#include "../Common/RegisterCodec.h"
   510.9 +#include "7zAes.h"
  510.10 +
  510.11 +static void *CreateCodec() { return (void *)(ICompressFilter *)(new NCrypto::NSevenZ::CDecoder()); }
  510.12 +#ifndef EXTRACT_ONLY
  510.13 +static void *CreateCodecOut() { return (void *)(ICompressFilter *)(new NCrypto::NSevenZ::CEncoder()); }
  510.14 +#else
  510.15 +#define CreateCodecOut 0
  510.16 +#endif
  510.17 +
  510.18 +static CCodecInfo g_CodecInfo =
  510.19 +  { CreateCodec, CreateCodecOut, 0x06F10701, L"7zAES", 1, true };
  510.20 +
  510.21 +REGISTER_CODEC(7zAES)
   511.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   511.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/HmacSha1.cpp	Sat Mar 03 10:31:27 2012 -0600
   511.3 @@ -0,0 +1,109 @@
   511.4 +// HmacSha1.cpp
   511.5 +
   511.6 +#include "StdAfx.h"
   511.7 +
   511.8 +#include "HmacSha1.h"
   511.9 +
  511.10 +namespace NCrypto {
  511.11 +namespace NSha1 {
  511.12 +
  511.13 +void CHmac::SetKey(const Byte *key, size_t keySize)
  511.14 +{
  511.15 +  Byte keyTemp[kBlockSize];
  511.16 +  size_t i;
  511.17 +  for (i = 0; i < kBlockSize; i++)
  511.18 +    keyTemp[i] = 0;
  511.19 +  if(keySize > kBlockSize)
  511.20 +  {
  511.21 +    _sha.Init();
  511.22 +    _sha.Update(key, keySize);
  511.23 +    _sha.Final(keyTemp);
  511.24 +    keySize = kDigestSize;
  511.25 +  }
  511.26 +  else
  511.27 +    for (i = 0; i < keySize; i++)
  511.28 +      keyTemp[i] = key[i];
  511.29 +  for (i = 0; i < kBlockSize; i++)
  511.30 +    keyTemp[i] ^= 0x36;
  511.31 +  _sha.Init();
  511.32 +  _sha.Update(keyTemp, kBlockSize);
  511.33 +  for (i = 0; i < kBlockSize; i++)
  511.34 +    keyTemp[i] ^= 0x36 ^ 0x5C;
  511.35 +  _sha2.Init();
  511.36 +  _sha2.Update(keyTemp, kBlockSize);
  511.37 +}
  511.38 +
  511.39 +void CHmac::Final(Byte *mac, size_t macSize)
  511.40 +{
  511.41 +  Byte digest[kDigestSize];
  511.42 +  _sha.Final(digest);
  511.43 +  _sha2.Update(digest, kDigestSize);
  511.44 +  _sha2.Final(digest);
  511.45 +  for(size_t i = 0; i < macSize; i++)
  511.46 +    mac[i] = digest[i];
  511.47 +}
  511.48 +
  511.49 +
  511.50 +void CHmac32::SetKey(const Byte *key, size_t keySize)
  511.51 +{
  511.52 +  UInt32 keyTemp[kBlockSizeInWords];
  511.53 +  size_t i;
  511.54 +  for (i = 0; i < kBlockSizeInWords; i++)
  511.55 +    keyTemp[i] = 0;
  511.56 +  if(keySize > kBlockSize)
  511.57 +  {
  511.58 +    CContext sha;
  511.59 +    sha.Init();
  511.60 +    sha.Update(key, keySize);
  511.61 +    Byte digest[kDigestSize];
  511.62 +    sha.Final(digest);
  511.63 +    
  511.64 +    for (int i = 0 ; i < kDigestSizeInWords; i++)
  511.65 +      keyTemp[i] =
  511.66 +          ((UInt32)(digest[i * 4 + 0]) << 24) |
  511.67 +          ((UInt32)(digest[i * 4 + 1]) << 16) |
  511.68 +          ((UInt32)(digest[i * 4 + 2]) <<  8) |
  511.69 +          ((UInt32)(digest[i * 4 + 3]));
  511.70 +    keySize = kDigestSizeInWords;
  511.71 +  }
  511.72 +  else
  511.73 +    for (size_t i = 0; i < keySize; i++)
  511.74 +      keyTemp[i / 4] |= (key[i] << (24 - 8 * (i & 3)));
  511.75 +  for (i = 0; i < kBlockSizeInWords; i++)
  511.76 +    keyTemp[i] ^= 0x36363636;
  511.77 +  _sha.Init();
  511.78 +  _sha.Update(keyTemp, kBlockSizeInWords);
  511.79 +  for (i = 0; i < kBlockSizeInWords; i++)
  511.80 +    keyTemp[i] ^= 0x36363636 ^ 0x5C5C5C5C;
  511.81 +  _sha2.Init();
  511.82 +  _sha2.Update(keyTemp, kBlockSizeInWords);
  511.83 +}
  511.84 +
  511.85 +void CHmac32::Final(UInt32 *mac, size_t macSize)
  511.86 +{
  511.87 +  UInt32 digest[kDigestSizeInWords];
  511.88 +  _sha.Final(digest);
  511.89 +  _sha2.Update(digest, kDigestSizeInWords);
  511.90 +  _sha2.Final(digest);
  511.91 +  for(size_t i = 0; i < macSize; i++)
  511.92 +    mac[i] = digest[i];
  511.93 +}
  511.94 +
  511.95 +void CHmac32::GetLoopXorDigest(UInt32 *mac, UInt32 numIteration)
  511.96 +{
  511.97 +  UInt32 block[kBlockSizeInWords];
  511.98 +  UInt32 block2[kBlockSizeInWords];
  511.99 +  _sha.PrepareBlock(block, kDigestSizeInWords);
 511.100 +  _sha2.PrepareBlock(block2, kDigestSizeInWords);
 511.101 +  for(unsigned int s = 0; s < kDigestSizeInWords; s++)
 511.102 +    block[s] = mac[s];
 511.103 +  for(UInt32 i = 0; i < numIteration; i++)
 511.104 +  {
 511.105 +    _sha.GetBlockDigest(block, block2);
 511.106 +    _sha2.GetBlockDigest(block2, block);
 511.107 +    for (unsigned int s = 0; s < kDigestSizeInWords; s++)
 511.108 +      mac[s] ^= block[s];
 511.109 +  }
 511.110 +}
 511.111 +
 511.112 +}}
   512.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   512.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/HmacSha1.h	Sat Mar 03 10:31:27 2012 -0600
   512.3 @@ -0,0 +1,39 @@
   512.4 +// HmacSha1.h
   512.5 +// Implements HMAC-SHA-1 (RFC2104, FIPS-198)
   512.6 +
   512.7 +#ifndef __CRYPTO_HMAC_SHA1_H
   512.8 +#define __CRYPTO_HMAC_SHA1_H
   512.9 +
  512.10 +#include "Sha1.h"
  512.11 +
  512.12 +namespace NCrypto {
  512.13 +namespace NSha1 {
  512.14 +
  512.15 +// Use:  SetKey(key, keySize); for () Update(data, size); Final(mac, macSize);
  512.16 +
  512.17 +class CHmac
  512.18 +{
  512.19 +  CContext _sha;
  512.20 +  CContext _sha2;
  512.21 +public:
  512.22 +  void SetKey(const Byte *key, size_t keySize);
  512.23 +  void Update(const Byte *data, size_t dataSize) { _sha.Update(data, dataSize); }
  512.24 +  void Final(Byte *mac, size_t macSize = kDigestSize);
  512.25 +};
  512.26 +
  512.27 +class CHmac32
  512.28 +{
  512.29 +  CContext32 _sha;
  512.30 +  CContext32 _sha2;
  512.31 +public:
  512.32 +  void SetKey(const Byte *key, size_t keySize);
  512.33 +  void Update(const UInt32 *data, size_t dataSize) { _sha.Update(data, dataSize); }
  512.34 +  void Final(UInt32 *mac, size_t macSize = kDigestSizeInWords);
  512.35 +  
  512.36 +  // It'sa for hmac function. in,out: mac[kDigestSizeInWords].
  512.37 +  void GetLoopXorDigest(UInt32 *mac, UInt32 numIteration);
  512.38 +};
  512.39 +
  512.40 +}}
  512.41 +
  512.42 +#endif
   513.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   513.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/MyAes.cpp	Sat Mar 03 10:31:27 2012 -0600
   513.3 @@ -0,0 +1,57 @@
   513.4 +// Crypto/MyAes.cpp
   513.5 +
   513.6 +#include "StdAfx.h"
   513.7 +
   513.8 +#include "MyAes.h"
   513.9 +
  513.10 +namespace NCrypto {
  513.11 +
  513.12 +struct CAesTabInit { CAesTabInit() { AesGenTables();} } g_AesTabInit;
  513.13 +
  513.14 +STDMETHODIMP CAesCbcEncoder::Init() { return S_OK; }
  513.15 +
  513.16 +STDMETHODIMP_(UInt32) CAesCbcEncoder::Filter(Byte *data, UInt32 size)
  513.17 +{
  513.18 +  return (UInt32)AesCbc_Encode(&Aes, data, size);
  513.19 +}
  513.20 +
  513.21 +STDMETHODIMP CAesCbcEncoder::SetKey(const Byte *data, UInt32 size)
  513.22 +{
  513.23 +  if ((size & 0x7) != 0 || size < 16 || size > 32)
  513.24 +    return E_INVALIDARG;
  513.25 +  Aes_SetKeyEncode(&Aes.aes, data, size);
  513.26 +  return S_OK;
  513.27 +}
  513.28 +
  513.29 +STDMETHODIMP CAesCbcEncoder::SetInitVector(const Byte *data, UInt32 size)
  513.30 +{
  513.31 +  if (size != AES_BLOCK_SIZE)
  513.32 +    return E_INVALIDARG;
  513.33 +  AesCbc_Init(&Aes, data);
  513.34 +  return S_OK;
  513.35 +}
  513.36 +
  513.37 +STDMETHODIMP CAesCbcDecoder::Init() { return S_OK; }
  513.38 +
  513.39 +STDMETHODIMP_(UInt32) CAesCbcDecoder::Filter(Byte *data, UInt32 size)
  513.40 +{
  513.41 +  return (UInt32)AesCbc_Decode(&Aes, data, size);
  513.42 +}
  513.43 +
  513.44 +STDMETHODIMP CAesCbcDecoder::SetKey(const Byte *data, UInt32 size)
  513.45 +{
  513.46 +  if ((size & 0x7) != 0 || size < 16 || size > 32)
  513.47 +    return E_INVALIDARG;
  513.48 +  Aes_SetKeyDecode(&Aes.aes, data, size);
  513.49 +  return S_OK;
  513.50 +}
  513.51 +
  513.52 +STDMETHODIMP CAesCbcDecoder::SetInitVector(const Byte *data, UInt32 size)
  513.53 +{
  513.54 +  if (size != AES_BLOCK_SIZE)
  513.55 +    return E_INVALIDARG;
  513.56 +  AesCbc_Init(&Aes, data);
  513.57 +  return S_OK;
  513.58 +}
  513.59 +
  513.60 +}
   514.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   514.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/MyAes.h	Sat Mar 03 10:31:27 2012 -0600
   514.3 @@ -0,0 +1,48 @@
   514.4 +// Crypto/MyAes.h
   514.5 +
   514.6 +#ifndef __CRYPTO_MY_AES_H
   514.7 +#define __CRYPTO_MY_AES_H
   514.8 +
   514.9 +extern "C"
  514.10 +{
  514.11 +#include "../../../C/Aes.h"
  514.12 +}
  514.13 +
  514.14 +#include "../../Common/MyCom.h"
  514.15 +#include "../../Common/Types.h"
  514.16 +
  514.17 +#include "../ICoder.h"
  514.18 +
  514.19 +namespace NCrypto {
  514.20 +
  514.21 +class CAesCbcEncoder:
  514.22 +  public ICompressFilter,
  514.23 +  public ICryptoProperties,
  514.24 +  public CMyUnknownImp
  514.25 +{
  514.26 +  CAesCbc Aes;
  514.27 +public:
  514.28 +  MY_UNKNOWN_IMP1(ICryptoProperties)
  514.29 +  STDMETHOD(Init)();
  514.30 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
  514.31 +  STDMETHOD(SetKey)(const Byte *data, UInt32 size);
  514.32 +  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size);
  514.33 +};
  514.34 +
  514.35 +class CAesCbcDecoder:
  514.36 +  public ICompressFilter,
  514.37 +  public ICryptoProperties,
  514.38 +  public CMyUnknownImp
  514.39 +{
  514.40 +  CAesCbc Aes;
  514.41 +public:
  514.42 +  MY_UNKNOWN_IMP1(ICryptoProperties)
  514.43 +  STDMETHOD(Init)();
  514.44 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
  514.45 +  STDMETHOD(SetKey)(const Byte *data, UInt32 size);
  514.46 +  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size);
  514.47 +};
  514.48 +
  514.49 +}
  514.50 +
  514.51 +#endif
   515.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   515.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp	Sat Mar 03 10:31:27 2012 -0600
   515.3 @@ -0,0 +1,83 @@
   515.4 +// Pbkdf2HmacSha1.cpp
   515.5 +
   515.6 +#include "StdAfx.h"
   515.7 +
   515.8 +#include "HmacSha1.h"
   515.9 +
  515.10 +namespace NCrypto {
  515.11 +namespace NSha1 {
  515.12 +
  515.13 +void Pbkdf2Hmac(const Byte *pwd, size_t pwdSize, const Byte *salt, size_t saltSize,
  515.14 +    UInt32 numIterations, Byte *key, size_t keySize)
  515.15 +{
  515.16 +  CHmac baseCtx;
  515.17 +  baseCtx.SetKey(pwd, pwdSize);
  515.18 +  for (UInt32 i = 1; keySize > 0; i++)
  515.19 +  {
  515.20 +    CHmac ctx = baseCtx;
  515.21 +    ctx.Update(salt, saltSize);
  515.22 +    Byte u[kDigestSize] = { (Byte)(i >> 24), (Byte)(i >> 16), (Byte)(i >> 8), (Byte)(i) };
  515.23 +    const unsigned int curSize = (keySize < kDigestSize) ? (unsigned int)keySize : kDigestSize;
  515.24 +    ctx.Update(u, 4);
  515.25 +    ctx.Final(u, kDigestSize);
  515.26 +
  515.27 +    unsigned int s;
  515.28 +    for (s = 0; s < curSize; s++)
  515.29 +      key[s] = u[s];
  515.30 +    
  515.31 +    for (UInt32 j = numIterations; j > 1; j--)
  515.32 +    {
  515.33 +      ctx = baseCtx;
  515.34 +      ctx.Update(u, kDigestSize);
  515.35 +      ctx.Final(u, kDigestSize);
  515.36 +      for (s = 0; s < curSize; s++)
  515.37 +        key[s] ^= u[s];
  515.38 +    }
  515.39 +
  515.40 +    key += curSize;
  515.41 +    keySize -= curSize;
  515.42 +  }
  515.43 +}
  515.44 +
  515.45 +void Pbkdf2Hmac32(const Byte *pwd, size_t pwdSize, const UInt32 *salt, size_t saltSize,
  515.46 +    UInt32 numIterations, UInt32 *key, size_t keySize)
  515.47 +{
  515.48 +  CHmac32 baseCtx;
  515.49 +  baseCtx.SetKey(pwd, pwdSize);
  515.50 +  for (UInt32 i = 1; keySize > 0; i++)
  515.51 +  {
  515.52 +    CHmac32 ctx = baseCtx;
  515.53 +    ctx.Update(salt, saltSize);
  515.54 +    UInt32 u[kDigestSizeInWords] = { i };
  515.55 +    const unsigned int curSize = (keySize < kDigestSizeInWords) ? (unsigned int)keySize : kDigestSizeInWords;
  515.56 +    ctx.Update(u, 1);
  515.57 +    ctx.Final(u, kDigestSizeInWords);
  515.58 +
  515.59 +    // Speed-optimized code start
  515.60 +    ctx = baseCtx;
  515.61 +    ctx.GetLoopXorDigest(u, numIterations - 1);
  515.62 +    // Speed-optimized code end
  515.63 +    
  515.64 +    unsigned int s;
  515.65 +    for (s = 0; s < curSize; s++)
  515.66 +      key[s] = u[s];
  515.67 +    
  515.68 +    /*
  515.69 +    // Default code start
  515.70 +    for (UInt32 j = numIterations; j > 1; j--)
  515.71 +    {
  515.72 +      ctx = baseCtx;
  515.73 +      ctx.Update(u, kDigestSizeInWords);
  515.74 +      ctx.Final(u, kDigestSizeInWords);
  515.75 +      for (s = 0; s < curSize; s++)
  515.76 +        key[s] ^= u[s];
  515.77 +    }
  515.78 +    // Default code end
  515.79 +    */
  515.80 +
  515.81 +    key += curSize;
  515.82 +    keySize -= curSize;
  515.83 +  }
  515.84 +}
  515.85 +
  515.86 +}}
   516.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   516.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/Pbkdf2HmacSha1.h	Sat Mar 03 10:31:27 2012 -0600
   516.3 @@ -0,0 +1,21 @@
   516.4 +// Pbkdf2HmacSha1.h
   516.5 +// Password-Based Key Derivation Function (RFC 2898, PKCS #5) based on HMAC-SHA-1
   516.6 +
   516.7 +#ifndef __CRYPTO_PBKDF2_HMAC_SHA1_H
   516.8 +#define __CRYPTO_PBKDF2_HMAC_SHA1_H
   516.9 +
  516.10 +#include <stddef.h>
  516.11 +#include "../../Common/Types.h"
  516.12 +
  516.13 +namespace NCrypto {
  516.14 +namespace NSha1 {
  516.15 +
  516.16 +void Pbkdf2Hmac(const Byte *pwd, size_t pwdSize, const Byte *salt, size_t saltSize,
  516.17 +    UInt32 numIterations, Byte *key, size_t keySize);
  516.18 +
  516.19 +void Pbkdf2Hmac32(const Byte *pwd, size_t pwdSize, const UInt32 *salt, size_t saltSize,
  516.20 +    UInt32 numIterations, UInt32 *key, size_t keySize);
  516.21 +
  516.22 +}}
  516.23 +
  516.24 +#endif
   517.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   517.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/RandGen.cpp	Sat Mar 03 10:31:27 2012 -0600
   517.3 @@ -0,0 +1,107 @@
   517.4 +// RandGen.cpp
   517.5 +
   517.6 +#include "StdAfx.h"
   517.7 +
   517.8 +#include <stdio.h>
   517.9 +#include "Windows/Synchronization.h"
  517.10 +#include "RandGen.h"
  517.11 +
  517.12 +#ifndef _WIN32
  517.13 +#include <unistd.h>
  517.14 +#define USE_POSIX_TIME
  517.15 +#define USE_POSIX_TIME2
  517.16 +#endif
  517.17 +
  517.18 +#ifdef USE_POSIX_TIME
  517.19 +#include <time.h>
  517.20 +#ifdef USE_POSIX_TIME2
  517.21 +#include <sys/time.h>
  517.22 +#endif
  517.23 +#endif
  517.24 +
  517.25 +// This is not very good random number generator.
  517.26 +// Please use it only for salt.
  517.27 +// First generated data block depends from timer and processID.
  517.28 +// Other generated data blocks depend from previous state
  517.29 +// Maybe it's possible to restore original timer value from generated value.
  517.30 +
  517.31 +void CRandomGenerator::Init()
  517.32 +{
  517.33 +  NCrypto::NSha1::CContext hash;
  517.34 +  hash.Init();
  517.35 +
  517.36 +  #ifdef _WIN32
  517.37 +  DWORD w = ::GetCurrentProcessId();
  517.38 +  hash.Update((const Byte *)&w, sizeof(w));
  517.39 +  w = ::GetCurrentThreadId();
  517.40 +  hash.Update((const Byte *)&w, sizeof(w));
  517.41 +  #else
  517.42 +  pid_t pid = getpid();
  517.43 +  hash.Update((const Byte *)&pid, sizeof(pid));
  517.44 +  pid = getppid();
  517.45 +  hash.Update((const Byte *)&pid, sizeof(pid));
  517.46 +  #endif
  517.47 +
  517.48 +  for (int i = 0; i < 1000; i++)
  517.49 +  {
  517.50 +    #ifdef _WIN32
  517.51 +    LARGE_INTEGER v;
  517.52 +    if (::QueryPerformanceCounter(&v))
  517.53 +      hash.Update((const Byte *)&v.QuadPart, sizeof(v.QuadPart));
  517.54 +    #endif
  517.55 +
  517.56 +    #ifdef USE_POSIX_TIME
  517.57 +    #ifdef USE_POSIX_TIME2
  517.58 +    timeval v;
  517.59 +    if (gettimeofday(&v, 0) == 0)
  517.60 +    {
  517.61 +      hash.Update((const Byte *)&v.tv_sec, sizeof(v.tv_sec));
  517.62 +      hash.Update((const Byte *)&v.tv_usec, sizeof(v.tv_usec));
  517.63 +    }
  517.64 +    #endif
  517.65 +    time_t v2 = time(NULL);
  517.66 +    hash.Update((const Byte *)&v2, sizeof(v2));
  517.67 +    #endif
  517.68 +
  517.69 +    DWORD tickCount = ::GetTickCount();
  517.70 +    hash.Update((const Byte *)&tickCount, sizeof(tickCount));
  517.71 +    
  517.72 +    for (int j = 0; j < 100; j++)
  517.73 +    {
  517.74 +      hash.Final(_buff);
  517.75 +      hash.Init();
  517.76 +      hash.Update(_buff, NCrypto::NSha1::kDigestSize);
  517.77 +    }
  517.78 +  }
  517.79 +  hash.Final(_buff);
  517.80 +  _needInit = false;
  517.81 +}
  517.82 +
  517.83 +static NWindows::NSynchronization::CCriticalSection g_CriticalSection;
  517.84 +
  517.85 +void CRandomGenerator::Generate(Byte *data, unsigned int size)
  517.86 +{
  517.87 +  g_CriticalSection.Enter();
  517.88 +  if (_needInit)
  517.89 +    Init();
  517.90 +  while (size > 0)
  517.91 +  {
  517.92 +    NCrypto::NSha1::CContext hash;
  517.93 +    
  517.94 +    hash.Init();
  517.95 +    hash.Update(_buff, NCrypto::NSha1::kDigestSize);
  517.96 +    hash.Final(_buff);
  517.97 +    
  517.98 +    hash.Init();
  517.99 +    UInt32 salt = 0xF672ABD1;
 517.100 +    hash.Update((const Byte *)&salt, sizeof(salt));
 517.101 +    hash.Update(_buff, NCrypto::NSha1::kDigestSize);
 517.102 +    Byte buff[NCrypto::NSha1::kDigestSize];
 517.103 +    hash.Final(buff);
 517.104 +    for (unsigned int i = 0; i < NCrypto::NSha1::kDigestSize && size > 0; i++, size--)
 517.105 +      *data++ = buff[i];
 517.106 +  }
 517.107 +  g_CriticalSection.Leave();
 517.108 +}
 517.109 +
 517.110 +CRandomGenerator g_RandomGenerator;
   518.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   518.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/RandGen.h	Sat Mar 03 10:31:27 2012 -0600
   518.3 @@ -0,0 +1,21 @@
   518.4 +// RandGen.h
   518.5 +
   518.6 +#ifndef __CRYPTO_RAND_GEN_H
   518.7 +#define __CRYPTO_RAND_GEN_H
   518.8 +
   518.9 +#include "Sha1.h"
  518.10 +
  518.11 +class CRandomGenerator
  518.12 +{
  518.13 +  Byte _buff[NCrypto::NSha1::kDigestSize];
  518.14 +  bool _needInit;
  518.15 +
  518.16 +  void Init();
  518.17 +public:
  518.18 +  CRandomGenerator(): _needInit(true) {};
  518.19 +  void Generate(Byte *data, unsigned size);
  518.20 +};
  518.21 +
  518.22 +extern CRandomGenerator g_RandomGenerator;
  518.23 +
  518.24 +#endif
   519.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   519.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/Rar20Crypto.cpp	Sat Mar 03 10:31:27 2012 -0600
   519.3 @@ -0,0 +1,136 @@
   519.4 +// Crypto/Rar20Crypto.cpp
   519.5 +
   519.6 +#include "StdAfx.h"
   519.7 +
   519.8 +extern "C"
   519.9 +{
  519.10 +  #include "../../../C/7zCrc.h"
  519.11 +  #include "../../../C/CpuArch.h"
  519.12 +  #include "../../../C/RotateDefs.h"
  519.13 +}
  519.14 +
  519.15 +#include "Rar20Crypto.h"
  519.16 +
  519.17 +namespace NCrypto {
  519.18 +namespace NRar20 {
  519.19 +
  519.20 +static const int kNumRounds = 32;
  519.21 +
  519.22 +static const Byte InitSubstTable[256] = {
  519.23 +  215, 19,149, 35, 73,197,192,205,249, 28, 16,119, 48,221,  2, 42,
  519.24 +  232,  1,177,233, 14, 88,219, 25,223,195,244, 90, 87,239,153,137,
  519.25 +  255,199,147, 70, 92, 66,246, 13,216, 40, 62, 29,217,230, 86,  6,
  519.26 +   71, 24,171,196,101,113,218,123, 93, 91,163,178,202, 67, 44,235,
  519.27 +  107,250, 75,234, 49,167,125,211, 83,114,157,144, 32,193,143, 36,
  519.28 +  158,124,247,187, 89,214,141, 47,121,228, 61,130,213,194,174,251,
  519.29 +   97,110, 54,229,115, 57,152, 94,105,243,212, 55,209,245, 63, 11,
  519.30 +  164,200, 31,156, 81,176,227, 21, 76, 99,139,188,127, 17,248, 51,
  519.31 +  207,120,189,210,  8,226, 41, 72,183,203,135,165,166, 60, 98,  7,
  519.32 +  122, 38,155,170, 69,172,252,238, 39,134, 59,128,236, 27,240, 80,
  519.33 +  131,  3, 85,206,145, 79,154,142,159,220,201,133, 74, 64, 20,129,
  519.34 +  224,185,138,103,173,182, 43, 34,254, 82,198,151,231,180, 58, 10,
  519.35 +  118, 26,102, 12, 50,132, 22,191,136,111,162,179, 45,  4,148,108,
  519.36 +  161, 56, 78,126,242,222, 15,175,146, 23, 33,241,181,190, 77,225,
  519.37 +    0, 46,169,186, 68, 95,237, 65, 53,208,253,168,  9, 18,100, 52,
  519.38 +  116,184,160, 96,109, 37, 30,106,140,104,150,  5,204,117,112, 84
  519.39 +};
  519.40 +
  519.41 +void CData::UpdateKeys(const Byte *data)
  519.42 +{
  519.43 +  for (int i = 0; i < 16; i += 4)
  519.44 +    for (int j = 0; j < 4; j++)
  519.45 +      Keys[j] ^= g_CrcTable[data[i + j]];
  519.46 +}
  519.47 +
  519.48 +static void Swap(Byte *b1, Byte *b2)
  519.49 +{
  519.50 +  Byte b = *b1;
  519.51 +  *b1 = *b2;
  519.52 +  *b2 = b;
  519.53 +}
  519.54 +
  519.55 +void CData::SetPassword(const Byte *password, UInt32 passwordLen)
  519.56 +{
  519.57 +  Keys[0] = 0xD3A3B879L;
  519.58 +  Keys[1] = 0x3F6D12F7L;
  519.59 +  Keys[2] = 0x7515A235L;
  519.60 +  Keys[3] = 0xA4E7F123L;
  519.61 +  
  519.62 +  Byte psw[256];
  519.63 +  memset(psw, 0, sizeof(psw));
  519.64 +  memcpy(psw, password, passwordLen);
  519.65 +  memcpy(SubstTable, InitSubstTable, sizeof(SubstTable));
  519.66 +
  519.67 +  for (UInt32 j = 0; j < 256; j++)
  519.68 +    for (UInt32 i = 0; i < passwordLen; i += 2)
  519.69 +    {
  519.70 +      UInt32 n2 = (Byte)g_CrcTable[(psw[i + 1] + j) & 0xFF];
  519.71 +      UInt32 n1 = (Byte)g_CrcTable[(psw[i] - j) & 0xFF];
  519.72 +      for (UInt32 k = 1; (n1 & 0xFF) != n2; n1++, k++)
  519.73 +        Swap(&SubstTable[n1 & 0xFF], &SubstTable[(n1 + i + k) & 0xFF]);
  519.74 +    }
  519.75 +  for (UInt32 i = 0; i < passwordLen; i+= 16)
  519.76 +    EncryptBlock(&psw[i]);
  519.77 +}
  519.78 +
  519.79 +void CData::CryptBlock(Byte *buf, bool encrypt)
  519.80 +{
  519.81 +  Byte inBuf[16];
  519.82 +  UInt32 A, B, C, D, T, TA, TB;
  519.83 +
  519.84 +  A = GetUi32(buf +  0) ^ Keys[0];
  519.85 +  B = GetUi32(buf +  4) ^ Keys[1];
  519.86 +  C = GetUi32(buf +  8) ^ Keys[2];
  519.87 +  D = GetUi32(buf + 12) ^ Keys[3];
  519.88 +
  519.89 +  if (!encrypt)
  519.90 +    memcpy(inBuf, buf, sizeof(inBuf));
  519.91 +  
  519.92 +  for (int i = 0; i < kNumRounds; i++)
  519.93 +  {
  519.94 +    UInt32 key = Keys[(encrypt ? i : (kNumRounds - 1 - i)) & 3];
  519.95 +    T = ((C + rotlFixed(D, 11)) ^ key);
  519.96 +    TA = A ^ SubstLong(T);
  519.97 +    T = ((D ^ rotlFixed(C, 17)) + key);
  519.98 +    TB = B ^ SubstLong(T);
  519.99 +    A = C;
 519.100 +    B = D;
 519.101 +    C = TA;
 519.102 +    D = TB;
 519.103 +  }
 519.104 +
 519.105 +  SetUi32(buf +  0, C ^ Keys[0]);
 519.106 +  SetUi32(buf +  4, D ^ Keys[1]);
 519.107 +  SetUi32(buf +  8, A ^ Keys[2]);
 519.108 +  SetUi32(buf + 12, B ^ Keys[3]);
 519.109 +
 519.110 +  UpdateKeys(encrypt ? buf : inBuf);
 519.111 +}
 519.112 +
 519.113 +STDMETHODIMP CDecoder::CryptoSetPassword(const Byte *data, UInt32 size)
 519.114 +{
 519.115 +  _cipher.SetPassword(data, size);
 519.116 +  return S_OK;
 519.117 +}
 519.118 +
 519.119 +STDMETHODIMP CDecoder::Init()
 519.120 +{
 519.121 +  return S_OK;
 519.122 +}
 519.123 +
 519.124 +static const UInt32 kBlockSize = 16;
 519.125 +
 519.126 +STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size)
 519.127 +{
 519.128 +  if (size == 0)
 519.129 +    return 0;
 519.130 +  if (size < kBlockSize)
 519.131 +    return kBlockSize;
 519.132 +  UInt32 i;
 519.133 +  size -= kBlockSize;
 519.134 +  for (i = 0; i <= size; i += kBlockSize)
 519.135 +    _cipher.DecryptBlock(data + i);
 519.136 +  return i;
 519.137 +}
 519.138 +
 519.139 +}}
   520.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   520.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/Rar20Crypto.h	Sat Mar 03 10:31:27 2012 -0600
   520.3 @@ -0,0 +1,50 @@
   520.4 +// Crypto/Rar20Crypto.h
   520.5 +
   520.6 +#ifndef __CRYPTO_RAR20_CRYPTO_H
   520.7 +#define __CRYPTO_RAR20_CRYPTO_H
   520.8 +
   520.9 +#include "Common/MyCom.h"
  520.10 +
  520.11 +#include "../ICoder.h"
  520.12 +#include "../IPassword.h"
  520.13 +
  520.14 +namespace NCrypto {
  520.15 +namespace NRar20 {
  520.16 +
  520.17 +class CData
  520.18 +{
  520.19 +  Byte SubstTable[256];
  520.20 +  UInt32 Keys[4];
  520.21 +  
  520.22 +  UInt32 SubstLong(UInt32 t)
  520.23 +  {
  520.24 +    return (UInt32)SubstTable[(int)t & 255] |
  520.25 +           ((UInt32)SubstTable[(int)(t >> 8) & 255] << 8) |
  520.26 +           ((UInt32)SubstTable[(int)(t >> 16) & 255] << 16) |
  520.27 +           ((UInt32)SubstTable[(int)(t >> 24) & 255] << 24);
  520.28 +  }
  520.29 +  void UpdateKeys(const Byte *data);
  520.30 +  void CryptBlock(Byte *buf, bool encrypt);
  520.31 +public:
  520.32 +  void EncryptBlock(Byte *buf) { CryptBlock(buf, true); }
  520.33 +  void DecryptBlock(Byte *buf) { CryptBlock(buf, false); }
  520.34 +  void SetPassword(const Byte *password, UInt32 passwordLen);
  520.35 +};
  520.36 +
  520.37 +class CDecoder:
  520.38 +  public ICompressFilter,
  520.39 +  public ICryptoSetPassword,
  520.40 +  public CMyUnknownImp
  520.41 +{
  520.42 +  CData _cipher;
  520.43 +public:
  520.44 +  MY_UNKNOWN_IMP1(ICryptoSetPassword)
  520.45 +
  520.46 +  STDMETHOD(Init)();
  520.47 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
  520.48 +  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
  520.49 +};
  520.50 +
  520.51 +}}
  520.52 +
  520.53 +#endif
   521.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   521.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/RarAes.cpp	Sat Mar 03 10:31:27 2012 -0600
   521.3 @@ -0,0 +1,139 @@
   521.4 +// Crypto/RarAes.cpp
   521.5 +// Note: you must include MyAes.cpp to project to initialize AES tables
   521.6 +
   521.7 +#include "StdAfx.h"
   521.8 +
   521.9 +#include "RarAes.h"
  521.10 +#include "Sha1.h"
  521.11 +
  521.12 +namespace NCrypto {
  521.13 +namespace NRar29 {
  521.14 +
  521.15 +CDecoder::CDecoder():
  521.16 +  _thereIsSalt(false),
  521.17 +  _needCalculate(true),
  521.18 +  _rar350Mode(false)
  521.19 +{
  521.20 +  for (int i = 0; i < sizeof(_salt); i++)
  521.21 +    _salt[i] = 0;
  521.22 +}
  521.23 +
  521.24 +STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
  521.25 +{
  521.26 +  bool thereIsSaltPrev = _thereIsSalt;
  521.27 +  _thereIsSalt = false;
  521.28 +  if (size == 0)
  521.29 +    return S_OK;
  521.30 +  if (size < 8)
  521.31 +    return E_INVALIDARG;
  521.32 +  _thereIsSalt = true;
  521.33 +  bool same = false;
  521.34 +  if (_thereIsSalt == thereIsSaltPrev)
  521.35 +  {
  521.36 +    same = true;
  521.37 +    if (_thereIsSalt)
  521.38 +    {
  521.39 +      for (int i = 0; i < sizeof(_salt); i++)
  521.40 +        if (_salt[i] != data[i])
  521.41 +        {
  521.42 +          same = false;
  521.43 +          break;
  521.44 +        }
  521.45 +    }
  521.46 +  }
  521.47 +  for (int i = 0; i < sizeof(_salt); i++)
  521.48 +    _salt[i] = data[i];
  521.49 +  if (!_needCalculate && !same)
  521.50 +    _needCalculate = true;
  521.51 +  return S_OK;
  521.52 +}
  521.53 +
  521.54 +static const int kMaxPasswordLength = 127 * 2;
  521.55 +
  521.56 +STDMETHODIMP CDecoder::CryptoSetPassword(const Byte *data, UInt32 size)
  521.57 +{
  521.58 +  if (size > kMaxPasswordLength)
  521.59 +    size = kMaxPasswordLength;
  521.60 +  bool same = false;
  521.61 +  if (size == buffer.GetCapacity())
  521.62 +  {
  521.63 +    same = true;
  521.64 +    for (UInt32 i = 0; i < size; i++)
  521.65 +      if (data[i] != buffer[i])
  521.66 +      {
  521.67 +        same = false;
  521.68 +        break;
  521.69 +      }
  521.70 +  }
  521.71 +  if (!_needCalculate && !same)
  521.72 +    _needCalculate = true;
  521.73 +  buffer.SetCapacity(size);
  521.74 +  memcpy(buffer, data, size);
  521.75 +  return S_OK;
  521.76 +}
  521.77 +
  521.78 +STDMETHODIMP CDecoder::Init()
  521.79 +{
  521.80 +  Calculate();
  521.81 +  Aes_SetKeyDecode(&Aes.aes, aesKey, kRarAesKeySize);
  521.82 +  AesCbc_Init(&Aes, aesInit);
  521.83 +  return S_OK;
  521.84 +}
  521.85 +
  521.86 +STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size)
  521.87 +{
  521.88 +  return (UInt32)AesCbc_Decode(&Aes, data, size);
  521.89 +}
  521.90 +
  521.91 +void CDecoder::Calculate()
  521.92 +{
  521.93 +  if (_needCalculate)
  521.94 +  {
  521.95 +    const int kSaltSize = 8;
  521.96 +    
  521.97 +    Byte rawPassword[kMaxPasswordLength + kSaltSize];
  521.98 +    
  521.99 +    memcpy(rawPassword, buffer, buffer.GetCapacity());
 521.100 +    
 521.101 +    size_t rawLength = buffer.GetCapacity();
 521.102 +    
 521.103 +    if (_thereIsSalt)
 521.104 +    {
 521.105 +      memcpy(rawPassword + rawLength, _salt, kSaltSize);
 521.106 +      rawLength += kSaltSize;
 521.107 +    }
 521.108 +    
 521.109 +    NSha1::CContext sha;
 521.110 +    sha.Init();
 521.111 +
 521.112 +    // seems rar reverts hash for sha.
 521.113 +    const int hashRounds = 0x40000;
 521.114 +    int i;
 521.115 +    for (i = 0; i < hashRounds; i++)
 521.116 +    {
 521.117 +      sha.Update(rawPassword, rawLength, _rar350Mode);
 521.118 +      Byte pswNum[3] = { (Byte)i, (Byte)(i >> 8), (Byte)(i >> 16) };
 521.119 +      sha.Update(pswNum, 3, _rar350Mode);
 521.120 +      if (i % (hashRounds / 16) == 0)
 521.121 +      {
 521.122 +        NSha1::CContext shaTemp = sha;
 521.123 +        Byte digest[NSha1::kDigestSize];
 521.124 +        shaTemp.Final(digest);
 521.125 +        aesInit[i / (hashRounds / 16)] = (Byte)digest[4 * 4 + 3];
 521.126 +      }
 521.127 +    }
 521.128 +    /*
 521.129 +    // it's test message for sha
 521.130 +    const char *message = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
 521.131 +    sha.Update((const Byte *)message, strlen(message));
 521.132 +    */
 521.133 +    Byte digest[20];
 521.134 +    sha.Final(digest);
 521.135 +    for (i = 0; i < 4; i++)
 521.136 +      for (int j = 0; j < 4; j++)
 521.137 +        aesKey[i * 4 + j] = (digest[i * 4 + 3 - j]);
 521.138 +  }
 521.139 +  _needCalculate = false;
 521.140 +}
 521.141 +
 521.142 +}}
   522.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   522.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/RarAes.h	Sat Mar 03 10:31:27 2012 -0600
   522.3 @@ -0,0 +1,62 @@
   522.4 +// Crypto/RarAes.h
   522.5 +
   522.6 +#ifndef __CRYPTO_RAR_AES_H
   522.7 +#define __CRYPTO_RAR_AES_H
   522.8 +
   522.9 +extern "C"
  522.10 +{
  522.11 +#include "../../../C/Aes.h"
  522.12 +}
  522.13 +
  522.14 +#include "Common/Buffer.h"
  522.15 +#include "Common/MyCom.h"
  522.16 +
  522.17 +#include "../ICoder.h"
  522.18 +#include "../IPassword.h"
  522.19 +
  522.20 +namespace NCrypto {
  522.21 +namespace NRar29 {
  522.22 +
  522.23 +const UInt32 kRarAesKeySize = 16;
  522.24 +
  522.25 +class CDecoder:
  522.26 +  public ICompressFilter,
  522.27 +  public ICompressSetDecoderProperties2,
  522.28 +  public ICryptoSetPassword,
  522.29 +  public CMyUnknownImp
  522.30 +{
  522.31 +  Byte _salt[8];
  522.32 +  bool _thereIsSalt;
  522.33 +  CByteBuffer buffer;
  522.34 +  Byte aesKey[kRarAesKeySize];
  522.35 +  Byte aesInit[AES_BLOCK_SIZE];
  522.36 +  bool _needCalculate;
  522.37 +
  522.38 +  CAesCbc Aes;
  522.39 +
  522.40 +  bool _rar350Mode;
  522.41 +
  522.42 +  void Calculate();
  522.43 +
  522.44 +public:
  522.45 +
  522.46 +  MY_UNKNOWN_IMP2(
  522.47 +    ICryptoSetPassword,
  522.48 +    ICompressSetDecoderProperties2)
  522.49 +
  522.50 +  STDMETHOD(Init)();
  522.51 +
  522.52 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
  522.53 +
  522.54 +  STDMETHOD(CryptoSetPassword)(const Byte *aData, UInt32 aSize);
  522.55 +
  522.56 +  // ICompressSetDecoderProperties
  522.57 +  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
  522.58 +
  522.59 +  CDecoder();
  522.60 +  void SetRar350Mode(bool rar350Mode) { _rar350Mode = rar350Mode; }
  522.61 +};
  522.62 +
  522.63 +}}
  522.64 +
  522.65 +#endif
   523.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   523.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/Sha1.cpp	Sat Mar 03 10:31:27 2012 -0600
   523.3 @@ -0,0 +1,213 @@
   523.4 +// Crypto/Sha1.cpp
   523.5 +// This file is based on public domain
   523.6 +// Steve Reid and Wei Dai's code from Crypto++
   523.7 +
   523.8 +#include "StdAfx.h"
   523.9 +
  523.10 +#include "Sha1.h"
  523.11 +extern "C"
  523.12 +{
  523.13 +#include "../../../C/RotateDefs.h"
  523.14 +}
  523.15 +
  523.16 +namespace NCrypto {
  523.17 +namespace NSha1 {
  523.18 +
  523.19 +// define it for speed optimization
  523.20 +// #define _SHA1_UNROLL
  523.21 +
  523.22 +static const unsigned kNumW =
  523.23 +  #ifdef _SHA1_UNROLL
  523.24 +  16;
  523.25 +  #else
  523.26 +  80;
  523.27 +  #endif
  523.28 +  
  523.29 +
  523.30 +#define w0(i) (W[(i)] = data[(i)])
  523.31 +
  523.32 +#ifdef _SHA1_UNROLL
  523.33 +#define w1(i) (W[(i)&15] = rotlFixed(W[((i)-3)&15] ^ W[((i)-8)&15] ^ W[((i)-14)&15] ^ W[((i)-16)&15], 1))
  523.34 +#else
  523.35 +#define w1(i) (W[(i)] = rotlFixed(W[(i)-3] ^ W[(i)-8] ^ W[(i)-14] ^ W[(i)-16], 1))
  523.36 +#endif
  523.37 +
  523.38 +#define f1(x,y,z) (z^(x&(y^z)))
  523.39 +#define f2(x,y,z) (x^y^z)
  523.40 +#define f3(x,y,z) ((x&y)|(z&(x|y)))
  523.41 +#define f4(x,y,z) (x^y^z)
  523.42 +
  523.43 +#define RK1(a,b,c,d,e,i, f, w, k) e += f(b,c,d) + w(i) + k + rotlFixed(a,5); b = rotlFixed(b,30);
  523.44 +
  523.45 +#define R0(a,b,c,d,e,i) RK1(a,b,c,d,e,i, f1, w0, 0x5A827999)
  523.46 +#define R1(a,b,c,d,e,i) RK1(a,b,c,d,e,i, f1, w1, 0x5A827999)
  523.47 +#define R2(a,b,c,d,e,i) RK1(a,b,c,d,e,i, f2, w1, 0x6ED9EBA1)
  523.48 +#define R3(a,b,c,d,e,i) RK1(a,b,c,d,e,i, f3, w1, 0x8F1BBCDC)
  523.49 +#define R4(a,b,c,d,e,i) RK1(a,b,c,d,e,i, f4, w1, 0xCA62C1D6)
  523.50 +
  523.51 +#define RX_1_4(rx1, rx4, i) rx1(a,b,c,d,e,i); rx4(e,a,b,c,d,i+1); rx4(d,e,a,b,c,i+2); rx4(c,d,e,a,b,i+3); rx4(b,c,d,e,a,i+4);
  523.52 +#define RX_5(rx, i) RX_1_4(rx, rx, i);
  523.53 +
  523.54 +void CContextBase::Init()
  523.55 +{
  523.56 +  _state[0] = 0x67452301;
  523.57 +  _state[1] = 0xEFCDAB89;
  523.58 +  _state[2] = 0x98BADCFE;
  523.59 +  _state[3] = 0x10325476;
  523.60 +  _state[4] = 0xC3D2E1F0;
  523.61 +  _count = 0;
  523.62 +}
  523.63 +
  523.64 +void CContextBase::GetBlockDigest(UInt32 *data, UInt32 *destDigest, bool returnRes)
  523.65 +{
  523.66 +  UInt32 a, b, c, d, e;
  523.67 +  UInt32 W[kNumW];
  523.68 +
  523.69 +  a = _state[0];
  523.70 +  b = _state[1];
  523.71 +  c = _state[2];
  523.72 +  d = _state[3];
  523.73 +  e = _state[4];
  523.74 +  #ifdef _SHA1_UNROLL
  523.75 +  RX_5(R0, 0); RX_5(R0, 5); RX_5(R0, 10);
  523.76 +  #else
  523.77 +  int i;
  523.78 +  for (i = 0; i < 15; i += 5) { RX_5(R0, i); }
  523.79 +  #endif
  523.80 +
  523.81 +  RX_1_4(R0, R1, 15);
  523.82 +
  523.83 +
  523.84 +  #ifdef _SHA1_UNROLL
  523.85 +  RX_5(R2, 20); RX_5(R2, 25); RX_5(R2, 30); RX_5(R2, 35);
  523.86 +  RX_5(R3, 40); RX_5(R3, 45); RX_5(R3, 50); RX_5(R3, 55);
  523.87 +  RX_5(R4, 60); RX_5(R4, 65); RX_5(R4, 70); RX_5(R4, 75);
  523.88 +  #else
  523.89 +  i = 20;
  523.90 +  for (; i < 40; i += 5) { RX_5(R2, i); }
  523.91 +  for (; i < 60; i += 5) { RX_5(R3, i); }
  523.92 +  for (; i < 80; i += 5) { RX_5(R4, i); }
  523.93 +  #endif
  523.94 +
  523.95 +  destDigest[0] = _state[0] + a;
  523.96 +  destDigest[1] = _state[1] + b;
  523.97 +  destDigest[2] = _state[2] + c;
  523.98 +  destDigest[3] = _state[3] + d;
  523.99 +  destDigest[4] = _state[4] + e;
 523.100 +
 523.101 +  if (returnRes)
 523.102 +    for (int i = 0 ; i < 16; i++)
 523.103 +      data[i] = W[kNumW - 16 + i];
 523.104 +  
 523.105 +  // Wipe variables
 523.106 +  // a = b = c = d = e = 0;
 523.107 +}
 523.108 +
 523.109 +void CContextBase::PrepareBlock(UInt32 *block, unsigned size) const
 523.110 +{
 523.111 +  unsigned curBufferPos = size & 0xF;
 523.112 +  block[curBufferPos++] = 0x80000000;
 523.113 +  while (curBufferPos != (16 - 2))
 523.114 +    block[curBufferPos++] = 0;
 523.115 +  const UInt64 lenInBits = (_count << 9) + ((UInt64)size << 5);
 523.116 +  block[curBufferPos++] = (UInt32)(lenInBits >> 32);
 523.117 +  block[curBufferPos++] = (UInt32)(lenInBits);
 523.118 +}
 523.119 +
 523.120 +void CContext::Update(Byte *data, size_t size, bool rar350Mode)
 523.121 +{
 523.122 +  bool returnRes = false;
 523.123 +  unsigned curBufferPos = _count2;
 523.124 +  while (size-- > 0)
 523.125 +  {
 523.126 +    int pos = (int)(curBufferPos & 3);
 523.127 +    if (pos == 0)
 523.128 +      _buffer[curBufferPos >> 2] = 0;
 523.129 +    _buffer[curBufferPos >> 2] |= ((UInt32)*data++) << (8 * (3 - pos));
 523.130 +    if (++curBufferPos == kBlockSize)
 523.131 +    {
 523.132 +      curBufferPos = 0;
 523.133 +      CContextBase::UpdateBlock(_buffer, returnRes);
 523.134 +      if (returnRes)
 523.135 +        for (int i = 0; i < kBlockSizeInWords; i++)
 523.136 +        {
 523.137 +          UInt32 d = _buffer[i];
 523.138 +          data[i * 4 + 0 - kBlockSize] = (Byte)(d);
 523.139 +          data[i * 4 + 1 - kBlockSize] = (Byte)(d >>  8);
 523.140 +          data[i * 4 + 2 - kBlockSize] = (Byte)(d >> 16);
 523.141 +          data[i * 4 + 3 - kBlockSize] = (Byte)(d >> 24);
 523.142 +        }
 523.143 +      returnRes = rar350Mode;
 523.144 +    }
 523.145 +  }
 523.146 +  _count2 = curBufferPos;
 523.147 +}
 523.148 +
 523.149 +void CContext::Final(Byte *digest)
 523.150 +{
 523.151 +  const UInt64 lenInBits = (_count << 9) + ((UInt64)_count2 << 3);
 523.152 +  unsigned curBufferPos = _count2;
 523.153 +  int pos = (int)(curBufferPos & 3);
 523.154 +  curBufferPos >>= 2;
 523.155 +  if (pos == 0)
 523.156 +    _buffer[curBufferPos] = 0;
 523.157 +  _buffer[curBufferPos++] |= ((UInt32)0x80) << (8 * (3 - pos));
 523.158 +
 523.159 +  while (curBufferPos != (16 - 2))
 523.160 +  {
 523.161 +    curBufferPos &= 0xF;
 523.162 +    if (curBufferPos == 0)
 523.163 +      UpdateBlock();
 523.164 +    _buffer[curBufferPos++] = 0;
 523.165 +  }
 523.166 +  _buffer[curBufferPos++] = (UInt32)(lenInBits >> 32);
 523.167 +  _buffer[curBufferPos++] = (UInt32)(lenInBits);
 523.168 +  UpdateBlock();
 523.169 +
 523.170 +  int i;
 523.171 +  for (i = 0; i < kDigestSizeInWords; i++)
 523.172 +  {
 523.173 +    UInt32 state = _state[i] & 0xFFFFFFFF;
 523.174 +    *digest++ = (Byte)(state >> 24);
 523.175 +    *digest++ = (Byte)(state >> 16);
 523.176 +    *digest++ = (Byte)(state >> 8);
 523.177 +    *digest++ = (Byte)(state);
 523.178 +  }
 523.179 +  Init();
 523.180 +}
 523.181 +
 523.182 +///////////////////////////
 523.183 +// Words version
 523.184 +
 523.185 +void CContext32::Update(const UInt32 *data, size_t size)
 523.186 +{
 523.187 +  while (size-- > 0)
 523.188 +  {
 523.189 +    _buffer[_count2++] = *data++;
 523.190 +    if (_count2 == kBlockSizeInWords)
 523.191 +    {
 523.192 +      _count2 = 0;
 523.193 +      UpdateBlock();
 523.194 +    }
 523.195 +  }
 523.196 +}
 523.197 +
 523.198 +void CContext32::Final(UInt32 *digest)
 523.199 +{
 523.200 +  const UInt64 lenInBits = (_count << 9) + ((UInt64)_count2 << 5);
 523.201 +  unsigned curBufferPos = _count2;
 523.202 +  _buffer[curBufferPos++] = 0x80000000;
 523.203 +  while (curBufferPos != (16 - 2))
 523.204 +  {
 523.205 +    curBufferPos &= 0xF;
 523.206 +    if (curBufferPos == 0)
 523.207 +      UpdateBlock();
 523.208 +    _buffer[curBufferPos++] = 0;
 523.209 +  }
 523.210 +  _buffer[curBufferPos++] = (UInt32)(lenInBits >> 32);
 523.211 +  _buffer[curBufferPos++] = (UInt32)(lenInBits);
 523.212 +  GetBlockDigest(_buffer, digest);
 523.213 +  Init();
 523.214 +}
 523.215 +
 523.216 +}}
   524.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   524.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/Sha1.h	Sat Mar 03 10:31:27 2012 -0600
   524.3 @@ -0,0 +1,68 @@
   524.4 +// Crypto/Sha1.h
   524.5 +// This file is based on public domain
   524.6 +// Steve Reid and Wei Dai's code from Crypto++
   524.7 +
   524.8 +#ifndef __CRYPTO_SHA1_H
   524.9 +#define __CRYPTO_SHA1_H
  524.10 +
  524.11 +#include <stddef.h>
  524.12 +#include "../../Common/Types.h"
  524.13 +
  524.14 +// Sha1 implementation in RAR before version 3.60 has bug:
  524.15 +// it changes data bytes in some cases.
  524.16 +// So this class supports both versions: normal_SHA and rar3Mode
  524.17 +
  524.18 +namespace NCrypto {
  524.19 +namespace NSha1 {
  524.20 +
  524.21 +const unsigned kBlockSize = 64;
  524.22 +const unsigned kDigestSize = 20;
  524.23 +
  524.24 +const unsigned kBlockSizeInWords = (kBlockSize >> 2);
  524.25 +const unsigned kDigestSizeInWords = (kDigestSize >> 2);
  524.26 +
  524.27 +class CContextBase
  524.28 +{
  524.29 +protected:
  524.30 +  UInt32 _state[5];
  524.31 +  UInt64 _count;
  524.32 +  void UpdateBlock(UInt32 *data, bool returnRes = false)
  524.33 +  {
  524.34 +    GetBlockDigest(data, _state, returnRes);
  524.35 +    _count++;
  524.36 +  }
  524.37 +public:
  524.38 +  void Init();
  524.39 +  void GetBlockDigest(UInt32 *blockData, UInt32 *destDigest, bool returnRes = false);
  524.40 +  // PrepareBlock can be used only when size <= 13. size in Words
  524.41 +  void PrepareBlock(UInt32 *block, unsigned int size) const;
  524.42 +};
  524.43 +
  524.44 +class CContextBase2: public CContextBase
  524.45 +{
  524.46 +protected:
  524.47 +  unsigned _count2;
  524.48 +  UInt32 _buffer[kBlockSizeInWords];
  524.49 +  void UpdateBlock() { CContextBase::UpdateBlock(_buffer); }
  524.50 +public:
  524.51 +  void Init() { CContextBase::Init(); _count2 = 0; }
  524.52 +};
  524.53 +
  524.54 +class CContext: public CContextBase2
  524.55 +{
  524.56 +public:
  524.57 +  void Update(Byte *data, size_t size, bool rar350Mode = false);
  524.58 +  void Update(const Byte *data, size_t size) { Update((Byte *)data, size, false); }
  524.59 +  void Final(Byte *digest);
  524.60 +};
  524.61 +
  524.62 +class CContext32: public CContextBase2
  524.63 +{
  524.64 +public:
  524.65 +  void Update(const UInt32 *data, size_t size);
  524.66 +  void Final(UInt32 *digest);
  524.67 +};
  524.68 +
  524.69 +}}
  524.70 +
  524.71 +#endif
   525.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   525.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   525.3 @@ -0,0 +1,8 @@
   525.4 +// StdAfx.h
   525.5 +
   525.6 +#ifndef __STDAFX_H
   525.7 +#define __STDAFX_H
   525.8 +
   525.9 +#include "../../Common/MyWindows.h"
  525.10 +
  525.11 +#endif
   526.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   526.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/WzAes.cpp	Sat Mar 03 10:31:27 2012 -0600
   526.3 @@ -0,0 +1,209 @@
   526.4 +// Crypto/WzAes.cpp
   526.5 +/*
   526.6 +This code implements Brian Gladman's scheme
   526.7 +specified in password Based File Encryption Utility.
   526.8 +
   526.9 +Note: you must include MyAes.cpp to project to initialize AES tables
  526.10 +*/
  526.11 +
  526.12 +#include "StdAfx.h"
  526.13 +
  526.14 +#include "../Common/StreamObjects.h"
  526.15 +#include "../Common/StreamUtils.h"
  526.16 +
  526.17 +#include "Pbkdf2HmacSha1.h"
  526.18 +#include "RandGen.h"
  526.19 +#include "WzAes.h"
  526.20 +
  526.21 +// define it if you don't want to use speed-optimized version of Pbkdf2HmacSha1
  526.22 +// #define _NO_WZAES_OPTIMIZATIONS
  526.23 +
  526.24 +namespace NCrypto {
  526.25 +namespace NWzAes {
  526.26 +
  526.27 +const unsigned int kAesKeySizeMax = 32;
  526.28 +
  526.29 +static const UInt32 kNumKeyGenIterations = 1000;
  526.30 +
  526.31 +STDMETHODIMP CBaseCoder::CryptoSetPassword(const Byte *data, UInt32 size)
  526.32 +{
  526.33 +  if(size > kPasswordSizeMax)
  526.34 +    return E_INVALIDARG;
  526.35 +  _key.Password.SetCapacity(size);
  526.36 +  memcpy(_key.Password, data, size);
  526.37 +  return S_OK;
  526.38 +}
  526.39 +
  526.40 +#define SetUi32(p, d) { UInt32 x = (d); (p)[0] = (Byte)x; (p)[1] = (Byte)(x >> 8); \
  526.41 +    (p)[2] = (Byte)(x >> 16); (p)[3] = (Byte)(x >> 24); }
  526.42 +
  526.43 +void CBaseCoder::EncryptData(Byte *data, UInt32 size)
  526.44 +{
  526.45 +  unsigned int pos = _blockPos;
  526.46 +  for (; size > 0; size--)
  526.47 +  {
  526.48 +    if (pos == AES_BLOCK_SIZE)
  526.49 +    {
  526.50 +      if (++_counter[0] == 0)
  526.51 +        _counter[1]++;
  526.52 +      UInt32 temp[4];
  526.53 +      Aes_Encode32(&Aes, temp, _counter);
  526.54 +      SetUi32(_buffer,      temp[0]);
  526.55 +      SetUi32(_buffer + 4,  temp[1]);
  526.56 +      SetUi32(_buffer + 8,  temp[2]);
  526.57 +      SetUi32(_buffer + 12, temp[3]);
  526.58 +      pos = 0;
  526.59 +    }
  526.60 +    *data++ ^= _buffer[pos++];
  526.61 +  }
  526.62 +  _blockPos = pos;
  526.63 +}
  526.64 +
  526.65 +#ifndef _NO_WZAES_OPTIMIZATIONS
  526.66 +
  526.67 +static void BytesToBeUInt32s(const Byte *src, UInt32 *dest, int destSize)
  526.68 +{
  526.69 +  for (int i = 0 ; i < destSize; i++)
  526.70 +      dest[i] =
  526.71 +          ((UInt32)(src[i * 4 + 0]) << 24) |
  526.72 +          ((UInt32)(src[i * 4 + 1]) << 16) |
  526.73 +          ((UInt32)(src[i * 4 + 2]) <<  8) |
  526.74 +          ((UInt32)(src[i * 4 + 3]));
  526.75 +}
  526.76 +
  526.77 +#endif
  526.78 +
  526.79 +STDMETHODIMP CBaseCoder::Init()
  526.80 +{
  526.81 +  UInt32 keySize = _key.GetKeySize();
  526.82 +  UInt32 keysTotalSize = 2 * keySize + kPwdVerifCodeSize;
  526.83 +  Byte buf[2 * kAesKeySizeMax + kPwdVerifCodeSize];
  526.84 +  
  526.85 +  // for (int ii = 0; ii < 1000; ii++)
  526.86 +  {
  526.87 +    #ifdef _NO_WZAES_OPTIMIZATIONS
  526.88 +
  526.89 +    NSha1::Pbkdf2Hmac(
  526.90 +      _key.Password, _key.Password.GetCapacity(),
  526.91 +      _key.Salt, _key.GetSaltSize(),
  526.92 +      kNumKeyGenIterations,
  526.93 +      buf, keysTotalSize);
  526.94 +
  526.95 +    #else
  526.96 +
  526.97 +    UInt32 buf32[(2 * kAesKeySizeMax + kPwdVerifCodeSize + 3) / 4];
  526.98 +    UInt32 key32SizeTotal = (keysTotalSize + 3) / 4;
  526.99 +    UInt32 salt[kSaltSizeMax * 4];
 526.100 +    UInt32 saltSizeInWords = _key.GetSaltSize() / 4;
 526.101 +    BytesToBeUInt32s(_key.Salt, salt, saltSizeInWords);
 526.102 +    NSha1::Pbkdf2Hmac32(
 526.103 +      _key.Password, _key.Password.GetCapacity(),
 526.104 +      salt, saltSizeInWords,
 526.105 +      kNumKeyGenIterations,
 526.106 +      buf32, key32SizeTotal);
 526.107 +    for (UInt32 j = 0; j < keysTotalSize; j++)
 526.108 +      buf[j] = (Byte)(buf32[j / 4] >> (24 - 8 * (j & 3)));
 526.109 +    
 526.110 +    #endif
 526.111 +  }
 526.112 +
 526.113 +  _hmac.SetKey(buf + keySize, keySize);
 526.114 +  memcpy(_key.PwdVerifComputed, buf + 2 * keySize, kPwdVerifCodeSize);
 526.115 +  
 526.116 +  _blockPos = AES_BLOCK_SIZE;
 526.117 +  for (int i = 0; i < 4; i++)
 526.118 +    _counter[i] = 0;
 526.119 +
 526.120 +  Aes_SetKeyEncode(&Aes, buf, keySize);
 526.121 +  return S_OK;
 526.122 +}
 526.123 +
 526.124 +/*
 526.125 +STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
 526.126 +{
 526.127 +  Byte keySizeMode = 3;
 526.128 +  return outStream->Write(&keySizeMode, 1, NULL);
 526.129 +}
 526.130 +*/
 526.131 +
 526.132 +HRESULT CEncoder::WriteHeader(ISequentialOutStream *outStream)
 526.133 +{
 526.134 +  UInt32 saltSize = _key.GetSaltSize();
 526.135 +  g_RandomGenerator.Generate(_key.Salt, saltSize);
 526.136 +  Init();
 526.137 +  RINOK(WriteStream(outStream, _key.Salt, saltSize));
 526.138 +  return WriteStream(outStream, _key.PwdVerifComputed, kPwdVerifCodeSize);
 526.139 +}
 526.140 +
 526.141 +HRESULT CEncoder::WriteFooter(ISequentialOutStream *outStream)
 526.142 +{
 526.143 +  Byte mac[kMacSize];
 526.144 +  _hmac.Final(mac, kMacSize);
 526.145 +  return WriteStream(outStream, mac, kMacSize);
 526.146 +}
 526.147 +
 526.148 +STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
 526.149 +{
 526.150 +  if (size != 1)
 526.151 +    return E_INVALIDARG;
 526.152 +  _key.Init();
 526.153 +  Byte keySizeMode = data[0];
 526.154 +  if (keySizeMode < 1 || keySizeMode > 3)
 526.155 +    return E_INVALIDARG;
 526.156 +  _key.KeySizeMode = keySizeMode;
 526.157 +  return S_OK;
 526.158 +}
 526.159 +
 526.160 +HRESULT CDecoder::ReadHeader(ISequentialInStream *inStream)
 526.161 +{
 526.162 +  UInt32 saltSize = _key.GetSaltSize();
 526.163 +  UInt32 extraSize = saltSize + kPwdVerifCodeSize;
 526.164 +  Byte temp[kSaltSizeMax + kPwdVerifCodeSize];
 526.165 +  RINOK(ReadStream_FAIL(inStream, temp, extraSize));
 526.166 +  UInt32 i;
 526.167 +  for (i = 0; i < saltSize; i++)
 526.168 +    _key.Salt[i] = temp[i];
 526.169 +  for (i = 0; i < kPwdVerifCodeSize; i++)
 526.170 +    _pwdVerifFromArchive[i] = temp[saltSize + i];
 526.171 +  return S_OK;
 526.172 +}
 526.173 +
 526.174 +static bool CompareArrays(const Byte *p1, const Byte *p2, UInt32 size)
 526.175 +{
 526.176 +  for (UInt32 i = 0; i < size; i++)
 526.177 +    if (p1[i] != p2[i])
 526.178 +      return false;
 526.179 +  return true;
 526.180 +}
 526.181 +
 526.182 +bool CDecoder::CheckPasswordVerifyCode()
 526.183 +{
 526.184 +  return CompareArrays(_key.PwdVerifComputed, _pwdVerifFromArchive, kPwdVerifCodeSize);
 526.185 +}
 526.186 +
 526.187 +HRESULT CDecoder::CheckMac(ISequentialInStream *inStream, bool &isOK)
 526.188 +{
 526.189 +  isOK = false;
 526.190 +  Byte mac1[kMacSize];
 526.191 +  RINOK(ReadStream_FAIL(inStream, mac1, kMacSize));
 526.192 +  Byte mac2[kMacSize];
 526.193 +  _hmac.Final(mac2, kMacSize);
 526.194 +  isOK = CompareArrays(mac1, mac2, kMacSize);
 526.195 +  return S_OK;
 526.196 +}
 526.197 +
 526.198 +STDMETHODIMP_(UInt32) CEncoder::Filter(Byte *data, UInt32 size)
 526.199 +{
 526.200 +  EncryptData(data, size);
 526.201 +  _hmac.Update(data, size);
 526.202 +  return size;
 526.203 +}
 526.204 +
 526.205 +STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size)
 526.206 +{
 526.207 +  _hmac.Update(data, size);
 526.208 +  EncryptData(data, size);
 526.209 +  return size;
 526.210 +}
 526.211 +
 526.212 +}}
   527.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   527.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/WzAes.h	Sat Mar 03 10:31:27 2012 -0600
   527.3 @@ -0,0 +1,119 @@
   527.4 +// Crypto/WzAes.h
   527.5 +/*
   527.6 +This code implements Brian Gladman's scheme
   527.7 +specified in password Based File Encryption Utility:
   527.8 +  - AES encryption (128,192,256-bit) in Counter (CTR) mode.
   527.9 +  - HMAC-SHA1 authentication for encrypted data (10 bytes)
  527.10 +  - Keys are derived by PPKDF2(RFC2898)-HMAC-SHA1 from ASCII password and
  527.11 +    Salt (saltSize = aesKeySize / 2).
  527.12 +  - 2 bytes contain Password Verifier's Code
  527.13 +*/
  527.14 +
  527.15 +#ifndef __CRYPTO_WZ_AES_H
  527.16 +#define __CRYPTO_WZ_AES_H
  527.17 +
  527.18 +extern "C"
  527.19 +{
  527.20 +#include "../../../C/Aes.h"
  527.21 +}
  527.22 +
  527.23 +#include "Common/Buffer.h"
  527.24 +#include "Common/MyCom.h"
  527.25 +#include "Common/MyVector.h"
  527.26 +
  527.27 +#include "../ICoder.h"
  527.28 +#include "../IPassword.h"
  527.29 +
  527.30 +#include "HmacSha1.h"
  527.31 +
  527.32 +namespace NCrypto {
  527.33 +namespace NWzAes {
  527.34 +
  527.35 +const unsigned int kSaltSizeMax = 16;
  527.36 +const unsigned int kMacSize = 10;
  527.37 +
  527.38 +const UInt32 kPasswordSizeMax = 99; // 128;
  527.39 +
  527.40 +// Password Verification Code Size
  527.41 +const unsigned int kPwdVerifCodeSize = 2;
  527.42 +
  527.43 +class CKeyInfo
  527.44 +{
  527.45 +public:
  527.46 +  Byte KeySizeMode; // 1 - 128-bit , 2 - 192-bit , 3 - 256-bit
  527.47 +  Byte Salt[kSaltSizeMax];
  527.48 +  Byte PwdVerifComputed[kPwdVerifCodeSize];
  527.49 +
  527.50 +  CByteBuffer Password;
  527.51 +
  527.52 +  UInt32 GetKeySize() const  { return (8 * (KeySizeMode & 3) + 8); }
  527.53 +  UInt32 GetSaltSize() const { return (4 * (KeySizeMode & 3) + 4); }
  527.54 +
  527.55 +  CKeyInfo() { Init(); }
  527.56 +  void Init() { KeySizeMode = 3; }
  527.57 +};
  527.58 +
  527.59 +class CBaseCoder:
  527.60 +  public ICompressFilter,
  527.61 +  public ICryptoSetPassword,
  527.62 +  public CMyUnknownImp
  527.63 +{
  527.64 +protected:
  527.65 +  CKeyInfo _key;
  527.66 +  UInt32 _counter[AES_BLOCK_SIZE / 4];
  527.67 +  Byte _buffer[AES_BLOCK_SIZE];
  527.68 +  NSha1::CHmac _hmac;
  527.69 +  unsigned int _blockPos;
  527.70 +  Byte _pwdVerifFromArchive[kPwdVerifCodeSize];
  527.71 +
  527.72 +  void EncryptData(Byte *data, UInt32 size);
  527.73 +
  527.74 +  CAes Aes;
  527.75 +
  527.76 +public:
  527.77 +  STDMETHOD(Init)();
  527.78 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) = 0;
  527.79 +  
  527.80 +  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
  527.81 +
  527.82 +  UInt32 GetHeaderSize() const { return _key.GetSaltSize() + kPwdVerifCodeSize; }
  527.83 +};
  527.84 +
  527.85 +class CEncoder:
  527.86 +  public CBaseCoder
  527.87 +  // public ICompressWriteCoderProperties
  527.88 +{
  527.89 +public:
  527.90 +  MY_UNKNOWN_IMP1(ICryptoSetPassword)
  527.91 +  //  ICompressWriteCoderProperties
  527.92 +  // STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
  527.93 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
  527.94 +  HRESULT WriteHeader(ISequentialOutStream *outStream);
  527.95 +  HRESULT WriteFooter(ISequentialOutStream *outStream);
  527.96 +  bool SetKeyMode(Byte mode)
  527.97 +  {
  527.98 +    if (mode < 1 || mode > 3)
  527.99 +      return false;
 527.100 +    _key.KeySizeMode = mode;
 527.101 +    return true;
 527.102 +  }
 527.103 +};
 527.104 +
 527.105 +class CDecoder:
 527.106 +  public CBaseCoder,
 527.107 +  public ICompressSetDecoderProperties2
 527.108 +{
 527.109 +public:
 527.110 +  MY_UNKNOWN_IMP2(
 527.111 +      ICryptoSetPassword,
 527.112 +      ICompressSetDecoderProperties2)
 527.113 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
 527.114 +  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
 527.115 +  HRESULT ReadHeader(ISequentialInStream *inStream);
 527.116 +  bool CheckPasswordVerifyCode();
 527.117 +  HRESULT CheckMac(ISequentialInStream *inStream, bool &isOK);
 527.118 +};
 527.119 +
 527.120 +}}
 527.121 +
 527.122 +#endif
   528.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   528.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/ZipCrypto.cpp	Sat Mar 03 10:31:27 2012 -0600
   528.3 @@ -0,0 +1,131 @@
   528.4 +// Crypto/ZipCrypto.cpp
   528.5 +
   528.6 +#include "StdAfx.h"
   528.7 +
   528.8 +extern "C"
   528.9 +{
  528.10 +#include "../../../C/7zCrc.h"
  528.11 +}
  528.12 +
  528.13 +#include "../Common/StreamUtils.h"
  528.14 +
  528.15 +#include "RandGen.h"
  528.16 +#include "ZipCrypto.h"
  528.17 +
  528.18 +namespace NCrypto {
  528.19 +namespace NZip {
  528.20 +
  528.21 +void CCipher::UpdateKeys(Byte b)
  528.22 +{
  528.23 +  Keys[0] = CRC_UPDATE_BYTE(Keys[0], b);
  528.24 +  Keys[1] += Keys[0] & 0xff;
  528.25 +  Keys[1] = Keys[1] * 134775813L + 1;
  528.26 +  Keys[2] = CRC_UPDATE_BYTE(Keys[2], (Byte)(Keys[1] >> 24));
  528.27 +}
  528.28 +
  528.29 +void CCipher::SetPassword(const Byte *password, UInt32 passwordLen)
  528.30 +{
  528.31 +  Keys[0] = 305419896L;
  528.32 +  Keys[1] = 591751049L;
  528.33 +  Keys[2] = 878082192L;
  528.34 +  for (UInt32 i = 0; i < passwordLen; i++)
  528.35 +    UpdateKeys(password[i]);
  528.36 +}
  528.37 +
  528.38 +Byte CCipher::DecryptByteSpec()
  528.39 +{
  528.40 +  UInt32 temp = Keys[2] | 2;
  528.41 +  return (Byte)((temp * (temp ^ 1)) >> 8);
  528.42 +}
  528.43 +
  528.44 +Byte CCipher::DecryptByte(Byte b)
  528.45 +{
  528.46 +  Byte c = (Byte)(b ^ DecryptByteSpec());
  528.47 +  UpdateKeys(c);
  528.48 +  return c;
  528.49 +}
  528.50 +
  528.51 +Byte CCipher::EncryptByte(Byte b)
  528.52 +{
  528.53 +  Byte c = (Byte)(b ^ DecryptByteSpec());
  528.54 +  UpdateKeys(b);
  528.55 +  return c;
  528.56 +}
  528.57 +
  528.58 +void CCipher::DecryptHeader(Byte *buf)
  528.59 +{
  528.60 +  for (unsigned i = 0; i < kHeaderSize; i++)
  528.61 +    buf[i] = DecryptByte(buf[i]);
  528.62 +}
  528.63 +
  528.64 +void CCipher::EncryptHeader(Byte *buf)
  528.65 +{
  528.66 +  for (unsigned i = 0; i < kHeaderSize; i++)
  528.67 +    buf[i] = EncryptByte(buf[i]);
  528.68 +}
  528.69 +
  528.70 +STDMETHODIMP CEncoder::CryptoSetPassword(const Byte *data, UInt32 size)
  528.71 +{
  528.72 +  _cipher.SetPassword(data, size);
  528.73 +  return S_OK;
  528.74 +}
  528.75 +
  528.76 +STDMETHODIMP CEncoder::CryptoSetCRC(UInt32 crc)
  528.77 +{
  528.78 +  _crc = crc;
  528.79 +  return S_OK;
  528.80 +}
  528.81 +
  528.82 +STDMETHODIMP CEncoder::Init()
  528.83 +{
  528.84 +  return S_OK;
  528.85 +}
  528.86 +
  528.87 +HRESULT CEncoder::WriteHeader(ISequentialOutStream *outStream)
  528.88 +{
  528.89 +  Byte header[kHeaderSize];
  528.90 +  g_RandomGenerator.Generate(header, kHeaderSize - 2);
  528.91 +
  528.92 +  header[kHeaderSize - 1] = Byte(_crc >> 24);
  528.93 +  header[kHeaderSize - 2] = Byte(_crc >> 16);
  528.94 +
  528.95 +  _cipher.EncryptHeader(header);
  528.96 +  return WriteStream(outStream, header, kHeaderSize);
  528.97 +}
  528.98 +
  528.99 +STDMETHODIMP_(UInt32) CEncoder::Filter(Byte *data, UInt32 size)
 528.100 +{
 528.101 +  UInt32 i;
 528.102 +  for (i = 0; i < size; i++)
 528.103 +    data[i] = _cipher.EncryptByte(data[i]);
 528.104 +  return i;
 528.105 +}
 528.106 +
 528.107 +STDMETHODIMP CDecoder::CryptoSetPassword(const Byte *data, UInt32 size)
 528.108 +{
 528.109 +  _cipher.SetPassword(data, size);
 528.110 +  return S_OK;
 528.111 +}
 528.112 +
 528.113 +HRESULT CDecoder::ReadHeader(ISequentialInStream *inStream)
 528.114 +{
 528.115 +  Byte header[kHeaderSize];
 528.116 +  RINOK(ReadStream_FAIL(inStream, header, kHeaderSize));
 528.117 +  _cipher.DecryptHeader(header);
 528.118 +  return S_OK;
 528.119 +}
 528.120 +
 528.121 +STDMETHODIMP CDecoder::Init()
 528.122 +{
 528.123 +  return S_OK;
 528.124 +}
 528.125 +
 528.126 +STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size)
 528.127 +{
 528.128 +  UInt32 i;
 528.129 +  for (i = 0; i < size; i++)
 528.130 +    data[i] = _cipher.DecryptByte(data[i]);
 528.131 +  return i;
 528.132 +}
 528.133 +
 528.134 +}}
   529.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   529.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/ZipCrypto.h	Sat Mar 03 10:31:27 2012 -0600
   529.3 @@ -0,0 +1,71 @@
   529.4 +// Crypto/ZipCrypto.h
   529.5 +
   529.6 +#ifndef __CRYPTO_ZIP_CRYPTO_H
   529.7 +#define __CRYPTO_ZIP_CRYPTO_H
   529.8 +
   529.9 +#include "Common/MyCom.h"
  529.10 +
  529.11 +#include "../ICoder.h"
  529.12 +#include "../IPassword.h"
  529.13 +
  529.14 +namespace NCrypto {
  529.15 +namespace NZip {
  529.16 +
  529.17 +const unsigned kHeaderSize = 12;
  529.18 +
  529.19 +class CCipher
  529.20 +{
  529.21 +  UInt32 Keys[3];
  529.22 +
  529.23 +  void UpdateKeys(Byte b);
  529.24 +  Byte DecryptByteSpec();
  529.25 +public:
  529.26 +  void SetPassword(const Byte *password, UInt32 passwordLen);
  529.27 +  Byte DecryptByte(Byte b);
  529.28 +  Byte EncryptByte(Byte b);
  529.29 +  void DecryptHeader(Byte *buf);
  529.30 +  void EncryptHeader(Byte *buf);
  529.31 +};
  529.32 +
  529.33 +class CEncoder :
  529.34 +  public ICompressFilter,
  529.35 +  public ICryptoSetPassword,
  529.36 +  public ICryptoSetCRC,
  529.37 +  public CMyUnknownImp
  529.38 +{
  529.39 +  CCipher _cipher;
  529.40 +  UInt32 _crc;
  529.41 +public:
  529.42 +  MY_UNKNOWN_IMP2(
  529.43 +      ICryptoSetPassword,
  529.44 +      ICryptoSetCRC
  529.45 +  )
  529.46 +  STDMETHOD(Init)();
  529.47 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
  529.48 +
  529.49 +  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
  529.50 +  STDMETHOD(CryptoSetCRC)(UInt32 crc);
  529.51 +  HRESULT WriteHeader(ISequentialOutStream *outStream);
  529.52 +};
  529.53 +
  529.54 +
  529.55 +class CDecoder:
  529.56 +  public ICompressFilter,
  529.57 +  public ICryptoSetPassword,
  529.58 +  public CMyUnknownImp
  529.59 +{
  529.60 +  CCipher _cipher;
  529.61 +public:
  529.62 +  MY_UNKNOWN_IMP1(ICryptoSetPassword)
  529.63 +
  529.64 +  STDMETHOD(Init)();
  529.65 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
  529.66 +  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
  529.67 +
  529.68 +  HRESULT ReadHeader(ISequentialInStream *inStream);
  529.69 +};
  529.70 +
  529.71 +
  529.72 +}}
  529.73 +
  529.74 +#endif
   530.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   530.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/ZipStrong.cpp	Sat Mar 03 10:31:27 2012 -0600
   530.3 @@ -0,0 +1,180 @@
   530.4 +// Crypto/ZipStrong.cpp
   530.5 +
   530.6 +#include "StdAfx.h"
   530.7 +
   530.8 +extern "C"
   530.9 +{
  530.10 +#include "../../../C/7zCrc.h"
  530.11 +#include "../../../C/CpuArch.h"
  530.12 +}
  530.13 +
  530.14 +#include "../Common/StreamUtils.h"
  530.15 +
  530.16 +#include "MyAES.h"
  530.17 +#include "Sha1.h"
  530.18 +#include "ZipStrong.h"
  530.19 +
  530.20 +namespace NCrypto {
  530.21 +namespace NZipStrong {
  530.22 +
  530.23 +static const UInt16 kAES128 = 0x660E;
  530.24 +
  530.25 +// DeriveKey* function is similar to CryptDeriveKey() from Windows.
  530.26 +// But MSDN tells that we need such scheme only if
  530.27 +// "the required key length is longer than the hash value"
  530.28 +// but ZipStrong uses it always.
  530.29 +
  530.30 +static void DeriveKey2(const Byte *digest, Byte c, Byte *dest)
  530.31 +{
  530.32 +  Byte buf[64];
  530.33 +  memset(buf, c, 64);
  530.34 +  for (unsigned i = 0; i < NSha1::kDigestSize; i++)
  530.35 +    buf[i] ^= digest[i];
  530.36 +  NSha1::CContext sha;
  530.37 +  sha.Init();
  530.38 +  sha.Update(buf, 64);
  530.39 +  sha.Final(dest);
  530.40 +}
  530.41 + 
  530.42 +static void DeriveKey(NSha1::CContext &sha, Byte *key)
  530.43 +{
  530.44 +  Byte digest[NSha1::kDigestSize];
  530.45 +  sha.Final(digest);
  530.46 +  Byte temp[NSha1::kDigestSize * 2];
  530.47 +  DeriveKey2(digest, 0x36, temp);
  530.48 +  DeriveKey2(digest, 0x5C, temp + NSha1::kDigestSize);
  530.49 +  memcpy(key, temp, 32);
  530.50 +}
  530.51 +
  530.52 +void CKeyInfo::SetPassword(const Byte *data, UInt32 size)
  530.53 +{
  530.54 +  NSha1::CContext sha;
  530.55 +  sha.Init();
  530.56 +  sha.Update(data, size);
  530.57 +  DeriveKey(sha, MasterKey);
  530.58 +}
  530.59 +
  530.60 +STDMETHODIMP CBaseCoder::CryptoSetPassword(const Byte *data, UInt32 size)
  530.61 +{
  530.62 +  _key.SetPassword(data, size);
  530.63 +  return S_OK;
  530.64 +}
  530.65 +
  530.66 +STDMETHODIMP CBaseCoder::Init()
  530.67 +{
  530.68 +  return S_OK;
  530.69 +}
  530.70 +
  530.71 +HRESULT CDecoder::ReadHeader(ISequentialInStream *inStream, UInt32 /* crc */, UInt64 /* unpackSize */)
  530.72 +{
  530.73 +  Byte temp[4];
  530.74 +  RINOK(ReadStream_FALSE(inStream, temp, 2));
  530.75 +  _ivSize = GetUi16(temp);
  530.76 +  if (_ivSize == 0)
  530.77 +  {
  530.78 +    return E_NOTIMPL;
  530.79 +    /*
  530.80 +    SetUi32(_iv, crc);
  530.81 +    for (int i = 0; i < 8; i++)
  530.82 +     _iv[4 + i] = (Byte)(unpackSize >> (8 * i));
  530.83 +    SetUi32(_iv + 12, 0);
  530.84 +    */
  530.85 +  }
  530.86 +  else if (_ivSize == 16)
  530.87 +  {
  530.88 +    RINOK(ReadStream_FALSE(inStream, _iv, _ivSize));
  530.89 +  }
  530.90 +  else
  530.91 +    return E_NOTIMPL;
  530.92 +  RINOK(ReadStream_FALSE(inStream, temp, 4));
  530.93 +  _remSize = GetUi32(temp);
  530.94 +  if (_remSize > _buf.GetCapacity())
  530.95 +  {
  530.96 +    _buf.Free();
  530.97 +    _buf.SetCapacity(_remSize);
  530.98 +  }
  530.99 +  return ReadStream_FALSE(inStream, _buf, _remSize);
 530.100 +}
 530.101 +
 530.102 +HRESULT CDecoder::CheckPassword(bool &passwOK)
 530.103 +{
 530.104 +  passwOK = false;
 530.105 +  if (_remSize < 10)
 530.106 +    return E_NOTIMPL;
 530.107 +  Byte *p = _buf;
 530.108 +  UInt16 format = GetUi16(p);
 530.109 +  if (format != 3)
 530.110 +    return E_NOTIMPL;
 530.111 +  UInt16 algId  = GetUi16(p + 2);
 530.112 +  if (algId < kAES128)
 530.113 +    return E_NOTIMPL;
 530.114 +  algId -= kAES128;
 530.115 +  if (algId > 2)
 530.116 +    return E_NOTIMPL;
 530.117 +  UInt16 bitLen = GetUi16(p + 4);
 530.118 +  UInt16 flags  = GetUi16(p + 6);
 530.119 +  if (algId * 64 + 128 != bitLen)
 530.120 +    return E_NOTIMPL;
 530.121 +  _key.KeySize = 16 + algId * 8;
 530.122 +  if ((flags & 1) == 0)
 530.123 +    return E_NOTIMPL;
 530.124 +  UInt32 rdSize = GetUi16(p + 8);
 530.125 +  UInt32 pos = 10;
 530.126 +  Byte *rd = p + pos;
 530.127 +  pos += rdSize;
 530.128 +  if (pos + 4 > _remSize)
 530.129 +    return E_NOTIMPL;
 530.130 +  UInt32 reserved = GetUi32(p + pos);
 530.131 +  pos += 4;
 530.132 +  if (reserved != 0)
 530.133 +    return E_NOTIMPL;
 530.134 +  if (pos + 2 > _remSize)
 530.135 +    return E_NOTIMPL;
 530.136 +  UInt32 validSize = GetUi16(p + pos);
 530.137 +  pos += 2;
 530.138 +  Byte *validData = p + pos;
 530.139 +  if (pos + validSize != _remSize)
 530.140 +    return E_NOTIMPL;
 530.141 +
 530.142 +  if (!_aesFilter)
 530.143 +    _aesFilter = new CAesCbcDecoder;
 530.144 +
 530.145 +  CMyComPtr<ICryptoProperties> cp;
 530.146 +  RINOK(_aesFilter.QueryInterface(IID_ICryptoProperties, &cp));
 530.147 +  {
 530.148 +    RINOK(cp->SetKey(_key.MasterKey, _key.KeySize));
 530.149 +    RINOK(cp->SetInitVector(_iv, 16));
 530.150 +    _aesFilter->Init();
 530.151 +    if (_aesFilter->Filter(rd, rdSize) != rdSize)
 530.152 +      return E_NOTIMPL;
 530.153 +  }
 530.154 +
 530.155 +  Byte fileKey[32];
 530.156 +  NSha1::CContext sha;
 530.157 +  sha.Init();
 530.158 +  sha.Update(_iv, 16);
 530.159 +  sha.Update(rd, rdSize - 16); // we don't use last 16 bytes (PAD bytes)
 530.160 +  DeriveKey(sha, fileKey);
 530.161 +  
 530.162 +  RINOK(cp->SetKey(fileKey, _key.KeySize));
 530.163 +  RINOK(cp->SetInitVector(_iv, 16));
 530.164 +  _aesFilter->Init();
 530.165 +  if (_aesFilter->Filter(validData, validSize) != validSize)
 530.166 +    return E_NOTIMPL;
 530.167 +
 530.168 +  if (validSize < 4)
 530.169 +    return E_NOTIMPL;
 530.170 +  validSize -= 4;
 530.171 +  if (GetUi32(validData + validSize) != CrcCalc(validData, validSize))
 530.172 +    return S_OK;
 530.173 +  passwOK = true;
 530.174 +  _aesFilter->Init();
 530.175 +  return S_OK;
 530.176 +}
 530.177 +
 530.178 +STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size)
 530.179 +{
 530.180 +  return _aesFilter->Filter(data, size);
 530.181 +}
 530.182 +
 530.183 +}}
   531.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   531.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/ZipStrong.h	Sat Mar 03 10:31:27 2012 -0600
   531.3 @@ -0,0 +1,53 @@
   531.4 +// Crypto/ZipStrong.h
   531.5 +
   531.6 +#ifndef __CRYPTO_ZIP_STRONG_H
   531.7 +#define __CRYPTO_ZIP_STRONG_H
   531.8 +
   531.9 +#include "Common/MyCom.h"
  531.10 +#include "Common/Buffer.h"
  531.11 +
  531.12 +#include "../ICoder.h"
  531.13 +#include "../IPassword.h"
  531.14 +
  531.15 +namespace NCrypto {
  531.16 +namespace NZipStrong {
  531.17 +
  531.18 +struct CKeyInfo
  531.19 +{
  531.20 +  Byte MasterKey[32];
  531.21 +  UInt32 KeySize;
  531.22 +  void SetPassword(const Byte *data, UInt32 size);
  531.23 +};
  531.24 +
  531.25 +class CBaseCoder:
  531.26 +  public ICompressFilter,
  531.27 +  public ICryptoSetPassword,
  531.28 +  public CMyUnknownImp
  531.29 +{
  531.30 +protected:
  531.31 +  CKeyInfo _key;
  531.32 +  CMyComPtr<ICompressFilter> _aesFilter;
  531.33 +  CByteBuffer _buf;
  531.34 +public:
  531.35 +  STDMETHOD(Init)();
  531.36 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) = 0;
  531.37 +  
  531.38 +  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
  531.39 +};
  531.40 +
  531.41 +class CDecoder:
  531.42 +  public CBaseCoder
  531.43 +{
  531.44 +  UInt32 _ivSize;
  531.45 +  Byte _iv[16];
  531.46 +  UInt32 _remSize;
  531.47 +public:
  531.48 +  MY_UNKNOWN_IMP1(ICryptoSetPassword)
  531.49 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
  531.50 +  HRESULT ReadHeader(ISequentialInStream *inStream, UInt32 crc, UInt64 unpackSize);
  531.51 +  HRESULT CheckPassword(bool &passwOK);
  531.52 +};
  531.53 +
  531.54 +}}
  531.55 +
  531.56 +#endif
   532.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   532.2 +++ b/src/win32/7zip/7z/CPP/7zip/ICoder.h	Sat Mar 03 10:31:27 2012 -0600
   532.3 @@ -0,0 +1,186 @@
   532.4 +// ICoder.h
   532.5 +
   532.6 +#ifndef __ICODER_H
   532.7 +#define __ICODER_H
   532.8 +
   532.9 +#include "IStream.h"
  532.10 +
  532.11 +#define CODER_INTERFACE(i, x) DECL_INTERFACE(i, 4, x)
  532.12 +
  532.13 +CODER_INTERFACE(ICompressProgressInfo, 0x04)
  532.14 +{
  532.15 +  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;
  532.16 +};
  532.17 +
  532.18 +CODER_INTERFACE(ICompressCoder, 0x05)
  532.19 +{
  532.20 +  STDMETHOD(Code)(ISequentialInStream *inStream,
  532.21 +      ISequentialOutStream *outStream,
  532.22 +      const UInt64 *inSize,
  532.23 +      const UInt64 *outSize,
  532.24 +      ICompressProgressInfo *progress) PURE;
  532.25 +};
  532.26 +
  532.27 +CODER_INTERFACE(ICompressCoder2, 0x18)
  532.28 +{
  532.29 +  STDMETHOD(Code)(ISequentialInStream **inStreams,
  532.30 +      const UInt64 **inSizes,
  532.31 +      UInt32 numInStreams,
  532.32 +      ISequentialOutStream **outStreams,
  532.33 +      const UInt64 **outSizes,
  532.34 +      UInt32 numOutStreams,
  532.35 +      ICompressProgressInfo *progress) PURE;
  532.36 +};
  532.37 +
  532.38 +namespace NCoderPropID
  532.39 +{
  532.40 +  enum EEnum
  532.41 +  {
  532.42 +    kDictionarySize = 0x400,
  532.43 +    kUsedMemorySize,
  532.44 +    kOrder,
  532.45 +    kBlockSize,
  532.46 +    kPosStateBits = 0x440,
  532.47 +    kLitContextBits,
  532.48 +    kLitPosBits,
  532.49 +    kNumFastBytes = 0x450,
  532.50 +    kMatchFinder,
  532.51 +    kMatchFinderCycles,
  532.52 +    kNumPasses = 0x460,
  532.53 +    kAlgorithm = 0x470,
  532.54 +    kMultiThread = 0x480,
  532.55 +    kNumThreads,
  532.56 +    kEndMarker = 0x490
  532.57 +  };
  532.58 +}
  532.59 +
  532.60 +CODER_INTERFACE(ICompressSetCoderProperties, 0x20)
  532.61 +{
  532.62 +  STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
  532.63 +      const PROPVARIANT *properties, UInt32 numProperties) PURE;
  532.64 +};
  532.65 +
  532.66 +/*
  532.67 +CODER_INTERFACE(ICompressSetCoderProperties, 0x21)
  532.68 +{
  532.69 +  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;
  532.70 +};
  532.71 +*/
  532.72 +
  532.73 +CODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)
  532.74 +{
  532.75 +  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;
  532.76 +};
  532.77 +
  532.78 +CODER_INTERFACE(ICompressWriteCoderProperties, 0x23)
  532.79 +{
  532.80 +  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;
  532.81 +};
  532.82 +
  532.83 +CODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)
  532.84 +{
  532.85 +  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;
  532.86 +};
  532.87 +
  532.88 +CODER_INTERFACE(ICompressSetCoderMt, 0x25)
  532.89 +{
  532.90 +  STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE;
  532.91 +};
  532.92 +
  532.93 +CODER_INTERFACE(ICompressGetSubStreamSize, 0x30)
  532.94 +{
  532.95 +  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;
  532.96 +};
  532.97 +
  532.98 +CODER_INTERFACE(ICompressSetInStream, 0x31)
  532.99 +{
 532.100 +  STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;
 532.101 +  STDMETHOD(ReleaseInStream)() PURE;
 532.102 +};
 532.103 +
 532.104 +CODER_INTERFACE(ICompressSetOutStream, 0x32)
 532.105 +{
 532.106 +  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;
 532.107 +  STDMETHOD(ReleaseOutStream)() PURE;
 532.108 +};
 532.109 +
 532.110 +CODER_INTERFACE(ICompressSetInStreamSize, 0x33)
 532.111 +{
 532.112 +  STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;
 532.113 +};
 532.114 +
 532.115 +CODER_INTERFACE(ICompressSetOutStreamSize, 0x34)
 532.116 +{
 532.117 +  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;
 532.118 +};
 532.119 +
 532.120 +CODER_INTERFACE(ICompressFilter, 0x40)
 532.121 +{
 532.122 +  STDMETHOD(Init)() PURE;
 532.123 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;
 532.124 +  // Filter return outSize (UInt32)
 532.125 +  // if (outSize <= size): Filter have converted outSize bytes
 532.126 +  // if (outSize > size): Filter have not converted anything.
 532.127 +  //      and it needs at least outSize bytes to convert one block
 532.128 +  //      (it's for crypto block algorithms).
 532.129 +};
 532.130 +
 532.131 +CODER_INTERFACE(ICompressCodecsInfo, 0x60)
 532.132 +{
 532.133 +  STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods) PURE;
 532.134 +  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) PURE;
 532.135 +  STDMETHOD(CreateDecoder)(UInt32 index, const GUID *iid, void **coder) PURE;
 532.136 +  STDMETHOD(CreateEncoder)(UInt32 index, const GUID *iid, void **coder) PURE;
 532.137 +};
 532.138 +CODER_INTERFACE(ISetCompressCodecsInfo, 0x61)
 532.139 +{
 532.140 +  STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo) PURE;
 532.141 +};
 532.142 +
 532.143 +CODER_INTERFACE(ICryptoProperties, 0x80)
 532.144 +{
 532.145 +  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;
 532.146 +  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;
 532.147 +};
 532.148 +
 532.149 +/*
 532.150 +CODER_INTERFACE(ICryptoResetSalt, 0x88)
 532.151 +{
 532.152 +  STDMETHOD(ResetSalt)() PURE;
 532.153 +};
 532.154 +*/
 532.155 +
 532.156 +CODER_INTERFACE(ICryptoResetInitVector, 0x8C)
 532.157 +{
 532.158 +  STDMETHOD(ResetInitVector)() PURE;
 532.159 +};
 532.160 +
 532.161 +CODER_INTERFACE(ICryptoSetPassword, 0x90)
 532.162 +{
 532.163 +  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;
 532.164 +};
 532.165 +
 532.166 +CODER_INTERFACE(ICryptoSetCRC, 0xA0)
 532.167 +{
 532.168 +  STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;
 532.169 +};
 532.170 +
 532.171 +//////////////////////
 532.172 +// It's for DLL file
 532.173 +namespace NMethodPropID
 532.174 +{
 532.175 +  enum EEnum
 532.176 +  {
 532.177 +    kID,
 532.178 +    kName,
 532.179 +    kDecoder,
 532.180 +    kEncoder,
 532.181 +    kInStreams,
 532.182 +    kOutStreams,
 532.183 +    kDescription,
 532.184 +    kDecoderIsAssigned,
 532.185 +    kEncoderIsAssigned
 532.186 +  };
 532.187 +}
 532.188 +
 532.189 +#endif
   533.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   533.2 +++ b/src/win32/7zip/7z/CPP/7zip/IDecl.h	Sat Mar 03 10:31:27 2012 -0600
   533.3 @@ -0,0 +1,15 @@
   533.4 +// IDecl.h
   533.5 +
   533.6 +#ifndef __IDECL_H
   533.7 +#define __IDECL_H
   533.8 +
   533.9 +#include "../Common/MyUnknown.h"
  533.10 +
  533.11 +#define DECL_INTERFACE_SUB(i, base, groupId, subId) \
  533.12 +DEFINE_GUID(IID_ ## i, \
  533.13 +0x23170F69, 0x40C1, 0x278A, 0, 0, 0, (groupId), 0, (subId), 0, 0); \
  533.14 +struct i: public base
  533.15 +
  533.16 +#define DECL_INTERFACE(i, groupId, subId) DECL_INTERFACE_SUB(i, IUnknown, groupId, subId)
  533.17 +
  533.18 +#endif
   534.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   534.2 +++ b/src/win32/7zip/7z/CPP/7zip/IPassword.h	Sat Mar 03 10:31:27 2012 -0600
   534.3 @@ -0,0 +1,24 @@
   534.4 +// IPassword.h
   534.5 +
   534.6 +#ifndef __IPASSWORD_H
   534.7 +#define __IPASSWORD_H
   534.8 +
   534.9 +#include "../Common/MyUnknown.h"
  534.10 +#include "../Common/Types.h"
  534.11 +
  534.12 +#include "IDecl.h"
  534.13 +
  534.14 +#define PASSWORD_INTERFACE(i, x) DECL_INTERFACE(i, 5, x)
  534.15 +
  534.16 +PASSWORD_INTERFACE(ICryptoGetTextPassword, 0x10)
  534.17 +{
  534.18 +  STDMETHOD(CryptoGetTextPassword)(BSTR *password) PURE;
  534.19 +};
  534.20 +
  534.21 +PASSWORD_INTERFACE(ICryptoGetTextPassword2, 0x11)
  534.22 +{
  534.23 +  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password) PURE;
  534.24 +};
  534.25 +
  534.26 +#endif
  534.27 +
   535.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   535.2 +++ b/src/win32/7zip/7z/CPP/7zip/IProgress.h	Sat Mar 03 10:31:27 2012 -0600
   535.3 @@ -0,0 +1,33 @@
   535.4 +// Interface/IProgress.h
   535.5 +
   535.6 +#ifndef __IPROGRESS_H
   535.7 +#define __IPROGRESS_H
   535.8 +
   535.9 +#include "../Common/MyUnknown.h"
  535.10 +#include "../Common/Types.h"
  535.11 +
  535.12 +#include "IDecl.h"
  535.13 +
  535.14 +#define INTERFACE_IProgress(x) \
  535.15 +  STDMETHOD(SetTotal)(UInt64 total) x; \
  535.16 +  STDMETHOD(SetCompleted)(const UInt64 *completeValue) x; \
  535.17 +
  535.18 +DECL_INTERFACE(IProgress, 0, 5)
  535.19 +{
  535.20 +  INTERFACE_IProgress(PURE)
  535.21 +};
  535.22 +
  535.23 +/*
  535.24 +// {23170F69-40C1-278A-0000-000000050002}
  535.25 +DEFINE_GUID(IID_IProgress2,
  535.26 +0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x02);
  535.27 +MIDL_INTERFACE("23170F69-40C1-278A-0000-000000050002")
  535.28 +IProgress2: public IUnknown
  535.29 +{
  535.30 +public:
  535.31 +  STDMETHOD(SetTotal)(const UInt64 *total) PURE;
  535.32 +  STDMETHOD(SetCompleted)(const UInt64 *completeValue) PURE;
  535.33 +};
  535.34 +*/
  535.35 +
  535.36 +#endif
   536.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   536.2 +++ b/src/win32/7zip/7z/CPP/7zip/IStream.h	Sat Mar 03 10:31:27 2012 -0600
   536.3 @@ -0,0 +1,58 @@
   536.4 +// IStream.h
   536.5 +
   536.6 +#ifndef __ISTREAM_H
   536.7 +#define __ISTREAM_H
   536.8 +
   536.9 +#include "../Common/MyUnknown.h"
  536.10 +#include "../Common/Types.h"
  536.11 +
  536.12 +#include "IDecl.h"
  536.13 +
  536.14 +#define STREAM_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 3, x)
  536.15 +#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)
  536.16 +
  536.17 +STREAM_INTERFACE(ISequentialInStream, 0x01)
  536.18 +{
  536.19 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;
  536.20 +  /*
  536.21 +  Out: if size != 0, return_value = S_OK and (*processedSize == 0),
  536.22 +    then there are no more bytes in stream.
  536.23 +  if (size > 0) && there are bytes in stream,
  536.24 +  this function must read at least 1 byte.
  536.25 +  This function is allowed to read less than number of remaining bytes in stream.
  536.26 +  You must call Read function in loop, if you need exact amount of data
  536.27 +  */
  536.28 +};
  536.29 +
  536.30 +STREAM_INTERFACE(ISequentialOutStream, 0x02)
  536.31 +{
  536.32 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;
  536.33 +  /*
  536.34 +  if (size > 0) this function must write at least 1 byte.
  536.35 +  This function is allowed to write less than "size".
  536.36 +  You must call Write function in loop, if you need to write exact amount of data
  536.37 +  */
  536.38 +};
  536.39 +
  536.40 +STREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)
  536.41 +{
  536.42 +  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;
  536.43 +};
  536.44 +
  536.45 +STREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)
  536.46 +{
  536.47 +  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;
  536.48 +  STDMETHOD(SetSize)(Int64 newSize) PURE;
  536.49 +};
  536.50 +
  536.51 +STREAM_INTERFACE(IStreamGetSize, 0x06)
  536.52 +{
  536.53 +  STDMETHOD(GetSize)(UInt64 *size) PURE;
  536.54 +};
  536.55 +
  536.56 +STREAM_INTERFACE(IOutStreamFlush, 0x07)
  536.57 +{
  536.58 +  STDMETHOD(Flush)() PURE;
  536.59 +};
  536.60 +
  536.61 +#endif
   537.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   537.2 +++ b/src/win32/7zip/7z/CPP/7zip/PropID.h	Sat Mar 03 10:31:27 2012 -0600
   537.3 @@ -0,0 +1,69 @@
   537.4 +// PropID.h
   537.5 +
   537.6 +#ifndef __7ZIP_PROPID_H
   537.7 +#define __7ZIP_PROPID_H
   537.8 +
   537.9 +enum
  537.10 +{
  537.11 +  kpidNoProperty = 0,
  537.12 +  
  537.13 +  kpidHandlerItemIndex = 2,
  537.14 +  kpidPath,
  537.15 +  kpidName,
  537.16 +  kpidExtension,
  537.17 +  kpidIsDir,
  537.18 +  kpidSize,
  537.19 +  kpidPackSize,
  537.20 +  kpidAttrib,
  537.21 +  kpidCTime,
  537.22 +  kpidATime,
  537.23 +  kpidMTime,
  537.24 +  kpidSolid,
  537.25 +  kpidCommented,
  537.26 +  kpidEncrypted,
  537.27 +  kpidSplitBefore,
  537.28 +  kpidSplitAfter,
  537.29 +  kpidDictionarySize,
  537.30 +  kpidCRC,
  537.31 +  kpidType,
  537.32 +  kpidIsAnti,
  537.33 +  kpidMethod,
  537.34 +  kpidHostOS,
  537.35 +  kpidFileSystem,
  537.36 +  kpidUser,
  537.37 +  kpidGroup,
  537.38 +  kpidBlock,
  537.39 +  kpidComment,
  537.40 +  kpidPosition,
  537.41 +  kpidPrefix,
  537.42 +  kpidNumSubDirs,
  537.43 +  kpidNumSubFiles,
  537.44 +  kpidUnpackVer,
  537.45 +  kpidVolume,
  537.46 +  kpidIsVolume,
  537.47 +  kpidOffset,
  537.48 +  kpidLinks,
  537.49 +  kpidNumBlocks,
  537.50 +  kpidNumVolumes,
  537.51 +  kpidTimeType,
  537.52 +  kpidBit64,
  537.53 +  kpidBigEndian,
  537.54 +  kpidCpu,
  537.55 +  kpidPhySize,
  537.56 +  kpidHeadersSize,
  537.57 +  kpidChecksum,
  537.58 +  kpidCharacts,
  537.59 +  kpidVa,
  537.60 +
  537.61 +  kpidTotalSize = 0x1100,
  537.62 +  kpidFreeSpace,
  537.63 +  kpidClusterSize,
  537.64 +  kpidVolumeName,
  537.65 +
  537.66 +  kpidLocalName = 0x1200,
  537.67 +  kpidProvider,
  537.68 +
  537.69 +  kpidUserDefined = 0x10000
  537.70 +};
  537.71 +
  537.72 +#endif
   538.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   538.2 +++ b/src/win32/7zip/7z/CPP/Common/Buffer.h	Sat Mar 03 10:31:27 2012 -0600
   538.3 @@ -0,0 +1,77 @@
   538.4 +// Common/Buffer.h
   538.5 +
   538.6 +#ifndef __COMMON_BUFFER_H
   538.7 +#define __COMMON_BUFFER_H
   538.8 +
   538.9 +#include "Defs.h"
  538.10 +
  538.11 +template <class T> class CBuffer
  538.12 +{
  538.13 +protected:
  538.14 +  size_t _capacity;
  538.15 +  T *_items;
  538.16 +public:
  538.17 +  void Free()
  538.18 +  {
  538.19 +    delete []_items;
  538.20 +    _items = 0;
  538.21 +    _capacity = 0;
  538.22 +  }
  538.23 +  CBuffer(): _capacity(0), _items(0) {};
  538.24 +  CBuffer(const CBuffer &buffer): _capacity(0), _items(0) { *this = buffer; }
  538.25 +  CBuffer(size_t size): _items(0),  _capacity(0) {  SetCapacity(size); }
  538.26 +  virtual ~CBuffer() { delete []_items; }
  538.27 +  operator T *() { return _items; };
  538.28 +  operator const T *() const { return _items; };
  538.29 +  size_t GetCapacity() const { return  _capacity; }
  538.30 +  void SetCapacity(size_t newCapacity)
  538.31 +  {
  538.32 +    if (newCapacity == _capacity)
  538.33 +      return;
  538.34 +    T *newBuffer;
  538.35 +    if (newCapacity > 0)
  538.36 +    {
  538.37 +      newBuffer = new T[newCapacity];
  538.38 +      if (_capacity > 0)
  538.39 +        memmove(newBuffer, _items, MyMin(_capacity, newCapacity) * sizeof(T));
  538.40 +    }
  538.41 +    else
  538.42 +      newBuffer = 0;
  538.43 +    delete []_items;
  538.44 +    _items = newBuffer;
  538.45 +    _capacity = newCapacity;
  538.46 +  }
  538.47 +  CBuffer& operator=(const CBuffer &buffer)
  538.48 +  {
  538.49 +    Free();
  538.50 +    if (buffer._capacity > 0)
  538.51 +    {
  538.52 +      SetCapacity(buffer._capacity);
  538.53 +      memmove(_items, buffer._items, buffer._capacity * sizeof(T));
  538.54 +    }
  538.55 +    return *this;
  538.56 +  }
  538.57 +};
  538.58 +
  538.59 +template <class T>
  538.60 +bool operator==(const CBuffer<T>& b1, const CBuffer<T>& b2)
  538.61 +{
  538.62 +  if (b1.GetCapacity() != b2.GetCapacity())
  538.63 +    return false;
  538.64 +  for (size_t i = 0; i < b1.GetCapacity(); i++)
  538.65 +    if (b1[i] != b2[i])
  538.66 +      return false;
  538.67 +  return true;
  538.68 +}
  538.69 +
  538.70 +template <class T>
  538.71 +bool operator!=(const CBuffer<T>& b1, const CBuffer<T>& b2)
  538.72 +{
  538.73 +  return !(b1 == b2);
  538.74 +}
  538.75 +
  538.76 +typedef CBuffer<char> CCharBuffer;
  538.77 +typedef CBuffer<wchar_t> CWCharBuffer;
  538.78 +typedef CBuffer<unsigned char> CByteBuffer;
  538.79 +
  538.80 +#endif
   539.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   539.2 +++ b/src/win32/7zip/7z/CPP/Common/CRC.cpp	Sat Mar 03 10:31:27 2012 -0600
   539.3 @@ -0,0 +1,10 @@
   539.4 +// Common/CRC.cpp
   539.5 +
   539.6 +#include "StdAfx.h"
   539.7 +
   539.8 +extern "C"
   539.9 +{
  539.10 +#include "../../C/7zCrc.h"
  539.11 +}
  539.12 +
  539.13 +struct CCRCTableInit { CCRCTableInit() { CrcGenerateTable(); } } g_CRCTableInit;
   540.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   540.2 +++ b/src/win32/7zip/7z/CPP/Common/ComTry.h	Sat Mar 03 10:31:27 2012 -0600
   540.3 @@ -0,0 +1,17 @@
   540.4 +// ComTry.h
   540.5 +
   540.6 +#ifndef __COM_TRY_H
   540.7 +#define __COM_TRY_H
   540.8 +
   540.9 +#include "MyWindows.h"
  540.10 +// #include "Exception.h"
  540.11 +// #include "NewHandler.h"
  540.12 +
  540.13 +#define COM_TRY_BEGIN try {
  540.14 +#define COM_TRY_END } catch(...) { return E_OUTOFMEMORY; }
  540.15 +  
  540.16 +  // catch(const CNewException &) { return E_OUTOFMEMORY; }\
  540.17 +  // catch(const CSystemException &e) { return e.ErrorCode; }\
  540.18 +  // catch(...) { return E_FAIL; }
  540.19 +
  540.20 +#endif
   541.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   541.2 +++ b/src/win32/7zip/7z/CPP/Common/Defs.h	Sat Mar 03 10:31:27 2012 -0600
   541.3 @@ -0,0 +1,20 @@
   541.4 +// Common/Defs.h
   541.5 +
   541.6 +#ifndef __COMMON_DEFS_H
   541.7 +#define __COMMON_DEFS_H
   541.8 +
   541.9 +template <class T> inline T MyMin(T a, T b)
  541.10 +  {  return a < b ? a : b; }
  541.11 +template <class T> inline T MyMax(T a, T b)
  541.12 +  {  return a > b ? a : b; }
  541.13 +
  541.14 +template <class T> inline int MyCompare(T a, T b)
  541.15 +  {  return a < b ? -1 : (a == b ? 0 : 1); }
  541.16 +
  541.17 +inline int BoolToInt(bool value)
  541.18 +  { return (value ? 1: 0); }
  541.19 +
  541.20 +inline bool IntToBool(int value)
  541.21 +  { return (value != 0); }
  541.22 +
  541.23 +#endif
   542.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   542.2 +++ b/src/win32/7zip/7z/CPP/Common/DynamicBuffer.h	Sat Mar 03 10:31:27 2012 -0600
   542.3 @@ -0,0 +1,47 @@
   542.4 +// Common/DynamicBuffer.h
   542.5 +
   542.6 +#ifndef __COMMON_DYNAMICBUFFER_H
   542.7 +#define __COMMON_DYNAMICBUFFER_H
   542.8 +
   542.9 +#include "Buffer.h"
  542.10 +
  542.11 +template <class T> class CDynamicBuffer: public CBuffer<T>
  542.12 +{
  542.13 +  void GrowLength(size_t size)
  542.14 +  {
  542.15 +    size_t delta;
  542.16 +    if (this->_capacity > 64)
  542.17 +      delta = this->_capacity / 4;
  542.18 +    else if (this->_capacity > 8)
  542.19 +      delta = 16;
  542.20 +    else
  542.21 +      delta = 4;
  542.22 +    delta = MyMax(delta, size);
  542.23 +    SetCapacity(this->_capacity + delta);
  542.24 +  }
  542.25 +public:
  542.26 +  CDynamicBuffer(): CBuffer<T>() {};
  542.27 +  CDynamicBuffer(const CDynamicBuffer &buffer): CBuffer<T>(buffer) {};
  542.28 +  CDynamicBuffer(size_t size): CBuffer<T>(size) {};
  542.29 +  CDynamicBuffer& operator=(const CDynamicBuffer &buffer)
  542.30 +  {
  542.31 +    this->Free();
  542.32 +    if (buffer._capacity > 0)
  542.33 +    {
  542.34 +      SetCapacity(buffer._capacity);
  542.35 +      memmove(this->_items, buffer._items, buffer._capacity * sizeof(T));
  542.36 +    }
  542.37 +    return *this;
  542.38 +  }
  542.39 +  void EnsureCapacity(size_t capacity)
  542.40 +  {
  542.41 +    if (this->_capacity < capacity)
  542.42 +      GrowLength(capacity - this->_capacity);
  542.43 +  }
  542.44 +};
  542.45 +
  542.46 +typedef CDynamicBuffer<char> CCharDynamicBuffer;
  542.47 +typedef CDynamicBuffer<wchar_t> CWCharDynamicBuffer;
  542.48 +typedef CDynamicBuffer<unsigned char> CByteDynamicBuffer;
  542.49 +
  542.50 +#endif
   543.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   543.2 +++ b/src/win32/7zip/7z/CPP/Common/InitializeStaticLib.h	Sat Mar 03 10:31:27 2012 -0600
   543.3 @@ -0,0 +1,29 @@
   543.4 +// Common/InitializeStaticLib.h
   543.5 +//
   543.6 +// it's necessary to include this from one cpp file in order to use 7zip as a static library,
   543.7 +// otherwise the linker will optimize away some important internals of 7zip.
   543.8 +
   543.9 +#ifndef __COMMON_INITIALIZESTATICLIB_H
  543.10 +#define __COMMON_INITIALIZESTATICLIB_H
  543.11 +
  543.12 +#define FORCE_REF(dec, var) extern dec var; void* var##ref = (void*)&var;
  543.13 +
  543.14 +#include "../7zip/Common/DeclareCodecs.h"
  543.15 +#include "../7zip/Common/DeclareArcs.h"
  543.16 +
  543.17 +FORCE_REF(struct CCRCTableInit, g_CRCTableInit)
  543.18 +
  543.19 +
  543.20 +// these don't seem to be necessary with my compiler,
  543.21 +// but they're here in case a different compiler more aggressively strips out unreferenced code
  543.22 +FORCE_REF(class CBZip2CrcTableInit, g_BZip2CrcTableInit)
  543.23 +namespace NCrypto { struct CAesTabInit; FORCE_REF(CAesTabInit, g_AesTabInit) }
  543.24 +namespace NBitl { struct CInverterTableInitializer; FORCE_REF(CInverterTableInitializer, g_InverterTableInitializer) }
  543.25 +namespace NCompress { namespace NRar3 { class CDistInit; FORCE_REF(CDistInit, g_DistInit) }}
  543.26 +namespace NArchive { namespace NLzh { class CCRCTableInit; FORCE_REF(CCRCTableInit, g_CRCTableInit) }}
  543.27 +namespace NArchive { namespace N7z { class SignatureInitializer; FORCE_REF(SignatureInitializer, g_SignatureInitializer) }}
  543.28 +namespace NArchive{ namespace NRar{ namespace NHeader{ class CMarkerInitializer; FORCE_REF(CMarkerInitializer, g_MarkerInitializer) }}}
  543.29 +namespace NArchive { namespace NZip { namespace NSignature{ class CMarkersInitializer; FORCE_REF(CMarkersInitializer, g_MarkerInitializer) }}}
  543.30 +
  543.31 +
  543.32 +#endif
   544.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   544.2 +++ b/src/win32/7zip/7z/CPP/Common/IntToString.cpp	Sat Mar 03 10:31:27 2012 -0600
   544.3 @@ -0,0 +1,63 @@
   544.4 +// Common/IntToString.cpp
   544.5 +
   544.6 +#include "StdAfx.h"
   544.7 +
   544.8 +#include "IntToString.h"
   544.9 +
  544.10 +void ConvertUInt64ToString(UInt64 value, char *s, UInt32 base)
  544.11 +{
  544.12 +  if (base < 2 || base > 36)
  544.13 +  {
  544.14 +    *s = '\0';
  544.15 +    return;
  544.16 +  }
  544.17 +  char temp[72];
  544.18 +  int pos = 0;
  544.19 +  do
  544.20 +  {
  544.21 +    int delta = (int)(value % base);
  544.22 +    temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10)));
  544.23 +    value /= base;
  544.24 +  }
  544.25 +  while (value != 0);
  544.26 +  do
  544.27 +    *s++ = temp[--pos];
  544.28 +  while (pos > 0);
  544.29 +  *s = '\0';
  544.30 +}
  544.31 +
  544.32 +void ConvertUInt64ToString(UInt64 value, wchar_t *s)
  544.33 +{
  544.34 +  wchar_t temp[32];
  544.35 +  int pos = 0;
  544.36 +  do
  544.37 +  {
  544.38 +    temp[pos++] = (wchar_t)(L'0' + (int)(value % 10));
  544.39 +    value /= 10;
  544.40 +  }
  544.41 +  while (value != 0);
  544.42 +  do
  544.43 +    *s++ = temp[--pos];
  544.44 +  while (pos > 0);
  544.45 +  *s = L'\0';
  544.46 +}
  544.47 +
  544.48 +void ConvertInt64ToString(Int64 value, char *s)
  544.49 +{
  544.50 +  if (value < 0)
  544.51 +  {
  544.52 +    *s++ = '-';
  544.53 +    value = -value;
  544.54 +  }
  544.55 +  ConvertUInt64ToString(value, s);
  544.56 +}
  544.57 +
  544.58 +void ConvertInt64ToString(Int64 value, wchar_t *s)
  544.59 +{
  544.60 +  if (value < 0)
  544.61 +  {
  544.62 +    *s++ = L'-';
  544.63 +    value = -value;
  544.64 +  }
  544.65 +  ConvertUInt64ToString(value, s);
  544.66 +}
   545.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   545.2 +++ b/src/win32/7zip/7z/CPP/Common/IntToString.h	Sat Mar 03 10:31:27 2012 -0600
   545.3 @@ -0,0 +1,15 @@
   545.4 +// Common/IntToString.h
   545.5 +
   545.6 +#ifndef __COMMON_INTTOSTRING_H
   545.7 +#define __COMMON_INTTOSTRING_H
   545.8 +
   545.9 +#include <stddef.h>
  545.10 +#include "Types.h"
  545.11 +
  545.12 +void ConvertUInt64ToString(UInt64 value, char *s, UInt32 base = 10);
  545.13 +void ConvertUInt64ToString(UInt64 value, wchar_t *s);
  545.14 +
  545.15 +void ConvertInt64ToString(Int64 value, char *s);
  545.16 +void ConvertInt64ToString(Int64 value, wchar_t *s);
  545.17 +
  545.18 +#endif
   546.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   546.2 +++ b/src/win32/7zip/7z/CPP/Common/MyCom.h	Sat Mar 03 10:31:27 2012 -0600
   546.3 @@ -0,0 +1,225 @@
   546.4 +// MyCom.h
   546.5 +
   546.6 +#ifndef __MYCOM_H
   546.7 +#define __MYCOM_H
   546.8 +
   546.9 +#include "MyWindows.h"
  546.10 +
  546.11 +#ifndef RINOK
  546.12 +#define RINOK(x) { HRESULT __result_ = (x); if (__result_ != S_OK) return __result_; }
  546.13 +#endif
  546.14 +
  546.15 +template <class T>
  546.16 +class CMyComPtr
  546.17 +{
  546.18 +  T* _p;
  546.19 +public:
  546.20 +  // typedef T _PtrClass;
  546.21 +  CMyComPtr() { _p = NULL;}
  546.22 +  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }
  546.23 +  CMyComPtr(const CMyComPtr<T>& lp)
  546.24 +  {
  546.25 +    if ((_p = lp._p) != NULL)
  546.26 +      _p->AddRef();
  546.27 +  }
  546.28 +  ~CMyComPtr() { if (_p) _p->Release(); }
  546.29 +  void Release() { if (_p) { _p->Release(); _p = NULL; } }
  546.30 +  operator T*() const {  return (T*)_p;  }
  546.31 +  // T& operator*() const {  return *_p; }
  546.32 +  T** operator&() { return &_p; }
  546.33 +  T* operator->() const { return _p; }
  546.34 +  T* operator=(T* p)
  546.35 +  {
  546.36 +    if (p != 0)
  546.37 +      p->AddRef();
  546.38 +    if (_p)
  546.39 +      _p->Release();
  546.40 +    _p = p;
  546.41 +    return p;
  546.42 +  }
  546.43 +  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }
  546.44 +  bool operator!() const { return (_p == NULL); }
  546.45 +  // bool operator==(T* pT) const {  return _p == pT; }
  546.46 +  // Compare two objects for equivalence
  546.47 +  void Attach(T* p2)
  546.48 +  {
  546.49 +    Release();
  546.50 +    _p = p2;
  546.51 +  }
  546.52 +  T* Detach()
  546.53 +  {
  546.54 +    T* pt = _p;
  546.55 +    _p = NULL;
  546.56 +    return pt;
  546.57 +  }
  546.58 +  #ifdef _WIN32
  546.59 +  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
  546.60 +  {
  546.61 +    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);
  546.62 +  }
  546.63 +  #endif
  546.64 +  /*
  546.65 +  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
  546.66 +  {
  546.67 +    CLSID clsid;
  546.68 +    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);
  546.69 +    ATLASSERT(_p == NULL);
  546.70 +    if (SUCCEEDED(hr))
  546.71 +      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);
  546.72 +    return hr;
  546.73 +  }
  546.74 +  */
  546.75 +  template <class Q>
  546.76 +  HRESULT QueryInterface(REFGUID iid, Q** pp) const
  546.77 +  {
  546.78 +    return _p->QueryInterface(iid, (void**)pp);
  546.79 +  }
  546.80 +};
  546.81 +
  546.82 +//////////////////////////////////////////////////////////
  546.83 +
  546.84 +inline HRESULT StringToBstr(LPCOLESTR src, BSTR *bstr)
  546.85 +{
  546.86 +  *bstr = ::SysAllocString(src);
  546.87 +  return (*bstr != 0) ? S_OK : E_OUTOFMEMORY;
  546.88 +}
  546.89 +
  546.90 +class CMyComBSTR
  546.91 +{
  546.92 +public:
  546.93 +  BSTR m_str;
  546.94 +  CMyComBSTR(): m_str(NULL) {}
  546.95 +  CMyComBSTR(LPCOLESTR src) { m_str = ::SysAllocString(src); }
  546.96 +  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }
  546.97 +  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }
  546.98 +  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }
  546.99 +  /*
 546.100 +  CMyComBSTR(REFGUID src)
 546.101 +  {
 546.102 +    LPOLESTR szGuid;
 546.103 +    StringFromCLSID(src, &szGuid);
 546.104 +    m_str = ::SysAllocString(szGuid);
 546.105 +    CoTaskMemFree(szGuid);
 546.106 +  }
 546.107 +  */
 546.108 +  ~CMyComBSTR() { ::SysFreeString(m_str); }
 546.109 +  CMyComBSTR& operator=(const CMyComBSTR& src)
 546.110 +  {
 546.111 +    if (m_str != src.m_str)
 546.112 +    {
 546.113 +      if (m_str)
 546.114 +        ::SysFreeString(m_str);
 546.115 +      m_str = src.MyCopy();
 546.116 +    }
 546.117 +    return *this;
 546.118 +  }
 546.119 +  CMyComBSTR& operator=(LPCOLESTR src)
 546.120 +  {
 546.121 +    ::SysFreeString(m_str);
 546.122 +    m_str = ::SysAllocString(src);
 546.123 +    return *this;
 546.124 +  }
 546.125 +  unsigned int Length() const { return ::SysStringLen(m_str); }
 546.126 +  operator BSTR() const { return m_str; }
 546.127 +  BSTR* operator&() { return &m_str; }
 546.128 +  BSTR MyCopy() const
 546.129 +  {
 546.130 +    int byteLen = ::SysStringByteLen(m_str);
 546.131 +    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);
 546.132 +    memcpy(res, m_str, byteLen);
 546.133 +    return res;
 546.134 +  }
 546.135 +  /*
 546.136 +  void Attach(BSTR src) { m_str = src; }
 546.137 +  BSTR Detach()
 546.138 +  {
 546.139 +    BSTR s = m_str;
 546.140 +    m_str = NULL;
 546.141 +    return s;
 546.142 +  }
 546.143 +  */
 546.144 +  void Empty()
 546.145 +  {
 546.146 +    ::SysFreeString(m_str);
 546.147 +    m_str = NULL;
 546.148 +  }
 546.149 +  bool operator!() const {  return (m_str == NULL); }
 546.150 +};
 546.151 +
 546.152 +//////////////////////////////////////////////////////////
 546.153 +
 546.154 +class CMyUnknownImp
 546.155 +{
 546.156 +public:
 546.157 +  ULONG __m_RefCount;
 546.158 +  CMyUnknownImp(): __m_RefCount(0) {}
 546.159 +};
 546.160 +
 546.161 +#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \
 546.162 +    (REFGUID iid, void **outObject) {
 546.163 +
 546.164 +#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \
 546.165 +    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }
 546.166 +
 546.167 +#define MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) if (iid == IID_IUnknown) \
 546.168 +    { *outObject = (void *)(IUnknown *)(i *)this; AddRef(); return S_OK; }
 546.169 +
 546.170 +#define MY_QUERYINTERFACE_BEGIN2(i) MY_QUERYINTERFACE_BEGIN \
 546.171 +    MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \
 546.172 +    MY_QUERYINTERFACE_ENTRY(i)
 546.173 +
 546.174 +#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }
 546.175 +
 546.176 +#define MY_ADDREF_RELEASE \
 546.177 +STDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \
 546.178 +STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \
 546.179 +  return __m_RefCount; delete this; return 0; }
 546.180 +
 546.181 +#define MY_UNKNOWN_IMP_SPEC(i) \
 546.182 +  MY_QUERYINTERFACE_BEGIN \
 546.183 +  i \
 546.184 +  MY_QUERYINTERFACE_END \
 546.185 +  MY_ADDREF_RELEASE
 546.186 +
 546.187 +
 546.188 +#define MY_UNKNOWN_IMP MY_QUERYINTERFACE_BEGIN \
 546.189 +  MY_QUERYINTERFACE_ENTRY_UNKNOWN(IUnknown) \
 546.190 +  MY_QUERYINTERFACE_END \
 546.191 +  MY_ADDREF_RELEASE
 546.192 +
 546.193 +#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \
 546.194 +  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \
 546.195 +  MY_QUERYINTERFACE_ENTRY(i) \
 546.196 +  )
 546.197 +
 546.198 +#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \
 546.199 +  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \
 546.200 +  MY_QUERYINTERFACE_ENTRY(i1) \
 546.201 +  MY_QUERYINTERFACE_ENTRY(i2) \
 546.202 +  )
 546.203 +
 546.204 +#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \
 546.205 +  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \
 546.206 +  MY_QUERYINTERFACE_ENTRY(i1) \
 546.207 +  MY_QUERYINTERFACE_ENTRY(i2) \
 546.208 +  MY_QUERYINTERFACE_ENTRY(i3) \
 546.209 +  )
 546.210 +
 546.211 +#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \
 546.212 +  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \
 546.213 +  MY_QUERYINTERFACE_ENTRY(i1) \
 546.214 +  MY_QUERYINTERFACE_ENTRY(i2) \
 546.215 +  MY_QUERYINTERFACE_ENTRY(i3) \
 546.216 +  MY_QUERYINTERFACE_ENTRY(i4) \
 546.217 +  )
 546.218 +
 546.219 +#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \
 546.220 +  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \
 546.221 +  MY_QUERYINTERFACE_ENTRY(i1) \
 546.222 +  MY_QUERYINTERFACE_ENTRY(i2) \
 546.223 +  MY_QUERYINTERFACE_ENTRY(i3) \
 546.224 +  MY_QUERYINTERFACE_ENTRY(i4) \
 546.225 +  MY_QUERYINTERFACE_ENTRY(i5) \
 546.226 +  )
 546.227 +
 546.228 +#endif
   547.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   547.2 +++ b/src/win32/7zip/7z/CPP/Common/MyException.h	Sat Mar 03 10:31:27 2012 -0600
   547.3 @@ -0,0 +1,14 @@
   547.4 +// Common/Exception.h
   547.5 +
   547.6 +#ifndef __COMMON_EXCEPTION_H
   547.7 +#define __COMMON_EXCEPTION_H
   547.8 +
   547.9 +#include "MyWindows.h"
  547.10 +
  547.11 +struct CSystemException
  547.12 +{
  547.13 +  HRESULT ErrorCode;
  547.14 +  CSystemException(HRESULT errorCode): ErrorCode(errorCode) {}
  547.15 +};
  547.16 +
  547.17 +#endif
   548.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   548.2 +++ b/src/win32/7zip/7z/CPP/Common/MyInitGuid.h	Sat Mar 03 10:31:27 2012 -0600
   548.3 @@ -0,0 +1,15 @@
   548.4 +// Common/MyInitGuid.h
   548.5 +
   548.6 +#ifndef __COMMON_MYINITGUID_H
   548.7 +#define __COMMON_MYINITGUID_H
   548.8 +
   548.9 +#ifdef _WIN32
  548.10 +#include <initguid.h>
  548.11 +#else
  548.12 +#define INITGUID
  548.13 +#include "MyGuidDef.h"
  548.14 +DEFINE_GUID(IID_IUnknown,
  548.15 +0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
  548.16 +#endif
  548.17 +
  548.18 +#endif
   549.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   549.2 +++ b/src/win32/7zip/7z/CPP/Common/MyMap.cpp	Sat Mar 03 10:31:27 2012 -0600
   549.3 @@ -0,0 +1,140 @@
   549.4 +// MyMap.cpp
   549.5 +
   549.6 +#include "StdAfx.h"
   549.7 +
   549.8 +#include "MyMap.h"
   549.9 +
  549.10 +static const unsigned kNumBitsMax = sizeof(UInt32) * 8;
  549.11 +
  549.12 +static UInt32 GetSubBits(UInt32 value, unsigned startPos, unsigned numBits)
  549.13 +{
  549.14 +  if (startPos == sizeof(value) * 8)
  549.15 +    return 0;
  549.16 +  value >>= startPos;
  549.17 +  if (numBits == sizeof(value) * 8)
  549.18 +    return value;
  549.19 +  return value & (((UInt32)1 << numBits) - 1);
  549.20 +}
  549.21 +
  549.22 +static inline unsigned GetSubBit(UInt32 v, unsigned n) { return (unsigned)(v >> n) & 1; }
  549.23 +
  549.24 +bool CMap32::Find(UInt32 key, UInt32 &valueRes) const
  549.25 +{
  549.26 +  valueRes = (UInt32)(Int32)-1;
  549.27 +  if (Nodes.Size() == 0)
  549.28 +    return false;
  549.29 +  if (Nodes.Size() == 1)
  549.30 +  {
  549.31 +    const CNode &n = Nodes[0];
  549.32 +    if (n.Len == kNumBitsMax)
  549.33 +    {
  549.34 +      valueRes = n.Values[0];
  549.35 +      return (key == n.Key);
  549.36 +    }
  549.37 +  }
  549.38 +
  549.39 +  int cur = 0;
  549.40 +  unsigned bitPos = kNumBitsMax;
  549.41 +  for (;;)
  549.42 +  {
  549.43 +    const CNode &n = Nodes[cur];
  549.44 +    bitPos -= n.Len;
  549.45 +    if (GetSubBits(key, bitPos, n.Len) != GetSubBits(n.Key, bitPos, n.Len))
  549.46 +      return false;
  549.47 +    unsigned bit = GetSubBit(key, --bitPos);
  549.48 +    if (n.IsLeaf[bit])
  549.49 +    {
  549.50 +      valueRes = n.Values[bit];
  549.51 +      return (key == n.Keys[bit]);
  549.52 +    }
  549.53 +    cur = (int)n.Keys[bit];
  549.54 +  }
  549.55 +}
  549.56 +
  549.57 +bool CMap32::Set(UInt32 key, UInt32 value)
  549.58 +{
  549.59 +  if (Nodes.Size() == 0)
  549.60 +  {
  549.61 +    CNode n;
  549.62 +    n.Key = n.Keys[0] = n.Keys[1] = key;
  549.63 +    n.Values[0] = n.Values[1] = value;
  549.64 +    n.IsLeaf[0] = n.IsLeaf[1] = 1;
  549.65 +    n.Len = kNumBitsMax;
  549.66 +    Nodes.Add(n);
  549.67 +    return false;
  549.68 +  }
  549.69 +  if (Nodes.Size() == 1)
  549.70 +  {
  549.71 +    CNode &n = Nodes[0];
  549.72 +    if (n.Len == kNumBitsMax)
  549.73 +    {
  549.74 +      if (key == n.Key)
  549.75 +      {
  549.76 +        n.Values[0] = n.Values[1] = value;
  549.77 +        return true;
  549.78 +      }
  549.79 +      unsigned i = kNumBitsMax - 1;
  549.80 +      for (;GetSubBit(key, i) == GetSubBit(n.Key, i); i--);
  549.81 +      n.Len = (UInt16)(kNumBitsMax - (1 + i));
  549.82 +      unsigned newBit = GetSubBit(key, i);
  549.83 +      n.Values[newBit] = value;
  549.84 +      n.Keys[newBit] = key;
  549.85 +      return false;
  549.86 +    }
  549.87 +  }
  549.88 +
  549.89 +  int cur = 0;
  549.90 +  unsigned bitPos = kNumBitsMax;
  549.91 +  for (;;)
  549.92 +  {
  549.93 +    CNode &n = Nodes[cur];
  549.94 +    bitPos -= n.Len;
  549.95 +    if (GetSubBits(key, bitPos, n.Len) != GetSubBits(n.Key, bitPos, n.Len))
  549.96 +    {
  549.97 +      unsigned i = n.Len - 1;
  549.98 +      for (; GetSubBit(key, bitPos + i) == GetSubBit(n.Key, bitPos + i); i--);
  549.99 +      
 549.100 +      CNode e2(n);
 549.101 +      e2.Len = (UInt16)i;
 549.102 +
 549.103 +      n.Len = (UInt16)(n.Len - (1 + i));
 549.104 +      unsigned newBit = GetSubBit(key, bitPos + i);
 549.105 +      n.Values[newBit] = value;
 549.106 +      n.IsLeaf[newBit] = 1;
 549.107 +      n.IsLeaf[1 - newBit] = 0;
 549.108 +      n.Keys[newBit] = key;
 549.109 +      n.Keys[1 - newBit] = Nodes.Size();
 549.110 +      Nodes.Add(e2);
 549.111 +      return false;
 549.112 +    }
 549.113 +    unsigned bit = GetSubBit(key, --bitPos);
 549.114 +
 549.115 +    if (n.IsLeaf[bit])
 549.116 +    {
 549.117 +      if (key == n.Keys[bit])
 549.118 +      {
 549.119 +        n.Values[bit] = value;
 549.120 +        return true;
 549.121 +      }
 549.122 +      unsigned i = bitPos - 1;
 549.123 +      for (;GetSubBit(key, i) == GetSubBit(n.Keys[bit], i); i--);
 549.124 +     
 549.125 +      CNode e2;
 549.126 +      
 549.127 +      unsigned newBit = GetSubBit(key, i);
 549.128 +      e2.Values[newBit] = value;
 549.129 +      e2.Values[1 - newBit] = n.Values[bit];
 549.130 +      e2.IsLeaf[newBit] = e2.IsLeaf[1 - newBit] = 1;
 549.131 +      e2.Keys[newBit] = key;
 549.132 +      e2.Keys[1 - newBit] = e2.Key = n.Keys[bit];
 549.133 +      e2.Len = (UInt16)(bitPos - (1 + i));
 549.134 +
 549.135 +      n.IsLeaf[bit] = 0;
 549.136 +      n.Keys[bit] = Nodes.Size();
 549.137 +
 549.138 +      Nodes.Add(e2);
 549.139 +      return false;
 549.140 +    }
 549.141 +    cur = (int)n.Keys[bit];
 549.142 +  }
 549.143 +}
   550.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   550.2 +++ b/src/win32/7zip/7z/CPP/Common/MyMap.h	Sat Mar 03 10:31:27 2012 -0600
   550.3 @@ -0,0 +1,28 @@
   550.4 +// MyMap.h
   550.5 +
   550.6 +#ifndef __COMMON_MYMAP_H
   550.7 +#define __COMMON_MYMAP_H
   550.8 +
   550.9 +#include "MyVector.h"
  550.10 +#include "Types.h"
  550.11 +
  550.12 +class CMap32
  550.13 +{
  550.14 +  struct CNode
  550.15 +  {
  550.16 +    UInt32 Key;
  550.17 +    UInt32 Keys[2];
  550.18 +    UInt32 Values[2];
  550.19 +    UInt16 Len;
  550.20 +    Byte IsLeaf[2];
  550.21 +  };
  550.22 +  CRecordVector<CNode> Nodes;
  550.23 +
  550.24 +public:
  550.25 +
  550.26 +  void Clear() { Nodes.Clear(); }
  550.27 +  bool Find(UInt32 key, UInt32 &valueRes) const;
  550.28 +  bool Set(UInt32 key, UInt32 value); // returns true, if there is such key already
  550.29 +};
  550.30 +
  550.31 +#endif
   551.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   551.2 +++ b/src/win32/7zip/7z/CPP/Common/MyString.cpp	Sat Mar 03 10:31:27 2012 -0600
   551.3 @@ -0,0 +1,198 @@
   551.4 +// Common/MyString.cpp
   551.5 +
   551.6 +#include "StdAfx.h"
   551.7 +
   551.8 +#ifdef _WIN32
   551.9 +#include "StringConvert.h"
  551.10 +#else
  551.11 +#include <ctype.h>
  551.12 +#endif
  551.13 +
  551.14 +#include "MyString.h"
  551.15 +
  551.16 +
  551.17 +#ifdef _WIN32
  551.18 +
  551.19 +#ifndef _UNICODE
  551.20 +
  551.21 +wchar_t MyCharUpper(wchar_t c)
  551.22 +{
  551.23 +  if (c == 0)
  551.24 +    return 0;
  551.25 +  wchar_t *res = CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c);
  551.26 +  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
  551.27 +    return (wchar_t)(unsigned int)(UINT_PTR)res;
  551.28 +  const int kBufferSize = 4;
  551.29 +  char s[kBufferSize + 1];
  551.30 +  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);
  551.31 +  if (numChars == 0 || numChars > kBufferSize)
  551.32 +    return c;
  551.33 +  s[numChars] = 0;
  551.34 +  ::CharUpperA(s);
  551.35 +  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);
  551.36 +  return c;
  551.37 +}
  551.38 +
  551.39 +wchar_t MyCharLower(wchar_t c)
  551.40 +{
  551.41 +  if (c == 0)
  551.42 +    return 0;
  551.43 +  wchar_t *res = CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c);
  551.44 +  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
  551.45 +    return (wchar_t)(unsigned int)(UINT_PTR)res;
  551.46 +  const int kBufferSize = 4;
  551.47 +  char s[kBufferSize + 1];
  551.48 +  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);
  551.49 +  if (numChars == 0 || numChars > kBufferSize)
  551.50 +    return c;
  551.51 +  s[numChars] = 0;
  551.52 +  ::CharLowerA(s);
  551.53 +  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);
  551.54 +  return c;
  551.55 +}
  551.56 +
  551.57 +wchar_t * MyStringUpper(wchar_t *s)
  551.58 +{
  551.59 +  if (s == 0)
  551.60 +    return 0;
  551.61 +  wchar_t *res = CharUpperW(s);
  551.62 +  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
  551.63 +    return res;
  551.64 +  AString a = UnicodeStringToMultiByte(s);
  551.65 +  a.MakeUpper();
  551.66 +  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));
  551.67 +}
  551.68 +
  551.69 +wchar_t * MyStringLower(wchar_t *s)
  551.70 +{
  551.71 +  if (s == 0)
  551.72 +    return 0;
  551.73 +  wchar_t *res = CharLowerW(s);
  551.74 +  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
  551.75 +    return res;
  551.76 +  AString a = UnicodeStringToMultiByte(s);
  551.77 +  a.MakeLower();
  551.78 +  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));
  551.79 +}
  551.80 +
  551.81 +#endif
  551.82 +
  551.83 +/*
  551.84 +inline int ConvertCompareResult(int r) { return r - 2; }
  551.85 +
  551.86 +int MyStringCollate(const wchar_t *s1, const wchar_t *s2)
  551.87 +{
  551.88 +  int res = CompareStringW(
  551.89 +        LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1);
  551.90 +  #ifdef _UNICODE
  551.91 +  return ConvertCompareResult(res);
  551.92 +  #else
  551.93 +  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
  551.94 +    return ConvertCompareResult(res);
  551.95 +  return MyStringCollate(UnicodeStringToMultiByte(s1),
  551.96 +        UnicodeStringToMultiByte(s2));
  551.97 +  #endif
  551.98 +}
  551.99 +
 551.100 +#ifndef _WIN32_WCE
 551.101 +int MyStringCollate(const char *s1, const char *s2)
 551.102 +{
 551.103 +  return ConvertCompareResult(CompareStringA(
 551.104 +    LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1));
 551.105 +}
 551.106 +
 551.107 +int MyStringCollateNoCase(const char *s1, const char *s2)
 551.108 +{
 551.109 +  return ConvertCompareResult(CompareStringA(
 551.110 +    LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1));
 551.111 +}
 551.112 +#endif
 551.113 +
 551.114 +int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)
 551.115 +{
 551.116 +  int res = CompareStringW(
 551.117 +        LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1);
 551.118 +  #ifdef _UNICODE
 551.119 +  return ConvertCompareResult(res);
 551.120 +  #else
 551.121 +  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
 551.122 +    return ConvertCompareResult(res);
 551.123 +  return MyStringCollateNoCase(UnicodeStringToMultiByte(s1),
 551.124 +      UnicodeStringToMultiByte(s2));
 551.125 +  #endif
 551.126 +}
 551.127 +*/
 551.128 +
 551.129 +#else
 551.130 +
 551.131 +wchar_t MyCharUpper(wchar_t c)
 551.132 +{
 551.133 +  return toupper(c);
 551.134 +}
 551.135 +
 551.136 +/*
 551.137 +int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)
 551.138 +{
 551.139 +  for (;;)
 551.140 +  {
 551.141 +    wchar_t c1 = *s1++;
 551.142 +    wchar_t c2 = *s2++;
 551.143 +    wchar_t u1 = MyCharUpper(c1);
 551.144 +    wchar_t u2 = MyCharUpper(c2);
 551.145 +
 551.146 +    if (u1 < u2) return -1;
 551.147 +    if (u1 > u2) return 1;
 551.148 +    if (u1 == 0) return 0;
 551.149 +  }
 551.150 +}
 551.151 +*/
 551.152 +
 551.153 +#endif
 551.154 +
 551.155 +int MyStringCompare(const char *s1, const char *s2)
 551.156 +{
 551.157 +  for (;;)
 551.158 +  {
 551.159 +    unsigned char c1 = (unsigned char)*s1++;
 551.160 +    unsigned char c2 = (unsigned char)*s2++;
 551.161 +    if (c1 < c2) return -1;
 551.162 +    if (c1 > c2) return 1;
 551.163 +    if (c1 == 0) return 0;
 551.164 +  }
 551.165 +}
 551.166 +
 551.167 +int MyStringCompare(const wchar_t *s1, const wchar_t *s2)
 551.168 +{
 551.169 +  for (;;)
 551.170 +  {
 551.171 +    wchar_t c1 = *s1++;
 551.172 +    wchar_t c2 = *s2++;
 551.173 +    if (c1 < c2) return -1;
 551.174 +    if (c1 > c2) return 1;
 551.175 +    if (c1 == 0) return 0;
 551.176 +  }
 551.177 +}
 551.178 +
 551.179 +int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)
 551.180 +{
 551.181 +  for (;;)
 551.182 +  {
 551.183 +    wchar_t c1 = *s1++;
 551.184 +    wchar_t c2 = *s2++;
 551.185 +    if (c1 != c2)
 551.186 +    {
 551.187 +      wchar_t u1 = MyCharUpper(c1);
 551.188 +      wchar_t u2 = MyCharUpper(c2);
 551.189 +      if (u1 < u2) return -1;
 551.190 +      if (u1 > u2) return 1;
 551.191 +    }
 551.192 +    if (c1 == 0) return 0;
 551.193 +  }
 551.194 +}
 551.195 +
 551.196 +#ifdef _WIN32
 551.197 +int MyStringCompareNoCase(const char *s1, const char *s2)
 551.198 +{
 551.199 +  return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2));
 551.200 +}
 551.201 +#endif
   552.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   552.2 +++ b/src/win32/7zip/7z/CPP/Common/MyString.h	Sat Mar 03 10:31:27 2012 -0600
   552.3 @@ -0,0 +1,631 @@
   552.4 +// Common/String.h
   552.5 +
   552.6 +#ifndef __COMMON_STRING_H
   552.7 +#define __COMMON_STRING_H
   552.8 +
   552.9 +#include <string.h>
  552.10 +// #include <wchar.h>
  552.11 +
  552.12 +#include "MyVector.h"
  552.13 +
  552.14 +#ifdef _WIN32
  552.15 +#include "MyWindows.h"
  552.16 +#endif
  552.17 +
  552.18 +template <class T>
  552.19 +inline int MyStringLen(const T *s)
  552.20 +{
  552.21 +  int i;
  552.22 +  for (i = 0; s[i] != '\0'; i++);
  552.23 +  return i;
  552.24 +}
  552.25 +
  552.26 +template <class T>
  552.27 +inline T * MyStringCopy(T *dest, const T *src)
  552.28 +{
  552.29 +  T *destStart = dest;
  552.30 +  while ((*dest++ = *src++) != 0);
  552.31 +  return destStart;
  552.32 +}
  552.33 +
  552.34 +inline wchar_t* MyStringGetNextCharPointer(wchar_t *p)
  552.35 +  { return (p + 1); }
  552.36 +inline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)
  552.37 +  { return (p + 1); }
  552.38 +inline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p)
  552.39 +  { return (p - 1); }
  552.40 +inline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p)
  552.41 +  { return (p - 1); }
  552.42 +
  552.43 +#ifdef _WIN32
  552.44 +
  552.45 +inline char* MyStringGetNextCharPointer(char *p)
  552.46 +  { return CharNextA(p); }
  552.47 +inline const char* MyStringGetNextCharPointer(const char *p)
  552.48 +  { return CharNextA(p); }
  552.49 +
  552.50 +inline char* MyStringGetPrevCharPointer(char *base, char *p)
  552.51 +  { return CharPrevA(base, p); }
  552.52 +inline const char* MyStringGetPrevCharPointer(const char *base, const char *p)
  552.53 +  { return CharPrevA(base, p); }
  552.54 +
  552.55 +inline char MyCharUpper(char c)
  552.56 +  { return (char)(unsigned int)(UINT_PTR)CharUpperA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }
  552.57 +#ifdef _UNICODE
  552.58 +inline wchar_t MyCharUpper(wchar_t c)
  552.59 +  { return (wchar_t)(unsigned int)(UINT_PTR)CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); }
  552.60 +#else
  552.61 +wchar_t MyCharUpper(wchar_t c);
  552.62 +#endif
  552.63 +
  552.64 +inline char MyCharLower(char c)
  552.65 +  { return (char)(unsigned int)(UINT_PTR)CharLowerA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }
  552.66 +#ifdef _UNICODE
  552.67 +inline wchar_t MyCharLower(wchar_t c)
  552.68 +  { return (wchar_t)(unsigned int)(UINT_PTR)CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); }
  552.69 +#else
  552.70 +wchar_t MyCharLower(wchar_t c);
  552.71 +#endif
  552.72 +
  552.73 +inline char * MyStringUpper(char *s) { return CharUpperA(s); }
  552.74 +#ifdef _UNICODE
  552.75 +inline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); }
  552.76 +#else
  552.77 +wchar_t * MyStringUpper(wchar_t *s);
  552.78 +#endif
  552.79 +
  552.80 +inline char * MyStringLower(char *s) { return CharLowerA(s); }
  552.81 +#ifdef _UNICODE
  552.82 +inline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); }
  552.83 +#else
  552.84 +wchar_t * MyStringLower(wchar_t *s);
  552.85 +#endif
  552.86 +
  552.87 +#else // Standard-C
  552.88 +wchar_t MyCharUpper(wchar_t c);
  552.89 +#endif
  552.90 +
  552.91 +//////////////////////////////////////
  552.92 +// Compare
  552.93 +
  552.94 +/*
  552.95 +#ifndef _WIN32_WCE
  552.96 +int MyStringCollate(const char *s1, const char *s2);
  552.97 +int MyStringCollateNoCase(const char *s1, const char *s2);
  552.98 +#endif
  552.99 +int MyStringCollate(const wchar_t *s1, const wchar_t *s2);
 552.100 +int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);
 552.101 +*/
 552.102 +
 552.103 +int MyStringCompare(const char *s1, const char  *s2);
 552.104 +int MyStringCompare(const wchar_t *s1, const wchar_t *s2);
 552.105 +
 552.106 +#ifdef _WIN32
 552.107 +int MyStringCompareNoCase(const char *s1, const char  *s2);
 552.108 +#endif
 552.109 +
 552.110 +int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2);
 552.111 +
 552.112 +template <class T>
 552.113 +class CStringBase
 552.114 +{
 552.115 +  void TrimLeftWithCharSet(const CStringBase &charSet)
 552.116 +  {
 552.117 +    const T *p = _chars;
 552.118 +    while (charSet.Find(*p) >= 0 && (*p != 0))
 552.119 +      p = GetNextCharPointer(p);
 552.120 +    Delete(0, (int)(p - _chars));
 552.121 +  }
 552.122 +  void TrimRightWithCharSet(const CStringBase &charSet)
 552.123 +  {
 552.124 +    const T *p = _chars;
 552.125 +    const T *pLast = NULL;
 552.126 +    while (*p != 0)
 552.127 +    {
 552.128 +      if (charSet.Find(*p) >= 0)
 552.129 +      {
 552.130 +        if (pLast == NULL)
 552.131 +          pLast = p;
 552.132 +      }
 552.133 +      else
 552.134 +        pLast = NULL;
 552.135 +      p = GetNextCharPointer(p);
 552.136 +    }
 552.137 +    if (pLast != NULL)
 552.138 +    {
 552.139 +      int i = (int)(pLast - _chars);
 552.140 +      Delete(i, _length - i);
 552.141 +    }
 552.142 +
 552.143 +  }
 552.144 +  void MoveItems(int destIndex, int srcIndex)
 552.145 +  {
 552.146 +    memmove(_chars + destIndex, _chars + srcIndex,
 552.147 +        sizeof(T) * (_length - srcIndex + 1));
 552.148 +  }
 552.149 +  
 552.150 +  void InsertSpace(int &index, int size)
 552.151 +  {
 552.152 +    CorrectIndex(index);
 552.153 +    GrowLength(size);
 552.154 +    MoveItems(index + size, index);
 552.155 +  }
 552.156 +
 552.157 +  static T *GetNextCharPointer(T *p)
 552.158 +    { return MyStringGetNextCharPointer(p); }
 552.159 +  static const T *GetNextCharPointer(const T *p)
 552.160 +    { return MyStringGetNextCharPointer(p); }
 552.161 +  static T *GetPrevCharPointer(T *base, T *p)
 552.162 +    { return MyStringGetPrevCharPointer(base, p); }
 552.163 +  static const T *GetPrevCharPointer(const T *base, const T *p)
 552.164 +    { return MyStringGetPrevCharPointer(base, p); }
 552.165 +protected:
 552.166 +  T *_chars;
 552.167 +  int _length;
 552.168 +  int _capacity;
 552.169 +  
 552.170 +  void SetCapacity(int newCapacity)
 552.171 +  {
 552.172 +    int realCapacity = newCapacity + 1;
 552.173 +    if (realCapacity == _capacity)
 552.174 +      return;
 552.175 +    /*
 552.176 +    const int kMaxStringSize = 0x20000000;
 552.177 +    #ifndef _WIN32_WCE
 552.178 +    if (newCapacity > kMaxStringSize || newCapacity < _length)
 552.179 +      throw 1052337;
 552.180 +    #endif
 552.181 +    */
 552.182 +    T *newBuffer = new T[realCapacity];
 552.183 +    if (_capacity > 0)
 552.184 +    {
 552.185 +      for (int i = 0; i < _length; i++)
 552.186 +        newBuffer[i] = _chars[i];
 552.187 +      delete []_chars;
 552.188 +    }
 552.189 +    _chars = newBuffer;
 552.190 +    _chars[_length] = 0;
 552.191 +    _capacity = realCapacity;
 552.192 +  }
 552.193 +
 552.194 +  void GrowLength(int n)
 552.195 +  {
 552.196 +    int freeSize = _capacity - _length - 1;
 552.197 +    if (n <= freeSize)
 552.198 +      return;
 552.199 +    int delta;
 552.200 +    if (_capacity > 64)
 552.201 +      delta = _capacity / 2;
 552.202 +    else if (_capacity > 8)
 552.203 +      delta = 16;
 552.204 +    else
 552.205 +      delta = 4;
 552.206 +    if (freeSize + delta < n)
 552.207 +      delta = n - freeSize;
 552.208 +    SetCapacity(_capacity + delta);
 552.209 +  }
 552.210 +
 552.211 +  void CorrectIndex(int &index) const
 552.212 +  {
 552.213 +    if (index > _length)
 552.214 +      index = _length;
 552.215 +  }
 552.216 +
 552.217 +public:
 552.218 +  CStringBase(): _chars(0), _length(0), _capacity(0) { SetCapacity(3); }
 552.219 +  CStringBase(T c):  _chars(0), _length(0), _capacity(0)
 552.220 +  {
 552.221 +    SetCapacity(1);
 552.222 +    _chars[0] = c;
 552.223 +    _chars[1] = 0;
 552.224 +    _length = 1;
 552.225 +  }
 552.226 +  CStringBase(const T *chars): _chars(0), _length(0), _capacity(0)
 552.227 +  {
 552.228 +    int length = MyStringLen(chars);
 552.229 +    SetCapacity(length);
 552.230 +    MyStringCopy(_chars, chars); // can be optimized by memove()
 552.231 +    _length = length;
 552.232 +  }
 552.233 +  CStringBase(const CStringBase &s):  _chars(0), _length(0), _capacity(0)
 552.234 +  {
 552.235 +    SetCapacity(s._length);
 552.236 +    MyStringCopy(_chars, s._chars);
 552.237 +    _length = s._length;
 552.238 +  }
 552.239 +  ~CStringBase() {  delete []_chars; }
 552.240 +
 552.241 +  operator const T*() const { return _chars;}
 552.242 +
 552.243 +  // The minimum size of the character buffer in characters.
 552.244 +  // This value does not include space for a null terminator.
 552.245 +  T* GetBuffer(int minBufLength)
 552.246 +  {
 552.247 +    if (minBufLength >= _capacity)
 552.248 +      SetCapacity(minBufLength);
 552.249 +    return _chars;
 552.250 +  }
 552.251 +  void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); }
 552.252 +  void ReleaseBuffer(int newLength)
 552.253 +  {
 552.254 +    /*
 552.255 +    #ifndef _WIN32_WCE
 552.256 +    if (newLength >= _capacity)
 552.257 +      throw 282217;
 552.258 +    #endif
 552.259 +    */
 552.260 +    _chars[newLength] = 0;
 552.261 +    _length = newLength;
 552.262 +  }
 552.263 +
 552.264 +  CStringBase& operator=(T c)
 552.265 +  {
 552.266 +    Empty();
 552.267 +    SetCapacity(1);
 552.268 +    _chars[0] = c;
 552.269 +    _chars[1] = 0;
 552.270 +    _length = 1;
 552.271 +    return *this;
 552.272 +  }
 552.273 +  CStringBase& operator=(const T *chars)
 552.274 +  {
 552.275 +    Empty();
 552.276 +    int length = MyStringLen(chars);
 552.277 +    SetCapacity(length);
 552.278 +    MyStringCopy(_chars, chars);
 552.279 +    _length = length;
 552.280 +    return *this;
 552.281 +  }
 552.282 +  CStringBase& operator=(const CStringBase& s)
 552.283 +  {
 552.284 +    if (&s == this)
 552.285 +      return *this;
 552.286 +    Empty();
 552.287 +    SetCapacity(s._length);
 552.288 +    MyStringCopy(_chars, s._chars);
 552.289 +    _length = s._length;
 552.290 +    return *this;
 552.291 +  }
 552.292 +  
 552.293 +  CStringBase& operator+=(T c)
 552.294 +  {
 552.295 +    GrowLength(1);
 552.296 +    _chars[_length] = c;
 552.297 +    _chars[++_length] = 0;
 552.298 +    return *this;
 552.299 +  }
 552.300 +  CStringBase& operator+=(const T *s)
 552.301 +  {
 552.302 +    int len = MyStringLen(s);
 552.303 +    GrowLength(len);
 552.304 +    MyStringCopy(_chars + _length, s);
 552.305 +    _length += len;
 552.306 +    return *this;
 552.307 +  }
 552.308 +  CStringBase& operator+=(const CStringBase &s)
 552.309 +  {
 552.310 +    GrowLength(s._length);
 552.311 +    MyStringCopy(_chars + _length, s._chars);
 552.312 +    _length += s._length;
 552.313 +    return *this;
 552.314 +  }
 552.315 +  void Empty()
 552.316 +  {
 552.317 +    _length = 0;
 552.318 +    _chars[0] = 0;
 552.319 +  }
 552.320 +  int Length() const { return _length; }
 552.321 +  bool IsEmpty() const { return (_length == 0); }
 552.322 +
 552.323 +  CStringBase Mid(int startIndex) const
 552.324 +    { return Mid(startIndex, _length - startIndex); }
 552.325 +  CStringBase Mid(int startIndex, int count ) const
 552.326 +  {
 552.327 +    if (startIndex + count > _length)
 552.328 +      count = _length - startIndex;
 552.329 +    
 552.330 +    if (startIndex == 0 && startIndex + count == _length)
 552.331 +      return *this;
 552.332 +    
 552.333 +    CStringBase<T> result;
 552.334 +    result.SetCapacity(count);
 552.335 +    // MyStringNCopy(result._chars, _chars + startIndex, count);
 552.336 +    for (int i = 0; i < count; i++)
 552.337 +      result._chars[i] = _chars[startIndex + i];
 552.338 +    result._chars[count] = 0;
 552.339 +    result._length = count;
 552.340 +    return result;
 552.341 +  }
 552.342 +  CStringBase Left(int count) const
 552.343 +    { return Mid(0, count); }
 552.344 +  CStringBase Right(int count) const
 552.345 +  {
 552.346 +    if (count > _length)
 552.347 +      count = _length;
 552.348 +    return Mid(_length - count, count);
 552.349 +  }
 552.350 +
 552.351 +  void MakeUpper()
 552.352 +    { MyStringUpper(_chars); }
 552.353 +  void MakeLower()
 552.354 +    { MyStringLower(_chars); }
 552.355 +
 552.356 +  int Compare(const CStringBase& s) const
 552.357 +    { return MyStringCompare(_chars, s._chars); }
 552.358 +
 552.359 +  int Compare(const T *s) const
 552.360 +    { return MyStringCompare(_chars, s); }
 552.361 +
 552.362 +  int CompareNoCase(const CStringBase& s) const
 552.363 +    { return MyStringCompareNoCase(_chars, s._chars); }
 552.364 +
 552.365 +  int CompareNoCase(const T *s) const
 552.366 +    { return MyStringCompareNoCase(_chars, s); }
 552.367 +
 552.368 +  /*
 552.369 +  int Collate(const CStringBase& s) const
 552.370 +    { return MyStringCollate(_chars, s._chars); }
 552.371 +  int CollateNoCase(const CStringBase& s) const
 552.372 +    { return MyStringCollateNoCase(_chars, s._chars); }
 552.373 +  */
 552.374 +
 552.375 +  int Find(T c) const { return Find(c, 0); }
 552.376 +  int Find(T c, int startIndex) const
 552.377 +  {
 552.378 +    T *p = _chars + startIndex;
 552.379 +    for (;;)
 552.380 +    {
 552.381 +      if (*p == c)
 552.382 +        return (int)(p - _chars);
 552.383 +      if (*p == 0)
 552.384 +        return -1;
 552.385 +      p = GetNextCharPointer(p);
 552.386 +    }
 552.387 +  }
 552.388 +  int Find(const CStringBase &s) const { return Find(s, 0); }
 552.389 +  int Find(const CStringBase &s, int startIndex) const
 552.390 +  {
 552.391 +    if (s.IsEmpty())
 552.392 +      return startIndex;
 552.393 +    for (; startIndex < _length; startIndex++)
 552.394 +    {
 552.395 +      int j;
 552.396 +      for (j = 0; j < s._length && startIndex + j < _length; j++)
 552.397 +        if (_chars[startIndex+j] != s._chars[j])
 552.398 +          break;
 552.399 +      if (j == s._length)
 552.400 +        return startIndex;
 552.401 +    }
 552.402 +    return -1;
 552.403 +  }
 552.404 +  int ReverseFind(T c) const
 552.405 +  {
 552.406 +    if (_length == 0)
 552.407 +      return -1;
 552.408 +    T *p = _chars + _length - 1;
 552.409 +    for (;;)
 552.410 +    {
 552.411 +      if (*p == c)
 552.412 +        return (int)(p - _chars);
 552.413 +      if (p == _chars)
 552.414 +        return -1;
 552.415 +      p = GetPrevCharPointer(_chars, p);
 552.416 +    }
 552.417 +  }
 552.418 +  int FindOneOf(const CStringBase &s) const
 552.419 +  {
 552.420 +    for (int i = 0; i < _length; i++)
 552.421 +      if (s.Find(_chars[i]) >= 0)
 552.422 +        return i;
 552.423 +      return -1;
 552.424 +  }
 552.425 +
 552.426 +  void TrimLeft(T c)
 552.427 +  {
 552.428 +    const T *p = _chars;
 552.429 +    while (c == *p)
 552.430 +      p = GetNextCharPointer(p);
 552.431 +    Delete(0, p - _chars);
 552.432 +  }
 552.433 +  private:
 552.434 +  CStringBase GetTrimDefaultCharSet()
 552.435 +  {
 552.436 +    CStringBase<T> charSet;
 552.437 +    charSet += (T)' ';
 552.438 +    charSet += (T)'\n';
 552.439 +    charSet += (T)'\t';
 552.440 +    return charSet;
 552.441 +  }
 552.442 +  public:
 552.443 +
 552.444 +  void TrimLeft()
 552.445 +  {
 552.446 +    TrimLeftWithCharSet(GetTrimDefaultCharSet());
 552.447 +  }
 552.448 +  void TrimRight()
 552.449 +  {
 552.450 +    TrimRightWithCharSet(GetTrimDefaultCharSet());
 552.451 +  }
 552.452 +  void TrimRight(T c)
 552.453 +  {
 552.454 +    const T *p = _chars;
 552.455 +    const T *pLast = NULL;
 552.456 +    while (*p != 0)
 552.457 +    {
 552.458 +      if (*p == c)
 552.459 +      {
 552.460 +        if (pLast == NULL)
 552.461 +          pLast = p;
 552.462 +      }
 552.463 +      else
 552.464 +        pLast = NULL;
 552.465 +      p = GetNextCharPointer(p);
 552.466 +    }
 552.467 +    if (pLast != NULL)
 552.468 +    {
 552.469 +      int i = pLast - _chars;
 552.470 +      Delete(i, _length - i);
 552.471 +    }
 552.472 +  }
 552.473 +  void Trim()
 552.474 +  {
 552.475 +    TrimRight();
 552.476 +    TrimLeft();
 552.477 +  }
 552.478 +
 552.479 +  int Insert(int index, T c)
 552.480 +  {
 552.481 +    InsertSpace(index, 1);
 552.482 +    _chars[index] = c;
 552.483 +    _length++;
 552.484 +    return _length;
 552.485 +  }
 552.486 +  int Insert(int index, const CStringBase &s)
 552.487 +  {
 552.488 +    CorrectIndex(index);
 552.489 +    if (s.IsEmpty())
 552.490 +      return _length;
 552.491 +    int numInsertChars = s.Length();
 552.492 +    InsertSpace(index, numInsertChars);
 552.493 +    for (int i = 0; i < numInsertChars; i++)
 552.494 +      _chars[index + i] = s[i];
 552.495 +    _length += numInsertChars;
 552.496 +    return _length;
 552.497 +  }
 552.498 +
 552.499 +  // !!!!!!!!!!!!!!! test it if newChar = '\0'
 552.500 +  int Replace(T oldChar, T newChar)
 552.501 +  {
 552.502 +    if (oldChar == newChar)
 552.503 +      return 0;
 552.504 +    int number  = 0;
 552.505 +    int pos  = 0;
 552.506 +    while (pos < Length())
 552.507 +    {
 552.508 +      pos = Find(oldChar, pos);
 552.509 +      if (pos < 0)
 552.510 +        break;
 552.511 +      _chars[pos] = newChar;
 552.512 +      pos++;
 552.513 +      number++;
 552.514 +    }
 552.515 +    return number;
 552.516 +  }
 552.517 +  int Replace(const CStringBase &oldString, const CStringBase &newString)
 552.518 +  {
 552.519 +    if (oldString.IsEmpty())
 552.520 +      return 0;
 552.521 +    if (oldString == newString)
 552.522 +      return 0;
 552.523 +    int oldStringLength = oldString.Length();
 552.524 +    int newStringLength = newString.Length();
 552.525 +    int number  = 0;
 552.526 +    int pos  = 0;
 552.527 +    while (pos < _length)
 552.528 +    {
 552.529 +      pos = Find(oldString, pos);
 552.530 +      if (pos < 0)
 552.531 +        break;
 552.532 +      Delete(pos, oldStringLength);
 552.533 +      Insert(pos, newString);
 552.534 +      pos += newStringLength;
 552.535 +      number++;
 552.536 +    }
 552.537 +    return number;
 552.538 +  }
 552.539 +  int Delete(int index, int count = 1 )
 552.540 +  {
 552.541 +    if (index + count > _length)
 552.542 +      count = _length - index;
 552.543 +    if (count > 0)
 552.544 +    {
 552.545 +      MoveItems(index, index + count);
 552.546 +      _length -= count;
 552.547 +    }
 552.548 +    return _length;
 552.549 +  }
 552.550 +};
 552.551 +
 552.552 +template <class T>
 552.553 +CStringBase<T> operator+(const CStringBase<T>& s1, const CStringBase<T>& s2)
 552.554 +{
 552.555 +  CStringBase<T> result(s1);
 552.556 +  result += s2;
 552.557 +  return result;
 552.558 +}
 552.559 +
 552.560 +template <class T>
 552.561 +CStringBase<T> operator+(const CStringBase<T>& s, T c)
 552.562 +{
 552.563 +  CStringBase<T> result(s);
 552.564 +  result += c;
 552.565 +  return result;
 552.566 +}
 552.567 +
 552.568 +template <class T>
 552.569 +CStringBase<T> operator+(T c, const CStringBase<T>& s)
 552.570 +{
 552.571 +  CStringBase<T> result(c);
 552.572 +  result += s;
 552.573 +  return result;
 552.574 +}
 552.575 +
 552.576 +template <class T>
 552.577 +CStringBase<T> operator+(const CStringBase<T>& s, const T * chars)
 552.578 +{
 552.579 +  CStringBase<T> result(s);
 552.580 +  result += chars;
 552.581 +  return result;
 552.582 +}
 552.583 +
 552.584 +template <class T>
 552.585 +CStringBase<T> operator+(const T * chars, const CStringBase<T>& s)
 552.586 +{
 552.587 +  CStringBase<T> result(chars);
 552.588 +  result += s;
 552.589 +  return result;
 552.590 +}
 552.591 +
 552.592 +template <class T>
 552.593 +bool operator==(const CStringBase<T>& s1, const CStringBase<T>& s2)
 552.594 +  { return (s1.Compare(s2) == 0); }
 552.595 +
 552.596 +template <class T>
 552.597 +bool operator<(const CStringBase<T>& s1, const CStringBase<T>& s2)
 552.598 +  { return (s1.Compare(s2) < 0); }
 552.599 +
 552.600 +template <class T>
 552.601 +bool operator==(const T *s1, const CStringBase<T>& s2)
 552.602 +  { return (s2.Compare(s1) == 0); }
 552.603 +
 552.604 +template <class T>
 552.605 +bool operator==(const CStringBase<T>& s1, const T *s2)
 552.606 +  { return (s1.Compare(s2) == 0); }
 552.607 +
 552.608 +template <class T>
 552.609 +bool operator!=(const CStringBase<T>& s1, const CStringBase<T>& s2)
 552.610 +  { return (s1.Compare(s2) != 0); }
 552.611 +
 552.612 +template <class T>
 552.613 +bool operator!=(const T *s1, const CStringBase<T>& s2)
 552.614 +  { return (s2.Compare(s1) != 0); }
 552.615 +
 552.616 +template <class T>
 552.617 +bool operator!=(const CStringBase<T>& s1, const T *s2)
 552.618 +  { return (s1.Compare(s2) != 0); }
 552.619 +
 552.620 +typedef CStringBase<char> AString;
 552.621 +typedef CStringBase<wchar_t> UString;
 552.622 +
 552.623 +typedef CObjectVector<AString> AStringVector;
 552.624 +typedef CObjectVector<UString> UStringVector;
 552.625 +
 552.626 +#ifdef _UNICODE
 552.627 +  typedef UString CSysString;
 552.628 +#else
 552.629 +  typedef AString CSysString;
 552.630 +#endif
 552.631 +
 552.632 +typedef CObjectVector<CSysString> CSysStringVector;
 552.633 +
 552.634 +#endif
   553.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   553.2 +++ b/src/win32/7zip/7z/CPP/Common/MyUnknown.h	Sat Mar 03 10:31:27 2012 -0600
   553.3 @@ -0,0 +1,24 @@
   553.4 +// MyUnknown.h
   553.5 +
   553.6 +#ifndef __MYUNKNOWN_H
   553.7 +#define __MYUNKNOWN_H
   553.8 +
   553.9 +#ifdef _WIN32
  553.10 +
  553.11 +#ifdef _WIN32_WCE
  553.12 +#if (_WIN32_WCE > 300)
  553.13 +#include <basetyps.h>
  553.14 +#else
  553.15 +#define MIDL_INTERFACE(x) struct
  553.16 +#endif
  553.17 +#else
  553.18 +#include <basetyps.h>
  553.19 +#endif
  553.20 +
  553.21 +#include <unknwn.h>
  553.22 +
  553.23 +#else
  553.24 +#include "MyWindows.h"
  553.25 +#endif
  553.26 +  
  553.27 +#endif
   554.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   554.2 +++ b/src/win32/7zip/7z/CPP/Common/MyVector.cpp	Sat Mar 03 10:31:27 2012 -0600
   554.3 @@ -0,0 +1,90 @@
   554.4 +// Common/MyVector.cpp
   554.5 +
   554.6 +#include "StdAfx.h"
   554.7 +
   554.8 +#include <string.h>
   554.9 +
  554.10 +#include "MyVector.h"
  554.11 +
  554.12 +CBaseRecordVector::~CBaseRecordVector() { ClearAndFree(); }
  554.13 +
  554.14 +void CBaseRecordVector::ClearAndFree()
  554.15 +{
  554.16 +  Clear();
  554.17 +  delete []((unsigned char *)_items);
  554.18 +  _capacity = 0;
  554.19 +  _size = 0;
  554.20 +  _items = 0;
  554.21 +}
  554.22 +
  554.23 +void CBaseRecordVector::Clear() { DeleteFrom(0); }
  554.24 +void CBaseRecordVector::DeleteBack() { Delete(_size - 1); }
  554.25 +void CBaseRecordVector::DeleteFrom(int index)
  554.26 +{
  554.27 +	Delete(index, _size - index);
  554.28 +}
  554.29 +
  554.30 +void CBaseRecordVector::ReserveOnePosition()
  554.31 +{
  554.32 +  if (_size != _capacity)
  554.33 +    return;
  554.34 +  int delta = 1;
  554.35 +  if (_capacity >= 64)
  554.36 +    delta = _capacity / 4;
  554.37 +  else if (_capacity >= 8)
  554.38 +    delta = 8;
  554.39 +  Reserve(_capacity + delta);
  554.40 +}
  554.41 +
  554.42 +void CBaseRecordVector::Reserve(int newCapacity)
  554.43 +{
  554.44 +  // if (newCapacity <= _capacity)
  554.45 +  if (newCapacity == _capacity)
  554.46 +    return;
  554.47 +  if ((unsigned)newCapacity >= ((unsigned)1 << (sizeof(unsigned) * 8 - 1)))
  554.48 +    throw 1052353;
  554.49 +  size_t newSize = (size_t)(unsigned)newCapacity * _itemSize;
  554.50 +  if (newSize / _itemSize != (size_t)(unsigned)newCapacity)
  554.51 +    throw 1052354;
  554.52 +  unsigned char *p = NULL;
  554.53 +  if (newSize > 0)
  554.54 +  {
  554.55 +    p = new unsigned char[newSize];
  554.56 +    if (p == 0)
  554.57 +      throw 1052355;
  554.58 +    int numRecordsToMove = (_size < newCapacity ? _size : newCapacity);
  554.59 +    memcpy(p, _items, _itemSize * numRecordsToMove);
  554.60 +  }
  554.61 +  delete [](unsigned char *)_items;
  554.62 +  _items = p;
  554.63 +  _capacity = newCapacity;
  554.64 +}
  554.65 +
  554.66 +void CBaseRecordVector::ReserveDown()
  554.67 +{
  554.68 +  Reserve(_size);
  554.69 +}
  554.70 +
  554.71 +void CBaseRecordVector::MoveItems(int destIndex, int srcIndex)
  554.72 +{
  554.73 +  memmove(((unsigned char *)_items) + destIndex * _itemSize,
  554.74 +    ((unsigned char  *)_items) + srcIndex * _itemSize,
  554.75 +    _itemSize * (_size - srcIndex));
  554.76 +}
  554.77 +
  554.78 +void CBaseRecordVector::InsertOneItem(int index)
  554.79 +{
  554.80 +  ReserveOnePosition();
  554.81 +  MoveItems(index + 1, index);
  554.82 +  _size++;
  554.83 +}
  554.84 +
  554.85 +void CBaseRecordVector::Delete(int index, int num)
  554.86 +{
  554.87 +  TestIndexAndCorrectNum(index, num);
  554.88 +  if (num > 0)
  554.89 +  {
  554.90 +    MoveItems(index, index + num);
  554.91 +    _size -= num;
  554.92 +  }
  554.93 +}
   555.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   555.2 +++ b/src/win32/7zip/7z/CPP/Common/MyVector.h	Sat Mar 03 10:31:27 2012 -0600
   555.3 @@ -0,0 +1,256 @@
   555.4 +// Common/Vector.h
   555.5 +
   555.6 +#ifndef __COMMON_VECTOR_H
   555.7 +#define __COMMON_VECTOR_H
   555.8 +
   555.9 +#include "Defs.h"
  555.10 +
  555.11 +class CBaseRecordVector
  555.12 +{
  555.13 +  void MoveItems(int destIndex, int srcIndex);
  555.14 +protected:
  555.15 +  int _capacity;
  555.16 +  int _size;
  555.17 +  void *_items;
  555.18 +  size_t _itemSize;
  555.19 +  
  555.20 +  void ReserveOnePosition();
  555.21 +  void InsertOneItem(int index);
  555.22 +  void TestIndexAndCorrectNum(int index, int &num) const
  555.23 +    { if (index + num > _size) num = _size - index; }
  555.24 +public:
  555.25 +  CBaseRecordVector(size_t itemSize): _capacity(0), _size(0), _items(0), _itemSize(itemSize) {}
  555.26 +  virtual ~CBaseRecordVector();
  555.27 +  void ClearAndFree();
  555.28 +  int Size() const { return _size; }
  555.29 +  bool IsEmpty() const { return (_size == 0); }
  555.30 +  void Reserve(int newCapacity);
  555.31 +  void ReserveDown();
  555.32 +  virtual void Delete(int index, int num = 1);
  555.33 +  void Clear();
  555.34 +  void DeleteFrom(int index);
  555.35 +  void DeleteBack();
  555.36 +};
  555.37 +
  555.38 +template <class T>
  555.39 +class CRecordVector: public CBaseRecordVector
  555.40 +{
  555.41 +public:
  555.42 +  CRecordVector(): CBaseRecordVector(sizeof(T)){};
  555.43 +  CRecordVector(const CRecordVector &v): CBaseRecordVector(sizeof(T)) { *this = v; }
  555.44 +  CRecordVector& operator=(const CRecordVector &v)
  555.45 +  {
  555.46 +    Clear();
  555.47 +    return (*this += v);
  555.48 +  }
  555.49 +  CRecordVector& operator+=(const CRecordVector &v)
  555.50 +  {
  555.51 +    int size = v.Size();
  555.52 +    Reserve(Size() + size);
  555.53 +    for (int i = 0; i < size; i++)
  555.54 +      Add(v[i]);
  555.55 +    return *this;
  555.56 +  }
  555.57 +  int Add(T item)
  555.58 +  {
  555.59 +    ReserveOnePosition();
  555.60 +    ((T *)_items)[_size] = item;
  555.61 +    return _size++;
  555.62 +  }
  555.63 +  void Insert(int index, T item)
  555.64 +  {
  555.65 +    InsertOneItem(index);
  555.66 +    ((T *)_items)[index] = item;
  555.67 +  }
  555.68 +  // T* GetPointer() const { return (T*)_items; }
  555.69 +  // operator const T *() const { return _items; };
  555.70 +  const T& operator[](int index) const { return ((T *)_items)[index]; }
  555.71 +  T& operator[](int index) { return ((T *)_items)[index]; }
  555.72 +  const T& Front() const { return operator[](0); }
  555.73 +  T& Front() { return operator[](0); }
  555.74 +  const T& Back() const { return operator[](_size - 1); }
  555.75 +  T& Back() { return operator[](_size - 1); }
  555.76 +
  555.77 +  void Swap(int i, int j)
  555.78 +  {
  555.79 +    T temp = operator[](i);
  555.80 +    operator[](i) = operator[](j);
  555.81 +    operator[](j) = temp;
  555.82 +  }
  555.83 +
  555.84 +  int FindInSorted(const T& item) const
  555.85 +  {
  555.86 +    int left = 0, right = Size();
  555.87 +    while (left != right)
  555.88 +    {
  555.89 +      int mid = (left + right) / 2;
  555.90 +      const T& midValue = (*this)[mid];
  555.91 +      if (item == midValue)
  555.92 +        return mid;
  555.93 +      if (item < midValue)
  555.94 +        right = mid;
  555.95 +      else
  555.96 +        left = mid + 1;
  555.97 +    }
  555.98 +    return -1;
  555.99 +  }
 555.100 +
 555.101 +  int AddToUniqueSorted(const T& item)
 555.102 +  {
 555.103 +    int left = 0, right = Size();
 555.104 +    while (left != right)
 555.105 +    {
 555.106 +      int mid = (left + right) / 2;
 555.107 +      const T& midValue = (*this)[mid];
 555.108 +      if (item == midValue)
 555.109 +        return mid;
 555.110 +      if (item < midValue)
 555.111 +        right = mid;
 555.112 +      else
 555.113 +        left = mid + 1;
 555.114 +    }
 555.115 +    Insert(right, item);
 555.116 +    return right;
 555.117 +  }
 555.118 +
 555.119 +  static void SortRefDown(T* p, int k, int size, int (*compare)(const T*, const T*, void *), void *param)
 555.120 +  {
 555.121 +    T temp = p[k];
 555.122 +    for (;;)
 555.123 +    {
 555.124 +      int s = (k << 1);
 555.125 +      if (s > size)
 555.126 +        break;
 555.127 +      if (s < size && compare(p + s + 1, p + s, param) > 0)
 555.128 +        s++;
 555.129 +      if (compare(&temp, p + s, param) >= 0)
 555.130 +        break;
 555.131 +      p[k] = p[s];
 555.132 +      k = s;
 555.133 +    }
 555.134 +    p[k] = temp;
 555.135 +  }
 555.136 +
 555.137 +  void Sort(int (*compare)(const T*, const T*, void *), void *param)
 555.138 +  {
 555.139 +    int size = _size;
 555.140 +    if (size <= 1)
 555.141 +      return;
 555.142 +    T* p = (&Front()) - 1;
 555.143 +    {
 555.144 +      int i = size / 2;
 555.145 +      do
 555.146 +        SortRefDown(p, i, size, compare, param);
 555.147 +      while (--i != 0);
 555.148 +    }
 555.149 +    do
 555.150 +    {
 555.151 +      T temp = p[size];
 555.152 +      p[size--] = p[1];
 555.153 +      p[1] = temp;
 555.154 +      SortRefDown(p, 1, size, compare, param);
 555.155 +    }
 555.156 +    while (size > 1);
 555.157 +  }
 555.158 +};
 555.159 +
 555.160 +typedef CRecordVector<int> CIntVector;
 555.161 +typedef CRecordVector<unsigned int> CUIntVector;
 555.162 +typedef CRecordVector<bool> CBoolVector;
 555.163 +typedef CRecordVector<unsigned char> CByteVector;
 555.164 +typedef CRecordVector<void *> CPointerVector;
 555.165 +
 555.166 +template <class T>
 555.167 +class CObjectVector: public CPointerVector
 555.168 +{
 555.169 +public:
 555.170 +  CObjectVector() {};
 555.171 +  ~CObjectVector() { Clear(); };
 555.172 +  CObjectVector(const CObjectVector &v) { *this = v; }
 555.173 +  CObjectVector& operator=(const CObjectVector &v)
 555.174 +  {
 555.175 +    Clear();
 555.176 +    return (*this += v);
 555.177 +  }
 555.178 +  CObjectVector& operator+=(const CObjectVector &v)
 555.179 +  {
 555.180 +    int size = v.Size();
 555.181 +    Reserve(Size() + size);
 555.182 +    for (int i = 0; i < size; i++)
 555.183 +      Add(v[i]);
 555.184 +    return *this;
 555.185 +  }
 555.186 +  const T& operator[](int index) const
 555.187 +  {
 555.188 +	  return *((T *)CPointerVector::operator[](index));
 555.189 +  }
 555.190 +  T& operator[](int index)
 555.191 +  {
 555.192 +	  return *((T *)CPointerVector::operator[](index));
 555.193 +  }
 555.194 +  T& Front() { return operator[](0); }
 555.195 +  const T& Front() const { return operator[](0); }
 555.196 +  T& Back() { return operator[](_size - 1); }
 555.197 +  const T& Back() const { return operator[](_size - 1); }
 555.198 +  int Add(const T& item) { return CPointerVector::Add(new T(item)); }
 555.199 +  void Insert(int index, const T& item) { CPointerVector::Insert(index, new T(item)); }
 555.200 +  virtual void Delete(int index, int num = 1)
 555.201 +  {
 555.202 +    TestIndexAndCorrectNum(index, num);
 555.203 +    for (int i = 0; i < num; i++)
 555.204 +      delete (T *)(((void **)_items)[index + i]);
 555.205 +    CPointerVector::Delete(index, num);
 555.206 +  }
 555.207 +  int Find(const T& item) const
 555.208 +  {
 555.209 +    for (int i = 0; i < Size(); i++)
 555.210 +      if (item == (*this)[i])
 555.211 +        return i;
 555.212 +    return -1;
 555.213 +  }
 555.214 +  int FindInSorted(const T& item) const
 555.215 +  {
 555.216 +    int left = 0, right = Size();
 555.217 +    while (left != right)
 555.218 +    {
 555.219 +      int mid = (left + right) / 2;
 555.220 +      const T& midValue = (*this)[mid];
 555.221 +      if (item == midValue)
 555.222 +        return mid;
 555.223 +      if (item < midValue)
 555.224 +        right = mid;
 555.225 +      else
 555.226 +        left = mid + 1;
 555.227 +    }
 555.228 +    return -1;
 555.229 +  }
 555.230 +  int AddToSorted(const T& item)
 555.231 +  {
 555.232 +    int left = 0, right = Size();
 555.233 +    while (left != right)
 555.234 +    {
 555.235 +      int mid = (left + right) / 2;
 555.236 +      const T& midValue = (*this)[mid];
 555.237 +      if (item == midValue)
 555.238 +      {
 555.239 +        right = mid + 1;
 555.240 +        break;
 555.241 +      }
 555.242 +      if (item < midValue)
 555.243 +        right = mid;
 555.244 +      else
 555.245 +        left = mid + 1;
 555.246 +    }
 555.247 +    Insert(right, item);
 555.248 +    return right;
 555.249 +  }
 555.250 +
 555.251 +  void Sort(int (*compare)(void *const *, void *const *, void *), void *param)
 555.252 +    { CPointerVector::Sort(compare, param); }
 555.253 +
 555.254 +  static int CompareObjectItems(void *const *a1, void *const *a2, void * /* param */)
 555.255 +    { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }
 555.256 +  void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }
 555.257 +};
 555.258 +
 555.259 +#endif
   556.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   556.2 +++ b/src/win32/7zip/7z/CPP/Common/MyWindows.h	Sat Mar 03 10:31:27 2012 -0600
   556.3 @@ -0,0 +1,214 @@
   556.4 +// MyWindows.h
   556.5 +
   556.6 +#ifndef __MYWINDOWS_H
   556.7 +#define __MYWINDOWS_H
   556.8 +
   556.9 +#ifdef _WIN32
  556.10 +
  556.11 +#include <windows.h>
  556.12 +
  556.13 +#define CHAR_PATH_SEPARATOR '\\'
  556.14 +#define WCHAR_PATH_SEPARATOR L'\\'
  556.15 +#define STRING_PATH_SEPARATOR "\\"
  556.16 +#define WSTRING_PATH_SEPARATOR L"\\"
  556.17 +
  556.18 +#else
  556.19 +
  556.20 +#define CHAR_PATH_SEPARATOR '/'
  556.21 +#define WCHAR_PATH_SEPARATOR L'/'
  556.22 +#define STRING_PATH_SEPARATOR "/"
  556.23 +#define WSTRING_PATH_SEPARATOR L"/"
  556.24 +
  556.25 +#include <stddef.h> // for wchar_t
  556.26 +#include <string.h>
  556.27 +
  556.28 +#include "MyGuidDef.h"
  556.29 +
  556.30 +typedef char CHAR;
  556.31 +typedef unsigned char UCHAR;
  556.32 +
  556.33 +#undef BYTE
  556.34 +typedef unsigned char BYTE;
  556.35 +
  556.36 +typedef short SHORT;
  556.37 +typedef unsigned short USHORT;
  556.38 +
  556.39 +#undef WORD
  556.40 +typedef unsigned short WORD;
  556.41 +typedef short VARIANT_BOOL;
  556.42 +
  556.43 +typedef int INT;
  556.44 +typedef Int32 INT32;
  556.45 +typedef unsigned int UINT;
  556.46 +typedef UInt32 UINT32;
  556.47 +typedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit
  556.48 +typedef UINT32 ULONG;
  556.49 +
  556.50 +#undef DWORD
  556.51 +typedef UINT32 DWORD;
  556.52 +
  556.53 +typedef Int64 LONGLONG;
  556.54 +typedef UInt64 ULONGLONG;
  556.55 +
  556.56 +typedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;
  556.57 +typedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;
  556.58 +
  556.59 +typedef const CHAR *LPCSTR;
  556.60 +typedef CHAR TCHAR;
  556.61 +typedef const TCHAR *LPCTSTR;
  556.62 +typedef wchar_t WCHAR;
  556.63 +typedef WCHAR OLECHAR;
  556.64 +typedef const WCHAR *LPCWSTR;
  556.65 +typedef OLECHAR *BSTR;
  556.66 +typedef const OLECHAR *LPCOLESTR;
  556.67 +typedef OLECHAR *LPOLESTR;
  556.68 +
  556.69 +typedef struct _FILETIME
  556.70 +{
  556.71 +  DWORD dwLowDateTime;
  556.72 +  DWORD dwHighDateTime;
  556.73 +}FILETIME;
  556.74 +
  556.75 +#define HRESULT LONG
  556.76 +#define FAILED(Status) ((HRESULT)(Status)<0)
  556.77 +typedef ULONG PROPID;
  556.78 +typedef LONG SCODE;
  556.79 +
  556.80 +#define S_OK    ((HRESULT)0x00000000L)
  556.81 +#define S_FALSE ((HRESULT)0x00000001L)
  556.82 +#define E_NOTIMPL ((HRESULT)0x80004001L)
  556.83 +#define E_NOINTERFACE ((HRESULT)0x80004002L)
  556.84 +#define E_ABORT ((HRESULT)0x80004004L)
  556.85 +#define E_FAIL ((HRESULT)0x80004005L)
  556.86 +#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)
  556.87 +#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
  556.88 +#define E_INVALIDARG ((HRESULT)0x80070057L)
  556.89 +
  556.90 +#ifdef _MSC_VER
  556.91 +#define STDMETHODCALLTYPE __stdcall
  556.92 +#else
  556.93 +#define STDMETHODCALLTYPE
  556.94 +#endif
  556.95 +
  556.96 +#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f
  556.97 +#define STDMETHOD(f) STDMETHOD_(HRESULT, f)
  556.98 +#define STDMETHODIMP_(type) type STDMETHODCALLTYPE
  556.99 +#define STDMETHODIMP STDMETHODIMP_(HRESULT)
 556.100 +
 556.101 +#define PURE = 0
 556.102 +
 556.103 +#define MIDL_INTERFACE(x) struct
 556.104 +
 556.105 +#ifdef __cplusplus
 556.106 +
 556.107 +DEFINE_GUID(IID_IUnknown,
 556.108 +0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
 556.109 +struct IUnknown
 556.110 +{
 556.111 +  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;
 556.112 +  STDMETHOD_(ULONG, AddRef)() PURE;
 556.113 +  STDMETHOD_(ULONG, Release)() PURE;
 556.114 +  #ifndef _WIN32
 556.115 +  virtual ~IUnknown() {}
 556.116 +  #endif
 556.117 +};
 556.118 +
 556.119 +typedef IUnknown *LPUNKNOWN;
 556.120 +
 556.121 +#endif
 556.122 +
 556.123 +#define VARIANT_TRUE ((VARIANT_BOOL)-1)
 556.124 +#define VARIANT_FALSE ((VARIANT_BOOL)0)
 556.125 +
 556.126 +enum VARENUM
 556.127 +{
 556.128 +  VT_EMPTY = 0,
 556.129 +  VT_NULL = 1,
 556.130 +  VT_I2 = 2,
 556.131 +  VT_I4 = 3,
 556.132 +  VT_R4 = 4,
 556.133 +  VT_R8 = 5,
 556.134 +  VT_CY = 6,
 556.135 +  VT_DATE = 7,
 556.136 +  VT_BSTR = 8,
 556.137 +  VT_DISPATCH = 9,
 556.138 +  VT_ERROR = 10,
 556.139 +  VT_BOOL = 11,
 556.140 +  VT_VARIANT = 12,
 556.141 +  VT_UNKNOWN = 13,
 556.142 +  VT_DECIMAL = 14,
 556.143 +  VT_I1 = 16,
 556.144 +  VT_UI1 = 17,
 556.145 +  VT_UI2 = 18,
 556.146 +  VT_UI4 = 19,
 556.147 +  VT_I8 = 20,
 556.148 +  VT_UI8 = 21,
 556.149 +  VT_INT = 22,
 556.150 +  VT_UINT = 23,
 556.151 +  VT_VOID = 24,
 556.152 +  VT_HRESULT = 25,
 556.153 +  VT_FILETIME = 64
 556.154 +};
 556.155 +
 556.156 +typedef unsigned short VARTYPE;
 556.157 +typedef WORD PROPVAR_PAD1;
 556.158 +typedef WORD PROPVAR_PAD2;
 556.159 +typedef WORD PROPVAR_PAD3;
 556.160 +
 556.161 +#ifdef __cplusplus
 556.162 +
 556.163 +typedef struct tagPROPVARIANT
 556.164 +{
 556.165 +  VARTYPE vt;
 556.166 +  PROPVAR_PAD1 wReserved1;
 556.167 +  PROPVAR_PAD2 wReserved2;
 556.168 +  PROPVAR_PAD3 wReserved3;
 556.169 +  union
 556.170 +  {
 556.171 +    CHAR cVal;
 556.172 +    UCHAR bVal;
 556.173 +    SHORT iVal;
 556.174 +    USHORT uiVal;
 556.175 +    LONG lVal;
 556.176 +    ULONG ulVal;
 556.177 +    INT intVal;
 556.178 +    UINT uintVal;
 556.179 +    LARGE_INTEGER hVal;
 556.180 +    ULARGE_INTEGER uhVal;
 556.181 +    VARIANT_BOOL boolVal;
 556.182 +    SCODE scode;
 556.183 +    FILETIME filetime;
 556.184 +    BSTR bstrVal;
 556.185 +  };
 556.186 +} PROPVARIANT;
 556.187 +
 556.188 +typedef PROPVARIANT tagVARIANT;
 556.189 +typedef tagVARIANT VARIANT;
 556.190 +typedef VARIANT VARIANTARG;
 556.191 +
 556.192 +MY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);
 556.193 +MY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);
 556.194 +
 556.195 +#endif
 556.196 +
 556.197 +MY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);
 556.198 +MY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);
 556.199 +MY_EXTERN_C void SysFreeString(BSTR bstr);
 556.200 +MY_EXTERN_C UINT SysStringByteLen(BSTR bstr);
 556.201 +MY_EXTERN_C UINT SysStringLen(BSTR bstr);
 556.202 +
 556.203 +MY_EXTERN_C DWORD GetLastError();
 556.204 +MY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);
 556.205 +
 556.206 +#define CP_ACP    0
 556.207 +#define CP_OEMCP  1
 556.208 +
 556.209 +typedef enum tagSTREAM_SEEK
 556.210 +{
 556.211 +  STREAM_SEEK_SET = 0,
 556.212 +  STREAM_SEEK_CUR = 1,
 556.213 +  STREAM_SEEK_END = 2
 556.214 +} STREAM_SEEK;
 556.215 +
 556.216 +#endif
 556.217 +#endif
   557.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   557.2 +++ b/src/win32/7zip/7z/CPP/Common/MyXml.cpp	Sat Mar 03 10:31:27 2012 -0600
   557.3 @@ -0,0 +1,209 @@
   557.4 +// MyXml.cpp
   557.5 +
   557.6 +#include "StdAfx.h"
   557.7 +
   557.8 +#include "MyXml.h"
   557.9 +
  557.10 +static bool IsValidChar(char c)
  557.11 +{
  557.12 +  return
  557.13 +    c >= 'a' && c <= 'z' ||
  557.14 +    c >= 'A' && c <= 'Z' ||
  557.15 +    c >= '0' && c <= '9' ||
  557.16 +    c == '-';
  557.17 +}
  557.18 +
  557.19 +static bool IsSpaceChar(char c)
  557.20 +{
  557.21 +  return (c == ' ' || c == '\t' || c == 0x0D || c == 0x0A);
  557.22 +}
  557.23 +
  557.24 +#define SKEEP_SPACES(s, pos) while (IsSpaceChar(s[pos])) pos++;
  557.25 +
  557.26 +static bool ReadProperty(const AString &s, int &pos, CXmlProp &prop)
  557.27 +{
  557.28 +  prop.Name.Empty();
  557.29 +  prop.Value.Empty();
  557.30 +  for (; pos < s.Length(); pos++)
  557.31 +  {
  557.32 +    char c = s[pos];
  557.33 +    if (!IsValidChar(c))
  557.34 +      break;
  557.35 +    prop.Name += c;
  557.36 +  }
  557.37 +  
  557.38 +  if (prop.Name.IsEmpty())
  557.39 +    return false;
  557.40 +
  557.41 +  SKEEP_SPACES(s, pos);
  557.42 +  if (s[pos++] != '=')
  557.43 +    return false;
  557.44 +
  557.45 +  SKEEP_SPACES(s, pos);
  557.46 +  if (s[pos++] != '\"')
  557.47 +    return false;
  557.48 +  
  557.49 +  while (pos < s.Length())
  557.50 +  {
  557.51 +    char c = s[pos++];
  557.52 +    if (c == '\"')
  557.53 +      return true;
  557.54 +    prop.Value += c;
  557.55 +  }
  557.56 +  return false;
  557.57 +}
  557.58 +
  557.59 +int CXmlItem::FindProperty(const AString &propName) const
  557.60 +{
  557.61 +  for (int i = 0; i < Props.Size(); i++)
  557.62 +    if (Props[i].Name == propName)
  557.63 +      return i;
  557.64 +  return -1;
  557.65 +}
  557.66 +
  557.67 +AString CXmlItem::GetPropertyValue(const AString &propName) const
  557.68 +{
  557.69 +  int index = FindProperty(propName);
  557.70 +  if (index >= 0)
  557.71 +    return Props[index].Value;
  557.72 +  return AString();
  557.73 +}
  557.74 +
  557.75 +bool CXmlItem::IsTagged(const AString &tag) const
  557.76 +{
  557.77 +  return (IsTag && Name == tag);
  557.78 +}
  557.79 +
  557.80 +int CXmlItem::FindSubTag(const AString &tag) const
  557.81 +{
  557.82 +  for (int i = 0; i < SubItems.Size(); i++)
  557.83 +    if (SubItems[i].IsTagged(tag))
  557.84 +      return i;
  557.85 +  return -1;
  557.86 +}
  557.87 +
  557.88 +AString CXmlItem::GetSubString() const
  557.89 +{
  557.90 +  if (SubItems.Size() == 1)
  557.91 +  {
  557.92 +    const CXmlItem &item = SubItems[0];
  557.93 +    if (!item.IsTag)
  557.94 +      return item.Name;
  557.95 +  }
  557.96 +  return AString();
  557.97 +}
  557.98 +
  557.99 +AString CXmlItem::GetSubStringForTag(const AString &tag) const
 557.100 +{
 557.101 +  int index = FindSubTag(tag);
 557.102 +  if (index >= 0)
 557.103 +    return SubItems[index].GetSubString();
 557.104 +  return AString();
 557.105 +}
 557.106 +
 557.107 +bool CXmlItem::ParseItems(const AString &s, int &pos, int numAllowedLevels)
 557.108 +{
 557.109 +  if (numAllowedLevels == 0)
 557.110 +    return false;
 557.111 +  SubItems.Clear();
 557.112 +  AString finishString = "</";
 557.113 +  for (;;)
 557.114 +  {
 557.115 +    SKEEP_SPACES(s, pos);
 557.116 +
 557.117 +    if (s.Mid(pos, finishString.Length()) == finishString)
 557.118 +      return true;
 557.119 +      
 557.120 +    CXmlItem item;
 557.121 +    if (!item.ParseItem(s, pos, numAllowedLevels - 1))
 557.122 +      return false;
 557.123 +    SubItems.Add(item);
 557.124 +  }
 557.125 +}
 557.126 +
 557.127 +bool CXmlItem::ParseItem(const AString &s, int &pos, int numAllowedLevels)
 557.128 +{
 557.129 +  SKEEP_SPACES(s, pos);
 557.130 +
 557.131 +  int pos2 = s.Find('<', pos);
 557.132 +  if (pos2 < 0)
 557.133 +    return false;
 557.134 +  if (pos2 != pos)
 557.135 +  {
 557.136 +    IsTag = false;
 557.137 +    Name += s.Mid(pos, pos2 - pos);
 557.138 +    pos = pos2;
 557.139 +    return true;
 557.140 +  }
 557.141 +  IsTag = true;
 557.142 +
 557.143 +  pos++;
 557.144 +  SKEEP_SPACES(s, pos);
 557.145 +
 557.146 +  for (; pos < s.Length(); pos++)
 557.147 +  {
 557.148 +    char c = s[pos];
 557.149 +    if (!IsValidChar(c))
 557.150 +      break;
 557.151 +    Name += c;
 557.152 +  }
 557.153 +  if (Name.IsEmpty() || pos == s.Length())
 557.154 +    return false;
 557.155 +
 557.156 +  int posTemp = pos;
 557.157 +  for (;;)
 557.158 +  {
 557.159 +    SKEEP_SPACES(s, pos);
 557.160 +    if (s[pos] == '/')
 557.161 +    {
 557.162 +      pos++;
 557.163 +      // SKEEP_SPACES(s, pos);
 557.164 +      return (s[pos++] == '>');
 557.165 +    }
 557.166 +    if (s[pos] == '>')
 557.167 +    {
 557.168 +      if (!ParseItems(s, ++pos, numAllowedLevels))
 557.169 +        return false;
 557.170 +      AString finishString = AString("</") + Name + AString(">");
 557.171 +      if (s.Mid(pos, finishString.Length()) != finishString)
 557.172 +        return false;
 557.173 +      pos += finishString.Length();
 557.174 +      return true;
 557.175 +    }
 557.176 +    if (posTemp == pos)
 557.177 +      return false;
 557.178 +
 557.179 +    CXmlProp prop;
 557.180 +    if (!ReadProperty(s, pos, prop))
 557.181 +      return false;
 557.182 +    Props.Add(prop);
 557.183 +    posTemp = pos;
 557.184 +  }
 557.185 +}
 557.186 +
 557.187 +bool SkeepHeader(const AString &s, int &pos, const AString &startString, const AString &endString)
 557.188 +{
 557.189 +  SKEEP_SPACES(s, pos);
 557.190 +  if (s.Mid(pos, startString.Length()) == startString)
 557.191 +  {
 557.192 +    pos = s.Find(endString, pos);
 557.193 +    if (pos < 0)
 557.194 +      return false;
 557.195 +    pos += endString.Length();
 557.196 +    SKEEP_SPACES(s, pos);
 557.197 +  }
 557.198 +  return true;
 557.199 +}
 557.200 +
 557.201 +bool CXml::Parse(const AString &s)
 557.202 +{
 557.203 +  int pos = 0;
 557.204 +  if (!SkeepHeader(s, pos, "<?xml", "?>"))
 557.205 +    return false;
 557.206 +  if (!SkeepHeader(s, pos, "<!DOCTYPE", ">"))
 557.207 +    return false;
 557.208 +  if (!Root.ParseItem(s, pos, 1000))
 557.209 +    return false;
 557.210 +  SKEEP_SPACES(s, pos);
 557.211 +  return (pos == s.Length() && Root.IsTag);
 557.212 +}
   558.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   558.2 +++ b/src/win32/7zip/7z/CPP/Common/MyXml.h	Sat Mar 03 10:31:27 2012 -0600
   558.3 @@ -0,0 +1,40 @@
   558.4 +// MyXml.h
   558.5 +
   558.6 +#ifndef __MYXML_H
   558.7 +#define __MYXML_H
   558.8 +
   558.9 +#include "MyString.h"
  558.10 +
  558.11 +struct CXmlProp
  558.12 +{
  558.13 +  AString Name;
  558.14 +  AString Value;
  558.15 +};
  558.16 +
  558.17 +class CXmlItem
  558.18 +{
  558.19 +  bool ParseItems(const AString &s, int &pos, int numAllowedLevels);
  558.20 +
  558.21 +public:
  558.22 +  AString Name;
  558.23 +  bool IsTag;
  558.24 +  CObjectVector<CXmlProp> Props;
  558.25 +  CObjectVector<CXmlItem> SubItems;
  558.26 +
  558.27 +  bool ParseItem(const AString &s, int &pos, int numAllowedLevels);
  558.28 +  
  558.29 +  bool IsTagged(const AString &tag) const;
  558.30 +  int FindProperty(const AString &propName) const;
  558.31 +  AString GetPropertyValue(const AString &propName) const;
  558.32 +  AString GetSubString() const;
  558.33 +  int FindSubTag(const AString &tag) const;
  558.34 +  AString GetSubStringForTag(const AString &tag) const;
  558.35 +};
  558.36 +
  558.37 +struct CXml
  558.38 +{
  558.39 +  CXmlItem Root;
  558.40 +  bool Parse(const AString &s);
  558.41 +};
  558.42 +
  558.43 +#endif
   559.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   559.2 +++ b/src/win32/7zip/7z/CPP/Common/NewHandler.cpp	Sat Mar 03 10:31:27 2012 -0600
   559.3 @@ -0,0 +1,116 @@
   559.4 +// NewHandler.cpp
   559.5 + 
   559.6 +#include "StdAfx.h"
   559.7 +
   559.8 +#include <stdlib.h>
   559.9 +
  559.10 +#include "NewHandler.h"
  559.11 +
  559.12 +// #define DEBUG_MEMORY_LEAK
  559.13 +
  559.14 +#ifndef DEBUG_MEMORY_LEAK
  559.15 +
  559.16 +#ifdef _WIN32
  559.17 +void *
  559.18 +#ifdef _MSC_VER
  559.19 +__cdecl
  559.20 +#endif
  559.21 +operator new(size_t size)
  559.22 +{
  559.23 +  // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size);
  559.24 +  void *p = ::malloc(size);
  559.25 +  if (p == 0)
  559.26 +    throw CNewException();
  559.27 +  return p;
  559.28 +}
  559.29 +
  559.30 +void
  559.31 +#ifdef _MSC_VER
  559.32 +__cdecl
  559.33 +#endif
  559.34 +operator delete(void *p) throw()
  559.35 +{
  559.36 +  /*
  559.37 +  if (p == 0)
  559.38 +    return;
  559.39 +  ::HeapFree(::GetProcessHeap(), 0, p);
  559.40 +  */
  559.41 +  ::free(p);
  559.42 +}
  559.43 +#endif
  559.44 +
  559.45 +#else
  559.46 +
  559.47 +#pragma init_seg(lib)
  559.48 +const int kDebugSize = 1000000;
  559.49 +static void *a[kDebugSize];
  559.50 +static int index = 0;
  559.51 +
  559.52 +static int numAllocs = 0;
  559.53 +void * __cdecl operator new(size_t size)
  559.54 +{
  559.55 +  numAllocs++;
  559.56 +  void *p = HeapAlloc(GetProcessHeap(), 0, size);
  559.57 +  if (index == 40)
  559.58 +  {
  559.59 +    int t = 1;
  559.60 +  }
  559.61 +  if (index < kDebugSize)
  559.62 +  {
  559.63 +    a[index] = p;
  559.64 +    index++;
  559.65 +  }
  559.66 +  if (p == 0)
  559.67 +    throw CNewException();
  559.68 +  printf("Alloc %6d, size = %8d\n", numAllocs, size);
  559.69 +  return p;
  559.70 +}
  559.71 +
  559.72 +class CC
  559.73 +{
  559.74 +public:
  559.75 +  CC()
  559.76 +  {
  559.77 +    for (int i = 0; i < kDebugSize; i++)
  559.78 +      a[i] = 0;
  559.79 +  }
  559.80 +  ~CC()
  559.81 +  {
  559.82 +    for (int i = 0; i < kDebugSize; i++)
  559.83 +      if (a[i] != 0)
  559.84 +        return;
  559.85 +  }
  559.86 +} g_CC;
  559.87 +
  559.88 +
  559.89 +void __cdecl operator delete(void *p)
  559.90 +{
  559.91 +  if (p == 0)
  559.92 +    return;
  559.93 +  /*
  559.94 +  for (int i = 0; i < index; i++)
  559.95 +    if (a[i] == p)
  559.96 +      a[i] = 0;
  559.97 +  */
  559.98 +  HeapFree(GetProcessHeap(), 0, p);
  559.99 +  numAllocs--;
 559.100 +  printf("Free %d\n", numAllocs);
 559.101 +}
 559.102 +
 559.103 +#endif
 559.104 +
 559.105 +/*
 559.106 +int MemErrorVC(size_t)
 559.107 +{
 559.108 +  throw CNewException();
 559.109 +  // return 1;
 559.110 +}
 559.111 +CNewHandlerSetter::CNewHandlerSetter()
 559.112 +{
 559.113 +  // MemErrorOldVCFunction = _set_new_handler(MemErrorVC);
 559.114 +}
 559.115 +CNewHandlerSetter::~CNewHandlerSetter()
 559.116 +{
 559.117 +  // _set_new_handler(MemErrorOldVCFunction);
 559.118 +}
 559.119 +*/
   560.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   560.2 +++ b/src/win32/7zip/7z/CPP/Common/NewHandler.h	Sat Mar 03 10:31:27 2012 -0600
   560.3 @@ -0,0 +1,16 @@
   560.4 +// Common/NewHandler.h
   560.5 +
   560.6 +#ifndef __COMMON_NEWHANDLER_H
   560.7 +#define __COMMON_NEWHANDLER_H
   560.8 +
   560.9 +class CNewException {};
  560.10 +
  560.11 +#ifdef _WIN32
  560.12 +void
  560.13 +#ifdef _MSC_VER
  560.14 +__cdecl
  560.15 +#endif
  560.16 +operator delete(void *p) throw();
  560.17 +#endif
  560.18 +
  560.19 +#endif
   561.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   561.2 +++ b/src/win32/7zip/7z/CPP/Common/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   561.3 @@ -0,0 +1,9 @@
   561.4 +// StdAfx.h
   561.5 +
   561.6 +#ifndef __STDAFX_H
   561.7 +#define __STDAFX_H
   561.8 +
   561.9 +#include "MyWindows.h"
  561.10 +#include "NewHandler.h"
  561.11 +
  561.12 +#endif
   562.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   562.2 +++ b/src/win32/7zip/7z/CPP/Common/StringConvert.cpp	Sat Mar 03 10:31:27 2012 -0600
   562.3 @@ -0,0 +1,102 @@
   562.4 +// Common/StringConvert.cpp
   562.5 +
   562.6 +#include "StdAfx.h"
   562.7 +
   562.8 +#include "StringConvert.h"
   562.9 +
  562.10 +#ifndef _WIN32
  562.11 +#include <stdlib.h>
  562.12 +#endif
  562.13 +
  562.14 +#ifdef _WIN32
  562.15 +UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)
  562.16 +{
  562.17 +  UString resultString;
  562.18 +  if (!srcString.IsEmpty())
  562.19 +  {
  562.20 +    int numChars = MultiByteToWideChar(codePage, 0, srcString,
  562.21 +      srcString.Length(), resultString.GetBuffer(srcString.Length()),
  562.22 +      srcString.Length() + 1);
  562.23 +    #ifndef _WIN32_WCE
  562.24 +    if (numChars == 0)
  562.25 +      throw 282228;
  562.26 +    #endif
  562.27 +    resultString.ReleaseBuffer(numChars);
  562.28 +  }
  562.29 +  return resultString;
  562.30 +}
  562.31 +
  562.32 +AString UnicodeStringToMultiByte(const UString &s, UINT codePage, char defaultChar, bool &defaultCharWasUsed)
  562.33 +{
  562.34 +  AString dest;
  562.35 +  defaultCharWasUsed = false;
  562.36 +  if (!s.IsEmpty())
  562.37 +  {
  562.38 +    int numRequiredBytes = s.Length() * 2;
  562.39 +    BOOL defUsed;
  562.40 +    int numChars = WideCharToMultiByte(codePage, 0, s, s.Length(),
  562.41 +        dest.GetBuffer(numRequiredBytes), numRequiredBytes + 1,
  562.42 +        &defaultChar, &defUsed);
  562.43 +    defaultCharWasUsed = (defUsed != FALSE);
  562.44 +    #ifndef _WIN32_WCE
  562.45 +    if (numChars == 0)
  562.46 +      throw 282229;
  562.47 +    #endif
  562.48 +    dest.ReleaseBuffer(numChars);
  562.49 +  }
  562.50 +  return dest;
  562.51 +}
  562.52 +
  562.53 +AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)
  562.54 +{
  562.55 +  bool defaultCharWasUsed;
  562.56 +  return UnicodeStringToMultiByte(srcString, codePage, '_', defaultCharWasUsed);
  562.57 +}
  562.58 +
  562.59 +#ifndef _WIN32_WCE
  562.60 +AString SystemStringToOemString(const CSysString &srcString)
  562.61 +{
  562.62 +  AString result;
  562.63 +  CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));
  562.64 +  result.ReleaseBuffer();
  562.65 +  return result;
  562.66 +}
  562.67 +#endif
  562.68 +
  562.69 +#else
  562.70 +
  562.71 +UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)
  562.72 +{
  562.73 +  UString resultString;
  562.74 +  for (int i = 0; i < srcString.Length(); i++)
  562.75 +    resultString += wchar_t(srcString[i]);
  562.76 +  /*
  562.77 +  if (!srcString.IsEmpty())
  562.78 +  {
  562.79 +    int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);
  562.80 +    if (numChars < 0) throw "Your environment does not support UNICODE";
  562.81 +    resultString.ReleaseBuffer(numChars);
  562.82 +  }
  562.83 +  */
  562.84 +  return resultString;
  562.85 +}
  562.86 +
  562.87 +AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)
  562.88 +{
  562.89 +  AString resultString;
  562.90 +  for (int i = 0; i < srcString.Length(); i++)
  562.91 +    resultString += char(srcString[i]);
  562.92 +  /*
  562.93 +  if (!srcString.IsEmpty())
  562.94 +  {
  562.95 +    int numRequiredBytes = srcString.Length() * 6 + 1;
  562.96 +    int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);
  562.97 +    if (numChars < 0) throw "Your environment does not support UNICODE";
  562.98 +    resultString.ReleaseBuffer(numChars);
  562.99 +  }
 562.100 +  */
 562.101 +  return resultString;
 562.102 +}
 562.103 +
 562.104 +#endif
 562.105 +
   563.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   563.2 +++ b/src/win32/7zip/7z/CPP/Common/StringConvert.h	Sat Mar 03 10:31:27 2012 -0600
   563.3 @@ -0,0 +1,73 @@
   563.4 +// Common/StringConvert.h
   563.5 +
   563.6 +#ifndef __COMMON_STRINGCONVERT_H
   563.7 +#define __COMMON_STRINGCONVERT_H
   563.8 +
   563.9 +#include "MyWindows.h"
  563.10 +#include "MyString.h"
  563.11 +#include "Types.h"
  563.12 +
  563.13 +UString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);
  563.14 +AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage, char defaultChar, bool &defaultCharWasUsed);
  563.15 +AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);
  563.16 +
  563.17 +
  563.18 +inline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)
  563.19 +  { return unicodeString; }
  563.20 +inline const UString& GetUnicodeString(const UString &unicodeString)
  563.21 +  { return unicodeString; }
  563.22 +inline UString GetUnicodeString(const AString &ansiString)
  563.23 +  { return MultiByteToUnicodeString(ansiString); }
  563.24 +inline UString GetUnicodeString(const AString &multiByteString, UINT codePage)
  563.25 +  { return MultiByteToUnicodeString(multiByteString, codePage); }
  563.26 +inline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)
  563.27 +  { return unicodeString; }
  563.28 +inline const UString& GetUnicodeString(const UString &unicodeString, UINT)
  563.29 +  { return unicodeString; }
  563.30 +
  563.31 +inline const char* GetAnsiString(const char* ansiString)
  563.32 +  { return ansiString; }
  563.33 +inline const AString& GetAnsiString(const AString &ansiString)
  563.34 +  { return ansiString; }
  563.35 +inline AString GetAnsiString(const UString &unicodeString)
  563.36 +  { return UnicodeStringToMultiByte(unicodeString); }
  563.37 +
  563.38 +inline const char* GetOemString(const char* oemString)
  563.39 +  { return oemString; }
  563.40 +inline const AString& GetOemString(const AString &oemString)
  563.41 +  { return oemString; }
  563.42 +inline AString GetOemString(const UString &unicodeString)
  563.43 +  { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }
  563.44 +
  563.45 +
  563.46 +#ifdef _UNICODE
  563.47 +  inline const wchar_t* GetSystemString(const wchar_t* unicodeString)
  563.48 +    { return unicodeString;}
  563.49 +  inline const UString& GetSystemString(const UString &unicodeString)
  563.50 +    { return unicodeString;}
  563.51 +  inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT /* codePage */)
  563.52 +    { return unicodeString;}
  563.53 +  inline const UString& GetSystemString(const UString &unicodeString, UINT /* codePage */)
  563.54 +    { return unicodeString;}
  563.55 +  inline UString GetSystemString(const AString &multiByteString, UINT codePage)
  563.56 +    { return MultiByteToUnicodeString(multiByteString, codePage);}
  563.57 +  inline UString GetSystemString(const AString &multiByteString)
  563.58 +    { return MultiByteToUnicodeString(multiByteString);}
  563.59 +#else
  563.60 +  inline const char* GetSystemString(const char *ansiString)
  563.61 +    { return ansiString; }
  563.62 +  inline const AString& GetSystemString(const AString &multiByteString, UINT)
  563.63 +    { return multiByteString; }
  563.64 +  inline const char * GetSystemString(const char *multiByteString, UINT)
  563.65 +    { return multiByteString; }
  563.66 +  inline AString GetSystemString(const UString &unicodeString)
  563.67 +    { return UnicodeStringToMultiByte(unicodeString); }
  563.68 +  inline AString GetSystemString(const UString &unicodeString, UINT codePage)
  563.69 +    { return UnicodeStringToMultiByte(unicodeString, codePage); }
  563.70 +#endif
  563.71 +
  563.72 +#ifndef _WIN32_WCE
  563.73 +AString SystemStringToOemString(const CSysString &srcString);
  563.74 +#endif
  563.75 +
  563.76 +#endif
   564.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   564.2 +++ b/src/win32/7zip/7z/CPP/Common/StringToInt.cpp	Sat Mar 03 10:31:27 2012 -0600
   564.3 @@ -0,0 +1,90 @@
   564.4 +// Common/StringToInt.cpp
   564.5 +
   564.6 +#include "StdAfx.h"
   564.7 +
   564.8 +#include "StringToInt.h"
   564.9 +
  564.10 +UInt64 ConvertStringToUInt64(const char *s, const char **end)
  564.11 +{
  564.12 +  UInt64 result = 0;
  564.13 +  for (;;)
  564.14 +  {
  564.15 +    char c = *s;
  564.16 +    if (c < '0' || c > '9')
  564.17 +    {
  564.18 +      if (end != NULL)
  564.19 +        *end = s;
  564.20 +      return result;
  564.21 +    }
  564.22 +    result *= 10;
  564.23 +    result += (c - '0');
  564.24 +    s++;
  564.25 +  }
  564.26 +}
  564.27 +
  564.28 +UInt64 ConvertOctStringToUInt64(const char *s, const char **end)
  564.29 +{
  564.30 +  UInt64 result = 0;
  564.31 +  for (;;)
  564.32 +  {
  564.33 +    char c = *s;
  564.34 +    if (c < '0' || c > '7')
  564.35 +    {
  564.36 +      if (end != NULL)
  564.37 +        *end = s;
  564.38 +      return result;
  564.39 +    }
  564.40 +    result <<= 3;
  564.41 +    result += (c - '0');
  564.42 +    s++;
  564.43 +  }
  564.44 +}
  564.45 +
  564.46 +UInt64 ConvertHexStringToUInt64(const char *s, const char **end)
  564.47 +{
  564.48 +  UInt64 result = 0;
  564.49 +  for (;;)
  564.50 +  {
  564.51 +    char c = *s;
  564.52 +    UInt32 v;
  564.53 +    if (c >= '0' && c <= '9') v = (c - '0');
  564.54 +    else if (c >= 'A' && c <= 'F') v = 10 + (c - 'A');
  564.55 +    else if (c >= 'a' && c <= 'f') v = 10 + (c - 'a');
  564.56 +    else
  564.57 +    {
  564.58 +      if (end != NULL)
  564.59 +        *end = s;
  564.60 +      return result;
  564.61 +    }
  564.62 +    result <<= 4;
  564.63 +    result |= v;
  564.64 +    s++;
  564.65 +  }
  564.66 +}
  564.67 +
  564.68 +
  564.69 +UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)
  564.70 +{
  564.71 +  UInt64 result = 0;
  564.72 +  for (;;)
  564.73 +  {
  564.74 +    wchar_t c = *s;
  564.75 +    if (c < '0' || c > '9')
  564.76 +    {
  564.77 +      if (end != NULL)
  564.78 +        *end = s;
  564.79 +      return result;
  564.80 +    }
  564.81 +    result *= 10;
  564.82 +    result += (c - '0');
  564.83 +    s++;
  564.84 +  }
  564.85 +}
  564.86 +
  564.87 +
  564.88 +Int64 ConvertStringToInt64(const char *s, const char **end)
  564.89 +{
  564.90 +  if (*s == '-')
  564.91 +    return -(Int64)ConvertStringToUInt64(s + 1, end);
  564.92 +  return ConvertStringToUInt64(s, end);
  564.93 +}
   565.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   565.2 +++ b/src/win32/7zip/7z/CPP/Common/StringToInt.h	Sat Mar 03 10:31:27 2012 -0600
   565.3 @@ -0,0 +1,18 @@
   565.4 +// Common/StringToInt.h
   565.5 +
   565.6 +#ifndef __COMMON_STRINGTOINT_H
   565.7 +#define __COMMON_STRINGTOINT_H
   565.8 +
   565.9 +#include <string.h>
  565.10 +#include "Types.h"
  565.11 +
  565.12 +UInt64 ConvertStringToUInt64(const char *s, const char **end);
  565.13 +UInt64 ConvertOctStringToUInt64(const char *s, const char **end);
  565.14 +UInt64 ConvertHexStringToUInt64(const char *s, const char **end);
  565.15 +UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);
  565.16 +
  565.17 +Int64 ConvertStringToInt64(const char *s, const char **end);
  565.18 +
  565.19 +#endif
  565.20 +
  565.21 +
   566.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   566.2 +++ b/src/win32/7zip/7z/CPP/Common/Types.h	Sat Mar 03 10:31:27 2012 -0600
   566.3 @@ -0,0 +1,14 @@
   566.4 +// Common/Types.h
   566.5 +
   566.6 +#ifndef __COMMON_TYPES_H
   566.7 +#define __COMMON_TYPES_H
   566.8 +
   566.9 +extern "C"
  566.10 +{
  566.11 +#include "../../C/Types.h"
  566.12 +}
  566.13 +
  566.14 +typedef int HRes;
  566.15 +
  566.16 +#endif
  566.17 +
   567.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   567.2 +++ b/src/win32/7zip/7z/CPP/Common/UTFConvert.cpp	Sat Mar 03 10:31:27 2012 -0600
   567.3 @@ -0,0 +1,145 @@
   567.4 +// UTFConvert.cpp
   567.5 +
   567.6 +#include "StdAfx.h"
   567.7 +
   567.8 +#include "UTFConvert.h"
   567.9 +#include "Types.h"
  567.10 +
  567.11 +static const Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
  567.12 +
  567.13 +static Bool Utf8_To_Utf16(wchar_t *dest, size_t *destLen, const char *src, size_t srcLen)
  567.14 +{
  567.15 +  size_t destPos = 0, srcPos = 0;
  567.16 +  for (;;)
  567.17 +  {
  567.18 +    Byte c;
  567.19 +    int numAdds;
  567.20 +    if (srcPos == srcLen)
  567.21 +    {
  567.22 +      *destLen = destPos;
  567.23 +      return True;
  567.24 +    }
  567.25 +    c = (Byte)src[srcPos++];
  567.26 +
  567.27 +    if (c < 0x80)
  567.28 +    {
  567.29 +      if (dest)
  567.30 +        dest[destPos] = (wchar_t)c;
  567.31 +      destPos++;
  567.32 +      continue;
  567.33 +    }
  567.34 +    if (c < 0xC0)
  567.35 +      break;
  567.36 +    for (numAdds = 1; numAdds < 5; numAdds++)
  567.37 +      if (c < kUtf8Limits[numAdds])
  567.38 +        break;
  567.39 +    UInt32 value = (c - kUtf8Limits[numAdds - 1]);
  567.40 +
  567.41 +    do
  567.42 +    {
  567.43 +      Byte c2;
  567.44 +      if (srcPos == srcLen)
  567.45 +        break;
  567.46 +      c2 = (Byte)src[srcPos++];
  567.47 +      if (c2 < 0x80 || c2 >= 0xC0)
  567.48 +        break;
  567.49 +      value <<= 6;
  567.50 +      value |= (c2 - 0x80);
  567.51 +    }
  567.52 +    while (--numAdds != 0);
  567.53 +    
  567.54 +    if (value < 0x10000)
  567.55 +    {
  567.56 +      if (dest)
  567.57 +        dest[destPos] = (wchar_t)value;
  567.58 +      destPos++;
  567.59 +    }
  567.60 +    else
  567.61 +    {
  567.62 +      value -= 0x10000;
  567.63 +      if (value >= 0x100000)
  567.64 +        break;
  567.65 +      if (dest)
  567.66 +      {
  567.67 +        dest[destPos + 0] = (wchar_t)(0xD800 + (value >> 10));
  567.68 +        dest[destPos + 1] = (wchar_t)(0xDC00 + (value & 0x3FF));
  567.69 +      }
  567.70 +      destPos += 2;
  567.71 +    }
  567.72 +  }
  567.73 +  *destLen = destPos;
  567.74 +  return False;
  567.75 +}
  567.76 +
  567.77 +static Bool Utf16_To_Utf8(char *dest, size_t *destLen, const wchar_t *src, size_t srcLen)
  567.78 +{
  567.79 +  size_t destPos = 0, srcPos = 0;
  567.80 +  for (;;)
  567.81 +  {
  567.82 +    unsigned numAdds;
  567.83 +    UInt32 value;
  567.84 +    if (srcPos == srcLen)
  567.85 +    {
  567.86 +      *destLen = destPos;
  567.87 +      return True;
  567.88 +    }
  567.89 +    value = src[srcPos++];
  567.90 +    if (value < 0x80)
  567.91 +    {
  567.92 +      if (dest)
  567.93 +        dest[destPos] = (char)value;
  567.94 +      destPos++;
  567.95 +      continue;
  567.96 +    }
  567.97 +    if (value >= 0xD800 && value < 0xE000)
  567.98 +    {
  567.99 +      UInt32 c2;
 567.100 +      if (value >= 0xDC00 || srcPos == srcLen)
 567.101 +        break;
 567.102 +      c2 = src[srcPos++];
 567.103 +      if (c2 < 0xDC00 || c2 >= 0xE000)
 567.104 +        break;
 567.105 +      value = ((value - 0xD800) << 10) | (c2 - 0xDC00);
 567.106 +    }
 567.107 +    for (numAdds = 1; numAdds < 5; numAdds++)
 567.108 +      if (value < (((UInt32)1) << (numAdds * 5 + 6)))
 567.109 +        break;
 567.110 +    if (dest)
 567.111 +      dest[destPos] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));
 567.112 +    destPos++;
 567.113 +    do
 567.114 +    {
 567.115 +      numAdds--;
 567.116 +      if (dest)
 567.117 +        dest[destPos] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));
 567.118 +      destPos++;
 567.119 +    }
 567.120 +    while (numAdds != 0);
 567.121 +  }
 567.122 +  *destLen = destPos;
 567.123 +  return False;
 567.124 +}
 567.125 +
 567.126 +bool ConvertUTF8ToUnicode(const AString &src, UString &dest)
 567.127 +{
 567.128 +  dest.Empty();
 567.129 +  size_t destLen = 0;
 567.130 +  Utf8_To_Utf16(NULL, &destLen, src, src.Length());
 567.131 +  wchar_t *p = dest.GetBuffer((int)destLen);
 567.132 +  Bool res = Utf8_To_Utf16(p, &destLen, src, src.Length());
 567.133 +  p[destLen] = 0;
 567.134 +  dest.ReleaseBuffer();
 567.135 +  return res ? true : false;
 567.136 +}
 567.137 +
 567.138 +bool ConvertUnicodeToUTF8(const UString &src, AString &dest)
 567.139 +{
 567.140 +  dest.Empty();
 567.141 +  size_t destLen = 0;
 567.142 +  Utf16_To_Utf8(NULL, &destLen, src, src.Length());
 567.143 +  char *p = dest.GetBuffer((int)destLen);
 567.144 +  Bool res = Utf16_To_Utf8(p, &destLen, src, src.Length());
 567.145 +  p[destLen] = 0;
 567.146 +  dest.ReleaseBuffer();
 567.147 +  return res ? true : false;
 567.148 +}
   568.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   568.2 +++ b/src/win32/7zip/7z/CPP/Common/UTFConvert.h	Sat Mar 03 10:31:27 2012 -0600
   568.3 @@ -0,0 +1,11 @@
   568.4 +// Common/UTFConvert.h
   568.5 +
   568.6 +#ifndef __COMMON_UTFCONVERT_H
   568.7 +#define __COMMON_UTFCONVERT_H
   568.8 +
   568.9 +#include "MyString.h"
  568.10 +
  568.11 +bool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString);
  568.12 +bool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString);
  568.13 +
  568.14 +#endif
   569.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   569.2 +++ b/src/win32/7zip/7z/CPP/Common/Wildcard.cpp	Sat Mar 03 10:31:27 2012 -0600
   569.3 @@ -0,0 +1,458 @@
   569.4 +// Common/Wildcard.cpp
   569.5 +
   569.6 +#include "StdAfx.h"
   569.7 +
   569.8 +#include "Wildcard.h"
   569.9 +
  569.10 +bool g_CaseSensitive =
  569.11 +  #ifdef _WIN32
  569.12 +    false;
  569.13 +  #else
  569.14 +    true;
  569.15 +  #endif
  569.16 +
  569.17 +static const wchar_t kAnyCharsChar = L'*';
  569.18 +static const wchar_t kAnyCharChar = L'?';
  569.19 +
  569.20 +#ifdef _WIN32
  569.21 +static const wchar_t kDirDelimiter1 = L'\\';
  569.22 +#endif
  569.23 +static const wchar_t kDirDelimiter2 = L'/';
  569.24 +
  569.25 +static const UString kWildCardCharSet = L"?*";
  569.26 +
  569.27 +static const UString kIllegalWildCardFileNameChars=
  569.28 +  L"\x1\x2\x3\x4\x5\x6\x7\x8\x9\xA\xB\xC\xD\xE\xF"
  569.29 +  L"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
  569.30 +  L"\"/:<>\\|";
  569.31 +
  569.32 +
  569.33 +static inline bool IsCharDirLimiter(wchar_t c)
  569.34 +{
  569.35 +  return (
  569.36 +    #ifdef _WIN32
  569.37 +    c == kDirDelimiter1 ||
  569.38 +    #endif
  569.39 +    c == kDirDelimiter2);
  569.40 +}
  569.41 +
  569.42 +int CompareFileNames(const UString &s1, const UString &s2)
  569.43 +{
  569.44 +  if (g_CaseSensitive)
  569.45 +    return s1.Compare(s2);
  569.46 +  return s1.CompareNoCase(s2);
  569.47 +}
  569.48 +
  569.49 +// -----------------------------------------
  569.50 +// this function compares name with mask
  569.51 +// ? - any char
  569.52 +// * - any char or empty
  569.53 +
  569.54 +static bool EnhancedMaskTest(const wchar_t *mask, const wchar_t *name)
  569.55 +{
  569.56 +  for (;;)
  569.57 +  {
  569.58 +    wchar_t m = *mask;
  569.59 +    wchar_t c = *name;
  569.60 +    if (m == 0)
  569.61 +      return (c == 0);
  569.62 +    if (m == kAnyCharsChar)
  569.63 +    {
  569.64 +      if (EnhancedMaskTest(mask + 1, name))
  569.65 +        return true;
  569.66 +      if (c == 0)
  569.67 +        return false;
  569.68 +    }
  569.69 +    else
  569.70 +    {
  569.71 +      if (m == kAnyCharChar)
  569.72 +      {
  569.73 +        if (c == 0)
  569.74 +          return false;
  569.75 +      }
  569.76 +      else if (m != c)
  569.77 +        if (g_CaseSensitive || MyCharUpper(m) != MyCharUpper(c))
  569.78 +          return false;
  569.79 +      mask++;
  569.80 +    }
  569.81 +    name++;
  569.82 +  }
  569.83 +}
  569.84 +
  569.85 +// --------------------------------------------------
  569.86 +// Splits path to strings
  569.87 +
  569.88 +void SplitPathToParts(const UString &path, UStringVector &pathParts)
  569.89 +{
  569.90 +  pathParts.Clear();
  569.91 +  UString name;
  569.92 +  int len = path.Length();
  569.93 +  if (len == 0)
  569.94 +    return;
  569.95 +  for (int i = 0; i < len; i++)
  569.96 +  {
  569.97 +    wchar_t c = path[i];
  569.98 +    if (IsCharDirLimiter(c))
  569.99 +    {
 569.100 +      pathParts.Add(name);
 569.101 +      name.Empty();
 569.102 +    }
 569.103 +    else
 569.104 +      name += c;
 569.105 +  }
 569.106 +  pathParts.Add(name);
 569.107 +}
 569.108 +
 569.109 +void SplitPathToParts(const UString &path, UString &dirPrefix, UString &name)
 569.110 +{
 569.111 +  int i;
 569.112 +  for (i = path.Length() - 1; i >= 0; i--)
 569.113 +    if (IsCharDirLimiter(path[i]))
 569.114 +      break;
 569.115 +  dirPrefix = path.Left(i + 1);
 569.116 +  name = path.Mid(i + 1);
 569.117 +}
 569.118 +
 569.119 +UString ExtractDirPrefixFromPath(const UString &path)
 569.120 +{
 569.121 +  int i;
 569.122 +  for (i = path.Length() - 1; i >= 0; i--)
 569.123 +    if (IsCharDirLimiter(path[i]))
 569.124 +      break;
 569.125 +  return path.Left(i + 1);
 569.126 +}
 569.127 +
 569.128 +UString ExtractFileNameFromPath(const UString &path)
 569.129 +{
 569.130 +  int i;
 569.131 +  for (i = path.Length() - 1; i >= 0; i--)
 569.132 +    if (IsCharDirLimiter(path[i]))
 569.133 +      break;
 569.134 +  return path.Mid(i + 1);
 569.135 +}
 569.136 +
 569.137 +
 569.138 +bool CompareWildCardWithName(const UString &mask, const UString &name)
 569.139 +{
 569.140 +  return EnhancedMaskTest(mask, name);
 569.141 +}
 569.142 +
 569.143 +bool DoesNameContainWildCard(const UString &path)
 569.144 +{
 569.145 +  return (path.FindOneOf(kWildCardCharSet) >= 0);
 569.146 +}
 569.147 +
 569.148 +
 569.149 +// ----------------------------------------------------------'
 569.150 +// NWildcard
 569.151 +
 569.152 +namespace NWildcard {
 569.153 +
 569.154 +
 569.155 +/*
 569.156 +M = MaskParts.Size();
 569.157 +N = TestNameParts.Size();
 569.158 +
 569.159 +                           File                          Dir
 569.160 +ForFile     req   M<=N  [N-M, N)                          -
 569.161 +         nonreq   M=N   [0, M)                            -
 569.162 + 
 569.163 +ForDir      req   M<N   [0, M) ... [N-M-1, N-1)  same as ForBoth-File
 569.164 +         nonreq         [0, M)                   same as ForBoth-File
 569.165 +
 569.166 +ForBoth     req   m<=N  [0, M) ... [N-M, N)      same as ForBoth-File
 569.167 +         nonreq         [0, M)                   same as ForBoth-File
 569.168 +
 569.169 +*/
 569.170 +
 569.171 +bool CItem::CheckPath(const UStringVector &pathParts, bool isFile) const
 569.172 +{
 569.173 +  if (!isFile && !ForDir)
 569.174 +    return false;
 569.175 +  int delta = (int)pathParts.Size() - (int)PathParts.Size();
 569.176 +  if (delta < 0)
 569.177 +    return false;
 569.178 +  int start = 0;
 569.179 +  int finish = 0;
 569.180 +  if (isFile)
 569.181 +  {
 569.182 +    if (!ForDir && !Recursive && delta !=0)
 569.183 +      return false;
 569.184 +    if (!ForFile && delta == 0)
 569.185 +      return false;
 569.186 +    if (!ForDir && Recursive)
 569.187 +      start = delta;
 569.188 +  }
 569.189 +  if (Recursive)
 569.190 +  {
 569.191 +    finish = delta;
 569.192 +    if (isFile && !ForFile)
 569.193 +      finish = delta - 1;
 569.194 +  }
 569.195 +  for (int d = start; d <= finish; d++)
 569.196 +  {
 569.197 +    int i;
 569.198 +    for (i = 0; i < PathParts.Size(); i++)
 569.199 +      if (!CompareWildCardWithName(PathParts[i], pathParts[i + d]))
 569.200 +        break;
 569.201 +    if (i == PathParts.Size())
 569.202 +      return true;
 569.203 +  }
 569.204 +  return false;
 569.205 +}
 569.206 +
 569.207 +int CCensorNode::FindSubNode(const UString &name) const
 569.208 +{
 569.209 +  for (int i = 0; i < SubNodes.Size(); i++)
 569.210 +    if (CompareFileNames(SubNodes[i].Name, name) == 0)
 569.211 +      return i;
 569.212 +  return -1;
 569.213 +}
 569.214 +
 569.215 +void CCensorNode::AddItemSimple(bool include, CItem &item)
 569.216 +{
 569.217 +  if (include)
 569.218 +    IncludeItems.Add(item);
 569.219 +  else
 569.220 +    ExcludeItems.Add(item);
 569.221 +}
 569.222 +
 569.223 +void CCensorNode::AddItem(bool include, CItem &item)
 569.224 +{
 569.225 +  if (item.PathParts.Size() <= 1)
 569.226 +  {
 569.227 +    AddItemSimple(include, item);
 569.228 +    return;
 569.229 +  }
 569.230 +  const UString &front = item.PathParts.Front();
 569.231 +  if (DoesNameContainWildCard(front))
 569.232 +  {
 569.233 +    AddItemSimple(include, item);
 569.234 +    return;
 569.235 +  }
 569.236 +  int index = FindSubNode(front);
 569.237 +  if (index < 0)
 569.238 +    index = SubNodes.Add(CCensorNode(front, this));
 569.239 +  item.PathParts.Delete(0);
 569.240 +  SubNodes[index].AddItem(include, item);
 569.241 +}
 569.242 +
 569.243 +void CCensorNode::AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir)
 569.244 +{
 569.245 +  CItem item;
 569.246 +  SplitPathToParts(path, item.PathParts);
 569.247 +  item.Recursive = recursive;
 569.248 +  item.ForFile = forFile;
 569.249 +  item.ForDir = forDir;
 569.250 +  AddItem(include, item);
 569.251 +}
 569.252 +
 569.253 +bool CCensorNode::NeedCheckSubDirs() const
 569.254 +{
 569.255 +  for (int i = 0; i < IncludeItems.Size(); i++)
 569.256 +  {
 569.257 +    const CItem &item = IncludeItems[i];
 569.258 +    if (item.Recursive || item.PathParts.Size() > 1)
 569.259 +      return true;
 569.260 +  }
 569.261 +  return false;
 569.262 +}
 569.263 +
 569.264 +bool CCensorNode::AreThereIncludeItems() const
 569.265 +{
 569.266 +  if (IncludeItems.Size() > 0)
 569.267 +    return true;
 569.268 +  for (int i = 0; i < SubNodes.Size(); i++)
 569.269 +    if (SubNodes[i].AreThereIncludeItems())
 569.270 +      return true;
 569.271 +  return false;
 569.272 +}
 569.273 +
 569.274 +bool CCensorNode::CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const
 569.275 +{
 569.276 +  const CObjectVector<CItem> &items = include ? IncludeItems : ExcludeItems;
 569.277 +  for (int i = 0; i < items.Size(); i++)
 569.278 +    if (items[i].CheckPath(pathParts, isFile))
 569.279 +      return true;
 569.280 +  return false;
 569.281 +}
 569.282 +
 569.283 +bool CCensorNode::CheckPath(UStringVector &pathParts, bool isFile, bool &include) const
 569.284 +{
 569.285 +  if (CheckPathCurrent(false, pathParts, isFile))
 569.286 +  {
 569.287 +    include = false;
 569.288 +    return true;
 569.289 +  }
 569.290 +  include = true;
 569.291 +  bool finded = CheckPathCurrent(true, pathParts, isFile);
 569.292 +  if (pathParts.Size() == 1)
 569.293 +    return finded;
 569.294 +  int index = FindSubNode(pathParts.Front());
 569.295 +  if (index >= 0)
 569.296 +  {
 569.297 +    UStringVector pathParts2 = pathParts;
 569.298 +    pathParts2.Delete(0);
 569.299 +    if (SubNodes[index].CheckPath(pathParts2, isFile, include))
 569.300 +      return true;
 569.301 +  }
 569.302 +  return finded;
 569.303 +}
 569.304 +
 569.305 +bool CCensorNode::CheckPath(const UString &path, bool isFile, bool &include) const
 569.306 +{
 569.307 +  UStringVector pathParts;
 569.308 +  SplitPathToParts(path, pathParts);
 569.309 +  return CheckPath(pathParts, isFile, include);
 569.310 +}
 569.311 +
 569.312 +bool CCensorNode::CheckPath(const UString &path, bool isFile) const
 569.313 +{
 569.314 +  bool include;
 569.315 +  if (CheckPath(path, isFile, include))
 569.316 +    return include;
 569.317 +  return false;
 569.318 +}
 569.319 +
 569.320 +bool CCensorNode::CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const
 569.321 +{
 569.322 +  if (CheckPathCurrent(include, pathParts, isFile))
 569.323 +    return true;
 569.324 +  if (Parent == 0)
 569.325 +    return false;
 569.326 +  pathParts.Insert(0, Name);
 569.327 +  return Parent->CheckPathToRoot(include, pathParts, isFile);
 569.328 +}
 569.329 +
 569.330 +/*
 569.331 +bool CCensorNode::CheckPathToRoot(bool include, const UString &path, bool isFile) const
 569.332 +{
 569.333 +  UStringVector pathParts;
 569.334 +  SplitPathToParts(path, pathParts);
 569.335 +  return CheckPathToRoot(include, pathParts, isFile);
 569.336 +}
 569.337 +*/
 569.338 +
 569.339 +void CCensorNode::AddItem2(bool include, const UString &path, bool recursive)
 569.340 +{
 569.341 +  if (path.IsEmpty())
 569.342 +    return;
 569.343 +  bool forFile = true;
 569.344 +  bool forFolder = true;
 569.345 +  UString path2 = path;
 569.346 +  if (IsCharDirLimiter(path[path.Length() - 1]))
 569.347 +  {
 569.348 +    path2.Delete(path.Length() - 1);
 569.349 +    forFile = false;
 569.350 +  }
 569.351 +  AddItem(include, path2, recursive, forFile, forFolder);
 569.352 +}
 569.353 +
 569.354 +void CCensorNode::ExtendExclude(const CCensorNode &fromNodes)
 569.355 +{
 569.356 +  ExcludeItems += fromNodes.ExcludeItems;
 569.357 +  for (int i = 0; i < fromNodes.SubNodes.Size(); i++)
 569.358 +  {
 569.359 +    const CCensorNode &node = fromNodes.SubNodes[i];
 569.360 +    int subNodeIndex = FindSubNode(node.Name);
 569.361 +    if (subNodeIndex < 0)
 569.362 +      subNodeIndex = SubNodes.Add(CCensorNode(node.Name, this));
 569.363 +    SubNodes[subNodeIndex].ExtendExclude(node);
 569.364 +  }
 569.365 +}
 569.366 +
 569.367 +int CCensor::FindPrefix(const UString &prefix) const
 569.368 +{
 569.369 +  for (int i = 0; i < Pairs.Size(); i++)
 569.370 +    if (CompareFileNames(Pairs[i].Prefix, prefix) == 0)
 569.371 +      return i;
 569.372 +  return -1;
 569.373 +}
 569.374 +
 569.375 +void CCensor::AddItem(bool include, const UString &path, bool recursive)
 569.376 +{
 569.377 +  UStringVector pathParts;
 569.378 +  SplitPathToParts(path, pathParts);
 569.379 +  bool forFile = true;
 569.380 +  if (pathParts.Back().IsEmpty())
 569.381 +  {
 569.382 +    forFile = false;
 569.383 +    pathParts.DeleteBack();
 569.384 +  }
 569.385 +  const UString &front = pathParts.Front();
 569.386 +  bool isAbs = false;
 569.387 +  if (front.IsEmpty())
 569.388 +    isAbs = true;
 569.389 +  else if (front.Length() == 2 && front[1] == L':')
 569.390 +    isAbs = true;
 569.391 +  else
 569.392 +  {
 569.393 +    for (int i = 0; i < pathParts.Size(); i++)
 569.394 +    {
 569.395 +      const UString &part = pathParts[i];
 569.396 +      if (part == L".." || part == L".")
 569.397 +      {
 569.398 +        isAbs = true;
 569.399 +        break;
 569.400 +      }
 569.401 +    }
 569.402 +  }
 569.403 +  int numAbsParts = 0;
 569.404 +  if (isAbs)
 569.405 +    if (pathParts.Size() > 1)
 569.406 +      numAbsParts = pathParts.Size() - 1;
 569.407 +    else
 569.408 +      numAbsParts = 1;
 569.409 +  UString prefix;
 569.410 +  for (int i = 0; i < numAbsParts; i++)
 569.411 +  {
 569.412 +    const UString &front = pathParts.Front();
 569.413 +    if (DoesNameContainWildCard(front))
 569.414 +      break;
 569.415 +    prefix += front;
 569.416 +    prefix += WCHAR_PATH_SEPARATOR;
 569.417 +    pathParts.Delete(0);
 569.418 +  }
 569.419 +  int index = FindPrefix(prefix);
 569.420 +  if (index < 0)
 569.421 +    index = Pairs.Add(CPair(prefix));
 569.422 +
 569.423 +  CItem item;
 569.424 +  item.PathParts = pathParts;
 569.425 +  item.ForDir = true;
 569.426 +  item.ForFile = forFile;
 569.427 +  item.Recursive = recursive;
 569.428 +  Pairs[index].Head.AddItem(include, item);
 569.429 +}
 569.430 +
 569.431 +bool CCensor::CheckPath(const UString &path, bool isFile) const
 569.432 +{
 569.433 +  bool finded = false;
 569.434 +  for (int i = 0; i < Pairs.Size(); i++)
 569.435 +  {
 569.436 +    bool include;
 569.437 +    if (Pairs[i].Head.CheckPath(path, isFile, include))
 569.438 +    {
 569.439 +      if (!include)
 569.440 +        return false;
 569.441 +      finded = true;
 569.442 +    }
 569.443 +  }
 569.444 +  return finded;
 569.445 +}
 569.446 +
 569.447 +void CCensor::ExtendExclude()
 569.448 +{
 569.449 +  int i;
 569.450 +  for (i = 0; i < Pairs.Size(); i++)
 569.451 +    if (Pairs[i].Prefix.IsEmpty())
 569.452 +      break;
 569.453 +  if (i == Pairs.Size())
 569.454 +    return;
 569.455 +  int index = i;
 569.456 +  for (i = 0; i < Pairs.Size(); i++)
 569.457 +    if (index != i)
 569.458 +      Pairs[i].Head.ExtendExclude(Pairs[index].Head);
 569.459 +}
 569.460 +
 569.461 +}
   570.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   570.2 +++ b/src/win32/7zip/7z/CPP/Common/Wildcard.h	Sat Mar 03 10:31:27 2012 -0600
   570.3 @@ -0,0 +1,80 @@
   570.4 +// Common/Wildcard.h
   570.5 +
   570.6 +#ifndef __COMMON_WILDCARD_H
   570.7 +#define __COMMON_WILDCARD_H
   570.8 +
   570.9 +#include "MyString.h"
  570.10 +
  570.11 +int CompareFileNames(const UString &s1, const UString &s2);
  570.12 +
  570.13 +void SplitPathToParts(const UString &path, UStringVector &pathParts);
  570.14 +void SplitPathToParts(const UString &path, UString &dirPrefix, UString &name);
  570.15 +UString ExtractDirPrefixFromPath(const UString &path);
  570.16 +UString ExtractFileNameFromPath(const UString &path);
  570.17 +bool DoesNameContainWildCard(const UString &path);
  570.18 +bool CompareWildCardWithName(const UString &mask, const UString &name);
  570.19 +
  570.20 +namespace NWildcard {
  570.21 +
  570.22 +struct CItem
  570.23 +{
  570.24 +  UStringVector PathParts;
  570.25 +  bool Recursive;
  570.26 +  bool ForFile;
  570.27 +  bool ForDir;
  570.28 +  bool CheckPath(const UStringVector &pathParts, bool isFile) const;
  570.29 +};
  570.30 +
  570.31 +class CCensorNode
  570.32 +{
  570.33 +  CCensorNode *Parent;
  570.34 +  bool CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const;
  570.35 +  void AddItemSimple(bool include, CItem &item);
  570.36 +  bool CheckPath(UStringVector &pathParts, bool isFile, bool &include) const;
  570.37 +public:
  570.38 +  CCensorNode(): Parent(0) { };
  570.39 +  CCensorNode(const UString &name, CCensorNode *parent): Name(name), Parent(parent) { };
  570.40 +  UString Name;
  570.41 +  CObjectVector<CCensorNode> SubNodes;
  570.42 +  CObjectVector<CItem> IncludeItems;
  570.43 +  CObjectVector<CItem> ExcludeItems;
  570.44 +
  570.45 +  int FindSubNode(const UString &path) const;
  570.46 +
  570.47 +  void AddItem(bool include, CItem &item);
  570.48 +  void AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir);
  570.49 +  void AddItem2(bool include, const UString &path, bool recursive);
  570.50 +
  570.51 +  bool NeedCheckSubDirs() const;
  570.52 +  bool AreThereIncludeItems() const;
  570.53 +
  570.54 +  bool CheckPath(const UString &path, bool isFile, bool &include) const;
  570.55 +  bool CheckPath(const UString &path, bool isFile) const;
  570.56 +
  570.57 +  bool CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const;
  570.58 +  // bool CheckPathToRoot(const UString &path, bool isFile, bool include) const;
  570.59 +  void ExtendExclude(const CCensorNode &fromNodes);
  570.60 +};
  570.61 +
  570.62 +struct CPair
  570.63 +{
  570.64 +  UString Prefix;
  570.65 +  CCensorNode Head;
  570.66 +  CPair(const UString &prefix): Prefix(prefix) { };
  570.67 +};
  570.68 +
  570.69 +class CCensor
  570.70 +{
  570.71 +  int FindPrefix(const UString &prefix) const;
  570.72 +public:
  570.73 +  CObjectVector<CPair> Pairs;
  570.74 +  bool AllAreRelative() const
  570.75 +    { return (Pairs.Size() == 1 && Pairs.Front().Prefix.IsEmpty()); }
  570.76 +  void AddItem(bool include, const UString &path, bool recursive);
  570.77 +  bool CheckPath(const UString &path, bool isFile) const;
  570.78 +  void ExtendExclude();
  570.79 +};
  570.80 +
  570.81 +}
  570.82 +
  570.83 +#endif
   571.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   571.2 +++ b/src/win32/7zip/7z/CPP/Windows/Defs.h	Sat Mar 03 10:31:27 2012 -0600
   571.3 @@ -0,0 +1,23 @@
   571.4 +// Windows/Defs.h
   571.5 +
   571.6 +#ifndef __WINDOWS_DEFS_H
   571.7 +#define __WINDOWS_DEFS_H
   571.8 +
   571.9 +inline bool BOOLToBool(BOOL value)
  571.10 +  { return (value != FALSE); }
  571.11 +
  571.12 +#ifdef _WIN32
  571.13 +inline bool LRESULTToBool(LRESULT value)
  571.14 +  { return (value != FALSE); }
  571.15 +#endif
  571.16 +
  571.17 +inline BOOL BoolToBOOL(bool value)
  571.18 +  { return (value ? TRUE: FALSE); }
  571.19 +
  571.20 +inline VARIANT_BOOL BoolToVARIANT_BOOL(bool value)
  571.21 +  { return (value ? VARIANT_TRUE: VARIANT_FALSE); }
  571.22 +
  571.23 +inline bool VARIANT_BOOLToBool(VARIANT_BOOL value)
  571.24 +  { return (value != VARIANT_FALSE); }
  571.25 +
  571.26 +#endif
   572.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   572.2 +++ b/src/win32/7zip/7z/CPP/Windows/FileDir.cpp	Sat Mar 03 10:31:27 2012 -0600
   572.3 @@ -0,0 +1,841 @@
   572.4 +// Windows/FileDir.cpp
   572.5 +
   572.6 +#include "StdAfx.h"
   572.7 +
   572.8 +#include "FileDir.h"
   572.9 +#include "FileName.h"
  572.10 +#include "FileFind.h"
  572.11 +#include "Defs.h"
  572.12 +#ifndef _UNICODE
  572.13 +#include "../Common/StringConvert.h"
  572.14 +#endif
  572.15 +
  572.16 +#ifndef _UNICODE
  572.17 +extern bool g_IsNT;
  572.18 +#endif
  572.19 +
  572.20 +namespace NWindows {
  572.21 +namespace NFile {
  572.22 +
  572.23 +#if defined(WIN_LONG_PATH) && defined(_UNICODE)
  572.24 +#define WIN_LONG_PATH2
  572.25 +#endif
  572.26 +
  572.27 +// SetCurrentDirectory doesn't support \\?\ prefix
  572.28 +
  572.29 +#ifdef WIN_LONG_PATH
  572.30 +bool GetLongPathBase(LPCWSTR fileName, UString &res);
  572.31 +bool GetLongPath(LPCWSTR fileName, UString &res);
  572.32 +#endif
  572.33 +
  572.34 +namespace NDirectory {
  572.35 +
  572.36 +#ifndef _UNICODE
  572.37 +static inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
  572.38 +static UString GetUnicodePath(const CSysString &sysPath)
  572.39 +  { return MultiByteToUnicodeString(sysPath, GetCurrentCodePage()); }
  572.40 +static CSysString GetSysPath(LPCWSTR sysPath)
  572.41 +  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }
  572.42 +#endif
  572.43 +
  572.44 +bool MyGetWindowsDirectory(CSysString &path)
  572.45 +{
  572.46 +  UINT needLength = ::GetWindowsDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);
  572.47 +  path.ReleaseBuffer();
  572.48 +  return (needLength > 0 && needLength <= MAX_PATH);
  572.49 +}
  572.50 +
  572.51 +bool MyGetSystemDirectory(CSysString &path)
  572.52 +{
  572.53 +  UINT needLength = ::GetSystemDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);
  572.54 +  path.ReleaseBuffer();
  572.55 +  return (needLength > 0 && needLength <= MAX_PATH);
  572.56 +}
  572.57 +
  572.58 +#ifndef _UNICODE
  572.59 +bool MyGetWindowsDirectory(UString &path)
  572.60 +{
  572.61 +  if (g_IsNT)
  572.62 +  {
  572.63 +    UINT needLength = ::GetWindowsDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);
  572.64 +    path.ReleaseBuffer();
  572.65 +    return (needLength > 0 && needLength <= MAX_PATH);
  572.66 +  }
  572.67 +  CSysString sysPath;
  572.68 +  if (!MyGetWindowsDirectory(sysPath))
  572.69 +    return false;
  572.70 +  path = GetUnicodePath(sysPath);
  572.71 +  return true;
  572.72 +}
  572.73 +
  572.74 +bool MyGetSystemDirectory(UString &path)
  572.75 +{
  572.76 +  if (g_IsNT)
  572.77 +  {
  572.78 +    UINT needLength = ::GetSystemDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);
  572.79 +    path.ReleaseBuffer();
  572.80 +    return (needLength > 0 && needLength <= MAX_PATH);
  572.81 +  }
  572.82 +  CSysString sysPath;
  572.83 +  if (!MyGetSystemDirectory(sysPath))
  572.84 +    return false;
  572.85 +  path = GetUnicodePath(sysPath);
  572.86 +  return true;
  572.87 +}
  572.88 +#endif
  572.89 +
  572.90 +bool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)
  572.91 +{
  572.92 +  #ifndef _UNICODE
  572.93 +  if (!g_IsNT)
  572.94 +  {
  572.95 +    ::SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  572.96 +    return false;
  572.97 +  }
  572.98 +  #endif
  572.99 +  HANDLE hDir = ::CreateFileW(fileName, GENERIC_WRITE,
 572.100 +      FILE_SHARE_READ | FILE_SHARE_WRITE,
 572.101 +      NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
 572.102 +  #ifdef WIN_LONG_PATH
 572.103 +  if (hDir == INVALID_HANDLE_VALUE)
 572.104 +  {
 572.105 +    UString longPath;
 572.106 +    if (GetLongPath(fileName, longPath))
 572.107 +      hDir = ::CreateFileW(longPath, GENERIC_WRITE,
 572.108 +        FILE_SHARE_READ | FILE_SHARE_WRITE,
 572.109 +        NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
 572.110 +  }
 572.111 +  #endif
 572.112 +
 572.113 +  bool res = false;
 572.114 +  if (hDir != INVALID_HANDLE_VALUE)
 572.115 +  {
 572.116 +    res = BOOLToBool(::SetFileTime(hDir, cTime, aTime, mTime));
 572.117 +    ::CloseHandle(hDir);
 572.118 +  }
 572.119 +  return res;
 572.120 +}
 572.121 +
 572.122 +bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes)
 572.123 +{
 572.124 +  if (::SetFileAttributes(fileName, fileAttributes))
 572.125 +    return true;
 572.126 +  #ifdef WIN_LONG_PATH2
 572.127 +  UString longPath;
 572.128 +  if (GetLongPath(fileName, longPath))
 572.129 +    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));
 572.130 +  #endif
 572.131 +  return false;
 572.132 +}
 572.133 +
 572.134 +bool MyRemoveDirectory(LPCTSTR pathName)
 572.135 +{
 572.136 +  if (::RemoveDirectory(pathName))
 572.137 +    return true;
 572.138 +  #ifdef WIN_LONG_PATH2
 572.139 +  UString longPath;
 572.140 +  if (GetLongPath(pathName, longPath))
 572.141 +    return BOOLToBool(::RemoveDirectoryW(longPath));
 572.142 +  #endif
 572.143 +  return false;
 572.144 +}
 572.145 +
 572.146 +#ifdef WIN_LONG_PATH
 572.147 +bool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2)
 572.148 +{
 572.149 +  if (!GetLongPathBase(s1, d1) || !GetLongPathBase(s2, d2))
 572.150 +    return false;
 572.151 +  if (d1.IsEmpty() && d2.IsEmpty()) return false;
 572.152 +  if (d1.IsEmpty()) d1 = s1;
 572.153 +  if (d2.IsEmpty()) d2 = s2;
 572.154 +  return true;
 572.155 +}
 572.156 +#endif
 572.157 +
 572.158 +bool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName)
 572.159 +{
 572.160 +  if (::MoveFile(existFileName, newFileName))
 572.161 +    return true;
 572.162 +  #ifdef WIN_LONG_PATH2
 572.163 +  UString d1, d2;
 572.164 +  if (GetLongPaths(existFileName, newFileName, d1, d2))
 572.165 +    return BOOLToBool(::MoveFileW(d1, d2));
 572.166 +  #endif
 572.167 +  return false;
 572.168 +}
 572.169 +
 572.170 +#ifndef _UNICODE
 572.171 +bool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes)
 572.172 +{
 572.173 +  if (!g_IsNT)
 572.174 +    return MySetFileAttributes(GetSysPath(fileName), fileAttributes);
 572.175 +  if (::SetFileAttributesW(fileName, fileAttributes))
 572.176 +    return true;
 572.177 +  #ifdef WIN_LONG_PATH
 572.178 +  UString longPath;
 572.179 +  if (GetLongPath(fileName, longPath))
 572.180 +    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));
 572.181 +  #endif
 572.182 +  return false;
 572.183 +}
 572.184 +
 572.185 +
 572.186 +bool MyRemoveDirectory(LPCWSTR pathName)
 572.187 +{
 572.188 +  if (!g_IsNT)
 572.189 +    return MyRemoveDirectory(GetSysPath(pathName));
 572.190 +  if (::RemoveDirectoryW(pathName))
 572.191 +    return true;
 572.192 +  #ifdef WIN_LONG_PATH
 572.193 +  UString longPath;
 572.194 +  if (GetLongPath(pathName, longPath))
 572.195 +    return BOOLToBool(::RemoveDirectoryW(longPath));
 572.196 +  #endif
 572.197 +  return false;
 572.198 +}
 572.199 +
 572.200 +bool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName)
 572.201 +{
 572.202 +  if (!g_IsNT)
 572.203 +    return MyMoveFile(GetSysPath(existFileName), GetSysPath(newFileName));
 572.204 +  if (::MoveFileW(existFileName, newFileName))
 572.205 +    return true;
 572.206 +  #ifdef WIN_LONG_PATH
 572.207 +  UString d1, d2;
 572.208 +  if (GetLongPaths(existFileName, newFileName, d1, d2))
 572.209 +    return BOOLToBool(::MoveFileW(d1, d2));
 572.210 +  #endif
 572.211 +  return false;
 572.212 +}
 572.213 +#endif
 572.214 +
 572.215 +bool MyCreateDirectory(LPCTSTR pathName)
 572.216 +{
 572.217 +  if (::CreateDirectory(pathName, NULL))
 572.218 +    return true;
 572.219 +  #ifdef WIN_LONG_PATH2
 572.220 +  if (::GetLastError() != ERROR_ALREADY_EXISTS)
 572.221 +  {
 572.222 +    UString longPath;
 572.223 +    if (GetLongPath(pathName, longPath))
 572.224 +      return BOOLToBool(::CreateDirectoryW(longPath, NULL));
 572.225 +  }
 572.226 +  #endif
 572.227 +  return false;
 572.228 +}
 572.229 +
 572.230 +#ifndef _UNICODE
 572.231 +bool MyCreateDirectory(LPCWSTR pathName)
 572.232 +{
 572.233 +  if (!g_IsNT)
 572.234 +    return MyCreateDirectory(GetSysPath(pathName));
 572.235 +  if (::CreateDirectoryW(pathName, NULL))
 572.236 +    return true;
 572.237 +  #ifdef WIN_LONG_PATH
 572.238 +  if (::GetLastError() != ERROR_ALREADY_EXISTS)
 572.239 +  {
 572.240 +    UString longPath;
 572.241 +    if (GetLongPath(pathName, longPath))
 572.242 +      return BOOLToBool(::CreateDirectoryW(longPath, NULL));
 572.243 +  }
 572.244 +  #endif
 572.245 +  return false;
 572.246 +}
 572.247 +#endif
 572.248 +
 572.249 +/*
 572.250 +bool CreateComplexDirectory(LPCTSTR pathName)
 572.251 +{
 572.252 +  NName::CParsedPath path;
 572.253 +  path.ParsePath(pathName);
 572.254 +  CSysString fullPath = path.Prefix;
 572.255 +  DWORD errorCode = ERROR_SUCCESS;
 572.256 +  for (int i = 0; i < path.PathParts.Size(); i++)
 572.257 +  {
 572.258 +    const CSysString &string = path.PathParts[i];
 572.259 +    if (string.IsEmpty())
 572.260 +    {
 572.261 +      if (i != path.PathParts.Size() - 1)
 572.262 +        return false;
 572.263 +      return true;
 572.264 +    }
 572.265 +    fullPath += path.PathParts[i];
 572.266 +    if (!MyCreateDirectory(fullPath))
 572.267 +    {
 572.268 +      DWORD errorCode = GetLastError();
 572.269 +      if (errorCode != ERROR_ALREADY_EXISTS)
 572.270 +        return false;
 572.271 +    }
 572.272 +    fullPath += NName::kDirDelimiter;
 572.273 +  }
 572.274 +  return true;
 572.275 +}
 572.276 +*/
 572.277 +
 572.278 +bool CreateComplexDirectory(LPCTSTR _aPathName)
 572.279 +{
 572.280 +  CSysString pathName = _aPathName;
 572.281 +  int pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));
 572.282 +  if (pos > 0 && pos == pathName.Length() - 1)
 572.283 +  {
 572.284 +    if (pathName.Length() == 3 && pathName[1] == ':')
 572.285 +      return true; // Disk folder;
 572.286 +    pathName.Delete(pos);
 572.287 +  }
 572.288 +  CSysString pathName2 = pathName;
 572.289 +  pos = pathName.Length();
 572.290 +  for (;;)
 572.291 +  {
 572.292 +    if (MyCreateDirectory(pathName))
 572.293 +      break;
 572.294 +    if (::GetLastError() == ERROR_ALREADY_EXISTS)
 572.295 +    {
 572.296 +      NFind::CFileInfo fileInfo;
 572.297 +      if (!NFind::FindFile(pathName, fileInfo)) // For network folders
 572.298 +        return true;
 572.299 +      if (!fileInfo.IsDir())
 572.300 +        return false;
 572.301 +      break;
 572.302 +    }
 572.303 +    pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));
 572.304 +    if (pos < 0 || pos == 0)
 572.305 +      return false;
 572.306 +    if (pathName[pos - 1] == ':')
 572.307 +      return false;
 572.308 +    pathName = pathName.Left(pos);
 572.309 +  }
 572.310 +  pathName = pathName2;
 572.311 +  while (pos < pathName.Length())
 572.312 +  {
 572.313 +    pos = pathName.Find(TEXT(CHAR_PATH_SEPARATOR), pos + 1);
 572.314 +    if (pos < 0)
 572.315 +      pos = pathName.Length();
 572.316 +    if (!MyCreateDirectory(pathName.Left(pos)))
 572.317 +      return false;
 572.318 +  }
 572.319 +  return true;
 572.320 +}
 572.321 +
 572.322 +#ifndef _UNICODE
 572.323 +
 572.324 +bool CreateComplexDirectory(LPCWSTR _aPathName)
 572.325 +{
 572.326 +  UString pathName = _aPathName;
 572.327 +  int pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);
 572.328 +  if (pos > 0 && pos == pathName.Length() - 1)
 572.329 +  {
 572.330 +    if (pathName.Length() == 3 && pathName[1] == L':')
 572.331 +      return true; // Disk folder;
 572.332 +    pathName.Delete(pos);
 572.333 +  }
 572.334 +  UString pathName2 = pathName;
 572.335 +  pos = pathName.Length();
 572.336 +  for (;;)
 572.337 +  {
 572.338 +    if (MyCreateDirectory(pathName))
 572.339 +      break;
 572.340 +    if (::GetLastError() == ERROR_ALREADY_EXISTS)
 572.341 +    {
 572.342 +      NFind::CFileInfoW fileInfo;
 572.343 +      if (!NFind::FindFile(pathName, fileInfo)) // For network folders
 572.344 +        return true;
 572.345 +      if (!fileInfo.IsDir())
 572.346 +        return false;
 572.347 +      break;
 572.348 +    }
 572.349 +    pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);
 572.350 +    if (pos < 0 || pos == 0)
 572.351 +      return false;
 572.352 +    if (pathName[pos - 1] == L':')
 572.353 +      return false;
 572.354 +    pathName = pathName.Left(pos);
 572.355 +  }
 572.356 +  pathName = pathName2;
 572.357 +  while (pos < pathName.Length())
 572.358 +  {
 572.359 +    pos = pathName.Find(WCHAR_PATH_SEPARATOR, pos + 1);
 572.360 +    if (pos < 0)
 572.361 +      pos = pathName.Length();
 572.362 +    if (!MyCreateDirectory(pathName.Left(pos)))
 572.363 +      return false;
 572.364 +  }
 572.365 +  return true;
 572.366 +}
 572.367 +
 572.368 +#endif
 572.369 +
 572.370 +bool DeleteFileAlways(LPCTSTR name)
 572.371 +{
 572.372 +  if (!MySetFileAttributes(name, 0))
 572.373 +    return false;
 572.374 +  if (::DeleteFile(name))
 572.375 +    return true;
 572.376 +  #ifdef WIN_LONG_PATH2
 572.377 +  UString longPath;
 572.378 +  if (GetLongPath(name, longPath))
 572.379 +    return BOOLToBool(::DeleteFileW(longPath));
 572.380 +  #endif
 572.381 +  return false;
 572.382 +}
 572.383 +
 572.384 +#ifndef _UNICODE
 572.385 +bool DeleteFileAlways(LPCWSTR name)
 572.386 +{
 572.387 +  if (!g_IsNT)
 572.388 +    return DeleteFileAlways(GetSysPath(name));
 572.389 +  if (!MySetFileAttributes(name, 0))
 572.390 +    return false;
 572.391 +  if (::DeleteFileW(name))
 572.392 +    return true;
 572.393 +  #ifdef WIN_LONG_PATH
 572.394 +  UString longPath;
 572.395 +  if (GetLongPath(name, longPath))
 572.396 +    return BOOLToBool(::DeleteFileW(longPath));
 572.397 +  #endif
 572.398 +  return false;
 572.399 +}
 572.400 +#endif
 572.401 +
 572.402 +static bool RemoveDirectorySubItems2(const CSysString pathPrefix, const NFind::CFileInfo &fileInfo)
 572.403 +{
 572.404 +  if (fileInfo.IsDir())
 572.405 +    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);
 572.406 +  return DeleteFileAlways(pathPrefix + fileInfo.Name);
 572.407 +}
 572.408 +
 572.409 +bool RemoveDirectoryWithSubItems(const CSysString &path)
 572.410 +{
 572.411 +  NFind::CFileInfo fileInfo;
 572.412 +  CSysString pathPrefix = path + NName::kDirDelimiter;
 572.413 +  {
 572.414 +    NFind::CEnumerator enumerator(pathPrefix + TCHAR(NName::kAnyStringWildcard));
 572.415 +    while (enumerator.Next(fileInfo))
 572.416 +      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))
 572.417 +        return false;
 572.418 +  }
 572.419 +  if (!MySetFileAttributes(path, 0))
 572.420 +    return false;
 572.421 +  return MyRemoveDirectory(path);
 572.422 +}
 572.423 +
 572.424 +#ifndef _UNICODE
 572.425 +static bool RemoveDirectorySubItems2(const UString pathPrefix, const NFind::CFileInfoW &fileInfo)
 572.426 +{
 572.427 +  if (fileInfo.IsDir())
 572.428 +    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);
 572.429 +  return DeleteFileAlways(pathPrefix + fileInfo.Name);
 572.430 +}
 572.431 +bool RemoveDirectoryWithSubItems(const UString &path)
 572.432 +{
 572.433 +  NFind::CFileInfoW fileInfo;
 572.434 +  UString pathPrefix = path + UString(NName::kDirDelimiter);
 572.435 +  {
 572.436 +    NFind::CEnumeratorW enumerator(pathPrefix + UString(NName::kAnyStringWildcard));
 572.437 +    while (enumerator.Next(fileInfo))
 572.438 +      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))
 572.439 +        return false;
 572.440 +  }
 572.441 +  if (!MySetFileAttributes(path, 0))
 572.442 +    return false;
 572.443 +  return MyRemoveDirectory(path);
 572.444 +}
 572.445 +#endif
 572.446 +
 572.447 +#ifndef _WIN32_WCE
 572.448 +
 572.449 +bool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath)
 572.450 +{
 572.451 +  DWORD needLength = ::GetShortPathName(longPath, shortPath.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);
 572.452 +  shortPath.ReleaseBuffer();
 572.453 +  return (needLength > 0 && needLength < MAX_PATH);
 572.454 +}
 572.455 +
 572.456 +bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, int &fileNamePartStartIndex)
 572.457 +{
 572.458 +  resultPath.Empty();
 572.459 +  LPTSTR fileNamePointer = 0;
 572.460 +  LPTSTR buffer = resultPath.GetBuffer(MAX_PATH);
 572.461 +  DWORD needLength = ::GetFullPathName(fileName, MAX_PATH + 1, buffer, &fileNamePointer);
 572.462 +  resultPath.ReleaseBuffer();
 572.463 +  if (needLength == 0)
 572.464 +    return false;
 572.465 +  if (needLength >= MAX_PATH)
 572.466 +  {
 572.467 +    #ifdef WIN_LONG_PATH2
 572.468 +    needLength++;
 572.469 +    buffer = resultPath.GetBuffer(needLength + 1);
 572.470 +    DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);
 572.471 +    resultPath.ReleaseBuffer();
 572.472 +    if (needLength2 == 0 || needLength2 > needLength)
 572.473 +    #endif
 572.474 +      return false;
 572.475 +  }
 572.476 +  if (fileNamePointer == 0)
 572.477 +    fileNamePartStartIndex = lstrlen(fileName);
 572.478 +  else
 572.479 +    fileNamePartStartIndex = (int)(fileNamePointer - buffer);
 572.480 +  return true;
 572.481 +}
 572.482 +
 572.483 +#ifndef _UNICODE
 572.484 +bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, int &fileNamePartStartIndex)
 572.485 +{
 572.486 +  resultPath.Empty();
 572.487 +  if (g_IsNT)
 572.488 +  {
 572.489 +    LPWSTR fileNamePointer = 0;
 572.490 +    LPWSTR buffer = resultPath.GetBuffer(MAX_PATH);
 572.491 +    DWORD needLength = ::GetFullPathNameW(fileName, MAX_PATH + 1, buffer, &fileNamePointer);
 572.492 +    resultPath.ReleaseBuffer();
 572.493 +    if (needLength == 0)
 572.494 +      return false;
 572.495 +    if (needLength >= MAX_PATH)
 572.496 +    {
 572.497 +      #ifdef WIN_LONG_PATH
 572.498 +      needLength++;
 572.499 +      buffer = resultPath.GetBuffer(needLength + 1);
 572.500 +      DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);
 572.501 +      resultPath.ReleaseBuffer();
 572.502 +      if (needLength2 == 0 || needLength2 > needLength)
 572.503 +      #endif
 572.504 +        return false;
 572.505 +    }
 572.506 +    if (fileNamePointer == 0)
 572.507 +      fileNamePartStartIndex = MyStringLen(fileName);
 572.508 +    else
 572.509 +      fileNamePartStartIndex = (int)(fileNamePointer - buffer);
 572.510 +  }
 572.511 +  else
 572.512 +  {
 572.513 +    CSysString sysPath;
 572.514 +    if (!MyGetFullPathName(GetSysPath(fileName), sysPath, fileNamePartStartIndex))
 572.515 +      return false;
 572.516 +    UString resultPath1 = GetUnicodePath(sysPath.Left(fileNamePartStartIndex));
 572.517 +    UString resultPath2 = GetUnicodePath(sysPath.Mid(fileNamePartStartIndex));
 572.518 +    fileNamePartStartIndex = resultPath1.Length();
 572.519 +    resultPath = resultPath1 + resultPath2;
 572.520 +  }
 572.521 +  return true;
 572.522 +}
 572.523 +#endif
 572.524 +
 572.525 +
 572.526 +bool MyGetFullPathName(LPCTSTR fileName, CSysString &path)
 572.527 +{
 572.528 +  int index;
 572.529 +  return MyGetFullPathName(fileName, path, index);
 572.530 +}
 572.531 +
 572.532 +#ifndef _UNICODE
 572.533 +bool MyGetFullPathName(LPCWSTR fileName, UString &path)
 572.534 +{
 572.535 +  int index;
 572.536 +  return MyGetFullPathName(fileName, path, index);
 572.537 +}
 572.538 +#endif
 572.539 +
 572.540 +bool GetOnlyName(LPCTSTR fileName, CSysString &resultName)
 572.541 +{
 572.542 +  int index;
 572.543 +  if (!MyGetFullPathName(fileName, resultName, index))
 572.544 +    return false;
 572.545 +  resultName = resultName.Mid(index);
 572.546 +  return true;
 572.547 +}
 572.548 +
 572.549 +#ifndef _UNICODE
 572.550 +bool GetOnlyName(LPCWSTR fileName, UString &resultName)
 572.551 +{
 572.552 +  int index;
 572.553 +  if (!MyGetFullPathName(fileName, resultName, index))
 572.554 +    return false;
 572.555 +  resultName = resultName.Mid(index);
 572.556 +  return true;
 572.557 +}
 572.558 +#endif
 572.559 +
 572.560 +bool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName)
 572.561 +{
 572.562 +  int index;
 572.563 +  if (!MyGetFullPathName(fileName, resultName, index))
 572.564 +    return false;
 572.565 +  resultName = resultName.Left(index);
 572.566 +  return true;
 572.567 +}
 572.568 +
 572.569 +#ifndef _UNICODE
 572.570 +bool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName)
 572.571 +{
 572.572 +  int index;
 572.573 +  if (!MyGetFullPathName(fileName, resultName, index))
 572.574 +    return false;
 572.575 +  resultName = resultName.Left(index);
 572.576 +  return true;
 572.577 +}
 572.578 +#endif
 572.579 +
 572.580 +bool MyGetCurrentDirectory(CSysString &path)
 572.581 +{
 572.582 +  DWORD needLength = ::GetCurrentDirectory(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));
 572.583 +  path.ReleaseBuffer();
 572.584 +  return (needLength > 0 && needLength <= MAX_PATH);
 572.585 +}
 572.586 +
 572.587 +#ifndef _UNICODE
 572.588 +bool MySetCurrentDirectory(LPCWSTR path)
 572.589 +{
 572.590 +  if (g_IsNT)
 572.591 +    return BOOLToBool(::SetCurrentDirectoryW(path));
 572.592 +  return MySetCurrentDirectory(GetSysPath(path));
 572.593 +}
 572.594 +bool MyGetCurrentDirectory(UString &path)
 572.595 +{
 572.596 +  if (g_IsNT)
 572.597 +  {
 572.598 +    DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));
 572.599 +    path.ReleaseBuffer();
 572.600 +    return (needLength > 0 && needLength <= MAX_PATH);
 572.601 +  }
 572.602 +  CSysString sysPath;
 572.603 +  if (!MyGetCurrentDirectory(sysPath))
 572.604 +    return false;
 572.605 +  path = GetUnicodePath(sysPath);
 572.606 +  return true;
 572.607 +}
 572.608 +#endif
 572.609 +#endif
 572.610 +
 572.611 +bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,
 572.612 +  CSysString &resultPath, UINT32 &filePart)
 572.613 +{
 572.614 +  LPTSTR filePartPointer;
 572.615 +  DWORD value = ::SearchPath(path, fileName, extension,
 572.616 +    MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);
 572.617 +  filePart = (UINT32)(filePartPointer - (LPCTSTR)resultPath);
 572.618 +  resultPath.ReleaseBuffer();
 572.619 +  return (value > 0 && value <= MAX_PATH);
 572.620 +}
 572.621 +
 572.622 +#ifndef _UNICODE
 572.623 +bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,
 572.624 +  UString &resultPath, UINT32 &filePart)
 572.625 +{
 572.626 +  if (g_IsNT)
 572.627 +  {
 572.628 +    LPWSTR filePartPointer = 0;
 572.629 +    DWORD value = ::SearchPathW(path, fileName, extension,
 572.630 +        MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);
 572.631 +    filePart = (UINT32)(filePartPointer - (LPCWSTR)resultPath);
 572.632 +    resultPath.ReleaseBuffer();
 572.633 +    return (value > 0 && value <= MAX_PATH);
 572.634 +  }
 572.635 +  
 572.636 +  CSysString sysPath;
 572.637 +  if (!MySearchPath(
 572.638 +      path != 0 ? (LPCTSTR)GetSysPath(path): 0,
 572.639 +      fileName != 0 ? (LPCTSTR)GetSysPath(fileName): 0,
 572.640 +      extension != 0 ? (LPCTSTR)GetSysPath(extension): 0,
 572.641 +      sysPath, filePart))
 572.642 +    return false;
 572.643 +  UString resultPath1 = GetUnicodePath(sysPath.Left(filePart));
 572.644 +  UString resultPath2 = GetUnicodePath(sysPath.Mid(filePart));
 572.645 +  filePart = resultPath1.Length();
 572.646 +  resultPath = resultPath1 + resultPath2;
 572.647 +  return true;
 572.648 +}
 572.649 +#endif
 572.650 +
 572.651 +bool MyGetTempPath(CSysString &path)
 572.652 +{
 572.653 +  DWORD needLength = ::GetTempPath(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));
 572.654 +  path.ReleaseBuffer();
 572.655 +  return (needLength > 0 && needLength <= MAX_PATH);
 572.656 +}
 572.657 +
 572.658 +#ifndef _UNICODE
 572.659 +bool MyGetTempPath(UString &path)
 572.660 +{
 572.661 +  path.Empty();
 572.662 +  if (g_IsNT)
 572.663 +  {
 572.664 +    DWORD needLength = ::GetTempPathW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));
 572.665 +    path.ReleaseBuffer();
 572.666 +    return (needLength > 0 && needLength <= MAX_PATH);
 572.667 +  }
 572.668 +  CSysString sysPath;
 572.669 +  if (!MyGetTempPath(sysPath))
 572.670 +    return false;
 572.671 +  path = GetUnicodePath(sysPath);
 572.672 +  return true;
 572.673 +}
 572.674 +#endif
 572.675 +
 572.676 +UINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &path)
 572.677 +{
 572.678 +  UINT number = ::GetTempFileName(dirPath, prefix, 0, path.GetBuffer(MAX_PATH + 1));
 572.679 +  path.ReleaseBuffer();
 572.680 +  return number;
 572.681 +}
 572.682 +
 572.683 +#ifndef _UNICODE
 572.684 +UINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &path)
 572.685 +{
 572.686 +  if (g_IsNT)
 572.687 +  {
 572.688 +    UINT number = ::GetTempFileNameW(dirPath, prefix, 0, path.GetBuffer(MAX_PATH));
 572.689 +    path.ReleaseBuffer();
 572.690 +    return number;
 572.691 +  }
 572.692 +  CSysString sysPath;
 572.693 +  UINT number = MyGetTempFileName(
 572.694 +      dirPath ? (LPCTSTR)GetSysPath(dirPath): 0,
 572.695 +      prefix ? (LPCTSTR)GetSysPath(prefix): 0,
 572.696 +      sysPath);
 572.697 +  path = GetUnicodePath(sysPath);
 572.698 +  return number;
 572.699 +}
 572.700 +#endif
 572.701 +
 572.702 +UINT CTempFile::Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath)
 572.703 +{
 572.704 +  Remove();
 572.705 +  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);
 572.706 +  if (number != 0)
 572.707 +  {
 572.708 +    _fileName = resultPath;
 572.709 +    _mustBeDeleted = true;
 572.710 +  }
 572.711 +  return number;
 572.712 +}
 572.713 +
 572.714 +bool CTempFile::Create(LPCTSTR prefix, CSysString &resultPath)
 572.715 +{
 572.716 +  CSysString tempPath;
 572.717 +  if (!MyGetTempPath(tempPath))
 572.718 +    return false;
 572.719 +  if (Create(tempPath, prefix, resultPath) != 0)
 572.720 +    return true;
 572.721 +  if (!MyGetWindowsDirectory(tempPath))
 572.722 +    return false;
 572.723 +  return (Create(tempPath, prefix, resultPath) != 0);
 572.724 +}
 572.725 +
 572.726 +bool CTempFile::Remove()
 572.727 +{
 572.728 +  if (!_mustBeDeleted)
 572.729 +    return true;
 572.730 +  _mustBeDeleted = !DeleteFileAlways(_fileName);
 572.731 +  return !_mustBeDeleted;
 572.732 +}
 572.733 +
 572.734 +#ifndef _UNICODE
 572.735 +
 572.736 +UINT CTempFileW::Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath)
 572.737 +{
 572.738 +  Remove();
 572.739 +  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);
 572.740 +  if (number != 0)
 572.741 +  {
 572.742 +    _fileName = resultPath;
 572.743 +    _mustBeDeleted = true;
 572.744 +  }
 572.745 +  return number;
 572.746 +}
 572.747 +
 572.748 +bool CTempFileW::Create(LPCWSTR prefix, UString &resultPath)
 572.749 +{
 572.750 +  UString tempPath;
 572.751 +  if (!MyGetTempPath(tempPath))
 572.752 +    return false;
 572.753 +  if (Create(tempPath, prefix, resultPath) != 0)
 572.754 +    return true;
 572.755 +  if (!MyGetWindowsDirectory(tempPath))
 572.756 +    return false;
 572.757 +  return (Create(tempPath, prefix, resultPath) != 0);
 572.758 +}
 572.759 +
 572.760 +bool CTempFileW::Remove()
 572.761 +{
 572.762 +  if (!_mustBeDeleted)
 572.763 +    return true;
 572.764 +  _mustBeDeleted = !DeleteFileAlways(_fileName);
 572.765 +  return !_mustBeDeleted;
 572.766 +}
 572.767 +
 572.768 +#endif
 572.769 +
 572.770 +bool CreateTempDirectory(LPCTSTR prefix, CSysString &dirName)
 572.771 +{
 572.772 +  /*
 572.773 +  CSysString prefix = tempPath + prefixChars;
 572.774 +  CRandom random;
 572.775 +  random.Init();
 572.776 +  */
 572.777 +  for (;;)
 572.778 +  {
 572.779 +    CTempFile tempFile;
 572.780 +    if (!tempFile.Create(prefix, dirName))
 572.781 +      return false;
 572.782 +    if (!::DeleteFile(dirName))
 572.783 +      return false;
 572.784 +    /*
 572.785 +    UINT32 randomNumber = random.Generate();
 572.786 +    TCHAR randomNumberString[32];
 572.787 +    _stprintf(randomNumberString, _T("%04X"), randomNumber);
 572.788 +    dirName = prefix + randomNumberString;
 572.789 +    */
 572.790 +    if (NFind::DoesFileExist(dirName))
 572.791 +      continue;
 572.792 +    if (MyCreateDirectory(dirName))
 572.793 +      return true;
 572.794 +    if (::GetLastError() != ERROR_ALREADY_EXISTS)
 572.795 +      return false;
 572.796 +  }
 572.797 +}
 572.798 +
 572.799 +bool CTempDirectory::Create(LPCTSTR prefix)
 572.800 +{
 572.801 +  Remove();
 572.802 +  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir));
 572.803 +}
 572.804 +
 572.805 +#ifndef _UNICODE
 572.806 +
 572.807 +bool CreateTempDirectory(LPCWSTR prefix, UString &dirName)
 572.808 +{
 572.809 +  /*
 572.810 +  CSysString prefix = tempPath + prefixChars;
 572.811 +  CRandom random;
 572.812 +  random.Init();
 572.813 +  */
 572.814 +  for (;;)
 572.815 +  {
 572.816 +    CTempFileW tempFile;
 572.817 +    if (!tempFile.Create(prefix, dirName))
 572.818 +      return false;
 572.819 +    if (!DeleteFileAlways(dirName))
 572.820 +      return false;
 572.821 +    /*
 572.822 +    UINT32 randomNumber = random.Generate();
 572.823 +    TCHAR randomNumberString[32];
 572.824 +    _stprintf(randomNumberString, _T("%04X"), randomNumber);
 572.825 +    dirName = prefix + randomNumberString;
 572.826 +    */
 572.827 +    if (NFind::DoesFileExist(dirName))
 572.828 +      continue;
 572.829 +    if (MyCreateDirectory(dirName))
 572.830 +      return true;
 572.831 +    if (::GetLastError() != ERROR_ALREADY_EXISTS)
 572.832 +      return false;
 572.833 +  }
 572.834 +}
 572.835 +
 572.836 +bool CTempDirectoryW::Create(LPCWSTR prefix)
 572.837 +{
 572.838 +  Remove();
 572.839 +  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir));
 572.840 +}
 572.841 +
 572.842 +#endif
 572.843 +
 572.844 +}}}
   573.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   573.2 +++ b/src/win32/7zip/7z/CPP/Windows/FileDir.h	Sat Mar 03 10:31:27 2012 -0600
   573.3 @@ -0,0 +1,178 @@
   573.4 +// Windows/FileDir.h
   573.5 +
   573.6 +#ifndef __WINDOWS_FILEDIR_H
   573.7 +#define __WINDOWS_FILEDIR_H
   573.8 +
   573.9 +#include "../Common/MyString.h"
  573.10 +#include "Defs.h"
  573.11 +
  573.12 +namespace NWindows {
  573.13 +namespace NFile {
  573.14 +namespace NDirectory {
  573.15 +
  573.16 +#ifdef WIN_LONG_PATH
  573.17 +bool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2);
  573.18 +#endif
  573.19 +
  573.20 +bool MyGetWindowsDirectory(CSysString &path);
  573.21 +bool MyGetSystemDirectory(CSysString &path);
  573.22 +#ifndef _UNICODE
  573.23 +bool MyGetWindowsDirectory(UString &path);
  573.24 +bool MyGetSystemDirectory(UString &path);
  573.25 +#endif
  573.26 +
  573.27 +bool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);
  573.28 +
  573.29 +bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes);
  573.30 +bool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName);
  573.31 +bool MyRemoveDirectory(LPCTSTR pathName);
  573.32 +bool MyCreateDirectory(LPCTSTR pathName);
  573.33 +bool CreateComplexDirectory(LPCTSTR pathName);
  573.34 +bool DeleteFileAlways(LPCTSTR name);
  573.35 +bool RemoveDirectoryWithSubItems(const CSysString &path);
  573.36 +
  573.37 +#ifndef _UNICODE
  573.38 +bool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes);
  573.39 +bool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName);
  573.40 +bool MyRemoveDirectory(LPCWSTR pathName);
  573.41 +bool MyCreateDirectory(LPCWSTR pathName);
  573.42 +bool CreateComplexDirectory(LPCWSTR pathName);
  573.43 +bool DeleteFileAlways(LPCWSTR name);
  573.44 +bool RemoveDirectoryWithSubItems(const UString &path);
  573.45 +#endif
  573.46 +
  573.47 +#ifndef _WIN32_WCE
  573.48 +bool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath);
  573.49 +
  573.50 +bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath,
  573.51 +    int &fileNamePartStartIndex);
  573.52 +bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath);
  573.53 +bool GetOnlyName(LPCTSTR fileName, CSysString &resultName);
  573.54 +bool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName);
  573.55 +#ifndef _UNICODE
  573.56 +bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath,
  573.57 +    int &fileNamePartStartIndex);
  573.58 +bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath);
  573.59 +bool GetOnlyName(LPCWSTR fileName, UString &resultName);
  573.60 +bool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName);
  573.61 +#endif
  573.62 +
  573.63 +inline bool MySetCurrentDirectory(LPCTSTR path)
  573.64 +  { return BOOLToBool(::SetCurrentDirectory(path)); }
  573.65 +bool MyGetCurrentDirectory(CSysString &resultPath);
  573.66 +#ifndef _UNICODE
  573.67 +bool MySetCurrentDirectory(LPCWSTR path);
  573.68 +bool MyGetCurrentDirectory(UString &resultPath);
  573.69 +#endif
  573.70 +#endif
  573.71 +
  573.72 +bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,
  573.73 +  CSysString &resultPath, UINT32 &filePart);
  573.74 +#ifndef _UNICODE
  573.75 +bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,
  573.76 +  UString &resultPath, UINT32 &filePart);
  573.77 +#endif
  573.78 +
  573.79 +inline bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,
  573.80 +  CSysString &resultPath)
  573.81 +{
  573.82 +  UINT32 value;
  573.83 +  return MySearchPath(path, fileName, extension, resultPath, value);
  573.84 +}
  573.85 +
  573.86 +#ifndef _UNICODE
  573.87 +inline bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,
  573.88 +  UString &resultPath)
  573.89 +{
  573.90 +  UINT32 value;
  573.91 +  return MySearchPath(path, fileName, extension, resultPath, value);
  573.92 +}
  573.93 +#endif
  573.94 +
  573.95 +bool MyGetTempPath(CSysString &resultPath);
  573.96 +#ifndef _UNICODE
  573.97 +bool MyGetTempPath(UString &resultPath);
  573.98 +#endif
  573.99 +
 573.100 +UINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);
 573.101 +#ifndef _UNICODE
 573.102 +UINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);
 573.103 +#endif
 573.104 +
 573.105 +class CTempFile
 573.106 +{
 573.107 +  bool _mustBeDeleted;
 573.108 +  CSysString _fileName;
 573.109 +public:
 573.110 +  CTempFile(): _mustBeDeleted(false) {}
 573.111 +  ~CTempFile() { Remove(); }
 573.112 +  void DisableDeleting() { _mustBeDeleted = false; }
 573.113 +  UINT Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);
 573.114 +  bool Create(LPCTSTR prefix, CSysString &resultPath);
 573.115 +  bool Remove();
 573.116 +};
 573.117 +
 573.118 +#ifdef _UNICODE
 573.119 +typedef CTempFile CTempFileW;
 573.120 +#else
 573.121 +class CTempFileW
 573.122 +{
 573.123 +  bool _mustBeDeleted;
 573.124 +  UString _fileName;
 573.125 +public:
 573.126 +  CTempFileW(): _mustBeDeleted(false) {}
 573.127 +  ~CTempFileW() { Remove(); }
 573.128 +  void DisableDeleting() { _mustBeDeleted = false; }
 573.129 +  UINT Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);
 573.130 +  bool Create(LPCWSTR prefix, UString &resultPath);
 573.131 +  bool Remove();
 573.132 +};
 573.133 +#endif
 573.134 +
 573.135 +bool CreateTempDirectory(LPCTSTR prefixChars, CSysString &dirName);
 573.136 +
 573.137 +class CTempDirectory
 573.138 +{
 573.139 +  bool _mustBeDeleted;
 573.140 +  CSysString _tempDir;
 573.141 +public:
 573.142 +  const CSysString &GetPath() const { return _tempDir; }
 573.143 +  CTempDirectory(): _mustBeDeleted(false) {}
 573.144 +  ~CTempDirectory() { Remove();  }
 573.145 +  bool Create(LPCTSTR prefix) ;
 573.146 +  bool Remove()
 573.147 +  {
 573.148 +    if (!_mustBeDeleted)
 573.149 +      return true;
 573.150 +    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);
 573.151 +    return (!_mustBeDeleted);
 573.152 +  }
 573.153 +  void DisableDeleting() { _mustBeDeleted = false; }
 573.154 +};
 573.155 +
 573.156 +#ifdef _UNICODE
 573.157 +typedef CTempDirectory CTempDirectoryW;
 573.158 +#else
 573.159 +class CTempDirectoryW
 573.160 +{
 573.161 +  bool _mustBeDeleted;
 573.162 +  UString _tempDir;
 573.163 +public:
 573.164 +  const UString &GetPath() const { return _tempDir; }
 573.165 +  CTempDirectoryW(): _mustBeDeleted(false) {}
 573.166 +  ~CTempDirectoryW() { Remove();  }
 573.167 +  bool Create(LPCWSTR prefix) ;
 573.168 +  bool Remove()
 573.169 +  {
 573.170 +    if (!_mustBeDeleted)
 573.171 +      return true;
 573.172 +    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);
 573.173 +    return (!_mustBeDeleted);
 573.174 +  }
 573.175 +  void DisableDeleting() { _mustBeDeleted = false; }
 573.176 +};
 573.177 +#endif
 573.178 +
 573.179 +}}}
 573.180 +
 573.181 +#endif
   574.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   574.2 +++ b/src/win32/7zip/7z/CPP/Windows/FileFind.cpp	Sat Mar 03 10:31:27 2012 -0600
   574.3 @@ -0,0 +1,402 @@
   574.4 +// Windows/FileFind.cpp
   574.5 +
   574.6 +#include "StdAfx.h"
   574.7 +
   574.8 +#include "FileFind.h"
   574.9 +#ifndef _UNICODE
  574.10 +#include "../Common/StringConvert.h"
  574.11 +#endif
  574.12 +
  574.13 +#ifndef _UNICODE
  574.14 +extern bool g_IsNT;
  574.15 +#endif
  574.16 +
  574.17 +namespace NWindows {
  574.18 +namespace NFile {
  574.19 +
  574.20 +#if defined(WIN_LONG_PATH) && defined(_UNICODE)
  574.21 +#define WIN_LONG_PATH2
  574.22 +#endif
  574.23 +
  574.24 +bool GetLongPath(LPCWSTR fileName, UString &res);
  574.25 +
  574.26 +namespace NFind {
  574.27 +
  574.28 +static const TCHAR kDot = TEXT('.');
  574.29 +
  574.30 +bool CFileInfo::IsDots() const
  574.31 +{
  574.32 +  if (!IsDir() || Name.IsEmpty())
  574.33 +    return false;
  574.34 +  if (Name[0] != kDot)
  574.35 +    return false;
  574.36 +  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);
  574.37 +}
  574.38 +
  574.39 +#ifndef _UNICODE
  574.40 +bool CFileInfoW::IsDots() const
  574.41 +{
  574.42 +  if (!IsDir() || Name.IsEmpty())
  574.43 +    return false;
  574.44 +  if (Name[0] != kDot)
  574.45 +    return false;
  574.46 +  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);
  574.47 +}
  574.48 +#endif
  574.49 +
  574.50 +static void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfo &fi)
  574.51 +{
  574.52 +  fi.Attrib = fd.dwFileAttributes;
  574.53 +  fi.CTime = fd.ftCreationTime;
  574.54 +  fi.ATime = fd.ftLastAccessTime;
  574.55 +  fi.MTime = fd.ftLastWriteTime;
  574.56 +  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;
  574.57 +  fi.Name = fd.cFileName;
  574.58 +  #ifndef _WIN32_WCE
  574.59 +  fi.ReparseTag = fd.dwReserved0;
  574.60 +  #else
  574.61 +  fi.ObjectID = fd.dwOID;
  574.62 +  #endif
  574.63 +}
  574.64 +
  574.65 +#ifndef _UNICODE
  574.66 +
  574.67 +static inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
  574.68 +
  574.69 +static void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATAW &fd, CFileInfoW &fi)
  574.70 +{
  574.71 +  fi.Attrib = fd.dwFileAttributes;
  574.72 +  fi.CTime = fd.ftCreationTime;
  574.73 +  fi.ATime = fd.ftLastAccessTime;
  574.74 +  fi.MTime = fd.ftLastWriteTime;
  574.75 +  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;
  574.76 +  fi.Name = fd.cFileName;
  574.77 +  #ifndef _WIN32_WCE
  574.78 +  fi.ReparseTag = fd.dwReserved0;
  574.79 +  #else
  574.80 +  fi.ObjectID = fd.dwOID;
  574.81 +  #endif
  574.82 +}
  574.83 +
  574.84 +static void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfoW &fi)
  574.85 +{
  574.86 +  fi.Attrib = fd.dwFileAttributes;
  574.87 +  fi.CTime = fd.ftCreationTime;
  574.88 +  fi.ATime = fd.ftLastAccessTime;
  574.89 +  fi.MTime = fd.ftLastWriteTime;
  574.90 +  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;
  574.91 +  fi.Name = GetUnicodeString(fd.cFileName, GetCurrentCodePage());
  574.92 +  #ifndef _WIN32_WCE
  574.93 +  fi.ReparseTag = fd.dwReserved0;
  574.94 +  #else
  574.95 +  fi.ObjectID = fd.dwOID;
  574.96 +  #endif
  574.97 +}
  574.98 +#endif
  574.99 +  
 574.100 +////////////////////////////////
 574.101 +// CFindFile
 574.102 +
 574.103 +bool CFindFile::Close()
 574.104 +{
 574.105 +  if (_handle == INVALID_HANDLE_VALUE)
 574.106 +    return true;
 574.107 +  if (!::FindClose(_handle))
 574.108 +    return false;
 574.109 +  _handle = INVALID_HANDLE_VALUE;
 574.110 +  return true;
 574.111 +}
 574.112 +
 574.113 +          
 574.114 +bool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo)
 574.115 +{
 574.116 +  if (!Close())
 574.117 +    return false;
 574.118 +  WIN32_FIND_DATA fd;
 574.119 +  _handle = ::FindFirstFile(wildcard, &fd);
 574.120 +  #ifdef WIN_LONG_PATH2
 574.121 +  if (_handle == INVALID_HANDLE_VALUE)
 574.122 +  {
 574.123 +    UString longPath;
 574.124 +    if (GetLongPath(wildcard, longPath))
 574.125 +      _handle = ::FindFirstFileW(longPath, &fd);
 574.126 +  }
 574.127 +  #endif
 574.128 +  if (_handle == INVALID_HANDLE_VALUE)
 574.129 +    return false;
 574.130 +  ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);
 574.131 +  return true;
 574.132 +}
 574.133 +
 574.134 +#ifndef _UNICODE
 574.135 +bool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo)
 574.136 +{
 574.137 +  if (!Close())
 574.138 +    return false;
 574.139 +  if (g_IsNT)
 574.140 +  {
 574.141 +    WIN32_FIND_DATAW fd;
 574.142 +    _handle = ::FindFirstFileW(wildcard, &fd);
 574.143 +    #ifdef WIN_LONG_PATH
 574.144 +    if (_handle == INVALID_HANDLE_VALUE)
 574.145 +    {
 574.146 +      UString longPath;
 574.147 +      if (GetLongPath(wildcard, longPath))
 574.148 +        _handle = ::FindFirstFileW(longPath, &fd);
 574.149 +    }
 574.150 +    #endif
 574.151 +    if (_handle != INVALID_HANDLE_VALUE)
 574.152 +      ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);
 574.153 +  }
 574.154 +  else
 574.155 +  {
 574.156 +    WIN32_FIND_DATAA fd;
 574.157 +    _handle = ::FindFirstFileA(UnicodeStringToMultiByte(wildcard,
 574.158 +        GetCurrentCodePage()), &fd);
 574.159 +    if (_handle != INVALID_HANDLE_VALUE)
 574.160 +      ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);
 574.161 +  }
 574.162 +  return (_handle != INVALID_HANDLE_VALUE);
 574.163 +}
 574.164 +#endif
 574.165 +
 574.166 +bool CFindFile::FindNext(CFileInfo &fileInfo)
 574.167 +{
 574.168 +  WIN32_FIND_DATA fd;
 574.169 +  bool result = BOOLToBool(::FindNextFile(_handle, &fd));
 574.170 +  if (result)
 574.171 +    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);
 574.172 +  return result;
 574.173 +}
 574.174 +
 574.175 +#ifndef _UNICODE
 574.176 +bool CFindFile::FindNext(CFileInfoW &fileInfo)
 574.177 +{
 574.178 +  if (g_IsNT)
 574.179 +  {
 574.180 +    WIN32_FIND_DATAW fd;
 574.181 +    if (!::FindNextFileW(_handle, &fd))
 574.182 +      return false;
 574.183 +    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);
 574.184 +  }
 574.185 +  else
 574.186 +  {
 574.187 +    WIN32_FIND_DATAA fd;
 574.188 +    if (!::FindNextFileA(_handle, &fd))
 574.189 +      return false;
 574.190 +    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);
 574.191 +  }
 574.192 +  return true;
 574.193 +}
 574.194 +#endif
 574.195 +
 574.196 +bool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo)
 574.197 +{
 574.198 +  CFindFile finder;
 574.199 +  return finder.FindFirst(wildcard, fileInfo);
 574.200 +}
 574.201 +
 574.202 +#ifndef _UNICODE
 574.203 +bool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo)
 574.204 +{
 574.205 +  CFindFile finder;
 574.206 +  return finder.FindFirst(wildcard, fileInfo);
 574.207 +}
 574.208 +#endif
 574.209 +
 574.210 +bool DoesFileExist(LPCTSTR name)
 574.211 +{
 574.212 +  CFileInfo fileInfo;
 574.213 +  return FindFile(name, fileInfo);
 574.214 +}
 574.215 +
 574.216 +#ifndef _UNICODE
 574.217 +bool DoesFileExist(LPCWSTR name)
 574.218 +{
 574.219 +  CFileInfoW fileInfo;
 574.220 +  return FindFile(name, fileInfo);
 574.221 +}
 574.222 +#endif
 574.223 +
 574.224 +/////////////////////////////////////
 574.225 +// CEnumerator
 574.226 +
 574.227 +bool CEnumerator::NextAny(CFileInfo &fileInfo)
 574.228 +{
 574.229 +  if (_findFile.IsHandleAllocated())
 574.230 +    return _findFile.FindNext(fileInfo);
 574.231 +  else
 574.232 +    return _findFile.FindFirst(_wildcard, fileInfo);
 574.233 +}
 574.234 +
 574.235 +bool CEnumerator::Next(CFileInfo &fileInfo)
 574.236 +{
 574.237 +  for (;;)
 574.238 +  {
 574.239 +    if (!NextAny(fileInfo))
 574.240 +      return false;
 574.241 +    if (!fileInfo.IsDots())
 574.242 +      return true;
 574.243 +  }
 574.244 +}
 574.245 +
 574.246 +bool CEnumerator::Next(CFileInfo &fileInfo, bool &found)
 574.247 +{
 574.248 +  if (Next(fileInfo))
 574.249 +  {
 574.250 +    found = true;
 574.251 +    return true;
 574.252 +  }
 574.253 +  found = false;
 574.254 +  return (::GetLastError() == ERROR_NO_MORE_FILES);
 574.255 +}
 574.256 +
 574.257 +#ifndef _UNICODE
 574.258 +bool CEnumeratorW::NextAny(CFileInfoW &fileInfo)
 574.259 +{
 574.260 +  if (_findFile.IsHandleAllocated())
 574.261 +    return _findFile.FindNext(fileInfo);
 574.262 +  else
 574.263 +    return _findFile.FindFirst(_wildcard, fileInfo);
 574.264 +}
 574.265 +
 574.266 +bool CEnumeratorW::Next(CFileInfoW &fileInfo)
 574.267 +{
 574.268 +  for (;;)
 574.269 +  {
 574.270 +    if (!NextAny(fileInfo))
 574.271 +      return false;
 574.272 +    if (!fileInfo.IsDots())
 574.273 +      return true;
 574.274 +  }
 574.275 +}
 574.276 +
 574.277 +bool CEnumeratorW::Next(CFileInfoW &fileInfo, bool &found)
 574.278 +{
 574.279 +  if (Next(fileInfo))
 574.280 +  {
 574.281 +    found = true;
 574.282 +    return true;
 574.283 +  }
 574.284 +  found = false;
 574.285 +  return (::GetLastError() == ERROR_NO_MORE_FILES);
 574.286 +}
 574.287 +
 574.288 +#endif
 574.289 +
 574.290 +////////////////////////////////
 574.291 +// CFindChangeNotification
 574.292 +// FindFirstChangeNotification can return 0. MSDN doesn't tell about it.
 574.293 +
 574.294 +bool CFindChangeNotification::Close()
 574.295 +{
 574.296 +  if (!IsHandleAllocated())
 574.297 +    return true;
 574.298 +  if (!::FindCloseChangeNotification(_handle))
 574.299 +    return false;
 574.300 +  _handle = INVALID_HANDLE_VALUE;
 574.301 +  return true;
 574.302 +}
 574.303 +           
 574.304 +HANDLE CFindChangeNotification::FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter)
 574.305 +{
 574.306 +  _handle = ::FindFirstChangeNotification(pathName, BoolToBOOL(watchSubtree), notifyFilter);
 574.307 +  #ifdef WIN_LONG_PATH2
 574.308 +  if (!IsHandleAllocated())
 574.309 +  {
 574.310 +    UString longPath;
 574.311 +    if (GetLongPath(pathName, longPath))
 574.312 +      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);
 574.313 +  }
 574.314 +  #endif
 574.315 +  return _handle;
 574.316 +}
 574.317 +
 574.318 +#ifndef _UNICODE
 574.319 +HANDLE CFindChangeNotification::FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter)
 574.320 +{
 574.321 +  if (!g_IsNT)
 574.322 +    return FindFirst(UnicodeStringToMultiByte(pathName, GetCurrentCodePage()), watchSubtree, notifyFilter);
 574.323 +  _handle = ::FindFirstChangeNotificationW(pathName, BoolToBOOL(watchSubtree), notifyFilter);
 574.324 +  #ifdef WIN_LONG_PATH
 574.325 +  if (!IsHandleAllocated())
 574.326 +  {
 574.327 +    UString longPath;
 574.328 +    if (GetLongPath(pathName, longPath))
 574.329 +      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);
 574.330 +  }
 574.331 +  #endif
 574.332 +  return _handle;
 574.333 +}
 574.334 +#endif
 574.335 +
 574.336 +#ifndef _WIN32_WCE
 574.337 +bool MyGetLogicalDriveStrings(CSysStringVector &driveStrings)
 574.338 +{
 574.339 +  driveStrings.Clear();
 574.340 +  UINT32 size = GetLogicalDriveStrings(0, NULL);
 574.341 +  if (size == 0)
 574.342 +    return false;
 574.343 +  CSysString buffer;
 574.344 +  UINT32 newSize = GetLogicalDriveStrings(size, buffer.GetBuffer(size));
 574.345 +  if (newSize == 0)
 574.346 +    return false;
 574.347 +  if (newSize > size)
 574.348 +    return false;
 574.349 +  CSysString string;
 574.350 +  for (UINT32 i = 0; i < newSize; i++)
 574.351 +  {
 574.352 +    TCHAR c = buffer[i];
 574.353 +    if (c == TEXT('\0'))
 574.354 +    {
 574.355 +      driveStrings.Add(string);
 574.356 +      string.Empty();
 574.357 +    }
 574.358 +    else
 574.359 +      string += c;
 574.360 +  }
 574.361 +  if (!string.IsEmpty())
 574.362 +    return false;
 574.363 +  return true;
 574.364 +}
 574.365 +
 574.366 +#ifndef _UNICODE
 574.367 +bool MyGetLogicalDriveStrings(UStringVector &driveStrings)
 574.368 +{
 574.369 +  driveStrings.Clear();
 574.370 +  if (g_IsNT)
 574.371 +  {
 574.372 +    UINT32 size = GetLogicalDriveStringsW(0, NULL);
 574.373 +    if (size == 0)
 574.374 +      return false;
 574.375 +    UString buffer;
 574.376 +    UINT32 newSize = GetLogicalDriveStringsW(size, buffer.GetBuffer(size));
 574.377 +    if (newSize == 0)
 574.378 +      return false;
 574.379 +    if (newSize > size)
 574.380 +      return false;
 574.381 +    UString string;
 574.382 +    for (UINT32 i = 0; i < newSize; i++)
 574.383 +    {
 574.384 +      WCHAR c = buffer[i];
 574.385 +      if (c == L'\0')
 574.386 +      {
 574.387 +        driveStrings.Add(string);
 574.388 +        string.Empty();
 574.389 +      }
 574.390 +      else
 574.391 +        string += c;
 574.392 +    }
 574.393 +    return string.IsEmpty();
 574.394 +  }
 574.395 +  CSysStringVector driveStringsA;
 574.396 +  bool res = MyGetLogicalDriveStrings(driveStringsA);
 574.397 +  for (int i = 0; i < driveStringsA.Size(); i++)
 574.398 +    driveStrings.Add(GetUnicodeString(driveStringsA[i]));
 574.399 +  return res;
 574.400 +}
 574.401 +#endif
 574.402 +
 574.403 +#endif
 574.404 +
 574.405 +}}}
   575.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   575.2 +++ b/src/win32/7zip/7z/CPP/Windows/FileFind.h	Sat Mar 03 10:31:27 2012 -0600
   575.3 @@ -0,0 +1,153 @@
   575.4 +// Windows/FileFind.h
   575.5 +
   575.6 +#ifndef __WINDOWS_FILEFIND_H
   575.7 +#define __WINDOWS_FILEFIND_H
   575.8 +
   575.9 +#include "../Common/MyString.h"
  575.10 +#include "../Common/Types.h"
  575.11 +#include "FileName.h"
  575.12 +#include "Defs.h"
  575.13 +
  575.14 +namespace NWindows {
  575.15 +namespace NFile {
  575.16 +namespace NFind {
  575.17 +
  575.18 +namespace NAttributes
  575.19 +{
  575.20 +  inline bool IsReadOnly(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_READONLY) != 0; }
  575.21 +  inline bool IsHidden(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_HIDDEN) != 0; }
  575.22 +  inline bool IsSystem(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_SYSTEM) != 0; }
  575.23 +  inline bool IsDir(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0; }
  575.24 +  inline bool IsArchived(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ARCHIVE) != 0; }
  575.25 +  inline bool IsCompressed(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_COMPRESSED) != 0; }
  575.26 +  inline bool IsEncrypted(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ENCRYPTED) != 0; }
  575.27 +}
  575.28 +
  575.29 +class CFileInfoBase
  575.30 +{
  575.31 +  bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); }
  575.32 +public:
  575.33 +  UInt64 Size;
  575.34 +  FILETIME CTime;
  575.35 +  FILETIME ATime;
  575.36 +  FILETIME MTime;
  575.37 +  DWORD Attrib;
  575.38 +  
  575.39 +  #ifndef _WIN32_WCE
  575.40 +  UINT32 ReparseTag;
  575.41 +  #else
  575.42 +  DWORD ObjectID;
  575.43 +  #endif
  575.44 +
  575.45 +  bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }
  575.46 +  bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }
  575.47 +  bool IsDir() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); }
  575.48 +  bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); }
  575.49 +  bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); }
  575.50 +  bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); }
  575.51 +  bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); }
  575.52 +  bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); }
  575.53 +  bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); }
  575.54 +  bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); }
  575.55 +  bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }
  575.56 +  bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }
  575.57 +};
  575.58 +
  575.59 +class CFileInfo: public CFileInfoBase
  575.60 +{
  575.61 +public:
  575.62 +  CSysString Name;
  575.63 +  bool IsDots() const;
  575.64 +};
  575.65 +
  575.66 +#ifdef _UNICODE
  575.67 +typedef CFileInfo CFileInfoW;
  575.68 +#else
  575.69 +class CFileInfoW: public CFileInfoBase
  575.70 +{
  575.71 +public:
  575.72 +  UString Name;
  575.73 +  bool IsDots() const;
  575.74 +};
  575.75 +#endif
  575.76 +
  575.77 +class CFindFile
  575.78 +{
  575.79 +  friend class CEnumerator;
  575.80 +  HANDLE _handle;
  575.81 +public:
  575.82 +  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE; }
  575.83 +  CFindFile(): _handle(INVALID_HANDLE_VALUE) {}
  575.84 +  ~CFindFile() {  Close(); }
  575.85 +  bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo);
  575.86 +  bool FindNext(CFileInfo &fileInfo);
  575.87 +  #ifndef _UNICODE
  575.88 +  bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo);
  575.89 +  bool FindNext(CFileInfoW &fileInfo);
  575.90 +  #endif
  575.91 +  bool Close();
  575.92 +};
  575.93 +
  575.94 +bool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo);
  575.95 +
  575.96 +bool DoesFileExist(LPCTSTR name);
  575.97 +#ifndef _UNICODE
  575.98 +bool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);
  575.99 +bool DoesFileExist(LPCWSTR name);
 575.100 +#endif
 575.101 +
 575.102 +class CEnumerator
 575.103 +{
 575.104 +  CFindFile _findFile;
 575.105 +  CSysString _wildcard;
 575.106 +  bool NextAny(CFileInfo &fileInfo);
 575.107 +public:
 575.108 +  CEnumerator(): _wildcard(NName::kAnyStringWildcard) {}
 575.109 +  CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {}
 575.110 +  bool Next(CFileInfo &fileInfo);
 575.111 +  bool Next(CFileInfo &fileInfo, bool &found);
 575.112 +};
 575.113 +
 575.114 +#ifdef _UNICODE
 575.115 +typedef CEnumerator CEnumeratorW;
 575.116 +#else
 575.117 +class CEnumeratorW
 575.118 +{
 575.119 +  CFindFile _findFile;
 575.120 +  UString _wildcard;
 575.121 +  bool NextAny(CFileInfoW &fileInfo);
 575.122 +public:
 575.123 +  CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {}
 575.124 +  CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {}
 575.125 +  bool Next(CFileInfoW &fileInfo);
 575.126 +  bool Next(CFileInfoW &fileInfo, bool &found);
 575.127 +};
 575.128 +#endif
 575.129 +
 575.130 +class CFindChangeNotification
 575.131 +{
 575.132 +  HANDLE _handle;
 575.133 +public:
 575.134 +  operator HANDLE () { return _handle; }
 575.135 +  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; }
 575.136 +  CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}
 575.137 +  ~CFindChangeNotification() { Close(); }
 575.138 +  bool Close();
 575.139 +  HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter);
 575.140 +  #ifndef _UNICODE
 575.141 +  HANDLE FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter);
 575.142 +  #endif
 575.143 +  bool FindNext() { return BOOLToBool(::FindNextChangeNotification(_handle)); }
 575.144 +};
 575.145 +
 575.146 +#ifndef _WIN32_WCE
 575.147 +bool MyGetLogicalDriveStrings(CSysStringVector &driveStrings);
 575.148 +#ifndef _UNICODE
 575.149 +bool MyGetLogicalDriveStrings(UStringVector &driveStrings);
 575.150 +#endif
 575.151 +#endif
 575.152 +
 575.153 +}}}
 575.154 +
 575.155 +#endif
 575.156 +
   576.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   576.2 +++ b/src/win32/7zip/7z/CPP/Windows/FileIO.cpp	Sat Mar 03 10:31:27 2012 -0600
   576.3 @@ -0,0 +1,317 @@
   576.4 +// Windows/FileIO.cpp
   576.5 +
   576.6 +#include "StdAfx.h"
   576.7 +
   576.8 +#include "FileIO.h"
   576.9 +#include "Defs.h"
  576.10 +#ifdef WIN_LONG_PATH
  576.11 +#include "../Common/MyString.h"
  576.12 +#endif
  576.13 +#ifndef _UNICODE
  576.14 +#include "../Common/StringConvert.h"
  576.15 +#endif
  576.16 +
  576.17 +#ifndef _UNICODE
  576.18 +extern bool g_IsNT;
  576.19 +#endif
  576.20 +
  576.21 +namespace NWindows {
  576.22 +namespace NFile {
  576.23 +
  576.24 +#if defined(WIN_LONG_PATH) && defined(_UNICODE)
  576.25 +#define WIN_LONG_PATH2
  576.26 +#endif
  576.27 +
  576.28 +#ifdef WIN_LONG_PATH
  576.29 +bool GetLongPathBase(LPCWSTR s, UString &res)
  576.30 +{
  576.31 +  res.Empty();
  576.32 +  int len = MyStringLen(s);
  576.33 +  wchar_t c = s[0];
  576.34 +  if (len < 1 || c == L'\\' || c == L'.' && (len == 1 || len == 2 && s[1] == L'.'))
  576.35 +    return true;
  576.36 +  UString curDir;
  576.37 +  bool isAbs = false;
  576.38 +  if (len > 3)
  576.39 +    isAbs = (s[1] == L':' && s[2] == L'\\' && (c >= L'a' && c <= L'z' || c >= L'A' && c <= L'Z'));
  576.40 +
  576.41 +  if (!isAbs)
  576.42 +    {
  576.43 +      DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, curDir.GetBuffer(MAX_PATH + 1));
  576.44 +      curDir.ReleaseBuffer();
  576.45 +      if (needLength == 0 || needLength > MAX_PATH)
  576.46 +        return false;
  576.47 +      if (curDir[curDir.Length() - 1] != L'\\')
  576.48 +        curDir += L'\\';
  576.49 +    }
  576.50 +  res = UString(L"\\\\?\\") + curDir + s;
  576.51 +  return true;
  576.52 +}
  576.53 +
  576.54 +bool GetLongPath(LPCWSTR path, UString &longPath)
  576.55 +{
  576.56 +  if (GetLongPathBase(path, longPath))
  576.57 +    return !longPath.IsEmpty();
  576.58 +  return false;
  576.59 +}
  576.60 +#endif
  576.61 +
  576.62 +namespace NIO {
  576.63 +
  576.64 +CFileBase::~CFileBase() { Close(); }
  576.65 +
  576.66 +bool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,
  576.67 +    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
  576.68 +{
  576.69 +  if (!Close())
  576.70 +    return false;
  576.71 +  _handle = ::CreateFile(fileName, desiredAccess, shareMode,
  576.72 +      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,
  576.73 +      flagsAndAttributes, (HANDLE)NULL);
  576.74 +  #ifdef WIN_LONG_PATH2
  576.75 +  if (_handle == INVALID_HANDLE_VALUE)
  576.76 +  {
  576.77 +    UString longPath;
  576.78 +    if (GetLongPath(fileName, longPath))
  576.79 +      _handle = ::CreateFileW(longPath, desiredAccess, shareMode,
  576.80 +        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,
  576.81 +        flagsAndAttributes, (HANDLE)NULL);
  576.82 +  }
  576.83 +  #endif
  576.84 +  return (_handle != INVALID_HANDLE_VALUE);
  576.85 +}
  576.86 +
  576.87 +#ifndef _UNICODE
  576.88 +bool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,
  576.89 +    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
  576.90 +{
  576.91 +  if (!g_IsNT)
  576.92 +    return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP),
  576.93 +      desiredAccess, shareMode, creationDisposition, flagsAndAttributes);
  576.94 +  if (!Close())
  576.95 +    return false;
  576.96 +  _handle = ::CreateFileW(fileName, desiredAccess, shareMode,
  576.97 +    (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,
  576.98 +    flagsAndAttributes, (HANDLE)NULL);
  576.99 +  #ifdef WIN_LONG_PATH
 576.100 +  if (_handle == INVALID_HANDLE_VALUE)
 576.101 +  {
 576.102 +    UString longPath;
 576.103 +    if (GetLongPath(fileName, longPath))
 576.104 +      _handle = ::CreateFileW(longPath, desiredAccess, shareMode,
 576.105 +        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,
 576.106 +        flagsAndAttributes, (HANDLE)NULL);
 576.107 +  }
 576.108 +  #endif
 576.109 +  return (_handle != INVALID_HANDLE_VALUE);
 576.110 +}
 576.111 +#endif
 576.112 +
 576.113 +bool CFileBase::Close()
 576.114 +{
 576.115 +  if (_handle == INVALID_HANDLE_VALUE)
 576.116 +    return true;
 576.117 +  if (!::CloseHandle(_handle))
 576.118 +    return false;
 576.119 +  _handle = INVALID_HANDLE_VALUE;
 576.120 +  return true;
 576.121 +}
 576.122 +
 576.123 +bool CFileBase::GetPosition(UInt64 &position) const
 576.124 +{
 576.125 +  return Seek(0, FILE_CURRENT, position);
 576.126 +}
 576.127 +
 576.128 +bool CFileBase::GetLength(UInt64 &length) const
 576.129 +{
 576.130 +  DWORD sizeHigh;
 576.131 +  DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);
 576.132 +  if (sizeLow == 0xFFFFFFFF)
 576.133 +    if (::GetLastError() != NO_ERROR)
 576.134 +      return false;
 576.135 +  length = (((UInt64)sizeHigh) << 32) + sizeLow;
 576.136 +  return true;
 576.137 +}
 576.138 +
 576.139 +bool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const
 576.140 +{
 576.141 +  LARGE_INTEGER value;
 576.142 +  value.QuadPart = distanceToMove;
 576.143 +  value.LowPart = ::SetFilePointer(_handle, value.LowPart, &value.HighPart, moveMethod);
 576.144 +  if (value.LowPart == 0xFFFFFFFF)
 576.145 +    if (::GetLastError() != NO_ERROR)
 576.146 +      return false;
 576.147 +  newPosition = value.QuadPart;
 576.148 +  return true;
 576.149 +}
 576.150 +
 576.151 +bool CFileBase::Seek(UInt64 position, UInt64 &newPosition)
 576.152 +{
 576.153 +  return Seek(position, FILE_BEGIN, newPosition);
 576.154 +}
 576.155 +
 576.156 +bool CFileBase::SeekToBegin()
 576.157 +{
 576.158 +  UInt64 newPosition;
 576.159 +  return Seek(0, newPosition);
 576.160 +}
 576.161 +
 576.162 +bool CFileBase::SeekToEnd(UInt64 &newPosition)
 576.163 +{
 576.164 +  return Seek(0, FILE_END, newPosition);
 576.165 +}
 576.166 +
 576.167 +bool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const
 576.168 +{
 576.169 +  BY_HANDLE_FILE_INFORMATION winFileInfo;
 576.170 +  if (!::GetFileInformationByHandle(_handle, &winFileInfo))
 576.171 +    return false;
 576.172 +  fileInfo.Attributes = winFileInfo.dwFileAttributes;
 576.173 +  fileInfo.CTime = winFileInfo.ftCreationTime;
 576.174 +  fileInfo.ATime = winFileInfo.ftLastAccessTime;
 576.175 +  fileInfo.MTime = winFileInfo.ftLastWriteTime;
 576.176 +  fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes;
 576.177 +  fileInfo.Size = (((UInt64)winFileInfo.nFileSizeHigh) << 32) +  winFileInfo.nFileSizeLow;
 576.178 +  fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;
 576.179 +  fileInfo.FileIndex = (((UInt64)winFileInfo.nFileIndexHigh) << 32) + winFileInfo.nFileIndexLow;
 576.180 +  return true;
 576.181 +}
 576.182 +
 576.183 +/////////////////////////
 576.184 +// CInFile
 576.185 +
 576.186 +bool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
 576.187 +  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }
 576.188 +
 576.189 +bool CInFile::OpenShared(LPCTSTR fileName, bool shareForWrite)
 576.190 +{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }
 576.191 +
 576.192 +bool CInFile::Open(LPCTSTR fileName)
 576.193 +  { return OpenShared(fileName, false); }
 576.194 +
 576.195 +#ifndef _UNICODE
 576.196 +bool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
 576.197 +  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }
 576.198 +
 576.199 +bool CInFile::OpenShared(LPCWSTR fileName, bool shareForWrite)
 576.200 +{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }
 576.201 +
 576.202 +bool CInFile::Open(LPCWSTR fileName)
 576.203 +  { return OpenShared(fileName, false); }
 576.204 +#endif
 576.205 +
 576.206 +// ReadFile and WriteFile functions in Windows have BUG:
 576.207 +// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
 576.208 +// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
 576.209 +// (Insufficient system resources exist to complete the requested service).
 576.210 +
 576.211 +// Probably in some version of Windows there are problems with other sizes:
 576.212 +// for 32 MB (maybe also for 16 MB).
 576.213 +// And message can be "Network connection was lost"
 576.214 +
 576.215 +static UInt32 kChunkSizeMax = (1 << 22);
 576.216 +
 576.217 +bool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)
 576.218 +{
 576.219 +  if (size > kChunkSizeMax)
 576.220 +    size = kChunkSizeMax;
 576.221 +  DWORD processedLoc = 0;
 576.222 +  bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));
 576.223 +  processedSize = (UInt32)processedLoc;
 576.224 +  return res;
 576.225 +}
 576.226 +
 576.227 +bool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)
 576.228 +{
 576.229 +  processedSize = 0;
 576.230 +  do
 576.231 +  {
 576.232 +    UInt32 processedLoc = 0;
 576.233 +    bool res = ReadPart(data, size, processedLoc);
 576.234 +    processedSize += processedLoc;
 576.235 +    if (!res)
 576.236 +      return false;
 576.237 +    if (processedLoc == 0)
 576.238 +      return true;
 576.239 +    data = (void *)((unsigned char *)data + processedLoc);
 576.240 +    size -= processedLoc;
 576.241 +  }
 576.242 +  while (size > 0);
 576.243 +  return true;
 576.244 +}
 576.245 +
 576.246 +/////////////////////////
 576.247 +// COutFile
 576.248 +
 576.249 +bool COutFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
 576.250 +  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }
 576.251 +
 576.252 +static inline DWORD GetCreationDisposition(bool createAlways)
 576.253 +  { return createAlways? CREATE_ALWAYS: CREATE_NEW; }
 576.254 +
 576.255 +bool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)
 576.256 +  { return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }
 576.257 +
 576.258 +bool COutFile::Create(LPCTSTR fileName, bool createAlways)
 576.259 +  { return Open(fileName, GetCreationDisposition(createAlways)); }
 576.260 +
 576.261 +#ifndef _UNICODE
 576.262 +
 576.263 +bool COutFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
 576.264 +  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,      creationDisposition, flagsAndAttributes); }
 576.265 +
 576.266 +bool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)
 576.267 +  { return Open(fileName, FILE_SHARE_READ,  creationDisposition, FILE_ATTRIBUTE_NORMAL); }
 576.268 +
 576.269 +bool COutFile::Create(LPCWSTR fileName, bool createAlways)
 576.270 +  { return Open(fileName, GetCreationDisposition(createAlways)); }
 576.271 +
 576.272 +#endif
 576.273 +
 576.274 +bool COutFile::SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)
 576.275 +  { return BOOLToBool(::SetFileTime(_handle, cTime, aTime, mTime)); }
 576.276 +
 576.277 +bool COutFile::SetMTime(const FILETIME *mTime) {  return SetTime(NULL, NULL, mTime); }
 576.278 +
 576.279 +bool COutFile::WritePart(const void *data, UInt32 size, UInt32 &processedSize)
 576.280 +{
 576.281 +  if (size > kChunkSizeMax)
 576.282 +    size = kChunkSizeMax;
 576.283 +  DWORD processedLoc = 0;
 576.284 +  bool res = BOOLToBool(::WriteFile(_handle, data, size, &processedLoc, NULL));
 576.285 +  processedSize = (UInt32)processedLoc;
 576.286 +  return res;
 576.287 +}
 576.288 +
 576.289 +bool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize)
 576.290 +{
 576.291 +  processedSize = 0;
 576.292 +  do
 576.293 +  {
 576.294 +    UInt32 processedLoc = 0;
 576.295 +    bool res = WritePart(data, size, processedLoc);
 576.296 +    processedSize += processedLoc;
 576.297 +    if (!res)
 576.298 +      return false;
 576.299 +    if (processedLoc == 0)
 576.300 +      return true;
 576.301 +    data = (const void *)((const unsigned char *)data + processedLoc);
 576.302 +    size -= processedLoc;
 576.303 +  }
 576.304 +  while (size > 0);
 576.305 +  return true;
 576.306 +}
 576.307 +
 576.308 +bool COutFile::SetEndOfFile() { return BOOLToBool(::SetEndOfFile(_handle)); }
 576.309 +
 576.310 +bool COutFile::SetLength(UInt64 length)
 576.311 +{
 576.312 +  UInt64 newPosition;
 576.313 +  if (!Seek(length, newPosition))
 576.314 +    return false;
 576.315 +  if (newPosition != length)
 576.316 +    return false;
 576.317 +  return SetEndOfFile();
 576.318 +}
 576.319 +
 576.320 +}}}
   577.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   577.2 +++ b/src/win32/7zip/7z/CPP/Windows/FileIO.h	Sat Mar 03 10:31:27 2012 -0600
   577.3 @@ -0,0 +1,99 @@
   577.4 +// Windows/FileIO.h
   577.5 +
   577.6 +#ifndef __WINDOWS_FILEIO_H
   577.7 +#define __WINDOWS_FILEIO_H
   577.8 +
   577.9 +#include "../Common/Types.h"
  577.10 +
  577.11 +namespace NWindows {
  577.12 +namespace NFile {
  577.13 +namespace NIO {
  577.14 +
  577.15 +struct CByHandleFileInfo
  577.16 +{
  577.17 +  DWORD    Attributes;
  577.18 +  FILETIME CTime;
  577.19 +  FILETIME ATime;
  577.20 +  FILETIME MTime;
  577.21 +  DWORD    VolumeSerialNumber;
  577.22 +  UInt64   Size;
  577.23 +  DWORD    NumberOfLinks;
  577.24 +  UInt64   FileIndex;
  577.25 +};
  577.26 +
  577.27 +class CFileBase
  577.28 +{
  577.29 +protected:
  577.30 +  HANDLE _handle;
  577.31 +  bool Create(LPCTSTR fileName, DWORD desiredAccess,
  577.32 +      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);
  577.33 +  #ifndef _UNICODE
  577.34 +  bool Create(LPCWSTR fileName, DWORD desiredAccess,
  577.35 +      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);
  577.36 +  #endif
  577.37 +
  577.38 +public:
  577.39 +  CFileBase(): _handle(INVALID_HANDLE_VALUE){};
  577.40 +  ~CFileBase();
  577.41 +
  577.42 +  bool Close();
  577.43 +
  577.44 +  bool GetPosition(UInt64 &position) const;
  577.45 +  bool GetLength(UInt64 &length) const;
  577.46 +
  577.47 +  bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;
  577.48 +  bool Seek(UInt64 position, UInt64 &newPosition);
  577.49 +  bool SeekToBegin();
  577.50 +  bool SeekToEnd(UInt64 &newPosition);
  577.51 +  
  577.52 +  bool GetFileInformation(CByHandleFileInfo &fileInfo) const;
  577.53 +};
  577.54 +
  577.55 +class CInFile: public CFileBase
  577.56 +{
  577.57 +public:
  577.58 +  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
  577.59 +  bool OpenShared(LPCTSTR fileName, bool shareForWrite);
  577.60 +  bool Open(LPCTSTR fileName);
  577.61 +  #ifndef _UNICODE
  577.62 +  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
  577.63 +  bool OpenShared(LPCWSTR fileName, bool shareForWrite);
  577.64 +  bool Open(LPCWSTR fileName);
  577.65 +  #endif
  577.66 +  bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);
  577.67 +  bool Read(void *data, UInt32 size, UInt32 &processedSize);
  577.68 +};
  577.69 +
  577.70 +class COutFile: public CFileBase
  577.71 +{
  577.72 +  // DWORD m_CreationDisposition;
  577.73 +public:
  577.74 +  // COutFile(): m_CreationDisposition(CREATE_NEW){};
  577.75 +  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
  577.76 +  bool Open(LPCTSTR fileName, DWORD creationDisposition);
  577.77 +  bool Create(LPCTSTR fileName, bool createAlways);
  577.78 +
  577.79 +  #ifndef _UNICODE
  577.80 +  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
  577.81 +  bool Open(LPCWSTR fileName, DWORD creationDisposition);
  577.82 +  bool Create(LPCWSTR fileName, bool createAlways);
  577.83 +  #endif
  577.84 +
  577.85 +  /*
  577.86 +  void SetOpenCreationDisposition(DWORD creationDisposition)
  577.87 +    { m_CreationDisposition = creationDisposition; }
  577.88 +  void SetOpenCreationDispositionCreateAlways()
  577.89 +    { m_CreationDisposition = CREATE_ALWAYS; }
  577.90 +  */
  577.91 +
  577.92 +  bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);
  577.93 +  bool SetMTime(const FILETIME *mTime);
  577.94 +  bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);
  577.95 +  bool Write(const void *data, UInt32 size, UInt32 &processedSize);
  577.96 +  bool SetEndOfFile();
  577.97 +  bool SetLength(UInt64 length);
  577.98 +};
  577.99 +
 577.100 +}}}
 577.101 +
 577.102 +#endif
   578.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   578.2 +++ b/src/win32/7zip/7z/CPP/Windows/FileName.h	Sat Mar 03 10:31:27 2012 -0600
   578.3 @@ -0,0 +1,25 @@
   578.4 +// Windows/FileName.h
   578.5 +
   578.6 +#ifndef __WINDOWS_FILENAME_H
   578.7 +#define __WINDOWS_FILENAME_H
   578.8 +
   578.9 +#include "../Common/MyString.h"
  578.10 +
  578.11 +namespace NWindows {
  578.12 +namespace NFile {
  578.13 +namespace NName {
  578.14 +
  578.15 +const TCHAR kDirDelimiter = CHAR_PATH_SEPARATOR;
  578.16 +const TCHAR kAnyStringWildcard = '*';
  578.17 +
  578.18 +void NormalizeDirPathPrefix(CSysString &dirPath); // ensures that it ended with '\\'
  578.19 +#ifndef _UNICODE
  578.20 +void NormalizeDirPathPrefix(UString &dirPath); // ensures that it ended with '\\'
  578.21 +#endif
  578.22 +
  578.23 +void SplitNameToPureNameAndExtension(const UString &fullName,
  578.24 +    UString &pureName, UString &extensionDelimiter, UString &extension);
  578.25 +
  578.26 +}}}
  578.27 +
  578.28 +#endif
   579.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   579.2 +++ b/src/win32/7zip/7z/CPP/Windows/Handle.h	Sat Mar 03 10:31:27 2012 -0600
   579.3 @@ -0,0 +1,37 @@
   579.4 +// Windows/Handle.h
   579.5 +
   579.6 +#ifndef __WINDOWS_HANDLE_H
   579.7 +#define __WINDOWS_HANDLE_H
   579.8 +
   579.9 +namespace NWindows {
  579.10 +
  579.11 +class CHandle
  579.12 +{
  579.13 +protected:
  579.14 +  HANDLE _handle;
  579.15 +public:
  579.16 +  operator HANDLE() { return _handle; }
  579.17 +  CHandle(): _handle(NULL) {}
  579.18 +  ~CHandle() { Close(); }
  579.19 +  bool Close()
  579.20 +  {
  579.21 +    if (_handle == NULL)
  579.22 +      return true;
  579.23 +    if (!::CloseHandle(_handle))
  579.24 +      return false;
  579.25 +    _handle = NULL;
  579.26 +    return true;
  579.27 +  }
  579.28 +  void Attach(HANDLE handle)
  579.29 +    { _handle = handle; }
  579.30 +  HANDLE Detach()
  579.31 +  {
  579.32 +    HANDLE handle = _handle;
  579.33 +    _handle = NULL;
  579.34 +    return handle;
  579.35 +  }
  579.36 +};
  579.37 +
  579.38 +}
  579.39 +
  579.40 +#endif
   580.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   580.2 +++ b/src/win32/7zip/7z/CPP/Windows/PropVariant.cpp	Sat Mar 03 10:31:27 2012 -0600
   580.3 @@ -0,0 +1,312 @@
   580.4 +// Windows/PropVariant.cpp
   580.5 +
   580.6 +#include "StdAfx.h"
   580.7 +
   580.8 +#include "PropVariant.h"
   580.9 +
  580.10 +#include "../Common/Defs.h"
  580.11 +
  580.12 +namespace NWindows {
  580.13 +namespace NCOM {
  580.14 +
  580.15 +CPropVariant::CPropVariant(const PROPVARIANT& varSrc)
  580.16 +{
  580.17 +  vt = VT_EMPTY;
  580.18 +  InternalCopy(&varSrc);
  580.19 +}
  580.20 +
  580.21 +CPropVariant::CPropVariant(const CPropVariant& varSrc)
  580.22 +{
  580.23 +  vt = VT_EMPTY;
  580.24 +  InternalCopy(&varSrc);
  580.25 +}
  580.26 +
  580.27 +CPropVariant::CPropVariant(BSTR bstrSrc)
  580.28 +{
  580.29 +  vt = VT_EMPTY;
  580.30 +  *this = bstrSrc;
  580.31 +}
  580.32 +
  580.33 +CPropVariant::CPropVariant(LPCOLESTR lpszSrc)
  580.34 +{
  580.35 +  vt = VT_EMPTY;
  580.36 +  *this = lpszSrc;
  580.37 +}
  580.38 +
  580.39 +CPropVariant& CPropVariant::operator=(const CPropVariant& varSrc)
  580.40 +{
  580.41 +  InternalCopy(&varSrc);
  580.42 +  return *this;
  580.43 +}
  580.44 +CPropVariant& CPropVariant::operator=(const PROPVARIANT& varSrc)
  580.45 +{
  580.46 +  InternalCopy(&varSrc);
  580.47 +  return *this;
  580.48 +}
  580.49 +
  580.50 +CPropVariant& CPropVariant::operator=(BSTR bstrSrc)
  580.51 +{
  580.52 +  *this = (LPCOLESTR)bstrSrc;
  580.53 +  return *this;
  580.54 +}
  580.55 +
  580.56 +CPropVariant& CPropVariant::operator=(LPCOLESTR lpszSrc)
  580.57 +{
  580.58 +  InternalClear();
  580.59 +  vt = VT_BSTR;
  580.60 +  wReserved1 = 0;
  580.61 +  bstrVal = ::SysAllocString(lpszSrc);
  580.62 +  if (bstrVal == NULL && lpszSrc != NULL)
  580.63 +  {
  580.64 +    vt = VT_ERROR;
  580.65 +    scode = E_OUTOFMEMORY;
  580.66 +  }
  580.67 +  return *this;
  580.68 +}
  580.69 +
  580.70 +
  580.71 +CPropVariant& CPropVariant::operator=(bool bSrc)
  580.72 +{
  580.73 +  if (vt != VT_BOOL)
  580.74 +  {
  580.75 +    InternalClear();
  580.76 +    vt = VT_BOOL;
  580.77 +  }
  580.78 +  boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE;
  580.79 +  return *this;
  580.80 +}
  580.81 +
  580.82 +CPropVariant& CPropVariant::operator=(UInt32 value)
  580.83 +{
  580.84 +  if (vt != VT_UI4)
  580.85 +  {
  580.86 +    InternalClear();
  580.87 +    vt = VT_UI4;
  580.88 +  }
  580.89 +  ulVal = value;
  580.90 +  return *this;
  580.91 +}
  580.92 +
  580.93 +CPropVariant& CPropVariant::operator=(UInt64 value)
  580.94 +{
  580.95 +  if (vt != VT_UI8)
  580.96 +  {
  580.97 +    InternalClear();
  580.98 +    vt = VT_UI8;
  580.99 +  }
 580.100 +  uhVal.QuadPart = value;
 580.101 +  return *this;
 580.102 +}
 580.103 +
 580.104 +CPropVariant& CPropVariant::operator=(const FILETIME &value)
 580.105 +{
 580.106 +  if (vt != VT_FILETIME)
 580.107 +  {
 580.108 +    InternalClear();
 580.109 +    vt = VT_FILETIME;
 580.110 +  }
 580.111 +  filetime = value;
 580.112 +  return *this;
 580.113 +}
 580.114 +
 580.115 +CPropVariant& CPropVariant::operator=(Int32 value)
 580.116 +{
 580.117 +  if (vt != VT_I4)
 580.118 +  {
 580.119 +    InternalClear();
 580.120 +    vt = VT_I4;
 580.121 +  }
 580.122 +  lVal = value;
 580.123 +  
 580.124 +  return *this;
 580.125 +}
 580.126 +
 580.127 +CPropVariant& CPropVariant::operator=(Byte value)
 580.128 +{
 580.129 +  if (vt != VT_UI1)
 580.130 +  {
 580.131 +    InternalClear();
 580.132 +    vt = VT_UI1;
 580.133 +  }
 580.134 +  bVal = value;
 580.135 +  return *this;
 580.136 +}
 580.137 +
 580.138 +CPropVariant& CPropVariant::operator=(Int16 value)
 580.139 +{
 580.140 +  if (vt != VT_I2)
 580.141 +  {
 580.142 +    InternalClear();
 580.143 +    vt = VT_I2;
 580.144 +  }
 580.145 +  iVal = value;
 580.146 +  return *this;
 580.147 +}
 580.148 +
 580.149 +/*
 580.150 +CPropVariant& CPropVariant::operator=(LONG value)
 580.151 +{
 580.152 +  if (vt != VT_I4)
 580.153 +  {
 580.154 +    InternalClear();
 580.155 +    vt = VT_I4;
 580.156 +  }
 580.157 +  lVal = value;
 580.158 +  return *this;
 580.159 +}
 580.160 +*/
 580.161 +
 580.162 +static HRESULT MyPropVariantClear(PROPVARIANT *propVariant)
 580.163 +{
 580.164 +  switch(propVariant->vt)
 580.165 +  {
 580.166 +    case VT_UI1:
 580.167 +    case VT_I1:
 580.168 +    case VT_I2:
 580.169 +    case VT_UI2:
 580.170 +    case VT_BOOL:
 580.171 +    case VT_I4:
 580.172 +    case VT_UI4:
 580.173 +    case VT_R4:
 580.174 +    case VT_INT:
 580.175 +    case VT_UINT:
 580.176 +    case VT_ERROR:
 580.177 +    case VT_FILETIME:
 580.178 +    case VT_UI8:
 580.179 +    case VT_R8:
 580.180 +    case VT_CY:
 580.181 +    case VT_DATE:
 580.182 +      propVariant->vt = VT_EMPTY;
 580.183 +      propVariant->wReserved1 = 0;
 580.184 +      return S_OK;
 580.185 +  }
 580.186 +  return ::VariantClear((VARIANTARG *)propVariant);
 580.187 +}
 580.188 +
 580.189 +HRESULT CPropVariant::Clear()
 580.190 +{
 580.191 +  return MyPropVariantClear(this);
 580.192 +}
 580.193 +
 580.194 +HRESULT CPropVariant::Copy(const PROPVARIANT* pSrc)
 580.195 +{
 580.196 +  ::VariantClear((tagVARIANT *)this);
 580.197 +  switch(pSrc->vt)
 580.198 +  {
 580.199 +    case VT_UI1:
 580.200 +    case VT_I1:
 580.201 +    case VT_I2:
 580.202 +    case VT_UI2:
 580.203 +    case VT_BOOL:
 580.204 +    case VT_I4:
 580.205 +    case VT_UI4:
 580.206 +    case VT_R4:
 580.207 +    case VT_INT:
 580.208 +    case VT_UINT:
 580.209 +    case VT_ERROR:
 580.210 +    case VT_FILETIME:
 580.211 +    case VT_UI8:
 580.212 +    case VT_R8:
 580.213 +    case VT_CY:
 580.214 +    case VT_DATE:
 580.215 +      memmove((PROPVARIANT*)this, pSrc, sizeof(PROPVARIANT));
 580.216 +      return S_OK;
 580.217 +  }
 580.218 +  return ::VariantCopy((tagVARIANT *)this, (tagVARIANT *)(pSrc));
 580.219 +}
 580.220 +
 580.221 +
 580.222 +HRESULT CPropVariant::Attach(PROPVARIANT* pSrc)
 580.223 +{
 580.224 +  HRESULT hr = Clear();
 580.225 +  if (FAILED(hr))
 580.226 +    return hr;
 580.227 +  memcpy(this, pSrc, sizeof(PROPVARIANT));
 580.228 +  pSrc->vt = VT_EMPTY;
 580.229 +  return S_OK;
 580.230 +}
 580.231 +
 580.232 +HRESULT CPropVariant::Detach(PROPVARIANT* pDest)
 580.233 +{
 580.234 +  HRESULT hr = MyPropVariantClear(pDest);
 580.235 +  if (FAILED(hr))
 580.236 +    return hr;
 580.237 +  memcpy(pDest, this, sizeof(PROPVARIANT));
 580.238 +  vt = VT_EMPTY;
 580.239 +  return S_OK;
 580.240 +}
 580.241 +
 580.242 +HRESULT CPropVariant::InternalClear()
 580.243 +{
 580.244 +  HRESULT hr = Clear();
 580.245 +  if (FAILED(hr))
 580.246 +  {
 580.247 +    vt = VT_ERROR;
 580.248 +    scode = hr;
 580.249 +  }
 580.250 +  return hr;
 580.251 +}
 580.252 +
 580.253 +void CPropVariant::InternalCopy(const PROPVARIANT* pSrc)
 580.254 +{
 580.255 +  HRESULT hr = Copy(pSrc);
 580.256 +  if (FAILED(hr))
 580.257 +  {
 580.258 +    vt = VT_ERROR;
 580.259 +    scode = hr;
 580.260 +  }
 580.261 +}
 580.262 +
 580.263 +int CPropVariant::Compare(const CPropVariant &a)
 580.264 +{
 580.265 +  if (vt != a.vt)
 580.266 +    return 0; // it's mean some bug
 580.267 +  switch (vt)
 580.268 +  {
 580.269 +    case VT_EMPTY:
 580.270 +      return 0;
 580.271 +    
 580.272 +    /*
 580.273 +    case VT_I1:
 580.274 +      return MyCompare(cVal, a.cVal);
 580.275 +    */
 580.276 +    case VT_UI1:
 580.277 +      return MyCompare(bVal, a.bVal);
 580.278 +
 580.279 +    case VT_I2:
 580.280 +      return MyCompare(iVal, a.iVal);
 580.281 +    case VT_UI2:
 580.282 +      return MyCompare(uiVal, a.uiVal);
 580.283 +    
 580.284 +    case VT_I4:
 580.285 +      return MyCompare(lVal, a.lVal);
 580.286 +    /*
 580.287 +    case VT_INT:
 580.288 +      return MyCompare(intVal, a.intVal);
 580.289 +    */
 580.290 +    case VT_UI4:
 580.291 +      return MyCompare(ulVal, a.ulVal);
 580.292 +    /*
 580.293 +    case VT_UINT:
 580.294 +      return MyCompare(uintVal, a.uintVal);
 580.295 +    */
 580.296 +    case VT_I8:
 580.297 +      return MyCompare(hVal.QuadPart, a.hVal.QuadPart);
 580.298 +    case VT_UI8:
 580.299 +      return MyCompare(uhVal.QuadPart, a.uhVal.QuadPart);
 580.300 +
 580.301 +    case VT_BOOL:
 580.302 +      return -MyCompare(boolVal, a.boolVal);
 580.303 +
 580.304 +    case VT_FILETIME:
 580.305 +      return ::CompareFileTime(&filetime, &a.filetime);
 580.306 +    case VT_BSTR:
 580.307 +      return 0; // Not implemented
 580.308 +      // return MyCompare(aPropVarint.cVal);
 580.309 +
 580.310 +    default:
 580.311 +      return 0;
 580.312 +  }
 580.313 +}
 580.314 +
 580.315 +}}
   581.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   581.2 +++ b/src/win32/7zip/7z/CPP/Windows/PropVariant.h	Sat Mar 03 10:31:27 2012 -0600
   581.3 @@ -0,0 +1,57 @@
   581.4 +// Windows/PropVariant.h
   581.5 +
   581.6 +#ifndef __WINDOWS_PROPVARIANT_H
   581.7 +#define __WINDOWS_PROPVARIANT_H
   581.8 +
   581.9 +#include "../Common/MyWindows.h"
  581.10 +#include "../Common/Types.h"
  581.11 +
  581.12 +namespace NWindows {
  581.13 +namespace NCOM {
  581.14 +
  581.15 +class CPropVariant : public tagPROPVARIANT
  581.16 +{
  581.17 +public:
  581.18 +  CPropVariant() { vt = VT_EMPTY; wReserved1 = 0; }
  581.19 +  ~CPropVariant() { Clear(); }
  581.20 +  CPropVariant(const PROPVARIANT& varSrc);
  581.21 +  CPropVariant(const CPropVariant& varSrc);
  581.22 +  CPropVariant(BSTR bstrSrc);
  581.23 +  CPropVariant(LPCOLESTR lpszSrc);
  581.24 +  CPropVariant(bool bSrc) { vt = VT_BOOL; wReserved1 = 0; boolVal = (bSrc ? VARIANT_TRUE : VARIANT_FALSE); };
  581.25 +  CPropVariant(UInt32 value) { vt = VT_UI4; wReserved1 = 0; ulVal = value; }
  581.26 +  CPropVariant(UInt64 value) { vt = VT_UI8; wReserved1 = 0; uhVal = *(ULARGE_INTEGER*)&value; }
  581.27 +  CPropVariant(const FILETIME &value) { vt = VT_FILETIME; wReserved1 = 0; filetime = value; }
  581.28 +  CPropVariant(Int32 value) { vt = VT_I4; wReserved1 = 0; lVal = value; }
  581.29 +  CPropVariant(Byte value) { vt = VT_UI1; wReserved1 = 0; bVal = value; }
  581.30 +  CPropVariant(Int16 value) { vt = VT_I2; wReserved1 = 0; iVal = value; }
  581.31 +  // CPropVariant(LONG value, VARTYPE vtSrc = VT_I4) { vt = vtSrc; lVal = value; }
  581.32 +
  581.33 +  CPropVariant& operator=(const CPropVariant& varSrc);
  581.34 +  CPropVariant& operator=(const PROPVARIANT& varSrc);
  581.35 +  CPropVariant& operator=(BSTR bstrSrc);
  581.36 +  CPropVariant& operator=(LPCOLESTR lpszSrc);
  581.37 +  CPropVariant& operator=(bool bSrc);
  581.38 +  CPropVariant& operator=(UInt32 value);
  581.39 +  CPropVariant& operator=(UInt64 value);
  581.40 +  CPropVariant& operator=(const FILETIME &value);
  581.41 +
  581.42 +  CPropVariant& operator=(Int32 value);
  581.43 +  CPropVariant& operator=(Byte value);
  581.44 +  CPropVariant& operator=(Int16 value);
  581.45 +  // CPropVariant& operator=(LONG  value);
  581.46 +
  581.47 +  HRESULT Clear();
  581.48 +  HRESULT Copy(const PROPVARIANT* pSrc);
  581.49 +  HRESULT Attach(PROPVARIANT* pSrc);
  581.50 +  HRESULT Detach(PROPVARIANT* pDest);
  581.51 +
  581.52 +  HRESULT InternalClear();
  581.53 +  void InternalCopy(const PROPVARIANT* pSrc);
  581.54 +
  581.55 +  int Compare(const CPropVariant &a1);
  581.56 +};
  581.57 +
  581.58 +}}
  581.59 +
  581.60 +#endif
   582.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   582.2 +++ b/src/win32/7zip/7z/CPP/Windows/StdAfx.h	Sat Mar 03 10:31:27 2012 -0600
   582.3 @@ -0,0 +1,9 @@
   582.4 +// StdAfx.h
   582.5 +
   582.6 +#ifndef __STDAFX_H
   582.7 +#define __STDAFX_H
   582.8 +
   582.9 +#include "../Common/MyWindows.h"
  582.10 +#include "../Common/NewHandler.h"
  582.11 +
  582.12 +#endif
   583.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   583.2 +++ b/src/win32/7zip/7z/CPP/Windows/Synchronization.h	Sat Mar 03 10:31:27 2012 -0600
   583.3 @@ -0,0 +1,168 @@
   583.4 +// Windows/Synchronization.h
   583.5 +
   583.6 +#ifndef __WINDOWS_SYNCHRONIZATION_H
   583.7 +#define __WINDOWS_SYNCHRONIZATION_H
   583.8 +
   583.9 +#include "Defs.h"
  583.10 +
  583.11 +extern "C"
  583.12 +{
  583.13 +#include "../../C/Threads.h"
  583.14 +}
  583.15 +
  583.16 +#ifdef _WIN32
  583.17 +#include "Handle.h"
  583.18 +#endif
  583.19 +
  583.20 +namespace NWindows {
  583.21 +namespace NSynchronization {
  583.22 +
  583.23 +class CBaseEvent
  583.24 +{
  583.25 +protected:
  583.26 +  ::CEvent _object;
  583.27 +public:
  583.28 +  bool IsCreated() { return Event_IsCreated(&_object) != 0; }
  583.29 +  operator HANDLE() { return _object.handle; }
  583.30 +  CBaseEvent() { Event_Construct(&_object); }
  583.31 +  ~CBaseEvent() { Close(); }
  583.32 +  WRes Close() { return Event_Close(&_object); }
  583.33 +  #ifdef _WIN32
  583.34 +  WRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL,
  583.35 +      LPSECURITY_ATTRIBUTES securityAttributes = NULL)
  583.36 +  {
  583.37 +    _object.handle = ::CreateEvent(securityAttributes, BoolToBOOL(manualReset),
  583.38 +        BoolToBOOL(initiallyOwn), name);
  583.39 +    if (_object.handle != 0)
  583.40 +      return 0;
  583.41 +    return ::GetLastError();
  583.42 +  }
  583.43 +  WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)
  583.44 +  {
  583.45 +    _object.handle = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name);
  583.46 +    if (_object.handle != 0)
  583.47 +      return 0;
  583.48 +    return ::GetLastError();
  583.49 +  }
  583.50 +  #endif
  583.51 +
  583.52 +  WRes Set() { return Event_Set(&_object); }
  583.53 +  // bool Pulse() { return BOOLToBool(::PulseEvent(_handle)); }
  583.54 +  WRes Reset() { return Event_Reset(&_object); }
  583.55 +  WRes Lock() { return Event_Wait(&_object); }
  583.56 +};
  583.57 +
  583.58 +class CManualResetEvent: public CBaseEvent
  583.59 +{
  583.60 +public:
  583.61 +  WRes Create(bool initiallyOwn = false)
  583.62 +  {
  583.63 +    return ManualResetEvent_Create(&_object, initiallyOwn ? 1: 0);
  583.64 +  }
  583.65 +  WRes CreateIfNotCreated()
  583.66 +  {
  583.67 +    if (IsCreated())
  583.68 +      return 0;
  583.69 +    return ManualResetEvent_CreateNotSignaled(&_object);
  583.70 +  }
  583.71 +  #ifdef _WIN32
  583.72 +  WRes CreateWithName(bool initiallyOwn, LPCTSTR name)
  583.73 +  {
  583.74 +    return CBaseEvent::Create(true, initiallyOwn, name);
  583.75 +  }
  583.76 +  #endif
  583.77 +};
  583.78 +
  583.79 +class CAutoResetEvent: public CBaseEvent
  583.80 +{
  583.81 +public:
  583.82 +  WRes Create()
  583.83 +  {
  583.84 +    return AutoResetEvent_CreateNotSignaled(&_object);
  583.85 +  }
  583.86 +  WRes CreateIfNotCreated()
  583.87 +  {
  583.88 +    if (IsCreated())
  583.89 +      return 0;
  583.90 +    return AutoResetEvent_CreateNotSignaled(&_object);
  583.91 +  }
  583.92 +};
  583.93 +
  583.94 +#ifdef _WIN32
  583.95 +class CObject: public CHandle
  583.96 +{
  583.97 +public:
  583.98 +  WRes Lock(DWORD timeoutInterval = INFINITE)
  583.99 +    { return (::WaitForSingleObject(_handle, timeoutInterval) == WAIT_OBJECT_0 ? 0 : ::GetLastError()); }
 583.100 +};
 583.101 +class CMutex: public CObject
 583.102 +{
 583.103 +public:
 583.104 +  WRes Create(bool initiallyOwn, LPCTSTR name = NULL,
 583.105 +      LPSECURITY_ATTRIBUTES securityAttributes = NULL)
 583.106 +  {
 583.107 +    _handle = ::CreateMutex(securityAttributes, BoolToBOOL(initiallyOwn), name);
 583.108 +    if (_handle != 0)
 583.109 +      return 0;
 583.110 +    return ::GetLastError();
 583.111 +  }
 583.112 +  WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)
 583.113 +  {
 583.114 +    _handle = ::OpenMutex(desiredAccess, BoolToBOOL(inheritHandle), name);
 583.115 +    if (_handle != 0)
 583.116 +      return 0;
 583.117 +    return ::GetLastError();
 583.118 +  }
 583.119 +  WRes Release()
 583.120 +  {
 583.121 +    return ::ReleaseMutex(_handle) ? 0 : ::GetLastError();
 583.122 +  }
 583.123 +};
 583.124 +class CMutexLock
 583.125 +{
 583.126 +  CMutex *_object;
 583.127 +public:
 583.128 +  CMutexLock(CMutex &object): _object(&object) { _object->Lock(); }
 583.129 +  ~CMutexLock() { _object->Release(); }
 583.130 +};
 583.131 +#endif
 583.132 +
 583.133 +class CSemaphore
 583.134 +{
 583.135 +  ::CSemaphore _object;
 583.136 +public:
 583.137 +  CSemaphore() { Semaphore_Construct(&_object); }
 583.138 +  ~CSemaphore() { Close(); }
 583.139 +  WRes Close() {  return Semaphore_Close(&_object); }
 583.140 +  operator HANDLE() { return _object.handle; }
 583.141 +  WRes Create(UInt32 initiallyCount, UInt32 maxCount)
 583.142 +  {
 583.143 +    return Semaphore_Create(&_object, initiallyCount, maxCount);
 583.144 +  }
 583.145 +  WRes Release() { return Semaphore_Release1(&_object); }
 583.146 +  WRes Release(UInt32 releaseCount) { return Semaphore_ReleaseN(&_object, releaseCount); }
 583.147 +  WRes Lock() { return Semaphore_Wait(&_object); }
 583.148 +};
 583.149 +
 583.150 +class CCriticalSection
 583.151 +{
 583.152 +  ::CCriticalSection _object;
 583.153 +public:
 583.154 +  CCriticalSection() { CriticalSection_Init(&_object); }
 583.155 +  ~CCriticalSection() { CriticalSection_Delete(&_object); }
 583.156 +  void Enter() { CriticalSection_Enter(&_object); }
 583.157 +  void Leave() { CriticalSection_Leave(&_object); }
 583.158 +};
 583.159 +
 583.160 +class CCriticalSectionLock
 583.161 +{
 583.162 +  CCriticalSection *_object;
 583.163 +  void Unlock()  { _object->Leave(); }
 583.164 +public:
 583.165 +  CCriticalSectionLock(CCriticalSection &object): _object(&object) {_object->Enter(); }
 583.166 +  ~CCriticalSectionLock() { Unlock(); }
 583.167 +};
 583.168 +
 583.169 +}}
 583.170 +
 583.171 +#endif
   584.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   584.2 +++ b/src/win32/7zip/7z/CPP/Windows/Thread.h	Sat Mar 03 10:31:27 2012 -0600
   584.3 @@ -0,0 +1,38 @@
   584.4 +// Windows/Thread.h
   584.5 +
   584.6 +#ifndef __WINDOWS_THREAD_H
   584.7 +#define __WINDOWS_THREAD_H
   584.8 +
   584.9 +#include "Defs.h"
  584.10 +
  584.11 +extern "C"
  584.12 +{
  584.13 +#include "../../C/Threads.h"
  584.14 +}
  584.15 +
  584.16 +namespace NWindows {
  584.17 +
  584.18 +class CThread
  584.19 +{
  584.20 +  ::CThread thread;
  584.21 +public:
  584.22 +  CThread() { Thread_Construct(&thread); }
  584.23 +  ~CThread() { Close(); }
  584.24 +  bool IsCreated() { return Thread_WasCreated(&thread) != 0; }
  584.25 +  WRes Close()  { return Thread_Close(&thread); }
  584.26 +  WRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
  584.27 +    { return Thread_Create(&thread, startAddress, parameter); }
  584.28 +  WRes Wait() { return Thread_Wait(&thread); }
  584.29 +  
  584.30 +  #ifdef _WIN32
  584.31 +  DWORD Resume() { return ::ResumeThread(thread.handle); }
  584.32 +  DWORD Suspend() { return ::SuspendThread(thread.handle); }
  584.33 +  bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread.handle, exitCode)); }
  584.34 +  int GetPriority() { return ::GetThreadPriority(thread.handle); }
  584.35 +  bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread.handle, priority)); }
  584.36 +  #endif
  584.37 +};
  584.38 +
  584.39 +}
  584.40 +
  584.41 +#endif
   585.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   585.2 +++ b/src/win32/7zip/7z/CPP/Windows/Time.cpp	Sat Mar 03 10:31:27 2012 -0600
   585.3 @@ -0,0 +1,86 @@
   585.4 +// Windows/Time.cpp
   585.5 +
   585.6 +#include "StdAfx.h"
   585.7 +
   585.8 +#include "Time.h"
   585.9 +#include "Windows/Defs.h"
  585.10 +
  585.11 +namespace NWindows {
  585.12 +namespace NTime {
  585.13 +
  585.14 +bool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime)
  585.15 +{
  585.16 +  return BOOLToBool(::DosDateTimeToFileTime((UInt16)(dosTime >> 16), (UInt16)(dosTime & 0xFFFF), &fileTime));
  585.17 +}
  585.18 +
  585.19 +static const UInt32 kHighDosTime = 0xFF9FBF7D;
  585.20 +static const UInt32 kLowDosTime = 0x210000;
  585.21 +
  585.22 +bool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime)
  585.23 +{
  585.24 +  WORD datePart, timePart;
  585.25 +  if (!::FileTimeToDosDateTime(&fileTime, &datePart, &timePart))
  585.26 +  {
  585.27 +    dosTime = (fileTime.dwHighDateTime >= 0x01C00000) ? kHighDosTime : kLowDosTime;
  585.28 +    return false;
  585.29 +  }
  585.30 +  dosTime = (((UInt32)datePart) << 16) + timePart;
  585.31 +  return true;
  585.32 +}
  585.33 +
  585.34 +static const UInt32 kNumTimeQuantumsInSecond = 10000000;
  585.35 +static const UInt64 kUnixTimeStartValue = ((UInt64)kNumTimeQuantumsInSecond) * 60 * 60 * 24 * 134774;
  585.36 +
  585.37 +void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime)
  585.38 +{
  585.39 +  UInt64 v = kUnixTimeStartValue + ((UInt64)unixTime) * kNumTimeQuantumsInSecond;
  585.40 +  fileTime.dwLowDateTime = (DWORD)v;
  585.41 +  fileTime.dwHighDateTime = (DWORD)(v >> 32);
  585.42 +}
  585.43 +
  585.44 +bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime)
  585.45 +{
  585.46 +  UInt64 winTime = (((UInt64)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;
  585.47 +  if (winTime < kUnixTimeStartValue)
  585.48 +  {
  585.49 +    unixTime = 0;
  585.50 +    return false;
  585.51 +  }
  585.52 +  winTime = (winTime - kUnixTimeStartValue) / kNumTimeQuantumsInSecond;
  585.53 +  if (winTime > 0xFFFFFFFF)
  585.54 +  {
  585.55 +    unixTime = 0xFFFFFFFF;
  585.56 +    return false;
  585.57 +  }
  585.58 +  unixTime = (UInt32)winTime;
  585.59 +  return true;
  585.60 +}
  585.61 +
  585.62 +bool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,
  585.63 +  unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds)
  585.64 +{
  585.65 +  resSeconds = 0;
  585.66 +  if (year < 1601 || year >= 10000 || month < 1 || month > 12 ||
  585.67 +      day < 1 || day > 31 || hour > 23 || min > 59 || sec > 59)
  585.68 +    return false;
  585.69 +  UInt32 numYears = year - 1601;
  585.70 +  UInt32 numDays = numYears * 365 + numYears / 4 - numYears / 100 + numYears / 400;
  585.71 +  Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  585.72 +  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
  585.73 +    ms[1] = 29;
  585.74 +  month--;
  585.75 +  for (unsigned i = 0; i < month; i++)
  585.76 +    numDays += ms[i];
  585.77 +  numDays += day - 1;
  585.78 +  resSeconds = ((UInt64)(numDays * 24 + hour) * 60 + min) * 60 + sec;
  585.79 +  return true;
  585.80 +}
  585.81 +
  585.82 +void GetCurUtcFileTime(FILETIME &ft)
  585.83 +{
  585.84 +  SYSTEMTIME st;
  585.85 +  GetSystemTime(&st);
  585.86 +  SystemTimeToFileTime(&st, &ft);
  585.87 +}
  585.88 +
  585.89 +}}
   586.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   586.2 +++ b/src/win32/7zip/7z/CPP/Windows/Time.h	Sat Mar 03 10:31:27 2012 -0600
   586.3 @@ -0,0 +1,21 @@
   586.4 +// Windows/Time.h
   586.5 +
   586.6 +#ifndef __WINDOWS_TIME_H
   586.7 +#define __WINDOWS_TIME_H
   586.8 +
   586.9 +#include "Common/Types.h"
  586.10 +
  586.11 +namespace NWindows {
  586.12 +namespace NTime {
  586.13 +
  586.14 +bool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime);
  586.15 +bool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime);
  586.16 +void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime);
  586.17 +bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime);
  586.18 +bool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,
  586.19 +  unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds);
  586.20 +void GetCurUtcFileTime(FILETIME &ft);
  586.21 +
  586.22 +}}
  586.23 +
  586.24 +#endif
   587.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   587.2 +++ b/src/win32/7zip/7z/DOC/License.txt	Sat Mar 03 10:31:27 2012 -0600
   587.3 @@ -0,0 +1,57 @@
   587.4 +NOTE: The 7-zip library source is available under the LGPL,
   587.5 +however, this copy of it is distributed under the GPL 2.0.
   587.6 +This license has been modified accordingly.
   587.7 +
   587.8 +
   587.9 +  7-Zip source code
  587.10 +  ~~~~~~~~~~~~~~~~~
  587.11 +  License for use and distribution
  587.12 +  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  587.13 +
  587.14 +  7-Zip Copyright (C) 1999-2009 Igor Pavlov.
  587.15 +
  587.16 +  Licenses for files are:
  587.17 +
  587.18 +    1) The 8 files in CPP/7zip/Compress/Rar*:  GNU GPL 2.0 + unRAR restriction
  587.19 +    2) All other files:  GNU GPL 2.0
  587.20 +
  587.21 +  The GNU GPL + unRAR restriction means that you must follow both 
  587.22 +  GNU GPL rules and unRAR restriction rules.
  587.23 +
  587.24 +
  587.25 +  GNU GPL information
  587.26 +  --------------------
  587.27 +
  587.28 +    This program is free software; you can redistribute it and/or
  587.29 +    modify it under the terms of the GNU General Public License
  587.30 +    as published by the Free Software Foundation; either version 2
  587.31 +    of the License, or (at your option) any later version.
  587.32 +
  587.33 +    This program is distributed in the hope that it will be useful,
  587.34 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  587.35 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  587.36 +    GNU General Public License for more details.
  587.37 +
  587.38 +    You should have received a copy of the GNU General Public License
  587.39 +    along with this program; if not, write to the Free Software
  587.40 +    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  587.41 +
  587.42 +
  587.43 +  unRAR restriction
  587.44 +  -----------------
  587.45 +
  587.46 +    The decompression engine for RAR archives was developed using source 
  587.47 +    code of unRAR program.
  587.48 +    All copyrights to original unRAR code are owned by Alexander Roshal.
  587.49 +
  587.50 +    The license for original unRAR code has the following restriction:
  587.51 +
  587.52 +    The unRAR sources cannot be used to re-create the RAR compression algorithm, 
  587.53 +    which is proprietary. Distribution of modified unRAR sources in separate form 
  587.54 +    or as a part of other software is permitted, provided that it is clearly
  587.55 +    stated in the documentation and source comments that the code may
  587.56 +    not be used to develop a RAR (WinRAR) compatible archiver.
  587.57 +
  587.58 +
  587.59 +  --
  587.60 +  Igor Pavlov
   588.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   588.2 +++ b/src/win32/7zip/7z/DOC/gpl.txt	Sat Mar 03 10:31:27 2012 -0600
   588.3 @@ -0,0 +1,339 @@
   588.4 +		    GNU GENERAL PUBLIC LICENSE
   588.5 +		       Version 2, June 1991
   588.6 +
   588.7 + Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
   588.8 + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   588.9 + Everyone is permitted to copy and distribute verbatim copies
  588.10 + of this license document, but changing it is not allowed.
  588.11 +
  588.12 +			    Preamble
  588.13 +
  588.14 +  The licenses for most software are designed to take away your
  588.15 +freedom to share and change it.  By contrast, the GNU General Public
  588.16 +License is intended to guarantee your freedom to share and change free
  588.17 +software--to make sure the software is free for all its users.  This
  588.18 +General Public License applies to most of the Free Software
  588.19 +Foundation's software and to any other program whose authors commit to
  588.20 +using it.  (Some other Free Software Foundation software is covered by
  588.21 +the GNU Lesser General Public License instead.)  You can apply it to
  588.22 +your programs, too.
  588.23 +
  588.24 +  When we speak of free software, we are referring to freedom, not
  588.25 +price.  Our General Public Licenses are designed to make sure that you
  588.26 +have the freedom to distribute copies of free software (and charge for
  588.27 +this service if you wish), that you receive source code or can get it
  588.28 +if you want it, that you can change the software or use pieces of it
  588.29 +in new free programs; and that you know you can do these things.
  588.30 +
  588.31 +  To protect your rights, we need to make restrictions that forbid
  588.32 +anyone to deny you these rights or to ask you to surrender the rights.
  588.33 +These restrictions translate to certain responsibilities for you if you
  588.34 +distribute copies of the software, or if you modify it.
  588.35 +
  588.36 +  For example, if you distribute copies of such a program, whether
  588.37 +gratis or for a fee, you must give the recipients all the rights that
  588.38 +you have.  You must make sure that they, too, receive or can get the
  588.39 +source code.  And you must show them these terms so they know their
  588.40 +rights.
  588.41 +
  588.42 +  We protect your rights with two steps: (1) copyright the software, and
  588.43 +(2) offer you this license which gives you legal permission to copy,
  588.44 +distribute and/or modify the software.
  588.45 +
  588.46 +  Also, for each author's protection and ours, we want to make certain
  588.47 +that everyone understands that there is no warranty for this free
  588.48 +software.  If the software is modified by someone else and passed on, we
  588.49 +want its recipients to know that what they have is not the original, so
  588.50 +that any problems introduced by others will not reflect on the original
  588.51 +authors' reputations.
  588.52 +
  588.53 +  Finally, any free program is threatened constantly by software
  588.54 +patents.  We wish to avoid the danger that redistributors of a free
  588.55 +program will individually obtain patent licenses, in effect making the
  588.56 +program proprietary.  To prevent this, we have made it clear that any
  588.57 +patent must be licensed for everyone's free use or not licensed at all.
  588.58 +
  588.59 +  The precise terms and conditions for copying, distribution and
  588.60 +modification follow.
  588.61 +
  588.62 +		    GNU GENERAL PUBLIC LICENSE
  588.63 +   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  588.64 +
  588.65 +  0. This License applies to any program or other work which contains
  588.66 +a notice placed by the copyright holder saying it may be distributed
  588.67 +under the terms of this General Public License.  The "Program", below,
  588.68 +refers to any such program or work, and a "work based on the Program"
  588.69 +means either the Program or any derivative work under copyright law:
  588.70 +that is to say, a work containing the Program or a portion of it,
  588.71 +either verbatim or with modifications and/or translated into another
  588.72 +language.  (Hereinafter, translation is included without limitation in
  588.73 +the term "modification".)  Each licensee is addressed as "you".
  588.74 +
  588.75 +Activities other than copying, distribution and modification are not
  588.76 +covered by this License; they are outside its scope.  The act of
  588.77 +running the Program is not restricted, and the output from the Program
  588.78 +is covered only if its contents constitute a work based on the
  588.79 +Program (independent of having been made by running the Program).
  588.80 +Whether that is true depends on what the Program does.
  588.81 +
  588.82 +  1. You may copy and distribute verbatim copies of the Program's
  588.83 +source code as you receive it, in any medium, provided that you
  588.84 +conspicuously and appropriately publish on each copy an appropriate
  588.85 +copyright notice and disclaimer of warranty; keep intact all the
  588.86 +notices that refer to this License and to the absence of any warranty;
  588.87 +and give any other recipients of the Program a copy of this License
  588.88 +along with the Program.
  588.89 +
  588.90 +You may charge a fee for the physical act of transferring a copy, and
  588.91 +you may at your option offer warranty protection in exchange for a fee.
  588.92 +
  588.93 +  2. You may modify your copy or copies of the Program or any portion
  588.94 +of it, thus forming a work based on the Program, and copy and
  588.95 +distribute such modifications or work under the terms of Section 1
  588.96 +above, provided that you also meet all of these conditions:
  588.97 +
  588.98 +    a) You must cause the modified files to carry prominent notices
  588.99 +    stating that you changed the files and the date of any change.
 588.100 +
 588.101 +    b) You must cause any work that you distribute or publish, that in
 588.102 +    whole or in part contains or is derived from the Program or any
 588.103 +    part thereof, to be licensed as a whole at no charge to all third
 588.104 +    parties under the terms of this License.
 588.105 +
 588.106 +    c) If the modified program normally reads commands interactively
 588.107 +    when run, you must cause it, when started running for such
 588.108 +    interactive use in the most ordinary way, to print or display an
 588.109 +    announcement including an appropriate copyright notice and a
 588.110 +    notice that there is no warranty (or else, saying that you provide
 588.111 +    a warranty) and that users may redistribute the program under
 588.112 +    these conditions, and telling the user how to view a copy of this
 588.113 +    License.  (Exception: if the Program itself is interactive but
 588.114 +    does not normally print such an announcement, your work based on
 588.115 +    the Program is not required to print an announcement.)
 588.116 +
 588.117 +These requirements apply to the modified work as a whole.  If
 588.118 +identifiable sections of that work are not derived from the Program,
 588.119 +and can be reasonably considered independent and separate works in
 588.120 +themselves, then this License, and its terms, do not apply to those
 588.121 +sections when you distribute them as separate works.  But when you
 588.122 +distribute the same sections as part of a whole which is a work based
 588.123 +on the Program, the distribution of the whole must be on the terms of
 588.124 +this License, whose permissions for other licensees extend to the
 588.125 +entire whole, and thus to each and every part regardless of who wrote it.
 588.126 +
 588.127 +Thus, it is not the intent of this section to claim rights or contest
 588.128 +your rights to work written entirely by you; rather, the intent is to
 588.129 +exercise the right to control the distribution of derivative or
 588.130 +collective works based on the Program.
 588.131 +
 588.132 +In addition, mere aggregation of another work not based on the Program
 588.133 +with the Program (or with a work based on the Program) on a volume of
 588.134 +a storage or distribution medium does not bring the other work under
 588.135 +the scope of this License.
 588.136 +
 588.137 +  3. You may copy and distribute the Program (or a work based on it,
 588.138 +under Section 2) in object code or executable form under the terms of
 588.139 +Sections 1 and 2 above provided that you also do one of the following:
 588.140 +
 588.141 +    a) Accompany it with the complete corresponding machine-readable
 588.142 +    source code, which must be distributed under the terms of Sections
 588.143 +    1 and 2 above on a medium customarily used for software interchange; or,
 588.144 +
 588.145 +    b) Accompany it with a written offer, valid for at least three
 588.146 +    years, to give any third party, for a charge no more than your
 588.147 +    cost of physically performing source distribution, a complete
 588.148 +    machine-readable copy of the corresponding source code, to be
 588.149 +    distributed under the terms of Sections 1 and 2 above on a medium
 588.150 +    customarily used for software interchange; or,
 588.151 +
 588.152 +    c) Accompany it with the information you received as to the offer
 588.153 +    to distribute corresponding source code.  (This alternative is
 588.154 +    allowed only for noncommercial distribution and only if you
 588.155 +    received the program in object code or executable form with such
 588.156 +    an offer, in accord with Subsection b above.)
 588.157 +
 588.158 +The source code for a work means the preferred form of the work for
 588.159 +making modifications to it.  For an executable work, complete source
 588.160 +code means all the source code for all modules it contains, plus any
 588.161 +associated interface definition files, plus the scripts used to
 588.162 +control compilation and installation of the executable.  However, as a
 588.163 +special exception, the source code distributed need not include
 588.164 +anything that is normally distributed (in either source or binary
 588.165 +form) with the major components (compiler, kernel, and so on) of the
 588.166 +operating system on which the executable runs, unless that component
 588.167 +itself accompanies the executable.
 588.168 +
 588.169 +If distribution of executable or object code is made by offering
 588.170 +access to copy from a designated place, then offering equivalent
 588.171 +access to copy the source code from the same place counts as
 588.172 +distribution of the source code, even though third parties are not
 588.173 +compelled to copy the source along with the object code.
 588.174 +
 588.175 +  4. You may not copy, modify, sublicense, or distribute the Program
 588.176 +except as expressly provided under this License.  Any attempt
 588.177 +otherwise to copy, modify, sublicense or distribute the Program is
 588.178 +void, and will automatically terminate your rights under this License.
 588.179 +However, parties who have received copies, or rights, from you under
 588.180 +this License will not have their licenses terminated so long as such
 588.181 +parties remain in full compliance.
 588.182 +
 588.183 +  5. You are not required to accept this License, since you have not
 588.184 +signed it.  However, nothing else grants you permission to modify or
 588.185 +distribute the Program or its derivative works.  These actions are
 588.186 +prohibited by law if you do not accept this License.  Therefore, by
 588.187 +modifying or distributing the Program (or any work based on the
 588.188 +Program), you indicate your acceptance of this License to do so, and
 588.189 +all its terms and conditions for copying, distributing or modifying
 588.190 +the Program or works based on it.
 588.191 +
 588.192 +  6. Each time you redistribute the Program (or any work based on the
 588.193 +Program), the recipient automatically receives a license from the
 588.194 +original licensor to copy, distribute or modify the Program subject to
 588.195 +these terms and conditions.  You may not impose any further
 588.196 +restrictions on the recipients' exercise of the rights granted herein.
 588.197 +You are not responsible for enforcing compliance by third parties to
 588.198 +this License.
 588.199 +
 588.200 +  7. If, as a consequence of a court judgment or allegation of patent
 588.201 +infringement or for any other reason (not limited to patent issues),
 588.202 +conditions are imposed on you (whether by court order, agreement or
 588.203 +otherwise) that contradict the conditions of this License, they do not
 588.204 +excuse you from the conditions of this License.  If you cannot
 588.205 +distribute so as to satisfy simultaneously your obligations under this
 588.206 +License and any other pertinent obligations, then as a consequence you
 588.207 +may not distribute the Program at all.  For example, if a patent
 588.208 +license would not permit royalty-free redistribution of the Program by
 588.209 +all those who receive copies directly or indirectly through you, then
 588.210 +the only way you could satisfy both it and this License would be to
 588.211 +refrain entirely from distribution of the Program.
 588.212 +
 588.213 +If any portion of this section is held invalid or unenforceable under
 588.214 +any particular circumstance, the balance of the section is intended to
 588.215 +apply and the section as a whole is intended to apply in other
 588.216 +circumstances.
 588.217 +
 588.218 +It is not the purpose of this section to induce you to infringe any
 588.219 +patents or other property right claims or to contest validity of any
 588.220 +such claims; this section has the sole purpose of protecting the
 588.221 +integrity of the free software distribution system, which is
 588.222 +implemented by public license practices.  Many people have made
 588.223 +generous contributions to the wide range of software distributed
 588.224 +through that system in reliance on consistent application of that
 588.225 +system; it is up to the author/donor to decide if he or she is willing
 588.226 +to distribute software through any other system and a licensee cannot
 588.227 +impose that choice.
 588.228 +
 588.229 +This section is intended to make thoroughly clear what is believed to
 588.230 +be a consequence of the rest of this License.
 588.231 +
 588.232 +  8. If the distribution and/or use of the Program is restricted in
 588.233 +certain countries either by patents or by copyrighted interfaces, the
 588.234 +original copyright holder who places the Program under this License
 588.235 +may add an explicit geographical distribution limitation excluding
 588.236 +those countries, so that distribution is permitted only in or among
 588.237 +countries not thus excluded.  In such case, this License incorporates
 588.238 +the limitation as if written in the body of this License.
 588.239 +
 588.240 +  9. The Free Software Foundation may publish revised and/or new versions
 588.241 +of the General Public License from time to time.  Such new versions will
 588.242 +be similar in spirit to the present version, but may differ in detail to
 588.243 +address new problems or concerns.
 588.244 +
 588.245 +Each version is given a distinguishing version number.  If the Program
 588.246 +specifies a version number of this License which applies to it and "any
 588.247 +later version", you have the option of following the terms and conditions
 588.248 +either of that version or of any later version published by the Free
 588.249 +Software Foundation.  If the Program does not specify a version number of
 588.250 +this License, you may choose any version ever published by the Free Software
 588.251 +Foundation.
 588.252 +
 588.253 +  10. If you wish to incorporate parts of the Program into other free
 588.254 +programs whose distribution conditions are different, write to the author
 588.255 +to ask for permission.  For software which is copyrighted by the Free
 588.256 +Software Foundation, write to the Free Software Foundation; we sometimes
 588.257 +make exceptions for this.  Our decision will be guided by the two goals
 588.258 +of preserving the free status of all derivatives of our free software and
 588.259 +of promoting the sharing and reuse of software generally.
 588.260 +
 588.261 +			    NO WARRANTY
 588.262 +
 588.263 +  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
 588.264 +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
 588.265 +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
 588.266 +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
 588.267 +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 588.268 +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
 588.269 +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
 588.270 +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
 588.271 +REPAIR OR CORRECTION.
 588.272 +
 588.273 +  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
 588.274 +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
 588.275 +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
 588.276 +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
 588.277 +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
 588.278 +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
 588.279 +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
 588.280 +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
 588.281 +POSSIBILITY OF SUCH DAMAGES.
 588.282 +
 588.283 +		     END OF TERMS AND CONDITIONS
 588.284 +
 588.285 +	    How to Apply These Terms to Your New Programs
 588.286 +
 588.287 +  If you develop a new program, and you want it to be of the greatest
 588.288 +possible use to the public, the best way to achieve this is to make it
 588.289 +free software which everyone can redistribute and change under these terms.
 588.290 +
 588.291 +  To do so, attach the following notices to the program.  It is safest
 588.292 +to attach them to the start of each source file to most effectively
 588.293 +convey the exclusion of warranty; and each file should have at least
 588.294 +the "copyright" line and a pointer to where the full notice is found.
 588.295 +
 588.296 +    <one line to give the program's name and a brief idea of what it does.>
 588.297 +    Copyright (C) <year>  <name of author>
 588.298 +
 588.299 +    This program is free software; you can redistribute it and/or modify
 588.300 +    it under the terms of the GNU General Public License as published by
 588.301 +    the Free Software Foundation; either version 2 of the License, or
 588.302 +    (at your option) any later version.
 588.303 +
 588.304 +    This program is distributed in the hope that it will be useful,
 588.305 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
 588.306 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 588.307 +    GNU General Public License for more details.
 588.308 +
 588.309 +    You should have received a copy of the GNU General Public License along
 588.310 +    with this program; if not, write to the Free Software Foundation, Inc.,
 588.311 +    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 588.312 +
 588.313 +Also add information on how to contact you by electronic and paper mail.
 588.314 +
 588.315 +If the program is interactive, make it output a short notice like this
 588.316 +when it starts in an interactive mode:
 588.317 +
 588.318 +    Gnomovision version 69, Copyright (C) year name of author
 588.319 +    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
 588.320 +    This is free software, and you are welcome to redistribute it
 588.321 +    under certain conditions; type `show c' for details.
 588.322 +
 588.323 +The hypothetical commands `show w' and `show c' should show the appropriate
 588.324 +parts of the General Public License.  Of course, the commands you use may
 588.325 +be called something other than `show w' and `show c'; they could even be
 588.326 +mouse-clicks or menu items--whatever suits your program.
 588.327 +
 588.328 +You should also get your employer (if you work as a programmer) or your
 588.329 +school, if any, to sign a "copyright disclaimer" for the program, if
 588.330 +necessary.  Here is a sample; alter the names:
 588.331 +
 588.332 +  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
 588.333 +  `Gnomovision' (which makes passes at compilers) written by James Hacker.
 588.334 +
 588.335 +  <signature of Ty Coon>, 1 April 1989
 588.336 +  Ty Coon, President of Vice
 588.337 +
 588.338 +This General Public License does not permit incorporating your program into
 588.339 +proprietary programs.  If your program is a subroutine library, you may
 588.340 +consider it more useful to permit linking proprietary applications with the
 588.341 +library.  If this is what you want to do, use the GNU Lesser General
 588.342 +Public License instead of this License.
   589.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   589.2 +++ b/src/win32/7zip/7z/DOC/readme.txt	Sat Mar 03 10:31:27 2012 -0600
   589.3 @@ -0,0 +1,49 @@
   589.4 +This copy of the 7-zip source code has been modified as follows:
   589.5 +- Encoding support has been disabled, so only archive extraction is supported.
   589.6 +- Some archive formats have been removed, so only 7z, bzip2, gzip, lzh, lzma, rar, split, tar, and zip are supported.
   589.7 +- Support for using it as a static library has been added. (specifically, a file called InitializeStaticLib.h)
   589.8 +- Occasional minor fixes/customization not really worth describing in detail.
   589.9 +- The LGPL part of the 7-zip library source license has been upgraded to GPL 2.0 (as per condition 3 of the LGPL 2.1)
  589.10 +
  589.11 +You can find most of the files in this library in the "7-Zip Source code" download at http://www.7-zip.org/ distributed under the LGPL 2.1.
  589.12 +A small subset of them are in the LZMA SDK which is public domain and can be found at http://www.7-zip.org/sdk.html
  589.13 +
  589.14 +
  589.15 +
  589.16 +7-Zip 4.64 Sources
  589.17 +------------------
  589.18 +
  589.19 +7-Zip is a file archiver for Windows 95/98/ME/NT/2000/2003/XP/Vista. 
  589.20 +
  589.21 +7-Zip Copyright (C) 1999-2009 Igor Pavlov.
  589.22 +
  589.23 +
  589.24 +License Info
  589.25 +------------
  589.26 +
  589.27 +This copy of 7-Zip is free software distributed under the GNU GPL 2.0
  589.28 +(with an additional restriction that has always applied to the unRar code).
  589.29 +read License.txt for more infomation about license.
  589.30 +
  589.31 +Notes about unRAR license:
  589.32 +
  589.33 +Please check main restriction from unRar license:
  589.34 +
  589.35 +   2. The unRAR sources may be used in any software to handle RAR
  589.36 +      archives without limitations free of charge, but cannot be used
  589.37 +      to re-create the RAR compression algorithm, which is proprietary.
  589.38 +      Distribution of modified unRAR sources in separate form or as a
  589.39 +      part of other software is permitted, provided that it is clearly
  589.40 +      stated in the documentation and source comments that the code may
  589.41 +      not be used to develop a RAR (WinRAR) compatible archiver.
  589.42 +
  589.43 +In brief it means:
  589.44 +1) You can compile and use compiled files under GNU GPL rules, since 
  589.45 +   unRAR license almost has no restrictions for compiled files.
  589.46 +   You can link these compiled files to GPL programs.
  589.47 +2) You can fix bugs in source code and use compiled fixed version.
  589.48 +3) You can not use unRAR sources to re-create the RAR compression algorithm.
  589.49 +
  589.50 +---
  589.51 +Igor Pavlov
  589.52 +http://www.7-zip.org
   590.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   590.2 +++ b/src/win32/7zip/7z/DOC/unRarLicense.txt	Sat Mar 03 10:31:27 2012 -0600
   590.3 @@ -0,0 +1,41 @@
   590.4 + ******    *****   ******   unRAR - free utility for RAR archives
   590.5 + **   **  **   **  **   **  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   590.6 + ******   *******  ******    License for use and distribution of
   590.7 + **   **  **   **  **   **   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   590.8 + **   **  **   **  **   **         FREE portable version
   590.9 +                                   ~~~~~~~~~~~~~~~~~~~~~
  590.10 +
  590.11 +      The source code of unRAR utility is freeware. This means:
  590.12 +
  590.13 +   1. All copyrights to RAR and the utility unRAR are exclusively
  590.14 +      owned by the author - Alexander Roshal.
  590.15 +
  590.16 +   2. The unRAR sources may be used in any software to handle RAR
  590.17 +      archives without limitations free of charge, but cannot be used
  590.18 +      to re-create the RAR compression algorithm, which is proprietary.
  590.19 +      Distribution of modified unRAR sources in separate form or as a
  590.20 +      part of other software is permitted, provided that it is clearly
  590.21 +      stated in the documentation and source comments that the code may
  590.22 +      not be used to develop a RAR (WinRAR) compatible archiver.
  590.23 +
  590.24 +   3. The unRAR utility may be freely distributed. No person or company 
  590.25 +      may charge a fee for the distribution of unRAR without written
  590.26 +      permission from the copyright holder.
  590.27 +
  590.28 +   4. THE RAR ARCHIVER AND THE UNRAR UTILITY ARE DISTRIBUTED "AS IS".
  590.29 +      NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED.  YOU USE AT 
  590.30 +      YOUR OWN RISK. THE AUTHOR WILL NOT BE LIABLE FOR DATA LOSS, 
  590.31 +      DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING
  590.32 +      OR MISUSING THIS SOFTWARE.
  590.33 +
  590.34 +   5. Installing and using the unRAR utility signifies acceptance of
  590.35 +      these terms and conditions of the license.
  590.36 +
  590.37 +   6. If you don't agree with terms of the license you must remove
  590.38 +      unRAR files from your storage devices and cease to use the
  590.39 +      utility.
  590.40 +
  590.41 +      Thank you for your interest in RAR and unRAR.
  590.42 +
  590.43 +
  590.44 +                                            Alexander L. Roshal
  590.45 \ No newline at end of file
   591.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   591.2 +++ b/src/win32/7zip/7zip.cpp	Sat Mar 03 10:31:27 2012 -0600
   591.3 @@ -0,0 +1,392 @@
   591.4 +#include "7zip.h"
   591.5 +
   591.6 +#include "7z/C/Types.h"
   591.7 +#include "7z/CPP/7zip/Archive/IArchive.h"
   591.8 +#include "7z/CPP/Common/InitializeStaticLib.h" // important! (if using a static lib)
   591.9 +
  591.10 +#include <string>
  591.11 +#include <vector>
  591.12 +#include <cassert>
  591.13 +#include <malloc.h>
  591.14 +
  591.15 +#include "7zipstreams.h" // defines OutStream and InFileStream
  591.16 +
  591.17 +STDAPI GetNumberOfFormats(UINT32 *numFormats);
  591.18 +STDAPI GetHandlerProperty2(UInt32 formatIndex, PROPID propID, PROPVARIANT *value);
  591.19 +STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject);
  591.20 +
  591.21 +struct ArchiveFormatInfo
  591.22 +{
  591.23 +	std::string name;
  591.24 +	std::vector<std::string> extensions;
  591.25 +	std::string signature;
  591.26 +	GUID guid;
  591.27 +};
  591.28 +
  591.29 +static std::vector<ArchiveFormatInfo> s_formatInfos;
  591.30 +
  591.31 +static std::string wstrToStr(const wchar_t* wstr)
  591.32 +{
  591.33 +/*
  591.34 +	// This thing wouldn't work
  591.35 +	char* str = (char*)_alloca((wcslen(wstr)+1));
  591.36 +    sprintf(str, "%S", wstr);
  591.37 +	return std::string(str);
  591.38 +*/
  591.39 +//	setlocale(LC_CTYPE, ".ACP");
  591.40 +	size_t n = wcstombs(NULL, wstr, 0);
  591.41 +	if (n == (size_t)-1)	// failed
  591.42 +	{
  591.43 +//		setlocale(LC_CTYPE, "C");
  591.44 +		return std::string();
  591.45 +	}
  591.46 +	char* str = (char*)_alloca(n + 1);
  591.47 +	wcstombs(str, wstr, n);
  591.48 +	str[n] = '\0';
  591.49 +//	setlocale(LC_CTYPE, "C");
  591.50 +	return std::string(str);
  591.51 +}
  591.52 +
  591.53 +static std::vector<std::string> tokenize(const std::string & str, const std::string & delim)
  591.54 +{
  591.55 +	std::vector<std::string> tokens;
  591.56 +	size_t p0 = 0, p1 = std::string::npos;
  591.57 +	while(p0 != std::string::npos)
  591.58 +	{
  591.59 +		p1 = str.find_first_of(delim, p0);
  591.60 +		if(p1 != p0)
  591.61 +		{
  591.62 +			std::string token = str.substr(p0, p1 - p0);
  591.63 +			tokens.push_back(token);
  591.64 +		}
  591.65 +		p0 = str.find_first_not_of(delim, p1);
  591.66 +	}
  591.67 +	return tokens;
  591.68 +}
  591.69 +
  591.70 +static std::string s_supportedFormatsFilter;
  591.71 +const char* GetSupportedFormatsFilter()
  591.72 +{
  591.73 +	assert(!s_formatInfos.empty());
  591.74 +	if(s_supportedFormatsFilter.empty())
  591.75 +	{
  591.76 +		s_supportedFormatsFilter = "";
  591.77 +		for(size_t i = 0; i < s_formatInfos.size(); i++)
  591.78 +		{
  591.79 +			for(size_t j = 0; j < s_formatInfos[i].extensions.size(); j++)
  591.80 +			{
  591.81 +				s_supportedFormatsFilter += ";*.";
  591.82 +				s_supportedFormatsFilter += s_formatInfos[i].extensions[j];
  591.83 +			}
  591.84 +		}
  591.85 +	}
  591.86 +	return s_supportedFormatsFilter.c_str();
  591.87 +}
  591.88 +
  591.89 +void InitDecoder()
  591.90 +{
  591.91 +	CleanupDecoder();
  591.92 +
  591.93 +	UINT32 numFormats = 0;
  591.94 +	GetNumberOfFormats(&numFormats);
  591.95 +
  591.96 +	for(unsigned int i = 0; i < numFormats; i++)
  591.97 +	{
  591.98 +		PROPVARIANT var = {VT_EMPTY};
  591.99 +		ArchiveFormatInfo info;
 591.100 +
 591.101 +		GetHandlerProperty2(i, NArchive::kName, &var);
 591.102 +		if(var.vt == VT_BSTR)
 591.103 +			info.name = wstrToStr(var.bstrVal);
 591.104 +
 591.105 +		GetHandlerProperty2(i, NArchive::kExtension, &var);
 591.106 +		if(var.vt == VT_BSTR)
 591.107 +			info.extensions = tokenize(wstrToStr(var.bstrVal), " ");
 591.108 +
 591.109 +		GetHandlerProperty2(i, NArchive::kStartSignature, &var);
 591.110 +		if(var.vt == VT_BSTR)
 591.111 +			info.signature = (const char*)var.bstrVal; // note: there's no 100% correct way of doing this with the existing 7-zip interface, but this is much better than using SysStringLen() in any way (it would return 1 for the signature "BZh", for example)
 591.112 +
 591.113 +		GetHandlerProperty2(i,NArchive::kClassID,&var);
 591.114 +		if(var.vt == VT_BSTR)
 591.115 +			memcpy(&info.guid, var.bstrVal, 16);
 591.116 +		else
 591.117 +			memset(&info.guid, 0, 16);
 591.118 +
 591.119 +		s_formatInfos.push_back(info);
 591.120 +
 591.121 +		VariantClear((VARIANTARG*)&var);
 591.122 +	}
 591.123 +}
 591.124 +
 591.125 +void CleanupDecoder()
 591.126 +{
 591.127 +	s_formatInfos.clear();
 591.128 +	s_supportedFormatsFilter.clear();
 591.129 +}
 591.130 +
 591.131 +#include "7z/CPP/7zip/Archive/Zip/ZipHandler.h"
 591.132 +
 591.133 +
 591.134 +ArchiveFile::ArchiveFile(const char* filename, const char* displayFilename)
 591.135 +{
 591.136 +	assert(!s_formatInfos.empty());
 591.137 +
 591.138 +	m_typeIndex = -1;
 591.139 +	m_numItems = 0;
 591.140 +	m_items = NULL;
 591.141 +	m_filename = NULL;
 591.142 +	m_displayFilename = NULL;
 591.143 +	m_userMadeSelection = false;
 591.144 +
 591.145 +	FILE* file = fopen(filename, "rb");
 591.146 +	if(!file)
 591.147 +		return;
 591.148 +
 591.149 +	m_filename = new char[strlen(filename)+1];
 591.150 +	strcpy(m_filename, filename);
 591.151 +
 591.152 +	if(displayFilename)
 591.153 +	{
 591.154 +		m_displayFilename = new char[strlen(displayFilename)+1];
 591.155 +		strcpy(m_displayFilename, displayFilename);
 591.156 +	}
 591.157 +
 591.158 +	// detect archive type using format signature in file
 591.159 +	for(size_t i = 0; i < s_formatInfos.size() && m_typeIndex < 0; i++)
 591.160 +	{
 591.161 +		fseek(file, 0, SEEK_SET);
 591.162 +		
 591.163 +		std::string& formatSig = s_formatInfos[i].signature;
 591.164 +		int len = formatSig.size();
 591.165 +
 591.166 +		if(len == 0)
 591.167 +			continue; // because some formats have no signature
 591.168 +
 591.169 +		char* fileSig = (char*)_alloca(len);
 591.170 +		fread(fileSig, 1, len, file);
 591.171 +
 591.172 +		if(!memcmp(formatSig.c_str(), fileSig, len))
 591.173 +			m_typeIndex = i;
 591.174 +	}
 591.175 +
 591.176 +	// if no signature match has been found, detect archive type using filename.
 591.177 +	// this is only for signature-less formats
 591.178 +	const char* fileExt = strrchr(filename, '.');
 591.179 +	if(fileExt++)
 591.180 +	{
 591.181 +		for(size_t i = 0; i < s_formatInfos.size() && m_typeIndex < 0; i++)
 591.182 +		{
 591.183 +			if(s_formatInfos[i].signature.empty())
 591.184 +			{
 591.185 +				std::vector<std::string>& formatExts = s_formatInfos[i].extensions;
 591.186 +				for(size_t j = 0; j < formatExts.size(); j++)
 591.187 +				{
 591.188 +					if(!_stricmp(formatExts[j].c_str(), fileExt))
 591.189 +					{
 591.190 +						m_typeIndex = i;
 591.191 +						break;
 591.192 +					}
 591.193 +				}
 591.194 +			}
 591.195 +		}
 591.196 +	}
 591.197 +
 591.198 +	if(m_typeIndex < 0)
 591.199 +	{
 591.200 +		// uncompressed
 591.201 +
 591.202 +		m_numItems = 1;
 591.203 +		m_items = new ArchiveItem[m_numItems];
 591.204 +
 591.205 +		fseek(file, 0, SEEK_END);
 591.206 +		m_items[0].size = ftell(file);
 591.207 +
 591.208 +		m_items[0].name = new char[strlen(filename)+1];
 591.209 +		strcpy(m_items[0].name, filename);
 591.210 +	}
 591.211 +	else
 591.212 +	{
 591.213 +		IInArchive* object = NULL;
 591.214 +		if(SUCCEEDED(CreateObject(&s_formatInfos[m_typeIndex].guid, &IID_IInArchive, (void**)&object)))
 591.215 +		{
 591.216 +			InFileStream* ifs = new InFileStream(filename);
 591.217 +			if(SUCCEEDED(object->Open(ifs,0,0)))
 591.218 +			{
 591.219 +				UInt32 numItems = 0;
 591.220 +				object->GetNumberOfItems(&numItems);
 591.221 +				m_numItems = numItems;
 591.222 +				m_items = new ArchiveItem[m_numItems];
 591.223 +
 591.224 +				for(int i = 0; i < m_numItems; i++)
 591.225 +				{
 591.226 +					PROPVARIANT var = {VT_EMPTY};
 591.227 +					ArchiveItem& item = m_items[i];
 591.228 +
 591.229 +					object->GetProperty(i, kpidSize, &var);
 591.230 +					item.size = var.uhVal.LowPart;
 591.231 +
 591.232 +					object->GetProperty(i, kpidPath, &var);
 591.233 +					std::string& path = wstrToStr(var.bstrVal);
 591.234 +					item.name = new char[path.size()+1];
 591.235 +					strcpy(item.name, path.c_str());
 591.236 +
 591.237 +					//object->GetProperty(i, kpidMethod, &var);
 591.238 +					//std::string& method = wstrToStr(var.bstrVal);
 591.239 +					//item.method = new char[method.size()+1];
 591.240 +					//strcpy(item.method, method.c_str());
 591.241 +
 591.242 +					object->GetProperty(i, kpidEncrypted, &var);
 591.243 +#ifdef _NO_CRYPTO
 591.244 +					if(var.boolVal)
 591.245 +						item.size = 0; // don't support decompressing it, pretend size zero
 591.246 +#else
 591.247 +					#error password support NYI... see client7z.cpp
 591.248 +					item.encrypted = !!var.boolVal;
 591.249 +#endif
 591.250 +
 591.251 +					VariantClear((VARIANTARG*)&var);
 591.252 +				}
 591.253 +
 591.254 +				object->Close();
 591.255 +			}
 591.256 +
 591.257 +			object->Release();
 591.258 +		}
 591.259 +	}
 591.260 +
 591.261 +	fclose(file);
 591.262 +}
 591.263 +
 591.264 +ArchiveFile::~ArchiveFile()
 591.265 +{
 591.266 +	for(int i = 0; i < m_numItems; i++)
 591.267 +	{
 591.268 +		delete[] m_items[i].name;
 591.269 +	}
 591.270 +	delete[] m_items;
 591.271 +	delete[] m_filename;
 591.272 +	delete[] m_displayFilename;
 591.273 +}
 591.274 +
 591.275 +const char* ArchiveFile::GetArchiveTypeName()
 591.276 +{
 591.277 +	assert(!s_formatInfos.empty());
 591.278 +
 591.279 +	if((size_t)m_typeIndex >= s_formatInfos.size())
 591.280 +		return "";
 591.281 +
 591.282 +	return s_formatInfos[m_typeIndex].name.c_str();
 591.283 +}
 591.284 +
 591.285 +int ArchiveFile::GetNumItems()
 591.286 +{
 591.287 +	return m_numItems;
 591.288 +}
 591.289 +
 591.290 +int ArchiveFile::GetItemSize(int item)
 591.291 +{
 591.292 +	assert(item >= 0 && item < m_numItems);
 591.293 +	if(!(item >= 0 && item < m_numItems)) return 0;
 591.294 +	return m_items[item].size;
 591.295 +}
 591.296 +
 591.297 +const char* ArchiveFile::GetItemName(int item)
 591.298 +{
 591.299 +	//assert(item >= 0 && item < m_numItems);
 591.300 +	if(!(item >= 0 && item < m_numItems)) return "";
 591.301 +	return m_items[item].name;
 591.302 +}
 591.303 +
 591.304 +bool ArchiveFile::IsCompressed()
 591.305 +{
 591.306 +	return (m_typeIndex >= 0);
 591.307 +}
 591.308 +
 591.309 +int ArchiveFile::ExtractItem(int index, unsigned char* outBuffer, int bufSize) const
 591.310 +{
 591.311 +	assert(!s_formatInfos.empty());
 591.312 +	//assert(index >= 0 && index < m_numItems);
 591.313 +	if(!(index >= 0 && index < m_numItems)) return 0;
 591.314 +
 591.315 +	ArchiveItem& item = m_items[index];
 591.316 +
 591.317 +	if(bufSize < item.size)
 591.318 +		return 0;
 591.319 +
 591.320 +	if(m_typeIndex < 0)
 591.321 +	{
 591.322 +		// uncompressed
 591.323 +		FILE* file = fopen(m_filename, "rb");
 591.324 +		fread(outBuffer, 1, item.size, file);
 591.325 +		fclose(file);
 591.326 +	}
 591.327 +	else
 591.328 +	{
 591.329 +		IInArchive* object = NULL;
 591.330 +		HRESULT hr = E_FAIL;
 591.331 +		if(SUCCEEDED(CreateObject(&s_formatInfos[m_typeIndex].guid, &IID_IInArchive, (void**)&object)))
 591.332 +		{
 591.333 +			InFileStream* ifs = new InFileStream(m_filename);
 591.334 +			if(SUCCEEDED(object->Open(ifs,0,0)))
 591.335 +			{
 591.336 +				OutStream* os = new OutStream(index, outBuffer, item.size);
 591.337 +				const UInt32 indices [1] = {index};
 591.338 +				hr = object->Extract(indices, 1, 0, os);
 591.339 +				object->Close();
 591.340 +			}
 591.341 +			object->Release();
 591.342 +		}
 591.343 +		if(FAILED(hr))
 591.344 +			return 0;
 591.345 +	}
 591.346 +
 591.347 +	return item.size;
 591.348 +}
 591.349 +
 591.350 +
 591.351 +
 591.352 +int ArchiveFile::ExtractItem(int index, const char* outFilename) const
 591.353 +{
 591.354 +	assert(!s_formatInfos.empty());
 591.355 +	//assert(index >= 0 && index < m_numItems);
 591.356 +	if(!(index >= 0 && index < m_numItems)) return 0;
 591.357 +
 591.358 +	ArchiveItem& item = m_items[index];
 591.359 +	int rv = item.size;
 591.360 +
 591.361 +	DWORD outAttributes = GetFileAttributes(outFilename);
 591.362 +	if(outAttributes & FILE_ATTRIBUTE_READONLY)
 591.363 +		SetFileAttributes(outFilename, outAttributes & ~FILE_ATTRIBUTE_READONLY); // temporarily remove read-only attribute so we can decompress to there
 591.364 +
 591.365 +	if(m_typeIndex < 0)
 591.366 +	{
 591.367 +		// uncompressed
 591.368 +		if(!CopyFile(m_filename, outFilename, false))
 591.369 +			rv = 0;
 591.370 +	}
 591.371 +	else
 591.372 +	{
 591.373 +		IInArchive* object = NULL;
 591.374 +		HRESULT hr = E_FAIL;
 591.375 +		if(SUCCEEDED(CreateObject(&s_formatInfos[m_typeIndex].guid, &IID_IInArchive, (void**)&object)))
 591.376 +		{
 591.377 +			InFileStream* ifs = new InFileStream(m_filename);
 591.378 +			if(SUCCEEDED(object->Open(ifs,0,0)))
 591.379 +			{
 591.380 +				OutStream* os = new OutStream(index, outFilename);
 591.381 +				const UInt32 indices [1] = {index};
 591.382 +				hr = object->Extract(indices, 1, 0, os);
 591.383 +				object->Close();
 591.384 +			}
 591.385 +			object->Release();
 591.386 +		}
 591.387 +		if(FAILED(hr))
 591.388 +			rv = 0;
 591.389 +	}
 591.390 +
 591.391 +	if(outAttributes & FILE_ATTRIBUTE_READONLY)
 591.392 +		SetFileAttributes(outFilename, outAttributes); // restore read-only attribute
 591.393 +
 591.394 +	return rv;
 591.395 +}
   592.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   592.2 +++ b/src/win32/7zip/7zip.h	Sat Mar 03 10:31:27 2012 -0600
   592.3 @@ -0,0 +1,45 @@
   592.4 +#ifndef _7ZIP_DEC_HEADER
   592.5 +#define _7ZIP_DEC_HEADER
   592.6 +
   592.7 +// 7zip file extraction
   592.8 +// NOTE: if you want to add support for opening files within archives to something,
   592.9 +// consider using the higher-level interface provided by OpenArchive.h instead
  592.10 +
  592.11 +void InitDecoder();
  592.12 +void CleanupDecoder();
  592.13 +const char* GetSupportedFormatsFilter();
  592.14 +
  592.15 +// simplest way of extracting a file after calling InitDecoder():
  592.16 +// int size = ArchiveFile(filename).ExtractItem(0, buf, sizeof(buf));
  592.17 +
  592.18 +struct ArchiveFile
  592.19 +{
  592.20 +	ArchiveFile(const char* filename, const char* displayFilename=0);
  592.21 +	virtual ~ArchiveFile();
  592.22 +
  592.23 +	int GetNumItems();
  592.24 +	int GetItemSize(int item);
  592.25 +	const char* GetItemName(int item);
  592.26 +	int ExtractItem(int item, unsigned char* outBuffer, int bufSize) const; // returns size, or 0 if failed
  592.27 +	int ExtractItem(int item, const char* outFilename) const;
  592.28 +
  592.29 +	bool IsCompressed();
  592.30 +	const char* GetArchiveTypeName();
  592.31 +	const char* GetArchiveFileName() { return m_displayFilename ? m_displayFilename : m_filename; }
  592.32 +
  592.33 +	bool m_userMadeSelection;
  592.34 +
  592.35 +protected:
  592.36 +	struct ArchiveItem
  592.37 +	{
  592.38 +		int size;
  592.39 +		char* name;
  592.40 +	};
  592.41 +	ArchiveItem* m_items;
  592.42 +	int m_numItems;
  592.43 +	int m_typeIndex;
  592.44 +	char* m_filename;
  592.45 +	char* m_displayFilename;
  592.46 +};
  592.47 +
  592.48 +#endif
   593.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   593.2 +++ b/src/win32/7zip/7zip.rc	Sat Mar 03 10:31:27 2012 -0600
   593.3 @@ -0,0 +1,97 @@
   593.4 +// Microsoft Visual C++ generated resource script.
   593.5 +//
   593.6 +#include "../resource.h"
   593.7 +
   593.8 +#define APSTUDIO_READONLY_SYMBOLS
   593.9 +/////////////////////////////////////////////////////////////////////////////
  593.10 +//
  593.11 +// Generated from the TEXTINCLUDE 2 resource.
  593.12 +//
  593.13 +#include "afxres.h"
  593.14 +
  593.15 +/////////////////////////////////////////////////////////////////////////////
  593.16 +#undef APSTUDIO_READONLY_SYMBOLS
  593.17 +
  593.18 +/////////////////////////////////////////////////////////////////////////////
  593.19 +// English (U.S.) resources
  593.20 +
  593.21 +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
  593.22 +#ifdef _WIN32
  593.23 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
  593.24 +#pragma code_page(1252)
  593.25 +#endif //_WIN32
  593.26 +
  593.27 +
  593.28 +/////////////////////////////////////////////////////////////////////////////
  593.29 +//
  593.30 +// Dialog
  593.31 +//
  593.32 +
  593.33 +IDD_ARCHIVEFILECHOOSER DIALOGEX 0, 0, 182, 113
  593.34 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_THICKFRAME
  593.35 +CAPTION "Choose File"
  593.36 +FONT 8, "MS Shell Dlg", 400, 0, 0x1
  593.37 +BEGIN
  593.38 +    DEFPUSHBUTTON   "&OK",IDOK,128,94,50,16
  593.39 +    PUSHBUTTON      "&Cancel",ID_CANCEL,73,94,50,16
  593.40 +    LISTBOX         IDC_LIST1,4,4,173,87,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
  593.41 +END
  593.42 +
  593.43 +
  593.44 +/////////////////////////////////////////////////////////////////////////////
  593.45 +//
  593.46 +// DESIGNINFO
  593.47 +//
  593.48 +
  593.49 +#ifdef APSTUDIO_INVOKED
  593.50 +GUIDELINES DESIGNINFO 
  593.51 +BEGIN
  593.52 +    IDD_ARCHIVEFILECHOOSER, DIALOG
  593.53 +    BEGIN
  593.54 +        RIGHTMARGIN, 181
  593.55 +    END
  593.56 +END
  593.57 +#endif    // APSTUDIO_INVOKED
  593.58 +
  593.59 +
  593.60 +
  593.61 +
  593.62 +#ifdef APSTUDIO_INVOKED
  593.63 +/////////////////////////////////////////////////////////////////////////////
  593.64 +//
  593.65 +// TEXTINCLUDE
  593.66 +//
  593.67 +
  593.68 +1 TEXTINCLUDE 
  593.69 +BEGIN
  593.70 +    "resource.h\0"
  593.71 +END
  593.72 +
  593.73 +3 TEXTINCLUDE 
  593.74 +BEGIN
  593.75 +    "\r\0"
  593.76 +END
  593.77 +
  593.78 +2 TEXTINCLUDE 
  593.79 +BEGIN
  593.80 +    "#include ""afxres.h""\r\0"
  593.81 +END
  593.82 +
  593.83 +#endif    // APSTUDIO_INVOKED
  593.84 +
  593.85 +
  593.86 +#endif    // English (U.S.) resources
  593.87 +/////////////////////////////////////////////////////////////////////////////
  593.88 +
  593.89 +
  593.90 +
  593.91 +#ifndef APSTUDIO_INVOKED
  593.92 +/////////////////////////////////////////////////////////////////////////////
  593.93 +//
  593.94 +// Generated from the TEXTINCLUDE 3 resource.
  593.95 +//
  593.96 +
  593.97 +
  593.98 +/////////////////////////////////////////////////////////////////////////////
  593.99 +#endif    // not APSTUDIO_INVOKED
 593.100 +
   594.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   594.2 +++ b/src/win32/7zip/7zipstreams.h	Sat Mar 03 10:31:27 2012 -0600
   594.3 @@ -0,0 +1,315 @@
   594.4 +// This file is (modified) from
   594.5 +// FCEUX (2009)
   594.6 +// FCE Ultra - NES/Famicom Emulator
   594.7 +// Copyright (C) 2003 Xodnizel
   594.8 +// 
   594.9 +// This program is free software; you can redistribute it and/or modify
  594.10 +// it under the terms of the GNU General Public License as published by
  594.11 +// the Free Software Foundation; either version 2 of the License, or
  594.12 +// (at your option) any later version.
  594.13 +// 
  594.14 +// This program is distributed in the hope that it will be useful,
  594.15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  594.16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  594.17 +// GNU General Public License for more details.
  594.18 +// 
  594.19 +// You should have received a copy of the GNU General Public License
  594.20 +// along with this program; if not, write to the Free Software
  594.21 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  594.22 +
  594.23 +#ifndef _7ZIPSTREAMS_HEADER
  594.24 +#define _7ZIPSTREAMS_HEADER
  594.25 +
  594.26 +#include "7z/CPP/Common/MyCom.h"
  594.27 +
  594.28 +class ICountedSequentialOutStream : public ISequentialOutStream
  594.29 +{
  594.30 +public:
  594.31 +	virtual UINT32 Size() const = 0;
  594.32 +};
  594.33 +
  594.34 +class SeqMemoryOutStream : public ICountedSequentialOutStream, private CMyUnknownImp
  594.35 +{
  594.36 +	UINT8* const output;
  594.37 +	UINT32 pos;
  594.38 +	const UINT32 size;
  594.39 +	ULONG refCount;
  594.40 +
  594.41 +	HRESULT STDMETHODCALLTYPE QueryInterface(REFGUID, void**)
  594.42 +	{
  594.43 +		return E_NOINTERFACE;
  594.44 +	}
  594.45 +
  594.46 +	HRESULT STDMETHODCALLTYPE Write(const void* data, UInt32 length, UInt32* bytesWritten)
  594.47 +	{
  594.48 +		if (data != NULL || size == 0)
  594.49 +		{
  594.50 +			//assert(length <= size - pos);
  594.51 +
  594.52 +			if (length > size - pos)
  594.53 +				length = size - pos;
  594.54 +
  594.55 +			if(data)
  594.56 +				memcpy(output + pos, data, length);
  594.57 +			pos += length;
  594.58 +
  594.59 +			if (bytesWritten)
  594.60 +				*bytesWritten = length;
  594.61 +
  594.62 +			return S_OK;
  594.63 +		}
  594.64 +		else
  594.65 +		{
  594.66 +			return E_INVALIDARG;
  594.67 +		}
  594.68 +	}
  594.69 +
  594.70 +	MY_ADDREF_RELEASE
  594.71 +
  594.72 +public:
  594.73 +
  594.74 +	SeqMemoryOutStream(void* d, UINT32 s) : output((UINT8*)d), pos(0), size(s), refCount(0) {}
  594.75 +
  594.76 +	virtual ~SeqMemoryOutStream()
  594.77 +	{
  594.78 +		int a = 0;
  594.79 +	}
  594.80 +
  594.81 +	UINT32 Size() const
  594.82 +	{
  594.83 +		return pos;
  594.84 +	}
  594.85 +};
  594.86 +
  594.87 +class SeqFileOutStream : public ICountedSequentialOutStream, private CMyUnknownImp
  594.88 +{
  594.89 +	FILE* file;
  594.90 +	UINT32 pos;
  594.91 +	ULONG refCount;
  594.92 +
  594.93 +	HRESULT STDMETHODCALLTYPE QueryInterface(REFGUID, void**)
  594.94 +	{
  594.95 +		return E_NOINTERFACE;
  594.96 +	}
  594.97 +
  594.98 +	HRESULT STDMETHODCALLTYPE Write(const void* data, UInt32 length, UInt32* bytesWritten)
  594.99 +	{
 594.100 +		if(!file)
 594.101 +			return E_FAIL;
 594.102 +
 594.103 +		if (data != NULL)
 594.104 +		{
 594.105 +			int written = 0;
 594.106 +			if(data)
 594.107 +				written = fwrite(data, 1, length, file);
 594.108 +
 594.109 +			pos += written;
 594.110 +			if (bytesWritten)
 594.111 +				*bytesWritten = written;
 594.112 +
 594.113 +			return S_OK;
 594.114 +		}
 594.115 +		else
 594.116 +		{
 594.117 +			return E_INVALIDARG;
 594.118 +		}
 594.119 +	}
 594.120 +
 594.121 +	MY_ADDREF_RELEASE
 594.122 +
 594.123 +public:
 594.124 +
 594.125 +	SeqFileOutStream(const char* outFilename) : pos(0), refCount(0)
 594.126 +	{
 594.127 +		file = fopen(outFilename, "wb");
 594.128 +	}
 594.129 +	virtual ~SeqFileOutStream()
 594.130 +	{
 594.131 +		if(file)
 594.132 +			fclose(file);
 594.133 +	}
 594.134 +
 594.135 +	UINT32 Size() const
 594.136 +	{
 594.137 +		return pos;
 594.138 +	}
 594.139 +};
 594.140 +
 594.141 +
 594.142 +class OutStream : public IArchiveExtractCallback, private CMyUnknownImp
 594.143 +{
 594.144 +	ICountedSequentialOutStream* seqStream;
 594.145 +	const UINT32 index;
 594.146 +	ULONG refCount;
 594.147 +
 594.148 +	HRESULT STDMETHODCALLTYPE QueryInterface(REFGUID, void**)
 594.149 +	{
 594.150 +		return E_NOINTERFACE;
 594.151 +	}
 594.152 +
 594.153 +	HRESULT STDMETHODCALLTYPE PrepareOperation(Int32)
 594.154 +	{
 594.155 +		return S_OK;
 594.156 +	}
 594.157 +
 594.158 +	HRESULT STDMETHODCALLTYPE SetTotal(UInt64)
 594.159 +	{
 594.160 +		return S_OK;
 594.161 +	}
 594.162 +
 594.163 +	HRESULT STDMETHODCALLTYPE SetCompleted(const UInt64*)
 594.164 +	{
 594.165 +		return S_OK;
 594.166 +	}
 594.167 +
 594.168 +	HRESULT STDMETHODCALLTYPE SetOperationResult(Int32)
 594.169 +	{
 594.170 +		return S_OK;
 594.171 +	}
 594.172 +
 594.173 +	HRESULT STDMETHODCALLTYPE GetStream(UInt32 id, ISequentialOutStream** ptr, Int32 mode)
 594.174 +	{
 594.175 +		switch (mode)
 594.176 +		{
 594.177 +			case NArchive::NExtract::NAskMode::kExtract:
 594.178 +			case NArchive::NExtract::NAskMode::kTest:
 594.179 +
 594.180 +				if (id != index || ptr == NULL)
 594.181 +					return S_FALSE;
 594.182 +				else
 594.183 +					*ptr = seqStream;
 594.184 +			// fall through
 594.185 +			case NArchive::NExtract::NAskMode::kSkip:
 594.186 +				return S_OK;
 594.187 +
 594.188 +			default:
 594.189 +				return E_INVALIDARG;
 594.190 +		}
 594.191 +	}
 594.192 +
 594.193 +	MY_ADDREF_RELEASE
 594.194 +
 594.195 +public:
 594.196 +
 594.197 +	OutStream(UINT32 index, void* data, UINT32 size) : index(index), refCount(0)
 594.198 +	{
 594.199 +		seqStream = new SeqMemoryOutStream(data, size);
 594.200 +		seqStream->AddRef();
 594.201 +	}
 594.202 +	OutStream(UINT32 index, const char* outFilename) : index(index), refCount(0)
 594.203 +	{
 594.204 +		seqStream = new SeqFileOutStream(outFilename);
 594.205 +		seqStream->AddRef();
 594.206 +	}
 594.207 +	virtual ~OutStream()
 594.208 +	{
 594.209 +		//seqStream->Release(); // commented out because apparently IInArchive::Extract() calls Release one more time than it calls AddRef
 594.210 +	}
 594.211 +	UINT32 Size() const
 594.212 +	{
 594.213 +		return seqStream->Size();
 594.214 +	}
 594.215 +};
 594.216 +
 594.217 +class InStream : public IInStream, private IStreamGetSize, private CMyUnknownImp
 594.218 +{
 594.219 +	ULONG refCount;
 594.220 +
 594.221 +	HRESULT STDMETHODCALLTYPE QueryInterface(REFGUID, void**)
 594.222 +	{
 594.223 +		return E_NOINTERFACE;
 594.224 +	}
 594.225 +
 594.226 +	HRESULT STDMETHODCALLTYPE GetSize(UInt64* outSize)
 594.227 +	{
 594.228 +		if (outSize)
 594.229 +		{
 594.230 +			*outSize = size;
 594.231 +			return S_OK;
 594.232 +		}
 594.233 +		else
 594.234 +		{
 594.235 +			return E_INVALIDARG;
 594.236 +		}
 594.237 +	}
 594.238 +
 594.239 +	MY_ADDREF_RELEASE
 594.240 +
 594.241 +protected:
 594.242 +
 594.243 +	UINT32 size;
 594.244 +
 594.245 +public:
 594.246 +
 594.247 +	explicit InStream() : refCount(0) {}
 594.248 +	virtual ~InStream() {}
 594.249 +};
 594.250 +
 594.251 +
 594.252 +class InFileStream : public InStream
 594.253 +{
 594.254 +public:
 594.255 +
 594.256 +	virtual ~InFileStream()
 594.257 +	{
 594.258 +		if(file)
 594.259 +			fclose(file);
 594.260 +	}
 594.261 +
 594.262 +	FILE* file;
 594.263 +
 594.264 +	InFileStream(const char* fname) : file(NULL)
 594.265 +	{
 594.266 +		file = fopen(fname, "rb");
 594.267 +		if(file)
 594.268 +		{
 594.269 +			fseek(file, 0, SEEK_END);
 594.270 +			size = ftell(file);
 594.271 +			fseek(file, 0, SEEK_SET);
 594.272 +		}
 594.273 +	}
 594.274 +
 594.275 +	HRESULT STDMETHODCALLTYPE Read(void* data, UInt32 length, UInt32* bytesRead)
 594.276 +	{
 594.277 +		if(!file)
 594.278 +			return E_FAIL;
 594.279 +
 594.280 +		if (data != NULL || length == 0)
 594.281 +		{
 594.282 +			int read = fread(data, 1, length, file);
 594.283 +			
 594.284 +			if (bytesRead)
 594.285 +				*bytesRead = read;
 594.286 +
 594.287 +			return S_OK;
 594.288 +		}
 594.289 +		else
 594.290 +		{
 594.291 +			return E_INVALIDARG;
 594.292 +		}
 594.293 +	}
 594.294 +
 594.295 +	HRESULT STDMETHODCALLTYPE Seek(Int64 offset, UInt32 origin, UInt64* pos)
 594.296 +	{
 594.297 +		if(!file)
 594.298 +			return E_FAIL;
 594.299 +
 594.300 +		if (origin < 3)
 594.301 +		{
 594.302 +			fseek(file, (long)offset, origin);
 594.303 +			origin = ftell(file);
 594.304 +
 594.305 +			if (pos)
 594.306 +				*pos = origin;
 594.307 +
 594.308 +			return S_OK;
 594.309 +		}
 594.310 +		else
 594.311 +		{
 594.312 +			return E_INVALIDARG;
 594.313 +		}
 594.314 +	
 594.315 +	}
 594.316 +};
 594.317 +
 594.318 +#endif
   595.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   595.2 +++ b/src/win32/7zip/OpenArchive.cpp	Sat Mar 03 10:31:27 2012 -0600
   595.3 @@ -0,0 +1,713 @@
   595.4 +#include "../stdafx.h"
   595.5 +#include "../resource.h"
   595.6 +#include <windows.h>
   595.7 +#include <mmsystem.h>
   595.8 +#include <cstdio>
   595.9 +#include <cerrno>
  595.10 +#include <cassert>
  595.11 +#include <cstring>
  595.12 +#include <map>
  595.13 +#include <vector>
  595.14 +#include <algorithm>
  595.15 +#include "7zip.h"
  595.16 +//#include "G_main.h"
  595.17 +//#include "G_dsound.h"
  595.18 +#include "OpenArchive.h"
  595.19 +
  595.20 +LRESULT CALLBACK ArchiveFileChooser(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  595.21 +static int s_archiveFileChooserResult = -1;
  595.22 +
  595.23 +static HWND s_parentHWND = NULL;
  595.24 +void SetArchiveParentHWND(void* hwnd) { s_parentHWND = (HWND)hwnd; }
  595.25 +static HWND GetArchiveParentHWND() { return s_parentHWND ? s_parentHWND : AfxGetApp()->m_pMainWnd->GetSafeHwnd(); }
  595.26 +
  595.27 +static char Str_Tmp [2048];
  595.28 +
  595.29 +struct ArchiveFileChooserInfo
  595.30 +{
  595.31 +	ArchiveFileChooserInfo(ArchiveFile& theArchive, const char** ignoreExtensions, int& numIgnoreExtensions) : archive(theArchive)
  595.32 +	{
  595.33 +tryagain:
  595.34 +		int numItems = archive.GetNumItems();
  595.35 +		for(int i = 0; i < numItems; i++)
  595.36 +		{
  595.37 +			if(archive.GetItemSize(i))
  595.38 +			{
  595.39 +				const char* name = archive.GetItemName(i);
  595.40 +				const char* ext = strrchr(name, '.');
  595.41 +				bool ok = true;
  595.42 +				if(ext++)
  595.43 +				{
  595.44 +					for(int j = 0; j < numIgnoreExtensions; j++)
  595.45 +					{
  595.46 +						const char* ext2 = ignoreExtensions[j];
  595.47 +						const char* wild = strchr(ext2, '*');
  595.48 +						if(!wild)
  595.49 +						{
  595.50 +							if(!_stricmp(ext, ext2))
  595.51 +							{
  595.52 +								ok = false;
  595.53 +								break;
  595.54 +							}
  595.55 +						}
  595.56 +						else // very limited (end only) wildcard support
  595.57 +						{
  595.58 +							if(!_strnicmp(ext, ext2, wild - ext2))
  595.59 +							{
  595.60 +								ok = false;
  595.61 +								break;
  595.62 +							}
  595.63 +						}
  595.64 +					}
  595.65 +				}
  595.66 +				if(ok)
  595.67 +				{
  595.68 +					ArchiveFileChooserInfo::FileInfo fi = { name, i };
  595.69 +					files.push_back(fi);
  595.70 +				}
  595.71 +			}
  595.72 +		}
  595.73 +
  595.74 +		if(files.empty() && numIgnoreExtensions)
  595.75 +		{
  595.76 +			// try again without any exclusions if we excluded everything in the archive
  595.77 +			numIgnoreExtensions = 0;
  595.78 +			goto tryagain;
  595.79 +		}
  595.80 +
  595.81 +		// strip away prefix paths that are common to all the files
  595.82 +		bool stripping = !files.empty();
  595.83 +		while(stripping)
  595.84 +		{
  595.85 +			const char* firstName = files[0].name.c_str();
  595.86 +			const char* slash = strchr(firstName, '\\');
  595.87 +			const char* slash2 = strchr(firstName, '/');
  595.88 +			slash = max(slash, slash2);
  595.89 +			if(!slash++)
  595.90 +				break;
  595.91 +			for(size_t i = 1; i < files.size(); i++)
  595.92 +				if(strncmp(firstName, files[i].name.c_str(), slash - firstName))
  595.93 +					stripping = false;
  595.94 +			if(stripping)
  595.95 +				for(size_t i = 0; i < files.size(); i++)
  595.96 +					files[i].name = files[i].name.substr(slash - firstName, files[i].name.length() - (slash - firstName));
  595.97 +		}
  595.98 +
  595.99 +		// sort by filename
 595.100 +		std::sort(files.begin(), files.end(), FileInfo::Sort);
 595.101 +	}
 595.102 +
 595.103 +//protected:
 595.104 +
 595.105 +	struct FileInfo
 595.106 +	{
 595.107 +		std::string name;
 595.108 +		int itemIndex;
 595.109 +		
 595.110 +		static bool Sort(const FileInfo& elem1, const FileInfo& elem2)
 595.111 +		{
 595.112 +			int comp = elem1.name.compare(elem2.name);
 595.113 +			return comp ? (comp < 0) : (elem1.itemIndex < elem2.itemIndex);
 595.114 +		}
 595.115 +	};
 595.116 +
 595.117 +	ArchiveFile& archive;
 595.118 +	std::vector<FileInfo> files;
 595.119 +};
 595.120 +
 595.121 +static void ClearLayoutStates();
 595.122 +
 595.123 +int ChooseItemFromArchive(ArchiveFile& archive, bool autoChooseIfOnly1, const char** ignoreExtensions, int numIgnoreExtensions)
 595.124 +{
 595.125 +	int prevNumIgnoreExtensions = numIgnoreExtensions;
 595.126 +	archive.m_userMadeSelection = false;
 595.127 +
 595.128 +	// prepare a list of files to choose from the archive
 595.129 +	ArchiveFileChooserInfo info (archive, ignoreExtensions, numIgnoreExtensions);
 595.130 +
 595.131 +	// based on our list, decide which item in the archive to choose
 595.132 +
 595.133 +	// check if there's nothing
 595.134 +	if(info.files.size() < 1)
 595.135 +	{
 595.136 +		MessageBox(GetArchiveParentHWND(), "The archive is either empty or encrypted.", "Nothing to load!", MB_OK | MB_ICONWARNING);
 595.137 +		return -1;
 595.138 +	}
 595.139 +
 595.140 +	// warn if all the files in the archive have extensions we should ignore
 595.141 +	if(numIgnoreExtensions != prevNumIgnoreExtensions)
 595.142 +	{
 595.143 +		CString msg;
 595.144 +		msg.Format("The archive appears to only contain the wrong type of files.\n\n(in \"%s\")", archive.GetArchiveFileName());
 595.145 +		int answer = MessageBox(GetArchiveParentHWND(), msg, "Warning", MB_OKCANCEL | MB_ICONWARNING | MB_DEFBUTTON2);
 595.146 +		if(answer == IDCANCEL)
 595.147 +			return -1;
 595.148 +	}
 595.149 +
 595.150 +	// if there's only 1 item, choose it
 595.151 +	if(info.files.size() == 1 && autoChooseIfOnly1 && numIgnoreExtensions == prevNumIgnoreExtensions)
 595.152 +		return info.files[0].itemIndex;
 595.153 +
 595.154 +	// bring up a dialog to choose the index if there's more than 1
 595.155 +	DialogBoxParam(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD_ARCHIVEFILECHOOSER), GetArchiveParentHWND(), (DLGPROC) ArchiveFileChooser,(LPARAM) &info);
 595.156 +	archive.m_userMadeSelection = (s_archiveFileChooserResult != -1);
 595.157 +	return s_archiveFileChooserResult;
 595.158 +}
 595.159 +
 595.160 +
 595.161 +
 595.162 +
 595.163 +#define DEFAULT_EXTENSION ".tmp"
 595.164 +#define DEFAULT_CATEGORY "vba"
 595.165 +
 595.166 +static struct TempFiles
 595.167 +{
 595.168 +	struct TemporaryFile
 595.169 +	{
 595.170 +		TemporaryFile(const char* cat, const char* ext)
 595.171 +		{
 595.172 +			if(!ext || !*ext) ext = DEFAULT_EXTENSION;
 595.173 +			if(!cat || !*cat) cat = DEFAULT_CATEGORY;
 595.174 +			category = cat;
 595.175 +
 595.176 +			char tempPath [2048];
 595.177 +			GetTempPath(2048, tempPath);
 595.178 +			//GetTempFileName(tempPath, cat, 0, filename, ext); // alas
 595.179 +
 595.180 +			char*const fname = tempPath + strlen(tempPath);
 595.181 +			unsigned short start = (unsigned short)(timeGetTime() & 0xFFFF);
 595.182 +			unsigned short n = start + 1;
 595.183 +			while(n != start)
 595.184 +			{
 595.185 +				_snprintf(fname, 2048 - (fname - tempPath), "%s%04X%s", cat, n, ext);
 595.186 +				FILE* file = fopen(tempPath, "wb");
 595.187 +				if(file)
 595.188 +				{
 595.189 +					// mark the temporary file as read-only and (whatever this does) temporary
 595.190 +					DWORD attributes = GetFileAttributes(tempPath);
 595.191 +					attributes |= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_TEMPORARY;
 595.192 +					SetFileAttributes(tempPath, attributes);
 595.193 +
 595.194 +					fclose(file);
 595.195 +
 595.196 +					// add it to our registry of files that need to be deleted, in case we fail to terminate properly
 595.197 +					TempFiles::AddEntryToGarbageRegistry(tempPath);
 595.198 +
 595.199 +					break;
 595.200 +				}
 595.201 +				n++;
 595.202 +			}
 595.203 +			strcpy(filename, tempPath);
 595.204 +		}
 595.205 +		TemporaryFile(const TemporaryFile& copy)
 595.206 +		{
 595.207 +			strcpy(filename, copy.filename);
 595.208 +			category = copy.category;
 595.209 +		}
 595.210 +		TemporaryFile()
 595.211 +		{
 595.212 +			filename[0] = 0;
 595.213 +			// category[0] = 0;	// error
 595.214 +		}
 595.215 +		bool Delete(bool returnFalseOnRegistryRemovalFailure=false)
 595.216 +		{
 595.217 +			if(!*filename)
 595.218 +				return true; // guess it already didn't exist
 595.219 +
 595.220 +			// remove read-only attribute so Windows will let us delete it
 595.221 +			// (our temporary files are read-only to discourage other apps from tampering)
 595.222 +			DWORD attributes = GetFileAttributes(filename);
 595.223 +			if(attributes & FILE_ATTRIBUTE_READONLY)
 595.224 +				SetFileAttributes(filename, attributes & ~FILE_ATTRIBUTE_READONLY);
 595.225 +
 595.226 +			if(_unlink(filename) == 0 || errno != EACCES)
 595.227 +			{
 595.228 +				// remove it from our registry of files that need to be deleted, to reduce accumulation
 595.229 +				bool removed = TempFiles::RemoveEntryFromGarbageRegistry(filename);
 595.230 +
 595.231 +				*filename = '\0';
 595.232 +				return removed || !returnFalseOnRegistryRemovalFailure; // successfully deleted or already didn't exist, return true unless registry removal failure notification was requested and that failed
 595.233 +			}
 595.234 +
 595.235 +			// restore read-only if we couldn't delete it (not sure if this ever succeeds or matters though)
 595.236 +			if(attributes & FILE_ATTRIBUTE_READONLY)
 595.237 +				SetFileAttributes(filename, attributes);
 595.238 +
 595.239 +			return false; // failed to delete read-only or in-use file
 595.240 +		}
 595.241 +		char filename [MAX_PATH];
 595.242 +		std::string category;
 595.243 +	};
 595.244 +
 595.245 +	std::vector<TemporaryFile> tempFiles;
 595.246 +
 595.247 +	const char* GetFile(const char* category, const char* extension)
 595.248 +	{
 595.249 +		tempFiles.push_back(TemporaryFile(category, extension));
 595.250 +		return tempFiles.back().filename;
 595.251 +	}
 595.252 +
 595.253 +	void ReleaseFile(const char* filename)
 595.254 +	{
 595.255 +		for(int i = (int)tempFiles.size()-1; i >= 0; i--)
 595.256 +		{
 595.257 +			if(!strcmp(filename, tempFiles[i].filename))
 595.258 +			{
 595.259 +				if(tempFiles[i].Delete())
 595.260 +					tempFiles.erase(tempFiles.begin() + i);
 595.261 +			}
 595.262 +		}
 595.263 +	}
 595.264 +
 595.265 +	void ReleaseCategory(const char* cat, const char* exceptionFilename)
 595.266 +	{
 595.267 +		for(int i = (int)tempFiles.size()-1; i >= 0; i--)
 595.268 +		{
 595.269 +			if(!strcmp(cat, tempFiles[i].category.c_str()) &&
 595.270 +				(!exceptionFilename ||
 595.271 +				  strcmp(exceptionFilename, tempFiles[i].filename)))
 595.272 +			{
 595.273 +				if(tempFiles[i].Delete())
 595.274 +					tempFiles.erase(tempFiles.begin() + i);
 595.275 +			}
 595.276 +		}
 595.277 +	}
 595.278 +
 595.279 +	// delete all temporary files on shutdown
 595.280 +	~TempFiles()
 595.281 +	{
 595.282 +		for(size_t i = 0; i < tempFiles.size(); i++)
 595.283 +		{
 595.284 +			tempFiles[i].Delete();
 595.285 +		}
 595.286 +
 595.287 +		TempFiles::CleanOutGarbageRegistry();
 595.288 +	}
 595.289 +
 595.290 +	// run this on startup to delete any files that we failed to delete last time
 595.291 +	// in case we crashed or were forcefully terminated
 595.292 +	TempFiles()
 595.293 +	{
 595.294 +		TempFiles::CleanOutGarbageRegistry();
 595.295 +	}
 595.296 +
 595.297 +	static void AddEntryToGarbageRegistry(const char* filename)
 595.298 +	{
 595.299 +		char gbgFile[2048];
 595.300 +		GetTempPath(2048, gbgFile);
 595.301 +		strcat(gbgFile, "VBATempFileRecords");
 595.302 +		char key[64];
 595.303 +		int i = 0;
 595.304 +		while(true)
 595.305 +		{
 595.306 +			sprintf(key, "File%d", i);
 595.307 +			GetPrivateProfileString("Files", key, "", Str_Tmp, 2048, gbgFile);
 595.308 +			if(!*Str_Tmp)
 595.309 +				break;
 595.310 +			i++;
 595.311 +		}
 595.312 +		WritePrivateProfileString("Files", key, filename, gbgFile);
 595.313 +	}
 595.314 +	static bool RemoveEntryFromGarbageRegistry(const char* filename)
 595.315 +	{
 595.316 +		char gbgFile[2048];
 595.317 +		GetTempPath(2048, gbgFile);
 595.318 +		strcat(gbgFile, "VBATempFileRecords");
 595.319 +		char key[64];
 595.320 +		int i = 0;
 595.321 +		int deleteSlot = -1;
 595.322 +		while(true)
 595.323 +		{
 595.324 +			sprintf(key, "File%d", i);
 595.325 +			GetPrivateProfileString("Files", key, "", Str_Tmp, 2048, gbgFile);
 595.326 +			if(!*Str_Tmp)
 595.327 +				break;
 595.328 +			if(!strcmp(Str_Tmp, filename))
 595.329 +				deleteSlot = i;
 595.330 +			i++;
 595.331 +		}
 595.332 +		--i;
 595.333 +		if(i >= 0 && deleteSlot >= 0)
 595.334 +		{
 595.335 +			if(i != deleteSlot)
 595.336 +			{
 595.337 +				sprintf(key, "File%d", i);
 595.338 +				GetPrivateProfileString("Files", key, "", Str_Tmp, 2048, gbgFile);
 595.339 +				sprintf(key, "File%d", deleteSlot);
 595.340 +				WritePrivateProfileString("Files", key, Str_Tmp, gbgFile);
 595.341 +			}
 595.342 +			sprintf(key, "File%d", i);
 595.343 +			if(0 == WritePrivateProfileString("Files", key, NULL, gbgFile))
 595.344 +				return false;
 595.345 +		}
 595.346 +		if(i <= 0 && deleteSlot == 0)
 595.347 +			_unlink(gbgFile);
 595.348 +		return true;
 595.349 +	}
 595.350 +
 595.351 +private:
 595.352 +	static void CleanOutGarbageRegistry()
 595.353 +	{
 595.354 +		char gbgFile[2048];
 595.355 +		GetTempPath(2048, gbgFile);
 595.356 +		strcat(gbgFile, "VBATempFileRecords");
 595.357 +
 595.358 +		char key[64];
 595.359 +		int i = 0;
 595.360 +		while(true)
 595.361 +		{
 595.362 +			sprintf(key, "File%d", i);
 595.363 +			GetPrivateProfileString("Files", key, "", Str_Tmp, 2048, gbgFile);
 595.364 +			if(!*Str_Tmp)
 595.365 +				break;
 595.366 +			TemporaryFile temp;
 595.367 +			strcpy(temp.filename, Str_Tmp);
 595.368 +			if(!temp.Delete(true))
 595.369 +				i++;
 595.370 +		}
 595.371 +	}
 595.372 +
 595.373 +} s_tempFiles;
 595.374 +
 595.375 +
 595.376 +const char* GetTempFile(const char* category, const char* extension)
 595.377 +{
 595.378 +	return s_tempFiles.GetFile(category, extension);
 595.379 +}
 595.380 +void ReleaseTempFile(const char* filename)
 595.381 +{
 595.382 +	s_tempFiles.ReleaseFile(filename);
 595.383 +}
 595.384 +void ReleaseTempFileCategory(const char* cat, const char* exceptionFilename)
 595.385 +{
 595.386 +	if(!cat || !*cat) cat = DEFAULT_CATEGORY;
 595.387 +	s_tempFiles.ReleaseCategory(cat, exceptionFilename);
 595.388 +}
 595.389 +
 595.390 +
 595.391 +
 595.392 +// example input Name:          "C:\games.zip"
 595.393 +// example output LogicalName:  "C:\games.zip|Metroid.gba"
 595.394 +// example output PhysicalName: "C:\Documents and Settings\User\Local Settings\Temp\VBA\rom7A37.gba"
 595.395 +// assumes arguments are character buffers with 2048 bytes each
 595.396 +bool ObtainFile(const char* Name, char *const & LogicalName, char *const & PhysicalName, const char* category, const char** ignoreExtensions, int numIgnoreExtensions)
 595.397 +{
 595.398 +restart:
 595.399 +	char ArchivePaths [2048];
 595.400 +	strcpy(LogicalName, Name);
 595.401 +	strcpy(PhysicalName, Name);
 595.402 +	strcpy(ArchivePaths, Name);
 595.403 +	char* bar = strchr(ArchivePaths, '|');
 595.404 +	if(bar)
 595.405 +	{
 595.406 +		PhysicalName[bar - ArchivePaths] = 0; // doesn't belong in the physical name
 595.407 +		LogicalName[bar - ArchivePaths] = 0; // we'll reconstruct the logical name as we go
 595.408 +		*bar++ = 0; // bar becomes the next logical archive path component
 595.409 +	}
 595.410 +
 595.411 +	bool userSelected = false;
 595.412 +
 595.413 +	while(true)
 595.414 +	{
 595.415 +		ArchiveFile archive (PhysicalName, LogicalName);
 595.416 +		if(!archive.IsCompressed())
 595.417 +		{
 595.418 +			if(archive.GetNumItems() > 0)
 595.419 +				return true;
 595.420 +			else
 595.421 +			{
 595.422 +				// failed or cancelled... backtrack to outermost archive if not already there
 595.423 +				char* div = NULL;
 595.424 +				if(LogicalName[strlen(LogicalName)-1] == '|')
 595.425 +				{
 595.426 +					LogicalName[strlen(LogicalName)-1] = '\0';
 595.427 +					div = strrchr(LogicalName, '|');
 595.428 +				}
 595.429 +				if(div && userSelected)
 595.430 +					goto restart;
 595.431 +				else
 595.432 +					return false;
 595.433 +			}
 595.434 +		}
 595.435 +		else
 595.436 +		{
 595.437 +			int item = -1;
 595.438 +			bool forceManual = false;
 595.439 +			if(bar && *bar) // try following the in-archive part of the logical path
 595.440 +			{
 595.441 +				char* bar2 = strchr(bar, '|');
 595.442 +				if(bar2) *bar2++ = 0;
 595.443 +				int numItems = archive.GetNumItems();
 595.444 +				for(int i = 0; i < numItems; i++)
 595.445 +				{
 595.446 +					if(archive.GetItemSize(i))
 595.447 +					{
 595.448 +						const char* itemName = archive.GetItemName(i);
 595.449 +						if(!_stricmp(itemName, bar))
 595.450 +						{
 595.451 +							item = i; // match found, now we'll auto-follow the path
 595.452 +							break;
 595.453 +						}
 595.454 +					}
 595.455 +				}
 595.456 +				if(item < 0)
 595.457 +				{
 595.458 +					forceManual = true; // we don't want it choosing something else without user permission
 595.459 +					bar = NULL; // remaining archive path is invalid
 595.460 +				}
 595.461 +				else
 595.462 +					bar = bar2; // advance to next archive path part
 595.463 +			}
 595.464 +			if(item < 0)
 595.465 +				item = ChooseItemFromArchive(archive, !forceManual, ignoreExtensions, numIgnoreExtensions);
 595.466 +			
 595.467 +			userSelected |= archive.m_userMadeSelection;
 595.468 +
 595.469 +			const char* TempFileName = s_tempFiles.GetFile(category, strrchr(archive.GetItemName(item), '.'));
 595.470 +			if(!archive.ExtractItem(item, TempFileName))
 595.471 +				s_tempFiles.ReleaseFile(TempFileName);
 595.472 +			s_tempFiles.ReleaseFile(PhysicalName);
 595.473 +			strcpy(PhysicalName, TempFileName);
 595.474 +			_snprintf(LogicalName + strlen(LogicalName), 2048 - (strlen(LogicalName)+1), "|%s", archive.GetItemName(item));
 595.475 +		}
 595.476 +	}
 595.477 +}
 595.478 +
 595.479 +
 595.480 +
 595.481 +struct ControlLayoutInfo
 595.482 +{
 595.483 +	int controlID;
 595.484 +	
 595.485 +	enum LayoutType // what to do when the containing window resizes
 595.486 +	{
 595.487 +		NONE, // leave the control where it was
 595.488 +		RESIZE_END, // resize the control
 595.489 +		MOVE_START, // move the control
 595.490 +	};
 595.491 +	LayoutType horizontalLayout;
 595.492 +	LayoutType verticalLayout;
 595.493 +};
 595.494 +struct ControlLayoutState
 595.495 +{
 595.496 +	int x,y,width,height;
 595.497 +	bool valid;
 595.498 +	ControlLayoutState() : valid(false) {}
 595.499 +};
 595.500 +
 595.501 +static ControlLayoutInfo controlLayoutInfos [] = {
 595.502 +	{IDC_LIST1, ControlLayoutInfo::RESIZE_END, ControlLayoutInfo::RESIZE_END},
 595.503 +	{IDOK,      ControlLayoutInfo::MOVE_START, ControlLayoutInfo::MOVE_START},
 595.504 +	{ID_CANCEL, ControlLayoutInfo::MOVE_START, ControlLayoutInfo::MOVE_START},
 595.505 +};
 595.506 +static const int numControlLayoutInfos = sizeof(controlLayoutInfos)/sizeof(*controlLayoutInfos);
 595.507 +
 595.508 +static ControlLayoutState s_layoutState [numControlLayoutInfos];
 595.509 +static int s_windowWidth = 182, s_windowHeight = 113;
 595.510 +
 595.511 +
 595.512 +LRESULT CALLBACK ArchiveFileChooser(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 595.513 +{
 595.514 +	RECT r, r2;
 595.515 +	int dx1, dy1, dx2, dy2;
 595.516 +	static std::map<int,int> s_listToItemsMap;
 595.517 +
 595.518 +	switch(uMsg)
 595.519 +	{
 595.520 +		case WM_INITDIALOG:
 595.521 +		{
 595.522 +			//Clear_Sound_Buffer();
 595.523 +			
 595.524 +			//if(Full_Screen)
 595.525 +			//{
 595.526 +			//	while (ShowCursor(false) >= 0);
 595.527 +			//	while (ShowCursor(true) < 0);
 595.528 +			//}
 595.529 +
 595.530 +			for(int i = 0; i < numControlLayoutInfos; i++)
 595.531 +				s_layoutState[i].valid = false;
 595.532 +
 595.533 +			GetWindowRect(AfxGetApp()->m_pMainWnd->GetSafeHwnd(), &r);
 595.534 +			dx1 = (r.right - r.left) / 2;
 595.535 +			dy1 = (r.bottom - r.top) / 2;
 595.536 +
 595.537 +			GetWindowRect(hDlg, &r2);
 595.538 +			dx2 = (r2.right - r2.left) / 2;
 595.539 +			dy2 = (r2.bottom - r2.top) / 2;
 595.540 +
 595.541 +			//SetWindowPos(hDlg, NULL, max(0, r.left + (dx1 - dx2)), max(0, r.top + (dy1 - dy2)), NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
 595.542 +			SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
 595.543 +
 595.544 +			ArchiveFileChooserInfo& info = *(ArchiveFileChooserInfo*)lParam;
 595.545 +			std::vector<ArchiveFileChooserInfo::FileInfo>& files = info.files;
 595.546 +			ArchiveFile& archive = info.archive;
 595.547 +
 595.548 +			std::string title = "Choose File in ";
 595.549 +			title += archive.GetArchiveTypeName();
 595.550 +			title += " Archive";
 595.551 +			SetWindowText(hDlg, title.c_str());
 595.552 +
 595.553 +			// populate list
 595.554 +			for(size_t i = 0; i < files.size(); i++)
 595.555 +			{
 595.556 +				int listIndex = SendDlgItemMessage(hDlg, IDC_LIST1, LB_ADDSTRING, (WPARAM) 0, (LONG) (LPTSTR) files[i].name.c_str());
 595.557 +				s_listToItemsMap[listIndex] = files[i].itemIndex;
 595.558 +			}
 595.559 +
 595.560 +			SendDlgItemMessage(hDlg, IDC_LIST1, LB_SETCURSEL, (WPARAM) 0, (LPARAM) 0);
 595.561 +
 595.562 +			{
 595.563 +				RECT r3;
 595.564 +				GetClientRect(hDlg, &r3);
 595.565 +				s_windowWidth = r3.right - r3.left;
 595.566 +				s_windowHeight = r3.bottom - r3.top;
 595.567 +			}
 595.568 +
 595.569 +			return true;
 595.570 +		}	break;
 595.571 +
 595.572 +		case WM_SIZING:
 595.573 +		{
 595.574 +			// enforce a minimum window size
 595.575 +
 595.576 +			LPRECT r = (LPRECT) lParam;
 595.577 +			int minimumWidth = 281;
 595.578 +			int minimumHeight = 117;
 595.579 +			if(r->right - r->left < minimumWidth)
 595.580 +				if(wParam == WMSZ_LEFT || wParam == WMSZ_TOPLEFT || wParam == WMSZ_BOTTOMLEFT)
 595.581 +					r->left = r->right - minimumWidth;
 595.582 +				else
 595.583 +					r->right = r->left + minimumWidth;
 595.584 +			if(r->bottom - r->top < minimumHeight)
 595.585 +				if(wParam == WMSZ_TOP || wParam == WMSZ_TOPLEFT || wParam == WMSZ_TOPRIGHT)
 595.586 +					r->top = r->bottom - minimumHeight;
 595.587 +				else
 595.588 +					r->bottom = r->top + minimumHeight;
 595.589 +			return TRUE;
 595.590 +		}
 595.591 +
 595.592 +		case WM_SIZE:
 595.593 +		{
 595.594 +			// resize or move controls in the window as necessary when the window is resized
 595.595 +
 595.596 +			int prevDlgWidth = s_windowWidth;
 595.597 +			int prevDlgHeight = s_windowHeight;
 595.598 +
 595.599 +			int dlgWidth = LOWORD(lParam);
 595.600 +			int dlgHeight = HIWORD(lParam);
 595.601 +
 595.602 +			int deltaWidth = dlgWidth - prevDlgWidth;
 595.603 +			int deltaHeight = dlgHeight - prevDlgHeight;
 595.604 +
 595.605 +			for(int i = 0; i < numControlLayoutInfos; i++)
 595.606 +			{
 595.607 +				ControlLayoutInfo layoutInfo = controlLayoutInfos[i];
 595.608 +				ControlLayoutState& layoutState = s_layoutState[i];
 595.609 +
 595.610 +				HWND hCtrl = GetDlgItem(hDlg,layoutInfo.controlID);
 595.611 +
 595.612 +				int x,y,width,height;
 595.613 +				if(layoutState.valid)
 595.614 +				{
 595.615 +					x = layoutState.x;
 595.616 +					y = layoutState.y;
 595.617 +					width = layoutState.width;
 595.618 +					height = layoutState.height;
 595.619 +				}
 595.620 +				else
 595.621 +				{
 595.622 +					RECT r;
 595.623 +					GetWindowRect(hCtrl, &r);
 595.624 +					POINT p = {r.left, r.top};
 595.625 +					ScreenToClient(hDlg, &p);
 595.626 +					x = p.x;
 595.627 +					y = p.y;
 595.628 +					width = r.right - r.left;
 595.629 +					height = r.bottom - r.top;
 595.630 +				}
 595.631 +
 595.632 +				switch(layoutInfo.horizontalLayout)
 595.633 +				{
 595.634 +					case ControlLayoutInfo::RESIZE_END: width += deltaWidth; break;
 595.635 +					case ControlLayoutInfo::MOVE_START: x += deltaWidth; break;
 595.636 +					default: break;
 595.637 +				}
 595.638 +				switch(layoutInfo.verticalLayout)
 595.639 +				{
 595.640 +					case ControlLayoutInfo::RESIZE_END: height += deltaHeight; break;
 595.641 +					case ControlLayoutInfo::MOVE_START: y += deltaHeight; break;
 595.642 +					default: break;
 595.643 +				}
 595.644 +
 595.645 +				SetWindowPos(hCtrl, 0, x,y, width,height, 0);
 595.646 +
 595.647 +				layoutState.x = x;
 595.648 +				layoutState.y = y;
 595.649 +				layoutState.width = width;
 595.650 +				layoutState.height = height;
 595.651 +				layoutState.valid = true;
 595.652 +			}
 595.653 +
 595.654 +			s_windowWidth = dlgWidth;
 595.655 +			s_windowHeight = dlgHeight;
 595.656 +
 595.657 +			RedrawWindow(hDlg, NULL, NULL, RDW_INVALIDATE);
 595.658 +		}
 595.659 +		break;
 595.660 +
 595.661 +		case WM_COMMAND:
 595.662 +			switch(LOWORD(wParam))
 595.663 +			{
 595.664 +				case IDC_LIST1:
 595.665 +					if(HIWORD(wParam) == LBN_DBLCLK)
 595.666 +					{
 595.667 +						POINT pos;
 595.668 +						GetCursorPos(&pos);
 595.669 +						int clickedItem = LBItemFromPt(GetDlgItem(hDlg, IDC_LIST1), pos, FALSE);
 595.670 +						if(clickedItem != -1)
 595.671 +						{
 595.672 +							SendMessage(hDlg, WM_COMMAND, IDOK, 0);
 595.673 +						}
 595.674 +					}
 595.675 +					return TRUE;
 595.676 +
 595.677 +				case IDOK:
 595.678 +				{	
 595.679 +					int listIndex = SendDlgItemMessage(hDlg, IDC_LIST1, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
 595.680 +					s_archiveFileChooserResult = s_listToItemsMap[listIndex];
 595.681 +					s_listToItemsMap.clear();
 595.682 +					//if(Full_Screen)
 595.683 +					//{
 595.684 +					//	while (ShowCursor(true) < 0);
 595.685 +					//	while (ShowCursor(false) >= 0);
 595.686 +					//}
 595.687 +					EndDialog(hDlg, false);
 595.688 +				}	return TRUE;
 595.689 +
 595.690 +				case ID_CANCEL:
 595.691 +				case IDCANCEL:
 595.692 +					s_archiveFileChooserResult = -1;
 595.693 +					s_listToItemsMap.clear();
 595.694 +					//if(Full_Screen)
 595.695 +					//{
 595.696 +					//	while (ShowCursor(true) < 0);
 595.697 +					//	while (ShowCursor(false) >= 0);
 595.698 +					//}
 595.699 +					EndDialog(hDlg, false);
 595.700 +					return TRUE;
 595.701 +			}
 595.702 +
 595.703 +		case WM_CLOSE:
 595.704 +			s_archiveFileChooserResult = -1;
 595.705 +			s_listToItemsMap.clear();
 595.706 +			//if(Full_Screen)
 595.707 +			//{
 595.708 +			//	while (ShowCursor(true) < 0);
 595.709 +			//	while (ShowCursor(false) >= 0);
 595.710 +			//}
 595.711 +			EndDialog(hDlg, false);
 595.712 +			return TRUE;
 595.713 +	}
 595.714 +
 595.715 +	return false;
 595.716 +}
   596.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   596.2 +++ b/src/win32/7zip/OpenArchive.h	Sat Mar 03 10:31:27 2012 -0600
   596.3 @@ -0,0 +1,43 @@
   596.4 +// for retrieving files from archives and/or managing temporary files
   596.5 +
   596.6 +#ifndef OPENARCHIVE_HEADER
   596.7 +#define OPENARCHIVE_HEADER
   596.8 +
   596.9 +#include "7zip.h"
  596.10 +
  596.11 +// ObtainFile()
  596.12 +// this is the main, high-level function for opening possibly-compressed files.
  596.13 +// you don't need to check whether the file is compressed beforehand,
  596.14 +// this function will figure that out and work correctly either way.
  596.15 +// it also does the work of bringing up a within-archive file selector dialog if necessary,
  596.16 +// which even allows navigating to a file within an archive that's within the archive.
  596.17 +// the output PhysicalName is the filename of an uncompressed file
  596.18 +// for you to load with fopen or whatever,
  596.19 +// unless the function fails (or is cancelled) in which case it will return false.
  596.20 +// example input Name:          "C:\games.zip"
  596.21 +// example output LogicalName:  "C:\games.zip|Metroid.gba"
  596.22 +// example output PhysicalName: "C:\Documents and Settings\User\Local Settings\Temp\VBA\rom7A37.gba"
  596.23 +// assumes the three name arguments are distinct character buffers with exactly 2048 bytes each
  596.24 +bool ObtainFile(const char* Name, char *const & LogicalName, char *const & PhysicalName, const char* category=NULL, const char** ignoreExtensions=NULL, int numIgnoreExtensions=0);
  596.25 +
  596.26 +// ReleaseTempFileCategory()
  596.27 +// this is for deleting the temporary files that ObtainFile() can create.
  596.28 +// using it is optional because they will auto-delete on proper shutdown of the program,
  596.29 +// but it's nice to be able to clean up the files as early as possible.
  596.30 +// pass in the same "category" string you passed into ObtainFile(),
  596.31 +// and this will delete all files of that category.
  596.32 +// you can optionally specify one filename to not delete even if its category matches.
  596.33 +// note that any still-open files cannot be deleted yet and will be skipped.
  596.34 +void ReleaseTempFileCategory(const char* category, const char* exceptionFilename=NULL);
  596.35 +
  596.36 +// sets the parent window of subsequent archive selector dialogs
  596.37 +// NULL resets this to the default (main VBA emulator window)
  596.38 +void SetArchiveParentHWND(void* hwnd=NULL);
  596.39 +
  596.40 +// the rest of these are more internal utility functions,
  596.41 +// but they could be generally useful outside of that
  596.42 +const char* GetTempFile(const char* category=NULL, const char* extension=NULL); // creates a temp file and returns a path to it.  extension if any should include the '.'
  596.43 +void ReleaseTempFile(const char* filename); // deletes a particular temporary file, by filename
  596.44 +int ChooseItemFromArchive(ArchiveFile& archive, bool autoChooseIfOnly1=true, const char** ignoreExtensions=0, int numIgnoreExtensions=0); // gets an index to a file within an already-open archive, using the file chooser if there's more than one choice
  596.45 +
  596.46 +#endif
   597.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   597.2 +++ b/src/win32/AVIWrite.cpp	Sat Mar 03 10:31:27 2012 -0600
   597.3 @@ -0,0 +1,281 @@
   597.4 +#include "stdafx.h"
   597.5 +#include <cstdio>
   597.6 +#include <cassert>
   597.7 +
   597.8 +#include "AVIWrite.h"
   597.9 +#include "../common/System.h"
  597.10 +
  597.11 +AVIWrite::AVIWrite()
  597.12 +{
  597.13 +	m_failed = false;
  597.14 +	m_file   = NULL;
  597.15 +	m_stream = NULL;
  597.16 +	m_streamCompressed = NULL;
  597.17 +	m_streamSound      = NULL;
  597.18 +	m_videoFrames      = 0;
  597.19 +	m_samplesSound     = 0;
  597.20 +	m_videoFramesTotal = 0;
  597.21 +	m_samplesSoundTotal= 0;
  597.22 +	m_totalBytes       = 0;
  597.23 +	m_segmentNumber    = 0;
  597.24 +	m_usePrevOptions   = false;
  597.25 +	m_pauseRecording   = false;
  597.26 +
  597.27 +	AVIFileInit();
  597.28 +}
  597.29 +
  597.30 +void AVIWrite::CleanUp()
  597.31 +{
  597.32 +	if (m_streamSound)
  597.33 +	{
  597.34 +		AVIStreamClose(m_streamSound);
  597.35 +		m_streamSound = NULL;
  597.36 +	}
  597.37 +	if (m_streamCompressed)
  597.38 +	{
  597.39 +		AVIStreamClose(m_streamCompressed);
  597.40 +		m_streamCompressed = NULL;
  597.41 +	}
  597.42 +	if (m_stream)
  597.43 +	{
  597.44 +		AVIStreamClose(m_stream);
  597.45 +		m_stream = NULL;
  597.46 +	}
  597.47 +	if (m_file)
  597.48 +	{
  597.49 +		AVIFileClose(m_file);
  597.50 +		m_file = NULL;
  597.51 +	}
  597.52 +}
  597.53 +
  597.54 +AVIWrite::~AVIWrite()
  597.55 +{
  597.56 +	CleanUp();
  597.57 +	AVIFileExit();
  597.58 +}
  597.59 +
  597.60 +void AVIWrite::SetVideoFormat(BITMAPINFOHEADER *bh)
  597.61 +{
  597.62 +	// force size to 0x28 to avoid extra fields
  597.63 +	memcpy(&m_bitmap, bh, 0x28);
  597.64 +}
  597.65 +
  597.66 +void AVIWrite::SetSoundFormat(WAVEFORMATEX *format)
  597.67 +{
  597.68 +	memcpy(&m_soundFormat, format, sizeof(WAVEFORMATEX));
  597.69 +	ZeroMemory(&m_soundHeader, sizeof(AVISTREAMINFO));
  597.70 +	// setup the sound stream header
  597.71 +	m_soundHeader.fccType         = streamtypeAUDIO;
  597.72 +	m_soundHeader.dwQuality       = (DWORD)-1;
  597.73 +	m_soundHeader.dwScale         = format->nBlockAlign;
  597.74 +	m_soundHeader.dwInitialFrames = 1;
  597.75 +	m_soundHeader.dwRate       = format->nAvgBytesPerSec;
  597.76 +	m_soundHeader.dwSampleSize = format->nBlockAlign;
  597.77 +
  597.78 +	// create the sound stream
  597.79 +	if (FAILED(AVIFileCreateStream(m_file, &m_streamSound, &m_soundHeader)))
  597.80 +	{
  597.81 +		m_failed = true;
  597.82 +		return;
  597.83 +	}
  597.84 +
  597.85 +	// setup the sound stream format
  597.86 +	if (FAILED(AVIStreamSetFormat(m_streamSound, 0, (void *)&m_soundFormat,
  597.87 +	                              sizeof(WAVEFORMATEX))))
  597.88 +	{
  597.89 +		m_failed = true;
  597.90 +		return;
  597.91 +	}
  597.92 +}
  597.93 +
  597.94 +bool AVIWrite::Open(const char *filename)
  597.95 +{
  597.96 +	// this is only here because AVIFileOpen doesn't seem to do it for us
  597.97 +	FILE*fd = fopen(filename, "wb");
  597.98 +	if (!fd)
  597.99 +	{
 597.100 +		systemMessage(0, "AVI recording failed: file is read-only or already in use.");
 597.101 +		m_failed = true;
 597.102 +		return false;
 597.103 +	}
 597.104 +	fclose(fd);
 597.105 +
 597.106 +	// create the AVI file
 597.107 +	if (FAILED(AVIFileOpen(&m_file,
 597.108 +	                       filename,
 597.109 +	                       OF_WRITE | OF_CREATE,
 597.110 +	                       NULL)))
 597.111 +	{
 597.112 +		m_failed = true;
 597.113 +		return false;
 597.114 +	}
 597.115 +	// setup the video stream information
 597.116 +	ZeroMemory(&m_header, sizeof(AVISTREAMINFO));
 597.117 +	m_header.fccType = streamtypeVIDEO;
 597.118 +	m_header.dwScale = 1;
 597.119 +	m_header.dwRate  = m_fps;
 597.120 +	m_header.dwSuggestedBufferSize = m_bitmap.biSizeImage;
 597.121 +
 597.122 +	// create the video stream
 597.123 +	if (FAILED(AVIFileCreateStream(m_file,
 597.124 +	                               &m_stream,
 597.125 +	                               &m_header)))
 597.126 +	{
 597.127 +		m_failed = true;
 597.128 +		return false;
 597.129 +	}
 597.130 +
 597.131 +	if (!m_usePrevOptions)
 597.132 +	{
 597.133 +		ZeroMemory(&m_options, sizeof(AVICOMPRESSOPTIONS));
 597.134 +		m_arrayOptions[0] = &m_options;
 597.135 +
 597.136 +		// call the dialog to setup the compress options to be used
 597.137 +		if (!AVISaveOptions(AfxGetApp()->m_pMainWnd->GetSafeHwnd(), 0, 1, &m_stream, m_arrayOptions))
 597.138 +		{
 597.139 +			m_failed = true;
 597.140 +			return false;
 597.141 +		}
 597.142 +	}
 597.143 +
 597.144 +	// create the compressed stream
 597.145 +	if (FAILED(AVIMakeCompressedStream(&m_streamCompressed, m_stream, &m_options, NULL)))
 597.146 +	{
 597.147 +		m_failed = true;
 597.148 +		return false;
 597.149 +	}
 597.150 +
 597.151 +	// setup the video stream format
 597.152 +	if (FAILED(AVIStreamSetFormat(m_streamCompressed, 0,
 597.153 +	                              &m_bitmap,
 597.154 +	                              m_bitmap.biSize +
 597.155 +	                              m_bitmap.biClrUsed * sizeof(RGBQUAD))))
 597.156 +	{
 597.157 +		m_failed = true;
 597.158 +		return false;
 597.159 +	}
 597.160 +
 597.161 +	m_videoFrames  = 0;
 597.162 +	m_samplesSound = 0;
 597.163 +	m_totalBytes   = 0;
 597.164 +	if (!m_usePrevOptions) {
 597.165 +		m_videoFramesTotal  = 0;
 597.166 +		m_samplesSoundTotal = 0;
 597.167 +	}
 597.168 +
 597.169 +	strncpy(m_aviFileName, filename, MAX_PATH);
 597.170 +	strncpy(m_aviBaseName, filename, MAX_PATH);
 597.171 +	m_aviFileName[MAX_PATH - 1] = '\0';
 597.172 +	m_aviBaseName[MAX_PATH - 1] = '\0';
 597.173 +	char *dot = strrchr(m_aviBaseName, '.');
 597.174 +	if (dot && dot > strrchr(m_aviBaseName, '/') && dot > strrchr(m_aviBaseName, '\\'))
 597.175 +	{
 597.176 +		strcpy(m_aviExtension, dot);
 597.177 +		dot[0] = '\0';
 597.178 +	}
 597.179 +
 597.180 +	return true;
 597.181 +}
 597.182 +
 597.183 +bool AVIWrite::AddSound(const u8 *sound, int len)
 597.184 +{
 597.185 +	LONG byteBuffer;
 597.186 +
 597.187 +	// return if we failed somewhere already
 597.188 +	if (m_failed)
 597.189 +		return false;
 597.190 +
 597.191 +	assert(len % m_soundFormat.nBlockAlign == 0);
 597.192 +	int samples = len / m_soundFormat.nBlockAlign;
 597.193 +
 597.194 +	if (FAILED(AVIStreamWrite(m_streamSound,
 597.195 +	                          m_samplesSound,
 597.196 +	                          samples,
 597.197 +	                          (LPVOID)sound,
 597.198 +	                          len,
 597.199 +	                          0,
 597.200 +	                          NULL,
 597.201 +	                          &byteBuffer)))
 597.202 +	{
 597.203 +		m_failed = true;
 597.204 +		return false;
 597.205 +	}
 597.206 +	m_samplesSound += samples;
 597.207 +	m_samplesSoundTotal += samples;
 597.208 +	m_totalBytes   += byteBuffer;
 597.209 +	return true;
 597.210 +}
 597.211 +
 597.212 +bool AVIWrite::NextSegment()
 597.213 +{
 597.214 +	char avi_fname[MAX_PATH];
 597.215 +	strcpy(avi_fname, m_aviBaseName);
 597.216 +	char avi_fname_temp[MAX_PATH];
 597.217 +	sprintf(avi_fname_temp, "%s_part%d%s", avi_fname, m_segmentNumber+2, m_aviExtension);
 597.218 +	m_segmentNumber++;
 597.219 +
 597.220 +	CleanUp();
 597.221 +
 597.222 +	m_usePrevOptions = true;
 597.223 +	bool ret = Open(avi_fname_temp);
 597.224 +	m_usePrevOptions = false;
 597.225 +	strcpy(m_aviBaseName, avi_fname);
 597.226 +
 597.227 +	return ret;
 597.228 +}
 597.229 +
 597.230 +bool AVIWrite::AddFrame(const u8 *bmp)
 597.231 +{
 597.232 +	LONG byteBuffer;
 597.233 +
 597.234 +	if (m_failed)
 597.235 +		return false;
 597.236 +
 597.237 +	// write the frame to the video stream
 597.238 +	if (FAILED(AVIStreamWrite(m_streamCompressed,
 597.239 +	                          m_videoFrames,
 597.240 +	                          1,
 597.241 +	                          (LPVOID)bmp,
 597.242 +	                          m_bitmap.biSizeImage,
 597.243 +	                          AVIIF_KEYFRAME,
 597.244 +	                          NULL,
 597.245 +	                          &byteBuffer)))
 597.246 +	{
 597.247 +		m_failed = true;
 597.248 +		return false;
 597.249 +	}
 597.250 +	m_videoFrames++;
 597.251 +	m_videoFramesTotal++;
 597.252 +	m_totalBytes += byteBuffer;
 597.253 +
 597.254 +	// segment / split AVI when it's almost 2 GB (2000MB, to be precise)
 597.255 +	if (!(m_videoFrames % 60) && m_totalBytes > 2097152000)
 597.256 +		return NextSegment();
 597.257 +	else
 597.258 +		return true;
 597.259 +}
 597.260 +
 597.261 +bool AVIWrite::IsSoundAdded()
 597.262 +{
 597.263 +	return m_streamSound != NULL;
 597.264 +}
 597.265 +
 597.266 +void AVIWrite::SetFPS(int f)
 597.267 +{
 597.268 +	m_fps = f;
 597.269 +}
 597.270 +
 597.271 +int AVIWrite::videoFrames()
 597.272 +{
 597.273 +	return m_videoFramesTotal;
 597.274 +}
 597.275 +
 597.276 +void AVIWrite::Pause(bool pause)
 597.277 +{
 597.278 +	m_pauseRecording = pause;
 597.279 +}
 597.280 +
 597.281 +bool AVIWrite::IsPaused()
 597.282 +{
 597.283 +	return m_pauseRecording;
 597.284 +}
 597.285 \ No newline at end of file
   598.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   598.2 +++ b/src/win32/AVIWrite.h	Sat Mar 03 10:31:27 2012 -0600
   598.3 @@ -0,0 +1,54 @@
   598.4 +#ifndef VBA_WIN32_AVIWRITE_H
   598.5 +#define VBA_WIN32_AVIWRITE_H
   598.6 +
   598.7 +#if _MSC_VER > 1000
   598.8 +#pragma once
   598.9 +#endif // _MSC_VER > 1000
  598.10 +
  598.11 +#include <vfw.h>
  598.12 +
  598.13 +class AVIWrite {
  598.14 + public:
  598.15 +  AVIWrite();
  598.16 +  virtual ~AVIWrite();
  598.17 +
  598.18 +  bool Open(const char *filename);
  598.19 +  virtual bool AddFrame(const u8 *bmp);
  598.20 +  void SetFPS(int fps);
  598.21 +  void SetVideoFormat(BITMAPINFOHEADER *);
  598.22 +  bool IsSoundAdded();
  598.23 +  void SetSoundFormat(WAVEFORMATEX *);
  598.24 +  bool AddSound(const u8 *sound, int len);
  598.25 +  int videoFrames();
  598.26 +  void Pause(bool pause);
  598.27 +  bool IsPaused();
  598.28 +
  598.29 + private:
  598.30 +  int m_fps;
  598.31 +  WAVEFORMATEX m_soundFormat;
  598.32 +  BITMAPINFOHEADER m_bitmap;
  598.33 +  AVISTREAMINFO m_header;
  598.34 +  AVISTREAMINFO m_soundHeader;
  598.35 +  PAVIFILE m_file;
  598.36 +  PAVISTREAM m_stream;
  598.37 +  PAVISTREAM m_streamCompressed;
  598.38 +  PAVISTREAM m_streamSound;
  598.39 +  AVICOMPRESSOPTIONS m_options;
  598.40 +  AVICOMPRESSOPTIONS *m_arrayOptions[1];
  598.41 +  int m_videoFrames;
  598.42 +  int m_samplesSound;
  598.43 +  int m_videoFramesTotal;
  598.44 +  int m_samplesSoundTotal;
  598.45 +  LONG m_totalBytes;
  598.46 +  bool m_failed;
  598.47 +  int m_segmentNumber;
  598.48 +  bool m_usePrevOptions;
  598.49 +  bool m_pauseRecording;
  598.50 +  char m_aviFileName[MAX_PATH];
  598.51 +  char m_aviBaseName[MAX_PATH];
  598.52 +  char m_aviExtension[MAX_PATH];
  598.53 +  void CleanUp();
  598.54 +  bool NextSegment();
  598.55 +};
  598.56 +
  598.57 +#endif // VBA_WIN32_AVIWRITE_H
   599.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   599.2 +++ b/src/win32/AboutDialog.cpp	Sat Mar 03 10:31:27 2012 -0600
   599.3 @@ -0,0 +1,60 @@
   599.4 +// AboutDialog.cpp : implementation file
   599.5 +//
   599.6 +
   599.7 +#include "stdafx.h"
   599.8 +#include "resource.h"
   599.9 +#include "AboutDialog.h"
  599.10 +
  599.11 +#include "../version.h"
  599.12 +
  599.13 +/////////////////////////////////////////////////////////////////////////////
  599.14 +// AboutDialog dialog
  599.15 +
  599.16 +AboutDialog::AboutDialog(CWnd*pParent /*=NULL*/)
  599.17 +	: CDialog(AboutDialog::IDD, pParent)
  599.18 +{
  599.19 +	//{{AFX_DATA_INIT(AboutDialog)
  599.20 +	m_version = _T(VBA_VERSION_STRING);
  599.21 +	//}}AFX_DATA_INIT
  599.22 +}
  599.23 +
  599.24 +void AboutDialog::DoDataExchange(CDataExchange*pDX)
  599.25 +{
  599.26 +	CDialog::DoDataExchange(pDX);
  599.27 +	//{{AFX_DATA_MAP(AboutDialog)
  599.28 +	DDX_Text(pDX, IDC_VERSION, m_version);
  599.29 +	DDX_Control(pDX, IDC_URL, m_link);
  599.30 +	//}}AFX_DATA_MAP
  599.31 +}
  599.32 +
  599.33 +BEGIN_MESSAGE_MAP(AboutDialog, CDialog)
  599.34 +//{{AFX_MSG_MAP(AboutDialog)
  599.35 +//}}AFX_MSG_MAP
  599.36 +END_MESSAGE_MAP()
  599.37 +
  599.38 +/////////////////////////////////////////////////////////////////////////////
  599.39 +// AboutDialog message handlers
  599.40 +
  599.41 +BOOL AboutDialog::OnInitDialog()
  599.42 +{
  599.43 +	CDialog::OnInitDialog();
  599.44 +
  599.45 +	CWnd *p = GetDlgItem(IDC_TRANSLATOR_URL);
  599.46 +	if (p)
  599.47 +	{
  599.48 +		m_translator.SubclassDlgItem(IDC_TRANSLATOR_URL, this);
  599.49 +	}
  599.50 +
  599.51 +	m_link.SetWindowText(VBA_RR_SITE);
  599.52 +
  599.53 +	return TRUE; // return TRUE unless you set the focus to a control
  599.54 +	// EXCEPTION: OCX Property Pages should return FALSE
  599.55 +}
  599.56 +
  599.57 +void AboutDialog::OnOK()
  599.58 +{
  599.59 +	// TODO: Add extra validation here
  599.60 +
  599.61 +	CDialog::OnOK();
  599.62 +}
  599.63 +
   600.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   600.2 +++ b/src/win32/AboutDialog.h	Sat Mar 03 10:31:27 2012 -0600
   600.3 @@ -0,0 +1,52 @@
   600.4 +#if !defined(AFX_ABOUTDIALOG_H__48D787B2_0699_4F03_827D_404EC70DDDB2__INCLUDED_)
   600.5 +#define AFX_ABOUTDIALOG_H__48D787B2_0699_4F03_827D_404EC70DDDB2__INCLUDED_
   600.6 +
   600.7 +#if _MSC_VER > 1000
   600.8 +#pragma once
   600.9 +#endif // _MSC_VER > 1000
  600.10 +
  600.11 +// -*- C++ -*-
  600.12 +// AboutDialog.h : header file
  600.13 +//
  600.14 +
  600.15 +#include "Hyperlink.h"
  600.16 +
  600.17 +/////////////////////////////////////////////////////////////////////////////
  600.18 +// AboutDialog dialog
  600.19 +
  600.20 +class AboutDialog : public CDialog
  600.21 +{
  600.22 +	Hyperlink m_link;
  600.23 +	Hyperlink m_translator;
  600.24 +	// Construction
  600.25 +public:
  600.26 +	AboutDialog(CWnd*pParent = NULL);  // standard constructor
  600.27 +
  600.28 +	// Dialog Data
  600.29 +	//{{AFX_DATA(AboutDialog)
  600.30 +	enum { IDD = IDD_ABOUT };
  600.31 +	CString m_version;
  600.32 +	//}}AFX_DATA
  600.33 +
  600.34 +	// Overrides
  600.35 +	// ClassWizard generated virtual function overrides
  600.36 +	//{{AFX_VIRTUAL(AboutDialog)
  600.37 +protected:
  600.38 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  600.39 +	//}}AFX_VIRTUAL
  600.40 +
  600.41 +	// Implementation
  600.42 +protected:
  600.43 +	// Generated message map functions
  600.44 +	//{{AFX_MSG(AboutDialog)
  600.45 +	virtual BOOL OnInitDialog();
  600.46 +	virtual void OnOK();
  600.47 +	//}}AFX_MSG
  600.48 +
  600.49 +	DECLARE_MESSAGE_MAP()
  600.50 +};
  600.51 +
  600.52 +//{{AFX_INSERT_LOCATION}}
  600.53 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  600.54 +
  600.55 +#endif // !defined(AFX_ABOUTDIALOG_H__48D787B2_0699_4F03_827D_404EC70DDDB2__INCLUDED_)
   601.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   601.2 +++ b/src/win32/AccelEditor.cpp	Sat Mar 03 10:31:27 2012 -0600
   601.3 @@ -0,0 +1,659 @@
   601.4 +// AccelEditor.cpp : implementation file
   601.5 +//
   601.6 +
   601.7 +#include "stdafx.h"
   601.8 +#include "resource.h"
   601.9 +#include "AccelEditor.h"
  601.10 +#include "CmdAccelOb.h"
  601.11 +#include "VBA.h"
  601.12 +
  601.13 +/////////////////////////////////////////////////////////////////////////////
  601.14 +// AccelEditor dialog
  601.15 +
  601.16 +AccelEditor::AccelEditor(CWnd *pParent, CMenu *pMenu, CAcceleratorManager *pExtMgr)
  601.17 +	: ResizeDlg(AccelEditor::IDD, pParent), m_pMenuSrc(pMenu), m_pExtMgr(pExtMgr)
  601.18 +{
  601.19 +	//{{AFX_DATA_INIT(AccelEditor)
  601.20 +	// NOTE: the ClassWizard will add member initialization here
  601.21 +	//}}AFX_DATA_INIT
  601.22 +}
  601.23 +
  601.24 +BOOL AccelEditor::IsModified() const
  601.25 +{
  601.26 +	return m_modified;
  601.27 +}
  601.28 +
  601.29 +const CAcceleratorManager &AccelEditor::GetResultMangager() const
  601.30 +{
  601.31 +	return m_result;
  601.32 +}
  601.33 +
  601.34 +void AccelEditor::DoDataExchange(CDataExchange *pDX)
  601.35 +{
  601.36 +	CDialog::DoDataExchange(pDX);
  601.37 +	//{{AFX_DATA_MAP(AccelEditor)
  601.38 +	DDX_Control(pDX, IDC_CURRENTS, m_currents);
  601.39 +	DDX_Control(pDX, IDC_ALREADY_AFFECTED, m_alreadyAffected);
  601.40 +	DDX_Control(pDX, IDC_COMMANDS, m_commands);
  601.41 +	DDX_Control(pDX, IDC_EDIT_KEY, m_key);
  601.42 +	DDX_Control(pDX, IDC_ACCELEDIT_AUTOTIMEOUT, m_timeout);
  601.43 +	DDX_Control(pDX, IDC_ACCELEDIT_PROGRESSBAR, m_progress);
  601.44 +	//}}AFX_DATA_MAP
  601.45 +}
  601.46 +
  601.47 +BEGIN_MESSAGE_MAP(AccelEditor, CDialog)
  601.48 +//{{AFX_MSG_MAP(AccelEditor)
  601.49 +ON_BN_CLICKED(ID_OK, &AccelEditor::OnOk)
  601.50 +ON_BN_CLICKED(ID_CANCEL, &AccelEditor::OnCancel)
  601.51 +ON_BN_CLICKED(IDC_ACCELEDIT_APPLY, &AccelEditor::OnApply)
  601.52 +ON_BN_CLICKED(IDC_RESET, &AccelEditor::OnReset)
  601.53 +ON_BN_CLICKED(IDC_ASSIGN, &AccelEditor::OnAssign)
  601.54 +ON_BN_CLICKED(IDC_REMOVE, &AccelEditor::OnRemove)
  601.55 +ON_BN_CLICKED(IDC_ACCELEDIT_REPLACE, &AccelEditor::OnReplace)
  601.56 +ON_CONTROL(EN_CHANGE, IDC_EDIT_KEY, &AccelEditor::OnKeyboardEditChange)
  601.57 +ON_CONTROL(EN_KILLFOCUS, IDC_EDIT_KEY, &AccelEditor::OnKeyboardEditKillfocus)
  601.58 +ON_CONTROL(EN_SETFOCUS, IDC_ACCELEDIT_AUTOTIMEOUT, &AccelEditor::OnTimeoutEditSetfocus)
  601.59 +ON_CONTROL(EN_KILLFOCUS, IDC_ACCELEDIT_AUTOTIMEOUT, &AccelEditor::OnTimeoutEditKillfocus)
  601.60 +ON_NOTIFY(TVN_SELCHANGED, IDC_COMMANDS, &AccelEditor::OnTvnSelchangedCommands)
  601.61 +//ON_NOTIFY(LVN_ITEMCHANGED, IDC_CURRENTS, &AccelEditor::OnListItemChanged)
  601.62 +ON_NOTIFY(NM_DBLCLK, IDC_CURRENTS, &AccelEditor::OnListDblClick)
  601.63 +ON_NOTIFY(NM_CLICK, IDC_CURRENTS, &AccelEditor::OnListClick)
  601.64 +ON_WM_TIMER()
  601.65 +//}}AFX_MSG_MAP
  601.66 +END_MESSAGE_MAP()
  601.67 +
  601.68 +/////////////////////////////////////////////////////////////////////////////
  601.69 +// AccelEditor message handlers
  601.70 +
  601.71 +BOOL AccelEditor::OnInitDialog()
  601.72 +{
  601.73 +	CDialog::OnInitDialog();
  601.74 +
  601.75 +	DIALOG_SIZER_START(sz)
  601.76 +	DIALOG_SIZER_ENTRY(ID_OK, DS_MoveX)
  601.77 +	DIALOG_SIZER_ENTRY(ID_CANCEL, DS_MoveX)
  601.78 +	DIALOG_SIZER_ENTRY(IDC_ACCELEDIT_APPLY, DS_MoveX)
  601.79 +	DIALOG_SIZER_ENTRY(IDC_ASSIGN, DS_MoveX)
  601.80 +	DIALOG_SIZER_ENTRY(IDC_REMOVE, DS_MoveX)
  601.81 +	DIALOG_SIZER_ENTRY(IDC_ACCELEDIT_REPLACE, DS_MoveX)
  601.82 +	DIALOG_SIZER_ENTRY(IDC_COMMANDS, DS_SizeX | DS_SizeY)
  601.83 +	DIALOG_SIZER_ENTRY(IDC_CURRENTS, DS_MoveX | DS_SizeY)
  601.84 +	DIALOG_SIZER_ENTRY(IDC_EDIT_KEY, DS_MoveX | DS_MoveY)
  601.85 +	DIALOG_SIZER_ENTRY(IDC_EDIT_KEY, DS_MoveX | DS_MoveY)
  601.86 +	DIALOG_SIZER_ENTRY(IDC_STATIC2, DS_MoveY)
  601.87 +	DIALOG_SIZER_ENTRY(IDC_STATIC3, DS_MoveX | DS_MoveY)
  601.88 +	DIALOG_SIZER_ENTRY(IDC_STATIC4, DS_MoveX | DS_MoveY)
  601.89 +	DIALOG_SIZER_ENTRY(IDC_STATIC5, DS_MoveX | DS_MoveY)
  601.90 +	DIALOG_SIZER_ENTRY(IDC_ACCELEDIT_AUTOTIMEOUT, DS_SizeX | DS_MoveY)
  601.91 +	DIALOG_SIZER_END()
  601.92 +	SetData(sz,
  601.93 +	        TRUE,
  601.94 +	        HKEY_CURRENT_USER,
  601.95 +	        "Software\\Emulators\\VisualBoyAdvance\\Viewer\\AccelEditor",
  601.96 +	        NULL);
  601.97 +
  601.98 +	if (m_pExtMgr)
  601.99 +		m_result = m_mgr = *m_pExtMgr;
 601.100 +
 601.101 +	m_currents.SetExtendedStyle(LVS_EX_FULLROWSELECT);
 601.102 +	m_currents.InsertColumn(0, "Keys");
 601.103 +	m_currents.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
 601.104 +	InitCommands();
 601.105 +	m_autoMode	   = AUTO_REPLACE;
 601.106 +	m_modified	   = FALSE;
 601.107 +	m_timeoutValue = 1000;
 601.108 +	CString timeoutStr;
 601.109 +	timeoutStr.Format("%d", m_timeoutValue);
 601.110 +	m_timeout.SetWindowText(timeoutStr);
 601.111 +	m_progress.SetPos(0);
 601.112 +
 601.113 +	GetDlgItem(IDC_ACCELEDIT_APPLY)->EnableWindow(FALSE);
 601.114 +	return TRUE; // return TRUE unless you set the focus to a control
 601.115 +	             // EXCEPTION: OCX Property Pages should return FALSE
 601.116 +}
 601.117 +
 601.118 +void AccelEditor::AddCommandsFromTable()
 601.119 +{
 601.120 +	POSITION pos = m_mgr.m_mapAccelString.GetStartPosition();
 601.121 +	while (pos != NULL)
 601.122 +	{
 601.123 +		CString command;
 601.124 +		WORD	wID;
 601.125 +		m_mgr.m_mapAccelString.GetNextAssoc(pos, command, wID);
 601.126 +		int nPos = command.Find('\\');
 601.127 +
 601.128 +		if (nPos == 0)  // skip menu commands
 601.129 +		{
 601.130 +			continue;
 601.131 +		}
 601.132 +
 601.133 +		HTREEITEM newItem = TVI_ROOT;
 601.134 +#if 0
 601.135 +/*
 601.136 +        while (nPos != -1)
 601.137 +        {
 601.138 +            newItem = m_commands.InsertItem(command.Left(nPos), newItem);
 601.139 +            command.Delete(0, nPos + 1);
 601.140 +            nPos = command.Find('\\');
 601.141 +        }
 601.142 + */
 601.143 +#endif
 601.144 +		newItem = m_commands.InsertItem(command, newItem);
 601.145 +		m_commands.SetItemData(newItem, wID);
 601.146 +		m_hItems.AddTail(newItem);
 601.147 +	}
 601.148 +}
 601.149 +
 601.150 +// recursive calls
 601.151 +void AccelEditor::AddCommandsFromMenu(CMenu *pMenu, HTREEITEM hParent)
 601.152 +{
 601.153 +	UINT nIndexMax = pMenu->GetMenuItemCount();
 601.154 +	for (UINT nIndex = 0; nIndex < nIndexMax; ++nIndex)
 601.155 +	{
 601.156 +		UINT nID = pMenu->GetMenuItemID(nIndex);
 601.157 +		if (nID == 0)
 601.158 +			continue;  // menu separator or invalid cmd - ignore it
 601.159 +
 601.160 +		if (nID == (UINT)-1)
 601.161 +		{
 601.162 +			// possibly a submenu
 601.163 +			CMenu *pSubMenu = pMenu->GetSubMenu(nIndex);
 601.164 +			if (pSubMenu != NULL)
 601.165 +			{
 601.166 +				CString tempStr;
 601.167 +				pMenu->GetMenuString(nIndex, tempStr, MF_BYPOSITION);
 601.168 +				tempStr.Remove('&');
 601.169 +				HTREEITEM newItem = m_commands.InsertItem(tempStr, hParent);
 601.170 +				AddCommandsFromMenu(pSubMenu, newItem);
 601.171 +			}
 601.172 +		}
 601.173 +		else
 601.174 +		{
 601.175 +			// normal menu item
 601.176 +			// generate the strings
 601.177 +			CString command;
 601.178 +			pMenu->GetMenuString(nIndex, command, MF_BYPOSITION);
 601.179 +			int nPos = command.ReverseFind('\t');
 601.180 +			if (nPos != -1)
 601.181 +			{
 601.182 +				command.Delete(nPos, command.GetLength() - nPos);
 601.183 +			}
 601.184 +			command.Remove('&');
 601.185 +			HTREEITEM newItem = m_commands.InsertItem(command, hParent);
 601.186 +			m_commands.SetItemData(newItem, nID);
 601.187 +			m_hItems.AddTail(newItem);
 601.188 +		}
 601.189 +	}
 601.190 +}
 601.191 +
 601.192 +void AccelEditor::InitCommands()
 601.193 +{
 601.194 +	m_commands.DeleteAllItems();
 601.195 +	m_hItems.RemoveAll();
 601.196 +	m_alreadyAffected.SetWindowText("");
 601.197 +
 601.198 +	AddCommandsFromMenu(m_pMenuSrc, TVI_ROOT);
 601.199 +	AddCommandsFromTable();
 601.200 +}
 601.201 +
 601.202 +BOOL AccelEditor::PreTranslateMessage(MSG *pMsg)
 601.203 +{
 601.204 +	CWnd *pFocus = GetFocus();
 601.205 +	if (pFocus == &m_currents)
 601.206 +	{
 601.207 +		if (pMsg->message == WM_KEYDOWN)
 601.208 +		{
 601.209 +			switch (pMsg->wParam)
 601.210 +			{
 601.211 +			case VK_ESCAPE:
 601.212 +				m_currents.SetItemState(-1, 0, LVIS_SELECTED);
 601.213 +				CheckListSelections();
 601.214 +				break;
 601.215 +			case VK_RETURN:
 601.216 +			case VK_INSERT:
 601.217 +				// kludge to workaround CKeyboardEdit::PreTranslateMessage()
 601.218 +				break;
 601.219 +			case VK_DELETE:
 601.220 +			case VK_BACK:
 601.221 +				OnRemove();
 601.222 +				break;
 601.223 +			case VK_F6:
 601.224 +			case VK_LEFT:
 601.225 +				m_commands.SetFocus();
 601.226 +				break;
 601.227 +			case VK_RIGHT:
 601.228 +				GetDlgItem(ID_OK)->SetFocus();
 601.229 +			default:
 601.230 +				return ResizeDlg::PreTranslateMessage(pMsg);
 601.231 +			}
 601.232 +			return TRUE;
 601.233 +		}
 601.234 +		else if (pMsg->message == WM_KEYUP)	// kludge to workaround CKeyboardEdit::PreTranslateMessage()
 601.235 +		{
 601.236 +			switch (pMsg->wParam)
 601.237 +			{
 601.238 +			case VK_RETURN:
 601.239 +				OnEdit();
 601.240 +				break;
 601.241 +			case VK_INSERT:
 601.242 +				OnNew();
 601.243 +				break;
 601.244 +			default:
 601.245 +				return ResizeDlg::PreTranslateMessage(pMsg);
 601.246 +			}
 601.247 +			return TRUE;
 601.248 +		}
 601.249 +	}
 601.250 +	else if (pFocus == &m_commands)
 601.251 +	{
 601.252 +		if (pMsg->message == WM_KEYDOWN)
 601.253 +		{
 601.254 +			switch (pMsg->wParam)
 601.255 +			{
 601.256 +			case VK_F6:
 601.257 +				m_currents.SetFocus();
 601.258 +				break;
 601.259 +			case VK_RIGHT:
 601.260 +				if (!m_commands.ItemHasChildren(m_commands.GetSelectedItem()))
 601.261 +				{
 601.262 +					m_currents.SetFocus();
 601.263 +					break;
 601.264 +				}
 601.265 +				// fall through
 601.266 +			default:
 601.267 +				return ResizeDlg::PreTranslateMessage(pMsg);
 601.268 +			}
 601.269 +			return TRUE;
 601.270 +		}
 601.271 +	}
 601.272 +
 601.273 +	return ResizeDlg::PreTranslateMessage(pMsg);
 601.274 +}
 601.275 +
 601.276 +void AccelEditor::OnOk()
 601.277 +{
 601.278 +	OnApply();
 601.279 +//	OnTimeoutEditKillfocus();
 601.280 +	EndDialog(TRUE);
 601.281 +}
 601.282 +
 601.283 +void AccelEditor::OnCancel()
 601.284 +{
 601.285 +//	OnTimeoutEditKillfocus();
 601.286 +//	EndDialog(m_modified);
 601.287 +	EndDialog(FALSE);	// this allows the caller to cancel even if the user has Apply'ed
 601.288 +}
 601.289 +
 601.290 +void AccelEditor::OnApply()
 601.291 +{
 601.292 +	m_result   = m_mgr;
 601.293 +	GetDlgItem(IDC_ACCELEDIT_APPLY)->EnableWindow(FALSE);
 601.294 +}
 601.295 +
 601.296 +void AccelEditor::OnReset()
 601.297 +{
 601.298 +	m_mgr.Default(); /// FIXME accelerator reset NYI
 601.299 +	systemMessage(
 601.300 +	    0,
 601.301 +	    "The \"Reset All Accelerators\" feature is currently unimplemented.\nYou can achieve the same result by closing VBA, opening up your \"vba.ini\" file, deleting the line that starts with \"keyboard\", then reopening VBA.");
 601.302 +	InitCommands(); // update the listboxes.
 601.303 +}
 601.304 +
 601.305 +void AccelEditor::OnAssign()
 601.306 +{
 601.307 +	if (CheckAffected())
 601.308 +		return;
 601.309 +
 601.310 +	// get the currently selected group
 601.311 +	HTREEITEM hItem = m_commands.GetSelectedItem();
 601.312 +	if (hItem == NULL)
 601.313 +		return;  // abort
 601.314 +
 601.315 +	// Get the object who manage the accels list, associated to the command.
 601.316 +	WORD wIDCommand = LOWORD(m_commands.GetItemData(hItem));
 601.317 +
 601.318 +	CCmdAccelOb *pCmdAccel;
 601.319 +	if (m_mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) != TRUE)
 601.320 +		return;
 601.321 +
 601.322 +	WORD wKey;
 601.323 +	bool bCtrl, bAlt, bShift;
 601.324 +	if (!m_key.GetAccelKey(wKey, bCtrl, bAlt, bShift))
 601.325 +		return;  // no valid key, abort
 601.326 +
 601.327 +	BYTE cVirt = 0;
 601.328 +	if (bCtrl)
 601.329 +		cVirt |= FCONTROL;
 601.330 +	if (bAlt)
 601.331 +		cVirt |= FALT;
 601.332 +	if (bShift)
 601.333 +		cVirt |= FSHIFT;
 601.334 +
 601.335 +	cVirt |= FVIRTKEY;
 601.336 +
 601.337 +	// Create the new key...
 601.338 +	CAccelsOb *pAccel = new CAccelsOb(cVirt, wKey, false);
 601.339 +	ASSERT(pAccel != NULL);
 601.340 +	// ...and add in the list.
 601.341 +	pCmdAccel->m_Accels.AddTail(pAccel);
 601.342 +
 601.343 +	// Update the listbox.
 601.344 +	CString szBuffer;
 601.345 +	pAccel->GetString(szBuffer);
 601.346 +
 601.347 +	int index = m_currents.GetNextItem(-1, LVNI_SELECTED);
 601.348 +	if (index < 0)
 601.349 +		index = 0;
 601.350 +	m_currents.InsertItem(index, szBuffer);
 601.351 +	m_currents.SetItemData(index, reinterpret_cast<DWORD>(pAccel));
 601.352 +	m_currents.SetItemState(-1, 0, LVIS_SELECTED);	// deselect other items first
 601.353 +	m_currents.SetItemState(index, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
 601.354 +	GetDlgItem(IDC_REMOVE)->EnableWindow(TRUE);
 601.355 +	GetDlgItem(IDC_ACCELEDIT_REPLACE)->EnableWindow(TRUE);
 601.356 +
 601.357 +	// Reset the key editor.
 601.358 +//	m_key.ResetKey();
 601.359 +
 601.360 +	m_modified = TRUE;
 601.361 +	GetDlgItem(IDC_ACCELEDIT_APPLY)->EnableWindow(TRUE);
 601.362 +}
 601.363 +
 601.364 +void AccelEditor::OnRemove()
 601.365 +{
 601.366 +	// Some controls
 601.367 +	POSITION selected = m_currents.GetFirstSelectedItemPosition();
 601.368 +	if (selected == NULL)
 601.369 +		return;
 601.370 +
 601.371 +	HTREEITEM hItem = m_commands.GetSelectedItem();
 601.372 +	if (hItem == NULL)
 601.373 +		return;
 601.374 +
 601.375 +	// Ref to the ID command
 601.376 +	WORD wIDCommand = LOWORD(m_commands.GetItemData(hItem));
 601.377 +
 601.378 +	// Run through the accels, and control if it can be deleted.
 601.379 +	CCmdAccelOb *pCmdAccel;
 601.380 +	if (m_mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) == TRUE)
 601.381 +	{
 601.382 +		POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
 601.383 +		POSITION PrevPos;
 601.384 +		while (pos != NULL)
 601.385 +		{
 601.386 +			PrevPos = pos;
 601.387 +			CAccelsOb *pAccel = pCmdAccel->m_Accels.GetNext(pos);
 601.388 +			do
 601.389 +			{
 601.390 +				int indexCurrent = m_currents.GetNextSelectedItem(selected);
 601.391 +				CAccelsOb *pAccelCurrent = reinterpret_cast<CAccelsOb *>(m_currents.GetItemData(indexCurrent));
 601.392 +				if (pAccel == pAccelCurrent)
 601.393 +				{
 601.394 +					if (!pAccel->m_bLocked)
 601.395 +					{
 601.396 +						// not locked, so we delete the key
 601.397 +						pCmdAccel->m_Accels.RemoveAt(PrevPos);
 601.398 +						delete pAccel;
 601.399 +						// and update the listboxes/key editor/static text
 601.400 +						m_currents.DeleteItem(indexCurrent);
 601.401 +						m_modified = TRUE;
 601.402 +						break;
 601.403 +					}
 601.404 +					else
 601.405 +					{
 601.406 +						systemMessage(0, "Unable to remove this locked accelerator: ", m_currents.GetItemText(indexCurrent, KEY_COLUMN));
 601.407 +						m_currents.SetItemState(indexCurrent, 0, LVIS_SELECTED); // deselect it
 601.408 +						break;
 601.409 +					}
 601.410 +				}
 601.411 +			}
 601.412 +			while (selected != NULL);
 601.413 +
 601.414 +			selected = m_currents.GetFirstSelectedItemPosition();
 601.415 +			if (selected == NULL)	// the normal exit of this function
 601.416 +			{
 601.417 +				m_currents.SetItemState(m_currents.GetNextItem(-1, LVIS_FOCUSED), LVIS_SELECTED, LVIS_SELECTED);
 601.418 +				if (m_currents.GetSelectedCount() == 0)
 601.419 +				{
 601.420 +					GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
 601.421 +					GetDlgItem(IDC_ACCELEDIT_REPLACE)->EnableWindow(FALSE);
 601.422 +				}
 601.423 +				GetDlgItem(IDC_ACCELEDIT_APPLY)->EnableWindow(m_modified);
 601.424 +				return;
 601.425 +			}
 601.426 +		}
 601.427 +		systemMessage(0, "internal error (AccelEditor::Remove : pAccel unavailable)");
 601.428 +		return;
 601.429 +	}
 601.430 +	systemMessage(0, "internal error (AccelEditor::Remove : Lookup failed)");
 601.431 +}
 601.432 +
 601.433 +void AccelEditor::OnReplace()
 601.434 +{
 601.435 +	if (CheckAffected())
 601.436 +		return;
 601.437 +	OnRemove();
 601.438 +	OnAssign();
 601.439 +}
 601.440 +
 601.441 +void AccelEditor::OnNew()
 601.442 +{
 601.443 +	m_autoMode = AUTO_NEW;
 601.444 +	m_key.SetFocus();
 601.445 +}
 601.446 +
 601.447 +void AccelEditor::OnEdit()
 601.448 +{
 601.449 +	m_autoMode = AUTO_REPLACE;
 601.450 +	m_key.SetFocus();
 601.451 +}
 601.452 +
 601.453 +BOOL AccelEditor::CheckAffected()
 601.454 +{
 601.455 +	m_alreadyAffected.SetWindowText("");
 601.456 +
 601.457 +	WORD wKey;
 601.458 +	bool bCtrl, bAlt, bShift;
 601.459 +	if (!m_key.GetAccelKey(wKey, bCtrl, bAlt, bShift))
 601.460 +		return TRUE;  // no valid key, abort
 601.461 +
 601.462 +	POSITION posItem = m_hItems.GetHeadPosition();
 601.463 +	while (posItem != NULL)
 601.464 +	{
 601.465 +		HTREEITEM hItem		  = m_hItems.GetNext(posItem);
 601.466 +		WORD	  wIDCommand2 = LOWORD(m_commands.GetItemData(hItem));
 601.467 +
 601.468 +		CCmdAccelOb *pCmdAccel;
 601.469 +		m_mgr.m_mapAccelTable.Lookup(wIDCommand2, pCmdAccel);
 601.470 +
 601.471 +		POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
 601.472 +		while (pos != NULL)
 601.473 +		{
 601.474 +			CAccelsOb *pAccel = pCmdAccel->m_Accels.GetNext(pos);
 601.475 +			if (pAccel->IsEqual(wKey, bCtrl, bAlt, bShift))
 601.476 +			{
 601.477 +				// the key is already affected (in the same or other command)
 601.478 +				// (the parts that were commented out allow for a one-to-many mapping,
 601.479 +				//  which is only disabled because the MFC stuff that automagically activates the commands
 601.480 +				//  doesn't seem to be capable of activating more than one command per accelerator...)
 601.481 +				m_alreadyAffected.SetWindowText(pCmdAccel->m_szCommand);
 601.482 +				return TRUE;
 601.483 +			}
 601.484 +		}
 601.485 +	}
 601.486 +
 601.487 +	return FALSE;
 601.488 +}
 601.489 +
 601.490 +BOOL AccelEditor::CheckJammed()
 601.491 +{
 601.492 +	WORD jam;
 601.493 +	if (m_key.GetJamKey(jam))
 601.494 +	{
 601.495 +		// these go first, or the timer would be set again
 601.496 +		m_key.ResetKey();
 601.497 +		m_key.SetWindowText("Interrupted");
 601.498 +		if (m_currents.IsWindowEnabled())
 601.499 +			m_currents.SetFocus();
 601.500 +		else
 601.501 +			m_commands.SetFocus();
 601.502 +		return TRUE;
 601.503 +	}
 601.504 +	return FALSE;
 601.505 +}
 601.506 +
 601.507 +BOOL AccelEditor::CheckListSelections()
 601.508 +{
 601.509 +	BOOL result = m_currents.GetFirstSelectedItemPosition() ? TRUE : FALSE;
 601.510 +
 601.511 +	GetDlgItem(IDC_REMOVE)->EnableWindow(result);
 601.512 +	GetDlgItem(IDC_ACCELEDIT_REPLACE)->EnableWindow(result);
 601.513 +
 601.514 +	return result;
 601.515 +}
 601.516 +
 601.517 +void AccelEditor::OnTvnSelchangedCommands(NMHDR *pNMHDR, LRESULT *pResult)
 601.518 +{
 601.519 +//	LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
 601.520 +
 601.521 +	// TODO: Add your control notification handler code here
 601.522 +	// Check if some commands exist.
 601.523 +	HTREEITEM hItem = m_commands.GetSelectedItem();
 601.524 +	if (hItem == NULL)
 601.525 +		return;
 601.526 +
 601.527 +	m_currents.DeleteAllItems();
 601.528 +
 601.529 +	WORD wIDCommand = LOWORD(m_commands.GetItemData(hItem));
 601.530 +	CCmdAccelOb *pCmdAccel;
 601.531 +	if (m_mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel))
 601.532 +	{
 601.533 +		CAccelsOb *pAccel;
 601.534 +		CString	   szBuffer;
 601.535 +		POSITION   pos = pCmdAccel->m_Accels.GetHeadPosition();
 601.536 +
 601.537 +		// Add the keys to the 'currents keys' listbox.
 601.538 +		while (pos != NULL)
 601.539 +		{
 601.540 +			pAccel = pCmdAccel->m_Accels.GetNext(pos);
 601.541 +			pAccel->GetString(szBuffer);
 601.542 +			int index = m_currents.InsertItem(m_currents.GetItemCount(), szBuffer);
 601.543 +			// and a pointer to the accel object.
 601.544 +			m_currents.SetItemData(index, (DWORD)pAccel);
 601.545 +		}
 601.546 +
 601.547 +		m_currents.SetItemState(0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
 601.548 +		GetDlgItem(IDC_ASSIGN)->EnableWindow(TRUE);
 601.549 +		m_currents.EnableWindow(TRUE);
 601.550 +	}
 601.551 +	else
 601.552 +	{
 601.553 +		GetDlgItem(IDC_ASSIGN)->EnableWindow(FALSE);
 601.554 +		m_currents.EnableWindow(FALSE);
 601.555 +	}
 601.556 +
 601.557 +	// Init the key editor
 601.558 +//  m_pKey->ResetKey();
 601.559 +//	m_alreadyAffected.SetWindowText("");
 601.560 +
 601.561 +	CheckListSelections();
 601.562 +
 601.563 +	*pResult = 0;
 601.564 +}
 601.565 +
 601.566 +/*
 601.567 +void AccelEditor::OnListItemChanged(NMHDR *pNMHDR, LRESULT *pResult)
 601.568 +{
 601.569 +	NMLISTVIEW *pNMListView = reinterpret_cast<NMLISTVIEW *>(pNMHDR);
 601.570 +	if (pNMListView->uChanged == LVIF_STATE)
 601.571 +	{
 601.572 +		if ((pNMListView->uOldState & LVIS_SELECTED) && !(pNMListView->uNewState & LVIS_SELECTED))
 601.573 +		{
 601.574 +		}
 601.575 +	}
 601.576 +
 601.577 +	*pResult = 0;
 601.578 +}
 601.579 +*/
 601.580 +
 601.581 +void AccelEditor::OnListClick(NMHDR *pNMHDR, LRESULT *pResult)
 601.582 +{
 601.583 +	CheckListSelections();
 601.584 +	*pResult = 0;
 601.585 +}
 601.586 +
 601.587 +void AccelEditor::OnListDblClick(NMHDR *pNMHDR, LRESULT *pResult)
 601.588 +{
 601.589 +	if (m_currents.GetFirstSelectedItemPosition())
 601.590 +		OnEdit();
 601.591 +	else
 601.592 +		OnNew();
 601.593 +	*pResult = 0;
 601.594 +}
 601.595 +
 601.596 +void AccelEditor::OnKeyboardEditChange()
 601.597 +{
 601.598 +	if (!m_key.IsDefined())
 601.599 +		return;
 601.600 +
 601.601 +//	if (CheckJammed())
 601.602 +//		return;
 601.603 +
 601.604 +	OnKeyboardEditKillfocus();
 601.605 +	CheckAffected();
 601.606 +	if (m_timeoutValue == 0)
 601.607 +		return;
 601.608 +
 601.609 +	m_progress.SetRange32(0, m_timeoutValue);
 601.610 +	SetTimer(1, 50, NULL);
 601.611 +}
 601.612 +
 601.613 +void AccelEditor::OnKeyboardEditKillfocus()
 601.614 +{
 601.615 +	KillTimer(1);
 601.616 +	m_timer = 0;
 601.617 +	m_progress.SetPos(0);
 601.618 +	m_progress.SetBarColor(RGB(128, 0, 255));
 601.619 +}
 601.620 +
 601.621 +void AccelEditor::OnTimeoutEditSetfocus()
 601.622 +{
 601.623 +	m_timeout.PostMessage(EM_SETSEL, 0, -1);
 601.624 +}
 601.625 +
 601.626 +void AccelEditor::OnTimeoutEditKillfocus()
 601.627 +{
 601.628 +	CString str;
 601.629 +	m_timeout.GetWindowText(str);
 601.630 +	m_timeoutValue = atoi(str);
 601.631 +	m_autoMode	   = AUTO_REPLACE;
 601.632 +}
 601.633 +
 601.634 +void AccelEditor::OnTimer(UINT_PTR nIDEvent)
 601.635 +{
 601.636 +	if (nIDEvent == 1)
 601.637 +	{
 601.638 +		m_timer += 50;
 601.639 +		if (m_timer >= m_timeoutValue)
 601.640 +		{
 601.641 +			m_progress.SetPos(m_timeoutValue);
 601.642 +			m_progress.SetBarColor(RGB(255, 255, 0));
 601.643 +			if (m_autoMode == AUTO_NEW)
 601.644 +			{
 601.645 +				OnAssign();
 601.646 +			}
 601.647 +			else
 601.648 +			{
 601.649 +				OnReplace();
 601.650 +			}
 601.651 +			if (m_currents.IsWindowEnabled())
 601.652 +				m_currents.SetFocus();
 601.653 +			else
 601.654 +				m_commands.SetFocus();
 601.655 +			return;
 601.656 +		}
 601.657 +		UINT green = (m_timer * 255 / m_timeoutValue) ;
 601.658 +		m_progress.SetBarColor(RGB(128 + green / 2, green, 255 - green));
 601.659 +		m_progress.SetPos(m_timer);
 601.660 +	}
 601.661 +}
 601.662 +
   602.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   602.2 +++ b/src/win32/AccelEditor.h	Sat Mar 03 10:31:27 2012 -0600
   602.3 @@ -0,0 +1,93 @@
   602.4 +#if !defined(AFX_ACCELEDITOR_H__66F5C854_E28E_40D1_B763_1850374B46A2__INCLUDED_)
   602.5 +#define AFX_ACCELEDITOR_H__66F5C854_E28E_40D1_B763_1850374B46A2__INCLUDED_
   602.6 +
   602.7 +#if _MSC_VER > 1000
   602.8 +#pragma once
   602.9 +#endif // _MSC_VER > 1000
  602.10 +// AccelEditor.h : header file
  602.11 +//
  602.12 +#include "AcceleratorManager.h"
  602.13 +#include "KeyboardEdit.h"
  602.14 +#include "ResizeDlg.h"
  602.15 +
  602.16 +/////////////////////////////////////////////////////////////////////////////
  602.17 +// AccelEditor dialog
  602.18 +
  602.19 +class AccelEditor : public ResizeDlg
  602.20 +{
  602.21 +	// Construction
  602.22 +public:
  602.23 +	void InitCommands();
  602.24 +	void AddCommandsFromTable();
  602.25 +	void AddCommandsFromMenu(CMenu *pMenu, HTREEITEM hParent);
  602.26 +	BOOL IsModified() const;
  602.27 +	const CAcceleratorManager &GetResultMangager() const;
  602.28 +	AccelEditor(CWnd *pParent, CMenu *pMenu, CAcceleratorManager *pExtMgr = NULL);  // non-standard constructor
  602.29 +	virtual BOOL PreTranslateMessage(MSG *pMsg);
  602.30 +
  602.31 +	// Dialog Data
  602.32 +	//{{AFX_DATA(AccelEditor)
  602.33 +protected:
  602.34 +	enum { IDD = IDD_ACCEL_EDITOR };
  602.35 +	enum { KEY_COLUMN = 0 };
  602.36 +	enum { AUTO_REPLACE = 0, AUTO_NEW };
  602.37 +	CListCtrl		  m_currents;
  602.38 +	CStatic			  m_alreadyAffected;
  602.39 +	CTreeCtrl		  m_commands;
  602.40 +	CKeyboardEdit	  m_key;
  602.41 +	CEdit			  m_timeout;
  602.42 +	CProgressCtrl	  m_progress;
  602.43 +	CList<HTREEITEM>  m_hItems;
  602.44 +
  602.45 +	int m_timeoutValue;
  602.46 +	int m_timer;
  602.47 +	int m_autoMode;
  602.48 +	BOOL m_modified;
  602.49 +	CAcceleratorManager m_mgr, m_result;
  602.50 +	CAcceleratorManager *m_pExtMgr;
  602.51 +	CMenu *m_pMenuSrc;
  602.52 +	//}}AFX_DATA
  602.53 +
  602.54 +	// Overrides
  602.55 +	// ClassWizard generated virtual function overrides
  602.56 +	//{{AFX_VIRTUAL(AccelEditor)
  602.57 +protected:
  602.58 +	virtual void DoDataExchange(CDataExchange *pDX);   // DDX/DDV support
  602.59 +	//}}AFX_VIRTUAL
  602.60 +
  602.61 +	// Implementation
  602.62 +protected:
  602.63 +	BOOL CheckAffected();
  602.64 +	BOOL CheckJammed();
  602.65 +	BOOL CheckListSelections();
  602.66 +
  602.67 +	// Generated message map functions
  602.68 +	//{{AFX_MSG(AccelEditor)
  602.69 +	virtual BOOL OnInitDialog();
  602.70 +	afx_msg void OnOk();
  602.71 +	afx_msg void OnCancel();
  602.72 +	afx_msg void OnApply();
  602.73 +	afx_msg void OnReset();
  602.74 +	afx_msg void OnAssign();
  602.75 +	afx_msg void OnRemove();
  602.76 +	afx_msg void OnReplace();
  602.77 +	afx_msg void OnNew();
  602.78 +	afx_msg void OnEdit();
  602.79 +
  602.80 +	afx_msg void OnTvnSelchangedCommands(NMHDR *pNMHDR, LRESULT *pResult);
  602.81 +//	afx_msg void OnListItemChanged(NMHDR *pNMHDR, LRESULT *pResult);
  602.82 +	afx_msg void OnListClick(NMHDR *pNMHDR, LRESULT *pResult);
  602.83 +	afx_msg void OnListDblClick(NMHDR *pNMHDR, LRESULT *pResult);
  602.84 +	afx_msg void OnKeyboardEditChange();
  602.85 +	afx_msg void OnKeyboardEditKillfocus();
  602.86 +	afx_msg void OnTimeoutEditSetfocus();
  602.87 +	afx_msg void OnTimeoutEditKillfocus();
  602.88 +	afx_msg void OnTimer(UINT_PTR nIDEvent);
  602.89 +	//}}AFX_MSG
  602.90 +	DECLARE_MESSAGE_MAP()
  602.91 +};
  602.92 +
  602.93 +//{{AFX_INSERT_LOCATION}}
  602.94 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  602.95 +
  602.96 +#endif // !defined(AFX_ACCELEDITOR_H__66F5C854_E28E_40D1_B763_1850374B46A2__INCLUDED_)
   603.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   603.2 +++ b/src/win32/AcceleratorManager.cpp	Sat Mar 03 10:31:27 2012 -0600
   603.3 @@ -0,0 +1,729 @@
   603.4 +////////////////////////////////////////////////////////////////////////////////
   603.5 +// Copyright (C) 1998 by Thierry Maurel
   603.6 +// All rights reserved
   603.7 +//
   603.8 +// Distribute freely, except: don't remove my name from the source or
   603.9 +// documentation (don't take credit for my work), mark your changes (don't
  603.10 +// get me blamed for your possible bugs), don't alter or remove this
  603.11 +// notice.
  603.12 +// No warrantee of any kind, express or implied, is included with this
  603.13 +// software; use at your own risk, responsibility for damages (if any) to
  603.14 +// anyone resulting from the use of this software rests entirely with the
  603.15 +// user.
  603.16 +//
  603.17 +// Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  603.18 +// I'll try to keep a version up to date.  I can be reached as follows:
  603.19 +//    tmaurel@caramail.com   (or tmaurel@hol.fr)
  603.20 +//
  603.21 +////////////////////////////////////////////////////////////////////////////////
  603.22 +// File    : AcceleratorManager.cpp
  603.23 +// Project : AccelsEditor
  603.24 +////////////////////////////////////////////////////////////////////////////////
  603.25 +// Version : 1.0                       * Author : T.Maurel
  603.26 +// Date    : 17.08.98
  603.27 +//
  603.28 +// Remarks : implementation of the CAcceleratorManager class.
  603.29 +//
  603.30 +////////////////////////////////////////////////////////////////////////////////
  603.31 +// Modified by aquanull:
  603.32 +// All win32 registry stuff removed
  603.33 +
  603.34 +#include "stdafx.h"
  603.35 +#include <windows.h> // MIIM_STRING
  603.36 +#include "resource.h"
  603.37 +#include "AcceleratorManager.h"
  603.38 +#include "CmdAccelOb.h"
  603.39 +#include "Reg.h"
  603.40 +#include "VBA.h"
  603.41 +//#include "../common/System.h"
  603.42 +
  603.43 +CAcceleratorManager::CAcceleratorManager()
  603.44 +{
  603.45 +	m_bAutoSave     = FALSE;
  603.46 +	m_pWndConnected = NULL;
  603.47 +
  603.48 +	m_bDefaultTable = false;
  603.49 +}
  603.50 +
  603.51 +CAcceleratorManager::~CAcceleratorManager()
  603.52 +{
  603.53 +#if 0
  603.54 +	if (m_bAutoSave)
  603.55 +	{
  603.56 +		bool bRet = Write();
  603.57 +		if (!bRet)
  603.58 +			systemMessage(0, "CAcceleratorManager::~CAcceleratorManager\nError in CAcceleratorManager::Write...");
  603.59 +	}
  603.60 +#endif
  603.61 +	Reset();
  603.62 +}
  603.63 +
  603.64 +CAcceleratorManager & CAcceleratorManager::operator=(const CAcceleratorManager& accelmgr)
  603.65 +{
  603.66 +	Reset();
  603.67 +
  603.68 +	CCmdAccelOb*pCmdAccel;
  603.69 +	CCmdAccelOb*pNewCmdAccel;
  603.70 +	WORD        wKey;
  603.71 +	// Copy the 2 tables : normal accel table...
  603.72 +	POSITION pos = accelmgr.m_mapAccelTable.GetStartPosition();
  603.73 +	while (pos != NULL)
  603.74 +	{
  603.75 +		accelmgr.m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
  603.76 +		pNewCmdAccel = new CCmdAccelOb;
  603.77 +		ASSERT(pNewCmdAccel != NULL);
  603.78 +		*pNewCmdAccel = *pCmdAccel;
  603.79 +		m_mapAccelTable.SetAt(wKey, pNewCmdAccel);
  603.80 +	}
  603.81 +	// ... and saved accel table.
  603.82 +	pos = accelmgr.m_mapAccelTableSaved.GetStartPosition();
  603.83 +	while (pos != NULL)
  603.84 +	{
  603.85 +		accelmgr.m_mapAccelTableSaved.GetNextAssoc(pos, wKey, pCmdAccel);
  603.86 +		pNewCmdAccel = new CCmdAccelOb;
  603.87 +		ASSERT(pNewCmdAccel != NULL);
  603.88 +		*pNewCmdAccel = *pCmdAccel;
  603.89 +		m_mapAccelTableSaved.SetAt(wKey, pNewCmdAccel);
  603.90 +	}
  603.91 +
  603.92 +	// The Strings-ID table
  603.93 +	CString szKey;
  603.94 +	pos = accelmgr.m_mapAccelString.GetStartPosition();
  603.95 +	while (pos != NULL)
  603.96 +	{
  603.97 +		accelmgr.m_mapAccelString.GetNextAssoc(pos, szKey, wKey);
  603.98 +		m_mapAccelString.SetAt(szKey, wKey);
  603.99 +	}
 603.100 +	m_bDefaultTable = accelmgr.m_bDefaultTable;
 603.101 +
 603.102 +	return *this;
 603.103 +}
 603.104 +
 603.105 +//////////////////////////////////////////////////////////////////////
 603.106 +// Internal fcts
 603.107 +//
 603.108 +void CAcceleratorManager::Reset()
 603.109 +{
 603.110 +	CCmdAccelOb*pCmdAccel;
 603.111 +	WORD        wKey;
 603.112 +	POSITION    pos = m_mapAccelTable.GetStartPosition();
 603.113 +	while (pos != NULL)
 603.114 +	{
 603.115 +		m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
 603.116 +		delete pCmdAccel;
 603.117 +	}
 603.118 +	m_mapAccelTable.RemoveAll();
 603.119 +	m_mapAccelString.RemoveAll();
 603.120 +
 603.121 +	pos = m_mapAccelTableSaved.GetStartPosition();
 603.122 +	while (pos != NULL)
 603.123 +	{
 603.124 +		m_mapAccelTableSaved.GetNextAssoc(pos, wKey, pCmdAccel);
 603.125 +		delete pCmdAccel;
 603.126 +	}
 603.127 +	m_mapAccelTableSaved.RemoveAll();
 603.128 +}
 603.129 +
 603.130 +bool CAcceleratorManager::AddAccel(BYTE cVirt, WORD wIDCommand, WORD wKey, LPCTSTR szCommand, bool bLocked)
 603.131 +{
 603.132 +	ASSERT(szCommand != NULL);
 603.133 +
 603.134 +	WORD wIDCmd;
 603.135 +	if (m_mapAccelString.Lookup(szCommand, wIDCmd) == TRUE)
 603.136 +	{
 603.137 +		if (wIDCmd != wIDCommand)
 603.138 +			return false;
 603.139 +	}
 603.140 +
 603.141 +	CCmdAccelOb*pCmdAccel = NULL;
 603.142 +	if (m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) == TRUE)
 603.143 +	{
 603.144 +		if (pCmdAccel->m_szCommand != szCommand)
 603.145 +		{
 603.146 +			return false;
 603.147 +		}
 603.148 +		CAccelsOb*pAccel;
 603.149 +		POSITION  pos = pCmdAccel->m_Accels.GetHeadPosition();
 603.150 +		while (pos != NULL)
 603.151 +		{
 603.152 +			pAccel = pCmdAccel->m_Accels.GetNext(pos);
 603.153 +			if (pAccel->m_cVirt == cVirt &&
 603.154 +			    pAccel->m_wKey == wKey)
 603.155 +				return FALSE;
 603.156 +		}
 603.157 +		// Adding the accelerator
 603.158 +		pCmdAccel->Add(cVirt, wKey, bLocked);
 603.159 +	}
 603.160 +	else
 603.161 +	{
 603.162 +		pCmdAccel = new CCmdAccelOb(cVirt, wIDCommand, wKey, szCommand, bLocked);
 603.163 +		ASSERT(pCmdAccel != NULL);
 603.164 +		m_mapAccelTable.SetAt(wIDCommand, pCmdAccel);
 603.165 +	}
 603.166 +	// 2nd table
 603.167 +	m_mapAccelString.SetAt(szCommand, wIDCommand);
 603.168 +	return true;
 603.169 +}
 603.170 +
 603.171 +//////////////////////////////////////////////////////////////////////
 603.172 +// Debug fcts
 603.173 +//
 603.174 +#ifdef _DEBUG
 603.175 +void CAcceleratorManager::AssertValid() const
 603.176 +{}
 603.177 +
 603.178 +void CAcceleratorManager::Dump(CDumpContext& dc) const
 603.179 +{
 603.180 +	CCmdAccelOb*pCmdAccel;
 603.181 +	WORD        wKey;
 603.182 +	dc << "CAcceleratorManager::Dump :\n";
 603.183 +	dc << "m_mapAccelTable :\n";
 603.184 +	POSITION pos = m_mapAccelTable.GetStartPosition();
 603.185 +	while (pos != NULL)
 603.186 +	{
 603.187 +		m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
 603.188 +		dc << "a CCmdAccelOb at 0x"  << (void *)pCmdAccel << " = {\n";
 603.189 +		dc << pCmdAccel;
 603.190 +		dc << "}\n";
 603.191 +	}
 603.192 +	dc << "\nm_mapAccelTableSaved\n";
 603.193 +	pos = m_mapAccelTableSaved.GetStartPosition();
 603.194 +	while (pos != NULL)
 603.195 +	{
 603.196 +		m_mapAccelTableSaved.GetNextAssoc(pos, wKey, pCmdAccel);
 603.197 +		dc << "a CCmdAccelOb at 0x" << (void *)pCmdAccel << " = {\n";
 603.198 +		dc << pCmdAccel;
 603.199 +		dc << "}\n";
 603.200 +	}
 603.201 +}
 603.202 +
 603.203 +#endif
 603.204 +
 603.205 +void CAcceleratorManager::Connect(CWnd*pWnd, bool bAutoSave)
 603.206 +{
 603.207 +	ASSERT(m_pWndConnected == NULL);
 603.208 +	m_pWndConnected = pWnd;
 603.209 +	m_bAutoSave     = bAutoSave;
 603.210 +}
 603.211 +
 603.212 +//////////////////////////////////////////////////////////////////////
 603.213 +// Update the application's ACCELs table
 603.214 +//
 603.215 +bool CAcceleratorManager::UpdateWndTable()
 603.216 +{
 603.217 +	int iLoop = 0;
 603.218 +	CTypedPtrArray<CPtrArray, LPACCEL> arrayACCEL;
 603.219 +
 603.220 +	CCmdAccelOb*pCmdAccel;
 603.221 +	WORD        wKey;
 603.222 +	LPACCEL     pACCEL;
 603.223 +	CAccelsOb*  pAccelOb;
 603.224 +	POSITION    pos = m_mapAccelTable.GetStartPosition();
 603.225 +	while (pos != NULL)
 603.226 +	{
 603.227 +		m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
 603.228 +		POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
 603.229 +		while (pos != NULL)
 603.230 +		{
 603.231 +			pAccelOb = pCmdAccel->m_Accels.GetNext(pos);
 603.232 +
 603.233 +			pACCEL = new ACCEL;
 603.234 +			ASSERT(pACCEL != NULL);
 603.235 +			pACCEL->fVirt = pAccelOb->m_cVirt;
 603.236 +			pACCEL->key   = pAccelOb->m_wKey;
 603.237 +			pACCEL->cmd   = pCmdAccel->m_wIDCommand;
 603.238 +			arrayACCEL.Add(pACCEL);
 603.239 +		}
 603.240 +	}
 603.241 +
 603.242 +	int     nAccel  = arrayACCEL.GetSize();
 603.243 +	LPACCEL lpAccel = (LPACCEL)LocalAlloc(LPTR, nAccel * sizeof(ACCEL));
 603.244 +	if (!lpAccel)
 603.245 +	{
 603.246 +		for (iLoop = 0; iLoop < nAccel; iLoop++)
 603.247 +			delete arrayACCEL.GetAt(iLoop);
 603.248 +		arrayACCEL.RemoveAll();
 603.249 +
 603.250 +		return false;
 603.251 +	}
 603.252 +
 603.253 +	for (iLoop = 0; iLoop < nAccel; iLoop++)
 603.254 +	{
 603.255 +		pACCEL = arrayACCEL.GetAt(iLoop);
 603.256 +		lpAccel[iLoop].fVirt = pACCEL->fVirt;
 603.257 +		lpAccel[iLoop].key   = pACCEL->key;
 603.258 +		lpAccel[iLoop].cmd   = pACCEL->cmd;
 603.259 +
 603.260 +		delete pACCEL;
 603.261 +	}
 603.262 +	arrayACCEL.RemoveAll();
 603.263 +
 603.264 +	HACCEL hNewTable = CreateAcceleratorTable(lpAccel, nAccel);
 603.265 +	if (!hNewTable)
 603.266 +	{
 603.267 +		::LocalFree(lpAccel);
 603.268 +		return false;
 603.269 +	}
 603.270 +	HACCEL hOldTable = theApp.hAccel;
 603.271 +	if (!::DestroyAcceleratorTable(hOldTable))
 603.272 +	{
 603.273 +		::LocalFree(lpAccel);
 603.274 +		return false;
 603.275 +	}
 603.276 +	theApp.hAccel = hNewTable;
 603.277 +	::LocalFree(lpAccel);
 603.278 +
 603.279 +	UpdateMenu(GetMenu(*AfxGetApp()->m_pMainWnd));
 603.280 +
 603.281 +	return true;
 603.282 +}
 603.283 +
 603.284 +//////////////////////////////////////////////////////////////////////
 603.285 +// Create/Destroy accelerators
 603.286 +//
 603.287 +bool CAcceleratorManager::DeleteAccel(BYTE cVirt, WORD wIDCommand, WORD wKey)
 603.288 +{
 603.289 +	CCmdAccelOb*pCmdAccel = NULL;
 603.290 +	if (m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) == TRUE)
 603.291 +	{
 603.292 +		POSITION  pos = pCmdAccel->m_Accels.GetHeadPosition();
 603.293 +		POSITION  PrevPos;
 603.294 +		CAccelsOb*pAccel = NULL;
 603.295 +		while (pos != NULL)
 603.296 +		{
 603.297 +			PrevPos = pos;
 603.298 +			pAccel  = pCmdAccel->m_Accels.GetNext(pos);
 603.299 +			if (pAccel->m_bLocked == true)
 603.300 +				return false;
 603.301 +
 603.302 +			if (pAccel->m_cVirt == cVirt && pAccel->m_wKey == wKey)
 603.303 +			{
 603.304 +				pCmdAccel->m_Accels.RemoveAt(PrevPos);
 603.305 +				delete pAccel;
 603.306 +				return true;
 603.307 +			}
 603.308 +		}
 603.309 +	}
 603.310 +	return false;
 603.311 +}
 603.312 +
 603.313 +bool CAcceleratorManager::DeleteEntry(WORD wIDCommand)
 603.314 +{
 603.315 +	CCmdAccelOb*pCmdAccel = NULL;
 603.316 +	VERIFY(m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) == TRUE);
 603.317 +
 603.318 +	CAccelsOb*pAccel;
 603.319 +	POSITION  pos = pCmdAccel->m_Accels.GetHeadPosition();
 603.320 +	while (pos != NULL)
 603.321 +	{
 603.322 +		pAccel = pCmdAccel->m_Accels.GetNext(pos);
 603.323 +		if (pAccel->m_bLocked == true)
 603.324 +			return false;
 603.325 +	}
 603.326 +	m_mapAccelString.RemoveKey(pCmdAccel->m_szCommand);
 603.327 +	m_mapAccelTable.RemoveKey(wIDCommand);
 603.328 +	delete pCmdAccel;
 603.329 +
 603.330 +	return true;
 603.331 +}
 603.332 +
 603.333 +bool CAcceleratorManager::DeleteEntry(LPCTSTR szCommand)
 603.334 +{
 603.335 +	ASSERT(szCommand != NULL);
 603.336 +
 603.337 +	WORD wIDCommand;
 603.338 +	if (m_mapAccelString.Lookup(szCommand, wIDCommand) == TRUE)
 603.339 +	{
 603.340 +		return DeleteEntry(wIDCommand);
 603.341 +	}
 603.342 +	return true;
 603.343 +}
 603.344 +
 603.345 +bool CAcceleratorManager::SetAccel(BYTE cVirt, WORD wIDCommand, WORD wKey, LPCTSTR szCommand, bool bLocked)
 603.346 +{
 603.347 +	ASSERT(szCommand != NULL);
 603.348 +
 603.349 +	return AddAccel(cVirt, wIDCommand, wKey, szCommand, bLocked);
 603.350 +}
 603.351 +
 603.352 +bool CAcceleratorManager::AddCommandAccel(WORD wIDCommand, LPCTSTR szCommand, bool bLocked)
 603.353 +{
 603.354 +	ASSERT(szCommand != NULL);
 603.355 +
 603.356 +	ASSERT(m_pWndConnected != NULL);
 603.357 +	HACCEL hOriginalTable = theApp.hAccel;
 603.358 +
 603.359 +	int     nAccel  = ::CopyAcceleratorTable(hOriginalTable, NULL, 0);
 603.360 +	LPACCEL lpAccel = (LPACCEL)LocalAlloc(LPTR, (nAccel) * sizeof(ACCEL));
 603.361 +	if (!lpAccel)
 603.362 +		return false;
 603.363 +	::CopyAcceleratorTable(hOriginalTable, lpAccel, nAccel);
 603.364 +
 603.365 +	bool bRet = false;
 603.366 +	for (int i = 0; i < nAccel; i++)
 603.367 +	{
 603.368 +		if (lpAccel[i].cmd == wIDCommand)
 603.369 +			bRet = AddAccel(lpAccel[i].fVirt, wIDCommand, lpAccel[i].key, szCommand, bLocked);
 603.370 +	}
 603.371 +	::LocalFree(lpAccel);
 603.372 +	return bRet;
 603.373 +}
 603.374 +
 603.375 +bool CAcceleratorManager::CreateEntry(WORD wIDCommand, LPCTSTR szCommand)
 603.376 +{
 603.377 +	ASSERT(szCommand != NULL);
 603.378 +
 603.379 +	WORD wIDDummy;
 603.380 +	if (m_mapAccelString.Lookup(szCommand, wIDDummy) == TRUE)
 603.381 +		return false;
 603.382 +
 603.383 +	CCmdAccelOb*pCmdAccel = new CCmdAccelOb(wIDCommand, szCommand);
 603.384 +	ASSERT(pCmdAccel != NULL);
 603.385 +	m_mapAccelTable.SetAt(wIDCommand, pCmdAccel);
 603.386 +	m_mapAccelString.SetAt(szCommand, wIDCommand);
 603.387 +
 603.388 +	return false;
 603.389 +}
 603.390 +
 603.391 +//////////////////////////////////////////////////////////////////////
 603.392 +// Get a string from the ACCEL definition
 603.393 +//
 603.394 +bool CAcceleratorManager::GetStringFromACCEL(ACCEL*pACCEL, CString& szAccel)
 603.395 +{
 603.396 +	ASSERT(pACCEL != NULL);
 603.397 +
 603.398 +	CAccelsOb accel(pACCEL);
 603.399 +	accel.GetString(szAccel);
 603.400 +
 603.401 +	if (szAccel.IsEmpty())
 603.402 +		return false;
 603.403 +	else
 603.404 +		return true;
 603.405 +}
 603.406 +
 603.407 +bool CAcceleratorManager::GetStringFromACCEL(BYTE cVirt, WORD nCode, CString& szAccel)
 603.408 +{
 603.409 +	CAccelsOb accel(cVirt, nCode);
 603.410 +	accel.GetString(szAccel);
 603.411 +
 603.412 +	if (szAccel.IsEmpty())
 603.413 +		return false;
 603.414 +	else
 603.415 +		return true;
 603.416 +}
 603.417 +
 603.418 +void CAcceleratorManager::UpdateMenu(HMENU menu)
 603.419 +{
 603.420 +	int count = GetMenuItemCount(menu);
 603.421 +
 603.422 +	OSVERSIONINFO info = {0};
 603.423 +	info.dwOSVersionInfoSize = sizeof(info);
 603.424 +	GetVersionEx(&info);
 603.425 +
 603.426 +	if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
 603.427 +	{
 603.428 +		MENUITEMINFO info = {0};
 603.429 +		info.cbSize = sizeof(info) - sizeof(HBITMAP);
 603.430 +		info.fMask  = MIIM_ID | MIIM_SUBMENU;
 603.431 +		for (int i = 0; i < count; i++)
 603.432 +		{
 603.433 +			GetMenuItemInfo(menu, i, TRUE, &info);
 603.434 +
 603.435 +			if (info.hSubMenu != NULL)
 603.436 +			{
 603.437 +				UpdateMenu(info.hSubMenu);
 603.438 +			}
 603.439 +			else
 603.440 +			{
 603.441 +				if (info.wID != (UINT)-1)
 603.442 +				{
 603.443 +					char         ss[128];
 603.444 +					MENUITEMINFO info2 = {0};
 603.445 +					info2.cbSize     = sizeof(info2) - sizeof(HBITMAP);	// FIXME: why?
 603.446 +					info2.fMask      = MIIM_STRING;
 603.447 +					info2.dwTypeData = ss;
 603.448 +					info2.cch        = 128;
 603.449 +					GetMenuItemInfo(menu, i, MF_BYPOSITION, &info2);
 603.450 +
 603.451 +					CString str(ss);
 603.452 +					int     index = str.Find('\t');
 603.453 +					if (index != -1)
 603.454 +						str = str.Left(index);
 603.455 +
 603.456 +					WORD command = info.wID;
 603.457 +
 603.458 +					CCmdAccelOb *o;
 603.459 +					if (m_mapAccelTable.Lookup(command, o))
 603.460 +					{
 603.461 +						if (o->m_Accels.GetCount())
 603.462 +						{
 603.463 +							POSITION   pos   = o->m_Accels.GetHeadPosition();
 603.464 +							CAccelsOb *accel = o->m_Accels.GetNext(pos);
 603.465 +
 603.466 +							CString s;
 603.467 +							accel->GetString(s);
 603.468 +							str += "\t";
 603.469 +							str += s;
 603.470 +						}
 603.471 +					}
 603.472 +					if (str != ss)
 603.473 +						ModifyMenu(menu, i, MF_BYPOSITION | MF_STRING, info.wID, str);
 603.474 +				}
 603.475 +			}
 603.476 +		}
 603.477 +	}
 603.478 +	else
 603.479 +	{
 603.480 +		MENUITEMINFO info = {0};
 603.481 +		info.cbSize = sizeof(info);
 603.482 +		info.fMask  = MIIM_ID | MIIM_SUBMENU;
 603.483 +		for (int i = 0; i < count; i++)
 603.484 +		{
 603.485 +			GetMenuItemInfo(menu, i, TRUE, &info);
 603.486 +
 603.487 +			if (info.hSubMenu != NULL)
 603.488 +			{
 603.489 +				UpdateMenu(info.hSubMenu);
 603.490 +			}
 603.491 +			else
 603.492 +			{
 603.493 +				if (info.wID != (WORD)-1)
 603.494 +				{
 603.495 +					wchar_t ss[128];
 603.496 +					wchar_t str[512];
 603.497 +					MENUITEMINFOW info2 = {0};
 603.498 +					info2.cbSize     = sizeof(info2);
 603.499 +					info2.fMask      = MIIM_STRING;
 603.500 +					info2.dwTypeData = ss;
 603.501 +					info2.cch        = 128;
 603.502 +					GetMenuItemInfoW(menu, i, MF_BYPOSITION, &info2);
 603.503 +
 603.504 +					wcscpy(str, ss);
 603.505 +
 603.506 +					wchar_t *p = wcschr(str, '\t');
 603.507 +					if (p)
 603.508 +						*p = 0;
 603.509 +
 603.510 +					CCmdAccelOb *o;
 603.511 +					WORD         command = info.wID;
 603.512 +					if (m_mapAccelTable.Lookup(command, o))
 603.513 +					{
 603.514 +						if (o->m_Accels.GetCount())
 603.515 +						{
 603.516 +							POSITION pos = o->m_Accels.GetHeadPosition();
 603.517 +
 603.518 +							CAccelsOb *accel = o->m_Accels.GetNext(pos);
 603.519 +
 603.520 +							CString s;
 603.521 +							accel->GetString(s);
 603.522 +
 603.523 +							wchar_t temp[128];
 603.524 +							temp[0] = '\t';
 603.525 +							temp[1] = 0;
 603.526 +							wcscat(str, temp);
 603.527 +							p = temp;
 603.528 +							for (const char *sp = s; *sp; sp++)
 603.529 +								*p++ = *sp;
 603.530 +							*p = 0;
 603.531 +							wcscat(str, temp);
 603.532 +						}
 603.533 +					}
 603.534 +					if (wcscmp(str, ss))
 603.535 +						ModifyMenuW(menu, i, MF_BYPOSITION | MF_STRING, info.wID, str);
 603.536 +				}
 603.537 +			}
 603.538 +		}
 603.539 +	}
 603.540 +}
 603.541 +
 603.542 +//////////////////////////////////////////////////////////////////////
 603.543 +// In/Out to the registry
 603.544 +//
 603.545 +bool CAcceleratorManager::Load()
 603.546 +{
 603.547 +//	ASSERT(szRegKey != NULL);
 603.548 +
 603.549 +//	m_hRegKey  = hRegKey;
 603.550 +//	m_szRegKey = szRegKey;
 603.551 +
 603.552 +	DWORD data[2048/sizeof(DWORD)];
 603.553 +
 603.554 +	DWORD len = sizeof(data);
 603.555 +	if (regQueryBinaryValue("keyboard", (char *)data, len))
 603.556 +	{
 603.557 +		int count = len/sizeof(DWORD);
 603.558 +
 603.559 +		CCmdAccelOb*pCmdAccel;
 603.560 +		CAccelsOb*  pAccel;
 603.561 +		DWORD       dwIDAccelData, dwAccelData;
 603.562 +		BOOL        bExistID;
 603.563 +		int         iIndex = 0;
 603.564 +		if (count)
 603.565 +		{
 603.566 +			WORD     wKey;
 603.567 +			POSITION pos = m_mapAccelTable.GetStartPosition();
 603.568 +
 603.569 +			while (pos != NULL)
 603.570 +			{
 603.571 +				m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
 603.572 +				pCmdAccel->DeleteUserAccels();
 603.573 +			}
 603.574 +
 603.575 +			while (iIndex < count)
 603.576 +			{
 603.577 +				dwIDAccelData = data[iIndex++];
 603.578 +
 603.579 +				WORD wIDCommand = LOWORD(dwIDAccelData);
 603.580 +				bExistID = m_mapAccelTable.Lookup(wIDCommand, pCmdAccel);
 603.581 +
 603.582 +				if (bExistID)
 603.583 +				{
 603.584 +					pCmdAccel->DeleteUserAccels();
 603.585 +				}
 603.586 +				for (int j = 0; j < HIWORD(dwIDAccelData) && iIndex < count; j++)
 603.587 +				{
 603.588 +					dwAccelData = data[iIndex++];
 603.589 +					if (bExistID)
 603.590 +					{
 603.591 +						pAccel = new CAccelsOb;
 603.592 +						ASSERT(pAccel != NULL);
 603.593 +						pAccel->SetData(dwAccelData);
 603.594 +						pCmdAccel->Add(pAccel);
 603.595 +					}
 603.596 +				}
 603.597 +			}
 603.598 +		}
 603.599 +		UpdateWndTable();
 603.600 +		return true;
 603.601 +	}
 603.602 +	return false;
 603.603 +}
 603.604 +
 603.605 +bool CAcceleratorManager::Write()
 603.606 +{
 603.607 +	CDWordArray AccelsDatasArray;
 603.608 +	CDWordArray CmdDatasArray;
 603.609 +
 603.610 +	int         iCount = 0;
 603.611 +	CCmdAccelOb*pCmdAccel;
 603.612 +	CAccelsOb*  pAccel;
 603.613 +	DWORD       dwAccelData;
 603.614 +
 603.615 +	WORD     wKey;
 603.616 +	POSITION pos = m_mapAccelTable.GetStartPosition();
 603.617 +	while (pos != NULL)
 603.618 +	{
 603.619 +		m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
 603.620 +		CmdDatasArray.RemoveAll();
 603.621 +
 603.622 +		POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
 603.623 +		while (pos != NULL)
 603.624 +		{
 603.625 +			pAccel = pCmdAccel->m_Accels.GetNext(pos);
 603.626 +			//      if (!pAccel->m_bLocked) {
 603.627 +			dwAccelData = pAccel->GetData();
 603.628 +			CmdDatasArray.Add(dwAccelData);
 603.629 +			//      }
 603.630 +		}
 603.631 +
 603.632 +		if (CmdDatasArray.GetSize() > 0)
 603.633 +		{
 603.634 +			CmdDatasArray.InsertAt(0, MAKELONG(pCmdAccel->m_wIDCommand, CmdDatasArray.GetSize()));
 603.635 +
 603.636 +			AccelsDatasArray.Append(CmdDatasArray);
 603.637 +			iCount++;
 603.638 +		}
 603.639 +	}
 603.640 +	//  AccelsDatasArray.InsertAt(0, MAKELONG(65535, iCount));
 603.641 +
 603.642 +	int    count = AccelsDatasArray.GetSize();
 603.643 +	DWORD *data  = (DWORD *)malloc(count * sizeof(DWORD));
 603.644 +	ASSERT(data != NULL);
 603.645 +
 603.646 +	for (int index = 0; index < count; index++)
 603.647 +		data[index] = AccelsDatasArray[index];
 603.648 +
 603.649 +	regSetBinaryValue("keyboard", (char *)data, count*sizeof(DWORD));
 603.650 +
 603.651 +	AccelsDatasArray.RemoveAll();
 603.652 +	CmdDatasArray.RemoveAll();
 603.653 +
 603.654 +	free(data);
 603.655 +
 603.656 +	return true;
 603.657 +}
 603.658 +
 603.659 +//////////////////////////////////////////////////////////////////////
 603.660 +// Defaults values management.
 603.661 +//
 603.662 +bool CAcceleratorManager::CreateDefaultTable()
 603.663 +{
 603.664 +	if (m_bDefaultTable)
 603.665 +		return false;
 603.666 +
 603.667 +	CCmdAccelOb*pCmdAccel;
 603.668 +	CCmdAccelOb*pNewCmdAccel;
 603.669 +
 603.670 +	CAccelsOb*pAccel;
 603.671 +	CAccelsOb*pNewAccel;
 603.672 +
 603.673 +	WORD     wKey;
 603.674 +	POSITION pos = m_mapAccelTable.GetStartPosition();
 603.675 +	while (pos != NULL)
 603.676 +	{
 603.677 +		m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
 603.678 +		pNewCmdAccel = new CCmdAccelOb;
 603.679 +		ASSERT(pNewCmdAccel != NULL);
 603.680 +
 603.681 +		POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
 603.682 +		while (pos != NULL)
 603.683 +		{
 603.684 +			pAccel = pCmdAccel->m_Accels.GetNext(pos);
 603.685 +			if (!pAccel->m_bLocked)
 603.686 +			{
 603.687 +				pNewAccel = new CAccelsOb;
 603.688 +				ASSERT(pNewAccel != NULL);
 603.689 +
 603.690 +				*pNewAccel = *pAccel;
 603.691 +				pNewCmdAccel->m_Accels.AddTail(pNewAccel);
 603.692 +			}
 603.693 +		}
 603.694 +		if (pNewCmdAccel->m_Accels.GetCount() != 0)
 603.695 +		{
 603.696 +			pNewCmdAccel->m_wIDCommand = pCmdAccel->m_wIDCommand;
 603.697 +			pNewCmdAccel->m_szCommand  = pCmdAccel->m_szCommand;
 603.698 +
 603.699 +			m_mapAccelTableSaved.SetAt(wKey, pNewCmdAccel);
 603.700 +		}
 603.701 +		else
 603.702 +			delete pNewCmdAccel;
 603.703 +	}
 603.704 +
 603.705 +	m_bDefaultTable = true;
 603.706 +	return true;
 603.707 +}
 603.708 +
 603.709 +#include "mainwnd.h"
 603.710 +bool CAcceleratorManager::Default()
 603.711 +{
 603.712 +	/// this is NYI for some reason, so the "Reset All" button doesn't work
 603.713 +
 603.714 +#if 0
 603.715 +	// still doesn't work:
 603.716 +    Reset();
 603.717 +    regDeleteValue("keyboard");
 603.718 +    regDeleteValue("keyboardCount");
 603.719 +    Connect((MainWnd *)theApp.m_pMainWnd);
 603.720 +    extern void winAccelAddCommands(CAcceleratorManager& mgr);
 603.721 +    Load();
 603.722 +    CreateDefaultTable();
 603.723 +    winAccelAddCommands(*this);
 603.724 +    UpdateWndTable();
 603.725 +    Write();
 603.726 +    UpdateMenu(theApp.menu);
 603.727 +    m_pWndConnected = NULL;
 603.728 +#endif
 603.729 +
 603.730 +	return true;
 603.731 +}
 603.732 +
   604.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   604.2 +++ b/src/win32/AcceleratorManager.h	Sat Mar 03 10:31:27 2012 -0600
   604.3 @@ -0,0 +1,135 @@
   604.4 +////////////////////////////////////////////////////////////////////////////////
   604.5 +// Copyright (C) 1998 by Thierry Maurel
   604.6 +// All rights reserved
   604.7 +//
   604.8 +// Distribute freely, except: don't remove my name from the source or
   604.9 +// documentation (don't take credit for my work), mark your changes (don't
  604.10 +// get me blamed for your possible bugs), don't alter or remove this
  604.11 +// notice.
  604.12 +// No warrantee of any kind, express or implied, is included with this
  604.13 +// software; use at your own risk, responsibility for damages (if any) to
  604.14 +// anyone resulting from the use of this software rests entirely with the
  604.15 +// user.
  604.16 +//
  604.17 +// Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  604.18 +// I'll try to keep a version up to date.  I can be reached as follows:
  604.19 +//    tmaurel@caramail.com   (or tmaurel@hol.fr)
  604.20 +//
  604.21 +////////////////////////////////////////////////////////////////////////////////
  604.22 +// File    : AcceleratorManager.h
  604.23 +// Project : AccelsEditor
  604.24 +////////////////////////////////////////////////////////////////////////////////
  604.25 +// Version : 1.0                       * Author : T.Maurel
  604.26 +// Date    : 17.08.98
  604.27 +//
  604.28 +// Remarks : interface for the CAcceleratorManager class.
  604.29 +//
  604.30 +////////////////////////////////////////////////////////////////////////////////
  604.31 +#if !defined(AFX_ACCELERATORMANAGER_H__A6D76F4B_26C6_11D2_BE72_006097AC8D00__INCLUDED_)
  604.32 +#define AFX_ACCELERATORMANAGER_H__A6D76F4B_26C6_11D2_BE72_006097AC8D00__INCLUDED_
  604.33 +
  604.34 +#if _MSC_VER >= 1000
  604.35 +#pragma once
  604.36 +#endif // _MSC_VER >= 1000
  604.37 +
  604.38 +#include "afxtempl.h"
  604.39 +
  604.40 +class CCmdAccelOb;
  604.41 +
  604.42 +// Helper map
  604.43 +#ifndef CMapStringToWord
  604.44 +typedef CMap< CString, LPCSTR, WORD, WORD & > CMapStringToWord;
  604.45 +#endif
  604.46 +
  604.47 +#ifndef CMapWordToCCmdAccelOb
  604.48 +typedef CMap< WORD, WORD &, CCmdAccelOb *, CCmdAccelOb * & > CMapWordToCCmdAccelOb;
  604.49 +#endif
  604.50 +
  604.51 +////////////////////////////////////////////////////////////////////////////////
  604.52 +// All Registry stuff removed
  604.53 +
  604.54 +class CAcceleratorManager : public CObject
  604.55 +{
  604.56 +	friend class AccelEditor;
  604.57 +public:
  604.58 +	CAcceleratorManager();
  604.59 +	virtual ~CAcceleratorManager();
  604.60 +
  604.61 +	// Operations
  604.62 +public:
  604.63 +	void UpdateMenu(HMENU menu);
  604.64 +	// Connection to the main application wnd
  604.65 +	void Connect(CWnd *pWnd, bool bAutoSave = true);
  604.66 +	// In/Out
  604.67 +	bool Load();
  604.68 +	bool Write();
  604.69 +	// Get the initials accels, not the user's
  604.70 +	bool Default();
  604.71 +	// Save a copy in the 2 maps called xxxSaved, which are used in case
  604.72 +	// of Default(), to reload the defaults accels.
  604.73 +	bool CreateDefaultTable();
  604.74 +	bool IsDefaultTableAvailable() {return m_bDefaultTable;}
  604.75 +	bool IsMapStringCommandsEmpty()
  604.76 +	{
  604.77 +		if (m_mapAccelString.IsEmpty())
  604.78 +			return true;
  604.79 +		else
  604.80 +			return false;
  604.81 +	}
  604.82 +
  604.83 +	bool IsAutoSave() {return m_bAutoSave;}
  604.84 +	void SetAutoSave(bool bAutoSave) {m_bAutoSave = bAutoSave;}
  604.85 +
  604.86 +	// Helper fct, used for new menus strings
  604.87 +	bool GetStringFromACCEL(ACCEL*pACCEL, CString& szAccel);
  604.88 +	bool GetStringFromACCEL(BYTE cVirt, WORD nCode, CString& szAccel);
  604.89 +
  604.90 +	// Update the ACCELS table in the application, from the specified
  604.91 +	// datas in the manager.
  604.92 +	bool UpdateWndTable();
  604.93 +
  604.94 +	// Modification helper fcts
  604.95 +	bool SetAccel(BYTE cVirt, WORD wIDCommand, WORD wNewCaract,
  604.96 +	              LPCTSTR szCommand, bool bLocked = false);
  604.97 +	bool AddCommandAccel(WORD wIDCommand, LPCTSTR szCommand, bool bLocked = true);
  604.98 +	bool CreateEntry(WORD wIDCommand, LPCTSTR szCommand);
  604.99 +
 604.100 +	bool DeleteEntry(LPCTSTR szCommand);
 604.101 +	bool DeleteEntry(WORD wIDCommand);
 604.102 +	bool DeleteAccel(BYTE cVirt, WORD wIDCommand, WORD wNewCaract);
 604.103 +
 604.104 +	// Affectation operator
 604.105 +	CAcceleratorManager & operator=(const CAcceleratorManager& accelmgr);
 604.106 +public:
 604.107 +#ifdef _DEBUG
 604.108 +	virtual void AssertValid() const;
 604.109 +	virtual void Dump(CDumpContext& dc) const;
 604.110 +#endif
 604.111 +protected:
 604.112 +	// Erase all the datas
 604.113 +	void Reset();
 604.114 +	// Internal affect fct.
 604.115 +	bool AddAccel(BYTE cVirt, WORD wIDCommand, WORD wKey,
 604.116 +	              LPCTSTR szCommand, bool bLocked);
 604.117 +
 604.118 +	// Attributes
 604.119 +protected:
 604.120 +	CWnd *m_pWndConnected;
 604.121 +
 604.122 +	// User datas
 604.123 +/*TEMP HACK*/
 604.124 +public:
 604.125 +	CMapStringToWord m_mapAccelString;
 604.126 +/*TEMP HACK*/
 604.127 +public:
 604.128 +	CMapWordToCCmdAccelOb m_mapAccelTable;
 604.129 +protected:
 604.130 +	// Default datas
 604.131 +	CMapWordToCCmdAccelOb m_mapAccelTableSaved;
 604.132 +	bool m_bDefaultTable;
 604.133 +
 604.134 +	// if true, there is an auto-save, when the destructor is called
 604.135 +	bool m_bAutoSave;
 604.136 +};
 604.137 +
 604.138 +#endif // !defined(AFX_ACCELERATORMANAGER_H__A6D76F4B_26C6_11D2_BE72_006097AC8D00__INCLUDED_)
   605.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   605.2 +++ b/src/win32/Associate.cpp	Sat Mar 03 10:31:27 2012 -0600
   605.3 @@ -0,0 +1,105 @@
   605.4 +// Associate.cpp : implementation file
   605.5 +//
   605.6 +
   605.7 +#include "stdafx.h"
   605.8 +#include "resource.h"
   605.9 +#include "Associate.h"
  605.10 +#include "Reg.h"
  605.11 +
  605.12 +/////////////////////////////////////////////////////////////////////////////
  605.13 +// Associate dialog
  605.14 +
  605.15 +Associate::Associate(CWnd*pParent /*=NULL*/)
  605.16 +	: CDialog(Associate::IDD, pParent)
  605.17 +{
  605.18 +	//{{AFX_DATA_INIT(Associate)
  605.19 +	m_agb = FALSE;
  605.20 +	m_bin = FALSE;
  605.21 +	m_cgb = FALSE;
  605.22 +	m_gb  = FALSE;
  605.23 +	m_gba = FALSE;
  605.24 +	m_gbc = FALSE;
  605.25 +	m_sgb = FALSE;
  605.26 +	//}}AFX_DATA_INIT
  605.27 +}
  605.28 +
  605.29 +void Associate::DoDataExchange(CDataExchange*pDX)
  605.30 +{
  605.31 +	CDialog::DoDataExchange(pDX);
  605.32 +	//{{AFX_DATA_MAP(Associate)
  605.33 +	DDX_Check(pDX, IDC_AGB, m_agb);
  605.34 +	DDX_Check(pDX, IDC_BIN, m_bin);
  605.35 +	DDX_Check(pDX, IDC_CGB, m_cgb);
  605.36 +	DDX_Check(pDX, IDC_GB, m_gb);
  605.37 +	DDX_Check(pDX, IDC_GBA, m_gba);
  605.38 +	DDX_Check(pDX, IDC_GBC, m_gbc);
  605.39 +	DDX_Check(pDX, IDC_SGB, m_sgb);
  605.40 +	//}}AFX_DATA_MAP
  605.41 +}
  605.42 +
  605.43 +BEGIN_MESSAGE_MAP(Associate, CDialog)
  605.44 +//{{AFX_MSG_MAP(Associate)
  605.45 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
  605.46 +ON_BN_CLICKED(ID_OK, OnOk)
  605.47 +//}}AFX_MSG_MAP
  605.48 +END_MESSAGE_MAP()
  605.49 +
  605.50 +/////////////////////////////////////////////////////////////////////////////
  605.51 +// Associate message handlers
  605.52 +
  605.53 +BOOL Associate::OnInitDialog()
  605.54 +{
  605.55 +	CDialog::OnInitDialog();
  605.56 +
  605.57 +	CenterWindow();
  605.58 +
  605.59 +	return TRUE; // return TRUE unless you set the focus to a control
  605.60 +	             // EXCEPTION: OCX Property Pages should return FALSE
  605.61 +}
  605.62 +
  605.63 +void Associate::OnCancel()
  605.64 +{
  605.65 +	EndDialog(FALSE);
  605.66 +}
  605.67 +
  605.68 +void Associate::OnOk()
  605.69 +{
  605.70 +	UpdateData();
  605.71 +
  605.72 +	int mask = 0;
  605.73 +	if (m_gb)
  605.74 +		mask |= 1;
  605.75 +	if (m_sgb)
  605.76 +		mask |= 2;
  605.77 +	if (m_cgb)
  605.78 +		mask |= 4;
  605.79 +	if (m_gbc)
  605.80 +		mask |= 8;
  605.81 +	if (m_gba)
  605.82 +		mask |= 16;
  605.83 +	if (m_agb)
  605.84 +		mask |= 32;
  605.85 +	if (m_bin)
  605.86 +		mask |= 64;
  605.87 +	if (mask)
  605.88 +	{
  605.89 +		char    applicationPath[2048];
  605.90 +		CString commandPath;
  605.91 +		LPCTSTR types[] = { ".gb", ".sgb", ".cgb", ".gbc", ".gba", ".agb", ".bin" };
  605.92 +		GetModuleFileName(NULL, applicationPath, 2048);
  605.93 +		commandPath.Format("\"%s\" \"%%1\"", applicationPath);
  605.94 +		regAssociateType("VisualBoyAdvance.Binary",
  605.95 +		                 "Binary",
  605.96 +		                 commandPath);
  605.97 +
  605.98 +		for (int i = 0; i < 7; i++)
  605.99 +		{
 605.100 +			if (mask & (1<<i))
 605.101 +			{
 605.102 +				regCreateFileType(types[i], "VisualBoyAdvance.Binary");
 605.103 +			}
 605.104 +		}
 605.105 +	}
 605.106 +	EndDialog(TRUE);
 605.107 +}
 605.108 +
   606.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   606.2 +++ b/src/win32/Associate.h	Sat Mar 03 10:31:27 2012 -0600
   606.3 @@ -0,0 +1,52 @@
   606.4 +#if !defined(AFX_ASSOCIATE_H__3326525B_B405_40A7_82C4_B2594669A930__INCLUDED_)
   606.5 +#define AFX_ASSOCIATE_H__3326525B_B405_40A7_82C4_B2594669A930__INCLUDED_
   606.6 +
   606.7 +#if _MSC_VER > 1000
   606.8 +#pragma once
   606.9 +#endif // _MSC_VER > 1000
  606.10 +// Associate.h : header file
  606.11 +//
  606.12 +
  606.13 +/////////////////////////////////////////////////////////////////////////////
  606.14 +// Associate dialog
  606.15 +
  606.16 +class Associate : public CDialog
  606.17 +{
  606.18 +	// Construction
  606.19 +public:
  606.20 +	Associate(CWnd*pParent = NULL);  // standard constructor
  606.21 +
  606.22 +	// Dialog Data
  606.23 +	//{{AFX_DATA(Associate)
  606.24 +	enum { IDD = IDD_ASSOCIATIONS };
  606.25 +	BOOL m_agb;
  606.26 +	BOOL m_bin;
  606.27 +	BOOL m_cgb;
  606.28 +	BOOL m_gb;
  606.29 +	BOOL m_gba;
  606.30 +	BOOL m_gbc;
  606.31 +	BOOL m_sgb;
  606.32 +	//}}AFX_DATA
  606.33 +
  606.34 +	// Overrides
  606.35 +	// ClassWizard generated virtual function overrides
  606.36 +	//{{AFX_VIRTUAL(Associate)
  606.37 +protected:
  606.38 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  606.39 +	//}}AFX_VIRTUAL
  606.40 +
  606.41 +	// Implementation
  606.42 +protected:
  606.43 +	// Generated message map functions
  606.44 +	//{{AFX_MSG(Associate)
  606.45 +	virtual BOOL OnInitDialog();
  606.46 +	afx_msg void OnCancel();
  606.47 +	afx_msg void OnOk();
  606.48 +	//}}AFX_MSG
  606.49 +	DECLARE_MESSAGE_MAP()
  606.50 +};
  606.51 +
  606.52 +//{{AFX_INSERT_LOCATION}}
  606.53 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  606.54 +
  606.55 +#endif // !defined(AFX_ASSOCIATE_H__3326525B_B405_40A7_82C4_B2594669A930__INCLUDED_)
   607.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   607.2 +++ b/src/win32/BitmapControl.cpp	Sat Mar 03 10:31:27 2012 -0600
   607.3 @@ -0,0 +1,262 @@
   607.4 +// BitmapControl.cpp : implementation file
   607.5 +//
   607.6 +
   607.7 +#include "stdafx.h"
   607.8 +#include "BitmapControl.h"
   607.9 +
  607.10 +bool BitmapControl::isRegistered = false;
  607.11 +
  607.12 +/////////////////////////////////////////////////////////////////////////////
  607.13 +// BitmapControl
  607.14 +
  607.15 +IMPLEMENT_DYNCREATE(BitmapControl, CScrollView)
  607.16 +
  607.17 +  BitmapControl::BitmapControl()
  607.18 +{
  607.19 +  w = 0;
  607.20 +  h = 0;
  607.21 +  data = NULL;
  607.22 +  bmpInfo = NULL;
  607.23 +  stretch = false;
  607.24 +  registerClass();
  607.25 +  CSize sizeTotal;
  607.26 +  sizeTotal.cx = sizeTotal.cy = 0;
  607.27 +  SetScrollSizes(MM_TEXT, sizeTotal);
  607.28 +}
  607.29 +
  607.30 +BitmapControl::~BitmapControl()
  607.31 +{
  607.32 +}
  607.33 +
  607.34 +
  607.35 +BEGIN_MESSAGE_MAP(BitmapControl, CScrollView)
  607.36 +  //{{AFX_MSG_MAP(BitmapControl)
  607.37 +  ON_WM_ERASEBKGND()
  607.38 +  ON_WM_SIZE()
  607.39 +  ON_WM_LBUTTONDOWN()
  607.40 +  //}}AFX_MSG_MAP
  607.41 +  END_MESSAGE_MAP()
  607.42 +
  607.43 +  /////////////////////////////////////////////////////////////////////////////
  607.44 +// BitmapControl drawing
  607.45 +
  607.46 +void BitmapControl::OnInitialUpdate()
  607.47 +{
  607.48 +  CScrollView::OnInitialUpdate();
  607.49 +
  607.50 +  CSize sizeTotal;
  607.51 +  // TODO: calculate the total size of this view
  607.52 +  sizeTotal.cx = sizeTotal.cy = 100;
  607.53 +  SetScrollSizes(MM_TEXT, sizeTotal);
  607.54 +}
  607.55 +
  607.56 +void BitmapControl::OnDraw(CDC* dc)
  607.57 +{
  607.58 +  RECT r;
  607.59 +  GetClientRect(&r);
  607.60 +  int w1 = r.right - r.left;
  607.61 +  int h1 = r.bottom - r.top;
  607.62 +  CDC memDC;
  607.63 +  memDC.CreateCompatibleDC(dc);
  607.64 +  if(!stretch) {
  607.65 +    if(w > w1)
  607.66 +      w1 = w;
  607.67 +    if(h > h1)
  607.68 +      h1 = h;
  607.69 +  }
  607.70 +  CBitmap bitmap, *pOldBitmap;
  607.71 +  bitmap.CreateCompatibleBitmap(dc, w1, h1);
  607.72 +  pOldBitmap = memDC.SelectObject(&bitmap);
  607.73 +  if(stretch) {
  607.74 +    bmpInfo->bmiHeader.biWidth = w;
  607.75 +    bmpInfo->bmiHeader.biHeight = -h;
  607.76 +    
  607.77 +    StretchDIBits(memDC.GetSafeHdc(),
  607.78 +                  0,
  607.79 +                  0,
  607.80 +                  w1,
  607.81 +                  h1, 
  607.82 +                  0,
  607.83 +                  0,
  607.84 +                  w,
  607.85 +                  h,
  607.86 +                  data,
  607.87 +                  bmpInfo,
  607.88 +                  DIB_RGB_COLORS,
  607.89 +                  SRCCOPY);
  607.90 +  } else {
  607.91 +    FillOutsideRect(&memDC, CBrush::FromHandle(GetSysColorBrush(COLOR_BTNFACE)));
  607.92 +    
  607.93 +    bmpInfo->bmiHeader.biWidth = w;
  607.94 +    bmpInfo->bmiHeader.biHeight = -h;
  607.95 +    SetDIBitsToDevice(memDC.GetSafeHdc(),
  607.96 +                      0,
  607.97 +                      0,
  607.98 +                      w,
  607.99 +                      h,
 607.100 +                      0,
 607.101 +                      0,
 607.102 +                      0,
 607.103 +                      h,
 607.104 +                      data,
 607.105 +                      bmpInfo,
 607.106 +                      DIB_RGB_COLORS);
 607.107 +  }
 607.108 +
 607.109 +  dc->BitBlt(0,0,w1,h1,
 607.110 +             &memDC,0,0,SRCCOPY);
 607.111 +  memDC.SelectObject(pOldBitmap);
 607.112 +
 607.113 +  bitmap.DeleteObject();
 607.114 +  memDC.DeleteDC();  
 607.115 +}
 607.116 +
 607.117 +/////////////////////////////////////////////////////////////////////////////
 607.118 +// BitmapControl diagnostics
 607.119 +
 607.120 +#ifdef _DEBUG
 607.121 +void BitmapControl::AssertValid() const
 607.122 +{
 607.123 +  CScrollView::AssertValid();
 607.124 +}
 607.125 +
 607.126 +void BitmapControl::Dump(CDumpContext& dc) const
 607.127 +{
 607.128 +  CScrollView::Dump(dc);
 607.129 +}
 607.130 +#endif //_DEBUG
 607.131 +
 607.132 +/////////////////////////////////////////////////////////////////////////////
 607.133 +// BitmapControl message handlers
 607.134 +
 607.135 +BOOL BitmapControl::OnEraseBkgnd(CDC* pDC) 
 607.136 +{
 607.137 +  return TRUE;
 607.138 +}
 607.139 +
 607.140 +void BitmapControl::OnSize(UINT nType, int cx, int cy) 
 607.141 +{
 607.142 +  if(!stretch)
 607.143 +    CScrollView::OnSize(nType, cx, cy);
 607.144 +}
 607.145 +
 607.146 +void BitmapControl::OnLButtonDown(UINT nFlags, CPoint pt) 
 607.147 +{
 607.148 +  if(!data)
 607.149 +    return;
 607.150 +  int x = pt.x;
 607.151 +  int y = pt.y;
 607.152 +
 607.153 +  WPARAM point;
 607.154 +  
 607.155 +  if(stretch) {
 607.156 +    RECT rect;
 607.157 +    GetClientRect(&rect);
 607.158 +  
 607.159 +    int height = rect.bottom - rect.top;
 607.160 +    int width = rect.right - rect.left;
 607.161 +  
 607.162 +    int xx = (x * w) / width;
 607.163 +    int yy = (y * h) / height;
 607.164 +
 607.165 +    point = xx | (yy<<16);
 607.166 +
 607.167 +    int xxx = xx / 8;
 607.168 +    int yyy = yy / 8;
 607.169 +
 607.170 +    for(int i = 0; i < 8; i++) {
 607.171 +      memcpy(&colors[i*3*8], &data[xxx * 8 * 3 +
 607.172 +                                   w * yyy * 8 * 3 +
 607.173 +                                   i * w * 3], 8 * 3);
 607.174 +    }
 607.175 +  } else {
 607.176 +    POINT p;
 607.177 +    p.x = GetScrollPos(SB_HORZ);
 607.178 +    p.y = GetScrollPos(SB_VERT);
 607.179 +
 607.180 +    p.x += x;
 607.181 +    p.y += y;
 607.182 +
 607.183 +    if(p.x >= w ||
 607.184 +       p.y >= h)
 607.185 +      return;
 607.186 +
 607.187 +    point = p.x | (p.y<<16);
 607.188 +    
 607.189 +    int xxx = p.x / 8;
 607.190 +    int yyy = p.y / 8;
 607.191 +
 607.192 +    for(int i = 0; i < 8; i++) {
 607.193 +      memcpy(&colors[i*3*8], &data[xxx * 8 * 3 +
 607.194 +                                   w * yyy * 8 * 3 +
 607.195 +                                   i * w * 3], 8 * 3);
 607.196 +    }
 607.197 +  }
 607.198 +  
 607.199 +  GetParent()->SendMessage(WM_MAPINFO,
 607.200 +                           point,
 607.201 +                           (LPARAM)colors);
 607.202 +}
 607.203 +
 607.204 +void BitmapControl::setBmpInfo(BITMAPINFO *info)
 607.205 +{
 607.206 +  bmpInfo = info;
 607.207 +}
 607.208 +
 607.209 +void BitmapControl::setData(u8 *d)
 607.210 +{
 607.211 +  data = d;
 607.212 +}
 607.213 +
 607.214 +void BitmapControl::setSize(int w1, int h1)
 607.215 +{
 607.216 +  if(w != w1 || h != h1) {
 607.217 +    w = w1;
 607.218 +    h = h1;
 607.219 +    SIZE s;
 607.220 +    s.cx = w;
 607.221 +    s.cy = h;
 607.222 +    SetScrollSizes(MM_TEXT, s);
 607.223 +  }
 607.224 +}
 607.225 +
 607.226 +void BitmapControl::refresh()
 607.227 +{
 607.228 +  Invalidate();
 607.229 +}
 607.230 +
 607.231 +
 607.232 +void BitmapControl::registerClass()
 607.233 +{
 607.234 +  if(!isRegistered) {
 607.235 +    WNDCLASS wc;
 607.236 +    ZeroMemory(&wc, sizeof(wc));
 607.237 +    wc.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
 607.238 +    wc.lpfnWndProc = (WNDPROC)::DefWindowProc;
 607.239 +    wc.hInstance = AfxGetInstanceHandle();
 607.240 +    wc.hIcon = NULL;
 607.241 +    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
 607.242 +    wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
 607.243 +    wc.lpszMenuName = NULL;
 607.244 +    wc.lpszClassName = "VbaBitmapControl";
 607.245 +    AfxRegisterClass(&wc);
 607.246 +    isRegistered = true;
 607.247 +  }
 607.248 +}
 607.249 +
 607.250 +void BitmapControl::setStretch(bool b)
 607.251 +{
 607.252 +  if(b != stretch) {
 607.253 +    stretch = b;
 607.254 +    Invalidate();
 607.255 +  }
 607.256 +}
 607.257 +
 607.258 +bool BitmapControl::getStretch()
 607.259 +{
 607.260 +  return stretch;
 607.261 +}
 607.262 +
 607.263 +void BitmapControl::PostNcDestroy() 
 607.264 +{
 607.265 +}
   608.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   608.2 +++ b/src/win32/BitmapControl.h	Sat Mar 03 10:31:27 2012 -0600
   608.3 @@ -0,0 +1,75 @@
   608.4 +#if !defined(AFX_BITMAPCONTROL_H__2434AADB_B6A5_4E43_AA16_7B65B6F7FA26__INCLUDED_)
   608.5 +#define AFX_BITMAPCONTROL_H__2434AADB_B6A5_4E43_AA16_7B65B6F7FA26__INCLUDED_
   608.6 +
   608.7 +#if _MSC_VER > 1000
   608.8 +#pragma once
   608.9 +#endif // _MSC_VER > 1000
  608.10 +// BitmapControl.h : header file
  608.11 +//
  608.12 +#ifndef WM_MAPINFO
  608.13 +#define WM_MAPINFO WM_APP+101
  608.14 +#endif
  608.15 +
  608.16 +/////////////////////////////////////////////////////////////////////////////
  608.17 +// BitmapControl view
  608.18 +
  608.19 +class BitmapControl : public CScrollView
  608.20 +{
  608.21 +public:
  608.22 +	BitmapControl();         // protected constructor used by dynamic creation
  608.23 +protected:
  608.24 +	DECLARE_DYNCREATE(BitmapControl)
  608.25 +
  608.26 +	// Attributes
  608.27 +public:
  608.28 +	// Operations
  608.29 +public:
  608.30 +	void setStretch(bool b);
  608.31 +	void refresh();
  608.32 +	void setSize(int w1, int h1);
  608.33 +	void setData(u8 *d);
  608.34 +	void setBmpInfo(BITMAPINFO *info);
  608.35 +	static bool isRegistered;
  608.36 +
  608.37 +	// Overrides
  608.38 +	// ClassWizard generated virtual function overrides
  608.39 +	//{{AFX_VIRTUAL(BitmapControl)
  608.40 +protected:
  608.41 +	virtual void OnDraw(CDC*pDC);     // overridden to draw this view
  608.42 +	virtual void OnInitialUpdate();   // first time after construct
  608.43 +	virtual void PostNcDestroy();
  608.44 +	//}}AFX_VIRTUAL
  608.45 +
  608.46 +	// Implementation
  608.47 +public:
  608.48 +	bool getStretch();
  608.49 +	virtual ~BitmapControl();
  608.50 +protected:
  608.51 +#ifdef _DEBUG
  608.52 +	virtual void AssertValid() const;
  608.53 +	virtual void Dump(CDumpContext& dc) const;
  608.54 +#endif
  608.55 +
  608.56 +	// Generated message map functions
  608.57 +	//{{AFX_MSG(BitmapControl)
  608.58 +	afx_msg BOOL OnEraseBkgnd(CDC*pDC);
  608.59 +	afx_msg void OnSize(UINT nType, int cx, int cy);
  608.60 +	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  608.61 +	//}}AFX_MSG
  608.62 +	DECLARE_MESSAGE_MAP()
  608.63 +private:
  608.64 +	void registerClass();
  608.65 +	bool        stretch;
  608.66 +	u8          colors[3*64];
  608.67 +	BITMAPINFO *bmpInfo;
  608.68 +	u8 *        data;
  608.69 +	int         h;
  608.70 +	int         w;
  608.71 +};
  608.72 +
  608.73 +/////////////////////////////////////////////////////////////////////////////
  608.74 +
  608.75 +//{{AFX_INSERT_LOCATION}}
  608.76 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  608.77 +
  608.78 +#endif // !defined(AFX_BITMAPCONTROL_H__2434AADB_B6A5_4E43_AA16_7B65B6F7FA26__INCLUDED_)
   609.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   609.2 +++ b/src/win32/BugReport.cpp	Sat Mar 03 10:31:27 2012 -0600
   609.3 @@ -0,0 +1,235 @@
   609.4 +// BugReport.cpp : implementation file
   609.5 +//
   609.6 +
   609.7 +#include "stdafx.h"
   609.8 +#include "resource.h"
   609.9 +#include "BugReport.h"
  609.10 +#include "VBA.h"
  609.11 +
  609.12 +#include "../version.h"
  609.13 +#include "../gba/agbprint.h"
  609.14 +#include "../gba/Flash.h"
  609.15 +#include "../gba/GBACheats.h"
  609.16 +#include "../gba/GBAGlobals.h"
  609.17 +#include "../gb/gbCheats.h"
  609.18 +#include "../gb/gbGlobals.h"
  609.19 +#include "../gba/RTC.h"
  609.20 +#include "../gba/GBASound.h"
  609.21 +#include "../common/vbalua.h"
  609.22 +
  609.23 +/////////////////////////////////////////////////////////////////////////////
  609.24 +// BugReport dialog
  609.25 +
  609.26 +BugReport::BugReport(CWnd*pParent /*=NULL*/)
  609.27 +	: CDialog(BugReport::IDD, pParent)
  609.28 +{
  609.29 +	//{{AFX_DATA_INIT(BugReport)
  609.30 +	// NOTE: the ClassWizard will add member initialization here
  609.31 +	//}}AFX_DATA_INIT
  609.32 +}
  609.33 +
  609.34 +void BugReport::DoDataExchange(CDataExchange*pDX)
  609.35 +{
  609.36 +	CDialog::DoDataExchange(pDX);
  609.37 +	//{{AFX_DATA_MAP(BugReport)
  609.38 +	DDX_Control(pDX, IDC_BUG_REPORT, m_report);
  609.39 +	//}}AFX_DATA_MAP
  609.40 +}
  609.41 +
  609.42 +BEGIN_MESSAGE_MAP(BugReport, CDialog)
  609.43 +//{{AFX_MSG_MAP(BugReport)
  609.44 +ON_BN_CLICKED(IDC_COPY, OnCopy)
  609.45 +ON_BN_CLICKED(ID_OK, OnOk)
  609.46 +//}}AFX_MSG_MAP
  609.47 +END_MESSAGE_MAP()
  609.48 +
  609.49 +/////////////////////////////////////////////////////////////////////////////
  609.50 +// BugReport message handlers
  609.51 +
  609.52 +void BugReport::OnCopy()
  609.53 +{
  609.54 +	OpenClipboard();
  609.55 +
  609.56 +	EmptyClipboard();
  609.57 +	CString report;
  609.58 +	m_report.GetWindowText(report);
  609.59 +
  609.60 +	HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE,
  609.61 +	                               (report.GetLength() + 1) * sizeof(CHAR));
  609.62 +	if (hglbCopy == NULL)
  609.63 +	{
  609.64 +		CloseClipboard();
  609.65 +		return;
  609.66 +	}
  609.67 +
  609.68 +	// Lock the handle and copy the text to the buffer.
  609.69 +
  609.70 +	LPSTR lptstrCopy = (LPSTR)GlobalLock(hglbCopy);
  609.71 +	memcpy(lptstrCopy, (const char *)report,
  609.72 +	       report.GetLength() * sizeof(CHAR));
  609.73 +	lptstrCopy[report.GetLength()] = (TCHAR) 0;  // null character
  609.74 +	GlobalUnlock(hglbCopy);
  609.75 +
  609.76 +	// Place the handle on the clipboard.
  609.77 +
  609.78 +	SetClipboardData(CF_TEXT, hglbCopy);
  609.79 +	CloseClipboard();
  609.80 +
  609.81 +	systemMessage(IDS_BUG_REPORT, "Bug report has been copied to the Clipboard");
  609.82 +}
  609.83 +
  609.84 +void BugReport::OnOk()
  609.85 +{
  609.86 +	EndDialog(TRUE);
  609.87 +}
  609.88 +
  609.89 +BOOL BugReport::OnInitDialog()
  609.90 +{
  609.91 +	CDialog::OnInitDialog();
  609.92 +
  609.93 +	CenterWindow();
  609.94 +
  609.95 +	CString report = createReport();
  609.96 +
  609.97 +	m_report.SetFont(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)));
  609.98 +
  609.99 +	m_report.SetWindowText(report);
 609.100 +
 609.101 +	return TRUE; // return TRUE unless you set the focus to a control
 609.102 +	// EXCEPTION: OCX Property Pages should return FALSE
 609.103 +}
 609.104 +
 609.105 +static void AppendFormat(CString& report, const char *format, ...)
 609.106 +{
 609.107 +	CString buffer;
 609.108 +	va_list valist;
 609.109 +
 609.110 +	va_start(valist, format);
 609.111 +	buffer.FormatV(format, valist);
 609.112 +	va_end(valist);
 609.113 +	report += buffer;
 609.114 +}
 609.115 +
 609.116 +CString BugReport::createReport()
 609.117 +{
 609.118 +	theApp.winCheckFullscreen();
 609.119 +
 609.120 +	CString report = "";
 609.121 +	AppendFormat(report, "Emu version  : %s\r\n", VBA_VERSION_STRING);
 609.122 +AppendFormat(report, "Emu type     : %s\r\n", VBA_BUILDTYPE_STRING);
 609.123 +
 609.124 +	if (systemIsEmulating())
 609.125 +	{
 609.126 +		AppendFormat(report, "Game         : %s\r\n", theApp.gameFilename);
 609.127 +
 609.128 +		char buffer[20];
 609.129 +		if (systemCartridgeType == 0)
 609.130 +		{
 609.131 +			u32 check = 0;
 609.132 +			for (int i = 0; i < 0x4000; i += 4)
 609.133 +			{
 609.134 +				check += *((u32 *)&bios[i]);
 609.135 +			}
 609.136 +			AppendFormat(report, "BIOS checksum: %08X\r\n", check);
 609.137 +
 609.138 +			strncpy(buffer, (const char *)&rom[0xa0], 12);
 609.139 +			buffer[12] = 0;
 609.140 +			AppendFormat(report, "Internal name: %s\r\n", buffer);
 609.141 +
 609.142 +			strncpy(buffer, (const char *)&rom[0xac], 4);
 609.143 +			buffer[4] = 0;
 609.144 +			AppendFormat(report, "Game code    : %s\r\n", buffer);
 609.145 +
 609.146 +			CString res = "";
 609.147 +			u32 *   p   = (u32 *)rom;
 609.148 +			u32 *   end = (u32 *)((char *)rom+theApp.romSize);
 609.149 +			while (p  < end)
 609.150 +			{
 609.151 +				u32 d = READ32LE(p);
 609.152 +
 609.153 +				if (d == 0x52504545)
 609.154 +				{
 609.155 +					if (memcmp(p, "EEPROM_", 7) == 0)
 609.156 +					{
 609.157 +						res += (const char *)p;
 609.158 +						res += ' ';
 609.159 +					}
 609.160 +				}
 609.161 +				else if (d == 0x4D415253)
 609.162 +				{
 609.163 +					if (memcmp(p, "SRAM_", 5) == 0)
 609.164 +					{
 609.165 +						res += (const char *)p;
 609.166 +						res += ' ';
 609.167 +					}
 609.168 +				}
 609.169 +				else if (d == 0x53414C46)
 609.170 +				{
 609.171 +					if (memcmp(p, "FLASH1M_", 8) == 0)
 609.172 +					{
 609.173 +						res += (const char *)p;
 609.174 +						res += ' ';
 609.175 +					}
 609.176 +				}
 609.177 +				else if (memcmp(p, "FLASH", 5) == 0)
 609.178 +				{
 609.179 +					res += (const char *)p;
 609.180 +					res += ' ';
 609.181 +				}
 609.182 +				else if (d == 0x52494953)
 609.183 +				{
 609.184 +					if (memcmp(p, "SIIRTC_V", 8) == 0)
 609.185 +					{
 609.186 +						res += (const char *)p;
 609.187 +						res += ' ';
 609.188 +					}
 609.189 +				}
 609.190 +				p++;
 609.191 +			}
 609.192 +			if (res.GetLength() > 0)
 609.193 +				AppendFormat(report, "Cart Save    : %s\r\n", res);
 609.194 +		}
 609.195 +		else if (systemCartridgeType == 1)
 609.196 +		{
 609.197 +			strncpy(buffer, (const char *)&gbRom[0x134], 15);
 609.198 +			buffer[15] = 0;
 609.199 +			AppendFormat(report, "Game title   : %s\r\n", buffer);
 609.200 +		}
 609.201 +	}
 609.202 +
 609.203 +	AppendFormat(report, "Using BIOS   : %d\r\n", useBios);
 609.204 +	AppendFormat(report, "Skip BIOS    : %d\r\n", theApp.skipBiosFile);
 609.205 +	AppendFormat(report, "Disable SFX  : %d\r\n", cpuDisableSfx);
 609.206 +///  AppendFormat(report, "Skip intro   : %d\r\n", theApp.removeIntros);
 609.207 +	AppendFormat(report, "Throttle     : %d\r\n", theApp.throttle);
 609.208 +	AppendFormat(report, "Rewind       : %d\r\n", theApp.rewindTimer);
 609.209 +	AppendFormat(report, "Lua          : %d\r\n", VBALuaRunning());
 609.210 +///  AppendFormat(report, "Auto frame   : %d\r\n", theApp.autoFrameSkip);
 609.211 +	AppendFormat(report, "Video option : %d\r\n", theApp.videoOption);
 609.212 +	AppendFormat(report, "Render type  : %d\r\n", theApp.renderMethod);
 609.213 +	AppendFormat(report, "Color depth  : %d\r\n", systemColorDepth);
 609.214 +	AppendFormat(report, "Red shift    : %08x\r\n", systemRedShift);
 609.215 +	AppendFormat(report, "Green shift  : %08x\r\n", systemGreenShift);
 609.216 +	AppendFormat(report, "Blue shift   : %08x\r\n", systemBlueShift);
 609.217 +	AppendFormat(report, "Layer setting: %04X\r\n", layerSettings);
 609.218 +	AppendFormat(report, "Save type    : %d (%d)\r\n",
 609.219 +	             theApp.winSaveType, cpuSaveType);
 609.220 +	AppendFormat(report, "Flash size   : %08X (%08x)\r\n",
 609.221 +	             theApp.winFlashSize, flashSize);
 609.222 +	AppendFormat(report, "RTC          : %d (%d)\r\n", theApp.winRtcEnable,
 609.223 +	             rtcIsEnabled());
 609.224 +	AppendFormat(report, "AGBPrint     : %d\r\n", agbPrintIsEnabled());
 609.225 +	AppendFormat(report, "Turbo Mode   : %d\r\n", theApp.speedupToggle);
 609.226 +	AppendFormat(report, "Synchronize  : %d\r\n", synchronize);
 609.227 +	AppendFormat(report, "Sound OFF    : %d\r\n", soundOffFlag);
 609.228 +	AppendFormat(report, "Channels     : %04x\r\n", soundGetEnabledChannels() & 0x30f);
 609.229 +	AppendFormat(report, "Old Sync     : %d\r\n", theApp.useOldSync);
 609.230 +	AppendFormat(report, "Priority     : %d\r\n", theApp.threadPriority);
 609.231 +	AppendFormat(report, "Filters      : %d (%d)\r\n", theApp.filterType, theApp.ifbType);
 609.232 +	AppendFormat(report, "Cheats       : %d\r\n", cheatsNumber);
 609.233 +	AppendFormat(report, "GB Cheats    : %d\r\n", gbCheatNumber);
 609.234 +	AppendFormat(report, "GB Emu Type  : %d\r\n", gbEmulatorType);
 609.235 +
 609.236 +	return report;
 609.237 +}
 609.238 +
   610.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   610.2 +++ b/src/win32/BugReport.h	Sat Mar 03 10:31:27 2012 -0600
   610.3 @@ -0,0 +1,48 @@
   610.4 +#if !defined(AFX_BUGREPORT_H__DE7BC381_E45D_4200_910C_E5378E6364C9__INCLUDED_)
   610.5 +#define AFX_BUGREPORT_H__DE7BC381_E45D_4200_910C_E5378E6364C9__INCLUDED_
   610.6 +
   610.7 +#if _MSC_VER > 1000
   610.8 +#pragma once
   610.9 +#endif // _MSC_VER > 1000
  610.10 +// BugReport.h : header file
  610.11 +//
  610.12 +
  610.13 +/////////////////////////////////////////////////////////////////////////////
  610.14 +// BugReport dialog
  610.15 +
  610.16 +class BugReport : public CDialog
  610.17 +{
  610.18 +	// Construction
  610.19 +public:
  610.20 +	BugReport(CWnd*pParent = NULL);  // standard constructor
  610.21 +
  610.22 +	// Dialog Data
  610.23 +	//{{AFX_DATA(BugReport)
  610.24 +	enum { IDD = IDD_BUG_REPORT };
  610.25 +	CEdit m_report;
  610.26 +	//}}AFX_DATA
  610.27 +
  610.28 +	// Overrides
  610.29 +	// ClassWizard generated virtual function overrides
  610.30 +	//{{AFX_VIRTUAL(BugReport)
  610.31 +protected:
  610.32 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  610.33 +	//}}AFX_VIRTUAL
  610.34 +
  610.35 +	// Implementation
  610.36 +protected:
  610.37 +	CString createReport();
  610.38 +
  610.39 +	// Generated message map functions
  610.40 +	//{{AFX_MSG(BugReport)
  610.41 +	afx_msg void OnCopy();
  610.42 +	afx_msg void OnOk();
  610.43 +	virtual BOOL OnInitDialog();
  610.44 +	//}}AFX_MSG
  610.45 +	DECLARE_MESSAGE_MAP()
  610.46 +};
  610.47 +
  610.48 +//{{AFX_INSERT_LOCATION}}
  610.49 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  610.50 +
  610.51 +#endif // !defined(AFX_BUGREPORT_H__DE7BC381_E45D_4200_910C_E5378E6364C9__INCLUDED_)
   611.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   611.2 +++ b/src/win32/CmdAccelOb.cpp	Sat Mar 03 10:31:27 2012 -0600
   611.3 @@ -0,0 +1,539 @@
   611.4 +////////////////////////////////////////////////////////////////////////////////
   611.5 +// Copyright (C) 1998 by Thierry Maurel
   611.6 +// All rights reserved
   611.7 +//
   611.8 +// Distribute freely, except: don't remove my name from the source or
   611.9 +// documentation (don't take credit for my work), mark your changes (don't
  611.10 +// get me blamed for your possible bugs), don't alter or remove this
  611.11 +// notice.
  611.12 +// No warrantee of any kind, express or implied, is included with this
  611.13 +// software; use at your own risk, responsibility for damages (if any) to
  611.14 +// anyone resulting from the use of this software rests entirely with the
  611.15 +// user.
  611.16 +//
  611.17 +// Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  611.18 +// I'll try to keep a version up to date.  I can be reached as follows:
  611.19 +//    tmaurel@caramail.com   (or tmaurel@hol.fr)
  611.20 +//
  611.21 +////////////////////////////////////////////////////////////////////////////////
  611.22 +// File    : CmdAccelOb.cpp
  611.23 +// Project : AccelsEditor
  611.24 +////////////////////////////////////////////////////////////////////////////////
  611.25 +// Version : 1.0                       * Author : T.Maurel
  611.26 +// Date    : 17.08.98
  611.27 +//
  611.28 +// Remarks :
  611.29 +//
  611.30 +////////////////////////////////////////////////////////////////////////////////
  611.31 +// modified by the VBA-rr team
  611.32 +
  611.33 +#include "stdafx.h"
  611.34 +#include "CmdAccelOb.h"
  611.35 +
  611.36 +////////////////////////////////////////////////////////////////////////
  611.37 +//
  611.38 +//
  611.39 +MAPVIRTKEYS mapVirtKeys[] = {
  611.40 +	{ VK_LBUTTON,		 "LBUTTON"				},
  611.41 +	{ VK_RBUTTON,		 "RBUTTON"				},
  611.42 +	{ VK_CANCEL,		 "Cancel"				},
  611.43 +	{ VK_MBUTTON,		 "MBUTTON"				},
  611.44 +	{ VK_BACK,			 "Backspace"			},
  611.45 +	{ VK_TAB,			 "Tab"					},
  611.46 +	{ VK_CLEAR,			 "Clear"				},
  611.47 +	{ VK_RETURN,		 "Enter"				},
  611.48 +	{ VK_SHIFT,			 "Shift"				},
  611.49 +	{ VK_LSHIFT,		 "LShift"				},
  611.50 +	{ VK_RSHIFT,		 "RShift"				},
  611.51 +	{ VK_CONTROL,		 "Control"				},
  611.52 +	{ VK_LCONTROL,		 "LControl"				},
  611.53 +	{ VK_RCONTROL,		 "RControl"				},
  611.54 +	{ VK_MENU,			 "Alt"					},
  611.55 +	{ VK_LMENU,			 "LAlt"					},
  611.56 +	{ VK_RMENU,			 "RAlt"					},
  611.57 +	{ VK_PAUSE,			 "Pause"				},
  611.58 +	{ VK_CAPITAL,		 "Caps Lock"			},
  611.59 +	{ VK_ESCAPE,		 "Escape"				},
  611.60 +	{ VK_SPACE,			 "Space"				},
  611.61 +	{ VK_PRIOR,			 "Prior"				},
  611.62 +	{ VK_NEXT,			 "Next"					},
  611.63 +	{ VK_END,			 "End"					},
  611.64 +	{ VK_HOME,			 "Home"					},
  611.65 +	{ VK_LEFT,			 "Left"					},
  611.66 +	{ VK_UP,			 "Up"					},
  611.67 +	{ VK_RIGHT,			 "Right"				},
  611.68 +	{ VK_DOWN,			 "Down"					},
  611.69 +	{ VK_SELECT,		 "Select"				},
  611.70 +	{ VK_PRINT,			 "Print"				},
  611.71 +	{ VK_EXECUTE,		 "Execute"				},
  611.72 +	{ VK_SNAPSHOT,		 "Snapshot"				},
  611.73 +	{ VK_INSERT,		 "Insert"				},
  611.74 +	{ VK_DELETE,		 "Delete"				},
  611.75 +	{ VK_HELP,			 "Help"					},
  611.76 +	{ WORD('0'),		 "0"					},
  611.77 +	{ WORD('1'),		 "1"					},
  611.78 +	{ WORD('2'),		 "2"					},
  611.79 +	{ WORD('3'),		 "3"					},
  611.80 +	{ WORD('4'),		 "4"					},
  611.81 +	{ WORD('5'),		 "5"					},
  611.82 +	{ WORD('6'),		 "6"					},
  611.83 +	{ WORD('7'),		 "7"					},
  611.84 +	{ WORD('8'),		 "8"					},
  611.85 +	{ WORD('9'),		 "9"					},
  611.86 +	{ WORD('A'),		 "A"					},
  611.87 +	{ WORD('B'),		 "B"					},
  611.88 +	{ WORD('C'),		 "C"					},
  611.89 +	{ WORD('D'),		 "D"					},
  611.90 +	{ WORD('E'),		 "E"					},
  611.91 +	{ WORD('F'),		 "F"					},
  611.92 +	{ WORD('G'),		 "G"					},
  611.93 +	{ WORD('H'),		 "H"					},
  611.94 +	{ WORD('I'),		 "I"					},
  611.95 +	{ WORD('J'),		 "J"					},
  611.96 +	{ WORD('K'),		 "K"					},
  611.97 +	{ WORD('L'),		 "L"					},
  611.98 +	{ WORD('M'),		 "M"					},
  611.99 +	{ WORD('N'),		 "N"					},
 611.100 +	{ WORD('O'),		 "O"					},
 611.101 +	{ WORD('P'),		 "P"					},
 611.102 +	{ WORD('Q'),		 "Q"					},
 611.103 +	{ WORD('R'),		 "R"					},
 611.104 +	{ WORD('S'),		 "S"					},
 611.105 +	{ WORD('T'),		 "T"					},
 611.106 +	{ WORD('U'),		 "U"					},
 611.107 +	{ WORD('V'),		 "V"					},
 611.108 +	{ WORD('W'),		 "W"					},
 611.109 +	{ WORD('X'),		 "X"					},
 611.110 +	{ WORD('Y'),		 "Y"					},
 611.111 +	{ WORD('Z'),		 "Z"					},
 611.112 +	{ VK_LWIN,			 "LWIN"					},
 611.113 +	{ VK_RWIN,			 "RWIN"					},
 611.114 +	{ VK_APPS,			 "APPS"					},
 611.115 +	{ VK_NUMPAD0,		 "NumPad0"				},
 611.116 +	{ VK_NUMPAD1,		 "NumPad1"				},
 611.117 +	{ VK_NUMPAD2,		 "NumPad2"				},
 611.118 +	{ VK_NUMPAD3,		 "NumPad3"				},
 611.119 +	{ VK_NUMPAD4,		 "NumPad4"				},
 611.120 +	{ VK_NUMPAD5,		 "NumPad5"				},
 611.121 +	{ VK_NUMPAD6,		 "NumPad6"				},
 611.122 +	{ VK_NUMPAD7,		 "NumPad7"				},
 611.123 +	{ VK_NUMPAD8,		 "NumPad8"				},
 611.124 +	{ VK_NUMPAD9,		 "NumPad9"				},
 611.125 +	{ VK_MULTIPLY,		 "NumpadMultiply"		},
 611.126 +	{ VK_ADD,			 "NumpadAdd"			},
 611.127 +	{ VK_SEPARATOR,		 "Separator"			},
 611.128 +	{ VK_SUBTRACT,		 "NumpadSubtract"		},
 611.129 +	{ VK_DECIMAL,		 "NumpadDecimal"		},
 611.130 +	{ VK_DIVIDE,		 "NumpadDivide"			},
 611.131 +	{ VK_F1,			 "F1"					},
 611.132 +	{ VK_F2,			 "F2"					},
 611.133 +	{ VK_F3,			 "F3"					},
 611.134 +	{ VK_F4,			 "F4"					},
 611.135 +	{ VK_F5,			 "F5"					},
 611.136 +	{ VK_F6,			 "F6"					},
 611.137 +	{ VK_F7,			 "F7"					},
 611.138 +	{ VK_F8,			 "F8"					},
 611.139 +	{ VK_F9,			 "F9"					},
 611.140 +	{ VK_F10,			 "F10"					},
 611.141 +	{ VK_F11,			 "F11"					},
 611.142 +	{ VK_F12,			 "F12"					},
 611.143 +	{ VK_F13,			 "F13"					},
 611.144 +	{ VK_F14,			 "F14"					},
 611.145 +	{ VK_F15,			 "F15"					},
 611.146 +	{ VK_F16,			 "F16"					},
 611.147 +	{ VK_F17,			 "F17"					},
 611.148 +	{ VK_F18,			 "F18"					},
 611.149 +	{ VK_F19,			 "F19"					},
 611.150 +	{ VK_F20,			 "F20"					},
 611.151 +	{ VK_F21,			 "F21"					},
 611.152 +	{ VK_F22,			 "F22"					},
 611.153 +	{ VK_F23,			 "F23"					},
 611.154 +	{ VK_F24,			 "F24"					},
 611.155 +	{ VK_NUMLOCK,		 "Num Lock"				},
 611.156 +	{ VK_SCROLL,		 "Scroll Lock"			},
 611.157 +	{ VK_ATTN,			 "Attention"			},
 611.158 +	{ VK_CRSEL,			 "CRSEL"				},
 611.159 +	{ VK_EXSEL,			 "EXSEL"				},
 611.160 +	{ VK_EREOF,			 "EREOF"				},
 611.161 +	{ VK_PLAY,			 "Play"					},
 611.162 +	{ VK_ZOOM,			 "Zoom"					},
 611.163 +	{ VK_NONAME,		 "No Name"				},
 611.164 +	{ VK_PA1,			 "PA1"					},
 611.165 +	{ VK_OEM_CLEAR,		 "Clear2"				},
 611.166 +	{ VK_OEM_1,			 "Semicolon;"			},
 611.167 +	{ VK_OEM_2,			 "Slash/"				},
 611.168 +	{ VK_OEM_3,			 "Tilde~"				},
 611.169 +	{ VK_OEM_4,			 "LBracket["			},
 611.170 +	{ VK_OEM_5,			 "Backslash\\"			},
 611.171 +	{ VK_OEM_6,			 "RBracket]"			},
 611.172 +	{ VK_OEM_7,			 "Apostrophe'"			},
 611.173 +	{ VK_OEM_8,			 "OEM8"					},
 611.174 +	{ VK_OEM_PLUS,		 "Plus+"				},
 611.175 +	{ VK_OEM_MINUS,		 "Minus-"				},
 611.176 +	{ VK_OEM_COMMA,		 "Comma,"				},
 611.177 +	{ VK_OEM_PERIOD,	 "Period."				},
 611.178 +	{ VK_OEM_AX,		 "Apostrophe`"			},
 611.179 +	{ VK_OEM_102,		 "<> or \\|"			},
 611.180 +	{ VK_ICO_HELP,		 "ICO Help"				},
 611.181 +	{ VK_ICO_00,		 "ICO 00"				},
 611.182 +	{ VK_OEM_FJ_JISHO,	 "JISHO"				},
 611.183 +	{ VK_OEM_FJ_MASSHOU, "MASSHOU"				},
 611.184 +	{ VK_OEM_FJ_TOUROKU, "TOUROKU"				},
 611.185 +	{ VK_OEM_FJ_LOYA,	 "LOYA"					},
 611.186 +	{ VK_OEM_FJ_ROYA,	 "ROYA"					},
 611.187 +	{ VK_OEM_NEC_EQUAL,	 "Numpad Equals"		},
 611.188 +};
 611.189 +
 611.190 +////////////////////////////////////////////////////////////////////////
 611.191 +//
 611.192 +//
 611.193 +MAPVIRTKEYS mapVirtSysKeys[] = {
 611.194 +	{ FCONTROL, "Ctrl"	  },
 611.195 +	{ FALT,		"Alt"	  },
 611.196 +	{ FSHIFT,	"Shift"	  },
 611.197 +};
 611.198 +
 611.199 +////////////////////////////////////////////////////////////////////////
 611.200 +// helper fct for external access
 611.201 +////////////////////////////////////////////////////////////////////////
 611.202 +//
 611.203 +//
 611.204 +TCHAR *mapVirtKeysStringFromWORD(WORD wKey)
 611.205 +{
 611.206 +	for (int index = 0; index < sizeof(mapVirtKeys) / sizeof(mapVirtKeys[0]); index++)
 611.207 +	{
 611.208 +		if (mapVirtKeys[index].wKey == wKey)
 611.209 +			return mapVirtKeys[index].szKey;
 611.210 +	}
 611.211 +	return NULL;
 611.212 +}
 611.213 +
 611.214 +////////////////////////////////////////////////////////////////////////
 611.215 +//
 611.216 +#define DEFAULT_ACCEL   0x01
 611.217 +#define USER_ACCEL              0x02
 611.218 +
 611.219 +////////////////////////////////////////////////////////////////////////
 611.220 +//
 611.221 +////////////////////////////////////////////////////////////////////////
 611.222 +//
 611.223 +//
 611.224 +CAccelsOb::CAccelsOb()
 611.225 +{
 611.226 +	m_cVirt	  = 0;
 611.227 +	m_wKey	  = 0;
 611.228 +	m_bLocked = false;
 611.229 +}
 611.230 +
 611.231 +////////////////////////////////////////////////////////////////////////
 611.232 +//
 611.233 +//
 611.234 +CAccelsOb::CAccelsOb(CAccelsOb *pFrom)
 611.235 +{
 611.236 +	ASSERT(pFrom != NULL);
 611.237 +
 611.238 +	m_cVirt	  = pFrom->m_cVirt;
 611.239 +	m_wKey	  = pFrom->m_wKey;
 611.240 +	m_bLocked = pFrom->m_bLocked;
 611.241 +}
 611.242 +
 611.243 +////////////////////////////////////////////////////////////////////////
 611.244 +//
 611.245 +//
 611.246 +CAccelsOb::CAccelsOb(BYTE cVirt, WORD wKey, bool bLocked)
 611.247 +{
 611.248 +	m_cVirt	  = cVirt;
 611.249 +	m_wKey	  = wKey;
 611.250 +	m_bLocked = bLocked;
 611.251 +}
 611.252 +
 611.253 +////////////////////////////////////////////////////////////////////////
 611.254 +//
 611.255 +//
 611.256 +CAccelsOb::CAccelsOb(LPACCEL pACCEL)
 611.257 +{
 611.258 +	ASSERT(pACCEL != NULL);
 611.259 +
 611.260 +	m_cVirt	  = pACCEL->fVirt;
 611.261 +	m_wKey	  = pACCEL->key;
 611.262 +	m_bLocked = false;
 611.263 +}
 611.264 +
 611.265 +////////////////////////////////////////////////////////////////////////
 611.266 +//
 611.267 +//
 611.268 +CAccelsOb & CAccelsOb::operator=(const CAccelsOb &from)
 611.269 +{
 611.270 +	m_cVirt	  = from.m_cVirt;
 611.271 +	m_wKey	  = from.m_wKey;
 611.272 +	m_bLocked = from.m_bLocked;
 611.273 +
 611.274 +	return *this;
 611.275 +}
 611.276 +
 611.277 +////////////////////////////////////////////////////////////////////////
 611.278 +//
 611.279 +////////////////////////////////////////////////////////////////////////
 611.280 +//
 611.281 +//
 611.282 +void CAccelsOb::GetString(CString &szBuffer)
 611.283 +{
 611.284 +	szBuffer = "";
 611.285 +
 611.286 +	// modifiers part
 611.287 +	for (int i = 0; i < sizetable(mapVirtSysKeys); i++)
 611.288 +	{
 611.289 +		if (m_cVirt & mapVirtSysKeys[i].wKey)
 611.290 +		{
 611.291 +			szBuffer += mapVirtSysKeys[i].szKey;
 611.292 +			if (m_wKey)
 611.293 +				szBuffer += "+";
 611.294 +		}
 611.295 +	}
 611.296 +
 611.297 +	// in case of the object is not assigned, we avoid error messages
 611.298 +	if (m_wKey == 0)
 611.299 +		return;
 611.300 +
 611.301 +	// and virtual key part
 611.302 +	for (int i = 0; i < sizetable(mapVirtKeys); i++)
 611.303 +	{
 611.304 +		if (m_wKey == mapVirtKeys[i].wKey)
 611.305 +		{
 611.306 +			szBuffer += mapVirtKeys[i].szKey;
 611.307 +			return;
 611.308 +		}
 611.309 +	}
 611.310 +
 611.311 +	AfxMessageBox("Internal error : (CAccelsOb::GetString) m_wKey invalid");
 611.312 +}
 611.313 +
 611.314 +////////////////////////////////////////////////////////////////////////
 611.315 +//
 611.316 +//
 611.317 +bool CAccelsOb::IsEqual(WORD wKey, bool bCtrl, bool bAlt, bool bShift)
 611.318 +{
 611.319 +	bool m_bCtrl  = (m_cVirt & FCONTROL) ? true : false;
 611.320 +	bool m_bAlt	  = (m_cVirt & FALT) ? true : false;
 611.321 +	bool m_bShift = (m_cVirt & FSHIFT) ? true : false;
 611.322 +
 611.323 +	bool bRet = (bCtrl == m_bCtrl) && (bAlt == m_bAlt) && (bShift == m_bShift) && (m_wKey == wKey);
 611.324 +
 611.325 +	return bRet;
 611.326 +}
 611.327 +
 611.328 +////////////////////////////////////////////////////////////////////////
 611.329 +//
 611.330 +//
 611.331 +DWORD CAccelsOb::GetData()
 611.332 +{
 611.333 +	BYTE cLocalCodes = 0;
 611.334 +	if (m_bLocked)
 611.335 +		cLocalCodes = DEFAULT_ACCEL;
 611.336 +	else
 611.337 +		cLocalCodes = USER_ACCEL;
 611.338 +
 611.339 +	WORD bCodes = MAKEWORD(m_cVirt, cLocalCodes);
 611.340 +	return MAKELONG(m_wKey, bCodes);
 611.341 +}
 611.342 +
 611.343 +////////////////////////////////////////////////////////////////////////
 611.344 +//
 611.345 +//
 611.346 +bool CAccelsOb::SetData(DWORD dwDatas)
 611.347 +{
 611.348 +	m_wKey = LOWORD(dwDatas);
 611.349 +
 611.350 +	WORD bCodes = HIWORD(dwDatas);
 611.351 +	m_cVirt = LOBYTE(bCodes);
 611.352 +
 611.353 +	BYTE cLocalCodes = HIBYTE(bCodes);
 611.354 +	m_bLocked = (cLocalCodes == DEFAULT_ACCEL);
 611.355 +
 611.356 +	return true;
 611.357 +}
 611.358 +
 611.359 +////////////////////////////////////////////////////////////////////////
 611.360 +//
 611.361 +#ifdef _DEBUG
 611.362 +////////////////////////////////////////////////////////////////////////
 611.363 +//
 611.364 +//
 611.365 +void CAccelsOb::AssertValid() const
 611.366 +{
 611.367 +	CObject::AssertValid();
 611.368 +}
 611.369 +
 611.370 +////////////////////////////////////////////////////////////////////////
 611.371 +//
 611.372 +//
 611.373 +void CAccelsOb::Dump(CDumpContext &dc) const
 611.374 +{
 611.375 +	dc << "\t\t";
 611.376 +	CObject::Dump(dc);
 611.377 +	dc << "\t\tlocked=" << m_bLocked << ", cVirt=" << m_cVirt << ", wKey=" << m_wKey << "\n\n";
 611.378 +}
 611.379 +
 611.380 +#endif
 611.381 +
 611.382 +////////////////////////////////////////////////////////////////////////
 611.383 +//
 611.384 +////////////////////////////////////////////////////////////////////////
 611.385 +//
 611.386 +//
 611.387 +CCmdAccelOb::CCmdAccelOb()
 611.388 +{}
 611.389 +
 611.390 +////////////////////////////////////////////////////////////////////////
 611.391 +//
 611.392 +//
 611.393 +CCmdAccelOb::CCmdAccelOb(WORD wIDCommand, LPCTSTR szCommand)
 611.394 +{
 611.395 +	ASSERT(szCommand != NULL);
 611.396 +
 611.397 +	m_wIDCommand = wIDCommand;
 611.398 +	m_szCommand	 = szCommand;
 611.399 +}
 611.400 +
 611.401 +////////////////////////////////////////////////////////////////////////
 611.402 +//
 611.403 +//
 611.404 +CCmdAccelOb::CCmdAccelOb(BYTE cVirt, WORD wIDCommand, WORD wKey, LPCTSTR szCommand, bool bLocked)
 611.405 +{
 611.406 +	ASSERT(szCommand != NULL);
 611.407 +
 611.408 +	m_wIDCommand = wIDCommand;
 611.409 +	m_szCommand	 = szCommand;
 611.410 +
 611.411 +	CAccelsOb *pAccel = new CAccelsOb(cVirt, wKey, bLocked);
 611.412 +	ASSERT(pAccel != NULL);
 611.413 +	m_Accels.AddTail(pAccel);
 611.414 +}
 611.415 +
 611.416 +////////////////////////////////////////////////////////////////////////
 611.417 +//
 611.418 +//
 611.419 +CCmdAccelOb::~CCmdAccelOb()
 611.420 +{
 611.421 +	POSITION pos = m_Accels.GetHeadPosition();
 611.422 +	while (pos != NULL)
 611.423 +		delete m_Accels.GetNext(pos);
 611.424 +	m_Accels.RemoveAll();
 611.425 +}
 611.426 +
 611.427 +////////////////////////////////////////////////////////////////////////
 611.428 +//
 611.429 +////////////////////////////////////////////////////////////////////////
 611.430 +//
 611.431 +//
 611.432 +void CCmdAccelOb::Add(BYTE cVirt, WORD wKey, bool bLocked)
 611.433 +{
 611.434 +	CAccelsOb *pAccel = new CAccelsOb(cVirt, wKey, bLocked);
 611.435 +	ASSERT(pAccel != NULL);
 611.436 +	m_Accels.AddTail(pAccel);
 611.437 +}
 611.438 +
 611.439 +////////////////////////////////////////////////////////////////////////
 611.440 +//
 611.441 +//
 611.442 +void CCmdAccelOb::Add(CAccelsOb *pAccel)
 611.443 +{
 611.444 +	ASSERT(pAccel != NULL);
 611.445 +	m_Accels.AddTail(pAccel);
 611.446 +}
 611.447 +
 611.448 +////////////////////////////////////////////////////////////////////////
 611.449 +//
 611.450 +//
 611.451 +CCmdAccelOb & CCmdAccelOb::operator=(const CCmdAccelOb &from)
 611.452 +{
 611.453 +	Reset();
 611.454 +
 611.455 +	m_wIDCommand = from.m_wIDCommand;
 611.456 +	m_szCommand	 = from.m_szCommand;
 611.457 +
 611.458 +	CAccelsOb *pAccel;
 611.459 +	POSITION   pos = from.m_Accels.GetHeadPosition();
 611.460 +	while (pos != NULL)
 611.461 +	{
 611.462 +		pAccel = new CAccelsOb(from.m_Accels.GetNext(pos));
 611.463 +		ASSERT(pAccel != NULL);
 611.464 +		m_Accels.AddTail(pAccel);
 611.465 +	}
 611.466 +	return *this;
 611.467 +}
 611.468 +
 611.469 +////////////////////////////////////////////////////////////////////////
 611.470 +//
 611.471 +//
 611.472 +void CCmdAccelOb::DeleteUserAccels()
 611.473 +{
 611.474 +	CAccelsOb *pAccel;
 611.475 +	POSITION   prevPos;
 611.476 +	POSITION   pos = m_Accels.GetHeadPosition();
 611.477 +	while (pos != NULL)
 611.478 +	{
 611.479 +		prevPos = pos;
 611.480 +		pAccel	= m_Accels.GetNext(pos);
 611.481 +		if (!pAccel->m_bLocked)
 611.482 +		{
 611.483 +			delete pAccel;
 611.484 +			m_Accels.RemoveAt(prevPos);
 611.485 +		}
 611.486 +	}
 611.487 +}
 611.488 +
 611.489 +////////////////////////////////////////////////////////////////////////
 611.490 +//
 611.491 +//
 611.492 +void CCmdAccelOb::Reset()
 611.493 +{
 611.494 +	m_wIDCommand = 0;
 611.495 +	m_szCommand	 = "Empty command";
 611.496 +
 611.497 +	CAccelsOb *pAccel;
 611.498 +	POSITION   pos = m_Accels.GetHeadPosition();
 611.499 +	while (pos != NULL)
 611.500 +	{
 611.501 +		pAccel = m_Accels.GetNext(pos);
 611.502 +		delete pAccel;
 611.503 +	}
 611.504 +}
 611.505 +
 611.506 +////////////////////////////////////////////////////////////////////////
 611.507 +//
 611.508 +#ifdef _DEBUG
 611.509 +////////////////////////////////////////////////////////////////////////
 611.510 +//
 611.511 +//
 611.512 +void CCmdAccelOb::AssertValid() const
 611.513 +{
 611.514 +	// call base class function first
 611.515 +	CObject::AssertValid();
 611.516 +}
 611.517 +
 611.518 +////////////////////////////////////////////////////////////////////////
 611.519 +//
 611.520 +//
 611.521 +void CCmdAccelOb::Dump(CDumpContext &dc) const
 611.522 +{
 611.523 +	// call base class function first
 611.524 +	dc << "\t";
 611.525 +	CObject::Dump(dc);
 611.526 +
 611.527 +	// now do the stuff for our specific class
 611.528 +	dc << "\tIDCommand = " << m_wIDCommand;
 611.529 +	dc << "\n\tszCommand = " << m_szCommand;
 611.530 +	dc << "\n\tAccelerators = {\n";
 611.531 +
 611.532 +	CAccelsOb *pAccel;
 611.533 +	POSITION   pos = m_Accels.GetHeadPosition();
 611.534 +	while (pos != NULL)
 611.535 +	{
 611.536 +		pAccel = m_Accels.GetNext(pos);
 611.537 +		dc << pAccel;
 611.538 +	}
 611.539 +	dc << "\t}\n";
 611.540 +}
 611.541 +
 611.542 +#endif
   612.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   612.2 +++ b/src/win32/CmdAccelOb.h	Sat Mar 03 10:31:27 2012 -0600
   612.3 @@ -0,0 +1,110 @@
   612.4 +////////////////////////////////////////////////////////////////////////////////
   612.5 +// Copyright (C) 1998 by Thierry Maurel
   612.6 +// All rights reserved
   612.7 +//
   612.8 +// Distribute freely, except: don't remove my name from the source or
   612.9 +// documentation (don't take credit for my work), mark your changes (don't
  612.10 +// get me blamed for your possible bugs), don't alter or remove this
  612.11 +// notice.
  612.12 +// No warrantee of any kind, express or implied, is included with this
  612.13 +// software; use at your own risk, responsibility for damages (if any) to
  612.14 +// anyone resulting from the use of this software rests entirely with the
  612.15 +// user.
  612.16 +//
  612.17 +// Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  612.18 +// I'll try to keep a version up to date.  I can be reached as follows:
  612.19 +//    tmaurel@caramail.com   (or tmaurel@hol.fr)
  612.20 +//
  612.21 +////////////////////////////////////////////////////////////////////////////////
  612.22 +// File    : CmdAccelOb.h
  612.23 +// Project : AccelsEditor
  612.24 +////////////////////////////////////////////////////////////////////////////////
  612.25 +// Version : 1.0                       * Author : T.Maurel
  612.26 +// Date    : 17.08.98
  612.27 +//
  612.28 +// Remarks :
  612.29 +//
  612.30 +////////////////////////////////////////////////////////////////////////////////
  612.31 +#ifndef __CMDACCEL_OB_INCLUDE
  612.32 +#define __CMDACCEL_OB_INCLUDE
  612.33 +
  612.34 +#if _MSC_VER > 1000
  612.35 +#pragma once
  612.36 +#endif // _MSC_VER > 1000
  612.37 +
  612.38 +#include <afxtempl.h>  // MFC Templates extension
  612.39 +
  612.40 +////////////////////////////////////////////////////////////////////////
  612.41 +//
  612.42 +//
  612.43 +typedef struct tagMAPVIRTKEYS
  612.44 +{
  612.45 +	WORD  wKey;
  612.46 +	TCHAR szKey[15];
  612.47 +} MAPVIRTKEYS, *PMAPVIRTKEYS;
  612.48 +
  612.49 +////////////////////////////////////////////////////////////////////////
  612.50 +//
  612.51 +//
  612.52 +#define sizetable(table) (sizeof(table)/sizeof(table[0]))
  612.53 +
  612.54 +////////////////////////////////////////////////////////////////////////
  612.55 +//
  612.56 +//
  612.57 +class CAccelsOb : public CObject
  612.58 +{
  612.59 +public:
  612.60 +	CAccelsOb();
  612.61 +	CAccelsOb(CAccelsOb*pFrom);
  612.62 +	CAccelsOb(BYTE cVirt, WORD wKey, bool bLocked = false);
  612.63 +	CAccelsOb(LPACCEL pACCEL);
  612.64 +public:
  612.65 +	CAccelsOb & operator=(const CAccelsOb& from);
  612.66 +
  612.67 +	void GetString(CString& szBuffer);
  612.68 +	bool IsEqual(WORD wKey, bool bCtrl, bool bAlt, bool bShift);
  612.69 +	DWORD GetData();
  612.70 +	bool SetData(DWORD dwDatas);
  612.71 +public:
  612.72 +#ifdef _DEBUG
  612.73 +	virtual void AssertValid() const;
  612.74 +	virtual void Dump(CDumpContext& dc) const;
  612.75 +#endif
  612.76 +public:
  612.77 +	BYTE m_cVirt;
  612.78 +	WORD m_wKey;
  612.79 +	bool m_bLocked;
  612.80 +};
  612.81 +
  612.82 +//////////////////////////////////////////////////////////////////////
  612.83 +//
  612.84 +//
  612.85 +class CCmdAccelOb : public CObject
  612.86 +{
  612.87 +public:
  612.88 +	CCmdAccelOb();
  612.89 +	CCmdAccelOb(WORD wIDCommand, LPCTSTR szCommand);
  612.90 +	CCmdAccelOb(BYTE cVirt, WORD wIDCommand, WORD wKey, LPCTSTR szCommand, bool bLocked = false);
  612.91 +	~CCmdAccelOb();
  612.92 +public:
  612.93 +	void Add(CAccelsOb*pAccel);
  612.94 +	void Add(BYTE cVirt, WORD wKey, bool bLocked = false);
  612.95 +	void Reset();
  612.96 +	void DeleteUserAccels();
  612.97 +
  612.98 +	CCmdAccelOb & operator=(const CCmdAccelOb& from);
  612.99 +public:
 612.100 +#ifdef _DEBUG
 612.101 +	virtual void AssertValid() const;
 612.102 +	virtual void Dump(CDumpContext& dc) const;
 612.103 +#endif
 612.104 +public:
 612.105 +	WORD    m_wIDCommand;
 612.106 +	CString m_szCommand;
 612.107 +
 612.108 +	CList< CAccelsOb *, CAccelsOb * & > m_Accels;
 612.109 +};
 612.110 +
 612.111 +////////////////////////////////////////////////////////////////////////
 612.112 +#endif // __CMDACCEL_OB_INCLUDE
 612.113 +
   613.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   613.2 +++ b/src/win32/ColorButton.cpp	Sat Mar 03 10:31:27 2012 -0600
   613.3 @@ -0,0 +1,95 @@
   613.4 +// ColorButton.cpp : implementation file
   613.5 +//
   613.6 +
   613.7 +#include "stdafx.h"
   613.8 +#include "ColorButton.h"
   613.9 +
  613.10 +bool ColorButton::isRegistered = false;
  613.11 +
  613.12 +/////////////////////////////////////////////////////////////////////////////
  613.13 +// ColorButton
  613.14 +
  613.15 +ColorButton::ColorButton()
  613.16 +{
  613.17 +  color = 0;
  613.18 +  registerClass();
  613.19 +}
  613.20 +
  613.21 +ColorButton::~ColorButton()
  613.22 +{
  613.23 +}
  613.24 +
  613.25 +
  613.26 +BEGIN_MESSAGE_MAP(ColorButton, CButton)
  613.27 +  //{{AFX_MSG_MAP(ColorButton)
  613.28 +  // NOTE - the ClassWizard will add and remove mapping macros here.
  613.29 +  //}}AFX_MSG_MAP
  613.30 +  END_MESSAGE_MAP()
  613.31 +
  613.32 +  /////////////////////////////////////////////////////////////////////////////
  613.33 +// ColorButton message handlers
  613.34 +
  613.35 +void ColorButton::PreSubclassWindow()
  613.36 +{
  613.37 +  SetWindowLong(m_hWnd, GWL_STYLE, GetStyle() | BS_OWNERDRAW);
  613.38 +  CWnd::PreSubclassWindow();
  613.39 +}
  613.40 +
  613.41 +void ColorButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  613.42 +{
  613.43 +  ASSERT(lpDrawItemStruct);
  613.44 +  
  613.45 +  int r = (color & 0x1f) << 3;
  613.46 +  int g = (color & 0x3e0) >> 2;
  613.47 +  int b = (color & 0x7c00) >> 7;
  613.48 +
  613.49 +  HDC dc = lpDrawItemStruct->hDC;
  613.50 +  UINT state = lpDrawItemStruct->itemState;
  613.51 +  RECT rect = lpDrawItemStruct->rcItem;
  613.52 +
  613.53 +  SIZE margins;
  613.54 +  margins.cx = ::GetSystemMetrics(SM_CXEDGE);
  613.55 +  margins.cy = ::GetSystemMetrics(SM_CYEDGE);
  613.56 +
  613.57 +  if(GetState() & BST_PUSHED)
  613.58 +    DrawEdge(dc, &rect, EDGE_SUNKEN, BF_RECT);
  613.59 +  else
  613.60 +    DrawEdge(dc, &rect, EDGE_RAISED, BF_RECT);
  613.61 +
  613.62 +  InflateRect(&rect, -margins.cx, -margins.cy);
  613.63 +  
  613.64 +  HBRUSH br = CreateSolidBrush((state & ODS_DISABLED) ? 
  613.65 +                               ::GetSysColor(COLOR_3DFACE) : RGB(r,g,b));
  613.66 +
  613.67 +  FillRect(dc, &rect, br);
  613.68 +
  613.69 +  if(state & ODS_FOCUS) {
  613.70 +    InflateRect(&rect, -1, -1);
  613.71 +    DrawFocusRect(dc, &rect);
  613.72 +  }
  613.73 +  
  613.74 +  DeleteObject(br);
  613.75 +}
  613.76 +
  613.77 +void ColorButton::setColor(u16 c)
  613.78 +{
  613.79 +  color = c;
  613.80 +  Invalidate();
  613.81 +}
  613.82 +
  613.83 +void ColorButton::registerClass()
  613.84 +{
  613.85 +  if(!isRegistered) {
  613.86 +    WNDCLASS wc;
  613.87 +    ZeroMemory(&wc, sizeof(wc));
  613.88 +    wc.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
  613.89 +    wc.lpfnWndProc = (WNDPROC)::DefWindowProc;
  613.90 +    wc.hInstance = AfxGetInstanceHandle();
  613.91 +    wc.hIcon = LoadCursor(NULL, IDC_ARROW);
  613.92 +    wc.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH);
  613.93 +    wc.lpszMenuName = NULL;
  613.94 +    wc.lpszClassName = "VbaColorButton";
  613.95 +    AfxRegisterClass(&wc);
  613.96 +    isRegistered = true;
  613.97 +  }
  613.98 +}
   614.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   614.2 +++ b/src/win32/ColorButton.h	Sat Mar 03 10:31:27 2012 -0600
   614.3 @@ -0,0 +1,54 @@
   614.4 +#if !defined(AFX_COLORBUTTON_H__DF02109B_B91C_49FD_954F_74A48B83C314__INCLUDED_)
   614.5 +#define AFX_COLORBUTTON_H__DF02109B_B91C_49FD_954F_74A48B83C314__INCLUDED_
   614.6 +
   614.7 +#if _MSC_VER > 1000
   614.8 +#pragma once
   614.9 +#endif // _MSC_VER > 1000
  614.10 +// ColorButton.h : header file
  614.11 +//
  614.12 +
  614.13 +/////////////////////////////////////////////////////////////////////////////
  614.14 +// ColorButton window
  614.15 +
  614.16 +class ColorButton : public CButton
  614.17 +{
  614.18 +	// Construction
  614.19 +public:
  614.20 +	ColorButton();
  614.21 +
  614.22 +	// Attributes
  614.23 +public:
  614.24 +	// Operations
  614.25 +	static bool isRegistered;
  614.26 +public:
  614.27 +	void PreSubclassWindow();
  614.28 +	void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  614.29 +
  614.30 +	// Overrides
  614.31 +	// ClassWizard generated virtual function overrides
  614.32 +	//{{AFX_VIRTUAL(ColorButton)
  614.33 +	//}}AFX_VIRTUAL
  614.34 +
  614.35 +	// Implementation
  614.36 +public:
  614.37 +	void setColor(u16 c);
  614.38 +	u16 color;
  614.39 +	virtual ~ColorButton();
  614.40 +
  614.41 +	void registerClass();
  614.42 +
  614.43 +	// Generated message map functions
  614.44 +protected:
  614.45 +	//{{AFX_MSG(ColorButton)
  614.46 +	// NOTE - the ClassWizard will add and remove member functions here.
  614.47 +	//}}AFX_MSG
  614.48 +
  614.49 +	DECLARE_MESSAGE_MAP()
  614.50 +};
  614.51 +
  614.52 +/////////////////////////////////////////////////////////////////////////////
  614.53 +
  614.54 +//{{AFX_INSERT_LOCATION}}
  614.55 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  614.56 +
  614.57 +#endif // !defined(AFX_COLORBUTTON_H__DF02109B_B91C_49FD_954F_74A48B83C314__INCLUDED_)
   615.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   615.2 +++ b/src/win32/ColorControl.cpp	Sat Mar 03 10:31:27 2012 -0600
   615.3 @@ -0,0 +1,78 @@
   615.4 +// ColorControl.cpp : implementation file
   615.5 +//
   615.6 +
   615.7 +#include "stdafx.h"
   615.8 +#include "ColorControl.h"
   615.9 +
  615.10 +bool ColorControl::isRegistered = false;
  615.11 +
  615.12 +/////////////////////////////////////////////////////////////////////////////
  615.13 +// ColorControl
  615.14 +
  615.15 +ColorControl::ColorControl()
  615.16 +{
  615.17 +  color = 0;
  615.18 +  registerClass();
  615.19 +}
  615.20 +
  615.21 +ColorControl::~ColorControl()
  615.22 +{
  615.23 +}
  615.24 +
  615.25 +
  615.26 +BEGIN_MESSAGE_MAP(ColorControl, CWnd)
  615.27 +  //{{AFX_MSG_MAP(ColorControl)
  615.28 +  ON_WM_PAINT()
  615.29 +  ON_WM_ERASEBKGND()
  615.30 +  //}}AFX_MSG_MAP
  615.31 +  END_MESSAGE_MAP()
  615.32 +
  615.33 +
  615.34 +  /////////////////////////////////////////////////////////////////////////////
  615.35 +// ColorControl message handlers
  615.36 +
  615.37 +void ColorControl::OnPaint() 
  615.38 +{
  615.39 +  CPaintDC dc(this); // device context for painting
  615.40 +}
  615.41 +
  615.42 +BOOL ColorControl::OnEraseBkgnd(CDC* pDC) 
  615.43 +{
  615.44 +  int r = (color & 0x1f) << 3;
  615.45 +  int g = (color & 0x3e0) >> 2;
  615.46 +  int b = (color & 0x7c00) >> 7;
  615.47 +
  615.48 +  CBrush br;
  615.49 +  br.CreateSolidBrush(RGB(r,g,b));
  615.50 +
  615.51 +  RECT rect;
  615.52 +  GetClientRect(&rect);
  615.53 +  pDC->FillRect(&rect,&br);
  615.54 +  pDC->DrawEdge(&rect, EDGE_SUNKEN, BF_RECT);
  615.55 +  br.DeleteObject();
  615.56 +  return TRUE;
  615.57 +}
  615.58 +
  615.59 +void ColorControl::setColor(u16 c)
  615.60 +{
  615.61 +  color = c;
  615.62 +  Invalidate();
  615.63 +}
  615.64 +
  615.65 +void ColorControl::registerClass()
  615.66 +{
  615.67 +  if(!isRegistered) {
  615.68 +    WNDCLASS wc;
  615.69 +    ZeroMemory(&wc, sizeof(wc));
  615.70 +    wc.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
  615.71 +    wc.lpfnWndProc = (WNDPROC)::DefWindowProc;
  615.72 +    wc.hInstance = AfxGetInstanceHandle();
  615.73 +    wc.hIcon = NULL;
  615.74 +    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  615.75 +    wc.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH);
  615.76 +    wc.lpszMenuName = NULL;
  615.77 +    wc.lpszClassName = "VbaColorControl";
  615.78 +    AfxRegisterClass(&wc);
  615.79 +    isRegistered = true;
  615.80 +  }
  615.81 +}
   616.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   616.2 +++ b/src/win32/ColorControl.h	Sat Mar 03 10:31:27 2012 -0600
   616.3 @@ -0,0 +1,53 @@
   616.4 +#if !defined(AFX_COLORCONTROL_H__747E1E47_DDFA_4D67_B337_A473F2BACB86__INCLUDED_)
   616.5 +#define AFX_COLORCONTROL_H__747E1E47_DDFA_4D67_B337_A473F2BACB86__INCLUDED_
   616.6 +
   616.7 +#if _MSC_VER > 1000
   616.8 +#pragma once
   616.9 +#endif // _MSC_VER > 1000
  616.10 +// ColorControl.h : header file
  616.11 +//
  616.12 +
  616.13 +/////////////////////////////////////////////////////////////////////////////
  616.14 +// ColorControl window
  616.15 +
  616.16 +class ColorControl : public CWnd
  616.17 +{
  616.18 +	// Construction
  616.19 +public:
  616.20 +	ColorControl();
  616.21 +
  616.22 +	// Attributes
  616.23 +public:
  616.24 +	// Operations
  616.25 +	static bool isRegistered;
  616.26 +
  616.27 +	// Operations
  616.28 +public:
  616.29 +	// Overrides
  616.30 +	// ClassWizard generated virtual function overrides
  616.31 +	//{{AFX_VIRTUAL(ColorControl)
  616.32 +	//}}AFX_VIRTUAL
  616.33 +
  616.34 +	// Implementation
  616.35 +public:
  616.36 +	void setColor(u16 c);
  616.37 +	u16 color;
  616.38 +	virtual ~ColorControl();
  616.39 +
  616.40 +	// Generated message map functions
  616.41 +protected:
  616.42 +	//{{AFX_MSG(ColorControl)
  616.43 +	afx_msg void OnPaint();
  616.44 +	afx_msg BOOL OnEraseBkgnd(CDC*pDC);
  616.45 +	//}}AFX_MSG
  616.46 +	DECLARE_MESSAGE_MAP()
  616.47 +private:
  616.48 +	void registerClass();
  616.49 +};
  616.50 +
  616.51 +/////////////////////////////////////////////////////////////////////////////
  616.52 +
  616.53 +//{{AFX_INSERT_LOCATION}}
  616.54 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  616.55 +
  616.56 +#endif // !defined(AFX_COLORCONTROL_H__747E1E47_DDFA_4D67_B337_A473F2BACB86__INCLUDED_)
   617.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   617.2 +++ b/src/win32/Commands.cpp	Sat Mar 03 10:31:27 2012 -0600
   617.3 @@ -0,0 +1,75 @@
   617.4 +#include "stdafx.h"
   617.5 +#include <afxres.h>
   617.6 +#include "resource.h"
   617.7 +#include "AcceleratorManager.h"
   617.8 +
   617.9 +#ifndef CMapStringToWord
  617.10 +typedef CMap< CString, LPCSTR, WORD, WORD & > CMapStringToWord;
  617.11 +#endif
  617.12 +
  617.13 +static CMapStringToWord winAccelStrings;
  617.14 +static bool initialized = false;
  617.15 +
  617.16 +struct
  617.17 +{
  617.18 +	const char *command;
  617.19 +	WORD        id;
  617.20 +} winAccelCommands[] = {
  617.21 +	{	"Minimize",				ID_SYSTEM_MINIMIZE	},
  617.22 +	{	"Maximize",				ID_SYSTEM_MAXIMIZE	},
  617.23 +};
  617.24 +
  617.25 +void winAccelAddCommandsFromTable(CAcceleratorManager &mgr)
  617.26 +{
  617.27 +	int count = sizeof(winAccelCommands)/sizeof(winAccelCommands[0]);
  617.28 +
  617.29 +	for (int i = 0; i < count; i++)
  617.30 +	{
  617.31 +		if (!mgr.AddCommandAccel(winAccelCommands[i].id, winAccelCommands[i].command, false))
  617.32 +			mgr.CreateEntry(winAccelCommands[i].id, winAccelCommands[i].command);
  617.33 +	}
  617.34 +}
  617.35 +
  617.36 +// recursive calls
  617.37 +void winAccelAddCommandsFromMenu(CAcceleratorManager &mgr, CMenu *pMenu, const CString &parentStr)
  617.38 +{
  617.39 +	UINT nIndexMax = pMenu->GetMenuItemCount();
  617.40 +	for (UINT nIndex = 0; nIndex < nIndexMax; ++nIndex)
  617.41 +	{
  617.42 +		UINT nID = pMenu->GetMenuItemID(nIndex);
  617.43 +		if (nID == 0)
  617.44 +			continue; // menu separator or invalid cmd - ignore it
  617.45 +
  617.46 +		if (nID == (UINT)-1)
  617.47 +		{
  617.48 +			// possibly a submenu
  617.49 +			CMenu *pSubMenu = pMenu->GetSubMenu(nIndex);
  617.50 +			if (pSubMenu != NULL)
  617.51 +			{
  617.52 +				CString tempStr;
  617.53 +				pMenu->GetMenuString(nIndex, tempStr, MF_BYPOSITION);
  617.54 +				tempStr.Remove('&');
  617.55 +				winAccelAddCommandsFromMenu(mgr, pSubMenu, parentStr + '\\' + tempStr);
  617.56 +			}
  617.57 +		}
  617.58 +		else
  617.59 +		{
  617.60 +			// normal menu item
  617.61 +			// generate the strings
  617.62 +			CString command;
  617.63 +			pMenu->GetMenuString(nIndex, command, MF_BYPOSITION);
  617.64 +			int nPos = command.ReverseFind('\t');
  617.65 +			if (nPos != -1)
  617.66 +			{
  617.67 +				command.Delete(nPos, command.GetLength() - nPos);
  617.68 +			}
  617.69 +			command.Remove('&');
  617.70 +			command = parentStr + '\\' + command;
  617.71 +			if (!mgr.AddCommandAccel(nID, command, false))
  617.72 +			{
  617.73 +				mgr.CreateEntry(nID, command);
  617.74 +			}
  617.75 +		}
  617.76 +	}
  617.77 +}
  617.78 +
   618.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   618.2 +++ b/src/win32/Direct3D.cpp	Sat Mar 03 10:31:27 2012 -0600
   618.3 @@ -0,0 +1,752 @@
   618.4 +#include "stdafx.h"
   618.5 +
   618.6 +#define DIRECT3D_VERSION 0x0800
   618.7 +#include "d3d8.h"
   618.8 +#include "d3dx8.h"
   618.9 +
  618.10 +#include "resource.h"
  618.11 +#include "MainWnd.h"
  618.12 +#include "Reg.h"
  618.13 +#include "VBA.h"
  618.14 +
  618.15 +//#include "../common/System.h"
  618.16 +#include "../gba/GBAGlobals.h"
  618.17 +#include "../gb/gbGlobals.h"
  618.18 +#include "../common/Text.h"
  618.19 +#include "../version.h"
  618.20 +
  618.21 +#ifdef MMX
  618.22 +extern "C" bool cpu_mmx;
  618.23 +
  618.24 +extern bool detectMMX();
  618.25 +#endif
  618.26 +
  618.27 +extern int Init_2xSaI(u32);
  618.28 +extern void directXMessage(const char *);
  618.29 +extern void winlog(const char *, ...);
  618.30 +
  618.31 +typedef struct _D3DTLVERTEX
  618.32 +{
  618.33 +	float    sx; /* Screen coordinates */
  618.34 +	float    sy;
  618.35 +	float    sz;
  618.36 +	float    rhw; /* Reciprocal of homogeneous w */
  618.37 +	D3DCOLOR color; /* Vertex color */
  618.38 +	float    tu; /* Texture coordinates */
  618.39 +	float    tv;
  618.40 +	_D3DTLVERTEX() { }
  618.41 +	_D3DTLVERTEX(const D3DVECTOR& v, float _rhw,
  618.42 +	             D3DCOLOR _color,
  618.43 +	             float _tu, float _tv)
  618.44 +	{
  618.45 +		sx    = v.x; sy = v.y; sz = v.z; rhw = _rhw;
  618.46 +		color = _color;
  618.47 +		tu    = _tu; tv = _tv;
  618.48 +	}
  618.49 +} D3DTLVERTEX, *LPD3DTLVERTEX;
  618.50 +
  618.51 +#define D3DFVF_TLVERTEX D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1
  618.52 +
  618.53 +class Direct3DDisplay : public IDisplay
  618.54 +{
  618.55 +public:
  618.56 +	Direct3DDisplay();
  618.57 +	virtual ~Direct3DDisplay();
  618.58 +
  618.59 +	virtual bool initialize();
  618.60 +	virtual void cleanup();
  618.61 +	virtual void render();
  618.62 +	virtual void checkFullScreen();
  618.63 +	virtual void renderMenu();
  618.64 +	virtual void clear();
  618.65 +	virtual bool changeRenderSize(int w, int h);
  618.66 +	virtual void resize(int w, int h);
  618.67 +	virtual DISPLAY_TYPE getType() { return DIRECT_3D; };
  618.68 +	virtual void setOption(const char *, int);
  618.69 +	virtual int selectFullScreenMode(GUID * *);
  618.70 +
  618.71 +private:
  618.72 +	HINSTANCE             d3dDLL;
  618.73 +	LPDIRECT3D8           pD3D;
  618.74 +	LPDIRECT3DDEVICE8     pDevice;
  618.75 +	LPDIRECT3DTEXTURE8    pTexture;
  618.76 +	D3DSURFACE_DESC       dsdBackBuffer;
  618.77 +	D3DPRESENT_PARAMETERS dpp;
  618.78 +	D3DFORMAT             screenFormat;
  618.79 +	int  width;
  618.80 +	int  height;
  618.81 +	bool filterDisabled;
  618.82 +	ID3DXFont *pFont;
  618.83 +	bool       failed;
  618.84 +	unsigned int textureSize;
  618.85 +	D3DTLVERTEX verts[4];
  618.86 +
  618.87 +
  618.88 +	void restoreDeviceObjects();
  618.89 +	void invalidateDeviceObjects();
  618.90 +	bool initializeOffscreen(int w, int h);
  618.91 +	void updateFiltering(int);
  618.92 +	void calculateVertices();
  618.93 +};
  618.94 +
  618.95 +Direct3DDisplay::Direct3DDisplay()
  618.96 +{
  618.97 +	d3dDLL         = NULL;
  618.98 +	pD3D           = NULL;
  618.99 +	pDevice        = NULL;
 618.100 +	pTexture       = NULL;
 618.101 +	pFont          = NULL;
 618.102 +	screenFormat   = D3DFMT_R5G6B5;
 618.103 +	width          = 0;
 618.104 +	height         = 0;
 618.105 +	filterDisabled = false;
 618.106 +	failed         = false;
 618.107 +	textureSize    = 0;
 618.108 +}
 618.109 +
 618.110 +Direct3DDisplay::~Direct3DDisplay()
 618.111 +{
 618.112 +	cleanup();
 618.113 +}
 618.114 +
 618.115 +void Direct3DDisplay::cleanup()
 618.116 +{
 618.117 +	if (pD3D != NULL)
 618.118 +	{
 618.119 +		if (pFont)
 618.120 +		{
 618.121 +			pFont->Release();
 618.122 +			pFont = NULL;
 618.123 +		}
 618.124 +
 618.125 +		if (pTexture)
 618.126 +		{
 618.127 +			pTexture->Release();
 618.128 +			pTexture = NULL;
 618.129 +		}
 618.130 +
 618.131 +		if (pDevice)
 618.132 +		{
 618.133 +			pDevice->Release();
 618.134 +			pDevice = NULL;
 618.135 +		}
 618.136 +
 618.137 +		pD3D->Release();
 618.138 +		pD3D = NULL;
 618.139 +
 618.140 +		if (d3dDLL != NULL)
 618.141 +		{
 618.142 +			FreeLibrary(d3dDLL);
 618.143 +			d3dDLL = NULL;
 618.144 +		}
 618.145 +	}
 618.146 +}
 618.147 +
 618.148 +bool Direct3DDisplay::initialize()
 618.149 +{
 618.150 +	CWnd *pWnd = theApp.m_pMainWnd;
 618.151 +
 618.152 +	d3dDLL = LoadLibrary("D3D8.DLL");
 618.153 +	LPDIRECT3D8 (WINAPI *D3DCreate)(UINT);
 618.154 +	if (d3dDLL != NULL)
 618.155 +	{
 618.156 +		D3DCreate = (LPDIRECT3D8 (WINAPI *)(UINT))
 618.157 +		            GetProcAddress(d3dDLL, "Direct3DCreate8");
 618.158 +
 618.159 +		if (D3DCreate == NULL)
 618.160 +		{
 618.161 +			directXMessage("Direct3DCreate8");
 618.162 +			return FALSE;
 618.163 +		}
 618.164 +	}
 618.165 +	else
 618.166 +	{
 618.167 +		directXMessage("D3D8.DLL");
 618.168 +		return FALSE;
 618.169 +	}
 618.170 +
 618.171 +	pD3D = D3DCreate(120);
 618.172 +
 618.173 +	if (pD3D == NULL)
 618.174 +	{
 618.175 +		winlog("Error creating Direct3D object\n");
 618.176 +		return FALSE;
 618.177 +	}
 618.178 +
 618.179 +	theApp.mode320Available = false;
 618.180 +	theApp.mode640Available = false;
 618.181 +	theApp.mode800Available = false;
 618.182 +
 618.183 +	D3DDISPLAYMODE mode;
 618.184 +	pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode);
 618.185 +
 618.186 +	switch (mode.Format)
 618.187 +	{
 618.188 +	case D3DFMT_R8G8B8:
 618.189 +		systemColorDepth = 24;
 618.190 +		systemRedShift   = 19;
 618.191 +		systemGreenShift = 11;
 618.192 +		systemBlueShift  = 3;
 618.193 +		break;
 618.194 +	case D3DFMT_X8R8G8B8:
 618.195 +		systemColorDepth = 32;
 618.196 +		systemRedShift   = 19;
 618.197 +		systemGreenShift = 11;
 618.198 +		systemBlueShift  = 3;
 618.199 +		Init_2xSaI(32);
 618.200 +		break;
 618.201 +	case D3DFMT_R5G6B5:
 618.202 +		systemColorDepth = 16;
 618.203 +		systemRedShift   = 11;
 618.204 +		systemGreenShift = 6;
 618.205 +		systemBlueShift  = 0;
 618.206 +		Init_2xSaI(565);
 618.207 +		break;
 618.208 +	case D3DFMT_X1R5G5B5:
 618.209 +		systemColorDepth = 16;
 618.210 +		systemRedShift   = 10;
 618.211 +		systemGreenShift = 5;
 618.212 +		systemBlueShift  = 0;
 618.213 +		Init_2xSaI(555);
 618.214 +		break;
 618.215 +	default:
 618.216 +		systemMessage(0, "Unsupport D3D format %d", mode.Format);
 618.217 +		return false;
 618.218 +	}
 618.219 +	theApp.fsColorDepth = systemColorDepth;
 618.220 +
 618.221 +#ifdef MMX
 618.222 +	if (!theApp.disableMMX)
 618.223 +		cpu_mmx = theApp.detectMMX();
 618.224 +	else
 618.225 +		cpu_mmx = 0;
 618.226 +#endif
 618.227 +
 618.228 +	screenFormat = mode.Format;
 618.229 +
 618.230 +	// check for available fullscreen modes
 618.231 +	ZeroMemory(&dpp, sizeof(dpp));
 618.232 +	dpp.Windowed         = TRUE;
 618.233 +	dpp.BackBufferFormat = mode.Format;
 618.234 +	dpp.BackBufferCount  = 1;
 618.235 +	dpp.SwapEffect       = D3DSWAPEFFECT_DISCARD;
 618.236 +	dpp.BackBufferWidth  = theApp.surfaceSizeX;
 618.237 +	dpp.BackBufferHeight = theApp.surfaceSizeY;
 618.238 +
 618.239 +	HRESULT hret = pD3D->CreateDevice(D3DADAPTER_DEFAULT,
 618.240 +	                                  D3DDEVTYPE_HAL,
 618.241 +	                                  pWnd->GetSafeHwnd(),
 618.242 +	                                  D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE,
 618.243 +	                                  &dpp,
 618.244 +	                                  &pDevice);
 618.245 +	if (!SUCCEEDED(hret))
 618.246 +	{
 618.247 +		winlog("Error creating Direct3DDevice %08x\n", hret);
 618.248 +		return false;
 618.249 +	}
 618.250 +
 618.251 +	restoreDeviceObjects();
 618.252 +
 618.253 +	switch (systemColorDepth)
 618.254 +	{
 618.255 +	case 16:
 618.256 +	{
 618.257 +		for (int i = 0; i < 0x10000; i++)
 618.258 +		{
 618.259 +			systemColorMap16[i] = ((i & 0x1f) << systemRedShift) |
 618.260 +			                      (((i & 0x3e0) >> 5) << systemGreenShift) |
 618.261 +			                      (((i & 0x7c00) >> 10) << systemBlueShift);
 618.262 +		}
 618.263 +		break;
 618.264 +	}
 618.265 +	case 24:
 618.266 +	case 32:
 618.267 +	{
 618.268 +		for (int i = 0; i < 0x10000; i++)
 618.269 +		{
 618.270 +			systemColorMap32[i] = ((i & 0x1f) << systemRedShift) |
 618.271 +			                      (((i & 0x3e0) >> 5) << systemGreenShift) |
 618.272 +			                      (((i & 0x7c00) >> 10) << systemBlueShift);
 618.273 +		}
 618.274 +		break;
 618.275 +	}
 618.276 +	}
 618.277 +
 618.278 +	theApp.updateFilter();
 618.279 +	theApp.updateIFB();
 618.280 +
 618.281 +	if (failed)
 618.282 +		return false;
 618.283 +
 618.284 +	pWnd->DragAcceptFiles(TRUE);
 618.285 +
 618.286 +	return TRUE;
 618.287 +}
 618.288 +
 618.289 +bool Direct3DDisplay::initializeOffscreen(int w, int h)
 618.290 +{
 618.291 +	int size = 256;
 618.292 +	if (w > 512 || h > 512)
 618.293 +		size = 1024;
 618.294 +	else if (w > 256 || h > 256)
 618.295 +		size = 512;
 618.296 +	textureSize = size;
 618.297 +
 618.298 +	UINT      ww     = size;
 618.299 +	UINT      hh     = size;
 618.300 +	D3DFORMAT format = screenFormat;
 618.301 +
 618.302 +	if (SUCCEEDED(D3DXCheckTextureRequirements(pDevice,
 618.303 +	                                           &ww,
 618.304 +	                                           &hh,
 618.305 +	                                           NULL,
 618.306 +	                                           0,
 618.307 +	                                           &format,
 618.308 +	                                           D3DPOOL_MANAGED)))
 618.309 +	{
 618.310 +		if ((int)ww < w || (int)hh < h)
 618.311 +		{
 618.312 +			if (theApp.filterFunction)
 618.313 +			{
 618.314 +				filterDisabled        = true;
 618.315 +				theApp.filterFunction = NULL;
 618.316 +				systemMessage(0, "3D card cannot support needed texture size for filter function. Disabling it");
 618.317 +			}
 618.318 +		}
 618.319 +		else
 618.320 +			filterDisabled = false;
 618.321 +		if (SUCCEEDED(D3DXCreateTexture(pDevice,
 618.322 +		                                ww,
 618.323 +		                                hh,
 618.324 +		                                0,
 618.325 +		                                0,
 618.326 +		                                format,
 618.327 +		                                D3DPOOL_MANAGED,
 618.328 +		                                &pTexture)))
 618.329 +		{
 618.330 +			width  = w;
 618.331 +			height = h;
 618.332 +			return true;
 618.333 +		}
 618.334 +	}
 618.335 +	return false;
 618.336 +}
 618.337 +
 618.338 +void Direct3DDisplay::updateFiltering(int filter)
 618.339 +{
 618.340 +	switch (filter)
 618.341 +	{
 618.342 +	default:
 618.343 +	case 0:
 618.344 +		// point filtering
 618.345 +		pDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_POINT);
 618.346 +		pDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_POINT);
 618.347 +		pDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_POINT);
 618.348 +		break;
 618.349 +	case 1:
 618.350 +		// bilinear
 618.351 +		pDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
 618.352 +		pDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
 618.353 +		pDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_POINT);
 618.354 +		break;
 618.355 +	}
 618.356 +}
 618.357 +
 618.358 +void Direct3DDisplay::restoreDeviceObjects()
 618.359 +{
 618.360 +	// Store render target surface desc
 618.361 +	LPDIRECT3DSURFACE8 pBackBuffer;
 618.362 +	HRESULT hr;
 618.363 +	if (SUCCEEDED(hr = pDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer)))
 618.364 +	{
 618.365 +		pBackBuffer->GetDesc(&dsdBackBuffer);
 618.366 +		pBackBuffer->Release();
 618.367 +	}
 618.368 +	else
 618.369 +		systemMessage(0, "Failed GetBackBuffer %08x", hr);
 618.370 +
 618.371 +	// Set up the texture
 618.372 +	pDevice->SetTextureStageState(0, D3DTSS_COLOROP,   D3DTOP_MODULATE);
 618.373 +	pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
 618.374 +	pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
 618.375 +
 618.376 +	int filter = regQueryDwordValue("d3dFilter", 0);
 618.377 +	if (filter < 0 || filter > 3)
 618.378 +		filter = 0;
 618.379 +	updateFiltering(filter);
 618.380 +
 618.381 +	// Set miscellaneous render states
 618.382 +	pDevice->SetRenderState(D3DRS_DITHERENABLE,   TRUE);
 618.383 +	pDevice->SetRenderState(D3DRS_ZENABLE,        FALSE);
 618.384 +
 618.385 +	// Set the projection matrix
 618.386 +	D3DXMATRIX matProj;
 618.387 +	FLOAT      fAspect = ((FLOAT)dsdBackBuffer.Width) / dsdBackBuffer.Height;
 618.388 +	D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, fAspect, 1.0f, 100.0f);
 618.389 +	pDevice->SetTransform(D3DTS_PROJECTION, &matProj);
 618.390 +
 618.391 +	// turn off lighting
 618.392 +	pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
 618.393 +
 618.394 +	if (pFont)
 618.395 +	{
 618.396 +		pFont->Release();
 618.397 +		pFont = NULL;
 618.398 +	}
 618.399 +	// Create a D3D font using D3DX
 618.400 +	HFONT hFont = CreateFont(14, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
 618.401 +	                         ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
 618.402 +	                         ANTIALIASED_QUALITY, FF_DONTCARE, "Arial");
 618.403 +	D3DXCreateFont(pDevice, hFont, &pFont);
 618.404 +}
 618.405 +
 618.406 +void Direct3DDisplay::clear()
 618.407 +{}
 618.408 +
 618.409 +void Direct3DDisplay::renderMenu()
 618.410 +{
 618.411 +	checkFullScreen();
 618.412 +	if (theApp.m_pMainWnd)
 618.413 +		theApp.m_pMainWnd->DrawMenuBar();
 618.414 +}
 618.415 +
 618.416 +void Direct3DDisplay::checkFullScreen()
 618.417 +{
 618.418 +	//  if(tripleBuffering)
 618.419 +	//    pDirect3D->FlipToGDISurface();
 618.420 +}
 618.421 +
 618.422 +void Direct3DDisplay::calculateVertices()
 618.423 +{
 618.424 +	// color
 618.425 +	D3DCOLOR col = 0xFFFFFFFF;
 618.426 +
 618.427 +	// calculate rhw
 618.428 +	FLOAT z	  = 1.0f;
 618.429 +	FLOAT rhw = 1.0f / (z * 990.0f + 10.0f);
 618.430 +
 618.431 +	// -0.5f is necessary in order to match texture alignment to display pixels
 618.432 +	FLOAT left     = -0.5f;
 618.433 +	FLOAT right    = dpp.BackBufferWidth - 0.5f;
 618.434 +	FLOAT top      = -0.5f;
 618.435 +	FLOAT bottom   = dpp.BackBufferHeight - 0.5f;
 618.436 +
 618.437 +	FLOAT textureX = (FLOAT)theApp.rect.right / (FLOAT)textureSize;
 618.438 +	FLOAT textureY = (FLOAT)theApp.rect.bottom / (FLOAT)textureSize;
 618.439 +
 618.440 +//#define D3D_DRAW_SINGLE_RECTANGLE
 618.441 +#ifdef D3D_DRAW_SINGLE_RECTANGLE
 618.442 +	// set up a rectangle
 618.443 +	verts[0] = D3DTLVERTEX(D3DXVECTOR3(left,  top,    z), rhw, col, 0.0f,     0.0f);
 618.444 +	verts[1] = D3DTLVERTEX(D3DXVECTOR3(right, top,    z), rhw, col, textureX, 0.0f);
 618.445 +	verts[2] = D3DTLVERTEX(D3DXVECTOR3(right, bottom, z), rhw, col, textureX, textureY);
 618.446 +	verts[3] = D3DTLVERTEX(D3DXVECTOR3(left,  bottom, z), rhw, col, 0.0f,     textureY);
 618.447 +#else
 618.448 +	// set up triangles
 618.449 +	verts[0] = D3DTLVERTEX(D3DXVECTOR3(left,  bottom, z), rhw, col, 0.0f,     textureY);
 618.450 +	verts[1] = D3DTLVERTEX(D3DXVECTOR3(left,  top,    z), rhw, col, 0.0f,     0.0f);
 618.451 +	verts[2] = D3DTLVERTEX(D3DXVECTOR3(right, bottom, z), rhw, col, textureX, textureY);
 618.452 +	verts[3] = D3DTLVERTEX(D3DXVECTOR3(right, top,    z), rhw, col, textureX, 0.0f);
 618.453 +#endif
 618.454 +}
 618.455 +
 618.456 +void Direct3DDisplay::render()
 618.457 +{
 618.458 +	if (!pDevice)
 618.459 +		return;
 618.460 +
 618.461 +	// Test the cooperative level to see if it's okay to render
 618.462 +	if (FAILED(pDevice->TestCooperativeLevel()))
 618.463 +	{
 618.464 +		return;
 618.465 +	}
 618.466 +	pDevice->Clear(0L, NULL, D3DCLEAR_TARGET, 0x000000ff, 1.0f, 0L);
 618.467 +
 618.468 +	if (SUCCEEDED(pDevice->BeginScene()))
 618.469 +	{
 618.470 +		D3DLOCKED_RECT locked;
 618.471 +		if (pTexture && SUCCEEDED(pTexture->LockRect(0, &locked, NULL, 0)))
 618.472 +		{
 618.473 +			if (theApp.filterFunction)
 618.474 +			{
 618.475 +				if (systemColorDepth == 16)
 618.476 +					theApp.filterFunction(pix + theApp.filterWidth * 2 + 4,
 618.477 +					                      theApp.filterWidth*2 + 4,
 618.478 +					                      (u8 *)theApp.delta,
 618.479 +					                      (u8 *)locked.pBits,
 618.480 +					                      locked.Pitch,
 618.481 +					                      theApp.filterWidth,
 618.482 +					                      theApp.filterHeight);
 618.483 +				else
 618.484 +					theApp.filterFunction(pix + theApp.filterWidth * 4 + 4,
 618.485 +					                      theApp.filterWidth * 4 + 4,
 618.486 +					                      (u8 *)theApp.delta,
 618.487 +					                      (u8 *)locked.pBits,
 618.488 +					                      locked.Pitch,
 618.489 +					                      theApp.filterWidth,
 618.490 +					                      theApp.filterHeight);
 618.491 +			}
 618.492 +			else
 618.493 +			{
 618.494 +				int copyX = 240;
 618.495 +				int copyY = 160;
 618.496 +
 618.497 +				if (systemCartridgeType == 1)
 618.498 +				{
 618.499 +					if (gbBorderOn)
 618.500 +					{
 618.501 +						copyX = 256;
 618.502 +						copyY = 224;
 618.503 +					}
 618.504 +					else
 618.505 +					{
 618.506 +						copyX = 160;
 618.507 +						copyY = 144;
 618.508 +					}
 618.509 +				}
 618.510 +				// MMX doesn't seem to be faster to copy the data
 618.511 +				__asm {
 618.512 +					mov eax, copyX;
 618.513 +					mov ebx, copyY;
 618.514 +
 618.515 +					mov esi, pix;
 618.516 +					mov edi, locked.pBits;
 618.517 +					mov edx, locked.Pitch;
 618.518 +					cmp systemColorDepth, 16;
 618.519 +					jnz gbaOtherColor;
 618.520 +					sub edx, eax;
 618.521 +					sub edx, eax;
 618.522 +					lea esi, [esi+2*eax+4];
 618.523 +					shr eax, 1;
 618.524 +gbaLoop16bit:
 618.525 +					mov ecx, eax;
 618.526 +					repz movsd;
 618.527 +					inc  esi;
 618.528 +					inc  esi;
 618.529 +					inc  esi;
 618.530 +					inc  esi;
 618.531 +					add  edi, edx;
 618.532 +					dec  ebx;
 618.533 +					jnz  gbaLoop16bit;
 618.534 +					jmp  gbaLoopEnd;
 618.535 +gbaOtherColor:
 618.536 +					cmp systemColorDepth, 32;
 618.537 +					jnz gbaOtherColor2;
 618.538 +
 618.539 +					sub edx, eax;
 618.540 +					sub edx, eax;
 618.541 +					sub edx, eax;
 618.542 +					sub edx, eax;
 618.543 +					lea esi, [esi+4*eax+4];
 618.544 +gbaLoop32bit:
 618.545 +					mov ecx, eax;
 618.546 +					repz movsd;
 618.547 +					add  esi, 4;
 618.548 +					add  edi, edx;
 618.549 +					dec  ebx;
 618.550 +					jnz  gbaLoop32bit;
 618.551 +					jmp  gbaLoopEnd;
 618.552 +gbaOtherColor2:
 618.553 +					lea eax, [eax+2*eax];
 618.554 +					sub edx, eax;
 618.555 +gbaLoop24bit:
 618.556 +					mov ecx, eax;
 618.557 +					shr  ecx, 2;
 618.558 +					repz movsd;
 618.559 +					add  edi, edx;
 618.560 +					dec  ebx;
 618.561 +					jnz  gbaLoop24bit;
 618.562 +gbaLoopEnd:
 618.563 +				}
 618.564 +			}
 618.565 +
 618.566 +			if (theApp.videoOption > VIDEO_4X && theApp.showSpeed)
 618.567 +			{
 618.568 +				char buffer[30];
 618.569 +				if (theApp.showSpeed == 1)
 618.570 +					sprintf(buffer, "%3d%%", systemSpeed);
 618.571 +				else
 618.572 +					sprintf(buffer, "%3d%%(%d, %d fps)", systemSpeed,
 618.573 +					        systemFrameSkip,
 618.574 +					        theApp.showRenderedFrames);
 618.575 +				if (theApp.showSpeedTransparent)
 618.576 +					drawTextTransp((u8 *)locked.pBits,
 618.577 +					               locked.Pitch,
 618.578 +					               theApp.rect.left+10,
 618.579 +					               theApp.rect.bottom-10,
 618.580 +					               buffer);
 618.581 +				else
 618.582 +					drawText((u8 *)locked.pBits,
 618.583 +					         locked.Pitch,
 618.584 +					         theApp.rect.left+10,
 618.585 +					         theApp.rect.bottom-10,
 618.586 +					         buffer);
 618.587 +			}
 618.588 +
 618.589 +			if (textMethod == 1)
 618.590 +			{
 618.591 +				DrawTextMessages((u8 *)locked.pBits, locked.Pitch, theApp.rect.left, theApp.rect.bottom);
 618.592 +			}
 618.593 +
 618.594 +			pTexture->UnlockRect(0);
 618.595 +
 618.596 +			// set the texture
 618.597 +			pDevice->SetTexture(0, pTexture);
 618.598 +
 618.599 +			// configure shader for vertex type
 618.600 +			pDevice->SetVertexShader(D3DFVF_TLVERTEX);
 618.601 +
 618.602 +#ifdef D3D_DRAW_SINGLE_RECTANGLE
 618.603 +			// draw the rectangle
 618.604 +				pDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, verts, sizeof(D3DTLVERTEX));
 618.605 +			//#undef D3D_DRAW_RECT
 618.606 +#else
 618.607 +			// draw the triangles
 618.608 +			pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, verts, sizeof(D3DTLVERTEX));
 618.609 +#endif
 618.610 +		}
 618.611 +
 618.612 +		if (textMethod == 2)
 618.613 +		{
 618.614 +			for (int slot = 0; slot < SCREEN_MESSAGE_SLOTS; slot++)
 618.615 +			{
 618.616 +				if (theApp.screenMessage[slot])
 618.617 +				{
 618.618 +					if ((theApp.screenMessageDuration[slot] < 0 || 
 618.619 +						(int)(GetTickCount() - theApp.screenMessageTime[slot]) < theApp.screenMessageDuration[slot]) &&
 618.620 +					    (!theApp.disableStatusMessage || slot == 1 || slot == 2) && pFont)
 618.621 +					{
 618.622 +						pFont->Begin();
 618.623 +						RECT     r;
 618.624 +						D3DCOLOR color;
 618.625 +
 618.626 +						r.left   = 10;
 618.627 +						r.top    = dpp.BackBufferHeight - 20*(slot+1);
 618.628 +						r.right  = dpp.BackBufferWidth - 10;
 618.629 +						r.bottom = r.top + 20;
 618.630 +
 618.631 +						if (outlinedText)
 618.632 +						{
 618.633 +							color = textColor != 7 ? D3DCOLOR_ARGB(255, 0, 0, 0) : D3DCOLOR_ARGB(255, 255, 255, 255);
 618.634 +
 618.635 +							// draw outline
 618.636 +							const static int xd [8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 618.637 +							const static int yd [8] = {-1, -1, -1, 0, 1, 1, 1, 0};
 618.638 +							for (int i = 0; i < 8; i++)
 618.639 +							{
 618.640 +								RECT r2 = r;
 618.641 +								r2.left += xd[i]; r2.right += xd[i];
 618.642 +								r2.top  += yd[i]; r2.bottom += yd[i];
 618.643 +
 618.644 +								pFont->DrawText(theApp.screenMessageBuffer[slot], -1, &r2, 0, color);
 618.645 +							}
 618.646 +						}
 618.647 +
 618.648 +						// draw center text
 618.649 +						switch (textColor)
 618.650 +						{
 618.651 +						case 0:
 618.652 +							color = D3DCOLOR_ARGB(255, 255, 255, 255); break;
 618.653 +						case 1:
 618.654 +							color = D3DCOLOR_ARGB(255, 255, 0, 0); break;
 618.655 +						case 2:
 618.656 +							color = D3DCOLOR_ARGB(255, 255, 255, 0); break;
 618.657 +						case 3:
 618.658 +							color = D3DCOLOR_ARGB(255, 0, 255, 0); break;
 618.659 +						case 4:
 618.660 +							color = D3DCOLOR_ARGB(255, 0, 255, 255); break;
 618.661 +						case 5:
 618.662 +							color = D3DCOLOR_ARGB(255, 0, 0, 255); break;
 618.663 +						case 6:
 618.664 +							color = D3DCOLOR_ARGB(255, 255, 0, 255); break;
 618.665 +						case 7:
 618.666 +							color = D3DCOLOR_ARGB(255, 0, 0, 0); break;
 618.667 +						}
 618.668 +						pFont->DrawText(theApp.screenMessageBuffer[slot], -1, &r, 0, color);
 618.669 +
 618.670 +						pFont->End();
 618.671 +					}
 618.672 +					else
 618.673 +					{
 618.674 +						theApp.screenMessage[slot] = false;
 618.675 +					}
 618.676 +				}
 618.677 +			}
 618.678 +		}
 618.679 +
 618.680 +		pDevice->EndScene();
 618.681 +
 618.682 +		pDevice->Present(NULL, NULL, NULL, NULL);
 618.683 +	}
 618.684 +}
 618.685 +
 618.686 +void Direct3DDisplay::invalidateDeviceObjects()
 618.687 +{
 618.688 +	if (pFont)
 618.689 +		pFont->Release();
 618.690 +	pFont = NULL;
 618.691 +}
 618.692 +
 618.693 +void Direct3DDisplay::resize(int w, int h)
 618.694 +{
 618.695 +	if (pDevice && w > 0 && h > 0)
 618.696 +	{
 618.697 +		dpp.BackBufferWidth  = w;
 618.698 +		dpp.BackBufferHeight = h;
 618.699 +		HRESULT hr;
 618.700 +		invalidateDeviceObjects();
 618.701 +		if (SUCCEEDED(hr = pDevice->Reset(&dpp)))
 618.702 +		{
 618.703 +			restoreDeviceObjects();
 618.704 +		}
 618.705 +		else
 618.706 +			systemMessage(0, "Failed device reset %08x", hr);
 618.707 +	}
 618.708 +	calculateVertices();
 618.709 +}
 618.710 +
 618.711 +bool Direct3DDisplay::changeRenderSize(int w, int h)
 618.712 +{
 618.713 +	if (w != width || h != height)
 618.714 +	{
 618.715 +		if (pTexture)
 618.716 +		{
 618.717 +			pTexture->Release();
 618.718 +			pTexture = NULL;
 618.719 +		}
 618.720 +		if (!initializeOffscreen(w, h))
 618.721 +		{
 618.722 +			failed = true;
 618.723 +			return false;
 618.724 +		}
 618.725 +	}
 618.726 +	calculateVertices();
 618.727 +
 618.728 +	return true;
 618.729 +}
 618.730 +
 618.731 +void Direct3DDisplay::setOption(const char *option, int value)
 618.732 +{
 618.733 +	if (!strcmp(option, "d3dFilter"))
 618.734 +		updateFiltering(value);
 618.735 +}
 618.736 +
 618.737 +int Direct3DDisplay::selectFullScreenMode(GUID * *)
 618.738 +{
 618.739 +	HWND wnd = GetDesktopWindow();
 618.740 +	RECT r;
 618.741 +	GetWindowRect(wnd, &r);
 618.742 +	int w  = (r.right - r.left) & 4095;
 618.743 +	int h  = (r.bottom - r.top) & 4095;
 618.744 +	HDC dc = GetDC(wnd);
 618.745 +	int c  = GetDeviceCaps(dc, BITSPIXEL);
 618.746 +	ReleaseDC(wnd, dc);
 618.747 +
 618.748 +	return (c << 24) | (w << 12) | h;
 618.749 +}
 618.750 +
 618.751 +IDisplay *newDirect3DDisplay()
 618.752 +{
 618.753 +	return new Direct3DDisplay();
 618.754 +}
 618.755 +
   619.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   619.2 +++ b/src/win32/DirectDraw.cpp	Sat Mar 03 10:31:27 2012 -0600
   619.3 @@ -0,0 +1,921 @@
   619.4 +#include "stdafx.h"
   619.5 +
   619.6 +#define DIRECTDRAW_VERSION 0x0700
   619.7 +#include "ddraw.h"
   619.8 +
   619.9 +#include "resource.h"
  619.10 +#include "MainWnd.h"
  619.11 +#include "Reg.h"
  619.12 +#include "VBA.h"
  619.13 +
  619.14 +#include "../common/System.h"
  619.15 +#include "../gba/GBAGlobals.h"
  619.16 +#include "../gb/gbGlobals.h"
  619.17 +#include "../common/Text.h"
  619.18 +#include "../version.h"
  619.19 +
  619.20 +extern u32 RGB_LOW_BITS_MASK;
  619.21 +extern int systemSpeed;
  619.22 +extern int Init_2xSaI(u32);
  619.23 +extern void directXMessage(const char *);
  619.24 +extern void winlog(const char *, ...);
  619.25 +extern int winVideoModeSelect(CWnd *, GUID * *);
  619.26 +
  619.27 +class DirectDrawDisplay : public IDisplay
  619.28 +{
  619.29 +private:
  619.30 +	HINSTANCE ddrawDLL;
  619.31 +	LPDIRECTDRAW7        pDirectDraw;
  619.32 +	LPDIRECTDRAWSURFACE7 ddsPrimary;
  619.33 +	LPDIRECTDRAWSURFACE7 ddsOffscreen;
  619.34 +	LPDIRECTDRAWSURFACE7 ddsFlip;
  619.35 +	LPDIRECTDRAWCLIPPER  ddsClipper;
  619.36 +	int  width;
  619.37 +	int  height;
  619.38 +	bool failed;
  619.39 +
  619.40 +	bool initializeOffscreen(int w, int h);
  619.41 +public:
  619.42 +	DirectDrawDisplay();
  619.43 +	virtual ~DirectDrawDisplay();
  619.44 +
  619.45 +	virtual bool initialize();
  619.46 +	virtual void cleanup();
  619.47 +	virtual void render();
  619.48 +	virtual void checkFullScreen();
  619.49 +	virtual void renderMenu();
  619.50 +	virtual void clear();
  619.51 +	virtual bool changeRenderSize(int w, int h);
  619.52 +	virtual DISPLAY_TYPE getType() { return DIRECT_DRAW; };
  619.53 +	virtual void setOption(const char *, int) {}
  619.54 +	virtual int selectFullScreenMode(GUID * *);
  619.55 +};
  619.56 +
  619.57 +static HRESULT WINAPI checkModesAvailable(LPDDSURFACEDESC2 surf, LPVOID lpContext)
  619.58 +{
  619.59 +	if (surf->dwWidth == 320 &&
  619.60 +	    surf->dwHeight == 240 &&
  619.61 +	    surf->ddpfPixelFormat.dwRGBBitCount == 16)
  619.62 +	{
  619.63 +		theApp.mode320Available = TRUE;
  619.64 +	}
  619.65 +	if (surf->dwWidth == 640 &&
  619.66 +	    surf->dwHeight == 480 &&
  619.67 +	    surf->ddpfPixelFormat.dwRGBBitCount == 16)
  619.68 +	{
  619.69 +		theApp.mode640Available = TRUE;
  619.70 +	}
  619.71 +	if (surf->dwWidth == 800 &&
  619.72 +	    surf->dwHeight == 600 &&
  619.73 +	    surf->ddpfPixelFormat.dwRGBBitCount == 16)
  619.74 +	{
  619.75 +		theApp.mode800Available = TRUE;
  619.76 +	}
  619.77 +	return DDENUMRET_OK;
  619.78 +}
  619.79 +
  619.80 +static int ffs(UINT mask)
  619.81 +{
  619.82 +	int m = 0;
  619.83 +	if (mask)
  619.84 +	{
  619.85 +		while (!(mask & (1 << m)))
  619.86 +			m++;
  619.87 +
  619.88 +		return (m);
  619.89 +	}
  619.90 +
  619.91 +	return (0);
  619.92 +}
  619.93 +
  619.94 +DirectDrawDisplay::DirectDrawDisplay()
  619.95 +{
  619.96 +	pDirectDraw  = NULL;
  619.97 +	ddsPrimary   = NULL;
  619.98 +	ddsOffscreen = NULL;
  619.99 +	ddsFlip      = NULL;
 619.100 +	ddsClipper   = NULL;
 619.101 +	ddrawDLL     = NULL;
 619.102 +	width        = 0;
 619.103 +	height       = 0;
 619.104 +	failed       = false;
 619.105 +}
 619.106 +
 619.107 +DirectDrawDisplay::~DirectDrawDisplay()
 619.108 +{
 619.109 +	cleanup();
 619.110 +}
 619.111 +
 619.112 +void DirectDrawDisplay::cleanup()
 619.113 +{
 619.114 +	if (pDirectDraw != NULL)
 619.115 +	{
 619.116 +		if (ddsClipper != NULL)
 619.117 +		{
 619.118 +			ddsClipper->Release();
 619.119 +			ddsClipper = NULL;
 619.120 +		}
 619.121 +
 619.122 +		if (ddsFlip != NULL)
 619.123 +		{
 619.124 +			ddsFlip->Release();
 619.125 +			ddsFlip = NULL;
 619.126 +		}
 619.127 +
 619.128 +		if (ddsOffscreen != NULL)
 619.129 +		{
 619.130 +			ddsOffscreen->Release();
 619.131 +			ddsOffscreen = NULL;
 619.132 +		}
 619.133 +
 619.134 +		if (ddsPrimary != NULL)
 619.135 +		{
 619.136 +			ddsPrimary->Release();
 619.137 +			ddsPrimary = NULL;
 619.138 +		}
 619.139 +
 619.140 +		pDirectDraw->Release();
 619.141 +		pDirectDraw = NULL;
 619.142 +	}
 619.143 +
 619.144 +	if (ddrawDLL != NULL)
 619.145 +	{
 619.146 +		/**/ ::FreeLibrary(ddrawDLL);
 619.147 +		ddrawDLL = NULL;
 619.148 +	}
 619.149 +	width  = 0;
 619.150 +	height = 0;
 619.151 +}
 619.152 +
 619.153 +bool DirectDrawDisplay::initialize()
 619.154 +{
 619.155 +	CWnd *pWnd = theApp.m_pMainWnd;
 619.156 +
 619.157 +	GUID *guid = NULL;
 619.158 +	if (theApp.ddrawEmulationOnly)
 619.159 +		guid = (GUID *)DDCREATE_EMULATIONONLY;
 619.160 +
 619.161 +	if (theApp.pVideoDriverGUID)
 619.162 +		guid = theApp.pVideoDriverGUID;
 619.163 +
 619.164 +	ddrawDLL = /**/ ::LoadLibrary("DDRAW.DLL");
 619.165 +	HRESULT (WINAPI *DDrawCreateEx)(GUID *, LPVOID *, REFIID, IUnknown *);
 619.166 +	if (ddrawDLL != NULL)
 619.167 +	{
 619.168 +		DDrawCreateEx = (HRESULT (WINAPI *)(GUID *, LPVOID *, REFIID, IUnknown *))
 619.169 +		                GetProcAddress(ddrawDLL, "DirectDrawCreateEx");
 619.170 +
 619.171 +		if (DDrawCreateEx == NULL)
 619.172 +		{
 619.173 +			directXMessage("DirectDrawCreateEx");
 619.174 +			return FALSE;
 619.175 +		}
 619.176 +	}
 619.177 +	else
 619.178 +	{
 619.179 +		directXMessage("DDRAW.DLL");
 619.180 +		return FALSE;
 619.181 +	}
 619.182 +
 619.183 +	theApp.ddrawUsingEmulationOnly = theApp.ddrawEmulationOnly;
 619.184 +
 619.185 +	HRESULT hret = DDrawCreateEx(guid,
 619.186 +	                             (void * *)&pDirectDraw,
 619.187 +	                             IID_IDirectDraw7,
 619.188 +	                             NULL);
 619.189 +
 619.190 +	if (hret != DD_OK)
 619.191 +	{
 619.192 +		winlog("Error creating DirectDraw object %08x\n", hret);
 619.193 +		if (theApp.ddrawEmulationOnly)
 619.194 +		{
 619.195 +			// disable emulation only setting in case of failure
 619.196 +			regSetDwordValue("ddrawEmulationOnly", 0);
 619.197 +		}
 619.198 +		//    errorMessage(myLoadString(IDS_ERROR_DISP_DRAWCREATE), hret);
 619.199 +		return FALSE;
 619.200 +	}
 619.201 +
 619.202 +	if (theApp.ddrawDebug)
 619.203 +	{
 619.204 +		DDCAPS driver;
 619.205 +		DDCAPS hel;
 619.206 +		ZeroMemory(&driver, sizeof(driver));
 619.207 +		ZeroMemory(&hel, sizeof(hel));
 619.208 +		driver.dwSize = sizeof(driver);
 619.209 +		hel.dwSize    = sizeof(hel);
 619.210 +		pDirectDraw->GetCaps(&driver, &hel);
 619.211 +		int    i;
 619.212 +		DWORD *p = (DWORD *)&driver;
 619.213 +		for (i = 0; i < (int)driver.dwSize; i += 4)
 619.214 +			winlog("Driver CAPS %2d: %08x\n", i>>2, *p++);
 619.215 +		p = (DWORD *)&hel;
 619.216 +		for (i = 0; i < (int)hel.dwSize; i += 4)
 619.217 +			winlog("HEL CAPS %2d: %08x\n", i>>2, *p++);
 619.218 +	}
 619.219 +
 619.220 +	theApp.mode320Available = false;
 619.221 +	theApp.mode640Available = false;
 619.222 +	theApp.mode800Available = false;
 619.223 +
 619.224 +	// check for available fullscreen modes
 619.225 +	pDirectDraw->EnumDisplayModes(DDEDM_STANDARDVGAMODES, NULL, NULL, checkModesAvailable);
 619.226 +
 619.227 +	DWORD flags = DDSCL_NORMAL;
 619.228 +
 619.229 +	if (theApp.videoOption >= VIDEO_320x240)
 619.230 +		flags = DDSCL_ALLOWMODEX |
 619.231 +		        DDSCL_ALLOWREBOOT |
 619.232 +		        DDSCL_EXCLUSIVE |
 619.233 +		        DDSCL_FULLSCREEN;
 619.234 +
 619.235 +	hret = pDirectDraw->SetCooperativeLevel(pWnd->m_hWnd, flags);
 619.236 +
 619.237 +	if (hret != DD_OK)
 619.238 +	{
 619.239 +		winlog("Error SetCooperativeLevel %08x\n", hret);
 619.240 +		//    errorMessage(myLoadString(IDS_ERROR_DISP_DRAWLEVEL), hret);
 619.241 +		return FALSE;
 619.242 +	}
 619.243 +
 619.244 +	if (theApp.videoOption > VIDEO_4X)
 619.245 +	{
 619.246 +		hret = pDirectDraw->SetDisplayMode(theApp.fsWidth,
 619.247 +		                                   theApp.fsHeight,
 619.248 +		                                   theApp.fsColorDepth,
 619.249 +		                                   0,
 619.250 +		                                   0);
 619.251 +		if (hret != DD_OK)
 619.252 +		{
 619.253 +			winlog("Error SetDisplayMode %08x\n", hret);
 619.254 +			//      errorMessage(myLoadString(IDS_ERROR_DISP_DRAWSET), hret);
 619.255 +			return FALSE;
 619.256 +		}
 619.257 +	}
 619.258 +
 619.259 +	DDSURFACEDESC2 ddsd;
 619.260 +	ZeroMemory(&ddsd, sizeof(ddsd));
 619.261 +	ddsd.dwSize         = sizeof(ddsd);
 619.262 +	ddsd.dwFlags        = DDSD_CAPS;
 619.263 +	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
 619.264 +
 619.265 +	if (theApp.videoOption > VIDEO_4X && theApp.tripleBuffering)
 619.266 +	{
 619.267 +		// setup triple buffering
 619.268 +		ddsd.dwFlags		  |= DDSD_BACKBUFFERCOUNT;
 619.269 +		ddsd.ddsCaps.dwCaps   |= DDSCAPS_COMPLEX | DDSCAPS_FLIP;
 619.270 +		ddsd.dwBackBufferCount = 2;
 619.271 +	}
 619.272 +
 619.273 +	hret = pDirectDraw->CreateSurface(&ddsd, &ddsPrimary, NULL);
 619.274 +	if (hret != DD_OK)
 619.275 +	{
 619.276 +		winlog("Error primary CreateSurface %08x\n", hret);
 619.277 +		//    errorMessage(myLoadString(IDS_ERROR_DISP_DRAWSURFACE), hret);
 619.278 +		return FALSE;
 619.279 +	}
 619.280 +
 619.281 +	if (theApp.ddrawDebug)
 619.282 +	{
 619.283 +		DDSCAPS2 caps;
 619.284 +		ZeroMemory(&caps, sizeof(caps));
 619.285 +		ddsPrimary->GetCaps(&caps);
 619.286 +
 619.287 +		winlog("Primary CAPS 1: %08x\n", caps.dwCaps);
 619.288 +		winlog("Primary CAPS 2: %08x\n", caps.dwCaps2);
 619.289 +		winlog("Primary CAPS 3: %08x\n", caps.dwCaps3);
 619.290 +		winlog("Primary CAPS 4: %08x\n", caps.dwCaps4);
 619.291 +	}
 619.292 +
 619.293 +	if (theApp.videoOption > VIDEO_4X && theApp.tripleBuffering)
 619.294 +	{
 619.295 +		DDSCAPS2 caps;
 619.296 +		ZeroMemory(&caps, sizeof(caps));
 619.297 +		// this gets the third surface. The front one is the primary,
 619.298 +		// the second is the backbuffer and the third is the flip
 619.299 +		// surface
 619.300 +		caps.dwCaps = DDSCAPS_BACKBUFFER;
 619.301 +
 619.302 +		hret = ddsPrimary->GetAttachedSurface(&caps, &ddsFlip);
 619.303 +		if (hret != DD_OK)
 619.304 +		{
 619.305 +			winlog("Failed to get attached surface %08x", hret);
 619.306 +			return FALSE;
 619.307 +		}
 619.308 +		ddsFlip->AddRef();
 619.309 +		clear();
 619.310 +	}
 619.311 +
 619.312 +	// create clipper in all modes to avoid paint problems
 619.313 +	//  if(videoOption <= VIDEO_4X) {
 619.314 +	hret = pDirectDraw->CreateClipper(0, &ddsClipper, NULL);
 619.315 +	if (hret == DD_OK)
 619.316 +	{
 619.317 +		ddsClipper->SetHWnd(0, pWnd->m_hWnd);
 619.318 +		if (theApp.videoOption > VIDEO_4X)
 619.319 +		{
 619.320 +			if (theApp.tripleBuffering)
 619.321 +				ddsFlip->SetClipper(ddsClipper);
 619.322 +			else
 619.323 +				ddsPrimary->SetClipper(ddsClipper);
 619.324 +		}
 619.325 +		else
 619.326 +			ddsPrimary->SetClipper(ddsClipper);
 619.327 +	}
 619.328 +	//  }
 619.329 +
 619.330 +	DDPIXELFORMAT px;
 619.331 +
 619.332 +	px.dwSize = sizeof(px);
 619.333 +
 619.334 +	hret = ddsPrimary->GetPixelFormat(&px);
 619.335 +
 619.336 +	switch (px.dwRGBBitCount)
 619.337 +	{
 619.338 +	case 15:
 619.339 +	case 16:
 619.340 +		systemColorDepth = 16;
 619.341 +		break;
 619.342 +	case 24:
 619.343 +		systemColorDepth      = 24;
 619.344 +		theApp.filterFunction = NULL;
 619.345 +		break;
 619.346 +	case 32:
 619.347 +		systemColorDepth = 32;
 619.348 +		break;
 619.349 +	default:
 619.350 +		systemMessage(
 619.351 +		    IDS_ERROR_DISP_COLOR,
 619.352 +		    "Unsupported display setting for color depth: %d bits. \nWindows desktop must be in either 16-bit, 24-bit or 32-bit mode for this program to work in window mode.",
 619.353 +		    px.dwRGBBitCount);
 619.354 +		return FALSE;
 619.355 +	}
 619.356 +	theApp.updateFilter();
 619.357 +	theApp.updateIFB();
 619.358 +
 619.359 +	if (failed)
 619.360 +		return false;
 619.361 +
 619.362 +	pWnd->DragAcceptFiles(TRUE);
 619.363 +
 619.364 +	return true;
 619.365 +}
 619.366 +
 619.367 +bool DirectDrawDisplay::changeRenderSize(int w, int h)
 619.368 +{
 619.369 +	if (w != width || h != height)
 619.370 +	{
 619.371 +		if (ddsOffscreen)
 619.372 +		{
 619.373 +			ddsOffscreen->Release();
 619.374 +			ddsOffscreen = NULL;
 619.375 +		}
 619.376 +		if (!initializeOffscreen(w, h))
 619.377 +		{
 619.378 +			failed = true;
 619.379 +			return false;
 619.380 +		}
 619.381 +	}
 619.382 +	return true;
 619.383 +}
 619.384 +
 619.385 +bool DirectDrawDisplay::initializeOffscreen(int w, int h)
 619.386 +{
 619.387 +	DDSURFACEDESC2 ddsd;
 619.388 +
 619.389 +	ZeroMemory(&ddsd, sizeof(ddsd));
 619.390 +	ddsd.dwSize         = sizeof(ddsd);
 619.391 +	ddsd.dwFlags        = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
 619.392 +	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
 619.393 +	if (theApp.ddrawUseVideoMemory)
 619.394 +		ddsd.ddsCaps.dwCaps |= (DDSCAPS_LOCALVIDMEM|DDSCAPS_VIDEOMEMORY);
 619.395 +	ddsd.dwWidth  = w;
 619.396 +	ddsd.dwHeight = h;
 619.397 +
 619.398 +	HRESULT hret = pDirectDraw->CreateSurface(&ddsd, &ddsOffscreen, NULL);
 619.399 +
 619.400 +	if (hret != DD_OK)
 619.401 +	{
 619.402 +		winlog("Error offscreen CreateSurface %08x\n", hret);
 619.403 +		if (theApp.ddrawUseVideoMemory)
 619.404 +		{
 619.405 +			regSetDwordValue("ddrawUseVideoMemory", 0);
 619.406 +		}
 619.407 +		//    errorMessage(myLoadString(IDS_ERROR_DISP_DRAWSURFACE2), hret);
 619.408 +		return false;
 619.409 +	}
 619.410 +
 619.411 +	if (theApp.ddrawDebug)
 619.412 +	{
 619.413 +		DDSCAPS2 caps;
 619.414 +		ZeroMemory(&caps, sizeof(caps));
 619.415 +		ddsOffscreen->GetCaps(&caps);
 619.416 +
 619.417 +		winlog("Offscreen CAPS 1: %08x\n", caps.dwCaps);
 619.418 +		winlog("Offscreen CAPS 2: %08x\n", caps.dwCaps2);
 619.419 +		winlog("Offscreen CAPS 3: %08x\n", caps.dwCaps3);
 619.420 +		winlog("Offscreen CAPS 4: %08x\n", caps.dwCaps4);
 619.421 +	}
 619.422 +
 619.423 +	DDPIXELFORMAT px;
 619.424 +
 619.425 +	px.dwSize = sizeof(px);
 619.426 +
 619.427 +	hret = ddsOffscreen->GetPixelFormat(&px);
 619.428 +
 619.429 +	if (theApp.ddrawDebug)
 619.430 +	{
 619.431 +		DWORD *pdword = (DWORD *)&px;
 619.432 +		for (int ii = 0; ii < 8; ii++)
 619.433 +		{
 619.434 +			winlog("Pixel format %d %08x\n", ii, pdword[ii]);
 619.435 +		}
 619.436 +	}
 619.437 +
 619.438 +	switch (px.dwRGBBitCount)
 619.439 +	{
 619.440 +	case 15:
 619.441 +	case 16:
 619.442 +		systemColorDepth = 16;
 619.443 +		break;
 619.444 +	case 24:
 619.445 +		systemColorDepth      = 24;
 619.446 +		theApp.filterFunction = NULL;
 619.447 +		break;
 619.448 +	case 32:
 619.449 +		systemColorDepth = 32;
 619.450 +		break;
 619.451 +	default:
 619.452 +		systemMessage(
 619.453 +		    IDS_ERROR_DISP_COLOR,
 619.454 +		    "Unsupported display setting for color depth: %d bits. \nWindows desktop must be in either 16-bit, 24-bit or 32-bit mode for this program to work in window mode.",
 619.455 +		    px.dwRGBBitCount);
 619.456 +		return FALSE;
 619.457 +	}
 619.458 +	if (theApp.ddrawDebug)
 619.459 +	{
 619.460 +		winlog("R Mask: %08x\n", px.dwRBitMask);
 619.461 +		winlog("G Mask: %08x\n", px.dwGBitMask);
 619.462 +		winlog("B Mask: %08x\n", px.dwBBitMask);
 619.463 +	}
 619.464 +
 619.465 +	systemRedShift   = ffs(px.dwRBitMask);
 619.466 +	systemGreenShift = ffs(px.dwGBitMask);
 619.467 +	systemBlueShift  = ffs(px.dwBBitMask);
 619.468 +
 619.469 +#ifdef MMX
 619.470 +	if (!theApp.disableMMX)
 619.471 +		cpu_mmx = theApp.detectMMX();
 619.472 +	else
 619.473 +		cpu_mmx = 0;
 619.474 +#endif
 619.475 +
 619.476 +	if ((px.dwFlags&DDPF_RGB) != 0 &&
 619.477 +	    px.dwRBitMask == 0xF800 &&
 619.478 +	    px.dwGBitMask == 0x07E0 &&
 619.479 +	    px.dwBBitMask == 0x001F)
 619.480 +	{
 619.481 +		systemGreenShift++;
 619.482 +		Init_2xSaI(565);
 619.483 +		RGB_LOW_BITS_MASK = 0x821;
 619.484 +	}
 619.485 +	else if ((px.dwFlags&DDPF_RGB) != 0 &&
 619.486 +	         px.dwRBitMask == 0x7C00 &&
 619.487 +	         px.dwGBitMask == 0x03E0 &&
 619.488 +	         px.dwBBitMask == 0x001F)
 619.489 +	{
 619.490 +		Init_2xSaI(555);
 619.491 +		RGB_LOW_BITS_MASK = 0x421;
 619.492 +	}
 619.493 +	else if ((px.dwFlags&DDPF_RGB) != 0 &&
 619.494 +	         px.dwRBitMask == 0x001F &&
 619.495 +	         px.dwGBitMask == 0x07E0 &&
 619.496 +	         px.dwBBitMask == 0xF800)
 619.497 +	{
 619.498 +		systemGreenShift++;
 619.499 +		Init_2xSaI(565);
 619.500 +		RGB_LOW_BITS_MASK = 0x821;
 619.501 +	}
 619.502 +	else if ((px.dwFlags&DDPF_RGB) != 0 &&
 619.503 +	         px.dwRBitMask == 0x001F &&
 619.504 +	         px.dwGBitMask == 0x03E0 &&
 619.505 +	         px.dwBBitMask == 0x7C00)
 619.506 +	{
 619.507 +		Init_2xSaI(555);
 619.508 +		RGB_LOW_BITS_MASK = 0x421;
 619.509 +	}
 619.510 +	else
 619.511 +	{
 619.512 +		// 32-bit or 24-bit
 619.513 +		if (systemColorDepth == 32 || systemColorDepth == 24)
 619.514 +		{
 619.515 +			systemRedShift   += 3;
 619.516 +			systemGreenShift += 3;
 619.517 +			systemBlueShift  += 3;
 619.518 +			if (systemColorDepth == 32)
 619.519 +				Init_2xSaI(32);
 619.520 +		}
 619.521 +	}
 619.522 +
 619.523 +	if (theApp.ddrawDebug)
 619.524 +	{
 619.525 +		winlog("R shift: %d\n", systemRedShift);
 619.526 +		winlog("G shift: %d\n", systemGreenShift);
 619.527 +		winlog("B shift: %d\n", systemBlueShift);
 619.528 +	}
 619.529 +
 619.530 +	switch (systemColorDepth)
 619.531 +	{
 619.532 +	case 16:
 619.533 +	{
 619.534 +		for (int i = 0; i < 0x10000; i++)
 619.535 +		{
 619.536 +			systemColorMap16[i] = ((i & 0x1f) << systemRedShift) |
 619.537 +			                      (((i & 0x3e0) >> 5) << systemGreenShift) |
 619.538 +			                      (((i & 0x7c00) >> 10) << systemBlueShift);
 619.539 +		}
 619.540 +		break;
 619.541 +	}
 619.542 +	case 24:
 619.543 +	case 32:
 619.544 +	{
 619.545 +		for (int i = 0; i < 0x10000; i++)
 619.546 +		{
 619.547 +			systemColorMap32[i] = ((i & 0x1f) << systemRedShift) |
 619.548 +			                      (((i & 0x3e0) >> 5) << systemGreenShift) |
 619.549 +			                      (((i & 0x7c00) >> 10) << systemBlueShift);
 619.550 +		}
 619.551 +		break;
 619.552 +	}
 619.553 +	}
 619.554 +	width  = w;
 619.555 +	height = h;
 619.556 +	return true;
 619.557 +}
 619.558 +
 619.559 +void DirectDrawDisplay::clear()
 619.560 +{
 619.561 +	if (theApp.videoOption <= VIDEO_4X || !theApp.tripleBuffering || ddsFlip == NULL)
 619.562 +		return;
 619.563 +
 619.564 +	DDBLTFX fx;
 619.565 +	ZeroMemory(&fx, sizeof(fx));
 619.566 +	fx.dwSize      = sizeof(fx);
 619.567 +	fx.dwFillColor = 0;
 619.568 +	ddsFlip->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
 619.569 +	ddsPrimary->Flip(NULL, 0);
 619.570 +	ddsFlip->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
 619.571 +	ddsPrimary->Flip(NULL, 0);
 619.572 +	ddsFlip->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
 619.573 +	ddsPrimary->Flip(NULL, 0);
 619.574 +}
 619.575 +
 619.576 +void DirectDrawDisplay::renderMenu()
 619.577 +{
 619.578 +	checkFullScreen();
 619.579 +	theApp.m_pMainWnd->DrawMenuBar();
 619.580 +}
 619.581 +
 619.582 +void DirectDrawDisplay::checkFullScreen()
 619.583 +{
 619.584 +	if (theApp.tripleBuffering)
 619.585 +		pDirectDraw->FlipToGDISurface();
 619.586 +}
 619.587 +
 619.588 +void DirectDrawDisplay::render()
 619.589 +{
 619.590 +	HRESULT hret;
 619.591 +
 619.592 +	if (pDirectDraw == NULL ||
 619.593 +	    ddsOffscreen == NULL ||
 619.594 +	    ddsPrimary == NULL)
 619.595 +		return;
 619.596 +
 619.597 +	bool fastForward = speedup;
 619.598 +#if (defined(WIN32) && !defined(SDL))
 619.599 +	if (theApp.frameSearchSkipping)
 619.600 +	{
 619.601 +		if (theApp.frameSearchFirstStep)
 619.602 +			fastForward = true;
 619.603 +		else
 619.604 +			return; // don't render skipped frame search frames
 619.605 +	}
 619.606 +#endif
 619.607 +
 619.608 +	DDSURFACEDESC2 ddsDesc;
 619.609 +
 619.610 +	ZeroMemory(&ddsDesc, sizeof(ddsDesc));
 619.611 +
 619.612 +	ddsDesc.dwSize = sizeof(ddsDesc);
 619.613 +
 619.614 +	hret = ddsOffscreen->Lock(NULL,
 619.615 +	                          &ddsDesc,
 619.616 +#ifndef FINAL_VERSION
 619.617 +	                          DDLOCK_NOSYSLOCK |
 619.618 +#endif
 619.619 +	                          DDLOCK_WRITEONLY | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,
 619.620 +	                          NULL);
 619.621 +
 619.622 +	if (hret == DDERR_SURFACELOST)
 619.623 +	{
 619.624 +		hret = ddsPrimary->Restore();
 619.625 +		if (hret == DD_OK)
 619.626 +		{
 619.627 +			hret = ddsOffscreen->Restore();
 619.628 +
 619.629 +			if (hret == DD_OK)
 619.630 +			{
 619.631 +				hret = ddsOffscreen->Lock(NULL,
 619.632 +				                          &ddsDesc,
 619.633 +#ifndef FINAL_VERSION
 619.634 +				                          DDLOCK_NOSYSLOCK |
 619.635 +#endif
 619.636 +				                          DDLOCK_WRITEONLY | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,
 619.637 +				                          NULL);
 619.638 +			}
 619.639 +		}
 619.640 +	}
 619.641 +
 619.642 +	if (hret == DD_OK)
 619.643 +	{
 619.644 +		if (theApp.filterFunction)
 619.645 +		{
 619.646 +			if (systemColorDepth == 16)
 619.647 +				(*theApp.filterFunction)(pix + theApp.filterWidth * 2 + 4,
 619.648 +				                         theApp.filterWidth * 2 + 4,
 619.649 +				                         (u8 *)theApp.delta,
 619.650 +				                         (u8 *)ddsDesc.lpSurface,
 619.651 +				                         ddsDesc.lPitch,
 619.652 +				                         theApp.filterWidth,
 619.653 +				                         theApp.filterHeight);
 619.654 +			else
 619.655 +				(*theApp.filterFunction)(pix + theApp.filterWidth * 4 + 4,
 619.656 +				                         theApp.filterWidth * 4 + 4,
 619.657 +				                         (u8 *)theApp.delta,
 619.658 +				                         (u8 *)ddsDesc.lpSurface,
 619.659 +				                         ddsDesc.lPitch,
 619.660 +				                         theApp.filterWidth,
 619.661 +				                         theApp.filterHeight);
 619.662 +		}
 619.663 +		else
 619.664 +		{
 619.665 +			int copyX = 240;
 619.666 +			int copyY = 160;
 619.667 +
 619.668 +			if (systemCartridgeType == 1)
 619.669 +			{
 619.670 +				if (gbBorderOn)
 619.671 +				{
 619.672 +					copyX = 256;
 619.673 +					copyY = 224;
 619.674 +				}
 619.675 +				else
 619.676 +				{
 619.677 +					copyX = 160;
 619.678 +					copyY = 144;
 619.679 +				}
 619.680 +			}
 619.681 +			// MMX doesn't seem to be faster to copy the data
 619.682 +			__asm {
 619.683 +				mov eax, copyX;
 619.684 +				mov ebx, copyY;
 619.685 +
 619.686 +				mov esi, pix;
 619.687 +				mov edi, ddsDesc.lpSurface;
 619.688 +				mov edx, ddsDesc.lPitch;
 619.689 +				cmp systemColorDepth, 16;
 619.690 +				jnz gbaOtherColor;
 619.691 +				sub edx, eax;
 619.692 +				sub edx, eax;
 619.693 +				lea esi, [esi+2*eax+4];
 619.694 +				shr eax, 1;
 619.695 +gbaLoop16bit:
 619.696 +				mov ecx, eax;
 619.697 +				repz movsd;
 619.698 +				inc  esi;
 619.699 +				inc  esi;
 619.700 +				inc  esi;
 619.701 +				inc  esi;
 619.702 +				add  edi, edx;
 619.703 +				dec  ebx;
 619.704 +				jnz  gbaLoop16bit;
 619.705 +				jmp  gbaLoopEnd;
 619.706 +gbaOtherColor:
 619.707 +				cmp systemColorDepth, 32;
 619.708 +				jnz gbaOtherColor2;
 619.709 +
 619.710 +				sub edx, eax;
 619.711 +				sub edx, eax;
 619.712 +				sub edx, eax;
 619.713 +				sub edx, eax;
 619.714 +				lea esi, [esi+4*eax+4];
 619.715 +gbaLoop32bit:
 619.716 +				mov ecx, eax;
 619.717 +				repz movsd;
 619.718 +				add  esi, 4;
 619.719 +				add  edi, edx;
 619.720 +				dec  ebx;
 619.721 +				jnz  gbaLoop32bit;
 619.722 +				jmp  gbaLoopEnd;
 619.723 +gbaOtherColor2:
 619.724 +				lea eax, [eax+2*eax];
 619.725 +				sub edx, eax;
 619.726 +gbaLoop24bit:
 619.727 +				mov ecx, eax;
 619.728 +				shr  ecx, 2;
 619.729 +				repz movsd;
 619.730 +				add  edi, edx;
 619.731 +				dec  ebx;
 619.732 +				jnz  gbaLoop24bit;
 619.733 +gbaLoopEnd:
 619.734 +			}
 619.735 +		}
 619.736 +		if (theApp.showSpeed && theApp.videoOption > VIDEO_4X)
 619.737 +		{
 619.738 +			char buffer[30];
 619.739 +			if (theApp.showSpeed == 1)
 619.740 +				sprintf(buffer, "%3d%%", systemSpeed);
 619.741 +			else
 619.742 +				sprintf(buffer, "%3d%%(%d, %d fps)", systemSpeed,
 619.743 +				        systemFrameSkip,
 619.744 +				        theApp.showRenderedFrames);
 619.745 +			if (theApp.showSpeedTransparent)
 619.746 +				drawTextTransp((u8 *)ddsDesc.lpSurface,
 619.747 +				               ddsDesc.lPitch,
 619.748 +				               theApp.rect.left+10,
 619.749 +				               theApp.rect.bottom-10,
 619.750 +				               buffer);
 619.751 +			else
 619.752 +				drawText((u8 *)ddsDesc.lpSurface,
 619.753 +				         ddsDesc.lPitch,
 619.754 +				         theApp.rect.left+10,
 619.755 +				         theApp.rect.bottom-10,
 619.756 +				         buffer);
 619.757 +		}
 619.758 +
 619.759 +		if (textMethod == 1)
 619.760 +		{
 619.761 +			DrawTextMessages((u8 *)ddsDesc.lpSurface, ddsDesc.lPitch, theApp.rect.left, theApp.rect.bottom);
 619.762 +		}
 619.763 +	}
 619.764 +	else if (theApp.ddrawDebug)
 619.765 +		winlog("Error during lock: %08x\n", hret);
 619.766 +
 619.767 +	hret = ddsOffscreen->Unlock(NULL);
 619.768 +
 619.769 +	if (hret == DD_OK)
 619.770 +	{
 619.771 +		// the correct point where to wait
 619.772 +		if (theApp.vsync && !fastForward)
 619.773 +		{
 619.774 +			hret = pDirectDraw->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, 0);
 619.775 +		}
 619.776 +
 619.777 +		ddsOffscreen->PageLock(0);
 619.778 +		if (theApp.tripleBuffering && theApp.videoOption > VIDEO_4X)
 619.779 +		{
 619.780 +			hret = ddsFlip->Blt(&theApp.dest, ddsOffscreen, NULL, DDBLT_WAIT, NULL);
 619.781 +			if (hret == DD_OK)
 619.782 +			{
 619.783 +				if (theApp.menuToggle || !theApp.active)
 619.784 +				{
 619.785 +					pDirectDraw->FlipToGDISurface();
 619.786 +					ddsPrimary->SetClipper(ddsClipper);
 619.787 +					hret = ddsPrimary->Blt(&theApp.dest, ddsFlip, NULL, DDBLT_ASYNC, NULL);
 619.788 +					// if using emulation only, then we have to redraw the menu
 619.789 +					// everytime. It seems like a bug in DirectDraw to me as we not
 619.790 +					// overwritting the menu area at all.
 619.791 +					if (theApp.ddrawUsingEmulationOnly)
 619.792 +						theApp.m_pMainWnd->DrawMenuBar();
 619.793 +				}
 619.794 +				else
 619.795 +					hret = ddsPrimary->Flip(NULL, 0);
 619.796 +			}
 619.797 +		}
 619.798 +		else
 619.799 +		{
 619.800 +			hret = ddsPrimary->Blt(&theApp.dest, ddsOffscreen, NULL, DDBLT_ASYNC, NULL);
 619.801 +
 619.802 +			if (hret == DDERR_SURFACELOST)
 619.803 +			{
 619.804 +				hret = ddsPrimary->Restore();
 619.805 +
 619.806 +				if (hret == DD_OK)
 619.807 +				{
 619.808 +					hret = ddsPrimary->Blt(&theApp.dest, ddsOffscreen, NULL, DDBLT_ASYNC, NULL);
 619.809 +				}
 619.810 +			}
 619.811 +		}
 619.812 +		ddsOffscreen->PageUnlock(0);
 619.813 +	}
 619.814 +	else if (theApp.ddrawDebug)
 619.815 +		winlog("Error during unlock: %08x\n", hret);
 619.816 +
 619.817 +	bool textMessageStarted = false;
 619.818 +
 619.819 +	if (textMethod == 2)
 619.820 +	{
 619.821 +		HDC hdc;
 619.822 +
 619.823 +		for (int slot = 0; slot < SCREEN_MESSAGE_SLOTS; slot++)
 619.824 +		{
 619.825 +			if (theApp.screenMessage[slot])
 619.826 +			{
 619.827 +				if ((theApp.screenMessageDuration[slot] < 0 || 
 619.828 +					(int)(GetTickCount() - theApp.screenMessageTime[slot]) < theApp.screenMessageDuration[slot]) &&
 619.829 +				    (!theApp.disableStatusMessage || slot == 1 || slot == 2))
 619.830 +				{
 619.831 +					if (!textMessageStarted)
 619.832 +					{
 619.833 +						textMessageStarted = true;
 619.834 +						ddsPrimary->SetClipper(ddsClipper);
 619.835 +						ddsPrimary->GetDC(&hdc);
 619.836 +						SetBkMode(hdc, TRANSPARENT);
 619.837 +						SetTextColor(hdc, textColor != 7 ? RGB(0, 0, 0) : RGB(255, 255, 255));
 619.838 +					}
 619.839 +
 619.840 +					if (outlinedText)
 619.841 +					{
 619.842 +						// draw black outline
 619.843 +						const static int xd [8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 619.844 +						const static int yd [8] = {-1, -1, -1, 0, 1, 1, 1, 0};
 619.845 +						for (int i = 0; i < 8; i++)
 619.846 +						{
 619.847 +							TextOut(hdc,
 619.848 +							        theApp.dest.left+10+xd[i],
 619.849 +							        theApp.dest.bottom - 20*(slot+1)+yd[i],
 619.850 +							        theApp.screenMessageBuffer[slot],
 619.851 +							        strlen(theApp.screenMessageBuffer[slot]));
 619.852 +						}
 619.853 +					}
 619.854 +				}
 619.855 +				else
 619.856 +				{
 619.857 +					theApp.screenMessage[slot] = false;
 619.858 +				}
 619.859 +			}
 619.860 +		}
 619.861 +
 619.862 +		if (textMessageStarted)
 619.863 +		{
 619.864 +			COLORREF color;
 619.865 +			switch (textColor)
 619.866 +			{
 619.867 +			case 0:
 619.868 +				color = RGB(255, 255, 255); break;
 619.869 +			case 1:
 619.870 +				color = RGB(255, 0, 0); break;
 619.871 +			case 2:
 619.872 +				color = RGB(255, 255, 0); break;
 619.873 +			case 3:
 619.874 +				color = RGB(0, 255, 0); break;
 619.875 +			case 4:
 619.876 +				color = RGB(0, 255, 255); break;
 619.877 +			case 5:
 619.878 +				color = RGB(0, 0, 255); break;
 619.879 +			case 6:
 619.880 +				color = RGB(255, 0, 255); break;
 619.881 +			case 7:
 619.882 +				color = RGB(0, 0, 0); break;
 619.883 +			}
 619.884 +			SetTextColor(hdc, color);
 619.885 +
 619.886 +			// draw center text
 619.887 +			for (int slot = 0; slot < SCREEN_MESSAGE_SLOTS; slot++)
 619.888 +			{
 619.889 +				if (theApp.screenMessage[slot])
 619.890 +				{
 619.891 +					if ((theApp.screenMessageDuration[slot] < 0 || 
 619.892 +						(int)(GetTickCount() - theApp.screenMessageTime[slot]) < theApp.screenMessageDuration[slot]) &&
 619.893 +					    (!theApp.disableStatusMessage || slot == 1 || slot == 2))
 619.894 +					{
 619.895 +						TextOut(hdc, theApp.dest.left+10, theApp.dest.bottom - 20*(slot+1), theApp.screenMessageBuffer[slot],
 619.896 +						        strlen(theApp.screenMessageBuffer[slot]));
 619.897 +					}
 619.898 +				}
 619.899 +			}
 619.900 +		}
 619.901 +
 619.902 +		if (textMessageStarted)
 619.903 +		{
 619.904 +			ddsPrimary->ReleaseDC(hdc);
 619.905 +		}
 619.906 +	}
 619.907 +
 619.908 +	if (hret != DD_OK)
 619.909 +	{
 619.910 +		if (theApp.ddrawDebug)
 619.911 +			winlog("Error on update screen: %08x\n", hret);
 619.912 +	}
 619.913 +}
 619.914 +
 619.915 +int DirectDrawDisplay::selectFullScreenMode(GUID **pGUID)
 619.916 +{
 619.917 +	return winVideoModeSelect(theApp.m_pMainWnd, pGUID);
 619.918 +}
 619.919 +
 619.920 +IDisplay *newDirectDrawDisplay()
 619.921 +{
 619.922 +	return new DirectDrawDisplay();
 619.923 +}
 619.924 +
   620.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   620.2 +++ b/src/win32/DirectInput.cpp	Sat Mar 03 10:31:27 2012 -0600
   620.3 @@ -0,0 +1,1242 @@
   620.4 +//#define USE_GETASYNCKEYSTATE_FOR_KEYBOARD
   620.5 +
   620.6 +#include "stdafx.h"
   620.7 +
   620.8 +#define DIRECTINPUT_VERSION 0x0500
   620.9 +#include "dinput.h"
  620.10 +
  620.11 +#include "resource.h"
  620.12 +#include "Input.h"
  620.13 +#include "Reg.h"
  620.14 +#include "WinResUtil.h"
  620.15 +
  620.16 +// master keyboard translation table
  620.17 +static const struct {
  620.18 +	int dik;
  620.19 +	int vk;
  620.20 +	int ascii;
  620.21 +} win_key_trans_table[] = {
  620.22 +	// dinput key		virtual key		ascii
  620.23 +	{ DIK_ESCAPE,		VK_ESCAPE,	 	27 },
  620.24 +	{ DIK_1,			'1',			'1' },
  620.25 +	{ DIK_2,			'2',			'2' },
  620.26 +	{ DIK_3,			'3',			'3' },
  620.27 +	{ DIK_4,			'4',			'4' },
  620.28 +	{ DIK_5,			'5',			'5' },
  620.29 +	{ DIK_6,			'6',			'6' },
  620.30 +	{ DIK_7,			'7',			'7' },
  620.31 +	{ DIK_8,			'8',			'8' },
  620.32 +	{ DIK_9,			'9',			'9' },
  620.33 +	{ DIK_0,			'0',			'0' },
  620.34 +	{ DIK_MINUS, 		VK_OEM_MINUS,	'-' },
  620.35 +	{ DIK_EQUALS,		VK_OEM_PLUS,	'=' },
  620.36 +	{ DIK_BACK, 		VK_BACK, 		8 },
  620.37 +	{ DIK_TAB, 			VK_TAB, 		9 },
  620.38 +	{ DIK_Q,			'Q',			'Q' },
  620.39 +	{ DIK_W,			'W',			'W' },
  620.40 +	{ DIK_E,			'E',			'E' },
  620.41 +	{ DIK_R,			'R',			'R' },
  620.42 +	{ DIK_T,			'T',			'T' },
  620.43 +	{ DIK_Y,			'Y',			'Y' },
  620.44 +	{ DIK_U,			'U',			'U' },
  620.45 +	{ DIK_I,			'I',			'I' },
  620.46 +	{ DIK_O,			'O',			'O' },
  620.47 +	{ DIK_P,			'P',			'P' },
  620.48 +	{ DIK_LBRACKET, 	VK_OEM_4,		'[' },
  620.49 +	{ DIK_RBRACKET, 	VK_OEM_6,		']' },
  620.50 +	{ DIK_RETURN, 		VK_RETURN, 		13 },
  620.51 +	{ DIK_LCONTROL, 	VK_LCONTROL, 	0 },
  620.52 +	{ DIK_A,			'A',			'A' },
  620.53 +	{ DIK_S,			'S',			'S' },
  620.54 +	{ DIK_D,			'D',			'D' },
  620.55 +	{ DIK_F,			'F',			'F' },
  620.56 +	{ DIK_G,			'G',			'G' },
  620.57 +	{ DIK_H,			'H',			'H' },
  620.58 +	{ DIK_J,			'J',			'J' },
  620.59 +	{ DIK_K,			'K',			'K' },
  620.60 +	{ DIK_L,			'L',			'L' },
  620.61 +	{ DIK_SEMICOLON,	VK_OEM_1,		';' },
  620.62 +	{ DIK_APOSTROPHE,	VK_OEM_7,		'\'' },
  620.63 +	{ DIK_GRAVE, 		VK_OEM_3,		'`' },
  620.64 +	{ DIK_LSHIFT, 		VK_LSHIFT, 		0 },
  620.65 +	{ DIK_BACKSLASH, 	VK_OEM_5,		'\\' },
  620.66 +	{ DIK_Z,			'Z',			'Z' },
  620.67 +	{ DIK_X,			'X',			'X' },
  620.68 +	{ DIK_C,			'C',			'C' },
  620.69 +	{ DIK_V,			'V',			'V' },
  620.70 +	{ DIK_B,			'B',			'B' },
  620.71 +	{ DIK_N,			'N',			'N' },
  620.72 +	{ DIK_M,			'M',			'M' },
  620.73 +	{ DIK_COMMA,		VK_OEM_COMMA,	',' },
  620.74 +	{ DIK_PERIOD, 		VK_OEM_PERIOD,	'.' },
  620.75 +	{ DIK_SLASH, 		VK_OEM_2,		'/' },
  620.76 +	{ DIK_RSHIFT, 		VK_RSHIFT, 		0 },
  620.77 +	{ DIK_MULTIPLY, 	VK_MULTIPLY,	'*' },
  620.78 +	{ DIK_LMENU, 		VK_LMENU, 		0 },
  620.79 +	{ DIK_SPACE, 		VK_SPACE,		' ' },
  620.80 +	{ DIK_CAPITAL, 		VK_CAPITAL, 	0 },
  620.81 +	{ DIK_F1,			VK_F1, 			0 },
  620.82 +	{ DIK_F2,			VK_F2, 			0 },
  620.83 +	{ DIK_F3,			VK_F3, 			0 },
  620.84 +	{ DIK_F4,			VK_F4, 			0 },
  620.85 +	{ DIK_F5,			VK_F5, 			0 },
  620.86 +	{ DIK_F6,			VK_F6, 			0 },
  620.87 +	{ DIK_F7,			VK_F7, 			0 },
  620.88 +	{ DIK_F8,			VK_F8, 			0 },
  620.89 +	{ DIK_F9,			VK_F9, 			0 },
  620.90 +	{ DIK_F10,			VK_F10, 		0 },
  620.91 +	{ DIK_NUMLOCK,		VK_NUMLOCK, 	0 },
  620.92 +	{ DIK_SCROLL,		VK_SCROLL, 		0 },
  620.93 +	{ DIK_NUMPAD7,		VK_NUMPAD7, 	0 },
  620.94 +	{ DIK_NUMPAD8,		VK_NUMPAD8, 	0 },
  620.95 +	{ DIK_NUMPAD9,		VK_NUMPAD9, 	0 },
  620.96 +	{ DIK_SUBTRACT,		VK_SUBTRACT, 	0 },
  620.97 +	{ DIK_NUMPAD4,		VK_NUMPAD4, 	0 },
  620.98 +	{ DIK_NUMPAD5,		VK_NUMPAD5, 	0 },
  620.99 +	{ DIK_NUMPAD6,		VK_NUMPAD6, 	0 },
 620.100 +	{ DIK_ADD,			VK_ADD, 		0 },
 620.101 +	{ DIK_NUMPAD1,		VK_NUMPAD1, 	0 },
 620.102 +	{ DIK_NUMPAD2,		VK_NUMPAD2, 	0 },
 620.103 +	{ DIK_NUMPAD3,		VK_NUMPAD3, 	0 },
 620.104 +	{ DIK_NUMPAD0,		VK_NUMPAD0, 	0 },
 620.105 +	{ DIK_DECIMAL,		VK_DECIMAL, 	0 },
 620.106 +	{ DIK_F11,			VK_F11, 		0 },
 620.107 +	{ DIK_F12,			VK_F12, 		0 },
 620.108 +	{ DIK_F13,			VK_F13, 		0 },
 620.109 +	{ DIK_F14,			VK_F14, 		0 },
 620.110 +	{ DIK_F15,			VK_F15, 		0 },
 620.111 +	{ DIK_NUMPADENTER,	VK_RETURN, 		0 },
 620.112 +	{ DIK_RCONTROL,		VK_RCONTROL, 	0 },
 620.113 +	{ DIK_DIVIDE,		VK_DIVIDE, 		0 },
 620.114 +	{ DIK_SYSRQ, 		0, 				0 },
 620.115 +	{ DIK_RMENU,		VK_RMENU, 		0 },
 620.116 +	{ DIK_HOME,			VK_HOME, 		0 },
 620.117 +	{ DIK_UP,			VK_UP, 			0 },
 620.118 +	{ DIK_PRIOR,		VK_PRIOR, 		0 },
 620.119 +	{ DIK_LEFT,			VK_LEFT, 		0 },
 620.120 +	{ DIK_RIGHT,		VK_RIGHT, 		0 },
 620.121 +	{ DIK_END,			VK_END, 		0 },
 620.122 +	{ DIK_DOWN,			VK_DOWN, 		0 },
 620.123 +	{ DIK_NEXT,			VK_NEXT, 		0 },
 620.124 +	{ DIK_INSERT,		VK_INSERT, 		0 },
 620.125 +	{ DIK_DELETE,		VK_DELETE, 		0 },
 620.126 +	{ DIK_LWIN,			VK_LWIN, 		0 },
 620.127 +	{ DIK_RWIN,			VK_RWIN, 		0 },
 620.128 +	{ DIK_APPS,			VK_APPS, 		0 },
 620.129 +	{ DIK_PAUSE,		VK_PAUSE,		0 },
 620.130 +	{ 0,				VK_CANCEL,		0 },
 620.131 +
 620.132 +	// New keys introduced in Windows 2000. These have no MAME codes to
 620.133 +	// preserve compatibility with old config files that may refer to them
 620.134 +	// as e.g. FORWARD instead of e.g. KEYCODE_WEBFORWARD. They need table
 620.135 +	// entries anyway because otherwise they aren't recognized when
 620.136 +	// GetAsyncKeyState polling is used (as happens currently when MAME is
 620.137 +	// paused). Some codes are missing because the mapping to vkey codes
 620.138 +	// isn't clear, and MapVirtualKey is no help.
 620.139 +
 620.140 +	{ DIK_MUTE,			VK_VOLUME_MUTE,			0 },
 620.141 +	{ DIK_VOLUMEDOWN,	VK_VOLUME_DOWN,			0 },
 620.142 +	{ DIK_VOLUMEUP,		VK_VOLUME_UP,			0 },
 620.143 +	{ DIK_WEBHOME,		VK_BROWSER_HOME,		0 },
 620.144 +	{ DIK_WEBSEARCH,	VK_BROWSER_SEARCH,		0 },
 620.145 +	{ DIK_WEBFAVORITES,	VK_BROWSER_FAVORITES,	0 },
 620.146 +	{ DIK_WEBREFRESH,	VK_BROWSER_REFRESH,		0 },
 620.147 +	{ DIK_WEBSTOP,		VK_BROWSER_STOP,		0 },
 620.148 +	{ DIK_WEBFORWARD,	VK_BROWSER_FORWARD,		0 },
 620.149 +	{ DIK_WEBBACK,		VK_BROWSER_BACK,		0 },
 620.150 +	{ DIK_MAIL,			VK_LAUNCH_MAIL,			0 },
 620.151 +	{ DIK_MEDIASELECT,	VK_LAUNCH_MEDIA_SELECT,	0 },
 620.152 +};
 620.153 +
 620.154 +extern void directXMessage(const char *);
 620.155 +extern void winlog(const char *msg, ...);
 620.156 +
 620.157 +#define POV_UP    1
 620.158 +#define POV_DOWN  2
 620.159 +#define POV_RIGHT 4
 620.160 +#define POV_LEFT  8
 620.161 +
 620.162 +class DirectInput : public Input
 620.163 +{
 620.164 +private:
 620.165 +	HINSTANCE dinputDLL;
 620.166 +public:
 620.167 +	virtual void checkDevices();
 620.168 +	DirectInput();
 620.169 +	virtual ~DirectInput();
 620.170 +
 620.171 +	virtual bool initialize();
 620.172 +	virtual bool readDevices();
 620.173 +	virtual u32 readDevice(int which, bool sensor);
 620.174 +	virtual CString getKeyName(LONG_PTR key);
 620.175 +	virtual void checkKeys();
 620.176 +	virtual void activate();
 620.177 +	virtual void loadSettings();
 620.178 +	virtual void saveSettings();
 620.179 +};
 620.180 +
 620.181 +struct deviceInfo
 620.182 +{
 620.183 +	LPDIRECTINPUTDEVICE device;
 620.184 +	BOOL isPolled;
 620.185 +	int  nButtons;
 620.186 +	int  nAxes;
 620.187 +	int  nPovs;
 620.188 +	BOOL first;
 620.189 +	struct
 620.190 +	{
 620.191 +		DWORD offset;
 620.192 +		LONG  center;
 620.193 +		LONG  negative;
 620.194 +		LONG  positive;
 620.195 +	} axis[8];
 620.196 +	int needed;
 620.197 +	union
 620.198 +	{
 620.199 +		UCHAR      data[256];
 620.200 +		DIJOYSTATE state;
 620.201 +	};
 620.202 +};
 620.203 +
 620.204 +static deviceInfo *  currentDevice = NULL;
 620.205 +static int           numDevices    = 1;
 620.206 +static deviceInfo *  pDevices      = NULL;
 620.207 +static LPDIRECTINPUT pDirectInput  = NULL;
 620.208 +static int           joyDebug      = 0;
 620.209 +static int           axisNumber    = 0;
 620.210 +
 620.211 +USHORT joypad[4][13] = {
 620.212 +	{
 620.213 +		DIK_LEFT,  DIK_RIGHT,
 620.214 +		DIK_UP,    DIK_DOWN,
 620.215 +		DIK_Z,     DIK_X,
 620.216 +		DIK_RETURN, DIK_BACK,
 620.217 +		DIK_A,     DIK_S,
 620.218 +		DIK_SPACE, DIK_F12,
 620.219 +		DIK_C
 620.220 +	},
 620.221 +	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
 620.222 +	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
 620.223 +	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
 620.224 +};
 620.225 +
 620.226 +USHORT motion[4] = {
 620.227 +	DIK_NUMPAD4, DIK_NUMPAD6, DIK_NUMPAD8, DIK_NUMPAD2
 620.228 +};
 620.229 +
 620.230 +static int winReadKey(char *name, int num)
 620.231 +{
 620.232 +	char buffer[80];
 620.233 +
 620.234 +	sprintf(buffer, "Joy%d_%s", num, name);
 620.235 +
 620.236 +	return regQueryDwordValue(buffer, (DWORD)-1);
 620.237 +}
 620.238 +
 620.239 +void winReadKeys()
 620.240 +{
 620.241 +	int key = -1;
 620.242 +
 620.243 +	for (int i = 0; i < 4; i++)
 620.244 +	{
 620.245 +		key = winReadKey("Left", i);
 620.246 +		if (key != -1)
 620.247 +			joypad[i][KEY_LEFT] = key;
 620.248 +		key = winReadKey("Right", i);
 620.249 +		if (key != -1)
 620.250 +			joypad[i][KEY_RIGHT] = key;
 620.251 +		key = winReadKey("Up", i);
 620.252 +		if (key != -1)
 620.253 +			joypad[i][KEY_UP] = key;
 620.254 +		key = winReadKey("Down", i);
 620.255 +		if (key != -1)
 620.256 +			joypad[i][KEY_DOWN] = key;
 620.257 +		key = winReadKey("A", i);
 620.258 +		if (key != -1)
 620.259 +			joypad[i][KEY_BUTTON_A] = key;
 620.260 +		key = winReadKey("B", i);
 620.261 +		if (key != -1)
 620.262 +			joypad[i][KEY_BUTTON_B] = key;
 620.263 +		key = winReadKey("L", i);
 620.264 +		if (key != -1)
 620.265 +			joypad[i][KEY_BUTTON_L] = key;
 620.266 +		key = winReadKey("R", i);
 620.267 +		if (key != -1)
 620.268 +			joypad[i][KEY_BUTTON_R] = key;
 620.269 +		key = winReadKey("Start", i);
 620.270 +		if (key != -1)
 620.271 +			joypad[i][KEY_BUTTON_START] = key;
 620.272 +		key = winReadKey("Select", i);
 620.273 +		if (key != -1)
 620.274 +			joypad[i][KEY_BUTTON_SELECT] = key;
 620.275 +		key = winReadKey("Speed", i);
 620.276 +		if (key != -1)
 620.277 +			joypad[i][KEY_BUTTON_SPEED] = key;
 620.278 +		key = winReadKey("Capture", i);
 620.279 +		if (key != -1)
 620.280 +			joypad[i][KEY_BUTTON_CAPTURE] = key;
 620.281 +		key = winReadKey("GS", i);
 620.282 +		if (key != -1)
 620.283 +			joypad[i][KEY_BUTTON_GS] = key;
 620.284 +	}
 620.285 +	key = regQueryDwordValue("Motion_Left", (DWORD)-1);
 620.286 +	if (key != -1)
 620.287 +		motion[KEY_LEFT] = key;
 620.288 +	key = regQueryDwordValue("Motion_Right", (DWORD)-1);
 620.289 +	if (key != -1)
 620.290 +		motion[KEY_RIGHT] = key;
 620.291 +	key = regQueryDwordValue("Motion_Up", (DWORD)-1);
 620.292 +	if (key != -1)
 620.293 +		motion[KEY_UP] = key;
 620.294 +	key = regQueryDwordValue("Motion_Down", (DWORD)-1);
 620.295 +	if (key != -1)
 620.296 +		motion[KEY_DOWN] = key;
 620.297 +}
 620.298 +
 620.299 +static void winSaveKey(char *name, int num, USHORT value)
 620.300 +{
 620.301 +	char buffer[80];
 620.302 +
 620.303 +	sprintf(buffer, "Joy%d_%s", num, name);
 620.304 +
 620.305 +	regSetDwordValue(buffer, value);
 620.306 +}
 620.307 +
 620.308 +void winSaveKeys()
 620.309 +{
 620.310 +	for (int i = 0; i < 4; i++)
 620.311 +	{
 620.312 +		winSaveKey("Left", i, joypad[i][KEY_LEFT]);
 620.313 +		winSaveKey("Right", i, joypad[i][KEY_RIGHT]);
 620.314 +		winSaveKey("Up", i, joypad[i][KEY_UP]);
 620.315 +		winSaveKey("Speed", i, joypad[i][KEY_BUTTON_SPEED]);
 620.316 +		winSaveKey("Capture", i, joypad[i][KEY_BUTTON_CAPTURE]);
 620.317 +		winSaveKey("GS", i, joypad[i][KEY_BUTTON_GS]);
 620.318 +		winSaveKey("Down", i, joypad[i][KEY_DOWN]);
 620.319 +		winSaveKey("A", i, joypad[i][KEY_BUTTON_A]);
 620.320 +		winSaveKey("B", i, joypad[i][KEY_BUTTON_B]);
 620.321 +		winSaveKey("L", i, joypad[i][KEY_BUTTON_L]);
 620.322 +		winSaveKey("R", i, joypad[i][KEY_BUTTON_R]);
 620.323 +		winSaveKey("Start", i, joypad[i][KEY_BUTTON_START]);
 620.324 +		winSaveKey("Select", i, joypad[i][KEY_BUTTON_SELECT]);
 620.325 +	}
 620.326 +	regSetDwordValue("joyVersion", 1);
 620.327 +
 620.328 +	regSetDwordValue("Motion_Left",
 620.329 +	                 motion[KEY_LEFT]);
 620.330 +	regSetDwordValue("Motion_Right",
 620.331 +	                 motion[KEY_RIGHT]);
 620.332 +	regSetDwordValue("Motion_Up",
 620.333 +	                 motion[KEY_UP]);
 620.334 +	regSetDwordValue("Motion_Down",
 620.335 +	                 motion[KEY_DOWN]);
 620.336 +}
 620.337 +
 620.338 +static BOOL CALLBACK EnumAxesCallback(const DIDEVICEOBJECTINSTANCE*pdidoi,
 620.339 +                                      VOID*pContext)
 620.340 +{
 620.341 +	DIPROPRANGE diprg;
 620.342 +	diprg.diph.dwSize       = sizeof(DIPROPRANGE);
 620.343 +	diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
 620.344 +	diprg.diph.dwHow        = DIPH_BYOFFSET;
 620.345 +	diprg.diph.dwObj        = pdidoi->dwOfs; // Specify the enumerated axis
 620.346 +
 620.347 +	diprg.lMin = -32768;
 620.348 +	diprg.lMax = 32767;
 620.349 +	// try to set the range
 620.350 +	if (FAILED(currentDevice->device->SetProperty(DIPROP_RANGE, &diprg.diph)))
 620.351 +	{
 620.352 +		// Get the range for the axis
 620.353 +		if (FAILED(currentDevice->device->
 620.354 +		           GetProperty(DIPROP_RANGE, &diprg.diph)))
 620.355 +		{
 620.356 +			return DIENUM_STOP;
 620.357 +		}
 620.358 +	}
 620.359 +
 620.360 +	DIPROPDWORD didz;
 620.361 +
 620.362 +	didz.diph.dwSize       = sizeof(didz);
 620.363 +	didz.diph.dwHeaderSize = sizeof(DIPROPHEADER);
 620.364 +	didz.diph.dwHow        = DIPH_BYOFFSET;
 620.365 +	didz.diph.dwObj        = pdidoi->dwOfs;
 620.366 +
 620.367 +	didz.dwData = 5000;
 620.368 +
 620.369 +	currentDevice->device->SetProperty(DIPROP_DEADZONE, &didz.diph);
 620.370 +
 620.371 +	LONG center    = (diprg.lMin + diprg.lMax)/2;
 620.372 +	LONG threshold = (diprg.lMax - center)/2;
 620.373 +
 620.374 +	// only 8 axis supported
 620.375 +	if (axisNumber < 8)
 620.376 +	{
 620.377 +		currentDevice->axis[axisNumber].center   = center;
 620.378 +		currentDevice->axis[axisNumber].negative = center - threshold;
 620.379 +		currentDevice->axis[axisNumber].positive = center + threshold;
 620.380 +		currentDevice->axis[axisNumber].offset   = pdidoi->dwOfs;
 620.381 +	}
 620.382 +	axisNumber++;
 620.383 +	return DIENUM_CONTINUE;
 620.384 +}
 620.385 +
 620.386 +static BOOL CALLBACK EnumPovsCallback(const DIDEVICEOBJECTINSTANCE*pdidoi,
 620.387 +                                      VOID*pContext)
 620.388 +{
 620.389 +	return DIENUM_CONTINUE;
 620.390 +}
 620.391 +
 620.392 +static BOOL CALLBACK DIEnumDevicesCallback(LPCDIDEVICEINSTANCE pInst,
 620.393 +                                           LPVOID lpvContext)
 620.394 +{
 620.395 +	ZeroMemory(&pDevices[numDevices], sizeof(deviceInfo));
 620.396 +
 620.397 +	HRESULT hRet = pDirectInput->CreateDevice(pInst->guidInstance,
 620.398 +	                                          &pDevices[numDevices].device,
 620.399 +	                                          NULL);
 620.400 +
 620.401 +	if (hRet != DI_OK)
 620.402 +		return DIENUM_STOP;
 620.403 +
 620.404 +	DIDEVCAPS caps;
 620.405 +	caps.dwSize = sizeof(DIDEVCAPS);
 620.406 +
 620.407 +	hRet = pDevices[numDevices].device->GetCapabilities(&caps);
 620.408 +
 620.409 +	if (hRet == DI_OK)
 620.410 +	{
 620.411 +		if (caps.dwFlags & DIDC_POLLEDDATAFORMAT ||
 620.412 +		    caps.dwFlags & DIDC_POLLEDDEVICE)
 620.413 +			pDevices[numDevices].isPolled = TRUE;
 620.414 +
 620.415 +		pDevices[numDevices].nButtons = caps.dwButtons;
 620.416 +		pDevices[numDevices].nAxes    = caps.dwAxes;
 620.417 +		pDevices[numDevices].nPovs    = caps.dwPOVs;
 620.418 +
 620.419 +		for (int i = 0; i < 6; i++)
 620.420 +		{
 620.421 +			pDevices[numDevices].axis[i].center   = 0x8000;
 620.422 +			pDevices[numDevices].axis[i].negative = 0x4000;
 620.423 +			pDevices[numDevices].axis[i].positive = 0xc000;
 620.424 +		}
 620.425 +	}
 620.426 +	else if (joyDebug)
 620.427 +		winlog("Failed to get device capabilities %08x\n", hRet);
 620.428 +
 620.429 +	if (joyDebug)
 620.430 +	{
 620.431 +		// don't translate. debug only
 620.432 +		winlog("******************************\n");
 620.433 +		winlog("Joystick %2d name    : %s\n", numDevices, pInst->tszProductName);
 620.434 +	}
 620.435 +
 620.436 +	numDevices++;
 620.437 +
 620.438 +	return DIENUM_CONTINUE;
 620.439 +}
 620.440 +
 620.441 +BOOL CALLBACK DIEnumDevicesCallback2(LPCDIDEVICEINSTANCE pInst,
 620.442 +                                     LPVOID lpvContext)
 620.443 +{
 620.444 +	numDevices++;
 620.445 +
 620.446 +	return DIENUM_CONTINUE;
 620.447 +}
 620.448 +
 620.449 +static int getPovState(DWORD value)
 620.450 +{
 620.451 +	int state = 0;
 620.452 +	if (LOWORD(value) != 0xFFFF)
 620.453 +	{
 620.454 +		if (value < 9000 || value > 27000)
 620.455 +			state |= POV_UP;
 620.456 +		if (value > 0 && value < 18000)
 620.457 +			state |= POV_RIGHT;
 620.458 +		if (value > 9000 && value < 27000)
 620.459 +			state |= POV_DOWN;
 620.460 +		if (value > 18000)
 620.461 +			state |= POV_LEFT;
 620.462 +	}
 620.463 +	return state;
 620.464 +}
 620.465 +
 620.466 +static void checkKeys()
 620.467 +{
 620.468 +	LONG_PTR dev = 0;
 620.469 +	int      i;
 620.470 +
 620.471 +	for (i = 0; i < numDevices; i++)
 620.472 +		pDevices[i].needed = 0;
 620.473 +
 620.474 +	for (i = 0; i < 4; i++)
 620.475 +	{
 620.476 +		dev = joypad[i][KEY_LEFT] >> 8;
 620.477 +		if (dev < numDevices && dev >= 0)
 620.478 +			pDevices[dev].needed = 1;
 620.479 +		else
 620.480 +			joypad[i][KEY_LEFT] = DIK_LEFT;
 620.481 +
 620.482 +		dev = joypad[i][KEY_RIGHT] >> 8;
 620.483 +		if (dev < numDevices && dev >= 0)
 620.484 +			pDevices[dev].needed = 1;
 620.485 +		else
 620.486 +			joypad[i][KEY_RIGHT] = DIK_RIGHT;
 620.487 +
 620.488 +		dev = joypad[i][KEY_UP] >> 8;
 620.489 +		if (dev < numDevices && dev >= 0)
 620.490 +			pDevices[dev].needed = 1;
 620.491 +		else
 620.492 +			joypad[i][KEY_UP] = DIK_UP;
 620.493 +
 620.494 +		dev = joypad[i][KEY_DOWN] >> 8;
 620.495 +		if (dev < numDevices && dev >= 0)
 620.496 +			pDevices[dev].needed = 1;
 620.497 +		else
 620.498 +			joypad[i][KEY_DOWN] = DIK_DOWN;
 620.499 +
 620.500 +		dev = joypad[i][KEY_BUTTON_A] >> 8;
 620.501 +		if (dev < numDevices && dev >= 0)
 620.502 +			pDevices[dev].needed = 1;
 620.503 +		else
 620.504 +			joypad[i][KEY_BUTTON_A] = DIK_Z;
 620.505 +
 620.506 +		dev = joypad[i][KEY_BUTTON_B] >> 8;
 620.507 +		if (dev < numDevices && dev >= 0)
 620.508 +			pDevices[dev].needed = 1;
 620.509 +		else
 620.510 +			joypad[i][KEY_BUTTON_B] = DIK_X;
 620.511 +
 620.512 +		dev = joypad[i][KEY_BUTTON_L] >> 8;
 620.513 +		if (dev < numDevices && dev >= 0)
 620.514 +			pDevices[dev].needed = 1;
 620.515 +		else
 620.516 +			joypad[i][KEY_BUTTON_L] = DIK_A;
 620.517 +
 620.518 +		dev = joypad[i][KEY_BUTTON_R] >> 8;
 620.519 +		if (dev < numDevices && dev >= 0)
 620.520 +			pDevices[dev].needed = 1;
 620.521 +		else
 620.522 +			joypad[i][KEY_BUTTON_R] = DIK_S;
 620.523 +
 620.524 +		dev = joypad[i][KEY_BUTTON_START] >> 8;
 620.525 +		if (dev < numDevices && dev >= 0)
 620.526 +			pDevices[dev].needed = 1;
 620.527 +		else
 620.528 +			joypad[i][KEY_BUTTON_START] = DIK_RETURN;
 620.529 +
 620.530 +		dev = joypad[i][KEY_BUTTON_SELECT] >> 8;
 620.531 +		if (dev < numDevices && dev >= 0)
 620.532 +			pDevices[dev].needed = 1;
 620.533 +		else
 620.534 +			joypad[i][KEY_BUTTON_SELECT] = DIK_BACK;
 620.535 +
 620.536 +		dev = joypad[i][KEY_BUTTON_SPEED] >> 8;
 620.537 +		if (dev < numDevices && dev >= 0)
 620.538 +			pDevices[dev].needed = 1;
 620.539 +		else
 620.540 +			joypad[i][KEY_BUTTON_SPEED] = DIK_SPACE;
 620.541 +
 620.542 +		dev = joypad[i][KEY_BUTTON_CAPTURE] >> 8;
 620.543 +		if (dev < numDevices && dev >= 0)
 620.544 +			pDevices[dev].needed = 1;
 620.545 +		else
 620.546 +			joypad[i][KEY_BUTTON_CAPTURE] = DIK_F12;
 620.547 +
 620.548 +		dev = joypad[i][KEY_BUTTON_GS] >> 8;
 620.549 +		if (dev < numDevices && dev >= 0)
 620.550 +			pDevices[dev].needed = 1;
 620.551 +		else
 620.552 +			joypad[i][KEY_BUTTON_GS] = DIK_C;
 620.553 +	}
 620.554 +
 620.555 +	dev = motion[KEY_UP] >> 8;
 620.556 +	if (dev < numDevices && dev >= 0)
 620.557 +		pDevices[dev].needed = 1;
 620.558 +	else
 620.559 +		motion[KEY_UP] = DIK_NUMPAD8;
 620.560 +
 620.561 +	dev = motion[KEY_DOWN] >> 8;
 620.562 +	if (dev < numDevices && dev >= 0)
 620.563 +		pDevices[dev].needed = 1;
 620.564 +	else
 620.565 +		motion[KEY_DOWN] = DIK_NUMPAD2;
 620.566 +
 620.567 +	dev = motion[KEY_LEFT] >> 8;
 620.568 +	if (dev < numDevices && dev >= 0)
 620.569 +		pDevices[dev].needed = 1;
 620.570 +	else
 620.571 +		motion[KEY_LEFT] = DIK_NUMPAD4;
 620.572 +
 620.573 +	dev = motion[KEY_RIGHT] >> 8;
 620.574 +	if (dev < numDevices && dev >= 0)
 620.575 +		pDevices[dev].needed = 1;
 620.576 +	else
 620.577 +		motion[KEY_RIGHT] = DIK_NUMPAD6;
 620.578 +}
 620.579 +
 620.580 +#define KEYDOWN(buffer, key) (buffer[key] & 0x80)
 620.581 +
 620.582 +static bool IsKeyDownAsync (WORD KeyIdent)
 620.583 +{
 620.584 +	//if (KeyIdent == 0 || KeyIdent == VK_ESCAPE) // if it's the 'disabled' key, it's never pressed
 620.585 +	//	return false;
 620.586 +
 620.587 +	//if (!GUI.BackgroundInput && GUI.hWnd != GetForegroundWindow())
 620.588 +	//	return false;
 620.589 +
 620.590 +	// the pause key is special, need this to catch all presses of it
 620.591 +	// Both GetKeyState and GetAsyncKeyState cannot catch it anyway,
 620.592 +	// so this should be handled in WM_KEYDOWN message.
 620.593 +	if (KeyIdent == VK_PAUSE)
 620.594 +	{
 620.595 +		return false;
 620.596 +//		if(GetAsyncKeyState(VK_PAUSE)) // not &'ing this with 0x8000 is intentional and necessary
 620.597 +//			return true;
 620.598 +	}
 620.599 +
 620.600 +	if (KeyIdent == VK_CAPITAL || KeyIdent == VK_NUMLOCK || KeyIdent == VK_SCROLL)
 620.601 +		return ((GetKeyState(KeyIdent) & 0x01) != 0);
 620.602 +	else
 620.603 +		return ((GetAsyncKeyState(KeyIdent) & 0x8000) != 0);
 620.604 +	//return ((GetKeyState (KeyIdent) & 0x80) != 0);
 620.605 +}
 620.606 +
 620.607 +static bool readKeyboard()
 620.608 +{
 620.609 +#ifndef USE_GETASYNCKEYSTATE_FOR_KEYBOARD
 620.610 +	if (pDevices[0].needed)
 620.611 +	{
 620.612 +		HRESULT hret = pDevices[0].device->
 620.613 +		               GetDeviceState(256,
 620.614 +		                              (LPVOID)pDevices[0].data);
 620.615 +
 620.616 +		if (hret == DIERR_INPUTLOST || hret == DIERR_NOTACQUIRED)
 620.617 +		{
 620.618 +			hret = pDevices[0].device->Acquire();
 620.619 +			if (hret != DI_OK)
 620.620 +				return false;
 620.621 +			hret = pDevices[0].device->GetDeviceState(256, (LPVOID)pDevices[0].data);
 620.622 +		}
 620.623 +
 620.624 +		return hret == DI_OK;
 620.625 +	}
 620.626 +#else
 620.627 +	for (int i = 0; i < sizeof(win_key_trans_table)/sizeof(win_key_trans_table[0]); i++) {
 620.628 +		pDevices[0].data[win_key_trans_table[i].dik] = IsKeyDownAsync(win_key_trans_table[i].vk) ? 0x80 : 0;
 620.629 +	}
 620.630 +#endif
 620.631 +	return true;
 620.632 +}
 620.633 +
 620.634 +static bool readJoystick(int joy)
 620.635 +{
 620.636 +	if (pDevices[joy].needed)
 620.637 +	{
 620.638 +		if (pDevices[joy].isPolled)
 620.639 +			((LPDIRECTINPUTDEVICE2)pDevices[joy].device)->Poll();
 620.640 +
 620.641 +		HRESULT hret = pDevices[joy].device->
 620.642 +		               GetDeviceState(sizeof(DIJOYSTATE),
 620.643 +		                              (LPVOID)&pDevices[joy].state);
 620.644 +
 620.645 +		if (hret == DIERR_INPUTLOST || hret == DIERR_NOTACQUIRED)
 620.646 +		{
 620.647 +			hret = pDevices[joy].device->Acquire();
 620.648 +
 620.649 +			if (hret == DI_OK)
 620.650 +			{
 620.651 +				if (pDevices[joy].isPolled)
 620.652 +					((LPDIRECTINPUTDEVICE2)pDevices[joy].device)->Poll();
 620.653 +
 620.654 +				hret = pDevices[joy].device->
 620.655 +				       GetDeviceState(sizeof(DIJOYSTATE),
 620.656 +				                      (LPVOID)&pDevices[joy].state);
 620.657 +			}
 620.658 +		}
 620.659 +
 620.660 +		return hret == DI_OK;
 620.661 +	}
 620.662 +
 620.663 +	return true;
 620.664 +}
 620.665 +
 620.666 +static void checkKeyboard()
 620.667 +{
 620.668 +	// mham fix. Patch #1378104
 620.669 +	UCHAR   keystate[256];
 620.670 +	HRESULT hret = pDevices[0].device->Acquire();
 620.671 +
 620.672 +	if (pDevices[0].first)
 620.673 +	{
 620.674 +		pDevices[0].device->GetDeviceState(256, (LPVOID)pDevices[0].data);
 620.675 +		pDevices[0].first = FALSE;
 620.676 +		return;
 620.677 +	}
 620.678 +
 620.679 +	hret = pDevices[0].device->
 620.680 +	       GetDeviceState(256, (LPVOID)keystate);
 620.681 +
 620.682 +	if (hret == DIERR_INPUTLOST || hret == DIERR_NOTACQUIRED)
 620.683 +	{
 620.684 +		return;
 620.685 +	}
 620.686 +
 620.687 +	if (hret == DI_OK)
 620.688 +	{
 620.689 +		for (int i = 0; i < 256; i++)
 620.690 +		{
 620.691 +			if (keystate[i] == pDevices[0].data[i])
 620.692 +				continue;
 620.693 +			if (KEYDOWN(keystate, i))
 620.694 +			{
 620.695 +				SendMessage(GetFocus(), JOYCONFIG_MESSAGE, 0, i);
 620.696 +				break;
 620.697 +			}
 620.698 +		}
 620.699 +	}
 620.700 +	memcpy(pDevices[0].data, keystate, sizeof(UCHAR) * 256);
 620.701 +}
 620.702 +
 620.703 +static void checkJoypads()
 620.704 +{
 620.705 +	DIDEVICEOBJECTINSTANCE di;
 620.706 +
 620.707 +	ZeroMemory(&di, sizeof(DIDEVICEOBJECTINSTANCE));
 620.708 +
 620.709 +	di.dwSize = sizeof(DIDEVICEOBJECTINSTANCE);
 620.710 +
 620.711 +	int i = 0;
 620.712 +
 620.713 +	DIJOYSTATE joystick;
 620.714 +
 620.715 +	for (i = 1; i < numDevices; i++)
 620.716 +	{
 620.717 +		HRESULT hret = pDevices[i].device->Acquire();
 620.718 +
 620.719 +		if (pDevices[i].isPolled)
 620.720 +			((LPDIRECTINPUTDEVICE2)pDevices[i].device)->Poll();
 620.721 +
 620.722 +		hret = pDevices[i].device->GetDeviceState(sizeof(joystick), &joystick);
 620.723 +
 620.724 +		int j;
 620.725 +
 620.726 +		if (pDevices[i].first)
 620.727 +		{
 620.728 +			memcpy(&pDevices[i].state, &joystick, sizeof(joystick));
 620.729 +			pDevices[i].first = FALSE;
 620.730 +			continue;
 620.731 +		}
 620.732 +
 620.733 +		for (j = 0; j < pDevices[i].nButtons; j++)
 620.734 +		{
 620.735 +			if (((pDevices[i].state.rgbButtons[j] ^ joystick.rgbButtons[j])
 620.736 +			     & joystick.rgbButtons[j]) & 0x80)
 620.737 +			{
 620.738 +				HWND focus = GetFocus();
 620.739 +
 620.740 +				SendMessage(focus, JOYCONFIG_MESSAGE, i, j+128);
 620.741 +			}
 620.742 +		}
 620.743 +
 620.744 +		for (j = 0; j < pDevices[i].nAxes && j < 8; j++)
 620.745 +		{
 620.746 +			LONG value = pDevices[i].axis[j].center;
 620.747 +			LONG old   = 0;
 620.748 +			switch (pDevices[i].axis[j].offset)
 620.749 +			{
 620.750 +			case DIJOFS_X:
 620.751 +				value = joystick.lX;
 620.752 +				old   = pDevices[i].state.lX;
 620.753 +				break;
 620.754 +			case DIJOFS_Y:
 620.755 +				value = joystick.lY;
 620.756 +				old   = pDevices[i].state.lY;
 620.757 +				break;
 620.758 +			case DIJOFS_Z:
 620.759 +				value = joystick.lZ;
 620.760 +				old   = pDevices[i].state.lZ;
 620.761 +				break;
 620.762 +			case DIJOFS_RX:
 620.763 +				value = joystick.lRx;
 620.764 +				old   = pDevices[i].state.lRx;
 620.765 +				break;
 620.766 +			case DIJOFS_RY:
 620.767 +				value = joystick.lRy;
 620.768 +				old   = pDevices[i].state.lRy;
 620.769 +				break;
 620.770 +			case DIJOFS_RZ:
 620.771 +				value = joystick.lRz;
 620.772 +				old   = pDevices[i].state.lRz;
 620.773 +				break;
 620.774 +			case DIJOFS_SLIDER(0):
 620.775 +				value = joystick.rglSlider[0];
 620.776 +				old   = pDevices[i].state.rglSlider[0];
 620.777 +				break;
 620.778 +			case DIJOFS_SLIDER(1):
 620.779 +				value = joystick.rglSlider[1];
 620.780 +				old   = pDevices[i].state.rglSlider[1];
 620.781 +				break;
 620.782 +			}
 620.783 +			if (value != old)
 620.784 +			{
 620.785 +				if (value < pDevices[i].axis[j].negative)
 620.786 +					SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<1));
 620.787 +				else if (value > pDevices[i].axis[j].positive)
 620.788 +					SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<1)+1);
 620.789 +			}
 620.790 +		}
 620.791 +
 620.792 +		for (j = 0; j < 4 && j < pDevices[i].nPovs; j++)
 620.793 +		{
 620.794 +			if (LOWORD(pDevices[i].state.rgdwPOV[j]) != LOWORD(joystick.rgdwPOV[j]))
 620.795 +			{
 620.796 +				int state = getPovState(joystick.rgdwPOV[j]);
 620.797 +
 620.798 +				if (state & POV_UP)
 620.799 +					SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x20);
 620.800 +				else if (state & POV_DOWN)
 620.801 +					SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x21);
 620.802 +				else if (state & POV_RIGHT)
 620.803 +					SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x22);
 620.804 +				else if (state & POV_LEFT)
 620.805 +					SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x23);
 620.806 +			}
 620.807 +		}
 620.808 +
 620.809 +		memcpy(&pDevices[i].state, &joystick, sizeof(joystick));
 620.810 +	}
 620.811 +}
 620.812 +
 620.813 +BOOL checkKey(LONG_PTR key)
 620.814 +{
 620.815 +	LONG_PTR dev = (key >> 8);
 620.816 +
 620.817 +	LONG_PTR k = (key & 255);
 620.818 +
 620.819 +	if (dev == 0)
 620.820 +	{
 620.821 +		return KEYDOWN(pDevices[0].data, k);
 620.822 +	}
 620.823 +	else if (dev >= numDevices)
 620.824 +	{
 620.825 +		return FALSE;
 620.826 +	}
 620.827 +	else
 620.828 +	{
 620.829 +		if (k < 16)
 620.830 +		{
 620.831 +			LONG_PTR axis  = k >> 1;
 620.832 +			LONG     value = pDevices[dev].axis[axis].center;
 620.833 +			switch (pDevices[dev].axis[axis].offset)
 620.834 +			{
 620.835 +			case DIJOFS_X:
 620.836 +				value = pDevices[dev].state.lX;
 620.837 +				break;
 620.838 +			case DIJOFS_Y:
 620.839 +				value = pDevices[dev].state.lY;
 620.840 +				break;
 620.841 +			case DIJOFS_Z:
 620.842 +				value = pDevices[dev].state.lZ;
 620.843 +				break;
 620.844 +			case DIJOFS_RX:
 620.845 +				value = pDevices[dev].state.lRx;
 620.846 +				break;
 620.847 +			case DIJOFS_RY:
 620.848 +				value = pDevices[dev].state.lRy;
 620.849 +				break;
 620.850 +			case DIJOFS_RZ:
 620.851 +				value = pDevices[dev].state.lRz;
 620.852 +				break;
 620.853 +			case DIJOFS_SLIDER(0):
 620.854 +				value = pDevices[dev].state.rglSlider[0];
 620.855 +				break;
 620.856 +			case DIJOFS_SLIDER(1):
 620.857 +				value = pDevices[dev].state.rglSlider[1];
 620.858 +				break;
 620.859 +			}
 620.860 +
 620.861 +			if (k & 1)
 620.862 +				return value > pDevices[dev].axis[axis].positive;
 620.863 +			return value < pDevices[dev].axis[axis].negative;
 620.864 +		}
 620.865 +		else if (k < 48)
 620.866 +		{
 620.867 +			LONG_PTR hat   = (k >> 2) & 3;
 620.868 +			int      state = getPovState(pDevices[dev].state.rgdwPOV[hat]);
 620.869 +			BOOL     res   = FALSE;
 620.870 +			switch (k & 3)
 620.871 +			{
 620.872 +			case 0:
 620.873 +				res = state & POV_UP;
 620.874 +				break;
 620.875 +			case 1:
 620.876 +				res = state & POV_DOWN;
 620.877 +				break;
 620.878 +			case 2:
 620.879 +				res = state & POV_RIGHT;
 620.880 +				break;
 620.881 +			case 3:
 620.882 +				res = state & POV_LEFT;
 620.883 +				break;
 620.884 +			}
 620.885 +			return res;
 620.886 +		}
 620.887 +		else if (k  >= 128)
 620.888 +		{
 620.889 +			return pDevices[dev].state.rgbButtons[k-128] & 0x80;
 620.890 +		}
 620.891 +	}
 620.892 +
 620.893 +	return FALSE;
 620.894 +}
 620.895 +
 620.896 +DirectInput::DirectInput()
 620.897 +{
 620.898 +	dinputDLL = NULL;
 620.899 +}
 620.900 +
 620.901 +DirectInput::~DirectInput()
 620.902 +{
 620.903 +	saveSettings();
 620.904 +	if (pDirectInput != NULL)
 620.905 +	{
 620.906 +		if (pDevices)
 620.907 +		{
 620.908 +			for (int i = 0; i < numDevices; i++)
 620.909 +			{
 620.910 +				if (pDevices[i].device)
 620.911 +				{
 620.912 +					pDevices[i].device->Unacquire();
 620.913 +					pDevices[i].device->Release();
 620.914 +					pDevices[i].device = NULL;
 620.915 +				}
 620.916 +			}
 620.917 +			free(pDevices);
 620.918 +			pDevices = NULL;
 620.919 +		}
 620.920 +
 620.921 +		pDirectInput->Release();
 620.922 +		pDirectInput = NULL;
 620.923 +	}
 620.924 +
 620.925 +	if (dinputDLL)
 620.926 +	{
 620.927 +		/**/ ::FreeLibrary(dinputDLL);
 620.928 +		dinputDLL = NULL;
 620.929 +	}
 620.930 +}
 620.931 +
 620.932 +bool DirectInput::initialize()
 620.933 +{
 620.934 +	joyDebug = GetPrivateProfileInt("config",
 620.935 +	                                "joyDebug",
 620.936 +	                                0,
 620.937 +	                                "VBA.ini");
 620.938 +	dinputDLL = /**/ ::LoadLibrary("DINPUT.DLL");
 620.939 +	HRESULT (WINAPI *DInputCreate)(HINSTANCE, DWORD, LPDIRECTINPUT *, IUnknown *);
 620.940 +	if (dinputDLL != NULL)
 620.941 +	{
 620.942 +		DInputCreate = (HRESULT (WINAPI *)(HINSTANCE, DWORD, LPDIRECTINPUT *, IUnknown *))
 620.943 +		               GetProcAddress(dinputDLL, "DirectInputCreateA");
 620.944 +
 620.945 +		if (DInputCreate == NULL)
 620.946 +		{
 620.947 +			directXMessage("DirectInputCreateA");
 620.948 +			return false;
 620.949 +		}
 620.950 +	}
 620.951 +	else
 620.952 +	{
 620.953 +		directXMessage("DINPUT.DLL");
 620.954 +		return false;
 620.955 +	}
 620.956 +
 620.957 +	HRESULT hret = DInputCreate(AfxGetInstanceHandle(),
 620.958 +	                            DIRECTINPUT_VERSION,
 620.959 +	                            &pDirectInput,
 620.960 +	                            NULL);
 620.961 +	if (hret != DI_OK)
 620.962 +	{
 620.963 +		//    errorMessage(myLoadString(IDS_ERROR_DISP_CREATE), hret);
 620.964 +		return false;
 620.965 +	}
 620.966 +
 620.967 +	hret = pDirectInput->EnumDevices(DIDEVTYPE_JOYSTICK,
 620.968 +	                                 DIEnumDevicesCallback2,
 620.969 +	                                 NULL,
 620.970 +	                                 DIEDFL_ATTACHEDONLY);
 620.971 +
 620.972 +	pDevices = (deviceInfo *)calloc(numDevices, sizeof(deviceInfo));
 620.973 +
 620.974 +	hret = pDirectInput->CreateDevice(GUID_SysKeyboard, &pDevices[0].device, NULL);
 620.975 +	pDevices[0].isPolled = false;
 620.976 +	pDevices[0].needed   = true;
 620.977 +	pDevices[0].first    = true;
 620.978 +
 620.979 +	if (hret != DI_OK)
 620.980 +	{
 620.981 +		//    errorMessage(myLoadString(IDS_ERROR_DISP_CREATEDEVICE), hret);
 620.982 +		return false;
 620.983 +	}
 620.984 +
 620.985 +	numDevices = 1;
 620.986 +
 620.987 +	hret = pDirectInput->EnumDevices(DIDEVTYPE_JOYSTICK,
 620.988 +	                                 DIEnumDevicesCallback,
 620.989 +	                                 NULL,
 620.990 +	                                 DIEDFL_ATTACHEDONLY);
 620.991 +
 620.992 +	//  hret = pDevices[0].device->SetCooperativeLevel(hWindow,
 620.993 +	//                                             DISCL_FOREGROUND|
 620.994 +	//                                             DISCL_NONEXCLUSIVE);
 620.995 +
 620.996 +	if (hret != DI_OK)
 620.997 +	{
 620.998 +		//    errorMessage(myLoadString(IDS_ERROR_DISP_LEVEL), hret);
 620.999 +		return false;
620.1000 +	}
620.1001 +
620.1002 +	hret = pDevices[0].device->SetDataFormat(&c_dfDIKeyboard);
620.1003 +
620.1004 +	if (hret != DI_OK)
620.1005 +	{
620.1006 +		//    errorMessage(myLoadString(IDS_ERROR_DISP_DATAFORMAT), hret);
620.1007 +		return false;
620.1008 +	}
620.1009 +
620.1010 +	for (int i = 1; i < numDevices; i++)
620.1011 +	{
620.1012 +		pDevices[i].device->SetDataFormat(&c_dfDIJoystick);
620.1013 +		pDevices[i].needed = false;
620.1014 +		pDevices[i].first  = true;
620.1015 +		currentDevice      = &pDevices[i];
620.1016 +		axisNumber         = 0;
620.1017 +		currentDevice->device->EnumObjects(EnumAxesCallback, NULL, DIDFT_AXIS);
620.1018 +		currentDevice->device->EnumObjects(EnumPovsCallback, NULL, DIDFT_POV);
620.1019 +		if (joyDebug)
620.1020 +		{
620.1021 +			// don't translate. debug only
620.1022 +			winlog("Joystick %2d polled  : %d\n",    i, currentDevice->isPolled);
620.1023 +			winlog("Joystick %2d buttons : %d\n",    i, currentDevice->nButtons);
620.1024 +			winlog("Joystick %2d povs    : %d\n",    i, currentDevice->nPovs);
620.1025 +			winlog("Joystick %2d axes    : %d\n",    i, currentDevice->nAxes);
620.1026 +			for (int j = 0; j < currentDevice->nAxes; j++)
620.1027 +			{
620.1028 +				winlog("Axis %2d offset      : %08lx\n", j, currentDevice->axis[j].
620.1029 +				       offset);
620.1030 +				winlog("Axis %2d center      : %08lx\n", j, currentDevice->axis[j].
620.1031 +				       center);
620.1032 +				winlog("Axis %2d negative    : %08lx\n",   j, currentDevice->axis[j].
620.1033 +				       negative);
620.1034 +				winlog("Axis %2d positive    : %08lx\n",   j, currentDevice->axis[j].
620.1035 +				       positive);
620.1036 +			}
620.1037 +		}
620.1038 +
620.1039 +		currentDevice = NULL;
620.1040 +	}
620.1041 +
620.1042 +	for (int i = 0; i < numDevices; i++)
620.1043 +		pDevices[i].device->Acquire();
620.1044 +
620.1045 +	return true;
620.1046 +}
620.1047 +
620.1048 +bool DirectInput::readDevices()
620.1049 +{
620.1050 +	bool ok = true;
620.1051 +	for (int i = 0; i < numDevices; i++)
620.1052 +	{
620.1053 +		if (pDevices[i].needed)
620.1054 +		{
620.1055 +			ok = (i > 0 ? readJoystick(i) : readKeyboard()) || ok;
620.1056 +		}
620.1057 +	}
620.1058 +	return ok;
620.1059 +}
620.1060 +
620.1061 +bool inputActive = true; // used to disable all input when the window is inactive
620.1062 +
620.1063 +u32 DirectInput::readDevice(int i, bool sensor)
620.1064 +{
620.1065 +	// this old hack is evil
620.1066 +	extern int  systemGetDefaultJoypad();
620.1067 +	extern int32 gbSgbMode, gbSgbMultiplayer;
620.1068 +	if (!(gbSgbMode && gbSgbMultiplayer))
620.1069 +		i = systemGetDefaultJoypad();
620.1070 +
620.1071 +	u32 res = 0;
620.1072 +
620.1073 +	// manual input
620.1074 +	if (inputActive)
620.1075 +	{
620.1076 +		if (checkKey(joypad[i][KEY_BUTTON_A]))
620.1077 +			res |= BUTTON_MASK_A;
620.1078 +		if (checkKey(joypad[i][KEY_BUTTON_B]))
620.1079 +			res |= BUTTON_MASK_B;
620.1080 +		if (checkKey(joypad[i][KEY_BUTTON_SELECT]))
620.1081 +			res |= BUTTON_MASK_SELECT;
620.1082 +		if (checkKey(joypad[i][KEY_BUTTON_START]))
620.1083 +			res |= BUTTON_MASK_START;
620.1084 +		if (checkKey(joypad[i][KEY_RIGHT]))
620.1085 +			res |= BUTTON_MASK_RIGHT;
620.1086 +		if (checkKey(joypad[i][KEY_LEFT]))
620.1087 +			res |= BUTTON_MASK_LEFT;
620.1088 +		if (checkKey(joypad[i][KEY_UP]))
620.1089 +			res |= BUTTON_MASK_UP;
620.1090 +		if (checkKey(joypad[i][KEY_DOWN]))
620.1091 +			res |= BUTTON_MASK_DOWN;
620.1092 +		if (checkKey(joypad[i][KEY_BUTTON_R]))
620.1093 +			res |= BUTTON_MASK_R;
620.1094 +		if (checkKey(joypad[i][KEY_BUTTON_L]))
620.1095 +			res |= BUTTON_MASK_L;
620.1096 +
620.1097 +		// unused
620.1098 +		if (checkKey(motion[KEY_LEFT]))
620.1099 +			res |= BUTTON_MASK_LEFT_MOTION;
620.1100 +		else if (checkKey(motion[KEY_RIGHT]))
620.1101 +			res |= BUTTON_MASK_RIGHT_MOTION;
620.1102 +		if (checkKey(motion[KEY_UP]))
620.1103 +			res |= BUTTON_MASK_UP_MOTION;
620.1104 +		else if (checkKey(motion[KEY_DOWN]))
620.1105 +			res |= BUTTON_MASK_DOWN_MOTION;
620.1106 +	}
620.1107 +
620.1108 +	u32 hackedButtons = 0;
620.1109 +	if (inputActive)
620.1110 +	{
620.1111 +		// the "non-button" buttons (what a hack!)
620.1112 +		if (checkKey(joypad[i][KEY_BUTTON_SPEED]))
620.1113 +			hackedButtons |= BUTTON_MASK_SPEED;
620.1114 +		if (checkKey(joypad[i][KEY_BUTTON_CAPTURE]))
620.1115 +			hackedButtons |= BUTTON_MASK_CAPTURE;
620.1116 +		if (checkKey(joypad[i][KEY_BUTTON_GS]))
620.1117 +			hackedButtons |= BUTTON_MASK_GAMESHARK;
620.1118 +	}
620.1119 +
620.1120 +	extern bool systemIsSpedUp();
620.1121 +	if (systemIsSpedUp())
620.1122 +		hackedButtons |= BUTTON_MASK_SPEED;
620.1123 +
620.1124 +	return res | hackedButtons;
620.1125 +}
620.1126 +
620.1127 +CString DirectInput::getKeyName(LONG_PTR key)
620.1128 +{
620.1129 +	LONG_PTR d = (key >> 8);
620.1130 +	LONG_PTR k = key & 255;
620.1131 +
620.1132 +	DIDEVICEOBJECTINSTANCE di;
620.1133 +
620.1134 +	ZeroMemory(&di, sizeof(DIDEVICEOBJECTINSTANCE));
620.1135 +
620.1136 +	di.dwSize = sizeof(DIDEVICEOBJECTINSTANCE);
620.1137 +
620.1138 +	CString winBuffer = winResLoadString(IDS_ERROR);
620.1139 +
620.1140 +	if (d == 0)
620.1141 +	{
620.1142 +		pDevices[0].device->GetObjectInfo(&di, (DWORD)key, DIPH_BYOFFSET);
620.1143 +		winBuffer = di.tszName;
620.1144 +	}
620.1145 +	else if (d < numDevices)
620.1146 +	{
620.1147 +		if (k < 16)
620.1148 +		{
620.1149 +			if (k < 4)
620.1150 +			{
620.1151 +				switch (k)
620.1152 +				{
620.1153 +				case 0:
620.1154 +					winBuffer.Format(winResLoadString(IDS_JOY_LEFT), d);
620.1155 +					break;
620.1156 +				case 1:
620.1157 +					winBuffer.Format(winResLoadString(IDS_JOY_RIGHT), d);
620.1158 +					break;
620.1159 +				case 2:
620.1160 +					winBuffer.Format(winResLoadString(IDS_JOY_UP), d);
620.1161 +					break;
620.1162 +				case 3:
620.1163 +					winBuffer.Format(winResLoadString(IDS_JOY_DOWN), d);
620.1164 +					break;
620.1165 +				}
620.1166 +			}
620.1167 +			else
620.1168 +			{
620.1169 +				pDevices[d].device->GetObjectInfo(&di,
620.1170 +				                                  pDevices[d].axis[k>>1].offset,
620.1171 +				                                  DIPH_BYOFFSET);
620.1172 +				if (k & 1)
620.1173 +					winBuffer.Format("Joy %d %s +", d, di.tszName);
620.1174 +				else
620.1175 +					winBuffer.Format("Joy %d %s -", d, di.tszName);
620.1176 +			}
620.1177 +		}
620.1178 +		else if (k < 48)
620.1179 +		{
620.1180 +			LONG_PTR hat = (k >> 2) & 3;
620.1181 +			pDevices[d].device->GetObjectInfo(&di,
620.1182 +			                                  (DWORD)DIJOFS_POV(hat),
620.1183 +			                                  DIPH_BYOFFSET);
620.1184 +			char *   dir = "up";
620.1185 +			LONG_PTR dd  = k & 3;
620.1186 +			if (dd == 1)
620.1187 +				dir = "down";
620.1188 +			else if (dd == 2)
620.1189 +				dir = "right";
620.1190 +			else if (dd == 3)
620.1191 +				dir = "left";
620.1192 +			winBuffer.Format("Joy %d %s %s", d, di.tszName, dir);
620.1193 +		}
620.1194 +		else
620.1195 +		{
620.1196 +			pDevices[d].device->GetObjectInfo(&di,
620.1197 +			                                  (DWORD)DIJOFS_BUTTON(k-128),
620.1198 +			                                  DIPH_BYOFFSET);
620.1199 +			winBuffer.Format(winResLoadString(IDS_JOY_BUTTON), d, di.tszName);
620.1200 +		}
620.1201 +	}
620.1202 +	else
620.1203 +	{
620.1204 +		// Joystick isn't plugged in.  We can't decipher k, so just show its value.
620.1205 +		winBuffer.Format("Joy %d (%d)", d, k);
620.1206 +	}
620.1207 +
620.1208 +	return winBuffer;
620.1209 +}
620.1210 +
620.1211 +void DirectInput::checkKeys()
620.1212 +{
620.1213 +	::checkKeys();
620.1214 +}
620.1215 +
620.1216 +Input *newDirectInput()
620.1217 +{
620.1218 +	return new DirectInput;
620.1219 +}
620.1220 +
620.1221 +void DirectInput::checkDevices()
620.1222 +{
620.1223 +	checkJoypads();
620.1224 +	checkKeyboard();
620.1225 +}
620.1226 +
620.1227 +void DirectInput::activate()
620.1228 +{
620.1229 +	for (int i = 0; i < numDevices; i++)
620.1230 +	{
620.1231 +		if (pDevices != NULL && pDevices[i].device != NULL)
620.1232 +			pDevices[i].device->Acquire();
620.1233 +	}
620.1234 +}
620.1235 +
620.1236 +void DirectInput::loadSettings()
620.1237 +{
620.1238 +	winReadKeys();
620.1239 +}
620.1240 +
620.1241 +void DirectInput::saveSettings()
620.1242 +{
620.1243 +	winSaveKeys();
620.1244 +}
620.1245 +
   621.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   621.2 +++ b/src/win32/DirectSound.cpp	Sat Mar 03 10:31:27 2012 -0600
   621.3 @@ -0,0 +1,534 @@
   621.4 +#include "stdafx.h"
   621.5 +#include <mmreg.h>
   621.6 +#include <dsound.h>
   621.7 +
   621.8 +#include "resource.h"
   621.9 +#include "AVIWrite.h"
  621.10 +#include "Sound.h"
  621.11 +#include "WavWriter.h"
  621.12 +#include "VBA.h"
  621.13 +
  621.14 +#include "../gba/GBAGlobals.h"
  621.15 +#include "../gba/GBASound.h"
  621.16 +#include "../common/nesvideos-piece.h"
  621.17 +
  621.18 +extern void directXMessage(const char *);
  621.19 +
  621.20 +class DirectSound : public ISound
  621.21 +{
  621.22 +private:
  621.23 +	HINSTANCE			dsoundDLL;
  621.24 +	LPDIRECTSOUND		pDirectSound;
  621.25 +	LPDIRECTSOUNDBUFFER dsbPrimary;
  621.26 +	LPDIRECTSOUNDBUFFER dsbSecondary;
  621.27 +	LPDIRECTSOUNDNOTIFY dsbNotify;
  621.28 +	HANDLE		 dsbEvent;
  621.29 +	WAVEFORMATEX wfx;
  621.30 +	float		 curRate;
  621.31 +public:
  621.32 +	DirectSound();
  621.33 +	virtual ~DirectSound();
  621.34 +
  621.35 +	bool init();
  621.36 +	void pause();
  621.37 +	void reset();
  621.38 +	void resume();
  621.39 +	void write();
  621.40 +	void setSpeed(float rate);
  621.41 +	bool isPlaying();
  621.42 +	void clearAudioBuffer();
  621.43 +};
  621.44 +
  621.45 +DirectSound::DirectSound()
  621.46 +{
  621.47 +	dsoundDLL	 = NULL;
  621.48 +	pDirectSound = NULL;
  621.49 +	dsbPrimary	 = NULL;
  621.50 +	dsbSecondary = NULL;
  621.51 +	dsbNotify	 = NULL;
  621.52 +	dsbEvent	 = NULL;
  621.53 +}
  621.54 +
  621.55 +DirectSound::~DirectSound()
  621.56 +{
  621.57 +	if (theApp.aviRecorder != NULL)
  621.58 +	{
  621.59 +		delete theApp.aviRecorder;
  621.60 +		theApp.aviRecorder	= NULL;
  621.61 +		theApp.aviRecording = false;
  621.62 +	}
  621.63 +
  621.64 +	if (theApp.soundRecording)
  621.65 +	{
  621.66 +		if (theApp.soundRecorder != NULL)
  621.67 +		{
  621.68 +			delete theApp.soundRecorder;
  621.69 +			theApp.soundRecorder = NULL;
  621.70 +		}
  621.71 +		theApp.soundRecording = false;
  621.72 +	}
  621.73 +
  621.74 +	if (dsbNotify != NULL)
  621.75 +	{
  621.76 +		dsbNotify->Release();
  621.77 +		dsbNotify = NULL;
  621.78 +	}
  621.79 +
  621.80 +	if (dsbEvent != NULL)
  621.81 +	{
  621.82 +		CloseHandle(dsbEvent);
  621.83 +		dsbEvent = NULL;
  621.84 +	}
  621.85 +
  621.86 +	if (pDirectSound != NULL)
  621.87 +	{
  621.88 +		if (dsbPrimary != NULL)
  621.89 +		{
  621.90 +			dsbPrimary->Release();
  621.91 +			dsbPrimary = NULL;
  621.92 +		}
  621.93 +
  621.94 +		if (dsbSecondary != NULL)
  621.95 +		{
  621.96 +			dsbSecondary->Release();
  621.97 +			dsbSecondary = NULL;
  621.98 +		}
  621.99 +
 621.100 +		pDirectSound->Release();
 621.101 +		pDirectSound = NULL;
 621.102 +	}
 621.103 +
 621.104 +	if (dsoundDLL != NULL)
 621.105 +	{
 621.106 +		FreeLibrary(dsoundDLL);
 621.107 +		dsoundDLL = NULL;
 621.108 +	}
 621.109 +}
 621.110 +
 621.111 +bool DirectSound::init()
 621.112 +{
 621.113 +	HRESULT hr;
 621.114 +
 621.115 +	dsoundDLL = LoadLibrary("DSOUND.DLL");
 621.116 +	HRESULT (WINAPI *DSoundCreate)(LPCGUID, LPDIRECTSOUND *, IUnknown *);
 621.117 +	if (dsoundDLL != NULL)
 621.118 +	{
 621.119 +		DSoundCreate = (HRESULT (WINAPI *)(LPCGUID, LPDIRECTSOUND *, IUnknown *))
 621.120 +		               GetProcAddress(dsoundDLL, "DirectSoundCreate");
 621.121 +
 621.122 +		if (DSoundCreate == NULL)
 621.123 +		{
 621.124 +			directXMessage("DirectSoundCreate");
 621.125 +			return false;
 621.126 +		}
 621.127 +	}
 621.128 +	else
 621.129 +	{
 621.130 +		directXMessage("DSOUND.DLL");
 621.131 +		return false;
 621.132 +	}
 621.133 +
 621.134 +	if (FAILED(hr = DSoundCreate(NULL, &pDirectSound, NULL)))
 621.135 +	{
 621.136 +		//    errorMessage(myLoadString(IDS_ERROR_SOUND_CREATE), hr);
 621.137 +		systemMessage(IDS_CANNOT_CREATE_DIRECTSOUND,
 621.138 +		              "Cannot create DirectSound %08x", hr);
 621.139 +		pDirectSound = NULL;
 621.140 +		dsbSecondary = NULL;
 621.141 +		return false;
 621.142 +	}
 621.143 +
 621.144 +	if (FAILED(hr = pDirectSound->SetCooperativeLevel((HWND)*theApp.m_pMainWnd, DSSCL_EXCLUSIVE)))
 621.145 +	{
 621.146 +		//    errorMessage(myLoadString(IDS_ERROR_SOUND_LEVEL), hr);
 621.147 +		systemMessage(IDS_CANNOT_SETCOOPERATIVELEVEL,
 621.148 +		              "Cannot SetCooperativeLevel %08x", hr);
 621.149 +		return false;
 621.150 +	}
 621.151 +
 621.152 +	DSBUFFERDESC dsbdesc;
 621.153 +	ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC));
 621.154 +	dsbdesc.dwSize	= sizeof(DSBUFFERDESC);
 621.155 +	dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
 621.156 +
 621.157 +	if (FAILED(hr = pDirectSound->CreateSoundBuffer(&dsbdesc, &dsbPrimary, NULL)))
 621.158 +	{
 621.159 +		//    errorMessage(myLoadString(IDS_ERROR_SOUND_BUFFER),hr);
 621.160 +		systemMessage(IDS_CANNOT_CREATESOUNDBUFFER,
 621.161 +		              "Cannot CreateSoundBuffer %08x", hr);
 621.162 +		return false;
 621.163 +	}
 621.164 +
 621.165 +	// Set primary buffer format
 621.166 +
 621.167 +	memset(&wfx, 0, sizeof(WAVEFORMATEX));
 621.168 +	wfx.wFormatTag = WAVE_FORMAT_PCM;
 621.169 +	wfx.nChannels  = 2;
 621.170 +	switch (soundQuality)
 621.171 +	{
 621.172 +	case 2:
 621.173 +		wfx.nSamplesPerSec	= 22050;
 621.174 +		soundBufferLen		= 736 * 2;
 621.175 +		soundBufferTotalLen = 7360 * 2;
 621.176 +		break;
 621.177 +	case 4:
 621.178 +		wfx.nSamplesPerSec	= 11025;
 621.179 +		soundBufferLen		= 368 * 2;
 621.180 +		soundBufferTotalLen = 3680 * 2;
 621.181 +		break;
 621.182 +	default:
 621.183 +		soundQuality		= 1;
 621.184 +		wfx.nSamplesPerSec	= 44100;
 621.185 +		soundBufferLen		= 1470 * 2;
 621.186 +		soundBufferTotalLen = 14700 * 2;
 621.187 +	}
 621.188 +	wfx.wBitsPerSample	= 16;
 621.189 +	wfx.nBlockAlign		= (wfx.wBitsPerSample / 8) * wfx.nChannels;
 621.190 +	wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
 621.191 +
 621.192 +	if (FAILED(hr = dsbPrimary->SetFormat(&wfx)))
 621.193 +	{
 621.194 +		//    errorMessage(myLoadString(IDS_ERROR_SOUND_PRIMARY),hr);
 621.195 +		systemMessage(IDS_CANNOT_SETFORMAT_PRIMARY,
 621.196 +		              "Cannot SetFormat for primary %08x", hr);
 621.197 +		return false;
 621.198 +	}
 621.199 +
 621.200 +	ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC));
 621.201 +	dsbdesc.dwSize		  = sizeof(DSBUFFERDESC);
 621.202 +	dsbdesc.dwFlags		  = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_CTRLFREQUENCY | DSBCAPS_GLOBALFOCUS;
 621.203 +	dsbdesc.dwBufferBytes = soundBufferTotalLen;
 621.204 +	dsbdesc.lpwfxFormat	  = &wfx;
 621.205 +
 621.206 +	if (FAILED(hr = pDirectSound->CreateSoundBuffer(&dsbdesc, &dsbSecondary, NULL)))
 621.207 +	{
 621.208 +		bool ok = false;
 621.209 +		while (dsbdesc.dwFlags != DSBCAPS_GETCURRENTPOSITION2)
 621.210 +		{
 621.211 +			if (dsbdesc.dwFlags & DSBCAPS_CTRLFREQUENCY)
 621.212 +				dsbdesc.dwFlags ^= DSBCAPS_CTRLFREQUENCY;
 621.213 +			else if (dsbdesc.dwFlags & DSBCAPS_GLOBALFOCUS)
 621.214 +				dsbdesc.dwFlags ^= DSBCAPS_GLOBALFOCUS;
 621.215 +			else if (dsbdesc.dwFlags & DSBCAPS_CTRLPOSITIONNOTIFY)
 621.216 +				dsbdesc.dwFlags ^= DSBCAPS_CTRLPOSITIONNOTIFY;
 621.217 +			if (SUCCEEDED(hr = pDirectSound->CreateSoundBuffer(&dsbdesc, &dsbSecondary, NULL)))
 621.218 +			{
 621.219 +				ok = true;
 621.220 +				break;
 621.221 +			}
 621.222 +		}
 621.223 +		if (!ok)
 621.224 +		{
 621.225 +			systemMessage(IDS_CANNOT_CREATESOUNDBUFFER_SEC, "Cannot CreateSoundBuffer secondary %08x", hr);
 621.226 +			return false;
 621.227 +		}
 621.228 +
 621.229 +		dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2;
 621.230 +	}
 621.231 +
 621.232 +	dsbSecondary->SetCurrentPosition(0);
 621.233 +
 621.234 +	if (!theApp.useOldSync)
 621.235 +	{
 621.236 +		hr = dsbSecondary->QueryInterface(IID_IDirectSoundNotify,
 621.237 +		                                  (void * *)&dsbNotify);
 621.238 +		if (!FAILED(hr))
 621.239 +		{
 621.240 +			dsbEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
 621.241 +
 621.242 +			DSBPOSITIONNOTIFY notify[10];
 621.243 +
 621.244 +			for (int i = 0; i < 10; i++)
 621.245 +			{
 621.246 +				notify[i].dwOffset	   = i * soundBufferLen;
 621.247 +				notify[i].hEventNotify = dsbEvent;
 621.248 +			}
 621.249 +			if (FAILED(dsbNotify->SetNotificationPositions(10, notify)))
 621.250 +			{
 621.251 +				dsbNotify->Release();
 621.252 +				dsbNotify = NULL;
 621.253 +				CloseHandle(dsbEvent);
 621.254 +				dsbEvent = NULL;
 621.255 +			}
 621.256 +		}
 621.257 +	}
 621.258 +
 621.259 +	hr = dsbPrimary->Play(0, 0, DSBPLAY_LOOPING);
 621.260 +
 621.261 +	if (FAILED(hr))
 621.262 +	{
 621.263 +		//    errorMessage(myLoadString(IDS_ERROR_SOUND_PLAYPRIM), hr);
 621.264 +		systemMessage(IDS_CANNOT_PLAY_PRIMARY, "Cannot Play primary %08x", hr);
 621.265 +		return false;
 621.266 +	}
 621.267 +
 621.268 +	systemSoundOn = true;
 621.269 +
 621.270 +	return true;
 621.271 +}
 621.272 +
 621.273 +void DirectSound::setSpeed(float rate)
 621.274 +{
 621.275 +	if (dsbSecondary == NULL || wfx.nSamplesPerSec <= 0)
 621.276 +		return;
 621.277 +
 621.278 +	if (rate != curRate)
 621.279 +	{
 621.280 +		curRate = rate;
 621.281 +
 621.282 +		if (rate > 4.0f)
 621.283 +			rate = 4.0f;
 621.284 +		if (rate < 0.06f)
 621.285 +			rate = 0.06f;
 621.286 +
 621.287 +		dsbSecondary->SetFrequency((DWORD)((float)wfx.nSamplesPerSec * rate));
 621.288 +	}
 621.289 +}
 621.290 +
 621.291 +void DirectSound::pause()
 621.292 +{
 621.293 +	if (dsbSecondary != NULL)
 621.294 +	{
 621.295 +		DWORD status = 0;
 621.296 +		dsbSecondary->GetStatus(&status);
 621.297 +
 621.298 +		if (status & DSBSTATUS_PLAYING)
 621.299 +		{
 621.300 +			//systemScreenMessage("sound stopped (pause)!", 3);
 621.301 +			dsbSecondary->Stop();
 621.302 +		}
 621.303 +	}
 621.304 +}
 621.305 +
 621.306 +bool DirectSound::isPlaying()
 621.307 +{
 621.308 +	if (dsbSecondary != NULL)
 621.309 +	{
 621.310 +		DWORD status = 0;
 621.311 +		dsbSecondary->GetStatus(&status);
 621.312 +
 621.313 +		if (status & DSBSTATUS_PLAYING)
 621.314 +		{
 621.315 +			return true;
 621.316 +		}
 621.317 +	}
 621.318 +	return false;
 621.319 +}
 621.320 +
 621.321 +void DirectSound::reset()
 621.322 +{
 621.323 +	if (dsbSecondary)
 621.324 +	{
 621.325 +		//systemScreenMessage("sound stopped (reset)!", 3);
 621.326 +		dsbSecondary->Stop();
 621.327 +		dsbSecondary->SetCurrentPosition(0);
 621.328 +	}
 621.329 +}
 621.330 +
 621.331 +void DirectSound::resume()
 621.332 +{
 621.333 +	if (dsbSecondary != NULL)
 621.334 +	{
 621.335 +		dsbSecondary->Play(0, 0, DSBPLAY_LOOPING);
 621.336 +	}
 621.337 +}
 621.338 +
 621.339 +long linearFrameCount	   = 0;
 621.340 +long linearSoundByteCount  = 0;
 621.341 +long linearSoundFrameCount = 0;
 621.342 +
 621.343 +void DirectSound::write()
 621.344 +{
 621.345 +	int	   len = soundBufferLen;
 621.346 +	LPVOID lpvPtr1;
 621.347 +	DWORD  dwBytes1;
 621.348 +	LPVOID lpvPtr2;
 621.349 +	DWORD  dwBytes2;
 621.350 +
 621.351 +	do
 621.352 +	{
 621.353 +		linearSoundByteCount += len;
 621.354 +		if (wfx.nAvgBytesPerSec)
 621.355 +			linearSoundFrameCount = 60 * linearSoundByteCount / wfx.nAvgBytesPerSec;
 621.356 +
 621.357 +		if (pDirectSound != NULL)
 621.358 +		{
 621.359 +			if (theApp.soundRecording)
 621.360 +			{
 621.361 +				if (dsbSecondary)
 621.362 +				{
 621.363 +					if (theApp.soundRecorder == NULL)
 621.364 +					{
 621.365 +						theApp.soundRecorder = new WavWriter;
 621.366 +						WAVEFORMATEX format;
 621.367 +						dsbSecondary->GetFormat(&format, sizeof(format), NULL);
 621.368 +						if (theApp.soundRecorder->Open(theApp.soundRecordName))
 621.369 +							theApp.soundRecorder->SetFormat(&format);
 621.370 +					}
 621.371 +				}
 621.372 +
 621.373 +				if (theApp.soundRecorder)
 621.374 +				{
 621.375 +					theApp.soundRecorder->AddSound((u8 *)soundFinalWave, len);
 621.376 +				}
 621.377 +			}
 621.378 +
 621.379 +			if (theApp.nvAudioLog)
 621.380 +			{
 621.381 +				NESVideoLoggingAudio((u8 *)soundFinalWave, wfx.nSamplesPerSec, wfx.wBitsPerSample, wfx.nChannels, len /
 621.382 +				                     (wfx.nChannels * (wfx.wBitsPerSample / 8)));
 621.383 +			}
 621.384 +
 621.385 +			// alternate avi record routine has been added in VBA.cpp
 621.386 +			if (!theApp.altAviRecordMethod && theApp.aviRecording)
 621.387 +			{
 621.388 +				if (theApp.aviRecorder && !theApp.aviRecorder->IsPaused())
 621.389 +				{
 621.390 +					if (dsbSecondary)
 621.391 +					{
 621.392 +						if (!theApp.aviRecorder->IsSoundAdded())
 621.393 +						{
 621.394 +							WAVEFORMATEX format;
 621.395 +							dsbSecondary->GetFormat(&format, sizeof(format), NULL);
 621.396 +							theApp.aviRecorder->SetSoundFormat(&format);
 621.397 +						}
 621.398 +					}
 621.399 +
 621.400 +					theApp.aviRecorder->AddSound((u8 *)soundFinalWave, len);
 621.401 +				}
 621.402 +			}
 621.403 +		}
 621.404 +	}
 621.405 +	while (linearSoundFrameCount <= linearFrameCount);
 621.406 +
 621.407 +	// arbitrarily wrap counters at 10000 frames to avoid mismatching wrap-around freeze
 621.408 +	if (linearSoundFrameCount > 10000 && linearFrameCount > 10000)
 621.409 +	{
 621.410 +		linearFrameCount	 -= 10000;
 621.411 +		linearSoundByteCount -= wfx.nAvgBytesPerSec * 10000 / 60;
 621.412 +		linearSoundFrameCount = 60 * linearSoundByteCount / wfx.nAvgBytesPerSec;
 621.413 +	}
 621.414 +
 621.415 +	if (!pDirectSound)
 621.416 +		return;
 621.417 +
 621.418 +	HRESULT hr;
 621.419 +
 621.420 +	bool fastForward = speedup;
 621.421 +#if (defined(WIN32) && !defined(SDL))
 621.422 +	fastForward |= theApp.frameSearchSkipping;
 621.423 +#endif
 621.424 +
 621.425 +	// slows down emulator to match up with the sound speed
 621.426 +	if (!fastForward && synchronize && !(theApp.throttle > 100 && theApp.accuratePitchThrottle)
 621.427 +		&& theApp.throttle >= 6 && theApp.throttle <= 400)
 621.428 +	{
 621.429 +		DWORD status = 0;
 621.430 +		hr = dsbSecondary->GetStatus(&status);
 621.431 +		if (status & DSBSTATUS_PLAYING)
 621.432 +		{
 621.433 +			if (!soundPaused)
 621.434 +			{
 621.435 +				DWORD play;
 621.436 +				while (true)
 621.437 +				{
 621.438 +					dsbSecondary->GetCurrentPosition(&play, NULL);
 621.439 +
 621.440 +					if (soundNextPosition + soundBufferLen < soundBufferTotalLen)
 621.441 +					{
 621.442 +						if (play < soundNextPosition
 621.443 +						    || play > soundNextPosition + soundBufferLen)
 621.444 +							break;
 621.445 +					}
 621.446 +					else
 621.447 +					{
 621.448 +						if (play < soundNextPosition
 621.449 +						    && play > (soundNextPosition + soundBufferLen) % soundBufferTotalLen)
 621.450 +							break;
 621.451 +					}
 621.452 +
 621.453 +					if (dsbEvent)
 621.454 +					{
 621.455 +						WaitForSingleObject(dsbEvent, 50);
 621.456 +					}
 621.457 +				}
 621.458 +			}
 621.459 +		}
 621.460 +		else
 621.461 +		{
 621.462 +			soundPaused = 1;
 621.463 +		}
 621.464 +	}
 621.465 +
 621.466 +	// Obtain memory address of write block. This will be in two parts
 621.467 +	// if the block wraps around.
 621.468 +	hr = dsbSecondary->Lock(soundNextPosition, soundBufferLen,
 621.469 +	                        &lpvPtr1, &dwBytes1, &lpvPtr2, &dwBytes2,
 621.470 +	                        0);
 621.471 +
 621.472 +	if (FAILED(hr))
 621.473 +	{
 621.474 +		char str [256];
 621.475 +		sprintf(str, "Locking secondary failed with %d", hr);
 621.476 +		systemScreenMessage(str);
 621.477 +	}
 621.478 +
 621.479 +	// If DSERR_BUFFERLOST is returned, restore and retry lock.
 621.480 +	if (DSERR_BUFFERLOST == hr)
 621.481 +	{
 621.482 +		dsbSecondary->Restore();
 621.483 +		hr = dsbSecondary->Lock(soundNextPosition, soundBufferLen,
 621.484 +		                        &lpvPtr1, &dwBytes1, &lpvPtr2, &dwBytes2,
 621.485 +		                        0);
 621.486 +	}
 621.487 +
 621.488 +	if (SUCCEEDED(hr))
 621.489 +	{
 621.490 +		if (theApp.muteFrameAdvance && theApp.winPauseNextFrame || theApp.winMuteForNow)
 621.491 +		{
 621.492 +			// Write 0 to pointers.
 621.493 +			if (NULL != lpvPtr1)
 621.494 +				ZeroMemory(lpvPtr1, dwBytes1);
 621.495 +			if (NULL != lpvPtr2)
 621.496 +				ZeroMemory(lpvPtr2, dwBytes2);
 621.497 +		}
 621.498 +		else
 621.499 +		{
 621.500 +			// Write to pointers.
 621.501 +			if (NULL != lpvPtr1)
 621.502 +				CopyMemory(lpvPtr1, soundFinalWave, dwBytes1);
 621.503 +			if (NULL != lpvPtr2)
 621.504 +				CopyMemory(lpvPtr2, soundFinalWave + dwBytes1, dwBytes2);
 621.505 +		}
 621.506 +
 621.507 +		// Release the data back to DirectSound.
 621.508 +		hr = dsbSecondary->Unlock(lpvPtr1, dwBytes1, lpvPtr2,
 621.509 +		                          dwBytes2);
 621.510 +	}
 621.511 +
 621.512 +	soundNextPosition += soundBufferLen;
 621.513 +	soundNextPosition %= soundBufferTotalLen;
 621.514 +}
 621.515 +
 621.516 +void DirectSound::clearAudioBuffer()
 621.517 +{
 621.518 +	LPVOID	lpvPtr1;
 621.519 +	DWORD	dwBytes1;
 621.520 +	LPVOID	lpvPtr2;
 621.521 +	DWORD	dwBytes2;
 621.522 +	HRESULT hr = dsbSecondary->Lock(0, soundBufferTotalLen, &lpvPtr1, &dwBytes1, &lpvPtr2, &dwBytes2, 0);
 621.523 +	if (!FAILED(hr))
 621.524 +	{
 621.525 +		if (lpvPtr1)
 621.526 +			memset(lpvPtr1, 0, dwBytes1);
 621.527 +		if (lpvPtr2)
 621.528 +			memset(lpvPtr2, 0, dwBytes2);
 621.529 +		hr = dsbSecondary->Unlock(lpvPtr1, dwBytes1, lpvPtr2, dwBytes2);
 621.530 +	}
 621.531 +}
 621.532 +
 621.533 +ISound *newDirectSound()
 621.534 +{
 621.535 +	return new DirectSound();
 621.536 +}
 621.537 +
   622.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   622.2 +++ b/src/win32/Directories.cpp	Sat Mar 03 10:31:27 2012 -0600
   622.3 @@ -0,0 +1,420 @@
   622.4 +// Directories.cpp : implementation file
   622.5 +//
   622.6 +
   622.7 +#include "stdafx.h"
   622.8 +#include <shlobj.h>
   622.9 +#include "resource.h"
  622.10 +#include "Directories.h"
  622.11 +#include "Reg.h"
  622.12 +#include "WinMiscUtil.h"
  622.13 +#include "WinResUtil.h"
  622.14 +
  622.15 +/////////////////////////////////////////////////////////////////////////////
  622.16 +// Directories dialog
  622.17 +
  622.18 +static int CALLBACK browseCallbackProc(HWND hWnd, UINT msg,
  622.19 +                                       LPARAM l, LPARAM data)
  622.20 +{
  622.21 +	char *buffer = (char *)data;
  622.22 +	switch (msg)
  622.23 +	{
  622.24 +	case BFFM_INITIALIZED:
  622.25 +		if (buffer[0])
  622.26 +			SendMessage(hWnd, BFFM_SETSELECTION, TRUE, (LPARAM)buffer);
  622.27 +		break;
  622.28 +	default:
  622.29 +		break;
  622.30 +	}
  622.31 +	return 0;
  622.32 +}
  622.33 +
  622.34 +Directories::Directories(CWnd*pParent /*=NULL*/)
  622.35 +	: CDialog(Directories::IDD, pParent)
  622.36 +{
  622.37 +	//{{AFX_DATA_INIT(Directories)
  622.38 +	// NOTE: the ClassWizard will add member initialization here
  622.39 +	//}}AFX_DATA_INIT
  622.40 +}
  622.41 +
  622.42 +void Directories::DoDataExchange(CDataExchange*pDX)
  622.43 +{
  622.44 +	CDialog::DoDataExchange(pDX);
  622.45 +	//{{AFX_DATA_MAP(Directories)
  622.46 +	DDX_Control(pDX, IDC_ROM_PATH, m_romPath);
  622.47 +	DDX_Control(pDX, IDC_GBXROM_PATH, m_gbxromPath);
  622.48 +	DDX_Control(pDX, IDC_BATTERY_PATH, m_batteryPath);
  622.49 +	DDX_Control(pDX, IDC_SAVE_PATH, m_savePath);
  622.50 +	DDX_Control(pDX, IDC_MOVIE_PATH, m_moviePath);
  622.51 +	DDX_Control(pDX, IDC_CHEAT_PATH, m_cheatPath);
  622.52 +	DDX_Control(pDX, IDC_IPS_PATH, m_ipsPath);
  622.53 +	DDX_Control(pDX, IDC_LUA_PATH, m_luaPath);
  622.54 +	DDX_Control(pDX, IDC_AVI_PATH, m_aviPath);
  622.55 +	DDX_Control(pDX, IDC_WAV_PATH, m_wavPath);
  622.56 +	DDX_Control(pDX, IDC_CAPTURE_PATH, m_capturePath);
  622.57 +	DDX_Control(pDX, IDC_WATCH_PATH, m_watchPath);
  622.58 +	//}}AFX_DATA_MAP
  622.59 +}
  622.60 +
  622.61 +BEGIN_MESSAGE_MAP(Directories, CDialog)
  622.62 +//{{AFX_MSG_MAP(Directories)
  622.63 +ON_BN_CLICKED(IDC_ROM_DIR, OnRomDir)
  622.64 +ON_BN_CLICKED(IDC_ROM_DIR_RESET, OnRomDirReset)
  622.65 +ON_BN_CLICKED(IDC_GBXROM_DIR, OnGBxRomDir)
  622.66 +ON_BN_CLICKED(IDC_GBXROM_DIR_RESET, OnGBxRomDirReset)
  622.67 +ON_BN_CLICKED(IDC_BATTERY_DIR, OnBatteryDir)
  622.68 +ON_BN_CLICKED(IDC_BATTERY_DIR_RESET, OnBatteryDirReset)
  622.69 +ON_BN_CLICKED(IDC_SAVE_DIR, OnSaveDir)
  622.70 +ON_BN_CLICKED(IDC_SAVE_DIR_RESET, OnSaveDirReset)
  622.71 +ON_BN_CLICKED(IDC_MOVIE_DIR, OnMovieDir)
  622.72 +ON_BN_CLICKED(IDC_MOVIE_DIR_RESET, OnMovieDirReset)
  622.73 +ON_BN_CLICKED(IDC_CHEAT_DIR, OnCheatDir)
  622.74 +ON_BN_CLICKED(IDC_CHEAT_DIR_RESET, OnCheatDirReset)
  622.75 +ON_BN_CLICKED(IDC_IPS_DIR, OnIpsDir)
  622.76 +ON_BN_CLICKED(IDC_IPS_DIR_RESET, OnIpsDirReset)
  622.77 +ON_BN_CLICKED(IDC_LUA_DIR, OnLuaDir)
  622.78 +ON_BN_CLICKED(IDC_LUA_DIR_RESET, OnLuaDirReset)
  622.79 +ON_BN_CLICKED(IDC_AVI_DIR, OnAviDir)
  622.80 +ON_BN_CLICKED(IDC_AVI_DIR_RESET, OnAviDirReset)
  622.81 +ON_BN_CLICKED(IDC_WAV_DIR, OnWavDir)
  622.82 +ON_BN_CLICKED(IDC_WAV_DIR_RESET, OnWavDirReset)
  622.83 +ON_BN_CLICKED(IDC_CAPTURE_DIR, OnCaptureDir)
  622.84 +ON_BN_CLICKED(IDC_CAPTURE_DIR_RESET, OnCaptureDirReset)
  622.85 +ON_BN_CLICKED(IDC_WATCH_DIR, OnWatchDir)
  622.86 +ON_BN_CLICKED(IDC_WATCH_DIR_RESET, OnWatchDirReset)
  622.87 +//}}AFX_MSG_MAP
  622.88 +END_MESSAGE_MAP()
  622.89 +
  622.90 +/////////////////////////////////////////////////////////////////////////////
  622.91 +// Directories message handlers
  622.92 +
  622.93 +BOOL Directories::OnInitDialog()
  622.94 +{
  622.95 +	CDialog::OnInitDialog();
  622.96 +
  622.97 +	CString p = regQueryStringValue(IDS_ROM_DIR, NULL);
  622.98 +	if (!p.IsEmpty())
  622.99 +		GetDlgItem(IDC_ROM_PATH)->SetWindowText(p);
 622.100 +
 622.101 +	p = regQueryStringValue(IDS_GBXROM_DIR, NULL);
 622.102 +	if (!p.IsEmpty())
 622.103 +		GetDlgItem(IDC_GBXROM_PATH)->SetWindowText(p);
 622.104 +
 622.105 +	p = regQueryStringValue(IDS_BATTERY_DIR, NULL);
 622.106 +	if (!p.IsEmpty())
 622.107 +		GetDlgItem(IDC_BATTERY_PATH)->SetWindowText(p);
 622.108 +
 622.109 +	p = regQueryStringValue(IDS_SAVE_DIR, NULL);
 622.110 +	if (!p.IsEmpty())
 622.111 +		GetDlgItem(IDC_SAVE_PATH)->SetWindowText(p);
 622.112 +
 622.113 +	p = regQueryStringValue(IDS_MOVIE_DIR, NULL);
 622.114 +	if (!p.IsEmpty())
 622.115 +		GetDlgItem(IDC_MOVIE_PATH)->SetWindowText(p);
 622.116 +
 622.117 +	p = regQueryStringValue(IDS_CHEAT_DIR, NULL);
 622.118 +	if (!p.IsEmpty())
 622.119 +		GetDlgItem(IDC_CHEAT_PATH)->SetWindowText(p);
 622.120 +
 622.121 +	p = regQueryStringValue(IDS_IPS_DIR, NULL);
 622.122 +	if (!p.IsEmpty())
 622.123 +		GetDlgItem(IDC_IPS_PATH)->SetWindowText(p);
 622.124 +
 622.125 +	p = regQueryStringValue(IDS_LUA_DIR, NULL);
 622.126 +	if (!p.IsEmpty())
 622.127 +		GetDlgItem(IDC_LUA_PATH)->SetWindowText(p);
 622.128 +
 622.129 +	p = regQueryStringValue(IDS_AVI_DIR, NULL);
 622.130 +	if (!p.IsEmpty())
 622.131 +		GetDlgItem(IDC_AVI_PATH)->SetWindowText(p);
 622.132 +
 622.133 +	p = regQueryStringValue(IDS_WAV_DIR, NULL);
 622.134 +	if (!p.IsEmpty())
 622.135 +		GetDlgItem(IDC_WAV_PATH)->SetWindowText(p);
 622.136 +
 622.137 +	p = regQueryStringValue(IDS_CAPTURE_DIR, NULL);
 622.138 +	if (!p.IsEmpty())
 622.139 +		GetDlgItem(IDC_CAPTURE_PATH)->SetWindowText(p);
 622.140 +
 622.141 +	p = regQueryStringValue(IDS_WATCH_DIR, NULL);
 622.142 +	if (!p.IsEmpty())
 622.143 +		GetDlgItem(IDC_WATCH_PATH)->SetWindowText(p);
 622.144 +
 622.145 +	CenterWindow();
 622.146 +
 622.147 +	return TRUE; // return TRUE unless you set the focus to a control
 622.148 +	             // EXCEPTION: OCX Property Pages should return FALSE
 622.149 +}
 622.150 +
 622.151 +void Directories::OnRomDir()
 622.152 +{
 622.153 +	m_romPath.GetWindowText(initialFolderDir);
 622.154 +	CString p = browseForDir(winResLoadString(IDS_SELECT_ROM_DIR));
 622.155 +	if (!p.IsEmpty())
 622.156 +		m_romPath.SetWindowText(p);
 622.157 +}
 622.158 +
 622.159 +void Directories::OnRomDirReset()
 622.160 +{
 622.161 +	m_romPath.SetWindowText("");
 622.162 +}
 622.163 +
 622.164 +void Directories::OnGBxRomDir()
 622.165 +{
 622.166 +	m_gbxromPath.GetWindowText(initialFolderDir);
 622.167 +	CString p = browseForDir(winResLoadString(IDS_SELECT_GBXROM_DIR));
 622.168 +	if (!p.IsEmpty())
 622.169 +		m_gbxromPath.SetWindowText(p);
 622.170 +}
 622.171 +
 622.172 +void Directories::OnGBxRomDirReset()
 622.173 +{
 622.174 +	m_gbxromPath.SetWindowText("");
 622.175 +}
 622.176 +
 622.177 +void Directories::OnBatteryDir()
 622.178 +{
 622.179 +	m_batteryPath.GetWindowText(initialFolderDir);
 622.180 +	CString p = browseForDir(winResLoadString(IDS_SELECT_BATTERY_DIR));
 622.181 +	if (!p.IsEmpty())
 622.182 +		m_batteryPath.SetWindowText(p);
 622.183 +}
 622.184 +
 622.185 +void Directories::OnBatteryDirReset()
 622.186 +{
 622.187 +	m_batteryPath.SetWindowText("");
 622.188 +}
 622.189 +
 622.190 +void Directories::OnSaveDir()
 622.191 +{
 622.192 +	m_savePath.GetWindowText(initialFolderDir);
 622.193 +	CString p = browseForDir(winResLoadString(IDS_SELECT_SAVE_DIR));
 622.194 +	if (!p.IsEmpty())
 622.195 +		m_savePath.SetWindowText(p);
 622.196 +}
 622.197 +
 622.198 +void Directories::OnSaveDirReset()
 622.199 +{
 622.200 +	m_savePath.SetWindowText("");
 622.201 +}
 622.202 +
 622.203 +void Directories::OnMovieDir()
 622.204 +{
 622.205 +	m_moviePath.GetWindowText(initialFolderDir);
 622.206 +	CString p = browseForDir(winResLoadString(IDS_SELECT_MOVIE_DIR));
 622.207 +	if (!p.IsEmpty())
 622.208 +		m_moviePath.SetWindowText(p);
 622.209 +}
 622.210 +
 622.211 +void Directories::OnMovieDirReset()
 622.212 +{
 622.213 +	m_moviePath.SetWindowText("");
 622.214 +}
 622.215 +
 622.216 +void Directories::OnCheatDir()
 622.217 +{
 622.218 +	m_cheatPath.GetWindowText(initialFolderDir);
 622.219 +	CString p = browseForDir(winResLoadString(IDS_SELECT_CHEAT_DIR));
 622.220 +	if (!p.IsEmpty())
 622.221 +		m_cheatPath.SetWindowText(p);
 622.222 +}
 622.223 +
 622.224 +void Directories::OnCheatDirReset()
 622.225 +{
 622.226 +	m_cheatPath.SetWindowText("");
 622.227 +}
 622.228 +
 622.229 +void Directories::OnLuaDir()
 622.230 +{
 622.231 +	m_luaPath.GetWindowText(initialFolderDir);
 622.232 +	CString p = browseForDir(winResLoadString(IDS_SELECT_LUA_DIR));
 622.233 +	if (!p.IsEmpty())
 622.234 +		m_luaPath.SetWindowText(p);
 622.235 +}
 622.236 +
 622.237 +void Directories::OnLuaDirReset()
 622.238 +{
 622.239 +	m_luaPath.SetWindowText("");
 622.240 +}
 622.241 +
 622.242 +void Directories::OnAviDir()
 622.243 +{
 622.244 +	m_aviPath.GetWindowText(initialFolderDir);
 622.245 +	CString p = browseForDir(winResLoadString(IDS_SELECT_AVI_DIR));
 622.246 +	if (!p.IsEmpty())
 622.247 +		m_aviPath.SetWindowText(p);
 622.248 +}
 622.249 +
 622.250 +void Directories::OnAviDirReset()
 622.251 +{
 622.252 +	m_aviPath.SetWindowText("");
 622.253 +}
 622.254 +
 622.255 +void Directories::OnWavDir()
 622.256 +{
 622.257 +	m_wavPath.GetWindowText(initialFolderDir);
 622.258 +	CString p = browseForDir(winResLoadString(IDS_SELECT_WAV_DIR));
 622.259 +	if (!p.IsEmpty())
 622.260 +		m_wavPath.SetWindowText(p);
 622.261 +}
 622.262 +
 622.263 +void Directories::OnWavDirReset()
 622.264 +{
 622.265 +	m_wavPath.SetWindowText("");
 622.266 +}
 622.267 +
 622.268 +void Directories::OnCaptureDir()
 622.269 +{
 622.270 +	m_capturePath.GetWindowText(initialFolderDir);
 622.271 +	CString p = browseForDir(winResLoadString(IDS_SELECT_CAPTURE_DIR));
 622.272 +	if (!p.IsEmpty())
 622.273 +		m_capturePath.SetWindowText(p);
 622.274 +}
 622.275 +
 622.276 +void Directories::OnCaptureDirReset()
 622.277 +{
 622.278 +	m_capturePath.SetWindowText("");
 622.279 +}
 622.280 +
 622.281 +void Directories::OnIpsDir()
 622.282 +{
 622.283 +	m_ipsPath.GetWindowText(initialFolderDir);
 622.284 +	CString p = browseForDir(winResLoadString(IDS_SELECT_IPS_DIR));
 622.285 +	if (!p.IsEmpty())
 622.286 +		m_ipsPath.SetWindowText(p);
 622.287 +}
 622.288 +
 622.289 +void Directories::OnIpsDirReset()
 622.290 +{
 622.291 +	m_ipsPath.SetWindowText("");
 622.292 +}
 622.293 +
 622.294 +void Directories::OnWatchDir()
 622.295 +{
 622.296 +	m_watchPath.GetWindowText(initialFolderDir);
 622.297 +	CString p = browseForDir(winResLoadString(IDS_SELECT_WATCH_DIR));
 622.298 +	if(!p.IsEmpty())
 622.299 +		m_watchPath.SetWindowText(p);
 622.300 +}
 622.301 +
 622.302 +void Directories::OnWatchDirReset()
 622.303 +{
 622.304 +	m_watchPath.SetWindowText("");
 622.305 +}
 622.306 +
 622.307 +void Directories::OnCancel()
 622.308 +{
 622.309 +	EndDialog(FALSE);
 622.310 +}
 622.311 +
 622.312 +void Directories::OnOK()
 622.313 +{
 622.314 +	CString buffer;
 622.315 +
 622.316 +	m_romPath.GetWindowText(buffer);
 622.317 +	if (!buffer.IsEmpty())
 622.318 +		regSetStringValue(IDS_ROM_DIR, buffer);
 622.319 +	else
 622.320 +		regDeleteValue(IDS_ROM_DIR);
 622.321 +
 622.322 +	m_gbxromPath.GetWindowText(buffer);
 622.323 +	if (!buffer.IsEmpty())
 622.324 +		regSetStringValue(IDS_GBXROM_DIR, buffer);
 622.325 +	else
 622.326 +		regDeleteValue(IDS_GBXROM_DIR);
 622.327 +
 622.328 +	m_batteryPath.GetWindowText(buffer);
 622.329 +	if (!buffer.IsEmpty())
 622.330 +		regSetStringValue(IDS_BATTERY_DIR, buffer);
 622.331 +	else
 622.332 +		regDeleteValue(IDS_BATTERY_DIR);
 622.333 +
 622.334 +	m_savePath.GetWindowText(buffer);
 622.335 +	if (!buffer.IsEmpty())
 622.336 +		regSetStringValue(IDS_SAVE_DIR, buffer);
 622.337 +	else
 622.338 +		regDeleteValue(IDS_SAVE_DIR);
 622.339 +
 622.340 +	m_moviePath.GetWindowText(buffer);
 622.341 +	if (!buffer.IsEmpty())
 622.342 +		regSetStringValue(IDS_MOVIE_DIR, buffer);
 622.343 +	else
 622.344 +		regDeleteValue(IDS_MOVIE_DIR);
 622.345 +
 622.346 +	m_cheatPath.GetWindowText(buffer);
 622.347 +	if (!buffer.IsEmpty())
 622.348 +		regSetStringValue(IDS_CHEAT_DIR, buffer);
 622.349 +	else
 622.350 +		regDeleteValue(IDS_CHEAT_DIR);
 622.351 +
 622.352 +	m_ipsPath.GetWindowText(buffer);
 622.353 +	if (!buffer.IsEmpty())
 622.354 +		regSetStringValue(IDS_IPS_DIR, buffer);
 622.355 +	else
 622.356 +		regDeleteValue(IDS_IPS_DIR);
 622.357 +
 622.358 +	m_luaPath.GetWindowText(buffer);
 622.359 +	if (!buffer.IsEmpty())
 622.360 +		regSetStringValue(IDS_LUA_DIR, buffer);
 622.361 +	else
 622.362 +		regDeleteValue(IDS_LUA_DIR);
 622.363 +
 622.364 +	m_aviPath.GetWindowText(buffer);
 622.365 +	if (!buffer.IsEmpty())
 622.366 +		regSetStringValue(IDS_AVI_DIR, buffer);
 622.367 +	else
 622.368 +		regDeleteValue(IDS_AVI_DIR);
 622.369 +
 622.370 +	m_wavPath.GetWindowText(buffer);
 622.371 +	if (!buffer.IsEmpty())
 622.372 +		regSetStringValue(IDS_WAV_DIR, buffer);
 622.373 +	else
 622.374 +		regDeleteValue(IDS_WAV_DIR);
 622.375 +
 622.376 +	m_capturePath.GetWindowText(buffer);
 622.377 +	if (!buffer.IsEmpty())
 622.378 +		regSetStringValue(IDS_CAPTURE_DIR, buffer);
 622.379 +	else
 622.380 +		regDeleteValue(IDS_CAPTURE_DIR);
 622.381 +
 622.382 +	m_watchPath.GetWindowText(buffer);
 622.383 +	if (!buffer.IsEmpty())
 622.384 +		regSetStringValue(IDS_WATCH_DIR, buffer);
 622.385 +	else
 622.386 +		regDeleteValue(IDS_WATCH_DIR);
 622.387 +
 622.388 +	EndDialog(TRUE);
 622.389 +}
 622.390 +
 622.391 +CString Directories::browseForDir(CString title)
 622.392 +{
 622.393 +	static char  buffer[1024];
 622.394 +	LPMALLOC     pMalloc;
 622.395 +	LPITEMIDLIST pidl;
 622.396 +
 622.397 +	CString res;
 622.398 +
 622.399 +	if (SUCCEEDED(SHGetMalloc(&pMalloc)))
 622.400 +	{
 622.401 +		BROWSEINFO bi;
 622.402 +		ZeroMemory(&bi, sizeof(bi));
 622.403 +		bi.hwndOwner = m_hWnd;
 622.404 +		bi.lpszTitle = title;
 622.405 +		bi.pidlRoot  = 0;
 622.406 +		bi.ulFlags   = BIF_RETURNONLYFSDIRS | BIF_USENEWUI;	// will fail if COINIT_MULTITHREADED
 622.407 +		bi.lpfn      = browseCallbackProc;
 622.408 +		bi.lParam    = (LPARAM)(LPCTSTR)initialFolderDir;
 622.409 +
 622.410 +		pidl = SHBrowseForFolder(&bi);
 622.411 +
 622.412 +		if (pidl)
 622.413 +		{
 622.414 +			if (SHGetPathFromIDList(pidl, buffer))
 622.415 +			{
 622.416 +				res = buffer;
 622.417 +			}
 622.418 +			pMalloc->Free(pidl);
 622.419 +			pMalloc->Release();
 622.420 +		}
 622.421 +	}
 622.422 +	return res;
 622.423 +}
   623.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   623.2 +++ b/src/win32/Directories.h	Sat Mar 03 10:31:27 2012 -0600
   623.3 @@ -0,0 +1,84 @@
   623.4 +#if !defined(AFX_DIRECTORIES_H__7ADB14C1_3C1B_4294_8D66_A4E87D6FC731__INCLUDED_)
   623.5 +#define AFX_DIRECTORIES_H__7ADB14C1_3C1B_4294_8D66_A4E87D6FC731__INCLUDED_
   623.6 +
   623.7 +#if _MSC_VER > 1000
   623.8 +#pragma once
   623.9 +#endif // _MSC_VER > 1000
  623.10 +// Directories.h : header file
  623.11 +//
  623.12 +
  623.13 +/////////////////////////////////////////////////////////////////////////////
  623.14 +// Directories dialog
  623.15 +
  623.16 +class Directories : public CDialog
  623.17 +{
  623.18 +	// Construction
  623.19 +public:
  623.20 +	CString initialFolderDir;
  623.21 +	CString browseForDir(CString title);
  623.22 +	Directories(CWnd*pParent = NULL);  // standard constructor
  623.23 +
  623.24 +	// Dialog Data
  623.25 +	//{{AFX_DATA(Directories)
  623.26 +	enum { IDD = IDD_DIRECTORIES };
  623.27 +	CEdit m_romPath;
  623.28 +	CEdit m_gbxromPath;
  623.29 +	CEdit m_batteryPath;
  623.30 +	CEdit m_savePath;
  623.31 +	CEdit m_moviePath;
  623.32 +	CEdit m_cheatPath;
  623.33 +	CEdit m_ipsPath;
  623.34 +	CEdit m_luaPath;
  623.35 +	CEdit m_aviPath;
  623.36 +	CEdit m_wavPath;
  623.37 +	CEdit m_capturePath;
  623.38 +	CEdit m_watchPath;
  623.39 +//  CEdit m_pluginPath;
  623.40 +	//}}AFX_DATA
  623.41 +
  623.42 +	// Overrides
  623.43 +	// ClassWizard generated virtual function overrides
  623.44 +	//{{AFX_VIRTUAL(Directories)
  623.45 +protected:
  623.46 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  623.47 +	//}}AFX_VIRTUAL
  623.48 +
  623.49 +	// Implementation
  623.50 +protected:
  623.51 +	// Generated message map functions
  623.52 +	//{{AFX_MSG(Directories)
  623.53 +	virtual BOOL OnInitDialog();
  623.54 +	afx_msg void OnRomDir();
  623.55 +	afx_msg void OnRomDirReset();
  623.56 +	afx_msg void OnGBxRomDir();
  623.57 +	afx_msg void OnGBxRomDirReset();
  623.58 +	afx_msg void OnBatteryDir();
  623.59 +	afx_msg void OnBatteryDirReset();
  623.60 +	afx_msg void OnSaveDir();
  623.61 +	afx_msg void OnSaveDirReset();
  623.62 +	afx_msg void OnMovieDir();
  623.63 +	afx_msg void OnMovieDirReset();
  623.64 +	afx_msg void OnCheatDir();
  623.65 +	afx_msg void OnCheatDirReset();
  623.66 +	afx_msg void OnIpsDir();
  623.67 +	afx_msg void OnIpsDirReset();
  623.68 +	afx_msg void OnLuaDir();
  623.69 +	afx_msg void OnLuaDirReset();
  623.70 +	afx_msg void OnAviDir();
  623.71 +	afx_msg void OnAviDirReset();
  623.72 +	afx_msg void OnWavDir();
  623.73 +	afx_msg void OnWavDirReset();
  623.74 +	afx_msg void OnCaptureDir();
  623.75 +	afx_msg void OnCaptureDirReset();
  623.76 +	afx_msg void OnWatchDir();
  623.77 +	afx_msg void OnWatchDirReset();
  623.78 +	virtual void OnCancel();
  623.79 +	virtual void OnOK();
  623.80 +	//}}AFX_MSG
  623.81 +	DECLARE_MESSAGE_MAP()
  623.82 +};
  623.83 +
  623.84 +//{{AFX_INSERT_LOCATION}}
  623.85 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  623.86 +
  623.87 +#endif // !defined(AFX_DIRECTORIES_H__7ADB14C1_3C1B_4294_8D66_A4E87D6FC731__INCLUDED_)
   624.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   624.2 +++ b/src/win32/Disassemble.cpp	Sat Mar 03 10:31:27 2012 -0600
   624.3 @@ -0,0 +1,342 @@
   624.4 +// Disassemble.cpp : implementation file
   624.5 +//
   624.6 +
   624.7 +#include "stdafx.h"
   624.8 +#include "resource.h"
   624.9 +#include "Disassemble.h"
  624.10 +#include "VBA.h"
  624.11 +
  624.12 +#include "../gba/armdis.h"
  624.13 +#include "../gba/GBA.h"
  624.14 +#include "../gba/GBAGlobals.h"
  624.15 +
  624.16 +extern void CPUUpdateCPSR();
  624.17 +
  624.18 +/////////////////////////////////////////////////////////////////////////////
  624.19 +// Disassemble dialog
  624.20 +
  624.21 +Disassemble::Disassemble(CWnd*pParent /*=NULL*/)
  624.22 +	: ResizeDlg(Disassemble::IDD, pParent)
  624.23 +{
  624.24 +	//{{AFX_DATA_INIT(Disassemble)
  624.25 +	m_c  = FALSE;
  624.26 +	m_f  = FALSE;
  624.27 +	m_i  = FALSE;
  624.28 +	m_n  = FALSE;
  624.29 +	m_t  = FALSE;
  624.30 +	m_v  = FALSE;
  624.31 +	m_z  = FALSE;
  624.32 +	//}}AFX_DATA_INIT
  624.33 +	autoUpdate = false;
  624.34 +	address    = 0;
  624.35 +	count      = 1;
  624.36 +	mode       = 0;
  624.37 +}
  624.38 +
  624.39 +void Disassemble::DoDataExchange(CDataExchange*pDX)
  624.40 +{
  624.41 +	CDialog::DoDataExchange(pDX);
  624.42 +	//{{AFX_DATA_MAP(Disassemble)
  624.43 +	DDX_Control(pDX, IDC_ADDRESS, m_address);
  624.44 +	DDX_Control(pDX, IDC_DISASSEMBLE, m_list);
  624.45 +	DDX_Check(pDX, IDC_C, m_c);
  624.46 +	DDX_Check(pDX, IDC_F, m_f);
  624.47 +	DDX_Check(pDX, IDC_I, m_i);
  624.48 +	DDX_Check(pDX, IDC_N, m_n);
  624.49 +	DDX_Check(pDX, IDC_T, m_t);
  624.50 +	DDX_Check(pDX, IDC_V, m_v);
  624.51 +	DDX_Check(pDX, IDC_Z, m_z);
  624.52 +	DDX_Radio(pDX, IDC_AUTOMATIC, mode);
  624.53 +	//}}AFX_DATA_MAP
  624.54 +}
  624.55 +
  624.56 +BEGIN_MESSAGE_MAP(Disassemble, CDialog)
  624.57 +//{{AFX_MSG_MAP(Disassemble)
  624.58 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
  624.59 +ON_BN_CLICKED(IDC_AUTOMATIC, OnAutomatic)
  624.60 +ON_BN_CLICKED(IDC_ARM, OnArm)
  624.61 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
  624.62 +ON_BN_CLICKED(IDC_GO, OnGo)
  624.63 +ON_BN_CLICKED(IDC_GOPC, OnGopc)
  624.64 +ON_BN_CLICKED(IDC_NEXT, OnNext)
  624.65 +ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
  624.66 +ON_BN_CLICKED(IDC_THUMB, OnThumb)
  624.67 +ON_WM_VSCROLL()
  624.68 +//}}AFX_MSG_MAP
  624.69 +END_MESSAGE_MAP()
  624.70 +
  624.71 +/////////////////////////////////////////////////////////////////////////////
  624.72 +// Disassemble message handlers
  624.73 +
  624.74 +void Disassemble::OnAutoUpdate()
  624.75 +{
  624.76 +	autoUpdate = !autoUpdate;
  624.77 +	if (autoUpdate)
  624.78 +	{
  624.79 +		theApp.winAddUpdateListener(this);
  624.80 +	}
  624.81 +	else
  624.82 +	{
  624.83 +		theApp.winRemoveUpdateListener(this);
  624.84 +	}
  624.85 +}
  624.86 +
  624.87 +void Disassemble::OnAutomatic()
  624.88 +{
  624.89 +	mode = 0;
  624.90 +	refresh();
  624.91 +}
  624.92 +
  624.93 +void Disassemble::OnArm()
  624.94 +{
  624.95 +	mode = 1;
  624.96 +	refresh();
  624.97 +}
  624.98 +
  624.99 +void Disassemble::OnClose()
 624.100 +{
 624.101 +	theApp.winRemoveUpdateListener(this);
 624.102 +
 624.103 +	DestroyWindow();
 624.104 +}
 624.105 +
 624.106 +void Disassemble::OnGo()
 624.107 +{
 624.108 +	CString buffer;
 624.109 +	m_address.GetWindowText(buffer);
 624.110 +	sscanf(buffer, "%x", &address);
 624.111 +	refresh();
 624.112 +}
 624.113 +
 624.114 +void Disassemble::OnGopc()
 624.115 +{
 624.116 +	if (armState)
 624.117 +		address = armNextPC - 16;
 624.118 +	else
 624.119 +		address = armNextPC - 8;
 624.120 +
 624.121 +	refresh();
 624.122 +}
 624.123 +
 624.124 +void Disassemble::OnNext()
 624.125 +{
 624.126 +	CPULoop(1);
 624.127 +	if (armState)
 624.128 +	{
 624.129 +		u32 total = address+count*4;
 624.130 +		if (armNextPC >= address && armNextPC < total)
 624.131 +		{}
 624.132 +		else
 624.133 +		{
 624.134 +			OnGopc();
 624.135 +		}
 624.136 +	}
 624.137 +	else
 624.138 +	{
 624.139 +		u32 total = address+count*2;
 624.140 +		if (armNextPC >= address && armNextPC < total)
 624.141 +		{}
 624.142 +		else
 624.143 +		{
 624.144 +			OnGopc();
 624.145 +		}
 624.146 +	}
 624.147 +	refresh();
 624.148 +}
 624.149 +
 624.150 +void Disassemble::OnRefresh()
 624.151 +{
 624.152 +	refresh();
 624.153 +}
 624.154 +
 624.155 +void Disassemble::OnThumb()
 624.156 +{
 624.157 +	mode = 2;
 624.158 +	refresh();
 624.159 +}
 624.160 +
 624.161 +BOOL Disassemble::OnInitDialog()
 624.162 +{
 624.163 +	CDialog::OnInitDialog();
 624.164 +
 624.165 +	DIALOG_SIZER_START(sz)
 624.166 +	DIALOG_SIZER_ENTRY(IDC_DISASSEMBLE, DS_SizeY)
 624.167 +	DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
 624.168 +	DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
 624.169 +	DIALOG_SIZER_ENTRY(IDC_NEXT,  DS_MoveY)
 624.170 +	DIALOG_SIZER_ENTRY(IDC_AUTO_UPDATE, DS_MoveY)
 624.171 +	DIALOG_SIZER_ENTRY(IDC_GOPC, DS_MoveY)
 624.172 +	DIALOG_SIZER_ENTRY(IDC_VSCROLL, DS_SizeY)
 624.173 +	DIALOG_SIZER_END()
 624.174 +	SetData(sz,
 624.175 +	        TRUE,
 624.176 +	        HKEY_CURRENT_USER,
 624.177 +	        "Software\\Emulators\\VisualBoyAdvance\\Viewer\\DisassembleView",
 624.178 +	        NULL);
 624.179 +
 624.180 +	SCROLLINFO si;
 624.181 +	ZeroMemory(&si, sizeof(si));
 624.182 +	si.cbSize = sizeof(si);
 624.183 +	si.fMask  = SIF_PAGE | SIF_RANGE | SIF_POS;
 624.184 +	si.nMin   = 0;
 624.185 +	si.nMax   = 100;
 624.186 +	si.nPos   = 50;
 624.187 +	si.nPage  = 0;
 624.188 +	GetDlgItem(IDC_VSCROLL)->SetScrollInfo(SB_CTL, &si, TRUE);
 624.189 +
 624.190 +	CFont *font = CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT));
 624.191 +	m_list.SetFont(font, FALSE);
 624.192 +	for (int i = 0; i < 17; i++)
 624.193 +		GetDlgItem(IDC_R0+i)->SetFont(font, FALSE);
 624.194 +
 624.195 +	GetDlgItem(IDC_MODE)->SetFont(font, FALSE);
 624.196 +
 624.197 +	m_address.LimitText(8);
 624.198 +	refresh();
 624.199 +
 624.200 +	return TRUE; // return TRUE unless you set the focus to a control
 624.201 +	             // EXCEPTION: OCX Property Pages should return FALSE
 624.202 +}
 624.203 +
 624.204 +void Disassemble::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar)
 624.205 +{
 624.206 +	switch (nSBCode)
 624.207 +	{
 624.208 +	case SB_LINEDOWN:
 624.209 +		if (mode == 0)
 624.210 +		{
 624.211 +			if (armState)
 624.212 +				address += 4;
 624.213 +			else
 624.214 +				address += 2;
 624.215 +		}
 624.216 +		else if (mode == 1)
 624.217 +			address += 4;
 624.218 +		else
 624.219 +			address += 2;
 624.220 +		break;
 624.221 +	case SB_LINEUP:
 624.222 +		if (mode == 0)
 624.223 +		{
 624.224 +			if (armState)
 624.225 +				address -= 4;
 624.226 +			else
 624.227 +				address -= 2;
 624.228 +		}
 624.229 +		else if (mode == 1)
 624.230 +			address -= 4;
 624.231 +		else
 624.232 +			address -= 2;
 624.233 +		break;
 624.234 +	case SB_PAGEDOWN:
 624.235 +		if (mode == 0)
 624.236 +		{
 624.237 +			if (armState)
 624.238 +				address += count*4;
 624.239 +			else
 624.240 +				address += count*2;
 624.241 +		}
 624.242 +		else if (mode == 1)
 624.243 +			address += count*4;
 624.244 +		else
 624.245 +			address += count*2;
 624.246 +		break;
 624.247 +	case SB_PAGEUP:
 624.248 +		if (mode == 0)
 624.249 +		{
 624.250 +			if (armState)
 624.251 +				address -= count*4;
 624.252 +			else
 624.253 +				address -= count*2;
 624.254 +		}
 624.255 +		else if (mode == 1)
 624.256 +			address -= count*4;
 624.257 +		else
 624.258 +			address -= count*2;
 624.259 +		break;
 624.260 +	}
 624.261 +	refresh();
 624.262 +
 624.263 +	CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
 624.264 +}
 624.265 +
 624.266 +void Disassemble::refresh()
 624.267 +{
 624.268 +	if (rom == NULL)
 624.269 +		return;
 624.270 +
 624.271 +	bool8 arm = armState;
 624.272 +
 624.273 +	if (mode != 0)
 624.274 +	{
 624.275 +		if (mode == 1)
 624.276 +			arm = true;
 624.277 +		else
 624.278 +			arm = false;
 624.279 +	}
 624.280 +
 624.281 +	int  h = m_list.GetItemHeight(0);
 624.282 +	RECT r;
 624.283 +	m_list.GetClientRect(&r);
 624.284 +	count = (r.bottom - r.top+1)/h;
 624.285 +
 624.286 +	m_list.ResetContent();
 624.287 +	if (!systemIsEmulating() && systemCartridgeType == 0)
 624.288 +		return;
 624.289 +
 624.290 +	char buffer[80];
 624.291 +	u32  addr = address;
 624.292 +	int  i;
 624.293 +	int  sel = -1;
 624.294 +	for (i = 0; i < count; i++)
 624.295 +	{
 624.296 +		if (addr == armNextPC)
 624.297 +			sel = i;
 624.298 +		if (arm)
 624.299 +		{
 624.300 +			addr += disArm(addr, buffer, 3);
 624.301 +		}
 624.302 +		else
 624.303 +		{
 624.304 +			addr += disThumb(addr, buffer, 3);
 624.305 +		}
 624.306 +		m_list.InsertString(-1, buffer);
 624.307 +	}
 624.308 +
 624.309 +	if (sel != -1)
 624.310 +		m_list.SetCurSel(sel);
 624.311 +
 624.312 +	CPUUpdateCPSR();
 624.313 +
 624.314 +	for (i = 0; i < 17; i++)
 624.315 +	{
 624.316 +		sprintf(buffer, "%08x", reg[i].I);
 624.317 +		GetDlgItem(IDC_R0+i)->SetWindowText(buffer);
 624.318 +	}
 624.319 +
 624.320 +	m_n = (reg[16].I & 0x80000000) != 0;
 624.321 +	m_z = (reg[16].I & 0x40000000) != 0;
 624.322 +	m_c = (reg[16].I & 0x20000000) != 0;
 624.323 +	m_v = (reg[16].I & 0x10000000) != 0;
 624.324 +	m_i = (reg[16].I & 0x80) != 0;
 624.325 +	m_f = (reg[16].I & 0x40) != 0;
 624.326 +	m_t = (reg[16].I & 0x20) != 0;
 624.327 +
 624.328 +	UpdateData(FALSE);
 624.329 +
 624.330 +	int v = reg[16].I & 0x1f;
 624.331 +	sprintf(buffer, "%02x", v);
 624.332 +	GetDlgItem(IDC_MODE)->SetWindowText(buffer);
 624.333 +}
 624.334 +
 624.335 +void Disassemble::update()
 624.336 +{
 624.337 +	OnGopc();
 624.338 +	refresh();
 624.339 +}
 624.340 +
 624.341 +void Disassemble::PostNcDestroy()
 624.342 +{
 624.343 +	delete this;
 624.344 +}
 624.345 +
   625.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   625.2 +++ b/src/win32/Disassemble.h	Sat Mar 03 10:31:27 2012 -0600
   625.3 @@ -0,0 +1,72 @@
   625.4 +#if !defined(AFX_DISASSEMBLE_H__CA10E857_7D76_4B19_A62B_D0677040FD0F__INCLUDED_)
   625.5 +#define AFX_DISASSEMBLE_H__CA10E857_7D76_4B19_A62B_D0677040FD0F__INCLUDED_
   625.6 +
   625.7 +#if _MSC_VER > 1000
   625.8 +#pragma once
   625.9 +#endif // _MSC_VER > 1000
  625.10 +// Disassemble.h : header file
  625.11 +//
  625.12 +
  625.13 +#include "IUpdate.h"
  625.14 +#include "ResizeDlg.h"
  625.15 +
  625.16 +/////////////////////////////////////////////////////////////////////////////
  625.17 +// Disassemble dialog
  625.18 +
  625.19 +class Disassemble : public ResizeDlg, IUpdateListener
  625.20 +{
  625.21 +	// Construction
  625.22 +public:
  625.23 +	virtual void update();
  625.24 +	void refresh();
  625.25 +	Disassemble(CWnd*pParent = NULL);  // standard constructor
  625.26 +
  625.27 +	// Dialog Data
  625.28 +	//{{AFX_DATA(Disassemble)
  625.29 +	enum { IDD = IDD_DISASSEMBLE };
  625.30 +	CEdit    m_address;
  625.31 +	CListBox m_list;
  625.32 +	BOOL     m_c;
  625.33 +	BOOL     m_f;
  625.34 +	BOOL     m_i;
  625.35 +	BOOL     m_n;
  625.36 +	BOOL     m_t;
  625.37 +	BOOL     m_v;
  625.38 +	BOOL     m_z;
  625.39 +	//}}AFX_DATA
  625.40 +	bool autoUpdate;
  625.41 +	int  count;
  625.42 +	u32  address;
  625.43 +	int  mode;
  625.44 +
  625.45 +	// Overrides
  625.46 +	// ClassWizard generated virtual function overrides
  625.47 +	//{{AFX_VIRTUAL(Disassemble)
  625.48 +protected:
  625.49 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  625.50 +	virtual void PostNcDestroy();
  625.51 +	//}}AFX_VIRTUAL
  625.52 +
  625.53 +	// Implementation
  625.54 +protected:
  625.55 +	// Generated message map functions
  625.56 +	//{{AFX_MSG(Disassemble)
  625.57 +	afx_msg void OnAutoUpdate();
  625.58 +	afx_msg void OnAutomatic();
  625.59 +	afx_msg void OnArm();
  625.60 +	afx_msg void OnClose();
  625.61 +	afx_msg void OnGo();
  625.62 +	afx_msg void OnGopc();
  625.63 +	afx_msg void OnNext();
  625.64 +	afx_msg void OnRefresh();
  625.65 +	afx_msg void OnThumb();
  625.66 +	virtual BOOL OnInitDialog();
  625.67 +	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar);
  625.68 +	//}}AFX_MSG
  625.69 +	DECLARE_MESSAGE_MAP()
  625.70 +};
  625.71 +
  625.72 +//{{AFX_INSERT_LOCATION}}
  625.73 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  625.74 +
  625.75 +#endif // !defined(AFX_DISASSEMBLE_H__CA10E857_7D76_4B19_A62B_D0677040FD0F__INCLUDED_)
   626.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   626.2 +++ b/src/win32/Display.h	Sat Mar 03 10:31:27 2012 -0600
   626.3 @@ -0,0 +1,35 @@
   626.4 +#ifndef VBA_WIN32_DISASSEMBLE_H
   626.5 +#define VBA_WIN32_DISASSEMBLE_H
   626.6 +
   626.7 +#if _MSC_VER > 1000
   626.8 +#pragma once
   626.9 +#endif // _MSC_VER > 1000
  626.10 +
  626.11 +enum DISPLAY_TYPE
  626.12 +{
  626.13 +	GDI         = 0,
  626.14 +	DIRECT_DRAW = 1,
  626.15 +	DIRECT_3D   = 2,
  626.16 +	OPENGL      = 3
  626.17 +};
  626.18 +
  626.19 +class IDisplay
  626.20 +{
  626.21 +public:
  626.22 +	IDisplay() {};
  626.23 +	virtual ~IDisplay() {};
  626.24 +
  626.25 +	virtual bool initialize() = 0;
  626.26 +	virtual void cleanup()    = 0;
  626.27 +	virtual void render()     = 0;
  626.28 +	virtual void checkFullScreen() { };
  626.29 +	virtual void renderMenu() { };
  626.30 +	virtual void clear() = 0;
  626.31 +	virtual bool changeRenderSize(int w, int h) { return true; };
  626.32 +	virtual void resize(int w, int h) {};
  626.33 +	virtual void setOption(const char *option, int value) = 0;
  626.34 +	virtual DISPLAY_TYPE getType() = 0;
  626.35 +	virtual int selectFullScreenMode(GUID * *) = 0;
  626.36 +};
  626.37 +
  626.38 +#endif // VBA_WIN32_DISASSEMBLE_H
   627.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   627.2 +++ b/src/win32/ExportGSASnapshot.cpp	Sat Mar 03 10:31:27 2012 -0600
   627.3 @@ -0,0 +1,92 @@
   627.4 +// ExportGSASnapshot.cpp : implementation file
   627.5 +//
   627.6 +
   627.7 +#include "stdafx.h"
   627.8 +#include "resource.h"
   627.9 +#include "ExportGSASnapshot.h"
  627.10 +
  627.11 +#include "../common/System.h"
  627.12 +#include "../gba/GBA.h"
  627.13 +#include "../NLS.h"
  627.14 +
  627.15 +/////////////////////////////////////////////////////////////////////////////
  627.16 +// ExportGSASnapshot dialog
  627.17 +
  627.18 +ExportGSASnapshot::ExportGSASnapshot(CString filename, CString title, CWnd*pParent /*=NULL*/)
  627.19 +	: CDialog(ExportGSASnapshot::IDD, pParent)
  627.20 +{
  627.21 +	//{{AFX_DATA_INIT(ExportGSASnapshot)
  627.22 +	m_desc  = _T("");
  627.23 +	m_notes = _T("");
  627.24 +	m_title = _T("");
  627.25 +	//}}AFX_DATA_INIT
  627.26 +	m_title    = title;
  627.27 +	m_filename = filename;
  627.28 +	char date[100];
  627.29 +	char time[100];
  627.30 +
  627.31 +	GetDateFormat(LOCALE_USER_DEFAULT,
  627.32 +	              DATE_SHORTDATE,
  627.33 +	              NULL,
  627.34 +	              NULL,
  627.35 +	              date,
  627.36 +	              100);
  627.37 +	GetTimeFormat(LOCALE_USER_DEFAULT,
  627.38 +	              0,
  627.39 +	              NULL,
  627.40 +	              NULL,
  627.41 +	              time,
  627.42 +	              100);
  627.43 +	m_desc.Format("%s %s", date, time);
  627.44 +}
  627.45 +
  627.46 +void ExportGSASnapshot::DoDataExchange(CDataExchange*pDX)
  627.47 +{
  627.48 +	CDialog::DoDataExchange(pDX);
  627.49 +	//{{AFX_DATA_MAP(ExportGSASnapshot)
  627.50 +	DDX_Text(pDX, IDC_DESC, m_desc);
  627.51 +	DDV_MaxChars(pDX, m_desc, 100);
  627.52 +	DDX_Text(pDX, IDC_NOTES, m_notes);
  627.53 +	DDV_MaxChars(pDX, m_notes, 512);
  627.54 +	DDX_Text(pDX, IDC_TITLE, m_title);
  627.55 +	DDV_MaxChars(pDX, m_title, 100);
  627.56 +	//}}AFX_DATA_MAP
  627.57 +}
  627.58 +
  627.59 +BEGIN_MESSAGE_MAP(ExportGSASnapshot, CDialog)
  627.60 +//{{AFX_MSG_MAP(ExportGSASnapshot)
  627.61 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
  627.62 +ON_BN_CLICKED(ID_OK, OnOk)
  627.63 +//}}AFX_MSG_MAP
  627.64 +END_MESSAGE_MAP()
  627.65 +
  627.66 +/////////////////////////////////////////////////////////////////////////////
  627.67 +// ExportGSASnapshot message handlers
  627.68 +
  627.69 +BOOL ExportGSASnapshot::OnInitDialog()
  627.70 +{
  627.71 +	CDialog::OnInitDialog();
  627.72 +	CenterWindow();
  627.73 +
  627.74 +	return TRUE; // return TRUE unless you set the focus to a control
  627.75 +	             // EXCEPTION: OCX Property Pages should return FALSE
  627.76 +}
  627.77 +
  627.78 +void ExportGSASnapshot::OnCancel()
  627.79 +{
  627.80 +	EndDialog(FALSE);
  627.81 +}
  627.82 +
  627.83 +void ExportGSASnapshot::OnOk()
  627.84 +{
  627.85 +	UpdateData(TRUE);
  627.86 +
  627.87 +	bool result = CPUWriteGSASnapshot(m_filename, m_title, m_desc, m_notes);
  627.88 +
  627.89 +	if (!result)
  627.90 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s",
  627.91 +		              m_filename);
  627.92 +
  627.93 +	EndDialog(TRUE);
  627.94 +}
  627.95 +
   628.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   628.2 +++ b/src/win32/ExportGSASnapshot.h	Sat Mar 03 10:31:27 2012 -0600
   628.3 @@ -0,0 +1,49 @@
   628.4 +#if !defined(AFX_EXPORTGSASNAPSHOT_H__ADF8566A_C64D_43CF_9CD2_A290370BA4F1__INCLUDED_)
   628.5 +#define AFX_EXPORTGSASNAPSHOT_H__ADF8566A_C64D_43CF_9CD2_A290370BA4F1__INCLUDED_
   628.6 +
   628.7 +#if _MSC_VER > 1000
   628.8 +#pragma once
   628.9 +#endif // _MSC_VER > 1000
  628.10 +// ExportGSASnapshot.h : header file
  628.11 +//
  628.12 +
  628.13 +/////////////////////////////////////////////////////////////////////////////
  628.14 +// ExportGSASnapshot dialog
  628.15 +
  628.16 +class ExportGSASnapshot : public CDialog
  628.17 +{
  628.18 +	// Construction
  628.19 +public:
  628.20 +	ExportGSASnapshot(CString filename, CString title, CWnd*pParent = NULL); // standard constructor
  628.21 +
  628.22 +	// Dialog Data
  628.23 +	//{{AFX_DATA(ExportGSASnapshot)
  628.24 +	enum { IDD = IDD_EXPORT_SPS };
  628.25 +	CString m_desc;
  628.26 +	CString m_notes;
  628.27 +	CString m_title;
  628.28 +	//}}AFX_DATA
  628.29 +	CString m_filename;
  628.30 +
  628.31 +	// Overrides
  628.32 +	// ClassWizard generated virtual function overrides
  628.33 +	//{{AFX_VIRTUAL(ExportGSASnapshot)
  628.34 +protected:
  628.35 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  628.36 +	//}}AFX_VIRTUAL
  628.37 +
  628.38 +	// Implementation
  628.39 +protected:
  628.40 +	// Generated message map functions
  628.41 +	//{{AFX_MSG(ExportGSASnapshot)
  628.42 +	virtual BOOL OnInitDialog();
  628.43 +	afx_msg void OnCancel();
  628.44 +	afx_msg void OnOk();
  628.45 +	//}}AFX_MSG
  628.46 +	DECLARE_MESSAGE_MAP()
  628.47 +};
  628.48 +
  628.49 +//{{AFX_INSERT_LOCATION}}
  628.50 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  628.51 +
  628.52 +#endif // !defined(AFX_EXPORTGSASNAPSHOT_H__ADF8566A_C64D_43CF_9CD2_A290370BA4F1__INCLUDED_)
   629.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   629.2 +++ b/src/win32/FileDlg.cpp	Sat Mar 03 10:31:27 2012 -0600
   629.3 @@ -0,0 +1,199 @@
   629.4 +// FileDlg.cpp: implementation of the FileDlg class.
   629.5 +//
   629.6 +//////////////////////////////////////////////////////////////////////
   629.7 +//#define WINVER 0x0410 // windows 98 - just for this 1 file - just in case
   629.8 +#include "stdafx.h"
   629.9 +#include <commdlg.h>
  629.10 +#include <dlgs.h>
  629.11 +#include "resource.h"
  629.12 +#include "FileDlg.h"
  629.13 +#include "Sound.h"
  629.14 +#include "VBA.h"
  629.15 +
  629.16 +static FileDlg *instance = NULL;
  629.17 +
  629.18 +static UINT_PTR CALLBACK HookFunc(HWND hwnd,
  629.19 +                                  UINT msg,
  629.20 +                                  WPARAM wParam,
  629.21 +                                  LPARAM lParam)
  629.22 +{
  629.23 +	if (instance)
  629.24 +	{
  629.25 +		if (msg == WM_NOTIFY)
  629.26 +		{
  629.27 +			OFNOTIFY *notify = (OFNOTIFY *)lParam;
  629.28 +			if (notify)
  629.29 +			{
  629.30 +				if (notify->hdr.code == CDN_TYPECHANGE)
  629.31 +				{
  629.32 +					instance->OnTypeChange(hwnd);
  629.33 +					return 1;
  629.34 +				}
  629.35 +			}
  629.36 +		}
  629.37 +	}
  629.38 +	return 0;
  629.39 +}
  629.40 +
  629.41 +static UINT_PTR CALLBACK HookFuncOldStyle(HWND hwnd,
  629.42 +                                          UINT msg,
  629.43 +                                          WPARAM wParam,
  629.44 +                                          LPARAM lParam)
  629.45 +{
  629.46 +	if (instance)
  629.47 +	{
  629.48 +		if (msg == WM_COMMAND)
  629.49 +		{
  629.50 +			if (HIWORD(wParam) == CBN_SELCHANGE)
  629.51 +			{
  629.52 +				if (LOWORD(wParam) == cmb1)
  629.53 +				{
  629.54 +					// call method with combobox handle to keep
  629.55 +					// behaviour there
  629.56 +					instance->OnTypeChange((HWND)lParam);
  629.57 +					return 1;
  629.58 +				}
  629.59 +			}
  629.60 +		}
  629.61 +	}
  629.62 +	return 0;
  629.63 +}
  629.64 +
  629.65 +/////////////////////////////////////////////////////////////////////////////
  629.66 +// FileDlg
  629.67 +
  629.68 +//////////////////////////////////////////////////////////////////////
  629.69 +// Construction/Destruction
  629.70 +//////////////////////////////////////////////////////////////////////
  629.71 +
  629.72 +FileDlg::FileDlg(CWnd *parent, LPCTSTR file, LPCTSTR filter,
  629.73 +                 int filterIndex, LPCTSTR ext, LPCTSTR *exts, LPCTSTR initialDir,
  629.74 +                 LPCTSTR title, bool save, bool noReadOnly)
  629.75 +{
  629.76 +	OSVERSIONINFO info;
  629.77 +	info.dwOSVersionInfoSize = sizeof(info);
  629.78 +	GetVersionEx(&info);
  629.79 +	m_file = file;
  629.80 +	int size = sizeof(OPENFILENAME);
  629.81 +
  629.82 +	// avoid problems if OPENFILENAME is already defined with the extended fields
  629.83 +	// needed for the enhanced open/save dialog
  629.84 +#if _WIN32_WINNT < 0x0500
  629.85 +	if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  629.86 +	{
  629.87 +		if (info.dwMajorVersion >= 5)
  629.88 +			size = sizeof(OPENFILENAMEEX);
  629.89 +	}
  629.90 +#endif
  629.91 +
  629.92 +	ZeroMemory(&m_ofn, sizeof(m_ofn));
  629.93 +	m_ofn.lpstrFile       = m_file.GetBuffer(MAX_PATH);
  629.94 +	m_ofn.nMaxFile        = MAX_PATH;
  629.95 +	m_ofn.lStructSize     = size;
  629.96 +	m_ofn.hwndOwner       = parent ? parent->GetSafeHwnd() : NULL;
  629.97 +	m_ofn.nFilterIndex    = filterIndex;
  629.98 +	m_ofn.lpstrInitialDir = initialDir;
  629.99 +	m_ofn.lpstrTitle      = title;
 629.100 +	m_ofn.lpstrDefExt     = ext;
 629.101 +	m_ofn.lpfnHook        = HookFunc;
 629.102 +	m_ofn.Flags  = OFN_PATHMUSTEXIST | OFN_ENABLESIZING | OFN_ENABLEHOOK;
 629.103 +	m_ofn.Flags |= OFN_EXPLORER;
 629.104 +	if (noReadOnly)
 629.105 +		m_ofn.Flags |= OFN_HIDEREADONLY;
 629.106 +	m_filter = filter;
 629.107 +
 629.108 +	char *p = m_filter.GetBuffer(0);
 629.109 +
 629.110 +	while ((p = strchr(p, '|')) != NULL)
 629.111 +		*p++ = 0;
 629.112 +	m_ofn.lpstrFilter = m_filter;
 629.113 +
 629.114 +	if (theApp.videoOption == VIDEO_320x240)
 629.115 +	{
 629.116 +		m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_OPENDLG);
 629.117 +		m_ofn.lpfnHook       = HookFuncOldStyle;
 629.118 +		m_ofn.Flags |= OFN_ENABLETEMPLATE;
 629.119 +		m_ofn.Flags &= ~OFN_EXPLORER;
 629.120 +	}
 629.121 +
 629.122 +	isSave     = save;
 629.123 +	extensions = exts;
 629.124 +
 629.125 +	instance = this;
 629.126 +}
 629.127 +
 629.128 +FileDlg::~FileDlg()
 629.129 +{
 629.130 +	instance = NULL;
 629.131 +}
 629.132 +
 629.133 +void FileDlg::OnTypeChange(HWND hwnd)
 629.134 +{
 629.135 +	HWND parent = GetParent(hwnd);
 629.136 +
 629.137 +	HWND fileNameControl = ::GetDlgItem(parent, cmb13);
 629.138 +
 629.139 +	if (fileNameControl == NULL)
 629.140 +		fileNameControl = ::GetDlgItem(parent, edt1);
 629.141 +
 629.142 +	if (fileNameControl == NULL)
 629.143 +		return;
 629.144 +
 629.145 +	CString filename;
 629.146 +	GetWindowText(fileNameControl, filename.GetBuffer(MAX_PATH), MAX_PATH);
 629.147 +	filename.ReleaseBuffer();
 629.148 +
 629.149 +	HWND typeControl = ::GetDlgItem(parent, cmb1);
 629.150 +
 629.151 +	ASSERT(typeControl != NULL);
 629.152 +
 629.153 +	int sel = ::SendMessage(typeControl, CB_GETCURSEL, 0, 0);
 629.154 +
 629.155 +	ASSERT(sel != -1);
 629.156 +
 629.157 +	LPCTSTR typeName = extensions[sel];
 629.158 +
 629.159 +	// sel could easily be an invalid index of extensions, so check for null guard
 629.160 +	for(int i = 0; i <= sel; i++)
 629.161 +		if(extensions[i] == NULL)
 629.162 +			typeName = "";
 629.163 +
 629.164 +	if (filename.GetLength() == 0)
 629.165 +	{
 629.166 +		if(*typeName)
 629.167 +			filename.Format("*%s", typeName);
 629.168 +	}
 629.169 +	else
 629.170 +	{
 629.171 +		int index = filename.Find('.');
 629.172 +		if (index == -1)
 629.173 +		{
 629.174 +			filename = filename + typeName;
 629.175 +		}
 629.176 +		else
 629.177 +		{
 629.178 +			filename = filename.Left(index) + typeName;
 629.179 +		}
 629.180 +	}
 629.181 +	SetWindowText(fileNameControl, filename);
 629.182 +}
 629.183 +
 629.184 +int FileDlg::getFilterIndex()
 629.185 +{
 629.186 +	return m_ofn.nFilterIndex;
 629.187 +}
 629.188 +
 629.189 +int FileDlg::DoModal()
 629.190 +{
 629.191 +	systemSoundClearBuffer();
 629.192 +	BOOL res = isSave ? GetSaveFileName(&m_ofn) :
 629.193 +	           GetOpenFileName(&m_ofn);
 629.194 +
 629.195 +	return res ? IDOK : IDCANCEL;
 629.196 +}
 629.197 +
 629.198 +LPCTSTR FileDlg::GetPathName()
 629.199 +{
 629.200 +	return (LPCTSTR)m_file;
 629.201 +}
 629.202 +
   630.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   630.2 +++ b/src/win32/FileDlg.h	Sat Mar 03 10:31:27 2012 -0600
   630.3 @@ -0,0 +1,43 @@
   630.4 +#if !defined(AFX_FILEDLG_H__7E4F8B92_1B63_4126_8261_D9334C645940__INCLUDED_)
   630.5 +#define AFX_FILEDLG_H__7E4F8B92_1B63_4126_8261_D9334C645940__INCLUDED_
   630.6 +
   630.7 +#if _MSC_VER > 1000
   630.8 +#pragma once
   630.9 +#endif // _MSC_VER > 1000
  630.10 +// FileDlg.h : header file
  630.11 +//
  630.12 +
  630.13 +struct OPENFILENAMEEX : public OPENFILENAME
  630.14 +{
  630.15 +	void *pvReserved;
  630.16 +	DWORD dwReserved;
  630.17 +	DWORD FlagsEx;
  630.18 +};
  630.19 +
  630.20 +/////////////////////////////////////////////////////////////////////////////
  630.21 +// FileDlg dialog
  630.22 +
  630.23 +class FileDlg
  630.24 +{
  630.25 +private:
  630.26 +	CString m_file;
  630.27 +	CString m_filter;
  630.28 +public:
  630.29 +	OPENFILENAMEEX m_ofn;
  630.30 +	int DoModal();
  630.31 +	LPCTSTR GetPathName();
  630.32 +	virtual int getFilterIndex();
  630.33 +	virtual void OnTypeChange(HWND hwnd);
  630.34 +	FileDlg(CWnd *parent, LPCTSTR file, LPCTSTR filter,
  630.35 +	        int filterIndex, LPCTSTR ext, LPCTSTR *exts, LPCTSTR initialDir,
  630.36 +	        LPCTSTR title, bool save, bool noReadOnly = false);
  630.37 +	virtual ~FileDlg();
  630.38 +protected:
  630.39 +	bool     isSave;
  630.40 +	LPCTSTR *extensions;
  630.41 +protected:
  630.42 +	//{{AFX_INSERT_LOCATION}}
  630.43 +	// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  630.44 +};
  630.45 +
  630.46 +#endif // !defined(AFX_FILEDLG_H__7E4F8B92_1B63_4126_8261_D9334C645940__INCLUDED_)
   631.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   631.2 +++ b/src/win32/GBACheatsDlg.cpp	Sat Mar 03 10:31:27 2012 -0600
   631.3 @@ -0,0 +1,1279 @@
   631.4 +// GBACheats.cpp : implementation file
   631.5 +//
   631.6 +
   631.7 +#include "stdafx.h"
   631.8 +#include "resource.h"
   631.9 +#include "GBACheatsDlg.h"
  631.10 +#include "Reg.h"
  631.11 +#include "StringTokenizer.h"
  631.12 +#include "WinResUtil.h"
  631.13 +#include "Sound.h"
  631.14 +#include "VBA.h"
  631.15 +
  631.16 +#include "../gba/GBACheats.h"
  631.17 +#include "../gba/GBAGlobals.h"
  631.18 +#include "../common/CheatSearch.h"
  631.19 +
  631.20 +////////////////////////////////
  631.21 +
  631.22 +bool winGbaCheatReaddress()
  631.23 +{
  631.24 +	if (cheatSearchData.count != 2)
  631.25 +		return false;
  631.26 +
  631.27 +	CheatSearchBlock *block = &cheatSearchData.blocks[0];
  631.28 +	block->data   = workRAM;
  631.29 +
  631.30 +	block         = &cheatSearchData.blocks[1];
  631.31 +	block->data   = internalRAM;
  631.32 +	
  631.33 +	cheatSearchData.count = 2;
  631.34 +	return true;
  631.35 +}
  631.36 +
  631.37 +/////////////////////////////////////////////////////////////////////////////
  631.38 +// GBACheatSearch dialog
  631.39 +
  631.40 +GBACheatSearch::GBACheatSearch(CWnd*pParent /*=NULL*/)
  631.41 +	: CDialog(GBACheatSearch::IDD, pParent)
  631.42 +{
  631.43 +	//{{AFX_DATA_INIT(GBACheatSearch)
  631.44 +	valueType    = -1;
  631.45 +	sizeType     = -1;
  631.46 +	searchType   = -1;
  631.47 +	numberType   = -1;
  631.48 +	updateValues = FALSE;
  631.49 +	//}}AFX_DATA_INIT
  631.50 +	data = NULL;
  631.51 +}
  631.52 +
  631.53 +GBACheatSearch::~GBACheatSearch()
  631.54 +{
  631.55 +	if (data)
  631.56 +		free(data);
  631.57 +}
  631.58 +
  631.59 +void GBACheatSearch::DoDataExchange(CDataExchange*pDX)
  631.60 +{
  631.61 +	CDialog::DoDataExchange(pDX);
  631.62 +	//{{AFX_DATA_MAP(GBACheatSearch)
  631.63 +	DDX_Control(pDX, IDC_VALUE, m_value);
  631.64 +	DDX_Control(pDX, IDC_CHEAT_LIST, m_list);
  631.65 +	DDX_Radio(pDX, IDC_OLD_VALUE, valueType);
  631.66 +	DDX_Radio(pDX, IDC_SIZE_8, sizeType);
  631.67 +	DDX_Radio(pDX, IDC_EQ, searchType);
  631.68 +	DDX_Radio(pDX, IDC_SIGNED, numberType);
  631.69 +	DDX_Check(pDX, IDC_UPDATE, updateValues);
  631.70 +	//}}AFX_DATA_MAP
  631.71 +}
  631.72 +
  631.73 +BEGIN_MESSAGE_MAP(GBACheatSearch, CDialog)
  631.74 +//{{AFX_MSG_MAP(GBACheatSearch)
  631.75 +ON_BN_CLICKED(ID_OK, OnOk)
  631.76 +ON_BN_CLICKED(IDC_START, OnStart)
  631.77 +ON_BN_CLICKED(IDC_SEARCH, OnSearch)
  631.78 +ON_BN_CLICKED(IDC_ADD_CHEAT, OnAddCheat)
  631.79 +ON_BN_CLICKED(IDC_UPDATE, OnUpdate)
  631.80 +ON_NOTIFY(LVN_GETDISPINFO, IDC_CHEAT_LIST, OnGetdispinfoCheatList)
  631.81 +ON_NOTIFY(LVN_ITEMCHANGED, IDC_CHEAT_LIST, OnItemchangedCheatList)
  631.82 +ON_CONTROL_RANGE(BN_CLICKED, IDC_OLD_VALUE, IDC_SPECIFIC_VALUE, OnValueType)
  631.83 +ON_CONTROL_RANGE(BN_CLICKED, IDC_EQ, IDC_GE, OnSearchType)
  631.84 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIGNED, IDC_HEXADECIMAL, OnNumberType)
  631.85 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIZE_8, IDC_SIZE_32, OnSizeType)
  631.86 +//}}AFX_MSG_MAP
  631.87 +ON_WM_CLOSE()
  631.88 +ON_BN_CLICKED(IDC_CHEATREFRESHBUTTON, OnBnClickedCheatrefreshbutton)
  631.89 +//ON_WM_DESTROY()
  631.90 +//ON_WM_NCDESTROY()
  631.91 +//ON_WM_SYSCOMMAND()
  631.92 +//ON_WM_ACTIVATE()
  631.93 +END_MESSAGE_MAP()
  631.94 +
  631.95 +/////////////////////////////////////////////////////////////////////////////
  631.96 +// GBACheatSearch message handlers
  631.97 +
  631.98 +void GBACheatSearch::OnOk()
  631.99 +{
 631.100 +	if (theApp.modelessCheatDialogIsOpen)
 631.101 +	{
 631.102 +		theApp.modelessCheatDialogIsOpen = false;
 631.103 +		DestroyWindow();
 631.104 +	}
 631.105 +	else
 631.106 +	{
 631.107 +		EndDialog(TRUE);
 631.108 +	}
 631.109 +}
 631.110 +
 631.111 +void GBACheatSearch::OnClose()
 631.112 +{
 631.113 +	CDialog::OnClose();
 631.114 +	if (theApp.modelessCheatDialogIsOpen)
 631.115 +	{
 631.116 +		theApp.modelessCheatDialogIsOpen = false;
 631.117 +		DestroyWindow();
 631.118 +	}
 631.119 +	else
 631.120 +	{
 631.121 +		EndDialog(FALSE);
 631.122 +	}
 631.123 +}
 631.124 +
 631.125 +void GBACheatSearch::OnStart()
 631.126 +{
 631.127 +	if (cheatSearchData.count == 0)
 631.128 +	{
 631.129 +		CheatSearchBlock *block = &cheatSearchData.blocks[0];
 631.130 +		block->data   = workRAM;
 631.131 +		block->offset = 0x2000000;
 631.132 +		block->size   = 0x40000;
 631.133 +		block->saved  = (u8 *)malloc(0x40000);
 631.134 +		block->bits   = (u8 *)malloc(0x40000>>3);
 631.135 +
 631.136 +		block         = &cheatSearchData.blocks[1];
 631.137 +		block->data   = internalRAM;
 631.138 +		block->offset = 0x3000000;
 631.139 +		block->size   = 0x8000;
 631.140 +		block->saved  = (u8 *)malloc(0x8000);
 631.141 +		block->bits   = (u8 *)malloc(0x8000>>3);
 631.142 +
 631.143 +		cheatSearchData.count = 2;
 631.144 +	}
 631.145 +
 631.146 +	cheatSearchStart(&cheatSearchData);
 631.147 +	GetDlgItem(IDC_SEARCH)->EnableWindow(TRUE);
 631.148 +
 631.149 +	if (theApp.modelessCheatDialogIsOpen)
 631.150 +	{
 631.151 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->ShowWindow(TRUE);
 631.152 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(FALSE);
 631.153 +	}
 631.154 +}
 631.155 +
 631.156 +void GBACheatSearch::OnSearch()
 631.157 +{
 631.158 +	CString buffer;
 631.159 +
 631.160 +	if (valueType == 0)
 631.161 +		cheatSearch(&cheatSearchData,
 631.162 +		            searchType,
 631.163 +		            sizeType,
 631.164 +		            numberType == 0);
 631.165 +	else
 631.166 +	{
 631.167 +		m_value.GetWindowText(buffer);
 631.168 +		if (buffer.IsEmpty())
 631.169 +		{
 631.170 +			systemMessage(IDS_NUMBER_CANNOT_BE_EMPTY, "Number cannot be empty");
 631.171 +			return;
 631.172 +		}
 631.173 +		int value = 0;
 631.174 +		switch (numberType)
 631.175 +		{
 631.176 +		case 0:
 631.177 +			sscanf(buffer, "%d", &value);
 631.178 +			break;
 631.179 +		case 1:
 631.180 +			sscanf(buffer, "%u", &value);
 631.181 +			break;
 631.182 +		default:
 631.183 +			sscanf(buffer, "%x", &value);
 631.184 +		}
 631.185 +		cheatSearchValue(&cheatSearchData,
 631.186 +		                 searchType,
 631.187 +		                 sizeType,
 631.188 +		                 numberType == 0,
 631.189 +		                 value);
 631.190 +	}
 631.191 +
 631.192 +	addChanges(true);
 631.193 +
 631.194 +	if (updateValues)
 631.195 +		cheatSearchUpdateValues(&cheatSearchData);
 631.196 +
 631.197 +	if (theApp.modelessCheatDialogIsOpen)
 631.198 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(cheatSearchGetCount(&cheatSearchData, sizeType) == 0 ? FALSE : TRUE);
 631.199 +
 631.200 +	if (0 == cheatSearchGetCount(&cheatSearchData, sizeType))
 631.201 +		OnStart();
 631.202 +}
 631.203 +
 631.204 +void GBACheatSearch::OnAddCheat()
 631.205 +{
 631.206 +	int mark = m_list.GetSelectionMark();
 631.207 +
 631.208 +	if (mark != -1)
 631.209 +	{
 631.210 +		LVITEM item;
 631.211 +		memset(&item, 0, sizeof(item));
 631.212 +		item.mask  = LVIF_PARAM;
 631.213 +		item.iItem = mark;
 631.214 +		if (m_list.GetItem(&item))
 631.215 +		{
 631.216 +			AddCheat dlg((u32)item.lParam);
 631.217 +			dlg.DoModal();
 631.218 +		}
 631.219 +	}
 631.220 +}
 631.221 +
 631.222 +void GBACheatSearch::OnUpdate()
 631.223 +{
 631.224 +	if (GetDlgItem(IDC_UPDATE)->SendMessage(BM_GETCHECK,
 631.225 +	                                        0,
 631.226 +	                                        0) & BST_CHECKED)
 631.227 +		updateValues = true;
 631.228 +	else
 631.229 +		updateValues = false;
 631.230 +	regSetDwordValue("cheatsUpdate", updateValues);
 631.231 +}
 631.232 +
 631.233 +void GBACheatSearch::OnGetdispinfoCheatList(NMHDR*pNMHDR, LRESULT*pResult)
 631.234 +{
 631.235 +	LV_DISPINFO*info = (LV_DISPINFO *)pNMHDR;
 631.236 +	if (info->item.mask & LVIF_TEXT)
 631.237 +	{
 631.238 +		int index = info->item.iItem;
 631.239 +		int col   = info->item.iSubItem;
 631.240 +
 631.241 +		switch (col)
 631.242 +		{
 631.243 +		case 0:
 631.244 +			strcpy(info->item.pszText, data[index].address);
 631.245 +			break;
 631.246 +		case 1:
 631.247 +			strcpy(info->item.pszText, data[index].oldValue);
 631.248 +			break;
 631.249 +		case 2:
 631.250 +			strcpy(info->item.pszText, data[index].newValue);
 631.251 +			break;
 631.252 +		}
 631.253 +	}
 631.254 +	*pResult = TRUE;
 631.255 +}
 631.256 +
 631.257 +void GBACheatSearch::OnItemchangedCheatList(NMHDR*pNMHDR, LRESULT*pResult)
 631.258 +{
 631.259 +	GetDlgItem(IDC_ADD_CHEAT)->EnableWindow(m_list.GetSelectionMark() != -1);
 631.260 +	*pResult = TRUE;
 631.261 +}
 631.262 +
 631.263 +BOOL GBACheatSearch::OnInitDialog()
 631.264 +{
 631.265 +	CDialog::OnInitDialog();
 631.266 +
 631.267 +	CString temp = winResLoadString(IDS_ADDRESS);
 631.268 +
 631.269 +	m_list.InsertColumn(0, temp, LVCFMT_CENTER, 125, 0);
 631.270 +
 631.271 +	temp = winResLoadString(IDS_OLD_VALUE);
 631.272 +	m_list.InsertColumn(1, temp, LVCFMT_CENTER, 125, 1);
 631.273 +
 631.274 +	temp = winResLoadString(IDS_NEW_VALUE);
 631.275 +	m_list.InsertColumn(2, temp, LVCFMT_CENTER, 125, 2);
 631.276 +
 631.277 +	m_list.SetFont(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)),
 631.278 +	               TRUE);
 631.279 +
 631.280 +	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT);
 631.281 +
 631.282 +	if (!cheatSearchData.count)
 631.283 +	{
 631.284 +		GetDlgItem(IDC_SEARCH)->EnableWindow(FALSE);
 631.285 +		GetDlgItem(IDC_ADD_CHEAT)->EnableWindow(FALSE);
 631.286 +	}
 631.287 +
 631.288 +	valueType = regQueryDwordValue("cheatsValueType", 0);
 631.289 +	if (valueType < 0 || valueType > 1)
 631.290 +		valueType = 0;
 631.291 +
 631.292 +	searchType = regQueryDwordValue("cheatsSearchType", SEARCH_EQ);
 631.293 +	if (searchType > 5 || searchType < 0)
 631.294 +		searchType = 0;
 631.295 +
 631.296 +	numberType = regQueryDwordValue("cheatsNumberType", 2);
 631.297 +	if (numberType < 0 || numberType > 2)
 631.298 +		numberType = 2;
 631.299 +
 631.300 +	sizeType = regQueryDwordValue("cheatsSizeType", 0);
 631.301 +	if (sizeType < 0 || sizeType > 2)
 631.302 +		sizeType = 0;
 631.303 +
 631.304 +	updateValues = regQueryDwordValue("cheatsUpdate", 0) ?
 631.305 +	               true : false;
 631.306 +
 631.307 +	UpdateData(FALSE);
 631.308 +
 631.309 +	if (valueType == 0)
 631.310 +		m_value.EnableWindow(FALSE);
 631.311 +	CenterWindow();
 631.312 +
 631.313 +	if (theApp.modelessCheatDialogIsOpen)
 631.314 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->ShowWindow(TRUE);
 631.315 +
 631.316 +	if (cheatSearchData.count)
 631.317 +	{
 631.318 +		addChanges(false);
 631.319 +		if (theApp.modelessCheatDialogIsOpen)
 631.320 +			GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(cheatSearchGetCount(&cheatSearchData,
 631.321 +			                                                                     sizeType) == 0 ? FALSE : TRUE);
 631.322 +	}
 631.323 +	else
 631.324 +	{
 631.325 +		if (theApp.modelessCheatDialogIsOpen)
 631.326 +			GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(FALSE);
 631.327 +	}
 631.328 +
 631.329 +	return TRUE; // return TRUE unless you set the focus to a control
 631.330 +	             // EXCEPTION: OCX Property Pages should return FALSE
 631.331 +}
 631.332 +
 631.333 +void GBACheatSearch::addChanges(bool showMsgs)
 631.334 +{
 631.335 +	int count = cheatSearchGetCount(&cheatSearchData, sizeType);
 631.336 +
 631.337 +	m_list.DeleteAllItems();
 631.338 +
 631.339 +	if (count > 4000)
 631.340 +	{
 631.341 +		if (showMsgs)
 631.342 +			systemMessage(
 631.343 +			    IDS_SEARCH_PRODUCED_TOO_MANY,
 631.344 +			    "Search produced %d results.\nThey have been remembered, but are too many to display.\nPlease refine it better by performing additional searches.",
 631.345 +			    count);
 631.346 +		return;
 631.347 +	}
 631.348 +
 631.349 +	if (count == 0)
 631.350 +	{
 631.351 +		if (showMsgs)
 631.352 +			systemMessage(IDS_SEARCH_PRODUCED_NO_RESULTS, "Search produced no results.");
 631.353 +		return;
 631.354 +	}
 631.355 +
 631.356 +	m_list.SetItemCount(count);
 631.357 +	if (data)
 631.358 +		free(data);
 631.359 +
 631.360 +	data = (WinCheatsData *)calloc(count, sizeof(WinCheatsData));
 631.361 +
 631.362 +	int inc = 1;
 631.363 +	switch (sizeType)
 631.364 +	{
 631.365 +	case 1:
 631.366 +		inc = 2;
 631.367 +		break;
 631.368 +	case 2:
 631.369 +		inc = 4;
 631.370 +		break;
 631.371 +	}
 631.372 +
 631.373 +	int index = 0;
 631.374 +	if (numberType == 0)
 631.375 +	{
 631.376 +		for (int i = 0; i < cheatSearchData.count; i++)
 631.377 +		{
 631.378 +			CheatSearchBlock *block = &cheatSearchData.blocks[i];
 631.379 +
 631.380 +			for (int j = 0; j < block->size; j += inc)
 631.381 +			{
 631.382 +				if (IS_BIT_SET(block->bits, j))
 631.383 +				{
 631.384 +					addChange(index++,
 631.385 +					          block->offset | j,
 631.386 +					          cheatSearchSignedRead(block->saved,
 631.387 +					                                j,
 631.388 +					                                sizeType),
 631.389 +					          cheatSearchSignedRead(block->data,
 631.390 +					                                j,
 631.391 +					                                sizeType));
 631.392 +				}
 631.393 +			}
 631.394 +		}
 631.395 +	}
 631.396 +	else
 631.397 +	{
 631.398 +		for (int i = 0; i < cheatSearchData.count; i++)
 631.399 +		{
 631.400 +			CheatSearchBlock *block = &cheatSearchData.blocks[i];
 631.401 +
 631.402 +			for (int j = 0; j < block->size; j += inc)
 631.403 +			{
 631.404 +				if (IS_BIT_SET(block->bits, j))
 631.405 +				{
 631.406 +					addChange(index++,
 631.407 +					          block->offset | j,
 631.408 +					          cheatSearchRead(block->saved,
 631.409 +					                          j,
 631.410 +					                          sizeType),
 631.411 +					          cheatSearchRead(block->data,
 631.412 +					                          j,
 631.413 +					                          sizeType));
 631.414 +				}
 631.415 +			}
 631.416 +		}
 631.417 +	}
 631.418 +
 631.419 +	for (int i = 0; i < count; i++)
 631.420 +	{
 631.421 +		LVITEM item;
 631.422 +
 631.423 +		item.mask      = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
 631.424 +		item.iItem     = i;
 631.425 +		item.iSubItem  = 0;
 631.426 +		item.lParam    = data[i].addr;
 631.427 +		item.state     = 0;
 631.428 +		item.stateMask = 0;
 631.429 +		item.pszText   = LPSTR_TEXTCALLBACK;
 631.430 +		m_list.InsertItem(&item);
 631.431 +
 631.432 +		m_list.SetItemText(i, 1, LPSTR_TEXTCALLBACK);
 631.433 +		m_list.SetItemText(i, 2, LPSTR_TEXTCALLBACK);
 631.434 +	}
 631.435 +}
 631.436 +
 631.437 +void GBACheatSearch::addChange(int index, u32 address, u32 oldValue, u32 newValue)
 631.438 +{
 631.439 +	data[index].addr = address;
 631.440 +	sprintf(data[index].address, "%08x", address);
 631.441 +	switch (numberType)
 631.442 +	{
 631.443 +	case 0:
 631.444 +		sprintf(data[index].oldValue, "%d", oldValue);
 631.445 +		sprintf(data[index].newValue, "%d", newValue);
 631.446 +		break;
 631.447 +	case 1:
 631.448 +		sprintf(data[index].oldValue, "%u", oldValue);
 631.449 +		sprintf(data[index].newValue, "%u", newValue);
 631.450 +		break;
 631.451 +	case 2:
 631.452 +		switch (sizeType)
 631.453 +		{
 631.454 +		case 0:
 631.455 +			sprintf(data[index].oldValue, "%02x", oldValue);
 631.456 +			sprintf(data[index].newValue, "%02x", newValue);
 631.457 +			break;
 631.458 +		case 1:
 631.459 +			sprintf(data[index].oldValue, "%04x", oldValue);
 631.460 +			sprintf(data[index].newValue, "%04x", newValue);
 631.461 +			break;
 631.462 +		case 2:
 631.463 +			sprintf(data[index].oldValue, "%08x", oldValue);
 631.464 +			sprintf(data[index].newValue, "%08x", newValue);
 631.465 +			break;
 631.466 +		}
 631.467 +	}
 631.468 +}
 631.469 +
 631.470 +void GBACheatSearch::OnValueType(UINT id)
 631.471 +{
 631.472 +	switch (id)
 631.473 +	{
 631.474 +	case IDC_OLD_VALUE:
 631.475 +		valueType = 0;
 631.476 +		m_value.EnableWindow(FALSE);
 631.477 +		regSetDwordValue("cheatsValueType", 0);
 631.478 +		break;
 631.479 +	case IDC_SPECIFIC_VALUE:
 631.480 +		valueType = 1;
 631.481 +		m_value.EnableWindow(TRUE);
 631.482 +		regSetDwordValue("cheatsValueType", 1);
 631.483 +		break;
 631.484 +	}
 631.485 +}
 631.486 +
 631.487 +void GBACheatSearch::OnSearchType(UINT id)
 631.488 +{
 631.489 +	switch (id)
 631.490 +	{
 631.491 +	case IDC_EQ:
 631.492 +		searchType = SEARCH_EQ;
 631.493 +		regSetDwordValue("cheatsSearchType", 0);
 631.494 +		break;
 631.495 +	case IDC_NE:
 631.496 +		searchType = SEARCH_NE;
 631.497 +		regSetDwordValue("cheatsSearchType", 1);
 631.498 +		break;
 631.499 +	case IDC_LT:
 631.500 +		searchType = SEARCH_LT;
 631.501 +		regSetDwordValue("cheatsSearchType", 2);
 631.502 +		break;
 631.503 +	case IDC_LE:
 631.504 +		searchType = SEARCH_LE;
 631.505 +		regSetDwordValue("cheatsSearchType", 3);
 631.506 +		break;
 631.507 +	case IDC_GT:
 631.508 +		searchType = SEARCH_GT;
 631.509 +		regSetDwordValue("cheatsSearchType", 4);
 631.510 +		break;
 631.511 +	case IDC_GE:
 631.512 +		searchType = SEARCH_GE;
 631.513 +		regSetDwordValue("cheatsSearchType", 5);
 631.514 +		break;
 631.515 +	}
 631.516 +}
 631.517 +
 631.518 +void GBACheatSearch::OnNumberType(UINT id)
 631.519 +{
 631.520 +	switch (id)
 631.521 +	{
 631.522 +	case IDC_SIGNED:
 631.523 +		numberType = 0;
 631.524 +		regSetDwordValue("cheatsNumberType", 0);
 631.525 +		if (m_list.GetItemCount())
 631.526 +		{
 631.527 +			addChanges(false);
 631.528 +		}
 631.529 +		break;
 631.530 +	case IDC_UNSIGNED:
 631.531 +		numberType = 1;
 631.532 +		regSetDwordValue("cheatsNumberType", 1);
 631.533 +		if (m_list.GetItemCount())
 631.534 +		{
 631.535 +			addChanges(false);
 631.536 +		}
 631.537 +		break;
 631.538 +	case IDC_HEXADECIMAL:
 631.539 +		numberType = 2;
 631.540 +		regSetDwordValue("cheatsNumberType", 2);
 631.541 +		if (m_list.GetItemCount())
 631.542 +		{
 631.543 +			addChanges(false);
 631.544 +		}
 631.545 +		break;
 631.546 +	}
 631.547 +}
 631.548 +
 631.549 +void GBACheatSearch::OnSizeType(UINT id)
 631.550 +{
 631.551 +	switch (id)
 631.552 +	{
 631.553 +	case IDC_SIZE_8:
 631.554 +		sizeType = BITS_8;
 631.555 +		regSetDwordValue("cheatsSizeType", 0);
 631.556 +		if (m_list.GetItemCount())
 631.557 +		{
 631.558 +			addChanges(false);
 631.559 +		}
 631.560 +		break;
 631.561 +	case IDC_SIZE_16:
 631.562 +		sizeType = BITS_16;
 631.563 +		regSetDwordValue("cheatsSizeType", 1);
 631.564 +		if (m_list.GetItemCount())
 631.565 +		{
 631.566 +			addChanges(false);
 631.567 +		}
 631.568 +		break;
 631.569 +	case IDC_SIZE_32:
 631.570 +		sizeType = BITS_32;
 631.571 +		regSetDwordValue("cheatsSizeType", 2);
 631.572 +		if (m_list.GetItemCount())
 631.573 +		{
 631.574 +			addChanges(false);
 631.575 +		}
 631.576 +		break;
 631.577 +	}
 631.578 +}
 631.579 +
 631.580 +/////////////////////////////////////////////////////////////////////////////
 631.581 +// AddCheat dialog
 631.582 +
 631.583 +AddCheat::AddCheat(u32 address, CWnd*pParent /*=NULL*/)
 631.584 +	: CDialog(AddCheat::IDD, pParent)
 631.585 +{
 631.586 +	//{{AFX_DATA_INIT(AddCheat)
 631.587 +	numberType = regQueryDwordValue("cheatsNumberType", 2);
 631.588 +	if (numberType < 0 || numberType > 2)
 631.589 +		numberType = 2;
 631.590 +	sizeType = regQueryDwordValue("cheatsSizeType", 0);
 631.591 +	if (sizeType < 0 || sizeType > 2)
 631.592 +		sizeType = 0;
 631.593 +	//}}AFX_DATA_INIT
 631.594 +	this->address = address;
 631.595 +}
 631.596 +
 631.597 +void AddCheat::DoDataExchange(CDataExchange*pDX)
 631.598 +{
 631.599 +	CDialog::DoDataExchange(pDX);
 631.600 +	//{{AFX_DATA_MAP(AddCheat)
 631.601 +	DDX_Control(pDX, IDC_VALUE, m_value);
 631.602 +	DDX_Control(pDX, IDC_DESC, m_desc);
 631.603 +	DDX_Control(pDX, IDC_ADDRESS, m_address);
 631.604 +	DDX_Radio(pDX, IDC_SIZE_8, sizeType);
 631.605 +	DDX_Radio(pDX, IDC_SIGNED, numberType);
 631.606 +	//}}AFX_DATA_MAP
 631.607 +}
 631.608 +
 631.609 +BEGIN_MESSAGE_MAP(AddCheat, CDialog)
 631.610 +//{{AFX_MSG_MAP(AddCheat)
 631.611 +ON_BN_CLICKED(ID_OK, OnOk)
 631.612 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
 631.613 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIGNED, IDC_HEXADECIMAL, OnNumberType)
 631.614 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIZE_8, IDC_SIZE_32, OnSizeType)
 631.615 +//}}AFX_MSG_MAP
 631.616 +END_MESSAGE_MAP()
 631.617 +
 631.618 +/////////////////////////////////////////////////////////////////////////////
 631.619 +// AddCheat message handlers
 631.620 +
 631.621 +void AddCheat::OnOk()
 631.622 +{
 631.623 +	// add cheat
 631.624 +	if (addCheat())
 631.625 +	{
 631.626 +		EndDialog(TRUE);
 631.627 +	}
 631.628 +}
 631.629 +
 631.630 +void AddCheat::OnCancel()
 631.631 +{
 631.632 +	EndDialog(FALSE);
 631.633 +}
 631.634 +
 631.635 +BOOL AddCheat::OnInitDialog()
 631.636 +{
 631.637 +	CDialog::OnInitDialog();
 631.638 +
 631.639 +	if (address != 0)
 631.640 +	{
 631.641 +		CString buffer;
 631.642 +		buffer.Format("%08x", address);
 631.643 +		m_address.SetWindowText(buffer);
 631.644 +		m_address.EnableWindow(FALSE);
 631.645 +	}
 631.646 +
 631.647 +	UpdateData(FALSE);
 631.648 +
 631.649 +	GetDlgItem(IDC_DESC)->SendMessage(EM_LIMITTEXT,
 631.650 +	                                  32,
 631.651 +	                                  0);
 631.652 +	if (address != 0)
 631.653 +	{
 631.654 +		GetDlgItem(IDC_SIZE_8)->EnableWindow(FALSE);
 631.655 +		GetDlgItem(IDC_SIZE_16)->EnableWindow(FALSE);
 631.656 +		GetDlgItem(IDC_SIZE_32)->EnableWindow(FALSE);
 631.657 +		GetDlgItem(IDC_HEXADECIMAL)->EnableWindow(FALSE);
 631.658 +		GetDlgItem(IDC_UNSIGNED)->EnableWindow(FALSE);
 631.659 +		GetDlgItem(IDC_SIGNED)->EnableWindow(FALSE);
 631.660 +	}
 631.661 +
 631.662 +	CenterWindow();
 631.663 +
 631.664 +	return TRUE; // return TRUE unless you set the focus to a control
 631.665 +	             // EXCEPTION: OCX Property Pages should return FALSE
 631.666 +}
 631.667 +
 631.668 +void AddCheat::OnNumberType(UINT id)
 631.669 +{
 631.670 +	switch (id)
 631.671 +	{
 631.672 +	case IDC_SIGNED:
 631.673 +		numberType = 0;
 631.674 +		regSetDwordValue("cheatsNumberType", 0);
 631.675 +		break;
 631.676 +	case IDC_UNSIGNED:
 631.677 +		numberType = 1;
 631.678 +		regSetDwordValue("cheatsNumberType", 1);
 631.679 +		break;
 631.680 +	case IDC_HEXADECIMAL:
 631.681 +		numberType = 2;
 631.682 +		regSetDwordValue("cheatsNumberType", 2);
 631.683 +		break;
 631.684 +	}
 631.685 +}
 631.686 +
 631.687 +void AddCheat::OnSizeType(UINT id)
 631.688 +{
 631.689 +	switch (id)
 631.690 +	{
 631.691 +	case IDC_SIZE_8:
 631.692 +		sizeType = BITS_8;
 631.693 +		regSetDwordValue("cheatsSizeType", 0);
 631.694 +		break;
 631.695 +	case IDC_SIZE_16:
 631.696 +		sizeType = BITS_16;
 631.697 +		regSetDwordValue("cheatsSizeType", 1);
 631.698 +		break;
 631.699 +	case IDC_SIZE_32:
 631.700 +		sizeType = BITS_32;
 631.701 +		regSetDwordValue("cheatsSizeType", 2);
 631.702 +		break;
 631.703 +	}
 631.704 +}
 631.705 +
 631.706 +bool AddCheat::addCheat()
 631.707 +{
 631.708 +	CString buffer;
 631.709 +	CString code;
 631.710 +
 631.711 +	m_address.GetWindowText(buffer);
 631.712 +	u32 address = 0;
 631.713 +	sscanf(buffer, "%x", &address);
 631.714 +	if ((address >= 0x02000000 && address < 0x02040000) ||
 631.715 +	    (address >= 0x03000000 && address < 0x03008000))
 631.716 +	{}
 631.717 +	else
 631.718 +	{
 631.719 +		systemMessage(IDS_INVALID_ADDRESS, "Invalid address: %08x", address);
 631.720 +		return false;
 631.721 +	}
 631.722 +	if (sizeType != 0)
 631.723 +	{
 631.724 +		if (sizeType == 1 && address & 1)
 631.725 +		{
 631.726 +			systemMessage(IDS_MISALIGNED_HALFWORD, "Misaligned half-word address: %08x", address);
 631.727 +			return false;
 631.728 +		}
 631.729 +		if (sizeType == 2 && address & 3)
 631.730 +		{
 631.731 +			systemMessage(IDS_MISALIGNED_WORD, "Misaligned word address: %08x", address);
 631.732 +			return false;
 631.733 +		}
 631.734 +	}
 631.735 +	u32 value;
 631.736 +	m_value.GetWindowText(buffer);
 631.737 +
 631.738 +	if (buffer.IsEmpty())
 631.739 +	{
 631.740 +		systemMessage(IDS_VALUE_CANNOT_BE_EMPTY, "Value cannot be empty");
 631.741 +		return false;
 631.742 +	}
 631.743 +
 631.744 +	switch (numberType)
 631.745 +	{
 631.746 +	case 0:
 631.747 +		sscanf(buffer, "%d", &value);
 631.748 +		break;
 631.749 +	case 1:
 631.750 +		sscanf(buffer, "%u", &value);
 631.751 +		break;
 631.752 +	default:
 631.753 +		sscanf(buffer, "%x", &value);
 631.754 +	}
 631.755 +
 631.756 +	m_desc.GetWindowText(buffer);
 631.757 +
 631.758 +	switch (sizeType)
 631.759 +	{
 631.760 +	case 0:
 631.761 +		code.Format("%08x:%02x", address, value);
 631.762 +		break;
 631.763 +	case 1:
 631.764 +		code.Format("%08x:%04x", address, value);
 631.765 +		break;
 631.766 +	case 2:
 631.767 +		code.Format("%08x:%08x", address, value);
 631.768 +		break;
 631.769 +	}
 631.770 +
 631.771 +	cheatsAdd(code, buffer, address, value, -1, sizeType);
 631.772 +	return true;
 631.773 +}
 631.774 +
 631.775 +/////////////////////////////////////////////////////////////////////////////
 631.776 +// GBACheatList dialog
 631.777 +
 631.778 +GBACheatList::GBACheatList(CWnd*pParent /*=NULL*/)
 631.779 +	: CDialog(GBACheatList::IDD, pParent)
 631.780 +{
 631.781 +	//{{AFX_DATA_INIT(GBACheatList)
 631.782 +	// NOTE: the ClassWizard will add member initialization here
 631.783 +	//}}AFX_DATA_INIT
 631.784 +}
 631.785 +
 631.786 +void GBACheatList::DoDataExchange(CDataExchange*pDX)
 631.787 +{
 631.788 +	CDialog::DoDataExchange(pDX);
 631.789 +	//{{AFX_DATA_MAP(GBACheatList)
 631.790 +	DDX_Control(pDX, IDC_RESTORE, m_restore);
 631.791 +	DDX_Control(pDX, IDC_CHEAT_LIST, m_list);
 631.792 +	//}}AFX_DATA_MAP
 631.793 +}
 631.794 +
 631.795 +BEGIN_MESSAGE_MAP(GBACheatList, CDialog)
 631.796 +//{{AFX_MSG_MAP(GBACheatList)
 631.797 +ON_BN_CLICKED(IDC_ADD_CHEAT, OnAddCheat)
 631.798 +ON_BN_CLICKED(IDC_ADD_CODE, OnAddCode)
 631.799 +ON_BN_CLICKED(IDC_ADD_CODEBREAKER, OnAddCodebreaker)
 631.800 +ON_BN_CLICKED(IDC_ADD_GAMESHARK, OnAddGameshark)
 631.801 +ON_BN_CLICKED(IDC_ENABLE, OnEnable)
 631.802 +ON_BN_CLICKED(IDC_REMOVE, OnRemove)
 631.803 +ON_BN_CLICKED(IDC_REMOVE_ALL, OnRemoveAll)
 631.804 +ON_BN_CLICKED(IDC_RESTORE, OnRestore)
 631.805 +ON_BN_CLICKED(ID_OK, OnOk)
 631.806 +ON_NOTIFY(LVN_ITEMCHANGED, IDC_CHEAT_LIST, OnItemchangedCheatList)
 631.807 +//}}AFX_MSG_MAP
 631.808 +END_MESSAGE_MAP()
 631.809 +
 631.810 +/////////////////////////////////////////////////////////////////////////////
 631.811 +// GBACheatList message handlers
 631.812 +
 631.813 +void GBACheatList::OnAddCheat()
 631.814 +{
 631.815 +	AddCheat dlg(0);
 631.816 +	dlg.DoModal();
 631.817 +	refresh();
 631.818 +}
 631.819 +
 631.820 +void GBACheatList::OnAddCode()
 631.821 +{
 631.822 +	AddCheatCode dlg;
 631.823 +	dlg.DoModal();
 631.824 +	refresh();
 631.825 +}
 631.826 +
 631.827 +void GBACheatList::OnAddCodebreaker()
 631.828 +{
 631.829 +	AddCBACode dlg;
 631.830 +	dlg.DoModal();
 631.831 +	refresh();
 631.832 +}
 631.833 +
 631.834 +void GBACheatList::OnAddGameshark()
 631.835 +{
 631.836 +	AddGSACode dlg;
 631.837 +	dlg.DoModal();
 631.838 +	refresh();
 631.839 +}
 631.840 +
 631.841 +void GBACheatList::OnEnable()
 631.842 +{
 631.843 +	int mark  = m_list.GetSelectionMark();
 631.844 +	int count = m_list.GetItemCount();
 631.845 +
 631.846 +	if (mark != -1)
 631.847 +	{
 631.848 +		LVITEM item;
 631.849 +		for (int i = 0; i < count; i++)
 631.850 +		{
 631.851 +			memset(&item, 0, sizeof(item));
 631.852 +			item.mask      = LVIF_PARAM|LVIF_STATE;
 631.853 +			item.stateMask = LVIS_SELECTED;
 631.854 +			item.iItem     = i;
 631.855 +			if (m_list.GetItem(&item))
 631.856 +			{
 631.857 +				if (item.state & LVIS_SELECTED)
 631.858 +				{
 631.859 +					if (cheatsList[item.lParam].enabled)
 631.860 +						cheatsDisable(item.lParam);
 631.861 +					else
 631.862 +						cheatsEnable(item.lParam);
 631.863 +				}
 631.864 +			}
 631.865 +		}
 631.866 +		refresh();
 631.867 +	}
 631.868 +}
 631.869 +
 631.870 +void GBACheatList::OnRemove()
 631.871 +{
 631.872 +	int mark  = m_list.GetSelectionMark();
 631.873 +	int count = m_list.GetItemCount();
 631.874 +
 631.875 +	if (mark != -1)
 631.876 +	{
 631.877 +		for (int i = count - 1; i >= 0; i--)
 631.878 +		{
 631.879 +			LVITEM item;
 631.880 +			memset(&item, 0, sizeof(item));
 631.881 +			item.mask      = LVIF_PARAM|LVIF_STATE;
 631.882 +			item.iItem     = i;
 631.883 +			item.stateMask = LVIS_SELECTED;
 631.884 +			if (m_list.GetItem(&item))
 631.885 +			{
 631.886 +				if (item.state & LVIS_SELECTED)
 631.887 +				{
 631.888 +					cheatsDelete(item.lParam, restoreValues);
 631.889 +				}
 631.890 +			}
 631.891 +		}
 631.892 +		refresh();
 631.893 +	}
 631.894 +}
 631.895 +
 631.896 +void GBACheatList::OnRemoveAll()
 631.897 +{
 631.898 +	cheatsDeleteAll(restoreValues);
 631.899 +	refresh();
 631.900 +}
 631.901 +
 631.902 +void GBACheatList::OnRestore()
 631.903 +{
 631.904 +	restoreValues = !restoreValues;
 631.905 +	regSetDwordValue("cheatsRestore", restoreValues);
 631.906 +}
 631.907 +
 631.908 +void GBACheatList::OnOk()
 631.909 +{
 631.910 +	EndDialog(TRUE);
 631.911 +}
 631.912 +
 631.913 +void GBACheatList::OnItemchangedCheatList(NMHDR*pNMHDR, LRESULT*pResult)
 631.914 +{
 631.915 +	if (m_list.GetSelectionMark() != -1)
 631.916 +	{
 631.917 +		GetDlgItem(IDC_REMOVE)->EnableWindow(TRUE);
 631.918 +		GetDlgItem(IDC_ENABLE)->EnableWindow(TRUE);
 631.919 +	}
 631.920 +	else
 631.921 +	{
 631.922 +		GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
 631.923 +		GetDlgItem(IDC_ENABLE)->EnableWindow(FALSE);
 631.924 +	}
 631.925 +
 631.926 +	if (!duringRefresh)
 631.927 +	{
 631.928 +		LPNMLISTVIEW l = (LPNMLISTVIEW)pNMHDR;
 631.929 +		if (l->uChanged & LVIF_STATE)
 631.930 +		{
 631.931 +			if (((l->uOldState & LVIS_STATEIMAGEMASK)>>12) !=
 631.932 +			    (((l->uNewState & LVIS_STATEIMAGEMASK)>>12)))
 631.933 +			{
 631.934 +				if (m_list.GetCheck(l->iItem))
 631.935 +					cheatsEnable(l->lParam);
 631.936 +				else
 631.937 +					cheatsDisable(l->lParam);
 631.938 +				refresh();
 631.939 +			}
 631.940 +		}
 631.941 +	}
 631.942 +
 631.943 +	*pResult = 0;
 631.944 +}
 631.945 +
 631.946 +BOOL GBACheatList::OnInitDialog()
 631.947 +{
 631.948 +	CDialog::OnInitDialog();
 631.949 +
 631.950 +	CString temp = winResLoadString(IDS_CODE);
 631.951 +	m_list.InsertColumn(0, temp, LVCFMT_LEFT, 170, 0);
 631.952 +	temp = winResLoadString(IDS_DESCRIPTION);
 631.953 +	m_list.InsertColumn(1, temp, LVCFMT_LEFT, 150, 1);
 631.954 +	temp = winResLoadString(IDS_STATUS);
 631.955 +	m_list.InsertColumn(2, temp, LVCFMT_LEFT, 80, 1);
 631.956 +
 631.957 +	m_list.SetFont(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)),
 631.958 +	               TRUE);
 631.959 +
 631.960 +	m_list.SetExtendedStyle(LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT);
 631.961 +
 631.962 +	duringRefresh = false;
 631.963 +
 631.964 +	restoreValues = regQueryDwordValue("cheatsRestore", 0) ?
 631.965 +	                true : false;
 631.966 +
 631.967 +	m_restore.SetCheck(restoreValues);
 631.968 +
 631.969 +	refresh();
 631.970 +	GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
 631.971 +	GetDlgItem(IDC_ENABLE)->EnableWindow(FALSE);
 631.972 +	CenterWindow();
 631.973 +
 631.974 +	return TRUE; // return TRUE unless you set the focus to a control
 631.975 +	             // EXCEPTION: OCX Property Pages should return FALSE
 631.976 +}
 631.977 +
 631.978 +void GBACheatList::refresh()
 631.979 +{
 631.980 +	duringRefresh = true;
 631.981 +	m_list.DeleteAllItems();
 631.982 +
 631.983 +	CString buffer;
 631.984 +
 631.985 +	for (int i = 0; i < cheatsNumber; i++)
 631.986 +	{
 631.987 +		LVITEM item;
 631.988 +
 631.989 +		item.mask      = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
 631.990 +		item.iItem     = i;
 631.991 +		item.iSubItem  = 0;
 631.992 +		item.lParam    = i;
 631.993 +		item.state     = 0;
 631.994 +		item.stateMask = 0;
 631.995 +		item.pszText   = cheatsList[i].codestring;
 631.996 +		m_list.InsertItem(&item);
 631.997 +
 631.998 +		m_list.SetCheck(i, (cheatsList[i].enabled) ? TRUE : FALSE);
 631.999 +
631.1000 +		m_list.SetItemText(i, 1, cheatsList[i].desc);
631.1001 +
631.1002 +		buffer = (cheatsList[i].enabled) ? 'E' : 'D';
631.1003 +		m_list.SetItemText(i, 2, buffer);
631.1004 +	}
631.1005 +	duringRefresh = false;
631.1006 +}
631.1007 +
631.1008 +/////////////////////////////////////////////////////////////////////////////
631.1009 +// AddGSACode dialog
631.1010 +
631.1011 +AddGSACode::AddGSACode(CWnd*pParent /*=NULL*/)
631.1012 +	: CDialog(AddGSACode::IDD, pParent)
631.1013 +{
631.1014 +	//{{AFX_DATA_INIT(AddGSACode)
631.1015 +	// NOTE: the ClassWizard will add member initialization here
631.1016 +	//}}AFX_DATA_INIT
631.1017 +}
631.1018 +
631.1019 +void AddGSACode::DoDataExchange(CDataExchange*pDX)
631.1020 +{
631.1021 +	CDialog::DoDataExchange(pDX);
631.1022 +	//{{AFX_DATA_MAP(AddGSACode)
631.1023 +	DDX_Control(pDX, IDC_DESC, m_desc);
631.1024 +	DDX_Control(pDX, IDC_CODE, m_code);
631.1025 +	//}}AFX_DATA_MAP
631.1026 +}
631.1027 +
631.1028 +BEGIN_MESSAGE_MAP(AddGSACode, CDialog)
631.1029 +//{{AFX_MSG_MAP(AddGSACode)
631.1030 +ON_BN_CLICKED(ID_OK, OnOk)
631.1031 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
631.1032 +//}}AFX_MSG_MAP
631.1033 +END_MESSAGE_MAP()
631.1034 +
631.1035 +/////////////////////////////////////////////////////////////////////////////
631.1036 +// AddGSACode message handlers
631.1037 +
631.1038 +void AddGSACode::OnOk()
631.1039 +{
631.1040 +	CString desc;
631.1041 +	CString buffer;
631.1042 +	CString part1;
631.1043 +	CString code;
631.1044 +	CString token;
631.1045 +
631.1046 +	m_code.GetWindowText(buffer);
631.1047 +	m_desc.GetWindowText(desc);
631.1048 +
631.1049 +	StringTokenizer st(buffer, " \t\n\r");
631.1050 +	part1.Empty();
631.1051 +	const char *t = st.next();
631.1052 +	while (t)
631.1053 +	{
631.1054 +		token = t;
631.1055 +		token.MakeUpper();
631.1056 +		if (token.GetLength() == 16)
631.1057 +			cheatsAddGSACode(token, desc, false);
631.1058 +		else if (token.GetLength() == 12)
631.1059 +		{
631.1060 +			code  = token.Left(8);
631.1061 +			code += " ";
631.1062 +			code += token.Right(4);
631.1063 +			cheatsAddCBACode(code, desc);
631.1064 +		}
631.1065 +		else if (part1.IsEmpty())
631.1066 +			part1 = token;
631.1067 +		else
631.1068 +		{
631.1069 +			if (token.GetLength() == 4)
631.1070 +			{
631.1071 +				code  = part1;
631.1072 +				code += " ";
631.1073 +				code += token;
631.1074 +				cheatsAddCBACode(code, desc);
631.1075 +			}
631.1076 +			else
631.1077 +			{
631.1078 +				code = part1 + token;
631.1079 +				cheatsAddGSACode(code, desc, true);
631.1080 +			}
631.1081 +			part1.Empty();
631.1082 +		}
631.1083 +
631.1084 +		t = st.next();
631.1085 +	}
631.1086 +	EndDialog(TRUE);
631.1087 +}
631.1088 +
631.1089 +void AddGSACode::OnCancel()
631.1090 +{
631.1091 +	EndDialog(FALSE);
631.1092 +}
631.1093 +
631.1094 +BOOL AddGSACode::OnInitDialog()
631.1095 +{
631.1096 +	CDialog::OnInitDialog();
631.1097 +
631.1098 +	m_code.LimitText(1024);
631.1099 +	m_desc.LimitText(32);
631.1100 +	CString title = winResLoadString(IDS_ADD_GSA_CODE);
631.1101 +	SetWindowText(title);
631.1102 +	CenterWindow();
631.1103 +
631.1104 +	return TRUE; // return TRUE unless you set the focus to a control
631.1105 +	             // EXCEPTION: OCX Property Pages should return FALSE
631.1106 +}
631.1107 +
631.1108 +/////////////////////////////////////////////////////////////////////////////
631.1109 +// AddCBACode dialog
631.1110 +
631.1111 +AddCBACode::AddCBACode(CWnd*pParent /*=NULL*/)
631.1112 +	: CDialog(AddCBACode::IDD, pParent)
631.1113 +{
631.1114 +	//{{AFX_DATA_INIT(AddCBACode)
631.1115 +	// NOTE: the ClassWizard will add member initialization here
631.1116 +	//}}AFX_DATA_INIT
631.1117 +}
631.1118 +
631.1119 +void AddCBACode::DoDataExchange(CDataExchange*pDX)
631.1120 +{
631.1121 +	CDialog::DoDataExchange(pDX);
631.1122 +	//{{AFX_DATA_MAP(AddCBACode)
631.1123 +	DDX_Control(pDX, IDC_DESC, m_desc);
631.1124 +	DDX_Control(pDX, IDC_CODE, m_code);
631.1125 +	//}}AFX_DATA_MAP
631.1126 +}
631.1127 +
631.1128 +BEGIN_MESSAGE_MAP(AddCBACode, CDialog)
631.1129 +//{{AFX_MSG_MAP(AddCBACode)
631.1130 +ON_BN_CLICKED(ID_OK, OnOk)
631.1131 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
631.1132 +//}}AFX_MSG_MAP
631.1133 +END_MESSAGE_MAP()
631.1134 +
631.1135 +/////////////////////////////////////////////////////////////////////////////
631.1136 +// AddCBACode message handlers
631.1137 +
631.1138 +void AddCBACode::OnOk()
631.1139 +{
631.1140 +	CString desc;
631.1141 +	CString buffer;
631.1142 +	CString part1;
631.1143 +	CString code;
631.1144 +	CString token;
631.1145 +
631.1146 +	m_code.GetWindowText(buffer);
631.1147 +	m_desc.GetWindowText(desc);
631.1148 +
631.1149 +	StringTokenizer st(buffer, " \t\n\r");
631.1150 +	part1.Empty();
631.1151 +	const char *t = st.next();
631.1152 +	while (t)
631.1153 +	{
631.1154 +		token = t;
631.1155 +		token.MakeUpper();
631.1156 +		if (token.GetLength() == 16)
631.1157 +			cheatsAddGSACode(token, desc, false);
631.1158 +		else if (token.GetLength() == 12)
631.1159 +		{
631.1160 +			code  = token.Left(8);
631.1161 +			code += " ";
631.1162 +			code += token.Right(4);
631.1163 +			cheatsAddCBACode(code, desc);
631.1164 +		}
631.1165 +		else if (part1.IsEmpty())
631.1166 +			part1 = token;
631.1167 +		else
631.1168 +		{
631.1169 +			if (token.GetLength() == 4)
631.1170 +			{
631.1171 +				code  = part1;
631.1172 +				code += " ";
631.1173 +				code += token;
631.1174 +				cheatsAddCBACode(code, desc);
631.1175 +			}
631.1176 +			else
631.1177 +			{
631.1178 +				code = part1 + token;
631.1179 +				cheatsAddGSACode(code, desc, true);
631.1180 +			}
631.1181 +			part1.Empty();
631.1182 +		}
631.1183 +
631.1184 +		t = st.next();
631.1185 +	}
631.1186 +	EndDialog(TRUE);
631.1187 +}
631.1188 +
631.1189 +void AddCBACode::OnCancel()
631.1190 +{
631.1191 +	EndDialog(FALSE);
631.1192 +}
631.1193 +
631.1194 +BOOL AddCBACode::OnInitDialog()
631.1195 +{
631.1196 +	CDialog::OnInitDialog();
631.1197 +
631.1198 +	m_code.LimitText(1024);
631.1199 +	m_desc.LimitText(32);
631.1200 +	CString title = winResLoadString(IDS_ADD_CBA_CODE);
631.1201 +	SetWindowText(title);
631.1202 +	CenterWindow();
631.1203 +
631.1204 +	return TRUE; // return TRUE unless you set the focus to a control
631.1205 +	             // EXCEPTION: OCX Property Pages should return FALSE
631.1206 +}
631.1207 +
631.1208 +/////////////////////////////////////////////////////////////////////////////
631.1209 +// AddCheatCode dialog
631.1210 +
631.1211 +AddCheatCode::AddCheatCode(CWnd*pParent /*=NULL*/)
631.1212 +	: CDialog(AddCheatCode::IDD, pParent)
631.1213 +{
631.1214 +	//{{AFX_DATA_INIT(AddCheatCode)
631.1215 +	// NOTE: the ClassWizard will add member initialization here
631.1216 +	//}}AFX_DATA_INIT
631.1217 +}
631.1218 +
631.1219 +void AddCheatCode::DoDataExchange(CDataExchange*pDX)
631.1220 +{
631.1221 +	CDialog::DoDataExchange(pDX);
631.1222 +	//{{AFX_DATA_MAP(AddCheatCode)
631.1223 +	DDX_Control(pDX, IDC_DESC, m_desc);
631.1224 +	DDX_Control(pDX, IDC_CODE, m_code);
631.1225 +	//}}AFX_DATA_MAP
631.1226 +}
631.1227 +
631.1228 +BEGIN_MESSAGE_MAP(AddCheatCode, CDialog)
631.1229 +//{{AFX_MSG_MAP(AddCheatCode)
631.1230 +ON_BN_CLICKED(ID_OK, OnOk)
631.1231 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
631.1232 +//}}AFX_MSG_MAP
631.1233 +END_MESSAGE_MAP()
631.1234 +
631.1235 +/////////////////////////////////////////////////////////////////////////////
631.1236 +// AddCheatCode message handlers
631.1237 +
631.1238 +void AddCheatCode::OnOk()
631.1239 +{
631.1240 +	CString desc;
631.1241 +	CString buffer;
631.1242 +	CString token;
631.1243 +
631.1244 +	m_code.GetWindowText(buffer);
631.1245 +	m_desc.GetWindowText(desc);
631.1246 +
631.1247 +	StringTokenizer st(buffer, " \t\n\r");
631.1248 +	const char *    t = st.next();
631.1249 +	while (t)
631.1250 +	{
631.1251 +		token = t;
631.1252 +		token.MakeUpper();
631.1253 +		cheatsAddCheatCode(token, desc);
631.1254 +		t = st.next();
631.1255 +	}
631.1256 +	EndDialog(TRUE);
631.1257 +}
631.1258 +
631.1259 +void AddCheatCode::OnCancel()
631.1260 +{
631.1261 +	EndDialog(FALSE);
631.1262 +}
631.1263 +
631.1264 +BOOL AddCheatCode::OnInitDialog()
631.1265 +{
631.1266 +	CDialog::OnInitDialog();
631.1267 +
631.1268 +	m_code.LimitText(1024);
631.1269 +	m_desc.LimitText(32);
631.1270 +	CString title = winResLoadString(IDS_ADD_CHEAT_CODE);
631.1271 +	SetWindowText(title);
631.1272 +	CenterWindow();
631.1273 +
631.1274 +	return TRUE; // return TRUE unless you set the focus to a control
631.1275 +	             // EXCEPTION: OCX Property Pages should return FALSE
631.1276 +}
631.1277 +
631.1278 +void GBACheatSearch::OnBnClickedCheatrefreshbutton()
631.1279 +{
631.1280 +	addChanges(false);
631.1281 +}
631.1282 +
   632.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   632.2 +++ b/src/win32/GBACheatsDlg.h	Sat Mar 03 10:31:27 2012 -0600
   632.3 @@ -0,0 +1,264 @@
   632.4 +#if !defined(AFX_GBACHEATS_H__FC31D47D_52C8_42B2_95C7_7C3FD09316A4__INCLUDED_)
   632.5 +#define AFX_GBACHEATS_H__FC31D47D_52C8_42B2_95C7_7C3FD09316A4__INCLUDED_
   632.6 +
   632.7 +#if _MSC_VER > 1000
   632.8 +#pragma once
   632.9 +#endif // _MSC_VER > 1000
  632.10 +// GBACheatsDlg.h : header file
  632.11 +//
  632.12 +
  632.13 +/////////////////////////////////////////////////////////////////////////////
  632.14 +// GBACheatSearch dialog
  632.15 +
  632.16 +struct WinCheatsData
  632.17 +{
  632.18 +	u32  addr;
  632.19 +	char address[9];
  632.20 +	char oldValue[12];
  632.21 +	char newValue[12];
  632.22 +};
  632.23 +
  632.24 +class GBACheatSearch : public CDialog
  632.25 +{
  632.26 +	// Construction
  632.27 +public:
  632.28 +	afx_msg void OnSizeType(UINT id);
  632.29 +	afx_msg void OnNumberType(UINT id);
  632.30 +	afx_msg void OnSearchType(UINT id);
  632.31 +	afx_msg void OnValueType(UINT id);
  632.32 +	void addChange(int index, u32 address, u32 oldValue, u32 newValue);
  632.33 +	GBACheatSearch(CWnd*pParent = NULL);  // standard constructor
  632.34 +	~GBACheatSearch();
  632.35 +
  632.36 +	// Dialog Data
  632.37 +	//{{AFX_DATA(GBACheatSearch)
  632.38 +	enum { IDD = IDD_CHEATS };
  632.39 +	CEdit     m_value;
  632.40 +	CListCtrl m_list;
  632.41 +	int       valueType;
  632.42 +	int       sizeType;
  632.43 +	int       searchType;
  632.44 +	int       numberType;
  632.45 +	BOOL      updateValues;
  632.46 +	//}}AFX_DATA
  632.47 +
  632.48 +	// Overrides
  632.49 +	// ClassWizard generated virtual function overrides
  632.50 +	//{{AFX_VIRTUAL(GBACheatSearch)
  632.51 +protected:
  632.52 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  632.53 +	//}}AFX_VIRTUAL
  632.54 +
  632.55 +	// Implementation
  632.56 +protected:
  632.57 +	// Generated message map functions
  632.58 +	//{{AFX_MSG(GBACheatSearch)
  632.59 +	afx_msg void OnOk();
  632.60 +	afx_msg void OnStart();
  632.61 +	afx_msg void OnSearch();
  632.62 +	afx_msg void OnAddCheat();
  632.63 +	afx_msg void OnUpdate();
  632.64 +	afx_msg void OnGetdispinfoCheatList(NMHDR*pNMHDR, LRESULT*pResult);
  632.65 +	afx_msg void OnItemchangedCheatList(NMHDR*pNMHDR, LRESULT*pResult);
  632.66 +	virtual BOOL OnInitDialog();
  632.67 +	//}}AFX_MSG
  632.68 +	DECLARE_MESSAGE_MAP()
  632.69 +private:
  632.70 +	void addChanges(bool showMsgs);
  632.71 +	WinCheatsData *data;
  632.72 +public:
  632.73 +	afx_msg void OnClose();
  632.74 +	afx_msg void OnBnClickedCheatrefreshbutton();
  632.75 +};
  632.76 +
  632.77 +/////////////////////////////////////////////////////////////////////////////
  632.78 +// AddCheat dialog
  632.79 +
  632.80 +class AddCheat : public CDialog
  632.81 +{
  632.82 +	// Construction
  632.83 +public:
  632.84 +	bool addCheat();
  632.85 +	afx_msg void OnSizeType(UINT id);
  632.86 +	afx_msg void OnNumberType(UINT id);
  632.87 +	AddCheat(u32 address, CWnd*pParent = NULL);  // standard constructor
  632.88 +
  632.89 +	// Dialog Data
  632.90 +	//{{AFX_DATA(AddCheat)
  632.91 +	enum { IDD = IDD_ADD_CHEAT };
  632.92 +	CEdit m_value;
  632.93 +	CEdit m_desc;
  632.94 +	CEdit m_address;
  632.95 +	int   sizeType;
  632.96 +	int   numberType;
  632.97 +	//}}AFX_DATA
  632.98 +
  632.99 +	// Overrides
 632.100 +	// ClassWizard generated virtual function overrides
 632.101 +	//{{AFX_VIRTUAL(AddCheat)
 632.102 +protected:
 632.103 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
 632.104 +	//}}AFX_VIRTUAL
 632.105 +
 632.106 +	// Implementation
 632.107 +protected:
 632.108 +	u32   address;
 632.109 +
 632.110 +	// Generated message map functions
 632.111 +	//{{AFX_MSG(AddCheat)
 632.112 +	afx_msg void OnOk();
 632.113 +	afx_msg void OnCancel();
 632.114 +	virtual BOOL OnInitDialog();
 632.115 +	//}}AFX_MSG
 632.116 +	DECLARE_MESSAGE_MAP()
 632.117 +};
 632.118 +/////////////////////////////////////////////////////////////////////////////
 632.119 +// GBACheatList dialog
 632.120 +
 632.121 +class GBACheatList : public CDialog
 632.122 +{
 632.123 +	// Construction
 632.124 +public:
 632.125 +	void refresh();
 632.126 +	GBACheatList(CWnd*pParent = NULL);  // standard constructor
 632.127 +
 632.128 +	// Dialog Data
 632.129 +	//{{AFX_DATA(GBACheatList)
 632.130 +	enum { IDD = IDD_CHEAT_LIST };
 632.131 +	CButton   m_restore;
 632.132 +	CListCtrl m_list;
 632.133 +	//}}AFX_DATA
 632.134 +
 632.135 +	// Overrides
 632.136 +	// ClassWizard generated virtual function overrides
 632.137 +	//{{AFX_VIRTUAL(GBACheatList)
 632.138 +protected:
 632.139 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
 632.140 +	//}}AFX_VIRTUAL
 632.141 +
 632.142 +	// Implementation
 632.143 +protected:
 632.144 +	bool duringRefresh;
 632.145 +	bool restoreValues;
 632.146 +
 632.147 +	// Generated message map functions
 632.148 +	//{{AFX_MSG(GBACheatList)
 632.149 +	afx_msg void OnAddCheat();
 632.150 +	afx_msg void OnAddCode();
 632.151 +	afx_msg void OnAddCodebreaker();
 632.152 +	afx_msg void OnAddGameshark();
 632.153 +	afx_msg void OnEnable();
 632.154 +	afx_msg void OnRemove();
 632.155 +	afx_msg void OnRemoveAll();
 632.156 +	afx_msg void OnRestore();
 632.157 +	afx_msg void OnOk();
 632.158 +	afx_msg void OnItemchangedCheatList(NMHDR*pNMHDR, LRESULT*pResult);
 632.159 +	virtual BOOL OnInitDialog();
 632.160 +	//}}AFX_MSG
 632.161 +	DECLARE_MESSAGE_MAP()
 632.162 +};
 632.163 +/////////////////////////////////////////////////////////////////////////////
 632.164 +// AddGSACode dialog
 632.165 +
 632.166 +class AddGSACode : public CDialog
 632.167 +{
 632.168 +	// Construction
 632.169 +public:
 632.170 +	AddGSACode(CWnd*pParent = NULL);  // standard constructor
 632.171 +
 632.172 +	// Dialog Data
 632.173 +	//{{AFX_DATA(AddGSACode)
 632.174 +	enum { IDD = IDD_ADD_CHEAT_DLG };
 632.175 +	CEdit m_desc;
 632.176 +	CEdit m_code;
 632.177 +	//}}AFX_DATA
 632.178 +
 632.179 +	// Overrides
 632.180 +	// ClassWizard generated virtual function overrides
 632.181 +	//{{AFX_VIRTUAL(AddGSACode)
 632.182 +protected:
 632.183 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
 632.184 +	//}}AFX_VIRTUAL
 632.185 +
 632.186 +	// Implementation
 632.187 +protected:
 632.188 +	// Generated message map functions
 632.189 +	//{{AFX_MSG(AddGSACode)
 632.190 +	afx_msg void OnOk();
 632.191 +	afx_msg void OnCancel();
 632.192 +	virtual BOOL OnInitDialog();
 632.193 +	//}}AFX_MSG
 632.194 +	DECLARE_MESSAGE_MAP()
 632.195 +};
 632.196 +
 632.197 +/////////////////////////////////////////////////////////////////////////////
 632.198 +// AddCBACode dialog
 632.199 +
 632.200 +class AddCBACode : public CDialog
 632.201 +{
 632.202 +	// Construction
 632.203 +public:
 632.204 +	AddCBACode(CWnd*pParent = NULL);  // standard constructor
 632.205 +
 632.206 +	// Dialog Data
 632.207 +	//{{AFX_DATA(AddCBACode)
 632.208 +	enum { IDD = IDD_ADD_CHEAT_DLG };
 632.209 +	CEdit m_desc;
 632.210 +	CEdit m_code;
 632.211 +	//}}AFX_DATA
 632.212 +
 632.213 +	// Overrides
 632.214 +	// ClassWizard generated virtual function overrides
 632.215 +	//{{AFX_VIRTUAL(AddCBACode)
 632.216 +protected:
 632.217 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
 632.218 +	//}}AFX_VIRTUAL
 632.219 +
 632.220 +	// Implementation
 632.221 +protected:
 632.222 +	// Generated message map functions
 632.223 +	//{{AFX_MSG(AddCBACode)
 632.224 +	afx_msg void OnOk();
 632.225 +	afx_msg void OnCancel();
 632.226 +	virtual BOOL OnInitDialog();
 632.227 +	//}}AFX_MSG
 632.228 +	DECLARE_MESSAGE_MAP()
 632.229 +};
 632.230 +
 632.231 +/////////////////////////////////////////////////////////////////////////////
 632.232 +// AddCheatCode dialog
 632.233 +
 632.234 +class AddCheatCode : public CDialog
 632.235 +{
 632.236 +	// Construction
 632.237 +public:
 632.238 +	AddCheatCode(CWnd*pParent = NULL);  // standard constructor
 632.239 +
 632.240 +	// Dialog Data
 632.241 +	//{{AFX_DATA(AddCheatCode)
 632.242 +	enum { IDD = IDD_ADD_CHEAT_DLG };
 632.243 +	CEdit m_desc;
 632.244 +	CEdit m_code;
 632.245 +	//}}AFX_DATA
 632.246 +
 632.247 +	// Overrides
 632.248 +	// ClassWizard generated virtual function overrides
 632.249 +	//{{AFX_VIRTUAL(AddCheatCode)
 632.250 +protected:
 632.251 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
 632.252 +	//}}AFX_VIRTUAL
 632.253 +
 632.254 +	// Implementation
 632.255 +protected:
 632.256 +	// Generated message map functions
 632.257 +	//{{AFX_MSG(AddCheatCode)
 632.258 +	afx_msg void OnOk();
 632.259 +	afx_msg void OnCancel();
 632.260 +	virtual BOOL OnInitDialog();
 632.261 +	//}}AFX_MSG
 632.262 +	DECLARE_MESSAGE_MAP()
 632.263 +};
 632.264 +//{{AFX_INSERT_LOCATION}}
 632.265 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
 632.266 +
 632.267 +#endif // !defined(AFX_GBACHEATS_H__FC31D47D_52C8_42B2_95C7_7C3FD09316A4__INCLUDED_)
   633.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   633.2 +++ b/src/win32/GBCheatsDlg.cpp	Sat Mar 03 10:31:27 2012 -0600
   633.3 @@ -0,0 +1,1140 @@
   633.4 +// GBCheats.cpp : implementation file
   633.5 +//
   633.6 +
   633.7 +#include "stdafx.h"
   633.8 +#include "resource.h"
   633.9 +#include "GBCheatsDlg.h"
  633.10 +#include "Reg.h"
  633.11 +#include "StringTokenizer.h"
  633.12 +#include "WinResUtil.h"
  633.13 +#include "Sound.h"
  633.14 +#include "VBA.h"
  633.15 +
  633.16 +#include "../common/CheatSearch.h"
  633.17 +#include "../gb/gbCheats.h"
  633.18 +#include "../gb/gbGlobals.h"
  633.19 +
  633.20 +static inline bool winGbCheatAddVerifyGs(const char *code, const char *desc)
  633.21 +{
  633.22 +	gbAddGsCheat(code, desc);
  633.23 +	return true;
  633.24 +}
  633.25 +
  633.26 +static inline bool winGbCheatAddVerifyGg(const char *code, const char *desc)
  633.27 +{
  633.28 +	gbAddGgCheat(code, desc);
  633.29 +	return true;
  633.30 +}
  633.31 +
  633.32 +////////////////////////////////
  633.33 +
  633.34 +bool winGbCheatReaddress()
  633.35 +{
  633.36 +	if (cheatSearchData.count != 3)
  633.37 +		return false;
  633.38 +
  633.39 +	CheatSearchBlock *block = &cheatSearchData.blocks[0];
  633.40 +	if (gbRamSize > 0)
  633.41 +	{
  633.42 +		if (gbRam)
  633.43 +			block->data = gbRam;
  633.44 +		else
  633.45 +			block->data = &gbMemory[0xa000];
  633.46 +		block->offset = 0xa000;
  633.47 +		block->size  = gbRamSize;
  633.48 +		cheatSearchSetSavedAndBits(block);
  633.49 +	}
  633.50 +	else
  633.51 +	{
  633.52 +		cheatSearchZeroBlock(&cheatSearchData.blocks[0]);
  633.53 +	}
  633.54 +
  633.55 +	block = &cheatSearchData.blocks[1];
  633.56 +	if (gbCgbMode)
  633.57 +	{
  633.58 +		block->data   = &gbMemory[0xc000];
  633.59 +		block->offset = 0xc000;
  633.60 +		block->size   = 0x1000;
  633.61 +		cheatSearchSetSavedAndBits(block);
  633.62 +
  633.63 +		block         = &cheatSearchData.blocks[2];
  633.64 +		block->data   = gbWram;
  633.65 +		block->offset = 0xd000;
  633.66 +		block->size   = 0x8000;
  633.67 +		cheatSearchSetSavedAndBits(block);
  633.68 +	}
  633.69 +	else
  633.70 +	{
  633.71 +		block->data   = &gbMemory[0xc000];
  633.72 +		block->offset = 0xc000;
  633.73 +		block->size   = 0x2000;
  633.74 +		cheatSearchSetSavedAndBits(block);
  633.75 +
  633.76 +		cheatSearchZeroBlock(&cheatSearchData.blocks[2]);
  633.77 +	}
  633.78 +
  633.79 +	cheatSearchData.count = 3;
  633.80 +	return true;
  633.81 +}
  633.82 +
  633.83 +/////////////////////////////////////////////////////////////////////////////
  633.84 +// GBCheatSearch dialog
  633.85 +
  633.86 +GBCheatSearch::GBCheatSearch(CWnd*pParent /*=NULL*/)
  633.87 +	: CDialog(GBCheatSearch::IDD, pParent)
  633.88 +{
  633.89 +	//{{AFX_DATA_INIT(GBCheatSearch)
  633.90 +	searchType   = -1;
  633.91 +	numberType   = -1;
  633.92 +	sizeType     = -1;
  633.93 +	updateValues = FALSE;
  633.94 +	valueType    = -1;
  633.95 +	//}}AFX_DATA_INIT
  633.96 +	data = NULL;
  633.97 +}
  633.98 +
  633.99 +GBCheatSearch::~GBCheatSearch()
 633.100 +{
 633.101 +	if (data)
 633.102 +		free(data);
 633.103 +}
 633.104 +
 633.105 +void GBCheatSearch::DoDataExchange(CDataExchange*pDX)
 633.106 +{
 633.107 +	CDialog::DoDataExchange(pDX);
 633.108 +	//{{AFX_DATA_MAP(GBCheatSearch)
 633.109 +	DDX_Control(pDX, IDC_VALUE, m_value);
 633.110 +	DDX_Control(pDX, IDC_CHEAT_LIST, m_list);
 633.111 +	DDX_Radio(pDX, IDC_EQ, searchType);
 633.112 +	DDX_Radio(pDX, IDC_SIGNED, numberType);
 633.113 +	DDX_Radio(pDX, IDC_SIZE_8, sizeType);
 633.114 +	DDX_Check(pDX, IDC_UPDATE, updateValues);
 633.115 +	DDX_Radio(pDX, IDC_OLD_VALUE, valueType);
 633.116 +	//}}AFX_DATA_MAP
 633.117 +}
 633.118 +
 633.119 +BEGIN_MESSAGE_MAP(GBCheatSearch, CDialog)
 633.120 +//{{AFX_MSG_MAP(GBCheatSearch)
 633.121 +ON_BN_CLICKED(ID_OK, OnOk)
 633.122 +ON_BN_CLICKED(IDC_ADD_CHEAT, OnAddCheat)
 633.123 +ON_BN_CLICKED(IDC_SEARCH, OnSearch)
 633.124 +ON_BN_CLICKED(IDC_START, OnStart)
 633.125 +ON_BN_CLICKED(IDC_UPDATE, OnUpdate)
 633.126 +ON_NOTIFY(LVN_GETDISPINFO, IDC_CHEAT_LIST, OnGetdispinfoCheatList)
 633.127 +ON_NOTIFY(LVN_ITEMCHANGED, IDC_CHEAT_LIST, OnItemchangedCheatList)
 633.128 +ON_CONTROL_RANGE(BN_CLICKED, IDC_OLD_VALUE, IDC_SPECIFIC_VALUE, OnValueType)
 633.129 +ON_CONTROL_RANGE(BN_CLICKED, IDC_EQ, IDC_GE, OnSearchType)
 633.130 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIGNED, IDC_HEXADECIMAL, OnNumberType)
 633.131 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIZE_8, IDC_SIZE_32, OnSizeType)
 633.132 +//}}AFX_MSG_MAP
 633.133 +ON_WM_CLOSE()
 633.134 +ON_BN_CLICKED(IDC_CHEATREFRESHBUTTON, OnBnClickedCheatrefreshbutton)
 633.135 +END_MESSAGE_MAP()
 633.136 +
 633.137 +/////////////////////////////////////////////////////////////////////////////
 633.138 +// GBCheatSearch message handlers
 633.139 +
 633.140 +void GBCheatSearch::OnOk()
 633.141 +{
 633.142 +	if (data)
 633.143 +		free(data);
 633.144 +	data = NULL;
 633.145 +
 633.146 +	if (theApp.modelessCheatDialogIsOpen)
 633.147 +	{
 633.148 +		theApp.modelessCheatDialogIsOpen = false;
 633.149 +		DestroyWindow();
 633.150 +	}
 633.151 +	else
 633.152 +	{
 633.153 +		EndDialog(TRUE);
 633.154 +	}
 633.155 +}
 633.156 +
 633.157 +void GBCheatSearch::OnClose()
 633.158 +{
 633.159 +	CDialog::OnClose();
 633.160 +	if (theApp.modelessCheatDialogIsOpen)
 633.161 +	{
 633.162 +		theApp.modelessCheatDialogIsOpen = false;
 633.163 +		DestroyWindow();
 633.164 +	}
 633.165 +	else
 633.166 +	{
 633.167 +		EndDialog(FALSE);
 633.168 +	}
 633.169 +}
 633.170 +
 633.171 +void GBCheatSearch::OnBnClickedCheatrefreshbutton()
 633.172 +{
 633.173 +	addChanges(false);
 633.174 +}
 633.175 +
 633.176 +void GBCheatSearch::OnAddCheat()
 633.177 +{
 633.178 +	int mark = m_list.GetSelectionMark();
 633.179 +
 633.180 +	if (mark != -1)
 633.181 +	{
 633.182 +		LVITEM item;
 633.183 +		memset(&item, 0, sizeof(item));
 633.184 +		item.mask  = LVIF_PARAM;
 633.185 +		item.iItem = mark;
 633.186 +		if (m_list.GetItem(&item))
 633.187 +		{
 633.188 +			AddGBCheat dlg((u32)item.lParam);
 633.189 +			dlg.DoModal();
 633.190 +		}
 633.191 +	}
 633.192 +}
 633.193 +
 633.194 +void GBCheatSearch::OnSearch()
 633.195 +{
 633.196 +	CString buffer;
 633.197 +	if (valueType == 0)
 633.198 +		cheatSearch(&cheatSearchData,
 633.199 +		            searchType,
 633.200 +		            sizeType,
 633.201 +		            numberType == 0);
 633.202 +	else
 633.203 +	{
 633.204 +		m_value.GetWindowText(buffer);
 633.205 +		if (buffer.IsEmpty())
 633.206 +		{
 633.207 +			systemMessage(IDS_NUMBER_CANNOT_BE_EMPTY, "Number cannot be empty");
 633.208 +			return;
 633.209 +		}
 633.210 +		int value = 0;
 633.211 +		switch (numberType)
 633.212 +		{
 633.213 +		case 0:
 633.214 +			sscanf(buffer, "%d", &value);
 633.215 +			break;
 633.216 +		case 1:
 633.217 +			sscanf(buffer, "%u", &value);
 633.218 +			break;
 633.219 +		default:
 633.220 +			sscanf(buffer, "%x", &value);
 633.221 +		}
 633.222 +		cheatSearchValue(&cheatSearchData,
 633.223 +		                 searchType,
 633.224 +		                 sizeType,
 633.225 +		                 numberType == 0,
 633.226 +		                 value);
 633.227 +	}
 633.228 +
 633.229 +	addChanges(true);
 633.230 +
 633.231 +	if (updateValues)
 633.232 +		cheatSearchUpdateValues(&cheatSearchData);
 633.233 +
 633.234 +	if (theApp.modelessCheatDialogIsOpen)
 633.235 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(cheatSearchGetCount(&cheatSearchData, sizeType) == 0 ? FALSE : TRUE);
 633.236 +
 633.237 +	if (0 == cheatSearchGetCount(&cheatSearchData, sizeType))
 633.238 +		OnStart();
 633.239 +}
 633.240 +
 633.241 +void GBCheatSearch::OnStart()
 633.242 +{
 633.243 +	if (cheatSearchData.count == 0)
 633.244 +	{
 633.245 +		CheatSearchBlock *block = &cheatSearchData.blocks[0];
 633.246 +		if (gbRamSize > 0)
 633.247 +		{
 633.248 +			if (gbRam)
 633.249 +				block->data = gbRam;
 633.250 +			else
 633.251 +				block->data = &gbMemory[0xa000];
 633.252 +			block->size  = gbRamSize;
 633.253 +			block->offset = 0xa000;
 633.254 +			block->saved = (u8 *)malloc(gbRamSize);
 633.255 +			block->bits  = (u8 *)malloc(gbRamSize >> 3);
 633.256 +		}
 633.257 +		else
 633.258 +		{
 633.259 +			cheatSearchZeroBlock(&cheatSearchData.blocks[0]);
 633.260 +		}
 633.261 +
 633.262 +		block = &cheatSearchData.blocks[1];
 633.263 +		if (gbCgbMode)
 633.264 +		{
 633.265 +			block->data   = &gbMemory[0xc000];
 633.266 +			block->size   = 0x1000;
 633.267 +			block->offset = 0xc000;
 633.268 +			block->saved  = (u8 *)malloc(0x1000);
 633.269 +			block->bits   = (u8 *)malloc(0x1000 >> 3);
 633.270 +
 633.271 +			block         = &cheatSearchData.blocks[2];
 633.272 +			block->data   = gbWram;
 633.273 +			block->size   = 0x8000;
 633.274 +			block->offset = 0xd000;
 633.275 +			block->saved  = (u8 *)malloc(0x8000);
 633.276 +			block->bits   = (u8 *)malloc(0x8000 >> 3);
 633.277 +		}
 633.278 +		else
 633.279 +		{
 633.280 +			block->data   = &gbMemory[0xc000];
 633.281 +			block->size   = 0x2000;
 633.282 +			block->offset = 0xc000;
 633.283 +			block->saved  = (u8 *)malloc(0x2000);
 633.284 +			block->bits   = (u8 *)malloc(0x2000 >> 3);
 633.285 +
 633.286 +			cheatSearchZeroBlock(&cheatSearchData.blocks[2]);
 633.287 +		}
 633.288 +
 633.289 +		cheatSearchData.count = 3;
 633.290 +	}
 633.291 +
 633.292 +	cheatSearchStart(&cheatSearchData);
 633.293 +	GetDlgItem(IDC_SEARCH)->EnableWindow(TRUE);
 633.294 +
 633.295 +	if (theApp.modelessCheatDialogIsOpen)
 633.296 +	{
 633.297 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->ShowWindow(TRUE);
 633.298 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(FALSE);
 633.299 +	}
 633.300 +}
 633.301 +
 633.302 +void GBCheatSearch::OnUpdate()
 633.303 +{
 633.304 +	if (GetDlgItem(IDC_UPDATE)->SendMessage(BM_GETCHECK,
 633.305 +	                                        0,
 633.306 +	                                        0) & BST_CHECKED)
 633.307 +		updateValues = true;
 633.308 +	else
 633.309 +		updateValues = false;
 633.310 +	regSetDwordValue("gbCheatsUpdate", updateValues);
 633.311 +}
 633.312 +
 633.313 +BOOL GBCheatSearch::OnInitDialog()
 633.314 +{
 633.315 +	CDialog::OnInitDialog();
 633.316 +
 633.317 +	CString temp = winResLoadString(IDS_ADDRESS);
 633.318 +
 633.319 +	m_list.InsertColumn(0, temp, LVCFMT_CENTER, 125, 0);
 633.320 +
 633.321 +	temp = winResLoadString(IDS_OLD_VALUE);
 633.322 +	m_list.InsertColumn(1, temp, LVCFMT_CENTER, 125, 1);
 633.323 +
 633.324 +	temp = winResLoadString(IDS_NEW_VALUE);
 633.325 +	m_list.InsertColumn(2, temp, LVCFMT_CENTER, 125, 2);
 633.326 +
 633.327 +	m_list.SetFont(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)),
 633.328 +	               TRUE);
 633.329 +
 633.330 +	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT);
 633.331 +
 633.332 +	if (!cheatSearchData.count)
 633.333 +	{
 633.334 +		GetDlgItem(IDC_SEARCH)->EnableWindow(FALSE);
 633.335 +		GetDlgItem(IDC_ADD_CHEAT)->EnableWindow(FALSE);
 633.336 +	}
 633.337 +
 633.338 +	valueType = regQueryDwordValue("gbCheatsValueType", 0);
 633.339 +	if (valueType < 0 || valueType > 1)
 633.340 +		valueType = 2;
 633.341 +
 633.342 +	searchType = regQueryDwordValue("gbCheatsSearchType",
 633.343 +	                                SEARCH_EQ);
 633.344 +	if (searchType < 0 || searchType > 5)
 633.345 +		searchType = 0;
 633.346 +
 633.347 +	numberType = regQueryDwordValue("gbCheatsNumberType", 2);
 633.348 +	if (numberType < 0 || numberType > 2)
 633.349 +		numberType = 2;
 633.350 +
 633.351 +	sizeType = regQueryDwordValue("gbCheatsSizeType", 0);
 633.352 +	if (sizeType < 0 || sizeType > 2)
 633.353 +		sizeType = 0;
 633.354 +
 633.355 +	updateValues = regQueryDwordValue("gbCheatsUpdate", 0) ?
 633.356 +	               true : false;
 633.357 +
 633.358 +	UpdateData(FALSE);
 633.359 +
 633.360 +	if (valueType == 0)
 633.361 +		m_value.EnableWindow(FALSE);
 633.362 +
 633.363 +	CenterWindow();
 633.364 +
 633.365 +	if (theApp.modelessCheatDialogIsOpen)
 633.366 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->ShowWindow(TRUE);
 633.367 +
 633.368 +	if (cheatSearchData.count)
 633.369 +	{
 633.370 +		addChanges(false);
 633.371 +		if (theApp.modelessCheatDialogIsOpen)
 633.372 +			GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(cheatSearchGetCount(&cheatSearchData,
 633.373 +			                                                                     sizeType) == 0 ? FALSE : TRUE);
 633.374 +	}
 633.375 +	else
 633.376 +	{
 633.377 +		if (theApp.modelessCheatDialogIsOpen)
 633.378 +			GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(FALSE);
 633.379 +	}
 633.380 +
 633.381 +	return TRUE; // return TRUE unless you set the focus to a control
 633.382 +	             // EXCEPTION: OCX Property Pages should return FALSE
 633.383 +}
 633.384 +
 633.385 +void GBCheatSearch::OnGetdispinfoCheatList(NMHDR*pNMHDR, LRESULT*pResult)
 633.386 +{
 633.387 +	LV_DISPINFO*info = (LV_DISPINFO *)pNMHDR;
 633.388 +	if (info->item.mask & LVIF_TEXT)
 633.389 +	{
 633.390 +		int index = info->item.iItem;
 633.391 +		int col   = info->item.iSubItem;
 633.392 +
 633.393 +		switch (col)
 633.394 +		{
 633.395 +		case 0:
 633.396 +			strcpy(info->item.pszText, data[index].address);
 633.397 +			break;
 633.398 +		case 1:
 633.399 +			strcpy(info->item.pszText, data[index].oldValue);
 633.400 +			break;
 633.401 +		case 2:
 633.402 +			strcpy(info->item.pszText, data[index].newValue);
 633.403 +			break;
 633.404 +		}
 633.405 +	}
 633.406 +	*pResult = TRUE;
 633.407 +}
 633.408 +
 633.409 +void GBCheatSearch::OnItemchangedCheatList(NMHDR*pNMHDR, LRESULT*pResult)
 633.410 +{
 633.411 +	GetDlgItem(IDC_ADD_CHEAT)->EnableWindow(m_list.GetSelectionMark() != -1);
 633.412 +}
 633.413 +
 633.414 +int GBCheatSearch::getBank(u16 addr, int j)
 633.415 +{
 633.416 +	switch (addr >> 12)
 633.417 +	{
 633.418 +	case 0x0a:
 633.419 +		return j / 0x2000;
 633.420 +	case 0x0d:
 633.421 +		return j / 0x1000;
 633.422 +	}
 633.423 +	return 0;
 633.424 +}
 633.425 +
 633.426 +void GBCheatSearch::addChange(int index, int bank, u16 address, int offset, u32 oldValue, u32 newValue)
 633.427 +{
 633.428 +	data[index].bank = bank;
 633.429 +	if (bank)
 633.430 +	{
 633.431 +		if (address == 0xa000)
 633.432 +			address |= offset & 0x1fff;
 633.433 +		else
 633.434 +			address |= offset & 0xfff;
 633.435 +	}
 633.436 +	else
 633.437 +		address |= offset;
 633.438 +	data[index].addr = address;
 633.439 +	sprintf(data[index].address, "%02x:%04x", bank, address);
 633.440 +	switch (numberType)
 633.441 +	{
 633.442 +	case 0:
 633.443 +		sprintf(data[index].oldValue, "%d", oldValue);
 633.444 +		sprintf(data[index].newValue, "%d", newValue);
 633.445 +		break;
 633.446 +	case 1:
 633.447 +		sprintf(data[index].oldValue, "%u", oldValue);
 633.448 +		sprintf(data[index].newValue, "%u", newValue);
 633.449 +		break;
 633.450 +	case 2:
 633.451 +		switch (sizeType)
 633.452 +		{
 633.453 +		case 0:
 633.454 +			sprintf(data[index].oldValue, "%02x", oldValue);
 633.455 +			sprintf(data[index].newValue, "%02x", newValue);
 633.456 +			break;
 633.457 +		case 1:
 633.458 +			sprintf(data[index].oldValue, "%04x", oldValue);
 633.459 +			sprintf(data[index].newValue, "%04x", newValue);
 633.460 +			break;
 633.461 +		case 2:
 633.462 +			sprintf(data[index].oldValue, "%08x", oldValue);
 633.463 +			sprintf(data[index].newValue, "%08x", newValue);
 633.464 +			break;
 633.465 +		}
 633.466 +	}
 633.467 +}
 633.468 +
 633.469 +void GBCheatSearch::addChanges(bool showMsg)
 633.470 +{
 633.471 +	int count = cheatSearchGetCount(&cheatSearchData, sizeType);
 633.472 +
 633.473 +	m_list.DeleteAllItems();
 633.474 +
 633.475 +	if (count > 4000)
 633.476 +	{
 633.477 +		if (showMsg)
 633.478 +			systemMessage(
 633.479 +			    IDS_SEARCH_PRODUCED_TOO_MANY,
 633.480 +			    "Search produced %d results.\nThey have been remembered, but are too many to display.\nPlease refine it better by performing additional searches.",
 633.481 +			    count);
 633.482 +		return;
 633.483 +	}
 633.484 +
 633.485 +	if (count == 0)
 633.486 +	{
 633.487 +		if (showMsg)
 633.488 +			systemMessage(IDS_SEARCH_PRODUCED_NO_RESULTS, "Search produced no results");
 633.489 +		return;
 633.490 +	}
 633.491 +
 633.492 +	m_list.SetItemCount(count);
 633.493 +	if (data)
 633.494 +		free(data);
 633.495 +
 633.496 +	data = (WinGbCheatsData *)calloc(count, sizeof(WinGbCheatsData));
 633.497 +
 633.498 +	int inc = 1;
 633.499 +	switch (sizeType)
 633.500 +	{
 633.501 +	case 1:
 633.502 +		inc = 2;
 633.503 +		break;
 633.504 +	case 2:
 633.505 +		inc = 4;
 633.506 +		break;
 633.507 +	}
 633.508 +
 633.509 +	int index = 0;
 633.510 +	if (numberType == 0)
 633.511 +	{
 633.512 +		for (int i = 0; i < cheatSearchData.count; i++)
 633.513 +		{
 633.514 +			CheatSearchBlock *block = &cheatSearchData.blocks[i];
 633.515 +
 633.516 +			for (int j = 0; j < block->size; j += inc)
 633.517 +			{
 633.518 +				if (IS_BIT_SET(block->bits, j))
 633.519 +				{
 633.520 +					addChange(index++,
 633.521 +					          getBank(block->offset|j, j),
 633.522 +					          block->offset,
 633.523 +					          j,
 633.524 +					          cheatSearchSignedRead(block->saved,
 633.525 +					                                j,
 633.526 +					                                sizeType),
 633.527 +					          cheatSearchSignedRead(block->data,
 633.528 +					                                j,
 633.529 +					                                sizeType));
 633.530 +				}
 633.531 +			}
 633.532 +		}
 633.533 +	}
 633.534 +	else
 633.535 +	{
 633.536 +		for (int i = 0; i < cheatSearchData.count; i++)
 633.537 +		{
 633.538 +			CheatSearchBlock *block = &cheatSearchData.blocks[i];
 633.539 +
 633.540 +			for (int j = 0; j < block->size; j += inc)
 633.541 +			{
 633.542 +				if (IS_BIT_SET(block->bits, j))
 633.543 +				{
 633.544 +					addChange(index++,
 633.545 +					          getBank(block->offset|j, j),
 633.546 +					          block->offset,
 633.547 +					          j,
 633.548 +					          cheatSearchRead(block->saved,
 633.549 +					                          j,
 633.550 +					                          sizeType),
 633.551 +					          cheatSearchRead(block->data,
 633.552 +					                          j,
 633.553 +					                          sizeType));
 633.554 +				}
 633.555 +			}
 633.556 +		}
 633.557 +	}
 633.558 +
 633.559 +	for (int i = 0; i < count; i++)
 633.560 +	{
 633.561 +		LVITEM item;
 633.562 +
 633.563 +		item.mask     = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
 633.564 +		item.iItem    = i;
 633.565 +		item.iSubItem = 0;
 633.566 +		item.lParam   = data[i].addr|
 633.567 +		                (data[i].bank << 16);
 633.568 +		item.state     = 0;
 633.569 +		item.stateMask = 0;
 633.570 +		item.pszText   = LPSTR_TEXTCALLBACK;
 633.571 +		m_list.InsertItem(&item);
 633.572 +
 633.573 +		m_list.SetItemText(i, 1, LPSTR_TEXTCALLBACK);
 633.574 +		m_list.SetItemText(i, 2, LPSTR_TEXTCALLBACK);
 633.575 +	}
 633.576 +}
 633.577 +
 633.578 +void GBCheatSearch::OnValueType(UINT id)
 633.579 +{
 633.580 +	switch (id)
 633.581 +	{
 633.582 +	case IDC_OLD_VALUE:
 633.583 +		valueType = 0;
 633.584 +		m_value.EnableWindow(FALSE);
 633.585 +		regSetDwordValue("gbCheatsValueType", 0);
 633.586 +		break;
 633.587 +	case IDC_SPECIFIC_VALUE:
 633.588 +		valueType = 1;
 633.589 +		m_value.EnableWindow(TRUE);
 633.590 +		regSetDwordValue("gbCheatsValueType", 1);
 633.591 +		break;
 633.592 +	}
 633.593 +}
 633.594 +
 633.595 +void GBCheatSearch::OnSearchType(UINT id)
 633.596 +{
 633.597 +	switch (id)
 633.598 +	{
 633.599 +	case IDC_EQ:
 633.600 +		searchType = SEARCH_EQ;
 633.601 +		regSetDwordValue("gbCheatsSearchType", 0);
 633.602 +		break;
 633.603 +	case IDC_NE:
 633.604 +		searchType = SEARCH_NE;
 633.605 +		regSetDwordValue("gbCheatsSearchType", 1);
 633.606 +		break;
 633.607 +	case IDC_LT:
 633.608 +		searchType = SEARCH_LT;
 633.609 +		regSetDwordValue("gbCheatsSearchType", 2);
 633.610 +		break;
 633.611 +	case IDC_LE:
 633.612 +		searchType = SEARCH_LE;
 633.613 +		regSetDwordValue("gbCheatsSearchType", 3);
 633.614 +		break;
 633.615 +	case IDC_GT:
 633.616 +		searchType = SEARCH_GT;
 633.617 +		regSetDwordValue("gbCheatsSearchType", 4);
 633.618 +		break;
 633.619 +	case IDC_GE:
 633.620 +		searchType = SEARCH_GE;
 633.621 +		regSetDwordValue("gbCheatsSearchType", 5);
 633.622 +		break;
 633.623 +	}
 633.624 +}
 633.625 +
 633.626 +void GBCheatSearch::OnNumberType(UINT id)
 633.627 +{
 633.628 +	switch (id)
 633.629 +	{
 633.630 +	case IDC_SIGNED:
 633.631 +		numberType = 0;
 633.632 +		regSetDwordValue("gbCheatsNumberType", 0);
 633.633 +		if (m_list.GetItemCount())
 633.634 +		{
 633.635 +			addChanges(false);
 633.636 +		}
 633.637 +		break;
 633.638 +	case IDC_UNSIGNED:
 633.639 +		numberType = 1;
 633.640 +		regSetDwordValue("gbCheatsNumberType", 1);
 633.641 +		if (m_list.GetItemCount())
 633.642 +		{
 633.643 +			addChanges(false);
 633.644 +		}
 633.645 +		break;
 633.646 +	case IDC_HEXADECIMAL:
 633.647 +		numberType = 2;
 633.648 +		regSetDwordValue("gbCheatsNumberType", 2);
 633.649 +		if (m_list.GetItemCount())
 633.650 +		{
 633.651 +			addChanges(false);
 633.652 +		}
 633.653 +		break;
 633.654 +	}
 633.655 +}
 633.656 +
 633.657 +void GBCheatSearch::OnSizeType(UINT id)
 633.658 +{
 633.659 +	switch (id)
 633.660 +	{
 633.661 +	case IDC_SIZE_8:
 633.662 +		sizeType = BITS_8;
 633.663 +		regSetDwordValue("gbCheatsSizeType", 0);
 633.664 +		if (m_list.GetItemCount())
 633.665 +		{
 633.666 +			addChanges(false);
 633.667 +		}
 633.668 +		break;
 633.669 +	case IDC_SIZE_16:
 633.670 +		sizeType = BITS_16;
 633.671 +		regSetDwordValue("gbCheatsSizeType", 1);
 633.672 +		if (m_list.GetItemCount())
 633.673 +		{
 633.674 +			addChanges(false);
 633.675 +		}
 633.676 +		break;
 633.677 +	case IDC_SIZE_32:
 633.678 +		sizeType = BITS_32;
 633.679 +		regSetDwordValue("gbCheatsSizeType", 2);
 633.680 +		if (m_list.GetItemCount())
 633.681 +		{
 633.682 +			addChanges(false);
 633.683 +		}
 633.684 +		break;
 633.685 +	}
 633.686 +}
 633.687 +
 633.688 +/////////////////////////////////////////////////////////////////////////////
 633.689 +// AddGBCheat dialog
 633.690 +
 633.691 +AddGBCheat::AddGBCheat(u32 addr, CWnd*pParent /*=NULL*/)
 633.692 +	: CDialog(AddGBCheat::IDD, pParent)
 633.693 +{
 633.694 +	//{{AFX_DATA_INIT(AddGBCheat)
 633.695 +	numberType = regQueryDwordValue("gbCheatsNumberType", 2);
 633.696 +	if (numberType < 0 || numberType > 2)
 633.697 +		numberType = 2;
 633.698 +	sizeType = regQueryDwordValue("gbCheatsSizeType", 0);
 633.699 +	if (sizeType < 0 || sizeType > 2)
 633.700 +		sizeType = 0;
 633.701 +	//}}AFX_DATA_INIT
 633.702 +	address = addr;
 633.703 +}
 633.704 +
 633.705 +void AddGBCheat::DoDataExchange(CDataExchange*pDX)
 633.706 +{
 633.707 +	CDialog::DoDataExchange(pDX);
 633.708 +	//{{AFX_DATA_MAP(AddGBCheat)
 633.709 +	DDX_Control(pDX, IDC_VALUE, m_value);
 633.710 +	DDX_Control(pDX, IDC_ADDRESS, m_address);
 633.711 +	DDX_Control(pDX, IDC_DESC, m_desc);
 633.712 +	DDX_Radio(pDX, IDC_SIZE_8, sizeType);
 633.713 +	DDX_Radio(pDX, IDC_SIGNED, numberType);
 633.714 +	//}}AFX_DATA_MAP
 633.715 +}
 633.716 +
 633.717 +BEGIN_MESSAGE_MAP(AddGBCheat, CDialog)
 633.718 +//{{AFX_MSG_MAP(AddGBCheat)
 633.719 +ON_BN_CLICKED(ID_OK, OnOk)
 633.720 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
 633.721 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIGNED, IDC_HEXADECIMAL, OnNumberType)
 633.722 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIZE_8, IDC_SIZE_32, OnSizeType)
 633.723 +//}}AFX_MSG_MAP
 633.724 +END_MESSAGE_MAP()
 633.725 +
 633.726 +/////////////////////////////////////////////////////////////////////////////
 633.727 +// AddGBCheat message handlers
 633.728 +
 633.729 +void AddGBCheat::OnCancel()
 633.730 +{
 633.731 +	EndDialog(FALSE);
 633.732 +}
 633.733 +
 633.734 +void AddGBCheat::OnOk()
 633.735 +{
 633.736 +	// add cheat
 633.737 +	if (addCheat())
 633.738 +	{
 633.739 +		EndDialog(TRUE);
 633.740 +	}
 633.741 +}
 633.742 +
 633.743 +bool AddGBCheat::addCheat()
 633.744 +{
 633.745 +	CString buffer;
 633.746 +	CString code;
 633.747 +
 633.748 +	u32 value;
 633.749 +	m_value.GetWindowText(buffer);
 633.750 +
 633.751 +	if (buffer.IsEmpty())
 633.752 +	{
 633.753 +		systemMessage(IDS_VALUE_CANNOT_BE_EMPTY, "Value cannot be empty");
 633.754 +		return false;
 633.755 +	}
 633.756 +
 633.757 +	switch (numberType)
 633.758 +	{
 633.759 +	case 0:
 633.760 +		sscanf(buffer, "%d", &value);
 633.761 +		break;
 633.762 +	case 1:
 633.763 +		sscanf(buffer, "%u", &value);
 633.764 +		break;
 633.765 +	default:
 633.766 +		sscanf(buffer, "%x", &value);
 633.767 +	}
 633.768 +
 633.769 +	m_desc.GetWindowText(buffer);
 633.770 +
 633.771 +	int bank = (address >> 16);
 633.772 +	address &= 0xFFFF;
 633.773 +
 633.774 +	if (address >= 0xd000)
 633.775 +		bank += 0x90;
 633.776 +	else
 633.777 +		bank = 0x01;
 633.778 +
 633.779 +	switch (sizeType)
 633.780 +	{
 633.781 +	case 0:
 633.782 +		code.Format("%02X%02X%02X%02X", bank, value, address&0xFF, address>>8);
 633.783 +		gbAddGsCheat(code, buffer);
 633.784 +		break;
 633.785 +	case 1:
 633.786 +		code.Format("%02X%02X%02X%02X", bank, value&0xFF, address&0xFF,
 633.787 +		            address>>8);
 633.788 +		gbAddGsCheat(code, buffer);
 633.789 +		address++;
 633.790 +		code.Format("%02X%02X%02X%02X", bank, value>>8, address&0xFF,
 633.791 +		            address>>8);
 633.792 +		gbAddGsCheat(code, buffer);
 633.793 +		break;
 633.794 +	case 2:
 633.795 +		code.Format("%02X%02X%02X%02X", bank, value&0xFF, address&0xFF,
 633.796 +		            address>>8);
 633.797 +		gbAddGsCheat(code, buffer);
 633.798 +		address++;
 633.799 +		code.Format("%02X%02X%02X%02X", bank, (value>>8) & 0xFF, address&0xFF,
 633.800 +		            address>>8);
 633.801 +		gbAddGsCheat(code, buffer);
 633.802 +		address++;
 633.803 +		code.Format("%02X%02X%02X%02X", bank, (value>>16)&0xFF, address&0xFF,
 633.804 +		            address>>8);
 633.805 +		gbAddGsCheat(code, buffer);
 633.806 +		address++;
 633.807 +		code.Format("%02X%02X%02X%02X", bank, value>>24, address&0xFF,
 633.808 +		            address>>8);
 633.809 +		gbAddGsCheat(code, buffer);
 633.810 +		break;
 633.811 +	}
 633.812 +
 633.813 +	return true;
 633.814 +}
 633.815 +
 633.816 +BOOL AddGBCheat::OnInitDialog()
 633.817 +{
 633.818 +	CDialog::OnInitDialog();
 633.819 +
 633.820 +	CString buffer;
 633.821 +	buffer.Format("%02x:%08x", (address>>16), address&0xFFFF);
 633.822 +	m_address.SetWindowText(buffer);
 633.823 +	m_address.EnableWindow(FALSE);
 633.824 +	::SetWindowLong(m_address,
 633.825 +	                GWL_USERDATA,
 633.826 +	                address);
 633.827 +
 633.828 +	UpdateData(FALSE);
 633.829 +
 633.830 +	m_desc.LimitText(32);
 633.831 +
 633.832 +	if (address != 0)
 633.833 +	{
 633.834 +		GetDlgItem(IDC_SIZE_8)->EnableWindow(FALSE);
 633.835 +		GetDlgItem(IDC_SIZE_16)->EnableWindow(FALSE);
 633.836 +		GetDlgItem(IDC_SIZE_32)->EnableWindow(FALSE);
 633.837 +		GetDlgItem(IDC_HEXADECIMAL)->EnableWindow(FALSE);
 633.838 +		GetDlgItem(IDC_UNSIGNED)->EnableWindow(FALSE);
 633.839 +		GetDlgItem(IDC_SIGNED)->EnableWindow(FALSE);
 633.840 +	}
 633.841 +	CenterWindow();
 633.842 +
 633.843 +	return TRUE; // return TRUE unless you set the focus to a control
 633.844 +	             // EXCEPTION: OCX Property Pages should return FALSE
 633.845 +}
 633.846 +
 633.847 +void AddGBCheat::OnNumberType(UINT id)
 633.848 +{
 633.849 +	switch (id)
 633.850 +	{
 633.851 +	case IDC_SIGNED:
 633.852 +		numberType = 0;
 633.853 +		regSetDwordValue("gbCheatsNumberType", 0);
 633.854 +		break;
 633.855 +	case IDC_UNSIGNED:
 633.856 +		numberType = 1;
 633.857 +		regSetDwordValue("gbCheatsNumberType", 1);
 633.858 +		break;
 633.859 +	case IDC_HEXADECIMAL:
 633.860 +		numberType = 2;
 633.861 +		regSetDwordValue("gbCheatsNumberType", 2);
 633.862 +		break;
 633.863 +	}
 633.864 +}
 633.865 +
 633.866 +void AddGBCheat::OnSizeType(UINT id)
 633.867 +{
 633.868 +	switch (id)
 633.869 +	{
 633.870 +	case IDC_SIZE_8:
 633.871 +		sizeType = BITS_8;
 633.872 +		regSetDwordValue("gbCheatsSizeType", 0);
 633.873 +		break;
 633.874 +	case IDC_SIZE_16:
 633.875 +		sizeType = BITS_16;
 633.876 +		regSetDwordValue("gbCheatsSizeType", 1);
 633.877 +		break;
 633.878 +	case IDC_SIZE_32:
 633.879 +		sizeType = BITS_32;
 633.880 +		regSetDwordValue("gbCheatsSizeType", 2);
 633.881 +		break;
 633.882 +	}
 633.883 +}
 633.884 +
 633.885 +/////////////////////////////////////////////////////////////////////////////
 633.886 +// GBCheatList dialog
 633.887 +
 633.888 +GBCheatList::GBCheatList(CWnd*pParent /*=NULL*/)
 633.889 +	: CDialog(GBCheatList::IDD, pParent)
 633.890 +{
 633.891 +	//{{AFX_DATA_INIT(GBCheatList)
 633.892 +	// NOTE: the ClassWizard will add member initialization here
 633.893 +	//}}AFX_DATA_INIT
 633.894 +	duringRefresh = false;
 633.895 +}
 633.896 +
 633.897 +void GBCheatList::DoDataExchange(CDataExchange*pDX)
 633.898 +{
 633.899 +	CDialog::DoDataExchange(pDX);
 633.900 +	//{{AFX_DATA_MAP(GBCheatList)
 633.901 +	DDX_Control(pDX, IDC_CHEAT_LIST, m_list);
 633.902 +	//}}AFX_DATA_MAP
 633.903 +}
 633.904 +
 633.905 +BEGIN_MESSAGE_MAP(GBCheatList, CDialog)
 633.906 +//{{AFX_MSG_MAP(GBCheatList)
 633.907 +ON_BN_CLICKED(ID_OK, OnOk)
 633.908 +ON_BN_CLICKED(IDC_ADD_GG_CHEAT, OnAddGgCheat)
 633.909 +ON_BN_CLICKED(IDC_ADD_GS_CHEAT, OnAddGsCheat)
 633.910 +ON_BN_CLICKED(IDC_ENABLE, OnEnable)
 633.911 +ON_BN_CLICKED(IDC_REMOVE, OnRemove)
 633.912 +ON_BN_CLICKED(IDC_REMOVE_ALL, OnRemoveAll)
 633.913 +ON_NOTIFY(LVN_ITEMCHANGED, IDC_CHEAT_LIST, OnItemchangedCheatList)
 633.914 +//}}AFX_MSG_MAP
 633.915 +END_MESSAGE_MAP()
 633.916 +
 633.917 +/////////////////////////////////////////////////////////////////////////////
 633.918 +// GBCheatList message handlers
 633.919 +
 633.920 +void GBCheatList::OnOk()
 633.921 +{
 633.922 +	EndDialog(TRUE);
 633.923 +}
 633.924 +
 633.925 +void GBCheatList::OnAddGgCheat()
 633.926 +{
 633.927 +	CString   temp = winResLoadString(IDS_ADD_GG_CODE);
 633.928 +	AddGBCode dlg(winGbCheatAddVerifyGg, 11, temp);
 633.929 +	dlg.DoModal();
 633.930 +	refresh();
 633.931 +}
 633.932 +
 633.933 +void GBCheatList::OnAddGsCheat()
 633.934 +{
 633.935 +	CString temp = winResLoadString(IDS_ADD_GS_CODE);
 633.936 +
 633.937 +	AddGBCode dlg(winGbCheatAddVerifyGs, 8, temp);
 633.938 +	dlg.DoModal();
 633.939 +	refresh();
 633.940 +}
 633.941 +
 633.942 +void GBCheatList::OnEnable()
 633.943 +{
 633.944 +	int mark = m_list.GetSelectionMark();
 633.945 +
 633.946 +	if (mark != -1)
 633.947 +	{
 633.948 +		LVITEM item;
 633.949 +		memset(&item, 0, sizeof(item));
 633.950 +		item.mask  = LVIF_PARAM;
 633.951 +		item.iItem = mark;
 633.952 +		if (m_list.GetItem(&item))
 633.953 +		{
 633.954 +			if (gbCheatList[item.lParam].enabled)
 633.955 +				gbCheatDisable(item.lParam);
 633.956 +			else
 633.957 +				gbCheatEnable(item.lParam);
 633.958 +			refresh();
 633.959 +		}
 633.960 +	}
 633.961 +}
 633.962 +
 633.963 +void GBCheatList::OnRemove()
 633.964 +{
 633.965 +	int mark = m_list.GetSelectionMark();
 633.966 +
 633.967 +	if (mark != -1)
 633.968 +	{
 633.969 +		LVITEM item;
 633.970 +		memset(&item, 0, sizeof(item));
 633.971 +		item.mask  = LVIF_PARAM;
 633.972 +		item.iItem = mark;
 633.973 +		if (m_list.GetItem(&item))
 633.974 +		{
 633.975 +			gbCheatRemove(item.lParam);
 633.976 +			refresh();
 633.977 +		}
 633.978 +	}
 633.979 +}
 633.980 +
 633.981 +void GBCheatList::OnRemoveAll()
 633.982 +{
 633.983 +	gbCheatRemoveAll();
 633.984 +	refresh();
 633.985 +}
 633.986 +
 633.987 +void GBCheatList::OnItemchangedCheatList(NMHDR*pNMHDR, LRESULT*pResult)
 633.988 +{
 633.989 +	if (m_list.GetSelectionMark() != -1)
 633.990 +	{
 633.991 +		GetDlgItem(IDC_REMOVE)->EnableWindow(TRUE);
 633.992 +		GetDlgItem(IDC_ENABLE)->EnableWindow(TRUE);
 633.993 +	}
 633.994 +	else
 633.995 +	{
 633.996 +		GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
 633.997 +		GetDlgItem(IDC_ENABLE)->EnableWindow(FALSE);
 633.998 +	}
 633.999 +
633.1000 +	if (!duringRefresh)
633.1001 +	{
633.1002 +		LPNMLISTVIEW l = (LPNMLISTVIEW)pNMHDR;
633.1003 +		if (l->uChanged & LVIF_STATE)
633.1004 +		{
633.1005 +			if (((l->uOldState & LVIS_STATEIMAGEMASK)>>12) !=
633.1006 +			    (((l->uNewState & LVIS_STATEIMAGEMASK)>>12)))
633.1007 +			{
633.1008 +				if (m_list.GetCheck(l->iItem))
633.1009 +					gbCheatEnable(l->lParam);
633.1010 +				else
633.1011 +					gbCheatDisable(l->lParam);
633.1012 +				refresh();
633.1013 +			}
633.1014 +		}
633.1015 +	}
633.1016 +}
633.1017 +
633.1018 +BOOL GBCheatList::OnInitDialog()
633.1019 +{
633.1020 +	CDialog::OnInitDialog();
633.1021 +
633.1022 +	CString temp = winResLoadString(IDS_CODE);
633.1023 +	m_list.InsertColumn(0, temp, LVCFMT_LEFT, 120, 0);
633.1024 +	temp = winResLoadString(IDS_DESCRIPTION);
633.1025 +	m_list.InsertColumn(1, temp, LVCFMT_LEFT, 200, 1);
633.1026 +	temp = winResLoadString(IDS_STATUS);
633.1027 +	m_list.InsertColumn(2, temp, LVCFMT_LEFT, 80, 2);
633.1028 +
633.1029 +	m_list.SetFont(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)),
633.1030 +	               TRUE);
633.1031 +
633.1032 +	m_list.SetExtendedStyle(LVS_EX_CHECKBOXES |
633.1033 +	                        LVS_EX_FULLROWSELECT);
633.1034 +
633.1035 +	refresh();
633.1036 +	GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
633.1037 +	GetDlgItem(IDC_ENABLE)->EnableWindow(FALSE);
633.1038 +	CenterWindow();
633.1039 +
633.1040 +	return TRUE; // return TRUE unless you set the focus to a control
633.1041 +	             // EXCEPTION: OCX Property Pages should return FALSE
633.1042 +}
633.1043 +
633.1044 +void GBCheatList::refresh()
633.1045 +{
633.1046 +	duringRefresh = true;
633.1047 +
633.1048 +	m_list.DeleteAllItems();
633.1049 +
633.1050 +	char buffer[2];
633.1051 +
633.1052 +	for (int i = 0; i < gbCheatNumber; i++)
633.1053 +	{
633.1054 +		LVITEM item;
633.1055 +
633.1056 +		item.mask      = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
633.1057 +		item.iItem     = i;
633.1058 +		item.iSubItem  = 0;
633.1059 +		item.lParam    = i;
633.1060 +		item.state     = 0;
633.1061 +		item.stateMask = 0;
633.1062 +		item.pszText   = gbCheatList[i].cheatCode;
633.1063 +		m_list.InsertItem(&item);
633.1064 +
633.1065 +		m_list.SetCheck(i, (gbCheatList[i].enabled ? TRUE : FALSE));
633.1066 +
633.1067 +		m_list.SetItemText(i, 1, gbCheatList[i].cheatDesc);
633.1068 +
633.1069 +		buffer[0] = (gbCheatList[i].enabled) ? 'E' : 'D';
633.1070 +		buffer[1] = 0;
633.1071 +		m_list.SetItemText(i, 2, buffer);
633.1072 +	}
633.1073 +	duringRefresh = false;
633.1074 +}
633.1075 +
633.1076 +/////////////////////////////////////////////////////////////////////////////
633.1077 +// AddGBCode dialog
633.1078 +
633.1079 +AddGBCode::AddGBCode(bool(*verify)(const char *, const char *), int len, const char *title, CWnd*pParent /*=NULL*/)
633.1080 +	: CDialog(AddGBCode::IDD, pParent)
633.1081 +{
633.1082 +	//{{AFX_DATA_INIT(AddGBCode)
633.1083 +	// NOTE: the ClassWizard will add member initialization here
633.1084 +	//}}AFX_DATA_INIT
633.1085 +	addVerify = verify;
633.1086 +	addLength = len;
633.1087 +	addTitle  = title;
633.1088 +}
633.1089 +
633.1090 +void AddGBCode::DoDataExchange(CDataExchange*pDX)
633.1091 +{
633.1092 +	CDialog::DoDataExchange(pDX);
633.1093 +	//{{AFX_DATA_MAP(AddGBCode)
633.1094 +	DDX_Control(pDX, IDC_DESC, m_desc);
633.1095 +	DDX_Control(pDX, IDC_CODE, m_code);
633.1096 +	//}}AFX_DATA_MAP
633.1097 +}
633.1098 +
633.1099 +BEGIN_MESSAGE_MAP(AddGBCode, CDialog)
633.1100 +//{{AFX_MSG_MAP(AddGBCode)
633.1101 +ON_BN_CLICKED(ID_OK, OnOk)
633.1102 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
633.1103 +//}}AFX_MSG_MAP
633.1104 +END_MESSAGE_MAP()
633.1105 +
633.1106 +/////////////////////////////////////////////////////////////////////////////
633.1107 +// AddGBCode message handlers
633.1108 +
633.1109 +void AddGBCode::OnOk()
633.1110 +{
633.1111 +	CString desc;
633.1112 +	CString buffer;
633.1113 +	m_code.GetWindowText(buffer);
633.1114 +	m_desc.GetWindowText(desc);
633.1115 +
633.1116 +	StringTokenizer st(buffer, " \t\n\r");
633.1117 +	const char *    t = st.next();
633.1118 +	while (t)
633.1119 +	{
633.1120 +		addVerify(t, desc);
633.1121 +		t = st.next();
633.1122 +	}
633.1123 +	EndDialog(TRUE);
633.1124 +}
633.1125 +
633.1126 +void AddGBCode::OnCancel()
633.1127 +{
633.1128 +	EndDialog(FALSE);
633.1129 +}
633.1130 +
633.1131 +BOOL AddGBCode::OnInitDialog()
633.1132 +{
633.1133 +	CDialog::OnInitDialog();
633.1134 +
633.1135 +	m_code.LimitText(1024);
633.1136 +	m_desc.LimitText(32);
633.1137 +	SetWindowText(addTitle);
633.1138 +	CenterWindow();
633.1139 +
633.1140 +	return TRUE; // return TRUE unless you set the focus to a control
633.1141 +	             // EXCEPTION: OCX Property Pages should return FALSE
633.1142 +}
633.1143 +
   634.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   634.2 +++ b/src/win32/GBCheatsDlg.h	Sat Mar 03 10:31:27 2012 -0600
   634.3 @@ -0,0 +1,198 @@
   634.4 +#if !defined(AFX_GBCHEATSDLG_H__8ECCB04A_AB75_4552_8625_C6FBF30A95D9__INCLUDED_)
   634.5 +#define AFX_GBCHEATSDLG_H__8ECCB04A_AB75_4552_8625_C6FBF30A95D9__INCLUDED_
   634.6 +
   634.7 +#if _MSC_VER > 1000
   634.8 +#pragma once
   634.9 +#endif // _MSC_VER > 1000
  634.10 +// GBCheats.h : header file
  634.11 +//
  634.12 +
  634.13 +/////////////////////////////////////////////////////////////////////////////
  634.14 +// GBCheatSearch dialog
  634.15 +
  634.16 +struct WinGbCheatsData
  634.17 +{
  634.18 +	int  bank;
  634.19 +	u16  addr;
  634.20 +	char address[9];
  634.21 +	char oldValue[12];
  634.22 +	char newValue[12];
  634.23 +};
  634.24 +
  634.25 +class GBCheatSearch : public CDialog
  634.26 +{
  634.27 +	// Construction
  634.28 +public:
  634.29 +	afx_msg void OnSizeType(UINT id);
  634.30 +	afx_msg void OnNumberType(UINT id);
  634.31 +	afx_msg void OnSearchType(UINT id);
  634.32 +	afx_msg void OnValueType(UINT id);
  634.33 +	void addChanges(bool showMsg);
  634.34 +	void addChange(int index, int bank, u16 address, int offset, u32 oldValue, u32 newValue);
  634.35 +	int getBank(u16 addr, int j);
  634.36 +	GBCheatSearch(CWnd*pParent = NULL);  // standard constructor
  634.37 +	~GBCheatSearch();
  634.38 +
  634.39 +	// Dialog Data
  634.40 +	//{{AFX_DATA(GBCheatSearch)
  634.41 +	enum { IDD = IDD_CHEATS };
  634.42 +	CEdit     m_value;
  634.43 +	CListCtrl m_list;
  634.44 +	int       searchType;
  634.45 +	int       numberType;
  634.46 +	int       sizeType;
  634.47 +	BOOL      updateValues;
  634.48 +	int       valueType;
  634.49 +	//}}AFX_DATA
  634.50 +
  634.51 +	// Overrides
  634.52 +	// ClassWizard generated virtual function overrides
  634.53 +	//{{AFX_VIRTUAL(GBCheatSearch)
  634.54 +protected:
  634.55 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  634.56 +	//}}AFX_VIRTUAL
  634.57 +
  634.58 +	// Implementation
  634.59 +protected:
  634.60 +	WinGbCheatsData *data;
  634.61 +
  634.62 +	// Generated message map functions
  634.63 +	//{{AFX_MSG(GBCheatSearch)
  634.64 +	afx_msg void OnOk();
  634.65 +	afx_msg void OnAddCheat();
  634.66 +	afx_msg void OnSearch();
  634.67 +	afx_msg void OnStart();
  634.68 +	afx_msg void OnUpdate();
  634.69 +	virtual BOOL OnInitDialog();
  634.70 +	afx_msg void OnGetdispinfoCheatList(NMHDR*pNMHDR, LRESULT*pResult);
  634.71 +	afx_msg void OnItemchangedCheatList(NMHDR*pNMHDR, LRESULT*pResult);
  634.72 +	//}}AFX_MSG
  634.73 +	DECLARE_MESSAGE_MAP()
  634.74 +public:
  634.75 +	afx_msg void OnClose();
  634.76 +	afx_msg void OnBnClickedCheatrefreshbutton();
  634.77 +};
  634.78 +
  634.79 +/////////////////////////////////////////////////////////////////////////////
  634.80 +// AddGBCheat dialog
  634.81 +
  634.82 +class AddGBCheat : public CDialog
  634.83 +{
  634.84 +	// Construction
  634.85 +public:
  634.86 +	afx_msg void OnSizeType(UINT id);
  634.87 +	afx_msg void OnNumberType(UINT id);
  634.88 +	bool addCheat();
  634.89 +	AddGBCheat(u32 addr, CWnd*pParent = NULL);  // standard constructor
  634.90 +
  634.91 +	// Dialog Data
  634.92 +	//{{AFX_DATA(AddGBCheat)
  634.93 +	enum { IDD = IDD_ADD_CHEAT };
  634.94 +	CEdit m_value;
  634.95 +	CEdit m_address;
  634.96 +	CEdit m_desc;
  634.97 +	int   sizeType;
  634.98 +	int   numberType;
  634.99 +	//}}AFX_DATA
 634.100 +
 634.101 +	// Overrides
 634.102 +	// ClassWizard generated virtual function overrides
 634.103 +	//{{AFX_VIRTUAL(AddGBCheat)
 634.104 +protected:
 634.105 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
 634.106 +	//}}AFX_VIRTUAL
 634.107 +
 634.108 +	// Implementation
 634.109 +protected:
 634.110 +	u32 address;
 634.111 +
 634.112 +	// Generated message map functions
 634.113 +	//{{AFX_MSG(AddGBCheat)
 634.114 +	afx_msg void OnCancel();
 634.115 +	afx_msg void OnOk();
 634.116 +	virtual BOOL OnInitDialog();
 634.117 +	//}}AFX_MSG
 634.118 +	DECLARE_MESSAGE_MAP()
 634.119 +};
 634.120 +/////////////////////////////////////////////////////////////////////////////
 634.121 +// GBCheatList dialog
 634.122 +
 634.123 +class GBCheatList : public CDialog
 634.124 +{
 634.125 +	// Construction
 634.126 +public:
 634.127 +	void refresh();
 634.128 +	GBCheatList(CWnd*pParent = NULL);  // standard constructor
 634.129 +
 634.130 +	// Dialog Data
 634.131 +	//{{AFX_DATA(GBCheatList)
 634.132 +	enum { IDD = IDD_GB_CHEAT_LIST };
 634.133 +	CListCtrl m_list;
 634.134 +	//}}AFX_DATA
 634.135 +
 634.136 +	// Overrides
 634.137 +	// ClassWizard generated virtual function overrides
 634.138 +	//{{AFX_VIRTUAL(GBCheatList)
 634.139 +protected:
 634.140 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
 634.141 +	//}}AFX_VIRTUAL
 634.142 +
 634.143 +	// Implementation
 634.144 +protected:
 634.145 +	bool duringRefresh;
 634.146 +
 634.147 +	// Generated message map functions
 634.148 +	//{{AFX_MSG(GBCheatList)
 634.149 +	afx_msg void OnOk();
 634.150 +	afx_msg void OnAddGgCheat();
 634.151 +	afx_msg void OnAddGsCheat();
 634.152 +	afx_msg void OnEnable();
 634.153 +	afx_msg void OnRemove();
 634.154 +	afx_msg void OnRemoveAll();
 634.155 +	afx_msg void OnItemchangedCheatList(NMHDR*pNMHDR, LRESULT*pResult);
 634.156 +	virtual BOOL OnInitDialog();
 634.157 +	//}}AFX_MSG
 634.158 +	DECLARE_MESSAGE_MAP()
 634.159 +};
 634.160 +
 634.161 +/////////////////////////////////////////////////////////////////////////////
 634.162 +// AddGBCode dialog
 634.163 +
 634.164 +class AddGBCode : public CDialog
 634.165 +{
 634.166 +	// Construction
 634.167 +public:
 634.168 +	AddGBCode(bool(*verify)(const char *, const char *), int, const char *, CWnd*pParent = NULL);  // standard constructor
 634.169 +
 634.170 +	// Dialog Data
 634.171 +	//{{AFX_DATA(AddGBCode)
 634.172 +	enum { IDD = IDD_ADD_CHEAT_DLG };
 634.173 +	CEdit m_desc;
 634.174 +	CEdit m_code;
 634.175 +	//}}AFX_DATA
 634.176 +
 634.177 +	// Overrides
 634.178 +	// ClassWizard generated virtual function overrides
 634.179 +	//{{AFX_VIRTUAL(AddGBCode)
 634.180 +protected:
 634.181 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
 634.182 +	//}}AFX_VIRTUAL
 634.183 +
 634.184 +	// Implementation
 634.185 +protected:
 634.186 +	int     addLength;
 634.187 +	CString addTitle;
 634.188 +	bool    (*addVerify)(const char *, const char *);
 634.189 +
 634.190 +	// Generated message map functions
 634.191 +	//{{AFX_MSG(AddGBCode)
 634.192 +	afx_msg void OnOk();
 634.193 +	afx_msg void OnCancel();
 634.194 +	virtual BOOL OnInitDialog();
 634.195 +	//}}AFX_MSG
 634.196 +	DECLARE_MESSAGE_MAP()
 634.197 +};
 634.198 +//{{AFX_INSERT_LOCATION}}
 634.199 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
 634.200 +
 634.201 +#endif // !defined(AFX_GBCHEATSDLG_H__8ECCB04A_AB75_4552_8625_C6FBF30A95D9__INCLUDED_)
   635.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   635.2 +++ b/src/win32/GBColorDlg.cpp	Sat Mar 03 10:31:27 2012 -0600
   635.3 @@ -0,0 +1,238 @@
   635.4 +// GBColorDlg.cpp : implementation file
   635.5 +//
   635.6 +
   635.7 +#include "stdafx.h"
   635.8 +#include "resource.h"
   635.9 +#include "GBColorDlg.h"
  635.10 +#include "Reg.h"
  635.11 +
  635.12 +extern int32 gbPaletteOption;
  635.13 +extern int   emulating;
  635.14 +extern int   systemCartridgeType;
  635.15 +extern u16   gbPalette[128];
  635.16 +extern u16   systemGbPalette[24];
  635.17 +
  635.18 +static u16 defaultPalettes[][24] = {
  635.19 +	{
  635.20 +		0x7FFF, 0x56B5, 0x318C, 0x0000,  0x7FFF, 0x56B5, 0x318C, 0x0000,
  635.21 +	},
  635.22 +	{
  635.23 +		0x6200, 0x7E10, 0x7C10, 0x5000,  0x6200, 0x7E10, 0x7C10, 0x5000,
  635.24 +	},
  635.25 +	{
  635.26 +		0x4008, 0x4000, 0x2000, 0x2008,  0x4008, 0x4000, 0x2000, 0x2008,
  635.27 +	},
  635.28 +	{
  635.29 +		0x43F0, 0x03E0, 0x4200, 0x2200,  0x43F0, 0x03E0, 0x4200, 0x2200,
  635.30 +	},
  635.31 +	{
  635.32 +		0x43FF, 0x03FF, 0x221F, 0x021F,  0x43FF, 0x03FF, 0x221F, 0x021F,
  635.33 +	},
  635.34 +	{
  635.35 +		0x621F, 0x7E1F, 0x7C1F, 0x2010,  0x621F, 0x7E1F, 0x7C1F, 0x2010,
  635.36 +	},
  635.37 +	{
  635.38 +		0x621F, 0x401F, 0x001F, 0x2010,  0x621F, 0x401F, 0x001F, 0x2010,
  635.39 +	},
  635.40 +	{
  635.41 +		0x1314, 0x0E91, 0x0E0D, 0x2108,  0x1314, 0x0E91, 0x0E0D, 0x2108,
  635.42 +	}
  635.43 +};
  635.44 +
  635.45 +/////////////////////////////////////////////////////////////////////////////
  635.46 +// GBColorDlg dialog
  635.47 +
  635.48 +GBColorDlg::GBColorDlg(CWnd*pParent /*=NULL*/)
  635.49 +	: CDialog(GBColorDlg::IDD, pParent)
  635.50 +{
  635.51 +	//{{AFX_DATA_INIT(GBColorDlg)
  635.52 +	which = -1;
  635.53 +	//}}AFX_DATA_INIT
  635.54 +	which = gbPaletteOption;
  635.55 +}
  635.56 +
  635.57 +void GBColorDlg::DoDataExchange(CDataExchange*pDX)
  635.58 +{
  635.59 +	CDialog::DoDataExchange(pDX);
  635.60 +	//{{AFX_DATA_MAP(GBColorDlg)
  635.61 +	DDX_Control(pDX, IDC_PREDEFINED, m_predefined);
  635.62 +	DDX_Radio(pDX, IDC_DEFAULT, which);
  635.63 +	//}}AFX_DATA_MAP
  635.64 +}
  635.65 +
  635.66 +BEGIN_MESSAGE_MAP(GBColorDlg, CDialog)
  635.67 +//{{AFX_MSG_MAP(GBColorDlg)
  635.68 +ON_BN_CLICKED(IDC_DEFAULT, OnDefault)
  635.69 +ON_BN_CLICKED(IDC_RESET, OnReset)
  635.70 +ON_BN_CLICKED(IDC_USER1, OnUser1)
  635.71 +ON_BN_CLICKED(IDC_USER2, OnUser2)
  635.72 +ON_BN_CLICKED(ID_OK, OnOk)
  635.73 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
  635.74 +ON_CBN_SELCHANGE(IDC_PREDEFINED, OnSelchangePredefined)
  635.75 +//}}AFX_MSG_MAP
  635.76 +ON_CONTROL_RANGE(BN_CLICKED, IDC_COLOR_BG0, IDC_COLOR_OB3, OnColorClicked)
  635.77 +END_MESSAGE_MAP()
  635.78 +
  635.79 +/////////////////////////////////////////////////////////////////////////////
  635.80 +// GBColorDlg message handlers
  635.81 +
  635.82 +void GBColorDlg::OnDefault()
  635.83 +{
  635.84 +	setWhich(0);
  635.85 +}
  635.86 +
  635.87 +void GBColorDlg::OnReset()
  635.88 +{
  635.89 +	int s = which * 8;
  635.90 +	colors[s++] = (0x1f) | (0x1f << 5) | (0x1f << 10);
  635.91 +	colors[s++] = (0x15) | (0x15 << 5) | (0x15 << 10);
  635.92 +	colors[s++] = (0x0c) | (0x0c << 5) | (0x0c << 10);
  635.93 +	colors[s++] = 0;
  635.94 +
  635.95 +	colors[s++] = (0x1f) | (0x1f << 5) | (0x1f << 10);
  635.96 +	colors[s++] = (0x15) | (0x15 << 5) | (0x15 << 10);
  635.97 +	colors[s++] = (0x0c) | (0x0c << 5) | (0x0c << 10);
  635.98 +	colors[s]   = 0;
  635.99 +	setWhich(which);
 635.100 +}
 635.101 +
 635.102 +void GBColorDlg::OnUser1()
 635.103 +{
 635.104 +	setWhich(1);
 635.105 +}
 635.106 +
 635.107 +void GBColorDlg::OnUser2()
 635.108 +{
 635.109 +	setWhich(2);
 635.110 +}
 635.111 +
 635.112 +void GBColorDlg::OnCancel()
 635.113 +{
 635.114 +	EndDialog(FALSE);
 635.115 +}
 635.116 +
 635.117 +void GBColorDlg::OnOk()
 635.118 +{
 635.119 +	EndDialog(TRUE);
 635.120 +}
 635.121 +
 635.122 +BOOL GBColorDlg::OnInitDialog()
 635.123 +{
 635.124 +	CDialog::OnInitDialog();
 635.125 +
 635.126 +	colorControls[0].SubclassDlgItem(IDC_COLOR_BG0, this);
 635.127 +	colorControls[1].SubclassDlgItem(IDC_COLOR_BG1, this);
 635.128 +	colorControls[2].SubclassDlgItem(IDC_COLOR_BG2, this);
 635.129 +	colorControls[3].SubclassDlgItem(IDC_COLOR_BG3, this);
 635.130 +	colorControls[4].SubclassDlgItem(IDC_COLOR_OB0, this);
 635.131 +	colorControls[5].SubclassDlgItem(IDC_COLOR_OB1, this);
 635.132 +	colorControls[6].SubclassDlgItem(IDC_COLOR_OB2, this);
 635.133 +	colorControls[7].SubclassDlgItem(IDC_COLOR_OB3, this);
 635.134 +
 635.135 +	for (int i = 0; i < 24; i++)
 635.136 +	{
 635.137 +		colors[i] = systemGbPalette[i];
 635.138 +	}
 635.139 +
 635.140 +	const char *names[] = {
 635.141 +		"Standard",
 635.142 +		"Blue Sea",
 635.143 +		"Dark Night",
 635.144 +		"Green Forest",
 635.145 +		"Hot Desert",
 635.146 +		"Pink Dreams",
 635.147 +		"Weird Colors",
 635.148 +		"Real Colors"
 635.149 +	};
 635.150 +
 635.151 +	for (int j = 0; j < 8; j++)
 635.152 +	{
 635.153 +		int index = m_predefined.AddString(names[j]);
 635.154 +		m_predefined.SetItemData(index, j);
 635.155 +	}
 635.156 +
 635.157 +	RECT cbSize;
 635.158 +	int  Height;
 635.159 +
 635.160 +	m_predefined.GetClientRect(&cbSize);
 635.161 +	Height  = m_predefined.GetItemHeight(0);
 635.162 +	Height += m_predefined.GetItemHeight(0) * (10);
 635.163 +
 635.164 +	// Note: The use of SM_CYEDGE assumes that we're using Windows '95
 635.165 +	// Now add on the height of the border of the edit box
 635.166 +	Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges
 635.167 +
 635.168 +	// The height of the border of the drop-down box
 635.169 +	Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges
 635.170 +
 635.171 +	// now set the size of the window
 635.172 +	m_predefined.SetWindowPos(NULL,
 635.173 +	                          0, 0,
 635.174 +	                          cbSize.right, Height,
 635.175 +	                          SWP_NOMOVE | SWP_NOZORDER);
 635.176 +
 635.177 +	setWhich(which);
 635.178 +
 635.179 +	CenterWindow();
 635.180 +
 635.181 +	return TRUE; // return TRUE unless you set the focus to a control
 635.182 +	             // EXCEPTION: OCX Property Pages should return FALSE
 635.183 +}
 635.184 +
 635.185 +void GBColorDlg::setWhich(int w)
 635.186 +{
 635.187 +	which = w;
 635.188 +
 635.189 +	for (int i = 0; i < 8; i++)
 635.190 +	{
 635.191 +		colorControls[i].setColor(colors[which*8+i]);
 635.192 +	}
 635.193 +}
 635.194 +
 635.195 +u16 *GBColorDlg::getColors()
 635.196 +{
 635.197 +	return colors;
 635.198 +}
 635.199 +
 635.200 +void GBColorDlg::OnColorClicked(UINT id)
 635.201 +{
 635.202 +	id -= IDC_COLOR_BG0;
 635.203 +
 635.204 +	u16 color = colors[which*8+id];
 635.205 +
 635.206 +	COLORREF colorInit =
 635.207 +	    RGB((color & 0x1f) << 3, ((color >> 5) & 0x1f) << 3, ((color >> 10) & 0x1f) << 3);
 635.208 +
 635.209 +	CColorDialog dlg(colorInit,
 635.210 +	                 CC_FULLOPEN | CC_ANYCOLOR, this);
 635.211 +
 635.212 +	if (IDOK == dlg.DoModal())
 635.213 +	{
 635.214 +		COLORREF c = dlg.GetColor();
 635.215 +
 635.216 +		colors[which*8+id] = (u16)((c >> 3) & 0x1f | ((c >> 11) & 0x1f) << 5 |
 635.217 +		                           ((c >> 19) & 0x1f) << 10);
 635.218 +		colorControls[id].setColor(colors[which*8+id]);
 635.219 +	}
 635.220 +}
 635.221 +
 635.222 +int GBColorDlg::getWhich()
 635.223 +{
 635.224 +	return which;
 635.225 +}
 635.226 +
 635.227 +void GBColorDlg::OnSelchangePredefined()
 635.228 +{
 635.229 +	int sel = m_predefined.GetCurSel();
 635.230 +
 635.231 +	if (sel != -1)
 635.232 +	{
 635.233 +		int data = m_predefined.GetItemData(sel);
 635.234 +		for (int i = 0; i < 8; i++)
 635.235 +		{
 635.236 +			colorControls[i].setColor(defaultPalettes[data][i]);
 635.237 +			colors[which*8+i] = defaultPalettes[data][i];
 635.238 +		}
 635.239 +	}
 635.240 +}
 635.241 +
   636.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   636.2 +++ b/src/win32/GBColorDlg.h	Sat Mar 03 10:31:27 2012 -0600
   636.3 @@ -0,0 +1,60 @@
   636.4 +#if !defined(AFX_GBCOLORDLG_H__8D6126EF_06BB_48CF_ABB3_2CC4B1B60358__INCLUDED_)
   636.5 +#define AFX_GBCOLORDLG_H__8D6126EF_06BB_48CF_ABB3_2CC4B1B60358__INCLUDED_
   636.6 +
   636.7 +#if _MSC_VER > 1000
   636.8 +#pragma once
   636.9 +#endif // _MSC_VER > 1000
  636.10 +// GBColorDlg.h : header file
  636.11 +//
  636.12 +
  636.13 +#include "ColorButton.h"  // Added by ClassView
  636.14 +
  636.15 +/////////////////////////////////////////////////////////////////////////////
  636.16 +// GBColorDlg dialog
  636.17 +
  636.18 +class GBColorDlg : public CDialog
  636.19 +{
  636.20 +	// Construction
  636.21 +public:
  636.22 +	int getWhich();
  636.23 +	afx_msg void OnColorClicked(UINT id);
  636.24 +	u16 *getColors();
  636.25 +	void setWhich(int w);
  636.26 +	u16         colors[24];
  636.27 +	ColorButton colorControls[8];
  636.28 +	GBColorDlg(CWnd*pParent = NULL);  // standard constructor
  636.29 +
  636.30 +	// Dialog Data
  636.31 +	//{{AFX_DATA(GBColorDlg)
  636.32 +	enum { IDD = IDD_GB_COLORS };
  636.33 +	CComboBox m_predefined;
  636.34 +	int       which;
  636.35 +	//}}AFX_DATA
  636.36 +
  636.37 +	// Overrides
  636.38 +	// ClassWizard generated virtual function overrides
  636.39 +	//{{AFX_VIRTUAL(GBColorDlg)
  636.40 +protected:
  636.41 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  636.42 +	//}}AFX_VIRTUAL
  636.43 +
  636.44 +	// Implementation
  636.45 +protected:
  636.46 +	// Generated message map functions
  636.47 +	//{{AFX_MSG(GBColorDlg)
  636.48 +	afx_msg void OnDefault();
  636.49 +	afx_msg void OnReset();
  636.50 +	afx_msg void OnUser1();
  636.51 +	afx_msg void OnUser2();
  636.52 +	afx_msg void OnCancel();
  636.53 +	afx_msg void OnOk();
  636.54 +	virtual BOOL OnInitDialog();
  636.55 +	afx_msg void OnSelchangePredefined();
  636.56 +	//}}AFX_MSG
  636.57 +	DECLARE_MESSAGE_MAP()
  636.58 +};
  636.59 +
  636.60 +//{{AFX_INSERT_LOCATION}}
  636.61 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  636.62 +
  636.63 +#endif // !defined(AFX_GBCOLORDLG_H__8D6126EF_06BB_48CF_ABB3_2CC4B1B60358__INCLUDED_)
   637.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   637.2 +++ b/src/win32/GBDisassemble.cpp	Sat Mar 03 10:31:27 2012 -0600
   637.3 @@ -0,0 +1,241 @@
   637.4 +// GBDisassemble.cpp : implementation file
   637.5 +//
   637.6 +
   637.7 +#include "stdafx.h"
   637.8 +#include "resource.h"
   637.9 +#include "GBDisassemble.h"
  637.10 +#include "VBA.h"
  637.11 +
  637.12 +#include "../gb/GB.h"
  637.13 +#include "../gb/gbGlobals.h"
  637.14 +
  637.15 +extern gbRegister AF;
  637.16 +extern gbRegister BC;
  637.17 +extern gbRegister DE;
  637.18 +extern gbRegister HL;
  637.19 +extern gbRegister SP;
  637.20 +extern gbRegister PC;
  637.21 +extern u16        IFF;
  637.22 +extern int        gbDis(char *, u16);
  637.23 +
  637.24 +/////////////////////////////////////////////////////////////////////////////
  637.25 +// GBDisassemble dialog
  637.26 +
  637.27 +GBDisassemble::GBDisassemble(CWnd*pParent /*=NULL*/)
  637.28 +	: ResizeDlg(GBDisassemble::IDD, pParent)
  637.29 +{
  637.30 +	//{{AFX_DATA_INIT(GBDisassemble)
  637.31 +	m_c = FALSE;
  637.32 +	m_h = FALSE;
  637.33 +	m_n = FALSE;
  637.34 +	m_z = FALSE;
  637.35 +	//}}AFX_DATA_INIT
  637.36 +	address     = 0;
  637.37 +	autoUpdate  = false;
  637.38 +	count       = 1;
  637.39 +	lastAddress = 0;
  637.40 +}
  637.41 +
  637.42 +void GBDisassemble::DoDataExchange(CDataExchange*pDX)
  637.43 +{
  637.44 +	CDialog::DoDataExchange(pDX);
  637.45 +	//{{AFX_DATA_MAP(GBDisassemble)
  637.46 +	DDX_Control(pDX, IDC_ADDRESS, m_address);
  637.47 +	DDX_Control(pDX, IDC_DISASSEMBLE, m_list);
  637.48 +	DDX_Check(pDX, IDC_C, m_c);
  637.49 +	DDX_Check(pDX, IDC_H, m_h);
  637.50 +	DDX_Check(pDX, IDC_N, m_n);
  637.51 +	DDX_Check(pDX, IDC_Z, m_z);
  637.52 +	//}}AFX_DATA_MAP
  637.53 +}
  637.54 +
  637.55 +BEGIN_MESSAGE_MAP(GBDisassemble, CDialog)
  637.56 +//{{AFX_MSG_MAP(GBDisassemble)
  637.57 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
  637.58 +ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
  637.59 +ON_BN_CLICKED(IDC_NEXT, OnNext)
  637.60 +ON_BN_CLICKED(IDC_GO, OnGo)
  637.61 +ON_BN_CLICKED(IDC_GOPC, OnGopc)
  637.62 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
  637.63 +ON_WM_VSCROLL()
  637.64 +//}}AFX_MSG_MAP
  637.65 +END_MESSAGE_MAP()
  637.66 +
  637.67 +/////////////////////////////////////////////////////////////////////////////
  637.68 +// GBDisassemble message handlers
  637.69 +
  637.70 +void GBDisassemble::OnClose()
  637.71 +{
  637.72 +	theApp.winRemoveUpdateListener(this);
  637.73 +
  637.74 +	DestroyWindow();
  637.75 +}
  637.76 +
  637.77 +void GBDisassemble::OnRefresh()
  637.78 +{
  637.79 +	refresh();
  637.80 +}
  637.81 +
  637.82 +void GBDisassemble::OnNext()
  637.83 +{
  637.84 +	gbEmulate(1);
  637.85 +	if (PC.W < address || PC.W >= lastAddress)
  637.86 +		OnGopc();
  637.87 +	refresh();
  637.88 +}
  637.89 +
  637.90 +void GBDisassemble::OnGo()
  637.91 +{
  637.92 +	CString buffer;
  637.93 +	m_address.GetWindowText(buffer);
  637.94 +	sscanf(buffer, "%x", &address);
  637.95 +	refresh();
  637.96 +}
  637.97 +
  637.98 +void GBDisassemble::OnGopc()
  637.99 +{
 637.100 +	address = PC.W;
 637.101 +
 637.102 +	refresh();
 637.103 +}
 637.104 +
 637.105 +void GBDisassemble::OnAutoUpdate()
 637.106 +{
 637.107 +	autoUpdate = !autoUpdate;
 637.108 +	if (autoUpdate)
 637.109 +	{
 637.110 +		theApp.winAddUpdateListener(this);
 637.111 +	}
 637.112 +	else
 637.113 +	{
 637.114 +		theApp.winRemoveUpdateListener(this);
 637.115 +	}
 637.116 +}
 637.117 +
 637.118 +BOOL GBDisassemble::OnInitDialog()
 637.119 +{
 637.120 +	CDialog::OnInitDialog();
 637.121 +
 637.122 +	DIALOG_SIZER_START(sz)
 637.123 +	DIALOG_SIZER_ENTRY(IDC_DISASSEMBLE, DS_SizeY)
 637.124 +	DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
 637.125 +	DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
 637.126 +	DIALOG_SIZER_ENTRY(IDC_NEXT,  DS_MoveY)
 637.127 +	DIALOG_SIZER_ENTRY(IDC_AUTO_UPDATE, DS_MoveY)
 637.128 +	DIALOG_SIZER_ENTRY(IDC_GOPC, DS_MoveY)
 637.129 +	DIALOG_SIZER_ENTRY(IDC_VSCROLL, DS_SizeY)
 637.130 +	DIALOG_SIZER_END()
 637.131 +	SetData(sz,
 637.132 +	        TRUE,
 637.133 +	        HKEY_CURRENT_USER,
 637.134 +	        "Software\\Emulators\\VisualBoyAdvance\\Viewer\\GBDisassembleView",
 637.135 +	        NULL);
 637.136 +
 637.137 +	SCROLLINFO si;
 637.138 +	ZeroMemory(&si, sizeof(si));
 637.139 +	si.cbSize = sizeof(si);
 637.140 +	si.fMask  = SIF_PAGE | SIF_RANGE | SIF_POS;
 637.141 +	si.nMin   = 0;
 637.142 +	si.nMax   = 100;
 637.143 +	si.nPos   = 50;
 637.144 +	si.nPage  = 0;
 637.145 +	GetDlgItem(IDC_VSCROLL)->SetScrollInfo(SB_CTL, &si, TRUE);
 637.146 +	CFont *font = CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT));
 637.147 +	m_list.SetFont(font);
 637.148 +
 637.149 +	for (int i = 0; i < 7; i++)
 637.150 +		GetDlgItem(IDC_R0+i)->SetFont(font);
 637.151 +
 637.152 +	m_address.LimitText(4);
 637.153 +	refresh();
 637.154 +
 637.155 +	return TRUE; // return TRUE unless you set the focus to a control
 637.156 +	             // EXCEPTION: OCX Property Pages should return FALSE
 637.157 +}
 637.158 +
 637.159 +void GBDisassemble::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar)
 637.160 +{
 637.161 +	char buffer[80];
 637.162 +
 637.163 +	switch (nSBCode)
 637.164 +	{
 637.165 +	case SB_LINEDOWN:
 637.166 +		address += gbDis(buffer, address);
 637.167 +		break;
 637.168 +	case SB_LINEUP:
 637.169 +		address--;
 637.170 +		break;
 637.171 +	case SB_PAGEDOWN:
 637.172 +		address = lastAddress;
 637.173 +		break;
 637.174 +	case SB_PAGEUP:
 637.175 +		address -= count;
 637.176 +		break;
 637.177 +	}
 637.178 +	refresh();
 637.179 +
 637.180 +	CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
 637.181 +}
 637.182 +
 637.183 +void GBDisassemble::refresh()
 637.184 +{
 637.185 +	if (gbRom == NULL)
 637.186 +		return;
 637.187 +
 637.188 +	int  h = m_list.GetItemHeight(0);
 637.189 +	RECT r;
 637.190 +	m_list.GetClientRect(&r);
 637.191 +	count = (r.bottom - r.top+1)/h;
 637.192 +
 637.193 +	m_list.ResetContent();
 637.194 +	if (!systemIsEmulating() || systemCartridgeType != 1)
 637.195 +		return;
 637.196 +
 637.197 +	char buffer[80];
 637.198 +	u16  addr = address;
 637.199 +	int  i;
 637.200 +	int  sel = -1;
 637.201 +	for (i = 0; i < count; i++)
 637.202 +	{
 637.203 +		if (addr == PC.W)
 637.204 +			sel = i;
 637.205 +		addr += gbDis(buffer, addr);
 637.206 +		m_list.InsertString(-1, buffer);
 637.207 +	}
 637.208 +	lastAddress = addr-1;
 637.209 +	if (sel != -1)
 637.210 +		m_list.SetCurSel(sel);
 637.211 +
 637.212 +	sprintf(buffer, "%04x", AF.W);
 637.213 +	GetDlgItem(IDC_R0)->SetWindowText(buffer);
 637.214 +	sprintf(buffer, "%04x", BC.W);
 637.215 +	GetDlgItem(IDC_R1)->SetWindowText(buffer);
 637.216 +	sprintf(buffer, "%04x", DE.W);
 637.217 +	GetDlgItem(IDC_R2)->SetWindowText(buffer);
 637.218 +	sprintf(buffer, "%04x", HL.W);
 637.219 +	GetDlgItem(IDC_R3)->SetWindowText(buffer);
 637.220 +	sprintf(buffer, "%04x", SP.W);
 637.221 +	GetDlgItem(IDC_R4)->SetWindowText(buffer);
 637.222 +	sprintf(buffer, "%04x", PC.W);
 637.223 +	GetDlgItem(IDC_R5)->SetWindowText(buffer);
 637.224 +	sprintf(buffer, "%04x", IFF);
 637.225 +	GetDlgItem(IDC_R6)->SetWindowText(buffer);
 637.226 +
 637.227 +	m_z = (AF.B.B0 & 0x80) != 0;
 637.228 +	m_n = (AF.B.B0 & 0x40) != 0;
 637.229 +	m_h = (AF.B.B0 & 0x20) != 0;
 637.230 +	m_c = (AF.B.B0 & 0x10) != 0;
 637.231 +	UpdateData(FALSE);
 637.232 +}
 637.233 +
 637.234 +void GBDisassemble::update()
 637.235 +{
 637.236 +	OnGopc();
 637.237 +	refresh();
 637.238 +}
 637.239 +
 637.240 +void GBDisassemble::PostNcDestroy()
 637.241 +{
 637.242 +	delete this;
 637.243 +}
 637.244 +
   638.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   638.2 +++ b/src/win32/GBDisassemble.h	Sat Mar 03 10:31:27 2012 -0600
   638.3 @@ -0,0 +1,69 @@
   638.4 +#if !defined(AFX_GBDISASSEMBLE_H__3EFD5B47_6DBF_4F63_8F91_A9511EC590EB__INCLUDED_)
   638.5 +#define AFX_GBDISASSEMBLE_H__3EFD5B47_6DBF_4F63_8F91_A9511EC590EB__INCLUDED_
   638.6 +
   638.7 +#if _MSC_VER > 1000
   638.8 +#pragma once
   638.9 +#endif // _MSC_VER > 1000
  638.10 +// -*- C++ -*-
  638.11 +// GBDisassemble.h : header file
  638.12 +//
  638.13 +
  638.14 +#include "IUpdate.h"
  638.15 +#include "ResizeDlg.h"
  638.16 +
  638.17 +/////////////////////////////////////////////////////////////////////////////
  638.18 +// GBDisassemble dialog
  638.19 +
  638.20 +class GBDisassemble : public ResizeDlg, IUpdateListener
  638.21 +{
  638.22 +	// Construction
  638.23 +public:
  638.24 +	//bool autoUpdate;	// If these two variables are defined here, the dialog will crash!
  638.25 +	//u16  address;		// There might be a bug within MFC.
  638.26 +	virtual void update();
  638.27 +	void refresh();
  638.28 +	GBDisassemble(CWnd*pParent = NULL);  // standard constructor
  638.29 +
  638.30 +	// Dialog Data
  638.31 +	//{{AFX_DATA(GBDisassemble)
  638.32 +	enum { IDD = IDD_GB_DISASSEMBLE };
  638.33 +	CEdit    m_address;
  638.34 +	CListBox m_list;
  638.35 +	BOOL     m_c;
  638.36 +	BOOL     m_h;
  638.37 +	BOOL     m_n;
  638.38 +	BOOL     m_z;
  638.39 +	//}}AFX_DATA
  638.40 +	bool autoUpdate;
  638.41 +	int  count;
  638.42 +	u16  address;
  638.43 +	u16  lastAddress;
  638.44 +
  638.45 +	// Overrides
  638.46 +	// ClassWizard generated virtual function overrides
  638.47 +	//{{AFX_VIRTUAL(GBDisassemble)
  638.48 +protected:
  638.49 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  638.50 +	virtual void PostNcDestroy();
  638.51 +	//}}AFX_VIRTUAL
  638.52 +
  638.53 +	// Implementation
  638.54 +protected:
  638.55 +	// Generated message map functions
  638.56 +	//{{AFX_MSG(GBDisassemble)
  638.57 +	afx_msg void OnClose();
  638.58 +	afx_msg void OnRefresh();
  638.59 +	afx_msg void OnNext();
  638.60 +	afx_msg void OnGo();
  638.61 +	afx_msg void OnGopc();
  638.62 +	afx_msg void OnAutoUpdate();
  638.63 +	virtual BOOL OnInitDialog();
  638.64 +	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar);
  638.65 +	//}}AFX_MSG
  638.66 +	DECLARE_MESSAGE_MAP()
  638.67 +};
  638.68 +
  638.69 +//{{AFX_INSERT_LOCATION}}
  638.70 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  638.71 +
  638.72 +#endif // !defined(AFX_GBDISASSEMBLE_H__3EFD5B47_6DBF_4F63_8F91_A9511EC590EB__INCLUDED_)
   639.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   639.2 +++ b/src/win32/GBMapView.cpp	Sat Mar 03 10:31:27 2012 -0600
   639.3 @@ -0,0 +1,589 @@
   639.4 +// GBMapView.cpp : implementation file
   639.5 +//
   639.6 +
   639.7 +#include "stdafx.h"
   639.8 +#include "resource.h"
   639.9 +#include "GBMapView.h"
  639.10 +#include "FileDlg.h"
  639.11 +#include "Reg.h"
  639.12 +#include "WinResUtil.h"
  639.13 +#include "VBA.h"
  639.14 +
  639.15 +//#include "../common/System.h"
  639.16 +#include "../gb/gbGlobals.h"
  639.17 +#include "../NLS.h"
  639.18 +#include "../common/Util.h"
  639.19 +
  639.20 +extern "C" {
  639.21 +#include <png.h>
  639.22 +}
  639.23 +
  639.24 +extern u8 gbInvertTab[256];
  639.25 +
  639.26 +/////////////////////////////////////////////////////////////////////////////
  639.27 +// GBMapView dialog
  639.28 +
  639.29 +GBMapView::GBMapView(CWnd*pParent /*=NULL*/)
  639.30 +	: ResizeDlg(GBMapView::IDD, pParent)
  639.31 +{
  639.32 +	//{{AFX_DATA_INIT(GBMapView)
  639.33 +	// NOTE: the ClassWizard will add member initialization here
  639.34 +	//}}AFX_DATA_INIT
  639.35 +	autoUpdate = false;
  639.36 +
  639.37 +	memset(&bmpInfo.bmiHeader, 0, sizeof(bmpInfo.bmiHeader));
  639.38 +
  639.39 +	bmpInfo.bmiHeader.biSize        = sizeof(bmpInfo.bmiHeader);
  639.40 +	bmpInfo.bmiHeader.biWidth       = 1024;
  639.41 +	bmpInfo.bmiHeader.biHeight      = -1024;
  639.42 +	bmpInfo.bmiHeader.biPlanes      = 1;
  639.43 +	bmpInfo.bmiHeader.biBitCount    = 24;
  639.44 +	bmpInfo.bmiHeader.biCompression = BI_RGB;
  639.45 +	data = (u8 *)calloc(1, 3 * 1024 * 1024);
  639.46 +
  639.47 +	mapView.setData(data);
  639.48 +	mapView.setBmpInfo(&bmpInfo);
  639.49 +
  639.50 +	bg   = 0;
  639.51 +	bank = 0;
  639.52 +}
  639.53 +
  639.54 +void GBMapView::DoDataExchange(CDataExchange*pDX)
  639.55 +{
  639.56 +	CDialog::DoDataExchange(pDX);
  639.57 +	//{{AFX_DATA_MAP(GBMapView)
  639.58 +	// NOTE: the ClassWizard will add DDX and DDV calls here
  639.59 +	//}}AFX_DATA_MAP
  639.60 +	DDX_Control(pDX, IDC_MAP_VIEW, mapView);
  639.61 +	DDX_Control(pDX, IDC_MAP_VIEW_ZOOM, mapViewZoom);
  639.62 +	DDX_Control(pDX, IDC_COLOR, color);
  639.63 +}
  639.64 +
  639.65 +BEGIN_MESSAGE_MAP(GBMapView, CDialog)
  639.66 +//{{AFX_MSG_MAP(GBMapView)
  639.67 +ON_BN_CLICKED(IDC_SAVE, OnSave)
  639.68 +ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
  639.69 +ON_BN_CLICKED(IDC_BG0, OnBg0)
  639.70 +ON_BN_CLICKED(IDC_BG1, OnBg1)
  639.71 +ON_BN_CLICKED(IDC_BANK_0, OnBank0)
  639.72 +ON_BN_CLICKED(IDC_BANK_1, OnBank1)
  639.73 +ON_BN_CLICKED(IDC_STRETCH, OnStretch)
  639.74 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
  639.75 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
  639.76 +//}}AFX_MSG_MAP
  639.77 +ON_MESSAGE(WM_MAPINFO, OnMapInfo)
  639.78 +ON_MESSAGE(WM_COLINFO, OnColInfo)
  639.79 +END_MESSAGE_MAP()
  639.80 +
  639.81 +/////////////////////////////////////////////////////////////////////////////
  639.82 +// GBMapView message handlers
  639.83 +
  639.84 +GBMapView::~GBMapView()
  639.85 +{
  639.86 +	free(data);
  639.87 +	data = NULL;
  639.88 +}
  639.89 +
  639.90 +void GBMapView::saveBMP(const char *name)
  639.91 +{
  639.92 +	u8 writeBuffer[1024 * 3];
  639.93 +
  639.94 +	FILE *fp = fopen(name, "wb");
  639.95 +
  639.96 +	if (!fp)
  639.97 +	{
  639.98 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
  639.99 +		return;
 639.100 +	}
 639.101 +
 639.102 +	struct
 639.103 +	{
 639.104 +		u8 ident[2];
 639.105 +		u8 filesize[4];
 639.106 +		u8 reserved[4];
 639.107 +		u8 dataoffset[4];
 639.108 +		u8 headersize[4];
 639.109 +		u8 width[4];
 639.110 +		u8 height[4];
 639.111 +		u8 planes[2];
 639.112 +		u8 bitsperpixel[2];
 639.113 +		u8 compression[4];
 639.114 +		u8 datasize[4];
 639.115 +		u8 hres[4];
 639.116 +		u8 vres[4];
 639.117 +		u8 colors[4];
 639.118 +		u8 importantcolors[4];
 639.119 +		u8 pad[2];
 639.120 +	} bmpheader;
 639.121 +	memset(&bmpheader, 0, sizeof(bmpheader));
 639.122 +
 639.123 +	bmpheader.ident[0] = 'B';
 639.124 +	bmpheader.ident[1] = 'M';
 639.125 +
 639.126 +	u32 fsz = sizeof(bmpheader) + w*h*3;
 639.127 +	utilPutDword(bmpheader.filesize, fsz);
 639.128 +	utilPutDword(bmpheader.dataoffset, 0x38);
 639.129 +	utilPutDword(bmpheader.headersize, 0x28);
 639.130 +	utilPutDword(bmpheader.width, w);
 639.131 +	utilPutDword(bmpheader.height, h);
 639.132 +	utilPutDword(bmpheader.planes, 1);
 639.133 +	utilPutDword(bmpheader.bitsperpixel, 24);
 639.134 +	utilPutDword(bmpheader.datasize, 3*w*h);
 639.135 +
 639.136 +	fwrite(&bmpheader, 1, sizeof(bmpheader), fp);
 639.137 +
 639.138 +	u8 *b = writeBuffer;
 639.139 +
 639.140 +	int sizeX = w;
 639.141 +	int sizeY = h;
 639.142 +
 639.143 +	u8 *pixU8 = (u8 *)data+3*w*(h-1);
 639.144 +	for (int y = 0; y < sizeY; y++)
 639.145 +	{
 639.146 +		for (int x = 0; x < sizeX; x++)
 639.147 +		{
 639.148 +			*b++ = *pixU8++; // B
 639.149 +			*b++ = *pixU8++; // G
 639.150 +			*b++ = *pixU8++; // R
 639.151 +		}
 639.152 +		pixU8 -= 2*3*w;
 639.153 +		fwrite(writeBuffer, 1, 3*w, fp);
 639.154 +
 639.155 +		b = writeBuffer;
 639.156 +	}
 639.157 +
 639.158 +	fclose(fp);
 639.159 +}
 639.160 +
 639.161 +void GBMapView::savePNG(const char *name)
 639.162 +{
 639.163 +	u8 writeBuffer[1024 * 3];
 639.164 +
 639.165 +	FILE *fp = fopen(name, "wb");
 639.166 +
 639.167 +	if (!fp)
 639.168 +	{
 639.169 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
 639.170 +		return;
 639.171 +	}
 639.172 +
 639.173 +	png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
 639.174 +	                                              NULL,
 639.175 +	                                              NULL,
 639.176 +	                                              NULL);
 639.177 +	if (!png_ptr)
 639.178 +	{
 639.179 +		fclose(fp);
 639.180 +		return;
 639.181 +	}
 639.182 +
 639.183 +	png_infop info_ptr = png_create_info_struct(png_ptr);
 639.184 +
 639.185 +	if (!info_ptr)
 639.186 +	{
 639.187 +		png_destroy_write_struct(&png_ptr, NULL);
 639.188 +		fclose(fp);
 639.189 +		return;
 639.190 +	}
 639.191 +
 639.192 +	if (setjmp(png_ptr->jmpbuf))
 639.193 +	{
 639.194 +		png_destroy_write_struct(&png_ptr, NULL);
 639.195 +		fclose(fp);
 639.196 +		return;
 639.197 +	}
 639.198 +
 639.199 +	png_init_io(png_ptr, fp);
 639.200 +
 639.201 +	png_set_IHDR(png_ptr,
 639.202 +	             info_ptr,
 639.203 +	             w,
 639.204 +	             h,
 639.205 +	             8,
 639.206 +	             PNG_COLOR_TYPE_RGB,
 639.207 +	             PNG_INTERLACE_NONE,
 639.208 +	             PNG_COMPRESSION_TYPE_DEFAULT,
 639.209 +	             PNG_FILTER_TYPE_DEFAULT);
 639.210 +
 639.211 +	png_write_info(png_ptr, info_ptr);
 639.212 +
 639.213 +	u8 *b = writeBuffer;
 639.214 +
 639.215 +	int sizeX = w;
 639.216 +	int sizeY = h;
 639.217 +
 639.218 +	u8 *pixU8 = (u8 *)data;
 639.219 +	for (int y = 0; y < sizeY; y++)
 639.220 +	{
 639.221 +		for (int x = 0; x < sizeX; x++)
 639.222 +		{
 639.223 +			int blue  = *pixU8++;
 639.224 +			int green = *pixU8++;
 639.225 +			int red   = *pixU8++;
 639.226 +
 639.227 +			*b++ = red;
 639.228 +			*b++ = green;
 639.229 +			*b++ = blue;
 639.230 +		}
 639.231 +		png_write_row(png_ptr, writeBuffer);
 639.232 +
 639.233 +		b = writeBuffer;
 639.234 +	}
 639.235 +
 639.236 +	png_write_end(png_ptr, info_ptr);
 639.237 +
 639.238 +	png_destroy_write_struct(&png_ptr, &info_ptr);
 639.239 +
 639.240 +	fclose(fp);
 639.241 +}
 639.242 +
 639.243 +void GBMapView::OnSave()
 639.244 +{
 639.245 +	CString filename;
 639.246 +
 639.247 +	if (theApp.captureFormat == 0)
 639.248 +		filename = "map.png";
 639.249 +	else
 639.250 +		filename = "map.bmp";
 639.251 +
 639.252 +	LPCTSTR exts[] = {".png", ".bmp", NULL };
 639.253 +	CString filter = winResLoadFilter(IDS_FILTER_PNG);
 639.254 +	CString title  = winResLoadString(IDS_SELECT_CAPTURE_NAME);
 639.255 +
 639.256 +	FileDlg dlg(this,
 639.257 +	            filename,
 639.258 +	            filter,
 639.259 +	            theApp.captureFormat ? 2 : 1,
 639.260 +	            theApp.captureFormat ? "BMP" : "PNG",
 639.261 +	            exts,
 639.262 +	            "",
 639.263 +	            title,
 639.264 +	            true);
 639.265 +
 639.266 +	if (dlg.DoModal() == IDCANCEL)
 639.267 +	{
 639.268 +		return;
 639.269 +	}
 639.270 +
 639.271 +	if (dlg.getFilterIndex() == 2)
 639.272 +		saveBMP(dlg.GetPathName());
 639.273 +	else
 639.274 +		savePNG(dlg.GetPathName());
 639.275 +}
 639.276 +
 639.277 +void GBMapView::render()
 639.278 +{
 639.279 +	u8 *bank0;
 639.280 +	u8 *bank1;
 639.281 +	if (gbCgbMode)
 639.282 +	{
 639.283 +		bank0 = &gbVram[0x0000];
 639.284 +		bank1 = &gbVram[0x2000];
 639.285 +	}
 639.286 +	else
 639.287 +	{
 639.288 +		bank0 = &gbMemory[0x8000];
 639.289 +		bank1 = NULL;
 639.290 +	}
 639.291 +
 639.292 +	int tile_map_address = 0x1800;
 639.293 +	if (bg == 1)
 639.294 +		tile_map_address = 0x1c00;
 639.295 +
 639.296 +	int tile_pattern = 0x0000;
 639.297 +	if (bank == 1)
 639.298 +		tile_pattern = 0x0800;
 639.299 +
 639.300 +	w = 256;
 639.301 +	h = 256;
 639.302 +
 639.303 +	int tile = 0;
 639.304 +	for (int y = 0; y < 32; y++)
 639.305 +	{
 639.306 +		for (int x = 0; x < 32; x++)
 639.307 +		{
 639.308 +			u8 *bmp   = &data[y * 8 * 32 * 24 + x*24];
 639.309 +			u8  attrs = 0;
 639.310 +			if (bank1 != NULL)
 639.311 +				attrs = bank1[tile_map_address];
 639.312 +			u8 tile = bank0[tile_map_address];
 639.313 +			tile_map_address++;
 639.314 +
 639.315 +			if (bank == 1)
 639.316 +			{
 639.317 +				if (tile < 128)
 639.318 +					tile += 128;
 639.319 +				else
 639.320 +					tile -= 128;
 639.321 +			}
 639.322 +			for (int j = 0; j < 8; j++)
 639.323 +			{
 639.324 +				int tile_pattern_address = attrs & 0x40 ?
 639.325 +				                           tile_pattern + tile*16 + (7-j)*2 :
 639.326 +				                           tile_pattern + tile*16+j*2;
 639.327 +
 639.328 +				u8 tile_a = 0;
 639.329 +				u8 tile_b = 0;
 639.330 +
 639.331 +				if (attrs & 0x08)
 639.332 +				{
 639.333 +					tile_a = bank1[tile_pattern_address++];
 639.334 +					tile_b = bank1[tile_pattern_address];
 639.335 +				}
 639.336 +				else
 639.337 +				{
 639.338 +					tile_a = bank0[tile_pattern_address++];
 639.339 +					tile_b = bank0[tile_pattern_address];
 639.340 +				}
 639.341 +
 639.342 +				if (attrs & 0x20)
 639.343 +				{
 639.344 +					tile_a = gbInvertTab[tile_a];
 639.345 +					tile_b = gbInvertTab[tile_b];
 639.346 +				}
 639.347 +
 639.348 +				u8 mask = 0x80;
 639.349 +
 639.350 +				while (mask > 0)
 639.351 +				{
 639.352 +					u8 c = (tile_a & mask) ? 1 : 0;
 639.353 +					c += (tile_b & mask) ? 2 : 0;
 639.354 +
 639.355 +					if (gbCgbMode)
 639.356 +						c = c + (attrs & 7)*4;
 639.357 +
 639.358 +					u16 color = gbPalette[c];
 639.359 +
 639.360 +					*bmp++ = ((color >> 10) & 0x1f) << 3;
 639.361 +					*bmp++ = ((color >> 5) & 0x1f) << 3;
 639.362 +					*bmp++ = (color & 0x1f) << 3;
 639.363 +
 639.364 +					mask >>= 1;
 639.365 +				}
 639.366 +				bmp += 31*24;
 639.367 +			}
 639.368 +		}
 639.369 +	}
 639.370 +}
 639.371 +
 639.372 +void GBMapView::paint()
 639.373 +{
 639.374 +	if (gbRom == NULL)
 639.375 +		return;
 639.376 +	render();
 639.377 +
 639.378 +	SIZE s;
 639.379 +	if (mapView.getStretch())
 639.380 +	{
 639.381 +		mapView.setSize(w, h);
 639.382 +		s.cx = s.cy = 1;
 639.383 +		mapView.SetScrollSizes(MM_TEXT, s);
 639.384 +	}
 639.385 +	else
 639.386 +	{
 639.387 +		mapView.setSize(w, h);
 639.388 +		s.cx = w;
 639.389 +		s.cy = h;
 639.390 +		mapView.SetScrollSizes(MM_TEXT, s);
 639.391 +	}
 639.392 +
 639.393 +	mapView.refresh();
 639.394 +}
 639.395 +
 639.396 +void GBMapView::OnRefresh()
 639.397 +{
 639.398 +	paint();
 639.399 +}
 639.400 +
 639.401 +void GBMapView::update()
 639.402 +{
 639.403 +	paint();
 639.404 +}
 639.405 +
 639.406 +BOOL GBMapView::OnInitDialog()
 639.407 +{
 639.408 +	CDialog::OnInitDialog();
 639.409 +
 639.410 +	DIALOG_SIZER_START(sz)
 639.411 +	DIALOG_SIZER_ENTRY(IDC_MAP_VIEW, DS_SizeX | DS_SizeY)
 639.412 +	DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
 639.413 +	DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
 639.414 +	DIALOG_SIZER_ENTRY(IDC_SAVE,  DS_MoveY)
 639.415 +	DIALOG_SIZER_ENTRY(IDC_COLOR, DS_MoveY)
 639.416 +	DIALOG_SIZER_ENTRY(IDC_R, DS_MoveY)
 639.417 +	DIALOG_SIZER_ENTRY(IDC_G, DS_MoveY)
 639.418 +	DIALOG_SIZER_ENTRY(IDC_B, DS_MoveY)
 639.419 +	DIALOG_SIZER_END()
 639.420 +	SetData(sz,
 639.421 +	        TRUE,
 639.422 +	        HKEY_CURRENT_USER,
 639.423 +	        "Software\\Emulators\\VisualBoyAdvance\\Viewer\\GBMapView",
 639.424 +	        NULL);
 639.425 +
 639.426 +	int s = regQueryDwordValue("mapViewStretch", 0);
 639.427 +	if (s)
 639.428 +		mapView.setStretch(true);
 639.429 +	((CButton *)GetDlgItem(IDC_STRETCH))->SetCheck(s);
 639.430 +
 639.431 +	UINT id = IDC_BANK_0;
 639.432 +	if (bank == 1)
 639.433 +		id = IDC_BANK_1;
 639.434 +	CheckRadioButton(IDC_BANK_0, IDC_BANK_1, id);
 639.435 +	id = IDC_BG0;
 639.436 +	if (bg == 1)
 639.437 +		id = IDC_BG1;
 639.438 +	CheckRadioButton(IDC_BG0, IDC_BG1, id);
 639.439 +	paint();
 639.440 +
 639.441 +	return TRUE; // return TRUE unless you set the focus to a control
 639.442 +	             // EXCEPTION: OCX Property Pages should return FALSE
 639.443 +}
 639.444 +
 639.445 +void GBMapView::OnBg0()
 639.446 +{
 639.447 +	bg = 0;
 639.448 +	paint();
 639.449 +}
 639.450 +
 639.451 +void GBMapView::OnBg1()
 639.452 +{
 639.453 +	bg = 1;
 639.454 +	paint();
 639.455 +}
 639.456 +
 639.457 +void GBMapView::OnBank0()
 639.458 +{
 639.459 +	bank = 0;
 639.460 +	paint();
 639.461 +}
 639.462 +
 639.463 +void GBMapView::OnBank1()
 639.464 +{
 639.465 +	bank = 1;
 639.466 +	paint();
 639.467 +}
 639.468 +
 639.469 +void GBMapView::OnStretch()
 639.470 +{
 639.471 +	mapView.setStretch(!mapView.getStretch());
 639.472 +	paint();
 639.473 +	regSetDwordValue("mapViewStretch", mapView.getStretch());
 639.474 +}
 639.475 +
 639.476 +void GBMapView::OnAutoUpdate()
 639.477 +{
 639.478 +	autoUpdate = !autoUpdate;
 639.479 +	if (autoUpdate)
 639.480 +	{
 639.481 +		theApp.winAddUpdateListener(this);
 639.482 +	}
 639.483 +	else
 639.484 +	{
 639.485 +		theApp.winRemoveUpdateListener(this);
 639.486 +	}
 639.487 +}
 639.488 +
 639.489 +void GBMapView::OnClose()
 639.490 +{
 639.491 +	theApp.winRemoveUpdateListener(this);
 639.492 +
 639.493 +	DestroyWindow();
 639.494 +}
 639.495 +
 639.496 +u32 GBMapView::GetClickAddress(int x, int y)
 639.497 +{
 639.498 +	u32 base = 0x9800;
 639.499 +	if (bg == 1)
 639.500 +		base = 0x9c00;
 639.501 +
 639.502 +	return base + (y >> 3)*32 + (x >> 3);
 639.503 +}
 639.504 +
 639.505 +LRESULT GBMapView::OnMapInfo(WPARAM wParam, LPARAM lParam)
 639.506 +{
 639.507 +	u8 *colors = (u8 *)lParam;
 639.508 +	mapViewZoom.setColors(colors);
 639.509 +
 639.510 +	int x = wParam & 0xffff;
 639.511 +	int y = (wParam >> 16);
 639.512 +
 639.513 +	CString buffer;
 639.514 +	buffer.Format("(%d,%d)", x, y);
 639.515 +	GetDlgItem(IDC_XY)->SetWindowText(buffer);
 639.516 +
 639.517 +	u32 address = GetClickAddress(x, y);
 639.518 +	buffer.Format("0x%08X", address);
 639.519 +	GetDlgItem(IDC_ADDRESS)->SetWindowText(buffer);
 639.520 +
 639.521 +	u8 attrs = 0;
 639.522 +
 639.523 +	u8 tile = gbReadMemoryQuick(0x9000 | (address & 0xfff));
 639.524 +	if (gbCgbMode)
 639.525 +	{
 639.526 +		attrs = gbVram[0x2000 + address - 0x8000];
 639.527 +		tile  = gbVram[address & 0x1fff];
 639.528 +	}
 639.529 +
 639.530 +	if (bank == 1)
 639.531 +	{
 639.532 +		if (tile > 128)
 639.533 +			tile -= 128;
 639.534 +		else
 639.535 +			tile += 128;
 639.536 +	}
 639.537 +
 639.538 +	buffer.Format("%d", tile);
 639.539 +	GetDlgItem(IDC_TILE_NUM)->SetWindowText(buffer);
 639.540 +
 639.541 +	buffer.Empty();
 639.542 +	buffer += attrs & 0x20 ? 'H' : '-';
 639.543 +	buffer += attrs & 0x40 ? 'V' : '-';
 639.544 +	GetDlgItem(IDC_FLIP)->SetWindowText(buffer);
 639.545 +
 639.546 +	if (gbCgbMode)
 639.547 +	{
 639.548 +		buffer.Format("%d", (attrs & 7));
 639.549 +	}
 639.550 +	else
 639.551 +		buffer = "---";
 639.552 +	GetDlgItem(IDC_PALETTE_NUM)->SetWindowText(buffer);
 639.553 +
 639.554 +	buffer.Empty();
 639.555 +	if (gbCgbMode)
 639.556 +		buffer += attrs & 0x80 ? 'P' : '-';
 639.557 +	else
 639.558 +		buffer += '-';
 639.559 +	GetDlgItem(IDC_PRIORITY)->SetWindowText(buffer);
 639.560 +
 639.561 +	return TRUE;
 639.562 +}
 639.563 +
 639.564 +LRESULT GBMapView::OnColInfo(WPARAM wParam, LPARAM)
 639.565 +{
 639.566 +	u16 c = (u16)wParam;
 639.567 +
 639.568 +	color.setColor(c);
 639.569 +
 639.570 +	int r = (c & 0x1f);
 639.571 +	int g = (c & 0x3e0) >> 5;
 639.572 +	int b = (c & 0x7c00) >> 10;
 639.573 +
 639.574 +	CString buffer;
 639.575 +	buffer.Format("R: %d", r);
 639.576 +	GetDlgItem(IDC_R)->SetWindowText(buffer);
 639.577 +
 639.578 +	buffer.Format("G: %d", g);
 639.579 +	GetDlgItem(IDC_G)->SetWindowText(buffer);
 639.580 +
 639.581 +	buffer.Format("B: %d", b);
 639.582 +	GetDlgItem(IDC_B)->SetWindowText(buffer);
 639.583 +
 639.584 +	return TRUE;
 639.585 +}
 639.586 +
 639.587 +void GBMapView::PostNcDestroy()
 639.588 +{
 639.589 +	delete this;
 639.590 +	CDialog::PostNcDestroy();
 639.591 +}
 639.592 +
   640.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   640.2 +++ b/src/win32/GBMapView.h	Sat Mar 03 10:31:27 2012 -0600
   640.3 @@ -0,0 +1,81 @@
   640.4 +#if !defined(AFX_GBMAPVIEW_H__4CD23D38_F2CD_4B95_AE76_2781591DD077__INCLUDED_)
   640.5 +#define AFX_GBMAPVIEW_H__4CD23D38_F2CD_4B95_AE76_2781591DD077__INCLUDED_
   640.6 +
   640.7 +#if _MSC_VER > 1000
   640.8 +#pragma once
   640.9 +#endif // _MSC_VER > 1000
  640.10 +// -*- C++ -*-
  640.11 +// GBMapView.h : header file
  640.12 +//
  640.13 +
  640.14 +#include "BitmapControl.h"
  640.15 +#include "ColorControl.h"
  640.16 +#include "ZoomControl.h"
  640.17 +#include "ResizeDlg.h"
  640.18 +#include "IUpdate.h"
  640.19 +
  640.20 +/////////////////////////////////////////////////////////////////////////////
  640.21 +// GBMapView dialog
  640.22 +
  640.23 +class GBMapView : public ResizeDlg, IUpdateListener
  640.24 +{
  640.25 +private:
  640.26 +	BITMAPINFO    bmpInfo;
  640.27 +	u8 *          data;
  640.28 +	int           bank;
  640.29 +	int           bg;
  640.30 +	int           w;
  640.31 +	int           h;
  640.32 +	BitmapControl mapView;
  640.33 +	ZoomControl   mapViewZoom;
  640.34 +	ColorControl  color;
  640.35 +	bool          autoUpdate;
  640.36 +	// Construction
  640.37 +public:
  640.38 +	afx_msg LRESULT OnColInfo(WPARAM wParam, LPARAM lParam);
  640.39 +	afx_msg LRESULT OnMapInfo(WPARAM wParam, LPARAM lParam);
  640.40 +	u32 GetClickAddress(int x, int y);
  640.41 +	void update();
  640.42 +	void paint();
  640.43 +	void render();
  640.44 +	void savePNG(const char *name);
  640.45 +	void saveBMP(const char *name);
  640.46 +	~GBMapView();
  640.47 +	GBMapView(CWnd*pParent = NULL);  // standard constructor
  640.48 +
  640.49 +	// Dialog Data
  640.50 +	//{{AFX_DATA(GBMapView)
  640.51 +	enum { IDD = IDD_GB_MAP_VIEW };
  640.52 +	// NOTE: the ClassWizard will add data members here
  640.53 +	//}}AFX_DATA
  640.54 +
  640.55 +	// Overrides
  640.56 +	// ClassWizard generated virtual function overrides
  640.57 +	//{{AFX_VIRTUAL(GBMapView)
  640.58 +protected:
  640.59 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  640.60 +	virtual void PostNcDestroy();
  640.61 +	//}}AFX_VIRTUAL
  640.62 +
  640.63 +	// Implementation
  640.64 +protected:
  640.65 +	// Generated message map functions
  640.66 +	//{{AFX_MSG(GBMapView)
  640.67 +	afx_msg void OnSave();
  640.68 +	afx_msg void OnRefresh();
  640.69 +	virtual BOOL OnInitDialog();
  640.70 +	afx_msg void OnBg0();
  640.71 +	afx_msg void OnBg1();
  640.72 +	afx_msg void OnBank0();
  640.73 +	afx_msg void OnBank1();
  640.74 +	afx_msg void OnStretch();
  640.75 +	afx_msg void OnAutoUpdate();
  640.76 +	afx_msg void OnClose();
  640.77 +	//}}AFX_MSG
  640.78 +	DECLARE_MESSAGE_MAP()
  640.79 +};
  640.80 +
  640.81 +//{{AFX_INSERT_LOCATION}}
  640.82 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  640.83 +
  640.84 +#endif // !defined(AFX_GBMAPVIEW_H__4CD23D38_F2CD_4B95_AE76_2781591DD077__INCLUDED_)
   641.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   641.2 +++ b/src/win32/GBMemoryViewerDlg.cpp	Sat Mar 03 10:31:27 2012 -0600
   641.3 @@ -0,0 +1,448 @@
   641.4 +// GBMemoryViewerDlg.cpp : implementation file
   641.5 +//
   641.6 +
   641.7 +#include "stdafx.h"
   641.8 +#include "resource.h"
   641.9 +#include "GBMemoryViewerDlg.h"
  641.10 +#include "FileDlg.h"
  641.11 +#include "MemoryViewerAddressSize.h"
  641.12 +#include "Reg.h"
  641.13 +#include "WinResUtil.h"
  641.14 +#include "VBA.h"
  641.15 +
  641.16 +//#include "../common/System.h"
  641.17 +#include "../gb/gbGlobals.h"
  641.18 +
  641.19 +GBMemoryViewer::GBMemoryViewer()
  641.20 +	: MemoryViewer()
  641.21 +{
  641.22 +	setAddressSize(1);
  641.23 +}
  641.24 +
  641.25 +void GBMemoryViewer::readData(u32 address, int len, u8 *data)
  641.26 +{
  641.27 +	u16 addr = address & 0xffff;
  641.28 +	if (emulating && gbRom != NULL)
  641.29 +	{
  641.30 +		for (int i = 0; i < len; i++)
  641.31 +		{
  641.32 +			*data++ = gbReadMemoryQuick(addr);
  641.33 +			addr++;
  641.34 +		}
  641.35 +	}
  641.36 +	else
  641.37 +	{
  641.38 +		for (int i = 0; i < len; i++)
  641.39 +		{
  641.40 +			*data++ = 0;
  641.41 +			addr++;
  641.42 +		}
  641.43 +	}
  641.44 +}
  641.45 +
  641.46 +void GBMemoryViewer::editData(u32 address, int size, int mask, u32 value)
  641.47 +{
  641.48 +	u32 oldValue;
  641.49 +	u16 addr = (u16)address & 0xffff;
  641.50 +	switch (size)
  641.51 +	{
  641.52 +	case 8:
  641.53 +		oldValue  = gbReadMemoryQuick(addr);
  641.54 +		oldValue &= mask;
  641.55 +		oldValue |= (u8)value;
  641.56 +		gbWriteMemoryQuick(addr, oldValue);
  641.57 +		break;
  641.58 +	case 16:
  641.59 +		oldValue = gbReadMemoryQuick(addr) |
  641.60 +		           (gbReadMemoryQuick(addr + 1) << 8);
  641.61 +		oldValue &= mask;
  641.62 +		oldValue |= (u16)value;
  641.63 +		gbWriteMemoryQuick(addr, (oldValue & 255));
  641.64 +		gbWriteMemoryQuick(addr+1, (oldValue >> 8));
  641.65 +		break;
  641.66 +	case 32:
  641.67 +		oldValue = gbReadMemoryQuick(addr) |
  641.68 +		           (gbReadMemoryQuick(addr + 1) << 8) |
  641.69 +		           (gbReadMemoryQuick(addr + 2) << 16) |
  641.70 +		           (gbReadMemoryQuick(addr + 3) << 24);
  641.71 +		oldValue &= mask;
  641.72 +		oldValue |= (u32)value;
  641.73 +		gbWriteMemoryQuick(addr, (oldValue & 255));
  641.74 +		gbWriteMemoryQuick(addr+1, (oldValue >> 8));
  641.75 +		gbWriteMemoryQuick(addr+2, (oldValue >> 16));
  641.76 +		gbWriteMemoryQuick(addr+3, (oldValue >> 24));
  641.77 +		break;
  641.78 +	}
  641.79 +}
  641.80 +
  641.81 +/////////////////////////////////////////////////////////////////////////////
  641.82 +// GBMemoryViewerDlg dialog
  641.83 +
  641.84 +GBMemoryViewerDlg::GBMemoryViewerDlg(CWnd*pParent /*=NULL*/)
  641.85 +	: ResizeDlg(GBMemoryViewerDlg::IDD, pParent)
  641.86 +{
  641.87 +	//{{AFX_DATA_INIT(GBMemoryViewerDlg)
  641.88 +	m_size = -1;
  641.89 +	//}}AFX_DATA_INIT
  641.90 +	autoUpdate = false;
  641.91 +}
  641.92 +
  641.93 +void GBMemoryViewerDlg::DoDataExchange(CDataExchange*pDX)
  641.94 +{
  641.95 +	CDialog::DoDataExchange(pDX);
  641.96 +	//{{AFX_DATA_MAP(GBMemoryViewerDlg)
  641.97 +	DDX_Control(pDX, IDC_CURRENT_ADDRESS, m_current);
  641.98 +	DDX_Control(pDX, IDC_ADDRESS, m_address);
  641.99 +	DDX_Control(pDX, IDC_ADDRESSES, m_addresses);
 641.100 +	DDX_Radio(pDX, IDC_8_BIT, m_size);
 641.101 +	//}}AFX_DATA_MAP
 641.102 +	DDX_Control(pDX, IDC_VIEWER, m_viewer);
 641.103 +}
 641.104 +
 641.105 +BEGIN_MESSAGE_MAP(GBMemoryViewerDlg, CDialog)
 641.106 +//{{AFX_MSG_MAP(GBMemoryViewerDlg)
 641.107 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
 641.108 +ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
 641.109 +ON_BN_CLICKED(IDC_8_BIT, On8Bit)
 641.110 +ON_BN_CLICKED(IDC_16_BIT, On16Bit)
 641.111 +ON_BN_CLICKED(IDC_32_BIT, On32Bit)
 641.112 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
 641.113 +ON_BN_CLICKED(IDC_DECIMAL_DISPLAY, OnDecimalDisplay)
 641.114 +ON_BN_CLICKED(IDC_ALIGN, OnAlign)
 641.115 +ON_BN_CLICKED(IDC_GO, OnGo)
 641.116 +ON_CBN_SELCHANGE(IDC_ADDRESSES, OnSelchangeAddresses)
 641.117 +ON_BN_CLICKED(IDC_SAVE, OnSave)
 641.118 +ON_BN_CLICKED(IDC_LOAD, OnLoad)
 641.119 +//}}AFX_MSG_MAP
 641.120 +END_MESSAGE_MAP()
 641.121 +
 641.122 +/////////////////////////////////////////////////////////////////////////////
 641.123 +// GBMemoryViewerDlg message handlers
 641.124 +
 641.125 +BOOL GBMemoryViewerDlg::OnInitDialog()
 641.126 +{
 641.127 +	CDialog::OnInitDialog();
 641.128 +
 641.129 +	autoUpdate = !regQueryDwordValue("memViewerAutoUpdate", 1);
 641.130 +	OnAutoUpdate(); // inverts and update dialog
 641.131 +
 641.132 +	decimalDisplay = !regQueryDwordValue("memViewerDecimalDisplay", 0);
 641.133 +	OnDecimalDisplay();
 641.134 +
 641.135 +	align = !regQueryDwordValue("memViewerAlign", 0);
 641.136 +	OnAlign();
 641.137 +
 641.138 +	DIALOG_SIZER_START(sz)
 641.139 +	DIALOG_SIZER_ENTRY(IDC_VIEWER, DS_SizeX | DS_SizeY)
 641.140 +	DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
 641.141 +	DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
 641.142 +	DIALOG_SIZER_ENTRY(IDC_LOAD, DS_MoveY)
 641.143 +	DIALOG_SIZER_ENTRY(IDC_SAVE, DS_MoveY)
 641.144 +	DIALOG_SIZER_ENTRY(IDC_AUTO_UPDATE, DS_MoveY)
 641.145 +	DIALOG_SIZER_ENTRY(IDC_DECIMAL_DISPLAY, DS_MoveY)
 641.146 +	DIALOG_SIZER_ENTRY(IDC_ALIGN, DS_MoveY)
 641.147 +	DIALOG_SIZER_ENTRY(IDC_CURRENT_ADDRESS_LABEL, DS_MoveY | DS_MoveX)
 641.148 +	DIALOG_SIZER_ENTRY(IDC_CURRENT_ADDRESS, DS_MoveY | DS_MoveX)
 641.149 +	DIALOG_SIZER_END()
 641.150 +	SetData(sz,
 641.151 +	        TRUE,
 641.152 +	        HKEY_CURRENT_USER,
 641.153 +	        "Software\\Emulators\\VisualBoyAdvance\\Viewer\\GBMemoryView",
 641.154 +	        NULL);
 641.155 +
 641.156 +	m_viewer.setDialog(this);
 641.157 +	m_viewer.ShowScrollBar(SB_VERT, TRUE);
 641.158 +	m_viewer.EnableScrollBar(SB_VERT, ESB_ENABLE_BOTH);
 641.159 +
 641.160 +	LPCTSTR s[] = {
 641.161 +		"0x0000 - ROM",
 641.162 +		"0x4000 - ROM",
 641.163 +		"0x8000 - VRAM",
 641.164 +		"0xA000 - SRAM",
 641.165 +		"0xC000 - RAM",
 641.166 +		"0xD000 - WRAM",
 641.167 +		"0xFF00 - I/O",
 641.168 +		"0xFF80 - RAM"
 641.169 +	};
 641.170 +
 641.171 +	for (int i = 0; i < 8; i++)
 641.172 +		m_addresses.AddString(s[i]);
 641.173 +
 641.174 +	m_addresses.SetCurSel(0);
 641.175 +
 641.176 +	RECT cbSize;
 641.177 +	int  Height;
 641.178 +
 641.179 +	m_addresses.GetClientRect(&cbSize);
 641.180 +	Height  = m_addresses.GetItemHeight(-1);
 641.181 +	Height += m_addresses.GetItemHeight(0) * (9);
 641.182 +
 641.183 +	// Note: The use of SM_CYEDGE assumes that we're using Windows '95
 641.184 +	// Now add on the height of the border of the edit box
 641.185 +	Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges
 641.186 +
 641.187 +	// The height of the border of the drop-down box
 641.188 +	Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges
 641.189 +
 641.190 +	// now set the size of the window
 641.191 +	m_addresses.SetWindowPos(NULL,
 641.192 +	                         0, 0,
 641.193 +	                         cbSize.right, Height,
 641.194 +	                         SWP_NOMOVE | SWP_NOZORDER);
 641.195 +
 641.196 +	m_address.LimitText(8);
 641.197 +
 641.198 +	m_size = regQueryDwordValue("memViewerDataSize", 0);
 641.199 +	if (m_size < 0 || m_size > 2)
 641.200 +		m_size = 0;
 641.201 +	m_viewer.setSize(m_size);
 641.202 +	UpdateData(FALSE);
 641.203 +
 641.204 +	m_current.SetFont(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)));
 641.205 +
 641.206 +	return TRUE; // return TRUE unless you set the focus to a control
 641.207 +	             // EXCEPTION: OCX Property Pages should return FALSE
 641.208 +}
 641.209 +
 641.210 +void GBMemoryViewerDlg::OnClose()
 641.211 +{
 641.212 +	theApp.winRemoveUpdateListener(this);
 641.213 +
 641.214 +	DestroyWindow();
 641.215 +}
 641.216 +
 641.217 +void GBMemoryViewerDlg::OnRefresh()
 641.218 +{
 641.219 +	m_viewer.Invalidate();
 641.220 +}
 641.221 +
 641.222 +void GBMemoryViewerDlg::update()
 641.223 +{
 641.224 +	OnRefresh();
 641.225 +}
 641.226 +
 641.227 +void GBMemoryViewerDlg::On8Bit()
 641.228 +{
 641.229 +	m_viewer.setSize(0);
 641.230 +	regSetDwordValue("memViewerDataSize", 0);
 641.231 +}
 641.232 +
 641.233 +void GBMemoryViewerDlg::On16Bit()
 641.234 +{
 641.235 +	m_viewer.setSize(1);
 641.236 +	regSetDwordValue("memViewerDataSize", 1);
 641.237 +}
 641.238 +
 641.239 +void GBMemoryViewerDlg::On32Bit()
 641.240 +{
 641.241 +	m_viewer.setSize(2);
 641.242 +	regSetDwordValue("memViewerDataSize", 2);
 641.243 +}
 641.244 +
 641.245 +void GBMemoryViewerDlg::OnAutoUpdate()
 641.246 +{
 641.247 +	autoUpdate = !autoUpdate;
 641.248 +	if (autoUpdate)
 641.249 +	{
 641.250 +		theApp.winAddUpdateListener(this);
 641.251 +	}
 641.252 +	else
 641.253 +	{
 641.254 +		theApp.winRemoveUpdateListener(this);
 641.255 +	}
 641.256 +	if (GetDlgItem(IDC_AUTO_UPDATE))
 641.257 +		((CButton *)GetDlgItem(IDC_AUTO_UPDATE))->SetCheck(autoUpdate ? TRUE : FALSE);
 641.258 +	regSetDwordValue("memViewerAutoUpdate", autoUpdate);
 641.259 +}
 641.260 +
 641.261 +void GBMemoryViewerDlg::OnDecimalDisplay()
 641.262 +{
 641.263 +	decimalDisplay = !decimalDisplay;
 641.264 +	m_viewer.setDecimal(decimalDisplay ? true : false);
 641.265 +	if (GetDlgItem(IDC_DECIMAL_DISPLAY))
 641.266 +		((CButton *)GetDlgItem(IDC_DECIMAL_DISPLAY))->SetCheck(decimalDisplay ? TRUE : FALSE);
 641.267 +
 641.268 +	regSetDwordValue("memViewerDecimalDisplay", decimalDisplay);
 641.269 +}
 641.270 +
 641.271 +void GBMemoryViewerDlg::OnAlign()
 641.272 +{
 641.273 +	align = !align;
 641.274 +	if (GetDlgItem(IDC_ALIGN))
 641.275 +		((CButton *)GetDlgItem(IDC_ALIGN))->SetCheck(align ? TRUE : FALSE);
 641.276 +
 641.277 +	regSetDwordValue("memViewerAlign", align);
 641.278 +}
 641.279 +
 641.280 +void GBMemoryViewerDlg::OnGo()
 641.281 +{
 641.282 +	CString buffer;
 641.283 +
 641.284 +	m_address.GetWindowText(buffer);
 641.285 +
 641.286 +	u32 address;
 641.287 +	sscanf(buffer, "%x", &address);
 641.288 +	if (align)
 641.289 +		address &= ~0xF;
 641.290 +	else
 641.291 +	{
 641.292 +		if (m_viewer.getSize() == 1)
 641.293 +			address &= ~1;
 641.294 +		else if (m_viewer.getSize() == 2)
 641.295 +			address &= ~3;
 641.296 +	}
 641.297 +	m_viewer.setAddress(address);
 641.298 +}
 641.299 +
 641.300 +void GBMemoryViewerDlg::OnSelchangeAddresses()
 641.301 +{
 641.302 +	int cur = m_addresses.GetCurSel();
 641.303 +
 641.304 +	switch (cur)
 641.305 +	{
 641.306 +	case 0:
 641.307 +		m_viewer.setAddress(0x0000);
 641.308 +		break;
 641.309 +	case 1:
 641.310 +		m_viewer.setAddress(0x4000);
 641.311 +		break;
 641.312 +	case 2:
 641.313 +		m_viewer.setAddress(0x8000);
 641.314 +		break;
 641.315 +	case 3:
 641.316 +		m_viewer.setAddress(0xa000);
 641.317 +		break;
 641.318 +	case 4:
 641.319 +		m_viewer.setAddress(0xc000);
 641.320 +		break;
 641.321 +	case 5:
 641.322 +		m_viewer.setAddress(0xd000);
 641.323 +		break;
 641.324 +	case 6:
 641.325 +		m_viewer.setAddress(0xff00);
 641.326 +		break;
 641.327 +	case 7:
 641.328 +		m_viewer.setAddress(0xff80);
 641.329 +		break;
 641.330 +	}
 641.331 +}
 641.332 +
 641.333 +void GBMemoryViewerDlg::setCurrentAddress(u32 address)
 641.334 +{
 641.335 +	CString buffer;
 641.336 +
 641.337 +	buffer.Format("0x%08X", address);
 641.338 +	m_current.SetWindowText(buffer);
 641.339 +}
 641.340 +
 641.341 +void GBMemoryViewerDlg::OnSave()
 641.342 +{
 641.343 +	MemoryViewerAddressSize dlg;
 641.344 +
 641.345 +	dlg.setAddress(m_viewer.getCurrentAddress());
 641.346 +
 641.347 +	LPCTSTR exts[] = { ".dmp", NULL };
 641.348 +
 641.349 +	CString filter = winResLoadFilter(IDS_FILTER_DUMP);
 641.350 +	CString title  = winResLoadString(IDS_SELECT_DUMP_FILE);
 641.351 +
 641.352 +	if (dlg.DoModal() == IDOK)
 641.353 +	{
 641.354 +		CString buffer;
 641.355 +		FileDlg file(this,
 641.356 +		             buffer,
 641.357 +		             filter,
 641.358 +		             0,
 641.359 +		             "DMP",
 641.360 +		             exts,
 641.361 +		             "",
 641.362 +		             title,
 641.363 +		             true);
 641.364 +		if (file.DoModal() == IDOK)
 641.365 +		{
 641.366 +			buffer = file.GetPathName();
 641.367 +			FILE *f = fopen(buffer, "wb");
 641.368 +
 641.369 +			if (f == NULL)
 641.370 +			{
 641.371 +				systemMessage(IDS_ERROR_CREATING_FILE, buffer);
 641.372 +				return;
 641.373 +			}
 641.374 +
 641.375 +			int size = dlg.getSize();
 641.376 +			u16 addr = dlg.getAddress() & 0xffff;
 641.377 +
 641.378 +			for (int i = 0; i < size; i++)
 641.379 +			{
 641.380 +				fputc(gbReadMemoryQuick(addr), f);
 641.381 +				addr++;
 641.382 +			}
 641.383 +
 641.384 +			fclose(f);
 641.385 +		}
 641.386 +	}
 641.387 +}
 641.388 +
 641.389 +void GBMemoryViewerDlg::OnLoad()
 641.390 +{
 641.391 +	CString buffer;
 641.392 +	LPCTSTR exts[] = { ".dmp", NULL };
 641.393 +	CString filter = winResLoadFilter(IDS_FILTER_DUMP);
 641.394 +	CString title  = winResLoadString(IDS_SELECT_DUMP_FILE);
 641.395 +
 641.396 +	FileDlg file(this,
 641.397 +	             buffer,
 641.398 +	             filter,
 641.399 +	             0,
 641.400 +	             "DMP",
 641.401 +	             exts,
 641.402 +	             "",
 641.403 +	             title,
 641.404 +	             false);
 641.405 +
 641.406 +	if (file.DoModal() == IDOK)
 641.407 +	{
 641.408 +		buffer = file.GetPathName();
 641.409 +		FILE *f = fopen(buffer, "rb");
 641.410 +		if (f == NULL)
 641.411 +		{
 641.412 +			systemMessage(IDS_CANNOT_OPEN_FILE,
 641.413 +			              "Cannot open file %s",
 641.414 +			              buffer);
 641.415 +			return;
 641.416 +		}
 641.417 +
 641.418 +		MemoryViewerAddressSize dlg;
 641.419 +
 641.420 +		fseek(f, 0, SEEK_END);
 641.421 +		int size = ftell(f);
 641.422 +
 641.423 +		fseek(f, 0, SEEK_SET);
 641.424 +
 641.425 +		dlg.setAddress(m_viewer.getCurrentAddress());
 641.426 +		dlg.setSize(size);
 641.427 +
 641.428 +		if (dlg.DoModal() == IDOK)
 641.429 +		{
 641.430 +			int size = dlg.getSize();
 641.431 +			u16 addr = dlg.getAddress() & 0xffff;
 641.432 +
 641.433 +			for (int i = 0; i < size; i++)
 641.434 +			{
 641.435 +				int c = fgetc(f);
 641.436 +				if (c == -1)
 641.437 +					break;
 641.438 +				gbWriteMemoryQuick(addr, c);
 641.439 +				addr++;
 641.440 +			}
 641.441 +			OnRefresh();
 641.442 +		}
 641.443 +		fclose(f);
 641.444 +	}
 641.445 +}
 641.446 +
 641.447 +void GBMemoryViewerDlg::PostNcDestroy()
 641.448 +{
 641.449 +	delete this;
 641.450 +}
 641.451 +
   642.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   642.2 +++ b/src/win32/GBMemoryViewerDlg.h	Sat Mar 03 10:31:27 2012 -0600
   642.3 @@ -0,0 +1,79 @@
   642.4 +#if !defined(AFX_GBMEMORYVIEWERDLG_H__23AD2804_EFA5_4900_AEC5_47196A41C50D__INCLUDED_)
   642.5 +#define AFX_GBMEMORYVIEWERDLG_H__23AD2804_EFA5_4900_AEC5_47196A41C50D__INCLUDED_
   642.6 +
   642.7 +#if _MSC_VER > 1000
   642.8 +#pragma once
   642.9 +#endif // _MSC_VER > 1000
  642.10 +// -*- C++ -*-
  642.11 +// GBMemoryViewerDlg.h : header file
  642.12 +//
  642.13 +#include "MemoryViewer.h"
  642.14 +#include "ResizeDlg.h"
  642.15 +#include "IUpdate.h"
  642.16 +
  642.17 +class GBMemoryViewer : public MemoryViewer
  642.18 +{
  642.19 +public:
  642.20 +	GBMemoryViewer();
  642.21 +	virtual void readData(u32, int, u8 *);
  642.22 +	virtual void editData(u32, int, int, u32);
  642.23 +};
  642.24 +
  642.25 +/////////////////////////////////////////////////////////////////////////////
  642.26 +// GBMemoryViewerDlg dialog
  642.27 +
  642.28 +class GBMemoryViewerDlg : public ResizeDlg, IUpdateListener, IMemoryViewerDlg
  642.29 +{
  642.30 +	GBMemoryViewer m_viewer;
  642.31 +	bool autoUpdate;
  642.32 +	int  decimalDisplay;
  642.33 +	int  align;
  642.34 +	// Construction
  642.35 +public:
  642.36 +	void setCurrentAddress(u32 address);
  642.37 +	GBMemoryViewerDlg(CWnd*pParent = NULL);  // standard constructor
  642.38 +
  642.39 +	virtual void update();
  642.40 +
  642.41 +	// Dialog Data
  642.42 +	//{{AFX_DATA(GBMemoryViewerDlg)
  642.43 +	enum { IDD = IDD_MEM_VIEWER };
  642.44 +	CEdit     m_current;
  642.45 +	CEdit     m_address;
  642.46 +	CComboBox m_addresses;
  642.47 +	int       m_size;
  642.48 +	//}}AFX_DATA
  642.49 +
  642.50 +	// Overrides
  642.51 +	// ClassWizard generated virtual function overrides
  642.52 +	//{{AFX_VIRTUAL(GBMemoryViewerDlg)
  642.53 +protected:
  642.54 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  642.55 +	virtual void PostNcDestroy();
  642.56 +	//}}AFX_VIRTUAL
  642.57 +
  642.58 +	// Implementation
  642.59 +protected:
  642.60 +	// Generated message map functions
  642.61 +	//{{AFX_MSG(GBMemoryViewerDlg)
  642.62 +	virtual BOOL OnInitDialog();
  642.63 +	afx_msg void OnClose();
  642.64 +	afx_msg void OnRefresh();
  642.65 +	afx_msg void On8Bit();
  642.66 +	afx_msg void On16Bit();
  642.67 +	afx_msg void On32Bit();
  642.68 +	afx_msg void OnAutoUpdate();
  642.69 +	afx_msg void OnDecimalDisplay();
  642.70 +	afx_msg void OnAlign();
  642.71 +	afx_msg void OnGo();
  642.72 +	afx_msg void OnSelchangeAddresses();
  642.73 +	afx_msg void OnSave();
  642.74 +	afx_msg void OnLoad();
  642.75 +	//}}AFX_MSG
  642.76 +	DECLARE_MESSAGE_MAP()
  642.77 +};
  642.78 +
  642.79 +//{{AFX_INSERT_LOCATION}}
  642.80 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  642.81 +
  642.82 +#endif // !defined(AFX_GBMEMORYVIEWERDLG_H__23AD2804_EFA5_4900_AEC5_47196A41C50D__INCLUDED_)
   643.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   643.2 +++ b/src/win32/GBOamView.cpp	Sat Mar 03 10:31:27 2012 -0600
   643.3 @@ -0,0 +1,598 @@
   643.4 +// GBOamView.cpp : implementation file
   643.5 +//
   643.6 +
   643.7 +#include "stdafx.h"
   643.8 +#include "resource.h"
   643.9 +#include "GBOamView.h"
  643.10 +#include "FileDlg.h"
  643.11 +#include "Reg.h"
  643.12 +#include "WinResUtil.h"
  643.13 +#include "VBA.h"
  643.14 +
  643.15 +//#include "../common/System.h"
  643.16 +#include "../gb/gbGlobals.h"
  643.17 +#include "../NLS.h"
  643.18 +#include "../common/Util.h"
  643.19 +
  643.20 +extern "C" {
  643.21 +#include <png.h>
  643.22 +}
  643.23 +
  643.24 +/////////////////////////////////////////////////////////////////////////////
  643.25 +// GBOamView dialog
  643.26 +
  643.27 +GBOamView::GBOamView(CWnd*pParent /*=NULL*/)
  643.28 +	: ResizeDlg(GBOamView::IDD, pParent)
  643.29 +{
  643.30 +	//{{AFX_DATA_INIT(GBOamView)
  643.31 +	m_stretch = FALSE;
  643.32 +	//}}AFX_DATA_INIT
  643.33 +	autoUpdate = false;
  643.34 +
  643.35 +	memset(&bmpInfo.bmiHeader, 0, sizeof(bmpInfo.bmiHeader));
  643.36 +
  643.37 +	bmpInfo.bmiHeader.biSize        = sizeof(bmpInfo.bmiHeader);
  643.38 +	bmpInfo.bmiHeader.biWidth       = 8;
  643.39 +	bmpInfo.bmiHeader.biHeight      = 16;
  643.40 +	bmpInfo.bmiHeader.biPlanes      = 1;
  643.41 +	bmpInfo.bmiHeader.biBitCount    = 24;
  643.42 +	bmpInfo.bmiHeader.biCompression = BI_RGB;
  643.43 +	data = (u8 *)calloc(1, 3 * 8 * 16);
  643.44 +
  643.45 +	oamView.setData(data);
  643.46 +	oamView.setBmpInfo(&bmpInfo);
  643.47 +
  643.48 +	number = 0;
  643.49 +}
  643.50 +
  643.51 +void GBOamView::DoDataExchange(CDataExchange*pDX)
  643.52 +{
  643.53 +	CDialog::DoDataExchange(pDX);
  643.54 +	//{{AFX_DATA_MAP(GBOamView)
  643.55 +	DDX_Control(pDX, IDC_SPRITE, m_sprite);
  643.56 +	DDX_Check(pDX, IDC_STRETCH, m_stretch);
  643.57 +	//}}AFX_DATA_MAP
  643.58 +	DDX_Control(pDX, IDC_COLOR, color);
  643.59 +	DDX_Control(pDX, IDC_OAM_VIEW, oamView);
  643.60 +	DDX_Control(pDX, IDC_OAM_VIEW_ZOOM, oamZoom);
  643.61 +}
  643.62 +
  643.63 +BEGIN_MESSAGE_MAP(GBOamView, CDialog)
  643.64 +//{{AFX_MSG_MAP(GBOamView)
  643.65 +ON_BN_CLICKED(IDC_STRETCH, OnStretch)
  643.66 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
  643.67 +ON_EN_CHANGE(IDC_SPRITE, OnChangeSprite)
  643.68 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
  643.69 +ON_WM_HSCROLL()
  643.70 +//}}AFX_MSG_MAP
  643.71 +ON_MESSAGE(WM_MAPINFO, OnMapInfo)
  643.72 +ON_MESSAGE(WM_COLINFO, OnColInfo)
  643.73 +END_MESSAGE_MAP()
  643.74 +
  643.75 +/////////////////////////////////////////////////////////////////////////////
  643.76 +// GBOamView message handlers
  643.77 +
  643.78 +GBOamView::~GBOamView()
  643.79 +{
  643.80 +	free(data);
  643.81 +	data = NULL;
  643.82 +}
  643.83 +
  643.84 +void GBOamView::paint()
  643.85 +{
  643.86 +	if (gbRom == NULL)
  643.87 +		return;
  643.88 +
  643.89 +	render();
  643.90 +	oamView.setSize(w, h);
  643.91 +	oamView.refresh();
  643.92 +}
  643.93 +
  643.94 +void GBOamView::update()
  643.95 +{
  643.96 +	paint();
  643.97 +}
  643.98 +
  643.99 +void GBOamView::setAttributes(int y, int x, int tile, int flags)
 643.100 +{
 643.101 +	CString buffer;
 643.102 +
 643.103 +	int flipH = flags & 0x20;
 643.104 +	int flipV = flags & 0x40;
 643.105 +	int prio  = (flags & 0x80) >> 7;
 643.106 +	int pal   = flags & 0x7;
 643.107 +	int oap   = (flags & 0x08) >> 3;
 643.108 +	int bank  = (flags & 0x10) >> 4;
 643.109 +
 643.110 +	buffer.Format("%d,%d", x, y);
 643.111 +	GetDlgItem(IDC_POS)->SetWindowText(buffer);
 643.112 +
 643.113 +	buffer.Format("%d", pal);
 643.114 +	GetDlgItem(IDC_PALETTE)->SetWindowText(buffer);
 643.115 +
 643.116 +	buffer.Format("%d", tile);
 643.117 +	GetDlgItem(IDC_TILE)->SetWindowText(buffer);
 643.118 +
 643.119 +	buffer.Format("%d", prio);
 643.120 +	GetDlgItem(IDC_PRIO)->SetWindowText(buffer);
 643.121 +
 643.122 +	buffer.Format("%d", bank);
 643.123 +	GetDlgItem(IDC_BANK)->SetWindowText(buffer);
 643.124 +
 643.125 +	buffer.Empty();
 643.126 +	if (flipH)
 643.127 +		buffer += 'H';
 643.128 +	else
 643.129 +		buffer += ' ';
 643.130 +	if (flipV)
 643.131 +		buffer += 'V';
 643.132 +	else
 643.133 +		buffer += ' ';
 643.134 +	GetDlgItem(IDC_FLAGS)->SetWindowText(buffer);
 643.135 +
 643.136 +	buffer.Format("%d", oap);
 643.137 +	GetDlgItem(IDC_OAP)->SetWindowText(buffer);
 643.138 +}
 643.139 +
 643.140 +void GBOamView::render()
 643.141 +{
 643.142 +	int m = 0;
 643.143 +	if (gbRom == NULL)
 643.144 +		return;
 643.145 +
 643.146 +	u16 addr = number * 4 + 0xfe00;
 643.147 +
 643.148 +	int size = register_LCDC & 4;
 643.149 +
 643.150 +	u8 y    = gbReadMemoryQuick(addr++);
 643.151 +	u8 x    = gbReadMemoryQuick(addr++);
 643.152 +	u8 tile = gbReadMemoryQuick(addr++);
 643.153 +	if (size)
 643.154 +		tile &= 254;
 643.155 +	u8 flags = gbReadMemoryQuick(addr++);
 643.156 +
 643.157 +	u8 *bmp = data;
 643.158 +
 643.159 +	w = 8;
 643.160 +	h = size ? 16 : 8;
 643.161 +
 643.162 +	setAttributes(y, x, tile, flags);
 643.163 +
 643.164 +	u8 *bank0;
 643.165 +	u8 *bank1;
 643.166 +	if (gbCgbMode)
 643.167 +	{
 643.168 +		if (register_VBK & 1)
 643.169 +		{
 643.170 +			bank0 = &gbVram[0x0000];
 643.171 +			bank1 = &gbVram[0x2000];
 643.172 +		}
 643.173 +		else
 643.174 +		{
 643.175 +			bank0 = &gbVram[0x0000];
 643.176 +			bank1 = &gbVram[0x2000];
 643.177 +		}
 643.178 +	}
 643.179 +	else
 643.180 +	{
 643.181 +		bank0 = &gbMemory[0x8000];
 643.182 +		bank1 = NULL;
 643.183 +	}
 643.184 +
 643.185 +	int init = 0x0000;
 643.186 +
 643.187 +	u8 *pal = gbObp0;
 643.188 +
 643.189 +	if ((flags & 0x10))
 643.190 +		pal = gbObp1;
 643.191 +
 643.192 +	for (int yy = 0; yy < h; yy++)
 643.193 +	{
 643.194 +		int address = init + tile * 16 + 2*yy;
 643.195 +		int a       = 0;
 643.196 +		int b       = 0;
 643.197 +
 643.198 +		if (gbCgbMode && flags & 0x08)
 643.199 +		{
 643.200 +			a = bank1[address++];
 643.201 +			b = bank1[address++];
 643.202 +		}
 643.203 +		else
 643.204 +		{
 643.205 +			a = bank0[address++];
 643.206 +			b = bank0[address++];
 643.207 +		}
 643.208 +
 643.209 +		for (int xx = 0; xx < 8; xx++)
 643.210 +		{
 643.211 +			u8 mask = 1 << (7-xx);
 643.212 +			u8 c    = 0;
 643.213 +			if ((a & mask))
 643.214 +				c++;
 643.215 +			if ((b & mask))
 643.216 +				c += 2;
 643.217 +
 643.218 +			// make sure that sprites will work even in CGB mode
 643.219 +			if (gbCgbMode)
 643.220 +			{
 643.221 +				c = c + (flags & 0x07)*4 + 32;
 643.222 +			}
 643.223 +			else
 643.224 +			{
 643.225 +				c = pal[c];
 643.226 +			}
 643.227 +
 643.228 +			u16 color = gbPalette[c];
 643.229 +			*bmp++ = ((color >> 10) & 0x1f) << 3;
 643.230 +			*bmp++ = ((color >> 5) & 0x1f) << 3;
 643.231 +			*bmp++ = (color & 0x1f) << 3;
 643.232 +		}
 643.233 +	}
 643.234 +}
 643.235 +
 643.236 +void GBOamView::saveBMP(const char *name)
 643.237 +{
 643.238 +	u8 writeBuffer[1024 * 3];
 643.239 +
 643.240 +	FILE *fp = fopen(name, "wb");
 643.241 +
 643.242 +	if (!fp)
 643.243 +	{
 643.244 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
 643.245 +		return;
 643.246 +	}
 643.247 +
 643.248 +	struct
 643.249 +	{
 643.250 +		u8 ident[2];
 643.251 +		u8 filesize[4];
 643.252 +		u8 reserved[4];
 643.253 +		u8 dataoffset[4];
 643.254 +		u8 headersize[4];
 643.255 +		u8 width[4];
 643.256 +		u8 height[4];
 643.257 +		u8 planes[2];
 643.258 +		u8 bitsperpixel[2];
 643.259 +		u8 compression[4];
 643.260 +		u8 datasize[4];
 643.261 +		u8 hres[4];
 643.262 +		u8 vres[4];
 643.263 +		u8 colors[4];
 643.264 +		u8 importantcolors[4];
 643.265 +		u8 pad[2];
 643.266 +	} bmpheader;
 643.267 +	memset(&bmpheader, 0, sizeof(bmpheader));
 643.268 +
 643.269 +	bmpheader.ident[0] = 'B';
 643.270 +	bmpheader.ident[1] = 'M';
 643.271 +
 643.272 +	u32 fsz = sizeof(bmpheader) + w*h*3;
 643.273 +	utilPutDword(bmpheader.filesize, fsz);
 643.274 +	utilPutDword(bmpheader.dataoffset, 0x38);
 643.275 +	utilPutDword(bmpheader.headersize, 0x28);
 643.276 +	utilPutDword(bmpheader.width, w);
 643.277 +	utilPutDword(bmpheader.height, h);
 643.278 +	utilPutDword(bmpheader.planes, 1);
 643.279 +	utilPutDword(bmpheader.bitsperpixel, 24);
 643.280 +	utilPutDword(bmpheader.datasize, 3*w*h);
 643.281 +
 643.282 +	fwrite(&bmpheader, 1, sizeof(bmpheader), fp);
 643.283 +
 643.284 +	u8 *b = writeBuffer;
 643.285 +
 643.286 +	int sizeX = w;
 643.287 +	int sizeY = h;
 643.288 +
 643.289 +	u8 *pixU8 = (u8 *)data+3*w*(h-1);
 643.290 +	for (int y = 0; y < sizeY; y++)
 643.291 +	{
 643.292 +		for (int x = 0; x < sizeX; x++)
 643.293 +		{
 643.294 +			*b++ = *pixU8++; // B
 643.295 +			*b++ = *pixU8++; // G
 643.296 +			*b++ = *pixU8++; // R
 643.297 +		}
 643.298 +		pixU8 -= 2*3*w;
 643.299 +		fwrite(writeBuffer, 1, 3*w, fp);
 643.300 +
 643.301 +		b = writeBuffer;
 643.302 +	}
 643.303 +
 643.304 +	fclose(fp);
 643.305 +}
 643.306 +
 643.307 +void GBOamView::savePNG(const char *name)
 643.308 +{
 643.309 +	u8 writeBuffer[1024 * 3];
 643.310 +
 643.311 +	FILE *fp = fopen(name, "wb");
 643.312 +
 643.313 +	if (!fp)
 643.314 +	{
 643.315 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
 643.316 +		return;
 643.317 +	}
 643.318 +
 643.319 +	png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
 643.320 +	                                              NULL,
 643.321 +	                                              NULL,
 643.322 +	                                              NULL);
 643.323 +	if (!png_ptr)
 643.324 +	{
 643.325 +		fclose(fp);
 643.326 +		return;
 643.327 +	}
 643.328 +
 643.329 +	png_infop info_ptr = png_create_info_struct(png_ptr);
 643.330 +
 643.331 +	if (!info_ptr)
 643.332 +	{
 643.333 +		png_destroy_write_struct(&png_ptr, NULL);
 643.334 +		fclose(fp);
 643.335 +		return;
 643.336 +	}
 643.337 +
 643.338 +	if (setjmp(png_ptr->jmpbuf))
 643.339 +	{
 643.340 +		png_destroy_write_struct(&png_ptr, NULL);
 643.341 +		fclose(fp);
 643.342 +		return;
 643.343 +	}
 643.344 +
 643.345 +	png_init_io(png_ptr, fp);
 643.346 +
 643.347 +	png_set_IHDR(png_ptr,
 643.348 +	             info_ptr,
 643.349 +	             w,
 643.350 +	             h,
 643.351 +	             8,
 643.352 +	             PNG_COLOR_TYPE_RGB,
 643.353 +	             PNG_INTERLACE_NONE,
 643.354 +	             PNG_COMPRESSION_TYPE_DEFAULT,
 643.355 +	             PNG_FILTER_TYPE_DEFAULT);
 643.356 +
 643.357 +	png_write_info(png_ptr, info_ptr);
 643.358 +
 643.359 +	u8 *b = writeBuffer;
 643.360 +
 643.361 +	int sizeX = w;
 643.362 +	int sizeY = h;
 643.363 +
 643.364 +	u8 *pixU8 = (u8 *)data;
 643.365 +	for (int y = 0; y < sizeY; y++)
 643.366 +	{
 643.367 +		for (int x = 0; x < sizeX; x++)
 643.368 +		{
 643.369 +			int blue  = *pixU8++;
 643.370 +			int green = *pixU8++;
 643.371 +			int red   = *pixU8++;
 643.372 +
 643.373 +			*b++ = red;
 643.374 +			*b++ = green;
 643.375 +			*b++ = blue;
 643.376 +		}
 643.377 +		png_write_row(png_ptr, writeBuffer);
 643.378 +
 643.379 +		b = writeBuffer;
 643.380 +	}
 643.381 +
 643.382 +	png_write_end(png_ptr, info_ptr);
 643.383 +
 643.384 +	png_destroy_write_struct(&png_ptr, &info_ptr);
 643.385 +
 643.386 +	fclose(fp);
 643.387 +}
 643.388 +
 643.389 +void GBOamView::save()
 643.390 +{
 643.391 +	CString captureBuffer;
 643.392 +
 643.393 +	if (theApp.captureFormat == 0)
 643.394 +		captureBuffer = "oam.png";
 643.395 +	else
 643.396 +		captureBuffer = "oam.bmp";
 643.397 +
 643.398 +	LPCTSTR exts[] = {".png", ".bmp", NULL };
 643.399 +
 643.400 +	CString filter = winResLoadFilter(IDS_FILTER_PNG);
 643.401 +	CString title  = winResLoadString(IDS_SELECT_CAPTURE_NAME);
 643.402 +
 643.403 +	FileDlg dlg(this,
 643.404 +	            captureBuffer,
 643.405 +	            filter,
 643.406 +	            theApp.captureFormat ? 2 : 1,
 643.407 +	            theApp.captureFormat ? "BMP" : "PNG",
 643.408 +	            exts,
 643.409 +	            "",
 643.410 +	            title,
 643.411 +	            true);
 643.412 +
 643.413 +	if (dlg.DoModal() == IDCANCEL)
 643.414 +	{
 643.415 +		return;
 643.416 +	}
 643.417 +	captureBuffer = dlg.GetPathName();
 643.418 +
 643.419 +	if (dlg.getFilterIndex() == 2)
 643.420 +		saveBMP(captureBuffer);
 643.421 +	else
 643.422 +		savePNG(captureBuffer);
 643.423 +}
 643.424 +
 643.425 +BOOL GBOamView::OnInitDialog()
 643.426 +{
 643.427 +	CDialog::OnInitDialog();
 643.428 +
 643.429 +	DIALOG_SIZER_START(sz)
 643.430 +	DIALOG_SIZER_ENTRY(IDC_OAM_VIEW, DS_SizeX | DS_SizeY)
 643.431 +	DIALOG_SIZER_ENTRY(IDC_OAM_VIEW_ZOOM, DS_MoveX)
 643.432 +	DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
 643.433 +	DIALOG_SIZER_ENTRY(IDC_SAVE,  DS_MoveY)
 643.434 +	DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
 643.435 +	DIALOG_SIZER_ENTRY(IDC_COLOR, DS_MoveY)
 643.436 +	DIALOG_SIZER_ENTRY(IDC_R, DS_MoveY)
 643.437 +	DIALOG_SIZER_ENTRY(IDC_G, DS_MoveY)
 643.438 +	DIALOG_SIZER_ENTRY(IDC_B, DS_MoveY)
 643.439 +	DIALOG_SIZER_END()
 643.440 +	SetData(sz,
 643.441 +	        TRUE,
 643.442 +	        HKEY_CURRENT_USER,
 643.443 +	        "Software\\Emulators\\VisualBoyAdvance\\Viewer\\GBOamView",
 643.444 +	        NULL);
 643.445 +
 643.446 +	m_sprite.SetWindowText("0");
 643.447 +
 643.448 +	updateScrollInfo();
 643.449 +
 643.450 +	m_stretch = regQueryDwordValue("GBOamViewStretch", 0);
 643.451 +	if (m_stretch)
 643.452 +		oamView.setStretch(true);
 643.453 +	UpdateData(FALSE);
 643.454 +
 643.455 +	paint();
 643.456 +
 643.457 +	return TRUE; // return TRUE unless you set the focus to a control
 643.458 +	             // EXCEPTION: OCX Property Pages should return FALSE
 643.459 +}
 643.460 +
 643.461 +void GBOamView::OnStretch()
 643.462 +{
 643.463 +	oamView.setStretch(!oamView.getStretch());
 643.464 +	paint();
 643.465 +	regSetDwordValue("GBOamViewStretch", oamView.getStretch());
 643.466 +}
 643.467 +
 643.468 +void GBOamView::OnAutoUpdate()
 643.469 +{
 643.470 +	autoUpdate = !autoUpdate;
 643.471 +	if (autoUpdate)
 643.472 +	{
 643.473 +		theApp.winAddUpdateListener(this);
 643.474 +	}
 643.475 +	else
 643.476 +	{
 643.477 +		theApp.winRemoveUpdateListener(this);
 643.478 +	}
 643.479 +}
 643.480 +
 643.481 +void GBOamView::OnChangeSprite()
 643.482 +{
 643.483 +	CString buffer;
 643.484 +	m_sprite.GetWindowText(buffer);
 643.485 +	int n = atoi(buffer);
 643.486 +	if (n < 0 || n > 39)
 643.487 +	{
 643.488 +		buffer.Format("%d", number);
 643.489 +		m_sprite.SetWindowText(buffer);
 643.490 +		return;
 643.491 +	}
 643.492 +	number = n;
 643.493 +	paint();
 643.494 +	updateScrollInfo();
 643.495 +}
 643.496 +
 643.497 +void GBOamView::OnClose()
 643.498 +{
 643.499 +	theApp.winRemoveUpdateListener(this);
 643.500 +
 643.501 +	DestroyWindow();
 643.502 +}
 643.503 +
 643.504 +LRESULT GBOamView::OnMapInfo(WPARAM, LPARAM lParam)
 643.505 +{
 643.506 +	u8 *colors = (u8 *)lParam;
 643.507 +	oamZoom.setColors(colors);
 643.508 +
 643.509 +	return TRUE;
 643.510 +}
 643.511 +
 643.512 +LRESULT GBOamView::OnColInfo(WPARAM wParam, LPARAM lParam)
 643.513 +{
 643.514 +	u16 c = (u16)wParam;
 643.515 +
 643.516 +	color.setColor(c);
 643.517 +
 643.518 +	int r = (c & 0x1f);
 643.519 +	int g = (c & 0x3e0) >> 5;
 643.520 +	int b = (c & 0x7c00) >> 10;
 643.521 +
 643.522 +	CString buffer;
 643.523 +	buffer.Format("R: %d", r);
 643.524 +	GetDlgItem(IDC_R)->SetWindowText(buffer);
 643.525 +
 643.526 +	buffer.Format("G: %d", g);
 643.527 +	GetDlgItem(IDC_G)->SetWindowText(buffer);
 643.528 +
 643.529 +	buffer.Format("B: %d", b);
 643.530 +	GetDlgItem(IDC_B)->SetWindowText(buffer);
 643.531 +
 643.532 +	return TRUE;
 643.533 +}
 643.534 +
 643.535 +void GBOamView::updateScrollInfo()
 643.536 +{
 643.537 +	SCROLLINFO si;
 643.538 +	ZeroMemory(&si, sizeof(si));
 643.539 +	si.cbSize = sizeof(si);
 643.540 +	si.fMask  = SIF_PAGE | SIF_RANGE | SIF_DISABLENOSCROLL | SIF_POS;
 643.541 +	si.nMin   = 0;
 643.542 +	si.nMax   = 39;
 643.543 +	si.nPage  = 1;
 643.544 +	si.nPos   = number;
 643.545 +	GetDlgItem(IDC_SCROLLBAR)->SetScrollInfo(SB_CTL,
 643.546 +	                                         &si,
 643.547 +	                                         TRUE);
 643.548 +}
 643.549 +
 643.550 +void GBOamView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar)
 643.551 +{
 643.552 +	switch (nSBCode)
 643.553 +	{
 643.554 +	case SB_BOTTOM:
 643.555 +		number = 39;
 643.556 +		break;
 643.557 +	case SB_LINEDOWN:
 643.558 +		number++;
 643.559 +		if (number > 39)
 643.560 +			number = 39;
 643.561 +		break;
 643.562 +	case SB_LINEUP:
 643.563 +		number--;
 643.564 +		if (number < 0)
 643.565 +			number = 0;
 643.566 +		break;
 643.567 +	case SB_PAGEDOWN:
 643.568 +		number += 16;
 643.569 +		if (number > 39)
 643.570 +			number = 39;
 643.571 +		break;
 643.572 +	case SB_PAGEUP:
 643.573 +		number -= 16;
 643.574 +		if (number < 0)
 643.575 +			number = 0;
 643.576 +		break;
 643.577 +	case SB_TOP:
 643.578 +		number = 0;
 643.579 +		break;
 643.580 +	case SB_THUMBTRACK:
 643.581 +		number = nPos;
 643.582 +		if (number < 0)
 643.583 +			number = 0;
 643.584 +		if (number > 39)
 643.585 +			number = 39;
 643.586 +		break;
 643.587 +	}
 643.588 +
 643.589 +	updateScrollInfo();
 643.590 +
 643.591 +	CString buffer;
 643.592 +	buffer.Format("%d", number);
 643.593 +	m_sprite.SetWindowText(buffer);
 643.594 +	paint();
 643.595 +}
 643.596 +
 643.597 +void GBOamView::PostNcDestroy()
 643.598 +{
 643.599 +	delete this;
 643.600 +}
 643.601 +
   644.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   644.2 +++ b/src/win32/GBOamView.h	Sat Mar 03 10:31:27 2012 -0600
   644.3 @@ -0,0 +1,82 @@
   644.4 +#if !defined(AFX_GBOAMVIEW_H__FE8105E6_9693_479A_8C57_DEEA1B2EA3D6__INCLUDED_)
   644.5 +#define AFX_GBOAMVIEW_H__FE8105E6_9693_479A_8C57_DEEA1B2EA3D6__INCLUDED_
   644.6 +
   644.7 +#if _MSC_VER > 1000
   644.8 +#pragma once
   644.9 +#endif // _MSC_VER > 1000
  644.10 +// -*- C++ -*-
  644.11 +// GBOamView.h : header file
  644.12 +//
  644.13 +
  644.14 +#include "BitmapControl.h"
  644.15 +#include "ZoomControl.h"
  644.16 +#include "ColorControl.h"
  644.17 +
  644.18 +#include "IUpdate.h"
  644.19 +#include "ResizeDlg.h"
  644.20 +
  644.21 +/////////////////////////////////////////////////////////////////////////////
  644.22 +// GBOamView dialog
  644.23 +
  644.24 +class GBOamView : public ResizeDlg, IUpdateListener
  644.25 +{
  644.26 +private:
  644.27 +	BITMAPINFO    bmpInfo;
  644.28 +	u8 *          data;
  644.29 +	int           w;
  644.30 +	int           h;
  644.31 +	int           number;
  644.32 +	bool          autoUpdate;
  644.33 +	BitmapControl oamView;
  644.34 +	ZoomControl   oamZoom;
  644.35 +	ColorControl  color;
  644.36 +
  644.37 +	// Construction
  644.38 +public:
  644.39 +	void updateScrollInfo();
  644.40 +	void save();
  644.41 +	void savePNG(const char *name);
  644.42 +	void saveBMP(const char *name);
  644.43 +	void render();
  644.44 +	void setAttributes(int y, int x, int tile, int flags);
  644.45 +	void paint();
  644.46 +	~GBOamView();
  644.47 +	GBOamView(CWnd*pParent = NULL);  // standard constructor
  644.48 +
  644.49 +	afx_msg LRESULT OnColInfo(WPARAM wParam, LPARAM lParam);
  644.50 +	afx_msg LRESULT OnMapInfo(WPARAM wParam, LPARAM lParam);
  644.51 +	virtual void update();
  644.52 +
  644.53 +	// Dialog Data
  644.54 +	//{{AFX_DATA(GBOamView)
  644.55 +	enum { IDD = IDD_GB_OAM_VIEW };
  644.56 +	CEdit m_sprite;
  644.57 +	BOOL  m_stretch;
  644.58 +	//}}AFX_DATA
  644.59 +
  644.60 +	// Overrides
  644.61 +	// ClassWizard generated virtual function overrides
  644.62 +	//{{AFX_VIRTUAL(GBOamView)
  644.63 +protected:
  644.64 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  644.65 +	virtual void PostNcDestroy();
  644.66 +	//}}AFX_VIRTUAL
  644.67 +
  644.68 +	// Implementation
  644.69 +protected:
  644.70 +	// Generated message map functions
  644.71 +	//{{AFX_MSG(GBOamView)
  644.72 +	virtual BOOL OnInitDialog();
  644.73 +	afx_msg void OnStretch();
  644.74 +	afx_msg void OnAutoUpdate();
  644.75 +	afx_msg void OnChangeSprite();
  644.76 +	afx_msg void OnClose();
  644.77 +	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar);
  644.78 +	//}}AFX_MSG
  644.79 +	DECLARE_MESSAGE_MAP()
  644.80 +};
  644.81 +
  644.82 +//{{AFX_INSERT_LOCATION}}
  644.83 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  644.84 +
  644.85 +#endif // !defined(AFX_GBOAMVIEW_H__FE8105E6_9693_479A_8C57_DEEA1B2EA3D6__INCLUDED_)
   645.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   645.2 +++ b/src/win32/GBPaletteView.cpp	Sat Mar 03 10:31:27 2012 -0600
   645.3 @@ -0,0 +1,219 @@
   645.4 +// GBPaletteView.cpp : implementation file
   645.5 +//
   645.6 +
   645.7 +#include "stdafx.h"
   645.8 +#include "resource.h"
   645.9 +#include "GBPaletteView.h"
  645.10 +#include "FileDlg.h"
  645.11 +#include "WinResUtil.h"
  645.12 +#include "VBA.h"
  645.13 +
  645.14 +#include "../gb/gbGlobals.h"
  645.15 +
  645.16 +void GBPaletteViewControl::updatePalette()
  645.17 +{
  645.18 +	if (gbRom)
  645.19 +	{
  645.20 +		memcpy(palette, &gbPalette[paletteAddress], 64);
  645.21 +	}
  645.22 +}
  645.23 +
  645.24 +/////////////////////////////////////////////////////////////////////////////
  645.25 +// GBPaletteView dialog
  645.26 +
  645.27 +GBPaletteView::GBPaletteView(CWnd*pParent /*=NULL*/)
  645.28 +	: ResizeDlg(GBPaletteView::IDD, pParent)
  645.29 +{
  645.30 +	//{{AFX_DATA_INIT(GBPaletteView)
  645.31 +	// NOTE: the ClassWizard will add member initialization here
  645.32 +	//}}AFX_DATA_INIT
  645.33 +	autoUpdate = false;
  645.34 +}
  645.35 +
  645.36 +GBPaletteView::~GBPaletteView()
  645.37 +{}
  645.38 +
  645.39 +void GBPaletteView::DoDataExchange(CDataExchange*pDX)
  645.40 +{
  645.41 +	CDialog::DoDataExchange(pDX);
  645.42 +	//{{AFX_DATA_MAP(GBPaletteView)
  645.43 +	// NOTE: the ClassWizard will add DDX and DDV calls here
  645.44 +	//}}AFX_DATA_MAP
  645.45 +	DDX_Control(pDX, IDC_PALETTE_VIEW, paletteView);
  645.46 +	DDX_Control(pDX, IDC_PALETTE_VIEW_OBJ, paletteViewOBJ);
  645.47 +	DDX_Control(pDX, IDC_COLOR, colorControl);
  645.48 +}
  645.49 +
  645.50 +BEGIN_MESSAGE_MAP(GBPaletteView, CDialog)
  645.51 +//{{AFX_MSG_MAP(GBPaletteView)
  645.52 +ON_BN_CLICKED(IDC_SAVE_BG, OnSaveBg)
  645.53 +ON_BN_CLICKED(IDC_SAVE_OBJ, OnSaveObj)
  645.54 +ON_BN_CLICKED(IDC_REFRESH2, OnRefresh2)
  645.55 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
  645.56 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
  645.57 +//}}AFX_MSG_MAP
  645.58 +ON_MESSAGE(WM_PALINFO, OnPalInfo)
  645.59 +END_MESSAGE_MAP()
  645.60 +
  645.61 +/////////////////////////////////////////////////////////////////////////////
  645.62 +// GBPaletteView message handlers
  645.63 +
  645.64 +BOOL GBPaletteView::OnInitDialog()
  645.65 +{
  645.66 +	CDialog::OnInitDialog();
  645.67 +
  645.68 +	DIALOG_SIZER_START(sz)
  645.69 +	DIALOG_SIZER_END()
  645.70 +    SetData(sz,
  645.71 +            FALSE,
  645.72 +            HKEY_CURRENT_USER,
  645.73 +            "Software\\Emulators\\VisualBoyAdvance\\Viewer\\GBPaletteView",
  645.74 +            NULL);
  645.75 +
  645.76 +	paletteView.init(32, 64, 128);
  645.77 +	paletteViewOBJ.init(32, 64, 128);
  645.78 +
  645.79 +	paletteView.setPaletteAddress(0);
  645.80 +	paletteView.refresh();
  645.81 +
  645.82 +	paletteViewOBJ.setPaletteAddress(32);
  645.83 +	paletteViewOBJ.refresh();
  645.84 +
  645.85 +	return TRUE; // return TRUE unless you set the focus to a control
  645.86 +	             // EXCEPTION: OCX Property Pages should return FALSE
  645.87 +}
  645.88 +
  645.89 +void GBPaletteView::save(int which)
  645.90 +{
  645.91 +	CString captureBuffer;
  645.92 +
  645.93 +	if (which == 0)
  645.94 +		captureBuffer = "bg.pal";
  645.95 +	else
  645.96 +		captureBuffer = "obj.pal";
  645.97 +
  645.98 +	LPCTSTR exts[] = {".pal", ".pal", ".act", NULL };
  645.99 +
 645.100 +	CString filter = winResLoadFilter(IDS_FILTER_PAL);
 645.101 +	CString title  = winResLoadString(IDS_SELECT_PALETTE_NAME);
 645.102 +	FileDlg dlg(this,
 645.103 +	            captureBuffer,
 645.104 +	            filter,
 645.105 +	            1,
 645.106 +	            "PAL",
 645.107 +	            exts,
 645.108 +	            "",
 645.109 +	            title,
 645.110 +	            true);
 645.111 +
 645.112 +	if (dlg.DoModal() == IDCANCEL)
 645.113 +	{
 645.114 +		return;
 645.115 +	}
 645.116 +
 645.117 +	PaletteViewControl *p = NULL;
 645.118 +
 645.119 +	if (which == 0)
 645.120 +		p = &paletteView;
 645.121 +	else
 645.122 +		p = &paletteViewOBJ;
 645.123 +
 645.124 +	switch (dlg.getFilterIndex())
 645.125 +	{
 645.126 +	case 0:
 645.127 +	case 1:
 645.128 +		p->saveMSPAL(captureBuffer);
 645.129 +		break;
 645.130 +	case 2:
 645.131 +		p->saveJASCPAL(captureBuffer);
 645.132 +		break;
 645.133 +	case 3:
 645.134 +		p->saveAdobe(captureBuffer);
 645.135 +		break;
 645.136 +	}
 645.137 +}
 645.138 +
 645.139 +void GBPaletteView::OnSaveBg()
 645.140 +{
 645.141 +	save(0);
 645.142 +}
 645.143 +
 645.144 +void GBPaletteView::OnSaveObj()
 645.145 +{
 645.146 +	save(1);
 645.147 +}
 645.148 +
 645.149 +void GBPaletteView::OnRefresh2()
 645.150 +{
 645.151 +	paletteView.refresh();
 645.152 +	paletteViewOBJ.refresh();
 645.153 +}
 645.154 +
 645.155 +void GBPaletteView::update()
 645.156 +{
 645.157 +	OnRefresh2();
 645.158 +}
 645.159 +
 645.160 +void GBPaletteView::OnAutoUpdate()
 645.161 +{
 645.162 +	autoUpdate = !autoUpdate;
 645.163 +	if (autoUpdate)
 645.164 +	{
 645.165 +		theApp.winAddUpdateListener(this);
 645.166 +	}
 645.167 +	else
 645.168 +	{
 645.169 +		theApp.winRemoveUpdateListener(this);
 645.170 +	}
 645.171 +}
 645.172 +
 645.173 +void GBPaletteView::OnClose()
 645.174 +{
 645.175 +	theApp.winRemoveUpdateListener(this);
 645.176 +
 645.177 +	DestroyWindow();
 645.178 +}
 645.179 +
 645.180 +LRESULT GBPaletteView::OnPalInfo(WPARAM wParam, LPARAM lParam)
 645.181 +{
 645.182 +	u16     color   = (u16)wParam;
 645.183 +	u32     address = (u32)lParam;
 645.184 +	CString buffer;
 645.185 +
 645.186 +	bool isOBJ = address >= 32;
 645.187 +	address &= 31;
 645.188 +
 645.189 +	buffer.Format("%d", address);
 645.190 +	GetDlgItem(IDC_ADDRESS)->SetWindowText(buffer);
 645.191 +
 645.192 +	int r = (color & 0x1f);
 645.193 +	int g = (color & 0x3e0) >> 5;
 645.194 +	int b = (color & 0x7c00) >> 10;
 645.195 +
 645.196 +	buffer.Format("%d", r);
 645.197 +	GetDlgItem(IDC_R)->SetWindowText(buffer);
 645.198 +
 645.199 +	buffer.Format("%d", g);
 645.200 +	GetDlgItem(IDC_G)->SetWindowText(buffer);
 645.201 +
 645.202 +	buffer.Format("%d", b);
 645.203 +	GetDlgItem(IDC_B)->SetWindowText(buffer);
 645.204 +
 645.205 +	buffer.Format("0x%04X", color);
 645.206 +	GetDlgItem(IDC_VALUE)->SetWindowText(buffer);
 645.207 +
 645.208 +	colorControl.setColor(color);
 645.209 +
 645.210 +	if (isOBJ)
 645.211 +		paletteView.setSelected(-1);
 645.212 +	else
 645.213 +		paletteViewOBJ.setSelected(-1);
 645.214 +
 645.215 +	return TRUE;
 645.216 +}
 645.217 +
 645.218 +void GBPaletteView::PostNcDestroy()
 645.219 +{
 645.220 +	delete this;
 645.221 +}
 645.222 +
   646.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   646.2 +++ b/src/win32/GBPaletteView.h	Sat Mar 03 10:31:27 2012 -0600
   646.3 @@ -0,0 +1,72 @@
   646.4 +#if !defined(AFX_GBPALETTEVIEW_H__F909FF55_3021_4301_B017_0C2C9D8D8C08__INCLUDED_)
   646.5 +#define AFX_GBPALETTEVIEW_H__F909FF55_3021_4301_B017_0C2C9D8D8C08__INCLUDED_
   646.6 +
   646.7 +#if _MSC_VER > 1000
   646.8 +#pragma once
   646.9 +#endif // _MSC_VER > 1000
  646.10 +// -*- C++ -*-
  646.11 +// GBPaletteView.h : header file
  646.12 +//
  646.13 +
  646.14 +#include "ColorControl.h"
  646.15 +#include "IUpdate.h"
  646.16 +#include "PaletteViewControl.h"
  646.17 +#include "ResizeDlg.h"
  646.18 +
  646.19 +class GBPaletteViewControl : public PaletteViewControl
  646.20 +{
  646.21 +public:
  646.22 +	virtual void updatePalette();
  646.23 +};
  646.24 +
  646.25 +/////////////////////////////////////////////////////////////////////////////
  646.26 +// GBPaletteView dialog
  646.27 +
  646.28 +class GBPaletteView : public ResizeDlg, IUpdateListener
  646.29 +{
  646.30 +private:
  646.31 +	GBPaletteViewControl paletteView;
  646.32 +	GBPaletteViewControl paletteViewOBJ;
  646.33 +	ColorControl         colorControl;
  646.34 +	bool autoUpdate;
  646.35 +	// Construction
  646.36 +public:
  646.37 +	void save(int which);
  646.38 +	GBPaletteView(CWnd*pParent = NULL);  // standard constructor
  646.39 +	virtual ~GBPaletteView();
  646.40 +
  646.41 +	// Dialog Data
  646.42 +	//{{AFX_DATA(GBPaletteView)
  646.43 +	enum { IDD = IDD_GB_PALETTE_VIEW };
  646.44 +	// NOTE: the ClassWizard will add data members here
  646.45 +	//}}AFX_DATA
  646.46 +
  646.47 +	// Overrides
  646.48 +	// ClassWizard generated virtual function overrides
  646.49 +	//{{AFX_VIRTUAL(GBPaletteView)
  646.50 +protected:
  646.51 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  646.52 +	virtual void PostNcDestroy();
  646.53 +	//}}AFX_VIRTUAL
  646.54 +
  646.55 +	virtual void update();
  646.56 +
  646.57 +	// Implementation
  646.58 +protected:
  646.59 +	afx_msg virtual LRESULT OnPalInfo(WPARAM wParam, LPARAM lParam);
  646.60 +	// Generated message map functions
  646.61 +	//{{AFX_MSG(GBPaletteView)
  646.62 +	virtual BOOL OnInitDialog();
  646.63 +	afx_msg void OnSaveBg();
  646.64 +	afx_msg void OnSaveObj();
  646.65 +	afx_msg void OnRefresh2();
  646.66 +	afx_msg void OnAutoUpdate();
  646.67 +	afx_msg void OnClose();
  646.68 +	//}}AFX_MSG
  646.69 +	DECLARE_MESSAGE_MAP()
  646.70 +};
  646.71 +
  646.72 +//{{AFX_INSERT_LOCATION}}
  646.73 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  646.74 +
  646.75 +#endif // !defined(AFX_GBPALETTEVIEW_H__F909FF55_3021_4301_B017_0C2C9D8D8C08__INCLUDED_)
   647.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   647.2 +++ b/src/win32/GBPrinterDlg.cpp	Sat Mar 03 10:31:27 2012 -0600
   647.3 @@ -0,0 +1,485 @@
   647.4 +// GBPrinter.cpp : implementation file
   647.5 +//
   647.6 +
   647.7 +#include "stdafx.h"
   647.8 +#include "resource.h"
   647.9 +#include "GBPrinterDlg.h"
  647.10 +#include "FileDlg.h"
  647.11 +#include "Reg.h"
  647.12 +#include "WinResUtil.h"
  647.13 +#include "VBA.h"
  647.14 +
  647.15 +//#include "../common/System.h"
  647.16 +#include "../NLS.h"
  647.17 +#include "../common/Util.h"
  647.18 +
  647.19 +extern "C" {
  647.20 +#include <png.h>
  647.21 +}
  647.22 +
  647.23 +/////////////////////////////////////////////////////////////////////////////
  647.24 +// GBPrinter dialog
  647.25 +
  647.26 +GBPrinterDlg::GBPrinterDlg(CWnd*pParent /*=NULL*/)
  647.27 +	: CDialog(GBPrinterDlg::IDD, pParent)
  647.28 +{
  647.29 +	//{{AFX_DATA_INIT(GBPrinterDlg)
  647.30 +	m_scale = -1;
  647.31 +	//}}AFX_DATA_INIT
  647.32 +	bitmap = (BITMAPINFO *)bitmapHeader;
  647.33 +
  647.34 +	bitmap->bmiHeader.biSize            = sizeof(BITMAPINFOHEADER);
  647.35 +	bitmap->bmiHeader.biWidth           = 160;
  647.36 +	bitmap->bmiHeader.biHeight          = -144;
  647.37 +	bitmap->bmiHeader.biPlanes          = 1;
  647.38 +	bitmap->bmiHeader.biBitCount        = 8;
  647.39 +	bitmap->bmiHeader.biCompression     = BI_RGB;
  647.40 +	bitmap->bmiHeader.biSizeImage       = 160*144;
  647.41 +	bitmap->bmiHeader.biXPelsPerMeter   = 0;
  647.42 +	bitmap->bmiHeader.biYPelsPerMeter   = 0;
  647.43 +	bitmap->bmiHeader.biClrUsed         = 4;
  647.44 +	bitmap->bmiHeader.biClrImportant    = 4;
  647.45 +	bitmap->bmiColors[0].rgbBlue        =
  647.46 +	    bitmap->bmiColors[0].rgbGreen   =
  647.47 +	        bitmap->bmiColors[0].rgbRed =
  647.48 +	            255;
  647.49 +	bitmap->bmiColors[0].rgbReserved    = 0;
  647.50 +	bitmap->bmiColors[1].rgbBlue        =
  647.51 +	    bitmap->bmiColors[1].rgbGreen   =
  647.52 +	        bitmap->bmiColors[1].rgbRed =
  647.53 +	            168;
  647.54 +	bitmap->bmiColors[1].rgbReserved    = 0;
  647.55 +	bitmap->bmiColors[2].rgbBlue        =
  647.56 +	    bitmap->bmiColors[2].rgbGreen   =
  647.57 +	        bitmap->bmiColors[2].rgbRed =
  647.58 +	            96;
  647.59 +	bitmap->bmiColors[2].rgbReserved    = 0;
  647.60 +	bitmap->bmiColors[3].rgbBlue        =
  647.61 +	    bitmap->bmiColors[3].rgbGreen   =
  647.62 +	        bitmap->bmiColors[3].rgbRed =
  647.63 +	            0;
  647.64 +	bitmap->bmiColors[3].rgbReserved = 0;
  647.65 +}
  647.66 +
  647.67 +void GBPrinterDlg::DoDataExchange(CDataExchange*pDX)
  647.68 +{
  647.69 +	CDialog::DoDataExchange(pDX);
  647.70 +	//{{AFX_DATA_MAP(GBPrinterDlg)
  647.71 +	DDX_Radio(pDX, IDC_1X, m_scale);
  647.72 +	//}}AFX_DATA_MAP
  647.73 +}
  647.74 +
  647.75 +BEGIN_MESSAGE_MAP(GBPrinterDlg, CDialog)
  647.76 +//{{AFX_MSG_MAP(GBPrinterDlg)
  647.77 +ON_BN_CLICKED(ID_SAVE, OnSave)
  647.78 +ON_BN_CLICKED(ID_PRINT, OnPrint)
  647.79 +ON_BN_CLICKED(ID_OK, OnOk)
  647.80 +ON_BN_CLICKED(IDC_1X, On1x)
  647.81 +ON_BN_CLICKED(IDC_2X, On2x)
  647.82 +ON_BN_CLICKED(IDC_3X, On3x)
  647.83 +ON_BN_CLICKED(IDC_4X, On4x)
  647.84 +ON_WM_PAINT()
  647.85 +//}}AFX_MSG_MAP
  647.86 +END_MESSAGE_MAP()
  647.87 +
  647.88 +/////////////////////////////////////////////////////////////////////////////
  647.89 +// GBPrinter message handlers
  647.90 +
  647.91 +void GBPrinterDlg::saveAsBMP(const char *name)
  647.92 +{
  647.93 +	u8 writeBuffer[512 * 3];
  647.94 +
  647.95 +	FILE *fp = fopen(name, "wb");
  647.96 +
  647.97 +	if (!fp)
  647.98 +	{
  647.99 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
 647.100 +		return;
 647.101 +	}
 647.102 +
 647.103 +	struct
 647.104 +	{
 647.105 +		u8 ident[2];
 647.106 +		u8 filesize[4];
 647.107 +		u8 reserved[4];
 647.108 +		u8 dataoffset[4];
 647.109 +		u8 headersize[4];
 647.110 +		u8 width[4];
 647.111 +		u8 height[4];
 647.112 +		u8 planes[2];
 647.113 +		u8 bitsperpixel[2];
 647.114 +		u8 compression[4];
 647.115 +		u8 datasize[4];
 647.116 +		u8 hres[4];
 647.117 +		u8 vres[4];
 647.118 +		u8 colors[4];
 647.119 +		u8 importantcolors[4];
 647.120 +		u8 pad[2];
 647.121 +	} bmpheader;
 647.122 +	memset(&bmpheader, 0, sizeof(bmpheader));
 647.123 +
 647.124 +	bmpheader.ident[0] = 'B';
 647.125 +	bmpheader.ident[1] = 'M';
 647.126 +
 647.127 +	u32 fsz = sizeof(bmpheader) + 160*144*3;
 647.128 +	utilPutDword(bmpheader.filesize, fsz);
 647.129 +	utilPutDword(bmpheader.dataoffset, 0x38);
 647.130 +	utilPutDword(bmpheader.headersize, 0x28);
 647.131 +	utilPutDword(bmpheader.width, 160);
 647.132 +	utilPutDword(bmpheader.height, 144);
 647.133 +	utilPutDword(bmpheader.planes, 1);
 647.134 +	utilPutDword(bmpheader.bitsperpixel, 24);
 647.135 +	utilPutDword(bmpheader.datasize, 160*144);
 647.136 +
 647.137 +	fwrite(&bmpheader, 1, sizeof(bmpheader), fp);
 647.138 +
 647.139 +	u8 *b    = writeBuffer;
 647.140 +	u8 *data = (u8 *)bitmapData;
 647.141 +	u8 *p    = data + (160*143);
 647.142 +	for (int y = 0; y < 144; y++)
 647.143 +	{
 647.144 +		for (int x = 0; x < 160; x++)
 647.145 +		{
 647.146 +			u8 c = *p++;
 647.147 +
 647.148 +			*b++ = bitmap->bmiColors[c].rgbBlue;
 647.149 +			*b++ = bitmap->bmiColors[c].rgbGreen;
 647.150 +			*b++ = bitmap->bmiColors[c].rgbRed;
 647.151 +		}
 647.152 +		p -= 2*(160);
 647.153 +		fwrite(writeBuffer, 1, 3*160, fp);
 647.154 +
 647.155 +		b = writeBuffer;
 647.156 +	}
 647.157 +
 647.158 +	fclose(fp);
 647.159 +}
 647.160 +
 647.161 +void GBPrinterDlg::saveAsPNG(const char *name)
 647.162 +{
 647.163 +	u8 writeBuffer[160 * 3];
 647.164 +
 647.165 +	FILE *fp = fopen(name, "wb");
 647.166 +
 647.167 +	if (!fp)
 647.168 +	{
 647.169 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s",
 647.170 +		              name);
 647.171 +		return;
 647.172 +	}
 647.173 +
 647.174 +	png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
 647.175 +	                                              NULL,
 647.176 +	                                              NULL,
 647.177 +	                                              NULL);
 647.178 +	if (!png_ptr)
 647.179 +	{
 647.180 +		fclose(fp);
 647.181 +		return;
 647.182 +	}
 647.183 +
 647.184 +	png_infop info_ptr = png_create_info_struct(png_ptr);
 647.185 +
 647.186 +	if (!info_ptr)
 647.187 +	{
 647.188 +		png_destroy_write_struct(&png_ptr, NULL);
 647.189 +		fclose(fp);
 647.190 +		return;
 647.191 +	}
 647.192 +
 647.193 +	if (setjmp(png_ptr->jmpbuf))
 647.194 +	{
 647.195 +		png_destroy_write_struct(&png_ptr, NULL);
 647.196 +		fclose(fp);
 647.197 +		return;
 647.198 +	}
 647.199 +
 647.200 +	png_init_io(png_ptr, fp);
 647.201 +
 647.202 +	png_set_IHDR(png_ptr,
 647.203 +	             info_ptr,
 647.204 +	             160,
 647.205 +	             144,
 647.206 +	             8,
 647.207 +	             PNG_COLOR_TYPE_RGB,
 647.208 +	             PNG_INTERLACE_NONE,
 647.209 +	             PNG_COMPRESSION_TYPE_DEFAULT,
 647.210 +	             PNG_FILTER_TYPE_DEFAULT);
 647.211 +
 647.212 +	png_write_info(png_ptr, info_ptr);
 647.213 +
 647.214 +	u8 *b = writeBuffer;
 647.215 +
 647.216 +	int sizeX = 160;
 647.217 +	int sizeY = 144;
 647.218 +
 647.219 +	u8 *pixU8 = (u8 *)bitmapData;
 647.220 +	for (int y = 0; y < sizeY; y++)
 647.221 +	{
 647.222 +		for (int x = 0; x < sizeX; x++)
 647.223 +		{
 647.224 +			u8 c = *pixU8++;
 647.225 +			*b++ = bitmap->bmiColors[c].rgbRed;
 647.226 +			*b++ = bitmap->bmiColors[c].rgbGreen;
 647.227 +			*b++ = bitmap->bmiColors[c].rgbBlue;
 647.228 +		}
 647.229 +		png_write_row(png_ptr, writeBuffer);
 647.230 +
 647.231 +		b = writeBuffer;
 647.232 +	}
 647.233 +
 647.234 +	png_write_end(png_ptr, info_ptr);
 647.235 +
 647.236 +	png_destroy_write_struct(&png_ptr, &info_ptr);
 647.237 +
 647.238 +	fclose(fp);
 647.239 +}
 647.240 +
 647.241 +void GBPrinterDlg::OnSave()
 647.242 +{
 647.243 +	CString captureBuffer;
 647.244 +
 647.245 +	if (theApp.captureFormat == 0)
 647.246 +		captureBuffer = "printer.png";
 647.247 +	else
 647.248 +		captureBuffer = "printer.bmp";
 647.249 +
 647.250 +	LPCTSTR exts[] = {".png", ".bmp", NULL };
 647.251 +
 647.252 +	CString filter = winResLoadFilter(IDS_FILTER_PNG);
 647.253 +	CString title  = winResLoadString(IDS_SELECT_CAPTURE_NAME);
 647.254 +
 647.255 +	FileDlg dlg(this,
 647.256 +	            captureBuffer,
 647.257 +	            filter,
 647.258 +	            theApp.captureFormat ? 2 : 1,
 647.259 +	            theApp.captureFormat ? "BMP" : "PNG",
 647.260 +	            exts,
 647.261 +	            "",
 647.262 +	            title,
 647.263 +	            true);
 647.264 +
 647.265 +	if (dlg.DoModal() == IDCANCEL)
 647.266 +	{
 647.267 +		return;
 647.268 +	}
 647.269 +
 647.270 +	captureBuffer = dlg.GetPathName();
 647.271 +
 647.272 +	if (dlg.getFilterIndex() == 2)
 647.273 +		saveAsBMP(captureBuffer);
 647.274 +	else
 647.275 +		saveAsPNG(captureBuffer);
 647.276 +}
 647.277 +
 647.278 +void GBPrinterDlg::OnPrint()
 647.279 +{
 647.280 +	CPrintDialog dlg(FALSE);
 647.281 +
 647.282 +	dlg.m_pd.nFromPage = 1;
 647.283 +	dlg.m_pd.nToPage   = 1;
 647.284 +	dlg.m_pd.nMinPage  = 1;
 647.285 +	dlg.m_pd.nMaxPage  = 1;
 647.286 +	dlg.m_pd.nCopies   = 1;
 647.287 +
 647.288 +	if (dlg.DoModal() == IDOK)
 647.289 +	{
 647.290 +		DOCINFO di;
 647.291 +		float   fLogPelsX1 = 0;
 647.292 +		float   fLogPelsX2 = 0;
 647.293 +		float   fLogPelsY1 = 0;
 647.294 +		float   fLogPelsY2 = 0;
 647.295 +		float   fScaleX    = 0, fScaleY = 0;
 647.296 +		CDC *   winDC      = NULL;
 647.297 +		memset(&di, 0, sizeof(di));
 647.298 +		di.cbSize = sizeof(DOCINFO);
 647.299 +		CString docName = winResLoadString(IDS_POCKET_PRINTER);
 647.300 +		di.lpszDocName = docName;
 647.301 +		CDC dc;
 647.302 +		dc.Attach(dlg.GetPrinterDC());
 647.303 +		int nError = dc.StartDoc(&di);
 647.304 +
 647.305 +		if (nError == SP_ERROR)
 647.306 +		{
 647.307 +			systemMessage(IDS_ERROR_ON_STARTDOC, "Error on StartDoc");
 647.308 +			goto error;
 647.309 +		}
 647.310 +		nError = dc.StartPage();
 647.311 +		if (nError <= 0)
 647.312 +		{
 647.313 +			systemMessage(IDS_ERROR_ON_STARTPAGE, "Error on StartPage");
 647.314 +			goto error;
 647.315 +		}
 647.316 +
 647.317 +		winDC      = GetDC();
 647.318 +		fLogPelsX1 = (float)winDC->GetDeviceCaps(LOGPIXELSX);
 647.319 +		fLogPelsY1 = (float)winDC->GetDeviceCaps(LOGPIXELSY);
 647.320 +		ReleaseDC(winDC);
 647.321 +
 647.322 +		fLogPelsX2 = (float)dc.GetDeviceCaps(LOGPIXELSX);
 647.323 +		fLogPelsY2 = (float)dc.GetDeviceCaps(LOGPIXELSY);
 647.324 +
 647.325 +		if (fLogPelsX1 > fLogPelsX2)
 647.326 +			fScaleX = fLogPelsX1 / fLogPelsX2;
 647.327 +		else
 647.328 +			fScaleX = fLogPelsX2 / fLogPelsX1;
 647.329 +
 647.330 +		if (fLogPelsY1 > fLogPelsY2)
 647.331 +			fScaleY = fLogPelsY1 / fLogPelsY2;
 647.332 +		else
 647.333 +			fScaleY = fLogPelsY2 / fLogPelsY1;
 647.334 +
 647.335 +		fScaleX *= (scale+1);
 647.336 +		fScaleY *= (scale+1);
 647.337 +
 647.338 +		if (StretchDIBits(dc,
 647.339 +		                  0,
 647.340 +		                  0,
 647.341 +		                  (int)((float)160*fScaleX),
 647.342 +		                  (int)((float)144*fScaleY),
 647.343 +		                  0,
 647.344 +		                  0,
 647.345 +		                  160,
 647.346 +		                  144,
 647.347 +		                  bitmapData,
 647.348 +		                  bitmap,
 647.349 +		                  DIB_RGB_COLORS,
 647.350 +		                  SRCCOPY) == GDI_ERROR)
 647.351 +		{
 647.352 +			systemMessage(IDS_ERROR_PRINTING_ON_STRETCH,
 647.353 +			              "Error printing on StretchDIBits");
 647.354 +		}
 647.355 +
 647.356 +		nError = dc.EndPage();
 647.357 +
 647.358 +		if (nError <= 0)
 647.359 +		{
 647.360 +			systemMessage(IDS_ERROR_ON_ENDPAGE, "Error on EndPage");
 647.361 +			goto error;
 647.362 +		}
 647.363 +
 647.364 +		nError = dc.EndDoc();
 647.365 +
 647.366 +		if (nError <= 0)
 647.367 +			systemMessage(IDS_ERROR_ON_ENDDOC, "Error on EndDoc");
 647.368 +error:
 647.369 +		dc.DeleteDC();
 647.370 +	}
 647.371 +}
 647.372 +
 647.373 +void GBPrinterDlg::processData(u8 *data)
 647.374 +{
 647.375 +	for (int y = 0; y < 0x12; y++)
 647.376 +	{
 647.377 +		for (int x = 0; x < 0x14; x++)
 647.378 +		{
 647.379 +			for (int k = 0; k < 8; k++)
 647.380 +			{
 647.381 +				int a = *data++;
 647.382 +				int b = *data++;
 647.383 +				for (int j = 0; j < 8; j++)
 647.384 +				{
 647.385 +					int mask = 1 << (7-j);
 647.386 +					int c    = 0;
 647.387 +					if (a & mask)
 647.388 +						c++;
 647.389 +					if (b & mask)
 647.390 +						c += 2;
 647.391 +					bitmapData[x*8+j + 160*(y*8+k)] = c;
 647.392 +				}
 647.393 +			}
 647.394 +		}
 647.395 +	}
 647.396 +}
 647.397 +
 647.398 +BOOL GBPrinterDlg::OnInitDialog()
 647.399 +{
 647.400 +	CDialog::OnInitDialog();
 647.401 +
 647.402 +	scale = regQueryDwordValue("printerScale", 0);
 647.403 +	if (scale < 0 || scale > 3)
 647.404 +		scale = 0;
 647.405 +	m_scale = scale;
 647.406 +	UpdateData(FALSE);
 647.407 +
 647.408 +	CenterWindow();
 647.409 +
 647.410 +	return TRUE; // return TRUE unless you set the focus to a control
 647.411 +	             // EXCEPTION: OCX Property Pages should return FALSE
 647.412 +}
 647.413 +
 647.414 +void GBPrinterDlg::OnOk()
 647.415 +{
 647.416 +	EndDialog(TRUE);
 647.417 +}
 647.418 +
 647.419 +void GBPrinterDlg::On1x()
 647.420 +{
 647.421 +	regSetDwordValue("printerScale", 0);
 647.422 +	scale = 0;
 647.423 +}
 647.424 +
 647.425 +void GBPrinterDlg::On2x()
 647.426 +{
 647.427 +	regSetDwordValue("printerScale", 1);
 647.428 +	scale = 1;
 647.429 +}
 647.430 +
 647.431 +void GBPrinterDlg::On3x()
 647.432 +{
 647.433 +	regSetDwordValue("printerScale", 2);
 647.434 +	scale = 2;
 647.435 +}
 647.436 +
 647.437 +void GBPrinterDlg::On4x()
 647.438 +{
 647.439 +	regSetDwordValue("printerScale", 3);
 647.440 +	scale = 3;
 647.441 +}
 647.442 +
 647.443 +void GBPrinterDlg::OnPaint()
 647.444 +{
 647.445 +	CPaintDC dc(this); // device context for painting
 647.446 +
 647.447 +	RECT  rect;
 647.448 +	CWnd *h = GetDlgItem(IDC_GB_PRINTER);
 647.449 +	h->GetWindowRect(&rect);
 647.450 +	POINT p;
 647.451 +	p.x = rect.left;
 647.452 +	p.y = rect.top;
 647.453 +	ScreenToClient((POINT *)&p);
 647.454 +	rect.left = p.x+1;
 647.455 +	rect.top  = p.y+1;
 647.456 +	p.x       = rect.right;
 647.457 +	p.y       = rect.bottom;
 647.458 +	ScreenToClient((POINT *)&p);
 647.459 +	rect.right  = p.x-1;
 647.460 +	rect.bottom = p.y-1;
 647.461 +
 647.462 +	StretchDIBits(dc,
 647.463 +	              rect.left,
 647.464 +	              rect.top,
 647.465 +	              rect.right - rect.left,
 647.466 +	              rect.bottom - rect.top,
 647.467 +	              0,
 647.468 +	              0,
 647.469 +	              160,
 647.470 +	              144,
 647.471 +	              bitmapData,
 647.472 +	              bitmap,
 647.473 +	              DIB_RGB_COLORS,
 647.474 +	              SRCCOPY);
 647.475 +}
 647.476 +
 647.477 +void systemGbPrint(u8 *data,
 647.478 +                   int pages,
 647.479 +                   int feed,
 647.480 +                   int palette,
 647.481 +                   int contrast)
 647.482 +{
 647.483 +	theApp.winCheckFullscreen();
 647.484 +	GBPrinterDlg printer;
 647.485 +	printer.processData(data);
 647.486 +	printer.DoModal();
 647.487 +}
 647.488 +
   648.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   648.2 +++ b/src/win32/GBPrinterDlg.h	Sat Mar 03 10:31:27 2012 -0600
   648.3 @@ -0,0 +1,61 @@
   648.4 +#if !defined(AFX_GBPRINTER_H__3180CC5A_1F9D_47E5_B044_407442CB40A4__INCLUDED_)
   648.5 +#define AFX_GBPRINTER_H__3180CC5A_1F9D_47E5_B044_407442CB40A4__INCLUDED_
   648.6 +
   648.7 +#if _MSC_VER > 1000
   648.8 +#pragma once
   648.9 +#endif // _MSC_VER > 1000
  648.10 +// -*- C++ -*-
  648.11 +// GBPrinter.h : header file
  648.12 +//
  648.13 +
  648.14 +/////////////////////////////////////////////////////////////////////////////
  648.15 +// GBPrinter dialog
  648.16 +
  648.17 +class GBPrinterDlg : public CDialog
  648.18 +{
  648.19 +private:
  648.20 +	u8 bitmapHeader[sizeof(BITMAPINFO)+4*sizeof(RGBQUAD)];
  648.21 +	BITMAPINFO *bitmap;
  648.22 +	u8  bitmapData[160*144];
  648.23 +	int scale;
  648.24 +	// Construction
  648.25 +public:
  648.26 +	void processData(u8 *data);
  648.27 +	void saveAsPNG(const char *name);
  648.28 +	void saveAsBMP(const char *name);
  648.29 +	GBPrinterDlg(CWnd*pParent = NULL);  // standard constructor
  648.30 +
  648.31 +	// Dialog Data
  648.32 +	//{{AFX_DATA(GBPrinterDlg)
  648.33 +	enum { IDD = IDD_GB_PRINTER };
  648.34 +	int m_scale;
  648.35 +	//}}AFX_DATA
  648.36 +
  648.37 +	// Overrides
  648.38 +	// ClassWizard generated virtual function overrides
  648.39 +	//{{AFX_VIRTUAL(GBPrinterDlg)
  648.40 +protected:
  648.41 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  648.42 +	//}}AFX_VIRTUAL
  648.43 +
  648.44 +	// Implementation
  648.45 +protected:
  648.46 +	// Generated message map functions
  648.47 +	//{{AFX_MSG(GBPrinterDlg)
  648.48 +	afx_msg void OnSave();
  648.49 +	afx_msg void OnPrint();
  648.50 +	virtual BOOL OnInitDialog();
  648.51 +	afx_msg void OnOk();
  648.52 +	afx_msg void On1x();
  648.53 +	afx_msg void On2x();
  648.54 +	afx_msg void On3x();
  648.55 +	afx_msg void On4x();
  648.56 +	afx_msg void OnPaint();
  648.57 +	//}}AFX_MSG
  648.58 +	DECLARE_MESSAGE_MAP()
  648.59 +};
  648.60 +
  648.61 +//{{AFX_INSERT_LOCATION}}
  648.62 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  648.63 +
  648.64 +#endif // !defined(AFX_GBPRINTER_H__3180CC5A_1F9D_47E5_B044_407442CB40A4__INCLUDED_)
   649.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   649.2 +++ b/src/win32/GBTileView.cpp	Sat Mar 03 10:31:27 2012 -0600
   649.3 @@ -0,0 +1,517 @@
   649.4 +// GBTileView.cpp : implementation file
   649.5 +//
   649.6 +
   649.7 +#include "stdafx.h"
   649.8 +#include "resource.h"
   649.9 +#include "GBTileView.h"
  649.10 +#include "FileDlg.h"
  649.11 +#include "Reg.h"
  649.12 +#include "WinResUtil.h"
  649.13 +#include "VBA.h"
  649.14 +
  649.15 +//#include "../common/System.h"
  649.16 +#include "../gb/gbGlobals.h"
  649.17 +#include "../NLS.h"
  649.18 +#include "../common/Util.h"
  649.19 +
  649.20 +extern "C" {
  649.21 +#include <png.h>
  649.22 +}
  649.23 +
  649.24 +/////////////////////////////////////////////////////////////////////////////
  649.25 +// GBTileView dialog
  649.26 +
  649.27 +GBTileView::GBTileView(CWnd*pParent /*=NULL*/)
  649.28 +	: ResizeDlg(GBTileView::IDD, pParent)
  649.29 +{
  649.30 +	//{{AFX_DATA_INIT(GBTileView)
  649.31 +	m_charBase = -1;
  649.32 +	m_bank     = -1;
  649.33 +	m_stretch  = FALSE;
  649.34 +	//}}AFX_DATA_INIT
  649.35 +	autoUpdate = false;
  649.36 +
  649.37 +	memset(&bmpInfo, 0, sizeof(bmpInfo));
  649.38 +
  649.39 +	bmpInfo.bmiHeader.biSize        = sizeof(bmpInfo.bmiHeader);
  649.40 +	bmpInfo.bmiHeader.biWidth       = 32*8;
  649.41 +	bmpInfo.bmiHeader.biHeight      = 32*8;
  649.42 +	bmpInfo.bmiHeader.biPlanes      = 1;
  649.43 +	bmpInfo.bmiHeader.biBitCount    = 24;
  649.44 +	bmpInfo.bmiHeader.biCompression = BI_RGB;
  649.45 +	data = (u8 *)calloc(1, 3 * 32*32 * 64);
  649.46 +
  649.47 +	tileView.setData(data);
  649.48 +	tileView.setBmpInfo(&bmpInfo);
  649.49 +
  649.50 +	charBase = 0;
  649.51 +	palette  = 0;
  649.52 +	bank     = 0;
  649.53 +	w        = h = 0;
  649.54 +}
  649.55 +
  649.56 +GBTileView::~GBTileView()
  649.57 +{
  649.58 +	free(data);
  649.59 +	data = NULL;
  649.60 +}
  649.61 +
  649.62 +void GBTileView::DoDataExchange(CDataExchange*pDX)
  649.63 +{
  649.64 +	CDialog::DoDataExchange(pDX);
  649.65 +	//{{AFX_DATA_MAP(GBTileView)
  649.66 +	DDX_Control(pDX, IDC_PALETTE_SLIDER, m_slider);
  649.67 +	DDX_Radio(pDX, IDC_CHARBASE_0, m_charBase);
  649.68 +	DDX_Radio(pDX, IDC_BANK_0, m_bank);
  649.69 +	DDX_Check(pDX, IDC_STRETCH, m_stretch);
  649.70 +	//}}AFX_DATA_MAP
  649.71 +	DDX_Control(pDX, IDC_TILE_VIEW, tileView);
  649.72 +	DDX_Control(pDX, IDC_MAP_VIEW_ZOOM, zoom);
  649.73 +	DDX_Control(pDX, IDC_COLOR, color);
  649.74 +}
  649.75 +
  649.76 +BEGIN_MESSAGE_MAP(GBTileView, CDialog)
  649.77 +//{{AFX_MSG_MAP(GBTileView)
  649.78 +ON_BN_CLICKED(IDC_SAVE, OnSave)
  649.79 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
  649.80 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
  649.81 +ON_BN_CLICKED(IDC_CHARBASE_0, OnCharbase0)
  649.82 +ON_BN_CLICKED(IDC_CHARBASE_1, OnCharbase1)
  649.83 +ON_BN_CLICKED(IDC_BANK_0, OnBank0)
  649.84 +ON_BN_CLICKED(IDC_BANK_1, OnBank1)
  649.85 +ON_BN_CLICKED(IDC_STRETCH, OnStretch)
  649.86 +ON_WM_HSCROLL()
  649.87 +//}}AFX_MSG_MAP
  649.88 +ON_MESSAGE(WM_MAPINFO, OnMapInfo)
  649.89 +ON_MESSAGE(WM_COLINFO, OnColInfo)
  649.90 +END_MESSAGE_MAP()
  649.91 +
  649.92 +/////////////////////////////////////////////////////////////////////////////
  649.93 +// GBTileView message handlers
  649.94 +
  649.95 +void GBTileView::saveBMP(const char *name)
  649.96 +{
  649.97 +	u8 writeBuffer[1024 * 3];
  649.98 +
  649.99 +	FILE *fp = fopen(name, "wb");
 649.100 +
 649.101 +	if (!fp)
 649.102 +	{
 649.103 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
 649.104 +		return;
 649.105 +	}
 649.106 +
 649.107 +	struct
 649.108 +	{
 649.109 +		u8 ident[2];
 649.110 +		u8 filesize[4];
 649.111 +		u8 reserved[4];
 649.112 +		u8 dataoffset[4];
 649.113 +		u8 headersize[4];
 649.114 +		u8 width[4];
 649.115 +		u8 height[4];
 649.116 +		u8 planes[2];
 649.117 +		u8 bitsperpixel[2];
 649.118 +		u8 compression[4];
 649.119 +		u8 datasize[4];
 649.120 +		u8 hres[4];
 649.121 +		u8 vres[4];
 649.122 +		u8 colors[4];
 649.123 +		u8 importantcolors[4];
 649.124 +		u8 pad[2];
 649.125 +	} bmpheader;
 649.126 +	memset(&bmpheader, 0, sizeof(bmpheader));
 649.127 +
 649.128 +	bmpheader.ident[0] = 'B';
 649.129 +	bmpheader.ident[1] = 'M';
 649.130 +
 649.131 +	u32 fsz = sizeof(bmpheader) + w*h*3;
 649.132 +	utilPutDword(bmpheader.filesize, fsz);
 649.133 +	utilPutDword(bmpheader.dataoffset, 0x38);
 649.134 +	utilPutDword(bmpheader.headersize, 0x28);
 649.135 +	utilPutDword(bmpheader.width, w);
 649.136 +	utilPutDword(bmpheader.height, h);
 649.137 +	utilPutDword(bmpheader.planes, 1);
 649.138 +	utilPutDword(bmpheader.bitsperpixel, 24);
 649.139 +	utilPutDword(bmpheader.datasize, 3*w*h);
 649.140 +
 649.141 +	fwrite(&bmpheader, 1, sizeof(bmpheader), fp);
 649.142 +
 649.143 +	u8 *b = writeBuffer;
 649.144 +
 649.145 +	int sizeX = w;
 649.146 +	int sizeY = h;
 649.147 +
 649.148 +	u8 *pixU8 = (u8 *)data+3*w*(h-1);
 649.149 +	for (int y = 0; y < sizeY; y++)
 649.150 +	{
 649.151 +		for (int x = 0; x < sizeX; x++)
 649.152 +		{
 649.153 +			*b++ = *pixU8++; // B
 649.154 +			*b++ = *pixU8++; // G
 649.155 +			*b++ = *pixU8++; // R
 649.156 +		}
 649.157 +		pixU8 -= 2*3*w;
 649.158 +		fwrite(writeBuffer, 1, 3*w, fp);
 649.159 +
 649.160 +		b = writeBuffer;
 649.161 +	}
 649.162 +
 649.163 +	fclose(fp);
 649.164 +}
 649.165 +
 649.166 +void GBTileView::savePNG(const char *name)
 649.167 +{
 649.168 +	u8 writeBuffer[1024 * 3];
 649.169 +
 649.170 +	FILE *fp = fopen(name, "wb");
 649.171 +
 649.172 +	if (!fp)
 649.173 +	{
 649.174 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
 649.175 +		return;
 649.176 +	}
 649.177 +
 649.178 +	png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
 649.179 +	                                              NULL,
 649.180 +	                                              NULL,
 649.181 +	                                              NULL);
 649.182 +	if (!png_ptr)
 649.183 +	{
 649.184 +		fclose(fp);
 649.185 +		return;
 649.186 +	}
 649.187 +
 649.188 +	png_infop info_ptr = png_create_info_struct(png_ptr);
 649.189 +
 649.190 +	if (!info_ptr)
 649.191 +	{
 649.192 +		png_destroy_write_struct(&png_ptr, NULL);
 649.193 +		fclose(fp);
 649.194 +		return;
 649.195 +	}
 649.196 +
 649.197 +	if (setjmp(png_ptr->jmpbuf))
 649.198 +	{
 649.199 +		png_destroy_write_struct(&png_ptr, NULL);
 649.200 +		fclose(fp);
 649.201 +		return;
 649.202 +	}
 649.203 +
 649.204 +	png_init_io(png_ptr, fp);
 649.205 +
 649.206 +	png_set_IHDR(png_ptr,
 649.207 +	             info_ptr,
 649.208 +	             w,
 649.209 +	             h,
 649.210 +	             8,
 649.211 +	             PNG_COLOR_TYPE_RGB,
 649.212 +	             PNG_INTERLACE_NONE,
 649.213 +	             PNG_COMPRESSION_TYPE_DEFAULT,
 649.214 +	             PNG_FILTER_TYPE_DEFAULT);
 649.215 +
 649.216 +	png_write_info(png_ptr, info_ptr);
 649.217 +
 649.218 +	u8 *b = writeBuffer;
 649.219 +
 649.220 +	int sizeX = w;
 649.221 +	int sizeY = h;
 649.222 +
 649.223 +	u8 *pixU8 = (u8 *)data;
 649.224 +	for (int y = 0; y < sizeY; y++)
 649.225 +	{
 649.226 +		for (int x = 0; x < sizeX; x++)
 649.227 +		{
 649.228 +			int blue  = *pixU8++;
 649.229 +			int green = *pixU8++;
 649.230 +			int red   = *pixU8++;
 649.231 +
 649.232 +			*b++ = red;
 649.233 +			*b++ = green;
 649.234 +			*b++ = blue;
 649.235 +		}
 649.236 +		png_write_row(png_ptr, writeBuffer);
 649.237 +
 649.238 +		b = writeBuffer;
 649.239 +	}
 649.240 +
 649.241 +	png_write_end(png_ptr, info_ptr);
 649.242 +
 649.243 +	png_destroy_write_struct(&png_ptr, &info_ptr);
 649.244 +
 649.245 +	fclose(fp);
 649.246 +}
 649.247 +
 649.248 +void GBTileView::OnSave()
 649.249 +{
 649.250 +	CString captureBuffer;
 649.251 +
 649.252 +	if (theApp.captureFormat == 0)
 649.253 +		captureBuffer = "tiles.png";
 649.254 +	else
 649.255 +		captureBuffer = "tiles.bmp";
 649.256 +
 649.257 +	LPCTSTR exts[] = {".png", ".bmp", NULL };
 649.258 +
 649.259 +	CString filter = winResLoadFilter(IDS_FILTER_PNG);
 649.260 +	CString title  = winResLoadString(IDS_SELECT_CAPTURE_NAME);
 649.261 +
 649.262 +	FileDlg dlg(this,
 649.263 +	            captureBuffer,
 649.264 +	            filter,
 649.265 +	            theApp.captureFormat ? 2 : 1,
 649.266 +	            theApp.captureFormat ? "BMP" : "PNG",
 649.267 +	            exts,
 649.268 +	            "",
 649.269 +	            title,
 649.270 +	            true);
 649.271 +
 649.272 +	if (dlg.DoModal() == IDCANCEL)
 649.273 +	{
 649.274 +		return;
 649.275 +	}
 649.276 +
 649.277 +	captureBuffer = dlg.GetPathName();
 649.278 +
 649.279 +	if (theApp.captureFormat)
 649.280 +		saveBMP(captureBuffer);
 649.281 +	else
 649.282 +		savePNG(captureBuffer);
 649.283 +}
 649.284 +
 649.285 +void GBTileView::renderTile(int tile, int x, int y, u8 *charBase)
 649.286 +{
 649.287 +	u8 *bmp = &data[24*x + 8*16*24*y];
 649.288 +
 649.289 +	for (int j = 0; j < 8; j++)
 649.290 +	{
 649.291 +		u8 mask   = 0x80;
 649.292 +		u8 tile_a = charBase[tile*16+j*2];
 649.293 +		u8 tile_b = charBase[tile*16+j*2+1];
 649.294 +
 649.295 +		for (int i = 0; i < 8; i++)
 649.296 +		{
 649.297 +			u8 c = (tile_a & mask) ? 1 : 0;
 649.298 +			c += ((tile_b & mask) ? 2 : 0);
 649.299 +
 649.300 +			if (gbCgbMode)
 649.301 +			{
 649.302 +				c = c + palette*4;
 649.303 +			}
 649.304 +			else
 649.305 +			{
 649.306 +				c = gbBgp[c];
 649.307 +			}
 649.308 +
 649.309 +			u16 color = gbPalette[c];
 649.310 +
 649.311 +			*bmp++ = ((color >> 10) & 0x1f) << 3;
 649.312 +			*bmp++ = ((color >> 5) & 0x1f) << 3;
 649.313 +			*bmp++ = (color & 0x1f) << 3;
 649.314 +
 649.315 +			mask >>= 1;
 649.316 +		}
 649.317 +		bmp += 15*24; // advance line
 649.318 +	}
 649.319 +}
 649.320 +
 649.321 +void GBTileView::render()
 649.322 +{
 649.323 +	int tiles = 0x0000;
 649.324 +	if (charBase)
 649.325 +		tiles = 0x0800;
 649.326 +	u8 *charBase = (gbVram != NULL) ?
 649.327 +	               (bank ? &gbVram[0x2000+tiles] : &gbVram[tiles]) :
 649.328 +	               &gbMemory[0x8000+tiles];
 649.329 +
 649.330 +	int tile = 0;
 649.331 +	for (int y = 0; y < 16; y++)
 649.332 +	{
 649.333 +		for (int x = 0; x < 16; x++)
 649.334 +		{
 649.335 +			renderTile(tile, x, y, charBase);
 649.336 +			tile++;
 649.337 +		}
 649.338 +	}
 649.339 +	tileView.setSize(16*8, 16*8);
 649.340 +	w = 16*8;
 649.341 +	h = 16*8;
 649.342 +	SIZE s;
 649.343 +	s.cx = s.cy = 16*8;
 649.344 +	if (tileView.getStretch())
 649.345 +	{
 649.346 +		s.cx = s.cy = 1;
 649.347 +	}
 649.348 +	tileView.SetScrollSizes(MM_TEXT, s);
 649.349 +}
 649.350 +
 649.351 +void GBTileView::update()
 649.352 +{
 649.353 +	paint();
 649.354 +}
 649.355 +
 649.356 +BOOL GBTileView::OnInitDialog()
 649.357 +{
 649.358 +	CDialog::OnInitDialog();
 649.359 +
 649.360 +	DIALOG_SIZER_START(sz)
 649.361 +	DIALOG_SIZER_ENTRY(IDC_TILE_VIEW, DS_SizeX | DS_SizeY)
 649.362 +	DIALOG_SIZER_ENTRY(IDC_COLOR, DS_MoveY)
 649.363 +	DIALOG_SIZER_ENTRY(IDC_R, DS_MoveY)
 649.364 +	DIALOG_SIZER_ENTRY(IDC_G, DS_MoveY)
 649.365 +	DIALOG_SIZER_ENTRY(IDC_B, DS_MoveY)
 649.366 +	DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
 649.367 +	DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
 649.368 +	DIALOG_SIZER_ENTRY(IDC_SAVE, DS_MoveY)
 649.369 +	DIALOG_SIZER_END()
 649.370 +	SetData(sz,
 649.371 +	        TRUE,
 649.372 +	        HKEY_CURRENT_USER,
 649.373 +	        "Software\\Emulators\\VisualBoyAdvance\\Viewer\\GBTileView",
 649.374 +	        NULL);
 649.375 +
 649.376 +	m_charBase = charBase;
 649.377 +	m_bank     = bank;
 649.378 +
 649.379 +	m_slider.SetRange(0, 7);
 649.380 +	m_slider.SetPageSize(2);
 649.381 +	m_slider.SetTicFreq(1);
 649.382 +	paint();
 649.383 +
 649.384 +	m_stretch = regQueryDwordValue("tileViewStretch", 0);
 649.385 +	if (m_stretch)
 649.386 +		tileView.setStretch(true);
 649.387 +	UpdateData(FALSE);
 649.388 +
 649.389 +	return TRUE; // return TRUE unless you set the focus to a control
 649.390 +	             // EXCEPTION: OCX Property Pages should return FALSE
 649.391 +}
 649.392 +
 649.393 +void GBTileView::OnClose()
 649.394 +{
 649.395 +	theApp.winRemoveUpdateListener(this);
 649.396 +
 649.397 +	DestroyWindow();
 649.398 +}
 649.399 +
 649.400 +void GBTileView::OnAutoUpdate()
 649.401 +{
 649.402 +	autoUpdate = !autoUpdate;
 649.403 +	if (autoUpdate)
 649.404 +	{
 649.405 +		theApp.winAddUpdateListener(this);
 649.406 +	}
 649.407 +	else
 649.408 +	{
 649.409 +		theApp.winRemoveUpdateListener(this);
 649.410 +	}
 649.411 +}
 649.412 +
 649.413 +void GBTileView::paint()
 649.414 +{
 649.415 +	if (gbRom != NULL)
 649.416 +	{
 649.417 +		render();
 649.418 +		tileView.refresh();
 649.419 +	}
 649.420 +}
 649.421 +
 649.422 +void GBTileView::OnCharbase0()
 649.423 +{
 649.424 +	charBase = 0;
 649.425 +	paint();
 649.426 +}
 649.427 +
 649.428 +void GBTileView::OnCharbase1()
 649.429 +{
 649.430 +	charBase = 1;
 649.431 +	paint();
 649.432 +}
 649.433 +
 649.434 +void GBTileView::OnBank0()
 649.435 +{
 649.436 +	bank = 0;
 649.437 +	paint();
 649.438 +}
 649.439 +
 649.440 +void GBTileView::OnBank1()
 649.441 +{
 649.442 +	bank = 1;
 649.443 +	paint();
 649.444 +}
 649.445 +
 649.446 +void GBTileView::OnStretch()
 649.447 +{
 649.448 +	tileView.setStretch(!tileView.getStretch());
 649.449 +	paint();
 649.450 +	regSetDwordValue("tileViewStretch", tileView.getStretch());
 649.451 +}
 649.452 +
 649.453 +LRESULT GBTileView::OnMapInfo(WPARAM wParam, LPARAM lParam)
 649.454 +{
 649.455 +	u8 *colors = (u8 *)lParam;
 649.456 +	zoom.setColors(colors);
 649.457 +
 649.458 +	int x = (wParam & 0xFFFF)/8;
 649.459 +	int y = ((wParam >> 16) & 0xFFFF)/8;
 649.460 +
 649.461 +	int tiles = 0x0000;
 649.462 +	if (charBase)
 649.463 +		tiles = 0x0800;
 649.464 +	u32 address = 0x8000 + tiles;
 649.465 +	int tile    = 16 * y + x;
 649.466 +
 649.467 +	address += 16 * tile;
 649.468 +
 649.469 +	CString buffer;
 649.470 +	buffer.Format("%d", tile);
 649.471 +	GetDlgItem(IDC_TILE_NUMBER)->SetWindowText(buffer);
 649.472 +
 649.473 +	buffer.Format("%04x", address);
 649.474 +	GetDlgItem(IDC_ADDRESS)->SetWindowText(buffer);
 649.475 +
 649.476 +	return TRUE;
 649.477 +}
 649.478 +
 649.479 +LRESULT GBTileView::OnColInfo(WPARAM wParam, LPARAM)
 649.480 +{
 649.481 +	u16 c = (u16)wParam;
 649.482 +
 649.483 +	color.setColor(c);
 649.484 +
 649.485 +	int r = (c & 0x1f);
 649.486 +	int g = (c & 0x3e0) >> 5;
 649.487 +	int b = (c & 0x7c00) >> 10;
 649.488 +
 649.489 +	CString buffer;
 649.490 +	buffer.Format("R: %d", r);
 649.491 +	GetDlgItem(IDC_R)->SetWindowText(buffer);
 649.492 +
 649.493 +	buffer.Format("G: %d", g);
 649.494 +	GetDlgItem(IDC_G)->SetWindowText(buffer);
 649.495 +
 649.496 +	buffer.Format("B: %d", b);
 649.497 +	GetDlgItem(IDC_B)->SetWindowText(buffer);
 649.498 +
 649.499 +	return TRUE;
 649.500 +}
 649.501 +
 649.502 +void GBTileView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar)
 649.503 +{
 649.504 +	switch (nSBCode)
 649.505 +	{
 649.506 +	case TB_THUMBPOSITION:
 649.507 +		palette = nPos;
 649.508 +		break;
 649.509 +	default:
 649.510 +		palette = m_slider.GetPos();
 649.511 +		break;
 649.512 +	}
 649.513 +	paint();
 649.514 +}
 649.515 +
 649.516 +void GBTileView::PostNcDestroy()
 649.517 +{
 649.518 +	delete this;
 649.519 +}
 649.520 +
   650.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   650.2 +++ b/src/win32/GBTileView.h	Sat Mar 03 10:31:27 2012 -0600
   650.3 @@ -0,0 +1,85 @@
   650.4 +#if !defined(AFX_GBTILEVIEW_H__C8C8DEBB_17ED_4C5C_9DBE_D730A49B312C__INCLUDED_)
   650.5 +#define AFX_GBTILEVIEW_H__C8C8DEBB_17ED_4C5C_9DBE_D730A49B312C__INCLUDED_
   650.6 +
   650.7 +#if _MSC_VER > 1000
   650.8 +#pragma once
   650.9 +#endif // _MSC_VER > 1000
  650.10 +// -*- C++ -*-
  650.11 +// GBTileView.h : header file
  650.12 +//
  650.13 +#include "BitmapControl.h"
  650.14 +#include "ColorControl.h"
  650.15 +#include "IUpdate.h"
  650.16 +#include "ResizeDlg.h"
  650.17 +#include "ZoomControl.h"
  650.18 +
  650.19 +/////////////////////////////////////////////////////////////////////////////
  650.20 +// GBTileView dialog
  650.21 +
  650.22 +class GBTileView : public ResizeDlg, IUpdateListener
  650.23 +{
  650.24 +	int charBase;
  650.25 +	int palette;
  650.26 +	int bank;
  650.27 +	BitmapControl tileView;
  650.28 +	BITMAPINFO    bmpInfo;
  650.29 +	u8 *         data;
  650.30 +	ZoomControl  zoom;
  650.31 +	ColorControl color;
  650.32 +	int          w;
  650.33 +	int          h;
  650.34 +	bool         autoUpdate;
  650.35 +	// Construction
  650.36 +public:
  650.37 +	void paint();
  650.38 +	void render();
  650.39 +	void renderTile(int tile, int x, int y, u8 *charBase);
  650.40 +	void savePNG(const char *name);
  650.41 +	void saveBMP(const char *name);
  650.42 +	GBTileView(CWnd*pParent = NULL);  // standard constructor
  650.43 +	virtual ~GBTileView();
  650.44 +
  650.45 +	virtual void update();
  650.46 +
  650.47 +	// Dialog Data
  650.48 +	//{{AFX_DATA(GBTileView)
  650.49 +	enum { IDD = IDD_GB_TILE_VIEWER };
  650.50 +	CSliderCtrl m_slider;
  650.51 +	int         m_charBase;
  650.52 +	int         m_bank;
  650.53 +	BOOL        m_stretch;
  650.54 +	//}}AFX_DATA
  650.55 +
  650.56 +	// Overrides
  650.57 +	// ClassWizard generated virtual function overrides
  650.58 +	//{{AFX_VIRTUAL(GBTileView)
  650.59 +protected:
  650.60 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  650.61 +	virtual void PostNcDestroy();
  650.62 +	//}}AFX_VIRTUAL
  650.63 +
  650.64 +	// Implementation
  650.65 +protected:
  650.66 +	virtual afx_msg LRESULT OnMapInfo(WPARAM wParam, LPARAM lParam);
  650.67 +	virtual afx_msg LRESULT OnColInfo(WPARAM wParam, LPARAM lParam);
  650.68 +
  650.69 +	// Generated message map functions
  650.70 +	//{{AFX_MSG(GBTileView)
  650.71 +	afx_msg void OnSave();
  650.72 +	virtual BOOL OnInitDialog();
  650.73 +	afx_msg void OnClose();
  650.74 +	afx_msg void OnAutoUpdate();
  650.75 +	afx_msg void OnCharbase0();
  650.76 +	afx_msg void OnCharbase1();
  650.77 +	afx_msg void OnBank0();
  650.78 +	afx_msg void OnBank1();
  650.79 +	afx_msg void OnStretch();
  650.80 +	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar);
  650.81 +	//}}AFX_MSG
  650.82 +	DECLARE_MESSAGE_MAP()
  650.83 +};
  650.84 +
  650.85 +//{{AFX_INSERT_LOCATION}}
  650.86 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  650.87 +
  650.88 +#endif // !defined(AFX_GBTILEVIEW_H__C8C8DEBB_17ED_4C5C_9DBE_D730A49B312C__INCLUDED_)
   651.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   651.2 +++ b/src/win32/GDBConnection.cpp	Sat Mar 03 10:31:27 2012 -0600
   651.3 @@ -0,0 +1,248 @@
   651.4 +// GDBConnection.cpp : implementation file
   651.5 +//
   651.6 +
   651.7 +#include "stdafx.h"
   651.8 +#include "resource.h"
   651.9 +#include "GDBConnection.h"
  651.10 +
  651.11 +#include "../common/System.h"
  651.12 +
  651.13 +#define SOCKET_MESSAGE WM_APP+1
  651.14 +
  651.15 +static bool initialized = false;
  651.16 +
  651.17 +/////////////////////////////////////////////////////////////////////////////
  651.18 +// GDBPortDlg dialog
  651.19 +
  651.20 +GDBPortDlg::GDBPortDlg(CWnd*pParent /*=NULL*/)
  651.21 +	: CDialog(GDBPortDlg::IDD, pParent)
  651.22 +{
  651.23 +	//{{AFX_DATA_INIT(GDBPortDlg)
  651.24 +	// NOTE: the ClassWizard will add member initialization here
  651.25 +	//}}AFX_DATA_INIT
  651.26 +	port = 55555;
  651.27 +	sock = INVALID_SOCKET;
  651.28 +
  651.29 +	if (!initialized)
  651.30 +	{
  651.31 +		WSADATA wsaData;
  651.32 +
  651.33 +		int error = WSAStartup(MAKEWORD(1, 1), &wsaData);
  651.34 +
  651.35 +		initialized = true;
  651.36 +	}
  651.37 +}
  651.38 +
  651.39 +void GDBPortDlg::DoDataExchange(CDataExchange*pDX)
  651.40 +{
  651.41 +	CDialog::DoDataExchange(pDX);
  651.42 +	//{{AFX_DATA_MAP(GDBPortDlg)
  651.43 +	DDX_Control(pDX, IDC_PORT, m_port);
  651.44 +	//}}AFX_DATA_MAP
  651.45 +}
  651.46 +
  651.47 +BEGIN_MESSAGE_MAP(GDBPortDlg, CDialog)
  651.48 +//{{AFX_MSG_MAP(GDBPortDlg)
  651.49 +ON_BN_CLICKED(ID_OK, OnOk)
  651.50 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
  651.51 +ON_WM_CLOSE()
  651.52 +//}}AFX_MSG_MAP
  651.53 +END_MESSAGE_MAP()
  651.54 +
  651.55 +/////////////////////////////////////////////////////////////////////////////
  651.56 +// GDBPortDlg message handlers
  651.57 +
  651.58 +int GDBPortDlg::getPort()
  651.59 +{
  651.60 +	return port;
  651.61 +}
  651.62 +
  651.63 +SOCKET GDBPortDlg::getSocket()
  651.64 +{
  651.65 +	return sock;
  651.66 +}
  651.67 +
  651.68 +BOOL GDBPortDlg::OnInitDialog()
  651.69 +{
  651.70 +	CDialog::OnInitDialog();
  651.71 +
  651.72 +	CString buffer;
  651.73 +
  651.74 +	buffer.Format("%d", port);
  651.75 +
  651.76 +	m_port.SetWindowText(buffer);
  651.77 +
  651.78 +	CenterWindow();
  651.79 +
  651.80 +	return TRUE; // return TRUE unless you set the focus to a control
  651.81 +	             // EXCEPTION: OCX Property Pages should return FALSE
  651.82 +}
  651.83 +
  651.84 +void GDBPortDlg::OnOk()
  651.85 +{
  651.86 +	CString buffer;
  651.87 +
  651.88 +	m_port.GetWindowText(buffer);
  651.89 +
  651.90 +	sockaddr_in address;
  651.91 +	address.sin_family      = AF_INET;
  651.92 +	address.sin_addr.s_addr = inet_addr("0.0.0.0");
  651.93 +	address.sin_port        = htons(atoi(buffer));
  651.94 +	port = ntohs(address.sin_port);
  651.95 +
  651.96 +	SOCKET s = socket(AF_INET, SOCK_STREAM, 0);
  651.97 +
  651.98 +	if (s != INVALID_SOCKET)
  651.99 +	{
 651.100 +		int error = bind(s, (sockaddr *)&address, sizeof(address));
 651.101 +
 651.102 +		if (error)
 651.103 +		{
 651.104 +			systemMessage(IDS_ERROR_BINDING, "Error binding socket. Port probably in use.");
 651.105 +			error = closesocket(s);
 651.106 +			EndDialog(FALSE);
 651.107 +		}
 651.108 +		else
 651.109 +		{
 651.110 +			error = listen(s, 1);
 651.111 +			if (!error)
 651.112 +			{
 651.113 +				sock = s;
 651.114 +				EndDialog(TRUE);
 651.115 +			}
 651.116 +			else
 651.117 +			{
 651.118 +				systemMessage(IDS_ERROR_LISTENING, "Error listening on socket.");
 651.119 +				closesocket(s);
 651.120 +				EndDialog(FALSE);
 651.121 +			}
 651.122 +		}
 651.123 +	}
 651.124 +	else
 651.125 +	{
 651.126 +		systemMessage(IDS_ERROR_CREATING_SOCKET, "Error creating socket.");
 651.127 +		EndDialog(FALSE);
 651.128 +	}
 651.129 +}
 651.130 +
 651.131 +void GDBPortDlg::OnCancel()
 651.132 +{
 651.133 +	OnClose();
 651.134 +}
 651.135 +
 651.136 +void GDBPortDlg::OnClose()
 651.137 +{
 651.138 +	EndDialog(FALSE);
 651.139 +}
 651.140 +
 651.141 +/////////////////////////////////////////////////////////////////////////////
 651.142 +// GDBWaitingDlg dialog
 651.143 +
 651.144 +GDBWaitingDlg::GDBWaitingDlg(SOCKET s, int p, CWnd*pParent /*=NULL*/)
 651.145 +	: CDialog(GDBWaitingDlg::IDD, pParent)
 651.146 +{
 651.147 +	//{{AFX_DATA_INIT(GDBWaitingDlg)
 651.148 +	//}}AFX_DATA_INIT
 651.149 +	port         = p & 65535;
 651.150 +	listenSocket = s;
 651.151 +}
 651.152 +
 651.153 +void GDBWaitingDlg::DoDataExchange(CDataExchange*pDX)
 651.154 +{
 651.155 +	CDialog::DoDataExchange(pDX);
 651.156 +	//{{AFX_DATA_MAP(GDBWaitingDlg)
 651.157 +	DDX_Control(pDX, IDC_PORT, m_port);
 651.158 +	//}}AFX_DATA_MAP
 651.159 +}
 651.160 +
 651.161 +BEGIN_MESSAGE_MAP(GDBWaitingDlg, CDialog)
 651.162 +//{{AFX_MSG_MAP(GDBWaitingDlg)
 651.163 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
 651.164 +ON_WM_CLOSE()
 651.165 +//}}AFX_MSG_MAP
 651.166 +END_MESSAGE_MAP()
 651.167 +
 651.168 +/////////////////////////////////////////////////////////////////////////////
 651.169 +// GDBWaitingDlg message handlers
 651.170 +
 651.171 +BOOL GDBWaitingDlg::OnInitDialog()
 651.172 +{
 651.173 +	CDialog::OnInitDialog();
 651.174 +
 651.175 +	CString buffer;
 651.176 +
 651.177 +	buffer.Format("%d", port);
 651.178 +
 651.179 +	m_port.SetWindowText(buffer);
 651.180 +
 651.181 +	CenterWindow();
 651.182 +
 651.183 +	int error = WSAAsyncSelect(listenSocket,
 651.184 +	                           (HWND)*this,
 651.185 +	                           SOCKET_MESSAGE,
 651.186 +	                           FD_ACCEPT);
 651.187 +
 651.188 +	return TRUE; // return TRUE unless you set the focus to a control
 651.189 +	             // EXCEPTION: OCX Property Pages should return FALSE
 651.190 +}
 651.191 +
 651.192 +LRESULT GDBWaitingDlg::OnSocketAccept(WPARAM wParam, LPARAM lParam)
 651.193 +{
 651.194 +	if (LOWORD(lParam) == FD_ACCEPT)
 651.195 +	{
 651.196 +		WSAAsyncSelect(listenSocket, (HWND)*this, 0, 0);
 651.197 +
 651.198 +		int flag = 0;
 651.199 +		ioctlsocket(listenSocket, FIONBIO, (unsigned long *)&flag);
 651.200 +
 651.201 +		SOCKET s = accept(listenSocket, NULL, NULL);
 651.202 +		if (s != INVALID_SOCKET)
 651.203 +		{
 651.204 +			char dummy;
 651.205 +			recv(s, &dummy, 1, 0);
 651.206 +			if (dummy != '+')
 651.207 +			{
 651.208 +				systemMessage(IDS_ACK_NOT_RECEIVED, "ACK not received from GDB.");
 651.209 +				OnClose(); // calls EndDialog
 651.210 +			}
 651.211 +			else
 651.212 +			{
 651.213 +				sock = s;
 651.214 +				EndDialog(TRUE);
 651.215 +			}
 651.216 +		}
 651.217 +	}
 651.218 +
 651.219 +	return TRUE;
 651.220 +}
 651.221 +
 651.222 +void GDBWaitingDlg::OnCancel()
 651.223 +{
 651.224 +	OnClose();
 651.225 +}
 651.226 +
 651.227 +void GDBWaitingDlg::OnClose()
 651.228 +{
 651.229 +	if (sock != INVALID_SOCKET)
 651.230 +	{
 651.231 +		closesocket(sock);
 651.232 +		sock = INVALID_SOCKET;
 651.233 +	}
 651.234 +	if (listenSocket != INVALID_SOCKET)
 651.235 +	{
 651.236 +		closesocket(listenSocket);
 651.237 +		listenSocket = INVALID_SOCKET;
 651.238 +	}
 651.239 +	EndDialog(FALSE);
 651.240 +}
 651.241 +
 651.242 +SOCKET GDBWaitingDlg::getListenSocket()
 651.243 +{
 651.244 +	return listenSocket;
 651.245 +}
 651.246 +
 651.247 +SOCKET GDBWaitingDlg::getSocket()
 651.248 +{
 651.249 +	return sock;
 651.250 +}
 651.251 +
   652.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   652.2 +++ b/src/win32/GDBConnection.h	Sat Mar 03 10:31:27 2012 -0600
   652.3 @@ -0,0 +1,92 @@
   652.4 +#if !defined(AFX_GDBCONNECTION_H__DD73B298_E1A7_4A46_B282_E7A2B37FC9D9__INCLUDED_)
   652.5 +#define AFX_GDBCONNECTION_H__DD73B298_E1A7_4A46_B282_E7A2B37FC9D9__INCLUDED_
   652.6 +
   652.7 +#if _MSC_VER > 1000
   652.8 +#pragma once
   652.9 +#endif // _MSC_VER > 1000
  652.10 +// -*- C++ -*-
  652.11 +// GDBConnection.h : header file
  652.12 +//
  652.13 +
  652.14 +#include <winsock.h>
  652.15 +
  652.16 +/////////////////////////////////////////////////////////////////////////////
  652.17 +// GDBPortDlg dialog
  652.18 +
  652.19 +class GDBPortDlg : public CDialog
  652.20 +{
  652.21 +	int    port;
  652.22 +	SOCKET sock;
  652.23 +	// Construction
  652.24 +public:
  652.25 +	SOCKET getSocket();
  652.26 +	int getPort();
  652.27 +	GDBPortDlg(CWnd*pParent = NULL);  // standard constructor
  652.28 +
  652.29 +	// Dialog Data
  652.30 +	//{{AFX_DATA(GDBPortDlg)
  652.31 +	enum { IDD = IDD_GDB_PORT };
  652.32 +	CEdit m_port;
  652.33 +	//}}AFX_DATA
  652.34 +
  652.35 +	// Overrides
  652.36 +	// ClassWizard generated virtual function overrides
  652.37 +	//{{AFX_VIRTUAL(GDBPortDlg)
  652.38 +protected:
  652.39 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  652.40 +	//}}AFX_VIRTUAL
  652.41 +
  652.42 +	// Implementation
  652.43 +protected:
  652.44 +	// Generated message map functions
  652.45 +	//{{AFX_MSG(GDBPortDlg)
  652.46 +	virtual BOOL OnInitDialog();
  652.47 +	afx_msg void OnOk();
  652.48 +	afx_msg void OnCancel();
  652.49 +	afx_msg void OnClose();
  652.50 +	//}}AFX_MSG
  652.51 +	DECLARE_MESSAGE_MAP()
  652.52 +};
  652.53 +
  652.54 +/////////////////////////////////////////////////////////////////////////////
  652.55 +// GDBWaitingDlg dialog
  652.56 +
  652.57 +class GDBWaitingDlg : public CDialog
  652.58 +{
  652.59 +	int    port;
  652.60 +	SOCKET listenSocket;
  652.61 +	SOCKET sock;
  652.62 +	// Construction
  652.63 +public:
  652.64 +	SOCKET getSocket();
  652.65 +	SOCKET getListenSocket();
  652.66 +	afx_msg LRESULT OnSocketAccept(WPARAM wParam, LPARAM lParam);
  652.67 +	GDBWaitingDlg(SOCKET s, int p, CWnd*pParent = NULL); // standard constructor
  652.68 +
  652.69 +	// Dialog Data
  652.70 +	//{{AFX_DATA(GDBWaitingDlg)
  652.71 +	enum { IDD = IDD_GDB_WAITING };
  652.72 +	CStatic m_port;
  652.73 +	//}}AFX_DATA
  652.74 +
  652.75 +	// Overrides
  652.76 +	// ClassWizard generated virtual function overrides
  652.77 +	//{{AFX_VIRTUAL(GDBWaitingDlg)
  652.78 +protected:
  652.79 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  652.80 +	//}}AFX_VIRTUAL
  652.81 +
  652.82 +	// Implementation
  652.83 +protected:
  652.84 +	// Generated message map functions
  652.85 +	//{{AFX_MSG(GDBWaitingDlg)
  652.86 +	virtual BOOL OnInitDialog();
  652.87 +	afx_msg void OnCancel();
  652.88 +	afx_msg void OnClose();
  652.89 +	//}}AFX_MSG
  652.90 +	DECLARE_MESSAGE_MAP()
  652.91 +};
  652.92 +//{{AFX_INSERT_LOCATION}}
  652.93 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  652.94 +
  652.95 +#endif // !defined(AFX_GDBCONNECTION_H__DD73B298_E1A7_4A46_B282_E7A2B37FC9D9__INCLUDED_)
   653.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   653.2 +++ b/src/win32/GDIDisplay.cpp	Sat Mar 03 10:31:27 2012 -0600
   653.3 @@ -0,0 +1,387 @@
   653.4 +#include "stdafx.h"
   653.5 +#include <cstdio>
   653.6 +
   653.7 +#include "resource.h"
   653.8 +#include "MainWnd.h"
   653.9 +#include "Reg.h"
  653.10 +#include "VBA.h"
  653.11 +
  653.12 +#include "../gba/GBAGlobals.h"
  653.13 +#include "../gb/gbGlobals.h"
  653.14 +#include "../common/Text.h"
  653.15 +#include "../version.h"
  653.16 +
  653.17 +extern u32 RGB_LOW_BITS_MASK;
  653.18 +extern int systemSpeed;
  653.19 +extern void winlog(const char *, ...);
  653.20 +extern int Init_2xSaI(u32);
  653.21 +
  653.22 +class GDIDisplay : public IDisplay
  653.23 +{
  653.24 +private:
  653.25 +	u8 *filterData;
  653.26 +	u8  info[sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)];
  653.27 +public:
  653.28 +	GDIDisplay();
  653.29 +	virtual ~GDIDisplay();
  653.30 +
  653.31 +	virtual bool initialize();
  653.32 +	virtual void cleanup();
  653.33 +	virtual void render();
  653.34 +	virtual void checkFullScreen();
  653.35 +	virtual void renderMenu();
  653.36 +	virtual void clear();
  653.37 +	virtual DISPLAY_TYPE getType() { return GDI; };
  653.38 +	virtual void setOption(const char *, int) {}
  653.39 +	virtual int selectFullScreenMode(GUID * *);
  653.40 +};
  653.41 +
  653.42 +static int calculateShift(u32 mask)
  653.43 +{
  653.44 +	int m = 0;
  653.45 +
  653.46 +	while (mask)
  653.47 +	{
  653.48 +		m++;
  653.49 +		mask >>= 1;
  653.50 +	}
  653.51 +
  653.52 +	return m-5;
  653.53 +}
  653.54 +
  653.55 +GDIDisplay::GDIDisplay()
  653.56 +{
  653.57 +	filterData = (u8 *)malloc(4*16*256*256); // sufficient for 4x filters @ 32bit color depth
  653.58 +}
  653.59 +
  653.60 +GDIDisplay::~GDIDisplay()
  653.61 +{
  653.62 +	cleanup();
  653.63 +}
  653.64 +
  653.65 +void GDIDisplay::cleanup()
  653.66 +{
  653.67 +	if (filterData)
  653.68 +	{
  653.69 +		free(filterData);
  653.70 +		filterData = NULL;
  653.71 +	}
  653.72 +}
  653.73 +
  653.74 +bool GDIDisplay::initialize()
  653.75 +{
  653.76 +	CWnd *pWnd = theApp.m_pMainWnd;
  653.77 +
  653.78 +	theApp.mode320Available = false;
  653.79 +	theApp.mode640Available = false;
  653.80 +	theApp.mode800Available = false;
  653.81 +
  653.82 +	HDC         dc  = GetDC(NULL);
  653.83 +	HBITMAP     hbm = CreateCompatibleBitmap(dc, 1, 1);
  653.84 +	BITMAPINFO *bi  = (BITMAPINFO *)info;
  653.85 +	ZeroMemory(bi, sizeof(info));
  653.86 +	bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  653.87 +	GetDIBits(dc, hbm, 0, 1, NULL, (LPBITMAPINFO)info, DIB_RGB_COLORS);
  653.88 +	GetDIBits(dc, hbm, 0, 1, NULL, (LPBITMAPINFO)info, DIB_RGB_COLORS);
  653.89 +	DeleteObject(hbm);
  653.90 +	ReleaseDC(NULL, dc);
  653.91 +
  653.92 +	if (bi->bmiHeader.biCompression == BI_BITFIELDS)
  653.93 +	{
  653.94 +		systemColorDepth = bi->bmiHeader.biBitCount;
  653.95 +		if (systemColorDepth == 15)
  653.96 +			systemColorDepth = 16;
  653.97 +		systemRedShift   = calculateShift(*((DWORD *)&bi->bmiColors[0]));
  653.98 +		systemGreenShift = calculateShift(*((DWORD *)&bi->bmiColors[1]));
  653.99 +		systemBlueShift  = calculateShift(*((DWORD *)&bi->bmiColors[2]));
 653.100 +		if (systemColorDepth == 16)
 653.101 +		{
 653.102 +			if (systemGreenShift == 6)
 653.103 +			{
 653.104 +				Init_2xSaI(565);
 653.105 +				RGB_LOW_BITS_MASK = 0x821;
 653.106 +			}
 653.107 +			else
 653.108 +			{
 653.109 +				Init_2xSaI(555);
 653.110 +				RGB_LOW_BITS_MASK = 0x421;
 653.111 +			}
 653.112 +		}
 653.113 +		else if (systemColorDepth == 32)
 653.114 +			Init_2xSaI(32);
 653.115 +	}
 653.116 +	else
 653.117 +	{
 653.118 +		systemColorDepth = 32;
 653.119 +		systemRedShift   = 19;
 653.120 +		systemGreenShift = 11;
 653.121 +		systemBlueShift  = 3;
 653.122 +
 653.123 +		Init_2xSaI(32);
 653.124 +	}
 653.125 +	theApp.fsColorDepth = systemColorDepth;
 653.126 +	if (systemColorDepth == 24)
 653.127 +		theApp.filterFunction = NULL;
 653.128 +#ifdef MMX
 653.129 +	if (!theApp.disableMMX)
 653.130 +		cpu_mmx = theApp.detectMMX();
 653.131 +	else
 653.132 +		cpu_mmx = 0;
 653.133 +#endif
 653.134 +
 653.135 +	switch (systemColorDepth)
 653.136 +	{
 653.137 +	case 16:
 653.138 +	{
 653.139 +		for (int i = 0; i < 0x10000; i++)
 653.140 +		{
 653.141 +			systemColorMap16[i] = ((i & 0x1f) << systemRedShift) |
 653.142 +			                      (((i & 0x3e0) >> 5) << systemGreenShift) |
 653.143 +			                      (((i & 0x7c00) >> 10) << systemBlueShift);
 653.144 +		}
 653.145 +		break;
 653.146 +	}
 653.147 +	case 24:
 653.148 +	case 32:
 653.149 +	{
 653.150 +		for (int i = 0; i < 0x10000; i++)
 653.151 +		{
 653.152 +			systemColorMap32[i] = ((i & 0x1f) << systemRedShift) |
 653.153 +			                      (((i & 0x3e0) >> 5) << systemGreenShift) |
 653.154 +			                      (((i & 0x7c00) >> 10) << systemBlueShift);
 653.155 +		}
 653.156 +		break;
 653.157 +	}
 653.158 +	}
 653.159 +	theApp.updateFilter();
 653.160 +	theApp.updateIFB();
 653.161 +
 653.162 +	pWnd->DragAcceptFiles(TRUE);
 653.163 +
 653.164 +	return TRUE;
 653.165 +}
 653.166 +
 653.167 +void GDIDisplay::clear()
 653.168 +{}
 653.169 +
 653.170 +void GDIDisplay::renderMenu()
 653.171 +{
 653.172 +	checkFullScreen();
 653.173 +	theApp.m_pMainWnd->DrawMenuBar();
 653.174 +}
 653.175 +
 653.176 +void GDIDisplay::checkFullScreen()
 653.177 +{}
 653.178 +
 653.179 +void GDIDisplay::render()
 653.180 +{
 653.181 +	void (*filterFunction)(u8 *, u32, u8 *, u8 *, u32, int, int) = theApp.filterFunction;
 653.182 +	int  filterWidth = theApp.filterWidth, filterHeight = theApp.filterHeight;
 653.183 +/*
 653.184 +    if(textMethod == 1)
 653.185 +    {
 653.186 +        int copyX = 240, copyY = 160;
 653.187 +        if(systemCartridgeType == 1)
 653.188 +            if(gbBorderOn) copyX = 256, copyY = 224;
 653.189 +            else           copyX = 160, copyY = 144;
 653.190 +
 653.191 +        extern void Simple1x(u8*,u32,u8*,u8*,u32,int,int);
 653.192 +        filterFunction = Simple1x;
 653.193 +        filterWidth = copyX*2;
 653.194 +        filterHeight = copyY*2;
 653.195 +    }
 653.196 + */
 653.197 +	BITMAPINFO *bi = (BITMAPINFO *)info;
 653.198 +	bi->bmiHeader.biWidth  = filterWidth+1;
 653.199 +	bi->bmiHeader.biHeight = -filterHeight;
 653.200 +
 653.201 +	int pitch = filterWidth * 2 + 4;
 653.202 +	if (systemColorDepth == 32)
 653.203 +		pitch = filterWidth * 4 + 4;
 653.204 +	// FIXME: is the 24bit color depth still being used nowadays?
 653.205 +	else if (systemColorDepth == 24)
 653.206 +		pitch = filterWidth * 3;
 653.207 +
 653.208 +	// FIXME: is this working if systemColorDepth == 24?
 653.209 +	int filterPitch = theApp.rect.right*2;
 653.210 +	if (systemColorDepth == 32)
 653.211 +		filterPitch = theApp.rect.right*4;
 653.212 +	else if (systemColorDepth == 24)
 653.213 +		filterPitch = theApp.rect.right*3;
 653.214 +
 653.215 +/*
 653.216 +	// HACK: see below
 653.217 +	if (textMethod == 1 && !filterFunction)
 653.218 +	{
 653.219 +		textMethod = 0; // must not be after systemMessage!
 653.220 +		systemMessage(
 653.221 +		    0,
 653.222 +		    "The \"On Game\" text display mode does not work with this combination of renderers and filters.\nThe display mode is automatically being changed to \"In Game\" instead,\nbut this may cause message text to go into AVI recordings and screenshots.\nThis can be reconfigured by choosing \"Options->Video->Text Display Options...\"");
 653.223 +	}
 653.224 +*/
 653.225 +
 653.226 +	if (filterFunction)
 653.227 +	{
 653.228 +		bi->bmiHeader.biWidth  = theApp.rect.right;
 653.229 +		bi->bmiHeader.biHeight = -theApp.rect.bottom;
 653.230 +
 653.231 +		(*filterFunction)(pix + pitch,
 653.232 +						  pitch,
 653.233 +						  (u8 *)theApp.delta,
 653.234 +						  (u8 *)filterData,
 653.235 +						  filterPitch,
 653.236 +						  filterWidth,
 653.237 +						  filterHeight);
 653.238 +	}
 653.239 +
 653.240 +	if (theApp.showSpeed && theApp.videoOption > VIDEO_4X)
 653.241 +	{
 653.242 +		char buffer[30];
 653.243 +		if (theApp.showSpeed == 1)
 653.244 +			sprintf(buffer, "%3d%%", systemSpeed);
 653.245 +		else
 653.246 +			sprintf(buffer, "%3d%%(%d, %d fps)", systemSpeed,
 653.247 +			        systemFrameSkip,
 653.248 +			        theApp.showRenderedFrames);
 653.249 +
 653.250 +		if (filterFunction)
 653.251 +		{
 653.252 +			if (theApp.showSpeedTransparent)
 653.253 +				drawTextTransp((u8 *)filterData,
 653.254 +				               filterPitch,
 653.255 +				               theApp.rect.left+10,
 653.256 +				               theApp.rect.bottom-10,
 653.257 +				               buffer);
 653.258 +			else
 653.259 +				drawText((u8 *)filterData,
 653.260 +				         filterPitch,
 653.261 +			             theApp.rect.left+10,
 653.262 +			             theApp.rect.bottom-10,
 653.263 +				         buffer);
 653.264 +		}
 653.265 +		else
 653.266 +		{
 653.267 +			if (theApp.showSpeedTransparent)
 653.268 +				drawTextTransp((u8 *)pix,
 653.269 +				               pitch,
 653.270 +				               theApp.rect.left+10,
 653.271 +				               theApp.rect.bottom-10,
 653.272 +				               buffer);
 653.273 +			else
 653.274 +				drawText((u8 *)pix,
 653.275 +				         pitch,
 653.276 +			             theApp.rect.left+10,
 653.277 +			             theApp.rect.bottom-10,
 653.278 +				         buffer);
 653.279 +		}
 653.280 +	}
 653.281 +
 653.282 +	if (textMethod == 1 && filterFunction)
 653.283 +	{
 653.284 +		DrawTextMessages((u8 *)filterData, filterPitch, theApp.rect.left, theApp.rect.bottom);
 653.285 +	}
 653.286 +
 653.287 +	POINT p;
 653.288 +	p.x = theApp.dest.left;
 653.289 +	p.y = theApp.dest.top;
 653.290 +	CWnd *pWnd = theApp.m_pMainWnd;
 653.291 +	pWnd->ScreenToClient(&p);
 653.292 +	POINT p2;
 653.293 +	p2.x = theApp.dest.right;
 653.294 +	p2.y = theApp.dest.bottom;
 653.295 +	pWnd->ScreenToClient(&p2);
 653.296 +
 653.297 +	CDC *dc = pWnd->GetDC();
 653.298 +
 653.299 +	StretchDIBits((HDC)*dc,
 653.300 +	              p.x,
 653.301 +	              p.y,
 653.302 +	              p2.x - p.x,
 653.303 +	              p2.y - p.y,
 653.304 +	              0,
 653.305 +	              0,
 653.306 +	              theApp.rect.right,
 653.307 +	              theApp.rect.bottom,
 653.308 +	              filterFunction ? filterData : pix+pitch,
 653.309 +	              bi,
 653.310 +	              DIB_RGB_COLORS,
 653.311 +	              SRCCOPY);
 653.312 +
 653.313 +	if (textMethod == 2 || (textMethod == 1 && !filterFunction)) // HACK: so that textMethod isn't changed
 653.314 +		for (int slot = 0; slot < SCREEN_MESSAGE_SLOTS; slot++)
 653.315 +		{
 653.316 +			if (theApp.screenMessage[slot])
 653.317 +			{
 653.318 +				if ((theApp.screenMessageDuration[slot] < 0 || 
 653.319 +					(int)(GetTickCount() - theApp.screenMessageTime[slot]) < theApp.screenMessageDuration[slot]) &&
 653.320 +				    (!theApp.disableStatusMessage || slot == 1 || slot == 2))
 653.321 +				{
 653.322 +					dc->SetBkMode(TRANSPARENT);
 653.323 +
 653.324 +					if (outlinedText)
 653.325 +					{
 653.326 +						dc->SetTextColor(textColor != 7 ? RGB(0, 0, 0) : RGB(255, 255, 255));
 653.327 +
 653.328 +						// draw black outline
 653.329 +						const static int xd [8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 653.330 +						const static int yd [8] = {-1, -1, -1, 0, 1, 1, 1, 0};
 653.331 +						for (int i = 0; i < 8; i++)
 653.332 +						{
 653.333 +							dc->TextOut(p.x+10+xd[i], p2.y - 20*(slot+1)+yd[i], theApp.screenMessageBuffer[slot]);
 653.334 +						}
 653.335 +					}
 653.336 +
 653.337 +					COLORREF color;
 653.338 +					switch (textColor)
 653.339 +					{
 653.340 +					case 0:
 653.341 +						color = RGB(255, 255, 255); break;
 653.342 +					case 1:
 653.343 +						color = RGB(255, 0, 0); break;
 653.344 +					case 2:
 653.345 +						color = RGB(255, 255, 0); break;
 653.346 +					case 3:
 653.347 +						color = RGB(0, 255, 0); break;
 653.348 +					case 4:
 653.349 +						color = RGB(0, 255, 255); break;
 653.350 +					case 5:
 653.351 +						color = RGB(0, 0, 255); break;
 653.352 +					case 6:
 653.353 +						color = RGB(255, 0, 255); break;
 653.354 +					case 7:
 653.355 +						color = RGB(0, 0, 0); break;
 653.356 +					}
 653.357 +					dc->SetTextColor(color);
 653.358 +
 653.359 +					// draw center text
 653.360 +					dc->TextOut(p.x+10, p2.y - 20*(slot+1), theApp.screenMessageBuffer[slot]);
 653.361 +				}
 653.362 +				else
 653.363 +				{
 653.364 +					theApp.screenMessage[slot] = false;
 653.365 +				}
 653.366 +			}
 653.367 +		}
 653.368 +
 653.369 +	pWnd->ReleaseDC(dc);
 653.370 +}
 653.371 +
 653.372 +int GDIDisplay::selectFullScreenMode(GUID * *)
 653.373 +{
 653.374 +	HWND wnd = GetDesktopWindow();
 653.375 +	RECT r;
 653.376 +	GetWindowRect(wnd, &r);
 653.377 +	int w  = (r.right - r.left) & 4095;
 653.378 +	int h  = (r.bottom - r.top) & 4095;
 653.379 +	HDC dc = GetDC(wnd);
 653.380 +	int c  = GetDeviceCaps(dc, BITSPIXEL);
 653.381 +	ReleaseDC(wnd, dc);
 653.382 +
 653.383 +	return (c << 24) | (w << 12) | h;
 653.384 +}
 653.385 +
 653.386 +IDisplay *newGDIDisplay()
 653.387 +{
 653.388 +	return new GDIDisplay();
 653.389 +}
 653.390 +
   654.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   654.2 +++ b/src/win32/GSACodeSelect.cpp	Sat Mar 03 10:31:27 2012 -0600
   654.3 @@ -0,0 +1,96 @@
   654.4 +// GSACodeSelect.cpp : implementation file
   654.5 +//
   654.6 +
   654.7 +#include "stdafx.h"
   654.8 +#include "resource.h"
   654.9 +#include "GSACodeSelect.h"
  654.10 +
  654.11 +/////////////////////////////////////////////////////////////////////////////
  654.12 +// GSACodeSelect dialog
  654.13 +
  654.14 +GSACodeSelect::GSACodeSelect(FILE *file, CWnd*pParent /*=NULL*/)
  654.15 +	: CDialog(GSACodeSelect::IDD, pParent)
  654.16 +{
  654.17 +	//{{AFX_DATA_INIT(GSACodeSelect)
  654.18 +	// NOTE: the ClassWizard will add member initialization here
  654.19 +	//}}AFX_DATA_INIT
  654.20 +	m_file = file;
  654.21 +}
  654.22 +
  654.23 +void GSACodeSelect::DoDataExchange(CDataExchange*pDX)
  654.24 +{
  654.25 +	CDialog::DoDataExchange(pDX);
  654.26 +	//{{AFX_DATA_MAP(GSACodeSelect)
  654.27 +	DDX_Control(pDX, IDC_GAME_LIST, m_games);
  654.28 +	//}}AFX_DATA_MAP
  654.29 +}
  654.30 +
  654.31 +BEGIN_MESSAGE_MAP(GSACodeSelect, CDialog)
  654.32 +//{{AFX_MSG_MAP(GSACodeSelect)
  654.33 +ON_BN_CLICKED(ID_OK, OnOk)
  654.34 +ON_LBN_SELCHANGE(IDC_GAME_LIST, OnSelchangeGameList)
  654.35 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
  654.36 +//}}AFX_MSG_MAP
  654.37 +END_MESSAGE_MAP()
  654.38 +
  654.39 +/////////////////////////////////////////////////////////////////////////////
  654.40 +// GSACodeSelect message handlers
  654.41 +
  654.42 +void GSACodeSelect::OnCancel()
  654.43 +{
  654.44 +	EndDialog(-1);
  654.45 +}
  654.46 +
  654.47 +void GSACodeSelect::OnOk()
  654.48 +{
  654.49 +	EndDialog(m_games.GetCurSel());
  654.50 +}
  654.51 +
  654.52 +void GSACodeSelect::OnSelchangeGameList()
  654.53 +{
  654.54 +	int   item = m_games.GetCurSel();
  654.55 +	CWnd *ok   = GetDlgItem(ID_OK);
  654.56 +
  654.57 +	ok->EnableWindow(item != -1);
  654.58 +}
  654.59 +
  654.60 +BOOL GSACodeSelect::OnInitDialog()
  654.61 +{
  654.62 +	CDialog::OnInitDialog();
  654.63 +
  654.64 +	char buffer[1024];
  654.65 +
  654.66 +	FILE *f     = m_file;
  654.67 +	int   games = 0;
  654.68 +	int   len   = 0;
  654.69 +	fseek(f, -4, SEEK_CUR);
  654.70 +	fread(&games, 1, 4, f);
  654.71 +	while (games > 0)
  654.72 +	{
  654.73 +		fread(&len, 1, 4, f);
  654.74 +		fread(buffer, 1, len, f);
  654.75 +		buffer[len] = 0;
  654.76 +		m_games.AddString(buffer);
  654.77 +		int codes = 0;
  654.78 +		fread(&codes, 1, 4, f);
  654.79 +
  654.80 +		while (codes > 0)
  654.81 +		{
  654.82 +			fread(&len, 1, 4, f);
  654.83 +			fseek(f, len, SEEK_CUR);
  654.84 +			fread(&len, 1, 4, f);
  654.85 +			fseek(f, len, SEEK_CUR);
  654.86 +			fseek(f, 4, SEEK_CUR);
  654.87 +			fread(&len, 1, 4, f);
  654.88 +			fseek(f, len*12, SEEK_CUR);
  654.89 +			codes--;
  654.90 +		}
  654.91 +		games--;
  654.92 +	}
  654.93 +	GetDlgItem(ID_OK)->EnableWindow(FALSE);
  654.94 +	CenterWindow();
  654.95 +
  654.96 +	return TRUE; // return TRUE unless you set the focus to a control
  654.97 +	             // EXCEPTION: OCX Property Pages should return FALSE
  654.98 +}
  654.99 +
   655.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   655.2 +++ b/src/win32/GSACodeSelect.h	Sat Mar 03 10:31:27 2012 -0600
   655.3 @@ -0,0 +1,49 @@
   655.4 +#if !defined(AFX_GSACODESELECT_H__189BD94D_288F_4E2A_9395_EAB16F104D87__INCLUDED_)
   655.5 +#define AFX_GSACODESELECT_H__189BD94D_288F_4E2A_9395_EAB16F104D87__INCLUDED_
   655.6 +
   655.7 +#if _MSC_VER > 1000
   655.8 +#pragma once
   655.9 +#endif // _MSC_VER > 1000
  655.10 +// -*- C++ -*-
  655.11 +// GSACodeSelect.h : header file
  655.12 +//
  655.13 +
  655.14 +/////////////////////////////////////////////////////////////////////////////
  655.15 +// GSACodeSelect dialog
  655.16 +
  655.17 +class GSACodeSelect : public CDialog
  655.18 +{
  655.19 +	// Construction
  655.20 +public:
  655.21 +	GSACodeSelect(FILE *file, CWnd*pParent = NULL);  // standard constructor
  655.22 +
  655.23 +	// Dialog Data
  655.24 +	//{{AFX_DATA(GSACodeSelect)
  655.25 +	enum { IDD = IDD_CODE_SELECT };
  655.26 +	CListBox m_games;
  655.27 +	//}}AFX_DATA
  655.28 +	FILE *m_file;
  655.29 +
  655.30 +	// Overrides
  655.31 +	// ClassWizard generated virtual function overrides
  655.32 +	//{{AFX_VIRTUAL(GSACodeSelect)
  655.33 +protected:
  655.34 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  655.35 +	//}}AFX_VIRTUAL
  655.36 +
  655.37 +	// Implementation
  655.38 +protected:
  655.39 +	// Generated message map functions
  655.40 +	//{{AFX_MSG(GSACodeSelect)
  655.41 +	afx_msg void OnCancel();
  655.42 +	afx_msg void OnOk();
  655.43 +	afx_msg void OnSelchangeGameList();
  655.44 +	virtual BOOL OnInitDialog();
  655.45 +	//}}AFX_MSG
  655.46 +	DECLARE_MESSAGE_MAP()
  655.47 +};
  655.48 +
  655.49 +//{{AFX_INSERT_LOCATION}}
  655.50 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  655.51 +
  655.52 +#endif // !defined(AFX_GSACODESELECT_H__189BD94D_288F_4E2A_9395_EAB16F104D87__INCLUDED_)
   656.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   656.2 +++ b/src/win32/Hyperlink.cpp	Sat Mar 03 10:31:27 2012 -0600
   656.3 @@ -0,0 +1,93 @@
   656.4 +// Hyperlink.cpp : implementation file
   656.5 +//
   656.6 +
   656.7 +#include "stdafx.h"
   656.8 +#include "Hyperlink.h"
   656.9 +
  656.10 +/////////////////////////////////////////////////////////////////////////////
  656.11 +// Hyperlink
  656.12 +
  656.13 +Hyperlink::Hyperlink()
  656.14 +{
  656.15 +  m_over = false;
  656.16 +}
  656.17 +
  656.18 +Hyperlink::~Hyperlink()
  656.19 +{
  656.20 +  m_underlineFont.DeleteObject();
  656.21 +}
  656.22 +
  656.23 +
  656.24 +BEGIN_MESSAGE_MAP(Hyperlink, CStatic)
  656.25 +  //{{AFX_MSG_MAP(Hyperlink)
  656.26 +  ON_WM_CTLCOLOR_REFLECT()
  656.27 +  ON_WM_ERASEBKGND()
  656.28 +  ON_WM_MOUSEMOVE()
  656.29 +  //}}AFX_MSG_MAP
  656.30 +  ON_CONTROL_REFLECT(STN_CLICKED, OnClicked)
  656.31 +END_MESSAGE_MAP()
  656.32 +
  656.33 +  /////////////////////////////////////////////////////////////////////////////
  656.34 +// Hyperlink message handlers
  656.35 +
  656.36 +void Hyperlink::PreSubclassWindow() 
  656.37 +{
  656.38 +  DWORD dwStyle = GetStyle();
  656.39 +  ::SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);
  656.40 +
  656.41 +  // 32649 is the hand cursor
  656.42 +  m_cursor = LoadCursor(NULL, MAKEINTRESOURCE(32649));
  656.43 +
  656.44 +  CFont *font = GetFont();
  656.45 +
  656.46 +  LOGFONT lg;
  656.47 +  font->GetLogFont(&lg);
  656.48 +
  656.49 +  lg.lfUnderline = TRUE;
  656.50 +  
  656.51 +  m_underlineFont.CreateFontIndirect(&lg);
  656.52 +  SetFont(&m_underlineFont);
  656.53 +	
  656.54 +  CStatic::PreSubclassWindow();
  656.55 +}
  656.56 +
  656.57 +void Hyperlink::OnClicked()
  656.58 +{
  656.59 +  CString url;
  656.60 +  GetWindowText(url);
  656.61 +  ::ShellExecute(0, _T("open"), url, 
  656.62 +                 0, 0, SW_SHOWNORMAL);
  656.63 +}
  656.64 +
  656.65 +HBRUSH Hyperlink::CtlColor(CDC* pDC, UINT nCtlColor) 
  656.66 +{
  656.67 +  pDC->SetTextColor(RGB(0,0,240));
  656.68 +	
  656.69 +  return (HBRUSH)GetStockObject(NULL_BRUSH);
  656.70 +}
  656.71 +
  656.72 +BOOL Hyperlink::OnEraseBkgnd(CDC* pDC) 
  656.73 +{
  656.74 +  CRect rect;
  656.75 +  GetClientRect(rect);
  656.76 +  pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DFACE));
  656.77 +
  656.78 +  return TRUE;
  656.79 +}
  656.80 +
  656.81 +void Hyperlink::OnMouseMove(UINT nFlags, CPoint point) 
  656.82 +{
  656.83 +  if(!m_over) {
  656.84 +    m_over = true;
  656.85 +    SetCapture();
  656.86 +    ::SetCursor(m_cursor);
  656.87 +  } else {
  656.88 +    CRect r;
  656.89 +    GetClientRect(&r);
  656.90 +
  656.91 +    if(!r.PtInRect(point)) {
  656.92 +      m_over = false;
  656.93 +      ReleaseCapture();
  656.94 +    }
  656.95 +  }
  656.96 +}
   657.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   657.2 +++ b/src/win32/Hyperlink.h	Sat Mar 03 10:31:27 2012 -0600
   657.3 @@ -0,0 +1,54 @@
   657.4 +#if !defined(AFX_HYPERLINK_H__BECEAB7D_31FB_4727_A42B_8732162EEBCC__INCLUDED_)
   657.5 +#define AFX_HYPERLINK_H__BECEAB7D_31FB_4727_A42B_8732162EEBCC__INCLUDED_
   657.6 +
   657.7 +#if _MSC_VER > 1000
   657.8 +#pragma once
   657.9 +#endif // _MSC_VER > 1000
  657.10 +// Hyperlink.h : header file
  657.11 +//
  657.12 +
  657.13 +/////////////////////////////////////////////////////////////////////////////
  657.14 +// Hyperlink window
  657.15 +
  657.16 +class Hyperlink : public CStatic
  657.17 +{
  657.18 +// Construction
  657.19 +public:
  657.20 +	Hyperlink();
  657.21 +
  657.22 +// Attributes
  657.23 +public:
  657.24 +// Operations
  657.25 +public:
  657.26 +// Overrides
  657.27 +	// ClassWizard generated virtual function overrides
  657.28 +	//{{AFX_VIRTUAL(Hyperlink)
  657.29 +protected:
  657.30 +	virtual void PreSubclassWindow();
  657.31 +	//}}AFX_VIRTUAL
  657.32 +
  657.33 +// Implementation
  657.34 +public:
  657.35 +	bool    m_over;
  657.36 +	HCURSOR m_cursor;
  657.37 +	afx_msg void OnClicked();
  657.38 +	CFont m_underlineFont;
  657.39 +	virtual ~Hyperlink();
  657.40 +
  657.41 +	// Generated message map functions
  657.42 +protected:
  657.43 +	//{{AFX_MSG(Hyperlink)
  657.44 +	afx_msg HBRUSH CtlColor(CDC*pDC, UINT nCtlColor);
  657.45 +	afx_msg BOOL OnEraseBkgnd(CDC*pDC);
  657.46 +	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  657.47 +	//}}AFX_MSG
  657.48 +
  657.49 +	DECLARE_MESSAGE_MAP()
  657.50 +};
  657.51 +
  657.52 +/////////////////////////////////////////////////////////////////////////////
  657.53 +
  657.54 +//{{AFX_INSERT_LOCATION}}
  657.55 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  657.56 +
  657.57 +#endif // !defined(AFX_HYPERLINK_H__BECEAB7D_31FB_4727_A42B_8732162EEBCC__INCLUDED_)
   658.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   658.2 +++ b/src/win32/IOViewer.cpp	Sat Mar 03 10:31:27 2012 -0600
   658.3 @@ -0,0 +1,183 @@
   658.4 +// IOViewer.cpp : implementation file
   658.5 +//
   658.6 +
   658.7 +#include "stdafx.h"
   658.8 +#include "resource.h"
   658.9 +#include "IOViewer.h"
  658.10 +#include "VBA.h"
  658.11 +
  658.12 +#include "../gba/GBA.h" // CPUWriteHalfWord
  658.13 +#include "../gba/GBAGlobals.h"
  658.14 +
  658.15 +#include "IOViewerRegs.h"
  658.16 +
  658.17 +/////////////////////////////////////////////////////////////////////////////
  658.18 +// IOViewer dialog
  658.19 +
  658.20 +IOViewer::IOViewer(CWnd*pParent /*=NULL*/)
  658.21 +	: ResizeDlg(IOViewer::IDD, pParent)
  658.22 +{
  658.23 +	//{{AFX_DATA_INIT(IOViewer)
  658.24 +	// NOTE: the ClassWizard will add member initialization here
  658.25 +	//}}AFX_DATA_INIT
  658.26 +	selected   = 0;
  658.27 +	autoUpdate = false;
  658.28 +}
  658.29 +
  658.30 +void IOViewer::DoDataExchange(CDataExchange*pDX)
  658.31 +{
  658.32 +	CDialog::DoDataExchange(pDX);
  658.33 +	//{{AFX_DATA_MAP(IOViewer)
  658.34 +	DDX_Control(pDX, IDC_VALUE, m_value);
  658.35 +	DDX_Control(pDX, IDC_ADDRESSES, m_address);
  658.36 +	//}}AFX_DATA_MAP
  658.37 +}
  658.38 +
  658.39 +BEGIN_MESSAGE_MAP(IOViewer, CDialog)
  658.40 +//{{AFX_MSG_MAP(IOViewer)
  658.41 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
  658.42 +ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
  658.43 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
  658.44 +ON_CBN_SELCHANGE(IDC_ADDRESSES, OnSelchangeAddresses)
  658.45 +ON_BN_CLICKED(IDC_APPLY, OnApply)
  658.46 +//}}AFX_MSG_MAP
  658.47 +END_MESSAGE_MAP()
  658.48 +
  658.49 +/////////////////////////////////////////////////////////////////////////////
  658.50 +// IOViewer message handlers
  658.51 +
  658.52 +void IOViewer::OnClose()
  658.53 +{
  658.54 +	theApp.winRemoveUpdateListener(this);
  658.55 +
  658.56 +	DestroyWindow();
  658.57 +}
  658.58 +
  658.59 +void IOViewer::OnRefresh()
  658.60 +{
  658.61 +	// TODO: Add your control notification handler code here
  658.62 +}
  658.63 +
  658.64 +void IOViewer::OnAutoUpdate()
  658.65 +{
  658.66 +	autoUpdate = !autoUpdate;
  658.67 +	if (autoUpdate)
  658.68 +	{
  658.69 +		theApp.winAddUpdateListener(this);
  658.70 +	}
  658.71 +	else
  658.72 +	{
  658.73 +		theApp.winRemoveUpdateListener(this);
  658.74 +	}
  658.75 +}
  658.76 +
  658.77 +void IOViewer::OnSelchangeAddresses()
  658.78 +{
  658.79 +	selected = m_address.GetCurSel();
  658.80 +
  658.81 +	update();
  658.82 +}
  658.83 +
  658.84 +void IOViewer::PostNcDestroy()
  658.85 +{
  658.86 +	delete this;
  658.87 +}
  658.88 +
  658.89 +BOOL IOViewer::OnInitDialog()
  658.90 +{
  658.91 +	CDialog::OnInitDialog();
  658.92 +
  658.93 +	// winCenterWindow(getHandle());
  658.94 +	DIALOG_SIZER_START(sz)
  658.95 +	DIALOG_SIZER_END()
  658.96 +	SetData(sz,
  658.97 +	        TRUE,
  658.98 +	        HKEY_CURRENT_USER,
  658.99 +	        "Software\\Emulators\\VisualBoyAdvance\\Viewer\\IOView",
 658.100 +	        NULL);
 658.101 +
 658.102 +	CFont *font = CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT));
 658.103 +	int    i;
 658.104 +	for (i = 0; i < sizeof(ioViewRegisters)/sizeof(IOData); i++)
 658.105 +	{
 658.106 +		m_address.AddString(ioViewRegisters[i].name);
 658.107 +	}
 658.108 +	m_address.SetFont(font);
 658.109 +	for (i = 0; i < 16; i++)
 658.110 +	{
 658.111 +		GetDlgItem(IDC_BIT_0+i)->SetFont(font);
 658.112 +	}
 658.113 +
 658.114 +	RECT cbSize;
 658.115 +	int  Height;
 658.116 +
 658.117 +	m_address.GetClientRect(&cbSize);
 658.118 +	Height  = m_address.GetItemHeight(0);
 658.119 +	Height += m_address.GetItemHeight(0) * (10);
 658.120 +
 658.121 +	// Note: The use of SM_CYEDGE assumes that we're using Windows '95
 658.122 +	// Now add on the height of the border of the edit box
 658.123 +	Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges
 658.124 +
 658.125 +	// The height of the border of the drop-down box
 658.126 +	Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges
 658.127 +
 658.128 +	// now set the size of the window
 658.129 +	m_address.SetWindowPos(NULL,
 658.130 +	                       0, 0,
 658.131 +	                       cbSize.right, Height,
 658.132 +	                       SWP_NOMOVE | SWP_NOZORDER);
 658.133 +
 658.134 +	m_address.SetCurSel(0);
 658.135 +	update();
 658.136 +
 658.137 +	return TRUE; // return TRUE unless you set the focus to a control
 658.138 +	             // EXCEPTION: OCX Property Pages should return FALSE
 658.139 +}
 658.140 +
 658.141 +void IOViewer::update()
 658.142 +{
 658.143 +	CString buffer;
 658.144 +
 658.145 +	const IOData *sel = &ioViewRegisters[selected];
 658.146 +	u16 data = sel->address ? *sel->address :
 658.147 +	           (ioMem ? *((u16 *)&ioMem[sel->offset]) : 0);
 658.148 +
 658.149 +	for (int i = 0; i < 16; i++)
 658.150 +	{
 658.151 +		CButton *pWnd = (CButton *)GetDlgItem(IDC_BIT_0 + i);
 658.152 +
 658.153 +		if (pWnd)
 658.154 +		{
 658.155 +			if (!(sel->write & (1 << i)))
 658.156 +				pWnd->EnableWindow(FALSE);
 658.157 +			else
 658.158 +				pWnd->EnableWindow(TRUE);
 658.159 +			pWnd->SetCheck(((data & (1 << i)) >> i));
 658.160 +			buffer.Format("%2d %s", i, sel->bits[i]);
 658.161 +			pWnd->SetWindowText(buffer);
 658.162 +		}
 658.163 +	}
 658.164 +
 658.165 +	buffer.Format("%04X", data);
 658.166 +	m_value.SetWindowText(buffer);
 658.167 +}
 658.168 +
 658.169 +void IOViewer::OnApply()
 658.170 +{
 658.171 +	const IOData *sel = &ioViewRegisters[selected];
 658.172 +	u16 res = 0;
 658.173 +	for (int i = 0; i < 16; i++)
 658.174 +	{
 658.175 +		CButton *pWnd = (CButton *)GetDlgItem(IDC_BIT_0 + i);
 658.176 +
 658.177 +		if (pWnd)
 658.178 +		{
 658.179 +			if (pWnd->GetCheck())
 658.180 +				res |= (1 << i);
 658.181 +		}
 658.182 +	}
 658.183 +	CPUWriteHalfWord(0x4000000+sel->offset, res);
 658.184 +	update();
 658.185 +}
 658.186 +
   659.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   659.2 +++ b/src/win32/IOViewer.h	Sat Mar 03 10:31:27 2012 -0600
   659.3 @@ -0,0 +1,58 @@
   659.4 +#if !defined(AFX_IOVIEWER_H__9C266B78_FC02_4572_9062_0241802B0E76__INCLUDED_)
   659.5 +#define AFX_IOVIEWER_H__9C266B78_FC02_4572_9062_0241802B0E76__INCLUDED_
   659.6 +
   659.7 +#if _MSC_VER > 1000
   659.8 +#pragma once
   659.9 +#endif // _MSC_VER > 1000
  659.10 +// -*- C++ -*-
  659.11 +// IOViewer.h : header file
  659.12 +//
  659.13 +
  659.14 +#include "ResizeDlg.h"
  659.15 +#include "IUpdate.h"
  659.16 +
  659.17 +/////////////////////////////////////////////////////////////////////////////
  659.18 +// IOViewer dialog
  659.19 +
  659.20 +class IOViewer : public ResizeDlg, IUpdateListener
  659.21 +{
  659.22 +	// Construction
  659.23 +public:
  659.24 +	void update();
  659.25 +	bool autoUpdate;
  659.26 +	int  selected;
  659.27 +	IOViewer(CWnd*pParent = NULL);  // standard constructor
  659.28 +
  659.29 +	// Dialog Data
  659.30 +	//{{AFX_DATA(IOViewer)
  659.31 +	enum { IDD = IDD_IO_VIEWER };
  659.32 +	CStatic   m_value;
  659.33 +	CComboBox m_address;
  659.34 +	//}}AFX_DATA
  659.35 +
  659.36 +	// Overrides
  659.37 +	// ClassWizard generated virtual function overrides
  659.38 +	//{{AFX_VIRTUAL(IOViewer)
  659.39 +protected:
  659.40 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  659.41 +	virtual void PostNcDestroy();
  659.42 +	//}}AFX_VIRTUAL
  659.43 +
  659.44 +	// Implementation
  659.45 +protected:
  659.46 +	// Generated message map functions
  659.47 +	//{{AFX_MSG(IOViewer)
  659.48 +	afx_msg void OnClose();
  659.49 +	afx_msg void OnRefresh();
  659.50 +	afx_msg void OnAutoUpdate();
  659.51 +	afx_msg void OnSelchangeAddresses();
  659.52 +	virtual BOOL OnInitDialog();
  659.53 +	afx_msg void OnApply();
  659.54 +	//}}AFX_MSG
  659.55 +	DECLARE_MESSAGE_MAP()
  659.56 +};
  659.57 +
  659.58 +//{{AFX_INSERT_LOCATION}}
  659.59 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  659.60 +
  659.61 +#endif // !defined(AFX_IOVIEWER_H__9C266B78_FC02_4572_9062_0241802B0E76__INCLUDED_)
   660.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   660.2 +++ b/src/win32/IOViewerRegs.h	Sat Mar 03 10:31:27 2012 -0600
   660.3 @@ -0,0 +1,2078 @@
   660.4 +#ifndef VBA_IOVIEWERREGS_H
   660.5 +#define VBA_IOVIEWERREGS_H
   660.6 +
   660.7 +#if _MSC_VER > 1000
   660.8 +#pragma once
   660.9 +#endif // _MSC_VER > 1000
  660.10 +
  660.11 +struct IOData
  660.12 +{
  660.13 +	u16 * address;
  660.14 +	u16   offset;
  660.15 +	char *name;
  660.16 +	u16   write;
  660.17 +	char *bits[16];
  660.18 +};
  660.19 +
  660.20 +const IOData ioViewRegisters[] = {
  660.21 +	{
  660.22 +		&DISPCNT, 0, "0x4000000-DISPCNT", 0xFFF7,
  660.23 +		{
  660.24 +			"",
  660.25 +			"",
  660.26 +			"BG Mode (3 bits)",
  660.27 +			"CGB Mode",
  660.28 +			"Display Frame",
  660.29 +			"H-Blank Interval OBJ processing",
  660.30 +			"OBJ Character mapping",
  660.31 +			"Forced blank",
  660.32 +			"BG0",
  660.33 +			"BG1",
  660.34 +			"BG2",
  660.35 +			"BG3",
  660.36 +			"OBJ",
  660.37 +			"WIN0",
  660.38 +			"WIN1",
  660.39 +			"OBJWIN"
  660.40 +		}
  660.41 +	},
  660.42 +	{
  660.43 +		&DISPSTAT, 4, "0x4000004-DISPSTAT", 0xFF38,
  660.44 +		{
  660.45 +			"V-Blank Status",
  660.46 +			"H-Blank Status",
  660.47 +			"VCOUNT Evaluation",
  660.48 +			"V-Blank Interrupt Enable",
  660.49 +			"H-Blank Interrupt Enable",
  660.50 +			"VCOUNT Match Interrupt Enable",
  660.51 +			"",
  660.52 +			"",
  660.53 +			"",
  660.54 +			"",
  660.55 +			"",
  660.56 +			"",
  660.57 +			"",
  660.58 +			"",
  660.59 +			"",
  660.60 +			"VCOUNT setting (8 bits)"
  660.61 +		}
  660.62 +	},
  660.63 +	{
  660.64 +		&VCOUNT, 6, "0x4000006-VCOUNT", 0x0000,
  660.65 +		{
  660.66 +			"",
  660.67 +			"",
  660.68 +			"",
  660.69 +			"",
  660.70 +			"",
  660.71 +			"",
  660.72 +			"",
  660.73 +			"VCOUNT (8 bits)",
  660.74 +			"",
  660.75 +			"",
  660.76 +			"",
  660.77 +			"",
  660.78 +			"",
  660.79 +			"",
  660.80 +			"",
  660.81 +			""
  660.82 +		}
  660.83 +	},
  660.84 +	{
  660.85 +		&BG0CNT, 8, "0x4000008-BG0CNT", 0xDFCF,
  660.86 +		{
  660.87 +			"",
  660.88 +			"Priority (2 bits)",
  660.89 +			"",
  660.90 +			"Char base (2 bits)",
  660.91 +			"",
  660.92 +			"",
  660.93 +			"Mosaic",
  660.94 +			"16/256 colors",
  660.95 +			"",
  660.96 +			"",
  660.97 +			"",
  660.98 +			"",
  660.99 +			"Screen Base Block (5 bits)",
 660.100 +			"",
 660.101 +			"",
 660.102 +			"Size (2 bits)"
 660.103 +		}
 660.104 +	},
 660.105 +	{
 660.106 +		&BG1CNT, 0xA, "0x400000A-BG1CNT", 0xDFCF,
 660.107 +		{
 660.108 +			"",
 660.109 +			"Priority (2 bits)",
 660.110 +			"",
 660.111 +			"Char base (2 bits)",
 660.112 +			"",
 660.113 +			"",
 660.114 +			"Mosaic",
 660.115 +			"16/256 colors",
 660.116 +			"",
 660.117 +			"",
 660.118 +			"",
 660.119 +			"",
 660.120 +			"Screen Base Block (5 bits)",
 660.121 +			"",
 660.122 +			"",
 660.123 +			"Size (2 bits)"
 660.124 +		}
 660.125 +	},
 660.126 +	{
 660.127 +		&BG2CNT, 0xC, "0x400000C-BG2CNT", 0xFFCF,
 660.128 +		{
 660.129 +			"",
 660.130 +			"Priority (2 bits)",
 660.131 +			"",
 660.132 +			"Char base (2 bits)",
 660.133 +			"",
 660.134 +			"",
 660.135 +			"Mosaic",
 660.136 +			"16/256 colors",
 660.137 +			"",
 660.138 +			"",
 660.139 +			"",
 660.140 +			"",
 660.141 +			"Screen Base Block (5 bits)",
 660.142 +			"Area Overflow",
 660.143 +			"",
 660.144 +			"Size (2 bits)"
 660.145 +		}
 660.146 +	},
 660.147 +	{
 660.148 +		&BG3CNT, 0xE, "0x400000E-BG3CNT", 0xFFCF,
 660.149 +		{
 660.150 +			"",
 660.151 +			"Priority (2 bits)",
 660.152 +			"",
 660.153 +			"Char base (2 bits)",
 660.154 +			"",
 660.155 +			"",
 660.156 +			"Mosaic",
 660.157 +			"16/256 colors",
 660.158 +			"",
 660.159 +			"",
 660.160 +			"",
 660.161 +			"",
 660.162 +			"Screen Base Block (5 bits)",
 660.163 +			"Area Overflow",
 660.164 +			"",
 660.165 +			"Size (2 bits)"
 660.166 +		}
 660.167 +	},
 660.168 +	{
 660.169 +		&BG0HOFS, 0x10, "0x4000010-BG0HOFS", 0x01FF,
 660.170 +		{
 660.171 +			"",
 660.172 +			"",
 660.173 +			"",
 660.174 +			"",
 660.175 +			"",
 660.176 +			"",
 660.177 +			"",
 660.178 +			"",
 660.179 +			"Horizontal Offset (9 bits, W)",
 660.180 +			"",
 660.181 +			"",
 660.182 +			"",
 660.183 +			"",
 660.184 +			"",
 660.185 +			"",
 660.186 +			""
 660.187 +		}
 660.188 +	},
 660.189 +	{
 660.190 +		&BG0VOFS, 0x12, "0x4000012-BG0VOFS", 0x01FF,
 660.191 +		{
 660.192 +			"",
 660.193 +			"",
 660.194 +			"",
 660.195 +			"",
 660.196 +			"",
 660.197 +			"",
 660.198 +			"",
 660.199 +			"",
 660.200 +			"Vertical Offset (9 bits, W)",
 660.201 +			"",
 660.202 +			"",
 660.203 +			"",
 660.204 +			"",
 660.205 +			"",
 660.206 +			"",
 660.207 +			""
 660.208 +		}
 660.209 +	},
 660.210 +	{
 660.211 +		&BG1HOFS, 0x14, "0x4000014-BG1HOFS", 0x01FF,
 660.212 +		{
 660.213 +			"",
 660.214 +			"",
 660.215 +			"",
 660.216 +			"",
 660.217 +			"",
 660.218 +			"",
 660.219 +			"",
 660.220 +			"",
 660.221 +			"Horizontal Offset (9 bits, W)",
 660.222 +			"",
 660.223 +			"",
 660.224 +			"",
 660.225 +			"",
 660.226 +			"",
 660.227 +			"",
 660.228 +			""
 660.229 +		}
 660.230 +	},
 660.231 +	{
 660.232 +		&BG1VOFS, 0x16, "0x4000016-BG1VOFS", 0x01FF,
 660.233 +		{
 660.234 +			"",
 660.235 +			"",
 660.236 +			"",
 660.237 +			"",
 660.238 +			"",
 660.239 +			"",
 660.240 +			"",
 660.241 +			"",
 660.242 +			"Vertical Offset (9 bits, W)",
 660.243 +			"",
 660.244 +			"",
 660.245 +			"",
 660.246 +			"",
 660.247 +			"",
 660.248 +			"",
 660.249 +			""
 660.250 +		}
 660.251 +	},
 660.252 +	{
 660.253 +		&BG2HOFS, 0x18, "0x4000018-BG8HOFS", 0x01FF,
 660.254 +		{
 660.255 +			"",
 660.256 +			"",
 660.257 +			"",
 660.258 +			"",
 660.259 +			"",
 660.260 +			"",
 660.261 +			"",
 660.262 +			"",
 660.263 +			"Horizontal Offset (9 bits, W)",
 660.264 +			"",
 660.265 +			"",
 660.266 +			"",
 660.267 +			"",
 660.268 +			"",
 660.269 +			"",
 660.270 +			""
 660.271 +		}
 660.272 +	},
 660.273 +	{
 660.274 +		&BG2VOFS, 0x1A, "0x400001A-BG2VOFS", 0x01FF,
 660.275 +		{
 660.276 +			"",
 660.277 +			"",
 660.278 +			"",
 660.279 +			"",
 660.280 +			"",
 660.281 +			"",
 660.282 +			"",
 660.283 +			"",
 660.284 +			"Vertical Offset (9 bits, W)",
 660.285 +			"",
 660.286 +			"",
 660.287 +			"",
 660.288 +			"",
 660.289 +			"",
 660.290 +			"",
 660.291 +			""
 660.292 +		}
 660.293 +	},
 660.294 +	{
 660.295 +		&BG3HOFS, 0x1C, "0x400001C-BG3HOFS", 0x01FF,
 660.296 +		{
 660.297 +			"",
 660.298 +			"",
 660.299 +			"",
 660.300 +			"",
 660.301 +			"",
 660.302 +			"",
 660.303 +			"",
 660.304 +			"",
 660.305 +			"Horizontal Offset (9 bits,W)",
 660.306 +			"",
 660.307 +			"",
 660.308 +			"",
 660.309 +			"",
 660.310 +			"",
 660.311 +			"",
 660.312 +			""
 660.313 +		}
 660.314 +	},
 660.315 +	{
 660.316 +		&BG3VOFS, 0x1E, "0x400001E-BG3VOFS", 0x01FF,
 660.317 +		{
 660.318 +			"",
 660.319 +			"",
 660.320 +			"",
 660.321 +			"",
 660.322 +			"",
 660.323 +			"",
 660.324 +			"",
 660.325 +			"",
 660.326 +			"Vertical Offset (9 bits,W)",
 660.327 +			"",
 660.328 +			"",
 660.329 +			"",
 660.330 +			"",
 660.331 +			"",
 660.332 +			"",
 660.333 +			""
 660.334 +		}
 660.335 +	},
 660.336 +	{
 660.337 +		&BG2PA, 0x20, "0x4000020-BG2PA", 0xFFFF,
 660.338 +		{
 660.339 +			"",
 660.340 +			"",
 660.341 +			"",
 660.342 +			"",
 660.343 +			"",
 660.344 +			"",
 660.345 +			"",
 660.346 +			"",
 660.347 +			"",
 660.348 +			"",
 660.349 +			"",
 660.350 +			"",
 660.351 +			"",
 660.352 +			"",
 660.353 +			"",
 660.354 +			"dx (16 bits,W)"
 660.355 +		}
 660.356 +	},
 660.357 +	{
 660.358 +		&BG2PB, 0x22, "0x4000022-BG2PB", 0xFFFF,
 660.359 +		{
 660.360 +			"",
 660.361 +			"",
 660.362 +			"",
 660.363 +			"",
 660.364 +			"",
 660.365 +			"",
 660.366 +			"",
 660.367 +			"",
 660.368 +			"",
 660.369 +			"",
 660.370 +			"",
 660.371 +			"",
 660.372 +			"",
 660.373 +			"",
 660.374 +			"",
 660.375 +			"dmx (16 bits,W)"
 660.376 +		}
 660.377 +	},
 660.378 +	{
 660.379 +		&BG2PC, 0x24, "0x4000024-BG2PC", 0xFFFF,
 660.380 +		{
 660.381 +			"",
 660.382 +			"",
 660.383 +			"",
 660.384 +			"",
 660.385 +			"",
 660.386 +			"",
 660.387 +			"",
 660.388 +			"",
 660.389 +			"",
 660.390 +			"",
 660.391 +			"",
 660.392 +			"",
 660.393 +			"",
 660.394 +			"",
 660.395 +			"",
 660.396 +			"dy (16 bits,W)"
 660.397 +		}
 660.398 +	},
 660.399 +	{
 660.400 +		&BG2PD, 0x26, "0x4000026-BG2PD", 0xFFFF,
 660.401 +		{
 660.402 +			"",
 660.403 +			"",
 660.404 +			"",
 660.405 +			"",
 660.406 +			"",
 660.407 +			"",
 660.408 +			"",
 660.409 +			"",
 660.410 +			"",
 660.411 +			"",
 660.412 +			"",
 660.413 +			"",
 660.414 +			"",
 660.415 +			"",
 660.416 +			"",
 660.417 +			"dmy (16 bits,W)"
 660.418 +		}
 660.419 +	},
 660.420 +	{
 660.421 +		&BG2X_L, 0x28, "0x4000028-BG2X_L", 0xFFFF,
 660.422 +		{
 660.423 +			"",
 660.424 +			"",
 660.425 +			"",
 660.426 +			"",
 660.427 +			"",
 660.428 +			"",
 660.429 +			"",
 660.430 +			"",
 660.431 +			"",
 660.432 +			"",
 660.433 +			"",
 660.434 +			"",
 660.435 +			"",
 660.436 +			"",
 660.437 +			"",
 660.438 +			"X low bits (16 bits,W)"
 660.439 +		}
 660.440 +	},
 660.441 +	{
 660.442 +		&BG2X_H, 0x2A, "0x400002A-BG2X_H", 0x0FFF,
 660.443 +		{
 660.444 +			"",
 660.445 +			"",
 660.446 +			"",
 660.447 +			"",
 660.448 +			"",
 660.449 +			"",
 660.450 +			"",
 660.451 +			"",
 660.452 +			"",
 660.453 +			"",
 660.454 +			"",
 660.455 +			"X high bits (12 bits,W)",
 660.456 +			"",
 660.457 +			"",
 660.458 +			"",
 660.459 +			"",
 660.460 +		}
 660.461 +	},
 660.462 +	{
 660.463 +		&BG2Y_L, 0x2C, "0x400002C-BG2Y_L", 0xFFFF,
 660.464 +		{
 660.465 +			"",
 660.466 +			"",
 660.467 +			"",
 660.468 +			"",
 660.469 +			"",
 660.470 +			"",
 660.471 +			"",
 660.472 +			"",
 660.473 +			"",
 660.474 +			"",
 660.475 +			"",
 660.476 +			"",
 660.477 +			"",
 660.478 +			"",
 660.479 +			"",
 660.480 +			"Y low bits (16 bits,W)"
 660.481 +		}
 660.482 +	},
 660.483 +	{
 660.484 +		&BG2Y_H, 0x2E, "0x400002E-BG2Y_H", 0x0FFF,
 660.485 +		{
 660.486 +			"",
 660.487 +			"",
 660.488 +			"",
 660.489 +			"",
 660.490 +			"",
 660.491 +			"",
 660.492 +			"",
 660.493 +			"",
 660.494 +			"",
 660.495 +			"",
 660.496 +			"",
 660.497 +			"Y hight bits (12 bits,W)",
 660.498 +			"",
 660.499 +			"",
 660.500 +			"",
 660.501 +			"",
 660.502 +		}
 660.503 +	},
 660.504 +	{
 660.505 +		&BG3PA, 0x30, "0x4000030-BG3PA", 0xFFFF,
 660.506 +		{
 660.507 +			"",
 660.508 +			"",
 660.509 +			"",
 660.510 +			"",
 660.511 +			"",
 660.512 +			"",
 660.513 +			"",
 660.514 +			"",
 660.515 +			"",
 660.516 +			"",
 660.517 +			"",
 660.518 +			"",
 660.519 +			"",
 660.520 +			"",
 660.521 +			"",
 660.522 +			"dx (16 bits,W)"
 660.523 +		}
 660.524 +	},
 660.525 +	{
 660.526 +		&BG3PB, 0x32, "0x4000032-BG3PB", 0xFFFF,
 660.527 +		{
 660.528 +			"",
 660.529 +			"",
 660.530 +			"",
 660.531 +			"",
 660.532 +			"",
 660.533 +			"",
 660.534 +			"",
 660.535 +			"",
 660.536 +			"",
 660.537 +			"",
 660.538 +			"",
 660.539 +			"",
 660.540 +			"",
 660.541 +			"",
 660.542 +			"",
 660.543 +			"dmx (16 bits,W)"
 660.544 +		}
 660.545 +	},
 660.546 +	{
 660.547 +		&BG3PC, 0x34, "0x4000034-BG3PC", 0xFFFF,
 660.548 +		{
 660.549 +			"",
 660.550 +			"",
 660.551 +			"",
 660.552 +			"",
 660.553 +			"",
 660.554 +			"",
 660.555 +			"",
 660.556 +			"",
 660.557 +			"",
 660.558 +			"",
 660.559 +			"",
 660.560 +			"",
 660.561 +			"",
 660.562 +			"",
 660.563 +			"",
 660.564 +			"dy (16 bits,W)"
 660.565 +		}
 660.566 +	},
 660.567 +	{
 660.568 +		&BG3PD, 0x36, "0x4000036-BG3PD", 0xFFFF,
 660.569 +		{
 660.570 +			"",
 660.571 +			"",
 660.572 +			"",
 660.573 +			"",
 660.574 +			"",
 660.575 +			"",
 660.576 +			"",
 660.577 +			"",
 660.578 +			"",
 660.579 +			"",
 660.580 +			"",
 660.581 +			"",
 660.582 +			"",
 660.583 +			"",
 660.584 +			"",
 660.585 +			"dmy (16 bits,W)"
 660.586 +		}
 660.587 +	},
 660.588 +	{
 660.589 +		&BG3X_L, 0x38, "0x4000038-BG3X_L", 0xFFFF,
 660.590 +		{
 660.591 +			"",
 660.592 +			"",
 660.593 +			"",
 660.594 +			"",
 660.595 +			"",
 660.596 +			"",
 660.597 +			"",
 660.598 +			"",
 660.599 +			"",
 660.600 +			"",
 660.601 +			"",
 660.602 +			"",
 660.603 +			"",
 660.604 +			"",
 660.605 +			"",
 660.606 +			"X low bits (16 bits,W)"
 660.607 +		}
 660.608 +	},
 660.609 +	{
 660.610 +		&BG3X_H, 0x3A, "0x400003A-BG3X_H", 0x0FFF,
 660.611 +		{
 660.612 +			"",
 660.613 +			"",
 660.614 +			"",
 660.615 +			"",
 660.616 +			"",
 660.617 +			"",
 660.618 +			"",
 660.619 +			"",
 660.620 +			"",
 660.621 +			"",
 660.622 +			"",
 660.623 +			"X hight bits (12 bits,W)",
 660.624 +			"",
 660.625 +			"",
 660.626 +			"",
 660.627 +			"",
 660.628 +		}
 660.629 +	},
 660.630 +	{
 660.631 +		&BG3Y_L, 0x3C, "0x400003C-BG3Y_L", 0xFFFF,
 660.632 +		{
 660.633 +			"",
 660.634 +			"",
 660.635 +			"",
 660.636 +			"",
 660.637 +			"",
 660.638 +			"",
 660.639 +			"",
 660.640 +			"",
 660.641 +			"",
 660.642 +			"",
 660.643 +			"",
 660.644 +			"",
 660.645 +			"",
 660.646 +			"",
 660.647 +			"",
 660.648 +			"Y low bits (16 bits,W)"
 660.649 +		}
 660.650 +	},
 660.651 +	{
 660.652 +		&BG3Y_H, 0x3E, "0x400003E-BG3Y_H", 0x0FFF,
 660.653 +		{
 660.654 +			"",
 660.655 +			"",
 660.656 +			"",
 660.657 +			"",
 660.658 +			"",
 660.659 +			"",
 660.660 +			"",
 660.661 +			"",
 660.662 +			"",
 660.663 +			"",
 660.664 +			"",
 660.665 +			"Y hight bits (12 bits,W)",
 660.666 +			"",
 660.667 +			"",
 660.668 +			"",
 660.669 +			"",
 660.670 +		}
 660.671 +	},
 660.672 +	{
 660.673 +		&WIN0H, 0x40, "0x4000040-WIN0H", 0xFFFF,
 660.674 +		{
 660.675 +			"",
 660.676 +			"",
 660.677 +			"",
 660.678 +			"",
 660.679 +			"",
 660.680 +			"",
 660.681 +			"",
 660.682 +			"Win 0 lower-right X (8 bits,W)",
 660.683 +			"",
 660.684 +			"",
 660.685 +			"",
 660.686 +			"",
 660.687 +			"",
 660.688 +			"",
 660.689 +			"",
 660.690 +			"Win 0 upper-left X (8 bits,W)",
 660.691 +		}
 660.692 +	},
 660.693 +	{
 660.694 +		&WIN1H, 0x42, "0x4000042-WIN1H", 0xFFFF,
 660.695 +		{
 660.696 +			"",
 660.697 +			"",
 660.698 +			"",
 660.699 +			"",
 660.700 +			"",
 660.701 +			"",
 660.702 +			"",
 660.703 +			"Win 1 lower-right X (8 bits,W)",
 660.704 +			"",
 660.705 +			"",
 660.706 +			"",
 660.707 +			"",
 660.708 +			"",
 660.709 +			"",
 660.710 +			"",
 660.711 +			"Win 1 upper-left (8 bits,W)",
 660.712 +		}
 660.713 +	},
 660.714 +	{
 660.715 +		&WIN0V, 0x44, "0x4000044-WIN0V", 0xFFFF,
 660.716 +		{
 660.717 +			"",
 660.718 +			"",
 660.719 +			"",
 660.720 +			"",
 660.721 +			"",
 660.722 +			"",
 660.723 +			"",
 660.724 +			"Win 0 lower-right Y (8 bits,W)",
 660.725 +			"",
 660.726 +			"",
 660.727 +			"",
 660.728 +			"",
 660.729 +			"",
 660.730 +			"",
 660.731 +			"",
 660.732 +			"Win 0 upper-left Y (8 bits,W)",
 660.733 +		}
 660.734 +	},
 660.735 +	{
 660.736 +		&WIN1V, 0x46, "0x4000046-WIN1V", 0xFFFF,
 660.737 +		{
 660.738 +			"",
 660.739 +			"",
 660.740 +			"",
 660.741 +			"",
 660.742 +			"",
 660.743 +			"",
 660.744 +			"",
 660.745 +			"Win 1 lower-right Y (8 bits,W)",
 660.746 +			"",
 660.747 +			"",
 660.748 +			"",
 660.749 +			"",
 660.750 +			"",
 660.751 +			"",
 660.752 +			"",
 660.753 +			"Win 1 upper-left Y (8 bits,W)",
 660.754 +		}
 660.755 +	},
 660.756 +	{
 660.757 +		&WININ, 0x48, "0x4000048-WININ", 0x3F3F,
 660.758 +		{
 660.759 +			"WIN0 BG0",
 660.760 +			"WIN0 BG1",
 660.761 +			"WIN0 BG2",
 660.762 +			"WIN0 BG3",
 660.763 +			"WIN0 OBJ",
 660.764 +			"WIN0 Special FX",
 660.765 +			"",
 660.766 +			"",
 660.767 +			"WIN1 BG0",
 660.768 +			"WIN1 BG1",
 660.769 +			"WIN1 BG2",
 660.770 +			"WIN1 BG3",
 660.771 +			"WIN1 OBJ",
 660.772 +			"WIN1 Special FX",
 660.773 +			"",
 660.774 +			"",
 660.775 +		}
 660.776 +	},
 660.777 +	{
 660.778 +		&WINOUT, 0x4A, "0x400004A-WINOUT", 0x3F3F,
 660.779 +		{
 660.780 +			"WIN0/1 BG0",
 660.781 +			"WIN0/1 BG1",
 660.782 +			"WIN0/1 BG2",
 660.783 +			"WIN0/1 BG3",
 660.784 +			"WIN0/1 OBJ",
 660.785 +			"WIN0/1 Special FX",
 660.786 +			"",
 660.787 +			"",
 660.788 +			"OBJWIN BG0",
 660.789 +			"OBJWIN BG1",
 660.790 +			"OBJWIN BG2",
 660.791 +			"OBJWIN BG3",
 660.792 +			"OBJWIN OBJ",
 660.793 +			"OBJWIN Special FX",
 660.794 +			"",
 660.795 +			"",
 660.796 +		}
 660.797 +	},
 660.798 +	{
 660.799 +		&MOSAIC, 0x4C, "0x400004C-MOSAIC", 0xFFFF,
 660.800 +		{
 660.801 +			"",
 660.802 +			"",
 660.803 +			"",
 660.804 +			"BG H Size (4 bits,W)",
 660.805 +			"",
 660.806 +			"",
 660.807 +			"",
 660.808 +			"BG V Size (4 bits,W)",
 660.809 +			"",
 660.810 +			"",
 660.811 +			"",
 660.812 +			"OBJ H Size (4 bits,W)",
 660.813 +			"",
 660.814 +			"",
 660.815 +			"",
 660.816 +			"OBJ V Size (4 bits,W)",
 660.817 +		}
 660.818 +	},
 660.819 +	{
 660.820 +		&BLDMOD, 0x50, "0x4000050-BLDMOD", 0x3FFF,
 660.821 +		{
 660.822 +			"1st BG0",
 660.823 +			"1st BG1",
 660.824 +			"1st BG2",
 660.825 +			"1st BG3",
 660.826 +			"1st OBJ",
 660.827 +			"1st BD",
 660.828 +			"",
 660.829 +			"FX Type (2 bits)",
 660.830 +			"2nd BG0",
 660.831 +			"2nd BG1",
 660.832 +			"2nd BG2",
 660.833 +			"2nd BG3",
 660.834 +			"2nd OBJ",
 660.835 +			"2nd BD",
 660.836 +			"",
 660.837 +			"",
 660.838 +		}
 660.839 +	},
 660.840 +	{
 660.841 +		&COLEV, 0x52, "0x4000052-COLEV", 0x1F1F,
 660.842 +		{
 660.843 +			"",
 660.844 +			"",
 660.845 +			"",
 660.846 +			"",
 660.847 +			"Coefficient EVA (5 bits,W)",
 660.848 +			"",
 660.849 +			"",
 660.850 +			"",
 660.851 +			"",
 660.852 +			"",
 660.853 +			"",
 660.854 +			"",
 660.855 +			"Coefficient EVB (5 bits,W)",
 660.856 +			"",
 660.857 +			"",
 660.858 +			"",
 660.859 +		}
 660.860 +	},
 660.861 +	{
 660.862 +		&COLY, 0x54, "0x4000054-COLEY", 0x001F,
 660.863 +		{
 660.864 +			"",
 660.865 +			"",
 660.866 +			"",
 660.867 +			"",
 660.868 +			"Coefficient EVY (5 bits,W)",
 660.869 +			"",
 660.870 +			"",
 660.871 +			"",
 660.872 +			"",
 660.873 +			"",
 660.874 +			"",
 660.875 +			"",
 660.876 +			"",
 660.877 +			"",
 660.878 +			"",
 660.879 +			"",
 660.880 +		}
 660.881 +	},
 660.882 +	{
 660.883 +		NULL, 0x60, "0x4000060-SG10_L", 0x007F,
 660.884 +		{
 660.885 +			"",
 660.886 +			"",
 660.887 +			"Sweep Shifts (3 bits)",
 660.888 +			"Sweep addition/decrease",
 660.889 +			"",
 660.890 +			"",
 660.891 +			"Sweep Time (3 bits)",
 660.892 +			"",
 660.893 +			"",
 660.894 +			"",
 660.895 +			"",
 660.896 +			"",
 660.897 +			"",
 660.898 +			"",
 660.899 +			"",
 660.900 +			"",
 660.901 +		}
 660.902 +	},
 660.903 +	{
 660.904 +		NULL, 0x62, "0x4000062-SG10_H", 0xFFFF,
 660.905 +		{
 660.906 +			"",
 660.907 +			"",
 660.908 +			"",
 660.909 +			"",
 660.910 +			"",
 660.911 +			"Sound Length (6 bits,W)",
 660.912 +			"",
 660.913 +			"Waveform Type (2 bits)",
 660.914 +			"",
 660.915 +			"",
 660.916 +			"Envelope Steps (3 bits)",
 660.917 +			"Envelope Attenuate/Amplify",
 660.918 +			"",
 660.919 +			"",
 660.920 +			"",
 660.921 +			"Envelope Initial Value",
 660.922 +		}
 660.923 +	},
 660.924 +	{
 660.925 +		NULL, 0x64, "0x4000064-SG11", 0xC7FF,
 660.926 +		{
 660.927 +			"",
 660.928 +			"",
 660.929 +			"",
 660.930 +			"",
 660.931 +			"",
 660.932 +			"",
 660.933 +			"",
 660.934 +			"",
 660.935 +			"",
 660.936 +			"",
 660.937 +			"Frequency (11 bits,W)",
 660.938 +			"",
 660.939 +			"",
 660.940 +			"",
 660.941 +			"Sound Continuous/Counter",
 660.942 +			"Initialization (W)",
 660.943 +		}
 660.944 +	},
 660.945 +	{
 660.946 +		NULL, 0x68, "0x4000068-SG20", 0xFFFF,
 660.947 +		{
 660.948 +			"",
 660.949 +			"",
 660.950 +			"",
 660.951 +			"",
 660.952 +			"",
 660.953 +			"Sound Length (6 bits,W)",
 660.954 +			"",
 660.955 +			"Waveform Type (2 bits)",
 660.956 +			"",
 660.957 +			"",
 660.958 +			"Envelope Steps (3 bits)",
 660.959 +			"Envelope Attenuate/Amplify",
 660.960 +			"",
 660.961 +			"",
 660.962 +			"",
 660.963 +			"Envelope Initial Value",
 660.964 +		}
 660.965 +	},
 660.966 +	{
 660.967 +		NULL, 0x6C, "0x400006C-SG21", 0xC7FF,
 660.968 +		{
 660.969 +			"",
 660.970 +			"",
 660.971 +			"",
 660.972 +			"",
 660.973 +			"",
 660.974 +			"",
 660.975 +			"",
 660.976 +			"",
 660.977 +			"",
 660.978 +			"",
 660.979 +			"Frequency (11 bits,W)",
 660.980 +			"",
 660.981 +			"",
 660.982 +			"",
 660.983 +			"Sound Continuous/Counter",
 660.984 +			"Initialization (W)",
 660.985 +		}
 660.986 +	},
 660.987 +	{
 660.988 +		NULL, 0x70, "0x4000070-SG30_L", 0x00E0,
 660.989 +		{
 660.990 +			"",
 660.991 +			"",
 660.992 +			"",
 660.993 +			"",
 660.994 +			"",
 660.995 +			"Waveform 32/64 Steps",
 660.996 +			"Waveform Bank 0/1",
 660.997 +			"Sound Output",
 660.998 +			"",
 660.999 +			"",
660.1000 +			"",
660.1001 +			"",
660.1002 +			"",
660.1003 +			"",
660.1004 +			"",
660.1005 +			"",
660.1006 +		}
660.1007 +	},
660.1008 +	{
660.1009 +		NULL, 0x72, "0x4000072-SG30_H", 0xE0FF,
660.1010 +		{
660.1011 +			"",
660.1012 +			"",
660.1013 +			"",
660.1014 +			"",
660.1015 +			"",
660.1016 +			"",
660.1017 +			"",
660.1018 +			"Sound Length (8 bits,W)",
660.1019 +			"",
660.1020 +			"",
660.1021 +			"",
660.1022 +			"",
660.1023 +			"",
660.1024 +			"",
660.1025 +			"Output Level (2 bits)",
660.1026 +			"Forced 3/4 Output Level",
660.1027 +		}
660.1028 +	},
660.1029 +	{
660.1030 +		NULL, 0x74, "0x4000074-SG31", 0xC7FF,
660.1031 +		{
660.1032 +			"",
660.1033 +			"",
660.1034 +			"",
660.1035 +			"",
660.1036 +			"",
660.1037 +			"",
660.1038 +			"",
660.1039 +			"",
660.1040 +			"",
660.1041 +			"",
660.1042 +			"Frequency (11 bits,W)",
660.1043 +			"",
660.1044 +			"",
660.1045 +			"",
660.1046 +			"Sound Continuous/Counter",
660.1047 +			"Initialization (W)",
660.1048 +		}
660.1049 +	},
660.1050 +	{
660.1051 +		NULL, 0x78, "0x4000078-SG40", 0xFF3F,
660.1052 +		{
660.1053 +			"",
660.1054 +			"",
660.1055 +			"",
660.1056 +			"",
660.1057 +			"",
660.1058 +			"Sound Length (6 bits,W)",
660.1059 +			"",
660.1060 +			"",
660.1061 +			"",
660.1062 +			"",
660.1063 +			"Envelope Steps (3 bits)",
660.1064 +			"Envelope Attenuate/Amplify",
660.1065 +			"",
660.1066 +			"",
660.1067 +			"",
660.1068 +			"Envelope Initial Value",
660.1069 +		}
660.1070 +	},
660.1071 +	{
660.1072 +		NULL, 0x7C, "0x400007C-SG41", 0xC0FF,
660.1073 +		{
660.1074 +			"",
660.1075 +			"",
660.1076 +			"Dividing Ratio Freq. (3 bits)",
660.1077 +			"Counter 15/7 Steps",
660.1078 +			"",
660.1079 +			"",
660.1080 +			"",
660.1081 +			"Counter Shift Clock (4 bits)",
660.1082 +			"",
660.1083 +			"",
660.1084 +			"",
660.1085 +			"",
660.1086 +			"",
660.1087 +			"",
660.1088 +			"Sound Continuous/Counter",
660.1089 +			"Initialization (W)",
660.1090 +		}
660.1091 +	},
660.1092 +	{
660.1093 +		NULL, 0x80, "0x4000080-SGCNT0_L", 0xFF77,
660.1094 +		{
660.1095 +			"",
660.1096 +			"",
660.1097 +			"Right Volume (3 bits)",
660.1098 +			"",
660.1099 +			"",
660.1100 +			"",
660.1101 +			"Left Volume (3 bits)",
660.1102 +			"",
660.1103 +			"Channel 1->Right",
660.1104 +			"Channel 2->Right",
660.1105 +			"Channel 3->Right",
660.1106 +			"Channel 4->Right",
660.1107 +			"Channel 1->Left",
660.1108 +			"Channel 2->Left",
660.1109 +			"Channel 3->Left",
660.1110 +			"Channel 4->Left",
660.1111 +		}
660.1112 +	},
660.1113 +	{
660.1114 +		NULL, 0x82, "0x4000082-SGCNT0_H", 0xFF1F,
660.1115 +		{
660.1116 +			"",
660.1117 +			"Sound 1-4 Volume (2 bits)",
660.1118 +			"DMA Sound A Volume",
660.1119 +			"DMA Sound B Volume",
660.1120 +			"",
660.1121 +			"",
660.1122 +			"",
660.1123 +			"",
660.1124 +			"DMA Sound A->Right",
660.1125 +			"DMA Sound A->Left",
660.1126 +			"DMA Sound A Timer",
660.1127 +			"DMA Sound A Reset FIFO",
660.1128 +			"DMA Sound B->Right",
660.1129 +			"DMA Sound B->Left",
660.1130 +			"DMA Sound B Timer",
660.1131 +			"DMA Sound B Reset FIFO",
660.1132 +		}
660.1133 +	},
660.1134 +	{
660.1135 +		NULL, 0x84, "0x4000084-SGCNT1", 0x0080,
660.1136 +		{
660.1137 +			"Sound 1 On",
660.1138 +			"Sound 2 On",
660.1139 +			"Sound 3 On",
660.1140 +			"Sound 4 On",
660.1141 +			"",
660.1142 +			"",
660.1143 +			"",
660.1144 +			"Master Sound Enable",
660.1145 +			"",
660.1146 +			"",
660.1147 +			"",
660.1148 +			"",
660.1149 +			"",
660.1150 +			"",
660.1151 +			"",
660.1152 +			"",
660.1153 +		}
660.1154 +	},
660.1155 +	{
660.1156 +		NULL, 0x88, "0x4000088-SGBIAS", 0xC3FF,
660.1157 +		{
660.1158 +			"",
660.1159 +			"",
660.1160 +			"",
660.1161 +			"",
660.1162 +			"",
660.1163 +			"",
660.1164 +			"",
660.1165 +			"",
660.1166 +			"",
660.1167 +			"Bias Level (10 bits)",
660.1168 +			"",
660.1169 +			"",
660.1170 +			"",
660.1171 +			"",
660.1172 +			"",
660.1173 +			"Sampling Rate (2 bits)",
660.1174 +		}
660.1175 +	},
660.1176 +	{
660.1177 +		NULL, 0xA0, "0x40000A0-SIGFIFOA_L", 0xFFFF,
660.1178 +		{
660.1179 +			"",
660.1180 +			"",
660.1181 +			"",
660.1182 +			"",
660.1183 +			"",
660.1184 +			"",
660.1185 +			"",
660.1186 +			"Data 0 (8 bits)",
660.1187 +			"",
660.1188 +			"",
660.1189 +			"",
660.1190 +			"",
660.1191 +			"",
660.1192 +			"",
660.1193 +			"",
660.1194 +			"Data 1 (8 bits)",
660.1195 +		}
660.1196 +	},
660.1197 +	{
660.1198 +		NULL, 0xA2, "0x40000A2-SIGFIFOA_H", 0xFFFF,
660.1199 +		{
660.1200 +			"",
660.1201 +			"",
660.1202 +			"",
660.1203 +			"",
660.1204 +			"",
660.1205 +			"",
660.1206 +			"",
660.1207 +			"Data 2 (8 bits)",
660.1208 +			"",
660.1209 +			"",
660.1210 +			"",
660.1211 +			"",
660.1212 +			"",
660.1213 +			"",
660.1214 +			"",
660.1215 +			"Data 3 (8 bits)",
660.1216 +		}
660.1217 +	},
660.1218 +	{
660.1219 +		NULL, 0xA4, "0x40000A4-SIGFIFOB_L", 0xFFFF,
660.1220 +		{
660.1221 +			"",
660.1222 +			"",
660.1223 +			"",
660.1224 +			"",
660.1225 +			"",
660.1226 +			"",
660.1227 +			"",
660.1228 +			"Data 0 (8 bits)",
660.1229 +			"",
660.1230 +			"",
660.1231 +			"",
660.1232 +			"",
660.1233 +			"",
660.1234 +			"",
660.1235 +			"",
660.1236 +			"Data 1 (8 bits)",
660.1237 +		}
660.1238 +	},
660.1239 +	{
660.1240 +		NULL, 0xA6, "0x40000A6-SIGFIFOB_H", 0xFFFF,
660.1241 +		{
660.1242 +			"",
660.1243 +			"",
660.1244 +			"",
660.1245 +			"",
660.1246 +			"",
660.1247 +			"",
660.1248 +			"",
660.1249 +			"Data 2 (8 bits)",
660.1250 +			"",
660.1251 +			"",
660.1252 +			"",
660.1253 +			"",
660.1254 +			"",
660.1255 +			"",
660.1256 +			"",
660.1257 +			"Data 3 (8 bits)",
660.1258 +		}
660.1259 +	},
660.1260 +	{
660.1261 +		&DM0SAD_L, 0xB0, "0x40000B0-DM0SAD_L", 0xFFFF,
660.1262 +		{
660.1263 +			"",
660.1264 +			"",
660.1265 +			"",
660.1266 +			"",
660.1267 +			"",
660.1268 +			"",
660.1269 +			"",
660.1270 +			"",
660.1271 +			"",
660.1272 +			"",
660.1273 +			"",
660.1274 +			"",
660.1275 +			"",
660.1276 +			"",
660.1277 +			"",
660.1278 +			"Source Address (lower 16 bits)",
660.1279 +		}
660.1280 +	},
660.1281 +	{
660.1282 +		&DM0SAD_H, 0xB2, "0x40000B2-DM0SAD_H", 0x07FF,
660.1283 +		{
660.1284 +			"",
660.1285 +			"",
660.1286 +			"",
660.1287 +			"",
660.1288 +			"",
660.1289 +			"",
660.1290 +			"",
660.1291 +			"",
660.1292 +			"",
660.1293 +			"",
660.1294 +			"Source Address (upper 11 bits)",
660.1295 +			"",
660.1296 +			"",
660.1297 +			"",
660.1298 +			"",
660.1299 +			"",
660.1300 +		}
660.1301 +	},
660.1302 +	{
660.1303 +		&DM0DAD_L, 0xB4, "0x40000B4-DM0DAD_L", 0xFFFF,
660.1304 +		{
660.1305 +			"",
660.1306 +			"",
660.1307 +			"",
660.1308 +			"",
660.1309 +			"",
660.1310 +			"",
660.1311 +			"",
660.1312 +			"",
660.1313 +			"",
660.1314 +			"",
660.1315 +			"",
660.1316 +			"",
660.1317 +			"",
660.1318 +			"",
660.1319 +			"",
660.1320 +			"Destination Address (lower 16 bits)",
660.1321 +		}
660.1322 +	},
660.1323 +	{
660.1324 +		&DM0DAD_H, 0xB6, "0x40000B6-DM0DAD_H", 0x07FF,
660.1325 +		{
660.1326 +			"",
660.1327 +			"",
660.1328 +			"",
660.1329 +			"",
660.1330 +			"",
660.1331 +			"",
660.1332 +			"",
660.1333 +			"",
660.1334 +			"",
660.1335 +			"",
660.1336 +			"Destination Address (upper 11 bits)",
660.1337 +			"",
660.1338 +			"",
660.1339 +			"",
660.1340 +			"",
660.1341 +			"",
660.1342 +		}
660.1343 +	},
660.1344 +	{
660.1345 +		&DM0CNT_L, 0xB8, "0x40000B8-DM0CNT_L", 0x3FFF,
660.1346 +		{
660.1347 +			"",
660.1348 +			"",
660.1349 +			"",
660.1350 +			"",
660.1351 +			"",
660.1352 +			"",
660.1353 +			"",
660.1354 +			"",
660.1355 +			"",
660.1356 +			"",
660.1357 +			"",
660.1358 +			"",
660.1359 +			"",
660.1360 +			"Count (14 bits)",
660.1361 +			"",
660.1362 +			"",
660.1363 +		}
660.1364 +	},
660.1365 +	{
660.1366 +		&DM0CNT_H, 0xBA, "0x40000BA-DM0CNT_H", 0xF7E0,
660.1367 +		{
660.1368 +			"",
660.1369 +			"",
660.1370 +			"",
660.1371 +			"",
660.1372 +			"",
660.1373 +			"",
660.1374 +			"Destination Address Control (2 bits)",
660.1375 +			"",
660.1376 +			"Source Address Control (2 bits)",
660.1377 +			"Repeat",
660.1378 +			"Transfer Type",
660.1379 +			"",
660.1380 +			"",
660.1381 +			"Start Timing (2 bits)",
660.1382 +			"Interrupt Request",
660.1383 +			"Enable",
660.1384 +		}
660.1385 +	},
660.1386 +	{
660.1387 +		&DM1SAD_L, 0xBC, "0x40000BC-DM1SAD_L", 0xFFFF,
660.1388 +		{
660.1389 +			"",
660.1390 +			"",
660.1391 +			"",
660.1392 +			"",
660.1393 +			"",
660.1394 +			"",
660.1395 +			"",
660.1396 +			"",
660.1397 +			"",
660.1398 +			"",
660.1399 +			"",
660.1400 +			"",
660.1401 +			"",
660.1402 +			"",
660.1403 +			"",
660.1404 +			"Source Address (lower 16 bits)",
660.1405 +		}
660.1406 +	},
660.1407 +	{
660.1408 +		&DM1SAD_H, 0xBE, "0x40000BE-DM1SAD_H", 0x0FFF,
660.1409 +		{
660.1410 +			"",
660.1411 +			"",
660.1412 +			"",
660.1413 +			"",
660.1414 +			"",
660.1415 +			"",
660.1416 +			"",
660.1417 +			"",
660.1418 +			"",
660.1419 +			"",
660.1420 +			"",
660.1421 +			"Source Address (upper 12 bits)",
660.1422 +			"",
660.1423 +			"",
660.1424 +			"",
660.1425 +			"",
660.1426 +		}
660.1427 +	},
660.1428 +	{
660.1429 +		&DM1DAD_L, 0xC0, "0x40000C0-DM1DAD_L", 0xFFFF,
660.1430 +		{
660.1431 +			"",
660.1432 +			"",
660.1433 +			"",
660.1434 +			"",
660.1435 +			"",
660.1436 +			"",
660.1437 +			"",
660.1438 +			"",
660.1439 +			"",
660.1440 +			"",
660.1441 +			"",
660.1442 +			"",
660.1443 +			"",
660.1444 +			"",
660.1445 +			"",
660.1446 +			"Destination Address (lower 16 bits)",
660.1447 +		}
660.1448 +	},
660.1449 +	{
660.1450 +		&DM1DAD_H, 0xC2, "0x40000C2-DM1DAD_H", 0x07FF,
660.1451 +		{
660.1452 +			"",
660.1453 +			"",
660.1454 +			"",
660.1455 +			"",
660.1456 +			"",
660.1457 +			"",
660.1458 +			"",
660.1459 +			"",
660.1460 +			"",
660.1461 +			"",
660.1462 +			"Destination Address (upper 11 bits)",
660.1463 +			"",
660.1464 +			"",
660.1465 +			"",
660.1466 +			"",
660.1467 +			"",
660.1468 +		}
660.1469 +	},
660.1470 +	{
660.1471 +		&DM1CNT_L, 0xC4, "0x40000C4-DM1CNT_L", 0x3FFF,
660.1472 +		{
660.1473 +			"",
660.1474 +			"",
660.1475 +			"",
660.1476 +			"",
660.1477 +			"",
660.1478 +			"",
660.1479 +			"",
660.1480 +			"",
660.1481 +			"",
660.1482 +			"",
660.1483 +			"",
660.1484 +			"",
660.1485 +			"",
660.1486 +			"Count (14 bits)",
660.1487 +			"",
660.1488 +			"",
660.1489 +		}
660.1490 +	},
660.1491 +	{
660.1492 +		&DM1CNT_H, 0xC6, "0x40000C6-DM1CNT_H", 0xF7E0,
660.1493 +		{
660.1494 +			"",
660.1495 +			"",
660.1496 +			"",
660.1497 +			"",
660.1498 +			"",
660.1499 +			"",
660.1500 +			"Destination Address Control (2 bits)",
660.1501 +			"",
660.1502 +			"Source Address Control (2 bits)",
660.1503 +			"Repeat",
660.1504 +			"Transfer Type",
660.1505 +			"",
660.1506 +			"",
660.1507 +			"Start Timing (2 bits)",
660.1508 +			"Interrupt Request",
660.1509 +			"Enable",
660.1510 +		}
660.1511 +	},
660.1512 +	{
660.1513 +		&DM2SAD_L, 0xC8, "0x40000C8-DM2SAD_L", 0xFFFF,
660.1514 +		{
660.1515 +			"",
660.1516 +			"",
660.1517 +			"",
660.1518 +			"",
660.1519 +			"",
660.1520 +			"",
660.1521 +			"",
660.1522 +			"",
660.1523 +			"",
660.1524 +			"",
660.1525 +			"",
660.1526 +			"",
660.1527 +			"",
660.1528 +			"",
660.1529 +			"",
660.1530 +			"Source Address (lower 16 bits)",
660.1531 +		}
660.1532 +	},
660.1533 +	{
660.1534 +		&DM2SAD_H, 0xCA, "0x40000CA-DM2SAD_H", 0x0FFF,
660.1535 +		{
660.1536 +			"",
660.1537 +			"",
660.1538 +			"",
660.1539 +			"",
660.1540 +			"",
660.1541 +			"",
660.1542 +			"",
660.1543 +			"",
660.1544 +			"",
660.1545 +			"",
660.1546 +			"",
660.1547 +			"Source Address (upper 12 bits)",
660.1548 +			"",
660.1549 +			"",
660.1550 +			"",
660.1551 +			"",
660.1552 +		}
660.1553 +	},
660.1554 +	{
660.1555 +		&DM2DAD_L, 0xCC, "0x40000CC-DM2DAD_L", 0xFFFF,
660.1556 +		{
660.1557 +			"",
660.1558 +			"",
660.1559 +			"",
660.1560 +			"",
660.1561 +			"",
660.1562 +			"",
660.1563 +			"",
660.1564 +			"",
660.1565 +			"",
660.1566 +			"",
660.1567 +			"",
660.1568 +			"",
660.1569 +			"",
660.1570 +			"",
660.1571 +			"",
660.1572 +			"Destination Address (lower 16 bits)",
660.1573 +		}
660.1574 +	},
660.1575 +	{
660.1576 +		&DM2DAD_H, 0xCE, "0x40000CE-DM2DAD_H", 0x07FF,
660.1577 +		{
660.1578 +			"",
660.1579 +			"",
660.1580 +			"",
660.1581 +			"",
660.1582 +			"",
660.1583 +			"",
660.1584 +			"",
660.1585 +			"",
660.1586 +			"",
660.1587 +			"",
660.1588 +			"Destination Address (upper 11 bits)",
660.1589 +			"",
660.1590 +			"",
660.1591 +			"",
660.1592 +			"",
660.1593 +			"",
660.1594 +		}
660.1595 +	},
660.1596 +	{
660.1597 +		&DM2CNT_L, 0xD0, "0x40000D0-DM2CNT_L", 0x3FFF,
660.1598 +		{
660.1599 +			"",
660.1600 +			"",
660.1601 +			"",
660.1602 +			"",
660.1603 +			"",
660.1604 +			"",
660.1605 +			"",
660.1606 +			"",
660.1607 +			"",
660.1608 +			"",
660.1609 +			"",
660.1610 +			"",
660.1611 +			"",
660.1612 +			"Count (14 bits)",
660.1613 +			"",
660.1614 +			"",
660.1615 +		}
660.1616 +	},
660.1617 +	{
660.1618 +		&DM2CNT_H, 0xD2, "0x40000D2-DM2CNT_H", 0xF7E0,
660.1619 +		{
660.1620 +			"",
660.1621 +			"",
660.1622 +			"",
660.1623 +			"",
660.1624 +			"",
660.1625 +			"",
660.1626 +			"Destination Address Control (2 bits)",
660.1627 +			"",
660.1628 +			"Source Address Control (2 bits)",
660.1629 +			"Repeat",
660.1630 +			"Transfer Type",
660.1631 +			"",
660.1632 +			"",
660.1633 +			"Start Timing (2 bits)",
660.1634 +			"Interrupt Request",
660.1635 +			"Enable",
660.1636 +		}
660.1637 +	},
660.1638 +	{
660.1639 +		&DM3SAD_L, 0xD4, "0x40000D4-DM3SAD_L", 0xFFFF,
660.1640 +		{
660.1641 +			"",
660.1642 +			"",
660.1643 +			"",
660.1644 +			"",
660.1645 +			"",
660.1646 +			"",
660.1647 +			"",
660.1648 +			"",
660.1649 +			"",
660.1650 +			"",
660.1651 +			"",
660.1652 +			"",
660.1653 +			"",
660.1654 +			"",
660.1655 +			"",
660.1656 +			"Source Address (lower 16 bits)",
660.1657 +		}
660.1658 +	},
660.1659 +	{
660.1660 +		&DM3SAD_H, 0xD6, "0x40000D6-DM3SAD_H", 0x0FFF,
660.1661 +		{
660.1662 +			"",
660.1663 +			"",
660.1664 +			"",
660.1665 +			"",
660.1666 +			"",
660.1667 +			"",
660.1668 +			"",
660.1669 +			"",
660.1670 +			"",
660.1671 +			"",
660.1672 +			"",
660.1673 +			"Source Address (upper 12 bits)",
660.1674 +			"",
660.1675 +			"",
660.1676 +			"",
660.1677 +			"",
660.1678 +		}
660.1679 +	},
660.1680 +	{
660.1681 +		&DM3DAD_L, 0xD8, "0x40000D8-DM3DAD_L", 0xFFFF,
660.1682 +		{
660.1683 +			"",
660.1684 +			"",
660.1685 +			"",
660.1686 +			"",
660.1687 +			"",
660.1688 +			"",
660.1689 +			"",
660.1690 +			"",
660.1691 +			"",
660.1692 +			"",
660.1693 +			"",
660.1694 +			"",
660.1695 +			"",
660.1696 +			"",
660.1697 +			"",
660.1698 +			"Destination Address (lower 16 bits)",
660.1699 +		}
660.1700 +	},
660.1701 +	{
660.1702 +		&DM3DAD_H, 0xDA, "0x40000DA-DM3DAD_H", 0x0FFF,
660.1703 +		{
660.1704 +			"",
660.1705 +			"",
660.1706 +			"",
660.1707 +			"",
660.1708 +			"",
660.1709 +			"",
660.1710 +			"",
660.1711 +			"",
660.1712 +			"",
660.1713 +			"",
660.1714 +			"",
660.1715 +			"Destination Address (upper 12 bits)",
660.1716 +			"",
660.1717 +			"",
660.1718 +			"",
660.1719 +			"",
660.1720 +		}
660.1721 +	},
660.1722 +	{
660.1723 +		&DM3CNT_L, 0xDC, "0x40000DC-DM3CNT_L", 0xFFFF,
660.1724 +		{
660.1725 +			"",
660.1726 +			"",
660.1727 +			"",
660.1728 +			"",
660.1729 +			"",
660.1730 +			"",
660.1731 +			"",
660.1732 +			"",
660.1733 +			"",
660.1734 +			"",
660.1735 +			"",
660.1736 +			"",
660.1737 +			"",
660.1738 +			"",
660.1739 +			"",
660.1740 +			"Count (16 bits)",
660.1741 +		}
660.1742 +	},
660.1743 +	{
660.1744 +		&DM3CNT_H, 0xDE, "0x40000DE-DM3CNT_H", 0xFFE0,
660.1745 +		{
660.1746 +			"",
660.1747 +			"",
660.1748 +			"",
660.1749 +			"",
660.1750 +			"",
660.1751 +			"",
660.1752 +			"Destination Address Control (2 bits)",
660.1753 +			"",
660.1754 +			"Source Address Control (2 bits)",
660.1755 +			"Repeat",
660.1756 +			"Transfer Type",
660.1757 +			"Game Pak Data Request",
660.1758 +			"",
660.1759 +			"Start Timing (2 bits)",
660.1760 +			"Interrupt Request",
660.1761 +			"Enable",
660.1762 +		}
660.1763 +	},
660.1764 +	{
660.1765 +		&TM0D, 0x100, "0x4000100-TM0D", 0xFFFF,
660.1766 +		{
660.1767 +			"",
660.1768 +			"",
660.1769 +			"",
660.1770 +			"",
660.1771 +			"",
660.1772 +			"",
660.1773 +			"",
660.1774 +			"",
660.1775 +			"",
660.1776 +			"",
660.1777 +			"",
660.1778 +			"",
660.1779 +			"",
660.1780 +			"",
660.1781 +			"",
660.1782 +			"Timer Counter (16 bits)",
660.1783 +		}
660.1784 +	},
660.1785 +	{
660.1786 +		&TM0CNT, 0x102, "0x4000102-TM0CNT", 0x00C7,
660.1787 +		{
660.1788 +			"",
660.1789 +			"Scalar Selection (2 bits)",
660.1790 +			"Count Up",
660.1791 +			"",
660.1792 +			"",
660.1793 +			"",
660.1794 +			"Interrupt Request",
660.1795 +			"Enable",
660.1796 +			"",
660.1797 +			"",
660.1798 +			"",
660.1799 +			"",
660.1800 +			"",
660.1801 +			"",
660.1802 +			"",
660.1803 +			"",
660.1804 +		}
660.1805 +	},
660.1806 +	{
660.1807 +		&TM1D, 0x104, "0x4000104-TM1D", 0xFFFF,
660.1808 +		{
660.1809 +			"",
660.1810 +			"",
660.1811 +			"",
660.1812 +			"",
660.1813 +			"",
660.1814 +			"",
660.1815 +			"",
660.1816 +			"",
660.1817 +			"",
660.1818 +			"",
660.1819 +			"",
660.1820 +			"",
660.1821 +			"",
660.1822 +			"",
660.1823 +			"",
660.1824 +			"Timer Counter (16 bits)",
660.1825 +		}
660.1826 +	},
660.1827 +	{
660.1828 +		&TM1CNT, 0x106, "0x4000106-TM1CNT", 0x00C7,
660.1829 +		{
660.1830 +			"",
660.1831 +			"Scalar Selection (2 bits)",
660.1832 +			"Count Up",
660.1833 +			"",
660.1834 +			"",
660.1835 +			"",
660.1836 +			"Interrupt Request",
660.1837 +			"Enable",
660.1838 +			"",
660.1839 +			"",
660.1840 +			"",
660.1841 +			"",
660.1842 +			"",
660.1843 +			"",
660.1844 +			"",
660.1845 +			"",
660.1846 +		}
660.1847 +	},
660.1848 +	{
660.1849 +		&TM2D, 0x108, "0x4000108-TM2D", 0xFFFF,
660.1850 +		{
660.1851 +			"",
660.1852 +			"",
660.1853 +			"",
660.1854 +			"",
660.1855 +			"",
660.1856 +			"",
660.1857 +			"",
660.1858 +			"",
660.1859 +			"",
660.1860 +			"",
660.1861 +			"",
660.1862 +			"",
660.1863 +			"",
660.1864 +			"",
660.1865 +			"",
660.1866 +			"Timer Counter (16 bits)",
660.1867 +		}
660.1868 +	},
660.1869 +	{
660.1870 +		&TM2CNT, 0x10A, "0x400010A-TM2CNT", 0x00C7,
660.1871 +		{
660.1872 +			"",
660.1873 +			"Scalar Selection (2 bits)",
660.1874 +			"Count Up",
660.1875 +			"",
660.1876 +			"",
660.1877 +			"",
660.1878 +			"Interrupt Request",
660.1879 +			"Enable",
660.1880 +			"",
660.1881 +			"",
660.1882 +			"",
660.1883 +			"",
660.1884 +			"",
660.1885 +			"",
660.1886 +			"",
660.1887 +			"",
660.1888 +		}
660.1889 +	},
660.1890 +	{
660.1891 +		&TM3D, 0x10C, "0x400010C-TM3D", 0xFFFF,
660.1892 +		{
660.1893 +			"",
660.1894 +			"",
660.1895 +			"",
660.1896 +			"",
660.1897 +			"",
660.1898 +			"",
660.1899 +			"",
660.1900 +			"",
660.1901 +			"",
660.1902 +			"",
660.1903 +			"",
660.1904 +			"",
660.1905 +			"",
660.1906 +			"",
660.1907 +			"",
660.1908 +			"Timer Counter (16 bits)",
660.1909 +		}
660.1910 +	},
660.1911 +	{
660.1912 +		&TM3CNT, 0x10E, "0x400010E-TM3CNT", 0x00C7,
660.1913 +		{
660.1914 +			"",
660.1915 +			"Scalar Selection (2 bits)",
660.1916 +			"Count Up",
660.1917 +			"",
660.1918 +			"",
660.1919 +			"",
660.1920 +			"Interrupt Request",
660.1921 +			"Enable",
660.1922 +			"",
660.1923 +			"",
660.1924 +			"",
660.1925 +			"",
660.1926 +			"",
660.1927 +			"",
660.1928 +			"",
660.1929 +			"",
660.1930 +		}
660.1931 +	},
660.1932 +	{
660.1933 +		&P1, 0x130, "0x4000130-P1", 0x03FF,
660.1934 +		{
660.1935 +			"A",
660.1936 +			"B",
660.1937 +			"Select",
660.1938 +			"Start",
660.1939 +			"Right",
660.1940 +			"Left",
660.1941 +			"Up",
660.1942 +			"Down",
660.1943 +			"Shoulder Right",
660.1944 +			"Shoulder Left",
660.1945 +			"",
660.1946 +			"",
660.1947 +			"",
660.1948 +			"",
660.1949 +			"",
660.1950 +			"",
660.1951 +		}
660.1952 +	},
660.1953 +	{
660.1954 +		NULL, 0x132, "0x4000132-P1CNT", 0xC3FF,
660.1955 +		{
660.1956 +			"A",
660.1957 +			"B",
660.1958 +			"Select",
660.1959 +			"Start",
660.1960 +			"Right",
660.1961 +			"Left",
660.1962 +			"Up",
660.1963 +			"Down",
660.1964 +			"Shoulder Right",
660.1965 +			"Shoulder Left",
660.1966 +			"",
660.1967 +			"",
660.1968 +			"",
660.1969 +			"",
660.1970 +			"Interrupt Request",
660.1971 +			"Interrupt Condition",
660.1972 +		}
660.1973 +	},
660.1974 +	{
660.1975 +		&IE, 0x200, "0x4000200-IE", 0x3FFF,
660.1976 +		{
660.1977 +			"VBlank",
660.1978 +			"HBlank",
660.1979 +			"VCount",
660.1980 +			"Timer 0",
660.1981 +			"Timer 1",
660.1982 +			"Timer 2",
660.1983 +			"Timer 3",
660.1984 +			"Serial",
660.1985 +			"DMA 0",
660.1986 +			"DMA 1",
660.1987 +			"DMA 2",
660.1988 +			"DMA 3",
660.1989 +			"Keypad",
660.1990 +			"Game Pak",
660.1991 +			"",
660.1992 +			"",
660.1993 +		}
660.1994 +	},
660.1995 +	{
660.1996 +		&IF, 0x202, "0x4000202-IF", 0x0000,
660.1997 +		{
660.1998 +			"VBlank",
660.1999 +			"HBlank",
660.2000 +			"VCount",
660.2001 +			"Timer 0",
660.2002 +			"Timer 1",
660.2003 +			"Timer 2",
660.2004 +			"Timer 3",
660.2005 +			"Serial",
660.2006 +			"DMA 0",
660.2007 +			"DMA 1",
660.2008 +			"DMA 2",
660.2009 +			"DMA 3",
660.2010 +			"Keypad",
660.2011 +			"Game Pak",
660.2012 +			"",
660.2013 +			"",
660.2014 +		}
660.2015 +	},
660.2016 +	{
660.2017 +		NULL, 0x204, "0x4000204-WAITCNT", 0x5FFF,
660.2018 +		{
660.2019 +			"",
660.2020 +			"SRAM Wait Control (2 bits)",
660.2021 +			"",
660.2022 +			"Wait State 0 First Access (2 bits)",
660.2023 +			"Wait State 0 Second Access",
660.2024 +			"",
660.2025 +			"Wait State 1 First Access (2 bits)",
660.2026 +			"Wait State 1 Second Access",
660.2027 +			"",
660.2028 +			"Wait State 2 First Access (2 bits)",
660.2029 +			"Wait State 2 Second Access",
660.2030 +			"",
660.2031 +			"PHI Terminal Output (2 bits)",
660.2032 +			"",
660.2033 +			"Game Pak Prefetch Buffer",
660.2034 +			"Game Pak Type Flag",
660.2035 +		}
660.2036 +	},
660.2037 +	{
660.2038 +		&IME, 0x208, "0x4000208-IME", 0x0001,
660.2039 +		{
660.2040 +			"Master Interrupt Enable",
660.2041 +			"",
660.2042 +			"",
660.2043 +			"",
660.2044 +			"",
660.2045 +			"",
660.2046 +			"",
660.2047 +			"",
660.2048 +			"",
660.2049 +			"",
660.2050 +			"",
660.2051 +			"",
660.2052 +			"",
660.2053 +			"",
660.2054 +			"",
660.2055 +			"",
660.2056 +		}
660.2057 +	},
660.2058 +	{
660.2059 +		NULL, 0x300, "0x4000300-HALTCNT", 0x8001,
660.2060 +		{
660.2061 +			"First Boot",
660.2062 +			"",
660.2063 +			"",
660.2064 +			"",
660.2065 +			"",
660.2066 +			"",
660.2067 +			"",
660.2068 +			"",
660.2069 +			"",
660.2070 +			"",
660.2071 +			"",
660.2072 +			"",
660.2073 +			"",
660.2074 +			"",
660.2075 +			"",
660.2076 +			"Power Down",
660.2077 +		}
660.2078 +	},
660.2079 +};
660.2080 +
660.2081 +#endif // VBA_IOVIEWERREGS_H
   661.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   661.2 +++ b/src/win32/IUpdate.h	Sat Mar 03 10:31:27 2012 -0600
   661.3 @@ -0,0 +1,14 @@
   661.4 +#ifndef VBA_WIN32_IUPDATE_H
   661.5 +#define VBA_WIN32_IUPDATE_H
   661.6 +
   661.7 +#if _MSC_VER > 1000
   661.8 +#pragma once
   661.9 +#endif // _MSC_VER > 1000
  661.10 +
  661.11 +class IUpdateListener
  661.12 +{
  661.13 +public:
  661.14 +	virtual void update() = 0;
  661.15 +};
  661.16 +
  661.17 +#endif
   662.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   662.2 +++ b/src/win32/Input.h	Sat Mar 03 10:31:27 2012 -0600
   662.3 @@ -0,0 +1,30 @@
   662.4 +#ifndef VBA_WIN32_INPUT_H
   662.5 +#define VBA_WIN32_INPUT_H
   662.6 +
   662.7 +#if _MSC_VER > 1000
   662.8 +#pragma once
   662.9 +#endif // _MSC_VER > 1000
  662.10 +
  662.11 +#include "../common/inputGlobal.h"
  662.12 +
  662.13 +#define JOYCONFIG_MESSAGE (WM_USER + 1000)
  662.14 +
  662.15 +class Input
  662.16 +{
  662.17 +public:
  662.18 +	Input() {};
  662.19 +	virtual ~Input() {};
  662.20 +
  662.21 +	virtual bool initialize() = 0;
  662.22 +
  662.23 +	virtual bool readDevices() = 0;
  662.24 +	virtual u32 readDevice(int which, bool sensor) = 0;
  662.25 +	virtual CString getKeyName(LONG_PTR key) = 0;
  662.26 +	virtual void checkKeys()    = 0;
  662.27 +	virtual void checkDevices() = 0;
  662.28 +	virtual void activate()     = 0;
  662.29 +	virtual void loadSettings() = 0;
  662.30 +	virtual void saveSettings() = 0;
  662.31 +};
  662.32 +
  662.33 +#endif
   663.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   663.2 +++ b/src/win32/Joypad.cpp	Sat Mar 03 10:31:27 2012 -0600
   663.3 @@ -0,0 +1,402 @@
   663.4 +// Joypad.cpp : implementation file
   663.5 +//
   663.6 +
   663.7 +#include "stdafx.h"
   663.8 +#include "resource.h"
   663.9 +#include "Joypad.h"
  663.10 +#include "Input.h"
  663.11 +#include "VBA.h"
  663.12 +
  663.13 +extern USHORT joypad[4][13];
  663.14 +extern USHORT motion[4];
  663.15 +
  663.16 +/////////////////////////////////////////////////////////////////////////////
  663.17 +// JoypadEditControl
  663.18 +
  663.19 +JoypadEditControl::JoypadEditControl()
  663.20 +{}
  663.21 +
  663.22 +JoypadEditControl::~JoypadEditControl()
  663.23 +{}
  663.24 +
  663.25 +BEGIN_MESSAGE_MAP(JoypadEditControl, CEdit)
  663.26 +//{{AFX_MSG_MAP(JoypadEditControl)
  663.27 +ON_WM_CHAR()
  663.28 +//}}AFX_MSG_MAP
  663.29 +ON_MESSAGE(JOYCONFIG_MESSAGE, OnJoyConfig)
  663.30 +END_MESSAGE_MAP()
  663.31 +
  663.32 +/////////////////////////////////////////////////////////////////////////////
  663.33 +// JoypadEditControl message handlers
  663.34 +
  663.35 +void JoypadEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  663.36 +{}
  663.37 +
  663.38 +LRESULT JoypadEditControl::OnJoyConfig(WPARAM wParam, LPARAM lParam)
  663.39 +{
  663.40 +	SetWindowLong(GetSafeHwnd(), GWL_USERDATA, ((wParam<<8)|lParam));
  663.41 +	SetWindowText(theApp.input->getKeyName((wParam<<8)|lParam));
  663.42 +	GetParent()->GetNextDlgTabItem(this, FALSE)->SetFocus();
  663.43 +	return TRUE;
  663.44 +}
  663.45 +
  663.46 +BOOL JoypadEditControl::PreTranslateMessage(MSG *pMsg)
  663.47 +{
  663.48 +	if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_RETURN))
  663.49 +		return TRUE;
  663.50 +
  663.51 +	return CEdit::PreTranslateMessage(pMsg);
  663.52 +}
  663.53 +
  663.54 +/////////////////////////////////////////////////////////////////////////////
  663.55 +// JoypadConfig dialog
  663.56 +
  663.57 +JoypadConfig::JoypadConfig(int w, CWnd*pParent /*=NULL*/)
  663.58 +	: CDialog(JoypadConfig::IDD, pParent)
  663.59 +{
  663.60 +	//{{AFX_DATA_INIT(JoypadConfig)
  663.61 +	//}}AFX_DATA_INIT
  663.62 +	timerId = 0;
  663.63 +	which   = w;
  663.64 +	if (which < 0 || which > 3)
  663.65 +		which = 0;
  663.66 +}
  663.67 +
  663.68 +void JoypadConfig::DoDataExchange(CDataExchange*pDX)
  663.69 +{
  663.70 +	CDialog::DoDataExchange(pDX);
  663.71 +	//{{AFX_DATA_MAP(JoypadConfig)
  663.72 +	DDX_Control(pDX, IDC_EDIT_UP, up);
  663.73 +	DDX_Control(pDX, IDC_EDIT_SPEED, speed);
  663.74 +	DDX_Control(pDX, IDC_EDIT_RIGHT, right);
  663.75 +	DDX_Control(pDX, IDC_EDIT_LEFT, left);
  663.76 +	DDX_Control(pDX, IDC_EDIT_DOWN, down);
  663.77 +	DDX_Control(pDX, IDC_EDIT_CAPTURE, capture);
  663.78 +	DDX_Control(pDX, IDC_EDIT_BUTTON_START, buttonStart);
  663.79 +	DDX_Control(pDX, IDC_EDIT_BUTTON_SELECT, buttonSelect);
  663.80 +	DDX_Control(pDX, IDC_EDIT_BUTTON_R, buttonR);
  663.81 +	DDX_Control(pDX, IDC_EDIT_BUTTON_L, buttonL);
  663.82 +	DDX_Control(pDX, IDC_EDIT_BUTTON_GS, buttonGS);
  663.83 +	DDX_Control(pDX, IDC_EDIT_BUTTON_B, buttonB);
  663.84 +	DDX_Control(pDX, IDC_EDIT_BUTTON_A, buttonA);
  663.85 +	//}}AFX_DATA_MAP
  663.86 +}
  663.87 +
  663.88 +BEGIN_MESSAGE_MAP(JoypadConfig, CDialog)
  663.89 +//{{AFX_MSG_MAP(JoypadConfig)
  663.90 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
  663.91 +ON_BN_CLICKED(ID_OK, OnOk)
  663.92 +ON_WM_CHAR()
  663.93 +ON_WM_DESTROY()
  663.94 +ON_WM_TIMER()
  663.95 +ON_WM_KEYDOWN()
  663.96 +//}}AFX_MSG_MAP
  663.97 +END_MESSAGE_MAP()
  663.98 +
  663.99 +/////////////////////////////////////////////////////////////////////////////
 663.100 +// JoypadConfig message handlers
 663.101 +
 663.102 +void JoypadConfig::OnCancel()
 663.103 +{
 663.104 +	EndDialog(FALSE);
 663.105 +}
 663.106 +
 663.107 +void JoypadConfig::OnOk()
 663.108 +{
 663.109 +	assignKeys();
 663.110 +	theApp.input->checkKeys();
 663.111 +	EndDialog(TRUE);
 663.112 +}
 663.113 +
 663.114 +void JoypadConfig::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
 663.115 +{}
 663.116 +
 663.117 +void JoypadConfig::OnDestroy()
 663.118 +{
 663.119 +	CDialog::OnDestroy();
 663.120 +
 663.121 +	KillTimer(timerId);
 663.122 +}
 663.123 +
 663.124 +void JoypadConfig::OnTimer(UINT nIDEvent)
 663.125 +{
 663.126 +	theApp.input->checkDevices();
 663.127 +
 663.128 +	CDialog::OnTimer(nIDEvent);
 663.129 +}
 663.130 +
 663.131 +void JoypadConfig::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
 663.132 +{}
 663.133 +
 663.134 +BOOL JoypadConfig::OnInitDialog()
 663.135 +{
 663.136 +	CDialog::OnInitDialog();
 663.137 +
 663.138 +	timerId = SetTimer(0, 200, NULL);
 663.139 +
 663.140 +	SetWindowLong(up, GWL_USERDATA, joypad[which][KEY_UP]);
 663.141 +	up.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_UP]));
 663.142 +
 663.143 +	SetWindowLong(down, GWL_USERDATA, joypad[which][KEY_DOWN]);
 663.144 +	down.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_DOWN]));
 663.145 +
 663.146 +	SetWindowLong(left, GWL_USERDATA, joypad[which][KEY_LEFT]);
 663.147 +	left.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_LEFT]));
 663.148 +
 663.149 +	SetWindowLong(right, GWL_USERDATA, joypad[which][KEY_RIGHT]);
 663.150 +	right.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_RIGHT]));
 663.151 +
 663.152 +	SetWindowLong(buttonA, GWL_USERDATA, joypad[which][KEY_BUTTON_A]);
 663.153 +	buttonA.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_A]));
 663.154 +
 663.155 +	SetWindowLong(buttonB, GWL_USERDATA, joypad[which][KEY_BUTTON_B]);
 663.156 +	buttonB.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_B]));
 663.157 +
 663.158 +	SetWindowLong(buttonL, GWL_USERDATA, joypad[which][KEY_BUTTON_L]);
 663.159 +	buttonL.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_L]));
 663.160 +
 663.161 +	SetWindowLong(buttonR, GWL_USERDATA, joypad[which][KEY_BUTTON_R]);
 663.162 +	buttonR.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_R]));
 663.163 +
 663.164 +	SetWindowLong(buttonSelect, GWL_USERDATA, joypad[which][KEY_BUTTON_SELECT]);
 663.165 +	buttonSelect.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_SELECT]));
 663.166 +
 663.167 +	SetWindowLong(buttonStart, GWL_USERDATA, joypad[which][KEY_BUTTON_START]);
 663.168 +	buttonStart.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_START]));
 663.169 +
 663.170 +	SetWindowLong(speed, GWL_USERDATA, joypad[which][KEY_BUTTON_SPEED]);
 663.171 +	speed.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_SPEED]));
 663.172 +
 663.173 +	SetWindowLong(capture, GWL_USERDATA, joypad[which][KEY_BUTTON_CAPTURE]);
 663.174 +	capture.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_CAPTURE]));
 663.175 +
 663.176 +	SetWindowLong(buttonGS, GWL_USERDATA, joypad[which][KEY_BUTTON_GS]);
 663.177 +	buttonGS.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_GS]));
 663.178 +
 663.179 +	CenterWindow();
 663.180 +
 663.181 +	return TRUE; // return TRUE unless you set the focus to a control
 663.182 +	             // EXCEPTION: OCX Property Pages should return FALSE
 663.183 +}
 663.184 +
 663.185 +void JoypadConfig::assignKey(int id, int key)
 663.186 +{
 663.187 +	switch (id)
 663.188 +	{
 663.189 +	case IDC_EDIT_LEFT:
 663.190 +		joypad[which][KEY_LEFT] = key;
 663.191 +		break;
 663.192 +	case IDC_EDIT_RIGHT:
 663.193 +		joypad[which][KEY_RIGHT] = key;
 663.194 +		break;
 663.195 +	case IDC_EDIT_UP:
 663.196 +		joypad[which][KEY_UP] = key;
 663.197 +		break;
 663.198 +	case IDC_EDIT_SPEED:
 663.199 +		joypad[which][KEY_BUTTON_SPEED] = key;
 663.200 +		break;
 663.201 +	case IDC_EDIT_CAPTURE:
 663.202 +		joypad[which][KEY_BUTTON_CAPTURE] = key;
 663.203 +		break;
 663.204 +	case IDC_EDIT_DOWN:
 663.205 +		joypad[which][KEY_DOWN] = key;
 663.206 +		break;
 663.207 +	case IDC_EDIT_BUTTON_A:
 663.208 +		joypad[which][KEY_BUTTON_A] = key;
 663.209 +		break;
 663.210 +	case IDC_EDIT_BUTTON_B:
 663.211 +		joypad[which][KEY_BUTTON_B] = key;
 663.212 +		break;
 663.213 +	case IDC_EDIT_BUTTON_L:
 663.214 +		joypad[which][KEY_BUTTON_L] = key;
 663.215 +		break;
 663.216 +	case IDC_EDIT_BUTTON_R:
 663.217 +		joypad[which][KEY_BUTTON_R] = key;
 663.218 +		break;
 663.219 +	case IDC_EDIT_BUTTON_START:
 663.220 +		joypad[which][KEY_BUTTON_START] = key;
 663.221 +		break;
 663.222 +	case IDC_EDIT_BUTTON_SELECT:
 663.223 +		joypad[which][KEY_BUTTON_SELECT] = key;
 663.224 +		break;
 663.225 +	case IDC_EDIT_BUTTON_GS:
 663.226 +		joypad[which][KEY_BUTTON_GS] = key;
 663.227 +		break;
 663.228 +	}
 663.229 +}
 663.230 +
 663.231 +void JoypadConfig::assignKeys()
 663.232 +{
 663.233 +	int id;
 663.234 +
 663.235 +	id = IDC_EDIT_UP;
 663.236 +	assignKey(id, GetWindowLong(up, GWL_USERDATA));
 663.237 +
 663.238 +	id = IDC_EDIT_DOWN;
 663.239 +	assignKey(id, GetWindowLong(down, GWL_USERDATA));
 663.240 +
 663.241 +	id = IDC_EDIT_LEFT;
 663.242 +	assignKey(id, GetWindowLong(left, GWL_USERDATA));
 663.243 +
 663.244 +	id = IDC_EDIT_RIGHT;
 663.245 +	assignKey(id, GetWindowLong(right, GWL_USERDATA));
 663.246 +
 663.247 +	id = IDC_EDIT_BUTTON_A;
 663.248 +	assignKey(id, GetWindowLong(buttonA, GWL_USERDATA));
 663.249 +
 663.250 +	id = IDC_EDIT_BUTTON_B;
 663.251 +	assignKey(id, GetWindowLong(buttonB, GWL_USERDATA));
 663.252 +
 663.253 +	id = IDC_EDIT_BUTTON_L;
 663.254 +	assignKey(id, GetWindowLong(buttonL, GWL_USERDATA));
 663.255 +
 663.256 +	id = IDC_EDIT_BUTTON_R;
 663.257 +	assignKey(id, GetWindowLong(buttonR, GWL_USERDATA));
 663.258 +
 663.259 +	id = IDC_EDIT_BUTTON_SELECT;
 663.260 +	assignKey(id, GetWindowLong(buttonSelect, GWL_USERDATA));
 663.261 +
 663.262 +	id = IDC_EDIT_BUTTON_START;
 663.263 +	assignKey(id, GetWindowLong(buttonStart, GWL_USERDATA));
 663.264 +
 663.265 +	id = IDC_EDIT_SPEED;
 663.266 +	assignKey(id, GetWindowLong(speed, GWL_USERDATA));
 663.267 +
 663.268 +	id = IDC_EDIT_CAPTURE;
 663.269 +	assignKey(id, GetWindowLong(capture, GWL_USERDATA));
 663.270 +
 663.271 +	id = IDC_EDIT_BUTTON_GS;
 663.272 +	assignKey(id, GetWindowLong(buttonGS, GWL_USERDATA));
 663.273 +
 663.274 +	//  winSaveKeys();
 663.275 +}
 663.276 +
 663.277 +/////////////////////////////////////////////////////////////////////////////
 663.278 +// MotionConfig dialog
 663.279 +
 663.280 +MotionConfig::MotionConfig(CWnd*pParent /*=NULL*/)
 663.281 +	: CDialog(MotionConfig::IDD, pParent)
 663.282 +{
 663.283 +	//{{AFX_DATA_INIT(MotionConfig)
 663.284 +	// NOTE: the ClassWizard will add member initialization here
 663.285 +	//}}AFX_DATA_INIT
 663.286 +	timerId = 0;
 663.287 +}
 663.288 +
 663.289 +void MotionConfig::DoDataExchange(CDataExchange*pDX)
 663.290 +{
 663.291 +	CDialog::DoDataExchange(pDX);
 663.292 +	//{{AFX_DATA_MAP(MotionConfig)
 663.293 +	DDX_Control(pDX, IDC_EDIT_UP, up);
 663.294 +	DDX_Control(pDX, IDC_EDIT_RIGHT, right);
 663.295 +	DDX_Control(pDX, IDC_EDIT_LEFT, left);
 663.296 +	DDX_Control(pDX, IDC_EDIT_DOWN, down);
 663.297 +	//}}AFX_DATA_MAP
 663.298 +}
 663.299 +
 663.300 +BEGIN_MESSAGE_MAP(MotionConfig, CDialog)
 663.301 +//{{AFX_MSG_MAP(MotionConfig)
 663.302 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
 663.303 +ON_BN_CLICKED(ID_OK, OnOk)
 663.304 +ON_WM_CHAR()
 663.305 +ON_WM_DESTROY()
 663.306 +ON_WM_KEYDOWN()
 663.307 +ON_WM_TIMER()
 663.308 +//}}AFX_MSG_MAP
 663.309 +END_MESSAGE_MAP()
 663.310 +
 663.311 +/////////////////////////////////////////////////////////////////////////////
 663.312 +// MotionConfig message handlers
 663.313 +
 663.314 +void MotionConfig::OnCancel()
 663.315 +{
 663.316 +	EndDialog(FALSE);
 663.317 +}
 663.318 +
 663.319 +void MotionConfig::OnOk()
 663.320 +{
 663.321 +	assignKeys();
 663.322 +	theApp.input->checkKeys();
 663.323 +	EndDialog(TRUE);
 663.324 +}
 663.325 +
 663.326 +void MotionConfig::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
 663.327 +{}
 663.328 +
 663.329 +void MotionConfig::OnDestroy()
 663.330 +{
 663.331 +	CDialog::OnDestroy();
 663.332 +
 663.333 +	KillTimer(timerId);
 663.334 +}
 663.335 +
 663.336 +BOOL MotionConfig::OnInitDialog()
 663.337 +{
 663.338 +	CDialog::OnInitDialog();
 663.339 +
 663.340 +	timerId = SetTimer(0, 200, NULL);
 663.341 +
 663.342 +	SetWindowLong(up, GWL_USERDATA, motion[KEY_UP]);
 663.343 +	up.SetWindowText(theApp.input->getKeyName(motion[KEY_UP]));
 663.344 +
 663.345 +	SetWindowLong(down, GWL_USERDATA, motion[KEY_DOWN]);
 663.346 +	down.SetWindowText(theApp.input->getKeyName(motion[KEY_DOWN]));
 663.347 +
 663.348 +	SetWindowLong(left, GWL_USERDATA, motion[KEY_LEFT]);
 663.349 +	left.SetWindowText(theApp.input->getKeyName(motion[KEY_LEFT]));
 663.350 +
 663.351 +	SetWindowLong(right, GWL_USERDATA, motion[KEY_RIGHT]);
 663.352 +	right.SetWindowText(theApp.input->getKeyName(motion[KEY_RIGHT]));
 663.353 +
 663.354 +	CenterWindow();
 663.355 +
 663.356 +	return TRUE; // return TRUE unless you set the focus to a control
 663.357 +	             // EXCEPTION: OCX Property Pages should return FALSE
 663.358 +}
 663.359 +
 663.360 +void MotionConfig::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
 663.361 +{}
 663.362 +
 663.363 +void MotionConfig::OnTimer(UINT nIDEvent)
 663.364 +{
 663.365 +	theApp.input->checkDevices();
 663.366 +
 663.367 +	CDialog::OnTimer(nIDEvent);
 663.368 +}
 663.369 +
 663.370 +void MotionConfig::assignKey(int id, int key)
 663.371 +{
 663.372 +	switch (id)
 663.373 +	{
 663.374 +	case IDC_EDIT_LEFT:
 663.375 +		motion[KEY_LEFT] = key;
 663.376 +		break;
 663.377 +	case IDC_EDIT_RIGHT:
 663.378 +		motion[KEY_RIGHT] = key;
 663.379 +		break;
 663.380 +	case IDC_EDIT_UP:
 663.381 +		motion[KEY_UP] = key;
 663.382 +		break;
 663.383 +	case IDC_EDIT_DOWN:
 663.384 +		motion[KEY_DOWN] = key;
 663.385 +		break;
 663.386 +	}
 663.387 +}
 663.388 +
 663.389 +void MotionConfig::assignKeys()
 663.390 +{
 663.391 +	int id;
 663.392 +
 663.393 +	id = IDC_EDIT_UP;
 663.394 +	assignKey(id, GetWindowLong(up, GWL_USERDATA));
 663.395 +
 663.396 +	id = IDC_EDIT_DOWN;
 663.397 +	assignKey(id, GetWindowLong(down, GWL_USERDATA));
 663.398 +
 663.399 +	id = IDC_EDIT_LEFT;
 663.400 +	assignKey(id, GetWindowLong(left, GWL_USERDATA));
 663.401 +
 663.402 +	id = IDC_EDIT_RIGHT;
 663.403 +	assignKey(id, GetWindowLong(right, GWL_USERDATA));
 663.404 +}
 663.405 +
   664.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   664.2 +++ b/src/win32/Joypad.h	Sat Mar 03 10:31:27 2012 -0600
   664.3 @@ -0,0 +1,145 @@
   664.4 +#if !defined(AFX_JOYPAD_H__FFFB2470_9EEC_4D2D_A5F0_3BF31579999A__INCLUDED_)
   664.5 +#define AFX_JOYPAD_H__FFFB2470_9EEC_4D2D_A5F0_3BF31579999A__INCLUDED_
   664.6 +
   664.7 +#if _MSC_VER > 1000
   664.8 +#pragma once
   664.9 +#endif // _MSC_VER > 1000
  664.10 +// -*- C++ -*-
  664.11 +// Joypad.h : header file
  664.12 +//
  664.13 +
  664.14 +/////////////////////////////////////////////////////////////////////////////
  664.15 +// JoypadEditControl window
  664.16 +
  664.17 +class JoypadEditControl : public CEdit
  664.18 +{
  664.19 +	// Construction
  664.20 +public:
  664.21 +	JoypadEditControl();
  664.22 +
  664.23 +	// Attributes
  664.24 +public:
  664.25 +	// Operations
  664.26 +public:
  664.27 +	// Overrides
  664.28 +	// ClassWizard generated virtual function overrides
  664.29 +	//{{AFX_VIRTUAL(JoypadEditControl)
  664.30 +	//}}AFX_VIRTUAL
  664.31 +
  664.32 +	// Implementation
  664.33 +public:
  664.34 +	virtual BOOL PreTranslateMessage(MSG *pMsg);
  664.35 +	afx_msg LRESULT OnJoyConfig(WPARAM wParam, LPARAM lParam);
  664.36 +	virtual ~JoypadEditControl();
  664.37 +
  664.38 +	// Generated message map functions
  664.39 +protected:
  664.40 +	//{{AFX_MSG(JoypadEditControl)
  664.41 +	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  664.42 +	//}}AFX_MSG
  664.43 +
  664.44 +	DECLARE_MESSAGE_MAP()
  664.45 +};
  664.46 +
  664.47 +/////////////////////////////////////////////////////////////////////////////
  664.48 +
  664.49 +/////////////////////////////////////////////////////////////////////////////
  664.50 +// JoypadConfig dialog
  664.51 +
  664.52 +class JoypadConfig : public CDialog
  664.53 +{
  664.54 +	// Construction
  664.55 +public:
  664.56 +	void assignKeys();
  664.57 +	void assignKey(int id, int key);
  664.58 +	JoypadConfig(int w, CWnd*pParent = NULL);  // standard constructor
  664.59 +
  664.60 +	// Dialog Data
  664.61 +	//{{AFX_DATA(JoypadConfig)
  664.62 +	enum { IDD = IDD_CONFIG };
  664.63 +	JoypadEditControl up;
  664.64 +	JoypadEditControl speed;
  664.65 +	JoypadEditControl right;
  664.66 +	JoypadEditControl left;
  664.67 +	JoypadEditControl down;
  664.68 +	JoypadEditControl capture;
  664.69 +	JoypadEditControl buttonStart;
  664.70 +	JoypadEditControl buttonSelect;
  664.71 +	JoypadEditControl buttonR;
  664.72 +	JoypadEditControl buttonL;
  664.73 +	JoypadEditControl buttonGS;
  664.74 +	JoypadEditControl buttonB;
  664.75 +	JoypadEditControl buttonA;
  664.76 +	//}}AFX_DATA
  664.77 +
  664.78 +	// Overrides
  664.79 +	// ClassWizard generated virtual function overrides
  664.80 +	//{{AFX_VIRTUAL(JoypadConfig)
  664.81 +protected:
  664.82 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  664.83 +	//}}AFX_VIRTUAL
  664.84 +
  664.85 +	// Implementation
  664.86 +protected:
  664.87 +	UINT timerId;
  664.88 +	int  which;
  664.89 +
  664.90 +	// Generated message map functions
  664.91 +	//{{AFX_MSG(JoypadConfig)
  664.92 +	afx_msg void OnCancel();
  664.93 +	afx_msg void OnOk();
  664.94 +	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  664.95 +	afx_msg void OnDestroy();
  664.96 +	afx_msg void OnTimer(UINT nIDEvent);
  664.97 +	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  664.98 +	virtual BOOL OnInitDialog();
  664.99 +	//}}AFX_MSG
 664.100 +	DECLARE_MESSAGE_MAP()
 664.101 +};
 664.102 +/////////////////////////////////////////////////////////////////////////////
 664.103 +// MotionConfig dialog
 664.104 +
 664.105 +class MotionConfig : public CDialog
 664.106 +{
 664.107 +	// Construction
 664.108 +public:
 664.109 +	void assignKeys();
 664.110 +	void assignKey(int id, int key);
 664.111 +	MotionConfig(CWnd*pParent = NULL);  // standard constructor
 664.112 +
 664.113 +	// Dialog Data
 664.114 +	//{{AFX_DATA(MotionConfig)
 664.115 +	enum { IDD = IDD_MOTION_CONFIG };
 664.116 +	JoypadEditControl up;
 664.117 +	JoypadEditControl right;
 664.118 +	JoypadEditControl left;
 664.119 +	JoypadEditControl down;
 664.120 +	//}}AFX_DATA
 664.121 +
 664.122 +	// Overrides
 664.123 +	// ClassWizard generated virtual function overrides
 664.124 +	//{{AFX_VIRTUAL(MotionConfig)
 664.125 +protected:
 664.126 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
 664.127 +	//}}AFX_VIRTUAL
 664.128 +
 664.129 +	// Implementation
 664.130 +protected:
 664.131 +	// Generated message map functions
 664.132 +	//{{AFX_MSG(MotionConfig)
 664.133 +	afx_msg void OnCancel();
 664.134 +	afx_msg void OnOk();
 664.135 +	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
 664.136 +	afx_msg void OnDestroy();
 664.137 +	virtual BOOL OnInitDialog();
 664.138 +	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
 664.139 +	afx_msg void OnTimer(UINT nIDEvent);
 664.140 +	//}}AFX_MSG
 664.141 +	DECLARE_MESSAGE_MAP()
 664.142 +private:
 664.143 +	UINT timerId;
 664.144 +};
 664.145 +//{{AFX_INSERT_LOCATION}}
 664.146 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
 664.147 +
 664.148 +#endif // !defined(AFX_JOYPAD_H__FFFB2470_9EEC_4D2D_A5F0_3BF31579999A__INCLUDED_)
   665.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   665.2 +++ b/src/win32/KeyboardEdit.cpp	Sat Mar 03 10:31:27 2012 -0600
   665.3 @@ -0,0 +1,271 @@
   665.4 +////////////////////////////////////////////////////////////////////////////////
   665.5 +// Copyright (C) 1998 by Thierry Maurel
   665.6 +// All rights reserved
   665.7 +//
   665.8 +// Distribute freely, except: don't remove my name from the source or
   665.9 +// documentation (don't take credit for my work), mark your changes (don't
  665.10 +// get me blamed for your possible bugs), don't alter or remove this
  665.11 +// notice.
  665.12 +// No warrantee of any kind, express or implied, is included with this
  665.13 +// software; use at your own risk, responsibility for damages (if any) to
  665.14 +// anyone resulting from the use of this software rests entirely with the
  665.15 +// user.
  665.16 +//
  665.17 +// Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  665.18 +// I'll try to keep a version up to date.  I can be reached as follows:
  665.19 +//    tmaurel@caramail.com   (or tmaurel@hol.fr)
  665.20 +//
  665.21 +////////////////////////////////////////////////////////////////////////////////
  665.22 +// File    : KeyboardEdit.cpp
  665.23 +// Project : AccelsEditor
  665.24 +////////////////////////////////////////////////////////////////////////////////
  665.25 +// Version : 1.0                       * Authors : A.Lebatard + T.Maurel
  665.26 +// Date    : 17.08.98
  665.27 +//
  665.28 +// Remarks : implementation file
  665.29 +//
  665.30 +
  665.31 +////////////////////////////////////////////////////////////////////////////////
  665.32 +// modified by aquanull
  665.33 +
  665.34 +#include "stdafx.h"
  665.35 +#include "KeyboardEdit.h"
  665.36 +
  665.37 +extern TCHAR *mapVirtKeysStringFromWORD(WORD wKey);
  665.38 +
  665.39 +IMPLEMENT_DYNAMIC(CKeyboardEdit, CEdit)
  665.40 +
  665.41 +/////////////////////////////////////////////////////////////////////////////
  665.42 +// CKeyboardEdit
  665.43 +
  665.44 +CKeyboardEdit::CKeyboardEdit()
  665.45 +{
  665.46 +	ResetKey();
  665.47 +}
  665.48 +
  665.49 +CKeyboardEdit::~CKeyboardEdit()
  665.50 +{}
  665.51 +
  665.52 +BEGIN_MESSAGE_MAP(CKeyboardEdit, CEdit)
  665.53 +//{{AFX_MSG_MAP(CKeyboardEdit)
  665.54 +ON_CONTROL_REFLECT_EX(EN_CHANGE, &CKeyboardEdit::OnEnChange)
  665.55 +ON_CONTROL_REFLECT_EX(EN_SETFOCUS, &CKeyboardEdit::OnEnSetfocus)
  665.56 +ON_CONTROL_REFLECT_EX(EN_KILLFOCUS, &CKeyboardEdit::OnEnKillfocus)
  665.57 +//}}AFX_MSG_MAP
  665.58 +END_MESSAGE_MAP()
  665.59 +
  665.60 +/////////////////////////////////////////////////////////////////////////////
  665.61 +// CKeyboardEdit message handlers
  665.62 +BOOL CKeyboardEdit::PreTranslateMessage(MSG *pMsg)
  665.63 +{
  665.64 +	if (pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN)
  665.65 +	{
  665.66 +		int key = pMsg->wParam;
  665.67 +		m_keys[key] = true;
  665.68 +		switch (key)
  665.69 +		{
  665.70 +		case VK_CONTROL:
  665.71 +		case VK_MENU:
  665.72 +		case VK_SHIFT:
  665.73 +			m_bCtrlPressed	= m_keys[VK_CONTROL];
  665.74 +			m_bAltPressed	= m_keys[VK_MENU];;
  665.75 +			m_bShiftPressed = m_keys[VK_SHIFT];
  665.76 +			if (!m_keys[m_wVirtKey])
  665.77 +			{
  665.78 +				if (m_keys[m_wJamKey])
  665.79 +				{
  665.80 +					m_wVirtKey = m_wJamKey;
  665.81 +					m_wJamKey  = 0;
  665.82 +				}
  665.83 +				else
  665.84 +					m_wVirtKey = 0;
  665.85 +			}
  665.86 +			if (!m_keys[m_wJamKey])
  665.87 +				m_wJamKey = 0;
  665.88 +			break;
  665.89 +		default:
  665.90 +			m_bCtrlPressed	= m_keys[VK_CONTROL];
  665.91 +			m_bAltPressed	= m_keys[VK_MENU];
  665.92 +			m_bShiftPressed = m_keys[VK_SHIFT];
  665.93 +			if (m_wVirtKey != key)
  665.94 +			{
  665.95 +				if (m_keys[m_wVirtKey])
  665.96 +					m_wJamKey = m_wVirtKey;
  665.97 +				else
  665.98 +					m_wJamKey = 0;
  665.99 +				m_wVirtKey = key;
 665.100 +			}
 665.101 +			else if (!m_keys[m_wJamKey])
 665.102 +				m_wJamKey = 0;
 665.103 +			break;
 665.104 +		}
 665.105 +		DisplayKeyboardString();
 665.106 +		return TRUE;
 665.107 +	}
 665.108 +	else if (pMsg->message == WM_KEYUP || pMsg->message == WM_SYSKEYUP)
 665.109 +	{
 665.110 +		int key = pMsg->wParam;
 665.111 +		m_keys[key] = false;
 665.112 +		switch (key)
 665.113 +		{
 665.114 +		case VK_CONTROL:
 665.115 +		case VK_MENU:
 665.116 +		case VK_SHIFT:
 665.117 +			break;
 665.118 +		default:
 665.119 +			m_bCtrlPressed	= m_keys[VK_CONTROL];
 665.120 +			m_bAltPressed	= m_keys[VK_MENU];
 665.121 +			m_bShiftPressed = m_keys[VK_SHIFT];
 665.122 +			if (m_wJamKey)
 665.123 +			{
 665.124 +				if (!m_keys[m_wVirtKey])
 665.125 +				{
 665.126 +					m_wVirtKey = m_wJamKey;
 665.127 +					m_wJamKey  = 0;
 665.128 +				}
 665.129 +				if (!m_keys[m_wJamKey])
 665.130 +					m_wJamKey = 0;
 665.131 +			}
 665.132 +			break;
 665.133 +		}
 665.134 +		DisplayKeyboardString();
 665.135 +		return TRUE;
 665.136 +	}
 665.137 +
 665.138 +	return CEdit::PreTranslateMessage(pMsg);
 665.139 +}
 665.140 +
 665.141 +BOOL CKeyboardEdit::OnEnChange()
 665.142 +{
 665.143 +	return FALSE;
 665.144 +}
 665.145 +
 665.146 +BOOL CKeyboardEdit::OnEnSetfocus()
 665.147 +{
 665.148 +	//SetSel(0, -1, TRUE);	// mouse click makes this in vain, so we use the method below instead
 665.149 +	PostMessage(EM_SETSEL, 0, -1);
 665.150 +	m_bForceUpdate = true;
 665.151 +	return FALSE;
 665.152 +}
 665.153 +
 665.154 +BOOL CKeyboardEdit::OnEnKillfocus()
 665.155 +{
 665.156 +	AllKeyUp();
 665.157 +	return FALSE;
 665.158 +}
 665.159 +
 665.160 +////////////////////////////////////////////////////////////////////////
 665.161 +//
 665.162 +void CKeyboardEdit::DisplayKeyboardString()
 665.163 +{
 665.164 +	CString strKbd;
 665.165 +
 665.166 +	// modifiers
 665.167 +	if (m_bCtrlPressed)
 665.168 +		strKbd = "Ctrl";
 665.169 +
 665.170 +	if (m_bAltPressed)
 665.171 +	{
 665.172 +		if (strKbd.GetLength() > 0)
 665.173 +			strKbd += '+';
 665.174 +		strKbd += "Alt";
 665.175 +	}
 665.176 +	if (m_bShiftPressed)
 665.177 +	{
 665.178 +		if (strKbd.GetLength() > 0)
 665.179 +			strKbd += '+';
 665.180 +		strKbd += "Shift";
 665.181 +	}
 665.182 +	// virtual key
 665.183 +	LPCTSTR szVirtKey = mapVirtKeysStringFromWORD(m_wVirtKey);
 665.184 +	if (szVirtKey != NULL)
 665.185 +	{
 665.186 +		if (strKbd.GetLength() > 0)
 665.187 +			strKbd += '+';
 665.188 +		strKbd += szVirtKey;
 665.189 +	}
 665.190 +	// jammed key
 665.191 +	LPCTSTR szJamKey = mapVirtKeysStringFromWORD(m_wJamKey);
 665.192 +	if (szJamKey != NULL)
 665.193 +	{
 665.194 +		strKbd += '(';
 665.195 +		strKbd += szJamKey;
 665.196 +		strKbd += ')';
 665.197 +	}
 665.198 +
 665.199 +	if (m_bForceUpdate)
 665.200 +	{
 665.201 +		m_bForceUpdate = false;
 665.202 +		SetWindowText(strKbd);
 665.203 +	}
 665.204 +	else
 665.205 +	{
 665.206 +		CString oldString;
 665.207 +		GetWindowText(oldString);
 665.208 +		if (oldString.Compare(strKbd))
 665.209 +			SetWindowText(strKbd);
 665.210 +	}
 665.211 +}
 665.212 +
 665.213 +////////////////////////////////////////////////////////////////////////
 665.214 +//
 665.215 +void CKeyboardEdit::ResetKey()
 665.216 +{
 665.217 +	AllKeyUp();
 665.218 +
 665.219 +	m_bForceUpdate		= true;
 665.220 +	m_bCtrlPressed	= false;
 665.221 +	m_bAltPressed	= false;
 665.222 +	m_bShiftPressed = false;
 665.223 +	m_wVirtKey		= 0;
 665.224 +	m_wJamKey		= 0;
 665.225 +
 665.226 +	if (m_hWnd != NULL)
 665.227 +	{
 665.228 +		CString oldString;
 665.229 +		GetWindowText(oldString);
 665.230 +		if (!oldString.IsEmpty())
 665.231 +			SetWindowText(_T(""));
 665.232 +	}
 665.233 +}
 665.234 +
 665.235 +void CKeyboardEdit::AllKeyUp()
 665.236 +{
 665.237 +	for (int i = 0; i < 256; ++i)
 665.238 +		m_keys[i] = 0;
 665.239 +}
 665.240 +
 665.241 +////////////////////////////////////////////////////////////////////////
 665.242 +//
 665.243 +bool CKeyboardEdit::GetAccelKey(WORD &wVirtKey, bool &bCtrl, bool &bAlt, bool &bShift) const
 665.244 +{
 665.245 +	if (!IsDefined())
 665.246 +		return false;
 665.247 +
 665.248 +	wVirtKey = m_wVirtKey;
 665.249 +	bAlt	 = m_bAltPressed;
 665.250 +	bCtrl	 = m_bCtrlPressed;
 665.251 +	bShift	 = m_bShiftPressed;
 665.252 +	return true;
 665.253 +}
 665.254 +
 665.255 +bool CKeyboardEdit::GetJamKey(WORD &wJamKey) const
 665.256 +{
 665.257 +	if (m_wJamKey != 0)
 665.258 +		wJamKey = m_wJamKey;
 665.259 +	return m_wJamKey != 0;
 665.260 +}
 665.261 +
 665.262 +bool CKeyboardEdit::IsDefined() const
 665.263 +{
 665.264 +	return bool(m_wVirtKey || m_bAltPressed || m_bCtrlPressed || m_bShiftPressed);
 665.265 +}
 665.266 +
 665.267 +bool CKeyboardEdit::IsFinished() const
 665.268 +{
 665.269 +	bool finished = true;
 665.270 +	for (int i = 0; i < 256; ++i)
 665.271 +		if (m_keys[i])
 665.272 +			finished = false;
 665.273 +	return finished;
 665.274 +}
   666.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   666.2 +++ b/src/win32/KeyboardEdit.h	Sat Mar 03 10:31:27 2012 -0600
   666.3 @@ -0,0 +1,96 @@
   666.4 +////////////////////////////////////////////////////////////////////////////////
   666.5 +// Copyright (C) 1998 by Thierry Maurel
   666.6 +// All rights reserved
   666.7 +//
   666.8 +// Distribute freely, except: don't remove my name from the source or
   666.9 +// documentation (don't take credit for my work), mark your changes (don't
  666.10 +// get me blamed for your possible bugs), don't alter or remove this
  666.11 +// notice.
  666.12 +// No warrantee of any kind, express or implied, is included with this
  666.13 +// software; use at your own risk, responsibility for damages (if any) to
  666.14 +// anyone resulting from the use of this software rests entirely with the
  666.15 +// user.
  666.16 +//
  666.17 +// Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  666.18 +// I'll try to keep a version up to date.  I can be reached as follows:
  666.19 +//    tmaurel@caramail.com   (or tmaurel@hol.fr)
  666.20 +//
  666.21 +////////////////////////////////////////////////////////////////////////////////
  666.22 +// File    : KeyboardEdit.h
  666.23 +// Project : AccelsEditor
  666.24 +////////////////////////////////////////////////////////////////////////////////
  666.25 +// Version : 1.0                       * Authors : A.Lebatard + T.Maurel
  666.26 +// Date    : 17.08.98
  666.27 +//
  666.28 +// Remarks :
  666.29 +//
  666.30 +////////////////////////////////////////////////////////////////////////////////
  666.31 +// Modified by the VBA-rr Team
  666.32 +
  666.33 +#if !defined(AFX_KEYBOARDEDIT_H__88E35AB0_2E23_11D2_BA24_0060B0B5E151__INCLUDED_)
  666.34 +#define AFX_KEYBOARDEDIT_H__88E35AB0_2E23_11D2_BA24_0060B0B5E151__INCLUDED_
  666.35 +
  666.36 +#if _MSC_VER >= 1000
  666.37 +#pragma once
  666.38 +#endif // _MSC_VER >= 1000
  666.39 +// KeyboardEdit.h : header file
  666.40 +//
  666.41 +
  666.42 +/////////////////////////////////////////////////////////////////////////////
  666.43 +// CKeyboardEdit window
  666.44 +
  666.45 +class CKeyboardEdit : public CEdit
  666.46 +{
  666.47 +	DECLARE_DYNAMIC(CKeyboardEdit)	// what will this do?
  666.48 +
  666.49 +	// Construction
  666.50 +public:
  666.51 +	CKeyboardEdit();
  666.52 +
  666.53 +	// Operations
  666.54 +public:
  666.55 +	void ResetKey();
  666.56 +	void AllKeyUp();
  666.57 +	bool GetAccelKey(WORD &wVirtKey, bool &bCtrl, bool &bAlt, bool &bShift) const;
  666.58 +	bool GetJamKey(WORD &wJamKey) const;
  666.59 +	bool IsDefined() const;
  666.60 +	bool IsFinished() const;
  666.61 +
  666.62 +	// Overrides
  666.63 +	// ClassWizard generated virtual function overrides
  666.64 +	//{{AFX_VIRTUAL(CKeyboardEdit)
  666.65 +public:
  666.66 +	virtual BOOL PreTranslateMessage(MSG *pMsg);
  666.67 +	virtual ~CKeyboardEdit();
  666.68 +	//}}AFX_VIRTUAL
  666.69 +
  666.70 +protected:
  666.71 +	void DisplayKeyboardString();
  666.72 +
  666.73 +	// Attributes
  666.74 +protected:
  666.75 +	BYTE m_keys[256];
  666.76 +	bool m_bForceUpdate;
  666.77 +	bool m_bCtrlPressed;
  666.78 +	bool m_bAltPressed;
  666.79 +	bool m_bShiftPressed;
  666.80 +	WORD m_wVirtKey;
  666.81 +	WORD m_wJamKey;
  666.82 +
  666.83 +	// Generated message map functions
  666.84 +public:
  666.85 +	//{{AFX_MSG(CKeyboardEdit)
  666.86 +	afx_msg BOOL OnEnChange();
  666.87 +	afx_msg BOOL OnEnSetfocus();
  666.88 +	afx_msg BOOL OnEnKillfocus();
  666.89 +	//}}AFX_MSG
  666.90 +
  666.91 +	DECLARE_MESSAGE_MAP()
  666.92 +};
  666.93 +
  666.94 +/////////////////////////////////////////////////////////////////////////////
  666.95 +
  666.96 +//{{AFX_INSERT_LOCATION}}
  666.97 +// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  666.98 +
  666.99 +#endif // !defined(AFX_KEYBOARDEDIT_H__88E35AB0_2E23_11D2_BA24_0060B0B5E151__INCLUDED_)
   667.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   667.2 +++ b/src/win32/LangSelect.cpp	Sat Mar 03 10:31:27 2012 -0600
   667.3 @@ -0,0 +1,75 @@
   667.4 +// LangSelect.cpp : implementation file
   667.5 +//
   667.6 +
   667.7 +#include "stdafx.h"
   667.8 +#include "resource.h"
   667.9 +#include "LangSelect.h"
  667.10 +#include "VBA.h"
  667.11 +
  667.12 +/////////////////////////////////////////////////////////////////////////////
  667.13 +// LangSelect dialog
  667.14 +
  667.15 +LangSelect::LangSelect(CWnd*pParent /*=NULL*/)
  667.16 +	: CDialog(LangSelect::IDD, pParent)
  667.17 +{
  667.18 +	//{{AFX_DATA_INIT(LangSelect)
  667.19 +	// NOTE: the ClassWizard will add member initialization here
  667.20 +	//}}AFX_DATA_INIT
  667.21 +}
  667.22 +
  667.23 +void LangSelect::DoDataExchange(CDataExchange*pDX)
  667.24 +{
  667.25 +	CDialog::DoDataExchange(pDX);
  667.26 +	//{{AFX_DATA_MAP(LangSelect)
  667.27 +	DDX_Control(pDX, IDC_LANG_STRING, m_langString);
  667.28 +	DDX_Control(pDX, IDC_LANG_NAME, m_langName);
  667.29 +	//}}AFX_DATA_MAP
  667.30 +}
  667.31 +
  667.32 +BEGIN_MESSAGE_MAP(LangSelect, CDialog)
  667.33 +//{{AFX_MSG_MAP(LangSelect)
  667.34 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
  667.35 +ON_BN_CLICKED(ID_OK, OnOk)
  667.36 +//}}AFX_MSG_MAP
  667.37 +END_MESSAGE_MAP()
  667.38 +
  667.39 +/////////////////////////////////////////////////////////////////////////////
  667.40 +// LangSelect message handlers
  667.41 +
  667.42 +void LangSelect::OnCancel()
  667.43 +{
  667.44 +	EndDialog(FALSE);
  667.45 +}
  667.46 +
  667.47 +void LangSelect::OnOk()
  667.48 +{
  667.49 +	m_langString.GetWindowText(theApp.languageName);
  667.50 +	EndDialog(TRUE);
  667.51 +}
  667.52 +
  667.53 +BOOL LangSelect::OnInitDialog()
  667.54 +{
  667.55 +	CDialog::OnInitDialog();
  667.56 +
  667.57 +	char lbuffer[10];
  667.58 +	if (GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SABBREVLANGNAME,
  667.59 +	                  lbuffer, 10))
  667.60 +	{
  667.61 +		m_langName.SetWindowText(lbuffer);
  667.62 +	}
  667.63 +	else
  667.64 +	{
  667.65 +		m_langName.SetWindowText("???");
  667.66 +	}
  667.67 +
  667.68 +	if (!theApp.languageName.IsEmpty())
  667.69 +		m_langString.SetWindowText(theApp.languageName);
  667.70 +
  667.71 +	m_langString.LimitText(3);
  667.72 +
  667.73 +	CenterWindow();
  667.74 +
  667.75 +	return TRUE; // return TRUE unless you set the focus to a control
  667.76 +	             // EXCEPTION: OCX Property Pages should return FALSE
  667.77 +}
  667.78 +
   668.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   668.2 +++ b/src/win32/LangSelect.h	Sat Mar 03 10:31:27 2012 -0600
   668.3 @@ -0,0 +1,48 @@
   668.4 +#if !defined(AFX_LANGSELECT_H__63619E13_A375_4ED4_952F_DCF8998C2914__INCLUDED_)
   668.5 +#define AFX_LANGSELECT_H__63619E13_A375_4ED4_952F_DCF8998C2914__INCLUDED_
   668.6 +
   668.7 +#if _MSC_VER > 1000
   668.8 +#pragma once
   668.9 +#endif // _MSC_VER > 1000
  668.10 +// -*- C++ -*-
  668.11 +// LangSelect.h : header file
  668.12 +//
  668.13 +
  668.14 +/////////////////////////////////////////////////////////////////////////////
  668.15 +// LangSelect dialog
  668.16 +
  668.17 +class LangSelect : public CDialog
  668.18 +{
  668.19 +	// Construction
  668.20 +public:
  668.21 +	LangSelect(CWnd*pParent = NULL);  // standard constructor
  668.22 +
  668.23 +	// Dialog Data
  668.24 +	//{{AFX_DATA(LangSelect)
  668.25 +	enum { IDD = IDD_LANG_SELECT };
  668.26 +	CEdit   m_langString;
  668.27 +	CStatic m_langName;
  668.28 +	//}}AFX_DATA
  668.29 +
  668.30 +	// Overrides
  668.31 +	// ClassWizard generated virtual function overrides
  668.32 +	//{{AFX_VIRTUAL(LangSelect)
  668.33 +protected:
  668.34 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  668.35 +	//}}AFX_VIRTUAL
  668.36 +
  668.37 +	// Implementation
  668.38 +protected:
  668.39 +	// Generated message map functions
  668.40 +	//{{AFX_MSG(LangSelect)
  668.41 +	afx_msg void OnCancel();
  668.42 +	afx_msg void OnOk();
  668.43 +	virtual BOOL OnInitDialog();
  668.44 +	//}}AFX_MSG
  668.45 +	DECLARE_MESSAGE_MAP()
  668.46 +};
  668.47 +
  668.48 +//{{AFX_INSERT_LOCATION}}
  668.49 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  668.50 +
  668.51 +#endif // !defined(AFX_LANGSELECT_H__63619E13_A375_4ED4_952F_DCF8998C2914__INCLUDED_)
   669.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   669.2 +++ b/src/win32/Logging.cpp	Sat Mar 03 10:31:27 2012 -0600
   669.3 @@ -0,0 +1,273 @@
   669.4 +// Logging.cpp : implementation file
   669.5 +//
   669.6 +
   669.7 +#include "stdafx.h"
   669.8 +#include "resource.h"
   669.9 +#include "Logging.h"
  669.10 +#include "FileDlg.h"
  669.11 +
  669.12 +#include "../common/System.h"
  669.13 +
  669.14 +/////////////////////////////////////////////////////////////////////////////
  669.15 +// Logging dialog
  669.16 +
  669.17 +Logging *Logging::instance = NULL;
  669.18 +CString Logging:: text;
  669.19 +
  669.20 +Logging::Logging(CWnd*pParent /*=NULL*/)
  669.21 +	: ResizeDlg(Logging::IDD, pParent)
  669.22 +{
  669.23 +	//{{AFX_DATA_INIT(Logging)
  669.24 +	m_swi = FALSE;
  669.25 +	m_unaligned_access = FALSE;
  669.26 +	m_illegal_write    = FALSE;
  669.27 +	m_illegal_read     = FALSE;
  669.28 +	m_dma0      = FALSE;
  669.29 +	m_dma1      = FALSE;
  669.30 +	m_dma2      = FALSE;
  669.31 +	m_dma3      = FALSE;
  669.32 +	m_agbprint  = FALSE;
  669.33 +	m_undefined = FALSE;
  669.34 +	//}}AFX_DATA_INIT
  669.35 +}
  669.36 +
  669.37 +void Logging::DoDataExchange(CDataExchange*pDX)
  669.38 +{
  669.39 +	CDialog::DoDataExchange(pDX);
  669.40 +	//{{AFX_DATA_MAP(Logging)
  669.41 +	DDX_Control(pDX, IDC_LOG, m_log);
  669.42 +	DDX_Check(pDX, IDC_VERBOSE_SWI, m_swi);
  669.43 +	DDX_Check(pDX, IDC_VERBOSE_UNALIGNED_ACCESS, m_unaligned_access);
  669.44 +	DDX_Check(pDX, IDC_VERBOSE_ILLEGAL_WRITE, m_illegal_write);
  669.45 +	DDX_Check(pDX, IDC_VERBOSE_ILLEGAL_READ, m_illegal_read);
  669.46 +	DDX_Check(pDX, IDC_VERBOSE_DMA0, m_dma0);
  669.47 +	DDX_Check(pDX, IDC_VERBOSE_DMA1, m_dma1);
  669.48 +	DDX_Check(pDX, IDC_VERBOSE_DMA2, m_dma2);
  669.49 +	DDX_Check(pDX, IDC_VERBOSE_DMA3, m_dma3);
  669.50 +	DDX_Check(pDX, IDC_VERBOSE_AGBPRINT, m_agbprint);
  669.51 +	DDX_Check(pDX, IDC_VERBOSE_UNDEFINED, m_undefined);
  669.52 +	//}}AFX_DATA_MAP
  669.53 +}
  669.54 +
  669.55 +BEGIN_MESSAGE_MAP(Logging, CDialog)
  669.56 +//{{AFX_MSG_MAP(Logging)
  669.57 +ON_BN_CLICKED(ID_OK, OnOk)
  669.58 +ON_BN_CLICKED(IDC_CLEAR, OnClear)
  669.59 +ON_BN_CLICKED(IDC_VERBOSE_AGBPRINT, OnVerboseAgbprint)
  669.60 +ON_BN_CLICKED(IDC_VERBOSE_DMA0, OnVerboseDma0)
  669.61 +ON_BN_CLICKED(IDC_VERBOSE_DMA1, OnVerboseDma1)
  669.62 +ON_BN_CLICKED(IDC_VERBOSE_DMA2, OnVerboseDma2)
  669.63 +ON_BN_CLICKED(IDC_VERBOSE_DMA3, OnVerboseDma3)
  669.64 +ON_BN_CLICKED(IDC_VERBOSE_ILLEGAL_READ, OnVerboseIllegalRead)
  669.65 +ON_BN_CLICKED(IDC_VERBOSE_ILLEGAL_WRITE, OnVerboseIllegalWrite)
  669.66 +ON_BN_CLICKED(IDC_VERBOSE_SWI, OnVerboseSwi)
  669.67 +ON_BN_CLICKED(IDC_VERBOSE_UNALIGNED_ACCESS, OnVerboseUnalignedAccess)
  669.68 +ON_BN_CLICKED(IDC_VERBOSE_UNDEFINED, OnVerboseUndefined)
  669.69 +ON_BN_CLICKED(IDC_SAVE, OnSave)
  669.70 +ON_EN_ERRSPACE(IDC_LOG, OnErrspaceLog)
  669.71 +ON_EN_MAXTEXT(IDC_LOG, OnMaxtextLog)
  669.72 +ON_WM_CLOSE()
  669.73 +//}}AFX_MSG_MAP
  669.74 +END_MESSAGE_MAP()
  669.75 +
  669.76 +/////////////////////////////////////////////////////////////////////////////
  669.77 +// Logging message handlers
  669.78 +
  669.79 +void Logging::OnOk()
  669.80 +{
  669.81 +	EndDialog(TRUE);
  669.82 +
  669.83 +	instance = NULL;
  669.84 +}
  669.85 +
  669.86 +void Logging::OnClear()
  669.87 +{
  669.88 +	text = "";
  669.89 +	m_log.SetWindowText("");
  669.90 +}
  669.91 +
  669.92 +void Logging::OnVerboseAgbprint()
  669.93 +{
  669.94 +	systemVerbose ^= 512;
  669.95 +}
  669.96 +
  669.97 +void Logging::OnVerboseDma0()
  669.98 +{
  669.99 +	systemVerbose ^= 16;
 669.100 +}
 669.101 +
 669.102 +void Logging::OnVerboseDma1()
 669.103 +{
 669.104 +	systemVerbose ^= 32;
 669.105 +}
 669.106 +
 669.107 +void Logging::OnVerboseDma2()
 669.108 +{
 669.109 +	systemVerbose ^= 64;
 669.110 +}
 669.111 +
 669.112 +void Logging::OnVerboseDma3()
 669.113 +{
 669.114 +	systemVerbose ^= 128;
 669.115 +}
 669.116 +
 669.117 +void Logging::OnVerboseIllegalRead()
 669.118 +{
 669.119 +	systemVerbose ^= 8;
 669.120 +}
 669.121 +
 669.122 +void Logging::OnVerboseIllegalWrite()
 669.123 +{
 669.124 +	systemVerbose ^= 4;
 669.125 +}
 669.126 +
 669.127 +void Logging::OnVerboseSwi()
 669.128 +{
 669.129 +	systemVerbose ^= 1;
 669.130 +}
 669.131 +
 669.132 +void Logging::OnVerboseUnalignedAccess()
 669.133 +{
 669.134 +	systemVerbose ^= 2;
 669.135 +}
 669.136 +
 669.137 +void Logging::OnVerboseUndefined()
 669.138 +{
 669.139 +	systemVerbose ^= 256;
 669.140 +}
 669.141 +
 669.142 +void Logging::OnSave()
 669.143 +{
 669.144 +	int len = m_log.GetWindowTextLength();
 669.145 +
 669.146 +	char *mem = (char *)malloc(len);
 669.147 +
 669.148 +	if (mem)
 669.149 +	{
 669.150 +		LPCTSTR exts[] = { ".txt", NULL };
 669.151 +		m_log.GetWindowText(mem, len);
 669.152 +		CString filter = "All Files|*.*||";
 669.153 +		FileDlg dlg(this, "", filter, 0,
 669.154 +		            NULL, exts, NULL, "Save output", true);
 669.155 +
 669.156 +		if (dlg.DoModal() == IDOK)
 669.157 +		{
 669.158 +			FILE *f = fopen(dlg.GetPathName(), "w");
 669.159 +			if (f)
 669.160 +			{
 669.161 +				fwrite(mem, 1, len, f);
 669.162 +				fclose(f);
 669.163 +			}
 669.164 +		}
 669.165 +	}
 669.166 +
 669.167 +	free(mem);
 669.168 +}
 669.169 +
 669.170 +void Logging::OnErrspaceLog()
 669.171 +{
 669.172 +	systemMessage(0, "Error allocating space");
 669.173 +}
 669.174 +
 669.175 +void Logging::OnMaxtextLog()
 669.176 +{
 669.177 +	systemMessage(0, "Max text length reached %d", m_log.GetLimitText());
 669.178 +}
 669.179 +
 669.180 +void Logging::PostNcDestroy()
 669.181 +{
 669.182 +	delete this;
 669.183 +}
 669.184 +
 669.185 +BOOL Logging::OnInitDialog()
 669.186 +{
 669.187 +	CDialog::OnInitDialog();
 669.188 +
 669.189 +	DIALOG_SIZER_START(sz)
 669.190 +	DIALOG_SIZER_ENTRY(IDC_LOG, DS_SizeY|DS_SizeX)
 669.191 +	DIALOG_SIZER_ENTRY(ID_OK, DS_MoveY)
 669.192 +	DIALOG_SIZER_ENTRY(IDC_CLEAR, DS_MoveY)
 669.193 +	DIALOG_SIZER_ENTRY(IDC_SAVE, DS_MoveY)
 669.194 +	DIALOG_SIZER_END()
 669.195 +	SetData(sz,
 669.196 +	        TRUE,
 669.197 +	        HKEY_CURRENT_USER,
 669.198 +	        "Software\\Emulators\\VisualBoyAdvance\\Viewer\\LogView",
 669.199 +	        NULL);
 669.200 +
 669.201 +	m_swi = (systemVerbose & 1) != 0;
 669.202 +	m_unaligned_access = (systemVerbose & 2) != 0;
 669.203 +	m_illegal_write    = (systemVerbose & 4) != 0;
 669.204 +	m_illegal_read     = (systemVerbose & 8) != 0;
 669.205 +	m_dma0      = (systemVerbose & 16) != 0;
 669.206 +	m_dma1      = (systemVerbose & 32) != 0;
 669.207 +	m_dma2      = (systemVerbose & 64) != 0;
 669.208 +	m_dma3      = (systemVerbose & 128) != 0;
 669.209 +	m_undefined = (systemVerbose & 256) != 0;
 669.210 +	m_agbprint  = (systemVerbose & 256) != 0;
 669.211 +	UpdateData(FALSE);
 669.212 +
 669.213 +	m_log.LimitText(-1);
 669.214 +	m_log.SetWindowText(text);
 669.215 +
 669.216 +	return TRUE; // return TRUE unless you set the focus to a control
 669.217 +	             // EXCEPTION: OCX Property Pages should return FALSE
 669.218 +}
 669.219 +
 669.220 +void Logging::log(const char *s)
 669.221 +{
 669.222 +	int size = ::SendMessage(m_log, WM_GETTEXTLENGTH, 0, 0);
 669.223 +	m_log.SetSel(size, size);
 669.224 +	m_log.ReplaceSel(s);
 669.225 +}
 669.226 +
 669.227 +void Logging::OnClose()
 669.228 +{
 669.229 +	EndDialog(FALSE);
 669.230 +
 669.231 +	instance = NULL;
 669.232 +
 669.233 +	CDialog::OnClose();
 669.234 +}
 669.235 +
 669.236 +void toolsLogging()
 669.237 +{
 669.238 +	if (Logging::instance == NULL)
 669.239 +	{
 669.240 +		Logging::instance = new Logging();
 669.241 +		Logging::instance->Create(IDD_LOGGING, AfxGetApp()->m_pMainWnd);
 669.242 +		Logging::instance->ShowWindow(SW_SHOW);
 669.243 +	}
 669.244 +	else
 669.245 +	{
 669.246 +		Logging::instance->SetForegroundWindow();
 669.247 +	}
 669.248 +}
 669.249 +
 669.250 +void toolsLog(const char *s)
 669.251 +{
 669.252 +	CString str;
 669.253 +	int     state = 0;
 669.254 +	if (s)
 669.255 +	{
 669.256 +		char c = *s++;
 669.257 +		while (c)
 669.258 +		{
 669.259 +			if (c == '\n' && state == 0)
 669.260 +				str += '\r';
 669.261 +			else if (c == '\r')
 669.262 +				state = 1;
 669.263 +			else
 669.264 +				state = 0;
 669.265 +			str += c;
 669.266 +			c    = *s++;
 669.267 +		}
 669.268 +	}
 669.269 +
 669.270 +	Logging::text += str;
 669.271 +	if (Logging::instance != NULL)
 669.272 +	{
 669.273 +		Logging::instance->log(str);
 669.274 +	}
 669.275 +}
 669.276 +
   670.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   670.2 +++ b/src/win32/Logging.h	Sat Mar 03 10:31:27 2012 -0600
   670.3 @@ -0,0 +1,78 @@
   670.4 +#if !defined(AFX_LOGGING_H__222FC21A_D40D_450D_8A1C_D33305E47B85__INCLUDED_)
   670.5 +#define AFX_LOGGING_H__222FC21A_D40D_450D_8A1C_D33305E47B85__INCLUDED_
   670.6 +
   670.7 +#if _MSC_VER > 1000
   670.8 +#pragma once
   670.9 +#endif // _MSC_VER > 1000
  670.10 +// -*- C++ -*-
  670.11 +// Logging.h : header file
  670.12 +//
  670.13 +
  670.14 +#include "ResizeDlg.h"
  670.15 +
  670.16 +/////////////////////////////////////////////////////////////////////////////
  670.17 +// Logging dialog
  670.18 +
  670.19 +class Logging : public ResizeDlg
  670.20 +{
  670.21 +	// Construction
  670.22 +public:
  670.23 +	void log(const char *);
  670.24 +	Logging(CWnd*pParent = NULL);  // standard constructor
  670.25 +
  670.26 +	// Dialog Data
  670.27 +	//{{AFX_DATA(Logging)
  670.28 +	enum { IDD = IDD_LOGGING };
  670.29 +	CEdit m_log;
  670.30 +	BOOL  m_swi;
  670.31 +	BOOL  m_unaligned_access;
  670.32 +	BOOL  m_illegal_write;
  670.33 +	BOOL  m_illegal_read;
  670.34 +	BOOL  m_dma0;
  670.35 +	BOOL  m_dma1;
  670.36 +	BOOL  m_dma2;
  670.37 +	BOOL  m_dma3;
  670.38 +	BOOL  m_agbprint;
  670.39 +	BOOL  m_undefined;
  670.40 +	//}}AFX_DATA
  670.41 +
  670.42 +	// Overrides
  670.43 +	// ClassWizard generated virtual function overrides
  670.44 +	//{{AFX_VIRTUAL(Logging)
  670.45 +protected:
  670.46 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  670.47 +	virtual void PostNcDestroy();
  670.48 +	//}}AFX_VIRTUAL
  670.49 +
  670.50 +	// Implementation
  670.51 +protected:
  670.52 +	// Generated message map functions
  670.53 +	//{{AFX_MSG(Logging)
  670.54 +	afx_msg void OnOk();
  670.55 +	afx_msg void OnClear();
  670.56 +	afx_msg void OnVerboseAgbprint();
  670.57 +	afx_msg void OnVerboseDma0();
  670.58 +	afx_msg void OnVerboseDma1();
  670.59 +	afx_msg void OnVerboseDma2();
  670.60 +	afx_msg void OnVerboseDma3();
  670.61 +	afx_msg void OnVerboseIllegalRead();
  670.62 +	afx_msg void OnVerboseIllegalWrite();
  670.63 +	afx_msg void OnVerboseSwi();
  670.64 +	afx_msg void OnVerboseUnalignedAccess();
  670.65 +	afx_msg void OnVerboseUndefined();
  670.66 +	afx_msg void OnSave();
  670.67 +	afx_msg void OnErrspaceLog();
  670.68 +	afx_msg void OnMaxtextLog();
  670.69 +	virtual BOOL OnInitDialog();
  670.70 +	afx_msg void OnClose();
  670.71 +	//}}AFX_MSG
  670.72 +	DECLARE_MESSAGE_MAP()
  670.73 +public:
  670.74 +	static Logging *instance;
  670.75 +	static CString  text;
  670.76 +};
  670.77 +
  670.78 +//{{AFX_INSERT_LOCATION}}
  670.79 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  670.80 +
  670.81 +#endif // !defined(AFX_LOGGING_H__222FC21A_D40D_450D_8A1C_D33305E47B85__INCLUDED_)
   671.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   671.2 +++ b/src/win32/LuaOpenDialog.cpp	Sat Mar 03 10:31:27 2012 -0600
   671.3 @@ -0,0 +1,369 @@
   671.4 +// LuaOpenDialog.cpp : implementation file
   671.5 +//
   671.6 +
   671.7 +//#include "stdafx.h"
   671.8 +//#include "resource.h"
   671.9 +#include "LuaOpenDialog.h"
  671.10 +#include "MainWnd.h"
  671.11 +#include "WinResUtil.h"
  671.12 +#include "WinMiscUtil.h"
  671.13 +#include "VBA.h"
  671.14 +#include "Sound.h"
  671.15 +
  671.16 +#include "../common/vbalua.h"
  671.17 +
  671.18 +HWND LuaConsoleHWnd = NULL;
  671.19 +HFONT hFont = NULL;
  671.20 +LOGFONT LuaConsoleLogFont;
  671.21 +
  671.22 +struct ControlLayoutInfo
  671.23 +{
  671.24 +	int controlID;
  671.25 +	
  671.26 +	enum LayoutType // what to do when the containing window resizes
  671.27 +	{
  671.28 +		NONE, // leave the control where it was
  671.29 +		RESIZE_END, // resize the control
  671.30 +		MOVE_START, // move the control
  671.31 +	};
  671.32 +	LayoutType horizontalLayout;
  671.33 +	LayoutType verticalLayout;
  671.34 +};
  671.35 +struct ControlLayoutState
  671.36 +{
  671.37 +	int x,y,width,height;
  671.38 +	bool valid;
  671.39 +	ControlLayoutState() : valid(false) {}
  671.40 +};
  671.41 +
  671.42 +static ControlLayoutInfo controlLayoutInfos [] = {
  671.43 +	{IDC_LUACONSOLE, ControlLayoutInfo::RESIZE_END, ControlLayoutInfo::RESIZE_END},
  671.44 +	{IDC_EDIT_LUAPATH, ControlLayoutInfo::RESIZE_END, ControlLayoutInfo::NONE},
  671.45 +	{IDC_BUTTON_LUARUN, ControlLayoutInfo::MOVE_START, ControlLayoutInfo::NONE},
  671.46 +	{IDC_BUTTON_LUASTOP, ControlLayoutInfo::MOVE_START, ControlLayoutInfo::NONE},
  671.47 +};
  671.48 +static const int numControlLayoutInfos = sizeof(controlLayoutInfos)/sizeof(*controlLayoutInfos);
  671.49 +
  671.50 +struct {
  671.51 +	int width; int height;
  671.52 +	ControlLayoutState layoutState [numControlLayoutInfos];
  671.53 +} windowInfo;
  671.54 +
  671.55 +void PrintToWindowConsole(int hDlgAsInt, const char* str)
  671.56 +{
  671.57 +	HWND hDlg = (HWND)hDlgAsInt;
  671.58 +	HWND hConsole = GetDlgItem(hDlg, IDC_LUACONSOLE);
  671.59 +
  671.60 +	int length = GetWindowTextLength(hConsole);
  671.61 +	if(length >= 250000)
  671.62 +	{
  671.63 +		// discard first half of text if it's getting too long
  671.64 +		SendMessage(hConsole, EM_SETSEL, 0, length/2);
  671.65 +		SendMessage(hConsole, EM_REPLACESEL, false, (LPARAM)"");
  671.66 +		length = GetWindowTextLength(hConsole);
  671.67 +	}
  671.68 +	SendMessage(hConsole, EM_SETSEL, length, length);
  671.69 +
  671.70 +	//LuaPerWindowInfo& info = LuaWindowInfo[hDlg];
  671.71 +
  671.72 +	{
  671.73 +		SendMessage(hConsole, EM_REPLACESEL, false, (LPARAM)str);
  671.74 +	}
  671.75 +}
  671.76 +
  671.77 +void WinLuaOnStart(int hDlgAsInt)
  671.78 +{
  671.79 +	HWND hDlg = (HWND)hDlgAsInt;
  671.80 +	//LuaPerWindowInfo& info = LuaWindowInfo[hDlg];
  671.81 +	//info.started = true;
  671.82 +	EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_LUABROWSE), false); // disable browse while running because it misbehaves if clicked in a frameadvance loop
  671.83 +	EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_LUASTOP), true);
  671.84 +	SetWindowText(GetDlgItem(hDlg, IDC_BUTTON_LUARUN), "Restart");
  671.85 +	SetWindowText(GetDlgItem(hDlg, IDC_LUACONSOLE), ""); // clear the console
  671.86 +//	Show_Genesis_Screen(HWnd); // otherwise we might never show the first thing the script draws
  671.87 +}
  671.88 +
  671.89 +void WinLuaOnStop(int hDlgAsInt)
  671.90 +{
  671.91 +	HWND hDlg = (HWND)hDlgAsInt;
  671.92 +	//LuaPerWindowInfo& info = LuaWindowInfo[hDlg];
  671.93 +
  671.94 +	HWND prevWindow = GetActiveWindow();
  671.95 +	SetActiveWindow(hDlg); // bring to front among other script/secondary windows, since a stopped script will have some message for the user that would be easier to miss otherwise
  671.96 +	if(prevWindow == AfxGetMainWnd()->GetSafeHwnd()) SetActiveWindow(prevWindow);
  671.97 +
  671.98 +	//info.started = false;
  671.99 +	EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_LUABROWSE), true);
 671.100 +	EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_LUASTOP), false);
 671.101 +	SetWindowText(GetDlgItem(hDlg, IDC_BUTTON_LUARUN), "Run");
 671.102 +//	if(statusOK)
 671.103 +//		Show_Genesis_Screen(MainWindow->getHWnd()); // otherwise we might never show the last thing the script draws
 671.104 +	//if(info.closeOnStop)
 671.105 +	//	PostMessage(hDlg, WM_CLOSE, 0, 0);
 671.106 +}
 671.107 +
 671.108 +INT_PTR CALLBACK DlgLuaScriptDialog(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
 671.109 +{
 671.110 +	RECT r;
 671.111 +	RECT r2;
 671.112 +	int dx1, dy1, dx2, dy2;
 671.113 +
 671.114 +	switch (msg) {
 671.115 +
 671.116 +	case WM_INITDIALOG:
 671.117 +	{
 671.118 +		// remove the 30000 character limit from the console control
 671.119 +		SendMessage(GetDlgItem(hDlg, IDC_LUACONSOLE),EM_LIMITTEXT,0,0);
 671.120 +
 671.121 +		GetWindowRect(AfxGetMainWnd()->GetSafeHwnd(), &r);
 671.122 +		dx1 = (r.right - r.left) / 2;
 671.123 +		dy1 = (r.bottom - r.top) / 2;
 671.124 +
 671.125 +		GetWindowRect(hDlg, &r2);
 671.126 +		dx2 = (r2.right - r2.left) / 2;
 671.127 +		dy2 = (r2.bottom - r2.top) / 2;
 671.128 +
 671.129 +		int windowIndex = 0;//std::find(LuaScriptHWnds.begin(), LuaScriptHWnds.end(), hDlg) - LuaScriptHWnds.begin();
 671.130 +		int staggerOffset = windowIndex * 24;
 671.131 +		r.left += staggerOffset;
 671.132 +		r.right += staggerOffset;
 671.133 +		r.top += staggerOffset;
 671.134 +		r.bottom += staggerOffset;
 671.135 +
 671.136 +		// push it away from the main window if we can
 671.137 +		const int width = (r.right-r.left); 
 671.138 +		const int width2 = (r2.right-r2.left); 
 671.139 +		if(r.left+width2 + width < GetSystemMetrics(SM_CXSCREEN))
 671.140 +		{
 671.141 +			r.right += width;
 671.142 +			r.left += width;
 671.143 +		}
 671.144 +		else if((int)r.left - (int)width2 > 0)
 671.145 +		{
 671.146 +			r.right -= width2;
 671.147 +			r.left -= width2;
 671.148 +		}
 671.149 +
 671.150 +		SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
 671.151 +
 671.152 +		RECT r3;
 671.153 +		GetClientRect(hDlg, &r3);
 671.154 +		windowInfo.width = r3.right - r3.left;
 671.155 +		windowInfo.height = r3.bottom - r3.top;
 671.156 +		for(int i = 0; i < numControlLayoutInfos; i++) {
 671.157 +			ControlLayoutState& layoutState = windowInfo.layoutState[i];
 671.158 +			layoutState.valid = false;
 671.159 +		}
 671.160 +
 671.161 +		DragAcceptFiles(hDlg, true);
 671.162 +		SetDlgItemText(hDlg, IDC_EDIT_LUAPATH, VBAGetLuaScriptName());
 671.163 +
 671.164 +		SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &LuaConsoleLogFont, 0); // reset with an acceptable font
 671.165 +		return true;
 671.166 +	}	break;
 671.167 +
 671.168 +	case WM_SIZE:
 671.169 +	{
 671.170 +		// resize or move controls in the window as necessary when the window is resized
 671.171 +
 671.172 +		//LuaPerWindowInfo& windowInfo = LuaWindowInfo[hDlg];
 671.173 +		int prevDlgWidth = windowInfo.width;
 671.174 +		int prevDlgHeight = windowInfo.height;
 671.175 +
 671.176 +		int dlgWidth = LOWORD(lParam);
 671.177 +		int dlgHeight = HIWORD(lParam);
 671.178 +
 671.179 +		int deltaWidth = dlgWidth - prevDlgWidth;
 671.180 +		int deltaHeight = dlgHeight - prevDlgHeight;
 671.181 +
 671.182 +		for(int i = 0; i < numControlLayoutInfos; i++)
 671.183 +		{
 671.184 +			ControlLayoutInfo layoutInfo = controlLayoutInfos[i];
 671.185 +			ControlLayoutState& layoutState = windowInfo.layoutState[i];
 671.186 +
 671.187 +			HWND hCtrl = GetDlgItem(hDlg,layoutInfo.controlID);
 671.188 +
 671.189 +			int x,y,width,height;
 671.190 +			if(layoutState.valid)
 671.191 +			{
 671.192 +				x = layoutState.x;
 671.193 +				y = layoutState.y;
 671.194 +				width = layoutState.width;
 671.195 +				height = layoutState.height;
 671.196 +			}
 671.197 +			else
 671.198 +			{
 671.199 +				RECT r;
 671.200 +				GetWindowRect(hCtrl, &r);
 671.201 +				POINT p = {r.left, r.top};
 671.202 +				ScreenToClient(hDlg, &p);
 671.203 +				x = p.x;
 671.204 +				y = p.y;
 671.205 +				width = r.right - r.left;
 671.206 +				height = r.bottom - r.top;
 671.207 +			}
 671.208 +
 671.209 +			switch(layoutInfo.horizontalLayout)
 671.210 +			{
 671.211 +				case ControlLayoutInfo::RESIZE_END: width += deltaWidth; break;
 671.212 +				case ControlLayoutInfo::MOVE_START: x += deltaWidth; break;
 671.213 +				default: break;
 671.214 +			}
 671.215 +			switch(layoutInfo.verticalLayout)
 671.216 +			{
 671.217 +				case ControlLayoutInfo::RESIZE_END: height += deltaHeight; break;
 671.218 +				case ControlLayoutInfo::MOVE_START: y += deltaHeight; break;
 671.219 +				default: break;
 671.220 +			}
 671.221 +
 671.222 +			SetWindowPos(hCtrl, 0, x,y, width,height, 0);
 671.223 +
 671.224 +			layoutState.x = x;
 671.225 +			layoutState.y = y;
 671.226 +			layoutState.width = width;
 671.227 +			layoutState.height = height;
 671.228 +			layoutState.valid = true;
 671.229 +		}
 671.230 +
 671.231 +		windowInfo.width = dlgWidth;
 671.232 +		windowInfo.height = dlgHeight;
 671.233 +
 671.234 +		RedrawWindow(hDlg, NULL, NULL, RDW_INVALIDATE);
 671.235 +	}	break;
 671.236 +
 671.237 +	case WM_COMMAND:
 671.238 +		switch (LOWORD(wParam)) {
 671.239 +			case IDOK:
 671.240 +			case IDCANCEL: {
 671.241 +				EndDialog(hDlg, true); // goto case WM_CLOSE;
 671.242 +			}	break;
 671.243 +
 671.244 +			case IDC_BUTTON_LUARUN:
 671.245 +			{
 671.246 +				char filename[MAX_PATH];
 671.247 +				GetDlgItemText(hDlg, IDC_EDIT_LUAPATH, filename, MAX_PATH);
 671.248 +				VBALoadLuaCode(filename);
 671.249 +			}	break;
 671.250 +
 671.251 +			case IDC_BUTTON_LUASTOP:
 671.252 +			{
 671.253 +				VBALuaStop();
 671.254 +			}	break;
 671.255 +
 671.256 +			case IDC_BUTTON_LUAEDIT:
 671.257 +			{
 671.258 +				char Str_Tmp [1024];
 671.259 +				SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_GETTEXT,(WPARAM)512,(LPARAM)Str_Tmp);
 671.260 +				// tell the OS to open the file with its associated editor,
 671.261 +				// without blocking on it or leaving a command window open.
 671.262 +				if((int)ShellExecute(NULL, "edit", Str_Tmp, NULL, NULL, SW_SHOWNORMAL) == SE_ERR_NOASSOC)
 671.263 +					if((int)ShellExecute(NULL, "open", Str_Tmp, NULL, NULL, SW_SHOWNORMAL) == SE_ERR_NOASSOC)
 671.264 +						ShellExecute(NULL, NULL, "notepad", Str_Tmp, NULL, SW_SHOWNORMAL);
 671.265 +			}	break;
 671.266 +
 671.267 +			case IDC_BUTTON_LUABROWSE:
 671.268 +			{
 671.269 +				systemSoundClearBuffer();
 671.270 +
 671.271 +				CString filter = winResLoadFilter(IDS_FILTER_LUA);
 671.272 +				CString title  = winResLoadString(IDS_SELECT_LUA_NAME);
 671.273 +
 671.274 +				CString luaName = winGetDestFilename(theApp.gameFilename, IDS_LUA_DIR, ".lua");
 671.275 +				CString luaDir = winGetDestDir(IDS_LUA_DIR);
 671.276 +
 671.277 +				filter.Replace('|', '\000');
 671.278 +//				char *p = filter.GetBuffer(0);
 671.279 +//				while ((p = strchr(p, '|')) != NULL)
 671.280 +//					*p++ = 0;
 671.281 +
 671.282 +				OPENFILENAME  ofn;
 671.283 +				ZeroMemory( (LPVOID)&ofn, sizeof(OPENFILENAME) );
 671.284 +				ofn.lpstrFile       = luaName.GetBuffer(MAX_PATH);
 671.285 +				ofn.nMaxFile        = MAX_PATH;
 671.286 +				ofn.lStructSize     = sizeof(OPENFILENAME);
 671.287 +				ofn.hwndOwner       = hDlg;
 671.288 +				ofn.lpstrFilter     = filter;
 671.289 +				ofn.nFilterIndex    = 0;
 671.290 +				ofn.lpstrInitialDir = luaDir;
 671.291 +				ofn.lpstrTitle      = title;
 671.292 +				ofn.lpstrDefExt     = "lua";
 671.293 +				ofn.Flags           = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_ENABLESIZING | OFN_EXPLORER; // hide previously-ignored read-only checkbox (the real read-only box is in the open-movie dialog itself)
 671.294 +				if(GetOpenFileName( &ofn ))
 671.295 +				{
 671.296 +					SetWindowText(GetDlgItem(hDlg, IDC_EDIT_LUAPATH), luaName);
 671.297 +				}
 671.298 +				return true;
 671.299 +			}	break;
 671.300 +
 671.301 +			case IDC_EDIT_LUAPATH:
 671.302 +			{
 671.303 +				char filename[MAX_PATH];
 671.304 +				GetDlgItemText(hDlg, IDC_EDIT_LUAPATH, filename, MAX_PATH);
 671.305 +				FILE* file = fopen(filename, "rb");
 671.306 +				EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_LUAEDIT), file != NULL);
 671.307 +				if(file)
 671.308 +					fclose(file);
 671.309 +			}	break;
 671.310 +
 671.311 +			case IDC_LUACONSOLE_CHOOSEFONT:
 671.312 +			{
 671.313 +				CHOOSEFONT cf;
 671.314 +
 671.315 +				ZeroMemory(&cf, sizeof(cf));
 671.316 +				cf.lStructSize = sizeof(CHOOSEFONT);
 671.317 +				cf.hwndOwner = hDlg;
 671.318 +				cf.lpLogFont = &LuaConsoleLogFont;
 671.319 +				cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT;
 671.320 +				if (ChooseFont(&cf)) {
 671.321 +					if (hFont) {
 671.322 +						DeleteObject(hFont);
 671.323 +						hFont = NULL;
 671.324 +					}
 671.325 +					hFont = CreateFontIndirect(&LuaConsoleLogFont);
 671.326 +					if (hFont)
 671.327 +						SendDlgItemMessage(hDlg, IDC_LUACONSOLE, WM_SETFONT, (WPARAM)hFont, 0);
 671.328 +				}
 671.329 +			}	break;
 671.330 +
 671.331 +			case IDC_LUACONSOLE_CLEAR:
 671.332 +			{
 671.333 +				SetWindowText(GetDlgItem(hDlg, IDC_LUACONSOLE), "");
 671.334 +			}	break;
 671.335 +		}
 671.336 +		break;
 671.337 +
 671.338 +	case WM_CLOSE: {
 671.339 +		SendMessage(hDlg, WM_DESTROY, 0, 0);
 671.340 +	}	break;
 671.341 +
 671.342 +	case WM_DESTROY: {
 671.343 +		//VBALuaStop();
 671.344 +		DragAcceptFiles(hDlg, FALSE);
 671.345 +		if (hFont) {
 671.346 +			DeleteObject(hFont);
 671.347 +			hFont = NULL;
 671.348 +		}
 671.349 +		LuaConsoleHWnd = NULL;
 671.350 +	}	break;
 671.351 +
 671.352 +	case WM_DROPFILES: {
 671.353 +		HDROP hDrop;
 671.354 +		//UINT fileNo;
 671.355 +		UINT fileCount;
 671.356 +		char filename[_MAX_PATH];
 671.357 +
 671.358 +		hDrop = (HDROP)wParam;
 671.359 +		fileCount = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
 671.360 +		if (fileCount > 0) {
 671.361 +			DragQueryFile(hDrop, 0, filename, sizeof(filename));
 671.362 +			SetWindowText(GetDlgItem(hDlg, IDC_EDIT_LUAPATH), filename);
 671.363 +		}
 671.364 +		DragFinish(hDrop);
 671.365 +		return true;
 671.366 +	}	break;
 671.367 +
 671.368 +	}
 671.369 +
 671.370 +	return false;
 671.371 +
 671.372 +}
   672.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   672.2 +++ b/src/win32/LuaOpenDialog.h	Sat Mar 03 10:31:27 2012 -0600
   672.3 @@ -0,0 +1,21 @@
   672.4 +#if !defined(VBA_WIN32_LUAOPENDIALOG_H_INCLUDED)
   672.5 +#define VBA_WIN32_LUAOPENDIALOG_H_INCLUDED
   672.6 +
   672.7 +#if _MSC_VER > 1000
   672.8 +#pragma once
   672.9 +#endif // _MSC_VER > 1000
  672.10 +// -*- C++ -*-
  672.11 +// LuaOpenDialog.h : header file
  672.12 +//
  672.13 +
  672.14 +#include "stdafx.h"
  672.15 +#include "resource.h"
  672.16 +
  672.17 +extern HWND LuaConsoleHWnd;
  672.18 +
  672.19 +void PrintToWindowConsole(int hDlgAsInt, const char* str);
  672.20 +void WinLuaOnStart(int hDlgAsInt);
  672.21 +void WinLuaOnStop(int hDlgAsInt);
  672.22 +INT_PTR CALLBACK DlgLuaScriptDialog(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  672.23 +
  672.24 +#endif // !defined(VBA_WIN32_LUAOPENDIALOG_H_INCLUDED)
   673.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   673.2 +++ b/src/win32/MainWnd.cpp	Sat Mar 03 10:31:27 2012 -0600
   673.3 @@ -0,0 +1,1511 @@
   673.4 +// MainWnd.cpp : implementation file
   673.5 +//
   673.6 +
   673.7 +#include "stdafx.h"
   673.8 +#include <winsock.h>
   673.9 +
  673.10 +#include "resource.h"
  673.11 +#include "MainWnd.h"
  673.12 +
  673.13 +#include "CmdAccelOb.h"
  673.14 +#include "FileDlg.h"
  673.15 +#include "ModeConfirm.h"
  673.16 +#include "Reg.h"
  673.17 +#include "WinResUtil.h"
  673.18 +#include "WinMiscUtil.h"
  673.19 +#include "Input.h"
  673.20 +#include "7zip/7zip.h"
  673.21 +#include "7zip/OpenArchive.h"
  673.22 +#include "LuaOpenDialog.h"
  673.23 +#include "ram_search.h"
  673.24 +#include "ramwatch.h"
  673.25 +#include "Sound.h"
  673.26 +#include "VBA.h"
  673.27 +
  673.28 +#include "../version.h"
  673.29 +#include "../common/Util.h"
  673.30 +#include "../common/movie.h"
  673.31 +#include "../common/vbalua.h"
  673.32 +#include "../gba/GBASound.h"
  673.33 +#include "../gba/GBAGlobals.h"
  673.34 +#include "../gb/gbGlobals.h"
  673.35 +
  673.36 +#define VBA_CONFIRM_MODE WM_APP + 100
  673.37 +
  673.38 +/////////////////////////////////////////////////////////////////////////////
  673.39 +// MainWnd
  673.40 +
  673.41 +MainWnd::MainWnd()
  673.42 +{
  673.43 +	m_hAccelTable = NULL;
  673.44 +	arrow		  = LoadCursor(NULL, IDC_ARROW);
  673.45 +
  673.46 +	InitDecoder();
  673.47 +}
  673.48 +
  673.49 +MainWnd::~MainWnd()
  673.50 +{
  673.51 +	CleanupDecoder();
  673.52 +}
  673.53 +
  673.54 +BEGIN_MESSAGE_MAP(MainWnd, CWnd)
  673.55 +//{{AFX_MSG_MAP(MainWnd)
  673.56 +ON_WM_MOVE()
  673.57 +ON_WM_SIZE()
  673.58 +ON_WM_CLOSE()
  673.59 +ON_WM_INITMENUPOPUP()
  673.60 +ON_WM_INITMENU()
  673.61 +ON_WM_CONTEXTMENU()
  673.62 +ON_WM_MOUSEMOVE()
  673.63 +ON_WM_ACTIVATE()
  673.64 +ON_WM_ACTIVATEAPP()
  673.65 +ON_WM_DROPFILES()
  673.66 +ON_WM_PAINT()
  673.67 +
  673.68 +ON_COMMAND(ID_HELP_ABOUT, OnHelpAbout)
  673.69 +ON_COMMAND(ID_HELP_FAQ, OnHelpFaq)
  673.70 +ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
  673.71 +ON_COMMAND(ID_FILE_OPENGAMEBOY, OnFileOpenGBx)
  673.72 +ON_COMMAND(ID_FILE_PAUSE, OnFilePause)
  673.73 +ON_UPDATE_COMMAND_UI(ID_FILE_PAUSE, OnUpdateFilePause)
  673.74 +ON_COMMAND(ID_FILE_RESET, OnFileReset)
  673.75 +ON_UPDATE_COMMAND_UI(ID_FILE_RESET, OnUpdateFileReset)
  673.76 +ON_UPDATE_COMMAND_UI(ID_FILE_RECENT_FREEZE, OnUpdateFileRecentFreeze)
  673.77 +ON_COMMAND(ID_FILE_RECENT_RESET, OnFileRecentReset)
  673.78 +ON_COMMAND(ID_FILE_RECENT_FREEZE, OnFileRecentFreeze)
  673.79 +ON_COMMAND(ID_FILE_EXIT, OnFileExit)
  673.80 +ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
  673.81 +ON_UPDATE_COMMAND_UI(ID_FILE_CLOSE, OnUpdateFileClose)
  673.82 +ON_COMMAND(ID_FILE_LOAD, OnFileLoad)
  673.83 +ON_UPDATE_COMMAND_UI(ID_FILE_LOAD, OnUpdateFileLoad)
  673.84 +ON_COMMAND(ID_FILE_SAVE, OnFileSave)
  673.85 +ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
  673.86 +ON_COMMAND(ID_FILE_IMPORT_BATTERYFILE, OnFileImportBatteryfile)
  673.87 +ON_UPDATE_COMMAND_UI(ID_FILE_IMPORT_BATTERYFILE, OnUpdateFileImportBatteryfile)
  673.88 +ON_COMMAND(ID_FILE_IMPORT_GAMESHARKCODEFILE, OnFileImportGamesharkcodefile)
  673.89 +ON_UPDATE_COMMAND_UI(ID_FILE_IMPORT_GAMESHARKCODEFILE, OnUpdateFileImportGamesharkcodefile)
  673.90 +ON_COMMAND(ID_FILE_IMPORT_GAMESHARKSNAPSHOT, OnFileImportGamesharksnapshot)
  673.91 +ON_UPDATE_COMMAND_UI(ID_FILE_IMPORT_GAMESHARKSNAPSHOT, OnUpdateFileImportGamesharksnapshot)
  673.92 +ON_COMMAND(ID_FILE_EXPORT_BATTERYFILE, OnFileExportBatteryfile)
  673.93 +ON_UPDATE_COMMAND_UI(ID_FILE_EXPORT_BATTERYFILE, OnUpdateFileExportBatteryfile)
  673.94 +ON_COMMAND(ID_FILE_EXPORT_GAMESHARKSNAPSHOT, OnFileExportGamesharksnapshot)
  673.95 +ON_UPDATE_COMMAND_UI(ID_FILE_EXPORT_GAMESHARKSNAPSHOT, OnUpdateFileExportGamesharksnapshot)
  673.96 +ON_COMMAND(ID_FILE_QUICKSCREENCAPTURE, OnFileQuickScreencapture)
  673.97 +ON_COMMAND(ID_FILE_SCREENCAPTURE, OnFileScreencapture)
  673.98 +ON_UPDATE_COMMAND_UI(ID_FILE_SCREENCAPTURE, OnUpdateFileScreencapture)
  673.99 +ON_COMMAND(ID_FILE_ROMINFORMATION, OnFileRominformation)
 673.100 +ON_UPDATE_COMMAND_UI(ID_FILE_ROMINFORMATION, OnUpdateFileRominformation)
 673.101 +ON_COMMAND(ID_FILE_TOGGLEMENU, OnFileTogglemenu)
 673.102 +ON_UPDATE_COMMAND_UI(ID_FILE_TOGGLEMENU, OnUpdateFileTogglemenu)
 673.103 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_6, OnUpdateOptionsFrameskipThrottle6)
 673.104 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_15, OnUpdateOptionsFrameskipThrottle15)
 673.105 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_25, OnUpdateOptionsFrameskipThrottle25)
 673.106 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_50, OnUpdateOptionsFrameskipThrottle50)
 673.107 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_75, OnUpdateOptionsFrameskipThrottle75)
 673.108 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_100, OnUpdateOptionsFrameskipThrottle100)
 673.109 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_125, OnUpdateOptionsFrameskipThrottle125)
 673.110 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_150, OnUpdateOptionsFrameskipThrottle150)
 673.111 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_200, OnUpdateOptionsFrameskipThrottle200)
 673.112 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_300, OnUpdateOptionsFrameskipThrottle300)
 673.113 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_400, OnUpdateOptionsFrameskipThrottle400)
 673.114 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_600, OnUpdateOptionsFrameskipThrottle600)
 673.115 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_1000, OnUpdateOptionsFrameskipThrottle1000)
 673.116 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_OTHER, OnUpdateOptionsFrameskipThrottleOther)
 673.117 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_INCREASE, OnUpdateOptionsFrameskipThrottleIncrease)
 673.118 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_THROTTLE_DECREASE, OnUpdateOptionsFrameskipThrottleDecrease)
 673.119 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_6, OnOptionsFrameskipThrottle6)
 673.120 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_15, OnOptionsFrameskipThrottle15)
 673.121 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_25, OnOptionsFrameskipThrottle25)
 673.122 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_50, OnOptionsFrameskipThrottle50)
 673.123 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_75, OnOptionsFrameskipThrottle75)
 673.124 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_100, OnOptionsFrameskipThrottle100)
 673.125 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_125, OnOptionsFrameskipThrottle125)
 673.126 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_150, OnOptionsFrameskipThrottle150)
 673.127 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_200, OnOptionsFrameskipThrottle200)
 673.128 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_300, OnOptionsFrameskipThrottle300)
 673.129 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_400, OnOptionsFrameskipThrottle400)
 673.130 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_600, OnOptionsFrameskipThrottle600)
 673.131 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_1000, OnOptionsFrameskipThrottle1000)
 673.132 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_OTHER, OnOptionsFrameskipThrottleOther)
 673.133 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_INCREASE, OnOptionsFrameskipThrottleIncrease)
 673.134 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_THROTTLE_DECREASE, OnOptionsFrameskipThrottleDecrease)
 673.135 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_ACCURATEPITCH, OnOptionsFrameskipAccuratePitch)
 673.136 +ON_COMMAND(ID_OPTIONS_FRAMESKIP_ACCURATESPEED, OnOptionsFrameskipAccurateSpeed)
 673.137 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_ACCURATEPITCH, OnUpdateOptionsFrameskipAccuratePitch)
 673.138 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FRAMESKIP_ACCURATESPEED, OnUpdateOptionsFrameskipAccurateSpeed)
 673.139 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_FRAMESKIP_0, OnUpdateOptionsVideoFrameskip0)
 673.140 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_FRAMESKIP_1, OnUpdateOptionsVideoFrameskip1)
 673.141 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_FRAMESKIP_2, OnUpdateOptionsVideoFrameskip2)
 673.142 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_FRAMESKIP_3, OnUpdateOptionsVideoFrameskip3)
 673.143 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_FRAMESKIP_4, OnUpdateOptionsVideoFrameskip4)
 673.144 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_FRAMESKIP_5, OnUpdateOptionsVideoFrameskip5)
 673.145 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_FRAMESKIP_6, OnUpdateOptionsVideoFrameskip6)
 673.146 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_FRAMESKIP_7, OnUpdateOptionsVideoFrameskip7)
 673.147 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_FRAMESKIP_8, OnUpdateOptionsVideoFrameskip8)
 673.148 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_FRAMESKIP_9, OnUpdateOptionsVideoFrameskip9)
 673.149 +ON_COMMAND(ID_OPTIONS_VIDEO_VSYNC, OnOptionsVideoVsync)
 673.150 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_VSYNC, OnUpdateOptionsVideoVsync)
 673.151 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_X1, OnUpdateOptionsVideoX1)
 673.152 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_X2, OnUpdateOptionsVideoX2)
 673.153 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_X3, OnUpdateOptionsVideoX3)
 673.154 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_X4, OnUpdateOptionsVideoX4)
 673.155 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_FULLSCREEN320X240, OnUpdateOptionsVideoFullscreen320x240)
 673.156 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_FULLSCREEN640X480, OnUpdateOptionsVideoFullscreen640x480)
 673.157 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_FULLSCREEN800X600, OnUpdateOptionsVideoFullscreen800x600)
 673.158 +ON_COMMAND(ID_OPTIONS_VIDEO_FULLSCREEN320X240, OnOptionsVideoFullscreen320x240)
 673.159 +ON_COMMAND(ID_OPTIONS_VIDEO_FULLSCREEN640X480, OnOptionsVideoFullscreen640x480)
 673.160 +ON_COMMAND(ID_OPTIONS_VIDEO_FULLSCREEN800X600, OnOptionsVideoFullscreen800x600)
 673.161 +ON_COMMAND(ID_OPTIONS_VIDEO_FULLSCREEN, OnOptionsVideoFullscreen)
 673.162 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_FULLSCREEN, OnUpdateOptionsVideoFullscreen)
 673.163 +ON_COMMAND(ID_OPTIONS_VIDEO_DISABLESFX, OnOptionsVideoDisablesfx)
 673.164 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_DISABLESFX, OnUpdateOptionsVideoDisablesfx)
 673.165 +ON_COMMAND(ID_OPTIONS_VIDEO_FULLSCREENSTRETCHTOFIT, OnOptionsVideoFullscreenstretchtofit)
 673.166 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_FULLSCREENSTRETCHTOFIT, OnUpdateOptionsVideoFullscreenstretchtofit)
 673.167 +ON_COMMAND(ID_OPTIONS_VIDEO_RENDERMETHOD_GDI, OnOptionsVideoRendermethodGdi)
 673.168 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_RENDERMETHOD_GDI, OnUpdateOptionsVideoRendermethodGdi)
 673.169 +ON_COMMAND(ID_OPTIONS_VIDEO_RENDERMETHOD_DIRECTDRAW, OnOptionsVideoRendermethodDirectdraw)
 673.170 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_RENDERMETHOD_DIRECTDRAW, OnUpdateOptionsVideoRendermethodDirectdraw)
 673.171 +ON_COMMAND(ID_OPTIONS_VIDEO_RENDERMETHOD_DIRECT3D, OnOptionsVideoRendermethodDirect3d)
 673.172 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_RENDERMETHOD_DIRECT3D, OnUpdateOptionsVideoRendermethodDirect3d)
 673.173 +ON_COMMAND(ID_OPTIONS_VIDEO_RENDERMETHOD_OPENGL, OnOptionsVideoRendermethodOpengl)
 673.174 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_RENDERMETHOD_OPENGL, OnUpdateOptionsVideoRendermethodOpengl)
 673.175 +ON_COMMAND(ID_OPTIONS_VIDEO_TRIPLEBUFFERING, OnOptionsVideoTriplebuffering)
 673.176 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_TRIPLEBUFFERING, OnUpdateOptionsVideoTriplebuffering)
 673.177 +ON_COMMAND(ID_OPTIONS_VIDEO_DDRAWEMULATIONONLY, OnOptionsVideoDdrawemulationonly)
 673.178 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_DDRAWEMULATIONONLY, OnUpdateOptionsVideoDdrawemulationonly)
 673.179 +ON_COMMAND(ID_OPTIONS_VIDEO_DDRAWUSEVIDEOMEMORY, OnOptionsVideoDdrawusevideomemory)
 673.180 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_DDRAWUSEVIDEOMEMORY, OnUpdateOptionsVideoDdrawusevideomemory)
 673.181 +ON_COMMAND(ID_OPTIONS_VIDEO_RENDEROPTIONS_D3DNOFILTER, OnOptionsVideoRenderoptionsD3dnofilter)
 673.182 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_RENDEROPTIONS_D3DNOFILTER, OnUpdateOptionsVideoRenderoptionsD3dnofilter)
 673.183 +ON_COMMAND(ID_OPTIONS_VIDEO_RENDEROPTIONS_D3DBILINEAR, OnOptionsVideoRenderoptionsD3dbilinear)
 673.184 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_RENDEROPTIONS_D3DBILINEAR, OnUpdateOptionsVideoRenderoptionsD3dbilinear)
 673.185 +ON_COMMAND(ID_OPTIONS_VIDEO_RENDEROPTIONS_GLNEAREST, OnOptionsVideoRenderoptionsGlnearest)
 673.186 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_RENDEROPTIONS_GLNEAREST, OnUpdateOptionsVideoRenderoptionsGlnearest)
 673.187 +ON_COMMAND(ID_OPTIONS_VIDEO_RENDEROPTIONS_GLBILINEAR, OnOptionsVideoRenderoptionsGlbilinear)
 673.188 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_RENDEROPTIONS_GLBILINEAR, OnUpdateOptionsVideoRenderoptionsGlbilinear)
 673.189 +ON_COMMAND(ID_OPTIONS_VIDEO_RENDEROPTIONS_GLTRIANGLE, OnOptionsVideoRenderoptionsGltriangle)
 673.190 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_RENDEROPTIONS_GLTRIANGLE, OnUpdateOptionsVideoRenderoptionsGltriangle)
 673.191 +ON_COMMAND(ID_OPTIONS_VIDEO_RENDEROPTIONS_GLQUADS, OnOptionsVideoRenderoptionsGlquads)
 673.192 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_RENDEROPTIONS_GLQUADS, OnUpdateOptionsVideoRenderoptionsGlquads)
 673.193 +ON_COMMAND(ID_OPTIONS_VIDEO_RENDEROPTIONS_SELECTSKIN, OnOptionsVideoRenderoptionsSelectskin)
 673.194 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_RENDEROPTIONS_SELECTSKIN, OnUpdateOptionsVideoRenderoptionsSelectskin)
 673.195 +ON_COMMAND(ID_OPTIONS_VIDEO_RENDEROPTIONS_SKIN, OnOptionsVideoRenderoptionsSkin)
 673.196 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_RENDEROPTIONS_SKIN, OnUpdateOptionsVideoRenderoptionsSkin)
 673.197 +ON_COMMAND(ID_OPTIONS_EMULATOR_ASSOCIATE, OnOptionsEmulatorAssociate)
 673.198 +ON_COMMAND(ID_OPTIONS_EMULATOR_DIRECTORIES, OnOptionsEmulatorDirectories)
 673.199 +ON_COMMAND_RANGE(ID_OPTIONS_PREFER_ARCHIVE_NAME, ID_OPTIONS_PREFER_ROM_NAME, OnOptionsEmulatorFilenamePreference)
 673.200 +ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_PREFER_ARCHIVE_NAME, ID_OPTIONS_PREFER_ROM_NAME, OnUpdateOptionsEmulatorFilenamePreference)
 673.201 +ON_COMMAND(ID_OPTIONS_VIDEO_DISABLESTATUSMESSAGES, OnOptionsVideoDisablestatusmessages)
 673.202 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_DISABLESTATUSMESSAGES, OnUpdateOptionsVideoDisablestatusmessages)
 673.203 +ON_COMMAND(ID_OPTIONS_EMULATOR_SYNCHRONIZE, OnOptionsEmulatorSynchronize)
 673.204 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_SYNCHRONIZE, OnUpdateOptionsEmulatorSynchronize)
 673.205 +
 673.206 +ON_COMMAND(ID_OPTIONS_EMULATOR_ALWAYSONTOP, OnOptionsEmulatorAlwaysOnTop)
 673.207 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_ALWAYSONTOP, OnUpdateOptionsEmulatorAlwaysOnTop)
 673.208 +ON_COMMAND(ID_OPTIONS_EMULATOR_PAUSEWHENINACTIVE, OnOptionsEmulatorPausewheninactive)
 673.209 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_PAUSEWHENINACTIVE, OnUpdateOptionsEmulatorPausewheninactive)
 673.210 +ON_COMMAND(ID_OPTIONS_EMULATOR_BACKGROUNDINPUT, OnOptionsEmulatorEnableBackgroundInput)
 673.211 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_BACKGROUNDINPUT, OnUpdateOptionsEmulatorEnableBackgroundInput)
 673.212 +ON_COMMAND(ID_OPTIONS_EMULATOR_SPEEDUPTOGGLE, OnOptionsEmulatorSpeeduptoggle)
 673.213 +
 673.214 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_SPEEDUPTOGGLE, OnUpdateOptionsEmulatorSpeeduptoggle)
 673.215 +ON_COMMAND(ID_OPTIONS_EMULATOR_REMOVEINTROSGBA, OnOptionsEmulatorRemoveintrosgba)
 673.216 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_REMOVEINTROSGBA, OnUpdateOptionsEmulatorRemoveintrosgba)
 673.217 +ON_COMMAND(ID_OPTIONS_EMULATOR_AUTOMATICALLYIPSPATCH, OnOptionsEmulatorAutomaticallyipspatch)
 673.218 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_AUTOMATICALLYIPSPATCH, OnUpdateOptionsEmulatorAutomaticallyipspatch)
 673.219 +ON_COMMAND(ID_OPTIONS_EMULATOR_AGBPRINT, OnOptionsEmulatorAgbprint)
 673.220 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_AGBPRINT, OnUpdateOptionsEmulatorAgbprint)
 673.221 +ON_COMMAND(ID_OPTIONS_EMULATOR_REALTIMECLOCK, OnOptionsEmulatorRealtimeclock)
 673.222 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_REALTIMECLOCK, OnUpdateOptionsEmulatorRealtimeclock)
 673.223 +ON_COMMAND(ID_OPTIONS_EMULATOR_AUTOHIDEMENU, OnOptionsEmulatorAutohidemenu)
 673.224 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_AUTOHIDEMENU, OnUpdateOptionsEmulatorAutohidemenu)
 673.225 +ON_COMMAND(ID_OPTIONS_EMULATOR_REWINDINTERVAL, OnOptionsEmulatorRewindinterval)
 673.226 +ON_COMMAND(ID_OPTIONS_EMULATOR_SAVETYPE_AUTOMATIC, OnOptionsEmulatorSavetypeAutomatic)
 673.227 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_SAVETYPE_AUTOMATIC, OnUpdateOptionsEmulatorSavetypeAutomatic)
 673.228 +ON_COMMAND(ID_OPTIONS_EMULATOR_SAVETYPE_EEPROM, OnOptionsEmulatorSavetypeEeprom)
 673.229 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_SAVETYPE_EEPROM, OnUpdateOptionsEmulatorSavetypeEeprom)
 673.230 +ON_COMMAND(ID_OPTIONS_EMULATOR_SAVETYPE_SRAM, OnOptionsEmulatorSavetypeSram)
 673.231 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_SAVETYPE_SRAM, OnUpdateOptionsEmulatorSavetypeSram)
 673.232 +ON_COMMAND(ID_OPTIONS_EMULATOR_SAVETYPE_FLASH, OnOptionsEmulatorSavetypeFlash)
 673.233 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_SAVETYPE_FLASH, OnUpdateOptionsEmulatorSavetypeFlash)
 673.234 +ON_COMMAND(ID_OPTIONS_EMULATOR_SAVETYPE_EEPROMSENSOR, OnOptionsEmulatorSavetypeEepromsensor)
 673.235 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_SAVETYPE_EEPROMSENSOR, OnUpdateOptionsEmulatorSavetypeEepromsensor)
 673.236 +ON_COMMAND(ID_OPTIONS_EMULATOR_SAVETYPE_NONE, OnOptionsEmulatorSavetypeNone)
 673.237 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_SAVETYPE_NONE, OnUpdateOptionsEmulatorSavetypeNone)
 673.238 +ON_COMMAND(ID_OPTIONS_EMULATOR_SAVETYPE_FLASH512K, OnOptionsEmulatorSavetypeFlash512k)
 673.239 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_SAVETYPE_FLASH512K, OnUpdateOptionsEmulatorSavetypeFlash512k)
 673.240 +ON_COMMAND(ID_OPTIONS_EMULATOR_SAVETYPE_FLASH1M, OnOptionsEmulatorSavetypeFlash1m)
 673.241 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_SAVETYPE_FLASH1M, OnUpdateOptionsEmulatorSavetypeFlash1m)
 673.242 +ON_COMMAND(ID_OPTIONS_EMULATOR_USEBIOSFILE, OnOptionsEmulatorUsebiosfile)
 673.243 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_USEBIOSFILE, OnUpdateOptionsEmulatorUsebiosfile)
 673.244 +ON_COMMAND(ID_OPTIONS_EMULATOR_SKIPBIOS, OnOptionsEmulatorSkipbios)
 673.245 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_SKIPBIOS, OnUpdateOptionsEmulatorSkipbios)
 673.246 +ON_COMMAND(ID_OPTIONS_EMULATOR_SELECTBIOSFILE, OnOptionsEmulatorSelectbiosfile)
 673.247 +
 673.248 +ON_COMMAND(ID_EMULATOR_USE_OLD_FRAME_TIMING, OnOptionsEmulatorUseOldGBTiming)
 673.249 +ON_UPDATE_COMMAND_UI(ID_EMULATOR_USE_OLD_FRAME_TIMING, OnUpdateOptionsEmulatorUseOldGBTiming)
 673.250 +ON_COMMAND(ID_EMULATOR_USE_GB_INPUT_KLUDGE, OnOptionsEmulatorUseGBNullInputKludge)
 673.251 +ON_UPDATE_COMMAND_UI(ID_EMULATOR_USE_GB_INPUT_KLUDGE, OnUpdateOptionsEmulatorUseGBNullInputKludge)
 673.252 +ON_COMMAND(ID_EMULATOR_GBALAG, OnOptionsEmulatorGBALag)
 673.253 +ON_UPDATE_COMMAND_UI(ID_EMULATOR_GBALAG, OnUpdateOptionsEmulatorGBALag)
 673.254 +
 673.255 +ON_COMMAND(ID_OPTIONS_EMULATOR_PNGFORMAT, OnOptionsEmulatorPngformat)
 673.256 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_PNGFORMAT, OnUpdateOptionsEmulatorPngformat)
 673.257 +ON_COMMAND(ID_OPTIONS_EMULATOR_BMPFORMAT, OnOptionsEmulatorBmpformat)
 673.258 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_BMPFORMAT, OnUpdateOptionsEmulatorBmpformat)
 673.259 +ON_COMMAND(ID_OPTIONS_SOUND_DISABLE, OnOptionsSoundDisable)
 673.260 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_DISABLE, OnUpdateOptionsSoundDisable)
 673.261 +ON_COMMAND(ID_OPTIONS_SOUND_MUTE, OnOptionsSoundMute)
 673.262 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_MUTE, OnUpdateOptionsSoundMute)
 673.263 +ON_COMMAND(ID_OPTIONS_SOUND_OFF, OnOptionsSoundOff)
 673.264 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_OFF, OnUpdateOptionsSoundOff)
 673.265 +ON_COMMAND(ID_OPTIONS_SOUND_ON, OnOptionsSoundOn)
 673.266 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_ON, OnUpdateOptionsSoundOn)
 673.267 +ON_COMMAND(ID_OPTIONS_SOUND_USEOLDSYNCHRONIZATION, OnOptionsSoundUseoldsynchronization)
 673.268 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_USEOLDSYNCHRONIZATION, OnUpdateOptionsSoundUseoldsynchronization)
 673.269 +ON_COMMAND(ID_OPTIONS_SOUND_ECHO, OnOptionsSoundEcho)
 673.270 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_ECHO, OnUpdateOptionsSoundEcho)
 673.271 +ON_COMMAND(ID_OPTIONS_SOUND_LOWPASSFILTER, OnOptionsSoundLowpassfilter)
 673.272 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_LOWPASSFILTER, OnUpdateOptionsSoundLowpassfilter)
 673.273 +ON_COMMAND(ID_OPTIONS_SOUND_REVERSESTEREO, OnOptionsSoundReversestereo)
 673.274 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_REVERSESTEREO, OnUpdateOptionsSoundReversestereo)
 673.275 +ON_COMMAND(ID_OPTIONS_SOUND_MUTEFRAMEADVANCE, OnOptionsSoundMuteFrameAdvance)
 673.276 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_MUTEFRAMEADVANCE, OnUpdateOptionsSoundMuteFrameAdvance)
 673.277 +ON_COMMAND(ID_OPTIONS_SOUND_MUTEWHENINACTIVE, OnOptionsSoundMuteWhenInactive)
 673.278 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_MUTEWHENINACTIVE, OnUpdateOptionsSoundMuteWhenInactive)
 673.279 +ON_COMMAND(ID_OPTIONS_SOUND_11KHZ, OnOptionsSound11khz)
 673.280 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_11KHZ, OnUpdateOptionsSound11khz)
 673.281 +ON_COMMAND(ID_OPTIONS_SOUND_22KHZ, OnOptionsSound22khz)
 673.282 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_22KHZ, OnUpdateOptionsSound22khz)
 673.283 +ON_COMMAND(ID_OPTIONS_SOUND_44KHZ, OnOptionsSound44khz)
 673.284 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_44KHZ, OnUpdateOptionsSound44khz)
 673.285 +ON_COMMAND(ID_OPTIONS_SOUND_CHANNEL1, OnOptionsSoundChannel1)
 673.286 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_CHANNEL1, OnUpdateOptionsSoundChannel1)
 673.287 +ON_COMMAND(ID_OPTIONS_SOUND_CHANNEL2, OnOptionsSoundChannel2)
 673.288 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_CHANNEL2, OnUpdateOptionsSoundChannel2)
 673.289 +ON_COMMAND(ID_OPTIONS_SOUND_CHANNEL3, OnOptionsSoundChannel3)
 673.290 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_CHANNEL3, OnUpdateOptionsSoundChannel3)
 673.291 +ON_COMMAND(ID_OPTIONS_SOUND_CHANNEL4, OnOptionsSoundChannel4)
 673.292 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_CHANNEL4, OnUpdateOptionsSoundChannel4)
 673.293 +ON_COMMAND(ID_OPTIONS_SOUND_DIRECTSOUNDA, OnOptionsSoundDirectsounda)
 673.294 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_DIRECTSOUNDA, OnUpdateOptionsSoundDirectsounda)
 673.295 +ON_COMMAND(ID_OPTIONS_SOUND_DIRECTSOUNDB, OnOptionsSoundDirectsoundb)
 673.296 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_DIRECTSOUNDB, OnUpdateOptionsSoundDirectsoundb)
 673.297 +ON_COMMAND(ID_OPTIONS_GAMEBOY_BORDER, OnOptionsGameboyBorder)
 673.298 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_GAMEBOY_BORDER, OnUpdateOptionsGameboyBorder)
 673.299 +ON_COMMAND(ID_OPTIONS_GAMEBOY_PRINTER, OnOptionsGameboyPrinter)
 673.300 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_GAMEBOY_PRINTER, OnUpdateOptionsGameboyPrinter)
 673.301 +ON_COMMAND(ID_OPTIONS_GAMEBOY_BORDERAUTOMATIC, OnOptionsGameboyBorderAutomatic)
 673.302 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_GAMEBOY_BORDERAUTOMATIC, OnUpdateOptionsGameboyBorderAutomatic)
 673.303 +ON_COMMAND(ID_OPTIONS_GAMEBOY_AUTOMATIC, OnOptionsGameboyAutomatic)
 673.304 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_GAMEBOY_AUTOMATIC, OnUpdateOptionsGameboyAutomatic)
 673.305 +ON_COMMAND(ID_OPTIONS_GAMEBOY_GBA, OnOptionsGameboyGba)
 673.306 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_GAMEBOY_GBA, OnUpdateOptionsGameboyGba)
 673.307 +ON_COMMAND(ID_OPTIONS_GAMEBOY_CGB, OnOptionsGameboyCgb)
 673.308 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_GAMEBOY_CGB, OnUpdateOptionsGameboyCgb)
 673.309 +ON_COMMAND(ID_OPTIONS_GAMEBOY_SGB, OnOptionsGameboySgb)
 673.310 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_GAMEBOY_SGB, OnUpdateOptionsGameboySgb)
 673.311 +ON_COMMAND(ID_OPTIONS_GAMEBOY_SGB2, OnOptionsGameboySgb2)
 673.312 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_GAMEBOY_SGB2, OnUpdateOptionsGameboySgb2)
 673.313 +ON_COMMAND(ID_OPTIONS_GAMEBOY_GB, OnOptionsGameboyGb)
 673.314 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_GAMEBOY_GB, OnUpdateOptionsGameboyGb)
 673.315 +ON_COMMAND(ID_OPTIONS_GAMEBOY_REALCOLORS, OnOptionsGameboyRealcolors)
 673.316 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_GAMEBOY_REALCOLORS, OnUpdateOptionsGameboyRealcolors)
 673.317 +ON_COMMAND(ID_OPTIONS_GAMEBOY_GAMEBOYCOLORS, OnOptionsGameboyGameboycolors)
 673.318 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_GAMEBOY_GAMEBOYCOLORS, OnUpdateOptionsGameboyGameboycolors)
 673.319 +ON_COMMAND(ID_OPTIONS_GAMEBOY_COLORS, OnOptionsGameboyColors)
 673.320 +ON_COMMAND(ID_OPTIONS_FILTER_DISABLEMMX, OnOptionsFilterDisablemmx)
 673.321 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_FILTER_DISABLEMMX, OnUpdateOptionsFilterDisablemmx)
 673.322 +ON_COMMAND(ID_OPTIONS_LANGUAGE_SYSTEM, OnOptionsLanguageSystem)
 673.323 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_LANGUAGE_SYSTEM, OnUpdateOptionsLanguageSystem)
 673.324 +ON_COMMAND(ID_OPTIONS_LANGUAGE_ENGLISH, OnOptionsLanguageEnglish)
 673.325 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_LANGUAGE_ENGLISH, OnUpdateOptionsLanguageEnglish)
 673.326 +ON_COMMAND(ID_OPTIONS_LANGUAGE_OTHER, OnOptionsLanguageOther)
 673.327 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_LANGUAGE_OTHER, OnUpdateOptionsLanguageOther)
 673.328 +ON_COMMAND(ID_OPTIONS_JOYPAD_CONFIGURE_1, OnOptionsJoypadConfigure1)
 673.329 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_JOYPAD_CONFIGURE_1, OnUpdateOptionsJoypadConfigure1)
 673.330 +ON_COMMAND(ID_OPTIONS_JOYPAD_CONFIGURE_2, OnOptionsJoypadConfigure2)
 673.331 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_JOYPAD_CONFIGURE_2, OnUpdateOptionsJoypadConfigure2)
 673.332 +ON_COMMAND(ID_OPTIONS_JOYPAD_CONFIGURE_3, OnOptionsJoypadConfigure3)
 673.333 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_JOYPAD_CONFIGURE_3, OnUpdateOptionsJoypadConfigure3)
 673.334 +ON_COMMAND(ID_OPTIONS_JOYPAD_CONFIGURE_4, OnOptionsJoypadConfigure4)
 673.335 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_JOYPAD_CONFIGURE_4, OnUpdateOptionsJoypadConfigure4)
 673.336 +ON_COMMAND(ID_OPTIONS_JOYPAD_MOTIONCONFIGURE, OnOptionsJoypadMotionconfigure)
 673.337 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_JOYPAD_MOTIONCONFIGURE, OnUpdateOptionsJoypadMotionconfigure)
 673.338 +ON_COMMAND(ID_OPTIONS_JOYPAD_ALLOWLEFTRIGHT, OnOptionsJoypadAllowLeftRight)
 673.339 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_JOYPAD_ALLOWLEFTRIGHT, OnUpdateOptionsJoypadAllowLeftRight)
 673.340 +ON_COMMAND(ID_OPTIONS_JOYPAD_AUTOFIRE_ACCOUNTFORLAG, OnOptionsJoypadAutofireAccountForLag)
 673.341 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_JOYPAD_AUTOFIRE_ACCOUNTFORLAG, OnUpdateOptionsJoypadAutofireAccountForLag)
 673.342 +ON_COMMAND(ID_CHEATS_SEARCHFORCHEATS, OnCheatsSearchforcheats)
 673.343 +ON_UPDATE_COMMAND_UI(ID_CHEATS_SEARCHFORCHEATS, OnUpdateCheatsSearchforcheats)
 673.344 +ON_COMMAND(ID_CHEATS_CHEATLIST, OnCheatsCheatlist)
 673.345 +ON_UPDATE_COMMAND_UI(ID_CHEATS_CHEATLIST, OnUpdateCheatsCheatlist)
 673.346 +ON_COMMAND(ID_CHEATS_AUTOMATICSAVELOADCHEATS, OnCheatsAutomaticsaveloadcheats)
 673.347 +ON_COMMAND(ID_CHEATS_PAUSEDURINGCHEATSEARCH, OnCheatsPauseDuringCheatSearch)
 673.348 +ON_COMMAND(ID_CHEATS_LOADCHEATLIST, OnCheatsLoadcheatlist)
 673.349 +ON_UPDATE_COMMAND_UI(ID_CHEATS_LOADCHEATLIST, OnUpdateCheatsLoadcheatlist)
 673.350 +ON_COMMAND(ID_CHEATS_SAVECHEATLIST, OnCheatsSavecheatlist)
 673.351 +ON_UPDATE_COMMAND_UI(ID_CHEATS_SAVECHEATLIST, OnUpdateCheatsSavecheatlist)
 673.352 +ON_COMMAND(ID_TOOLS_DISASSEMBLE, OnToolsDisassemble)
 673.353 +ON_UPDATE_COMMAND_UI(ID_TOOLS_DISASSEMBLE, OnUpdateToolsDisassemble)
 673.354 +ON_COMMAND(ID_TOOLS_LOGGING, OnToolsLogging)
 673.355 +ON_UPDATE_COMMAND_UI(ID_TOOLS_LOGGING, OnUpdateToolsLogging)
 673.356 +ON_COMMAND(ID_TOOLS_IOVIEWER, OnToolsIoviewer)
 673.357 +ON_UPDATE_COMMAND_UI(ID_TOOLS_IOVIEWER, OnUpdateToolsIoviewer)
 673.358 +ON_COMMAND(ID_TOOLS_MAPVIEW, OnToolsMapview)
 673.359 +ON_UPDATE_COMMAND_UI(ID_TOOLS_MAPVIEW, OnUpdateToolsMapview)
 673.360 +ON_COMMAND(ID_TOOLS_MEMORYVIEWER, OnToolsMemoryviewer)
 673.361 +ON_UPDATE_COMMAND_UI(ID_TOOLS_MEMORYVIEWER, OnUpdateToolsMemoryviewer)
 673.362 +ON_COMMAND(ID_TOOLS_OAMVIEWER, OnToolsOamviewer)
 673.363 +ON_UPDATE_COMMAND_UI(ID_TOOLS_OAMVIEWER, OnUpdateToolsOamviewer)
 673.364 +ON_COMMAND(ID_TOOLS_PALETTEVIEW, OnToolsPaletteview)
 673.365 +ON_UPDATE_COMMAND_UI(ID_TOOLS_PALETTEVIEW, OnUpdateToolsPaletteview)
 673.366 +ON_COMMAND(ID_TOOLS_TILEVIEWER, OnToolsTileviewer)
 673.367 +ON_UPDATE_COMMAND_UI(ID_TOOLS_TILEVIEWER, OnUpdateToolsTileviewer)
 673.368 +
 673.369 +ON_COMMAND(ID_DEBUG_NEXTFRAME, OnDebugNextframe)
 673.370 +ON_UPDATE_COMMAND_UI(ID_DEBUG_NEXTFRAME, OnUpdateDebugNextframe)
 673.371 +ON_COMMAND(ID_DEBUG_NEXTFRAME_ACCOUNTFORLAG, OnDebugNextframeAccountForLag)
 673.372 +ON_UPDATE_COMMAND_UI(ID_DEBUG_NEXTFRAME_ACCOUNTFORLAG, OnUpdateDebugNextframeAccountForLag)
 673.373 +ON_COMMAND(ID_DEBUG_FRAMESEARCH, OnDebugFramesearch)
 673.374 +ON_UPDATE_COMMAND_UI(ID_DEBUG_FRAMESEARCH, OnUpdateDebugFramesearch)
 673.375 +ON_COMMAND(ID_DEBUG_FRAMESEARCHPREV, OnDebugFramesearchPrev)
 673.376 +ON_UPDATE_COMMAND_UI(ID_DEBUG_FRAMESEARCHPREV, OnUpdateDebugFramesearchPrev)
 673.377 +ON_COMMAND(ID_DEBUG_FRAMESEARCHLOAD, OnDebugFramesearchLoad)
 673.378 +ON_UPDATE_COMMAND_UI(ID_DEBUG_FRAMESEARCHLOAD, OnUpdateDebugFramesearchLoad)
 673.379 +ON_UPDATE_COMMAND_UI(ID_CHEATS_AUTOMATICSAVELOADCHEATS, OnUpdateCheatsAutomaticsaveloadcheats)
 673.380 +ON_UPDATE_COMMAND_UI(ID_CHEATS_PAUSEDURINGCHEATSEARCH, OnUpdateCheatsPauseDuringCheatSearch)
 673.381 +ON_COMMAND(ID_TOOLS_FRAMECOUNTER, OnToolsFrameCounter)
 673.382 +ON_UPDATE_COMMAND_UI(ID_TOOLS_FRAMECOUNTER, OnUpdateToolsFrameCounter)
 673.383 +ON_COMMAND(ID_TOOLS_LAGCOUNTER, OnToolsLagCounter)
 673.384 +ON_UPDATE_COMMAND_UI(ID_TOOLS_LAGCOUNTER, OnUpdateToolsLagCounter)
 673.385 +ON_COMMAND(ID_TOOLS_EXTRACOUNTER, OnToolsExtraCounter)
 673.386 +ON_UPDATE_COMMAND_UI(ID_TOOLS_EXTRACOUNTER, OnUpdateToolsExtraCounter)
 673.387 +ON_COMMAND(ID_TOOLS_EXTRACOUNTERRESET, OnToolsExtraCounterReset)
 673.388 +ON_COMMAND(ID_TOOLS_INPUTDISPLAY, OnToolsInputDisplay)
 673.389 +ON_UPDATE_COMMAND_UI(ID_TOOLS_INPUTDISPLAY, OnUpdateToolsInputDisplay)
 673.390 +ON_COMMAND(ID_TOOLS_DEBUG_GDB, OnToolsDebugGdb)
 673.391 +ON_UPDATE_COMMAND_UI(ID_TOOLS_DEBUG_GDB, OnUpdateToolsDebugGdb)
 673.392 +ON_COMMAND(ID_TOOLS_DEBUG_LOADANDWAIT, OnToolsDebugLoadandwait)
 673.393 +ON_UPDATE_COMMAND_UI(ID_TOOLS_DEBUG_LOADANDWAIT, OnUpdateToolsDebugLoadandwait)
 673.394 +ON_COMMAND(ID_TOOLS_DEBUG_BREAK, OnToolsDebugBreak)
 673.395 +ON_UPDATE_COMMAND_UI(ID_TOOLS_DEBUG_BREAK, OnUpdateToolsDebugBreak)
 673.396 +ON_COMMAND(ID_TOOLS_DEBUG_DISCONNECT, OnToolsDebugDisconnect)
 673.397 +ON_UPDATE_COMMAND_UI(ID_TOOLS_DEBUG_DISCONNECT, OnUpdateToolsDebugDisconnect)
 673.398 +
 673.399 +ON_COMMAND(ID_TOOLS_SOUNDRECORDING, OnToolsSoundRecording)
 673.400 +ON_UPDATE_COMMAND_UI(ID_TOOLS_SOUNDRECORDING, OnUpdateToolsSoundRecording)
 673.401 +ON_COMMAND(ID_TOOLS_AVIRECORDING, OnToolsAVIRecording)
 673.402 +ON_UPDATE_COMMAND_UI(ID_TOOLS_AVIRECORDING, OnUpdateToolsAVIRecording)
 673.403 +ON_COMMAND(ID_TOOLS_PAUSEAVIRECORDING, OnToolsPauseAVIRecording)
 673.404 +ON_UPDATE_COMMAND_UI(ID_TOOLS_PAUSEAVIRECORDING, OnUpdateToolsPauseAVIRecording)
 673.405 +
 673.406 +ON_COMMAND(ID_MOVIE_RECORD, OnToolsRecordMovie)
 673.407 +ON_UPDATE_COMMAND_UI(ID_MOVIE_RECORD, OnUpdateToolsRecordMovie)
 673.408 +ON_COMMAND(ID_MOVIE_STOP, OnToolsStopMovie)
 673.409 +ON_UPDATE_COMMAND_UI(ID_MOVIE_STOP, OnUpdateToolsStopMovie)
 673.410 +ON_COMMAND(ID_MOVIE_PLAY, OnToolsPlayMovie)
 673.411 +ON_UPDATE_COMMAND_UI(ID_MOVIE_PLAY, OnUpdateToolsPlayMovie)
 673.412 +ON_COMMAND(ID_MOVIE_READONLY, OnToolsPlayReadOnly)
 673.413 +ON_UPDATE_COMMAND_UI(ID_MOVIE_READONLY, OnUpdateToolsPlayReadOnly)
 673.414 +ON_COMMAND(ID_MOVIE_ASSC_WITH_SAVESTATE, OnAsscWithSaveState)
 673.415 +ON_UPDATE_COMMAND_UI(ID_MOVIE_ASSC_WITH_SAVESTATE, OnUpdateAsscWithSaveState)
 673.416 +ON_COMMAND(ID_MOVIE_RESUME_RECORD, OnToolsResumeRecord)
 673.417 +ON_UPDATE_COMMAND_UI(ID_MOVIE_RESUME_RECORD, OnUpdateToolsResumeRecord)
 673.418 +ON_COMMAND(ID_MOVIE_RESTART_PLAY, OnToolsPlayRestart)
 673.419 +ON_UPDATE_COMMAND_UI(ID_MOVIE_RESTART_PLAY, OnUpdateToolsPlayRestart)
 673.420 +
 673.421 +ON_COMMAND(ID_MOVIE_END_PAUSE, OnToolsOnMovieEndPause)
 673.422 +ON_UPDATE_COMMAND_UI(ID_MOVIE_END_PAUSE, OnUpdateToolsOnMovieEndPause)
 673.423 +ON_COMMAND(ID_MOVIE_END_STOP, OnToolsOnMovieEndStop)
 673.424 +ON_UPDATE_COMMAND_UI(ID_MOVIE_END_STOP, OnUpdateToolsOnMovieEndStop)
 673.425 +ON_COMMAND(ID_MOVIE_END_RESTART, OnToolsOnMovieEndRestart)
 673.426 +ON_UPDATE_COMMAND_UI(ID_MOVIE_END_RESTART, OnUpdateToolsOnMovieEndRestart)
 673.427 +ON_COMMAND(ID_MOVIE_END_APPEND, OnToolsOnMovieEndAppend)
 673.428 +ON_UPDATE_COMMAND_UI(ID_MOVIE_END_APPEND, OnUpdateToolsOnMovieEndAppend)
 673.429 +ON_COMMAND(ID_MOVIE_END_KEEP, OnToolsOnMovieEndKeep)
 673.430 +ON_UPDATE_COMMAND_UI(ID_MOVIE_END_KEEP, OnUpdateToolsOnMovieEndKeep)
 673.431 +
 673.432 +ON_COMMAND(ID_MOVIE_TOOL_SET_PAUSE_AT, OnToolsMovieSetPauseAt)
 673.433 +ON_UPDATE_COMMAND_UI(ID_MOVIE_TOOL_SET_PAUSE_AT, OnUpdateToolsSetMoviePauseAt)
 673.434 +ON_COMMAND(ID_MOVIE_TOOL_CONVERT, OnToolsMovieConvertCurrent)
 673.435 +ON_UPDATE_COMMAND_UI(ID_MOVIE_TOOL_CONVERT, OnUpdateToolsMovieConvertCurrent)
 673.436 +ON_COMMAND(ID_MOVIE_TOOL_AUTO_CONVERT, OnToolsMovieAutoConvert)
 673.437 +ON_UPDATE_COMMAND_UI(ID_MOVIE_TOOL_AUTO_CONVERT, OnUpdateToolsMovieAutoConvert)
 673.438 +ON_COMMAND(ID_MOVIE_TOOL_FIX_HEADER, OnToolsMovieFixHeader)
 673.439 +ON_UPDATE_COMMAND_UI(ID_MOVIE_TOOL_FIX_HEADER, OnUpdateToolsMovieFixHeader)
 673.440 +ON_COMMAND(ID_MOVIE_TOOL_TRUNCATE, OnToolsMovieTruncateAtCurrent)
 673.441 +ON_UPDATE_COMMAND_UI(ID_MOVIE_TOOL_TRUNCATE, OnUpdateToolsMovieTruncateAtCurrent)
 673.442 +ON_COMMAND(ID_MOVIE_TOOL_EXTRACT_FROM_SAVEGAME, OnToolsMovieExtractFromSavegame)
 673.443 +ON_UPDATE_COMMAND_UI(ID_MOVIE_TOOL_EXTRACT_FROM_SAVEGAME, OnUpdateToolsMovieExtractFromSavegame)
 673.444 +
 673.445 +ON_COMMAND(ID_TOOLS_REWIND, OnToolsRewind)
 673.446 +ON_UPDATE_COMMAND_UI(ID_TOOLS_REWIND, OnUpdateToolsRewind)
 673.447 +ON_COMMAND(ID_TOOLS_CUSTOMIZE, OnToolsCustomize)
 673.448 +ON_UPDATE_COMMAND_UI(ID_TOOLS_CUSTOMIZE, OnUpdateToolsCustomize)
 673.449 +// ON_COMMAND(ID_TOOLS_CUSTOMIZE_COMMON, OnToolsCustomizeCommon)
 673.450 +// ON_UPDATE_COMMAND_UI(ID_TOOLS_CUSTOMIZE_COMMON, OnUpdateToolsCustomizeCommon)
 673.451 +ON_COMMAND(ID_HELP_BUGREPORT, OnHelpBugreport)
 673.452 +
 673.453 +ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE10, OnFileRecentFile)
 673.454 +ON_COMMAND_EX_RANGE(ID_FILE_LOADGAME_SLOT1, ID_FILE_LOADGAME_SLOT10, OnFileLoadSlot)
 673.455 +ON_COMMAND_EX_RANGE(ID_FILE_SAVEGAME_SLOT1, ID_FILE_SAVEGAME_SLOT10, OnFileSaveSlot)
 673.456 +ON_COMMAND_EX_RANGE(ID_SELECT_SLOT1, ID_SELECT_SLOT10, OnSelectSlot)
 673.457 +ON_UPDATE_COMMAND_UI_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE10, OnUpdateFileRecentFile)
 673.458 +ON_UPDATE_COMMAND_UI_RANGE(ID_FILE_LOADGAME_SLOT1, ID_FILE_LOADGAME_SLOT10, OnUpdateFileLoadSlot)
 673.459 +ON_UPDATE_COMMAND_UI_RANGE(ID_FILE_SAVEGAME_SLOT1, ID_FILE_SAVEGAME_SLOT10, OnUpdateFileSaveSlot)
 673.460 +ON_UPDATE_COMMAND_UI_RANGE(ID_SELECT_SLOT1, ID_SELECT_SLOT10, OnUpdateSelectSlot)
 673.461 +
 673.462 +ON_COMMAND(ID_FILE_SAVEGAME_OLDESTSLOT, OnFileSavegameOldestslot)
 673.463 +ON_UPDATE_COMMAND_UI(ID_FILE_SAVEGAME_OLDESTSLOT, OnUpdateFileSavegameOldestslot)
 673.464 +ON_COMMAND(ID_FILE_LOADGAME_MOSTRECENT, OnFileLoadgameMostrecent)
 673.465 +ON_UPDATE_COMMAND_UI(ID_FILE_LOADGAME_MOSTRECENT, OnUpdateFileLoadgameMostrecent)
 673.466 +ON_COMMAND(ID_FILE_SAVEGAME_CURRENT, OnFileSavegameCurrent)
 673.467 +ON_UPDATE_COMMAND_UI(ID_FILE_SAVEGAME_CURRENT, OnUpdateFileSavegameCurrent)
 673.468 +ON_COMMAND(ID_FILE_LOADGAME_CURRENT, OnFileLoadgameCurrent)
 673.469 +ON_UPDATE_COMMAND_UI(ID_FILE_LOADGAME_CURRENT, OnUpdateFileLoadgameCurrent)
 673.470 +ON_COMMAND(ID_FILE_LOADGAME_MAKECURRENT, OnFileLoadgameMakeCurrent)
 673.471 +ON_UPDATE_COMMAND_UI(ID_FILE_LOADGAME_MAKECURRENT, OnUpdateFileLoadgameMakeCurrent)
 673.472 +ON_COMMAND(ID_FILE_SAVEGAME_MAKECURRENT, OnFileSavegameMakeCurrent)
 673.473 +ON_UPDATE_COMMAND_UI(ID_FILE_SAVEGAME_MAKECURRENT, OnUpdateFileSavegameMakeCurrent)
 673.474 +
 673.475 +ON_COMMAND(ID_FILE_SAVEGAME_INCREMENTSLOT, OnFileSavegameIncrementSlot)
 673.476 +ON_UPDATE_COMMAND_UI(ID_FILE_SAVEGAME_INCREMENTSLOT, OnUpdateFileSavegameIncrementSlot)
 673.477 +ON_COMMAND(ID_FILE_SAVEGAME_DECREMENTSLOT, OnFileSavegameDecrementSlot)
 673.478 +ON_UPDATE_COMMAND_UI(ID_FILE_SAVEGAME_DECREMENTSLOT, OnUpdateFileSavegameDecrementSlot)
 673.479 +ON_COMMAND(ID_FILE_SLOT_DISPLAYMODIFICATIONTIME, OnFileSlotDisplayModificationTime)
 673.480 +ON_UPDATE_COMMAND_UI(ID_FILE_SLOT_DISPLAYMODIFICATIONTIME, OnUpdateFileSlotDisplayModificationTime)
 673.481 +
 673.482 +ON_COMMAND(ID_FILE_LOADGAME_AUTOLOADMOSTRECENT, OnFileLoadgameAutoloadmostrecent)
 673.483 +ON_UPDATE_COMMAND_UI(ID_FILE_LOADGAME_AUTOLOADMOSTRECENT, OnUpdateFileLoadgameAutoloadmostrecent)
 673.484 +ON_COMMAND(ID_FILE_LOADGAME_MAKERECENT, OnFileLoadgameMakeRecent)
 673.485 +ON_UPDATE_COMMAND_UI(ID_FILE_LOADGAME_MAKERECENT, OnUpdateFileLoadgameMakeRecent)
 673.486 +
 673.487 +ON_COMMAND(ID_OPTIONS_SOUND_VOLUME_25X, OnOptionsSoundVolume25x)
 673.488 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_VOLUME_25X, OnUpdateOptionsSoundVolume25x)
 673.489 +ON_COMMAND(ID_OPTIONS_SOUND_VOLUME_5X, OnOptionsSoundVolume5x)
 673.490 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_VOLUME_5X, OnUpdateOptionsSoundVolume5x)
 673.491 +ON_COMMAND(ID_CHEATS_DISABLECHEATS, OnCheatsDisablecheats)
 673.492 +ON_UPDATE_COMMAND_UI(ID_CHEATS_DISABLECHEATS, OnUpdateCheatsDisablecheats)
 673.493 +ON_COMMAND(ID_OPTIONS_VIDEO_FULLSCREENMAXSCALE, OnOptionsVideoFullscreenmaxscale)
 673.494 +
 673.495 +ON_COMMAND_EX_RANGE(ID_OPTIONS_VIDEO_FRAMESKIP_0, ID_OPTIONS_VIDEO_FRAMESKIP_9, OnOptionsFrameskip)
 673.496 +ON_COMMAND_EX_RANGE(ID_OPTIONS_VIDEO_X1, ID_OPTIONS_VIDEO_X4, OnOptionVideoSize)
 673.497 +ON_COMMAND_EX_RANGE(ID_OPTIONS_VIDEO_LAYERS_BG0, ID_OPTIONS_VIDEO_LAYERS_OBJWIN, OnVideoLayer)
 673.498 +ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_VIDEO_LAYERS_BG0, ID_OPTIONS_VIDEO_LAYERS_OBJWIN, OnUpdateVideoLayer)
 673.499 +ON_COMMAND(ID_SYSTEM_MINIMIZE, OnSystemMinimize)
 673.500 +ON_COMMAND(ID_SYSTEM_MAXIMIZE, OnSystemMaximize)
 673.501 +ON_COMMAND_EX_RANGE(ID_OPTIONS_EMULATOR_SHOWSPEED_NONE, ID_OPTIONS_EMULATOR_SHOWSPEED_TRANSPARENT, OnOptionsEmulatorShowSpeed)
 673.502 +ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_EMULATOR_SHOWSPEED_NONE,
 673.503 +                           ID_OPTIONS_EMULATOR_SHOWSPEED_TRANSPARENT,
 673.504 +                           OnUpdateOptionsEmulatorShowSpeed)
 673.505 +ON_COMMAND_EX_RANGE(ID_OPTIONS_SOUND_VOLUME_1X, ID_OPTIONS_SOUND_VOLUME_4X, OnOptionsSoundVolume)
 673.506 +ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_SOUND_VOLUME_1X, ID_OPTIONS_SOUND_VOLUME_4X, OnUpdateOptionsSoundVolume)
 673.507 +ON_COMMAND_EX_RANGE(ID_OPTIONS_PRIORITY_HIGHEST, ID_OPTIONS_PRIORITY_BELOWNORMAL, OnOptionsPriority)
 673.508 +ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_PRIORITY_HIGHEST, ID_OPTIONS_PRIORITY_BELOWNORMAL, OnUpdateOptionsPriority)
 673.509 +
 673.510 +ON_COMMAND_EX_RANGE(ID_OPTIONS_FILTER_NORMAL, ID_OPTIONS_FILTER_TVMODE, OnOptionsFilter)
 673.511 +ON_COMMAND_EX_RANGE(ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL, ID_OPTIONS_FILTER16BIT_MOTIONBLUREXPERIMENTAL, OnOptionsFilter)
 673.512 +ON_COMMAND_EX_RANGE(ID_OPTIONS_FILTER16BIT_ADVANCEMAMESCALE2X, ID_OPTIONS_FILTER16BIT_SIMPLE2X, OnOptionsFilter)
 673.513 +ON_COMMAND_EX_RANGE(ID_OPTIONS_FILTER_BILINEAR, ID_OPTIONS_FILTER_BILINEARPLUS, OnOptionsFilter)
 673.514 +ON_COMMAND_EX_RANGE(ID_OPTIONS_FILTER_SCANLINES, ID_OPTIONS_FILTER_SCANLINES, OnOptionsFilter)
 673.515 +ON_COMMAND_EX_RANGE(ID_OPTIONS_FILTER_LQ2X, ID_OPTIONS_FILTER_HQ3X2, OnOptionsFilter)
 673.516 +ON_COMMAND_EX_RANGE(ID_OPTIONS_FILTER16BIT_SIMPLE3X, ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL4X, OnOptionsFilter)
 673.517 +ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_FILTER_NORMAL, ID_OPTIONS_FILTER_TVMODE, OnUpdateOptionsFilter)
 673.518 +ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL, ID_OPTIONS_FILTER16BIT_MOTIONBLUREXPERIMENTAL, OnUpdateOptionsFilter)
 673.519 +ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_FILTER16BIT_ADVANCEMAMESCALE2X, ID_OPTIONS_FILTER16BIT_SIMPLE2X, OnUpdateOptionsFilter)
 673.520 +ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_FILTER_BILINEAR, ID_OPTIONS_FILTER_BILINEARPLUS, OnUpdateOptionsFilter)
 673.521 +ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_FILTER_SCANLINES, ID_OPTIONS_FILTER_SCANLINES, OnUpdateOptionsFilter)
 673.522 +ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_FILTER_LQ2X, ID_OPTIONS_FILTER_HQ3X2, OnUpdateOptionsFilter)
 673.523 +ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_FILTER16BIT_SIMPLE3X, ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL4X, OnUpdateOptionsFilter)
 673.524 +ON_COMMAND_EX_RANGE(ID_OPTIONS_FILTER_INTERFRAMEBLENDING_NONE, ID_OPTIONS_FILTER_INTERFRAMEBLENDING_SMART, OnOptionsFilterIFB)
 673.525 +ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_FILTER_INTERFRAMEBLENDING_NONE,
 673.526 +                           ID_OPTIONS_FILTER_INTERFRAMEBLENDING_SMART,
 673.527 +                           OnUpdateOptionsFilterIFB)
 673.528 +
 673.529 +ON_COMMAND_EX_RANGE(ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_1, ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_4, OnOptionsJoypadDefault)
 673.530 +ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_1, ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_4, OnUpdateOptionsJoypadDefault)
 673.531 +ON_COMMAND_EX_RANGE(ID_OPTIONS_JOYPAD_AUTOFIRE_A, ID_OPTIONS_JOYPAD_AUTOFIRE_CLEAR, OnOptionsJoypadAutofire)
 673.532 +ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_JOYPAD_AUTOFIRE_A, ID_OPTIONS_JOYPAD_AUTOFIRE_CLEAR, OnUpdateOptionsJoypadAutofire)
 673.533 +ON_COMMAND_EX_RANGE(ID_STICKY_A, ID_STICKY_CLEAR, OnOptionsJoypadSticky)
 673.534 +ON_UPDATE_COMMAND_UI_RANGE(ID_STICKY_A, ID_STICKY_CLEAR, OnUpdateOptionsJoypadSticky)
 673.535 +ON_MESSAGE(VBA_CONFIRM_MODE, OnConfirmMode)
 673.536 +ON_MESSAGE(WM_SYSCOMMAND, OnMySysCommand)
 673.537 +ON_COMMAND(ID_OPTIONS_VIDEO_TEXTDISPLAYOPTIONS, OnOptionsVideoTextdisplayoptions)
 673.538 +ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIDEO_TEXTDISPLAYOPTIONS, OnUpdateOptionsVideoTextdisplayoptions)
 673.539 +
 673.540 +ON_COMMAND(ID_FILE_LUA_OPEN, OnFileLuaOpen)
 673.541 +ON_UPDATE_COMMAND_UI(ID_FILE_LUA_OPEN, OnUpdateFileLuaOpen)
 673.542 +ON_COMMAND(ID_FILE_LUA_CLOSE_ALL, OnFileLuaCloseAll)
 673.543 +ON_UPDATE_COMMAND_UI(ID_FILE_LUA_CLOSE_ALL, OnUpdateFileLuaCloseAll)
 673.544 +ON_COMMAND(ID_FILE_LUA_RELOAD, OnFileLuaReload)
 673.545 +ON_COMMAND(ID_FILE_LUA_STOP, OnFileLuaStop)
 673.546 +ON_COMMAND(ID_RAM_SEARCH, OnFileRamSearch)
 673.547 +ON_UPDATE_COMMAND_UI(ID_RAM_SEARCH, OnUpdateFileRamSearch)
 673.548 +ON_COMMAND(ID_RAM_WATCH, OnFileRamWatch)
 673.549 +ON_UPDATE_COMMAND_UI(ID_RAM_WATCH, OnUpdateFileRamWatch)
 673.550 +//}}AFX_MSG_MAP
 673.551 +END_MESSAGE_MAP()
 673.552 +
 673.553 +/////////////////////////////////////////////////////////////////////////////
 673.554 +// MainWnd message handlers
 673.555 +
 673.556 +bool vbaShuttingDown = false;
 673.557 +
 673.558 +void MainWnd::OnClose()
 673.559 +{
 673.560 +	vbaShuttingDown = true; // HACK to fix crash on exit while memory viewer is open
 673.561 +
 673.562 +	CWnd::OnClose();
 673.563 +
 673.564 +	delete this;
 673.565 +}
 673.566 +
 673.567 +void MainWnd::OnMove(int x, int y)
 673.568 +{
 673.569 +	CWnd::OnMove(x, y);
 673.570 +
 673.571 +	if (!theApp.changingVideoSize)
 673.572 +	{
 673.573 +		if (this)
 673.574 +		{
 673.575 +			if (!IsIconic() && !IsZoomed())
 673.576 +			{
 673.577 +				RECT r;
 673.578 +
 673.579 +				GetWindowRect(&r);
 673.580 +				theApp.windowPositionX = r.left;
 673.581 +				theApp.windowPositionY = r.top;
 673.582 +				theApp.adjustDestRect();
 673.583 +				regSetDwordValue("windowX", theApp.windowPositionX);
 673.584 +				regSetDwordValue("windowY", theApp.windowPositionY);
 673.585 +			}
 673.586 +		}
 673.587 +	}
 673.588 +}
 673.589 +
 673.590 +void MainWnd::OnSize(UINT nType, int cx, int cy)
 673.591 +{
 673.592 +	CWnd::OnSize(nType, cx, cy);
 673.593 +
 673.594 +	static int lastType = -1;
 673.595 +
 673.596 +	// FIXME: hack to re-maximize window after it auto-unmaximizes while loading a ROM
 673.597 +	if (nType == SIZE_MAXIMIZED && lastType == SIZE_MAXIMIZED)
 673.598 +	{
 673.599 +		lastType = -1;
 673.600 +		ShowWindow(SW_SHOWMAXIMIZED);
 673.601 +		MoveWindow(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
 673.602 +		return;
 673.603 +	}
 673.604 +
 673.605 +	lastType = nType;
 673.606 +
 673.607 +	if (IsIconic())
 673.608 +	{
 673.609 +		theApp.iconic = true;
 673.610 +		return;
 673.611 +	}
 673.612 +	else if (theApp.iconic)
 673.613 +	{
 673.614 +		theApp.iconic = false;
 673.615 +	}
 673.616 +
 673.617 +	if (!theApp.changingVideoSize)
 673.618 +	{
 673.619 +		if (this)
 673.620 +		{
 673.621 +			if (theApp.videoOption <= VIDEO_4X)
 673.622 +			{
 673.623 +				theApp.surfaceSizeX = cx;
 673.624 +				theApp.surfaceSizeY = cy;
 673.625 +				theApp.adjustDestRect();
 673.626 +				if (theApp.display)
 673.627 +					theApp.display->resize(theApp.dest.right - theApp.dest.left, theApp.dest.bottom - theApp.dest.top);
 673.628 +				systemRefreshScreen();  // useful when shrinking
 673.629 +			}
 673.630 +		}
 673.631 +	}
 673.632 +}
 673.633 +
 673.634 +void MainWnd::OnContextMenu(CWnd *pWnd, CPoint point)
 673.635 +{
 673.636 +	winMouseOn();
 673.637 +}
 673.638 +
 673.639 +void MainWnd::OnSystemMinimize()
 673.640 +{
 673.641 +	ShowWindow(SW_SHOWMINIMIZED);
 673.642 +}
 673.643 +
 673.644 +void MainWnd::OnSystemMaximize()
 673.645 +{
 673.646 +	ShowWindow(SW_SHOWMAXIMIZED);
 673.647 +}
 673.648 +
 673.649 +void MainWnd::OnPaint()
 673.650 +{
 673.651 +	CPaintDC dc(this); // device context for painting, calling BeginPaint/EndPaint internally
 673.652 +	if (emulating && (!theApp.active || theApp.paused))
 673.653 +	{
 673.654 +		systemRedrawScreen();
 673.655 +	}
 673.656 +}
 673.657 +
 673.658 +static bool translatingAccelerator = false;
 673.659 +
 673.660 +// FIXME: this fix for accel keys is ugly
 673.661 +//   using too many static variables for a single accel key kludge
 673.662 +static bool	  recursiveCall	  = true;
 673.663 +static bool	  fullUpdated	  = false;
 673.664 +static bool	  lastKeyModifier = false;  // maybe better check current key press status instead
 673.665 +static WPARAM lastKey		  = 0;
 673.666 +
 673.667 +BOOL MainWnd::PreTranslateMessage(MSG *pMsg)
 673.668 +{
 673.669 +	if (RamSearchHWnd && ::IsDialogMessage(RamSearchHWnd, pMsg))
 673.670 +	{
 673.671 +		return TRUE;
 673.672 +	}
 673.673 +	else if (RamWatchHWnd && ::IsDialogMessage(RamWatchHWnd, pMsg))
 673.674 +	{
 673.675 +		if (RamWatchAccels)
 673.676 +			TranslateAccelerator(RamWatchHWnd, RamWatchAccels, pMsg);
 673.677 +		return TRUE;
 673.678 +	}
 673.679 +	else if (LuaConsoleHWnd && ::IsDialogMessage(LuaConsoleHWnd, pMsg))
 673.680 +	{
 673.681 +		return TRUE;
 673.682 +	}
 673.683 +	else if (CWnd::PreTranslateMessage(pMsg))
 673.684 +	{
 673.685 +		return TRUE;
 673.686 +	}
 673.687 +	else if (pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN)
 673.688 +	{
 673.689 +		translatingAccelerator = true;
 673.690 +
 673.691 +		bool bHit		= theApp.hAccel != NULL &&  ::TranslateAccelerator(m_hWnd, theApp.hAccel, pMsg);
 673.692 +		bool isModifier = pMsg->wParam == VK_SHIFT || pMsg->wParam == VK_CONTROL || pMsg->wParam == VK_MENU;
 673.693 +
 673.694 +		// HACK to get around the fact that TranslateAccelerator can't handle modifier-only accelerators
 673.695 +		// (it would be better to fix TranslateAccelerator, but its code is in a Microsoft library...)
 673.696 +		if (!bHit)
 673.697 +		{
 673.698 +			if (isModifier)
 673.699 +			{
 673.700 +				// do a linear loop through all accelerators to find modifier-only ones...
 673.701 +				CCmdAccelOb *pCmdAccel;
 673.702 +				WORD		 wKey;
 673.703 +				CAccelsOb *	 pAccelOb;
 673.704 +				POSITION	 pos	   = theApp.winAccelMgr.m_mapAccelTable.GetStartPosition();
 673.705 +				const int	 modifiers = ((pMsg->wParam == VK_SHIFT) ? FSHIFT : ((pMsg->wParam == VK_CONTROL) ? FCONTROL : FALT));
 673.706 +				while (pos != NULL)
 673.707 +				{
 673.708 +					theApp.winAccelMgr.m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
 673.709 +					POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
 673.710 +					while (pos != NULL)
 673.711 +					{
 673.712 +						pAccelOb = pCmdAccel->m_Accels.GetNext(pos);
 673.713 +
 673.714 +						if (pAccelOb->m_wKey == 0) // if accelerator-only
 673.715 +						{
 673.716 +							if ((pAccelOb->m_cVirt & modifiers) == modifiers) // if modifier matches
 673.717 +							{
 673.718 +								bHit = true;
 673.719 +								SendMessage(WM_COMMAND, pCmdAccel->m_wIDCommand, 0); // tell Windows to call the right function
 673.720 +							}
 673.721 +						}
 673.722 +					}
 673.723 +				}
 673.724 +			}
 673.725 +
 673.726 +			if (!bHit)
 673.727 +			{
 673.728 +				lastKeyModifier = true;
 673.729 +			}
 673.730 +		}
 673.731 +
 673.732 +		if (bHit)
 673.733 +		{
 673.734 +			if (lastKeyModifier && !isModifier)
 673.735 +			{
 673.736 +				fullUpdated		= false;
 673.737 +				lastKeyModifier = false;
 673.738 +			}
 673.739 +
 673.740 +			if (lastKey != pMsg->wParam)
 673.741 +			{
 673.742 +				fullUpdated = false;
 673.743 +				lastKey		= pMsg->wParam;
 673.744 +			}
 673.745 +		}
 673.746 +
 673.747 +		translatingAccelerator = false;
 673.748 +		return bHit ? TRUE : FALSE;
 673.749 +	}
 673.750 +
 673.751 +	return FALSE;
 673.752 +}
 673.753 +
 673.754 +void MainWnd::OnMouseMove(UINT nFlags, CPoint point)
 673.755 +{
 673.756 +	winMouseOn();
 673.757 +
 673.758 +	CWnd::OnMouseMove(nFlags, point);
 673.759 +}
 673.760 +
 673.761 +// recursive kludge
 673.762 +static void InitMenuKludge(CMenu *pParentMenu, CMenu *pMenu, CCmdTarget *pWnd)
 673.763 +{
 673.764 +	ASSERT(pMenu != NULL);
 673.765 +
 673.766 +	CCmdUI state;
 673.767 +	state.m_pParentMenu = pParentMenu;
 673.768 +	state.m_pMenu		= pMenu;
 673.769 +	ASSERT(state.m_pOther == NULL);
 673.770 +
 673.771 +	state.m_nIndexMax = pMenu->GetMenuItemCount();
 673.772 +	for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
 673.773 +	     state.m_nIndex++)
 673.774 +	{
 673.775 +		state.m_nID = pMenu->GetMenuItemID(state.m_nIndex);
 673.776 +		if (state.m_nID == 0)
 673.777 +			continue;  // menu separator or invalid cmd - ignore it
 673.778 +
 673.779 +		ASSERT(state.m_pOther == NULL);
 673.780 +		ASSERT(state.m_pMenu != NULL);
 673.781 +		if (state.m_nID == (UINT)-1)
 673.782 +		{
 673.783 +			// possibly a popup menu, route to first item of that popup
 673.784 +			state.m_pSubMenu = pMenu->GetSubMenu(state.m_nIndex);
 673.785 +			if (state.m_pSubMenu == NULL)
 673.786 +			{
 673.787 +				continue; // first item of popup can't be routed to
 673.788 +			}
 673.789 +
 673.790 +			state.DoUpdate(pWnd, false);
 673.791 +			if (recursiveCall)
 673.792 +			{
 673.793 +				// FIXME: slow recursive calls to fix enabling/disabling of accel keys
 673.794 +				InitMenuKludge(state.m_pMenu, state.m_pSubMenu, pWnd);
 673.795 +			}
 673.796 +		}
 673.797 +		else
 673.798 +		{
 673.799 +			// normal menu item
 673.800 +			// Auto enable/disable if frame window has 'm_bAutoMenuEnable'
 673.801 +			//    set and command is _not_ a system command.
 673.802 +			state.m_pSubMenu = NULL;
 673.803 +			state.DoUpdate(pWnd, state.m_nID < 0xF000);
 673.804 +		}
 673.805 +
 673.806 +		// adjust for menu deletions and additions
 673.807 +		UINT nCount = pMenu->GetMenuItemCount();
 673.808 +		if (nCount < state.m_nIndexMax)
 673.809 +		{
 673.810 +			state.m_nIndex -= (state.m_nIndexMax - nCount);
 673.811 +			while (state.m_nIndex < nCount &&
 673.812 +			       pMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
 673.813 +			{
 673.814 +				state.m_nIndex++;
 673.815 +			}
 673.816 +		}
 673.817 +		state.m_nIndexMax = nCount;
 673.818 +	}
 673.819 +}
 673.820 +
 673.821 +void MainWnd::OnInitMenuPopup(CMenu *pMenu, UINT nIndex, BOOL bSysMenu)
 673.822 +{
 673.823 +	ASSERT(pMenu != NULL);
 673.824 +
 673.825 +	CCmdUI state;
 673.826 +	state.m_pMenu = pMenu;
 673.827 +	ASSERT(state.m_pOther == NULL);
 673.828 +	ASSERT(state.m_pParentMenu == NULL);
 673.829 +
 673.830 +	// determine if menu is popup in top-level menu and set m_pOther to
 673.831 +	//  it if so (m_pParentMenu == NULL indicates that it is secondary popup)
 673.832 +	HMENU hParentMenu;
 673.833 +	if (AfxGetThreadState()->m_hTrackingMenu == pMenu->m_hMenu)
 673.834 +		state.m_pParentMenu = pMenu;  // parent == child for tracking popup
 673.835 +	else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
 673.836 +	{
 673.837 +		CWnd *pParent = GetTopLevelParent();
 673.838 +		// children windows don't have menus -- need to go to the top!
 673.839 +		if (pParent != NULL &&
 673.840 +		    (hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
 673.841 +		{
 673.842 +			int nIndexMax = ::GetMenuItemCount(hParentMenu);
 673.843 +			for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
 673.844 +			{
 673.845 +				if (::GetSubMenu(hParentMenu, nIndex) == pMenu->m_hMenu)
 673.846 +				{
 673.847 +					// when popup is found, m_pParentMenu is containing menu
 673.848 +					state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
 673.849 +					break;
 673.850 +				}
 673.851 +			}
 673.852 +		}
 673.853 +	}
 673.854 +
 673.855 +	// FIXME: magic to workaround the accel key bug without slowing down too much
 673.856 +	if (translatingAccelerator && !fullUpdated && state.m_pParentMenu == &theApp.m_menu)
 673.857 +	{
 673.858 +		state.m_pMenu = state.m_pParentMenu;
 673.859 +		recursiveCall = true;
 673.860 +		fullUpdated	  = true;
 673.861 +	}
 673.862 +	else if (!translatingAccelerator && fullUpdated)
 673.863 +	{
 673.864 +		fullUpdated = false;
 673.865 +	}
 673.866 +
 673.867 +	InitMenuKludge(state.m_pParentMenu, state.m_pMenu, this);
 673.868 +
 673.869 +	recursiveCall = false;
 673.870 +}
 673.871 +
 673.872 +void MainWnd::OnInitMenu(CMenu *pMenu)
 673.873 +{
 673.874 +//	CWnd::OnInitMenu(pMenu);
 673.875 +
 673.876 +	if (translatingAccelerator)
 673.877 +	{}
 673.878 +	else
 673.879 +	{
 673.880 +		// HACK: we only want to call this if the user is pulling down the menu,
 673.881 +		// but TranslateAccelerator also causes OnInitMenu to be called, so ignore that
 673.882 +
 673.883 +		systemSoundPause();
 673.884 +	}
 673.885 +}
 673.886 +
 673.887 +void MainWnd::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
 673.888 +{
 673.889 +	CWnd::OnActivate(nState, pWndOther, bMinimized);
 673.890 +
 673.891 +	bool activated = (nState == WA_ACTIVE || nState == WA_CLICKACTIVE) && !bMinimized;
 673.892 +
 673.893 +	theApp.active = activated || !theApp.pauseWhenInactive;
 673.894 +
 673.895 +	extern bool inputActive;
 673.896 +	inputActive = activated || (!theApp.pauseWhenInactive && theApp.enableBackgroundInput);
 673.897 +
 673.898 +	if (theApp.active)
 673.899 +	{
 673.900 +		if (theApp.input)
 673.901 +		{
 673.902 +			theApp.input->activate();
 673.903 +		}
 673.904 +
 673.905 +		if (!theApp.paused && emulating)
 673.906 +		{
 673.907 +			systemSoundResume();
 673.908 +		}
 673.909 +	}
 673.910 +	else
 673.911 +	{
 673.912 +		theApp.wasPaused = true;
 673.913 +
 673.914 +		if (!theApp.paused && emulating)
 673.915 +		{
 673.916 +			systemSoundPause();
 673.917 +		}
 673.918 +
 673.919 +		memset(theApp.delta, 255, sizeof(theApp.delta));
 673.920 +	}
 673.921 +
 673.922 +	if (theApp.muteWhenInactive)
 673.923 +	{
 673.924 +		theApp.winMuteForNow = !activated;
 673.925 +	}
 673.926 +
 673.927 +	if (theApp.paused && emulating)
 673.928 +	{
 673.929 +		systemRefreshScreen();
 673.930 +	}
 673.931 +}
 673.932 +
 673.933 +#if _MSC_VER <= 1200
 673.934 +void MainWnd::OnActivateApp(BOOL bActive, HTASK hTask)
 673.935 +#else
 673.936 +void MainWnd::OnActivateApp(BOOL bActive, DWORD hTask)
 673.937 +#endif
 673.938 +{
 673.939 +	CWnd::OnActivateApp(bActive, hTask);
 673.940 +
 673.941 +	if (theApp.tripleBuffering && theApp.videoOption > VIDEO_4X)
 673.942 +	{
 673.943 +		if (bActive)
 673.944 +		{
 673.945 +			if (theApp.display)
 673.946 +				theApp.display->clear();
 673.947 +		}
 673.948 +	}
 673.949 +}
 673.950 +
 673.951 +LRESULT MainWnd::OnMySysCommand(WPARAM wParam, LPARAM lParam)
 673.952 +{
 673.953 +	if (emulating && !theApp.paused)
 673.954 +	{
 673.955 +		if ((wParam & 0xFFF0) == SC_SCREENSAVE || (wParam & 0xFFF0) == SC_MONITORPOWER)
 673.956 +			return 0;
 673.957 +	}
 673.958 +	return Default();
 673.959 +}
 673.960 +
 673.961 +void MainWnd::OnDropFiles(HDROP hDropInfo)
 673.962 +{
 673.963 +	// FIXME: required for the accel key fix
 673.964 +	fullUpdated = false;
 673.965 +
 673.966 +	systemSoundClearBuffer();
 673.967 +
 673.968 +	char szFile[1024];
 673.969 +	char ext[1024];
 673.970 +
 673.971 +	if (DragQueryFile(hDropInfo, 0, szFile, 1024))
 673.972 +	{
 673.973 +		DragFinish(hDropInfo);
 673.974 +
 673.975 +		_splitpath(szFile, NULL, NULL, NULL, ext);
 673.976 +		if (strcasecmp(ext, ".lua") == 0)
 673.977 +		{
 673.978 +			if (VBALoadLuaCode(szFile))
 673.979 +			{
 673.980 +				// success, there is nothing to do
 673.981 +			}
 673.982 +			else
 673.983 +			{
 673.984 +				// Errors are displayed by the Lua code.
 673.985 +			}
 673.986 +		}
 673.987 +		else if (strcasecmp(ext, ".vbm") == 0)
 673.988 +		{
 673.989 +			SMovie movieInfo;
 673.990 +			char * movieName = szFile;
 673.991 +			char   romTitle [12];
 673.992 +			uint32 romGameCode;
 673.993 +			uint16 checksum;
 673.994 +			uint8  crc;
 673.995 +
 673.996 +			if (VBAMovieGetInfo(movieName, &movieInfo) != MOVIE_SUCCESS)
 673.997 +			{
 673.998 +				return;
 673.999 +			}
673.1000 +
673.1001 +			int cartType = movieInfo.header.typeFlags & 1 ? 0 : 1;
673.1002 +
673.1003 +			if (!emulating)
673.1004 +			{
673.1005 +				theApp.winCheckFullscreen();
673.1006 +				if (winFileOpenSelect(cartType))
673.1007 +				{
673.1008 +					if (VBAMovieActive())
673.1009 +						VBAMovieStop(false);  // will only get here on user selecting to play a ROM, canceling movie
673.1010 +					if (!winFileRun())
673.1011 +						return;
673.1012 +				}
673.1013 +				else
673.1014 +					return;
673.1015 +			}
673.1016 +			VBAMovieGetRomInfo(movieInfo, romTitle, romGameCode, checksum, crc);
673.1017 +
673.1018 +			while (movieInfo.header.romCRC != crc
673.1019 +			       || strncmp(movieInfo.header.romTitle, romTitle, 12) != 0
673.1020 +			       || movieInfo.header.romOrBiosChecksum != checksum
673.1021 +			       && !((movieInfo.header.optionFlags & MOVIE_SETTING_USEBIOSFILE) == 0 && checksum == 0))
673.1022 +			{
673.1023 +				char msg[1024], warning1[1024], warning2[1024], buffer[1024];
673.1024 +
673.1025 +				strcpy(warning1, "");
673.1026 +				strcpy(warning2, "");
673.1027 +				{
673.1028 +					char str [13];
673.1029 +					strncpy(str, movieInfo.header.romTitle, 12);
673.1030 +					str[12] = '\0';
673.1031 +					sprintf(buffer, "title=%s  ", str);
673.1032 +					strcat(warning1, buffer);
673.1033 +
673.1034 +					strncpy(str, romTitle, 12);
673.1035 +					str[12] = '\0';
673.1036 +					sprintf(buffer, "title=%s  ", str);
673.1037 +					strcat(warning2, buffer);
673.1038 +				}
673.1039 +				{
673.1040 +					sprintf(buffer, "type=%s  ",
673.1041 +					        (movieInfo.header.typeFlags & MOVIE_TYPE_GBA) ?
673.1042 +					        "GBA" : (movieInfo.header.typeFlags & MOVIE_TYPE_GBC) ?
673.1043 +					        "GBC" : (movieInfo.header.typeFlags & MOVIE_TYPE_SGB) ? "SGB" : "GB");
673.1044 +					strcat(warning1, buffer);
673.1045 +
673.1046 +					sprintf(buffer, "type=%s  ", systemCartridgeType ==
673.1047 +					        0 ? "GBA" : (gbRom[0x143] & 0x80 ? "GBC" : (gbRom[0x146] == 0x03 ? "SGB" : "GB")));
673.1048 +					strcat(warning2, buffer);
673.1049 +				}
673.1050 +				{
673.1051 +					sprintf(buffer, "crc=%02x  ", movieInfo.header.romCRC);
673.1052 +					strcat(warning1, buffer);
673.1053 +
673.1054 +					sprintf(buffer, "crc=%02x  ", crc);
673.1055 +					strcat(warning2, buffer);
673.1056 +				}
673.1057 +				{
673.1058 +					char code [5];
673.1059 +					if (movieInfo.header.typeFlags & MOVIE_TYPE_GBA)
673.1060 +					{
673.1061 +						memcpy(code, &movieInfo.header.romGameCode, 4);
673.1062 +						code[4] = '\0';
673.1063 +						sprintf(buffer, "code=%s  ", code);
673.1064 +						strcat(warning1, buffer);
673.1065 +					}
673.1066 +
673.1067 +					if (systemCartridgeType == 0)
673.1068 +					{
673.1069 +						memcpy(code, &romGameCode, 4);
673.1070 +						code[4] = '\0';
673.1071 +						sprintf(buffer, "code=%s  ", code);
673.1072 +						strcat(warning2, buffer);
673.1073 +					}
673.1074 +				}
673.1075 +				{
673.1076 +					sprintf(buffer,
673.1077 +					        movieInfo.header.typeFlags &
673.1078 +					        MOVIE_TYPE_GBA ? ((movieInfo.header.optionFlags & MOVIE_SETTING_USEBIOSFILE) ==
673.1079 +					                          0 ? "(bios=none)  " : "(bios=%04x)  ") : "check=%04x  ",
673.1080 +					        movieInfo.header.romOrBiosChecksum);
673.1081 +					strcat(warning1, buffer);
673.1082 +
673.1083 +					sprintf(buffer,
673.1084 +					        checksum == 0 ? "(bios=none)  " : systemCartridgeType == 0 ? "(bios=%04x)  " : "check=%04x  ",
673.1085 +					        checksum);
673.1086 +					strcat(warning2, buffer);
673.1087 +				}
673.1088 +
673.1089 +				strcpy(msg, "");
673.1090 +				sprintf(buffer, "Movie ROM: %s\n", warning1);
673.1091 +				strcat(msg, buffer);
673.1092 +				sprintf(buffer, "Your ROM: %s\n", warning2);
673.1093 +				strcat(msg, buffer);
673.1094 +				strcat(msg, "still want to play the movie?");
673.1095 +
673.1096 +				int sel = MessageBox(msg, TEXT("ROM Mismatch"), MB_ABORTRETRYIGNORE | MB_ICONQUESTION);
673.1097 +				switch (sel)
673.1098 +				{
673.1099 +				case IDABORT:
673.1100 +					return;
673.1101 +				case IDRETRY:
673.1102 +					theApp.winCheckFullscreen();
673.1103 +					if (winFileOpenSelect(cartType))
673.1104 +					{
673.1105 +						if (VBAMovieActive())
673.1106 +							VBAMovieStop(false);  // will only get here on user selecting to play a ROM, canceling movie
673.1107 +						if (!winFileRun())
673.1108 +							return;
673.1109 +						VBAMovieGetRomInfo(movieInfo, romTitle, romGameCode, checksum, crc);
673.1110 +					}
673.1111 +					else
673.1112 +						return;
673.1113 +					break;
673.1114 +				default:
673.1115 +					goto romcheck_exit;
673.1116 +				}
673.1117 +			}
673.1118 +romcheck_exit:
673.1119 +
673.1120 +			bool useBIOSFile = (movieInfo.header.optionFlags & MOVIE_SETTING_USEBIOSFILE) != 0;
673.1121 +			if (useBIOSFile)
673.1122 +			{
673.1123 +				extern bool systemLoadBIOS(const char *biosFileName, bool useBiosFile);
673.1124 +				if (!systemLoadBIOS(theApp.biosFileName, useBIOSFile))
673.1125 +				{
673.1126 +					systemMessage(0, "This movie requires a valid GBA BIOS file to play.\nPlease locate a BIOS file.");
673.1127 +					((MainWnd *)theApp.m_pMainWnd)->OnOptionsEmulatorSelectbiosfile();
673.1128 +					if (!systemLoadBIOS(theApp.biosFileName, useBIOSFile))
673.1129 +					{
673.1130 +						systemMessage(0, "\"%s\" is not a valid BIOS file; cannot play movie without one.", theApp.biosFileName);
673.1131 +						return;
673.1132 +					}
673.1133 +				}
673.1134 +			}
673.1135 +
673.1136 +			int code = VBAMovieOpen(movieName, TRUE);
673.1137 +
673.1138 +			if (code != MOVIE_SUCCESS)
673.1139 +			{
673.1140 +				if (code == MOVIE_FILE_NOT_FOUND)
673.1141 +					systemMessage(0, "Could not find movie file \"%s\".", (const char *)movieName);
673.1142 +				else if (code == MOVIE_WRONG_FORMAT)
673.1143 +					systemMessage(0, "Movie file \"%s\" is not in proper VBM format.", (const char *)movieName);
673.1144 +				else if (code == MOVIE_WRONG_VERSION)
673.1145 +					systemMessage(0, "Movie file \"%s\" is not a supported version.", (const char *)movieName);
673.1146 +				else
673.1147 +					systemMessage(0, "Failed to open movie \"%s\".", (const char *)movieName);
673.1148 +				return;
673.1149 +			}
673.1150 +		}
673.1151 +		else if (strcasecmp(ext, ".wch") == 0)
673.1152 +		{
673.1153 +			if (emulating)
673.1154 +			{
673.1155 +				MainWnd::OnFileRamWatch();
673.1156 +				Load_Watches(true, szFile);
673.1157 +			}
673.1158 +		}
673.1159 +		else
673.1160 +		{
673.1161 +			theApp.romFilename = szFile;
673.1162 +			if (winFileRun())
673.1163 +			{
673.1164 +				SetForegroundWindow();
673.1165 +			}
673.1166 +		}
673.1167 +	}
673.1168 +	else
673.1169 +		DragFinish(hDropInfo);
673.1170 +}
673.1171 +
673.1172 +/////////////////////
673.1173 +
673.1174 +void MainWnd::winMouseOn()
673.1175 +{
673.1176 +	SetCursor(arrow);
673.1177 +	if (theApp.videoOption > VIDEO_4X)
673.1178 +	{
673.1179 +		theApp.mouseCounter = 120;
673.1180 +	}
673.1181 +	else
673.1182 +		theApp.mouseCounter = 0;
673.1183 +}
673.1184 +
673.1185 +void MainWnd::winConfirmMode()
673.1186 +{
673.1187 +	if (theApp.renderMethod == DIRECT_DRAW && theApp.videoOption > VIDEO_4X)
673.1188 +	{
673.1189 +		theApp.winCheckFullscreen();
673.1190 +		ModeConfirm dlg(this);
673.1191 +
673.1192 +		if (!dlg.DoModal())
673.1193 +		{
673.1194 +			theApp.updateVideoSize(ID_OPTIONS_VIDEO_X2);
673.1195 +		}
673.1196 +	}
673.1197 +}
673.1198 +
673.1199 +bool MainWnd::winFileOpenSelect(int cartridgeType)
673.1200 +{
673.1201 +	int selectedFilter = regQueryDwordValue("selectedFilter", 0);
673.1202 +	if (selectedFilter < 0 || selectedFilter > 2)
673.1203 +		selectedFilter = 0;
673.1204 +
673.1205 +	LPCTSTR exts[] = { NULL };
673.1206 +	CString filter = winResLoadFilter(IDS_FILTER_ROM);
673.1207 +	CString title  = winResLoadString(IDS_SELECT_ROM);
673.1208 +
673.1209 +	bool	isOverrideEmpty = false;
673.1210 +	CString initialDir		= regQueryStringValue(cartridgeType == 0 ? IDS_ROM_DIR : IDS_GBXROM_DIR, NULL);
673.1211 +	if (initialDir.IsEmpty())
673.1212 +	{
673.1213 +		isOverrideEmpty = true;
673.1214 +		CString altDir = regQueryStringValue(cartridgeType != 0 ? IDS_ROM_DIR : IDS_GBXROM_DIR, NULL);
673.1215 +		initialDir = altDir.IsEmpty() ? theApp.exeDir : altDir;
673.1216 +	}
673.1217 +
673.1218 +	FileDlg dlg(this, "", filter, selectedFilter, "ROM", exts, initialDir, title, false, true);
673.1219 +
673.1220 +	if (dlg.DoModal() == IDOK)
673.1221 +	{
673.1222 +		regSetDwordValue("selectedFilter", dlg.m_ofn.nFilterIndex);
673.1223 +		theApp.romFilename = dlg.GetPathName();
673.1224 +		initialDir		   = winGetDirFromFilename(theApp.romFilename);
673.1225 +
673.1226 +		// we have directory override for that purpose
673.1227 +		// but this can be...desirable
673.1228 +		if (isOverrideEmpty)
673.1229 +			regSetStringValue(cartridgeType == 0 ? IDS_ROM_DIR : IDS_GBXROM_DIR, initialDir);
673.1230 +		return true;
673.1231 +	}
673.1232 +	return false;
673.1233 +}
673.1234 +
673.1235 +// some extensions that might commonly be near emulation-related files that we almost certainly can't open, or at least not
673.1236 +// directly.
673.1237 +// also includes definitely non-ROM extensions we know about, since we only use this variable in a ROM opening function.
673.1238 +// we do this by exclusion instead of inclusion because we don't want to exclude extensions used for any archive files, even
673.1239 +// extensionless or unusually-named archives.
673.1240 +static const char *s_romIgnoreExtensions[] = {
673.1241 +	"vbm", "sgm",  "clt",  "dat",	"gbs",	"gcf",	"spc", "xpc", "pal", "act", "dmp", "avi", "ini", "txt", "nfo",
673.1242 +	"htm", "html", "jpg",  "jpeg",	"png",	"bmp",	"gif", "mp3", "wav", "lnk", "exe", "bat", "sav", "luasav"
673.1243 +};
673.1244 +
673.1245 +#include "GBACheatsDlg.h"
673.1246 +#include "GBCheatsDlg.h"
673.1247 +
673.1248 +#include "../common/CheatSearch.h"
673.1249 +#include "../gba/GBA.h"
673.1250 +#include "../gb/GB.h"
673.1251 +#include "../gba/Flash.h"
673.1252 +#include "../gba/RTC.h"
673.1253 +
673.1254 +void MainWnd::winFileClose(bool reopening)
673.1255 +{
673.1256 +	if (rom != NULL || gbRom != NULL)
673.1257 +	{
673.1258 +		if (theApp.autoSaveLoadCheatList)
673.1259 +			winSaveCheatListDefault();
673.1260 +
673.1261 +		if (!reopening)
673.1262 +		{
673.1263 +			// save battery file before we change the filename...
673.1264 +			winWriteBatteryFile();
673.1265 +			cheatSearchCleanup(&cheatSearchData);
673.1266 +			capturePrevious = 0;
673.1267 +			captureNumber	= 0;
673.1268 +		}
673.1269 +
673.1270 +		theApp.emulator.emuCleanUp();
673.1271 +
673.1272 +		extern void remoteCleanUp();
673.1273 +		remoteCleanUp();
673.1274 +	}
673.1275 +
673.1276 +	if (VBAMovieActive())
673.1277 +		VBAMovieStop(false);  // will only get here on user selecting to open a ROM, canceling movie
673.1278 +
673.1279 +	theApp.frameSearching	   = false;
673.1280 +	theApp.frameSearchSkipping = false;
673.1281 +	emulating = 0;
673.1282 +
673.1283 +	if (this)
673.1284 +		RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN);
673.1285 +	systemSetTitle(VBA_NAME_AND_VERSION);
673.1286 +}
673.1287 +
673.1288 +bool MainWnd::winFileRun(bool reopening)
673.1289 +{
673.1290 +	int prevCartridgeType = systemCartridgeType;
673.1291 +
673.1292 +	//bool requiresInitRAMSearch = (rom == NULL && gbRom == NULL) || !reopening;
673.1293 +	winFileClose(reopening);
673.1294 +
673.1295 +	// use ObtainFile to support opening files within archives (.7z, .rar, .zip, .zip.rar.7z, etc.)
673.1296 +	if (theApp.romFilename.GetLength() > 2048) theApp.romFilename.Truncate(2048);
673.1297 +
673.1298 +	char logicalName[2048], physicalName[2048];
673.1299 +
673.1300 +	// FIXME: assertion failure in fopen.c if canceled
673.1301 +	if (ObtainFile(theApp.romFilename, logicalName, physicalName, "rom", s_romIgnoreExtensions,
673.1302 +	               sizeof(s_romIgnoreExtensions) / sizeof(*s_romIgnoreExtensions)))
673.1303 +	{
673.1304 +		// theApp.romFilename is exactly the filename used for opening, while theApp.gameFilename is always the logical name
673.1305 +		theApp.romFilename = theApp.gameFilename = logicalName;
673.1306 +		ReleaseTempFileCategory("rom", physicalName);
673.1307 +	}
673.1308 +	else
673.1309 +	{
673.1310 +		return false;
673.1311 +	}
673.1312 +
673.1313 +	IMAGE_TYPE type = utilFindType(physicalName);
673.1314 +
673.1315 +	if (type == IMAGE_UNKNOWN)
673.1316 +	{
673.1317 +		systemMessage(IDS_UNSUPPORTED_FILE_TYPE,
673.1318 +		              "The file \"%s\" is an unsupported type.", logicalName);
673.1319 +		return false;
673.1320 +	}
673.1321 +	systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
673.1322 +	systemCartridgeType		= (int)type;
673.1323 +	if (type == IMAGE_GB)
673.1324 +	{
673.1325 +		if (!gbLoadRom(physicalName))
673.1326 +			return false;
673.1327 +
673.1328 +		gbBorderOn		= theApp.winGbBorderOn;
673.1329 +		theApp.emulator = GBSystem;
673.1330 +		theApp.romSize	= gbRomSize;
673.1331 +		if (theApp.autoIPS)
673.1332 +		{
673.1333 +			CString ipsname = winGetDestFilename(logicalName, IDS_IPS_DIR, ".ips");
673.1334 +			int		size	= gbRomSize;
673.1335 +			utilApplyIPS(ipsname, &gbRom, &size);
673.1336 +			if (size != gbRomSize)
673.1337 +			{
673.1338 +				extern bool gbUpdateSizes();
673.1339 +				gbUpdateSizes();
673.1340 +				theApp.romSize = size;
673.1341 +			}
673.1342 +		}
673.1343 +
673.1344 +		useBios = false;    // FIXME
673.1345 +		
673.1346 +		if (reopening)
673.1347 +		{
673.1348 +			bool winGbCheatReaddress();
673.1349 +			winGbCheatReaddress();
673.1350 +		}
673.1351 +	}
673.1352 +	else
673.1353 +	{
673.1354 +		int size = CPULoadRom(physicalName);
673.1355 +		if (!size)
673.1356 +			return false;
673.1357 +
673.1358 +		flashSetSize(theApp.winFlashSize);
673.1359 +		rtcEnable(theApp.winRtcEnable);
673.1360 +		cpuSaveType = theApp.winSaveType;
673.1361 +
673.1362 +		//    if(cpuEnhancedDetection && winSaveType == 0) {
673.1363 +		//      utilGBAFindSave(rom, size);
673.1364 +		//    }
673.1365 +
673.1366 +		char buffer[5];
673.1367 +		strncpy(buffer, (const char *)&rom[0xac], 4);
673.1368 +		buffer[4] = 0;
673.1369 +
673.1370 +		// vba-over.ini
673.1371 +		CString vbaOverINI = theApp.exeDir;
673.1372 +		vbaOverINI += "\\vba-over.ini";
673.1373 +
673.1374 +		UINT i = GetPrivateProfileInt(buffer, "rtcEnabled", -1, vbaOverINI);
673.1375 +		if (i != (UINT)-1)
673.1376 +			rtcEnable(i == 0 ? false : true);
673.1377 +
673.1378 +		i = GetPrivateProfileInt(buffer, "flashSize", -1, vbaOverINI);
673.1379 +		if (i != (UINT)-1 && (i == 0x10000 || i == 0x20000))
673.1380 +			flashSetSize((int)i);
673.1381 +
673.1382 +		i = GetPrivateProfileInt(buffer, "saveType", -1, vbaOverINI);
673.1383 +		if (i != (UINT)-1 && (i <= 5))
673.1384 +			cpuSaveType = (int)i;
673.1385 +
673.1386 +		/* disabled due to problems
673.1387 +		   if(theApp.removeIntros && rom != NULL) {
673.1388 +		   *((u32 *)rom)= 0xea00002e;
673.1389 +		   }
673.1390 +		 */
673.1391 +		theApp.emulator = GBASystem;
673.1392 +		theApp.romSize	= size;
673.1393 +		if (theApp.autoIPS)
673.1394 +		{
673.1395 +			CString ipsname = winGetDestFilename(logicalName, IDS_IPS_DIR, ".ips");
673.1396 +			int		size	= 0x2000000;
673.1397 +			utilApplyIPS(ipsname, &rom, &size);
673.1398 +		}
673.1399 +
673.1400 +		skipBios = theApp.skipBiosFile ? true : false;
673.1401 +		CPUInit();
673.1402 +		CPULoadBios(theApp.biosFileName, theApp.useBiosFile ? true : false);
673.1403 +		CPUReset();
673.1404 +
673.1405 +		if (reopening)
673.1406 +		{
673.1407 +			bool winGbaCheatReaddress();
673.1408 +			winGbaCheatReaddress();
673.1409 +		}
673.1410 +	}
673.1411 +
673.1412 +	if (theApp.soundInitialized)
673.1413 +	{
673.1414 +		if (systemCartridgeType == 1)
673.1415 +			gbSoundReset();
673.1416 +		else
673.1417 +			soundReset();
673.1418 +	}
673.1419 +	else
673.1420 +	{
673.1421 +		if (!soundOffFlag)
673.1422 +			soundInit();
673.1423 +		theApp.soundInitialized = true;
673.1424 +	}
673.1425 +
673.1426 +	winReadBatteryFile();
673.1427 +
673.1428 +	emulating = true;
673.1429 +
673.1430 +	if (theApp.autoSaveLoadCheatList)
673.1431 +		winLoadCheatListDefault();
673.1432 +
673.1433 +	if (theApp.filenamePreference == 0)
673.1434 +		theApp.addRecentFile(winGetOriginalFilename(logicalName));
673.1435 +	else
673.1436 +		theApp.addRecentFile(logicalName);
673.1437 +
673.1438 +	theApp.updateWindowSize(theApp.videoOption);
673.1439 +
673.1440 +	theApp.updateFrameSkip();
673.1441 +
673.1442 +	if (theApp.autoHideMenu && theApp.videoOption > VIDEO_4X && theApp.menuToggle)
673.1443 +		OnFileTogglemenu();
673.1444 +
673.1445 +	if (theApp.autoLoadMostRecent && !VBAMovieActive() && !VBAMovieLoading()) // would cause desync in movies...
673.1446 +		OnFileLoadgameMostrecent();
673.1447 +
673.1448 +	theApp.renderedFrames = 0;
673.1449 +
673.1450 +	theApp.rewindCount		= 0;
673.1451 +	theApp.rewindCounter	= 0;
673.1452 +	theApp.rewindSaveNeeded = false;
673.1453 +
673.1454 +	{
673.1455 +		extern bool playMovieFile, playMovieFileReadOnly, outputWavFile, outputAVIFile, flagHideMenu; // from VBA.cpp
673.1456 +		extern char movieFileToPlay[1024], wavFileToOutput[1024]; // from VBA.cpp
673.1457 +		extern int	pauseAfterTime; // from VBA.cpp
673.1458 +		if (playMovieFile)
673.1459 +		{
673.1460 +			playMovieFile = false;
673.1461 +			VBAMovieOpen(movieFileToPlay, playMovieFileReadOnly);
673.1462 +		}
673.1463 +		if (outputWavFile)
673.1464 +		{
673.1465 +			outputWavFile = false;
673.1466 +			theApp.soundRecordName = wavFileToOutput;
673.1467 +			theApp.soundRecording  = true;
673.1468 +		}
673.1469 +		if (outputAVIFile)
673.1470 +		{
673.1471 +			outputAVIFile = false;
673.1472 +			OnToolsStartAVIRecording();
673.1473 +		}
673.1474 +		if (pauseAfterTime >= 0)
673.1475 +		{
673.1476 +			VBAMovieSetPauseAt(pauseAfterTime);
673.1477 +		}
673.1478 +		if (flagHideMenu)
673.1479 +		{
673.1480 +			OnFileTogglemenu();
673.1481 +			theApp.updateWindowSize(theApp.videoOption);
673.1482 +		}
673.1483 +	}
673.1484 +
673.1485 +	if (systemCartridgeType != prevCartridgeType)
673.1486 +	{
673.1487 +		extern GBACheatSearch gbaDlg;
673.1488 +		extern GBCheatSearch  gbDlg;
673.1489 +		if (!theApp.pauseDuringCheatSearch && theApp.modelessCheatDialogIsOpen)
673.1490 +		{
673.1491 +			gbaDlg.DestroyWindow();
673.1492 +			gbDlg.DestroyWindow();
673.1493 +			theApp.modelessCheatDialogIsOpen = false;
673.1494 +		}
673.1495 +	}
673.1496 +
673.1497 +	theApp.winCheckFullscreen();
673.1498 +	ReopenRamWindows();
673.1499 +
673.1500 +	// FIXME
673.1501 +	reset_address_info();
673.1502 +	//if (requiresInitRAMSearch)
673.1503 +	{
673.1504 +		// extern void soft_reset_address_info();
673.1505 +		// soft_reset_address_info();
673.1506 +	}
673.1507 +
673.1508 +	VBAUpdateButtonPressDisplay();
673.1509 +	VBAUpdateFrameCountDisplay();
673.1510 +	systemRefreshScreen();
673.1511 +
673.1512 +	return true;
673.1513 +}
673.1514 +
   674.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   674.2 +++ b/src/win32/MainWnd.h	Sat Mar 03 10:31:27 2012 -0600
   674.3 @@ -0,0 +1,541 @@
   674.4 +#if !defined(AFX_MAINWND_H__E8AD28B9_C9FB_4EC2_A2DC_DD1BBA55A275__INCLUDED_)
   674.5 +#define AFX_MAINWND_H__E8AD28B9_C9FB_4EC2_A2DC_DD1BBA55A275__INCLUDED_
   674.6 +
   674.7 +#if _MSC_VER > 1000
   674.8 +#pragma once
   674.9 +#endif // _MSC_VER > 1000
  674.10 +// MainWnd.h : header file
  674.11 +//
  674.12 +
  674.13 +/////////////////////////////////////////////////////////////////////////////
  674.14 +// MainWnd window
  674.15 +
  674.16 +class MainWnd : public CWnd
  674.17 +{
  674.18 +	// Constructor/Destructor
  674.19 +public:
  674.20 +	MainWnd();
  674.21 +	virtual ~MainWnd();
  674.22 +
  674.23 +	// Attributes
  674.24 +private:
  674.25 +	HCURSOR arrow;
  674.26 +	HACCEL m_hAccelTable;
  674.27 +
  674.28 +	// Implementation
  674.29 +private:
  674.30 +
  674.31 +	// Operations
  674.32 +public:
  674.33 +	afx_msg void OnOptionsEmulatorSelectbiosfile();
  674.34 +	void winFileClose(bool reopening = false);
  674.35 +	bool winFileRun(bool reopening = false);
  674.36 +	bool winFileOpenSelect(int cartridgeType);
  674.37 +	void winMouseOn();
  674.38 +	void winConfirmMode();
  674.39 +
  674.40 +	// Overrides
  674.41 +	// ClassWizard generated virtual function overrides
  674.42 +	//{{AFX_VIRTUAL(MainWnd)
  674.43 +public:
  674.44 +	virtual BOOL PreTranslateMessage(MSG*pMsg);
  674.45 +	//}}AFX_VIRTUAL
  674.46 +
  674.47 +	// Generated message map functions
  674.48 +protected:
  674.49 +	//{{AFX_MSG(MainWnd)
  674.50 +	afx_msg LRESULT OnConfirmMode(WPARAM, LPARAM);
  674.51 +	afx_msg LRESULT OnMySysCommand(WPARAM, LPARAM);
  674.52 +
  674.53 +	afx_msg void OnMove(int x, int y);
  674.54 +	afx_msg void OnContextMenu(CWnd*pWnd, CPoint point);
  674.55 +	afx_msg void OnSize(UINT nType, int cx, int cy);
  674.56 +	afx_msg void OnClose();
  674.57 +	afx_msg void OnInitMenuPopup(CMenu*pPopupMenu, UINT nIndex, BOOL bSysMenu);
  674.58 +	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  674.59 +	afx_msg void OnInitMenu(CMenu*pMenu);
  674.60 +	afx_msg void OnPaint();
  674.61 +	afx_msg void OnDropFiles(HDROP hDropInfo);
  674.62 +	afx_msg void OnActivate(UINT nState, CWnd*pWndOther, BOOL bMinimized);
  674.63 +#if _MSC_VER <= 1200
  674.64 +	afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);
  674.65 +#else
  674.66 +	afx_msg void OnActivateApp(BOOL bActive, DWORD hTask);
  674.67 +#endif
  674.68 +
  674.69 +	afx_msg void OnUpdateOptionsJoypadAutofire(CCmdUI *pCmdUI);
  674.70 +	afx_msg BOOL OnOptionsJoypadAutofire(UINT nID);
  674.71 +	afx_msg void OnUpdateOptionsJoypadSticky(CCmdUI *pCmdUI);
  674.72 +	afx_msg BOOL OnOptionsJoypadSticky(UINT nID);
  674.73 +	afx_msg void OnUpdateOptionsJoypadDefault(CCmdUI *pCmdUI);
  674.74 +	afx_msg BOOL OnOptionsJoypadDefault(UINT nID);
  674.75 +	afx_msg void OnUpdateOptionsFilterIFB(CCmdUI *pCmdUI);
  674.76 +	afx_msg BOOL OnOptionsFilterIFB(UINT nID);
  674.77 +	afx_msg void OnUpdateOptionsFilter(CCmdUI *pCmdUI);
  674.78 +	afx_msg BOOL OnOptionsFilter(UINT nID);
  674.79 +	afx_msg void OnUpdateOptionsPriority(CCmdUI *pCmdUI);
  674.80 +	afx_msg BOOL OnOptionsPriority(UINT nID);
  674.81 +	afx_msg void OnUpdateOptionsSoundVolume(CCmdUI *pCmdUI);
  674.82 +	afx_msg BOOL OnOptionsSoundVolume(UINT nID);
  674.83 +	afx_msg void OnUpdateOptionsEmulatorShowSpeed(CCmdUI *pCmdUI);
  674.84 +	afx_msg BOOL OnOptionsEmulatorShowSpeed(UINT nID);
  674.85 +	afx_msg void OnUpdateVideoLayer(CCmdUI*pCmdUI);
  674.86 +	afx_msg BOOL OnVideoLayer(UINT nID);
  674.87 +	afx_msg BOOL OnOptionVideoSize(UINT nID);
  674.88 +	afx_msg BOOL OnOptionsFrameskip(UINT nID);
  674.89 +	afx_msg void OnFileTogglemenu();
  674.90 +
  674.91 +	afx_msg void OnSystemMinimize();
  674.92 +	afx_msg void OnSystemMaximize();
  674.93 +
  674.94 +	afx_msg void OnHelpAbout();
  674.95 +	afx_msg void OnHelpFaq();
  674.96 +	afx_msg void OnFileOpen();
  674.97 +	afx_msg void OnFileOpenGBx();
  674.98 +	afx_msg void OnFilePause();
  674.99 +	afx_msg void OnUpdateFilePause(CCmdUI*pCmdUI);
 674.100 +	afx_msg void OnFileReset();
 674.101 +	afx_msg void OnUpdateFileReset(CCmdUI*pCmdUI);
 674.102 +	afx_msg void OnUpdateFileRecentFreeze(CCmdUI*pCmdUI);
 674.103 +	afx_msg void OnFileRecentReset();
 674.104 +	afx_msg void OnFileRecentFreeze();
 674.105 +	afx_msg void OnFileExit();
 674.106 +	afx_msg void OnFileClose();
 674.107 +	afx_msg void OnUpdateFileClose(CCmdUI*pCmdUI);
 674.108 +	afx_msg void OnFileLoad();
 674.109 +	afx_msg void OnUpdateFileLoad(CCmdUI*pCmdUI);
 674.110 +	afx_msg void OnFileSave();
 674.111 +	afx_msg void OnUpdateFileSave(CCmdUI*pCmdUI);
 674.112 +	afx_msg void OnFileImportBatteryfile();
 674.113 +	afx_msg void OnUpdateFileImportBatteryfile(CCmdUI*pCmdUI);
 674.114 +	afx_msg void OnFileImportGamesharkcodefile();
 674.115 +	afx_msg void OnUpdateFileImportGamesharkcodefile(CCmdUI*pCmdUI);
 674.116 +	afx_msg void OnFileImportGamesharksnapshot();
 674.117 +	afx_msg void OnUpdateFileImportGamesharksnapshot(CCmdUI*pCmdUI);
 674.118 +	afx_msg void OnFileExportBatteryfile();
 674.119 +	afx_msg void OnUpdateFileExportBatteryfile(CCmdUI*pCmdUI);
 674.120 +	afx_msg void OnFileExportGamesharksnapshot();
 674.121 +	afx_msg void OnUpdateFileExportGamesharksnapshot(CCmdUI*pCmdUI);
 674.122 +	afx_msg void OnFileQuickScreencapture();
 674.123 +	afx_msg void OnFileScreencapture();
 674.124 +	afx_msg void OnUpdateFileScreencapture(CCmdUI*pCmdUI);
 674.125 +	afx_msg void OnFileRominformation();
 674.126 +	afx_msg void OnUpdateFileRominformation(CCmdUI*pCmdUI);
 674.127 +	afx_msg void OnUpdateFileTogglemenu(CCmdUI*pCmdUI);
 674.128 +	afx_msg void OnUpdateOptionsFrameskipThrottleNothrottle(CCmdUI*pCmdUI);
 674.129 +	afx_msg void OnUpdateOptionsFrameskipThrottle6(CCmdUI*pCmdUI);
 674.130 +	afx_msg void OnUpdateOptionsFrameskipThrottle15(CCmdUI*pCmdUI);
 674.131 +	afx_msg void OnUpdateOptionsFrameskipThrottle25(CCmdUI*pCmdUI);
 674.132 +	afx_msg void OnUpdateOptionsFrameskipThrottle50(CCmdUI*pCmdUI);
 674.133 +	afx_msg void OnUpdateOptionsFrameskipThrottle75(CCmdUI*pCmdUI);
 674.134 +	afx_msg void OnUpdateOptionsFrameskipThrottle100(CCmdUI*pCmdUI);
 674.135 +	afx_msg void OnUpdateOptionsFrameskipThrottle125(CCmdUI*pCmdUI);
 674.136 +	afx_msg void OnUpdateOptionsFrameskipThrottle150(CCmdUI*pCmdUI);
 674.137 +	afx_msg void OnUpdateOptionsFrameskipThrottle200(CCmdUI*pCmdUI);
 674.138 +	afx_msg void OnUpdateOptionsFrameskipThrottle300(CCmdUI*pCmdUI);
 674.139 +	afx_msg void OnUpdateOptionsFrameskipThrottle400(CCmdUI*pCmdUI);
 674.140 +	afx_msg void OnUpdateOptionsFrameskipThrottle600(CCmdUI*pCmdUI);
 674.141 +	afx_msg void OnUpdateOptionsFrameskipThrottle1000(CCmdUI*pCmdUI);
 674.142 +	afx_msg void OnUpdateOptionsFrameskipThrottleOther(CCmdUI*pCmdUI);
 674.143 +	afx_msg void OnUpdateOptionsFrameskipThrottleIncrease(CCmdUI*pCmdUI);
 674.144 +	afx_msg void OnUpdateOptionsFrameskipThrottleDecrease(CCmdUI*pCmdUI);
 674.145 +	afx_msg void OnOptionsFrameskipThrottleNothrottle();
 674.146 +	afx_msg void OnOptionsFrameskipThrottle6();
 674.147 +	afx_msg void OnOptionsFrameskipThrottle15();
 674.148 +	afx_msg void OnOptionsFrameskipThrottle25();
 674.149 +	afx_msg void OnOptionsFrameskipThrottle50();
 674.150 +	afx_msg void OnOptionsFrameskipThrottle75();
 674.151 +	afx_msg void OnOptionsFrameskipThrottle100();
 674.152 +	afx_msg void OnOptionsFrameskipThrottle125();
 674.153 +	afx_msg void OnOptionsFrameskipThrottle150();
 674.154 +	afx_msg void OnOptionsFrameskipThrottle200();
 674.155 +	afx_msg void OnOptionsFrameskipThrottle300();
 674.156 +	afx_msg void OnOptionsFrameskipThrottle400();
 674.157 +	afx_msg void OnOptionsFrameskipThrottle600();
 674.158 +	afx_msg void OnOptionsFrameskipThrottle1000();
 674.159 +	afx_msg void OnOptionsFrameskipThrottleOther();
 674.160 +	afx_msg void OnOptionsFrameskipThrottleIncrease();
 674.161 +	afx_msg void OnOptionsFrameskipThrottleDecrease();
 674.162 +	afx_msg void OnOptionsFrameskipAccuratePitch();
 674.163 +	afx_msg void OnOptionsFrameskipAccurateSpeed();
 674.164 +	afx_msg void OnUpdateOptionsFrameskipAccuratePitch(CCmdUI*pCmdUI);
 674.165 +	afx_msg void OnUpdateOptionsFrameskipAccurateSpeed(CCmdUI*pCmdUI);
 674.166 +	afx_msg void OnUpdateOptionsVideoFrameskip0(CCmdUI*pCmdUI);
 674.167 +	afx_msg void OnUpdateOptionsVideoFrameskip1(CCmdUI*pCmdUI);
 674.168 +	afx_msg void OnUpdateOptionsVideoFrameskip2(CCmdUI*pCmdUI);
 674.169 +	afx_msg void OnUpdateOptionsVideoFrameskip3(CCmdUI*pCmdUI);
 674.170 +	afx_msg void OnUpdateOptionsVideoFrameskip4(CCmdUI*pCmdUI);
 674.171 +	afx_msg void OnUpdateOptionsVideoFrameskip5(CCmdUI*pCmdUI);
 674.172 +	afx_msg void OnUpdateOptionsVideoFrameskip6(CCmdUI*pCmdUI);
 674.173 +	afx_msg void OnUpdateOptionsVideoFrameskip7(CCmdUI*pCmdUI);
 674.174 +	afx_msg void OnUpdateOptionsVideoFrameskip8(CCmdUI*pCmdUI);
 674.175 +	afx_msg void OnUpdateOptionsVideoFrameskip9(CCmdUI*pCmdUI);
 674.176 +	afx_msg void OnOptionsVideoVsync();
 674.177 +	afx_msg void OnUpdateOptionsVideoVsync(CCmdUI*pCmdUI);
 674.178 +	afx_msg void OnUpdateOptionsVideoX1(CCmdUI*pCmdUI);
 674.179 +	afx_msg void OnUpdateOptionsVideoX2(CCmdUI*pCmdUI);
 674.180 +	afx_msg void OnUpdateOptionsVideoX3(CCmdUI*pCmdUI);
 674.181 +	afx_msg void OnUpdateOptionsVideoX4(CCmdUI*pCmdUI);
 674.182 +	afx_msg void OnUpdateOptionsVideoFullscreen320x240(CCmdUI*pCmdUI);
 674.183 +	afx_msg void OnUpdateOptionsVideoFullscreen640x480(CCmdUI*pCmdUI);
 674.184 +	afx_msg void OnUpdateOptionsVideoFullscreen800x600(CCmdUI*pCmdUI);
 674.185 +	afx_msg void OnOptionsVideoFullscreen320x240();
 674.186 +	afx_msg void OnOptionsVideoFullscreen640x480();
 674.187 +	afx_msg void OnOptionsVideoFullscreen800x600();
 674.188 +	afx_msg void OnOptionsVideoFullscreen();
 674.189 +	afx_msg void OnUpdateOptionsVideoFullscreen(CCmdUI*pCmdUI);
 674.190 +	afx_msg void OnOptionsVideoDisablesfx();
 674.191 +	afx_msg void OnUpdateOptionsVideoDisablesfx(CCmdUI*pCmdUI);
 674.192 +	afx_msg void OnOptionsVideoFullscreenstretchtofit();
 674.193 +	afx_msg void OnUpdateOptionsVideoFullscreenstretchtofit(CCmdUI*pCmdUI);
 674.194 +	afx_msg void OnOptionsVideoRendermethodGdi();
 674.195 +	afx_msg void OnUpdateOptionsVideoRendermethodGdi(CCmdUI*pCmdUI);
 674.196 +	afx_msg void OnOptionsVideoRendermethodDirectdraw();
 674.197 +	afx_msg void OnUpdateOptionsVideoRendermethodDirectdraw(CCmdUI*pCmdUI);
 674.198 +	afx_msg void OnOptionsVideoRendermethodDirect3d();
 674.199 +	afx_msg void OnUpdateOptionsVideoRendermethodDirect3d(CCmdUI*pCmdUI);
 674.200 +	afx_msg void OnOptionsVideoRendermethodOpengl();
 674.201 +	afx_msg void OnUpdateOptionsVideoRendermethodOpengl(CCmdUI*pCmdUI);
 674.202 +	afx_msg void OnOptionsVideoTriplebuffering();
 674.203 +	afx_msg void OnUpdateOptionsVideoTriplebuffering(CCmdUI*pCmdUI);
 674.204 +	afx_msg void OnOptionsVideoDdrawemulationonly();
 674.205 +	afx_msg void OnUpdateOptionsVideoDdrawemulationonly(CCmdUI*pCmdUI);
 674.206 +	afx_msg void OnOptionsVideoDdrawusevideomemory();
 674.207 +	afx_msg void OnUpdateOptionsVideoDdrawusevideomemory(CCmdUI*pCmdUI);
 674.208 +	afx_msg void OnOptionsVideoRenderoptionsD3dnofilter();
 674.209 +	afx_msg void OnUpdateOptionsVideoRenderoptionsD3dnofilter(CCmdUI*pCmdUI);
 674.210 +	afx_msg void OnOptionsVideoRenderoptionsD3dbilinear();
 674.211 +	afx_msg void OnUpdateOptionsVideoRenderoptionsD3dbilinear(CCmdUI*pCmdUI);
 674.212 +	afx_msg void OnOptionsVideoRenderoptionsGlnearest();
 674.213 +	afx_msg void OnUpdateOptionsVideoRenderoptionsGlnearest(CCmdUI*pCmdUI);
 674.214 +	afx_msg void OnOptionsVideoRenderoptionsGlbilinear();
 674.215 +	afx_msg void OnUpdateOptionsVideoRenderoptionsGlbilinear(CCmdUI*pCmdUI);
 674.216 +	afx_msg void OnOptionsVideoRenderoptionsGltriangle();
 674.217 +	afx_msg void OnUpdateOptionsVideoRenderoptionsGltriangle(CCmdUI*pCmdUI);
 674.218 +	afx_msg void OnOptionsVideoRenderoptionsGlquads();
 674.219 +	afx_msg void OnUpdateOptionsVideoRenderoptionsGlquads(CCmdUI*pCmdUI);
 674.220 +	afx_msg void OnOptionsVideoRenderoptionsSelectskin();
 674.221 +	afx_msg void OnUpdateOptionsVideoRenderoptionsSelectskin(CCmdUI*pCmdUI);
 674.222 +	afx_msg void OnOptionsVideoRenderoptionsSkin();
 674.223 +	afx_msg void OnUpdateOptionsVideoRenderoptionsSkin(CCmdUI*pCmdUI);
 674.224 +
 674.225 +	afx_msg void OnOptionsEmulatorAssociate();
 674.226 +	afx_msg void OnOptionsEmulatorDirectories();
 674.227 +	afx_msg void OnOptionsEmulatorFilenamePreference(UINT nID);
 674.228 +	afx_msg void OnUpdateOptionsEmulatorFilenamePreference(CCmdUI*pCmdUI);
 674.229 +	afx_msg void OnOptionsVideoDisablestatusmessages();
 674.230 +	afx_msg void OnUpdateOptionsVideoDisablestatusmessages(CCmdUI*pCmdUI);
 674.231 +	afx_msg void OnOptionsEmulatorSynchronize();
 674.232 +	afx_msg void OnUpdateOptionsEmulatorSynchronize(CCmdUI*pCmdUI);
 674.233 +	afx_msg void OnOptionsEmulatorAlwaysOnTop();
 674.234 +	afx_msg void OnUpdateOptionsEmulatorAlwaysOnTop(CCmdUI*pCmdUI);
 674.235 +	afx_msg void OnOptionsEmulatorPausewheninactive();
 674.236 +	afx_msg void OnUpdateOptionsEmulatorPausewheninactive(CCmdUI*pCmdUI);
 674.237 +	afx_msg void OnOptionsEmulatorEnableBackgroundInput();
 674.238 +	afx_msg void OnUpdateOptionsEmulatorEnableBackgroundInput(CCmdUI*pCmdUI);
 674.239 +	afx_msg void OnOptionsEmulatorSpeeduptoggle();
 674.240 +	afx_msg void OnUpdateOptionsEmulatorSpeeduptoggle(CCmdUI*pCmdUI);
 674.241 +	afx_msg void OnOptionsEmulatorRemoveintrosgba();
 674.242 +	afx_msg void OnUpdateOptionsEmulatorRemoveintrosgba(CCmdUI*pCmdUI);
 674.243 +	afx_msg void OnOptionsEmulatorAutomaticallyipspatch();
 674.244 +	afx_msg void OnUpdateOptionsEmulatorAutomaticallyipspatch(CCmdUI*pCmdUI);
 674.245 +	afx_msg void OnOptionsEmulatorAgbprint();
 674.246 +	afx_msg void OnUpdateOptionsEmulatorAgbprint(CCmdUI*pCmdUI);
 674.247 +	afx_msg void OnOptionsEmulatorRealtimeclock();
 674.248 +	afx_msg void OnUpdateOptionsEmulatorRealtimeclock(CCmdUI*pCmdUI);
 674.249 +	afx_msg void OnOptionsEmulatorAutohidemenu();
 674.250 +	afx_msg void OnUpdateOptionsEmulatorAutohidemenu(CCmdUI*pCmdUI);
 674.251 +	afx_msg void OnOptionsEmulatorRewindinterval();
 674.252 +	afx_msg void OnOptionsEmulatorSavetypeAutomatic();
 674.253 +	afx_msg void OnUpdateOptionsEmulatorSavetypeAutomatic(CCmdUI*pCmdUI);
 674.254 +	afx_msg void OnOptionsEmulatorSavetypeEeprom();
 674.255 +	afx_msg void OnUpdateOptionsEmulatorSavetypeEeprom(CCmdUI*pCmdUI);
 674.256 +	afx_msg void OnOptionsEmulatorSavetypeSram();
 674.257 +	afx_msg void OnUpdateOptionsEmulatorSavetypeSram(CCmdUI*pCmdUI);
 674.258 +	afx_msg void OnOptionsEmulatorSavetypeFlash();
 674.259 +	afx_msg void OnUpdateOptionsEmulatorSavetypeFlash(CCmdUI*pCmdUI);
 674.260 +	afx_msg void OnOptionsEmulatorSavetypeEepromsensor();
 674.261 +	afx_msg void OnUpdateOptionsEmulatorSavetypeEepromsensor(CCmdUI*pCmdUI);
 674.262 +	afx_msg void OnOptionsEmulatorSavetypeNone();
 674.263 +	afx_msg void OnUpdateOptionsEmulatorSavetypeNone(CCmdUI*pCmdUI);
 674.264 +	afx_msg void OnOptionsEmulatorSavetypeFlash512k();
 674.265 +	afx_msg void OnUpdateOptionsEmulatorSavetypeFlash512k(CCmdUI*pCmdUI);
 674.266 +	afx_msg void OnOptionsEmulatorSavetypeFlash1m();
 674.267 +	afx_msg void OnUpdateOptionsEmulatorSavetypeFlash1m(CCmdUI*pCmdUI);
 674.268 +	afx_msg void OnOptionsEmulatorUseOldGBTiming();
 674.269 +	afx_msg void OnUpdateOptionsEmulatorUseOldGBTiming(CCmdUI*pCmdUI);
 674.270 +	afx_msg void OnOptionsEmulatorUseGBNullInputKludge();
 674.271 +	afx_msg void OnUpdateOptionsEmulatorUseGBNullInputKludge(CCmdUI*pCmdUI);
 674.272 +	afx_msg void OnOptionsEmulatorGBALag();
 674.273 +	afx_msg void OnUpdateOptionsEmulatorGBALag(CCmdUI*pCmdUI);
 674.274 +	afx_msg void OnOptionsEmulatorUsebiosfile();
 674.275 +	afx_msg void OnUpdateOptionsEmulatorUsebiosfile(CCmdUI*pCmdUI);
 674.276 +
 674.277 +	afx_msg void OnOptionsEmulatorSkipbios();
 674.278 +	afx_msg void OnUpdateOptionsEmulatorSkipbios(CCmdUI*pCmdUI);
 674.279 +	afx_msg void OnOptionsEmulatorPngformat();
 674.280 +	afx_msg void OnUpdateOptionsEmulatorPngformat(CCmdUI*pCmdUI);
 674.281 +	afx_msg void OnOptionsEmulatorBmpformat();
 674.282 +	afx_msg void OnUpdateOptionsEmulatorBmpformat(CCmdUI*pCmdUI);
 674.283 +
 674.284 +	afx_msg void OnOptionsSoundDisable();
 674.285 +	afx_msg void OnUpdateOptionsSoundDisable(CCmdUI*pCmdUI);
 674.286 +	afx_msg void OnOptionsSoundMute();
 674.287 +	afx_msg void OnUpdateOptionsSoundMute(CCmdUI*pCmdUI);
 674.288 +	afx_msg void OnOptionsSoundOff();
 674.289 +	afx_msg void OnUpdateOptionsSoundOff(CCmdUI*pCmdUI);
 674.290 +	afx_msg void OnOptionsSoundOn();
 674.291 +	afx_msg void OnUpdateOptionsSoundOn(CCmdUI*pCmdUI);
 674.292 +	afx_msg void OnOptionsSoundUseoldsynchronization();
 674.293 +	afx_msg void OnUpdateOptionsSoundUseoldsynchronization(CCmdUI*pCmdUI);
 674.294 +	afx_msg void OnOptionsSoundEcho();
 674.295 +	afx_msg void OnUpdateOptionsSoundEcho(CCmdUI*pCmdUI);
 674.296 +	afx_msg void OnOptionsSoundLowpassfilter();
 674.297 +	afx_msg void OnUpdateOptionsSoundLowpassfilter(CCmdUI*pCmdUI);
 674.298 +	afx_msg void OnOptionsSoundReversestereo();
 674.299 +	afx_msg void OnUpdateOptionsSoundReversestereo(CCmdUI*pCmdUI);
 674.300 +	afx_msg void OnOptionsSoundMuteFrameAdvance();
 674.301 +	afx_msg void OnUpdateOptionsSoundMuteFrameAdvance(CCmdUI*pCmdUI);
 674.302 +	afx_msg void OnOptionsSoundMuteWhenInactive();
 674.303 +	afx_msg void OnUpdateOptionsSoundMuteWhenInactive(CCmdUI*pCmdUI);
 674.304 +	afx_msg void OnOptionsSound11khz();
 674.305 +	afx_msg void OnUpdateOptionsSound11khz(CCmdUI*pCmdUI);
 674.306 +	afx_msg void OnOptionsSound22khz();
 674.307 +	afx_msg void OnUpdateOptionsSound22khz(CCmdUI*pCmdUI);
 674.308 +	afx_msg void OnOptionsSound44khz();
 674.309 +	afx_msg void OnUpdateOptionsSound44khz(CCmdUI*pCmdUI);
 674.310 +	afx_msg void OnOptionsSoundChannel1();
 674.311 +	afx_msg void OnUpdateOptionsSoundChannel1(CCmdUI*pCmdUI);
 674.312 +	afx_msg void OnOptionsSoundChannel2();
 674.313 +	afx_msg void OnUpdateOptionsSoundChannel2(CCmdUI*pCmdUI);
 674.314 +	afx_msg void OnOptionsSoundChannel3();
 674.315 +	afx_msg void OnUpdateOptionsSoundChannel3(CCmdUI*pCmdUI);
 674.316 +	afx_msg void OnOptionsSoundChannel4();
 674.317 +	afx_msg void OnUpdateOptionsSoundChannel4(CCmdUI*pCmdUI);
 674.318 +	afx_msg void OnOptionsSoundDirectsounda();
 674.319 +	afx_msg void OnUpdateOptionsSoundDirectsounda(CCmdUI*pCmdUI);
 674.320 +	afx_msg void OnOptionsSoundDirectsoundb();
 674.321 +	afx_msg void OnUpdateOptionsSoundDirectsoundb(CCmdUI*pCmdUI);
 674.322 +	afx_msg void OnOptionsGameboyBorder();
 674.323 +	afx_msg void OnUpdateOptionsGameboyBorder(CCmdUI*pCmdUI);
 674.324 +	afx_msg void OnOptionsGameboyPrinter();
 674.325 +	afx_msg void OnUpdateOptionsGameboyPrinter(CCmdUI*pCmdUI);
 674.326 +	afx_msg void OnOptionsGameboyBorderAutomatic();
 674.327 +	afx_msg void OnUpdateOptionsGameboyBorderAutomatic(CCmdUI*pCmdUI);
 674.328 +	afx_msg void OnOptionsGameboyAutomatic();
 674.329 +	afx_msg void OnUpdateOptionsGameboyAutomatic(CCmdUI*pCmdUI);
 674.330 +	afx_msg void OnOptionsGameboyGba();
 674.331 +	afx_msg void OnUpdateOptionsGameboyGba(CCmdUI*pCmdUI);
 674.332 +	afx_msg void OnOptionsGameboyCgb();
 674.333 +	afx_msg void OnUpdateOptionsGameboyCgb(CCmdUI*pCmdUI);
 674.334 +	afx_msg void OnOptionsGameboySgb();
 674.335 +	afx_msg void OnUpdateOptionsGameboySgb(CCmdUI*pCmdUI);
 674.336 +	afx_msg void OnOptionsGameboySgb2();
 674.337 +	afx_msg void OnUpdateOptionsGameboySgb2(CCmdUI*pCmdUI);
 674.338 +	afx_msg void OnOptionsGameboyGb();
 674.339 +	afx_msg void OnUpdateOptionsGameboyGb(CCmdUI*pCmdUI);
 674.340 +	afx_msg void OnOptionsGameboyRealcolors();
 674.341 +	afx_msg void OnUpdateOptionsGameboyRealcolors(CCmdUI*pCmdUI);
 674.342 +	afx_msg void OnOptionsGameboyGameboycolors();
 674.343 +	afx_msg void OnUpdateOptionsGameboyGameboycolors(CCmdUI*pCmdUI);
 674.344 +	afx_msg void OnOptionsGameboyColors();
 674.345 +	afx_msg void OnOptionsFilterDisablemmx();
 674.346 +	afx_msg void OnUpdateOptionsFilterDisablemmx(CCmdUI*pCmdUI);
 674.347 +	afx_msg void OnOptionsLanguageSystem();
 674.348 +	afx_msg void OnUpdateOptionsLanguageSystem(CCmdUI*pCmdUI);
 674.349 +	afx_msg void OnOptionsLanguageEnglish();
 674.350 +	afx_msg void OnUpdateOptionsLanguageEnglish(CCmdUI*pCmdUI);
 674.351 +	afx_msg void OnOptionsLanguageOther();
 674.352 +	afx_msg void OnUpdateOptionsLanguageOther(CCmdUI*pCmdUI);
 674.353 +	afx_msg void OnOptionsJoypadConfigure1();
 674.354 +	afx_msg void OnUpdateOptionsJoypadConfigure1(CCmdUI*pCmdUI);
 674.355 +	afx_msg void OnOptionsJoypadConfigure2();
 674.356 +	afx_msg void OnUpdateOptionsJoypadConfigure2(CCmdUI*pCmdUI);
 674.357 +	afx_msg void OnOptionsJoypadConfigure3();
 674.358 +	afx_msg void OnUpdateOptionsJoypadConfigure3(CCmdUI*pCmdUI);
 674.359 +	afx_msg void OnOptionsJoypadConfigure4();
 674.360 +	afx_msg void OnUpdateOptionsJoypadConfigure4(CCmdUI*pCmdUI);
 674.361 +	afx_msg void OnOptionsJoypadMotionconfigure();
 674.362 +	afx_msg void OnUpdateOptionsJoypadMotionconfigure(CCmdUI*pCmdUI);
 674.363 +	afx_msg void OnOptionsJoypadAllowLeftRight();
 674.364 +	afx_msg void OnUpdateOptionsJoypadAllowLeftRight(CCmdUI*pCmdUI);
 674.365 +	afx_msg void OnOptionsJoypadAutofireAccountForLag();
 674.366 +	afx_msg void OnUpdateOptionsJoypadAutofireAccountForLag(CCmdUI*pCmdUI);
 674.367 +	afx_msg void OnCheatsSearchforcheats();
 674.368 +	afx_msg void OnUpdateCheatsSearchforcheats(CCmdUI*pCmdUI);
 674.369 +	afx_msg void OnCheatsCheatlist();
 674.370 +	afx_msg void OnUpdateCheatsCheatlist(CCmdUI*pCmdUI);
 674.371 +	afx_msg void OnCheatsAutomaticsaveloadcheats();
 674.372 +	afx_msg void OnCheatsPauseDuringCheatSearch();
 674.373 +	afx_msg void OnCheatsLoadcheatlist();
 674.374 +	afx_msg void OnUpdateCheatsLoadcheatlist(CCmdUI*pCmdUI);
 674.375 +	afx_msg void OnCheatsSavecheatlist();
 674.376 +	afx_msg void OnUpdateCheatsSavecheatlist(CCmdUI*pCmdUI);
 674.377 +	afx_msg void OnToolsDisassemble();
 674.378 +	afx_msg void OnUpdateToolsDisassemble(CCmdUI*pCmdUI);
 674.379 +	afx_msg void OnToolsLogging();
 674.380 +	afx_msg void OnUpdateToolsLogging(CCmdUI*pCmdUI);
 674.381 +	afx_msg void OnToolsIoviewer();
 674.382 +	afx_msg void OnUpdateToolsIoviewer(CCmdUI*pCmdUI);
 674.383 +	afx_msg void OnToolsMapview();
 674.384 +	afx_msg void OnUpdateToolsMapview(CCmdUI*pCmdUI);
 674.385 +	afx_msg void OnToolsMemoryviewer();
 674.386 +	afx_msg void OnUpdateToolsMemoryviewer(CCmdUI*pCmdUI);
 674.387 +	afx_msg void OnToolsOamviewer();
 674.388 +	afx_msg void OnUpdateToolsOamviewer(CCmdUI*pCmdUI);
 674.389 +	afx_msg void OnToolsPaletteview();
 674.390 +	afx_msg void OnUpdateToolsPaletteview(CCmdUI*pCmdUI);
 674.391 +	afx_msg void OnToolsTileviewer();
 674.392 +	afx_msg void OnUpdateToolsTileviewer(CCmdUI*pCmdUI);
 674.393 +	afx_msg void OnDebugNextframe();
 674.394 +	afx_msg void OnUpdateDebugNextframe(CCmdUI*pCmdUI);
 674.395 +	afx_msg void OnDebugNextframeAccountForLag();
 674.396 +	afx_msg void OnUpdateDebugNextframeAccountForLag(CCmdUI*pCmdUI);
 674.397 +	afx_msg void OnDebugFramesearch();
 674.398 +	afx_msg void OnUpdateDebugFramesearch(CCmdUI*pCmdUI);
 674.399 +	afx_msg void OnDebugFramesearchPrev();
 674.400 +	afx_msg void OnUpdateDebugFramesearchPrev(CCmdUI*pCmdUI);
 674.401 +	afx_msg void OnDebugFramesearchLoad();
 674.402 +	afx_msg void OnUpdateDebugFramesearchLoad(CCmdUI*pCmdUI);
 674.403 +	afx_msg void OnUpdateCheatsAutomaticsaveloadcheats(CCmdUI*pCmdUI);
 674.404 +	afx_msg void OnUpdateCheatsPauseDuringCheatSearch(CCmdUI*pCmdUI);
 674.405 +	afx_msg void OnToolsFrameCounter();
 674.406 +	afx_msg void OnUpdateToolsFrameCounter(CCmdUI*pCmdUI);
 674.407 +	afx_msg void OnToolsLagCounter();
 674.408 +	afx_msg void OnUpdateToolsLagCounter(CCmdUI*pCmdUI);
 674.409 +	afx_msg void OnToolsExtraCounter();
 674.410 +	afx_msg void OnUpdateToolsExtraCounter(CCmdUI*pCmdUI);
 674.411 +	afx_msg void OnToolsExtraCounterReset();
 674.412 +	afx_msg void OnToolsInputDisplay();
 674.413 +	afx_msg void OnUpdateToolsInputDisplay(CCmdUI*pCmdUI);
 674.414 +	afx_msg void OnToolsDebugGdb();
 674.415 +	afx_msg void OnUpdateToolsDebugGdb(CCmdUI*pCmdUI);
 674.416 +	afx_msg void OnToolsDebugLoadandwait();
 674.417 +	afx_msg void OnUpdateToolsDebugLoadandwait(CCmdUI*pCmdUI);
 674.418 +	afx_msg void OnToolsDebugBreak();
 674.419 +	afx_msg void OnUpdateToolsDebugBreak(CCmdUI*pCmdUI);
 674.420 +	afx_msg void OnToolsDebugDisconnect();
 674.421 +	afx_msg void OnUpdateToolsDebugDisconnect(CCmdUI*pCmdUI);
 674.422 +	afx_msg void OnToolsSoundStartrecording();
 674.423 +	afx_msg void OnToolsSoundStoprecording();
 674.424 +	afx_msg void OnToolsSoundRecording();
 674.425 +	afx_msg void OnUpdateToolsSoundRecording(CCmdUI*pCmdUI);
 674.426 +	afx_msg void OnToolsStartAVIRecording();
 674.427 +	afx_msg void OnToolsPauseAVIRecording();
 674.428 +	afx_msg void OnToolsStopAVIRecording();
 674.429 +	afx_msg void OnToolsAVIRecording();
 674.430 +	afx_msg void OnUpdateToolsAVIRecording(CCmdUI*pCmdUI);
 674.431 +	afx_msg void OnUpdateToolsPauseAVIRecording(CCmdUI*pCmdUI);
 674.432 +
 674.433 +	afx_msg void OnToolsRecordMovie();
 674.434 +	afx_msg void OnUpdateToolsRecordMovie(CCmdUI*pCmdUI);
 674.435 +	afx_msg void OnToolsStopMovie();
 674.436 +	afx_msg void OnUpdateToolsStopMovie(CCmdUI*pCmdUI);
 674.437 +	afx_msg void OnToolsPlayMovie();
 674.438 +	afx_msg void OnUpdateToolsPlayMovie(CCmdUI*pCmdUI);
 674.439 +	afx_msg void OnToolsPlayReadOnly();
 674.440 +	afx_msg void OnUpdateToolsPlayReadOnly(CCmdUI*pCmdUI);
 674.441 +	afx_msg void OnAsscWithSaveState();
 674.442 +	afx_msg void OnUpdateAsscWithSaveState(CCmdUI*pCmdUI);
 674.443 +	afx_msg void OnToolsResumeRecord();
 674.444 +	afx_msg void OnUpdateToolsResumeRecord(CCmdUI*pCmdUI);
 674.445 +	afx_msg void OnToolsPlayRestart();
 674.446 +	afx_msg void OnUpdateToolsPlayRestart(CCmdUI*pCmdUI);
 674.447 +
 674.448 +	afx_msg void OnToolsOnMovieEndPause();
 674.449 +	afx_msg void OnUpdateToolsOnMovieEndPause(CCmdUI*pCmdUI);
 674.450 +	afx_msg void OnToolsOnMovieEndStop();
 674.451 +	afx_msg void OnUpdateToolsOnMovieEndStop(CCmdUI*pCmdUI);
 674.452 +	afx_msg void OnToolsOnMovieEndRestart();
 674.453 +	afx_msg void OnUpdateToolsOnMovieEndRestart(CCmdUI*pCmdUI);
 674.454 +	afx_msg void OnToolsOnMovieEndAppend();
 674.455 +	afx_msg void OnUpdateToolsOnMovieEndAppend(CCmdUI*pCmdUI);
 674.456 +	afx_msg void OnToolsOnMovieEndKeep();
 674.457 +	afx_msg void OnUpdateToolsOnMovieEndKeep(CCmdUI*pCmdUI);
 674.458 +
 674.459 +	afx_msg void OnToolsMovieSetPauseAt();
 674.460 +	afx_msg void OnUpdateToolsSetMoviePauseAt(CCmdUI*pCmdUI);
 674.461 +	afx_msg void OnToolsMovieConvertCurrent();
 674.462 +	afx_msg void OnUpdateToolsMovieConvertCurrent(CCmdUI*pCmdUI);
 674.463 +	afx_msg void OnToolsMovieAutoConvert();
 674.464 +	afx_msg void OnUpdateToolsMovieAutoConvert(CCmdUI*pCmdUI);
 674.465 +	afx_msg void OnToolsMovieFixHeader();
 674.466 +	afx_msg void OnUpdateToolsMovieFixHeader(CCmdUI*pCmdUI);
 674.467 +	afx_msg void OnToolsMovieTruncateAtCurrent();
 674.468 +	afx_msg void OnUpdateToolsMovieTruncateAtCurrent(CCmdUI*pCmdUI);
 674.469 +	afx_msg void OnToolsMovieExtractFromSavegame();
 674.470 +	afx_msg void OnUpdateToolsMovieExtractFromSavegame(CCmdUI*pCmdUI);
 674.471 +
 674.472 +	afx_msg void OnToolsRewind();
 674.473 +	afx_msg void OnUpdateToolsRewind(CCmdUI*pCmdUI);
 674.474 +	afx_msg void OnToolsCustomize();
 674.475 +	afx_msg void OnUpdateToolsCustomize(CCmdUI*pCmdUI);
 674.476 +//	afx_msg void OnToolsCustomizeCommon();
 674.477 +//	afx_msg void OnUpdateToolsCustomizeCommon(CCmdUI*pCmdUI);
 674.478 +	afx_msg void OnToolsCopyVBAWatchSetting();
 674.479 +	afx_msg void OnToolsCopyVBxWatchSetting();
 674.480 +	afx_msg void OnHelpBugreport();
 674.481 +
 674.482 +	afx_msg void OnFileSavegameOldestslot();
 674.483 +	afx_msg void OnUpdateFileSavegameOldestslot(CCmdUI*pCmdUI);
 674.484 +	afx_msg void OnFileLoadgameMostrecent();
 674.485 +	afx_msg void OnUpdateFileLoadgameMostrecent(CCmdUI*pCmdUI);
 674.486 +	afx_msg void OnFileLoadgameAutoloadmostrecent();
 674.487 +	afx_msg void OnUpdateFileLoadgameAutoloadmostrecent(CCmdUI*pCmdUI);
 674.488 +	afx_msg void OnFileLoadgameMakeRecent();
 674.489 +	afx_msg void OnUpdateFileLoadgameMakeRecent(CCmdUI*pCmdUI);
 674.490 +
 674.491 +	afx_msg void OnFileSavegameCurrent();
 674.492 +	afx_msg void OnUpdateFileSavegameCurrent(CCmdUI*pCmdUI);
 674.493 +	afx_msg void OnFileLoadgameCurrent();
 674.494 +	afx_msg void OnUpdateFileLoadgameCurrent(CCmdUI*pCmdUI);
 674.495 +	afx_msg void OnFileLoadgameMakeCurrent();
 674.496 +	afx_msg void OnUpdateFileLoadgameMakeCurrent(CCmdUI*pCmdUI);
 674.497 +	afx_msg void OnFileSavegameMakeCurrent();
 674.498 +	afx_msg void OnUpdateFileSavegameMakeCurrent(CCmdUI*pCmdUI);
 674.499 +	afx_msg void OnFileSavegameIncrementSlot();
 674.500 +	afx_msg void OnUpdateFileSavegameIncrementSlot(CCmdUI*pCmdUI);
 674.501 +	afx_msg void OnFileSavegameDecrementSlot();
 674.502 +	afx_msg void OnUpdateFileSavegameDecrementSlot(CCmdUI*pCmdUI);
 674.503 +	afx_msg void OnFileSlotDisplayModificationTime();
 674.504 +	afx_msg void OnUpdateFileSlotDisplayModificationTime(CCmdUI*pCmdUI);
 674.505 +
 674.506 +	afx_msg void OnOptionsSoundVolume25x();
 674.507 +	afx_msg void OnUpdateOptionsSoundVolume25x(CCmdUI*pCmdUI);
 674.508 +	afx_msg void OnOptionsSoundVolume5x();
 674.509 +	afx_msg void OnUpdateOptionsSoundVolume5x(CCmdUI*pCmdUI);
 674.510 +	afx_msg void OnCheatsDisablecheats();
 674.511 +	afx_msg void OnUpdateCheatsDisablecheats(CCmdUI*pCmdUI);
 674.512 +	afx_msg void OnOptionsVideoFullscreenmaxscale();
 674.513 +	afx_msg void OnOptionsVideoTextdisplayoptions();
 674.514 +	afx_msg void OnUpdateOptionsVideoTextdisplayoptions(CCmdUI *pCmdUI);
 674.515 +
 674.516 +	afx_msg void OnUpdateFileRecentFile(CCmdUI *pCmdUI);
 674.517 +	afx_msg void OnUpdateFileLoadSlot(CCmdUI *pCmdUI);
 674.518 +	afx_msg void OnUpdateFileSaveSlot(CCmdUI *pCmdUI);
 674.519 +	afx_msg void OnUpdateSelectSlot(CCmdUI *pCmdUI);
 674.520 +	afx_msg BOOL OnFileRecentFile(UINT nID);
 674.521 +	afx_msg BOOL OnFileLoadSlot(UINT nID);
 674.522 +	afx_msg BOOL OnFileSaveSlot(UINT nID);
 674.523 +	afx_msg BOOL OnSelectSlot(UINT nID);
 674.524 +
 674.525 +	afx_msg void OnFileLuaOpen();
 674.526 +	afx_msg void OnUpdateFileLuaOpen(CCmdUI *pCmdUI);
 674.527 +	afx_msg void OnFileLuaCloseAll();
 674.528 +	afx_msg void OnUpdateFileLuaCloseAll(CCmdUI *pCmdUI);
 674.529 +	afx_msg void OnFileLuaReload();
 674.530 +	afx_msg void OnFileLuaStop();
 674.531 +	afx_msg void OnFileRamSearch();
 674.532 +	afx_msg void OnUpdateFileRamSearch(CCmdUI *pCmdUI);
 674.533 +	afx_msg void OnFileRamWatch();
 674.534 +	afx_msg void OnUpdateFileRamWatch(CCmdUI *pCmdUI);
 674.535 +	//}}AFX_MSG
 674.536 +	DECLARE_MESSAGE_MAP()
 674.537 +};
 674.538 +
 674.539 +/////////////////////////////////////////////////////////////////////////////
 674.540 +
 674.541 +//{{AFX_INSERT_LOCATION}}
 674.542 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
 674.543 +
 674.544 +#endif // !defined(AFX_MAINWND_H__E8AD28B9_C9FB_4EC2_A2DC_DD1BBA55A275__INCLUDED_)
   675.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   675.2 +++ b/src/win32/MainWndCheats.cpp	Sat Mar 03 10:31:27 2012 -0600
   675.3 @@ -0,0 +1,164 @@
   675.4 +#include "stdafx.h"
   675.5 +#include "resource.h"
   675.6 +#include "MainWnd.h"
   675.7 +#include "FileDlg.h"
   675.8 +#include "GBACheatsDlg.h"
   675.9 +#include "GBCheatsDlg.h"
  675.10 +#include "Reg.h"
  675.11 +#include "WinResUtil.h"
  675.12 +#include "WinMiscUtil.h"
  675.13 +#include "VBA.h"
  675.14 +
  675.15 +#include "../gba/GBA.h"
  675.16 +#include "../gba/GBAGlobals.h"
  675.17 +#include "../gb/gbCheats.h"
  675.18 +
  675.19 +GBACheatSearch gbaDlg;
  675.20 +GBCheatSearch  gbDlg;
  675.21 +
  675.22 +void MainWnd::OnCheatsSearchforcheats()
  675.23 +{
  675.24 +	theApp.winCheckFullscreen();
  675.25 +
  675.26 +	if (theApp.modelessCheatDialogIsOpen)
  675.27 +	{
  675.28 +		gbaDlg.DestroyWindow();
  675.29 +		gbDlg.DestroyWindow();
  675.30 +		theApp.modelessCheatDialogIsOpen = false;
  675.31 +	}
  675.32 +
  675.33 +	if (systemCartridgeType == 0)
  675.34 +	{
  675.35 +		if (theApp.pauseDuringCheatSearch)
  675.36 +		{
  675.37 +			gbaDlg.DoModal();
  675.38 +		}
  675.39 +		else
  675.40 +		{
  675.41 +			if (!theApp.modelessCheatDialogIsOpen)
  675.42 +			{
  675.43 +				theApp.modelessCheatDialogIsOpen = true;
  675.44 +				gbaDlg.Create(GBACheatSearch::IDD, theApp.m_pMainWnd);
  675.45 +			}
  675.46 +		}
  675.47 +	}
  675.48 +	else
  675.49 +	{
  675.50 +		if (theApp.pauseDuringCheatSearch)
  675.51 +		{
  675.52 +			gbDlg.DoModal();
  675.53 +		}
  675.54 +		else
  675.55 +		{
  675.56 +			if (!theApp.modelessCheatDialogIsOpen)
  675.57 +			{
  675.58 +				theApp.modelessCheatDialogIsOpen = true;
  675.59 +				gbDlg.Create(GBCheatSearch::IDD, theApp.m_pMainWnd);
  675.60 +			}
  675.61 +		}
  675.62 +	}
  675.63 +}
  675.64 +
  675.65 +void MainWnd::OnUpdateCheatsSearchforcheats(CCmdUI*pCmdUI)
  675.66 +{
  675.67 +	pCmdUI->Enable(emulating);
  675.68 +}
  675.69 +
  675.70 +void MainWnd::OnCheatsCheatlist()
  675.71 +{
  675.72 +	theApp.winCheckFullscreen();
  675.73 +	if (systemCartridgeType == 0)
  675.74 +	{
  675.75 +		GBACheatList dlg;
  675.76 +		dlg.DoModal();
  675.77 +	}
  675.78 +	else
  675.79 +	{
  675.80 +		GBCheatList dlg;
  675.81 +		dlg.DoModal();
  675.82 +	}
  675.83 +}
  675.84 +
  675.85 +void MainWnd::OnUpdateCheatsCheatlist(CCmdUI*pCmdUI)
  675.86 +{
  675.87 +	pCmdUI->Enable(emulating);
  675.88 +}
  675.89 +
  675.90 +void MainWnd::OnCheatsAutomaticsaveloadcheats()
  675.91 +{
  675.92 +	theApp.autoSaveLoadCheatList = !theApp.autoSaveLoadCheatList;
  675.93 +}
  675.94 +
  675.95 +void MainWnd::OnUpdateCheatsAutomaticsaveloadcheats(CCmdUI*pCmdUI)
  675.96 +{
  675.97 +	pCmdUI->SetCheck(theApp.autoSaveLoadCheatList);
  675.98 +}
  675.99 +
 675.100 +void MainWnd::OnCheatsPauseDuringCheatSearch()
 675.101 +{
 675.102 +	theApp.pauseDuringCheatSearch = !theApp.pauseDuringCheatSearch;
 675.103 +}
 675.104 +
 675.105 +void MainWnd::OnUpdateCheatsPauseDuringCheatSearch(CCmdUI*pCmdUI)
 675.106 +{
 675.107 +	pCmdUI->SetCheck(theApp.pauseDuringCheatSearch);
 675.108 +}
 675.109 +
 675.110 +void MainWnd::OnCheatsLoadcheatlist()
 675.111 +{
 675.112 +	theApp.winCheckFullscreen();
 675.113 +
 675.114 +	LPCTSTR exts[] = { ".clt", NULL };
 675.115 +	CString filter = winResLoadFilter(IDS_FILTER_CHEAT_LIST);
 675.116 +	CString title  = winResLoadString(IDS_SELECT_CHEAT_LIST_NAME);
 675.117 +
 675.118 +	CString cheatName = winGetDestFilename(theApp.gameFilename, IDS_CHEAT_DIR, exts[0]);
 675.119 +	CString cheatDir = winGetDestDir(IDS_CHEAT_DIR);
 675.120 +
 675.121 +	FileDlg dlg(this, cheatName, filter, 0, "CLT", exts, cheatDir, title, false);
 675.122 +
 675.123 +	if (dlg.DoModal() == IDOK)
 675.124 +	{
 675.125 +		winLoadCheatList(dlg.GetPathName());
 675.126 +	}
 675.127 +}
 675.128 +
 675.129 +void MainWnd::OnUpdateCheatsLoadcheatlist(CCmdUI*pCmdUI)
 675.130 +{
 675.131 +	pCmdUI->Enable(emulating);
 675.132 +}
 675.133 +
 675.134 +void MainWnd::OnCheatsSavecheatlist()
 675.135 +{
 675.136 +	theApp.winCheckFullscreen();
 675.137 +
 675.138 +	LPCTSTR exts[] = { ".clt", NULL };
 675.139 +	CString filter = winResLoadFilter(IDS_FILTER_CHEAT_LIST);
 675.140 +	CString title  = winResLoadString(IDS_SELECT_CHEAT_LIST_NAME);
 675.141 +
 675.142 +	CString cheatName = winGetDestFilename(theApp.gameFilename, IDS_CHEAT_DIR, exts[0]);
 675.143 +	CString cheatDir = winGetDestDir(IDS_CHEAT_DIR);
 675.144 +
 675.145 +	FileDlg dlg(this, cheatName, filter, 0, "CLT", exts, cheatDir, title, true);
 675.146 +
 675.147 +	if (dlg.DoModal() == IDOK)
 675.148 +	{
 675.149 +		winSaveCheatList(dlg.GetPathName());
 675.150 +	}
 675.151 +}
 675.152 +
 675.153 +void MainWnd::OnUpdateCheatsSavecheatlist(CCmdUI*pCmdUI)
 675.154 +{
 675.155 +	pCmdUI->Enable(emulating);
 675.156 +}
 675.157 +
 675.158 +void MainWnd::OnCheatsDisablecheats()
 675.159 +{
 675.160 +	cheatsEnabled = !cheatsEnabled;
 675.161 +}
 675.162 +
 675.163 +void MainWnd::OnUpdateCheatsDisablecheats(CCmdUI*pCmdUI)
 675.164 +{
 675.165 +	pCmdUI->SetCheck(!cheatsEnabled);
 675.166 +}
 675.167 +
   676.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   676.2 +++ b/src/win32/MainWndFile.cpp	Sat Mar 03 10:31:27 2012 -0600
   676.3 @@ -0,0 +1,1004 @@
   676.4 +#include "stdafx.h"
   676.5 +#include "resource.h"
   676.6 +#include "MainWnd.h"
   676.7 +#include "ExportGSASnapshot.h"
   676.8 +#include "FileDlg.h"
   676.9 +#include "GSACodeSelect.h"
  676.10 +#include "RomInfo.h"
  676.11 +#include "Reg.h"
  676.12 +#include "WinResUtil.h"
  676.13 +#include "WinMiscUtil.h"
  676.14 +#include "LuaOpenDialog.h"
  676.15 +#include "ram_search.h"
  676.16 +#include "ramwatch.h"
  676.17 +#include "Sound.h"
  676.18 +#include "VBA.h"
  676.19 +
  676.20 +#include "../NLS.h"
  676.21 +#include "../version.h"
  676.22 +#include "../gba/GBA.h"
  676.23 +#include "../gba/GBAGlobals.h"
  676.24 +#include "../gba/EEprom.h"
  676.25 +#include "../gba/GBASound.h"
  676.26 +#include "../gb/GB.h"
  676.27 +#include "../gb/gbGlobals.h"
  676.28 +#include "../common/movie.h"
  676.29 +#include "../common/vbalua.h"
  676.30 +
  676.31 +void MainWnd::OnFileOpen()
  676.32 +{
  676.33 +	theApp.winCheckFullscreen();
  676.34 +	if (winFileOpenSelect(0))
  676.35 +	{
  676.36 +		winFileRun();
  676.37 +	}
  676.38 +}
  676.39 +
  676.40 +void MainWnd::OnFileOpenGBx()
  676.41 +{
  676.42 +	theApp.winCheckFullscreen();
  676.43 +	if (winFileOpenSelect(1))
  676.44 +	{
  676.45 +		winFileRun();
  676.46 +	}
  676.47 +}
  676.48 +
  676.49 +void MainWnd::OnFilePause()
  676.50 +{
  676.51 +	systemSetPause(!theApp.paused);
  676.52 +}
  676.53 +
  676.54 +void MainWnd::OnUpdateFilePause(CCmdUI *pCmdUI)
  676.55 +{
  676.56 +	pCmdUI->SetCheck(theApp.paused);
  676.57 +}
  676.58 +
  676.59 +void MainWnd::OnFileReset()
  676.60 +{
  676.61 +	if (emulating)
  676.62 +	{
  676.63 +		if (VBAMovieGetState() == MOVIE_STATE_PLAY)
  676.64 +		{
  676.65 +			OnToolsPlayRestart();   // HACK: shortcut
  676.66 +		}
  676.67 +		else
  676.68 +		{
  676.69 +			theApp.emulator.emuReset(true);
  676.70 +			systemScreenMessage(winResLoadString(IDS_RESET));
  676.71 +		}
  676.72 +	}
  676.73 +}
  676.74 +
  676.75 +void MainWnd::OnUpdateFileReset(CCmdUI *pCmdUI)
  676.76 +{
  676.77 +	pCmdUI->Enable(emulating);
  676.78 +}
  676.79 +
  676.80 +void MainWnd::OnFileRecentFreeze()
  676.81 +{
  676.82 +	theApp.recentFreeze = !theApp.recentFreeze;
  676.83 +}
  676.84 +
  676.85 +void MainWnd::OnUpdateFileRecentFreeze(CCmdUI *pCmdUI)
  676.86 +{
  676.87 +	pCmdUI->SetCheck(theApp.recentFreeze);
  676.88 +}
  676.89 +
  676.90 +void MainWnd::OnFileRecentReset()
  676.91 +{
  676.92 +	theApp.winCheckFullscreen();
  676.93 +	systemSoundClearBuffer();
  676.94 +	if (MessageBox("Really clear your recent ROMs list?", //winResLoadString(IDS_REALLY_CLEAR),
  676.95 +	               winResLoadString(IDS_CONFIRM_ACTION),
  676.96 +	               MB_YESNO | MB_DEFBUTTON2) == IDNO)
  676.97 +		return;
  676.98 +
  676.99 +	for (int i = 0; i < 10; ++i)
 676.100 +		theApp.recentFiles[i] = "";
 676.101 +}
 676.102 +
 676.103 +BOOL MainWnd::OnFileRecentFile(UINT nID)
 676.104 +{
 676.105 +	if (theApp.recentFiles[(nID & 0xFFFF) - ID_FILE_MRU_FILE1].GetLength())
 676.106 +	{
 676.107 +		theApp.romFilename = theApp.recentFiles[(nID & 0xFFFF) - ID_FILE_MRU_FILE1];
 676.108 +		winFileRun();
 676.109 +	}
 676.110 +	return TRUE;
 676.111 +}
 676.112 +
 676.113 +void MainWnd::OnUpdateFileRecentFile(CCmdUI *pCmdUI)
 676.114 +{
 676.115 +	int fileID = pCmdUI->m_nID - ID_FILE_MRU_FILE1;
 676.116 +
 676.117 +	bool bExist = !theApp.recentFiles[fileID].IsEmpty();
 676.118 +
 676.119 +	if (pCmdUI->m_pMenu != NULL)
 676.120 +	{
 676.121 +		CString p = theApp.recentFiles[fileID];
 676.122 +
 676.123 +		int index = max(p.ReverseFind('/'), max(p.ReverseFind('\\'), p.ReverseFind('|')));
 676.124 +
 676.125 +		if (index != -1)
 676.126 +		{
 676.127 +			p.Delete(0, index + 1);
 676.128 +		}
 676.129 +
 676.130 +		p.Replace("&", "&&");
 676.131 +
 676.132 +		CString number("1&0 - ");
 676.133 +		if (fileID < 9)
 676.134 +			number.Format("&%d - ", fileID + 1);
 676.135 +
 676.136 +		if (p.IsEmpty())
 676.137 +		{
 676.138 +			p	   = "No Recent ROM";
 676.139 +			bExist = false;
 676.140 +		}
 676.141 +
 676.142 +		pCmdUI->SetText(number + p);
 676.143 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
 676.144 +	}
 676.145 +
 676.146 +	pCmdUI->Enable(bExist);
 676.147 +}
 676.148 +
 676.149 +void MainWnd::OnFileExit()
 676.150 +{
 676.151 +	if (AskSave())
 676.152 +		SendMessage(WM_CLOSE);
 676.153 +}
 676.154 +
 676.155 +void MainWnd::OnFileClose()
 676.156 +{
 676.157 +	// save battery file before we change the filename...
 676.158 +	CloseRamWindows();
 676.159 +	winFileClose();
 676.160 +}
 676.161 +
 676.162 +void MainWnd::OnUpdateFileClose(CCmdUI *pCmdUI)
 676.163 +{
 676.164 +	pCmdUI->Enable(emulating);
 676.165 +}
 676.166 +
 676.167 +void MainWnd::OnFileLoad()
 676.168 +{
 676.169 +	theApp.winCheckFullscreen();
 676.170 +
 676.171 +	LPCTSTR exts[] = { ".sgm", NULL };
 676.172 +	CString filter = winResLoadFilter(IDS_FILTER_SGM);
 676.173 +	CString title  = winResLoadString(IDS_SELECT_SAVE_GAME_NAME);
 676.174 +
 676.175 +	CString saveName = winGetDestFilename(theApp.gameFilename, IDS_SAVE_DIR, exts[0]);
 676.176 +	CString saveDir	 = winGetDestDir(IDS_SAVE_DIR);
 676.177 +
 676.178 +	FileDlg dlg(this, saveName, filter, 0, "SGM", exts, saveDir, title, false, true);
 676.179 +
 676.180 +	if (dlg.DoModal() == IDOK)
 676.181 +	{
 676.182 +		bool res = winReadSaveGame(dlg.GetPathName());
 676.183 +
 676.184 +		theApp.rewindCount		= 0;
 676.185 +		theApp.rewindCounter	= 0;
 676.186 +		theApp.rewindSaveNeeded = false;
 676.187 +
 676.188 +		if (res)
 676.189 +		{
 676.190 +			if (VBAMovieActive() && !VBAMovieReadOnly())
 676.191 +			{
 676.192 +				VBAMovieSwitchToRecording();
 676.193 +			}
 676.194 +			systemScreenMessage(winResLoadString(IDS_LOADED_STATE));
 676.195 +		}
 676.196 +	}
 676.197 +}
 676.198 +
 676.199 +void MainWnd::OnUpdateFileLoad(CCmdUI *pCmdUI)
 676.200 +{
 676.201 +	pCmdUI->Enable(emulating);
 676.202 +}
 676.203 +
 676.204 +BOOL MainWnd::OnFileLoadSlot(UINT nID)
 676.205 +{
 676.206 +	nID = nID + 1 - ID_FILE_LOADGAME_SLOT1;
 676.207 +
 676.208 +	CString filename = winGetSavestateFilename(theApp.gameFilename, nID);
 676.209 +
 676.210 +	bool res = winReadSaveGame(filename);
 676.211 +
 676.212 +	// deleting rewinds because you loaded a save state is stupid
 676.213 +///  theApp.rewindCount = 0;
 676.214 +///  theApp.rewindCounter = 0;
 676.215 +///  theApp.rewindSaveNeeded = false;
 676.216 +
 676.217 +	if (res)
 676.218 +	{
 676.219 +		CString format;
 676.220 +		if (VBAMovieActive())
 676.221 +		{
 676.222 +			if (VBAMovieReadOnly())
 676.223 +			{
 676.224 +				format = winResLoadString(IDS_REPLAYED_STATE_N);
 676.225 +			}
 676.226 +			else
 676.227 +			{
 676.228 +				VBAMovieSwitchToRecording();
 676.229 +				format = winResLoadString(IDS_RERECORDED_STATE_N);
 676.230 +			}
 676.231 +		}
 676.232 +		else
 676.233 +		{
 676.234 +			format = winResLoadString(IDS_LOADED_STATE_N);
 676.235 +		}
 676.236 +
 676.237 +		CString buffer;
 676.238 +		buffer.Format(format, nID);
 676.239 +		systemScreenMessage(buffer);
 676.240 +
 676.241 +		int lastSlot = theApp.currentSlot;
 676.242 +
 676.243 +		if (theApp.loadMakesRecent)
 676.244 +		{
 676.245 +			// to update the file's modification date
 676.246 +			SYSTEMTIME st;
 676.247 +			FILETIME   ft;
 676.248 +			GetSystemTime(&st);
 676.249 +			SystemTimeToFileTime(&st, &ft);
 676.250 +			HANDLE fh = CreateFile(filename, 
 676.251 +									GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 
 676.252 +									NULL, 
 676.253 +									OPEN_EXISTING, 
 676.254 +									0, 
 676.255 +									NULL);
 676.256 +			if (fh != INVALID_HANDLE_VALUE)
 676.257 +				SetFileTime(fh, NULL, NULL, &ft);
 676.258 +			CloseHandle(fh);
 676.259 +		}
 676.260 +
 676.261 +		if (theApp.loadMakesCurrent)
 676.262 +			theApp.currentSlot = nID - 1;
 676.263 +		else
 676.264 +			theApp.currentSlot = lastSlot;  // restore value in case the call to OnFileSaveSlot changed it
 676.265 +
 676.266 +		theApp.frameSearching	   = false;
 676.267 +		theApp.frameSearchSkipping = false;
 676.268 +	}
 676.269 +
 676.270 +	return res;
 676.271 +}
 676.272 +
 676.273 +void MainWnd::OnFileSave()
 676.274 +{
 676.275 +	theApp.winCheckFullscreen();
 676.276 +
 676.277 +	LPCTSTR exts[] = { ".sgm", NULL };
 676.278 +	CString filter = winResLoadFilter(IDS_FILTER_SGM);
 676.279 +	CString title  = winResLoadString(IDS_SELECT_SAVE_GAME_NAME);
 676.280 +
 676.281 +	CString saveName = winGetDestFilename(theApp.gameFilename, IDS_SAVE_DIR, exts[0]);
 676.282 +	CString saveDir	 = winGetDestDir(IDS_SAVE_DIR);
 676.283 +
 676.284 +	FileDlg dlg(this, saveName, filter, 0, "SGM", exts, saveDir, title, true);
 676.285 +
 676.286 +	if (dlg.DoModal() == IDOK)
 676.287 +	{
 676.288 +		bool res = winWriteSaveGame(dlg.GetPathName());
 676.289 +		if (res)
 676.290 +			systemScreenMessage(winResLoadString(IDS_WROTE_STATE));
 676.291 +	}
 676.292 +}
 676.293 +
 676.294 +void MainWnd::OnUpdateFileSave(CCmdUI *pCmdUI)
 676.295 +{
 676.296 +	pCmdUI->Enable(emulating);
 676.297 +}
 676.298 +
 676.299 +BOOL MainWnd::OnFileSaveSlot(UINT nID)
 676.300 +{
 676.301 +	nID = nID + 1 - ID_FILE_SAVEGAME_SLOT1;
 676.302 +
 676.303 +	if (theApp.saveMakesCurrent)
 676.304 +		theApp.currentSlot = nID - 1;
 676.305 +
 676.306 +	CString filename = winGetSavestateFilename(theApp.gameFilename, nID);
 676.307 +
 676.308 +	bool res = winWriteSaveGame(filename);
 676.309 +
 676.310 +	CString format = winResLoadString(IDS_WROTE_STATE_N);
 676.311 +	CString buffer;
 676.312 +	buffer.Format(format, nID);
 676.313 +
 676.314 +	systemScreenMessage(buffer);
 676.315 +
 676.316 +	return res;
 676.317 +}
 676.318 +
 676.319 +BOOL MainWnd::OnSelectSlot(UINT nID)
 676.320 +{
 676.321 +	nID -= ID_SELECT_SLOT1;
 676.322 +	theApp.currentSlot = nID;
 676.323 +
 676.324 +	CString buffer;
 676.325 +	buffer.Format("Slot %d selected", nID + 1);
 676.326 +	systemScreenMessage(buffer, 0);
 676.327 +
 676.328 +	return true;
 676.329 +}
 676.330 +
 676.331 +void MainWnd::OnFileImportBatteryfile()
 676.332 +{
 676.333 +	theApp.winCheckFullscreen();
 676.334 +
 676.335 +	LPCTSTR exts[] = { ".sav", NULL };
 676.336 +	CString filter = winResLoadFilter(IDS_FILTER_SAV);
 676.337 +	CString title  = winResLoadString(IDS_SELECT_BATTERY_FILE);
 676.338 +
 676.339 +	CString batteryName = winGetDestFilename(theApp.gameFilename, IDS_BATTERY_DIR, exts[0]);
 676.340 +	CString batteryDir	= winGetDestDir(IDS_BATTERY_DIR);
 676.341 +
 676.342 +	FileDlg dlg(this, batteryName, filter, 0, "SAV", exts, batteryDir, title, false, true);
 676.343 +
 676.344 +	if (dlg.DoModal() == IDCANCEL)
 676.345 +		return;
 676.346 +
 676.347 +	CString str1 = winResLoadString(IDS_SAVE_WILL_BE_LOST);
 676.348 +	CString str2 = winResLoadString(IDS_CONFIRM_ACTION);
 676.349 +
 676.350 +	systemSoundClearBuffer();
 676.351 +	if (MessageBox(str1,
 676.352 +	               str2,
 676.353 +	               MB_OKCANCEL) == IDCANCEL)
 676.354 +		return;
 676.355 +
 676.356 +	bool res = false;
 676.357 +
 676.358 +	res = theApp.emulator.emuReadBattery(dlg.GetPathName());
 676.359 +
 676.360 +	if (!res)
 676.361 +		systemMessage(MSG_CANNOT_OPEN_FILE, "Cannot open file %s", dlg.GetPathName());
 676.362 +	else
 676.363 +	{
 676.364 +		theApp.emulator.emuReset(true);
 676.365 +	}
 676.366 +}
 676.367 +
 676.368 +void MainWnd::OnUpdateFileImportBatteryfile(CCmdUI *pCmdUI)
 676.369 +{
 676.370 +	// we allow this as we allow using cheats during recording
 676.371 +	pCmdUI->Enable(emulating /*&& !VBAMovieActive()*/);
 676.372 +}
 676.373 +
 676.374 +void MainWnd::OnFileImportGamesharkcodefile()
 676.375 +{
 676.376 +	theApp.winCheckFullscreen();
 676.377 +
 676.378 +	LPCTSTR exts[] = { NULL };
 676.379 +	CString filter = systemCartridgeType == 0 ? winResLoadFilter(IDS_FILTER_SPC) : winResLoadFilter(IDS_FILTER_GCF);
 676.380 +	CString title  = winResLoadString(IDS_SELECT_CODE_FILE);
 676.381 +
 676.382 +	FileDlg dlg(this, "", filter, 0, "", exts, "", title, false, true);
 676.383 +
 676.384 +	if (dlg.DoModal() == IDCANCEL)
 676.385 +		return;
 676.386 +
 676.387 +	CString str1 = winResLoadString(IDS_CODES_WILL_BE_LOST);
 676.388 +	CString str2 = winResLoadString(IDS_CONFIRM_ACTION);
 676.389 +
 676.390 +	systemSoundClearBuffer();
 676.391 +	if (MessageBox(str1,
 676.392 +	               str2,
 676.393 +	               MB_OKCANCEL) == IDCANCEL)
 676.394 +		return;
 676.395 +
 676.396 +	CString file = dlg.GetPathName();
 676.397 +	bool	res	 = winImportGSACodeFile(file);
 676.398 +}
 676.399 +
 676.400 +void MainWnd::OnUpdateFileImportGamesharkcodefile(CCmdUI *pCmdUI)
 676.401 +{
 676.402 +	pCmdUI->Enable(emulating /*&& !VBAMovieActive()*/);
 676.403 +}
 676.404 +
 676.405 +void MainWnd::OnFileImportGamesharksnapshot()
 676.406 +{
 676.407 +	theApp.winCheckFullscreen();
 676.408 +
 676.409 +	LPCTSTR exts[] = { NULL };
 676.410 +	CString filter = systemCartridgeType == 1 ? winResLoadFilter(IDS_FILTER_GBS) : winResLoadFilter(IDS_FILTER_SPS);
 676.411 +	CString title  = winResLoadString(IDS_SELECT_SNAPSHOT_FILE);
 676.412 +
 676.413 +	FileDlg dlg(this, "", filter, 0, "", exts, "", title, false, true);
 676.414 +
 676.415 +	if (dlg.DoModal() == IDCANCEL)
 676.416 +		return;
 676.417 +
 676.418 +	CString str1 = winResLoadString(IDS_SAVE_WILL_BE_LOST);
 676.419 +	CString str2 = winResLoadString(IDS_CONFIRM_ACTION);
 676.420 +
 676.421 +	systemSoundClearBuffer();
 676.422 +	if (MessageBox(str1,
 676.423 +	               str2,
 676.424 +	               MB_OKCANCEL) == IDCANCEL)
 676.425 +		return;
 676.426 +
 676.427 +	if (systemCartridgeType == 1)
 676.428 +		gbReadGSASnapshot(dlg.GetPathName());
 676.429 +	else
 676.430 +		CPUReadGSASnapshot(dlg.GetPathName());
 676.431 +}
 676.432 +
 676.433 +void MainWnd::OnUpdateFileImportGamesharksnapshot(CCmdUI *pCmdUI)
 676.434 +{
 676.435 +	pCmdUI->Enable(emulating /*&& !VBAMovieActive()*/);
 676.436 +}
 676.437 +
 676.438 +void MainWnd::OnFileExportBatteryfile()
 676.439 +{
 676.440 +	theApp.winCheckFullscreen();
 676.441 +
 676.442 +	LPCTSTR exts[] = { ".sav", ".dat", NULL };
 676.443 +	CString filter = winResLoadFilter(IDS_FILTER_SAV);
 676.444 +	CString title  = winResLoadString(IDS_SELECT_BATTERY_FILE);
 676.445 +
 676.446 +	CString batteryName = winGetDestFilename(theApp.gameFilename, IDS_BATTERY_DIR, exts[0]);
 676.447 +	CString batteryDir	= winGetDestDir(IDS_BATTERY_DIR);
 676.448 +
 676.449 +	FileDlg dlg(this, batteryName, filter, 1, "SAV", exts, batteryDir, title, true);
 676.450 +
 676.451 +	if (dlg.DoModal() == IDCANCEL)
 676.452 +	{
 676.453 +		return;
 676.454 +	}
 676.455 +
 676.456 +	bool result = false;
 676.457 +
 676.458 +	if (systemCartridgeType == 1)
 676.459 +	{
 676.460 +		result = gbWriteBatteryFile(dlg.GetPathName(), false);
 676.461 +	}
 676.462 +	else
 676.463 +		result = theApp.emulator.emuWriteBattery(dlg.GetPathName());
 676.464 +
 676.465 +	if (!result)
 676.466 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s",
 676.467 +		              dlg.GetPathName());
 676.468 +}
 676.469 +
 676.470 +void MainWnd::OnUpdateFileExportBatteryfile(CCmdUI *pCmdUI)
 676.471 +{
 676.472 +	pCmdUI->Enable(emulating);
 676.473 +}
 676.474 +
 676.475 +void MainWnd::OnFileExportGamesharksnapshot()
 676.476 +{
 676.477 +	theApp.winCheckFullscreen();
 676.478 +	if (eepromInUse)
 676.479 +	{
 676.480 +		systemMessage(IDS_EEPROM_NOT_SUPPORTED, "EEPROM saves cannot be exported");
 676.481 +		return;
 676.482 +	}
 676.483 +
 676.484 +	LPCTSTR exts[] = { ".sps", NULL };
 676.485 +
 676.486 +	CString filter = winResLoadFilter(IDS_FILTER_SPS);
 676.487 +	CString title  = winResLoadString(IDS_SELECT_SNAPSHOT_FILE);
 676.488 +
 676.489 +	CString name = winGetDestFilename(theApp.gameFilename, CString(), exts[0]);
 676.490 +
 676.491 +	FileDlg dlg(this, name, filter, 1, "SPS", exts, "", title, true);
 676.492 +
 676.493 +	if (dlg.DoModal() == IDCANCEL)
 676.494 +		return;
 676.495 +
 676.496 +	char buffer[16];
 676.497 +	strncpy(buffer, (const char *)&rom[0xa0], 12);
 676.498 +	buffer[12] = 0;
 676.499 +
 676.500 +	ExportGSASnapshot dlg2(dlg.GetPathName(), buffer, this);
 676.501 +	dlg2.DoModal();
 676.502 +}
 676.503 +
 676.504 +void MainWnd::OnUpdateFileExportGamesharksnapshot(CCmdUI *pCmdUI)
 676.505 +{
 676.506 +	pCmdUI->Enable(emulating && systemCartridgeType == 0);
 676.507 +}
 676.508 +
 676.509 +void MainWnd::OnFileQuickScreencapture()
 676.510 +{
 676.511 +	extern int32 captureNumber;   // GBAGlobals.cpp
 676.512 +	captureNumber = winScreenCapture(captureNumber);
 676.513 +}
 676.514 +
 676.515 +void MainWnd::OnFileScreencapture()
 676.516 +{
 676.517 +	theApp.winCheckFullscreen();
 676.518 +
 676.519 +	LPCTSTR exts[] = { ".png", ".bmp", NULL };
 676.520 +
 676.521 +	CString filter = winResLoadFilter(IDS_FILTER_PNG);
 676.522 +	CString title  = winResLoadString(IDS_SELECT_CAPTURE_NAME);
 676.523 +
 676.524 +	CString ext;
 676.525 +
 676.526 +	if (theApp.captureFormat != 0)
 676.527 +		ext.Format(".bmp");
 676.528 +	else
 676.529 +		ext.Format(".png");
 676.530 +
 676.531 +	CString captureName = winGetDestFilename(theApp.gameFilename, IDS_CAPTURE_DIR, ext);
 676.532 +	CString captureDir	= winGetDestDir(IDS_CAPTURE_DIR);
 676.533 +
 676.534 +	FileDlg dlg(this,
 676.535 +	            captureName,
 676.536 +	            filter,
 676.537 +	            theApp.captureFormat ? 2 : 1,
 676.538 +	            theApp.captureFormat ? "BMP" : "PNG",
 676.539 +	            exts,
 676.540 +	            captureDir,
 676.541 +	            title,
 676.542 +	            true);
 676.543 +
 676.544 +	if (dlg.DoModal() == IDCANCEL)
 676.545 +		return;
 676.546 +
 676.547 +	if (dlg.getFilterIndex() == 2)
 676.548 +		theApp.emulator.emuWriteBMP(dlg.GetPathName());
 676.549 +	else
 676.550 +		theApp.emulator.emuWritePNG(dlg.GetPathName());
 676.551 +
 676.552 +	systemScreenMessage(winResLoadString(IDS_SCREEN_CAPTURE));
 676.553 +}
 676.554 +
 676.555 +void MainWnd::OnUpdateFileScreencapture(CCmdUI *pCmdUI)
 676.556 +{
 676.557 +	pCmdUI->Enable(emulating);
 676.558 +}
 676.559 +
 676.560 +void MainWnd::OnFileRominformation()
 676.561 +{
 676.562 +	theApp.winCheckFullscreen();
 676.563 +	if (systemCartridgeType == 0)
 676.564 +	{
 676.565 +		RomInfoGBA dlg(rom);
 676.566 +		dlg.DoModal();
 676.567 +	}
 676.568 +	else
 676.569 +	{
 676.570 +		RomInfoGB dlg(gbRom);
 676.571 +		dlg.DoModal();
 676.572 +	}
 676.573 +}
 676.574 +
 676.575 +void MainWnd::OnUpdateFileRominformation(CCmdUI *pCmdUI)
 676.576 +{
 676.577 +	pCmdUI->Enable(emulating);
 676.578 +}
 676.579 +
 676.580 +void MainWnd::OnFileTogglemenu()
 676.581 +{
 676.582 +	theApp.menuToggle = !theApp.menuToggle;
 676.583 +
 676.584 +	if (theApp.menuToggle)
 676.585 +	{
 676.586 +		SetMenu(&theApp.m_menu);
 676.587 +		if (theApp.tripleBuffering)
 676.588 +		{
 676.589 +			if (theApp.display)
 676.590 +				theApp.display->renderMenu();
 676.591 +		}
 676.592 +	}
 676.593 +	else
 676.594 +	{
 676.595 +		SetMenu(NULL);
 676.596 +	}
 676.597 +
 676.598 +	theApp.adjustDestRect();
 676.599 +}
 676.600 +
 676.601 +void MainWnd::OnUpdateFileTogglemenu(CCmdUI *pCmdUI)
 676.602 +{
 676.603 +	pCmdUI->Enable(theApp.videoOption > VIDEO_4X);
 676.604 +}
 676.605 +
 676.606 +void MainWnd::OnFileSavegameOldestslot()
 676.607 +{
 676.608 +	if (!emulating)
 676.609 +		return;
 676.610 +
 676.611 +	CFileStatus status;
 676.612 +	CString		str;
 676.613 +	time_t		time  = -1;
 676.614 +	int			found = -1;
 676.615 +
 676.616 +	for (int i = 0; i < 10; i++)
 676.617 +	{
 676.618 +		if (CFile::GetStatus(winGetSavestateFilename(theApp.gameFilename, i + 1), status))
 676.619 +		{
 676.620 +			if (time - status.m_mtime.GetTime() > 0 || time == -1)
 676.621 +			{
 676.622 +				time  = (time_t)status.m_mtime.GetTime();
 676.623 +				found = i;
 676.624 +			}
 676.625 +		}
 676.626 +		else
 676.627 +		{
 676.628 +			found = i;
 676.629 +			break;
 676.630 +		}
 676.631 +	}
 676.632 +
 676.633 +	OnFileSaveSlot(ID_FILE_SAVEGAME_SLOT1 + found);
 676.634 +}
 676.635 +
 676.636 +void MainWnd::OnUpdateFileSavegameOldestslot(CCmdUI *pCmdUI)
 676.637 +{
 676.638 +	bool enabled = emulating;
 676.639 +	if (pCmdUI->m_pMenu != NULL)
 676.640 +	{
 676.641 +		CFileStatus status;
 676.642 +		time_t		time  = -1;
 676.643 +		int			found = -1;
 676.644 +
 676.645 +		if (emulating)
 676.646 +		{
 676.647 +			for (int i = 0; i < 10; i++)
 676.648 +			{
 676.649 +				if (CFile::GetStatus(winGetSavestateFilename(theApp.gameFilename, i + 1), status))
 676.650 +				{
 676.651 +					if (time - status.m_mtime.GetTime() > 0 || time == -1)
 676.652 +					{
 676.653 +						time  = (time_t)status.m_mtime.GetTime();
 676.654 +						found = i;
 676.655 +					}
 676.656 +				}
 676.657 +				else
 676.658 +				{
 676.659 +					found = i;
 676.660 +					break;
 676.661 +				}
 676.662 +			}
 676.663 +		}
 676.664 +
 676.665 +		CString str;
 676.666 +		enabled = (found != -1);
 676.667 +		if (enabled)
 676.668 +			str.Format("&Oldest Slot (#%d)", found + 1);
 676.669 +		else
 676.670 +			str.Format("&Oldest Slot", found + 1);
 676.671 +
 676.672 +		pCmdUI->SetText(str);
 676.673 +
 676.674 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
 676.675 +	}
 676.676 +
 676.677 +	pCmdUI->Enable(enabled);
 676.678 +}
 676.679 +
 676.680 +void MainWnd::OnFileLoadgameMostrecent()
 676.681 +{
 676.682 +	if (!emulating)
 676.683 +		return;
 676.684 +
 676.685 +	CFileStatus status;
 676.686 +	CString		str;
 676.687 +	time_t		time  = 0;
 676.688 +	int			found = -1;
 676.689 +
 676.690 +	for (int i = 0; i < 10; i++)
 676.691 +	{
 676.692 +		if (CFile::GetStatus(winGetSavestateFilename(theApp.gameFilename, i + 1), status))
 676.693 +		{
 676.694 +			if (status.m_mtime.GetTime() > time)
 676.695 +			{
 676.696 +				time  = (time_t)status.m_mtime.GetTime();
 676.697 +				found = i;
 676.698 +			}
 676.699 +		}
 676.700 +	}
 676.701 +
 676.702 +	if (found != -1)
 676.703 +	{
 676.704 +		OnFileLoadSlot(ID_FILE_LOADGAME_SLOT1 + found);
 676.705 +	}
 676.706 +}
 676.707 +
 676.708 +void MainWnd::OnUpdateFileLoadgameMostrecent(CCmdUI *pCmdUI)
 676.709 +{
 676.710 +	bool enabled = emulating;
 676.711 +	if (pCmdUI->m_pMenu != NULL)
 676.712 +	{
 676.713 +		CFileStatus status;
 676.714 +		int			found = -1;
 676.715 +
 676.716 +		time_t time = 0;
 676.717 +		if (emulating)
 676.718 +		{
 676.719 +			for (int i = 0; i < 10; i++)
 676.720 +			{
 676.721 +				if (CFile::GetStatus(winGetSavestateFilename(theApp.gameFilename, i + 1), status))
 676.722 +				{
 676.723 +					if (status.m_mtime.GetTime() > time)
 676.724 +					{
 676.725 +						time  = (time_t)status.m_mtime.GetTime();
 676.726 +						found = i;
 676.727 +					}
 676.728 +				}
 676.729 +			}
 676.730 +		}
 676.731 +
 676.732 +		CString str;
 676.733 +		enabled = (found != -1);
 676.734 +		if (enabled)
 676.735 +			str.Format("Most &Recent Slot (#%d)", found + 1);
 676.736 +		else
 676.737 +			str.Format("Most &Recent Slot", found + 1);
 676.738 +
 676.739 +		pCmdUI->SetText(str);
 676.740 +
 676.741 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
 676.742 +	}
 676.743 +
 676.744 +	pCmdUI->Enable(enabled);
 676.745 +}
 676.746 +
 676.747 +void MainWnd::OnUpdateFileLoadSlot(CCmdUI *pCmdUI)
 676.748 +{
 676.749 +	int slotID = pCmdUI->m_nID - ID_FILE_LOADGAME_SLOT1 + 1;
 676.750 +
 676.751 +	if (pCmdUI->m_pMenu != NULL)
 676.752 +	{
 676.753 +		pCmdUI->SetText(winGetSavestateMenuString(theApp.gameFilename, slotID));
 676.754 +
 676.755 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
 676.756 +	}
 676.757 +
 676.758 +	pCmdUI->Enable(emulating && winFileExists(winGetSavestateFilename(theApp.gameFilename, slotID)));
 676.759 +}
 676.760 +
 676.761 +void MainWnd::OnUpdateFileSaveSlot(CCmdUI *pCmdUI)
 676.762 +{
 676.763 +	if (pCmdUI->m_pMenu != NULL)
 676.764 +	{
 676.765 +		int slotID = pCmdUI->m_nID - ID_FILE_SAVEGAME_SLOT1 + 1;
 676.766 +
 676.767 +		pCmdUI->SetText(winGetSavestateMenuString(theApp.gameFilename, slotID));
 676.768 +
 676.769 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
 676.770 +	}
 676.771 +
 676.772 +	pCmdUI->Enable(emulating);
 676.773 +}
 676.774 +
 676.775 +void MainWnd::OnUpdateSelectSlot(CCmdUI *pCmdUI)
 676.776 +{
 676.777 +	if (pCmdUI->m_pMenu != NULL)
 676.778 +	{
 676.779 +		int slot = pCmdUI->m_nID - ID_SELECT_SLOT1;
 676.780 +
 676.781 +		pCmdUI->SetText(winGetSavestateMenuString(theApp.gameFilename, slot + 1));
 676.782 +
 676.783 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
 676.784 +
 676.785 +		pCmdUI->SetCheck(slot == theApp.currentSlot);
 676.786 +	}
 676.787 +}
 676.788 +
 676.789 +void MainWnd::OnFileLoadgameAutoloadmostrecent()
 676.790 +{
 676.791 +	theApp.autoLoadMostRecent = !theApp.autoLoadMostRecent;
 676.792 +}
 676.793 +
 676.794 +void MainWnd::OnUpdateFileLoadgameAutoloadmostrecent(CCmdUI *pCmdUI)
 676.795 +{
 676.796 +	pCmdUI->SetCheck(theApp.autoLoadMostRecent);
 676.797 +}
 676.798 +
 676.799 +void MainWnd::OnFileLoadgameMakeRecent()
 676.800 +{
 676.801 +	theApp.loadMakesRecent = !theApp.loadMakesRecent;
 676.802 +}
 676.803 +
 676.804 +void MainWnd::OnUpdateFileLoadgameMakeRecent(CCmdUI *pCmdUI)
 676.805 +{
 676.806 +	pCmdUI->SetCheck(theApp.loadMakesRecent);
 676.807 +}
 676.808 +
 676.809 +void MainWnd::OnFileSavegameCurrent()
 676.810 +{
 676.811 +	OnFileSaveSlot(ID_FILE_SAVEGAME_SLOT1 + theApp.currentSlot);
 676.812 +}
 676.813 +
 676.814 +void MainWnd::OnUpdateFileSavegameCurrent(CCmdUI *pCmdUI)
 676.815 +{
 676.816 +	if (pCmdUI->m_pMenu != NULL)
 676.817 +	{
 676.818 +		int slotID = theApp.currentSlot + 1;
 676.819 +
 676.820 +		CString str;
 676.821 +		str.Format("&Current Slot (#%d)", slotID);
 676.822 +
 676.823 +		pCmdUI->SetText(str);
 676.824 +
 676.825 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
 676.826 +	}
 676.827 +
 676.828 +	pCmdUI->Enable(emulating);
 676.829 +}
 676.830 +
 676.831 +void MainWnd::OnFileLoadgameCurrent()
 676.832 +{
 676.833 +	OnFileLoadSlot(ID_FILE_LOADGAME_SLOT1 + theApp.currentSlot);
 676.834 +}
 676.835 +
 676.836 +void MainWnd::OnUpdateFileLoadgameCurrent(CCmdUI *pCmdUI)
 676.837 +{
 676.838 +	int slotID = theApp.currentSlot + 1;
 676.839 +
 676.840 +	if (pCmdUI->m_pMenu != NULL)
 676.841 +	{
 676.842 +		CString str;
 676.843 +		str.Format("&Current Slot (#%d)", slotID);
 676.844 +
 676.845 +		pCmdUI->SetText(str);
 676.846 +
 676.847 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
 676.848 +	}
 676.849 +
 676.850 +	CFileStatus status;
 676.851 +	pCmdUI->Enable(emulating && CFile::GetStatus(winGetSavestateFilename(theApp.gameFilename, slotID), status));
 676.852 +}
 676.853 +
 676.854 +void MainWnd::OnFileLoadgameMakeCurrent()
 676.855 +{
 676.856 +	theApp.loadMakesCurrent = !theApp.loadMakesCurrent;
 676.857 +}
 676.858 +
 676.859 +void MainWnd::OnUpdateFileLoadgameMakeCurrent(CCmdUI *pCmdUI)
 676.860 +{
 676.861 +	pCmdUI->SetCheck(theApp.loadMakesCurrent);
 676.862 +}
 676.863 +
 676.864 +void MainWnd::OnFileSavegameMakeCurrent()
 676.865 +{
 676.866 +	theApp.saveMakesCurrent = !theApp.saveMakesCurrent;
 676.867 +}
 676.868 +
 676.869 +void MainWnd::OnUpdateFileSavegameMakeCurrent(CCmdUI *pCmdUI)
 676.870 +{
 676.871 +	pCmdUI->SetCheck(theApp.saveMakesCurrent);
 676.872 +}
 676.873 +
 676.874 +void MainWnd::OnFileSavegameIncrementSlot()
 676.875 +{
 676.876 +	theApp.currentSlot = (theApp.currentSlot + 1) % 10;
 676.877 +
 676.878 +	char str [32];
 676.879 +	sprintf(str, "Current Slot: %d", theApp.currentSlot + 1);
 676.880 +	systemScreenMessage(str, 0);
 676.881 +}
 676.882 +
 676.883 +void MainWnd::OnUpdateFileSavegameIncrementSlot(CCmdUI *pCmdUI)
 676.884 +{
 676.885 +	if (pCmdUI->m_pMenu != NULL)
 676.886 +	{
 676.887 +		int slotID = theApp.currentSlot + 1;
 676.888 +
 676.889 +		CString str;
 676.890 +		str.Format("&Increase Current Slot (#%d -> #%d)", slotID, slotID % 10 + 1);
 676.891 +
 676.892 +		pCmdUI->SetText(str);
 676.893 +
 676.894 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
 676.895 +	}
 676.896 +}
 676.897 +
 676.898 +void MainWnd::OnFileSavegameDecrementSlot()
 676.899 +{
 676.900 +	theApp.currentSlot = (theApp.currentSlot + 9) % 10;
 676.901 +
 676.902 +	char str [32];
 676.903 +	sprintf(str, "Current Slot: %d", theApp.currentSlot + 1);
 676.904 +	systemScreenMessage(str, 0);
 676.905 +}
 676.906 +
 676.907 +void MainWnd::OnUpdateFileSavegameDecrementSlot(CCmdUI *pCmdUI)
 676.908 +{
 676.909 +	if (pCmdUI->m_pMenu != NULL)
 676.910 +	{
 676.911 +		int slotID = theApp.currentSlot + 1;
 676.912 +
 676.913 +		CString str;
 676.914 +		str.Format("&Decrease Current Slot (#%d -> #%d)", slotID, (slotID + 8) % 10 + 1);
 676.915 +
 676.916 +		pCmdUI->SetText(str);
 676.917 +
 676.918 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
 676.919 +	}
 676.920 +}
 676.921 +
 676.922 +void MainWnd::OnFileSlotDisplayModificationTime()
 676.923 +{
 676.924 +	theApp.showSlotTime = !theApp.showSlotTime;
 676.925 +}
 676.926 +
 676.927 +void MainWnd::OnUpdateFileSlotDisplayModificationTime(CCmdUI *pCmdUI)
 676.928 +{
 676.929 +	pCmdUI->SetCheck(theApp.showSlotTime);
 676.930 +}
 676.931 +
 676.932 +void MainWnd::OnFileLuaOpen()
 676.933 +{
 676.934 +	theApp.winCheckFullscreen();
 676.935 +
 676.936 +	if (!LuaConsoleHWnd)
 676.937 +	{
 676.938 +		LuaConsoleHWnd = ::CreateDialog(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD_LUA), AfxGetMainWnd()->GetSafeHwnd(), (DLGPROC) DlgLuaScriptDialog);
 676.939 +	}
 676.940 +	else
 676.941 +		::SetForegroundWindow(LuaConsoleHWnd);
 676.942 +}
 676.943 +
 676.944 +void MainWnd::OnUpdateFileLuaOpen(CCmdUI *pCmdUI)
 676.945 +{
 676.946 +	pCmdUI->SetCheck(LuaConsoleHWnd != NULL);
 676.947 +	pCmdUI->Enable(true);
 676.948 +}
 676.949 +
 676.950 +void MainWnd::OnFileLuaCloseAll()
 676.951 +{
 676.952 +	if (LuaConsoleHWnd)
 676.953 +		::PostMessage(LuaConsoleHWnd, WM_CLOSE, 0, 0);
 676.954 +}
 676.955 +
 676.956 +void MainWnd::OnFileLuaReload()
 676.957 +{
 676.958 +	VBAReloadLuaCode();
 676.959 +}
 676.960 +
 676.961 +void MainWnd::OnFileLuaStop()
 676.962 +{
 676.963 +	VBALuaStop();
 676.964 +}
 676.965 +
 676.966 +void MainWnd::OnFileRamSearch()
 676.967 +{
 676.968 +	theApp.winCheckFullscreen();
 676.969 +
 676.970 +	if (!RamSearchHWnd)
 676.971 +	{
 676.972 +		reset_address_info();
 676.973 +		LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 676.974 +		::CreateDialog(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD_RAMSEARCH), AfxGetMainWnd()->GetSafeHwnd(), (DLGPROC) RamSearchProc);
 676.975 +	}
 676.976 +	else
 676.977 +		::SetForegroundWindow(RamSearchHWnd);
 676.978 +}
 676.979 +
 676.980 +void MainWnd::OnUpdateFileRamSearch(CCmdUI *pCmdUI)
 676.981 +{
 676.982 +	pCmdUI->Enable(TRUE);
 676.983 +}
 676.984 +
 676.985 +void MainWnd::OnFileRamWatch()
 676.986 +{
 676.987 +	theApp.winCheckFullscreen();
 676.988 +
 676.989 +	if (!RamWatchHWnd)
 676.990 +	{
 676.991 +		LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 676.992 +		RamWatchHWnd = ::CreateDialog(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD_RAMWATCH), AfxGetMainWnd()->GetSafeHwnd(), (DLGPROC) RamWatchProc);
 676.993 +	}
 676.994 +	else
 676.995 +		::SetForegroundWindow(RamWatchHWnd);
 676.996 +}
 676.997 +
 676.998 +void MainWnd::OnUpdateFileRamWatch(CCmdUI *pCmdUI)
 676.999 +{
676.1000 +	pCmdUI->Enable(TRUE);
676.1001 +}
676.1002 +
676.1003 +void MainWnd::OnUpdateFileLuaCloseAll(CCmdUI *pCmdUI)
676.1004 +{
676.1005 +	pCmdUI->Enable(LuaConsoleHWnd != NULL);
676.1006 +}
676.1007 +
   677.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   677.2 +++ b/src/win32/MainWndHelp.cpp	Sat Mar 03 10:31:27 2012 -0600
   677.3 @@ -0,0 +1,30 @@
   677.4 +#include "stdafx.h"
   677.5 +#include "resource.h"
   677.6 +#include "MainWnd.h"
   677.7 +#include "AboutDialog.h"
   677.8 +#include "BugReport.h"
   677.9 +#include "VBA.h"
  677.10 +
  677.11 +extern int emulating;
  677.12 +
  677.13 +void MainWnd::OnHelpAbout()
  677.14 +{
  677.15 +	theApp.winCheckFullscreen();
  677.16 +	AboutDialog dlg;
  677.17 +
  677.18 +	dlg.DoModal();
  677.19 +}
  677.20 +
  677.21 +void MainWnd::OnHelpFaq()
  677.22 +{
  677.23 +	::ShellExecute(0, _T("open"), "http://vba.ngemu.com/faq.shtml",
  677.24 +	               0, 0, SW_SHOWNORMAL);
  677.25 +}
  677.26 +
  677.27 +void MainWnd::OnHelpBugreport()
  677.28 +{
  677.29 +	BugReport dlg(theApp.m_pMainWnd);
  677.30 +
  677.31 +	dlg.DoModal();
  677.32 +}
  677.33 +
   678.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   678.2 +++ b/src/win32/MainWndOptions.cpp	Sat Mar 03 10:31:27 2012 -0600
   678.3 @@ -0,0 +1,2309 @@
   678.4 +#include "stdafx.h"
   678.5 +#include "resource.h"
   678.6 +#include "MainWnd.h"
   678.7 +#include "Associate.h"
   678.8 +#include "Directories.h"
   678.9 +#include "FileDlg.h"
  678.10 +#include "GBColorDlg.h"
  678.11 +#include "Joypad.h"
  678.12 +#include "MaxScale.h"
  678.13 +#include "ModeConfirm.h"
  678.14 +#include "Reg.h"
  678.15 +#include "RewindInterval.h"
  678.16 +#include "Throttle.h"
  678.17 +#include "TextOptions.h"
  678.18 +#include "WinResUtil.h"
  678.19 +#include "VBA.h"
  678.20 +
  678.21 +#include "../gba/GBA.h"
  678.22 +#include "../gba/GBAGlobals.h"
  678.23 +#include "../gba/Flash.h"
  678.24 +#include "../gba/GBASound.h"
  678.25 +#include "../gba/agbprint.h"
  678.26 +#include "../gb/GB.h"
  678.27 +#include "../gb/gbGlobals.h"
  678.28 +#include "../gb/gbPrinter.h"
  678.29 +#include "../common/inputGlobal.h"
  678.30 +#include "../common/movie.h"
  678.31 +#include "../version.h"
  678.32 +
  678.33 +extern int emulating;
  678.34 +
  678.35 +#define VBA_CONFIRM_MODE WM_APP + 100
  678.36 +
  678.37 +void MainWnd::OnOptionsFrameskipThrottleNothrottle()
  678.38 +{
  678.39 +	systemSetThrottle(0);
  678.40 +}
  678.41 +
  678.42 +void MainWnd::OnUpdateOptionsFrameskipThrottleNothrottle(CCmdUI*pCmdUI)
  678.43 +{
  678.44 +	pCmdUI->SetCheck(theApp.throttle == 0);
  678.45 +}
  678.46 +
  678.47 +void MainWnd::OnOptionsFrameskipThrottle6()
  678.48 +{
  678.49 +	systemSetThrottle(6);
  678.50 +}
  678.51 +
  678.52 +void MainWnd::OnUpdateOptionsFrameskipThrottle6(CCmdUI*pCmdUI)
  678.53 +{
  678.54 +	pCmdUI->SetCheck(theApp.throttle == 6);
  678.55 +}
  678.56 +
  678.57 +void MainWnd::OnOptionsFrameskipThrottle15()
  678.58 +{
  678.59 +	systemSetThrottle(15);
  678.60 +}
  678.61 +
  678.62 +void MainWnd::OnUpdateOptionsFrameskipThrottle15(CCmdUI*pCmdUI)
  678.63 +{
  678.64 +	pCmdUI->SetCheck(theApp.throttle == 15);
  678.65 +}
  678.66 +
  678.67 +void MainWnd::OnOptionsFrameskipThrottle25()
  678.68 +{
  678.69 +	systemSetThrottle(25);
  678.70 +}
  678.71 +
  678.72 +void MainWnd::OnUpdateOptionsFrameskipThrottle25(CCmdUI*pCmdUI)
  678.73 +{
  678.74 +	pCmdUI->SetCheck(theApp.throttle == 25);
  678.75 +}
  678.76 +
  678.77 +void MainWnd::OnOptionsFrameskipThrottle50()
  678.78 +{
  678.79 +	systemSetThrottle(50);
  678.80 +}
  678.81 +
  678.82 +void MainWnd::OnUpdateOptionsFrameskipThrottle50(CCmdUI*pCmdUI)
  678.83 +{
  678.84 +	pCmdUI->SetCheck(theApp.throttle == 50);
  678.85 +}
  678.86 +
  678.87 +void MainWnd::OnOptionsFrameskipThrottle75()
  678.88 +{
  678.89 +	systemSetThrottle(75);
  678.90 +}
  678.91 +
  678.92 +void MainWnd::OnUpdateOptionsFrameskipThrottle75(CCmdUI*pCmdUI)
  678.93 +{
  678.94 +	pCmdUI->SetCheck(theApp.throttle == 75);
  678.95 +}
  678.96 +
  678.97 +void MainWnd::OnOptionsFrameskipThrottle100()
  678.98 +{
  678.99 +	systemSetThrottle(100);
 678.100 +}
 678.101 +
 678.102 +void MainWnd::OnUpdateOptionsFrameskipThrottle100(CCmdUI*pCmdUI)
 678.103 +{
 678.104 +	pCmdUI->SetCheck(theApp.throttle == 100);
 678.105 +}
 678.106 +
 678.107 +void MainWnd::OnOptionsFrameskipThrottle125()
 678.108 +{
 678.109 +	systemSetThrottle(125);
 678.110 +}
 678.111 +
 678.112 +void MainWnd::OnUpdateOptionsFrameskipThrottle125(CCmdUI*pCmdUI)
 678.113 +{
 678.114 +	pCmdUI->SetCheck(theApp.throttle == 125);
 678.115 +}
 678.116 +
 678.117 +void MainWnd::OnOptionsFrameskipThrottle150()
 678.118 +{
 678.119 +	systemSetThrottle(150);
 678.120 +}
 678.121 +
 678.122 +void MainWnd::OnUpdateOptionsFrameskipThrottle150(CCmdUI*pCmdUI)
 678.123 +{
 678.124 +	pCmdUI->SetCheck(theApp.throttle == 150);
 678.125 +}
 678.126 +
 678.127 +void MainWnd::OnOptionsFrameskipThrottle200()
 678.128 +{
 678.129 +	systemSetThrottle(200);
 678.130 +}
 678.131 +
 678.132 +void MainWnd::OnUpdateOptionsFrameskipThrottle200(CCmdUI*pCmdUI)
 678.133 +{
 678.134 +	pCmdUI->SetCheck(theApp.throttle == 200);
 678.135 +}
 678.136 +
 678.137 +void MainWnd::OnOptionsFrameskipThrottle300()
 678.138 +{
 678.139 +	systemSetThrottle(300);
 678.140 +}
 678.141 +
 678.142 +void MainWnd::OnUpdateOptionsFrameskipThrottle300(CCmdUI*pCmdUI)
 678.143 +{
 678.144 +	pCmdUI->SetCheck(theApp.throttle == 300);
 678.145 +}
 678.146 +
 678.147 +void MainWnd::OnOptionsFrameskipThrottle400()
 678.148 +{
 678.149 +	systemSetThrottle(400);
 678.150 +}
 678.151 +
 678.152 +void MainWnd::OnUpdateOptionsFrameskipThrottle400(CCmdUI*pCmdUI)
 678.153 +{
 678.154 +	pCmdUI->SetCheck(theApp.throttle == 400);
 678.155 +}
 678.156 +
 678.157 +void MainWnd::OnOptionsFrameskipThrottle600()
 678.158 +{
 678.159 +	systemSetThrottle(600);
 678.160 +}
 678.161 +
 678.162 +void MainWnd::OnUpdateOptionsFrameskipThrottle600(CCmdUI*pCmdUI)
 678.163 +{
 678.164 +	pCmdUI->SetCheck(theApp.throttle == 600);
 678.165 +}
 678.166 +
 678.167 +void MainWnd::OnOptionsFrameskipThrottle1000()
 678.168 +{
 678.169 +	systemSetThrottle(1000);
 678.170 +}
 678.171 +
 678.172 +void MainWnd::OnUpdateOptionsFrameskipThrottle1000(CCmdUI*pCmdUI)
 678.173 +{
 678.174 +	pCmdUI->SetCheck(theApp.throttle == 1000);
 678.175 +}
 678.176 +
 678.177 +void MainWnd::OnOptionsFrameskipThrottleOther()
 678.178 +{
 678.179 +	Throttle dlg;
 678.180 +	int      v = dlg.DoModal();
 678.181 +	if (v)
 678.182 +		systemSetThrottle(v);
 678.183 +}
 678.184 +
 678.185 +void MainWnd::OnUpdateOptionsFrameskipThrottleOther(CCmdUI*pCmdUI)
 678.186 +{
 678.187 +}
 678.188 +
 678.189 +void MainWnd::OnOptionsFrameskipThrottleIncrease()
 678.190 +{
 678.191 +	systemIncreaseThrottle();
 678.192 +}
 678.193 +
 678.194 +void MainWnd::OnUpdateOptionsFrameskipThrottleIncrease(CCmdUI*pCmdUI)
 678.195 +{
 678.196 +}
 678.197 +
 678.198 +void MainWnd::OnOptionsFrameskipThrottleDecrease()
 678.199 +{
 678.200 +	systemDecreaseThrottle();
 678.201 +}
 678.202 +
 678.203 +void MainWnd::OnUpdateOptionsFrameskipThrottleDecrease(CCmdUI*pCmdUI)
 678.204 +{
 678.205 +}
 678.206 +
 678.207 +/*
 678.208 +   void MainWnd::OnOptionsFrameskipAutomatic()
 678.209 +   {
 678.210 +   theApp.autoFrameSkip = !theApp.autoFrameSkip;
 678.211 +   if(!theApp.autoFrameSkip && emulating)
 678.212 +    theApp.updateFrameSkip();
 678.213 +   }
 678.214 +
 678.215 +   void MainWnd::OnUpdateOptionsFrameskipAutomatic(CCmdUI* pCmdUI)
 678.216 +   {
 678.217 +   pCmdUI->SetCheck(theApp.autoFrameSkip);
 678.218 +   }
 678.219 + */
 678.220 +
 678.221 +void MainWnd::OnOptionsFrameskipAccuratePitch()
 678.222 +{
 678.223 +	theApp.accuratePitchThrottle = true;
 678.224 +}
 678.225 +
 678.226 +void MainWnd::OnUpdateOptionsFrameskipAccuratePitch(CCmdUI*pCmdUI)
 678.227 +{
 678.228 +	pCmdUI->SetCheck(theApp.accuratePitchThrottle);
 678.229 +	pCmdUI->Enable(!soundOffFlag && synchronize);
 678.230 +}
 678.231 +
 678.232 +void MainWnd::OnOptionsFrameskipAccurateSpeed()
 678.233 +{
 678.234 +	theApp.accuratePitchThrottle = false;
 678.235 +}
 678.236 +
 678.237 +void MainWnd::OnUpdateOptionsFrameskipAccurateSpeed(CCmdUI*pCmdUI)
 678.238 +{
 678.239 +	pCmdUI->SetCheck(!theApp.accuratePitchThrottle);
 678.240 +	pCmdUI->Enable(!soundOffFlag && synchronize);
 678.241 +}
 678.242 +
 678.243 +BOOL MainWnd::OnOptionsFrameskip(UINT nID)
 678.244 +{
 678.245 +	switch (nID)
 678.246 +	{
 678.247 +	case ID_OPTIONS_VIDEO_FRAMESKIP_0:
 678.248 +	case ID_OPTIONS_VIDEO_FRAMESKIP_1:
 678.249 +	case ID_OPTIONS_VIDEO_FRAMESKIP_2:
 678.250 +	case ID_OPTIONS_VIDEO_FRAMESKIP_3:
 678.251 +	case ID_OPTIONS_VIDEO_FRAMESKIP_4:
 678.252 +	case ID_OPTIONS_VIDEO_FRAMESKIP_5:
 678.253 +	case ID_OPTIONS_VIDEO_FRAMESKIP_6:
 678.254 +	case ID_OPTIONS_VIDEO_FRAMESKIP_7:
 678.255 +	case ID_OPTIONS_VIDEO_FRAMESKIP_8:
 678.256 +	case ID_OPTIONS_VIDEO_FRAMESKIP_9:
 678.257 +		if (systemCartridgeType == 0)
 678.258 +		{
 678.259 +			frameSkip = nID - ID_OPTIONS_VIDEO_FRAMESKIP_0;
 678.260 +		}
 678.261 +		else
 678.262 +		{
 678.263 +			gbFrameSkip = nID - ID_OPTIONS_VIDEO_FRAMESKIP_0;
 678.264 +		}
 678.265 +		if (emulating)
 678.266 +			theApp.updateFrameSkip();
 678.267 +		return TRUE;
 678.268 +		break;
 678.269 +	}
 678.270 +	return FALSE;
 678.271 +}
 678.272 +
 678.273 +void MainWnd::OnUpdateOptionsVideoFrameskip0(CCmdUI*pCmdUI)
 678.274 +{
 678.275 +	pCmdUI->SetCheck(systemCartridgeType == 0 ? frameSkip == 0 : gbFrameSkip == 0);
 678.276 +}
 678.277 +
 678.278 +void MainWnd::OnUpdateOptionsVideoFrameskip1(CCmdUI*pCmdUI)
 678.279 +{
 678.280 +	pCmdUI->SetCheck(systemCartridgeType == 0 ? frameSkip == 1 : gbFrameSkip == 1);
 678.281 +}
 678.282 +
 678.283 +void MainWnd::OnUpdateOptionsVideoFrameskip2(CCmdUI*pCmdUI)
 678.284 +{
 678.285 +	pCmdUI->SetCheck(systemCartridgeType == 0 ? frameSkip == 2 : gbFrameSkip == 2);
 678.286 +}
 678.287 +
 678.288 +void MainWnd::OnUpdateOptionsVideoFrameskip3(CCmdUI*pCmdUI)
 678.289 +{
 678.290 +	pCmdUI->SetCheck(systemCartridgeType == 0 ? frameSkip == 3 : gbFrameSkip == 3);
 678.291 +}
 678.292 +
 678.293 +void MainWnd::OnUpdateOptionsVideoFrameskip4(CCmdUI*pCmdUI)
 678.294 +{
 678.295 +	pCmdUI->SetCheck(systemCartridgeType == 0 ? frameSkip == 4 : gbFrameSkip == 4);
 678.296 +}
 678.297 +
 678.298 +void MainWnd::OnUpdateOptionsVideoFrameskip5(CCmdUI*pCmdUI)
 678.299 +{
 678.300 +	pCmdUI->SetCheck(systemCartridgeType == 0 ? frameSkip == 5 : gbFrameSkip == 5);
 678.301 +}
 678.302 +
 678.303 +void MainWnd::OnUpdateOptionsVideoFrameskip6(CCmdUI*pCmdUI)
 678.304 +{
 678.305 +	pCmdUI->SetCheck(systemCartridgeType == 0 ? frameSkip == 6 : gbFrameSkip == 6);
 678.306 +}
 678.307 +
 678.308 +void MainWnd::OnUpdateOptionsVideoFrameskip7(CCmdUI*pCmdUI)
 678.309 +{
 678.310 +	pCmdUI->SetCheck(systemCartridgeType == 0 ? frameSkip == 7 : gbFrameSkip == 7);
 678.311 +}
 678.312 +
 678.313 +void MainWnd::OnUpdateOptionsVideoFrameskip8(CCmdUI*pCmdUI)
 678.314 +{
 678.315 +	pCmdUI->SetCheck(systemCartridgeType == 0 ? frameSkip == 8 : gbFrameSkip == 8);
 678.316 +}
 678.317 +
 678.318 +void MainWnd::OnUpdateOptionsVideoFrameskip9(CCmdUI*pCmdUI)
 678.319 +{
 678.320 +	pCmdUI->SetCheck(systemCartridgeType == 0 ? frameSkip == 9 : gbFrameSkip == 9);
 678.321 +}
 678.322 +
 678.323 +void MainWnd::OnOptionsVideoVsync()
 678.324 +{
 678.325 +	theApp.vsync = !theApp.vsync;
 678.326 +}
 678.327 +
 678.328 +void MainWnd::OnUpdateOptionsVideoVsync(CCmdUI*pCmdUI)
 678.329 +{
 678.330 +	pCmdUI->SetCheck(theApp.vsync);
 678.331 +}
 678.332 +
 678.333 +void MainWnd::OnUpdateOptionsVideoX1(CCmdUI*pCmdUI)
 678.334 +{
 678.335 +	pCmdUI->SetCheck(theApp.videoOption == VIDEO_1X);
 678.336 +}
 678.337 +
 678.338 +void MainWnd::OnUpdateOptionsVideoX2(CCmdUI*pCmdUI)
 678.339 +{
 678.340 +	pCmdUI->SetCheck(theApp.videoOption == VIDEO_2X);
 678.341 +}
 678.342 +
 678.343 +void MainWnd::OnUpdateOptionsVideoX3(CCmdUI*pCmdUI)
 678.344 +{
 678.345 +	pCmdUI->SetCheck(theApp.videoOption == VIDEO_3X);
 678.346 +}
 678.347 +
 678.348 +void MainWnd::OnUpdateOptionsVideoX4(CCmdUI*pCmdUI)
 678.349 +{
 678.350 +	pCmdUI->SetCheck(theApp.videoOption == VIDEO_4X);
 678.351 +}
 678.352 +
 678.353 +void MainWnd::OnUpdateOptionsVideoFullscreen320x240(CCmdUI*pCmdUI)
 678.354 +{
 678.355 +	pCmdUI->Enable(theApp.mode320Available);
 678.356 +	pCmdUI->SetCheck(theApp.videoOption == VIDEO_320x240);
 678.357 +}
 678.358 +
 678.359 +void MainWnd::OnUpdateOptionsVideoFullscreen640x480(CCmdUI*pCmdUI)
 678.360 +{
 678.361 +	pCmdUI->Enable(theApp.mode640Available);
 678.362 +	pCmdUI->SetCheck(theApp.videoOption == VIDEO_640x480);
 678.363 +}
 678.364 +
 678.365 +void MainWnd::OnUpdateOptionsVideoFullscreen800x600(CCmdUI*pCmdUI)
 678.366 +{
 678.367 +	pCmdUI->Enable(theApp.mode800Available);
 678.368 +	pCmdUI->SetCheck(theApp.videoOption == VIDEO_800x600);
 678.369 +}
 678.370 +
 678.371 +BOOL MainWnd::OnOptionVideoSize(UINT nID)
 678.372 +{
 678.373 +	theApp.updateVideoSize(nID);
 678.374 +	theApp.m_pMainWnd->PostMessage(VBA_CONFIRM_MODE);
 678.375 +	return TRUE;
 678.376 +}
 678.377 +
 678.378 +void MainWnd::OnOptionsVideoFullscreen320x240()
 678.379 +{
 678.380 +	OnOptionVideoSize(ID_OPTIONS_VIDEO_FULLSCREEN320X240);
 678.381 +}
 678.382 +
 678.383 +void MainWnd::OnOptionsVideoFullscreen640x480()
 678.384 +{
 678.385 +	OnOptionVideoSize(ID_OPTIONS_VIDEO_FULLSCREEN640X480);
 678.386 +}
 678.387 +
 678.388 +void MainWnd::OnOptionsVideoFullscreen800x600()
 678.389 +{
 678.390 +	OnOptionVideoSize(ID_OPTIONS_VIDEO_FULLSCREEN800X600);
 678.391 +}
 678.392 +
 678.393 +void MainWnd::OnOptionsVideoFullscreen()
 678.394 +{
 678.395 +	theApp.winCheckFullscreen();
 678.396 +	GUID *pGUID = NULL;
 678.397 +	int   size  = theApp.display->selectFullScreenMode(&pGUID);
 678.398 +	if (size != -1)
 678.399 +	{
 678.400 +		int width      = (size >> 12) & 4095;
 678.401 +		int height     = (size & 4095);
 678.402 +		int colorDepth = (size >> 24);
 678.403 +		if (width != theApp.fsWidth ||
 678.404 +		    height != theApp.fsHeight ||
 678.405 +		    colorDepth != theApp.fsColorDepth ||
 678.406 +		    pGUID != theApp.pVideoDriverGUID ||
 678.407 +		    theApp.videoOption != VIDEO_OTHER)
 678.408 +		{
 678.409 +			theApp.fsForceChange    = true;
 678.410 +			theApp.fsWidth          = width;
 678.411 +			theApp.fsHeight         = height;
 678.412 +			theApp.fsColorDepth     = colorDepth;
 678.413 +			theApp.pVideoDriverGUID = pGUID;
 678.414 +			if (pGUID)
 678.415 +			{
 678.416 +				theApp.videoDriverGUID = *pGUID;
 678.417 +				regSetDwordValue("defaultVideoDriver", FALSE);
 678.418 +				regSetBinaryValue("videoDriverGUID",
 678.419 +				                  (char *)pGUID, sizeof(GUID));
 678.420 +			}
 678.421 +			else
 678.422 +			{
 678.423 +				regSetDwordValue("defaultVideoDriver", TRUE);
 678.424 +			}
 678.425 +			theApp.updateVideoSize(ID_OPTIONS_VIDEO_FULLSCREEN);
 678.426 +			theApp.m_pMainWnd->PostMessage(VBA_CONFIRM_MODE);
 678.427 +		}
 678.428 +	}
 678.429 +}
 678.430 +
 678.431 +void MainWnd::OnUpdateOptionsVideoFullscreen(CCmdUI*pCmdUI)
 678.432 +{
 678.433 +	pCmdUI->SetCheck(theApp.videoOption == VIDEO_OTHER);
 678.434 +}
 678.435 +
 678.436 +void MainWnd::OnOptionsVideoDisablesfx()
 678.437 +{
 678.438 +	cpuDisableSfx = !cpuDisableSfx;
 678.439 +	if (emulating && systemCartridgeType == 0)
 678.440 +		CPUUpdateRender();
 678.441 +}
 678.442 +
 678.443 +void MainWnd::OnUpdateOptionsVideoDisablesfx(CCmdUI*pCmdUI)
 678.444 +{
 678.445 +	pCmdUI->SetCheck(cpuDisableSfx);
 678.446 +}
 678.447 +
 678.448 +void MainWnd::OnOptionsVideoFullscreenstretchtofit()
 678.449 +{
 678.450 +	theApp.fullScreenStretch = !theApp.fullScreenStretch;
 678.451 +	theApp.updateWindowSize(theApp.videoOption);
 678.452 +	if (theApp.display)
 678.453 +		theApp.display->clear();
 678.454 +}
 678.455 +
 678.456 +void MainWnd::OnUpdateOptionsVideoFullscreenstretchtofit(CCmdUI*pCmdUI)
 678.457 +{
 678.458 +	pCmdUI->SetCheck(theApp.fullScreenStretch);
 678.459 +}
 678.460 +
 678.461 +BOOL MainWnd::OnVideoLayer(UINT nID)
 678.462 +{
 678.463 +	layerSettings ^= 0x0100 << ((nID & 0xFFFF) - ID_OPTIONS_VIDEO_LAYERS_BG0);
 678.464 +	layerEnable = DISPCNT & layerSettings;
 678.465 +	CPUUpdateRenderBuffers(false);
 678.466 +	return TRUE;
 678.467 +}
 678.468 +
 678.469 +void MainWnd::OnUpdateVideoLayer(CCmdUI *pCmdUI)
 678.470 +{
 678.471 +	pCmdUI->SetCheck((layerSettings >> (8 + pCmdUI->m_nID - ID_OPTIONS_VIDEO_LAYERS_BG0)) & 1);
 678.472 +	switch (pCmdUI->m_nID)
 678.473 +	{
 678.474 +	case ID_OPTIONS_VIDEO_LAYERS_BG1:
 678.475 +	case ID_OPTIONS_VIDEO_LAYERS_BG2:
 678.476 +	case ID_OPTIONS_VIDEO_LAYERS_BG3:
 678.477 +	case ID_OPTIONS_VIDEO_LAYERS_WIN1:
 678.478 +	case ID_OPTIONS_VIDEO_LAYERS_OBJWIN:
 678.479 +		pCmdUI->Enable(systemCartridgeType == 0);
 678.480 +		break;
 678.481 +	}
 678.482 +}
 678.483 +
 678.484 +void MainWnd::OnOptionsVideoRendermethodGdi()
 678.485 +{
 678.486 +	theApp.renderMethod = GDI;
 678.487 +	theApp.updateRenderMethod(false);
 678.488 +}
 678.489 +
 678.490 +void MainWnd::OnUpdateOptionsVideoRendermethodGdi(CCmdUI*pCmdUI)
 678.491 +{
 678.492 +	pCmdUI->SetCheck(theApp.renderMethod == GDI);
 678.493 +}
 678.494 +
 678.495 +void MainWnd::OnOptionsVideoRendermethodDirectdraw()
 678.496 +{
 678.497 +	theApp.renderMethod = DIRECT_DRAW;
 678.498 +	theApp.updateRenderMethod(false);
 678.499 +}
 678.500 +
 678.501 +void MainWnd::OnUpdateOptionsVideoRendermethodDirectdraw(CCmdUI*pCmdUI)
 678.502 +{
 678.503 +	pCmdUI->SetCheck(theApp.renderMethod == DIRECT_DRAW);
 678.504 +}
 678.505 +
 678.506 +void MainWnd::OnOptionsVideoRendermethodDirect3d()
 678.507 +{
 678.508 +	theApp.renderMethod = DIRECT_3D;
 678.509 +	theApp.updateRenderMethod(false);
 678.510 +}
 678.511 +
 678.512 +void MainWnd::OnUpdateOptionsVideoRendermethodDirect3d(CCmdUI*pCmdUI)
 678.513 +{
 678.514 +	pCmdUI->SetCheck(theApp.renderMethod == DIRECT_3D);
 678.515 +}
 678.516 +
 678.517 +void MainWnd::OnOptionsVideoRendermethodOpengl()
 678.518 +{
 678.519 +	theApp.renderMethod = OPENGL;
 678.520 +	theApp.updateRenderMethod(false);
 678.521 +}
 678.522 +
 678.523 +void MainWnd::OnUpdateOptionsVideoRendermethodOpengl(CCmdUI*pCmdUI)
 678.524 +{
 678.525 +	pCmdUI->SetCheck(theApp.renderMethod == OPENGL);
 678.526 +}
 678.527 +
 678.528 +void MainWnd::OnOptionsVideoTriplebuffering()
 678.529 +{
 678.530 +	theApp.tripleBuffering = !theApp.tripleBuffering;
 678.531 +}
 678.532 +
 678.533 +void MainWnd::OnUpdateOptionsVideoTriplebuffering(CCmdUI*pCmdUI)
 678.534 +{
 678.535 +	pCmdUI->SetCheck(theApp.tripleBuffering);
 678.536 +}
 678.537 +
 678.538 +void MainWnd::OnOptionsVideoDdrawemulationonly()
 678.539 +{
 678.540 +	theApp.ddrawEmulationOnly = !theApp.ddrawEmulationOnly;
 678.541 +}
 678.542 +
 678.543 +void MainWnd::OnUpdateOptionsVideoDdrawemulationonly(CCmdUI*pCmdUI)
 678.544 +{
 678.545 +	pCmdUI->SetCheck(theApp.ddrawEmulationOnly);
 678.546 +}
 678.547 +
 678.548 +void MainWnd::OnOptionsVideoDdrawusevideomemory()
 678.549 +{
 678.550 +	theApp.ddrawUseVideoMemory = !theApp.ddrawUseVideoMemory;
 678.551 +}
 678.552 +
 678.553 +void MainWnd::OnUpdateOptionsVideoDdrawusevideomemory(CCmdUI*pCmdUI)
 678.554 +{
 678.555 +	pCmdUI->SetCheck(theApp.ddrawUseVideoMemory);
 678.556 +}
 678.557 +
 678.558 +void MainWnd::OnOptionsVideoRenderoptionsD3dnofilter()
 678.559 +{
 678.560 +	theApp.d3dFilter = 0;
 678.561 +	if (theApp.display)
 678.562 +		theApp.display->setOption("d3dFilter", 0);
 678.563 +}
 678.564 +
 678.565 +void MainWnd::OnUpdateOptionsVideoRenderoptionsD3dnofilter(CCmdUI*pCmdUI)
 678.566 +{
 678.567 +	pCmdUI->SetCheck(theApp.d3dFilter == 0);
 678.568 +}
 678.569 +
 678.570 +void MainWnd::OnOptionsVideoRenderoptionsD3dbilinear()
 678.571 +{
 678.572 +	theApp.d3dFilter = 1;
 678.573 +	if (theApp.display)
 678.574 +		theApp.display->setOption("d3dFilter", 1);
 678.575 +}
 678.576 +
 678.577 +void MainWnd::OnUpdateOptionsVideoRenderoptionsD3dbilinear(CCmdUI*pCmdUI)
 678.578 +{
 678.579 +	pCmdUI->SetCheck(theApp.d3dFilter == 1);
 678.580 +}
 678.581 +
 678.582 +void MainWnd::OnOptionsVideoRenderoptionsGlnearest()
 678.583 +{
 678.584 +	theApp.glFilter = 0;
 678.585 +	if (theApp.display)
 678.586 +		theApp.display->setOption("glFilter", 0);
 678.587 +}
 678.588 +
 678.589 +void MainWnd::OnUpdateOptionsVideoRenderoptionsGlnearest(CCmdUI*pCmdUI)
 678.590 +{
 678.591 +	pCmdUI->SetCheck(theApp.glFilter == 0);
 678.592 +}
 678.593 +
 678.594 +void MainWnd::OnOptionsVideoRenderoptionsGlbilinear()
 678.595 +{
 678.596 +	theApp.glFilter = 1;
 678.597 +	if (theApp.display)
 678.598 +		theApp.display->setOption("glFilter", 1);
 678.599 +}
 678.600 +
 678.601 +void MainWnd::OnUpdateOptionsVideoRenderoptionsGlbilinear(CCmdUI*pCmdUI)
 678.602 +{
 678.603 +	pCmdUI->SetCheck(theApp.glFilter == 1);
 678.604 +}
 678.605 +
 678.606 +void MainWnd::OnOptionsVideoRenderoptionsGltriangle()
 678.607 +{
 678.608 +	theApp.glType = 0;
 678.609 +	if (theApp.display)
 678.610 +		theApp.display->setOption("glType", 0);
 678.611 +}
 678.612 +
 678.613 +void MainWnd::OnUpdateOptionsVideoRenderoptionsGltriangle(CCmdUI*pCmdUI)
 678.614 +{
 678.615 +	pCmdUI->SetCheck(theApp.glType == 0);
 678.616 +}
 678.617 +
 678.618 +void MainWnd::OnOptionsVideoRenderoptionsGlquads()
 678.619 +{
 678.620 +	theApp.glType = 1;
 678.621 +	if (theApp.display)
 678.622 +		theApp.display->setOption("glType", 1);
 678.623 +}
 678.624 +
 678.625 +void MainWnd::OnUpdateOptionsVideoRenderoptionsGlquads(CCmdUI*pCmdUI)
 678.626 +{
 678.627 +	pCmdUI->SetCheck(theApp.glType == 1);
 678.628 +}
 678.629 +
 678.630 +void MainWnd::OnOptionsVideoRenderoptionsSelectskin()
 678.631 +{}
 678.632 +
 678.633 +void MainWnd::OnUpdateOptionsVideoRenderoptionsSelectskin(CCmdUI*pCmdUI)
 678.634 +{}
 678.635 +
 678.636 +void MainWnd::OnOptionsVideoRenderoptionsSkin()
 678.637 +{}
 678.638 +
 678.639 +void MainWnd::OnUpdateOptionsVideoRenderoptionsSkin(CCmdUI*pCmdUI)
 678.640 +{}
 678.641 +
 678.642 +void MainWnd::OnOptionsEmulatorAssociate()
 678.643 +{
 678.644 +	theApp.winCheckFullscreen();
 678.645 +	Associate dlg;
 678.646 +	dlg.DoModal();
 678.647 +}
 678.648 +
 678.649 +void MainWnd::OnOptionsEmulatorDirectories()
 678.650 +{
 678.651 +	theApp.winCheckFullscreen();
 678.652 +	Directories dlg;
 678.653 +	dlg.DoModal();
 678.654 +}
 678.655 +
 678.656 +void MainWnd::OnOptionsEmulatorFilenamePreference(UINT nID)
 678.657 +{
 678.658 +	theApp.filenamePreference = nID - ID_OPTIONS_PREFER_ARCHIVE_NAME;
 678.659 +}
 678.660 +
 678.661 +void MainWnd::OnUpdateOptionsEmulatorFilenamePreference(CCmdUI *pCmdUI)
 678.662 +{
 678.663 +	pCmdUI->SetRadio(pCmdUI->m_nID == theApp.filenamePreference + ID_OPTIONS_PREFER_ARCHIVE_NAME);
 678.664 +}
 678.665 +
 678.666 +void MainWnd::OnOptionsVideoDisablestatusmessages()
 678.667 +{
 678.668 +	theApp.disableStatusMessage = !theApp.disableStatusMessage;
 678.669 +}
 678.670 +
 678.671 +void MainWnd::OnUpdateOptionsVideoDisablestatusmessages(CCmdUI*pCmdUI)
 678.672 +{
 678.673 +	pCmdUI->SetCheck(theApp.disableStatusMessage);
 678.674 +}
 678.675 +
 678.676 +void MainWnd::OnOptionsEmulatorSynchronize()
 678.677 +{
 678.678 +	synchronize = !synchronize;
 678.679 +}
 678.680 +
 678.681 +void MainWnd::OnUpdateOptionsEmulatorSynchronize(CCmdUI*pCmdUI)
 678.682 +{
 678.683 +	pCmdUI->SetCheck(synchronize);
 678.684 +}
 678.685 +
 678.686 +void MainWnd::OnOptionsEmulatorAlwaysOnTop()
 678.687 +{
 678.688 +	theApp.alwaysOnTop = !theApp.alwaysOnTop;
 678.689 +	SetWindowPos((theApp.alwaysOnTop ? &wndTopMost : &wndNoTopMost), 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
 678.690 +}
 678.691 +
 678.692 +void MainWnd::OnUpdateOptionsEmulatorAlwaysOnTop(CCmdUI*pCmdUI)
 678.693 +{
 678.694 +	pCmdUI->SetCheck(theApp.alwaysOnTop);
 678.695 +}
 678.696 +
 678.697 +void MainWnd::OnOptionsEmulatorPausewheninactive()
 678.698 +{
 678.699 +	theApp.pauseWhenInactive = !theApp.pauseWhenInactive;
 678.700 +}
 678.701 +
 678.702 +void MainWnd::OnUpdateOptionsEmulatorPausewheninactive(CCmdUI*pCmdUI)
 678.703 +{
 678.704 +	pCmdUI->SetCheck(theApp.pauseWhenInactive);
 678.705 +}
 678.706 +
 678.707 +void MainWnd::OnOptionsEmulatorEnableBackgroundInput()
 678.708 +{
 678.709 +	theApp.enableBackgroundInput = !theApp.enableBackgroundInput;
 678.710 +}
 678.711 +
 678.712 +void MainWnd::OnUpdateOptionsEmulatorEnableBackgroundInput(CCmdUI*pCmdUI)
 678.713 +{
 678.714 +	pCmdUI->SetCheck(theApp.enableBackgroundInput);
 678.715 +}
 678.716 +
 678.717 +BOOL MainWnd::OnOptionsPriority(UINT nID)
 678.718 +{
 678.719 +	switch (nID)
 678.720 +	{
 678.721 +	case ID_OPTIONS_PRIORITY_HIGHEST:
 678.722 +		theApp.threadPriority = 0;
 678.723 +		break;
 678.724 +	case ID_OPTIONS_PRIORITY_ABOVENORMAL:
 678.725 +		theApp.threadPriority = 1;
 678.726 +		break;
 678.727 +	case ID_OPTIONS_PRIORITY_NORMAL:
 678.728 +		theApp.threadPriority = 2;
 678.729 +		break;
 678.730 +	case ID_OPTIONS_PRIORITY_BELOWNORMAL:
 678.731 +		theApp.threadPriority = 3;
 678.732 +		break;
 678.733 +	default:
 678.734 +		return FALSE;
 678.735 +	}
 678.736 +	theApp.updatePriority();
 678.737 +
 678.738 +	return TRUE;
 678.739 +}
 678.740 +
 678.741 +void MainWnd::OnUpdateOptionsPriority(CCmdUI *pCmdUI)
 678.742 +{
 678.743 +	switch (pCmdUI->m_nID)
 678.744 +	{
 678.745 +	case ID_OPTIONS_PRIORITY_HIGHEST:
 678.746 +		pCmdUI->SetCheck(theApp.threadPriority == 0);
 678.747 +		break;
 678.748 +	case ID_OPTIONS_PRIORITY_ABOVENORMAL:
 678.749 +		pCmdUI->SetCheck(theApp.threadPriority == 1);
 678.750 +		break;
 678.751 +	case ID_OPTIONS_PRIORITY_NORMAL:
 678.752 +		pCmdUI->SetCheck(theApp.threadPriority == 2);
 678.753 +		break;
 678.754 +	case ID_OPTIONS_PRIORITY_BELOWNORMAL:
 678.755 +		pCmdUI->SetCheck(theApp.threadPriority == 3);
 678.756 +		break;
 678.757 +	}
 678.758 +}
 678.759 +
 678.760 +void MainWnd::OnOptionsEmulatorSpeeduptoggle()
 678.761 +{
 678.762 +	theApp.speedupToggle = !theApp.speedupToggle;
 678.763 +}
 678.764 +
 678.765 +void MainWnd::OnUpdateOptionsEmulatorSpeeduptoggle(CCmdUI*pCmdUI)
 678.766 +{
 678.767 +	pCmdUI->SetCheck(theApp.speedupToggle);
 678.768 +}
 678.769 +
 678.770 +void MainWnd::OnOptionsEmulatorRemoveintrosgba()
 678.771 +{
 678.772 +	//  theApp.removeIntros = !theApp.removeIntros;
 678.773 +}
 678.774 +
 678.775 +void MainWnd::OnUpdateOptionsEmulatorRemoveintrosgba(CCmdUI*pCmdUI)
 678.776 +{
 678.777 +	pCmdUI->Enable(false);
 678.778 +	//  pCmdUI->SetCheck(theApp.removeIntros);
 678.779 +}
 678.780 +
 678.781 +void MainWnd::OnOptionsEmulatorAutomaticallyipspatch()
 678.782 +{
 678.783 +	theApp.autoIPS = !theApp.autoIPS;
 678.784 +}
 678.785 +
 678.786 +void MainWnd::OnUpdateOptionsEmulatorAutomaticallyipspatch(CCmdUI*pCmdUI)
 678.787 +{
 678.788 +	pCmdUI->SetCheck(theApp.autoIPS);
 678.789 +}
 678.790 +
 678.791 +void MainWnd::OnOptionsEmulatorAgbprint()
 678.792 +{
 678.793 +	agbPrintEnable(!agbPrintIsEnabled());
 678.794 +}
 678.795 +
 678.796 +void MainWnd::OnUpdateOptionsEmulatorAgbprint(CCmdUI*pCmdUI)
 678.797 +{
 678.798 +	pCmdUI->SetCheck(agbPrintIsEnabled());
 678.799 +}
 678.800 +
 678.801 +void MainWnd::OnOptionsEmulatorRealtimeclock()
 678.802 +{
 678.803 +	theApp.winRtcEnable = !theApp.winRtcEnable;
 678.804 +}
 678.805 +
 678.806 +void MainWnd::OnUpdateOptionsEmulatorRealtimeclock(CCmdUI*pCmdUI)
 678.807 +{
 678.808 +	pCmdUI->SetCheck(theApp.winRtcEnable);
 678.809 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
 678.810 +}
 678.811 +
 678.812 +void MainWnd::OnOptionsEmulatorAutohidemenu()
 678.813 +{
 678.814 +	theApp.autoHideMenu = !theApp.autoHideMenu;
 678.815 +}
 678.816 +
 678.817 +void MainWnd::OnUpdateOptionsEmulatorAutohidemenu(CCmdUI*pCmdUI)
 678.818 +{
 678.819 +	pCmdUI->SetCheck(theApp.autoHideMenu);
 678.820 +}
 678.821 +
 678.822 +void MainWnd::OnOptionsEmulatorRewindinterval()
 678.823 +{
 678.824 +	RewindInterval dlg((float)theApp.rewindTimer/6.0f, theApp.rewindSlots);
 678.825 +	int v = dlg.DoModal();
 678.826 +
 678.827 +	if (v >= 0)
 678.828 +	{
 678.829 +		int interval = v & 0x0000ffff;
 678.830 +		int slots    = (v & 0xffff0000) >> 16;
 678.831 +
 678.832 +		int prevSlots = theApp.rewindSlots;
 678.833 +
 678.834 +		theApp.rewindTimer = interval; // already converted to a multiple of 10 frames
 678.835 +		theApp.rewindSlots = slots;
 678.836 +		if (interval == 0 || slots == 0)
 678.837 +		{
 678.838 +			theApp.rewindTimer = theApp.rewindSlots = 0;
 678.839 +			regSetDwordValue("rewindTimer", interval);
 678.840 +			regSetDwordValue("rewindSlots", slots);
 678.841 +			if (theApp.rewindMemory)
 678.842 +				free(theApp.rewindMemory);
 678.843 +			theApp.rewindMemory     = NULL;
 678.844 +			theApp.rewindCount      = 0;
 678.845 +			theApp.rewindCounter    = 0;
 678.846 +			theApp.rewindSaveNeeded = false;
 678.847 +		}
 678.848 +		else
 678.849 +		{
 678.850 +			regSetDwordValue("rewindTimer", interval);
 678.851 +			regSetDwordValue("rewindSlots", slots);
 678.852 +			if (slots != prevSlots)
 678.853 +			{
 678.854 +				if (theApp.rewindMemory)
 678.855 +					free(theApp.rewindMemory);
 678.856 +				theApp.rewindMemory = NULL;
 678.857 +				theApp.rewindPos    = 0;
 678.858 +			}
 678.859 +			if (theApp.rewindMemory == NULL)
 678.860 +				theApp.rewindMemory = (char *)malloc(theApp.rewindSlots*REWIND_SIZE);
 678.861 +			theApp.rewindCount      = 0;
 678.862 +			theApp.rewindSaveNeeded = true;
 678.863 +		}
 678.864 +	}
 678.865 +}
 678.866 +
 678.867 +BOOL MainWnd::OnOptionsEmulatorShowSpeed(UINT nID)
 678.868 +{
 678.869 +	switch (nID)
 678.870 +	{
 678.871 +	case ID_OPTIONS_EMULATOR_SHOWSPEED_NONE:
 678.872 +		theApp.showSpeed = 0;
 678.873 +		systemSetTitle(VBA_NAME_AND_VERSION);
 678.874 +		break;
 678.875 +	case ID_OPTIONS_EMULATOR_SHOWSPEED_PERCENTAGE:
 678.876 +		theApp.showSpeed = 1;
 678.877 +		break;
 678.878 +	case ID_OPTIONS_EMULATOR_SHOWSPEED_DETAILED:
 678.879 +		theApp.showSpeed = 2;
 678.880 +		break;
 678.881 +	case ID_OPTIONS_EMULATOR_SHOWSPEED_TRANSPARENT:
 678.882 +		theApp.showSpeedTransparent = !theApp.showSpeedTransparent;
 678.883 +		break;
 678.884 +	default:
 678.885 +		return FALSE;
 678.886 +	}
 678.887 +	return TRUE;
 678.888 +}
 678.889 +
 678.890 +void MainWnd::OnUpdateOptionsEmulatorShowSpeed(CCmdUI *pCmdUI)
 678.891 +{
 678.892 +	switch (pCmdUI->m_nID)
 678.893 +	{
 678.894 +	case ID_OPTIONS_EMULATOR_SHOWSPEED_NONE:
 678.895 +		pCmdUI->SetCheck(theApp.showSpeed == 0);
 678.896 +		break;
 678.897 +	case ID_OPTIONS_EMULATOR_SHOWSPEED_PERCENTAGE:
 678.898 +		pCmdUI->SetCheck(theApp.showSpeed == 1);
 678.899 +		break;
 678.900 +	case ID_OPTIONS_EMULATOR_SHOWSPEED_DETAILED:
 678.901 +		pCmdUI->SetCheck(theApp.showSpeed == 2);
 678.902 +		break;
 678.903 +	case ID_OPTIONS_EMULATOR_SHOWSPEED_TRANSPARENT:
 678.904 +		pCmdUI->SetCheck(theApp.showSpeedTransparent);
 678.905 +		break;
 678.906 +	}
 678.907 +}
 678.908 +
 678.909 +void MainWnd::OnOptionsEmulatorSavetypeAutomatic()
 678.910 +{
 678.911 +	theApp.winSaveType = 0;
 678.912 +}
 678.913 +
 678.914 +void MainWnd::OnUpdateOptionsEmulatorSavetypeAutomatic(CCmdUI*pCmdUI)
 678.915 +{
 678.916 +	pCmdUI->SetCheck(theApp.winSaveType == 0);
 678.917 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
 678.918 +}
 678.919 +
 678.920 +void MainWnd::OnOptionsEmulatorSavetypeEeprom()
 678.921 +{
 678.922 +	theApp.winSaveType = 1;
 678.923 +}
 678.924 +
 678.925 +void MainWnd::OnUpdateOptionsEmulatorSavetypeEeprom(CCmdUI*pCmdUI)
 678.926 +{
 678.927 +	pCmdUI->SetCheck(theApp.winSaveType == 1);
 678.928 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
 678.929 +}
 678.930 +
 678.931 +void MainWnd::OnOptionsEmulatorSavetypeSram()
 678.932 +{
 678.933 +	theApp.winSaveType = 2;
 678.934 +}
 678.935 +
 678.936 +void MainWnd::OnUpdateOptionsEmulatorSavetypeSram(CCmdUI*pCmdUI)
 678.937 +{
 678.938 +	pCmdUI->SetCheck(theApp.winSaveType == 2);
 678.939 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
 678.940 +}
 678.941 +
 678.942 +void MainWnd::OnOptionsEmulatorSavetypeFlash()
 678.943 +{
 678.944 +	theApp.winSaveType = 3;
 678.945 +}
 678.946 +
 678.947 +void MainWnd::OnUpdateOptionsEmulatorSavetypeFlash(CCmdUI*pCmdUI)
 678.948 +{
 678.949 +	pCmdUI->SetCheck(theApp.winSaveType == 3);
 678.950 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
 678.951 +}
 678.952 +
 678.953 +void MainWnd::OnOptionsEmulatorSavetypeEepromsensor()
 678.954 +{
 678.955 +	theApp.winSaveType = 4;
 678.956 +}
 678.957 +
 678.958 +void MainWnd::OnUpdateOptionsEmulatorSavetypeEepromsensor(CCmdUI*pCmdUI)
 678.959 +{
 678.960 +	pCmdUI->SetCheck(theApp.winSaveType == 4);
 678.961 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
 678.962 +}
 678.963 +
 678.964 +void MainWnd::OnOptionsEmulatorSavetypeNone()
 678.965 +{
 678.966 +	theApp.winSaveType = 5;
 678.967 +}
 678.968 +
 678.969 +void MainWnd::OnUpdateOptionsEmulatorSavetypeNone(CCmdUI*pCmdUI)
 678.970 +{
 678.971 +	pCmdUI->SetCheck(theApp.winSaveType == 5);
 678.972 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
 678.973 +}
 678.974 +
 678.975 +void MainWnd::OnOptionsEmulatorSavetypeFlash512k()
 678.976 +{
 678.977 +	flashSetSize(0x10000);
 678.978 +	theApp.winFlashSize = 0x10000;
 678.979 +}
 678.980 +
 678.981 +void MainWnd::OnUpdateOptionsEmulatorSavetypeFlash512k(CCmdUI*pCmdUI)
 678.982 +{
 678.983 +	pCmdUI->SetCheck(theApp.winFlashSize == 0x10000);
 678.984 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
 678.985 +}
 678.986 +
 678.987 +void MainWnd::OnOptionsEmulatorSavetypeFlash1m()
 678.988 +{
 678.989 +	flashSetSize(0x20000);
 678.990 +	theApp.winFlashSize = 0x20000;
 678.991 +}
 678.992 +
 678.993 +void MainWnd::OnUpdateOptionsEmulatorSavetypeFlash1m(CCmdUI*pCmdUI)
 678.994 +{
 678.995 +	pCmdUI->SetCheck(theApp.winFlashSize == 0x20000);
 678.996 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
 678.997 +}
 678.998 +
 678.999 +void MainWnd::OnOptionsEmulatorUsebiosfile()
678.1000 +{
678.1001 +	if (!theApp.biosFileName.IsEmpty())
678.1002 +		theApp.useBiosFile = !theApp.useBiosFile;
678.1003 +}
678.1004 +
678.1005 +void MainWnd::OnUpdateOptionsEmulatorUsebiosfile(CCmdUI*pCmdUI)
678.1006 +{
678.1007 +	pCmdUI->SetCheck(theApp.useBiosFile);
678.1008 +	pCmdUI->Enable(!theApp.biosFileName.IsEmpty() && (!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL)));
678.1009 +}
678.1010 +
678.1011 +void MainWnd::OnOptionsEmulatorSkipbios()
678.1012 +{
678.1013 +	theApp.skipBiosFile = !theApp.skipBiosFile;
678.1014 +}
678.1015 +
678.1016 +void MainWnd::OnUpdateOptionsEmulatorSkipbios(CCmdUI*pCmdUI)
678.1017 +{
678.1018 +	pCmdUI->SetCheck(theApp.skipBiosFile);
678.1019 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
678.1020 +}
678.1021 +
678.1022 +void MainWnd::OnOptionsEmulatorUseOldGBTiming()
678.1023 +{
678.1024 +	useOldFrameTiming = !useOldFrameTiming;
678.1025 +}
678.1026 +
678.1027 +void MainWnd::OnUpdateOptionsEmulatorUseOldGBTiming(CCmdUI*pCmdUI)
678.1028 +{
678.1029 +	pCmdUI->SetCheck(useOldFrameTiming);
678.1030 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
678.1031 +}
678.1032 +
678.1033 +void MainWnd::OnOptionsEmulatorUseGBNullInputKludge()
678.1034 +{
678.1035 +	if (VBAMovieActive())
678.1036 +		gbNullInputHackTempEnabled = !gbNullInputHackTempEnabled;
678.1037 +	else
678.1038 +		gbNullInputHackTempEnabled = gbNullInputHackEnabled = !gbNullInputHackEnabled;
678.1039 +}
678.1040 +
678.1041 +void MainWnd::OnUpdateOptionsEmulatorUseGBNullInputKludge(CCmdUI*pCmdUI)
678.1042 +{
678.1043 +	pCmdUI->SetCheck(VBAMovieActive() || GetAsyncKeyState(VK_CONTROL) ? gbNullInputHackTempEnabled : gbNullInputHackEnabled);
678.1044 +	pCmdUI->Enable((!VBAMovieActive() && !useOldFrameTiming) || GetAsyncKeyState(VK_CONTROL));
678.1045 +}
678.1046 +
678.1047 +void MainWnd::OnOptionsEmulatorGBALag()
678.1048 +{
678.1049 +	extern void TogglePrefetchHack();
678.1050 +	TogglePrefetchHack();
678.1051 +	memLagEnabled = memLagTempEnabled; // memLagEnabled is only to hold the last value that the user chose, so temporary changes
678.1052 +                                       // don't get into the registry
678.1053 +}
678.1054 +
678.1055 +void MainWnd::OnUpdateOptionsEmulatorGBALag(CCmdUI*pCmdUI)
678.1056 +{
678.1057 +	pCmdUI->SetCheck(!memLagTempEnabled);
678.1058 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
678.1059 +}
678.1060 +
678.1061 +void MainWnd::OnOptionsEmulatorSelectbiosfile()
678.1062 +{
678.1063 +	theApp.winCheckFullscreen();
678.1064 +	LPCTSTR exts[] = { NULL };
678.1065 +	CString filter = winResLoadFilter(IDS_FILTER_BIOS);
678.1066 +	CString title  = winResLoadString(IDS_SELECT_BIOS_FILE);
678.1067 +
678.1068 +	FileDlg dlg(this,
678.1069 +	            theApp.biosFileName,
678.1070 +	            filter,
678.1071 +	            0,
678.1072 +	            "BIOS",
678.1073 +	            exts,
678.1074 +	            "",
678.1075 +	            title,
678.1076 +	            false);
678.1077 +
678.1078 +	if (dlg.DoModal() == IDOK)
678.1079 +	{
678.1080 +		theApp.biosFileName = dlg.GetPathName();
678.1081 +	}
678.1082 +}
678.1083 +
678.1084 +void MainWnd::OnOptionsEmulatorPngformat()
678.1085 +{
678.1086 +	theApp.captureFormat = 0;
678.1087 +}
678.1088 +
678.1089 +void MainWnd::OnUpdateOptionsEmulatorPngformat(CCmdUI*pCmdUI)
678.1090 +{
678.1091 +	pCmdUI->SetCheck(theApp.captureFormat == 0);
678.1092 +}
678.1093 +
678.1094 +void MainWnd::OnOptionsEmulatorBmpformat()
678.1095 +{
678.1096 +	theApp.captureFormat = 1;
678.1097 +}
678.1098 +
678.1099 +void MainWnd::OnUpdateOptionsEmulatorBmpformat(CCmdUI*pCmdUI)
678.1100 +{
678.1101 +	pCmdUI->SetCheck(theApp.captureFormat == 1);
678.1102 +}
678.1103 +
678.1104 +void MainWnd::OnOptionsSoundDisable()
678.1105 +{
678.1106 +	if (soundOffFlag)
678.1107 +	{
678.1108 +		soundOffFlag = false;
678.1109 +		soundInit();
678.1110 +	}
678.1111 +	else
678.1112 +	{
678.1113 +		soundOffFlag = true;
678.1114 +		soundShutdown();
678.1115 +	}
678.1116 +}
678.1117 +
678.1118 +void MainWnd::OnUpdateOptionsSoundDisable(CCmdUI*pCmdUI)
678.1119 +{
678.1120 +	pCmdUI->SetCheck(soundOffFlag);
678.1121 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
678.1122 +}
678.1123 +
678.1124 +static void OnSoundToggleEnabled(int c)
678.1125 +{
678.1126 +	if (soundGetEnabledChannels() & c)
678.1127 +	{
678.1128 +		soundDisableChannels(c);
678.1129 +	}
678.1130 +	else
678.1131 +	{
678.1132 +		soundEnableChannels(c);
678.1133 +	}
678.1134 +}
678.1135 +
678.1136 +void MainWnd::OnOptionsSoundMute()
678.1137 +{
678.1138 +	if ((soundGetEnabledChannels() & 0x030f) == 0)
678.1139 +		soundEnableChannels(0x030f);
678.1140 +	else
678.1141 +		soundDisableChannels(0x030f);
678.1142 +}
678.1143 +
678.1144 +void MainWnd::OnUpdateOptionsSoundMute(CCmdUI*pCmdUI)
678.1145 +{
678.1146 +	pCmdUI->SetCheck((soundGetEnabledChannels() & 0x030f) == 0);
678.1147 +}
678.1148 +
678.1149 +void MainWnd::OnOptionsSoundOff()
678.1150 +{
678.1151 +	soundDisableChannels(0x030f);
678.1152 +}
678.1153 +
678.1154 +void MainWnd::OnUpdateOptionsSoundOff(CCmdUI*pCmdUI)
678.1155 +{
678.1156 +	pCmdUI->SetCheck((soundGetEnabledChannels() & 0x030f) == 0);
678.1157 +}
678.1158 +
678.1159 +void MainWnd::OnOptionsSoundOn()
678.1160 +{
678.1161 +	soundEnableChannels(0x030f);
678.1162 +}
678.1163 +
678.1164 +void MainWnd::OnUpdateOptionsSoundOn(CCmdUI*pCmdUI)
678.1165 +{
678.1166 +	pCmdUI->SetCheck(soundGetEnabledChannels() == 0x030f);
678.1167 +}
678.1168 +
678.1169 +void MainWnd::OnOptionsSoundUseoldsynchronization()
678.1170 +{
678.1171 +	theApp.useOldSync = !theApp.useOldSync;
678.1172 +	systemMessage(IDS_SETTING_WILL_BE_EFFECTIVE,
678.1173 +	              "Setting will be effective the next time you start the emulator");
678.1174 +}
678.1175 +
678.1176 +void MainWnd::OnUpdateOptionsSoundUseoldsynchronization(CCmdUI*pCmdUI)
678.1177 +{
678.1178 +	pCmdUI->SetCheck(theApp.useOldSync);
678.1179 +}
678.1180 +
678.1181 +void MainWnd::OnOptionsSoundEcho()
678.1182 +{
678.1183 +	soundEcho = !soundEcho;
678.1184 +}
678.1185 +
678.1186 +void MainWnd::OnUpdateOptionsSoundEcho(CCmdUI*pCmdUI)
678.1187 +{
678.1188 +	pCmdUI->SetCheck(soundEcho);
678.1189 +}
678.1190 +
678.1191 +void MainWnd::OnOptionsSoundLowpassfilter()
678.1192 +{
678.1193 +	soundLowPass = !soundLowPass;
678.1194 +}
678.1195 +
678.1196 +void MainWnd::OnUpdateOptionsSoundLowpassfilter(CCmdUI*pCmdUI)
678.1197 +{
678.1198 +	pCmdUI->SetCheck(soundLowPass);
678.1199 +}
678.1200 +
678.1201 +void MainWnd::OnOptionsSoundReversestereo()
678.1202 +{
678.1203 +	soundReverse = !soundReverse;
678.1204 +}
678.1205 +
678.1206 +void MainWnd::OnUpdateOptionsSoundReversestereo(CCmdUI*pCmdUI)
678.1207 +{
678.1208 +	pCmdUI->SetCheck(soundReverse);
678.1209 +}
678.1210 +
678.1211 +void MainWnd::OnOptionsSoundMuteFrameAdvance()
678.1212 +{
678.1213 +	theApp.muteFrameAdvance = !theApp.muteFrameAdvance;
678.1214 +}
678.1215 +
678.1216 +void MainWnd::OnUpdateOptionsSoundMuteFrameAdvance(CCmdUI*pCmdUI)
678.1217 +{
678.1218 +	pCmdUI->SetCheck(theApp.muteFrameAdvance);
678.1219 +}
678.1220 +
678.1221 +void MainWnd::OnOptionsSoundMuteWhenInactive()
678.1222 +{
678.1223 +	theApp.muteWhenInactive = !theApp.muteWhenInactive;
678.1224 +}
678.1225 +
678.1226 +void MainWnd::OnUpdateOptionsSoundMuteWhenInactive(CCmdUI*pCmdUI)
678.1227 +{
678.1228 +	pCmdUI->SetCheck(theApp.muteWhenInactive);
678.1229 +}
678.1230 +
678.1231 +void MainWnd::OnOptionsSound11khz()
678.1232 +{
678.1233 +	if (systemCartridgeType == 0)
678.1234 +		soundSetQuality(4);
678.1235 +	else
678.1236 +		gbSoundSetQuality(4);
678.1237 +}
678.1238 +
678.1239 +void MainWnd::OnUpdateOptionsSound11khz(CCmdUI*pCmdUI)
678.1240 +{
678.1241 +	pCmdUI->SetCheck(soundQuality == 4);
678.1242 +	pCmdUI->Enable((!VBAMovieActive() ||
678.1243 +	                GetAsyncKeyState(VK_CONTROL)) && !(theApp.soundRecording || theApp.aviRecording || theApp.nvAudioLog));
678.1244 +}
678.1245 +
678.1246 +void MainWnd::OnOptionsSound22khz()
678.1247 +{
678.1248 +	if (systemCartridgeType == 0)
678.1249 +		soundSetQuality(2);
678.1250 +	else
678.1251 +		gbSoundSetQuality(2);
678.1252 +}
678.1253 +
678.1254 +void MainWnd::OnUpdateOptionsSound22khz(CCmdUI*pCmdUI)
678.1255 +{
678.1256 +	pCmdUI->SetCheck(soundQuality == 2);
678.1257 +	pCmdUI->Enable((!VBAMovieActive() ||
678.1258 +	                GetAsyncKeyState(VK_CONTROL)) && !(theApp.soundRecording || theApp.aviRecording || theApp.nvAudioLog));
678.1259 +}
678.1260 +
678.1261 +void MainWnd::OnOptionsSound44khz()
678.1262 +{
678.1263 +	systemSoundSetQuality(1);
678.1264 +}
678.1265 +
678.1266 +void MainWnd::OnUpdateOptionsSound44khz(CCmdUI*pCmdUI)
678.1267 +{
678.1268 +	pCmdUI->SetCheck(soundQuality == 1);
678.1269 +	pCmdUI->Enable(!(theApp.soundRecording || theApp.aviRecording || theApp.nvAudioLog));
678.1270 +}
678.1271 +
678.1272 +BOOL MainWnd::OnOptionsSoundVolume(UINT nID)
678.1273 +{
678.1274 +	soundVolume = nID - ID_OPTIONS_SOUND_VOLUME_1X;
678.1275 +	return TRUE;
678.1276 +}
678.1277 +
678.1278 +void MainWnd::OnUpdateOptionsSoundVolume(CCmdUI *pCmdUI)
678.1279 +{
678.1280 +	pCmdUI->SetCheck(soundVolume == (int)(pCmdUI->m_nID - ID_OPTIONS_SOUND_VOLUME_1X));
678.1281 +}
678.1282 +
678.1283 +void MainWnd::OnOptionsSoundVolume25x()
678.1284 +{
678.1285 +	soundVolume = 4;
678.1286 +}
678.1287 +
678.1288 +void MainWnd::OnUpdateOptionsSoundVolume25x(CCmdUI*pCmdUI)
678.1289 +{
678.1290 +	pCmdUI->SetCheck(soundVolume == 4);
678.1291 +}
678.1292 +
678.1293 +void MainWnd::OnOptionsSoundVolume5x()
678.1294 +{
678.1295 +	soundVolume = 5;
678.1296 +}
678.1297 +
678.1298 +void MainWnd::OnUpdateOptionsSoundVolume5x(CCmdUI*pCmdUI)
678.1299 +{
678.1300 +	pCmdUI->SetCheck(soundVolume == 5);
678.1301 +}
678.1302 +
678.1303 +void MainWnd::OnOptionsSoundChannel1()
678.1304 +{
678.1305 +	OnSoundToggleEnabled(0x01);
678.1306 +}
678.1307 +
678.1308 +void MainWnd::OnUpdateOptionsSoundChannel1(CCmdUI*pCmdUI)
678.1309 +{
678.1310 +	pCmdUI->SetCheck(soundGetEnabledChannels() & 0x01);
678.1311 +}
678.1312 +
678.1313 +void MainWnd::OnOptionsSoundChannel2()
678.1314 +{
678.1315 +	OnSoundToggleEnabled(0x02);
678.1316 +}
678.1317 +
678.1318 +void MainWnd::OnUpdateOptionsSoundChannel2(CCmdUI*pCmdUI)
678.1319 +{
678.1320 +	pCmdUI->SetCheck(soundGetEnabledChannels() & 0x02);
678.1321 +}
678.1322 +
678.1323 +void MainWnd::OnOptionsSoundChannel3()
678.1324 +{
678.1325 +	OnSoundToggleEnabled(0x04);
678.1326 +}
678.1327 +
678.1328 +void MainWnd::OnUpdateOptionsSoundChannel3(CCmdUI*pCmdUI)
678.1329 +{
678.1330 +	pCmdUI->SetCheck(soundGetEnabledChannels() & 0x04);
678.1331 +}
678.1332 +
678.1333 +void MainWnd::OnOptionsSoundChannel4()
678.1334 +{
678.1335 +	OnSoundToggleEnabled(0x08);
678.1336 +}
678.1337 +
678.1338 +void MainWnd::OnUpdateOptionsSoundChannel4(CCmdUI*pCmdUI)
678.1339 +{
678.1340 +	pCmdUI->SetCheck(soundGetEnabledChannels() & 0x08);
678.1341 +}
678.1342 +
678.1343 +void MainWnd::OnOptionsSoundDirectsounda()
678.1344 +{
678.1345 +	OnSoundToggleEnabled(0x0100);
678.1346 +}
678.1347 +
678.1348 +void MainWnd::OnUpdateOptionsSoundDirectsounda(CCmdUI*pCmdUI)
678.1349 +{
678.1350 +	pCmdUI->SetCheck(soundGetEnabledChannels() & 0x0100);
678.1351 +	//pCmdUI->Enable(systemCartridgeType == 0);
678.1352 +}
678.1353 +
678.1354 +void MainWnd::OnOptionsSoundDirectsoundb()
678.1355 +{
678.1356 +	OnSoundToggleEnabled(0x0200);
678.1357 +}
678.1358 +
678.1359 +void MainWnd::OnUpdateOptionsSoundDirectsoundb(CCmdUI*pCmdUI)
678.1360 +{
678.1361 +	pCmdUI->SetCheck(soundGetEnabledChannels() & 0x0200);
678.1362 +	//pCmdUI->Enable(systemCartridgeType == 0);
678.1363 +}
678.1364 +
678.1365 +void MainWnd::OnOptionsGameboyBorder()
678.1366 +{
678.1367 +	theApp.winGbBorderOn = !theApp.winGbBorderOn;
678.1368 +	gbBorderOn = theApp.winGbBorderOn;
678.1369 +	if (emulating && systemCartridgeType == 1 && gbBorderOn)
678.1370 +	{
678.1371 +		gbSgbRenderBorder();
678.1372 +	}
678.1373 +	theApp.updateWindowSize(theApp.videoOption);
678.1374 +}
678.1375 +
678.1376 +void MainWnd::OnUpdateOptionsGameboyBorder(CCmdUI*pCmdUI)
678.1377 +{
678.1378 +	pCmdUI->SetCheck(theApp.winGbBorderOn);
678.1379 +}
678.1380 +
678.1381 +void MainWnd::OnOptionsGameboyPrinter()
678.1382 +{
678.1383 +	theApp.winGbPrinterEnabled = !theApp.winGbPrinterEnabled;
678.1384 +	if (theApp.winGbPrinterEnabled)
678.1385 +		gbSerialFunction = gbPrinterSend;
678.1386 +	else
678.1387 +		gbSerialFunction = NULL;
678.1388 +}
678.1389 +
678.1390 +void MainWnd::OnUpdateOptionsGameboyPrinter(CCmdUI*pCmdUI)
678.1391 +{
678.1392 +	pCmdUI->SetCheck(gbSerialFunction == gbPrinterSend);
678.1393 +}
678.1394 +
678.1395 +void MainWnd::OnOptionsGameboyBorderAutomatic()
678.1396 +{
678.1397 +	gbBorderAutomatic = !gbBorderAutomatic;
678.1398 +	if (emulating && systemCartridgeType == 1 && gbBorderOn)
678.1399 +	{
678.1400 +		gbSgbRenderBorder();
678.1401 +		theApp.updateWindowSize(theApp.videoOption);
678.1402 +	}
678.1403 +}
678.1404 +
678.1405 +void MainWnd::OnUpdateOptionsGameboyBorderAutomatic(CCmdUI*pCmdUI)
678.1406 +{
678.1407 +	pCmdUI->SetCheck(gbBorderAutomatic);
678.1408 +}
678.1409 +
678.1410 +void MainWnd::OnOptionsGameboyAutomatic()
678.1411 +{
678.1412 +	gbEmulatorType = 0;
678.1413 +}
678.1414 +
678.1415 +void MainWnd::OnUpdateOptionsGameboyAutomatic(CCmdUI*pCmdUI)
678.1416 +{
678.1417 +	pCmdUI->SetCheck(gbEmulatorType == 0);
678.1418 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
678.1419 +}
678.1420 +
678.1421 +void MainWnd::OnOptionsGameboyGba()
678.1422 +{
678.1423 +	gbEmulatorType = 4;
678.1424 +}
678.1425 +
678.1426 +void MainWnd::OnUpdateOptionsGameboyGba(CCmdUI*pCmdUI)
678.1427 +{
678.1428 +	pCmdUI->SetCheck(gbEmulatorType == 4);
678.1429 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
678.1430 +}
678.1431 +
678.1432 +void MainWnd::OnOptionsGameboyCgb()
678.1433 +{
678.1434 +	gbEmulatorType = 1;
678.1435 +}
678.1436 +
678.1437 +void MainWnd::OnUpdateOptionsGameboyCgb(CCmdUI*pCmdUI)
678.1438 +{
678.1439 +	pCmdUI->SetCheck(gbEmulatorType == 1);
678.1440 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
678.1441 +}
678.1442 +
678.1443 +void MainWnd::OnOptionsGameboySgb()
678.1444 +{
678.1445 +	gbEmulatorType = 2;
678.1446 +}
678.1447 +
678.1448 +void MainWnd::OnUpdateOptionsGameboySgb(CCmdUI*pCmdUI)
678.1449 +{
678.1450 +	pCmdUI->SetCheck(gbEmulatorType == 2);
678.1451 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
678.1452 +}
678.1453 +
678.1454 +void MainWnd::OnOptionsGameboySgb2()
678.1455 +{
678.1456 +	gbEmulatorType = 5;
678.1457 +}
678.1458 +
678.1459 +void MainWnd::OnUpdateOptionsGameboySgb2(CCmdUI*pCmdUI)
678.1460 +{
678.1461 +	pCmdUI->SetCheck(gbEmulatorType == 5);
678.1462 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
678.1463 +}
678.1464 +
678.1465 +void MainWnd::OnOptionsGameboyGb()
678.1466 +{
678.1467 +	gbEmulatorType = 3;
678.1468 +}
678.1469 +
678.1470 +void MainWnd::OnUpdateOptionsGameboyGb(CCmdUI*pCmdUI)
678.1471 +{
678.1472 +	pCmdUI->SetCheck(gbEmulatorType == 3);
678.1473 +	pCmdUI->Enable(!VBAMovieActive() || GetAsyncKeyState(VK_CONTROL));
678.1474 +}
678.1475 +
678.1476 +void MainWnd::OnOptionsGameboyRealcolors()
678.1477 +{
678.1478 +	gbColorOption = 0;
678.1479 +}
678.1480 +
678.1481 +void MainWnd::OnUpdateOptionsGameboyRealcolors(CCmdUI*pCmdUI)
678.1482 +{
678.1483 +	pCmdUI->SetCheck(gbColorOption == 0);
678.1484 +}
678.1485 +
678.1486 +void MainWnd::OnOptionsGameboyGameboycolors()
678.1487 +{
678.1488 +	gbColorOption = 1;
678.1489 +}
678.1490 +
678.1491 +void MainWnd::OnUpdateOptionsGameboyGameboycolors(CCmdUI*pCmdUI)
678.1492 +{
678.1493 +	pCmdUI->SetCheck(gbColorOption == 1);
678.1494 +}
678.1495 +
678.1496 +void MainWnd::OnOptionsGameboyColors()
678.1497 +{
678.1498 +	theApp.winCheckFullscreen();
678.1499 +	GBColorDlg dlg;
678.1500 +	if (dlg.DoModal())
678.1501 +	{
678.1502 +		gbPaletteOption = dlg.getWhich();
678.1503 +		memcpy(systemGbPalette, dlg.getColors(), 24*sizeof(u16));
678.1504 +		if (emulating && systemCartridgeType == 1)
678.1505 +		{
678.1506 +			memcpy(gbPalette, &systemGbPalette[dlg.getWhich()*8], 8*sizeof(u16));
678.1507 +		}
678.1508 +	}
678.1509 +}
678.1510 +
678.1511 +BOOL MainWnd::OnOptionsFilter(UINT nID)
678.1512 +{
678.1513 +	switch (nID)
678.1514 +	{
678.1515 +	case ID_OPTIONS_FILTER_NORMAL:
678.1516 +		theApp.filterType = 0;
678.1517 +		break;
678.1518 +	case ID_OPTIONS_FILTER_TVMODE:
678.1519 +		theApp.filterType = 1;
678.1520 +		break;
678.1521 +	case ID_OPTIONS_FILTER_2XSAI:
678.1522 +		theApp.filterType = 2;
678.1523 +		break;
678.1524 +	case ID_OPTIONS_FILTER_SUPER2XSAI:
678.1525 +		theApp.filterType = 3;
678.1526 +		break;
678.1527 +	case ID_OPTIONS_FILTER_SUPEREAGLE:
678.1528 +		theApp.filterType = 4;
678.1529 +		break;
678.1530 +	case ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL:
678.1531 +		theApp.filterType = 5;
678.1532 +		break;
678.1533 +	case ID_OPTIONS_FILTER16BIT_MOTIONBLUREXPERIMENTAL:
678.1534 +		theApp.filterType = 6;
678.1535 +		break;
678.1536 +	case ID_OPTIONS_FILTER16BIT_ADVANCEMAMESCALE2X:
678.1537 +		theApp.filterType = 7;
678.1538 +		break;
678.1539 +	case ID_OPTIONS_FILTER16BIT_SIMPLE2X:
678.1540 +		theApp.filterType = 8;
678.1541 +		break;
678.1542 +	case ID_OPTIONS_FILTER_BILINEAR:
678.1543 +		theApp.filterType = 9;
678.1544 +		break;
678.1545 +	case ID_OPTIONS_FILTER_BILINEARPLUS:
678.1546 +		theApp.filterType = 10;
678.1547 +		break;
678.1548 +	case ID_OPTIONS_FILTER_SCANLINES:
678.1549 +		theApp.filterType = 11;
678.1550 +		break;
678.1551 +	case ID_OPTIONS_FILTER_HQ2X2:
678.1552 +		theApp.filterType = 12;
678.1553 +		break;
678.1554 +	case ID_OPTIONS_FILTER_HQ2X:
678.1555 +		theApp.filterType = 13;
678.1556 +		break;
678.1557 +	case ID_OPTIONS_FILTER_LQ2X:
678.1558 +		theApp.filterType = 14;
678.1559 +		break;
678.1560 +	case ID_OPTIONS_FILTER_HQ3X2:
678.1561 +		theApp.filterType = 15;
678.1562 +		break;
678.1563 +	case ID_OPTIONS_FILTER_HQ3X:
678.1564 +		theApp.filterType = 16;
678.1565 +		break;
678.1566 +	case ID_OPTIONS_FILTER16BIT_SIMPLE3X:
678.1567 +		theApp.filterType = 17;
678.1568 +		break;
678.1569 +	case ID_OPTIONS_FILTER16BIT_SIMPLE4X:
678.1570 +		theApp.filterType = 18;
678.1571 +		break;
678.1572 +	case ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL3X:
678.1573 +		theApp.filterType = 19;
678.1574 +		break;
678.1575 +	case ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL4X:
678.1576 +		theApp.filterType = 20;
678.1577 +		break;
678.1578 +	default:
678.1579 +		return FALSE;
678.1580 +	}
678.1581 +	theApp.updateFilter();
678.1582 +	return TRUE;
678.1583 +}
678.1584 +
678.1585 +void MainWnd::OnUpdateOptionsFilter(CCmdUI *pCmdUI)
678.1586 +{
678.1587 +	pCmdUI->Enable(systemColorDepth == 16 || systemColorDepth == 32);
678.1588 +	switch (pCmdUI->m_nID)
678.1589 +	{
678.1590 +	case ID_OPTIONS_FILTER_NORMAL:
678.1591 +		pCmdUI->SetCheck(theApp.filterType == 0);
678.1592 +		break;
678.1593 +	case ID_OPTIONS_FILTER_TVMODE:
678.1594 +		pCmdUI->SetCheck(theApp.filterType == 1);
678.1595 +		break;
678.1596 +	case ID_OPTIONS_FILTER_2XSAI:
678.1597 +		pCmdUI->SetCheck(theApp.filterType == 2);
678.1598 +		break;
678.1599 +	case ID_OPTIONS_FILTER_SUPER2XSAI:
678.1600 +		pCmdUI->SetCheck(theApp.filterType == 3);
678.1601 +		break;
678.1602 +	case ID_OPTIONS_FILTER_SUPEREAGLE:
678.1603 +		pCmdUI->SetCheck(theApp.filterType == 4);
678.1604 +		break;
678.1605 +	case ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL:
678.1606 +		pCmdUI->SetCheck(theApp.filterType == 5);
678.1607 +		break;
678.1608 +	case ID_OPTIONS_FILTER16BIT_MOTIONBLUREXPERIMENTAL:
678.1609 +		pCmdUI->SetCheck(theApp.filterType == 6);
678.1610 +		break;
678.1611 +	case ID_OPTIONS_FILTER16BIT_ADVANCEMAMESCALE2X:
678.1612 +		pCmdUI->SetCheck(theApp.filterType == 7);
678.1613 +		break;
678.1614 +	case ID_OPTIONS_FILTER16BIT_SIMPLE2X:
678.1615 +		pCmdUI->SetCheck(theApp.filterType == 8);
678.1616 +		break;
678.1617 +	case ID_OPTIONS_FILTER_BILINEAR:
678.1618 +		pCmdUI->SetCheck(theApp.filterType == 9);
678.1619 +		break;
678.1620 +	case ID_OPTIONS_FILTER_BILINEARPLUS:
678.1621 +		pCmdUI->SetCheck(theApp.filterType == 10);
678.1622 +		break;
678.1623 +	case ID_OPTIONS_FILTER_SCANLINES:
678.1624 +		pCmdUI->SetCheck(theApp.filterType == 11);
678.1625 +		break;
678.1626 +	case ID_OPTIONS_FILTER_HQ2X2:
678.1627 +		pCmdUI->SetCheck(theApp.filterType == 12);
678.1628 +		break;
678.1629 +	case ID_OPTIONS_FILTER_HQ2X:
678.1630 +		pCmdUI->SetCheck(theApp.filterType == 13);
678.1631 +		break;
678.1632 +	case ID_OPTIONS_FILTER_LQ2X:
678.1633 +		pCmdUI->SetCheck(theApp.filterType == 14);
678.1634 +		break;
678.1635 +	case ID_OPTIONS_FILTER_HQ3X2:
678.1636 +		pCmdUI->SetCheck(theApp.filterType == 15);
678.1637 +		break;
678.1638 +	case ID_OPTIONS_FILTER_HQ3X:
678.1639 +		pCmdUI->SetCheck(theApp.filterType == 16);
678.1640 +		break;
678.1641 +	case ID_OPTIONS_FILTER16BIT_SIMPLE3X:
678.1642 +		pCmdUI->SetCheck(theApp.filterType == 17);
678.1643 +		break;
678.1644 +	case ID_OPTIONS_FILTER16BIT_SIMPLE4X:
678.1645 +		pCmdUI->SetCheck(theApp.filterType == 18);
678.1646 +		break;
678.1647 +	case ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL3X:
678.1648 +		pCmdUI->SetCheck(theApp.filterType == 19);
678.1649 +		break;
678.1650 +	case ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL4X:
678.1651 +		pCmdUI->SetCheck(theApp.filterType == 20);
678.1652 +		break;
678.1653 +	}
678.1654 +}
678.1655 +
678.1656 +BOOL MainWnd::OnOptionsFilterIFB(UINT nID)
678.1657 +{
678.1658 +	switch (nID)
678.1659 +	{
678.1660 +	case ID_OPTIONS_FILTER_INTERFRAMEBLENDING_NONE:
678.1661 +		theApp.ifbType = 0;
678.1662 +		break;
678.1663 +	case ID_OPTIONS_FILTER_INTERFRAMEBLENDING_MOTIONBLUR:
678.1664 +		theApp.ifbType = 1;
678.1665 +		break;
678.1666 +	case ID_OPTIONS_FILTER_INTERFRAMEBLENDING_SMART:
678.1667 +		theApp.ifbType = 2;
678.1668 +		break;
678.1669 +	default:
678.1670 +		return FALSE;
678.1671 +	}
678.1672 +	theApp.updateIFB();
678.1673 +	return TRUE;
678.1674 +}
678.1675 +
678.1676 +void MainWnd::OnUpdateOptionsFilterIFB(CCmdUI *pCmdUI)
678.1677 +{
678.1678 +	switch (pCmdUI->m_nID)
678.1679 +	{
678.1680 +	case ID_OPTIONS_FILTER_INTERFRAMEBLENDING_NONE:
678.1681 +		pCmdUI->SetCheck(theApp.ifbType == 0);
678.1682 +		break;
678.1683 +	case ID_OPTIONS_FILTER_INTERFRAMEBLENDING_MOTIONBLUR:
678.1684 +		pCmdUI->SetCheck(theApp.ifbType == 1);
678.1685 +		break;
678.1686 +	case ID_OPTIONS_FILTER_INTERFRAMEBLENDING_SMART:
678.1687 +		pCmdUI->SetCheck(theApp.ifbType == 2);
678.1688 +		break;
678.1689 +	}
678.1690 +}
678.1691 +
678.1692 +void MainWnd::OnOptionsFilterDisablemmx()
678.1693 +{
678.1694 +	theApp.disableMMX = !theApp.disableMMX;
678.1695 +	if (!theApp.disableMMX)
678.1696 +		cpu_mmx = theApp.detectMMX();
678.1697 +	else
678.1698 +		cpu_mmx = 0;
678.1699 +}
678.1700 +
678.1701 +void MainWnd::OnUpdateOptionsFilterDisablemmx(CCmdUI*pCmdUI)
678.1702 +{
678.1703 +	pCmdUI->SetCheck(theApp.disableMMX);
678.1704 +}
678.1705 +
678.1706 +void MainWnd::OnOptionsLanguageSystem()
678.1707 +{
678.1708 +	theApp.winSetLanguageOption(0, false);
678.1709 +}
678.1710 +
678.1711 +void MainWnd::OnUpdateOptionsLanguageSystem(CCmdUI*pCmdUI)
678.1712 +{
678.1713 +	pCmdUI->SetCheck(theApp.languageOption == 0);
678.1714 +}
678.1715 +
678.1716 +void MainWnd::OnOptionsLanguageEnglish()
678.1717 +{
678.1718 +	theApp.winSetLanguageOption(1, false);
678.1719 +}
678.1720 +
678.1721 +void MainWnd::OnUpdateOptionsLanguageEnglish(CCmdUI*pCmdUI)
678.1722 +{
678.1723 +	pCmdUI->SetCheck(theApp.languageOption == 1);
678.1724 +}
678.1725 +
678.1726 +void MainWnd::OnOptionsLanguageOther()
678.1727 +{
678.1728 +	theApp.winCheckFullscreen();
678.1729 +	theApp.winSetLanguageOption(2, false);
678.1730 +}
678.1731 +
678.1732 +void MainWnd::OnUpdateOptionsLanguageOther(CCmdUI*pCmdUI)
678.1733 +{
678.1734 +	pCmdUI->SetCheck(theApp.languageOption == 2);
678.1735 +}
678.1736 +
678.1737 +void MainWnd::OnOptionsJoypadConfigure1()
678.1738 +{
678.1739 +	theApp.winCheckFullscreen();
678.1740 +	JoypadConfig dlg(0);
678.1741 +	dlg.DoModal();
678.1742 +}
678.1743 +
678.1744 +void MainWnd::OnUpdateOptionsJoypadConfigure1(CCmdUI*pCmdUI)
678.1745 +{
678.1746 +	pCmdUI->Enable(theApp.videoOption != VIDEO_320x240);
678.1747 +}
678.1748 +
678.1749 +void MainWnd::OnOptionsJoypadConfigure2()
678.1750 +{
678.1751 +	theApp.winCheckFullscreen();
678.1752 +	JoypadConfig dlg(1);
678.1753 +	dlg.DoModal();
678.1754 +}
678.1755 +
678.1756 +void MainWnd::OnUpdateOptionsJoypadConfigure2(CCmdUI*pCmdUI)
678.1757 +{
678.1758 +	pCmdUI->Enable(theApp.videoOption != VIDEO_320x240);
678.1759 +}
678.1760 +
678.1761 +void MainWnd::OnOptionsJoypadConfigure3()
678.1762 +{
678.1763 +	theApp.winCheckFullscreen();
678.1764 +	JoypadConfig dlg(2);
678.1765 +	dlg.DoModal();
678.1766 +}
678.1767 +
678.1768 +void MainWnd::OnUpdateOptionsJoypadConfigure3(CCmdUI*pCmdUI)
678.1769 +{
678.1770 +	pCmdUI->Enable(theApp.videoOption != VIDEO_320x240);
678.1771 +}
678.1772 +
678.1773 +void MainWnd::OnOptionsJoypadConfigure4()
678.1774 +{
678.1775 +	theApp.winCheckFullscreen();
678.1776 +	JoypadConfig dlg(3);
678.1777 +	dlg.DoModal();
678.1778 +}
678.1779 +
678.1780 +void MainWnd::OnUpdateOptionsJoypadConfigure4(CCmdUI*pCmdUI)
678.1781 +{
678.1782 +	pCmdUI->Enable(theApp.videoOption != VIDEO_320x240);
678.1783 +}
678.1784 +
678.1785 +BOOL MainWnd::OnOptionsJoypadDefault(UINT nID)
678.1786 +{
678.1787 +	theApp.joypadDefault = nID - ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_1;
678.1788 +	return TRUE;
678.1789 +}
678.1790 +
678.1791 +void MainWnd::OnUpdateOptionsJoypadDefault(CCmdUI *pCmdUI)
678.1792 +{
678.1793 +	pCmdUI->SetCheck(theApp.joypadDefault == (int)(pCmdUI->m_nID - ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_1));
678.1794 +}
678.1795 +
678.1796 +void MainWnd::OnOptionsJoypadMotionconfigure()
678.1797 +{
678.1798 +	theApp.winCheckFullscreen();
678.1799 +	MotionConfig dlg;
678.1800 +	dlg.DoModal();
678.1801 +}
678.1802 +
678.1803 +void MainWnd::OnUpdateOptionsJoypadMotionconfigure(CCmdUI*pCmdUI)
678.1804 +{
678.1805 +	pCmdUI->Enable(theApp.videoOption != VIDEO_320x240);
678.1806 +}
678.1807 +
678.1808 +void MainWnd::OnOptionsJoypadAllowLeftRight()
678.1809 +{
678.1810 +	theApp.allowLeftRight = !theApp.allowLeftRight;
678.1811 +}
678.1812 +
678.1813 +void MainWnd::OnUpdateOptionsJoypadAllowLeftRight(CCmdUI*pCmdUI)
678.1814 +{
678.1815 +	pCmdUI->SetCheck(theApp.allowLeftRight);
678.1816 +}
678.1817 +
678.1818 +void MainWnd::OnOptionsJoypadAutofireAccountForLag()
678.1819 +{
678.1820 +	theApp.autofireAccountForLag = !theApp.autofireAccountForLag;
678.1821 +}
678.1822 +
678.1823 +void MainWnd::OnUpdateOptionsJoypadAutofireAccountForLag(CCmdUI*pCmdUI)
678.1824 +{
678.1825 +	pCmdUI->SetCheck(theApp.autofireAccountForLag);
678.1826 +}
678.1827 +
678.1828 +BOOL MainWnd::OnOptionsJoypadAutofire(UINT nID)
678.1829 +{
678.1830 +	int & autoFire  = (theApp.autoFireToggle ? theApp.autoFire : theApp.autoFire2);
678.1831 +	int & autoFire2 = (theApp.autoFireToggle ? theApp.autoFire2 : theApp.autoFire);
678.1832 +	int   autoFires = (theApp.autoFire | theApp.autoFire2);
678.1833 +
678.1834 +	switch (nID)
678.1835 +	{
678.1836 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_A:
678.1837 +		if (autoFires & BUTTON_MASK_A)
678.1838 +		{
678.1839 +			autoFire &= ~BUTTON_MASK_A;
678.1840 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_A_DISABLED));
678.1841 +		}
678.1842 +		else
678.1843 +		{
678.1844 +			autoFire |= BUTTON_MASK_A;
678.1845 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_A));
678.1846 +		}
678.1847 +		autoFire2       &= ~BUTTON_MASK_A;
678.1848 +		theApp.autoHold &= ~BUTTON_MASK_A;
678.1849 +		break;
678.1850 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_B:
678.1851 +		if (autoFires & BUTTON_MASK_B)
678.1852 +		{
678.1853 +			autoFire &= ~BUTTON_MASK_B;
678.1854 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_B_DISABLED));
678.1855 +		}
678.1856 +		else
678.1857 +		{
678.1858 +			autoFire |= BUTTON_MASK_B;
678.1859 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_B));
678.1860 +		}
678.1861 +		autoFire2       &= ~BUTTON_MASK_B;
678.1862 +		theApp.autoHold &= ~BUTTON_MASK_B;
678.1863 +		break;
678.1864 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_L:
678.1865 +		if (autoFires & BUTTON_MASK_L)
678.1866 +		{
678.1867 +			autoFire &= ~BUTTON_MASK_L;
678.1868 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_L_DISABLED));
678.1869 +		}
678.1870 +		else
678.1871 +		{
678.1872 +			autoFire |= BUTTON_MASK_L;
678.1873 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_L));
678.1874 +		}
678.1875 +		autoFire2       &= ~BUTTON_MASK_L;
678.1876 +		theApp.autoHold &= ~BUTTON_MASK_L;
678.1877 +		break;
678.1878 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_R:
678.1879 +		if (autoFires & BUTTON_MASK_R)
678.1880 +		{
678.1881 +			autoFire &= ~BUTTON_MASK_R;
678.1882 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_R_DISABLED));
678.1883 +		}
678.1884 +		else
678.1885 +		{
678.1886 +			autoFire |= BUTTON_MASK_R;
678.1887 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_R));
678.1888 +		}
678.1889 +		autoFire2       &= ~BUTTON_MASK_R;
678.1890 +		theApp.autoHold &= ~BUTTON_MASK_R;
678.1891 +		break;
678.1892 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_START:
678.1893 +		if (autoFires & BUTTON_MASK_START)
678.1894 +		{
678.1895 +			autoFire &= ~BUTTON_MASK_START;
678.1896 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_START_DISABLED));
678.1897 +		}
678.1898 +		else
678.1899 +		{
678.1900 +			autoFire |= BUTTON_MASK_START;
678.1901 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_START));
678.1902 +		}
678.1903 +		autoFire2       &= ~BUTTON_MASK_START;
678.1904 +		theApp.autoHold &= ~BUTTON_MASK_START;
678.1905 +		break;
678.1906 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_SELECT:
678.1907 +		if (autoFires & BUTTON_MASK_SELECT)
678.1908 +		{
678.1909 +			autoFire &= ~BUTTON_MASK_SELECT;
678.1910 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_SELECT_DISABLED));
678.1911 +		}
678.1912 +		else
678.1913 +		{
678.1914 +			autoFire |= BUTTON_MASK_SELECT;
678.1915 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_SELECT));
678.1916 +		}
678.1917 +		autoFire2       &= ~BUTTON_MASK_SELECT;
678.1918 +		theApp.autoHold &= ~BUTTON_MASK_SELECT;
678.1919 +		break;
678.1920 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_UP:
678.1921 +		if (autoFires & BUTTON_MASK_UP)
678.1922 +		{
678.1923 +			autoFire &= ~BUTTON_MASK_UP;
678.1924 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_UP_DISABLED));
678.1925 +		}
678.1926 +		else
678.1927 +		{
678.1928 +			autoFire |= BUTTON_MASK_UP;
678.1929 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_UP));
678.1930 +		}
678.1931 +		autoFire2       &= ~BUTTON_MASK_UP;
678.1932 +		theApp.autoHold &= ~BUTTON_MASK_UP;
678.1933 +		break;
678.1934 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_DOWN:
678.1935 +		if (autoFires & BUTTON_MASK_DOWN)
678.1936 +		{
678.1937 +			autoFire &= ~BUTTON_MASK_DOWN;
678.1938 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_DOWN_DISABLED));
678.1939 +		}
678.1940 +		else
678.1941 +		{
678.1942 +			autoFire |= BUTTON_MASK_DOWN;
678.1943 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_DOWN));
678.1944 +		}
678.1945 +		autoFire2       &= ~BUTTON_MASK_DOWN;
678.1946 +		theApp.autoHold &= ~BUTTON_MASK_DOWN;
678.1947 +		break;
678.1948 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_LEFT:
678.1949 +		if (autoFires & BUTTON_MASK_LEFT)
678.1950 +		{
678.1951 +			autoFire &= ~BUTTON_MASK_LEFT;
678.1952 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_LEFT_DISABLED));
678.1953 +		}
678.1954 +		else
678.1955 +		{
678.1956 +			autoFire |= BUTTON_MASK_LEFT;
678.1957 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_LEFT));
678.1958 +		}
678.1959 +		autoFire2       &= ~BUTTON_MASK_LEFT;
678.1960 +		theApp.autoHold &= ~BUTTON_MASK_LEFT;
678.1961 +		break;
678.1962 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_RIGHT:
678.1963 +		if (autoFires & BUTTON_MASK_RIGHT)
678.1964 +		{
678.1965 +			autoFire &= ~BUTTON_MASK_RIGHT;
678.1966 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_RIGHT_DISABLED));
678.1967 +		}
678.1968 +		else
678.1969 +		{
678.1970 +			autoFire |= BUTTON_MASK_RIGHT;
678.1971 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_RIGHT));
678.1972 +		}
678.1973 +		autoFire2       &= ~BUTTON_MASK_RIGHT;
678.1974 +		theApp.autoHold &= ~BUTTON_MASK_RIGHT;
678.1975 +		break;
678.1976 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_CLEAR:
678.1977 +		if (autoFires != 0)
678.1978 +		{
678.1979 +			theApp.autoFire = theApp.autoFire2 = 0;
678.1980 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_DISABLED));
678.1981 +		}
678.1982 +		else
678.1983 +		{
678.1984 +///      systemScreenMessage(winResLoadString(IDS_AUTOFIRE_ALREADY_DISABLED));
678.1985 +			systemScreenMessage("already cleared");
678.1986 +		}
678.1987 +		break;
678.1988 +	default:
678.1989 +		return FALSE;
678.1990 +	}
678.1991 +
678.1992 +	extern void VBAUpdateButtonPressDisplay(); VBAUpdateButtonPressDisplay();
678.1993 +
678.1994 +	return TRUE;
678.1995 +}
678.1996 +
678.1997 +void MainWnd::OnUpdateOptionsJoypadAutofire(CCmdUI *pCmdUI)
678.1998 +{
678.1999 +///  pCmdUI->Enable(emulating); // FIXME: this is right, but disabling menu items screws up accelerators until you view the
678.2000 +// menu!
678.2001 +	pCmdUI->Enable(TRUE); // TEMP
678.2002 +
678.2003 +	int autoFires = (theApp.autoFire | theApp.autoFire2);
678.2004 +
678.2005 +	bool check = true;
678.2006 +	switch (pCmdUI->m_nID)
678.2007 +	{
678.2008 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_A:
678.2009 +		check = (autoFires & BUTTON_MASK_A) != 0;
678.2010 +		break;
678.2011 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_B:
678.2012 +		check = (autoFires & BUTTON_MASK_B) != 0;
678.2013 +		break;
678.2014 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_L:
678.2015 +		check = (autoFires & BUTTON_MASK_L) != 0;
678.2016 +///	extern int gbSgbMode; // from gbSGB.cpp
678.2017 +///	if(emulating && systemCartridgeType != 0 && !gbSgbMode) // regular GB has no L button
678.2018 +///      pCmdUI->Enable(false); // FIXME: this is right, but disabling menu items screws up accelerators until you view the
678.2019 +// menu!
678.2020 +		break;
678.2021 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_R:
678.2022 +		check = (autoFires & BUTTON_MASK_R) != 0;
678.2023 +///	extern int gbSgbMode; // from gbSGB.cpp
678.2024 +///	if(emulating && systemCartridgeType != 0 && !gbSgbMode) // regular GB has no R button
678.2025 +///      pCmdUI->Enable(false); // FIXME: this is right, but disabling menu items screws up accelerators until you view the
678.2026 +// menu!
678.2027 +		break;
678.2028 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_START:
678.2029 +		check = (autoFires & BUTTON_MASK_START) != 0;
678.2030 +		break;
678.2031 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_SELECT:
678.2032 +		check = (autoFires & BUTTON_MASK_SELECT) != 0;
678.2033 +		break;
678.2034 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_UP:
678.2035 +		check = (autoFires & BUTTON_MASK_UP) != 0;
678.2036 +		break;
678.2037 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_DOWN:
678.2038 +		check = (autoFires & BUTTON_MASK_DOWN) != 0;
678.2039 +		break;
678.2040 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_LEFT:
678.2041 +		check = (autoFires & BUTTON_MASK_LEFT) != 0;
678.2042 +		break;
678.2043 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_RIGHT:
678.2044 +		check = (autoFires & BUTTON_MASK_RIGHT) != 0;
678.2045 +		break;
678.2046 +	case ID_OPTIONS_JOYPAD_AUTOFIRE_CLEAR:
678.2047 +		check = (autoFires == 0);
678.2048 +///    pCmdUI->Enable(!check); // FIXME: this is right, but disabling menu items screws up accelerators until you view the menu!
678.2049 +		break;
678.2050 +	}
678.2051 +	pCmdUI->SetCheck(check);
678.2052 +}
678.2053 +
678.2054 +BOOL MainWnd::OnOptionsJoypadSticky(UINT nID)
678.2055 +{
678.2056 +	switch (nID)
678.2057 +	{
678.2058 +	case ID_STICKY_A:
678.2059 +		if (theApp.autoHold & BUTTON_MASK_A)
678.2060 +		{
678.2061 +			theApp.autoHold &= ~BUTTON_MASK_A;
678.2062 +///      systemScreenMessage(winResLoadString(IDS_STICKY_A_DISABLED));
678.2063 +		}
678.2064 +		else
678.2065 +		{
678.2066 +			theApp.autoHold |= BUTTON_MASK_A;
678.2067 +///      systemScreenMessage(winResLoadString(IDS_STICKY_A));
678.2068 +		}
678.2069 +		theApp.autoFire  &= ~BUTTON_MASK_A;
678.2070 +		theApp.autoFire2 &= ~BUTTON_MASK_A;
678.2071 +		break;
678.2072 +	case ID_STICKY_B:
678.2073 +		if (theApp.autoHold & BUTTON_MASK_B)
678.2074 +		{
678.2075 +			theApp.autoHold &= ~BUTTON_MASK_B;
678.2076 +///      systemScreenMessage(winResLoadString(IDS_STICKY_B_DISABLED));
678.2077 +		}
678.2078 +		else
678.2079 +		{
678.2080 +			theApp.autoHold |= BUTTON_MASK_B;
678.2081 +///      systemScreenMessage(winResLoadString(IDS_STICKY_B));
678.2082 +		}
678.2083 +		theApp.autoFire  &= ~BUTTON_MASK_B;
678.2084 +		theApp.autoFire2 &= ~BUTTON_MASK_B;
678.2085 +		break;
678.2086 +	case ID_STICKY_L:
678.2087 +		if (theApp.autoHold & BUTTON_MASK_L)
678.2088 +		{
678.2089 +			theApp.autoHold &= ~BUTTON_MASK_L;
678.2090 +///      systemScreenMessage(winResLoadString(IDS_STICKY_L_DISABLED));
678.2091 +		}
678.2092 +		else
678.2093 +		{
678.2094 +			theApp.autoHold |= BUTTON_MASK_L;
678.2095 +///      systemScreenMessage(winResLoadString(IDS_STICKY_L));
678.2096 +		}
678.2097 +		theApp.autoFire  &= ~BUTTON_MASK_L;
678.2098 +		theApp.autoFire2 &= ~BUTTON_MASK_L;
678.2099 +		break;
678.2100 +	case ID_STICKY_R:
678.2101 +		if (theApp.autoHold & BUTTON_MASK_R)
678.2102 +		{
678.2103 +			theApp.autoHold &= ~BUTTON_MASK_R;
678.2104 +///      systemScreenMessage(winResLoadString(IDS_STICKY_R_DISABLED));
678.2105 +		}
678.2106 +		else
678.2107 +		{
678.2108 +			theApp.autoHold |= BUTTON_MASK_R;
678.2109 +///      systemScreenMessage(winResLoadString(IDS_STICKY_R));
678.2110 +		}
678.2111 +		theApp.autoFire  &= ~BUTTON_MASK_R;
678.2112 +		theApp.autoFire2 &= ~BUTTON_MASK_R;
678.2113 +		break;
678.2114 +	case ID_STICKY_START:
678.2115 +		if (theApp.autoHold & BUTTON_MASK_START)
678.2116 +		{
678.2117 +			theApp.autoHold &= ~BUTTON_MASK_START;
678.2118 +///      systemScreenMessage(winResLoadString(IDS_STICKY_START_DISABLED));
678.2119 +		}
678.2120 +		else
678.2121 +		{
678.2122 +			theApp.autoHold |= BUTTON_MASK_START;
678.2123 +///      systemScreenMessage(winResLoadString(IDS_STICKY_START));
678.2124 +		}
678.2125 +		theApp.autoFire  &= ~BUTTON_MASK_START;
678.2126 +		theApp.autoFire2 &= ~BUTTON_MASK_START;
678.2127 +		break;
678.2128 +	case ID_STICKY_SELECT:
678.2129 +		if (theApp.autoHold & BUTTON_MASK_SELECT)
678.2130 +		{
678.2131 +			theApp.autoHold &= ~BUTTON_MASK_SELECT;
678.2132 +///      systemScreenMessage(winResLoadString(IDS_STICKY_SELECT_DISABLED));
678.2133 +		}
678.2134 +		else
678.2135 +		{
678.2136 +			theApp.autoHold |= BUTTON_MASK_SELECT;
678.2137 +///      systemScreenMessage(winResLoadString(IDS_STICKY_SELECT));
678.2138 +		}
678.2139 +		theApp.autoFire  &= ~BUTTON_MASK_SELECT;
678.2140 +		theApp.autoFire2 &= ~BUTTON_MASK_SELECT;
678.2141 +		break;
678.2142 +	case ID_STICKY_UP:
678.2143 +		if (theApp.autoHold & BUTTON_MASK_UP)
678.2144 +		{
678.2145 +			theApp.autoHold &= ~BUTTON_MASK_UP;
678.2146 +///      systemScreenMessage(winResLoadString(IDS_STICKY_UP_DISABLED));
678.2147 +		}
678.2148 +		else
678.2149 +		{
678.2150 +			theApp.autoHold |= BUTTON_MASK_UP;
678.2151 +///      systemScreenMessage(winResLoadString(IDS_STICKY_UP));
678.2152 +		}
678.2153 +		theApp.autoFire  &= ~BUTTON_MASK_UP;
678.2154 +		theApp.autoFire2 &= ~BUTTON_MASK_UP;
678.2155 +		if (!theApp.allowLeftRight)
678.2156 +			theApp.autoHold &= ~BUTTON_MASK_DOWN;
678.2157 +		break;
678.2158 +	case ID_STICKY_DOWN:
678.2159 +		if (theApp.autoHold & BUTTON_MASK_DOWN)
678.2160 +		{
678.2161 +			theApp.autoHold &= ~BUTTON_MASK_DOWN;
678.2162 +///      systemScreenMessage(winResLoadString(IDS_STICKY_DOWN_DISABLED));
678.2163 +		}
678.2164 +		else
678.2165 +		{
678.2166 +			theApp.autoHold |= BUTTON_MASK_DOWN;
678.2167 +///      systemScreenMessage(winResLoadString(IDS_STICKY_DOWN));
678.2168 +		}
678.2169 +		theApp.autoFire  &= ~BUTTON_MASK_DOWN;
678.2170 +		theApp.autoFire2 &= ~BUTTON_MASK_DOWN;
678.2171 +		if (!theApp.allowLeftRight)
678.2172 +			theApp.autoHold &= ~BUTTON_MASK_UP;
678.2173 +		break;
678.2174 +	case ID_STICKY_LEFT:
678.2175 +		if (theApp.autoHold & BUTTON_MASK_LEFT)
678.2176 +		{
678.2177 +			theApp.autoHold &= ~BUTTON_MASK_LEFT;
678.2178 +///      systemScreenMessage(winResLoadString(IDS_STICKY_LEFT_DISABLED));
678.2179 +		}
678.2180 +		else
678.2181 +		{
678.2182 +			theApp.autoHold |= BUTTON_MASK_LEFT;
678.2183 +///      systemScreenMessage(winResLoadString(IDS_STICKY_LEFT));
678.2184 +		}
678.2185 +		theApp.autoFire  &= ~BUTTON_MASK_LEFT;
678.2186 +		theApp.autoFire2 &= ~BUTTON_MASK_LEFT;
678.2187 +		if (!theApp.allowLeftRight)
678.2188 +			theApp.autoHold &= ~BUTTON_MASK_RIGHT;
678.2189 +		break;
678.2190 +	case ID_STICKY_RIGHT:
678.2191 +		if (theApp.autoHold & BUTTON_MASK_RIGHT)
678.2192 +		{
678.2193 +			theApp.autoHold &= ~BUTTON_MASK_RIGHT;
678.2194 +///      systemScreenMessage(winResLoadString(IDS_STICKY_RIGHT_DISABLED));
678.2195 +		}
678.2196 +		else
678.2197 +		{
678.2198 +			theApp.autoHold |= BUTTON_MASK_RIGHT;
678.2199 +///      systemScreenMessage(winResLoadString(IDS_STICKY_RIGHT));
678.2200 +		}
678.2201 +		theApp.autoFire  &= ~BUTTON_MASK_RIGHT;
678.2202 +		theApp.autoFire2 &= ~BUTTON_MASK_RIGHT;
678.2203 +		if (!theApp.allowLeftRight)
678.2204 +			theApp.autoHold &= ~BUTTON_MASK_LEFT;
678.2205 +		break;
678.2206 +	case ID_STICKY_CLEAR:
678.2207 +		if (theApp.autoHold != 0)
678.2208 +		{
678.2209 +			theApp.autoHold = 0;
678.2210 +///      systemScreenMessage(winResLoadString(IDS_STICKY_DISABLED));
678.2211 +		}
678.2212 +		else
678.2213 +		{
678.2214 +///      systemScreenMessage(winResLoadString(IDS_STICKY_ALREADY_DISABLED));
678.2215 +			systemScreenMessage("already cleared");
678.2216 +		}
678.2217 +		break;
678.2218 +	default:
678.2219 +		return FALSE;
678.2220 +	}
678.2221 +
678.2222 +	extern void VBAUpdateButtonPressDisplay(); VBAUpdateButtonPressDisplay();
678.2223 +
678.2224 +	return TRUE;
678.2225 +}
678.2226 +
678.2227 +void MainWnd::OnUpdateOptionsJoypadSticky(CCmdUI *pCmdUI)
678.2228 +{
678.2229 +///  pCmdUI->Enable(emulating); // FIXME: this is right, but disabling menu items screws up accelerators until you view the
678.2230 +// menu!
678.2231 +	pCmdUI->Enable(TRUE); // TEMP
678.2232 +
678.2233 +	bool check = true;
678.2234 +	switch (pCmdUI->m_nID)
678.2235 +	{
678.2236 +	case ID_STICKY_A:
678.2237 +		check = (theApp.autoHold & BUTTON_MASK_A) != 0;
678.2238 +		break;
678.2239 +	case ID_STICKY_B:
678.2240 +		check = (theApp.autoHold & BUTTON_MASK_B) != 0;
678.2241 +		break;
678.2242 +	case ID_STICKY_L:
678.2243 +		check = (theApp.autoHold & BUTTON_MASK_L) != 0;
678.2244 +///	extern int gbSgbMode; // from gbSGB.cpp
678.2245 +///	if(emulating && systemCartridgeType != 0 && !gbSgbMode) // regular GB has no L button
678.2246 +///      pCmdUI->Enable(false); // FIXME: this is right, but disabling menu items screws up accelerators until you view the
678.2247 +// menu!
678.2248 +		break;
678.2249 +	case ID_STICKY_R:
678.2250 +		check = (theApp.autoHold & BUTTON_MASK_R) != 0;
678.2251 +///	extern int gbSgbMode; // from gbSGB.cpp
678.2252 +///	if(emulating && systemCartridgeType != 0 && !gbSgbMode) // regular GB has no R button
678.2253 +///      pCmdUI->Enable(false); // FIXME: this is right, but disabling menu items screws up accelerators until you view the
678.2254 +// menu!
678.2255 +		break;
678.2256 +	case ID_STICKY_START:
678.2257 +		check = (theApp.autoHold & BUTTON_MASK_START) != 0;
678.2258 +		break;
678.2259 +	case ID_STICKY_SELECT:
678.2260 +		check = (theApp.autoHold & BUTTON_MASK_SELECT) != 0;
678.2261 +		break;
678.2262 +	case ID_STICKY_UP:
678.2263 +		check = (theApp.autoHold & BUTTON_MASK_UP) != 0;
678.2264 +		break;
678.2265 +	case ID_STICKY_DOWN:
678.2266 +		check = (theApp.autoHold & BUTTON_MASK_DOWN) != 0;
678.2267 +		break;
678.2268 +	case ID_STICKY_LEFT:
678.2269 +		check = (theApp.autoHold & BUTTON_MASK_LEFT) != 0;
678.2270 +		break;
678.2271 +	case ID_STICKY_RIGHT:
678.2272 +		check = (theApp.autoHold & BUTTON_MASK_RIGHT) != 0;
678.2273 +		break;
678.2274 +	case ID_STICKY_CLEAR:
678.2275 +		check = (theApp.autoHold == 0);
678.2276 +///    pCmdUI->Enable(!check); // FIXME: this is right, but disabling menu items screws up accelerators until you view the menu!
678.2277 +		break;
678.2278 +	}
678.2279 +	pCmdUI->SetCheck(check);
678.2280 +}
678.2281 +
678.2282 +LRESULT MainWnd::OnConfirmMode(WPARAM, LPARAM)
678.2283 +{
678.2284 +	// we need to do this separately or the window will not have the right
678.2285 +	// parent. must be related to the way MFC does modal dialogs
678.2286 +	winConfirmMode();
678.2287 +	return 0;
678.2288 +}
678.2289 +
678.2290 +void MainWnd::OnOptionsVideoFullscreenmaxscale()
678.2291 +{
678.2292 +	MaxScale dlg;
678.2293 +
678.2294 +	theApp.winCheckFullscreen();
678.2295 +
678.2296 +	dlg.DoModal();
678.2297 +}
678.2298 +
678.2299 +void MainWnd::OnOptionsVideoTextdisplayoptions()
678.2300 +{
678.2301 +	TextOptions dlg;
678.2302 +
678.2303 +	theApp.winCheckFullscreen();
678.2304 +
678.2305 +	dlg.DoModal();
678.2306 +}
678.2307 +
678.2308 +void MainWnd::OnUpdateOptionsVideoTextdisplayoptions(CCmdUI *pCmdUI)
678.2309 +{
678.2310 +	pCmdUI->Enable(TRUE);
678.2311 +}
678.2312 +
   679.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   679.2 +++ b/src/win32/MainWndTools.cpp	Sat Mar 03 10:31:27 2012 -0600
   679.3 @@ -0,0 +1,1000 @@
   679.4 +#include "stdafx.h"
   679.5 +#include <cassert>
   679.6 +#include "resource.h"
   679.7 +#include "MainWnd.h"
   679.8 +#include "AccelEditor.h"
   679.9 +#include "AVIWrite.h"
  679.10 +#include "Disassemble.h"
  679.11 +#include "FileDlg.h"
  679.12 +#include "GBDisassemble.h"
  679.13 +#include "GBMapView.h"
  679.14 +#include "GBMemoryViewerDlg.h"
  679.15 +#include "GBOamView.h"
  679.16 +#include "GBPaletteView.h"
  679.17 +#include "GBTileView.h"
  679.18 +#include "GDBConnection.h"
  679.19 +#include "IOViewer.h"
  679.20 +#include "MapView.h"
  679.21 +#include "MemoryViewerDlg.h"
  679.22 +#include "MovieOpen.h"
  679.23 +#include "MovieCreate.h"
  679.24 +#include "OamView.h"
  679.25 +#include "PaletteView.h"
  679.26 +#include "Reg.h"
  679.27 +#include "TileView.h"
  679.28 +#include "WavWriter.h"
  679.29 +#include "WinResUtil.h"
  679.30 +#include "WinMiscUtil.h"
  679.31 +#include "VBA.h"
  679.32 +
  679.33 +#include "../gba/GBA.h"
  679.34 +#include "../gba/GBAGlobals.h"
  679.35 +#include "../gb/GB.h"
  679.36 +
  679.37 +extern int32 gbBorderOn;
  679.38 +extern int32 soundQuality;
  679.39 +
  679.40 +extern bool debugger;
  679.41 +extern int	emulating;
  679.42 +extern int	remoteSocket;
  679.43 +
  679.44 +extern void remoteCleanUp();
  679.45 +extern void remoteSetSockets(SOCKET, SOCKET);
  679.46 +extern void toolsLogging();
  679.47 +
  679.48 +void MainWnd::OnToolsDisassemble()
  679.49 +{
  679.50 +	if (systemCartridgeType == 0)
  679.51 +	{
  679.52 +		Disassemble *dlg = new Disassemble();
  679.53 +		dlg->Create(IDD_DISASSEMBLE, this);
  679.54 +		dlg->ShowWindow(SW_SHOW);
  679.55 +	}
  679.56 +	else
  679.57 +	{
  679.58 +		GBDisassemble *dlg = new GBDisassemble();
  679.59 +		dlg->Create(IDD_GB_DISASSEMBLE, this);
  679.60 +		dlg->ShowWindow(SW_SHOW);
  679.61 +	}
  679.62 +}
  679.63 +
  679.64 +void MainWnd::OnUpdateToolsDisassemble(CCmdUI *pCmdUI)
  679.65 +{
  679.66 +	pCmdUI->Enable(theApp.videoOption <= VIDEO_4X);
  679.67 +}
  679.68 +
  679.69 +void MainWnd::OnToolsLogging()
  679.70 +{
  679.71 +	toolsLogging();
  679.72 +}
  679.73 +
  679.74 +void MainWnd::OnUpdateToolsLogging(CCmdUI *pCmdUI)
  679.75 +{
  679.76 +	pCmdUI->Enable(theApp.videoOption <= VIDEO_4X);
  679.77 +}
  679.78 +
  679.79 +void MainWnd::OnToolsIoviewer()
  679.80 +{
  679.81 +	IOViewer *dlg = new IOViewer;
  679.82 +	dlg->Create(IDD_IO_VIEWER, this);
  679.83 +	dlg->ShowWindow(SW_SHOW);
  679.84 +}
  679.85 +
  679.86 +void MainWnd::OnUpdateToolsIoviewer(CCmdUI *pCmdUI)
  679.87 +{
  679.88 +	pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && systemCartridgeType == 0);
  679.89 +}
  679.90 +
  679.91 +void MainWnd::OnToolsMapview()
  679.92 +{
  679.93 +	if (systemCartridgeType == 0)
  679.94 +	{
  679.95 +		MapView *dlg = new MapView;
  679.96 +		dlg->Create(IDD_MAP_VIEW, this);
  679.97 +		dlg->ShowWindow(SW_SHOW);
  679.98 +	}
  679.99 +	else
 679.100 +	{
 679.101 +		GBMapView *dlg = new GBMapView;
 679.102 +		dlg->Create(IDD_GB_MAP_VIEW, this);
 679.103 +		dlg->ShowWindow(SW_SHOW);
 679.104 +	}
 679.105 +}
 679.106 +
 679.107 +void MainWnd::OnUpdateToolsMapview(CCmdUI *pCmdUI)
 679.108 +{
 679.109 +	pCmdUI->Enable(theApp.videoOption <= VIDEO_4X);
 679.110 +}
 679.111 +
 679.112 +void MainWnd::OnToolsMemoryviewer()
 679.113 +{
 679.114 +	if (systemCartridgeType == 0)
 679.115 +	{
 679.116 +		MemoryViewerDlg *dlg = new MemoryViewerDlg;
 679.117 +		dlg->Create(IDD_MEM_VIEWER, this);
 679.118 +		dlg->ShowWindow(SW_SHOW);
 679.119 +	}
 679.120 +	else
 679.121 +	{
 679.122 +		GBMemoryViewerDlg *dlg = new GBMemoryViewerDlg;
 679.123 +		dlg->Create(IDD_MEM_VIEWER, this);
 679.124 +		dlg->ShowWindow(SW_SHOW);
 679.125 +	}
 679.126 +}
 679.127 +
 679.128 +void MainWnd::OnUpdateToolsMemoryviewer(CCmdUI *pCmdUI)
 679.129 +{
 679.130 +	pCmdUI->Enable(theApp.videoOption <= VIDEO_4X);
 679.131 +}
 679.132 +
 679.133 +void MainWnd::OnToolsOamviewer()
 679.134 +{
 679.135 +	if (systemCartridgeType == 0)
 679.136 +	{
 679.137 +		OamView *dlg = new OamView;
 679.138 +		dlg->Create(IDD_OAM_VIEW, this);
 679.139 +		dlg->ShowWindow(SW_SHOW);
 679.140 +	}
 679.141 +	else
 679.142 +	{
 679.143 +		GBOamView *dlg = new GBOamView;
 679.144 +		dlg->Create(IDD_GB_OAM_VIEW, this);
 679.145 +		dlg->ShowWindow(SW_SHOW);
 679.146 +	}
 679.147 +}
 679.148 +
 679.149 +void MainWnd::OnUpdateToolsOamviewer(CCmdUI *pCmdUI)
 679.150 +{
 679.151 +	pCmdUI->Enable(theApp.videoOption <= VIDEO_4X);
 679.152 +}
 679.153 +
 679.154 +void MainWnd::OnToolsPaletteview()
 679.155 +{
 679.156 +	if (systemCartridgeType == 0)
 679.157 +	{
 679.158 +		PaletteView *dlg = new PaletteView;
 679.159 +		dlg->Create(IDD_PALETTE_VIEW, this);
 679.160 +		dlg->ShowWindow(SW_SHOW);
 679.161 +	}
 679.162 +	else
 679.163 +	{
 679.164 +		GBPaletteView *dlg = new GBPaletteView;
 679.165 +		dlg->Create(IDD_GB_PALETTE_VIEW, this);
 679.166 +		dlg->ShowWindow(SW_SHOW);
 679.167 +	}
 679.168 +}
 679.169 +
 679.170 +void MainWnd::OnUpdateToolsPaletteview(CCmdUI *pCmdUI)
 679.171 +{
 679.172 +	pCmdUI->Enable(theApp.videoOption <= VIDEO_4X);
 679.173 +}
 679.174 +
 679.175 +void MainWnd::OnToolsTileviewer()
 679.176 +{
 679.177 +	if (systemCartridgeType == 0)
 679.178 +	{
 679.179 +		TileView *dlg = new TileView;
 679.180 +		dlg->Create(IDD_TILE_VIEWER, this);
 679.181 +		dlg->ShowWindow(SW_SHOW);
 679.182 +	}
 679.183 +	else
 679.184 +	{
 679.185 +		GBTileView *dlg = new GBTileView;
 679.186 +		dlg->Create(IDD_GB_TILE_VIEWER, this);
 679.187 +		dlg->ShowWindow(SW_SHOW);
 679.188 +	}
 679.189 +}
 679.190 +
 679.191 +void MainWnd::OnUpdateToolsTileviewer(CCmdUI *pCmdUI)
 679.192 +{
 679.193 +	pCmdUI->Enable(theApp.videoOption <= VIDEO_4X);
 679.194 +}
 679.195 +
 679.196 +void MainWnd::OnDebugNextframe()
 679.197 +{
 679.198 +	systemSetPause(false);
 679.199 +	theApp.winPauseNextFrame = true;
 679.200 +}
 679.201 +
 679.202 +void MainWnd::OnUpdateDebugNextframe(CCmdUI *pCmdUI)
 679.203 +{
 679.204 +	pCmdUI->Enable(emulating);
 679.205 +}
 679.206 +
 679.207 +void MainWnd::OnDebugNextframeAccountForLag()
 679.208 +{
 679.209 +	theApp.nextframeAccountForLag = !theApp.nextframeAccountForLag;
 679.210 +}
 679.211 +
 679.212 +void MainWnd::OnUpdateDebugNextframeAccountForLag(CCmdUI *pCmdUI)
 679.213 +{
 679.214 +	pCmdUI->SetCheck(theApp.nextframeAccountForLag);
 679.215 +}
 679.216 +
 679.217 +void MainWnd::OnDebugFramesearch()
 679.218 +{
 679.219 +	extern u16	  currentButtons [4];  // from System.cpp
 679.220 +	extern SMovie Movie;
 679.221 +	if (!theApp.frameSearching)
 679.222 +	{
 679.223 +		// starting a new search
 679.224 +		theApp.frameSearching		= true;
 679.225 +		theApp.frameSearchStart		= (Movie.state == MOVIE_STATE_NONE) ? systemCounters.frameCount : Movie.currentFrame;
 679.226 +		theApp.frameSearchLength	= 0;
 679.227 +		theApp.frameSearchLoadValid = false;
 679.228 +		theApp.emulator.emuWriteMemState(&theApp.frameSearchMemory[REWIND_SIZE * 0], REWIND_SIZE); // 0 is start state, 1 is
 679.229 +		                                                                                           // intermediate state (for
 679.230 +		                                                                                           // speedup when going
 679.231 +		                                                                                           // forward),
 679.232 +		                                                                                           // 2 is end state
 679.233 +		theApp.emulator.emuWriteMemState(&theApp.frameSearchMemory[REWIND_SIZE * 1], REWIND_SIZE);
 679.234 +
 679.235 +		// store old buttons from frame before the search
 679.236 +		for (int i = 0; i < 4; i++)
 679.237 +			theApp.frameSearchOldInput[i] = currentButtons[i];
 679.238 +	}
 679.239 +	else
 679.240 +	{
 679.241 +		// advance forward 1 step in the search
 679.242 +		theApp.frameSearchLength++;
 679.243 +
 679.244 +		// try it
 679.245 +		theApp.emulator.emuReadMemState(&theApp.frameSearchMemory[REWIND_SIZE * 1], REWIND_SIZE);
 679.246 +	}
 679.247 +
 679.248 +	char str [32];
 679.249 +	sprintf(str, "%d frame search", theApp.frameSearchLength);
 679.250 +	systemScreenMessage(str, 0);
 679.251 +
 679.252 +	theApp.frameSearchSkipping = true;
 679.253 +
 679.254 +	// make sure the display updates at least 1 frame to show the new message
 679.255 +	theApp.frameSearchFirstStep = true;
 679.256 +
 679.257 +	if (theApp.paused)
 679.258 +		theApp.paused = false;
 679.259 +}
 679.260 +
 679.261 +void MainWnd::OnUpdateDebugFramesearch(CCmdUI *pCmdUI)
 679.262 +{
 679.263 +	extern SMovie Movie;
 679.264 +	pCmdUI->Enable(emulating && Movie.state != MOVIE_STATE_PLAY);
 679.265 +	pCmdUI->SetCheck(theApp.frameSearching);
 679.266 +}
 679.267 +
 679.268 +void MainWnd::OnDebugFramesearchPrev()
 679.269 +{
 679.270 +	if (theApp.frameSearching)
 679.271 +	{
 679.272 +		if (theApp.frameSearchLength > 0)
 679.273 +		{
 679.274 +			// rewind 1 step in the search
 679.275 +			theApp.frameSearchLength--;
 679.276 +		}
 679.277 +
 679.278 +		// try it
 679.279 +		theApp.emulator.emuReadMemState(&theApp.frameSearchMemory[REWIND_SIZE * 0], REWIND_SIZE);
 679.280 +
 679.281 +		char str[32];
 679.282 +		sprintf(str, "%d frame search", theApp.frameSearchLength);
 679.283 +		systemScreenMessage(str, 0);
 679.284 +
 679.285 +		theApp.frameSearchSkipping = true;
 679.286 +
 679.287 +		// make sure the display updates at least 1 frame to show the new message
 679.288 +		theApp.frameSearchFirstStep = true;
 679.289 +
 679.290 +		if (theApp.paused)
 679.291 +			theApp.paused = false;
 679.292 +	}
 679.293 +}
 679.294 +
 679.295 +void MainWnd::OnUpdateDebugFramesearchPrev(CCmdUI *pCmdUI)
 679.296 +{
 679.297 +	extern SMovie Movie;
 679.298 +	pCmdUI->Enable(emulating && theApp.frameSearching && Movie.state != MOVIE_STATE_PLAY);
 679.299 +}
 679.300 +
 679.301 +void MainWnd::OnDebugFramesearchLoad()
 679.302 +{
 679.303 +	if (theApp.frameSearchLoadValid)
 679.304 +	{
 679.305 +		theApp.emulator.emuReadMemState(&theApp.frameSearchMemory[REWIND_SIZE * 2], REWIND_SIZE);
 679.306 +		theApp.paused = true;
 679.307 +
 679.308 +		if (theApp.frameSearching)
 679.309 +			systemScreenMessage("end frame search", 0);
 679.310 +		else
 679.311 +			systemScreenMessage("restore search end", 0);
 679.312 +	}
 679.313 +	theApp.frameSearching	   = false;
 679.314 +	theApp.frameSearchSkipping = false;
 679.315 +}
 679.316 +
 679.317 +void MainWnd::OnUpdateDebugFramesearchLoad(CCmdUI *pCmdUI)
 679.318 +{
 679.319 +	extern SMovie Movie;
 679.320 +	pCmdUI->Enable(emulating && Movie.state != MOVIE_STATE_PLAY);
 679.321 +}
 679.322 +
 679.323 +void MainWnd::OnToolsFrameCounter()
 679.324 +{
 679.325 +	theApp.frameCounter = !theApp.frameCounter;
 679.326 +	extern void VBAUpdateFrameCountDisplay(); VBAUpdateFrameCountDisplay();
 679.327 +}
 679.328 +
 679.329 +void MainWnd::OnUpdateToolsFrameCounter(CCmdUI *pCmdUI)
 679.330 +{
 679.331 +	pCmdUI->SetCheck(theApp.frameCounter);
 679.332 +}
 679.333 +
 679.334 +void MainWnd::OnToolsLagCounter()
 679.335 +{
 679.336 +	theApp.lagCounter = !theApp.lagCounter;
 679.337 +	extern void VBAUpdateFrameCountDisplay(); VBAUpdateFrameCountDisplay();
 679.338 +}
 679.339 +
 679.340 +void MainWnd::OnUpdateToolsLagCounter(CCmdUI *pCmdUI)
 679.341 +{
 679.342 +	pCmdUI->SetCheck(theApp.lagCounter);
 679.343 +}
 679.344 +
 679.345 +void MainWnd::OnToolsExtraCounter()
 679.346 +{
 679.347 +	theApp.extraCounter = !theApp.extraCounter;
 679.348 +	extern void VBAUpdateFrameCountDisplay(); VBAUpdateFrameCountDisplay();
 679.349 +}
 679.350 +
 679.351 +void MainWnd::OnUpdateToolsExtraCounter(CCmdUI *pCmdUI)
 679.352 +{
 679.353 +	pCmdUI->SetCheck(theApp.extraCounter);
 679.354 +}
 679.355 +
 679.356 +void MainWnd::OnToolsExtraCounterReset()
 679.357 +{
 679.358 +	systemCounters.extraCount = systemCounters.frameCount;
 679.359 +}
 679.360 +
 679.361 +void MainWnd::OnToolsInputDisplay()
 679.362 +{
 679.363 +	theApp.inputDisplay = !theApp.inputDisplay;
 679.364 +	systemScreenMessage(theApp.inputDisplay ? "Input Display On" : "Input Display Off");
 679.365 +	extern void VBAUpdateButtonPressDisplay(); VBAUpdateButtonPressDisplay();
 679.366 +}
 679.367 +
 679.368 +void MainWnd::OnUpdateToolsInputDisplay(CCmdUI *pCmdUI)
 679.369 +{
 679.370 +	pCmdUI->SetCheck(theApp.inputDisplay);
 679.371 +}
 679.372 +
 679.373 +void MainWnd::OnToolsDebugGdb()
 679.374 +{
 679.375 +	theApp.winCheckFullscreen();
 679.376 +	GDBPortDlg dlg;
 679.377 +
 679.378 +	if (dlg.DoModal())
 679.379 +	{
 679.380 +		GDBWaitingDlg wait(dlg.getSocket(), dlg.getPort());
 679.381 +		if (wait.DoModal())
 679.382 +		{
 679.383 +			remoteSetSockets(wait.getListenSocket(), wait.getSocket());
 679.384 +			debugger  = true;
 679.385 +			emulating = 1;
 679.386 +			systemCartridgeType = 0;
 679.387 +			theApp.gameFilename = "\\gnu_stub";
 679.388 +			rom					= (u8 *)malloc(0x2000000 + 4);
 679.389 +			workRAM				= (u8 *)calloc(1, 0x40000 + 4);
 679.390 +			bios				= (u8 *)calloc(1, 0x4000 + 4);
 679.391 +			internalRAM			= (u8 *)calloc(1, 0x8000 + 4);
 679.392 +			paletteRAM			= (u8 *)calloc(1, 0x400 + 4);
 679.393 +			vram				= (u8 *)calloc(1, 0x20000 + 4);
 679.394 +			oam					= (u8 *)calloc(1, 0x400 + 4);
 679.395 +			pix					= (u8 *)calloc(1, 4 * 240 * 160);
 679.396 +			ioMem				= (u8 *)calloc(1, 0x400 + 4);
 679.397 +
 679.398 +			theApp.emulator = GBASystem;
 679.399 +
 679.400 +			CPUInit();
 679.401 +			CPULoadBios(theApp.biosFileName, theApp.useBiosFile ? true : false);
 679.402 +			CPUReset();
 679.403 +		}
 679.404 +	}
 679.405 +}
 679.406 +
 679.407 +void MainWnd::OnUpdateToolsDebugGdb(CCmdUI *pCmdUI)
 679.408 +{
 679.409 +	pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket == -1);
 679.410 +}
 679.411 +
 679.412 +void MainWnd::OnToolsDebugLoadandwait()
 679.413 +{
 679.414 +	theApp.winCheckFullscreen();
 679.415 +	if (winFileOpenSelect(0))
 679.416 +	{
 679.417 +		if (winFileRun())
 679.418 +		{
 679.419 +			if (systemCartridgeType != 0)
 679.420 +			{
 679.421 +				systemMessage(IDS_ERROR_NOT_GBA_IMAGE, "Error: not a GBA image");
 679.422 +				OnFileClose();
 679.423 +				return;
 679.424 +			}
 679.425 +			GDBPortDlg dlg;
 679.426 +
 679.427 +			if (dlg.DoModal())
 679.428 +			{
 679.429 +				GDBWaitingDlg wait(dlg.getSocket(), dlg.getPort());
 679.430 +				if (wait.DoModal())
 679.431 +				{
 679.432 +					remoteSetSockets(wait.getListenSocket(), wait.getSocket());
 679.433 +					debugger  = true;
 679.434 +					emulating = 1;
 679.435 +				}
 679.436 +			}
 679.437 +		}
 679.438 +	}
 679.439 +}
 679.440 +
 679.441 +void MainWnd::OnUpdateToolsDebugLoadandwait(CCmdUI *pCmdUI)
 679.442 +{
 679.443 +	pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket == -1);
 679.444 +}
 679.445 +
 679.446 +void MainWnd::OnToolsDebugBreak()
 679.447 +{
 679.448 +	if (armState)
 679.449 +	{
 679.450 +		armNextPC -= 4;
 679.451 +		reg[15].I -= 4;
 679.452 +	}
 679.453 +	else
 679.454 +	{
 679.455 +		armNextPC -= 2;
 679.456 +		reg[15].I -= 2;
 679.457 +	}
 679.458 +	debugger = true;
 679.459 +}
 679.460 +
 679.461 +void MainWnd::OnUpdateToolsDebugBreak(CCmdUI *pCmdUI)
 679.462 +{
 679.463 +	pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket != -1);
 679.464 +}
 679.465 +
 679.466 +void MainWnd::OnToolsDebugDisconnect()
 679.467 +{
 679.468 +	remoteCleanUp();
 679.469 +	debugger = false;
 679.470 +}
 679.471 +
 679.472 +void MainWnd::OnUpdateToolsDebugDisconnect(CCmdUI *pCmdUI)
 679.473 +{
 679.474 +	pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket != -1);
 679.475 +}
 679.476 +
 679.477 +void MainWnd::OnToolsSoundRecording()
 679.478 +{
 679.479 +	if (!theApp.soundRecording)
 679.480 +		OnToolsSoundStartrecording();
 679.481 +	else
 679.482 +		OnToolsSoundStoprecording();
 679.483 +}
 679.484 +
 679.485 +void MainWnd::OnToolsSoundStartrecording()
 679.486 +{
 679.487 +	theApp.winCheckFullscreen();
 679.488 +
 679.489 +	CString wavName = theApp.gameFilename;
 679.490 +
 679.491 +	if (VBAMovieActive())
 679.492 +	{
 679.493 +		extern SMovie Movie;
 679.494 +		wavName = Movie.filename;
 679.495 +		int index = wavName.ReverseFind('.');
 679.496 +		if (index != -1)
 679.497 +			wavName = wavName.Left(index);
 679.498 +	}
 679.499 +
 679.500 +	LPCTSTR exts[] = { ".wav", NULL };
 679.501 +
 679.502 +	CString filter = winResLoadFilter(IDS_FILTER_WAV);
 679.503 +	CString title  = winResLoadString(IDS_SELECT_WAV_NAME);
 679.504 +
 679.505 +	wavName = winGetDestFilename(wavName, IDS_WAV_DIR, exts[0]);
 679.506 +	CString wavDir = winGetDestDir(IDS_WAV_DIR);
 679.507 +
 679.508 +	FileDlg dlg(this, wavName, filter, 1, "WAV", exts, wavDir, title, true);
 679.509 +
 679.510 +	if (dlg.DoModal() == IDCANCEL)
 679.511 +	{
 679.512 +		return;
 679.513 +	}
 679.514 +
 679.515 +	theApp.soundRecordName = dlg.GetPathName();
 679.516 +	theApp.soundRecording  = true;
 679.517 +}
 679.518 +
 679.519 +void MainWnd::OnToolsSoundStoprecording()
 679.520 +{
 679.521 +	if (theApp.soundRecorder)
 679.522 +	{
 679.523 +		delete theApp.soundRecorder;
 679.524 +		theApp.soundRecorder = NULL;
 679.525 +	}
 679.526 +	theApp.soundRecording = false;
 679.527 +}
 679.528 +
 679.529 +void MainWnd::OnUpdateToolsSoundRecording(CCmdUI *pCmdUI)
 679.530 +{
 679.531 +	if (pCmdUI->m_pMenu != NULL)
 679.532 +	{
 679.533 +		if (!theApp.soundRecording)
 679.534 +			pCmdUI->SetText(winResLoadString(IDS_STARTSOUNDRECORDING));
 679.535 +		else
 679.536 +			pCmdUI->SetText(winResLoadString(IDS_STOPSOUNDRECORDING));
 679.537 +
 679.538 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
 679.539 +	}
 679.540 +
 679.541 +	pCmdUI->Enable(emulating);
 679.542 +}
 679.543 +
 679.544 +void MainWnd::OnToolsAVIRecording()
 679.545 +{
 679.546 +	if (!theApp.aviRecording)
 679.547 +		OnToolsStartAVIRecording();
 679.548 +	else
 679.549 +		OnToolsStopAVIRecording();
 679.550 +}
 679.551 +
 679.552 +void MainWnd::OnToolsStartAVIRecording()
 679.553 +{
 679.554 +	theApp.winCheckFullscreen();
 679.555 +
 679.556 +	CString aviName = theApp.gameFilename;
 679.557 +
 679.558 +	if (VBAMovieActive())
 679.559 +	{
 679.560 +		extern SMovie Movie;
 679.561 +		aviName = Movie.filename;
 679.562 +		int index = aviName.ReverseFind('.');
 679.563 +		if (index != -1)
 679.564 +			aviName = aviName.Left(index);
 679.565 +	}
 679.566 +
 679.567 +	LPCTSTR exts[] = { ".avi", NULL };
 679.568 +
 679.569 +	CString filter = winResLoadFilter(IDS_FILTER_AVI);
 679.570 +	CString title  = winResLoadString(IDS_SELECT_AVI_NAME);
 679.571 +
 679.572 +	aviName = winGetDestFilename(aviName, IDS_AVI_DIR, exts[0]);
 679.573 +	CString aviDir = winGetDestDir(IDS_AVI_DIR);
 679.574 +
 679.575 +	FileDlg dlg(this, aviName, filter, 1, "AVI", exts, aviDir, title, true);
 679.576 +
 679.577 +	if (dlg.DoModal() == IDCANCEL)
 679.578 +	{
 679.579 +		return;
 679.580 +	}
 679.581 +
 679.582 +	theApp.aviRecordName = theApp.soundRecordName =  dlg.GetPathName();
 679.583 +	theApp.aviRecording	 = true;
 679.584 +
 679.585 +///  extern long linearFrameCount; linearFrameCount = 0;
 679.586 +///  extern long linearSoundByteCount; linearSoundByteCount = 0;
 679.587 +
 679.588 +	if (theApp.aviRecorder == NULL)
 679.589 +	{
 679.590 +		int width  = 240;
 679.591 +		int height = 160;
 679.592 +		switch (systemCartridgeType)
 679.593 +		{
 679.594 +		case 0:
 679.595 +			width  = 240;
 679.596 +			height = 160;
 679.597 +			break;
 679.598 +		case 1:
 679.599 +			if (gbBorderOn)
 679.600 +			{
 679.601 +				width  = 256;
 679.602 +				height = 224;
 679.603 +			}
 679.604 +			else
 679.605 +			{
 679.606 +				width  = 160;
 679.607 +				height = 144;
 679.608 +			}
 679.609 +			break;
 679.610 +		}
 679.611 +
 679.612 +		theApp.aviRecorder = new AVIWrite();
 679.613 +
 679.614 +		theApp.aviRecorder->SetFPS(60);
 679.615 +
 679.616 +		BITMAPINFOHEADER bi;
 679.617 +		memset(&bi, 0, sizeof(bi));
 679.618 +		bi.biSize	   = 0x28;
 679.619 +		bi.biPlanes	   = 1;
 679.620 +		bi.biBitCount  = 24;
 679.621 +		bi.biWidth	   = width;
 679.622 +		bi.biHeight	   = height;
 679.623 +		bi.biSizeImage = 3 * width * height;
 679.624 +		theApp.aviRecorder->SetVideoFormat(&bi);
 679.625 +		if (!theApp.aviRecorder->Open(theApp.aviRecordName))
 679.626 +		{
 679.627 +			delete theApp.aviRecorder;
 679.628 +			theApp.aviRecorder	= NULL;
 679.629 +			theApp.aviRecording = false;
 679.630 +		}
 679.631 +
 679.632 +		if (theApp.aviRecorder)
 679.633 +		{
 679.634 +			WAVEFORMATEX wfx;
 679.635 +			memset(&wfx, 0, sizeof(wfx));
 679.636 +			wfx.wFormatTag		= WAVE_FORMAT_PCM;
 679.637 +			wfx.nChannels		= 2;
 679.638 +			wfx.nSamplesPerSec	= 44100 / soundQuality;
 679.639 +			wfx.wBitsPerSample	= 16;
 679.640 +			wfx.nBlockAlign		= (wfx.wBitsPerSample / 8) * wfx.nChannels;
 679.641 +			wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
 679.642 +			wfx.cbSize = 0;
 679.643 +			theApp.aviRecorder->SetSoundFormat(&wfx);
 679.644 +		}
 679.645 +	}
 679.646 +}
 679.647 +
 679.648 +void MainWnd::OnToolsPauseAVIRecording()
 679.649 +{
 679.650 +	theApp.aviRecorder->Pause(!theApp.aviRecorder->IsPaused());
 679.651 +}
 679.652 +
 679.653 +void MainWnd::OnToolsStopAVIRecording()
 679.654 +{
 679.655 +	if (theApp.aviRecorder != NULL)
 679.656 +	{
 679.657 +		delete theApp.aviRecorder;
 679.658 +		theApp.aviRecorder = NULL;
 679.659 +	}
 679.660 +	theApp.aviRecording = false;
 679.661 +}
 679.662 +
 679.663 +void MainWnd::OnUpdateToolsAVIRecording(CCmdUI *pCmdUI)
 679.664 +{
 679.665 +	if (pCmdUI->m_pMenu != NULL)
 679.666 +	{
 679.667 +		if (!theApp.aviRecording)
 679.668 +			pCmdUI->SetText(winResLoadString(IDS_STARTAVIRECORDING));
 679.669 +		else
 679.670 +			pCmdUI->SetText(winResLoadString(IDS_STOPAVIRECORDING));
 679.671 +
 679.672 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
 679.673 +	}
 679.674 +
 679.675 +	pCmdUI->Enable(emulating);
 679.676 +}
 679.677 +
 679.678 +void MainWnd::OnUpdateToolsPauseAVIRecording(CCmdUI *pCmdUI)
 679.679 +{
 679.680 +	if (pCmdUI->m_pMenu != NULL)
 679.681 +	{
 679.682 +		if (!theApp.aviRecording)
 679.683 +		{
 679.684 +			pCmdUI->SetText(winResLoadString(IDS_PAUSEAVIRECORDING));
 679.685 +			theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
 679.686 +			pCmdUI->Enable(false);
 679.687 +		}
 679.688 +		else
 679.689 +		{
 679.690 +			if (!theApp.aviRecorder->IsPaused())
 679.691 +				pCmdUI->SetText(winResLoadString(IDS_PAUSEAVIRECORDING));
 679.692 +			else
 679.693 +				pCmdUI->SetText(winResLoadString(IDS_RESUMEAVIRECORDING));
 679.694 +
 679.695 +			theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
 679.696 +			pCmdUI->Enable(emulating);
 679.697 +		}
 679.698 +	}
 679.699 +}
 679.700 +
 679.701 +void MainWnd::OnToolsRecordMovie()
 679.702 +{
 679.703 +	MovieCreate dlg;
 679.704 +	dlg.DoModal();
 679.705 +}
 679.706 +
 679.707 +void MainWnd::OnUpdateToolsRecordMovie(CCmdUI *pCmdUI)
 679.708 +{
 679.709 +	pCmdUI->Enable(emulating);
 679.710 +}
 679.711 +
 679.712 +void MainWnd::OnToolsStopMovie()
 679.713 +{
 679.714 +	VBAMovieStop(false);
 679.715 +}
 679.716 +
 679.717 +void MainWnd::OnUpdateToolsStopMovie(CCmdUI *pCmdUI)
 679.718 +{
 679.719 +	pCmdUI->Enable(emulating && VBAMovieActive());
 679.720 +}
 679.721 +
 679.722 +void MainWnd::OnToolsPlayMovie()
 679.723 +{
 679.724 +	MovieOpen dlg;
 679.725 +	dlg.DoModal();
 679.726 +}
 679.727 +
 679.728 +void MainWnd::OnUpdateToolsPlayMovie(CCmdUI *pCmdUI)
 679.729 +{
 679.730 +	pCmdUI->Enable(emulating);
 679.731 +}
 679.732 +
 679.733 +void MainWnd::OnToolsPlayReadOnly()
 679.734 +{
 679.735 +	if (!VBAMovieActive())
 679.736 +	{
 679.737 +		theApp.movieReadOnly = !theApp.movieReadOnly;
 679.738 +		systemScreenMessage(theApp.movieReadOnly ? "Movie now read-only" : "Movie now editable");
 679.739 +	}
 679.740 +	else
 679.741 +		VBAMovieToggleReadOnly();
 679.742 +}
 679.743 +
 679.744 +void MainWnd::OnUpdateToolsPlayReadOnly(CCmdUI *pCmdUI)
 679.745 +{
 679.746 +///  pCmdUI->Enable(VBAMovieActive()); // FIXME: this is right, but disabling menu items screws up accelerators until you view
 679.747 +// the menu!
 679.748 +///  pCmdUI->SetCheck(VBAMovieReadOnly());
 679.749 +	pCmdUI->Enable(TRUE); // TEMP
 679.750 +	pCmdUI->SetCheck(VBAMovieActive() ? VBAMovieReadOnly() : theApp.movieReadOnly);
 679.751 +}
 679.752 +
 679.753 +void MainWnd::OnAsscWithSaveState()
 679.754 +{
 679.755 +	theApp.AsscWithSaveState = !theApp.AsscWithSaveState;
 679.756 +}
 679.757 +
 679.758 +void MainWnd::OnUpdateAsscWithSaveState(CCmdUI *pCmdUI)
 679.759 +{
 679.760 +	pCmdUI->Enable(TRUE); // TEMP
 679.761 +	pCmdUI->SetCheck(theApp.AsscWithSaveState);
 679.762 +}
 679.763 +
 679.764 +void MainWnd::OnToolsResumeRecord()
 679.765 +{
 679.766 +	// toggle playing/recording
 679.767 +	if (VBAMovieRecording())
 679.768 +	{
 679.769 +		if (!VBAMovieSwitchToPlaying())
 679.770 +			systemScreenMessage("Cannot continue playing");
 679.771 +	}
 679.772 +	else
 679.773 +	{
 679.774 +		if (!VBAMovieSwitchToRecording())
 679.775 +			systemScreenMessage("Cannot resume recording now");
 679.776 +	}
 679.777 +}
 679.778 +
 679.779 +void MainWnd::OnUpdateToolsResumeRecord(CCmdUI *pCmdUI)
 679.780 +{
 679.781 +	pCmdUI->Enable(VBAMovieActive());
 679.782 +}
 679.783 +
 679.784 +void MainWnd::OnToolsPlayRestart()
 679.785 +{
 679.786 +	VBAMovieRestart();
 679.787 +}
 679.788 +
 679.789 +void MainWnd::OnUpdateToolsPlayRestart(CCmdUI *pCmdUI)
 679.790 +{
 679.791 +	pCmdUI->Enable(VBAMovieActive());
 679.792 +}
 679.793 +
 679.794 +void MainWnd::OnToolsOnMovieEndPause()
 679.795 +{
 679.796 +	theApp.movieOnEndPause = !theApp.movieOnEndPause;
 679.797 +}
 679.798 +
 679.799 +void MainWnd::OnUpdateToolsOnMovieEndPause(CCmdUI *pCmdUI)
 679.800 +{
 679.801 +	pCmdUI->SetCheck(theApp.movieOnEndPause);
 679.802 +}
 679.803 +
 679.804 +void MainWnd::OnToolsOnMovieEndStop()
 679.805 +{
 679.806 +	theApp.movieOnEndBehavior = 0;
 679.807 +}
 679.808 +
 679.809 +void MainWnd::OnUpdateToolsOnMovieEndStop(CCmdUI *pCmdUI)
 679.810 +{
 679.811 +	pCmdUI->SetRadio(theApp.movieOnEndBehavior == 0);
 679.812 +}
 679.813 +
 679.814 +void MainWnd::OnToolsOnMovieEndRestart()
 679.815 +{
 679.816 +	theApp.movieOnEndBehavior = 1;
 679.817 +}
 679.818 +
 679.819 +void MainWnd::OnUpdateToolsOnMovieEndRestart(CCmdUI *pCmdUI)
 679.820 +{
 679.821 +	pCmdUI->SetRadio(theApp.movieOnEndBehavior == 1);
 679.822 +}
 679.823 +
 679.824 +void MainWnd::OnToolsOnMovieEndAppend()
 679.825 +{
 679.826 +	theApp.movieOnEndBehavior = 2;
 679.827 +}
 679.828 +
 679.829 +void MainWnd::OnUpdateToolsOnMovieEndAppend(CCmdUI *pCmdUI)
 679.830 +{
 679.831 +	pCmdUI->SetRadio(theApp.movieOnEndBehavior == 2);
 679.832 +}
 679.833 +
 679.834 +void MainWnd::OnToolsOnMovieEndKeep()
 679.835 +{
 679.836 +	theApp.movieOnEndBehavior = 3;
 679.837 +}
 679.838 +
 679.839 +void MainWnd::OnUpdateToolsOnMovieEndKeep(CCmdUI *pCmdUI)
 679.840 +{
 679.841 +	pCmdUI->SetRadio(theApp.movieOnEndBehavior == 3);
 679.842 +}
 679.843 +
 679.844 +/////////////////////////////////
 679.845 +
 679.846 +void MainWnd::OnToolsMovieSetPauseAt()
 679.847 +{
 679.848 +	// TODO
 679.849 +	VBAMovieSetPauseAt(-1);
 679.850 +}
 679.851 +
 679.852 +void MainWnd::OnUpdateToolsSetMoviePauseAt(CCmdUI *pCmdUI)
 679.853 +{
 679.854 +	// TODO
 679.855 +	pCmdUI->SetCheck(VBAMovieGetPauseAt() >= 0);
 679.856 +	pCmdUI->Enable(FALSE && VBAMovieActive());
 679.857 +}
 679.858 +
 679.859 +void MainWnd::OnToolsMovieConvertCurrent()
 679.860 +{
 679.861 +	// temporary
 679.862 +	int result = VBAMovieConvertCurrent();
 679.863 +	switch (result)
 679.864 +	{
 679.865 +	case MOVIE_SUCCESS:
 679.866 +		systemScreenMessage("Movie converted");
 679.867 +		break;
 679.868 +	case MOVIE_WRONG_VERSION:
 679.869 +		systemMessage(0, "Cannot convert from VBM revision %u", VBAMovieGetMinorVersion());
 679.870 +		break;
 679.871 +	default:
 679.872 +		systemScreenMessage("Nothing to convert");
 679.873 +		break;
 679.874 +	}
 679.875 +}
 679.876 +
 679.877 +void MainWnd::OnUpdateToolsMovieConvertCurrent(CCmdUI *pCmdUI)
 679.878 +{
 679.879 +	pCmdUI->Enable(VBAMovieActive());
 679.880 +}
 679.881 +
 679.882 +void MainWnd::OnToolsMovieAutoConvert()
 679.883 +{
 679.884 +	extern bool autoConvertMovieWhenPlaying;    // from movie.cpp
 679.885 +	autoConvertMovieWhenPlaying = !autoConvertMovieWhenPlaying;
 679.886 +	if (autoConvertMovieWhenPlaying)
 679.887 +	{
 679.888 +		int result = VBAMovieConvertCurrent();
 679.889 +		switch (result)
 679.890 +		{
 679.891 +		case MOVIE_SUCCESS:
 679.892 +			systemScreenMessage("Movie converted");
 679.893 +			break;
 679.894 +		case MOVIE_WRONG_VERSION:
 679.895 +			systemMessage(0, "Cannot convert from VBM revision %u", VBAMovieGetMinorVersion());
 679.896 +			break;
 679.897 +		default:
 679.898 +			systemScreenMessage("Auto movie conversion enabled");
 679.899 +			break;
 679.900 +		}
 679.901 +	}
 679.902 +}
 679.903 +
 679.904 +void MainWnd::OnUpdateToolsMovieAutoConvert(CCmdUI *pCmdUI)
 679.905 +{
 679.906 +	extern bool autoConvertMovieWhenPlaying;    // from movie.cpp
 679.907 +	pCmdUI->SetCheck(autoConvertMovieWhenPlaying);
 679.908 +}
 679.909 +
 679.910 +void MainWnd::OnToolsMovieTruncateAtCurrent()
 679.911 +{
 679.912 +	if (VBAMovieReadOnly())
 679.913 +		systemScreenMessage("Cannot truncate movie in this mode");
 679.914 +	else
 679.915 +		VBAMovieTuncateAtCurrentFrame();
 679.916 +}
 679.917 +
 679.918 +void MainWnd::OnUpdateToolsMovieTruncateAtCurrent(CCmdUI *pCmdUI)
 679.919 +{
 679.920 +	pCmdUI->Enable(VBAMovieActive());
 679.921 +}
 679.922 +
 679.923 +void MainWnd::OnToolsMovieFixHeader()
 679.924 +{
 679.925 +	VBAMovieFixHeader();
 679.926 +}
 679.927 +
 679.928 +void MainWnd::OnUpdateToolsMovieFixHeader(CCmdUI *pCmdUI)
 679.929 +{
 679.930 +	pCmdUI->Enable(VBAMovieActive());
 679.931 +}
 679.932 +
 679.933 +// TODO
 679.934 +void MainWnd::OnToolsMovieExtractFromSavegame()
 679.935 +{
 679.936 +	// Currently, snapshots taken from a movie don't contain the initial SRAM or savestate of the movie,
 679.937 +	// even if the movie was recorded from either of them. If a snapshot was taken at the first frame
 679.938 +	// i.e. Frame 0, it can be safely assumed that the snapshot reflects the initial state of such a movie.
 679.939 +	// However, if it was taken after the first frame, the SRAM contained might either be still the same
 679.940 +	// as the original (usually true if no write operations on the SRAM occured) or have been modified,
 679.941 +	// while the exact original state could hardly, if not impossibly, be safely worked out.
 679.942 +
 679.943 +	// TODO
 679.944 +}
 679.945 +
 679.946 +void MainWnd::OnUpdateToolsMovieExtractFromSavegame(CCmdUI *pCmdUI)
 679.947 +{
 679.948 +	pCmdUI->Enable(FALSE);
 679.949 +}
 679.950 +
 679.951 +///////////////////////////////////////////////////////////
 679.952 +
 679.953 +void MainWnd::OnToolsRewind()
 679.954 +{
 679.955 +	assert(theApp.rewindTimer > 0 && theApp.rewindSlots > 0);
 679.956 +	if (emulating && theApp.emulator.emuReadMemState && theApp.rewindMemory && theApp.rewindCount)
 679.957 +	{
 679.958 +		assert(theApp.rewindPos >= 0 && theApp.rewindPos < theApp.rewindSlots);
 679.959 +		theApp.rewindPos = (--theApp.rewindPos + theApp.rewindSlots) % theApp.rewindSlots;
 679.960 +		assert(theApp.rewindPos >= 0 && theApp.rewindPos < theApp.rewindSlots);
 679.961 +		theApp.emulator.emuReadMemState(&theApp.rewindMemory[REWIND_SIZE * theApp.rewindPos], REWIND_SIZE);
 679.962 +		theApp.rewindCount--;
 679.963 +		if (theApp.rewindCount > 0)
 679.964 +			theApp.rewindCounter = 0;
 679.965 +		else
 679.966 +		{
 679.967 +			theApp.rewindCounter	= theApp.rewindTimer;
 679.968 +			theApp.rewindSaveNeeded = true;
 679.969 +
 679.970 +			// immediately save state to avoid eroding away the earliest you can rewind to
 679.971 +			theApp.saveRewindStateIfNecessary();
 679.972 +
 679.973 +			theApp.rewindSaveNeeded = false;
 679.974 +		}
 679.975 +	}
 679.976 +}
 679.977 +
 679.978 +void MainWnd::OnUpdateToolsRewind(CCmdUI *pCmdUI)
 679.979 +{
 679.980 +	pCmdUI->Enable(theApp.rewindMemory != NULL && emulating && theApp.rewindCount);
 679.981 +}
 679.982 +
 679.983 +void MainWnd::OnToolsCustomize()
 679.984 +{
 679.985 +	theApp.recreateMenuBar();
 679.986 +
 679.987 +	AccelEditor dlg(this, &theApp.m_menu, &theApp.winAccelMgr);
 679.988 +	dlg.DoModal();
 679.989 +	if (dlg.IsModified())
 679.990 +	{
 679.991 +		theApp.winAccelMgr = dlg.GetResultMangager();
 679.992 +		theApp.winAccelMgr.UpdateWndTable();
 679.993 +		theApp.winAccelMgr.Write();
 679.994 +	}
 679.995 +
 679.996 +	theApp.winAccelMgr.UpdateMenu(theApp.menu); // we should always do this since the menu has been reloaded
 679.997 +}
 679.998 +
 679.999 +void MainWnd::OnUpdateToolsCustomize(CCmdUI *pCmdUI)
679.1000 +{
679.1001 +	pCmdUI->Enable(theApp.videoOption != VIDEO_320x240);
679.1002 +}
679.1003 +
   680.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   680.2 +++ b/src/win32/MapView.cpp	Sat Mar 03 10:31:27 2012 -0600
   680.3 @@ -0,0 +1,1066 @@
   680.4 +// MapView.cpp : implementation file
   680.5 +//
   680.6 +
   680.7 +#include "stdafx.h"
   680.8 +#include "resource.h"
   680.9 +#include "MapView.h"
  680.10 +#include "FileDlg.h"
  680.11 +#include "Reg.h"
  680.12 +#include "WinResUtil.h"
  680.13 +#include "VBA.h"
  680.14 +
  680.15 +#include "../gba/GBAGlobals.h"
  680.16 +#include "../NLS.h"
  680.17 +#include "../common/Util.h"
  680.18 +
  680.19 +extern "C" {
  680.20 +#include <png.h>
  680.21 +}
  680.22 +
  680.23 +/////////////////////////////////////////////////////////////////////////////
  680.24 +// MapView dialog
  680.25 +
  680.26 +MapView::MapView(CWnd*pParent /*=NULL*/)
  680.27 +	: ResizeDlg(MapView::IDD, pParent)
  680.28 +{
  680.29 +	//{{AFX_DATA_INIT(MapView)
  680.30 +	//}}AFX_DATA_INIT
  680.31 +	autoUpdate = false;
  680.32 +
  680.33 +	memset(&bmpInfo.bmiHeader, 0, sizeof(bmpInfo.bmiHeader));
  680.34 +
  680.35 +	bmpInfo.bmiHeader.biSize        = sizeof(bmpInfo.bmiHeader);
  680.36 +	bmpInfo.bmiHeader.biWidth       = 1024;
  680.37 +	bmpInfo.bmiHeader.biHeight      = -1024;
  680.38 +	bmpInfo.bmiHeader.biPlanes      = 1;
  680.39 +	bmpInfo.bmiHeader.biBitCount    = 24;
  680.40 +	bmpInfo.bmiHeader.biCompression = BI_RGB;
  680.41 +	data = (u8 *)calloc(1, 3 * 1024 * 1024);
  680.42 +
  680.43 +	mapView.setData(data);
  680.44 +	mapView.setBmpInfo(&bmpInfo);
  680.45 +
  680.46 +	control = BG0CNT;
  680.47 +
  680.48 +	bg    = 0;
  680.49 +	frame = 0;
  680.50 +}
  680.51 +
  680.52 +MapView::~MapView()
  680.53 +{
  680.54 +	free(data);
  680.55 +	data = NULL;
  680.56 +}
  680.57 +
  680.58 +void MapView::DoDataExchange(CDataExchange*pDX)
  680.59 +{
  680.60 +	CDialog::DoDataExchange(pDX);
  680.61 +	//{{AFX_DATA_MAP(MapView)
  680.62 +	DDX_Control(pDX, IDC_NUMCOLORS, m_numcolors);
  680.63 +	DDX_Control(pDX, IDC_MODE, m_mode);
  680.64 +	DDX_Control(pDX, IDC_OVERFLOW, m_overflow);
  680.65 +	DDX_Control(pDX, IDC_MOSAIC, m_mosaic);
  680.66 +	DDX_Control(pDX, IDC_PRIORITY, m_priority);
  680.67 +	DDX_Control(pDX, IDC_DIM, m_dim);
  680.68 +	DDX_Control(pDX, IDC_CHARBASE, m_charbase);
  680.69 +	DDX_Control(pDX, IDC_MAPBASE, m_mapbase);
  680.70 +	//}}AFX_DATA_MAP
  680.71 +	DDX_Control(pDX, IDC_MAP_VIEW, mapView);
  680.72 +	DDX_Control(pDX, IDC_MAP_VIEW_ZOOM, mapViewZoom);
  680.73 +	DDX_Control(pDX, IDC_COLOR, color);
  680.74 +}
  680.75 +
  680.76 +BEGIN_MESSAGE_MAP(MapView, CDialog)
  680.77 +//{{AFX_MSG_MAP(MapView)
  680.78 +ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
  680.79 +ON_BN_CLICKED(IDC_FRAME_0, OnFrame0)
  680.80 +ON_BN_CLICKED(IDC_FRAME_1, OnFrame1)
  680.81 +ON_BN_CLICKED(IDC_BG0, OnBg0)
  680.82 +ON_BN_CLICKED(IDC_BG1, OnBg1)
  680.83 +ON_BN_CLICKED(IDC_BG2, OnBg2)
  680.84 +ON_BN_CLICKED(IDC_BG3, OnBg3)
  680.85 +ON_BN_CLICKED(IDC_STRETCH, OnStretch)
  680.86 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
  680.87 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
  680.88 +ON_BN_CLICKED(IDC_SAVE, OnSave)
  680.89 +//}}AFX_MSG_MAP
  680.90 +ON_MESSAGE(WM_MAPINFO, OnMapInfo)
  680.91 +ON_MESSAGE(WM_COLINFO, OnColInfo)
  680.92 +END_MESSAGE_MAP()
  680.93 +
  680.94 +/////////////////////////////////////////////////////////////////////////////
  680.95 +// MapView message handlers
  680.96 +
  680.97 +void MapView::renderTextScreen(u16 control)
  680.98 +{
  680.99 +	u16 *palette    = (u16 *)paletteRAM;
 680.100 +	u8 * charBase   = &vram[((control >> 2) & 0x03) * 0x4000];
 680.101 +	u16 *screenBase = (u16 *)&vram[((control >> 8) & 0x1f) * 0x800];
 680.102 +	u8 * bmp        = data;
 680.103 +
 680.104 +	int sizeX = 256;
 680.105 +	int sizeY = 256;
 680.106 +	switch ((control >> 14) & 3)
 680.107 +	{
 680.108 +	case 0:
 680.109 +		break;
 680.110 +	case 1:
 680.111 +		sizeX = 512;
 680.112 +		break;
 680.113 +	case 2:
 680.114 +		sizeY = 512;
 680.115 +		break;
 680.116 +	case 3:
 680.117 +		sizeX = 512;
 680.118 +		sizeY = 512;
 680.119 +		break;
 680.120 +	}
 680.121 +
 680.122 +	w = sizeX;
 680.123 +	h = sizeY;
 680.124 +
 680.125 +	if (control & 0x80)
 680.126 +	{
 680.127 +		for (int y = 0; y < sizeY; y++)
 680.128 +		{
 680.129 +			int yy = y & 255;
 680.130 +
 680.131 +			if (y == 256 && sizeY > 256)
 680.132 +			{
 680.133 +				screenBase += 0x400;
 680.134 +				if (sizeX > 256)
 680.135 +					screenBase += 0x400;
 680.136 +			}
 680.137 +			u16 *screenSource = screenBase + ((yy>>3)*32);
 680.138 +
 680.139 +			for (int x = 0; x < sizeX; x++)
 680.140 +			{
 680.141 +				u16 data = *screenSource;
 680.142 +
 680.143 +				int tile  = data & 0x3FF;
 680.144 +				int tileX = (x & 7);
 680.145 +				int tileY = y & 7;
 680.146 +
 680.147 +				if (data & 0x0400)
 680.148 +					tileX = 7 - tileX;
 680.149 +				if (data & 0x0800)
 680.150 +					tileY = 7 - tileY;
 680.151 +
 680.152 +				u8 c = charBase[tile * 64 + tileY * 8 + tileX];
 680.153 +
 680.154 +				u16 color = palette[c];
 680.155 +
 680.156 +				*bmp++ = ((color >> 10) & 0x1f) << 3;
 680.157 +				*bmp++ = ((color >> 5) & 0x1f) << 3;
 680.158 +				*bmp++ = (color & 0x1f) << 3;
 680.159 +
 680.160 +				if (data & 0x0400)
 680.161 +				{
 680.162 +					if (tileX == 0)
 680.163 +						screenSource++;
 680.164 +				}
 680.165 +				else if (tileX == 7)
 680.166 +					screenSource++;
 680.167 +				if (x == 255 && sizeX > 256)
 680.168 +				{
 680.169 +					screenSource = screenBase + 0x400 + ((yy>>3)*32);
 680.170 +				}
 680.171 +			}
 680.172 +		}
 680.173 +	}
 680.174 +	else
 680.175 +	{
 680.176 +		for (int y = 0; y < sizeY; y++)
 680.177 +		{
 680.178 +			int yy = y & 255;
 680.179 +
 680.180 +			if (y == 256 && sizeY > 256)
 680.181 +			{
 680.182 +				screenBase += 0x400;
 680.183 +				if (sizeX > 256)
 680.184 +					screenBase += 0x400;
 680.185 +			}
 680.186 +			u16 *screenSource = screenBase + ((yy>>3)*32);
 680.187 +
 680.188 +			for (int x = 0; x < sizeX; x++)
 680.189 +			{
 680.190 +				u16 data = *screenSource;
 680.191 +
 680.192 +				int tile  = data & 0x3FF;
 680.193 +				int tileX = (x & 7);
 680.194 +				int tileY = y & 7;
 680.195 +
 680.196 +				if (data & 0x0400)
 680.197 +					tileX = 7 - tileX;
 680.198 +				if (data & 0x0800)
 680.199 +					tileY = 7 - tileY;
 680.200 +
 680.201 +				u8 color = charBase[tile * 32 + tileY * 4 + (tileX>>1)];
 680.202 +
 680.203 +				if (tileX & 1)
 680.204 +				{
 680.205 +					color = (color >> 4);
 680.206 +				}
 680.207 +				else
 680.208 +				{
 680.209 +					color &= 0x0F;
 680.210 +				}
 680.211 +
 680.212 +				int pal    = (*screenSource>>8) & 0xF0;
 680.213 +				u16 color2 = palette[pal + color];
 680.214 +
 680.215 +				*bmp++ = ((color2 >> 10) & 0x1f) << 3;
 680.216 +				*bmp++ = ((color2 >> 5) & 0x1f) << 3;
 680.217 +				*bmp++ = (color2 & 0x1f) << 3;
 680.218 +
 680.219 +				if (data & 0x0400)
 680.220 +				{
 680.221 +					if (tileX == 0)
 680.222 +						screenSource++;
 680.223 +				}
 680.224 +				else if (tileX == 7)
 680.225 +					screenSource++;
 680.226 +
 680.227 +				if (x == 255 && sizeX > 256)
 680.228 +				{
 680.229 +					screenSource = screenBase + 0x400 + ((yy>>3)*32);
 680.230 +				}
 680.231 +			}
 680.232 +		}
 680.233 +	}
 680.234 +	/*
 680.235 +	   switch(bg) {
 680.236 +	   case 0:
 680.237 +	   renderView(BG0HOFS<<8, BG0VOFS<<8,
 680.238 +	   0x100, 0x000,
 680.239 +	   0x000, 0x100,
 680.240 +	   (sizeX -1) <<8,
 680.241 +	   (sizeY -1) << 8,
 680.242 +	   true);
 680.243 +	   break;
 680.244 +	   case 1:
 680.245 +	   renderView(BG1HOFS<<8, BG1VOFS<<8,
 680.246 +	   0x100, 0x000,
 680.247 +	   0x000, 0x100,
 680.248 +	   (sizeX -1) <<8,
 680.249 +	   (sizeY -1) << 8,
 680.250 +	   true);
 680.251 +	   break;
 680.252 +	   case 2:
 680.253 +	   renderView(BG2HOFS<<8, BG2VOFS<<8,
 680.254 +	   0x100, 0x000,
 680.255 +	   0x000, 0x100,
 680.256 +	   (sizeX -1) <<8,
 680.257 +	   (sizeY -1) << 8,
 680.258 +	   true);
 680.259 +	   break;
 680.260 +	   case 3:
 680.261 +	   renderView(BG3HOFS<<8, BG3VOFS<<8,
 680.262 +	   0x100, 0x000,
 680.263 +	   0x000, 0x100,
 680.264 +	   (sizeX -1) <<8,
 680.265 +	   (sizeY -1) << 8,
 680.266 +	   true);
 680.267 +	   break;
 680.268 +	   }
 680.269 +	 */
 680.270 +}
 680.271 +
 680.272 +void MapView::renderRotScreen(u16 control)
 680.273 +{
 680.274 +	u16 *palette    = (u16 *)paletteRAM;
 680.275 +	u8 * charBase   = &vram[((control >> 2) & 0x03) * 0x4000];
 680.276 +	u8 * screenBase = (u8 *)&vram[((control >> 8) & 0x1f) * 0x800];
 680.277 +	u8 * bmp        = data;
 680.278 +
 680.279 +	int sizeX = 128;
 680.280 +	int sizeY = 128;
 680.281 +	switch ((control >> 14) & 3)
 680.282 +	{
 680.283 +	case 0:
 680.284 +		break;
 680.285 +	case 1:
 680.286 +		sizeX = sizeY = 256;
 680.287 +		break;
 680.288 +	case 2:
 680.289 +		sizeX = sizeY = 512;
 680.290 +		break;
 680.291 +	case 3:
 680.292 +		sizeX = sizeY = 1024;
 680.293 +		break;
 680.294 +	}
 680.295 +
 680.296 +	w = sizeX;
 680.297 +	h = sizeY;
 680.298 +
 680.299 +	if (control & 0x80)
 680.300 +	{
 680.301 +		for (int y = 0; y < sizeY; y++)
 680.302 +		{
 680.303 +			for (int x = 0; x < sizeX; x++)
 680.304 +			{
 680.305 +				int tile = screenBase[(x>>3) + (y>>3)*(w>>3)];
 680.306 +
 680.307 +				int tileX = (x & 7);
 680.308 +				int tileY = y & 7;
 680.309 +
 680.310 +				u8  color  = charBase[tile * 64 + tileY * 8 + tileX];
 680.311 +				u16 color2 = palette[color];
 680.312 +
 680.313 +				*bmp++ = ((color2 >> 10) & 0x1f) << 3;
 680.314 +				*bmp++ = ((color2 >> 5) & 0x1f) << 3;
 680.315 +				*bmp++ = (color2 & 0x1f) << 3;
 680.316 +			}
 680.317 +		}
 680.318 +	}
 680.319 +	else
 680.320 +	{
 680.321 +		for (int y = 0; y < sizeY; y++)
 680.322 +		{
 680.323 +			for (int x = 0; x < sizeX; x++)
 680.324 +			{
 680.325 +				int tile = screenBase[(x>>3) + (y>>3)*(w>>3)];
 680.326 +
 680.327 +				int tileX = (x & 7);
 680.328 +				int tileY = y & 7;
 680.329 +
 680.330 +				u8  color  = charBase[tile * 64 + tileY * 8 + tileX];
 680.331 +				u16 color2 = palette[color];
 680.332 +
 680.333 +				*bmp++ = ((color2 >> 10) & 0x1f) << 3;
 680.334 +				*bmp++ = ((color2 >> 5) & 0x1f) << 3;
 680.335 +				*bmp++ = (color2 & 0x1f) << 3;
 680.336 +			}
 680.337 +		}
 680.338 +	}
 680.339 +
 680.340 +	u32 xx;
 680.341 +	u32 yy;
 680.342 +
 680.343 +	switch (bg)
 680.344 +	{
 680.345 +	case 2:
 680.346 +		xx = BG2X_L | BG2X_H << 16;
 680.347 +		yy = BG2Y_L | BG2Y_H << 16;
 680.348 +
 680.349 +		/*
 680.350 +		      renderView(xx, yy,
 680.351 +		      BG2PA, BG2PC,
 680.352 +		      BG2PB, BG2PD,
 680.353 +		      (sizeX -1) <<8,
 680.354 +		      (sizeY -1) << 8,
 680.355 +		      (control & 0x2000) != 0);
 680.356 +		 */
 680.357 +		break;
 680.358 +	case 3:
 680.359 +		xx = BG3X_L | BG3X_H << 16;
 680.360 +		yy = BG3Y_L | BG3Y_H << 16;
 680.361 +		/*
 680.362 +		      renderView(xx, yy,
 680.363 +		      BG3PA, BG3PC,
 680.364 +		      BG3PB, BG3PD,
 680.365 +		      (sizeX -1) <<8,
 680.366 +		      (sizeY -1) << 8,
 680.367 +		      (control & 0x2000) != 0);
 680.368 +		 */
 680.369 +		break;
 680.370 +	}
 680.371 +}
 680.372 +
 680.373 +void MapView::renderMode0()
 680.374 +{
 680.375 +	renderTextScreen(control);
 680.376 +}
 680.377 +
 680.378 +void MapView::renderMode1()
 680.379 +{
 680.380 +	switch (bg)
 680.381 +	{
 680.382 +	case 0:
 680.383 +	case 1:
 680.384 +		renderTextScreen(control);
 680.385 +		break;
 680.386 +	case 2:
 680.387 +		renderRotScreen(control);
 680.388 +		break;
 680.389 +	default:
 680.390 +		bg      = 0;
 680.391 +		control = BG0CNT;
 680.392 +		renderTextScreen(control);
 680.393 +		break;
 680.394 +	}
 680.395 +}
 680.396 +
 680.397 +void MapView::renderMode2()
 680.398 +{
 680.399 +	switch (bg)
 680.400 +	{
 680.401 +	case 2:
 680.402 +	case 3:
 680.403 +		renderRotScreen(control);
 680.404 +		break;
 680.405 +	default:
 680.406 +		bg      = 2;
 680.407 +		control = BG2CNT;
 680.408 +		renderRotScreen(control);
 680.409 +		break;
 680.410 +	}
 680.411 +}
 680.412 +
 680.413 +void MapView::renderMode3()
 680.414 +{
 680.415 +	u8 * bmp = data;
 680.416 +	u16 *src = (u16 *)&vram[0];
 680.417 +
 680.418 +	w = 240;
 680.419 +	h = 160;
 680.420 +
 680.421 +	for (int y = 0; y < 160; y++)
 680.422 +	{
 680.423 +		for (int x = 0; x < 240; x++)
 680.424 +		{
 680.425 +			u16 data = *src++;
 680.426 +			*bmp++ = ((data >> 10) & 0x1f) << 3;
 680.427 +			*bmp++ = ((data >> 5) & 0x1f) << 3;
 680.428 +			*bmp++ = (data & 0x1f) << 3;
 680.429 +		}
 680.430 +	}
 680.431 +	bg = 2;
 680.432 +}
 680.433 +
 680.434 +void MapView::renderMode4()
 680.435 +{
 680.436 +	u8 * bmp = data;
 680.437 +	u8 * src = frame ? &vram[0xa000] : &vram[0];
 680.438 +	u16 *pal = (u16 *)&paletteRAM[0];
 680.439 +
 680.440 +	w = 240;
 680.441 +	h = 160;
 680.442 +
 680.443 +	for (int y = 0; y < 160; y++)
 680.444 +	{
 680.445 +		for (int x = 0; x < 240; x++)
 680.446 +		{
 680.447 +			u8  c    = *src++;
 680.448 +			u16 data = pal[c];
 680.449 +			*bmp++ = ((data >> 10) & 0x1f) << 3;
 680.450 +			*bmp++ = ((data >> 5) & 0x1f) << 3;
 680.451 +			*bmp++ = (data & 0x1f) << 3;
 680.452 +		}
 680.453 +	}
 680.454 +	bg = 2;
 680.455 +}
 680.456 +
 680.457 +void MapView::renderMode5()
 680.458 +{
 680.459 +	u8 * bmp = data;
 680.460 +	u16 *src = (u16 *)(frame ? &vram[0xa000] : &vram[0]);
 680.461 +
 680.462 +	w = 160;
 680.463 +	h = 128;
 680.464 +
 680.465 +	for (int y = 0; y < 128; y++)
 680.466 +	{
 680.467 +		for (int x = 0; x < 160; x++)
 680.468 +		{
 680.469 +			u16 data = *src++;
 680.470 +			*bmp++ = ((data >> 10) & 0x1f) << 3;
 680.471 +			*bmp++ = ((data >> 5) & 0x1f) << 3;
 680.472 +			*bmp++ = (data & 0x1f) << 3;
 680.473 +		}
 680.474 +	}
 680.475 +	bg = 2;
 680.476 +}
 680.477 +
 680.478 +void MapView::OnRefresh()
 680.479 +{
 680.480 +	paint();
 680.481 +}
 680.482 +
 680.483 +void MapView::paint()
 680.484 +{
 680.485 +	if (vram == NULL)
 680.486 +		return;
 680.487 +	int mode = DISPCNT & 7;
 680.488 +
 680.489 +	switch (bg)
 680.490 +	{
 680.491 +	default:
 680.492 +	case 0:
 680.493 +		control = BG0CNT;
 680.494 +		break;
 680.495 +	case 1:
 680.496 +		control = BG1CNT;
 680.497 +		break;
 680.498 +	case 2:
 680.499 +		control = BG2CNT;
 680.500 +		break;
 680.501 +	case 3:
 680.502 +		control = BG3CNT;
 680.503 +		break;
 680.504 +	}
 680.505 +
 680.506 +	switch (mode)
 680.507 +	{
 680.508 +	case 0:
 680.509 +		renderMode0();
 680.510 +		break;
 680.511 +	case 1:
 680.512 +		renderMode1();
 680.513 +		break;
 680.514 +	case 2:
 680.515 +		renderMode2();
 680.516 +		break;
 680.517 +	case 3:
 680.518 +		renderMode3();
 680.519 +		break;
 680.520 +	case 4:
 680.521 +		renderMode4();
 680.522 +		break;
 680.523 +	case 5:
 680.524 +		renderMode5();
 680.525 +		break;
 680.526 +	}
 680.527 +	enableButtons(mode);
 680.528 +	SIZE s;
 680.529 +
 680.530 +	if (mapView.getStretch())
 680.531 +	{
 680.532 +		mapView.setSize(w, h);
 680.533 +		s.cx = s.cy = 1;
 680.534 +		mapView.SetScrollSizes(MM_TEXT, s);
 680.535 +	}
 680.536 +	else
 680.537 +	{
 680.538 +		mapView.setSize(w, h);
 680.539 +		s.cx = w;
 680.540 +		s.cy = h;
 680.541 +		mapView.SetScrollSizes(MM_TEXT, s);
 680.542 +	}
 680.543 +
 680.544 +	mapView.refresh();
 680.545 +
 680.546 +	CString buffer;
 680.547 +
 680.548 +	u32 charBase   = ((control >> 2) & 0x03) * 0x4000 + 0x6000000;
 680.549 +	u32 screenBase = ((control >> 8) & 0x1f) * 0x800 + 0x6000000;
 680.550 +
 680.551 +	buffer.Format("%d", mode);
 680.552 +	m_mode.SetWindowText(buffer);
 680.553 +
 680.554 +	if (mode >= 3)
 680.555 +	{
 680.556 +		m_mapbase.SetWindowText("");
 680.557 +		m_charbase.SetWindowText("");
 680.558 +	}
 680.559 +	else
 680.560 +	{
 680.561 +		buffer.Format("0x%08X", screenBase);
 680.562 +		m_mapbase.SetWindowText(buffer);
 680.563 +
 680.564 +		buffer.Format("0x%08X", charBase);
 680.565 +		m_charbase.SetWindowText(buffer);
 680.566 +	}
 680.567 +
 680.568 +	buffer.Format("%dx%d", w, h);
 680.569 +	m_dim.SetWindowText(buffer);
 680.570 +
 680.571 +	m_numcolors.SetWindowText(control & 0x80 ? "256" : "16");
 680.572 +
 680.573 +	buffer.Format("%d", control & 3);
 680.574 +	m_priority.SetWindowText(buffer);
 680.575 +
 680.576 +	m_mosaic.SetWindowText(control & 0x40 ? "1" : "0");
 680.577 +
 680.578 +	m_overflow.SetWindowText(bg <= 1 ? "" :
 680.579 +	                         control & 0x2000 ? "1" : "0");
 680.580 +}
 680.581 +
 680.582 +BOOL MapView::OnInitDialog()
 680.583 +{
 680.584 +	CDialog::OnInitDialog();
 680.585 +
 680.586 +	DIALOG_SIZER_START(sz)
 680.587 +	DIALOG_SIZER_ENTRY(IDC_MAP_VIEW, DS_SizeX | DS_SizeY)
 680.588 +	DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
 680.589 +	DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
 680.590 +	DIALOG_SIZER_ENTRY(IDC_SAVE,  DS_MoveY)
 680.591 +	DIALOG_SIZER_ENTRY(IDC_COLOR, DS_MoveY)
 680.592 +	DIALOG_SIZER_ENTRY(IDC_R, DS_MoveY)
 680.593 +	DIALOG_SIZER_ENTRY(IDC_G, DS_MoveY)
 680.594 +	DIALOG_SIZER_ENTRY(IDC_B, DS_MoveY)
 680.595 +	DIALOG_SIZER_END()
 680.596 +	SetData(sz,
 680.597 +	        TRUE,
 680.598 +	        HKEY_CURRENT_USER,
 680.599 +	        "Software\\Emulators\\VisualBoyAdvance\\Viewer\\MapView",
 680.600 +	        NULL);
 680.601 +
 680.602 +	SIZE size;
 680.603 +	size.cx = 1;
 680.604 +	size.cy = 1;
 680.605 +	mapView.SetScrollSizes(MM_TEXT, size);
 680.606 +	int s = regQueryDwordValue("mapViewStretch", 0);
 680.607 +	if (s)
 680.608 +		mapView.setStretch(true);
 680.609 +	((CButton *)GetDlgItem(IDC_STRETCH))->SetCheck(s);
 680.610 +	paint();
 680.611 +
 680.612 +	return TRUE; // return TRUE unless you set the focus to a control
 680.613 +	             // EXCEPTION: OCX Property Pages should return FALSE
 680.614 +}
 680.615 +
 680.616 +void MapView::PostNcDestroy()
 680.617 +{
 680.618 +	delete this;
 680.619 +}
 680.620 +
 680.621 +void MapView::enableButtons(int mode)
 680.622 +{
 680.623 +	bool enable[6] = { true, true, true, true, true, true };
 680.624 +
 680.625 +	switch (mode)
 680.626 +	{
 680.627 +	case 0:
 680.628 +		enable[4] = false;
 680.629 +		enable[5] = false;
 680.630 +		break;
 680.631 +	case 1:
 680.632 +		enable[3] = false;
 680.633 +		enable[4] = false;
 680.634 +		enable[5] = false;
 680.635 +		break;
 680.636 +	case 2:
 680.637 +		enable[0] = false;
 680.638 +		enable[1] = false;
 680.639 +		enable[4] = false;
 680.640 +		enable[5] = false;
 680.641 +		break;
 680.642 +	case 3:
 680.643 +		enable[0] = false;
 680.644 +		enable[1] = false;
 680.645 +		enable[2] = false;
 680.646 +		enable[3] = false;
 680.647 +		enable[4] = false;
 680.648 +		enable[5] = false;
 680.649 +		break;
 680.650 +	case 4:
 680.651 +		enable[0] = false;
 680.652 +		enable[1] = false;
 680.653 +		enable[2] = false;
 680.654 +		enable[3] = false;
 680.655 +		break;
 680.656 +	case 5:
 680.657 +		enable[0] = false;
 680.658 +		enable[1] = false;
 680.659 +		enable[2] = false;
 680.660 +		enable[3] = false;
 680.661 +		break;
 680.662 +	}
 680.663 +	GetDlgItem(IDC_BG0)->EnableWindow(enable[0]);
 680.664 +	GetDlgItem(IDC_BG1)->EnableWindow(enable[1]);
 680.665 +	GetDlgItem(IDC_BG2)->EnableWindow(enable[2]);
 680.666 +	GetDlgItem(IDC_BG3)->EnableWindow(enable[3]);
 680.667 +	GetDlgItem(IDC_FRAME_0)->EnableWindow(enable[4]);
 680.668 +	GetDlgItem(IDC_FRAME_1)->EnableWindow(enable[5]);
 680.669 +	int id = IDC_BG0;
 680.670 +	switch (bg)
 680.671 +	{
 680.672 +	case 1:
 680.673 +		id = IDC_BG1;
 680.674 +		break;
 680.675 +	case 2:
 680.676 +		id = IDC_BG2;
 680.677 +		break;
 680.678 +	case 3:
 680.679 +		id = IDC_BG3;
 680.680 +		break;
 680.681 +	}
 680.682 +	CheckRadioButton(IDC_BG0, IDC_BG3, id);
 680.683 +	id = IDC_FRAME_0;
 680.684 +	if (frame != 0)
 680.685 +		id = IDC_FRAME_1;
 680.686 +	CheckRadioButton(IDC_FRAME_0, IDC_FRAME_1, id);
 680.687 +}
 680.688 +
 680.689 +void MapView::OnFrame0()
 680.690 +{
 680.691 +	frame = 0;
 680.692 +	paint();
 680.693 +}
 680.694 +
 680.695 +void MapView::OnFrame1()
 680.696 +{
 680.697 +	frame = 1;
 680.698 +	paint();
 680.699 +}
 680.700 +
 680.701 +void MapView::OnBg0()
 680.702 +{
 680.703 +	bg      = 0;
 680.704 +	control = BG0CNT;
 680.705 +	paint();
 680.706 +}
 680.707 +
 680.708 +void MapView::OnBg1()
 680.709 +{
 680.710 +	bg      = 1;
 680.711 +	control = BG1CNT;
 680.712 +	paint();
 680.713 +}
 680.714 +
 680.715 +void MapView::OnBg2()
 680.716 +{
 680.717 +	bg      = 2;
 680.718 +	control = BG2CNT;
 680.719 +	paint();
 680.720 +}
 680.721 +
 680.722 +void MapView::OnBg3()
 680.723 +{
 680.724 +	bg      = 3;
 680.725 +	control = BG3CNT;
 680.726 +	paint();
 680.727 +}
 680.728 +
 680.729 +void MapView::OnStretch()
 680.730 +{
 680.731 +	mapView.setStretch(!mapView.getStretch());
 680.732 +	paint();
 680.733 +	regSetDwordValue("mapViewStretch", mapView.getStretch());
 680.734 +}
 680.735 +
 680.736 +void MapView::OnAutoUpdate()
 680.737 +{
 680.738 +	autoUpdate = !autoUpdate;
 680.739 +	if (autoUpdate)
 680.740 +	{
 680.741 +		theApp.winAddUpdateListener(this);
 680.742 +	}
 680.743 +	else
 680.744 +	{
 680.745 +		theApp.winRemoveUpdateListener(this);
 680.746 +	}
 680.747 +}
 680.748 +
 680.749 +void MapView::update()
 680.750 +{
 680.751 +	paint();
 680.752 +}
 680.753 +
 680.754 +void MapView::OnClose()
 680.755 +{
 680.756 +	theApp.winRemoveUpdateListener(this);
 680.757 +
 680.758 +	DestroyWindow();
 680.759 +}
 680.760 +
 680.761 +u32 MapView::GetTextClickAddress(u32 base, int x, int y)
 680.762 +{
 680.763 +	if (y > 255 && h > 256)
 680.764 +	{
 680.765 +		base += 0x800;
 680.766 +		if (w > 256)
 680.767 +			base += 0x800;
 680.768 +	}
 680.769 +	if (x >= 256)
 680.770 +		base += 0x800;
 680.771 +	x    &= 255;
 680.772 +	y    &= 255;
 680.773 +	base += (x>>3)*2 + 64*(y>>3);
 680.774 +
 680.775 +	return base;
 680.776 +}
 680.777 +
 680.778 +u32 MapView::GetClickAddress(int x, int y)
 680.779 +{
 680.780 +	int mode = DISPCNT & 7;
 680.781 +
 680.782 +	u32 base = ((control >> 8) & 0x1f) * 0x800 + 0x6000000;
 680.783 +
 680.784 +	// all text bgs (16 bits)
 680.785 +	if (mode == 0 || (mode < 3 && bg < 2))
 680.786 +	{
 680.787 +		return GetTextClickAddress(base, x, y);
 680.788 +	}
 680.789 +	// rot bgs (8 bits)
 680.790 +	if (mode < 3)
 680.791 +	{
 680.792 +		return base + (x>>3) + (w>>3)*(y>>3);
 680.793 +	}
 680.794 +	// mode 3/5 (16 bits)
 680.795 +	if (mode != 4)
 680.796 +	{
 680.797 +		return 0x6000000 + 0xa000*frame + 2*x + w*y*2;
 680.798 +	}
 680.799 +	// mode 4 (8 bits)
 680.800 +	return 0x6000000 + 0xa000*frame + x + w*y;
 680.801 +}
 680.802 +
 680.803 +LRESULT MapView::OnMapInfo(WPARAM wParam, LPARAM lParam)
 680.804 +{
 680.805 +	u8 *colors = (u8 *)lParam;
 680.806 +	mapViewZoom.setColors(colors);
 680.807 +
 680.808 +	int x = wParam & 0xffff;
 680.809 +	int y = (wParam >> 16);
 680.810 +
 680.811 +	CString buffer;
 680.812 +	buffer.Format("(%d,%d)", x, y);
 680.813 +	GetDlgItem(IDC_XY)->SetWindowText(buffer);
 680.814 +
 680.815 +	u32 address = GetClickAddress(x, y);
 680.816 +	buffer.Format("0x%08X", address);
 680.817 +	GetDlgItem(IDC_ADDRESS)->SetWindowText(buffer);
 680.818 +
 680.819 +	int mode = DISPCNT & 7;
 680.820 +	if (mode >= 3)
 680.821 +	{
 680.822 +		// bitmap modes
 680.823 +		GetDlgItem(IDC_TILE_NUM)->SetWindowText("---");
 680.824 +		GetDlgItem(IDC_FLIP)->SetWindowText("--");
 680.825 +		GetDlgItem(IDC_PALETTE_NUM)->SetWindowText("---");
 680.826 +	}
 680.827 +	else if (mode == 0 || bg < 2)
 680.828 +	{
 680.829 +		// text bgs
 680.830 +		u16 value = *((u16 *)&vram[address - 0x6000000]);
 680.831 +
 680.832 +		int tile = value & 1023;
 680.833 +		buffer.Format("%d", tile);
 680.834 +		GetDlgItem(IDC_TILE_NUM)->SetWindowText(buffer);
 680.835 +		buffer.Empty();
 680.836 +		buffer += value & 1024 ? 'H' : '-';
 680.837 +		buffer += value & 2048 ? 'V' : '-';
 680.838 +		GetDlgItem(IDC_FLIP)->SetWindowText(buffer);
 680.839 +
 680.840 +		if (!(control & 0x80))
 680.841 +		{
 680.842 +			buffer.Format("%d", (value >> 12) & 15);
 680.843 +		}
 680.844 +		else
 680.845 +			buffer = "---";
 680.846 +		GetDlgItem(IDC_PALETTE_NUM)->SetWindowText(buffer);
 680.847 +	}
 680.848 +	else
 680.849 +	{
 680.850 +		// rot bgs
 680.851 +		GetDlgItem(IDC_TILE_NUM)->SetWindowText("---");
 680.852 +		GetDlgItem(IDC_FLIP)->SetWindowText("--");
 680.853 +		GetDlgItem(IDC_PALETTE_NUM)->SetWindowText("---");
 680.854 +	}
 680.855 +
 680.856 +	return TRUE;
 680.857 +}
 680.858 +
 680.859 +LRESULT MapView::OnColInfo(WPARAM wParam, LPARAM lParam)
 680.860 +{
 680.861 +	u16 c = (u16)wParam;
 680.862 +
 680.863 +	color.setColor(c);
 680.864 +
 680.865 +	int r = (c & 0x1f);
 680.866 +	int g = (c & 0x3e0) >> 5;
 680.867 +	int b = (c & 0x7c00) >> 10;
 680.868 +
 680.869 +	CString buffer;
 680.870 +	buffer.Format("R: %d", r);
 680.871 +	GetDlgItem(IDC_R)->SetWindowText(buffer);
 680.872 +
 680.873 +	buffer.Format("G: %d", g);
 680.874 +	GetDlgItem(IDC_G)->SetWindowText(buffer);
 680.875 +
 680.876 +	buffer.Format("B: %d", b);
 680.877 +	GetDlgItem(IDC_B)->SetWindowText(buffer);
 680.878 +
 680.879 +	return TRUE;
 680.880 +}
 680.881 +
 680.882 +void MapView::saveBMP(const char *name)
 680.883 +{
 680.884 +	u8 writeBuffer[1024 * 3];
 680.885 +
 680.886 +	FILE *fp = fopen(name, "wb");
 680.887 +
 680.888 +	if (!fp)
 680.889 +	{
 680.890 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
 680.891 +		return;
 680.892 +	}
 680.893 +
 680.894 +	struct
 680.895 +	{
 680.896 +		u8 ident[2];
 680.897 +		u8 filesize[4];
 680.898 +		u8 reserved[4];
 680.899 +		u8 dataoffset[4];
 680.900 +		u8 headersize[4];
 680.901 +		u8 width[4];
 680.902 +		u8 height[4];
 680.903 +		u8 planes[2];
 680.904 +		u8 bitsperpixel[2];
 680.905 +		u8 compression[4];
 680.906 +		u8 datasize[4];
 680.907 +		u8 hres[4];
 680.908 +		u8 vres[4];
 680.909 +		u8 colors[4];
 680.910 +		u8 importantcolors[4];
 680.911 +		u8 pad[2];
 680.912 +	} bmpheader;
 680.913 +	memset(&bmpheader, 0, sizeof(bmpheader));
 680.914 +
 680.915 +	bmpheader.ident[0] = 'B';
 680.916 +	bmpheader.ident[1] = 'M';
 680.917 +
 680.918 +	u32 fsz = sizeof(bmpheader) + w*h*3;
 680.919 +	utilPutDword(bmpheader.filesize, fsz);
 680.920 +	utilPutDword(bmpheader.dataoffset, 0x38);
 680.921 +	utilPutDword(bmpheader.headersize, 0x28);
 680.922 +	utilPutDword(bmpheader.width, w);
 680.923 +	utilPutDword(bmpheader.height, h);
 680.924 +	utilPutDword(bmpheader.planes, 1);
 680.925 +	utilPutDword(bmpheader.bitsperpixel, 24);
 680.926 +	utilPutDword(bmpheader.datasize, 3*w*h);
 680.927 +
 680.928 +	fwrite(&bmpheader, 1, sizeof(bmpheader), fp);
 680.929 +
 680.930 +	u8 *b = writeBuffer;
 680.931 +
 680.932 +	int sizeX = w;
 680.933 +	int sizeY = h;
 680.934 +
 680.935 +	u8 *pixU8 = (u8 *)data+3*w*(h-1);
 680.936 +	for (int y = 0; y < sizeY; y++)
 680.937 +	{
 680.938 +		for (int x = 0; x < sizeX; x++)
 680.939 +		{
 680.940 +			*b++ = *pixU8++; // B
 680.941 +			*b++ = *pixU8++; // G
 680.942 +			*b++ = *pixU8++; // R
 680.943 +		}
 680.944 +		pixU8 -= 2*3*w;
 680.945 +		fwrite(writeBuffer, 1, 3*w, fp);
 680.946 +
 680.947 +		b = writeBuffer;
 680.948 +	}
 680.949 +
 680.950 +	fclose(fp);
 680.951 +}
 680.952 +
 680.953 +void MapView::savePNG(const char *name)
 680.954 +{
 680.955 +	u8 writeBuffer[1024 * 3];
 680.956 +
 680.957 +	FILE *fp = fopen(name, "wb");
 680.958 +
 680.959 +	if (!fp)
 680.960 +	{
 680.961 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
 680.962 +		return;
 680.963 +	}
 680.964 +
 680.965 +	png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
 680.966 +	                                              NULL,
 680.967 +	                                              NULL,
 680.968 +	                                              NULL);
 680.969 +	if (!png_ptr)
 680.970 +	{
 680.971 +		fclose(fp);
 680.972 +		return;
 680.973 +	}
 680.974 +
 680.975 +	png_infop info_ptr = png_create_info_struct(png_ptr);
 680.976 +
 680.977 +	if (!info_ptr)
 680.978 +	{
 680.979 +		png_destroy_write_struct(&png_ptr, NULL);
 680.980 +		fclose(fp);
 680.981 +		return;
 680.982 +	}
 680.983 +
 680.984 +	if (setjmp(png_ptr->jmpbuf))
 680.985 +	{
 680.986 +		png_destroy_write_struct(&png_ptr, NULL);
 680.987 +		fclose(fp);
 680.988 +		return;
 680.989 +	}
 680.990 +
 680.991 +	png_init_io(png_ptr, fp);
 680.992 +
 680.993 +	png_set_IHDR(png_ptr,
 680.994 +	             info_ptr,
 680.995 +	             w,
 680.996 +	             h,
 680.997 +	             8,
 680.998 +	             PNG_COLOR_TYPE_RGB,
 680.999 +	             PNG_INTERLACE_NONE,
680.1000 +	             PNG_COMPRESSION_TYPE_DEFAULT,
680.1001 +	             PNG_FILTER_TYPE_DEFAULT);
680.1002 +
680.1003 +	png_write_info(png_ptr, info_ptr);
680.1004 +
680.1005 +	u8 *b = writeBuffer;
680.1006 +
680.1007 +	int sizeX = w;
680.1008 +	int sizeY = h;
680.1009 +
680.1010 +	u8 *pixU8 = (u8 *)data;
680.1011 +	for (int y = 0; y < sizeY; y++)
680.1012 +	{
680.1013 +		for (int x = 0; x < sizeX; x++)
680.1014 +		{
680.1015 +			int blue  = *pixU8++;
680.1016 +			int green = *pixU8++;
680.1017 +			int red   = *pixU8++;
680.1018 +
680.1019 +			*b++ = red;
680.1020 +			*b++ = green;
680.1021 +			*b++ = blue;
680.1022 +		}
680.1023 +		png_write_row(png_ptr, writeBuffer);
680.1024 +
680.1025 +		b = writeBuffer;
680.1026 +	}
680.1027 +
680.1028 +	png_write_end(png_ptr, info_ptr);
680.1029 +
680.1030 +	png_destroy_write_struct(&png_ptr, &info_ptr);
680.1031 +
680.1032 +	fclose(fp);
680.1033 +}
680.1034 +
680.1035 +void MapView::OnSave()
680.1036 +{
680.1037 +	CString filename;
680.1038 +
680.1039 +	if (theApp.captureFormat == 0)
680.1040 +		filename = "map.png";
680.1041 +	else
680.1042 +		filename = "map.bmp";
680.1043 +
680.1044 +	LPCTSTR exts[] = {".png", ".bmp", NULL };
680.1045 +
680.1046 +	CString filter = winResLoadFilter(IDS_FILTER_PNG);
680.1047 +	CString title  = winResLoadString(IDS_SELECT_CAPTURE_NAME);
680.1048 +
680.1049 +	FileDlg dlg(this,
680.1050 +	            filename,
680.1051 +	            filter,
680.1052 +	            theApp.captureFormat ? 2 : 1,
680.1053 +	            theApp.captureFormat ? "BMP" : "PNG",
680.1054 +	            exts,
680.1055 +	            "",
680.1056 +	            title,
680.1057 +	            true);
680.1058 +
680.1059 +	if (dlg.DoModal() == IDCANCEL)
680.1060 +	{
680.1061 +		return;
680.1062 +	}
680.1063 +
680.1064 +	if (dlg.getFilterIndex() == 2)
680.1065 +		saveBMP(dlg.GetPathName());
680.1066 +	else
680.1067 +		savePNG(dlg.GetPathName());
680.1068 +}
680.1069 +
   681.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   681.2 +++ b/src/win32/MapView.h	Sat Mar 03 10:31:27 2012 -0600
   681.3 @@ -0,0 +1,101 @@
   681.4 +#if !defined(AFX_MAPVIEW_H__20F40C77_8E10_44B7_BB49_7865F73C3E75__INCLUDED_)
   681.5 +#define AFX_MAPVIEW_H__20F40C77_8E10_44B7_BB49_7865F73C3E75__INCLUDED_
   681.6 +
   681.7 +#if _MSC_VER > 1000
   681.8 +#pragma once
   681.9 +#endif // _MSC_VER > 1000
  681.10 +// -*- C++ -*-
  681.11 +// MapView.h : header file
  681.12 +//
  681.13 +
  681.14 +#include "BitmapControl.h"
  681.15 +#include "ColorControl.h"
  681.16 +#include "ZoomControl.h"
  681.17 +#include "ResizeDlg.h"
  681.18 +#include "IUpdate.h"
  681.19 +
  681.20 +/////////////////////////////////////////////////////////////////////////////
  681.21 +// MapView dialog
  681.22 +
  681.23 +class MapView : public ResizeDlg, IUpdateListener
  681.24 +{
  681.25 +private:
  681.26 +	BITMAPINFO    bmpInfo;
  681.27 +	u8 *          data;
  681.28 +	int           frame;
  681.29 +	u16           control;
  681.30 +	int           bg;
  681.31 +	int           w;
  681.32 +	int           h;
  681.33 +	BitmapControl mapView;
  681.34 +	ZoomControl   mapViewZoom;
  681.35 +	ColorControl  color;
  681.36 +	bool          autoUpdate;
  681.37 +
  681.38 +	// Construction
  681.39 +public:
  681.40 +	void savePNG(const char *name);
  681.41 +	void saveBMP(const char *name);
  681.42 +	afx_msg LRESULT OnColInfo(WPARAM wParam, LPARAM lParam);
  681.43 +	afx_msg LRESULT OnMapInfo(WPARAM wParam, LPARAM lParam);
  681.44 +	u32 GetClickAddress(int x, int y);
  681.45 +	u32 GetTextClickAddress(u32 base, int x, int y);
  681.46 +	void update();
  681.47 +	void enableButtons(int mode);
  681.48 +	void paint();
  681.49 +	void renderMode5();
  681.50 +	void renderMode4();
  681.51 +	void renderMode3();
  681.52 +	void renderMode2();
  681.53 +	void renderMode1();
  681.54 +	void renderMode0();
  681.55 +	void renderRotScreen(u16 control);
  681.56 +	void renderTextScreen(u16 control);
  681.57 +	MapView(CWnd*pParent = NULL);  // standard constructor
  681.58 +	~MapView();
  681.59 +
  681.60 +	// Dialog Data
  681.61 +	//{{AFX_DATA(MapView)
  681.62 +	enum { IDD = IDD_MAP_VIEW };
  681.63 +	CStatic m_numcolors;
  681.64 +	CStatic m_mode;
  681.65 +	CStatic m_overflow;
  681.66 +	CStatic m_mosaic;
  681.67 +	CStatic m_priority;
  681.68 +	CStatic m_dim;
  681.69 +	CStatic m_charbase;
  681.70 +	CStatic m_mapbase;
  681.71 +	//}}AFX_DATA
  681.72 +
  681.73 +	// Overrides
  681.74 +	// ClassWizard generated virtual function overrides
  681.75 +	//{{AFX_VIRTUAL(MapView)
  681.76 +protected:
  681.77 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  681.78 +	virtual void PostNcDestroy();
  681.79 +	//}}AFX_VIRTUAL
  681.80 +
  681.81 +	// Implementation
  681.82 +protected:
  681.83 +	// Generated message map functions
  681.84 +	//{{AFX_MSG(MapView)
  681.85 +	afx_msg void OnRefresh();
  681.86 +	virtual BOOL OnInitDialog();
  681.87 +	afx_msg void OnFrame0();
  681.88 +	afx_msg void OnFrame1();
  681.89 +	afx_msg void OnBg0();
  681.90 +	afx_msg void OnBg1();
  681.91 +	afx_msg void OnBg2();
  681.92 +	afx_msg void OnBg3();
  681.93 +	afx_msg void OnStretch();
  681.94 +	afx_msg void OnAutoUpdate();
  681.95 +	afx_msg void OnClose();
  681.96 +	afx_msg void OnSave();
  681.97 +	//}}AFX_MSG
  681.98 +	DECLARE_MESSAGE_MAP()
  681.99 +};
 681.100 +
 681.101 +//{{AFX_INSERT_LOCATION}}
 681.102 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
 681.103 +
 681.104 +#endif // !defined(AFX_MAPVIEW_H__20F40C77_8E10_44B7_BB49_7865F73C3E75__INCLUDED_)
   682.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   682.2 +++ b/src/win32/MaxScale.cpp	Sat Mar 03 10:31:27 2012 -0600
   682.3 @@ -0,0 +1,64 @@
   682.4 +// MaxScale.cpp : implementation file
   682.5 +//
   682.6 +
   682.7 +#include "stdafx.h"
   682.8 +#include "resource.h"
   682.9 +#include "MaxScale.h"
  682.10 +#include "VBA.h"
  682.11 +
  682.12 +/////////////////////////////////////////////////////////////////////////////
  682.13 +// MaxScale dialog
  682.14 +
  682.15 +MaxScale::MaxScale(CWnd*pParent /*=NULL*/)
  682.16 +	: CDialog(MaxScale::IDD, pParent)
  682.17 +{
  682.18 +	//{{AFX_DATA_INIT(MaxScale)
  682.19 +	// NOTE: the ClassWizard will add member initialization here
  682.20 +	//}}AFX_DATA_INIT
  682.21 +}
  682.22 +
  682.23 +void MaxScale::DoDataExchange(CDataExchange*pDX)
  682.24 +{
  682.25 +	CDialog::DoDataExchange(pDX);
  682.26 +	//{{AFX_DATA_MAP(MaxScale)
  682.27 +	DDX_Control(pDX, IDC_VALUE, m_value);
  682.28 +	//}}AFX_DATA_MAP
  682.29 +}
  682.30 +
  682.31 +BEGIN_MESSAGE_MAP(MaxScale, CDialog)
  682.32 +//{{AFX_MSG_MAP(MaxScale)
  682.33 +ON_BN_CLICKED(ID_OK, OnOk)
  682.34 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
  682.35 +//}}AFX_MSG_MAP
  682.36 +END_MESSAGE_MAP()
  682.37 +
  682.38 +/////////////////////////////////////////////////////////////////////////////
  682.39 +// MaxScale message handlers
  682.40 +
  682.41 +void MaxScale::OnCancel()
  682.42 +{
  682.43 +	EndDialog(FALSE);
  682.44 +}
  682.45 +
  682.46 +void MaxScale::OnOk()
  682.47 +{
  682.48 +	CString tmp;
  682.49 +	m_value.GetWindowText(tmp);
  682.50 +	theApp.fsMaxScale = atoi(tmp);
  682.51 +	EndDialog(TRUE);
  682.52 +}
  682.53 +
  682.54 +BOOL MaxScale::OnInitDialog()
  682.55 +{
  682.56 +	CDialog::OnInitDialog();
  682.57 +
  682.58 +	CString temp;
  682.59 +
  682.60 +	temp.Format("%d", theApp.fsMaxScale);
  682.61 +
  682.62 +	m_value.SetWindowText(temp);
  682.63 +
  682.64 +	return TRUE;  // return TRUE unless you set the focus to a control
  682.65 +	              // EXCEPTION: OCX Property Pages should return FALSE
  682.66 +}
  682.67 +
   683.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   683.2 +++ b/src/win32/MaxScale.h	Sat Mar 03 10:31:27 2012 -0600
   683.3 @@ -0,0 +1,47 @@
   683.4 +#if !defined(AFX_MAXSCALE_H__3F42C0CC_DD5E_4A96_A60D_33AB7CBDE406__INCLUDED_)
   683.5 +#define AFX_MAXSCALE_H__3F42C0CC_DD5E_4A96_A60D_33AB7CBDE406__INCLUDED_
   683.6 +
   683.7 +#if _MSC_VER > 1000
   683.8 +#pragma once
   683.9 +#endif // _MSC_VER > 1000
  683.10 +// -*- C++ -*-
  683.11 +// MaxScale.h : header file
  683.12 +//
  683.13 +
  683.14 +/////////////////////////////////////////////////////////////////////////////
  683.15 +// MaxScale dialog
  683.16 +
  683.17 +class MaxScale : public CDialog
  683.18 +{
  683.19 +// Construction
  683.20 +public:
  683.21 +	MaxScale(CWnd*pParent = NULL);    // standard constructor
  683.22 +
  683.23 +// Dialog Data
  683.24 +	//{{AFX_DATA(MaxScale)
  683.25 +	enum { IDD = IDD_MAX_SCALE };
  683.26 +	CEdit m_value;
  683.27 +	//}}AFX_DATA
  683.28 +
  683.29 +// Overrides
  683.30 +	// ClassWizard generated virtual function overrides
  683.31 +	//{{AFX_VIRTUAL(MaxScale)
  683.32 +protected:
  683.33 +	virtual void DoDataExchange(CDataExchange*pDX);     // DDX/DDV support
  683.34 +	//}}AFX_VIRTUAL
  683.35 +
  683.36 +// Implementation
  683.37 +protected:
  683.38 +	// Generated message map functions
  683.39 +	//{{AFX_MSG(MaxScale)
  683.40 +	afx_msg void OnCancel();
  683.41 +	afx_msg void OnOk();
  683.42 +	virtual BOOL OnInitDialog();
  683.43 +	//}}AFX_MSG
  683.44 +	DECLARE_MESSAGE_MAP()
  683.45 +};
  683.46 +
  683.47 +//{{AFX_INSERT_LOCATION}}
  683.48 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  683.49 +
  683.50 +#endif // !defined(AFX_MAXSCALE_H__3F42C0CC_DD5E_4A96_A60D_33AB7CBDE406__INCLUDED_)
   684.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   684.2 +++ b/src/win32/MemoryViewer.cpp	Sat Mar 03 10:31:27 2012 -0600
   684.3 @@ -0,0 +1,688 @@
   684.4 +// MemoryViewer.cpp : implementation file
   684.5 +//
   684.6 +
   684.7 +#include "stdafx.h"
   684.8 +#include "resource.h"
   684.9 +#include "MemoryViewer.h"
  684.10 +
  684.11 +extern int emulating;
  684.12 +
  684.13 +/////////////////////////////////////////////////////////////////////////////
  684.14 +// MemoryViewer
  684.15 +
  684.16 +bool MemoryViewer::isRegistered = false;
  684.17 +
  684.18 +MemoryViewer::MemoryViewer()
  684.19 +{
  684.20 +	address        = 0;
  684.21 +	addressSize    = 0;
  684.22 +	dataSize       = 0;
  684.23 +	editAddress    = 0;
  684.24 +	editNibble     = 0;
  684.25 +	displayedLines = 0;
  684.26 +	hasCaret       = false;
  684.27 +	maxNibble      = 0;
  684.28 +	font        = (HFONT)GetStockObject(SYSTEM_FIXED_FONT);
  684.29 +	fontSize.cx = fontSize.cy = 0;
  684.30 +	beginAscii  = 0;
  684.31 +	beginHex    = 0;
  684.32 +	dlg         = NULL;
  684.33 +	registerClass();
  684.34 +}
  684.35 +
  684.36 +MemoryViewer::~MemoryViewer()
  684.37 +{}
  684.38 +
  684.39 +BEGIN_MESSAGE_MAP(MemoryViewer, CWnd)
  684.40 +//{{AFX_MSG_MAP(MemoryViewer)
  684.41 +ON_WM_ERASEBKGND()
  684.42 +ON_WM_PAINT()
  684.43 +ON_WM_VSCROLL()
  684.44 +ON_WM_GETDLGCODE()
  684.45 +ON_WM_LBUTTONDOWN()
  684.46 +ON_WM_SETFOCUS()
  684.47 +ON_WM_KILLFOCUS()
  684.48 +ON_WM_KEYDOWN()
  684.49 +//}}AFX_MSG_MAP
  684.50 +ON_MESSAGE(WM_CHAR, OnWMChar)
  684.51 +END_MESSAGE_MAP()
  684.52 +
  684.53 +/////////////////////////////////////////////////////////////////////////////
  684.54 +// MemoryViewer message handlers
  684.55 +
  684.56 +void MemoryViewer::setDialog(IMemoryViewerDlg *d)
  684.57 +{
  684.58 +	dlg = d;
  684.59 +}
  684.60 +
  684.61 +void MemoryViewer::setAddress(u32 a)
  684.62 +{
  684.63 +	address = a;
  684.64 +	if (displayedLines)
  684.65 +	{
  684.66 +		if (addressSize)
  684.67 +		{
  684.68 +			u16 addr = address;
  684.69 +			if ((u16)((addr+(displayedLines<<4)) & 0xFFFF) < addr)
  684.70 +			{
  684.71 +				address = 0xffff - (displayedLines<<4) + 1;
  684.72 +			}
  684.73 +		}
  684.74 +		else
  684.75 +		{
  684.76 +			if ((address+(displayedLines<<4)) < address)
  684.77 +			{
  684.78 +				address = 0xffffffff - (displayedLines<<4) + 1;
  684.79 +			}
  684.80 +		}
  684.81 +	}
  684.82 +	if (addressSize)
  684.83 +		address &= 0xffff;
  684.84 +	setCaretPos();
  684.85 +	InvalidateRect(NULL, TRUE);
  684.86 +}
  684.87 +
  684.88 +void MemoryViewer::setSize(int s)
  684.89 +{
  684.90 +	dataSize = s;
  684.91 +	if (s == 0)
  684.92 +		maxNibble = 1;
  684.93 +	else if (s == 1)
  684.94 +		maxNibble = 3;
  684.95 +	else
  684.96 +		maxNibble = 7;
  684.97 +
  684.98 +	InvalidateRect(NULL, TRUE);
  684.99 +}
 684.100 +
 684.101 +void MemoryViewer::setDecimal(bool decimalDisplayMode)
 684.102 +{
 684.103 +	decimalDisplay = decimalDisplayMode;
 684.104 +	InvalidateRect(NULL, TRUE);
 684.105 +}
 684.106 +
 684.107 +BOOL MemoryViewer::OnEraseBkgnd(CDC*pDC)
 684.108 +{
 684.109 +	return TRUE;
 684.110 +}
 684.111 +
 684.112 +void MemoryViewer::updateScrollInfo(int lines)
 684.113 +{
 684.114 +	int        page = lines * 16;
 684.115 +	SCROLLINFO si;
 684.116 +	ZeroMemory(&si, sizeof(si));
 684.117 +	si.cbSize = sizeof(si);
 684.118 +	si.fMask  = SIF_PAGE | SIF_RANGE | SIF_DISABLENOSCROLL | SIF_POS;
 684.119 +	si.nMin   = 0;
 684.120 +	if (addressSize)
 684.121 +	{
 684.122 +		si.nMax  = 0x10000/page;
 684.123 +		si.nPage = 1;
 684.124 +	}
 684.125 +	else
 684.126 +	{
 684.127 +		si.nMax  = 0xa000000 / page;
 684.128 +		si.nPage = page;
 684.129 +	}
 684.130 +
 684.131 +	si.nPos = address / page;
 684.132 +	SetScrollInfo(SB_VERT,
 684.133 +	              &si,
 684.134 +	              TRUE);
 684.135 +}
 684.136 +
 684.137 +void MemoryViewer::OnPaint()
 684.138 +{
 684.139 +	CPaintDC dc(this); // device context for painting
 684.140 +
 684.141 +	RECT rect;
 684.142 +	GetClientRect(&rect);
 684.143 +	int w = rect.right - rect.left;
 684.144 +	int h = rect.bottom - rect.top - 6;
 684.145 +
 684.146 +	CDC memDC;
 684.147 +	memDC.CreateCompatibleDC(&dc);
 684.148 +	CBitmap bitmap, *pOldBitmap;
 684.149 +	bitmap.CreateCompatibleBitmap(&dc, w, rect.bottom - rect.top);
 684.150 +	pOldBitmap = memDC.SelectObject(&bitmap);
 684.151 +
 684.152 +	memDC.FillRect(&rect, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
 684.153 +	memDC.DrawEdge(&rect, EDGE_ETCHED, BF_RECT);
 684.154 +
 684.155 +	CFont *oldFont = memDC.SelectObject(CFont::FromHandle(font));
 684.156 +
 684.157 +	fontSize = memDC.GetTextExtent("0", 1);
 684.158 +
 684.159 +	int lines = h / fontSize.cy;
 684.160 +
 684.161 +	displayedLines = lines;
 684.162 +
 684.163 +	updateScrollInfo(lines);
 684.164 +
 684.165 +	u32 addr = address;
 684.166 +
 684.167 +	memDC.SetTextColor(RGB(0, 0, 0));
 684.168 +
 684.169 +	u8 data[32];
 684.170 +
 684.171 +	RECT r;
 684.172 +	r.top    = 3;
 684.173 +	r.left   = 3;
 684.174 +	r.bottom = r.top+fontSize.cy;
 684.175 +	r.right  = rect.right-3;
 684.176 +
 684.177 +	int line = 0;
 684.178 +
 684.179 +	for (int i = 0; i < lines; i++)
 684.180 +	{
 684.181 +		CString buffer;
 684.182 +		if (addressSize)
 684.183 +			buffer.Format("%04X", addr);
 684.184 +		else
 684.185 +			buffer.Format("%08X", addr);
 684.186 +		memDC.DrawText(buffer, &r, DT_TOP | DT_LEFT | DT_NOPREFIX);
 684.187 +		r.left  += 10*fontSize.cx;
 684.188 +		beginHex = r.left;
 684.189 +		readData(addr, 16, data);
 684.190 +
 684.191 +		int j;
 684.192 +
 684.193 +		if (dataSize == 0)
 684.194 +		{
 684.195 +			for (j = 0; j < 16; j++)
 684.196 +			{
 684.197 +				const int nextRLeft = r.left + 3*fontSize.cx;
 684.198 +				if (!decimalDisplay)
 684.199 +					buffer.Format("%02X", data[j]);
 684.200 +				else
 684.201 +				{
 684.202 +					const signed char num = data[j];
 684.203 +					if (num < -9 || num > 99)
 684.204 +						r.left -= fontSize.cx;
 684.205 +					if (num >= -99 && num <= 99)
 684.206 +						buffer.Format("%2d", num);
 684.207 +					else
 684.208 +						buffer.Format("");
 684.209 +				}
 684.210 +				memDC.DrawText(buffer, &r, DT_TOP | DT_LEFT | DT_NOPREFIX);
 684.211 +				r.left = nextRLeft;
 684.212 +			}
 684.213 +		}
 684.214 +		if (dataSize == 1)
 684.215 +		{
 684.216 +			for (j = 0; j < 16; j += 2)
 684.217 +			{
 684.218 +				const int nextRLeft = r.left + 5*fontSize.cx;
 684.219 +				if (!decimalDisplay)
 684.220 +					buffer.Format("%04X", data[j] | data[j+1]<<8);
 684.221 +				else
 684.222 +				{
 684.223 +					const signed short num = data[j] | data[j+1]<<8;
 684.224 +					if (num < -999 || num > 9999)
 684.225 +						r.left -= fontSize.cx;
 684.226 +					if (num >= -9999 && num <= 9999)
 684.227 +						buffer.Format("%4d", num);
 684.228 +					else
 684.229 +						buffer.Format("");
 684.230 +				}
 684.231 +				memDC.DrawText(buffer, &r, DT_TOP | DT_LEFT | DT_NOPREFIX);
 684.232 +				r.left = nextRLeft;
 684.233 +			}
 684.234 +		}
 684.235 +		if (dataSize == 2)
 684.236 +		{
 684.237 +			for (j = 0; j < 16; j += 4)
 684.238 +			{
 684.239 +				if (!decimalDisplay)
 684.240 +					buffer.Format("%08X", data[j] | data[j+1]<<8 | data[j+2] << 16 | data[j+3] << 24);
 684.241 +				else
 684.242 +				{
 684.243 +					const signed long num = data[j] | data[j+1]<<8 | data[j+2] << 16 | data[j+3] << 24;
 684.244 +					if (num >= -9999999 && num <= 99999999)
 684.245 +						buffer.Format("%8d", num);
 684.246 +					else
 684.247 +						buffer.Format("");
 684.248 +				}
 684.249 +				memDC.DrawText(buffer, &r, DT_TOP | DT_LEFT | DT_NOPREFIX);
 684.250 +				r.left += 9*fontSize.cx;
 684.251 +			}
 684.252 +		}
 684.253 +
 684.254 +		line = r.left;
 684.255 +
 684.256 +		r.left    += fontSize.cx;
 684.257 +		beginAscii = r.left;
 684.258 +		buffer.Empty();
 684.259 +		for (j = 0; j < 16; j++)
 684.260 +		{
 684.261 +			char c = data[j];
 684.262 +			if (c >= 32 && c <= 127)
 684.263 +			{
 684.264 +				buffer += c;
 684.265 +			}
 684.266 +			else
 684.267 +				buffer += '.';
 684.268 +		}
 684.269 +
 684.270 +		memDC.DrawText(buffer, &r, DT_TOP | DT_LEFT | DT_NOPREFIX);
 684.271 +		addr += 16;
 684.272 +		if (addressSize)
 684.273 +			addr &= 0xffff;
 684.274 +		r.top    += fontSize.cy;
 684.275 +		r.bottom += fontSize.cy;
 684.276 +		r.left    = 3;
 684.277 +	}
 684.278 +	CPen pen;
 684.279 +	pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
 684.280 +	CPen *old = memDC.SelectObject(&pen);
 684.281 +
 684.282 +	memDC.MoveTo(3+fontSize.cx*9, 3);
 684.283 +	memDC.LineTo(3+fontSize.cx*9, 3+displayedLines*fontSize.cy);
 684.284 +
 684.285 +	memDC.MoveTo(line, 3);
 684.286 +	memDC.LineTo(line, 3+displayedLines*fontSize.cy);
 684.287 +
 684.288 +	memDC.SelectObject(old);
 684.289 +	pen.DeleteObject();
 684.290 +
 684.291 +	memDC.SelectObject(oldFont);
 684.292 +
 684.293 +	dc.BitBlt(0, 0, w, rect.bottom - rect.top, &memDC, 0, 0, SRCCOPY);
 684.294 +
 684.295 +	memDC.SelectObject(pOldBitmap);
 684.296 +	memDC.DeleteDC();
 684.297 +	bitmap.DeleteObject();
 684.298 +}
 684.299 +
 684.300 +void MemoryViewer::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar)
 684.301 +{
 684.302 +	int address = this->address;
 684.303 +	switch (nSBCode)
 684.304 +	{
 684.305 +	case SB_BOTTOM:
 684.306 +		address = 0xffffff00;
 684.307 +		break;
 684.308 +	case SB_LINEDOWN:
 684.309 +		address += 0x10;
 684.310 +		break;
 684.311 +	case SB_LINEUP:
 684.312 +		address -= 0x10;
 684.313 +		break;
 684.314 +	case SB_PAGEDOWN:
 684.315 +		address += (displayedLines<<4);
 684.316 +		break;
 684.317 +	case SB_PAGEUP:
 684.318 +		address -= (displayedLines<<4);
 684.319 +		break;
 684.320 +	case SB_TOP:
 684.321 +		address = 0;
 684.322 +		break;
 684.323 +	case SB_THUMBTRACK:
 684.324 +	{
 684.325 +		int        page = displayedLines * 16;
 684.326 +		SCROLLINFO si;
 684.327 +		ZeroMemory(&si, sizeof(si));
 684.328 +		si.cbSize = sizeof(si);
 684.329 +		si.fMask  = SIF_TRACKPOS;
 684.330 +		GetScrollInfo(SB_VERT, &si);
 684.331 +		address = page * si.nTrackPos;
 684.332 +		break;
 684.333 +	}
 684.334 +	}
 684.335 +	setAddress(address);
 684.336 +}
 684.337 +
 684.338 +UINT MemoryViewer::OnGetDlgCode()
 684.339 +{
 684.340 +	return DLGC_WANTALLKEYS;
 684.341 +}
 684.342 +
 684.343 +void MemoryViewer::createEditCaret(int w, int h)
 684.344 +{
 684.345 +	if (!hasCaret || caretWidth != w || caretHeight != h)
 684.346 +	{
 684.347 +		hasCaret    = true;
 684.348 +		caretWidth  = w;
 684.349 +		caretHeight = h;
 684.350 +		::CreateCaret(m_hWnd, (HBITMAP)0, w, h);
 684.351 +	}
 684.352 +}
 684.353 +
 684.354 +void MemoryViewer::destroyEditCaret()
 684.355 +{
 684.356 +	hasCaret = false;
 684.357 +	DestroyCaret();
 684.358 +}
 684.359 +
 684.360 +void MemoryViewer::setCaretPos()
 684.361 +{
 684.362 +	if (GetFocus() != this)
 684.363 +	{
 684.364 +		destroyEditCaret();
 684.365 +		return;
 684.366 +	}
 684.367 +
 684.368 +	if (dlg)
 684.369 +		dlg->setCurrentAddress(editAddress);
 684.370 +
 684.371 +	if (editAddress < address || editAddress > (address -1 + (displayedLines<<4)))
 684.372 +	{
 684.373 +		destroyEditCaret();
 684.374 +		return;
 684.375 +	}
 684.376 +
 684.377 +	int subAddress = (editAddress - address);
 684.378 +
 684.379 +	int x = 3+10*fontSize.cx+editNibble*fontSize.cx;
 684.380 +	int y = 3+fontSize.cy*((editAddress-address)>>4);
 684.381 +
 684.382 +	if (editAscii)
 684.383 +	{
 684.384 +		x = beginAscii + fontSize.cx*(subAddress&15);
 684.385 +	}
 684.386 +	else
 684.387 +	{
 684.388 +		switch (dataSize)
 684.389 +		{
 684.390 +		case 0:
 684.391 +			x += 3*fontSize.cx*(subAddress & 15);
 684.392 +			break;
 684.393 +		case 1:
 684.394 +			x += 5*fontSize.cx*((subAddress>>1) & 7);
 684.395 +			break;
 684.396 +		case 2:
 684.397 +			x += 9*fontSize.cx*((subAddress>>2) & 3);
 684.398 +			break;
 684.399 +		}
 684.400 +	}
 684.401 +
 684.402 +	RECT r;
 684.403 +	GetClientRect(&r);
 684.404 +	r.right -= 3;
 684.405 +	if (x >= r.right)
 684.406 +	{
 684.407 +		destroyEditCaret();
 684.408 +		return;
 684.409 +	}
 684.410 +	int w = fontSize.cx;
 684.411 +	if ((x+fontSize.cx) >= r.right)
 684.412 +		w = r.right - x;
 684.413 +	createEditCaret(w, fontSize.cy);
 684.414 +	::SetCaretPos(x, y);
 684.415 +	ShowCaret();
 684.416 +}
 684.417 +
 684.418 +void MemoryViewer::OnLButtonDown(UINT nFlags, CPoint point)
 684.419 +{
 684.420 +	int x           = point.x;
 684.421 +	int y           = point.y;
 684.422 +	int line        = (y-3)/fontSize.cy;
 684.423 +	int beforeAscii = beginHex;
 684.424 +	int inc         = 1;
 684.425 +	int sub         = 3*fontSize.cx;
 684.426 +	switch (dataSize)
 684.427 +	{
 684.428 +	case 0:
 684.429 +		beforeAscii += 47*fontSize.cx;
 684.430 +		break;
 684.431 +	case 1:
 684.432 +		beforeAscii += 39*fontSize.cx;
 684.433 +		inc          = 2;
 684.434 +		sub          = 5*fontSize.cx;
 684.435 +		break;
 684.436 +	case 2:
 684.437 +		beforeAscii += 35*fontSize.cx;
 684.438 +		inc          = 4;
 684.439 +		sub          = 9*fontSize.cx;
 684.440 +		break;
 684.441 +	}
 684.442 +
 684.443 +	editAddress = address + (line<<4);
 684.444 +	if (x >= beginHex && x < beforeAscii)
 684.445 +	{
 684.446 +		x -= beginHex;
 684.447 +		editNibble = 0;
 684.448 +		while (x > 0)
 684.449 +		{
 684.450 +			x -= sub;
 684.451 +			if (x >= 0)
 684.452 +				editAddress += inc;
 684.453 +			else
 684.454 +			{
 684.455 +				editNibble = (x + sub)/fontSize.cx;
 684.456 +			}
 684.457 +		}
 684.458 +		editAscii = false;
 684.459 +	}
 684.460 +	else if (x >= beginAscii)
 684.461 +	{
 684.462 +		int afterAscii = beginAscii+16*fontSize.cx;
 684.463 +		if (x >= afterAscii)
 684.464 +			x = afterAscii-1;
 684.465 +		editAddress += (x-beginAscii)/fontSize.cx;
 684.466 +		editNibble   = 0;
 684.467 +		editAscii    = true;
 684.468 +	}
 684.469 +	else
 684.470 +	{
 684.471 +		return;
 684.472 +	}
 684.473 +
 684.474 +	if (editNibble > maxNibble)
 684.475 +		editNibble = maxNibble;
 684.476 +	SetFocus();
 684.477 +	setCaretPos();
 684.478 +}
 684.479 +
 684.480 +void MemoryViewer::OnSetFocus(CWnd*pOldWnd)
 684.481 +{
 684.482 +	setCaretPos();
 684.483 +	InvalidateRect(NULL, TRUE);
 684.484 +}
 684.485 +
 684.486 +void MemoryViewer::OnKillFocus(CWnd*pNewWnd)
 684.487 +{
 684.488 +	destroyEditCaret();
 684.489 +	InvalidateRect(NULL, TRUE);
 684.490 +}
 684.491 +
 684.492 +void MemoryViewer::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
 684.493 +{
 684.494 +	bool isShift = (GetKeyState(VK_SHIFT) & 0x80000000) == 0x80000000;
 684.495 +
 684.496 +	switch (nChar)
 684.497 +	{
 684.498 +	case VK_RIGHT:
 684.499 +		if (editAscii)
 684.500 +			moveAddress(1, 0);
 684.501 +		else if (isShift)
 684.502 +			moveAddress((maxNibble+1)>>1, 0);
 684.503 +		else
 684.504 +			moveAddress(0, 1);
 684.505 +		break;
 684.506 +	case VK_LEFT:
 684.507 +		if (editAscii)
 684.508 +			moveAddress(-1, 0);
 684.509 +		else if (isShift)
 684.510 +			moveAddress(-((maxNibble+1)>>1), 0);
 684.511 +		else
 684.512 +			moveAddress(0, -1);
 684.513 +		break;
 684.514 +	case VK_DOWN:
 684.515 +		moveAddress(16, 0);
 684.516 +		break;
 684.517 +	case VK_UP:
 684.518 +		moveAddress(-16, 0);
 684.519 +		break;
 684.520 +	case VK_TAB:
 684.521 +		GetNextDlgTabItem(GetParent(), isShift)->SetFocus();
 684.522 +		break;
 684.523 +	}
 684.524 +}
 684.525 +
 684.526 +void MemoryViewer::moveAddress(s32 offset, int nibbleOff)
 684.527 +{
 684.528 +	if (offset == 0)
 684.529 +	{
 684.530 +		if (nibbleOff == -1)
 684.531 +		{
 684.532 +			editNibble--;
 684.533 +			if (editNibble == -1)
 684.534 +			{
 684.535 +				editAddress -= (maxNibble + 1) >> 1;
 684.536 +				editNibble   = maxNibble;
 684.537 +			}
 684.538 +			if (address == 0 && (editAddress >= (u32)(displayedLines<<4)))
 684.539 +			{
 684.540 +				editAddress = 0;
 684.541 +				editNibble  = 0;
 684.542 +				beep();
 684.543 +			}
 684.544 +			if (editAddress < address)
 684.545 +				setAddress(address - 16);
 684.546 +		}
 684.547 +		else
 684.548 +		{
 684.549 +			editNibble++;
 684.550 +			if (editNibble > maxNibble)
 684.551 +			{
 684.552 +				editNibble   = 0;
 684.553 +				editAddress += (maxNibble + 1) >> 1;
 684.554 +			}
 684.555 +			if (editAddress < address)
 684.556 +			{
 684.557 +				editAddress -= (maxNibble + 1) >> 1;
 684.558 +				editNibble   = maxNibble;
 684.559 +				beep();
 684.560 +			}
 684.561 +			if (editAddress >= (address+(displayedLines<<4)))
 684.562 +				setAddress(address+16);
 684.563 +		}
 684.564 +	}
 684.565 +	else
 684.566 +	{
 684.567 +		editAddress += offset;
 684.568 +		if (offset < 0 && editAddress > (address-1+(displayedLines<<4)))
 684.569 +		{
 684.570 +			editAddress -= offset;
 684.571 +			beep();
 684.572 +			return;
 684.573 +		}
 684.574 +		if (offset > 0 && (editAddress < address))
 684.575 +		{
 684.576 +			editAddress -= offset;
 684.577 +			beep();
 684.578 +			return;
 684.579 +		}
 684.580 +		if (editAddress < address)
 684.581 +		{
 684.582 +			if (offset & 15)
 684.583 +				setAddress((address+offset-16) & ~15);
 684.584 +			else
 684.585 +				setAddress(address+offset);
 684.586 +		}
 684.587 +		else if (editAddress > (address - 1 + (displayedLines<<4)))
 684.588 +		{
 684.589 +			if (offset & 15)
 684.590 +				setAddress((address+offset+16) & ~15);
 684.591 +			else
 684.592 +				setAddress(address+offset);
 684.593 +		}
 684.594 +	}
 684.595 +
 684.596 +	setCaretPos();
 684.597 +}
 684.598 +
 684.599 +LRESULT MemoryViewer::OnWMChar(WPARAM wParam, LPARAM LPARAM)
 684.600 +{
 684.601 +	if (OnEditInput(wParam))
 684.602 +		return 0;
 684.603 +	return 1;
 684.604 +}
 684.605 +
 684.606 +bool MemoryViewer::OnEditInput(UINT c)
 684.607 +{
 684.608 +	if (c > 255 || !emulating)
 684.609 +	{
 684.610 +		beep();
 684.611 +		return false;
 684.612 +	}
 684.613 +
 684.614 +	if (!editAscii)
 684.615 +		c = tolower(c);
 684.616 +
 684.617 +	u32 value = 256;
 684.618 +
 684.619 +	if (c >= 'a' && c <= 'f')
 684.620 +		value = 10 + (c - 'a');
 684.621 +	else if (c >= '0' && c <= '9')
 684.622 +		value = (c - '0');
 684.623 +	if (editAscii)
 684.624 +	{
 684.625 +		editData(editAddress, 8, 0, c);
 684.626 +		moveAddress(1, 0);
 684.627 +		InvalidateRect(NULL, TRUE);
 684.628 +	}
 684.629 +	else
 684.630 +	{
 684.631 +		if (value != 256)
 684.632 +		{
 684.633 +			value <<= 4*(maxNibble-editNibble);
 684.634 +			u32 mask = ~(15 << 4*(maxNibble - editNibble));
 684.635 +			switch (dataSize)
 684.636 +			{
 684.637 +			case 0:
 684.638 +				editData(editAddress, 8, mask, value);
 684.639 +				break;
 684.640 +			case 1:
 684.641 +				editData(editAddress, 16, mask, value);
 684.642 +				break;
 684.643 +			case 2:
 684.644 +				editData(editAddress, 32, mask, value);
 684.645 +				break;
 684.646 +			}
 684.647 +			moveAddress(0, 1);
 684.648 +			InvalidateRect(NULL, TRUE);
 684.649 +		}
 684.650 +	}
 684.651 +	return true;
 684.652 +}
 684.653 +
 684.654 +void MemoryViewer::beep()
 684.655 +{
 684.656 +	MessageBeep((UINT)-1);
 684.657 +}
 684.658 +
 684.659 +void MemoryViewer::registerClass()
 684.660 +{
 684.661 +	if (!isRegistered)
 684.662 +	{
 684.663 +		WNDCLASS wc;
 684.664 +		ZeroMemory(&wc, sizeof(wc));
 684.665 +		wc.style         = CS_PARENTDC | CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
 684.666 +		wc.lpfnWndProc   = (WNDPROC) ::DefWindowProc;
 684.667 +		wc.hInstance     = AfxGetInstanceHandle();
 684.668 +		wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
 684.669 +		wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
 684.670 +		wc.lpszMenuName  = NULL;
 684.671 +		wc.lpszClassName = "VbaMemoryViewer";
 684.672 +		AfxRegisterClass(&wc);
 684.673 +		isRegistered = true;
 684.674 +	}
 684.675 +}
 684.676 +
 684.677 +void MemoryViewer::setAddressSize(int s)
 684.678 +{
 684.679 +	addressSize = s;
 684.680 +}
 684.681 +
 684.682 +u32 MemoryViewer::getCurrentAddress()
 684.683 +{
 684.684 +	return editAddress;
 684.685 +}
 684.686 +
 684.687 +int MemoryViewer::getSize()
 684.688 +{
 684.689 +	return dataSize;
 684.690 +}
 684.691 +
   685.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   685.2 +++ b/src/win32/MemoryViewer.h	Sat Mar 03 10:31:27 2012 -0600
   685.3 @@ -0,0 +1,97 @@
   685.4 +#if !defined(AFX_MEMORYVIEWER_H__52C50474_5399_4D0B_A3E4_4C52C4E0EAA0__INCLUDED_)
   685.5 +#define AFX_MEMORYVIEWER_H__52C50474_5399_4D0B_A3E4_4C52C4E0EAA0__INCLUDED_
   685.6 +
   685.7 +#if _MSC_VER > 1000
   685.8 +#pragma once
   685.9 +#endif // _MSC_VER > 1000
  685.10 +// -*- C++ -*-
  685.11 +// MemoryViewer.h : header file
  685.12 +//
  685.13 +
  685.14 +/////////////////////////////////////////////////////////////////////////////
  685.15 +// MemoryViewer window
  685.16 +
  685.17 +class IMemoryViewerDlg
  685.18 +{
  685.19 +public:
  685.20 +	virtual void setCurrentAddress(u32 address) = 0;
  685.21 +};
  685.22 +
  685.23 +class MemoryViewer : public CWnd
  685.24 +{
  685.25 +	u32   address;
  685.26 +	int   addressSize;
  685.27 +	int   dataSize;
  685.28 +	bool  hasCaret;
  685.29 +	int   caretWidth;
  685.30 +	int   caretHeight;
  685.31 +	HFONT font;
  685.32 +	CSize fontSize;
  685.33 +	u32   editAddress;
  685.34 +	int   editNibble;
  685.35 +	int   maxNibble;
  685.36 +	int   displayedLines;
  685.37 +	int   beginAscii;
  685.38 +	int   beginHex;
  685.39 +	bool  editAscii;
  685.40 +	bool  decimalDisplay;
  685.41 +	IMemoryViewerDlg *dlg;
  685.42 +
  685.43 +	static bool isRegistered;
  685.44 +	// Construction
  685.45 +public:
  685.46 +	MemoryViewer();
  685.47 +
  685.48 +	// Attributes
  685.49 +public:
  685.50 +	// Operations
  685.51 +public:
  685.52 +	virtual void readData(u32, int, u8 *)     = 0;
  685.53 +	virtual void editData(u32, int, int, u32) = 0;
  685.54 +
  685.55 +	// Overrides
  685.56 +	// ClassWizard generated virtual function overrides
  685.57 +	//{{AFX_VIRTUAL(MemoryViewer)
  685.58 +	//}}AFX_VIRTUAL
  685.59 +
  685.60 +	// Implementation
  685.61 +public:
  685.62 +	int getSize();
  685.63 +	u32 getCurrentAddress();
  685.64 +	void setAddressSize(int s);
  685.65 +	void registerClass();
  685.66 +	void beep();
  685.67 +	bool OnEditInput(UINT c);
  685.68 +	void moveAddress(s32 offset, int nibbleOff);
  685.69 +	void setCaretPos();
  685.70 +	void destroyEditCaret();
  685.71 +	void createEditCaret(int w, int h);
  685.72 +	void updateScrollInfo(int lines);
  685.73 +	void setSize(int s);
  685.74 +	void setDecimal(bool decimalDisplayMode);
  685.75 +	void setAddress(u32 a);
  685.76 +	void setDialog(IMemoryViewerDlg *d);
  685.77 +	virtual ~MemoryViewer();
  685.78 +
  685.79 +	// Generated message map functions
  685.80 +protected:
  685.81 +	//{{AFX_MSG(MemoryViewer)
  685.82 +	afx_msg BOOL OnEraseBkgnd(CDC*pDC);
  685.83 +	afx_msg void OnPaint();
  685.84 +	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar);
  685.85 +	afx_msg UINT OnGetDlgCode();
  685.86 +	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  685.87 +	afx_msg void OnSetFocus(CWnd*pOldWnd);
  685.88 +	afx_msg void OnKillFocus(CWnd*pNewWnd);
  685.89 +	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  685.90 +	//}}AFX_MSG
  685.91 +	DECLARE_MESSAGE_MAP()
  685.92 +	afx_msg LRESULT OnWMChar(WPARAM wParam, LPARAM lParam);
  685.93 +};
  685.94 +
  685.95 +/////////////////////////////////////////////////////////////////////////////
  685.96 +
  685.97 +//{{AFX_INSERT_LOCATION}}
  685.98 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  685.99 +
 685.100 +#endif // !defined(AFX_MEMORYVIEWER_H__52C50474_5399_4D0B_A3E4_4C52C4E0EAA0__INCLUDED_)
   686.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   686.2 +++ b/src/win32/MemoryViewerAddressSize.cpp	Sat Mar 03 10:31:27 2012 -0600
   686.3 @@ -0,0 +1,115 @@
   686.4 +// MemoryViewerAddressSize.cpp : implementation file
   686.5 +//
   686.6 +
   686.7 +#include "stdafx.h"
   686.8 +#include "resource.h"
   686.9 +#include "MemoryViewerAddressSize.h"
  686.10 +
  686.11 +/////////////////////////////////////////////////////////////////////////////
  686.12 +// MemoryViewerAddressSize dialog
  686.13 +
  686.14 +MemoryViewerAddressSize::MemoryViewerAddressSize(u32 a, int s, CWnd*pParent /*=NULL*/)
  686.15 +	: CDialog(MemoryViewerAddressSize::IDD, pParent)
  686.16 +{
  686.17 +	//{{AFX_DATA_INIT(MemoryViewerAddressSize)
  686.18 +	// NOTE: the ClassWizard will add member initialization here
  686.19 +	//}}AFX_DATA_INIT
  686.20 +	address = a;
  686.21 +	size    = s;
  686.22 +}
  686.23 +
  686.24 +void MemoryViewerAddressSize::DoDataExchange(CDataExchange*pDX)
  686.25 +{
  686.26 +	CDialog::DoDataExchange(pDX);
  686.27 +	//{{AFX_DATA_MAP(MemoryViewerAddressSize)
  686.28 +	DDX_Control(pDX, IDC_SIZE_CONTROL, m_size);
  686.29 +	DDX_Control(pDX, IDC_ADDRESS, m_address);
  686.30 +	//}}AFX_DATA_MAP
  686.31 +}
  686.32 +
  686.33 +BEGIN_MESSAGE_MAP(MemoryViewerAddressSize, CDialog)
  686.34 +//{{AFX_MSG_MAP(MemoryViewerAddressSize)
  686.35 +ON_BN_CLICKED(ID_OK, OnOk)
  686.36 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
  686.37 +//}}AFX_MSG_MAP
  686.38 +END_MESSAGE_MAP()
  686.39 +
  686.40 +/////////////////////////////////////////////////////////////////////////////
  686.41 +// MemoryViewerAddressSize message handlers
  686.42 +
  686.43 +BOOL MemoryViewerAddressSize::OnInitDialog()
  686.44 +{
  686.45 +	CDialog::OnInitDialog();
  686.46 +
  686.47 +	CString buffer;
  686.48 +	if (address != 0xFFFFFFFF)
  686.49 +	{
  686.50 +		buffer.Format("%08X", address);
  686.51 +		m_address.SetWindowText(buffer);
  686.52 +	}
  686.53 +	if (size != -1)
  686.54 +	{
  686.55 +		buffer.Format("%08X", size);
  686.56 +		m_size.SetWindowText(buffer);
  686.57 +		m_size.EnableWindow(FALSE);
  686.58 +	}
  686.59 +
  686.60 +	if (size == -1 && address != 0xFFFFFFFF)
  686.61 +		m_size.SetFocus();
  686.62 +
  686.63 +	m_address.LimitText(9);
  686.64 +	m_size.LimitText(9);
  686.65 +
  686.66 +	return TRUE; // return TRUE unless you set the focus to a control
  686.67 +	             // EXCEPTION: OCX Property Pages should return FALSE
  686.68 +}
  686.69 +
  686.70 +void MemoryViewerAddressSize::OnOk()
  686.71 +{
  686.72 +	CString buffer;
  686.73 +
  686.74 +	m_address.GetWindowText(buffer);
  686.75 +	if (buffer.IsEmpty())
  686.76 +	{
  686.77 +		m_address.SetFocus();
  686.78 +		return;
  686.79 +	}
  686.80 +	sscanf(buffer, "%x", &address);
  686.81 +
  686.82 +	m_size.GetWindowText(buffer);
  686.83 +	if (buffer.IsEmpty())
  686.84 +	{
  686.85 +		m_size.SetFocus();
  686.86 +		return;
  686.87 +	}
  686.88 +	sscanf(buffer, "%x", &size);
  686.89 +	EndDialog(TRUE);
  686.90 +}
  686.91 +
  686.92 +void MemoryViewerAddressSize::OnCancel()
  686.93 +{
  686.94 +	EndDialog(FALSE);
  686.95 +}
  686.96 +
  686.97 +void MemoryViewerAddressSize::setAddress(u32 a)
  686.98 +{
  686.99 +	address = a;
 686.100 +}
 686.101 +
 686.102 +void MemoryViewerAddressSize::setSize(int s)
 686.103 +{
 686.104 +	size = s;
 686.105 +}
 686.106 +
 686.107 +u32 MemoryViewerAddressSize::getAddress()
 686.108 +{
 686.109 +	return address;
 686.110 +}
 686.111 +
 686.112 +\
 686.113 +
 686.114 +int MemoryViewerAddressSize::getSize()
 686.115 +{
 686.116 +	return size;
 686.117 +}
 686.118 +
   687.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   687.2 +++ b/src/win32/MemoryViewerAddressSize.h	Sat Mar 03 10:31:27 2012 -0600
   687.3 @@ -0,0 +1,54 @@
   687.4 +#if !defined(AFX_MEMORYVIEWERADDRESSSIZE_H__04605262_2B1D_4EED_A467_B6C56AC2CACD__INCLUDED_)
   687.5 +#define AFX_MEMORYVIEWERADDRESSSIZE_H__04605262_2B1D_4EED_A467_B6C56AC2CACD__INCLUDED_
   687.6 +
   687.7 +#if _MSC_VER > 1000
   687.8 +#pragma once
   687.9 +#endif // _MSC_VER > 1000
  687.10 +// -*- C++ -*-
  687.11 +// MemoryViewerAddressSize.h : header file
  687.12 +//
  687.13 +
  687.14 +/////////////////////////////////////////////////////////////////////////////
  687.15 +// MemoryViewerAddressSize dialog
  687.16 +
  687.17 +class MemoryViewerAddressSize : public CDialog
  687.18 +{
  687.19 +	u32 address;
  687.20 +	int size;
  687.21 +	// Construction
  687.22 +public:
  687.23 +	int getSize();
  687.24 +	u32 getAddress();
  687.25 +	void setSize(int s);
  687.26 +	void setAddress(u32 a);
  687.27 +	MemoryViewerAddressSize(u32 a = 0xffffff, int s = -1, CWnd*pParent = NULL); // standard constructor
  687.28 +
  687.29 +	// Dialog Data
  687.30 +	//{{AFX_DATA(MemoryViewerAddressSize)
  687.31 +	enum { IDD = IDD_ADDR_SIZE };
  687.32 +	CEdit m_size;
  687.33 +	CEdit m_address;
  687.34 +	//}}AFX_DATA
  687.35 +
  687.36 +	// Overrides
  687.37 +	// ClassWizard generated virtual function overrides
  687.38 +	//{{AFX_VIRTUAL(MemoryViewerAddressSize)
  687.39 +protected:
  687.40 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  687.41 +	//}}AFX_VIRTUAL
  687.42 +
  687.43 +	// Implementation
  687.44 +protected:
  687.45 +	// Generated message map functions
  687.46 +	//{{AFX_MSG(MemoryViewerAddressSize)
  687.47 +	virtual BOOL OnInitDialog();
  687.48 +	afx_msg void OnOk();
  687.49 +	afx_msg void OnCancel();
  687.50 +	//}}AFX_MSG
  687.51 +	DECLARE_MESSAGE_MAP()
  687.52 +};
  687.53 +
  687.54 +//{{AFX_INSERT_LOCATION}}
  687.55 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  687.56 +
  687.57 +#endif // !defined(AFX_MEMORYVIEWERADDRESSSIZE_H__04605262_2B1D_4EED_A467_B6C56AC2CACD__INCLUDED_)
   688.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   688.2 +++ b/src/win32/MemoryViewerDlg.cpp	Sat Mar 03 10:31:27 2012 -0600
   688.3 @@ -0,0 +1,449 @@
   688.4 +// MemoryViewerDlg.cpp : implementation file
   688.5 +//
   688.6 +
   688.7 +#include "stdafx.h"
   688.8 +#include "resource.h"
   688.9 +#include "MemoryViewerDlg.h"
  688.10 +#include "FileDlg.h"
  688.11 +#include "MemoryViewerAddressSize.h"
  688.12 +#include "Reg.h"
  688.13 +#include "WinResUtil.h"
  688.14 +#include "VBA.h"
  688.15 +
  688.16 +#include "../gba/GBAGlobals.h"
  688.17 +
  688.18 +#define CPUReadByteQuick(addr) \
  688.19 +    ::map[(addr)>>24].address[(addr) & ::map[(addr)>>24].mask]
  688.20 +#define CPUWriteByteQuick(addr, b) \
  688.21 +    ::map[(addr)>>24].address[(addr) & ::map[(addr)>>24].mask] = (b)
  688.22 +#define CPUReadHalfWordQuick(addr) \
  688.23 +    *((u16 *)&::map[(addr)>>24].address[(addr) & ::map[(addr)>>24].mask])
  688.24 +#define CPUWriteHalfWordQuick(addr, b) \
  688.25 +    *((u16 *)&::map[(addr)>>24].address[(addr) & ::map[(addr)>>24].mask]) = (b)
  688.26 +#define CPUReadMemoryQuick(addr) \
  688.27 +    *((u32 *)&::map[(addr)>>24].address[(addr) & ::map[(addr)>>24].mask])
  688.28 +#define CPUWriteMemoryQuick(addr, b) \
  688.29 +    *((u32 *)&::map[(addr)>>24].address[(addr) & ::map[(addr)>>24].mask]) = (b)
  688.30 +
  688.31 +/////////////////////////////////////////////////////////////////////////////
  688.32 +// GBAMemoryViewer control
  688.33 +
  688.34 +GBAMemoryViewer::GBAMemoryViewer()
  688.35 +	: MemoryViewer()
  688.36 +{
  688.37 +	setAddressSize(0);
  688.38 +}
  688.39 +
  688.40 +void GBAMemoryViewer::readData(u32 address, int len, u8 *data)
  688.41 +{
  688.42 +	if (emulating && rom != NULL)
  688.43 +	{
  688.44 +		for (int i = 0; i < len; i++)
  688.45 +		{
  688.46 +			*data++ = CPUReadByteQuick(address);
  688.47 +			address++;
  688.48 +		}
  688.49 +	}
  688.50 +	else
  688.51 +	{
  688.52 +		for (int i = 0; i < len; i++)
  688.53 +		{
  688.54 +			*data++ = 0;
  688.55 +			address++;
  688.56 +		}
  688.57 +	}
  688.58 +}
  688.59 +
  688.60 +void GBAMemoryViewer::editData(u32 address, int size, int mask, u32 value)
  688.61 +{
  688.62 +	u32 oldValue;
  688.63 +
  688.64 +	switch (size)
  688.65 +	{
  688.66 +	case 8:
  688.67 +		oldValue = (CPUReadByteQuick(address) & mask) | value;
  688.68 +		CPUWriteByteQuick(address, oldValue);
  688.69 +		break;
  688.70 +	case 16:
  688.71 +		oldValue = (CPUReadHalfWordQuick(address) & mask) | value;
  688.72 +		CPUWriteHalfWordQuick(address, oldValue);
  688.73 +		break;
  688.74 +	case 32:
  688.75 +		oldValue = (CPUReadMemoryQuick(address) & mask) | value;
  688.76 +		CPUWriteMemoryQuick(address, oldValue);
  688.77 +		break;
  688.78 +	}
  688.79 +}
  688.80 +
  688.81 +/////////////////////////////////////////////////////////////////////////////
  688.82 +// MemoryViewerDlg dialog
  688.83 +
  688.84 +MemoryViewerDlg::MemoryViewerDlg(CWnd*pParent /*=NULL*/)
  688.85 +	: ResizeDlg(MemoryViewerDlg::IDD, pParent)
  688.86 +{
  688.87 +	//{{AFX_DATA_INIT(MemoryViewerDlg)
  688.88 +	m_size = -1;
  688.89 +	//}}AFX_DATA_INIT
  688.90 +}
  688.91 +
  688.92 +void MemoryViewerDlg::DoDataExchange(CDataExchange*pDX)
  688.93 +{
  688.94 +	CDialog::DoDataExchange(pDX);
  688.95 +	//{{AFX_DATA_MAP(MemoryViewerDlg)
  688.96 +	DDX_Control(pDX, IDC_CURRENT_ADDRESS, m_current);
  688.97 +	DDX_Control(pDX, IDC_ADDRESS, m_address);
  688.98 +	DDX_Control(pDX, IDC_ADDRESSES, m_addresses);
  688.99 +	DDX_Check(pDX, IDC_AUTO_UPDATE, autoUpdate);
 688.100 +	DDX_Check(pDX, IDC_DECIMAL_DISPLAY, decimalDisplay);
 688.101 +	DDX_Check(pDX, IDC_ALIGN, align);
 688.102 +	DDX_Radio(pDX, IDC_8_BIT, m_size);
 688.103 +	//}}AFX_DATA_MAP
 688.104 +	DDX_Control(pDX, IDC_VIEWER, m_viewer);
 688.105 +}
 688.106 +
 688.107 +BEGIN_MESSAGE_MAP(MemoryViewerDlg, CDialog)
 688.108 +//{{AFX_MSG_MAP(MemoryViewerDlg)
 688.109 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
 688.110 +ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
 688.111 +ON_BN_CLICKED(IDC_8_BIT, On8Bit)
 688.112 +ON_BN_CLICKED(IDC_16_BIT, On16Bit)
 688.113 +ON_BN_CLICKED(IDC_32_BIT, On32Bit)
 688.114 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
 688.115 +ON_BN_CLICKED(IDC_DECIMAL_DISPLAY, OnDecimalDisplay)
 688.116 +ON_BN_CLICKED(IDC_ALIGN, OnAlign)
 688.117 +ON_BN_CLICKED(IDC_GO, OnGo)
 688.118 +ON_CBN_SELCHANGE(IDC_ADDRESSES, OnSelchangeAddresses)
 688.119 +ON_BN_CLICKED(IDC_SAVE, OnSave)
 688.120 +ON_BN_CLICKED(IDC_LOAD, OnLoad)
 688.121 +//}}AFX_MSG_MAP
 688.122 +END_MESSAGE_MAP()
 688.123 +
 688.124 +/////////////////////////////////////////////////////////////////////////////
 688.125 +// MemoryViewerDlg message handlers
 688.126 +
 688.127 +BOOL MemoryViewerDlg::OnInitDialog()
 688.128 +{
 688.129 +	CDialog::OnInitDialog();
 688.130 +
 688.131 +	DIALOG_SIZER_START(sz)
 688.132 +	DIALOG_SIZER_ENTRY(IDC_VIEWER, DS_SizeX | DS_SizeY)
 688.133 +	DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
 688.134 +	DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
 688.135 +	DIALOG_SIZER_ENTRY(IDC_LOAD, DS_MoveY)
 688.136 +	DIALOG_SIZER_ENTRY(IDC_SAVE, DS_MoveY)
 688.137 +	DIALOG_SIZER_ENTRY(IDC_AUTO_UPDATE, DS_MoveY)
 688.138 +	DIALOG_SIZER_ENTRY(IDC_DECIMAL_DISPLAY, DS_MoveY)
 688.139 +	DIALOG_SIZER_ENTRY(IDC_ALIGN, DS_MoveY)
 688.140 +	DIALOG_SIZER_ENTRY(IDC_CURRENT_ADDRESS_LABEL, DS_MoveY | DS_MoveX)
 688.141 +	DIALOG_SIZER_ENTRY(IDC_CURRENT_ADDRESS, DS_MoveY | DS_MoveX)
 688.142 +	DIALOG_SIZER_END()
 688.143 +	SetData(sz,
 688.144 +			TRUE,
 688.145 +			HKEY_CURRENT_USER,
 688.146 +			"Software\\Emulators\\VisualBoyAdvance\\Viewer\\GBDisassembleView",
 688.147 +			NULL);
 688.148 +
 688.149 +	autoUpdate = regQueryDwordValue("memViewerAutoUpdate", 1);
 688.150 +	if (autoUpdate)
 688.151 +	{
 688.152 +		theApp.winAddUpdateListener(this);
 688.153 +	}
 688.154 +	else
 688.155 +	{
 688.156 +		theApp.winRemoveUpdateListener(this);
 688.157 +	}
 688.158 +
 688.159 +	decimalDisplay = regQueryDwordValue("memViewerDecimalDisplay", 0);
 688.160 +	m_viewer.setDecimal(decimalDisplay ? true : false);
 688.161 +	align = regQueryDwordValue("memViewerAlign", 0);
 688.162 +
 688.163 +	m_viewer.setDialog(this);
 688.164 +	m_viewer.ShowScrollBar(SB_VERT, TRUE);
 688.165 +	m_viewer.EnableScrollBar(SB_VERT, ESB_ENABLE_BOTH);
 688.166 +
 688.167 +	LPCTSTR s[] = {
 688.168 +		"0x00000000 - BIOS",
 688.169 +		"0x02000000 - WRAM",
 688.170 +		"0x03000000 - IRAM",
 688.171 +		"0x04000000 - I/O",
 688.172 +		"0x05000000 - PALETTE",
 688.173 +		"0x06000000 - VRAM",
 688.174 +		"0x07000000 - OAM",
 688.175 +		"0x08000000 - ROM"
 688.176 +	};
 688.177 +
 688.178 +	for (int i = 0; i < 8; i++)
 688.179 +		m_addresses.AddString(s[i]);
 688.180 +
 688.181 +	m_addresses.SetCurSel(0);
 688.182 +
 688.183 +	RECT cbSize;
 688.184 +	int  Height;
 688.185 +
 688.186 +	m_addresses.GetClientRect(&cbSize);
 688.187 +	Height  = m_addresses.GetItemHeight(-1);
 688.188 +	Height += m_addresses.GetItemHeight(0) * (9);
 688.189 +
 688.190 +	// Note: The use of SM_CYEDGE assumes that we're using Windows '95
 688.191 +	// Now add on the height of the border of the edit box
 688.192 +	Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges
 688.193 +
 688.194 +	// The height of the border of the drop-down box
 688.195 +	Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges
 688.196 +
 688.197 +	// now set the size of the window
 688.198 +	m_addresses.SetWindowPos(NULL,
 688.199 +	                         0, 0,
 688.200 +	                         cbSize.right, Height,
 688.201 +	                         SWP_NOMOVE | SWP_NOZORDER);
 688.202 +
 688.203 +	m_address.LimitText(8);
 688.204 +
 688.205 +	m_size = regQueryDwordValue("memViewerDataSize", 1);
 688.206 +	if (m_size < 0 || m_size > 2)
 688.207 +		m_size = 0;
 688.208 +	m_viewer.setSize(m_size);
 688.209 +	UpdateData(FALSE);
 688.210 +
 688.211 +	m_current.SetFont(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)));
 688.212 +
 688.213 +	return TRUE; // return TRUE unless you set the focus to a control
 688.214 +	             // EXCEPTION: OCX Property Pages should return FALSE
 688.215 +}
 688.216 +
 688.217 +void MemoryViewerDlg::OnClose()
 688.218 +{
 688.219 +	theApp.winRemoveUpdateListener(this);
 688.220 +
 688.221 +	DestroyWindow();
 688.222 +}
 688.223 +
 688.224 +void MemoryViewerDlg::OnRefresh()
 688.225 +{
 688.226 +	m_viewer.Invalidate();
 688.227 +}
 688.228 +
 688.229 +void MemoryViewerDlg::update()
 688.230 +{
 688.231 +	OnRefresh();
 688.232 +}
 688.233 +
 688.234 +void MemoryViewerDlg::On8Bit()
 688.235 +{
 688.236 +	m_viewer.setSize(0);
 688.237 +	regSetDwordValue("memViewerDataSize", 0);
 688.238 +}
 688.239 +
 688.240 +void MemoryViewerDlg::On16Bit()
 688.241 +{
 688.242 +	m_viewer.setSize(1);
 688.243 +	regSetDwordValue("memViewerDataSize", 1);
 688.244 +}
 688.245 +
 688.246 +void MemoryViewerDlg::On32Bit()
 688.247 +{
 688.248 +	m_viewer.setSize(2);
 688.249 +	regSetDwordValue("memViewerDataSize", 2);
 688.250 +}
 688.251 +
 688.252 +void MemoryViewerDlg::OnAutoUpdate()
 688.253 +{
 688.254 +	autoUpdate = !autoUpdate;
 688.255 +	if (autoUpdate)
 688.256 +	{
 688.257 +		theApp.winAddUpdateListener(this);
 688.258 +	}
 688.259 +	else
 688.260 +	{
 688.261 +		theApp.winRemoveUpdateListener(this);
 688.262 +	}
 688.263 +	regSetDwordValue("memViewerAutoUpdate", autoUpdate);
 688.264 +}
 688.265 +
 688.266 +void MemoryViewerDlg::OnDecimalDisplay()
 688.267 +{
 688.268 +	decimalDisplay = !decimalDisplay;
 688.269 +	m_viewer.setDecimal(decimalDisplay ? true : false);
 688.270 +	regSetDwordValue("memViewerDecimalDisplay", decimalDisplay);
 688.271 +}
 688.272 +
 688.273 +void MemoryViewerDlg::OnAlign()
 688.274 +{
 688.275 +	align = !align;
 688.276 +	regSetDwordValue("memViewerAlign", align);
 688.277 +}
 688.278 +
 688.279 +void MemoryViewerDlg::OnGo()
 688.280 +{
 688.281 +	CString buffer;
 688.282 +
 688.283 +	m_address.GetWindowText(buffer);
 688.284 +
 688.285 +	u32 address;
 688.286 +	sscanf(buffer, "%x", &address);
 688.287 +	if (align)
 688.288 +		address &= ~0xF;
 688.289 +	else
 688.290 +	{
 688.291 +		if (m_viewer.getSize() == 1)
 688.292 +			address &= ~1;
 688.293 +		else if (m_viewer.getSize() == 2)
 688.294 +			address &= ~3;
 688.295 +	}
 688.296 +	m_viewer.setAddress(address);
 688.297 +}
 688.298 +
 688.299 +void MemoryViewerDlg::OnSelchangeAddresses()
 688.300 +{
 688.301 +	int cur = m_addresses.GetCurSel();
 688.302 +
 688.303 +	switch (cur)
 688.304 +	{
 688.305 +	case 0:
 688.306 +		m_viewer.setAddress(0);
 688.307 +		break;
 688.308 +	case 1:
 688.309 +		m_viewer.setAddress(0x2000000);
 688.310 +		break;
 688.311 +	case 2:
 688.312 +		m_viewer.setAddress(0x3000000);
 688.313 +		break;
 688.314 +	case 3:
 688.315 +		m_viewer.setAddress(0x4000000);
 688.316 +		break;
 688.317 +	case 4:
 688.318 +		m_viewer.setAddress(0x5000000);
 688.319 +		break;
 688.320 +	case 5:
 688.321 +		m_viewer.setAddress(0x6000000);
 688.322 +		break;
 688.323 +	case 6:
 688.324 +		m_viewer.setAddress(0x7000000);
 688.325 +		break;
 688.326 +	case 7:
 688.327 +		m_viewer.setAddress(0x8000000);
 688.328 +		break;
 688.329 +	}
 688.330 +}
 688.331 +
 688.332 +void MemoryViewerDlg::setCurrentAddress(u32 address)
 688.333 +{
 688.334 +	CString buffer;
 688.335 +
 688.336 +	buffer.Format("0x%08X", address);
 688.337 +	m_current.SetWindowText(buffer);
 688.338 +}
 688.339 +
 688.340 +void MemoryViewerDlg::OnSave()
 688.341 +{
 688.342 +	MemoryViewerAddressSize dlg;
 688.343 +	CString buffer;
 688.344 +
 688.345 +	dlg.setAddress(m_viewer.getCurrentAddress());
 688.346 +
 688.347 +	LPCTSTR exts[] = { ".dmp", NULL };
 688.348 +
 688.349 +	if (dlg.DoModal() == IDOK)
 688.350 +	{
 688.351 +		CString filter = winResLoadFilter(IDS_FILTER_DUMP);
 688.352 +		CString title  = winResLoadString(IDS_SELECT_DUMP_FILE);
 688.353 +
 688.354 +		FileDlg file(this,
 688.355 +		             buffer,
 688.356 +		             filter,
 688.357 +		             0,
 688.358 +		             "DMP",
 688.359 +		             exts,
 688.360 +		             "",
 688.361 +		             title,
 688.362 +		             true);
 688.363 +		if (file.DoModal() == IDOK)
 688.364 +		{
 688.365 +			buffer = file.GetPathName();
 688.366 +
 688.367 +			FILE *f = fopen(buffer, "wb");
 688.368 +
 688.369 +			if (f == NULL)
 688.370 +			{
 688.371 +				systemMessage(IDS_ERROR_CREATING_FILE, buffer);
 688.372 +				return;
 688.373 +			}
 688.374 +
 688.375 +			int size = dlg.getSize();
 688.376 +			u32 addr = dlg.getAddress();
 688.377 +
 688.378 +			for (int i = 0; i < size; i++)
 688.379 +			{
 688.380 +				fputc(CPUReadByteQuick(addr), f);
 688.381 +				addr++;
 688.382 +			}
 688.383 +
 688.384 +			fclose(f);
 688.385 +		}
 688.386 +	}
 688.387 +}
 688.388 +
 688.389 +void MemoryViewerDlg::OnLoad()
 688.390 +{
 688.391 +	CString buffer;
 688.392 +	LPCTSTR exts[] = { ".dmp", NULL };
 688.393 +
 688.394 +	CString filter = winResLoadFilter(IDS_FILTER_DUMP);
 688.395 +	CString title  = winResLoadString(IDS_SELECT_DUMP_FILE);
 688.396 +
 688.397 +	FileDlg file(this,
 688.398 +	             buffer,
 688.399 +	             filter,
 688.400 +	             0,
 688.401 +	             "DMP",
 688.402 +	             exts,
 688.403 +	             "",
 688.404 +	             title,
 688.405 +	             false);
 688.406 +
 688.407 +	if (file.DoModal() == IDOK)
 688.408 +	{
 688.409 +		buffer = file.GetPathName();
 688.410 +		FILE *f = fopen(buffer, "rb");
 688.411 +		if (f == NULL)
 688.412 +		{
 688.413 +			systemMessage(IDS_CANNOT_OPEN_FILE,
 688.414 +			              "Cannot open file %s",
 688.415 +			              buffer);
 688.416 +			return;
 688.417 +		}
 688.418 +
 688.419 +		MemoryViewerAddressSize dlg;
 688.420 +
 688.421 +		fseek(f, 0, SEEK_END);
 688.422 +		int size = ftell(f);
 688.423 +
 688.424 +		fseek(f, 0, SEEK_SET);
 688.425 +
 688.426 +		dlg.setAddress(m_viewer.getCurrentAddress());
 688.427 +		dlg.setSize(size);
 688.428 +
 688.429 +		if (dlg.DoModal() == IDOK)
 688.430 +		{
 688.431 +			int size = dlg.getSize();
 688.432 +			u32 addr = dlg.getAddress();
 688.433 +
 688.434 +			for (int i = 0; i < size; i++)
 688.435 +			{
 688.436 +				int c = fgetc(f);
 688.437 +				if (c == -1)
 688.438 +					break;
 688.439 +				CPUWriteByteQuick(addr, c);
 688.440 +				addr++;
 688.441 +			}
 688.442 +			OnRefresh();
 688.443 +		}
 688.444 +		fclose(f);
 688.445 +	}
 688.446 +}
 688.447 +
 688.448 +void MemoryViewerDlg::PostNcDestroy()
 688.449 +{
 688.450 +	delete this;
 688.451 +}
 688.452 +
   689.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   689.2 +++ b/src/win32/MemoryViewerDlg.h	Sat Mar 03 10:31:27 2012 -0600
   689.3 @@ -0,0 +1,79 @@
   689.4 +#if !defined(AFX_MEMORYVIEWERDLG_H__15046D5B_D5A2_4C49_A969_2A77F803F2F1__INCLUDED_)
   689.5 +#define AFX_MEMORYVIEWERDLG_H__15046D5B_D5A2_4C49_A969_2A77F803F2F1__INCLUDED_
   689.6 +
   689.7 +#if _MSC_VER > 1000
   689.8 +#pragma once
   689.9 +#endif // _MSC_VER > 1000
  689.10 +// -*- C++ -*-
  689.11 +// MemoryViewerDlg.h : header file
  689.12 +//
  689.13 +
  689.14 +#include "MemoryViewer.h"
  689.15 +#include "ResizeDlg.h"
  689.16 +#include "IUpdate.h"
  689.17 +
  689.18 +class GBAMemoryViewer : public MemoryViewer
  689.19 +{
  689.20 +public:
  689.21 +	GBAMemoryViewer();
  689.22 +	virtual void readData(u32, int, u8 *);
  689.23 +	virtual void editData(u32, int, int, u32);
  689.24 +};
  689.25 +
  689.26 +/////////////////////////////////////////////////////////////////////////////
  689.27 +// MemoryViewerDlg dialog
  689.28 +
  689.29 +class MemoryViewerDlg : public ResizeDlg, IUpdateListener, IMemoryViewerDlg
  689.30 +{
  689.31 +	GBAMemoryViewer m_viewer;
  689.32 +	// Construction
  689.33 +public:
  689.34 +	void setCurrentAddress(u32 address);
  689.35 +	int autoUpdate;
  689.36 +	int decimalDisplay;
  689.37 +	int align;
  689.38 +	void update();
  689.39 +	MemoryViewerDlg(CWnd*pParent = NULL);  // standard constructor
  689.40 +
  689.41 +	// Dialog Data
  689.42 +	//{{AFX_DATA(MemoryViewerDlg)
  689.43 +	enum { IDD = IDD_MEM_VIEWER };
  689.44 +	CEdit     m_current;
  689.45 +	CEdit     m_address;
  689.46 +	CComboBox m_addresses;
  689.47 +	int       m_size;
  689.48 +	//}}AFX_DATA
  689.49 +
  689.50 +	// Overrides
  689.51 +	// ClassWizard generated virtual function overrides
  689.52 +	//{{AFX_VIRTUAL(MemoryViewerDlg)
  689.53 +protected:
  689.54 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  689.55 +	virtual void PostNcDestroy();
  689.56 +	//}}AFX_VIRTUAL
  689.57 +
  689.58 +	// Implementation
  689.59 +protected:
  689.60 +	// Generated message map functions
  689.61 +	//{{AFX_MSG(MemoryViewerDlg)
  689.62 +	virtual BOOL OnInitDialog();
  689.63 +	afx_msg void OnClose();
  689.64 +	afx_msg void OnRefresh();
  689.65 +	afx_msg void On8Bit();
  689.66 +	afx_msg void On16Bit();
  689.67 +	afx_msg void On32Bit();
  689.68 +	afx_msg void OnAutoUpdate();
  689.69 +	afx_msg void OnDecimalDisplay();
  689.70 +	afx_msg void OnAlign();
  689.71 +	afx_msg void OnGo();
  689.72 +	afx_msg void OnSelchangeAddresses();
  689.73 +	afx_msg void OnSave();
  689.74 +	afx_msg void OnLoad();
  689.75 +	//}}AFX_MSG
  689.76 +	DECLARE_MESSAGE_MAP()
  689.77 +};
  689.78 +
  689.79 +//{{AFX_INSERT_LOCATION}}
  689.80 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  689.81 +
  689.82 +#endif // !defined(AFX_MEMORYVIEWERDLG_H__15046D5B_D5A2_4C49_A969_2A77F803F2F1__INCLUDED_)
   690.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   690.2 +++ b/src/win32/ModeConfirm.cpp	Sat Mar 03 10:31:27 2012 -0600
   690.3 @@ -0,0 +1,90 @@
   690.4 +// ModeConfirm.cpp : implementation file
   690.5 +//
   690.6 +
   690.7 +#include "stdafx.h"
   690.8 +#include "resource.h"
   690.9 +#include "ModeConfirm.h"
  690.10 +#include "VBA.h"
  690.11 +
  690.12 +/////////////////////////////////////////////////////////////////////////////
  690.13 +// ModeConfirm dialog
  690.14 +
  690.15 +
  690.16 +ModeConfirm::ModeConfirm(CWnd* pParent /*=NULL*/)
  690.17 +  : CDialog(ModeConfirm::IDD, pParent)
  690.18 +{
  690.19 +  //{{AFX_DATA_INIT(ModeConfirm)
  690.20 +  // NOTE: the ClassWizard will add member initialization here
  690.21 +  //}}AFX_DATA_INIT
  690.22 +}
  690.23 +
  690.24 +
  690.25 +void ModeConfirm::DoDataExchange(CDataExchange* pDX)
  690.26 +{
  690.27 +  CDialog::DoDataExchange(pDX);
  690.28 +  //{{AFX_DATA_MAP(ModeConfirm)
  690.29 +  // NOTE: the ClassWizard will add DDX and DDV calls here
  690.30 +  //}}AFX_DATA_MAP
  690.31 +}
  690.32 +
  690.33 +
  690.34 +BEGIN_MESSAGE_MAP(ModeConfirm, CDialog)
  690.35 +  //{{AFX_MSG_MAP(ModeConfirm)
  690.36 +  ON_BN_CLICKED(ID_CANCEL, OnCancel)
  690.37 +  ON_BN_CLICKED(ID_OK, OnOk)
  690.38 +  ON_WM_DESTROY()
  690.39 +  ON_WM_TIMER()
  690.40 +  //}}AFX_MSG_MAP
  690.41 +  END_MESSAGE_MAP()
  690.42 +
  690.43 +  /////////////////////////////////////////////////////////////////////////////
  690.44 +// ModeConfirm message handlers
  690.45 +
  690.46 +void ModeConfirm::OnCancel() 
  690.47 +{
  690.48 +  EndDialog(FALSE);
  690.49 +}
  690.50 +
  690.51 +void ModeConfirm::OnOk() 
  690.52 +{
  690.53 +  EndDialog(TRUE);
  690.54 +}
  690.55 +
  690.56 +void ModeConfirm::OnDestroy() 
  690.57 +{
  690.58 +  CDialog::OnDestroy();
  690.59 +  
  690.60 +  KillTimer(timer);
  690.61 +  timer = 0;
  690.62 +}
  690.63 +
  690.64 +BOOL ModeConfirm::OnInitDialog() 
  690.65 +{
  690.66 +  CDialog::OnInitDialog();
  690.67 +  
  690.68 +  timer = SetTimer(0, 1000, NULL);
  690.69 +
  690.70 +  count = 10;
  690.71 +
  690.72 +  CString buffer;
  690.73 +  buffer.Format("%d", count);
  690.74 +
  690.75 +  GetDlgItem(IDC_TIMER)->SetWindowText(buffer);
  690.76 +
  690.77 +  CenterWindow(theApp.m_pMainWnd);
  690.78 +  
  690.79 +  return TRUE;  // return TRUE unless you set the focus to a control
  690.80 +                // EXCEPTION: OCX Property Pages should return FALSE
  690.81 +}
  690.82 +
  690.83 +void ModeConfirm::OnTimer(UINT nIDEvent) 
  690.84 +{
  690.85 +  CString buffer;  
  690.86 +  count--;
  690.87 +  if(count == 0)
  690.88 +    EndDialog(FALSE);
  690.89 +  buffer.Format("%d", count);
  690.90 +  GetDlgItem(IDC_TIMER)->SetWindowText(buffer);
  690.91 +  
  690.92 +  CDialog::OnTimer(nIDEvent);
  690.93 +}
   691.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   691.2 +++ b/src/win32/ModeConfirm.h	Sat Mar 03 10:31:27 2012 -0600
   691.3 @@ -0,0 +1,51 @@
   691.4 +#if !defined(AFX_MODECONFIRM_H__AF9F877E_6EDF_4523_95C9_1C745ABBA796__INCLUDED_)
   691.5 +#define AFX_MODECONFIRM_H__AF9F877E_6EDF_4523_95C9_1C745ABBA796__INCLUDED_
   691.6 +
   691.7 +#if _MSC_VER > 1000
   691.8 +#pragma once
   691.9 +#endif // _MSC_VER > 1000
  691.10 +// -*- C++ -*-
  691.11 +// ModeConfirm.h : header file
  691.12 +//
  691.13 +
  691.14 +/////////////////////////////////////////////////////////////////////////////
  691.15 +// ModeConfirm dialog
  691.16 +
  691.17 +class ModeConfirm : public CDialog
  691.18 +{
  691.19 +	// Construction
  691.20 +public:
  691.21 +	int  count;
  691.22 +	UINT timer;
  691.23 +	ModeConfirm(CWnd*pParent);  // standard constructor
  691.24 +
  691.25 +	// Dialog Data
  691.26 +	//{{AFX_DATA(ModeConfirm)
  691.27 +	enum { IDD = IDD_MODE_CONFIRM };
  691.28 +	// NOTE: the ClassWizard will add data members here
  691.29 +	//}}AFX_DATA
  691.30 +
  691.31 +	// Overrides
  691.32 +	// ClassWizard generated virtual function overrides
  691.33 +	//{{AFX_VIRTUAL(ModeConfirm)
  691.34 +protected:
  691.35 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  691.36 +	//}}AFX_VIRTUAL
  691.37 +
  691.38 +	// Implementation
  691.39 +protected:
  691.40 +	// Generated message map functions
  691.41 +	//{{AFX_MSG(ModeConfirm)
  691.42 +	afx_msg void OnCancel();
  691.43 +	afx_msg void OnOk();
  691.44 +	afx_msg void OnDestroy();
  691.45 +	virtual BOOL OnInitDialog();
  691.46 +	afx_msg void OnTimer(UINT nIDEvent);
  691.47 +	//}}AFX_MSG
  691.48 +	DECLARE_MESSAGE_MAP()
  691.49 +};
  691.50 +
  691.51 +//{{AFX_INSERT_LOCATION}}
  691.52 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  691.53 +
  691.54 +#endif // !defined(AFX_MODECONFIRM_H__AF9F877E_6EDF_4523_95C9_1C745ABBA796__INCLUDED_)
   692.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   692.2 +++ b/src/win32/MovieCreate.cpp	Sat Mar 03 10:31:27 2012 -0600
   692.3 @@ -0,0 +1,389 @@
   692.4 +// MovieCreate.cpp : implementation file
   692.5 +//
   692.6 +
   692.7 +#include "stdafx.h"
   692.8 +#include "resource.h"
   692.9 +#include "MovieCreate.h"
  692.10 +#include "MainWnd.h"
  692.11 +#include "FileDlg.h"
  692.12 +#include "WinResUtil.h"
  692.13 +#include "WinMiscUtil.h"
  692.14 +#include "VBA.h"
  692.15 +
  692.16 +#include "../NLS.h"
  692.17 +#include "../common/Util.h"
  692.18 +#include "../common/movie.h"
  692.19 +#include "../gba/GBAGlobals.h"
  692.20 +#include "../gb/gbGlobals.h"
  692.21 +
  692.22 +extern u32 myROM[];
  692.23 +
  692.24 +#define GBC_CAPABLE ((gbRom[0x143] & 0x80) != 0)
  692.25 +#define SGB_CAPABLE (gbRom[0x146] == 0x03)
  692.26 +
  692.27 +// MovieCreate dialog
  692.28 +
  692.29 +IMPLEMENT_DYNAMIC(MovieCreate, CDialog)
  692.30 +MovieCreate::MovieCreate(CWnd *pParent /*=NULL*/)
  692.31 +	: CDialog(MovieCreate::IDD, pParent)
  692.32 +{
  692.33 +	//{{AFX_DATA_INIT(MovieCreate)
  692.34 +	m_startOption  = 2; // "from start" as default
  692.35 +	m_systemOption = systemCartridgeType == 0 ? 0 : (GBC_CAPABLE ? 1 : (SGB_CAPABLE ? 2 : 3)); // GBA, GBC, SGB, or GB
  692.36 +	m_biosOption   = systemCartridgeType == 0 ? (useBios ? 2 : 1) : 0; // none for non-GBA, or introless and based on settings
  692.37 +	//}}AFX_DATA_INIT
  692.38 +}
  692.39 +
  692.40 +MovieCreate::~MovieCreate()
  692.41 +{}
  692.42 +
  692.43 +BOOL MovieCreate::OnInitDialog()
  692.44 +{
  692.45 +	CDialog::OnInitDialog();
  692.46 +
  692.47 +	GetDlgItem(IDC_REC_GBA)->EnableWindow(systemCartridgeType == 0);
  692.48 +	GetDlgItem(IDC_REC_GBC)->EnableWindow(systemCartridgeType != 0 && GBC_CAPABLE);
  692.49 +	GetDlgItem(IDC_REC_SGB)->EnableWindow(systemCartridgeType != 0 && SGB_CAPABLE);
  692.50 +	GetDlgItem(IDC_REC_GB)->EnableWindow(systemCartridgeType != 0);
  692.51 +
  692.52 +	GetDlgItem(IDC_REC_NOBIOS)->EnableWindow(systemCartridgeType != 0);
  692.53 +	GetDlgItem(IDC_REC_EMUBIOS)->EnableWindow(systemCartridgeType == 0);
  692.54 +	GetDlgItem(IDC_REC_GBABIOS)->EnableWindow(systemCartridgeType == 0);
  692.55 +	GetDlgItem(IDC_REC_GBABIOSINTRO)->EnableWindow(systemCartridgeType == 0);
  692.56 +
  692.57 +	CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_NOBIOS + m_biosOption);
  692.58 +
  692.59 +	m_editFilename.LimitText(_MAX_PATH);
  692.60 +	m_editAuthor.LimitText(MOVIE_METADATA_AUTHOR_SIZE);
  692.61 +	m_editDescription.LimitText(MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
  692.62 +
  692.63 +	// convert the ROM filename into a default movie name
  692.64 +	CString movieName = winGetDestFilename(theApp.gameFilename, IDS_MOVIE_DIR, ".vbm");
  692.65 +
  692.66 +	GetDlgItem(IDC_MOVIE_FILENAME)->SetWindowText(movieName);
  692.67 +
  692.68 +	// scroll to show the rightmost side of the movie filename
  692.69 +	((CEdit *)GetDlgItem(IDC_MOVIE_FILENAME))->SetSel((DWORD)(movieName.GetLength() - 1), FALSE);
  692.70 +
  692.71 +	return TRUE; // return TRUE unless you set the focus to a control
  692.72 +	// EXCEPTION: OCX Property Pages should return FALSE
  692.73 +}
  692.74 +
  692.75 +void MovieCreate::DoDataExchange(CDataExchange *pDX)
  692.76 +{
  692.77 +	CDialog::DoDataExchange(pDX);
  692.78 +	//{{AFX_DATA_MAP(MovieCreate)
  692.79 +	DDX_Radio(pDX, IDC_RECNOW, m_startOption);
  692.80 +	DDX_Radio(pDX, IDC_REC_GBA, m_systemOption);
  692.81 +///	done manually DDX_Radio(pDX, IDC_REC_NOBIOS, m_biosOption);
  692.82 +	DDX_Control(pDX, IDC_EDIT_AUTHOR, m_editAuthor);
  692.83 +	DDX_Control(pDX, IDC_EDIT_DESCRIPTION, m_editDescription);
  692.84 +	DDX_Control(pDX, IDC_MOVIE_FILENAME, m_editFilename);
  692.85 +	//}}AFX_DATA_MAP
  692.86 +}
  692.87 +
  692.88 +BEGIN_MESSAGE_MAP(MovieCreate, CDialog)
  692.89 +ON_BN_CLICKED(IDOK, OnBnClickedOk)
  692.90 +ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
  692.91 +ON_BN_CLICKED(IDC_BROWSE, OnBnClickedBrowse)
  692.92 +ON_BN_CLICKED(IDC_RECSTART, OnBnClickedRecstart)
  692.93 +ON_BN_CLICKED(IDC_RECRESET, OnBnClickedRecreset)
  692.94 +ON_BN_CLICKED(IDC_RECNOW, OnBnClickedRecnow)
  692.95 +ON_BN_CLICKED(IDC_REC_GBA, OnBnClickedRecGba)
  692.96 +ON_BN_CLICKED(IDC_REC_GBC, OnBnClickedRecGbc)
  692.97 +ON_BN_CLICKED(IDC_REC_SGB, OnBnClickedRecSgb)
  692.98 +ON_BN_CLICKED(IDC_REC_GB, OnBnClickedRecGb)
  692.99 +ON_BN_CLICKED(IDC_REC_NOBIOS, OnBnClickedRecNobios)
 692.100 +ON_BN_CLICKED(IDC_REC_EMUBIOS, OnBnClickedRecEmubios)
 692.101 +ON_BN_CLICKED(IDC_REC_GBABIOS, OnBnClickedRecGbabios)
 692.102 +ON_BN_CLICKED(IDC_REC_GBABIOSINTRO, OnBnClickedRecGbabiosintro)
 692.103 +END_MESSAGE_MAP()
 692.104 +
 692.105 +// MovieCreate message handlers
 692.106 +
 692.107 +void MovieCreate::OnBnClickedBrowse()
 692.108 +{
 692.109 +	theApp.winCheckFullscreen();
 692.110 +
 692.111 +	LPCTSTR exts[] = { ".vbm", NULL };
 692.112 +
 692.113 +	CString filter = winResLoadFilter(IDS_FILTER_MOVIE);
 692.114 +	CString title  = winResLoadString(IDS_SELECT_MOVIE_NAME);
 692.115 +
 692.116 +	CString movieName = winGetDestFilename(theApp.gameFilename, IDS_MOVIE_DIR, exts[0]);
 692.117 +	CString movieDir  = winGetDestDir(IDS_MOVIE_DIR);
 692.118 +
 692.119 +	FileDlg dlg(this, movieName, filter, 1, "VBM", exts, movieDir, title, true);
 692.120 +
 692.121 +	if (dlg.DoModal() == IDCANCEL)
 692.122 +	{
 692.123 +		return;
 692.124 +	}
 692.125 +
 692.126 +	movieName = dlg.GetPathName();
 692.127 +
 692.128 +	GetDlgItem(IDC_MOVIE_FILENAME)->SetWindowText(movieName);
 692.129 +
 692.130 +	// scroll to show the rightmost side of the movie filename
 692.131 +	((CEdit *)GetDlgItem(IDC_MOVIE_FILENAME))->SetSel((DWORD)(movieName.GetLength() - 1), FALSE);
 692.132 +}
 692.133 +
 692.134 +void MovieCreate::OnBnClickedOk()
 692.135 +{
 692.136 +	// has to be done before creating the movie
 692.137 +	bool useBiosFile  = false;
 692.138 +	bool skipBiosFile = false;
 692.139 +
 692.140 +	if (m_biosOption == 1)
 692.141 +	{
 692.142 +		useBiosFile = false;
 692.143 +	}
 692.144 +	else if (m_biosOption == 2)
 692.145 +	{
 692.146 +		useBiosFile	 = true;
 692.147 +		skipBiosFile = true;
 692.148 +	}
 692.149 +	else if (m_biosOption == 3)
 692.150 +	{
 692.151 +		useBiosFile	 = true;
 692.152 +		skipBiosFile = false;
 692.153 +	}
 692.154 +
 692.155 +	extern bool systemLoadBIOS(const char *biosFileName, bool useBiosFile);
 692.156 +	if (!systemLoadBIOS(theApp.biosFileName, useBiosFile))
 692.157 +	{
 692.158 +		if (m_biosOption > 1)
 692.159 +		{
 692.160 +			systemMessage(0, "Invalid GBA BIOS file!");
 692.161 +			return;
 692.162 +		}
 692.163 +	}
 692.164 +
 692.165 +	theApp.useBiosFile = useBiosFile;
 692.166 +	if (useBiosFile)
 692.167 +		theApp.skipBiosFile = skipBiosFile;
 692.168 +
 692.169 +	int startFlags = 0, controllerFlags = 0, typeFlags = 0;
 692.170 +
 692.171 +	if (m_startOption == 0)
 692.172 +		startFlags |= MOVIE_START_FROM_SNAPSHOT;
 692.173 +	else if (m_startOption == 1)
 692.174 +		startFlags |= MOVIE_START_FROM_SRAM;
 692.175 +	//else
 692.176 +	//	startFlags = 0; // no SRAM or snapshot
 692.177 +
 692.178 +	if (m_systemOption == 0)
 692.179 +	{
 692.180 +		typeFlags	  |= MOVIE_TYPE_GBA;
 692.181 +		gbEmulatorType = 4;
 692.182 +	}
 692.183 +	else if (m_systemOption == 1)
 692.184 +	{
 692.185 +		typeFlags	  |= MOVIE_TYPE_GBC;
 692.186 +		gbEmulatorType = 1;
 692.187 +	}
 692.188 +	else if (m_systemOption == 2)
 692.189 +	{
 692.190 +		typeFlags	  |= MOVIE_TYPE_SGB;
 692.191 +		gbEmulatorType = 2;
 692.192 +	}
 692.193 +	else
 692.194 +	{
 692.195 +		gbEmulatorType = 3;  // plain old GB
 692.196 +	}
 692.197 +
 692.198 +	controllerFlags |= MOVIE_CONTROLLER(0);
 692.199 +	if (typeFlags & MOVIE_TYPE_SGB)
 692.200 +	{
 692.201 +		// XXX FIXME - the code for multiple controllers must be broken somehow
 692.202 +		// (it crashes strangely during FreezeToStream in SGB games)
 692.203 +
 692.204 +		// SGB games are free to request controllers while running, so we have to assume it needs all 4
 692.205 +///		controllerFlags |= MOVIE_CONTROLLER(1) | MOVIE_CONTROLLER(2) | MOVIE_CONTROLLER(3);
 692.206 +	}
 692.207 +
 692.208 +	// get author and movie info from the edit fields:
 692.209 +	char info [MOVIE_METADATA_SIZE], buffer [MOVIE_METADATA_SIZE];
 692.210 +
 692.211 +	GetDlgItem(IDC_EDIT_AUTHOR)->GetWindowText(buffer, MOVIE_METADATA_AUTHOR_SIZE);
 692.212 +	strncpy(info, buffer, MOVIE_METADATA_AUTHOR_SIZE);
 692.213 +	info[MOVIE_METADATA_AUTHOR_SIZE - 1] = '\0';
 692.214 +
 692.215 +	GetDlgItem(IDC_EDIT_DESCRIPTION)->GetWindowText(buffer, MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
 692.216 +	strncpy(info + MOVIE_METADATA_AUTHOR_SIZE, buffer, MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
 692.217 +	info[MOVIE_METADATA_SIZE - 1] = '\0';
 692.218 +
 692.219 +	if (memLagTempEnabled && systemCartridgeType == 0)
 692.220 +	{
 692.221 +		// lag reduction is off -- if the user didn't turn it off, silently turn it back on, otherwise ask
 692.222 +		int ans = !memLagEnabled ? IDYES : AfxGetApp()->m_pMainWnd->MessageBox(
 692.223 +		    "Lag reduction is currently OFF.\nIt is recommended that you turn this ON for recording.\nWould you like to turn it on now?",
 692.224 +		    "Warning",
 692.225 +		    MB_YESNOCANCEL | MB_ICONWARNING);
 692.226 +		switch (ans)
 692.227 +		{
 692.228 +		case IDYES:
 692.229 +			extern void SetPrefetchHack(bool);
 692.230 +			SetPrefetchHack(true);
 692.231 +			break;
 692.232 +		case IDNO:
 692.233 +			break;
 692.234 +		case IDCANCEL:
 692.235 +			return;
 692.236 +		}
 692.237 +	}
 692.238 +
 692.239 +	CString movieName;
 692.240 +	GetDlgItem(IDC_MOVIE_FILENAME)->GetWindowText(movieName);
 692.241 +
 692.242 +	// actually make the movie file:
 692.243 +	int code = VBAMovieCreate(movieName, info, startFlags, controllerFlags, typeFlags);
 692.244 +
 692.245 +	if (code != MOVIE_SUCCESS)
 692.246 +	{
 692.247 +		systemMessage(0, "Failed to create movie %s", (const char *)movieName);
 692.248 +		return;
 692.249 +	}
 692.250 +
 692.251 +	OnOK();
 692.252 +}
 692.253 +
 692.254 +void MovieCreate::OnBnClickedCancel()
 692.255 +{
 692.256 +	OnCancel();
 692.257 +}
 692.258 +
 692.259 +void MovieCreate::OnBnClickedRecstart()
 692.260 +{
 692.261 +	m_startOption = 2;
 692.262 +	if (systemCartridgeType == 0)
 692.263 +	{
 692.264 +		GetDlgItem(IDC_REC_EMUBIOS)->EnableWindow(TRUE);
 692.265 +		GetDlgItem(IDC_REC_GBABIOSINTRO)->EnableWindow(TRUE);
 692.266 +	}
 692.267 +	else
 692.268 +	{
 692.269 +		GetDlgItem(IDC_REC_GBC)->EnableWindow(GBC_CAPABLE);
 692.270 +		GetDlgItem(IDC_REC_SGB)->EnableWindow(SGB_CAPABLE);
 692.271 +		GetDlgItem(IDC_REC_GB)->EnableWindow(TRUE);
 692.272 +	}
 692.273 +}
 692.274 +
 692.275 +void MovieCreate::OnBnClickedRecreset()
 692.276 +{
 692.277 +	m_startOption = 1;
 692.278 +	if (systemCartridgeType == 0)
 692.279 +	{
 692.280 +		GetDlgItem(IDC_REC_EMUBIOS)->EnableWindow(TRUE);
 692.281 +		GetDlgItem(IDC_REC_GBABIOSINTRO)->EnableWindow(TRUE);
 692.282 +	}
 692.283 +	else
 692.284 +	{
 692.285 +		GetDlgItem(IDC_REC_GBC)->EnableWindow(GBC_CAPABLE);
 692.286 +		GetDlgItem(IDC_REC_SGB)->EnableWindow(SGB_CAPABLE);
 692.287 +		GetDlgItem(IDC_REC_GB)->EnableWindow(TRUE);
 692.288 +	}
 692.289 +}
 692.290 +
 692.291 +void MovieCreate::OnBnClickedRecnow()
 692.292 +{
 692.293 +	m_startOption = 0;
 692.294 +
 692.295 +	// starting from emulator bios file from a snapshot made while playing with GBA bios file won't work
 692.296 +	if (systemCartridgeType == 0 && useBios)
 692.297 +	{
 692.298 +		if (m_biosOption == 1)
 692.299 +		{
 692.300 +			OnBnClickedRecGbabios();
 692.301 +			CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_NOBIOS + m_biosOption);
 692.302 +		}
 692.303 +		GetDlgItem(IDC_REC_EMUBIOS)->EnableWindow(FALSE);
 692.304 +	}
 692.305 +
 692.306 +	// "with intro" distinction makes no sense when continuing from snapshot
 692.307 +	if (systemCartridgeType == 0)
 692.308 +	{
 692.309 +		if (m_biosOption == 3)
 692.310 +		{
 692.311 +			OnBnClickedRecGbabios();
 692.312 +			CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_NOBIOS + m_biosOption);
 692.313 +		}
 692.314 +		GetDlgItem(IDC_REC_GBABIOSINTRO)->EnableWindow(FALSE);
 692.315 +	}
 692.316 +
 692.317 +	// can't switch systems while recording from snapshot!
 692.318 +	if (systemCartridgeType != 0)
 692.319 +	{
 692.320 +		int curSystemOption = (gbCgbMode == 1 ? 1 : (gbSgbMode == 1 ? 2 : 3)); // GBC, SGB, or GB
 692.321 +		GetDlgItem(IDC_REC_GBC)->EnableWindow(curSystemOption == 1);
 692.322 +		GetDlgItem(IDC_REC_SGB)->EnableWindow(curSystemOption == 2);
 692.323 +		GetDlgItem(IDC_REC_GB)->EnableWindow(curSystemOption == 3);
 692.324 +		m_systemOption = curSystemOption;
 692.325 +		CheckRadioButton(IDC_REC_GBA, IDC_REC_GB, IDC_REC_GBA + m_systemOption);
 692.326 +	}
 692.327 +}
 692.328 +
 692.329 +void MovieCreate::OnBnClickedRecGba()
 692.330 +{
 692.331 +	m_systemOption = 0;
 692.332 +}
 692.333 +
 692.334 +void MovieCreate::OnBnClickedRecGbc()
 692.335 +{
 692.336 +	m_systemOption = 1;
 692.337 +}
 692.338 +
 692.339 +void MovieCreate::OnBnClickedRecSgb()
 692.340 +{
 692.341 +	m_systemOption = 2;
 692.342 +}
 692.343 +
 692.344 +void MovieCreate::OnBnClickedRecGb()
 692.345 +{
 692.346 +	m_systemOption = 3;
 692.347 +}
 692.348 +
 692.349 +void MovieCreate::OnBnClickedRecNobios()
 692.350 +{
 692.351 +	m_biosOption = 0;
 692.352 +}
 692.353 +
 692.354 +void MovieCreate::OnBnClickedRecEmubios()
 692.355 +{
 692.356 +	m_biosOption = 1;
 692.357 +}
 692.358 +
 692.359 +void MovieCreate::OnBnClickedRecGbabios()
 692.360 +{
 692.361 +	if (utilCheckBIOS(theApp.biosFileName, 4))
 692.362 +		m_biosOption = 2;
 692.363 +	else
 692.364 +	{
 692.365 +		((MainWnd *)theApp.m_pMainWnd)->OnOptionsEmulatorSelectbiosfile();
 692.366 +		if (utilCheckBIOS(theApp.biosFileName, 4))
 692.367 +			m_biosOption = 2;
 692.368 +		else
 692.369 +		{
 692.370 +			systemMessage(0, "This option requires a valid GBA BIOS file.");
 692.371 +			CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_EMUBIOS);
 692.372 +		}
 692.373 +	}
 692.374 +}
 692.375 +
 692.376 +void MovieCreate::OnBnClickedRecGbabiosintro()
 692.377 +{
 692.378 +	if (utilCheckBIOS(theApp.biosFileName, 4))
 692.379 +		m_biosOption = 3;
 692.380 +	else
 692.381 +	{
 692.382 +		((MainWnd *)theApp.m_pMainWnd)->OnOptionsEmulatorSelectbiosfile();
 692.383 +		if (utilCheckBIOS(theApp.biosFileName, 4))
 692.384 +			m_biosOption = 3;
 692.385 +		else
 692.386 +		{
 692.387 +			systemMessage(0, "This option requires a valid GBA BIOS file.");
 692.388 +			CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_EMUBIOS);
 692.389 +		}
 692.390 +	}
 692.391 +}
 692.392 +
   693.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   693.2 +++ b/src/win32/MovieCreate.h	Sat Mar 03 10:31:27 2012 -0600
   693.3 @@ -0,0 +1,50 @@
   693.4 +#ifndef VBA_MOVIECREATE_H
   693.5 +#define VBA_MOVIECREATE_H
   693.6 +
   693.7 +#if _MSC_VER > 1000
   693.8 +#pragma once
   693.9 +#endif // _MSC_VER > 1000
  693.10 +
  693.11 +// MovieCreate dialog
  693.12 +class MovieCreate : public CDialog
  693.13 +{
  693.14 +	DECLARE_DYNAMIC(MovieCreate)
  693.15 +
  693.16 +public:
  693.17 +	MovieCreate(CWnd* pParent = NULL);   // standard constructor
  693.18 +	virtual ~MovieCreate();
  693.19 +	virtual BOOL OnInitDialog() ;
  693.20 +
  693.21 +// Dialog Data
  693.22 +  //{{AFX_DATA(MovieCreate)
  693.23 +	enum { IDD = IDD_MOVIECREATE };
  693.24 +    int    m_startOption;
  693.25 +    int    m_systemOption;
  693.26 +    int    m_biosOption;
  693.27 +    CEdit  m_editAuthor;
  693.28 +    CEdit  m_editDescription;
  693.29 +    CEdit  m_editFilename;
  693.30 +	//}}AFX_DATA
  693.31 +
  693.32 +protected:
  693.33 +	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  693.34 +
  693.35 +	DECLARE_MESSAGE_MAP()
  693.36 +public:
  693.37 +	afx_msg void OnBnClickedOk();
  693.38 +	afx_msg void OnBnClickedCancel();
  693.39 +	afx_msg void OnBnClickedBrowse();
  693.40 +	afx_msg void OnBnClickedRecstart();
  693.41 +	afx_msg void OnBnClickedRecreset();
  693.42 +	afx_msg void OnBnClickedRecnow();
  693.43 +	afx_msg void OnBnClickedRecGba();
  693.44 +	afx_msg void OnBnClickedRecGbc();
  693.45 +	afx_msg void OnBnClickedRecSgb();
  693.46 +	afx_msg void OnBnClickedRecGb();
  693.47 +	afx_msg void OnBnClickedRecNobios();
  693.48 +	afx_msg void OnBnClickedRecEmubios();
  693.49 +	afx_msg void OnBnClickedRecGbabios();
  693.50 +	afx_msg void OnBnClickedRecGbabiosintro();
  693.51 +};
  693.52 +
  693.53 +#endif // VBA_MOVIECREATE_H
   694.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   694.2 +++ b/src/win32/MovieOpen.cpp	Sat Mar 03 10:31:27 2012 -0600
   694.3 @@ -0,0 +1,532 @@
   694.4 +// MovieOpen.cpp : implementation file
   694.5 +//
   694.6 +
   694.7 +#include "stdafx.h"
   694.8 +#include "resource.h"
   694.9 +#include "MovieOpen.h"
  694.10 +#include "MainWnd.h"
  694.11 +#include "FileDlg.h"
  694.12 +#include "WinResUtil.h"
  694.13 +#include "WinMiscUtil.h"
  694.14 +#include "VBA.h"
  694.15 +
  694.16 +#include "../gba/GBA.h"
  694.17 +#include "../gb/gbGlobals.h"
  694.18 +#include "../common/Util.h"
  694.19 +#include "7zip/OpenArchive.h"
  694.20 +
  694.21 +// MovieOpen dialog
  694.22 +
  694.23 +IMPLEMENT_DYNAMIC(MovieOpen, CDialog)
  694.24 +MovieOpen::MovieOpen(CWnd *pParent /*=NULL*/)
  694.25 +	: CDialog(MovieOpen::IDD, pParent)
  694.26 +{}
  694.27 +
  694.28 +MovieOpen::~MovieOpen()
  694.29 +{
  694.30 +	SetArchiveParentHWND(NULL);
  694.31 +}
  694.32 +
  694.33 +BOOL MovieOpen::OnInitDialog()
  694.34 +{
  694.35 +	CDialog::OnInitDialog();
  694.36 +
  694.37 +	pauseFrame = 0;
  694.38 +	ZeroMemory(&movieInfo, sizeof SMovie);
  694.39 +
  694.40 +	SetArchiveParentHWND(GetSafeHwnd());
  694.41 +
  694.42 +	GetDlgItem(IDC_CHECK_HIDEBORDER)->ShowWindow(FALSE);
  694.43 +	GetDlgItem(IDC_LABEL_WARNING1)->SetWindowText("");
  694.44 +	GetDlgItem(IDC_LABEL_WARNING2)->SetWindowText("");
  694.45 +	GetDlgItem(IDC_EDIT_PAUSEFRAME)->SetWindowText("");
  694.46 +	GetDlgItem(IDC_EDIT_PAUSEFRAME)->EnableWindow(FALSE);
  694.47 +	GetDlgItem(IDC_CHECK_PAUSEFRAME)->EnableWindow(FALSE);
  694.48 +
  694.49 +	CheckDlgButton(IDC_READONLY, TRUE);
  694.50 +	m_editDescription.SetReadOnly(theApp.movieReadOnly);
  694.51 +
  694.52 +	m_editFilename.LimitText(_MAX_PATH);
  694.53 +	m_editAuthor.LimitText(MOVIE_METADATA_AUTHOR_SIZE);
  694.54 +	m_editDescription.LimitText(MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
  694.55 +	m_editPauseFrame.LimitText(8);
  694.56 +
  694.57 +	// convert the ROM filename into a default movie name
  694.58 +	CString movieName = winGetDestFilename(theApp.gameFilename, IDS_MOVIE_DIR, ".vbm");
  694.59 +
  694.60 +	GetDlgItem(IDC_MOVIE_FILENAME)->SetWindowText(movieName);
  694.61 +
  694.62 +	// scroll to show the rightmost side of the movie filename
  694.63 +	((CEdit *)GetDlgItem(IDC_MOVIE_FILENAME))->SetSel((DWORD)(movieName.GetLength() - 1), FALSE);
  694.64 +
  694.65 +	OnBnClickedMovieRefresh();
  694.66 +
  694.67 +	return TRUE; // return TRUE unless you set the focus to a control
  694.68 +	// EXCEPTION: OCX Property Pages should return FALSE
  694.69 +}
  694.70 +
  694.71 +void MovieOpen::DoDataExchange(CDataExchange *pDX)
  694.72 +{
  694.73 +	CDialog::DoDataExchange(pDX);
  694.74 +	//{{AFX_DATA_MAP(MovieCreate)
  694.75 +	DDX_Control(pDX, IDC_EDIT_AUTHOR, m_editAuthor);
  694.76 +	DDX_Control(pDX, IDC_EDIT_DESCRIPTION, m_editDescription);
  694.77 +	DDX_Control(pDX, IDC_MOVIE_FILENAME, m_editFilename);
  694.78 +	DDX_Control(pDX, IDC_EDIT_PAUSEFRAME, m_editPauseFrame);
  694.79 +	//}}AFX_DATA_MAP
  694.80 +}
  694.81 +
  694.82 +BEGIN_MESSAGE_MAP(MovieOpen, CDialog)
  694.83 +ON_BN_CLICKED(IDC_BROWSE, OnBnClickedBrowse)
  694.84 +ON_BN_CLICKED(IDOK, OnBnClickedOk)
  694.85 +ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
  694.86 +ON_BN_CLICKED(IDC_MOVIE_REFRESH, OnBnClickedMovieRefresh)
  694.87 +ON_BN_CLICKED(IDC_READONLY, OnBnClickedReadonly)
  694.88 +ON_BN_CLICKED(IDC_CHECK_PAUSEFRAME, OnBnClickedCheckPauseframe)
  694.89 +ON_BN_CLICKED(IDC_CHECK_HIDEBORDER, OnBnClickedHideborder)
  694.90 +ON_EN_CHANGE(IDC_MOVIE_FILENAME, OnEnChangeMovieFilename)
  694.91 +END_MESSAGE_MAP()
  694.92 +
  694.93 +// MovieOpen message handlers
  694.94 +
  694.95 +// FIXME: file-scope-global
  694.96 +static bool shouldReopenBrowse = false;
  694.97 +
  694.98 +void MovieOpen::OnBnClickedBrowse()
  694.99 +{
 694.100 +	theApp.winCheckFullscreen();    // FIXME: necessary or not?
 694.101 +
 694.102 +	LPCTSTR exts[] = { ".vbm", NULL };
 694.103 +
 694.104 +	CString filter = winResLoadFilter(IDS_FILTER_MOVIE);
 694.105 +	CString title  = winResLoadString(IDS_SELECT_MOVIE_NAME);
 694.106 +
 694.107 +	CString movieName = winGetDestFilename(theApp.gameFilename, IDS_MOVIE_DIR, exts[0]);
 694.108 +	CString movieDir  = winGetDestDir(IDS_MOVIE_DIR);
 694.109 +
 694.110 +	FileDlg dlg(this, movieName, filter, 1, "VBM", exts, movieDir, title, false, true);
 694.111 +
 694.112 +	do
 694.113 +	{
 694.114 +		shouldReopenBrowse = false;
 694.115 +
 694.116 +		if (dlg.DoModal() == IDCANCEL)
 694.117 +		{
 694.118 +			return;
 694.119 +		}
 694.120 +
 694.121 +		movieName = dlg.GetPathName();
 694.122 +
 694.123 +		GetDlgItem(IDC_MOVIE_FILENAME)->SetWindowText(movieName);
 694.124 +
 694.125 +		// SetWindowText calls OnEnChangeMovieFilename which calls OnBnClickedMovieRefresh
 694.126 +		// so this extra call to OnBnClickedMovieRefresh is bad
 694.127 +		//OnBnClickedMovieRefresh();
 694.128 +	}
 694.129 +	while (shouldReopenBrowse);
 694.130 +
 694.131 +	// scroll to show the rightmost side of the movie filename
 694.132 +	((CEdit *)GetDlgItem(IDC_MOVIE_FILENAME))->SetSel((DWORD)(movieName.GetLength() - 1), FALSE);
 694.133 +}
 694.134 +
 694.135 +// some extensions that might commonly be near emulation-related files that we almost certainly can't open, or at least not
 694.136 +// directly.
 694.137 +// also includes definitely non-movie extensions we know about, since we only use this variable in a movie opening function.
 694.138 +// we do this by exclusion instead of inclusion because we don't want to exclude extensions used for any archive files, even
 694.139 +// extensionless or unusually-named archives.
 694.140 +static const char *s_movieIgnoreExtensions [] = {
 694.141 +	"gba", "gbc", "gb",	 "sgb",	 "cgb",	 "bin", "agb", "bios", "mb",   "elf",	"sgm",	"clt",	 "dat",	 "gbs",	 "gcf", "spc",
 694.142 +	"xpc", "pal", "act", "dmp",	 "avi",	 "ini", "txt", "nfo",  "htm",  "html",	"jpg",	"jpeg",	 "png",	 "bmp",	 "gif", "mp3",
 694.143 +	"wav", "lnk", "exe", "bat",	 "sav",	 "luasav"
 694.144 +};
 694.145 +
 694.146 +void MovieOpen::OnBnClickedMovieRefresh()
 694.147 +{
 694.148 +	static int recursionDepth = 0;
 694.149 +	if (recursionDepth > 0)
 694.150 +		return;
 694.151 +	struct Scope {Scope(){ ++ recursionDepth; } ~Scope(){ --recursionDepth; }} scope;
 694.152 +
 694.153 +	CString tempName;
 694.154 +	GetDlgItem(IDC_MOVIE_FILENAME)->GetWindowText(tempName);
 694.155 +
 694.156 +#if 1
 694.157 +	// use ObtainFile to support opening files within archives (.7z, .rar, .zip, .zip.rar.7z, etc.)
 694.158 +
 694.159 +	if (movieLogicalName.GetLength() > 2048) movieLogicalName.Truncate(2048);
 694.160 +
 694.161 +	char LogicalName[2048], PhysicalName[2048];
 694.162 +	if (ObtainFile(tempName, LogicalName, PhysicalName, "mov", s_movieIgnoreExtensions,
 694.163 +	               sizeof(s_movieIgnoreExtensions) / sizeof(*s_movieIgnoreExtensions)))
 694.164 +	{
 694.165 +		if (tempName != LogicalName)
 694.166 +		{
 694.167 +			int selStart = 0, selEnd = 0;
 694.168 +			((CEdit *)GetDlgItem(IDC_MOVIE_FILENAME))->GetSel(selStart, selEnd);
 694.169 +
 694.170 +			GetDlgItem(IDC_MOVIE_FILENAME)->SetWindowText(LogicalName);
 694.171 +
 694.172 +			((CEdit *)GetDlgItem(IDC_MOVIE_FILENAME))->SetSel(selStart, selEnd, FALSE);
 694.173 +		}
 694.174 +		moviePhysicalName = PhysicalName;
 694.175 +		movieLogicalName  = LogicalName;
 694.176 +		ReleaseTempFileCategory("mov", PhysicalName);
 694.177 +	}
 694.178 +	else
 694.179 +	{
 694.180 +		shouldReopenBrowse = true;
 694.181 +		return;
 694.182 +	}
 694.183 +#else
 694.184 +	// old version that only supports uncompressed movies
 694.185 +	moviePhysicalName = tempName;
 694.186 +	movieLogicalName  = tempName;
 694.187 +#endif
 694.188 +
 694.189 +	if (VBAMovieGetInfo(moviePhysicalName, &movieInfo) == MOVIE_SUCCESS)
 694.190 +	{
 694.191 +		if (movieInfo.readOnly)
 694.192 +		{
 694.193 +			CheckDlgButton(IDC_READONLY, TRUE);
 694.194 +			m_editDescription.SetReadOnly(TRUE);
 694.195 +		}
 694.196 +
 694.197 +		char buffer[MOVIE_METADATA_SIZE];
 694.198 +
 694.199 +		strncpy(buffer, movieInfo.authorInfo, MOVIE_METADATA_AUTHOR_SIZE);
 694.200 +		buffer[MOVIE_METADATA_AUTHOR_SIZE - 1] = '\0';
 694.201 +		GetDlgItem(IDC_EDIT_AUTHOR)->SetWindowText(buffer);
 694.202 +
 694.203 +		strncpy(buffer, movieInfo.authorInfo + MOVIE_METADATA_AUTHOR_SIZE, MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
 694.204 +		buffer[MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE - 1] = '\0';
 694.205 +		GetDlgItem(IDC_EDIT_DESCRIPTION)->SetWindowText(buffer);
 694.206 +
 694.207 +		int option = 2;
 694.208 +		if (movieInfo.header.startFlags & MOVIE_START_FROM_SRAM)
 694.209 +			option = 1;
 694.210 +		if (movieInfo.header.startFlags & MOVIE_START_FROM_SNAPSHOT)
 694.211 +			option = 0;
 694.212 +		CheckRadioButton(IDC_RECNOW, IDC_RECSTART, IDC_RECNOW + option);
 694.213 +
 694.214 +		option = 3;
 694.215 +		if (movieInfo.header.typeFlags & MOVIE_TYPE_SGB)
 694.216 +			option = 2;
 694.217 +		if (movieInfo.header.typeFlags & MOVIE_TYPE_GBC)
 694.218 +			option = 1;
 694.219 +		if (movieInfo.header.typeFlags & MOVIE_TYPE_GBA)
 694.220 +			option = 0;
 694.221 +		CheckRadioButton(IDC_REC_GBA, IDC_REC_GB, IDC_REC_GBA + option);
 694.222 +
 694.223 +		GetDlgItem(IDC_CHECK_HIDEBORDER)->ShowWindow(option == 2 ? TRUE : FALSE);
 694.224 +
 694.225 +		if (movieInfo.header.typeFlags & MOVIE_TYPE_GBA)
 694.226 +		{
 694.227 +			if (movieInfo.header.optionFlags & MOVIE_SETTING_USEBIOSFILE)
 694.228 +			{
 694.229 +				if (movieInfo.header.optionFlags & MOVIE_SETTING_SKIPBIOSFILE)
 694.230 +					option = 2;
 694.231 +				else
 694.232 +					option = 3;
 694.233 +			}
 694.234 +			else
 694.235 +				option = 1;
 694.236 +		}
 694.237 +		else
 694.238 +			option = 0;
 694.239 +
 694.240 +		CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_NOBIOS + option);
 694.241 +
 694.242 +		{
 694.243 +			char * p;
 694.244 +			time_t ttime = (time_t)movieInfo.header.uid;
 694.245 +			strncpy(buffer, ctime(&ttime), 127);
 694.246 +			buffer[127] = '\0';
 694.247 +			if ((p = strrchr(buffer, '\n')))
 694.248 +				*p = '\0';
 694.249 +			GetDlgItem(IDC_LABEL_DATE)->SetWindowText(buffer);
 694.250 +
 694.251 +			uint32 div	   = 60;
 694.252 +			uint32 l	   = (movieInfo.header.length_frames + (div >> 1)) / div;
 694.253 +			uint32 seconds = l % 60;
 694.254 +			l /= 60;
 694.255 +			uint32 minutes = l % 60;
 694.256 +			l /= 60;
 694.257 +			uint32 hours = l % 60;
 694.258 +			sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
 694.259 +			GetDlgItem(IDC_LABEL_LENGTH)->SetWindowText(buffer);
 694.260 +			sprintf(buffer, "%ld", movieInfo.header.length_frames);
 694.261 +			GetDlgItem(IDC_LABEL_FRAMES)->SetWindowText(buffer);
 694.262 +			sprintf(buffer, "%ld", movieInfo.header.rerecord_count);
 694.263 +			GetDlgItem(IDC_LABEL_RERECORD)->SetWindowText(buffer);
 694.264 +		}
 694.265 +
 694.266 +		{
 694.267 +			char warning1 [1024], warning2 [1024], buffer [1024];
 694.268 +
 694.269 +			strcpy(warning1, "");
 694.270 +			strcpy(warning2, "");
 694.271 +
 694.272 +			char   romTitle [12];
 694.273 +			uint32 romGameCode;
 694.274 +			uint16 checksum;
 694.275 +			uint8  crc;
 694.276 +
 694.277 +			VBAMovieGetRomInfo(movieInfo, romTitle, romGameCode, checksum, crc);
 694.278 +
 694.279 +			// rather than treat these as warnings, might as well always show the info in the dialog (it's probably more
 694.280 +			// informative and reassuring)
 694.281 +///			if (strncmp(movieInfo.header.romTitle,romTitle,12) != 0)
 694.282 +			{
 694.283 +				char str [13];
 694.284 +				strncpy(str, movieInfo.header.romTitle, 12);
 694.285 +				str[12] = '\0';
 694.286 +				sprintf(buffer, "title=%s  ", str);
 694.287 +				strcat(warning1, buffer);
 694.288 +
 694.289 +				strncpy(str, romTitle, 12);
 694.290 +				str[12] = '\0';
 694.291 +				sprintf(buffer, "title=%s  ", str);
 694.292 +				strcat(warning2, buffer);
 694.293 +			}
 694.294 +///			if (((movieInfo.header.typeFlags & MOVIE_TYPE_GBA)!=0) != (systemCartridgeType == 0))
 694.295 +			{
 694.296 +				sprintf(buffer, "type=%s  ",
 694.297 +				        (movieInfo.header.typeFlags & MOVIE_TYPE_GBA) ? "GBA" : (movieInfo.header.typeFlags &
 694.298 +				                                                                 MOVIE_TYPE_GBC) ? "GBC" : (movieInfo.header.
 694.299 +				                                                                                            typeFlags &
 694.300 +				                                                                                            MOVIE_TYPE_SGB) ? "SGB" : "GB");
 694.301 +				strcat(warning1, buffer);
 694.302 +
 694.303 +				sprintf(buffer, "type=%s  ", systemCartridgeType ==
 694.304 +				        0 ? "GBA" : (gbRom[0x143] & 0x80 ? "GBC" : (gbRom[0x146] == 0x03 ? "SGB" : "GB")));
 694.305 +				strcat(warning2, buffer);
 694.306 +			}
 694.307 +///			if (movieInfo.header.romCRC != crc)
 694.308 +			{
 694.309 +				sprintf(buffer, "crc=%02x  ", movieInfo.header.romCRC);
 694.310 +				strcat(warning1, buffer);
 694.311 +
 694.312 +				sprintf(buffer, "crc=%02x  ", crc);
 694.313 +				strcat(warning2, buffer);
 694.314 +			}
 694.315 +///			if (movieInfo.header.romGameCode != romGameCode)
 694.316 +			{
 694.317 +				char code [5];
 694.318 +				if (movieInfo.header.typeFlags & MOVIE_TYPE_GBA)
 694.319 +				{
 694.320 +					memcpy(code, &movieInfo.header.romGameCode, 4);
 694.321 +					code[4] = '\0';
 694.322 +					sprintf(buffer, "code=%s  ", code);
 694.323 +					strcat(warning1, buffer);
 694.324 +				}
 694.325 +
 694.326 +				if (systemCartridgeType == 0)
 694.327 +				{
 694.328 +					memcpy(code, &romGameCode, 4);
 694.329 +					code[4] = '\0';
 694.330 +					sprintf(buffer, "code=%s  ", code);
 694.331 +					strcat(warning2, buffer);
 694.332 +				}
 694.333 +			}
 694.334 +///			if (movieInfo.header.romOrBiosChecksum != checksum && !((movieInfo.header.optionFlags &
 694.335 +// MOVIE_SETTING_USEBIOSFILE)==0
 694.336 +// && checksum==0))
 694.337 +			{
 694.338 +				sprintf(buffer,
 694.339 +				        movieInfo.header.typeFlags &
 694.340 +				        MOVIE_TYPE_GBA ? ((movieInfo.header.optionFlags & MOVIE_SETTING_USEBIOSFILE) ==
 694.341 +				                          0 ? "(bios=none)  " : "(bios=%04x)  ") : "check=%04x  ",
 694.342 +				        movieInfo.header.romOrBiosChecksum);
 694.343 +				strcat(warning1, buffer);
 694.344 +
 694.345 +				sprintf(buffer,
 694.346 +				        checksum == 0 ? "(bios=none)  " : systemCartridgeType == 0 ? "(bios=%04x)  " : "check=%04x  ",
 694.347 +				        checksum);
 694.348 +				strcat(warning2, buffer);
 694.349 +			}
 694.350 +
 694.351 +			if (strlen(warning1) > 0)
 694.352 +			{
 694.353 +				sprintf(buffer, "Movie ROM: %s", warning1);
 694.354 +				GetDlgItem(IDC_LABEL_WARNING1)->SetWindowText(buffer);
 694.355 +
 694.356 +				sprintf(buffer, "Your ROM: %s", warning2);
 694.357 +
 694.358 +				//if(movieInfo.header.romCRC != crc
 694.359 +				//|| strncmp(movieInfo.header.romTitle,romTitle,12) != 0
 694.360 +				//|| movieInfo.header.romOrBiosChecksum != checksum && !((movieInfo.header.optionFlags &
 694.361 +				// MOVIE_SETTING_USEBIOSFILE)==0 && checksum==0))
 694.362 +				//	strcat(buffer, "<-- MISMATCH");
 694.363 +
 694.364 +				GetDlgItem(IDC_LABEL_WARNING2)->SetWindowText(buffer);
 694.365 +			}
 694.366 +			else
 694.367 +			{
 694.368 +				GetDlgItem(IDC_LABEL_WARNING1)->SetWindowText("(No problems detected)");
 694.369 +				GetDlgItem(IDC_LABEL_WARNING2)->SetWindowText(" ");
 694.370 +			}
 694.371 +		}
 694.372 +		GetDlgItem(IDC_CHECK_PAUSEFRAME)->EnableWindow(TRUE);
 694.373 +	}
 694.374 +	else
 694.375 +	{
 694.376 +		GetDlgItem(IDC_LABEL_DATE)->SetWindowText(" ");
 694.377 +		GetDlgItem(IDC_LABEL_LENGTH)->SetWindowText(" ");
 694.378 +		GetDlgItem(IDC_LABEL_FRAMES)->SetWindowText(" ");
 694.379 +		GetDlgItem(IDC_LABEL_RERECORD)->SetWindowText(" ");
 694.380 +		GetDlgItem(IDC_EDIT_AUTHOR)->SetWindowText(" ");
 694.381 +		GetDlgItem(IDC_EDIT_DESCRIPTION)->SetWindowText(" ");
 694.382 +		GetDlgItem(IDC_LABEL_WARNING1)->SetWindowText(" ");
 694.383 +		GetDlgItem(IDC_LABEL_WARNING2)->SetWindowText(" ");
 694.384 +
 694.385 +		GetDlgItem(IDC_EDIT_PAUSEFRAME)->SetWindowText("");
 694.386 +		GetDlgItem(IDC_EDIT_PAUSEFRAME)->EnableWindow(FALSE);
 694.387 +		GetDlgItem(IDC_CHECK_PAUSEFRAME)->EnableWindow(FALSE);
 694.388 +		CheckDlgButton(IDC_CHECK_PAUSEFRAME, FALSE);
 694.389 +/*
 694.390 +        /// FIXME: how to un-check all the radio buttons?
 694.391 +        CheckRadioButton(IDC_RECNOW, IDC_RECSTART, -1);
 694.392 +        CheckRadioButton(IDC_REC_GBA, IDC_REC_GB, -1);
 694.393 +        CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, -1);*/
 694.394 +	}
 694.395 +}
 694.396 +
 694.397 +BOOL MovieOpen::OnWndMsg(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *res)
 694.398 +{
 694.399 +	switch (msg)
 694.400 +	{
 694.401 +	case WM_CTLCOLORSTATIC:
 694.402 +	{
 694.403 +		//HWND hwndDlg = GetSafeHwnd();
 694.404 +		HWND warnDlg = NULL;
 694.405 +		GetDlgItem(IDC_LABEL_WARNING2, &warnDlg);
 694.406 +
 694.407 +		if ((HWND)lParam == warnDlg)
 694.408 +		{
 694.409 +			char   romTitle [12];
 694.410 +			uint32 romGameCode;
 694.411 +			uint16 checksum;
 694.412 +			uint8  crc;
 694.413 +
 694.414 +			VBAMovieGetRomInfo(movieInfo, romTitle, romGameCode, checksum, crc);
 694.415 +
 694.416 +			if (movieInfo.header.romCRC != crc
 694.417 +			    || strncmp(movieInfo.header.romTitle, romTitle, 12) != 0
 694.418 +			    || movieInfo.header.romOrBiosChecksum != checksum
 694.419 +			    && !((movieInfo.header.optionFlags & MOVIE_SETTING_USEBIOSFILE) == 0 && checksum == 0))
 694.420 +			{
 694.421 +				// draw the md5 sum in red if it's different from the md5 of the rom used in the replay
 694.422 +				HDC hdcStatic = (HDC)wParam;
 694.423 +				SetTextColor(hdcStatic, RGB(255, 0, 0));      // use red for a mismatch
 694.424 +
 694.425 +				// I'm not sure why this doesn't work to make the background transparent... it turns white anyway
 694.426 +				SetBkMode(hdcStatic, TRANSPARENT);
 694.427 +				return (LONG)GetStockObject(NULL_BRUSH);
 694.428 +			}
 694.429 +		}
 694.430 +		return FALSE;
 694.431 +	}
 694.432 +	}
 694.433 +	return CDialog::OnWndMsg(msg, wParam, lParam, res);
 694.434 +}
 694.435 +
 694.436 +void MovieOpen::OnBnClickedOk()
 694.437 +{
 694.438 +	bool useBIOSFile = (movieInfo.header.optionFlags & MOVIE_SETTING_USEBIOSFILE) != 0;
 694.439 +	if (useBIOSFile)
 694.440 +	{
 694.441 +		extern bool systemLoadBIOS(const char *biosFileName, bool useBiosFile);
 694.442 +		if (!systemLoadBIOS(theApp.biosFileName, useBIOSFile))
 694.443 +		{
 694.444 +			systemMessage(0, "This movie requires a valid GBA BIOS file to play.\nPlease locate a BIOS file.");
 694.445 +			((MainWnd *)theApp.m_pMainWnd)->OnOptionsEmulatorSelectbiosfile();
 694.446 +			if (!systemLoadBIOS(theApp.biosFileName, useBIOSFile))
 694.447 +			{
 694.448 +				systemMessage(0, "\"%s\" is not a valid BIOS file; cannot play movie without one.", theApp.biosFileName);
 694.449 +				return;
 694.450 +			}
 694.451 +		}
 694.452 +	}
 694.453 +
 694.454 +	int code = VBAMovieOpen(moviePhysicalName, IsDlgButtonChecked(IDC_READONLY) != FALSE);
 694.455 +
 694.456 +	if (code != MOVIE_SUCCESS)
 694.457 +	{
 694.458 +		if (code == MOVIE_FILE_NOT_FOUND)
 694.459 +			systemMessage(0, "Could not find movie file \"%s\".", (const char *)movieLogicalName);
 694.460 +		else if (code == MOVIE_WRONG_FORMAT)
 694.461 +			systemMessage(0, "Movie file \"%s\" is not in proper VBM format.", (const char *)movieLogicalName);
 694.462 +		else if (code == MOVIE_WRONG_VERSION)
 694.463 +			systemMessage(0, "Movie file \"%s\" is not a supported version.", (const char *)movieLogicalName);
 694.464 +		else
 694.465 +			systemMessage(0, "Failed to open movie \"%s\".", (const char *)movieLogicalName);
 694.466 +		return;
 694.467 +	}
 694.468 +	else
 694.469 +	{
 694.470 +		// get author and movie info from the edit fields (the description might change):
 694.471 +		char info[MOVIE_METADATA_SIZE], buffer[MOVIE_METADATA_SIZE];
 694.472 +
 694.473 +		GetDlgItem(IDC_EDIT_AUTHOR)->GetWindowText(buffer, MOVIE_METADATA_AUTHOR_SIZE);
 694.474 +		strncpy(info, buffer, MOVIE_METADATA_AUTHOR_SIZE);
 694.475 +		info[MOVIE_METADATA_AUTHOR_SIZE - 1] = '\0';
 694.476 +
 694.477 +		GetDlgItem(IDC_EDIT_DESCRIPTION)->GetWindowText(buffer, MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
 694.478 +		strncpy(info + MOVIE_METADATA_AUTHOR_SIZE, buffer, MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
 694.479 +		info[MOVIE_METADATA_SIZE - 1] = '\0';
 694.480 +
 694.481 +		VBAMovieSetMetadata(info);
 694.482 +	}
 694.483 +
 694.484 +	if (IsDlgButtonChecked(IDC_CHECK_PAUSEFRAME))
 694.485 +	{
 694.486 +		char buffer [9];
 694.487 +		GetDlgItem(IDC_EDIT_PAUSEFRAME)->GetWindowText(buffer, 8);
 694.488 +		buffer[8] = '\0';
 694.489 +
 694.490 +		int pauseFrame = atoi(buffer);
 694.491 +		if (pauseFrame >= 0)
 694.492 +			VBAMovieSetPauseAt(pauseFrame);
 694.493 +	}
 694.494 +
 694.495 +	OnOK();
 694.496 +}
 694.497 +
 694.498 +void MovieOpen::OnBnClickedCancel()
 694.499 +{
 694.500 +	OnCancel();
 694.501 +}
 694.502 +
 694.503 +void MovieOpen::OnBnClickedReadonly()
 694.504 +{
 694.505 +	theApp.movieReadOnly = IsDlgButtonChecked(IDC_READONLY) != 0;
 694.506 +	m_editDescription.SetReadOnly(theApp.movieReadOnly);
 694.507 +	OnBnClickedMovieRefresh();
 694.508 +}
 694.509 +
 694.510 +void MovieOpen::OnBnClickedCheckPauseframe()
 694.511 +{
 694.512 +	if (IsDlgButtonChecked(IDC_CHECK_PAUSEFRAME))
 694.513 +	{
 694.514 +		char buffer [8];
 694.515 +		_itoa(movieInfo.header.length_frames, buffer, 10);
 694.516 +		GetDlgItem(IDC_EDIT_PAUSEFRAME)->SetWindowText(buffer);
 694.517 +		GetDlgItem(IDC_EDIT_PAUSEFRAME)->EnableWindow(TRUE);
 694.518 +	}
 694.519 +	else
 694.520 +	{
 694.521 +		GetDlgItem(IDC_EDIT_PAUSEFRAME)->SetWindowText("");
 694.522 +		GetDlgItem(IDC_EDIT_PAUSEFRAME)->EnableWindow(FALSE);
 694.523 +	}
 694.524 +}
 694.525 +
 694.526 +void MovieOpen::OnBnClickedHideborder()
 694.527 +{
 694.528 +	theApp.hideMovieBorder = IsDlgButtonChecked(IDC_CHECK_HIDEBORDER) != 0;
 694.529 +}
 694.530 +
 694.531 +void MovieOpen::OnEnChangeMovieFilename()
 694.532 +{
 694.533 +	OnBnClickedMovieRefresh();
 694.534 +}
 694.535 +
   695.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   695.2 +++ b/src/win32/MovieOpen.h	Sat Mar 03 10:31:27 2012 -0600
   695.3 @@ -0,0 +1,58 @@
   695.4 +#ifndef VBA_MOVIE_OPEN_H
   695.5 +#define VBA_MOVIE_OPEN_H
   695.6 +
   695.7 +#if _MSC_VER > 1000
   695.8 +#pragma once
   695.9 +#endif // _MSC_VER > 1000
  695.10 +
  695.11 +#include "../common/movie.h"
  695.12 +
  695.13 +// MovieOpen dialog
  695.14 +
  695.15 +class MovieOpen : public CDialog
  695.16 +{
  695.17 +	DECLARE_DYNAMIC(MovieOpen)
  695.18 +public:
  695.19 +	MovieOpen(CWnd*pParent = NULL);    // standard constructor
  695.20 +	virtual ~MovieOpen();
  695.21 +
  695.22 +// Dialog Data
  695.23 +	//{{AFX_DATA(MovieOpen)
  695.24 +	enum { IDD = IDD_MOVIEOPEN };
  695.25 +	CEdit   m_editAuthor;
  695.26 +	CEdit   m_editDescription;
  695.27 +	CEdit   m_editFilename;
  695.28 +	CEdit   m_editPauseFrame;
  695.29 +	CString moviePhysicalName;
  695.30 +	CString movieLogicalName;
  695.31 +	//}}AFX_DATA
  695.32 +
  695.33 +	// Overrides
  695.34 +	// ClassWizard generated virtual function overrides
  695.35 +	//{{AFX_VIRTUAL(GBACheatList)
  695.36 +protected:
  695.37 +	virtual void DoDataExchange(CDataExchange*pDX);     // DDX/DDV support
  695.38 +	//}}AFX_VIRTUAL
  695.39 +
  695.40 +	// Implementation
  695.41 +protected:
  695.42 +	SMovie  movieInfo;
  695.43 +	int     pauseFrame;
  695.44 +
  695.45 +	// Generated message map functions
  695.46 +	//{{AFX_MSG(GBACheatList)
  695.47 +	afx_msg void OnBnClickedBrowse();
  695.48 +	afx_msg void OnBnClickedOk();
  695.49 +	afx_msg void OnBnClickedCancel();
  695.50 +	afx_msg void OnBnClickedMovieRefresh();
  695.51 +	afx_msg void OnBnClickedReadonly();
  695.52 +	afx_msg void OnBnClickedCheckPauseframe();
  695.53 +	afx_msg void OnBnClickedHideborder();
  695.54 +	afx_msg void OnEnChangeMovieFilename();
  695.55 +	virtual BOOL OnInitDialog() ;
  695.56 +	virtual BOOL OnWndMsg(UINT, WPARAM, LPARAM, LRESULT *);
  695.57 +	//}}AFX_MSG
  695.58 +	DECLARE_MESSAGE_MAP()
  695.59 +};
  695.60 +
  695.61 +#endif // VBA_MOVIE_OPEN_H
   696.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   696.2 +++ b/src/win32/OamView.cpp	Sat Mar 03 10:31:27 2012 -0600
   696.3 @@ -0,0 +1,668 @@
   696.4 +// OamView.cpp : implementation file
   696.5 +//
   696.6 +
   696.7 +#include "stdafx.h"
   696.8 +#include "resource.h"
   696.9 +#include "OamView.h"
  696.10 +#include "FileDlg.h"
  696.11 +#include "Reg.h"
  696.12 +#include "WinResUtil.h"
  696.13 +#include "VBA.h"
  696.14 +
  696.15 +#include "../gba/GBAGlobals.h"
  696.16 +#include "../NLS.h"
  696.17 +#include "../common/Util.h"
  696.18 +
  696.19 +extern "C" {
  696.20 +#include <png.h>
  696.21 +}
  696.22 +
  696.23 +/////////////////////////////////////////////////////////////////////////////
  696.24 +// OamView dialog
  696.25 +
  696.26 +OamView::OamView(CWnd*pParent /*=NULL*/)
  696.27 +	: ResizeDlg(OamView::IDD, pParent)
  696.28 +{
  696.29 +	//{{AFX_DATA_INIT(OamView)
  696.30 +	m_stretch = FALSE;
  696.31 +	//}}AFX_DATA_INIT
  696.32 +	autoUpdate = false;
  696.33 +
  696.34 +	memset(&bmpInfo.bmiHeader, 0, sizeof(bmpInfo.bmiHeader));
  696.35 +
  696.36 +	bmpInfo.bmiHeader.biSize        = sizeof(bmpInfo.bmiHeader);
  696.37 +	bmpInfo.bmiHeader.biWidth       = 32;
  696.38 +	bmpInfo.bmiHeader.biHeight      = 32;
  696.39 +	bmpInfo.bmiHeader.biPlanes      = 1;
  696.40 +	bmpInfo.bmiHeader.biBitCount    = 24;
  696.41 +	bmpInfo.bmiHeader.biCompression = BI_RGB;
  696.42 +	data = (u8 *)calloc(1, 3 * 64 * 64);
  696.43 +
  696.44 +	oamView.setData(data);
  696.45 +	oamView.setBmpInfo(&bmpInfo);
  696.46 +
  696.47 +	number = 0;
  696.48 +}
  696.49 +
  696.50 +void OamView::DoDataExchange(CDataExchange*pDX)
  696.51 +{
  696.52 +	CDialog::DoDataExchange(pDX);
  696.53 +	//{{AFX_DATA_MAP(OamView)
  696.54 +	DDX_Control(pDX, IDC_SPRITE, m_sprite);
  696.55 +	DDX_Check(pDX, IDC_STRETCH, m_stretch);
  696.56 +	//}}AFX_DATA_MAP
  696.57 +	DDX_Control(pDX, IDC_COLOR, color);
  696.58 +	DDX_Control(pDX, IDC_OAM_VIEW, oamView);
  696.59 +	DDX_Control(pDX, IDC_OAM_VIEW_ZOOM, oamZoom);
  696.60 +}
  696.61 +
  696.62 +BEGIN_MESSAGE_MAP(OamView, CDialog)
  696.63 +//{{AFX_MSG_MAP(OamView)
  696.64 +ON_BN_CLICKED(IDC_SAVE, OnSave)
  696.65 +ON_BN_CLICKED(IDC_STRETCH, OnStretch)
  696.66 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
  696.67 +ON_EN_CHANGE(IDC_SPRITE, OnChangeSprite)
  696.68 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
  696.69 +ON_WM_HSCROLL()
  696.70 +//}}AFX_MSG_MAP
  696.71 +ON_MESSAGE(WM_MAPINFO, OnMapInfo)
  696.72 +ON_MESSAGE(WM_COLINFO, OnColInfo)
  696.73 +END_MESSAGE_MAP()
  696.74 +
  696.75 +/////////////////////////////////////////////////////////////////////////////
  696.76 +// OamView message handlers
  696.77 +
  696.78 +OamView::~OamView()
  696.79 +{
  696.80 +	free(data);
  696.81 +	data = NULL;
  696.82 +}
  696.83 +
  696.84 +void OamView::paint()
  696.85 +{
  696.86 +	if (oam == NULL || paletteRAM == NULL || vram == NULL)
  696.87 +		return;
  696.88 +
  696.89 +	render();
  696.90 +	oamView.setSize(w, h);
  696.91 +	oamView.refresh();
  696.92 +}
  696.93 +
  696.94 +void OamView::update()
  696.95 +{
  696.96 +	paint();
  696.97 +}
  696.98 +
  696.99 +void OamView::setAttributes(u16 a0, u16 a1, u16 a2)
 696.100 +{
 696.101 +	CString buffer;
 696.102 +
 696.103 +	int y        = a0 & 255;
 696.104 +	int rot      = a0 & 512;
 696.105 +	int mode     = (a0 >> 10) & 3;
 696.106 +	int mosaic   = a0 & 4096;
 696.107 +	int color    = a0 & 8192;
 696.108 +	int duple    = a0 & 1024;
 696.109 +	int shape    = (a0 >> 14) & 3;
 696.110 +	int x        = a1 & 511;
 696.111 +	int rotParam = (a1 >> 9) & 31;
 696.112 +	int flipH    = a1 & 4096;
 696.113 +	int flipV    = a1 & 8192;
 696.114 +	int size     = (a1 >> 14) & 3;
 696.115 +	int tile     = a2 & 1023;
 696.116 +	int prio     = (a2 >> 10) & 3;
 696.117 +	int pal      = (a2 >> 12) & 15;
 696.118 +
 696.119 +	buffer.Format("%d,%d", x, y);
 696.120 +	GetDlgItem(IDC_POS)->SetWindowText(buffer);
 696.121 +
 696.122 +	buffer.Format("%d", mode);
 696.123 +	GetDlgItem(IDC_MODE)->SetWindowText(buffer);
 696.124 +
 696.125 +	GetDlgItem(IDC_COLORS)->SetWindowText(color ? "256" : "16");
 696.126 +
 696.127 +	buffer.Format("%d", pal);
 696.128 +	GetDlgItem(IDC_PALETTE)->SetWindowText(buffer);
 696.129 +
 696.130 +	buffer.Format("%d", tile);
 696.131 +	GetDlgItem(IDC_TILE)->SetWindowText(buffer);
 696.132 +
 696.133 +	buffer.Format("%d", prio);
 696.134 +	GetDlgItem(IDC_PRIO)->SetWindowText(buffer);
 696.135 +
 696.136 +	buffer.Format("%d,%d", w, h);
 696.137 +	GetDlgItem(IDC_SIZE2)->SetWindowText(buffer);
 696.138 +
 696.139 +	if (rot)
 696.140 +	{
 696.141 +		buffer.Format("%d", rotParam);
 696.142 +	}
 696.143 +	else
 696.144 +		buffer.Empty();
 696.145 +	GetDlgItem(IDC_ROT)->SetWindowText(buffer);
 696.146 +
 696.147 +	buffer.Empty();
 696.148 +
 696.149 +	if (rot)
 696.150 +		buffer += 'R';
 696.151 +	else
 696.152 +		buffer += ' ';
 696.153 +	if (!rot)
 696.154 +	{
 696.155 +		if (flipH)
 696.156 +			buffer += 'H';
 696.157 +		else
 696.158 +			buffer += ' ';
 696.159 +		if (flipV)
 696.160 +			buffer += 'V';
 696.161 +		else
 696.162 +			buffer += ' ';
 696.163 +	}
 696.164 +	else
 696.165 +	{
 696.166 +		buffer += ' ';
 696.167 +		buffer += ' ';
 696.168 +	}
 696.169 +	if (mosaic)
 696.170 +		buffer += 'M';
 696.171 +	else
 696.172 +		buffer += ' ';
 696.173 +	if (duple)
 696.174 +		buffer += 'D';
 696.175 +	else
 696.176 +		buffer += ' ';
 696.177 +
 696.178 +	GetDlgItem(IDC_FLAGS)->SetWindowText(buffer);
 696.179 +}
 696.180 +
 696.181 +void OamView::render()
 696.182 +{
 696.183 +	int m = 0;
 696.184 +	if (oam == NULL || paletteRAM == NULL || vram == NULL)
 696.185 +		return;
 696.186 +
 696.187 +	u16 *sprites       = &((u16 *)oam)[4*number];
 696.188 +	u16 *spritePalette = &((u16 *)paletteRAM)[0x100];
 696.189 +	u8 * bmp = data;
 696.190 +
 696.191 +	u16 a0 = *sprites++;
 696.192 +	u16 a1 = *sprites++;
 696.193 +	u16 a2 = *sprites++;
 696.194 +
 696.195 +	int sizeY = 8;
 696.196 +	int sizeX = 8;
 696.197 +
 696.198 +	switch (((a0 >>12) & 0x0c)|(a1>>14))
 696.199 +	{
 696.200 +	case 0:
 696.201 +		break;
 696.202 +	case 1:
 696.203 +		sizeX = sizeY = 16;
 696.204 +		break;
 696.205 +	case 2:
 696.206 +		sizeX = sizeY = 32;
 696.207 +		break;
 696.208 +	case 3:
 696.209 +		sizeX = sizeY = 64;
 696.210 +		break;
 696.211 +	case 4:
 696.212 +		sizeX = 16;
 696.213 +		break;
 696.214 +	case 5:
 696.215 +		sizeX = 32;
 696.216 +		break;
 696.217 +	case 6:
 696.218 +		sizeX = 32;
 696.219 +		sizeY = 16;
 696.220 +		break;
 696.221 +	case 7:
 696.222 +		sizeX = 64;
 696.223 +		sizeY = 32;
 696.224 +		break;
 696.225 +	case 8:
 696.226 +		sizeY = 16;
 696.227 +		break;
 696.228 +	case 9:
 696.229 +		sizeY = 32;
 696.230 +		break;
 696.231 +	case 10:
 696.232 +		sizeX = 16;
 696.233 +		sizeY = 32;
 696.234 +		break;
 696.235 +	case 11:
 696.236 +		sizeX = 32;
 696.237 +		sizeY = 64;
 696.238 +		break;
 696.239 +	default:
 696.240 +		return;
 696.241 +	}
 696.242 +
 696.243 +	w = sizeX;
 696.244 +	h = sizeY;
 696.245 +
 696.246 +	setAttributes(a0, a1, a2);
 696.247 +
 696.248 +	int sy = (a0 & 255);
 696.249 +
 696.250 +	if (a0 & 0x2000)
 696.251 +	{
 696.252 +		int c = (a2 & 0x3FF);
 696.253 +		//          if((DISPCNT & 7) > 2 && (c < 512))
 696.254 +		//            return;
 696.255 +		int inc = 32;
 696.256 +		if (DISPCNT & 0x40)
 696.257 +			inc = sizeX >> 2;
 696.258 +		else
 696.259 +			c &= 0x3FE;
 696.260 +
 696.261 +		for (int y = 0; y < sizeY; y++)
 696.262 +		{
 696.263 +			for (int x = 0; x < sizeX; x++)
 696.264 +			{
 696.265 +				u32 color = vram[0x10000 + (((c + (y>>3) * inc)*
 696.266 +				                             32 + (y & 7) * 8 + (x >> 3) * 64 +
 696.267 +				                             (x & 7))&0x7FFF)];
 696.268 +				color  = spritePalette[color];
 696.269 +				*bmp++ = ((color >> 10) & 0x1f) << 3;
 696.270 +				*bmp++ = ((color >> 5) & 0x1f) << 3;
 696.271 +				*bmp++ = (color & 0x1f) << 3;
 696.272 +			}
 696.273 +		}
 696.274 +	}
 696.275 +	else
 696.276 +	{
 696.277 +		int c = (a2 & 0x3FF);
 696.278 +		//      if((DISPCNT & 7) > 2 && (c < 512))
 696.279 +		//          continue;
 696.280 +
 696.281 +		int inc = 32;
 696.282 +		if (DISPCNT & 0x40)
 696.283 +			inc = sizeX >> 3;
 696.284 +		int palette = (a2 >> 8) & 0xF0;
 696.285 +		for (int y = 0; y < sizeY; y++)
 696.286 +		{
 696.287 +			for (int x = 0; x < sizeX; x++)
 696.288 +			{
 696.289 +				u32 color = vram[0x10000 + (((c + (y>>3) * inc)*
 696.290 +				                             32 + (y & 7) * 4 + (x >> 3) * 32 +
 696.291 +				                             ((x & 7)>>1))&0x7FFF)];
 696.292 +				if (x & 1)
 696.293 +					color >>= 4;
 696.294 +				else
 696.295 +					color &= 0x0F;
 696.296 +
 696.297 +				color  = spritePalette[palette+color];
 696.298 +				*bmp++ = ((color >> 10) & 0x1f) << 3;
 696.299 +				*bmp++ = ((color >> 5) & 0x1f) << 3;
 696.300 +				*bmp++ = (color & 0x1f) << 3;
 696.301 +			}
 696.302 +		}
 696.303 +	}
 696.304 +}
 696.305 +
 696.306 +void OamView::saveBMP(const char *name)
 696.307 +{
 696.308 +	u8 writeBuffer[1024 * 3];
 696.309 +
 696.310 +	FILE *fp = fopen(name, "wb");
 696.311 +
 696.312 +	if (!fp)
 696.313 +	{
 696.314 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
 696.315 +		return;
 696.316 +	}
 696.317 +
 696.318 +	struct
 696.319 +	{
 696.320 +		u8 ident[2];
 696.321 +		u8 filesize[4];
 696.322 +		u8 reserved[4];
 696.323 +		u8 dataoffset[4];
 696.324 +		u8 headersize[4];
 696.325 +		u8 width[4];
 696.326 +		u8 height[4];
 696.327 +		u8 planes[2];
 696.328 +		u8 bitsperpixel[2];
 696.329 +		u8 compression[4];
 696.330 +		u8 datasize[4];
 696.331 +		u8 hres[4];
 696.332 +		u8 vres[4];
 696.333 +		u8 colors[4];
 696.334 +		u8 importantcolors[4];
 696.335 +		u8 pad[2];
 696.336 +	} bmpheader;
 696.337 +	memset(&bmpheader, 0, sizeof(bmpheader));
 696.338 +
 696.339 +	bmpheader.ident[0] = 'B';
 696.340 +	bmpheader.ident[1] = 'M';
 696.341 +
 696.342 +	u32 fsz = sizeof(bmpheader) + w*h*3;
 696.343 +	utilPutDword(bmpheader.filesize, fsz);
 696.344 +	utilPutDword(bmpheader.dataoffset, 0x38);
 696.345 +	utilPutDword(bmpheader.headersize, 0x28);
 696.346 +	utilPutDword(bmpheader.width, w);
 696.347 +	utilPutDword(bmpheader.height, h);
 696.348 +	utilPutDword(bmpheader.planes, 1);
 696.349 +	utilPutDword(bmpheader.bitsperpixel, 24);
 696.350 +	utilPutDword(bmpheader.datasize, 3*w*h);
 696.351 +
 696.352 +	fwrite(&bmpheader, 1, sizeof(bmpheader), fp);
 696.353 +
 696.354 +	u8 *b = writeBuffer;
 696.355 +
 696.356 +	int sizeX = w;
 696.357 +	int sizeY = h;
 696.358 +
 696.359 +	u8 *pixU8 = (u8 *)data+3*w*(h-1);
 696.360 +	for (int y = 0; y < sizeY; y++)
 696.361 +	{
 696.362 +		for (int x = 0; x < sizeX; x++)
 696.363 +		{
 696.364 +			*b++ = *pixU8++; // B
 696.365 +			*b++ = *pixU8++; // G
 696.366 +			*b++ = *pixU8++; // R
 696.367 +		}
 696.368 +		pixU8 -= 2*3*w;
 696.369 +		fwrite(writeBuffer, 1, 3*w, fp);
 696.370 +
 696.371 +		b = writeBuffer;
 696.372 +	}
 696.373 +
 696.374 +	fclose(fp);
 696.375 +}
 696.376 +
 696.377 +void OamView::savePNG(const char *name)
 696.378 +{
 696.379 +	u8 writeBuffer[1024 * 3];
 696.380 +
 696.381 +	FILE *fp = fopen(name, "wb");
 696.382 +
 696.383 +	if (!fp)
 696.384 +	{
 696.385 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
 696.386 +		return;
 696.387 +	}
 696.388 +
 696.389 +	png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
 696.390 +	                                              NULL,
 696.391 +	                                              NULL,
 696.392 +	                                              NULL);
 696.393 +	if (!png_ptr)
 696.394 +	{
 696.395 +		fclose(fp);
 696.396 +		return;
 696.397 +	}
 696.398 +
 696.399 +	png_infop info_ptr = png_create_info_struct(png_ptr);
 696.400 +
 696.401 +	if (!info_ptr)
 696.402 +	{
 696.403 +		png_destroy_write_struct(&png_ptr, NULL);
 696.404 +		fclose(fp);
 696.405 +		return;
 696.406 +	}
 696.407 +
 696.408 +	if (setjmp(png_ptr->jmpbuf))
 696.409 +	{
 696.410 +		png_destroy_write_struct(&png_ptr, NULL);
 696.411 +		fclose(fp);
 696.412 +		return;
 696.413 +	}
 696.414 +
 696.415 +	png_init_io(png_ptr, fp);
 696.416 +
 696.417 +	png_set_IHDR(png_ptr,
 696.418 +	             info_ptr,
 696.419 +	             w,
 696.420 +	             h,
 696.421 +	             8,
 696.422 +	             PNG_COLOR_TYPE_RGB,
 696.423 +	             PNG_INTERLACE_NONE,
 696.424 +	             PNG_COMPRESSION_TYPE_DEFAULT,
 696.425 +	             PNG_FILTER_TYPE_DEFAULT);
 696.426 +
 696.427 +	png_write_info(png_ptr, info_ptr);
 696.428 +
 696.429 +	u8 *b = writeBuffer;
 696.430 +
 696.431 +	int sizeX = w;
 696.432 +	int sizeY = h;
 696.433 +
 696.434 +	u8 *pixU8 = (u8 *)data;
 696.435 +	for (int y = 0; y < sizeY; y++)
 696.436 +	{
 696.437 +		for (int x = 0; x < sizeX; x++)
 696.438 +		{
 696.439 +			int blue  = *pixU8++;
 696.440 +			int green = *pixU8++;
 696.441 +			int red   = *pixU8++;
 696.442 +
 696.443 +			*b++ = red;
 696.444 +			*b++ = green;
 696.445 +			*b++ = blue;
 696.446 +		}
 696.447 +		png_write_row(png_ptr, writeBuffer);
 696.448 +
 696.449 +		b = writeBuffer;
 696.450 +	}
 696.451 +
 696.452 +	png_write_end(png_ptr, info_ptr);
 696.453 +
 696.454 +	png_destroy_write_struct(&png_ptr, &info_ptr);
 696.455 +
 696.456 +	fclose(fp);
 696.457 +}
 696.458 +
 696.459 +void OamView::OnSave()
 696.460 +{
 696.461 +	CString captureBuffer;
 696.462 +
 696.463 +	if (theApp.captureFormat == 0)
 696.464 +		captureBuffer = "oam.png";
 696.465 +	else
 696.466 +		captureBuffer = "oam.bmp";
 696.467 +
 696.468 +	LPCTSTR exts[] = {".png", ".bmp", NULL };
 696.469 +
 696.470 +	CString filter = winResLoadFilter(IDS_FILTER_PNG);
 696.471 +	CString title  = winResLoadString(IDS_SELECT_CAPTURE_NAME);
 696.472 +
 696.473 +	FileDlg dlg(this,
 696.474 +	            captureBuffer,
 696.475 +	            filter,
 696.476 +	            theApp.captureFormat ? 2 : 1,
 696.477 +	            theApp.captureFormat ? "BMP" : "PNG",
 696.478 +	            exts,
 696.479 +	            "",
 696.480 +	            title,
 696.481 +	            true);
 696.482 +
 696.483 +	if (dlg.DoModal() == IDCANCEL)
 696.484 +	{
 696.485 +		return;
 696.486 +	}
 696.487 +	captureBuffer = dlg.GetPathName();
 696.488 +
 696.489 +	if (dlg.getFilterIndex() == 2)
 696.490 +		saveBMP(captureBuffer);
 696.491 +	else
 696.492 +		savePNG(captureBuffer);
 696.493 +}
 696.494 +
 696.495 +BOOL OamView::OnInitDialog()
 696.496 +{
 696.497 +	CDialog::OnInitDialog();
 696.498 +
 696.499 +	DIALOG_SIZER_START(sz)
 696.500 +	DIALOG_SIZER_ENTRY(IDC_OAM_VIEW, DS_SizeX | DS_SizeY)
 696.501 +	DIALOG_SIZER_ENTRY(IDC_OAM_VIEW_ZOOM, DS_MoveX)
 696.502 +	DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
 696.503 +	DIALOG_SIZER_ENTRY(IDC_SAVE,  DS_MoveY)
 696.504 +	DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
 696.505 +	DIALOG_SIZER_ENTRY(IDC_COLOR, DS_MoveY)
 696.506 +	DIALOG_SIZER_ENTRY(IDC_R, DS_MoveY)
 696.507 +	DIALOG_SIZER_ENTRY(IDC_G, DS_MoveY)
 696.508 +	DIALOG_SIZER_ENTRY(IDC_B, DS_MoveY)
 696.509 +	DIALOG_SIZER_END()
 696.510 +	SetData(sz,
 696.511 +	        TRUE,
 696.512 +	        HKEY_CURRENT_USER,
 696.513 +	        "Software\\Emulators\\VisualBoyAdvance\\Viewer\\OamView",
 696.514 +	        NULL);
 696.515 +
 696.516 +	m_sprite.SetWindowText("0");
 696.517 +
 696.518 +	updateScrollInfo();
 696.519 +
 696.520 +	m_stretch = regQueryDwordValue("oamViewStretch", 0);
 696.521 +	if (m_stretch)
 696.522 +		oamView.setStretch(true);
 696.523 +	UpdateData(FALSE);
 696.524 +
 696.525 +	paint();
 696.526 +
 696.527 +	return TRUE; // return TRUE unless you set the focus to a control
 696.528 +	             // EXCEPTION: OCX Property Pages should return FALSE
 696.529 +}
 696.530 +
 696.531 +void OamView::OnStretch()
 696.532 +{
 696.533 +	oamView.setStretch(!oamView.getStretch());
 696.534 +	paint();
 696.535 +	regSetDwordValue("oamViewStretch", oamView.getStretch());
 696.536 +}
 696.537 +
 696.538 +void OamView::OnAutoUpdate()
 696.539 +{
 696.540 +	autoUpdate = !autoUpdate;
 696.541 +	if (autoUpdate)
 696.542 +	{
 696.543 +		theApp.winAddUpdateListener(this);
 696.544 +	}
 696.545 +	else
 696.546 +	{
 696.547 +		theApp.winRemoveUpdateListener(this);
 696.548 +	}
 696.549 +}
 696.550 +
 696.551 +void OamView::OnChangeSprite()
 696.552 +{
 696.553 +	CString buffer;
 696.554 +	m_sprite.GetWindowText(buffer);
 696.555 +	int n = atoi(buffer);
 696.556 +	if (n < 0 || n > 127)
 696.557 +	{
 696.558 +		buffer.Format("%d", number);
 696.559 +		m_sprite.SetWindowText(buffer);
 696.560 +		return;
 696.561 +	}
 696.562 +	number = n;
 696.563 +	paint();
 696.564 +	updateScrollInfo();
 696.565 +}
 696.566 +
 696.567 +void OamView::OnClose()
 696.568 +{
 696.569 +	theApp.winRemoveUpdateListener(this);
 696.570 +
 696.571 +	DestroyWindow();
 696.572 +}
 696.573 +
 696.574 +LRESULT OamView::OnMapInfo(WPARAM wParam, LPARAM lParam)
 696.575 +{
 696.576 +	u8 *colors = (u8 *)lParam;
 696.577 +	oamZoom.setColors(colors);
 696.578 +
 696.579 +	return TRUE;
 696.580 +}
 696.581 +
 696.582 +LRESULT OamView::OnColInfo(WPARAM wParam, LPARAM lParam)
 696.583 +{
 696.584 +	u16 c = (u16)wParam;
 696.585 +
 696.586 +	color.setColor(c);
 696.587 +
 696.588 +	int r = (c & 0x1f);
 696.589 +	int g = (c & 0x3e0) >> 5;
 696.590 +	int b = (c & 0x7c00) >> 10;
 696.591 +
 696.592 +	CString buffer;
 696.593 +	buffer.Format("R: %d", r);
 696.594 +	GetDlgItem(IDC_R)->SetWindowText(buffer);
 696.595 +
 696.596 +	buffer.Format("G: %d", g);
 696.597 +	GetDlgItem(IDC_G)->SetWindowText(buffer);
 696.598 +
 696.599 +	buffer.Format("B: %d", b);
 696.600 +	GetDlgItem(IDC_B)->SetWindowText(buffer);
 696.601 +
 696.602 +	return TRUE;
 696.603 +}
 696.604 +
 696.605 +void OamView::updateScrollInfo()
 696.606 +{
 696.607 +	SCROLLINFO si;
 696.608 +	ZeroMemory(&si, sizeof(si));
 696.609 +	si.cbSize = sizeof(si);
 696.610 +	si.fMask  = SIF_PAGE | SIF_RANGE | SIF_DISABLENOSCROLL | SIF_POS;
 696.611 +	si.nMin   = 0;
 696.612 +	si.nMax   = 127;
 696.613 +	si.nPage  = 1;
 696.614 +	si.nPos   = number;
 696.615 +	GetDlgItem(IDC_SCROLLBAR)->SetScrollInfo(SB_CTL,
 696.616 +	                                         &si,
 696.617 +	                                         TRUE);
 696.618 +}
 696.619 +
 696.620 +void OamView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar)
 696.621 +{
 696.622 +	switch (nSBCode)
 696.623 +	{
 696.624 +	case SB_BOTTOM:
 696.625 +		number = 127;
 696.626 +		break;
 696.627 +	case SB_LINEDOWN:
 696.628 +		number++;
 696.629 +		if (number > 127)
 696.630 +			number = 127;
 696.631 +		break;
 696.632 +	case SB_LINEUP:
 696.633 +		number--;
 696.634 +		if (number < 0)
 696.635 +			number = 0;
 696.636 +		break;
 696.637 +	case SB_PAGEDOWN:
 696.638 +		number += 16;
 696.639 +		if (number > 127)
 696.640 +			number = 127;
 696.641 +		break;
 696.642 +	case SB_PAGEUP:
 696.643 +		number -= 16;
 696.644 +		if (number < 0)
 696.645 +			number = 0;
 696.646 +		break;
 696.647 +	case SB_TOP:
 696.648 +		number = 0;
 696.649 +		break;
 696.650 +	case SB_THUMBTRACK:
 696.651 +		number = nPos;
 696.652 +		if (number < 0)
 696.653 +			number = 0;
 696.654 +		if (number > 127)
 696.655 +			number = 127;
 696.656 +		break;
 696.657 +	}
 696.658 +
 696.659 +	updateScrollInfo();
 696.660 +
 696.661 +	CString buffer;
 696.662 +	buffer.Format("%d", number);
 696.663 +	m_sprite.SetWindowText(buffer);
 696.664 +	paint();
 696.665 +}
 696.666 +
 696.667 +void OamView::PostNcDestroy()
 696.668 +{
 696.669 +	delete this;
 696.670 +}
 696.671 +
   697.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   697.2 +++ b/src/win32/OamView.h	Sat Mar 03 10:31:27 2012 -0600
   697.3 @@ -0,0 +1,78 @@
   697.4 +#if !defined(AFX_OAMVIEW_H__E5369352_80F8_49C4_9F23_05EB6FC1345B__INCLUDED_)
   697.5 +#define AFX_OAMVIEW_H__E5369352_80F8_49C4_9F23_05EB6FC1345B__INCLUDED_
   697.6 +
   697.7 +#if _MSC_VER > 1000
   697.8 +#pragma once
   697.9 +#endif // _MSC_VER > 1000
  697.10 +// OamView.h : header file
  697.11 +//
  697.12 +#include "BitmapControl.h"
  697.13 +#include "ZoomControl.h"
  697.14 +#include "ColorControl.h"
  697.15 +#include "IUpdate.h"
  697.16 +#include "ResizeDlg.h"
  697.17 +
  697.18 +/////////////////////////////////////////////////////////////////////////////
  697.19 +// OamView dialog
  697.20 +
  697.21 +class OamView : public ResizeDlg, IUpdateListener
  697.22 +{
  697.23 +private:
  697.24 +	BITMAPINFO    bmpInfo;
  697.25 +	u8 *          data;
  697.26 +	int           w;
  697.27 +	int           h;
  697.28 +	int           number;
  697.29 +	bool          autoUpdate;
  697.30 +	BitmapControl oamView;
  697.31 +	ZoomControl   oamZoom;
  697.32 +	ColorControl  color;
  697.33 +
  697.34 +	// Construction
  697.35 +public:
  697.36 +	void updateScrollInfo();
  697.37 +	afx_msg LRESULT OnColInfo(WPARAM wParam, LPARAM lParam);
  697.38 +	afx_msg LRESULT OnMapInfo(WPARAM wParam, LPARAM lParam);
  697.39 +	void savePNG(const char *name);
  697.40 +	void saveBMP(const char *name);
  697.41 +	void render();
  697.42 +	void setAttributes(u16 a0, u16 a1, u16 a2);
  697.43 +	void paint();
  697.44 +	~OamView();
  697.45 +	OamView(CWnd*pParent = NULL);  // standard constructor
  697.46 +
  697.47 +	virtual void update();
  697.48 +	// Dialog Data
  697.49 +	//{{AFX_DATA(OamView)
  697.50 +	enum { IDD = IDD_OAM_VIEW };
  697.51 +	CEdit m_sprite;
  697.52 +	BOOL  m_stretch;
  697.53 +	//}}AFX_DATA
  697.54 +
  697.55 +	// Overrides
  697.56 +	// ClassWizard generated virtual function overrides
  697.57 +	//{{AFX_VIRTUAL(OamView)
  697.58 +protected:
  697.59 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  697.60 +	virtual void PostNcDestroy();
  697.61 +	//}}AFX_VIRTUAL
  697.62 +
  697.63 +	// Implementation
  697.64 +protected:
  697.65 +	// Generated message map functions
  697.66 +	//{{AFX_MSG(OamView)
  697.67 +	afx_msg void OnSave();
  697.68 +	virtual BOOL OnInitDialog();
  697.69 +	afx_msg void OnStretch();
  697.70 +	afx_msg void OnAutoUpdate();
  697.71 +	afx_msg void OnChangeSprite();
  697.72 +	afx_msg void OnClose();
  697.73 +	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar);
  697.74 +	//}}AFX_MSG
  697.75 +	DECLARE_MESSAGE_MAP()
  697.76 +};
  697.77 +
  697.78 +//{{AFX_INSERT_LOCATION}}
  697.79 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  697.80 +
  697.81 +#endif // !defined(AFX_OAMVIEW_H__E5369352_80F8_49C4_9F23_05EB6FC1345B__INCLUDED_)
   698.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   698.2 +++ b/src/win32/OpenGL.cpp	Sat Mar 03 10:31:27 2012 -0600
   698.3 @@ -0,0 +1,544 @@
   698.4 +#include "stdafx.h"
   698.5 +#include <gl/GL.h>
   698.6 +
   698.7 +#include "resource.h"
   698.8 +#include "MainWnd.h"
   698.9 +#include "Reg.h"
  698.10 +#include "VBA.h"
  698.11 +
  698.12 +#include "../gba/GBAGlobals.h"
  698.13 +#include "../gb/gbGlobals.h"
  698.14 +#include "../common/Text.h"
  698.15 +#include "../version.h"
  698.16 +
  698.17 +#ifdef MMX
  698.18 +extern "C" bool cpu_mmx;
  698.19 +
  698.20 +extern bool detectMMX();
  698.21 +#endif
  698.22 +
  698.23 +extern int systemSpeed;
  698.24 +extern int Init_2xSaI(u32);
  698.25 +extern void winlog(const char *, ...);
  698.26 +
  698.27 +class OpenGLDisplay : public IDisplay
  698.28 +{
  698.29 +private:
  698.30 +	HDC    hDC;
  698.31 +	HGLRC  hglrc;
  698.32 +	GLuint texture;
  698.33 +	int    width;
  698.34 +	int    height;
  698.35 +	float  size;
  698.36 +	u8 *   filterData;
  698.37 +	bool   failed;
  698.38 +
  698.39 +	bool initializeTexture(int w, int h);
  698.40 +	void updateFiltering(int);
  698.41 +public:
  698.42 +	OpenGLDisplay();
  698.43 +	virtual ~OpenGLDisplay();
  698.44 +
  698.45 +	virtual bool initialize();
  698.46 +	virtual void cleanup();
  698.47 +	virtual void render();
  698.48 +	virtual void checkFullScreen();
  698.49 +	virtual void renderMenu();
  698.50 +	virtual void clear();
  698.51 +	virtual bool changeRenderSize(int w, int h);
  698.52 +	virtual void resize(int w, int h);
  698.53 +	virtual DISPLAY_TYPE getType() { return OPENGL; };
  698.54 +	virtual void setOption(const char *, int);
  698.55 +	virtual int selectFullScreenMode(GUID * *);
  698.56 +};
  698.57 +
  698.58 +OpenGLDisplay::OpenGLDisplay()
  698.59 +{
  698.60 +	hDC        = NULL;
  698.61 +	hglrc      = NULL;
  698.62 +	texture    = 0;
  698.63 +	width      = 0;
  698.64 +	height     = 0;
  698.65 +	size       = 0.0f;
  698.66 +	filterData = (u8 *)malloc(4*16*256*256); // sufficient for 4x filters @ 32bit color depth
  698.67 +	failed     = false;
  698.68 +}
  698.69 +
  698.70 +OpenGLDisplay::~OpenGLDisplay()
  698.71 +{
  698.72 +	cleanup();
  698.73 +}
  698.74 +
  698.75 +void OpenGLDisplay::cleanup()
  698.76 +{
  698.77 +	if (texture != 0)
  698.78 +	{
  698.79 +		glDeleteTextures(1, &texture);
  698.80 +		texture = 0;
  698.81 +	}
  698.82 +	if (hglrc != NULL)
  698.83 +	{
  698.84 +		wglDeleteContext(hglrc);
  698.85 +		wglMakeCurrent(NULL, NULL);
  698.86 +		hglrc = NULL;
  698.87 +	}
  698.88 +	if (hDC != NULL)
  698.89 +	{
  698.90 +		ReleaseDC(*theApp.m_pMainWnd, hDC);
  698.91 +		hDC = NULL;
  698.92 +	}
  698.93 +	if (filterData)
  698.94 +	{
  698.95 +		free(filterData);
  698.96 +		filterData = NULL;
  698.97 +	}
  698.98 +	width  = 0;
  698.99 +	height = 0;
 698.100 +	size   = 0.0f;
 698.101 +}
 698.102 +
 698.103 +bool OpenGLDisplay::initialize()
 698.104 +{
 698.105 +	CWnd *pWnd = theApp.m_pMainWnd;
 698.106 +
 698.107 +	theApp.mode320Available = false;
 698.108 +	theApp.mode640Available = false;
 698.109 +	theApp.mode800Available = false;
 698.110 +
 698.111 +	CDC *dc  = pWnd->GetDC();
 698.112 +	HDC  hDC = dc->GetSafeHdc();
 698.113 +
 698.114 +	PIXELFORMATDESCRIPTOR pfd = {
 698.115 +		sizeof(PIXELFORMATDESCRIPTOR), //  size of this pfd
 698.116 +		1, // version number
 698.117 +		PFD_DRAW_TO_WINDOW | // support window
 698.118 +		PFD_SUPPORT_OPENGL | // support OpenGL
 698.119 +		PFD_DOUBLEBUFFER, // double buffered
 698.120 +		PFD_TYPE_RGBA, // RGBA type
 698.121 +		16, // 16-bit color depth
 698.122 +		0, 0, 0, 0, 0, 0,  // color bits ignored
 698.123 +		0, // no alpha buffer
 698.124 +		0, // shift bit ignored
 698.125 +		0, // no accumulation buffer
 698.126 +		0, 0, 0, 0, // accum bits ignored
 698.127 +		32, // 32-bit z-buffer
 698.128 +		0, // no stencil buffer
 698.129 +		0, // no auxiliary buffer
 698.130 +		PFD_MAIN_PLANE, // main layer
 698.131 +		0, // reserved
 698.132 +		0, 0, 0            // layer masks ignored
 698.133 +	};
 698.134 +	int iPixelFormat;
 698.135 +
 698.136 +	if (!(iPixelFormat = ChoosePixelFormat(hDC, &pfd)))
 698.137 +	{
 698.138 +		winlog("Failed ChoosePixelFormat\n");
 698.139 +		return false;
 698.140 +	}
 698.141 +
 698.142 +	// obtain detailed information about
 698.143 +	// the device context's first pixel format
 698.144 +	if (!(DescribePixelFormat(hDC, iPixelFormat,
 698.145 +	                          sizeof(PIXELFORMATDESCRIPTOR), &pfd)))
 698.146 +	{
 698.147 +		winlog("Failed DescribePixelFormat\n");
 698.148 +		return false;
 698.149 +	}
 698.150 +
 698.151 +	if (!SetPixelFormat(hDC, iPixelFormat, &pfd))
 698.152 +	{
 698.153 +		winlog("Failed SetPixelFormat\n");
 698.154 +		return false;
 698.155 +	}
 698.156 +
 698.157 +	if (!(hglrc = wglCreateContext(hDC)))
 698.158 +	{
 698.159 +		winlog("Failed wglCreateContext\n");
 698.160 +		return false;
 698.161 +	}
 698.162 +
 698.163 +	if (!wglMakeCurrent(hDC, hglrc))
 698.164 +	{
 698.165 +		winlog("Failed wglMakeCurrent\n");
 698.166 +		return false;
 698.167 +	}
 698.168 +	pWnd->ReleaseDC(dc);
 698.169 +
 698.170 +	// setup 2D gl environment
 698.171 +	glPushAttrib(GL_ENABLE_BIT);
 698.172 +	glDisable(GL_DEPTH_TEST);
 698.173 +	glDisable(GL_CULL_FACE);
 698.174 +	glEnable(GL_TEXTURE_2D);
 698.175 +
 698.176 +	glViewport(0, 0, theApp.surfaceSizeX, theApp.surfaceSizeY);
 698.177 +
 698.178 +	glMatrixMode(GL_PROJECTION);
 698.179 +	glLoadIdentity();
 698.180 +
 698.181 +	glOrtho(0.0, (GLdouble)(theApp.surfaceSizeX), (GLdouble)(theApp.surfaceSizeY),
 698.182 +	        0.0, 0.0, 1.0);
 698.183 +	glMatrixMode(GL_MODELVIEW);
 698.184 +	glLoadIdentity();
 698.185 +
 698.186 +	systemRedShift      = 3;
 698.187 +	systemGreenShift    = 11;
 698.188 +	systemBlueShift     = 19;
 698.189 +	systemColorDepth    = 32;
 698.190 +	theApp.fsColorDepth = 32;
 698.191 +
 698.192 +	Init_2xSaI(32);
 698.193 +#ifdef MMX
 698.194 +	if (!theApp.disableMMX)
 698.195 +		cpu_mmx = theApp.detectMMX();
 698.196 +	else
 698.197 +		cpu_mmx = 0;
 698.198 +#endif
 698.199 +
 698.200 +	if (theApp.ddrawDebug)
 698.201 +	{
 698.202 +		winlog("R shift: %d\n", systemRedShift);
 698.203 +		winlog("G shift: %d\n", systemGreenShift);
 698.204 +		winlog("B shift: %d\n", systemBlueShift);
 698.205 +	}
 698.206 +
 698.207 +	switch (systemColorDepth)
 698.208 +	{
 698.209 +	case 16:
 698.210 +	{
 698.211 +		for (int i = 0; i < 0x10000; i++)
 698.212 +		{
 698.213 +			systemColorMap16[i] = ((i & 0x1f) << systemRedShift) |
 698.214 +			                      (((i & 0x3e0) >> 5) << systemGreenShift) |
 698.215 +			                      (((i & 0x7c00) >> 10) << systemBlueShift);
 698.216 +		}
 698.217 +		break;
 698.218 +	}
 698.219 +	case 24:
 698.220 +	case 32:
 698.221 +	{
 698.222 +		for (int i = 0; i < 0x10000; i++)
 698.223 +		{
 698.224 +			systemColorMap32[i] = ((i & 0x1f) << systemRedShift) |
 698.225 +			                      (((i & 0x3e0) >> 5) << systemGreenShift) |
 698.226 +			                      (((i & 0x7c00) >> 10) << systemBlueShift);
 698.227 +		}
 698.228 +		break;
 698.229 +	}
 698.230 +	}
 698.231 +	theApp.updateFilter();
 698.232 +	theApp.updateIFB();
 698.233 +
 698.234 +	if (failed)
 698.235 +		return false;
 698.236 +
 698.237 +	pWnd->DragAcceptFiles(TRUE);
 698.238 +
 698.239 +	return TRUE;
 698.240 +}
 698.241 +
 698.242 +void OpenGLDisplay::clear()
 698.243 +{}
 698.244 +
 698.245 +void OpenGLDisplay::renderMenu()
 698.246 +{
 698.247 +	checkFullScreen();
 698.248 +	if (theApp.m_pMainWnd)
 698.249 +		theApp.m_pMainWnd->DrawMenuBar();
 698.250 +}
 698.251 +
 698.252 +void OpenGLDisplay::checkFullScreen()
 698.253 +{
 698.254 +	//  if(tripleBuffering)
 698.255 +	//    pOpenGL->FlipToGDISurface();
 698.256 +}
 698.257 +
 698.258 +void OpenGLDisplay::render()
 698.259 +{
 698.260 +	void (*filterFunction)(u8 *, u32, u8 *, u8 *, u32, int, int) = theApp.filterFunction;
 698.261 +	int  filterWidth = theApp.filterWidth, filterHeight = theApp.filterHeight;
 698.262 +/*
 698.263 +    if(textMethod == 1)
 698.264 +    {
 698.265 +        int copyX = 240, copyY = 160;
 698.266 +        if(systemCartridgeType == 1)
 698.267 +            if(gbBorderOn) copyX = 256, copyY = 224;
 698.268 +            else           copyX = 160, copyY = 144;
 698.269 +
 698.270 +        extern void Simple1x(u8*,u32,u8*,u8*,u32,int,int);
 698.271 +        filterFunction = Simple1x;
 698.272 +        filterWidth = copyX;
 698.273 +        filterHeight = copyY;
 698.274 +    }
 698.275 + */
 698.276 +	int pitch = filterWidth * 4 + 4;
 698.277 +	u8 *data  = pix + (theApp.sizeX+1)*4;
 698.278 +
 698.279 +	int filterPitch = theApp.rect.right*4;
 698.280 +
 698.281 +/*
 698.282 +	// HACK: see below
 698.283 +	if (textMethod == 1 && !filterFunction)
 698.284 +	{
 698.285 +		textMethod = 0; // must not be after systemMessage!
 698.286 +		systemMessage(
 698.287 +		    0,
 698.288 +		    "The \"On Game\" text display mode does not work with this combination of renderers and filters.\nThe display mode is automatically being changed to \"In Game\" instead,\nbut this may cause message text to go into AVI recordings and screenshots.\nThis can be reconfigured by choosing \"Options->Video->Text Display Options...\"");
 698.289 +	}
 698.290 +*/
 698.291 +
 698.292 +	if (filterFunction)
 698.293 +	{
 698.294 +		data = filterData;
 698.295 +		filterFunction(pix + pitch,
 698.296 +		               pitch,
 698.297 +		               (u8 *)theApp.delta,
 698.298 +		               (u8 *)filterData,
 698.299 +		               filterPitch,
 698.300 +		               filterWidth,
 698.301 +		               filterHeight);
 698.302 +	}
 698.303 +
 698.304 +	if (theApp.showSpeed && theApp.videoOption > VIDEO_4X)
 698.305 +	{
 698.306 +		char buffer[30];
 698.307 +		if (theApp.showSpeed == 1)
 698.308 +			sprintf(buffer, "%3d%%", systemSpeed);
 698.309 +		else
 698.310 +			sprintf(buffer, "%3d%%(%d, %d fps)", systemSpeed,
 698.311 +			        systemFrameSkip,
 698.312 +			        theApp.showRenderedFrames);
 698.313 +
 698.314 +		if (filterFunction)
 698.315 +		{
 698.316 +			if (theApp.showSpeedTransparent)
 698.317 +				drawTextTransp((u8 *)filterData,
 698.318 +				               filterPitch,
 698.319 +				               theApp.rect.left+10,
 698.320 +				               theApp.rect.bottom-10,
 698.321 +				               buffer);
 698.322 +			else
 698.323 +				drawText((u8 *)filterData,
 698.324 +				         filterPitch,
 698.325 +			             theApp.rect.left+10,
 698.326 +			             theApp.rect.bottom-10,
 698.327 +				         buffer);
 698.328 +		}
 698.329 +		else
 698.330 +		{
 698.331 +			if (theApp.showSpeedTransparent)
 698.332 +				drawTextTransp((u8 *)pix,
 698.333 +				               pitch,
 698.334 +				               theApp.rect.left+10,
 698.335 +				               theApp.rect.bottom-10,
 698.336 +				               buffer);
 698.337 +			else
 698.338 +				drawText((u8 *)pix,
 698.339 +				         pitch,
 698.340 +			             theApp.rect.left+10,
 698.341 +			             theApp.rect.bottom-10,
 698.342 +				         buffer);
 698.343 +		}
 698.344 +	}
 698.345 +
 698.346 +	if (textMethod == 1 && filterFunction)
 698.347 +	{
 698.348 +		DrawTextMessages((u8 *)filterData, filterPitch, theApp.rect.left, theApp.rect.bottom);
 698.349 +	}
 698.350 +
 698.351 +	// Texturemap complete texture to surface so we have free scaling
 698.352 +	// and antialiasing
 698.353 +	if (filterFunction)
 698.354 +	{
 698.355 +		glPixelStorei(GL_UNPACK_ROW_LENGTH, theApp.rect.right);
 698.356 +	}
 698.357 +	else
 698.358 +	{
 698.359 +		glPixelStorei(GL_UNPACK_ROW_LENGTH, theApp.sizeX+1);
 698.360 +	}
 698.361 +
 698.362 +	glTexSubImage2D(GL_TEXTURE_2D, 0,
 698.363 +					0, 0, theApp.rect.right, theApp.rect.bottom,
 698.364 +	                GL_RGBA, GL_UNSIGNED_BYTE, data);
 698.365 +
 698.366 +	if (theApp.glType == 0)
 698.367 +	{
 698.368 +		glBegin(GL_TRIANGLE_STRIP);
 698.369 +		glTexCoord2f(0.0, 0.0); glVertex3i(0, 0, 0);
 698.370 +		glTexCoord2f(theApp.rect.right/size, 0.0); glVertex3i(theApp.surfaceSizeX, 0, 0);
 698.371 +		glTexCoord2f(0.0, theApp.rect.bottom/size); glVertex3i(0, theApp.surfaceSizeY, 0);
 698.372 +		glTexCoord2f(theApp.rect.right/size, theApp.rect.bottom/size); glVertex3i(theApp.surfaceSizeX, theApp.surfaceSizeY, 0);
 698.373 +		glEnd();
 698.374 +	}
 698.375 +	else
 698.376 +	{
 698.377 +		glBegin(GL_QUADS);
 698.378 +		glTexCoord2f(0.0, 0.0); glVertex3i(0, 0, 0);
 698.379 +		glTexCoord2f(theApp.rect.right/size, 0.0); glVertex3i(theApp.surfaceSizeX, 0, 0);
 698.380 +		glTexCoord2f(theApp.rect.right/size, theApp.rect.bottom/size); glVertex3i(theApp.surfaceSizeX, theApp.surfaceSizeY, 0);
 698.381 +		glTexCoord2f(0.0, theApp.rect.bottom/size); glVertex3i(0, theApp.surfaceSizeY, 0);
 698.382 +		glEnd();
 698.383 +	}
 698.384 +
 698.385 +	CDC *dc = theApp.m_pMainWnd->GetDC();
 698.386 +
 698.387 +	if (textMethod == 2 || (textMethod == 1 && !filterFunction)) // HACK: so that textMethod isn't changed
 698.388 +	{
 698.389 +		for (int slot = 0; slot < SCREEN_MESSAGE_SLOTS; slot++)
 698.390 +		{
 698.391 +			if (theApp.screenMessage[slot])
 698.392 +			{
 698.393 +				if ((theApp.screenMessageDuration[slot] < 0 || 
 698.394 +					(int)(GetTickCount() - theApp.screenMessageTime[slot]) < theApp.screenMessageDuration[slot]) &&
 698.395 +				    (!theApp.disableStatusMessage || slot == 1 || slot == 2))
 698.396 +				{
 698.397 +					dc->SetBkMode(TRANSPARENT);
 698.398 +
 698.399 +					if (outlinedText)
 698.400 +					{
 698.401 +						dc->SetTextColor(textColor != 7 ? RGB(0, 0, 0) : RGB(255, 255, 255));
 698.402 +						// draw black outline
 698.403 +						const static int xd [8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 698.404 +						const static int yd [8] = {-1, -1, -1, 0, 1, 1, 1, 0};
 698.405 +						for (int i = 0; i < 8; i++)
 698.406 +						{
 698.407 +							dc->TextOut(10+xd[i], theApp.surfaceSizeY - 20*(slot+1)+yd[i], theApp.screenMessageBuffer[slot]);
 698.408 +						}
 698.409 +					}
 698.410 +
 698.411 +					COLORREF color;
 698.412 +					switch (textColor)
 698.413 +					{
 698.414 +					case 0:
 698.415 +						color = RGB(255, 255, 255); break;
 698.416 +					case 1:
 698.417 +						color = RGB(255, 0, 0); break;
 698.418 +					case 2:
 698.419 +						color = RGB(255, 255, 0); break;
 698.420 +					case 3:
 698.421 +						color = RGB(0, 255, 0); break;
 698.422 +					case 4:
 698.423 +						color = RGB(0, 255, 255); break;
 698.424 +					case 5:
 698.425 +						color = RGB(0, 0, 255); break;
 698.426 +					case 6:
 698.427 +						color = RGB(255, 0, 255); break;
 698.428 +					case 7:
 698.429 +						color = RGB(0, 0, 0); break;
 698.430 +					}
 698.431 +					dc->SetTextColor(color);
 698.432 +
 698.433 +					// draw center text
 698.434 +					dc->TextOut(10, theApp.surfaceSizeY - 20*(slot+1), theApp.screenMessageBuffer[slot]);
 698.435 +				}
 698.436 +				else
 698.437 +				{
 698.438 +					theApp.screenMessage[slot] = false;
 698.439 +				}
 698.440 +			}
 698.441 +		}
 698.442 +	}
 698.443 +
 698.444 +	SwapBuffers(dc->GetSafeHdc());
 698.445 +
 698.446 +	theApp.m_pMainWnd->ReleaseDC(dc);
 698.447 +}
 698.448 +
 698.449 +void OpenGLDisplay::resize(int w, int h)
 698.450 +{
 698.451 +	glViewport(0, 0, w, h);
 698.452 +	glMatrixMode(GL_PROJECTION);
 698.453 +	glLoadIdentity();
 698.454 +
 698.455 +	glOrtho(0.0, (GLdouble)(w), (GLdouble)(h), 0.0, 0.0, 1.0);
 698.456 +	glMatrixMode(GL_MODELVIEW);
 698.457 +	glLoadIdentity();
 698.458 +}
 698.459 +
 698.460 +void OpenGLDisplay::updateFiltering(int value)
 698.461 +{
 698.462 +	switch (value)
 698.463 +	{
 698.464 +	case 0:
 698.465 +		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 698.466 +		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 698.467 +		break;
 698.468 +	case 1:
 698.469 +		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 698.470 +		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 698.471 +		break;
 698.472 +	}
 698.473 +}
 698.474 +
 698.475 +bool OpenGLDisplay::initializeTexture(int w, int h)
 698.476 +{
 698.477 +	int mySize = 256;
 698.478 +	size = 256.0f;
 698.479 +	if (w > 511 || h > 511)
 698.480 +	{
 698.481 +		size   = 1024.0f;
 698.482 +		mySize = 1024;
 698.483 +	}
 698.484 +	else if (w > 255 || h > 255)
 698.485 +	{
 698.486 +		size   = 512.0f;
 698.487 +		mySize = 512;
 698.488 +	}
 698.489 +	glGenTextures(1, &texture);
 698.490 +	glBindTexture(GL_TEXTURE_2D, texture);
 698.491 +
 698.492 +	int filter = regQueryDwordValue("glFilter", 0);
 698.493 +	if (filter < 0 || filter > 1)
 698.494 +		filter = 0;
 698.495 +	updateFiltering(filter);
 698.496 +
 698.497 +	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mySize, mySize, 0, GL_RGBA,
 698.498 +	             GL_UNSIGNED_BYTE, NULL);
 698.499 +	width  = w;
 698.500 +	height = h;
 698.501 +
 698.502 +	return true;
 698.503 +}
 698.504 +
 698.505 +bool OpenGLDisplay::changeRenderSize(int w, int h)
 698.506 +{
 698.507 +	if (width != w || height != h)
 698.508 +	{
 698.509 +		if (texture != 0)
 698.510 +		{
 698.511 +			glDeleteTextures(1, &texture);
 698.512 +			texture = 0;
 698.513 +		}
 698.514 +		if (!initializeTexture(w, h))
 698.515 +		{
 698.516 +			failed = true;
 698.517 +			return false;
 698.518 +		}
 698.519 +	}
 698.520 +	return true;
 698.521 +}
 698.522 +
 698.523 +void OpenGLDisplay::setOption(const char *option, int value)
 698.524 +{
 698.525 +	if (!strcmp(option, "glFilter"))
 698.526 +		updateFiltering(value);
 698.527 +}
 698.528 +
 698.529 +int OpenGLDisplay::selectFullScreenMode(GUID * *)
 698.530 +{
 698.531 +	HWND wnd = GetDesktopWindow();
 698.532 +	RECT r;
 698.533 +	GetWindowRect(wnd, &r);
 698.534 +	int w  = (r.right - r.left) & 4095;
 698.535 +	int h  = (r.bottom - r.top) & 4095;
 698.536 +	HDC dc = GetDC(wnd);
 698.537 +	int c  = GetDeviceCaps(dc, BITSPIXEL);
 698.538 +	ReleaseDC(wnd, dc);
 698.539 +
 698.540 +	return (c << 24) | (w << 12) | h;
 698.541 +}
 698.542 +
 698.543 +IDisplay *newOpenGLDisplay()
 698.544 +{
 698.545 +	return new OpenGLDisplay();
 698.546 +}
 698.547 +
   699.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   699.2 +++ b/src/win32/PaletteView.cpp	Sat Mar 03 10:31:27 2012 -0600
   699.3 @@ -0,0 +1,217 @@
   699.4 +// PaletteView.cpp : implementation file
   699.5 +//
   699.6 +
   699.7 +#include "stdafx.h"
   699.8 +#include "FileDlg.h"
   699.9 +#include "PaletteView.h"
  699.10 +#include "WinResUtil.h"
  699.11 +#include "VBA.h" // for theApp
  699.12 +
  699.13 +#include "../gba/GBAGlobals.h"
  699.14 +
  699.15 +void GBAPaletteViewControl::updatePalette()
  699.16 +{
  699.17 +	if (paletteRAM != NULL)
  699.18 +		memcpy(palette, &paletteRAM[paletteAddress], 512);
  699.19 +}
  699.20 +
  699.21 +/////////////////////////////////////////////////////////////////////////////
  699.22 +// PaletteView dialog
  699.23 +
  699.24 +PaletteView::PaletteView(CWnd*pParent /*=NULL*/)
  699.25 +	: ResizeDlg(PaletteView::IDD, pParent)
  699.26 +{
  699.27 +	//{{AFX_DATA_INIT(PaletteView)
  699.28 +	// NOTE: the ClassWizard will add member initialization here
  699.29 +	//}}AFX_DATA_INIT
  699.30 +	autoUpdate = false;
  699.31 +}
  699.32 +
  699.33 +PaletteView::~PaletteView()
  699.34 +{}
  699.35 +
  699.36 +void PaletteView::DoDataExchange(CDataExchange*pDX)
  699.37 +{
  699.38 +	CDialog::DoDataExchange(pDX);
  699.39 +	//{{AFX_DATA_MAP(PaletteView)
  699.40 +	// NOTE: the ClassWizard will add DDX and DDV calls here
  699.41 +	//}}AFX_DATA_MAP
  699.42 +	DDX_Control(pDX, IDC_PALETTE_VIEW, paletteView);
  699.43 +	DDX_Control(pDX, IDC_PALETTE_VIEW_OBJ, paletteViewOBJ);
  699.44 +	DDX_Control(pDX, IDC_COLOR, colorControl);
  699.45 +}
  699.46 +
  699.47 +BEGIN_MESSAGE_MAP(PaletteView, CDialog)
  699.48 +//{{AFX_MSG_MAP(PaletteView)
  699.49 +ON_BN_CLICKED(IDC_SAVE_BG, OnSaveBg)
  699.50 +ON_BN_CLICKED(IDC_SAVE_OBJ, OnSaveObj)
  699.51 +ON_BN_CLICKED(IDC_REFRESH2, OnRefresh2)
  699.52 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
  699.53 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
  699.54 +//}}AFX_MSG_MAP
  699.55 +ON_MESSAGE(WM_PALINFO, OnPalInfo)
  699.56 +END_MESSAGE_MAP()
  699.57 +
  699.58 +/////////////////////////////////////////////////////////////////////////////
  699.59 +// PaletteView message handlers
  699.60 +
  699.61 +BOOL PaletteView::OnInitDialog()
  699.62 +{
  699.63 +	CDialog::OnInitDialog();
  699.64 +
  699.65 +	DIALOG_SIZER_START(sz)
  699.66 +	DIALOG_SIZER_END()
  699.67 +	SetData(sz,
  699.68 +	        FALSE,
  699.69 +	        HKEY_CURRENT_USER,
  699.70 +	        "Software\\Emulators\\VisualBoyAdvance\\Viewer\\PaletteView",
  699.71 +	        NULL);
  699.72 +
  699.73 +	paletteView.setPaletteAddress(0);
  699.74 +	paletteView.refresh();
  699.75 +
  699.76 +	paletteViewOBJ.setPaletteAddress(0x200);
  699.77 +	paletteViewOBJ.refresh();
  699.78 +
  699.79 +	return TRUE; // return TRUE unless you set the focus to a control
  699.80 +	             // EXCEPTION: OCX Property Pages should return FALSE
  699.81 +}
  699.82 +
  699.83 +void PaletteView::save(int which)
  699.84 +{
  699.85 +	CString captureBuffer;
  699.86 +
  699.87 +	if (which == 0)
  699.88 +		captureBuffer = "bg.pal";
  699.89 +	else
  699.90 +		captureBuffer = "obj.pal";
  699.91 +
  699.92 +	LPCTSTR exts[] = {".pal", ".pal", ".act", NULL };
  699.93 +
  699.94 +	CString filter = winResLoadFilter(IDS_FILTER_PAL);
  699.95 +	CString title  = winResLoadString(IDS_SELECT_PALETTE_NAME);
  699.96 +	FileDlg dlg(this,
  699.97 +	            captureBuffer,
  699.98 +	            filter,
  699.99 +	            1,
 699.100 +	            "PAL",
 699.101 +	            exts,
 699.102 +	            "",
 699.103 +	            title,
 699.104 +	            true);
 699.105 +
 699.106 +	if (dlg.DoModal() == IDCANCEL)
 699.107 +	{
 699.108 +		return;
 699.109 +	}
 699.110 +
 699.111 +	PaletteViewControl *p = NULL;
 699.112 +
 699.113 +	if (which == 0)
 699.114 +		p = &paletteView;
 699.115 +	else
 699.116 +		p = &paletteViewOBJ;
 699.117 +
 699.118 +	switch (dlg.getFilterIndex())
 699.119 +	{
 699.120 +	case 0:
 699.121 +	case 1:
 699.122 +		p->saveMSPAL(captureBuffer);
 699.123 +		break;
 699.124 +	case 2:
 699.125 +		p->saveJASCPAL(captureBuffer);
 699.126 +		break;
 699.127 +	case 3:
 699.128 +		p->saveAdobe(captureBuffer);
 699.129 +		break;
 699.130 +	}
 699.131 +}
 699.132 +
 699.133 +void PaletteView::OnSaveBg()
 699.134 +{
 699.135 +	save(0);
 699.136 +}
 699.137 +
 699.138 +void PaletteView::OnSaveObj()
 699.139 +{
 699.140 +	save(1);
 699.141 +}
 699.142 +
 699.143 +void PaletteView::OnRefresh2()
 699.144 +{
 699.145 +	paletteView.refresh();
 699.146 +	paletteViewOBJ.refresh();
 699.147 +}
 699.148 +
 699.149 +void PaletteView::update()
 699.150 +{
 699.151 +	OnRefresh2();
 699.152 +}
 699.153 +
 699.154 +void PaletteView::OnAutoUpdate()
 699.155 +{
 699.156 +	autoUpdate = !autoUpdate;
 699.157 +	if (autoUpdate)
 699.158 +	{
 699.159 +		theApp.winAddUpdateListener(this);
 699.160 +	}
 699.161 +	else
 699.162 +	{
 699.163 +		theApp.winRemoveUpdateListener(this);
 699.164 +	}
 699.165 +}
 699.166 +
 699.167 +void PaletteView::OnClose()
 699.168 +{
 699.169 +	theApp.winRemoveUpdateListener(this);
 699.170 +
 699.171 +	DestroyWindow();
 699.172 +}
 699.173 +
 699.174 +LRESULT PaletteView::OnPalInfo(WPARAM wParam, LPARAM lParam)
 699.175 +{
 699.176 +	u16     color   = (u16)wParam;
 699.177 +	u32     address = (u32)lParam;
 699.178 +	CString buffer;
 699.179 +
 699.180 +	if (address >= 0x200)
 699.181 +		address = 0x5000200 + 2*(address & 255);
 699.182 +	else
 699.183 +		address = 0x5000000 + 2*(address & 255);
 699.184 +
 699.185 +	buffer.Format("0x%08X", address);
 699.186 +	GetDlgItem(IDC_ADDRESS)->SetWindowText(buffer);
 699.187 +
 699.188 +	int r = (color & 0x1f);
 699.189 +	int g = (color & 0x3e0) >> 5;
 699.190 +	int b = (color & 0x7c00) >> 10;
 699.191 +
 699.192 +	buffer.Format("%d", r);
 699.193 +	GetDlgItem(IDC_R)->SetWindowText(buffer);
 699.194 +
 699.195 +	buffer.Format("%d", g);
 699.196 +	GetDlgItem(IDC_G)->SetWindowText(buffer);
 699.197 +
 699.198 +	buffer.Format("%d", b);
 699.199 +	GetDlgItem(IDC_B)->SetWindowText(buffer);
 699.200 +
 699.201 +	buffer.Format("0x%04X", color);
 699.202 +	GetDlgItem(IDC_VALUE)->SetWindowText(buffer);
 699.203 +
 699.204 +	colorControl.setColor(color);
 699.205 +
 699.206 +	if (address >= 0x5000200)
 699.207 +	{
 699.208 +		paletteView.setSelected(-1);
 699.209 +	}
 699.210 +	else
 699.211 +		paletteViewOBJ.setSelected(-1);
 699.212 +
 699.213 +	return TRUE;
 699.214 +}
 699.215 +
 699.216 +void PaletteView::PostNcDestroy()
 699.217 +{
 699.218 +	delete this;
 699.219 +}
 699.220 +
   700.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   700.2 +++ b/src/win32/PaletteView.h	Sat Mar 03 10:31:27 2012 -0600
   700.3 @@ -0,0 +1,73 @@
   700.4 +#if !defined(AFX_PALETTEVIEW1_H__0873E3FF_9486_4B2C_8EF0_59C3B4F47162__INCLUDED_)
   700.5 +#define AFX_PALETTEVIEW1_H__0873E3FF_9486_4B2C_8EF0_59C3B4F47162__INCLUDED_
   700.6 +
   700.7 +#if _MSC_VER > 1000
   700.8 +#pragma once
   700.9 +#endif // _MSC_VER > 1000
  700.10 +// -*- C++ -*-
  700.11 +// PaletteView.h : header file
  700.12 +//
  700.13 +
  700.14 +#include "IUpdate.h"
  700.15 +#include "resource.h"
  700.16 +#include "ResizeDlg.h"
  700.17 +#include "ColorControl.h"
  700.18 +#include "PaletteViewControl.h"
  700.19 +
  700.20 +class GBAPaletteViewControl : public PaletteViewControl
  700.21 +{
  700.22 +public:
  700.23 +	virtual void updatePalette();
  700.24 +};
  700.25 +
  700.26 +/////////////////////////////////////////////////////////////////////////////
  700.27 +// PaletteView dialog
  700.28 +
  700.29 +class PaletteView : public ResizeDlg, IUpdateListener
  700.30 +{
  700.31 +private:
  700.32 +	GBAPaletteViewControl paletteView;
  700.33 +	GBAPaletteViewControl paletteViewOBJ;
  700.34 +	ColorControl colorControl;
  700.35 +	bool         autoUpdate;
  700.36 +	// Construction
  700.37 +public:
  700.38 +	void save(int which);
  700.39 +	PaletteView(CWnd*pParent = NULL);  // standard constructor
  700.40 +	~PaletteView();
  700.41 +	afx_msg LRESULT OnPalInfo(WPARAM wParam, LPARAM lParam);
  700.42 +
  700.43 +	// Dialog Data
  700.44 +	//{{AFX_DATA(PaletteView)
  700.45 +	enum { IDD = IDD_PALETTE_VIEW };
  700.46 +	// NOTE: the ClassWizard will add data members here
  700.47 +	//}}AFX_DATA
  700.48 +
  700.49 +	// Overrides
  700.50 +	// ClassWizard generated virtual function overrides
  700.51 +	//{{AFX_VIRTUAL(PaletteView)
  700.52 +protected:
  700.53 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  700.54 +	virtual void PostNcDestroy();
  700.55 +	//}}AFX_VIRTUAL
  700.56 +
  700.57 +	virtual void update();
  700.58 +
  700.59 +	// Implementation
  700.60 +protected:
  700.61 +	// Generated message map functions
  700.62 +	//{{AFX_MSG(PaletteView)
  700.63 +	virtual BOOL OnInitDialog();
  700.64 +	afx_msg void OnSaveBg();
  700.65 +	afx_msg void OnSaveObj();
  700.66 +	afx_msg void OnRefresh2();
  700.67 +	afx_msg void OnAutoUpdate();
  700.68 +	afx_msg void OnClose();
  700.69 +	//}}AFX_MSG
  700.70 +	DECLARE_MESSAGE_MAP()
  700.71 +};
  700.72 +
  700.73 +//{{AFX_INSERT_LOCATION}}
  700.74 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  700.75 +
  700.76 +#endif // !defined(AFX_PALETTEVIEW1_H__0873E3FF_9486_4B2C_8EF0_59C3B4F47162__INCLUDED_)
   701.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   701.2 +++ b/src/win32/PaletteViewControl.cpp	Sat Mar 03 10:31:27 2012 -0600
   701.3 @@ -0,0 +1,384 @@
   701.4 +// PaletteViewControl.cpp : implementation file
   701.5 +//
   701.6 +
   701.7 +#include "stdafx.h"
   701.8 +#include "PaletteViewControl.h"
   701.9 +
  701.10 +#include "../common/Util.h"
  701.11 +
  701.12 +bool PaletteViewControl::isRegistered = false;
  701.13 +
  701.14 +/////////////////////////////////////////////////////////////////////////////
  701.15 +// PaletteViewControl
  701.16 +
  701.17 +PaletteViewControl::PaletteViewControl()
  701.18 +{
  701.19 +  memset(&bmpInfo.bmiHeader, 0, sizeof(bmpInfo.bmiHeader));
  701.20 +  
  701.21 +  bmpInfo.bmiHeader.biSize = sizeof(bmpInfo.bmiHeader);
  701.22 +  bmpInfo.bmiHeader.biWidth = 256;
  701.23 +  bmpInfo.bmiHeader.biHeight = -256;
  701.24 +  bmpInfo.bmiHeader.biPlanes = 1;
  701.25 +  bmpInfo.bmiHeader.biBitCount = 24;
  701.26 +  bmpInfo.bmiHeader.biCompression = BI_RGB;
  701.27 +  data = (u8 *)malloc(3 * 256 * 256);
  701.28 +
  701.29 +  w = 256;
  701.30 +  h = 256;
  701.31 +
  701.32 +  colors = 256;
  701.33 +
  701.34 +  paletteAddress = 0;
  701.35 +  
  701.36 +  ZeroMemory(palette, 512);
  701.37 +
  701.38 +  selected = -1;
  701.39 +  registerClass();
  701.40 +}
  701.41 +
  701.42 +PaletteViewControl::~PaletteViewControl()
  701.43 +{
  701.44 +  if(data)
  701.45 +    free(data);
  701.46 +}
  701.47 +
  701.48 +
  701.49 +BEGIN_MESSAGE_MAP(PaletteViewControl, CWnd)
  701.50 +  //{{AFX_MSG_MAP(PaletteViewControl)
  701.51 +  ON_WM_LBUTTONDOWN()
  701.52 +  ON_WM_ERASEBKGND()
  701.53 +  ON_WM_PAINT()
  701.54 +  //}}AFX_MSG_MAP
  701.55 +  END_MESSAGE_MAP()
  701.56 +
  701.57 +
  701.58 +  /////////////////////////////////////////////////////////////////////////////
  701.59 +// PaletteViewControl message handlers
  701.60 +
  701.61 +void PaletteViewControl::init(int c, int w, int h)
  701.62 +{
  701.63 +  this->w = w;
  701.64 +  this->h = h;
  701.65 +  this->colors = c;
  701.66 +
  701.67 +  bmpInfo.bmiHeader.biWidth = w;
  701.68 +  bmpInfo.bmiHeader.biHeight = -h;  
  701.69 +}
  701.70 +
  701.71 +
  701.72 +bool PaletteViewControl::saveAdobe(const char *name)
  701.73 +{
  701.74 +  FILE *f = fopen(name, "wb");
  701.75 +
  701.76 +  if(!f)
  701.77 +    return false;
  701.78 +
  701.79 +  for(int i = 0; i < colors; i++) {
  701.80 +    u16 c = palette[i];
  701.81 +    int r = (c & 0x1f) << 3;
  701.82 +    int g = (c & 0x3e0) >> 2;
  701.83 +    int b = (c & 0x7c00) >> 7;
  701.84 +
  701.85 +    u8 data[3] = { r, g, b };
  701.86 +    fwrite(data, 1, 3, f);
  701.87 +  }
  701.88 +  if(colors < 256) {
  701.89 +    for(int i = colors; i < 256; i++) {
  701.90 +      u8 data[3] = { 0, 0, 0 };
  701.91 +      fwrite(data, 1, 3, f);
  701.92 +    }
  701.93 +  }
  701.94 +  fclose(f);
  701.95 +
  701.96 +  return true;
  701.97 +}
  701.98 +
  701.99 +
 701.100 +bool PaletteViewControl::saveMSPAL(const char *name)
 701.101 +{
 701.102 +  FILE *f = fopen(name, "wb");
 701.103 +
 701.104 +  if(!f)
 701.105 +    return false;
 701.106 +
 701.107 +  u8 data[4] = { 'R', 'I', 'F', 'F' };
 701.108 +
 701.109 +  fwrite(data, 1, 4, f);
 701.110 +  utilPutDword(data, 256 * 4 + 16);
 701.111 +  fwrite(data, 1, 4, f);
 701.112 +  u8 data3[4] = { 'P', 'A', 'L', ' ' };
 701.113 +  fwrite(data3, 1, 4, f);
 701.114 +  u8 data4[4] = { 'd', 'a', 't', 'a' };
 701.115 +  fwrite(data4, 1, 4, f);
 701.116 +  utilPutDword(data, 256*4+4);
 701.117 +  fwrite(data, 1, 4, f);
 701.118 +  utilPutWord(&data[0], 0x0300);
 701.119 +  utilPutWord(&data[2], 256); // causes problems if not 16 or 256
 701.120 +  fwrite(data, 1, 4, f);
 701.121 +  
 701.122 +  for(int i = 0; i < colors; i++) {
 701.123 +    u16 c = palette[i];
 701.124 +    int r = (c & 0x1f) << 3;
 701.125 +    int g = (c & 0x3e0) >> 2;
 701.126 +    int b = (c & 0x7c00) >> 7;
 701.127 +
 701.128 +    u8 data7[4] = { r, g, b, 0 };
 701.129 +    fwrite(data7, 1, 4, f);
 701.130 +  }
 701.131 +  if(colors < 256) {
 701.132 +    for(int i = colors; i < 256; i++) {
 701.133 +      u8 data7[4] = { 0, 0, 0, 0 };
 701.134 +      fwrite(data7, 1, 4, f);
 701.135 +    }
 701.136 +  }
 701.137 +  fclose(f);
 701.138 +
 701.139 +  return true;
 701.140 +}
 701.141 +
 701.142 +
 701.143 +bool PaletteViewControl::saveJASCPAL(const char *name)
 701.144 +{
 701.145 +  FILE *f = fopen(name, "wb");
 701.146 +
 701.147 +  if(!f)
 701.148 +    return false;
 701.149 +
 701.150 +  fprintf(f, "JASC-PAL\r\n0100\r\n256\r\n");
 701.151 +  
 701.152 +  for(int i = 0; i < colors; i++) {
 701.153 +    u16 c = palette[i];
 701.154 +    int r = (c & 0x1f) << 3;
 701.155 +    int g = (c & 0x3e0) >> 2;
 701.156 +    int b = (c & 0x7c00) >> 7;
 701.157 +
 701.158 +    fprintf(f, "%d %d %d\r\n", r, g, b);
 701.159 +  }
 701.160 +  if(colors < 256) {
 701.161 +    for(int i = colors; i < 256; i++)
 701.162 +      fprintf(f, "0 0 0\r\n");
 701.163 +  }
 701.164 +  fclose(f);
 701.165 +
 701.166 +  return true;  
 701.167 +}
 701.168 +
 701.169 +void PaletteViewControl::setPaletteAddress(int address)
 701.170 +{
 701.171 +  paletteAddress = address;
 701.172 +}
 701.173 +
 701.174 +
 701.175 +void PaletteViewControl::setSelected(int s)
 701.176 +{
 701.177 +  selected = s;
 701.178 +  InvalidateRect(NULL, FALSE);
 701.179 +}
 701.180 +
 701.181 +
 701.182 +void PaletteViewControl::render(u16 color, int x, int y)
 701.183 +{
 701.184 +  u8 *start = data + y*16*w*3 + x*16*3;
 701.185 +  int skip = w*3-16*3;
 701.186 +
 701.187 +  int r = (color & 0x1f) << 3;
 701.188 +  int g = (color & 0x3e0) >> 2;
 701.189 +  int b = (color & 0x7c00) >> 7;
 701.190 +
 701.191 +  for(int i = 0; i < 16; i++) {
 701.192 +    *start++ = b;
 701.193 +    *start++ = g;
 701.194 +    *start++ = r;
 701.195 +
 701.196 +    *start++ = b;
 701.197 +    *start++ = g;
 701.198 +    *start++ = r;
 701.199 +
 701.200 +    *start++ = b;
 701.201 +    *start++ = g;
 701.202 +    *start++ = r;
 701.203 +
 701.204 +    *start++ = b;
 701.205 +    *start++ = g;
 701.206 +    *start++ = r;
 701.207 +
 701.208 +    *start++ = b;
 701.209 +    *start++ = g;
 701.210 +    *start++ = r;
 701.211 +
 701.212 +    *start++ = b;
 701.213 +    *start++ = g;
 701.214 +    *start++ = r;
 701.215 +
 701.216 +    *start++ = b;
 701.217 +    *start++ = g;
 701.218 +    *start++ = r;
 701.219 +
 701.220 +    *start++ = b;
 701.221 +    *start++ = g;
 701.222 +    *start++ = r;
 701.223 +
 701.224 +    *start++ = b;
 701.225 +    *start++ = g;
 701.226 +    *start++ = r;
 701.227 +
 701.228 +    *start++ = b;
 701.229 +    *start++ = g;
 701.230 +    *start++ = r;
 701.231 +
 701.232 +    *start++ = b;
 701.233 +    *start++ = g;
 701.234 +    *start++ = r;
 701.235 +
 701.236 +    *start++ = b;
 701.237 +    *start++ = g;
 701.238 +    *start++ = r;
 701.239 +
 701.240 +    *start++ = b;
 701.241 +    *start++ = g;
 701.242 +    *start++ = r;
 701.243 +
 701.244 +    *start++ = b;
 701.245 +    *start++ = g;
 701.246 +    *start++ = r;
 701.247 +
 701.248 +    *start++ = b;
 701.249 +    *start++ = g;
 701.250 +    *start++ = r;
 701.251 +
 701.252 +    *start++ = b;
 701.253 +    *start++ = g;
 701.254 +    *start++ = r;
 701.255 +    
 701.256 +    start += skip;
 701.257 +  }
 701.258 +}
 701.259 +
 701.260 +void PaletteViewControl::refresh()
 701.261 +{
 701.262 +  updatePalette();
 701.263 +  int sw = w/16;
 701.264 +  int sh = h/16;
 701.265 +  for(int i = 0; i < colors; i++) {
 701.266 +    render(palette[i], i & (sw-1), i/sw);
 701.267 +  }
 701.268 +  InvalidateRect(NULL, FALSE);
 701.269 +}
 701.270 +
 701.271 +void PaletteViewControl::OnLButtonDown(UINT nFlags, CPoint point) 
 701.272 +{
 701.273 +  int x = point.x;
 701.274 +  int y = point.y;
 701.275 +  RECT rect;
 701.276 +  GetClientRect(&rect);
 701.277 +  int h = rect.bottom - rect.top;
 701.278 +  int w = rect.right - rect.left;
 701.279 +  int sw = (this->w/16);
 701.280 +  int sh = (this->h/16);
 701.281 +  int mult = w / sw;
 701.282 +  int multY = h / sh;
 701.283 +
 701.284 +  setSelected(x/mult + (y/multY)*sw);
 701.285 +  
 701.286 +  GetParent()->SendMessage(WM_PALINFO,
 701.287 +                           palette[x/mult+(y/multY)*sw],
 701.288 +                           paletteAddress+(x/mult+(y/multY)*sw));
 701.289 +}
 701.290 +
 701.291 +BOOL PaletteViewControl::OnEraseBkgnd(CDC* pDC) 
 701.292 +{
 701.293 +  return TRUE;
 701.294 +}
 701.295 +
 701.296 +
 701.297 +void PaletteViewControl::OnPaint() 
 701.298 +{
 701.299 +  CPaintDC dc(this); // device context for painting
 701.300 +  
 701.301 +  RECT rect;
 701.302 +  GetClientRect(&rect);
 701.303 +  int w = rect.right - rect.left;
 701.304 +  int h = rect.bottom - rect.top;
 701.305 +  
 701.306 +  CDC memDC;
 701.307 +  memDC.CreateCompatibleDC(&dc);
 701.308 +  CBitmap bitmap, *pOldBitmap;
 701.309 +  bitmap.CreateCompatibleBitmap(&dc, w, h);
 701.310 +  pOldBitmap = memDC.SelectObject(&bitmap);
 701.311 +  
 701.312 +  StretchDIBits(memDC.GetSafeHdc(),
 701.313 +                0,
 701.314 +                0,
 701.315 +                w,
 701.316 +                h,
 701.317 +                0,
 701.318 +                0,
 701.319 +                this->w,
 701.320 +                this->h,
 701.321 +                data,
 701.322 +                &bmpInfo,
 701.323 +                DIB_RGB_COLORS,
 701.324 +                SRCCOPY);
 701.325 +  int sw = this->w / 16;
 701.326 +  int sh = this->h / 16;
 701.327 +  int mult  = w / sw;
 701.328 +  int multY = h / sh;
 701.329 +  CPen pen;
 701.330 +  pen.CreatePen(PS_SOLID, 1, RGB(192,192,192));
 701.331 +  CPen *old = memDC.SelectObject(&pen);
 701.332 +  int i;
 701.333 +  for(i = 1; i < sh; i++) {
 701.334 +    memDC.MoveTo(0, i * multY);
 701.335 +    memDC.LineTo(w, i * multY);
 701.336 +  }
 701.337 +  for(i = 1; i < sw; i++) {
 701.338 +    memDC.MoveTo(i * mult, 0);
 701.339 +    memDC.LineTo(i * mult, h);
 701.340 +  }
 701.341 +  memDC.DrawEdge(&rect, EDGE_SUNKEN, BF_RECT);
 701.342 +  memDC.SelectObject(old);
 701.343 +  pen.DeleteObject();
 701.344 +
 701.345 +  if(selected != -1) {
 701.346 +    pen.CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
 701.347 +    old = memDC.SelectObject(&pen);
 701.348 +
 701.349 +    int startX = (selected & (sw-1))*mult+1;
 701.350 +    int startY = (selected / sw)*multY+1;
 701.351 +    int endX = startX + mult-2;
 701.352 +    int endY = startY + multY-2;
 701.353 +    
 701.354 +    memDC.MoveTo(startX, startY);
 701.355 +    memDC.LineTo(endX, startY);
 701.356 +    memDC.LineTo(endX, endY);
 701.357 +    memDC.LineTo(startX, endY);
 701.358 +    memDC.LineTo(startX, startY-1);
 701.359 +
 701.360 +    memDC.SelectObject(old);
 701.361 +    pen.DeleteObject();
 701.362 +  }
 701.363 +  
 701.364 +  dc.BitBlt(0,0,w,h,
 701.365 +            &memDC,0,0,SRCCOPY);
 701.366 +
 701.367 +  memDC.SelectObject(pOldBitmap);
 701.368 +  bitmap.DeleteObject();
 701.369 +  memDC.DeleteDC();
 701.370 +}
 701.371 +
 701.372 +void PaletteViewControl::registerClass()
 701.373 +{
 701.374 +  if(!isRegistered) {
 701.375 +    WNDCLASS wc;
 701.376 +    ZeroMemory(&wc, sizeof(wc));
 701.377 +    wc.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
 701.378 +    wc.lpfnWndProc = (WNDPROC)::DefWindowProc;
 701.379 +    wc.hInstance = AfxGetInstanceHandle();
 701.380 +    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
 701.381 +    wc.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH);
 701.382 +    wc.lpszMenuName = NULL;
 701.383 +    wc.lpszClassName = "VbaPaletteViewControl";
 701.384 +    AfxRegisterClass(&wc);
 701.385 +    isRegistered = true;
 701.386 +  }
 701.387 +}
   702.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   702.2 +++ b/src/win32/PaletteViewControl.h	Sat Mar 03 10:31:27 2012 -0600
   702.3 @@ -0,0 +1,71 @@
   702.4 +#if !defined(AFX_PALETTEVIEWCONTROL_H__31F600AE_B7E5_4F6C_80B6_55E4B61FBD57__INCLUDED_)
   702.5 +#define AFX_PALETTEVIEWCONTROL_H__31F600AE_B7E5_4F6C_80B6_55E4B61FBD57__INCLUDED_
   702.6 +
   702.7 +#if _MSC_VER > 1000
   702.8 +#pragma once
   702.9 +#endif // _MSC_VER > 1000
  702.10 +// PaletteViewControl.h : header file
  702.11 +//
  702.12 +#define WM_PALINFO WM_APP+1
  702.13 +
  702.14 +/////////////////////////////////////////////////////////////////////////////
  702.15 +// PaletteViewControl window
  702.16 +
  702.17 +class PaletteViewControl : public CWnd
  702.18 +{
  702.19 +  int w;
  702.20 +  int h;
  702.21 +  int colors;
  702.22 +  u8 *data;
  702.23 +  BITMAPINFO bmpInfo;
  702.24 +  static bool isRegistered;
  702.25 +  int selected;
  702.26 + protected:
  702.27 +  u16 palette[256];
  702.28 +  int paletteAddress;  
  702.29 +  // Construction
  702.30 + public:
  702.31 +  PaletteViewControl();
  702.32 +
  702.33 +  virtual void updatePalette()=0;
  702.34 +
  702.35 +  // Attributes
  702.36 + public:
  702.37 +
  702.38 +  // Operations
  702.39 + public:
  702.40 +
  702.41 +  // Overrides
  702.42 +  // ClassWizard generated virtual function overrides
  702.43 +  //{{AFX_VIRTUAL(PaletteViewControl)
  702.44 +  //}}AFX_VIRTUAL
  702.45 +
  702.46 +  // Implementation
  702.47 + public:
  702.48 +  void registerClass();
  702.49 +  void refresh();
  702.50 +  void render(u16 color, int x, int y);
  702.51 +  void setSelected(int s);
  702.52 +  void setPaletteAddress(int address);
  702.53 +  bool saveJASCPAL(const char *name);
  702.54 +  bool saveMSPAL(const char *name);
  702.55 +  bool saveAdobe(const char *name);
  702.56 +  void init(int c, int w, int h);
  702.57 +  virtual ~PaletteViewControl();
  702.58 +
  702.59 +  // Generated message map functions
  702.60 + protected:
  702.61 +  //{{AFX_MSG(PaletteViewControl)
  702.62 +  afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  702.63 +  afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  702.64 +  afx_msg void OnPaint();
  702.65 +  //}}AFX_MSG
  702.66 +  DECLARE_MESSAGE_MAP()
  702.67 +    };
  702.68 +
  702.69 +    /////////////////////////////////////////////////////////////////////////////
  702.70 +
  702.71 +//{{AFX_INSERT_LOCATION}}
  702.72 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  702.73 +
  702.74 +#endif // !defined(AFX_PALETTEVIEWCONTROL_H__31F600AE_B7E5_4F6C_80B6_55E4B61FBD57__INCLUDED_)
   703.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   703.2 +++ b/src/win32/PerfTimer.cpp	Sat Mar 03 10:31:27 2012 -0600
   703.3 @@ -0,0 +1,35 @@
   703.4 +// CPerfTimer - a simple Win32 performance counter wrapper
   703.5 +// by Dean Wyant dwyant@mindspring.com
   703.6 +
   703.7 +#include "stdafx.h"
   703.8 +#include "PerfTimer.h"
   703.9 +
  703.10 +// Declare and initialize static member vars that get set only once and never change
  703.11 +__int64 CPerfTimer::m_Freq = 0; 
  703.12 +__int64 CPerfTimer::m_Adjust = 0; 
  703.13 +
  703.14 +// All functions defined inline for speed. After all, the performance counter is 
  703.15 +// supposed to be able to time very short events fairly accurately.
  703.16 +
  703.17 +
  703.18 +
  703.19 +BOOL CPerfTimer::IsSupported()
  703.20 +{ // Returns FALSE if performance counter not supported.
  703.21 +	// Call after constructing at least one CPerfTimer
  703.22 +	return (m_Freq > 1);
  703.23 +}
  703.24 +
  703.25 +const double CPerfTimer::Resolution()   
  703.26 +{ // Returns timer resolution in seconds
  703.27 +	return 1.0/(double)m_Freq; 
  703.28 +}
  703.29 +
  703.30 +const double CPerfTimer::Resolutionms() 
  703.31 +{ // Returns timer resolution in milliseconds
  703.32 +	return 1000.0/(double)m_Freq; 
  703.33 +}
  703.34 +
  703.35 +const double CPerfTimer::Resolutionus() 
  703.36 +{ // Returns timer resolution in microseconds
  703.37 +	return 1000000.0/(double)m_Freq; 
  703.38 +}
   704.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   704.2 +++ b/src/win32/PerfTimer.h	Sat Mar 03 10:31:27 2012 -0600
   704.3 @@ -0,0 +1,403 @@
   704.4 +// CPerfTimer - a simple Win32 performance counter wrapper
   704.5 +// by Dean Wyant dwyant@mindspring.com
   704.6 +
   704.7 +/*
   704.8 +
   704.9 +This class is simple to use. Just declare a variable(s) as type CPerfTimer,
  704.10 +call Start() to start timimg and call Stop() to stop timimg. You can pause a
  704.11 +timer by calling Stop() and then you can call Start() to resume. Retrieve the
  704.12 +elapsed time by calling an Elapsed..() function. Assignment, addition, 
  704.13 +subtraction and comparison are supported. There are a few information calls
  704.14 +available also. All calls except Start and Stop can be performed on a timer
  704.15 +without stopping it.
  704.16 +
  704.17 +*/
  704.18 +
  704.19 +#ifndef __PERFTIMER_H__
  704.20 +#define __PERFTIMER_H__
  704.21 +
  704.22 +class CPerfTimer
  704.23 +{
  704.24 +public:
  704.25 +	CPerfTimer(BOOL bStart = FALSE) {Init(bStart);}
  704.26 +
  704.27 +	CPerfTimer(const CPerfTimer& Src); 
  704.28 +
  704.29 +	virtual ~CPerfTimer() {;}
  704.30 +
  704.31 +	void Start(BOOL bReset = FALSE);   // Start from current value or optionally from 0
  704.32 +	void Stop();                       // Stop timing. Use Start afterwards to continue.
  704.33 +
  704.34 +	BOOL IsRunning();                  // Returns FALSE if stopped.
  704.35 +
  704.36 +	BOOL IsSupported();                // Returns FALSE if performance counter not supported.
  704.37 +	// Call after constructing at least one CPerfTimer
  704.38 +
  704.39 +	const double Resolution();         // Returns timer resolution in seconds
  704.40 +	const double Resolutionms();       // Returns timer resolution in milliseconds
  704.41 +	const double Resolutionus();       // Returns timer resolution in microseconds
  704.42 +
  704.43 +	const double Elapsed();            // Returns elapsed time in seconds
  704.44 +	const double Elapsedms();          // Returns elapsed time in milliseconds 
  704.45 +	const double Elapsedus();          // Returns elapsed time in microseconds
  704.46 +
  704.47 +	const CPerfTimer& operator=(const CPerfTimer& Src); // Assignment operator 
  704.48 +
  704.49 +	// Math operators
  704.50 +	CPerfTimer operator+(const CPerfTimer& Src) const;
  704.51 +	CPerfTimer operator-(const CPerfTimer& Src) const;
  704.52 +	const CPerfTimer& operator+=(const CPerfTimer& Src);
  704.53 +	const CPerfTimer& operator-=(const CPerfTimer& Src);
  704.54 +	// For time in seconds
  704.55 +	CPerfTimer operator+(const double Secs) const;
  704.56 +	CPerfTimer operator-(const double Secs) const;
  704.57 +	const CPerfTimer& operator+=(const double Secs);
  704.58 +	const CPerfTimer& operator-=(const double Secs);
  704.59 +
  704.60 +	// Boolean comparison operators
  704.61 +	BOOL operator<(const CPerfTimer& Src);
  704.62 +	BOOL operator>(const CPerfTimer& Src);
  704.63 +	BOOL operator<=(const CPerfTimer& Src);
  704.64 +	BOOL operator>=(const CPerfTimer& Src);
  704.65 +	// For time in seconds
  704.66 +	BOOL operator<(const double Secs);
  704.67 +	BOOL operator>(const double Secs);
  704.68 +	BOOL operator<=(const double Secs);
  704.69 +	BOOL operator>=(const double Secs);
  704.70 +
  704.71 +	virtual void Lock() const {;}     // Override for thread safe operation
  704.72 +	virtual void Unlock() const {;}     // Override for thread safe operation
  704.73 +protected:
  704.74 +	void Init(BOOL bStart);
  704.75 +	void Copy(const CPerfTimer& Src);
  704.76 +
  704.77 +private:
  704.78 +	__int64 m_Start;
  704.79 +	static __int64 m_Freq;   // does not change while system is running
  704.80 +	static __int64 m_Adjust; // Adjustment time it takes to Start and Stop
  704.81 +};
  704.82 +
  704.83 +class CPerfTimerT : public CPerfTimer
  704.84 +{ // You only need to use types of this class if a timer is going to be shared between threads
  704.85 +public:
  704.86 +	CPerfTimerT(BOOL bStart = FALSE)
  704.87 +	{
  704.88 +		m_hMutex = CreateMutex(NULL,FALSE,"");
  704.89 +		Init(bStart);
  704.90 +	}
  704.91 +
  704.92 +	CPerfTimerT(const CPerfTimerT& Src) 
  704.93 +	{ 
  704.94 +		m_hMutex = CreateMutex(NULL,FALSE,"");
  704.95 +		Copy(Src); 
  704.96 +	}
  704.97 +
  704.98 +	CPerfTimerT(const CPerfTimer& Src) 
  704.99 +	{ 
 704.100 +		m_hMutex = CreateMutex(NULL,FALSE,"");
 704.101 +		Copy(Src); 
 704.102 +	}
 704.103 +
 704.104 +	virtual ~CPerfTimerT() 
 704.105 +	{ CloseHandle(m_hMutex); }
 704.106 +
 704.107 +	const CPerfTimerT& operator=(const CPerfTimerT& Src) // Assignment operator 
 704.108 +	{
 704.109 +		Copy(Src);
 704.110 +		return *this; 
 704.111 +	}
 704.112 +
 704.113 +	virtual void Lock() const { WaitForSingleObject(m_hMutex,10000); }   
 704.114 +	virtual void Unlock() const { ReleaseMutex(m_hMutex); }   
 704.115 +private:
 704.116 +	HANDLE m_hMutex;
 704.117 +};
 704.118 +
 704.119 +inline void CPerfTimer::Init(BOOL bStart)
 704.120 +{
 704.121 +	if (!m_Freq) 
 704.122 +	{ // Initialization should only run once
 704.123 +		QueryPerformanceFrequency((LARGE_INTEGER *)&m_Freq); 
 704.124 +		if (!m_Freq)
 704.125 +			m_Freq = 1; // Timer will be useless but will not cause divide by zero
 704.126 +		m_Start = 0; 
 704.127 +		m_Adjust = 0; 
 704.128 +		Start();            // Time a Stop
 704.129 +		Stop(); 
 704.130 +		m_Adjust = m_Start;
 704.131 +	}
 704.132 +	// This is the only part that normally runs
 704.133 +	m_Start = 0; 
 704.134 +	if (bStart)
 704.135 +		Start(); 
 704.136 +}
 704.137 +
 704.138 +inline CPerfTimer::CPerfTimer(const CPerfTimer& Src)  
 704.139 +{
 704.140 +	Copy(Src);
 704.141 +}
 704.142 +
 704.143 +inline void CPerfTimer::Copy(const CPerfTimer& Src)
 704.144 +{
 704.145 +	if (&Src == this) 
 704.146 +		return; // avoid deadlock if someone tries to copy it to itself
 704.147 +	Src.Lock();
 704.148 +	Lock();
 704.149 +	m_Start = Src.m_Start; 
 704.150 +	Unlock();
 704.151 +	Src.Unlock();
 704.152 +}
 704.153 +
 704.154 +inline void CPerfTimer::Start(BOOL bReset) 
 704.155 +{ // Start from current value or optionally from 0
 704.156 +	__int64 i;
 704.157 +	QueryPerformanceCounter((LARGE_INTEGER *)&i);
 704.158 +	Lock();
 704.159 +	if ((!bReset) && (m_Start < 0))
 704.160 +		m_Start += i;   // We are starting with an accumulated time
 704.161 +	else 
 704.162 +		m_Start = i;    // Starting from 0
 704.163 +	Unlock();
 704.164 +} 
 704.165 +
 704.166 +inline void CPerfTimer::Stop() 
 704.167 +{ // Stop timing. Use Start afterwards to continue
 704.168 +	Lock();
 704.169 +	if (m_Start <= 0)
 704.170 +	{
 704.171 +		Unlock();
 704.172 +		return;          // Was not running
 704.173 +	}
 704.174 +	__int64 i;
 704.175 +	QueryPerformanceCounter((LARGE_INTEGER *)&i); 
 704.176 +	m_Start += -i;          // Stopped timer keeps elapsed timer ticks as a negative 
 704.177 +	if (m_Start < m_Adjust) // Do not overflow
 704.178 +		m_Start -= m_Adjust;  // Adjust for time timer code takes to run
 704.179 +	else 
 704.180 +		m_Start = 0;          // Stop must have been called directly after Start
 704.181 +	Unlock();
 704.182 +} 
 704.183 +
 704.184 +inline BOOL CPerfTimer::IsRunning() 
 704.185 +{ // Returns FALSE if stopped.
 704.186 +	Lock();
 704.187 +	BOOL bRet = (m_Start > 0); // When < 0, holds elpased clicks
 704.188 +	Unlock();
 704.189 +	return bRet;   
 704.190 +}
 704.191 +inline const double CPerfTimer::Elapsed()
 704.192 +{ // Returns elapsed time in seconds
 704.193 +	CPerfTimer Result(*this);
 704.194 +	Result.Stop();
 704.195 +	return (double)(-Result.m_Start)/(double)m_Freq; 
 704.196 +}
 704.197 +
 704.198 +inline const double CPerfTimer::Elapsedms() 
 704.199 +{ // Returns elapsed time in milliseconds
 704.200 +	CPerfTimer Result(*this);
 704.201 +	Result.Stop();
 704.202 +	return (-Result.m_Start*1000.0)/(double)m_Freq; 
 704.203 +}
 704.204 +
 704.205 +inline const double CPerfTimer::Elapsedus() 
 704.206 +{ // Returns elapsed time in microseconds
 704.207 +	CPerfTimer Result(*this);
 704.208 +
 704.209 +	return (-Result.m_Start * 1000000.0)/(double)m_Freq; 
 704.210 +}
 704.211 +
 704.212 +
 704.213 +// Assignment operator
 704.214 +inline const CPerfTimer& CPerfTimer::operator=(const CPerfTimer& Src) 
 704.215 +{
 704.216 +	Copy(Src);
 704.217 +	return *this; 
 704.218 +}
 704.219 +
 704.220 +
 704.221 +// Math operators
 704.222 +inline CPerfTimer CPerfTimer::operator+(const CPerfTimer& Src) const
 704.223 +{
 704.224 +	CPerfTimer Result(*this);
 704.225 +	Result += Src; 
 704.226 +	return Result; 
 704.227 +}
 704.228 +
 704.229 +inline CPerfTimer CPerfTimer::operator-(const CPerfTimer& Src) const
 704.230 +{
 704.231 +	CPerfTimer Result(*this);
 704.232 +	Result -= Src; 
 704.233 +	return Result; 
 704.234 +}
 704.235 +
 704.236 +inline const CPerfTimer& CPerfTimer::operator+=(const CPerfTimer& Src)
 704.237 +{
 704.238 +	CPerfTimer SrcStop(Src);  // Temp is necessary in case Src is not stopped
 704.239 +	SrcStop.Stop();
 704.240 +	Lock();
 704.241 +	m_Start += SrcStop.m_Start;
 704.242 +	Unlock();
 704.243 +	return *this; 
 704.244 +}
 704.245 +
 704.246 +inline const CPerfTimer& CPerfTimer::operator-=(const CPerfTimer& Src)
 704.247 +{
 704.248 +	CPerfTimer SrcStop(Src);  // Temp is necessary in case Src is not stopped
 704.249 +	SrcStop.Stop();
 704.250 +	Lock();
 704.251 +	m_Start -= SrcStop.m_Start; 
 704.252 +	Unlock();
 704.253 +	return *this; 
 704.254 +}
 704.255 +
 704.256 +// For time in seconds
 704.257 +inline CPerfTimer CPerfTimer::operator+(const double Secs) const
 704.258 +{
 704.259 +	CPerfTimer Result(*this);
 704.260 +	Result += Secs; 
 704.261 +	return Result; 
 704.262 +}
 704.263 +
 704.264 +inline CPerfTimer CPerfTimer::operator-(const double Secs) const
 704.265 +{
 704.266 +	CPerfTimer Result(*this);
 704.267 +	Result += Secs; 
 704.268 +	return Result; 
 704.269 +}
 704.270 +
 704.271 +inline const CPerfTimer& CPerfTimer::operator+=(const double Secs)
 704.272 +{
 704.273 +	Lock();
 704.274 +	m_Start -= (__int64)(Secs*(double)m_Freq);
 704.275 +	Unlock();
 704.276 +	return *this; 
 704.277 +}
 704.278 +
 704.279 +inline const CPerfTimer& CPerfTimer::operator-=(const double Secs)
 704.280 +{
 704.281 +	Lock();
 704.282 +	m_Start += (__int64)(Secs*(double)m_Freq);
 704.283 +	Unlock();
 704.284 +	return *this; 
 704.285 +}
 704.286 +
 704.287 +
 704.288 +
 704.289 +// Boolean comparison operators
 704.290 +inline BOOL CPerfTimer::operator<(const CPerfTimer& Src)
 704.291 +{ 
 704.292 +	BOOL bRet; 
 704.293 +	CPerfTimer Temp(Src);
 704.294 +	Lock();
 704.295 +	if (m_Start <= 0)
 704.296 +	{
 704.297 +		Temp.Stop();
 704.298 +		bRet = (m_Start > Temp.m_Start); 
 704.299 +		Unlock();
 704.300 +		return bRet;
 704.301 +	}
 704.302 +	else
 704.303 +		if (Temp.m_Start > 0)
 704.304 +		{
 704.305 +			bRet = (m_Start < Temp.m_Start); 
 704.306 +			Unlock();
 704.307 +			return bRet;
 704.308 +		}
 704.309 +		else
 704.310 +		{
 704.311 +			Unlock();
 704.312 +			CPerfTimer ThisStop(*this);
 704.313 +			ThisStop.Stop();
 704.314 +			return (ThisStop.m_Start > Temp.m_Start); 
 704.315 +		}
 704.316 +}
 704.317 +
 704.318 +inline BOOL CPerfTimer::operator>(const CPerfTimer& Src)
 704.319 +{ 
 704.320 +	BOOL bRet; 
 704.321 +	CPerfTimer Temp(Src);
 704.322 +	Lock();
 704.323 +	if (m_Start <= 0)
 704.324 +	{
 704.325 +		Temp.Stop();
 704.326 +		bRet = (m_Start < Temp.m_Start); 
 704.327 +		Unlock();
 704.328 +		return bRet;
 704.329 +	}
 704.330 +	else
 704.331 +		if (Temp.m_Start > 0)
 704.332 +		{
 704.333 +			bRet = (m_Start > Temp.m_Start); 
 704.334 +			Unlock();
 704.335 +			return bRet;
 704.336 +		}
 704.337 +		else
 704.338 +		{
 704.339 +			Unlock();
 704.340 +			CPerfTimer ThisStop(*this);
 704.341 +			ThisStop.Stop();
 704.342 +			return (ThisStop.m_Start < Temp.m_Start); 
 704.343 +		}
 704.344 +}
 704.345 +
 704.346 +inline BOOL CPerfTimer::operator<=(const CPerfTimer& Src)
 704.347 +{ 
 704.348 +	return !(*this > Src);
 704.349 +}
 704.350 +
 704.351 +inline BOOL CPerfTimer::operator>=(const CPerfTimer& Src)
 704.352 +{ 
 704.353 +	return !(*this < Src);
 704.354 +}
 704.355 +
 704.356 +// For time in seconds
 704.357 +inline BOOL CPerfTimer::operator<(const double Secs)
 704.358 +{ 
 704.359 +	BOOL bRet; 
 704.360 +	Lock();
 704.361 +	if (m_Start <= 0)
 704.362 +	{
 704.363 +		bRet = (m_Start > (__int64)(-Secs*(double)m_Freq)); 
 704.364 +		Unlock();
 704.365 +		return bRet;
 704.366 +	}
 704.367 +	else
 704.368 +	{
 704.369 +		Unlock();
 704.370 +		CPerfTimer ThisStop(*this);
 704.371 +		ThisStop.Stop();
 704.372 +		return (ThisStop.m_Start > (__int64)(-Secs*(double)m_Freq)); 
 704.373 +	}
 704.374 +}
 704.375 +
 704.376 +inline BOOL CPerfTimer::operator>(const double Secs)
 704.377 +{ 
 704.378 +	BOOL bRet; 
 704.379 +	Lock();
 704.380 +	if (m_Start <= 0)
 704.381 +	{
 704.382 +		bRet = (m_Start < (__int64)(-Secs*(double)m_Freq)); 
 704.383 +		Unlock();
 704.384 +		return bRet;
 704.385 +	}
 704.386 +	else
 704.387 +	{
 704.388 +		Unlock();
 704.389 +		CPerfTimer ThisStop(*this);
 704.390 +		ThisStop.Stop();
 704.391 +		return (ThisStop.m_Start < (__int64)(-Secs*(double)m_Freq)); 
 704.392 +	}
 704.393 +}
 704.394 +
 704.395 +inline BOOL CPerfTimer::operator<=(const double Secs)
 704.396 +{ 
 704.397 +	return !(*this > Secs);
 704.398 +}
 704.399 +
 704.400 +inline BOOL CPerfTimer::operator>=(const double Secs)
 704.401 +{ 
 704.402 +	return !(*this < Secs);
 704.403 +}
 704.404 +
 704.405 +
 704.406 +#endif //__PERFTIMER_H__
 704.407 \ No newline at end of file
   705.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   705.2 +++ b/src/win32/Reg.cpp	Sat Mar 03 10:31:27 2012 -0600
   705.3 @@ -0,0 +1,379 @@
   705.4 +#include "stdafx.h"
   705.5 +#include "Reg.h"
   705.6 +
   705.7 +static char    buffer[2048];
   705.8 +static HKEY    vbKey = NULL;
   705.9 +static CString regVbaPath;
  705.10 +
  705.11 +#define VBA_PREF "preferences"
  705.12 +
  705.13 +bool regEnabled = true;
  705.14 +
  705.15 +void regInit(const char *path)
  705.16 +{
  705.17 +	if (regEnabled)
  705.18 +	{
  705.19 +		DWORD disp = 0;
  705.20 +		LONG  res  = RegCreateKeyEx(HKEY_CURRENT_USER,
  705.21 +	                            "Software\\Emulators\\VisualBoyAdvance",
  705.22 +	                            0,
  705.23 +	                            "",
  705.24 +	                            REG_OPTION_NON_VOLATILE,
  705.25 +	                            KEY_ALL_ACCESS,
  705.26 +	                            NULL,
  705.27 +	                            &vbKey,
  705.28 +	                            &disp);
  705.29 +	}
  705.30 +	regVbaPath.Format("%s\\vba.ini", path);
  705.31 +}
  705.32 +
  705.33 +void regShutdown()
  705.34 +{
  705.35 +	LONG res = RegCloseKey(vbKey);
  705.36 +}
  705.37 +
  705.38 +const char *regGetINIPath()
  705.39 +{
  705.40 +	return regVbaPath;
  705.41 +}
  705.42 +
  705.43 +const char *regQueryStringValue(const char *key, const char *def)
  705.44 +{
  705.45 +	if (regEnabled)
  705.46 +	{
  705.47 +		DWORD type = 0;
  705.48 +		DWORD size = 2048;
  705.49 +
  705.50 +		LONG res = RegQueryValueEx(vbKey,
  705.51 +		                           key,
  705.52 +		                           NULL,
  705.53 +		                           &type,
  705.54 +		                           (UCHAR *)buffer,
  705.55 +		                           &size);
  705.56 +
  705.57 +		if (res == ERROR_SUCCESS && type == REG_SZ)
  705.58 +			return buffer;
  705.59 +
  705.60 +		return def;
  705.61 +	}
  705.62 +
  705.63 +	DWORD res = GetPrivateProfileString(VBA_PREF,
  705.64 +	                                    key,
  705.65 +	                                    def,
  705.66 +	                                    (LPTSTR)buffer,
  705.67 +	                                    2048,
  705.68 +	                                    regVbaPath);
  705.69 +
  705.70 +	if (res)
  705.71 +		return buffer;
  705.72 +
  705.73 +	return def;
  705.74 +}
  705.75 +
  705.76 +DWORD regQueryDwordValue(const char *key, DWORD def, bool force)
  705.77 +{
  705.78 +	if (regEnabled || force)
  705.79 +	{
  705.80 +		DWORD type   = 0;
  705.81 +		DWORD size   = sizeof(DWORD);
  705.82 +		DWORD result = 0;
  705.83 +
  705.84 +		LONG res = RegQueryValueEx(vbKey,
  705.85 +		                           key,
  705.86 +		                           NULL,
  705.87 +		                           &type,
  705.88 +		                           (UCHAR *)&result,
  705.89 +		                           &size);
  705.90 +
  705.91 +		if (res == ERROR_SUCCESS && type == REG_DWORD)
  705.92 +			return result;
  705.93 +
  705.94 +		return def;
  705.95 +	}
  705.96 +
  705.97 +	return GetPrivateProfileInt(VBA_PREF,
  705.98 +	                            key,
  705.99 +	                            def,
 705.100 +	                            regVbaPath);
 705.101 +}
 705.102 +
 705.103 +BOOL regQueryBinaryValue(const char *key, char *value, int count)
 705.104 +{
 705.105 +	if (regEnabled)
 705.106 +	{
 705.107 +		DWORD type   = 0;
 705.108 +		DWORD size   = count;
 705.109 +		DWORD result = 0;
 705.110 +
 705.111 +		LONG res = RegQueryValueEx(vbKey,
 705.112 +		                           key,
 705.113 +		                           NULL,
 705.114 +		                           &type,
 705.115 +		                           (UCHAR *)value,
 705.116 +		                           &size);
 705.117 +
 705.118 +		if (res == ERROR_SUCCESS && type == REG_BINARY)
 705.119 +			return TRUE;
 705.120 +
 705.121 +		return FALSE;
 705.122 +	}
 705.123 +	CString k = key;
 705.124 +	k += "Count";
 705.125 +	int size = GetPrivateProfileInt(VBA_PREF,
 705.126 +	                                k,
 705.127 +	                                -1,
 705.128 +	                                regVbaPath);
 705.129 +	if (size >= 0 && size < count)
 705.130 +		count = size;
 705.131 +	return GetPrivateProfileStruct(VBA_PREF,
 705.132 +	                               key,
 705.133 +	                               value,
 705.134 +	                               count,
 705.135 +	                               regVbaPath);
 705.136 +}
 705.137 +
 705.138 +void regSetStringValue(const char *key, const char *value)
 705.139 +{
 705.140 +	if (regEnabled)
 705.141 +	{
 705.142 +		LONG res = RegSetValueEx(vbKey,
 705.143 +		                         key,
 705.144 +		                         NULL,
 705.145 +		                         REG_SZ,
 705.146 +		                         (const UCHAR *)value,
 705.147 +		                         strlen(value)+1);
 705.148 +	}
 705.149 +	else
 705.150 +	{
 705.151 +		WritePrivateProfileString(VBA_PREF,
 705.152 +		                          key,
 705.153 +		                          value,
 705.154 +		                          regVbaPath);
 705.155 +	}
 705.156 +}
 705.157 +
 705.158 +void regSetDwordValue(const char *key, DWORD value, bool force)
 705.159 +{
 705.160 +	if (regEnabled || force)
 705.161 +	{
 705.162 +		LONG res = RegSetValueEx(vbKey,
 705.163 +		                         key,
 705.164 +		                         NULL,
 705.165 +		                         REG_DWORD,
 705.166 +		                         (const UCHAR *)&value,
 705.167 +		                         sizeof(DWORD));
 705.168 +	}
 705.169 +	else
 705.170 +	{
 705.171 +		wsprintf(buffer, "%u", value);
 705.172 +		WritePrivateProfileString(VBA_PREF,
 705.173 +		                          key,
 705.174 +		                          buffer,
 705.175 +		                          regVbaPath);
 705.176 +	}
 705.177 +}
 705.178 +
 705.179 +void regSetBinaryValue(const char *key, char *value, int count)
 705.180 +{
 705.181 +	if (regEnabled)
 705.182 +	{
 705.183 +		LONG res = RegSetValueEx(vbKey,
 705.184 +		                         key,
 705.185 +		                         NULL,
 705.186 +		                         REG_BINARY,
 705.187 +		                         (const UCHAR *)value,
 705.188 +		                         count);
 705.189 +	}
 705.190 +	else
 705.191 +	{
 705.192 +		CString k = key;
 705.193 +		k += "Count";
 705.194 +		wsprintf(buffer, "%u", count);
 705.195 +
 705.196 +		WritePrivateProfileString(VBA_PREF,
 705.197 +		                          k,
 705.198 +		                          buffer,
 705.199 +		                          regVbaPath);
 705.200 +
 705.201 +		WritePrivateProfileStruct(VBA_PREF,
 705.202 +		                          key,
 705.203 +		                          value,
 705.204 +		                          count,
 705.205 +		                          regVbaPath);
 705.206 +	}
 705.207 +}
 705.208 +
 705.209 +void regDeleteValue(const char *key)
 705.210 +{
 705.211 +	if (regEnabled)
 705.212 +	{
 705.213 +		LONG res = RegDeleteValue(vbKey,
 705.214 +		                          key);
 705.215 +	}
 705.216 +	else
 705.217 +	{
 705.218 +		WritePrivateProfileString(VBA_PREF,
 705.219 +		                          key,
 705.220 +		                          NULL,
 705.221 +		                          regVbaPath);
 705.222 +	}
 705.223 +}
 705.224 +
 705.225 +bool regCreateFileType(const char *ext, const char *type)
 705.226 +{
 705.227 +	DWORD disp = 0;
 705.228 +	HKEY  key;
 705.229 +	LONG  res = RegCreateKeyEx(HKEY_CLASSES_ROOT,
 705.230 +	                           ext,
 705.231 +	                           0,
 705.232 +	                           "",
 705.233 +	                           REG_OPTION_NON_VOLATILE,
 705.234 +	                           KEY_ALL_ACCESS,
 705.235 +	                           NULL,
 705.236 +	                           &key,
 705.237 +	                           &disp);
 705.238 +	if (res == ERROR_SUCCESS)
 705.239 +	{
 705.240 +		res = RegSetValueEx(key,
 705.241 +		                    "",
 705.242 +		                    0,
 705.243 +		                    REG_SZ,
 705.244 +		                    (const UCHAR *)type,
 705.245 +		                    strlen(type)+1);
 705.246 +		RegCloseKey(key);
 705.247 +		return true;
 705.248 +	}
 705.249 +	return false;
 705.250 +}
 705.251 +
 705.252 +bool regAssociateType(const char *type, const char *desc, const char *application)
 705.253 +{
 705.254 +	DWORD disp = 0;
 705.255 +	HKEY  key;
 705.256 +	LONG  res = RegCreateKeyEx(HKEY_CLASSES_ROOT,
 705.257 +	                           type,
 705.258 +	                           0,
 705.259 +	                           "",
 705.260 +	                           REG_OPTION_NON_VOLATILE,
 705.261 +	                           KEY_ALL_ACCESS,
 705.262 +	                           NULL,
 705.263 +	                           &key,
 705.264 +	                           &disp);
 705.265 +	if (res == ERROR_SUCCESS)
 705.266 +	{
 705.267 +		res = RegSetValueEx(key,
 705.268 +		                    "",
 705.269 +		                    0,
 705.270 +		                    REG_SZ,
 705.271 +		                    (const UCHAR *)desc,
 705.272 +		                    strlen(desc)+1);
 705.273 +		HKEY key2;
 705.274 +		res = RegCreateKeyEx(key,
 705.275 +		                     "Shell\\Open\\Command",
 705.276 +		                     0,
 705.277 +		                     "",
 705.278 +		                     REG_OPTION_NON_VOLATILE,
 705.279 +		                     KEY_ALL_ACCESS,
 705.280 +		                     NULL,
 705.281 +		                     &key2,
 705.282 +		                     &disp);
 705.283 +		if (res == ERROR_SUCCESS)
 705.284 +		{
 705.285 +			res = RegSetValueEx(key2,
 705.286 +			                    "",
 705.287 +			                    0,
 705.288 +			                    REG_SZ,
 705.289 +			                    (const UCHAR *)application,
 705.290 +			                    strlen(application)+1);
 705.291 +			RegCloseKey(key2);
 705.292 +			RegCloseKey(key);
 705.293 +			return true;
 705.294 +		}
 705.295 +
 705.296 +		RegCloseKey(key);
 705.297 +	}
 705.298 +	return false;
 705.299 +}
 705.300 +
 705.301 +static void regExportSettingsToINI(HKEY key, const char *section)
 705.302 +{
 705.303 +	char valueName[256];
 705.304 +	int  index = 0;
 705.305 +	while (1)
 705.306 +	{
 705.307 +		DWORD nameSize = 256;
 705.308 +		DWORD size     = 2048;
 705.309 +		DWORD type;
 705.310 +		LONG  res = RegEnumValue(key,
 705.311 +		                         index,
 705.312 +		                         valueName,
 705.313 +		                         &nameSize,
 705.314 +		                         NULL,
 705.315 +		                         &type,
 705.316 +		                         (LPBYTE)buffer,
 705.317 +		                         &size);
 705.318 +
 705.319 +		if (res == ERROR_SUCCESS)
 705.320 +		{
 705.321 +			switch (type)
 705.322 +			{
 705.323 +			case REG_DWORD:
 705.324 +			{
 705.325 +				char temp[256];
 705.326 +				wsprintf(temp, "%u", *((DWORD *)buffer));
 705.327 +				WritePrivateProfileString(section,
 705.328 +				                          valueName,
 705.329 +				                          temp,
 705.330 +				                          regVbaPath);
 705.331 +				break;
 705.332 +			}
 705.333 +			case REG_SZ:
 705.334 +				WritePrivateProfileString(section,
 705.335 +				                          valueName,
 705.336 +				                          buffer,
 705.337 +				                          regVbaPath);
 705.338 +				break;
 705.339 +			case REG_BINARY:
 705.340 +			{
 705.341 +				char temp[256];
 705.342 +
 705.343 +				wsprintf(temp, "%u", size);
 705.344 +				CString k = valueName;
 705.345 +				k += "Count";
 705.346 +				WritePrivateProfileString(section,
 705.347 +				                          k,
 705.348 +				                          temp,
 705.349 +				                          regVbaPath);
 705.350 +				WritePrivateProfileStruct(section,
 705.351 +				                          valueName,
 705.352 +				                          buffer,
 705.353 +				                          size,
 705.354 +				                          regVbaPath);
 705.355 +				break;
 705.356 +			}
 705.357 +			}
 705.358 +			index++;
 705.359 +		}
 705.360 +		else
 705.361 +			break;
 705.362 +	}
 705.363 +}
 705.364 +
 705.365 +void regExportSettingsToINI()
 705.366 +{
 705.367 +	if (vbKey != NULL)
 705.368 +	{
 705.369 +		regExportSettingsToINI(vbKey, VBA_PREF);
 705.370 +	}
 705.371 +
 705.372 +	HKEY key;
 705.373 +
 705.374 +	if (RegOpenKey(HKEY_CURRENT_USER,
 705.375 +	               "Software\\Emulators\\VisualBoyAdvance\\Viewer", &key) ==
 705.376 +	    ERROR_SUCCESS)
 705.377 +	{
 705.378 +		regExportSettingsToINI(key, "Viewer");
 705.379 +		RegCloseKey(key);
 705.380 +	}
 705.381 +}
 705.382 +
   706.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   706.2 +++ b/src/win32/Reg.h	Sat Mar 03 10:31:27 2012 -0600
   706.3 @@ -0,0 +1,18 @@
   706.4 +#ifndef VBA_REG_H
   706.5 +#define VBA_REG_H
   706.6 +
   706.7 +extern bool regEnabled;
   706.8 +
   706.9 +const char *regQueryStringValue(const char *key, const char *def);
  706.10 +DWORD regQueryDwordValue(const char *key, DWORD def, bool force = false);
  706.11 +BOOL regQueryBinaryValue(const char *key, char *value, int count);
  706.12 +void regSetStringValue(const char *key, const char *value);
  706.13 +void regSetDwordValue(const char *key, DWORD value, bool force = false);
  706.14 +void regSetBinaryValue(const char *key, char *value, int count);
  706.15 +void regDeleteValue(const char *key);
  706.16 +void regInit(const char *);
  706.17 +void regShutdown();
  706.18 +bool regCreateFileType(const char *ext, const char *type);
  706.19 +bool regAssociateType(const char *type, const char *desc, const char *application);
  706.20 +void regExportSettingsToINI();
  706.21 +#endif // VBA_REG_H
   707.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   707.2 +++ b/src/win32/ResizeDlg.cpp	Sat Mar 03 10:31:27 2012 -0600
   707.3 @@ -0,0 +1,609 @@
   707.4 +/*----------------------------------------------------------------------
   707.5 +   Copyright (c)  Gipsysoft. All Rights Reserved.
   707.6 +   File:   DialogSizer_Set.cpp
   707.7 +   Web site: http://gipsysoft.com
   707.8 +
   707.9 +   This software is provided 'as-is', without any express or implied warranty.
  707.10 +
  707.11 +   In no event will the author be held liable for any damages arising from the
  707.12 +   use of this software.
  707.13 +
  707.14 +   Permission is granted to anyone to use this software for any purpose, including
  707.15 +   commercial applications, and to alter it and redistribute it freely, subject
  707.16 +   to the following restrictions:
  707.17 +
  707.18 +   1) The origin of this software must not be misrepresented; you must not claim
  707.19 +   that you wrote the original software. If you use this software in a product,
  707.20 +   an acknowledgment in the product documentation is requested but not required.
  707.21 +   2) Altered source versions must be plainly marked as such, and must not be
  707.22 +   misrepresented as being the original software. Altered source is encouraged
  707.23 +   to be submitted back to the original author so it can be shared with the
  707.24 +   community. Please share your changes.
  707.25 +   3) This notice may not be removed or altered from any source distribution.
  707.26 +
  707.27 +   Owner:  russf@gipsysoft.com
  707.28 +   Purpose:        Main functionality for sizeable dialogs
  707.29 +
  707.30 +   Store a local copy of the user settings
  707.31 +   Subclass the window
  707.32 +   Respond to various messages withinn the subclassed window.
  707.33 +
  707.34 +   ----------------------------------------------------------------------*/
  707.35 +// modified by the VBA-rr Team
  707.36 +
  707.37 +#include "stdafx.h"
  707.38 +#include "ResizeDlg.h"
  707.39 +#include "VBA.h"
  707.40 +#include "Sound.h"
  707.41 +#include "WinHelper.h"
  707.42 +
  707.43 +IMPLEMENT_DYNAMIC(ResizeDlg, CDialog)
  707.44 +
  707.45 +// moved functions to this file to reduce number of files
  707.46 +
  707.47 +struct RegistryData
  707.48 +{
  707.49 +	WINDOWPLACEMENT m_wpl;
  707.50 +};
  707.51 +
  707.52 +struct DialogData       //      dd
  707.53 +{
  707.54 +	HKEY    hkRootSave;
  707.55 +	LPCTSTR pcszName;
  707.56 +
  707.57 +	//
  707.58 +	//    The number of items contained in the psd member.
  707.59 +	//    Used in the DeferWindowPos structure and in allocating memory
  707.60 +	int nItemCount;
  707.61 +	DialogSizerSizingItem *psd;
  707.62 +
  707.63 +	//
  707.64 +	//    We need the smallest to respond to the WM_GETMINMAXINFO message
  707.65 +	POINT m_ptSmallest;
  707.66 +
  707.67 +	//
  707.68 +	//    We don't strictly speaking need to say how big the biggest can be but
  707.69 +	POINT m_ptLargest;
  707.70 +	bool  m_bLargestSet;
  707.71 +
  707.72 +	//
  707.73 +	//    we need this to decide how much the window has changed size when we get a WM_SIZE message
  707.74 +	SIZE m_sizeClient;
  707.75 +
  707.76 +	//
  707.77 +	//    Draw the sizing grip...or not
  707.78 +	bool m_bMaximised;
  707.79 +	BOOL m_bShowSizingGrip;
  707.80 +
  707.81 +	WinHelper::CRect m_rcGrip;
  707.82 +};
  707.83 +
  707.84 +extern bool regEnabled;
  707.85 +extern const char *regGetINIPath();
  707.86 +
  707.87 +void AssertFailed(char *file, int line, char *exp)
  707.88 +{
  707.89 +	char buffer[1024];
  707.90 +
  707.91 +	sprintf(buffer, "File %s\nLine %d\nExpression %s\nPress Retry to debug",
  707.92 +	        file, line, exp);
  707.93 +	systemSoundClearBuffer();
  707.94 +	int res = MessageBox(*theApp.m_pMainWnd, buffer, "Assertion failed!",
  707.95 +	                     MB_ICONHAND | MB_SETFOREGROUND | MB_TASKMODAL |
  707.96 +	                     MB_ABORTRETRYIGNORE);
  707.97 +
  707.98 +	if (res == IDRETRY)
  707.99 +	{
 707.100 +		__asm int 3;
 707.101 +	}
 707.102 +	else if (res == IDABORT)
 707.103 +		SendMessage(*theApp.m_pMainWnd, WM_QUIT, 0, 0);
 707.104 +}
 707.105 +
 707.106 +void ApiFailure(char *pcszFilename, int nLine, char *pcszExpression)
 707.107 +{
 707.108 +	const DWORD dwLastError = ::GetLastError();
 707.109 +	LPCTSTR     lpMsgBuf;
 707.110 +	(void)::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
 707.111 +	                      FORMAT_MESSAGE_FROM_SYSTEM |
 707.112 +	                      FORMAT_MESSAGE_IGNORE_INSERTS,
 707.113 +	                      NULL, dwLastError,
 707.114 +	                      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
 707.115 +	                      (LPTSTR) &lpMsgBuf, 0, NULL);
 707.116 +
 707.117 +	char szExeName[ MAX_PATH ];
 707.118 +
 707.119 +	if (!GetModuleFileName(NULL, szExeName, countof(szExeName)))
 707.120 +		strcpy(szExeName, "<No Program Name>");
 707.121 +
 707.122 +	char szMessage[ 1024 ];
 707.123 +	_snprintf(szMessage, countof(szMessage),
 707.124 +	          "API VERIFY Failure!"
 707.125 +	          "\nProgram: %s"
 707.126 +	          "\n"
 707.127 +	          "\nFile %s"
 707.128 +	          "\nLine %d"
 707.129 +	          "\n"
 707.130 +	          "\nExpression %s"
 707.131 +	          "\n"
 707.132 +	          "\nLast Error %d"
 707.133 +	          "\n           %s"
 707.134 +	          "\n\nPress Retry to debug the application",
 707.135 +	          szExeName,
 707.136 +	          pcszFilename,
 707.137 +	          nLine,
 707.138 +	          pcszExpression,
 707.139 +	          dwLastError,
 707.140 +	          lpMsgBuf
 707.141 +	          );
 707.142 +
 707.143 +	(void)LocalFree((LPVOID)lpMsgBuf);
 707.144 +	HWND hwndParent = ::GetActiveWindow();
 707.145 +	hwndParent = ::GetLastActivePopup(hwndParent);
 707.146 +	systemSoundClearBuffer();
 707.147 +	int nCode = ::MessageBoxA(hwndParent,
 707.148 +	                          szMessage,
 707.149 +	                          "Debug Helper",
 707.150 +	                          MB_TASKMODAL | MB_ICONHAND | MB_ABORTRETRYIGNORE |
 707.151 +	                          MB_SETFOREGROUND);
 707.152 +	if (nCode == IDABORT)
 707.153 +	{
 707.154 +		::SendMessage(*theApp.m_pMainWnd, WM_QUIT, 0, 0);
 707.155 +	}
 707.156 +	else if (nCode == IDRETRY)
 707.157 +		__asm int 3;
 707.158 +}
 707.159 +
 707.160 +long FASTCALL RegQueryValueExRecursive(HKEY hKey,
 707.161 +                                       LPCTSTR lpValueName,
 707.162 +                                       LPDWORD lpReserved,
 707.163 +                                       LPDWORD lpType,
 707.164 +                                       LPBYTE lpData,
 707.165 +                                       LPDWORD lpcbData)
 707.166 +{
 707.167 +	TCHAR szBuffer[ 256 ];
 707.168 +	R_ASSERT(lstrlen(lpValueName) < countof(szBuffer));
 707.169 +	(void)lstrcpy(szBuffer, lpValueName);
 707.170 +
 707.171 +	LPTSTR pszBuffer = szBuffer;
 707.172 +	LPTSTR pszLast   = szBuffer;
 707.173 +	while (*pszBuffer)
 707.174 +	{
 707.175 +		if (*pszBuffer == _T('\\') || *pszBuffer == _T('/'))
 707.176 +		{
 707.177 +			pszLast     = pszBuffer;
 707.178 +			lpValueName = pszLast + 1;
 707.179 +		}
 707.180 +		pszBuffer++;
 707.181 +	}
 707.182 +
 707.183 +	if (!regEnabled)
 707.184 +	{
 707.185 +		if (GetPrivateProfileStruct("Viewer",
 707.186 +		                            lpValueName,
 707.187 +		                            lpData,
 707.188 +		                            *lpcbData,
 707.189 +		                            regGetINIPath()))
 707.190 +		{
 707.191 +			*lpType = REG_BINARY;
 707.192 +			return ERROR_SUCCESS;
 707.193 +		}
 707.194 +		return -1;
 707.195 +	}
 707.196 +
 707.197 +	bool m_bNeedToCloseKey = false;
 707.198 +	if (pszLast != szBuffer)
 707.199 +	{
 707.200 +		*pszLast = _T('\000');
 707.201 +		HKEY hkeyTemp;
 707.202 +		long lRet = RegOpenKey(hKey, szBuffer, &hkeyTemp);
 707.203 +		if (lRet != ERROR_SUCCESS)
 707.204 +		{
 707.205 +			return lRet;
 707.206 +		}
 707.207 +		hKey = hkeyTemp;
 707.208 +		m_bNeedToCloseKey = true;
 707.209 +	}
 707.210 +
 707.211 +	long lRet = RegQueryValueEx(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData);
 707.212 +	if (m_bNeedToCloseKey)
 707.213 +	{
 707.214 +		R_VERIFY(RegCloseKey(hKey) == ERROR_SUCCESS);
 707.215 +	}
 707.216 +	return lRet;
 707.217 +}
 707.218 +
 707.219 +long FASTCALL RegSetValueExRecursive(HKEY hKey,
 707.220 +                                     LPCTSTR lpValueName,
 707.221 +                                     DWORD Reserved,
 707.222 +                                     DWORD dwType,
 707.223 +                                     CONST BYTE*lpData,
 707.224 +                                     DWORD cbData)
 707.225 +{
 707.226 +	TCHAR szBuffer[ 256 ];
 707.227 +	R_ASSERT(lstrlen(lpValueName) < countof(szBuffer));
 707.228 +	(void)lstrcpy(szBuffer, lpValueName);
 707.229 +
 707.230 +	LPTSTR pszBuffer = szBuffer;
 707.231 +	LPTSTR pszLast   = szBuffer;
 707.232 +	while (*pszBuffer)
 707.233 +	{
 707.234 +		if (*pszBuffer == _T('\\') || *pszBuffer == _T('/'))
 707.235 +		{
 707.236 +			pszLast     = pszBuffer;
 707.237 +			lpValueName = pszLast + 1;
 707.238 +		}
 707.239 +		pszBuffer++;
 707.240 +	}
 707.241 +
 707.242 +	if (!regEnabled)
 707.243 +	{
 707.244 +		if (WritePrivateProfileStruct("Viewer",
 707.245 +		                              lpValueName,
 707.246 +		                              (LPVOID)lpData,
 707.247 +		                              cbData,
 707.248 +		                              regGetINIPath()))
 707.249 +		{
 707.250 +			return ERROR_SUCCESS;
 707.251 +		}
 707.252 +		return -1;
 707.253 +	}
 707.254 +
 707.255 +	bool m_bNeedToCloseKey = false;
 707.256 +	if (pszLast != szBuffer)
 707.257 +	{
 707.258 +		*pszLast = _T('\000');
 707.259 +		HKEY hkeyTemp;
 707.260 +		long lRet = RegOpenKey(hKey, szBuffer, &hkeyTemp);
 707.261 +		if (lRet != ERROR_SUCCESS)
 707.262 +		{
 707.263 +			lRet = RegCreateKey(hKey, szBuffer, &hkeyTemp);
 707.264 +			if (lRet != ERROR_SUCCESS)
 707.265 +				return lRet;
 707.266 +		}
 707.267 +		hKey = hkeyTemp;
 707.268 +		m_bNeedToCloseKey = true;
 707.269 +	}
 707.270 +
 707.271 +	long lRet = RegSetValueEx(hKey, lpValueName, Reserved, dwType, lpData, cbData);
 707.272 +	if (m_bNeedToCloseKey)
 707.273 +	{
 707.274 +		R_VERIFY(RegCloseKey(hKey) == ERROR_SUCCESS);
 707.275 +	}
 707.276 +	return lRet;
 707.277 +}
 707.278 +
 707.279 +int ResizeDlgGetItemCount(const DialogSizerSizingItem *psd)
 707.280 +{
 707.281 +	R_ASSERT(psd);
 707.282 +	int nCount = 0;
 707.283 +	while (psd->uSizeInfo != 0xFFFFFFFF)
 707.284 +	{
 707.285 +		nCount++;
 707.286 +		psd++;
 707.287 +	}
 707.288 +	return nCount;
 707.289 +}
 707.290 +
 707.291 +void ResizeDlgUpdateGripperRect(const int cx, const int cy, WinHelper::CRect &rcGrip)
 707.292 +{
 707.293 +	const int nGripWidth  = GetSystemMetrics(SM_CYVSCROLL);
 707.294 +	const int nGripHeight = GetSystemMetrics(SM_CXVSCROLL);
 707.295 +	rcGrip.left   = cx - nGripWidth;
 707.296 +	rcGrip.top    = cy - nGripHeight;
 707.297 +	rcGrip.right  = cx;
 707.298 +	rcGrip.bottom = cy;
 707.299 +}
 707.300 +
 707.301 +void ResizeDlgUpdateGripper(HWND hwnd, DialogData *pdd)
 707.302 +{
 707.303 +	if (pdd->m_bShowSizingGrip)
 707.304 +	{
 707.305 +		WinHelper::CRect rcOld(pdd->m_rcGrip);
 707.306 +
 707.307 +		ResizeDlgUpdateGripperRect(pdd->m_sizeClient.cx, pdd->m_sizeClient.cy, pdd->m_rcGrip);
 707.308 +
 707.309 +		//
 707.310 +		//        We also need to invalidate the combined area of the old and new rectangles
 707.311 +		//        otherwise we would have trail of grippers when we sized the dialog larger
 707.312 +		//        in any axis
 707.313 +		(void)UnionRect(&rcOld, &rcOld, &pdd->m_rcGrip);
 707.314 +		(void)InvalidateRect(hwnd, &rcOld, TRUE);
 707.315 +	}
 707.316 +}
 707.317 +
 707.318 +void ResizeDlgCopyItems(DialogSizerSizingItem *psdDest, const DialogSizerSizingItem *psdSource)
 707.319 +//
 707.320 +//    Will copy all of the items in psdSource into psdDest.
 707.321 +{
 707.322 +	//
 707.323 +	//    Loop til we reach the end
 707.324 +	while (psdSource->uSizeInfo != 0xFFFFFFFF)
 707.325 +	{
 707.326 +		*psdDest = *psdSource;
 707.327 +		psdDest++;
 707.328 +		psdSource++;
 707.329 +	}
 707.330 +	//    And when we do copy the last item
 707.331 +	*psdDest = *psdSource;
 707.332 +}
 707.333 +
 707.334 +ResizeDlg::ResizeDlg(UINT id, CWnd *parent)
 707.335 +	: CDialog(id, parent)
 707.336 +{
 707.337 +	dd = NULL;
 707.338 +}
 707.339 +
 707.340 +void *ResizeDlg::AddDialogData()
 707.341 +//
 707.342 +//    Firstly determine if the data already exists, if it does then return that, if not then we will
 707.343 +//    create and initialise a brand new structure.
 707.344 +{
 707.345 +	DialogData *pdd = (DialogData *)dd;
 707.346 +	if (!pdd)
 707.347 +	{
 707.348 +		pdd = (DialogData *)calloc(1, sizeof(DialogData));
 707.349 +	}
 707.350 +
 707.351 +	if (pdd)
 707.352 +	{
 707.353 +		//
 707.354 +		//  Store some sizes etc. for later.
 707.355 +		CRect rc;
 707.356 +		GetWindowRect(rc);
 707.357 +		pdd->m_ptSmallest.x = rc.Width();
 707.358 +		pdd->m_ptSmallest.y = rc.Height();
 707.359 +
 707.360 +		GetClientRect(rc);
 707.361 +		pdd->m_sizeClient = rc.Size();
 707.362 +		dd = pdd;
 707.363 +		ResizeDlgUpdateGripperRect(pdd->m_sizeClient.cx, pdd->m_sizeClient.cy, pdd->m_rcGrip);
 707.364 +	}
 707.365 +	return pdd;
 707.366 +}
 707.367 +
 707.368 +BOOL ResizeDlg::SetData(const DialogSizerSizingItem *psd,
 707.369 +                        BOOL bShowSizingGrip,
 707.370 +                        HKEY hkRootSave,
 707.371 +                        LPCTSTR pcszName,
 707.372 +                        SIZE *psizeMax)
 707.373 +//
 707.374 +//    Setting a dialog sizeable involves subclassing the window and handling it's
 707.375 +//    WM_SIZE messages, if we have a hkRootSave and pcszName then we will also be loading/saving
 707.376 +//    the size and position of the window from the registry. We load from the registry when we
 707.377 +//    subclass the window and we save to the registry when we get a WM_DESTROY.
 707.378 +//
 707.379 +//    It will return non-zero for success and zero if it fails
 707.380 +{
 707.381 +	R_ASSERT(psd);
 707.382 +	R_ASSERT((hkRootSave != NULL && pcszName != NULL)
 707.383 +	         || (hkRootSave == NULL && pcszName == NULL));
 707.384 +	//
 707.385 +	//    Make sure all of the parameters are valid.
 707.386 +	if (::IsWindow(*this)
 707.387 +	    && psd
 707.388 +	    && ((hkRootSave != NULL && pcszName != NULL &&
 707.389 +	         !IsBadStringPtr(pcszName, 0xFFFF)) ||
 707.390 +	        (hkRootSave == NULL && pcszName == NULL))
 707.391 +	    && (psizeMax == NULL || !IsBadReadPtr(psizeMax, sizeof(SIZE)))
 707.392 +	    )
 707.393 +	{
 707.394 +		DialogData *pdd = (DialogData *)AddDialogData();
 707.395 +		if (pdd)
 707.396 +		{
 707.397 +			pdd->hkRootSave        = hkRootSave;
 707.398 +			pdd->pcszName          = pcszName;
 707.399 +			pdd->m_bShowSizingGrip = bShowSizingGrip;
 707.400 +			pdd->nItemCount        = ResizeDlgGetItemCount(psd) + 1;
 707.401 +			pdd->psd = (DialogSizerSizingItem *)
 707.402 +			           calloc(pdd->nItemCount,
 707.403 +			                  sizeof(DialogSizerSizingItem));
 707.404 +			if (pdd->psd)
 707.405 +			{
 707.406 +				//
 707.407 +				//      Copy all of the user controls etc. for later, this way the user can quite happily
 707.408 +				//      let the structure go out of scope.
 707.409 +				ResizeDlgCopyItems(pdd->psd, psd);
 707.410 +				if (psizeMax)
 707.411 +				{
 707.412 +					pdd->m_ptLargest.x = psizeMax->cx;
 707.413 +					pdd->m_ptLargest.y = psizeMax->cy;
 707.414 +					pdd->m_bLargestSet = true;
 707.415 +				}
 707.416 +
 707.417 +				//
 707.418 +				//      If the there was save info passed in then we need to make damn good use of it
 707.419 +				//      by attempting to load the RegistryData structure
 707.420 +				if (hkRootSave && pcszName)
 707.421 +				{
 707.422 +					RegistryData rd;
 707.423 +					DWORD        dwSize = sizeof(RegistryData);
 707.424 +					DWORD        dwType = REG_BINARY;
 707.425 +					if (RegQueryValueExRecursive(hkRootSave, pcszName, NULL, &dwType, reinterpret_cast<LPBYTE>(&rd),
 707.426 +					                             &dwSize) == ERROR_SUCCESS && dwSize == sizeof(rd))
 707.427 +					{
 707.428 +						if (!(GetWindowLong(*this, GWL_STYLE) & WS_VISIBLE))
 707.429 +							rd.m_wpl.showCmd = SW_HIDE;
 707.430 +
 707.431 +						VAPI(SetWindowPlacement(&rd.m_wpl));
 707.432 +					}
 707.433 +				}
 707.434 +				return TRUE;
 707.435 +			}
 707.436 +			else
 707.437 +			{
 707.438 +				free(pdd);
 707.439 +			}
 707.440 +		}
 707.441 +	}
 707.442 +	return FALSE;
 707.443 +}
 707.444 +
 707.445 +void ResizeDlg::UpdateWindowSize(const int cx, const int cy, HWND hwnd)
 707.446 +{
 707.447 +	DialogData *pdd = (DialogData *)dd;
 707.448 +	if (pdd)
 707.449 +	{
 707.450 +		const int nDeltaX = cx - pdd->m_sizeClient.cx;
 707.451 +		const int nDeltaY = cy - pdd->m_sizeClient.cy;
 707.452 +		WinHelper::CDeferWindowPos def(pdd->nItemCount);
 707.453 +		WinHelper::CRect rc;
 707.454 +		const DialogSizerSizingItem *psd = pdd->psd;
 707.455 +		while (psd->uSizeInfo != 0xFFFFFFFF)
 707.456 +		{
 707.457 +			HWND hwndChild = ::GetDlgItem(*this, psd->uControlID);
 707.458 +			if (::IsWindow(hwndChild))
 707.459 +			{
 707.460 +				VAPI(::GetWindowRect(hwndChild, rc));
 707.461 +				(void)::MapWindowPoints(::GetDesktopWindow(),  hwnd,
 707.462 +				                        (LPPOINT)&rc, 2);
 707.463 +
 707.464 +				//
 707.465 +				//      Adjust the window horizontally
 707.466 +				if (psd->uSizeInfo & DS_MoveX)
 707.467 +				{
 707.468 +					rc.left  += nDeltaX;
 707.469 +					rc.right += nDeltaX;
 707.470 +				}
 707.471 +
 707.472 +				//
 707.473 +				//      Adjust the window vertically
 707.474 +				if (psd->uSizeInfo & DS_MoveY)
 707.475 +				{
 707.476 +					rc.top    += nDeltaY;
 707.477 +					rc.bottom += nDeltaY;
 707.478 +				}
 707.479 +
 707.480 +				//
 707.481 +				//      Size the window horizontally
 707.482 +				if (psd->uSizeInfo & DS_SizeX)
 707.483 +				{
 707.484 +					rc.right += nDeltaX;
 707.485 +				}
 707.486 +
 707.487 +				//
 707.488 +				//      Size the window vertically
 707.489 +				if (psd->uSizeInfo & DS_SizeY)
 707.490 +				{
 707.491 +					rc.bottom += nDeltaY;
 707.492 +				}
 707.493 +
 707.494 +				(void)def.DeferWindowPos(hwndChild, NULL, rc,
 707.495 +				                         SWP_NOACTIVATE | SWP_NOZORDER);
 707.496 +			}
 707.497 +			psd++;
 707.498 +		}
 707.499 +
 707.500 +		pdd->m_sizeClient.cx = cx;
 707.501 +		pdd->m_sizeClient.cy = cy;
 707.502 +
 707.503 +		//
 707.504 +		//  If we have a sizing grip enabled then adjust it's position
 707.505 +		ResizeDlgUpdateGripper(hwnd, pdd);
 707.506 +	}
 707.507 +}
 707.508 +
 707.509 +BOOL ResizeDlg::OnWndMsg(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *res)
 707.510 +//    Actual window procedure that will handle saving window size/position and moving
 707.511 +//    the controls whilst the window sizes.
 707.512 +{
 707.513 +	if (dd == NULL)
 707.514 +	{
 707.515 +		return CDialog::OnWndMsg(msg, wParam, lParam, res);
 707.516 +	}
 707.517 +	switch (msg)
 707.518 +	{
 707.519 +	case WM_ERASEBKGND:
 707.520 +	{
 707.521 +		BOOL        r   = CDialog::OnWndMsg(msg, wParam, lParam, res);
 707.522 +		DialogData *pdd = (DialogData *)dd;
 707.523 +		if (pdd && pdd->m_bShowSizingGrip && !pdd->m_bMaximised)
 707.524 +		{
 707.525 +			VAPI(::DrawFrameControl(reinterpret_cast<HDC>(wParam),
 707.526 +			                        pdd->m_rcGrip,
 707.527 +			                        DFC_SCROLL, DFCS_SCROLLSIZEGRIP));
 707.528 +		}
 707.529 +		return r;
 707.530 +	}
 707.531 +	case WM_SIZE:
 707.532 +	{
 707.533 +		DialogData *pdd = (DialogData *)dd;
 707.534 +		if (pdd && wParam != SIZE_MINIMIZED)
 707.535 +		{
 707.536 +			pdd->m_bMaximised = (wParam == SIZE_MAXIMIZED ? true : false);
 707.537 +			UpdateWindowSize(LOWORD(lParam), HIWORD(lParam), *this);
 707.538 +		}
 707.539 +		break;
 707.540 +	}
 707.541 +	case WM_NCHITTEST:
 707.542 +	{
 707.543 +		//
 707.544 +		//        If the gripper is enabled then perform a simple hit test on our gripper area.
 707.545 +		DialogData *pdd = (DialogData *)dd;
 707.546 +		if (pdd && pdd->m_bShowSizingGrip)
 707.547 +		{
 707.548 +			POINT pt = { LOWORD(lParam), HIWORD(lParam) };
 707.549 +			(void)ScreenToClient(&pt);
 707.550 +			if (PtInRect(pdd->m_rcGrip, pt))
 707.551 +				return (BOOL)HTBOTTOMRIGHT;
 707.552 +		}
 707.553 +		break;
 707.554 +	}
 707.555 +	case WM_GETMINMAXINFO:
 707.556 +	{
 707.557 +		//
 707.558 +		//        Our opportunity to say that we do not want the dialog to grow or shrink any more.
 707.559 +		DialogData * pdd   = (DialogData *)dd;
 707.560 +		LPMINMAXINFO lpmmi = reinterpret_cast<LPMINMAXINFO>(lParam);
 707.561 +		lpmmi->ptMinTrackSize = pdd->m_ptSmallest;
 707.562 +		if (pdd->m_bLargestSet)
 707.563 +		{
 707.564 +			lpmmi->ptMaxTrackSize = pdd->m_ptLargest;
 707.565 +		}
 707.566 +	}
 707.567 +		return (BOOL)0;
 707.568 +	case WM_NOTIFY:
 707.569 +	{
 707.570 +		if (reinterpret_cast<LPNMHDR>(lParam)->code == PSN_SETACTIVE)
 707.571 +		{
 707.572 +			CRect rc;
 707.573 +			VAPI(::GetClientRect(*GetParent(), &rc));
 707.574 +			UpdateWindowSize(rc.Width(), rc.Height(), *GetParent());
 707.575 +		}
 707.576 +		break;
 707.577 +	}
 707.578 +	case WM_DESTROY:
 707.579 +	{
 707.580 +		//
 707.581 +		//        Our opportunty for cleanup.
 707.582 +		//        Simply acquire all of our objects, free the appropriate memory and remove the
 707.583 +		//        properties from the window. If we do not remove the properties then they will constitute
 707.584 +		//        a resource leak.
 707.585 +		DialogData *pdd = (DialogData *)dd;
 707.586 +		if (pdd)
 707.587 +		{
 707.588 +			RegistryData rd;
 707.589 +			rd.m_wpl.length = sizeof(rd.m_wpl);
 707.590 +			VAPI(GetWindowPlacement(&rd.m_wpl));
 707.591 +
 707.592 +			if (pdd->hkRootSave && pdd->pcszName)
 707.593 +			{
 707.594 +				(void)RegSetValueExRecursive(pdd->hkRootSave, pdd->pcszName,
 707.595 +				                             NULL, REG_BINARY,
 707.596 +				                             reinterpret_cast<LPBYTE>(&rd),
 707.597 +				                             sizeof(rd));
 707.598 +			}
 707.599 +
 707.600 +			if (pdd->psd)
 707.601 +			{
 707.602 +				free(pdd->psd);
 707.603 +			}
 707.604 +			free(pdd);
 707.605 +		}
 707.606 +
 707.607 +		break;
 707.608 +	}
 707.609 +	}
 707.610 +	return CDialog::OnWndMsg(msg, wParam, lParam, res);
 707.611 +}
 707.612 +
   708.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   708.2 +++ b/src/win32/ResizeDlg.h	Sat Mar 03 10:31:27 2012 -0600
   708.3 @@ -0,0 +1,44 @@
   708.4 +#ifndef VBA_WIN32_RESIZEDLG_H
   708.5 +#define VBA_WIN32_RESIZEDLG_H
   708.6 +
   708.7 +#ifndef _INC_TCHAR
   708.8 +#include <tchar.h>
   708.9 +#endif  //      _INC_TCHAR
  708.10 +
  708.11 +//
  708.12 +//      Predefined sizing information
  708.13 +#define DS_MoveX                1
  708.14 +#define DS_MoveY                2
  708.15 +#define DS_SizeX                4
  708.16 +#define DS_SizeY                8
  708.17 +
  708.18 +typedef struct DialogSizerSizingItem    //      sdi
  708.19 +{
  708.20 +	UINT uControlID;
  708.21 +	UINT uSizeInfo;
  708.22 +} DialogSizerSizingItem;
  708.23 +
  708.24 +#define DIALOG_SIZER_START(name)      DialogSizerSizingItem name[] = {
  708.25 +#define DIALOG_SIZER_ENTRY(controlID, flags)  { controlID, flags },
  708.26 +#define DIALOG_SIZER_END()      { 0xFFFFFFFF, 0xFFFFFFFF } };
  708.27 +
  708.28 +class ResizeDlg : public CDialog
  708.29 +{
  708.30 +	DECLARE_DYNAMIC(ResizeDlg)	// what will this do?
  708.31 +public:
  708.32 +	ResizeDlg(UINT id, CWnd *parent = NULL);
  708.33 +
  708.34 +	void *AddDialogData();
  708.35 +	BOOL SetData(const DialogSizerSizingItem *psd,
  708.36 +	             BOOL bShowSizingGrip,
  708.37 +	             HKEY hkRootSave,
  708.38 +	             LPCTSTR pcszName,
  708.39 +	             SIZE *psizeMax);
  708.40 +	void UpdateWindowSize(const int cx, const int cy, HWND);
  708.41 +
  708.42 +	virtual BOOL OnWndMsg(UINT, WPARAM, LPARAM, LRESULT *);
  708.43 +private:
  708.44 +	void *dd;
  708.45 +};
  708.46 +
  708.47 +#endif
   709.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   709.2 +++ b/src/win32/RewindInterval.cpp	Sat Mar 03 10:31:27 2012 -0600
   709.3 @@ -0,0 +1,96 @@
   709.4 +// RewindInterval.cpp : implementation file
   709.5 +//
   709.6 +
   709.7 +#include "stdafx.h"
   709.8 +#include <cmath>
   709.9 +#include "resource.h"
  709.10 +#include "RewindInterval.h"
  709.11 +#include "VBA.h"
  709.12 +
  709.13 +/////////////////////////////////////////////////////////////////////////////
  709.14 +// RewindInterval dialog
  709.15 +
  709.16 +RewindInterval::RewindInterval(float interval, int slots, CWnd*pParent /*=NULL*/)
  709.17 +	: CDialog(RewindInterval::IDD, pParent)
  709.18 +{
  709.19 +	//{{AFX_DATA_INIT(RewindInterval)
  709.20 +	// NOTE: the ClassWizard will add member initialization here
  709.21 +	//}}AFX_DATA_INIT
  709.22 +	this->interval = interval;
  709.23 +	this->slots    = slots;
  709.24 +}
  709.25 +
  709.26 +void RewindInterval::DoDataExchange(CDataExchange*pDX)
  709.27 +{
  709.28 +	CDialog::DoDataExchange(pDX);
  709.29 +	//{{AFX_DATA_MAP(RewindInterval)
  709.30 +	DDX_Control(pDX, IDC_INTERVAL, m_interval);
  709.31 +	DDX_Control(pDX, IDC_REWINDSLOTS, m_slots);
  709.32 +	//}}AFX_DATA_MAP
  709.33 +}
  709.34 +
  709.35 +BEGIN_MESSAGE_MAP(RewindInterval, CDialog)
  709.36 +//{{AFX_MSG_MAP(RewindInterval)
  709.37 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
  709.38 +ON_BN_CLICKED(ID_OK, OnOk)
  709.39 +//}}AFX_MSG_MAP
  709.40 +END_MESSAGE_MAP()
  709.41 +
  709.42 +/////////////////////////////////////////////////////////////////////////////
  709.43 +// RewindInterval message handlers
  709.44 +
  709.45 +void RewindInterval::OnCancel()
  709.46 +{
  709.47 +	EndDialog(-1);
  709.48 +}
  709.49 +
  709.50 +void RewindInterval::OnOk()
  709.51 +{
  709.52 +	CString buffer, buffer2;
  709.53 +
  709.54 +	m_interval.GetWindowText(buffer);
  709.55 +	m_slots.GetWindowText(buffer2);
  709.56 +
  709.57 +	float interval = (float)atof(buffer);
  709.58 +	int   slots    = atoi(buffer2);
  709.59 +
  709.60 +	if (interval >= 0 && (int)interval <= 600)
  709.61 +	{
  709.62 +		if (slots >= 0 && slots <= MAX_REWIND_SLOTS)
  709.63 +		{
  709.64 +			int iInterval = (int)(interval*6.0f + 0.5f);
  709.65 +			if (interval > 0 && iInterval == 0)
  709.66 +				iInterval = 1;
  709.67 +			EndDialog(iInterval | (slots << 16));
  709.68 +			theApp.winAccelMgr.UpdateMenu(theApp.menu);
  709.69 +		}
  709.70 +		else
  709.71 +			systemMessage(IDS_INVALID_INTERVAL_VALUE,
  709.72 +			              "Invalid rewind slot amount. Please enter a number "
  709.73 +			              "between 0 and 128 slots");
  709.74 +	}
  709.75 +	else
  709.76 +		systemMessage(IDS_INVALID_INTERVAL_VALUE,
  709.77 +		              "Invalid rewind interval value. Please enter a number "
  709.78 +		              "between 0 and 600 seconds");
  709.79 +}
  709.80 +
  709.81 +BOOL RewindInterval::OnInitDialog()
  709.82 +{
  709.83 +	CDialog::OnInitDialog();
  709.84 +
  709.85 +	m_interval.LimitText(5);
  709.86 +	m_slots.LimitText(3);
  709.87 +
  709.88 +	CString buffer, buffer2;
  709.89 +	buffer.Format("%.1f", interval);
  709.90 +	m_interval.SetWindowText(buffer);
  709.91 +	buffer2.Format("%d", slots);
  709.92 +	m_slots.SetWindowText(buffer2);
  709.93 +
  709.94 +	CenterWindow();
  709.95 +
  709.96 +	return TRUE; // return TRUE unless you set the focus to a control
  709.97 +	             // EXCEPTION: OCX Property Pages should return FALSE
  709.98 +}
  709.99 +
   710.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   710.2 +++ b/src/win32/RewindInterval.h	Sat Mar 03 10:31:27 2012 -0600
   710.3 @@ -0,0 +1,49 @@
   710.4 +#if !defined(AFX_REWINDINTERVAL_H__C95AFF44_1F64_44C8_BAAB_A54B982D28EA__INCLUDED_)
   710.5 +#define AFX_REWINDINTERVAL_H__C95AFF44_1F64_44C8_BAAB_A54B982D28EA__INCLUDED_
   710.6 +
   710.7 +#if _MSC_VER > 1000
   710.8 +#pragma once
   710.9 +#endif // _MSC_VER > 1000
  710.10 +// RewindInterval.h : header file
  710.11 +//
  710.12 +
  710.13 +/////////////////////////////////////////////////////////////////////////////
  710.14 +// RewindInterval dialog
  710.15 +
  710.16 +class RewindInterval : public CDialog
  710.17 +{
  710.18 +	// Construction
  710.19 +public:
  710.20 +	float interval;
  710.21 +	int   slots;
  710.22 +	RewindInterval(float interval, int slots, CWnd*pParent = NULL);  // standard constructor
  710.23 +
  710.24 +	// Dialog Data
  710.25 +	//{{AFX_DATA(RewindInterval)
  710.26 +	enum { IDD = IDD_REWIND_INTERVAL };
  710.27 +	CEdit m_interval;
  710.28 +	CEdit m_slots;
  710.29 +	//}}AFX_DATA
  710.30 +
  710.31 +	// Overrides
  710.32 +	// ClassWizard generated virtual function overrides
  710.33 +	//{{AFX_VIRTUAL(RewindInterval)
  710.34 +protected:
  710.35 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  710.36 +	//}}AFX_VIRTUAL
  710.37 +
  710.38 +	// Implementation
  710.39 +protected:
  710.40 +	// Generated message map functions
  710.41 +	//{{AFX_MSG(RewindInterval)
  710.42 +	afx_msg void OnCancel();
  710.43 +	afx_msg void OnOk();
  710.44 +	virtual BOOL OnInitDialog();
  710.45 +	//}}AFX_MSG
  710.46 +	DECLARE_MESSAGE_MAP()
  710.47 +};
  710.48 +
  710.49 +//{{AFX_INSERT_LOCATION}}
  710.50 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  710.51 +
  710.52 +#endif // !defined(AFX_REWINDINTERVAL_H__C95AFF44_1F64_44C8_BAAB_A54B982D28EA__INCLUDED_)
   711.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   711.2 +++ b/src/win32/RomInfo.cpp	Sat Mar 03 10:31:27 2012 -0600
   711.3 @@ -0,0 +1,555 @@
   711.4 +// RomInfo.cpp : implementation file
   711.5 +//
   711.6 +
   711.7 +#include "stdafx.h"
   711.8 +#include "resource.h"
   711.9 +#include "RomInfo.h"
  711.10 +#include "WinResUtil.h"
  711.11 +
  711.12 +extern int32 gbRomSize;
  711.13 +
  711.14 +struct WinGBACompanyName
  711.15 +{
  711.16 +	LPCTSTR code;
  711.17 +	LPCTSTR name;
  711.18 +};
  711.19 +
  711.20 +static WinGBACompanyName winGBARomInfoCompanies[] = {
  711.21 +	{ "01", "Nintendo"							  },
  711.22 +	{ "02", "Rocket Games"						  },
  711.23 +	{ "08", "Capcom"							  },
  711.24 +	{ "09", "Hot B Co."							  },
  711.25 +	{ "0A", "Jaleco"							  },
  711.26 +	{ "0B", "Coconuts Japan"					  },
  711.27 +	{ "0C", "Coconuts Japan/G.X.Media"			  },
  711.28 +	{ "0H", "Starfish"							  },
  711.29 +	{ "0L", "Warashi Inc."						  },
  711.30 +	{ "0N", "Nowpro"							  },
  711.31 +	{ "0P", "Game Village"						  },
  711.32 +	{ "13", "Electronic Arts Japan"				  },
  711.33 +	{ "18", "Hudson Soft Japan"					  },
  711.34 +	{ "19", "S.C.P."							  },
  711.35 +	{ "1A", "Yonoman"							  },
  711.36 +	{ "1G", "SMDE"								  },
  711.37 +	{ "1P", "Creatures Inc."					  },
  711.38 +	{ "1Q", "TDK Deep Impresion"				  },
  711.39 +	{ "20", "Destination Software"				  },
  711.40 +	{ "22", "VR 1 Japan"						  },
  711.41 +	{ "25", "San-X"								  },
  711.42 +	{ "28", "Kemco Japan"						  },
  711.43 +	{ "29", "Seta"								  },
  711.44 +	{ "2H", "Ubisoft Japan"						  },
  711.45 +	{ "2K", "NEC InterChannel"					  },
  711.46 +	{ "2L", "Tam"								  },
  711.47 +	{ "2M", "Jordan"							  },
  711.48 +	{ "2N", "Smilesoft"							  },
  711.49 +	{ "2Q", "Mediakite"							  },
  711.50 +	{ "36", "Codemasters"						  },
  711.51 +	{ "37", "GAGA Communications"				  },
  711.52 +	{ "38", "Laguna"							  },
  711.53 +	{ "39", "Telstar Fun and Games"				  },
  711.54 +	{ "41", "Ubi Soft Entertainment"			  },
  711.55 +	{ "42", "Sunsoft"							  },
  711.56 +	{ "47", "Spectrum Holobyte"					  },
  711.57 +	{ "49", "IREM"								  },
  711.58 +	{ "4D", "Malibu Games"						  },
  711.59 +	{ "4F", "Eidos/U.S. Gold"					  },
  711.60 +	{ "4J", "Fox Interactive"					  },
  711.61 +	{ "4K", "Time Warner Interactive"			  },
  711.62 +	{ "4Q", "Disney"							  },
  711.63 +	{ "4S", "Black Pearl"						  },
  711.64 +	{ "4X", "GT Interactive"					  },
  711.65 +	{ "4Y", "RARE"								  },
  711.66 +	{ "4Z", "Crave Entertainment"				  },
  711.67 +	{ "50", "Absolute Entertainment"			  },
  711.68 +	{ "51", "Acclaim"							  },
  711.69 +	{ "52", "Activision"						  },
  711.70 +	{ "53", "American Sammy Corp."				  },
  711.71 +	{ "54", "Take 2 Interactive"				  },
  711.72 +	{ "55", "Hi Tech"							  },
  711.73 +	{ "56", "LJN LTD."							  },
  711.74 +	{ "58", "Mattel"							  },
  711.75 +	{ "5A", "Mindscape/Red Orb Ent."			  },
  711.76 +	{ "5C", "Taxan"								  },
  711.77 +	{ "5D", "Midway"							  },
  711.78 +	{ "5F", "American Softworks"				  },
  711.79 +	{ "5G", "Majesco Sales Inc"					  },
  711.80 +	{ "5H", "3DO"								  },
  711.81 +	{ "5K", "Hasbro"							  },
  711.82 +	{ "5L", "NewKidCo"							  },
  711.83 +	{ "5M", "Telegames"							  },
  711.84 +	{ "5N", "Metro3D"							  },
  711.85 +	{ "5P", "Vatical Entertainment"				  },
  711.86 +	{ "5Q", "LEGO Media"						  },
  711.87 +	{ "5S", "Xicat Interactive"					  },
  711.88 +	{ "5T", "Cryo Interactive"					  },
  711.89 +	{ "5W", "Red Storm Ent./BKN Ent."			  },
  711.90 +	{ "5X", "Microids"							  },
  711.91 +	{ "5Z", "Conspiracy Entertainment Corp."	  },
  711.92 +	{ "60", "Titus Interactive Studios"			  },
  711.93 +	{ "61", "Virgin Interactive"				  },
  711.94 +	{ "62", "Maxis"								  },
  711.95 +	{ "64", "LucasArts Entertainment"			  },
  711.96 +	{ "67", "Ocean"								  },
  711.97 +	{ "69", "Electronic Arts"					  },
  711.98 +	{ "6E", "Elite Systems Ltd."				  },
  711.99 +	{ "6F", "Electro Brain"						  },
 711.100 +	{ "6G", "The Learning Company"				  },
 711.101 +	{ "6H", "BBC"								  },
 711.102 +	{ "6J", "Software 2000"						  },
 711.103 +	{ "6L", "BAM! Entertainment"				  },
 711.104 +	{ "6M", "Studio 3"							  },
 711.105 +	{ "6Q", "Classified Games"					  },
 711.106 +	{ "6S", "TDK Mediactive"					  },
 711.107 +	{ "6U", "DreamCatcher"						  },
 711.108 +	{ "6V", "JoWood Productions"				  },
 711.109 +	{ "6W", "SEGA"								  },
 711.110 +	{ "6X", "Wannado Edition"					  },
 711.111 +	{ "6Y", "LSP"								  },
 711.112 +	{ "6Z", "ITE Media"							  },
 711.113 +	{ "70", "Infogrames"						  },
 711.114 +	{ "71", "Interplay"							  },
 711.115 +	{ "72", "JVC Musical Industries Inc"		  },
 711.116 +	{ "73", "Parker Brothers"					  },
 711.117 +	{ "75", "SCI"								  },
 711.118 +	{ "78", "THQ"								  },
 711.119 +	{ "79", "Accolade"							  },
 711.120 +	{ "7A", "Triffix Ent. Inc."					  },
 711.121 +	{ "7C", "Microprose Software"				  },
 711.122 +	{ "7D", "Universal Interactive Studios"		  },
 711.123 +	{ "7F", "Kemco"								  },
 711.124 +	{ "7G", "Rage Software"						  },
 711.125 +	{ "7H", "Encore"							  },
 711.126 +	{ "7J", "Zoo"								  },
 711.127 +	{ "7K", "BVM"								  },
 711.128 +	{ "7L", "Simon & Schuster Interactive"		  },
 711.129 +	{ "7M", "Asmik Ace Entertainment Inc./AIA"	  },
 711.130 +	{ "7N", "Empire Interactive"				  },
 711.131 +	{ "7Q", "Jester Interactive"				  },
 711.132 +	{ "7T", "Scholastic"						  },
 711.133 +	{ "7U", "Ignition Entertainment"			  },
 711.134 +	{ "7W", "Stadlbauer"						  },
 711.135 +	{ "80", "Misawa"							  },
 711.136 +	{ "83", "LOZC"								  },
 711.137 +	{ "8B", "Bulletproof Software"				  },
 711.138 +	{ "8C", "Vic Tokai Inc."					  },
 711.139 +	{ "8J", "General Entertainment"				  },
 711.140 +	{ "8N", "Success"							  },
 711.141 +	{ "8P", "SEGA Japan"						  },
 711.142 +	{ "91", "Chun Soft"							  },
 711.143 +	{ "92", "Video System"						  },
 711.144 +	{ "93", "BEC"								  },
 711.145 +	{ "96", "Yonezawa/S'pal"					  },
 711.146 +	{ "97", "Kaneko"							  },
 711.147 +	{ "99", "Victor Interactive Software"		  },
 711.148 +	{ "9A", "Nichibutsu/Nihon Bussan"			  },
 711.149 +	{ "9B", "Tecmo"								  },
 711.150 +	{ "9C", "Imagineer"							  },
 711.151 +	{ "9F", "Nova"								  },
 711.152 +	{ "9H", "Bottom Up"							  },
 711.153 +	{ "9L", "Hasbro Japan"						  },
 711.154 +	{ "9N", "Marvelous Entertainment"			  },
 711.155 +	{ "9P", "Keynet Inc."						  },
 711.156 +	{ "9Q", "Hands-On Entertainment"			  },
 711.157 +	{ "A0", "Telenet"							  },
 711.158 +	{ "A1", "Hori"								  },
 711.159 +	{ "A4", "Konami"							  },
 711.160 +	{ "A6", "Kawada"							  },
 711.161 +	{ "A7", "Takara"							  },
 711.162 +	{ "A9", "Technos Japan Corp."				  },
 711.163 +	{ "AA", "JVC"								  },
 711.164 +	{ "AC", "Toei Animation"					  },
 711.165 +	{ "AD", "Toho"								  },
 711.166 +	{ "AF", "Namco"								  },
 711.167 +	{ "AG", "Media Rings Corporation"			  },
 711.168 +	{ "AH", "J-Wing"							  },
 711.169 +	{ "AK", "KID"								  },
 711.170 +	{ "AL", "MediaFactory"						  },
 711.171 +	{ "AP", "Infogrames Hudson"					  },
 711.172 +	{ "AQ", "Kiratto. Ludic Inc"				  },
 711.173 +	{ "B0", "Acclaim Japan"						  },
 711.174 +	{ "B1", "ASCII"								  },
 711.175 +	{ "B2", "Bandai"							  },
 711.176 +	{ "B4", "Enix"								  },
 711.177 +	{ "B6", "HAL Laboratory"					  },
 711.178 +	{ "B7", "SNK"								  },
 711.179 +	{ "B9", "Pony Canyon Hanbai"				  },
 711.180 +	{ "BA", "Culture Brain"						  },
 711.181 +	{ "BB", "Sunsoft"							  },
 711.182 +	{ "BD", "Sony Imagesoft"					  },
 711.183 +	{ "BF", "Sammy"								  },
 711.184 +	{ "BG", "Magical"							  },
 711.185 +	{ "BJ", "Compile"							  },
 711.186 +	{ "BL", "MTO Inc."							  },
 711.187 +	{ "BN", "Sunrise Interactive"				  },
 711.188 +	{ "BP", "Global A Entertainment"			  },
 711.189 +	{ "BQ", "Fuuki"								  },
 711.190 +	{ "C0", "Taito"								  },
 711.191 +	{ "C2", "Kemco"								  },
 711.192 +	{ "C3", "Square Soft"						  },
 711.193 +	{ "C5", "Data East"							  },
 711.194 +	{ "C6", "Tonkin House"						  },
 711.195 +	{ "C8", "Koei"								  },
 711.196 +	{ "CA", "Konami/Palcom/Ultra"				  },
 711.197 +	{ "CB", "Vapinc/NTVIC"						  },
 711.198 +	{ "CC", "Use Co.,Ltd."						  },
 711.199 +	{ "CD", "Meldac"							  },
 711.200 +	{ "CE", "FCI/Pony Canyon"					  },
 711.201 +	{ "CF", "Angel"								  },
 711.202 +	{ "CM", "Konami Computer Entertainment Osaka" },
 711.203 +	{ "CP", "Enterbrain"						  },
 711.204 +	{ "D1", "Sofel"								  },
 711.205 +	{ "D2", "Quest"								  },
 711.206 +	{ "D3", "Sigma Enterprises"					  },
 711.207 +	{ "D4", "Ask Kodansa"						  },
 711.208 +	{ "D6", "Naxat"								  },
 711.209 +	{ "D7", "Copya System"						  },
 711.210 +	{ "D9", "Banpresto"							  },
 711.211 +	{ "DA", "TOMY"								  },
 711.212 +	{ "DB", "LJN Japan"							  },
 711.213 +	{ "DD", "NCS"								  },
 711.214 +	{ "DF", "Altron Corporation"				  },
 711.215 +	{ "DH", "Gaps Inc."							  },
 711.216 +	{ "DN", "ELF"								  },
 711.217 +	{ "E2", "Yutaka"							  },
 711.218 +	{ "E3", "Varie"								  },
 711.219 +	{ "E5", "Epoch"								  },
 711.220 +	{ "E7", "Athena"							  },
 711.221 +	{ "E8", "Asmik Ace Entertainment Inc."		  },
 711.222 +	{ "E9", "Natsume"							  },
 711.223 +	{ "EA", "King Records"						  },
 711.224 +	{ "EB", "Atlus"								  },
 711.225 +	{ "EC", "Epic/Sony Records"					  },
 711.226 +	{ "EE", "IGS"								  },
 711.227 +	{ "EL", "Spike"								  },
 711.228 +	{ "EM", "Konami Computer Entertainment Tokyo" },
 711.229 +	{ "EN", "Alphadream Corporation"			  },
 711.230 +	{ "F0", "A Wave"							  },
 711.231 +	{ "G1", "PCCW"								  },
 711.232 +	{ "G4", "KiKi Co Ltd"						  },
 711.233 +	{ "G5", "Open Sesame Inc."					  },
 711.234 +	{ "G6", "Sims"								  },
 711.235 +	{ "G7", "Broccoli"							  },
 711.236 +	{ "G8", "Avex"								  },
 711.237 +	{ "G9", "D3 Publisher"						  },
 711.238 +	{ "GB", "Konami Computer Entertainment Japan" },
 711.239 +	{ "GD", "Square-Enix"						  },
 711.240 +	{ "HY", "Sachen"							  },
 711.241 +	{ NULL, NULL								  }
 711.242 +};
 711.243 +
 711.244 +static LPCTSTR winGBARomInfoFindMakerCode(LPCTSTR code)
 711.245 +{
 711.246 +	int i = 0;
 711.247 +	while (winGBARomInfoCompanies[i].code)
 711.248 +	{
 711.249 +		if (!strcmp(winGBARomInfoCompanies[i].code, code))
 711.250 +			return winGBARomInfoCompanies[i].name;
 711.251 +		i++;
 711.252 +	}
 711.253 +	return (LPCTSTR)winResLoadString(IDS_UNKNOWN);
 711.254 +}
 711.255 +
 711.256 +/////////////////////////////////////////////////////////////////////////////
 711.257 +// RomInfoGB dialog
 711.258 +
 711.259 +RomInfoGB::RomInfoGB(u8 *rom, CWnd *pParent /*=NULL*/)
 711.260 +	: CDialog(RomInfoGB::IDD, pParent)
 711.261 +{
 711.262 +	//{{AFX_DATA_INIT(RomInfoGB)
 711.263 +	// NOTE: the ClassWizard will add member initialization here
 711.264 +	//}}AFX_DATA_INIT
 711.265 +	this->rom = rom;
 711.266 +}
 711.267 +
 711.268 +void RomInfoGB::DoDataExchange(CDataExchange *pDX)
 711.269 +{
 711.270 +	CDialog::DoDataExchange(pDX);
 711.271 +	//{{AFX_DATA_MAP(RomInfoGB)
 711.272 +	// NOTE: the ClassWizard will add DDX and DDV calls here
 711.273 +	//}}AFX_DATA_MAP
 711.274 +}
 711.275 +
 711.276 +BEGIN_MESSAGE_MAP(RomInfoGB, CDialog)
 711.277 +//{{AFX_MSG_MAP(RomInfoGB)
 711.278 +ON_BN_CLICKED(ID_OK, OnOk)
 711.279 +//}}AFX_MSG_MAP
 711.280 +END_MESSAGE_MAP()
 711.281 +
 711.282 +/////////////////////////////////////////////////////////////////////////////
 711.283 +// RomInfoGB message handlers
 711.284 +
 711.285 +void RomInfoGB::OnOk()
 711.286 +{
 711.287 +	EndDialog(TRUE);
 711.288 +}
 711.289 +
 711.290 +BOOL RomInfoGB::OnInitDialog()
 711.291 +{
 711.292 +	CDialog::OnInitDialog();
 711.293 +
 711.294 +	char buffer[128];
 711.295 +
 711.296 +	strncpy(buffer, (const char *)&rom[0x134], 15);
 711.297 +	buffer[15] = 0;
 711.298 +	GetDlgItem(IDC_ROM_TITLE)->SetWindowText(buffer);
 711.299 +
 711.300 +	sprintf(buffer, "%02x", rom[0x143]);
 711.301 +	GetDlgItem(IDC_ROM_COLOR)->SetWindowText(buffer);
 711.302 +
 711.303 +	strncpy(buffer, (const char *)&rom[0x144], 2);
 711.304 +	buffer[2] = 0;
 711.305 +	GetDlgItem(IDC_ROM_MAKER_CODE)->SetWindowText(buffer);
 711.306 +
 711.307 +	if (rom[0x14b] != 0x33)
 711.308 +	{
 711.309 +		sprintf(buffer, "%02X", rom[0x14b]);
 711.310 +		GetDlgItem(IDC_ROM_MAKER_CODE)->SetWindowText(buffer);
 711.311 +	}
 711.312 +	GetDlgItem(IDC_ROM_MAKER_NAME2)->SetWindowText(winGBARomInfoFindMakerCode(buffer));
 711.313 +
 711.314 +	sprintf(buffer, "%02x", rom[0x146]);
 711.315 +	GetDlgItem(IDC_ROM_UNIT_CODE)->SetWindowText(buffer);
 711.316 +
 711.317 +	CString type = winResLoadString(IDS_UNKNOWN);
 711.318 +	switch (rom[0x147])
 711.319 +	{
 711.320 +	case 0x00:
 711.321 +		type = "ROM";
 711.322 +		break;
 711.323 +	case 0x01:
 711.324 +		type = "ROM+MBC1";
 711.325 +		break;
 711.326 +	case 0x02:
 711.327 +		type = "ROM+MBC1+RAM";
 711.328 +		break;
 711.329 +	case 0x03:
 711.330 +		type = "ROM+MBC1+RAM+BATT";
 711.331 +		break;
 711.332 +	case 0x05:
 711.333 +		type = "ROM+MBC2";
 711.334 +		break;
 711.335 +	case 0x06:
 711.336 +		type = "ROM+MBC2+BATT";
 711.337 +		break;
 711.338 +	case 0x0f:
 711.339 +		type = "ROM+MBC3+TIMER+BATT";
 711.340 +		break;
 711.341 +	case 0x10:
 711.342 +		type = "ROM+MBC3+TIMER+RAM+BATT";
 711.343 +		break;
 711.344 +	case 0x11:
 711.345 +		type = "ROM+MBC3";
 711.346 +		break;
 711.347 +	case 0x12:
 711.348 +		type = "ROM+MBC3+RAM";
 711.349 +		break;
 711.350 +	case 0x13:
 711.351 +		type = "ROM+MBC3+RAM+BATT";
 711.352 +		break;
 711.353 +	case 0x19:
 711.354 +		type = "ROM+MBC5";
 711.355 +		break;
 711.356 +	case 0x1a:
 711.357 +		type = "ROM+MBC5+RAM";
 711.358 +		break;
 711.359 +	case 0x1b:
 711.360 +		type = "ROM+MBC5+RAM+BATT";
 711.361 +		break;
 711.362 +	case 0x1c:
 711.363 +		type = "ROM+MBC5+RUMBLE";
 711.364 +		break;
 711.365 +	case 0x1d:
 711.366 +		type = "ROM+MBC5+RUMBLE+RAM";
 711.367 +		break;
 711.368 +	case 0x1e:
 711.369 +		type = "ROM+MBC5+RUMBLE+RAM+BATT";
 711.370 +		break;
 711.371 +	case 0x22:
 711.372 +		type = "ROM+MBC7+BATT";
 711.373 +		break;
 711.374 +	case 0xfe:
 711.375 +		type = "ROM+HuC-3";
 711.376 +		break;
 711.377 +	case 0xff:
 711.378 +		type = "ROM+HuC-1";
 711.379 +		break;
 711.380 +	}
 711.381 +	sprintf(buffer, "%02x (%s)", rom[0x147], (const char *)type);
 711.382 +	GetDlgItem(IDC_ROM_DEVICE_TYPE)->SetWindowText(buffer);
 711.383 +
 711.384 +	type = winResLoadString(IDS_UNKNOWN);
 711.385 +	switch (rom[0x148])
 711.386 +	{
 711.387 +	case 0:
 711.388 +		type = "32K";
 711.389 +		break;
 711.390 +	case 1:
 711.391 +		type = "64K";
 711.392 +		break;
 711.393 +	case 2:
 711.394 +		type = "128K";
 711.395 +		break;
 711.396 +	case 3:
 711.397 +		type = "256K";
 711.398 +		break;
 711.399 +	case 4:
 711.400 +		type = "512K";
 711.401 +		break;
 711.402 +	case 5:
 711.403 +		type = "1M";
 711.404 +		break;
 711.405 +	case 6:
 711.406 +		type = "2M";
 711.407 +		break;
 711.408 +	case 7:
 711.409 +		type = "4M";
 711.410 +		break;
 711.411 +	}
 711.412 +
 711.413 +	sprintf(buffer, "%02x (%s)", rom[0x148], (const char *)type);
 711.414 +	GetDlgItem(IDC_ROM_SIZE)->SetWindowText(buffer);
 711.415 +
 711.416 +	type = winResLoadString(IDS_UNKNOWN);
 711.417 +	switch (rom[0x149])
 711.418 +	{
 711.419 +	case 0:
 711.420 +		type = winResLoadString(IDS_NONE);
 711.421 +		break;
 711.422 +	case 1:
 711.423 +		type = "2K";
 711.424 +		break;
 711.425 +	case 2:
 711.426 +		type = "8K";
 711.427 +		break;
 711.428 +	case 3:
 711.429 +		type = "32K";
 711.430 +		break;
 711.431 +	case 4:
 711.432 +		type = "128K";
 711.433 +		break;
 711.434 +	case 5:
 711.435 +		type = "64K";
 711.436 +		break;
 711.437 +	}
 711.438 +
 711.439 +	sprintf(buffer, "%02x (%s)", rom[0x149], (const char *)type);
 711.440 +	GetDlgItem(IDC_ROM_RAM_SIZE)->SetWindowText(buffer);
 711.441 +
 711.442 +	sprintf(buffer, "%02x", rom[0x14a]);
 711.443 +	GetDlgItem(IDC_ROM_DEST_CODE)->SetWindowText(buffer);
 711.444 +
 711.445 +	sprintf(buffer, "%02x", rom[0x14b]);
 711.446 +	GetDlgItem(IDC_ROM_LIC_CODE)->SetWindowText(buffer);
 711.447 +
 711.448 +	sprintf(buffer, "%02x", rom[0x14c]);
 711.449 +	GetDlgItem(IDC_ROM_VERSION)->SetWindowText(buffer);
 711.450 +
 711.451 +	u8	crc8 = 25;
 711.452 +	int i;
 711.453 +	for (i = 0x134; i < 0x14d; i++)
 711.454 +	{
 711.455 +		crc8 = (crc8 + rom[i]) & 0xFF;
 711.456 +	}
 711.457 +
 711.458 +	crc8 = 256 - crc8;
 711.459 +
 711.460 +	sprintf(buffer, "%02x (%02x)", crc8, rom[0x14d]);
 711.461 +	GetDlgItem(IDC_ROM_CRC)->SetWindowText(buffer);
 711.462 +
 711.463 +	u16 crc16 = 0;
 711.464 +	for (i = 0; i < gbRomSize; i++)
 711.465 +	{
 711.466 +		crc16 = (crc16 + rom[i]) & 0xFFFF;
 711.467 +	}
 711.468 +
 711.469 +	crc16 -= rom[0x14e];
 711.470 +	crc16 -= rom[0x14f];
 711.471 +	sprintf(buffer, "%04x (%04x)", crc16, (rom[0x14e] << 8) | rom[0x14f]);
 711.472 +	GetDlgItem(IDC_ROM_CHECKSUM)->SetWindowText(buffer);
 711.473 +
 711.474 +	CenterWindow();
 711.475 +
 711.476 +	return TRUE; // return TRUE unless you set the focus to a control
 711.477 +	             // EXCEPTION: OCX Property Pages should return FALSE
 711.478 +}
 711.479 +
 711.480 +/////////////////////////////////////////////////////////////////////////////
 711.481 +// RomInfoGBA dialog
 711.482 +
 711.483 +RomInfoGBA::RomInfoGBA(u8 *rom, CWnd *pParent /*=NULL*/)
 711.484 +	: CDialog(RomInfoGBA::IDD, pParent)
 711.485 +{
 711.486 +	//{{AFX_DATA_INIT(RomInfoGBA)
 711.487 +	// NOTE: the ClassWizard will add member initialization here
 711.488 +	//}}AFX_DATA_INIT
 711.489 +	this->rom = rom;
 711.490 +}
 711.491 +
 711.492 +void RomInfoGBA::DoDataExchange(CDataExchange *pDX)
 711.493 +{
 711.494 +	CDialog::DoDataExchange(pDX);
 711.495 +	//{{AFX_DATA_MAP(RomInfoGBA)
 711.496 +	// NOTE: the ClassWizard will add DDX and DDV calls here
 711.497 +	//}}AFX_DATA_MAP
 711.498 +}
 711.499 +
 711.500 +BEGIN_MESSAGE_MAP(RomInfoGBA, CDialog)
 711.501 +//{{AFX_MSG_MAP(RomInfoGBA)
 711.502 +ON_BN_CLICKED(ID_OK, OnOk)
 711.503 +//}}AFX_MSG_MAP
 711.504 +END_MESSAGE_MAP()
 711.505 +
 711.506 +/////////////////////////////////////////////////////////////////////////////
 711.507 +// RomInfoGBA message handlers
 711.508 +
 711.509 +void RomInfoGBA::OnOk()
 711.510 +{
 711.511 +	EndDialog(TRUE);
 711.512 +}
 711.513 +
 711.514 +BOOL RomInfoGBA::OnInitDialog()
 711.515 +{
 711.516 +	CDialog::OnInitDialog();
 711.517 +
 711.518 +	char buffer[13];
 711.519 +
 711.520 +	strncpy(buffer, (const char *)&rom[0xa0], 12);
 711.521 +	buffer[12] = 0;
 711.522 +	GetDlgItem(IDC_ROM_TITLE)->SetWindowText(buffer);
 711.523 +
 711.524 +	strncpy(buffer, (const char *)&rom[0xac], 4);
 711.525 +	buffer[4] = 0;
 711.526 +	GetDlgItem(IDC_ROM_GAME_CODE)->SetWindowText(buffer);
 711.527 +
 711.528 +	strncpy(buffer, (const char *)&rom[0xb0], 2);
 711.529 +	buffer[2] = 0;
 711.530 +	GetDlgItem(IDC_ROM_MAKER_CODE)->SetWindowText(buffer);
 711.531 +
 711.532 +	GetDlgItem(IDC_ROM_MAKER_NAME)->SetWindowText(winGBARomInfoFindMakerCode(buffer));
 711.533 +
 711.534 +	sprintf(buffer, "%02x", rom[0xb3]);
 711.535 +	GetDlgItem(IDC_ROM_UNIT_CODE)->SetWindowText(buffer);
 711.536 +
 711.537 +	sprintf(buffer, "%02x", rom[0xb4]);
 711.538 +	GetDlgItem(IDC_ROM_DEVICE_TYPE)->SetWindowText(buffer);
 711.539 +
 711.540 +	sprintf(buffer, "%02x", rom[0xbc]);
 711.541 +	GetDlgItem(IDC_ROM_VERSION)->SetWindowText(buffer);
 711.542 +
 711.543 +	u8 crc = 0x19;
 711.544 +	for (int i = 0xa0; i < 0xbd; i++)
 711.545 +	{
 711.546 +		crc = (crc + rom[i]) & 0xff;
 711.547 +	}
 711.548 +
 711.549 +	crc = (-crc) & 0xff;
 711.550 +
 711.551 +	sprintf(buffer, "%02x (%02x)", crc, rom[0xbd]);
 711.552 +	GetDlgItem(IDC_ROM_CRC)->SetWindowText(buffer);
 711.553 +	CenterWindow();
 711.554 +
 711.555 +	return TRUE; // return TRUE unless you set the focus to a control
 711.556 +	             // EXCEPTION: OCX Property Pages should return FALSE
 711.557 +}
 711.558 +
   712.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   712.2 +++ b/src/win32/RomInfo.h	Sat Mar 03 10:31:27 2012 -0600
   712.3 @@ -0,0 +1,79 @@
   712.4 +#if !defined(AFX_ROMINFO_H__9888A45C_3E71_4C0F_B119_EFC74DFF8CD3__INCLUDED_)
   712.5 +#define AFX_ROMINFO_H__9888A45C_3E71_4C0F_B119_EFC74DFF8CD3__INCLUDED_
   712.6 +
   712.7 +#if _MSC_VER > 1000
   712.8 +#pragma once
   712.9 +#endif // _MSC_VER > 1000
  712.10 +// -*- C++ -*-
  712.11 +// RomInfo.h : header file
  712.12 +//
  712.13 +
  712.14 +/////////////////////////////////////////////////////////////////////////////
  712.15 +// RomInfoGB dialog
  712.16 +
  712.17 +class RomInfoGB : public CDialog
  712.18 +{
  712.19 +	// Construction
  712.20 +public:
  712.21 +	RomInfoGB(u8 *rom, CWnd*pParent = NULL);  // standard constructor
  712.22 +
  712.23 +	// Dialog Data
  712.24 +	//{{AFX_DATA(RomInfoGB)
  712.25 +	enum { IDD = IDD_GB_ROM_INFO };
  712.26 +	// NOTE: the ClassWizard will add data members here
  712.27 +	//}}AFX_DATA
  712.28 +
  712.29 +	// Overrides
  712.30 +	// ClassWizard generated virtual function overrides
  712.31 +	//{{AFX_VIRTUAL(RomInfoGB)
  712.32 +protected:
  712.33 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  712.34 +	//}}AFX_VIRTUAL
  712.35 +	u8 *rom;
  712.36 +
  712.37 +	// Implementation
  712.38 +protected:
  712.39 +	// Generated message map functions
  712.40 +	//{{AFX_MSG(RomInfoGB)
  712.41 +	afx_msg void OnOk();
  712.42 +	virtual BOOL OnInitDialog();
  712.43 +	//}}AFX_MSG
  712.44 +	DECLARE_MESSAGE_MAP()
  712.45 +};
  712.46 +
  712.47 +/////////////////////////////////////////////////////////////////////////////
  712.48 +// RomInfoGBA dialog
  712.49 +
  712.50 +class RomInfoGBA : public CDialog
  712.51 +{
  712.52 +	// Construction
  712.53 +public:
  712.54 +	RomInfoGBA(u8 *rom, CWnd*pParent = NULL);  // standard constructor
  712.55 +
  712.56 +	// Dialog Data
  712.57 +	//{{AFX_DATA(RomInfoGBA)
  712.58 +	enum { IDD = IDD_GBA_ROM_INFO };
  712.59 +	// NOTE: the ClassWizard will add data members here
  712.60 +	//}}AFX_DATA
  712.61 +	u8 *rom;
  712.62 +
  712.63 +	// Overrides
  712.64 +	// ClassWizard generated virtual function overrides
  712.65 +	//{{AFX_VIRTUAL(RomInfoGBA)
  712.66 +protected:
  712.67 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  712.68 +	//}}AFX_VIRTUAL
  712.69 +
  712.70 +	// Implementation
  712.71 +protected:
  712.72 +	// Generated message map functions
  712.73 +	//{{AFX_MSG(RomInfoGBA)
  712.74 +	afx_msg void OnOk();
  712.75 +	virtual BOOL OnInitDialog();
  712.76 +	//}}AFX_MSG
  712.77 +	DECLARE_MESSAGE_MAP()
  712.78 +};
  712.79 +//{{AFX_INSERT_LOCATION}}
  712.80 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  712.81 +
  712.82 +#endif // !defined(AFX_ROMINFO_H__9888A45C_3E71_4C0F_B119_EFC74DFF8CD3__INCLUDED_)
   713.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   713.2 +++ b/src/win32/Sound.h	Sat Mar 03 10:31:27 2012 -0600
   713.3 @@ -0,0 +1,19 @@
   713.4 +#ifndef VBA_WIN32_SOUND_H
   713.5 +#define VBA_WIN32_SOUND_H
   713.6 +
   713.7 +class ISound
   713.8 +{
   713.9 +public:
  713.10 +	virtual ~ISound() {};
  713.11 +
  713.12 +	virtual bool init()   = 0;
  713.13 +	virtual void pause()  = 0;
  713.14 +	virtual void reset()  = 0;
  713.15 +	virtual void resume() = 0;
  713.16 +	virtual void write()  = 0;
  713.17 +	virtual void setSpeed(float rate) = 0;
  713.18 +	virtual bool isPlaying() = 0;
  713.19 +	virtual void clearAudioBuffer() {}
  713.20 +};
  713.21 +
  713.22 +#endif
   714.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   714.2 +++ b/src/win32/StringTokenizer.cpp	Sat Mar 03 10:31:27 2012 -0600
   714.3 @@ -0,0 +1,44 @@
   714.4 +// StringTokenizer.cpp: implementation of the StringTokenizer class.
   714.5 +//
   714.6 +//////////////////////////////////////////////////////////////////////
   714.7 +
   714.8 +#include "stdafx.h"
   714.9 +#include "StringTokenizer.h"
  714.10 +
  714.11 +//////////////////////////////////////////////////////////////////////
  714.12 +// Construction/Destruction
  714.13 +//////////////////////////////////////////////////////////////////////
  714.14 +
  714.15 +StringTokenizer::StringTokenizer(CString str, CString del)
  714.16 +{
  714.17 +	m_right = str;
  714.18 +	m_delim = del;
  714.19 +}
  714.20 +
  714.21 +StringTokenizer::~StringTokenizer()
  714.22 +{}
  714.23 +
  714.24 +const char *StringTokenizer::next()
  714.25 +{
  714.26 +	int index = m_right.FindOneOf(m_delim);
  714.27 +
  714.28 +	while (index == 0)
  714.29 +	{
  714.30 +		m_right = m_right.Right(m_right.GetLength()-1);
  714.31 +		index   = m_right.FindOneOf(m_delim);
  714.32 +	}
  714.33 +	if (index == -1)
  714.34 +	{
  714.35 +		if (m_right.IsEmpty())
  714.36 +			return NULL;
  714.37 +		m_token = m_right;
  714.38 +		m_right.Empty();
  714.39 +		return m_token;
  714.40 +	}
  714.41 +
  714.42 +	m_token = m_right.Left(index);
  714.43 +	m_right = m_right.Right(m_right.GetLength()-(1+index));
  714.44 +
  714.45 +	return m_token;
  714.46 +}
  714.47 +
   715.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   715.2 +++ b/src/win32/StringTokenizer.h	Sat Mar 03 10:31:27 2012 -0600
   715.3 @@ -0,0 +1,24 @@
   715.4 +// StringTokenizer.h: interface for the StringTokenizer class.
   715.5 +//
   715.6 +//////////////////////////////////////////////////////////////////////
   715.7 +
   715.8 +#if !defined(AFX_STRINGTOKENIZER_H__1AB4CD12_6B7A_49E4_A87F_75D3DC3FF20F__INCLUDED_)
   715.9 +#define AFX_STRINGTOKENIZER_H__1AB4CD12_6B7A_49E4_A87F_75D3DC3FF20F__INCLUDED_
  715.10 +
  715.11 +#if _MSC_VER > 1000
  715.12 +#pragma once
  715.13 +#endif // _MSC_VER > 1000
  715.14 +
  715.15 +class StringTokenizer
  715.16 +{
  715.17 +public:
  715.18 +	const char *next();
  715.19 +	StringTokenizer(CString str, CString token);
  715.20 +	virtual ~StringTokenizer();
  715.21 +private:
  715.22 +	CString m_token;
  715.23 +	CString m_delim;
  715.24 +	CString m_right;
  715.25 +};
  715.26 +
  715.27 +#endif // !defined(AFX_STRINGTOKENIZER_H__1AB4CD12_6B7A_49E4_A87F_75D3DC3FF20F__INCLUDED_)
   716.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   716.2 +++ b/src/win32/System.cpp	Sat Mar 03 10:31:27 2012 -0600
   716.3 @@ -0,0 +1,936 @@
   716.4 +// System.cpp : Defines the system behaviors for the emulator.
   716.5 +//
   716.6 +#include "stdafx.h"
   716.7 +#include "Sound.h"
   716.8 +#include "Input.h"
   716.9 +#include "IUpdate.h"
  716.10 +#include "ram_search.h"
  716.11 +#include "WinMiscUtil.h"
  716.12 +#include "WinResUtil.h"
  716.13 +#include "resource.h"
  716.14 +#include "VBA.h"
  716.15 +#include "../gba/GBA.h"
  716.16 +#include "../gba/GBAGlobals.h"
  716.17 +#include "../gba/GBASound.h"
  716.18 +#include "../gb/GB.h"
  716.19 +#include "../gb/gbGlobals.h"
  716.20 +//#include "../common/System.h"
  716.21 +#include "../common/movie.h"
  716.22 +#include "../common/vbalua.h"
  716.23 +#include "../common/Text.h"
  716.24 +#include "../common/Util.h"
  716.25 +#include "../common/nesvideos-piece.h"
  716.26 +#include "../version.h"
  716.27 +#include <cassert>
  716.28 +
  716.29 +struct EmulatedSystem theEmulator;
  716.30 +
  716.31 +u32	 RGB_LOW_BITS_MASK		 = 0;
  716.32 +int	 emulating				 = 0;
  716.33 +int	 systemCartridgeType	 = 0;
  716.34 +int	 systemSpeed			 = 0;
  716.35 +bool systemSoundOn			 = false;
  716.36 +u32	 systemColorMap32[0x10000];
  716.37 +u16	 systemColorMap16[0x10000];
  716.38 +u16	 systemGbPalette[24];
  716.39 +int	 systemRedShift			 = 0;
  716.40 +int	 systemBlueShift		 = 0;
  716.41 +int	 systemGreenShift		 = 0;
  716.42 +int	 systemColorDepth		 = 16;
  716.43 +int	 systemDebug			 = 0;
  716.44 +int	 systemVerbose			 = 0;
  716.45 +int	 systemFrameSkip		 = 0;
  716.46 +int	 systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
  716.47 +
  716.48 +const int32 INITIAL_SENSOR_VALUE = 2047;
  716.49 +
  716.50 +int32 sensorX = INITIAL_SENSOR_VALUE;
  716.51 +int32 sensorY = INITIAL_SENSOR_VALUE;
  716.52 +u16	  currentButtons [4] = { 0, 0, 0, 0 };	// constrain: never contains hacked buttons, only the lower 16 bits of each are used
  716.53 +u16   lastKeys = 0;
  716.54 +
  716.55 +// static_assertion that BUTTON_REGULAR_RECORDING_MASK should be an u16 constant
  716.56 +namespace { const void * const s_STATIC_ASSERTION_(static_cast<void *>(BUTTON_REGULAR_RECORDING_MASK & 0xFFFF0000)); }
  716.57 +
  716.58 +#define BMP_BUFFER_MAX_WIDTH (256)
  716.59 +#define BMP_BUFFER_MAX_HEIGHT (224)
  716.60 +#define BMP_BUFFER_MAX_DEPTH (4)
  716.61 +static u8 bmpBuffer[BMP_BUFFER_MAX_WIDTH * BMP_BUFFER_MAX_HEIGHT * BMP_BUFFER_MAX_DEPTH];
  716.62 +
  716.63 +static int s_stockThrottleValues[] = {
  716.64 +	6, 15, 25, 25, 37, 50, 75, 87, 100, 112, 125, 150, 200, 300, 400, 600, 800, 1000
  716.65 +};
  716.66 +
  716.67 +// systemXYZ: Win32 stuff
  716.68 +
  716.69 +// input
  716.70 +
  716.71 +void systemSetSensorX(int32 x)
  716.72 +{
  716.73 +	sensorX = x;
  716.74 +}
  716.75 +
  716.76 +void systemSetSensorY(int32 y)
  716.77 +{
  716.78 +	sensorY = y;
  716.79 +}
  716.80 +
  716.81 +void systemResetSensor()
  716.82 +{
  716.83 +	sensorX = sensorY = INITIAL_SENSOR_VALUE;
  716.84 +}
  716.85 +
  716.86 +int32 systemGetSensorX()
  716.87 +{
  716.88 +	return sensorX;
  716.89 +}
  716.90 +
  716.91 +int32 systemGetSensorY()
  716.92 +{
  716.93 +	return sensorY;
  716.94 +}
  716.95 +
  716.96 +// handles motion sensor input
  716.97 +void systemUpdateMotionSensor(int i)
  716.98 +{
  716.99 +	if (i < 0 || i > 3)
 716.100 +		i = 0;
 716.101 +
 716.102 +	if (currentButtons[i] & BUTTON_MASK_LEFT_MOTION)
 716.103 +	{
 716.104 +		sensorX += 3;
 716.105 +		if (sensorX > 2197)
 716.106 +			sensorX = 2197;
 716.107 +		if (sensorX < 2047)
 716.108 +			sensorX = 2057;
 716.109 +	}
 716.110 +	else if (currentButtons[i] & BUTTON_MASK_RIGHT_MOTION)
 716.111 +	{
 716.112 +		sensorX -= 3;
 716.113 +		if (sensorX < 1897)
 716.114 +			sensorX = 1897;
 716.115 +		if (sensorX > 2047)
 716.116 +			sensorX = 2037;
 716.117 +	}
 716.118 +	else if (sensorX > 2047)
 716.119 +	{
 716.120 +		sensorX -= 2;
 716.121 +		if (sensorX < 2047)
 716.122 +			sensorX = 2047;
 716.123 +	}
 716.124 +	else
 716.125 +	{
 716.126 +		sensorX += 2;
 716.127 +		if (sensorX > 2047)
 716.128 +			sensorX = 2047;
 716.129 +	}
 716.130 +
 716.131 +	if (currentButtons[i] & BUTTON_MASK_UP_MOTION)
 716.132 +	{
 716.133 +		sensorY += 3;
 716.134 +		if (sensorY > 2197)
 716.135 +			sensorY = 2197;
 716.136 +		if (sensorY < 2047)
 716.137 +			sensorY = 2057;
 716.138 +	}
 716.139 +	else if (currentButtons[i] & BUTTON_MASK_DOWN_MOTION)
 716.140 +	{
 716.141 +		sensorY -= 3;
 716.142 +		if (sensorY < 1897)
 716.143 +			sensorY = 1897;
 716.144 +		if (sensorY > 2047)
 716.145 +			sensorY = 2037;
 716.146 +	}
 716.147 +	else if (sensorY > 2047)
 716.148 +	{
 716.149 +		sensorY -= 2;
 716.150 +		if (sensorY < 2047)
 716.151 +			sensorY = 2047;
 716.152 +	}
 716.153 +	else
 716.154 +	{
 716.155 +		sensorY += 2;
 716.156 +		if (sensorY > 2047)
 716.157 +			sensorY = 2047;
 716.158 +	}
 716.159 +}
 716.160 +
 716.161 +int systemGetDefaultJoypad()
 716.162 +{
 716.163 +	return theApp.joypadDefault;
 716.164 +}
 716.165 +
 716.166 +void systemSetDefaultJoypad(int which)
 716.167 +{
 716.168 +	theApp.joypadDefault = which;
 716.169 +}
 716.170 +
 716.171 +bool systemReadJoypads()
 716.172 +{
 716.173 +	// this function is called at every frame, even if vba is fast-forwarded.
 716.174 +	// so we try to limit the input frequency here just in case.
 716.175 +	static u32 lastTime = systemGetClock();
 716.176 +	if ((u32)(systemGetClock() - lastTime) < 10)
 716.177 +		return false;
 716.178 +	lastTime = systemGetClock();
 716.179 +
 716.180 +	if (theApp.input)
 716.181 +		return theApp.input->readDevices();
 716.182 +	return false;
 716.183 +}
 716.184 +
 716.185 +u32 systemGetOriginalJoypad(int i, bool sensor)
 716.186 +{
 716.187 +	if (i < 0 || i > 3)
 716.188 +		i = 0;
 716.189 +
 716.190 +	u32 res = 0;
 716.191 +	if (theApp.input)
 716.192 +		res = theApp.input->readDevice(i, sensor);
 716.193 +
 716.194 +	// +auto input, XOR
 716.195 +	// maybe these should be moved into DirectInput.cpp
 716.196 +	if (theApp.autoFire || theApp.autoFire2)
 716.197 +	{
 716.198 +		res ^= (theApp.autoFireToggle ? theApp.autoFire : theApp.autoFire2);
 716.199 +		if (!theApp.autofireAccountForLag || !systemCounters.laggedLast)
 716.200 +		{
 716.201 +			theApp.autoFireToggle = !theApp.autoFireToggle;
 716.202 +		}
 716.203 +	}
 716.204 +	if (theApp.autoHold)
 716.205 +	{
 716.206 +		res ^= theApp.autoHold;
 716.207 +	}
 716.208 +
 716.209 +	// filter buttons
 716.210 +	// maybe better elsewhere?
 716.211 +	if (!theApp.allowLeftRight)
 716.212 +	{
 716.213 +		// disallow L+R or U+D to being pressed at the same time
 716.214 +		if ((res & (BUTTON_MASK_RIGHT | BUTTON_MASK_LEFT)) == (BUTTON_MASK_RIGHT | BUTTON_MASK_LEFT))
 716.215 +			res &= ~BUTTON_MASK_RIGHT;  // leave only LEFT on
 716.216 +		if ((res & (BUTTON_MASK_DOWN | BUTTON_MASK_UP)) == (BUTTON_MASK_DOWN | BUTTON_MASK_UP))
 716.217 +			res &= ~BUTTON_MASK_DOWN;  // leave only UP on
 716.218 +	}
 716.219 +
 716.220 +	if (!sensor)
 716.221 +	{
 716.222 +		if (res & BUTTON_MOTION_MASK)
 716.223 +			res &= ~BUTTON_MOTION_MASK;
 716.224 +	}
 716.225 +
 716.226 +	if (systemCartridgeType != 0 && !gbSgbMode) // regular GB has no L/R buttons
 716.227 +	{
 716.228 +		if (res & (BUTTON_GBA_ONLY))
 716.229 +			res &= ~BUTTON_GBA_ONLY;
 716.230 +	}
 716.231 +
 716.232 +	currentButtons[i] = res & BUTTON_REGULAR_RECORDING_MASK;
 716.233 +
 716.234 +	return res;
 716.235 +}
 716.236 +
 716.237 +u32 systemGetJoypad(int i, bool sensor)
 716.238 +{
 716.239 +	if (i < 0 || i > 3)
 716.240 +		i = 0;
 716.241 +
 716.242 +	// input priority: original+auto < Lua < frame search < movie, correct this if wrong
 716.243 +
 716.244 +	// get original+auto input
 716.245 +	u32 hackedButtons = systemGetOriginalJoypad(i, sensor) & BUTTON_NONRECORDINGONLY_MASK;
 716.246 +	u32 res = currentButtons[i];
 716.247 +
 716.248 +	// since movie input has the highest priority, there's no point to read from other input
 716.249 +	if (VBAMoviePlaying())
 716.250 +	{
 716.251 +		// VBAMovieRead() overwrites currentButtons[i]
 716.252 +		VBAMovieRead(i, sensor);
 716.253 +		res = currentButtons[i];
 716.254 +	}
 716.255 +	else
 716.256 +	{
 716.257 +		// Lua input, shouldn't have any side effect within them
 716.258 +		if (VBALuaUsingJoypad(i))
 716.259 +			res = VBALuaReadJoypad(i);
 716.260 +
 716.261 +		// override input above
 716.262 +		if (theApp.frameSearchSkipping)
 716.263 +			res = theApp.frameSearchOldInput[i];
 716.264 +
 716.265 +		// flush non-hack buttons into the "current buttons" input buffer, which will be read by the movie routine
 716.266 +		currentButtons[i] = res & BUTTON_REGULAR_RECORDING_MASK;
 716.267 +		VBAMovieWrite(i, sensor);
 716.268 +	}
 716.269 +
 716.270 +	return res | hackedButtons;
 716.271 +}
 716.272 +
 716.273 +void systemSetJoypad(int which, u32 buttons)
 716.274 +{
 716.275 +	if (which < 0 || which > 3)
 716.276 +		which = 0;
 716.277 +
 716.278 +	currentButtons[which] = buttons;
 716.279 +
 716.280 +	lastKeys = 0;
 716.281 +}
 716.282 +
 716.283 +void systemClearJoypads()
 716.284 +{
 716.285 +	for (int i = 0; i < 3; ++i)
 716.286 +		currentButtons[i] = 0;
 716.287 +
 716.288 +	lastKeys = 0;
 716.289 +}
 716.290 +
 716.291 +// screen
 716.292 +
 716.293 +// delayed repaint
 716.294 +void systemRefreshScreen()
 716.295 +{
 716.296 +	if (theApp.m_pMainWnd)
 716.297 +	{
 716.298 +		theApp.m_pMainWnd->PostMessage(WM_PAINT, NULL, NULL);
 716.299 +	}
 716.300 +}
 716.301 +
 716.302 +extern bool vbaShuttingDown;
 716.303 +
 716.304 +void systemRenderFrame()
 716.305 +{
 716.306 +	extern long linearSoundFrameCount;
 716.307 +	extern long linearFrameCount;
 716.308 +
 716.309 +	if (vbaShuttingDown)
 716.310 +		return;
 716.311 +
 716.312 +	++theApp.renderedFrames;
 716.313 +
 716.314 +	VBAUpdateFrameCountDisplay();
 716.315 +	VBAUpdateButtonPressDisplay();
 716.316 +
 716.317 +	// "in-game" text rendering
 716.318 +	if (textMethod == 0) // transparent text can only be painted once, so timed messages will not be updated
 716.319 +	{
 716.320 +		extern void DrawLuaGui();
 716.321 +		DrawLuaGui();
 716.322 +
 716.323 +		int copyX = 240, copyY = 160;
 716.324 +		if (systemCartridgeType == 1)
 716.325 +			if (gbBorderOn)
 716.326 +				copyX = 256, copyY = 224;
 716.327 +			else
 716.328 +				copyX = 160, copyY = 144;
 716.329 +		int pitch = copyX * (systemColorDepth / 8) + (systemColorDepth == 24 ? 0 : 4);  // FIXME: sure?
 716.330 +
 716.331 +		DrawTextMessages((u8 *)pix, pitch, 0, copyY);
 716.332 +	}
 716.333 +
 716.334 +	++linearFrameCount;
 716.335 +	if (!theApp.sound)
 716.336 +	{
 716.337 +		if (linearFrameCount > 10000)
 716.338 +			linearFrameCount -= 10000;
 716.339 +		linearSoundFrameCount = linearFrameCount;
 716.340 +	}
 716.341 +
 716.342 +	// record avi
 716.343 +	int width  = 240;
 716.344 +	int height = 160;
 716.345 +	switch (systemCartridgeType)
 716.346 +	{
 716.347 +	case 0:
 716.348 +		width  = 240;
 716.349 +		height = 160;
 716.350 +		break;
 716.351 +	case 1:
 716.352 +		if (gbBorderOn)
 716.353 +		{
 716.354 +			width  = 256;
 716.355 +			height = 224;
 716.356 +		}
 716.357 +		else
 716.358 +		{
 716.359 +			width  = 160;
 716.360 +			height = 144;
 716.361 +		}
 716.362 +		break;
 716.363 +	}
 716.364 +
 716.365 +	bool firstFrameLogged = false;
 716.366 +	--linearFrameCount;
 716.367 +	do
 716.368 +	{
 716.369 +		++linearFrameCount;
 716.370 +
 716.371 +		if (theApp.aviRecording && (!theApp.altAviRecordMethod || (theApp.altAviRecordMethod && !firstFrameLogged)))
 716.372 +		{
 716.373 +			// usually aviRecorder is created when vba starts avi recording, though
 716.374 +			if (theApp.aviRecorder == NULL)
 716.375 +			{
 716.376 +				theApp.aviRecorder = new AVIWrite();
 716.377 +
 716.378 +				theApp.aviRecorder->SetFPS(60);
 716.379 +
 716.380 +				BITMAPINFOHEADER bi;
 716.381 +				memset(&bi, 0, sizeof(bi));
 716.382 +				bi.biSize	   = 0x28;
 716.383 +				bi.biPlanes	   = 1;
 716.384 +				bi.biBitCount  = 24;
 716.385 +				bi.biWidth	   = width;
 716.386 +				bi.biHeight	   = height;
 716.387 +				bi.biSizeImage = 3 * width * height;
 716.388 +				theApp.aviRecorder->SetVideoFormat(&bi);
 716.389 +				if (!theApp.aviRecorder->Open(theApp.aviRecordName))
 716.390 +				{
 716.391 +					delete theApp.aviRecorder;
 716.392 +					theApp.aviRecorder	= NULL;
 716.393 +					theApp.aviRecording = false;
 716.394 +				}
 716.395 +			}
 716.396 +
 716.397 +			if (theApp.aviRecorder != NULL && !theApp.aviRecorder->IsPaused())
 716.398 +			{
 716.399 +				assert(
 716.400 +				    width <= BMP_BUFFER_MAX_WIDTH && height <= BMP_BUFFER_MAX_HEIGHT && systemColorDepth <=
 716.401 +				    BMP_BUFFER_MAX_DEPTH * 8);
 716.402 +				utilWriteBMP(bmpBuffer, width, height, systemColorDepth, pix);
 716.403 +				theApp.aviRecorder->AddFrame(bmpBuffer);
 716.404 +			}
 716.405 +		}
 716.406 +
 716.407 +		if (theApp.nvVideoLog)
 716.408 +		{
 716.409 +			// convert from whatever bit depth to 16-bit, while stripping away extra pixels
 716.410 +			assert(width <= BMP_BUFFER_MAX_WIDTH && height <= BMP_BUFFER_MAX_HEIGHT && 16 <= BMP_BUFFER_MAX_DEPTH * 8);
 716.411 +			utilWriteBMP(bmpBuffer, width, -height, 16, pix);
 716.412 +			NESVideoLoggingVideo((u8 *)bmpBuffer, width, height, 0x1000000 * 60);
 716.413 +		}
 716.414 +
 716.415 +		firstFrameLogged = true;
 716.416 +	}
 716.417 +	while (linearFrameCount < linearSoundFrameCount); // compensate for frames lost due to frame skip being nonzero, etc.
 716.418 +
 716.419 +	if (textMethod != 0) // do not draw Lua HUD to a video dump
 716.420 +	{
 716.421 +		extern void DrawLuaGui();
 716.422 +		DrawLuaGui();
 716.423 +	}
 716.424 +
 716.425 +	// interframe blending
 716.426 +	if (theApp.ifbFunction)
 716.427 +	{
 716.428 +		if (systemColorDepth == 16)
 716.429 +			theApp.ifbFunction(pix + theApp.filterWidth * 2 + 4, theApp.filterWidth * 2 + 4,
 716.430 +			                   theApp.filterWidth, theApp.filterHeight);
 716.431 +		else
 716.432 +			theApp.ifbFunction(pix + theApp.filterWidth * 4 + 4, theApp.filterWidth * 4 + 4,
 716.433 +			                   theApp.filterWidth, theApp.filterHeight);
 716.434 +	}
 716.435 +
 716.436 +	systemRedrawScreen();
 716.437 +}
 716.438 +
 716.439 +void systemRedrawScreen()
 716.440 +{
 716.441 +	if (vbaShuttingDown)
 716.442 +		return;
 716.443 +
 716.444 +	if (theApp.display)
 716.445 +		theApp.display->render();
 716.446 +
 716.447 +	systemUpdateListeners();
 716.448 +}
 716.449 +
 716.450 +void systemUpdateListeners()
 716.451 +{
 716.452 +	if (vbaShuttingDown)
 716.453 +		return;
 716.454 +
 716.455 +	Update_RAM_Search(); // updates RAM search and RAM watch
 716.456 +
 716.457 +	// update viewers etc.
 716.458 +	if (theApp.updateCount)
 716.459 +	{
 716.460 +		POSITION pos = theApp.updateList.GetHeadPosition();
 716.461 +		while (pos)
 716.462 +		{
 716.463 +			IUpdateListener *up = theApp.updateList.GetNext(pos);
 716.464 +			if (up)
 716.465 +				up->update();
 716.466 +		}
 716.467 +	}
 716.468 +}
 716.469 +
 716.470 +int systemScreenCapture(int captureNumber)
 716.471 +{
 716.472 +	return winScreenCapture(captureNumber);
 716.473 +}
 716.474 +
 716.475 +void systemMessage(int number, const char *defaultMsg, ...)
 716.476 +{
 716.477 +	CString buffer;
 716.478 +	va_list valist;
 716.479 +	CString msg = defaultMsg;
 716.480 +	if (number)
 716.481 +		msg = winResLoadString(number);
 716.482 +
 716.483 +	va_start(valist, defaultMsg);
 716.484 +	buffer.FormatV(msg, valist);
 716.485 +
 716.486 +	theApp.winCheckFullscreen();
 716.487 +	systemSoundClearBuffer();
 716.488 +	AfxGetApp()->m_pMainWnd->MessageBox(buffer, winResLoadString(IDS_ERROR), MB_OK | MB_ICONERROR);
 716.489 +
 716.490 +	va_end(valist);
 716.491 +}
 716.492 +
 716.493 +void systemScreenMessage(const char *msg, int slot, int duration, const char *colorList)
 716.494 +{
 716.495 +	if (slot < 0 || slot > SCREEN_MESSAGE_SLOTS)
 716.496 +		return;
 716.497 +
 716.498 +	theApp.screenMessage[slot] = true;
 716.499 +	theApp.screenMessageTime[slot]		  = GetTickCount();
 716.500 +	theApp.screenMessageDuration[slot]	  = duration;
 716.501 +	theApp.screenMessageBuffer[slot]	  = msg;
 716.502 +	theApp.screenMessageColorBuffer[slot] = colorList ? colorList : "";
 716.503 +
 716.504 +	if (theApp.screenMessageBuffer[slot].GetLength() > 40)
 716.505 +		theApp.screenMessageBuffer[slot] = theApp.screenMessageBuffer[slot].Left(40);
 716.506 +
 716.507 +	// update the display when a main slot message appears while the game is paused
 716.508 +	if (slot == 0 && (theApp.paused || (theApp.frameSearching)))
 716.509 +		systemRefreshScreen();
 716.510 +}
 716.511 +
 716.512 +void systemShowSpeed(int speed)
 716.513 +{
 716.514 +	systemSpeed = speed;
 716.515 +	theApp.showRenderedFrames = theApp.renderedFrames;
 716.516 +	theApp.renderedFrames	  = 0;
 716.517 +	if (theApp.videoOption <= VIDEO_4X && theApp.showSpeed)
 716.518 +	{
 716.519 +		CString buffer;
 716.520 +		if (theApp.showSpeed == 1)
 716.521 +			buffer.Format(VBA_NAME_AND_VERSION " %3d%%", systemSpeed);
 716.522 +		else
 716.523 +			buffer.Format(VBA_NAME_AND_VERSION " %3d%% (%d fps | %d skipped)",
 716.524 +			              systemSpeed,
 716.525 +			              theApp.showRenderedFrames,
 716.526 +			              systemFrameSkip);
 716.527 +
 716.528 +		systemSetTitle(buffer);
 716.529 +	}
 716.530 +}
 716.531 +
 716.532 +void systemSetTitle(const char *title)
 716.533 +{
 716.534 +	if (theApp.m_pMainWnd != NULL)
 716.535 +	{
 716.536 +		AfxGetApp()->m_pMainWnd->SetWindowText(title);
 716.537 +	}
 716.538 +}
 716.539 +
 716.540 +// timing/speed
 716.541 +
 716.542 +u32 systemGetClock()
 716.543 +{
 716.544 +	return timeGetTime();
 716.545 +}
 716.546 +
 716.547 +void systemIncreaseThrottle()
 716.548 +{
 716.549 +	int throttle = theApp.throttle;
 716.550 +
 716.551 +	if (throttle < 6)
 716.552 +		++throttle;
 716.553 +	else if (throttle < s_stockThrottleValues[_countof(s_stockThrottleValues) - 1])
 716.554 +	{
 716.555 +		int i = 0;
 716.556 +		while (throttle >= s_stockThrottleValues[i])
 716.557 +		{
 716.558 +			++i;
 716.559 +		}
 716.560 +		throttle = s_stockThrottleValues[i];
 716.561 +	}
 716.562 +
 716.563 +	systemSetThrottle(throttle);
 716.564 +}
 716.565 +
 716.566 +void systemDecreaseThrottle()
 716.567 +{
 716.568 +	int throttle = theApp.throttle;
 716.569 +
 716.570 +	if (throttle > 6)
 716.571 +	{
 716.572 +		int i = _countof(s_stockThrottleValues) - 1;
 716.573 +		while (throttle <= s_stockThrottleValues[i])
 716.574 +		{
 716.575 +			--i;
 716.576 +		}
 716.577 +		throttle = s_stockThrottleValues[i];
 716.578 +	}
 716.579 +	else if (throttle > 1)
 716.580 +		--throttle;
 716.581 +
 716.582 +	systemSetThrottle(throttle);
 716.583 +}
 716.584 +
 716.585 +void systemSetThrottle(int throttle)
 716.586 +{
 716.587 +	theApp.throttle = throttle;
 716.588 +	char str[256];
 716.589 +	sprintf(str, "%d%% throttle speed", theApp.throttle);
 716.590 +	systemScreenMessage(str);
 716.591 +}
 716.592 +
 716.593 +int systemGetThrottle()
 716.594 +{
 716.595 +	return theApp.throttle;
 716.596 +}
 716.597 +
 716.598 +void systemFrame()
 716.599 +{
 716.600 +	if (theApp.altAviRecordMethod && theApp.aviRecording)
 716.601 +	{
 716.602 +		if (theApp.aviRecorder)
 716.603 +		{
 716.604 +			if (!theApp.aviRecorder->IsSoundAdded())
 716.605 +			{
 716.606 +				WAVEFORMATEX wfx;
 716.607 +				memset(&wfx, 0, sizeof(wfx));
 716.608 +				wfx.wFormatTag		= WAVE_FORMAT_PCM;
 716.609 +				wfx.nChannels		= 2;
 716.610 +				wfx.nSamplesPerSec	= 44100 / soundQuality;
 716.611 +				wfx.wBitsPerSample	= 16;
 716.612 +				wfx.nBlockAlign		= (wfx.wBitsPerSample / 8) * wfx.nChannels;
 716.613 +				wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
 716.614 +				wfx.cbSize = 0;
 716.615 +				theApp.aviRecorder->SetSoundFormat(&wfx);
 716.616 +			}
 716.617 +			theApp.aviRecorder->AddSound((u8 *)soundFrameSound, soundFrameSoundWritten * 2);
 716.618 +		}
 716.619 +	}
 716.620 +
 716.621 +	soundFrameSoundWritten = 0;
 716.622 +
 716.623 +	// no more stupid updates :)
 716.624 +
 716.625 +	extern int quitAfterTime;                   // from VBA.cpp
 716.626 +	void	   VBAMovieStop(bool8 suppress_message); // from ../movie.cpp
 716.627 +	if (quitAfterTime >= 0 && systemCounters.frameCount == quitAfterTime)
 716.628 +	{
 716.629 +		VBAMovieStop(true);
 716.630 +		AfxPostQuitMessage(0);
 716.631 +	}
 716.632 +
 716.633 +	// change the sound speed, or set it to normal - must always do this or it won't get reset after a change, but that's OK
 716.634 +	// because it's inexpensive
 716.635 +	if (theApp.sound)
 716.636 +	{
 716.637 +		theApp.sound->setSpeed(
 716.638 +		    speedup || theApp.winPauseNextFrame || !synchronize || theApp.accuratePitchThrottle || theApp.useOldSync
 716.639 +			? 1.0f : (float)theApp.throttle / 100.0f);
 716.640 +	}
 716.641 +
 716.642 +	// if a throttle speed is set and we're not allowed to change the sound frequency to achieve it,
 716.643 +	// sleep for a certain amount each time we get here to approximate the necessary slowdown
 716.644 +	if (synchronize && (theApp.accuratePitchThrottle || !theApp.sound || theApp.throttle < 6) /*&& !theApp.winPauseNextFrame*/)
 716.645 +	{
 716.646 +		/// FIXME: this is still a horrible way of achieving a certain frame time
 716.647 +		///        (look at what Snes9x does - it's complicated but much much better)
 716.648 +
 716.649 +		static float sleepAmt = 0.0f; // variable to smooth out the sleeping amount so it doesn't oscillate so fast
 716.650 +//		if(!theApp.wasPaused) {
 716.651 +		if (!speedup)
 716.652 +		{
 716.653 +			u32 time = systemGetClock();
 716.654 +			u32 diff = time - theApp.throttleLastTime;
 716.655 +			if (theApp.wasPaused)
 716.656 +				diff = 0;
 716.657 +
 716.658 +			int target = (100000 / (60 * theApp.throttle));
 716.659 +			int d	   = (target - diff);
 716.660 +
 716.661 +			if (d > 1000) // added to avoid 500-day waits for vba to start emulating.
 716.662 +				d = 1000;  // I suspect most users aren't that patient, and would find 1 second to be a more reasonable delay.
 716.663 +
 716.664 +			sleepAmt = 0.8f * sleepAmt + 0.2f * (float)d;
 716.665 +			if (d - sleepAmt <= 1.5f && d - sleepAmt >= -1.5f)
 716.666 +				d = (int)(sleepAmt);
 716.667 +
 716.668 +			if (d > 0)
 716.669 +			{
 716.670 +				Sleep(d);
 716.671 +			}
 716.672 +		}
 716.673 +		theApp.throttleLastTime = systemGetClock();
 716.674 +		//}
 716.675 +		//else
 716.676 +		//{
 716.677 +		// Sleep(100);
 716.678 +		//}
 716.679 +	}
 716.680 +
 716.681 +	if (systemCounters.frameCount % 10 == 0)
 716.682 +	{
 716.683 +		if (theApp.rewindMemory)
 716.684 +		{
 716.685 +			if (++theApp.rewindCounter >= (theApp.rewindTimer))
 716.686 +			{
 716.687 +				theApp.rewindSaveNeeded = true;
 716.688 +				theApp.rewindCounter	= 0;
 716.689 +			}
 716.690 +		}
 716.691 +		if (systemSaveUpdateCounter)
 716.692 +		{
 716.693 +			if (--systemSaveUpdateCounter <= SYSTEM_SAVE_NOT_UPDATED)
 716.694 +			{
 716.695 +				winWriteBatteryFile();
 716.696 +				systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
 716.697 +			}
 716.698 +		}
 716.699 +	}
 716.700 +
 716.701 +	theApp.wasPaused = false;
 716.702 +///  theApp.autoFrameSkipLastTime = time;
 716.703 +}
 716.704 +
 716.705 +int systemFramesToSkip()
 716.706 +{
 716.707 +	int framesToSkip = systemFrameSkip;
 716.708 +
 716.709 +	bool fastForward = speedup;
 716.710 +
 716.711 +#if (defined(WIN32) && !defined(SDL))
 716.712 +	fastForward = (fastForward || theApp.frameSearchSkipping);
 716.713 +	int throttle = theApp.throttle;
 716.714 +	if (theApp.frameSearching && throttle < 100)
 716.715 +		throttle = 100;
 716.716 +#else
 716.717 +	extern int throttle;
 716.718 +#endif
 716.719 +
 716.720 +#if (defined(WIN32) && !defined(SDL))
 716.721 +	if (theApp.aviRecording || theApp.nvVideoLog)
 716.722 +	{
 716.723 +		framesToSkip = 0; // render all frames
 716.724 +	}
 716.725 +	else
 716.726 +	{
 716.727 +		if (fastForward)
 716.728 +			framesToSkip = 9;  // try 6 FPS during speedup
 716.729 +		else if (throttle != 100)
 716.730 +			framesToSkip = (framesToSkip * throttle) / 100;
 716.731 +	}
 716.732 +#endif
 716.733 +
 716.734 +	return framesToSkip;
 716.735 +}
 716.736 +
 716.737 +// sound
 716.738 +
 716.739 +bool systemSoundInit()
 716.740 +{
 716.741 +	if (theApp.sound)
 716.742 +		delete theApp.sound;
 716.743 +
 716.744 +	extern ISound *newDirectSound();
 716.745 +	theApp.sound = newDirectSound();
 716.746 +	return theApp.sound->init();
 716.747 +}
 716.748 +
 716.749 +void systemSoundShutdown()
 716.750 +{
 716.751 +	if (theApp.sound)
 716.752 +		delete theApp.sound;
 716.753 +	theApp.sound = NULL;
 716.754 +}
 716.755 +
 716.756 +void systemSoundPause()
 716.757 +{
 716.758 +	if (theApp.sound)
 716.759 +		theApp.sound->pause();
 716.760 +	soundPaused = 1;
 716.761 +}
 716.762 +
 716.763 +void systemSoundResume()
 716.764 +{
 716.765 +	if (theApp.sound)
 716.766 +		theApp.sound->resume();
 716.767 +	soundPaused = 0;
 716.768 +}
 716.769 +
 716.770 +bool systemSoundIsPaused()
 716.771 +{
 716.772 +//	return soundPaused;
 716.773 +	return !(theApp.sound && theApp.sound->isPlaying());
 716.774 +}
 716.775 +
 716.776 +void systemSoundClearBuffer()
 716.777 +{
 716.778 +	if (theApp.sound)
 716.779 +		theApp.sound->clearAudioBuffer();
 716.780 +}
 716.781 +
 716.782 +void systemSoundReset()
 716.783 +{
 716.784 +	if (theApp.sound)
 716.785 +		theApp.sound->reset();
 716.786 +}
 716.787 +
 716.788 +void systemSoundWriteToBuffer()
 716.789 +{
 716.790 +	if (theApp.sound)
 716.791 +		theApp.sound->write();
 716.792 +}
 716.793 +
 716.794 +bool systemSoundCanChangeQuality()
 716.795 +{
 716.796 +	return true;
 716.797 +}
 716.798 +
 716.799 +bool systemSoundSetQuality(int quality)
 716.800 +{
 716.801 +	if (systemCartridgeType == 0)
 716.802 +		soundSetQuality(quality);
 716.803 +	else
 716.804 +		gbSoundSetQuality(quality);
 716.805 +
 716.806 +	return true;
 716.807 +}
 716.808 +
 716.809 +// emulation
 716.810 +
 716.811 +bool systemIsEmulating()
 716.812 +{
 716.813 +	return emulating != 0;
 716.814 +}
 716.815 +
 716.816 +void systemGbBorderOn()
 716.817 +{
 716.818 +	if (vbaShuttingDown)
 716.819 +		return;
 716.820 +
 716.821 +	if (emulating && systemCartridgeType == 1)
 716.822 +	{
 716.823 +		theApp.updateWindowSize(theApp.videoOption);
 716.824 +	}
 716.825 +}
 716.826 +
 716.827 +bool systemIsRunningGBA()
 716.828 +{
 716.829 +	return (systemCartridgeType == 0);
 716.830 +}
 716.831 +
 716.832 +bool systemIsSpedUp()
 716.833 +{
 716.834 +	return theApp.speedupToggle;
 716.835 +}
 716.836 +
 716.837 +bool systemIsPaused()
 716.838 +{
 716.839 +	return theApp.paused;
 716.840 +}
 716.841 +
 716.842 +void systemSetPause(bool pause)
 716.843 +{
 716.844 +	if (pause)
 716.845 +	{
 716.846 +		capturePrevious	 = false;
 716.847 +		theApp.wasPaused = true;
 716.848 +		theApp.paused	 = true;
 716.849 +		theApp.speedupToggle = false;
 716.850 +		theApp.winPauseNextFrame = false;
 716.851 +		systemSoundPause();
 716.852 +		systemRefreshScreen();;
 716.853 +	}
 716.854 +	else
 716.855 +	{
 716.856 +		theApp.paused	 = false;
 716.857 +		systemSoundResume();
 716.858 +	}
 716.859 +}
 716.860 +
 716.861 +// aka. frame advance
 716.862 +bool systemPauseOnFrame()
 716.863 +{
 716.864 +	if (theApp.winPauseNextFrame)
 716.865 +	{
 716.866 +		if (!theApp.nextframeAccountForLag || !systemCounters.laggedLast)
 716.867 +		{
 716.868 +			theApp.winPauseNextFrame   = false;
 716.869 +			return true;
 716.870 +		}
 716.871 +	}
 716.872 +
 716.873 +	return false;
 716.874 +}
 716.875 +
 716.876 +bool systemLoadBIOS(const char *biosFileName, bool useBiosFile)
 716.877 +{
 716.878 +	bool use = false;
 716.879 +	if (systemCartridgeType == 0)
 716.880 +		use = CPULoadBios(biosFileName, useBiosFile);
 716.881 +	else
 716.882 +		use = false;
 716.883 +	return use;
 716.884 +}
 716.885 +
 716.886 +// FIXME: now platform-independant stuff
 716.887 +// it should be admitted that the naming schema/code organization is a whole mess
 716.888 +// these things should be moved somewhere else
 716.889 +
 716.890 +EmulatedSystemCounters systemCounters =
 716.891 +{
 716.892 +	// frameCount
 716.893 +	0,
 716.894 +	// lagCount
 716.895 +	0,
 716.896 +	// extraCount
 716.897 +	0,
 716.898 +	// lagged
 716.899 +	true,
 716.900 +	// laggedLast
 716.901 +	true,
 716.902 +};
 716.903 +
 716.904 +// VBAxyz stuff are not part of the core.
 716.905 +
 716.906 +void VBAOnEnteringFrameBoundary()
 716.907 +{
 716.908 +	CallRegisteredLuaFunctions(LUACALL_AFTEREMULATION);
 716.909 +
 716.910 +	if (VBALuaRunning())
 716.911 +	{
 716.912 +		VBALuaFrameBoundary();
 716.913 +	}
 716.914 +
 716.915 +	VBAMovieUpdateState();
 716.916 +}
 716.917 +
 716.918 +void VBAOnExitingFrameBoundary()
 716.919 +{
 716.920 +	;
 716.921 +}
 716.922 +
 716.923 +//////////////////////////////////////////////
 716.924 +// ultility
 716.925 +
 716.926 +extern void toolsLog(const char *);
 716.927 +
 716.928 +void log(const char *msg, ...)
 716.929 +{
 716.930 +	CString buffer;
 716.931 +	va_list valist;
 716.932 +
 716.933 +	va_start(valist, msg);
 716.934 +	buffer.FormatV(msg, valist);
 716.935 +
 716.936 +	toolsLog(buffer);
 716.937 +
 716.938 +	va_end(valist);
 716.939 +}
   717.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   717.2 +++ b/src/win32/TextOptions.cpp	Sat Mar 03 10:31:27 2012 -0600
   717.3 @@ -0,0 +1,81 @@
   717.4 +// TextOptions.cpp : implementation file
   717.5 +//
   717.6 +
   717.7 +#include "stdafx.h"
   717.8 +#include "../common/Text.h"
   717.9 +#include "resource.h"
  717.10 +#include "TextOptions.h"
  717.11 +
  717.12 +// TextOptions dialog
  717.13 +
  717.14 +IMPLEMENT_DYNAMIC(TextOptions, CDialog)
  717.15 +TextOptions::TextOptions(CWnd*pParent /*=NULL*/)
  717.16 +	: CDialog(TextOptions::IDD, pParent)
  717.17 +{}
  717.18 +
  717.19 +TextOptions::~TextOptions()
  717.20 +{}
  717.21 +
  717.22 +BOOL TextOptions::OnInitDialog()
  717.23 +{
  717.24 +	CDialog::OnInitDialog();
  717.25 +
  717.26 +	CheckRadioButton(IDC_RADIO_WHITE, IDC_RADIO_BLACK, IDC_RADIO_WHITE + textColor);
  717.27 +	CheckRadioButton(IDC_RADIO_PREFILTER, IDC_RADIO_POSTRENDER, IDC_RADIO_PREFILTER + textMethod);
  717.28 +	CheckDlgButton(IDC_CHECK_OUTLINED, outlinedText);
  717.29 +	CheckDlgButton(IDC_CHECK_TRANSPARENT, transparentText);
  717.30 +	GetDlgItem(IDC_CHECK_TRANSPARENT)->EnableWindow(GetCheckedRadioButton(IDC_RADIO_PREFILTER,
  717.31 +	                                                                      IDC_RADIO_POSTRENDER) != IDC_RADIO_POSTRENDER);
  717.32 +
  717.33 +	return TRUE;  // return TRUE unless you set the focus to a control
  717.34 +	// EXCEPTION: OCX Property Pages should return FALSE
  717.35 +}
  717.36 +
  717.37 +void TextOptions::DoDataExchange(CDataExchange*pDX)
  717.38 +{
  717.39 +	CDialog::DoDataExchange(pDX);
  717.40 +}
  717.41 +
  717.42 +BEGIN_MESSAGE_MAP(TextOptions, CDialog)
  717.43 +ON_BN_CLICKED(IDOK, OnBnClickedOk)
  717.44 +ON_BN_CLICKED(IDC_RADIO_PREFILTER, OnBnClickedRadioPrefilter)
  717.45 +ON_BN_CLICKED(IDC_RADIO_POSTFILTER, OnBnClickedRadioPostfilter)
  717.46 +ON_BN_CLICKED(IDC_RADIO_POSTRENDER, OnBnClickedRadioPostrender)
  717.47 +END_MESSAGE_MAP()
  717.48 +
  717.49 +// TextOptions message handlers
  717.50 +
  717.51 +void TextOptions::OnBnClickedOk()
  717.52 +{
  717.53 +	transparentText = IsDlgButtonChecked(IDC_CHECK_TRANSPARENT) != 0;
  717.54 +	outlinedText    = IsDlgButtonChecked(IDC_CHECK_OUTLINED) != 0;
  717.55 +	textMethod      = GetCheckedRadioButton(IDC_RADIO_PREFILTER, IDC_RADIO_POSTRENDER) - IDC_RADIO_PREFILTER;
  717.56 +	textColor       = GetCheckedRadioButton(IDC_RADIO_WHITE, IDC_RADIO_BLACK) - IDC_RADIO_WHITE;
  717.57 +	if (textMethod < 0)
  717.58 +		textMethod = 0;
  717.59 +	if (textMethod > 2)
  717.60 +		textMethod = 2;
  717.61 +	if (textColor < 0)
  717.62 +		textColor = 0;
  717.63 +	if (textColor > 7)
  717.64 +		textColor = 7;
  717.65 +
  717.66 +	OnOK();
  717.67 +}
  717.68 +
  717.69 +void TextOptions::OnBnClickedRadioPrefilter()
  717.70 +{
  717.71 +	GetDlgItem(IDC_CHECK_TRANSPARENT)->EnableWindow(TRUE);
  717.72 +}
  717.73 +
  717.74 +void TextOptions::OnBnClickedRadioPostfilter()
  717.75 +{
  717.76 +	GetDlgItem(IDC_CHECK_TRANSPARENT)->EnableWindow(TRUE);
  717.77 +}
  717.78 +
  717.79 +void TextOptions::OnBnClickedRadioPostrender()
  717.80 +{
  717.81 +	GetDlgItem(IDC_CHECK_TRANSPARENT)->EnableWindow(FALSE);
  717.82 +	CheckDlgButton(IDC_CHECK_TRANSPARENT, FALSE);
  717.83 +}
  717.84 +
   718.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   718.2 +++ b/src/win32/TextOptions.h	Sat Mar 03 10:31:27 2012 -0600
   718.3 @@ -0,0 +1,34 @@
   718.4 +#ifndef VBA_WIN32_TEXT_OPTIONS_H
   718.5 +#define VBA_WIN32_TEXT_OPTIONS_H
   718.6 +
   718.7 +#if _MSC_VER > 1000
   718.8 +#pragma once
   718.9 +#endif // _MSC_VER > 1000
  718.10 +
  718.11 +// TextOptions dialog
  718.12 +
  718.13 +class TextOptions : public CDialog
  718.14 +{
  718.15 +	DECLARE_DYNAMIC(TextOptions)
  718.16 +
  718.17 +public:
  718.18 +	TextOptions(CWnd* pParent = NULL);   // standard constructor
  718.19 +	virtual ~TextOptions();
  718.20 +
  718.21 +	virtual BOOL OnInitDialog() ;
  718.22 +
  718.23 +// Dialog Data
  718.24 +	enum { IDD = IDD_TEXTCONFIG };
  718.25 +
  718.26 +protected:
  718.27 +	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  718.28 +
  718.29 +	DECLARE_MESSAGE_MAP()
  718.30 +public:
  718.31 +	afx_msg void OnBnClickedOk();
  718.32 +	afx_msg void OnBnClickedRadioPrefilter();
  718.33 +	afx_msg void OnBnClickedRadioPostfilter();
  718.34 +	afx_msg void OnBnClickedRadioPostrender();
  718.35 +};
  718.36 +
  718.37 +#endif
   719.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   719.2 +++ b/src/win32/Throttle.cpp	Sat Mar 03 10:31:27 2012 -0600
   719.3 @@ -0,0 +1,62 @@
   719.4 +// Throttle.cpp : implementation file
   719.5 +//
   719.6 +
   719.7 +#include "stdafx.h"
   719.8 +#include "resource.h"
   719.9 +#include "Throttle.h"
  719.10 +#include "../common/System.h" // for system messages
  719.11 +
  719.12 +/////////////////////////////////////////////////////////////////////////////
  719.13 +// Throttle dialog
  719.14 +
  719.15 +Throttle::Throttle(CWnd*pParent /*=NULL*/)
  719.16 +	: CDialog(Throttle::IDD, pParent)
  719.17 +{
  719.18 +	//{{AFX_DATA_INIT(Throttle)
  719.19 +	m_throttle = 100;
  719.20 +	//}}AFX_DATA_INIT
  719.21 +}
  719.22 +
  719.23 +void Throttle::DoDataExchange(CDataExchange*pDX)
  719.24 +{
  719.25 +	CDialog::DoDataExchange(pDX);
  719.26 +	//{{AFX_DATA_MAP(Throttle)
  719.27 +	DDX_Text(pDX, IDC_THROTTLE, m_throttle);
  719.28 +	//}}AFX_DATA_MAP
  719.29 +}
  719.30 +
  719.31 +BEGIN_MESSAGE_MAP(Throttle, CDialog)
  719.32 +//{{AFX_MSG_MAP(Throttle)
  719.33 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
  719.34 +ON_BN_CLICKED(ID_OK, OnOk)
  719.35 +//}}AFX_MSG_MAP
  719.36 +END_MESSAGE_MAP()
  719.37 +
  719.38 +/////////////////////////////////////////////////////////////////////////////
  719.39 +// Throttle message handlers
  719.40 +
  719.41 +BOOL Throttle::OnInitDialog()
  719.42 +{
  719.43 +	CDialog::OnInitDialog();
  719.44 +
  719.45 +	CenterWindow();
  719.46 +
  719.47 +	return TRUE; // return TRUE unless you set the focus to a control
  719.48 +	             // EXCEPTION: OCX Property Pages should return FALSE
  719.49 +}
  719.50 +
  719.51 +void Throttle::OnCancel()
  719.52 +{
  719.53 +	EndDialog(false);
  719.54 +}
  719.55 +
  719.56 +void Throttle::OnOk()
  719.57 +{
  719.58 +	UpdateData();
  719.59 +
  719.60 +	if (m_throttle < 1 || m_throttle > 1000)
  719.61 +		systemMessage(IDS_INVALID_THROTTLE_VALUE, "Invalid throttle value. Please enter a number between 1 and 1000");
  719.62 +	else
  719.63 +		EndDialog(m_throttle);
  719.64 +}
  719.65 +
   720.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   720.2 +++ b/src/win32/Throttle.h	Sat Mar 03 10:31:27 2012 -0600
   720.3 @@ -0,0 +1,46 @@
   720.4 +#if !defined(AFX_THROTTLE_H__5F03B6E9_0C43_4933_A7BC_1618428C2B7F__INCLUDED_)
   720.5 +#define AFX_THROTTLE_H__5F03B6E9_0C43_4933_A7BC_1618428C2B7F__INCLUDED_
   720.6 +
   720.7 +#if _MSC_VER > 1000
   720.8 +#pragma once
   720.9 +#endif // _MSC_VER > 1000
  720.10 +// Throttle.h : header file
  720.11 +//
  720.12 +
  720.13 +/////////////////////////////////////////////////////////////////////////////
  720.14 +// Throttle dialog
  720.15 +
  720.16 +class Throttle : public CDialog
  720.17 +{
  720.18 +	// Construction
  720.19 +public:
  720.20 +	Throttle(CWnd*pParent = NULL);  // standard constructor
  720.21 +
  720.22 +	// Dialog Data
  720.23 +	//{{AFX_DATA(Throttle)
  720.24 +	enum { IDD = IDD_THROTTLE };
  720.25 +	int m_throttle;
  720.26 +	//}}AFX_DATA
  720.27 +
  720.28 +	// Overrides
  720.29 +	// ClassWizard generated virtual function overrides
  720.30 +	//{{AFX_VIRTUAL(Throttle)
  720.31 +protected:
  720.32 +	virtual void DoDataExchange(CDataExchange*pDX);   // DDX/DDV support
  720.33 +	//}}AFX_VIRTUAL
  720.34 +
  720.35 +	// Implementation
  720.36 +protected:
  720.37 +	// Generated message map functions
  720.38 +	//{{AFX_MSG(Throttle)
  720.39 +	virtual BOOL OnInitDialog();
  720.40 +	afx_msg void OnCancel();
  720.41 +	afx_msg void OnOk();
  720.42 +	//}}AFX_MSG
  720.43 +	DECLARE_MESSAGE_MAP()
  720.44 +};
  720.45 +
  720.46 +//{{AFX_INSERT_LOCATION}}
  720.47 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  720.48 +
  720.49 +#endif // !defined(AFX_THROTTLE_H__5F03B6E9_0C43_4933_A7BC_1618428C2B7F__INCLUDED_)
   721.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   721.2 +++ b/src/win32/TileView.cpp	Sat Mar 03 10:31:27 2012 -0600
   721.3 @@ -0,0 +1,582 @@
   721.4 +// TileView.cpp : implementation file
   721.5 +//
   721.6 +
   721.7 +#include "stdafx.h"
   721.8 +#include "resource.h"
   721.9 +#include "FileDlg.h"
  721.10 +#include "Reg.h"
  721.11 +#include "TileView.h"
  721.12 +#include "WinResUtil.h"
  721.13 +#include "VBA.h" // for theApp
  721.14 +
  721.15 +#include "../gba/GBAGlobals.h"
  721.16 +#include "../NLS.h"
  721.17 +#include "../common/Util.h"
  721.18 +
  721.19 +extern "C" {
  721.20 +#include <png.h>
  721.21 +}
  721.22 +
  721.23 +/////////////////////////////////////////////////////////////////////////////
  721.24 +// TileView dialog
  721.25 +
  721.26 +TileView::TileView(CWnd*pParent /*=NULL*/)
  721.27 +	: ResizeDlg(TileView::IDD, pParent)
  721.28 +{
  721.29 +	//{{AFX_DATA_INIT(TileView)
  721.30 +	m_colors   = -1;
  721.31 +	m_charBase = -1;
  721.32 +	m_stretch  = FALSE;
  721.33 +	//}}AFX_DATA_INIT
  721.34 +	autoUpdate = false;
  721.35 +
  721.36 +	memset(&bmpInfo, 0, sizeof(bmpInfo));
  721.37 +
  721.38 +	bmpInfo.bmiHeader.biSize        = sizeof(bmpInfo.bmiHeader);
  721.39 +	bmpInfo.bmiHeader.biWidth       = 32*8;
  721.40 +	bmpInfo.bmiHeader.biHeight      = 32*8;
  721.41 +	bmpInfo.bmiHeader.biPlanes      = 1;
  721.42 +	bmpInfo.bmiHeader.biBitCount    = 24;
  721.43 +	bmpInfo.bmiHeader.biCompression = BI_RGB;
  721.44 +	data = (u8 *)calloc(1, 3 * 32*32 * 64);
  721.45 +
  721.46 +	tileView.setData(data);
  721.47 +	tileView.setBmpInfo(&bmpInfo);
  721.48 +
  721.49 +	charBase    = 0;
  721.50 +	is256Colors = 0;
  721.51 +	palette     = 0;
  721.52 +	w = h = 0;
  721.53 +}
  721.54 +
  721.55 +TileView::~TileView()
  721.56 +{
  721.57 +	free(data);
  721.58 +	data = NULL;
  721.59 +}
  721.60 +
  721.61 +void TileView::DoDataExchange(CDataExchange*pDX)
  721.62 +{
  721.63 +	CDialog::DoDataExchange(pDX);
  721.64 +	//{{AFX_DATA_MAP(TileView)
  721.65 +	DDX_Control(pDX, IDC_PALETTE_SLIDER, m_slider);
  721.66 +	DDX_Radio(pDX, IDC_16_COLORS, m_colors);
  721.67 +	DDX_Radio(pDX, IDC_CHARBASE_0, m_charBase);
  721.68 +	DDX_Check(pDX, IDC_STRETCH, m_stretch);
  721.69 +	//}}AFX_DATA_MAP
  721.70 +	DDX_Control(pDX, IDC_TILE_VIEW, tileView);
  721.71 +	DDX_Control(pDX, IDC_MAP_VIEW_ZOOM, zoom);
  721.72 +	DDX_Control(pDX, IDC_COLOR, color);
  721.73 +}
  721.74 +
  721.75 +BEGIN_MESSAGE_MAP(TileView, CDialog)
  721.76 +//{{AFX_MSG_MAP(TileView)
  721.77 +ON_BN_CLICKED(IDC_SAVE, OnSave)
  721.78 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
  721.79 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
  721.80 +ON_BN_CLICKED(IDC_16_COLORS, On16Colors)
  721.81 +ON_BN_CLICKED(IDC_256_COLORS, On256Colors)
  721.82 +ON_BN_CLICKED(IDC_CHARBASE_0, OnCharbase0)
  721.83 +ON_BN_CLICKED(IDC_CHARBASE_1, OnCharbase1)
  721.84 +ON_BN_CLICKED(IDC_CHARBASE_2, OnCharbase2)
  721.85 +ON_BN_CLICKED(IDC_CHARBASE_3, OnCharbase3)
  721.86 +ON_BN_CLICKED(IDC_CHARBASE_4, OnCharbase4)
  721.87 +ON_BN_CLICKED(IDC_STRETCH, OnStretch)
  721.88 +ON_WM_HSCROLL()
  721.89 +//}}AFX_MSG_MAP
  721.90 +ON_MESSAGE(WM_MAPINFO, OnMapInfo)
  721.91 +ON_MESSAGE(WM_COLINFO, OnColInfo)
  721.92 +END_MESSAGE_MAP()
  721.93 +
  721.94 +/////////////////////////////////////////////////////////////////////////////
  721.95 +// TileView message handlers
  721.96 +
  721.97 +void TileView::saveBMP(const char *name)
  721.98 +{
  721.99 +	u8 writeBuffer[1024 * 3];
 721.100 +
 721.101 +	FILE *fp = fopen(name, "wb");
 721.102 +
 721.103 +	if (!fp)
 721.104 +	{
 721.105 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
 721.106 +		return;
 721.107 +	}
 721.108 +
 721.109 +	struct
 721.110 +	{
 721.111 +		u8 ident[2];
 721.112 +		u8 filesize[4];
 721.113 +		u8 reserved[4];
 721.114 +		u8 dataoffset[4];
 721.115 +		u8 headersize[4];
 721.116 +		u8 width[4];
 721.117 +		u8 height[4];
 721.118 +		u8 planes[2];
 721.119 +		u8 bitsperpixel[2];
 721.120 +		u8 compression[4];
 721.121 +		u8 datasize[4];
 721.122 +		u8 hres[4];
 721.123 +		u8 vres[4];
 721.124 +		u8 colors[4];
 721.125 +		u8 importantcolors[4];
 721.126 +		u8 pad[2];
 721.127 +	} bmpheader;
 721.128 +	memset(&bmpheader, 0, sizeof(bmpheader));
 721.129 +
 721.130 +	bmpheader.ident[0] = 'B';
 721.131 +	bmpheader.ident[1] = 'M';
 721.132 +
 721.133 +	u32 fsz = sizeof(bmpheader) + w*h*3;
 721.134 +	utilPutDword(bmpheader.filesize, fsz);
 721.135 +	utilPutDword(bmpheader.dataoffset, 0x38);
 721.136 +	utilPutDword(bmpheader.headersize, 0x28);
 721.137 +	utilPutDword(bmpheader.width, w);
 721.138 +	utilPutDword(bmpheader.height, h);
 721.139 +	utilPutDword(bmpheader.planes, 1);
 721.140 +	utilPutDword(bmpheader.bitsperpixel, 24);
 721.141 +	utilPutDword(bmpheader.datasize, 3*w*h);
 721.142 +
 721.143 +	fwrite(&bmpheader, 1, sizeof(bmpheader), fp);
 721.144 +
 721.145 +	u8 *b = writeBuffer;
 721.146 +
 721.147 +	int sizeX = w;
 721.148 +	int sizeY = h;
 721.149 +
 721.150 +	u8 *pixU8 = (u8 *)data+3*w*(h-1);
 721.151 +	for (int y = 0; y < sizeY; y++)
 721.152 +	{
 721.153 +		for (int x = 0; x < sizeX; x++)
 721.154 +		{
 721.155 +			*b++ = *pixU8++; // B
 721.156 +			*b++ = *pixU8++; // G
 721.157 +			*b++ = *pixU8++; // R
 721.158 +		}
 721.159 +		pixU8 -= 2*3*w;
 721.160 +		fwrite(writeBuffer, 1, 3*w, fp);
 721.161 +
 721.162 +		b = writeBuffer;
 721.163 +	}
 721.164 +
 721.165 +	fclose(fp);
 721.166 +}
 721.167 +
 721.168 +void TileView::savePNG(const char *name)
 721.169 +{
 721.170 +	u8 writeBuffer[1024 * 3];
 721.171 +
 721.172 +	FILE *fp = fopen(name, "wb");
 721.173 +
 721.174 +	if (!fp)
 721.175 +	{
 721.176 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
 721.177 +		return;
 721.178 +	}
 721.179 +
 721.180 +	png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
 721.181 +	                                              NULL,
 721.182 +	                                              NULL,
 721.183 +	                                              NULL);
 721.184 +	if (!png_ptr)
 721.185 +	{
 721.186 +		fclose(fp);
 721.187 +		return;
 721.188 +	}
 721.189 +
 721.190 +	png_infop info_ptr = png_create_info_struct(png_ptr);
 721.191 +
 721.192 +	if (!info_ptr)
 721.193 +	{
 721.194 +		png_destroy_write_struct(&png_ptr, NULL);
 721.195 +		fclose(fp);
 721.196 +		return;
 721.197 +	}
 721.198 +
 721.199 +	if (setjmp(png_ptr->jmpbuf))
 721.200 +	{
 721.201 +		png_destroy_write_struct(&png_ptr, NULL);
 721.202 +		fclose(fp);
 721.203 +		return;
 721.204 +	}
 721.205 +
 721.206 +	png_init_io(png_ptr, fp);
 721.207 +
 721.208 +	png_set_IHDR(png_ptr,
 721.209 +	             info_ptr,
 721.210 +	             w,
 721.211 +	             h,
 721.212 +	             8,
 721.213 +	             PNG_COLOR_TYPE_RGB,
 721.214 +	             PNG_INTERLACE_NONE,
 721.215 +	             PNG_COMPRESSION_TYPE_DEFAULT,
 721.216 +	             PNG_FILTER_TYPE_DEFAULT);
 721.217 +
 721.218 +	png_write_info(png_ptr, info_ptr);
 721.219 +
 721.220 +	u8 *b = writeBuffer;
 721.221 +
 721.222 +	int sizeX = w;
 721.223 +	int sizeY = h;
 721.224 +
 721.225 +	u8 *pixU8 = (u8 *)data;
 721.226 +	for (int y = 0; y < sizeY; y++)
 721.227 +	{
 721.228 +		for (int x = 0; x < sizeX; x++)
 721.229 +		{
 721.230 +			int blue  = *pixU8++;
 721.231 +			int green = *pixU8++;
 721.232 +			int red   = *pixU8++;
 721.233 +
 721.234 +			*b++ = red;
 721.235 +			*b++ = green;
 721.236 +			*b++ = blue;
 721.237 +		}
 721.238 +		png_write_row(png_ptr, writeBuffer);
 721.239 +
 721.240 +		b = writeBuffer;
 721.241 +	}
 721.242 +
 721.243 +	png_write_end(png_ptr, info_ptr);
 721.244 +
 721.245 +	png_destroy_write_struct(&png_ptr, &info_ptr);
 721.246 +
 721.247 +	fclose(fp);
 721.248 +}
 721.249 +
 721.250 +void TileView::OnSave()
 721.251 +{
 721.252 +	CString captureBuffer;
 721.253 +
 721.254 +	if (theApp.captureFormat == 0)
 721.255 +		captureBuffer = "tiles.png";
 721.256 +	else
 721.257 +		captureBuffer = "tiles.bmp";
 721.258 +
 721.259 +	LPCTSTR exts[] = {".png", ".bmp", NULL };
 721.260 +
 721.261 +	CString filter = winResLoadFilter(IDS_FILTER_PNG);
 721.262 +	CString title  = winResLoadString(IDS_SELECT_CAPTURE_NAME);
 721.263 +
 721.264 +	FileDlg dlg(this,
 721.265 +	            captureBuffer,
 721.266 +	            filter,
 721.267 +	            theApp.captureFormat ? 2 : 1,
 721.268 +	            theApp.captureFormat ? "BMP" : "PNG",
 721.269 +	            exts,
 721.270 +	            "",
 721.271 +	            title,
 721.272 +	            true);
 721.273 +
 721.274 +	if (dlg.DoModal() == IDCANCEL)
 721.275 +	{
 721.276 +		return;
 721.277 +	}
 721.278 +
 721.279 +	captureBuffer = dlg.GetPathName();
 721.280 +
 721.281 +	if (dlg.getFilterIndex() == 2)
 721.282 +		saveBMP(captureBuffer);
 721.283 +	else
 721.284 +		savePNG(captureBuffer);
 721.285 +}
 721.286 +
 721.287 +void TileView::renderTile256(int tile, int x, int y, u8 *charBase, u16 *palette)
 721.288 +{
 721.289 +	u8 *bmp = &data[24*x + 8*32*24*y];
 721.290 +
 721.291 +	for (int j = 0; j < 8; j++)
 721.292 +	{
 721.293 +		for (int i = 0; i < 8; i++)
 721.294 +		{
 721.295 +			u8 c = charBase[tile*64 + j * 8 + i];
 721.296 +
 721.297 +			u16 color = palette[c];
 721.298 +
 721.299 +			*bmp++ = ((color >> 10) & 0x1f) << 3;
 721.300 +			*bmp++ = ((color >> 5) & 0x1f) << 3;
 721.301 +			*bmp++ = (color & 0x1f) << 3;
 721.302 +		}
 721.303 +		bmp += 31*24; // advance line
 721.304 +	}
 721.305 +}
 721.306 +
 721.307 +void TileView::renderTile16(int tile, int x, int y, u8 *charBase, u16 *palette)
 721.308 +{
 721.309 +	u8 *bmp = &data[24*x + 8*32*24*y];
 721.310 +
 721.311 +	int pal = this->palette;
 721.312 +
 721.313 +	if (this->charBase == 4)
 721.314 +		pal += 16;
 721.315 +
 721.316 +	for (int j = 0; j < 8; j++)
 721.317 +	{
 721.318 +		for (int i = 0; i < 8; i++)
 721.319 +		{
 721.320 +			u8 c = charBase[tile*32 + j * 4 + (i>>1)];
 721.321 +
 721.322 +			if (i & 1)
 721.323 +				c = c>>4;
 721.324 +			else
 721.325 +				c = c & 15;
 721.326 +
 721.327 +			u16 color = palette[pal*16+c];
 721.328 +
 721.329 +			*bmp++ = ((color >> 10) & 0x1f) << 3;
 721.330 +			*bmp++ = ((color >> 5) & 0x1f) << 3;
 721.331 +			*bmp++ = (color & 0x1f) << 3;
 721.332 +		}
 721.333 +		bmp += 31*24; // advance line
 721.334 +	}
 721.335 +}
 721.336 +
 721.337 +void TileView::render()
 721.338 +{
 721.339 +	u16 *palette  = (u16 *)paletteRAM;
 721.340 +	u8 * charBase = &vram[this->charBase * 0x4000];
 721.341 +
 721.342 +	int maxY;
 721.343 +
 721.344 +	if (is256Colors)
 721.345 +	{
 721.346 +		int tile = 0;
 721.347 +		maxY = 16;
 721.348 +		for (int y = 0; y < maxY; y++)
 721.349 +		{
 721.350 +			for (int x = 0; x < 32; x++)
 721.351 +			{
 721.352 +				if (this->charBase == 4)
 721.353 +					renderTile256(tile, x, y, charBase, &palette[256]);
 721.354 +				else
 721.355 +					renderTile256(tile, x, y, charBase, palette);
 721.356 +				tile++;
 721.357 +			}
 721.358 +		}
 721.359 +		tileView.setSize(32*8, maxY*8);
 721.360 +		w = 32*8;
 721.361 +		h = maxY*8;
 721.362 +		SIZE s;
 721.363 +		s.cx = 32*8;
 721.364 +		s.cy = maxY*8;
 721.365 +		if (tileView.getStretch())
 721.366 +		{
 721.367 +			s.cx = s.cy = 1;
 721.368 +		}
 721.369 +		tileView.SetScrollSizes(MM_TEXT, s);
 721.370 +	}
 721.371 +	else
 721.372 +	{
 721.373 +		int tile = 0;
 721.374 +		maxY = 32;
 721.375 +		if (this->charBase == 3)
 721.376 +			maxY = 16;
 721.377 +		for (int y = 0; y < maxY; y++)
 721.378 +		{
 721.379 +			for (int x = 0; x < 32; x++)
 721.380 +			{
 721.381 +				renderTile16(tile, x, y, charBase, palette);
 721.382 +				tile++;
 721.383 +			}
 721.384 +		}
 721.385 +		tileView.setSize(32*8, maxY*8);
 721.386 +		w = 32*8;
 721.387 +		h = maxY*8;
 721.388 +		SIZE s;
 721.389 +		s.cx = 32*8;
 721.390 +		s.cy = maxY*8;
 721.391 +		if (tileView.getStretch())
 721.392 +		{
 721.393 +			s.cx = s.cy = 1;
 721.394 +		}
 721.395 +		tileView.SetScrollSizes(MM_TEXT, s);
 721.396 +	}
 721.397 +}
 721.398 +
 721.399 +void TileView::update()
 721.400 +{
 721.401 +	paint();
 721.402 +}
 721.403 +
 721.404 +BOOL TileView::OnInitDialog()
 721.405 +{
 721.406 +	CDialog::OnInitDialog();
 721.407 +
 721.408 +	DIALOG_SIZER_START(sz)
 721.409 +	DIALOG_SIZER_ENTRY(IDC_TILE_VIEW, DS_SizeX | DS_SizeY)
 721.410 +	DIALOG_SIZER_ENTRY(IDC_COLOR, DS_MoveY)
 721.411 +	DIALOG_SIZER_ENTRY(IDC_R, DS_MoveY)
 721.412 +	DIALOG_SIZER_ENTRY(IDC_G, DS_MoveY)
 721.413 +	DIALOG_SIZER_ENTRY(IDC_B, DS_MoveY)
 721.414 +	DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
 721.415 +	DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
 721.416 +	DIALOG_SIZER_ENTRY(IDC_SAVE, DS_MoveY)
 721.417 +	DIALOG_SIZER_END()
 721.418 +	SetData(sz,
 721.419 +	        TRUE,
 721.420 +	        HKEY_CURRENT_USER,
 721.421 +	        "Software\\Emulators\\VisualBoyAdvance\\Viewer\\TileView",
 721.422 +	        NULL);
 721.423 +
 721.424 +	m_colors   = is256Colors;
 721.425 +	m_charBase = charBase;
 721.426 +
 721.427 +	m_slider.SetRange(0, 15);
 721.428 +	m_slider.SetPageSize(4);
 721.429 +	m_slider.SetTicFreq(1);
 721.430 +
 721.431 +	paint();
 721.432 +
 721.433 +	m_stretch = regQueryDwordValue("tileViewStretch", 0);
 721.434 +	if (m_stretch)
 721.435 +		tileView.setStretch(true);
 721.436 +	UpdateData(FALSE);
 721.437 +
 721.438 +	return TRUE; // return TRUE unless you set the focus to a control
 721.439 +	             // EXCEPTION: OCX Property Pages should return FALSE
 721.440 +}
 721.441 +
 721.442 +void TileView::OnClose()
 721.443 +{
 721.444 +	theApp.winRemoveUpdateListener(this);
 721.445 +
 721.446 +	DestroyWindow();
 721.447 +}
 721.448 +
 721.449 +void TileView::OnAutoUpdate()
 721.450 +{
 721.451 +	autoUpdate = !autoUpdate;
 721.452 +	if (autoUpdate)
 721.453 +	{
 721.454 +		theApp.winAddUpdateListener(this);
 721.455 +	}
 721.456 +	else
 721.457 +	{
 721.458 +		theApp.winRemoveUpdateListener(this);
 721.459 +	}
 721.460 +}
 721.461 +
 721.462 +void TileView::paint()
 721.463 +{
 721.464 +	if (vram != NULL && paletteRAM != NULL)
 721.465 +	{
 721.466 +		render();
 721.467 +		tileView.refresh();
 721.468 +	}
 721.469 +}
 721.470 +
 721.471 +void TileView::On16Colors()
 721.472 +{
 721.473 +	is256Colors = 0;
 721.474 +	paint();
 721.475 +}
 721.476 +
 721.477 +void TileView::On256Colors()
 721.478 +{
 721.479 +	is256Colors = 1;
 721.480 +	paint();
 721.481 +}
 721.482 +
 721.483 +void TileView::OnCharbase0()
 721.484 +{
 721.485 +	charBase = 0;
 721.486 +	paint();
 721.487 +}
 721.488 +
 721.489 +void TileView::OnCharbase1()
 721.490 +{
 721.491 +	charBase = 1;
 721.492 +	paint();
 721.493 +}
 721.494 +
 721.495 +void TileView::OnCharbase2()
 721.496 +{
 721.497 +	charBase = 2;
 721.498 +	paint();
 721.499 +}
 721.500 +
 721.501 +void TileView::OnCharbase3()
 721.502 +{
 721.503 +	charBase = 3;
 721.504 +	paint();
 721.505 +}
 721.506 +
 721.507 +void TileView::OnCharbase4()
 721.508 +{
 721.509 +	charBase = 4;
 721.510 +	paint();
 721.511 +}
 721.512 +
 721.513 +void TileView::OnStretch()
 721.514 +{
 721.515 +	tileView.setStretch(!tileView.getStretch());
 721.516 +	paint();
 721.517 +	regSetDwordValue("tileViewStretch", tileView.getStretch());
 721.518 +}
 721.519 +
 721.520 +LRESULT TileView::OnMapInfo(WPARAM wParam, LPARAM lParam)
 721.521 +{
 721.522 +	u8 *colors = (u8 *)lParam;
 721.523 +	zoom.setColors(colors);
 721.524 +
 721.525 +	int x = (wParam & 0xFFFF)/8;
 721.526 +	int y = ((wParam >> 16) & 0xFFFF)/8;
 721.527 +
 721.528 +	u32 address = 0x6000000 + 0x4000 * charBase;
 721.529 +	int tile    = 32 * y + x;
 721.530 +	if (is256Colors)
 721.531 +		tile *= 2;
 721.532 +	address += 32 * tile;
 721.533 +
 721.534 +	CString buffer;
 721.535 +	buffer.Format("%d", tile);
 721.536 +	GetDlgItem(IDC_TILE_NUMBER)->SetWindowText(buffer);
 721.537 +
 721.538 +	buffer.Format("%08x", address);
 721.539 +	GetDlgItem(IDC_ADDRESS)->SetWindowText(buffer);
 721.540 +
 721.541 +	return TRUE;
 721.542 +}
 721.543 +
 721.544 +LRESULT TileView::OnColInfo(WPARAM wParam, LPARAM)
 721.545 +{
 721.546 +	u16 c = (u16)wParam;
 721.547 +
 721.548 +	color.setColor(c);
 721.549 +
 721.550 +	int r = (c & 0x1f);
 721.551 +	int g = (c & 0x3e0) >> 5;
 721.552 +	int b = (c & 0x7c00) >> 10;
 721.553 +
 721.554 +	CString buffer;
 721.555 +	buffer.Format("R: %d", r);
 721.556 +	GetDlgItem(IDC_R)->SetWindowText(buffer);
 721.557 +
 721.558 +	buffer.Format("G: %d", g);
 721.559 +	GetDlgItem(IDC_G)->SetWindowText(buffer);
 721.560 +
 721.561 +	buffer.Format("B: %d", b);
 721.562 +	GetDlgItem(IDC_B)->SetWindowText(buffer);
 721.563 +
 721.564 +	return TRUE;
 721.565 +}
 721.566 +
 721.567 +void TileView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar)
 721.568 +{
 721.569 +	switch (nSBCode)
 721.570 +	{
 721.571 +	case TB_THUMBPOSITION:
 721.572 +		palette = nPos;
 721.573 +		break;
 721.574 +	default:
 721.575 +		palette = m_slider.GetPos();
 721.576 +		break;
 721.577 +	}
 721.578 +	paint();
 721.579 +}
 721.580 +
 721.581 +void TileView::PostNcDestroy()
 721.582 +{
 721.583 +	delete this;
 721.584 +}
 721.585 +
   722.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   722.2 +++ b/src/win32/TileView.h	Sat Mar 03 10:31:27 2012 -0600
   722.3 @@ -0,0 +1,90 @@
   722.4 +#if !defined(AFX_TILEVIEW_H__055751EC_2DF3_495B_B643_29025465CD2E__INCLUDED_)
   722.5 +#define AFX_TILEVIEW_H__055751EC_2DF3_495B_B643_29025465CD2E__INCLUDED_
   722.6 +
   722.7 +#if _MSC_VER > 1000
   722.8 +#pragma once
   722.9 +#endif // _MSC_VER > 1000
  722.10 +// TileView.h : header file
  722.11 +//
  722.12 +
  722.13 +#include "BitmapControl.h"
  722.14 +#include "ColorControl.h"
  722.15 +#include "IUpdate.h"
  722.16 +#include "ResizeDlg.h"
  722.17 +#include "ZoomControl.h"
  722.18 +
  722.19 +/////////////////////////////////////////////////////////////////////////////
  722.20 +// TileView dialog
  722.21 +
  722.22 +class TileView : public ResizeDlg, IUpdateListener
  722.23 +{
  722.24 +  int charBase;
  722.25 +  int is256Colors;
  722.26 +  int palette;
  722.27 +  BitmapControl tileView;
  722.28 +  BITMAPINFO bmpInfo;
  722.29 +  u8 *data;
  722.30 +  ZoomControl zoom;
  722.31 +  ColorControl color;
  722.32 +  int w;
  722.33 +  int h;
  722.34 +  bool autoUpdate;
  722.35 +  // Construction
  722.36 + public:
  722.37 +  void paint();
  722.38 +  void render();
  722.39 +  void renderTile16(int tile, int x, int y, u8 *charBase, u16 *palette);
  722.40 +  void renderTile256(int tile, int x, int y, u8 *charBase, u16 *palette);
  722.41 +  void savePNG(const char *name);
  722.42 +  void saveBMP(const char *name);
  722.43 +  TileView(CWnd* pParent = NULL);   // standard constructor
  722.44 +  virtual ~TileView();
  722.45 +
  722.46 +  virtual void update();
  722.47 +
  722.48 +  // Dialog Data
  722.49 +  //{{AFX_DATA(TileView)
  722.50 +  enum { IDD = IDD_TILE_VIEWER };
  722.51 +  CSliderCtrl  m_slider;
  722.52 +  int    m_colors;
  722.53 +  int    m_charBase;
  722.54 +  BOOL  m_stretch;
  722.55 +  //}}AFX_DATA
  722.56 +
  722.57 +
  722.58 +  // Overrides
  722.59 +  // ClassWizard generated virtual function overrides
  722.60 +  //{{AFX_VIRTUAL(TileView)
  722.61 + protected:
  722.62 +  virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  722.63 +  virtual void PostNcDestroy();
  722.64 +  //}}AFX_VIRTUAL
  722.65 +
  722.66 +  // Implementation
  722.67 + protected:
  722.68 +  virtual afx_msg LRESULT OnMapInfo(WPARAM wParam, LPARAM lParam);
  722.69 +  virtual afx_msg LRESULT OnColInfo(WPARAM wParam, LPARAM lParam);
  722.70 +
  722.71 +  // Generated message map functions
  722.72 +  //{{AFX_MSG(TileView)
  722.73 +  afx_msg void OnSave();
  722.74 +  virtual BOOL OnInitDialog();
  722.75 +  afx_msg void OnClose();
  722.76 +  afx_msg void OnAutoUpdate();
  722.77 +  afx_msg void On16Colors();
  722.78 +  afx_msg void On256Colors();
  722.79 +  afx_msg void OnCharbase0();
  722.80 +  afx_msg void OnCharbase1();
  722.81 +  afx_msg void OnCharbase2();
  722.82 +  afx_msg void OnCharbase3();
  722.83 +  afx_msg void OnCharbase4();
  722.84 +  afx_msg void OnStretch();
  722.85 +  afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  722.86 +  //}}AFX_MSG
  722.87 +  DECLARE_MESSAGE_MAP()
  722.88 +    };
  722.89 +
  722.90 +    //{{AFX_INSERT_LOCATION}}
  722.91 +    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  722.92 +
  722.93 +#endif // !defined(AFX_TILEVIEW_H__055751EC_2DF3_495B_B643_29025465CD2E__INCLUDED_)
   723.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   723.2 +++ b/src/win32/VBA.clw	Sat Mar 03 10:31:27 2012 -0600
   723.3 @@ -0,0 +1,1715 @@
   723.4 +; CLW file contains information for the MFC ClassWizard
   723.5 +
   723.6 +[General Info]
   723.7 +Version=1
   723.8 +LastClass=Hyperlink
   723.9 +LastTemplate=CDialog
  723.10 +NewFileInclude1=#include "stdafx.h"
  723.11 +NewFileInclude2=#include "vba.h"
  723.12 +LastPage=0
  723.13 +
  723.14 +ClassCount=57
  723.15 +Class1=AboutDialog
  723.16 +Class2=Associate
  723.17 +Class3=ColorButton
  723.18 +Class4=ColorControl
  723.19 +Class5=Directories
  723.20 +Class6=ExportGSASnapshot
  723.21 +Class7=FileDlg
  723.22 +Class8=GBACheatSearch
  723.23 +Class9=AddCheat
  723.24 +Class10=GBACheatList
  723.25 +Class11=GBCheatSearch
  723.26 +Class12=AddGBCheat
  723.27 +Class13=GBColorDlg
  723.28 +Class14=GSACodeSelect
  723.29 +Class15=JoypadEditControl
  723.30 +Class16=JoypadConfig
  723.31 +Class17=MotionConfig
  723.32 +Class18=Hyperlink
  723.33 +Class19=LangSelect
  723.34 +Class20=MainWnd
  723.35 +Class21=ModeConfirm
  723.36 +Class22=RewindInterval
  723.37 +Class23=RomInfoGB
  723.38 +Class24=RomInfoGBA
  723.39 +Class25=SkinButton
  723.40 +Class26=Throttle
  723.41 +Class27=VBA
  723.42 +Class28=VideoMode
  723.43 +Class29=VideoDriverSelect
  723.44 +
  723.45 +ResourceCount=44
  723.46 +Resource1=IDD_MAX_SCALE
  723.47 +Resource2=IDD_GDB_WAITING
  723.48 +Resource3=IDD_GB_CHEAT_LIST
  723.49 +Resource4=IDD_CONFIG
  723.50 +Resource5=IDD_ADD_CHEAT_DLG
  723.51 +Resource6=IDD_GB_OAM_VIEW
  723.52 +Resource7=IDD_GB_ROM_INFO
  723.53 +Resource8=IDD_OPENDLG
  723.54 +Resource9=IDD_MAP_VIEW
  723.55 +Resource10=IDD_ABOUT
  723.56 +Resource11=IDD_CHEAT_LIST
  723.57 +Resource12=IDD_OAM_VIEW
  723.58 +Resource13=IDD_CODE_SELECT
  723.59 +Resource14=IDD_CHEATS
  723.60 +Resource15=IDD_GBA_ROM_INFO
  723.61 +Resource16=IDD_IO_VIEWER
  723.62 +Resource17=IDD_MEM_VIEWER
  723.63 +Resource18=IDD_ADDR_SIZE
  723.64 +Resource19=IDR_MENU
  723.65 +Resource20=IDD_PALETTE_VIEW
  723.66 +Resource21=IDD_ASSOCIATIONS
  723.67 +Resource22=IDD_GB_COLORS
  723.68 +Resource23=IDD_ADD_CHEAT
  723.69 +Resource24=IDD_DISASSEMBLE
  723.70 +Resource25=IDD_MODES
  723.71 +Resource26=IDD_GDB_PORT
  723.72 +Resource27=IDD_LANG_SELECT
  723.73 +Resource28=IDD_LOGGING
  723.74 +Resource29=IDD_DRIVERS
  723.75 +Resource30=IDD_EXPORT_SPS
  723.76 +Resource31=IDD_THROTTLE
  723.77 +Resource32=IDD_MODE_CONFIRM
  723.78 +Resource33=IDD_GB_DISASSEMBLE
  723.79 +Resource34=IDD_GB_PALETTE_VIEW
  723.80 +Resource35=IDD_REWIND_INTERVAL
  723.81 +Resource36=IDD_GB_TILE_VIEWER
  723.82 +Resource37=IDD_ACCEL_EDITOR
  723.83 +Resource38=IDD_GB_MAP_VIEW
  723.84 +Resource39=IDD_BUG_REPORT
  723.85 +Resource40=IDD_MOTION_CONFIG
  723.86 +Resource41=IDD_TILE_VIEWER
  723.87 +Class30=AddGSACode
  723.88 +Class31=GBCheatList
  723.89 +Class32=Disassemble
  723.90 +Class33=GBDisassemble
  723.91 +Class34=Logging
  723.92 +Class35=IOViewer
  723.93 +Class36=ZoomControl
  723.94 +Class37=BitmapControl
  723.95 +Class38=MapView
  723.96 +Class39=GBMapView
  723.97 +Class40=MemoryViewer
  723.98 +Class41=MemoryViewerDlg
  723.99 +Class42=MemoryViewerAddressSize
 723.100 +Class43=GBMemoryViewerDlg
 723.101 +Class44=OamView
 723.102 +Class45=GBOamView
 723.103 +Class46=PaletteViewControl
 723.104 +Class47=PaletteView
 723.105 +Class48=GBPaletteView
 723.106 +Class49=TileView
 723.107 +Class50=GBTileView
 723.108 +Class51=GBPrinterDlg
 723.109 +Class52=GDBPortDlg
 723.110 +Class53=GDBWaitingDlg
 723.111 +Class54=AccelEditor
 723.112 +Class55=CKeyboardEdit
 723.113 +Resource42=IDD_DIRECTORIES
 723.114 +Class56=MaxScale
 723.115 +Resource43=IDD_GB_PRINTER
 723.116 +Class57=BugReport
 723.117 +Resource44=IDR_ACCELERATOR
 723.118 +
 723.119 +[CLS:AboutDialog]
 723.120 +Type=0
 723.121 +BaseClass=CDialog
 723.122 +HeaderFile=AboutDialog.h
 723.123 +ImplementationFile=AboutDialog.cpp
 723.124 +LastObject=AboutDialog
 723.125 +
 723.126 +[CLS:Associate]
 723.127 +Type=0
 723.128 +BaseClass=CDialog
 723.129 +HeaderFile=Associate.h
 723.130 +ImplementationFile=Associate.cpp
 723.131 +LastObject=ID_OK
 723.132 +
 723.133 +[CLS:ColorButton]
 723.134 +Type=0
 723.135 +BaseClass=CButton
 723.136 +HeaderFile=ColorButton.h
 723.137 +ImplementationFile=ColorButton.cpp
 723.138 +
 723.139 +[CLS:ColorControl]
 723.140 +Type=0
 723.141 +BaseClass=CWnd
 723.142 +HeaderFile=ColorControl.h
 723.143 +ImplementationFile=ColorControl.cpp
 723.144 +
 723.145 +[CLS:Directories]
 723.146 +Type=0
 723.147 +BaseClass=CDialog
 723.148 +HeaderFile=Directories.h
 723.149 +ImplementationFile=Directories.cpp
 723.150 +
 723.151 +[CLS:ExportGSASnapshot]
 723.152 +Type=0
 723.153 +BaseClass=CDialog
 723.154 +HeaderFile=ExportGSASnapshot.h
 723.155 +ImplementationFile=ExportGSASnapshot.cpp
 723.156 +
 723.157 +[CLS:FileDlg]
 723.158 +Type=0
 723.159 +BaseClass=CFileDialog
 723.160 +HeaderFile=FileDlg.h
 723.161 +ImplementationFile=FileDlg.cpp
 723.162 +
 723.163 +[CLS:GBACheatSearch]
 723.164 +Type=0
 723.165 +BaseClass=CDialog
 723.166 +HeaderFile=GBACheats.h
 723.167 +ImplementationFile=GBACheats.cpp
 723.168 +
 723.169 +[CLS:AddCheat]
 723.170 +Type=0
 723.171 +BaseClass=CDialog
 723.172 +HeaderFile=GBACheats.h
 723.173 +ImplementationFile=GBACheats.cpp
 723.174 +
 723.175 +[CLS:GBACheatList]
 723.176 +Type=0
 723.177 +BaseClass=CDialog
 723.178 +HeaderFile=GBACheats.h
 723.179 +ImplementationFile=GBACheats.cpp
 723.180 +LastObject=GBACheatList
 723.181 +
 723.182 +[CLS:GBCheatSearch]
 723.183 +Type=0
 723.184 +BaseClass=CDialog
 723.185 +HeaderFile=GBCheatsDlg.h
 723.186 +ImplementationFile=GBCheatsDlg.cpp
 723.187 +
 723.188 +[CLS:AddGBCheat]
 723.189 +Type=0
 723.190 +BaseClass=CDialog
 723.191 +HeaderFile=GBCheatsDlg.h
 723.192 +ImplementationFile=GBCheatsDlg.cpp
 723.193 +LastObject=AddGBCheat
 723.194 +
 723.195 +[CLS:GBColorDlg]
 723.196 +Type=0
 723.197 +BaseClass=CDialog
 723.198 +HeaderFile=GBColorDlg.h
 723.199 +ImplementationFile=GBColorDlg.cpp
 723.200 +LastObject=IDC_PREDEFINED
 723.201 +Filter=D
 723.202 +VirtualFilter=dWC
 723.203 +
 723.204 +[CLS:GSACodeSelect]
 723.205 +Type=0
 723.206 +BaseClass=CDialog
 723.207 +HeaderFile=GSACodeSelect.h
 723.208 +ImplementationFile=GSACodeSelect.cpp
 723.209 +
 723.210 +[CLS:JoypadEditControl]
 723.211 +Type=0
 723.212 +BaseClass=CEdit
 723.213 +HeaderFile=Joypad.h
 723.214 +ImplementationFile=Joypad.cpp
 723.215 +
 723.216 +[CLS:JoypadConfig]
 723.217 +Type=0
 723.218 +BaseClass=CDialog
 723.219 +HeaderFile=Joypad.h
 723.220 +ImplementationFile=Joypad.cpp
 723.221 +
 723.222 +[CLS:CKeyboardEdit]
 723.223 +Type=0
 723.224 +BaseClass=CEdit
 723.225 +HeaderFile=KeyboardEdit.h
 723.226 +ImplementationFile=KeyboardEdit.cpp
 723.227 +
 723.228 +[CLS:MotionConfig]
 723.229 +Type=0
 723.230 +BaseClass=CDialog
 723.231 +HeaderFile=Joypad.h
 723.232 +ImplementationFile=Joypad.cpp
 723.233 +
 723.234 +[CLS:LangSelect]
 723.235 +Type=0
 723.236 +BaseClass=CDialog
 723.237 +HeaderFile=LangSelect.h
 723.238 +ImplementationFile=LangSelect.cpp
 723.239 +
 723.240 +[CLS:MainWnd]
 723.241 +Type=0
 723.242 +BaseClass=CWnd
 723.243 +HeaderFile=MainWnd.h
 723.244 +ImplementationFile=MainWnd.cpp
 723.245 +LastObject=ID_CHEATS_AUTOMATICSAVELOADCHEATS
 723.246 +Filter=W
 723.247 +VirtualFilter=WC
 723.248 +
 723.249 +[CLS:ModeConfirm]
 723.250 +Type=0
 723.251 +BaseClass=CDialog
 723.252 +HeaderFile=ModeConfirm.h
 723.253 +ImplementationFile=ModeConfirm.cpp
 723.254 +
 723.255 +[CLS:RewindInterval]
 723.256 +Type=0
 723.257 +BaseClass=CDialog
 723.258 +HeaderFile=RewindInterval.h
 723.259 +ImplementationFile=RewindInterval.cpp
 723.260 +
 723.261 +[CLS:RomInfoGB]
 723.262 +Type=0
 723.263 +BaseClass=CDialog
 723.264 +HeaderFile=RomInfo.h
 723.265 +ImplementationFile=RomInfo.cpp
 723.266 +
 723.267 +[CLS:RomInfoGBA]
 723.268 +Type=0
 723.269 +BaseClass=CDialog
 723.270 +HeaderFile=RomInfo.h
 723.271 +ImplementationFile=RomInfo.cpp
 723.272 +
 723.273 +[CLS:SkinButton]
 723.274 +Type=0
 723.275 +BaseClass=CWnd
 723.276 +HeaderFile=skinButton.h
 723.277 +ImplementationFile=skinButton.cpp
 723.278 +
 723.279 +[CLS:Throttle]
 723.280 +Type=0
 723.281 +BaseClass=CDialog
 723.282 +HeaderFile=Throttle.h
 723.283 +ImplementationFile=Throttle.cpp
 723.284 +
 723.285 +[CLS:VBA]
 723.286 +Type=0
 723.287 +BaseClass=CWinApp
 723.288 +HeaderFile=VBA.h
 723.289 +ImplementationFile=VBA.cpp
 723.290 +
 723.291 +[CLS:VideoMode]
 723.292 +Type=0
 723.293 +BaseClass=CDialog
 723.294 +HeaderFile=VideoMode.h
 723.295 +ImplementationFile=VideoMode.cpp
 723.296 +
 723.297 +[CLS:VideoDriverSelect]
 723.298 +Type=0
 723.299 +BaseClass=CDialog
 723.300 +HeaderFile=VideoMode.h
 723.301 +ImplementationFile=VideoMode.cpp
 723.302 +Filter=D
 723.303 +VirtualFilter=dWC
 723.304 +LastObject=ID_CANCEL
 723.305 +
 723.306 +[DLG:IDD_ABOUT]
 723.307 +Type=1
 723.308 +Class=AboutDialog
 723.309 +ControlCount=8
 723.310 +Control1=IDOK,button,1342242817
 723.311 +Control2=IDC_STATIC,static,1342177283
 723.312 +Control3=IDC_STATIC,static,1342308353
 723.313 +Control4=IDC_STATIC,static,1342308353
 723.314 +Control5=IDC_URL,static,1342308353
 723.315 +Control6=IDC_STATIC,static,1342308353
 723.316 +Control7=IDC_STATIC,static,1342308353
 723.317 +Control8=IDC_VERSION,static,1342308353
 723.318 +
 723.319 +[DLG:IDD_ASSOCIATIONS]
 723.320 +Type=1
 723.321 +Class=Associate
 723.322 +ControlCount=11
 723.323 +Control1=IDC_GB,button,1342242819
 723.324 +Control2=IDC_SGB,button,1342242819
 723.325 +Control3=IDC_CGB,button,1342242819
 723.326 +Control4=IDC_GBC,button,1342242819
 723.327 +Control5=IDC_GBA,button,1342242819
 723.328 +Control6=IDC_AGB,button,1342242819
 723.329 +Control7=IDC_BIN,button,1342242819
 723.330 +Control8=ID_OK,button,1342242817
 723.331 +Control9=ID_CANCEL,button,1342242816
 723.332 +Control10=IDC_STATIC,button,1342177287
 723.333 +Control11=IDC_STATIC,button,1342177287
 723.334 +
 723.335 +[DLG:IDD_DIRECTORIES]
 723.336 +Type=1
 723.337 +Class=Directories
 723.338 +ControlCount=22
 723.339 +Control1=IDC_ROM_DIR,button,1342242816
 723.340 +Control2=IDC_GBROM_DIR,button,1342242816
 723.341 +Control3=IDC_BATTERY_DIR,button,1342242816
 723.342 +Control4=IDC_SAVE_DIR,button,1342242816
 723.343 +Control5=IDC_CAPTURE_DIR,button,1342242816
 723.344 +Control6=IDOK,button,1342242817
 723.345 +Control7=IDCANCEL,button,1342242816
 723.346 +Control8=IDC_STATIC,static,1342308352
 723.347 +Control9=IDC_STATIC,static,1342308352
 723.348 +Control10=IDC_STATIC,static,1342308352
 723.349 +Control11=IDC_STATIC,static,1342308352
 723.350 +Control12=IDC_ROM_PATH,edit,1484849280
 723.351 +Control13=IDC_BATTERY_PATH,edit,1484849280
 723.352 +Control14=IDC_SAVE_PATH,edit,1484849280
 723.353 +Control15=IDC_CAPTURE_PATH,edit,1484849280
 723.354 +Control16=IDC_STATIC,static,1342308352
 723.355 +Control17=IDC_GBROM_PATH,edit,1484849280
 723.356 +Control18=IDC_ROM_DIR_RESET,button,1342242816
 723.357 +Control19=IDC_GBROM_DIR_RESET,button,1342242816
 723.358 +Control20=IDC_BATTERY_DIR_RESET,button,1342242816
 723.359 +Control21=IDC_SAVE_DIR_RESET,button,1342242816
 723.360 +Control22=IDC_CAPTURE_DIR_RESET,button,1342242816
 723.361 +
 723.362 +[DLG:IDD_EXPORT_SPS]
 723.363 +Type=1
 723.364 +Class=ExportGSASnapshot
 723.365 +ControlCount=8
 723.366 +Control1=IDC_TITLE,edit,1350631552
 723.367 +Control2=IDC_DESC,edit,1350631552
 723.368 +Control3=IDC_NOTES,edit,1350635652
 723.369 +Control4=ID_OK,button,1342242817
 723.370 +Control5=ID_CANCEL,button,1342242816
 723.371 +Control6=IDC_STATIC,static,1342308352
 723.372 +Control7=IDC_STATIC,static,1342308352
 723.373 +Control8=IDC_STATIC,static,1342308352
 723.374 +
 723.375 +[DLG:IDD_CHEATS]
 723.376 +Type=1
 723.377 +Class=GBACheatSearch
 723.378 +ControlCount=26
 723.379 +Control1=IDC_CHEAT_LIST,SysListView32,1350631429
 723.380 +Control2=IDC_OLD_VALUE,button,1342308361
 723.381 +Control3=IDC_SPECIFIC_VALUE,button,1342177289
 723.382 +Control4=IDC_SIZE_8,button,1342308361
 723.383 +Control5=IDC_SIZE_16,button,1342177289
 723.384 +Control6=IDC_SIZE_32,button,1342177289
 723.385 +Control7=IDC_EQ,button,1342308361
 723.386 +Control8=IDC_NE,button,1342177289
 723.387 +Control9=IDC_LT,button,1342177289
 723.388 +Control10=IDC_LE,button,1342177289
 723.389 +Control11=IDC_GT,button,1342177289
 723.390 +Control12=IDC_GE,button,1342177289
 723.391 +Control13=IDC_SIGNED,button,1342308361
 723.392 +Control14=IDC_UNSIGNED,button,1342177289
 723.393 +Control15=IDC_HEXADECIMAL,button,1342177289
 723.394 +Control16=IDC_UPDATE,button,1342373891
 723.395 +Control17=IDC_VALUE,edit,1350631552
 723.396 +Control18=IDC_START,button,1342373888
 723.397 +Control19=IDC_SEARCH,button,1342242816
 723.398 +Control20=IDC_ADD_CHEAT,button,1342242816
 723.399 +Control21=ID_OK,button,1342242817
 723.400 +Control22=IDC_STATIC,button,1342177287
 723.401 +Control23=IDC_STATIC,button,1342177287
 723.402 +Control24=IDC_STATIC,button,1342177287
 723.403 +Control25=IDC_STATIC,button,1342177287
 723.404 +Control26=IDC_STATIC,static,1342308352
 723.405 +
 723.406 +[DLG:IDD_ADD_CHEAT]
 723.407 +Type=1
 723.408 +Class=AddCheat
 723.409 +ControlCount=16
 723.410 +Control1=IDC_ADDRESS,edit,1350631552
 723.411 +Control2=IDC_VALUE,edit,1350631552
 723.412 +Control3=IDC_DESC,edit,1350631552
 723.413 +Control4=IDC_SIZE_8,button,1342373897
 723.414 +Control5=IDC_SIZE_16,button,1342177289
 723.415 +Control6=IDC_SIZE_32,button,1342177289
 723.416 +Control7=IDC_SIGNED,button,1342373897
 723.417 +Control8=IDC_UNSIGNED,button,1342177289
 723.418 +Control9=IDC_HEXADECIMAL,button,1342177289
 723.419 +Control10=ID_OK,button,1342373889
 723.420 +Control11=ID_CANCEL,button,1342242816
 723.421 +Control12=IDC_STATIC,static,1342308352
 723.422 +Control13=IDC_STATIC,button,1342177287
 723.423 +Control14=IDC_STATIC,static,1342308352
 723.424 +Control15=IDC_STATIC,button,1342177287
 723.425 +Control16=IDC_STATIC,static,1342308352
 723.426 +
 723.427 +[DLG:IDD_CHEAT_LIST]
 723.428 +Type=1
 723.429 +Class=GBACheatList
 723.430 +ControlCount=14
 723.431 +Control1=IDC_RESTORE,button,1342373891
 723.432 +Control2=IDC_ADD_CODE,button,1342373888
 723.433 +Control3=IDC_ADD_CHEAT,button,1342242816
 723.434 +Control4=IDC_ADD_GAMESHARK,button,1342242816
 723.435 +Control5=IDC_ADD_CODEBREAKER,button,1342242816
 723.436 +Control6=IDC_REMOVE,button,1342242816
 723.437 +Control7=IDC_REMOVE_ALL,button,1342242816
 723.438 +Control8=IDC_ENABLE,button,1342242816
 723.439 +Control9=ID_OK,button,1342373889
 723.440 +Control10=IDC_CHEAT_LIST,SysListView32,1350762497
 723.441 +Control11=IDC_STATIC,static,1342308352
 723.442 +Control12=IDC_STATIC,static,1342308352
 723.443 +Control13=IDC_STATIC,static,1342308352
 723.444 +Control14=IDC_STATIC,button,1342177287
 723.445 +
 723.446 +[DLG:IDD_GB_COLORS]
 723.447 +Type=1
 723.448 +Class=GBColorDlg
 723.449 +ControlCount=17
 723.450 +Control1=IDC_DEFAULT,button,1342308361
 723.451 +Control2=IDC_USER1,button,1342177289
 723.452 +Control3=IDC_USER2,button,1342177289
 723.453 +Control4=IDC_PREDEFINED,combobox,1344340227
 723.454 +Control5=IDC_COLOR_BG0,button,1342373888
 723.455 +Control6=IDC_COLOR_BG1,button,1342242816
 723.456 +Control7=IDC_COLOR_BG2,button,1342242816
 723.457 +Control8=IDC_COLOR_BG3,button,1342242816
 723.458 +Control9=IDC_COLOR_OB0,button,1342242816
 723.459 +Control10=IDC_COLOR_OB1,button,1342242816
 723.460 +Control11=IDC_COLOR_OB2,button,1342242816
 723.461 +Control12=IDC_COLOR_OB3,button,1342242816
 723.462 +Control13=IDC_RESET,button,1342242816
 723.463 +Control14=ID_OK,button,1342242817
 723.464 +Control15=ID_CANCEL,button,1342242816
 723.465 +Control16=IDC_STATIC,button,1342177287
 723.466 +Control17=IDC_STATIC,button,1342177287
 723.467 +
 723.468 +[DLG:IDD_CODE_SELECT]
 723.469 +Type=1
 723.470 +Class=GSACodeSelect
 723.471 +ControlCount=3
 723.472 +Control1=ID_OK,button,1342242817
 723.473 +Control2=ID_CANCEL,button,1342242816
 723.474 +Control3=IDC_GAME_LIST,listbox,1353777411
 723.475 +
 723.476 +[DLG:IDD_CONFIG]
 723.477 +Type=1
 723.478 +Class=JoypadConfig
 723.479 +ControlCount=28
 723.480 +Control1=IDC_EDIT_UP,edit,1350631552
 723.481 +Control2=IDC_EDIT_DOWN,edit,1350631552
 723.482 +Control3=IDC_EDIT_LEFT,edit,1350631552
 723.483 +Control4=IDC_EDIT_RIGHT,edit,1350631552
 723.484 +Control5=IDC_EDIT_BUTTON_A,edit,1350631552
 723.485 +Control6=IDC_EDIT_BUTTON_B,edit,1350631552
 723.486 +Control7=IDC_EDIT_BUTTON_L,edit,1350631552
 723.487 +Control8=IDC_EDIT_BUTTON_R,edit,1350631552
 723.488 +Control9=IDC_EDIT_BUTTON_SELECT,edit,1350631552
 723.489 +Control10=IDC_EDIT_BUTTON_START,edit,1350631552
 723.490 +Control11=IDC_EDIT_SPEED,edit,1350631552
 723.491 +Control12=IDC_EDIT_CAPTURE,edit,1350631552
 723.492 +Control13=IDC_EDIT_BUTTON_GS,edit,1350631552
 723.493 +Control14=ID_OK,button,1342242816
 723.494 +Control15=ID_CANCEL,button,1342242816
 723.495 +Control16=IDC_STATIC,static,1342308352
 723.496 +Control17=IDC_STATIC,static,1342308352
 723.497 +Control18=IDC_STATIC,static,1342308352
 723.498 +Control19=IDC_STATIC,static,1342308352
 723.499 +Control20=IDC_STATIC,static,1342308352
 723.500 +Control21=IDC_STATIC,static,1342308352
 723.501 +Control22=IDC_STATIC,static,1342308352
 723.502 +Control23=IDC_STATIC,static,1342308352
 723.503 +Control24=IDC_STATIC,static,1342308352
 723.504 +Control25=IDC_STATIC,static,1342308352
 723.505 +Control26=IDC_STATIC,static,1342308352
 723.506 +Control27=IDC_STATIC,static,1342308352
 723.507 +Control28=IDC_STATIC,static,1342308352
 723.508 +
 723.509 +[DLG:IDD_MOTION_CONFIG]
 723.510 +Type=1
 723.511 +Class=MotionConfig
 723.512 +ControlCount=10
 723.513 +Control1=IDC_EDIT_UP,edit,1350631552
 723.514 +Control2=IDC_EDIT_DOWN,edit,1350631552
 723.515 +Control3=IDC_EDIT_LEFT,edit,1350631552
 723.516 +Control4=IDC_EDIT_RIGHT,edit,1350631552
 723.517 +Control5=ID_OK,button,1342242816
 723.518 +Control6=ID_CANCEL,button,1342242816
 723.519 +Control7=IDC_STATIC,static,1342308352
 723.520 +Control8=IDC_STATIC,static,1342308352
 723.521 +Control9=IDC_STATIC,static,1342308352
 723.522 +Control10=IDC_STATIC,static,1342308352
 723.523 +
 723.524 +[DLG:IDD_LANG_SELECT]
 723.525 +Type=1
 723.526 +Class=LangSelect
 723.527 +ControlCount=6
 723.528 +Control1=IDC_LANG_STRING,edit,1350631552
 723.529 +Control2=ID_OK,button,1342242817
 723.530 +Control3=ID_CANCEL,button,1342242816
 723.531 +Control4=IDC_STATIC,static,1342308352
 723.532 +Control5=IDC_STATIC,static,1342308352
 723.533 +Control6=IDC_LANG_NAME,static,1342308352
 723.534 +
 723.535 +[DLG:IDD_MODE_CONFIRM]
 723.536 +Type=1
 723.537 +Class=ModeConfirm
 723.538 +ControlCount=4
 723.539 +Control1=ID_OK,button,1342242817
 723.540 +Control2=ID_CANCEL,button,1342242816
 723.541 +Control3=IDC_STATIC,static,1342308353
 723.542 +Control4=IDC_TIMER,static,1342308353
 723.543 +
 723.544 +[DLG:IDD_REWIND_INTERVAL]
 723.545 +Type=1
 723.546 +Class=RewindInterval
 723.547 +ControlCount=5
 723.548 +Control1=IDC_INTERVAL,edit,1350631552
 723.549 +Control2=ID_OK,button,1342242817
 723.550 +Control3=ID_CANCEL,button,1342242816
 723.551 +Control4=IDC_STATIC,static,1342308352
 723.552 +Control5=IDC_STATIC,static,1342308352
 723.553 +
 723.554 +[DLG:IDD_GB_ROM_INFO]
 723.555 +Type=1
 723.556 +Class=RomInfoGB
 723.557 +ControlCount=27
 723.558 +Control1=ID_OK,button,1342242817
 723.559 +Control2=IDC_STATIC,static,1342308352
 723.560 +Control3=IDC_STATIC,static,1342308352
 723.561 +Control4=IDC_STATIC,static,1342308352
 723.562 +Control5=IDC_STATIC,static,1342308352
 723.563 +Control6=IDC_STATIC,static,1342308352
 723.564 +Control7=IDC_STATIC,static,1342308352
 723.565 +Control8=IDC_ROM_TITLE,static,1342308352
 723.566 +Control9=IDC_ROM_MAKER_CODE,static,1342308352
 723.567 +Control10=IDC_ROM_UNIT_CODE,static,1342308352
 723.568 +Control11=IDC_ROM_DEVICE_TYPE,static,1342308352
 723.569 +Control12=IDC_ROM_VERSION,static,1342308352
 723.570 +Control13=IDC_ROM_CRC,static,1342308352
 723.571 +Control14=IDC_STATIC,static,1342308352
 723.572 +Control15=IDC_ROM_COLOR,static,1342308352
 723.573 +Control16=IDC_STATIC,static,1342308352
 723.574 +Control17=IDC_ROM_SIZE,static,1342308352
 723.575 +Control18=IDC_STATIC,static,1342308352
 723.576 +Control19=IDC_ROM_RAM_SIZE,static,1342308352
 723.577 +Control20=IDC_STATIC,static,1342308352
 723.578 +Control21=IDC_ROM_DEST_CODE,static,1342308352
 723.579 +Control22=IDC_STATIC,static,1342308352
 723.580 +Control23=IDC_ROM_LIC_CODE,static,1342308352
 723.581 +Control24=IDC_STATIC,static,1342308352
 723.582 +Control25=IDC_ROM_CHECKSUM,static,1342308352
 723.583 +Control26=IDC_ROM_MAKER_NAME2,static,1342308352
 723.584 +Control27=IDC_STATIC,static,1342308352
 723.585 +
 723.586 +[DLG:IDD_GBA_ROM_INFO]
 723.587 +Type=1
 723.588 +Class=RomInfoGBA
 723.589 +ControlCount=17
 723.590 +Control1=ID_OK,button,1342242817
 723.591 +Control2=IDC_STATIC,static,1342308352
 723.592 +Control3=IDC_STATIC,static,1342308352
 723.593 +Control4=IDC_STATIC,static,1342308352
 723.594 +Control5=IDC_STATIC,static,1342308352
 723.595 +Control6=IDC_STATIC,static,1342308352
 723.596 +Control7=IDC_STATIC,static,1342308352
 723.597 +Control8=IDC_STATIC,static,1342308352
 723.598 +Control9=IDC_ROM_TITLE,static,1342308352
 723.599 +Control10=IDC_ROM_GAME_CODE,static,1342308352
 723.600 +Control11=IDC_ROM_MAKER_CODE,static,1342308352
 723.601 +Control12=IDC_ROM_UNIT_CODE,static,1342308352
 723.602 +Control13=IDC_ROM_DEVICE_TYPE,static,1342308352
 723.603 +Control14=IDC_ROM_VERSION,static,1342308352
 723.604 +Control15=IDC_ROM_CRC,static,1342308352
 723.605 +Control16=IDC_ROM_MAKER_NAME,static,1342308352
 723.606 +Control17=IDC_STATIC,static,1342308352
 723.607 +
 723.608 +[DLG:IDD_THROTTLE]
 723.609 +Type=1
 723.610 +Class=Throttle
 723.611 +ControlCount=4
 723.612 +Control1=IDC_THROTTLE,edit,1350631552
 723.613 +Control2=ID_OK,button,1342242817
 723.614 +Control3=ID_CANCEL,button,1342242816
 723.615 +Control4=IDC_STATIC,static,1342308352
 723.616 +
 723.617 +[DLG:IDD_MODES]
 723.618 +Type=1
 723.619 +Class=VideoMode
 723.620 +ControlCount=4
 723.621 +Control1=IDC_MODES,listbox,1352728835
 723.622 +Control2=ID_OK,button,1342242817
 723.623 +Control3=ID_CANCEL,button,1342242816
 723.624 +Control4=IDC_STATIC,static,1342308352
 723.625 +
 723.626 +[DLG:IDD_DRIVERS]
 723.627 +Type=1
 723.628 +Class=VideoDriverSelect
 723.629 +ControlCount=4
 723.630 +Control1=IDC_DRIVERS,listbox,1352728833
 723.631 +Control2=ID_OK,button,1342242817
 723.632 +Control3=ID_CANCEL,button,1342242816
 723.633 +Control4=IDC_STATIC,static,1342308352
 723.634 +
 723.635 +[DLG:IDD_OPENDLG]
 723.636 +Type=1
 723.637 +Class=GBMemoryViewerDlg
 723.638 +ControlCount=12
 723.639 +Control1=1090,static,1342308352
 723.640 +Control2=1152,edit,1350632576
 723.641 +Control3=1120,listbox,1352732755
 723.642 +Control4=65535,static,1342308352
 723.643 +Control5=1088,static,1342308480
 723.644 +Control6=1121,listbox,1352732755
 723.645 +Control7=1089,static,1342308352
 723.646 +Control8=1136,combobox,1344340035
 723.647 +Control9=1091,static,1342308352
 723.648 +Control10=1137,combobox,1344340819
 723.649 +Control11=IDOK,button,1342373889
 723.650 +Control12=IDCANCEL,button,1342373888
 723.651 +
 723.652 +[DLG:IDD_GB_CHEAT_LIST]
 723.653 +Type=1
 723.654 +Class=GBCheatList
 723.655 +ControlCount=10
 723.656 +Control1=IDC_CHEAT_LIST,SysListView32,1350762497
 723.657 +Control2=IDC_ADD_GG_CHEAT,button,1342373888
 723.658 +Control3=IDC_ADD_GS_CHEAT,button,1342373888
 723.659 +Control4=IDC_REMOVE,button,1342242816
 723.660 +Control5=IDC_REMOVE_ALL,button,1342242816
 723.661 +Control6=IDC_ENABLE,button,1342242816
 723.662 +Control7=ID_OK,button,1342242817
 723.663 +Control8=IDC_STATIC,static,1342308352
 723.664 +Control9=IDC_STATIC,static,1342308352
 723.665 +Control10=IDC_STATIC,static,1342308352
 723.666 +
 723.667 +[DLG:IDD_ADD_CHEAT_DLG]
 723.668 +Type=1
 723.669 +Class=AddGSACode
 723.670 +ControlCount=6
 723.671 +Control1=IDC_DESC,edit,1350631552
 723.672 +Control2=IDC_CODE,edit,1350635724
 723.673 +Control3=ID_OK,button,1342242817
 723.674 +Control4=ID_CANCEL,button,1342242816
 723.675 +Control5=IDC_STATIC,static,1342308352
 723.676 +Control6=IDC_STATIC,static,1342308352
 723.677 +
 723.678 +[DLG:IDD_GB_PRINTER]
 723.679 +Type=1
 723.680 +Class=GBPrinterDlg
 723.681 +ControlCount=9
 723.682 +Control1=IDC_1X,button,1342308361
 723.683 +Control2=IDC_2X,button,1342177289
 723.684 +Control3=IDC_3X,button,1342177289
 723.685 +Control4=IDC_4X,button,1342177289
 723.686 +Control5=ID_PRINT,button,1342373889
 723.687 +Control6=ID_SAVE,button,1342242816
 723.688 +Control7=ID_OK,button,1342242816
 723.689 +Control8=IDC_GB_PRINTER,static,1342308359
 723.690 +Control9=IDC_STATIC,button,1342177287
 723.691 +
 723.692 +[DLG:IDD_MAP_VIEW]
 723.693 +Type=1
 723.694 +Class=MapView
 723.695 +ControlCount=44
 723.696 +Control1=IDC_FRAME_0,button,1342308361
 723.697 +Control2=IDC_FRAME_1,button,1342177289
 723.698 +Control3=IDC_BG0,button,1342308361
 723.699 +Control4=IDC_BG1,button,1342177289
 723.700 +Control5=IDC_BG2,button,1342177289
 723.701 +Control6=IDC_BG3,button,1342177289
 723.702 +Control7=IDC_STRETCH,button,1342242819
 723.703 +Control8=IDC_REFRESH,button,1342373888
 723.704 +Control9=IDC_SAVE,button,1342373888
 723.705 +Control10=IDC_CLOSE,button,1342242816
 723.706 +Control11=IDC_MAP_VIEW,VbaBitmapControl,1342373888
 723.707 +Control12=IDC_MAP_VIEW_ZOOM,VbaZoomControl,1342373888
 723.708 +Control13=IDC_COLOR,VbaColorControl,1342242816
 723.709 +Control14=IDC_R,static,1342308352
 723.710 +Control15=IDC_G,static,1342308352
 723.711 +Control16=IDC_B,static,1342308352
 723.712 +Control17=IDC_STATIC,button,1342177287
 723.713 +Control18=IDC_STATIC,button,1342177287
 723.714 +Control19=IDC_AUTO_UPDATE,button,1342242819
 723.715 +Control20=IDC_XY,static,1342308352
 723.716 +Control21=IDC_STATIC,static,1342308352
 723.717 +Control22=IDC_MODE,static,1342308352
 723.718 +Control23=IDC_STATIC,static,1342308352
 723.719 +Control24=IDC_MAPBASE,static,1342308352
 723.720 +Control25=IDC_STATIC,static,1342308352
 723.721 +Control26=IDC_CHARBASE,static,1342308352
 723.722 +Control27=IDC_STATIC,static,1342308352
 723.723 +Control28=IDC_DIM,static,1342308352
 723.724 +Control29=IDC_STATIC,static,1342308352
 723.725 +Control30=IDC_NUMCOLORS,static,1342308352
 723.726 +Control31=IDC_STATIC,static,1342308352
 723.727 +Control32=IDC_PRIORITY,static,1342308352
 723.728 +Control33=IDC_STATIC,static,1342308352
 723.729 +Control34=IDC_MOSAIC,static,1342308352
 723.730 +Control35=IDC_STATIC,static,1342308352
 723.731 +Control36=IDC_OVERFLOW,static,1342308352
 723.732 +Control37=IDC_STATIC,static,1342308352
 723.733 +Control38=IDC_ADDRESS,static,1342308352
 723.734 +Control39=IDC_STATIC,static,1342308352
 723.735 +Control40=IDC_TILE_NUM,static,1342308352
 723.736 +Control41=IDC_STATIC,static,1342308352
 723.737 +Control42=IDC_FLIP,static,1342308352
 723.738 +Control43=IDC_STATIC,static,1342308352
 723.739 +Control44=IDC_PALETTE_NUM,static,1342308352
 723.740 +
 723.741 +[DLG:IDD_PALETTE_VIEW]
 723.742 +Type=1
 723.743 +Class=PaletteView
 723.744 +ControlCount=21
 723.745 +Control1=IDC_SAVE_BG,button,1342242816
 723.746 +Control2=IDC_SAVE_OBJ,button,1342242816
 723.747 +Control3=IDC_REFRESH2,button,1342242816
 723.748 +Control4=IDC_CLOSE,button,1342242816
 723.749 +Control5=IDC_ADDRESS,static,1342308352
 723.750 +Control6=IDC_R,static,1342308352
 723.751 +Control7=IDC_G,static,1342308352
 723.752 +Control8=IDC_B,static,1342308352
 723.753 +Control9=IDC_VALUE,static,1342308352
 723.754 +Control10=IDC_COLOR,VbaColorControl,1342242816
 723.755 +Control11=IDC_PALETTE_VIEW,VbaPaletteViewControl,1342242816
 723.756 +Control12=IDC_PALETTE_VIEW_OBJ,VbaPaletteViewControl,1342242816
 723.757 +Control13=IDC_STATIC,button,1342177287
 723.758 +Control14=IDC_STATIC,button,1342177287
 723.759 +Control15=IDC_STATIC,static,1342308352
 723.760 +Control16=IDC_STATIC,static,1342308352
 723.761 +Control17=IDC_STATIC,static,1342308352
 723.762 +Control18=IDC_STATIC,static,1342308352
 723.763 +Control19=IDC_STATIC,static,1342308352
 723.764 +Control20=IDC_STATIC,static,1342308352
 723.765 +Control21=IDC_AUTO_UPDATE,button,1342242819
 723.766 +
 723.767 +[DLG:IDD_MEM_VIEWER]
 723.768 +Type=1
 723.769 +Class=MemoryViewerDlg
 723.770 +ControlCount=14
 723.771 +Control1=IDC_ADDRESSES,combobox,1344339971
 723.772 +Control2=IDC_8_BIT,button,1342308361
 723.773 +Control3=IDC_16_BIT,button,1342177289
 723.774 +Control4=IDC_32_BIT,button,1342177289
 723.775 +Control5=IDC_ADDRESS,edit,1350766728
 723.776 +Control6=IDC_GO,button,1342373889
 723.777 +Control7=IDC_VIEWER,VbaMemoryViewer,1342242816
 723.778 +Control8=IDC_AUTO_UPDATE,button,1342242819
 723.779 +Control9=IDC_REFRESH,button,1342242816
 723.780 +Control10=IDC_LOAD,button,1342242816
 723.781 +Control11=IDC_SAVE,button,1342242816
 723.782 +Control12=IDC_CLOSE,button,1342242816
 723.783 +Control13=IDC_CURRENT_ADDRESS_LABEL,static,1342308352
 723.784 +Control14=IDC_CURRENT_ADDRESS,edit,1484849282
 723.785 +
 723.786 +[DLG:IDD_OAM_VIEW]
 723.787 +Type=1
 723.788 +Class=OamView
 723.789 +ControlCount=32
 723.790 +Control1=IDC_SPRITE,edit,1350639746
 723.791 +Control2=IDC_SCROLLBAR,scrollbar,1342177280
 723.792 +Control3=IDC_STRETCH,button,1342242819
 723.793 +Control4=IDC_REFRESH,button,1342373888
 723.794 +Control5=IDC_SAVE,button,1342373888
 723.795 +Control6=IDC_CLOSE,button,1342242816
 723.796 +Control7=IDC_OAM_VIEW,VbaBitmapControl,1342373888
 723.797 +Control8=IDC_OAM_VIEW_ZOOM,VbaZoomControl,1342373888
 723.798 +Control9=IDC_COLOR,VbaColorControl,1342242816
 723.799 +Control10=IDC_POS,static,1342308352
 723.800 +Control11=IDC_MODE,static,1342308352
 723.801 +Control12=IDC_COLORS,static,1342308352
 723.802 +Control13=IDC_PALETTE,static,1342308352
 723.803 +Control14=IDC_TILE,static,1342308352
 723.804 +Control15=IDC_PRIO,static,1342308352
 723.805 +Control16=IDC_SIZE2,static,1342308352
 723.806 +Control17=IDC_ROT,static,1342308352
 723.807 +Control18=IDC_FLAGS,static,1342308352
 723.808 +Control19=IDC_R,static,1342308352
 723.809 +Control20=IDC_G,static,1342308352
 723.810 +Control21=IDC_B,static,1342308352
 723.811 +Control22=IDC_STATIC,static,1342308352
 723.812 +Control23=IDC_STATIC,static,1342308352
 723.813 +Control24=IDC_STATIC,static,1342308352
 723.814 +Control25=IDC_STATIC,static,1342308352
 723.815 +Control26=IDC_STATIC,static,1342308352
 723.816 +Control27=IDC_STATIC,static,1342308352
 723.817 +Control28=IDC_STATIC,static,1342308352
 723.818 +Control29=IDC_STATIC,static,1342308352
 723.819 +Control30=IDC_STATIC,static,1342308352
 723.820 +Control31=IDC_STATIC,static,1342308352
 723.821 +Control32=IDC_AUTO_UPDATE,button,1342242819
 723.822 +
 723.823 +[DLG:IDD_ACCEL_EDITOR]
 723.824 +Type=1
 723.825 +Class=AccelEditor
 723.826 +ControlCount=13
 723.827 +Control1=IDC_STATIC,static,1342308352
 723.828 +Control2=IDC_COMMANDS,listbox,1352732931
 723.829 +Control3=IDC_STATIC1,static,1342308352
 723.830 +Control4=IDC_CURRENTS,listbox,1352728835
 723.831 +Control5=ID_OK,button,1342242817
 723.832 +Control6=ID_CANCEL,button,1342242816
 723.833 +Control7=IDC_STATIC3,static,1342308352
 723.834 +Control8=IDC_EDIT_KEY,edit,1350631552
 723.835 +Control9=IDC_ASSIGN,button,1342242816
 723.836 +Control10=IDC_REMOVE,button,1342242816
 723.837 +Control11=IDC_RESET,button,1342242816
 723.838 +Control12=IDC_ALREADY_AFFECTED,static,1342308864
 723.839 +Control13=IDC_STATIC2,static,1342308352
 723.840 +
 723.841 +[DLG:IDD_TILE_VIEWER]
 723.842 +Type=1
 723.843 +Class=TileView
 723.844 +ControlCount=26
 723.845 +Control1=IDC_16_COLORS,button,1342308361
 723.846 +Control2=IDC_256_COLORS,button,1342177289
 723.847 +Control3=IDC_CHARBASE_0,button,1342308361
 723.848 +Control4=IDC_CHARBASE_1,button,1342177289
 723.849 +Control5=IDC_CHARBASE_2,button,1342177289
 723.850 +Control6=IDC_CHARBASE_3,button,1342177289
 723.851 +Control7=IDC_CHARBASE_4,button,1342177289
 723.852 +Control8=IDC_PALETTE_SLIDER,msctls_trackbar32,1342373889
 723.853 +Control9=IDC_STRETCH,button,1342242819
 723.854 +Control10=IDC_REFRESH,button,1342373888
 723.855 +Control11=IDC_SAVE,button,1342242816
 723.856 +Control12=IDC_CLOSE,button,1342242816
 723.857 +Control13=IDC_TILE_VIEW,VbaBitmapControl,1342373888
 723.858 +Control14=IDC_STATIC,button,1342177287
 723.859 +Control15=IDC_STATIC,button,1342177287
 723.860 +Control16=IDC_MAP_VIEW_ZOOM,VbaZoomControl,1342373888
 723.861 +Control17=IDC_COLOR,VbaColorControl,1342242816
 723.862 +Control18=IDC_R,static,1342308352
 723.863 +Control19=IDC_G,static,1342308352
 723.864 +Control20=IDC_B,static,1342308352
 723.865 +Control21=IDC_STATIC,static,1342308352
 723.866 +Control22=IDC_AUTO_UPDATE,button,1342242819
 723.867 +Control23=IDC_STATIC,static,1342308352
 723.868 +Control24=IDC_STATIC,static,1342308352
 723.869 +Control25=IDC_TILE_NUMBER,static,1342308352
 723.870 +Control26=IDC_ADDRESS,static,1342308352
 723.871 +
 723.872 +[DLG:IDD_DISASSEMBLE]
 723.873 +Type=1
 723.874 +Class=Disassemble
 723.875 +ControlCount=55
 723.876 +Control1=IDC_AUTOMATIC,button,1342308361
 723.877 +Control2=IDC_ARM,button,1342177289
 723.878 +Control3=IDC_THUMB,button,1342177289
 723.879 +Control4=IDC_ADDRESS,edit,1350762632
 723.880 +Control5=IDC_GO,button,1342242816
 723.881 +Control6=IDC_DISASSEMBLE,listbox,1350631683
 723.882 +Control7=IDC_AUTO_UPDATE,button,1342242819
 723.883 +Control8=IDC_REFRESH,button,1342242816
 723.884 +Control9=IDC_NEXT,button,1342242816
 723.885 +Control10=IDC_CLOSE,button,1342242817
 723.886 +Control11=IDC_STATIC,static,1342308352
 723.887 +Control12=IDC_STATIC,static,1342308352
 723.888 +Control13=IDC_STATIC,static,1342308352
 723.889 +Control14=IDC_STATIC,static,1342308352
 723.890 +Control15=IDC_STATIC,static,1342308352
 723.891 +Control16=IDC_STATIC,static,1342308352
 723.892 +Control17=IDC_STATIC,static,1342308352
 723.893 +Control18=IDC_STATIC,static,1342308352
 723.894 +Control19=IDC_R0,static,1342308352
 723.895 +Control20=IDC_R1,static,1342308352
 723.896 +Control21=IDC_R2,static,1342308352
 723.897 +Control22=IDC_R3,static,1342308352
 723.898 +Control23=IDC_R4,static,1342308352
 723.899 +Control24=IDC_R5,static,1342308352
 723.900 +Control25=IDC_R6,static,1342308352
 723.901 +Control26=IDC_R7,static,1342308352
 723.902 +Control27=IDC_R8,static,1342308352
 723.903 +Control28=IDC_R9,static,1342308352
 723.904 +Control29=IDC_R10,static,1342308352
 723.905 +Control30=IDC_R11,static,1342308352
 723.906 +Control31=IDC_R12,static,1342308352
 723.907 +Control32=IDC_R13,static,1342308352
 723.908 +Control33=IDC_R14,static,1342308352
 723.909 +Control34=IDC_R15,static,1342308352
 723.910 +Control35=IDC_STATIC,static,1342308352
 723.911 +Control36=IDC_STATIC,static,1342308352
 723.912 +Control37=IDC_STATIC,static,1342308352
 723.913 +Control38=IDC_STATIC,static,1342308352
 723.914 +Control39=IDC_STATIC,static,1342308352
 723.915 +Control40=IDC_STATIC,static,1342308352
 723.916 +Control41=IDC_STATIC,static,1342308352
 723.917 +Control42=IDC_STATIC,static,1342308352
 723.918 +Control43=IDC_R16,static,1342308352
 723.919 +Control44=IDC_STATIC,static,1342308352
 723.920 +Control45=IDC_N,button,1476460547
 723.921 +Control46=IDC_Z,button,1476460547
 723.922 +Control47=IDC_C,button,1476460547
 723.923 +Control48=IDC_V,button,1476460547
 723.924 +Control49=IDC_F,button,1476460547
 723.925 +Control50=IDC_I,button,1476460547
 723.926 +Control51=IDC_T,button,1476460547
 723.927 +Control52=IDC_STATIC,static,1342308352
 723.928 +Control53=IDC_MODE,static,1342308352
 723.929 +Control54=IDC_VSCROLL,scrollbar,1342177281
 723.930 +Control55=IDC_GOPC,button,1342242816
 723.931 +
 723.932 +[DLG:IDD_GDB_PORT]
 723.933 +Type=1
 723.934 +Class=GDBPortDlg
 723.935 +ControlCount=4
 723.936 +Control1=ID_OK,button,1342242817
 723.937 +Control2=ID_CANCEL,button,1342242816
 723.938 +Control3=IDC_STATIC,static,1342308352
 723.939 +Control4=IDC_PORT,edit,1350631554
 723.940 +
 723.941 +[DLG:IDD_GDB_WAITING]
 723.942 +Type=1
 723.943 +Class=GDBWaitingDlg
 723.944 +ControlCount=3
 723.945 +Control1=ID_CANCEL,button,1342242816
 723.946 +Control2=IDC_STATIC,static,1342308352
 723.947 +Control3=IDC_PORT,static,1342308352
 723.948 +
 723.949 +[DLG:IDD_LOGGING]
 723.950 +Type=1
 723.951 +Class=Logging
 723.952 +ControlCount=15
 723.953 +Control1=IDC_VERBOSE_SWI,button,1342242819
 723.954 +Control2=IDC_VERBOSE_UNALIGNED_ACCESS,button,1342242819
 723.955 +Control3=IDC_VERBOSE_ILLEGAL_WRITE,button,1342242819
 723.956 +Control4=IDC_VERBOSE_ILLEGAL_READ,button,1342242819
 723.957 +Control5=IDC_VERBOSE_DMA0,button,1342242819
 723.958 +Control6=IDC_VERBOSE_DMA1,button,1342242819
 723.959 +Control7=IDC_VERBOSE_DMA2,button,1342242819
 723.960 +Control8=IDC_VERBOSE_DMA3,button,1342242819
 723.961 +Control9=IDC_VERBOSE_UNDEFINED,button,1342242819
 723.962 +Control10=IDC_VERBOSE_AGBPRINT,button,1342242819
 723.963 +Control11=IDC_LOG,edit,1353779396
 723.964 +Control12=IDC_SAVE,button,1342242816
 723.965 +Control13=IDC_CLEAR,button,1342242816
 723.966 +Control14=ID_OK,button,1342242817
 723.967 +Control15=IDC_STATIC,button,1342177287
 723.968 +
 723.969 +[DLG:IDD_ADDR_SIZE]
 723.970 +Type=1
 723.971 +Class=MemoryViewerAddressSize
 723.972 +ControlCount=6
 723.973 +Control1=IDC_ADDRESS,edit,1350631552
 723.974 +Control2=IDC_SIZE_CONTROL,edit,1350631552
 723.975 +Control3=ID_OK,button,1342242817
 723.976 +Control4=ID_CANCEL,button,1342242816
 723.977 +Control5=IDC_STATIC,static,1342308352
 723.978 +Control6=IDC_STATIC,static,1342308352
 723.979 +
 723.980 +[DLG:IDD_GB_DISASSEMBLE]
 723.981 +Type=1
 723.982 +Class=GBDisassemble
 723.983 +ControlCount=27
 723.984 +Control1=IDC_ADDRESS,edit,1350762632
 723.985 +Control2=IDC_GO,button,1342242816
 723.986 +Control3=IDC_DISASSEMBLE,listbox,1350631683
 723.987 +Control4=IDC_AUTO_UPDATE,button,1342242819
 723.988 +Control5=IDC_REFRESH,button,1342242816
 723.989 +Control6=IDC_NEXT,button,1342242816
 723.990 +Control7=IDC_CLOSE,button,1342242817
 723.991 +Control8=IDC_STATIC,static,1342308352
 723.992 +Control9=IDC_STATIC,static,1342308352
 723.993 +Control10=IDC_STATIC,static,1342308352
 723.994 +Control11=IDC_STATIC,static,1342308352
 723.995 +Control12=IDC_STATIC,static,1342308352
 723.996 +Control13=IDC_R0,static,1342308352
 723.997 +Control14=IDC_R1,static,1342308352
 723.998 +Control15=IDC_R2,static,1342308352
 723.999 +Control16=IDC_R3,static,1342308352
723.1000 +Control17=IDC_R6,static,1342308352
723.1001 +Control18=IDC_N,button,1476460547
723.1002 +Control19=IDC_Z,button,1476460547
723.1003 +Control20=IDC_C,button,1476460547
723.1004 +Control21=IDC_H,button,1476460547
723.1005 +Control22=IDC_VSCROLL,scrollbar,1342177281
723.1006 +Control23=IDC_GOPC,button,1342242816
723.1007 +Control24=IDC_STATIC,static,1342308352
723.1008 +Control25=IDC_R4,static,1342308352
723.1009 +Control26=IDC_STATIC,static,1342308352
723.1010 +Control27=IDC_R5,static,1342308352
723.1011 +
723.1012 +[DLG:IDD_GB_OAM_VIEW]
723.1013 +Type=1
723.1014 +Class=GBOamView
723.1015 +ControlCount=28
723.1016 +Control1=IDC_SPRITE,edit,1350639746
723.1017 +Control2=IDC_SCROLLBAR,scrollbar,1342177280
723.1018 +Control3=IDC_STRETCH,button,1342242819
723.1019 +Control4=IDC_REFRESH,button,1342373888
723.1020 +Control5=IDC_SAVE,button,1342373888
723.1021 +Control6=IDC_CLOSE,button,1342242816
723.1022 +Control7=IDC_OAM_VIEW,VbaBitmapControl,1342373888
723.1023 +Control8=IDC_OAM_VIEW_ZOOM,VbaZoomControl,1342373888
723.1024 +Control9=IDC_COLOR,VbaColorControl,1342242816
723.1025 +Control10=IDC_POS,static,1342308352
723.1026 +Control11=IDC_PALETTE,static,1342308352
723.1027 +Control12=IDC_TILE,static,1342308352
723.1028 +Control13=IDC_PRIO,static,1342308352
723.1029 +Control14=IDC_OAP,static,1342308352
723.1030 +Control15=IDC_FLAGS,static,1342308352
723.1031 +Control16=IDC_R,static,1342308352
723.1032 +Control17=IDC_G,static,1342308352
723.1033 +Control18=IDC_B,static,1342308352
723.1034 +Control19=IDC_STATIC,static,1342308352
723.1035 +Control20=IDC_STATIC,static,1342308352
723.1036 +Control21=IDC_STATIC,static,1342308352
723.1037 +Control22=IDC_STATIC,static,1342308352
723.1038 +Control23=IDC_STATIC,static,1342308352
723.1039 +Control24=IDC_STATIC,static,1342308352
723.1040 +Control25=IDC_STATIC,static,1342308352
723.1041 +Control26=IDC_AUTO_UPDATE,button,1342242819
723.1042 +Control27=IDC_BANK,static,1342308352
723.1043 +Control28=IDC_STATIC,static,1342308352
723.1044 +
723.1045 +[DLG:IDD_GB_TILE_VIEWER]
723.1046 +Type=1
723.1047 +Class=GBTileView
723.1048 +ControlCount=23
723.1049 +Control1=IDC_BANK_0,button,1342308361
723.1050 +Control2=IDC_BANK_1,button,1342177289
723.1051 +Control3=IDC_CHARBASE_0,button,1342308361
723.1052 +Control4=IDC_CHARBASE_1,button,1342177289
723.1053 +Control5=IDC_STRETCH,button,1342242819
723.1054 +Control6=IDC_REFRESH,button,1342373888
723.1055 +Control7=IDC_SAVE,button,1342242816
723.1056 +Control8=IDC_CLOSE,button,1342242816
723.1057 +Control9=IDC_TILE_VIEW,VbaBitmapControl,1342373888
723.1058 +Control10=IDC_STATIC,button,1342177287
723.1059 +Control11=IDC_STATIC,button,1342177287
723.1060 +Control12=IDC_MAP_VIEW_ZOOM,VbaZoomControl,1342373888
723.1061 +Control13=IDC_COLOR,VbaColorControl,1342242816
723.1062 +Control14=IDC_R,static,1342308352
723.1063 +Control15=IDC_G,static,1342308352
723.1064 +Control16=IDC_B,static,1342308352
723.1065 +Control17=IDC_STATIC,static,1342308352
723.1066 +Control18=IDC_AUTO_UPDATE,button,1342242819
723.1067 +Control19=IDC_STATIC,static,1342308352
723.1068 +Control20=IDC_STATIC,static,1342308352
723.1069 +Control21=IDC_TILE_NUMBER,static,1342308352
723.1070 +Control22=IDC_ADDRESS,static,1342308352
723.1071 +Control23=IDC_PALETTE_SLIDER,msctls_trackbar32,1342373889
723.1072 +
723.1073 +[DLG:IDD_GB_MAP_VIEW]
723.1074 +Type=1
723.1075 +Class=GBMapView
723.1076 +ControlCount=28
723.1077 +Control1=IDC_BANK_0,button,1342308361
723.1078 +Control2=IDC_BANK_1,button,1342177289
723.1079 +Control3=IDC_BG0,button,1342308361
723.1080 +Control4=IDC_BG1,button,1342177289
723.1081 +Control5=IDC_STRETCH,button,1342242819
723.1082 +Control6=IDC_REFRESH,button,1342373888
723.1083 +Control7=IDC_SAVE,button,1342373888
723.1084 +Control8=IDC_CLOSE,button,1342242816
723.1085 +Control9=IDC_MAP_VIEW,VbaBitmapControl,1342373888
723.1086 +Control10=IDC_MAP_VIEW_ZOOM,VbaZoomControl,1342373888
723.1087 +Control11=IDC_COLOR,VbaColorControl,1342242816
723.1088 +Control12=IDC_R,static,1342308352
723.1089 +Control13=IDC_G,static,1342308352
723.1090 +Control14=IDC_B,static,1342308352
723.1091 +Control15=IDC_STATIC,button,1342177287
723.1092 +Control16=IDC_STATIC,button,1342177287
723.1093 +Control17=IDC_AUTO_UPDATE,button,1342242819
723.1094 +Control18=IDC_XY,static,1342308352
723.1095 +Control19=IDC_STATIC,static,1342308352
723.1096 +Control20=IDC_PRIORITY,static,1342308352
723.1097 +Control21=IDC_STATIC,static,1342308352
723.1098 +Control22=IDC_ADDRESS,static,1342308352
723.1099 +Control23=IDC_STATIC,static,1342308352
723.1100 +Control24=IDC_TILE_NUM,static,1342308352
723.1101 +Control25=IDC_STATIC,static,1342308352
723.1102 +Control26=IDC_FLIP,static,1342308352
723.1103 +Control27=IDC_STATIC,static,1342308352
723.1104 +Control28=IDC_PALETTE_NUM,static,1342308352
723.1105 +
723.1106 +[DLG:IDD_GB_PALETTE_VIEW]
723.1107 +Type=1
723.1108 +Class=GBPaletteView
723.1109 +ControlCount=21
723.1110 +Control1=IDC_SAVE_BG,button,1342242816
723.1111 +Control2=IDC_SAVE_OBJ,button,1342242816
723.1112 +Control3=IDC_REFRESH2,button,1342242816
723.1113 +Control4=IDC_CLOSE,button,1342242816
723.1114 +Control5=IDC_ADDRESS,static,1342308352
723.1115 +Control6=IDC_R,static,1342308352
723.1116 +Control7=IDC_G,static,1342308352
723.1117 +Control8=IDC_B,static,1342308352
723.1118 +Control9=IDC_VALUE,static,1342308352
723.1119 +Control10=IDC_COLOR,VbaColorControl,1342242816
723.1120 +Control11=IDC_PALETTE_VIEW,VbaPaletteViewControl,1342242816
723.1121 +Control12=IDC_PALETTE_VIEW_OBJ,VbaPaletteViewControl,1342242816
723.1122 +Control13=IDC_STATIC,button,1342177287
723.1123 +Control14=IDC_STATIC,button,1342177287
723.1124 +Control15=IDC_STATIC,static,1342308352
723.1125 +Control16=IDC_STATIC,static,1342308352
723.1126 +Control17=IDC_STATIC,static,1342308352
723.1127 +Control18=IDC_STATIC,static,1342308352
723.1128 +Control19=IDC_STATIC,static,1342308352
723.1129 +Control20=IDC_STATIC,static,1342308352
723.1130 +Control21=IDC_AUTO_UPDATE,button,1342242819
723.1131 +
723.1132 +[DLG:IDD_IO_VIEWER]
723.1133 +Type=1
723.1134 +Class=IOViewer
723.1135 +ControlCount=23
723.1136 +Control1=IDC_ADDRESSES,combobox,1344339971
723.1137 +Control2=IDC_VALUE,static,1342308354
723.1138 +Control3=IDC_BIT_15,button,1342242819
723.1139 +Control4=IDC_BIT_14,button,1342242819
723.1140 +Control5=IDC_BIT_13,button,1342242819
723.1141 +Control6=IDC_BIT_12,button,1342242819
723.1142 +Control7=IDC_BIT_11,button,1342242819
723.1143 +Control8=IDC_BIT_10,button,1342242819
723.1144 +Control9=IDC_BIT_9,button,1342242819
723.1145 +Control10=IDC_BIT_8,button,1342242819
723.1146 +Control11=IDC_BIT_7,button,1342242819
723.1147 +Control12=IDC_BIT_6,button,1342242819
723.1148 +Control13=IDC_BIT_5,button,1342242819
723.1149 +Control14=IDC_BIT_4,button,1342242819
723.1150 +Control15=IDC_BIT_3,button,1342242819
723.1151 +Control16=IDC_BIT_2,button,1342242819
723.1152 +Control17=IDC_BIT_1,button,1342242819
723.1153 +Control18=IDC_BIT_0,button,1342242819
723.1154 +Control19=IDC_AUTO_UPDATE,button,1342242819
723.1155 +Control20=IDC_REFRESH,button,1342242817
723.1156 +Control21=IDC_APPLY,button,1342242817
723.1157 +Control22=IDC_CLOSE,button,1342242816
723.1158 +Control23=IDC_STATIC,static,1342308352
723.1159 +
723.1160 +[MNU:IDR_MENU]
723.1161 +Type=1
723.1162 +Class=MainWnd
723.1163 +Command1=ID_FILE_OPEN
723.1164 +Command2=ID_FILE_OPENGAMEBOY
723.1165 +Command3=ID_FILE_LOAD
723.1166 +Command4=ID_FILE_SAVE
723.1167 +Command5=ID_FILE_LOADGAME_MOSTRECENT
723.1168 +Command6=ID_FILE_LOADGAME_AUTOLOADMOSTRECENT
723.1169 +Command7=ID_FILE_LOADGAME_SLOT1
723.1170 +Command8=ID_FILE_LOADGAME_SLOT2
723.1171 +Command9=ID_FILE_LOADGAME_SLOT3
723.1172 +Command10=ID_FILE_LOADGAME_SLOT4
723.1173 +Command11=ID_FILE_LOADGAME_SLOT5
723.1174 +Command12=ID_FILE_LOADGAME_SLOT6
723.1175 +Command13=ID_FILE_LOADGAME_SLOT7
723.1176 +Command14=ID_FILE_LOADGAME_SLOT8
723.1177 +Command15=ID_FILE_LOADGAME_SLOT9
723.1178 +Command16=ID_FILE_LOADGAME_SLOT10
723.1179 +Command17=ID_FILE_SAVEGAME_OLDESTSLOT
723.1180 +Command18=ID_FILE_SAVEGAME_SLOT1
723.1181 +Command19=ID_FILE_SAVEGAME_SLOT2
723.1182 +Command20=ID_FILE_SAVEGAME_SLOT3
723.1183 +Command21=ID_FILE_SAVEGAME_SLOT4
723.1184 +Command22=ID_FILE_SAVEGAME_SLOT5
723.1185 +Command23=ID_FILE_SAVEGAME_SLOT6
723.1186 +Command24=ID_FILE_SAVEGAME_SLOT7
723.1187 +Command25=ID_FILE_SAVEGAME_SLOT8
723.1188 +Command26=ID_FILE_SAVEGAME_SLOT9
723.1189 +Command27=ID_FILE_SAVEGAME_SLOT10
723.1190 +Command28=ID_FILE_PAUSE
723.1191 +Command29=ID_FILE_RESET
723.1192 +Command30=ID_FILE_RECENT_RESET
723.1193 +Command31=ID_FILE_RECENT_FREEZE
723.1194 +Command32=ID_FILE_IMPORT_BATTERYFILE
723.1195 +Command33=ID_FILE_IMPORT_GAMESHARKCODEFILE
723.1196 +Command34=ID_FILE_IMPORT_GAMESHARKSNAPSHOT
723.1197 +Command35=ID_FILE_EXPORT_BATTERYFILE
723.1198 +Command36=ID_FILE_EXPORT_GAMESHARKSNAPSHOT
723.1199 +Command37=ID_FILE_SCREENCAPTURE
723.1200 +Command38=ID_FILE_ROMINFORMATION
723.1201 +Command39=ID_FILE_TOGGLEMENU
723.1202 +Command40=ID_FILE_CLOSE
723.1203 +Command41=ID_FILE_EXIT
723.1204 +Command42=ID_OPTIONS_FRAMESKIP_THROTTLE_NOTHROTTLE
723.1205 +Command43=ID_OPTIONS_FRAMESKIP_THROTTLE_25
723.1206 +Command44=ID_OPTIONS_FRAMESKIP_THROTTLE_50
723.1207 +Command45=ID_OPTIONS_FRAMESKIP_THROTTLE_100
723.1208 +Command46=ID_OPTIONS_FRAMESKIP_THROTTLE_150
723.1209 +Command47=ID_OPTIONS_FRAMESKIP_THROTTLE_200
723.1210 +Command48=ID_OPTIONS_FRAMESKIP_THROTTLE_OTHER
723.1211 +Command49=ID_OPTIONS_FRAMESKIP_AUTOMATIC
723.1212 +Command50=ID_OPTIONS_VIDEO_FRAMESKIP_0
723.1213 +Command51=ID_OPTIONS_VIDEO_FRAMESKIP_1
723.1214 +Command52=ID_OPTIONS_VIDEO_FRAMESKIP_2
723.1215 +Command53=ID_OPTIONS_VIDEO_FRAMESKIP_3
723.1216 +Command54=ID_OPTIONS_VIDEO_FRAMESKIP_4
723.1217 +Command55=ID_OPTIONS_VIDEO_FRAMESKIP_5
723.1218 +Command56=ID_OPTIONS_VIDEO_FRAMESKIP_6
723.1219 +Command57=ID_OPTIONS_VIDEO_FRAMESKIP_7
723.1220 +Command58=ID_OPTIONS_VIDEO_FRAMESKIP_8
723.1221 +Command59=ID_OPTIONS_VIDEO_FRAMESKIP_9
723.1222 +Command60=ID_OPTIONS_VIDEO_VSYNC
723.1223 +Command61=ID_OPTIONS_VIDEO_RENDERMETHOD_GDI
723.1224 +Command62=ID_OPTIONS_VIDEO_RENDERMETHOD_DIRECTDRAW
723.1225 +Command63=ID_OPTIONS_VIDEO_RENDERMETHOD_DIRECT3D
723.1226 +Command64=ID_OPTIONS_VIDEO_RENDERMETHOD_OPENGL
723.1227 +Command65=ID_OPTIONS_VIDEO_DDRAWEMULATIONONLY
723.1228 +Command66=ID_OPTIONS_VIDEO_DDRAWUSEVIDEOMEMORY
723.1229 +Command67=ID_OPTIONS_VIDEO_TRIPLEBUFFERING
723.1230 +Command68=ID_OPTIONS_VIDEO_RENDEROPTIONS_D3DNOFILTER
723.1231 +Command69=ID_OPTIONS_VIDEO_RENDEROPTIONS_D3DBILINEAR
723.1232 +Command70=ID_OPTIONS_VIDEO_RENDEROPTIONS_GLNEAREST
723.1233 +Command71=ID_OPTIONS_VIDEO_RENDEROPTIONS_GLBILINEAR
723.1234 +Command72=ID_OPTIONS_VIDEO_RENDEROPTIONS_GLTRIANGLE
723.1235 +Command73=ID_OPTIONS_VIDEO_RENDEROPTIONS_GLQUADS
723.1236 +Command74=ID_OPTIONS_VIDEO_RENDEROPTIONS_SELECTSKIN
723.1237 +Command75=ID_OPTIONS_VIDEO_RENDEROPTIONS_SKIN
723.1238 +Command76=ID_OPTIONS_VIDEO_X1
723.1239 +Command77=ID_OPTIONS_VIDEO_X2
723.1240 +Command78=ID_OPTIONS_VIDEO_X3
723.1241 +Command79=ID_OPTIONS_VIDEO_X4
723.1242 +Command80=ID_OPTIONS_VIDEO_FULLSCREEN320X240
723.1243 +Command81=ID_OPTIONS_VIDEO_FULLSCREEN640X480
723.1244 +Command82=ID_OPTIONS_VIDEO_FULLSCREEN800X600
723.1245 +Command83=ID_OPTIONS_VIDEO_FULLSCREEN
723.1246 +Command84=ID_OPTIONS_VIDEO_FULLSCREENMAXSCALE
723.1247 +Command85=ID_OPTIONS_VIDEO_DISABLESFX
723.1248 +Command86=ID_OPTIONS_VIDEO_FULLSCREENSTRETCHTOFIT
723.1249 +Command87=ID_OPTIONS_VIDEO_LAYERS_BG0
723.1250 +Command88=ID_OPTIONS_VIDEO_LAYERS_BG1
723.1251 +Command89=ID_OPTIONS_VIDEO_LAYERS_BG2
723.1252 +Command90=ID_OPTIONS_VIDEO_LAYERS_BG3
723.1253 +Command91=ID_OPTIONS_VIDEO_LAYERS_OBJ
723.1254 +Command92=ID_OPTIONS_VIDEO_LAYERS_WIN0
723.1255 +Command93=ID_OPTIONS_VIDEO_LAYERS_WIN1
723.1256 +Command94=ID_OPTIONS_VIDEO_LAYERS_OBJWIN
723.1257 +Command95=ID_OPTIONS_EMULATOR_ASSOCIATE
723.1258 +Command96=ID_OPTIONS_EMULATOR_DIRECTORIES
723.1259 +Command97=ID_OPTIONS_EMULATOR_DISABLESTATUSMESSAGES
723.1260 +Command98=ID_OPTIONS_EMULATOR_SYNCHRONIZE
723.1261 +Command99=ID_OPTIONS_EMULATOR_PAUSEWHENINACTIVE
723.1262 +Command100=ID_OPTIONS_EMULATOR_SPEEDUPTOGGLE
723.1263 +Command101=ID_OPTIONS_EMULATOR_REMOVEINTROSGBA
723.1264 +Command102=ID_OPTIONS_EMULATOR_AUTOMATICALLYIPSPATCH
723.1265 +Command103=ID_OPTIONS_EMULATOR_AGBPRINT
723.1266 +Command104=ID_OPTIONS_EMULATOR_REALTIMECLOCK
723.1267 +Command105=ID_OPTIONS_EMULATOR_AUTOHIDEMENU
723.1268 +Command106=ID_OPTIONS_EMULATOR_REWINDINTERVAL
723.1269 +Command107=ID_OPTIONS_EMULATOR_SHOWSPEED_NONE
723.1270 +Command108=ID_OPTIONS_EMULATOR_SHOWSPEED_PERCENTAGE
723.1271 +Command109=ID_OPTIONS_EMULATOR_SHOWSPEED_DETAILED
723.1272 +Command110=ID_OPTIONS_EMULATOR_SHOWSPEED_TRANSPARENT
723.1273 +Command111=ID_OPTIONS_EMULATOR_SAVETYPE_AUTOMATIC
723.1274 +Command112=ID_OPTIONS_EMULATOR_SAVETYPE_EEPROM
723.1275 +Command113=ID_OPTIONS_EMULATOR_SAVETYPE_SRAM
723.1276 +Command114=ID_OPTIONS_EMULATOR_SAVETYPE_FLASH
723.1277 +Command115=ID_OPTIONS_EMULATOR_SAVETYPE_EEPROMSENSOR
723.1278 +Command116=ID_OPTIONS_EMULATOR_SAVETYPE_NONE
723.1279 +Command117=ID_OPTIONS_EMULATOR_SAVETYPE_FLASH512K
723.1280 +Command118=ID_OPTIONS_EMULATOR_SAVETYPE_FLASH1M
723.1281 +Command119=ID_OPTIONS_EMULATOR_SAVETYPE_ENHANCEDDETECTION
723.1282 +Command120=ID_OPTIONS_EMULATOR_USEBIOSFILE
723.1283 +Command121=ID_OPTIONS_EMULATOR_SKIPBIOS
723.1284 +Command122=ID_OPTIONS_EMULATOR_SELECTBIOSFILE
723.1285 +Command123=ID_OPTIONS_EMULATOR_PNGFORMAT
723.1286 +Command124=ID_OPTIONS_EMULATOR_BMPFORMAT
723.1287 +Command125=ID_OPTIONS_SOUND_OFF
723.1288 +Command126=ID_OPTIONS_SOUND_MUTE
723.1289 +Command127=ID_OPTIONS_SOUND_ON
723.1290 +Command128=ID_OPTIONS_SOUND_USEOLDSYNCHRONIZATION
723.1291 +Command129=ID_OPTIONS_SOUND_ECHO
723.1292 +Command130=ID_OPTIONS_SOUND_LOWPASSFILTER
723.1293 +Command131=ID_OPTIONS_SOUND_REVERSESTEREO
723.1294 +Command132=ID_OPTIONS_SOUND_CHANNEL1
723.1295 +Command133=ID_OPTIONS_SOUND_CHANNEL2
723.1296 +Command134=ID_OPTIONS_SOUND_CHANNEL3
723.1297 +Command135=ID_OPTIONS_SOUND_CHANNEL4
723.1298 +Command136=ID_OPTIONS_SOUND_DIRECTSOUNDA
723.1299 +Command137=ID_OPTIONS_SOUND_DIRECTSOUNDB
723.1300 +Command138=ID_OPTIONS_SOUND_11KHZ
723.1301 +Command139=ID_OPTIONS_SOUND_22KHZ
723.1302 +Command140=ID_OPTIONS_SOUND_44KHZ
723.1303 +Command141=ID_OPTIONS_SOUND_VOLUME_25X
723.1304 +Command142=ID_OPTIONS_SOUND_VOLUME_5X
723.1305 +Command143=ID_OPTIONS_SOUND_VOLUME_1X
723.1306 +Command144=ID_OPTIONS_SOUND_VOLUME_2X
723.1307 +Command145=ID_OPTIONS_SOUND_VOLUME_3X
723.1308 +Command146=ID_OPTIONS_SOUND_VOLUME_4X
723.1309 +Command147=ID_OPTIONS_GAMEBOY_BORDER
723.1310 +Command148=ID_OPTIONS_GAMEBOY_PRINTER
723.1311 +Command149=ID_OPTIONS_GAMEBOY_BORDERAUTOMATIC
723.1312 +Command150=ID_OPTIONS_GAMEBOY_AUTOMATIC
723.1313 +Command151=ID_OPTIONS_GAMEBOY_GBA
723.1314 +Command152=ID_OPTIONS_GAMEBOY_CGB
723.1315 +Command153=ID_OPTIONS_GAMEBOY_SGB
723.1316 +Command154=ID_OPTIONS_GAMEBOY_SGB2
723.1317 +Command155=ID_OPTIONS_GAMEBOY_GB
723.1318 +Command156=ID_OPTIONS_GAMEBOY_REALCOLORS
723.1319 +Command157=ID_OPTIONS_GAMEBOY_GAMEBOYCOLORS
723.1320 +Command158=ID_OPTIONS_GAMEBOY_COLORS
723.1321 +Command159=ID_OPTIONS_PRIORITY_HIGHEST
723.1322 +Command160=ID_OPTIONS_PRIORITY_ABOVENORMAL
723.1323 +Command161=ID_OPTIONS_PRIORITY_NORMAL
723.1324 +Command162=ID_OPTIONS_PRIORITY_BELOWNORMAL
723.1325 +Command163=ID_OPTIONS_FILTER_INTERFRAMEBLENDING_NONE
723.1326 +Command164=ID_OPTIONS_FILTER_INTERFRAMEBLENDING_MOTIONBLUR
723.1327 +Command165=ID_OPTIONS_FILTER_INTERFRAMEBLENDING_SMART
723.1328 +Command166=ID_OPTIONS_FILTER_NORMAL
723.1329 +Command167=ID_OPTIONS_FILTER_TVMODE
723.1330 +Command168=ID_OPTIONS_FILTER_2XSAI
723.1331 +Command169=ID_OPTIONS_FILTER_SUPER2XSAI
723.1332 +Command170=ID_OPTIONS_FILTER_SUPEREAGLE
723.1333 +Command171=ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL
723.1334 +Command172=ID_OPTIONS_FILTER16BIT_MOTIONBLUREXPERIMENTAL
723.1335 +Command173=ID_OPTIONS_FILTER16BIT_ADVANCEMAMESCALE2X
723.1336 +Command174=ID_OPTIONS_FILTER16BIT_SIMPLE2X
723.1337 +Command175=ID_OPTIONS_FILTER_BILINEAR
723.1338 +Command176=ID_OPTIONS_FILTER_BILINEARPLUS
723.1339 +Command177=ID_OPTIONS_FILTER_SCANLINES
723.1340 +Command178=ID_OPTIONS_FILTER_HQ2X
723.1341 +Command179=ID_OPTIONS_FILTER_LQ2X
723.1342 +Command180=ID_OPTIONS_FILTER_DISABLEMMX
723.1343 +Command181=ID_OPTIONS_JOYPAD_CONFIGURE_1
723.1344 +Command182=ID_OPTIONS_JOYPAD_CONFIGURE_2
723.1345 +Command183=ID_OPTIONS_JOYPAD_CONFIGURE_3
723.1346 +Command184=ID_OPTIONS_JOYPAD_CONFIGURE_4
723.1347 +Command185=ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_1
723.1348 +Command186=ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_2
723.1349 +Command187=ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_3
723.1350 +Command188=ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_4
723.1351 +Command189=ID_OPTIONS_JOYPAD_MOTIONCONFIGURE
723.1352 +Command190=ID_OPTIONS_JOYPAD_AUTOFIRE_A
723.1353 +Command191=ID_OPTIONS_JOYPAD_AUTOFIRE_B
723.1354 +Command192=ID_OPTIONS_JOYPAD_AUTOFIRE_L
723.1355 +Command193=ID_OPTIONS_JOYPAD_AUTOFIRE_R
723.1356 +Command194=ID_OPTIONS_LANGUAGE_SYSTEM
723.1357 +Command195=ID_OPTIONS_LANGUAGE_ENGLISH
723.1358 +Command196=ID_OPTIONS_LANGUAGE_OTHER
723.1359 +Command197=ID_CHEATS_SEARCHFORCHEATS
723.1360 +Command198=ID_CHEATS_CHEATLIST
723.1361 +Command199=ID_CHEATS_AUTOMATICSAVELOADCHEATS
723.1362 +Command200=ID_CHEATS_DISABLECHEATS
723.1363 +Command201=ID_CHEATS_LOADCHEATLIST
723.1364 +Command202=ID_CHEATS_SAVECHEATLIST
723.1365 +Command203=ID_TOOLS_DISASSEMBLE
723.1366 +Command204=ID_TOOLS_LOGGING
723.1367 +Command205=ID_TOOLS_IOVIEWER
723.1368 +Command206=ID_TOOLS_MAPVIEW
723.1369 +Command207=ID_TOOLS_MEMORYVIEWER
723.1370 +Command208=ID_TOOLS_OAMVIEWER
723.1371 +Command209=ID_TOOLS_PALETTEVIEW
723.1372 +Command210=ID_TOOLS_TILEVIEWER
723.1373 +Command211=ID_DEBUG_NEXTFRAME
723.1374 +Command212=ID_TOOLS_DEBUG_GDB
723.1375 +Command213=ID_TOOLS_DEBUG_LOADANDWAIT
723.1376 +Command214=ID_TOOLS_DEBUG_BREAK
723.1377 +Command215=ID_TOOLS_DEBUG_DISCONNECT
723.1378 +Command216=ID_OPTIONS_SOUND_STARTRECORDING
723.1379 +Command217=ID_OPTIONS_SOUND_STOPRECORDING
723.1380 +Command218=ID_TOOLS_RECORD_STARTAVIRECORDING
723.1381 +Command219=ID_TOOLS_RECORD_STOPAVIRECORDING
723.1382 +Command220=ID_TOOLS_RECORD_STARTMOVIERECORDING
723.1383 +Command221=ID_TOOLS_RECORD_STOPMOVIERECORDING
723.1384 +Command222=ID_TOOLS_PLAY_STARTMOVIEPLAYING
723.1385 +Command223=ID_TOOLS_PLAY_STOPMOVIEPLAYING
723.1386 +Command224=ID_TOOLS_REWIND
723.1387 +Command225=ID_TOOLS_CUSTOMIZE
723.1388 +Command226=ID_HELP_BUGREPORT
723.1389 +Command227=ID_HELP_FAQ
723.1390 +Command228=ID_HELP_ABOUT
723.1391 +CommandCount=228
723.1392 +
723.1393 +[ACL:IDR_ACCELERATOR]
723.1394 +Type=1
723.1395 +Class=?
723.1396 +Command1=ID_OPTIONS_VIDEO_LAYERS_BG0
723.1397 +Command2=ID_OPTIONS_JOYPAD_AUTOFIRE_A
723.1398 +Command3=ID_OPTIONS_VIDEO_LAYERS_BG1
723.1399 +Command4=ID_OPTIONS_JOYPAD_AUTOFIRE_B
723.1400 +Command5=ID_OPTIONS_VIDEO_LAYERS_BG2
723.1401 +Command6=ID_OPTIONS_JOYPAD_AUTOFIRE_L
723.1402 +Command7=ID_OPTIONS_VIDEO_LAYERS_BG3
723.1403 +Command8=ID_OPTIONS_JOYPAD_AUTOFIRE_R
723.1404 +Command9=ID_OPTIONS_VIDEO_LAYERS_OBJ
723.1405 +Command10=ID_OPTIONS_VIDEO_LAYERS_WIN0
723.1406 +Command11=ID_OPTIONS_VIDEO_LAYERS_WIN1
723.1407 +Command12=ID_OPTIONS_VIDEO_LAYERS_OBJWIN
723.1408 +Command13=ID_TOOLS_REWIND
723.1409 +Command14=ID_CHEATS_SEARCHFORCHEATS
723.1410 +Command15=ID_FILE_LOAD
723.1411 +Command16=ID_DEBUG_NEXTFRAME
723.1412 +Command17=ID_FILE_OPEN
723.1413 +Command18=ID_FILE_PAUSE
723.1414 +Command19=ID_FILE_RESET
723.1415 +Command20=ID_FILE_SAVE
723.1416 +Command21=ID_FILE_TOGGLEMENU
723.1417 +Command22=ID_FILE_LOADGAME_SLOT1
723.1418 +Command23=ID_FILE_MRU_FILE1
723.1419 +Command24=ID_FILE_SAVEGAME_SLOT1
723.1420 +Command25=ID_FILE_LOADGAME_SLOT10
723.1421 +Command26=ID_FILE_MRU_FILE10
723.1422 +Command27=ID_FILE_SAVEGAME_SLOT10
723.1423 +Command28=ID_FILE_LOADGAME_SLOT2
723.1424 +Command29=ID_FILE_MRU_FILE2
723.1425 +Command30=ID_FILE_SAVEGAME_SLOT2
723.1426 +Command31=ID_FILE_LOADGAME_SLOT3
723.1427 +Command32=ID_FILE_MRU_FILE3
723.1428 +Command33=ID_FILE_SAVEGAME_SLOT3
723.1429 +Command34=ID_FILE_LOADGAME_SLOT4
723.1430 +Command35=ID_FILE_MRU_FILE4
723.1431 +Command36=ID_FILE_SAVEGAME_SLOT4
723.1432 +Command37=ID_FILE_LOADGAME_SLOT5
723.1433 +Command38=ID_FILE_MRU_FILE5
723.1434 +Command39=ID_FILE_SAVEGAME_SLOT5
723.1435 +Command40=ID_FILE_LOADGAME_SLOT6
723.1436 +Command41=ID_FILE_MRU_FILE6
723.1437 +Command42=ID_FILE_SAVEGAME_SLOT6
723.1438 +Command43=ID_FILE_LOADGAME_SLOT7
723.1439 +Command44=ID_FILE_MRU_FILE7
723.1440 +Command45=ID_FILE_SAVEGAME_SLOT7
723.1441 +Command46=ID_FILE_LOADGAME_SLOT8
723.1442 +Command47=ID_FILE_MRU_FILE8
723.1443 +Command48=ID_FILE_SAVEGAME_SLOT8
723.1444 +Command49=ID_FILE_LOADGAME_SLOT9
723.1445 +Command50=ID_FILE_MRU_FILE9
723.1446 +Command51=ID_FILE_SAVEGAME_SLOT9
723.1447 +Command52=ID_FILE_EXIT
723.1448 +CommandCount=52
723.1449 +
723.1450 +[CLS:AddGSACode]
723.1451 +Type=0
723.1452 +HeaderFile=GBACheats.h
723.1453 +ImplementationFile=GBACheats.cpp
723.1454 +BaseClass=CDialog
723.1455 +Filter=D
723.1456 +VirtualFilter=dWC
723.1457 +LastObject=AddGSACode
723.1458 +
723.1459 +[CLS:GBCheatList]
723.1460 +Type=0
723.1461 +HeaderFile=GBCheatsDlg.h
723.1462 +ImplementationFile=GBCheatsDlg.cpp
723.1463 +BaseClass=CDialog
723.1464 +Filter=D
723.1465 +VirtualFilter=dWC
723.1466 +LastObject=GBCheatList
723.1467 +
723.1468 +[CLS:Disassemble]
723.1469 +Type=0
723.1470 +HeaderFile=Disassemble.h
723.1471 +ImplementationFile=Disassemble.cpp
723.1472 +BaseClass=CDialog
723.1473 +Filter=D
723.1474 +VirtualFilter=dWC
723.1475 +LastObject=Disassemble
723.1476 +
723.1477 +[CLS:GBDisassemble]
723.1478 +Type=0
723.1479 +HeaderFile=GBDisassemble.h
723.1480 +ImplementationFile=GBDisassemble.cpp
723.1481 +BaseClass=CDialog
723.1482 +Filter=D
723.1483 +LastObject=IDC_GO
723.1484 +VirtualFilter=dWC
723.1485 +
723.1486 +[CLS:Logging]
723.1487 +Type=0
723.1488 +HeaderFile=Logging.h
723.1489 +ImplementationFile=Logging.cpp
723.1490 +BaseClass=CDialog
723.1491 +Filter=D
723.1492 +VirtualFilter=dWC
723.1493 +LastObject=IDC_LOG
723.1494 +
723.1495 +[CLS:IOViewer]
723.1496 +Type=0
723.1497 +HeaderFile=IOViewer.h
723.1498 +ImplementationFile=IOViewer.cpp
723.1499 +BaseClass=CDialog
723.1500 +Filter=D
723.1501 +VirtualFilter=dWC
723.1502 +LastObject=ID_FILE_LOADGAME_SLOT1
723.1503 +
723.1504 +[CLS:ZoomControl]
723.1505 +Type=0
723.1506 +HeaderFile=ZoomControl.h
723.1507 +ImplementationFile=ZoomControl.cpp
723.1508 +BaseClass=CWnd
723.1509 +Filter=W
723.1510 +VirtualFilter=WC
723.1511 +LastObject=ZoomControl
723.1512 +
723.1513 +[CLS:BitmapControl]
723.1514 +Type=0
723.1515 +HeaderFile=BitmapControl.h
723.1516 +ImplementationFile=BitmapControl.cpp
723.1517 +BaseClass=CScrollView
723.1518 +Filter=C
723.1519 +VirtualFilter=VWC
723.1520 +LastObject=BitmapControl
723.1521 +
723.1522 +[CLS:MapView]
723.1523 +Type=0
723.1524 +HeaderFile=MapView.h
723.1525 +ImplementationFile=MapView.cpp
723.1526 +BaseClass=CDialog
723.1527 +Filter=D
723.1528 +LastObject=ID_CHEATS_AUTOMATICSAVELOADCHEATS
723.1529 +VirtualFilter=dWC
723.1530 +
723.1531 +[CLS:GBMapView]
723.1532 +Type=0
723.1533 +HeaderFile=GBMapView.h
723.1534 +ImplementationFile=GBMapView.cpp
723.1535 +BaseClass=CDialog
723.1536 +Filter=D
723.1537 +LastObject=GBMapView
723.1538 +VirtualFilter=dWC
723.1539 +
723.1540 +[CLS:MemoryViewer]
723.1541 +Type=0
723.1542 +HeaderFile=MemoryViewer.h
723.1543 +ImplementationFile=MemoryViewer.cpp
723.1544 +BaseClass=CWnd
723.1545 +Filter=W
723.1546 +VirtualFilter=WC
723.1547 +LastObject=ID_CHEATS_AUTOMATICSAVELOADCHEATS
723.1548 +
723.1549 +[CLS:MemoryViewerDlg]
723.1550 +Type=0
723.1551 +HeaderFile=MemoryViewerDlg.h
723.1552 +ImplementationFile=MemoryViewerDlg.cpp
723.1553 +BaseClass=CDialog
723.1554 +Filter=D
723.1555 +VirtualFilter=dWC
723.1556 +LastObject=MemoryViewerDlg
723.1557 +
723.1558 +[CLS:MemoryViewerAddressSize]
723.1559 +Type=0
723.1560 +HeaderFile=MemoryViewerAddressSize.h
723.1561 +ImplementationFile=MemoryViewerAddressSize.cpp
723.1562 +BaseClass=CDialog
723.1563 +Filter=D
723.1564 +LastObject=ID_CANCEL
723.1565 +VirtualFilter=dWC
723.1566 +
723.1567 +[CLS:GBMemoryViewerDlg]
723.1568 +Type=0
723.1569 +HeaderFile=GBMemoryViewerDlg.h
723.1570 +ImplementationFile=GBMemoryViewerDlg.cpp
723.1571 +BaseClass=CDialog
723.1572 +Filter=D
723.1573 +LastObject=GBMemoryViewerDlg
723.1574 +VirtualFilter=dWC
723.1575 +
723.1576 +[CLS:OamView]
723.1577 +Type=0
723.1578 +HeaderFile=OamView.h
723.1579 +ImplementationFile=OamView.cpp
723.1580 +BaseClass=CDialog
723.1581 +Filter=D
723.1582 +VirtualFilter=dWC
723.1583 +LastObject=ID_CHEATS_AUTOMATICSAVELOADCHEATS
723.1584 +
723.1585 +[CLS:GBOamView]
723.1586 +Type=0
723.1587 +HeaderFile=GBOamView.h
723.1588 +ImplementationFile=GBOamView.cpp
723.1589 +BaseClass=CDialog
723.1590 +Filter=D
723.1591 +LastObject=GBOamView
723.1592 +VirtualFilter=dWC
723.1593 +
723.1594 +[CLS:PaletteViewControl]
723.1595 +Type=0
723.1596 +HeaderFile=PaletteViewControl.h
723.1597 +ImplementationFile=PaletteViewControl.cpp
723.1598 +BaseClass=CWnd
723.1599 +Filter=W
723.1600 +VirtualFilter=WC
723.1601 +LastObject=ID_CHEATS_AUTOMATICSAVELOADCHEATS
723.1602 +
723.1603 +[CLS:PaletteView]
723.1604 +Type=0
723.1605 +HeaderFile=paletteview.h
723.1606 +ImplementationFile=paletteview.cpp
723.1607 +BaseClass=CDialog
723.1608 +LastObject=ID_CHEATS_AUTOMATICSAVELOADCHEATS
723.1609 +
723.1610 +[CLS:GBPaletteView]
723.1611 +Type=0
723.1612 +HeaderFile=GBPaletteView.h
723.1613 +ImplementationFile=GBPaletteView.cpp
723.1614 +BaseClass=CDialog
723.1615 +Filter=D
723.1616 +LastObject=GBPaletteView
723.1617 +VirtualFilter=dWC
723.1618 +
723.1619 +[CLS:TileView]
723.1620 +Type=0
723.1621 +HeaderFile=TileView.h
723.1622 +ImplementationFile=TileView.cpp
723.1623 +BaseClass=CDialog
723.1624 +Filter=D
723.1625 +VirtualFilter=dWC
723.1626 +LastObject=ID_CHEATS_AUTOMATICSAVELOADCHEATS
723.1627 +
723.1628 +[CLS:GBTileView]
723.1629 +Type=0
723.1630 +HeaderFile=GBTileView.h
723.1631 +ImplementationFile=GBTileView.cpp
723.1632 +BaseClass=CDialog
723.1633 +Filter=D
723.1634 +LastObject=GBTileView
723.1635 +VirtualFilter=dWC
723.1636 +
723.1637 +[CLS:GBPrinterDlg]
723.1638 +Type=0
723.1639 +HeaderFile=gbprinterdlg.h
723.1640 +ImplementationFile=gbprinterdlg.cpp
723.1641 +BaseClass=CDialog
723.1642 +Filter=D
723.1643 +VirtualFilter=dWC
723.1644 +LastObject=GBPrinterDlg
723.1645 +
723.1646 +[CLS:GDBPortDlg]
723.1647 +Type=0
723.1648 +HeaderFile=GDBConnection.h
723.1649 +ImplementationFile=GDBConnection.cpp
723.1650 +BaseClass=CDialog
723.1651 +Filter=D
723.1652 +LastObject=GDBPortDlg
723.1653 +VirtualFilter=dWC
723.1654 +
723.1655 +[CLS:GDBWaitingDlg]
723.1656 +Type=0
723.1657 +HeaderFile=GDBConnection.h
723.1658 +ImplementationFile=GDBConnection.cpp
723.1659 +BaseClass=CDialog
723.1660 +Filter=D
723.1661 +LastObject=GDBWaitingDlg
723.1662 +VirtualFilter=dWC
723.1663 +
723.1664 +[CLS:AccelEditor]
723.1665 +Type=0
723.1666 +HeaderFile=AccelEditor.h
723.1667 +ImplementationFile=AccelEditor.cpp
723.1668 +BaseClass=CDialog
723.1669 +Filter=D
723.1670 +LastObject=IDC_REMOVE
723.1671 +VirtualFilter=dWC
723.1672 +
723.1673 +[CLS:Hyperlink]
723.1674 +Type=0
723.1675 +HeaderFile=Hyperlink.h
723.1676 +ImplementationFile=Hyperlink.cpp
723.1677 +BaseClass=CStatic
723.1678 +Filter=W
723.1679 +VirtualFilter=WC
723.1680 +LastObject=Hyperlink
723.1681 +
723.1682 +[DLG:IDD_MAX_SCALE]
723.1683 +Type=1
723.1684 +Class=MaxScale
723.1685 +ControlCount=5
723.1686 +Control1=IDC_VALUE,edit,1350631552
723.1687 +Control2=ID_OK,button,1342242817
723.1688 +Control3=ID_CANCEL,button,1342242816
723.1689 +Control4=IDC_STATIC,static,1342308352
723.1690 +Control5=IDC_STATIC,static,1342308352
723.1691 +
723.1692 +[CLS:MaxScale]
723.1693 +Type=0
723.1694 +HeaderFile=MaxScale.h
723.1695 +ImplementationFile=MaxScale.cpp
723.1696 +BaseClass=CDialog
723.1697 +Filter=D
723.1698 +VirtualFilter=dWC
723.1699 +LastObject=MaxScale
723.1700 +
723.1701 +[DLG:IDD_BUG_REPORT]
723.1702 +Type=1
723.1703 +Class=BugReport
723.1704 +ControlCount=4
723.1705 +Control1=ID_OK,button,1342242816
723.1706 +Control2=IDC_BUG_REPORT,edit,1352730820
723.1707 +Control3=IDC_STATIC,static,1342308352
723.1708 +Control4=IDC_COPY,button,1342242817
723.1709 +
723.1710 +[CLS:BugReport]
723.1711 +Type=0
723.1712 +HeaderFile=BugReport.h
723.1713 +ImplementationFile=BugReport.cpp
723.1714 +BaseClass=CDialog
723.1715 +Filter=D
723.1716 +VirtualFilter=dWC
723.1717 +LastObject=BugReport
723.1718 +
   724.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   724.2 +++ b/src/win32/VBA.cpp	Sat Mar 03 10:31:27 2012 -0600
   724.3 @@ -0,0 +1,2272 @@
   724.4 +// VBA.cpp : Defines the class behaviors for the application.
   724.5 +//
   724.6 +#include "stdafx.h"
   724.7 +#include <mmsystem.h>
   724.8 +#include <cassert>
   724.9 +
  724.10 +#include "resource.h"
  724.11 +#include "VBA.h"
  724.12 +#include "AVIWrite.h"
  724.13 +#include "Input.h"
  724.14 +#include "IUpdate.h"
  724.15 +#include "LangSelect.h"
  724.16 +#include "MainWnd.h"
  724.17 +#include "Reg.h"
  724.18 +#include "WavWriter.h"
  724.19 +#include "WinResUtil.h"
  724.20 +#include "WinMiscUtil.h"
  724.21 +#include "ramwatch.h"
  724.22 +
  724.23 +#include "../gba/GBA.h"
  724.24 +#include "../gba/GBAGlobals.h"
  724.25 +#include "../gba/agbprint.h"
  724.26 +#include "../gb/GB.h"
  724.27 +#include "../gb/gbGlobals.h"
  724.28 +#include "../gb/gbPrinter.h"
  724.29 +#include "../common/CheatSearch.h"
  724.30 +#include "../gba/RTC.h"
  724.31 +#include "../gba/GBASound.h"
  724.32 +#include "../common/Util.h"
  724.33 +#include "../common/Text.h"
  724.34 +#include "../common/movie.h"
  724.35 +#include "../common/nesvideos-piece.h"
  724.36 +#include "../common/vbalua.h"
  724.37 +#include "../filters/filters.h"
  724.38 +#include "../version.h"
  724.39 +
  724.40 +extern IDisplay *newGDIDisplay();
  724.41 +extern IDisplay *newDirectDrawDisplay();
  724.42 +extern IDisplay *newDirect3DDisplay();
  724.43 +extern IDisplay *newOpenGLDisplay();
  724.44 +
  724.45 +extern Input *newDirectInput();
  724.46 +
  724.47 +extern void remoteStubSignal(int, int);
  724.48 +extern void remoteOutput(char *, u32);
  724.49 +extern void remoteStubMain();
  724.50 +extern void remoteSetProtocol(int);
  724.51 +extern void remoteCleanUp();
  724.52 +extern int remoteSocket;
  724.53 +
  724.54 +void winlog(const char *msg, ...);
  724.55 +
  724.56 +bool debugger = false;
  724.57 +
  724.58 +char movieFileToPlay[1024];
  724.59 +bool playMovieFile		   = false;
  724.60 +bool playMovieFileReadOnly = false;
  724.61 +char wavFileToOutput [1024];
  724.62 +bool outputWavFile	= false;
  724.63 +bool outputAVIFile	= false;
  724.64 +bool flagHideMenu	= false;
  724.65 +int	 quitAfterTime	= -1;
  724.66 +int	 pauseAfterTime = -1;
  724.67 +
  724.68 +void winSignal(int, int);
  724.69 +void winOutput(char *, u32);
  724.70 +
  724.71 +void (*dbgSignal)(int, int)	   = winSignal;
  724.72 +void (*dbgOutput)(char *, u32) = winOutput;
  724.73 +
  724.74 +#ifdef MMX
  724.75 +extern "C" bool cpu_mmx;
  724.76 +#endif
  724.77 +
  724.78 +// nowhere good to put them to
  724.79 +
  724.80 +void DrawTextMessages(u8 *dest, int pitch, int left, int bottom)
  724.81 +{
  724.82 +	for (int slot = 0; slot < SCREEN_MESSAGE_SLOTS; slot++)
  724.83 +	{
  724.84 +		if (theApp.screenMessage[slot])
  724.85 +		{
  724.86 +			if ((theApp.screenMessageDuration[slot] < 0 ||
  724.87 +			     (int)(GetTickCount() - theApp.screenMessageTime[slot]) < theApp.screenMessageDuration[slot]) &&
  724.88 +			    (!theApp.disableStatusMessage || slot == 1 || slot == 2))
  724.89 +			{
  724.90 +				drawText(dest,
  724.91 +				         pitch,
  724.92 +				         left,
  724.93 +				         bottom - 10 * (slot + 1),
  724.94 +				         theApp.screenMessageBuffer[slot],
  724.95 +				         theApp.screenMessageColorBuffer[slot]);
  724.96 +			}
  724.97 +			else
  724.98 +			{
  724.99 +				theApp.screenMessage[slot] = false;
 724.100 +			}
 724.101 +		}
 724.102 +	}
 724.103 +}
 724.104 +
 724.105 +// draw Lua graphics in game screen
 724.106 +void DrawLuaGui()
 724.107 +{
 724.108 +	int copyX		= 240, copyY       = 160;
 724.109 +	int screenX		= 240, screenY     = 160;
 724.110 +	int copyOffsetX = 0,   copyOffsetY = 0;
 724.111 +	if (systemCartridgeType == 1)
 724.112 +	{
 724.113 +		if (gbBorderOn)
 724.114 +		{
 724.115 +			copyX		= 256, copyY       = 224;
 724.116 +			screenX		= 256, screenY     = 224;
 724.117 +		}
 724.118 +		else
 724.119 +		{
 724.120 +			copyX = 160, copyY = 144;
 724.121 +			screenX = 160, screenY = 144;
 724.122 +		}
 724.123 +	}
 724.124 +	int pitch = copyX * (systemColorDepth / 8) + (systemColorDepth == 24 ? 0 : 4);
 724.125 +
 724.126 +	++copyOffsetY; // don't know why it's needed
 724.127 +
 724.128 +	VBALuaGui(&pix[copyOffsetY * pitch + copyOffsetX * (systemColorDepth / 8)], copyX, screenX, screenY);
 724.129 +	VBALuaClearGui();
 724.130 +}
 724.131 +
 724.132 +void directXMessage(const char *msg)
 724.133 +{
 724.134 +	systemMessage(
 724.135 +	    IDS_DIRECTX_7_REQUIRED,
 724.136 +	    "DirectX 7.0 or greater is required to run.\nDownload at http://www.microsoft.com/directx.\n\nError found at: %s",
 724.137 +	    msg);
 724.138 +}
 724.139 +
 724.140 +void winlog(const char *msg, ...)
 724.141 +{
 724.142 +	CString buffer;
 724.143 +	va_list valist;
 724.144 +
 724.145 +	va_start(valist, msg);
 724.146 +	buffer.FormatV(msg, valist);
 724.147 +
 724.148 +	FILE *winout = fopen("vba-trace.log", "w");
 724.149 +
 724.150 +	fputs(buffer, winout);
 724.151 +
 724.152 +	fclose(winout);
 724.153 +
 724.154 +	va_end(valist);
 724.155 +}
 724.156 +
 724.157 +// code from SDL_main.c for Windows
 724.158 +/* Parse a command line buffer into arguments */
 724.159 +
 724.160 +static int parseCommandLine(char *cmdline, char * *argv)
 724.161 +{
 724.162 +	char *bufp;
 724.163 +	int	  argc;
 724.164 +
 724.165 +	argc = 0;
 724.166 +	for (bufp = cmdline; *bufp; )
 724.167 +	{
 724.168 +		/* Skip leading whitespace */
 724.169 +		while (isspace(*bufp))
 724.170 +		{
 724.171 +			++bufp;
 724.172 +		}
 724.173 +		/* Skip over argument */
 724.174 +		if (*bufp == '"')
 724.175 +		{
 724.176 +			++bufp;
 724.177 +			if (*bufp)
 724.178 +			{
 724.179 +				if (argv)
 724.180 +				{
 724.181 +					argv[argc] = bufp;
 724.182 +				}
 724.183 +				++argc;
 724.184 +			}
 724.185 +			/* Skip over word */
 724.186 +			while (*bufp && (*bufp != '"'))
 724.187 +			{
 724.188 +				++bufp;
 724.189 +			}
 724.190 +		}
 724.191 +		else
 724.192 +		{
 724.193 +			if (*bufp)
 724.194 +			{
 724.195 +				if (argv)
 724.196 +				{
 724.197 +					argv[argc] = bufp;
 724.198 +				}
 724.199 +				++argc;
 724.200 +			}
 724.201 +			/* Skip over word */
 724.202 +			while (*bufp && !isspace(*bufp))
 724.203 +			{
 724.204 +				++bufp;
 724.205 +			}
 724.206 +		}
 724.207 +		if (*bufp)
 724.208 +		{
 724.209 +			if (argv)
 724.210 +			{
 724.211 +				*bufp = '\0';
 724.212 +			}
 724.213 +			++bufp;
 724.214 +		}
 724.215 +	}
 724.216 +	if (argv)
 724.217 +	{
 724.218 +		argv[argc] = NULL;
 724.219 +	}
 724.220 +	return(argc);
 724.221 +}
 724.222 +
 724.223 +static void debugSystemScreenMessage1(const char *msg)
 724.224 +{
 724.225 +	systemScreenMessage(msg, 3);
 724.226 +}
 724.227 +
 724.228 +static void debugSystemScreenMessage2(const char *msg)
 724.229 +{
 724.230 +	systemScreenMessage(msg, 4);
 724.231 +}
 724.232 +
 724.233 +static void winSignal(int, int)
 724.234 +{}
 724.235 +
 724.236 +#define CPUReadByteQuick(addr) \
 724.237 +    map[(addr) >> 24].address[(addr) & map[(addr) >> 24].mask]
 724.238 +
 724.239 +static void winOutput(char *s, u32 addr)
 724.240 +{
 724.241 +	if (s)
 724.242 +	{
 724.243 +		log(s);
 724.244 +	}
 724.245 +	else
 724.246 +	{
 724.247 +		CString str;
 724.248 +		char	c;
 724.249 +
 724.250 +		c = CPUReadByteQuick(addr);
 724.251 +		addr++;
 724.252 +		while (c)
 724.253 +		{
 724.254 +			str += c;
 724.255 +			c	 = CPUReadByteQuick(addr);
 724.256 +			addr++;
 724.257 +		}
 724.258 +		log(str);
 724.259 +	}
 724.260 +}
 724.261 +
 724.262 +typedef BOOL (WINAPI * GETMENUBARINFO)(HWND, LONG, LONG, PMENUBARINFO);
 724.263 +
 724.264 +static int winGetMenuBarHeight()
 724.265 +{
 724.266 +	HINSTANCE hinstDll = /**/ ::LoadLibrary("USER32.DLL");
 724.267 +
 724.268 +	if (hinstDll)
 724.269 +	{
 724.270 +		GETMENUBARINFO func = (GETMENUBARINFO)GetProcAddress(hinstDll, "GetMenuBarInfo");
 724.271 +
 724.272 +		if (func)
 724.273 +		{
 724.274 +			MENUBARINFO info;
 724.275 +			info.cbSize = sizeof(info);
 724.276 +
 724.277 +			func(AfxGetMainWnd()->GetSafeHwnd(), OBJID_MENU, 0, &info);
 724.278 +
 724.279 +			/**/ ::FreeLibrary(hinstDll);
 724.280 +
 724.281 +			return info.rcBar.bottom - info.rcBar.top + 1;
 724.282 +		}
 724.283 +	}
 724.284 +
 724.285 +	return GetSystemMetrics(SM_CYMENU);
 724.286 +}
 724.287 +
 724.288 +/////////////////////////////////////////////////////////////////////////////
 724.289 +// VBA
 724.290 +
 724.291 +BEGIN_MESSAGE_MAP(VBA, CWinApp)
 724.292 +//{{AFX_MSG_MAP(VBA)
 724.293 +// NOTE - the ClassWizard will add and remove mapping macros here.
 724.294 +//    DO NOT EDIT what you see in these blocks of generated code!
 724.295 +//}}AFX_MSG_MAP
 724.296 +END_MESSAGE_MAP()
 724.297 +
 724.298 +/////////////////////////////////////////////////////////////////////////////
 724.299 +// The one and only VBA object
 724.300 +
 724.301 +VBA theApp;
 724.302 +
 724.303 +/////////////////////////////////////////////////////////////////////////////
 724.304 +// VBA construction
 724.305 +
 724.306 +VBA::VBA() : emulator(::theEmulator)
 724.307 +{
 724.308 +	// important
 724.309 +	{
 724.310 +#ifdef MULTITHREAD_STDLOCALE_WORKAROUND
 724.311 +		// Note: there's a known threading bug regarding std::locale with MSVC according to
 724.312 +		// http://connect.microsoft.com/VisualStudio/feedback/details/492128/std-locale-constructor-modifies-global-locale-via-setlocale
 724.313 +		int iPreviousFlag = ::_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
 724.314 +#endif
 724.315 +		using std::locale;
 724.316 +		locale::global(locale(locale::classic(), "", locale::collate | locale::ctype));
 724.317 +
 724.318 +#ifdef MULTITHREAD_STDLOCALE_WORKAROUND
 724.319 +		if (iPreviousFlag > 0 )
 724.320 +			::_configthreadlocale(iPreviousFlag);
 724.321 +#endif
 724.322 +	}
 724.323 +
 724.324 +	mode320Available	 = false;
 724.325 +	mode640Available	 = false;
 724.326 +	mode800Available	 = false;
 724.327 +	windowPositionX		 = 0;
 724.328 +	windowPositionY		 = 0;
 724.329 +	filterFunction		 = NULL;
 724.330 +	ifbFunction			 = NULL;
 724.331 +	ifbType				 = 0;
 724.332 +	filterType			 = 0;
 724.333 +	filterWidth			 = 0;
 724.334 +	filterHeight		 = 0;
 724.335 +	fsWidth				 = 0;
 724.336 +	fsHeight			 = 0;
 724.337 +	fsColorDepth		 = 0;
 724.338 +	fsForceChange		 = false;
 724.339 +	surfaceSizeX		 = 0;
 724.340 +	surfaceSizeY		 = 0;
 724.341 +	sizeX				 = 0;
 724.342 +	sizeY				 = 0;
 724.343 +	videoOption			 = 0;
 724.344 +	fullScreenStretch	 = false;
 724.345 +	disableStatusMessage = false;
 724.346 +	showSpeed			 = 1;
 724.347 +	showSpeedTransparent = true;
 724.348 +	showRenderedFrames	 = 0;
 724.349 +	for (int j = 0; j < SCREEN_MESSAGE_SLOTS; j++)
 724.350 +	{
 724.351 +		screenMessage[j]		 = false;
 724.352 +		screenMessageTime[j]	 = 0;
 724.353 +		screenMessageDuration[j] = 0;
 724.354 +	}
 724.355 +	menuToggle		 = true;
 724.356 +	display			 = NULL;
 724.357 +	menu			 = NULL;
 724.358 +	popup			 = NULL;
 724.359 +	soundInitialized = false;
 724.360 +	useBiosFile		 = false;
 724.361 +	skipBiosFile	 = false;
 724.362 +	active			 = true;
 724.363 +	paused			 = false;
 724.364 +	recentFreeze	 = false;
 724.365 +	autoSaveLoadCheatList	  = false;
 724.366 +	pauseDuringCheatSearch	  = false;
 724.367 +	modelessCheatDialogIsOpen = false;
 724.368 +//	winout						= NULL;
 724.369 +//	removeIntros				= false;
 724.370 +	autoIPS = true;
 724.371 +	winGbBorderOn	  = 0;
 724.372 +	hideMovieBorder	  = false;
 724.373 +	winFlashSize	  = 0x10000;
 724.374 +	winRtcEnable	  = false;
 724.375 +	winSaveType		  = 0;
 724.376 +	rewindMemory	  = NULL;
 724.377 +	frameSearchMemory = NULL;
 724.378 +	rewindPos		  = 0;
 724.379 +	rewindTopPos	  = 0;
 724.380 +	rewindCounter	  = 0;
 724.381 +	rewindCount		  = 0;
 724.382 +	rewindSaveNeeded  = false;
 724.383 +	rewindTimer		  = 0;
 724.384 +	captureFormat	  = 0;
 724.385 +	tripleBuffering	  = true;
 724.386 +	autoHideMenu	  = false;
 724.387 +	throttle		  = 100;
 724.388 +	throttleLastTime  = 0;
 724.389 +///  autoFrameSkipLastTime		= 0;
 724.390 +///  autoFrameSkip				= false;
 724.391 +	vsync = false;
 724.392 +	changingVideoSize = false;
 724.393 +	pVideoDriverGUID  = NULL;
 724.394 +	renderMethod	  = DIRECT_DRAW;
 724.395 +	iconic = false;
 724.396 +	ddrawEmulationOnly		= false;
 724.397 +	ddrawUsingEmulationOnly = false;
 724.398 +	ddrawDebug				= false;
 724.399 +	ddrawUseVideoMemory		= false;
 724.400 +	d3dFilter				= 0;
 724.401 +	glFilter				= 0;
 724.402 +	glType					= 0;
 724.403 +	regEnabled				= false;
 724.404 +	pauseWhenInactive		= true;
 724.405 +	muteWhenInactive		= true;
 724.406 +	enableBackgroundInput	= false;
 724.407 +	alwaysOnTop				= false;
 724.408 +	filenamePreference		= true;
 724.409 +	frameCounter			= false;
 724.410 +	lagCounter				= false;
 724.411 +	extraCounter			= false;
 724.412 +	inputDisplay			= false;
 724.413 +	speedupToggle			= false;
 724.414 +	useOldSync				= false;
 724.415 +	allowLeftRight			= false;
 724.416 +	autofireAccountForLag	= false;
 724.417 +	nextframeAccountForLag	= false;
 724.418 +	muteFrameAdvance		= false;
 724.419 +	muteWhenInactive		= false;
 724.420 +	winMuteForNow		= false;
 724.421 +	winGbPrinterEnabled		= false;
 724.422 +	threadPriority			= 2;
 724.423 +	disableMMX				= false;
 724.424 +	languageOption			= 0;
 724.425 +	languageModule			= NULL;
 724.426 +	languageName			= "";
 724.427 +	renderedFrames			= 0;
 724.428 +	input					= NULL;
 724.429 +	joypadDefault			= 0;
 724.430 +	autoFire				= 0;
 724.431 +	autoFire2				= 0;
 724.432 +	autoHold				= 0;
 724.433 +	autoFireToggle			= false;
 724.434 +	winPauseNextFrame		= false;
 724.435 +	soundRecording			= false;
 724.436 +	soundRecorder			= NULL;
 724.437 +	sound					= NULL;
 724.438 +	aviRecording			= false;
 724.439 +	aviRecorder				= NULL;
 724.440 +	painting				= false;
 724.441 +	mouseCounter			= 0;
 724.442 +	movieReadOnly			= true;
 724.443 +	movieOnEndPause			= false;
 724.444 +	movieOnEndBehavior		= 0;
 724.445 +	wasPaused				= false;
 724.446 +	fsMaxScale				= 0;
 724.447 +	romSize					= 0;
 724.448 +	autoLoadMostRecent		= false;
 724.449 +	loadMakesRecent			= false;
 724.450 +	loadMakesCurrent		= false;
 724.451 +	saveMakesCurrent		= false;
 724.452 +	currentSlot				= 0;
 724.453 +	showSlotTime			= false;
 724.454 +	frameSearchLoadValid	= false;
 724.455 +	frameSearching			= false;
 724.456 +	frameSearchSkipping		= false;
 724.457 +	nvVideoLog				= false;
 724.458 +	nvAudioLog				= false;
 724.459 +	LoggingEnabled			= 0;
 724.460 +///  FPS = 60;
 724.461 +
 724.462 +	updateCount = 0;
 724.463 +
 724.464 +	systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
 724.465 +
 724.466 +	ZeroMemory(&emulator, sizeof(emulator));
 724.467 +
 724.468 +	hAccel = NULL;
 724.469 +
 724.470 +	for (int i = 0; i < 24; )
 724.471 +	{
 724.472 +		systemGbPalette[i++] = (0x1f) | (0x1f << 5) | (0x1f << 10);
 724.473 +		systemGbPalette[i++] = (0x15) | (0x15 << 5) | (0x15 << 10);
 724.474 +		systemGbPalette[i++] = (0x0c) | (0x0c << 5) | (0x0c << 10);
 724.475 +		systemGbPalette[i++] = 0;
 724.476 +	}
 724.477 +
 724.478 +	VBAMovieInit();
 724.479 +
 724.480 +	TIMECAPS tc;
 724.481 +	if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) == TIMERR_NOERROR)
 724.482 +	{
 724.483 +		wmTimerRes = min(max(tc.wPeriodMin, 1), tc.wPeriodMax);
 724.484 +		timeBeginPeriod(wmTimerRes);
 724.485 +	}
 724.486 +	else
 724.487 +	{
 724.488 +		wmTimerRes = 5;
 724.489 +		timeBeginPeriod(wmTimerRes);
 724.490 +	}
 724.491 +}
 724.492 +
 724.493 +VBA::~VBA()
 724.494 +{
 724.495 +	if (VBAMovieActive())
 724.496 +		VBAMovieStop(true);
 724.497 +
 724.498 +	saveSettings();
 724.499 +
 724.500 +	InterframeCleanup();
 724.501 +
 724.502 +	if (aviRecorder)
 724.503 +	{
 724.504 +		delete aviRecorder;
 724.505 +		aviRecorder	 = NULL;
 724.506 +		aviRecording = false;
 724.507 +	}
 724.508 +
 724.509 +	if (soundRecorder)
 724.510 +	{
 724.511 +		delete soundRecorder;
 724.512 +		soundRecorder = NULL;
 724.513 +	}
 724.514 +	soundRecording = false;
 724.515 +	soundPause();
 724.516 +	soundShutdown();
 724.517 +
 724.518 +	((MainWnd *)(m_pMainWnd))->winFileClose();
 724.519 +
 724.520 +	if (input)
 724.521 +		delete input;
 724.522 +
 724.523 +	shutdownDisplay();
 724.524 +
 724.525 +	if (rewindMemory)
 724.526 +		free(rewindMemory);
 724.527 +
 724.528 +	if (frameSearchMemory)
 724.529 +		free(frameSearchMemory);
 724.530 +
 724.531 +	timeEndPeriod(wmTimerRes);
 724.532 +}
 724.533 +
 724.534 +/////////////////////////////////////////////////////////////////////////////
 724.535 +// VBA initialization
 724.536 +
 724.537 +#include <afxdisp.h>
 724.538 +
 724.539 +BOOL VBA::InitInstance()
 724.540 +{
 724.541 +	AfxEnableControlContainer();
 724.542 +	// Standard initialization
 724.543 +	// If you are not using these features and wish to reduce the size
 724.544 +	//  of your final executable, you should remove from the following
 724.545 +	//  the specific initialization routines you do not need.
 724.546 +
 724.547 +//#ifdef _AFXDLL
 724.548 +//  Enable3dControls();      // Call this when using MFC in a shared DLL
 724.549 +//#else
 724.550 +//  Enable3dControlsStatic();  // Call this when linking to MFC statically
 724.551 +//#endif
 724.552 +
 724.553 +	SetRegistryKey(_T("VBA"));
 724.554 +
 724.555 +	remoteSetProtocol(0);
 724.556 +
 724.557 +	systemVerbose = GetPrivateProfileInt("config", "verbose", 0, "VBA.ini");
 724.558 +	systemDebug = GetPrivateProfileInt("config", "debug", 0, "VBA.ini");
 724.559 +	ddrawDebug = GetPrivateProfileInt("config", "ddrawDebug", 0, "VBA.ini") ? true : false;
 724.560 +
 724.561 +	wndClass = AfxRegisterWndClass(0, LoadCursor(IDC_ARROW), (HBRUSH)GetStockObject(BLACK_BRUSH), LoadIcon(IDI_ICON));
 724.562 +
 724.563 +	char winBuffer[2048];
 724.564 +	GetModuleFileName(NULL, winBuffer, 2048);
 724.565 +	char *p = strrchr(winBuffer, '\\');
 724.566 +	if (p)
 724.567 +		*p = 0;
 724.568 +	exeDir = winBuffer;
 724.569 +
 724.570 +	regInit(winBuffer);
 724.571 +
 724.572 +	loadSettings();
 724.573 +	theApp.LuaFastForward = -1;
 724.574 +	if (!initInput())
 724.575 +		return FALSE;
 724.576 +
 724.577 +	if (!initDisplay())
 724.578 +	{
 724.579 +		if (videoOption >= VIDEO_320x240)
 724.580 +		{
 724.581 +			regSetDwordValue("video", VIDEO_1X);
 724.582 +			if (pVideoDriverGUID)
 724.583 +				regSetDwordValue("defaultVideoDriver", TRUE);
 724.584 +		}
 724.585 +		return FALSE;
 724.586 +	}
 724.587 +
 724.588 +	hAccel = LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR));
 724.589 +
 724.590 +	winAccelMgr.Connect((MainWnd *)m_pMainWnd);
 724.591 +
 724.592 +	extern void winAccelAddCommandsFromMenu(CAcceleratorManager & mgr, CMenu * pMenu, const CString &parentStr);
 724.593 +	extern void winAccelAddCommandsFromTable(CAcceleratorManager & mgr);
 724.594 +
 724.595 +	winAccelAddCommandsFromMenu(winAccelMgr, &m_menu, CString());
 724.596 +	winAccelAddCommandsFromTable(winAccelMgr);
 724.597 +
 724.598 +	winAccelMgr.CreateDefaultTable();
 724.599 +	winAccelMgr.Load();
 724.600 +	winAccelMgr.UpdateWndTable();
 724.601 +	winAccelMgr.UpdateMenu(menu);
 724.602 +
 724.603 +	if (m_lpCmdLine[0])
 724.604 +	{
 724.605 +		int		argc = parseCommandLine(m_lpCmdLine, NULL);
 724.606 +		char * *argv = (char * *)malloc((argc + 1) * sizeof(char *));
 724.607 +		parseCommandLine(m_lpCmdLine, argv);
 724.608 +
 724.609 +		bool gotFlag = false, enoughArgs = false;
 724.610 +		for (int i = 0; i < argc; i++)
 724.611 +		{
 724.612 +			if (argv[i][0] == '-' || gotFlag)
 724.613 +			{
 724.614 +				if (!gotFlag)
 724.615 +					loadSettings();
 724.616 +				gotFlag = true;
 724.617 +				if (_stricmp(argv[i], "-rom") == 0)
 724.618 +				{
 724.619 +					if (i + 1 >= argc || argv[i + 1][0] == '-')
 724.620 +						goto invalidArgument;
 724.621 +					romFilename = argv[++i];
 724.622 +					winCorrectPath(romFilename);
 724.623 +					gameFilename = romFilename;
 724.624 +				}
 724.625 +				else if (_stricmp(argv[i], "-bios") == 0)
 724.626 +				{
 724.627 +					if (i + 1 >= argc || argv[i + 1][0] == '-')
 724.628 +						goto invalidArgument;
 724.629 +					biosFileName = argv[++i];
 724.630 +					winCorrectPath(biosFileName);
 724.631 +
 724.632 +					//systemLoadBIOS();
 724.633 +				}
 724.634 +				else if (_stricmp(argv[i], "-frameskip") == 0)
 724.635 +				{
 724.636 +					if (i + 1 >= argc || argv[i + 1][0] == '-')
 724.637 +						goto invalidArgument;
 724.638 +					frameSkip = atoi(argv[++i]);
 724.639 +					if (frameSkip < 0)
 724.640 +						frameSkip = 0;
 724.641 +					if (frameSkip > 9)
 724.642 +						frameSkip = 9;
 724.643 +					gbFrameSkip = frameSkip;
 724.644 +				}
 724.645 +				else if (_stricmp(argv[i], "-throttle") == 0)
 724.646 +				{
 724.647 +					if (i + 1 >= argc || argv[i + 1][0] == '-')
 724.648 +						goto invalidArgument;
 724.649 +					throttle = atoi(argv[++i]);
 724.650 +					if (throttle < 5)
 724.651 +						throttle = 5;
 724.652 +					if (throttle > 1000)
 724.653 +						throttle = 1000;
 724.654 +				}
 724.655 +				else if (_stricmp(argv[i], "-throttleKeepPitch") == 0)
 724.656 +				{
 724.657 +					if (i + 1 >= argc || argv[i + 1][0] == '-')
 724.658 +						goto invalidArgument;
 724.659 +					accuratePitchThrottle = atoi(argv[++i]) != 0;
 724.660 +				}
 724.661 +				else if (_stricmp(argv[i], "-synchronize") == 0)
 724.662 +				{
 724.663 +					if (i + 1 >= argc || argv[i + 1][0] == '-')
 724.664 +						goto invalidArgument;
 724.665 +					synchronize = atoi(argv[++i]) != 0;
 724.666 +				}
 724.667 +				else if (_stricmp(argv[i], "-hideborder") == 0)
 724.668 +				{
 724.669 +					if (i + 1 >= argc || argv[i + 1][0] == '-')
 724.670 +						goto invalidArgument;
 724.671 +					hideMovieBorder = atoi(argv[++i]) != 0;
 724.672 +				}
 724.673 +				else if (_stricmp(argv[i], "-play") == 0)
 724.674 +				{
 724.675 +					playMovieFile = true;
 724.676 +					if (i + 1 >= argc || argv[i + 1][0] == '-')
 724.677 +						goto invalidArgument;
 724.678 +					strcpy(movieFileToPlay, argv[++i]);
 724.679 +					winCorrectPath(movieFileToPlay);
 724.680 +					if (i + 1 >= argc || argv[i + 1][0] == '-') { --i; goto invalidArgument; }
 724.681 +					playMovieFileReadOnly = atoi(argv[++i]) != 0;
 724.682 +				}
 724.683 +				else if (_stricmp(argv[i], "-videoLog") == 0)
 724.684 +				{
 724.685 +					nvVideoLog	   = true;
 724.686 +					nvAudioLog	   = true;
 724.687 +					LoggingEnabled = 2;
 724.688 +					if (i + 1 >= argc || argv[i + 1][0] == '-') {}
 724.689 +					else
 724.690 +						NESVideoSetVideoCmd(argv[++i]);
 724.691 +				}
 724.692 +				else if (_stricmp(argv[i], "-logDebug") == 0)
 724.693 +				{
 724.694 +					NESVideoEnableDebugging(debugSystemScreenMessage1, debugSystemScreenMessage2);
 724.695 +				}
 724.696 +				else if (_stricmp(argv[i], "-logToFile") == 0)
 724.697 +				{
 724.698 +					NESVideoSetFileFuncs(fopen, fclose);
 724.699 +				}
 724.700 +				else if (_stricmp(argv[i], "-outputWAV") == 0)
 724.701 +				{
 724.702 +					outputWavFile = true;
 724.703 +					if (i + 1 >= argc || argv[i + 1][0] == '-')
 724.704 +						goto invalidArgument;
 724.705 +					strcpy(wavFileToOutput, argv[++i]);
 724.706 +				}
 724.707 +				else if (_stricmp(argv[i], "-outputAVI") == 0)
 724.708 +				{
 724.709 +					outputAVIFile = true;
 724.710 +				}
 724.711 +				else if (_stricmp(argv[i], "-quitAfter") == 0)
 724.712 +				{
 724.713 +					if (i + 1 >= argc || argv[i + 1][0] == '-')
 724.714 +						goto invalidArgument;
 724.715 +					quitAfterTime = atoi(argv[++i]);
 724.716 +				}
 724.717 +				else if (_stricmp(argv[i], "-pauseAt") == 0)
 724.718 +				{
 724.719 +					if (i + 1 >= argc || argv[i + 1][0] == '-')
 724.720 +						goto invalidArgument;
 724.721 +					pauseAfterTime = atoi(argv[++i]);
 724.722 +				}
 724.723 +				else if (_stricmp(argv[i], "-videoScale") == 0)
 724.724 +				{
 724.725 +					if (i + 1 >= argc || argv[i + 1][0] == '-')
 724.726 +						goto invalidArgument;
 724.727 +					int size = atoi(argv[++i]);
 724.728 +					if (size < 1)
 724.729 +						size = 1;
 724.730 +					if (size > 4)
 724.731 +						size = 4;
 724.732 +					switch (size)
 724.733 +					{
 724.734 +					case 1:
 724.735 +						videoOption = VIDEO_1X; break;
 724.736 +					case 2:
 724.737 +						videoOption = VIDEO_2X; break;
 724.738 +					case 3:
 724.739 +						videoOption = VIDEO_3X; break;
 724.740 +					case 4:
 724.741 +						videoOption = VIDEO_4X; break;
 724.742 +					}
 724.743 +				}
 724.744 +				else if (_stricmp(argv[i], "-hideMenu") == 0)
 724.745 +				{
 724.746 +					flagHideMenu = true;
 724.747 +				}
 724.748 +				else
 724.749 +				{
 724.750 +					enoughArgs = true;
 724.751 +invalidArgument:
 724.752 +					char str [2048];    // the string is larger than 1024 bytes
 724.753 +					strcpy(str, "");
 724.754 +					if (_stricmp(argv[i], "-h") != 0)
 724.755 +						if (enoughArgs)
 724.756 +							sprintf(str, "Invalid commandline argument %d: %s\n", i, argv[i]);
 724.757 +						else
 724.758 +							sprintf(str, "Not enough arguments for arg %d: %s\n", i, argv[i]);
 724.759 +					strcat(str, "Valid commands:\n"
 724.760 +					            "-h \t\t\t displays this help\n"
 724.761 +					            "-rom filename \t\t opens the given ROM\n"
 724.762 +					            "-bios filename \t\t use the given GBA BIOS\n"
 724.763 +					            "-play filename val \t\t plays the given VBM movie (val: 1 = read-only, 0 = editable)\n"
 724.764 +					            "-outputWAV filename \t outputs WAV audio to the given file\n"
 724.765 +					            "-outputAVI \t\t outputs an AVI (you are prompted for location and codec)\n"
 724.766 +					            "-frameskip val \t\t sets the frameskip amount to the given value\n"
 724.767 +					            "-synchronize val \t\t limits running speed to sound playing speed, (0 = off, 1 = on)\n"
 724.768 +					            "-throttle val \t\t sets the throttle speed to the given percentage\n"
 724.769 +					            "-hideborder val \t\t hides SGB border, if any (0 = show, 1 = hide)\n"
 724.770 +					            "-throttleKeepPitch val \t if throttle and synch, don't change sound freq (0 = off, 1 = on)\n"
 724.771 +					            "-quitAfter val \t\t close program when frame counter == val\n"
 724.772 +					            "-pauseAt val \t\t pause (movie) once when frame counter == val\n"
 724.773 +					            "-videoScale val \t\t sets the video size (val = 1 for 1X, 2 for 2X, 3 for 3X, or 4 for 4X)\n"
 724.774 +					            "-hideMenu \t\t hides the menu until program exit\n"
 724.775 +					            "\n"
 724.776 +					            "-videoLog args \t does (nesvideos) video+audio logging with the given arguments\n"
 724.777 +					            "-logToFile \t tells logging to use fopen/fclose of args, if logging is enabled\n"
 724.778 +					            "-logDebug  \t tells logging to output debug info to screen, if logging is enabled\n"
 724.779 +					       );
 724.780 +					theApp.winCheckFullscreen();
 724.781 +					AfxGetApp()->m_pMainWnd->MessageBox(str, "Commandline Help", MB_OK | MB_ICONINFORMATION);
 724.782 +					exit(0);
 724.783 +				}
 724.784 +			}
 724.785 +			else
 724.786 +			{
 724.787 +				// assume anything else is a ROM, for backward compatibility
 724.788 +				romFilename	 = argv[i++];
 724.789 +				gameFilename = romFilename;
 724.790 +				loadSettings();
 724.791 +			}
 724.792 +		}
 724.793 +
 724.794 +/*
 724.795 +        int index = filename.ReverseFind('.');
 724.796 +
 724.797 +        if (index != -1)
 724.798 +            filename = filename.Left(index);
 724.799 + */
 724.800 +		if (romFilename.GetLength() > 0)
 724.801 +		{
 724.802 +			((MainWnd *)theApp.m_pMainWnd)->winFileRun();
 724.803 +		}
 724.804 +		free(argv);
 724.805 +	}
 724.806 +
 724.807 +	return TRUE;
 724.808 +}
 724.809 +
 724.810 +void VBA::adjustDestRect()
 724.811 +{
 724.812 +	POINT point;
 724.813 +
 724.814 +	point.x = 0;
 724.815 +	point.y = 0;
 724.816 +
 724.817 +	m_pMainWnd->ClientToScreen(&point);
 724.818 +	dest.top  = point.y;
 724.819 +	dest.left = point.x;
 724.820 +
 724.821 +	point.x = surfaceSizeX;
 724.822 +	point.y = surfaceSizeY;
 724.823 +
 724.824 +	m_pMainWnd->ClientToScreen(&point);
 724.825 +	dest.bottom = point.y;
 724.826 +	dest.right	= point.x;
 724.827 +
 724.828 +	if (videoOption > VIDEO_4X)
 724.829 +	{
 724.830 +		int menuSkip = 0;
 724.831 +		if (menuToggle)
 724.832 +		{
 724.833 +			menuSkip = winGetMenuBarHeight();
 724.834 +		}
 724.835 +
 724.836 +		if (fullScreenStretch)
 724.837 +		{
 724.838 +			dest.top	= menuSkip;
 724.839 +			dest.left	= 0;
 724.840 +			dest.right	= fsWidth;
 724.841 +			dest.bottom = fsHeight;
 724.842 +		}
 724.843 +		else
 724.844 +		{
 724.845 +			int top	 = (fsHeight - surfaceSizeY) / 2;
 724.846 +			int left = (fsWidth - surfaceSizeX) / 2;
 724.847 +			dest.top	+= top - menuSkip * 2;
 724.848 +			dest.bottom += top;
 724.849 +			dest.left	+= left;
 724.850 +			dest.right	+= left;
 724.851 +		}
 724.852 +	}
 724.853 +}
 724.854 +
 724.855 +void VBA::updateIFB()
 724.856 +{
 724.857 +	if (systemColorDepth == 16)
 724.858 +	{
 724.859 +		switch (ifbType)
 724.860 +		{
 724.861 +		case 0:
 724.862 +		default:
 724.863 +			ifbFunction = NULL;
 724.864 +			break;
 724.865 +		case 1:
 724.866 +			ifbFunction = MotionBlurIB;
 724.867 +			break;
 724.868 +		case 2:
 724.869 +			ifbFunction = SmartIB;
 724.870 +			break;
 724.871 +		}
 724.872 +	}
 724.873 +	else if (systemColorDepth == 32)
 724.874 +	{
 724.875 +		switch (ifbType)
 724.876 +		{
 724.877 +		case 0:
 724.878 +		default:
 724.879 +			ifbFunction = NULL;
 724.880 +			break;
 724.881 +		case 1:
 724.882 +			ifbFunction = MotionBlurIB32;
 724.883 +			break;
 724.884 +		case 2:
 724.885 +			ifbFunction = SmartIB32;
 724.886 +			break;
 724.887 +		}
 724.888 +	}
 724.889 +	else
 724.890 +		ifbFunction = NULL;
 724.891 +}
 724.892 +
 724.893 +void VBA::updateFilter()
 724.894 +{
 724.895 +	filterWidth	 = sizeX;
 724.896 +	filterHeight = sizeY;
 724.897 +
 724.898 +	if (systemColorDepth == 16 && (videoOption > VIDEO_1X &&
 724.899 +	                               videoOption != VIDEO_320x240))
 724.900 +	{
 724.901 +		switch (filterType)
 724.902 +		{
 724.903 +		default:
 724.904 +		case 0:
 724.905 +			filterFunction = NULL;
 724.906 +			break;
 724.907 +		case 1:
 724.908 +			filterFunction = ScanlinesTV;
 724.909 +			break;
 724.910 +		case 2:
 724.911 +			filterFunction = _2xSaI;
 724.912 +			break;
 724.913 +		case 3:
 724.914 +			filterFunction = Super2xSaI;
 724.915 +			break;
 724.916 +		case 4:
 724.917 +			filterFunction = SuperEagle;
 724.918 +			break;
 724.919 +		case 5:
 724.920 +			filterFunction = Pixelate2x16;
 724.921 +			break;
 724.922 +		case 6:
 724.923 +			filterFunction = MotionBlur;
 724.924 +			break;
 724.925 +		case 7:
 724.926 +			filterFunction = AdMame2x;
 724.927 +			break;
 724.928 +		case 8:
 724.929 +			filterFunction = Simple2x16;
 724.930 +			break;
 724.931 +		case 9:
 724.932 +			filterFunction = Bilinear;
 724.933 +			break;
 724.934 +		case 10:
 724.935 +			filterFunction = BilinearPlus;
 724.936 +			break;
 724.937 +		case 11:
 724.938 +			filterFunction = Scanlines;
 724.939 +			break;
 724.940 +		case 12:
 724.941 +			filterFunction = hq2xS;
 724.942 +			break;
 724.943 +		case 13:
 724.944 +			filterFunction = hq2x;
 724.945 +			break;
 724.946 +		case 14:
 724.947 +			filterFunction = lq2x;
 724.948 +			break;
 724.949 +		case 15:
 724.950 +			filterFunction = hq3xS;
 724.951 +			break;
 724.952 +		case 16:
 724.953 +			filterFunction = hq3x;
 724.954 +			break;
 724.955 +		case 17:
 724.956 +			filterFunction = Simple3x16;
 724.957 +			break;
 724.958 +		case 18:
 724.959 +			filterFunction = Simple4x16;
 724.960 +			break;
 724.961 +		case 19:
 724.962 +			filterFunction = Pixelate3x16;
 724.963 +			break;
 724.964 +		case 20:
 724.965 +			filterFunction = Pixelate4x16;
 724.966 +			break;
 724.967 +		}
 724.968 +		switch (filterType)
 724.969 +		{
 724.970 +		case 0: // normal -> 1x texture
 724.971 +			rect.right	= sizeX;
 724.972 +			rect.bottom = sizeY;
 724.973 +			break;
 724.974 +		default: // other -> 2x texture
 724.975 +			rect.right	= sizeX * 2;
 724.976 +			rect.bottom = sizeY * 2;
 724.977 +			memset(delta, 255, sizeof(delta));
 724.978 +			break;
 724.979 +		case 15: // hq3x -> 3x texture
 724.980 +		case 16:
 724.981 +		case 17:
 724.982 +		case 19:
 724.983 +			rect.right	= sizeX * 3;
 724.984 +			rect.bottom = sizeY * 3;
 724.985 +			memset(delta, 255, sizeof(delta));
 724.986 +			break;
 724.987 +		case 18: // Simple4x -> 4x texture
 724.988 +		case 20:
 724.989 +			rect.right	= sizeX * 4;
 724.990 +			rect.bottom = sizeY * 4;
 724.991 +			memset(delta, 255, sizeof(delta));
 724.992 +			break;
 724.993 +		}
 724.994 +	}
 724.995 +	else
 724.996 +	{
 724.997 +		if (systemColorDepth == 32 && videoOption > VIDEO_1X &&
 724.998 +		    videoOption != VIDEO_320x240)
 724.999 +		{
724.1000 +			switch (filterType)
724.1001 +			{
724.1002 +			default:
724.1003 +			case 0:
724.1004 +				filterFunction = NULL;
724.1005 +				break;
724.1006 +			case 1:
724.1007 +				filterFunction = ScanlinesTV32;
724.1008 +				break;
724.1009 +			case 2:
724.1010 +				filterFunction = _2xSaI32;
724.1011 +				break;
724.1012 +			case 3:
724.1013 +				filterFunction = Super2xSaI32;
724.1014 +				break;
724.1015 +			case 4:
724.1016 +				filterFunction = SuperEagle32;
724.1017 +				break;
724.1018 +			case 5:
724.1019 +				filterFunction = Pixelate2x32;
724.1020 +				break;
724.1021 +			case 6:
724.1022 +				filterFunction = MotionBlur32;
724.1023 +				break;
724.1024 +			case 7:
724.1025 +				filterFunction = AdMame2x32;
724.1026 +				break;
724.1027 +			case 8:
724.1028 +				filterFunction = Simple2x32;
724.1029 +				break;
724.1030 +			case 9:
724.1031 +				filterFunction = Bilinear32;
724.1032 +				break;
724.1033 +			case 10:
724.1034 +				filterFunction = BilinearPlus32;
724.1035 +				break;
724.1036 +			case 11:
724.1037 +				filterFunction = Scanlines32;
724.1038 +				break;
724.1039 +			case 12:
724.1040 +				filterFunction = hq2xS32;
724.1041 +				break;
724.1042 +			case 13:
724.1043 +				filterFunction = hq2x32;
724.1044 +				break;
724.1045 +			case 14:
724.1046 +				filterFunction = lq2x32;
724.1047 +				break;
724.1048 +			case 15:
724.1049 +				filterFunction = hq3xS32;
724.1050 +				break;
724.1051 +			case 16:
724.1052 +				filterFunction = hq3x32;
724.1053 +				break;
724.1054 +			case 17:
724.1055 +				filterFunction = Simple3x32;
724.1056 +				break;
724.1057 +			case 18:
724.1058 +				filterFunction = Simple4x32;
724.1059 +				break;
724.1060 +			case 19:
724.1061 +				filterFunction = Pixelate3x32;
724.1062 +				break;
724.1063 +			case 20:
724.1064 +				filterFunction = Pixelate4x32;
724.1065 +				break;
724.1066 +			}
724.1067 +			switch (filterType)
724.1068 +			{
724.1069 +			case 0: // normal -> 1x texture
724.1070 +				rect.right	= sizeX;
724.1071 +				rect.bottom = sizeY;
724.1072 +				break;
724.1073 +			default: // other -> 2x texture
724.1074 +				rect.right	= sizeX * 2;
724.1075 +				rect.bottom = sizeY * 2;
724.1076 +				memset(delta, 255, sizeof(delta));
724.1077 +				break;
724.1078 +			case 15: // hq3x -> 3x texture
724.1079 +			case 16:
724.1080 +			case 17:
724.1081 +			case 19:
724.1082 +				rect.right	= sizeX * 3;
724.1083 +				rect.bottom = sizeY * 3;
724.1084 +				memset(delta, 255, sizeof(delta));
724.1085 +				break;
724.1086 +			case 18: // Simple4x -> 4x texture
724.1087 +			case 20:
724.1088 +				rect.right	= sizeX * 4;
724.1089 +				rect.bottom = sizeY * 4;
724.1090 +				memset(delta, 255, sizeof(delta));
724.1091 +				break;
724.1092 +			}
724.1093 +		}
724.1094 +		else
724.1095 +			filterFunction = NULL;
724.1096 +	}
724.1097 +
724.1098 +	if (display)
724.1099 +		display->changeRenderSize(rect.right, rect.bottom);
724.1100 +}
724.1101 +
724.1102 +void VBA::recreateMenuBar()
724.1103 +{
724.1104 +	m_menu.Detach();
724.1105 +	m_menu.Attach(winResLoadMenu(MAKEINTRESOURCE(IDR_MENU)));
724.1106 +
724.1107 +	if (m_pMainWnd && menuToggle)   // assuming that whether the menu has been set is always kept tracked
724.1108 +	{
724.1109 +		m_pMainWnd->SetMenu(&m_menu);
724.1110 +	}
724.1111 +
724.1112 +	if (menu != NULL)
724.1113 +	{
724.1114 +		DestroyMenu(menu);
724.1115 +	}
724.1116 +
724.1117 +	menu = m_menu.GetSafeHmenu();
724.1118 +}
724.1119 +
724.1120 +void VBA::updateMenuBar()
724.1121 +{
724.1122 +	if (flagHideMenu)
724.1123 +		return;
724.1124 +
724.1125 +	recreateMenuBar();
724.1126 +
724.1127 +	if (popup != NULL)
724.1128 +	{
724.1129 +		// force popup recreation if language changed
724.1130 +		DestroyMenu(popup);
724.1131 +		popup = NULL;
724.1132 +	}
724.1133 +}
724.1134 +
724.1135 +void VBA::saveRewindStateIfNecessary()
724.1136 +{
724.1137 +	if (rewindSaveNeeded && rewindMemory && emulator.emuWriteMemState)
724.1138 +	{
724.1139 +		rewindCount++;
724.1140 +		if (rewindCount > rewindSlots)
724.1141 +			rewindCount = rewindSlots;
724.1142 +		assert(rewindPos >= 0 && rewindPos < rewindSlots);
724.1143 +		if (emulator.emuWriteMemState(&rewindMemory[rewindPos * REWIND_SIZE], REWIND_SIZE))
724.1144 +		{
724.1145 +			rewindPos = ++rewindPos % rewindSlots;
724.1146 +			assert(rewindPos >= 0 && rewindPos < rewindSlots);
724.1147 +			if (rewindCount == rewindSlots)
724.1148 +				rewindTopPos = ++rewindTopPos % rewindSlots;
724.1149 +		}
724.1150 +	}
724.1151 +
724.1152 +	// also update/cache some frame search stuff
724.1153 +	if (frameSearching)
724.1154 +	{
724.1155 +		extern SMovie Movie;
724.1156 +		int curFrame = (Movie.state == MOVIE_STATE_NONE) ? systemCounters.frameCount : Movie.currentFrame;
724.1157 +		int endFrame = theApp.frameSearchStart + theApp.frameSearchLength;
724.1158 +		frameSearchSkipping	 = (curFrame < endFrame);
724.1159 +		frameSearchFirstStep = false;
724.1160 +
724.1161 +		if (curFrame == endFrame)
724.1162 +		{
724.1163 +			// cache intermediate state to speed up searching forward
724.1164 +			emulator.emuWriteMemState(&frameSearchMemory[REWIND_SIZE * 1], REWIND_SIZE);
724.1165 +		}
724.1166 +
724.1167 +		if (curFrame == endFrame + 1)
724.1168 +		{
724.1169 +			emulator.emuWriteMemState(&frameSearchMemory[REWIND_SIZE * 2], REWIND_SIZE);
724.1170 +			frameSearchLoadValid = true;
724.1171 +		}
724.1172 +	}
724.1173 +	else
724.1174 +	{
724.1175 +		frameSearchFirstStep = false;
724.1176 +
724.1177 +		assert(!frameSearchSkipping);
724.1178 +		// just in case
724.1179 +		frameSearchSkipping = false;
724.1180 +	}
724.1181 +}
724.1182 +
724.1183 +BOOL VBA::OnIdle(LONG lCount)
724.1184 +{
724.1185 +	if (emulating && debugger)
724.1186 +	{
724.1187 +		MSG msg;
724.1188 +		remoteStubMain();
724.1189 +		if (debugger)
724.1190 +			return TRUE;  // continue loop
724.1191 +		return !::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE);
724.1192 +	}
724.1193 +	else if (emulating && active && !paused)
724.1194 +	{
724.1195 +///    for(int i = 0; i < 2; i++)
724.1196 +		{
724.1197 +			emulator.emuMain(emulator.emuCount);
724.1198 +
724.1199 +			// save the state for rewinding, if necessary
724.1200 +			saveRewindStateIfNecessary();
724.1201 +
724.1202 +			rewindSaveNeeded = false;
724.1203 +		}
724.1204 +
724.1205 +		if (mouseCounter)
724.1206 +		{
724.1207 +			if (--mouseCounter == 0)
724.1208 +			{
724.1209 +				SetCursor(NULL);
724.1210 +			}
724.1211 +		}
724.1212 +		return TRUE;
724.1213 +	}
724.1214 +	else if (emulating) // this fixes display if resetting while paused
724.1215 +	{
724.1216 +//		VBAUpdateButtonPressDisplay();
724.1217 +		VBAUpdateFrameCountDisplay();
724.1218 +		systemRefreshScreen();
724.1219 +	}
724.1220 +
724.1221 +	return FALSE;
724.1222 +
724.1223 +	//  return CWinApp::OnIdle(lCount);
724.1224 +}
724.1225 +
724.1226 +void VBA::addRecentFile(const CString &file)
724.1227 +{
724.1228 +	// Do not change recent list if frozen
724.1229 +	if (recentFreeze)
724.1230 +		return;
724.1231 +	int i = 0;
724.1232 +	for (i = 0; i < 10; ++i)
724.1233 +	{
724.1234 +		if (recentFiles[i].GetLength() == 0)
724.1235 +			break;
724.1236 +
724.1237 +		if (recentFiles[i].Compare(file) == 0)
724.1238 +		{
724.1239 +			if (i == 0)
724.1240 +				return;
724.1241 +			CString p = recentFiles[i];
724.1242 +			for (int j = i; j > 0; --j)
724.1243 +			{
724.1244 +				recentFiles[j] = recentFiles[j - 1];
724.1245 +			}
724.1246 +			recentFiles[0] = p;
724.1247 +			return;
724.1248 +		}
724.1249 +	}
724.1250 +	int num = 0;
724.1251 +	for (i = 0; i < 10; ++i)
724.1252 +	{
724.1253 +		if (recentFiles[i].GetLength() != 0)
724.1254 +			++num;
724.1255 +	}
724.1256 +	if (num == 10)
724.1257 +	{
724.1258 +		--num;
724.1259 +	}
724.1260 +
724.1261 +	for (i = num; i >= 1; --i)
724.1262 +	{
724.1263 +		recentFiles[i] = recentFiles[i - 1];
724.1264 +	}
724.1265 +	recentFiles[0] = file;
724.1266 +}
724.1267 +
724.1268 +void VBA::updateFrameSkip()
724.1269 +{
724.1270 +	switch (systemCartridgeType)
724.1271 +	{
724.1272 +	case 0:
724.1273 +		systemFrameSkip = frameSkip;
724.1274 +		break;
724.1275 +	case 1:
724.1276 +		systemFrameSkip = gbFrameSkip;
724.1277 +		break;
724.1278 +	}
724.1279 +}
724.1280 +
724.1281 +void VBA::updateVideoSize(UINT id)
724.1282 +{
724.1283 +	int	 value		 = 0;
724.1284 +	bool forceUpdate = false;
724.1285 +
724.1286 +	switch (id)
724.1287 +	{
724.1288 +	case ID_OPTIONS_VIDEO_X1:
724.1289 +		value		= VIDEO_1X;
724.1290 +		forceUpdate = true;
724.1291 +		break;
724.1292 +	case ID_OPTIONS_VIDEO_X2:
724.1293 +		value		= VIDEO_2X;
724.1294 +		forceUpdate = true;
724.1295 +		break;
724.1296 +	case ID_OPTIONS_VIDEO_X3:
724.1297 +		value		= VIDEO_3X;
724.1298 +		forceUpdate = true;
724.1299 +		break;
724.1300 +	case ID_OPTIONS_VIDEO_X4:
724.1301 +		value		= VIDEO_4X;
724.1302 +		forceUpdate = true;
724.1303 +		break;
724.1304 +	case ID_OPTIONS_VIDEO_FULLSCREEN320X240:
724.1305 +		value		 = VIDEO_320x240;
724.1306 +		fsWidth		 = 320;
724.1307 +		fsHeight	 = 240;
724.1308 +		fsColorDepth = 16;
724.1309 +		break;
724.1310 +	case ID_OPTIONS_VIDEO_FULLSCREEN640X480:
724.1311 +		value		 = VIDEO_640x480;
724.1312 +		fsWidth		 = 640;
724.1313 +		fsHeight	 = 480;
724.1314 +		fsColorDepth = 16;
724.1315 +		break;
724.1316 +	case ID_OPTIONS_VIDEO_FULLSCREEN800X600:
724.1317 +		value		 = VIDEO_800x600;
724.1318 +		fsWidth		 = 800;
724.1319 +		fsHeight	 = 600;
724.1320 +		fsColorDepth = 16;
724.1321 +		break;
724.1322 +	case ID_OPTIONS_VIDEO_FULLSCREEN:
724.1323 +		value		= VIDEO_OTHER;
724.1324 +		forceUpdate = true;
724.1325 +		break;
724.1326 +	}
724.1327 +
724.1328 +	if (videoOption != value || forceUpdate)
724.1329 +		updateWindowSize(value);
724.1330 +}
724.1331 +
724.1332 +void VBA::updateWindowSize(int value)
724.1333 +{
724.1334 +	regSetDwordValue("video", value);
724.1335 +
724.1336 +	if (value == VIDEO_OTHER)
724.1337 +	{
724.1338 +		regSetDwordValue("fsWidth", fsWidth);
724.1339 +		regSetDwordValue("fsHeight", fsHeight);
724.1340 +		regSetDwordValue("fsColorDepth", fsColorDepth);
724.1341 +	}
724.1342 +
724.1343 +	if (display &&
724.1344 +	    (((value >= VIDEO_320x240 || videoOption >= VIDEO_320x240) && videoOption != value) ||
724.1345 +	     fsForceChange))
724.1346 +	{
724.1347 +		fsForceChange = false;
724.1348 +		videoOption	  = value;
724.1349 +		initDisplay();
724.1350 +	}
724.1351 +
724.1352 +	videoOption = value;
724.1353 +
724.1354 +	if (systemCartridgeType == 1)
724.1355 +	{
724.1356 +		if (gbBorderOn)
724.1357 +		{
724.1358 +			sizeX = 256;
724.1359 +			sizeY = 224;
724.1360 +			gbBorderLineSkip   = 256;
724.1361 +			gbBorderColumnSkip = 48;
724.1362 +			gbBorderRowSkip	   = 40;
724.1363 +		}
724.1364 +		else
724.1365 +		{
724.1366 +			sizeX = 160;
724.1367 +			sizeY = 144;
724.1368 +			gbBorderLineSkip   = 160;
724.1369 +			gbBorderColumnSkip = 0;
724.1370 +			gbBorderRowSkip	   = 0;
724.1371 +		}
724.1372 +	}
724.1373 +	else
724.1374 +	{
724.1375 +		sizeX = 240;
724.1376 +		sizeY = 160;
724.1377 +	}
724.1378 +
724.1379 +	switch (videoOption)
724.1380 +	{
724.1381 +	case VIDEO_1X:
724.1382 +		surfaceSizeX = sizeX;
724.1383 +		surfaceSizeY = sizeY;
724.1384 +		break;
724.1385 +	case VIDEO_2X:
724.1386 +		surfaceSizeX = sizeX * 2;
724.1387 +		surfaceSizeY = sizeY * 2;
724.1388 +		break;
724.1389 +	case VIDEO_3X:
724.1390 +		surfaceSizeX = sizeX * 3;
724.1391 +		surfaceSizeY = sizeY * 3;
724.1392 +		break;
724.1393 +	case VIDEO_4X:
724.1394 +		surfaceSizeX = sizeX * 4;
724.1395 +		surfaceSizeY = sizeY * 4;
724.1396 +		break;
724.1397 +	case VIDEO_320x240:
724.1398 +	case VIDEO_640x480:
724.1399 +	case VIDEO_800x600:
724.1400 +	case VIDEO_OTHER:
724.1401 +		// Need to fix this code later. For now, Fullscreen takes the whole screen.
724.1402 +		if (fullScreenStretch)
724.1403 +		{
724.1404 +			surfaceSizeX = fsWidth;
724.1405 +			surfaceSizeY = fsHeight;
724.1406 +		}
724.1407 +		else
724.1408 +		{
724.1409 +			double scaleX	= (double)fsWidth / (double)sizeX;
724.1410 +			double scaleY	= (double)fsHeight / (double)sizeY;
724.1411 +			double scaleMin = scaleX < scaleY ? scaleX : scaleY;
724.1412 +			if (fsMaxScale)
724.1413 +				scaleMin = scaleMin > fsMaxScale ? fsMaxScale : scaleMin;
724.1414 +			surfaceSizeX = (int)(scaleMin * sizeX);
724.1415 +			surfaceSizeY = (int)(scaleMin * sizeY);
724.1416 +		}
724.1417 +		break;
724.1418 +	}
724.1419 +
724.1420 +	rect.left	= 0;
724.1421 +	rect.top	= 0;
724.1422 +	rect.right	= sizeX;
724.1423 +	rect.bottom = sizeY;
724.1424 +
724.1425 +	int winSizeX = 0;
724.1426 +	int winSizeY = 0;
724.1427 +	int x		 = 0;
724.1428 +	int y		 = 0;
724.1429 +
724.1430 +	DWORD style	  = WS_POPUP | WS_VISIBLE;
724.1431 +	DWORD styleEx = alwaysOnTop ? WS_EX_TOPMOST : 0;
724.1432 +
724.1433 +	if (videoOption <= VIDEO_4X)
724.1434 +	{
724.1435 +		style |= WS_OVERLAPPEDWINDOW;
724.1436 +
724.1437 +		dest.left	= 0;
724.1438 +		dest.top	= 0;
724.1439 +		dest.right	= surfaceSizeX;
724.1440 +		dest.bottom = surfaceSizeY;
724.1441 +
724.1442 +		x = windowPositionX;
724.1443 +		y = windowPositionY;
724.1444 +	}
724.1445 +	else
724.1446 +	{
724.1447 +		dest.left	= 0;
724.1448 +		dest.top	= 0;
724.1449 +		dest.right	= fsWidth;
724.1450 +		dest.bottom = fsHeight;
724.1451 +	}
724.1452 +
724.1453 +	AdjustWindowRectEx(&dest, style, flagHideMenu ? FALSE : TRUE, styleEx);
724.1454 +	winSizeX = dest.right  - dest.left;
724.1455 +	winSizeY = dest.bottom - dest.top;
724.1456 +
724.1457 +	if (m_pMainWnd == NULL)
724.1458 +	{
724.1459 +		// Create a new window
724.1460 +		m_pMainWnd = new MainWnd;
724.1461 +		m_pMainWnd->CreateEx(styleEx,
724.1462 +		                     theApp.wndClass,
724.1463 +		                     VBA_NAME_AND_VERSION,
724.1464 +		                     style,
724.1465 +		                     x, y, winSizeX, winSizeY,
724.1466 +		                     NULL,
724.1467 +		                     0);
724.1468 +
724.1469 +		if (!(HWND)*m_pMainWnd)
724.1470 +		{
724.1471 +			winlog("Error creating Window %08x\n", GetLastError());
724.1472 +			AfxPostQuitMessage(0);
724.1473 +			return;
724.1474 +		}
724.1475 +	}
724.1476 +	else
724.1477 +	{
724.1478 +		m_pMainWnd->SetWindowPos(0, //HWND_TOPMOST,
724.1479 +		                         x,
724.1480 +		                         y,
724.1481 +		                         winSizeX,
724.1482 +		                         winSizeY,
724.1483 +		                         SWP_NOMOVE | SWP_SHOWWINDOW);
724.1484 +	}
724.1485 +
724.1486 +	updateMenuBar(); // add menubar first of all, or winGetMenuBarHeight() will get random height.
724.1487 +	winAccelMgr.UpdateMenu(menu);
724.1488 +	adjustDestRect();
724.1489 +
724.1490 +	updateIFB();
724.1491 +	updateFilter();
724.1492 +
724.1493 +	m_pMainWnd->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN);
724.1494 +}
724.1495 +
724.1496 +bool VBA::initDisplay()
724.1497 +{
724.1498 +	if (display)
724.1499 +	{
724.1500 +		changingVideoSize = true;
724.1501 +		shutdownDisplay();
724.1502 +		if (input)
724.1503 +		{
724.1504 +			delete input;
724.1505 +			input = NULL;
724.1506 +		}
724.1507 +		CWnd *pWnd = m_pMainWnd;
724.1508 +
724.1509 +		m_pMainWnd = NULL;
724.1510 +		pWnd->DragAcceptFiles(FALSE);
724.1511 +		pWnd->DestroyWindow();
724.1512 +		delete pWnd;
724.1513 +
724.1514 +		display = NULL;
724.1515 +	}
724.1516 +
724.1517 +	if (display == NULL)
724.1518 +	{
724.1519 +		updateWindowSize(videoOption);
724.1520 +
724.1521 +		switch (renderMethod)
724.1522 +		{
724.1523 +		case GDI:
724.1524 +			display = newGDIDisplay();
724.1525 +			break;
724.1526 +		case DIRECT_DRAW:
724.1527 +			display = newDirectDrawDisplay();
724.1528 +			break;
724.1529 +		case DIRECT_3D:
724.1530 +			display = newDirect3DDisplay();
724.1531 +			break;
724.1532 +		case OPENGL:
724.1533 +			display = newOpenGLDisplay();
724.1534 +			break;
724.1535 +		}
724.1536 +
724.1537 +		if (display->initialize())
724.1538 +		{
724.1539 +			if (input == NULL)
724.1540 +			{
724.1541 +				if (!initInput())
724.1542 +				{
724.1543 +					changingVideoSize = false;
724.1544 +					AfxPostQuitMessage(0);
724.1545 +					return false;
724.1546 +				}
724.1547 +			}
724.1548 +
724.1549 +			input->checkKeys();
724.1550 +
724.1551 +			changingVideoSize = false;
724.1552 +		}
724.1553 +		else
724.1554 +		{
724.1555 +			if (videoOption == VIDEO_320x240 ||
724.1556 +			    videoOption == VIDEO_640x480 ||
724.1557 +			    videoOption == VIDEO_800x600 ||
724.1558 +			    videoOption == VIDEO_OTHER)
724.1559 +			{
724.1560 +				regSetDwordValue("video", VIDEO_1X);
724.1561 +				if (pVideoDriverGUID)
724.1562 +					regSetDwordValue("defaultVideoDriver", TRUE);
724.1563 +			}
724.1564 +			changingVideoSize = false;
724.1565 +			return false;
724.1566 +		}
724.1567 +	}
724.1568 +	changingVideoSize = false;
724.1569 +	return true;
724.1570 +}
724.1571 +
724.1572 +bool VBA::updateRenderMethod(bool force)
724.1573 +{
724.1574 +	bool res = true;
724.1575 +	if (force || (display && display->getType() != renderMethod))
724.1576 +	{
724.1577 +		res = initDisplay();
724.1578 +
724.1579 +		while (!res && renderMethod > 0)
724.1580 +		{
724.1581 +			if (renderMethod == OPENGL)
724.1582 +				renderMethod = DIRECT_3D;
724.1583 +			else if (renderMethod == DIRECT_3D)
724.1584 +				renderMethod = DIRECT_DRAW;
724.1585 +			else if (renderMethod == DIRECT_DRAW)
724.1586 +				renderMethod = GDI;
724.1587 +
724.1588 +			res = initDisplay();
724.1589 +		}
724.1590 +	}
724.1591 +
724.1592 +	updateIFB();
724.1593 +	updateFilter();
724.1594 +
724.1595 +	m_pMainWnd->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN);
724.1596 +
724.1597 +	regSetDwordValue("renderMethod", renderMethod);
724.1598 +
724.1599 +	return res;
724.1600 +}
724.1601 +
724.1602 +void VBA::winCheckFullscreen()
724.1603 +{
724.1604 +	if (videoOption > VIDEO_4X && tripleBuffering)
724.1605 +	{
724.1606 +		if (display)
724.1607 +			display->checkFullScreen();
724.1608 +	}
724.1609 +}
724.1610 +
724.1611 +void VBA::shutdownDisplay()
724.1612 +{
724.1613 +	if (display != NULL)
724.1614 +	{
724.1615 +		display->cleanup();
724.1616 +		delete display;
724.1617 +		display = NULL;
724.1618 +	}
724.1619 +}
724.1620 +
724.1621 +void VBA::updatePriority()
724.1622 +{
724.1623 +	switch (threadPriority)
724.1624 +	{
724.1625 +	case 0:
724.1626 +		SetThreadPriority(THREAD_PRIORITY_HIGHEST);
724.1627 +		break;
724.1628 +	case 1:
724.1629 +		SetThreadPriority(THREAD_PRIORITY_ABOVE_NORMAL);
724.1630 +		break;
724.1631 +	case 3:
724.1632 +		SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL);
724.1633 +		break;
724.1634 +	default:
724.1635 +		SetThreadPriority(THREAD_PRIORITY_NORMAL);
724.1636 +	}
724.1637 +}
724.1638 +
724.1639 +#ifdef MMX
724.1640 +bool VBA::detectMMX()
724.1641 +{
724.1642 +	bool support = false;
724.1643 +	char brand[13];
724.1644 +
724.1645 +	// check for Intel chip
724.1646 +	__try {
724.1647 +		__asm {
724.1648 +			mov eax, 0;
724.1649 +			cpuid;
724.1650 +			mov [dword ptr brand + 0], ebx;
724.1651 +			mov [dword ptr brand + 4], edx;
724.1652 +			mov [dword ptr brand + 8], ecx;
724.1653 +		}
724.1654 +	}
724.1655 +	__except(EXCEPTION_EXECUTE_HANDLER) {
724.1656 +		if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
724.1657 +		{
724.1658 +			return false;
724.1659 +		}
724.1660 +		return false;
724.1661 +	}
724.1662 +	// Check for Intel or AMD CPUs
724.1663 +	if (strncmp(brand, "GenuineIntel", 12))
724.1664 +	{
724.1665 +		if (strncmp(brand, "AuthenticAMD", 12))
724.1666 +		{
724.1667 +			return false;
724.1668 +		}
724.1669 +	}
724.1670 +
724.1671 +	__asm {
724.1672 +		mov eax, 1;
724.1673 +		cpuid;
724.1674 +		test edx, 00800000h;
724.1675 +		jz	 NotFound;
724.1676 +		mov [support], 1;
724.1677 +NotFound:
724.1678 +	}
724.1679 +	return support;
724.1680 +}
724.1681 +
724.1682 +#endif
724.1683 +
724.1684 +void VBA::winSetLanguageOption(int option, bool force)
724.1685 +{
724.1686 +	if (((option == languageOption) && option != 2) && !force)
724.1687 +		return;
724.1688 +	switch (option)
724.1689 +	{
724.1690 +	case 0:
724.1691 +	{
724.1692 +		char lbuffer[10];
724.1693 +
724.1694 +		if (GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SABBREVLANGNAME,
724.1695 +		                  lbuffer, 10))
724.1696 +		{
724.1697 +			HINSTANCE l = winLoadLanguage(lbuffer);
724.1698 +			if (l == NULL)
724.1699 +			{
724.1700 +				LCID locIdBase = MAKELCID(MAKELANGID(PRIMARYLANGID(GetSystemDefaultLangID()), SUBLANG_NEUTRAL), SORT_DEFAULT);
724.1701 +				if (GetLocaleInfo(locIdBase, LOCALE_SABBREVLANGNAME,
724.1702 +				                  lbuffer, 10))
724.1703 +				{
724.1704 +					l = winLoadLanguage(lbuffer);
724.1705 +					if (l == NULL)
724.1706 +					{
724.1707 +						systemMessage(IDS_FAILED_TO_LOAD_LIBRARY,
724.1708 +						              "Failed to load library %s",
724.1709 +						              lbuffer);
724.1710 +						return;
724.1711 +					}
724.1712 +				}
724.1713 +			}
724.1714 +			AfxSetResourceHandle(l);
724.1715 +			if (languageModule != NULL)
724.1716 +				/**/ ::FreeLibrary(languageModule);
724.1717 +			languageModule = l;
724.1718 +		}
724.1719 +		else
724.1720 +		{
724.1721 +			systemMessage(IDS_FAILED_TO_GET_LOCINFO,
724.1722 +			              "Failed to get locale information");
724.1723 +			return;
724.1724 +		}
724.1725 +		break;
724.1726 +	}
724.1727 +	case 1:
724.1728 +		if (languageModule != NULL)
724.1729 +			/**/ ::FreeLibrary(languageModule);
724.1730 +		languageModule = NULL;
724.1731 +		AfxSetResourceHandle(AfxGetInstanceHandle());
724.1732 +		break;
724.1733 +	case 2:
724.1734 +	{
724.1735 +		if (!force)
724.1736 +		{
724.1737 +			LangSelect dlg;
724.1738 +			if (dlg.DoModal())
724.1739 +			{
724.1740 +				HINSTANCE l = winLoadLanguage(languageName);
724.1741 +				if (l == NULL)
724.1742 +				{
724.1743 +					systemMessage(IDS_FAILED_TO_LOAD_LIBRARY,
724.1744 +					              "Failed to load library %s",
724.1745 +					              languageName);
724.1746 +					return;
724.1747 +				}
724.1748 +				AfxSetResourceHandle(l);
724.1749 +				if (languageModule != NULL)
724.1750 +					/**/ ::FreeLibrary(languageModule);
724.1751 +				languageModule = l;
724.1752 +			}
724.1753 +		}
724.1754 +		else
724.1755 +		{
724.1756 +			if (languageName.IsEmpty())
724.1757 +				return;
724.1758 +			HINSTANCE l = winLoadLanguage(languageName);
724.1759 +			if (l == NULL)
724.1760 +			{
724.1761 +				systemMessage(IDS_FAILED_TO_LOAD_LIBRARY,
724.1762 +				              "Failed to load library %s",
724.1763 +				              languageName);
724.1764 +				return;
724.1765 +			}
724.1766 +			AfxSetResourceHandle(l);
724.1767 +			if (languageModule != NULL)
724.1768 +				FreeLibrary(languageModule);
724.1769 +			languageModule = l;
724.1770 +		}
724.1771 +		break;
724.1772 +	}
724.1773 +	}
724.1774 +	languageOption = option;
724.1775 +	updateMenuBar();
724.1776 +	theApp.winAccelMgr.UpdateMenu(theApp.menu);
724.1777 +}
724.1778 +
724.1779 +HINSTANCE VBA::winLoadLanguage(const char *name)
724.1780 +{
724.1781 +	CString buffer;
724.1782 +
724.1783 +	buffer.Format("vba_%s.dll", name);
724.1784 +
724.1785 +	HINSTANCE l = /**/ ::LoadLibrary(buffer);
724.1786 +
724.1787 +	if (l == NULL)
724.1788 +	{
724.1789 +		if (strlen(name) == 3)
724.1790 +		{
724.1791 +			char buffer2[3];
724.1792 +			buffer2[0] = name[0];
724.1793 +			buffer2[1] = name[1];
724.1794 +			buffer2[2] = 0;
724.1795 +			buffer.Format("vba_%s.dll", buffer2);
724.1796 +
724.1797 +			return /**/ ::LoadLibrary(buffer);
724.1798 +		}
724.1799 +	}
724.1800 +	return l;
724.1801 +}
724.1802 +
724.1803 +bool VBA::initInput()
724.1804 +{
724.1805 +	if (input)
724.1806 +		delete input;
724.1807 +	input = newDirectInput();
724.1808 +	if (input->initialize())
724.1809 +	{
724.1810 +		input->loadSettings();
724.1811 +		input->checkKeys();
724.1812 +		return true;
724.1813 +	}
724.1814 +	delete input;
724.1815 +	return false;
724.1816 +}
724.1817 +
724.1818 +void VBA::winAddUpdateListener(IUpdateListener *l)
724.1819 +{
724.1820 +	updateList.AddTail(l);
724.1821 +	updateCount++;
724.1822 +}
724.1823 +
724.1824 +void VBA::winRemoveUpdateListener(IUpdateListener *l)
724.1825 +{
724.1826 +	POSITION pos = updateList.Find(l);
724.1827 +	if (pos)
724.1828 +	{
724.1829 +		updateList.RemoveAt(pos);
724.1830 +		updateCount--;
724.1831 +		if (updateCount < 0)
724.1832 +			updateCount = 0;
724.1833 +	}
724.1834 +}
724.1835 +
724.1836 +void VBA::loadSettings()
724.1837 +{
724.1838 +	CString	buffer;
724.1839 +	// video
724.1840 +	bool defaultVideoDriver = regQueryDwordValue("defaultVideoDriver", true) ? true : false;
724.1841 +	if (!regQueryBinaryValue("videoDriverGUID", (char *)&videoDriverGUID, sizeof(GUID)))
724.1842 +	{
724.1843 +		defaultVideoDriver = TRUE;
724.1844 +	}
724.1845 +	if (defaultVideoDriver)
724.1846 +		pVideoDriverGUID = NULL;
724.1847 +	else
724.1848 +		pVideoDriverGUID = &videoDriverGUID;
724.1849 +
724.1850 +	videoOption = regQueryDwordValue("video", 0);
724.1851 +	if (videoOption < 0 || videoOption > VIDEO_OTHER)
724.1852 +		videoOption = 0;
724.1853 +	switch (videoOption)
724.1854 +	{
724.1855 +	case VIDEO_320x240:
724.1856 +		fsWidth		 = 320;
724.1857 +		fsHeight	 = 240;
724.1858 +		fsColorDepth = 16;
724.1859 +		break;
724.1860 +	case VIDEO_640x480:
724.1861 +		fsWidth		 = 640;
724.1862 +		fsHeight	 = 480;
724.1863 +		fsColorDepth = 16;
724.1864 +		break;
724.1865 +	case VIDEO_800x600:
724.1866 +		fsWidth		 = 800;
724.1867 +		fsHeight	 = 600;
724.1868 +		fsColorDepth = 16;
724.1869 +		break;
724.1870 +	}
724.1871 +	if (videoOption == VIDEO_OTHER)
724.1872 +	{
724.1873 +		if (fsWidth < 0 || fsWidth > 4095 || fsHeight < 0 || fsHeight > 4095)
724.1874 +			videoOption = 0;
724.1875 +		if (fsColorDepth != 16 && fsColorDepth != 24 && fsColorDepth != 32)
724.1876 +			videoOption = 0;
724.1877 +	}
724.1878 +
724.1879 +	fsWidth = regQueryDwordValue("fsWidth", 0);
724.1880 +	fsHeight = regQueryDwordValue("fsHeight", 0);
724.1881 +	fsColorDepth	  = regQueryDwordValue("fsColorDepth", 0);
724.1882 +	fsMaxScale		  = regQueryDwordValue("fsMaxScale", 0);
724.1883 +	fullScreenStretch = regQueryDwordValue("stretch", 0) ? true : false;
724.1884 +
724.1885 +	renderMethod = (DISPLAY_TYPE)regQueryDwordValue("renderMethod", DIRECT_DRAW);
724.1886 +	if (renderMethod < GDI || renderMethod > OPENGL)
724.1887 +		renderMethod = DIRECT_DRAW;
724.1888 +
724.1889 +	ddrawEmulationOnly	= regQueryDwordValue("ddrawEmulationOnly", false) ? true : false;
724.1890 +	ddrawUseVideoMemory = regQueryDwordValue("ddrawUseVideoMemory", false) ? true : false;
724.1891 +	tripleBuffering		= regQueryDwordValue("tripleBuffering", true) ? true : false;
724.1892 +	vsync = regQueryDwordValue("vsync", false) ? true : false;
724.1893 +
724.1894 +	d3dFilter = regQueryDwordValue("d3dFilter", 0);
724.1895 +	if (d3dFilter < 0 || d3dFilter > 1)
724.1896 +		d3dFilter = 0;
724.1897 +	glFilter = regQueryDwordValue("glFilter", 0);
724.1898 +	if (glFilter < 0 || glFilter > 1)
724.1899 +		glFilter = 0;
724.1900 +	glType = regQueryDwordValue("glType", 0);
724.1901 +	if (glType < 0 || glType > 1)
724.1902 +		glType = 0;
724.1903 +
724.1904 +	// pixel filter & ifb
724.1905 +	filterType = regQueryDwordValue("filter", 0);
724.1906 +	if (filterType < 0 || filterType > 20)
724.1907 +		filterType = 0;
724.1908 +	disableMMX = regQueryDwordValue("disableMMX", 0) ? true : false;
724.1909 +	ifbType	   = regQueryDwordValue("ifbType", 0);
724.1910 +	if (ifbType < 0 || ifbType > 2)
724.1911 +		ifbType = 0;
724.1912 +
724.1913 +	// frame skipping
724.1914 +	frameSkip = regQueryDwordValue("frameSkip", /*2*/ 0);
724.1915 +	if (frameSkip < 0 || frameSkip > 9)
724.1916 +		frameSkip = 1;
724.1917 +	gbFrameSkip = regQueryDwordValue("gbFrameSkip", 0);
724.1918 +	if (gbFrameSkip < 0 || gbFrameSkip > 9)
724.1919 +		gbFrameSkip = 0;
724.1920 +///  autoFrameSkip = regQueryDwordValue("autoFrameSkip", FALSE) ? TRUE : FALSE;
724.1921 +
724.1922 +	// input
724.1923 +	joypadDefault = regQueryDwordValue("joypadDefault", 0);
724.1924 +	if (joypadDefault < 0 || joypadDefault > 3)
724.1925 +		joypadDefault = 0;
724.1926 +	allowLeftRight		   = regQueryDwordValue("allowLeftRight", false) ? true : false;
724.1927 +	autofireAccountForLag  = regQueryDwordValue("autofireAccountForLag", false) ? true : false;
724.1928 +	nextframeAccountForLag = regQueryDwordValue("nextframeAccountForLag", false) ? true : false;
724.1929 +	theApp.AsscWithSaveState = regQueryDwordValue("AsscWithSaveState", false) ? true : false;
724.1930 +
724.1931 +	// speed
724.1932 +	throttle = regQueryDwordValue("throttle", 0);
724.1933 +	if (throttle < 5 || throttle > 1000)
724.1934 +		throttle = 100;
724.1935 +
724.1936 +	synchronize = regQueryDwordValue("synchronize", 1) ? true : false;
724.1937 +	accuratePitchThrottle = regQueryDwordValue("accuratePitchThrottle", FALSE) ? TRUE : FALSE;
724.1938 +
724.1939 +	// sound
724.1940 +	int resChannels = regQueryDwordValue("soundEnable", 0x30f);
724.1941 +	soundEnableChannels(resChannels);
724.1942 +	soundDisableChannels(~resChannels);
724.1943 +	soundOffFlag = (regQueryDwordValue("soundOff", 0)) ? true : false;
724.1944 +	soundQuality = regQueryDwordValue("soundQuality", 2);
724.1945 +	soundEcho	 = regQueryDwordValue("soundEcho", 0) ? true : false;
724.1946 +	soundLowPass = regQueryDwordValue("soundLowPass", 0) ? true : false;
724.1947 +	soundReverse = regQueryDwordValue("soundReverse", 0) ? true : false;
724.1948 +	soundVolume	 = regQueryDwordValue("soundVolume", 0);
724.1949 +	if (soundVolume < 0 || soundVolume > 5)
724.1950 +		soundVolume = 0;
724.1951 +	muteFrameAdvance = regQueryDwordValue("muteFrameAdvance", 0) ? TRUE : FALSE;
724.1952 +	muteWhenInactive = regQueryDwordValue("muteWhenInactive", 0) ? TRUE : FALSE;
724.1953 +
724.1954 +	// emulation
724.1955 +	memLagEnabled	  = regQueryDwordValue("memLagEnabled", false) ? true : false;
724.1956 +	memLagTempEnabled = memLagEnabled;
724.1957 +	gbNullInputHackEnabled	   = regQueryDwordValue("gbNullInputHackEnabled", false) ? true : false;
724.1958 +	gbNullInputHackTempEnabled = gbNullInputHackEnabled;
724.1959 +	useOldSync		  = regQueryDwordValue("useOldSync", 0) ? TRUE : FALSE;
724.1960 +	useOldFrameTiming = regQueryDwordValue("useOldGBTiming", false) ? true : false;
724.1961 +
724.1962 +	useBiosFile	 = regQueryDwordValue("useBios", 0) ? true : false;
724.1963 +	skipBiosFile = regQueryDwordValue("skipBios", 0) ? true : false;
724.1964 +	buffer		 = regQueryStringValue("biosFile", "");
724.1965 +	if (!buffer.IsEmpty())
724.1966 +	{
724.1967 +		biosFileName = buffer;
724.1968 +	}
724.1969 +//	removeIntros = regQueryDwordValue("removeIntros", false) ? true : false;
724.1970 +
724.1971 +	autoIPS = regQueryDwordValue("autoIPS", true) ? true : false;
724.1972 +
724.1973 +	agbPrintEnable(regQueryDwordValue("agbPrint", 0) ? true : false);
724.1974 +	winRtcEnable = regQueryDwordValue("rtcEnabled", 0) ? true : false;
724.1975 +	rtcEnable(winRtcEnable);
724.1976 +
724.1977 +	winSaveType = regQueryDwordValue("saveType", 0);
724.1978 +	if (winSaveType < 0 || winSaveType > 5)
724.1979 +		winSaveType = 0;
724.1980 +	cpuEnhancedDetection = regQueryDwordValue("enhancedDetection", 1) ? true : false;
724.1981 +	winFlashSize		 = regQueryDwordValue("flashSize", 0x10000);
724.1982 +	if (winFlashSize != 0x10000 && winFlashSize != 0x20000)
724.1983 +		winFlashSize = 0x10000;
724.1984 +
724.1985 +	cpuDisableSfx = regQueryDwordValue("disableSfx", 0) ? true : false;
724.1986 +
724.1987 +	// GBx
724.1988 +	winGbPrinterEnabled = regQueryDwordValue("gbPrinter", false) ? true : false;
724.1989 +	if (winGbPrinterEnabled)
724.1990 +		gbSerialFunction = gbPrinterSend;
724.1991 +	else
724.1992 +		gbSerialFunction = NULL;
724.1993 +	gbEmulatorType = regQueryDwordValue("emulatorType", 0);
724.1994 +	if (gbEmulatorType < 0 || gbEmulatorType > 5)
724.1995 +		gbEmulatorType = 1;
724.1996 +	winGbBorderOn	  = regQueryDwordValue("borderOn", 0);
724.1997 +	gbBorderAutomatic = regQueryDwordValue("borderAutomatic", 0);
724.1998 +
724.1999 +	gbColorOption	= regQueryDwordValue("colorOption", 0);
724.2000 +	gbPaletteOption = regQueryDwordValue("gbPaletteOption", 0);
724.2001 +	if (gbPaletteOption < 0)
724.2002 +		gbPaletteOption = 0;
724.2003 +	if (gbPaletteOption > 2)
724.2004 +		gbPaletteOption = 2;
724.2005 +	regQueryBinaryValue("gbPalette", (char *)systemGbPalette, 24 * sizeof(u16));
724.2006 +
724.2007 +	// head-up display
724.2008 +	showSpeed = regQueryDwordValue("showSpeed", 1);
724.2009 +	if (showSpeed < 0 || showSpeed > 2)
724.2010 +		showSpeed = 1;
724.2011 +	showSpeedTransparent = regQueryDwordValue("showSpeedTransparent", TRUE) ? TRUE : FALSE;
724.2012 +	outlinedText		 = regQueryDwordValue("outlinedText", TRUE) != 0;
724.2013 +	transparentText		 = regQueryDwordValue("transparentText", FALSE) != 0;
724.2014 +	textColor			 = regQueryDwordValue("textColor", 0);
724.2015 +	textMethod			 = regQueryDwordValue("textMethod", 1);
724.2016 +	frameCounter		 = regQueryDwordValue("frameCounter", false) ? true : false;
724.2017 +	lagCounter			 = regQueryDwordValue("lagCounter", false) ? true : false;
724.2018 +	extraCounter		 = regQueryDwordValue("extraCounter", false) ? true : false;
724.2019 +	inputDisplay		 = regQueryDwordValue("inputDisplay", false) ? true : false;
724.2020 +	disableStatusMessage = regQueryDwordValue("disableStatus", 0) ? true : false;
724.2021 +
724.2022 +	// UI
724.2023 +	windowPositionX = regQueryDwordValue("windowX", 0);
724.2024 +	if (windowPositionX < 0)
724.2025 +		windowPositionX = 0;
724.2026 +	windowPositionY = regQueryDwordValue("windowY", 0);
724.2027 +	if (windowPositionY < 0)
724.2028 +		windowPositionY = 0;
724.2029 +
724.2030 +	autoHideMenu = regQueryDwordValue("autoHideMenu", 0) ? true : false;
724.2031 +
724.2032 +	languageOption = regQueryDwordValue("language", 1);
724.2033 +	if (languageOption < 0 || languageOption > 2)
724.2034 +		languageOption = 1;
724.2035 +	buffer = regQueryStringValue("languageName", "");
724.2036 +	if (!buffer.IsEmpty())
724.2037 +	{
724.2038 +		languageName = buffer.Left(3);
724.2039 +	}
724.2040 +	else
724.2041 +		languageName = "";
724.2042 +	winSetLanguageOption(languageOption, true);
724.2043 +
724.2044 +	// preferences
724.2045 +	alwaysOnTop = regQueryDwordValue("alwaysOnTop", false) ? true : false;
724.2046 +	pauseWhenInactive	  = regQueryDwordValue("pauseWhenInactive", 1) ? true : false;
724.2047 +	enableBackgroundInput = regQueryDwordValue("enableBackgroundInput", 0) ? true : false;
724.2048 +	threadPriority		  = regQueryDwordValue("priority", 2);
724.2049 +	if (threadPriority < 0 || threadPriority > 3)
724.2050 +		threadPriority = 2;
724.2051 +	updatePriority();
724.2052 +
724.2053 +	filenamePreference = regQueryDwordValue("filenamePreference", 0);
724.2054 +	altAviRecordMethod = regQueryDwordValue("altAviRecordMethod", false) ? true : false;
724.2055 +	captureFormat	   = regQueryDwordValue("captureFormat", 0);
724.2056 +
724.2057 +	rewindTimer = regQueryDwordValue("rewindTimer", 0);
724.2058 +	rewindSlots = regQueryDwordValue("rewindSlots", 64);
724.2059 +	if (rewindTimer < 0 || rewindTimer > 600)
724.2060 +		rewindTimer = 0;
724.2061 +	if (rewindSlots <= 0)
724.2062 +		rewindTimer = rewindSlots = 0;
724.2063 +	if (rewindSlots > MAX_REWIND_SLOTS)
724.2064 +		rewindSlots = MAX_REWIND_SLOTS;
724.2065 +	if (rewindTimer != 0)
724.2066 +	{
724.2067 +		if (rewindMemory == NULL)
724.2068 +			rewindMemory = (char *)malloc(rewindSlots * REWIND_SIZE);
724.2069 +	}
724.2070 +
724.2071 +	if (frameSearchMemory == NULL)
724.2072 +		frameSearchMemory = (char *)malloc(3 * REWIND_SIZE);
724.2073 +
724.2074 +	recentFreeze = regQueryDwordValue("recentFreeze", false) ? true : false;
724.2075 +	for (int i = 0, j = 0; i < 10; ++i)
724.2076 +	{
724.2077 +		buffer.Format("recent%d", i);
724.2078 +		const char *s = regQueryStringValue(buffer, NULL);
724.2079 +		if (s == NULL)
724.2080 +			continue;
724.2081 +		recentFiles[j] = s;
724.2082 +		++j;
724.2083 +	}
724.2084 +
724.2085 +	autoLoadMostRecent = regQueryDwordValue("autoLoadMostRecent", false) ? true : false;
724.2086 +	loadMakesRecent	   = regQueryDwordValue("loadMakesRecent", false) ? true : false;
724.2087 +	loadMakesCurrent   = regQueryDwordValue("loadMakesCurrent", false) ? true : false;
724.2088 +	saveMakesCurrent   = regQueryDwordValue("saveMakesCurrent", false) ? true : false;
724.2089 +	currentSlot		   = regQueryDwordValue("currentSlot", 0);
724.2090 +	showSlotTime	   = regQueryDwordValue("showSlotTime", 0) ? true : false;
724.2091 +
724.2092 +	cheatsEnabled = regQueryDwordValue("cheatsEnabled", true) ? true : false;
724.2093 +	autoSaveLoadCheatList  = regQueryDwordValue("autoSaveCheatList", 0) ? true : false;
724.2094 +	pauseDuringCheatSearch = regQueryDwordValue("pauseDuringCheatSearch2", 0) ? true : false;
724.2095 +
724.2096 +	movieOnEndBehavior = regQueryDwordValue("movieOnEndBehavior", 0);
724.2097 +	movieOnEndPause	   = regQueryDwordValue("movieOnEndPause", 0) ? true : false;
724.2098 +
724.2099 +	extern bool autoConvertMovieWhenPlaying;    // from movie.cpp
724.2100 +	autoConvertMovieWhenPlaying = regQueryDwordValue("autoConvertMovieWhenPlaying", 0) ? true : false;
724.2101 +
724.2102 +	// RamWatch Settings
724.2103 +	AutoRWLoad		= regQueryDwordValue(AUTORWLOAD, false);
724.2104 +	RWSaveWindowPos = regQueryDwordValue(RWSAVEPOS, false);
724.2105 +	ramw_x = regQueryDwordValue(RAMWX, 0);
724.2106 +	ramw_y = regQueryDwordValue(RAMWY, 0);
724.2107 +
724.2108 +	// this is FILO
724.2109 +	for (int i = MAX_RECENT_WATCHES; i > 0; --i)
724.2110 +	{
724.2111 +		buffer.Format("recentWatch%d", i);
724.2112 +		const char *s = regQueryStringValue(buffer, NULL);
724.2113 +		if (s == NULL)
724.2114 +			continue;
724.2115 +		RWAddRecentFile(s);
724.2116 +	}
724.2117 +}
724.2118 +
724.2119 +void VBA::saveSettings()
724.2120 +{
724.2121 +	regSetDwordValue("defaultVideoDriver", pVideoDriverGUID == NULL);
724.2122 +	if (pVideoDriverGUID)
724.2123 +	{
724.2124 +		regSetBinaryValue("videoDriverGUID", (char *)&videoDriverGUID,
724.2125 +		                  sizeof(GUID));
724.2126 +	}
724.2127 +	regSetDwordValue("video", videoOption);
724.2128 +
724.2129 +	regSetDwordValue("fsWidth", fsWidth);
724.2130 +	regSetDwordValue("fsHeight", fsHeight);
724.2131 +	regSetDwordValue("fsColorDepth", fsColorDepth);
724.2132 +	regSetDwordValue("fsMaxScale", fsMaxScale);
724.2133 +
724.2134 +	regSetDwordValue("stretch", fullScreenStretch);
724.2135 +
724.2136 +	regSetDwordValue("renderMethod", renderMethod);
724.2137 +
724.2138 +	regSetDwordValue("ddrawEmulationOnly", ddrawEmulationOnly);
724.2139 +	regSetDwordValue("ddrawUseVideoMemory", ddrawUseVideoMemory);
724.2140 +	regSetDwordValue("tripleBuffering", tripleBuffering);
724.2141 +	regSetDwordValue("vsync", vsync);
724.2142 +
724.2143 +	regSetDwordValue("d3dFilter", d3dFilter);
724.2144 +	regSetDwordValue("glFilter", glFilter);
724.2145 +	regSetDwordValue("glType", glType);
724.2146 +
724.2147 +	// pixel filter & ifb
724.2148 +	regSetDwordValue("filter", filterType);
724.2149 +	regSetDwordValue("ifbType", ifbType);
724.2150 +	regSetDwordValue("disableMMX", disableMMX);
724.2151 +
724.2152 +	// frame skipping
724.2153 +	regSetDwordValue("frameSkip", frameSkip);
724.2154 +	regSetDwordValue("gbFrameSkip", gbFrameSkip);
724.2155 +///  regSetDwordValue("autoFrameSkip", autoFrameSkip);
724.2156 +
724.2157 +	// input
724.2158 +	regSetDwordValue("joypadDefault", joypadDefault);
724.2159 +	regSetDwordValue("allowLeftRight", allowLeftRight);
724.2160 +	regSetDwordValue("autofireAccountforLag", autofireAccountForLag);
724.2161 +	regSetDwordValue("nextframeAccountforLag", nextframeAccountForLag);
724.2162 +	regSetDwordValue("AsscWithSaveState", theApp.AsscWithSaveState);
724.2163 +
724.2164 +
724.2165 +	// speed
724.2166 +	regSetDwordValue("throttle", throttle);
724.2167 +	regSetDwordValue("synchronize", synchronize);
724.2168 +	regSetDwordValue("accuratePitchThrottle", accuratePitchThrottle);
724.2169 +
724.2170 +	// sound
724.2171 +	regSetDwordValue("soundEnable", soundGetEnabledChannels() & 0x030f);
724.2172 +	regSetDwordValue("soundOff", soundOffFlag);
724.2173 +	regSetDwordValue("soundQuality", soundQuality);
724.2174 +	regSetDwordValue("soundEcho", soundEcho);
724.2175 +	regSetDwordValue("soundLowPass", soundLowPass);
724.2176 +	regSetDwordValue("soundReverse", soundReverse);
724.2177 +	regSetDwordValue("soundVolume", soundVolume);
724.2178 +	regSetDwordValue("muteFrameAdvance", muteFrameAdvance);
724.2179 +	regSetDwordValue("muteWhenInactive", muteWhenInactive);
724.2180 +
724.2181 +	// emulation
724.2182 +	regSetDwordValue("useBios", useBiosFile);
724.2183 +	regSetDwordValue("skipBios", skipBiosFile);
724.2184 +	if (!biosFileName.IsEmpty())
724.2185 +		regSetStringValue("biosFile", biosFileName);
724.2186 +//	regSetDwordValue("removeIntros", removeIntros);
724.2187 +
724.2188 +	regSetDwordValue("autoIPS", autoIPS);
724.2189 +
724.2190 +	regSetDwordValue("memLagEnabled", memLagEnabled);
724.2191 +	regSetDwordValue("gbNullInputHackEnabled", gbNullInputHackEnabled);
724.2192 +	regSetDwordValue("useOldGBTiming", useOldFrameTiming);
724.2193 +	regSetDwordValue("useOldSync", useOldSync);
724.2194 +
724.2195 +	regSetDwordValue("agbPrint", agbPrintIsEnabled());
724.2196 +	regSetDwordValue("rtcEnabled", winRtcEnable);
724.2197 +
724.2198 +	regSetDwordValue("saveType", winSaveType);
724.2199 +	regSetDwordValue("enhancedDetection", cpuEnhancedDetection);
724.2200 +	regSetDwordValue("flashSize", winFlashSize);
724.2201 +
724.2202 +	regSetDwordValue("disableSfx", cpuDisableSfx);
724.2203 +
724.2204 +	// GBx
724.2205 +	regSetDwordValue("emulatorType", gbEmulatorType);
724.2206 +	regSetDwordValue("gbPrinter", winGbPrinterEnabled);
724.2207 +	regSetDwordValue("borderOn", winGbBorderOn);
724.2208 +	regSetDwordValue("borderAutomatic", gbBorderAutomatic);
724.2209 +
724.2210 +	regSetDwordValue("colorOption", gbColorOption);
724.2211 +	regSetDwordValue("gbPaletteOption", gbPaletteOption);
724.2212 +	regSetBinaryValue("gbPalette", (char *)systemGbPalette, 24 * sizeof(u16));
724.2213 +
724.2214 +	// head-up display
724.2215 +	regSetDwordValue("showSpeed", showSpeed);
724.2216 +	regSetDwordValue("showSpeedTransparent", showSpeedTransparent);
724.2217 +
724.2218 +	regSetDwordValue("outlinedText", outlinedText);
724.2219 +	regSetDwordValue("transparentText", transparentText);
724.2220 +	regSetDwordValue("textColor", textColor);
724.2221 +	regSetDwordValue("textMethod", textMethod);
724.2222 +	regSetDwordValue("frameCounter", frameCounter);
724.2223 +	regSetDwordValue("lagCounter", lagCounter);
724.2224 +	regSetDwordValue("extraCounter", extraCounter);
724.2225 +	regSetDwordValue("inputDisplay", inputDisplay);
724.2226 +	regSetDwordValue("disableStatus", disableStatusMessage);
724.2227 +
724.2228 +	// UI
724.2229 +	regSetDwordValue("windowX", windowPositionX);
724.2230 +	regSetDwordValue("windowY", windowPositionY);
724.2231 +
724.2232 +	regSetDwordValue("autoHideMenu", autoHideMenu);
724.2233 +
724.2234 +	regSetDwordValue("language", languageOption);
724.2235 +	regSetStringValue("languageName", languageName);
724.2236 +
724.2237 +	// preferences
724.2238 +	regSetDwordValue("alwaysOnTop", alwaysOnTop);
724.2239 +	regSetDwordValue("pauseWhenInactive", pauseWhenInactive);
724.2240 +	regSetDwordValue("enableBackgroundInput", enableBackgroundInput);
724.2241 +	regSetDwordValue("priority", threadPriority);
724.2242 +
724.2243 +	regSetDwordValue("filenamePreference", filenamePreference);
724.2244 +	regSetDwordValue("altAviRecordMethod", altAviRecordMethod);
724.2245 +	regSetDwordValue("captureFormat", captureFormat);
724.2246 +
724.2247 +	regSetDwordValue("cheatsEnabled", cheatsEnabled);
724.2248 +	regSetDwordValue("autoSaveCheatList", autoSaveLoadCheatList);
724.2249 +	regSetDwordValue("pauseDuringCheatSearch2", pauseDuringCheatSearch);
724.2250 +
724.2251 +	regSetDwordValue("rewindTimer", rewindTimer);
724.2252 +	regSetDwordValue("rewindSlots", rewindSlots);
724.2253 +
724.2254 +	regSetDwordValue("recentFreeze", recentFreeze);
724.2255 +	CString buffer;
724.2256 +	for (int i = 0; i < 10; i++)
724.2257 +	{
724.2258 +		buffer.Format("recent%d", i);
724.2259 +		regSetStringValue(buffer, recentFiles[i]);
724.2260 +	}
724.2261 +
724.2262 +	regSetDwordValue("autoLoadMostRecent", autoLoadMostRecent);
724.2263 +	regSetDwordValue("loadMakesRecent", loadMakesRecent);
724.2264 +	regSetDwordValue("loadMakesCurrent", loadMakesCurrent);
724.2265 +	regSetDwordValue("saveMakesCurrent", saveMakesCurrent);
724.2266 +	regSetDwordValue("currentSlot", currentSlot);
724.2267 +	regSetDwordValue("showSlotTime", showSlotTime);
724.2268 +
724.2269 +	regSetDwordValue("movieOnEndBehavior", movieOnEndBehavior);
724.2270 +	regSetDwordValue("movieOnEndPause", movieOnEndPause);
724.2271 +
724.2272 +	extern bool autoConvertMovieWhenPlaying;    // from movie.cpp
724.2273 +	regSetDwordValue("autoConvertMovieWhenPlaying", autoConvertMovieWhenPlaying);
724.2274 +}
724.2275 +
   725.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   725.2 +++ b/src/win32/VBA.h	Sat Mar 03 10:31:27 2012 -0600
   725.3 @@ -0,0 +1,274 @@
   725.4 +#if !defined(AFX_VBA_H__57514A10_49F9_4B83_A928_0D8A4A7306A3__INCLUDED_)
   725.5 +#define AFX_VBA_H__57514A10_49F9_4B83_A928_0D8A4A7306A3__INCLUDED_
   725.6 +
   725.7 +#if _MSC_VER > 1000
   725.8 +#pragma once
   725.9 +#endif // _MSC_VER > 1000
  725.10 +
  725.11 +/*
  725.12 +   #ifndef __AFXWIN_H__
  725.13 +   #error include 'stdafx.h' before including this file for PCH
  725.14 +   #endif
  725.15 + */
  725.16 +
  725.17 +#include <afxtempl.h>
  725.18 +
  725.19 +#include "AcceleratorManager.h"
  725.20 +#include "AVIWrite.h"
  725.21 +#include "Display.h"
  725.22 +#include "../common/System.h"
  725.23 +
  725.24 +/////////////////////////////////////////////////////////////////////////////
  725.25 +// VBA:
  725.26 +// See VBA.cpp for the implementation of this class
  725.27 +//
  725.28 +
  725.29 +enum
  725.30 +{
  725.31 +	VIDEO_1X, VIDEO_2X, VIDEO_3X, VIDEO_4X,
  725.32 +	VIDEO_320x240, VIDEO_640x480, VIDEO_800x600, VIDEO_OTHER
  725.33 +};
  725.34 +
  725.35 +#define REWIND_SIZE 400000
  725.36 +#define MAX_REWIND_SLOTS 256
  725.37 +#define SCREEN_MESSAGE_SLOTS 8
  725.38 +
  725.39 +/////////////////////////////////////////////////////////////////////////////
  725.40 +// forward decl
  725.41 +class IUpdateListener;
  725.42 +class Input;
  725.43 +class ISound;
  725.44 +class AVIWrite;
  725.45 +class WavWriter;
  725.46 +
  725.47 +class VBA : public CWinApp
  725.48 +{
  725.49 +public:
  725.50 +	CMenu	  m_menu;
  725.51 +	HMENU	  menu;
  725.52 +	HMENU	  popup;
  725.53 +	bool	  mode320Available;
  725.54 +	bool	  mode640Available;
  725.55 +	bool	  mode800Available;
  725.56 +	int		  windowPositionX;
  725.57 +	int		  windowPositionY;
  725.58 +	void	  (*filterFunction)(u8 *, u32, u8 *, u8 *, u32, int, int);
  725.59 +	void	  (*ifbFunction)(u8 *, u32, int, int);
  725.60 +	int		  ifbType;
  725.61 +	int		  filterType;
  725.62 +	int		  filterWidth;
  725.63 +	int		  filterHeight;
  725.64 +	int		  fsWidth;
  725.65 +	int		  fsHeight;
  725.66 +	int		  fsColorDepth;
  725.67 +	bool	  fsForceChange;
  725.68 +	bool	  AsscWithSaveState;
  725.69 +	int		  sizeX;
  725.70 +	int		  sizeY;
  725.71 +	int		  surfaceSizeX;
  725.72 +	int		  surfaceSizeY;
  725.73 +	int		  videoOption;
  725.74 +	bool	  fullScreenStretch;
  725.75 +	bool	  disableStatusMessage;
  725.76 +	int		  showSpeed;
  725.77 +	BOOL	  showSpeedTransparent;
  725.78 +	int		  showRenderedFrames;
  725.79 +	bool	  screenMessage [SCREEN_MESSAGE_SLOTS];
  725.80 +	CString	  screenMessageBuffer [SCREEN_MESSAGE_SLOTS];
  725.81 +	DWORD	  screenMessageTime [SCREEN_MESSAGE_SLOTS];
  725.82 +	int		  screenMessageDuration [SCREEN_MESSAGE_SLOTS];
  725.83 +	CString	  screenMessageColorBuffer [SCREEN_MESSAGE_SLOTS];
  725.84 +	u8 *	  delta[257 * 244 * 4];
  725.85 +	bool	  menuToggle;
  725.86 +	IDisplay *display;
  725.87 +	bool	  soundInitialized;
  725.88 +	bool	  useBiosFile;
  725.89 +	bool	  skipBiosFile;
  725.90 +	CString	  biosFileName;
  725.91 +	bool	  allowLeftRight;
  725.92 +	bool	  autofireAccountForLag;
  725.93 +	bool	  nextframeAccountForLag;
  725.94 +	bool	  active;
  725.95 +	bool	  iconic;
  725.96 +	bool	  paused;
  725.97 +	CString	  recentFiles[10];
  725.98 +	bool	  recentFreeze;
  725.99 +	bool	  autoSaveLoadCheatList;
 725.100 +	bool	  pauseDuringCheatSearch;
 725.101 +	bool	  modelessCheatDialogIsOpen;
 725.102 +//	FILE *    winout;
 725.103 +//	bool      removeIntros;
 725.104 +	bool  autoIPS;
 725.105 +	int	  winGbBorderOn;
 725.106 +	bool  hideMovieBorder;
 725.107 +	int	  winFlashSize;
 725.108 +	bool  winRtcEnable;
 725.109 +	int	  winSaveType;
 725.110 +	char *rewindMemory;
 725.111 +	int	  rewindPos;
 725.112 +	int	  rewindTopPos;
 725.113 +	int	  rewindCounter;
 725.114 +	int	  rewindCount;
 725.115 +	bool  rewindSaveNeeded;
 725.116 +	int	  rewindTimer;
 725.117 +	int	  rewindSlots;
 725.118 +	int	  captureFormat;
 725.119 +	bool  tripleBuffering;
 725.120 +	bool  autoHideMenu;
 725.121 +	bool  speedupToggle;
 725.122 +	int	  throttle;
 725.123 +	u32	  throttleLastTime;
 725.124 +///  u32 autoFrameSkipLastTime;
 725.125 +///  bool autoFrameSkip;
 725.126 +	bool		 accuratePitchThrottle;
 725.127 +	bool		 vsync;
 725.128 +	bool		 changingVideoSize;
 725.129 +	GUID		 videoDriverGUID;
 725.130 +	GUID *		 pVideoDriverGUID;
 725.131 +	DISPLAY_TYPE renderMethod;
 725.132 +	bool		 ddrawEmulationOnly;
 725.133 +	bool		 ddrawUsingEmulationOnly;
 725.134 +	bool		 ddrawDebug;
 725.135 +	bool		 ddrawUseVideoMemory;
 725.136 +	int			 d3dFilter;
 725.137 +	int			 glFilter;
 725.138 +	int			 glType;
 725.139 +	bool		 muteWhenInactive;
 725.140 +	bool		 muteFrameAdvance;
 725.141 +	bool		 pauseWhenInactive;
 725.142 +	bool		 enableBackgroundInput;
 725.143 +	bool		 alwaysOnTop;
 725.144 +	bool		 useOldSync;
 725.145 +	bool		 winGbPrinterEnabled;
 725.146 +	int			 threadPriority;
 725.147 +	bool		 disableMMX;
 725.148 +	int			 languageOption;
 725.149 +	CString		 languageName;
 725.150 +	HINSTANCE	 languageModule;
 725.151 +	int			 renderedFrames;
 725.152 +	Input *		 input;
 725.153 +	int			 joypadDefault;
 725.154 +	int			 autoFire, autoFire2;
 725.155 +	int			 autoHold;
 725.156 +	bool		 autoFireToggle;
 725.157 +	bool		 frameCounter;
 725.158 +	bool		 lagCounter;
 725.159 +	bool		 extraCounter;
 725.160 +	bool		 inputDisplay;
 725.161 +	bool		 movieReadOnly;
 725.162 +	bool		 movieOnEndPause;
 725.163 +	int			 movieOnEndBehavior;
 725.164 +	bool		 soundRecording;
 725.165 +	WavWriter *	 soundRecorder;
 725.166 +	CString		 soundRecordName;
 725.167 +	ISound *	 sound;
 725.168 +	bool		 aviRecording;
 725.169 +	AVIWrite *	 aviRecorder;
 725.170 +	CString		 aviRecordName;
 725.171 +	bool		 altAviRecordMethod;
 725.172 +	bool		 nvVideoLog;
 725.173 +	bool		 nvAudioLog;
 725.174 +	bool		 painting;  // for systemDrawScreen()
 725.175 +	int			 mouseCounter;
 725.176 +	bool		 winMuteForNow;
 725.177 +	bool		 winPauseNextFrame;
 725.178 +	bool		 wasPaused;
 725.179 +	int			 fsMaxScale;
 725.180 +	int			 romSize;
 725.181 +	bool		 autoLoadMostRecent;
 725.182 +	bool		 loadMakesRecent;
 725.183 +	bool		 loadMakesCurrent;
 725.184 +	bool		 saveMakesCurrent;
 725.185 +	int			 currentSlot;
 725.186 +	bool		 showSlotTime;
 725.187 +	int			 filenamePreference;
 725.188 +	int			 LuaFastForward;
 725.189 +	bool		 frameSearching;
 725.190 +	bool		 frameSearchSkipping;
 725.191 +	bool		 frameSearchFirstStep;
 725.192 +	bool		 frameSearchLoadValid;
 725.193 +	int			 frameSearchLength;
 725.194 +	int			 frameSearchStart;
 725.195 +	u32			 frameSearchOldInput[4];
 725.196 +	char *		 frameSearchMemory;
 725.197 +	DWORD		 wmTimerRes;
 725.198 +
 725.199 +	CList<IUpdateListener *, IUpdateListener * &> updateList;
 725.200 +	int updateCount;
 725.201 +
 725.202 +	CAcceleratorManager winAccelMgr;
 725.203 +	HACCEL hAccel;
 725.204 +
 725.205 +	RECT rect;
 725.206 +	RECT dest;
 725.207 +
 725.208 +	struct EmulatedSystem &emulator;
 725.209 +
 725.210 +	CString romFilename;
 725.211 +	CString gameFilename;
 725.212 +	CString exeName;
 725.213 +	CString exeDir;
 725.214 +	CString wndClass;
 725.215 +
 725.216 +public:
 725.217 +	VBA();
 725.218 +	~VBA();
 725.219 +
 725.220 +	void adjustDestRect();
 725.221 +	void recreateMenuBar();
 725.222 +	void updateIFB();
 725.223 +	void updateFilter();
 725.224 +	void updateMenuBar();
 725.225 +	void winAddUpdateListener(IUpdateListener *l);
 725.226 +	void winRemoveUpdateListener(IUpdateListener *l);
 725.227 +
 725.228 +	// Overrides
 725.229 +	// ClassWizard generated virtual function overrides
 725.230 +	//{{AFX_VIRTUAL(VBA)
 725.231 +public:
 725.232 +	virtual BOOL InitInstance();
 725.233 +	virtual BOOL OnIdle(LONG lCount);
 725.234 +	//}}AFX_VIRTUAL
 725.235 +
 725.236 +	// Implementation
 725.237 +public:
 725.238 +	HINSTANCE winLoadLanguage(const char *name);
 725.239 +	void winSetLanguageOption(int option, bool force);
 725.240 +#ifdef MMX
 725.241 +	bool detectMMX();
 725.242 +#endif
 725.243 +	void updatePriority();
 725.244 +	void shutdownDisplay();
 725.245 +	void winCheckFullscreen();
 725.246 +	bool updateRenderMethod(bool force);
 725.247 +	bool initDisplay();
 725.248 +	void updateWindowSize(int value);
 725.249 +	void updateVideoSize(UINT id);
 725.250 +	void updateFrameSkip();
 725.251 +	void loadSettings();
 725.252 +	void saveSettings();
 725.253 +	bool initInput();
 725.254 +	void addRecentFile(const CString &file);
 725.255 +	void saveRewindStateIfNecessary();
 725.256 +	//{{AFX_MSG(VBA)
 725.257 +	afx_msg void OnAppAbout();
 725.258 +	// NOTE - the ClassWizard will add and remove member functions here.
 725.259 +	//    DO NOT EDIT what you see in these blocks of generated code !
 725.260 +	//}}AFX_MSG
 725.261 +	DECLARE_MESSAGE_MAP()
 725.262 +};
 725.263 +
 725.264 +extern VBA theApp;
 725.265 +
 725.266 +#ifdef MMX
 725.267 +extern "C" bool cpu_mmx;
 725.268 +#endif
 725.269 +
 725.270 +extern void DrawTextMessages(u8 *dest, int pitch, int left, int bottom);
 725.271 +
 725.272 +/////////////////////////////////////////////////////////////////////////////
 725.273 +
 725.274 +//{{AFX_INSERT_LOCATION}}
 725.275 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
 725.276 +
 725.277 +#endif // !defined(AFX_VBA_H__57514A10_49F9_4B83_A928_0D8A4A7306A3__INCLUDED_)
   726.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   726.2 +++ b/src/win32/VersionInfo.h	Sat Mar 03 10:31:27 2012 -0600
   726.3 @@ -0,0 +1,33 @@
   726.4 +#ifndef VBA_VERSIONINFO_H
   726.5 +#define VBA_VERSIONINFO_H
   726.6 +
   726.7 +#if _MSC_VER > 1000
   726.8 +#pragma once
   726.9 +#endif // _MSC_VER > 1000
  726.10 +
  726.11 +#include "../version.h"
  726.12 +
  726.13 +#if SVN_REV > 65535
  726.14 +#	define VBA_RR_BUILD_NO 0
  726.15 +#else
  726.16 +#	define VBA_RR_BUILD_NO SVN_REV
  726.17 +#endif
  726.18 +
  726.19 +// diaplayed in the file attribute dialog
  726.20 +#define VBA_VERSIONINFO_FILEVER        7, VBA_RR_MAJOR_VERSION_NO, VBA_RR_MINOR_VERSION_NO, VBA_RR_BUILD_NO
  726.21 +#define VBA_VERSIONINFO_STRFILEVER     STRINGIZE_VALUE(VBA_VERSIONINFO_FILEVER) "\0"
  726.22 +
  726.23 +#define VBA_VERSIONINFO_PRODUCTVER     VBA_VERSIONINFO_FILEVER
  726.24 +#define VBA_VERSIONINFO_STRPRODUCTVER  VBA_VERSIONINFO_STRFILEVER
  726.25 +#define VBA_VERSIONINFO_STRCOPYRIGHT   "Copyright (C) 2005-2011 VBA-RR Development Team"
  726.26 +#define VBA_VERSIONINFO_ORGANIZATION   VBA_RR_SITE
  726.27 +
  726.28 +#ifdef _DEBUG
  726.29 +#	define VBA_VERSIONINFO_FILEFLAGS    VS_FF_DEBUG
  726.30 +#elif defined(PUBLIC_RELEASE)
  726.31 +#	define VBA_VERSIONINFO_FILEFLAGS    0
  726.32 +#else
  726.33 +#	define VBA_VERSIONINFO_FILEFLAGS    VS_FF_PRERELEASE
  726.34 +#endif
  726.35 +
  726.36 +#endif // VBA_VERSIONINFO_H
   727.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   727.2 +++ b/src/win32/VideoMode.cpp	Sat Mar 03 10:31:27 2012 -0600
   727.3 @@ -0,0 +1,347 @@
   727.4 +// VideoMode.cpp : implementation file
   727.5 +//
   727.6 +
   727.7 +#include "stdafx.h"
   727.8 +#include "resource.h"
   727.9 +
  727.10 +///		#define _AFXDLL /// EVIL
  727.11 +///		#include "afxwin.h" /// EVIL
  727.12 +///		#include "afxdll_.h" /// EVIL
  727.13 +
  727.14 +#define DIRECTDRAW_VERSION 0x0700
  727.15 +#include "ddraw.h"
  727.16 +
  727.17 +#include "VideoMode.h"
  727.18 +
  727.19 +#include "../common/System.h" // for system messages
  727.20 +
  727.21 +#define MAX_DRIVERS         32                  // 32 drivers maximum
  727.22 +
  727.23 +//-----------------------------------------------------------------------------
  727.24 +// Local structures
  727.25 +//-----------------------------------------------------------------------------
  727.26 +// Keeps data on the available DDraw drivers
  727.27 +struct
  727.28 +{
  727.29 +	char     szDescription[128];
  727.30 +	char     szName[128];
  727.31 +	GUID *   pGUID;
  727.32 +	GUID     GUIDcopy;
  727.33 +	HMONITOR hm;
  727.34 +} Drivers[MAX_DRIVERS];
  727.35 +
  727.36 +//-----------------------------------------------------------------------------
  727.37 +// Local data
  727.38 +//-----------------------------------------------------------------------------
  727.39 +static int gDriverCnt = 0;                      // Total number of drivers
  727.40 +static GUID *gpSelectedDriverGUID;
  727.41 +
  727.42 +//-----------------------------------------------------------------------------
  727.43 +// Name: DDEnumCallbackEx()
  727.44 +// Desc: This call back is used to determine the existing available DDraw
  727.45 +//       devices, so the user can pick which one to run on.
  727.46 +//-----------------------------------------------------------------------------
  727.47 +BOOL WINAPI
  727.48 +DDEnumCallbackEx(GUID *pGUID, LPSTR pDescription, LPSTR pName, LPVOID pContext, HMONITOR hm)
  727.49 +{
  727.50 +	if (pGUID)
  727.51 +	{
  727.52 +		Drivers[gDriverCnt].GUIDcopy = *pGUID;
  727.53 +		Drivers[gDriverCnt].pGUID    = &Drivers[gDriverCnt].GUIDcopy;
  727.54 +	}
  727.55 +	else
  727.56 +		Drivers[gDriverCnt].pGUID = NULL;
  727.57 +	Drivers[gDriverCnt].szDescription[127] = '\0';
  727.58 +	Drivers[gDriverCnt].szName[127]        = '\0';
  727.59 +	strncpy(Drivers[gDriverCnt].szDescription, pDescription, 127);
  727.60 +	strncpy(Drivers[gDriverCnt].szName, pName, 127);
  727.61 +	Drivers[gDriverCnt].hm = hm;
  727.62 +	if (gDriverCnt < MAX_DRIVERS)
  727.63 +		gDriverCnt++;
  727.64 +	else
  727.65 +		return DDENUMRET_CANCEL;
  727.66 +	return DDENUMRET_OK;
  727.67 +}
  727.68 +
  727.69 +//-----------------------------------------------------------------------------
  727.70 +// Name: DDEnumCallback()
  727.71 +// Desc: This callback is used only with old versions of DDraw.
  727.72 +//-----------------------------------------------------------------------------
  727.73 +BOOL WINAPI
  727.74 +DDEnumCallback(GUID *pGUID, LPSTR pDescription, LPSTR pName, LPVOID context)
  727.75 +{
  727.76 +	return (DDEnumCallbackEx(pGUID, pDescription, pName, context, NULL));
  727.77 +}
  727.78 +
  727.79 +static HRESULT WINAPI addVideoMode(LPDDSURFACEDESC2 surf, LPVOID lpContext)
  727.80 +{
  727.81 +	HWND h = (HWND)lpContext;
  727.82 +	char buffer[50];
  727.83 +
  727.84 +	switch (surf->ddpfPixelFormat.dwRGBBitCount)
  727.85 +	{
  727.86 +	case 16:
  727.87 +	case 24:
  727.88 +	case 32:
  727.89 +		if (surf->dwWidth >= 640 && surf->dwHeight >= 480)
  727.90 +		{
  727.91 +			sprintf(buffer, "%4dx%4dx%2d", surf->dwWidth, surf->dwHeight,
  727.92 +			        surf->ddpfPixelFormat.dwRGBBitCount);
  727.93 +			int pos = ::SendMessage(h, LB_ADDSTRING, 0, (LPARAM)buffer);
  727.94 +			::SendMessage(h, LB_SETITEMDATA, pos,
  727.95 +			              (surf->ddpfPixelFormat.dwRGBBitCount << 24) |
  727.96 +			              ((surf->dwWidth & 4095) << 12) |
  727.97 +			              (surf->dwHeight & 4095));
  727.98 +		}
  727.99 +	}
 727.100 +
 727.101 +	return DDENUMRET_OK;
 727.102 +}
 727.103 +
 727.104 +int winVideoModeSelect(CWnd *pWnd, GUID **guid)
 727.105 +{
 727.106 +	HINSTANCE h = /**/ ::LoadLibrary("ddraw.dll");
 727.107 +
 727.108 +	// If ddraw.dll doesn't exist in the search path,
 727.109 +	// then DirectX probably isn't installed, so fail.
 727.110 +	if (!h)
 727.111 +		return -1;
 727.112 +
 727.113 +	gDriverCnt = 0;
 727.114 +
 727.115 +	// Note that you must know which version of the
 727.116 +	// function to retrieve (see the following text).
 727.117 +	// For this example, we use the ANSI version.
 727.118 +	LPDIRECTDRAWENUMERATEEX lpDDEnumEx;
 727.119 +	lpDDEnumEx = (LPDIRECTDRAWENUMERATEEX)
 727.120 +	             GetProcAddress(h, "DirectDrawEnumerateExA");
 727.121 +
 727.122 +	// If the function is there, call it to enumerate all display
 727.123 +	// devices attached to the desktop, and any non-display DirectDraw
 727.124 +	// devices.
 727.125 +	if (lpDDEnumEx)
 727.126 +		lpDDEnumEx(DDEnumCallbackEx, NULL,
 727.127 +		           DDENUM_ATTACHEDSECONDARYDEVICES |
 727.128 +		           DDENUM_NONDISPLAYDEVICES
 727.129 +		           );
 727.130 +	else
 727.131 +	{
 727.132 +		/*
 727.133 +		 * We must be running on an old version of DirectDraw.
 727.134 +		 * Therefore MultiMon isn't supported. Fall back on
 727.135 +		 * DirectDrawEnumerate to enumerate standard devices on a
 727.136 +		 * single-monitor system.
 727.137 +		 */
 727.138 +		BOOL (WINAPI *lpDDEnum)(LPDDENUMCALLBACK, LPVOID);
 727.139 +
 727.140 +		lpDDEnum = (BOOL (WINAPI *)(LPDDENUMCALLBACK, LPVOID))
 727.141 +		           GetProcAddress(h, "DirectDrawEnumerateA");
 727.142 +		if (lpDDEnum)
 727.143 +			lpDDEnum(DDEnumCallback, NULL);
 727.144 +
 727.145 +		/* Note that it could be handy to let the OldCallback function
 727.146 +		 * be a wrapper for a DDEnumCallbackEx.
 727.147 +		 *
 727.148 +		 * Such a function would look like:
 727.149 +		 *    BOOL FAR PASCAL OldCallback(GUID FAR *lpGUID,
 727.150 +		 *                                LPSTR pDesc,
 727.151 +		 *                                LPSTR pName,
 727.152 +		 *                                LPVOID pContext)
 727.153 +		 *    {
 727.154 +		 *         return Callback(lpGUID,pDesc,pName,pContext,NULL);
 727.155 +		 *    }
 727.156 +		 */
 727.157 +	}
 727.158 +
 727.159 +	int selected = 0;
 727.160 +
 727.161 +	if (gDriverCnt > 1)
 727.162 +	{
 727.163 +		VideoDriverSelect d(pWnd);
 727.164 +
 727.165 +		selected = d.DoModal();
 727.166 +
 727.167 +		if (selected == -1)
 727.168 +		{
 727.169 +			// If the library was loaded by calling LoadLibrary(),
 727.170 +			// then you must use FreeLibrary() to let go of it.
 727.171 +			/**/ ::FreeLibrary(h);
 727.172 +
 727.173 +			return -1;
 727.174 +		}
 727.175 +	}
 727.176 +
 727.177 +	HRESULT (WINAPI *DDrawCreateEx)(GUID *, LPVOID *, REFIID, IUnknown *);
 727.178 +	DDrawCreateEx = (HRESULT (WINAPI *)(GUID *, LPVOID *, REFIID, IUnknown *))
 727.179 +	                GetProcAddress(h, "DirectDrawCreateEx");
 727.180 +
 727.181 +	LPDIRECTDRAW7 ddraw = NULL;
 727.182 +	if (DDrawCreateEx)
 727.183 +	{
 727.184 +		HRESULT hret = DDrawCreateEx(Drivers[selected].pGUID,
 727.185 +		                             (void * *)&ddraw,
 727.186 +		                             IID_IDirectDraw7,
 727.187 +		                             NULL);
 727.188 +		if (hret != DD_OK)
 727.189 +		{
 727.190 +			systemMessage(0, "Error during DirectDrawCreateEx: %08x", hret);
 727.191 +			/**/ ::FreeLibrary(h);
 727.192 +			return -1;
 727.193 +		}
 727.194 +	}
 727.195 +	else
 727.196 +	{
 727.197 +		// should not happen....
 727.198 +		systemMessage(0, "Error getting DirectDrawCreateEx");
 727.199 +		/**/ ::FreeLibrary(h);
 727.200 +		return -1;
 727.201 +	}
 727.202 +
 727.203 +	VideoMode dlg(ddraw, pWnd);
 727.204 +
 727.205 +	int res = dlg.DoModal();
 727.206 +
 727.207 +	if (res != -1)
 727.208 +	{
 727.209 +		*guid = Drivers[selected].pGUID;
 727.210 +	}
 727.211 +	ddraw->Release();
 727.212 +	ddraw = NULL;
 727.213 +
 727.214 +	// If the library was loaded by calling LoadLibrary(),
 727.215 +	// then you must use FreeLibrary() to let go of it.
 727.216 +	/**/ ::FreeLibrary(h);
 727.217 +
 727.218 +	return res;
 727.219 +}
 727.220 +
 727.221 +/////////////////////////////////////////////////////////////////////////////
 727.222 +// VideoMode dialog
 727.223 +
 727.224 +VideoMode::VideoMode(LPDIRECTDRAW7 pDraw, CWnd*pParent /*=NULL*/)
 727.225 +	: CDialog(VideoMode::IDD, pParent)
 727.226 +{
 727.227 +	//{{AFX_DATA_INIT(VideoMode)
 727.228 +	// NOTE: the ClassWizard will add member initialization here
 727.229 +	//}}AFX_DATA_INIT
 727.230 +	pDirectDraw = pDraw;
 727.231 +}
 727.232 +
 727.233 +void VideoMode::DoDataExchange(CDataExchange*pDX)
 727.234 +{
 727.235 +	CDialog::DoDataExchange(pDX);
 727.236 +	//{{AFX_DATA_MAP(VideoMode)
 727.237 +	DDX_Control(pDX, IDC_MODES, m_modes);
 727.238 +	//}}AFX_DATA_MAP
 727.239 +}
 727.240 +
 727.241 +BEGIN_MESSAGE_MAP(VideoMode, CDialog)
 727.242 +//{{AFX_MSG_MAP(VideoMode)
 727.243 +ON_LBN_SELCHANGE(IDC_MODES, OnSelchangeModes)
 727.244 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
 727.245 +ON_BN_CLICKED(ID_OK, OnOk)
 727.246 +//}}AFX_MSG_MAP
 727.247 +END_MESSAGE_MAP()
 727.248 +
 727.249 +/////////////////////////////////////////////////////////////////////////////
 727.250 +// VideoMode message handlers
 727.251 +
 727.252 +void VideoMode::OnSelchangeModes()
 727.253 +{
 727.254 +	int item = m_modes.GetCurSel();
 727.255 +
 727.256 +	GetDlgItem(ID_OK)->EnableWindow(item != -1);
 727.257 +}
 727.258 +
 727.259 +void VideoMode::OnCancel()
 727.260 +{
 727.261 +	EndDialog(-1);
 727.262 +}
 727.263 +
 727.264 +void VideoMode::OnOk()
 727.265 +{
 727.266 +	int cur = m_modes.GetCurSel();
 727.267 +
 727.268 +	if (cur != -1)
 727.269 +	{
 727.270 +		cur = m_modes.GetItemData(cur);
 727.271 +	}
 727.272 +	EndDialog(cur);
 727.273 +}
 727.274 +
 727.275 +BOOL VideoMode::OnInitDialog()
 727.276 +{
 727.277 +	CDialog::OnInitDialog();
 727.278 +
 727.279 +	// check for available fullscreen modes
 727.280 +	pDirectDraw->EnumDisplayModes(DDEDM_STANDARDVGAMODES, NULL, m_modes.m_hWnd,
 727.281 +	                              addVideoMode);
 727.282 +
 727.283 +	GetDlgItem(ID_OK)->EnableWindow(FALSE);
 727.284 +	CenterWindow();
 727.285 +
 727.286 +	return TRUE; // return TRUE unless you set the focus to a control
 727.287 +	             // EXCEPTION: OCX Property Pages should return FALSE
 727.288 +}
 727.289 +
 727.290 +/////////////////////////////////////////////////////////////////////////////
 727.291 +// VideoDriverSelect dialog
 727.292 +
 727.293 +VideoDriverSelect::VideoDriverSelect(CWnd*pParent /*=NULL*/)
 727.294 +	: CDialog(VideoDriverSelect::IDD, pParent)
 727.295 +{
 727.296 +	//{{AFX_DATA_INIT(VideoDriverSelect)
 727.297 +	// NOTE: the ClassWizard will add member initialization here
 727.298 +	//}}AFX_DATA_INIT
 727.299 +}
 727.300 +
 727.301 +void VideoDriverSelect::DoDataExchange(CDataExchange*pDX)
 727.302 +{
 727.303 +	CDialog::DoDataExchange(pDX);
 727.304 +	//{{AFX_DATA_MAP(VideoDriverSelect)
 727.305 +	DDX_Control(pDX, IDC_DRIVERS, m_drivers);
 727.306 +	//}}AFX_DATA_MAP
 727.307 +}
 727.308 +
 727.309 +BEGIN_MESSAGE_MAP(VideoDriverSelect, CDialog)
 727.310 +//{{AFX_MSG_MAP(VideoDriverSelect)
 727.311 +ON_BN_CLICKED(ID_OK, OnOk)
 727.312 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
 727.313 +ON_LBN_SELCHANGE(IDC_DRIVERS, OnSelchangeDrivers)
 727.314 +//}}AFX_MSG_MAP
 727.315 +END_MESSAGE_MAP()
 727.316 +
 727.317 +/////////////////////////////////////////////////////////////////////////////
 727.318 +// VideoDriverSelect message handlers
 727.319 +
 727.320 +void VideoDriverSelect::OnCancel()
 727.321 +{
 727.322 +	EndDialog(-1);
 727.323 +}
 727.324 +
 727.325 +void VideoDriverSelect::OnOk()
 727.326 +{
 727.327 +	EndDialog(m_drivers.GetCurSel());
 727.328 +}
 727.329 +
 727.330 +BOOL VideoDriverSelect::OnInitDialog()
 727.331 +{
 727.332 +	CDialog::OnInitDialog();
 727.333 +
 727.334 +	for (int i = 0; i < gDriverCnt; i++)
 727.335 +	{
 727.336 +		m_drivers.AddString(Drivers[i].szDescription);
 727.337 +	}
 727.338 +
 727.339 +	GetDlgItem(ID_OK)->EnableWindow(FALSE);
 727.340 +	CenterWindow();
 727.341 +
 727.342 +	return TRUE; // return TRUE unless you set the focus to a control
 727.343 +	             // EXCEPTION: OCX Property Pages should return FALSE
 727.344 +}
 727.345 +
 727.346 +void VideoDriverSelect::OnSelchangeDrivers()
 727.347 +{
 727.348 +	GetDlgItem(ID_OK)->EnableWindow(m_drivers.GetCurSel() != -1);
 727.349 +}
 727.350 +
   728.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   728.2 +++ b/src/win32/VideoMode.h	Sat Mar 03 10:31:27 2012 -0600
   728.3 @@ -0,0 +1,79 @@
   728.4 +#if !defined(AFX_VIDEOMODE_H__074B2426_32EA_4D69_9215_AB5E90F885D0__INCLUDED_)
   728.5 +#define AFX_VIDEOMODE_H__074B2426_32EA_4D69_9215_AB5E90F885D0__INCLUDED_
   728.6 +
   728.7 +#if _MSC_VER > 1000
   728.8 +#pragma once
   728.9 +#endif // _MSC_VER > 1000
  728.10 +// VideoMode.h : header file
  728.11 +//
  728.12 +
  728.13 +/////////////////////////////////////////////////////////////////////////////
  728.14 +// VideoMode dialog
  728.15 +
  728.16 +class VideoMode : public CDialog
  728.17 +{
  728.18 +	// Construction
  728.19 +public:
  728.20 +	VideoMode(LPDIRECTDRAW7 pDraw, CWnd *pParent = NULL); // standard constructor
  728.21 +
  728.22 +	// Dialog Data
  728.23 +	//{{AFX_DATA(VideoMode)
  728.24 +	enum { IDD = IDD_MODES };
  728.25 +	CListBox m_modes;
  728.26 +	//}}AFX_DATA
  728.27 +
  728.28 +	// Overrides
  728.29 +	// ClassWizard generated virtual function overrides
  728.30 +	//{{AFX_VIRTUAL(VideoMode)
  728.31 +protected:
  728.32 +	virtual void DoDataExchange(CDataExchange *pDX);  // DDX/DDV support
  728.33 +	//}}AFX_VIRTUAL
  728.34 +
  728.35 +	// Implementation
  728.36 +protected:
  728.37 +	// Generated message map functions
  728.38 +	//{{AFX_MSG(VideoMode)
  728.39 +	afx_msg void OnSelchangeModes();
  728.40 +	afx_msg void OnCancel();
  728.41 +	afx_msg void OnOk();
  728.42 +	virtual BOOL OnInitDialog();
  728.43 +	//}}AFX_MSG
  728.44 +	DECLARE_MESSAGE_MAP()
  728.45 +private:
  728.46 +	LPDIRECTDRAW7 pDirectDraw;
  728.47 +};
  728.48 +
  728.49 +/////////////////////////////////////////////////////////////////////////////
  728.50 +// VideoDriverSelect dialog
  728.51 +
  728.52 +class VideoDriverSelect : public CDialog
  728.53 +{
  728.54 +	// Construction
  728.55 +public:
  728.56 +	VideoDriverSelect(CWnd *pParent = NULL); // standard constructor
  728.57 +
  728.58 +	// Dialog Data
  728.59 +	//{{AFX_DATA(VideoDriverSelect)
  728.60 +	enum { IDD = IDD_DRIVERS };
  728.61 +	CListBox m_drivers;
  728.62 +	//}}AFX_DATA
  728.63 +
  728.64 +	// Overrides
  728.65 +	// ClassWizard generated virtual function overrides
  728.66 +	//{{AFX_VIRTUAL(VideoDriverSelect)
  728.67 +protected:
  728.68 +	virtual void DoDataExchange(CDataExchange *pDX);  // DDX/DDV support
  728.69 +	//}}AFX_VIRTUAL
  728.70 +
  728.71 +	// Implementation
  728.72 +protected:
  728.73 +	// Generated message map functions
  728.74 +	//{{AFX_MSG(VideoDriverSelect)
  728.75 +	afx_msg void OnCancel();
  728.76 +	afx_msg void OnOk();
  728.77 +	virtual BOOL OnInitDialog();
  728.78 +	afx_msg void OnSelchangeDrivers();
  728.79 +	//}}AFX_MSG
  728.80 +	DECLARE_MESSAGE_MAP()
  728.81 +};
  728.82 +#endif // !defined(AFX_VIDEOMODE_H__074B2426_32EA_4D69_9215_AB5E90F885D0__INCLUDED_)
   729.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   729.2 +++ b/src/win32/VisualBoyAdvance.exe.manifest	Sat Mar 03 10:31:27 2012 -0600
   729.3 @@ -0,0 +1,23 @@
   729.4 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
   729.5 +<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
   729.6 +<assemblyIdentity
   729.7 +    version="0.6.0.0"
   729.8 +    processorArchitecture="X86"
   729.9 +    name="VisualBoyAdvance"
  729.10 +    type="win32"
  729.11 +/>
  729.12 +<description>VisualBoyAdvance Emulator.</description>
  729.13 +<dependency>
  729.14 +    <dependentAssembly>
  729.15 +        <assemblyIdentity
  729.16 +            type="win32"
  729.17 +            name="Microsoft.Windows.Common-Controls"
  729.18 +            version="6.0.0.0"
  729.19 +            processorArchitecture="X86"
  729.20 +            publicKeyToken="6595b64144ccf1df"
  729.21 +            language="*"
  729.22 +        />
  729.23 +    </dependentAssembly>
  729.24 +</dependency>
  729.25 +</assembly>
  729.26 +
   730.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   730.2 +++ b/src/win32/WavWriter.cpp	Sat Mar 03 10:31:27 2012 -0600
   730.3 @@ -0,0 +1,92 @@
   730.4 +// WavWriter.cpp: implementation of the WavWriter class.
   730.5 +//
   730.6 +//////////////////////////////////////////////////////////////////////
   730.7 +
   730.8 +#include "stdafx.h"
   730.9 +#include "WavWriter.h"
  730.10 +
  730.11 +#include "../common/Util.h"
  730.12 +
  730.13 +//////////////////////////////////////////////////////////////////////
  730.14 +// Construction/Destruction
  730.15 +//////////////////////////////////////////////////////////////////////
  730.16 +
  730.17 +WavWriter::WavWriter()
  730.18 +{
  730.19 +	m_file    = NULL;
  730.20 +	m_len     = 0;
  730.21 +	m_posSize = 0;
  730.22 +}
  730.23 +
  730.24 +WavWriter::~WavWriter()
  730.25 +{
  730.26 +	if (m_file)
  730.27 +		Close();
  730.28 +}
  730.29 +
  730.30 +void WavWriter::Close()
  730.31 +{
  730.32 +	// calculate the total file length
  730.33 +	u32 len = ftell(m_file)-8;
  730.34 +	fseek(m_file, 4, SEEK_SET);
  730.35 +	u8 data[4];
  730.36 +	utilPutDword(data, len);
  730.37 +	fwrite(data, 1, 4, m_file);
  730.38 +	// write out the size of the data section
  730.39 +	fseek(m_file, m_posSize, SEEK_SET);
  730.40 +	utilPutDword(data, m_len);
  730.41 +	fwrite(data, 1, 4, m_file);
  730.42 +	fclose(m_file);
  730.43 +	m_file = NULL;
  730.44 +}
  730.45 +
  730.46 +bool WavWriter::Open(const char *name)
  730.47 +{
  730.48 +	if (m_file)
  730.49 +		Close();
  730.50 +	m_file = fopen(name, "wb");
  730.51 +
  730.52 +	if (!m_file)
  730.53 +		return false;
  730.54 +	// RIFF header
  730.55 +	u8 data[4] = { 'R', 'I', 'F', 'F' };
  730.56 +	fwrite(data, 1, 4, m_file);
  730.57 +	utilPutDword(data, 0);
  730.58 +	// write 0 for now. Will get filled during close
  730.59 +	fwrite(data, 1, 4, m_file);
  730.60 +	// write WAVE header
  730.61 +	u8 data2[4] = { 'W', 'A', 'V', 'E' };
  730.62 +	fwrite(data2, 1, 4, m_file);
  730.63 +	return true;
  730.64 +}
  730.65 +
  730.66 +void WavWriter::SetFormat(const WAVEFORMATEX *format)
  730.67 +{
  730.68 +	if (m_file == NULL)
  730.69 +		return;
  730.70 +	// write fmt header
  730.71 +	u8 data[4] = { 'f', 'm', 't', ' ' };
  730.72 +	fwrite(data, 1, 4, m_file);
  730.73 +	u32 value = sizeof(WAVEFORMATEX);
  730.74 +	utilPutDword(data, value);
  730.75 +	fwrite(data, 1, 4, m_file);
  730.76 +	fwrite(format, 1, sizeof(WAVEFORMATEX), m_file);
  730.77 +	// start data header
  730.78 +	u8 data2[4] = { 'd', 'a', 't', 'a' };
  730.79 +	fwrite(data2, 1, 4, m_file);
  730.80 +
  730.81 +	m_posSize = ftell(m_file);
  730.82 +	// write 0 for data chunk size. Filled out during Close()
  730.83 +	utilPutDword(data, 0);
  730.84 +	fwrite(data, 1, 4, m_file);
  730.85 +}
  730.86 +
  730.87 +void WavWriter::AddSound(const u8 *data, int len)
  730.88 +{
  730.89 +	if (m_file == NULL)
  730.90 +		return;
  730.91 +	// write a block of sound data
  730.92 +	fwrite(data, 1, len, m_file);
  730.93 +	m_len += len;
  730.94 +}
  730.95 +
   731.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   731.2 +++ b/src/win32/WavWriter.h	Sat Mar 03 10:31:27 2012 -0600
   731.3 @@ -0,0 +1,33 @@
   731.4 +#if !defined(AFX_WAVWRITER_H__BE6C9DE9_60E7_4192_9797_8C7F55B3CE46__INCLUDED_)
   731.5 +#define AFX_WAVWRITER_H__BE6C9DE9_60E7_4192_9797_8C7F55B3CE46__INCLUDED_
   731.6 +
   731.7 +#if _MSC_VER > 1000
   731.8 +#pragma once
   731.9 +#endif // _MSC_VER > 1000
  731.10 +
  731.11 +// -*- C++ -*-
  731.12 +// WavWriter.h: interface for the WavWriter class.
  731.13 +//
  731.14 +
  731.15 +#include <mmreg.h>
  731.16 +
  731.17 +class WavWriter  
  731.18 +{
  731.19 + private:
  731.20 +  FILE *m_file;
  731.21 +  int m_len;
  731.22 +  long m_posSize;
  731.23 +
  731.24 + public:
  731.25 +  WavWriter();
  731.26 +  ~WavWriter();
  731.27 +
  731.28 +  bool Open(const char *name);
  731.29 +  void SetFormat(const WAVEFORMATEX *format);
  731.30 +  void AddSound(const u8 *data, int len);
  731.31 +
  731.32 + private:
  731.33 +  void Close();
  731.34 +};
  731.35 +
  731.36 +#endif // !defined(AFX_WAVWRITER_H__BE6C9DE9_60E7_4192_9797_8C7F55B3CE46__INCLUDED_)
   732.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   732.2 +++ b/src/win32/WinHelper.h	Sat Mar 03 10:31:27 2012 -0600
   732.3 @@ -0,0 +1,229 @@
   732.4 +/*----------------------------------------------------------------------
   732.5 +   Copyright (c) 1998 Gipsysoft. All Rights Reserved.
   732.6 +   Please see the file "licence.txt" for licencing details.
   732.7 +   File:   WinHelper.h
   732.8 +   Owner:  russf@gipsysoft.com
   732.9 +   Purpose:        Windows helper functions, classes, structures and macros
  732.10 +   that make life a little easier
  732.11 +   These should all be zero impact classes etc. that is they
  732.12 +   should *not* have a cpp file associated with them.
  732.13 +   ----------------------------------------------------------------------*/
  732.14 +#ifndef WINHELPER_H
  732.15 +#define WINHELPER_H
  732.16 +
  732.17 +//#ifndef DEBUGHLP_H
  732.18 +//      #include <DebugHlp.h>
  732.19 +//#endif        //      DEBUGHLP_H
  732.20 +
  732.21 +#ifndef FASTCALL
  732.22 +#define FASTCALL
  732.23 +#endif  //      FASTCALL
  732.24 +
  732.25 +extern void AssertFailed(char *, int, char *);
  732.26 +extern void ApiFailure(char *, int, char *);
  732.27 +
  732.28 +#define R_VERIFY(a) R_ASSERT(a)
  732.29 +#define R_ASSERT(a) \
  732.30 +    do { \
  732.31 +		if (!(a)) { \
  732.32 +			AssertFailed(__FILE__, __LINE__, # a); \
  732.33 +		} \
  732.34 +	} while (0);
  732.35 +
  732.36 +#define VAPI(a) \
  732.37 +    do { \
  732.38 +		if (!(a)) { \
  732.39 +			ApiFailure(__FILE__, __LINE__, # a); \
  732.40 +		} \
  732.41 +	} while (0);
  732.42 +
  732.43 +#define ASSERT_VALID_HWND(a) ASSERT(::IsWindow(a))
  732.44 +
  732.45 +namespace WinHelper
  732.46 +{
  732.47 +	class CSize : public tagSIZE
  732.48 +		//
  732.49 +		//      Wrapper for the SIZE structure
  732.50 +	{
  732.51 +public:
  732.52 +		inline CSize() {};
  732.53 +		inline explicit CSize(const SIZE &size) { cx = size.cx; cy = size.cy; }
  732.54 +		inline explicit CSize(long nSizeX, long nSizeY) { cx = nSizeX; cy = nSizeY; }
  732.55 +		inline void Set(long nSizeX, long nSizeY) { cx = nSizeX; cy = nSizeY; }
  732.56 +		inline operator LPSIZE() { return this; };
  732.57 +
  732.58 +		inline bool operator !=(const SIZE &size) const { return cx != size.cx || cy != size.cy;}
  732.59 +		inline CSize & operator =(const SIZE &size) { cx = size.cx; cy = size.cy; return *this; }
  732.60 +		inline void Empty() { cx = cy = 0; }
  732.61 +	};
  732.62 +
  732.63 +	class CRect : public tagRECT
  732.64 +		//
  732.65 +		//      Wrapper for a RECT structure
  732.66 +	{
  732.67 +public:
  732.68 +		inline CRect() {}
  732.69 +		//      Initialisation constructor
  732.70 +		inline explicit CRect(const RECT& rhs) { Set(rhs.left, rhs.top, rhs.right, rhs.bottom);}
  732.71 +		inline CRect(int xLeft, int yTop, int xRight, int yBottom) { Set(xLeft, yTop, xRight, yBottom); }
  732.72 +		//      Get the width of the rectangle
  732.73 +		inline int Width() const { return right - left; }
  732.74 +		//      Get the height of the rectangle
  732.75 +		inline int Height() const { return bottom - top; }
  732.76 +		//      overloaded operator so you don't have to do &rc anymore
  732.77 +		inline operator LPCRECT() const { return this; };
  732.78 +		inline operator LPRECT() { return this; };
  732.79 +		//      Return the SIZE of the rectangle;
  732.80 +		inline CSize Size() const { CSize s(Width(), Height()); return s; }
  732.81 +		//      Return the top left of the rectangle
  732.82 +		inline POINT TopLeft() const { POINT pt = { left, top }; return pt; }
  732.83 +		//      Return the bottom right of the rectangle
  732.84 +		inline POINT BottomRight() const { POINT pt = { right, bottom }; return pt; }
  732.85 +		//      Set the rectangles left, top, right and bottom
  732.86 +		inline void Set(int xLeft, int yTop, int xRight, int yBottom) { top = yTop; bottom = yBottom; right = xRight; left =
  732.87 +			                                                                xLeft; }
  732.88 +		//      Return true if the rectangle contains all zeros
  732.89 +		inline bool IsEmpty() const { return left == 0 && right == 0 && top == 0 && bottom == 0 ? true : false; }
  732.90 +		//      Zero out our rectangle
  732.91 +		inline void Empty() { left = right = top = bottom = 0; }
  732.92 +		//      Set the size of the rect but leave the top left position untouched.
  732.93 +		inline void SetSize(const CSize &size) { bottom = top + size.cy; right = left + size.cx; }
  732.94 +		inline void SetSize(const SIZE &size) { bottom = top + size.cy; right = left + size.cx; }
  732.95 +		inline void SetSize(int cx, int cy) { bottom = top + cy; right = left + cx; }
  732.96 +		//      Move the rectangle by an offset
  732.97 +		inline void Offset(int cx, int cy)
  732.98 +		{
  732.99 +			top    += cy;
 732.100 +			bottom += cy;
 732.101 +			right  += cx;
 732.102 +			left   += cx;
 732.103 +		}
 732.104 +
 732.105 +		//      Inflate the rectangle by the cx and cy, use negative to shrink the rectangle
 732.106 +		inline void Inflate(int cx, int cy)
 732.107 +		{
 732.108 +			top    -= cy;
 732.109 +			bottom += cy;
 732.110 +			right  += cx;
 732.111 +			left   -= cx;
 732.112 +		}
 732.113 +
 732.114 +		//      Assignment from a RECT
 732.115 +		inline CRect &operator =(const RECT&rhs)
 732.116 +		{
 732.117 +			left  = rhs.left; top = rhs.top;
 732.118 +			right = rhs.right; bottom = rhs.bottom;
 732.119 +			return *this;
 732.120 +		}
 732.121 +
 732.122 +		//      Return true if the point passed is within the rectangle
 732.123 +		inline bool PtInRect(const POINT &pt) const {       return  (pt.x >= left && pt.x < right && pt.y >= top && pt.y <
 732.124 +			                                                         bottom); }
 732.125 +		//      Return true if the rectangle passed overlaps this rectangle
 732.126 +		inline bool Intersect(const RECT &rc) const { return (rc.left < right &&
 732.127 +			                                                            rc.right > left && rc.top < bottom && rc.bottom > top); }
 732.128 +	};
 732.129 +
 732.130 +	class CPoint : public tagPOINT
 732.131 +		//
 732.132 +		//      Wrapper for the POINT structure
 732.133 +	{
 732.134 +public:
 732.135 +		inline CPoint() {};
 732.136 +		inline CPoint(LPARAM lParam) { x = LOWORD(lParam); y = HIWORD(lParam); }
 732.137 +		inline CPoint(int nX, int nY) { x = nX; y = nY; }
 732.138 +		inline CPoint(const POINT &pt) { x = pt.x; y = pt.y; }
 732.139 +		inline bool operator ==(const CPoint &rhs) const { return x == rhs.x && y == rhs.y; }
 732.140 +		inline bool operator !=(const CPoint &rhs) const { return x != rhs.x || y != rhs.y; }
 732.141 +		inline operator LPPOINT() { return this; }
 732.142 +	};
 732.143 +
 732.144 +	class CScrollInfo : public tagSCROLLINFO
 732.145 +	{
 732.146 +public:
 732.147 +		CScrollInfo(UINT fPassedMask) { cbSize = sizeof(tagSCROLLINFO); fMask = fPassedMask; }
 732.148 +	};
 732.149 +
 732.150 +	class CCriticalSection
 732.151 +	//
 732.152 +	//      Simple crtical section handler/wrapper
 732.153 +	{
 732.154 +public:
 732.155 +		inline CCriticalSection()       { ::InitializeCriticalSection(&m_sect); }
 732.156 +		inline ~CCriticalSection() { ::DeleteCriticalSection(&m_sect); }
 732.157 +
 732.158 +		//      Blocking lock.
 732.159 +		inline void Lock()                      { ::EnterCriticalSection(&m_sect); }
 732.160 +		//      Unlock
 732.161 +		inline void Unlock()            { ::LeaveCriticalSection(&m_sect); }
 732.162 +
 732.163 +		class CLock
 732.164 +		//
 732.165 +		//      Simple lock class for the critcal section
 732.166 +		{
 732.167 +public:
 732.168 +			inline CLock(CCriticalSection &sect) : m_sect(sect) { m_sect.Lock(); }
 732.169 +			inline ~CLock() { m_sect.Unlock(); }
 732.170 +private:
 732.171 +			CCriticalSection &m_sect;
 732.172 +
 732.173 +			CLock();
 732.174 +			CLock(const CLock &);
 732.175 +			CLock & operator =(const CLock &);
 732.176 +		};
 732.177 +private:
 732.178 +		CRITICAL_SECTION m_sect;
 732.179 +
 732.180 +		CCriticalSection(const CCriticalSection &);
 732.181 +		CCriticalSection & operator =(const CCriticalSection &);
 732.182 +	};
 732.183 +
 732.184 +#define ZeroStructure(t) ZeroMemory(&t, sizeof(t))
 732.185 +#define countof(t)    (sizeof((t)) / sizeof((t)[0]))
 732.186 +#define UNREF(P) UNREFERENCED_PARAMETER(P)
 732.187 +
 732.188 +	inline bool IsShiftPressed()
 732.189 +	{
 732.190 +		return GetKeyState(VK_SHIFT) & 0x8000 ? true : false;
 732.191 +	}
 732.192 +
 732.193 +	inline bool IsAltPressed()
 732.194 +	{
 732.195 +		return GetKeyState(VK_MENU) & 0x8000 ? true : false;
 732.196 +	}
 732.197 +
 732.198 +	inline bool IsControlPressed()
 732.199 +	{
 732.200 +		return GetKeyState(VK_CONTROL) & 0x8000 ? true : false;
 732.201 +	}
 732.202 +
 732.203 +	inline HICON LoadIcon16x16(HINSTANCE hInst, UINT uID)
 732.204 +	//
 732.205 +	//      Load a 16x16 icon from the same resource as the other size icons.
 732.206 +	{
 732.207 +		return reinterpret_cast<HICON>(::LoadImage(hInst, MAKEINTRESOURCE(uID), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR));
 732.208 +	}
 732.209 +
 732.210 +	class CDeferWindowPos
 732.211 +	//
 732.212 +	//      Wrapper for the Begin, Defer and End WindowPos functions. Nothing glamorous.
 732.213 +	{
 732.214 +public:
 732.215 +		inline CDeferWindowPos(const int nWindows = 1) : m_hdlDef(::BeginDeferWindowPos(nWindows)) {}
 732.216 +		inline ~CDeferWindowPos() { R_VERIFY(::EndDeferWindowPos(m_hdlDef)); }
 732.217 +		inline HDWP DeferWindowPos(HWND hWnd, HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT uFlags)
 732.218 +		{
 732.219 +			return ::DeferWindowPos(m_hdlDef, hWnd, hWndInsertAfter, x, y, cx, cy, uFlags);
 732.220 +		}
 732.221 +
 732.222 +		inline HDWP DeferWindowPos(HWND hWnd, HWND hWndInsertAfter, const CRect &rc, UINT uFlags)
 732.223 +		{
 732.224 +			return ::DeferWindowPos(m_hdlDef, hWnd, hWndInsertAfter, rc.left, rc.top, rc.Width(), rc.Height(), uFlags);
 732.225 +		}
 732.226 +
 732.227 +private:
 732.228 +		HDWP m_hdlDef;
 732.229 +	};
 732.230 +}       //      WinHelper
 732.231 +
 732.232 +#endif //WINHELPER_H
   733.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   733.2 +++ b/src/win32/WinMiscUtil.cpp	Sat Mar 03 10:31:27 2012 -0600
   733.3 @@ -0,0 +1,497 @@
   733.4 +#include "stdafx.h"
   733.5 +#include "WinMiscUtil.h"
   733.6 +#include "WinResUtil.h"
   733.7 +#include "resource.h"
   733.8 +#include "../NLS.h"
   733.9 +#include "VBA.h"
  733.10 +#include "Reg.h"
  733.11 +#include "../common/movie.h"
  733.12 +#include <direct.h>
  733.13 +
  733.14 +#include "GSACodeSelect.h"
  733.15 +#include "../gba/GBACheats.h"
  733.16 +#include "../gb/gbCheats.h"
  733.17 +
  733.18 +// #undef WinDef macro garbage
  733.19 +#ifdef max
  733.20 +#undef max
  733.21 +#endif
  733.22 +
  733.23 +#ifdef min
  733.24 +#undef min
  733.25 +#endif
  733.26 +
  733.27 +using std::max;
  733.28 +using std::min;
  733.29 +
  733.30 +extern int emulating;
  733.31 +
  733.32 +extern const char IDS_ROM_DIR[]		= "romDir";
  733.33 +extern const char IDS_GBXROM_DIR[]	= "gbromDir";
  733.34 +extern const char IDS_BATTERY_DIR[]	= "batteryDir";
  733.35 +extern const char IDS_SAVE_DIR[]	= "saveDir";
  733.36 +extern const char IDS_MOVIE_DIR[]	= "moviesDir";
  733.37 +extern const char IDS_CHEAT_DIR[]	= "cheatsDir";
  733.38 +extern const char IDS_LUA_DIR[]		= "luaDir";
  733.39 +extern const char IDS_IPS_DIR[]		= "ipsDir";
  733.40 +extern const char IDS_AVI_DIR[]		= "aviRecordDir";
  733.41 +extern const char IDS_WAV_DIR[]		= "soundRecordDir";
  733.42 +extern const char IDS_CAPTURE_DIR[] = "captureDir";
  733.43 +extern const char IDS_WATCH_DIR[]	= "watchDir";
  733.44 +
  733.45 +extern const char IDS_ROM_DEFAULT_DIR[]		= "\\roms";
  733.46 +extern const char IDS_GBXROM_DEFAULT_DIR[]	= "\\gbroms";
  733.47 +extern const char IDS_BATTERY_DEFAULT_DIR[]	= "\\battery";
  733.48 +extern const char IDS_SAVE_DEFAULT_DIR[]	= "\\save";
  733.49 +extern const char IDS_MOVIE_DEFAULT_DIR[]	= "\\movies";
  733.50 +extern const char IDS_CHEAT_DEFAULT_DIR[]	= "\\cheats";
  733.51 +extern const char IDS_LUA_DEFAULT_DIR[]		= "\\lua";
  733.52 +extern const char IDS_IPS_DEFAULT_DIR[]		= "\\ips";
  733.53 +extern const char IDS_AVI_DEFAULT_DIR[]		= "\\avi";
  733.54 +extern const char IDS_WAV_DEFAULT_DIR[]		= "\\wav";
  733.55 +extern const char IDS_CAPTURE_DEFAULT_DIR[] = "\\screen";
  733.56 +extern const char IDS_WATCH_DEFAULT_DIR[]	= "\\watches";
  733.57 +
  733.58 +extern const char *IDS_tbl[] = {
  733.59 +	IDS_ROM_DIR,   IDS_GBXROM_DIR, IDS_BATTERY_DIR, IDS_SAVE_DIR, 
  733.60 +	IDS_MOVIE_DIR, IDS_CHEAT_DIR,  IDS_LUA_DIR,     IDS_IPS_DIR, 
  733.61 +	IDS_AVI_DIR,   IDS_WAV_DIR,    IDS_CAPTURE_DIR, IDS_WATCH_DIR
  733.62 +};
  733.63 +
  733.64 +extern const char *IDS_def_tbl[] = {
  733.65 +	IDS_ROM_DEFAULT_DIR,   IDS_GBXROM_DEFAULT_DIR, IDS_BATTERY_DEFAULT_DIR, IDS_SAVE_DEFAULT_DIR, 
  733.66 +	IDS_MOVIE_DEFAULT_DIR, IDS_CHEAT_DEFAULT_DIR,  IDS_LUA_DEFAULT_DIR,     IDS_IPS_DEFAULT_DIR, 
  733.67 +	IDS_AVI_DEFAULT_DIR,   IDS_WAV_DEFAULT_DIR,    IDS_CAPTURE_DEFAULT_DIR, IDS_WATCH_DEFAULT_DIR
  733.68 +};
  733.69 +
  733.70 +// these could be made VBA members, but  the VBA class is already oversized too much
  733.71 +//
  733.72 +
  733.73 +bool winFileExists(const CString &filename)
  733.74 +{
  733.75 +	FILE *f = fopen(filename, "rb");
  733.76 +	if (f)
  733.77 +	{
  733.78 +		fclose(f);
  733.79 +		return true;
  733.80 +	}
  733.81 +	return false;
  733.82 +}
  733.83 +
  733.84 +bool winIsDriveRoot(const CString &file)
  733.85 +{
  733.86 +	if (file.GetLength() == 3)
  733.87 +	{
  733.88 +		if (file[1] == ':' && file[2] == '\\')
  733.89 +			return true;
  733.90 +	}
  733.91 +	return false;
  733.92 +}
  733.93 +
  733.94 +CString winGetOriginalFilename(const CString &file)
  733.95 +{
  733.96 +	int index = file.Find('|');
  733.97 +
  733.98 +	if (index != -1)
  733.99 +		return file.Left(index);
 733.100 +	else
 733.101 +		return file;
 733.102 +}
 733.103 +
 733.104 +CString winGetDirFromFilename(const CString &file)
 733.105 +{
 733.106 +	CString temp  = winGetOriginalFilename(file);
 733.107 +	int		index = max(temp.ReverseFind('/'), temp.ReverseFind('\\'));
 733.108 +	if (index != -1)
 733.109 +	{
 733.110 +		temp = temp.Left(index);
 733.111 +		if (temp.GetLength() == 2 && temp[1] == ':')
 733.112 +			temp += "\\";
 733.113 +	}
 733.114 +
 733.115 +	return temp;
 733.116 +}
 733.117 +
 733.118 +CString winGetDestDir(const CString &TargetDirReg)
 733.119 +{
 733.120 +	CString targetDir = regQueryStringValue(TargetDirReg, NULL);
 733.121 +	int pos = targetDir.ReverseFind('\\');
 733.122 +	if (pos > 0 && pos == targetDir.GetLength() - 1)
 733.123 +		targetDir.Delete(pos);
 733.124 +
 733.125 +	// it makes no sense to create rom directories
 733.126 +	// see MainWnd::winFileOpenSelect for more info
 733.127 +	if (!TargetDirReg.Compare(IDS_ROM_DIR) || !TargetDirReg.Compare(IDS_GBXROM_DIR))
 733.128 +		return targetDir;
 733.129 +
 733.130 +	if (targetDir.IsEmpty())
 733.131 +	{
 733.132 +		targetDir = theApp.exeDir;		// reset the targetDir to the application's path
 733.133 +		if (!TargetDirReg.Compare(IDS_BATTERY_DIR))
 733.134 +		{
 733.135 +			targetDir += IDS_BATTERY_DEFAULT_DIR;
 733.136 +		}
 733.137 +		else if (!TargetDirReg.Compare(IDS_SAVE_DIR))
 733.138 +		{
 733.139 +			targetDir += IDS_SAVE_DEFAULT_DIR;
 733.140 +		}
 733.141 +		else if (!TargetDirReg.Compare(IDS_MOVIE_DIR))
 733.142 +		{
 733.143 +			targetDir += IDS_MOVIE_DEFAULT_DIR;
 733.144 +		}
 733.145 +		else if (!TargetDirReg.Compare(IDS_CHEAT_DIR))
 733.146 +		{
 733.147 +			targetDir += IDS_CHEAT_DEFAULT_DIR;
 733.148 +		}
 733.149 +		else if (!TargetDirReg.Compare(IDS_LUA_DIR))
 733.150 +		{
 733.151 +			targetDir += IDS_LUA_DEFAULT_DIR;
 733.152 +		}
 733.153 +		else if (!TargetDirReg.Compare(IDS_IPS_DIR))
 733.154 +		{
 733.155 +			targetDir += IDS_IPS_DEFAULT_DIR;
 733.156 +		}
 733.157 +		else if (!TargetDirReg.Compare(IDS_AVI_DIR))
 733.158 +		{
 733.159 +			targetDir += IDS_AVI_DEFAULT_DIR;
 733.160 +		}
 733.161 +		else if (!TargetDirReg.Compare(IDS_WAV_DIR))
 733.162 +		{
 733.163 +			targetDir += IDS_WAV_DEFAULT_DIR;
 733.164 +		}
 733.165 +		else if (!TargetDirReg.Compare(IDS_CAPTURE_DIR))
 733.166 +		{
 733.167 +			targetDir += IDS_CAPTURE_DEFAULT_DIR;
 733.168 +		}
 733.169 +		else if (!TargetDirReg.Compare(IDS_WATCH_DIR))
 733.170 +		{
 733.171 +			targetDir += IDS_WATCH_DEFAULT_DIR;
 733.172 +		}
 733.173 +		regSetStringValue(TargetDirReg, targetDir);	// Add the directory to the INI file
 733.174 +	}
 733.175 +
 733.176 +	_mkdir(targetDir);			// make the directory
 733.177 +
 733.178 +	return targetDir;
 733.179 +}
 733.180 +
 733.181 +CString winGetDestFilename(const CString &LogicalRomName, const CString &TargetDirReg, const CString &ext)
 733.182 +{
 733.183 +	if (LogicalRomName.GetLength() == 0)
 733.184 +		return CString();
 733.185 +
 733.186 +	CString targetDir = winGetDestDir(TargetDirReg);
 733.187 +	targetDir += '\\';
 733.188 +
 733.189 +	CString buffer = LogicalRomName;
 733.190 +
 733.191 +	int index = max(buffer.ReverseFind('/'), max(buffer.ReverseFind('\\'), buffer.ReverseFind('|')));
 733.192 +	if (index != -1)
 733.193 +		buffer = buffer.Right(buffer.GetLength() - index - 1);
 733.194 +
 733.195 +	index = buffer.ReverseFind('.');
 733.196 +	if (index != -1)
 733.197 +		buffer = buffer.Left(index);
 733.198 +
 733.199 +	CString filename;
 733.200 +	filename.Format("%s%s%s", targetDir, buffer, ext);
 733.201 +	bool fileExists = winFileExists(filename);
 733.202 +
 733.203 +	// check for old style of naming, for better backward compatibility
 733.204 +	if (!fileExists || theApp.filenamePreference == 0)
 733.205 +	{
 733.206 +		index = LogicalRomName.Find('|');
 733.207 +		if (index != -1)
 733.208 +		{
 733.209 +			buffer = LogicalRomName.Left(index);
 733.210 +			index  = max(buffer.ReverseFind('/'), buffer.ReverseFind('\\'));
 733.211 +
 733.212 +			int dotIndex = buffer.ReverseFind('.');
 733.213 +			if (dotIndex > index)
 733.214 +				buffer = buffer.Left(dotIndex);
 733.215 +
 733.216 +			if (index != -1)
 733.217 +				buffer = buffer.Right(buffer.GetLength() - index - 1);
 733.218 +
 733.219 +			CString filename2;
 733.220 +			filename2.Format("%s%s%s", targetDir, buffer, ext);
 733.221 +			bool file2Exists = winFileExists(filename2);
 733.222 +
 733.223 +			if ((file2Exists && !fileExists) || (theApp.filenamePreference == 0 && (file2Exists || !fileExists)))
 733.224 +				return filename2;
 733.225 +		}
 733.226 +	}
 733.227 +
 733.228 +	return filename;
 733.229 +}
 733.230 +
 733.231 +CString winGetSavestateFilename(const CString &LogicalRomName, int nID)
 733.232 +{
 733.233 +	CString		ext;
 733.234 +//	size_t		startindex;	// forget about C89/ANSI-C
 733.235 +//	size_t		endindex;
 733.236 +	if (VBAMovieActive() && theApp.AsscWithSaveState)
 733.237 +	{
 733.238 +		std::string fs(VBAMovieGetFilename());	// RVO tip
 733.239 +		size_t startindex = fs.find_last_of("/\\") ;
 733.240 +		if (startindex < fs.length())
 733.241 +			++startindex;	// luckily the found character can't be at the end of fs
 733.242 +		else
 733.243 +			startindex = 0;
 733.244 +		size_t endindex = fs.find_last_of(".");
 733.245 +		if (endindex < fs.length() && endindex > startindex)
 733.246 +			endindex;	//??
 733.247 +		else
 733.248 +			endindex = fs.length();
 733.249 +		fs = fs.substr(startindex, endindex - startindex);
 733.250 +		ext.Format("-%s-%d.sgm", fs.c_str(), nID);
 733.251 +	}
 733.252 +	else
 733.253 +	{
 733.254 +		ext.Format("%d.sgm", nID);
 733.255 +	}
 733.256 +	return winGetDestFilename(LogicalRomName, IDS_SAVE_DIR, ext);
 733.257 +}
 733.258 +
 733.259 +CString winGetSavestateMenuString(const CString &LogicalRomName, int nID)
 733.260 +{
 733.261 +	CString str;
 733.262 +	if (theApp.showSlotTime)
 733.263 +	{
 733.264 +		CFileStatus status;
 733.265 +		if (emulating && CFile::GetStatus(winGetSavestateFilename(LogicalRomName, nID), status))
 733.266 +		{
 733.267 +			str.Format("#&%d %s", nID, status.m_mtime.Format("%Y/%m/%d %H:%M:%S"));
 733.268 +		}
 733.269 +		else
 733.270 +		{
 733.271 +			str.Format("#&%d ----/--/-- --:--:--", nID);
 733.272 +		}
 733.273 +	}
 733.274 +	else
 733.275 +	{
 733.276 +		str.Format("Slot #&%d", nID);
 733.277 +	}
 733.278 +
 733.279 +	return str;
 733.280 +}
 733.281 +
 733.282 +void winCorrectPath(CString &path)
 733.283 +{
 733.284 +	if (winFileExists(path))
 733.285 +	{
 733.286 +		return;
 733.287 +	}
 733.288 +
 733.289 +	CString tempStr = theApp.exeDir;
 733.290 +	tempStr += "\\";
 733.291 +	tempStr += path;
 733.292 +
 733.293 +	if (winFileExists(tempStr))
 733.294 +	{
 733.295 +		path = tempStr;
 733.296 +		return;
 733.297 +	}
 733.298 +
 733.299 +	for (int i = 0; i < _countof(IDS_tbl); ++i)
 733.300 +	{
 733.301 +		tempStr = winGetDestDir(IDS_tbl[i]);
 733.302 +		tempStr += "\\";
 733.303 +		tempStr += path;
 733.304 +
 733.305 +		if (winFileExists(tempStr))
 733.306 +		{
 733.307 +			path = tempStr;
 733.308 +			return;
 733.309 +		}
 733.310 +	}
 733.311 +}
 733.312 +
 733.313 +void winCorrectPath(char *path)
 733.314 +{
 733.315 +	CString pathCStr(path);
 733.316 +	winCorrectPath(pathCStr);
 733.317 +	strcpy(path, pathCStr);
 733.318 +}
 733.319 +
 733.320 +// some file I/O
 733.321 +
 733.322 +int winScreenCapture(int captureNumber)
 733.323 +{
 733.324 +	CString ext;
 733.325 +	CString captureName;
 733.326 +
 733.327 +	do
 733.328 +	{
 733.329 +		if (theApp.captureFormat == 0)
 733.330 +			ext.Format("_%03d.png", captureNumber);
 733.331 +		else
 733.332 +			ext.Format("_%03d.bmp", captureNumber);
 733.333 +
 733.334 +		captureName = winGetDestFilename(theApp.gameFilename, IDS_CAPTURE_DIR, ext);
 733.335 +		++captureNumber;
 733.336 +	} while (winFileExists(captureName) && captureNumber > 0);
 733.337 +
 733.338 +	if (captureNumber < 0)
 733.339 +	{
 733.340 +		systemMessage(0, "Too many existing files (not less than %d)! Screen capture failed!", captureNumber - 1);
 733.341 +		return 0;
 733.342 +	}
 733.343 +
 733.344 +	if (theApp.captureFormat == 0)
 733.345 +		theApp.emulator.emuWritePNG(captureName);
 733.346 +	else
 733.347 +		theApp.emulator.emuWriteBMP(captureName);
 733.348 +
 733.349 +	systemScreenMessage(winResLoadString(IDS_SCREEN_CAPTURE));
 733.350 +
 733.351 +	return captureNumber;
 733.352 +}
 733.353 +
 733.354 +bool winImportGSACodeFile(CString &fileName)
 733.355 +{
 733.356 +	FILE *f = fopen(fileName, "rb");
 733.357 +
 733.358 +	if (f == NULL)
 733.359 +	{
 733.360 +		systemMessage(MSG_CANNOT_OPEN_FILE, "Cannot open file %s", fileName);
 733.361 +		return false;
 733.362 +	}
 733.363 +
 733.364 +	if (systemCartridgeType == 1)
 733.365 +	{
 733.366 +		fclose(f);
 733.367 +		return gbCheatReadGSCodeFile(fileName);
 733.368 +	}
 733.369 +
 733.370 +	u32 len;
 733.371 +	fread(&len, 1, 4, f);
 733.372 +	if (len != 14)
 733.373 +	{
 733.374 +		fclose(f);
 733.375 +		systemMessage(MSG_UNSUPPORTED_CODE_FILE, "Unsupported code file %s",
 733.376 +		              fileName);
 733.377 +		return false;
 733.378 +	}
 733.379 +	char buffer[16];
 733.380 +	fread(buffer, 1, 14, f);
 733.381 +	buffer[14] = 0;
 733.382 +	if (memcmp(buffer, "SharkPortCODES", 14))
 733.383 +	{
 733.384 +		fclose(f);
 733.385 +		systemMessage(MSG_UNSUPPORTED_CODE_FILE, "Unsupported code file %s",
 733.386 +		              fileName);
 733.387 +		return false;
 733.388 +	}
 733.389 +	fseek(f, 0x1e, SEEK_SET);
 733.390 +	fread(&len, 1, 4, f);
 733.391 +	int game = 0;
 733.392 +	if (len > 1)
 733.393 +	{
 733.394 +		GSACodeSelect dlg(f);
 733.395 +		game = dlg.DoModal();
 733.396 +	}
 733.397 +	fclose(f);
 733.398 +
 733.399 +	bool v3 = false;
 733.400 +
 733.401 +	int index = fileName.ReverseFind('.');
 733.402 +
 733.403 +	if (index != -1)
 733.404 +	{
 733.405 +		if (fileName.Right(3).CompareNoCase("XPC") == 0)
 733.406 +			v3 = true;
 733.407 +	}
 733.408 +
 733.409 +	if (game != -1)
 733.410 +	{
 733.411 +		return cheatsImportGSACodeFile(fileName, game, v3);
 733.412 +	}
 733.413 +
 733.414 +	return true;
 733.415 +}
 733.416 +
 733.417 +void winLoadCheatList(const char *name)
 733.418 +{
 733.419 +	bool res = false;
 733.420 +
 733.421 +	if (systemCartridgeType == 0)
 733.422 +		res = cheatsLoadCheatList(name);
 733.423 +	else
 733.424 +		res = gbCheatsLoadCheatList(name);
 733.425 +
 733.426 +	if (res)
 733.427 +		systemScreenMessage(winResLoadString(IDS_LOADED_CHEATS));
 733.428 +}
 733.429 +
 733.430 +void winSaveCheatList(const char *name)
 733.431 +{
 733.432 +	if (systemCartridgeType == 0)
 733.433 +		cheatsSaveCheatList(name);
 733.434 +	else
 733.435 +		gbCheatsSaveCheatList(name);
 733.436 +}
 733.437 +
 733.438 +void winLoadCheatListDefault()
 733.439 +{
 733.440 +	CString cheatName = winGetDestFilename(theApp.gameFilename, IDS_CHEAT_DIR, ".clt");
 733.441 +
 733.442 +	winLoadCheatList(cheatName);
 733.443 +}
 733.444 +
 733.445 +void winSaveCheatListDefault()
 733.446 +{
 733.447 +	CString cheatName = winGetDestFilename(theApp.gameFilename, IDS_CHEAT_DIR, ".clt");
 733.448 +
 733.449 +	winSaveCheatList(cheatName);
 733.450 +}
 733.451 +
 733.452 +bool winReadBatteryFile()
 733.453 +{
 733.454 +	CString batteryName = winGetDestFilename(theApp.gameFilename, IDS_BATTERY_DIR, ".sav");
 733.455 +
 733.456 +	bool res = false;
 733.457 +
 733.458 +	if (theApp.emulator.emuReadBattery)
 733.459 +		res = theApp.emulator.emuReadBattery(batteryName);
 733.460 +
 733.461 +	if (res)
 733.462 +		systemScreenMessage(winResLoadString(IDS_LOADED_BATTERY));
 733.463 +
 733.464 +	return res;
 733.465 +}
 733.466 +
 733.467 +bool winWriteBatteryFile()
 733.468 +{
 733.469 +	CString batteryName = winGetDestFilename(theApp.gameFilename, IDS_BATTERY_DIR, ".sav");
 733.470 +
 733.471 +	if (theApp.emulator.emuWriteBattery)
 733.472 +		return theApp.emulator.emuWriteBattery(batteryName);
 733.473 +
 733.474 +	return false;
 733.475 +}
 733.476 +
 733.477 +bool winEraseBatteryFile()
 733.478 +{
 733.479 +	CString batteryName = winGetDestFilename(theApp.gameFilename, IDS_BATTERY_DIR, ".sav");
 733.480 +	return !remove(batteryName);
 733.481 +}
 733.482 +
 733.483 +bool winReadSaveGame(const char *name)
 733.484 +{
 733.485 +	if (theApp.emulator.emuReadState)
 733.486 +		return theApp.emulator.emuReadState(name);
 733.487 +	return false;
 733.488 +}
 733.489 +
 733.490 +bool winWriteSaveGame(const char *name)
 733.491 +{
 733.492 +	if (theApp.emulator.emuWriteState)
 733.493 +		return theApp.emulator.emuWriteState(name);
 733.494 +	return false;
 733.495 +}
 733.496 +
 733.497 +bool winEraseSaveGame(const char *name)
 733.498 +{
 733.499 +	return !remove(name);
 733.500 +}
   734.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   734.2 +++ b/src/win32/WinMiscUtil.h	Sat Mar 03 10:31:27 2012 -0600
   734.3 @@ -0,0 +1,45 @@
   734.4 +#ifndef VBA_WIN32_WINMISCUTIL_H
   734.5 +#define VBA_WIN32_WINMISCUTIL_H
   734.6 +
   734.7 +#if _MSC_VER > 1000
   734.8 +#pragma once
   734.9 +#endif // _MSC_VER > 1000
  734.10 +
  734.11 +extern const char IDS_ROM_DIR[];
  734.12 +extern const char IDS_GBXROM_DIR[];
  734.13 +extern const char IDS_BATTERY_DIR[];
  734.14 +extern const char IDS_SAVE_DIR[];
  734.15 +extern const char IDS_MOVIE_DIR[];
  734.16 +extern const char IDS_CHEAT_DIR[];
  734.17 +extern const char IDS_LUA_DIR[];
  734.18 +extern const char IDS_IPS_DIR[];
  734.19 +extern const char IDS_AVI_DIR[];
  734.20 +extern const char IDS_WAV_DIR[];
  734.21 +extern const char IDS_CAPTURE_DIR[];
  734.22 +extern const char IDS_WATCH_DIR[];
  734.23 +
  734.24 +extern bool winFileExists(const CString &filename);
  734.25 +extern bool winIsDriveRoot(const CString &file);
  734.26 +extern CString winGetOriginalFilename(const CString &file);
  734.27 +extern CString winGetDirFromFilename(const CString &file);
  734.28 +extern CString winGetSavestateFilename(const CString &LogicalRomName, int nID);
  734.29 +extern CString winGetSavestateMenuString(const CString &LogicalRomName, int nID);
  734.30 +extern CString winGetDestDir(const CString &TargetDirReg);
  734.31 +extern CString winGetDestFilename(const CString &LogicalRomName, const CString &TargetDirReg, const CString &ext);
  734.32 +extern void winCorrectPath(CString &path);
  734.33 +extern void winCorrectPath(char *path);
  734.34 +
  734.35 +int winScreenCapture(int captureNumber = 0);
  734.36 +bool winImportGSACodeFile(CString& fileName);
  734.37 +void winLoadCheatList(const char *name);
  734.38 +void winSaveCheatList(const char *name);
  734.39 +void winLoadCheatListDefault();
  734.40 +void winSaveCheatListDefault();
  734.41 +bool winReadBatteryFile();
  734.42 +bool winWriteBatteryFile();
  734.43 +bool winEraseBatteryFile();
  734.44 +bool winReadSaveGame(const char *name);
  734.45 +bool winWriteSaveGame(const char *name);
  734.46 +bool winEraseSaveGame(const char *name);
  734.47 +
  734.48 +#endif // VBA_WIN32_WINMISCUTIL_H
   735.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   735.2 +++ b/src/win32/WinResUtil.cpp	Sat Mar 03 10:31:27 2012 -0600
   735.3 @@ -0,0 +1,99 @@
   735.4 +#include "stdafx.h"
   735.5 +#include "WinResUtil.h"
   735.6 +
   735.7 +static HINSTANCE winResGetInstance(LPCTSTR resType, LPCTSTR resName)
   735.8 +{
   735.9 +	// TODO: make language DLL first
  735.10 +	return AfxFindResourceHandle(resName, resType);
  735.11 +}
  735.12 +
  735.13 +UCHAR *winResGetResource(LPCTSTR resType, LPCTSTR resName)
  735.14 +{
  735.15 +	HINSTANCE winResInstance = winResGetInstance(resType, resName);
  735.16 +
  735.17 +	HRSRC hRsrc = FindResourceEx(winResInstance, resType, resName, 0);
  735.18 +
  735.19 +	if (hRsrc != NULL)
  735.20 +	{
  735.21 +		HGLOBAL hGlobal = LoadResource(winResInstance, hRsrc);
  735.22 +
  735.23 +		if (hGlobal != NULL)
  735.24 +		{
  735.25 +			UCHAR *b = (UCHAR *)LockResource(hGlobal);
  735.26 +
  735.27 +			return b;
  735.28 +		}
  735.29 +	}
  735.30 +	return NULL;
  735.31 +}
  735.32 +
  735.33 +HMENU winResLoadMenu(LPCTSTR menuName)
  735.34 +{
  735.35 +	UCHAR *b = winResGetResource(RT_MENU, menuName);
  735.36 +
  735.37 +	if (b != NULL)
  735.38 +	{
  735.39 +		HMENU menu = LoadMenuIndirect((CONST MENUTEMPLATE *)b);
  735.40 +
  735.41 +		if (menu != NULL)
  735.42 +			return menu;
  735.43 +	}
  735.44 +
  735.45 +	return LoadMenu(NULL, menuName);
  735.46 +}
  735.47 +
  735.48 +int winResDialogBox(LPCTSTR boxName, HWND parent, DLGPROC dlgProc, LPARAM lParam)
  735.49 +{
  735.50 +	/*
  735.51 +	   UCHAR * b = winResGetResource(RT_DIALOG, boxName);
  735.52 +
  735.53 +	   if(b != NULL) {
  735.54 +
  735.55 +	   return DialogBoxIndirectParam(hInstance,
  735.56 +	   (LPCDLGTEMPLATE)b,
  735.57 +	   parent,
  735.58 +	   dlgProc,
  735.59 +	   lParam);
  735.60 +	   }
  735.61 +
  735.62 +	   return DialogBoxParam(hInstance,
  735.63 +	   boxName,
  735.64 +	   parent,
  735.65 +	   dlgProc,
  735.66 +	   lParam);
  735.67 +	 */
  735.68 +	return 0;
  735.69 +}
  735.70 +
  735.71 +int winResDialogBox(LPCTSTR boxName, HWND parent, DLGPROC dlgProc)
  735.72 +{
  735.73 +	return winResDialogBox(boxName,
  735.74 +	                       parent,
  735.75 +	                       dlgProc,
  735.76 +	                       0);
  735.77 +}
  735.78 +
  735.79 +CString winResLoadString(UINT id)
  735.80 +{
  735.81 +	int       stId = id / 16 + 1;
  735.82 +	HINSTANCE inst = winResGetInstance(RT_STRING, MAKEINTRESOURCE(stId));
  735.83 +
  735.84 +	CString res;
  735.85 +	if (!res.LoadString(id))
  735.86 +	{
  735.87 +		// TODO: handle case where string is only in the default English
  735.88 +		res = "";
  735.89 +	}
  735.90 +
  735.91 +	res.Replace('_', '|');
  735.92 +
  735.93 +	return res;
  735.94 +}
  735.95 +
  735.96 +CString winResLoadFilter(UINT id)
  735.97 +{
  735.98 +	CString res = winResLoadString(id);
  735.99 +	res.Replace('_', '|');
 735.100 +
 735.101 +	return res;
 735.102 +}
   736.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   736.2 +++ b/src/win32/WinResUtil.h	Sat Mar 03 10:31:27 2012 -0600
   736.3 @@ -0,0 +1,14 @@
   736.4 +#ifndef VBA_WIN32_WINRESUTIL_H
   736.5 +#define VBA_WIN32_WINRESUTIL_H
   736.6 +
   736.7 +#if _MSC_VER > 1000
   736.8 +#pragma once
   736.9 +#endif // _MSC_VER > 1000
  736.10 +
  736.11 +extern HMENU winResLoadMenu(LPCTSTR menuName);
  736.12 +extern int winResDialogBox(LPCTSTR boxName, HWND parent, DLGPROC dlgProc);
  736.13 +extern int winResDialogBox(LPCTSTR boxName, HWND parent, DLGPROC dlgProc, LPARAM lParam);
  736.14 +extern CString winResLoadString(UINT id);
  736.15 +extern CString winResLoadFilter(UINT id);
  736.16 +
  736.17 +#endif // VBA_WIN32_WINRESUTIL_H
   737.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   737.2 +++ b/src/win32/ZoomControl.cpp	Sat Mar 03 10:31:27 2012 -0600
   737.3 @@ -0,0 +1,166 @@
   737.4 +// ZoomControl.cpp : implementation file
   737.5 +//
   737.6 +
   737.7 +#include "stdafx.h"
   737.8 +#include "ZoomControl.h"
   737.9 +
  737.10 +bool ZoomControl::isRegistered = false;
  737.11 +
  737.12 +/////////////////////////////////////////////////////////////////////////////
  737.13 +// ZoomControl
  737.14 +
  737.15 +ZoomControl::ZoomControl()
  737.16 +{
  737.17 +	ZeroMemory(colors, 3*64);
  737.18 +	selected = -1;
  737.19 +	registerClass();
  737.20 +}
  737.21 +
  737.22 +ZoomControl::~ZoomControl()
  737.23 +{}
  737.24 +
  737.25 +BEGIN_MESSAGE_MAP(ZoomControl, CWnd)
  737.26 +//{{AFX_MSG_MAP(ZoomControl)
  737.27 +ON_WM_PAINT()
  737.28 +ON_WM_LBUTTONDOWN()
  737.29 +ON_WM_ERASEBKGND()
  737.30 +//}}AFX_MSG_MAP
  737.31 +END_MESSAGE_MAP()
  737.32 +
  737.33 +/////////////////////////////////////////////////////////////////////////////
  737.34 +// ZoomControl message handlers
  737.35 +
  737.36 +void ZoomControl::registerClass()
  737.37 +{
  737.38 +	if (!isRegistered)
  737.39 +	{
  737.40 +		WNDCLASS wc;
  737.41 +		ZeroMemory(&wc, sizeof(wc));
  737.42 +		wc.style         = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
  737.43 +		wc.lpfnWndProc   = (WNDPROC) ::DefWindowProc;
  737.44 +		wc.hInstance     = AfxGetInstanceHandle();
  737.45 +		wc.hIcon         = NULL;
  737.46 +		wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  737.47 +		wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  737.48 +		wc.lpszMenuName  = NULL;
  737.49 +		wc.lpszClassName = "VbaZoomControl";
  737.50 +		AfxRegisterClass(&wc);
  737.51 +		isRegistered = true;
  737.52 +	}
  737.53 +}
  737.54 +
  737.55 +void ZoomControl::OnPaint()
  737.56 +{
  737.57 +	CPaintDC dc(this); // device context for painting
  737.58 +
  737.59 +	RECT rect;
  737.60 +	GetClientRect(&rect);
  737.61 +
  737.62 +	int w = rect.right - rect.left;
  737.63 +	int h = rect.bottom - rect.top;
  737.64 +
  737.65 +	CDC memDC ;
  737.66 +	memDC.CreateCompatibleDC(&dc);
  737.67 +	CBitmap bitmap, *pOldBitmap;
  737.68 +	bitmap.CreateCompatibleBitmap(&dc, w, h);
  737.69 +
  737.70 +	pOldBitmap = memDC.SelectObject(&bitmap);
  737.71 +
  737.72 +	int multX = w / 8;
  737.73 +	int multY = h / 8;
  737.74 +
  737.75 +	int i;
  737.76 +	for (i = 0; i < 64; i++)
  737.77 +	{
  737.78 +		CBrush b;
  737.79 +		b.CreateSolidBrush(RGB(colors[i*3+2], colors[i*3+1], colors[i*3]));
  737.80 +
  737.81 +		RECT r;
  737.82 +		int  x = i & 7;
  737.83 +		int  y = i / 8;
  737.84 +		r.top    = y*multY;
  737.85 +		r.left   = x*multX;
  737.86 +		r.bottom = r.top + multY;
  737.87 +		r.right  = r.left + multX;
  737.88 +		memDC.FillRect(&r, &b);
  737.89 +		b.DeleteObject();
  737.90 +	}
  737.91 +
  737.92 +	CPen pen;
  737.93 +	pen.CreatePen(PS_SOLID, 1, RGB(192, 192, 192));
  737.94 +	CPen *old = (CPen *)memDC.SelectObject(&pen);
  737.95 +
  737.96 +	for (i = 0; i < 8; i++)
  737.97 +	{
  737.98 +		memDC.MoveTo(0, i * multY);
  737.99 +		memDC.LineTo(w, i * multY);
 737.100 +		memDC.MoveTo(i * multX, 0);
 737.101 +		memDC.LineTo(i * multX, h);
 737.102 +	}
 737.103 +
 737.104 +	if (selected != -1)
 737.105 +	{
 737.106 +		CPen pen2;
 737.107 +		pen2.CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
 737.108 +		CPen *old2 = (CPen *)memDC.SelectObject(&pen2);
 737.109 +
 737.110 +		int startX = (selected & 7)*multX+1;
 737.111 +		int startY = (selected / 8)*multY+1;
 737.112 +		int endX   = startX + multX-2;
 737.113 +		int endY   = startY + multY-2;
 737.114 +
 737.115 +		memDC.MoveTo(startX, startY);
 737.116 +		memDC.LineTo(endX, startY);
 737.117 +		memDC.LineTo(endX, endY);
 737.118 +		memDC.LineTo(startX, endY);
 737.119 +		memDC.LineTo(startX, startY-1);
 737.120 +		memDC.SelectObject(old2);
 737.121 +		pen2.DeleteObject();
 737.122 +	}
 737.123 +	memDC.SelectObject(old);
 737.124 +	pen.DeleteObject();
 737.125 +
 737.126 +	dc.BitBlt(0, 0, w, h,
 737.127 +	          &memDC, 0, 0, SRCCOPY);
 737.128 +
 737.129 +	memDC.SelectObject(pOldBitmap);
 737.130 +	bitmap.DeleteObject();
 737.131 +	memDC.DeleteDC();
 737.132 +}
 737.133 +
 737.134 +void ZoomControl::OnLButtonDown(UINT nFlags, CPoint point)
 737.135 +{
 737.136 +	RECT rect;
 737.137 +	GetClientRect(&rect);
 737.138 +
 737.139 +	int height = rect.bottom - rect.top;
 737.140 +	int width  = rect.right - rect.left;
 737.141 +
 737.142 +	int multX = width / 8;
 737.143 +	int multY = height / 8;
 737.144 +
 737.145 +	selected = point.x / multX + 8 * (point.y / multY);
 737.146 +
 737.147 +	int c     = point.x / multX + 8 * (point.y/multY);
 737.148 +	u16 color = colors[c*3] << 7 |
 737.149 +	            colors[c*3+1] << 2 |
 737.150 +	            (colors[c*3+2] >> 3);
 737.151 +
 737.152 +	GetParent()->PostMessage(WM_COLINFO,
 737.153 +	                         color,
 737.154 +	                         0);
 737.155 +
 737.156 +	Invalidate();
 737.157 +}
 737.158 +
 737.159 +BOOL ZoomControl::OnEraseBkgnd(CDC*pDC)
 737.160 +{
 737.161 +	return TRUE;
 737.162 +}
 737.163 +
 737.164 +void ZoomControl::setColors(const u8 *c)
 737.165 +{
 737.166 +	memcpy(colors, c, 3*64);
 737.167 +	selected = -1;
 737.168 +	Invalidate();
 737.169 +}
   738.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   738.2 +++ b/src/win32/ZoomControl.h	Sat Mar 03 10:31:27 2012 -0600
   738.3 @@ -0,0 +1,56 @@
   738.4 +#if !defined(AFX_ZOOMCONTROL_H__BC193230_D2D6_4240_93AE_28C2EF2C641A__INCLUDED_)
   738.5 +#define AFX_ZOOMCONTROL_H__BC193230_D2D6_4240_93AE_28C2EF2C641A__INCLUDED_
   738.6 +
   738.7 +#if _MSC_VER > 1000
   738.8 +#pragma once
   738.9 +#endif // _MSC_VER > 1000
  738.10 +// ZoomControl.h : header file
  738.11 +//
  738.12 +#ifndef WM_COLINFO
  738.13 +#define WM_COLINFO WM_APP+100
  738.14 +#endif
  738.15 +
  738.16 +/////////////////////////////////////////////////////////////////////////////
  738.17 +// ZoomControl window
  738.18 +
  738.19 +class ZoomControl : public CWnd
  738.20 +{
  738.21 +	// Construction
  738.22 +public:
  738.23 +	ZoomControl();
  738.24 +
  738.25 +	// Attributes
  738.26 +public:
  738.27 +	// Operations
  738.28 +public:
  738.29 +	// Overrides
  738.30 +	// ClassWizard generated virtual function overrides
  738.31 +	//{{AFX_VIRTUAL(ZoomControl)
  738.32 +	//}}AFX_VIRTUAL
  738.33 +
  738.34 +	// Implementation
  738.35 +public:
  738.36 +	void setColors(const u8 *c);
  738.37 +	static bool isRegistered;
  738.38 +	virtual ~ZoomControl();
  738.39 +
  738.40 +	// Generated message map functions
  738.41 +protected:
  738.42 +	//{{AFX_MSG(ZoomControl)
  738.43 +	afx_msg void OnPaint();
  738.44 +	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  738.45 +	afx_msg BOOL OnEraseBkgnd(CDC*pDC);
  738.46 +	//}}AFX_MSG
  738.47 +	DECLARE_MESSAGE_MAP()
  738.48 +private:
  738.49 +	int selected;
  738.50 +	u8  colors[3*64];
  738.51 +	void registerClass();
  738.52 +};
  738.53 +
  738.54 +/////////////////////////////////////////////////////////////////////////////
  738.55 +
  738.56 +//{{AFX_INSERT_LOCATION}}
  738.57 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  738.58 +
  738.59 +#endif // !defined(AFX_ZOOMCONTROL_H__BC193230_D2D6_4240_93AE_28C2EF2C641A__INCLUDED_)
   739.1 Binary file src/win32/gbadvance.ico has changed
   740.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   740.2 +++ b/src/win32/ram_search.cpp	Sat Mar 03 10:31:27 2012 -0600
   740.3 @@ -0,0 +1,2127 @@
   740.4 +// A few notes about this implementation of a RAM search window:
   740.5 +//
   740.6 +// Speed of update was one of the highest priories.
   740.7 +// This is because I wanted the RAM search window to be able to
   740.8 +// update every single value in RAM every single frame, and
   740.9 +// keep track of the exact number of frames across which each value has changed,
  740.10 +// without causing the emulation to run noticeably slower than normal.
  740.11 +//
  740.12 +// The data representation was changed from one entry per valid address
  740.13 +// to one entry per contiguous range of uneliminated addresses
  740.14 +// which references uniform pools of per-address properties.
  740.15 +// - This saves time when there are many items because
  740.16 +//   it minimizes the amount of data that needs to be stored and processed per address.
  740.17 +// - It also saves time when there are few items because
  740.18 +//   it ensures that no time is wasted in iterating through
  740.19 +//   addresses that have already been eliminated from the search.
  740.20 +//
  740.21 +// The worst-case scenario is when every other item has been
  740.22 +// eliminated from the search, maximizing the number of regions.
  740.23 +// This implementation manages to handle even that pathological case
  740.24 +// acceptably well. In fact, it still updates faster than the previous implementation.
  740.25 +// The time spent setting up or clearing such a large number of regions
  740.26 +// is somewhat horrendous, but it seems reasonable to have poor worst-case speed
  740.27 +// during these sporadic "setup" steps to achieve an all-around faster per-update speed.
  740.28 +// (You can test this case by performing the search: Modulo 2 Is Specific Address 0)
  740.29 +
  740.30 +
  740.31 +#ifdef _WIN32
  740.32 +	#include "stdafx.h"
  740.33 +	#include "resource.h"
  740.34 +	#include "VBA.h"
  740.35 +	//#include <windows.h>
  740.36 +	#include <commctrl.h>
  740.37 +	#include "BaseTsd.h"
  740.38 +	#include "GBACheatsDlg.h"
  740.39 +	#include "GBCheatsDlg.h"
  740.40 +	typedef INT_PTR intptr_t;
  740.41 +#else
  740.42 +	#include "stdint.h"
  740.43 +#endif
  740.44 +#include <cassert>
  740.45 +#include <list>
  740.46 +#include <vector>
  740.47 +
  740.48 +#include "ram_search.h"
  740.49 +#include "ramwatch.h"
  740.50 +#include "../gba/GBAGlobals.h"
  740.51 +#include "../gb/gbGlobals.h"
  740.52 +#include "../common/vbalua.h"
  740.53 +#include "Reg.h"
  740.54 +
  740.55 +static inline u8* HardwareToSoftwareAddress(HWAddressType address)
  740.56 +{
  740.57 +	if(!emulating)
  740.58 +		return NULL;
  740.59 +
  740.60 +	// note: this currently follows the "quick" memory rules,
  740.61 +	// meaning it will miss whatever special cases aren't handled by read/writeMemoryQuick.
  740.62 +	// if this is made more accurate, it may be necessary to reduce regionSearchGranularity.
  740.63 +	if(systemCartridgeType == 0)
  740.64 +	{
  740.65 +		// GBA
  740.66 +		HWAddressType mask = ::map[address >> 24].mask;
  740.67 +		if(!mask || (address & 0xFFFFFF) > mask)
  740.68 +			return NULL;
  740.69 +		return &::map[address >> 24].address[address & mask];
  740.70 +	}
  740.71 +	else
  740.72 +	{
  740.73 +		// GB
  740.74 +		extern int32 gbEchoRAMFixOn;
  740.75 +		if (gbEchoRAMFixOn)
  740.76 +			if (address >= 0xe000 && address < 0xfe00)
  740.77 +				address -= 0x2000;
  740.78 +		if((address>>12) >= sizeof(gbMemoryMap)/sizeof(*gbMemoryMap))
  740.79 +			return NULL;
  740.80 +		return &gbMemoryMap[address>>12][address&0xfff];
  740.81 +	}
  740.82 +}
  740.83 +
  740.84 +
  740.85 +struct MemoryRegion
  740.86 +{
  740.87 +	HWAddressType hardwareAddress; // hardware address of the start of this region
  740.88 +	unsigned int size; // number of bytes to the end of this region
  740.89 +	unsigned char* softwareAddress; // pointer to the start of the live emulator source values for this region
  740.90 +
  740.91 +	unsigned int virtualIndex; // index into s_prevValues, s_curValues, and s_numChanges, valid after being initialized in ResetMemoryRegions()
  740.92 +	unsigned int itemIndex; // index into listbox items, valid when s_itemIndicesInvalid is false
  740.93 +};
  740.94 +
  740.95 +int MAX_RAM_SIZE = 0;
  740.96 +static unsigned char* s_prevValues = 0; // values at last search or reset
  740.97 +static unsigned char* s_curValues = 0; // values at last frame update
  740.98 +static unsigned short* s_numChanges = 0; // number of changes of the item starting at this virtual index address
  740.99 +static MemoryRegion** s_itemIndexToRegionPointer = 0; // used for random access into the memory list (trading memory size to get speed here, too bad it's so much memory), only valid when s_itemIndicesInvalid is false
 740.100 +static BOOL s_itemIndicesInvalid = true; // if true, the link from listbox items to memory regions (s_itemIndexToRegionPointer) and the link from memory regions to list box items (MemoryRegion::itemIndex) both need to be recalculated
 740.101 +static BOOL s_prevValuesNeedUpdate = true; // if true, the "prev" values should be updated using the "cur" values on the next frame update signaled
 740.102 +static unsigned int s_maxItemIndex = 0; // max currently valid item index, the listbox sometimes tries to update things past the end of the list so we need to know this to ignore those attempts
 740.103 +static int s_prevSelCount = -1;
 740.104 +
 740.105 +HWND RamSearchHWnd;
 740.106 +#define hWnd AfxGetMainWnd()->GetSafeHwnd()
 740.107 +#define hInst AfxGetInstanceHandle()
 740.108 +static char Str_Tmp [1024];
 740.109 +
 740.110 +int disableRamSearchUpdate = false;
 740.111 +
 740.112 +
 740.113 +
 740.114 +//static const MemoryRegion s_prgRegion    = {  0x020000, SEGACD_RAM_PRG_SIZE, (unsigned char*)Ram_Prg,     true};
 740.115 +//static const MemoryRegion s_word1MRegion = {  0x200000, SEGACD_1M_RAM_SIZE,  (unsigned char*)Ram_Word_1M, true};
 740.116 +//static const MemoryRegion s_word2MRegion = {  0x200000, SEGACD_2M_RAM_SIZE,  (unsigned char*)Ram_Word_2M, true};
 740.117 +//static const MemoryRegion s_z80Region    = {  0xA00000, Z80_RAM_SIZE,        (unsigned char*)Ram_Z80,     true};
 740.118 +//static const MemoryRegion s_68kRegion    = {  0xFF0000, _68K_RAM_SIZE,       (unsigned char*)Ram_68k,     true};
 740.119 +//static const MemoryRegion s_32xRegion    = {0x06000000, _32X_RAM_SIZE,       (unsigned char*)_32X_Ram,    false};
 740.120 +
 740.121 +// list of contiguous uneliminated memory regions
 740.122 +typedef std::list<MemoryRegion> MemoryList;
 740.123 +static MemoryList s_activeMemoryRegions;
 740.124 +static CRITICAL_SECTION s_activeMemoryRegionsCS;
 740.125 +
 740.126 +// for undo support (could be better, but this way was really easy)
 740.127 +static MemoryList s_activeMemoryRegionsBackup;
 740.128 +static int s_undoType = 0; // 0 means can't undo, 1 means can undo, 2 means can redo
 740.129 +
 740.130 +void RamSearchSaveUndoStateIfNotTooBig(HWND hDlg);
 740.131 +static const int tooManyRegionsForUndo = 10000;
 740.132 +
 740.133 +void ResetMemoryRegions()
 740.134 +{
 740.135 +	systemSoundClearBuffer();
 740.136 +	EnterCriticalSection(&s_activeMemoryRegionsCS);
 740.137 +
 740.138 +	s_activeMemoryRegions.clear();
 740.139 +
 740.140 +	// use HardwareToSoftwareAddress to figure out what all the possible memory regions are,
 740.141 +	// split up wherever there's a discontinuity in the address in our software RAM.
 740.142 +	static const int regionSearchGranularity = 0x100; // if this is too small, we'll waste time (in this function only), but if any region in RAM isn't evenly divisible by this, we might crash.
 740.143 +	HWAddressType hwRegionStart = 0;
 740.144 +	u8* regionStart = NULL;
 740.145 +	u8* regionEnd = NULL;
 740.146 +	for(HWAddressType addr = 0; addr != 0x10000000+regionSearchGranularity; addr += regionSearchGranularity)
 740.147 +	{
 740.148 +		u8* swAddr = HardwareToSoftwareAddress(addr);
 740.149 +		if(regionEnd && swAddr != regionEnd+regionSearchGranularity)
 740.150 +		{
 740.151 +			// hit end of region
 740.152 +			// check to see if it mirrors an existing one (in which case we discard it)
 740.153 +			bool discard = false;
 740.154 +			for(MemoryList::iterator iter = s_activeMemoryRegions.begin(); iter != s_activeMemoryRegions.end(); ++iter)
 740.155 +			{
 740.156 +				MemoryRegion& region = *iter;
 740.157 +				if(region.softwareAddress == regionStart)
 740.158 +				{
 740.159 +					unsigned int size = regionSearchGranularity + (regionEnd - regionStart);
 740.160 +					if(size <= region.size)
 740.161 +					{
 740.162 +						discard = true;
 740.163 +					}
 740.164 +					else
 740.165 +					{
 740.166 +						hwRegionStart += region.size;
 740.167 +						regionStart += region.size;
 740.168 +					}
 740.169 +					break;
 740.170 +				}
 740.171 +			}
 740.172 +			
 740.173 +			// don't include ROM in our RAM search (it's too huge)
 740.174 +			if(regionStart == rom || regionStart == gbRom)
 740.175 +				discard = true;
 740.176 +
 740.177 +			// create the region
 740.178 +			if(!discard)
 740.179 +			{
 740.180 +				MemoryRegion region = { hwRegionStart, regionSearchGranularity + (regionEnd - regionStart), regionStart };
 740.181 +				s_activeMemoryRegions.push_back(region);
 740.182 +			}
 740.183 +
 740.184 +			hwRegionStart = 0;
 740.185 +			regionStart = NULL;
 740.186 +			regionEnd = NULL;
 740.187 +		}
 740.188 +		if(swAddr)
 740.189 +		{
 740.190 +			if(regionStart)
 740.191 +			{
 740.192 +				// continue region
 740.193 +				regionEnd = swAddr;
 740.194 +			}
 740.195 +			else
 740.196 +			{
 740.197 +				// start new region
 740.198 +				hwRegionStart = addr;
 740.199 +				regionStart = swAddr;
 740.200 +				regionEnd = swAddr;
 740.201 +			}
 740.202 +		}
 740.203 +	}
 740.204 +
 740.205 +
 740.206 +	int nextVirtualIndex = 0;
 740.207 +	for(MemoryList::iterator iter = s_activeMemoryRegions.begin(); iter != s_activeMemoryRegions.end(); ++iter)
 740.208 +	{
 740.209 +		MemoryRegion& region = *iter;
 740.210 +		region.virtualIndex = nextVirtualIndex;
 740.211 +		assert(((intptr_t)region.softwareAddress & 1) == 0 && "somebody needs to reimplement ReadValueAtSoftwareAddress()");
 740.212 +		nextVirtualIndex = region.virtualIndex + region.size;
 740.213 +	}
 740.214 +	//assert(nextVirtualIndex <= MAX_RAM_SIZE);
 740.215 +
 740.216 +	if(nextVirtualIndex > MAX_RAM_SIZE)
 740.217 +	{
 740.218 +		s_prevValues = (unsigned char*)realloc(s_prevValues, sizeof(char)*(nextVirtualIndex+4));
 740.219 +		memset(s_prevValues, 0, sizeof(char)*(nextVirtualIndex+4));
 740.220 +
 740.221 +		s_curValues = (unsigned char*)realloc(s_curValues, sizeof(char)*(nextVirtualIndex+4));
 740.222 +		memset(s_curValues, 0, sizeof(char)*(nextVirtualIndex+4));
 740.223 +
 740.224 +		s_numChanges = (unsigned short*)realloc(s_numChanges, sizeof(short)*(nextVirtualIndex+4));
 740.225 +		memset(s_numChanges, 0, sizeof(short)*(nextVirtualIndex+4));
 740.226 +
 740.227 +		s_itemIndexToRegionPointer = (MemoryRegion**)realloc(s_itemIndexToRegionPointer, sizeof(MemoryRegion*)*(nextVirtualIndex+4));
 740.228 +		memset(s_itemIndexToRegionPointer, 0, sizeof(MemoryRegion*)*(nextVirtualIndex+4));
 740.229 +
 740.230 +		MAX_RAM_SIZE = nextVirtualIndex;
 740.231 +	}
 740.232 +	LeaveCriticalSection(&s_activeMemoryRegionsCS);
 740.233 +}
 740.234 +
 740.235 +// eliminates a range of hardware addresses from the search results
 740.236 +// returns 2 if it changed the region and moved the iterator to another region
 740.237 +// returns 1 if it changed the region but didn't move the iterator
 740.238 +// returns 0 if it had no effect
 740.239 +// warning: don't call anything that takes an itemIndex in a loop that calls DeactivateRegion...
 740.240 +//   doing so would be tremendously slow because DeactivateRegion invalidates the index cache
 740.241 +int DeactivateRegion(MemoryRegion& region, MemoryList::iterator& iter, HWAddressType hardwareAddress, unsigned int size)
 740.242 +{
 740.243 +	if(hardwareAddress + size <= region.hardwareAddress || hardwareAddress >= region.hardwareAddress + region.size)
 740.244 +	{
 740.245 +		// region is unaffected
 740.246 +		return 0;
 740.247 +	}
 740.248 +	else if(hardwareAddress > region.hardwareAddress && hardwareAddress + size >= region.hardwareAddress + region.size)
 740.249 +	{
 740.250 +		// erase end of region
 740.251 +		region.size = hardwareAddress - region.hardwareAddress;
 740.252 +		return 1;
 740.253 +	}
 740.254 +	else if(hardwareAddress <= region.hardwareAddress && hardwareAddress + size < region.hardwareAddress + region.size)
 740.255 +	{
 740.256 +		// erase start of region
 740.257 +		int eraseSize = (hardwareAddress + size) - region.hardwareAddress;
 740.258 +		region.hardwareAddress += eraseSize;
 740.259 +		region.size -= eraseSize;
 740.260 +		region.softwareAddress += eraseSize;
 740.261 +		region.virtualIndex += eraseSize;
 740.262 +		return 1;
 740.263 +	}
 740.264 +	else if(hardwareAddress <= region.hardwareAddress && hardwareAddress + size >= region.hardwareAddress + region.size)
 740.265 +	{
 740.266 +		// erase entire region
 740.267 +		iter = s_activeMemoryRegions.erase(iter);
 740.268 +		s_itemIndicesInvalid = TRUE;
 740.269 +		return 2;
 740.270 +	}
 740.271 +	else //if(hardwareAddress > region.hardwareAddress && hardwareAddress + size < region.hardwareAddress + region.size)
 740.272 +	{
 740.273 +		// split region
 740.274 +		int eraseSize = (hardwareAddress + size) - region.hardwareAddress;
 740.275 +		MemoryRegion region2 = {region.hardwareAddress + eraseSize, region.size - eraseSize, region.softwareAddress + eraseSize, region.virtualIndex + eraseSize};
 740.276 +		region.size = hardwareAddress - region.hardwareAddress;
 740.277 +		iter = s_activeMemoryRegions.insert(++iter, region2);
 740.278 +		s_itemIndicesInvalid = TRUE;
 740.279 +		return 2;
 740.280 +	}
 740.281 +}
 740.282 +
 740.283 +/*
 740.284 +// eliminates a range of hardware addresses from the search results
 740.285 +// this is a simpler but usually slower interface for the above function
 740.286 +void DeactivateRegion(HWAddressType hardwareAddress, unsigned int size)
 740.287 +{
 740.288 +	for(MemoryList::iterator iter = s_activeMemoryRegions.begin(); iter != s_activeMemoryRegions.end(); )
 740.289 +	{
 740.290 +		MemoryRegion& region = *iter;
 740.291 +		if(2 != DeactivateRegion(region, iter, hardwareAddress, size))
 740.292 +			++iter;
 740.293 +	}
 740.294 +}
 740.295 +*/
 740.296 +
 740.297 +struct AutoCritSect
 740.298 +{
 740.299 +	AutoCritSect(CRITICAL_SECTION* cs) : m_cs(cs) { EnterCriticalSection(m_cs); }
 740.300 +	~AutoCritSect() { LeaveCriticalSection(m_cs); }
 740.301 +	CRITICAL_SECTION* m_cs;
 740.302 +};
 740.303 +
 740.304 +// warning: can be slow
 740.305 +void CalculateItemIndices(int itemSize)
 740.306 +{
 740.307 +	AutoCritSect cs(&s_activeMemoryRegionsCS);
 740.308 +	unsigned int itemIndex = 0;
 740.309 +	for(MemoryList::iterator iter = s_activeMemoryRegions.begin(); iter != s_activeMemoryRegions.end(); ++iter)
 740.310 +	{
 740.311 +		MemoryRegion& region = *iter;
 740.312 +		region.itemIndex = itemIndex;
 740.313 +		int startSkipSize = ((unsigned int)(itemSize - (unsigned int)region.hardwareAddress)) % itemSize; // FIXME: is this still ok?
 740.314 +		unsigned int start = startSkipSize;
 740.315 +		unsigned int end = region.size;
 740.316 +		for(unsigned int i = start; i < end; i += itemSize)
 740.317 +			s_itemIndexToRegionPointer[itemIndex++] = &region;
 740.318 +	}
 740.319 +	s_maxItemIndex = itemIndex;
 740.320 +	s_itemIndicesInvalid = FALSE;
 740.321 +}
 740.322 +
 740.323 +template<typename stepType, typename compareType>
 740.324 +void UpdateRegionT(const MemoryRegion& region, const MemoryRegion* nextRegionPtr)
 740.325 +{
 740.326 +	//if(GetAsyncKeyState(VK_SHIFT) & 0x8000) // speed hack
 740.327 +	//	return;
 740.328 +
 740.329 +	if(s_prevValuesNeedUpdate)
 740.330 +		memcpy(s_prevValues + region.virtualIndex, s_curValues + region.virtualIndex, region.size + sizeof(compareType) - sizeof(stepType));
 740.331 +
 740.332 +	unsigned int startSkipSize = ((unsigned int)(sizeof(stepType) - region.hardwareAddress)) % sizeof(stepType);
 740.333 +
 740.334 +
 740.335 +	unsigned char* sourceAddr = region.softwareAddress - region.virtualIndex;
 740.336 +
 740.337 +	unsigned int indexStart = region.virtualIndex + startSkipSize;
 740.338 +	unsigned int indexEnd = region.virtualIndex + region.size;
 740.339 +
 740.340 +	if(sizeof(compareType) == 1)
 740.341 +	{
 740.342 +		for(unsigned int i = indexStart; i < indexEnd; i++)
 740.343 +		{
 740.344 +			if(s_curValues[i] != sourceAddr[i]) // if value changed
 740.345 +			{
 740.346 +				s_curValues[i] = sourceAddr[i]; // update value
 740.347 +				//if(s_numChanges[i] != 0xFFFF)
 740.348 +					s_numChanges[i]++; // increase change count
 740.349 +			}
 740.350 +		}
 740.351 +	}
 740.352 +	else // it's more complicated for non-byte sizes because:
 740.353 +	{    // - more than one byte can affect a given change count entry
 740.354 +	     // - when more than one of those bytes changes simultaneously the entry's change count should only increase by 1
 740.355 +	     // - a few of those bytes can be outside the region
 740.356 +
 740.357 +		unsigned int endSkipSize = ((unsigned int)(startSkipSize - region.size)) % sizeof(stepType);
 740.358 +		unsigned int lastIndexToRead = indexEnd + endSkipSize + sizeof(compareType) - sizeof(stepType);
 740.359 +		unsigned int lastIndexToCopy = lastIndexToRead;
 740.360 +		if(nextRegionPtr)
 740.361 +		{
 740.362 +			const MemoryRegion& nextRegion = *nextRegionPtr;
 740.363 +			int nextStartSkipSize = ((unsigned int)(sizeof(stepType) - nextRegion.hardwareAddress)) % sizeof(stepType);
 740.364 +			unsigned int nextIndexStart = nextRegion.virtualIndex + nextStartSkipSize;
 740.365 +			if(lastIndexToCopy > nextIndexStart)
 740.366 +				lastIndexToCopy = nextIndexStart;
 740.367 +		}
 740.368 +
 740.369 +		unsigned int nextValidChange [sizeof(compareType)];
 740.370 +		for(unsigned int i = 0; i < sizeof(compareType); i++)
 740.371 +			nextValidChange[i] = indexStart + i;
 740.372 +
 740.373 +		for(unsigned int i = indexStart, j = 0; i < lastIndexToRead; i++, j++)
 740.374 +		{
 740.375 +			if(s_curValues[i] != sourceAddr[i]) // if value of this byte changed
 740.376 +			{
 740.377 +				if(i < lastIndexToCopy)
 740.378 +					s_curValues[i] = sourceAddr[i]; // update value
 740.379 +				for(int k = 0; k < sizeof(compareType); k++) // loop through the previous entries that contain this byte
 740.380 +				{
 740.381 +					if(i >= indexEnd+k)
 740.382 +						continue;
 740.383 +					int m = (j-k+sizeof(compareType)) & (sizeof(compareType)-1);
 740.384 +					if(nextValidChange[m] <= i) // if we didn't already increase the change count for this entry
 740.385 +					{
 740.386 +						//if(s_numChanges[i-k] != 0xFFFF)
 740.387 +							s_numChanges[i-k]++; // increase the change count for this entry
 740.388 +						nextValidChange[m] = i-k+sizeof(compareType); // and remember not to increase it again
 740.389 +					}
 740.390 +				}
 740.391 +			}
 740.392 +		}
 740.393 +	}
 740.394 +}
 740.395 +
 740.396 +template<typename stepType, typename compareType>
 740.397 +void UpdateRegionsT()
 740.398 +{
 740.399 +	for(MemoryList::iterator iter = s_activeMemoryRegions.begin(); iter != s_activeMemoryRegions.end();)
 740.400 +	{
 740.401 +		const MemoryRegion& region = *iter;
 740.402 +		++iter;
 740.403 +		const MemoryRegion* nextRegion = (iter == s_activeMemoryRegions.end()) ? NULL : &*iter;
 740.404 +
 740.405 +		UpdateRegionT<stepType, compareType>(region, nextRegion);
 740.406 +	}
 740.407 +
 740.408 +	s_prevValuesNeedUpdate = false;
 740.409 +}
 740.410 +
 740.411 +template<typename stepType, typename compareType>
 740.412 +int CountRegionItemsT()
 740.413 +{
 740.414 +	AutoCritSect cs(&s_activeMemoryRegionsCS);
 740.415 +	if(sizeof(stepType) == 1)
 740.416 +	{
 740.417 +		if(s_activeMemoryRegions.empty())
 740.418 +			return 0;
 740.419 +
 740.420 +		if(s_itemIndicesInvalid)
 740.421 +			CalculateItemIndices(sizeof(stepType));
 740.422 +
 740.423 +		MemoryRegion& lastRegion = s_activeMemoryRegions.back();
 740.424 +		return lastRegion.itemIndex + lastRegion.size;
 740.425 +	}
 740.426 +	else // the branch above is faster but won't work if the step size isn't 1
 740.427 +	{
 740.428 +		int total = 0;
 740.429 +		for(MemoryList::iterator iter = s_activeMemoryRegions.begin(); iter != s_activeMemoryRegions.end(); ++iter)
 740.430 +		{
 740.431 +			MemoryRegion& region = *iter;
 740.432 +			int startSkipSize = ((unsigned int)(sizeof(stepType) - region.hardwareAddress)) % sizeof(stepType);
 740.433 +			total += (region.size - startSkipSize + (sizeof(stepType)-1)) / sizeof(stepType);
 740.434 +		}
 740.435 +		return total;
 740.436 +	}
 740.437 +}
 740.438 +
 740.439 +// returns information about the item in the form of a "fake" region
 740.440 +// that has the item in it and nothing else
 740.441 +template<typename stepType, typename compareType>
 740.442 +void ItemIndexToVirtualRegion(unsigned int itemIndex, MemoryRegion& virtualRegion)
 740.443 +{
 740.444 +	if(s_itemIndicesInvalid)
 740.445 +		CalculateItemIndices(sizeof(stepType));
 740.446 +
 740.447 +	if(itemIndex >= s_maxItemIndex)
 740.448 +	{
 740.449 +		memset(&virtualRegion, 0, sizeof(MemoryRegion));
 740.450 +		return;
 740.451 +	}
 740.452 +
 740.453 +	const MemoryRegion* regionPtr = s_itemIndexToRegionPointer[itemIndex];
 740.454 +	const MemoryRegion& region = *regionPtr;
 740.455 +
 740.456 +	int bytesWithinRegion = (itemIndex - region.itemIndex) * sizeof(stepType);
 740.457 +	int startSkipSize = ((unsigned int)(sizeof(stepType) - region.hardwareAddress)) % sizeof(stepType);
 740.458 +	bytesWithinRegion += startSkipSize;
 740.459 +	
 740.460 +	virtualRegion.size = sizeof(compareType);
 740.461 +	virtualRegion.hardwareAddress = region.hardwareAddress + bytesWithinRegion;
 740.462 +	virtualRegion.softwareAddress = region.softwareAddress + bytesWithinRegion;
 740.463 +	virtualRegion.virtualIndex = region.virtualIndex + bytesWithinRegion;
 740.464 +	virtualRegion.itemIndex = itemIndex;
 740.465 +	return;
 740.466 +}
 740.467 +
 740.468 +template<typename stepType, typename compareType>
 740.469 +unsigned int ItemIndexToVirtualIndex(unsigned int itemIndex)
 740.470 +{
 740.471 +	MemoryRegion virtualRegion;
 740.472 +	ItemIndexToVirtualRegion<stepType,compareType>(itemIndex, virtualRegion);
 740.473 +	return virtualRegion.virtualIndex;
 740.474 +}
 740.475 +
 740.476 +template<typename T>
 740.477 +T ReadLocalValue(const unsigned char* data)
 740.478 +{
 740.479 +	return *(const T*)data;
 740.480 +}
 740.481 +//template<> signed char ReadLocalValue(const unsigned char* data) { return *data; }
 740.482 +//template<> unsigned char ReadLocalValue(const unsigned char* data) { return *data; }
 740.483 +
 740.484 +
 740.485 +template<typename stepType, typename compareType>
 740.486 +compareType GetPrevValueFromVirtualIndex(unsigned int virtualIndex)
 740.487 +{
 740.488 +	return ReadLocalValue<compareType>(s_prevValues + virtualIndex);
 740.489 +	//return *(compareType*)(s_prevValues+virtualIndex);
 740.490 +}
 740.491 +template<typename stepType, typename compareType>
 740.492 +compareType GetCurValueFromVirtualIndex(unsigned int virtualIndex)
 740.493 +{
 740.494 +	return ReadLocalValue<compareType>(s_curValues + virtualIndex);
 740.495 +//	return *(compareType*)(s_curValues+virtualIndex);
 740.496 +}
 740.497 +template<typename stepType, typename compareType>
 740.498 +unsigned short GetNumChangesFromVirtualIndex(unsigned int virtualIndex)
 740.499 +{
 740.500 +	unsigned short num = s_numChanges[virtualIndex];
 740.501 +	//for(unsigned int i = 1; i < sizeof(stepType); i++)
 740.502 +	//	if(num < s_numChanges[virtualIndex+i])
 740.503 +	//		num = s_numChanges[virtualIndex+i];
 740.504 +	return num;
 740.505 +}
 740.506 +
 740.507 +template<typename stepType, typename compareType>
 740.508 +compareType GetPrevValueFromItemIndex(unsigned int itemIndex)
 740.509 +{
 740.510 +	int virtualIndex = ItemIndexToVirtualIndex<stepType,compareType>(itemIndex);
 740.511 +	return GetPrevValueFromVirtualIndex<stepType,compareType>(virtualIndex);
 740.512 +}
 740.513 +template<typename stepType, typename compareType>
 740.514 +compareType GetCurValueFromItemIndex(unsigned int itemIndex)
 740.515 +{
 740.516 +	int virtualIndex = ItemIndexToVirtualIndex<stepType,compareType>(itemIndex);
 740.517 +	return GetCurValueFromVirtualIndex<stepType,compareType>(virtualIndex);
 740.518 +}
 740.519 +template<typename stepType, typename compareType>
 740.520 +unsigned short GetNumChangesFromItemIndex(unsigned int itemIndex)
 740.521 +{
 740.522 +	int virtualIndex = ItemIndexToVirtualIndex<stepType,compareType>(itemIndex);
 740.523 +	return GetNumChangesFromVirtualIndex<stepType,compareType>(virtualIndex);
 740.524 +}
 740.525 +template<typename stepType, typename compareType>
 740.526 +unsigned int GetHardwareAddressFromItemIndex(unsigned int itemIndex)
 740.527 +{
 740.528 +	MemoryRegion virtualRegion;
 740.529 +	ItemIndexToVirtualRegion<stepType,compareType>(itemIndex, virtualRegion);
 740.530 +	return virtualRegion.hardwareAddress;
 740.531 +}
 740.532 +
 740.533 +// this one might be unreliable, haven't used it much
 740.534 +template<typename stepType, typename compareType>
 740.535 +unsigned int HardwareAddressToItemIndex(HWAddressType hardwareAddress)
 740.536 +{
 740.537 +	if(s_itemIndicesInvalid)
 740.538 +		CalculateItemIndices(sizeof(stepType));
 740.539 +
 740.540 +	for(MemoryList::iterator iter = s_activeMemoryRegions.begin(); iter != s_activeMemoryRegions.end(); ++iter)
 740.541 +	{
 740.542 +		MemoryRegion& region = *iter;
 740.543 +		if(hardwareAddress >= region.hardwareAddress && hardwareAddress < region.hardwareAddress + region.size)
 740.544 +		{
 740.545 +			int indexWithinRegion = (hardwareAddress - region.hardwareAddress) / sizeof(stepType);
 740.546 +			return region.itemIndex + indexWithinRegion;
 740.547 +		}
 740.548 +	}
 740.549 +
 740.550 +	return -1;
 740.551 +}
 740.552 +
 740.553 +
 740.554 +
 740.555 +// workaround for MSVC 7 that doesn't support varadic C99 macros
 740.556 +#define CALL_WITH_T_SIZE_TYPES_0(functionName, sizeTypeID, isSigned, requiresAligned) \
 740.557 +	(sizeTypeID == 'b' \
 740.558 +		? (isSigned \
 740.559 +			? functionName<char, signed char>() \
 740.560 +			: functionName<char, unsigned char>()) \
 740.561 +	: sizeTypeID == 'w' \
 740.562 +		? (isSigned \
 740.563 +			? (requiresAligned \
 740.564 +				? functionName<short, signed short>() \
 740.565 +				: functionName<char, signed short>()) \
 740.566 +			: (requiresAligned \
 740.567 +				? functionName<short, unsigned short>() \
 740.568 +				: functionName<char, unsigned short>())) \
 740.569 +	: sizeTypeID == 'd' \
 740.570 +		? (isSigned \
 740.571 +			? (requiresAligned \
 740.572 +				? functionName<short, signed long>() \
 740.573 +				: functionName<char, signed long>()) \
 740.574 +			: (requiresAligned \
 740.575 +				? functionName<short, unsigned long>() \
 740.576 +				: functionName<char, unsigned long>())) \
 740.577 +	: functionName<char, signed char>())
 740.578 +
 740.579 +#define CALL_WITH_T_SIZE_TYPES_1(functionName, sizeTypeID, isSigned, requiresAligned, p0) \
 740.580 +	(sizeTypeID == 'b' \
 740.581 +		? (isSigned \
 740.582 +			? functionName<char, signed char>(p0) \
 740.583 +			: functionName<char, unsigned char>(p0)) \
 740.584 +	: sizeTypeID == 'w' \
 740.585 +		? (isSigned \
 740.586 +			? (requiresAligned \
 740.587 +				? functionName<short, signed short>(p0) \
 740.588 +				: functionName<char, signed short>(p0)) \
 740.589 +			: (requiresAligned \
 740.590 +				? functionName<short, unsigned short>(p0) \
 740.591 +				: functionName<char, unsigned short>(p0))) \
 740.592 +	: sizeTypeID == 'd' \
 740.593 +		? (isSigned \
 740.594 +			? (requiresAligned \
 740.595 +				? functionName<short, signed long>(p0) \
 740.596 +				: functionName<char, signed long>(p0)) \
 740.597 +			: (requiresAligned \
 740.598 +				? functionName<short, unsigned long>(p0) \
 740.599 +				: functionName<char, unsigned long>(p0))) \
 740.600 +	: functionName<char, signed char>(p0))
 740.601 +
 740.602 +#define CALL_WITH_T_SIZE_TYPES_3(functionName, sizeTypeID, isSigned, requiresAligned, p0, p1, p2) \
 740.603 +	(sizeTypeID == 'b' \
 740.604 +		? (isSigned \
 740.605 +			? functionName<char, signed char>(p0, p1, p2) \
 740.606 +			: functionName<char, unsigned char>(p0, p1, p2)) \
 740.607 +	: sizeTypeID == 'w' \
 740.608 +		? (isSigned \
 740.609 +			? (requiresAligned \
 740.610 +				? functionName<short, signed short>(p0, p1, p2) \
 740.611 +				: functionName<char, signed short>(p0, p1, p2)) \
 740.612 +			: (requiresAligned \
 740.613 +				? functionName<short, unsigned short>(p0, p1, p2) \
 740.614 +				: functionName<char, unsigned short>(p0, p1, p2))) \
 740.615 +	: sizeTypeID == 'd' \
 740.616 +		? (isSigned \
 740.617 +			? (requiresAligned \
 740.618 +				? functionName<short, signed long>(p0, p1, p2) \
 740.619 +				: functionName<char, signed long>(p0, p1, p2)) \
 740.620 +			: (requiresAligned \
 740.621 +				? functionName<short, unsigned long>(p0, p1, p2) \
 740.622 +				: functionName<char, unsigned long>(p0, p1, p2))) \
 740.623 +	: functionName<char, signed char>(p0, p1, p2))
 740.624 +
 740.625 +#define CALL_WITH_T_SIZE_TYPES_4(functionName, sizeTypeID, isSigned, requiresAligned, p0, p1, p2, p3) \
 740.626 +	(sizeTypeID == 'b' \
 740.627 +		? (isSigned \
 740.628 +			? functionName<char, signed char>(p0, p1, p2, p3) \
 740.629 +			: functionName<char, unsigned char>(p0, p1, p2, p3)) \
 740.630 +	: sizeTypeID == 'w' \
 740.631 +		? (isSigned \
 740.632 +			? (requiresAligned \
 740.633 +				? functionName<short, signed short>(p0, p1, p2, p3) \
 740.634 +				: functionName<char, signed short>(p0, p1, p2, p3)) \
 740.635 +			: (requiresAligned \
 740.636 +				? functionName<short, unsigned short>(p0, p1, p2, p3) \
 740.637 +				: functionName<char, unsigned short>(p0, p1, p2, p3))) \
 740.638 +	: sizeTypeID == 'd' \
 740.639 +		? (isSigned \
 740.640 +			? (requiresAligned \
 740.641 +				? functionName<short, signed long>(p0, p1, p2, p3) \
 740.642 +				: functionName<char, signed long>(p0, p1, p2, p3)) \
 740.643 +			: (requiresAligned \
 740.644 +				? functionName<short, unsigned long>(p0, p1, p2, p3) \
 740.645 +				: functionName<char, unsigned long>(p0, p1, p2, p3))) \
 740.646 +	: functionName<char, signed char>(p0, p1, p2, p3))
 740.647 +
 740.648 +// version that takes a forced comparison type
 740.649 +#define CALL_WITH_T_STEP_3(functionName, sizeTypeID, type, requiresAligned, p0, p1, p2) \
 740.650 +	(sizeTypeID == 'b' \
 740.651 +		? functionName<char, type>(p0, p1, p2) \
 740.652 +	: sizeTypeID == 'w' \
 740.653 +		? (requiresAligned \
 740.654 +			? functionName<short, type>(p0, p1, p2) \
 740.655 +			: functionName<char, type>(p0, p1, p2)) \
 740.656 +	: sizeTypeID == 'd' \
 740.657 +		? (requiresAligned \
 740.658 +			? functionName<short, type>(p0, p1, p2) \
 740.659 +			: functionName<char, type>(p0, p1, p2)) \
 740.660 +	: functionName<char, type>(p0, p1, p2))
 740.661 +
 740.662 +// version that takes a forced comparison type
 740.663 +#define CALL_WITH_T_STEP_4(functionName, sizeTypeID, type, requiresAligned, p0, p1, p2, p3) \
 740.664 +	(sizeTypeID == 'b' \
 740.665 +		? functionName<char, type>(p0, p1, p2, p3) \
 740.666 +	: sizeTypeID == 'w' \
 740.667 +		? (requiresAligned \
 740.668 +			? functionName<short, type>(p0, p1, p2, p3) \
 740.669 +			: functionName<char, type>(p0, p1, p2, p3)) \
 740.670 +	: sizeTypeID == 'd' \
 740.671 +		? (requiresAligned \
 740.672 +			? functionName<short, type>(p0, p1, p2, p3) \
 740.673 +			: functionName<char, type>(p0, p1, p2, p3)) \
 740.674 +	: functionName<char, type>(p0, p1, p2, p3))
 740.675 +
 740.676 +// basic comparison functions:
 740.677 +template <typename T> inline bool LessCmp (T x, T y, T i)        { return x < y; }
 740.678 +template <typename T> inline bool MoreCmp (T x, T y, T i)        { return x > y; }
 740.679 +template <typename T> inline bool LessEqualCmp (T x, T y, T i)   { return x <= y; }
 740.680 +template <typename T> inline bool MoreEqualCmp (T x, T y, T i)   { return x >= y; }
 740.681 +template <typename T> inline bool EqualCmp (T x, T y, T i)       { return x == y; }
 740.682 +template <typename T> inline bool UnequalCmp (T x, T y, T i)     { return x != y; }
 740.683 +template <typename T> inline bool DiffByCmp (T x, T y, T p)      { return x - y == p || y - x == p; }
 740.684 +template <typename T> inline bool ModIsCmp (T x, T y, T p)       { return p && x % p == y; }
 740.685 +
 740.686 +// compare-to type functions:
 740.687 +template<typename stepType, typename T>
 740.688 +void SearchRelative (bool(*cmpFun)(T,T,T), T ignored, T param)
 740.689 +{
 740.690 +	for(MemoryList::iterator iter = s_activeMemoryRegions.begin(); iter != s_activeMemoryRegions.end(); )
 740.691 +	{
 740.692 +		MemoryRegion& region = *iter;
 740.693 +		int startSkipSize = ((unsigned int)(sizeof(stepType) - region.hardwareAddress)) % sizeof(stepType);
 740.694 +		unsigned int start = region.virtualIndex + startSkipSize;
 740.695 +		unsigned int end = region.virtualIndex + region.size;
 740.696 +		for(unsigned int i = start, hwaddr = region.hardwareAddress; i < end; i += sizeof(stepType), hwaddr += sizeof(stepType))
 740.697 +			if(!cmpFun(GetCurValueFromVirtualIndex<stepType,T>(i), GetPrevValueFromVirtualIndex<stepType,T>(i), param))
 740.698 +				if(2 == DeactivateRegion(region, iter, hwaddr, sizeof(stepType)))
 740.699 +					goto outerContinue;
 740.700 +		++iter;
 740.701 +outerContinue:
 740.702 +		continue;
 740.703 +	}
 740.704 +}
 740.705 +template<typename stepType, typename T>
 740.706 +void SearchSpecific (bool(*cmpFun)(T,T,T), T value, T param)
 740.707 +{
 740.708 +	for(MemoryList::iterator iter = s_activeMemoryRegions.begin(); iter != s_activeMemoryRegions.end(); )
 740.709 +	{
 740.710 +		MemoryRegion& region = *iter;
 740.711 +		int startSkipSize = ((unsigned int)(sizeof(stepType) - region.hardwareAddress)) % sizeof(stepType);
 740.712 +		unsigned int start = region.virtualIndex + startSkipSize;
 740.713 +		unsigned int end = region.virtualIndex + region.size;
 740.714 +		for(unsigned int i = start, hwaddr = region.hardwareAddress; i < end; i += sizeof(stepType), hwaddr += sizeof(stepType))
 740.715 +			if(!cmpFun(GetCurValueFromVirtualIndex<stepType,T>(i), value, param))
 740.716 +				if(2 == DeactivateRegion(region, iter, hwaddr, sizeof(stepType)))
 740.717 +					goto outerContinue;
 740.718 +		++iter;
 740.719 +outerContinue:
 740.720 +		continue;
 740.721 +	}
 740.722 +}
 740.723 +template<typename stepType, typename T>
 740.724 +void SearchAddress (bool(*cmpFun)(T,T,T), T address, T param)
 740.725 +{
 740.726 +	for(MemoryList::iterator iter = s_activeMemoryRegions.begin(); iter != s_activeMemoryRegions.end(); )
 740.727 +	{
 740.728 +		MemoryRegion& region = *iter;
 740.729 +		int startSkipSize = ((unsigned int)(sizeof(stepType) - region.hardwareAddress)) % sizeof(stepType);
 740.730 +		unsigned int start = region.virtualIndex + startSkipSize;
 740.731 +		unsigned int end = region.virtualIndex + region.size;
 740.732 +		for(unsigned int i = start, hwaddr = region.hardwareAddress; i < end; i += sizeof(stepType), hwaddr += sizeof(stepType))
 740.733 +			if(!cmpFun(hwaddr, address, param))
 740.734 +				if(2 == DeactivateRegion(region, iter, hwaddr, sizeof(stepType)))
 740.735 +					goto outerContinue;
 740.736 +		++iter;
 740.737 +outerContinue:
 740.738 +		continue;
 740.739 +	}
 740.740 +}
 740.741 +template<typename stepType, typename T>
 740.742 +void SearchChanges (bool(*cmpFun)(T,T,T), T changes, T param)
 740.743 +{
 740.744 +	for(MemoryList::iterator iter = s_activeMemoryRegions.begin(); iter != s_activeMemoryRegions.end(); )
 740.745 +	{
 740.746 +		MemoryRegion& region = *iter;
 740.747 +		int startSkipSize = ((unsigned int)(sizeof(stepType) - region.hardwareAddress)) % sizeof(stepType);
 740.748 +		unsigned int start = region.virtualIndex + startSkipSize;
 740.749 +		unsigned int end = region.virtualIndex + region.size;
 740.750 +		for(unsigned int i = start, hwaddr = region.hardwareAddress; i < end; i += sizeof(stepType), hwaddr += sizeof(stepType))
 740.751 +			if(!cmpFun(GetNumChangesFromVirtualIndex<stepType,T>(i), changes, param))
 740.752 +				if(2 == DeactivateRegion(region, iter, hwaddr, sizeof(stepType)))
 740.753 +					goto outerContinue;
 740.754 +		++iter;
 740.755 +outerContinue:
 740.756 +		continue;
 740.757 +	}
 740.758 +}
 740.759 +
 740.760 +char rs_c='s';
 740.761 +char rs_o='=';
 740.762 +char rs_t='s';
 740.763 +int rs_param=0, rs_val=0, rs_val_valid=0;
 740.764 +char rs_type_size = 'b', rs_last_type_size = rs_type_size;
 740.765 +bool noMisalign = true, rs_last_no_misalign = noMisalign;
 740.766 +//bool littleEndian = false;
 740.767 +int last_rs_possible = -1;
 740.768 +int last_rs_regions = -1;
 740.769 +
 740.770 +void prune(char c,char o,char t,int v,int p)
 740.771 +{
 740.772 +	// repetition-reducing macros
 740.773 +	#define DO_SEARCH(sf) \
 740.774 +	switch (o) \
 740.775 +	{ \
 740.776 +		case '<': DO_SEARCH_2(LessCmp,sf); break; \
 740.777 +		case '>': DO_SEARCH_2(MoreCmp,sf); break; \
 740.778 +		case '=': DO_SEARCH_2(EqualCmp,sf); break; \
 740.779 +		case '!': DO_SEARCH_2(UnequalCmp,sf); break; \
 740.780 +		case 'l': DO_SEARCH_2(LessEqualCmp,sf); break; \
 740.781 +		case 'm': DO_SEARCH_2(MoreEqualCmp,sf); break; \
 740.782 +		case 'd': DO_SEARCH_2(DiffByCmp,sf); break; \
 740.783 +		case '%': DO_SEARCH_2(ModIsCmp,sf); break; \
 740.784 +		default: assert(!"Invalid operator for this search type."); break; \
 740.785 +	}
 740.786 +
 740.787 +	// perform the search, eliminating nonmatching values
 740.788 +	switch (c)
 740.789 +	{
 740.790 +		#define DO_SEARCH_2(CmpFun,sf) CALL_WITH_T_SIZE_TYPES_3(sf, rs_type_size, t, noMisalign, CmpFun,v,p)
 740.791 +		case 'r': DO_SEARCH(SearchRelative); break;
 740.792 +		case 's': DO_SEARCH(SearchSpecific); break;
 740.793 +
 740.794 +		#undef DO_SEARCH_2
 740.795 +		#define DO_SEARCH_2(CmpFun,sf) CALL_WITH_T_STEP_3(sf, rs_type_size, unsigned int, noMisalign, CmpFun,v,p)
 740.796 +		case 'a': DO_SEARCH(SearchAddress); break;
 740.797 +
 740.798 +		#undef DO_SEARCH_2
 740.799 +		#define DO_SEARCH_2(CmpFun,sf) CALL_WITH_T_STEP_3(sf, rs_type_size, unsigned short, noMisalign, CmpFun,v,p)
 740.800 +		case 'n': DO_SEARCH(SearchChanges); break;
 740.801 +
 740.802 +		default: assert(!"Invalid search comparison type."); break;
 740.803 +	}
 740.804 +
 740.805 +	s_prevValuesNeedUpdate = true;
 740.806 +
 740.807 +	int prevNumItems = last_rs_possible;
 740.808 +
 740.809 +	CompactAddrs();
 740.810 +
 740.811 +	if(prevNumItems == last_rs_possible)
 740.812 +	{
 740.813 +		SetRamSearchUndoType(RamSearchHWnd, 0); // nothing to undo
 740.814 +	}
 740.815 +}
 740.816 +
 740.817 +
 740.818 +
 740.819 +
 740.820 +template<typename stepType, typename T>
 740.821 +bool CompareRelativeAtItem (bool(*cmpFun)(T,T,T), int itemIndex, T ignored, T param)
 740.822 +{
 740.823 +	return cmpFun(GetCurValueFromItemIndex<stepType,T>(itemIndex), GetPrevValueFromItemIndex<stepType,T>(itemIndex), param);
 740.824 +}
 740.825 +template<typename stepType, typename T>
 740.826 +bool CompareSpecificAtItem (bool(*cmpFun)(T,T,T), int itemIndex, T value, T param)
 740.827 +{
 740.828 +	return cmpFun(GetCurValueFromItemIndex<stepType,T>(itemIndex), value, param);
 740.829 +}
 740.830 +template<typename stepType, typename T>
 740.831 +bool CompareAddressAtItem (bool(*cmpFun)(T,T,T), int itemIndex, T address, T param)
 740.832 +{
 740.833 +	return cmpFun(GetHardwareAddressFromItemIndex<stepType,T>(itemIndex), address, param);
 740.834 +}
 740.835 +template<typename stepType, typename T>
 740.836 +bool CompareChangesAtItem (bool(*cmpFun)(T,T,T), int itemIndex, T changes, T param)
 740.837 +{
 740.838 +	return cmpFun(GetNumChangesFromItemIndex<stepType,T>(itemIndex), changes, param);
 740.839 +}
 740.840 +
 740.841 +int ReadControlInt(int controlID, bool forceHex, BOOL& success)
 740.842 +{
 740.843 +	int rv = 0;
 740.844 +	BOOL ok = false;
 740.845 +
 740.846 +	if(!forceHex)
 740.847 +	{
 740.848 +		rv = GetDlgItemInt(RamSearchHWnd,controlID,&ok,(rs_t == 's'));
 740.849 +	}
 740.850 +
 740.851 +	if(!ok)
 740.852 +	{
 740.853 +		if(GetDlgItemText(RamSearchHWnd,controlID,Str_Tmp,16))
 740.854 +		{
 740.855 +			for(int i = 0; Str_Tmp[i]; i++) {if(toupper(Str_Tmp[i]) == 'O') Str_Tmp[i] = '0';}
 740.856 +			const char* strPtr = Str_Tmp;
 740.857 +			bool negate = false;
 740.858 +			while(strPtr[0] == '-')
 740.859 +				strPtr++, negate = !negate;
 740.860 +			if(strPtr[0] == '+')
 740.861 +				strPtr++;
 740.862 +			if(strPtr[0] == '0' && tolower(strPtr[1]) == 'x')
 740.863 +				strPtr += 2, forceHex = true;
 740.864 +			if(strPtr[0] == '$')
 740.865 +				strPtr++, forceHex = true;
 740.866 +			if(!forceHex)
 740.867 +			{
 740.868 +				const char* strSearchPtr = strPtr;
 740.869 +				while(*strSearchPtr)
 740.870 +				{
 740.871 +					int c = tolower(*strSearchPtr++);
 740.872 +					if(c >= 'a' && c <= 'f')
 740.873 +						forceHex = true;
 740.874 +				}
 740.875 +			}
 740.876 +			const char* formatString = forceHex ? "%X" : ((rs_t=='s') ? "%d" : "%u");
 740.877 +			if(sscanf(strPtr, formatString, &rv) > 0)
 740.878 +				ok = true;
 740.879 +			if(negate)
 740.880 +				rv = -rv;
 740.881 +		}
 740.882 +	}
 740.883 +
 740.884 +	success = ok;
 740.885 +	return rv;
 740.886 +}
 740.887 +
 740.888 +
 740.889 +bool Set_RS_Val()
 740.890 +{
 740.891 +	BOOL success;
 740.892 +
 740.893 +	// update rs_val
 740.894 +	switch(rs_c)
 740.895 +	{
 740.896 +		case 'r':
 740.897 +		default:
 740.898 +			rs_val = 0;
 740.899 +			break;
 740.900 +		case 's':
 740.901 +			rs_val = ReadControlInt(IDC_EDIT_COMPAREVALUE, rs_t == 'h', success);
 740.902 +			if(!success)
 740.903 +				return false;
 740.904 +			if((rs_type_size == 'b' && rs_t == 's' && (rs_val < -128 || rs_val > 127)) ||
 740.905 +			   (rs_type_size == 'b' && rs_t != 's' && (rs_val < 0 || rs_val > 255)) ||
 740.906 +			   (rs_type_size == 'w' && rs_t == 's' && (rs_val < -32768 || rs_val > 32767)) ||
 740.907 +			   (rs_type_size == 'w' && rs_t != 's' && (rs_val < 0 || rs_val > 65535)))
 740.908 +			   return false;
 740.909 +			break;
 740.910 +		case 'a':
 740.911 +			rs_val = ReadControlInt(IDC_EDIT_COMPAREADDRESS, true, success);
 740.912 +			if(!success || rs_val < 0 || rs_val > 0x06040000)
 740.913 +				return false;
 740.914 +			break;
 740.915 +		case 'n': {
 740.916 +			rs_val = ReadControlInt(IDC_EDIT_COMPARECHANGES, false, success);
 740.917 +			if(!success || rs_val < 0 || rs_val > 0xFFFF)
 740.918 +				return false;
 740.919 +		}	break;
 740.920 +	}
 740.921 +
 740.922 +	// also update rs_param
 740.923 +	switch(rs_o)
 740.924 +	{
 740.925 +		default:
 740.926 +			rs_param = 0;
 740.927 +			break;
 740.928 +		case 'd':
 740.929 +			rs_param = ReadControlInt(IDC_EDIT_DIFFBY, false, success);
 740.930 +			if(!success)
 740.931 +				return false;
 740.932 +			if(rs_param < 0)
 740.933 +				rs_param = -rs_param;
 740.934 +			break;
 740.935 +		case '%':
 740.936 +			rs_param = ReadControlInt(IDC_EDIT_MODBY, false, success);
 740.937 +			if(!success || rs_param == 0)
 740.938 +				return false;
 740.939 +			break;
 740.940 +	}
 740.941 +
 740.942 +	// validate that rs_param fits in the comparison data type
 740.943 +	{
 740.944 +		int appliedSize = rs_type_size;
 740.945 +		int appliedSign = rs_t;
 740.946 +		if(rs_c == 'n')
 740.947 +			appliedSize = 'w', appliedSign = 'u';
 740.948 +		if(rs_c == 'a')
 740.949 +			appliedSize = 'd', appliedSign = 'u';
 740.950 +		if((appliedSize == 'b' && appliedSize == 's' && (rs_param < -128 || rs_param > 127)) ||
 740.951 +		   (appliedSize == 'b' && appliedSize != 's' && (rs_param < 0 || rs_param > 255)) ||
 740.952 +		   (appliedSize == 'w' && appliedSize == 's' && (rs_param < -32768 || rs_param > 32767)) ||
 740.953 +		   (appliedSize == 'w' && appliedSize != 's' && (rs_param < 0 || rs_param > 65535)))
 740.954 +		   return false;
 740.955 +	}
 740.956 +
 740.957 +	return true;
 740.958 +}
 740.959 +
 740.960 +bool IsSatisfied(int itemIndex)
 740.961 +{
 740.962 +	if(!rs_val_valid)
 740.963 +		return true;
 740.964 +	int o = rs_o;
 740.965 +	switch (rs_c)
 740.966 +	{
 740.967 +		#undef DO_SEARCH_2
 740.968 +		#define DO_SEARCH_2(CmpFun,sf) return CALL_WITH_T_SIZE_TYPES_4(sf, rs_type_size,(rs_t=='s'),noMisalign, CmpFun,itemIndex,rs_val,rs_param);
 740.969 +		case 'r': DO_SEARCH(CompareRelativeAtItem); break;
 740.970 +		case 's': DO_SEARCH(CompareSpecificAtItem); break;
 740.971 +
 740.972 +		#undef DO_SEARCH_2
 740.973 +		#define DO_SEARCH_2(CmpFun,sf) return CALL_WITH_T_STEP_4(sf, rs_type_size, unsigned int, noMisalign, CmpFun,itemIndex,rs_val,rs_param);
 740.974 +		case 'a': DO_SEARCH(CompareAddressAtItem); break;
 740.975 +
 740.976 +		#undef DO_SEARCH_2
 740.977 +		#define DO_SEARCH_2(CmpFun,sf) return CALL_WITH_T_STEP_4(sf, rs_type_size, unsigned short, noMisalign, CmpFun,itemIndex,rs_val,rs_param);
 740.978 +		case 'n': DO_SEARCH(CompareChangesAtItem); break;
 740.979 +	}
 740.980 +	return false;
 740.981 +}
 740.982 +
 740.983 +
 740.984 +
 740.985 +unsigned int ReadValueAtSoftwareAddress(const unsigned char* address, unsigned int size)
 740.986 +{
 740.987 +	unsigned int value = 0;
 740.988 +	if(address)
 740.989 +	{
 740.990 +		// assumes we're little-endian
 740.991 +		memcpy(&value, address, size);
 740.992 +	}
 740.993 +	return value;
 740.994 +}
 740.995 +void WriteValueAtSoftwareAddress(unsigned char* address, unsigned int value, unsigned int size)
 740.996 +{
 740.997 +	if(address)
 740.998 +	{
 740.999 +		// assumes we're little-endian
740.1000 +		memcpy(address, &value, size);
740.1001 +	}
740.1002 +}
740.1003 +unsigned int ReadValueAtHardwareAddress(HWAddressType address, unsigned int size)
740.1004 +{
740.1005 +	return ReadValueAtSoftwareAddress(HardwareToSoftwareAddress(address), size);
740.1006 +}
740.1007 +bool WriteValueAtHardwareAddress(HWAddressType address, unsigned int value, unsigned int size)
740.1008 +{
740.1009 +	WriteValueAtSoftwareAddress(HardwareToSoftwareAddress(address), value, size);
740.1010 +	return true;
740.1011 +}
740.1012 +bool IsHardwareAddressValid(HWAddressType address)
740.1013 +{
740.1014 +	return HardwareToSoftwareAddress(address) != NULL;
740.1015 +}
740.1016 +
740.1017 +
740.1018 +
740.1019 +int ResultCount=0;
740.1020 +bool AutoSearch=false;
740.1021 +bool AutoSearchAutoRetry=false;
740.1022 +LRESULT CALLBACK PromptWatchNameProc(HWND, UINT, WPARAM, LPARAM);
740.1023 +void UpdatePossibilities(int rs_possible, int regions);
740.1024 +
740.1025 +
740.1026 +void CompactAddrs()
740.1027 +{
740.1028 +	int size = (rs_type_size=='b' || !noMisalign) ? 1 : 2;
740.1029 +	int prevResultCount = ResultCount;
740.1030 +
740.1031 +	CalculateItemIndices(size);
740.1032 +	ResultCount = CALL_WITH_T_SIZE_TYPES_0(CountRegionItemsT, rs_type_size,rs_t=='s',noMisalign);
740.1033 +
740.1034 +	UpdatePossibilities(ResultCount, (int)s_activeMemoryRegions.size());
740.1035 +
740.1036 +	if(ResultCount != prevResultCount)
740.1037 +		ListView_SetItemCount(GetDlgItem(RamSearchHWnd,IDC_RAMLIST),ResultCount);
740.1038 +}
740.1039 +
740.1040 +void soft_reset_address_info ()
740.1041 +{
740.1042 +	s_prevValuesNeedUpdate = false;
740.1043 +	ResetMemoryRegions();
740.1044 +	if(!RamSearchHWnd)
740.1045 +	{
740.1046 +		EnterCriticalSection(&s_activeMemoryRegionsCS);
740.1047 +		s_activeMemoryRegions.clear();
740.1048 +		LeaveCriticalSection(&s_activeMemoryRegionsCS);
740.1049 +		ResultCount = 0;
740.1050 +	}
740.1051 +	else
740.1052 +	{
740.1053 +		// force s_prevValues to be valid
740.1054 +		signal_new_frame();
740.1055 +		s_prevValuesNeedUpdate = true;
740.1056 +		signal_new_frame();
740.1057 +	}
740.1058 +	if(s_numChanges)
740.1059 +		memset(s_numChanges, 0, (sizeof(*s_numChanges)*(MAX_RAM_SIZE)));
740.1060 +	CompactAddrs();
740.1061 +}
740.1062 +void reset_address_info ()
740.1063 +{
740.1064 +	SetRamSearchUndoType(RamSearchHWnd, 0);
740.1065 +	EnterCriticalSection(&s_activeMemoryRegionsCS);
740.1066 +	s_activeMemoryRegionsBackup.clear(); // not necessary, but we'll take the time hit here instead of at the next thing that sets up an undo
740.1067 +	LeaveCriticalSection(&s_activeMemoryRegionsCS);
740.1068 +	if(s_prevValues)
740.1069 +		memcpy(s_prevValues, s_curValues, (sizeof(*s_prevValues)*(MAX_RAM_SIZE)));
740.1070 +	s_prevValuesNeedUpdate = false;
740.1071 +	ResetMemoryRegions();
740.1072 +	if(!RamSearchHWnd)
740.1073 +	{
740.1074 +		EnterCriticalSection(&s_activeMemoryRegionsCS);
740.1075 +		s_activeMemoryRegions.clear();
740.1076 +		LeaveCriticalSection(&s_activeMemoryRegionsCS);
740.1077 +		ResultCount = 0;
740.1078 +	}
740.1079 +	else
740.1080 +	{
740.1081 +		// force s_prevValues to be valid
740.1082 +		signal_new_frame();
740.1083 +		s_prevValuesNeedUpdate = true;
740.1084 +		signal_new_frame();
740.1085 +	}
740.1086 +	memset(s_numChanges, 0, (sizeof(*s_numChanges)*(MAX_RAM_SIZE)));
740.1087 +	CompactAddrs();
740.1088 +}
740.1089 +
740.1090 +void signal_new_frame ()
740.1091 +{
740.1092 +	EnterCriticalSection(&s_activeMemoryRegionsCS);
740.1093 +	CALL_WITH_T_SIZE_TYPES_0(UpdateRegionsT, rs_type_size, rs_t=='s', noMisalign);
740.1094 +	LeaveCriticalSection(&s_activeMemoryRegionsCS);
740.1095 +}
740.1096 +
740.1097 +
740.1098 +
740.1099 +
740.1100 +
740.1101 +bool RamSearchClosed = false;
740.1102 +bool RamWatchClosed = false;
740.1103 +
740.1104 +void ResetResults()
740.1105 +{
740.1106 +	reset_address_info();
740.1107 +	ResultCount = 0;
740.1108 +	if (RamSearchHWnd)
740.1109 +		ListView_SetItemCount(GetDlgItem(RamSearchHWnd,IDC_RAMLIST),ResultCount);
740.1110 +}
740.1111 +void CloseRamWindows() //Close the Ram Search & Watch windows when rom closes
740.1112 +{
740.1113 +	ResetWatches();
740.1114 +	ResetResults();
740.1115 +	if (RamSearchHWnd)
740.1116 +	{
740.1117 +		SendMessage(RamSearchHWnd,WM_CLOSE,NULL,NULL);
740.1118 +		RamSearchClosed = true;
740.1119 +	}
740.1120 +	if (RamWatchHWnd)
740.1121 +	{
740.1122 +		SendMessage(RamWatchHWnd,WM_CLOSE,NULL,NULL);
740.1123 +		RamWatchClosed = true;
740.1124 +	}
740.1125 +}
740.1126 +void ReopenRamWindows() //Reopen them when a new Rom is loaded
740.1127 +{
740.1128 +	HWND hwnd = GetActiveWindow();
740.1129 +
740.1130 +	if (RamSearchClosed)
740.1131 +	{
740.1132 +		RamSearchClosed = false;
740.1133 +		if(!RamSearchHWnd)
740.1134 +		{
740.1135 +			reset_address_info();
740.1136 +			LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
740.1137 +			RamSearchHWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_RAMSEARCH), hWnd, (DLGPROC) RamSearchProc);
740.1138 +		}
740.1139 +		else
740.1140 +			::SetForegroundWindow(RamSearchHWnd);
740.1141 +	}
740.1142 +	if (RamWatchClosed || AutoRWLoad)
740.1143 +	{
740.1144 +		RamWatchClosed = false;
740.1145 +		if(!RamWatchHWnd)
740.1146 +		{
740.1147 +			if (AutoRWLoad) OpenRWRecentFile(0);
740.1148 +			LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
740.1149 +			RamWatchHWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_RAMWATCH), hWnd, (DLGPROC) RamWatchProc);
740.1150 +		}
740.1151 +		else
740.1152 +			::SetForegroundWindow(RamWatchHWnd);
740.1153 +	}
740.1154 +
740.1155 +	if (hwnd == hWnd && hwnd != GetActiveWindow())
740.1156 +		SetActiveWindow(hWnd); // restore focus to the main window if it had it before
740.1157 +}
740.1158 +
740.1159 +
740.1160 +
740.1161 +
740.1162 +
740.1163 +void RefreshRamListSelectedCountControlStatus(HWND hDlg)
740.1164 +{
740.1165 +	int selCount = ListView_GetSelectedCount(GetDlgItem(hDlg,IDC_RAMLIST));
740.1166 +	if(selCount != s_prevSelCount)
740.1167 +	{
740.1168 +		if(selCount < 2 || s_prevSelCount < 2)
740.1169 +		{
740.1170 +			EnableWindow(GetDlgItem(hDlg, IDC_C_WATCH), (WatchCount < MAX_WATCH_COUNT) ? TRUE : FALSE);
740.1171 +			EnableWindow(GetDlgItem(hDlg, IDC_C_ADDCHEAT), (selCount >= 1) ? TRUE : FALSE);
740.1172 +			EnableWindow(GetDlgItem(hDlg, IDC_C_ELIMINATE), (selCount >= 1) ? TRUE : FALSE);
740.1173 +		}
740.1174 +		s_prevSelCount = selCount;
740.1175 +	}
740.1176 +}
740.1177 +
740.1178 +
740.1179 +
740.1180 +
740.1181 +struct AddrRange
740.1182 +{
740.1183 +	unsigned int addr;
740.1184 +	unsigned int size;
740.1185 +	unsigned int End() const { return addr + size; }
740.1186 +	AddrRange(unsigned int a, unsigned int s) : addr(a),size(s){}
740.1187 +};
740.1188 +
740.1189 +void signal_new_size ()
740.1190 +{
740.1191 +	HWND lv = GetDlgItem(RamSearchHWnd,IDC_RAMLIST);
740.1192 +
740.1193 +	int oldSize = (rs_last_type_size=='b' || !rs_last_no_misalign) ? 1 : 2;
740.1194 +	int newSize = (rs_type_size=='b' || !noMisalign) ? 1 : 2;
740.1195 +	bool numberOfItemsChanged = (oldSize != newSize);
740.1196 +
740.1197 +	unsigned int itemsPerPage = ListView_GetCountPerPage(lv);
740.1198 +	unsigned int oldTopIndex = ListView_GetTopIndex(lv);
740.1199 +	unsigned int oldSelectionIndex = ListView_GetSelectionMark(lv);
740.1200 +	unsigned int oldTopAddr = CALL_WITH_T_SIZE_TYPES_1(GetHardwareAddressFromItemIndex, rs_last_type_size,rs_t=='s',rs_last_no_misalign, oldTopIndex);
740.1201 +	unsigned int oldSelectionAddr = CALL_WITH_T_SIZE_TYPES_1(GetHardwareAddressFromItemIndex, rs_last_type_size,rs_t=='s',rs_last_no_misalign, oldSelectionIndex);
740.1202 +
740.1203 +	std::vector<AddrRange> selHardwareAddrs;
740.1204 +	if(numberOfItemsChanged)
740.1205 +	{
740.1206 +		// store selection ranges
740.1207 +		// unfortunately this can take a while if the user has a huge range of items selected
740.1208 +		systemSoundClearBuffer();
740.1209 +		int selCount = ListView_GetSelectedCount(lv);
740.1210 +		int size = (rs_last_type_size=='b' || !rs_last_no_misalign) ? 1 : 2;
740.1211 +		int watchIndex = -1;
740.1212 +		for(int i = 0; i < selCount; ++i)
740.1213 +		{
740.1214 +			watchIndex = ListView_GetNextItem(lv, watchIndex, LVNI_SELECTED);
740.1215 +			int addr = CALL_WITH_T_SIZE_TYPES_1(GetHardwareAddressFromItemIndex, rs_last_type_size,rs_t=='s',rs_last_no_misalign, watchIndex);
740.1216 +			if(!selHardwareAddrs.empty() && addr == selHardwareAddrs.back().End())
740.1217 +				selHardwareAddrs.back().size += size;
740.1218 +			else if (!(noMisalign && oldSize < newSize && addr % newSize != 0))
740.1219 +				selHardwareAddrs.push_back(AddrRange(addr,size));
740.1220 +		}
740.1221 +	}
740.1222 +
740.1223 +	CompactAddrs();
740.1224 +
740.1225 +	rs_last_type_size = rs_type_size;
740.1226 +	rs_last_no_misalign = noMisalign;
740.1227 +
740.1228 +	if(numberOfItemsChanged)
740.1229 +	{
740.1230 +		// restore selection ranges
740.1231 +		unsigned int newTopIndex = CALL_WITH_T_SIZE_TYPES_1(HardwareAddressToItemIndex, rs_type_size,rs_t=='s',noMisalign, oldTopAddr);
740.1232 +		unsigned int newBottomIndex = newTopIndex + itemsPerPage - 1;
740.1233 +		SendMessage(lv, WM_SETREDRAW, FALSE, 0);
740.1234 +		ListView_SetItemState(lv, -1, 0, LVIS_SELECTED|LVIS_FOCUSED); // deselect all
740.1235 +		for(unsigned int i = 0; i < selHardwareAddrs.size(); i++)
740.1236 +		{
740.1237 +			// calculate index ranges of this selection
740.1238 +			const AddrRange& range = selHardwareAddrs[i];
740.1239 +			int selRangeTop = CALL_WITH_T_SIZE_TYPES_1(HardwareAddressToItemIndex, rs_type_size,rs_t=='s',noMisalign, range.addr);
740.1240 +			int selRangeBottom = -1;
740.1241 +			for(int endAddr = range.End()-1; endAddr >= selRangeTop && selRangeBottom == -1; endAddr--)
740.1242 +				selRangeBottom = CALL_WITH_T_SIZE_TYPES_1(HardwareAddressToItemIndex, rs_type_size,rs_t=='s',noMisalign, endAddr);
740.1243 +			if(selRangeBottom == -1)
740.1244 +				selRangeBottom = selRangeTop;
740.1245 +			if(selRangeTop == -1)
740.1246 +				continue;
740.1247 +
740.1248 +			// select the entire range
740.1249 +			for (int j = selRangeTop; j <= selRangeBottom; j++)
740.1250 +			{
740.1251 +				ListView_SetItemState(lv, j, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
740.1252 +			}
740.1253 +		}
740.1254 +
740.1255 +		// restore previous scroll position
740.1256 +		if(newBottomIndex != -1)
740.1257 +			ListView_EnsureVisible(lv, newBottomIndex, 0);
740.1258 +		if(newTopIndex != -1)
740.1259 +			ListView_EnsureVisible(lv, newTopIndex, 0);
740.1260 +
740.1261 +		SendMessage(lv, WM_SETREDRAW, TRUE, 0);
740.1262 +
740.1263 +		RefreshRamListSelectedCountControlStatus(RamSearchHWnd);
740.1264 +
740.1265 +		EnableWindow(GetDlgItem(RamSearchHWnd,IDC_MISALIGN), rs_type_size != 'b');
740.1266 +	}
740.1267 +	else
740.1268 +	{
740.1269 +		ListView_Update(lv, -1);
740.1270 +	}
740.1271 +	InvalidateRect(lv, NULL, TRUE);
740.1272 +	//SetFocus(lv);
740.1273 +}
740.1274 +
740.1275 +
740.1276 +
740.1277 +
740.1278 +LRESULT CustomDraw (LPARAM lParam)
740.1279 +{
740.1280 +	LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
740.1281 +
740.1282 +	switch(lplvcd->nmcd.dwDrawStage) 
740.1283 +	{
740.1284 +		case CDDS_PREPAINT :
740.1285 +			return CDRF_NOTIFYITEMDRAW;
740.1286 +
740.1287 +		case CDDS_ITEMPREPAINT:
740.1288 +		{
740.1289 +			int rv = CDRF_DODEFAULT;
740.1290 +
740.1291 +			if(lplvcd->nmcd.dwItemSpec % 2)
740.1292 +			{
740.1293 +				// alternate the background color slightly
740.1294 +				lplvcd->clrTextBk = RGB(248,248,255);
740.1295 +				rv = CDRF_NEWFONT;
740.1296 +			}
740.1297 +
740.1298 +			if(!IsSatisfied(lplvcd->nmcd.dwItemSpec))
740.1299 +			{
740.1300 +				// tint red any items that would be eliminated if a search were to run now
740.1301 +				lplvcd->clrText = RGB(192,64,64);
740.1302 +				rv = CDRF_NEWFONT;
740.1303 +			}
740.1304 +
740.1305 +			return rv;
740.1306 +		}	break;
740.1307 +	}
740.1308 +	return CDRF_DODEFAULT;
740.1309 +}
740.1310 +
740.1311 +void Update_RAM_Search() //keeps RAM values up to date in the search and watch windows
740.1312 +{
740.1313 +	if(disableRamSearchUpdate)
740.1314 +		return;
740.1315 +
740.1316 +	int prevValuesNeededUpdate;
740.1317 +	if (AutoSearch && !ResultCount)
740.1318 +	{
740.1319 +		if(!AutoSearchAutoRetry)
740.1320 +		{
740.1321 +			systemSoundClearBuffer();
740.1322 +			int answer = MessageBox(RamSearchHWnd,"Choosing Retry will reset the search once and continue autosearching.\nChoose Ignore will reset the search whenever necessary and continue autosearching.\nChoosing Abort will reset the search once and stop autosearching.","Autosearch - out of results.",MB_ABORTRETRYIGNORE|MB_DEFBUTTON2|MB_ICONINFORMATION);
740.1323 +			if(answer == IDABORT)
740.1324 +			{
740.1325 +				SendDlgItemMessage(RamSearchHWnd, IDC_C_AUTOSEARCH, BM_SETCHECK, BST_UNCHECKED, 0);
740.1326 +				SendMessage(RamSearchHWnd, WM_COMMAND, IDC_C_AUTOSEARCH, 0);
740.1327 +			}
740.1328 +			if(answer == IDIGNORE)
740.1329 +				AutoSearchAutoRetry = true;
740.1330 +		}
740.1331 +		reset_address_info();
740.1332 +		prevValuesNeededUpdate = s_prevValuesNeedUpdate;
740.1333 +	}
740.1334 +	else
740.1335 +	{
740.1336 +		prevValuesNeededUpdate = s_prevValuesNeedUpdate;
740.1337 +		if (RamSearchHWnd)
740.1338 +		{
740.1339 +			// update active RAM values
740.1340 +			signal_new_frame();
740.1341 +		}
740.1342 +
740.1343 +		if (AutoSearch && ResultCount)
740.1344 +		{
740.1345 +			systemSoundClearBuffer();
740.1346 +			if(!rs_val_valid)
740.1347 +				rs_val_valid = Set_RS_Val();
740.1348 +			if(rs_val_valid)
740.1349 +				prune(rs_c,rs_o,rs_t=='s',rs_val,rs_param);
740.1350 +		}
740.1351 +	}
740.1352 +
740.1353 +	if(RamSearchHWnd)
740.1354 +	{
740.1355 +		HWND lv = GetDlgItem(RamSearchHWnd,IDC_RAMLIST);
740.1356 +		if(prevValuesNeededUpdate != s_prevValuesNeedUpdate)
740.1357 +		{
740.1358 +			// previous values got updated, refresh everything visible
740.1359 +			ListView_Update(lv, -1);
740.1360 +		}
740.1361 +		else
740.1362 +		{
740.1363 +			// refresh any visible parts of the listview box that changed
740.1364 +			static int changes[128];
740.1365 +			int top = ListView_GetTopIndex(lv);
740.1366 +			int count = ListView_GetCountPerPage(lv);
740.1367 +			int start = -1;
740.1368 +			for(int i = top; i <= top+count; i++)
740.1369 +			{
740.1370 +				int changeNum = CALL_WITH_T_SIZE_TYPES_1(GetNumChangesFromItemIndex, rs_type_size,rs_t=='s',noMisalign, i); //s_numChanges[i];
740.1371 +				int changed = changeNum != changes[i-top];
740.1372 +				if(changed)
740.1373 +					changes[i-top] = changeNum;
740.1374 +
740.1375 +				if(start == -1)
740.1376 +				{
740.1377 +					if(i != top+count && changed)
740.1378 +					{
740.1379 +						start = i;
740.1380 +						//somethingChanged = true;
740.1381 +					}
740.1382 +				}
740.1383 +				else
740.1384 +				{
740.1385 +					if(i == top+count || !changed)
740.1386 +					{
740.1387 +						ListView_RedrawItems(lv, start, i-1);
740.1388 +						start = -1;
740.1389 +					}
740.1390 +				}
740.1391 +			}
740.1392 +		}
740.1393 +	}
740.1394 +
740.1395 +	if(RamWatchHWnd)
740.1396 +	{
740.1397 +		Update_RAM_Watch();
740.1398 +	}
740.1399 +}
740.1400 +
740.1401 +static int rs_lastPercent = -1;
740.1402 +inline void UpdateRamSearchProgressBar(int percent)
740.1403 +{
740.1404 +	if(rs_lastPercent != percent)
740.1405 +	{
740.1406 +		rs_lastPercent = percent;
740.1407 +		UpdateRamSearchTitleBar(percent);
740.1408 +	}
740.1409 +}
740.1410 +
740.1411 +static void SelectEditControl(int controlID)
740.1412 +{
740.1413 +	HWND hEdit = GetDlgItem(RamSearchHWnd,controlID);
740.1414 +	SetFocus(hEdit);
740.1415 +	SendMessage(hEdit, EM_SETSEL, 0, -1);
740.1416 +}
740.1417 +
740.1418 +static BOOL SelectingByKeyboard()
740.1419 +{
740.1420 +	int a = GetKeyState(VK_LEFT);
740.1421 +	int b = GetKeyState(VK_RIGHT);
740.1422 +	int c = GetKeyState(VK_UP);
740.1423 +	int d = GetKeyState(VK_DOWN); // space and tab are intentionally omitted
740.1424 +	return (a | b | c | d) & 0x80;
740.1425 +}
740.1426 +
740.1427 +
740.1428 +LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
740.1429 +{
740.1430 +	static int watchIndex=0;
740.1431 +
740.1432 +	switch(uMsg)
740.1433 +	{
740.1434 +		case WM_INITDIALOG: {
740.1435 +			RamSearchHWnd = hDlg;
740.1436 +			
740.1437 +			SetWindowPos(hDlg, NULL, regQueryDwordValue("ramSearchX", 0), regQueryDwordValue("ramSearchY", 0), NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
740.1438 +			switch(rs_o)
740.1439 +			{
740.1440 +				case '<':
740.1441 +					SendDlgItemMessage(hDlg, IDC_LESSTHAN, BM_SETCHECK, BST_CHECKED, 0);
740.1442 +					break;
740.1443 +				case '>':
740.1444 +					SendDlgItemMessage(hDlg, IDC_MORETHAN, BM_SETCHECK, BST_CHECKED, 0);
740.1445 +					break;
740.1446 +				case 'l':
740.1447 +					SendDlgItemMessage(hDlg, IDC_NOMORETHAN, BM_SETCHECK, BST_CHECKED, 0);
740.1448 +					break;
740.1449 +				case 'm':
740.1450 +					SendDlgItemMessage(hDlg, IDC_NOLESSTHAN, BM_SETCHECK, BST_CHECKED, 0);
740.1451 +					break;
740.1452 +				case '=': 
740.1453 +					SendDlgItemMessage(hDlg, IDC_EQUALTO, BM_SETCHECK, BST_CHECKED, 0);
740.1454 +					break;
740.1455 +				case '!':
740.1456 +					SendDlgItemMessage(hDlg, IDC_DIFFERENTFROM, BM_SETCHECK, BST_CHECKED, 0);
740.1457 +					break;
740.1458 +				case 'd':
740.1459 +					SendDlgItemMessage(hDlg, IDC_DIFFERENTBY, BM_SETCHECK, BST_CHECKED, 0);
740.1460 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_DIFFBY),true);
740.1461 +					break;
740.1462 +				case '%':
740.1463 +					SendDlgItemMessage(hDlg, IDC_MODULO, BM_SETCHECK, BST_CHECKED, 0);
740.1464 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_MODBY),true);
740.1465 +					break;
740.1466 +			}
740.1467 +			switch (rs_c)
740.1468 +			{
740.1469 +				case 'r':
740.1470 +					SendDlgItemMessage(hDlg, IDC_PREVIOUSVALUE, BM_SETCHECK, BST_CHECKED, 0);
740.1471 +					break;
740.1472 +				case 's':
740.1473 +					SendDlgItemMessage(hDlg, IDC_SPECIFICVALUE, BM_SETCHECK, BST_CHECKED, 0);
740.1474 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_COMPAREVALUE),true);
740.1475 +					break;
740.1476 +				case 'a':
740.1477 +					SendDlgItemMessage(hDlg, IDC_SPECIFICADDRESS, BM_SETCHECK, BST_CHECKED, 0);
740.1478 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_COMPAREADDRESS),true);
740.1479 +					break;
740.1480 +				case 'n':
740.1481 +					SendDlgItemMessage(hDlg, IDC_NUMBEROFCHANGES, BM_SETCHECK, BST_CHECKED, 0);
740.1482 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_COMPARECHANGES),true);
740.1483 +					break;
740.1484 +			}
740.1485 +			switch (rs_t)
740.1486 +			{
740.1487 +				case 's':
740.1488 +					SendDlgItemMessage(hDlg, IDC_SIGNED, BM_SETCHECK, BST_CHECKED, 0);
740.1489 +					break;
740.1490 +				case 'u':
740.1491 +					SendDlgItemMessage(hDlg, IDC_UNSIGNED, BM_SETCHECK, BST_CHECKED, 0);
740.1492 +					break;
740.1493 +				case 'h':
740.1494 +					SendDlgItemMessage(hDlg, IDC_HEX, BM_SETCHECK, BST_CHECKED, 0);
740.1495 +					break;
740.1496 +			}
740.1497 +			switch (rs_type_size)
740.1498 +			{
740.1499 +				case 'b':
740.1500 +					SendDlgItemMessage(hDlg, IDC_1_BYTE, BM_SETCHECK, BST_CHECKED, 0);
740.1501 +					break;
740.1502 +				case 'w':
740.1503 +					SendDlgItemMessage(hDlg, IDC_2_BYTES, BM_SETCHECK, BST_CHECKED, 0);
740.1504 +					break;
740.1505 +				case 'd':
740.1506 +					SendDlgItemMessage(hDlg, IDC_4_BYTES, BM_SETCHECK, BST_CHECKED, 0);
740.1507 +					break;
740.1508 +			}
740.1509 +
740.1510 +			s_prevValuesNeedUpdate = true;
740.1511 +
740.1512 +			SendDlgItemMessage(hDlg,IDC_C_AUTOSEARCH,BM_SETCHECK,AutoSearch?BST_CHECKED:BST_UNCHECKED,0);
740.1513 +			//const char* names[5] = {"Address","Value","Previous","Changes","Notes"};
740.1514 +			//int widths[5] = {62,64,64,55,55};
740.1515 +			const char* names[] = {"Address","Value","Previous","Changes"};
740.1516 +			int widths[4] = {68,76,76,68};
740.1517 +			if (!ResultCount)
740.1518 +				reset_address_info();
740.1519 +			else
740.1520 +			{
740.1521 +				signal_new_frame();
740.1522 +				CompactAddrs();
740.1523 +			}
740.1524 +			void init_list_box(HWND Box, const char* Strs[], int numColumns, int *columnWidths);
740.1525 +			init_list_box(GetDlgItem(hDlg,IDC_RAMLIST),names,4,widths);
740.1526 +			//ListView_SetItemCount(GetDlgItem(hDlg,IDC_RAMLIST),ResultCount);
740.1527 +			if (!noMisalign) SendDlgItemMessage(hDlg, IDC_MISALIGN, BM_SETCHECK, BST_CHECKED, 0);
740.1528 +			//if (littleEndian) SendDlgItemMessage(hDlg, IDC_ENDIAN, BM_SETCHECK, BST_CHECKED, 0);
740.1529 +			last_rs_possible = -1;
740.1530 +
740.1531 +			s_prevSelCount = -1;
740.1532 +			RefreshRamListSelectedCountControlStatus(hDlg);
740.1533 +
740.1534 +			// force misalign checkbox to refresh
740.1535 +			signal_new_size();
740.1536 +
740.1537 +			// force undo button to refresh
740.1538 +			int undoType = s_undoType;
740.1539 +			SetRamSearchUndoType(hDlg, -2);
740.1540 +			SetRamSearchUndoType(hDlg, undoType);
740.1541 +
740.1542 +			// force possibility count to refresh
740.1543 +			last_rs_possible--;
740.1544 +			UpdatePossibilities(ResultCount, (int)s_activeMemoryRegions.size());
740.1545 +			
740.1546 +			rs_val_valid = Set_RS_Val();
740.1547 +
740.1548 +			ListView_SetCallbackMask(GetDlgItem(hDlg,IDC_RAMLIST), LVIS_FOCUSED|LVIS_SELECTED);
740.1549 +
740.1550 +			return true;
740.1551 +		}	break;
740.1552 +
740.1553 +		case WM_NOTIFY:
740.1554 +		{
740.1555 +			LPNMHDR lP = (LPNMHDR) lParam;
740.1556 +			switch (lP->code)
740.1557 +			{
740.1558 +				case LVN_ITEMCHANGED: // selection changed event
740.1559 +				{
740.1560 +					NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)lP;
740.1561 +					if(pNMListView->uNewState & LVIS_FOCUSED ||
740.1562 +						(pNMListView->uNewState ^ pNMListView->uOldState) & LVIS_SELECTED)
740.1563 +					{
740.1564 +						// disable buttons that we don't have the right number of selected items for
740.1565 +						RefreshRamListSelectedCountControlStatus(hDlg);
740.1566 +					}
740.1567 +				}	break;
740.1568 +
740.1569 +				case LVN_GETDISPINFO:
740.1570 +				{
740.1571 +					LV_DISPINFO *Item = (LV_DISPINFO *)lParam;
740.1572 +					Item->item.mask = LVIF_TEXT;
740.1573 +					Item->item.state = 0;
740.1574 +					Item->item.iImage = 0;
740.1575 +					const unsigned int iNum = Item->item.iItem;
740.1576 +					static char num[11];
740.1577 +					switch (Item->item.iSubItem)
740.1578 +					{
740.1579 +						case 0:
740.1580 +						{
740.1581 +							int addr = CALL_WITH_T_SIZE_TYPES_1(GetHardwareAddressFromItemIndex, rs_type_size,rs_t=='s',noMisalign, iNum);
740.1582 +							sprintf(num,"%08X",addr);
740.1583 +							Item->item.pszText = num;
740.1584 +						}	return true;
740.1585 +						case 1:
740.1586 +						{
740.1587 +							int i = CALL_WITH_T_SIZE_TYPES_1(GetCurValueFromItemIndex, rs_type_size,rs_t=='s',noMisalign, iNum);
740.1588 +							const char* formatString = ((rs_t=='s') ? "%d" : (rs_t=='u') ? "%u" : (rs_type_size=='d' ? "%08X" : rs_type_size=='w' ? "%04X" : "%02X"));
740.1589 +							switch (rs_type_size)
740.1590 +							{
740.1591 +								case 'b':
740.1592 +								default: sprintf(num, formatString, rs_t=='s' ? (char)(i&0xff) : (unsigned char)(i&0xff)); break;
740.1593 +								case 'w': sprintf(num, formatString, rs_t=='s' ? (short)(i&0xffff) : (unsigned short)(i&0xffff)); break;
740.1594 +								case 'd': sprintf(num, formatString, rs_t=='s' ? (long)(i&0xffffffff) : (unsigned long)(i&0xffffffff)); break;
740.1595 +							}
740.1596 +							Item->item.pszText = num;
740.1597 +						}	return true;
740.1598 +						case 2:
740.1599 +						{
740.1600 +							int i = CALL_WITH_T_SIZE_TYPES_1(GetPrevValueFromItemIndex, rs_type_size,rs_t=='s',noMisalign, iNum);
740.1601 +							const char* formatString = ((rs_t=='s') ? "%d" : (rs_t=='u') ? "%u" : (rs_type_size=='d' ? "%08X" : rs_type_size=='w' ? "%04X" : "%02X"));
740.1602 +							switch (rs_type_size)
740.1603 +							{
740.1604 +								case 'b':
740.1605 +								default: sprintf(num, formatString, rs_t=='s' ? (char)(i&0xff) : (unsigned char)(i&0xff)); break;
740.1606 +								case 'w': sprintf(num, formatString, rs_t=='s' ? (short)(i&0xffff) : (unsigned short)(i&0xffff)); break;
740.1607 +								case 'd': sprintf(num, formatString, rs_t=='s' ? (long)(i&0xffffffff) : (unsigned long)(i&0xffffffff)); break;
740.1608 +							}
740.1609 +							Item->item.pszText = num;
740.1610 +						}	return true;
740.1611 +						case 3:
740.1612 +						{
740.1613 +							int i = CALL_WITH_T_SIZE_TYPES_1(GetNumChangesFromItemIndex, rs_type_size,rs_t=='s',noMisalign, iNum);
740.1614 +							sprintf(num,"%d",i);
740.1615 +
740.1616 +							Item->item.pszText = num;
740.1617 +						}	return true;
740.1618 +						//case 4:
740.1619 +						//	Item->item.pszText = rsaddrs[rsresults[iNum].Index].comment ? rsaddrs[rsresults[iNum].Index].comment : "";
740.1620 +						//	return true;
740.1621 +						default:
740.1622 +							return false;
740.1623 +					}
740.1624 +				}
740.1625 +
740.1626 +				case NM_CUSTOMDRAW:
740.1627 +				{
740.1628 +					SetWindowLong(hDlg, DWL_MSGRESULT, CustomDraw(lParam));
740.1629 +					return TRUE;
740.1630 +				}	break;
740.1631 +
740.1632 +				//case LVN_ODCACHEHINT: //Copied this bit from the MSDN virtual listbox code sample. Eventually it should probably do something.
740.1633 +				//{
740.1634 +				//	LPNMLVCACHEHINT   lpCacheHint = (LPNMLVCACHEHINT)lParam;
740.1635 +				//	return 0;
740.1636 +				//}
740.1637 +				//case LVN_ODFINDITEM: //Copied this bit from the MSDN virtual listbox code sample. Eventually it should probably do something.
740.1638 +				//{	
740.1639 +				//	LPNMLVFINDITEM lpFindItem = (LPNMLVFINDITEM)lParam;
740.1640 +				//	return 0;
740.1641 +				//}
740.1642 +			}
740.1643 +		}	break;
740.1644 +
740.1645 +		case WM_COMMAND:
740.1646 +		{
740.1647 +			int rv = false;
740.1648 +			switch(LOWORD(wParam))
740.1649 +			{
740.1650 +				case IDC_SIGNED:
740.1651 +					rs_t='s';
740.1652 +					signal_new_size();
740.1653 +					{rv = true; break;}
740.1654 +				case IDC_UNSIGNED:
740.1655 +					rs_t='u';
740.1656 +					signal_new_size();
740.1657 +					{rv = true; break;}
740.1658 +				case IDC_HEX:
740.1659 +					rs_t='h';
740.1660 +					signal_new_size();
740.1661 +					{rv = true; break;}
740.1662 +				case IDC_1_BYTE:
740.1663 +					rs_type_size = 'b';
740.1664 +					signal_new_size();
740.1665 +					{rv = true; break;}
740.1666 +				case IDC_2_BYTES:
740.1667 +					rs_type_size = 'w';
740.1668 +					signal_new_size();
740.1669 +					{rv = true; break;}
740.1670 +				case IDC_4_BYTES:
740.1671 +					rs_type_size = 'd';
740.1672 +					signal_new_size();
740.1673 +					{rv = true; break;}
740.1674 +				case IDC_MISALIGN:
740.1675 +					noMisalign = !noMisalign;
740.1676 +					//CompactAddrs();
740.1677 +					signal_new_size();
740.1678 +					{rv = true; break;}
740.1679 +//				case IDC_ENDIAN:
740.1680 +////					littleEndian = !littleEndian;
740.1681 +////					signal_new_size();
740.1682 +//					{rv = true; break;}				
740.1683 +				case IDC_LESSTHAN:
740.1684 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_DIFFBY),false);
740.1685 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_MODBY),false);
740.1686 +					rs_o = '<';
740.1687 +					{rv = true; break;}
740.1688 +				case IDC_MORETHAN:
740.1689 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_DIFFBY),false);
740.1690 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_MODBY),false);
740.1691 +					rs_o = '>';
740.1692 +					{rv = true; break;}
740.1693 +				case IDC_NOMORETHAN:
740.1694 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_DIFFBY),false);
740.1695 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_MODBY),false);
740.1696 +					rs_o = 'l';
740.1697 +					{rv = true; break;}
740.1698 +				case IDC_NOLESSTHAN:
740.1699 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_DIFFBY),false);
740.1700 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_MODBY),false);
740.1701 +					rs_o = 'm';
740.1702 +					{rv = true; break;}
740.1703 +				case IDC_EQUALTO:
740.1704 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_DIFFBY),false);
740.1705 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_MODBY),false);
740.1706 +					rs_o = '=';
740.1707 +					{rv = true; break;}
740.1708 +				case IDC_DIFFERENTFROM:
740.1709 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_DIFFBY),false);
740.1710 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_MODBY),false);
740.1711 +					rs_o = '!';
740.1712 +					{rv = true; break;}
740.1713 +				case IDC_DIFFERENTBY:
740.1714 +				{
740.1715 +					rs_o = 'd';
740.1716 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_DIFFBY),true);
740.1717 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_MODBY),false);
740.1718 +					if(!SelectingByKeyboard())
740.1719 +						SelectEditControl(IDC_EDIT_DIFFBY);
740.1720 +				}	{rv = true; break;}
740.1721 +				case IDC_MODULO:
740.1722 +				{
740.1723 +					rs_o = '%';
740.1724 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_DIFFBY),false);
740.1725 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_MODBY),true);
740.1726 +					if(!SelectingByKeyboard())
740.1727 +						SelectEditControl(IDC_EDIT_MODBY);
740.1728 +				}	{rv = true; break;}
740.1729 +				case IDC_PREVIOUSVALUE:
740.1730 +					rs_c='r';
740.1731 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_COMPAREVALUE),false);
740.1732 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_COMPAREADDRESS),false);
740.1733 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_COMPARECHANGES),false);
740.1734 +					{rv = true; break;}
740.1735 +				case IDC_SPECIFICVALUE:
740.1736 +				{
740.1737 +					rs_c = 's';
740.1738 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_COMPAREVALUE),true);
740.1739 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_COMPAREADDRESS),false);
740.1740 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_COMPARECHANGES),false);
740.1741 +					if(!SelectingByKeyboard())
740.1742 +						SelectEditControl(IDC_EDIT_COMPAREVALUE);
740.1743 +					{rv = true; break;}
740.1744 +				}
740.1745 +				case IDC_SPECIFICADDRESS:
740.1746 +				{
740.1747 +					rs_c = 'a';
740.1748 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_COMPAREADDRESS),true);
740.1749 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_COMPAREVALUE),false);
740.1750 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_COMPARECHANGES),false);
740.1751 +					if(!SelectingByKeyboard())
740.1752 +						SelectEditControl(IDC_EDIT_COMPAREADDRESS);
740.1753 +				}	{rv = true; break;}
740.1754 +				case IDC_NUMBEROFCHANGES:
740.1755 +				{
740.1756 +					rs_c = 'n';
740.1757 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_COMPARECHANGES),true);
740.1758 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_COMPAREVALUE),false);
740.1759 +					EnableWindow(GetDlgItem(hDlg,IDC_EDIT_COMPAREADDRESS),false);
740.1760 +					if(!SelectingByKeyboard())
740.1761 +						SelectEditControl(IDC_EDIT_COMPARECHANGES);
740.1762 +				}	{rv = true; break;}
740.1763 +				case IDC_C_ADDCHEAT:
740.1764 +				{
740.1765 +					HWND ramListControl = GetDlgItem(hDlg,IDC_RAMLIST);
740.1766 +					int watchItemIndex = ListView_GetNextItem(ramListControl, -1, LVNI_SELECTED);
740.1767 +					while (watchItemIndex >= 0)
740.1768 +					{
740.1769 +						unsigned long address = CALL_WITH_T_SIZE_TYPES_1(GetHardwareAddressFromItemIndex, rs_type_size,rs_t=='s',noMisalign, watchItemIndex);
740.1770 +
740.1771 +						int sizeType = -1;
740.1772 +						if(rs_type_size == 'b')
740.1773 +							sizeType = 0;
740.1774 +						else if(rs_type_size == 'w')
740.1775 +							sizeType = 1;
740.1776 +						else if(rs_type_size == 'd')
740.1777 +							sizeType = 2;
740.1778 +
740.1779 +						int numberType = -1;
740.1780 +						if(rs_t == 's')
740.1781 +							numberType = 0;
740.1782 +						else if(rs_t == 'u')
740.1783 +							numberType = 1;
740.1784 +						else if(rs_t == 'h')
740.1785 +							numberType = 2;
740.1786 +
740.1787 +						if(systemCartridgeType == 0)
740.1788 +						{
740.1789 +							AddCheat dlg (address/*, hDlg*/);
740.1790 +							if(sizeType != -1) dlg.sizeType = sizeType;
740.1791 +							if(numberType != -1) dlg.numberType = numberType;
740.1792 +							dlg.DoModal();
740.1793 +						}
740.1794 +						else
740.1795 +						{
740.1796 +							AddGBCheat dlg (address/*, hDlg*/);
740.1797 +							if(sizeType != -1) dlg.sizeType = sizeType;
740.1798 +							if(numberType != -1) dlg.numberType = numberType;
740.1799 +							dlg.DoModal();
740.1800 +						}
740.1801 +						watchItemIndex = ListView_GetNextItem(ramListControl, watchItemIndex, LVNI_SELECTED);
740.1802 +					}
740.1803 +				}	{rv = true; break;}
740.1804 +				case IDC_C_RESET:
740.1805 +				{
740.1806 +					RamSearchSaveUndoStateIfNotTooBig(RamSearchHWnd);
740.1807 +					int prevNumItems = last_rs_possible;
740.1808 +
740.1809 +					soft_reset_address_info();
740.1810 +
740.1811 +					if(prevNumItems == last_rs_possible)
740.1812 +						SetRamSearchUndoType(RamSearchHWnd, 0); // nothing to undo
740.1813 +
740.1814 +					ListView_SetItemState(GetDlgItem(hDlg,IDC_RAMLIST), -1, 0, LVIS_SELECTED); // deselect all
740.1815 +					//ListView_SetItemCount(GetDlgItem(hDlg,IDC_RAMLIST),ResultCount);
740.1816 +					ListView_SetSelectionMark(GetDlgItem(hDlg,IDC_RAMLIST), 0);
740.1817 +					RefreshRamListSelectedCountControlStatus(hDlg);
740.1818 +					{rv = true; break;}
740.1819 +				}
740.1820 +				case IDC_C_RESET_CHANGES:
740.1821 +					memset(s_numChanges, 0, (sizeof(*s_numChanges)*(MAX_RAM_SIZE)));
740.1822 +					ListView_Update(GetDlgItem(hDlg,IDC_RAMLIST), -1);
740.1823 +					//SetRamSearchUndoType(hDlg, 0);
740.1824 +					{rv = true; break;}
740.1825 +				case IDC_C_UNDO:
740.1826 +					if(s_undoType>0)
740.1827 +					{
740.1828 +						systemSoundClearBuffer();
740.1829 +						EnterCriticalSection(&s_activeMemoryRegionsCS);
740.1830 +						if(s_activeMemoryRegions.size() < tooManyRegionsForUndo)
740.1831 +						{
740.1832 +							MemoryList tempMemoryList = s_activeMemoryRegions;
740.1833 +							s_activeMemoryRegions = s_activeMemoryRegionsBackup;
740.1834 +							s_activeMemoryRegionsBackup = tempMemoryList;
740.1835 +							LeaveCriticalSection(&s_activeMemoryRegionsCS);
740.1836 +							SetRamSearchUndoType(hDlg, 3 - s_undoType);
740.1837 +						}
740.1838 +						else
740.1839 +						{
740.1840 +							s_activeMemoryRegions = s_activeMemoryRegionsBackup;
740.1841 +							LeaveCriticalSection(&s_activeMemoryRegionsCS);
740.1842 +							SetRamSearchUndoType(hDlg, -1);
740.1843 +						}
740.1844 +						CompactAddrs();
740.1845 +						ListView_SetItemState(GetDlgItem(hDlg,IDC_RAMLIST), -1, 0, LVIS_SELECTED); // deselect all
740.1846 +						ListView_SetSelectionMark(GetDlgItem(hDlg,IDC_RAMLIST), 0);
740.1847 +						RefreshRamListSelectedCountControlStatus(hDlg);
740.1848 +					}
740.1849 +					{rv = true; break;}
740.1850 +				case IDC_C_AUTOSEARCH:
740.1851 +					AutoSearch = SendDlgItemMessage(hDlg, IDC_C_AUTOSEARCH, BM_GETCHECK, 0, 0) != 0;
740.1852 +					AutoSearchAutoRetry = false;
740.1853 +					if (!AutoSearch) {rv = true; break;}
740.1854 +				case IDC_C_SEARCH:
740.1855 +				{
740.1856 +					systemSoundClearBuffer();
740.1857 +
740.1858 +					if(!rs_val_valid && !(rs_val_valid = Set_RS_Val()))
740.1859 +						goto invalid_field;
740.1860 +
740.1861 +					if(ResultCount)
740.1862 +					{
740.1863 +						RamSearchSaveUndoStateIfNotTooBig(hDlg);
740.1864 +
740.1865 +						prune(rs_c,rs_o,rs_t=='s',rs_val,rs_param);
740.1866 +
740.1867 +						RefreshRamListSelectedCountControlStatus(hDlg);
740.1868 +					}
740.1869 +
740.1870 +					if(!ResultCount)
740.1871 +					{
740.1872 +
740.1873 +						MessageBox(RamSearchHWnd,"Resetting search.","Out of results.",MB_OK|MB_ICONINFORMATION);
740.1874 +						soft_reset_address_info();
740.1875 +					}
740.1876 +
740.1877 +					{rv = true; break;}
740.1878 +
740.1879 +invalid_field:
740.1880 +					MessageBox(RamSearchHWnd,"Invalid or out-of-bound entered value.","Error",MB_OK|MB_ICONSTOP);
740.1881 +					if(AutoSearch) // stop autosearch if it just started
740.1882 +					{
740.1883 +						SendDlgItemMessage(hDlg, IDC_C_AUTOSEARCH, BM_SETCHECK, BST_UNCHECKED, 0);
740.1884 +						SendMessage(hDlg, WM_COMMAND, IDC_C_AUTOSEARCH, 0);
740.1885 +					}
740.1886 +					{rv = true; break;}
740.1887 +				}
740.1888 +				case IDC_C_WATCH:
740.1889 +				{
740.1890 +					HWND ramListControl = GetDlgItem(hDlg,IDC_RAMLIST);
740.1891 +					int selCount = ListView_GetSelectedCount(ramListControl);
740.1892 +
740.1893 +					bool inserted = false;
740.1894 +					int watchItemIndex = ListView_GetNextItem(ramListControl, -1, LVNI_SELECTED);
740.1895 +					while (watchItemIndex >= 0)
740.1896 +					{
740.1897 +						AddressWatcher tempWatch;
740.1898 +						tempWatch.Address = CALL_WITH_T_SIZE_TYPES_1(GetHardwareAddressFromItemIndex, rs_type_size,rs_t=='s',noMisalign, watchItemIndex);
740.1899 +						tempWatch.Size = rs_type_size;
740.1900 +						tempWatch.Type = rs_t;
740.1901 +						tempWatch.WrongEndian = 0; //Replace when I get little endian working
740.1902 +						tempWatch.comment = NULL;
740.1903 +
740.1904 +						if (selCount == 1)
740.1905 +							inserted |= InsertWatch(tempWatch, hDlg);
740.1906 +						else
740.1907 +							inserted |= InsertWatch(tempWatch, "");
740.1908 +
740.1909 +						watchItemIndex = ListView_GetNextItem(ramListControl, watchItemIndex, LVNI_SELECTED);
740.1910 +					}
740.1911 +					// bring up the ram watch window if it's not already showing so the user knows where the watch went
740.1912 +					if(inserted && !RamWatchHWnd)
740.1913 +						SendMessage(hWnd, WM_COMMAND, ID_RAM_WATCH, 0);
740.1914 +					SetForegroundWindow(RamSearchHWnd);
740.1915 +					{rv = true; break;}
740.1916 +				}
740.1917 +
740.1918 +				// eliminate all selected items
740.1919 +				case IDC_C_ELIMINATE:
740.1920 +				{
740.1921 +					RamSearchSaveUndoStateIfNotTooBig(hDlg);
740.1922 +
740.1923 +					HWND ramListControl = GetDlgItem(hDlg,IDC_RAMLIST);
740.1924 +					int size = (rs_type_size=='b' || !noMisalign) ? 1 : 2;
740.1925 +					int selCount = ListView_GetSelectedCount(ramListControl);
740.1926 +					int watchIndex = -1;
740.1927 +
740.1928 +					// time-saving trick #1:
740.1929 +					// condense the selected items into an array of address ranges
740.1930 +					std::vector<AddrRange> selHardwareAddrs;
740.1931 +					for(int i = 0, j = 1024; i < selCount; ++i, --j)
740.1932 +					{
740.1933 +						watchIndex = ListView_GetNextItem(ramListControl, watchIndex, LVNI_SELECTED);
740.1934 +						int addr = CALL_WITH_T_SIZE_TYPES_1(GetHardwareAddressFromItemIndex, rs_type_size,rs_t=='s',noMisalign, watchIndex);
740.1935 +						if(!selHardwareAddrs.empty() && addr == selHardwareAddrs.back().End())
740.1936 +							selHardwareAddrs.back().size += size;
740.1937 +						else
740.1938 +							selHardwareAddrs.push_back(AddrRange(addr,size));
740.1939 +
740.1940 +						if(!j) UpdateRamSearchProgressBar(i * 50 / selCount), j = 1024;
740.1941 +					}
740.1942 +
740.1943 +					// now deactivate the ranges
740.1944 +
740.1945 +					// time-saving trick #2:
740.1946 +					// take advantage of the fact that the listbox items must be in the same order as the regions
740.1947 +					MemoryList::iterator iter = s_activeMemoryRegions.begin();
740.1948 +					int numHardwareAddrRanges = selHardwareAddrs.size();
740.1949 +					for(int i = 0, j = 16; i < numHardwareAddrRanges; ++i, --j)
740.1950 +					{
740.1951 +						int addr = selHardwareAddrs[i].addr;
740.1952 +						int size = selHardwareAddrs[i].size;
740.1953 +						bool affected = false;
740.1954 +						while(iter != s_activeMemoryRegions.end())
740.1955 +						{
740.1956 +							MemoryRegion& region = *iter;
740.1957 +							int affNow = DeactivateRegion(region, iter, addr, size);
740.1958 +							if(affNow)
740.1959 +								affected = true;
740.1960 +							else if(affected)
740.1961 +								break;
740.1962 +							if(affNow != 2)
740.1963 +								++iter;
740.1964 +						}
740.1965 +
740.1966 +						if(!j) UpdateRamSearchProgressBar(50 + (i * 50 / selCount)), j = 16;
740.1967 +					}
740.1968 +					UpdateRamSearchTitleBar();
740.1969 +
740.1970 +					// careful -- if the above two time-saving tricks aren't working,
740.1971 +					// the runtime can absolutely explode (seconds -> hours) when there are lots of regions
740.1972 +
740.1973 +					ListView_SetItemState(ramListControl, -1, 0, LVIS_SELECTED); // deselect all
740.1974 +					signal_new_size();
740.1975 +					{rv = true; break;}
740.1976 +				}
740.1977 +				//case IDOK:
740.1978 +				case IDCANCEL:
740.1979 +					RamSearchHWnd = NULL;
740.1980 +/*					if (theApp.pauseDuringCheatSearch)
740.1981 +						EndDialog(hDlg, true);	// this should never be called on a modeless dialog
740.1982 +					else
740.1983 +*/
740.1984 +						DestroyWindow(hDlg);
740.1985 +					{rv = true; break;}
740.1986 +			}
740.1987 +
740.1988 +			// check refresh for comparison preview color update
740.1989 +			// also, update rs_val if needed
740.1990 +			bool needRefresh = false;
740.1991 +			switch(LOWORD(wParam))
740.1992 +			{
740.1993 +				case IDC_LESSTHAN:
740.1994 +				case IDC_MORETHAN:
740.1995 +				case IDC_NOMORETHAN:
740.1996 +				case IDC_NOLESSTHAN:
740.1997 +				case IDC_EQUALTO:
740.1998 +				case IDC_DIFFERENTFROM:
740.1999 +				case IDC_DIFFERENTBY:
740.2000 +				case IDC_MODULO:
740.2001 +				case IDC_PREVIOUSVALUE:
740.2002 +				case IDC_SPECIFICVALUE:
740.2003 +				case IDC_SPECIFICADDRESS:
740.2004 +				case IDC_NUMBEROFCHANGES:
740.2005 +				case IDC_SIGNED:
740.2006 +				case IDC_UNSIGNED:
740.2007 +				case IDC_HEX:
740.2008 +					rs_val_valid = Set_RS_Val();
740.2009 +					needRefresh = true;
740.2010 +					break;
740.2011 +				case IDC_EDIT_COMPAREVALUE:
740.2012 +				case IDC_EDIT_COMPAREADDRESS:
740.2013 +				case IDC_EDIT_COMPARECHANGES:
740.2014 +				case IDC_EDIT_DIFFBY:
740.2015 +				case IDC_EDIT_MODBY:
740.2016 +					if(HIWORD(wParam) == EN_CHANGE)
740.2017 +					{
740.2018 +						rs_val_valid = Set_RS_Val();
740.2019 +						needRefresh = true;
740.2020 +					}
740.2021 +					break;
740.2022 +			}
740.2023 +			if(needRefresh)
740.2024 +				ListView_Update(GetDlgItem(hDlg,IDC_RAMLIST), -1);
740.2025 +
740.2026 +
740.2027 +			return rv;
740.2028 +		}	break;
740.2029 +
740.2030 +		case WM_CLOSE:
740.2031 +			RECT r;
740.2032 +			GetWindowRect(hDlg, &r);
740.2033 +			regSetDwordValue("ramSearchX", r.left);
740.2034 +			regSetDwordValue("ramSearchY", r.top);
740.2035 +			SendMessage(RamSearchHWnd, WM_DESTROY, 0, 0);
740.2036 +			break;
740.2037 +		case WM_DESTROY:
740.2038 +			RamSearchHWnd = NULL;
740.2039 +//			theApp.modelessCheatDialogIsOpen = false;
740.2040 +//			return true;
740.2041 +			break;
740.2042 +	}
740.2043 +
740.2044 +	return false;
740.2045 +}
740.2046 +
740.2047 +void UpdateRamSearchTitleBar(int percent)
740.2048 +{
740.2049 +#define HEADER_STR " RAM Search - "
740.2050 +#define PROGRESS_STR " %d%% ... "
740.2051 +#define STATUS_STR "%d Possibilit%s (%d Region%s)"
740.2052 +
740.2053 +	int poss = last_rs_possible;
740.2054 +	int regions = last_rs_regions;
740.2055 +	if(poss <= 0)
740.2056 +		strcpy(Str_Tmp," RAM Search");
740.2057 +	else if(percent <= 0)
740.2058 +		sprintf(Str_Tmp, HEADER_STR STATUS_STR, poss, poss==1?"y":"ies", regions, regions==1?"":"s");
740.2059 +	else
740.2060 +		sprintf(Str_Tmp, PROGRESS_STR STATUS_STR, percent, poss, poss==1?"y":"ies", regions, regions==1?"":"s");
740.2061 +	SetWindowText(RamSearchHWnd, Str_Tmp);
740.2062 +}
740.2063 +
740.2064 +void UpdatePossibilities(int rs_possible, int regions)
740.2065 +{
740.2066 +	if(rs_possible != last_rs_possible)
740.2067 +	{
740.2068 +		last_rs_possible = rs_possible;
740.2069 +		last_rs_regions = regions;
740.2070 +		UpdateRamSearchTitleBar();
740.2071 +	}
740.2072 +}
740.2073 +
740.2074 +void SetRamSearchUndoType(HWND hDlg, int type)
740.2075 +{
740.2076 +	if(s_undoType != type)
740.2077 +	{
740.2078 +		if((s_undoType!=2 && s_undoType!=-1)!=(type!=2 && type!=-1))
740.2079 +			SendDlgItemMessage(hDlg,IDC_C_UNDO,WM_SETTEXT,0,(LPARAM)((type == 2 || type == -1) ? "Redo" : "Undo"));
740.2080 +		if((s_undoType>0)!=(type>0))
740.2081 +			EnableWindow(GetDlgItem(hDlg,IDC_C_UNDO),type>0);
740.2082 +		s_undoType = type;
740.2083 +	}
740.2084 +}
740.2085 +
740.2086 +void RamSearchSaveUndoStateIfNotTooBig(HWND hDlg)
740.2087 +{
740.2088 +	EnterCriticalSection(&s_activeMemoryRegionsCS);
740.2089 +	if(s_activeMemoryRegions.size() < tooManyRegionsForUndo)
740.2090 +	{
740.2091 +		s_activeMemoryRegionsBackup = s_activeMemoryRegions;
740.2092 +		LeaveCriticalSection(&s_activeMemoryRegionsCS);
740.2093 +		SetRamSearchUndoType(hDlg, 1);
740.2094 +	}
740.2095 +	else
740.2096 +	{
740.2097 +		LeaveCriticalSection(&s_activeMemoryRegionsCS);
740.2098 +		SetRamSearchUndoType(hDlg, 0);
740.2099 +	}
740.2100 +}
740.2101 +
740.2102 +struct InitRamSearch
740.2103 +{
740.2104 +	InitRamSearch()
740.2105 +	{
740.2106 +		InitializeCriticalSection(&s_activeMemoryRegionsCS);
740.2107 +	}
740.2108 +	~InitRamSearch()
740.2109 +	{
740.2110 +		DeleteCriticalSection(&s_activeMemoryRegionsCS);
740.2111 +	}
740.2112 +} initRamSearch;
740.2113 +
740.2114 +
740.2115 +void init_list_box(HWND Box, const char* Strs[], int numColumns, int *columnWidths) //initializes the ram search and/or ram watch listbox
740.2116 +{
740.2117 +	LVCOLUMN Col;
740.2118 +	Col.mask = LVCF_FMT | LVCF_ORDER | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
740.2119 +	Col.fmt = LVCFMT_CENTER;
740.2120 +	for (int i = 0; i < numColumns; i++)
740.2121 +	{
740.2122 +		Col.iOrder = i;
740.2123 +		Col.iSubItem = i;
740.2124 +		Col.pszText = (LPSTR)(Strs[i]);
740.2125 +		Col.cx = columnWidths[i];
740.2126 +		ListView_InsertColumn(Box,i,&Col);
740.2127 +	}
740.2128 +
740.2129 +	ListView_SetExtendedListViewStyle(Box, LVS_EX_FULLROWSELECT);
740.2130 +}
   741.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   741.2 +++ b/src/win32/ram_search.h	Sat Mar 03 10:31:27 2012 -0600
   741.3 @@ -0,0 +1,34 @@
   741.4 +#ifndef RAM_SEARCH_H
   741.5 +#define RAM_SEARCH_H
   741.6 +
   741.7 +
   741.8 +extern char rs_type_size;
   741.9 +extern int ResultCount;
  741.10 +typedef unsigned int HWAddressType;
  741.11 +
  741.12 +unsigned int sizeConv(unsigned int index,char size, char *prevSize = &rs_type_size, bool usePrev = false);
  741.13 +unsigned int GetRamValue(unsigned int Addr,char Size);
  741.14 +void prune(char Search, char Operater, char Type, int Value, int OperatorParameter);
  741.15 +void CompactAddrs();
  741.16 +void reset_address_info();
  741.17 +void signal_new_frame();
  741.18 +void signal_new_size();
  741.19 +void UpdateRamSearchTitleBar(int percent = 0);
  741.20 +void SetRamSearchUndoType(HWND hDlg, int type);
  741.21 +unsigned int ReadValueAtHardwareAddress(HWAddressType address, unsigned int size);
  741.22 +bool WriteValueAtHardwareAddress(HWAddressType address, unsigned int value, unsigned int size);
  741.23 +bool IsHardwareAddressValid(HWAddressType address);
  741.24 +extern int curr_ram_size;
  741.25 +extern bool noMisalign;
  741.26 +extern HWND RamSearchHWnd;
  741.27 +
  741.28 +
  741.29 +void ResetResults();
  741.30 +void CloseRamWindows(); //Close the Ram Search & Watch windows when rom closes
  741.31 +void ReopenRamWindows(); //Reopen them when a new Rom is loaded
  741.32 +void Update_RAM_Search(); //keeps RAM values up to date in the search and watch windows
  741.33 +
  741.34 +
  741.35 +
  741.36 +#endif
  741.37 +
   742.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   742.2 +++ b/src/win32/ramwatch.cpp	Sat Mar 03 10:31:27 2012 -0600
   742.3 @@ -0,0 +1,1249 @@
   742.4 +#include "stdafx.h"
   742.5 +#include "VBA.h"
   742.6 +#include "resource.h"
   742.7 +#include "WinMiscUtil.h"
   742.8 +#include "GBACheatsDlg.h"
   742.9 +#include "GBCheatsDlg.h"
  742.10 +#include "ram_search.h"
  742.11 +#include "ramwatch.h"
  742.12 +#include "reg.h"
  742.13 +#include "Sound.h"
  742.14 +#include <cassert>
  742.15 +#include <windows.h>
  742.16 +#include <string>
  742.17 +
  742.18 +/*
  742.19 +#include <commctrl.h>
  742.20 +#pragma comment(lib, "comctl32.lib")
  742.21 +#include <shellapi.h>
  742.22 +#pragma comment(lib, "shell32.lib")
  742.23 +#include <commdlg.h>
  742.24 +#pragma comment(lib, "comdlg32.lib")
  742.25 +*/
  742.26 +
  742.27 +static HMENU ramwatchmenu;
  742.28 +static HMENU rwrecentmenu;
  742.29 +/*static*/ HACCEL RamWatchAccels = NULL;
  742.30 +char rw_recent_files[MAX_RECENT_WATCHES][1024];
  742.31 +//char Watch_Dir[1024]="";
  742.32 +bool RWfileChanged = false; //Keeps track of whether the current watch file has been changed, if so, ramwatch will prompt to save changes
  742.33 +bool AutoRWLoad = false;    //Keeps track of whether Auto-load is checked
  742.34 +bool RWSaveWindowPos = false; //Keeps track of whether Save Window position is checked
  742.35 +char currentWatch[1024];
  742.36 +int ramw_x, ramw_y;			//Used to store ramwatch dialog window positions
  742.37 +AddressWatcher rswatches[MAX_WATCH_COUNT];
  742.38 +int WatchCount=0;
  742.39 +static int s_prevSelCount=-1;
  742.40 +
  742.41 +HWND RamWatchHWnd;
  742.42 +#define gamefilename theApp.gameFilename
  742.43 +#define hWnd AfxGetMainWnd()->GetSafeHwnd()
  742.44 +#define hInst AfxGetInstanceHandle()
  742.45 +static char Str_Tmp [1024];
  742.46 +
  742.47 +void init_list_box(HWND Box, const char* Strs[], int numColumns, int *columnWidths); //initializes the ram search and/or ram watch listbox
  742.48 +
  742.49 +#define MESSAGEBOXPARENT (RamWatchHWnd ? RamWatchHWnd : hWnd)
  742.50 +
  742.51 +bool QuickSaveWatches();
  742.52 +bool ResetWatches();
  742.53 +
  742.54 +void RefreshWatchListSelectedCountControlStatus(HWND hDlg);
  742.55 +
  742.56 +unsigned int GetCurrentValue(AddressWatcher& watch)
  742.57 +{
  742.58 +	return ReadValueAtHardwareAddress(watch.Address, watch.Size == 'd' ? 4 : watch.Size == 'w' ? 2 : 1);
  742.59 +}
  742.60 +
  742.61 +bool IsSameWatch(const AddressWatcher& l, const AddressWatcher& r)
  742.62 +{
  742.63 +	if (r.Size == 'S') return false;
  742.64 +	return ((l.Address == r.Address) && (l.Size == r.Size) && (l.Type == r.Type)/* && (l.WrongEndian == r.WrongEndian)*/);
  742.65 +}
  742.66 +
  742.67 +bool VerifyWatchNotAlreadyAdded(const AddressWatcher& watch)
  742.68 +{
  742.69 +	for (int j = 0; j < WatchCount; j++)
  742.70 +	{
  742.71 +		if (IsSameWatch(rswatches[j], watch))
  742.72 +		{
  742.73 +			if(RamWatchHWnd)
  742.74 +				SetForegroundWindow(RamWatchHWnd);
  742.75 +			return false;
  742.76 +		}
  742.77 +	}
  742.78 +	return true;
  742.79 +}
  742.80 +
  742.81 +
  742.82 +bool InsertWatch(const AddressWatcher& Watch, char *Comment)
  742.83 +{
  742.84 +	if(WatchCount >= MAX_WATCH_COUNT)
  742.85 +		return false;
  742.86 +
  742.87 +	int i = WatchCount++;
  742.88 +	AddressWatcher& NewWatch = rswatches[i];
  742.89 +	NewWatch = Watch;
  742.90 +	//if (NewWatch.comment) free(NewWatch.comment);
  742.91 +	NewWatch.comment = (char *) malloc(strlen(Comment)+2);
  742.92 +	NewWatch.CurValue = GetCurrentValue(NewWatch);
  742.93 +	strcpy(NewWatch.comment, Comment);
  742.94 +	ListView_SetItemCount(GetDlgItem(RamWatchHWnd,IDC_WATCHLIST),WatchCount);
  742.95 +	RWfileChanged=true;
  742.96 +
  742.97 +	return true;
  742.98 +}
  742.99 +
 742.100 +LRESULT CALLBACK PromptWatchNameProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) //Gets the description of a watched address
 742.101 +{
 742.102 +	RECT r;
 742.103 +	RECT r2;
 742.104 +	int dx1, dy1, dx2, dy2;
 742.105 +
 742.106 +	switch(uMsg)
 742.107 +	{
 742.108 +		case WM_INITDIALOG:
 742.109 +			//Clear_Sound_Buffer();
 742.110 +
 742.111 +			GetWindowRect(hWnd, &r);
 742.112 +			dx1 = (r.right - r.left) / 2;
 742.113 +			dy1 = (r.bottom - r.top) / 2;
 742.114 +
 742.115 +			GetWindowRect(hDlg, &r2);
 742.116 +			dx2 = (r2.right - r2.left) / 2;
 742.117 +			dy2 = (r2.bottom - r2.top) / 2;
 742.118 +
 742.119 +			//SetWindowPos(hDlg, NULL, max(0, r.left + (dx1 - dx2)), max(0, r.top + (dy1 - dy2)), NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
 742.120 +			SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
 742.121 +			strcpy(Str_Tmp,"Enter a name for this RAM address.");
 742.122 +			SendDlgItemMessage(hDlg,IDC_PROMPT_TEXT,WM_SETTEXT,0,(LPARAM)Str_Tmp);
 742.123 +			strcpy(Str_Tmp,"");
 742.124 +			SendDlgItemMessage(hDlg,IDC_PROMPT_TEXT2,WM_SETTEXT,0,(LPARAM)Str_Tmp);
 742.125 +			return true;
 742.126 +			break;
 742.127 +
 742.128 +		case WM_COMMAND:
 742.129 +			switch(LOWORD(wParam))
 742.130 +			{
 742.131 +				case IDOK:
 742.132 +				{
 742.133 +					GetDlgItemText(hDlg,IDC_PROMPT_EDIT,Str_Tmp,80);
 742.134 +					InsertWatch(rswatches[WatchCount],Str_Tmp);
 742.135 +					EndDialog(hDlg, true);
 742.136 +					return true;
 742.137 +					break;
 742.138 +				}
 742.139 +				case ID_CANCEL:
 742.140 +				case IDCANCEL:
 742.141 +					EndDialog(hDlg, false);
 742.142 +					return false;
 742.143 +					break;
 742.144 +			}
 742.145 +			break;
 742.146 +
 742.147 +		case WM_CLOSE:
 742.148 +			EndDialog(hDlg, false);
 742.149 +			return false;
 742.150 +			break;
 742.151 +	}
 742.152 +
 742.153 +	return false;
 742.154 +}
 742.155 +
 742.156 +bool InsertWatch(const AddressWatcher& Watch, HWND parent)
 742.157 +{
 742.158 +	if(!VerifyWatchNotAlreadyAdded(Watch))
 742.159 +		return false;
 742.160 +
 742.161 +	if(!parent)
 742.162 +		parent = RamWatchHWnd;
 742.163 +	if(!parent)
 742.164 +		parent = hWnd;
 742.165 +
 742.166 +	int prevWatchCount = WatchCount;
 742.167 +
 742.168 +	rswatches[WatchCount] = Watch;
 742.169 +	rswatches[WatchCount].CurValue = GetCurrentValue(rswatches[WatchCount]);
 742.170 +	systemSoundClearBuffer();
 742.171 +	DialogBox(hInst, MAKEINTRESOURCE(IDD_PROMPT), parent, (DLGPROC) PromptWatchNameProc);
 742.172 +
 742.173 +	return WatchCount > prevWatchCount;
 742.174 +}
 742.175 +
 742.176 +void Update_RAM_Watch()
 742.177 +{
 742.178 +	BOOL watchChanged[MAX_WATCH_COUNT] = {0};
 742.179 +
 742.180 +	if(WatchCount)
 742.181 +	{
 742.182 +		// update cached values and detect changes to displayed listview items
 742.183 +
 742.184 +		for(int i = 0; i < WatchCount; i++)
 742.185 +		{
 742.186 +			unsigned int prevCurValue = rswatches[i].CurValue;
 742.187 +			unsigned int newCurValue = GetCurrentValue(rswatches[i]);
 742.188 +			if(prevCurValue != newCurValue)
 742.189 +			{
 742.190 +				rswatches[i].CurValue = newCurValue;
 742.191 +				watchChanged[i] = TRUE;
 742.192 +			}
 742.193 +		}
 742.194 +	}
 742.195 +
 742.196 +	// refresh any visible parts of the listview box that changed
 742.197 +	HWND lv = GetDlgItem(RamWatchHWnd,IDC_WATCHLIST);
 742.198 +	int top = ListView_GetTopIndex(lv);
 742.199 +	int bottom = top + ListView_GetCountPerPage(lv) + 1; // +1 is so we will update a partially-displayed last item
 742.200 +	if(top < 0) top = 0;
 742.201 +	if(bottom > WatchCount) bottom = WatchCount;
 742.202 +	int start = -1;
 742.203 +	for(int i = top; i <= bottom; i++)
 742.204 +	{
 742.205 +		if(start == -1)
 742.206 +		{
 742.207 +			if(i != bottom && watchChanged[i])
 742.208 +			{
 742.209 +				start = i;
 742.210 +				//somethingChanged = true;
 742.211 +			}
 742.212 +		}
 742.213 +		else
 742.214 +		{
 742.215 +			if(i == bottom || !watchChanged[i])
 742.216 +			{
 742.217 +				ListView_RedrawItems(lv, start, i-1);
 742.218 +				start = -1;
 742.219 +			}
 742.220 +		}
 742.221 +	}
 742.222 +}
 742.223 +
 742.224 +bool AskSave()
 742.225 +{
 742.226 +	//This function asks to save changes if the watch file contents have changed
 742.227 +	//returns false only if a save was attempted but failed or was cancelled
 742.228 +	if (RWfileChanged)
 742.229 +	{
 742.230 +		systemSoundClearBuffer();
 742.231 +		int answer = MessageBox(MESSAGEBOXPARENT, "Save Changes?", "Ram Watch", MB_YESNOCANCEL);
 742.232 +		if(answer == IDYES)
 742.233 +			if(!QuickSaveWatches())
 742.234 +				return false;
 742.235 +		return (answer != IDCANCEL);
 742.236 +	}
 742.237 +	return true;
 742.238 +}
 742.239 +
 742.240 +void WriteRecentRWFiles()
 742.241 +{
 742.242 +	char str[2048];
 742.243 +	for (int i = 0; i < MAX_RECENT_WATCHES; i++)
 742.244 +	{
 742.245 +		sprintf(str, "recentWatch%d", i+1);
 742.246 +		regSetStringValue(str, &rw_recent_files[i][0]);
 742.247 +	}
 742.248 +}
 742.249 +
 742.250 +void UpdateRW_RMenu(HMENU menu, unsigned int mitem, unsigned int baseid)
 742.251 +{
 742.252 +	MENUITEMINFO moo;
 742.253 +	int x;
 742.254 +
 742.255 +	moo.cbSize = sizeof(moo);
 742.256 +	moo.fMask = MIIM_SUBMENU | MIIM_STATE;
 742.257 +
 742.258 +	GetMenuItemInfo(GetSubMenu(ramwatchmenu, 0), mitem, FALSE, &moo);
 742.259 +	moo.hSubMenu = menu;
 742.260 +	moo.fState = strlen(rw_recent_files[0]) ? MFS_ENABLED : MFS_GRAYED;
 742.261 +
 742.262 +	SetMenuItemInfo(GetSubMenu(ramwatchmenu, 0), mitem, FALSE, &moo);
 742.263 +
 742.264 +	// Remove all recent files submenus
 742.265 +	for(x = 0; x < MAX_RECENT_WATCHES; x++)
 742.266 +	{
 742.267 +		RemoveMenu(menu, baseid + x, MF_BYCOMMAND);
 742.268 +	}
 742.269 +
 742.270 +	// Recreate the menus
 742.271 +	for(x = MAX_RECENT_WATCHES - 1; x >= 0; x--)
 742.272 +	{  
 742.273 +		// Skip empty strings
 742.274 +		if(!strlen(rw_recent_files[x]))
 742.275 +		{
 742.276 +			continue;
 742.277 +		}
 742.278 +
 742.279 +		moo.cbSize = sizeof(moo);
 742.280 +		moo.fMask = MIIM_DATA | MIIM_ID | MIIM_TYPE;
 742.281 +
 742.282 +#if 0
 742.283 +		const int TEMP_STRING_LENGTH = 128 + 5;
 742.284 +		char tmp[TEMP_STRING_LENGTH];	// FIXME?
 742.285 +
 742.286 +		// Fill in the menu text.
 742.287 +		if(strlen(rw_recent_files[x]) < 128)
 742.288 +		{
 742.289 +			sprintf(tmp, "&%d. %s", ( x + 1 ) % 10, rw_recent_files[x]);
 742.290 +		}
 742.291 +		else
 742.292 +		{
 742.293 +			sprintf(tmp, "&%d. %s", ( x + 1 ) % 10, rw_recent_files[x] + strlen( rw_recent_files[x] ) - 127);
 742.294 +		}
 742.295 +#endif
 742.296 +		// the ATL way; it is really pain to work out a MBCS-compatible string replace function in the pure c way
 742.297 +		CString atltmp(rw_recent_files[x]);
 742.298 +		atltmp.Replace("&", "&&");
 742.299 +		char *tmp = atltmp.GetBuffer(0);
 742.300 +
 742.301 +		// Insert the menu item
 742.302 +		moo.cch = strlen(tmp);
 742.303 +		moo.fType = 0;
 742.304 +		moo.wID = baseid + x;
 742.305 +		moo.dwTypeData = tmp;
 742.306 +		InsertMenuItem(menu, 0, 1, &moo);
 742.307 +
 742.308 +		// atltmp.ReleaseBuffer();
 742.309 +	}
 742.310 +
 742.311 +	// I don't think one function shall do so many things in a row
 742.312 +//	WriteRecentRWFiles();	// write recent menu to ini
 742.313 +}
 742.314 +
 742.315 +void UpdateRWRecentArray(const char* addString, unsigned int arrayLen, HMENU menu, unsigned int menuItem, unsigned int baseId)
 742.316 +{
 742.317 +	const size_t len = 1024; // Avoid magic numbers
 742.318 +
 742.319 +	// Try to find out if the filename is already in the recent files list.
 742.320 +	for(unsigned int x = 0; x < arrayLen; x++)
 742.321 +	{
 742.322 +		if(strlen(rw_recent_files[x]))
 742.323 +		{
 742.324 +			if(!strncmp(rw_recent_files[x], addString, 1024))    // Item is already in list.
 742.325 +			{
 742.326 +				// If the filename is in the file list don't add it again.
 742.327 +				// Move it up in the list instead.
 742.328 +
 742.329 +				int y;
 742.330 +				char tmp[len];
 742.331 +
 742.332 +				// Save pointer.
 742.333 +				strncpy(tmp, rw_recent_files[x], len - 1);	// assuming rw_recent_files[n] is 0-terminated
 742.334 +				
 742.335 +				for(y = x; y; y--)
 742.336 +				{
 742.337 +					// Move items down.
 742.338 +					strncpy(rw_recent_files[y], rw_recent_files[y - 1], len);
 742.339 +				}
 742.340 +
 742.341 +				// Put item on top.
 742.342 +				strncpy(rw_recent_files[0],tmp, len);
 742.343 +
 742.344 +				// Update the recent files menu
 742.345 +				UpdateRW_RMenu(menu, menuItem, baseId);
 742.346 +
 742.347 +				return;
 742.348 +			}
 742.349 +		}
 742.350 +	}
 742.351 +
 742.352 +	// The filename wasn't found in the list. That means we need to add it.
 742.353 +
 742.354 +	// Move the other items down.
 742.355 +	for(unsigned int x = arrayLen - 1; x; x--)
 742.356 +	{
 742.357 +		strncpy(rw_recent_files[x],rw_recent_files[x - 1], len);
 742.358 +	}
 742.359 +
 742.360 +	// Add the new item.
 742.361 +	strncpy(rw_recent_files[0], addString, len);
 742.362 +	rw_recent_files[0][len - 1] = '\0';	// better not assume that
 742.363 +
 742.364 +	// Update the recent files menu
 742.365 +	UpdateRW_RMenu(menu, menuItem, baseId);
 742.366 +}
 742.367 +
 742.368 +void RWAddRecentFile(const char *filename)
 742.369 +{
 742.370 +	UpdateRWRecentArray(filename, MAX_RECENT_WATCHES, rwrecentmenu, RAMMENU_FILE_RECENT, RW_MENU_FIRST_RECENT_FILE);
 742.371 +}
 742.372 +
 742.373 +void OpenRWRecentFile(int memwRFileNumber)
 742.374 +{
 742.375 +	if(!ResetWatches())
 742.376 +		return;
 742.377 +
 742.378 +	int rnum = memwRFileNumber;
 742.379 +	if ((unsigned int)rnum >= MAX_RECENT_WATCHES)
 742.380 +		return; //just in case
 742.381 +
 742.382 +	char* x;
 742.383 +
 742.384 +	while(true)
 742.385 +	{
 742.386 +		x = rw_recent_files[rnum];
 742.387 +		if (!*x) 
 742.388 +			return;		//If no recent files exist just return.  Useful for Load last file on startup (or if something goes screwy)
 742.389 +
 742.390 +		if (rnum) //Change order of recent files if not most recent
 742.391 +		{
 742.392 +			RWAddRecentFile(x);
 742.393 +			rnum = 0;
 742.394 +		}
 742.395 +		else
 742.396 +		{
 742.397 +			break;
 742.398 +		}
 742.399 +	}
 742.400 +
 742.401 +	strcpy(currentWatch,x);
 742.402 +	strcpy(Str_Tmp,currentWatch);
 742.403 +
 742.404 +	//loadwatches here
 742.405 +	FILE *WatchFile = fopen(Str_Tmp,"rb");
 742.406 +	if (!WatchFile)
 742.407 +	{
 742.408 +		systemSoundClearBuffer();
 742.409 +		int answer = MessageBox(MESSAGEBOXPARENT,"Error opening file.","ERROR",MB_OKCANCEL);
 742.410 +		if (answer == IDOK)
 742.411 +		{
 742.412 +			rw_recent_files[rnum][0] = '\0';	//Clear file from list 
 742.413 +			if (rnum)							//Update the ramwatch list
 742.414 +				RWAddRecentFile(rw_recent_files[0]); 
 742.415 +			else
 742.416 +				RWAddRecentFile(rw_recent_files[1]);
 742.417 +		}
 742.418 +		return;
 742.419 +	}
 742.420 +	const char DELIM = '\t';
 742.421 +	AddressWatcher Temp;
 742.422 +	char mode;
 742.423 +	fgets(Str_Tmp,1024,WatchFile);
 742.424 +	sscanf(Str_Tmp,"%c%*s",&mode);
 742.425 +	//if ((mode == '1' && !(SegaCD_Started)) || (mode == '2' && !(_32X_Started)))
 742.426 +	//{
 742.427 +	//	char Device[8];
 742.428 +	//	strcpy(Device,(mode > '1')?"32X":"SegaCD");
 742.429 +	//	sprintf(Str_Tmp,"Warning: %s not started. \nWatches for %s addresses will be ignored.",Device,Device);
 742.430 +	//	MessageBox(MESSAGEBOXPARENT,Str_Tmp,"Possible Device Mismatch",MB_OK);
 742.431 +	//}
 742.432 +	int WatchAdd;
 742.433 +	fgets(Str_Tmp,1024,WatchFile);
 742.434 +	sscanf(Str_Tmp,"%d%*s",&WatchAdd);
 742.435 +	WatchAdd+=WatchCount;
 742.436 +	for (int i = WatchCount; i < WatchAdd; i++)
 742.437 +	{
 742.438 +		while (i < 0)
 742.439 +			i++;
 742.440 +		do {
 742.441 +			fgets(Str_Tmp,1024,WatchFile);
 742.442 +		} while (Str_Tmp[0] == '\n');
 742.443 +		sscanf(Str_Tmp,"%*05X%*c%08X%*c%c%*c%c%*c%d",&(Temp.Address),&(Temp.Size),&(Temp.Type),&(Temp.WrongEndian));
 742.444 +		Temp.WrongEndian = 0;
 742.445 +		char *Comment = strrchr(Str_Tmp,DELIM) + 1;
 742.446 +		*strrchr(Comment,'\n') = '\0';
 742.447 +		InsertWatch(Temp,Comment);
 742.448 +	}
 742.449 +
 742.450 +	fclose(WatchFile);
 742.451 +	if (RamWatchHWnd) {
 742.452 +		ListView_SetItemCount(GetDlgItem(RamWatchHWnd,IDC_WATCHLIST),WatchCount);
 742.453 +		RefreshWatchListSelectedCountControlStatus(RamWatchHWnd);
 742.454 +	}
 742.455 +	RWfileChanged=false;
 742.456 +	return;
 742.457 +}
 742.458 +
 742.459 +int Change_File_L(char *Dest, const char *Dir, const char *Titre, const char *Filter, const char *Ext, HWND hwnd)
 742.460 +{
 742.461 +	if (!strcmp(Dest, ""))
 742.462 +	{
 742.463 +		strcpy(Dest, "default.");
 742.464 +		strcat(Dest, Ext);
 742.465 +	}
 742.466 +
 742.467 +	SetCurrentDirectory(winGetDestDir(IDS_WATCH_DIR));
 742.468 +
 742.469 +	OPENFILENAME ofn;
 742.470 +
 742.471 +	memset(&ofn, 0, sizeof(OPENFILENAME));
 742.472 +
 742.473 +	ofn.lStructSize = sizeof(OPENFILENAME);
 742.474 +	ofn.hwndOwner = hwnd;
 742.475 +	ofn.hInstance = hInst;
 742.476 +	ofn.lpstrFile = Dest;
 742.477 +	ofn.nMaxFile = 2047;
 742.478 +	ofn.lpstrFilter = Filter;
 742.479 +	ofn.nFilterIndex = 1;
 742.480 +	ofn.lpstrInitialDir = Dir;
 742.481 +	ofn.lpstrTitle = Titre;
 742.482 +	ofn.lpstrDefExt = Ext;
 742.483 +	ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
 742.484 +
 742.485 +	systemSoundClearBuffer();
 742.486 +
 742.487 +	if (GetOpenFileName(&ofn)) return 1;
 742.488 +
 742.489 +	return 0;
 742.490 +}
 742.491 +
 742.492 +int Change_File_S(char *Dest, const char *Dir, const char *Titre, const char *Filter, const char *Ext, HWND hwnd)
 742.493 +{
 742.494 +	if (!strcmp(Dest, ""))
 742.495 +	{
 742.496 +		strcpy(Dest, "default.");
 742.497 +		strcat(Dest, Ext);
 742.498 +	}
 742.499 +
 742.500 +	SetCurrentDirectory(winGetDestDir(IDS_WATCH_DIR));
 742.501 +
 742.502 +	OPENFILENAME ofn;
 742.503 +
 742.504 +	memset(&ofn, 0, sizeof(OPENFILENAME));
 742.505 +
 742.506 +	ofn.lStructSize = sizeof(OPENFILENAME);
 742.507 +	ofn.hwndOwner = hwnd;
 742.508 +	ofn.hInstance = hInst;
 742.509 +	ofn.lpstrFile = Dest;
 742.510 +	ofn.nMaxFile = 2047;
 742.511 +	ofn.lpstrFilter = Filter;
 742.512 +	ofn.nFilterIndex = 1;
 742.513 +	ofn.lpstrInitialDir = Dir;
 742.514 +	ofn.lpstrTitle = Titre;
 742.515 +	ofn.lpstrDefExt = Ext;
 742.516 +	ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
 742.517 +
 742.518 +	if (GetSaveFileName(&ofn)) return 1;
 742.519 +
 742.520 +	return 0;
 742.521 +}
 742.522 +
 742.523 +bool Save_Watches()
 742.524 +{
 742.525 +	const char* slash = max(strrchr(gamefilename, '|'), max(strrchr(gamefilename, '\\'), strrchr(gamefilename, '/')));
 742.526 +	strcpy(Str_Tmp,slash ? slash+1 : gamefilename);
 742.527 +	char* dot = strrchr(Str_Tmp, '.');
 742.528 +	if(dot) *dot = 0;
 742.529 +	strcat(Str_Tmp,".wch");
 742.530 +	if(Change_File_S(Str_Tmp, winGetDestDir(IDS_WATCH_DIR), "Save Watches", "Watchlist\0*.wch\0All Files\0*.*\0\0", "wch", RamWatchHWnd))
 742.531 +	{
 742.532 +		FILE *WatchFile = fopen(Str_Tmp,"r+b");
 742.533 +		if (!WatchFile) WatchFile = fopen(Str_Tmp,"w+b");
 742.534 +		fputc('\n',WatchFile);
 742.535 +		strcpy(currentWatch,Str_Tmp);
 742.536 +		RWAddRecentFile(currentWatch);
 742.537 +		sprintf(Str_Tmp,"%d\n",WatchCount);
 742.538 +		fputs(Str_Tmp,WatchFile);
 742.539 +		const char DELIM = '\t';
 742.540 +		for (int i = 0; i < WatchCount; i++)
 742.541 +		{
 742.542 +			sprintf(Str_Tmp,"%05X%c%08X%c%c%c%c%c%d%c%s\n",i,DELIM,rswatches[i].Address,DELIM,rswatches[i].Size,DELIM,rswatches[i].Type,DELIM,rswatches[i].WrongEndian,DELIM,rswatches[i].comment);
 742.543 +			fputs(Str_Tmp,WatchFile);
 742.544 +		}
 742.545 +		
 742.546 +		fclose(WatchFile);
 742.547 +		RWfileChanged=false;
 742.548 +		//TODO: Add to recent list function call here
 742.549 +		return true;
 742.550 +	}
 742.551 +	return false;
 742.552 +}
 742.553 +
 742.554 +bool QuickSaveWatches()
 742.555 +{
 742.556 +if (RWfileChanged==false) return true; //If file has not changed, no need to save changes
 742.557 +if (currentWatch[0] == NULL) //If there is no currently loaded file, run to Save as and then return
 742.558 +	{
 742.559 +		return Save_Watches();
 742.560 +	}
 742.561 +		
 742.562 +		strcpy(Str_Tmp,currentWatch);
 742.563 +		FILE *WatchFile = fopen(Str_Tmp,"r+b");
 742.564 +		if (!WatchFile) WatchFile = fopen(Str_Tmp,"w+b");
 742.565 +		fputc('\n',WatchFile);
 742.566 +		sprintf(Str_Tmp,"%d\n",WatchCount);
 742.567 +		fputs(Str_Tmp,WatchFile);
 742.568 +		const char DELIM = '\t';
 742.569 +		for (int i = 0; i < WatchCount; i++)
 742.570 +		{
 742.571 +			sprintf(Str_Tmp,"%05X%c%08X%c%c%c%c%c%d%c%s\n",i,DELIM,rswatches[i].Address,DELIM,rswatches[i].Size,DELIM,rswatches[i].Type,DELIM,rswatches[i].WrongEndian,DELIM,rswatches[i].comment);
 742.572 +			fputs(Str_Tmp,WatchFile);
 742.573 +		}
 742.574 +		fclose(WatchFile);
 742.575 +		RWfileChanged=false;
 742.576 +		return true;
 742.577 +}
 742.578 +
 742.579 +bool Load_Watches(bool clear, const char* filename)
 742.580 +{
 742.581 +	const char DELIM = '\t';
 742.582 +	FILE* WatchFile = fopen(filename,"rb");
 742.583 +	if (!WatchFile)
 742.584 +	{
 742.585 +		systemSoundClearBuffer();
 742.586 +		MessageBox(MESSAGEBOXPARENT,"Error opening file.","ERROR",MB_OK);
 742.587 +		return false;
 742.588 +	}
 742.589 +	if(clear)
 742.590 +	{
 742.591 +		if(!ResetWatches())
 742.592 +		{
 742.593 +			fclose(WatchFile);
 742.594 +			return false;
 742.595 +		}
 742.596 +	}
 742.597 +	strcpy(currentWatch,filename);
 742.598 +	RWAddRecentFile(currentWatch);
 742.599 +	AddressWatcher Temp;
 742.600 +	char mode;
 742.601 +	fgets(Str_Tmp,1024,WatchFile);
 742.602 +	sscanf(Str_Tmp,"%c%*s",&mode);
 742.603 +	int WatchAdd;
 742.604 +	fgets(Str_Tmp,1024,WatchFile);
 742.605 +	sscanf(Str_Tmp,"%d%*s",&WatchAdd);
 742.606 +	WatchAdd+=WatchCount;
 742.607 +	for (int i = WatchCount; i < WatchAdd; i++)
 742.608 +	{
 742.609 +		while (i < 0)
 742.610 +			i++;
 742.611 +		do {
 742.612 +			fgets(Str_Tmp,1024,WatchFile);
 742.613 +		} while (Str_Tmp[0] == '\n');
 742.614 +		sscanf(Str_Tmp,"%*05X%*c%08X%*c%c%*c%c%*c%d",&(Temp.Address),&(Temp.Size),&(Temp.Type),&(Temp.WrongEndian));
 742.615 +		Temp.WrongEndian = 0;
 742.616 +		char *Comment = strrchr(Str_Tmp,DELIM) + 1;
 742.617 +		*strrchr(Comment,'\n') = '\0';
 742.618 +		InsertWatch(Temp,Comment);
 742.619 +	}
 742.620 +	
 742.621 +	fclose(WatchFile);
 742.622 +	if (RamWatchHWnd)
 742.623 +		ListView_SetItemCount(GetDlgItem(RamWatchHWnd,IDC_WATCHLIST),WatchCount);
 742.624 +	RWfileChanged=false;
 742.625 +	return true;
 742.626 +}
 742.627 +
 742.628 +bool Load_Watches(bool clear)
 742.629 +{
 742.630 +	const char* slash = max(strrchr(gamefilename, '|'), max(strrchr(gamefilename, '\\'), strrchr(gamefilename, '/')));
 742.631 +	strcpy(Str_Tmp,slash ? slash+1 : gamefilename);
 742.632 +	char* dot = strrchr(Str_Tmp, '.');
 742.633 +	if(dot) *dot = 0;
 742.634 +	strcat(Str_Tmp,".wch");
 742.635 +	if(Change_File_L(Str_Tmp, winGetDestDir(IDS_WATCH_DIR), "Load Watches", "Watchlist\0*.wch\0All Files\0*.*\0\0", "wch", RamWatchHWnd))
 742.636 +	{
 742.637 +		return Load_Watches(clear, Str_Tmp);
 742.638 +	}
 742.639 +	return false;
 742.640 +}
 742.641 +
 742.642 +bool ResetWatches()
 742.643 +{
 742.644 +	if(!AskSave())
 742.645 +		return false;
 742.646 +	for (;WatchCount>=0;WatchCount--)
 742.647 +	{
 742.648 +		free(rswatches[WatchCount].comment);
 742.649 +		rswatches[WatchCount].comment = NULL;
 742.650 +	}
 742.651 +	WatchCount++;
 742.652 +	if (RamWatchHWnd) {
 742.653 +		ListView_SetItemCount(GetDlgItem(RamWatchHWnd,IDC_WATCHLIST),WatchCount);
 742.654 +		RefreshWatchListSelectedCountControlStatus(RamWatchHWnd);
 742.655 +	}
 742.656 +	RWfileChanged = false;
 742.657 +	currentWatch[0] = NULL;
 742.658 +	return true;
 742.659 +}
 742.660 +
 742.661 +void RemoveWatch(int watchIndex)
 742.662 +{
 742.663 +	free(rswatches[watchIndex].comment);
 742.664 +	rswatches[watchIndex].comment = NULL;
 742.665 +	for (int i = watchIndex; i <= WatchCount; i++)
 742.666 +		rswatches[i] = rswatches[i+1];
 742.667 +	WatchCount--;
 742.668 +}
 742.669 +
 742.670 +LRESULT CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) //Gets info for a RAM Watch, and then inserts it into the Watch List
 742.671 +{
 742.672 +	RECT r;
 742.673 +	RECT r2;
 742.674 +	int dx1, dy1, dx2, dy2;
 742.675 +	static int index;
 742.676 +	static char s,t = s = 0;
 742.677 +
 742.678 +	switch(uMsg)
 742.679 +	{
 742.680 +		case WM_INITDIALOG:
 742.681 +			//Clear_Sound_Buffer();
 742.682 +			
 742.683 +
 742.684 +			GetWindowRect(hWnd, &r);
 742.685 +			dx1 = (r.right - r.left) / 2;
 742.686 +			dy1 = (r.bottom - r.top) / 2;
 742.687 +
 742.688 +			GetWindowRect(hDlg, &r2);
 742.689 +			dx2 = (r2.right - r2.left) / 2;
 742.690 +			dy2 = (r2.bottom - r2.top) / 2;
 742.691 +
 742.692 +			//SetWindowPos(hDlg, NULL, max(0, r.left + (dx1 - dx2)), max(0, r.top + (dy1 - dy2)), NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
 742.693 +			SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
 742.694 +			index = (int)lParam;
 742.695 +			sprintf(Str_Tmp,"%08X",rswatches[index].Address);
 742.696 +			SetDlgItemText(hDlg,IDC_EDIT_COMPAREADDRESS,Str_Tmp);
 742.697 +			if (rswatches[index].comment != NULL)
 742.698 +				SetDlgItemText(hDlg,IDC_PROMPT_EDIT,rswatches[index].comment);
 742.699 +			s = rswatches[index].Size;
 742.700 +			t = rswatches[index].Type;
 742.701 +			switch (s)
 742.702 +			{
 742.703 +				case 'b':
 742.704 +					SendDlgItemMessage(hDlg, IDC_1_BYTE, BM_SETCHECK, BST_CHECKED, 0);
 742.705 +					break;
 742.706 +				case 'w':
 742.707 +					SendDlgItemMessage(hDlg, IDC_2_BYTES, BM_SETCHECK, BST_CHECKED, 0);
 742.708 +					break;
 742.709 +				case 'd':
 742.710 +					SendDlgItemMessage(hDlg, IDC_4_BYTES, BM_SETCHECK, BST_CHECKED, 0);
 742.711 +					break;
 742.712 +				default:
 742.713 +					s = 0;
 742.714 +					break;
 742.715 +			}
 742.716 +			switch (t)
 742.717 +			{
 742.718 +				case 's':
 742.719 +					SendDlgItemMessage(hDlg, IDC_SIGNED, BM_SETCHECK, BST_CHECKED, 0);
 742.720 +					break;
 742.721 +				case 'u':
 742.722 +					SendDlgItemMessage(hDlg, IDC_UNSIGNED, BM_SETCHECK, BST_CHECKED, 0);
 742.723 +					break;
 742.724 +				case 'h':
 742.725 +					SendDlgItemMessage(hDlg, IDC_HEX, BM_SETCHECK, BST_CHECKED, 0);
 742.726 +					break;
 742.727 +				default:
 742.728 +					t = 0;
 742.729 +					break;
 742.730 +			}
 742.731 +
 742.732 +			return true;
 742.733 +			break;
 742.734 +		
 742.735 +		case WM_COMMAND:
 742.736 +			switch(LOWORD(wParam))
 742.737 +			{
 742.738 +				case IDC_SIGNED:
 742.739 +					t='s';
 742.740 +					return true;
 742.741 +				case IDC_UNSIGNED:
 742.742 +					t='u';
 742.743 +					return true;
 742.744 +				case IDC_HEX:
 742.745 +					t='h';
 742.746 +					return true;
 742.747 +				case IDC_1_BYTE:
 742.748 +					s = 'b';
 742.749 +					return true;
 742.750 +				case IDC_2_BYTES:
 742.751 +					s = 'w';
 742.752 +					return true;
 742.753 +				case IDC_4_BYTES:
 742.754 +					s = 'd';
 742.755 +					return true;
 742.756 +				case IDOK:
 742.757 +				{
 742.758 +					if (s && t)
 742.759 +					{
 742.760 +						AddressWatcher Temp;
 742.761 +						Temp.Size = s;
 742.762 +						Temp.Type = t;
 742.763 +						Temp.WrongEndian = false; //replace this when I get little endian working properly
 742.764 +						GetDlgItemText(hDlg,IDC_EDIT_COMPAREADDRESS,Str_Tmp,1024);
 742.765 +						char *addrstr = Str_Tmp;
 742.766 +						if (strlen(Str_Tmp) > 8) addrstr = &(Str_Tmp[strlen(Str_Tmp) - 9]);
 742.767 +						for(int i = 0; addrstr[i]; i++) {if(toupper(addrstr[i]) == 'O') addrstr[i] = '0';}
 742.768 +						sscanf(addrstr,"%08X",&(Temp.Address));
 742.769 +
 742.770 +						if((Temp.Address & ~0xFFFFFF) == ~0xFFFFFF)
 742.771 +							Temp.Address &= 0xFFFFFF;
 742.772 +
 742.773 +						if(IsHardwareAddressValid(Temp.Address))
 742.774 +						{
 742.775 +							GetDlgItemText(hDlg,IDC_PROMPT_EDIT,Str_Tmp,80);
 742.776 +							if (index < WatchCount) RemoveWatch(index);
 742.777 +							InsertWatch(Temp,Str_Tmp);
 742.778 +							if(RamWatchHWnd)
 742.779 +							{
 742.780 +								ListView_SetItemCount(GetDlgItem(RamWatchHWnd,IDC_WATCHLIST),WatchCount);
 742.781 +							}
 742.782 +							EndDialog(hDlg, true);
 742.783 +						}
 742.784 +						else
 742.785 +						{
 742.786 +							MessageBox(hDlg,"Invalid Address","ERROR",MB_OK);
 742.787 +						}
 742.788 +					}
 742.789 +					else
 742.790 +					{
 742.791 +						strcpy(Str_Tmp,"Error:");
 742.792 +						if (!s)
 742.793 +							strcat(Str_Tmp," Size must be specified.");
 742.794 +						if (!t)
 742.795 +							strcat(Str_Tmp," Type must be specified.");
 742.796 +						MessageBox(hDlg,Str_Tmp,"ERROR",MB_OK);
 742.797 +					}
 742.798 +					RWfileChanged=true;
 742.799 +					return true;
 742.800 +					break;
 742.801 +				}
 742.802 +				case ID_CANCEL:
 742.803 +				case IDCANCEL:
 742.804 +					EndDialog(hDlg, false);
 742.805 +					return false;
 742.806 +					break;
 742.807 +			}
 742.808 +			break;
 742.809 +
 742.810 +		case WM_CLOSE:
 742.811 +			EndDialog(hDlg, false);
 742.812 +			return false;
 742.813 +			break;
 742.814 +	}
 742.815 +
 742.816 +	return false;
 742.817 +}
 742.818 +
 742.819 +
 742.820 +
 742.821 +
 742.822 +void RamWatchEnableCommand(HWND hDlg, HMENU hMenu, UINT uIDEnableItem, bool enable)
 742.823 +{
 742.824 +	EnableWindow(GetDlgItem(hDlg, uIDEnableItem), (enable?TRUE:FALSE));
 742.825 +	if (hMenu != NULL) {
 742.826 +		if (uIDEnableItem == ID_WATCHES_UPDOWN) {
 742.827 +			EnableMenuItem(hMenu, IDC_C_WATCH_UP, MF_BYCOMMAND | (enable?MF_ENABLED:MF_GRAYED));
 742.828 +			EnableMenuItem(hMenu, IDC_C_WATCH_DOWN, MF_BYCOMMAND | (enable?MF_ENABLED:MF_GRAYED));
 742.829 +		}
 742.830 +		else
 742.831 +			EnableMenuItem(hMenu, uIDEnableItem, MF_BYCOMMAND | (enable?MF_ENABLED:MF_GRAYED));
 742.832 +	}
 742.833 +}
 742.834 +
 742.835 +void RefreshWatchListSelectedCountControlStatus(HWND hDlg)
 742.836 +{
 742.837 +	int selCount = ListView_GetSelectedCount(GetDlgItem(hDlg,IDC_WATCHLIST));
 742.838 +	if(selCount != s_prevSelCount)
 742.839 +	{
 742.840 +		if(selCount < 2 || s_prevSelCount < 2)
 742.841 +		{
 742.842 +			RamWatchEnableCommand(hDlg, ramwatchmenu, IDC_C_WATCH_EDIT, selCount == 1);
 742.843 +			RamWatchEnableCommand(hDlg, ramwatchmenu, IDC_C_WATCH_REMOVE, selCount >= 1);
 742.844 +			RamWatchEnableCommand(hDlg, ramwatchmenu, IDC_C_WATCH, WatchCount < MAX_WATCH_COUNT);
 742.845 +			RamWatchEnableCommand(hDlg, ramwatchmenu, IDC_C_WATCH_DUPLICATE, selCount == 1 && WatchCount < MAX_WATCH_COUNT);
 742.846 +			RamWatchEnableCommand(hDlg, ramwatchmenu, IDC_C_ADDCHEAT, selCount == 1);
 742.847 +			RamWatchEnableCommand(hDlg, ramwatchmenu, ID_WATCHES_UPDOWN, selCount == 1);
 742.848 +		}
 742.849 +		s_prevSelCount = selCount;
 742.850 +	}
 742.851 +}
 742.852 +
 742.853 +LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 742.854 +{
 742.855 +	RECT r;
 742.856 +	RECT r2;
 742.857 +	int dx1, dy1, dx2, dy2;
 742.858 +	static int watchIndex=0;
 742.859 +
 742.860 +	switch(uMsg)
 742.861 +	{
 742.862 +		case WM_MOVE: {
 742.863 +			RECT wrect;
 742.864 +			GetWindowRect(hDlg,&wrect);
 742.865 +			ramw_x = wrect.left;
 742.866 +			ramw_y = wrect.top;
 742.867 +			regSetDwordValue(RAMWX, ramw_x);
 742.868 +			regSetDwordValue(RAMWY, ramw_y);
 742.869 +		}	break;
 742.870 +
 742.871 +		case WM_INITDIALOG: {
 742.872 +			GetWindowRect(hWnd, &r);  //Ramwatch window
 742.873 +			dx1 = (r.right - r.left) / 2;
 742.874 +			dy1 = (r.bottom - r.top) / 2;
 742.875 +
 742.876 +			GetWindowRect(hDlg, &r2); // TASer window
 742.877 +			dx2 = (r2.right - r2.left) / 2;
 742.878 +			dy2 = (r2.bottom - r2.top) / 2;
 742.879 +
 742.880 +			
 742.881 +			// push it away from the main window if we can
 742.882 +			const int width = (r.right-r.left);
 742.883 +			const int height = (r.bottom - r.top);
 742.884 +			const int width2 = (r2.right-r2.left); 
 742.885 +			if(r.left+width2 + width < GetSystemMetrics(SM_CXSCREEN))
 742.886 +			{
 742.887 +				r.right += width;
 742.888 +				r.left += width;
 742.889 +			}
 742.890 +			else if((int)r.left - (int)width2 > 0)
 742.891 +			{
 742.892 +				r.right -= width2;
 742.893 +				r.left -= width2;
 742.894 +			}
 742.895 +			
 742.896 +			//-----------------------------------------------------------------------------------
 742.897 +			//If user has Save Window Pos selected, override default positioning
 742.898 +			if (RWSaveWindowPos)	
 742.899 +			{
 742.900 +				//If ramwindow is for some reason completely off screen, use default instead 
 742.901 +				if (ramw_x > (-width*2) || ramw_x < (width*2 + GetSystemMetrics(SM_CYSCREEN))   ) 
 742.902 +					r.left = ramw_x;	  //This also ignores cases of windows -32000 error codes
 742.903 +				//If ramwindow is for some reason completely off screen, use default instead 
 742.904 +				if (ramw_y > (0-height*2) ||ramw_y < (height*2 + GetSystemMetrics(SM_CYSCREEN))	)
 742.905 +					r.top = ramw_y;		  //This also ignores cases of windows -32000 error codes
 742.906 +			}
 742.907 +			//-------------------------------------------------------------------------------------
 742.908 +			SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
 742.909 +			
 742.910 +			ramwatchmenu=GetMenu(hDlg);
 742.911 +			rwrecentmenu=CreateMenu();
 742.912 +			UpdateRW_RMenu(rwrecentmenu, RAMMENU_FILE_RECENT, RW_MENU_FIRST_RECENT_FILE);
 742.913 +			
 742.914 +			const char* names[3] = {"Address","Value","Notes"};
 742.915 +			int widths[3] = {62,64,64+51+53};
 742.916 +			init_list_box(GetDlgItem(hDlg,IDC_WATCHLIST),names,3,widths);
 742.917 +			if (!ResultCount)
 742.918 +				reset_address_info();
 742.919 +			else
 742.920 +				signal_new_frame();
 742.921 +			ListView_SetItemCount(GetDlgItem(hDlg,IDC_WATCHLIST),WatchCount);
 742.922 +			if (!noMisalign) SendDlgItemMessage(hDlg, IDC_MISALIGN, BM_SETCHECK, BST_CHECKED, 0);
 742.923 +			//if (littleEndian) SendDlgItemMessage(hDlg, IDC_ENDIAN, BM_SETCHECK, BST_CHECKED, 0);
 742.924 +
 742.925 +			RamWatchAccels = LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_ACCELERATOR1));
 742.926 +
 742.927 +			// due to some bug in windows, the arrow button width from the resource gets ignored, so we have to set it here
 742.928 +			SetWindowPos(GetDlgItem(hDlg,ID_WATCHES_UPDOWN), 0,0,0, 30,60, SWP_NOMOVE);
 742.929 +
 742.930 +			Update_RAM_Watch();
 742.931 +
 742.932 +			DragAcceptFiles(hDlg, TRUE);
 742.933 +
 742.934 +			s_prevSelCount = -1;
 742.935 +			RefreshWatchListSelectedCountControlStatus(hDlg);
 742.936 +			return false;
 742.937 +		}	break;
 742.938 +		
 742.939 +		case WM_INITMENU:
 742.940 +			CheckMenuItem(ramwatchmenu, RAMMENU_FILE_AUTOLOAD, AutoRWLoad ? MF_CHECKED : MF_UNCHECKED);
 742.941 +			CheckMenuItem(ramwatchmenu, RAMMENU_FILE_SAVEWINDOW, RWSaveWindowPos ? MF_CHECKED : MF_UNCHECKED);
 742.942 +			break;
 742.943 +
 742.944 +		case WM_ENTERMENULOOP:
 742.945 +			systemSoundClearBuffer();
 742.946 +			break;
 742.947 +
 742.948 +		case WM_MENUSELECT:
 742.949 + 		case WM_ENTERSIZEMOVE:
 742.950 +			//Clear_Sound_Buffer();
 742.951 +			break;
 742.952 +
 742.953 +		case WM_NOTIFY:
 742.954 +		{
 742.955 +			switch(wParam)
 742.956 +			{
 742.957 +				case ID_WATCHES_UPDOWN:
 742.958 +				{
 742.959 +					switch(((LPNMUPDOWN)lParam)->hdr.code)
 742.960 +					{
 742.961 +						case UDN_DELTAPOS: {
 742.962 +							int delta = ((LPNMUPDOWN)lParam)->iDelta;
 742.963 +							SendMessage(hDlg, WM_COMMAND, delta<0 ? IDC_C_WATCH_UP : IDC_C_WATCH_DOWN,0);
 742.964 +						} break;
 742.965 +					}
 742.966 +				} break;
 742.967 +
 742.968 +				default:
 742.969 +				{
 742.970 +					LPNMHDR lP = (LPNMHDR) lParam;
 742.971 +					switch (lP->code)
 742.972 +					{
 742.973 +						case LVN_ITEMCHANGED: // selection changed event
 742.974 +						{
 742.975 +							NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)lP;
 742.976 +							if(pNMListView->uNewState & LVIS_FOCUSED ||
 742.977 +								(pNMListView->uNewState ^ pNMListView->uOldState) & LVIS_SELECTED)
 742.978 +							{
 742.979 +								// disable buttons that we don't have the right number of selected items for
 742.980 +								RefreshWatchListSelectedCountControlStatus(hDlg);
 742.981 +							}
 742.982 +						}	break;
 742.983 +
 742.984 +						case LVN_GETDISPINFO:
 742.985 +						{
 742.986 +							LV_DISPINFO *Item = (LV_DISPINFO *)lParam;
 742.987 +							Item->item.mask = LVIF_TEXT;
 742.988 +							Item->item.state = 0;
 742.989 +							Item->item.iImage = 0;
 742.990 +							const unsigned int iNum = Item->item.iItem;
 742.991 +							static char num[11];
 742.992 +							switch (Item->item.iSubItem)
 742.993 +							{
 742.994 +								case 0:
 742.995 +									sprintf(num,"%08X",rswatches[iNum].Address);
 742.996 +									Item->item.pszText = num;
 742.997 +									return true;
 742.998 +								case 1: {
 742.999 +									int i = rswatches[iNum].CurValue;
742.1000 +									int t = rswatches[iNum].Type;
742.1001 +									int size = rswatches[iNum].Size;
742.1002 +									const char* formatString = ((t=='s') ? "%d" : (t=='u') ? "%u" : (size=='d' ? "%08X" : size=='w' ? "%04X" : "%02X"));
742.1003 +									switch (size)
742.1004 +									{
742.1005 +										case 'b':
742.1006 +										default: sprintf(num, formatString, t=='s' ? (char)(i&0xff) : (unsigned char)(i&0xff)); break;
742.1007 +										case 'w': sprintf(num, formatString, t=='s' ? (short)(i&0xffff) : (unsigned short)(i&0xffff)); break;
742.1008 +										case 'd': sprintf(num, formatString, t=='s' ? (long)(i&0xffffffff) : (unsigned long)(i&0xffffffff)); break;
742.1009 +									}
742.1010 +
742.1011 +									Item->item.pszText = num;
742.1012 +								}	return true;
742.1013 +								case 2:
742.1014 +									Item->item.pszText = rswatches[iNum].comment ? rswatches[iNum].comment : "";
742.1015 +									return true;
742.1016 +
742.1017 +								default:
742.1018 +									return false;
742.1019 +							}
742.1020 +						}
742.1021 +						case LVN_ODFINDITEM:
742.1022 +						{	
742.1023 +							// disable search by keyboard typing,
742.1024 +							// because it interferes with some of the accelerators
742.1025 +							// and it isn't very useful here anyway
742.1026 +							SetWindowLong(hDlg, DWL_MSGRESULT, ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST)));
742.1027 +							return 1;
742.1028 +						}
742.1029 +					}
742.1030 +				}
742.1031 +			}
742.1032 +		}	break;
742.1033 +
742.1034 +		case WM_COMMAND:
742.1035 +			switch(LOWORD(wParam))
742.1036 +			{
742.1037 +				case RAMMENU_FILE_SAVE:
742.1038 +					QuickSaveWatches();
742.1039 +					break;
742.1040 +
742.1041 +				case RAMMENU_FILE_SAVEAS:	
742.1042 +				//case IDC_C_SAVE:
742.1043 +					return Save_Watches();
742.1044 +				case RAMMENU_FILE_OPEN:
742.1045 +					return Load_Watches(true);
742.1046 +				case RAMMENU_FILE_APPEND:
742.1047 +				//case IDC_C_LOAD:
742.1048 +					return Load_Watches(false);
742.1049 +				case RAMMENU_FILE_NEW:
742.1050 +				//case IDC_C_RESET:
742.1051 +					ResetWatches();
742.1052 +					return true;
742.1053 +				case IDC_C_WATCH_REMOVE:
742.1054 +				{
742.1055 +					HWND watchListControl = GetDlgItem(hDlg, IDC_WATCHLIST);
742.1056 +					watchIndex = ListView_GetNextItem(watchListControl, -1, LVNI_ALL | LVNI_SELECTED);
742.1057 +					while (watchIndex >= 0)
742.1058 +					{
742.1059 +						RemoveWatch(watchIndex);
742.1060 +						ListView_DeleteItem(watchListControl, watchIndex);
742.1061 +						watchIndex = ListView_GetNextItem(watchListControl, -1, LVNI_ALL | LVNI_SELECTED);
742.1062 +					}
742.1063 +					RWfileChanged=true;
742.1064 +					SetFocus(GetDlgItem(hDlg,IDC_WATCHLIST));
742.1065 +					return true;
742.1066 +				}
742.1067 +				case IDC_C_WATCH_EDIT:
742.1068 +					watchIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST));
742.1069 +					if(watchIndex != -1)
742.1070 +					{
742.1071 +						systemSoundClearBuffer();
742.1072 +						DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_EDITWATCH), hDlg, (DLGPROC) EditWatchProc,(LPARAM) watchIndex);
742.1073 +						SetFocus(GetDlgItem(hDlg,IDC_WATCHLIST));
742.1074 +					}
742.1075 +					return true;
742.1076 +				case IDC_C_WATCH:
742.1077 +					rswatches[WatchCount].Address = rswatches[WatchCount].WrongEndian = 0;
742.1078 +					rswatches[WatchCount].Size = 'b';
742.1079 +					rswatches[WatchCount].Type = 's';
742.1080 +					systemSoundClearBuffer();
742.1081 +					DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_EDITWATCH), hDlg, (DLGPROC) EditWatchProc,(LPARAM) WatchCount);
742.1082 +					SetFocus(GetDlgItem(hDlg,IDC_WATCHLIST));
742.1083 +					return true;
742.1084 +				case IDC_C_WATCH_DUPLICATE:
742.1085 +					watchIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST));
742.1086 +					if(watchIndex != -1)
742.1087 +					{
742.1088 +						rswatches[WatchCount].Address = rswatches[watchIndex].Address;
742.1089 +						rswatches[WatchCount].WrongEndian = rswatches[watchIndex].WrongEndian;
742.1090 +						rswatches[WatchCount].Size = rswatches[watchIndex].Size;
742.1091 +						rswatches[WatchCount].Type = rswatches[watchIndex].Type;
742.1092 +						systemSoundClearBuffer();
742.1093 +						DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_EDITWATCH), hDlg, (DLGPROC) EditWatchProc,(LPARAM) WatchCount);
742.1094 +						SetFocus(GetDlgItem(hDlg,IDC_WATCHLIST));
742.1095 +					}
742.1096 +					return true;
742.1097 +
742.1098 +				case IDC_C_WATCH_SEPARATE:
742.1099 +					AddressWatcher separator;
742.1100 +					separator.Address = 0;
742.1101 +					separator.WrongEndian = false;
742.1102 +					separator.Size = 'S';
742.1103 +					separator.Type = 'S';
742.1104 +					InsertWatch(separator, "----------------------------");
742.1105 +					SetFocus(GetDlgItem(hDlg,IDC_WATCHLIST));
742.1106 +					return true;
742.1107 +
742.1108 +				case IDC_C_WATCH_UP:
742.1109 +				{
742.1110 +					watchIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST));
742.1111 +					if (watchIndex == 0 || watchIndex == -1)
742.1112 +						return true;
742.1113 +					void *tmp = malloc(sizeof(AddressWatcher));
742.1114 +					memcpy(tmp,&(rswatches[watchIndex]),sizeof(AddressWatcher));
742.1115 +					memcpy(&(rswatches[watchIndex]),&(rswatches[watchIndex - 1]),sizeof(AddressWatcher));
742.1116 +					memcpy(&(rswatches[watchIndex - 1]),tmp,sizeof(AddressWatcher));
742.1117 +					free(tmp);
742.1118 +					ListView_SetItemState(GetDlgItem(hDlg,IDC_WATCHLIST),watchIndex,0,LVIS_FOCUSED|LVIS_SELECTED);
742.1119 +					ListView_SetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST),watchIndex-1);
742.1120 +					ListView_SetItemState(GetDlgItem(hDlg,IDC_WATCHLIST),watchIndex-1,LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED);
742.1121 +					ListView_SetItemCount(GetDlgItem(hDlg,IDC_WATCHLIST),WatchCount);
742.1122 +					RWfileChanged=true;
742.1123 +					return true;
742.1124 +				}
742.1125 +				case IDC_C_WATCH_DOWN:
742.1126 +				{
742.1127 +					watchIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST));
742.1128 +					if (watchIndex >= WatchCount - 1 || watchIndex == -1)
742.1129 +						return true;
742.1130 +					void *tmp = malloc(sizeof(AddressWatcher));
742.1131 +					memcpy(tmp,&(rswatches[watchIndex]),sizeof(AddressWatcher));
742.1132 +					memcpy(&(rswatches[watchIndex]),&(rswatches[watchIndex + 1]),sizeof(AddressWatcher));
742.1133 +					memcpy(&(rswatches[watchIndex + 1]),tmp,sizeof(AddressWatcher));
742.1134 +					free(tmp);
742.1135 +					ListView_SetItemState(GetDlgItem(hDlg,IDC_WATCHLIST),watchIndex,0,LVIS_FOCUSED|LVIS_SELECTED);
742.1136 +					ListView_SetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST),watchIndex+1);
742.1137 +					ListView_SetItemState(GetDlgItem(hDlg,IDC_WATCHLIST),watchIndex+1,LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED);
742.1138 +					ListView_SetItemCount(GetDlgItem(hDlg,IDC_WATCHLIST),WatchCount);
742.1139 +					RWfileChanged=true;
742.1140 +					return true;
742.1141 +				}
742.1142 +				case ID_WATCHES_UPDOWN:
742.1143 +				{
742.1144 +					int delta = ((LPNMUPDOWN)lParam)->iDelta;
742.1145 +					SendMessage(hDlg, WM_COMMAND, delta<0 ? IDC_C_WATCH_UP : IDC_C_WATCH_DOWN,0);
742.1146 +					break;
742.1147 +				}
742.1148 +				case RAMMENU_FILE_AUTOLOAD:
742.1149 +				{
742.1150 +					AutoRWLoad ^= 1;
742.1151 +					CheckMenuItem(ramwatchmenu, RAMMENU_FILE_AUTOLOAD, AutoRWLoad ? MF_CHECKED : MF_UNCHECKED);
742.1152 +					regSetDwordValue(AUTORWLOAD, AutoRWLoad);
742.1153 +					break;
742.1154 +				}
742.1155 +				case RAMMENU_FILE_SAVEWINDOW:
742.1156 +				{
742.1157 +					RWSaveWindowPos ^=1;
742.1158 +					CheckMenuItem(ramwatchmenu, RAMMENU_FILE_SAVEWINDOW, RWSaveWindowPos ? MF_CHECKED : MF_UNCHECKED);
742.1159 +					regSetDwordValue(RWSAVEPOS, RWSaveWindowPos);
742.1160 +					break;
742.1161 +				}
742.1162 +				case IDC_C_ADDCHEAT:
742.1163 +				{
742.1164 +					watchIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST));
742.1165 +					if(watchIndex >= 0)
742.1166 +					{
742.1167 +						unsigned int address = rswatches[watchIndex].Address;
742.1168 +
742.1169 +						int sizeType = -1;
742.1170 +						if(rswatches[watchIndex].Size == 'b')
742.1171 +							sizeType = 0;
742.1172 +						else if(rswatches[watchIndex].Size == 'w')
742.1173 +							sizeType = 1;
742.1174 +						else if(rswatches[watchIndex].Size == 'd')
742.1175 +							sizeType = 2;
742.1176 +
742.1177 +						int numberType = -1;
742.1178 +						if(rswatches[watchIndex].Type == 's')
742.1179 +							numberType = 0;
742.1180 +						else if(rswatches[watchIndex].Type == 'u')
742.1181 +							numberType = 1;
742.1182 +						else if(rswatches[watchIndex].Type == 'h')
742.1183 +							numberType = 2;
742.1184 +
742.1185 +						if(systemCartridgeType == 0)
742.1186 +						{
742.1187 +							AddCheat dlg (address/*, hDlg*/);
742.1188 +							if(sizeType != -1) dlg.sizeType = sizeType;
742.1189 +							if(numberType != -1) dlg.numberType = numberType;
742.1190 +							systemSoundClearBuffer();
742.1191 +							dlg.DoModal();
742.1192 +						}
742.1193 +						else
742.1194 +						{
742.1195 +							AddGBCheat dlg (address/*, hDlg*/);
742.1196 +							if(sizeType != -1) dlg.sizeType = sizeType;
742.1197 +							if(numberType != -1) dlg.numberType = numberType;
742.1198 +							systemSoundClearBuffer();
742.1199 +							dlg.DoModal();
742.1200 +						}
742.1201 +					}
742.1202 +				}
742.1203 +				break;
742.1204 +				case IDOK:
742.1205 +				case IDCANCEL:
742.1206 +					RamWatchHWnd = NULL;
742.1207 +					DragAcceptFiles(hDlg, FALSE);
742.1208 +					EndDialog(hDlg, true);
742.1209 +					return true;
742.1210 +				default:
742.1211 +					if (LOWORD(wParam) >= RW_MENU_FIRST_RECENT_FILE && LOWORD(wParam) < RW_MENU_FIRST_RECENT_FILE+MAX_RECENT_WATCHES && LOWORD(wParam) <= RW_MENU_LAST_RECENT_FILE)
742.1212 +					OpenRWRecentFile(LOWORD(wParam) - RW_MENU_FIRST_RECENT_FILE);
742.1213 +			}
742.1214 +			break;
742.1215 +
742.1216 +#if 0
742.1217 +		// this message is never received
742.1218 +		case WM_KEYDOWN: // handle accelerator keys
742.1219 +		{
742.1220 +			SetFocus(GetDlgItem(hDlg,IDC_WATCHLIST));
742.1221 +			MSG msg;
742.1222 +			msg.hwnd = hDlg;
742.1223 +			msg.message = uMsg;
742.1224 +			msg.wParam = wParam;
742.1225 +			msg.lParam = lParam;
742.1226 +			if(RamWatchAccels && TranslateAccelerator(hDlg, RamWatchAccels, &msg))
742.1227 +				return true;
742.1228 +		}	break;
742.1229 +#endif
742.1230 +
742.1231 +		case WM_CLOSE:
742.1232 +			SendMessage(RamWatchHWnd, WM_DESTROY, 0, 0);
742.1233 +			break;
742.1234 +
742.1235 +		case WM_DESTROY:
742.1236 +			// this is the correct place
742.1237 +			RamWatchHWnd = NULL;
742.1238 +			DragAcceptFiles(hDlg, FALSE);
742.1239 +			WriteRecentRWFiles();	// write recent menu to ini
742.1240 +			break;
742.1241 +
742.1242 +		case WM_DROPFILES:
742.1243 +		{
742.1244 +			HDROP hDrop = (HDROP)wParam;
742.1245 +			DragQueryFile(hDrop, 0, Str_Tmp, 1024);
742.1246 +			DragFinish(hDrop);
742.1247 +			return Load_Watches(true, Str_Tmp);
742.1248 +		}	break;
742.1249 +	}
742.1250 +
742.1251 +	return false;
742.1252 +}
   743.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   743.2 +++ b/src/win32/ramwatch.h	Sat Mar 03 10:31:27 2012 -0600
   743.3 @@ -0,0 +1,46 @@
   743.4 +#ifndef RAMWATCH_H
   743.5 +#define RAMWATCH_H
   743.6 +
   743.7 +bool ResetWatches();
   743.8 +void OpenRWRecentFile(int memwRFileNumber);
   743.9 +extern bool AutoRWLoad;
  743.10 +extern bool RWSaveWindowPos;
  743.11 +#define MAX_RECENT_WATCHES 5
  743.12 +extern char rw_recent_files[MAX_RECENT_WATCHES][1024];
  743.13 +extern bool AskSave();
  743.14 +extern int ramw_x;
  743.15 +extern int ramw_y;
  743.16 +extern bool RWfileChanged;
  743.17 +
  743.18 +//Constants
  743.19 +#define AUTORWLOAD "RamWatchAutoLoad"
  743.20 +#define RWSAVEPOS "RamWatchSaveWindowPos"
  743.21 +#define RAMWX "RamwX"
  743.22 +#define RAMWY "RamwY"
  743.23 +
  743.24 +// AddressWatcher is self-contained now
  743.25 +struct AddressWatcher
  743.26 +{
  743.27 +	unsigned int Address; // hardware address
  743.28 +	char Size;
  743.29 +	char Type;
  743.30 +	char* comment; // NULL means no comment, non-NULL means allocated comment
  743.31 +	bool WrongEndian;
  743.32 +	unsigned int CurValue;
  743.33 +};
  743.34 +#define MAX_WATCH_COUNT 256
  743.35 +extern AddressWatcher rswatches[MAX_WATCH_COUNT];
  743.36 +extern int WatchCount; // number of valid items in rswatches
  743.37 +
  743.38 +extern char Watch_Dir[1024];
  743.39 +
  743.40 +extern HWND RamWatchHWnd;
  743.41 +extern HACCEL RamWatchAccels;
  743.42 +
  743.43 +bool InsertWatch(const AddressWatcher& Watch, char *Comment);
  743.44 +bool InsertWatch(const AddressWatcher& Watch, HWND parent=NULL); // asks user for comment
  743.45 +void Update_RAM_Watch();
  743.46 +bool Load_Watches(bool clear, const char* filename);
  743.47 +void RWAddRecentFile(const char *filename);
  743.48 +
  743.49 +#endif
   744.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   744.2 +++ b/src/win32/resource.h	Sat Mar 03 10:31:27 2012 -0600
   744.3 @@ -0,0 +1,1076 @@
   744.4 +//{{NO_DEPENDENCIES}}
   744.5 +// Microsoft Visual C++ generated include file.
   744.6 +// Used by VBA.rc
   744.7 +//
   744.8 +#define IDS_UNSUPPORTED_VBA_SGM         1
   744.9 +#define IDS_CANNOT_LOAD_SGM             2
  744.10 +#define IDS_SAVE_GAME_NOT_USING_BIOS    3
  744.11 +#define IDS_SAVE_GAME_USING_BIOS        4
  744.12 +#define IDS_UNSUPPORTED_SAVE_TYPE       5
  744.13 +#define IDS_CANNOT_OPEN_FILE            6
  744.14 +#define IDS_BAD_ZIP_FILE                7
  744.15 +#define IDS_NO_IMAGE_ON_ZIP             8
  744.16 +#define IDS_ERROR_OPENING_IMAGE         9
  744.17 +#define IDS_ERROR_READING_IMAGE         10
  744.18 +#define IDS_UNSUPPORTED_BIOS_FUNCTION   11
  744.19 +#define IDS_INVALID_BIOS_FILE_SIZE      12
  744.20 +#define IDS_INVALID_CHEAT_CODE          13
  744.21 +#define IDS_UNKNOWN_ARM_OPCDOE          14
  744.22 +#define IDS_UNKNOWN_THUMB_OPCODE        15
  744.23 +#define IDS_ERROR_CREATING_FILE         16
  744.24 +#define IDS_FAILED_TO_READ_SGM          17
  744.25 +#define IDS_FAILED_TO_READ_RTC          18
  744.26 +#define IDS_UNSUPPORTED_VB_SGM          19
  744.27 +#define IDS_CANNOT_LOAD_SGM_FOR         20
  744.28 +#define IDS_ERROR_OPENING_IMAGE_FROM    21
  744.29 +#define IDS_ERROR_READING_IMAGE_FROM    22
  744.30 +#define IDS_UNSUPPORTED_ROM_SIZE        23
  744.31 +#define IDS_UNSUPPORTED_RAM_SIZE        24
  744.32 +#define IDS_UNKNOWN_CARTRIDGE_TYPE      25
  744.33 +#define IDS_MAXIMUM_NUMBER_OF_CHEATS    26
  744.34 +#define IDS_INVALID_GAMESHARK_CODE      27
  744.35 +#define IDS_INVALID_GAMEGENIE_CODE      28
  744.36 +#define IDS_INVALID_CHEAT_TO_REMOVE     29
  744.37 +#define IDS_INVALID_CHEAT_CODE_ADDRESS  30
  744.38 +#define IDS_UNSUPPORTED_CHEAT_LIST_VERSION 31
  744.39 +#define IDS_UNSUPPORTED_CHEAT_LIST_TYPE 32
  744.40 +#define IDS_INVALID_GSA_CODE            33
  744.41 +#define IDS_CANNOT_IMPORT_SNAPSHOT_FOR  34
  744.42 +#define IDS_UNSUPPORTED_SNAPSHOT_FILE   35
  744.43 +#define IDS_UNSUPPORTED_ARM_MODE        36
  744.44 +#define IDS_UNSUPPORTED_CODE_FILE       37
  744.45 +#define IDS_GSA_CODE_WARNING            38
  744.46 +#define IDS_INVALID_CBA_CODE            39
  744.47 +#define IDS_CBA_CODE_WARNING            40
  744.48 +#define IDS_OUT_OF_MEMORY               41
  744.49 +#define IDS_STRING42                    42
  744.50 +#define IDI_ICON                        101
  744.51 +#define IDD_REGISTERS                   102
  744.52 +#define IDD_DEBUG                       103
  744.53 +#define IDR_MENU                        104
  744.54 +#define IDD_ABOUT                       105
  744.55 +#define IDR_ACCELERATOR                 106
  744.56 +#define IDD_CHEATS                      107
  744.57 +#define IDD_ADD_CHEAT                   108
  744.58 +#define IDD_DIRECTORIES                 109
  744.59 +#define IDD_CONFIG                      110
  744.60 +#define IDD_GS                          111
  744.61 +#define IDD_GG                          112
  744.62 +#define IDD_CHEAT_LIST                  113
  744.63 +#define IDD_ASSOCIATIONS                114
  744.64 +#define IDR_GB_PRINTER                  115
  744.65 +#define IDD_GBA_ROM_INFO                116
  744.66 +#define IDD_GB_ROM_INFO                 117
  744.67 +#define IDD_GB_CHEAT_LIST               118
  744.68 +#define IDD_ADD_CHEAT_DLG               119
  744.69 +#define IDD_GB_PRINTER                  120
  744.70 +#define IDD_MOTION_CONFIG               121
  744.71 +#define IDD_LANG_SELECT                 122
  744.72 +#define IDD_CODE_SELECT                 123
  744.73 +#define IDD_OPENDLG                     124
  744.74 +#define IDD_MAP_VIEW                    126
  744.75 +#define IDD_PALETTE_VIEW                127
  744.76 +#define IDD_MEM_VIEWER                  128
  744.77 +#define IDD_OAM_VIEW                    130
  744.78 +#define IDD_ACCEL_EDITOR                131
  744.79 +#define IDD_TILE_VIEWER                 132
  744.80 +#define IDD_GB_COLORS                   133
  744.81 +#define IDD_DISASSEMBLE                 134
  744.82 +#define IDD_GDB_PORT                    135
  744.83 +#define IDD_GDB_WAITING                 136
  744.84 +#define IDD_LOGGING                     137
  744.85 +#define IDD_EXPORT_SPS                  138
  744.86 +#define IDD_ADDR_SIZE                   139
  744.87 +#define IDD_MODES                       140
  744.88 +#define IDD_DRIVERS                     142
  744.89 +#define IDD_THROTTLE                    143
  744.90 +#define IDD_GB_DISASSEMBLE              144
  744.91 +#define IDD_GB_OAM_VIEW                 145
  744.92 +#define IDD_GB_TILE_VIEWER              146
  744.93 +#define IDD_GB_MAP_VIEW                 147
  744.94 +#define IDD_GB_PALETTE_VIEW             148
  744.95 +#define IDD_MODE_CONFIRM                149
  744.96 +#define IDD_REWIND_INTERVAL             150
  744.97 +#define IDD_IO_VIEWER                   151
  744.98 +#define IDD_MAX_SCALE                   154
  744.99 +#define IDD_BUG_REPORT                  155
 744.100 +#define IDD_MOVIECREATE                 156
 744.101 +#define IDD_MOVIEOPEN                   157
 744.102 +#define IDD_TEXTCONFIG                  158
 744.103 +#define IDD_LUA                         159
 744.104 +#define IDD_ARCHIVEFILECHOOSER          160
 744.105 +#define IDD_RAMSEARCH                   161
 744.106 +#define IDD_EDITWATCH                   162
 744.107 +#define IDD_RAMWATCH                    163
 744.108 +#define IDD_PROMPT                      164
 744.109 +#define IDR_ACCELERATOR1                165
 744.110 +#define IDC_R0                          1000
 744.111 +#define IDC_EDIT_UP                     1000
 744.112 +#define IDC_R1                          1001
 744.113 +#define IDC_EDIT_DOWN                   1001
 744.114 +#define IDC_R2                          1002
 744.115 +#define IDC_EDIT_LEFT                   1002
 744.116 +#define IDC_R3                          1003
 744.117 +#define IDC_EDIT_RIGHT                  1003
 744.118 +#define IDC_R4                          1004
 744.119 +#define IDC_EDIT_BUTTON_A               1004
 744.120 +#define IDC_R5                          1005
 744.121 +#define IDC_EDIT_BUTTON_B               1005
 744.122 +#define IDC_R6                          1006
 744.123 +#define IDC_EDIT_BUTTON_SELECT          1006
 744.124 +#define IDC_R7                          1007
 744.125 +#define IDC_EDIT_BUTTON_START           1007
 744.126 +#define IDC_R8                          1008
 744.127 +#define ID_OK                           1008
 744.128 +#define IDC_R9                          1009
 744.129 +#define ID_CANCEL                       1009
 744.130 +#define ID_SAVE                         1009
 744.131 +#define IDC_R10                         1010
 744.132 +#define IDC_EDIT_SPEED                  1010
 744.133 +#define IDC_R11                         1011
 744.134 +#define IDC_EDIT_CAPTURE                1011
 744.135 +#define IDC_R12                         1012
 744.136 +#define IDC_EDIT_BUTTON_L               1012
 744.137 +#define IDC_R13                         1013
 744.138 +#define IDC_EDIT_BUTTON_GS              1013
 744.139 +#define IDC_R14                         1014
 744.140 +#define IDC_EDIT_BUTTON_R               1014
 744.141 +#define IDC_R15                         1015
 744.142 +#define IDC_R16                         1016
 744.143 +#define IDC_R17                         1017
 744.144 +#define IDC_N_FLAG                      1018
 744.145 +#define IDC_Z_FLAG                      1019
 744.146 +#define IDC_NEXT                        1019
 744.147 +#define IDC_C_FLAG                      1020
 744.148 +#define IDC_CONTINUE                    1020
 744.149 +#define IDC_V_FLAG                      1021
 744.150 +#define IDC_CHEAT_LIST                  1021
 744.151 +#define IDC_IRQ                         1022
 744.152 +#define IDC_START                       1022
 744.153 +#define IDC_T_FLAG                      1023
 744.154 +#define IDC_SEARCH                      1023
 744.155 +#define IDS_DIRECTX_7_REQUIRED          1024
 744.156 +#define IDC_ADD_CHEAT                   1024
 744.157 +#define IDC_OLD_VALUE                   1025
 744.158 +#define IDC_ADD_GS_CHEAT                1025
 744.159 +#define IDS_DISABLING_VIDEO_MEMORY      1025
 744.160 +#define IDC_ADD_GAMESHARK               1025
 744.161 +#define IDC_SPECIFIC_VALUE              1026
 744.162 +#define IDS_SETTING_WILL_BE_EFFECTIVE   1026
 744.163 +#define IDS_DISABLING_EMULATION_ONLY    1027
 744.164 +#define IDC_SIZE_8                      1028
 744.165 +#define IDS_FAILED_TO_OPEN_FILE         1028
 744.166 +#define IDC_SIZE_16                     1029
 744.167 +#define IDS_FAILED_TO_READ_ZIP_DIR      1029
 744.168 +#define IDC_SIZE_32                     1030
 744.169 +#define IDS_UNSUPPORTED_FILE_TYPE       1030
 744.170 +#define IDC_EQ                          1031
 744.171 +#define IDS_CANNOT_CREATE_DIRECTSOUND   1031
 744.172 +#define IDC_NE                          1032
 744.173 +#define IDS_CANNOT_SETCOOPERATIVELEVEL  1032
 744.174 +#define IDC_LT                          1033
 744.175 +#define IDS_CANNOT_CREATESOUNDBUFFER    1033
 744.176 +#define IDC_LE                          1034
 744.177 +#define IDS_CANNOT_SETFORMAT_PRIMARY    1034
 744.178 +#define IDC_GT                          1035
 744.179 +#define IDS_CANNOT_CREATESOUNDBUFFER_SEC 1035
 744.180 +#define IDC_GE                          1036
 744.181 +#define IDS_CANNOT_PLAY_PRIMARY         1036
 744.182 +#define IDC_SIGNED                      1037
 744.183 +#define IDS_SEARCH_PRODUCED_TOO_MANY    1037
 744.184 +#define IDC_UNSIGNED                    1038
 744.185 +#define IDS_NUMBER_CANNOT_BE_EMPTY      1038
 744.186 +#define IDS_INVALID_ADDRESS             1039
 744.187 +#define IDC_HEXADECIMAL                 1040
 744.188 +#define IDS_MISALIGNED_HALFWORD         1040
 744.189 +#define IDC_VALUE                       1041
 744.190 +#define IDS_MISALIGNED_WORD             1041
 744.191 +#define IDC_ADDRESS                     1042
 744.192 +#define IDS_VALUE_CANNOT_BE_EMPTY       1042
 744.193 +#define IDS_ERROR_ON_STARTDOC           1043
 744.194 +#define IDC_R                           1043
 744.195 +#define IDS_ERROR_ON_STARTPAGE          1044
 744.196 +#define IDC_G                           1044
 744.197 +#define IDS_ERROR_PRINTING_ON_STRETCH   1045
 744.198 +#define IDC_B                           1045
 744.199 +#define IDC_UPDATE                      1046
 744.200 +#define IDS_ERROR_ON_ENDPAGE            1046
 744.201 +#define IDC_TILE_NUM                    1046
 744.202 +#define IDC_GGDESC                      1047
 744.203 +#define IDS_ERROR_ON_ENDDOC             1047
 744.204 +#define IDC_FLIP                        1047
 744.205 +#define IDC_GGCODE                      1048
 744.206 +#define IDS_ERROR                       1048
 744.207 +#define IDC_PALETTE_NUM                 1048
 744.208 +#define IDC_GGADD                       1049
 744.209 +#define IDS_JOY_LEFT                    1049
 744.210 +#define IDC_GGDEL                       1050
 744.211 +#define IDS_JOY_RIGHT                   1050
 744.212 +#define IDC_GGLIST                      1051
 744.213 +#define IDS_JOY_UP                      1051
 744.214 +#define IDC_GGRES                       1052
 744.215 +#define IDS_JOY_DOWN                    1052
 744.216 +#define IDC_GGQUIT                      1053
 744.217 +#define IDS_JOY_BUTTON                  1053
 744.218 +#define IDC_GSDESC                      1054
 744.219 +#define IDC_GSCODE                      1055
 744.220 +#define IDC_GSADD                       1056
 744.221 +#define IDC_GSDEL                       1057
 744.222 +#define IDC_GSLIST                      1058
 744.223 +#define IDS_SELECT_BIOS_FILE            1058
 744.224 +#define IDC_GSRES                       1059
 744.225 +#define IDS_RESET                       1059
 744.226 +#define IDC_GSQUIT                      1060
 744.227 +#define IDS_AUTOFIRE_A_DISABLED         1060
 744.228 +#define IDC_FREEZE                      1061
 744.229 +#define IDS_AUTOFIRE_A                  1061
 744.230 +#define IDS_AUTOFIRE_B_DISABLED         1062
 744.231 +#define IDS_AUTOFIRE_B                  1063
 744.232 +#define IDS_AUTOFIRE_L_DISABLED         1064
 744.233 +#define IDS_AUTOFIRE_L                  1065
 744.234 +#define IDS_AUTOFIRE_R_DISABLED         1066
 744.235 +#define IDC_REMOVE                      1067
 744.236 +#define IDS_AUTOFIRE_R                  1067
 744.237 +#define IDC_REMOVE_ALL                  1068
 744.238 +#define IDS_SELECT_ROM                  1068
 744.239 +#define IDS_SELECT_SAVE_GAME_NAME       1069
 744.240 +#define IDC_ENABLE                      1070
 744.241 +#define IDS_LOADED_STATE                1070
 744.242 +#define IDS_LOADED_STATE_N              1071
 744.243 +#define IDS_WROTE_STATE                 1072
 744.244 +#define IDS_WROTE_STATE_N               1073
 744.245 +#define IDC_RESTORE                     1074
 744.246 +#define IDS_LOADED_BATTERY              1074
 744.247 +#define IDC_GBA                         1075
 744.248 +#define IDS_SELECT_CAPTURE_NAME         1075
 744.249 +#define IDC_AGB                         1076
 744.250 +#define IDS_SCREEN_CAPTURE              1076
 744.251 +#define IDC_BIN                         1077
 744.252 +#define IDS_ADDRESS                     1077
 744.253 +#define IDC_GB                          1078
 744.254 +#define IDS_OLD_VALUE                   1078
 744.255 +#define IDC_SGB                         1079
 744.256 +#define IDC_ROM_TITLE                   1079
 744.257 +#define IDS_NEW_VALUE                   1079
 744.258 +#define IDC_CGB                         1080
 744.259 +#define IDC_ROM_GAME_CODE               1080
 744.260 +#define IDS_ADD_CHEAT_CODE              1080
 744.261 +#define IDC_GBC                         1081
 744.262 +#define IDC_ROM_MAKER_CODE              1081
 744.263 +#define IDS_CODE                        1081
 744.264 +#define IDC_ROM_UNIT_CODE               1082
 744.265 +#define IDS_DESCRIPTION                 1082
 744.266 +#define IDC_ROM_DEVICE_TYPE             1083
 744.267 +#define IDS_STATUS                      1083
 744.268 +#define IDC_ROM_VERSION                 1084
 744.269 +#define IDS_ADD_GG_CODE                 1084
 744.270 +#define IDC_ROM_CRC                     1085
 744.271 +#define IDS_ADD_GS_CODE                 1085
 744.272 +#define IDC_ROM_COLOR                   1086
 744.273 +#define IDC_CODE                        1086
 744.274 +#define IDS_POCKET_PRINTER              1086
 744.275 +#define IDC_ROM_MAKER_NAME              1086
 744.276 +#define IDC_ROM_SIZE                    1087
 744.277 +#define IDC_DESC                        1087
 744.278 +#define IDS_UNKNOWN                     1087
 744.279 +#define IDC_ROM_RAM_SIZE                1088
 744.280 +#define IDC_ADD_GG_CHEAT                1088
 744.281 +#define IDS_NONE                        1088
 744.282 +#define IDC_ROM_DEST_CODE               1089
 744.283 +#define IDC_GB_PRINTER                  1089
 744.284 +#define IDS_FAILED_TO_LOAD_LIBRARY      1089
 744.285 +#define IDC_ROM_LIC_CODE                1090
 744.286 +#define IDC_1X                          1090
 744.287 +#define IDS_FAILED_TO_GET_LOCINFO       1090
 744.288 +#define IDC_EDIT_AUTHOR                 1090
 744.289 +#define IDC_ROM_CHECKSUM                1091
 744.290 +#define IDC_2X                          1091
 744.291 +#define IDS_SELECT_CHEAT_LIST_NAME      1091
 744.292 +#define IDC_EDIT_DESCRIPTION            1091
 744.293 +#define IDC_3X                          1092
 744.294 +#define IDS_FILTER_BIOS                 1092
 744.295 +#define IDC_4X                          1093
 744.296 +#define IDS_FILTER_ROM                  1093
 744.297 +#define IDC_ROM_MAKER_NAME2             1093
 744.298 +#define ID_PRINT                        1094
 744.299 +#define IDS_FILTER_SGM                  1094
 744.300 +#define IDC_ADD_GSA                     1095
 744.301 +#define IDC_ADD_CODE                    1095
 744.302 +#define IDS_FILTER_CHEAT_LIST           1095
 744.303 +#define IDC_TRANSLATION_BY              1096
 744.304 +#define IDS_FILTER_PNG                  1096
 744.305 +#define IDC_LANG_STRING                 1097
 744.306 +#define IDS_LOADED_CHEATS               1097
 744.307 +#define IDC_LANG_NAME                   1098
 744.308 +#define IDS_ERROR_DISP_COLOR            1098
 744.309 +#define IDS_ADD_GSA_CODE                1099
 744.310 +#define IDC_GAME_LIST                   1099
 744.311 +#define IDS_FILTER_SPS                  1100
 744.312 +#define IDS_SELECT_SNAPSHOT_FILE        1101
 744.313 +#define IDC_ADD_CODEBREAKER             1101
 744.314 +#define IDS_FILTER_SAV                  1102
 744.315 +#define IDS_SELECT_BATTERY_FILE         1103
 744.316 +#define IDS_FILTER_GBS                  1104
 744.317 +#define IDS_FILTER_GCF                  1105
 744.318 +#define IDS_SELECT_CODE_FILE            1106
 744.319 +#define IDS_SAVE_WILL_BE_LOST           1107
 744.320 +#define IDS_CONFIRM_ACTION              1108
 744.321 +#define IDS_CODES_WILL_BE_LOST          1109
 744.322 +#define IDS_FILTER_SPC                  1110
 744.323 +#define IDS_ADD_CBA_CODE                1111
 744.324 +#define IDS_FILTER_WAV                  1112
 744.325 +#define IDS_SELECT_WAV_NAME             1113
 744.326 +#define IDC_FRAME_0                     1113
 744.327 +#define IDS_FILTER_GBROM                1114
 744.328 +#define IDC_FRAME_1                     1114
 744.329 +#define IDC_BG0                         1115
 744.330 +#define IDS_FILTER_PAL                  1115
 744.331 +#define IDC_BG1                         1116
 744.332 +#define IDS_SELECT_PALETTE_NAME         1116
 744.333 +#define IDC_BG2                         1117
 744.334 +#define IDS_SEARCH_PRODUCED_NO_RESULTS  1117
 744.335 +#define IDC_BG3                         1118
 744.336 +#define IDS_ERROR_BINDING               1118
 744.337 +#define IDS_ERROR_LISTENING             1119
 744.338 +#define IDS_ERROR_CREATING_SOCKET       1120
 744.339 +#define IDS_ACK_NOT_RECEIVED            1121
 744.340 +#define IDS_ERROR_NOT_GBA_IMAGE         1122
 744.341 +#define IDS_EEPROM_NOT_SUPPORTED        1123
 744.342 +#define IDC_MAP_VIEW                    1124
 744.343 +#define IDS_FILTER_DUMP                 1124
 744.344 +#define IDC_PALETTE_VIEW                1125
 744.345 +#define IDS_SELECT_DUMP_FILE            1125
 744.346 +#define IDC_PALETTE_VIEW_OBJ            1126
 744.347 +#define IDC_REFRESH                     1126
 744.348 +#define IDS_FILTER_AVI                  1126
 744.349 +#define IDC_SAVE                        1127
 744.350 +#define IDC_GOPC                        1127
 744.351 +#define IDS_SELECT_AVI_NAME             1127
 744.352 +#define IDC_APPLY                       1127
 744.353 +#define IDS_INVALID_THROTTLE_VALUE      1128
 744.354 +#define IDC_REFRESH2                    1129
 744.355 +#define IDS_FILTER_INI                  1129
 744.356 +#define IDS_SELECT_SKIN_FILE            1130
 744.357 +#define IDC_CLOSE                       1131
 744.358 +#define IDS_FILTER_VMV                  1131
 744.359 +#define IDS_FILTER_MOVIE                1131
 744.360 +#define IDS_SELECT_MOVIE_NAME           1132
 744.361 +#define IDS_BUG_REPORT                  1133
 744.362 +#define IDS_UNSUPPORTED_MOVIE_VERSION   1134
 744.363 +#define IDS_END_OF_MOVIE                1135
 744.364 +#define IDC_COLOR                       1136
 744.365 +#define IDS_INVALID_INTERVAL_VALUE      1136
 744.366 +#define IDC_SAVE_BG                     1137
 744.367 +#define IDS_REGISTRY                    1137
 744.368 +#define IDC_SAVE_OBJ                    1138
 744.369 +#define IDC_MAP_VIEW_ZOOM               1138
 744.370 +#define IDS_MOVIE_PLAY                  1138
 744.371 +#define IDS_AUTOFIRE_DISABLED           1139
 744.372 +#define IDC_VIEWER                      1140
 744.373 +#define IDS_AUTOFIRE_ALREADY_DISABLED   1140
 744.374 +#define IDC_ADDRESSES                   1141
 744.375 +#define IDS_AUTOFIRE_START_DISABLED     1141
 744.376 +#define IDS_AUTOFIRE_START              1142
 744.377 +#define IDC_GO                          1143
 744.378 +#define IDS_AUTOFIRE_SELECT_DISABLED    1143
 744.379 +#define IDC_8_BIT                       1144
 744.380 +#define IDS_AUTOFIRE_SELECT             1144
 744.381 +#define IDC_16_BIT                      1145
 744.382 +#define IDS_AUTOFIRE_UP_DISABLED        1145
 744.383 +#define IDC_32_BIT                      1146
 744.384 +#define IDS_AUTOFIRE_UP                 1146
 744.385 +#define IDC_OAM_VIEW                    1147
 744.386 +#define IDS_AUTOFIRE_DOWN_DISABLED      1147
 744.387 +#define IDC_OAM_VIEW_ZOOM               1148
 744.388 +#define IDS_AUTOFIRE_DOWN               1148
 744.389 +#define IDS_AUTOFIRE_LEFT_DISABLED      1149
 744.390 +#define IDC_SPRITE                      1150
 744.391 +#define IDS_AUTOFIRE_LEFT               1150
 744.392 +#define IDC_POS                         1151
 744.393 +#define IDS_AUTOFIRE_RIGHT_DISABLED     1151
 744.394 +#define IDC_MODE                        1152
 744.395 +#define IDS_AUTOFIRE_RIGHT              1152
 744.396 +#define IDC_COLORS                      1153
 744.397 +#define IDC_MAPBASE                     1153
 744.398 +#define IDS_RERECORDED_STATE_N          1153
 744.399 +#define IDC_PALETTE                     1154
 744.400 +#define IDC_CHARBASE                    1154
 744.401 +#define IDS_REPLAYED_STATE_N            1154
 744.402 +#define IDC_TILE                        1155
 744.403 +#define IDC_DIM                         1155
 744.404 +#define IDC_PRIO                        1156
 744.405 +#define IDC_NUMCOLORS                   1156
 744.406 +#define IDC_SCROLLBAR                   1157
 744.407 +#define IDC_PRIORITY                    1157
 744.408 +#define IDC_MOSAIC                      1158
 744.409 +#define IDC_SIZE2                       1159
 744.410 +#define IDC_OVERFLOW                    1159
 744.411 +#define IDC_ROT                         1160
 744.412 +#define IDC_FLAGS                       1161
 744.413 +#define IDC_COMMANDS                    1162
 744.414 +#define IDC_BANK                        1162
 744.415 +#define IDC_CURRENTS                    1163
 744.416 +#define IDC_ASSIGN                      1164
 744.417 +#define IDC_RESET                       1165
 744.418 +#define IDC_EDIT_KEY                    1166
 744.419 +#define IDC_ALREADY_AFFECTED            1167
 744.420 +#define IDC_TILE_VIEW                   1168
 744.421 +#define IDC_16_COLORS                   1169
 744.422 +#define IDC_256_COLORS                  1170
 744.423 +#define IDC_CHARBASE_0                  1173
 744.424 +#define IDC_CHARBASE_1                  1174
 744.425 +#define IDC_CHARBASE_2                  1175
 744.426 +#define IDC_CHARBASE_3                  1176
 744.427 +#define IDC_PALETTE_SLIDER              1177
 744.428 +#define IDC_CHARBASE_4                  1178
 744.429 +#define IDC_COLOR_BG0                   1178
 744.430 +#define IDC_COLOR_BG1                   1179
 744.431 +#define IDC_URL                         1179
 744.432 +#define IDC_COLOR_BG2                   1180
 744.433 +#define IDC_STRETCH                     1180
 744.434 +#define IDC_COLOR_BG3                   1181
 744.435 +#define IDC_COLOR_OB0                   1182
 744.436 +#define IDC_COLOR_OB1                   1183
 744.437 +#define IDC_COLOR_OB2                   1184
 744.438 +#define IDC_COLOR_OB3                   1185
 744.439 +#define IDC_TRANSLATOR_URL              1186
 744.440 +#define IDC_STATIC1                     1187
 744.441 +#define IDC_STATIC2                     1188
 744.442 +#define IDC_STATIC3                     1189
 744.443 +#define IDC_STATIC4                     1190
 744.444 +#define IDC_DEFAULT                     1191
 744.445 +#define IDC_USER1                       1192
 744.446 +#define IDC_USER2                       1193
 744.447 +#define IDC_DISASSEMBLE                 1196
 744.448 +#define IDC_AUTOMATIC                   1199
 744.449 +#define IDC_ARM                         1200
 744.450 +#define IDC_THUMB                       1201
 744.451 +#define IDC_RECNOW                      1201
 744.452 +#define IDC_RECRESET                    1202
 744.453 +#define IDC_JOYPAD1                     1203
 744.454 +#define IDC_RECSTART                    1203
 744.455 +#define IDC_REC_NOBIOS                  1204
 744.456 +#define IDC_AUTO_UPDATE                 1204
 744.457 +#define IDC_JOYPAD2                     1204
 744.458 +#define IDC_REC_EMUBIOS                 1205
 744.459 +#define IDC_JOYPAD3                     1205
 744.460 +#define IDC_REC_GBABIOS                 1206
 744.461 +#define IDC_JOYPAD4                     1206
 744.462 +#define IDC_REC_GBABIOSINTRO            1207
 744.463 +#define IDC_MOVIE_FILENAME              1208
 744.464 +#define IDC_N                           1210
 744.465 +#define IDC_LABEL_DATE                  1210
 744.466 +#define IDC_Z                           1211
 744.467 +#define IDC_LABEL_LENGTH                1211
 744.468 +#define IDC_C                           1212
 744.469 +#define IDC_LABEL_FRAMES                1212
 744.470 +#define IDC_V                           1213
 744.471 +#define IDC_LABEL_RERECORD              1213
 744.472 +#define IDC_F                           1214
 744.473 +#define IDC_LABEL_FROM                  1214
 744.474 +#define IDC_I                           1215
 744.475 +#define IDC_T                           1216
 744.476 +#define IDC_LABEL_WARNING1              1216
 744.477 +#define IDC_PORT                        1217
 744.478 +#define IDC_LABEL_WARNING2              1217
 744.479 +#define IDC_VSCROLL                     1218
 744.480 +#define IDC_LABEL_FROM2                 1218
 744.481 +#define IDC_VERSION                     1219
 744.482 +#define IDC_VERBOSE_SWI                 1223
 744.483 +#define IDC_VERBOSE_UNALIGNED_ACCESS    1224
 744.484 +#define IDC_VERBOSE_ILLEGAL_WRITE       1225
 744.485 +#define IDC_VERBOSE_ILLEGAL_READ        1226
 744.486 +#define IDC_LOG                         1227
 744.487 +#define IDC_CLEAR                       1228
 744.488 +#define IDC_VERBOSE_DMA0                1229
 744.489 +#define IDC_VERBOSE_DMA1                1230
 744.490 +#define IDC_TILE_NUMBER                 1230
 744.491 +#define IDC_VERBOSE_DMA2                1231
 744.492 +#define IDC_XY                          1231
 744.493 +#define IDC_VERBOSE_DMA3                1232
 744.494 +#define IDC_VERBOSE_UNDEFINED           1233
 744.495 +#define IDC_TITLE                       1234
 744.496 +#define IDC_VERBOSE_AGBPRINT            1234
 744.497 +#define IDC_CURRENT_ADDRESS             1235
 744.498 +#define IDC_NOTES                       1236
 744.499 +#define IDC_CURRENT_ADDRESS_LABEL       1236
 744.500 +#define IDC_LOAD                        1238
 744.501 +#define IDC_SIZE_CONTROL                1240
 744.502 +#define IDC_MODES                       1240
 744.503 +#define IDC_DRIVERS                     1241
 744.504 +#define IDC_THROTTLE                    1242
 744.505 +#define IDC_READONLY                    1242
 744.506 +#define IDC_H                           1243
 744.507 +#define IDC_OAP                         1244
 744.508 +#define IDC_BANK_0                      1245
 744.509 +#define IDC_BANK_1                      1246
 744.510 +#define IDC_TIMER                       1247
 744.511 +#define IDC_INTERVAL                    1248
 744.512 +#define IDC_REWINDSLOTS                 1249
 744.513 +#define IDC_BIT_0                       1250
 744.514 +#define IDC_BIT_1                       1251
 744.515 +#define IDC_PREDEFINED                  1251
 744.516 +#define IDC_BIT_2                       1252
 744.517 +#define IDC_BUG_REPORT                  1252
 744.518 +#define IDC_BIT_3                       1253
 744.519 +#define IDC_COPY                        1253
 744.520 +#define IDC_BIT_4                       1254
 744.521 +#define IDC_BROWSE                      1254
 744.522 +#define IDC_BIT_5                       1255
 744.523 +#define IDC_COMBO1                      1255
 744.524 +#define IDC_MOVIE_REFRESH               1255
 744.525 +#define IDC_BIT_6                       1256
 744.526 +#define IDC_REC_GBA                     1257
 744.527 +#define IDC_BIT_7                       1257
 744.528 +#define IDC_REC_GBC                     1258
 744.529 +#define IDC_BIT_8                       1258
 744.530 +#define IDC_REC_SGB                     1259
 744.531 +#define IDC_BIT_9                       1259
 744.532 +#define IDC_REC_SGB2                    1260
 744.533 +#define IDC_BIT_10                      1260
 744.534 +#define IDC_REC_GB                      1260
 744.535 +#define IDC_BIT_11                      1261
 744.536 +#define IDC_RADIO1                      1261
 744.537 +#define IDC_BIT_12                      1262
 744.538 +#define IDC_EDIT_PAUSEFRAME             1262
 744.539 +#define IDC_BIT_13                      1263
 744.540 +#define IDC_CHECK_PAUSEFRAME            1263
 744.541 +#define IDC_BIT_14                      1264
 744.542 +#define IDC_SLIDER1                     1264
 744.543 +#define IDC_BIT_15                      1265
 744.544 +#define IDC_CHECK_HIDEBORDER            1265
 744.545 +#define IDC_RADIO_WHITE                 1266
 744.546 +#define IDC_RADIO_RED                   1267
 744.547 +#define IDC_RADIO_YELLOW                1268
 744.548 +#define IDC_RADIO_GREEN                 1269
 744.549 +#define IDC_RADIO_CYAN                  1270
 744.550 +#define IDC_RADIO_BLUE                  1271
 744.551 +#define IDC_RADIO_MAGENTA               1272
 744.552 +#define IDC_RADIO_BLACK                 1273
 744.553 +#define IDC_CHECK_OUTLINED              1274
 744.554 +#define IDC_CHECK_TRANSPARENT           1275
 744.555 +#define IDC_RADIO_PREFILTER             1276
 744.556 +#define IDC_RADIO_POSTFILTER            1277
 744.557 +#define IDC_RADIO_POSTRENDER            1278
 744.558 +#define IDC_COMMANDS_HIDDEN             1279
 744.559 +#define IDC_DECIMAL_DISPLAY             1281
 744.560 +#define IDC_ALIGN                       1282
 744.561 +#define IDC_CHEATREFRESHBUTTON          1283
 744.562 +#define IDC_EDIT_LUAPATH                1285
 744.563 +#define IDC_BUTTON_LUABROWSE            1286
 744.564 +#define IDS_FILTER_LUA                  1287
 744.565 +#define IDS_SELECT_LUA_NAME             1288
 744.566 +#define IDS_SELECT_LUA_DIR              1289
 744.567 +#define IDS_SELECT_MOVIE_DIR            1290
 744.568 +#define IDS_SELECT_ROM_DIR              1291
 744.569 +#define IDS_SELECT_GBXROM_DIR           1292
 744.570 +#define IDS_SELECT_BATTERY_DIR          1293
 744.571 +#define IDS_SELECT_SAVE_DIR             1294
 744.572 +#define IDS_SELECT_CAPTURE_DIR          1295
 744.573 +#define IDS_SELECT_AVI_DIR              1296
 744.574 +#define IDS_SELECT_WAV_DIR              1297
 744.575 +#define IDS_SELECT_CHEAT_DIR            1298
 744.576 +#define IDS_SELECT_WATCH_DIR            1299
 744.577 +#define IDS_SELECT_IPS_DIR              1300
 744.578 +#define IDS_SELECT_PLUGIN_DIR           1301
 744.579 +#define IDC_PLUGIN_DIR                  1308
 744.580 +#define IDC_WATCH_DIR                   1309
 744.581 +#define IDC_ROM_DIR                     1310
 744.582 +#define IDC_GBXROM_DIR                  1311
 744.583 +#define IDC_BATTERY_DIR                 1312
 744.584 +#define IDC_SAVE_DIR                    1313
 744.585 +#define IDC_MOVIE_DIR                   1314
 744.586 +#define IDC_CHEAT_DIR                   1315
 744.587 +#define IDC_LUA_DIR                     1316
 744.588 +#define IDC_AVI_DIR                     1317
 744.589 +#define IDC_WAV_DIR                     1318
 744.590 +#define IDC_CAPTURE_DIR                 1319
 744.591 +#define IDC_IPS_DIR                     1320
 744.592 +#define IDC_PLUGIN_PATH                 1328
 744.593 +#define IDC_WATCH_PATH                  1329
 744.594 +#define IDC_ROM_PATH                    1330
 744.595 +#define IDC_GBXROM_PATH                 1331
 744.596 +#define IDC_BATTERY_PATH                1332
 744.597 +#define IDC_SAVE_PATH                   1333
 744.598 +#define IDC_MOVIE_PATH                  1334
 744.599 +#define IDC_CHEAT_PATH                  1335
 744.600 +#define IDC_LUA_PATH                    1336
 744.601 +#define IDC_AVI_PATH                    1337
 744.602 +#define IDC_WAV_PATH                    1338
 744.603 +#define IDC_CAPTURE_PATH                1339
 744.604 +#define IDC_IPS_PATH                    1340
 744.605 +#define IDC_PLUGIN_DIR_RESET            1348
 744.606 +#define IDC_WATCH_DIR_RESET             1349
 744.607 +#define IDC_ROM_DIR_RESET               1350
 744.608 +#define IDC_GBXROM_DIR_RESET            1351
 744.609 +#define IDC_BATTERY_DIR_RESET           1352
 744.610 +#define IDC_SAVE_DIR_RESET              1353
 744.611 +#define IDC_MOVIE_DIR_RESET             1354
 744.612 +#define IDC_CHEAT_DIR_RESET             1355
 744.613 +#define IDC_LUA_DIR_RESET               1356
 744.614 +#define IDC_AVI_DIR_RESET               1357
 744.615 +#define IDC_WAV_DIR_RESET               1358
 744.616 +#define IDC_CAPTURE_DIR_RESET           1359
 744.617 +#define IDC_IPS_DIR_RESET               1360
 744.618 +#define IDC_LIST1                       1361
 744.619 +#define IDC_BUTTON_LUARUN               1362
 744.620 +#define IDC_BUTTON_LUASTOP              1363
 744.621 +#define IDC_LUACONSOLE                  1364
 744.622 +#define IDC_BUTTON_LUAEDIT              1365
 744.623 +#define IDC_LUACONSOLE_CLEAR            1366
 744.624 +#define IDC_LUACONSOLE_CHOOSEFONT       1367
 744.625 +#define IDC_ACCELEDIT_APPLY             1368
 744.626 +#define IDC_ACCELEDIT_SELECTALL         1369
 744.627 +#define IDC_ACCELEDIT_REPLACE           1370
 744.628 +#define IDC_ACCELEDIT_ONFLYKEYEDIT      1371
 744.629 +#define IDC_ACCELEDIT_PROGRESSBAR       1372
 744.630 +#define IDC_ACCELEDIT_AUTOTIMEOUT       1373
 744.631 +#define IDC_ACCELEDIT_UNDO              1374
 744.632 +#define IDC_STATIC5                     1375
 744.633 +#define ID_HELP_ABOUT                   40001
 744.634 +#define ID_FILE_EXIT                    40002
 744.635 +#define ID_OPTIONS_SOUND_MUTE           40003
 744.636 +#define ID_OPTIONS_VIDEO_VSYNC          40009
 744.637 +#define ID_OPTIONS_VIDEO_X1             40010
 744.638 +#define ID_OPTIONS_VIDEO_X2             40011
 744.639 +#define ID_OPTIONS_VIDEO_X3             40012
 744.640 +#define ID_OPTIONS_VIDEO_X4             40013
 744.641 +#define ID_FILE_PAUSE                   40014
 744.642 +#define ID_OPTIONS_EMULATOR_DIRECTORIES 40015
 744.643 +#define ID_OPTIONS_JOYPAD               40016
 744.644 +#define ID_OPTIONS_EMULATOR_SYNCHRONIZE 40017
 744.645 +#define ID_FILE_RESET                   40018
 744.646 +#define ID_FILE_LOAD                    40019
 744.647 +#define ID_OPTIONS_SOUND_DIRECTSOUNDA   40020
 744.648 +#define ID_OPTIONS_SOUND_DIRECTSOUNDB   40021
 744.649 +#define ID_OPTIONS_SOUND_DISABLE        40022
 744.650 +#define ID_OPTIONS_SOUND_OFF            40023
 744.651 +#define ID_OPTIONS_SOUND_ON             40024
 744.652 +#define ID_OPTIONS_SOUND_CHANNEL1       40025
 744.653 +#define ID_OPTIONS_SOUND_CHANNEL2       40026
 744.654 +#define ID_OPTIONS_SOUND_CHANNEL3       40027
 744.655 +#define ID_OPTIONS_SOUND_CHANNEL4       40028
 744.656 +#define ID_OPTIONS_EMULATOR_USEBIOSFILE 40029
 744.657 +#define ID_OPTIONS_EMULATOR_SELECTBIOSFILE 40030
 744.658 +#define ID_CHEATS_SEARCHFORCHEATS       40031
 744.659 +#define ID_CHEATS_ADDCHEAT              40032
 744.660 +#define ID_OPTIONS_VIDEO_DISABLESFX     40033
 744.661 +#define ID_OPTIONS_GAMEBOY_BORDER       40034
 744.662 +#define ID_FILE_SAVEGAME_SLOT1          40035
 744.663 +#define ID_FILE_SAVEGAME_SLOT2          40036
 744.664 +#define ID_FILE_SAVEGAME_SLOT3          40037
 744.665 +#define ID_FILE_SAVEGAME_SLOT4          40038
 744.666 +#define ID_FILE_SAVEGAME_SLOT5          40039
 744.667 +#define ID_FILE_SAVEGAME_SLOT6          40040
 744.668 +#define ID_FILE_SAVEGAME_SLOT7          40041
 744.669 +#define ID_FILE_SAVEGAME_SLOT8          40042
 744.670 +#define ID_FILE_SAVEGAME_SLOT9          40043
 744.671 +#define ID_FILE_SAVEGAME_SLOT10         40044
 744.672 +#define ID_FILE_LOADGAME_SLOT1          40045
 744.673 +#define ID_FILE_LOADGAME_SLOT2          40046
 744.674 +#define ID_FILE_LOADGAME_SLOT3          40047
 744.675 +#define ID_FILE_LOADGAME_SLOT4          40048
 744.676 +#define ID_FILE_LOADGAME_SLOT5          40049
 744.677 +#define ID_FILE_LOADGAME_SLOT6          40050
 744.678 +#define ID_FILE_LOADGAME_SLOT7          40051
 744.679 +#define ID_FILE_LOADGAME_SLOT8          40052
 744.680 +#define ID_FILE_LOADGAME_SLOT9          40053
 744.681 +#define ID_FILE_LOADGAME_SLOT10         40054
 744.682 +#define ID_OPTIONS_GAMEBOY_AUTOMATIC    40057
 744.683 +#define ID_OPTIONS_GAMEBOY_CGB          40058
 744.684 +#define ID_OPTIONS_GAMEBOY_GBA          40059
 744.685 +#define ID_OPTIONS_GAMEBOY_SGB          40060
 744.686 +#define ID_OPTIONS_GAMEBOY_GB           40062
 744.687 +#define ID_OPTIONS_GAMEBOY_REALCOLORS   40063
 744.688 +#define ID_OPTIONS_GAMEBOY_GAMEBOYCOLORS 40064
 744.689 +#define ID_CHEATS_GAMEBOY               40065
 744.690 +#define ID_OPTIONS_SOUND_11KHZ          40067
 744.691 +#define ID_OPTIONS_SOUND_22KHZ          40068
 744.692 +#define ID_OPTIONS_SOUND_44KHZ          40069
 744.693 +#define ID_OPTIONS_VIDEO_DDRAWEMULATIONONLY 40070
 744.694 +#define ID_OPTIONS_VIDEO_DDRAWUSEVIDEOMEMORY 40071
 744.695 +#define ID_OPTIONS_PRIORITY_HIGHEST     40072
 744.696 +#define ID_OPTIONS_PRIORITY_ABOVENORMAL 40073
 744.697 +#define ID_OPTIONS_PRIORITY_NORMAL      40074
 744.698 +#define ID_OPTIONS_PRIORITY_BELOWNORMAL 40075
 744.699 +#define ID_OPTIONS_VIDEO_FULLSCREEN320X240 40076
 744.700 +#define ID_OPTIONS_VIDEO_FULLSCREEN640X480 40077
 744.701 +#define ID_OPTIONS_FILTER_NORMAL        40078
 744.702 +#define ID_OPTIONS_FILTER_2XSAI         40079
 744.703 +#define ID_OPTIONS_FILTER_SUPER2XSAI    40081
 744.704 +#define ID_OPTIONS_FILTER_SUPEREAGLE    40082
 744.705 +#define ID_OPTIONS_FILTER_TVMODE        40083
 744.706 +#define ID_CHEATS_CHEATLIST             40084
 744.707 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_A_OLD 40085
 744.708 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_B_OLD 40086
 744.709 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_L_OLD 40087
 744.710 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_R_OLD 40088
 744.711 +#define ID_OPTIONS_VIDEO_FULLSCREENSTRETCHTOFIT 40089
 744.712 +#define ID_OPTIONS_EMULATOR_ASSOCIATE   40091
 744.713 +#define ID_OPTIONS_FILTER_DISABLEMMX    40093
 744.714 +#define ID_OPTIONS_1X                   40096
 744.715 +#define ID_OPTIONS_2X                   40097
 744.716 +#define ID_OPTIONS_3X                   40098
 744.717 +#define ID_OPTIONS_4X                   40099
 744.718 +#define ID_FILE_ROMINFORMATION          40100
 744.719 +#define ID_CHEATS_ADDCHEATCODE          40101
 744.720 +#define ID_OPTIONS_VIDEO_DISABLESTATUSMESSAGES 40102
 744.721 +#define ID_OPTIONS_JOYPAD_MOTIONCONFIGURE 40103
 744.722 +#define ID_FILE_SCREENCAPTURE           40104
 744.723 +#define ID_OPTIONS_LANGUAGE_SYSTEM      40105
 744.724 +#define ID_OPTIONS_LANGUAGE_ENGLISH     40106
 744.725 +#define ID_OPTIONS_LANGUAGE_OTHER       40107
 744.726 +#define ID_OPTIONS_GAMEBOY_PRINTER      40108
 744.727 +#define ID_FILE_RECENT_RESET            40109
 744.728 +#define ID_CHEATS_SAVECHEATLIST         40110
 744.729 +#define ID_CHEATS_LOADCHEATLIST         40111
 744.730 +#define ID_CHEATS_AUTOMATICSAVELOADCHEATS 40112
 744.731 +#define ID_FILE_IMPORT_GAMESHARKSNAPSHOT 40115
 744.732 +#define ID_FILE_IMPORT_BATTERYFILE      40116
 744.733 +#define ID_FILE_IMPORT_GAMESHARKCODEFILE 40117
 744.734 +#define ID_FILE_EXPORT_BATTERYFILE      40118
 744.735 +#define ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL 40121
 744.736 +#define ID_OPTIONS_FILTER16BIT_MOTIONBLUREXPERIMENTAL 40122
 744.737 +#define ID_OPTIONS_EMULATOR_PAUSEWHENINACTIVE 40123
 744.738 +#define ID_TOOLS_SOUNDRECORDING         40124
 744.739 +#define IDS_STARTSOUNDRECORDING         40125
 744.740 +#define IDS_STOPSOUNDRECORDING          40126
 744.741 +#define ID_OPTIONS_VIDEO_LAYERS_BG0     40127
 744.742 +#define ID_OPTIONS_VIDEO_LAYERS_BG1     40128
 744.743 +#define ID_OPTIONS_VIDEO_LAYERS_BG2     40129
 744.744 +#define ID_OPTIONS_VIDEO_LAYERS_BG3     40130
 744.745 +#define ID_OPTIONS_VIDEO_LAYERS_OBJ     40131
 744.746 +#define ID_OPTIONS_VIDEO_LAYERS_WIN0    40132
 744.747 +#define ID_OPTIONS_VIDEO_LAYERS_WIN1    40133
 744.748 +#define ID_OPTIONS_VIDEO_LAYERS_OBJWIN  40134
 744.749 +#define ID_FILE_OPENGAMEBOY             40135
 744.750 +#define ID_OPTIONS_SOUND_USEOLDSYNCHRONIZATION 40136
 744.751 +#define ID_DEBUG_NEXTFRAME              40137
 744.752 +#define ID_TOOLS_MAPVIEW                40138
 744.753 +#define ID_TOOLS_PALETTEVIEW            40139
 744.754 +#define ID_OPTIONS_EMULATOR_PNGFORMAT   40140
 744.755 +#define ID_OPTIONS_EMULATOR_BMPFORMAT   40141
 744.756 +#define ID_TOOLS_CUSTOMIZE_COMMON       40142
 744.757 +#define ID_TOOLS_MEMORYVIEWER           40143
 744.758 +#define ID_TOOLS_OAMVIEWER              40144
 744.759 +#define ID_TOOLS_TILEVIEWER             40146
 744.760 +#define ID_OPTIONS_GAMEBOY_COLORS       40147
 744.761 +#define ID_OPTIONS_SOUND_ECHO           40148
 744.762 +#define ID_OPTIONS_SOUND_LOWPASSFILTER  40149
 744.763 +#define ID_OPTIONS_SOUND_REVERSESTEREO  40150
 744.764 +#define ID_TOOLS_DISASSEMBLE            40151
 744.765 +#define ID_TOOLS_DEBUG_GDB              40152
 744.766 +#define ID_TOOLS_DEBUG_LOADANDWAIT      40153
 744.767 +#define ID_TOOLS_DEBUG_DISCONNECT       40154
 744.768 +#define ID_TOOLS_DEBUG_BREAK            40155
 744.769 +#define ID_TOOLS_LOGGING                40156
 744.770 +#define ID_OPTIONS_EMULATOR_SPEEDHACK   40157
 744.771 +#define ID_OPTIONS_EMULATOR_SPEEDUPTOGGLE 40158
 744.772 +#define ID_OPTIONS_EMULATOR_REMOVEINTROSGBA 40159
 744.773 +#define ID_OPTIONS_FILTER16BIT_ADVANCEMAMESCALE2X 40160
 744.774 +#define ID_OPTIONS_FILTER16BIT_SIMPLE2X 40161
 744.775 +#define ID_FILE_RECENT_FREEZE           40162
 744.776 +#define ID_FILE_EXPORT_GAMESHARKSNAPSHOT 40163
 744.777 +#define ID_OPTIONS_VIDEO_FULLSCREEN800X600 40164
 744.778 +#define ID_OPTIONS_FILTER16BIT_SIMPLE3X 40165
 744.779 +#define ID_OPTIONS_FILTER16BIT_SIMPLE4X 40166
 744.780 +#define ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL3X 40167
 744.781 +#define ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL4X 40168
 744.782 +#define ID_OPTIONS_EMULATOR_SAVETYPE_AUTOMATIC 40169
 744.783 +#define ID_OPTIONS_EMULATOR_SAVETYPE_EEPROM 40170
 744.784 +#define ID_OPTIONS_EMULATOR_SAVETYPE_SRAM 40171
 744.785 +#define ID_OPTIONS_EMULATOR_SAVETYPE_FLASH 40172
 744.786 +#define ID_OPTIONS_EMULATOR_SAVETYPE_EEPROMSENSOR 40173
 744.787 +#define ID_OPTIONS_EMULATOR_SAVETYPE_FLASH512K 40174
 744.788 +#define ID_OPTIONS_EMULATOR_SAVETYPE_FLASH1M 40175
 744.789 +#define ID_OPTIONS_EMULATOR_AUTOMATICALLYIPSPATCH 40176
 744.790 +#define ID_TOOLS_AVIRECORDING           40177
 744.791 +#define IDS_STARTAVIRECORDING           40178
 744.792 +#define IDS_STOPAVIRECORDING            40179
 744.793 +#define IDS_PAUSEAVIRECORDING           40180
 744.794 +#define IDS_RESUMEAVIRECORDING          40181
 744.795 +#define ID_OPTIONS_SOUND_VOLUME_1X      40182
 744.796 +#define ID_OPTIONS_SOUND_VOLUME_2X      40183
 744.797 +#define ID_OPTIONS_SOUND_VOLUME_3X      40184
 744.798 +#define ID_OPTIONS_SOUND_VOLUME_4X      40185
 744.799 +#define ID_OPTIONS_FILTER_BILINEAR      40186
 744.800 +#define ID_OPTIONS_FILTER_BILINEARPLUS  40187
 744.801 +#define ID_OPTIONS_FILTER_INTERFRAMEBLENDING_NONE 40188
 744.802 +#define ID_OPTIONS_FILTER_INTERFRAMEBLENDING_MOTIONBLUR 40189
 744.803 +#define ID_OPTIONS_FILTER_INTERFRAMEBLENDING_SMART 40190
 744.804 +#define ID_OPTIONS_VIDEO_FULLSCREEN     40191
 744.805 +#define ID_OPTIONS_VIDEO_TRIPLEBUFFERING 40192
 744.806 +#define ID_OPTIONS_FRAMESKIP_AUTOMATIC  40194
 744.807 +#define ID_OPTIONS_EMULATOR_SHOWSPEED_NONE 40195
 744.808 +#define ID_OPTIONS_EMULATOR_SHOWSPEED_PERCENTAGE 40196
 744.809 +#define ID_OPTIONS_EMULATOR_SHOWSPEED_DETAILED 40197
 744.810 +#define ID_OPTIONS_EMULATOR_SHOWSPEED_TRANSPARENT 40198
 744.811 +#define ID_OPTIONS_JOYPAD_CONFIGURE_1   40199
 744.812 +#define ID_OPTIONS_JOYPAD_CONFIGURE_2   40200
 744.813 +#define ID_OPTIONS_JOYPAD_CONFIGURE_3   40201
 744.814 +#define ID_OPTIONS_JOYPAD_CONFIGURE_4   40202
 744.815 +#define ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_1 40208
 744.816 +#define ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_2 40209
 744.817 +#define ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_3 40210
 744.818 +#define ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_4 40211
 744.819 +#define ID_OPTIONS_EMULATOR_STORESETTINGSINREGISTRY 40214
 744.820 +#define ID_FILE_EXPORT_SETTINGSTOINI    40215
 744.821 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_NOTHROTTLE 40216
 744.822 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_OTHER 40221
 744.823 +#define ID_SYSTEM_MAXIMIZE              40222
 744.824 +#define ID_OPTIONS_FILTER_SCANLINES     40223
 744.825 +#define ID_OPTIONS_VIDEO_RENDERMETHOD_GDI 40228
 744.826 +#define ID_OPTIONS_VIDEO_RENDERMETHOD_DIRECTDRAW 40229
 744.827 +#define ID_OPTIONS_VIDEO_RENDERMETHOD_DIRECT3D 40230
 744.828 +#define ID_OPTIONS_VIDEO_RENDERMETHOD_OPENGL 40231
 744.829 +#define ID_OPTIONS_VIDEO_RENDEROPTIONS_D3DNOFILTER 40233
 744.830 +#define ID_OPTIONS_VIDEO_RENDEROPTIONS_D3DBILINEAR 40234
 744.831 +#define ID_OPTIONS_VIDEO_RENDEROPTIONS_D3DTRILINEAR 40235
 744.832 +#define ID_OPTIONS_VIDEO_RENDEROPTIONS_D3DANISOTROPIC 40236
 744.833 +#define ID_OPTIONS_VIDEO_RENDEROPTIONS_GLNEAREST 40237
 744.834 +#define ID_OPTIONS_VIDEO_RENDEROPTIONS_GLBILINEAR 40238
 744.835 +#define ID_OPTIONS_VIDEO_RENDEROPTIONS_GLTRIANGLE 40239
 744.836 +#define ID_OPTIONS_VIDEO_RENDEROPTIONS_GLQUADS 40240
 744.837 +#define ID_OPTIONS_VIDEO_RENDEROPTIONS_SELECTSKIN 40245
 744.838 +#define ID_OPTIONS_VIDEO_RENDEROPTIONS_SKIN 40246
 744.839 +#define ID_OPTIONS_EMULATOR_AGBPRINT    40247
 744.840 +#define ID_OPTIONS_EMULATOR_REALTIMECLOCK 40248
 744.841 +#define ID_OPTIONS_GAMEBOY_SGB2         40249
 744.842 +#define ID_SYSTEM_MINIMIZE              40250
 744.843 +#define ID_MOVIE_RECORD                 40251
 744.844 +#define ID_MOVIE_PLAY                   40253
 744.845 +#define ID_MOVIE_STOP                   40254
 744.846 +#define ID_OPTIONS_EMULATOR_AUTOHIDEMENU 40255
 744.847 +#define ID_OPTIONS_GAMEBOY_BORDERAUTOMATIC 40256
 744.848 +#define ID_OPTIONS_EMULATOR_REWIND      40257
 744.849 +#define ID_TOOLS_REWIND                 40258
 744.850 +#define ID_OPTIONS_EMULATOR_SKIPBIOS    40259
 744.851 +#define ID_HELP_BUGREPORT               40260
 744.852 +#define ID_HELP_FAQ                     40261
 744.853 +#define ID_OPTIONS_EMULATOR_REWINDINTERVAL 40262
 744.854 +#define ID_FILE_TOGGLEMENU              40263
 744.855 +#define ID_OPTIONS_EMULATOR_SAVETYPE_NONE 40264
 744.856 +#define ID_OPTIONS_EMULATOR_SAVETYPE_ENHANCEDDETECTION 40265
 744.857 +#define ID_TOOLS_IOVIEWER               40266
 744.858 +#define ID_OPTIONS_SOUND_VOLUME_5X      40270
 744.859 +#define ID_OPTIONS_SOUND_VOLUME_25X     40271
 744.860 +#define ID_CHEATS_DISABLECHEATS         40272
 744.861 +#define ID_OPTIONS_VIDEO_FULLSCREENMAXSCALE 40273
 744.862 +#define ID_OPTIONS_FILTER_LQ2X          40275
 744.863 +#define ID_OPTIONS_FILTER_HQ2X          40276
 744.864 +#define ID_OPTIONS_FILTER_HQ2X2         40277
 744.865 +#define ID_OPTIONS_FILTER_HQ3X          40278
 744.866 +#define ID_OPTIONS_FILTER_HQ3X2         40279
 744.867 +#define ID_OPTIONS_FRAMESKIP_ACCURATEPITCH 40289
 744.868 +#define ID_OPTIONS_FRAMESKIP_ACCURATESPEED 40290
 744.869 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_6 40324
 744.870 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_15 40325
 744.871 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_25 40326
 744.872 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_37 40327
 744.873 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_50 40328
 744.874 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_75 40329
 744.875 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_87 40330
 744.876 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_100 40331
 744.877 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_112 40332
 744.878 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_125 40333
 744.879 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_150 40334
 744.880 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_200 40335
 744.881 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_300 40336
 744.882 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_400 40337
 744.883 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_600 40338
 744.884 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_800 40339
 744.885 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_1000 40340
 744.886 +#define ID_TOOLS_FRAMECOUNTER           40341
 744.887 +#define ID_TOOLS_INPUTDISPLAY           40342
 744.888 +#define ID_OPTIONS_VIDEO_FRAMESKIP_0    40350
 744.889 +#define ID_OPTIONS_VIDEO_FRAMESKIP_1    40351
 744.890 +#define ID_OPTIONS_VIDEO_FRAMESKIP_2    40352
 744.891 +#define ID_OPTIONS_VIDEO_FRAMESKIP_3    40353
 744.892 +#define ID_OPTIONS_VIDEO_FRAMESKIP_4    40354
 744.893 +#define ID_OPTIONS_VIDEO_FRAMESKIP_5    40355
 744.894 +#define ID_OPTIONS_VIDEO_FRAMESKIP_6    40356
 744.895 +#define ID_OPTIONS_VIDEO_FRAMESKIP_7    40357
 744.896 +#define ID_OPTIONS_VIDEO_FRAMESKIP_8    40358
 744.897 +#define ID_OPTIONS_VIDEO_FRAMESKIP_9    40359
 744.898 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_INCREASE 40364
 744.899 +#define ID_OPTIONS_FRAMESKIP_THROTTLE_DECREASE 40365
 744.900 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_A    40366
 744.901 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_B    40367
 744.902 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_L    40368
 744.903 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_R    40369
 744.904 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_START 40370
 744.905 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_SELECT 40371
 744.906 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_UP   40372
 744.907 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_DOWN 40373
 744.908 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_LEFT 40374
 744.909 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_RIGHT 40375
 744.910 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_CLEAR 40376
 744.911 +#define ID_OPTIONS_SOUND_MUTEFRAMEADVANCE 40378
 744.912 +#define ID_OPTIONS_JOYPAD_ALLOWLEFTRIGHT 40382
 744.913 +#define ID_MOVIE_READONLY               40385
 744.914 +#define ID_MOVIE_RESTART_PLAY           40387
 744.915 +#define ID_MOVIE_RESUME_RECORD          40388
 744.916 +#define ID_FILE_LOADGAME_AUTOLOADMOSTRECENT 40393
 744.917 +#define ID_EMULATOR_GBALAG              40394
 744.918 +#define ID_EMULATOR_USE_OLD_FRAME_TIMING 40395
 744.919 +#define ID_EMULATOR_USE_GB_INPUT_KLUDGE 40396
 744.920 +#define ID_OPTIONS_VIDEO_TEXTDISPLAYOPTIONS 40397
 744.921 +#define ID_STICKY_A                     40399
 744.922 +#define ID_STICKY_B                     40400
 744.923 +#define ID_STICKY_R                     40402
 744.924 +#define ID_STICKY_START                 40403
 744.925 +#define ID_STICKY_SELECT                40404
 744.926 +#define ID_STICKY_UP                    40405
 744.927 +#define ID_STICKY_DOWN                  40406
 744.928 +#define ID_STICKY_LEFT                  40407
 744.929 +#define ID_STICKY_RIGHT                 40408
 744.930 +#define ID_STICKY_L                     40410
 744.931 +#define ID_STICKY_CLEAR                 40412
 744.932 +#define ID_FILE_SAVEGAME_DECREMENTSLOT  40416
 744.933 +#define ID_FILE_LOADGAME_MOSTRECENT     40420
 744.934 +#define ID_FILE_LOADGAME_CURRENT        40423
 744.935 +#define ID_FILE_LOADGAME_MAKECURRENT    40424
 744.936 +#define ID_FILE_SAVEGAME_CURRENT        40427
 744.937 +#define ID_FILE_SAVEGAME_MAKECURRENT    40428
 744.938 +#define ID_FILE_SAVEGAME_OLDESTSLOT     40429
 744.939 +#define ID_FILE_SAVEGAME_INCREMENTSLOT  40430
 744.940 +#define ID_FILE_LOADGAME_MAKERECENT     40431
 744.941 +#define ID_DEBUG_FRAMESEARCH            40432
 744.942 +#define ID_DEBUG_FRAMESEARCHLOAD        40438
 744.943 +#define ID_DEBUG_FRAMESEARCHPREV        40439
 744.944 +#define ID_SELECT_SLOT1                 40440
 744.945 +#define ID_SELECT_SLOT2                 40441
 744.946 +#define ID_SELECT_SLOT3                 40442
 744.947 +#define ID_SELECT_SLOT4                 40443
 744.948 +#define ID_SELECT_SLOT5                 40444
 744.949 +#define ID_SELECT_SLOT6                 40445
 744.950 +#define ID_SELECT_SLOT7                 40446
 744.951 +#define ID_SELECT_SLOT8                 40447
 744.952 +#define ID_SELECT_SLOT9                 40448
 744.953 +#define ID_SELECT_SLOT10                40449
 744.954 +#define ID_TOOLS_DEBUG                  40450
 744.955 +#define ID_TOOLS_CUSTOMIZE              40452
 744.956 +#define ID_OPTIONS_SPEED                40453
 744.957 +#define ID_SPEED_BLA                    40454
 744.958 +#define ID_SPEED_FRAMESKIP              40455
 744.959 +#define ID_FRAMESKIP_BLA                40456
 744.960 +#define ID_SPEED_SETSPEED               40457
 744.961 +#define ID_SETSPEED_BLA                 40458
 744.962 +#define ID_SOUND_SOUNDCHANNELS          40459
 744.963 +#define ID_CHEATS_PAUSEDURINGCHEATSEARCH 40463
 744.964 +#define ID_TOOLS_LAGCOUNTER             40464
 744.965 +#define ID_FILE_LUA_OPEN                40467
 744.966 +#define ID_FILE_LUA_RELOAD              40468
 744.967 +#define ID_FILE_LUA_CLOSE_ALL           40469
 744.968 +#define ID_TOOLS_LAGCOUNTER_RESET       40470
 744.969 +#define ID_FILE_QUICKSCREENCAPTURE      40471
 744.970 +#define ID_MOVIE_END_EXIT               40480
 744.971 +#define ID_MOVIE_END_RESET              40481
 744.972 +#define ID_MOVIE_END_CLOSE              40482
 744.973 +#define ID_MOVIE_END_OPENGBA            40483
 744.974 +#define ID_MOVIE_END_OPENGBX            40484
 744.975 +#define ID_MOVIE_END_LOADGAME           40485
 744.976 +#define ID_MOVIE_END_SAVEGAME           40486
 744.977 +#define ID_MOVIE_END_PAUSE              40487
 744.978 +#define ID_MOVIE_END_RESTART            40488
 744.979 +#define ID_MOVIE_END_APPEND             40489
 744.980 +#define ID_MOVIE_END_STOP               40490
 744.981 +#define ID_MOVIE_END_KEEP               40491
 744.982 +#define ID_MOVIE_END_PLAY               40492
 744.983 +#define ID_MOVIE_END_NEW                40493
 744.984 +#define ID_MOVIE_TOOL_CONVERT           40501
 744.985 +#define ID_MOVIE_TOOL_TRUNCATE          40504
 744.986 +#define ID_MOVIE_TOOL_FIX_HEADER        40507
 744.987 +#define ID_MOVIE_TOOL_SET_PAUSE_AT      40510
 744.988 +#define ID_RAM_SEARCH                   40522
 744.989 +#define ID_RAM_WATCH                    40523
 744.990 +#define ID_MOVIE_TOOL_AUTO_CONVERT      40541
 744.991 +#define ID_MOVIE_TOOL_EXTRACT_FROM_SAVEGAME 40560
 744.992 +#define ID_MOVIE_TOOL_CONVERT_FILE          40561
 744.993 +#define RAMMENU_FILE_RECENT             40653
 744.994 +#define ID_WATCHES_MOVEUP               40664
 744.995 +#define ID_WATCHES_MOVEDOWN             40665
 744.996 +#define ID_WATCHES_EDITWATCH            40666
 744.997 +#define ID_WATCHES_REMOVEWATCH          40667
 744.998 +#define ID_WATCHES_NEWWATCH             40668
 744.999 +#define ID_WATCHES_DUPLICATEWATCH       40669
744.1000 +#define ID_WATCHES_UPDOWN               40670
744.1001 +#define ID_FILE_LUA_STOP                40671
744.1002 +#define IDC_EDIT_COMPAREVALUE           41090
744.1003 +#define IDC_EDIT_COMPAREADDRESS         41091
744.1004 +#define IDC_EDIT_COMPARECHANGES         41092
744.1005 +#define IDC_EDIT_DIFFBY                 41093
744.1006 +#define IDC_C_AUTOSEARCH                41094
744.1007 +#define IDC_EDIT_MODBY                  41095
744.1008 +#define IDC_RAMLIST                     41133
744.1009 +#define IDC_C_SEARCH                    41134
744.1010 +#define IDC_C_ADDCHEAT                  41135
744.1011 +#define IDC_C_RESET                     41136
744.1012 +#define IDC_1_BYTE                      41137
744.1013 +#define IDC_2_BYTES                     41138
744.1014 +#define IDC_C_WATCH                     41139
744.1015 +#define IDC_4_BYTES                     41140
744.1016 +#define IDC_LESSTHAN                    41141
744.1017 +#define IDC_MORETHAN                    41142
744.1018 +#define IDC_NOMORETHAN                  41143
744.1019 +#define IDC_NOLESSTHAN                  41144
744.1020 +#define IDC_EQUALTO                     41145
744.1021 +#define IDC_DIFFERENTFROM               41146
744.1022 +#define IDC_DIFFERENTBY                 41147
744.1023 +#define IDC_MODULO                      41148
744.1024 +#define IDC_HEX                         41151
744.1025 +#define IDC_C_UNDO                      41152
744.1026 +#define IDC_C_RESET_CHANGES             41153
744.1027 +#define IDC_PREVIOUSVALUE               42147
744.1028 +#define IDC_SPECIFICVALUE               42148
744.1029 +#define IDC_CHEATEDITVALUE              42156
744.1030 +#define IDC_SPECIFICADDRESS             42157
744.1031 +#define IDC_NUMBEROFCHANGES             42158
744.1032 +#define IDC_MISALIGN                    42159
744.1033 +#define IDC_WATCHLIST                   42171
744.1034 +#define IDC_C_ELIMINATE                 42174
744.1035 +#define RAMMENU_FILE_AUTOLOAD           42300
744.1036 +#define RAMMENU_FILE_APPEND             42301
744.1037 +#define RAMMENU_FILE_SAVEWINDOW         42302
744.1038 +#define RAMMENU_FILE_NEW                42303
744.1039 +#define RAMMENU_FILE_OPEN               42304
744.1040 +#define RAMMENU_FILE_SAVE               42305
744.1041 +#define RAMMENU_FILE_SAVEAS             42306
744.1042 +#define RW_MENU_FIRST_RECENT_FILE       42350
744.1043 +#define RW_MENU_LAST_RECENT_FILE        42370
744.1044 +#define ID_OPTIONS_PREFER_ARCHIVE_NAME  42400
744.1045 +#define ID_OPTIONS_PREFER_ROM_NAME      42401
744.1046 +#define ID_OPTIONS_EMULATOR_ALWAYSONTOP 42402
744.1047 +#define ID_OPTIONS_EMULATOR_BACKGROUNDINPUT 42403
744.1048 +#define ID_OPTIONS_SOUND_MUTEWHENINACTIVE 42404
744.1049 +#define ID_FILE_SLOT_DISPLAYMODIFICATIONTIME 42405
744.1050 +#define ID_TOOLS_PAUSEAVIRECORDING      42406
744.1051 +#define ID_AUTO_TAKELAGINTOACCOUNT      42407
744.1052 +#define ID_OPTIONS_JOYPAD_AUTOFIRE_ACCOUNTFORLAG 42408
744.1053 +#define ID_FILE_FRAMEADVANCESETTINGS    42409
744.1054 +#define ID_DEBUG_NEXTFRAME_ACCOUNTFORLAG 42410
744.1055 +#define ID_MOVIE_ASSOCIATEMOVIESWITHSAVESTATES 42411
744.1056 +#define ID_MOVIE_ASSC_WITH_SAVESTATE    42412
744.1057 +#define ID_TOOLS_EXTRACOUNTER           42413
744.1058 +#define ID_HEAD_EXTRACOUNTERRESET       42414
744.1059 +#define ID_TOOLS_EXTRACOUNTERRESET      42415
744.1060 +#define IDC_C_WATCH_DOWN                43400
744.1061 +#define IDC_C_WATCH_DUPLICATE           43401
744.1062 +#define IDC_C_WATCH_EDIT                43402
744.1063 +#define IDC_C_WATCH_REMOVE              43403
744.1064 +#define IDC_C_WATCH_UP                  43404
744.1065 +#define IDC_PROMPT_TEXT                 44000
744.1066 +#define IDC_PROMPT_TEXT2                44001
744.1067 +#define IDC_PROMPT_EDIT                 44005
744.1068 +#define IDC_C_WATCH_SEPARATE            55555
744.1069 +
744.1070 +// Next default values for new objects
744.1071 +// 
744.1072 +#ifdef APSTUDIO_INVOKED
744.1073 +#ifndef APSTUDIO_READONLY_SYMBOLS
744.1074 +#define _APS_NEXT_RESOURCE_VALUE        171
744.1075 +#define _APS_NEXT_COMMAND_VALUE         42416
744.1076 +#define _APS_NEXT_CONTROL_VALUE         1376
744.1077 +#define _APS_NEXT_SYMED_VALUE           103
744.1078 +#endif
744.1079 +#endif
   745.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   745.2 +++ b/src/win32/stdafx.cpp	Sat Mar 03 10:31:27 2012 -0600
   745.3 @@ -0,0 +1,8 @@
   745.4 +// stdafx.cpp : source file that includes just the standard includes
   745.5 +//      DialogSizer.pch will be the pre-compiled header
   745.6 +//      stdafx.obj will contain the pre-compiled type information
   745.7 +
   745.8 +#include "stdafx.h"
   745.9 +
  745.10 +// TODO: reference any additional headers you need in STDAFX.H
  745.11 +// and not in this file
   746.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   746.2 +++ b/src/win32/stdafx.h	Sat Mar 03 10:31:27 2012 -0600
   746.3 @@ -0,0 +1,47 @@
   746.4 +// stdafx.h : include file for standard system include files,
   746.5 +//  or project specific include files that are used frequently, but
   746.6 +//      are changed infrequently
   746.7 +//
   746.8 +
   746.9 +// some build target defines:
  746.10 +
  746.11 +#ifndef _WIN32_WINDOWS
  746.12 +///#	define _WIN32_WINDOWS 0x0410 // Windows 98 +
  746.13 +#   define _WIN32_WINDOWS 0x0500 // Windows NT +
  746.14 +///#	define _WIN32_WINDOWS 0x0501 // Windows XP +
  746.15 +#endif
  746.16 +
  746.17 +#ifndef _WIN32_WINNT
  746.18 +///#	define _WIN32_WINNT 0x0410 // Windows 98 +
  746.19 +#   define _WIN32_WINNT 0x0500 // Windows NT +
  746.20 +///#	define _WIN32_WINNT 0x0501 // Windows XP +
  746.21 +#endif
  746.22 +
  746.23 +#ifndef WINVER
  746.24 +///#	define WINVER 0x0410 // Windows 98 +
  746.25 +#   define WINVER 0x0500 // Windows NT +
  746.26 +///#	define WINVER 0x0501 // Windows XP +
  746.27 +#endif
  746.28 +
  746.29 +#if !defined(AFX_STDAFX_H__A7126ECB_A234_4116_A7D0_BE50547E87F8__INCLUDED_)
  746.30 +#define AFX_STDAFX_H__A7126ECB_A234_4116_A7D0_BE50547E87F8__INCLUDED_
  746.31 +
  746.32 +#if _MSC_VER > 1000
  746.33 +#pragma once
  746.34 +#endif // _MSC_VER > 1000
  746.35 +
  746.36 +// Insert your headers here
  746.37 +//#define WIN32_LEAN_AND_MEAN           // Exclude rarely-used stuff from Windows headers
  746.38 +
  746.39 +#include <afxwin.h>
  746.40 +#include <afxcmn.h>
  746.41 +#include <afxdlgs.h>
  746.42 +
  746.43 +#include "../Port.h"
  746.44 +
  746.45 +// TODO: reference additional headers your program requires here
  746.46 +
  746.47 +//{{AFX_INSERT_LOCATION}}
  746.48 +// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  746.49 +
  746.50 +#endif // !defined(AFX_STDAFX_H__A7126ECB_A234_4116_A7D0_BE50547E87F8__INCLUDED_)
   747.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   747.2 +++ b/src/win32/vba.rc	Sat Mar 03 10:31:27 2012 -0600
   747.3 @@ -0,0 +1,2664 @@
   747.4 +// Microsoft Visual C++ generated resource script.
   747.5 +//
   747.6 +#include "resource.h"
   747.7 +
   747.8 +#define APSTUDIO_READONLY_SYMBOLS
   747.9 +/////////////////////////////////////////////////////////////////////////////
  747.10 +//
  747.11 +// Generated from the TEXTINCLUDE 2 resource.
  747.12 +//
  747.13 +#include "afxres.h"
  747.14 +#include "vba.rc2"
  747.15 +/////////////////////////////////////////////////////////////////////////////
  747.16 +#undef APSTUDIO_READONLY_SYMBOLS
  747.17 +
  747.18 +/////////////////////////////////////////////////////////////////////////////
  747.19 +// English (United States) resources
  747.20 +
  747.21 +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
  747.22 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
  747.23 +#pragma code_page(1252)
  747.24 +
  747.25 +/////////////////////////////////////////////////////////////////////////////
  747.26 +//
  747.27 +// Version
  747.28 +//
  747.29 +
  747.30 +#include "VersionInfo.h"
  747.31 +VS_VERSION_INFO VERSIONINFO
  747.32 + FILEVERSION    VBA_VERSIONINFO_FILEVER
  747.33 + PRODUCTVERSION VBA_VERSIONINFO_PRODUCTVER
  747.34 + FILEFLAGSMASK  0x3fL
  747.35 + FILEFLAGS      VBA_VERSIONINFO_FILEFLAGS
  747.36 + FILEOS         0x40004L
  747.37 + FILETYPE       0x1L
  747.38 + FILESUBTYPE    0x0L
  747.39 +BEGIN
  747.40 +    BLOCK "StringFileInfo"
  747.41 +    BEGIN
  747.42 +        BLOCK "040904b0"
  747.43 +        BEGIN
  747.44 +            VALUE "Comments", "VBA-RR comes with NO WARRANTY. Use it at your own risk."
  747.45 +            VALUE "CompanyName", VBA_VERSIONINFO_ORGANIZATION
  747.46 +            VALUE "FileDescription", "VisualBoyAdvance-ReRecording Emulator"
  747.47 +            VALUE "FileVersion", VBA_VERSIONINFO_STRFILEVER
  747.48 +            VALUE "InternalName", "VBA-RR"
  747.49 +            VALUE "LegalCopyright", VBA_VERSIONINFO_STRCOPYRIGHT
  747.50 +            VALUE "OriginalFilename", "VisualBoyAdvance.exe"
  747.51 +            VALUE "ProductName", "GB/C/A emulator for Windows"
  747.52 +            VALUE "ProductVersion", VBA_VERSIONINFO_STRPRODUCTVER
  747.53 +            VALUE "PrivateBuild", "0"
  747.54 +            VALUE "SpecialBuild", "0"
  747.55 +        END
  747.56 +    END
  747.57 +    BLOCK "VarFileInfo"
  747.58 +    BEGIN
  747.59 +        VALUE "Translation", 0x409, 1200
  747.60 +    END
  747.61 +END
  747.62 +
  747.63 +
  747.64 +#ifdef APSTUDIO_INVOKED
  747.65 +/////////////////////////////////////////////////////////////////////////////
  747.66 +//
  747.67 +// TEXTINCLUDE
  747.68 +//
  747.69 +
  747.70 +1 TEXTINCLUDE 
  747.71 +BEGIN
  747.72 +    "resource.h\0"
  747.73 +END
  747.74 +
  747.75 +2 TEXTINCLUDE 
  747.76 +BEGIN
  747.77 +    "#include ""afxres.h""\r\n"
  747.78 +    "#include ""vba.rc2""\0"
  747.79 +END
  747.80 +
  747.81 +3 TEXTINCLUDE 
  747.82 +BEGIN
  747.83 +    "\r\n"
  747.84 +    "\0"
  747.85 +END
  747.86 +
  747.87 +#endif    // APSTUDIO_INVOKED
  747.88 +
  747.89 +
  747.90 +/////////////////////////////////////////////////////////////////////////////
  747.91 +//
  747.92 +// Icon
  747.93 +//
  747.94 +
  747.95 +// Icon with lowest ID value placed first to ensure application icon
  747.96 +// remains consistent on all systems.
  747.97 +IDI_ICON                ICON                    "gbadvance.ico"
  747.98 +
  747.99 +/////////////////////////////////////////////////////////////////////////////
 747.100 +//
 747.101 +// Dialog
 747.102 +//
 747.103 +
 747.104 +IDD_OPENDLG DIALOG 36, 24, 202, 117
 747.105 +STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_CONTEXTHELP | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.106 +CAPTION "Open"
 747.107 +FONT 8, "MS Shell Dlg"
 747.108 +BEGIN
 747.109 +    LTEXT           "File &name:",1090,2,1,81,8
 747.110 +    EDITTEXT        1152,0,10,104,12,ES_AUTOHSCROLL | ES_OEMCONVERT
 747.111 +    LISTBOX         1120,1,24,104,53,LBS_SORT | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_VSCROLL | WS_TABSTOP
 747.112 +    LTEXT           "&Folders:",-1,112,0,53,9
 747.113 +    LTEXT           "",1088,113,10,86,9,SS_NOPREFIX
 747.114 +    LISTBOX         1121,112,24,88,52,LBS_SORT | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_VSCROLL | WS_TABSTOP
 747.115 +    LTEXT           "List files of &type:",1089,1,75,81,9
 747.116 +    COMBOBOX        1136,1,87,104,13,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP
 747.117 +    LTEXT           "Dri&ves:",1091,113,76,70,9
 747.118 +    COMBOBOX        1137,112,87,71,68,CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP
 747.119 +    DEFPUSHBUTTON   "OK",IDOK,24,102,50,14,WS_GROUP
 747.120 +    PUSHBUTTON      "Cancel",IDCANCEL,90,102,50,14,WS_GROUP
 747.121 +END
 747.122 +
 747.123 +IDD_ABOUT DIALOGEX 0, 0, 164, 101
 747.124 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.125 +CAPTION "About VBA rerecording"
 747.126 +FONT 8, "MS Sans Serif", 0, 0, 0x0
 747.127 +BEGIN
 747.128 +    DEFPUSHBUTTON   "OK",IDOK,56,80,50,14
 747.129 +    ICON            IDI_ICON,IDC_STATIC,5,12,20,20
 747.130 +    CTEXT           "VisualBoyAdvance Emulator",IDC_STATIC,14,7,134,8
 747.131 +    CTEXT           "Copyright (c) 2004 Forgotten and the VBA team",IDC_STATIC,7,35,150,8
 747.132 +    CTEXT           "http://code.google.com/p/vba-rerecording/",IDC_URL,7,55,150,8
 747.133 +    CTEXT           "Contribution by Costis",IDC_STATIC,30,45,102,8
 747.134 +    CTEXT           "Version",IDC_STATIC,46,16,70,8
 747.135 +    CTEXT           "",IDC_VERSION,36,25,98,8
 747.136 +    CTEXT           "Re-recording additions by VBA-rr team",IDC_STATIC,14,66,136,8
 747.137 +END
 747.138 +
 747.139 +IDD_DIRECTORIES DIALOGEX 0, 0, 284, 260
 747.140 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.141 +CAPTION "Directories"
 747.142 +FONT 8, "MS Sans Serif", 0, 0, 0x0
 747.143 +BEGIN
 747.144 +    LTEXT           "GBA ROM:",IDC_STATIC,7,9,40,8
 747.145 +    EDITTEXT        IDC_ROM_PATH,49,7,160,14,ES_AUTOHSCROLL
 747.146 +    PUSHBUTTON      "...",IDC_ROM_DIR,213,7,24,14
 747.147 +    PUSHBUTTON      "Reset",IDC_ROM_DIR_RESET,242,7,35,14
 747.148 +    LTEXT           "GBx ROM:",IDC_STATIC,7,28,40,8
 747.149 +    EDITTEXT        IDC_GBXROM_PATH,49,26,160,14,ES_AUTOHSCROLL
 747.150 +    PUSHBUTTON      "...",IDC_GBXROM_DIR,213,26,24,14
 747.151 +    PUSHBUTTON      "Reset",IDC_GBXROM_DIR_RESET,242,26,35,14
 747.152 +    LTEXT           "Battery:",IDC_STATIC,7,47,40,8
 747.153 +    EDITTEXT        IDC_BATTERY_PATH,49,45,160,14,ES_AUTOHSCROLL
 747.154 +    PUSHBUTTON      "...",IDC_BATTERY_DIR,213,45,24,14
 747.155 +    PUSHBUTTON      "Reset",IDC_BATTERY_DIR_RESET,242,45,35,14
 747.156 +    LTEXT           "Save Game:",IDC_STATIC,7,66,40,8
 747.157 +    EDITTEXT        IDC_SAVE_PATH,49,64,160,14,ES_AUTOHSCROLL
 747.158 +    PUSHBUTTON      "...",IDC_SAVE_DIR,213,64,24,14
 747.159 +    PUSHBUTTON      "Reset",IDC_SAVE_DIR_RESET,242,64,35,14
 747.160 +    LTEXT           "Movies:",IDC_STATIC,7,85,40,8
 747.161 +    EDITTEXT        IDC_MOVIE_PATH,49,83,160,14,ES_AUTOHSCROLL
 747.162 +    PUSHBUTTON      "...",IDC_MOVIE_DIR,213,83,24,14
 747.163 +    PUSHBUTTON      "Reset",IDC_MOVIE_DIR_RESET,242,83,35,14
 747.164 +    LTEXT           "Cheats:",IDC_STATIC,7,104,40,8
 747.165 +    EDITTEXT        IDC_CHEAT_PATH,49,102,160,14,ES_AUTOHSCROLL
 747.166 +    PUSHBUTTON      "...",IDC_CHEAT_DIR,213,102,24,14
 747.167 +    PUSHBUTTON      "Reset",IDC_CHEAT_DIR_RESET,242,102,35,14
 747.168 +    LTEXT           "IPS:",IDC_STATIC,7,123,40,8
 747.169 +    EDITTEXT        IDC_IPS_PATH,49,121,160,14,ES_AUTOHSCROLL
 747.170 +    PUSHBUTTON      "...",IDC_IPS_DIR,213,121,24,14
 747.171 +    PUSHBUTTON      "Reset",IDC_IPS_DIR_RESET,242,121,35,14
 747.172 +    LTEXT           "Lua:",IDC_STATIC,7,142,40,8
 747.173 +    EDITTEXT        IDC_LUA_PATH,49,140,160,14,ES_AUTOHSCROLL
 747.174 +    PUSHBUTTON      "...",IDC_LUA_DIR,213,140,24,14
 747.175 +    PUSHBUTTON      "Reset",IDC_LUA_DIR_RESET,242,140,35,14
 747.176 +    LTEXT           "AVI:",IDC_STATIC,7,161,40,8
 747.177 +    EDITTEXT        IDC_AVI_PATH,49,159,160,14,ES_AUTOHSCROLL
 747.178 +    PUSHBUTTON      "...",IDC_AVI_DIR,213,159,24,14
 747.179 +    PUSHBUTTON      "Reset",IDC_AVI_DIR_RESET,242,159,35,14
 747.180 +    LTEXT           "WAV:",IDC_STATIC,7,180,40,8
 747.181 +    EDITTEXT        IDC_WAV_PATH,49,178,160,14,ES_AUTOHSCROLL
 747.182 +    PUSHBUTTON      "...",IDC_WAV_DIR,213,178,24,14
 747.183 +    PUSHBUTTON      "Reset",IDC_WAV_DIR_RESET,242,178,35,14
 747.184 +    LTEXT           "Capture:",IDC_STATIC,7,199,40,8
 747.185 +    EDITTEXT        IDC_CAPTURE_PATH,49,197,160,14,ES_AUTOHSCROLL
 747.186 +    PUSHBUTTON      "...",IDC_CAPTURE_DIR,213,197,23,14
 747.187 +    PUSHBUTTON      "Reset",IDC_CAPTURE_DIR_RESET,242,197,35,14
 747.188 +    LTEXT           "Watch:",IDC_STATIC,7,218,40,8
 747.189 +    EDITTEXT        IDC_WATCH_PATH,49,216,160,14,ES_AUTOHSCROLL
 747.190 +    PUSHBUTTON      "...",IDC_WATCH_DIR,213,216,23,14
 747.191 +    PUSHBUTTON      "Reset",IDC_WATCH_DIR_RESET,242,216,35,14
 747.192 +    DEFPUSHBUTTON   "OK",IDOK,88,236,50,16
 747.193 +    PUSHBUTTON      "Cancel",IDCANCEL,145,236,50,16
 747.194 +END
 747.195 +
 747.196 +IDD_CONFIG DIALOGEX 0, 0, 135, 211
 747.197 +STYLE DS_SYSMODAL | DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.198 +CAPTION "Joypad setup"
 747.199 +FONT 8, "MS Sans Serif", 0, 0, 0x0
 747.200 +BEGIN
 747.201 +    EDITTEXT        IDC_EDIT_UP,47,5,81,12,ES_AUTOHSCROLL
 747.202 +    EDITTEXT        IDC_EDIT_DOWN,47,19,81,12,ES_AUTOHSCROLL
 747.203 +    EDITTEXT        IDC_EDIT_LEFT,47,33,81,12,ES_AUTOHSCROLL
 747.204 +    EDITTEXT        IDC_EDIT_RIGHT,47,47,81,12,ES_AUTOHSCROLL
 747.205 +    EDITTEXT        IDC_EDIT_BUTTON_A,47,61,81,12,ES_AUTOHSCROLL
 747.206 +    EDITTEXT        IDC_EDIT_BUTTON_B,47,75,81,12,ES_AUTOHSCROLL
 747.207 +    EDITTEXT        IDC_EDIT_BUTTON_L,47,89,81,12,ES_AUTOHSCROLL
 747.208 +    EDITTEXT        IDC_EDIT_BUTTON_R,47,103,81,12,ES_AUTOHSCROLL
 747.209 +    EDITTEXT        IDC_EDIT_BUTTON_SELECT,47,117,81,12,ES_AUTOHSCROLL
 747.210 +    EDITTEXT        IDC_EDIT_BUTTON_START,47,131,81,12,ES_AUTOHSCROLL
 747.211 +    EDITTEXT        IDC_EDIT_SPEED,47,145,81,12,ES_AUTOHSCROLL
 747.212 +    EDITTEXT        IDC_EDIT_CAPTURE,47,159,81,12,ES_AUTOHSCROLL
 747.213 +    EDITTEXT        IDC_EDIT_BUTTON_GS,47,173,81,12,ES_AUTOHSCROLL
 747.214 +    PUSHBUTTON      "OK",ID_OK,20,190,40,14
 747.215 +    PUSHBUTTON      "Cancel",ID_CANCEL,74,190,40,14
 747.216 +    LTEXT           "Up:",IDC_STATIC,5,5,35,10
 747.217 +    LTEXT           "Down:",IDC_STATIC,5,19,35,10
 747.218 +    LTEXT           "Left:",IDC_STATIC,5,33,35,10
 747.219 +    LTEXT           "Right:",IDC_STATIC,5,47,35,10
 747.220 +    LTEXT           "Button A:",IDC_STATIC,5,61,40,10
 747.221 +    LTEXT           "Button B:",IDC_STATIC,5,75,40,10
 747.222 +    LTEXT           "Button L:",IDC_STATIC,5,89,40,10
 747.223 +    LTEXT           "Button R:",IDC_STATIC,5,103,40,10
 747.224 +    LTEXT           "Select:",IDC_STATIC,5,117,40,10
 747.225 +    LTEXT           "Start:",IDC_STATIC,5,131,40,10
 747.226 +    LTEXT           "Speed:",IDC_STATIC,5,145,40,10
 747.227 +    LTEXT           "Capture:",IDC_STATIC,5,159,40,10
 747.228 +    LTEXT           "GameShark:",IDC_STATIC,5,173,40,10
 747.229 +END
 747.230 +
 747.231 +IDD_CHEATS DIALOGEX 0, 0, 276, 253
 747.232 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 747.233 +CAPTION "Search for cheats"
 747.234 +FONT 8, "MS Sans Serif", 0, 0, 0x0
 747.235 +BEGIN
 747.236 +    CONTROL         "",IDC_CHEAT_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | WS_BORDER | WS_TABSTOP,3,5,265,111
 747.237 +    CONTROL         "Ol&d value",IDC_OLD_VALUE,"Button",BS_AUTORADIOBUTTON | WS_GROUP,11,129,46,10
 747.238 +    CONTROL         "Specifi&c value",IDC_SPECIFIC_VALUE,"Button",BS_AUTORADIOBUTTON,11,141,61,10
 747.239 +    CONTROL         "&8 bits",IDC_SIZE_8,"Button",BS_AUTORADIOBUTTON | WS_GROUP,11,167,33,10
 747.240 +    CONTROL         "&16 bits",IDC_SIZE_16,"Button",BS_AUTORADIOBUTTON,11,179,37,10
 747.241 +    CONTROL         "&32 bits",IDC_SIZE_32,"Button",BS_AUTORADIOBUTTON,11,191,37,10
 747.242 +    CONTROL         "&Equal",IDC_EQ,"Button",BS_AUTORADIOBUTTON | WS_GROUP,100,128,34,10
 747.243 +    CONTROL         "&Not equal",IDC_NE,"Button",BS_AUTORADIOBUTTON,100,140,47,10
 747.244 +    CONTROL         "&Less than",IDC_LT,"Button",BS_AUTORADIOBUTTON,100,152,47,10
 747.245 +    CONTROL         "Le&ss or equal",IDC_LE,"Button",BS_AUTORADIOBUTTON,100,164,58,10
 747.246 +    CONTROL         "&Greater than",IDC_GT,"Button",BS_AUTORADIOBUTTON,100,176,59,10
 747.247 +    CONTROL         "G&reater or equal",IDC_GE,"Button",BS_AUTORADIOBUTTON,100,188,67,10
 747.248 +    CONTROL         "S&igned",IDC_SIGNED,"Button",BS_AUTORADIOBUTTON | WS_GROUP,202,130,38,10
 747.249 +    CONTROL         "&Unsigned",IDC_UNSIGNED,"Button",BS_AUTORADIOBUTTON,202,142,46,10
 747.250 +    CONTROL         "&Hexadecimal",IDC_HEXADECIMAL,"Button",BS_AUTORADIOBUTTON,202,154,57,10
 747.251 +    CONTROL         "search u&pdates vals",IDC_UPDATE,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,192,192,76,10
 747.252 +    EDITTEXT        IDC_VALUE,95,211,172,14,ES_AUTOHSCROLL
 747.253 +    PUSHBUTTON      "&Start",IDC_START,15,237,50,14,WS_GROUP
 747.254 +    PUSHBUTTON      "S&earch",IDC_SEARCH,80,236,50,14
 747.255 +    PUSHBUTTON      "&Add cheat",IDC_ADD_CHEAT,145,236,50,14
 747.256 +    DEFPUSHBUTTON   "OK",ID_OK,210,236,50,14
 747.257 +    GROUPBOX        "&Search type",IDC_STATIC,3,118,84,36
 747.258 +    GROUPBOX        "&Data size",IDC_STATIC,3,158,84,44
 747.259 +    GROUPBOX        "Compare type",IDC_STATIC,95,118,92,84
 747.260 +    GROUPBOX        "Signed/Unsigned",IDC_STATIC,192,118,76,50
 747.261 +    LTEXT           "Enter &value:",IDC_STATIC,3,214,69,8
 747.262 +    PUSHBUTTON      "Refresh New &Values",IDC_CHEATREFRESHBUTTON,192,172,75,14,NOT WS_VISIBLE
 747.263 +END
 747.264 +
 747.265 +IDD_ADD_CHEAT DIALOG 0, 0, 186, 137
 747.266 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.267 +CAPTION "Add cheat"
 747.268 +FONT 8, "MS Sans Serif"
 747.269 +BEGIN
 747.270 +    EDITTEXT        IDC_ADDRESS,60,6,123,14,ES_AUTOHSCROLL
 747.271 +    EDITTEXT        IDC_VALUE,60,24,123,14,ES_AUTOHSCROLL
 747.272 +    EDITTEXT        IDC_DESC,60,42,123,14,ES_AUTOHSCROLL
 747.273 +    CONTROL         "8-bit",IDC_SIZE_8,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,11,70,29,10
 747.274 +    CONTROL         "16-bit",IDC_SIZE_16,"Button",BS_AUTORADIOBUTTON,62,70,33,10
 747.275 +    CONTROL         "32-bit",IDC_SIZE_32,"Button",BS_AUTORADIOBUTTON,117,70,33,10
 747.276 +    CONTROL         "&Signed",IDC_SIGNED,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,11,97,38,10
 747.277 +    CONTROL         "&Unsigned",IDC_UNSIGNED,"Button",BS_AUTORADIOBUTTON,62,98,46,10
 747.278 +    CONTROL         "&Hexadecimal",IDC_HEXADECIMAL,"Button",BS_AUTORADIOBUTTON,117,98,57,10
 747.279 +    DEFPUSHBUTTON   "&OK",ID_OK,36,116,50,14,WS_GROUP
 747.280 +    PUSHBUTTON      "&Cancel",ID_CANCEL,99,116,50,14
 747.281 +    LTEXT           "&Value:",IDC_STATIC,3,27,54,8
 747.282 +    GROUPBOX        "Number format",IDC_STATIC,3,88,180,24
 747.283 +    LTEXT           "&Address:",IDC_STATIC,3,9,54,8
 747.284 +    GROUPBOX        "Size",IDC_STATIC,3,60,180,24
 747.285 +    LTEXT           "&Description:",IDC_STATIC,3,45,55,8
 747.286 +END
 747.287 +
 747.288 +IDD_CHEAT_LIST DIALOG 0, 0, 280, 250
 747.289 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.290 +CAPTION "Cheat list"
 747.291 +FONT 8, "MS Sans Serif"
 747.292 +BEGIN
 747.293 +    CONTROL         "Restore &previous values",IDC_RESTORE,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,5,183,92,10
 747.294 +    PUSHBUTTON      "&Code...",IDC_ADD_CODE,9,208,64,14,WS_GROUP
 747.295 +    PUSHBUTTON      "C&heat...",IDC_ADD_CHEAT,75,208,64,14
 747.296 +    PUSHBUTTON      "&Gameshark...",IDC_ADD_GAMESHARK,141,208,64,14
 747.297 +    PUSHBUTTON      "CodeBreaker...",IDC_ADD_CODEBREAKER,206,208,64,14
 747.298 +    PUSHBUTTON      "&Remove",IDC_REMOVE,9,230,64,14
 747.299 +    PUSHBUTTON      "Remove A&ll",IDC_REMOVE_ALL,75,230,64,14
 747.300 +    PUSHBUTTON      "&Enable/Dis.",IDC_ENABLE,141,230,64,14
 747.301 +    DEFPUSHBUTTON   "&OK",ID_OK,206,230,64,14,WS_GROUP
 747.302 +    CONTROL         "",IDC_CHEAT_LIST,"SysListView32",LVS_REPORT | WS_BORDER | WS_GROUP | WS_TABSTOP,5,15,269,156
 747.303 +    LTEXT           "Status legend:",IDC_STATIC,6,3,46,8
 747.304 +    LTEXT           "E: Enabled",IDC_STATIC,188,3,36,8
 747.305 +    LTEXT           "D: Disabled",IDC_STATIC,234,3,38,8
 747.306 +    GROUPBOX        "Add",IDC_STATIC,5,199,268,27
 747.307 +END
 747.308 +
 747.309 +IDD_ASSOCIATIONS DIALOG 0, 0, 116, 95
 747.310 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.311 +CAPTION "Associations"
 747.312 +FONT 8, "MS Sans Serif"
 747.313 +BEGIN
 747.314 +    CONTROL         ".gb",IDC_GB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,15,26,10
 747.315 +    CONTROL         ".sgb",IDC_SGB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,29,29,10
 747.316 +    CONTROL         ".cgb",IDC_CGB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,43,30,10
 747.317 +    CONTROL         ".gbc",IDC_GBC,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,57,30,10
 747.318 +    CONTROL         ".gba",IDC_GBA,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,75,13,30,10
 747.319 +    CONTROL         ".agb",IDC_AGB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,75,27,30,10
 747.320 +    CONTROL         ".bin",IDC_BIN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,75,41,27,10
 747.321 +    DEFPUSHBUTTON   "OK",ID_OK,3,78,50,14
 747.322 +    PUSHBUTTON      "Cancel",ID_CANCEL,63,78,50,14
 747.323 +    GROUPBOX        "GBA Types",IDC_STATIC,63,3,50,51
 747.324 +    GROUPBOX        "GB Types",IDC_STATIC,3,3,50,69
 747.325 +END
 747.326 +
 747.327 +IDD_GBA_ROM_INFO DIALOG 0, 0, 220, 142
 747.328 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.329 +CAPTION "Rom information"
 747.330 +FONT 8, "MS Sans Serif"
 747.331 +BEGIN
 747.332 +    DEFPUSHBUTTON   "OK",ID_OK,84,121,50,14
 747.333 +    LTEXT           "Game title:",IDC_STATIC,7,10,60,8
 747.334 +    LTEXT           "Game code:",IDC_STATIC,7,24,60,8
 747.335 +    LTEXT           "Maker code:",IDC_STATIC,7,38,60,8
 747.336 +    LTEXT           "Main unit code:",IDC_STATIC,7,66,60,8
 747.337 +    LTEXT           "Device type:",IDC_STATIC,7,80,60,8
 747.338 +    LTEXT           "ROM version:",IDC_STATIC,7,94,60,8
 747.339 +    LTEXT           "CRC:",IDC_STATIC,7,108,60,8
 747.340 +    LTEXT           "",IDC_ROM_TITLE,80,10,133,8
 747.341 +    LTEXT           "",IDC_ROM_GAME_CODE,80,24,133,8
 747.342 +    LTEXT           "",IDC_ROM_MAKER_CODE,80,38,133,8
 747.343 +    LTEXT           "",IDC_ROM_UNIT_CODE,80,66,133,8
 747.344 +    LTEXT           "",IDC_ROM_DEVICE_TYPE,80,80,133,8
 747.345 +    LTEXT           "",IDC_ROM_VERSION,80,94,133,8
 747.346 +    LTEXT           "",IDC_ROM_CRC,80,108,133,8
 747.347 +    LTEXT           "",IDC_ROM_MAKER_NAME,80,52,133,8
 747.348 +    LTEXT           "Maker name:",IDC_STATIC,7,52,60,8
 747.349 +END
 747.350 +
 747.351 +IDD_GB_ROM_INFO DIALOG 0, 0, 220, 225
 747.352 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.353 +CAPTION "Rom information"
 747.354 +FONT 8, "MS Sans Serif"
 747.355 +BEGIN
 747.356 +    DEFPUSHBUTTON   "OK",ID_OK,84,200,50,14
 747.357 +    LTEXT           "Game title:",IDC_STATIC,7,10,60,8
 747.358 +    LTEXT           "Maker code:",IDC_STATIC,7,38,60,8
 747.359 +    LTEXT           "Unit code:",IDC_STATIC,7,68,60,8
 747.360 +    LTEXT           "Cartridge type:",IDC_STATIC,7,82,60,8
 747.361 +    LTEXT           "ROM version:",IDC_STATIC,7,152,60,8
 747.362 +    LTEXT           "CRC:",IDC_STATIC,7,166,60,8
 747.363 +    LTEXT           "",IDC_ROM_TITLE,80,10,133,8
 747.364 +    LTEXT           "",IDC_ROM_MAKER_CODE,80,38,133,8
 747.365 +    LTEXT           "",IDC_ROM_UNIT_CODE,80,68,133,8
 747.366 +    LTEXT           "",IDC_ROM_DEVICE_TYPE,80,82,133,8
 747.367 +    LTEXT           "",IDC_ROM_VERSION,80,152,133,8
 747.368 +    LTEXT           "",IDC_ROM_CRC,80,166,133,8
 747.369 +    LTEXT           "Color:",IDC_STATIC,7,24,60,8
 747.370 +    LTEXT           "",IDC_ROM_COLOR,80,24,133,8
 747.371 +    LTEXT           "ROM size:",IDC_STATIC,7,96,60,8
 747.372 +    LTEXT           "",IDC_ROM_SIZE,80,96,133,8
 747.373 +    LTEXT           "RAM size:",IDC_STATIC,7,110,60,8
 747.374 +    LTEXT           "",IDC_ROM_RAM_SIZE,80,110,133,8
 747.375 +    LTEXT           "Dest. code:",IDC_STATIC,7,124,60,8
 747.376 +    LTEXT           "",IDC_ROM_DEST_CODE,80,124,133,8
 747.377 +    LTEXT           "License code:",IDC_STATIC,7,138,60,8
 747.378 +    LTEXT           "",IDC_ROM_LIC_CODE,80,138,133,8
 747.379 +    LTEXT           "Checksum:",IDC_STATIC,7,180,60,8
 747.380 +    LTEXT           "",IDC_ROM_CHECKSUM,80,180,133,8
 747.381 +    LTEXT           "",IDC_ROM_MAKER_NAME2,80,52,133,8
 747.382 +    LTEXT           "Maker name:",IDC_STATIC,7,52,60,8
 747.383 +END
 747.384 +
 747.385 +IDD_GB_CHEAT_LIST DIALOG 0, 0, 286, 221
 747.386 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.387 +CAPTION "Gameboy Cheat List"
 747.388 +FONT 8, "MS Sans Serif"
 747.389 +BEGIN
 747.390 +    CONTROL         "",IDC_CHEAT_LIST,"SysListView32",LVS_REPORT | WS_BORDER | WS_GROUP | WS_TABSTOP,9,20,269,156
 747.391 +    PUSHBUTTON      "Add &GameGenie...",IDC_ADD_GG_CHEAT,9,183,80,14,WS_GROUP
 747.392 +    PUSHBUTTON      "&Add GameShark...",IDC_ADD_GS_CHEAT,103,183,80,14,WS_GROUP
 747.393 +    PUSHBUTTON      "&Remove",IDC_REMOVE,197,183,80,14
 747.394 +    PUSHBUTTON      "Remove A&ll",IDC_REMOVE_ALL,9,202,80,14
 747.395 +    PUSHBUTTON      "&Enable/Dis.",IDC_ENABLE,103,202,80,14
 747.396 +    DEFPUSHBUTTON   "&OK",ID_OK,197,202,80,14
 747.397 +    LTEXT           "Status legend:",IDC_STATIC,10,9,46,8
 747.398 +    LTEXT           "E: Enabled",IDC_STATIC,195,9,36,8
 747.399 +    LTEXT           "D: Disabled",IDC_STATIC,241,9,38,8
 747.400 +END
 747.401 +
 747.402 +IDD_ADD_CHEAT_DLG DIALOG 0, 0, 182, 107
 747.403 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.404 +CAPTION "Title"
 747.405 +FONT 8, "MS Sans Serif"
 747.406 +BEGIN
 747.407 +    EDITTEXT        IDC_DESC,60,7,120,14,ES_AUTOHSCROLL
 747.408 +    EDITTEXT        IDC_CODE,60,23,120,58,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
 747.409 +    DEFPUSHBUTTON   "OK",ID_OK,33,86,50,14
 747.410 +    PUSHBUTTON      "Cancel",ID_CANCEL,99,86,50,14
 747.411 +    LTEXT           "&Description:",IDC_STATIC,3,10,54,8
 747.412 +    LTEXT           "&Code:",IDC_STATIC,3,29,54,8
 747.413 +END
 747.414 +
 747.415 +IDD_GB_PRINTER DIALOG 0, 0, 178, 209
 747.416 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.417 +CAPTION "GB Printer"
 747.418 +FONT 8, "MS Sans Serif"
 747.419 +BEGIN
 747.420 +    CONTROL         "&1x",IDC_1X,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,166,22,10
 747.421 +    CONTROL         "&2x",IDC_2X,"Button",BS_AUTORADIOBUTTON,55,166,23,10
 747.422 +    CONTROL         "&3x",IDC_3X,"Button",BS_AUTORADIOBUTTON,98,166,23,10
 747.423 +    CONTROL         "&4x",IDC_4X,"Button",BS_AUTORADIOBUTTON,141,166,23,10
 747.424 +    DEFPUSHBUTTON   "&Print...",ID_PRINT,7,190,50,14,WS_GROUP
 747.425 +    PUSHBUTTON      "&Save...",ID_SAVE,64,190,50,14
 747.426 +    PUSHBUTTON      "&Close",ID_OK,121,190,50,14
 747.427 +    CONTROL         "",IDC_GB_PRINTER,"Static",SS_BLACKFRAME | WS_GROUP,7,6,162,146
 747.428 +    GROUPBOX        "Print Size",IDC_STATIC,7,156,162,25
 747.429 +END
 747.430 +
 747.431 +IDD_MOTION_CONFIG DIALOG 0, 0, 135, 78
 747.432 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.433 +CAPTION "Motion Sensor"
 747.434 +FONT 8, "MS Sans Serif"
 747.435 +BEGIN
 747.436 +    EDITTEXT        IDC_EDIT_UP,47,2,81,12,ES_AUTOHSCROLL
 747.437 +    EDITTEXT        IDC_EDIT_DOWN,47,16,81,12,ES_AUTOHSCROLL
 747.438 +    EDITTEXT        IDC_EDIT_LEFT,47,30,81,12,ES_AUTOHSCROLL
 747.439 +    EDITTEXT        IDC_EDIT_RIGHT,47,44,81,12,ES_AUTOHSCROLL
 747.440 +    PUSHBUTTON      "OK",ID_OK,20,60,40,14
 747.441 +    PUSHBUTTON      "Cancel",ID_CANCEL,74,60,40,14
 747.442 +    LTEXT           "Up:",IDC_STATIC,5,2,35,10
 747.443 +    LTEXT           "Down:",IDC_STATIC,5,16,35,10
 747.444 +    LTEXT           "Left:",IDC_STATIC,5,30,35,10
 747.445 +    LTEXT           "Right:",IDC_STATIC,5,44,35,10
 747.446 +END
 747.447 +
 747.448 +IDD_LANG_SELECT DIALOG 0, 0, 186, 68
 747.449 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.450 +CAPTION "Language selection"
 747.451 +FONT 8, "MS Sans Serif"
 747.452 +BEGIN
 747.453 +    EDITTEXT        IDC_LANG_STRING,140,25,40,14,ES_AUTOHSCROLL
 747.454 +    DEFPUSHBUTTON   "OK",ID_OK,30,49,50,14
 747.455 +    PUSHBUTTON      "Cancel",ID_CANCEL,104,49,50,14
 747.456 +    LTEXT           "Current system language is:",IDC_STATIC,6,9,123,8
 747.457 +    LTEXT           "Enter language name (3 letter):",IDC_STATIC,6,30,127,8
 747.458 +    LTEXT           "",IDC_LANG_NAME,140,9,40,8
 747.459 +END
 747.460 +
 747.461 +IDD_CODE_SELECT DIALOG 0, 0, 316, 235
 747.462 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.463 +CAPTION "Select codes to import"
 747.464 +FONT 8, "MS Sans Serif"
 747.465 +BEGIN
 747.466 +    DEFPUSHBUTTON   "OK",ID_OK,91,214,50,14
 747.467 +    PUSHBUTTON      "Cancel",ID_CANCEL,174,214,50,14
 747.468 +    LISTBOX         IDC_GAME_LIST,7,7,302,205,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP
 747.469 +END
 747.470 +
 747.471 +IDD_MAP_VIEW DIALOG 0, 0, 322, 238
 747.472 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
 747.473 +CAPTION "Map view"
 747.474 +FONT 8, "MS Sans Serif"
 747.475 +BEGIN
 747.476 +    CONTROL         "Frame 0",IDC_FRAME_0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,22,41,10
 747.477 +    CONTROL         "Frame 1",IDC_FRAME_1,"Button",BS_AUTORADIOBUTTON,13,36,41,10
 747.478 +    CONTROL         "BG0",IDC_BG0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,63,30,10
 747.479 +    CONTROL         "BG1",IDC_BG1,"Button",BS_AUTORADIOBUTTON,13,77,30,10
 747.480 +    CONTROL         "BG2",IDC_BG2,"Button",BS_AUTORADIOBUTTON,13,91,30,10
 747.481 +    CONTROL         "BG3",IDC_BG3,"Button",BS_AUTORADIOBUTTON,13,105,30,10
 747.482 +    CONTROL         "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,7,122,68,10
 747.483 +    CONTROL         "Auto update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,7,134,55,10
 747.484 +    PUSHBUTTON      "&Refresh",IDC_REFRESH,25,217,50,14,WS_GROUP
 747.485 +    PUSHBUTTON      "&Save...",IDC_SAVE,88,217,50,14,WS_GROUP
 747.486 +    PUSHBUTTON      "&Close",IDC_CLOSE,155,217,50,14
 747.487 +    CONTROL         "MapView",IDC_MAP_VIEW,"VbaBitmapControl",WS_GROUP | WS_TABSTOP,187,15,128,128
 747.488 +    CONTROL         "Zoom",IDC_MAP_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | WS_TABSTOP,7,148,64,64
 747.489 +    CONTROL         "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,187,164,48,47
 747.490 +    LTEXT           "",IDC_R,245,173,50,8
 747.491 +    LTEXT           "",IDC_G,245,185,50,8
 747.492 +    LTEXT           "",IDC_B,245,197,50,8
 747.493 +    GROUPBOX        "Frame",IDC_STATIC,7,11,63,37
 747.494 +    GROUPBOX        "Background",IDC_STATIC,7,52,63,67
 747.495 +    LTEXT           "",IDC_XY,129,95,53,8
 747.496 +    LTEXT           "Mode:",IDC_STATIC,80,15,34,8
 747.497 +    LTEXT           "",IDC_MODE,130,15,53,8
 747.498 +    LTEXT           "Map Base:",IDC_STATIC,80,25,35,8
 747.499 +    LTEXT           "",IDC_MAPBASE,130,25,53,8
 747.500 +    LTEXT           "Char Base:",IDC_STATIC,80,35,36,8
 747.501 +    LTEXT           "",IDC_CHARBASE,130,35,53,8
 747.502 +    LTEXT           "Size:",IDC_STATIC,80,45,37,8
 747.503 +    LTEXT           "",IDC_DIM,130,45,53,8
 747.504 +    LTEXT           "Colors:",IDC_STATIC,80,55,37,8
 747.505 +    LTEXT           "",IDC_NUMCOLORS,130,55,53,8
 747.506 +    LTEXT           "Priority:",IDC_STATIC,80,65,37,8
 747.507 +    LTEXT           "",IDC_PRIORITY,130,65,53,8
 747.508 +    LTEXT           "Mosaic:",IDC_STATIC,80,75,37,8
 747.509 +    LTEXT           "",IDC_MOSAIC,130,75,53,8
 747.510 +    LTEXT           "Overflow:",IDC_STATIC,80,85,37,8
 747.511 +    LTEXT           "",IDC_OVERFLOW,130,85,53,8
 747.512 +    LTEXT           "Address:",IDC_STATIC,80,105,37,8
 747.513 +    LTEXT           "",IDC_ADDRESS,130,105,53,8
 747.514 +    LTEXT           "Tile:",IDC_STATIC,80,115,37,8
 747.515 +    LTEXT           "",IDC_TILE_NUM,130,115,53,8
 747.516 +    LTEXT           "Flip:",IDC_STATIC,80,125,37,8
 747.517 +    LTEXT           "",IDC_FLIP,130,125,53,8
 747.518 +    LTEXT           "Palette:",IDC_STATIC,80,135,37,8
 747.519 +    LTEXT           "",IDC_PALETTE_NUM,130,135,53,8
 747.520 +END
 747.521 +
 747.522 +IDD_PALETTE_VIEW DIALOG 0, 0, 316, 266
 747.523 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
 747.524 +CAPTION "Palette View"
 747.525 +FONT 8, "MS Sans Serif"
 747.526 +BEGIN
 747.527 +    PUSHBUTTON      "Save BG...",IDC_SAVE_BG,30,245,50,14
 747.528 +    PUSHBUTTON      "Save OBJ...",IDC_SAVE_OBJ,98,245,50,14
 747.529 +    PUSHBUTTON      "&Refresh",IDC_REFRESH2,166,245,50,14
 747.530 +    PUSHBUTTON      "&Close",IDC_CLOSE,234,245,50,14
 747.531 +    LTEXT           "",IDC_ADDRESS,53,168,50,8
 747.532 +    LTEXT           "",IDC_R,53,180,50,8
 747.533 +    LTEXT           "",IDC_G,53,192,50,8
 747.534 +    LTEXT           "",IDC_B,53,204,50,8
 747.535 +    LTEXT           "",IDC_VALUE,53,216,50,8
 747.536 +    CONTROL         "Custom1",IDC_COLOR,"VbaColorControl",WS_TABSTOP,161,168,50,50
 747.537 +    CONTROL         "PaletteViewBG",IDC_PALETTE_VIEW,"VbaPaletteViewControl",WS_TABSTOP,12,30,128,128
 747.538 +    CONTROL         "PaletteViewBG",IDC_PALETTE_VIEW_OBJ,
 747.539 +                    "VbaPaletteViewControl",WS_TABSTOP,166,30,128,128
 747.540 +    GROUPBOX        "Background",IDC_STATIC,7,20,137,143
 747.541 +    GROUPBOX        "Sprite",IDC_STATIC,161,20,137,143
 747.542 +    LTEXT           "Address:",IDC_STATIC,7,168,38,8
 747.543 +    LTEXT           "R:",IDC_STATIC,7,180,41,8
 747.544 +    LTEXT           "G:",IDC_STATIC,7,192,43,8
 747.545 +    LTEXT           "B:",IDC_STATIC,7,204,38,8
 747.546 +    LTEXT           "Value:",IDC_STATIC,7,216,38,8
 747.547 +    LTEXT           "Click on a color for more information",IDC_STATIC,7,7,302,8
 747.548 +    CONTROL         "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,229,71,10
 747.549 +END
 747.550 +
 747.551 +IDD_MEM_VIEWER DIALOGEX 0, 0, 380, 178
 747.552 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
 747.553 +CAPTION "Memory viewer"
 747.554 +FONT 8, "MS Sans Serif", 0, 0, 0x0
 747.555 +BEGIN
 747.556 +    COMBOBOX        IDC_ADDRESSES,7,7,109,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
 747.557 +    CONTROL         "8-bit",IDC_8_BIT,"Button",BS_AUTORADIOBUTTON | WS_GROUP,120,9,29,10
 747.558 +    CONTROL         "16-bit",IDC_16_BIT,"Button",BS_AUTORADIOBUTTON,154,9,33,10
 747.559 +    CONTROL         "32-bit",IDC_32_BIT,"Button",BS_AUTORADIOBUTTON,192,9,33,10
 747.560 +    EDITTEXT        IDC_ADDRESS,238,7,82,14,ES_UPPERCASE | ES_AUTOHSCROLL | ES_WANTRETURN | WS_GROUP
 747.561 +    DEFPUSHBUTTON   "&Go",IDC_GO,323,7,50,14,WS_GROUP
 747.562 +    CONTROL         "Viewer",IDC_VIEWER,"VbaMemoryViewer",WS_TABSTOP,7,22,366,112
 747.563 +    CONTROL         "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,139,71,10
 747.564 +    PUSHBUTTON      "&Refresh",IDC_REFRESH,67,157,50,14
 747.565 +    PUSHBUTTON      "&Load...",IDC_LOAD,132,157,50,14
 747.566 +    PUSHBUTTON      "&Save...",IDC_SAVE,197,157,50,14
 747.567 +    PUSHBUTTON      "&Close",IDC_CLOSE,262,157,50,14
 747.568 +    LTEXT           "Current address:",IDC_CURRENT_ADDRESS_LABEL,235,142,52,8
 747.569 +    EDITTEXT        IDC_CURRENT_ADDRESS,291,139,82,14,ES_RIGHT | ES_AUTOHSCROLL | WS_DISABLED
 747.570 +    CONTROL         "Decimal Display",IDC_DECIMAL_DISPLAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,85,139,66,10
 747.571 +    CONTROL         "Align to 16-byte",IDC_ALIGN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,159,139,65,10
 747.572 +END
 747.573 +
 747.574 +IDD_OAM_VIEW DIALOG 0, 0, 234, 185
 747.575 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
 747.576 +CAPTION "Oam Viewer"
 747.577 +FONT 8, "MS Sans Serif"
 747.578 +BEGIN
 747.579 +    EDITTEXT        IDC_SPRITE,7,19,76,14,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER
 747.580 +    SCROLLBAR       IDC_SCROLLBAR,7,33,76,11
 747.581 +    CONTROL         "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,138,79,10
 747.582 +    PUSHBUTTON      "&Refresh",IDC_REFRESH,7,164,50,14,WS_GROUP
 747.583 +    PUSHBUTTON      "&Save...",IDC_SAVE,91,164,50,14,WS_GROUP
 747.584 +    PUSHBUTTON      "&Close",IDC_CLOSE,177,164,50,14
 747.585 +    CONTROL         "MapView",IDC_OAM_VIEW,"VbaBitmapControl",WS_GROUP | WS_TABSTOP,87,7,64,64
 747.586 +    CONTROL         "Zoom",IDC_OAM_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | WS_TABSTOP,163,7,64,64
 747.587 +    CONTROL         "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,87,79,48,47
 747.588 +    LTEXT           "",IDC_POS,31,47,50,8
 747.589 +    LTEXT           "",IDC_MODE,31,57,50,8
 747.590 +    LTEXT           "",IDC_COLORS,31,67,50,8
 747.591 +    LTEXT           "",IDC_PALETTE,31,77,50,8
 747.592 +    LTEXT           "",IDC_TILE,31,87,50,8
 747.593 +    LTEXT           "",IDC_PRIO,31,97,50,8
 747.594 +    LTEXT           "",IDC_SIZE2,31,107,50,8
 747.595 +    LTEXT           "",IDC_ROT,31,117,50,8
 747.596 +    LTEXT           "",IDC_FLAGS,31,127,50,8
 747.597 +    LTEXT           "",IDC_R,145,88,50,8
 747.598 +    LTEXT           "",IDC_G,145,100,50,8
 747.599 +    LTEXT           "",IDC_B,145,112,50,8
 747.600 +    LTEXT           "Pos:",IDC_STATIC,7,47,24,8
 747.601 +    LTEXT           "Mode:",IDC_STATIC,7,57,24,8
 747.602 +    LTEXT           "Colors:",IDC_STATIC,7,67,24,8
 747.603 +    LTEXT           "Pal:",IDC_STATIC,7,77,24,8
 747.604 +    LTEXT           "Tile:",IDC_STATIC,7,87,24,8
 747.605 +    LTEXT           "Prio:",IDC_STATIC,7,97,24,8
 747.606 +    LTEXT           "Size:",IDC_STATIC,7,107,24,8
 747.607 +    LTEXT           "Sprite:",IDC_STATIC,7,7,50,8
 747.608 +    LTEXT           "Rot.:",IDC_STATIC,7,117,24,8
 747.609 +    LTEXT           "Flags:",IDC_STATIC,7,127,24,8
 747.610 +    CONTROL         "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,150,71,10
 747.611 +END
 747.612 +
 747.613 +IDD_ACCEL_EDITOR DIALOGEX 0, 0, 320, 180
 747.614 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
 747.615 +CAPTION "Accelerator Editor"
 747.616 +FONT 8, "MS Sans Serif", 0, 0, 0x0
 747.617 +BEGIN
 747.618 +    LTEXT           "Commands:",IDC_STATIC,9,9,38,8
 747.619 +    LTEXT           "Current Keys:",IDC_STATIC1,156,9,43,8
 747.620 +    LTEXT           "Enter new accelerator:",IDC_STATIC3,156,87,99,8
 747.621 +    LTEXT           "Static",IDC_ALREADY_AFFECTED,7,162,306,8,SS_CENTERIMAGE
 747.622 +    LTEXT           "Already assigned to:",IDC_STATIC2,7,148,85,8
 747.623 +    LTEXT           "(0 to disable, millisec)",IDC_STATIC5,156,148,101,8
 747.624 +    LTEXT           "Kill focus on timeout:",IDC_STATIC4,156,136,89,8
 747.625 +    CONTROL         "",IDC_COMMANDS,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_DISABLEDRAGDROP | TVS_SHOWSELALWAYS | WS_BORDER | WS_HSCROLL | WS_TABSTOP,7,18,139,124
 747.626 +    EDITTEXT        IDC_EDIT_KEY,156,100,100,12,ES_AUTOHSCROLL | NOT WS_TABSTOP,WS_EX_TRANSPARENT
 747.627 +    CONTROL         "",IDC_ACCELEDIT_PROGRESSBAR,"msctls_progress32",PBS_SMOOTH | WS_BORDER,156,116,100,14
 747.628 +    CONTROL         "",IDC_CURRENTS,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_NOLABELWRAP | LVS_ALIGNLEFT | LVS_NOSCROLL | LVS_NOCOLUMNHEADER | WS_BORDER | WS_TABSTOP,156,19,100,63
 747.629 +    DEFPUSHBUTTON   "&OK",ID_OK,263,7,50,14
 747.630 +    PUSHBUTTON      "&Cancel",ID_CANCEL,263,25,50,14
 747.631 +    PUSHBUTTON      "&Apply",IDC_ACCELEDIT_APPLY,264,44,49,14
 747.632 +    PUSHBUTTON      "&Insert",IDC_ASSIGN,263,82,50,14
 747.633 +    PUSHBUTTON      "&Delete",IDC_REMOVE,263,100,50,14
 747.634 +    PUSHBUTTON      "&Replace",IDC_ACCELEDIT_REPLACE,263,118,50,14
 747.635 +    EDITTEXT        IDC_ACCELEDIT_AUTOTIMEOUT,265,143,48,14,ES_AUTOHSCROLL | ES_NUMBER
 747.636 +END
 747.637 +
 747.638 +IDD_TILE_VIEWER DIALOG 0, 0, 326, 266
 747.639 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
 747.640 +CAPTION "Tile Viewer"
 747.641 +FONT 8, "MS Sans Serif"
 747.642 +BEGIN
 747.643 +    CONTROL         "16",IDC_16_COLORS,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,20,24,10
 747.644 +    CONTROL         "256",IDC_256_COLORS,"Button",BS_AUTORADIOBUTTON,13,30,28,10
 747.645 +    CONTROL         "0x6000000",IDC_CHARBASE_0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,57,51,10
 747.646 +    CONTROL         "0x6004000",IDC_CHARBASE_1,"Button",BS_AUTORADIOBUTTON,13,67,51,10
 747.647 +    CONTROL         "0x6008000",IDC_CHARBASE_2,"Button",BS_AUTORADIOBUTTON,13,77,51,10
 747.648 +    CONTROL         "0x600C000",IDC_CHARBASE_3,"Button",BS_AUTORADIOBUTTON,13,87,52,10
 747.649 +    CONTROL         "0x6010000",IDC_CHARBASE_4,"Button",BS_AUTORADIOBUTTON,13,97,49,10
 747.650 +    CONTROL         "Slider1",IDC_PALETTE_SLIDER,"msctls_trackbar32",TBS_AUTOTICKS | WS_GROUP | WS_TABSTOP,1,124,76,22
 747.651 +    CONTROL         "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,149,79,10
 747.652 +    PUSHBUTTON      "Refresh",IDC_REFRESH,7,245,50,14,WS_GROUP
 747.653 +    PUSHBUTTON      "Save...",IDC_SAVE,138,245,50,14
 747.654 +    PUSHBUTTON      "Close",IDC_CLOSE,269,245,50,14
 747.655 +    CONTROL         "Custom1",IDC_TILE_VIEW,"VbaBitmapControl",WS_GROUP | WS_TABSTOP,191,7,128,128
 747.656 +    GROUPBOX        "Colors",IDC_STATIC,7,7,66,38
 747.657 +    GROUPBOX        "Char Base",IDC_STATIC,7,46,65,64
 747.658 +    CONTROL         "Zoom",IDC_MAP_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | WS_TABSTOP,7,174,64,64
 747.659 +    CONTROL         "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,98,183,48,47
 747.660 +    LTEXT           "",IDC_R,156,192,50,8
 747.661 +    LTEXT           "",IDC_G,156,204,50,8
 747.662 +    LTEXT           "",IDC_B,156,216,50,8
 747.663 +    LTEXT           "Palette:",IDC_STATIC,7,113,65,8
 747.664 +    CONTROL         "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,160,71,10
 747.665 +    LTEXT           "Tile:",IDC_STATIC,79,14,41,8
 747.666 +    LTEXT           "Address:",IDC_STATIC,79,26,41,8
 747.667 +    LTEXT           "",IDC_TILE_NUMBER,135,14,50,8
 747.668 +    LTEXT           "",IDC_ADDRESS,135,26,50,8
 747.669 +END
 747.670 +
 747.671 +IDD_GB_COLORS DIALOGEX 0, 0, 169, 121
 747.672 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.673 +CAPTION "Gameboy Mono Colors"
 747.674 +FONT 8, "MS Sans Serif", 0, 0, 0x0
 747.675 +BEGIN
 747.676 +    CONTROL         "Default",IDC_DEFAULT,"Button",BS_AUTORADIOBUTTON | WS_GROUP,7,7,39,10
 747.677 +    CONTROL         "User 1",IDC_USER1,"Button",BS_AUTORADIOBUTTON,67,7,37,10
 747.678 +    CONTROL         "User 2",IDC_USER2,"Button",BS_AUTORADIOBUTTON,125,7,37,10
 747.679 +    COMBOBOX        IDC_PREDEFINED,7,21,155,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
 747.680 +    PUSHBUTTON      "",IDC_COLOR_BG0,15,47,28,14,WS_GROUP
 747.681 +    PUSHBUTTON      "",IDC_COLOR_BG1,52,47,28,14
 747.682 +    PUSHBUTTON      "",IDC_COLOR_BG2,89,47,28,14
 747.683 +    PUSHBUTTON      "",IDC_COLOR_BG3,126,47,28,14
 747.684 +    PUSHBUTTON      "",IDC_COLOR_OB0,15,78,28,14
 747.685 +    PUSHBUTTON      "",IDC_COLOR_OB1,52,78,28,14
 747.686 +    PUSHBUTTON      "",IDC_COLOR_OB2,89,78,28,14
 747.687 +    PUSHBUTTON      "",IDC_COLOR_OB3,126,78,28,14
 747.688 +    PUSHBUTTON      "Reset",IDC_RESET,7,100,50,14
 747.689 +    DEFPUSHBUTTON   "OK",ID_OK,59,100,50,14
 747.690 +    PUSHBUTTON      "Cancel",ID_CANCEL,111,100,50,14
 747.691 +    GROUPBOX        "Background",IDC_STATIC,8,37,154,29
 747.692 +    GROUPBOX        "Sprite",IDC_STATIC,8,67,154,30
 747.693 +END
 747.694 +
 747.695 +IDD_DISASSEMBLE DIALOG 0, 0, 402, 225
 747.696 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
 747.697 +CAPTION "Disassemble"
 747.698 +FONT 8, "MS Sans Serif"
 747.699 +BEGIN
 747.700 +    CONTROL         "Automatic",IDC_AUTOMATIC,"Button",BS_AUTORADIOBUTTON | WS_GROUP,7,9,47,10
 747.701 +    CONTROL         "ARM",IDC_ARM,"Button",BS_AUTORADIOBUTTON,62,9,32,10
 747.702 +    CONTROL         "THUMB",IDC_THUMB,"Button",BS_AUTORADIOBUTTON,103,9,42,10
 747.703 +    EDITTEXT        IDC_ADDRESS,158,7,65,14,ES_UPPERCASE | ES_AUTOHSCROLL | WS_GROUP
 747.704 +    DEFPUSHBUTTON   "Go",IDC_GO,232,7,50,14
 747.705 +    LISTBOX         IDC_DISASSEMBLE,7,25,276,161,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_TABSTOP
 747.706 +    CONTROL         "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,191,71,10
 747.707 +    PUSHBUTTON      "Refresh",IDC_REFRESH,120,204,50,14
 747.708 +    PUSHBUTTON      "Next",IDC_NEXT,233,204,50,14
 747.709 +    PUSHBUTTON      "Close",IDC_CLOSE,346,204,50,14
 747.710 +    LTEXT           "R0:",IDC_STATIC,309,7,18,8
 747.711 +    LTEXT           "R1:",IDC_STATIC,309,15,18,8
 747.712 +    LTEXT           "R2:",IDC_STATIC,309,23,18,8
 747.713 +    LTEXT           "R3:",IDC_STATIC,309,31,18,8
 747.714 +    LTEXT           "R4:",IDC_STATIC,309,39,18,8
 747.715 +    LTEXT           "R5:",IDC_STATIC,309,47,18,8
 747.716 +    LTEXT           "R6:",IDC_STATIC,309,55,18,8
 747.717 +    LTEXT           "R7:",IDC_STATIC,309,63,18,8
 747.718 +    LTEXT           "",IDC_R0,344,7,52,8
 747.719 +    LTEXT           "",IDC_R1,344,15,52,8
 747.720 +    LTEXT           "",IDC_R2,344,23,52,8
 747.721 +    LTEXT           "",IDC_R3,344,31,52,8
 747.722 +    LTEXT           "",IDC_R4,344,39,52,8
 747.723 +    LTEXT           "",IDC_R5,344,47,52,8
 747.724 +    LTEXT           "",IDC_R6,344,55,52,8
 747.725 +    LTEXT           "",IDC_R7,344,63,52,8
 747.726 +    LTEXT           "",IDC_R8,344,71,52,8
 747.727 +    LTEXT           "",IDC_R9,344,79,52,8
 747.728 +    LTEXT           "",IDC_R10,344,87,52,8
 747.729 +    LTEXT           "",IDC_R11,344,95,52,8
 747.730 +    LTEXT           "",IDC_R12,344,103,52,8
 747.731 +    LTEXT           "",IDC_R13,344,111,52,8
 747.732 +    LTEXT           "",IDC_R14,344,119,52,8
 747.733 +    LTEXT           "",IDC_R15,344,127,52,8
 747.734 +    LTEXT           "R8:",IDC_STATIC,309,71,18,8
 747.735 +    LTEXT           "R9:",IDC_STATIC,309,79,18,8
 747.736 +    LTEXT           "R10:",IDC_STATIC,309,87,18,8
 747.737 +    LTEXT           "R11:",IDC_STATIC,309,95,18,8
 747.738 +    LTEXT           "R12:",IDC_STATIC,309,103,18,8
 747.739 +    LTEXT           "R13:",IDC_STATIC,309,111,18,8
 747.740 +    LTEXT           "R14:",IDC_STATIC,309,119,18,8
 747.741 +    LTEXT           "R15:",IDC_STATIC,309,127,18,8
 747.742 +    LTEXT           "",IDC_R16,344,135,52,8
 747.743 +    LTEXT           "R16:",IDC_STATIC,309,135,20,8
 747.744 +    CONTROL         "N",IDC_N,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,309,146,21,10
 747.745 +    CONTROL         "Z",IDC_Z,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,309,156,21,10
 747.746 +    CONTROL         "C",IDC_C,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,309,166,21,10
 747.747 +    CONTROL         "V",IDC_V,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,309,176,21,10
 747.748 +    CONTROL         "F",IDC_F,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,342,156,20,10
 747.749 +    CONTROL         "I",IDC_I,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,342,146,18,10
 747.750 +    CONTROL         "T",IDC_T,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,342,166,21,10
 747.751 +    LTEXT           "Mode:",IDC_STATIC,341,176,21,8
 747.752 +    LTEXT           "",IDC_MODE,376,176,20,8
 747.753 +    SCROLLBAR       IDC_VSCROLL,283,25,10,161,SBS_VERT
 747.754 +    PUSHBUTTON      "Goto R15",IDC_GOPC,7,204,50,14
 747.755 +END
 747.756 +
 747.757 +IDD_GDB_PORT DIALOG 0, 0, 186, 51
 747.758 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.759 +CAPTION "GDB connection"
 747.760 +FONT 8, "MS Sans Serif"
 747.761 +BEGIN
 747.762 +    DEFPUSHBUTTON   "OK",ID_OK,34,30,50,14
 747.763 +    PUSHBUTTON      "Cancel",ID_CANCEL,102,30,50,14
 747.764 +    LTEXT           "Port to wait for connection:",IDC_STATIC,7,10,105,8
 747.765 +    EDITTEXT        IDC_PORT,125,7,54,14,ES_RIGHT | ES_AUTOHSCROLL
 747.766 +END
 747.767 +
 747.768 +IDD_GDB_WAITING DIALOG 0, 0, 186, 44
 747.769 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.770 +CAPTION "Waiting..."
 747.771 +FONT 8, "MS Sans Serif"
 747.772 +BEGIN
 747.773 +    PUSHBUTTON      "Cancel",ID_CANCEL,67,23,50,14
 747.774 +    LTEXT           "Waiting for connection on port:",IDC_STATIC,7,7,117,8
 747.775 +    LTEXT           "",IDC_PORT,143,7,36,8
 747.776 +END
 747.777 +
 747.778 +IDD_LOGGING DIALOG 0, 0, 366, 218
 747.779 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
 747.780 +CAPTION "Logging"
 747.781 +FONT 8, "MS Sans Serif"
 747.782 +BEGIN
 747.783 +    CONTROL         "SWI",IDC_VERBOSE_SWI,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,17,87,10
 747.784 +    CONTROL         "Unaligned memory",IDC_VERBOSE_UNALIGNED_ACCESS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,30,87,10
 747.785 +    CONTROL         "Illegal write",IDC_VERBOSE_ILLEGAL_WRITE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,43,87,10
 747.786 +    CONTROL         "Illegal read",IDC_VERBOSE_ILLEGAL_READ,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,56,87,10
 747.787 +    CONTROL         "DMA 0",IDC_VERBOSE_DMA0,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,69,87,10
 747.788 +    CONTROL         "DMA 1",IDC_VERBOSE_DMA1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,82,87,10
 747.789 +    CONTROL         "DMA 2",IDC_VERBOSE_DMA2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,95,87,10
 747.790 +    CONTROL         "DMA 3",IDC_VERBOSE_DMA3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,108,87,10
 747.791 +    CONTROL         "Undefined instruction",IDC_VERBOSE_UNDEFINED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,121,87,10
 747.792 +    CONTROL         "AGBPrint",IDC_VERBOSE_AGBPRINT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,134,87,10
 747.793 +    EDITTEXT        IDC_LOG,107,7,252,183,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | WS_HSCROLL
 747.794 +    PUSHBUTTON      "Save...",IDC_SAVE,75,197,50,14
 747.795 +    PUSHBUTTON      "Clear",IDC_CLEAR,137,197,50,14
 747.796 +    DEFPUSHBUTTON   "OK",ID_OK,197,197,50,14
 747.797 +    GROUPBOX        "Verbose",IDC_STATIC,7,7,93,142
 747.798 +END
 747.799 +
 747.800 +IDD_EXPORT_SPS DIALOG 0, 0, 248, 148
 747.801 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.802 +CAPTION "Export Gameshark Snapshot"
 747.803 +FONT 8, "MS Sans Serif"
 747.804 +BEGIN
 747.805 +    EDITTEXT        IDC_TITLE,84,7,157,14,ES_AUTOHSCROLL
 747.806 +    EDITTEXT        IDC_DESC,84,27,157,14,ES_AUTOHSCROLL
 747.807 +    EDITTEXT        IDC_NOTES,84,47,157,73,ES_MULTILINE | ES_AUTOHSCROLL | ES_WANTRETURN
 747.808 +    DEFPUSHBUTTON   "OK",ID_OK,67,127,50,14
 747.809 +    PUSHBUTTON      "Cancel",ID_CANCEL,130,127,50,14
 747.810 +    LTEXT           "Title:",IDC_STATIC,7,8,62,8
 747.811 +    LTEXT           "Description:",IDC_STATIC,7,28,63,8
 747.812 +    LTEXT           "Notes:",IDC_STATIC,7,48,60,8
 747.813 +END
 747.814 +
 747.815 +IDD_ADDR_SIZE DIALOG 0, 0, 186, 67
 747.816 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.817 +CAPTION "Enter address and size"
 747.818 +FONT 8, "MS Sans Serif"
 747.819 +BEGIN
 747.820 +    EDITTEXT        IDC_ADDRESS,99,6,80,14,ES_AUTOHSCROLL
 747.821 +    EDITTEXT        IDC_SIZE_CONTROL,99,26,80,14,ES_AUTOHSCROLL
 747.822 +    DEFPUSHBUTTON   "OK",ID_OK,34,46,50,14
 747.823 +    PUSHBUTTON      "Cancel",ID_CANCEL,102,46,50,14
 747.824 +    LTEXT           "Address:",IDC_STATIC,7,11,65,8
 747.825 +    LTEXT           "Size:",IDC_STATIC,7,29,65,8
 747.826 +END
 747.827 +
 747.828 +IDD_MODES DIALOG 0, 0, 208, 129
 747.829 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.830 +CAPTION "Select video mode"
 747.831 +FONT 8, "MS Sans Serif"
 747.832 +BEGIN
 747.833 +    LISTBOX         IDC_MODES,7,18,194,80,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
 747.834 +    DEFPUSHBUTTON   "OK",ID_OK,45,108,50,14
 747.835 +    PUSHBUTTON      "Cancel",ID_CANCEL,112,108,50,14
 747.836 +    LTEXT           "Available video modes:",IDC_STATIC,7,7,194,8
 747.837 +END
 747.838 +
 747.839 +IDD_DRIVERS DIALOG 0, 0, 208, 121
 747.840 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.841 +CAPTION "Select video driver"
 747.842 +FONT 8, "MS Sans Serif"
 747.843 +BEGIN
 747.844 +    LISTBOX         IDC_DRIVERS,7,17,194,80,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
 747.845 +    DEFPUSHBUTTON   "OK",ID_OK,45,104,50,14
 747.846 +    PUSHBUTTON      "Cancel",ID_CANCEL,112,104,50,14
 747.847 +    LTEXT           "Available drivers:",IDC_STATIC,7,7,194,8
 747.848 +END
 747.849 +
 747.850 +IDD_THROTTLE DIALOGEX 0, 0, 186, 63
 747.851 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 747.852 +CAPTION "Throttle"
 747.853 +FONT 8, "MS Sans Serif", 0, 0, 0x0
 747.854 +BEGIN
 747.855 +    EDITTEXT        IDC_THROTTLE,7,20,172,14,ES_AUTOHSCROLL
 747.856 +    DEFPUSHBUTTON   "OK",ID_OK,37,42,50,14
 747.857 +    PUSHBUTTON      "Cancel",ID_CANCEL,99,42,50,14
 747.858 +    LTEXT           "Enter desired throttle (1%...1000%):",IDC_STATIC,7,7,172,8
 747.859 +END
 747.860 +
 747.861 +IDD_GB_DISASSEMBLE DIALOG 0, 0, 344, 225
 747.862 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
 747.863 +CAPTION "GB Disassemble"
 747.864 +FONT 8, "MS Sans Serif"
 747.865 +BEGIN
 747.866 +    EDITTEXT        IDC_ADDRESS,7,7,65,14,ES_UPPERCASE | ES_AUTOHSCROLL | WS_GROUP
 747.867 +    DEFPUSHBUTTON   "Go",IDC_GO,81,7,50,14
 747.868 +    LISTBOX         IDC_DISASSEMBLE,7,25,222,161,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_TABSTOP
 747.869 +    CONTROL         "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,191,71,10
 747.870 +    PUSHBUTTON      "Refresh",IDC_REFRESH,100,204,50,14
 747.871 +    PUSHBUTTON      "Next",IDC_NEXT,193,204,50,14
 747.872 +    PUSHBUTTON      "Close",IDC_CLOSE,287,204,50,14
 747.873 +    LTEXT           "AF:",IDC_STATIC,250,25,18,8
 747.874 +    LTEXT           "BC:",IDC_STATIC,250,35,18,8
 747.875 +    LTEXT           "DE:",IDC_STATIC,250,45,18,8
 747.876 +    LTEXT           "HL:",IDC_STATIC,250,55,18,8
 747.877 +    LTEXT           "IFF:",IDC_STATIC,250,85,18,8
 747.878 +    LTEXT           "",IDC_R0,285,25,52,8
 747.879 +    LTEXT           "",IDC_R1,285,35,52,8
 747.880 +    LTEXT           "",IDC_R2,285,45,52,8
 747.881 +    LTEXT           "",IDC_R3,285,55,52,8
 747.882 +    LTEXT           "",IDC_R6,285,85,52,8
 747.883 +    CONTROL         "N",IDC_N,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,250,109,21,10
 747.884 +    CONTROL         "Z",IDC_Z,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,250,97,21,10
 747.885 +    CONTROL         "C",IDC_C,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,250,133,21,10
 747.886 +    CONTROL         "H",IDC_H,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,250,121,21,10
 747.887 +    SCROLLBAR       IDC_VSCROLL,229,25,10,161,SBS_VERT
 747.888 +    PUSHBUTTON      "Goto PC",IDC_GOPC,7,204,50,14
 747.889 +    LTEXT           "SP:",IDC_STATIC,250,65,18,8
 747.890 +    LTEXT           "",IDC_R4,285,65,52,8
 747.891 +    LTEXT           "PC:",IDC_STATIC,250,75,18,8
 747.892 +    LTEXT           "",IDC_R5,285,75,52,8
 747.893 +END
 747.894 +
 747.895 +IDD_GB_OAM_VIEW DIALOG 0, 0, 234, 185
 747.896 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 747.897 +CAPTION "GB Oam Viewer"
 747.898 +FONT 8, "MS Sans Serif"
 747.899 +BEGIN
 747.900 +    EDITTEXT        IDC_SPRITE,7,19,76,14,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER
 747.901 +    SCROLLBAR       IDC_SCROLLBAR,7,33,76,11
 747.902 +    CONTROL         "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,138,79,10
 747.903 +    PUSHBUTTON      "&Refresh",IDC_REFRESH,7,164,50,14,WS_GROUP
 747.904 +    PUSHBUTTON      "&Save...",IDC_SAVE,91,164,50,14,WS_GROUP
 747.905 +    PUSHBUTTON      "&Close",IDC_CLOSE,177,164,50,14
 747.906 +    CONTROL         "MapView",IDC_OAM_VIEW,"VbaBitmapControl",WS_GROUP | WS_TABSTOP,87,7,64,64
 747.907 +    CONTROL         "Zoom",IDC_OAM_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | WS_TABSTOP,163,7,64,64
 747.908 +    CONTROL         "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,87,79,48,47
 747.909 +    LTEXT           "",IDC_POS,31,47,50,8
 747.910 +    LTEXT           "",IDC_PALETTE,31,87,50,8
 747.911 +    LTEXT           "",IDC_TILE,31,57,50,8
 747.912 +    LTEXT           "",IDC_PRIO,31,67,50,8
 747.913 +    LTEXT           "",IDC_OAP,31,77,50,8
 747.914 +    LTEXT           "",IDC_FLAGS,31,97,50,8
 747.915 +    LTEXT           "",IDC_R,145,88,50,8
 747.916 +    LTEXT           "",IDC_G,145,100,50,8
 747.917 +    LTEXT           "",IDC_B,145,112,50,8
 747.918 +    LTEXT           "Pos:",IDC_STATIC,7,47,24,8
 747.919 +    LTEXT           "Pal:",IDC_STATIC,7,87,24,8
 747.920 +    LTEXT           "Tile:",IDC_STATIC,7,57,24,8
 747.921 +    LTEXT           "Prio:",IDC_STATIC,7,67,24,8
 747.922 +    LTEXT           "OAP:",IDC_STATIC,7,77,24,8
 747.923 +    LTEXT           "Sprite:",IDC_STATIC,7,7,50,8
 747.924 +    LTEXT           "Flags:",IDC_STATIC,7,97,24,8
 747.925 +    CONTROL         "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,150,71,10
 747.926 +    LTEXT           "",IDC_BANK,31,107,50,8
 747.927 +    LTEXT           "Bank:",IDC_STATIC,7,107,24,8
 747.928 +END
 747.929 +
 747.930 +IDD_GB_TILE_VIEWER DIALOG 0, 0, 326, 238
 747.931 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 747.932 +CAPTION "GB Tile Viewer"
 747.933 +FONT 8, "MS Sans Serif"
 747.934 +BEGIN
 747.935 +    CONTROL         "0",IDC_BANK_0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,20,20,10
 747.936 +    CONTROL         "1",IDC_BANK_1,"Button",BS_AUTORADIOBUTTON,13,30,20,10
 747.937 +    CONTROL         "0x8000",IDC_CHARBASE_0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,57,39,10
 747.938 +    CONTROL         "0x8800",IDC_CHARBASE_1,"Button",BS_AUTORADIOBUTTON,13,67,39,10
 747.939 +    CONTROL         "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,122,79,10
 747.940 +    PUSHBUTTON      "Refresh",IDC_REFRESH,7,217,50,14,WS_GROUP
 747.941 +    PUSHBUTTON      "Save...",IDC_SAVE,138,217,50,14
 747.942 +    PUSHBUTTON      "Close",IDC_CLOSE,269,217,50,14
 747.943 +    CONTROL         "Custom1",IDC_TILE_VIEW,"VbaBitmapControl",WS_GROUP | WS_TABSTOP,191,7,128,128
 747.944 +    GROUPBOX        "VRAM Bank",IDC_STATIC,7,7,66,38
 747.945 +    GROUPBOX        "Char Base",IDC_STATIC,7,46,65,35
 747.946 +    CONTROL         "Zoom",IDC_MAP_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | WS_TABSTOP,7,147,64,64
 747.947 +    CONTROL         "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,98,156,48,47
 747.948 +    LTEXT           "",IDC_R,156,164,50,8
 747.949 +    LTEXT           "",IDC_G,156,176,50,8
 747.950 +    LTEXT           "",IDC_B,156,188,50,8
 747.951 +    LTEXT           "Palette:",IDC_STATIC,7,86,65,8
 747.952 +    CONTROL         "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,133,71,10
 747.953 +    LTEXT           "Tile:",IDC_STATIC,79,14,41,8
 747.954 +    LTEXT           "Address:",IDC_STATIC,79,26,41,8
 747.955 +    LTEXT           "",IDC_TILE_NUMBER,135,14,50,8
 747.956 +    LTEXT           "",IDC_ADDRESS,135,26,50,8
 747.957 +    CONTROL         "Slider1",IDC_PALETTE_SLIDER,"msctls_trackbar32",TBS_AUTOTICKS | WS_GROUP | WS_TABSTOP,1,98,76,22
 747.958 +END
 747.959 +
 747.960 +IDD_GB_MAP_VIEW DIALOG 0, 0, 322, 238
 747.961 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
 747.962 +CAPTION "GB Map Viewer"
 747.963 +FONT 8, "MS Sans Serif"
 747.964 +BEGIN
 747.965 +    CONTROL         "0x8000",IDC_BANK_0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,22,39,10
 747.966 +    CONTROL         "0x8800",IDC_BANK_1,"Button",BS_AUTORADIOBUTTON,13,36,39,10
 747.967 +    CONTROL         "0x9800",IDC_BG0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,63,39,10
 747.968 +    CONTROL         "0x9C00",IDC_BG1,"Button",BS_AUTORADIOBUTTON,13,77,40,10
 747.969 +    CONTROL         "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,122,68,10
 747.970 +    PUSHBUTTON      "&Refresh",IDC_REFRESH,25,217,50,14,WS_GROUP
 747.971 +    PUSHBUTTON      "&Save...",IDC_SAVE,88,217,50,14,WS_GROUP
 747.972 +    PUSHBUTTON      "&Close",IDC_CLOSE,155,217,50,14
 747.973 +    CONTROL         "MapView",IDC_MAP_VIEW,"VbaBitmapControl",WS_GROUP | WS_TABSTOP,187,15,128,128
 747.974 +    CONTROL         "Zoom",IDC_MAP_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | WS_TABSTOP,7,148,64,64
 747.975 +    CONTROL         "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,187,164,48,47
 747.976 +    LTEXT           "",IDC_R,245,173,50,8
 747.977 +    LTEXT           "",IDC_G,245,185,50,8
 747.978 +    LTEXT           "",IDC_B,245,197,50,8
 747.979 +    GROUPBOX        "Char Base",IDC_STATIC,7,11,63,37
 747.980 +    GROUPBOX        "Map Base",IDC_STATIC,7,52,63,41
 747.981 +    CONTROL         "Auto update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,134,55,10
 747.982 +    LTEXT           "",IDC_XY,129,18,53,8
 747.983 +    LTEXT           "Priority:",IDC_STATIC,80,68,37,8
 747.984 +    LTEXT           "",IDC_PRIORITY,130,68,53,8
 747.985 +    LTEXT           "Address:",IDC_STATIC,80,28,37,8
 747.986 +    LTEXT           "",IDC_ADDRESS,130,28,53,8
 747.987 +    LTEXT           "Tile:",IDC_STATIC,80,38,37,8
 747.988 +    LTEXT           "",IDC_TILE_NUM,130,38,53,8
 747.989 +    LTEXT           "Flip:",IDC_STATIC,80,48,37,8
 747.990 +    LTEXT           "",IDC_FLIP,130,48,53,8
 747.991 +    LTEXT           "Palette:",IDC_STATIC,80,58,37,8
 747.992 +    LTEXT           "",IDC_PALETTE_NUM,130,58,53,8
 747.993 +END
 747.994 +
 747.995 +IDD_GB_PALETTE_VIEW DIALOG 0, 0, 196, 234
 747.996 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 747.997 +CAPTION "GB Palette Viewer"
 747.998 +FONT 8, "MS Sans Serif"
 747.999 +BEGIN
747.1000 +    PUSHBUTTON      "Save BG...",IDC_SAVE_BG,7,191,50,14
747.1001 +    PUSHBUTTON      "Save OBJ...",IDC_SAVE_OBJ,73,191,50,14
747.1002 +    PUSHBUTTON      "&Refresh",IDC_REFRESH2,139,191,50,14
747.1003 +    PUSHBUTTON      "&Close",IDC_CLOSE,73,213,50,14
747.1004 +    LTEXT           "",IDC_ADDRESS,53,117,50,8
747.1005 +    LTEXT           "",IDC_R,53,129,50,8
747.1006 +    LTEXT           "",IDC_G,53,141,50,8
747.1007 +    LTEXT           "",IDC_B,53,153,50,8
747.1008 +    LTEXT           "",IDC_VALUE,53,165,50,8
747.1009 +    CONTROL         "Custom1",IDC_COLOR,"VbaColorControl",WS_TABSTOP,119,117,50,50
747.1010 +    CONTROL         "PaletteViewBG",IDC_PALETTE_VIEW,"VbaPaletteViewControl",WS_TABSTOP,11,30,64,64
747.1011 +    CONTROL         "PaletteViewBG",IDC_PALETTE_VIEW_OBJ,
747.1012 +                    "VbaPaletteViewControl",WS_TABSTOP,120,30,64,64
747.1013 +    GROUPBOX        "BG",IDC_STATIC,6,20,74,81
747.1014 +    GROUPBOX        "Sprite",IDC_STATIC,115,20,74,81
747.1015 +    LTEXT           "Index:",IDC_STATIC,7,117,38,8
747.1016 +    LTEXT           "R:",IDC_STATIC,7,129,41,8
747.1017 +    LTEXT           "G:",IDC_STATIC,7,141,43,8
747.1018 +    LTEXT           "B:",IDC_STATIC,7,153,38,8
747.1019 +    LTEXT           "Value:",IDC_STATIC,7,165,38,8
747.1020 +    LTEXT           "Click on a color for more information",IDC_STATIC,7,7,182,8
747.1021 +    CONTROL         "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,178,71,10
747.1022 +END
747.1023 +
747.1024 +IDD_MODE_CONFIRM DIALOG 0, 0, 186, 57
747.1025 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
747.1026 +CAPTION "Confirm mode"
747.1027 +FONT 8, "MS Sans Serif"
747.1028 +BEGIN
747.1029 +    DEFPUSHBUTTON   "OK",ID_OK,31,36,50,14
747.1030 +    PUSHBUTTON      "Cancel",ID_CANCEL,103,36,50,14
747.1031 +    CTEXT           "Do you want to keep the current mode?",IDC_STATIC,7,7,172,8
747.1032 +    CTEXT           "",IDC_TIMER,7,19,172,8
747.1033 +END
747.1034 +
747.1035 +IDD_REWIND_INTERVAL DIALOGEX 0, 0, 188, 132
747.1036 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
747.1037 +CAPTION "Rewind Settings"
747.1038 +FONT 8, "MS Sans Serif", 0, 0, 0x0
747.1039 +BEGIN
747.1040 +    EDITTEXT        IDC_INTERVAL,7,26,174,14,ES_AUTOHSCROLL
747.1041 +    DEFPUSHBUTTON   "OK",ID_OK,37,111,50,14
747.1042 +    PUSHBUTTON      "Cancel",ID_CANCEL,99,111,50,14
747.1043 +    LTEXT           "Enter the rewind interval (0.2 ... 600) in seconds:",IDC_STATIC,7,7,174,8
747.1044 +    LTEXT           "Or enter 0 to disable rewind.",IDC_STATIC,7,15,174,8
747.1045 +    EDITTEXT        IDC_REWINDSLOTS,7,66,174,14,ES_AUTOHSCROLL
747.1046 +    LTEXT           "Enter number of rewind slots (1...256)",IDC_STATIC,7,46,174,8
747.1047 +    LTEXT           "Or enter 0 to disable rewind.",IDC_STATIC,7,55,174,8
747.1048 +    LTEXT           "If enabled, File->Rewind will rewind the state by <interval> seconds, as many as <slots> intervals back.",IDC_STATIC,7,87,173,17
747.1049 +END
747.1050 +
747.1051 +IDD_IO_VIEWER DIALOG 0, 0, 269, 238
747.1052 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
747.1053 +CAPTION "I/O Viewer"
747.1054 +FONT 8, "MS Sans Serif"
747.1055 +BEGIN
747.1056 +    COMBOBOX        IDC_ADDRESSES,7,7,255,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
747.1057 +    RTEXT           "",IDC_VALUE,103,23,159,8
747.1058 +    CONTROL         "",IDC_BIT_15,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,34,255,10
747.1059 +    CONTROL         "",IDC_BIT_14,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,44,255,10
747.1060 +    CONTROL         "",IDC_BIT_13,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,54,255,8
747.1061 +    CONTROL         "",IDC_BIT_12,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,64,255,10
747.1062 +    CONTROL         "",IDC_BIT_11,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,74,255,10
747.1063 +    CONTROL         "",IDC_BIT_10,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,84,255,10
747.1064 +    CONTROL         "",IDC_BIT_9,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,94,255,10
747.1065 +    CONTROL         "",IDC_BIT_8,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,104,255,10
747.1066 +    CONTROL         "",IDC_BIT_7,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,114,255,10
747.1067 +    CONTROL         "",IDC_BIT_6,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,124,255,10
747.1068 +    CONTROL         "",IDC_BIT_5,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,134,255,10
747.1069 +    CONTROL         "",IDC_BIT_4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,144,255,10
747.1070 +    CONTROL         "",IDC_BIT_3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,154,255,10
747.1071 +    CONTROL         "",IDC_BIT_2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,164,255,10
747.1072 +    CONTROL         "",IDC_BIT_1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,174,255,10
747.1073 +    CONTROL         "",IDC_BIT_0,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,184,255,10
747.1074 +    CONTROL         "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,201,71,10
747.1075 +    DEFPUSHBUTTON   "&Refresh",IDC_REFRESH,54,221,50,14
747.1076 +    DEFPUSHBUTTON   "&Apply",IDC_APPLY,110,221,50,14
747.1077 +    PUSHBUTTON      "&Close",IDC_CLOSE,166,221,50,14
747.1078 +    LTEXT           "Value:",IDC_STATIC,7,23,72,8
747.1079 +END
747.1080 +
747.1081 +IDD_MAX_SCALE DIALOG 0, 0, 186, 68
747.1082 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
747.1083 +CAPTION "Fullscreen scale"
747.1084 +FONT 8, "MS Sans Serif"
747.1085 +BEGIN
747.1086 +    EDITTEXT        IDC_VALUE,7,28,172,14,ES_AUTOHSCROLL
747.1087 +    DEFPUSHBUTTON   "OK",ID_OK,37,47,50,14
747.1088 +    PUSHBUTTON      "Cancel",ID_CANCEL,99,47,50,14
747.1089 +    LTEXT           "Enter the maxium fullscreen scale:",IDC_STATIC,7,7,172,8
747.1090 +    LTEXT           "Enter 0 to use maximum scale.",IDC_STATIC,7,17,172,8
747.1091 +END
747.1092 +
747.1093 +IDD_BUG_REPORT DIALOG 0, 0, 296, 186
747.1094 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
747.1095 +CAPTION "Bug Report"
747.1096 +FONT 8, "MS Sans Serif"
747.1097 +BEGIN
747.1098 +    PUSHBUTTON      "&OK",ID_OK,157,165,50,14
747.1099 +    EDITTEXT        IDC_BUG_REPORT,11,22,278,131,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL
747.1100 +    LTEXT           "Bug report data:",IDC_STATIC,7,7,282,8
747.1101 +    DEFPUSHBUTTON   "&Copy",IDC_COPY,87,164,50,14
747.1102 +END
747.1103 +
747.1104 +IDD_MOVIECREATE DIALOGEX 0, 0, 320, 168
747.1105 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
747.1106 +CAPTION "Record Movie"
747.1107 +FONT 8, "MS Sans Serif", 0, 0, 0x1
747.1108 +BEGIN
747.1109 +    DEFPUSHBUTTON   "OK",IDOK,193,147,50,14
747.1110 +    PUSHBUTTON      "Cancel",IDCANCEL,256,147,50,14
747.1111 +    EDITTEXT        IDC_MOVIE_FILENAME,7,18,250,13,ES_AUTOHSCROLL
747.1112 +    LTEXT           "Movie File",-1,7,7,33,8
747.1113 +    PUSHBUTTON      "&Browse...",IDC_BROWSE,264,17,48,14
747.1114 +    EDITTEXT        IDC_EDIT_AUTHOR,57,35,200,14,ES_AUTOHSCROLL
747.1115 +    LTEXT           "Author:",-1,7,38,43,8,0,WS_EX_RIGHT
747.1116 +    EDITTEXT        IDC_EDIT_DESCRIPTION,57,52,255,14,ES_AUTOHSCROLL
747.1117 +    LTEXT           "Description:",-1,7,55,43,8,0,WS_EX_RIGHT
747.1118 +    GROUPBOX        "Game System",-1,116,74,85,64
747.1119 +    CONTROL         "Game Boy Advance",IDC_REC_GBA,"Button",BS_AUTORADIOBUTTON | WS_GROUP,119,86,79,10
747.1120 +    CONTROL         "Game Boy Color",IDC_REC_GBC,"Button",BS_AUTORADIOBUTTON,119,99,67,10
747.1121 +    CONTROL         "Super Game Boy",IDC_REC_SGB,"Button",BS_AUTORADIOBUTTON,119,112,69,10
747.1122 +    CONTROL         "Game Boy",IDC_REC_GB,"Button",BS_AUTORADIOBUTTON,119,124,49,10
747.1123 +    GROUPBOX        "Bios Settings",-1,214,74,86,64
747.1124 +    GROUPBOX        "Record Options",-1,18,74,85,64
747.1125 +    CONTROL         "From now (snapshot)",IDC_RECNOW,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,21,118,77,10
747.1126 +    CONTROL         "From reset (SRAM)",IDC_RECRESET,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,21,104,75,10
747.1127 +    CONTROL         "From start (power-on)",IDC_RECSTART,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,21,90,78,10
747.1128 +    CONTROL         "No BIOS",IDC_REC_NOBIOS,"Button",BS_AUTORADIOBUTTON | WS_GROUP,218,86,44,10
747.1129 +    CONTROL         "Emulator's BIOS",IDC_REC_EMUBIOS,"Button",BS_AUTORADIOBUTTON,218,99,67,10
747.1130 +    CONTROL         "GBA BIOS",IDC_REC_GBABIOS,"Button",BS_AUTORADIOBUTTON,218,112,49,10
747.1131 +    CONTROL         "GBA BIOS with intro",IDC_REC_GBABIOSINTRO,"Button",BS_AUTORADIOBUTTON,218,124,79,10
747.1132 +END
747.1133 +
747.1134 +IDD_MOVIEOPEN DIALOGEX 0, 0, 320, 240
747.1135 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
747.1136 +CAPTION "Play Movie"
747.1137 +FONT 8, "MS Sans Serif", 0, 0, 0x0
747.1138 +BEGIN
747.1139 +    DEFPUSHBUTTON   "OK",IDOK,196,214,50,14
747.1140 +    PUSHBUTTON      "Cancel",IDCANCEL,255,214,50,14
747.1141 +    EDITTEXT        IDC_MOVIE_FILENAME,7,18,250,13,ES_AUTOHSCROLL
747.1142 +    LTEXT           "Movie File",-1,7,7,33,8
747.1143 +    PUSHBUTTON      "&Browse...",IDC_BROWSE,265,17,48,14
747.1144 +    LTEXT           "Recording Date:",-1,12,87,53,8
747.1145 +    LTEXT           "Length:",-1,40,99,25,8
747.1146 +    LTEXT           "Frames:",-1,40,111,26,8
747.1147 +    LTEXT           "Re-record Count:",-1,10,123,55,8
747.1148 +    LTEXT           "DATE",IDC_LABEL_DATE,68,87,124,8
747.1149 +    LTEXT           "LENGTH",IDC_LABEL_LENGTH,68,99,93,8
747.1150 +    LTEXT           "FRAMES",IDC_LABEL_FRAMES,68,111,67,8
747.1151 +    LTEXT           "RERECORD",IDC_LABEL_RERECORD,68,123,46,8
747.1152 +    CONTROL         "Open Read-Only",IDC_READONLY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,189,7,70,10
747.1153 +    LTEXT           "Press OK to start playing the movie.\nNote that this will erase or overwrite your game's SRAM,\nand may change other emulator settings.",-1,8,209,177,24
747.1154 +    LTEXT           "Movie ROM: ...",IDC_LABEL_WARNING1,8,34,300,8
747.1155 +    LTEXT           "Your ROM: ...",IDC_LABEL_WARNING2,12,43,295,9,0,WS_EX_TRANSPARENT
747.1156 +    EDITTEXT        IDC_EDIT_AUTHOR,57,54,200,12,ES_AUTOHSCROLL | ES_READONLY
747.1157 +    LTEXT           "Author:",-1,7,56,43,8,0,WS_EX_RIGHT
747.1158 +    EDITTEXT        IDC_EDIT_DESCRIPTION,57,68,255,12,ES_AUTOHSCROLL
747.1159 +    LTEXT           "Description:",-1,7,69,43,8,0,WS_EX_RIGHT
747.1160 +    GROUPBOX        "Game System",-1,112,137,85,64
747.1161 +    RADIOBUTTON     "Game Boy Advance",IDC_REC_GBA,116,149,79,10,WS_DISABLED | WS_GROUP
747.1162 +    RADIOBUTTON     "Game Boy Color",IDC_REC_GBC,116,162,67,10,WS_DISABLED
747.1163 +    RADIOBUTTON     "Super Game Boy",IDC_REC_SGB,116,175,69,10,WS_DISABLED
747.1164 +    RADIOBUTTON     "Game Boy",IDC_REC_GB,116,187,49,10,WS_DISABLED
747.1165 +    GROUPBOX        "Record Options",-1,18,137,77,64
747.1166 +    RADIOBUTTON     "From snapshot",IDC_RECNOW,22,180,62,10,WS_DISABLED | WS_GROUP | WS_TABSTOP
747.1167 +    RADIOBUTTON     "From reset/SRAM",IDC_RECRESET,22,167,70,10,WS_DISABLED | WS_TABSTOP
747.1168 +    RADIOBUTTON     "From power-on",IDC_RECSTART,22,153,63,10,WS_DISABLED | WS_TABSTOP
747.1169 +    RADIOBUTTON     "No BIOS",IDC_REC_NOBIOS,219,149,44,10,WS_DISABLED | WS_GROUP
747.1170 +    RADIOBUTTON     "Emulator's BIOS",IDC_REC_EMUBIOS,219,162,67,10,WS_DISABLED
747.1171 +    RADIOBUTTON     "GBA BIOS",IDC_REC_GBABIOS,219,175,49,10,WS_DISABLED
747.1172 +    RADIOBUTTON     "GBA BIOS with intro",IDC_REC_GBABIOSINTRO,219,187,79,10,WS_DISABLED
747.1173 +    GROUPBOX        "Bios Settings",-1,214,137,86,64
747.1174 +    PUSHBUTTON      "&Refresh",IDC_MOVIE_REFRESH,265,3,48,14
747.1175 +    EDITTEXT        IDC_EDIT_PAUSEFRAME,254,109,45,12,ES_AUTOHSCROLL
747.1176 +    CONTROL         "Pause at frame:",IDC_CHECK_PAUSEFRAME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,189,110,63,10
747.1177 +    CONTROL         "Hide SGB Border",IDC_CHECK_HIDEBORDER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,116,123,70,10
747.1178 +END
747.1179 +
747.1180 +IDD_TEXTCONFIG DIALOGEX 0, 0, 139, 120
747.1181 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
747.1182 +CAPTION "Text Options"
747.1183 +FONT 8, "MS Shell Dlg", 400, 0, 0x1
747.1184 +BEGIN
747.1185 +    DEFPUSHBUTTON   "OK",IDOK,69,99,63,14
747.1186 +    PUSHBUTTON      "Cancel",IDCANCEL,7,99,53,14
747.1187 +    GROUPBOX        "Color",IDC_STATIC,7,7,54,86
747.1188 +    CONTROL         "White",IDC_RADIO_WHITE,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,16,35,8
747.1189 +    CONTROL         "Red",IDC_RADIO_RED,"Button",BS_AUTORADIOBUTTON,13,25,29,8
747.1190 +    CONTROL         "Yellow",IDC_RADIO_YELLOW,"Button",BS_AUTORADIOBUTTON,13,34,36,9
747.1191 +    CONTROL         "Green",IDC_RADIO_GREEN,"Button",BS_AUTORADIOBUTTON,13,43,35,9
747.1192 +    CONTROL         "Cyan",IDC_RADIO_CYAN,"Button",BS_AUTORADIOBUTTON,13,53,33,8
747.1193 +    CONTROL         "Blue",IDC_RADIO_BLUE,"Button",BS_AUTORADIOBUTTON,13,63,29,8
747.1194 +    CONTROL         "Magenta",IDC_RADIO_MAGENTA,"Button",BS_AUTORADIOBUTTON,13,72,44,8
747.1195 +    CONTROL         "Black",IDC_RADIO_BLACK,"Button",BS_AUTORADIOBUTTON,13,82,32,8
747.1196 +    CONTROL         "Outlined",IDC_CHECK_OUTLINED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,74,17,43,10
747.1197 +    CONTROL         "Transparent",IDC_CHECK_TRANSPARENT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,74,28,55,10
747.1198 +    GROUPBOX        "Mode",IDC_STATIC,69,7,63,36
747.1199 +    GROUPBOX        "Display",IDC_STATIC,69,48,63,45
747.1200 +    CONTROL         "In Game",IDC_RADIO_PREFILTER,"Button",BS_AUTORADIOBUTTON | WS_GROUP,73,58,43,10
747.1201 +    CONTROL         "On Game",IDC_RADIO_POSTFILTER,"Button",BS_AUTORADIOBUTTON,73,69,45,10
747.1202 +    CONTROL         "On Screen",IDC_RADIO_POSTRENDER,"Button",BS_AUTORADIOBUTTON,73,80,49,10
747.1203 +END
747.1204 +
747.1205 +IDD_LUA DIALOGEX 0, 0, 270, 150
747.1206 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_POPUP | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
747.1207 +CAPTION "Lua Script"
747.1208 +MENU LUAWINDOW_MENU
747.1209 +FONT 8, "MS Shell Dlg", 400, 0, 0x1
747.1210 +BEGIN
747.1211 +    PUSHBUTTON      "Browse...",IDC_BUTTON_LUABROWSE,7,31,48,16
747.1212 +    PUSHBUTTON      "Run",IDC_BUTTON_LUARUN,213,31,50,16
747.1213 +    PUSHBUTTON      "Stop",IDC_BUTTON_LUASTOP,160,31,50,16
747.1214 +    EDITTEXT        IDC_EDIT_LUAPATH,7,16,256,14,ES_AUTOHSCROLL
747.1215 +    EDITTEXT        IDC_LUACONSOLE,7,61,256,81,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | WS_VSCROLL
747.1216 +    LTEXT           "Output Console",IDC_STATIC,7,51,51,8
747.1217 +    LTEXT           "Script File",IDC_STATIC,7,7,32,8
747.1218 +    PUSHBUTTON      "Edit",IDC_BUTTON_LUAEDIT,58,31,46,16
747.1219 +END
747.1220 +
747.1221 +IDD_RAMSEARCH DIALOGEX 0, 0, 287, 292
747.1222 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
747.1223 +CAPTION " RAM Search"
747.1224 +FONT 8, "MS Shell Dlg", 400, 0, 0x1
747.1225 +BEGIN
747.1226 +    CONTROL         "",IDC_RAMLIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP,9,9,214,151,WS_EX_CLIENTEDGE
747.1227 +    PUSHBUTTON      "&Search",IDC_C_SEARCH,226,9,52,16
747.1228 +    PUSHBUTTON      "&Add Cheat",IDC_C_ADDCHEAT,226,145,52,16
747.1229 +    PUSHBUTTON      "&Watch",IDC_C_WATCH,226,127,52,16
747.1230 +    PUSHBUTTON      "&Reset",IDC_C_RESET,226,27,52,16
747.1231 +    PUSHBUTTON      "&Eliminate",IDC_C_ELIMINATE,226,109,52,16
747.1232 +    GROUPBOX        "Comparison Operator",IDC_STATIC,10,166,102,118,0,WS_EX_TRANSPARENT
747.1233 +    CONTROL         "Less Than",IDC_LESSTHAN,"Button",BS_AUTORADIOBUTTON | WS_GROUP,14,178,95,11
747.1234 +    CONTROL         "Greater Than",IDC_MORETHAN,"Button",BS_AUTORADIOBUTTON,14,191,95,11
747.1235 +    CONTROL         "Less Than or Equal To",IDC_NOMORETHAN,"Button",BS_AUTORADIOBUTTON,14,204,95,11
747.1236 +    CONTROL         "Greater Than or Equal To",IDC_NOLESSTHAN,"Button",BS_AUTORADIOBUTTON,14,217,95,11
747.1237 +    CONTROL         "Equal To",IDC_EQUALTO,"Button",BS_AUTORADIOBUTTON,14,230,95,11
747.1238 +    CONTROL         "Not Equal To",IDC_DIFFERENTFROM,"Button",BS_AUTORADIOBUTTON,14,243,95,11
747.1239 +    CONTROL         "Different By:",IDC_DIFFERENTBY,"Button",BS_AUTORADIOBUTTON,14,256,52,11
747.1240 +    CONTROL         "Modulo",IDC_MODULO,"Button",BS_AUTORADIOBUTTON,14,269,35,11
747.1241 +    EDITTEXT        IDC_EDIT_DIFFBY,69,255,38,12,ES_UPPERCASE | ES_AUTOHSCROLL | WS_DISABLED
747.1242 +    EDITTEXT        IDC_EDIT_MODBY,51,267,38,12,ES_UPPERCASE | ES_AUTOHSCROLL | WS_DISABLED
747.1243 +    GROUPBOX        "Compare To / By",IDC_STATIC,118,166,153,58,0,WS_EX_TRANSPARENT
747.1244 +    CONTROL         "Previous Value",IDC_PREVIOUSVALUE,"Button",BS_AUTORADIOBUTTON | WS_GROUP,121,176,67,10
747.1245 +    CONTROL         "Specific Value:",IDC_SPECIFICVALUE,"Button",BS_AUTORADIOBUTTON,121,187,67,10
747.1246 +    CONTROL         "Specific Address:",IDC_SPECIFICADDRESS,"Button",BS_AUTORADIOBUTTON,121,198,67,10
747.1247 +    CONTROL         "Number of Changes:",IDC_NUMBEROFCHANGES,"Button",BS_AUTORADIOBUTTON,121,209,76,10
747.1248 +    EDITTEXT        IDC_EDIT_COMPAREVALUE,203,183,63,12,ES_UPPERCASE | ES_AUTOHSCROLL | WS_DISABLED
747.1249 +    EDITTEXT        IDC_EDIT_COMPAREADDRESS,203,195,63,12,ES_UPPERCASE | ES_AUTOHSCROLL | WS_DISABLED
747.1250 +    EDITTEXT        IDC_EDIT_COMPARECHANGES,203,207,63,12,ES_UPPERCASE | ES_AUTOHSCROLL | WS_DISABLED
747.1251 +    GROUPBOX        "Data Type / Display",IDC_STATIC,196,227,75,44,0,WS_EX_TRANSPARENT
747.1252 +    CONTROL         "Signed",IDC_SIGNED,"Button",BS_AUTORADIOBUTTON | WS_GROUP,200,237,67,8
747.1253 +    CONTROL         "Unsigned",IDC_UNSIGNED,"Button",BS_AUTORADIOBUTTON,200,248,67,8
747.1254 +    CONTROL         "Hexadecimal",IDC_HEX,"Button",BS_AUTORADIOBUTTON,200,259,67,8
747.1255 +    CONTROL         "Autosearch",IDC_C_AUTOSEARCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,200,273,52,11
747.1256 +    GROUPBOX        "Data Size",IDC_STATIC,117,227,73,57,0,WS_EX_TRANSPARENT
747.1257 +    CONTROL         "1 byte",IDC_1_BYTE,"Button",BS_AUTORADIOBUTTON | WS_GROUP,121,237,61,11
747.1258 +    CONTROL         "2 bytes",IDC_2_BYTES,"Button",BS_AUTORADIOBUTTON,121,248,61,11
747.1259 +    CONTROL         "4 bytes",IDC_4_BYTES,"Button",BS_AUTORADIOBUTTON,121,259,61,11
747.1260 +    CONTROL         "Check Misaligned",IDC_MISALIGN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,121,272,65,8
747.1261 +    PUSHBUTTON      "&Clear Change Counts",IDC_C_RESET_CHANGES,226,46,52,20,BS_MULTILINE
747.1262 +    PUSHBUTTON      "&Undo",IDC_C_UNDO,226,69,52,16,WS_DISABLED
747.1263 +    LTEXT           "Is",IDC_STATIC,92,270,12,8
747.1264 +END
747.1265 +
747.1266 +IDD_EDITWATCH DIALOGEX 0, 0, 181, 95
747.1267 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
747.1268 +CAPTION " Edit Watch"
747.1269 +FONT 8, "MS Shell Dlg", 400, 0, 0x1
747.1270 +BEGIN
747.1271 +    CTEXT           "Address:",IDC_SPECIFICADDRESS,18,12,35,10
747.1272 +    EDITTEXT        IDC_EDIT_COMPAREADDRESS,55,10,65,12,ES_UPPERCASE | ES_AUTOHSCROLL
747.1273 +    CTEXT           "Notes:",IDC_PROMPT_TEXT,18,24,45,10
747.1274 +    EDITTEXT        IDC_PROMPT_EDIT,55,22,65,12,ES_AUTOHSCROLL
747.1275 +    GROUPBOX        "Data Type",IDC_STATIC,14,37,75,42,0,WS_EX_TRANSPARENT
747.1276 +    CONTROL         "&Signed",IDC_SIGNED,"Button",BS_AUTORADIOBUTTON | WS_GROUP,18,47,67,8
747.1277 +    CONTROL         "&Unsigned",IDC_UNSIGNED,"Button",BS_AUTORADIOBUTTON,18,57,67,8
747.1278 +    CONTROL         "&Hexadecimal",IDC_HEX,"Button",BS_AUTORADIOBUTTON,18,67,67,8
747.1279 +    GROUPBOX        "Data Size",IDC_STATIC,94,37,73,42,0,WS_EX_TRANSPARENT
747.1280 +    CONTROL         "&1 byte",IDC_1_BYTE,"Button",BS_AUTORADIOBUTTON | WS_GROUP,98,47,61,11
747.1281 +    CONTROL         "&2 bytes",IDC_2_BYTES,"Button",BS_AUTORADIOBUTTON,98,57,61,11
747.1282 +    CONTROL         "&4 bytes",IDC_4_BYTES,"Button",BS_AUTORADIOBUTTON,98,67,61,11
747.1283 +    DEFPUSHBUTTON   "&OK",IDOK,66,80,50,14
747.1284 +    PUSHBUTTON      "&Cancel",ID_CANCEL,120,80,50,14
747.1285 +END
747.1286 +
747.1287 +IDD_RAMWATCH DIALOGEX 0, 0, 269, 242
747.1288 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
747.1289 +CAPTION " RAM Watch"
747.1290 +MENU RAMWATCH_MENU
747.1291 +FONT 8, "MS Shell Dlg", 400, 0, 0x1
747.1292 +BEGIN
747.1293 +    CONTROL         "",IDC_WATCHLIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP,9,9,210,222,WS_EX_CLIENTEDGE
747.1294 +    PUSHBUTTON      "&Edit",IDC_C_WATCH_EDIT,226,66,34,14
747.1295 +    PUSHBUTTON      "&Remove",IDC_C_WATCH_REMOVE,226,83,34,14
747.1296 +    PUSHBUTTON      "&New",IDC_C_WATCH,226,100,34,14
747.1297 +    PUSHBUTTON      "Duplic&ate",IDC_C_WATCH_DUPLICATE,226,117,34,14
747.1298 +    PUSHBUTTON      "Add &Cheat",IDC_C_ADDCHEAT,222,156,42,16
747.1299 +    GROUPBOX        "Watches",IDC_STATIC,222,11,42,144
747.1300 +    CONTROL         "",ID_WATCHES_UPDOWN,"msctls_updown32",WS_TABSTOP,232,23,19,36
747.1301 +    PUSHBUTTON      "Separator",IDC_C_WATCH_SEPARATE,225,135,36,14
747.1302 +END
747.1303 +
747.1304 +IDD_PROMPT DIALOGEX 0, 0, 190, 70
747.1305 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
747.1306 +CAPTION "Input Prompt"
747.1307 +FONT 8, "MS Sans Serif", 0, 0, 0x0
747.1308 +BEGIN
747.1309 +    EDITTEXT        IDC_PROMPT_EDIT,10,30,170,15,ES_AUTOHSCROLL
747.1310 +    DEFPUSHBUTTON   "OK",IDOK,100,50,50,15
747.1311 +    PUSHBUTTON      "Cancel",ID_CANCEL,40,50,50,15
747.1312 +    CTEXT           "",IDC_PROMPT_TEXT,0,3,190,8,SS_CENTERIMAGE
747.1313 +    CTEXT           "",IDC_PROMPT_TEXT2,0,15,190,8,SS_CENTERIMAGE
747.1314 +END
747.1315 +
747.1316 +
747.1317 +/////////////////////////////////////////////////////////////////////////////
747.1318 +//
747.1319 +// DESIGNINFO
747.1320 +//
747.1321 +
747.1322 +#ifdef APSTUDIO_INVOKED
747.1323 +GUIDELINES DESIGNINFO
747.1324 +BEGIN
747.1325 +    IDD_OPENDLG, DIALOG
747.1326 +    BEGIN
747.1327 +        RIGHTMARGIN, 165
747.1328 +    END
747.1329 +
747.1330 +    IDD_ABOUT, DIALOG
747.1331 +    BEGIN
747.1332 +        LEFTMARGIN, 7
747.1333 +        RIGHTMARGIN, 157
747.1334 +        TOPMARGIN, 7
747.1335 +        BOTTOMMARGIN, 94
747.1336 +    END
747.1337 +
747.1338 +    IDD_DIRECTORIES, DIALOG
747.1339 +    BEGIN
747.1340 +        LEFTMARGIN, 7
747.1341 +        RIGHTMARGIN, 277
747.1342 +        TOPMARGIN, 7
747.1343 +        BOTTOMMARGIN, 233
747.1344 +    END
747.1345 +
747.1346 +    IDD_CONFIG, DIALOG
747.1347 +    BEGIN
747.1348 +        LEFTMARGIN, 7
747.1349 +        RIGHTMARGIN, 128
747.1350 +        TOPMARGIN, 7
747.1351 +        BOTTOMMARGIN, 204
747.1352 +    END
747.1353 +
747.1354 +    IDD_CHEATS, DIALOG
747.1355 +    BEGIN
747.1356 +        LEFTMARGIN, 7
747.1357 +        RIGHTMARGIN, 269
747.1358 +        TOPMARGIN, 7
747.1359 +        BOTTOMMARGIN, 246
747.1360 +    END
747.1361 +
747.1362 +    IDD_ADD_CHEAT, DIALOG
747.1363 +    BEGIN
747.1364 +        LEFTMARGIN, 7
747.1365 +        RIGHTMARGIN, 179
747.1366 +        TOPMARGIN, 7
747.1367 +        BOTTOMMARGIN, 130
747.1368 +    END
747.1369 +
747.1370 +    IDD_CHEAT_LIST, DIALOG
747.1371 +    BEGIN
747.1372 +        LEFTMARGIN, 7
747.1373 +        RIGHTMARGIN, 273
747.1374 +        TOPMARGIN, 7
747.1375 +        BOTTOMMARGIN, 243
747.1376 +    END
747.1377 +
747.1378 +    IDD_ASSOCIATIONS, DIALOG
747.1379 +    BEGIN
747.1380 +        LEFTMARGIN, 7
747.1381 +        RIGHTMARGIN, 109
747.1382 +        TOPMARGIN, 7
747.1383 +        BOTTOMMARGIN, 88
747.1384 +    END
747.1385 +
747.1386 +    IDD_GBA_ROM_INFO, DIALOG
747.1387 +    BEGIN
747.1388 +        LEFTMARGIN, 7
747.1389 +        RIGHTMARGIN, 213
747.1390 +        TOPMARGIN, 7
747.1391 +        BOTTOMMARGIN, 135
747.1392 +    END
747.1393 +
747.1394 +    IDD_GB_ROM_INFO, DIALOG
747.1395 +    BEGIN
747.1396 +        LEFTMARGIN, 7
747.1397 +        RIGHTMARGIN, 213
747.1398 +        TOPMARGIN, 7
747.1399 +        BOTTOMMARGIN, 218
747.1400 +    END
747.1401 +
747.1402 +    IDD_GB_CHEAT_LIST, DIALOG
747.1403 +    BEGIN
747.1404 +        LEFTMARGIN, 7
747.1405 +        RIGHTMARGIN, 279
747.1406 +        TOPMARGIN, 7
747.1407 +        BOTTOMMARGIN, 214
747.1408 +    END
747.1409 +
747.1410 +    IDD_ADD_CHEAT_DLG, DIALOG
747.1411 +    BEGIN
747.1412 +        LEFTMARGIN, 7
747.1413 +        RIGHTMARGIN, 175
747.1414 +        TOPMARGIN, 7
747.1415 +        BOTTOMMARGIN, 100
747.1416 +    END
747.1417 +
747.1418 +    IDD_GB_PRINTER, DIALOG
747.1419 +    BEGIN
747.1420 +        LEFTMARGIN, 7
747.1421 +        RIGHTMARGIN, 171
747.1422 +        TOPMARGIN, 7
747.1423 +        BOTTOMMARGIN, 202
747.1424 +    END
747.1425 +
747.1426 +    IDD_MOTION_CONFIG, DIALOG
747.1427 +    BEGIN
747.1428 +        LEFTMARGIN, 7
747.1429 +        RIGHTMARGIN, 128
747.1430 +        TOPMARGIN, 7
747.1431 +        BOTTOMMARGIN, 71
747.1432 +    END
747.1433 +
747.1434 +    IDD_LANG_SELECT, DIALOG
747.1435 +    BEGIN
747.1436 +        LEFTMARGIN, 7
747.1437 +        RIGHTMARGIN, 179
747.1438 +        TOPMARGIN, 7
747.1439 +        BOTTOMMARGIN, 61
747.1440 +    END
747.1441 +
747.1442 +    IDD_CODE_SELECT, DIALOG
747.1443 +    BEGIN
747.1444 +        LEFTMARGIN, 7
747.1445 +        RIGHTMARGIN, 309
747.1446 +        TOPMARGIN, 7
747.1447 +        BOTTOMMARGIN, 228
747.1448 +    END
747.1449 +
747.1450 +    IDD_MAP_VIEW, DIALOG
747.1451 +    BEGIN
747.1452 +        LEFTMARGIN, 7
747.1453 +        RIGHTMARGIN, 315
747.1454 +        TOPMARGIN, 7
747.1455 +        BOTTOMMARGIN, 231
747.1456 +    END
747.1457 +
747.1458 +    IDD_PALETTE_VIEW, DIALOG
747.1459 +    BEGIN
747.1460 +        LEFTMARGIN, 7
747.1461 +        RIGHTMARGIN, 309
747.1462 +        TOPMARGIN, 7
747.1463 +        BOTTOMMARGIN, 259
747.1464 +    END
747.1465 +
747.1466 +    IDD_MEM_VIEWER, DIALOG
747.1467 +    BEGIN
747.1468 +        LEFTMARGIN, 7
747.1469 +        RIGHTMARGIN, 373
747.1470 +        TOPMARGIN, 7
747.1471 +        BOTTOMMARGIN, 171
747.1472 +    END
747.1473 +
747.1474 +    IDD_OAM_VIEW, DIALOG
747.1475 +    BEGIN
747.1476 +        LEFTMARGIN, 7
747.1477 +        RIGHTMARGIN, 227
747.1478 +        TOPMARGIN, 7
747.1479 +        BOTTOMMARGIN, 178
747.1480 +    END
747.1481 +
747.1482 +    IDD_ACCEL_EDITOR, DIALOG
747.1483 +    BEGIN
747.1484 +        LEFTMARGIN, 7
747.1485 +        RIGHTMARGIN, 313
747.1486 +        TOPMARGIN, 7
747.1487 +        BOTTOMMARGIN, 172
747.1488 +    END
747.1489 +
747.1490 +    IDD_TILE_VIEWER, DIALOG
747.1491 +    BEGIN
747.1492 +        LEFTMARGIN, 7
747.1493 +        RIGHTMARGIN, 319
747.1494 +        TOPMARGIN, 7
747.1495 +        BOTTOMMARGIN, 259
747.1496 +    END
747.1497 +
747.1498 +    IDD_GB_COLORS, DIALOG
747.1499 +    BEGIN
747.1500 +        LEFTMARGIN, 7
747.1501 +        RIGHTMARGIN, 162
747.1502 +        TOPMARGIN, 7
747.1503 +        BOTTOMMARGIN, 114
747.1504 +    END
747.1505 +
747.1506 +    IDD_DISASSEMBLE, DIALOG
747.1507 +    BEGIN
747.1508 +        LEFTMARGIN, 7
747.1509 +        RIGHTMARGIN, 396
747.1510 +        TOPMARGIN, 7
747.1511 +        BOTTOMMARGIN, 218
747.1512 +    END
747.1513 +
747.1514 +    IDD_GDB_PORT, DIALOG
747.1515 +    BEGIN
747.1516 +        LEFTMARGIN, 7
747.1517 +        RIGHTMARGIN, 179
747.1518 +        TOPMARGIN, 7
747.1519 +        BOTTOMMARGIN, 44
747.1520 +    END
747.1521 +
747.1522 +    IDD_GDB_WAITING, DIALOG
747.1523 +    BEGIN
747.1524 +        LEFTMARGIN, 7
747.1525 +        RIGHTMARGIN, 179
747.1526 +        TOPMARGIN, 7
747.1527 +        BOTTOMMARGIN, 37
747.1528 +    END
747.1529 +
747.1530 +    IDD_LOGGING, DIALOG
747.1531 +    BEGIN
747.1532 +        LEFTMARGIN, 7
747.1533 +        RIGHTMARGIN, 359
747.1534 +        TOPMARGIN, 7
747.1535 +        BOTTOMMARGIN, 211
747.1536 +    END
747.1537 +
747.1538 +    IDD_EXPORT_SPS, DIALOG
747.1539 +    BEGIN
747.1540 +        LEFTMARGIN, 7
747.1541 +        RIGHTMARGIN, 241
747.1542 +        TOPMARGIN, 7
747.1543 +        BOTTOMMARGIN, 141
747.1544 +    END
747.1545 +
747.1546 +    IDD_ADDR_SIZE, DIALOG
747.1547 +    BEGIN
747.1548 +        LEFTMARGIN, 7
747.1549 +        RIGHTMARGIN, 179
747.1550 +        TOPMARGIN, 7
747.1551 +        BOTTOMMARGIN, 60
747.1552 +    END
747.1553 +
747.1554 +    IDD_MODES, DIALOG
747.1555 +    BEGIN
747.1556 +        LEFTMARGIN, 7
747.1557 +        RIGHTMARGIN, 201
747.1558 +        TOPMARGIN, 7
747.1559 +        BOTTOMMARGIN, 122
747.1560 +    END
747.1561 +
747.1562 +    IDD_DRIVERS, DIALOG
747.1563 +    BEGIN
747.1564 +        LEFTMARGIN, 7
747.1565 +        RIGHTMARGIN, 201
747.1566 +        TOPMARGIN, 7
747.1567 +        BOTTOMMARGIN, 114
747.1568 +    END
747.1569 +
747.1570 +    IDD_THROTTLE, DIALOG
747.1571 +    BEGIN
747.1572 +        LEFTMARGIN, 7
747.1573 +        RIGHTMARGIN, 179
747.1574 +        TOPMARGIN, 7
747.1575 +        BOTTOMMARGIN, 56
747.1576 +    END
747.1577 +
747.1578 +    IDD_GB_DISASSEMBLE, DIALOG
747.1579 +    BEGIN
747.1580 +        LEFTMARGIN, 7
747.1581 +        RIGHTMARGIN, 337
747.1582 +        TOPMARGIN, 7
747.1583 +        BOTTOMMARGIN, 218
747.1584 +    END
747.1585 +
747.1586 +    IDD_GB_OAM_VIEW, DIALOG
747.1587 +    BEGIN
747.1588 +        LEFTMARGIN, 7
747.1589 +        RIGHTMARGIN, 227
747.1590 +        TOPMARGIN, 7
747.1591 +        BOTTOMMARGIN, 178
747.1592 +    END
747.1593 +
747.1594 +    IDD_GB_TILE_VIEWER, DIALOG
747.1595 +    BEGIN
747.1596 +        LEFTMARGIN, 7
747.1597 +        RIGHTMARGIN, 319
747.1598 +        TOPMARGIN, 7
747.1599 +        BOTTOMMARGIN, 231
747.1600 +    END
747.1601 +
747.1602 +    IDD_GB_MAP_VIEW, DIALOG
747.1603 +    BEGIN
747.1604 +        LEFTMARGIN, 7
747.1605 +        RIGHTMARGIN, 315
747.1606 +        TOPMARGIN, 7
747.1607 +        BOTTOMMARGIN, 231
747.1608 +    END
747.1609 +
747.1610 +    IDD_GB_PALETTE_VIEW, DIALOG
747.1611 +    BEGIN
747.1612 +        LEFTMARGIN, 7
747.1613 +        RIGHTMARGIN, 189
747.1614 +        TOPMARGIN, 7
747.1615 +        BOTTOMMARGIN, 227
747.1616 +    END
747.1617 +
747.1618 +    IDD_MODE_CONFIRM, DIALOG
747.1619 +    BEGIN
747.1620 +        LEFTMARGIN, 7
747.1621 +        RIGHTMARGIN, 179
747.1622 +        TOPMARGIN, 7
747.1623 +        BOTTOMMARGIN, 50
747.1624 +    END
747.1625 +
747.1626 +    IDD_REWIND_INTERVAL, DIALOG
747.1627 +    BEGIN
747.1628 +        LEFTMARGIN, 7
747.1629 +        RIGHTMARGIN, 181
747.1630 +        TOPMARGIN, 7
747.1631 +        BOTTOMMARGIN, 125
747.1632 +    END
747.1633 +
747.1634 +    IDD_IO_VIEWER, DIALOG
747.1635 +    BEGIN
747.1636 +        LEFTMARGIN, 7
747.1637 +        RIGHTMARGIN, 262
747.1638 +        TOPMARGIN, 7
747.1639 +        BOTTOMMARGIN, 235
747.1640 +    END
747.1641 +
747.1642 +    IDD_MAX_SCALE, DIALOG
747.1643 +    BEGIN
747.1644 +        LEFTMARGIN, 7
747.1645 +        RIGHTMARGIN, 179
747.1646 +        TOPMARGIN, 7
747.1647 +        BOTTOMMARGIN, 61
747.1648 +    END
747.1649 +
747.1650 +    IDD_BUG_REPORT, DIALOG
747.1651 +    BEGIN
747.1652 +        LEFTMARGIN, 7
747.1653 +        RIGHTMARGIN, 289
747.1654 +        TOPMARGIN, 7
747.1655 +        BOTTOMMARGIN, 179
747.1656 +    END
747.1657 +
747.1658 +    IDD_MOVIECREATE, DIALOG
747.1659 +    BEGIN
747.1660 +        LEFTMARGIN, 7
747.1661 +        RIGHTMARGIN, 312
747.1662 +        TOPMARGIN, 7
747.1663 +        BOTTOMMARGIN, 161
747.1664 +    END
747.1665 +
747.1666 +    IDD_MOVIEOPEN, DIALOG
747.1667 +    BEGIN
747.1668 +        LEFTMARGIN, 7
747.1669 +        RIGHTMARGIN, 313
747.1670 +        TOPMARGIN, 7
747.1671 +        BOTTOMMARGIN, 235
747.1672 +    END
747.1673 +
747.1674 +    IDD_TEXTCONFIG, DIALOG
747.1675 +    BEGIN
747.1676 +        LEFTMARGIN, 7
747.1677 +        RIGHTMARGIN, 132
747.1678 +        TOPMARGIN, 7
747.1679 +        BOTTOMMARGIN, 113
747.1680 +    END
747.1681 +
747.1682 +    IDD_RAMSEARCH, DIALOG
747.1683 +    BEGIN
747.1684 +    END
747.1685 +END
747.1686 +#endif    // APSTUDIO_INVOKED
747.1687 +
747.1688 +
747.1689 +/////////////////////////////////////////////////////////////////////////////
747.1690 +//
747.1691 +// Menu
747.1692 +//
747.1693 +
747.1694 +IDR_MENU MENU
747.1695 +BEGIN
747.1696 +    POPUP "&File"
747.1697 +    BEGIN
747.1698 +        MENUITEM "&Open GBA ROM...",            ID_FILE_OPEN
747.1699 +        MENUITEM "Open &GBx ROM...",            ID_FILE_OPENGAMEBOY
747.1700 +        POPUP "Rece&nt ROM"
747.1701 +        BEGIN
747.1702 +            MENUITEM "&Clear",                      ID_FILE_RECENT_RESET
747.1703 +            MENUITEM "&Lock",                       ID_FILE_RECENT_FREEZE
747.1704 +            MENUITEM SEPARATOR
747.1705 +            MENUITEM "Open Recent ROM #&1",         ID_FILE_MRU_FILE1
747.1706 +            MENUITEM "Open Recent ROM #&2",         ID_FILE_MRU_FILE2
747.1707 +            MENUITEM "Open Recent ROM #&3",         ID_FILE_MRU_FILE3
747.1708 +            MENUITEM "Open Recent ROM #&4",         ID_FILE_MRU_FILE4
747.1709 +            MENUITEM "Open Recent ROM #&5",         ID_FILE_MRU_FILE5
747.1710 +            MENUITEM "Open Recent ROM #&6",         ID_FILE_MRU_FILE6
747.1711 +            MENUITEM "Open Recent ROM #&7",         ID_FILE_MRU_FILE7
747.1712 +            MENUITEM "Open Recent ROM #&8",         ID_FILE_MRU_FILE8
747.1713 +            MENUITEM "Open Recent ROM #&9",         ID_FILE_MRU_FILE9
747.1714 +            MENUITEM "Open Recent ROM #1&0",        ID_FILE_MRU_FILE10
747.1715 +        END
747.1716 +        MENUITEM SEPARATOR
747.1717 +        POPUP "&Load Game"
747.1718 +        BEGIN
747.1719 +            MENUITEM "&Current Slot",               ID_FILE_LOADGAME_CURRENT
747.1720 +            MENUITEM "Most &Recent Slot",           ID_FILE_LOADGAME_MOSTRECENT
747.1721 +            MENUITEM "Load From &File...",          ID_FILE_LOAD
747.1722 +            MENUITEM SEPARATOR
747.1723 +            MENUITEM "Import &Battery File...",     ID_FILE_IMPORT_BATTERYFILE
747.1724 +            MENUITEM "Import &Gameshark Snapshot...", ID_FILE_IMPORT_GAMESHARKSNAPSHOT
747.1725 +            MENUITEM SEPARATOR
747.1726 +            MENUITEM "Slot #&1",                    ID_FILE_LOADGAME_SLOT1
747.1727 +            MENUITEM "Slot #&2",                    ID_FILE_LOADGAME_SLOT2
747.1728 +            MENUITEM "Slot #&3",                    ID_FILE_LOADGAME_SLOT3
747.1729 +            MENUITEM "Slot #&4",                    ID_FILE_LOADGAME_SLOT4
747.1730 +            MENUITEM "Slot #&5",                    ID_FILE_LOADGAME_SLOT5
747.1731 +            MENUITEM "Slot #&6",                    ID_FILE_LOADGAME_SLOT6
747.1732 +            MENUITEM "Slot #&7",                    ID_FILE_LOADGAME_SLOT7
747.1733 +            MENUITEM "Slot #&8",                    ID_FILE_LOADGAME_SLOT8
747.1734 +            MENUITEM "Slot #&9",                    ID_FILE_LOADGAME_SLOT9
747.1735 +            MENUITEM "Slot #1&0",                   ID_FILE_LOADGAME_SLOT10
747.1736 +            MENUITEM SEPARATOR
747.1737 +            MENUITEM "&Make 'Current' On Load",     ID_FILE_LOADGAME_MAKECURRENT
747.1738 +            MENUITEM "Make 'Recent' On &Load",      ID_FILE_LOADGAME_MAKERECENT
747.1739 +            MENUITEM SEPARATOR
747.1740 +            MENUITEM "&Auto Load Most Recent On Start", ID_FILE_LOADGAME_AUTOLOADMOSTRECENT
747.1741 +        END
747.1742 +        POPUP "&Save Game"
747.1743 +        BEGIN
747.1744 +            MENUITEM "&Current Slot",               ID_FILE_SAVEGAME_CURRENT
747.1745 +            MENUITEM "&Oldest Slot",                ID_FILE_SAVEGAME_OLDESTSLOT
747.1746 +            MENUITEM "Save To &File...",            ID_FILE_SAVE
747.1747 +            MENUITEM SEPARATOR
747.1748 +            MENUITEM "Export &Battery File...",     ID_FILE_EXPORT_BATTERYFILE
747.1749 +            MENUITEM "Export &Gameshark Snapshot...", ID_FILE_EXPORT_GAMESHARKSNAPSHOT
747.1750 +            MENUITEM SEPARATOR
747.1751 +            MENUITEM "Slot #&1",                    ID_FILE_SAVEGAME_SLOT1
747.1752 +            MENUITEM "Slot #&2",                    ID_FILE_SAVEGAME_SLOT2
747.1753 +            MENUITEM "Slot #&3",                    ID_FILE_SAVEGAME_SLOT3
747.1754 +            MENUITEM "Slot #&4",                    ID_FILE_SAVEGAME_SLOT4
747.1755 +            MENUITEM "Slot #&5",                    ID_FILE_SAVEGAME_SLOT5
747.1756 +            MENUITEM "Slot #&6",                    ID_FILE_SAVEGAME_SLOT6
747.1757 +            MENUITEM "Slot #&7",                    ID_FILE_SAVEGAME_SLOT7
747.1758 +            MENUITEM "Slot #&8",                    ID_FILE_SAVEGAME_SLOT8
747.1759 +            MENUITEM "Slot #&9",                    ID_FILE_SAVEGAME_SLOT9
747.1760 +            MENUITEM "Slot #1&0",                   ID_FILE_SAVEGAME_SLOT10
747.1761 +            MENUITEM SEPARATOR
747.1762 +            MENUITEM "&Make 'Current' On Save",     ID_FILE_SAVEGAME_MAKECURRENT
747.1763 +        END
747.1764 +        POPUP "C&urrent Slot"
747.1765 +        BEGIN
747.1766 +            MENUITEM "&Increase Current Slot",      ID_FILE_SAVEGAME_INCREMENTSLOT
747.1767 +            MENUITEM "&Decrease Current Slot",      ID_FILE_SAVEGAME_DECREMENTSLOT
747.1768 +            MENUITEM SEPARATOR
747.1769 +            MENUITEM "Slot #&1",                    ID_SELECT_SLOT1
747.1770 +            MENUITEM "Slot #&2",                    ID_SELECT_SLOT2
747.1771 +            MENUITEM "Slot #&3",                    ID_SELECT_SLOT3
747.1772 +            MENUITEM "Slot #&4",                    ID_SELECT_SLOT4
747.1773 +            MENUITEM "Slot #&5",                    ID_SELECT_SLOT5
747.1774 +            MENUITEM "Slot #&6",                    ID_SELECT_SLOT6
747.1775 +            MENUITEM "Slot #&7",                    ID_SELECT_SLOT7
747.1776 +            MENUITEM "Slot #&8",                    ID_SELECT_SLOT8
747.1777 +            MENUITEM "Slot #&9",                    ID_SELECT_SLOT9
747.1778 +            MENUITEM "Slot #1&0",                   ID_SELECT_SLOT10
747.1779 +            MENUITEM SEPARATOR
747.1780 +            MENUITEM "Show &Timestamps",            ID_FILE_SLOT_DISPLAYMODIFICATIONTIME
747.1781 +        END
747.1782 +        MENUITEM SEPARATOR
747.1783 +        MENUITEM "&Pause",                      ID_FILE_PAUSE
747.1784 +        MENUITEM "&Frame Advance",              ID_DEBUG_NEXTFRAME
747.1785 +        MENUITEM "    &Account For Lag",        ID_DEBUG_NEXTFRAME_ACCOUNTFORLAG
747.1786 +        MENUITEM "Re&wind",                     ID_TOOLS_REWIND
747.1787 +        MENUITEM "Rewind Se&ttings...",         ID_OPTIONS_EMULATOR_REWINDINTERVAL
747.1788 +        MENUITEM SEPARATOR
747.1789 +        MENUITEM "&Reset",                      ID_FILE_RESET
747.1790 +        MENUITEM "&Close",                      ID_FILE_CLOSE
747.1791 +        MENUITEM SEPARATOR
747.1792 +        MENUITEM "Rom &Information...",         ID_FILE_ROMINFORMATION
747.1793 +        MENUITEM SEPARATOR
747.1794 +        MENUITEM "E&xit",                       ID_FILE_EXIT
747.1795 +    END
747.1796 +    POPUP "&Options"
747.1797 +    BEGIN
747.1798 +        POPUP "&Input"
747.1799 +        BEGIN
747.1800 +            POPUP "&Configure Controllers"
747.1801 +            BEGIN
747.1802 +                MENUITEM "Controller &1...",            ID_OPTIONS_JOYPAD_CONFIGURE_1
747.1803 +                MENUITEM "Controller &2...",            ID_OPTIONS_JOYPAD_CONFIGURE_2
747.1804 +                MENUITEM "Controller &3...",            ID_OPTIONS_JOYPAD_CONFIGURE_3
747.1805 +                MENUITEM "Controller &4...",            ID_OPTIONS_JOYPAD_CONFIGURE_4
747.1806 +                MENUITEM SEPARATOR
747.1807 +                MENUITEM "&Motion Sensor...",           ID_OPTIONS_JOYPAD_MOTIONCONFIGURE
747.1808 +            END
747.1809 +            POPUP "&Use Controller"
747.1810 +            BEGIN
747.1811 +                MENUITEM "Controller &1",               ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_1
747.1812 +                MENUITEM "Controller &2",               ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_2
747.1813 +                MENUITEM "Controller &3",               ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_3
747.1814 +                MENUITEM "Controller &4",               ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_4
747.1815 +            END
747.1816 +            MENUITEM SEPARATOR
747.1817 +            MENUITEM "&Allow Left+Right / Up+Down", ID_OPTIONS_JOYPAD_ALLOWLEFTRIGHT
747.1818 +            MENUITEM SEPARATOR
747.1819 +            POPUP "Auto-&Fire"
747.1820 +            BEGIN
747.1821 +                MENUITEM "&A",                          ID_OPTIONS_JOYPAD_AUTOFIRE_A
747.1822 +                MENUITEM "&B",                          ID_OPTIONS_JOYPAD_AUTOFIRE_B
747.1823 +                MENUITEM "&L",                          ID_OPTIONS_JOYPAD_AUTOFIRE_L
747.1824 +                MENUITEM "&R",                          ID_OPTIONS_JOYPAD_AUTOFIRE_R
747.1825 +                MENUITEM "&Start",                      ID_OPTIONS_JOYPAD_AUTOFIRE_START
747.1826 +                MENUITEM "Selec&t",                     ID_OPTIONS_JOYPAD_AUTOFIRE_SELECT
747.1827 +                MENUITEM "&Up",                         ID_OPTIONS_JOYPAD_AUTOFIRE_UP
747.1828 +                MENUITEM "&Down",                       ID_OPTIONS_JOYPAD_AUTOFIRE_DOWN
747.1829 +                MENUITEM "L&eft",                       ID_OPTIONS_JOYPAD_AUTOFIRE_LEFT
747.1830 +                MENUITEM "R&ight",                      ID_OPTIONS_JOYPAD_AUTOFIRE_RIGHT
747.1831 +                MENUITEM SEPARATOR
747.1832 +                MENUITEM "&Clear All",                  ID_OPTIONS_JOYPAD_AUTOFIRE_CLEAR
747.1833 +                MENUITEM "Account &For Lag",            ID_OPTIONS_JOYPAD_AUTOFIRE_ACCOUNTFORLAG
747.1834 +            END
747.1835 +            POPUP "Auto-&Hold"
747.1836 +            BEGIN
747.1837 +                MENUITEM "&A",                          ID_STICKY_A
747.1838 +                MENUITEM "&B",                          ID_STICKY_B
747.1839 +                MENUITEM "&L",                          ID_STICKY_L
747.1840 +                MENUITEM "&R",                          ID_STICKY_R
747.1841 +                MENUITEM "&Start",                      ID_STICKY_START
747.1842 +                MENUITEM "Selec&t",                     ID_STICKY_SELECT
747.1843 +                MENUITEM "&Up",                         ID_STICKY_UP
747.1844 +                MENUITEM "&Down",                       ID_STICKY_DOWN
747.1845 +                MENUITEM "L&eft",                       ID_STICKY_LEFT
747.1846 +                MENUITEM "R&ight",                      ID_STICKY_RIGHT
747.1847 +                MENUITEM SEPARATOR
747.1848 +                MENUITEM "&Clear All",                  ID_STICKY_CLEAR
747.1849 +            END
747.1850 +            MENUITEM SEPARATOR
747.1851 +            MENUITEM "Customi&ze All Commands...",  ID_TOOLS_CUSTOMIZE
747.1852 +        END
747.1853 +        POPUP "&Speed"
747.1854 +        BEGIN
747.1855 +            POPUP "Set &Speed"
747.1856 +            BEGIN
747.1857 +                MENUITEM "6% (Very Slow)",              ID_OPTIONS_FRAMESKIP_THROTTLE_6
747.1858 +                MENUITEM "15%",                         ID_OPTIONS_FRAMESKIP_THROTTLE_15
747.1859 +                MENUITEM "25%",                         ID_OPTIONS_FRAMESKIP_THROTTLE_25
747.1860 +                MENUITEM "50% (Half Speed)",            ID_OPTIONS_FRAMESKIP_THROTTLE_50
747.1861 +                MENUITEM "75%",                         ID_OPTIONS_FRAMESKIP_THROTTLE_75
747.1862 +                MENUITEM "100% (Normal Speed)",         ID_OPTIONS_FRAMESKIP_THROTTLE_100
747.1863 +                MENUITEM "150%",                        ID_OPTIONS_FRAMESKIP_THROTTLE_150
747.1864 +                MENUITEM "200% (Double Speed)",         ID_OPTIONS_FRAMESKIP_THROTTLE_200
747.1865 +                MENUITEM "300%",                        ID_OPTIONS_FRAMESKIP_THROTTLE_300
747.1866 +                MENUITEM "400%",                        ID_OPTIONS_FRAMESKIP_THROTTLE_400
747.1867 +                MENUITEM "600% (Very Fast)",            ID_OPTIONS_FRAMESKIP_THROTTLE_600
747.1868 +                MENUITEM "&Other...",                   ID_OPTIONS_FRAMESKIP_THROTTLE_OTHER
747.1869 +                MENUITEM SEPARATOR
747.1870 +                MENUITEM "&Increase",                   ID_OPTIONS_FRAMESKIP_THROTTLE_INCREASE
747.1871 +                MENUITEM "&Decrease",                   ID_OPTIONS_FRAMESKIP_THROTTLE_DECREASE
747.1872 +            END
747.1873 +            POPUP "&Frame Skip"
747.1874 +            BEGIN
747.1875 +                MENUITEM "Skip &0 (Don't Skip Any Frames)", ID_OPTIONS_VIDEO_FRAMESKIP_0
747.1876 +                MENUITEM "Skip &1 (Skip Every Other Frame)", ID_OPTIONS_VIDEO_FRAMESKIP_1
747.1877 +                MENUITEM "Skip &2 (Skip 2 Out Of Every 3 Frames)", ID_OPTIONS_VIDEO_FRAMESKIP_2
747.1878 +                MENUITEM "Skip &3",                     ID_OPTIONS_VIDEO_FRAMESKIP_3
747.1879 +                MENUITEM "Skip &4",                     ID_OPTIONS_VIDEO_FRAMESKIP_4
747.1880 +                MENUITEM "Skip &5",                     ID_OPTIONS_VIDEO_FRAMESKIP_5
747.1881 +                MENUITEM "Skip &6",                     ID_OPTIONS_VIDEO_FRAMESKIP_6
747.1882 +                MENUITEM "Skip &7",                     ID_OPTIONS_VIDEO_FRAMESKIP_7
747.1883 +                MENUITEM "Skip &8",                     ID_OPTIONS_VIDEO_FRAMESKIP_8
747.1884 +                MENUITEM "Skip &9 (Skip 9 Out Of Every 10 Frames)", ID_OPTIONS_VIDEO_FRAMESKIP_9
747.1885 +            END
747.1886 +            MENUITEM SEPARATOR
747.1887 +            MENUITEM "&Turbo Mode",                 ID_OPTIONS_EMULATOR_SPEEDUPTOGGLE
747.1888 +            MENUITEM SEPARATOR
747.1889 +            MENUITEM "S&ynchronize Emulation Speed", ID_OPTIONS_EMULATOR_SYNCHRONIZE
747.1890 +            MENUITEM "    Accurate Sound &Pitch",   ID_OPTIONS_FRAMESKIP_ACCURATEPITCH
747.1891 +            MENUITEM "    Accurate &Emulation Speed", ID_OPTIONS_FRAMESKIP_ACCURATESPEED
747.1892 +        END
747.1893 +        MENUITEM SEPARATOR
747.1894 +        POPUP "&Video"
747.1895 +        BEGIN
747.1896 +            POPUP "&Render Method"
747.1897 +            BEGIN
747.1898 +                MENUITEM "&GDI",                        ID_OPTIONS_VIDEO_RENDERMETHOD_GDI
747.1899 +                MENUITEM SEPARATOR
747.1900 +                MENUITEM "&DirectDraw",                 ID_OPTIONS_VIDEO_RENDERMETHOD_DIRECTDRAW
747.1901 +                MENUITEM "    DDraw &Emulation Only",   ID_OPTIONS_VIDEO_DDRAWEMULATIONONLY
747.1902 +                MENUITEM "    DDraw &Use Video Memory", ID_OPTIONS_VIDEO_DDRAWUSEVIDEOMEMORY
747.1903 +                MENUITEM "    DDraw &Triple Buffering", ID_OPTIONS_VIDEO_TRIPLEBUFFERING
747.1904 +                MENUITEM "    DDraw &VSync",            ID_OPTIONS_VIDEO_VSYNC
747.1905 +                MENUITEM SEPARATOR
747.1906 +                MENUITEM "Direct&3D",                   ID_OPTIONS_VIDEO_RENDERMETHOD_DIRECT3D
747.1907 +                MENUITEM "    D3D &Nearest",            ID_OPTIONS_VIDEO_RENDEROPTIONS_D3DNOFILTER
747.1908 +                MENUITEM "    D3D &Bilinear",           ID_OPTIONS_VIDEO_RENDEROPTIONS_D3DBILINEAR
747.1909 +                MENUITEM SEPARATOR
747.1910 +                MENUITEM "&OpenGL",                     ID_OPTIONS_VIDEO_RENDERMETHOD_OPENGL
747.1911 +                MENUITEM "    GL Ne&arest",             ID_OPTIONS_VIDEO_RENDEROPTIONS_GLNEAREST
747.1912 +                MENUITEM "    GL B&ilinear",            ID_OPTIONS_VIDEO_RENDEROPTIONS_GLBILINEAR
747.1913 +                MENUITEM "    GL T&riangle",            ID_OPTIONS_VIDEO_RENDEROPTIONS_GLTRIANGLE
747.1914 +                MENUITEM "    GL &Quads",               ID_OPTIONS_VIDEO_RENDEROPTIONS_GLQUADS
747.1915 +            END
747.1916 +            MENUITEM SEPARATOR
747.1917 +            MENUITEM "&1x Window Size",             ID_OPTIONS_VIDEO_X1
747.1918 +            MENUITEM "&2x Window Size",             ID_OPTIONS_VIDEO_X2
747.1919 +            MENUITEM "&3x Window Size",             ID_OPTIONS_VIDEO_X3
747.1920 +            MENUITEM "&4x Window Size",             ID_OPTIONS_VIDEO_X4
747.1921 +            MENUITEM SEPARATOR
747.1922 +            MENUITEM "Full Screen (320x240)",       ID_OPTIONS_VIDEO_FULLSCREEN320X240
747.1923 +            MENUITEM "Full Screen (640x480)",       ID_OPTIONS_VIDEO_FULLSCREEN640X480
747.1924 +            MENUITEM "Full Screen (800x600)",       ID_OPTIONS_VIDEO_FULLSCREEN800X600
747.1925 +            MENUITEM "&Other Full Screen...",       ID_OPTIONS_VIDEO_FULLSCREEN
747.1926 +            MENUITEM SEPARATOR
747.1927 +            MENUITEM "Full Screen &Max Scale...",   ID_OPTIONS_VIDEO_FULLSCREENMAXSCALE
747.1928 +            MENUITEM "Full Screen &Ignore Ratio",   ID_OPTIONS_VIDEO_FULLSCREENSTRETCHTOFIT
747.1929 +            MENUITEM "Full Screen &Hide Menu",      ID_FILE_TOGGLEMENU
747.1930 +            MENUITEM "Full Screen &Auto Hide Menu", ID_OPTIONS_EMULATOR_AUTOHIDEMENU
747.1931 +            MENUITEM SEPARATOR
747.1932 +            MENUITEM "&Disable SFX",                ID_OPTIONS_VIDEO_DISABLESFX
747.1933 +            POPUP "Graphics &Layers"
747.1934 +            BEGIN
747.1935 +                MENUITEM "BG 0",                        ID_OPTIONS_VIDEO_LAYERS_BG0
747.1936 +                MENUITEM "BG 1",                        ID_OPTIONS_VIDEO_LAYERS_BG1
747.1937 +                MENUITEM "BG 2",                        ID_OPTIONS_VIDEO_LAYERS_BG2
747.1938 +                MENUITEM "BG 3",                        ID_OPTIONS_VIDEO_LAYERS_BG3
747.1939 +                MENUITEM "OBJ",                         ID_OPTIONS_VIDEO_LAYERS_OBJ
747.1940 +                MENUITEM "WIN 0",                       ID_OPTIONS_VIDEO_LAYERS_WIN0
747.1941 +                MENUITEM "WIN 1",                       ID_OPTIONS_VIDEO_LAYERS_WIN1
747.1942 +                MENUITEM "OBJ WIN",                     ID_OPTIONS_VIDEO_LAYERS_OBJWIN
747.1943 +            END
747.1944 +        END
747.1945 +        POPUP "Pixel &Filter"
747.1946 +        BEGIN
747.1947 +            POPUP "&Interframe Blending"
747.1948 +            BEGIN
747.1949 +                MENUITEM "&None",                       ID_OPTIONS_FILTER_INTERFRAMEBLENDING_NONE
747.1950 +                MENUITEM SEPARATOR
747.1951 +                MENUITEM "&Motion Blur",                ID_OPTIONS_FILTER_INTERFRAMEBLENDING_MOTIONBLUR
747.1952 +                MENUITEM "&Smart",                      ID_OPTIONS_FILTER_INTERFRAMEBLENDING_SMART
747.1953 +            END
747.1954 +            MENUITEM SEPARATOR
747.1955 +            POPUP "&Miscellaneous 2x"
747.1956 +            BEGIN
747.1957 +                MENUITEM "&None",                       ID_OPTIONS_FILTER_NORMAL
747.1958 +                MENUITEM SEPARATOR
747.1959 +                MENUITEM "&TV Mode",                    ID_OPTIONS_FILTER_TVMODE
747.1960 +                MENUITEM "Scan&lines",                  ID_OPTIONS_FILTER_SCANLINES
747.1961 +                MENUITEM SEPARATOR
747.1962 +                MENUITEM "&Bilinear",                   ID_OPTIONS_FILTER_BILINEAR
747.1963 +                MENUITEM "Bilinear Pl&us",              ID_OPTIONS_FILTER_BILINEARPLUS
747.1964 +                MENUITEM SEPARATOR
747.1965 +                MENUITEM "&Motion Blur",                ID_OPTIONS_FILTER16BIT_MOTIONBLUREXPERIMENTAL
747.1966 +            END
747.1967 +            POPUP "&2x Magnification"
747.1968 +            BEGIN
747.1969 +                MENUITEM "Simple 2&x",                  ID_OPTIONS_FILTER16BIT_SIMPLE2X
747.1970 +                MENUITEM "&Pixelate 2x",                ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL
747.1971 +                MENUITEM SEPARATOR
747.1972 +                MENUITEM "&2xSaI",                      ID_OPTIONS_FILTER_2XSAI
747.1973 +                MENUITEM "&Super 2xSaI",                ID_OPTIONS_FILTER_SUPER2XSAI
747.1974 +                MENUITEM "Super &Eagle",                ID_OPTIONS_FILTER_SUPEREAGLE
747.1975 +                MENUITEM "&AdvanceMAME Scale2x",        ID_OPTIONS_FILTER16BIT_ADVANCEMAMESCALE2X
747.1976 +                MENUITEM SEPARATOR
747.1977 +                MENUITEM "LQ2x",                        ID_OPTIONS_FILTER_LQ2X
747.1978 +                MENUITEM "HQ2x",                        ID_OPTIONS_FILTER_HQ2X
747.1979 +                MENUITEM "HQ2xS",                       ID_OPTIONS_FILTER_HQ2X2
747.1980 +            END
747.1981 +            POPUP "&3x Magnification"
747.1982 +            BEGIN
747.1983 +                MENUITEM "Simple 3&x",                  ID_OPTIONS_FILTER16BIT_SIMPLE3X
747.1984 +                MENUITEM "&Pixelate 3x",                ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL3X
747.1985 +                MENUITEM SEPARATOR
747.1986 +                MENUITEM "HQ3x",                        ID_OPTIONS_FILTER_HQ3X
747.1987 +                MENUITEM "HQ3xS",                       ID_OPTIONS_FILTER_HQ3X2
747.1988 +            END
747.1989 +            POPUP "&4x Magnification"
747.1990 +            BEGIN
747.1991 +                MENUITEM "Simple 4&x",                  ID_OPTIONS_FILTER16BIT_SIMPLE4X
747.1992 +                MENUITEM "&Pixelate 4x",                ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL4X
747.1993 +            END
747.1994 +            MENUITEM SEPARATOR
747.1995 +            MENUITEM "&Disable MMX Optimizations",  ID_OPTIONS_FILTER_DISABLEMMX
747.1996 +        END
747.1997 +        POPUP "&Audio"
747.1998 +        BEGIN
747.1999 +            MENUITEM "&Disable",                    ID_OPTIONS_SOUND_DISABLE
747.2000 +            MENUITEM SEPARATOR
747.2001 +            MENUITEM "&Mute All Channels",          ID_OPTIONS_SOUND_MUTE
747.2002 +            MENUITEM "Mute Frame &Advance",         ID_OPTIONS_SOUND_MUTEFRAMEADVANCE
747.2003 +            MENUITEM "Mute When &Inactive",         ID_OPTIONS_SOUND_MUTEWHENINACTIVE
747.2004 +            MENUITEM SEPARATOR
747.2005 +            MENUITEM "&Use Old Synchronization",    ID_OPTIONS_SOUND_USEOLDSYNCHRONIZATION
747.2006 +            MENUITEM "&Reverse Stereo",             ID_OPTIONS_SOUND_REVERSESTEREO
747.2007 +            MENUITEM SEPARATOR
747.2008 +            MENUITEM "&Echo",                       ID_OPTIONS_SOUND_ECHO
747.2009 +            MENUITEM "&Low Pass Filter",            ID_OPTIONS_SOUND_LOWPASSFILTER
747.2010 +            MENUITEM SEPARATOR
747.2011 +            POPUP "&Volume"
747.2012 +            BEGIN
747.2013 +                MENUITEM "&.25x",                       ID_OPTIONS_SOUND_VOLUME_25X
747.2014 +                MENUITEM ".&5x",                        ID_OPTIONS_SOUND_VOLUME_5X
747.2015 +                MENUITEM "&1x",                         ID_OPTIONS_SOUND_VOLUME_1X
747.2016 +                MENUITEM "&2x",                         ID_OPTIONS_SOUND_VOLUME_2X
747.2017 +                MENUITEM "&3x",                         ID_OPTIONS_SOUND_VOLUME_3X
747.2018 +                MENUITEM "&4x",                         ID_OPTIONS_SOUND_VOLUME_4X
747.2019 +            END
747.2020 +            POPUP "&Channels"
747.2021 +            BEGIN
747.2022 +                MENUITEM "&Enable All Channels",        ID_OPTIONS_SOUND_ON, CHECKED
747.2023 +                MENUITEM "&Disable All Channels",       ID_OPTIONS_SOUND_OFF
747.2024 +                MENUITEM SEPARATOR
747.2025 +                MENUITEM "Channel &1",                  ID_OPTIONS_SOUND_CHANNEL1, CHECKED
747.2026 +                MENUITEM "Channel &2",                  ID_OPTIONS_SOUND_CHANNEL2, CHECKED
747.2027 +                MENUITEM "Channel &3",                  ID_OPTIONS_SOUND_CHANNEL3, CHECKED
747.2028 +                MENUITEM "Channel &4",                  ID_OPTIONS_SOUND_CHANNEL4, CHECKED
747.2029 +                MENUITEM "Direct Sound &A",             ID_OPTIONS_SOUND_DIRECTSOUNDA, CHECKED
747.2030 +                MENUITEM "Direct Sound &B",             ID_OPTIONS_SOUND_DIRECTSOUNDB, CHECKED
747.2031 +            END
747.2032 +            MENUITEM SEPARATOR
747.2033 +            MENUITEM "&11 Khz",                     ID_OPTIONS_SOUND_11KHZ
747.2034 +            MENUITEM "&22 Khz",                     ID_OPTIONS_SOUND_22KHZ
747.2035 +            MENUITEM "&44 Khz",                     ID_OPTIONS_SOUND_44KHZ
747.2036 +        END
747.2037 +        MENUITEM SEPARATOR
747.2038 +        POPUP "&Emulation"
747.2039 +        BEGIN
747.2040 +            MENUITEM "&Real Time Clock",            ID_OPTIONS_EMULATOR_REALTIMECLOCK
747.2041 +            POPUP "Save &Type"
747.2042 +            BEGIN
747.2043 +                MENUITEM "&Automatic",                  ID_OPTIONS_EMULATOR_SAVETYPE_AUTOMATIC
747.2044 +                MENUITEM "&EEPROM",                     ID_OPTIONS_EMULATOR_SAVETYPE_EEPROM
747.2045 +                MENUITEM "&SRAM",                       ID_OPTIONS_EMULATOR_SAVETYPE_SRAM
747.2046 +                MENUITEM "&Flash",                      ID_OPTIONS_EMULATOR_SAVETYPE_FLASH
747.2047 +                MENUITEM "EE&PROM+Sensor",              ID_OPTIONS_EMULATOR_SAVETYPE_EEPROMSENSOR
747.2048 +                MENUITEM "&None",                       ID_OPTIONS_EMULATOR_SAVETYPE_NONE
747.2049 +                MENUITEM SEPARATOR
747.2050 +                MENUITEM "Flash &64K",                  ID_OPTIONS_EMULATOR_SAVETYPE_FLASH512K
747.2051 +                MENUITEM "Flash &128K",                 ID_OPTIONS_EMULATOR_SAVETYPE_FLASH1M
747.2052 +                MENUITEM SEPARATOR
747.2053 +                MENUITEM "Enhanced &Detection",         ID_OPTIONS_EMULATOR_SAVETYPE_ENHANCEDDETECTION
747.2054 +            END
747.2055 +            MENUITEM SEPARATOR
747.2056 +            MENUITEM "GBA &Lag Reduction",          ID_EMULATOR_GBALAG
747.2057 +            MENUITEM "Use &Old Frame Timing",       ID_EMULATOR_USE_OLD_FRAME_TIMING
747.2058 +            MENUITEM "    Use &GB Null Input Kludge", ID_EMULATOR_USE_GB_INPUT_KLUDGE
747.2059 +            MENUITEM SEPARATOR
747.2060 +            MENUITEM "&Use BIOS File",              ID_OPTIONS_EMULATOR_USEBIOSFILE
747.2061 +            MENUITEM "Skip BIOS &Intro",            ID_OPTIONS_EMULATOR_SKIPBIOS
747.2062 +            MENUITEM "Select &BIOS File...",        ID_OPTIONS_EMULATOR_SELECTBIOSFILE
747.2063 +            MENUITEM SEPARATOR
747.2064 +            MENUITEM "Automatic IPS &Patching",     ID_OPTIONS_EMULATOR_AUTOMATICALLYIPSPATCH
747.2065 +        END
747.2066 +        POPUP "Gameboy &Mode"
747.2067 +        BEGIN
747.2068 +            MENUITEM "Automatic &Detection",        ID_OPTIONS_GAMEBOY_AUTOMATIC
747.2069 +            MENUITEM "Game Boy &Advance (GBA/AGB)", ID_OPTIONS_GAMEBOY_GBA
747.2070 +            MENUITEM "Game Boy &Color (GBC/CGB)",   ID_OPTIONS_GAMEBOY_CGB
747.2071 +            MENUITEM "Game Boy Color + SGB b&orders", ID_OPTIONS_GAMEBOY_SGB2
747.2072 +            MENUITEM "&Super Game Boy (SGB)",       ID_OPTIONS_GAMEBOY_SGB
747.2073 +            MENUITEM "Game &Boy (GB)",              ID_OPTIONS_GAMEBOY_GB
747.2074 +            MENUITEM SEPARATOR
747.2075 +            MENUITEM "Border A&utomatic",           ID_OPTIONS_GAMEBOY_BORDERAUTOMATIC
747.2076 +            MENUITEM "Border Al&ways",              ID_OPTIONS_GAMEBOY_BORDER
747.2077 +            MENUITEM SEPARATOR
747.2078 +            MENUITEM "GB &Printer",                 ID_OPTIONS_GAMEBOY_PRINTER
747.2079 +            MENUITEM SEPARATOR
747.2080 +            MENUITEM "&Real Colors",                ID_OPTIONS_GAMEBOY_REALCOLORS
747.2081 +            MENUITEM "Ga&meboy Colors",             ID_OPTIONS_GAMEBOY_GAMEBOYCOLORS
747.2082 +            MENUITEM "Customi&ze Colors...",        ID_OPTIONS_GAMEBOY_COLORS
747.2083 +        END
747.2084 +        MENUITEM SEPARATOR
747.2085 +        POPUP "&Head-Up Display"
747.2086 +        BEGIN
747.2087 +            MENUITEM "&Frame Counter",              ID_TOOLS_FRAMECOUNTER
747.2088 +            MENUITEM "    &Lag Counter",            ID_TOOLS_LAGCOUNTER
747.2089 +            MENUITEM "    &Extra Counter",          ID_TOOLS_EXTRACOUNTER
747.2090 +            MENUITEM "    Extra Counter &Reset",    ID_TOOLS_EXTRACOUNTERRESET
747.2091 +            MENUITEM "&Input Display",              ID_TOOLS_INPUTDISPLAY
747.2092 +            MENUITEM SEPARATOR
747.2093 +            MENUITEM "&Text Display Options...",    ID_OPTIONS_VIDEO_TEXTDISPLAYOPTIONS
747.2094 +            MENUITEM "Disable Status &Messages",    ID_OPTIONS_VIDEO_DISABLESTATUSMESSAGES
747.2095 +            MENUITEM SEPARATOR
747.2096 +            POPUP "Show &Speed"
747.2097 +            BEGIN
747.2098 +                MENUITEM "None",                        ID_OPTIONS_EMULATOR_SHOWSPEED_NONE
747.2099 +                MENUITEM "Percentage",                  ID_OPTIONS_EMULATOR_SHOWSPEED_PERCENTAGE
747.2100 +                MENUITEM "Detailed",                    ID_OPTIONS_EMULATOR_SHOWSPEED_DETAILED
747.2101 +                MENUITEM SEPARATOR
747.2102 +                MENUITEM "Transparent",                 ID_OPTIONS_EMULATOR_SHOWSPEED_TRANSPARENT
747.2103 +            END
747.2104 +        END
747.2105 +        POPUP "&Preferences"
747.2106 +        BEGIN
747.2107 +            MENUITEM "Always On &Top",              ID_OPTIONS_EMULATOR_ALWAYSONTOP
747.2108 +            MENUITEM "Enable &Background Input",    ID_OPTIONS_EMULATOR_BACKGROUNDINPUT
747.2109 +            MENUITEM "Pause When &Inactive",        ID_OPTIONS_EMULATOR_PAUSEWHENINACTIVE
747.2110 +            POPUP "Process &Priority"
747.2111 +            BEGIN
747.2112 +                MENUITEM "&Highest",                    ID_OPTIONS_PRIORITY_HIGHEST
747.2113 +                MENUITEM "&Above Normal",               ID_OPTIONS_PRIORITY_ABOVENORMAL
747.2114 +                MENUITEM "&Normal",                     ID_OPTIONS_PRIORITY_NORMAL
747.2115 +                MENUITEM "&Below Normal",               ID_OPTIONS_PRIORITY_BELOWNORMAL
747.2116 +            END
747.2117 +            MENUITEM SEPARATOR
747.2118 +            POPUP "Relevant File &Naming"
747.2119 +            BEGIN
747.2120 +                MENUITEM "Prefer On-Disk &Archive Filename", ID_OPTIONS_PREFER_ARCHIVE_NAME
747.2121 +                MENUITEM "Prefer Logical &ROM Filename", ID_OPTIONS_PREFER_ROM_NAME
747.2122 +            END
747.2123 +            MENUITEM "&Directories...",             ID_OPTIONS_EMULATOR_DIRECTORIES
747.2124 +            MENUITEM "&Associate...",               ID_OPTIONS_EMULATOR_ASSOCIATE
747.2125 +            MENUITEM SEPARATOR
747.2126 +            POPUP "UI &Language"
747.2127 +            BEGIN
747.2128 +                MENUITEM "&System",                     ID_OPTIONS_LANGUAGE_SYSTEM
747.2129 +                MENUITEM "&English",                    ID_OPTIONS_LANGUAGE_ENGLISH
747.2130 +                MENUITEM "&Other...",                   ID_OPTIONS_LANGUAGE_OTHER
747.2131 +            END
747.2132 +        END
747.2133 +    END
747.2134 +    POPUP "&Cheats"
747.2135 +    BEGIN
747.2136 +        MENUITEM "&RAM Search...",              ID_RAM_SEARCH
747.2137 +        MENUITEM "RAM &Watch...",               ID_RAM_WATCH
747.2138 +        MENUITEM SEPARATOR
747.2139 +        MENUITEM "Old &Cheat Search...",        ID_CHEATS_SEARCHFORCHEATS
747.2140 +        MENUITEM "&Pause During Cheat Search",  ID_CHEATS_PAUSEDURINGCHEATSEARCH
747.2141 +        MENUITEM SEPARATOR
747.2142 +        MENUITEM "&View Cheat List...",         ID_CHEATS_CHEATLIST
747.2143 +        MENUITEM "&Load Cheat List...",         ID_CHEATS_LOADCHEATLIST
747.2144 +        MENUITEM "&Save Cheat List...",         ID_CHEATS_SAVECHEATLIST
747.2145 +        MENUITEM "&Auto Save/Load Cheat List",  ID_CHEATS_AUTOMATICSAVELOADCHEATS
747.2146 +        MENUITEM SEPARATOR
747.2147 +        MENUITEM "Import &Gameshark Code File...", ID_FILE_IMPORT_GAMESHARKCODEFILE
747.2148 +        MENUITEM SEPARATOR
747.2149 +        MENUITEM "&Disable All Cheats",         ID_CHEATS_DISABLECHEATS
747.2150 +    END
747.2151 +    POPUP "&Tools"
747.2152 +    BEGIN
747.2153 +        POPUP "&Debug"
747.2154 +        BEGIN
747.2155 +            MENUITEM "&Disassemble...",             ID_TOOLS_DISASSEMBLE
747.2156 +            MENUITEM "&Logging...",                 ID_TOOLS_LOGGING
747.2157 +            MENUITEM "&IO Viewer...",               ID_TOOLS_IOVIEWER
747.2158 +            MENUITEM "&Map Viewer...",              ID_TOOLS_MAPVIEW
747.2159 +            MENUITEM "Memory &Viewer...",           ID_TOOLS_MEMORYVIEWER
747.2160 +            MENUITEM "&OAM Viewer...",              ID_TOOLS_OAMVIEWER
747.2161 +            MENUITEM "&Palette Viewer...",          ID_TOOLS_PALETTEVIEW
747.2162 +            MENUITEM "&Tile Viewer...",             ID_TOOLS_TILEVIEWER
747.2163 +            MENUITEM SEPARATOR
747.2164 +            MENUITEM "&AGB Print",                  ID_OPTIONS_EMULATOR_AGBPRINT
747.2165 +            POPUP "&GDB"
747.2166 +            BEGIN
747.2167 +                MENUITEM "&Wait For Connection...",     ID_TOOLS_DEBUG_GDB
747.2168 +                MENUITEM "&Load And Wait...",           ID_TOOLS_DEBUG_LOADANDWAIT
747.2169 +                MENUITEM "&Break Into GDB",             ID_TOOLS_DEBUG_BREAK
747.2170 +                MENUITEM "&Disconnect",                 ID_TOOLS_DEBUG_DISCONNECT
747.2171 +            END
747.2172 +        END
747.2173 +        MENUITEM SEPARATOR
747.2174 +        MENUITEM "Frame &Search",               ID_DEBUG_FRAMESEARCH
747.2175 +        MENUITEM "Frame Search Pre&v",          ID_DEBUG_FRAMESEARCHPREV
747.2176 +        MENUITEM "Frame Search &End",           ID_DEBUG_FRAMESEARCHLOAD
747.2177 +        MENUITEM SEPARATOR
747.2178 +        POPUP "&Lua Scripting"
747.2179 +        BEGIN
747.2180 +            MENUITEM "&New Lua Script Window...",   ID_FILE_LUA_OPEN
747.2181 +            MENUITEM "Close &All Script Windows",   ID_FILE_LUA_CLOSE_ALL
747.2182 +        END
747.2183 +        MENUITEM SEPARATOR
747.2184 +        POPUP "&Movie"
747.2185 +        BEGIN
747.2186 +            MENUITEM "&Play Movie...",              ID_MOVIE_PLAY
747.2187 +            MENUITEM "&Watch From Beginning",       ID_MOVIE_RESTART_PLAY
747.2188 +            MENUITEM SEPARATOR
747.2189 +            MENUITEM "Record &New Movie...",        ID_MOVIE_RECORD
747.2190 +            MENUITEM "&Resume/Exit Recording",      ID_MOVIE_RESUME_RECORD
747.2191 +            MENUITEM SEPARATOR
747.2192 +            MENUITEM "Read-&Only Mode",             ID_MOVIE_READONLY
747.2193 +            POPUP "When Movie &Ends"
747.2194 +            BEGIN
747.2195 +                MENUITEM "&Pause Emulator",             ID_MOVIE_END_PAUSE
747.2196 +                MENUITEM SEPARATOR
747.2197 +                MENUITEM "&Close Movie",                ID_MOVIE_END_STOP
747.2198 +                MENUITEM "&Watch From Beginning",       ID_MOVIE_END_RESTART
747.2199 +                MENUITEM "&Append If Modified",         ID_MOVIE_END_APPEND
747.2200 +                MENUITEM "&Leave Open",                 ID_MOVIE_END_KEEP
747.2201 +            END
747.2202 +            MENUITEM SEPARATOR
747.2203 +            MENUITEM "&Stop Movie",                 ID_MOVIE_STOP
747.2204 +            MENUITEM SEPARATOR
747.2205 +            POPUP "Advanced &Tools"
747.2206 +            BEGIN
747.2207 +                MENUITEM "&Convert Current To VBM 1.1", ID_MOVIE_TOOL_CONVERT
747.2208 +                MENUITEM SEPARATOR
747.2209 +                MENUITEM "&Auto Convert Opened Movie",  ID_MOVIE_TOOL_AUTO_CONVERT
747.2210 +                MENUITEM SEPARATOR
747.2211 +                MENUITEM "Fix &Header",                 ID_MOVIE_TOOL_FIX_HEADER
747.2212 +                MENUITEM SEPARATOR
747.2213 +                MENUITEM "&Truncate At Current Frame",  ID_MOVIE_TOOL_TRUNCATE
747.2214 +            END
747.2215 +            MENUITEM "&Associate With Savestates",  ID_MOVIE_ASSC_WITH_SAVESTATE
747.2216 +        END
747.2217 +        MENUITEM "Pause/Resume AVI &Recording", ID_TOOLS_PAUSEAVIRECORDING
747.2218 +        MENUITEM "Start/Stop &AVI Recording...", ID_TOOLS_AVIRECORDING
747.2219 +        MENUITEM "Start/Stop &WAV Recording...", ID_TOOLS_SOUNDRECORDING
747.2220 +        MENUITEM SEPARATOR
747.2221 +        MENUITEM "Screenshot &Capture...",      ID_FILE_SCREENCAPTURE
747.2222 +        POPUP "Screenshot &Format"
747.2223 +        BEGIN
747.2224 +            MENUITEM "&PNG",                        ID_OPTIONS_EMULATOR_PNGFORMAT
747.2225 +            MENUITEM "&BMP",                        ID_OPTIONS_EMULATOR_BMPFORMAT
747.2226 +        END
747.2227 +    END
747.2228 +    POPUP "&Help"
747.2229 +    BEGIN
747.2230 +        MENUITEM "&FAQ (Website)...",           ID_HELP_FAQ
747.2231 +        MENUITEM "&Bug Report...",              ID_HELP_BUGREPORT
747.2232 +        MENUITEM SEPARATOR
747.2233 +        MENUITEM "&About...",                   ID_HELP_ABOUT
747.2234 +    END
747.2235 +END
747.2236 +
747.2237 +RAMWATCH_MENU MENU
747.2238 +BEGIN
747.2239 +    POPUP "&File"
747.2240 +    BEGIN
747.2241 +        MENUITEM "&New List\tCtrl+N",           RAMMENU_FILE_NEW
747.2242 +        MENUITEM "&Open...\tCtrl+O",            RAMMENU_FILE_OPEN
747.2243 +        MENUITEM "&Save\tCtrl+S",               RAMMENU_FILE_SAVE
747.2244 +        MENUITEM "Sa&ve As...\tCtrl+Shift+S",   RAMMENU_FILE_SAVEAS
747.2245 +        MENUITEM "&Append File...",             RAMMENU_FILE_APPEND
747.2246 +        MENUITEM "&Recent",                     RAMMENU_FILE_RECENT
747.2247 +        MENUITEM SEPARATOR
747.2248 +        MENUITEM "Auto-&Load",                  RAMMENU_FILE_AUTOLOAD
747.2249 +        MENUITEM "Save &Window Position",       RAMMENU_FILE_SAVEWINDOW
747.2250 +        MENUITEM SEPARATOR
747.2251 +        MENUITEM "&Close\tAlt+F4",              IDCANCEL
747.2252 +    END
747.2253 +    POPUP "&Watches"
747.2254 +    BEGIN
747.2255 +        MENUITEM "&New Watch\tN",               IDC_C_WATCH
747.2256 +        MENUITEM "&Edit Watch\tE",              IDC_C_WATCH_EDIT
747.2257 +        MENUITEM "&Remove Watch\tR",            IDC_C_WATCH_REMOVE
747.2258 +        MENUITEM "Duplic&ate Watch\tA",         IDC_C_WATCH_DUPLICATE
747.2259 +        MENUITEM SEPARATOR
747.2260 +        MENUITEM "Move &Up\tU",                 IDC_C_WATCH_UP
747.2261 +        MENUITEM "Move &Down\tD",               IDC_C_WATCH_DOWN
747.2262 +    END
747.2263 +END
747.2264 +
747.2265 +LUAWINDOW_MENU MENU
747.2266 +BEGIN
747.2267 +    POPUP "Console"
747.2268 +    BEGIN
747.2269 +        MENUITEM "&Font...",                    IDC_LUACONSOLE_CHOOSEFONT
747.2270 +        MENUITEM "Clear",                       IDC_LUACONSOLE_CLEAR
747.2271 +    END
747.2272 +END
747.2273 +
747.2274 +
747.2275 +/////////////////////////////////////////////////////////////////////////////
747.2276 +//
747.2277 +// Accelerator
747.2278 +//
747.2279 +
747.2280 +IDR_ACCELERATOR ACCELERATORS
747.2281 +BEGIN
747.2282 +    "C",            ID_CHEATS_SEARCHFORCHEATS, VIRTKEY, CONTROL, NOINVERT
747.2283 +    VK_OEM_6,       ID_DEBUG_FRAMESEARCH,   VIRTKEY, NOINVERT
747.2284 +    "L",            ID_DEBUG_FRAMESEARCHLOAD, VIRTKEY, NOINVERT
747.2285 +    VK_OEM_4,       ID_DEBUG_FRAMESEARCHPREV, VIRTKEY, NOINVERT
747.2286 +    "N",            ID_DEBUG_NEXTFRAME,     VIRTKEY, CONTROL, NOINVERT
747.2287 +    VK_OEM_5,       ID_DEBUG_NEXTFRAME,     VIRTKEY, NOINVERT
747.2288 +    "X",            ID_FILE_EXIT,           VIRTKEY, CONTROL, NOINVERT
747.2289 +    "L",            ID_FILE_LOAD,           VIRTKEY, SHIFT, CONTROL, NOINVERT
747.2290 +    "L",            ID_FILE_LOADGAME_CURRENT, VIRTKEY, CONTROL, NOINVERT
747.2291 +    VK_F1,          ID_FILE_LOADGAME_SLOT1, VIRTKEY, NOINVERT
747.2292 +    VK_F10,         ID_FILE_LOADGAME_SLOT10, VIRTKEY, NOINVERT
747.2293 +    VK_F2,          ID_FILE_LOADGAME_SLOT2, VIRTKEY, NOINVERT
747.2294 +    VK_F3,          ID_FILE_LOADGAME_SLOT3, VIRTKEY, NOINVERT
747.2295 +    VK_F4,          ID_FILE_LOADGAME_SLOT4, VIRTKEY, NOINVERT
747.2296 +    VK_F5,          ID_FILE_LOADGAME_SLOT5, VIRTKEY, NOINVERT
747.2297 +    VK_F6,          ID_FILE_LOADGAME_SLOT6, VIRTKEY, NOINVERT
747.2298 +    VK_F7,          ID_FILE_LOADGAME_SLOT7, VIRTKEY, NOINVERT
747.2299 +    VK_F8,          ID_FILE_LOADGAME_SLOT8, VIRTKEY, NOINVERT
747.2300 +    VK_F9,          ID_FILE_LOADGAME_SLOT9, VIRTKEY, NOINVERT
747.2301 +    VK_F1,          ID_FILE_MRU_FILE1,      VIRTKEY, CONTROL, NOINVERT
747.2302 +    VK_F10,         ID_FILE_MRU_FILE10,     VIRTKEY, CONTROL, NOINVERT
747.2303 +    VK_F2,          ID_FILE_MRU_FILE2,      VIRTKEY, CONTROL, NOINVERT
747.2304 +    VK_F3,          ID_FILE_MRU_FILE3,      VIRTKEY, CONTROL, NOINVERT
747.2305 +    VK_F4,          ID_FILE_MRU_FILE4,      VIRTKEY, CONTROL, NOINVERT
747.2306 +    VK_F5,          ID_FILE_MRU_FILE5,      VIRTKEY, CONTROL, NOINVERT
747.2307 +    VK_F6,          ID_FILE_MRU_FILE6,      VIRTKEY, CONTROL, NOINVERT
747.2308 +    VK_F7,          ID_FILE_MRU_FILE7,      VIRTKEY, CONTROL, NOINVERT
747.2309 +    VK_F8,          ID_FILE_MRU_FILE8,      VIRTKEY, CONTROL, NOINVERT
747.2310 +    VK_F9,          ID_FILE_MRU_FILE9,      VIRTKEY, CONTROL, NOINVERT
747.2311 +    "O",            ID_FILE_OPEN,           VIRTKEY, CONTROL, NOINVERT
747.2312 +    "G",            ID_FILE_OPENGAMEBOY,    VIRTKEY, CONTROL, NOINVERT
747.2313 +    "P",            ID_FILE_PAUSE,          VIRTKEY, CONTROL, NOINVERT
747.2314 +    VK_PAUSE,       ID_FILE_PAUSE,          VIRTKEY, NOINVERT
747.2315 +    "R",            ID_FILE_RESET,          VIRTKEY, CONTROL, NOINVERT
747.2316 +    "S",            ID_FILE_SAVE,           VIRTKEY, SHIFT, CONTROL, NOINVERT
747.2317 +    "S",            ID_FILE_SAVEGAME_CURRENT, VIRTKEY, CONTROL, NOINVERT
747.2318 +    VK_F1,          ID_FILE_SAVEGAME_SLOT1, VIRTKEY, SHIFT, NOINVERT
747.2319 +    VK_F10,         ID_FILE_SAVEGAME_SLOT10, VIRTKEY, SHIFT, NOINVERT
747.2320 +    VK_F2,          ID_FILE_SAVEGAME_SLOT2, VIRTKEY, SHIFT, NOINVERT
747.2321 +    VK_F3,          ID_FILE_SAVEGAME_SLOT3, VIRTKEY, SHIFT, NOINVERT
747.2322 +    VK_F4,          ID_FILE_SAVEGAME_SLOT4, VIRTKEY, SHIFT, NOINVERT
747.2323 +    VK_F5,          ID_FILE_SAVEGAME_SLOT5, VIRTKEY, SHIFT, NOINVERT
747.2324 +    VK_F6,          ID_FILE_SAVEGAME_SLOT6, VIRTKEY, SHIFT, NOINVERT
747.2325 +    VK_F7,          ID_FILE_SAVEGAME_SLOT7, VIRTKEY, SHIFT, NOINVERT
747.2326 +    VK_F8,          ID_FILE_SAVEGAME_SLOT8, VIRTKEY, SHIFT, NOINVERT
747.2327 +    VK_F9,          ID_FILE_SAVEGAME_SLOT9, VIRTKEY, SHIFT, NOINVERT
747.2328 +    VK_ESCAPE,      ID_FILE_TOGGLEMENU,     VIRTKEY, NOINVERT
747.2329 +    "8",            ID_MOVIE_READONLY,      VIRTKEY, SHIFT, NOINVERT
747.2330 +    VK_OEM_MINUS,   ID_OPTIONS_FRAMESKIP_THROTTLE_DECREASE, VIRTKEY, NOINVERT
747.2331 +    VK_OEM_PLUS,    ID_OPTIONS_FRAMESKIP_THROTTLE_INCREASE, VIRTKEY, NOINVERT
747.2332 +    "1",            ID_OPTIONS_JOYPAD_AUTOFIRE_A, VIRTKEY, ALT, NOINVERT
747.2333 +    "2",            ID_OPTIONS_JOYPAD_AUTOFIRE_B, VIRTKEY, ALT, NOINVERT
747.2334 +    VK_OEM_3,       ID_OPTIONS_JOYPAD_AUTOFIRE_CLEAR, VIRTKEY, ALT, NOINVERT
747.2335 +    "8",            ID_OPTIONS_JOYPAD_AUTOFIRE_DOWN, VIRTKEY, ALT, NOINVERT
747.2336 +    "3",            ID_OPTIONS_JOYPAD_AUTOFIRE_L, VIRTKEY, ALT, NOINVERT
747.2337 +    "9",            ID_OPTIONS_JOYPAD_AUTOFIRE_LEFT, VIRTKEY, ALT, NOINVERT
747.2338 +    "4",            ID_OPTIONS_JOYPAD_AUTOFIRE_R, VIRTKEY, ALT, NOINVERT
747.2339 +    "0",            ID_OPTIONS_JOYPAD_AUTOFIRE_RIGHT, VIRTKEY, ALT, NOINVERT
747.2340 +    "6",            ID_OPTIONS_JOYPAD_AUTOFIRE_SELECT, VIRTKEY, ALT, NOINVERT
747.2341 +    "5",            ID_OPTIONS_JOYPAD_AUTOFIRE_START, VIRTKEY, ALT, NOINVERT
747.2342 +    "7",            ID_OPTIONS_JOYPAD_AUTOFIRE_UP, VIRTKEY, ALT, NOINVERT
747.2343 +    "1",            ID_OPTIONS_VIDEO_LAYERS_BG0, VIRTKEY, CONTROL, NOINVERT
747.2344 +    "2",            ID_OPTIONS_VIDEO_LAYERS_BG1, VIRTKEY, CONTROL, NOINVERT
747.2345 +    "3",            ID_OPTIONS_VIDEO_LAYERS_BG2, VIRTKEY, CONTROL, NOINVERT
747.2346 +    "4",            ID_OPTIONS_VIDEO_LAYERS_BG3, VIRTKEY, CONTROL, NOINVERT
747.2347 +    "5",            ID_OPTIONS_VIDEO_LAYERS_OBJ, VIRTKEY, CONTROL, NOINVERT
747.2348 +    "8",            ID_OPTIONS_VIDEO_LAYERS_OBJWIN, VIRTKEY, CONTROL, NOINVERT
747.2349 +    "6",            ID_OPTIONS_VIDEO_LAYERS_WIN0, VIRTKEY, CONTROL, NOINVERT
747.2350 +    "7",            ID_OPTIONS_VIDEO_LAYERS_WIN1, VIRTKEY, CONTROL, NOINVERT
747.2351 +    "1",            ID_SELECT_SLOT1,        VIRTKEY, NOINVERT
747.2352 +    "0",            ID_SELECT_SLOT10,       VIRTKEY, NOINVERT
747.2353 +    "2",            ID_SELECT_SLOT2,        VIRTKEY, NOINVERT
747.2354 +    "3",            ID_SELECT_SLOT3,        VIRTKEY, NOINVERT
747.2355 +    "4",            ID_SELECT_SLOT4,        VIRTKEY, NOINVERT
747.2356 +    "5",            ID_SELECT_SLOT5,        VIRTKEY, NOINVERT
747.2357 +    "6",            ID_SELECT_SLOT6,        VIRTKEY, NOINVERT
747.2358 +    "7",            ID_SELECT_SLOT7,        VIRTKEY, NOINVERT
747.2359 +    "8",            ID_SELECT_SLOT8,        VIRTKEY, NOINVERT
747.2360 +    "9",            ID_SELECT_SLOT9,        VIRTKEY, NOINVERT
747.2361 +    VK_OEM_PERIOD,  ID_TOOLS_FRAMECOUNTER,  VIRTKEY, NOINVERT
747.2362 +    VK_OEM_COMMA,   ID_TOOLS_INPUTDISPLAY,  VIRTKEY, NOINVERT
747.2363 +    "B",            ID_TOOLS_REWIND,        VIRTKEY, CONTROL, NOINVERT
747.2364 +    "R",            ID_MOVIE_RESTART_PLAY,  VIRTKEY, SHIFT, NOINVERT
747.2365 +END
747.2366 +
747.2367 +IDR_ACCELERATOR1 ACCELERATORS
747.2368 +BEGIN
747.2369 +    "N",            IDC_C_WATCH,            VIRTKEY, NOINVERT
747.2370 +    "D",            IDC_C_WATCH_DOWN,       VIRTKEY, NOINVERT
747.2371 +    "A",            IDC_C_WATCH_DUPLICATE,  VIRTKEY, NOINVERT
747.2372 +    "E",            IDC_C_WATCH_EDIT,       VIRTKEY, NOINVERT
747.2373 +    "R",            IDC_C_WATCH_REMOVE,     VIRTKEY, NOINVERT
747.2374 +    "U",            IDC_C_WATCH_UP,         VIRTKEY, NOINVERT
747.2375 +    "N",            RAMMENU_FILE_NEW,       VIRTKEY, CONTROL, NOINVERT
747.2376 +    "O",            RAMMENU_FILE_OPEN,      VIRTKEY, CONTROL, NOINVERT
747.2377 +    "S",            RAMMENU_FILE_SAVE,      VIRTKEY, CONTROL, NOINVERT
747.2378 +    "S",            RAMMENU_FILE_SAVEAS,    VIRTKEY, SHIFT, CONTROL, NOINVERT
747.2379 +END
747.2380 +
747.2381 +
747.2382 +/////////////////////////////////////////////////////////////////////////////
747.2383 +//
747.2384 +// RT_MANIFEST
747.2385 +//
747.2386 +
747.2387 +1                       RT_MANIFEST             "VisualBoyAdvance.exe.manifest"
747.2388 +
747.2389 +/////////////////////////////////////////////////////////////////////////////
747.2390 +//
747.2391 +// String Table
747.2392 +//
747.2393 +
747.2394 +STRINGTABLE
747.2395 +BEGIN
747.2396 +    IDS_STARTAVIRECORDING   "Start &AVI Recording..."
747.2397 +    IDS_STOPAVIRECORDING    "Stop &AVI Recording"
747.2398 +    IDS_PAUSEAVIRECORDING   "Pause AVI &Recording"
747.2399 +    IDS_RESUMEAVIRECORDING  "Resume AVI &Recording"
747.2400 +END
747.2401 +
747.2402 +STRINGTABLE
747.2403 +BEGIN
747.2404 +    IDS_STARTSOUNDRECORDING "Start &WAV Recording..."
747.2405 +    IDS_STOPSOUNDRECORDING  "Stop &WAV Recording"
747.2406 +END
747.2407 +
747.2408 +STRINGTABLE
747.2409 +BEGIN
747.2410 +    IDS_UNSUPPORTED_VBA_SGM "Unsupported VisualBoyAdvance save game version %d"
747.2411 +    IDS_CANNOT_LOAD_SGM     "Cannot load save game for %s"
747.2412 +    IDS_SAVE_GAME_NOT_USING_BIOS "Save game is not using the BIOS file"
747.2413 +    IDS_SAVE_GAME_USING_BIOS "Save game is using the BIOS file"
747.2414 +    IDS_UNSUPPORTED_SAVE_TYPE "Unsupported save type %d"
747.2415 +    IDS_CANNOT_OPEN_FILE    "Cannot open file %s"
747.2416 +    IDS_BAD_ZIP_FILE        "Bad ZIP file %s"
747.2417 +    IDS_NO_IMAGE_ON_ZIP     "No image found on ZIP file %s"
747.2418 +    IDS_ERROR_OPENING_IMAGE "Error opening image %s"
747.2419 +    IDS_ERROR_READING_IMAGE "Error reading image %s"
747.2420 +    IDS_UNSUPPORTED_BIOS_FUNCTION 
747.2421 +                            "Unsupported BIOS function %02x called from %08x. A BIOS file is needed in order to get correct behaviour."
747.2422 +    IDS_INVALID_BIOS_FILE_SIZE "Invalid BIOS file size"
747.2423 +    IDS_INVALID_CHEAT_CODE  "Invalid cheat code '%s'. Supported formats are:\nXXXXXXXX:YY, XXXXXXXX:YYYY, XXXXXXXX:YYYYYYYY."
747.2424 +    IDS_UNKNOWN_ARM_OPCDOE  "Unimplemented opcode %08x from %08x"
747.2425 +    IDS_UNKNOWN_THUMB_OPCODE "Unknown opcode %04x from %08x"
747.2426 +END
747.2427 +
747.2428 +STRINGTABLE
747.2429 +BEGIN
747.2430 +    IDS_ERROR_CREATING_FILE "Error creating file %s"
747.2431 +    IDS_FAILED_TO_READ_SGM  "Failed to read complete save game %s (%d)"
747.2432 +    IDS_FAILED_TO_READ_RTC  "Failed to read RTC from save game %s (continuing)"
747.2433 +    IDS_UNSUPPORTED_VB_SGM  "Unsupported VisualBoy save game version %d"
747.2434 +    IDS_CANNOT_LOAD_SGM_FOR "Cannot load save game for %s. Playing %s"
747.2435 +    IDS_ERROR_OPENING_IMAGE_FROM "Error opening image %s from zip file %s"
747.2436 +    IDS_ERROR_READING_IMAGE_FROM "Error reading image %s from zip file %s"
747.2437 +    IDS_UNSUPPORTED_ROM_SIZE "Unsupported rom size %02x"
747.2438 +    IDS_UNSUPPORTED_RAM_SIZE "Unsupported ram size %02x"
747.2439 +    IDS_UNKNOWN_CARTRIDGE_TYPE "Unknown cartridge type %02x"
747.2440 +    IDS_MAXIMUM_NUMBER_OF_CHEATS "Maximum number of cheats reached."
747.2441 +    IDS_INVALID_GAMESHARK_CODE "Invalid GameShark code: %s"
747.2442 +    IDS_INVALID_GAMEGENIE_CODE "Invalid GameGenie code: %s"
747.2443 +    IDS_INVALID_CHEAT_TO_REMOVE "Invalid cheat to remove %d"
747.2444 +    IDS_INVALID_CHEAT_CODE_ADDRESS "Invalid cheat code address: %08x"
747.2445 +    IDS_UNSUPPORTED_CHEAT_LIST_VERSION "Unsupported cheat list version %d"
747.2446 +END
747.2447 +
747.2448 +STRINGTABLE
747.2449 +BEGIN
747.2450 +    IDS_DIRECTX_7_REQUIRED  "DirectX 7.0 or greater is required to run.\nDownload at http://www.microsoft.com/directx.\n\nError found at: %s"
747.2451 +    IDS_DISABLING_VIDEO_MEMORY "Disabling Use Video Memory setting"
747.2452 +    IDS_SETTING_WILL_BE_EFFECTIVE 
747.2453 +                            "Setting will be effective the next time you start the emulator"
747.2454 +    IDS_DISABLING_EMULATION_ONLY "Disabling Emulation Only setting"
747.2455 +    IDS_FAILED_TO_OPEN_FILE "Failed to open file %s"
747.2456 +    IDS_FAILED_TO_READ_ZIP_DIR "Failed to read zip directory for file %s"
747.2457 +    IDS_UNSUPPORTED_FILE_TYPE "The file ""%s"" is an unsupported type."
747.2458 +    IDS_CANNOT_CREATE_DIRECTSOUND "Cannot create DirectSound %08x"
747.2459 +    IDS_CANNOT_SETCOOPERATIVELEVEL "Cannot SetCooperativeLevel %08x"
747.2460 +    IDS_CANNOT_CREATESOUNDBUFFER "Cannot CreateSoundBuffer %08x"
747.2461 +    IDS_CANNOT_SETFORMAT_PRIMARY "Cannot SetFormat for primary %08x"
747.2462 +    IDS_CANNOT_CREATESOUNDBUFFER_SEC "Cannot CreateSoundBuffer secondary %08x"
747.2463 +    IDS_CANNOT_PLAY_PRIMARY "Cannot Play primary %08x"
747.2464 +    IDS_SEARCH_PRODUCED_TOO_MANY 
747.2465 +                            "Search produced %d results.\nThey have been remembered, but are too many to display.\nPlease refine it better by performing additional searches."
747.2466 +    IDS_NUMBER_CANNOT_BE_EMPTY "Number cannot be empty"
747.2467 +    IDS_INVALID_ADDRESS     "Invalid address: %08x"
747.2468 +END
747.2469 +
747.2470 +STRINGTABLE
747.2471 +BEGIN
747.2472 +    IDS_MISALIGNED_HALFWORD "Misaligned half-word address: %08x"
747.2473 +    IDS_MISALIGNED_WORD     "Misaligned word address: %08x"
747.2474 +    IDS_VALUE_CANNOT_BE_EMPTY "Value cannot be empty"
747.2475 +    IDS_ERROR_ON_STARTDOC   "Error on StartDoc"
747.2476 +    IDS_ERROR_ON_STARTPAGE  "Error on StartPage"
747.2477 +    IDS_ERROR_PRINTING_ON_STRETCH "Error printing on StretchDIBits"
747.2478 +    IDS_ERROR_ON_ENDPAGE    "Error on EndPage"
747.2479 +    IDS_ERROR_ON_ENDDOC     "Error on EndDoc"
747.2480 +    IDS_ERROR               "Error"
747.2481 +    IDS_JOY_LEFT            "Joy %d Left"
747.2482 +    IDS_JOY_RIGHT           "Joy %d Right"
747.2483 +    IDS_JOY_UP              "Joy %d Up"
747.2484 +    IDS_JOY_DOWN            "Joy %d Down"
747.2485 +    IDS_JOY_BUTTON          "Joy %d %s"
747.2486 +END
747.2487 +
747.2488 +STRINGTABLE
747.2489 +BEGIN
747.2490 +    IDS_SELECT_BIOS_FILE    "Select BIOS file"
747.2491 +    IDS_RESET               "Reset"
747.2492 +    IDS_AUTOFIRE_A_DISABLED "turbo A off"
747.2493 +    IDS_AUTOFIRE_A          "turbo A on"
747.2494 +    IDS_AUTOFIRE_B_DISABLED "turbo B off"
747.2495 +    IDS_AUTOFIRE_B          "turbo B on"
747.2496 +    IDS_AUTOFIRE_L_DISABLED "turbo L off"
747.2497 +    IDS_AUTOFIRE_L          "turbo L on"
747.2498 +    IDS_AUTOFIRE_R_DISABLED "turbo R off"
747.2499 +    IDS_AUTOFIRE_R          "turbo R on"
747.2500 +    IDS_SELECT_ROM          "Select ROM"
747.2501 +    IDS_SELECT_SAVE_GAME_NAME "Select save game name"
747.2502 +    IDS_LOADED_STATE        "Loaded state"
747.2503 +    IDS_LOADED_STATE_N      "Loaded %d"
747.2504 +END
747.2505 +
747.2506 +STRINGTABLE
747.2507 +BEGIN
747.2508 +    IDS_WROTE_STATE         "Saved state"
747.2509 +    IDS_WROTE_STATE_N       "Saved %d"
747.2510 +    IDS_LOADED_BATTERY      "Loaded battery"
747.2511 +    IDS_SELECT_CAPTURE_NAME "Select screen capture name"
747.2512 +    IDS_SCREEN_CAPTURE      "Screen capture"
747.2513 +    IDS_ADDRESS             "Address"
747.2514 +    IDS_OLD_VALUE           "Old Value"
747.2515 +    IDS_NEW_VALUE           "New Value"
747.2516 +    IDS_ADD_CHEAT_CODE      "Add cheat code"
747.2517 +    IDS_CODE                "Code"
747.2518 +    IDS_DESCRIPTION         "Description"
747.2519 +    IDS_STATUS              "Status"
747.2520 +    IDS_ADD_GG_CODE         "Add GameGenie code"
747.2521 +    IDS_ADD_GS_CODE         "Add GameShark code"
747.2522 +    IDS_POCKET_PRINTER      "Pocket Printer"
747.2523 +    IDS_UNKNOWN             "Unknown"
747.2524 +END
747.2525 +
747.2526 +STRINGTABLE
747.2527 +BEGIN
747.2528 +    IDS_NONE                "None"
747.2529 +    IDS_FAILED_TO_LOAD_LIBRARY "Failed to load library %s"
747.2530 +    IDS_FAILED_TO_GET_LOCINFO "Failed to get locale information"
747.2531 +    IDS_SELECT_CHEAT_LIST_NAME "Select cheat list name"
747.2532 +    IDS_FILTER_BIOS         "Gameboy Advance_*.bin;*.agb;*.gba;*.bios;*.zip;*.z;*.gz;*.tar_All Files_*.*__"
747.2533 +    IDS_FILTER_ROM          "All Gameboy / Gameboy Advance_*.bin;*.agb;*.gba;*.mb;*.elf;*.gb;*.sgb;*.cgb;*.gbc;*.zip;*.z;*.gz;*.7z;*.rar;*.lzma;*.bz2;*.bzip2;*.tar_All GB / GBA (uncompressed only)_*.bin;*.agb;*.gba;*.mb;*.elf;*.gb;*.sgb;*.cgb;*.gbc_Gameboy Advance (uncompressed only)_*.bin;*.agb;*.gba_Gameboy (uncompressed only)_*.gb;*.sgb;*.cgb;*.gbc_Archive Files_*.zip;*.z;*.gz;*.7z;*.rar;*.lzma;*.bz2;*.bzip2;*.tar_All Files_*.*__"
747.2534 +    IDS_FILTER_SGM          "VisualBoyAdvance Save Game_*.sgm_All Files_*.*__"
747.2535 +    IDS_FILTER_CHEAT_LIST   "VisualBoyAdvance Cheat List_*.clt_All Files_*.*__"
747.2536 +    IDS_FILTER_PNG          "PNG Image_*.png_BMP Image_*.bmp_All Files_*.*__"
747.2537 +    IDS_LOADED_CHEATS       "Loaded cheats"
747.2538 +    IDS_ERROR_DISP_COLOR    "Unsupported display setting for color depth: %d bits. \nWindows desktop must be in either 16-bit, 24-bit or 32-bit mode for this program to work in window mode."
747.2539 +    IDS_ADD_GSA_CODE        "Add GamesharkAdvance code"
747.2540 +    IDS_FILTER_SPS          "Gameshark Snapshot_*.sps_All Files_*.*__"
747.2541 +    IDS_SELECT_SNAPSHOT_FILE "Select snapshot file"
747.2542 +    IDS_FILTER_SAV          "Battery file_*.sav_Flash save_*.dat_All Files_*.*__"
747.2543 +    IDS_SELECT_BATTERY_FILE "Select battery file"
747.2544 +END
747.2545 +
747.2546 +STRINGTABLE
747.2547 +BEGIN
747.2548 +    IDS_UNSUPPORTED_CHEAT_LIST_TYPE "Unsupported cheat list type %d"
747.2549 +    IDS_INVALID_GSA_CODE    "Invalid GSA code. Format is XXXXXXXXYYYYYYYY."
747.2550 +    IDS_CANNOT_IMPORT_SNAPSHOT_FOR 
747.2551 +                            "Cannot import snapshot for %s. Current game is %s"
747.2552 +    IDS_UNSUPPORTED_SNAPSHOT_FILE "Unsupported snapshot file %s"
747.2553 +    IDS_UNSUPPORTED_ARM_MODE "Unsupported ARM mode %02x"
747.2554 +    IDS_UNSUPPORTED_CODE_FILE "Unsupported code file %s"
747.2555 +    IDS_GSA_CODE_WARNING    "Warning: cheats are for game %s. Current game is %s.\nCodes may not work correctly."
747.2556 +    IDS_INVALID_CBA_CODE    "Invalid CBA code. Format is XXXXXXXX YYYY."
747.2557 +    IDS_CBA_CODE_WARNING    "Warning: Codes seem to be for a different game.\nCodes may not work correctly."
747.2558 +    IDS_OUT_OF_MEMORY       "Failed to allocate memory for %s"
747.2559 +END
747.2560 +
747.2561 +STRINGTABLE
747.2562 +BEGIN
747.2563 +    IDS_FILTER_GBS          "Gameboy Snapshot_*.gbs_All Files_*.*__"
747.2564 +    IDS_FILTER_GCF          "Gameshark Code File_*.gcf_All Files_*.*__"
747.2565 +    IDS_SELECT_CODE_FILE    "Select code file"
747.2566 +    IDS_SAVE_WILL_BE_LOST   "Importing a snapshot file will erase any saved games and reset the emulator. Do you want to continue?"
747.2567 +    IDS_CONFIRM_ACTION      "Please confirm action"
747.2568 +    IDS_CODES_WILL_BE_LOST  "Importing a code file will erase any entered codes. Do you want to continue?"
747.2569 +    IDS_FILTER_SPC          "Gameshark Code File_*.spc;*.xpc_All Files_*.*__"
747.2570 +    IDS_ADD_CBA_CODE        "Add CodeBreakerAdvance code"
747.2571 +    IDS_FILTER_WAV          "Wave file_*.wav_All Files_*.*__"
747.2572 +    IDS_SELECT_WAV_NAME     "Select wave file name"
747.2573 +    IDS_FILTER_GBROM        "All Gameboy_*.gb;*.sgb;*.cgb;*.gbc;*.zip;*.z;*.gz;*.7z;*.rar;*.lzma;*.bz2;*.bzip2;*.tar_Gameboy_*.gb_Super Gameboy_*.sgb_Color Gameboy_*.cgb;*.gbc_All Files_*.*__"
747.2574 +    IDS_FILTER_PAL          "Windows Palette (*.PAL)_*.pal_PaintShop Palette (*.PAL)_*.pal_Adobe Color Table (*.ACT)_*.act_All Files_*.*__"
747.2575 +    IDS_SELECT_PALETTE_NAME "Select palette name:"
747.2576 +    IDS_SEARCH_PRODUCED_NO_RESULTS "Search produced no results."
747.2577 +    IDS_ERROR_BINDING       "Error binding socket. Port probably in use."
747.2578 +    IDS_ERROR_LISTENING     "Error listening on socket."
747.2579 +END
747.2580 +
747.2581 +STRINGTABLE
747.2582 +BEGIN
747.2583 +    IDS_ERROR_CREATING_SOCKET "Error creating socket."
747.2584 +    IDS_ACK_NOT_RECEIVED    "ACK not received from GDB."
747.2585 +    IDS_ERROR_NOT_GBA_IMAGE "Error: not a GBA image."
747.2586 +    IDS_EEPROM_NOT_SUPPORTED "EEPROM saves cannot be exported."
747.2587 +    IDS_FILTER_DUMP         "Memory Dump_*.dmp_All Files_*.*__"
747.2588 +    IDS_SELECT_DUMP_FILE    "Select dump file name"
747.2589 +    IDS_FILTER_AVI          "AVI File_*.avi_All Files_*.*__"
747.2590 +    IDS_SELECT_AVI_NAME     "Select AVI file name"
747.2591 +    IDS_INVALID_THROTTLE_VALUE 
747.2592 +                            "Invalid throttle value. Please enter a number between 5 and 1000."
747.2593 +    IDS_FILTER_INI          "Skin INI File_*.ini_All Files_*.*__"
747.2594 +    IDS_SELECT_SKIN_FILE    "Select the skin file name"
747.2595 +    IDS_FILTER_MOVIE        "VisualBoyAdvance Movie (.vbm)_*.vbm;*.zip;*.z;*.gz;*.7z;*.rar;*.lzma;*.bz2;*.bzip2;*.tar_VisualBoyAdvance Movie (uncompressed only)_*.vbm_Archive Files_*.zip;*.z;*.gz;*.7z;*.rar;*.lzma;*.bz2;*.bzip2;*.tar_All Files_*.*__"
747.2596 +    IDS_SELECT_MOVIE_NAME   "Select movie name"
747.2597 +    IDS_BUG_REPORT          "The bug report information is now available on the Windows Clipboard. Please paste it into any bug report made by email or on forums to help solve problems more easily."
747.2598 +    IDS_UNSUPPORTED_MOVIE_VERSION "Unsupported movie version %d."
747.2599 +    IDS_END_OF_MOVIE        "end of movie"
747.2600 +END
747.2601 +
747.2602 +STRINGTABLE
747.2603 +BEGIN
747.2604 +    IDS_INVALID_INTERVAL_VALUE 
747.2605 +                            "Invalid rewind interval value. Please enter a number between 0 and 600 seconds."
747.2606 +    IDS_REGISTRY            "VisualBoyAdvance no longer uses the registry to store its settings. Your previous settings have been exported into the file: %s"
747.2607 +    IDS_MOVIE_PLAY          "Playing a movie will load a save state which may erase your previous battery saves. Please be sure to have a saved state if you don't want to loose any previous data."
747.2608 +    IDS_AUTOFIRE_DISABLED   "autofire off"
747.2609 +    IDS_AUTOFIRE_ALREADY_DISABLED "autofire already off"
747.2610 +    IDS_AUTOFIRE_START_DISABLED "turbo Start off"
747.2611 +    IDS_AUTOFIRE_START      "turbo Start on"
747.2612 +    IDS_AUTOFIRE_SELECT_DISABLED "turbo Select off"
747.2613 +    IDS_AUTOFIRE_SELECT     "turbo Select on"
747.2614 +    IDS_AUTOFIRE_UP_DISABLED "turbo Up off"
747.2615 +    IDS_AUTOFIRE_UP         "turbo Up on"
747.2616 +    IDS_AUTOFIRE_DOWN_DISABLED "turbo Down off"
747.2617 +    IDS_AUTOFIRE_DOWN       "turbo Down on"
747.2618 +    IDS_AUTOFIRE_LEFT_DISABLED "turbo Left off"
747.2619 +    IDS_AUTOFIRE_LEFT       "turbo Left on"
747.2620 +    IDS_AUTOFIRE_RIGHT_DISABLED "turbo Right off"
747.2621 +END
747.2622 +
747.2623 +STRINGTABLE
747.2624 +BEGIN
747.2625 +    IDS_AUTOFIRE_RIGHT      "turbo Right on"
747.2626 +    IDS_RERECORDED_STATE_N  "Re-record from %d"
747.2627 +    IDS_REPLAYED_STATE_N    "Rewind to %d"
747.2628 +END
747.2629 +
747.2630 +STRINGTABLE
747.2631 +BEGIN
747.2632 +    IDS_FILTER_LUA          "Lua Script (.lua)_*.lua_All Files_*.*__"
747.2633 +    IDS_SELECT_LUA_NAME     "Select Lua script file name"
747.2634 +    IDS_SELECT_LUA_DIR      "Select Lua script file directory:"
747.2635 +    IDS_SELECT_MOVIE_DIR    "Select movie directory:"
747.2636 +    IDS_SELECT_ROM_DIR      "Select GBA ROM directory:"
747.2637 +    IDS_SELECT_GBXROM_DIR   "Select GBx ROM directory:"
747.2638 +    IDS_SELECT_BATTERY_DIR  "Select Battery directory:"
747.2639 +    IDS_SELECT_SAVE_DIR     "Select Save Directory:"
747.2640 +    IDS_SELECT_CAPTURE_DIR  "Select Capture directory:"
747.2641 +END
747.2642 +
747.2643 +STRINGTABLE
747.2644 +BEGIN
747.2645 +    IDS_SELECT_AVI_DIR      "Select AVI recording directory:"
747.2646 +    IDS_SELECT_WAV_DIR      "Select Sound recording directory:"
747.2647 +    IDS_SELECT_CHEAT_DIR    "Select Cheat list directory:"
747.2648 +    IDS_SELECT_WATCH_DIR    "Select Memory watch file directory:"
747.2649 +    IDS_SELECT_IPS_DIR      "Select IPS directory:"
747.2650 +    IDS_SELECT_PLUGIN_DIR   "Select Plugin directory:"
747.2651 +END
747.2652 +
747.2653 +#endif    // English (United States) resources
747.2654 +/////////////////////////////////////////////////////////////////////////////
747.2655 +
747.2656 +
747.2657 +
747.2658 +#ifndef APSTUDIO_INVOKED
747.2659 +/////////////////////////////////////////////////////////////////////////////
747.2660 +//
747.2661 +// Generated from the TEXTINCLUDE 3 resource.
747.2662 +//
747.2663 +
747.2664 +
747.2665 +/////////////////////////////////////////////////////////////////////////////
747.2666 +#endif    // not APSTUDIO_INVOKED
747.2667 +
   748.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   748.2 +++ b/src/win32/vba.rc2	Sat Mar 03 10:31:27 2012 -0600
   748.3 @@ -0,0 +1,50 @@
   748.4 +
   748.5 +// what the hell? all this file does is cause enigmatic build errors...
   748.6 +
   748.7 +/*
   748.8 +#ifndef _MAC
   748.9 +#include "../AutoBuild.h"
  748.10 +/////////////////////////////////////////////////////////////////////////////
  748.11 +//
  748.12 +// Version
  748.13 +//
  748.14 +
  748.15 +VS_VERSION_INFO VERSIONINFO
  748.16 + FILEVERSION FILEVER
  748.17 + PRODUCTVERSION PRODUCTVER
  748.18 + FILEFLAGSMASK 0x3fL
  748.19 +#ifdef _DEBUG
  748.20 + FILEFLAGS 0x29L
  748.21 +#else
  748.22 + FILEFLAGS 0x28L
  748.23 +#endif
  748.24 + FILEOS 0x40004L
  748.25 + FILETYPE 0x1L
  748.26 + FILESUBTYPE 0x0L
  748.27 +BEGIN
  748.28 +    BLOCK "StringFileInfo"
  748.29 +    BEGIN
  748.30 +        BLOCK "040904b0"
  748.31 +        BEGIN
  748.32 +            VALUE "Comments", "VisualBoyAdvance comes with NO WARRANTY. Use it at your own risk.\0"
  748.33 +            VALUE "CompanyName", "None\0"
  748.34 +            VALUE "FileDescription", "VisualBoyAdvance emulator\0"
  748.35 +            VALUE "FileVersion", STRFILEVER
  748.36 +            VALUE "InternalName", "VisualBoyAdvance\0"
  748.37 +            VALUE "LegalCopyright", "Copyright © 2004 Forgotten and the VBA team\0"
  748.38 +            VALUE "LegalTrademarks", "\0"
  748.39 +            VALUE "OriginalFilename", "VisualBoyAdvance.exe\0"
  748.40 +            VALUE "PrivateBuild", "0\0"
  748.41 +            VALUE "ProductName", "VisualBoyAdvance emulator\0"
  748.42 +            VALUE "ProductVersion", STRPRODUCTVER
  748.43 +            VALUE "SpecialBuild", "0\0"
  748.44 +        END
  748.45 +    END
  748.46 +    BLOCK "VarFileInfo"
  748.47 +    BEGIN
  748.48 +        VALUE "Translation", 0x409, 1200
  748.49 +    END
  748.50 +END
  748.51 +
  748.52 +#endif    // !_MAC
  748.53 +*/
  748.54 \ No newline at end of file